pub enum PublicKey {
Ed25519([u8; 32]),
Secp256k1([u8; 64]),
}Expand description
Ed25519 or Secp256k1 public key.
Stored as fixed-size arrays matching nearcore’s representation:
- Ed25519: 32-byte compressed point
- Secp256k1: 64-byte uncompressed point (x, y coordinates, no
0x04prefix)
Variants§
Ed25519([u8; 32])
Ed25519 public key (32 bytes).
Secp256k1([u8; 64])
Secp256k1 public key (64 bytes, uncompressed without prefix).
This matches nearcore’s representation: raw x,y coordinates
without the 0x04 uncompressed point prefix.
Implementations§
Source§impl PublicKey
impl PublicKey
Sourcepub fn ed25519_from_bytes(bytes: [u8; 32]) -> Self
pub fn ed25519_from_bytes(bytes: [u8; 32]) -> Self
Create an Ed25519 public key from raw 32 bytes.
Sourcepub fn secp256k1_from_bytes(bytes: [u8; 64]) -> Self
pub fn secp256k1_from_bytes(bytes: [u8; 64]) -> Self
Create a Secp256k1 public key from raw 64-byte uncompressed coordinates.
The 64 bytes are the raw x,y coordinates without the 0x04 prefix,
matching nearcore’s format.
Validates that the point is on the secp256k1 curve.
§Panics
Panics if the bytes do not represent a valid point on the secp256k1 curve.
Sourcepub fn secp256k1_from_compressed(bytes: [u8; 33]) -> Self
pub fn secp256k1_from_compressed(bytes: [u8; 33]) -> Self
Create a Secp256k1 public key from a compressed 33-byte SEC1 encoding.
The key is validated and stored internally in uncompressed (64-byte) format matching nearcore’s representation.
§Panics
Panics if the bytes do not represent a valid point on the secp256k1 curve.
Sourcepub fn secp256k1_from_uncompressed(bytes: [u8; 65]) -> Self
pub fn secp256k1_from_uncompressed(bytes: [u8; 65]) -> Self
Create a Secp256k1 public key from an uncompressed 65-byte SEC1 encoding
(with 0x04 prefix).
The key is validated and stored internally without the prefix (64 bytes), matching nearcore’s format.
§Panics
Panics if the bytes do not represent a valid point on the secp256k1 curve.
Sourcepub fn as_ed25519_bytes(&self) -> Option<&[u8; 32]>
pub fn as_ed25519_bytes(&self) -> Option<&[u8; 32]>
Get the key data as a fixed-size array for Ed25519 keys.
Sourcepub fn as_secp256k1_bytes(&self) -> Option<&[u8; 64]>
pub fn as_secp256k1_bytes(&self) -> Option<&[u8; 64]>
Get the key data as a fixed-size array for Secp256k1 keys (64-byte uncompressed, no prefix).
Trait Implementations§
Source§impl BorshDeserialize for PublicKey
impl BorshDeserialize for PublicKey
fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self>
Source§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
Source§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where
R: Read,
Source§impl BorshSerialize for PublicKey
impl BorshSerialize for PublicKey
Source§impl<'de> Deserialize<'de> for PublicKey
impl<'de> Deserialize<'de> for PublicKey
Source§fn deserialize<__D>(deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for PublicKey
impl StructuralPartialEq for PublicKey
Auto Trait Implementations§
impl Freeze for PublicKey
impl RefUnwindSafe for PublicKey
impl Send for PublicKey
impl Sync for PublicKey
impl Unpin for PublicKey
impl UnsafeUnpin for PublicKey
impl UnwindSafe for PublicKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.