starknet 4.9.0 → 4.10.0

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.
Files changed (65) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +1 -3
  3. package/__tests__/account.test.ts +1 -1
  4. package/__tests__/defaultProvider.test.ts +85 -210
  5. package/__tests__/fixtures.ts +1 -1
  6. package/__tests__/rpcProvider.test.ts +4 -3
  7. package/__tests__/udc.test.ts +41 -0
  8. package/account/default.d.ts +3 -1
  9. package/account/default.js +50 -0
  10. package/account/interface.d.ts +24 -7
  11. package/constants.d.ts +7 -1
  12. package/constants.js +7 -1
  13. package/contract/default.d.ts +11 -27
  14. package/contract/default.js +104 -120
  15. package/contract/interface.d.ts +5 -2
  16. package/dist/account/default.d.ts +3 -1
  17. package/dist/account/default.js +50 -0
  18. package/dist/account/interface.d.ts +24 -7
  19. package/dist/constants.d.ts +7 -1
  20. package/dist/constants.js +7 -1
  21. package/dist/contract/default.d.ts +11 -27
  22. package/dist/contract/default.js +104 -120
  23. package/dist/contract/interface.d.ts +5 -2
  24. package/dist/provider/rpc.d.ts +3 -1
  25. package/dist/provider/rpc.js +15 -2
  26. package/dist/provider/sequencer.d.ts +4 -2
  27. package/dist/provider/sequencer.js +18 -5
  28. package/dist/signer/default.d.ts +2 -2
  29. package/dist/signer/default.js +15 -15
  30. package/dist/signer/interface.d.ts +2 -0
  31. package/dist/types/api/index.d.ts +0 -6
  32. package/dist/types/index.d.ts +1 -1
  33. package/dist/types/lib.d.ts +13 -0
  34. package/dist/utils/number.d.ts +1 -0
  35. package/dist/utils/number.js +3 -1
  36. package/package.json +1 -1
  37. package/provider/rpc.d.ts +3 -1
  38. package/provider/rpc.js +15 -2
  39. package/provider/sequencer.d.ts +4 -2
  40. package/provider/sequencer.js +18 -5
  41. package/signer/default.d.ts +2 -2
  42. package/signer/default.js +15 -15
  43. package/signer/interface.d.ts +2 -0
  44. package/src/account/default.ts +43 -3
  45. package/src/account/interface.ts +34 -7
  46. package/src/constants.ts +7 -0
  47. package/src/contract/default.ts +123 -140
  48. package/src/contract/interface.ts +5 -2
  49. package/src/provider/rpc.ts +7 -3
  50. package/src/provider/sequencer.ts +13 -4
  51. package/src/signer/default.ts +18 -18
  52. package/src/signer/interface.ts +2 -0
  53. package/src/types/api/index.ts +0 -4
  54. package/src/types/index.ts +1 -1
  55. package/src/types/lib.ts +13 -0
  56. package/src/utils/number.ts +2 -0
  57. package/types/api/index.d.ts +0 -6
  58. package/types/index.d.ts +1 -1
  59. package/types/lib.d.ts +13 -0
  60. package/utils/number.d.ts +1 -0
  61. package/utils/number.js +3 -1
  62. package/www/docs/API/account.md +122 -22
  63. package/www/docs/API/contract.md +39 -3
  64. package/www/docs/API/provider.md +4 -0
  65. package/www/docs/API/signer.md +56 -2
@@ -252,28 +252,12 @@ var Contract = /** @class */ (function () {
252
252
  }
253
253
  });
254
254
  }
255
- /**
256
- * Saves the address of the contract deployed on network that will be used for interaction
257
- *
258
- * @param address - address of the contract
259
- */
260
255
  Contract.prototype.attach = function (address) {
261
256
  this.address = address;
262
257
  };
263
- /**
264
- * Attaches to new Provider or Account
265
- *
266
- * @param providerOrAccount - new Provider or Account to attach to
267
- */
268
258
  Contract.prototype.connect = function (providerOrAccount) {
269
259
  this.providerOrAccount = providerOrAccount;
270
260
  };
271
- /**
272
- * Resolves when contract is deployed on the network or when no deployment transaction is found
273
- *
274
- * @returns Promise that resolves when contract is deployed on the network or when no deployment transaction is found
275
- * @throws When deployment fails
276
- */
277
261
  Contract.prototype.deployed = function () {
278
262
  return __awaiter(this, void 0, void 0, function () {
279
263
  return __generator(this, function (_a) {
@@ -290,6 +274,110 @@ var Contract = /** @class */ (function () {
290
274
  });
291
275
  });
292
276
  };
277
+ Contract.prototype.call = function (method, args, _a) {
278
+ if (args === void 0) { args = []; }
279
+ var _b = _a === void 0 ? {} : _a, _c = _b.blockIdentifier, blockIdentifier = _c === void 0 ? 'pending' : _c;
280
+ return __awaiter(this, void 0, void 0, function () {
281
+ var inputs, calldata;
282
+ var _this = this;
283
+ return __generator(this, function (_d) {
284
+ // ensure contract is connected
285
+ (0, minimalistic_assert_1.default)(this.address !== null, 'contract is not connected to an address');
286
+ // validate method and args
287
+ this.validateMethodAndArgs('CALL', method, args);
288
+ inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
289
+ calldata = this.compileCalldata(args, inputs);
290
+ return [2 /*return*/, this.providerOrAccount
291
+ .callContract({
292
+ contractAddress: this.address,
293
+ calldata: calldata,
294
+ entrypoint: method,
295
+ }, blockIdentifier)
296
+ .then(function (x) { return _this.parseResponse(method, x.result); })];
297
+ });
298
+ });
299
+ };
300
+ Contract.prototype.invoke = function (method, args, options) {
301
+ if (args === void 0) { args = []; }
302
+ if (options === void 0) { options = {}; }
303
+ // ensure contract is connected
304
+ (0, minimalistic_assert_1.default)(this.address !== null, 'contract is not connected to an address');
305
+ // validate method and args
306
+ this.validateMethodAndArgs('INVOKE', method, args);
307
+ var inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
308
+ var inputsLength = inputs.reduce(function (acc, input) {
309
+ if (!/_len$/.test(input.name)) {
310
+ return acc + 1;
311
+ }
312
+ return acc;
313
+ }, 0);
314
+ if (args.length !== inputsLength) {
315
+ throw Error("Invalid number of arguments, expected ".concat(inputsLength, " arguments, but got ").concat(args.length));
316
+ }
317
+ // compile calldata
318
+ var calldata = this.compileCalldata(args, inputs);
319
+ var invocation = {
320
+ contractAddress: this.address,
321
+ calldata: calldata,
322
+ entrypoint: method,
323
+ };
324
+ if ('execute' in this.providerOrAccount) {
325
+ return this.providerOrAccount.execute(invocation, undefined, {
326
+ maxFee: options.maxFee,
327
+ nonce: options.nonce,
328
+ });
329
+ }
330
+ if (!options.nonce) {
331
+ throw new Error("Nonce is required when invoking a function without an account");
332
+ }
333
+ // eslint-disable-next-line no-console
334
+ console.warn("Invoking ".concat(method, " without an account. This will not work on a public node."));
335
+ return this.providerOrAccount.invokeFunction(__assign(__assign({}, invocation), { signature: options.signature || [] }), {
336
+ nonce: options.nonce,
337
+ });
338
+ };
339
+ Contract.prototype.estimate = function (method, args) {
340
+ if (args === void 0) { args = []; }
341
+ return __awaiter(this, void 0, void 0, function () {
342
+ var invocation;
343
+ var _a;
344
+ return __generator(this, function (_b) {
345
+ // ensure contract is connected
346
+ (0, minimalistic_assert_1.default)(this.address !== null, 'contract is not connected to an address');
347
+ // validate method and args
348
+ this.validateMethodAndArgs('INVOKE', method, args);
349
+ invocation = (_a = this.populateTransaction)[method].apply(_a, __spreadArray([], __read(args), false));
350
+ if ('estimateInvokeFee' in this.providerOrAccount) {
351
+ return [2 /*return*/, this.providerOrAccount.estimateInvokeFee(invocation)];
352
+ }
353
+ throw Error('Contract must be connected to the account contract to estimate');
354
+ });
355
+ });
356
+ };
357
+ Contract.prototype.populate = function (method, args) {
358
+ if (args === void 0) { args = []; }
359
+ var inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
360
+ return {
361
+ contractAddress: this.address,
362
+ entrypoint: method,
363
+ calldata: this.compileCalldata(args, inputs),
364
+ };
365
+ };
366
+ /**
367
+ * Deep parse of the object that has been passed to the method
368
+ *
369
+ * @param struct - struct that needs to be calculated
370
+ * @return {number} - number of members for the given struct
371
+ */
372
+ Contract.prototype.calculateStructMembers = function (struct) {
373
+ var _this = this;
374
+ return this.structs[struct].members.reduce(function (acc, member) {
375
+ if (member.type === 'felt') {
376
+ return acc + 1;
377
+ }
378
+ return acc + _this.calculateStructMembers(member.type);
379
+ }, 0);
380
+ };
293
381
  /**
294
382
  * Validates if all arguments that are passed to the method are corresponding to the ones in the abi
295
383
  *
@@ -371,21 +459,6 @@ var Contract = /** @class */ (function () {
371
459
  }
372
460
  });
373
461
  };
374
- /**
375
- * Deep parse of the object that has been passed to the method
376
- *
377
- * @param struct - struct that needs to be calculated
378
- * @return {number} - number of members for the given struct
379
- */
380
- Contract.prototype.calculateStructMembers = function (struct) {
381
- var _this = this;
382
- return this.structs[struct].members.reduce(function (acc, member) {
383
- if (member.type === 'felt') {
384
- return acc + 1;
385
- }
386
- return acc + _this.calculateStructMembers(member.type);
387
- }, 0);
388
- };
389
462
  /**
390
463
  * Deep parse of the object that has been passed to the method
391
464
  *
@@ -562,95 +635,6 @@ var Contract = /** @class */ (function () {
562
635
  return acc;
563
636
  }, []);
564
637
  };
565
- Contract.prototype.invoke = function (method, args, options) {
566
- if (args === void 0) { args = []; }
567
- if (options === void 0) { options = {}; }
568
- // ensure contract is connected
569
- (0, minimalistic_assert_1.default)(this.address !== null, 'contract is not connected to an address');
570
- // validate method and args
571
- this.validateMethodAndArgs('INVOKE', method, args);
572
- var inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
573
- var inputsLength = inputs.reduce(function (acc, input) {
574
- if (!/_len$/.test(input.name)) {
575
- return acc + 1;
576
- }
577
- return acc;
578
- }, 0);
579
- if (args.length !== inputsLength) {
580
- throw Error("Invalid number of arguments, expected ".concat(inputsLength, " arguments, but got ").concat(args.length));
581
- }
582
- // compile calldata
583
- var calldata = this.compileCalldata(args, inputs);
584
- var invocation = {
585
- contractAddress: this.address,
586
- calldata: calldata,
587
- entrypoint: method,
588
- };
589
- if ('execute' in this.providerOrAccount) {
590
- return this.providerOrAccount.execute(invocation, undefined, {
591
- maxFee: options.maxFee,
592
- nonce: options.nonce,
593
- });
594
- }
595
- if (!options.nonce) {
596
- throw new Error("Nonce is required when invoking a function without an account");
597
- }
598
- // eslint-disable-next-line no-console
599
- console.warn("Invoking ".concat(method, " without an account. This will not work on a public node."));
600
- return this.providerOrAccount.invokeFunction(__assign(__assign({}, invocation), { signature: options.signature || [] }), {
601
- nonce: options.nonce,
602
- });
603
- };
604
- Contract.prototype.call = function (method, args, _a) {
605
- if (args === void 0) { args = []; }
606
- var _b = _a === void 0 ? {} : _a, _c = _b.blockIdentifier, blockIdentifier = _c === void 0 ? 'pending' : _c;
607
- return __awaiter(this, void 0, void 0, function () {
608
- var inputs, calldata;
609
- var _this = this;
610
- return __generator(this, function (_d) {
611
- // ensure contract is connected
612
- (0, minimalistic_assert_1.default)(this.address !== null, 'contract is not connected to an address');
613
- // validate method and args
614
- this.validateMethodAndArgs('CALL', method, args);
615
- inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
616
- calldata = this.compileCalldata(args, inputs);
617
- return [2 /*return*/, this.providerOrAccount
618
- .callContract({
619
- contractAddress: this.address,
620
- calldata: calldata,
621
- entrypoint: method,
622
- }, blockIdentifier)
623
- .then(function (x) { return _this.parseResponse(method, x.result); })];
624
- });
625
- });
626
- };
627
- Contract.prototype.estimate = function (method, args) {
628
- if (args === void 0) { args = []; }
629
- return __awaiter(this, void 0, void 0, function () {
630
- var invocation;
631
- var _a;
632
- return __generator(this, function (_b) {
633
- // ensure contract is connected
634
- (0, minimalistic_assert_1.default)(this.address !== null, 'contract is not connected to an address');
635
- // validate method and args
636
- this.validateMethodAndArgs('INVOKE', method, args);
637
- invocation = (_a = this.populateTransaction)[method].apply(_a, __spreadArray([], __read(args), false));
638
- if ('estimateInvokeFee' in this.providerOrAccount) {
639
- return [2 /*return*/, this.providerOrAccount.estimateInvokeFee(invocation)];
640
- }
641
- throw Error('Contract must be connected to the account contract to estimate');
642
- });
643
- });
644
- };
645
- Contract.prototype.populate = function (method, args) {
646
- if (args === void 0) { args = []; }
647
- var inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
648
- return {
649
- contractAddress: this.address,
650
- entrypoint: method,
651
- calldata: this.compileCalldata(args, inputs),
652
- };
653
- };
654
638
  return Contract;
655
639
  }());
656
640
  exports.Contract = Contract;
@@ -44,6 +44,7 @@ export declare abstract class ContractInterface {
44
44
  *
45
45
  * @param method name of the method
46
46
  * @param args Array of the arguments for the call
47
+ * @param options optional blockIdentifier
47
48
  * @returns Result of the call as an array with key value pars
48
49
  */
49
50
  abstract call(method: string, args?: Array<any>, options?: {
@@ -54,14 +55,16 @@ export declare abstract class ContractInterface {
54
55
  *
55
56
  * @param method name of the method
56
57
  * @param args Array of the arguments for the invoke
58
+ * @param options
57
59
  * @returns Add Transaction Response
58
60
  */
59
61
  abstract invoke(method: string, args?: Array<any>, options?: Overrides): Promise<InvokeFunctionResponse>;
60
62
  /**
61
- * Calls a method on a contract
63
+ * Estimates a method on a contract
62
64
  *
63
65
  * @param method name of the method
64
66
  * @param args Array of the arguments for the call
67
+ * @param options optional blockIdentifier
65
68
  */
66
69
  abstract estimate(method: string, args?: Array<any>, options?: {
67
70
  blockIdentifier?: BlockIdentifier;
@@ -71,7 +74,7 @@ export declare abstract class ContractInterface {
71
74
  *
72
75
  * @param method name of the method
73
76
  * @param args Array of the arguments for the call
74
- * @returns Invocation objet
77
+ * @returns Invocation object
75
78
  */
76
79
  abstract populate(method: string, args?: Array<any>): Invocation;
77
80
  }
@@ -8,10 +8,12 @@ import { BlockIdentifier } from './utils';
8
8
  export declare type RpcProviderOptions = {
9
9
  nodeUrl: string;
10
10
  retries?: number;
11
+ headers?: object;
11
12
  };
12
13
  export declare class RpcProvider implements ProviderInterface {
13
14
  nodeUrl: string;
14
15
  chainId: StarknetChainId;
16
+ headers: object;
15
17
  private responseParser;
16
18
  private retries;
17
19
  constructor(optionsOrProvider: RpcProviderOptions);
@@ -34,7 +36,7 @@ export declare class RpcProvider implements ProviderInterface {
34
36
  getTransactionByBlockIdAndIndex(blockIdentifier: BlockIdentifier, index: number): Promise<RPC.GetTransactionByBlockIdAndIndex>;
35
37
  getTransactionReceipt(txHash: string): Promise<GetTransactionReceiptResponse>;
36
38
  getClass(classHash: RPC.Felt): Promise<RPC.ContractClass>;
37
- getClassAt(contractAddress: string, blockIdentifier: BlockIdentifier): Promise<RPC.ContractClass>;
39
+ getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<RPC.ContractClass>;
38
40
  getCode(_contractAddress: string, _blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
39
41
  getEstimateFee(invocation: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
40
42
  getInvokeEstimateFee(invocation: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -52,9 +63,10 @@ var RpcProvider = /** @class */ (function () {
52
63
  function RpcProvider(optionsOrProvider) {
53
64
  var _this = this;
54
65
  this.responseParser = new rpc_1.RPCResponseParser();
55
- var nodeUrl = optionsOrProvider.nodeUrl, retries = optionsOrProvider.retries;
66
+ var nodeUrl = optionsOrProvider.nodeUrl, retries = optionsOrProvider.retries, headers = optionsOrProvider.headers;
56
67
  this.nodeUrl = nodeUrl;
57
68
  this.retries = retries || 200;
69
+ this.headers = __assign({ 'Content-Type': 'application/json' }, headers);
58
70
  this.getChainId().then(function (chainId) {
59
71
  _this.chainId = chainId;
60
72
  });
@@ -63,7 +75,7 @@ var RpcProvider = /** @class */ (function () {
63
75
  return (0, fetchPonyfill_1.default)(this.nodeUrl, {
64
76
  method: 'POST',
65
77
  body: (0, json_1.stringify)({ method: method, jsonrpc: '2.0', params: params, id: 0 }),
66
- headers: { 'Content-Type': 'application/json' },
78
+ headers: this.headers,
67
79
  });
68
80
  };
69
81
  RpcProvider.prototype.errorHandler = function (error) {
@@ -243,6 +255,7 @@ var RpcProvider = /** @class */ (function () {
243
255
  });
244
256
  };
245
257
  RpcProvider.prototype.getClassAt = function (contractAddress, blockIdentifier) {
258
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
246
259
  return __awaiter(this, void 0, void 0, function () {
247
260
  var block_id;
248
261
  return __generator(this, function (_a) {
@@ -5,7 +5,7 @@ import { DeclareContractTransaction, DeployAccountContractTransaction } from '..
5
5
  import { BigNumberish } from '../utils/number';
6
6
  import { ProviderInterface } from './interface';
7
7
  import { BlockIdentifier } from './utils';
8
- declare type NetworkName = 'mainnet-alpha' | 'goerli-alpha';
8
+ declare type NetworkName = 'mainnet-alpha' | 'goerli-alpha' | 'goerli-alpha-2';
9
9
  export declare type SequencerProviderOptions = {
10
10
  network: NetworkName;
11
11
  } | {
@@ -13,15 +13,17 @@ export declare type SequencerProviderOptions = {
13
13
  feederGatewayUrl?: string;
14
14
  gatewayUrl?: string;
15
15
  chainId?: StarknetChainId;
16
+ headers?: object;
16
17
  };
17
18
  export declare class SequencerProvider implements ProviderInterface {
18
19
  baseUrl: string;
19
20
  feederGatewayUrl: string;
20
21
  gatewayUrl: string;
21
22
  chainId: StarknetChainId;
23
+ headers: object | undefined;
22
24
  private responseParser;
23
25
  constructor(optionsOrProvider?: SequencerProviderOptions);
24
- protected static getNetworkFromName(name: NetworkName): "https://alpha-mainnet.starknet.io" | "https://alpha4.starknet.io";
26
+ protected static getNetworkFromName(name: NetworkName): "https://alpha-mainnet.starknet.io" | "https://alpha4.starknet.io" | "https://alpha4-2.starknet.io";
25
27
  protected static getChainIdFromBaseUrl(baseUrl: string): StarknetChainId;
26
28
  private getFetchUrl;
27
29
  private getFetchMethod;
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -79,7 +90,7 @@ function isEmptyQueryObject(obj) {
79
90
  }
80
91
  var SequencerProvider = /** @class */ (function () {
81
92
  function SequencerProvider(optionsOrProvider) {
82
- if (optionsOrProvider === void 0) { optionsOrProvider = { network: 'goerli-alpha' }; }
93
+ if (optionsOrProvider === void 0) { optionsOrProvider = { network: 'goerli-alpha-2' }; }
83
94
  var _a;
84
95
  this.responseParser = new sequencer_1.SequencerAPIResponseParser();
85
96
  if ('network' in optionsOrProvider) {
@@ -94,6 +105,7 @@ var SequencerProvider = /** @class */ (function () {
94
105
  this.gatewayUrl = (0, url_1.buildUrl)(this.baseUrl, 'gateway', optionsOrProvider.gatewayUrl);
95
106
  this.chainId =
96
107
  (_a = optionsOrProvider.chainId) !== null && _a !== void 0 ? _a : SequencerProvider.getChainIdFromBaseUrl(optionsOrProvider.baseUrl);
108
+ this.headers = optionsOrProvider === null || optionsOrProvider === void 0 ? void 0 : optionsOrProvider.headers;
97
109
  }
98
110
  }
99
111
  SequencerProvider.getNetworkFromName = function (name) {
@@ -101,6 +113,9 @@ var SequencerProvider = /** @class */ (function () {
101
113
  case 'mainnet-alpha':
102
114
  return 'https://alpha-mainnet.starknet.io';
103
115
  case 'goerli-alpha':
116
+ return 'https://alpha4.starknet.io';
117
+ case 'goerli-alpha-2':
118
+ return 'https://alpha4-2.starknet.io';
104
119
  default:
105
120
  return 'https://alpha4.starknet.io';
106
121
  }
@@ -149,11 +164,9 @@ var SequencerProvider = /** @class */ (function () {
149
164
  };
150
165
  SequencerProvider.prototype.getHeaders = function (method) {
151
166
  if (method === 'POST') {
152
- return {
153
- 'Content-Type': 'application/json',
154
- };
167
+ return __assign({ 'Content-Type': 'application/json' }, this.headers);
155
168
  }
156
- return undefined;
169
+ return this.headers;
157
170
  };
158
171
  // typesafe fetch
159
172
  SequencerProvider.prototype.fetchEndpoint = function (endpoint) {
@@ -6,8 +6,8 @@ export declare class Signer implements SignerInterface {
6
6
  protected keyPair: KeyPair;
7
7
  constructor(keyPair?: KeyPair);
8
8
  getPubKey(): Promise<string>;
9
+ signMessage(typedData: TypedData, accountAddress: string): Promise<Signature>;
9
10
  signTransaction(transactions: Call[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): Promise<Signature>;
10
- signDeclareTransaction({ classHash, senderAddress, chainId, maxFee, version, nonce }: DeclareSignerDetails): Promise<Signature>;
11
11
  signDeployAccountTransaction({ classHash, contractAddress, constructorCalldata, addressSalt, maxFee, version, chainId, nonce, }: DeployAccountSignerDetails): Promise<Signature>;
12
- signMessage(typedData: TypedData, accountAddress: string): Promise<Signature>;
12
+ signDeclareTransaction({ classHash, senderAddress, chainId, maxFee, version, nonce }: DeclareSignerDetails): Promise<Signature>;
13
13
  }
@@ -53,6 +53,15 @@ var Signer = /** @class */ (function () {
53
53
  });
54
54
  });
55
55
  };
56
+ Signer.prototype.signMessage = function (typedData, accountAddress) {
57
+ return __awaiter(this, void 0, void 0, function () {
58
+ var msgHash;
59
+ return __generator(this, function (_a) {
60
+ msgHash = (0, typedData_1.getMessageHash)(typedData, accountAddress);
61
+ return [2 /*return*/, (0, ellipticCurve_1.sign)(this.keyPair, msgHash)];
62
+ });
63
+ });
64
+ };
56
65
  Signer.prototype.signTransaction = function (transactions, transactionsDetail, abis) {
57
66
  return __awaiter(this, void 0, void 0, function () {
58
67
  var calldata, msgHash;
@@ -66,18 +75,6 @@ var Signer = /** @class */ (function () {
66
75
  });
67
76
  });
68
77
  };
69
- Signer.prototype.signDeclareTransaction = function (
70
- // contractClass: ContractClass, // Should be used once class hash is present in ContractClass
71
- _a) {
72
- var classHash = _a.classHash, senderAddress = _a.senderAddress, chainId = _a.chainId, maxFee = _a.maxFee, version = _a.version, nonce = _a.nonce;
73
- return __awaiter(this, void 0, void 0, function () {
74
- var msgHash;
75
- return __generator(this, function (_b) {
76
- msgHash = (0, hash_1.calculateDeclareTransactionHash)(classHash, senderAddress, version, maxFee, chainId, nonce);
77
- return [2 /*return*/, (0, ellipticCurve_1.sign)(this.keyPair, msgHash)];
78
- });
79
- });
80
- };
81
78
  Signer.prototype.signDeployAccountTransaction = function (_a) {
82
79
  var classHash = _a.classHash, contractAddress = _a.contractAddress, constructorCalldata = _a.constructorCalldata, addressSalt = _a.addressSalt, maxFee = _a.maxFee, version = _a.version, chainId = _a.chainId, nonce = _a.nonce;
83
80
  return __awaiter(this, void 0, void 0, function () {
@@ -88,11 +85,14 @@ var Signer = /** @class */ (function () {
88
85
  });
89
86
  });
90
87
  };
91
- Signer.prototype.signMessage = function (typedData, accountAddress) {
88
+ Signer.prototype.signDeclareTransaction = function (
89
+ // contractClass: ContractClass, // Should be used once class hash is present in ContractClass
90
+ _a) {
91
+ var classHash = _a.classHash, senderAddress = _a.senderAddress, chainId = _a.chainId, maxFee = _a.maxFee, version = _a.version, nonce = _a.nonce;
92
92
  return __awaiter(this, void 0, void 0, function () {
93
93
  var msgHash;
94
- return __generator(this, function (_a) {
95
- msgHash = (0, typedData_1.getMessageHash)(typedData, accountAddress);
94
+ return __generator(this, function (_b) {
95
+ msgHash = (0, hash_1.calculateDeclareTransactionHash)(classHash, senderAddress, version, maxFee, chainId, nonce);
96
96
  return [2 /*return*/, (0, ellipticCurve_1.sign)(this.keyPair, msgHash)];
97
97
  });
98
98
  });
@@ -32,6 +32,7 @@ export declare abstract class SignerInterface {
32
32
  abstract signTransaction(transactions: Call[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): Promise<Signature>;
33
33
  /**
34
34
  * Signs a DEPLOY_ACCOUNT transaction with the starknet private key and returns the signature
35
+ *
35
36
  * @param transaction
36
37
  * - contractAddress - the computed address of the contract
37
38
  * - constructorCalldata - calldata to be passed in deploy constructor
@@ -45,6 +46,7 @@ export declare abstract class SignerInterface {
45
46
  abstract signDeployAccountTransaction(transaction: DeployAccountSignerDetails): Promise<Signature>;
46
47
  /**
47
48
  * Signs a DECLARE transaction with the starknet private key and returns the signature
49
+ *
48
50
  * @param transaction
49
51
  * - classHash - computed class hash. Will be replaced by ContractClass in future once class hash is present in CompiledContract
50
52
  * - senderAddress - the address of the sender
@@ -1,11 +1,5 @@
1
1
  import { BigNumberish } from '../../utils/number';
2
2
  import { Signature } from '../lib';
3
- export declare type RawArgs = {
4
- [inputName: string]: string | string[] | {
5
- type: 'struct';
6
- [k: string]: BigNumberish;
7
- };
8
- };
9
3
  export declare type Calldata = string[];
10
4
  export declare type Overrides = {
11
5
  maxFee?: BigNumberish;
@@ -1,6 +1,6 @@
1
1
  export * from './lib';
2
2
  export * as api from './api';
3
- export { Calldata, Overrides, RawArgs } from './api';
3
+ export { Calldata, Overrides } from './api';
4
4
  export * from './signer';
5
5
  export * from './contract';
6
6
  export * from './account';
@@ -5,11 +5,24 @@ export declare type KeyPair = EC.KeyPair;
5
5
  export declare type Signature = string[];
6
6
  export declare type RawCalldata = BigNumberish[];
7
7
  export declare type AllowArray<T> = T | T[];
8
+ export declare type RawArgs = {
9
+ [inputName: string]: string | string[] | {
10
+ type: 'struct';
11
+ [k: string]: BigNumberish;
12
+ };
13
+ } | string[];
8
14
  export interface ContractClass {
9
15
  program: CompressedProgram;
10
16
  entry_points_by_type: RPC.ContractClass['entry_points_by_type'];
11
17
  abi?: Abi;
12
18
  }
19
+ export declare type UniversalDeployerContractPayload = {
20
+ classHash: BigNumberish;
21
+ salt: string;
22
+ unique: boolean;
23
+ constructorCalldata?: RawArgs;
24
+ isDevnet?: boolean;
25
+ };
13
26
  export declare type DeployContractPayload = {
14
27
  contract: CompiledContract | string;
15
28
  constructorCalldata?: RawCalldata;
@@ -13,3 +13,4 @@ export declare const toHexString: (value: string) => string;
13
13
  export declare function getDecimalString(value: string): string;
14
14
  export declare function getHexString(value: string): string;
15
15
  export declare function getHexStringArray(value: Array<string>): string[];
16
+ export declare const toCairoBool: (value: boolean) => string;
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.getHexStringArray = exports.getHexString = exports.getDecimalString = exports.toHexString = exports.isStringWholeNumber = exports.bigNumberishArrayToHexadecimalStringArray = exports.bigNumberishArrayToDecimalStringArray = exports.assertInRange = exports.toFelt = exports.hexToDecimalString = exports.toHex = exports.toBN = exports.isHex = void 0;
29
+ exports.toCairoBool = exports.getHexStringArray = exports.getHexString = exports.getDecimalString = exports.toHexString = exports.isStringWholeNumber = exports.bigNumberishArrayToHexadecimalStringArray = exports.bigNumberishArrayToDecimalStringArray = exports.assertInRange = exports.toFelt = exports.hexToDecimalString = exports.toHex = exports.toBN = exports.isHex = void 0;
30
30
  var bn_js_1 = __importStar(require("bn.js"));
31
31
  var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
32
32
  var encode_1 = require("./encode");
@@ -108,3 +108,5 @@ function getHexStringArray(value) {
108
108
  return value.map(function (el) { return getHexString(el); });
109
109
  }
110
110
  exports.getHexStringArray = getHexStringArray;
111
+ var toCairoBool = function (value) { return (+value).toString(); };
112
+ exports.toCairoBool = toCairoBool;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starknet",
3
- "version": "4.9.0",
3
+ "version": "4.10.0",
4
4
  "description": "JavaScript library for StarkNet",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/provider/rpc.d.ts CHANGED
@@ -8,10 +8,12 @@ import { BlockIdentifier } from './utils';
8
8
  export declare type RpcProviderOptions = {
9
9
  nodeUrl: string;
10
10
  retries?: number;
11
+ headers?: object;
11
12
  };
12
13
  export declare class RpcProvider implements ProviderInterface {
13
14
  nodeUrl: string;
14
15
  chainId: StarknetChainId;
16
+ headers: object;
15
17
  private responseParser;
16
18
  private retries;
17
19
  constructor(optionsOrProvider: RpcProviderOptions);
@@ -34,7 +36,7 @@ export declare class RpcProvider implements ProviderInterface {
34
36
  getTransactionByBlockIdAndIndex(blockIdentifier: BlockIdentifier, index: number): Promise<RPC.GetTransactionByBlockIdAndIndex>;
35
37
  getTransactionReceipt(txHash: string): Promise<GetTransactionReceiptResponse>;
36
38
  getClass(classHash: RPC.Felt): Promise<RPC.ContractClass>;
37
- getClassAt(contractAddress: string, blockIdentifier: BlockIdentifier): Promise<RPC.ContractClass>;
39
+ getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<RPC.ContractClass>;
38
40
  getCode(_contractAddress: string, _blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
39
41
  getEstimateFee(invocation: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
40
42
  getInvokeEstimateFee(invocation: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;