Skip to content

Commit

Permalink
Merge pull request #1 from xian-network/extend_crypto
Browse files Browse the repository at this point in the history
Extend `crypto` with `key_is_valid` function to check address
  • Loading branch information
Endogen authored Jun 4, 2024
2 parents a158983 + 2b4fcb6 commit 79f248c
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions docs/concepts/crypto.md
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
```

0 comments on commit 79f248c

Please sign in to comment.