@snapshot-labs/snapshot.js 0.12.0 → 0.12.2
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 +22 -13
- package/dist/snapshot.esm.js +22 -13
- package/dist/snapshot.min.js +15 -15
- package/dist/src/verify/index.d.ts +1 -1
- package/package.json +2 -1
- package/src/constants.json +1 -1
- package/src/sign/index.ts +3 -3
- package/src/verify/index.ts +1 -1
- package/src/verify/starknet.spec.ts +57 -23
- package/src/verify/starknet.ts +26 -13
package/dist/snapshot.cjs.js
CHANGED
|
@@ -14,6 +14,7 @@ var set = require('lodash.set');
|
|
|
14
14
|
var providers$1 = require('@ethersproject/providers');
|
|
15
15
|
var bytes = require('@ethersproject/bytes');
|
|
16
16
|
var starknet$1 = require('starknet');
|
|
17
|
+
var bignumber = require('@ethersproject/bignumber');
|
|
17
18
|
var wallet = require('@ethersproject/wallet');
|
|
18
19
|
|
|
19
20
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -260,7 +261,7 @@ const deleteSpaceType = {
|
|
|
260
261
|
]
|
|
261
262
|
};
|
|
262
263
|
|
|
263
|
-
var
|
|
264
|
+
var mainnet = {
|
|
264
265
|
hub: "https://hub.snapshot.org",
|
|
265
266
|
sequencer: "https://seq.snapshot.org"
|
|
266
267
|
};
|
|
@@ -273,7 +274,7 @@ var local = {
|
|
|
273
274
|
sequencer: "http://localhost:3001"
|
|
274
275
|
};
|
|
275
276
|
var constants = {
|
|
276
|
-
|
|
277
|
+
mainnet: mainnet,
|
|
277
278
|
testnet: testnet,
|
|
278
279
|
local: local
|
|
279
280
|
};
|
|
@@ -286,8 +287,8 @@ const domain = {
|
|
|
286
287
|
// chainId: 1
|
|
287
288
|
};
|
|
288
289
|
class Client {
|
|
289
|
-
constructor(address = constants.
|
|
290
|
-
address = address.replace(constants.
|
|
290
|
+
constructor(address = constants.mainnet.sequencer, options = {}) {
|
|
291
|
+
address = address.replace(constants.mainnet.hub, constants.mainnet.sequencer);
|
|
291
292
|
address = address.replace(constants.testnet.hub, constants.testnet.sequencer);
|
|
292
293
|
address = address.replace(constants.local.hub, constants.local.sequencer);
|
|
293
294
|
this.address = address;
|
|
@@ -1405,11 +1406,11 @@ const RPC_URLS = {
|
|
|
1405
1406
|
};
|
|
1406
1407
|
const ABI = [
|
|
1407
1408
|
{
|
|
1408
|
-
name: 'argent::account::
|
|
1409
|
+
name: 'argent::common::account::IAccount',
|
|
1409
1410
|
type: 'interface',
|
|
1410
1411
|
items: [
|
|
1411
1412
|
{
|
|
1412
|
-
name: '
|
|
1413
|
+
name: 'is_valid_signature',
|
|
1413
1414
|
type: 'function',
|
|
1414
1415
|
inputs: [
|
|
1415
1416
|
{
|
|
@@ -1417,7 +1418,7 @@ const ABI = [
|
|
|
1417
1418
|
type: 'core::felt252'
|
|
1418
1419
|
},
|
|
1419
1420
|
{
|
|
1420
|
-
name: '
|
|
1421
|
+
name: 'signature',
|
|
1421
1422
|
type: 'core::array::Array::<core::felt252>'
|
|
1422
1423
|
}
|
|
1423
1424
|
],
|
|
@@ -1448,12 +1449,20 @@ function getHash(data, address) {
|
|
|
1448
1449
|
}
|
|
1449
1450
|
function verify(address_1, sig_1, data_1) {
|
|
1450
1451
|
return __awaiter(this, arguments, void 0, function* (address, sig, data, network = 'SN_MAIN', options = {}) {
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
sig
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1452
|
+
try {
|
|
1453
|
+
const contractAccount = new starknet$1.Contract(ABI, address, getProvider$1(network, options));
|
|
1454
|
+
if (sig.length < 2) {
|
|
1455
|
+
throw new Error('Invalid signature format');
|
|
1456
|
+
}
|
|
1457
|
+
const result = yield contractAccount.is_valid_signature(getHash(data, address), sig.slice(-2));
|
|
1458
|
+
return bignumber.BigNumber.from(result).eq(bignumber.BigNumber.from('370462705988'));
|
|
1459
|
+
}
|
|
1460
|
+
catch (e) {
|
|
1461
|
+
if (e.message.includes('Contract not found')) {
|
|
1462
|
+
throw new Error('Contract not deployed');
|
|
1463
|
+
}
|
|
1464
|
+
throw e;
|
|
1465
|
+
}
|
|
1457
1466
|
});
|
|
1458
1467
|
}
|
|
1459
1468
|
|
package/dist/snapshot.esm.js
CHANGED
|
@@ -12,6 +12,7 @@ import set from 'lodash.set';
|
|
|
12
12
|
import { StaticJsonRpcProvider } from '@ethersproject/providers';
|
|
13
13
|
import { hexlify, arrayify } from '@ethersproject/bytes';
|
|
14
14
|
import { Contract, RpcProvider, typedData, validateAndParseAddress } from 'starknet';
|
|
15
|
+
import { BigNumber } from '@ethersproject/bignumber';
|
|
15
16
|
import { verifyTypedData } from '@ethersproject/wallet';
|
|
16
17
|
|
|
17
18
|
/*! *****************************************************************************
|
|
@@ -250,7 +251,7 @@ const deleteSpaceType = {
|
|
|
250
251
|
]
|
|
251
252
|
};
|
|
252
253
|
|
|
253
|
-
var
|
|
254
|
+
var mainnet = {
|
|
254
255
|
hub: "https://hub.snapshot.org",
|
|
255
256
|
sequencer: "https://seq.snapshot.org"
|
|
256
257
|
};
|
|
@@ -263,7 +264,7 @@ var local = {
|
|
|
263
264
|
sequencer: "http://localhost:3001"
|
|
264
265
|
};
|
|
265
266
|
var constants = {
|
|
266
|
-
|
|
267
|
+
mainnet: mainnet,
|
|
267
268
|
testnet: testnet,
|
|
268
269
|
local: local
|
|
269
270
|
};
|
|
@@ -276,8 +277,8 @@ const domain = {
|
|
|
276
277
|
// chainId: 1
|
|
277
278
|
};
|
|
278
279
|
class Client {
|
|
279
|
-
constructor(address = constants.
|
|
280
|
-
address = address.replace(constants.
|
|
280
|
+
constructor(address = constants.mainnet.sequencer, options = {}) {
|
|
281
|
+
address = address.replace(constants.mainnet.hub, constants.mainnet.sequencer);
|
|
281
282
|
address = address.replace(constants.testnet.hub, constants.testnet.sequencer);
|
|
282
283
|
address = address.replace(constants.local.hub, constants.local.sequencer);
|
|
283
284
|
this.address = address;
|
|
@@ -1395,11 +1396,11 @@ const RPC_URLS = {
|
|
|
1395
1396
|
};
|
|
1396
1397
|
const ABI = [
|
|
1397
1398
|
{
|
|
1398
|
-
name: 'argent::account::
|
|
1399
|
+
name: 'argent::common::account::IAccount',
|
|
1399
1400
|
type: 'interface',
|
|
1400
1401
|
items: [
|
|
1401
1402
|
{
|
|
1402
|
-
name: '
|
|
1403
|
+
name: 'is_valid_signature',
|
|
1403
1404
|
type: 'function',
|
|
1404
1405
|
inputs: [
|
|
1405
1406
|
{
|
|
@@ -1407,7 +1408,7 @@ const ABI = [
|
|
|
1407
1408
|
type: 'core::felt252'
|
|
1408
1409
|
},
|
|
1409
1410
|
{
|
|
1410
|
-
name: '
|
|
1411
|
+
name: 'signature',
|
|
1411
1412
|
type: 'core::array::Array::<core::felt252>'
|
|
1412
1413
|
}
|
|
1413
1414
|
],
|
|
@@ -1438,12 +1439,20 @@ function getHash(data, address) {
|
|
|
1438
1439
|
}
|
|
1439
1440
|
function verify(address_1, sig_1, data_1) {
|
|
1440
1441
|
return __awaiter(this, arguments, void 0, function* (address, sig, data, network = 'SN_MAIN', options = {}) {
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
sig
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1442
|
+
try {
|
|
1443
|
+
const contractAccount = new Contract(ABI, address, getProvider$1(network, options));
|
|
1444
|
+
if (sig.length < 2) {
|
|
1445
|
+
throw new Error('Invalid signature format');
|
|
1446
|
+
}
|
|
1447
|
+
const result = yield contractAccount.is_valid_signature(getHash(data, address), sig.slice(-2));
|
|
1448
|
+
return BigNumber.from(result).eq(BigNumber.from('370462705988'));
|
|
1449
|
+
}
|
|
1450
|
+
catch (e) {
|
|
1451
|
+
if (e.message.includes('Contract not found')) {
|
|
1452
|
+
throw new Error('Contract not deployed');
|
|
1453
|
+
}
|
|
1454
|
+
throw e;
|
|
1455
|
+
}
|
|
1447
1456
|
});
|
|
1448
1457
|
}
|
|
1449
1458
|
|