@did-btc1/keypair / SecretKey
Class: SecretKey
Defined in: secret.ts:79
Encapsulates a secp256k1 secret key Provides get methods for different formats (raw, secret, point). Provides helpers methods for comparison, serialization and publicKey generation. SecretKey
Implements
Constructors
Constructor
> new SecretKey(entropy
): SecretKey
Defined in: secret.ts:94
Instantiates an instance of SecretKey.
Parameters
entropy
Entropy
bytes (Uint8Array) or secret (bigint)
Returns
SecretKey
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:139
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(): Hex
Defined in: secret.ts:159
Returns the raw secret key as a hex string.
Returns
Hex
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:169
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:149
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(): Bytes
Defined in: secret.ts:212
Computes the public key from the secret key bytes.
Returns
Bytes
The computed public key
Implementation of
encode()
> encode(): string
Defined in: secret.ts:178
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:203
Checks if this secret key is equal to another.
Parameters
other
SecretKey
The other secret key
Returns
boolean
True if the private keys are equal, false otherwise
Implementation of
isValid()
> isValid(): boolean
Defined in: secret.ts:251
Checks if the secret key is valid.
Returns
boolean
True if the secret key is valid, false otherwise
Implementation of
isValidPair()
> isValidPair(pk
): boolean
Defined in: secret.ts:260
Checks if the public key is a valid secp256k1 point.
Parameters
pk
The public key to validate
Returns
boolean
True if the public key is valid, false otherwise
json()
> json(): SecretKeyObject
Defined in: secret.ts:239
Converts the secret key to a JSON object.
Returns
SecretKeyObject
The secret key as a JSON object
Implementation of
decode()
> static
decode(multibase
): Bytes
Defined in: secret.ts:275
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
Bytes
The decoded secret key.
fromJSON()
> static
fromJSON(json
): SecretKey
Defined in: secret.ts:310
Creates a SecretKey object from a JSON object.
Parameters
json
SecretKeyObject
The JSON object containing the secret key bytes
Returns
SecretKey
A new SecretKey object
fromSecret()
> static
fromSecret(secret
): SecretKey
Defined in: secret.ts:367
Creates a new SecretKey object from a bigint secret.
Parameters
secret
bigint
The secret bigint
Returns
SecretKey
A new SecretKey object
generate()
> static
generate(): SecretKey
Defined in: secret.ts:393
Creates a new SecretKey from random secret key bytes.
Returns
SecretKey
A new SecretKey object
getPublicKey()
> static
getPublicKey(bytes
): Bytes
Defined in: secret.ts:406
Generates a public key from the given secret key bytes.
Parameters
bytes
Bytes
The secret key bytes
Returns
Bytes
The computed public key bytes
random()
> static
random(): Bytes
Defined in: secret.ts:380
Generates random secret key bytes.
Returns
Bytes
Uint8Array of 32 random bytes.
toBytes()
> static
toBytes(secret
): Bytes
Defined in: secret.ts:345
Convert a secret key bytes to a bigint secret.
Parameters
secret
bigint
The secret key secret.
Returns
Bytes
The secret key secret as secret key bytes.
toKeyPair()
> static
toKeyPair(bytes
): SchnorrKeyPair
Defined in: secret.ts:320
Converts a SecretKey or KeyBytes to a Pair.
Parameters
bytes
Bytes
Returns
The SchnorrKeyPair object containing the public and private keys
Throws
If the secret key is not valid
toSecret()
> static
toSecret(bytes
): bigint
Defined in: secret.ts:336
Convert a bigint secret to secret key bytes.
Parameters
bytes
Bytes
The secret key bytes
Returns
bigint
The secret key bytes as a bigint secret