导出 BIP32 public 密钥(在 Base64 中)

Exporting a BIP32 public key (in Base64)

我正在使用 this BIP32 实现来派生密钥。如何在 Base64 中导出派生的 public 密钥?

var node = bip32js.bip32.fromBase58('<some private key>');
var child = node.derivePath('m/0/0');
var publicKey = child.publicKey(); // This gets the public key for the child
console.log(btoa(publicKey)) // This gives an error since the returned public key is not a string

junderw on Github 回答了这个问题:

publicKey is a Buffer.

publicKey.toString('hex') will turn it into a hex string.

同样,对于Base64,可以使用'base64'。