js 中的高清钱包 bip44 - 如何为比特币以外的链创建地址?
hd wallet bip44 in js - how to create an address for a chain other than bitcoin?
我有一个基本上取自this test script in 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 地址,但一定还有其他我遗漏的东西。
你能帮我找出我哪里出错了吗?
我探索过的其他资源:
- https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
- https://github.com/satoshilabs/slips/blob/master/slip-0044.md
- https://medium.com/@harshagoli/hd-wallets-explained-from-high-level-to-nuts-and-bolts-9a41545f5b0
- https://github.com/topics/bip44
- How to validate HD wallet address to match BIP44
俯瞰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());
我有一个基本上取自this test script in 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 地址,但一定还有其他我遗漏的东西。
你能帮我找出我哪里出错了吗?
我探索过的其他资源:
- https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
- https://github.com/satoshilabs/slips/blob/master/slip-0044.md
- https://medium.com/@harshagoli/hd-wallets-explained-from-high-level-to-nuts-and-bolts-9a41545f5b0
- https://github.com/topics/bip44
- How to validate HD wallet address to match BIP44
俯瞰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());