根据bip39标准,我想在JavaScript中从助记词中获取种子。
我使用以下代码:
我使用以下代码:
function mnemonicToSeed(mnemonic,passphrase){
if (typeof passphrase != 'string') passphrase='';
window.crypto.subtle.importKey(
'raw',
stringToArrayBuffer(mnemonic),
{
name: 'PBKDF2',
},
false,
['deriveKey']
).then((importedKey) => {
crypto.subtle.deriveKey({
name: "PBKDF2",
salt: stringToArrayBuffer('mnemonic'+passphrase),
iterations: 2048,
hash: { name: 'SHA-512' }
},
importedKey,
{
name: 'HMAC',
hash: 'SHA-512',
length: 512
},
true,
['sign']
).then(function(derivedKey) {
console.log('derivedKey: '+derivedKey);
});
});
}
但是最后console.log('derivedKey: '+derivedKey);
的结果是这样的:
derivedKey: [object CryptoKey]
现在如何将derivedKey转换为相应的十六进制字符串种子?