Skip to content

Commit

Permalink
Add support for signTypedData to AwsKmsWallet (#2125)
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-maj authored Jan 9, 2024
1 parent b3cf65b commit e66e906
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/pink-files-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@thirdweb-dev/wallets": patch
---

Add signTypedData to AwsKmsWallet
20 changes: 18 additions & 2 deletions packages/wallets/src/evm/wallets/aws-kms.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbstractWallet } from "./abstract";
import type { Signer } from "ethers";
import { ethers, TypedDataDomain, type Signer, TypedDataField } from "ethers";
import type { AwsKmsSignerCredentials } from "ethers-aws-kms-signer";

/**
Expand Down Expand Up @@ -44,7 +44,23 @@ export class AwsKmsWallet extends AbstractWallet {
this.#signer = new Promise(async (resolve, reject) => {
try {
const { AwsKmsSigner } = await import("ethers-aws-kms-signer");
resolve(new AwsKmsSigner(this.#options));
const signer = new AwsKmsSigner(this.#options);

// Need to add this because ethers-aws-kms-signer doesn't support
(signer as any)._signTypedData = async function (
domain: TypedDataDomain,
types: Record<string, Array<TypedDataField>>,
value: Record<string, any>,
) {
const hash = ethers.utils._TypedDataEncoder.hash(
domain,
types,
value,
);
return signer._signDigest(hash);
};

resolve(signer);
} catch (err) {
// remove the cached promise so we can try again
this.#signer = undefined;
Expand Down

0 comments on commit e66e906

Please sign in to comment.