Commit 66ed8cf8 authored by Zhenzhen Zhan's avatar Zhenzhen Zhan
Browse files

Start doing address prefix change

parent eb0b3864
Pipeline #632 failed with stages
......@@ -459,7 +459,8 @@ Address.prototype.isPayToScriptHash = function() {
* @returns {Buffer} Bitcoin address buffer
*/
Address.prototype.toBuffer = function() {
var version = new Buffer([this.network[this.type]]);
var prefixPropName = this.type === 'scripthash' ? 'scriptAddressPrefix' : 'pubkeyAddressPrefix';
var version = this.network[prefixPropName];
var buf = Buffer.concat([version, this.hashBuffer]);
return buf;
};
......
......@@ -54,8 +54,10 @@ function get(arg, keys) {
* @param {Object} data
* @param {string} data.name - The name of the network
* @param {string} data.alias - The aliased name of the network
* @param {Buffer} data.pubkeyAddressPrefix - The publickey address prefix
* @param {Number} data.pubkeyhash - The publickey hash prefix
* @param {Number} data.privatekey - The privatekey prefix
* @param {Buffer} data.scriptAddressPrefix - The script address prefix
* @param {Number} data.scripthash - The scripthash prefix
* @param {Number} data.xpubkey - The extended public key magic
* @param {Number} data.xprivkey - The extended private key magic
......@@ -71,8 +73,10 @@ function addNetwork(data) {
JSUtil.defineImmutable(network, {
name: data.name,
alias: data.alias,
pubkeyAddressPrefix: data.pubkeyAddressPrefix,
pubkeyhash: data.pubkeyhash,
privatekey: data.privatekey,
scriptAddressPrefix: data.scriptAddressPrefix,
scripthash: data.scripthash,
xpubkey: data.xpubkey,
xprivkey: data.xprivkey
......@@ -129,8 +133,10 @@ function removeNetwork(network) {
addNetwork({
name: 'livenet',
alias: 'mainnet',
pubkeyAddressPrefix: Buffer.from([0x01, 0x75, 0x07]), // represents "CRW" after converting to base58
pubkeyhash: 0x00,
privatekey: 0x80,
scriptAddressPrefix: Buffer.from([0x01, 0x74, 0xf1]), // represents "CRM" after converting to base58
scripthash: 0x1c,
xpubkey: 0x0488b21e,
xprivkey: 0x0488ade4,
......@@ -158,8 +164,10 @@ var livenet = get('livenet');
addNetwork({
name: 'testnet',
alias: 'regtest',
pubkeyAddressPrefix: Buffer.from([0x01, 0x7a, 0xcd, 0x67]), // represents "tCRW" after converting to base58
pubkeyhash: 0x6f,
privatekey: 0xef,
scriptAddressPrefix: Buffer.from([0x01, 0x7a, 0xcd, 0x51]), // represents "tCRM" after converting to base58
scripthash: 0xc4,
xpubkey: 0x043587cf,
xprivkey: 0x04358394
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment