sed -i 's/ var / const /', with const->let fixes
This commit is contained in:
parent
91b8823aa8
commit
a5db0a4e44
46 changed files with 776 additions and 769 deletions
test/integration
|
@ -15,40 +15,40 @@ function getAddress (node, network) {
|
|||
|
||||
describe('bitcoinjs-lib (BIP32)', function () {
|
||||
it('can import a BIP32 testnet xpriv and export to WIF', function () {
|
||||
var xpriv = 'tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK'
|
||||
var node = bip32.fromBase58(xpriv, bitcoin.networks.testnet)
|
||||
const xpriv = 'tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK'
|
||||
const node = bip32.fromBase58(xpriv, bitcoin.networks.testnet)
|
||||
|
||||
assert.equal(node.toWIF(), 'cQfoY67cetFNunmBUX5wJiw3VNoYx3gG9U9CAofKE6BfiV1fSRw7')
|
||||
})
|
||||
|
||||
it('can export a BIP32 xpriv, then import it', function () {
|
||||
var mnemonic = 'praise you muffin lion enable neck grocery crumble super myself license ghost'
|
||||
var seed = bip39.mnemonicToSeed(mnemonic)
|
||||
var node = bip32.fromSeed(seed)
|
||||
var string = node.toBase58()
|
||||
var restored = bip32.fromBase58(string)
|
||||
const mnemonic = 'praise you muffin lion enable neck grocery crumble super myself license ghost'
|
||||
const seed = bip39.mnemonicToSeed(mnemonic)
|
||||
const node = bip32.fromSeed(seed)
|
||||
const string = node.toBase58()
|
||||
const restored = bip32.fromBase58(string)
|
||||
|
||||
assert.equal(getAddress(node), getAddress(restored)) // same public key
|
||||
assert.equal(node.toWIF(), restored.toWIF()) // same private key
|
||||
})
|
||||
|
||||
it('can export a BIP32 xpub', function () {
|
||||
var mnemonic = 'praise you muffin lion enable neck grocery crumble super myself license ghost'
|
||||
var seed = bip39.mnemonicToSeed(mnemonic)
|
||||
var node = bip32.fromSeed(seed)
|
||||
var string = node.neutered().toBase58()
|
||||
const mnemonic = 'praise you muffin lion enable neck grocery crumble super myself license ghost'
|
||||
const seed = bip39.mnemonicToSeed(mnemonic)
|
||||
const node = bip32.fromSeed(seed)
|
||||
const string = node.neutered().toBase58()
|
||||
|
||||
assert.equal(string, 'xpub661MyMwAqRbcGhVeaVfEBA25e3cP9DsJQZoE8iep5fZSxy3TnPBNBgWnMZx56oreNc48ZoTkQfatNJ9VWnQ7ZcLZcVStpaXLTeG8bGrzX3n')
|
||||
})
|
||||
|
||||
it('can create a BIP32, bitcoin, account 0, external address', function () {
|
||||
var path = "m/0'/0/0"
|
||||
var root = bip32.fromSeed(Buffer.from('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd', 'hex'))
|
||||
const path = "m/0'/0/0"
|
||||
const root = bip32.fromSeed(Buffer.from('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd', 'hex'))
|
||||
|
||||
var child1 = root.derivePath(path)
|
||||
const child1 = root.derivePath(path)
|
||||
|
||||
// option 2, manually
|
||||
var child1b = root.deriveHardened(0)
|
||||
const child1b = root.deriveHardened(0)
|
||||
.derive(0)
|
||||
.derive(0)
|
||||
|
||||
|
@ -57,12 +57,12 @@ describe('bitcoinjs-lib (BIP32)', function () {
|
|||
})
|
||||
|
||||
it('can create a BIP44, bitcoin, account 0, external address', function () {
|
||||
var root = bip32.fromSeed(Buffer.from('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd', 'hex'))
|
||||
const root = bip32.fromSeed(Buffer.from('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd', 'hex'))
|
||||
|
||||
var child1 = root.derivePath("m/44'/0'/0'/0/0")
|
||||
const child1 = root.derivePath("m/44'/0'/0'/0/0")
|
||||
|
||||
// option 2, manually
|
||||
var child1b = root.deriveHardened(44)
|
||||
const child1b = root.deriveHardened(44)
|
||||
.deriveHardened(0)
|
||||
.deriveHardened(0)
|
||||
.derive(0)
|
||||
|
@ -73,29 +73,29 @@ describe('bitcoinjs-lib (BIP32)', function () {
|
|||
})
|
||||
|
||||
it('can create a BIP49, bitcoin testnet, account 0, external address', function () {
|
||||
var mnemonic = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
|
||||
var seed = bip39.mnemonicToSeed(mnemonic)
|
||||
var root = bip32.fromSeed(seed)
|
||||
const mnemonic = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
|
||||
const seed = bip39.mnemonicToSeed(mnemonic)
|
||||
const root = bip32.fromSeed(seed)
|
||||
|
||||
var path = "m/49'/1'/0'/0/0"
|
||||
var child = root.derivePath(path)
|
||||
const path = "m/49'/1'/0'/0/0"
|
||||
const child = root.derivePath(path)
|
||||
|
||||
var keyhash = bitcoin.crypto.hash160(child.publicKey)
|
||||
var scriptSig = bitcoin.script.witnessPubKeyHash.output.encode(keyhash)
|
||||
var addressBytes = bitcoin.crypto.hash160(scriptSig)
|
||||
var outputScript = bitcoin.script.scriptHash.output.encode(addressBytes)
|
||||
var address = bitcoin.address.fromOutputScript(outputScript, bitcoin.networks.testnet)
|
||||
const keyhash = bitcoin.crypto.hash160(child.publicKey)
|
||||
const scriptSig = bitcoin.script.witnessPubKeyHash.output.encode(keyhash)
|
||||
const addressBytes = bitcoin.crypto.hash160(scriptSig)
|
||||
const outputScript = bitcoin.script.scriptHash.output.encode(addressBytes)
|
||||
const address = bitcoin.address.fromOutputScript(outputScript, bitcoin.networks.testnet)
|
||||
|
||||
assert.equal(address, '2Mww8dCYPUpKHofjgcXcBCEGmniw9CoaiD2')
|
||||
})
|
||||
|
||||
it('can use BIP39 to generate BIP32 addresses', function () {
|
||||
// var mnemonic = bip39.generateMnemonic()
|
||||
var mnemonic = 'praise you muffin lion enable neck grocery crumble super myself license ghost'
|
||||
const mnemonic = 'praise you muffin lion enable neck grocery crumble super myself license ghost'
|
||||
assert(bip39.validateMnemonic(mnemonic))
|
||||
|
||||
var seed = bip39.mnemonicToSeed(mnemonic)
|
||||
var root = bip32.fromSeed(seed)
|
||||
const seed = bip39.mnemonicToSeed(mnemonic)
|
||||
const root = bip32.fromSeed(seed)
|
||||
|
||||
// receive addresses
|
||||
assert.strictEqual(getAddress(root.derivePath("m/0'/0/0")), '1AVQHbGuES57wD68AJi7Gcobc3RZrfYWTC')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue