Class: Secp256k1SecretKey ​
Defined in: secret.ts:77
Encapsulates a secp256k1 secret key Provides get methods for different formats (raw, secret, point). Provides helpers methods for comparison, serialization and publicKey generation. Secp256k1SecretKey
Implements ​
Implements ​
Constructors ​
Constructor ​
new Secp256k1SecretKey(
entropy):Secp256k1SecretKey
Defined in: secret.ts:92
Instantiates an instance of Secp256k1SecretKey.
Parameters ​
entropy ​
bigint | Bytes
bytes (Uint8Array) or secret (bigint)
Returns ​
Secp256k1SecretKey
Throws ​
If entropy is not provided, not a valid 32-byte secret key or not a valid bigint seed
Accessors ​
bytes ​
Get Signature ​
get bytes():
Uint8Array
Defined in: secret.ts:147
Get the secret key entropy as a byte array.
Returns ​
Uint8Array
The secret key bytes as a Uint8Array
Get the secret key bytes.
Implementation of ​
hex ​
Get Signature ​
get hex():
string
Defined in: secret.ts:167
Returns the raw secret key as a hex string.
Returns ​
string
The secret key as a hex string
Get the secret key as a hex string.
Implementation of ​
multibase ​
Get Signature ​
get multibase():
string
Defined in: secret.ts:177
Encode the secret key bytes as a secretKeyMultibase string.
Returns ​
string
The secret key in base58btc multibase format
seed ​
Get Signature ​
get seed():
bigint
Defined in: secret.ts:157
Get the secret key entropy as a bigint.
Returns ​
bigint
The secret key as a bigint
Getter returns the secret key bytes in bigint format. Setter allows alternative method of using a bigint seed for the entropy.
Implementation of ​
Methods ​
computePublicKey() ​
computePublicKey():
CompressedSecp256k1PublicKey
Defined in: secret.ts:206
Computes the public key from the secret key bytes.
Returns ​
The computed public key
Implementation of ​
destroy() ​
destroy():
void
Defined in: secret.ts:137
Zeros out secret key material from memory. The instance should not be used after calling this method.
Returns ​
void
encode() ​
encode():
string
Defined in: secret.ts:186
Encodes the secret key bytes to BIP340 multibase format.
Returns ​
string
The secret key in BIP340 multibase format.
equals() ​
equals(
other):boolean
Defined in: secret.ts:198
Checks if this secret key is equal to another.
Parameters ​
other ​
The other secret key
Returns ​
boolean
True if the private keys are equal, false otherwise
Implementation of ​
exportJSON() ​
exportJSON():
SecretKeyObject
Defined in: secret.ts:222
Exports the secret key as a JSON object. Contains sensitive material.
Returns ​
The secret key as a JSON object
hasValidPublicKey() ​
hasValidPublicKey():
boolean
Defined in: secret.ts:252
Checks if the public key is a valid secp256k1 point.
Returns ​
boolean
True if the public key is valid, false otherwise
isValid() ​
isValid():
boolean
Defined in: secret.ts:244
Checks if the secret key is valid.
Returns ​
boolean
True if the secret key is valid, false otherwise
Implementation of ​
sign() ​
sign(
data,opts?):Bytes
Defined in: secret.ts:269
Produce a signature over arbitrary data using schnorr or ecdsa.
Parameters ​
data ​
Data to be signed.
opts? ​
Options for signing.
Returns ​
Signature byte array.
Throws ​
if no private key is provided.
toJSON() ​
toJSON():
object
Defined in: secret.ts:214
Safe JSON representation. Does not expose secret material. Called implicitly by JSON.stringify(). Use exportJSON() for full serialization.
Returns ​
object
type ​
type:
string
toString() ​
toString():
string
Defined in: secret.ts:231
Prevents secret material from appearing in console.log
Returns ​
string
decode() ​
staticdecode(multibase):Bytes
Defined in: secret.ts:289
Decodes the multibase string to the 34-byte secret key (2 byte prefix + 32 byte key).
Parameters ​
multibase ​
string
The multibase string to decode
Returns ​
The decoded secret key.
fromBigInt() ​
staticfromBigInt(bint):Secp256k1SecretKey
Defined in: secret.ts:364
Creates a new Secp256k1SecretKey object from a bigint secret.
Parameters ​
bint ​
bigint
The secret bigint
Returns ​
Secp256k1SecretKey
A new Secp256k1SecretKey object
fromJSON() ​
staticfromJSON(json):Secp256k1SecretKey
Defined in: secret.ts:324
Creates a Secp256k1SecretKey object from a JSON object.
Parameters ​
json ​
The JSON object containing the secret key bytes
Returns ​
Secp256k1SecretKey
A new Secp256k1SecretKey object
generate() ​
staticgenerate():Secp256k1SecretKey
Defined in: secret.ts:385
Creates a new Secp256k1SecretKey from random secret key bytes.
Returns ​
Secp256k1SecretKey
A new Secp256k1SecretKey object
getPublicKey() ​
staticgetPublicKey(bytes):CompressedSecp256k1PublicKey
Defined in: secret.ts:398
Generates a public key from the given secret key bytes.
Parameters ​
bytes ​
The secret key bytes
Returns ​
The computed public key bytes
random() ​
staticrandom():Bytes
Defined in: secret.ts:372
Generates random secret key bytes.
Returns ​
Uint8Array of 32 random bytes.
toBytes() ​
statictoBytes(secret):Bytes
Defined in: secret.ts:342
Convert a secret key bytes to a bigint secret.
Parameters ​
secret ​
bigint
The secret key secret.
Returns ​
The secret key secret as secret key bytes.
toSecret() ​
statictoSecret(bytes):bigint
Defined in: secret.ts:333
Convert a bigint secret to secret key bytes.
Parameters ​
bytes ​
The secret key bytes
Returns ​
bigint
The secret key bytes as a bigint secret