2
2
3
3
var $ = require ( 'preconditions' ) . singleton ( ) ;
4
4
import * as _ from 'lodash' ;
5
- import { Common } from './common' ;
5
+ import { Constants , Utils } from './common' ;
6
6
import { Credentials } from './credentials' ;
7
7
8
8
var Bitcore = require ( 'bitcore-lib' ) ;
@@ -13,8 +13,6 @@ const async = require('async');
13
13
const Uuid = require ( 'uuid' ) ;
14
14
15
15
var Errors = require ( './errors' ) ;
16
- var Constants = Common . Constants ;
17
- var Utils = Common . Utils ;
18
16
19
17
const wordsForLang : any = {
20
18
en : Mnemonic . Words . ENGLISH ,
@@ -63,7 +61,7 @@ export class Key {
63
61
return a . id == b . id ;
64
62
}
65
63
66
- static create = function ( opts ) {
64
+ static create = function ( opts ) {
67
65
opts = opts || { } ;
68
66
if ( opts . language && ! wordsForLang [ opts . language ] )
69
67
throw new Error ( 'Unsupported language' ) ;
@@ -90,7 +88,7 @@ export class Key {
90
88
return x ;
91
89
} ;
92
90
93
- static fromMnemonic = function ( words , opts ) {
91
+ static fromMnemonic = function ( words , opts ) {
94
92
$ . checkArgument ( words ) ;
95
93
if ( opts ) $ . shouldBeObject ( opts ) ;
96
94
opts = opts || { } ;
@@ -111,7 +109,7 @@ export class Key {
111
109
return x ;
112
110
} ;
113
111
114
- static fromExtendedPrivateKey = function ( xPriv , opts ) {
112
+ static fromExtendedPrivateKey = function ( xPriv , opts ) {
115
113
$ . checkArgument ( xPriv ) ;
116
114
opts = opts || { } ;
117
115
@@ -136,37 +134,37 @@ export class Key {
136
134
return x ;
137
135
} ;
138
136
139
- static fromObj = function ( obj ) {
137
+ static fromObj = function ( obj ) {
140
138
$ . shouldBeObject ( obj ) ;
141
139
142
140
var x : any = new Key ( ) ;
143
141
if ( obj . version != x . version ) {
144
142
throw new Error ( 'Bad Key version' ) ;
145
143
}
146
144
147
- _ . each ( Key . FIELDS , function ( k ) {
145
+ _ . each ( Key . FIELDS , function ( k ) {
148
146
x [ k ] = obj [ k ] ;
149
147
} ) ;
150
148
151
149
$ . checkState ( x . xPrivKey || x . xPrivKeyEncrypted , 'invalid input' ) ;
152
150
return x ;
153
151
} ;
154
152
155
- toObj = function ( ) {
153
+ toObj = function ( ) {
156
154
var self = this ;
157
155
158
156
var x = { } ;
159
- _ . each ( Key . FIELDS , function ( k ) {
157
+ _ . each ( Key . FIELDS , function ( k ) {
160
158
x [ k ] = self [ k ] ;
161
159
} ) ;
162
160
return x ;
163
161
} ;
164
162
165
- isPrivKeyEncrypted = function ( ) {
163
+ isPrivKeyEncrypted = function ( ) {
166
164
return ! ! this . xPrivKeyEncrypted && ! this . xPrivKey ;
167
165
} ;
168
166
169
- checkPassword = function ( password ) {
167
+ checkPassword = function ( password ) {
170
168
if ( this . isPrivKeyEncrypted ( ) ) {
171
169
try {
172
170
sjcl . decrypt ( password , this . xPrivKeyEncrypted ) ;
@@ -178,7 +176,7 @@ export class Key {
178
176
return null ;
179
177
} ;
180
178
181
- get = function ( password ) {
179
+ get = function ( password ) {
182
180
var keys : any = { } ;
183
181
let fingerPrintUpdated = false ;
184
182
@@ -213,7 +211,7 @@ export class Key {
213
211
return keys ;
214
212
} ;
215
213
216
- encrypt = function ( password , opts ) {
214
+ encrypt = function ( password , opts ) {
217
215
if ( this . xPrivKeyEncrypted )
218
216
throw new Error ( 'Private key already encrypted' ) ;
219
217
@@ -229,7 +227,7 @@ export class Key {
229
227
delete this . mnemonic ;
230
228
} ;
231
229
232
- decrypt = function ( password ) {
230
+ decrypt = function ( password ) {
233
231
if ( ! this . xPrivKeyEncrypted )
234
232
throw new Error ( 'Private key is not encrypted' ) ;
235
233
@@ -246,7 +244,7 @@ export class Key {
246
244
}
247
245
} ;
248
246
249
- derive = function ( password , path ) {
247
+ derive = function ( password , path ) {
250
248
$ . checkArgument ( path , 'no path at derive()' ) ;
251
249
var xPrivKey = new Bitcore . HDPrivateKey (
252
250
this . get ( password ) . xPrivKey ,
@@ -306,7 +304,7 @@ export class Key {
306
304
* opts.n
307
305
*/
308
306
309
- createCredentials = function ( password , opts ) {
307
+ createCredentials = function ( password , opts ) {
310
308
opts = opts || { } ;
311
309
312
310
if ( password ) $ . shouldBeString ( password , 'provide password' ) ;
@@ -357,7 +355,7 @@ export class Key {
357
355
* opts.requestPrivKey
358
356
*/
359
357
360
- createAccess = function ( password , opts ) {
358
+ createAccess = function ( password , opts ) {
361
359
opts = opts || { } ;
362
360
$ . shouldBeString ( opts . path ) ;
363
361
@@ -374,7 +372,7 @@ export class Key {
374
372
} ;
375
373
} ;
376
374
377
- sign = function ( rootPath , txp , password , cb ) {
375
+ sign = function ( rootPath , txp , password , cb ) {
378
376
$ . shouldBeString ( rootPath ) ;
379
377
if ( this . isPrivKeyEncrypted ( ) && ! password ) {
380
378
return cb ( new Errors . ENCRYPTED_PRIVATE_KEY ( ) ) ;
@@ -385,7 +383,7 @@ export class Key {
385
383
var derived = this . derive ( password , rootPath ) ;
386
384
var xpriv = new Bitcore . HDPrivateKey ( derived ) ;
387
385
388
- _ . each ( txp . inputs , function ( i ) {
386
+ _ . each ( txp . inputs , function ( i ) {
389
387
$ . checkState (
390
388
i . path ,
391
389
'Input derivation path not available (signing transaction)'
@@ -397,11 +395,11 @@ export class Key {
397
395
} ) ;
398
396
399
397
var t = Utils . buildTx ( txp ) ;
400
- var signatures = _ . map ( privs , function ( priv , i ) {
398
+ var signatures = _ . map ( privs , function ( priv , i ) {
401
399
return t . getSignatures ( priv ) ;
402
400
} ) ;
403
401
404
- signatures = _ . map ( _ . sortBy ( _ . flatten ( signatures ) , 'inputIndex' ) , function (
402
+ signatures = _ . map ( _ . sortBy ( _ . flatten ( signatures ) , 'inputIndex' ) , function (
405
403
s
406
404
) {
407
405
return s . signature . toDER ( ) . toString ( 'hex' ) ;
0 commit comments