@did-btc1/method / GeneralUtils
Class: GeneralUtils
Defined in: packages/method/src/utils/general.ts:14
Static class of general utility functions for the did-btc1 spec implementation GeneralUtils
Constructors
Constructor
> new GeneralUtils(): GeneralUtils
Returns
GeneralUtils
Methods
bigintToBuffer()
> static
bigintToBuffer(value
): Buffer
Defined in: packages/method/src/utils/general.ts:37
Converts a bigint to a buffer
Parameters
value
bigint
The bigint to convert
Returns
Buffer
The buffer representation of the bigint
deriveChildKey()
> static
deriveChildKey(hdkey
, path
): HDKey
Defined in: packages/method/src/utils/general.ts:194
Derives a child key from an HDKey
Parameters
hdkey
HDKey
The HDKey to derive the child key from
path
string
The path to derive the child key from
Returns
HDKey
A Promise resolving to the child key
Throws
Error if the child key cannot be derived
encode()
> static
encode(xOnlyKeyBytes
): string
Defined in: packages/method/src/utils/general.ts:20
Helper function to encode a secp256k1 key in SchnorrSecp256k1 Multikey Format
Parameters
xOnlyKeyBytes
Bytes
Returns
string
generateCompressedSecp256k1KeyPair()
> static
generateCompressedSecp256k1KeyPair(): object
Defined in: packages/method/src/utils/general.ts:61
Returns
object
privateKey
> privateKey: Bytes
publicKey
> publicKey: Bytes
generateHdWallet()
> static
generateHdWallet(): Promise
<HdWallet
>
Defined in: packages/method/src/utils/general.ts:47
Generates a new mnemonic phrase and HD wallet
Returns
Promise
<HdWallet
>
Promise resolving to a new hdwallet object w/ mnemonic and hdkey
Throws
if the public key bytes cannot be derived
recoverHdChildFromMnemonic()
> static
recoverHdChildFromMnemonic(mnemonic
, path
): Promise
<Uint8Array
<ArrayBufferLike
>>
Defined in: packages/method/src/utils/general.ts:172
Recovers an HDKey from a mnemonic phrase
Parameters
mnemonic
string
The mnemonic phrase to recover the HDKey from
path
string
The path to derive the child key from
Returns
Promise
<Uint8Array
<ArrayBufferLike
>>
Promise resolving to the recovered private key bytes
Throws
if the HDKey cannot be recovered
recoverHdWallet()
> static
recoverHdWallet(mnemonic
, seed?
): Promise
<HDKey
>
Defined in: packages/method/src/utils/general.ts:76
Recovers an HDKey from a mnemonic phrase
Parameters
mnemonic
string
The mnemonic phrase to recover the HDKey from
seed?
Uint8Array
<ArrayBufferLike
>
Optional seed to recover the HDKey from
Returns
Promise
<HDKey
>
Promise resolving to the recovered HDKey
Throws
Error if the HDKey cannot be recovered
recoverRawPrivateKey()
> static
recoverRawPrivateKey(entropy
): Uint8Array
Defined in: packages/method/src/utils/general.ts:119
Recovers a secp256k1 privateKey from its original entropy
Parameters
entropy
Uint8Array
The entropy to recover the privateKey from
Returns
Uint8Array
The recovered privateKey
Throws
if the privateKey cannot be recovered
recoverTweakedRawPrivateKey()
> static
recoverTweakedRawPrivateKey(xorEntropy
, salt
): Uint8Array
Defined in: packages/method/src/utils/general.ts:95
Recovers a secp256k1 privateKey from its original entropy
Parameters
xorEntropy
Uint8Array
The original entropy to recover the privateKey from
salt
Uint8Array
The salt used to tweak the privateKey
Returns
Uint8Array
The recovered privateKey
Throws
if the privateKey cannot be recovered
XNOR()
> static
XNOR(tweakedEntropy
, salt
): Uint8Array
Defined in: packages/method/src/utils/general.ts:157
Untweak the entropy with a salt using XNOR
Parameters
tweakedEntropy
Uint8Array
The tweaked entropy to untweak
salt
Uint8Array
The salt to untweak the entropy with
Returns
Uint8Array
The original entropy
XOR()
> static
XOR(entropy
, salt
): Uint8Array
Defined in: packages/method/src/utils/general.ts:142
Tweak the entropy with a salt using XOR
Parameters
entropy
Uint8Array
The entropy to tweak
salt
Uint8Array
The salt to tweak the entropy with
Returns
Uint8Array
The tweaked entropy