@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
package/dist/cjs/browser.js
CHANGED
|
@@ -11983,6 +11983,14 @@ const restakeEIP712Types = {
|
|
|
11983
11983
|
{ name: "deadline", type: "uint256" },
|
|
11984
11984
|
],
|
|
11985
11985
|
};
|
|
11986
|
+
const commitKickstarterEIP712Types = {
|
|
11987
|
+
CommitKickstarter: [
|
|
11988
|
+
{ name: "nonce", type: "uint256" },
|
|
11989
|
+
{ name: "amount", type: "uint256" },
|
|
11990
|
+
{ name: "kickstarterId", type: "string" },
|
|
11991
|
+
{ name: "deadline", type: "uint256" },
|
|
11992
|
+
],
|
|
11993
|
+
};
|
|
11986
11994
|
// Separate request schemas for clarity between stake and unstake
|
|
11987
11995
|
const stakeSignatureRequestSchema = z.object({
|
|
11988
11996
|
wallet: z.string().regex(/^0x[a-fA-F0-9]{40}$/),
|
|
@@ -12018,6 +12026,14 @@ const restakeSignatureRequestSchema = z.object({
|
|
|
12018
12026
|
toZoneId: z.string(),
|
|
12019
12027
|
deadline: z.string(),
|
|
12020
12028
|
});
|
|
12029
|
+
const commitKickstarterSignatureRequestSchema = z.object({
|
|
12030
|
+
wallet: z.string().regex(/^0x[a-fA-F0-9]{40}$/),
|
|
12031
|
+
signature: z.string().regex(/^0x[a-fA-F0-9]{130}$/),
|
|
12032
|
+
nonce: z.string(),
|
|
12033
|
+
amount: z.string(),
|
|
12034
|
+
kickstarterId: z.string(),
|
|
12035
|
+
deadline: z.string(),
|
|
12036
|
+
});
|
|
12021
12037
|
function isDeadlineExpired(deadline) {
|
|
12022
12038
|
const nowSeconds = BigInt(Math.floor(Date.now() / 1000));
|
|
12023
12039
|
return deadline < nowSeconds;
|
|
@@ -12084,6 +12100,21 @@ function buildRestakeMessage(req) {
|
|
|
12084
12100
|
throw new Error("Zone must be non-negative");
|
|
12085
12101
|
return { nonce, amount, fromZoneId, toZoneId, deadline };
|
|
12086
12102
|
}
|
|
12103
|
+
function buildCommitKickstarterMessage(req) {
|
|
12104
|
+
const nonce = BigInt(req.nonce);
|
|
12105
|
+
const amount = BigInt(req.amount);
|
|
12106
|
+
const deadline = BigInt(req.deadline);
|
|
12107
|
+
const kickstarterId = req.kickstarterId;
|
|
12108
|
+
if (nonce < 0n)
|
|
12109
|
+
throw new Error("Nonce must be non-negative");
|
|
12110
|
+
if (amount < 0n)
|
|
12111
|
+
throw new Error("Amount must be non-negative");
|
|
12112
|
+
if (deadline < 0n)
|
|
12113
|
+
throw new Error("Deadline must be non-negative");
|
|
12114
|
+
if (!kickstarterId)
|
|
12115
|
+
throw new Error("kickstarterId must be non-empty");
|
|
12116
|
+
return { nonce, amount, kickstarterId, deadline };
|
|
12117
|
+
}
|
|
12087
12118
|
// Helper to validate the signature using viem
|
|
12088
12119
|
async function validateStakeSignature(input, domain = stakeControlEIP712Domain) {
|
|
12089
12120
|
const message = buildStakeMessage({
|
|
@@ -12195,6 +12226,33 @@ async function validateRestakeSignature(input, domain = stakeControlEIP712Domain
|
|
|
12195
12226
|
return { valid: false, recovered: null, reason: "signature_failed" };
|
|
12196
12227
|
}
|
|
12197
12228
|
}
|
|
12229
|
+
async function validateCommitKickstarterSignature(input, domain = stakeControlEIP712Domain) {
|
|
12230
|
+
const message = buildCommitKickstarterMessage({
|
|
12231
|
+
nonce: input.nonce,
|
|
12232
|
+
amount: input.amount,
|
|
12233
|
+
kickstarterId: input.kickstarterId,
|
|
12234
|
+
deadline: input.deadline,
|
|
12235
|
+
});
|
|
12236
|
+
if (isDeadlineExpired(message.deadline)) {
|
|
12237
|
+
return { valid: false, recovered: null, reason: "deadline_expired" };
|
|
12238
|
+
}
|
|
12239
|
+
try {
|
|
12240
|
+
const verified = await viem.verifyTypedData({
|
|
12241
|
+
address: input.wallet,
|
|
12242
|
+
domain,
|
|
12243
|
+
types: commitKickstarterEIP712Types,
|
|
12244
|
+
primaryType: "CommitKickstarter",
|
|
12245
|
+
message,
|
|
12246
|
+
signature: input.signature,
|
|
12247
|
+
});
|
|
12248
|
+
return verified
|
|
12249
|
+
? { valid: true, recovered: input.wallet, reason: null }
|
|
12250
|
+
: { valid: false, recovered: null, reason: "signer_mismatch" };
|
|
12251
|
+
}
|
|
12252
|
+
catch (_) {
|
|
12253
|
+
return { valid: false, recovered: null, reason: "signature_failed" };
|
|
12254
|
+
}
|
|
12255
|
+
}
|
|
12198
12256
|
|
|
12199
12257
|
exports.ControlRouter = regionRouter.ControlRouter;
|
|
12200
12258
|
exports.DECIMALS_BY_TOKEN = regionRouter.DECIMALS_BY_TOKEN;
|
|
@@ -12215,10 +12273,13 @@ exports.getAddresses = regionRouter.getAddresses;
|
|
|
12215
12273
|
exports.regionMetadata = regionRouter.regionMetadata;
|
|
12216
12274
|
exports.usStates = regionRouter.usStates;
|
|
12217
12275
|
exports.useForwarder = regionRouter.useForwarder;
|
|
12276
|
+
exports.buildCommitKickstarterMessage = buildCommitKickstarterMessage;
|
|
12218
12277
|
exports.buildRestakeMessage = buildRestakeMessage;
|
|
12219
12278
|
exports.buildStakeMessage = buildStakeMessage;
|
|
12220
12279
|
exports.buildUnstakeMoveMessage = buildUnstakeMoveMessage;
|
|
12221
12280
|
exports.buildUnstakeUnlockMessage = buildUnstakeUnlockMessage;
|
|
12281
|
+
exports.commitKickstarterEIP712Types = commitKickstarterEIP712Types;
|
|
12282
|
+
exports.commitKickstarterSignatureRequestSchema = commitKickstarterSignatureRequestSchema;
|
|
12222
12283
|
exports.restakeEIP712Types = restakeEIP712Types;
|
|
12223
12284
|
exports.restakeSignatureRequestSchema = restakeSignatureRequestSchema;
|
|
12224
12285
|
exports.stakeControlEIP712Domain = stakeControlEIP712Domain;
|
|
@@ -12228,6 +12289,7 @@ exports.unstakeMoveEIP712Types = unstakeMoveEIP712Types;
|
|
|
12228
12289
|
exports.unstakeMoveSignatureRequestSchema = unstakeMoveSignatureRequestSchema;
|
|
12229
12290
|
exports.unstakeUnlockEIP712Types = unstakeUnlockEIP712Types;
|
|
12230
12291
|
exports.unstakeUnlockSignatureRequestSchema = unstakeUnlockSignatureRequestSchema;
|
|
12292
|
+
exports.validateCommitKickstarterSignature = validateCommitKickstarterSignature;
|
|
12231
12293
|
exports.validateRestakeSignature = validateRestakeSignature;
|
|
12232
12294
|
exports.validateStakeSignature = validateStakeSignature;
|
|
12233
12295
|
exports.validateUnstakeMoveSignature = validateUnstakeMoveSignature;
|