0

我有一个小脚本,基本上取自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());

它非常适合派生比特币地址(派生路径"m/44'/0'/0'/0/0"),但是当尝试派生任何其他地址时,它似乎不起作用。输出是这样的:

16CzcgCURH83h3cLQ91ZpavDjXSfuNru4c

该地址以 1 开头,而 RVN 地址以 R 开头。

我错误地认为仅通过更改派生路径以匹配 RVN ( 175) 就会生成 Raven 地址,但我肯定还缺少其他东西。

你能帮我弄清楚我哪里出错了吗?

我探索的其他资源:

4

1 回答 1

0

查看https://github.com/iancoleman/bip39 我发现我必须指定正确的 ravencoin 网络规范(不太了解这个对象的含义),但是一旦我这样做了,它就完美地工作了。

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());
于 2021-05-26T18:10:58.150 回答