Account Creation in Wallet
Last updated
async generate(mnemonic: string, derivationPath?: string): Promise<KeyPair> {
const entropy = Buffer.from(mnemonicToEntropy(mnemonic), "hex");
const seed96 = shake256.create({ dkLen: 96 }).update(entropy).digest();
const keys = slh.slh_dsa_shake_256f.keygen(seed96);
const originalPublicKey = Buffer.from(keys.publicKey);
const strippedPubKey = originalPublicKey.subarray(1);
const publicKeyHash = keccak256(strippedPubKey);
const addressBytes = publicKeyHash.slice(-20);
const address = bufferToHex(addressBytes);
return {
address: address.toLowerCase(),
privateKey: bufferToHex(keys.secretKey),
publicKey: bufferToHex(originalPublicKey),
};
}