pub struct Ed25519 {
/// The underlying raw `[u8; 64]` data of the signature.
bits: [u8; 64],
}
Expand description
An ed25519 signature.
Fields
bits: [u8; 64]
The underlying raw [u8; 64]
data of the signature.
Implementations
pub fn new() -> Self
pub fn new() -> Self
Creates a zeroed out instances of a Ed25519 signature.
Returns
[Ed25519] - A zero ed25519 signature.
Examples
use std::crypto::Ed25519;
fn foo() {
let new_ed25519 = Ed25519::new();
assert(new_ed25519.bits()[0] == 0u8);
assert(new_ed25519.bits()[63] == 0u8);
}
pub fn bits(self) -> [u8; 64]
pub fn bits(self) -> [u8; 64]
Returns the underlying raw [u8; 64]
data of the signature.
Returns
- [[u8; 64]] - The raw data of the signature.
Examples
use std::crypto::Ed25519;
fn foo() -> {
let new_ed25519 = Ed25519::new();
assert(new_ed25519.bits()[0] == 0u8);
}
pub fn verify(
self,
public_key: PublicKey,
message: Message,
) -> Result<(), SignatureError>
pub fn verify(
self,
public_key: PublicKey,
message: Message,
) -> Result<(), SignatureError>
Verifies that a 32-byte curve25519 public key derived from the private key was used to sign a message.
Returns a Result
to let the caller choose an error handling strategy.
Additional Information
NOTE: This uses a 32-byte public key.
Arguments
public_key
: [PublicKey] - The public key that signed the message.message
: [Message] - The hashed signed data.
Returns
- [Result<bool, SignatureError>] - A verified result or an error.
Examples
use std::{crypto::{Ed25519, Signature, Message, PublicKey}, constants::ZERO_B256};
fn foo() {
let signature: Ed25519 = Ed25519::from((
0xf38cef9361894be6c6e0eddec28a663d099d7ddff17c8077a1447d7ecb4e6545,
0xf5084560039486d3462dd65a40c80a74709b2f06d450ffc5dc00345c6b2cdd00
));
let message: Message = Message::from(0x1e45523606c96c98ba970ff7cf9511fab8b25e1bcd52ced30b81df1e4a9c4323);
// Only 32 bytes are valid for 32-byte curve25519 public keys
let public_key: PublicKey = PublicKey::from(0x314fa58689bbe1da2430517de2d772b384a1c1d2e9cb87e73c6afcf246045b10);
// A verified public key with signature
let verified = signature.verify(pub_key, msg_hash);
assert(verified.is_ok());
}
Trait Implementations
impl AbiEncode for Ed25519
impl AbiEncode for Ed25519
pub fn abi_encode(self, buffer: Buffer) -> Buffer
impl AbiDecode for Ed25519
impl AbiDecode for Ed25519
pub fn abi_decode(refmut buffer: BufferReader) -> Self
impl Eq for Ed25519
impl Eq for Ed25519
pub fn eq(self, other: Self) -> bool
pub fn neq(self, other: Self) -> bool
pub fn neq(self, other: Self) -> bool
Evaluates if two values of the same type are not equal.
Additional Information
This function is inherited when eq()
is implemented.
Arguments
other
: [Self] - The value of the same type.
Returns
- [bool] -
true
if the two values are not equal, otherwisefalse
.
Examples
struct MyStruct {
val: u64,
}
impl Eq for MyStruct {
fn eq(self, other: Self) -> bool {
self.val == other.val
}
}
fn foo() {
let struct1 = MyStruct { val: 10 };
let struct2 = MyStruct { val: 2 };
let result = struct1 != struct2;
assert(result);
}