使用 NEAR Lib 生成密钥对

Generate keypair using NEAR Lib

我当前创建密钥对的代码片段是

const nearLib = require("nearlib");

const keyRandom = nearLib.utils.KeyPairEd25519.fromRandom(); 
console.log(keyRandom);
console.log(keyRandom.getPublicKey());

我的密钥对的 public 密钥的输出是

PublicKey {
  keyType: 0,
  data: Uint8Array [
     86,  17,  27, 168, 244, 140, 239, 176,
    142, 254, 255, 212, 141, 228,  99, 185,
     50, 153, 127, 160, 174,  91, 203,  42,
     84,   0, 187,  25,   6, 138, 241,  84
  ]
}

这到底是什么?期待一个 base 58 public 键,而不是 Uint8Array,我可以将它转换为 base58 吗?不确定如何在此处进行或为什么以这种方式显示。

只需在 returned public 键上使用 .toString()。类似于:

console.log(keyRandom.publicKey.toString());

这将 return 密钥作为 base58 编码字符串。