Advertisement
SHA888

Untitled

Mar 2nd, 2023
1,363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 2.39 KB | None | 0 0
  1. #[ink(message)]
  2.         pub fn verify_identity_response(&mut self, signature: [u8; 65]) -> Result<bool> {
  3.             // Ensure flow began
  4.             // Todo: Extract accountId later, the person authorizer can't call as the user
  5.             if !self
  6.                 .account_verification_flow_initiation
  7.                 .contains(&self.env().caller())
  8.             {
  9.                 return Err(Error::VerificationFlowNotInitiated);
  10.             }
  11.  
  12.             if !self.authorizers.contains(&self.env().caller()) {
  13.                 return Err(Error::NotAuthorized);
  14.             }
  15.  
  16.             // Get ECDSA public key out of account
  17.             let candidate_pub_key = self.env().caller().ecdsa_public_key(); // TODO: [Work in progress] - This is not working yet -
  18.  
  19.             // Verify using the caller's signature
  20.             // https://substrate.dev/rustdocs/v2.0.0/sp_io/crypto/fn.secp256k1_ecdsa_recover.html
  21.             let message_hash: [u8; 32] = [0; 32]; // TODO: [Please review] - Is this the right way to do this?
  22.  
  23.             let output: [u8; 33] = [0; 33]; // TODO: [Please review] - Is this the right way to do this?
  24.  
  25.             let recovered_key = ink::env::ecdsa_recover(
  26.                 &signature,
  27.                 &message_hash,
  28.                 &mut output
  29.             );
  30.  
  31.             let index = self.project_index;
  32.  
  33.             // Check recovered key == candidate_pub_key
  34.             if recovered_key == candidate_pub_key {
  35.                 // Remove flow initiation
  36.                 self.account_verification_flow_initiation.take(&self.env().caller());
  37.                 // Add to verified accounts
  38.                 self.verified_accounts.insert(index.try_into().unwrap(), self.env().caller());
  39.                 Ok(true)
  40.             } else {
  41.                 Err(Error::VerificationFailed)
  42.             }
  43.  
  44. ❯ cargo check
  45.     Checking chocolate v0.1.0 (/home/sha888/chocolate/chocolate-contract)
  46. error[E0599]: no method named `ecdsa_public_key` found for struct `ink::ink_primitives::AccountId` in the current scope
  47.    --> lib.rs:275:57
  48.     |
  49. 275 |             let candidate_pub_key = self.env().caller().ecdsa_public_key();
  50.     |                                                         ^^^^^^^^^^^^^^^^ method not found in `ink::ink_primitives::AccountId`
  51.  
  52. For more information about this error, try `rustc --explain E0599`.
  53. error: could not compile `chocolate` due to previous error
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement