Add structure
This commit is contained in:
parent
f13dea2376
commit
6a0d5ce89a
1 changed files with 40 additions and 0 deletions
40
js/models/core/Structure.js
Normal file
40
js/models/core/Structure.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
'use strict';
|
||||
|
||||
|
||||
var imports = require('soop').imports();
|
||||
|
||||
function Structure() {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Based on https://github.com/maraoz/bips/blob/master/bip-NNNN.mediawiki
|
||||
* m / purpose' / cosigner_index / change / address_index
|
||||
*/
|
||||
var PURPOSE = 45;
|
||||
var MAX_NON_HARDENED = 0x8000000 - 1;
|
||||
|
||||
var SHARED_INDEX = MAX_NON_HARDENED - 0;
|
||||
var ID_INDEX = MAX_NON_HARDENED - 1;
|
||||
|
||||
var BIP45_PUBLIC_PREFIX = 'm/'+ PURPOSE+'\'';
|
||||
Structure.BIP45_PUBLIC_PREFIX = BIP45_PUBLIC_PREFIX;
|
||||
|
||||
Structure.Branch = function(address_index, isChange, cosigner_index) {
|
||||
var ret = 'm/'+
|
||||
(typeof cosigner_index !== 'undefined'? cosigner_index: SHARED_INDEX)+'/'+
|
||||
(isChange?1:0)+'/'+
|
||||
address_index;
|
||||
return ret;
|
||||
};
|
||||
|
||||
Structure.FullBranch = function(address_index, isChange, cosigner_index) {
|
||||
var sub = Structure.Branch(address_index, isChange, cosigner_index);
|
||||
sub = sub.substring(2);
|
||||
return BIP45_PUBLIC_PREFIX + '/' + sub;
|
||||
};
|
||||
Structure.IdFullBranch = Structure.FullBranch(0, 0, ID_INDEX);
|
||||
Structure.IdBranch = Structure.Branch(0, 0, ID_INDEX);
|
||||
|
||||
|
||||
module.exports = require('soop')(Structure);
|
||||
Loading…
Add table
Add a link
Reference in a new issue