@@ -32,6 +32,8 @@ use web3::{
32
32
Web3 ,
33
33
} ;
34
34
35
+ mod error;
36
+
35
37
lazy_static ! {
36
38
static ref ADEXCORE_ABI : & ' static [ u8 ] =
37
39
include_bytes!( "../../lib/protocol-eth/abi/AdExCore.json" ) ;
@@ -431,181 +433,6 @@ pub fn ewt_verify(
431
433
Ok ( verified_payload)
432
434
}
433
435
434
- mod error {
435
- use primitives:: adapter:: { AdapterErrorKind , Error as AdapterError } ;
436
- use primitives:: ChannelId ;
437
- use std:: fmt;
438
-
439
- #[ derive( Debug ) ]
440
- pub enum Error {
441
- Keystore ( KeystoreError ) ,
442
- WalletUnlock ( ethstore:: Error ) ,
443
- Web3 ( web3:: Error ) ,
444
- RelayerClient ( reqwest:: Error ) ,
445
- /// When the ChannelId that we get from hashing the EthereumChannel with the contract address
446
- /// does not align with the provided Channel
447
- InvalidChannelId {
448
- expected : ChannelId ,
449
- actual : ChannelId ,
450
- } ,
451
- ChannelInactive ( ChannelId ) ,
452
- /// Signing of the message failed
453
- SignMessage ( EwtSigningError ) ,
454
- VerifyMessage ( EwtVerifyError ) ,
455
- ContractInitialization ( ethabi:: Error ) ,
456
- ContractQuerying ( web3:: contract:: Error ) ,
457
- /// Error occurred during verification of Signature and/or StateRoot and/or Address
458
- VerifyAddress ( VerifyError ) ,
459
- }
460
-
461
- impl std:: error:: Error for Error { }
462
-
463
- impl AdapterErrorKind for Error { }
464
-
465
- impl fmt:: Display for Error {
466
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
467
- use Error :: * ;
468
-
469
- match self {
470
- Keystore ( err) => write ! ( f, "Keystore: {}" , err) ,
471
- WalletUnlock ( err) => write ! ( f, "Wallet unlocking: {}" , err) ,
472
- Web3 ( err) => write ! ( f, "Web3: {}" , err) ,
473
- RelayerClient ( err) => write ! ( f, "Relayer client: {}" , err) ,
474
- InvalidChannelId { expected, actual} => write ! ( f, "The hashed EthereumChannel.id ({}) is not the same as the Channel.id ({}) that was provided" , expected, actual) ,
475
- ChannelInactive ( channel_id) => write ! ( f, "Channel ({}) is not Active on the ethereum network" , channel_id) ,
476
- SignMessage ( err) => write ! ( f, "Signing message: {}" , err) ,
477
- VerifyMessage ( err) => write ! ( f, "Verifying message: {}" , err) ,
478
- ContractInitialization ( err) => write ! ( f, "Contract initialization: {}" , err) ,
479
- ContractQuerying ( err) => write ! ( f, "Contract querying: {}" , err) ,
480
- VerifyAddress ( err) => write ! ( f, "Verifying address: {}" , err)
481
- }
482
- }
483
- }
484
-
485
- #[ derive( Debug ) ]
486
- /// Error returned on `eth_adapter.verify()` when the combination of
487
- /// (signer, state_root, signature) **doesn't align**.
488
- pub enum VerifyError {
489
- PublicKeyRecovery ( parity_crypto:: publickey:: Error ) ,
490
- StateRootDecoding ( hex:: FromHexError ) ,
491
- SignatureDecoding ( hex:: FromHexError ) ,
492
- SignatureNotPrefixed ,
493
- }
494
-
495
- impl fmt:: Display for VerifyError {
496
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
497
- use VerifyError :: * ;
498
-
499
- match self {
500
- PublicKeyRecovery ( err) => {
501
- write ! ( f, "Recovering the public key from the signature: {}" , err)
502
- }
503
- StateRootDecoding ( err) => write ! ( f, "Decoding the hex of the state root: {}" , err) ,
504
- SignatureDecoding ( err) => write ! ( f, "Decoding the hex of the signature: {}" , err) ,
505
- SignatureNotPrefixed => write ! ( f, "Signature is not prefixed with `0x`" ) ,
506
- }
507
- }
508
- }
509
-
510
- impl From < VerifyError > for AdapterError < Error > {
511
- fn from ( err : VerifyError ) -> Self {
512
- AdapterError :: Adapter ( Error :: VerifyAddress ( err) )
513
- }
514
- }
515
-
516
- #[ derive( Debug ) ]
517
- pub enum KeystoreError {
518
- /// `address` key is missing from the keystore file
519
- AddressMissing ,
520
- /// The `address` key in the keystore file is not a valid `ValidatorId`
521
- AddressInvalid ( primitives:: DomainError ) ,
522
- /// reading the keystore file failed
523
- ReadingFile ( std:: io:: Error ) ,
524
- /// Deserializing the keystore file failed
525
- Deserialization ( serde_json:: Error ) ,
526
- }
527
-
528
- impl std:: error:: Error for KeystoreError {
529
- fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
530
- use KeystoreError :: * ;
531
- match self {
532
- AddressMissing => None ,
533
- AddressInvalid ( err) => Some ( err) ,
534
- ReadingFile ( err) => Some ( err) ,
535
- Deserialization ( err) => Some ( err) ,
536
- }
537
- }
538
- }
539
-
540
- impl fmt:: Display for KeystoreError {
541
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
542
- use KeystoreError :: * ;
543
-
544
- match self {
545
- AddressMissing => write ! ( f, "\" address\" key missing in keystore file" ) ,
546
- AddressInvalid ( err) => write ! ( f, "\" address\" is invalid: {}" , err) ,
547
- ReadingFile ( err) => write ! ( f, "Reading keystore file: {}" , err) ,
548
- Deserialization ( err) => write ! ( f, "Deserializing keystore file: {}" , err) ,
549
- }
550
- }
551
- }
552
-
553
- impl From < KeystoreError > for AdapterError < Error > {
554
- fn from ( err : KeystoreError ) -> Self {
555
- AdapterError :: Adapter ( Error :: Keystore ( err) )
556
- }
557
- }
558
-
559
- #[ derive( Debug ) ]
560
- pub enum EwtSigningError {
561
- HeaderSerialization ( serde_json:: Error ) ,
562
- PayloadSerialization ( serde_json:: Error ) ,
563
- SigningMessage ( ethstore:: Error ) ,
564
- DecodingHexSignature ( hex:: FromHexError ) ,
565
- }
566
-
567
- impl fmt:: Display for EwtSigningError {
568
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
569
- use EwtSigningError :: * ;
570
-
571
- match self {
572
- HeaderSerialization ( err) => write ! ( f, "Header serialization: {}" , err) ,
573
- PayloadSerialization ( err) => write ! ( f, "Payload serialization: {}" , err) ,
574
- SigningMessage ( err) => write ! ( f, "Signing message: {}" , err) ,
575
- DecodingHexSignature ( err) => write ! ( f, "Decoding hex of Signature: {}" , err) ,
576
- }
577
- }
578
- }
579
- impl From < EwtSigningError > for AdapterError < Error > {
580
- fn from ( err : EwtSigningError ) -> Self {
581
- AdapterError :: Adapter ( Error :: SignMessage ( err) )
582
- }
583
- }
584
-
585
- #[ derive( Debug ) ]
586
- pub enum EwtVerifyError {
587
- AddressRecovery ( parity_crypto:: publickey:: Error ) ,
588
- SignatureDecoding ( base64:: DecodeError ) ,
589
- PayloadDecoding ( base64:: DecodeError ) ,
590
- PayloadDeserialization ( serde_json:: Error ) ,
591
- PayloadUtf8 ( std:: string:: FromUtf8Error ) ,
592
- }
593
-
594
- impl fmt:: Display for EwtVerifyError {
595
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
596
- use EwtVerifyError :: * ;
597
-
598
- match self {
599
- AddressRecovery ( err) => write ! ( f, "Address recovery: {}" , err) ,
600
- SignatureDecoding ( err) => write ! ( f, "Signature decoding: {}" , err) ,
601
- PayloadDecoding ( err) => write ! ( f, "Payload decoding: {}" , err) ,
602
- PayloadDeserialization ( err) => write ! ( f, "Payload deserialization: {}" , err) ,
603
- PayloadUtf8 ( err) => write ! ( f, "Payload is not a valid utf8 string: {}" , err) ,
604
- }
605
- }
606
- }
607
- }
608
-
609
436
#[ cfg( test) ]
610
437
mod test {
611
438
use super :: * ;
0 commit comments