mirror of
https://github.com/luxfhe/example-smart-wallet.git
synced 2026-10-30 18:13:16 +00:00
- @luxfhe/wasm: ^0.2.0 - @luxfhe/kms: ^0.2.0 - @luxfhe/relayer-sdk: ^0.6.0 - @luxfhe/mock-contracts: ^0.6.0 - Remove deprecated Zama dependencies
71 lines
2.2 KiB
TypeScript
71 lines
2.2 KiB
TypeScript
import { EIP712Message } from "@luxfhe/sdk";
|
|
import { PermissionV2 } from "./types";
|
|
import { EIP712Types } from "@luxfhe/sdk";
|
|
import { zeroAddress } from "viem";
|
|
|
|
const PermitV2SignatureAllFields = [
|
|
{ name: "issuer", type: "address" },
|
|
{ name: "expiration", type: "uint64" },
|
|
{ name: "contracts", type: "address[]" },
|
|
{ name: "projects", type: "string[]" },
|
|
{ name: "recipient", type: "address" },
|
|
{ name: "validatorId", type: "uint256" },
|
|
{ name: "validatorContract", type: "address" },
|
|
{ name: "sealingKey", type: "bytes32" },
|
|
{ name: "issuerSignature", type: "bytes" },
|
|
] as const;
|
|
type PermitV2SignatureFieldOption = (typeof PermitV2SignatureAllFields)[number]["name"];
|
|
|
|
export const SignatureTypes = {
|
|
PermissionedV2IssuerSelf: [
|
|
"issuer",
|
|
"expiration",
|
|
"contracts",
|
|
"projects",
|
|
"recipient",
|
|
"validatorId",
|
|
"validatorContract",
|
|
"sealingKey",
|
|
] satisfies PermitV2SignatureFieldOption[],
|
|
PermissionedV2IssuerShared: [
|
|
"issuer",
|
|
"expiration",
|
|
"contracts",
|
|
"projects",
|
|
"recipient",
|
|
"validatorId",
|
|
"validatorContract",
|
|
] satisfies PermitV2SignatureFieldOption[],
|
|
PermissionedV2Recipient: ["sealingKey", "issuerSignature"] satisfies PermitV2SignatureFieldOption[],
|
|
} as const;
|
|
export type PermitV2SignaturePrimaryType = keyof typeof SignatureTypes;
|
|
|
|
export const getSignatureTypesAndMessage = <T extends PermitV2SignatureFieldOption>(
|
|
primaryType: PermitV2SignaturePrimaryType,
|
|
fields: T[] | readonly T[],
|
|
values: Pick<PermissionV2, T> & Partial<PermissionV2>,
|
|
): { types: EIP712Types; primaryType: string; message: EIP712Message } => {
|
|
const types = {
|
|
[primaryType]: PermitV2SignatureAllFields.filter(fieldType => fields.includes(fieldType.name as T)),
|
|
};
|
|
|
|
const message: Record<T, string | string[] | number | number[]> = {} as Record<
|
|
T,
|
|
string | string[] | number | number[]
|
|
>;
|
|
fields.forEach(field => {
|
|
if (field in values) {
|
|
message[field] = values[field];
|
|
}
|
|
});
|
|
|
|
return { types, primaryType, message: message as EIP712Message };
|
|
};
|
|
|
|
export const getSignatureDomain = (chainId: string) => ({
|
|
name: "LuxFHE Permission v2.0.0",
|
|
version: "v2.0.0",
|
|
chainId: parseInt(chainId),
|
|
verifyingContract: zeroAddress,
|
|
});
|