@@ -3,152 +3,7 @@ import { joinSignature } from 'ethers/lib/utils';
33
44import { SigShare } from '@lit-protocol/types' ;
55
6- import {
7- decryptWithSignatureShares ,
8- encrypt ,
9- verifyAndDecryptWithSignatureShares ,
10- combineSignatureShares ,
11- verifySignature ,
12- combineEcdsaShares ,
13- } from './crypto' ;
14-
15- const publicKey =
16- '8e29447d7b0666fe41c357dbbdbdac0ac8ac973f88439a07f85fa31fa6fa3cea87c2eaa8b367e1c97764800fb5636892' ;
17- const secretMessage = new Uint8Array ( [
18- 240 , 23 , 185 , 6 , 87 , 33 , 173 , 216 , 53 , 84 , 80 , 135 , 190 , 16 , 58 , 85 , 97 , 75 ,
19- 3 , 192 , 215 , 82 , 217 , 5 , 40 , 65 , 2 , 214 , 40 , 177 , 53 , 150 ,
20- ] ) ;
21- const identityParam = new Uint8Array ( [
22- 101 , 110 , 99 , 114 , 121 , 112 , 116 , 95 , 100 , 101 , 99 , 114 , 121 , 112 , 116 , 95 ,
23- 119 , 111 , 114 , 107 , 115 ,
24- ] ) ;
25-
26- describe ( 'crypto' , ( ) => {
27- it ( 'should encrypt' , async ( ) => {
28- // execute
29- const ciphertext = await encrypt ( publicKey , secretMessage , identityParam ) ;
30-
31- // assert
32- expect ( ciphertext . length ) . toBeGreaterThan ( 0 ) ;
33- } ) ;
34-
35- it ( 'should decrypt' , async ( ) => {
36- // prepare
37- const ciphertext =
38- 'l9a/01WDJB/euKxtbWcuQ8ez/c9eZ+jQryTHZVLN0kfd7XHoLs6FeWUVmk89ovQGkQJnnFDKjq6kgJxvIIrxXd9DaGuRBozLdA1G9Nk413YhTEqsENuHU0nSa4i6F912KltE15sbWKpDfPnZF6CA2UKBAw==' ;
39- const signatureShares = [
40- '01b2b44a0bf7184f19efacad98e213818edd3f8909dd798129ef169b877d68d77ba630005609f48b80203717d82092a45b06a9de0e61a97b2672b38b31f9ae43e64383d0375a51c75db8972613cc6b099b95c189fd8549ed973ee94b08749f4cac' ,
41- '02a8343d5602f523286c4c59356fdcfc51953290495d98cb91a56b59bd1a837ea969cc521382164e85787128ce7f944de303d8e0b5fc4becede0c894bec1adc490fdc133939cca70fb3f504b9bf7b156527b681d9f0619828cd8050c819e46fdb1' ,
42- '03b1594ab0cb56f47437b3720dc181661481ca0e36078b79c9a4acc50042f076bf66b68fbd12a1d55021a668555f0eed0a08dfe74455f557b30f1a9c32435a81479ca8843f5b74b176a8d10c5845a84213441eaaaf2ba57e32581584393541c5aa' ,
43- ] ;
44-
45- // execute
46- const plaintext = await decryptWithSignatureShares (
47- ciphertext ,
48- signatureShares . map ( ( s ) => ( {
49- ProofOfPossession : s ,
50- } ) )
51- ) ;
52-
53- // assert
54- expect ( plaintext ) . toEqual ( secretMessage ) ;
55- } ) ;
56-
57- it ( 'should verify + decrypt' , async ( ) => {
58- const ciphertext =
59- 'l9a/01WDJB/euKxtbWcuQ8ez/c9eZ+jQryTHZVLN0kfd7XHoLs6FeWUVmk89ovQGkQJnnFDKjq6kgJxvIIrxXd9DaGuRBozLdA1G9Nk413YhTEqsENuHU0nSa4i6F912KltE15sbWKpDfPnZF6CA2UKBAw==' ;
60- const signatureShares = [
61- '01b2b44a0bf7184f19efacad98e213818edd3f8909dd798129ef169b877d68d77ba630005609f48b80203717d82092a45b06a9de0e61a97b2672b38b31f9ae43e64383d0375a51c75db8972613cc6b099b95c189fd8549ed973ee94b08749f4cac' ,
62- '02a8343d5602f523286c4c59356fdcfc51953290495d98cb91a56b59bd1a837ea969cc521382164e85787128ce7f944de303d8e0b5fc4becede0c894bec1adc490fdc133939cca70fb3f504b9bf7b156527b681d9f0619828cd8050c819e46fdb1' ,
63- '03b1594ab0cb56f47437b3720dc181661481ca0e36078b79c9a4acc50042f076bf66b68fbd12a1d55021a668555f0eed0a08dfe74455f557b30f1a9c32435a81479ca8843f5b74b176a8d10c5845a84213441eaaaf2ba57e32581584393541c5aa' ,
64- ] ;
65-
66- // execute
67- const plaintext = await verifyAndDecryptWithSignatureShares (
68- publicKey ,
69- identityParam ,
70- ciphertext ,
71- signatureShares . map ( ( s ) => ( {
72- ProofOfPossession : s ,
73- } ) )
74- ) ;
75-
76- // assert
77- expect ( plaintext ) . toEqual ( secretMessage ) ;
78- } ) ;
79-
80- it ( 'should combine signature shares' , async ( ) => {
81- const signatureShares = [
82- '01b2b44a0bf7184f19efacad98e213818edd3f8909dd798129ef169b877d68d77ba630005609f48b80203717d82092a45b06a9de0e61a97b2672b38b31f9ae43e64383d0375a51c75db8972613cc6b099b95c189fd8549ed973ee94b08749f4cac' ,
83- '02a8343d5602f523286c4c59356fdcfc51953290495d98cb91a56b59bd1a837ea969cc521382164e85787128ce7f944de303d8e0b5fc4becede0c894bec1adc490fdc133939cca70fb3f504b9bf7b156527b681d9f0619828cd8050c819e46fdb1' ,
84- '03b1594ab0cb56f47437b3720dc181661481ca0e36078b79c9a4acc50042f076bf66b68fbd12a1d55021a668555f0eed0a08dfe74455f557b30f1a9c32435a81479ca8843f5b74b176a8d10c5845a84213441eaaaf2ba57e32581584393541c5aa' ,
85- ] . map ( ( s ) => ( {
86- ProofOfPossession : s ,
87- } ) ) ;
88-
89- // execute
90- const combinedSignature = await combineSignatureShares ( signatureShares ) ;
91-
92- // assert
93- expect ( combinedSignature . length ) . toEqual ( 192 ) ;
94- } ) ;
95-
96- it ( 'should verify signature' , async ( ) => {
97- const publicKey =
98- 'ad1bd6c66f849ccbcc20fa08c26108f3df7db0068df032cc184779cc967159da4dd5669de563af7252b540f0759aee5a' ;
99- const message = new Uint8Array ( [
100- 101 , 121 , 74 , 104 , 98 , 71 , 99 , 105 , 79 , 105 , 74 , 67 , 84 , 70 , 77 , 120 , 77 ,
101- 105 , 48 , 122 , 79 , 68 , 69 , 105 , 76 , 67 , 74 , 48 , 101 , 88 , 65 , 105 , 79 , 105 ,
102- 74 , 75 , 86 , 49 , 81 , 105 , 102 , 81 , 46 , 101 , 121 , 74 , 112 , 99 , 51 , 77 , 105 ,
103- 79 , 105 , 74 , 77 , 83 , 86 , 81 , 105 , 76 , 67 , 74 , 122 , 100 , 87 , 73 , 105 , 79 ,
104- 105 , 73 , 119 , 101 , 68 , 81 , 121 , 78 , 84 , 108 , 108 , 78 , 68 , 81 , 50 , 78 , 122 ,
105- 65 , 119 , 78 , 84 , 77 , 48 , 79 , 84 , 70 , 108 , 78 , 50 , 73 , 48 , 90 , 109 , 85 , 48 ,
106- 89 , 84 , 69 , 121 , 77 , 71 , 77 , 51 , 77 , 71 , 74 , 108 , 77 , 87 , 86 , 104 , 90 , 68 ,
107- 89 , 48 , 78 , 109 , 73 , 105 , 76 , 67 , 74 , 106 , 97 , 71 , 70 , 112 , 98 , 105 , 73 ,
108- 54 , 73 , 109 , 86 , 48 , 97 , 71 , 86 , 121 , 90 , 88 , 86 , 116 , 73 , 105 , 119 , 105 ,
109- 97 , 87 , 70 , 48 , 73 , 106 , 111 , 120 , 78 , 106 , 103 , 51 , 78 , 84 , 89 , 121 , 77 ,
110- 106 , 99 , 49 , 76 , 67 , 74 , 108 , 101 , 72 , 65 , 105 , 79 , 106 , 69 , 50 , 79 , 68 ,
111- 99 , 50 , 77 , 68 , 85 , 48 , 78 , 122 , 85 , 115 , 73 , 109 , 70 , 106 , 89 , 50 , 86 ,
112- 122 , 99 , 48 , 78 , 118 , 98 , 110 , 82 , 121 , 98 , 50 , 120 , 68 , 98 , 50 , 53 , 107 ,
113- 97 , 88 , 82 , 112 , 98 , 50 , 53 , 122 , 73 , 106 , 112 , 98 , 101 , 121 , 74 , 106 , 98 ,
114- 50 , 53 , 48 , 99 , 109 , 70 , 106 , 100 , 69 , 70 , 107 , 90 , 72 , 74 , 108 , 99 , 51 ,
115- 77 , 105 , 79 , 105 , 73 , 105 , 76 , 67 , 74 , 106 , 97 , 71 , 70 , 112 , 98 , 105 , 73 ,
116- 54 , 73 , 109 , 86 , 48 , 97 , 71 , 86 , 121 , 90 , 88 , 86 , 116 , 73 , 105 , 119 , 105 ,
117- 99 , 51 , 82 , 104 , 98 , 109 , 82 , 104 , 99 , 109 , 82 , 68 , 98 , 50 , 53 , 48 , 99 ,
118- 109 , 70 , 106 , 100 , 70 , 82 , 53 , 99 , 71 , 85 , 105 , 79 , 105 , 73 , 105 , 76 , 67 ,
119- 74 , 116 , 90 , 88 , 82 , 111 , 98 , 50 , 81 , 105 , 79 , 105 , 73 , 105 , 76 , 67 , 74 ,
120- 119 , 89 , 88 , 74 , 104 , 98 , 87 , 86 , 48 , 90 , 88 , 74 , 122 , 73 , 106 , 112 , 98 ,
121- 73 , 106 , 112 , 49 , 99 , 50 , 86 , 121 , 81 , 87 , 82 , 107 , 99 , 109 , 86 , 122 , 99 ,
122- 121 , 74 , 100 , 76 , 67 , 74 , 121 , 90 , 88 , 82 , 49 , 99 , 109 , 53 , 87 , 89 , 87 ,
123- 120 , 49 , 90 , 86 , 82 , 108 , 99 , 51 , 81 , 105 , 79 , 110 , 115 , 105 , 89 , 50 , 57 ,
124- 116 , 99 , 71 , 70 , 121 , 89 , 88 , 82 , 118 , 99 , 105 , 73 , 54 , 73 , 106 , 48 , 105 ,
125- 76 , 67 , 74 , 50 , 89 , 87 , 120 , 49 , 90 , 83 , 73 , 54 , 73 , 106 , 66 , 52 , 78 , 68 ,
126- 73 , 49 , 79 , 85 , 85 , 48 , 78 , 68 , 89 , 51 , 77 , 68 , 65 , 49 , 77 , 122 , 81 , 53 ,
127- 77 , 85 , 85 , 51 , 89 , 106 , 82 , 71 , 82 , 84 , 82 , 66 , 77 , 84 , 73 , 119 , 81 , 122 ,
128- 99 , 119 , 89 , 109 , 85 , 120 , 90 , 85 , 70 , 69 , 78 , 106 , 81 , 50 , 89 , 105 , 74 ,
129- 57 , 102 , 86 , 48 , 115 , 73 , 109 , 86 , 50 , 98 , 85 , 78 , 118 , 98 , 110 , 82 , 121 ,
130- 89 , 87 , 78 , 48 , 81 , 50 , 57 , 117 , 90 , 71 , 108 , 48 , 97 , 87 , 57 , 117 , 99 ,
131- 121 , 73 , 54 , 98 , 110 , 86 , 115 , 98 , 67 , 119 , 105 , 99 , 50 , 57 , 115 , 85 , 110 ,
132- 66 , 106 , 81 , 50 , 57 , 117 , 90 , 71 , 108 , 48 , 97 , 87 , 57 , 117 , 99 , 121 , 73 ,
133- 54 , 98 , 110 , 86 , 115 , 98 , 67 , 119 , 105 , 100 , 87 , 53 , 112 , 90 , 109 , 108 ,
134- 108 , 90 , 69 , 70 , 106 , 89 , 50 , 86 , 122 , 99 , 48 , 78 , 118 , 98 , 110 , 82 , 121 ,
135- 98 , 50 , 120 , 68 , 98 , 50 , 53 , 107 , 97 , 88 , 82 , 112 , 98 , 50 , 53 , 122 , 73 ,
136- 106 , 112 , 117 , 100 , 87 , 120 , 115 , 102 , 81 ,
137- ] ) ;
138- const signature = new Uint8Array ( [
139- 182 , 185 , 8 , 21 , 143 , 23 , 47 , 21 , 128 , 30 , 241 , 43 , 141 , 206 , 108 , 16 ,
140- 199 , 242 , 16 , 200 , 195 , 85 , 109 , 38 , 227 , 52 , 132 , 136 , 239 , 11 , 105 , 214 ,
141- 254 , 23 , 107 , 236 , 105 , 73 , 129 , 48 , 242 , 17 , 225 , 172 , 114 , 29 , 214 , 178 ,
142- 12 , 158 , 255 , 169 , 220 , 84 , 179 , 19 , 53 , 94 , 223 , 192 , 80 , 199 , 24 , 68 ,
143- 37 , 91 , 82 , 163 , 89 , 102 , 105 , 0 , 26 , 211 , 133 , 24 , 224 , 192 , 142 , 39 ,
144- 134 , 118 , 255 , 80 , 221 , 163 , 231 , 178 , 180 , 23 , 144 , 60 , 214 , 208 , 132 ,
145- 207 ,
146- ] ) ;
147-
148- // execute
149- await verifySignature ( publicKey , message , signature ) ;
150- } ) ;
151- } ) ;
6+ import { combineEcdsaShares } from './crypto' ;
1527
1538describe ( 'combine ECDSA Shares' , ( ) => {
1549 it ( 'Should recombine ECDSA signature shares' , async ( ) => {
@@ -157,7 +12,6 @@ describe('combine ECDSA Shares', () => {
15712 sigType : 'ECDSA_CAIT_SITH' as const ,
15813 signatureShare :
15914 'BC8108AD9CAE8358942BB4B27632B87FFA705CCB675F85A59847CC1B84845A38' ,
160- shareIndex : 0 ,
16115 bigR : '03E6D15C805443F57F57E180C730C2FCA5297F7671E8148A669410808AB4D70122' ,
16216 publicKey :
16317 '03AECABDF2EDC1194BED6FE9650F08D109C77D2526236EA3F6C20F88E0675643BC' ,
@@ -169,7 +23,6 @@ describe('combine ECDSA Shares', () => {
16923 sigType : 'K256' as const ,
17024 signatureShare :
17125 'BA77EB500884A60583DEA49578D4BB64BB55EF497F37C88DF935D739CE8E0A9F' ,
172- shareIndex : 0 ,
17326 bigR : '03E6D15C805443F57F57E180C730C2FCA5297F7671E8148A669410808AB4D70122' ,
17427 publicKey :
17528 '03AECABDF2EDC1194BED6FE9650F08D109C77D2526236EA3F6C20F88E0675643BC' ,
@@ -181,7 +34,6 @@ describe('combine ECDSA Shares', () => {
18134 sigType : 'ECDSA_CAIT_SITH' as const ,
18235 signatureShare :
18336 'EF850AE61B6D658976B2560B880BF03ABC1A070BACDEAE2311781F65A524F245' ,
184- shareIndex : 0 ,
18537 bigR : '03E6D15C805443F57F57E180C730C2FCA5297F7671E8148A669410808AB4D70122' ,
18638 publicKey :
18739 '03AECABDF2EDC1194BED6FE9650F08D109C77D2526236EA3F6C20F88E0675643BC' ,
0 commit comments