pub struct Secp256r1Account { /* private fields */ }Use WebAuthnAccount for on-chain transaction signing. Bare secp256r1 signatures are not accepted by Aptos validators (the on-chain AnySignature variant 2 is WebAuthn, not Secp256r1Ecdsa). This type is retained for off-chain use only.
secp256r1 only.Expand description
A Secp256r1 (P-256) ECDSA account.
§⚠️ Deprecated for on-chain transaction signing
On current Aptos networks the on-chain AnySignature variant at index
2 is WebAuthn, not bare secp256r1 ECDSA. Transactions signed by
this account type are rejected by every Aptos validator. Use
WebAuthnAccount instead – it reuses the
same key material and produces the correct WebAuthn-envelope wire
format.
This type is still useful for off-chain P-256 use (sign / verify of
arbitrary bytes, key import/export, key-derivation testing) and for
constructing MultiKeyAccount public-key
material.
§Example
use aptos_sdk::account::Secp256r1Account;
// For off-chain signing only -- this account cannot submit
// transactions to a live Aptos network. Use `WebAuthnAccount` for that.
let account = Secp256r1Account::generate();
println!("Address: {}", account.address());Implementations§
Source§impl Secp256r1Account
impl Secp256r1Account
Sourcepub fn from_private_key(private_key: Secp256r1PrivateKey) -> Self
pub fn from_private_key(private_key: Secp256r1PrivateKey) -> Self
Creates an account from a private key.
Sourcepub fn from_private_key_bytes(bytes: &[u8]) -> AptosResult<Self>
pub fn from_private_key_bytes(bytes: &[u8]) -> AptosResult<Self>
Creates an account from private key bytes.
§Errors
Returns an error if the bytes are not a valid Secp256r1 private key (must be exactly 32 bytes and a valid curve point).
Sourcepub fn from_private_key_hex(hex_str: &str) -> AptosResult<Self>
pub fn from_private_key_hex(hex_str: &str) -> AptosResult<Self>
Creates an account from a private key hex string.
§Errors
This function will return an error if:
- The hex string is invalid or cannot be decoded
- The decoded bytes are not a valid Secp256r1 private key
Sourcepub fn address(&self) -> AccountAddress
pub fn address(&self) -> AccountAddress
Returns the account address.
Sourcepub fn public_key(&self) -> &Secp256r1PublicKey
pub fn public_key(&self) -> &Secp256r1PublicKey
Returns the public key.
Sourcepub fn private_key(&self) -> &Secp256r1PrivateKey
pub fn private_key(&self) -> &Secp256r1PrivateKey
Returns a reference to the private key.
Sourcepub fn sign_message(&self, message: &[u8]) -> Secp256r1Signature
pub fn sign_message(&self, message: &[u8]) -> Secp256r1Signature
Signs a message and returns the Secp256r1 signature.
Trait Implementations§
Source§impl Account for Secp256r1Account
impl Account for Secp256r1Account
Source§fn address(&self) -> AccountAddress
fn address(&self) -> AccountAddress
Source§fn authentication_key(&self) -> AuthenticationKey
fn authentication_key(&self) -> AuthenticationKey
Source§fn sign(&self, message: &[u8]) -> AptosResult<Vec<u8>>
fn sign(&self, message: &[u8]) -> AptosResult<Vec<u8>>
Source§fn signature_scheme(&self) -> u8
fn signature_scheme(&self) -> u8
Source§impl Clone for Secp256r1Account
impl Clone for Secp256r1Account
Source§fn clone(&self) -> Secp256r1Account
fn clone(&self) -> Secp256r1Account
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more