简体   繁体   English

js中的hd wallet bip44 - 如何为比特币以外的链创建地址?

[英]hd wallet bip44 in js - how to create an address for a chain other than bitcoin?

I have a small script basically taken from this test script in bitcoinjs-lib我有一个小脚本,基本上取自bitcoinjs-lib 中的这个测试脚本

function getAddress(node) {
    const bitcoin = require('bitcoinjs-lib');
    return bitcoin.payments.p2pkh({ pubkey: node.publicKey }).address;
}

function BIP44() {
    /* create a BIP44, rvn, account 0, external address */
    const bip32 = require('bip32');
    const root = bip32.fromSeed(
        Buffer.from(
        'dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd',
        'hex',
        ),
    );
    const childAuto = root.derivePath("m/44'/175'/0'/0/0");
    const childManual = root
        .deriveHardened(44)
        .deriveHardened(175)
        .deriveHardened(0)
        .derive(0)
        .derive(0);
    return getAddress(childAuto);
}
console.log(BIP44());

It works perfectly for deriving a bitcoin address (derivation path "m/44'/0'/0'/0/0" ) but when trying to derive any other address it doesn't seem to work.它非常适合派生比特币地址(派生路径"m/44'/0'/0'/0/0" ),但是当尝试派生任何其他地址时,它似乎不起作用。 The output is this: output 是这样的:

16CzcgCURH83h3cLQ91ZpavDjXSfuNru4c

That address starts with a 1, whereas RVN addresses start with R.该地址以 1 开头,而 RVN 地址以 R 开头。

I mistakenly assumed that merely by changing the derivation path to match RVN ( 175 ) it would generate Raven addresses, but there must be something else I'm missing.我错误地认为仅通过更改派生路径以匹配 RVN ( 175 ) 就会生成 Raven 地址,但我肯定还缺少其他东西。

Can you help me figure out where I'm going wrong?你能帮我弄清楚我哪里出错了吗?

Other resources I've explored:我探索的其他资源:

looking over https://github.com/iancoleman/bip39 I found I had to specify the correct ravencoin network specifications (don't really understand what this object means) but once I did, it worked perfectly.查看https://github.com/iancoleman/bip39我发现我必须指定正确的 ravencoin 网络规范(真的不明白这个 object 是什么意思)但是一旦我这样做了,它就完美地工作了。

function getAddress(node, network) {
    const bitcoin = require('bitcoinjs-lib');
    return bitcoin.payments.p2pkh({ pubkey: node.publicKey, network }).address;
}

function getNetwork() {
    /* https://github.com/iancoleman/bip39/blob/c4f0c2908faab1452937e50a7d3a400fed42a0a8/src/js/bitcoinjs-extensions.js */
    return {
        messagePrefix: '\x16Raven Signed Message:\n',
        bip32: {
          public: 0x0488B21E,
          private: 0x0488ADE4,
        },
        pubKeyHash: 0x3c,
        scriptHash: 0x7a,
        wif: 0x80,
    };
}


function BIP44() {
    /* create a BIP44, rvn, account 0, external address */
    const bip32 = require('bip32');
    const root = bip32.fromSeed(
        Buffer.from(
        'dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd',
        'hex',
        ),
    );
    const childAuto = root.derivePath("m/44'/175'/0'/0/0");
    const childManual = root
        .deriveHardened(44)
        .deriveHardened(175)
        .deriveHardened(0)
        .derive(0)
        .derive(0);
    return getAddress(childAuto, getNetwork());
    
}
console.log(BIP44());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM