@glowlabs-org/utils 0.2.50 → 0.2.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -71,6 +71,21 @@ export declare const restakeEIP712Types: {
71
71
  readonly type: "uint256";
72
72
  }];
73
73
  };
74
+ export declare const commitKickstarterEIP712Types: {
75
+ readonly CommitKickstarter: readonly [{
76
+ readonly name: "nonce";
77
+ readonly type: "uint256";
78
+ }, {
79
+ readonly name: "amount";
80
+ readonly type: "uint256";
81
+ }, {
82
+ readonly name: "kickstarterId";
83
+ readonly type: "string";
84
+ }, {
85
+ readonly name: "deadline";
86
+ readonly type: "uint256";
87
+ }];
88
+ };
74
89
  export declare const stakeSignatureRequestSchema: z.ZodObject<{
75
90
  wallet: z.ZodString;
76
91
  signature: z.ZodString;
@@ -105,10 +120,19 @@ export declare const restakeSignatureRequestSchema: z.ZodObject<{
105
120
  toZoneId: z.ZodString;
106
121
  deadline: z.ZodString;
107
122
  }, z.core.$strip>;
123
+ export declare const commitKickstarterSignatureRequestSchema: z.ZodObject<{
124
+ wallet: z.ZodString;
125
+ signature: z.ZodString;
126
+ nonce: z.ZodString;
127
+ amount: z.ZodString;
128
+ kickstarterId: z.ZodString;
129
+ deadline: z.ZodString;
130
+ }, z.core.$strip>;
108
131
  export type StakeSignatureRequest = z.infer<typeof stakeSignatureRequestSchema>;
109
132
  export type UnstakeUnlockSignatureRequest = z.infer<typeof unstakeUnlockSignatureRequestSchema>;
110
133
  export type UnstakeMoveSignatureRequest = z.infer<typeof unstakeMoveSignatureRequestSchema>;
111
134
  export type RestakeSignatureRequest = z.infer<typeof restakeSignatureRequestSchema>;
135
+ export type CommitKickstarterSignatureRequest = z.infer<typeof commitKickstarterSignatureRequestSchema>;
112
136
  export type StakeMessage = {
113
137
  nonce: bigint;
114
138
  amount: bigint;
@@ -135,6 +159,12 @@ export type RestakeMessage = {
135
159
  toZoneId: bigint;
136
160
  deadline: bigint;
137
161
  };
162
+ export type CommitKickstarterMessage = {
163
+ nonce: bigint;
164
+ amount: bigint;
165
+ kickstarterId: string;
166
+ deadline: bigint;
167
+ };
138
168
  export type SignatureValidationReason = "deadline_expired" | "signature_failed" | "signer_mismatch" | null;
139
169
  export type SignatureValidationResult = {
140
170
  valid: boolean;
@@ -145,12 +175,15 @@ type StakeMessageInput = Pick<StakeSignatureRequest, "nonce" | "amount" | "toZon
145
175
  type UnstakeUnlockMessageInput = Pick<UnstakeUnlockSignatureRequest, "nonce" | "amount" | "fromZoneId" | "deadline">;
146
176
  type UnstakeMoveMessageInput = Pick<UnstakeMoveSignatureRequest, "nonce" | "amount" | "fromZoneId" | "toZoneId" | "deadline">;
147
177
  type RestakeMessageInput = Pick<RestakeSignatureRequest, "nonce" | "amount" | "fromZoneId" | "toZoneId" | "deadline">;
178
+ type CommitKickstarterMessageInput = Pick<CommitKickstarterSignatureRequest, "nonce" | "amount" | "kickstarterId" | "deadline">;
148
179
  export declare function buildStakeMessage(req: StakeMessageInput): StakeMessage;
149
180
  export declare function buildUnstakeUnlockMessage(req: UnstakeUnlockMessageInput): UnstakeUnlockMessage;
150
181
  export declare function buildUnstakeMoveMessage(req: UnstakeMoveMessageInput): UnstakeMoveMessage;
151
182
  export declare function buildRestakeMessage(req: RestakeMessageInput): RestakeMessage;
183
+ export declare function buildCommitKickstarterMessage(req: CommitKickstarterMessageInput): CommitKickstarterMessage;
152
184
  export declare function validateStakeSignature(input: StakeSignatureRequest, domain?: typeof stakeControlEIP712Domain): Promise<SignatureValidationResult>;
153
185
  export declare function validateUnstakeUnlockSignature(input: UnstakeUnlockSignatureRequest, domain?: typeof stakeControlEIP712Domain): Promise<SignatureValidationResult>;
154
186
  export declare function validateUnstakeMoveSignature(input: UnstakeMoveSignatureRequest, domain?: typeof stakeControlEIP712Domain): Promise<SignatureValidationResult>;
155
187
  export declare function validateRestakeSignature(input: RestakeSignatureRequest, domain?: typeof stakeControlEIP712Domain): Promise<SignatureValidationResult>;
188
+ export declare function validateCommitKickstarterSignature(input: CommitKickstarterSignatureRequest, domain?: typeof stakeControlEIP712Domain): Promise<SignatureValidationResult>;
156
189
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glowlabs-org/utils",
3
- "version": "0.2.50",
3
+ "version": "0.2.51",
4
4
  "description": "A library containing all typechain types and addresses relating to the glow guarded launch",
5
5
  "keywords": [],
6
6
  "author": "",
@@ -48,6 +48,15 @@ export const restakeEIP712Types = {
48
48
  ],
49
49
  } as const;
50
50
 
51
+ export const commitKickstarterEIP712Types = {
52
+ CommitKickstarter: [
53
+ { name: "nonce", type: "uint256" },
54
+ { name: "amount", type: "uint256" },
55
+ { name: "kickstarterId", type: "string" },
56
+ { name: "deadline", type: "uint256" },
57
+ ],
58
+ } as const;
59
+
51
60
  // Separate request schemas for clarity between stake and unstake
52
61
  export const stakeSignatureRequestSchema = z.object({
53
62
  wallet: z.string().regex(/^0x[a-fA-F0-9]{40}$/),
@@ -87,6 +96,15 @@ export const restakeSignatureRequestSchema = z.object({
87
96
  deadline: z.string(),
88
97
  });
89
98
 
99
+ export const commitKickstarterSignatureRequestSchema = z.object({
100
+ wallet: z.string().regex(/^0x[a-fA-F0-9]{40}$/),
101
+ signature: z.string().regex(/^0x[a-fA-F0-9]{130}$/),
102
+ nonce: z.string(),
103
+ amount: z.string(),
104
+ kickstarterId: z.string(),
105
+ deadline: z.string(),
106
+ });
107
+
90
108
  export type StakeSignatureRequest = z.infer<typeof stakeSignatureRequestSchema>;
91
109
  export type UnstakeUnlockSignatureRequest = z.infer<
92
110
  typeof unstakeUnlockSignatureRequestSchema
@@ -97,6 +115,9 @@ export type UnstakeMoveSignatureRequest = z.infer<
97
115
  export type RestakeSignatureRequest = z.infer<
98
116
  typeof restakeSignatureRequestSchema
99
117
  >;
118
+ export type CommitKickstarterSignatureRequest = z.infer<
119
+ typeof commitKickstarterSignatureRequestSchema
120
+ >;
100
121
 
101
122
  export type StakeMessage = {
102
123
  nonce: bigint;
@@ -128,6 +149,13 @@ export type RestakeMessage = {
128
149
  deadline: bigint;
129
150
  };
130
151
 
152
+ export type CommitKickstarterMessage = {
153
+ nonce: bigint;
154
+ amount: bigint;
155
+ kickstarterId: string;
156
+ deadline: bigint;
157
+ };
158
+
131
159
  export type SignatureValidationReason =
132
160
  | "deadline_expired"
133
161
  | "signature_failed"
@@ -163,6 +191,11 @@ type RestakeMessageInput = Pick<
163
191
  "nonce" | "amount" | "fromZoneId" | "toZoneId" | "deadline"
164
192
  >;
165
193
 
194
+ type CommitKickstarterMessageInput = Pick<
195
+ CommitKickstarterSignatureRequest,
196
+ "nonce" | "amount" | "kickstarterId" | "deadline"
197
+ >;
198
+
166
199
  export function buildStakeMessage(req: StakeMessageInput): StakeMessage {
167
200
  const nonce = BigInt(req.nonce);
168
201
  const amount = BigInt(req.amount);
@@ -219,6 +252,20 @@ export function buildRestakeMessage(req: RestakeMessageInput): RestakeMessage {
219
252
  return { nonce, amount, fromZoneId, toZoneId, deadline };
220
253
  }
221
254
 
255
+ export function buildCommitKickstarterMessage(
256
+ req: CommitKickstarterMessageInput
257
+ ): CommitKickstarterMessage {
258
+ const nonce = BigInt(req.nonce);
259
+ const amount = BigInt(req.amount);
260
+ const deadline = BigInt(req.deadline);
261
+ const kickstarterId = req.kickstarterId;
262
+ if (nonce < 0n) throw new Error("Nonce must be non-negative");
263
+ if (amount < 0n) throw new Error("Amount must be non-negative");
264
+ if (deadline < 0n) throw new Error("Deadline must be non-negative");
265
+ if (!kickstarterId) throw new Error("kickstarterId must be non-empty");
266
+ return { nonce, amount, kickstarterId, deadline };
267
+ }
268
+
222
269
  // Helper to validate the signature using viem
223
270
  export async function validateStakeSignature(
224
271
  input: StakeSignatureRequest,
@@ -341,3 +388,33 @@ export async function validateRestakeSignature(
341
388
  return { valid: false, recovered: null, reason: "signature_failed" };
342
389
  }
343
390
  }
391
+
392
+ export async function validateCommitKickstarterSignature(
393
+ input: CommitKickstarterSignatureRequest,
394
+ domain: typeof stakeControlEIP712Domain = stakeControlEIP712Domain
395
+ ): Promise<SignatureValidationResult> {
396
+ const message = buildCommitKickstarterMessage({
397
+ nonce: input.nonce,
398
+ amount: input.amount,
399
+ kickstarterId: input.kickstarterId,
400
+ deadline: input.deadline,
401
+ });
402
+ if (isDeadlineExpired(message.deadline)) {
403
+ return { valid: false, recovered: null, reason: "deadline_expired" };
404
+ }
405
+ try {
406
+ const verified = await verifyTypedData({
407
+ address: input.wallet as Hex,
408
+ domain,
409
+ types: commitKickstarterEIP712Types,
410
+ primaryType: "CommitKickstarter",
411
+ message,
412
+ signature: input.signature as Hex,
413
+ });
414
+ return verified
415
+ ? { valid: true, recovered: input.wallet, reason: null }
416
+ : { valid: false, recovered: null, reason: "signer_mismatch" };
417
+ } catch (_) {
418
+ return { valid: false, recovered: null, reason: "signature_failed" };
419
+ }
420
+ }