@@ -37,10 +37,19 @@ import {
37
37
ResponseIdentity ,
38
38
ResponseSign
39
39
} from './types'
40
- import { encodeRound3Inputs , minimizeRound3Inputs } from "./ironfish" ;
40
+ import {
41
+ serializeDkgGetCommitments ,
42
+ serializeDkgGetNonces ,
43
+ serializeDkgRound1 ,
44
+ serializeDkgRound2 ,
45
+ serializeDkgRound3 , serializeDkgSign ,
46
+ } from './serialize'
47
+ import { deserializeDkgRound1 , deserializeDkgRound2 } from './deserialize'
41
48
42
49
export * from './types'
43
50
51
+ const DUMMY_PATH = "m/44'/1338'/0" ;
52
+
44
53
export default class IronfishApp extends GenericApp {
45
54
readonly CLA_DKG : number = 0x63 ;
46
55
readonly INS ! : IronfishIns
@@ -181,20 +190,9 @@ export default class IronfishApp extends GenericApp {
181
190
] )
182
191
}
183
192
184
- async dkgRound1 ( path : string , index :number , identities : string [ ] , minSigners : number ) : Promise < ResponseDkgRound1 > {
185
- let blob = Buffer
186
- . alloc ( 1 + 1 + identities . length * 129 + 1 ) ;
187
- console . log ( `dkgRound1 msg size: ${ blob . byteLength } ` )
188
-
189
-
190
- blob . writeUint8 ( index ) ;
191
- blob . writeUint8 ( identities . length , 1 ) ;
192
- for ( let i = 0 ; i < identities . length ; i ++ ) {
193
- blob . fill ( Buffer . from ( identities [ i ] , "hex" ) , 1 + 1 + ( i * 129 ) )
194
- }
195
- blob . writeUint8 ( minSigners , 1 + 1 + identities . length * 129 ) ;
196
-
197
- const chunks = this . prepareChunks ( path , blob )
193
+ async dkgRound1 ( index :number , identities : string [ ] , minSigners : number ) : Promise < ResponseDkgRound1 > {
194
+ const blob = serializeDkgRound1 ( index , identities , minSigners ) ;
195
+ const chunks = this . prepareChunks ( DUMMY_PATH , blob )
198
196
199
197
try {
200
198
let response = Buffer . alloc ( 0 )
@@ -251,22 +249,10 @@ export default class IronfishApp extends GenericApp {
251
249
}
252
250
253
251
} else {
254
- // console.log("raw round1 " + data.toString("hex"))
255
- let pos = 0
256
- const secretPackageLen = data . readUint16BE ( pos )
257
- pos += 2
258
- const secretPackage = data . subarray ( pos , pos + secretPackageLen )
259
- pos += secretPackageLen
260
- const publicPackageLen = data . readUint16BE ( pos )
261
- pos += 2
262
- const publicPackage = data . subarray ( pos , pos + publicPackageLen )
263
- pos += publicPackageLen
264
-
265
252
return {
266
253
returnCode,
267
254
errorMessage,
268
- secretPackage,
269
- publicPackage
255
+ ...deserializeDkgRound1 ( data )
270
256
}
271
257
}
272
258
}
@@ -277,35 +263,9 @@ export default class IronfishApp extends GenericApp {
277
263
}
278
264
279
265
280
- async dkgRound2 ( path : string , index : number , round1PublicPackages : string [ ] , round1SecretPackage : string ) : Promise < ResponseDkgRound2 > {
281
- let round1PublicPackagesLen = round1PublicPackages [ 0 ] . length / 2
282
- let round1SecretPackageLen = round1SecretPackage . length / 2
283
-
284
- let blob = Buffer
285
- . alloc ( 1 + 1 + 2 + round1PublicPackages . length * round1PublicPackagesLen + 2 + round1SecretPackageLen ) ;
286
- console . log ( `dkgRound2 msg size: ${ blob . byteLength } ` )
287
-
288
- let pos = 0 ;
289
-
290
- blob . writeUint8 ( index , pos ) ;
291
- pos += 1 ;
292
- blob . writeUint8 ( round1PublicPackages . length , pos ) ;
293
- pos += 1 ;
294
- blob . writeUint16BE ( round1PublicPackagesLen , pos ) ;
295
- pos += 2 ;
296
-
297
- for ( let i = 0 ; i < round1PublicPackages . length ; i ++ ) {
298
- blob . fill ( Buffer . from ( round1PublicPackages [ i ] , "hex" ) , pos )
299
- pos += round1PublicPackagesLen ;
300
- }
301
-
302
- blob . writeUint16BE ( round1SecretPackageLen , pos ) ;
303
- pos += 2 ;
304
-
305
- blob . fill ( Buffer . from ( round1SecretPackage , "hex" ) , pos )
306
- pos += round1SecretPackageLen ;
307
-
308
- const chunks = this . prepareChunks ( path , blob )
266
+ async dkgRound2 ( index : number , round1PublicPackages : string [ ] , round1SecretPackage : string ) : Promise < ResponseDkgRound2 > {
267
+ const blob = serializeDkgRound2 ( index , round1PublicPackages , round1SecretPackage )
268
+ const chunks = this . prepareChunks ( DUMMY_PATH , blob )
309
269
310
270
try {
311
271
let response = Buffer . alloc ( 0 )
@@ -362,21 +322,10 @@ export default class IronfishApp extends GenericApp {
362
322
}
363
323
364
324
} else {
365
- let pos = 0
366
- const secretPackageLen = data . readUint16BE ( pos )
367
- pos += 2
368
- const secretPackage = data . subarray ( pos , pos + secretPackageLen )
369
- pos += secretPackageLen
370
- const publicPackageLen = data . readUint16BE ( pos )
371
- pos += 2
372
- const publicPackage = data . subarray ( pos , pos + publicPackageLen )
373
- pos += publicPackageLen
374
-
375
325
return {
376
326
returnCode,
377
327
errorMessage,
378
- secretPackage,
379
- publicPackage
328
+ ...deserializeDkgRound2 ( data )
380
329
}
381
330
}
382
331
}
@@ -387,11 +336,9 @@ export default class IronfishApp extends GenericApp {
387
336
}
388
337
389
338
390
- async dkgRound3 ( path : string , index : number , round1PublicPackages : string [ ] , round2PublicPackages : string [ ] , round2SecretPackage : string ) : Promise < ResponseDkgRound3 > {
391
- const { participants, round2PublicPkgs, round1PublicPkgs, gskBytes } = minimizeRound3Inputs ( index , round1PublicPackages , round2PublicPackages )
392
- const blob = encodeRound3Inputs ( index , participants , round1PublicPkgs , round2PublicPkgs , round2SecretPackage , gskBytes )
393
-
394
- const chunks = this . prepareChunks ( path , blob )
339
+ async dkgRound3 ( index : number , round1PublicPackages : string [ ] , round2PublicPackages : string [ ] , round2SecretPackage : string ) : Promise < ResponseDkgRound3 > {
340
+ const blob = serializeDkgRound3 ( index , round1PublicPackages , round2PublicPackages , round2SecretPackage )
341
+ const chunks = this . prepareChunks ( DUMMY_PATH , blob )
395
342
396
343
try {
397
344
let response = Buffer . alloc ( 0 )
@@ -461,21 +408,9 @@ export default class IronfishApp extends GenericApp {
461
408
}
462
409
463
410
464
- async dkgGetCommitments ( path : string , identities : string [ ] , tx_hash : string ) : Promise < ResponseDkgGetCommitments > {
465
- let blob = Buffer
466
- . alloc ( 1 + identities . length * 129 + 32 ) ;
467
- console . log ( `dkgGetCommitment msg size: ${ blob . byteLength } ` )
468
-
469
-
470
- blob . writeUint8 ( identities . length , 0 ) ;
471
-
472
- for ( let i = 0 ; i < identities . length ; i ++ ) {
473
- blob . fill ( Buffer . from ( identities [ i ] , "hex" ) , 1 + ( i * 129 ) ) ;
474
- }
475
-
476
- blob . fill ( Buffer . from ( tx_hash , "hex" ) , 1 + identities . length * 129 ) ;
477
-
478
- const chunks = this . prepareChunks ( path , blob )
411
+ async dkgGetCommitments ( identities : string [ ] , tx_hash : string ) : Promise < ResponseDkgGetCommitments > {
412
+ const blob = serializeDkgGetCommitments ( identities , tx_hash )
413
+ const chunks = this . prepareChunks ( DUMMY_PATH , blob )
479
414
480
415
try {
481
416
let response = Buffer . alloc ( 0 )
@@ -547,21 +482,9 @@ export default class IronfishApp extends GenericApp {
547
482
}
548
483
549
484
550
- async dkgGetNonces ( path : string , identities : string [ ] , tx_hash : string ) : Promise < ResponseDkgGetNonces > {
551
- let blob = Buffer
552
- . alloc ( 1 + identities . length * 129 + 32 ) ;
553
- console . log ( `dkgGetNonces msg size: ${ blob . byteLength } ` )
554
-
555
-
556
- blob . writeUint8 ( identities . length , 0 ) ;
557
-
558
- for ( let i = 0 ; i < identities . length ; i ++ ) {
559
- blob . fill ( Buffer . from ( identities [ i ] , "hex" ) , 1 + ( i * 129 ) ) ;
560
- }
561
-
562
- blob . fill ( Buffer . from ( tx_hash , "hex" ) , 1 + identities . length * 129 ) ;
563
-
564
- const chunks = this . prepareChunks ( path , blob )
485
+ async dkgGetNonces ( identities : string [ ] , tx_hash : string ) : Promise < ResponseDkgGetNonces > {
486
+ const blob = serializeDkgGetNonces ( identities , tx_hash )
487
+ const chunks = this . prepareChunks ( DUMMY_PATH , blob )
565
488
566
489
try {
567
490
let response = Buffer . alloc ( 0 )
@@ -632,32 +555,9 @@ export default class IronfishApp extends GenericApp {
632
555
}
633
556
}
634
557
635
- async dkgSign ( path : string , pkRandomness : string , frostSigningPackage : string , nonces : string ) : Promise < ResponseDkgSign > {
636
- let pkRandomnessLen = pkRandomness . length / 2
637
- let frostSigningPackageLen = frostSigningPackage . length / 2
638
- let noncesLen = nonces . length / 2
639
-
640
- let blob = Buffer
641
- . alloc ( 2 + pkRandomnessLen + 2 + frostSigningPackageLen + 2 + noncesLen ) ;
642
- console . log ( `dkgSign msg size: ${ blob . byteLength } ` )
643
-
644
- let pos = 0 ;
645
-
646
- blob . writeUint16BE ( pkRandomnessLen , pos ) ;
647
- pos += 2 ;
648
- blob . fill ( Buffer . from ( pkRandomness , "hex" ) , pos ) ;
649
- pos += pkRandomnessLen ;
650
-
651
- blob . writeUint16BE ( frostSigningPackageLen , pos ) ;
652
- pos += 2 ;
653
- blob . fill ( Buffer . from ( frostSigningPackage , "hex" ) , pos ) ;
654
- pos += frostSigningPackageLen ;
655
-
656
- blob . writeUint16BE ( noncesLen , pos ) ;
657
- pos += 2 ;
658
- blob . fill ( Buffer . from ( nonces , "hex" ) , pos ) ;
659
-
660
- const chunks = this . prepareChunks ( path , blob )
558
+ async dkgSign ( pkRandomness : string , frostSigningPackage : string , nonces : string ) : Promise < ResponseDkgSign > {
559
+ const blob = serializeDkgSign ( pkRandomness , frostSigningPackage , nonces )
560
+ const chunks = this . prepareChunks ( DUMMY_PATH , blob )
661
561
662
562
try {
663
563
let response = Buffer . alloc ( 0 )
@@ -838,8 +738,8 @@ export default class IronfishApp extends GenericApp {
838
738
}
839
739
840
740
841
- async dkgRestoreKeys ( path : string , encryptedKeys : string ) : Promise < ResponseBase > {
842
- const chunks = this . prepareChunks ( path , Buffer . from ( encryptedKeys , "hex" ) )
741
+ async dkgRestoreKeys ( encryptedKeys : string ) : Promise < ResponseBase > {
742
+ const chunks = this . prepareChunks ( DUMMY_PATH , Buffer . from ( encryptedKeys , "hex" ) )
843
743
844
744
try {
845
745
let response = Buffer . alloc ( 0 )
0 commit comments