@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.
- package/dist/cjs/browser.js +62 -0
- package/dist/cjs/browser.js.map +1 -1
- package/dist/cjs/utils/stake-control.d.ts +33 -0
- package/dist/esm/browser.js +59 -1
- package/dist/esm/browser.js.map +1 -1
- package/dist/esm/utils/stake-control.d.ts +33 -0
- package/package.json +1 -1
- package/src/utils/stake-control.ts +77 -0
|
@@ -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/dist/esm/browser.js
CHANGED
|
@@ -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,6 +12098,21 @@ 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
12117
|
async function validateStakeSignature(input, domain = stakeControlEIP712Domain) {
|
|
12087
12118
|
const message = buildStakeMessage({
|
|
@@ -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) {
|
|
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
|