Skip to content

Commit

Permalink
Add name to permitV2 and create form
Browse files Browse the repository at this point in the history
  • Loading branch information
architect-dev committed Nov 27, 2024
1 parent ff764d5 commit 74052b8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
17 changes: 11 additions & 6 deletions packages/nextjs/components/PermitModal/Create/Create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,17 @@ export const PermitV2ModalCreate = () => {
</button>
</div>

{/* Name */}
<div className="flex flex-row items-center justify-start gap-4">
<div className="text-sm font-bold">Name:</div>
<InputBase
name="permit-name"
value={name}
placeholder="Unnamed Permit"
onChange={(value: string) => setName(value)}
/>
</div>

{/* (Sharing) Recipient */}
{type === PermitV2CreateType.Sharing && (
<div className="flex flex-row items-center justify-start gap-4">
Expand All @@ -162,12 +173,6 @@ export const PermitV2ModalCreate = () => {
</div>
)}

{/* Name */}
<div className="flex flex-row items-center justify-start gap-4">
<div className="text-sm font-bold">Name (optional):</div>
<InputBase name="permit-name" value={name} placeholder="name" onChange={(value: string) => setName(value)} />
</div>

{/* Expiration */}
<div className="flex flex-row items-center justify-start gap-4">
<div className="text-sm font-bold">Expires in:</div>
Expand Down
15 changes: 7 additions & 8 deletions packages/nextjs/permits/permitV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import { getSignatureTypesAndMessage, SignatureTypes } from "./generate";

export class PermitV2 implements PermitV2Interface {
/**
* Optional name for this permit, only for organization and UX
* Name for this permit, only for organization and UX
*/
public name?: string;
public name: string;
/**
* The type of the PermitV2 (self / sharing)
* (self) Permit that will be signed and used by the issuer
Expand Down Expand Up @@ -79,7 +79,7 @@ export class PermitV2 implements PermitV2Interface {
*/
public recipientSignature: string;

public constructor(options: PermitV2Interface & { name?: string }) {
public constructor(options: PermitV2Interface) {
this.name = options.name;
this.type = options.type;
this.issuer = options.issuer;
Expand All @@ -94,7 +94,7 @@ export class PermitV2 implements PermitV2Interface {
this.recipientSignature = options.recipientSignature;
}

static async create(options: PermitV2Options & { name?: string }) {
static async create(options: PermitV2Options) {
const { success, data: parsed, error } = PermitV2ParamsValidator.safeParse(options);

if (!success) {
Expand All @@ -107,14 +107,13 @@ export class PermitV2 implements PermitV2Interface {
: await GenerateSealingKey();

return new PermitV2({
name: options.name,
...parsed,
sealingPair,
});
}

static async createAndSign(
options: PermitV2Options & { name?: string },
options: PermitV2Options,
chainId: string | undefined,
signer: AbstractSigner | undefined,
) {
Expand Down Expand Up @@ -145,7 +144,7 @@ export class PermitV2 implements PermitV2Interface {
* Utility to extract the public data from a permit.
* Used in `serialize`, `getPermission`, `getHash` etc
*/
getInterface = (): PermitV2Interface & { name?: string } => {
getInterface = (): PermitV2Interface => {
return {
name: this.name,
type: this.type,
Expand Down Expand Up @@ -203,7 +202,7 @@ export class PermitV2 implements PermitV2Interface {
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { type, sealingPair, ...permit } = permitData;
const { name, type, sealingPair, ...permit } = permitData;
return {
...permit,
sealingKey: `0x${sealingPair.publicKey}`,
Expand Down
1 change: 1 addition & 0 deletions packages/nextjs/permits/permitV2.z.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const SerializedSealingPair = z.object({
});

const zPermitV2WithDefaults = z.object({
name: z.string().optional().default("Unnamed Permit"),
type: z.enum(["self", "sharing", "recipient"]),
issuer: z.string().refine(val => val !== zeroAddress, {
message: "PermitV2 issuer :: must not be zeroAddress",
Expand Down
6 changes: 5 additions & 1 deletion packages/nextjs/permits/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ export interface AbstractSigner {
* Type representing the full PermitV2
*/
export type PermitV2Interface = {
/**
* Name for this permit, only for organization and UX
*/
name: string;
/**
* The type of the PermitV2 (self / sharing)
* (self) Permit that will be signed and used by the issuer
Expand Down Expand Up @@ -363,7 +367,7 @@ export type SerializedPermitV2 = Omit<PermitV2Interface, "sealingPair"> & {
* A type representing the PermissionV2 struct that is passed to PermissionedV2.sol to grant encrypted data access.
*/
export type PermissionV2 = Expand<
Omit<PermitV2Interface, "type" | "sealingPair"> & {
Omit<PermitV2Interface, "name" | "type" | "sealingPair"> & {
sealingKey: string;
}
>;
Expand Down

0 comments on commit 74052b8

Please sign in to comment.