diff --git a/src/address.js b/src/address.js index 9a010dd39..7de6d5d58 100644 --- a/src/address.js +++ b/src/address.js @@ -1,7 +1,7 @@ var base58 = require('./base58') var base58check = require('./base58check') var convert = require('./convert') -var mainnet = require('./network').mainnet.addressVersion +var bitcoin = require('./network').bitcoin.pubKeyHash function Address(bytes, version) { if (!(this instanceof Address)) { @@ -21,7 +21,7 @@ function Address(bytes, version) { } else if (bytes.length <= 40) { this.hash = convert.hexToBytes(bytes) - this.version = version || mainnet + this.version = version || bitcoin } else { throw new Error('Invalid or unrecognized input') @@ -29,7 +29,7 @@ function Address(bytes, version) { } else { this.hash = bytes - this.version = version || mainnet + this.version = version || bitcoin } } diff --git a/src/eckey.js b/src/eckey.js index 6c738775b..0ed6180d2 100644 --- a/src/eckey.js +++ b/src/eckey.js @@ -30,6 +30,7 @@ ECKey.prototype.import = function (input, compressed) { input instanceof ECKey ? input.priv : input instanceof BigInteger ? input.mod(ecparams.getN()) : Array.isArray(input) ? fromBin(input.slice(0, 32)) + : Buffer.isBuffer(input) ? fromBin(input.slice(0, 32)) : typeof input != "string" ? null : input.length == 44 ? fromBin(convert.base64ToBytes(input)) : input.length == 51 && input[0] == '5' ? fromBin(base58check.decode(input).payload) @@ -74,7 +75,7 @@ ECKey.version_bytes = { } ECKey.prototype.toWif = function(version) { - version = version || Network.mainnet.addressVersion + version = version || Network.bitcoin.pubKeyHash return base58check.encode(this.toBytes(), ECKey.version_bytes[version]) } @@ -136,6 +137,7 @@ ECPubKey.prototype.import = function(input, compressed) { : input instanceof ECPubKey ? input.pub : typeof input == "string" ? decode(convert.hexToBytes(input)) : Array.isArray(input) ? decode(input) + : Buffer.isBuffer(input) ? decode(input) : null assert(this.pub !== null) @@ -169,7 +171,7 @@ ECPubKey.prototype.toBin = function(compressed) { } ECPubKey.prototype.toWif = function(version) { - version = version || Network.mainnet.addressVersion + version = version || Network.bitcoin.pubKeyHash return base58check.encode(this.toBytes(), version) } @@ -177,7 +179,7 @@ ECPubKey.prototype.toWif = function(version) { ECPubKey.prototype.toString = ECPubKey.prototype.toHex ECPubKey.prototype.getAddress = function(version) { - version = version || Network.mainnet.addressVersion + version = version || Network.bitcoin.pubKeyHash return new Address(crypto.hash160(this.toBytes()), version) } diff --git a/src/hdwallet.js b/src/hdwallet.js index 627611127..4655e74f5 100644 --- a/src/hdwallet.js +++ b/src/hdwallet.js @@ -1,32 +1,37 @@ -var Address = require('./address') var assert = require('assert') var base58 = require('./base58') var convert = require('./convert') + +var Address = require('./address') +var BigInteger = require('./jsbn/jsbn') var CJS = require('crypto-js') var crypto = require('./crypto') var ECKey = require('./eckey').ECKey var ECPubKey = require('./eckey').ECPubKey -var format = require('util').format var Network = require('./network') +var sec = require('./jsbn/sec') +var ecparams = sec("secp256k1") + function HmacSHA512(buffer, secret) { var words = convert.bytesToWordArray(buffer) var hash = CJS.HmacSHA512(words, secret) - return convert.wordArrayToBytes(hash) + return new Buffer(convert.wordArrayToBytes(hash)) } -function HDWallet(seed, network) { - if (seed === undefined) return; +function HDWallet(seed, netstr) { + if (seed == undefined) return; // FIXME: Boo, should be stricter var I = HmacSHA512(seed, 'Bitcoin seed') this.chaincode = I.slice(32) - this.network = network || 'mainnet' + this.network = netstr || 'bitcoin' + if(!Network.hasOwnProperty(this.network)) { throw new Error("Unknown network: " + this.network) } - this.priv = new ECKey(I.slice(0, 32).concat([1]), true) + this.priv = new ECKey(I.slice(0, 32), true) this.pub = this.priv.getPub() this.index = 0 this.depth = 0 @@ -35,16 +40,8 @@ function HDWallet(seed, network) { HDWallet.HIGHEST_BIT = 0x80000000 HDWallet.LENGTH = 78 -function arrayEqual(a, b) { - return !(a < b || a > b) -} - HDWallet.fromSeedHex = function(hex, network) { - return new HDWallet(convert.hexToBytes(hex), network) -} - -HDWallet.fromSeedString = function(string, network) { - return new HDWallet(convert.stringToBytes(string), network) + return new HDWallet(new Buffer(hex, 'hex'), network) } HDWallet.fromBase58 = function(string) { @@ -57,37 +54,27 @@ HDWallet.fromBase58 = function(string) { assert.deepEqual(newChecksum, checksum) assert.equal(payload.length, HDWallet.LENGTH) - return HDWallet.fromBytes(payload) + return HDWallet.fromBuffer(payload) } HDWallet.fromHex = function(input) { - return HDWallet.fromBytes(convert.hexToBytes(input)) + return HDWallet.fromBuffer(new Buffer(input, 'hex')) } -HDWallet.fromBytes = function(input) { - // This 78 byte structure can be encoded like other Bitcoin data in Base58. (+32 bits checksum) - if (input.length != HDWallet.LENGTH) { - throw new Error(format('Invalid input length, %s. Expected %s.', input.length, HDWallet.LENGTH)) - } - - // FIXME: transitionary fix - if (Buffer.isBuffer(input)) { - input = Array.prototype.map.bind(input, function(x) { return x })() - } +HDWallet.fromBuffer = function(input) { + assert(input.length === HDWallet.LENGTH) var hd = new HDWallet() - // 4 byte: version bytes (mainnet: 0x0488B21E public, 0x0488ADE4 private - // testnet: 0x043587CF public, 0x04358394 private) - var versionBytes = input.slice(0, 4) - var versionWord = convert.bytesToWords(versionBytes)[0] - var type + // 4 byte: version bytes + var version = input.readUInt32BE(0) + var type for(var name in Network) { var network = Network[name] - for(var t in network.hdVersions) { - if (versionWord != network.hdVersions[t]) continue + for(var t in network.bip32) { + if (version != network.bip32[t]) continue type = t hd.network = name @@ -95,19 +82,21 @@ HDWallet.fromBytes = function(input) { } if (!hd.network) { - throw new Error(format('Could not find version %s', convert.bytesToHex(versionBytes))) + throw new Error('Could not find version ' + version.toString(16)) } // 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, ... - hd.depth = input[4] + hd.depth = input.readUInt8(4) // 4 bytes: the fingerprint of the parent's key (0x00000000 if master key) - hd.parentFingerprint = input.slice(5, 9) - assert((hd.depth === 0) == arrayEqual(hd.parentFingerprint, [0, 0, 0, 0])) + hd.parentFingerprint = input.readUInt32BE(5) + if (hd.depth === 0) { + assert(hd.parentFingerprint === 0x00000000) + } // 4 bytes: child number. This is the number i in xi = xpar/i, with xi the key being serialized. // This is encoded in MSB order. (0x00000000 if master key) - hd.index = convert.bytesToNum(input.slice(9, 13).reverse()) + hd.index = input.readUInt32BE(9) assert(hd.depth > 0 || hd.index === 0) // 32 bytes: the chain code @@ -116,7 +105,7 @@ HDWallet.fromBytes = function(input) { // 33 bytes: the public key or private key data (0x02 + X or 0x03 + X for // public keys, 0x00 + k for private keys) if (type == 'priv') { - hd.priv = new ECKey(input.slice(46, 78).concat([1]), true) + hd.priv = new ECKey(input.slice(46, 78), true) hd.pub = hd.priv.getPub() } else { hd.pub = new ECPubKey(input.slice(45, 78), true) @@ -130,63 +119,57 @@ HDWallet.prototype.getIdentifier = function() { } HDWallet.prototype.getFingerprint = function() { - return Array.prototype.slice.call(this.getIdentifier(), 0, 4) + return this.getIdentifier().slice(0, 4) } HDWallet.prototype.getAddress = function() { return new Address(crypto.hash160(this.pub.toBytes()), this.getKeyVersion()) } -HDWallet.prototype.toBytes = function(priv) { - var buffer = [] - +HDWallet.prototype.toBuffer = function(priv) { // Version - // 4 byte: version bytes (mainnet: 0x0488B21E public, 0x0488ADE4 private; testnet: 0x043587CF public, - // 0x04358394 private) - var version = Network[this.network].hdVersions[priv ? 'priv' : 'pub'] - var vBytes = convert.wordsToBytes([version]) + var version = Network[this.network].bip32[priv ? 'priv' : 'pub'] + var buffer = new Buffer(HDWallet.LENGTH) - buffer = buffer.concat(vBytes) - assert.equal(buffer.length, 4) + // 4 bytes: version bytes + buffer.writeUInt32BE(version, 0) // Depth // 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, .... - buffer.push(this.depth) - assert.equal(buffer.length, 4 + 1) + buffer.writeUInt8(this.depth, 4) // 4 bytes: the fingerprint of the parent's key (0x00000000 if master key) - buffer = buffer.concat(this.depth ? this.parentFingerprint : [0, 0, 0, 0]) - assert.equal(buffer.length, 4 + 1 + 4) + var fingerprint = this.depth ? this.parentFingerprint : 0x00000000 + buffer.writeUInt32BE(fingerprint, 5) // 4 bytes: child number. This is the number i in xi = xpar/i, with xi the key being serialized. - // This is encoded in MSB order. (0x00000000 if master key) - buffer = buffer.concat(convert.numToBytes(this.index, 4).reverse()) - assert.equal(buffer.length, 4 + 1 + 4 + 4) + // This is encoded in Big endian. (0x00000000 if master key) + buffer.writeUInt32BE(this.index, 9) // 32 bytes: the chain code - buffer = buffer.concat(this.chaincode) - assert.equal(buffer.length, 4 + 1 + 4 + 4 + 32) + this.chaincode.copy(buffer, 13) // 33 bytes: the public key or private key data - // (0x02 + X or 0x03 + X for public keys, 0x00 + k for private keys) if (priv) { assert(this.priv, 'Cannot serialize to private without private key') - buffer.push(0) - buffer = buffer.concat(this.priv.toBytes().slice(0, 32)) + + // 0x00 + k for private keys + buffer.writeUInt8(0, 45) + new Buffer(this.priv.toBytes()).copy(buffer, 46) } else { - buffer = buffer.concat(this.pub.toBytes(true)) + + // X9.62 encoding for public keys + new Buffer(this.pub.toBytes()).copy(buffer, 45) } return buffer } - HDWallet.prototype.toHex = function(priv) { - var bytes = this.toBytes(priv) - return convert.bytesToHex(bytes) + return this.toBuffer(priv).toString('hex') } HDWallet.prototype.toBase58 = function(priv) { - var buffer = new Buffer(this.toBytes(priv)) + var buffer = new Buffer(this.toBuffer(priv)) var checksum = crypto.hash256(buffer).slice(0, 4) return base58.encode(Buffer.concat([ @@ -196,47 +179,58 @@ HDWallet.prototype.toBase58 = function(priv) { } HDWallet.prototype.derive = function(i) { - var I - , iBytes = convert.numToBytes(i, 4).reverse() + var iBytes = convert.numToBytes(i, 4).reverse() , cPar = this.chaincode , usePriv = i >= HDWallet.HIGHEST_BIT , SHA512 = CJS.algo.SHA512 + var I if (usePriv) { assert(this.priv, 'Private derive on public key') // If 1, private derivation is used: // let I = HMAC-SHA512(Key = cpar, Data = 0x00 || kpar || i) [Note:] var kPar = this.priv.toBytes().slice(0, 32) + + // FIXME: Dislikes buffers I = HmacFromBytesToBytes(SHA512, [0].concat(kPar, iBytes), cPar) } else { // If 0, public derivation is used: // let I = HMAC-SHA512(Key = cpar, Data = χ(kpar*G) || i) - var KPar = this.pub.toBytes(true) + var KPar = this.pub.toBytes() + + // FIXME: Dislikes buffers I = HmacFromBytesToBytes(SHA512, KPar.concat(iBytes), cPar) } + // FIXME: Boo, CSJ.algo.SHA512 uses byte arrays + I = new Buffer(I) + // Split I = IL || IR into two 32-byte sequences, IL and IR. - var IL = I.slice(0, 32) - , IR = I.slice(32) + var ILb = I.slice(0, 32) + , IRb = I.slice(32) var hd = new HDWallet() hd.network = this.network + var IL = BigInteger.fromByteArrayUnsigned(ILb) + if (this.priv) { // ki = IL + kpar (mod n). - hd.priv = this.priv.add(new ECKey(IL.concat([1]))) - hd.priv.compressed = true - hd.priv.version = this.getKeyVersion() + var ki = IL.add(this.priv.priv).mod(ecparams.getN()) + + hd.priv = new ECKey(ki, true) hd.pub = hd.priv.getPub() } else { // Ki = (IL + kpar)*G = IL*G + Kpar - hd.pub = this.pub.add(new ECKey(IL.concat([1]), true).getPub()) + var Ki = IL.multiply(ecparams.getG()).add(this.pub.pub) + + hd.pub = new ECPubKey(Ki, true) } // ci = IR. - hd.chaincode = IR - hd.parentFingerprint = this.getFingerprint() + hd.chaincode = IRb + hd.parentFingerprint = this.getFingerprint().readUInt32BE(0) hd.depth = this.depth + 1 hd.index = i hd.pub.compressed = true @@ -248,7 +242,7 @@ HDWallet.prototype.derivePrivate = function(index) { } HDWallet.prototype.getKeyVersion = function() { - return Network[this.network].addressVersion + return Network[this.network].pubKeyHash } HDWallet.prototype.toString = HDWallet.prototype.toBase58 diff --git a/src/network.js b/src/network.js index 6621a2c78..4a531dd2e 100644 --- a/src/network.js +++ b/src/network.js @@ -1,19 +1,29 @@ +// https://en.bitcoin.it/wiki/List_of_address_prefixes module.exports = { - mainnet: { - addressVersion: 0, - p2shVersion: 5, - hdVersions: { - pub: 0x0488B21E, - priv: 0x0488ADE4 - } + bitcoin: { + bip32: { + pub: 0x0488b21e, + priv: 0x0488ade4 + }, + pubKeyHash: 0x00, + scriptHash: 0x05, + wif: 0x80 + }, + dogecoin: { + pubKeyHash: 0x30, + scriptHash: 0x20, + wif: 0x9e + }, + litecoin: { + scriptHash: 0x30, }, testnet: { - addressVersion: 111, - p2shVersion: 196, - hdVersions: { - pub: 0x043587CF, + bip32: { + pub: 0x043587cf, priv: 0x04358394 - } + }, + pubKeyHash: 0x6f, + scriptHash: 0xc4, + wif: 0xef } } - diff --git a/src/script.js b/src/script.js index 636f5ddb3..deeea9aa4 100644 --- a/src/script.js +++ b/src/script.js @@ -369,8 +369,8 @@ Script.prototype.writeBytes = function(data) { Script.createOutputScript = function(address) { var script = new Script() address = new Address(address) - if (address.version == network.mainnet.p2shVersion || - address.version == network.testnet.p2shVersion) { + if (address.version == network.bitcoin.scriptHash || + address.version == network.testnet.scriptHash) { // Standard pay-to-script-hash script.writeOp(Opcode.map.OP_HASH160) script.writeBytes(address.hash) diff --git a/src/wallet.js b/src/wallet.js index 2b69f3249..563f9318b 100644 --- a/src/wallet.js +++ b/src/wallet.js @@ -7,7 +7,7 @@ function Wallet(seed, options) { if (!(this instanceof Wallet)) { return new Wallet(seed, options); } var options = options || {} - var network = options.network || 'mainnet' + var network = options.network || 'bitcoin' // Stored in a closure to make accidental serialization less likely var masterkey = null diff --git a/test/address.js b/test/address.js index 98dd03f5b..3d8336cb6 100644 --- a/test/address.js +++ b/test/address.js @@ -3,26 +3,26 @@ var Address = require('../src/address') var network = require('../src/network') var base58 = require('../src/base58') var base58check = require('../src/base58check') -var mainnet = network.mainnet.addressVersion -var testnet = network.testnet.addressVersion +var bitcoin = network.bitcoin.pubKeyHash +var testnet = network.testnet.pubKeyHash describe('Address', function() { - var testnetAddress, mainnetAddress - var testnetP2shAddress, mainnetP2shAddress + var testnetAddress, bitcoinAddress + var testnetP2shAddress, bitcoinP2shAddress beforeEach(function(){ - mainnetAddress = '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa' + bitcoinAddress = '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa' testnetAddress = 'mzBc4XEFSdzCDcTxAgf6EZXgsZWpztRhef' - mainnetP2shAddress = '3NJZLcZEEYBpxYEUGewU4knsQRn1WM5Fkt' + bitcoinP2shAddress = '3NJZLcZEEYBpxYEUGewU4knsQRn1WM5Fkt' testnetP2shAddress = '2MxKEf2su6FGAUfCEAHreGFQvEYrfYNHvL7' }) describe('parsing', function() { it('works with Address object', function() { - var addr = new Address(new Address('mwrB4fgT1KSBCqELaWv7o7tsExuQzW3NY3', network.testnet.addressVersion)) + var addr = new Address(new Address('mwrB4fgT1KSBCqELaWv7o7tsExuQzW3NY3', network.testnet.pubKeyHash)) assert.equal(addr.toString(), 'mwrB4fgT1KSBCqELaWv7o7tsExuQzW3NY3') - assert.equal(addr.version, network.testnet.addressVersion) + assert.equal(addr.version, network.testnet.pubKeyHash) }) it('works with hex', function() { @@ -37,15 +37,15 @@ describe('Address', function() { }) it('works for byte input', function() { - var hash = base58check.decode(mainnetAddress) + var hash = base58check.decode(bitcoinAddress) var addr = new Address(hash.payload) assert.equal(addr.hash, hash.payload) - assert.equal(network.mainnet.addressVersion, hash.version) + assert.equal(network.bitcoin.pubKeyHash, hash.version) var hash = base58check.decode(testnetAddress) var addr = new Address(hash.payload) assert.equal(addr.hash, hash.payload) - assert.equal(network.testnet.addressVersion, hash.version) + assert.equal(network.testnet.pubKeyHash, hash.version) }) it('fails for bad input', function() { @@ -57,8 +57,8 @@ describe('Address', function() { describe('getVersion', function() { it('returns the proper address version', function() { - assert.equal(Address.getVersion(mainnetAddress), network.mainnet.addressVersion) - assert.equal(Address.getVersion(testnetAddress), network.testnet.addressVersion) + assert.equal(Address.getVersion(bitcoinAddress), network.bitcoin.pubKeyHash) + assert.equal(Address.getVersion(testnetAddress), network.testnet.pubKeyHash) }) }) @@ -72,9 +72,9 @@ describe('Address', function() { describe('Constructor', function(){ it('resolves version correctly', function(){ assert.equal((new Address(testnetAddress)).version, testnet) - assert.equal((new Address(mainnetAddress)).version, mainnet) - assert.equal((new Address(testnetP2shAddress)).version, network.testnet.p2shVersion) - assert.equal((new Address(mainnetP2shAddress)).version, network.mainnet.p2shVersion) + assert.equal((new Address(bitcoinAddress)).version, bitcoin) + assert.equal((new Address(testnetP2shAddress)).version, network.testnet.scriptHash) + assert.equal((new Address(bitcoinP2shAddress)).version, network.bitcoin.scriptHash) }) }) @@ -85,7 +85,7 @@ describe('Address', function() { } validate(testnetAddress) - validate(mainnetAddress) + validate(bitcoinAddress) validate('12KYrjTdVGjFMtaxERSk3gphreJ5US8aUP') validate('12QeMLzSrB8XH8FvEzPMVoRxVAzTr5XM2y') validate('1oNLrsHnBcR6dpaBpwz3LSwutbUNkNSjs') @@ -94,7 +94,7 @@ describe('Address', function() { // p2sh addresses validate(testnetP2shAddress) - validate(mainnetP2shAddress) + validate(bitcoinP2shAddress) }) it('does not validate illegal examples', function() { diff --git a/test/eckey.js b/test/eckey.js index 94d03c7da..4134333ec 100644 --- a/test/eckey.js +++ b/test/eckey.js @@ -6,7 +6,7 @@ var bytesToHex = convert.bytesToHex var hexToBytes = convert.hexToBytes var Address = require('../src/address') var Network = require('../src/network') -var testnet = Network.testnet.addressVersion +var testnet = Network.testnet.pubKeyHash describe('ECKey', function() { describe('constructor', function() { @@ -83,7 +83,7 @@ describe('ECKey', function() { return ECPubKey(x).toHex(false) }) - it('mainnet', function() { + it('bitcoin', function() { var addresses = [ '19SgmoUj4xowEjwtXvNAtYTAgbvR9iBCui', '1MsHWS1BnwMc3tLE8G35UXsS58fKipzB7a', diff --git a/test/hdwallet.js b/test/hdwallet.js index 86f4b1e4d..ae28adb0f 100644 --- a/test/hdwallet.js +++ b/test/hdwallet.js @@ -1,11 +1,11 @@ -var HDWallet = require('../src/hdwallet.js') var assert = require('assert') -var convert = require('../src/convert.js') -var Network = require('../src/network') -var mainnet = Network.mainnet.addressVersion -var testnet = Network.testnet.addressVersion -var b2h = convert.bytesToHex +var HDWallet = require('../').HDWallet + +function b2h(buf) { + assert(Buffer.isBuffer(buf)) + return buf.toString('hex') +} describe('HDWallet', function() { describe('toBase58', function() { @@ -33,10 +33,10 @@ describe('HDWallet', function() { describe('constructor & seed deserialization', function() { var expectedPrivateKey = '0fd71c652e847ba7ea7956e3cf3fc0a0985871846b1b2c23b9c6a29a38cee86001' - var seed = [ + var seed = new Buffer([ 99, 114, 97, 122, 121, 32, 104, 111, 114, 115, 101, 32, 98, 97, 116, 116, 101, 114, 121, 32, 115, 116, 97, 112, 108, 101 - ] + ]) it('creates from binary seed', function() { var hd = new HDWallet(seed) @@ -47,16 +47,7 @@ describe('HDWallet', function() { describe('fromSeedHex', function() { it('creates from hex seed', function() { - var hd = HDWallet.fromSeedHex(b2h(seed)) - - assert.equal(hd.priv.toHex(), expectedPrivateKey) - assert(hd.pub) - }) - }) - - describe('fromSeedString', function() { - it('creates from string seed', function() { - var hd = HDWallet.fromSeedString(convert.bytesToString(seed)) + var hd = HDWallet.fromSeedHex(seed.toString('hex')) assert.equal(hd.priv.toHex(), expectedPrivateKey) assert(hd.pub) @@ -241,8 +232,8 @@ describe('HDWallet', function() { }) describe('network types', function() { - it('ensures that a mainnet Wallet generates mainnet addresses', function() { - var wallet = new HDWallet('foobar', 'mainnet') + it('ensures that a bitcoin Wallet generates bitcoin addresses', function() { + var wallet = new HDWallet('foobar', 'bitcoin') assert.equal(wallet.getAddress().toString(), '1JNymexJHEr5u1BndiChMStFkCgPm4EQ6o') }) diff --git a/test/message.js b/test/message.js index 9e257b502..0038a3ebd 100644 --- a/test/message.js +++ b/test/message.js @@ -2,7 +2,7 @@ var assert = require('assert') var convert = require('../').convert var ECKey = require('../src/eckey').ECKey var Message = require('../').Message -var testnet = require('../').network.testnet.addressVersion +var testnet = require('../').network.testnet.pubKeyHash describe('Message', function() { var msg diff --git a/test/script.js b/test/script.js index db41206a4..3e7d045d1 100644 --- a/test/script.js +++ b/test/script.js @@ -109,7 +109,7 @@ describe('Script', function() { '02fab2dea1458990793f56f42e4a47dbf35a12a351f26fa5d7e0cc7447eaafa21f', '036c6802ce7e8113723dd92cdb852e492ebb157a871ca532c3cb9ed08248ff0e19'] numSigs = 2 - network = Network.mainnet.p2shVersion + network = Network.bitcoin.scriptHash }) it('should create valid multi-sig address', function() { @@ -118,7 +118,7 @@ describe('Script', function() { var multiSigAddress = Address(multisig, network).toString() assert.ok(Address.validate(multiSigAddress)) - assert.equal(Address.getVersion(multiSigAddress), Network.mainnet.p2shVersion) + assert.equal(Address.getVersion(multiSigAddress), Network.bitcoin.scriptHash) assert.equal(multiSigAddress,'32vYjxBb7pHJJyXgNk8UoK3BdRDxBzny2v') }) diff --git a/test/wallet.js b/test/wallet.js index a99828667..565e3c8ed 100644 --- a/test/wallet.js +++ b/test/wallet.js @@ -25,8 +25,8 @@ describe('Wallet', function() { assert.ok(Wallet(seed) instanceof Wallet) }) - it('defaults to Bitcoin mainnet', function() { - assert.equal(wallet.getMasterKey().network, 'mainnet') + it('defaults to Bitcoin network', function() { + assert.equal(wallet.getMasterKey().network, 'bitcoin') }) it("generates m/0' as the main account", function() {