@snapshot-labs/snapshot.js 0.4.46 → 0.4.48

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.
@@ -38,6 +38,7 @@ export interface Vote {
38
38
  privacy?: string;
39
39
  reason?: string;
40
40
  app?: string;
41
+ metadata?: string;
41
42
  }
42
43
  export interface Follow {
43
44
  from?: string;
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var fetch = require('cross-fetch');
4
+ var address = require('@ethersproject/address');
4
5
  var bytes = require('@ethersproject/bytes');
5
6
  var abi = require('@ethersproject/abi');
6
7
  var contracts = require('@ethersproject/contracts');
@@ -156,7 +157,8 @@ var voteTypes = {
156
157
  { name: 'proposal', type: 'string' },
157
158
  { name: 'choice', type: 'uint32' },
158
159
  { name: 'reason', type: 'string' },
159
- { name: 'app', type: 'string' }
160
+ { name: 'app', type: 'string' },
161
+ { name: 'metadata', type: 'string' }
160
162
  ]
161
163
  };
162
164
  var voteArrayTypes = {
@@ -167,7 +169,8 @@ var voteArrayTypes = {
167
169
  { name: 'proposal', type: 'string' },
168
170
  { name: 'choice', type: 'uint32[]' },
169
171
  { name: 'reason', type: 'string' },
170
- { name: 'app', type: 'string' }
172
+ { name: 'app', type: 'string' },
173
+ { name: 'metadata', type: 'string' }
171
174
  ]
172
175
  };
173
176
  var voteStringTypes = {
@@ -178,7 +181,8 @@ var voteStringTypes = {
178
181
  { name: 'proposal', type: 'string' },
179
182
  { name: 'choice', type: 'string' },
180
183
  { name: 'reason', type: 'string' },
181
- { name: 'app', type: 'string' }
184
+ { name: 'app', type: 'string' },
185
+ { name: 'metadata', type: 'string' }
182
186
  ]
183
187
  };
184
188
  var vote2Types = {
@@ -189,7 +193,8 @@ var vote2Types = {
189
193
  { name: 'proposal', type: 'bytes32' },
190
194
  { name: 'choice', type: 'uint32' },
191
195
  { name: 'reason', type: 'string' },
192
- { name: 'app', type: 'string' }
196
+ { name: 'app', type: 'string' },
197
+ { name: 'metadata', type: 'string' }
193
198
  ]
194
199
  };
195
200
  var voteArray2Types = {
@@ -200,7 +205,8 @@ var voteArray2Types = {
200
205
  { name: 'proposal', type: 'bytes32' },
201
206
  { name: 'choice', type: 'uint32[]' },
202
207
  { name: 'reason', type: 'string' },
203
- { name: 'app', type: 'string' }
208
+ { name: 'app', type: 'string' },
209
+ { name: 'metadata', type: 'string' }
204
210
  ]
205
211
  };
206
212
  var voteString2Types = {
@@ -211,7 +217,8 @@ var voteString2Types = {
211
217
  { name: 'proposal', type: 'bytes32' },
212
218
  { name: 'choice', type: 'string' },
213
219
  { name: 'reason', type: 'string' },
214
- { name: 'app', type: 'string' }
220
+ { name: 'app', type: 'string' },
221
+ { name: 'metadata', type: 'string' }
215
222
  ]
216
223
  };
217
224
  var followTypes = {
@@ -275,24 +282,24 @@ var Client = /** @class */ (function () {
275
282
  if (address === void 0) { address = hubs[0]; }
276
283
  this.address = address;
277
284
  }
278
- Client.prototype.sign = function (web3, address, message, types) {
285
+ Client.prototype.sign = function (web3, address$1, message, types) {
279
286
  return __awaiter(this, void 0, void 0, function () {
280
- var signer, data, sig;
287
+ var signer, checksumAddress, data, sig;
281
288
  return __generator(this, function (_a) {
282
289
  switch (_a.label) {
283
290
  case 0:
284
291
  signer = (web3 === null || web3 === void 0 ? void 0 : web3.getSigner) ? web3.getSigner() : web3;
285
- if (!message.from)
286
- message.from = address;
292
+ checksumAddress = address.getAddress(address$1);
293
+ message.from = message.from ? address.getAddress(message.from) : checksumAddress;
287
294
  if (!message.timestamp)
288
295
  message.timestamp = parseInt((Date.now() / 1e3).toFixed());
289
296
  data = { domain: domain, types: types, message: message };
290
297
  return [4 /*yield*/, signer._signTypedData(domain, data.types, message)];
291
298
  case 1:
292
299
  sig = _a.sent();
293
- return [4 /*yield*/, this.send({ address: address, sig: sig, data: data })];
300
+ return [4 /*yield*/, this.send({ address: checksumAddress, sig: sig, data: data })];
294
301
  case 2:
295
- // console.log('Sign', { address, sig, data });
302
+ //console.log('Sign', { address: checksumAddress, sig, data });
296
303
  return [2 /*return*/, _a.sent()];
297
304
  }
298
305
  });
@@ -372,6 +379,8 @@ var Client = /** @class */ (function () {
372
379
  message.reason = '';
373
380
  if (!message.app)
374
381
  message.app = '';
382
+ if (!message.metadata)
383
+ message.metadata = '{}';
375
384
  type2 = message.proposal.startsWith('0x');
376
385
  type = type2 ? vote2Types : voteTypes;
377
386
  if (['approval', 'ranked-choice'].includes(message.type))
@@ -383,6 +392,7 @@ var Client = /** @class */ (function () {
383
392
  if (isShutter)
384
393
  type = type2 ? voteString2Types : voteStringTypes;
385
394
  delete message.privacy;
395
+ // @ts-ignore
386
396
  delete message.type;
387
397
  return [4 /*yield*/, this.sign(web3, address, message, type)];
388
398
  case 1: return [2 /*return*/, _a.sent()];
@@ -3176,6 +3186,43 @@ var networks = {
3176
3186
  },
3177
3187
  start: 22090160,
3178
3188
  logo: "ipfs://QmRfiNT4tDhyxfpYcjNde4BMPPWEAygYNPdAaS9bra6aFC"
3189
+ },
3190
+ "71401": {
3191
+ key: "71401",
3192
+ name: "Godwoken V1 Testnet",
3193
+ chainId: 71401,
3194
+ network: "testnet",
3195
+ testnet: true,
3196
+ multicall: "0xcA11bde05977b3631167028862bE2a173976CA11",
3197
+ rpc: [
3198
+ "https://godwoken-testnet-v1.ckbapp.dev"
3199
+ ],
3200
+ ws: [
3201
+ "wss://godwoken-testnet-v1.ckbapp.dev/ws"
3202
+ ],
3203
+ explorer: {
3204
+ url: "https://gw-explorer.nervosdao.community"
3205
+ },
3206
+ start: 115283,
3207
+ logo: "ipfs://QmR6Q2CTds6Uwu8Euo7BKvFKAeg1AyVSxWzqCvyquDD7NF"
3208
+ },
3209
+ "71402": {
3210
+ key: "71402",
3211
+ name: "Godwoken V1",
3212
+ chainId: 71402,
3213
+ network: "mainnet",
3214
+ multicall: "0xcA11bde05977b3631167028862bE2a173976CA11",
3215
+ rpc: [
3216
+ "https://v1.mainnet.godwoken.io/rpc"
3217
+ ],
3218
+ ws: [
3219
+ "wss://v1.mainnet.godwoken.io/ws"
3220
+ ],
3221
+ explorer: {
3222
+ url: "https://gwscan.com"
3223
+ },
3224
+ start: 15034,
3225
+ logo: "ipfs://QmR6Q2CTds6Uwu8Euo7BKvFKAeg1AyVSxWzqCvyquDD7NF"
3179
3226
  },
3180
3227
  "80001": {
3181
3228
  key: "80001",
@@ -1,4 +1,5 @@
1
1
  import fetch from 'cross-fetch';
2
+ import { getAddress } from '@ethersproject/address';
2
3
  import { hexlify, arrayify } from '@ethersproject/bytes';
3
4
  import { Interface } from '@ethersproject/abi';
4
5
  import { Contract } from '@ethersproject/contracts';
@@ -147,7 +148,8 @@ var voteTypes = {
147
148
  { name: 'proposal', type: 'string' },
148
149
  { name: 'choice', type: 'uint32' },
149
150
  { name: 'reason', type: 'string' },
150
- { name: 'app', type: 'string' }
151
+ { name: 'app', type: 'string' },
152
+ { name: 'metadata', type: 'string' }
151
153
  ]
152
154
  };
153
155
  var voteArrayTypes = {
@@ -158,7 +160,8 @@ var voteArrayTypes = {
158
160
  { name: 'proposal', type: 'string' },
159
161
  { name: 'choice', type: 'uint32[]' },
160
162
  { name: 'reason', type: 'string' },
161
- { name: 'app', type: 'string' }
163
+ { name: 'app', type: 'string' },
164
+ { name: 'metadata', type: 'string' }
162
165
  ]
163
166
  };
164
167
  var voteStringTypes = {
@@ -169,7 +172,8 @@ var voteStringTypes = {
169
172
  { name: 'proposal', type: 'string' },
170
173
  { name: 'choice', type: 'string' },
171
174
  { name: 'reason', type: 'string' },
172
- { name: 'app', type: 'string' }
175
+ { name: 'app', type: 'string' },
176
+ { name: 'metadata', type: 'string' }
173
177
  ]
174
178
  };
175
179
  var vote2Types = {
@@ -180,7 +184,8 @@ var vote2Types = {
180
184
  { name: 'proposal', type: 'bytes32' },
181
185
  { name: 'choice', type: 'uint32' },
182
186
  { name: 'reason', type: 'string' },
183
- { name: 'app', type: 'string' }
187
+ { name: 'app', type: 'string' },
188
+ { name: 'metadata', type: 'string' }
184
189
  ]
185
190
  };
186
191
  var voteArray2Types = {
@@ -191,7 +196,8 @@ var voteArray2Types = {
191
196
  { name: 'proposal', type: 'bytes32' },
192
197
  { name: 'choice', type: 'uint32[]' },
193
198
  { name: 'reason', type: 'string' },
194
- { name: 'app', type: 'string' }
199
+ { name: 'app', type: 'string' },
200
+ { name: 'metadata', type: 'string' }
195
201
  ]
196
202
  };
197
203
  var voteString2Types = {
@@ -202,7 +208,8 @@ var voteString2Types = {
202
208
  { name: 'proposal', type: 'bytes32' },
203
209
  { name: 'choice', type: 'string' },
204
210
  { name: 'reason', type: 'string' },
205
- { name: 'app', type: 'string' }
211
+ { name: 'app', type: 'string' },
212
+ { name: 'metadata', type: 'string' }
206
213
  ]
207
214
  };
208
215
  var followTypes = {
@@ -268,22 +275,22 @@ var Client = /** @class */ (function () {
268
275
  }
269
276
  Client.prototype.sign = function (web3, address, message, types) {
270
277
  return __awaiter(this, void 0, void 0, function () {
271
- var signer, data, sig;
278
+ var signer, checksumAddress, data, sig;
272
279
  return __generator(this, function (_a) {
273
280
  switch (_a.label) {
274
281
  case 0:
275
282
  signer = (web3 === null || web3 === void 0 ? void 0 : web3.getSigner) ? web3.getSigner() : web3;
276
- if (!message.from)
277
- message.from = address;
283
+ checksumAddress = getAddress(address);
284
+ message.from = message.from ? getAddress(message.from) : checksumAddress;
278
285
  if (!message.timestamp)
279
286
  message.timestamp = parseInt((Date.now() / 1e3).toFixed());
280
287
  data = { domain: domain, types: types, message: message };
281
288
  return [4 /*yield*/, signer._signTypedData(domain, data.types, message)];
282
289
  case 1:
283
290
  sig = _a.sent();
284
- return [4 /*yield*/, this.send({ address: address, sig: sig, data: data })];
291
+ return [4 /*yield*/, this.send({ address: checksumAddress, sig: sig, data: data })];
285
292
  case 2:
286
- // console.log('Sign', { address, sig, data });
293
+ //console.log('Sign', { address: checksumAddress, sig, data });
287
294
  return [2 /*return*/, _a.sent()];
288
295
  }
289
296
  });
@@ -363,6 +370,8 @@ var Client = /** @class */ (function () {
363
370
  message.reason = '';
364
371
  if (!message.app)
365
372
  message.app = '';
373
+ if (!message.metadata)
374
+ message.metadata = '{}';
366
375
  type2 = message.proposal.startsWith('0x');
367
376
  type = type2 ? vote2Types : voteTypes;
368
377
  if (['approval', 'ranked-choice'].includes(message.type))
@@ -374,6 +383,7 @@ var Client = /** @class */ (function () {
374
383
  if (isShutter)
375
384
  type = type2 ? voteString2Types : voteStringTypes;
376
385
  delete message.privacy;
386
+ // @ts-ignore
377
387
  delete message.type;
378
388
  return [4 /*yield*/, this.sign(web3, address, message, type)];
379
389
  case 1: return [2 /*return*/, _a.sent()];
@@ -3167,6 +3177,43 @@ var networks = {
3167
3177
  },
3168
3178
  start: 22090160,
3169
3179
  logo: "ipfs://QmRfiNT4tDhyxfpYcjNde4BMPPWEAygYNPdAaS9bra6aFC"
3180
+ },
3181
+ "71401": {
3182
+ key: "71401",
3183
+ name: "Godwoken V1 Testnet",
3184
+ chainId: 71401,
3185
+ network: "testnet",
3186
+ testnet: true,
3187
+ multicall: "0xcA11bde05977b3631167028862bE2a173976CA11",
3188
+ rpc: [
3189
+ "https://godwoken-testnet-v1.ckbapp.dev"
3190
+ ],
3191
+ ws: [
3192
+ "wss://godwoken-testnet-v1.ckbapp.dev/ws"
3193
+ ],
3194
+ explorer: {
3195
+ url: "https://gw-explorer.nervosdao.community"
3196
+ },
3197
+ start: 115283,
3198
+ logo: "ipfs://QmR6Q2CTds6Uwu8Euo7BKvFKAeg1AyVSxWzqCvyquDD7NF"
3199
+ },
3200
+ "71402": {
3201
+ key: "71402",
3202
+ name: "Godwoken V1",
3203
+ chainId: 71402,
3204
+ network: "mainnet",
3205
+ multicall: "0xcA11bde05977b3631167028862bE2a173976CA11",
3206
+ rpc: [
3207
+ "https://v1.mainnet.godwoken.io/rpc"
3208
+ ],
3209
+ ws: [
3210
+ "wss://v1.mainnet.godwoken.io/ws"
3211
+ ],
3212
+ explorer: {
3213
+ url: "https://gwscan.com"
3214
+ },
3215
+ start: 15034,
3216
+ logo: "ipfs://QmR6Q2CTds6Uwu8Euo7BKvFKAeg1AyVSxWzqCvyquDD7NF"
3170
3217
  },
3171
3218
  "80001": {
3172
3219
  key: "80001",