-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
552ca20
commit b4114f1
Showing
5 changed files
with
216 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { getAddress, type Address } from "viem"; | ||
import type { ChainAwareAddress } from "../../db/schema"; | ||
import { chainShortNames } from "./eip3770-shortnames"; | ||
import type { TypedDataDomain } from "abitype/zod"; | ||
|
||
type EIP712Domain = Zod.infer<typeof TypedDataDomain>; | ||
|
||
type LinkingMessage = { | ||
address: Address; | ||
groupId: string; | ||
}; | ||
|
||
export function getLinkWalletEIP712TypedData( | ||
safeAddress: ChainAwareAddress, | ||
groupId: string, | ||
) { | ||
const [chainShortName, addressFromSplit] = safeAddress.split(":"); | ||
|
||
if (!chainShortName || !addressFromSplit) { | ||
throw new Error("Invalid safe address"); | ||
} | ||
|
||
const address = getAddress(addressFromSplit); | ||
|
||
const [chainId] = | ||
Object.entries(chainShortNames).find( | ||
([_, shortName]) => shortName === chainShortName, | ||
) ?? []; | ||
|
||
if (!chainId) { | ||
throw new Error(`Chain ${chainShortName} not supported`); | ||
} | ||
|
||
const domain: EIP712Domain = { | ||
name: "Link Safe With XMTP Group Chat", | ||
version: "1", | ||
chainId: Number(chainId), | ||
}; | ||
|
||
const types = { | ||
EIP712Domain: [ | ||
{ name: "name", type: "string" }, | ||
{ name: "version", type: "string" }, | ||
{ name: "chainId", type: "uint256" }, | ||
], | ||
LinkingMessage: [ | ||
{ name: "address", type: "address" }, | ||
{ name: "groupId", type: "string" }, | ||
], | ||
}; | ||
|
||
const message: LinkingMessage = { address, groupId }; | ||
|
||
return { | ||
domain, | ||
types, | ||
primaryType: "LinkingMessage" as const, | ||
message, | ||
}; | ||
} |
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