@@ -46,6 +46,20 @@ describe('ecsign', function() {
46
46
)
47
47
assert . equal ( sig . v , 41 )
48
48
} )
49
+
50
+ it ( 'should produce a signature for chainId=150' , function ( ) {
51
+ const chainId = 150
52
+ const sig = ecsign ( echash , ecprivkey , chainId )
53
+ assert . deepEqual (
54
+ sig . r ,
55
+ Buffer . from ( '99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9' , 'hex' ) ,
56
+ )
57
+ assert . deepEqual (
58
+ sig . s ,
59
+ Buffer . from ( '129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca66' , 'hex' ) ,
60
+ )
61
+ assert . equal ( sig . v , chainId * 2 + 35 )
62
+ } )
49
63
} )
50
64
51
65
describe ( 'ecrecover' , function ( ) {
@@ -63,6 +77,14 @@ describe('ecrecover', function() {
63
77
const pubkey = ecrecover ( echash , v , r , s , chainId )
64
78
assert . deepEqual ( pubkey , privateToPublic ( ecprivkey ) )
65
79
} )
80
+ it ( 'should recover a public key (chainId = 150)' , function ( ) {
81
+ const chainId = 150
82
+ const r = Buffer . from ( '99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9' , 'hex' )
83
+ const s = Buffer . from ( '129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca66' , 'hex' )
84
+ const v = chainId * 2 + 35
85
+ const pubkey = ecrecover ( echash , v , r , s , chainId )
86
+ assert . deepEqual ( pubkey , privateToPublic ( ecprivkey ) )
87
+ } )
66
88
it ( 'should fail on an invalid signature (v = 21)' , function ( ) {
67
89
const r = Buffer . from ( '99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9' , 'hex' )
68
90
const s = Buffer . from ( '129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca66' , 'hex' )
@@ -160,6 +182,13 @@ describe('isValidSignature', function() {
160
182
const v = 41
161
183
assert . equal ( isValidSignature ( v , r , s , false , chainId ) , true )
162
184
} )
185
+ it ( 'should work otherwise(chainId=150)' , function ( ) {
186
+ const chainId = 150
187
+ const r = Buffer . from ( '99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9' , 'hex' )
188
+ const s = Buffer . from ( '129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca66' , 'hex' )
189
+ const v = chainId * 2 + 35
190
+ assert . equal ( isValidSignature ( v , r , s , false , chainId ) , true )
191
+ } )
163
192
// FIXME: add homestead test
164
193
} )
165
194
@@ -194,13 +223,32 @@ describe('message sig', function() {
194
223
)
195
224
} )
196
225
197
- it ( 'should throw on invalid length' , function ( ) {
226
+ it ( 'should return hex strings that the RPC can use (chainId=150)' , function ( ) {
227
+ const chainId = 150
228
+ const v = chainId * 2 + 35
229
+ assert . equal (
230
+ toRpcSig ( v , r , s , chainId ) ,
231
+ '0x99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca66014f' ,
232
+ )
233
+ assert . deepEqual (
234
+ fromRpcSig (
235
+ '0x99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca66014f' ,
236
+ ) ,
237
+ {
238
+ v,
239
+ r : r ,
240
+ s : s ,
241
+ } ,
242
+ )
243
+ } )
244
+
245
+ it ( 'should throw on shorter length' , function ( ) {
198
246
assert . throws ( function ( ) {
199
247
fromRpcSig ( '' )
200
248
} )
201
249
assert . throws ( function ( ) {
202
250
fromRpcSig (
203
- '0x99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca660042 ' ,
251
+ '0x99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca ' ,
204
252
)
205
253
} )
206
254
} )
0 commit comments