Crates.io | solana-ed25519-instruction |
lib.rs | solana-ed25519-instruction |
version | 0.2.1 |
source | src |
created_at | 2024-09-01 10:13:58.273853 |
updated_at | 2024-09-05 17:37:55.165774 |
description | Deserialization for Ed25519 instruction data |
homepage | |
repository | |
max_upload_size | |
id | 1359465 |
size | 10,450 |
This Rust module provides a structured way to deserialize and work with Ed25519 signatures in the context of Solana's BPF programs. It allows for deserialization of signature data, extraction of public keys (signers), and retrieval of signed data, making it easier to validate and work with Ed25519 signatures on the Solana blockchain.
BorshDeserialize
trait for easy deserialization from byte streams, making it compatible with the Borsh serialization format commonly used in Solana programs.use solana_program::pubkey::Pubkey;
use borsh::BorshDeserialize;
let mut input = /* some byte array containing Ed25519 signature data */;
let signature = Ed25519Signature::deserialize_reader(&mut input).unwrap();
let signer_pubkey: &Pubkey = signature.0[0].get_signer(&input_data);
let signature_data: &[u8; 64] = signature.0[0].get_signature(&input_data);
let signed_data = signature.0[0].get_data(&input_data);
The Ed25519Signature
struct is a wrapper around a Vec<Ed25519SignatureOffsets>
, where each Ed25519SignatureOffsets
struct represents a single signature and its associated offsets within the instruction data.
The Ed25519Signature
and related structs implement the BorshDeserialize
trait, allowing them to be deserialized from a byte stream using the Borsh serialization format. This makes it easy to work with Solana programs that utilize Borsh for data serialization.
To ensure the correctness of the deserialization and data extraction, it is recommended to write unit tests that validate the behavior of these methods with known inputs.
#[test]
fn test_signature_extraction() {
let mut input = /* byte array containing Ed25519 signature data */;
let signature = Ed25519Signature::deserialize_reader(&mut input).unwrap();
let signer = signature.0[0].get_signer(&input_data);
assert_eq!(signer, &expected_pubkey);
}
This project is licensed under the MIT License. See the LICENSE file for details.