我有一个小脚本,基本上是从这个测试脚本在bitcoinjs中。中摘取的
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地址,但肯定还有我遗漏的东西。
你能帮我找出我哪里出错了吗?
我探索过的其他资源:
发布于 2021-05-26 18:10:58
回顾一下https://github.com/iancoleman/bip39,我发现我必须指定正确的raven铜币网络规范(并不真正理解这个对象的含义),但是一旦我这样做了,它就完美地工作了。
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());https://stackoverflow.com/questions/67709692
复制相似问题