@@ -112,8 +112,7 @@ impl Adapter for EthereumAdapter {
112
112
113
113
fn sign ( & self , state_root : & str ) -> AdapterResult < String , Self :: AdapterError > {
114
114
if let Some ( wallet) = & self . wallet {
115
- let state_root =
116
- hex:: decode ( state_root) . map_err ( StateRootError :: StateRootHexDecoding ) ?;
115
+ let state_root = hex:: decode ( state_root) . map_err ( VerifyError :: StateRootDecoding ) ?;
117
116
let message = Message :: from_slice ( & hash_message ( & state_root) ) ;
118
117
let wallet_sign = wallet
119
118
. sign ( & self . keystore_pwd , & message)
@@ -133,17 +132,16 @@ impl Adapter for EthereumAdapter {
133
132
sig : & str ,
134
133
) -> AdapterResult < bool , Self :: AdapterError > {
135
134
if !sig. starts_with ( "0x" ) {
136
- return Err ( StateRootError :: SignatureNotPrefixed . into ( ) ) ;
135
+ return Err ( VerifyError :: SignatureNotPrefixed . into ( ) ) ;
137
136
}
138
- let decoded_signature =
139
- hex:: decode ( & sig[ 2 ..] ) . map_err ( StateRootError :: SignatureHexDecoding ) ?;
137
+ let decoded_signature = hex:: decode ( & sig[ 2 ..] ) . map_err ( VerifyError :: SignatureDecoding ) ?;
140
138
let address = Address :: from_slice ( signer. inner ( ) ) ;
141
139
let signature = Signature :: from_electrum ( & decoded_signature) ;
142
- let state_root = hex:: decode ( state_root) . map_err ( StateRootError :: StateRootHexDecoding ) ?;
140
+ let state_root = hex:: decode ( state_root) . map_err ( VerifyError :: StateRootDecoding ) ?;
143
141
let message = Message :: from_slice ( & hash_message ( & state_root) ) ;
144
142
145
143
let verify_address = verify_address ( & address, & signature, & message)
146
- . map_err ( StateRootError :: PublicKeyRecovery ) ?;
144
+ . map_err ( VerifyError :: PublicKeyRecovery ) ?;
147
145
148
146
Ok ( verify_address)
149
147
}
@@ -454,7 +452,8 @@ mod error {
454
452
VerifyMessage ( EwtVerifyError ) ,
455
453
ContractInitialization ( ethabi:: Error ) ,
456
454
ContractQuerying ( web3:: contract:: Error ) ,
457
- StateRoot ( StateRootError ) ,
455
+ /// Error occurred during verification of Signature and/or StateRoot and/or Address
456
+ VerifyAddress ( VerifyError ) ,
458
457
}
459
458
460
459
impl std:: error:: Error for Error { }
@@ -466,51 +465,49 @@ mod error {
466
465
use Error :: * ;
467
466
468
467
match self {
469
- Keystore ( err) => write ! ( f, "Keystore error - {}" , err) ,
470
- WalletUnlock ( err) => write ! ( f, "Wallet unlocking error - {}" , err) ,
471
- Web3 ( err) => write ! ( f, "Web3 error - {}" , err) ,
472
- RelayerClient ( err) => write ! ( f, "Relayer client error - {}" , err) ,
468
+ Keystore ( err) => write ! ( f, "Keystore: {}" , err) ,
469
+ WalletUnlock ( err) => write ! ( f, "Wallet unlocking: {}" , err) ,
470
+ Web3 ( err) => write ! ( f, "Web3: {}" , err) ,
471
+ RelayerClient ( err) => write ! ( f, "Relayer client: {}" , err) ,
473
472
InvalidChannelId { expected, actual} => write ! ( f, "The hashed EthereumChannel.id ({}) is not the same as the Channel.id ({}) that was provided" , expected, actual) ,
474
473
ChannelInactive ( channel_id) => write ! ( f, "Channel ({}) is not Active on the ethereum network" , channel_id) ,
475
- SignMessage ( err) => write ! ( f, "Signing message - {}" , err) ,
476
- VerifyMessage ( err) => write ! ( f, "Verifying message - {}" , err) ,
477
- ContractInitialization ( err) => write ! ( f, "Contract initialization - {}" , err) ,
478
- ContractQuerying ( err) => write ! ( f, "Contract querying - {}" , err) ,
479
- StateRoot ( err) => write ! ( f, "State root - {}" , err)
474
+ SignMessage ( err) => write ! ( f, "Signing message: {}" , err) ,
475
+ VerifyMessage ( err) => write ! ( f, "Verifying message: {}" , err) ,
476
+ ContractInitialization ( err) => write ! ( f, "Contract initialization: {}" , err) ,
477
+ ContractQuerying ( err) => write ! ( f, "Contract querying: {}" , err) ,
478
+ VerifyAddress ( err) => write ! ( f, "Verifying address: {}" , err)
480
479
}
481
480
}
482
481
}
483
482
484
483
#[ derive( Debug ) ]
485
- pub enum StateRootError {
484
+ /// Error returned on `eth_adapter.verify()` when the combination of
485
+ /// (signer, state_root, signature) **doesn't align**.
486
+ pub enum VerifyError {
486
487
PublicKeyRecovery ( parity_crypto:: publickey:: Error ) ,
487
- StateRootHexDecoding ( hex:: FromHexError ) ,
488
- SignatureHexDecoding ( hex:: FromHexError ) ,
488
+ StateRootDecoding ( hex:: FromHexError ) ,
489
+ SignatureDecoding ( hex:: FromHexError ) ,
489
490
SignatureNotPrefixed ,
490
491
}
491
492
492
- impl fmt:: Display for StateRootError {
493
+ impl fmt:: Display for VerifyError {
493
494
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
494
- use StateRootError :: * ;
495
+ use VerifyError :: * ;
495
496
496
497
match self {
497
498
PublicKeyRecovery ( err) => {
498
- write ! ( f, "Recovering the public key from the signature - {}" , err)
499
- }
500
- StateRootHexDecoding ( err) => {
501
- write ! ( f, "Decoding the hex of the state root - {}" , err)
502
- }
503
- SignatureHexDecoding ( err) => {
504
- write ! ( f, "Decoding the hex of the signature - {}" , err)
499
+ write ! ( f, "Recovering the public key from the signature: {}" , err)
505
500
}
501
+ StateRootDecoding ( err) => write ! ( f, "Decoding the hex of the state root: {}" , err) ,
502
+ SignatureDecoding ( err) => write ! ( f, "Decoding the hex of the signature: {}" , err) ,
506
503
SignatureNotPrefixed => write ! ( f, "Signature is not prefixed with `0x`" ) ,
507
504
}
508
505
}
509
506
}
510
507
511
- impl From < StateRootError > for AdapterError < Error > {
512
- fn from ( err : StateRootError ) -> Self {
513
- AdapterError :: Adapter ( Error :: StateRoot ( err) )
508
+ impl From < VerifyError > for AdapterError < Error > {
509
+ fn from ( err : VerifyError ) -> Self {
510
+ AdapterError :: Adapter ( Error :: VerifyAddress ( err) )
514
511
}
515
512
}
516
513
@@ -544,9 +541,9 @@ mod error {
544
541
545
542
match self {
546
543
AddressMissing => write ! ( f, "\" address\" key missing in keystore file" ) ,
547
- AddressInvalid ( err) => write ! ( f, "\" address\" is invalid - {}" , err) ,
548
- ReadingFile ( err) => write ! ( f, "Reading keystore file - {}" , err) ,
549
- Deserialization ( err) => write ! ( f, "Deserializing keystore file - {}" , err) ,
544
+ AddressInvalid ( err) => write ! ( f, "\" address\" is invalid: {}" , err) ,
545
+ ReadingFile ( err) => write ! ( f, "Reading keystore file: {}" , err) ,
546
+ Deserialization ( err) => write ! ( f, "Deserializing keystore file: {}" , err) ,
550
547
}
551
548
}
552
549
}
@@ -570,10 +567,10 @@ mod error {
570
567
use EwtSigningError :: * ;
571
568
572
569
match self {
573
- HeaderSerialization ( err) => write ! ( f, "Header serialization - {}" , err) ,
574
- PayloadSerialization ( err) => write ! ( f, "Payload serialization - {}" , err) ,
575
- SigningMessage ( err) => write ! ( f, "Signing message - {}" , err) ,
576
- DecodingHexSignature ( err) => write ! ( f, "Decoding hex of Signature - {}" , err) ,
570
+ HeaderSerialization ( err) => write ! ( f, "Header serialization: {}" , err) ,
571
+ PayloadSerialization ( err) => write ! ( f, "Payload serialization: {}" , err) ,
572
+ SigningMessage ( err) => write ! ( f, "Signing message: {}" , err) ,
573
+ DecodingHexSignature ( err) => write ! ( f, "Decoding hex of Signature: {}" , err) ,
577
574
}
578
575
}
579
576
}
@@ -597,11 +594,11 @@ mod error {
597
594
use EwtVerifyError :: * ;
598
595
599
596
match self {
600
- AddressRecovery ( err) => write ! ( f, "Address recovery - {}" , err) ,
601
- SignatureDecoding ( err) => write ! ( f, "Signature decoding - {}" , err) ,
602
- PayloadDecoding ( err) => write ! ( f, "Payload decoding - {}" , err) ,
603
- PayloadDeserialization ( err) => write ! ( f, "Payload deserialization - {}" , err) ,
604
- PayloadUtf8 ( err) => write ! ( f, "Payload is not a valid utf8 string - {}" , err) ,
597
+ AddressRecovery ( err) => write ! ( f, "Address recovery: {}" , err) ,
598
+ SignatureDecoding ( err) => write ! ( f, "Signature decoding: {}" , err) ,
599
+ PayloadDecoding ( err) => write ! ( f, "Payload decoding: {}" , err) ,
600
+ PayloadDeserialization ( err) => write ! ( f, "Payload deserialization: {}" , err) ,
601
+ PayloadUtf8 ( err) => write ! ( f, "Payload is not a valid utf8 string: {}" , err) ,
605
602
}
606
603
}
607
604
}
0 commit comments