-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from xian-network/extend_crypto
Extend `crypto` with `key_is_valid` function to check address
- Loading branch information
Showing
1 changed file
with
23 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,35 @@ | ||
## Crypto Standard Library | ||
|
||
In this example, the verify_signature function is an exported function in a Xian smart contract. It takes a verification key (vk), a message (msg), and a signature (signature). It uses the verify function from the crypto module to check if the signature is valid for the given message and verification key. The result (True or False) is then returned. This can be used to ensure data integrity and authenticity in transactions within the smart contract environment. | ||
The `crypto` module uses the `PyNaCl` library under the hood, employing the `Ed25519` signature scheme. The module consists of the following functions | ||
|
||
This module uses the `PyNaCl` library under the hood, employing the `Ed25519` signature scheme. | ||
### verify_signature | ||
|
||
It checks if the signature is valid for the given message and verification key. The result (True or False) is then returned. This can be used to ensure data integrity and authenticity in transactions within the smart contract environment. | ||
|
||
How to use it in a contract: | ||
|
||
```python | ||
@export | ||
def verify_signature(vk: str, msg: str, signature: str): | ||
# Use the verify function to check if the signature is valid for the given message and verification key | ||
# Check if the signature is valid for the given message and verification key | ||
is_valid = crypto.verify(vk, msg, signature) | ||
|
||
# Return the result of the verification | ||
return is_valid | ||
``` | ||
|
||
### key_is_valid | ||
|
||
It checks if the provided key (address) is valid or not. The result (True or False) is then returned. | ||
|
||
How to use it in a contract: | ||
|
||
```python | ||
@export | ||
def verify_address(address: str): | ||
# Check if the given address is a valid Ed25519 key | ||
is_valid = key_is_valid(address) | ||
|
||
# Return the result of the verification | ||
return is_valid | ||
``` |