|
1 | 1 | import assert from 'assert'; |
2 | 2 | import { ed25519 } from '@noble/curves/ed25519'; |
| 3 | +import { EddsaMPSDsg, MPSUtil } from '../../../../src/tss/eddsa-mps'; |
3 | 4 | import { deriveUnhardenedMps } from '../../../../src/tss/eddsa-mps/derive'; |
4 | | -import { generateEdDsaDKGKeyShares, runEdDsaDSG } from './util'; |
| 5 | +import { generateEdDsaDKGKeyShares } from './util'; |
5 | 6 |
|
6 | 7 | const MESSAGE = Buffer.from('The Times 03/Jan/2009 Chancellor on brink of second bailout for banks'); |
7 | 8 |
|
@@ -63,28 +64,40 @@ describe('deriveUnhardenedMps', function () { |
63 | 64 | }); |
64 | 65 |
|
65 | 66 | describe('DSG signature cross-check against the public key derived by deriveUnhardenedMps', function () { |
| 67 | + let sigAtRoot: Buffer; |
| 68 | + let sigAtM0: Buffer; |
| 69 | + let sigAtM01: Buffer; |
| 70 | + |
| 71 | + before(function () { |
| 72 | + const dsgA1 = new EddsaMPSDsg.DSG(0); |
| 73 | + MPSUtil.executeTillRound(3, dsgA1, new EddsaMPSDsg.DSG(2), userKeyShare, bitgoKeyShare, MESSAGE, 'm'); |
| 74 | + sigAtRoot = dsgA1.getSignature(); |
| 75 | + |
| 76 | + const dsgA2 = new EddsaMPSDsg.DSG(0); |
| 77 | + MPSUtil.executeTillRound(3, dsgA2, new EddsaMPSDsg.DSG(2), userKeyShare, bitgoKeyShare, MESSAGE, 'm/0'); |
| 78 | + sigAtM0 = dsgA2.getSignature(); |
| 79 | + |
| 80 | + const dsgA3 = new EddsaMPSDsg.DSG(0); |
| 81 | + MPSUtil.executeTillRound(3, dsgA3, new EddsaMPSDsg.DSG(2), userKeyShare, bitgoKeyShare, MESSAGE, 'm/0/1'); |
| 82 | + sigAtM01 = dsgA3.getSignature(); |
| 83 | + }); |
| 84 | + |
66 | 85 | it('signature from DSG at "m" verifies against the root public key', function () { |
67 | | - const { dsgA } = runEdDsaDSG(userKeyShare, bitgoKeyShare, 0, 2, MESSAGE, 'm'); |
68 | | - const sig = dsgA.getSignature(); |
69 | | - assert(ed25519.verify(sig, MESSAGE, rootPubKey), 'DSG at "m" should verify against the raw DKG public key'); |
| 86 | + assert(ed25519.verify(sigAtRoot, MESSAGE, rootPubKey), 'DSG at "m" should verify against the raw DKG public key'); |
70 | 87 | }); |
71 | 88 |
|
72 | 89 | it('signature from DSG at "m/0" verifies against deriveUnhardenedMps(commonKeychain, "m/0")', function () { |
73 | 90 | const derivedPk = Buffer.from(deriveUnhardenedMps(commonKeychain, 'm/0').slice(0, 64), 'hex'); |
74 | | - const { dsgA } = runEdDsaDSG(userKeyShare, bitgoKeyShare, 0, 2, MESSAGE, 'm/0'); |
75 | | - const sig = dsgA.getSignature(); |
76 | 91 | assert( |
77 | | - ed25519.verify(sig, MESSAGE, derivedPk), |
| 92 | + ed25519.verify(sigAtM0, MESSAGE, derivedPk), |
78 | 93 | 'DSG at "m/0" should verify against deriveUnhardenedMps result at "m/0"' |
79 | 94 | ); |
80 | 95 | }); |
81 | 96 |
|
82 | 97 | it('signature from DSG at "m/0/1" verifies against deriveUnhardenedMps(commonKeychain, "m/0/1")', function () { |
83 | 98 | const derivedPk = Buffer.from(deriveUnhardenedMps(commonKeychain, 'm/0/1').slice(0, 64), 'hex'); |
84 | | - const { dsgA } = runEdDsaDSG(userKeyShare, bitgoKeyShare, 0, 2, MESSAGE, 'm/0/1'); |
85 | | - const sig = dsgA.getSignature(); |
86 | 99 | assert( |
87 | | - ed25519.verify(sig, MESSAGE, derivedPk), |
| 100 | + ed25519.verify(sigAtM01, MESSAGE, derivedPk), |
88 | 101 | 'DSG at "m/0/1" should verify against deriveUnhardenedMps result at "m/0/1"' |
89 | 102 | ); |
90 | 103 | }); |
|
0 commit comments