Skip to content

Commit c11f4b4

Browse files
Merge pull request #15 from originalworks/expose-sign-typed-data
Expose sign typed data
2 parents 10b3a90 + 33a6c4e commit c11f4b4

File tree

3 files changed

+46
-22
lines changed

3 files changed

+46
-22
lines changed

Cargo.lock

Lines changed: 24 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ow_wallet_adapter"
3-
version = "0.1.6"
3+
version = "0.1.7"
44
edition = "2024"
55
license = "MIT OR Apache-2.0"
66
description = "Original Works EVM wallet adapter library with KMS integration"
@@ -10,7 +10,9 @@ readme = "README.md"
1010

1111
[dependencies]
1212
alloy = "1.6.3"
13+
alloy-signer = { version = "1.8.3", features = ["eip712"] }
1314
alloy-signer-aws = "1.6.3"
15+
alloy-sol-types = "1.5.7"
1416
anyhow = "1.0.101"
1517
aws-config = "1.8.13"
1618
aws-sdk-kms = "1.99.0"

src/wallet.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::OwWalletConfig;
12
use alloy::eips::BlockId;
23
use alloy::network::EthereumWallet;
34
use alloy::primitives::{Address, B256};
@@ -7,13 +8,13 @@ use alloy::providers::fillers::{
78
use alloy::providers::{Provider, ProviderBuilder};
89
use alloy::signers::Signer;
910
use alloy::signers::local::PrivateKeySigner;
11+
use alloy::sol_types::SolStruct;
1012
use alloy_signer_aws::AwsSigner;
13+
use alloy_sol_types::Eip712Domain;
1114
use anyhow::Context;
1215
use aws_config::BehaviorVersion;
1316
use aws_config::meta::region::RegionProviderChain;
1417

15-
use crate::OwWalletConfig;
16-
1718
pub struct OwWallet {
1819
pub use_kms: bool,
1920
pub wallet: EthereumWallet,
@@ -134,4 +135,20 @@ impl OwWallet {
134135
}
135136
Ok(signature)
136137
}
138+
139+
pub async fn sign_typed_data<T: SolStruct + Send + Sync>(
140+
&self,
141+
payload: &T,
142+
domain: &Eip712Domain,
143+
) -> anyhow::Result<alloy::signers::Signature> {
144+
let signature;
145+
if self.use_kms {
146+
let aws_signer = self.try_aws_signer()?;
147+
signature = aws_signer.sign_typed_data(payload, domain).await?;
148+
} else {
149+
let private_key_signer = self.try_private_key_signer()?;
150+
signature = private_key_signer.sign_typed_data(payload, domain).await?;
151+
}
152+
Ok(signature)
153+
}
137154
}

0 commit comments

Comments
 (0)