UNPKG

@aptos-labs/ts-sdk

Version:
114 lines (110 loc) 4.04 kB
import { HexInput, AuthenticationKeyScheme } from './types/index.mjs'; import { Serializable, Serializer } from './bcs/serializer.mjs'; import { AccountAddress } from './core/accountAddress.mjs'; import { Deserializer } from './bcs/deserializer.mjs'; import { Signature } from './core/crypto/signature.mjs'; import { Hex } from './core/hex.mjs'; /** * Each account stores an authentication key. Authentication key enables account owners to rotate * their private key(s) associated with the account without changing the address that hosts their account. * @see {@link https://aptos.dev/concepts/accounts | Account Basics} * * Account addresses can be derived from AuthenticationKey */ declare class AuthenticationKey extends Serializable { /** * An authentication key is always a SHA3-256 hash of data, and is always 32 bytes. * * The data to hash depends on the underlying public key type and the derivation scheme. */ static readonly LENGTH: number; /** * The raw bytes of the authentication key. */ readonly data: Hex; constructor(args: { data: HexInput; }); serialize(serializer: Serializer): void; /** * Deserialize an AuthenticationKey from the byte buffer in a Deserializer instance. * @param deserializer The deserializer to deserialize the AuthenticationKey from. * @returns An instance of AuthenticationKey. */ static deserialize(deserializer: Deserializer): AuthenticationKey; toString(): string; toUint8Array(): Uint8Array; static fromSchemeAndBytes(args: { scheme: AuthenticationKeyScheme; input: HexInput; }): AuthenticationKey; /** * @deprecated Use `fromPublicKey` instead * Derives an AuthenticationKey from the public key seed bytes and an explicit derivation scheme. * * This facilitates targeting a specific scheme for deriving an authentication key from a public key. * * @param args - the public key and scheme to use for the derivation */ static fromPublicKeyAndScheme(args: { publicKey: AccountPublicKey; scheme: AuthenticationKeyScheme; }): AuthenticationKey; /** * Converts a PublicKey(s) to an AuthenticationKey, using the derivation scheme inferred from the * instance of the PublicKey type passed in. * * @param args.publicKey * @returns AuthenticationKey */ static fromPublicKey(args: { publicKey: AccountPublicKey; }): AuthenticationKey; /** * Derives an account address from an AuthenticationKey. Since an AccountAddress is also 32 bytes, * the AuthenticationKey bytes are directly translated to an AccountAddress. * * @returns AccountAddress */ derivedAddress(): AccountAddress; } /** * Arguments for verifying a signature */ interface VerifySignatureArgs { message: HexInput; signature: Signature; } /** * An abstract representation of a public key. * * Provides a common interface for verifying any signature. */ declare abstract class PublicKey extends Serializable { /** * Verifies that the private key associated with this public key signed the message with the given signature. * @param args.message The message that was signed * @param args.signature The signature to verify */ abstract verifySignature(args: VerifySignatureArgs): boolean; /** * Get the raw public key bytes */ abstract toUint8Array(): Uint8Array; /** * Get the public key as a hex string with a 0x prefix e.g. 0x123456... */ toString(): string; } /** * An abstract representation of an account public key. * * Provides a common interface for deriving an authentication key. */ declare abstract class AccountPublicKey extends PublicKey { /** * Get the authentication key associated with this public key */ abstract authKey(): AuthenticationKey; } export { AuthenticationKey as A, PublicKey as P, type VerifySignatureArgs as V, AccountPublicKey as a };