Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hewigovens/1711879ea8a555c0f6368a3a8a782cf8 to your computer and use it in GitHub Desktop.
Save hewigovens/1711879ea8a555c0f6368a3a8a782cf8 to your computer and use it in GitHub Desktop.
generate-slip-0132-test-vectors.js
const bitcoinjs = require('bitcoinjs-lib') // @3.3.2
const bchaddrjs = require('bchaddrjs')
const bip39 = require('bip39')
const clone = require('lodash.clonedeep')
const networks = bitcoinjs.networks
const script = bitcoinjs.script
/*
Bitcoin 0x0488b21e - xpub 0x0488ade4 - xprv P2PKH or P2SH
Bitcoin 0x049d7cb2 - ypub 0x049d7878 - yprv P2WPKH in P2SH
Bitcoin 0x0295b43f - Ypub 0x0295b005 - Yprv P2WSH in P2SH
Bitcoin 0x04b24746 - zpub 0x04b2430c - zprv P2WPKH
Bitcoin 0x02aa7ed3 - Zpub 0x02aa7a99 - Zprv P2WSH
*/
// Default is BIP-44
networks.bitcoin.bip32.outputScript = (pubkey) => {
return script.pubKeyHash.output.encode(
bitcoinjs.crypto.hash160(pubkey))
}
networks.bitcoincash = clone(networks.bitcoin)
// BIP-49 is P2PKH-in-P2SH
networks.bip49 = clone(networks.bitcoin)
networks.bip49.bip32 = {
public: 0x049d7cb2,
private: 0x049d7878,
outputScript: (pubkey) => {
const spendScript = script.witnessPubKeyHash.output.encode(
bitcoinjs.crypto.hash160(pubkey))
return script.scriptHash.output.encode(
bitcoinjs.crypto.hash160(spendScript))
}
}
// BIP-84 is P2WPKH with bech32-encoded addresses
networks.bip84 = clone(networks.bitcoin)
networks.bip84.bip32 = {
public: 0x04b24746,
private: 0x04b2430c,
outputScript: (pubkey) => {
return script.witnessPubKeyHash.output.encode(
bitcoinjs.crypto.hash160(pubkey))
}
}
networks.litecoin = clone(networks.bip84)
networks.litecoin.bech32 = "ltc";
// Entropy: 0x00
const mnemonic = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
const seedHex = bip39.mnemonicToSeedHex(mnemonic)
function printScheme(purpose, coin, network) {
const path = `m/${purpose}'/${coin}'/0'`
const rootNode = bitcoinjs.HDNode.fromSeedHex(seedHex, network)
const accountNode = rootNode.derivePath(path)
const pubkey = accountNode.derive(0).derive(0).getPublicKeyBuffer()
const address = bitcoinjs.address.fromOutputScript(
network.bip32.outputScript(pubkey), network)
console.log(`\n${path}`)
console.log(accountNode.toBase58())
console.log(accountNode.neutered().toBase58())
console.log(`${path}/0/0 address:`)
console.log(address)
if (network == networks.bitcoincash) {
console.log(bchaddrjs.toCashAddress(address))
}
}
printScheme(44, 0, networks.bitcoin)
printScheme(49, 0, networks.bip49)
printScheme(84, 0, networks.bip84)
printScheme(84, 2, networks.litecoin)
printScheme(44, 145, networks.bitcoincash)
{
"name": "generate-slip-0132-test-vectors",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"base-x": {
"version": "3.0.5",
"resolved": "https://registry.npmjs.org/base-x/-/base-x-3.0.5.tgz",
"integrity": "sha512-C3picSgzPSLE+jW3tcBzJoGwitOtazb5B+5YmAxZm2ybmTi9LNgAtDO/jjVEBZwHoXmDBZ9m/IELj3elJVRBcA==",
"requires": {
"safe-buffer": "^5.0.1"
}
},
"bchaddrjs": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/bchaddrjs/-/bchaddrjs-0.3.0.tgz",
"integrity": "sha512-XtOie1INzvGsoXKzOh/CUQ4p98Z/X+MSOV1aqFZZXG8BdZofvlXwtwcNrJDlwdfOqCVCVcFBgLBkuXEOcIQ/0w==",
"requires": {
"bs58check": "^2.1.2",
"cashaddrjs": "^0.2.9"
}
},
"bech32": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/bech32/-/bech32-1.1.3.tgz",
"integrity": "sha512-yuVFUvrNcoJi0sv5phmqc6P+Fl1HjRDRNOOkHY2X/3LBy2bIGNSFx4fZ95HMaXHupuS7cZR15AsvtmCIF4UEyg=="
},
"big-integer": {
"version": "1.6.40",
"resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.40.tgz",
"integrity": "sha512-CjhtJp0BViLzP1ZkEnoywjgtFQXS2pomKjAJtIISTCnuHILkLcAXLdFLG/nxsHc4s9kJfc+82Xpg8WNyhfACzQ=="
},
"bigi": {
"version": "1.4.2",
"resolved": "https://registry.npmjs.org/bigi/-/bigi-1.4.2.tgz",
"integrity": "sha1-nGZalfiLiwj8Bc/XMfVhhZ1yWCU="
},
"bip39": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/bip39/-/bip39-2.5.0.tgz",
"integrity": "sha512-xwIx/8JKoT2+IPJpFEfXoWdYwP7UVAoUxxLNfGCfVowaJE7yg1Y5B1BVPqlUNsBq5/nGwmFkwRJ8xDW4sX8OdA==",
"requires": {
"create-hash": "^1.1.0",
"pbkdf2": "^3.0.9",
"randombytes": "^2.0.1",
"safe-buffer": "^5.0.1",
"unorm": "^1.3.3"
}
},
"bip66": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/bip66/-/bip66-1.1.5.tgz",
"integrity": "sha1-AfqHSHhcpwlV1QESF9GzE5lpyiI=",
"requires": {
"safe-buffer": "^5.0.1"
}
},
"bitcoin-ops": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/bitcoin-ops/-/bitcoin-ops-1.4.1.tgz",
"integrity": "sha512-pef6gxZFztEhaE9RY9HmWVmiIHqCb2OyS4HPKkpc6CIiiOa3Qmuoylxc5P2EkU3w+5eTSifI9SEZC88idAIGow=="
},
"bitcoinjs-lib": {
"version": "3.3.2",
"resolved": "https://registry.npmjs.org/bitcoinjs-lib/-/bitcoinjs-lib-3.3.2.tgz",
"integrity": "sha512-l5qqvbaK8wwtANPf6oEffykycg4383XgEYdia1rI7/JpGf1jfRWlOUCvx5TiTZS7kyIvY4j/UhIQ2urLsvGkzw==",
"requires": {
"bech32": "^1.1.2",
"bigi": "^1.4.0",
"bip66": "^1.1.0",
"bitcoin-ops": "^1.3.0",
"bs58check": "^2.0.0",
"create-hash": "^1.1.0",
"create-hmac": "^1.1.3",
"ecurve": "^1.0.0",
"merkle-lib": "^2.0.10",
"pushdata-bitcoin": "^1.0.1",
"randombytes": "^2.0.1",
"safe-buffer": "^5.0.1",
"typeforce": "^1.11.3",
"varuint-bitcoin": "^1.0.4",
"wif": "^2.0.1"
}
},
"bs58": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/bs58/-/bs58-4.0.1.tgz",
"integrity": "sha1-vhYedsNU9veIrkBx9j806MTwpCo=",
"requires": {
"base-x": "^3.0.2"
}
},
"bs58check": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/bs58check/-/bs58check-2.1.2.tgz",
"integrity": "sha512-0TS1jicxdU09dwJMNZtVAfzPi6Q6QeN0pM1Fkzrjn+XYHvzMKPU3pHVpva+769iNVSfIYWf7LJ6WR+BuuMf8cA==",
"requires": {
"bs58": "^4.0.0",
"create-hash": "^1.1.0",
"safe-buffer": "^5.1.2"
}
},
"cashaddrjs": {
"version": "0.2.9",
"resolved": "https://registry.npmjs.org/cashaddrjs/-/cashaddrjs-0.2.9.tgz",
"integrity": "sha512-DhJF4iAH0/RM3UjHDHKRxzs09YGL9px+oTyizzydanhC7jTyM2aJ+aLKA96vZGTTWayvvr2iDF2l13lpqXiRFg==",
"requires": {
"big-integer": "^1.6.34"
}
},
"cipher-base": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/cipher-base/-/cipher-base-1.0.4.tgz",
"integrity": "sha512-Kkht5ye6ZGmwv40uUDZztayT2ThLQGfnj/T71N/XzeZeo3nf8foyW7zGTsPYkEya3m5f3cAypH+qe7YOrM1U2Q==",
"requires": {
"inherits": "^2.0.1",
"safe-buffer": "^5.0.1"
}
},
"create-hash": {
"version": "1.2.0",
"resolved": "http://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz",
"integrity": "sha512-z00bCGNHDG8mHAkP7CtT1qVu+bFQUPjYq/4Iv3C3kWjTFV10zIjfSoeqXo9Asws8gwSHDGj/hl2u4OGIjapeCg==",
"requires": {
"cipher-base": "^1.0.1",
"inherits": "^2.0.1",
"md5.js": "^1.3.4",
"ripemd160": "^2.0.1",
"sha.js": "^2.4.0"
}
},
"create-hmac": {
"version": "1.1.7",
"resolved": "http://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz",
"integrity": "sha512-MJG9liiZ+ogc4TzUwuvbER1JRdgvUFSB5+VR/g5h82fGaIRWMWddtKBHi7/sVhfjQZ6SehlyhvQYrcYkaUIpLg==",
"requires": {
"cipher-base": "^1.0.3",
"create-hash": "^1.1.0",
"inherits": "^2.0.1",
"ripemd160": "^2.0.0",
"safe-buffer": "^5.0.1",
"sha.js": "^2.4.8"
}
},
"ecurve": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/ecurve/-/ecurve-1.0.6.tgz",
"integrity": "sha512-/BzEjNfiSuB7jIWKcS/z8FK9jNjmEWvUV2YZ4RLSmcDtP7Lq0m6FvDuSnJpBlDpGRpfRQeTLGLBI8H+kEv0r+w==",
"requires": {
"bigi": "^1.1.0",
"safe-buffer": "^5.0.1"
}
},
"hash-base": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.0.4.tgz",
"integrity": "sha1-X8hoaEfs1zSZQDMZprCj8/auSRg=",
"requires": {
"inherits": "^2.0.1",
"safe-buffer": "^5.0.1"
}
},
"inherits": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
},
"lodash.clonedeep": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
"integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8="
},
"md5.js": {
"version": "1.3.5",
"resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz",
"integrity": "sha512-xitP+WxNPcTTOgnTJcrhM0xvdPepipPSf3I8EIpGKeFLjt3PlJLIDG3u8EX53ZIubkb+5U2+3rELYpEhHhzdkg==",
"requires": {
"hash-base": "^3.0.0",
"inherits": "^2.0.1",
"safe-buffer": "^5.1.2"
}
},
"merkle-lib": {
"version": "2.0.10",
"resolved": "https://registry.npmjs.org/merkle-lib/-/merkle-lib-2.0.10.tgz",
"integrity": "sha1-grjbrnXieneFOItz+ddyXQ9vMyY="
},
"pbkdf2": {
"version": "3.0.17",
"resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.0.17.tgz",
"integrity": "sha512-U/il5MsrZp7mGg3mSQfn742na2T+1/vHDCG5/iTI3X9MKUuYUZVLQhyRsg06mCgDBTd57TxzgZt7P+fYfjRLtA==",
"requires": {
"create-hash": "^1.1.2",
"create-hmac": "^1.1.4",
"ripemd160": "^2.0.1",
"safe-buffer": "^5.0.1",
"sha.js": "^2.4.8"
}
},
"pushdata-bitcoin": {
"version": "1.0.1",
"resolved": "http://registry.npmjs.org/pushdata-bitcoin/-/pushdata-bitcoin-1.0.1.tgz",
"integrity": "sha1-FZMdPNlnreUiBvUjqnMxrvfUOvc=",
"requires": {
"bitcoin-ops": "^1.3.0"
}
},
"randombytes": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.0.6.tgz",
"integrity": "sha512-CIQ5OFxf4Jou6uOKe9t1AOgqpeU5fd70A8NPdHSGeYXqXsPe6peOwI0cUl88RWZ6sP1vPMV3avd/R6cZ5/sP1A==",
"requires": {
"safe-buffer": "^5.1.0"
}
},
"ripemd160": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/ripemd160/-/ripemd160-2.0.2.tgz",
"integrity": "sha512-ii4iagi25WusVoiC4B4lq7pbXfAp3D9v5CwfkY33vffw2+pkDjY1D8GaN7spsxvCSx8dkPqOZCEZyfxcmJG2IA==",
"requires": {
"hash-base": "^3.0.0",
"inherits": "^2.0.1"
}
},
"safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
},
"sha.js": {
"version": "2.4.11",
"resolved": "http://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz",
"integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==",
"requires": {
"inherits": "^2.0.1",
"safe-buffer": "^5.0.1"
}
},
"typeforce": {
"version": "1.17.0",
"resolved": "https://registry.npmjs.org/typeforce/-/typeforce-1.17.0.tgz",
"integrity": "sha512-juby+ePzggryLPetNhEuQT5s0Wtj8hw1UvQVpwuosS1JQ2DBo8OXntxVIfxgwSvqjIrYOZE6TVoppcb9OfYiiQ=="
},
"unorm": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/unorm/-/unorm-1.4.1.tgz",
"integrity": "sha1-NkIA1fE2RsqLzURJAnEzVhR5IwA="
},
"varuint-bitcoin": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/varuint-bitcoin/-/varuint-bitcoin-1.1.0.tgz",
"integrity": "sha512-jCEPG+COU/1Rp84neKTyDJQr478/hAfVp5xxYn09QEH0yBjbmPeMfuuQIrp+BUD83hybtYZKhr5elV3bvdV1bA==",
"requires": {
"safe-buffer": "^5.1.1"
}
},
"wif": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/wif/-/wif-2.0.6.tgz",
"integrity": "sha1-CNP1IFbGZnkplyb63g1DKudLRwQ=",
"requires": {
"bs58check": "<3.0.0"
}
}
}
}
{
"name": "generate-slip-0132-test-vectors",
"version": "1.0.0",
"description": "",
"main": "generate-slip-0132-test-vectors.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+ssh://git@gist.github.com/1711879ea8a555c0f6368a3a8a782cf8.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://gist.github.com/1711879ea8a555c0f6368a3a8a782cf8"
},
"homepage": "https://gist.github.com/1711879ea8a555c0f6368a3a8a782cf8",
"dependencies": {
"bchaddrjs": "^0.3.0",
"bip39": "^2.5.0",
"bitcoinjs-lib": "^3.3.2",
"lodash.clonedeep": "^4.5.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment