@snapshot-labs/snapshot.js 0.14.11 → 0.14.12
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/snapshot.cjs.js +29 -4
- package/dist/snapshot.esm.js +29 -4
- package/dist/snapshot.min.js +1 -1
- package/package.json +1 -1
- package/src/sign/hashedTypes.json +1 -0
- package/src/verify/starknet.spec.ts +18 -8
- package/src/verify/starknet.ts +33 -5
package/dist/snapshot.cjs.js
CHANGED
|
@@ -2329,14 +2329,39 @@ function getHash(data, address) {
|
|
|
2329
2329
|
const { domain, types, primaryType, message } = data;
|
|
2330
2330
|
return starknet$1.typedData.getMessageHash({ types, primaryType, domain, message }, address);
|
|
2331
2331
|
}
|
|
2332
|
+
/**
|
|
2333
|
+
* Processes a StarkNet signature array and returns the appropriate signature format
|
|
2334
|
+
* for contract verification.
|
|
2335
|
+
* Returns the r ands values for each signature in the array.
|
|
2336
|
+
*
|
|
2337
|
+
* Handles the following cases:
|
|
2338
|
+
* - 2-item array: Standard signature, returns as-is.
|
|
2339
|
+
* - 3-item array: Some wallets (e.g., Braavos) may return a 3-item array; returns the last two items.
|
|
2340
|
+
* - Multi-signer array: For multisig accounts, the array may contain multiple signatures;
|
|
2341
|
+
* this function extracts the relevant signature pairs.
|
|
2342
|
+
*
|
|
2343
|
+
* @param {string[]} sig - The signature array to process. Must have at least 2 items.
|
|
2344
|
+
* @returns {string[]} The processed signature array suitable for contract verification.
|
|
2345
|
+
* @throws {Error} If the signature array has fewer than 2 items.
|
|
2346
|
+
*/
|
|
2347
|
+
function getSignatureArray(sig) {
|
|
2348
|
+
if (sig.length < 2) {
|
|
2349
|
+
throw new Error('Invalid signature format');
|
|
2350
|
+
}
|
|
2351
|
+
if (sig.length <= 3) {
|
|
2352
|
+
return sig.slice(-2);
|
|
2353
|
+
}
|
|
2354
|
+
const results = [];
|
|
2355
|
+
for (let i = 1; i < sig.length; i += 4) {
|
|
2356
|
+
results.push(sig[i + 2], sig[i + 3]);
|
|
2357
|
+
}
|
|
2358
|
+
return results;
|
|
2359
|
+
}
|
|
2332
2360
|
function verify(address_1, sig_1, data_1) {
|
|
2333
2361
|
return __awaiter(this, arguments, void 0, function* (address, sig, data, network = 'SN_MAIN', options = {}) {
|
|
2334
2362
|
try {
|
|
2335
2363
|
const contractAccount = new starknet$1.Contract(ABI, address, getProvider$1(network, options));
|
|
2336
|
-
|
|
2337
|
-
throw new Error('Invalid signature format');
|
|
2338
|
-
}
|
|
2339
|
-
const result = yield contractAccount.is_valid_signature(getHash(data, address), sig.slice(-2));
|
|
2364
|
+
const result = yield contractAccount.is_valid_signature(getHash(data, address), getSignatureArray(sig));
|
|
2340
2365
|
return bignumber.BigNumber.from(result).eq(bignumber.BigNumber.from('370462705988'));
|
|
2341
2366
|
}
|
|
2342
2367
|
catch (e) {
|
package/dist/snapshot.esm.js
CHANGED
|
@@ -2319,14 +2319,39 @@ function getHash(data, address) {
|
|
|
2319
2319
|
const { domain, types, primaryType, message } = data;
|
|
2320
2320
|
return typedData.getMessageHash({ types, primaryType, domain, message }, address);
|
|
2321
2321
|
}
|
|
2322
|
+
/**
|
|
2323
|
+
* Processes a StarkNet signature array and returns the appropriate signature format
|
|
2324
|
+
* for contract verification.
|
|
2325
|
+
* Returns the r ands values for each signature in the array.
|
|
2326
|
+
*
|
|
2327
|
+
* Handles the following cases:
|
|
2328
|
+
* - 2-item array: Standard signature, returns as-is.
|
|
2329
|
+
* - 3-item array: Some wallets (e.g., Braavos) may return a 3-item array; returns the last two items.
|
|
2330
|
+
* - Multi-signer array: For multisig accounts, the array may contain multiple signatures;
|
|
2331
|
+
* this function extracts the relevant signature pairs.
|
|
2332
|
+
*
|
|
2333
|
+
* @param {string[]} sig - The signature array to process. Must have at least 2 items.
|
|
2334
|
+
* @returns {string[]} The processed signature array suitable for contract verification.
|
|
2335
|
+
* @throws {Error} If the signature array has fewer than 2 items.
|
|
2336
|
+
*/
|
|
2337
|
+
function getSignatureArray(sig) {
|
|
2338
|
+
if (sig.length < 2) {
|
|
2339
|
+
throw new Error('Invalid signature format');
|
|
2340
|
+
}
|
|
2341
|
+
if (sig.length <= 3) {
|
|
2342
|
+
return sig.slice(-2);
|
|
2343
|
+
}
|
|
2344
|
+
const results = [];
|
|
2345
|
+
for (let i = 1; i < sig.length; i += 4) {
|
|
2346
|
+
results.push(sig[i + 2], sig[i + 3]);
|
|
2347
|
+
}
|
|
2348
|
+
return results;
|
|
2349
|
+
}
|
|
2322
2350
|
function verify(address_1, sig_1, data_1) {
|
|
2323
2351
|
return __awaiter(this, arguments, void 0, function* (address, sig, data, network = 'SN_MAIN', options = {}) {
|
|
2324
2352
|
try {
|
|
2325
2353
|
const contractAccount = new Contract(ABI, address, getProvider$1(network, options));
|
|
2326
|
-
|
|
2327
|
-
throw new Error('Invalid signature format');
|
|
2328
|
-
}
|
|
2329
|
-
const result = yield contractAccount.is_valid_signature(getHash(data, address), sig.slice(-2));
|
|
2354
|
+
const result = yield contractAccount.is_valid_signature(getHash(data, address), getSignatureArray(sig));
|
|
2330
2355
|
return BigNumber.from(result).eq(BigNumber.from('370462705988'));
|
|
2331
2356
|
}
|
|
2332
2357
|
catch (e) {
|