@@ -3,7 +3,18 @@ const should = require('should');
3
3
const testutils = require ( './testutils' ) ;
4
4
const admin = require ( '../app/admin.js' ) ;
5
5
const WalletKey = require ( '../app/models/walletkey' ) ;
6
+ const MasterKey = require ( '../app/models/masterkey' ) ;
6
7
const utils = require ( '../app/utils.js' ) ;
8
+ const Promise = require ( 'bluebird' ) ;
9
+ const co = Promise . coroutine ;
10
+ let originalVerifcationPub = process . config . verificationPub ;
11
+
12
+ const testVerificationPub = '1GS6JPCUpyFZLrE5bbJBcpeg1EdqW63nHd' ;
13
+ const xpub = 'xpub661MyMwAqRbcGGPNi42htgwXoLuPjEtdRSRUm65GWRPAb31WPRRkxzL18TGrpU2sirNjXAHFjAEmiav9kmVfY83dTfxh3DVVwNcM9JNVebh' ;
14
+ const xpubSig = 'IJB1Ubed4LNVvHfbH3s7i9duWmVi+98rCcGpB/t/V9xkY+VLl+YEv3w/g/79QgHYFv4D/nm2SGrT+FaOL1PomTU' ;
15
+ const xlmPub = 'GCM67ICQVOYN7GYYHMMGVPQ7NDCLNVBM4R74IIQTG65H4DM3KGEDMW3S' ;
16
+ const xlmSig = 'IBdvAO2063rsqo6zyhcoq4qGWMZFFQXCbcP4X7/vnbuyQO7VF2FHHr/M85CQb/yBfPgZRy5VsmDmrW3Qa6OXk6w' ;
17
+ const badSig = 'IBadAO2063rsqo6zyhcoq4qGWMZFFQXCbcP4X7/vnbuyQO7VF2FHHr/M85CQb/yBfPgZRy5VsmDmrW3Qa6OXk6w' ;
7
18
8
19
describe ( 'Offline Admin Tool' , function ( ) {
9
20
before ( function ( ) {
@@ -12,15 +23,18 @@ describe('Offline Admin Tool', function() {
12
23
13
24
after ( function ( ) {
14
25
testutils . mongoose . connection . close ( ) ;
26
+ process . config . verificationPub = originalVerifcationPub ;
15
27
} ) ;
16
28
17
29
describe ( 'Xpub validation' , function ( ) {
30
+
18
31
// Xpub importing was tested with a local file with contents: (w/o line breaks)
19
32
// xpub6AHA9hZDN11k2ijHMeS5QqHx2KP9aMBRhTDqANMnwVtdyw2TDYRmF8PjpvwUFcL1Et8Hj59S3gTSMcUQ5gAqTz3Wd8EsMTmF3DChhqPQBnU,
20
33
// xpub69pXXVvsBtZHWE1wgoix7xRAnbp1r6tR1kTK9cKvCd4QgYh4JBSLBmLA65Kg7rCMwGYrNHKFKxZDtjRkU4Ex2ozMYGfk14EyotJ5xjf2Goy,
21
34
// xpub6AU2iYgKUY8FvUc2Nz2fcWpKU1HJTeYTbzv4MZLGPBw2YnhoZPkkUo54fvqZyVtxtszMdyksF8k3iqMcoegyvj72xKZCmuCjDWneXjjztLN
22
35
// and successfully saved to local Mongo instance
23
36
describe ( 'failure' , function ( ) {
37
+ process . config . verificationPub = null ;
24
38
it ( 'should fail if length is not 111' , function ( ) {
25
39
const SHORT_XPUB = { path : 'm/0\'' , pub : 'xpub1234567890' } ;
26
40
@@ -42,14 +56,15 @@ describe('Offline Admin Tool', function() {
42
56
43
57
describe ( 'success' , function ( ) {
44
58
it ( 'should succeed with a valid key' , function ( ) {
59
+ process . config . verificationPub = null ;
45
60
const GOOD_XPUB = { path : 'm/0\'' , pub : 'xpub6B7XuUcPQ9MeszNzaTTGtni9W79MmFnHa7FUe7Hrbv3pefnaDFCHtJWaWdg1FVbocHhivnCRTCbHTjDrMBEyAGDJHGyqCnLhtEWP2rtb1sL' } ;
46
-
47
61
admin . validateKey ( GOOD_XPUB , 'xpub' ) . should . equal ( true ) ;
48
62
} ) ;
49
63
} ) ;
50
64
} ) ;
51
65
52
66
describe ( 'BIP32 child key derivation' , function ( ) {
67
+ process . config . verificationPub = null ;
53
68
// from https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki test vector 2 chain m
54
69
const MASTER_XPUB = 'xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB' ;
55
70
@@ -80,6 +95,7 @@ describe('Offline Admin Tool', function() {
80
95
} ) ;
81
96
82
97
describe ( 'Stellar key derivation' , function ( ) {
98
+ process . config . verificationPub = null ;
83
99
// from test 3 at https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0005.md#test-cases
84
100
const MASTER_SEED = '937ae91f6ab6f12461d9936dfc1375ea5312d097f3f1eb6fed6a82fbe38c85824da8704389831482db0433e5f6c6c9700ff1946aa75ad8cc2654d6e40f567866'
85
101
@@ -120,6 +136,86 @@ describe('Offline Admin Tool', function() {
120
136
} )
121
137
} ) ;
122
138
139
+ describe ( 'Key signature verification' , function ( ) {
140
+
141
+ describe ( 'failure' , function ( ) {
142
+ it ( 'should fail xpub validation with a bad signature' , function ( ) {
143
+ process . config . verificationPub = testVerificationPub ;
144
+ const key = {
145
+ pub : xpub ,
146
+ signature : badSig
147
+ } ;
148
+ const valid = admin . validateKey ( key , 'xpub' ) ;
149
+ valid . should . equal ( false ) ;
150
+ } ) ;
151
+
152
+ it ( 'should fail xlm validation with a bad signature' , function ( ) {
153
+ process . config . verificationPub = testVerificationPub ;
154
+ const key = {
155
+ pub : xlmPub ,
156
+ signature : badSig
157
+ } ;
158
+ const valid = admin . validateKey ( key , 'xlm' ) ;
159
+ valid . should . equal ( false ) ;
160
+ } ) ;
161
+
162
+ it ( 'should fail xpub validation with no signature' , function ( ) {
163
+ process . config . verificationPub = testVerificationPub ;
164
+ const key = {
165
+ pub : xpub
166
+ } ;
167
+ const valid = admin . validateKey ( key , 'xpub' ) ;
168
+ valid . should . equal ( false ) ;
169
+ } ) ;
170
+
171
+ it ( 'should fail xlm validation with no signature' , function ( ) {
172
+ process . config . verificationPub = testVerificationPub ;
173
+ const key = {
174
+ pub : xlmPub
175
+ } ;
176
+ const valid = admin . validateKey ( key , 'xlm' ) ;
177
+ valid . should . equal ( false ) ;
178
+ } ) ;
179
+ } ) ;
180
+
181
+ describe ( 'success' , function ( ) {
182
+ it ( 'should validate xpub with a good signature' , function ( ) {
183
+ process . config . verificationPub = testVerificationPub ;
184
+ const key = {
185
+ pub : xpub ,
186
+ signature : xpubSig
187
+ } ;
188
+ const valid = admin . validateKey ( key , 'xpub' ) ;
189
+ valid . should . equal ( true ) ;
190
+ } ) ;
191
+
192
+ it ( 'should validate xlm with a good signature' , function ( ) {
193
+ process . config . verificationPub = testVerificationPub ;
194
+ const key = {
195
+ pub : xlmPub ,
196
+ signature : xlmSig
197
+ } ;
198
+ const valid = admin . validateKey ( key , 'xlm' ) ;
199
+ valid . should . equal ( true ) ;
200
+ } ) ;
201
+ } ) ;
202
+ } ) ;
203
+
204
+ describe ( 'Save a key with a signature' , co ( function * ( ) {
205
+ it ( 'should successfully save a key with a signature to the database' , co ( function * ( ) {
206
+ process . config . verificationPub = testVerificationPub ;
207
+ const key = {
208
+ pub : xpub ,
209
+ signature : xpubSig ,
210
+ path : '0'
211
+ } ;
212
+ const keyList = [ key ] ;
213
+ yield admin . saveKeys ( keyList , 'xpub' ) ;
214
+ const foundKey = yield MasterKey . findOne ( { pub : xpub } ) ;
215
+ foundKey . should . have . property ( 'signature' ) ;
216
+ } ) ) ;
217
+ } ) ) ;
218
+
123
219
describe ( 'Verification' , function ( ) {
124
220
before ( function ( ) {
125
221
const key = new WalletKey ( {
0 commit comments