@@ -357,7 +357,7 @@ describe('wallet', () => {
357
357
} ,
358
358
primaryType : 'EIP712Domain' ,
359
359
domain : {
360
- verifyingContract : '996101235222674412020337938588541139382869425796 ' ,
360
+ verifyingContract : '0Xae7ab96520de3a18e5e111b5eaab095312d7fe84 ' ,
361
361
} ,
362
362
message : { } ,
363
363
} ;
@@ -391,6 +391,139 @@ describe('wallet', () => {
391
391
signatureMethod : 'eth_signTypedData_v3' ,
392
392
} ) ;
393
393
} ) ;
394
+
395
+ it ( 'should throw if verifyingContract is invalid hex value' , async ( ) => {
396
+ const { engine } = createTestSetup ( ) ;
397
+ const getAccounts = async ( ) => testAddresses . slice ( ) ;
398
+ const witnessedMsgParams : TypedMessageParams [ ] = [ ] ;
399
+ const processTypedMessageV3 = async ( msgParams : TypedMessageParams ) => {
400
+ witnessedMsgParams . push ( msgParams ) ;
401
+ // Assume testMsgSig is the expected signature result
402
+ return testMsgSig ;
403
+ } ;
404
+
405
+ engine . push (
406
+ createWalletMiddleware ( { getAccounts, processTypedMessageV3 } ) ,
407
+ ) ;
408
+
409
+ const message = {
410
+ types : {
411
+ EIP712Domain : [
412
+ { name : 'name' , type : 'string' } ,
413
+ { name : 'version' , type : 'string' } ,
414
+ { name : 'chainId' , type : 'uint256' } ,
415
+ { name : 'verifyingContract' , type : 'address' } ,
416
+ ] ,
417
+ } ,
418
+ primaryType : 'EIP712Domain' ,
419
+ domain : {
420
+ verifyingContract : '917551056842671309452305380979543736893630245704' ,
421
+ } ,
422
+ message : { } ,
423
+ } ;
424
+
425
+ const stringifiedMessage = JSON . stringify ( message ) ;
426
+
427
+ const payload = {
428
+ method : 'eth_signTypedData_v3' ,
429
+ params : [ testAddresses [ 0 ] , stringifiedMessage ] , // Assuming testAddresses[0] is a valid address from your setup
430
+ } ;
431
+
432
+ const promise = pify ( engine . handle ) . call ( engine , payload ) ;
433
+ await expect ( promise ) . rejects . toThrow ( 'Invalid input.' ) ;
434
+ } ) ;
435
+ } ) ;
436
+
437
+ describe ( 'signTypedDataV4' , ( ) => {
438
+ const getMsgParams = ( verifyingContract ?: string ) => ( {
439
+ types : {
440
+ EIP712Domain : [
441
+ { name : 'name' , type : 'string' } ,
442
+ { name : 'version' , type : 'string' } ,
443
+ { name : 'chainId' , type : 'uint256' } ,
444
+ { name : 'verifyingContract' , type : 'address' } ,
445
+ ] ,
446
+ Permit : [
447
+ { name : 'owner' , type : 'address' } ,
448
+ { name : 'spender' , type : 'address' } ,
449
+ { name : 'value' , type : 'uint256' } ,
450
+ { name : 'nonce' , type : 'uint256' } ,
451
+ { name : 'deadline' , type : 'uint256' } ,
452
+ ] ,
453
+ } ,
454
+ primaryType : 'Permit' ,
455
+ domain : {
456
+ name : 'MyToken' ,
457
+ version : '1' ,
458
+ verifyingContract :
459
+ verifyingContract ?? '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC' ,
460
+ chainId : '0x1' ,
461
+ } ,
462
+ message : {
463
+ owner : testAddresses [ 0 ] ,
464
+ spender : '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc' ,
465
+ value : 3000 ,
466
+ nonce : 0 ,
467
+ deadline : 50000000000 ,
468
+ } ,
469
+ } ) ;
470
+
471
+ it ( 'should not throw if request is permit with valid hex value for verifyingContract address' , async ( ) => {
472
+ const { engine } = createTestSetup ( ) ;
473
+ const getAccounts = async ( ) => testAddresses . slice ( ) ;
474
+ const witnessedMsgParams : TypedMessageParams [ ] = [ ] ;
475
+ const processTypedMessageV4 = async ( msgParams : TypedMessageParams ) => {
476
+ witnessedMsgParams . push ( msgParams ) ;
477
+ // Assume testMsgSig is the expected signature result
478
+ return testMsgSig ;
479
+ } ;
480
+
481
+ engine . push (
482
+ createWalletMiddleware ( { getAccounts, processTypedMessageV4 } ) ,
483
+ ) ;
484
+
485
+ const payload = {
486
+ method : 'eth_signTypedData_v4' ,
487
+ params : [ testAddresses [ 0 ] , JSON . stringify ( getMsgParams ( ) ) ] ,
488
+ } ;
489
+
490
+ const promise = pify ( engine . handle ) . call ( engine , payload ) ;
491
+ const result = await promise ;
492
+ expect ( result ) . toStrictEqual ( {
493
+ id : undefined ,
494
+ jsonrpc : undefined ,
495
+ result :
496
+ '0x68dc980608bceb5f99f691e62c32caccaee05317309015e9454eba1a14c3cd4505d1dd098b8339801239c9bcaac3c4df95569dcf307108b92f68711379be14d81c' ,
497
+ } ) ;
498
+ } ) ;
499
+
500
+ it ( 'should throw if request is permit with invalid hex value for verifyingContract address' , async ( ) => {
501
+ const { engine } = createTestSetup ( ) ;
502
+ const getAccounts = async ( ) => testAddresses . slice ( ) ;
503
+ const witnessedMsgParams : TypedMessageParams [ ] = [ ] ;
504
+ const processTypedMessageV4 = async ( msgParams : TypedMessageParams ) => {
505
+ witnessedMsgParams . push ( msgParams ) ;
506
+ // Assume testMsgSig is the expected signature result
507
+ return testMsgSig ;
508
+ } ;
509
+
510
+ engine . push (
511
+ createWalletMiddleware ( { getAccounts, processTypedMessageV4 } ) ,
512
+ ) ;
513
+
514
+ const payload = {
515
+ method : 'eth_signTypedData_v4' ,
516
+ params : [
517
+ testAddresses [ 0 ] ,
518
+ JSON . stringify (
519
+ getMsgParams ( '917551056842671309452305380979543736893630245704' ) ,
520
+ ) ,
521
+ ] ,
522
+ } ;
523
+
524
+ const promise = pify ( engine . handle ) . call ( engine , payload ) ;
525
+ await expect ( promise ) . rejects . toThrow ( 'Invalid input.' ) ;
526
+ } ) ;
394
527
} ) ;
395
528
396
529
describe ( 'sign' , ( ) => {
0 commit comments