add preconditions to Structure.js
This commit is contained in:
parent
88e6ea9f40
commit
2bf8ac912f
6 changed files with 22 additions and 27 deletions
|
|
@ -190,7 +190,7 @@ PublicKeyRing.prototype.getScriptPubKeyHex = function(index, isChange) {
|
|||
|
||||
//generate a new address, update index.
|
||||
PublicKeyRing.prototype.generateAddress = function(isChange) {
|
||||
|
||||
isChange = !!isChange;
|
||||
var index = isChange ? this.indexes.getChangeIndex() : this.indexes.getReceiveIndex();
|
||||
var ret = this.getAddress(index, isChange);
|
||||
this.indexes.increment(isChange);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
var imports = require('soop').imports();
|
||||
var preconditions = require('preconditions').singleton();
|
||||
|
||||
function Structure() {}
|
||||
|
||||
|
|
@ -18,6 +19,8 @@ var BIP45_PUBLIC_PREFIX = 'm/' + PURPOSE + '\'';
|
|||
Structure.BIP45_PUBLIC_PREFIX = BIP45_PUBLIC_PREFIX;
|
||||
|
||||
Structure.Branch = function(address_index, isChange, cosigner_index) {
|
||||
preconditions.shouldBeNumber(address_index);
|
||||
preconditions.shouldBeBoolean(isChange);
|
||||
var ret = 'm/' +
|
||||
(typeof cosigner_index !== 'undefined' ? cosigner_index : SHARED_INDEX) + '/' +
|
||||
(isChange ? 1 : 0) + '/' +
|
||||
|
|
@ -32,6 +35,7 @@ Structure.FullBranch = function(address_index, isChange, cosigner_index) {
|
|||
};
|
||||
|
||||
Structure.indicesForPath = function(path) {
|
||||
preconditions.shouldBeString(path);
|
||||
var s = path.split('/');
|
||||
return {
|
||||
isChange: s[3] === '1',
|
||||
|
|
@ -39,8 +43,8 @@ Structure.indicesForPath = function(path) {
|
|||
};
|
||||
};
|
||||
|
||||
Structure.IdFullBranch = Structure.FullBranch(0, 0, ID_INDEX);
|
||||
Structure.IdBranch = Structure.Branch(0, 0, ID_INDEX);
|
||||
Structure.IdFullBranch = Structure.FullBranch(0, false, ID_INDEX);
|
||||
Structure.IdBranch = Structure.Branch(0, false, ID_INDEX);
|
||||
Structure.PURPOSE = PURPOSE;
|
||||
Structure.MAX_NON_HARDENED = MAX_NON_HARDENED;
|
||||
Structure.SHARED_INDEX = SHARED_INDEX;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ var imports = require('soop').imports();
|
|||
var http = require('http');
|
||||
var EventEmitter = imports.EventEmitter || require('events').EventEmitter;
|
||||
var async = require('async');
|
||||
var preconditions = require('preconditions').instance();
|
||||
var preconditions = require('preconditions').singleton();
|
||||
|
||||
var bitcore = require('bitcore');
|
||||
var bignum = bitcore.Bignum;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue