@glowlabs-org/utils 0.2.50 → 0.2.52

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.
@@ -1,9 +1,9 @@
1
1
  import z from "zod";
2
- export declare const stakeControlEIP712Domain: {
3
- readonly name: "ControlManager";
4
- readonly version: "1";
5
- readonly chainId: number;
6
- readonly verifyingContract: "0x0000000000000000000000000000000000000000";
2
+ export declare const stakeControlEIP712Domain: (chainId: number) => {
3
+ name: string;
4
+ version: string;
5
+ chainId: number;
6
+ verifyingContract: "0x0000000000000000000000000000000000000000";
7
7
  };
8
8
  export declare const stakeEIP712Types: {
9
9
  readonly Stake: readonly [{
@@ -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;
152
- export declare function validateStakeSignature(input: StakeSignatureRequest, domain?: typeof stakeControlEIP712Domain): Promise<SignatureValidationResult>;
153
- export declare function validateUnstakeUnlockSignature(input: UnstakeUnlockSignatureRequest, domain?: typeof stakeControlEIP712Domain): Promise<SignatureValidationResult>;
154
- export declare function validateUnstakeMoveSignature(input: UnstakeMoveSignatureRequest, domain?: typeof stakeControlEIP712Domain): Promise<SignatureValidationResult>;
155
- export declare function validateRestakeSignature(input: RestakeSignatureRequest, domain?: typeof stakeControlEIP712Domain): Promise<SignatureValidationResult>;
183
+ export declare function buildCommitKickstarterMessage(req: CommitKickstarterMessageInput): CommitKickstarterMessage;
184
+ export declare function validateStakeSignature(input: StakeSignatureRequest, domain?: ReturnType<typeof stakeControlEIP712Domain>): Promise<SignatureValidationResult>;
185
+ export declare function validateUnstakeUnlockSignature(input: UnstakeUnlockSignatureRequest, domain?: ReturnType<typeof stakeControlEIP712Domain>): Promise<SignatureValidationResult>;
186
+ export declare function validateUnstakeMoveSignature(input: UnstakeMoveSignatureRequest, domain?: ReturnType<typeof stakeControlEIP712Domain>): Promise<SignatureValidationResult>;
187
+ export declare function validateRestakeSignature(input: RestakeSignatureRequest, domain?: ReturnType<typeof stakeControlEIP712Domain>): Promise<SignatureValidationResult>;
188
+ export declare function validateCommitKickstarterSignature(input: CommitKickstarterSignatureRequest, domain?: ReturnType<typeof stakeControlEIP712Domain>): Promise<SignatureValidationResult>;
156
189
  export {};
@@ -11939,12 +11939,12 @@ var z = /*#__PURE__*/Object.freeze({
11939
11939
  xid: xid
11940
11940
  });
11941
11941
 
11942
- const stakeControlEIP712Domain = {
11942
+ const stakeControlEIP712Domain = (chainId) => ({
11943
11943
  name: "ControlManager",
11944
11944
  version: "1",
11945
- chainId: Number(process.env.CHAIN_ID) || 1,
11945
+ chainId,
11946
11946
  verifyingContract: "0x0000000000000000000000000000000000000000",
11947
- };
11947
+ });
11948
11948
  // Distinct EIP-712 type sets for stake vs unstake
11949
11949
  const stakeEIP712Types = {
11950
11950
  Stake: [
@@ -11981,6 +11981,14 @@ const restakeEIP712Types = {
11981
11981
  { name: "deadline", type: "uint256" },
11982
11982
  ],
11983
11983
  };
11984
+ const commitKickstarterEIP712Types = {
11985
+ CommitKickstarter: [
11986
+ { name: "nonce", type: "uint256" },
11987
+ { name: "amount", type: "uint256" },
11988
+ { name: "kickstarterId", type: "string" },
11989
+ { name: "deadline", type: "uint256" },
11990
+ ],
11991
+ };
11984
11992
  // Separate request schemas for clarity between stake and unstake
11985
11993
  const stakeSignatureRequestSchema = z.object({
11986
11994
  wallet: z.string().regex(/^0x[a-fA-F0-9]{40}$/),
@@ -12016,6 +12024,14 @@ const restakeSignatureRequestSchema = z.object({
12016
12024
  toZoneId: z.string(),
12017
12025
  deadline: z.string(),
12018
12026
  });
12027
+ const commitKickstarterSignatureRequestSchema = z.object({
12028
+ wallet: z.string().regex(/^0x[a-fA-F0-9]{40}$/),
12029
+ signature: z.string().regex(/^0x[a-fA-F0-9]{130}$/),
12030
+ nonce: z.string(),
12031
+ amount: z.string(),
12032
+ kickstarterId: z.string(),
12033
+ deadline: z.string(),
12034
+ });
12019
12035
  function isDeadlineExpired(deadline) {
12020
12036
  const nowSeconds = BigInt(Math.floor(Date.now() / 1000));
12021
12037
  return deadline < nowSeconds;
@@ -12082,8 +12098,23 @@ function buildRestakeMessage(req) {
12082
12098
  throw new Error("Zone must be non-negative");
12083
12099
  return { nonce, amount, fromZoneId, toZoneId, deadline };
12084
12100
  }
12101
+ function buildCommitKickstarterMessage(req) {
12102
+ const nonce = BigInt(req.nonce);
12103
+ const amount = BigInt(req.amount);
12104
+ const deadline = BigInt(req.deadline);
12105
+ const kickstarterId = req.kickstarterId;
12106
+ if (nonce < 0n)
12107
+ throw new Error("Nonce must be non-negative");
12108
+ if (amount < 0n)
12109
+ throw new Error("Amount must be non-negative");
12110
+ if (deadline < 0n)
12111
+ throw new Error("Deadline must be non-negative");
12112
+ if (!kickstarterId)
12113
+ throw new Error("kickstarterId must be non-empty");
12114
+ return { nonce, amount, kickstarterId, deadline };
12115
+ }
12085
12116
  // Helper to validate the signature using viem
12086
- async function validateStakeSignature(input, domain = stakeControlEIP712Domain) {
12117
+ async function validateStakeSignature(input, domain = stakeControlEIP712Domain(1)) {
12087
12118
  const message = buildStakeMessage({
12088
12119
  nonce: input.nonce,
12089
12120
  amount: input.amount,
@@ -12110,7 +12141,7 @@ async function validateStakeSignature(input, domain = stakeControlEIP712Domain)
12110
12141
  return { valid: false, recovered: null, reason: "signature_failed" };
12111
12142
  }
12112
12143
  }
12113
- async function validateUnstakeUnlockSignature(input, domain = stakeControlEIP712Domain) {
12144
+ async function validateUnstakeUnlockSignature(input, domain = stakeControlEIP712Domain(1)) {
12114
12145
  const message = buildUnstakeUnlockMessage({
12115
12146
  nonce: input.nonce,
12116
12147
  amount: input.amount,
@@ -12137,7 +12168,7 @@ async function validateUnstakeUnlockSignature(input, domain = stakeControlEIP712
12137
12168
  return { valid: false, recovered: null, reason: "signature_failed" };
12138
12169
  }
12139
12170
  }
12140
- async function validateUnstakeMoveSignature(input, domain = stakeControlEIP712Domain) {
12171
+ async function validateUnstakeMoveSignature(input, domain = stakeControlEIP712Domain(1)) {
12141
12172
  const message = buildUnstakeMoveMessage({
12142
12173
  nonce: input.nonce,
12143
12174
  amount: input.amount,
@@ -12165,7 +12196,7 @@ async function validateUnstakeMoveSignature(input, domain = stakeControlEIP712Do
12165
12196
  return { valid: false, recovered: null, reason: "signature_failed" };
12166
12197
  }
12167
12198
  }
12168
- async function validateRestakeSignature(input, domain = stakeControlEIP712Domain) {
12199
+ async function validateRestakeSignature(input, domain = stakeControlEIP712Domain(1)) {
12169
12200
  const message = buildRestakeMessage({
12170
12201
  nonce: input.nonce,
12171
12202
  amount: input.amount,
@@ -12193,6 +12224,33 @@ async function validateRestakeSignature(input, domain = stakeControlEIP712Domain
12193
12224
  return { valid: false, recovered: null, reason: "signature_failed" };
12194
12225
  }
12195
12226
  }
12227
+ async function validateCommitKickstarterSignature(input, domain = stakeControlEIP712Domain(1)) {
12228
+ const message = buildCommitKickstarterMessage({
12229
+ nonce: input.nonce,
12230
+ amount: input.amount,
12231
+ kickstarterId: input.kickstarterId,
12232
+ deadline: input.deadline,
12233
+ });
12234
+ if (isDeadlineExpired(message.deadline)) {
12235
+ return { valid: false, recovered: null, reason: "deadline_expired" };
12236
+ }
12237
+ try {
12238
+ const verified = await verifyTypedData({
12239
+ address: input.wallet,
12240
+ domain,
12241
+ types: commitKickstarterEIP712Types,
12242
+ primaryType: "CommitKickstarter",
12243
+ message,
12244
+ signature: input.signature,
12245
+ });
12246
+ return verified
12247
+ ? { valid: true, recovered: input.wallet, reason: null }
12248
+ : { valid: false, recovered: null, reason: "signer_mismatch" };
12249
+ }
12250
+ catch (_) {
12251
+ return { valid: false, recovered: null, reason: "signature_failed" };
12252
+ }
12253
+ }
12196
12254
 
12197
- export { buildRestakeMessage, buildStakeMessage, buildUnstakeMoveMessage, buildUnstakeUnlockMessage, restakeEIP712Types, restakeSignatureRequestSchema, stakeControlEIP712Domain, stakeEIP712Types, stakeSignatureRequestSchema, unstakeMoveEIP712Types, unstakeMoveSignatureRequestSchema, unstakeUnlockEIP712Types, unstakeUnlockSignatureRequestSchema, validateRestakeSignature, validateStakeSignature, validateUnstakeMoveSignature, validateUnstakeUnlockSignature };
12255
+ export { buildCommitKickstarterMessage, buildRestakeMessage, buildStakeMessage, buildUnstakeMoveMessage, buildUnstakeUnlockMessage, commitKickstarterEIP712Types, commitKickstarterSignatureRequestSchema, restakeEIP712Types, restakeSignatureRequestSchema, stakeControlEIP712Domain, stakeEIP712Types, stakeSignatureRequestSchema, unstakeMoveEIP712Types, unstakeMoveSignatureRequestSchema, unstakeUnlockEIP712Types, unstakeUnlockSignatureRequestSchema, validateCommitKickstarterSignature, validateRestakeSignature, validateStakeSignature, validateUnstakeMoveSignature, validateUnstakeUnlockSignature };
12198
12256
  //# sourceMappingURL=browser.js.map