【问题标题】:How should I properly create a Ripple Paper Wallet using Ripple-lib or an official api?我应该如何使用 Ripple-lib 或官方 API 正确创建 Ripple Paper Wallet?
【发布时间】:2018-01-12 04:03:02
【问题描述】:

我正在尝试使用官方的 Ripple Api,ripple-lib 创建一个纸质钱包。

generateAddress() 接受一些参数。

'use strict';
const RippleAPI = require('ripple-lib').RippleAPI;

const api = new RippleAPI({
  server: 'wss://s1.ripple.com' // Public rippled server
});
api.connect().then(() => {
  return api.generateAddress();
}).then(info => {
  console.log(info);
  console.log('getAccountInfo done');

  /* end custom code -------------------------------------- */
}).then(() => {
  return api.disconnect();
}).then(() => {
  console.log('done and disconnected.');
}).catch(console.error);

这段代码实际上创建了一个密钥和一个“地址”。

{
  secret: 'sheWb..................HRyLhk',
  address: 'rNLJ.......................qu3nbb'
}

好的。现在我已经创建了我的帐户。如果我用 20XRP Reserve 为其提供资金,它将成为一个活跃的 Ripple 账户。耶!

但我不明白:

  • 什么是或如何获取我的公钥?
  • 什么是或如何获得我的主公钥?
  • generateAddress() 方法接受三个参数。此处描述:https://ripple.com/build/rippleapi/#generateaddress 但我不知道如何编写这些参数。我对此感兴趣,因为我认为在第一个参数中,“选项”对象是我可以为密钥定义密码的地方。也许我错了。

有人可以对这些担忧有所了解吗?

编辑: 我现在认为传递给generateAddress() 的选项对象与传递给构造函数RippleApi() 的选项参数相同https://ripple.com/build/rippleapi/#parameters 有人可以确认吗?

【问题讨论】:

    标签: ripple


    【解决方案1】:

    对于纸质钱包,您只需要地址(公共)和秘密(私人):

    https://github.com/Bithomp/xrp-paper-wallet

    其实只有secret就足够了,因为你可以从secret中得到一个address。

    https://github.com/Bithomp/bithomp-tools

    在 Ripple 中,您不必为每个新订单/用户使用新帐户。对于每笔新交易,您都可以使用目标标签。这就是您可以识别客户/订单的方式。 Ripple 还支持密钥轮换,因此如果 主密钥 暴露,您可以禁用它并使用 常规密钥。在最佳实践中,您分配一个常规密钥并使用它在线签署交易,而主密钥始终离线。如果常规密钥暴露,您可以用新的常规密钥替换它。

    在涟漪中,您可以使用 keypair(公钥 + 私钥)或 secret 签署交易。

    你可以在这里https://iancoleman.io/bip39/ 获得涟漪的密钥对

    ripple-lib 的 generateAddress() 为您提供:

    1) 涟漪地址(您的公共地址)以r

    开头

    您可以分享它,它可以用来向您发送付款。 您可以在资源管理器中搜索公共地址。

    例如:https://bithomp.com/explorer/r9fVvKgMMPkBHQ3n28sifxi22zKphwkf8u

    2) secret - 主密钥,将用于签署交易。

    3) 您还可以分配一个常规键 (https://developers.ripple.com/assign-a-regular-key-pair.html)

    Options 只有两个参数:

    • algorithm 字符串,要为其生成地址的数字签名算法。可以是 ecdsa-secp256k1(默认)或 ed25519。

    • 熵数组\整数,用于生成种子的熵。

    希望对你有帮助..

    【讨论】:

      【解决方案2】:

      generateAddress() 方法接受三个参数。描述 在这里:https://ripple.com/build/rippleapi/#generateaddress 但我没有 了解如何编写这些参数。我对此感兴趣 因为我认为在第一个参数中,“选项”对象是 我可以在其中定义密钥的密码。也许我是 错了。

      这里有一些 javascript 代码来演示熵输入到 generateAddress 方法。

      // This functions works on modern browswers, not sure about Node.js. Try https://www.npmjs.com/package/js-sha512 or https://nodejs.org/api/crypto.html
      async function fun_SHA512_array(entropy) {
          'use strict';
      
          // Turns a string into an array of integers.
          // Made possible by https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest
      
          const msgUint8 = new TextEncoder().encode(entropy);                           // encode as (utf-8) Uint8Array
          const hashBuffer = await crypto.subtle.digest('SHA-512', msgUint8);           // hash the message
          const hashArray = Array.from(new Uint8Array(hashBuffer));                     // convert buffer to byte array
          // const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); // convert bytes to hex string
      
          return hashArray;
      }
      
      const str_entropy = "Use a cryptographically strong, randomly created string of characters here.";
      // Or, your passphrase string would go here.
      // Or, you could use a BIP39 Mnemonic but you'd have to remember how you constructed the string. e.g. Did you separate the words with a comma or with a space?
      // Or, on the linux terminal you can use: openssl rand -base64 n
      // Where n = the number of characters you wish to randomly generate. Which are then converted to base64, therefore the amount of characters ends up being more than n.
      
      var array_sha512 = [];
      
      fun_SHA512_array(str_entropy).then(array_sha512 => {
          var obj_new_account = api.generateAddress({"entropy": array_sha512});
          var str_secret = obj_new_account.secret;
          var str_public_address = obj_new_account.address;
      
          console.log(str_secret);
          console.log(str_public_address);
      });
      

      记住,熵就像一粒种子,总是会产生相同的secret和address。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-10
        • 2015-04-13
        • 1970-01-01
        • 1970-01-01
        • 2021-03-23
        相关资源
        最近更新 更多