Created
November 29, 2020 21:50
-
-
Save marceloneil/4a5511af978e0a763a6f5f8602faf037 to your computer and use it in GitHub Desktop.
Change xpub prefix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const bs58 = require('bs58') | |
const shajs = require('sha.js') | |
const start = "xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8" | |
const startBuf = bs58.decode(start) | |
// overwrite with new base58 key prefix. these prefixes can be found in chainparams.cpp for bitcoin forks: | |
// https://github.com/bitcoin/bitcoin/blob/7ae86b3c6845873ca96650fc69beb4ae5285c801/src/chainparams.cpp#L134 | |
// https://github.com/dogecoin/dogecoin/blob/0b46a40ed125d7bf4b5a485b91350bc8bdc48fc8/src/chainparams.cpp#L170 | |
const prefix = Buffer.from("02facafd", "hex") | |
prefix.copy(startBuf, 0, 0, 5) | |
// regenerate checksum | |
const dataBuf = startBuf.slice(0, 78) | |
let checksum = shajs('sha256').update(dataBuf).digest() | |
checksum = shajs('sha256').update(checksum).digest() | |
checksum = checksum.slice(0, 4) | |
// concat checksum | |
const endBuf = Buffer.concat([dataBuf, checksum], 82) | |
const end = bs58.encode(endBuf) | |
console.log(end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment