-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add gcp-signer * chore: format import * chore: add eyre and adapt signing to aws implementation * fix example * add gcp signer to README * polish --------- Co-authored-by: Adegbite Ademola Kelvin <adegbiteademolakelvin@Adegbites-MacBook-Pro.local> Co-authored-by: zerosnacks <zerosnacks@protonmail.com>
- Loading branch information
1 parent
5a6776f
commit 77848d0
Showing
6 changed files
with
48 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//! Example showing how to use the GCP KMS signer. | ||
use alloy::signers::{ | ||
gcp::{GcpKeyRingRef, GcpSigner, KeySpecifier}, | ||
Signer, | ||
}; | ||
use eyre::{Ok, Result}; | ||
use gcloud_sdk::{ | ||
google::cloud::kms::v1::key_management_service_client::KeyManagementServiceClient, GoogleApi, | ||
}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let project_id = | ||
std::env::var("GOOGLE_PROJECT_ID").expect("GOOGLE_PROJECT_ID not set in .env file"); | ||
let location = std::env::var("GOOGLE_LOCATION").expect("GOOGLE_LOCATION not set in .env file"); | ||
let keyring = std::env::var("GOOGLE_KEYRING").expect("GOOGLE_KEYRING not set in .env file"); | ||
let key_name = std::env::var("GOOGLE_KEY_NAME").expect("GOOGLE_KEY_NAME not set in .env file"); | ||
|
||
let keyring = GcpKeyRingRef::new(&project_id, &location, &keyring); | ||
let client = GoogleApi::from_function( | ||
KeyManagementServiceClient::new, | ||
"https://cloudkms.googleapis.com", | ||
None, | ||
) | ||
.await?; | ||
|
||
let key_version = 1; | ||
let specifier = KeySpecifier::new(keyring, &key_name, key_version); | ||
let signer = GcpSigner::new(client, specifier, Some(key_version)).await?; | ||
|
||
let message = "Hello, world!"; | ||
let signature = signer.sign_message(message.as_bytes()).await?; | ||
|
||
assert_eq!(signature.recover_address_from_msg(message)?, signer.address()); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters