Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: signTypedData draft #519

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/account/BaseSmartContractAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export abstract class BaseSmartContractAccount<
* @param _params -- Typed Data params to sign
*/
async signTypedData(_params: SignTypedDataParams): Promise<`0x${string}`> {
throw new Error("signTypedData not supported")
return this.signer.signTypedData(_params)
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/account/utils/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
parseAbiParameters
} from "viem"
import type { UserOperationStruct } from "../../account"
import { type SupportedSigner, convertSigner } from "../../account"
import { type SupportedSigner, convertSigner, MAGIC_BYTES } from "../../account"
import { extractChainIdFromBundlerUrl } from "../../bundler"
import { extractChainIdFromPaymasterUrl } from "../../bundler"
import type { BiconomySmartAccountV2Config } from "./Types.js"
Expand Down Expand Up @@ -156,7 +156,7 @@ export const wrapSignatureWith6492 = ({
factoryCalldata,
signature
]),
"0x6492649264926492649264926492649264926492649264926492649264926492"
MAGIC_BYTES
])
}

Expand Down
51 changes: 51 additions & 0 deletions tests/account/read.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -877,4 +877,55 @@ describe("Account:Read", () => {
await expect(smartAccount.buildUserOp([tx1, tx2])).resolves.toBeTruthy()
}
)

test.concurrent(
"should sign typed data",
async () => {
const smartAccount = await createSmartAccountClient({
signer: walletClient,
bundlerUrl
})

const typedData = {
account: walletClient.account,
domain: {
name: "Ether Mail",
version: "1",
chainId: chain.id,
verifyingContract: smartAccountAddress
},
types: {
Person: [
{ name: "name", type: "string" },
{ name: "wallet", type: "address" }
],
Mail: [
{ name: "from", type: "Person" },
{ name: "to", type: "Person" },
{ name: "contents", type: "string" }
]
},
primaryType: "Mail" as const,
message: {
from: {
name: "Cow",
wallet: "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"
},
to: {
name: "Bob",
wallet: "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"
},
contents: "Hello, Bob!"
}
}

const signature = await smartAccount.signTypedData(typedData)
const isVerified = await publicClient.verifyTypedData({
address: account.address,
signature,
...typedData
})
expect(isVerified).toBeTruthy()
}
)
})
Loading