starknet 3.10.3 → 3.12.1

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 (50) hide show
  1. package/.releaserc +1 -1
  2. package/CHANGELOG.md +30 -0
  3. package/__tests__/account.test.ts +3 -1
  4. package/__tests__/provider.test.ts +3 -3
  5. package/__tests__/utils/address.test.ts +30 -1
  6. package/account/default.d.ts +5 -3
  7. package/account/default.js +37 -6
  8. package/account/interface.d.ts +2 -2
  9. package/contract/default.d.ts +1 -1
  10. package/dist/account/default.d.ts +6 -3
  11. package/dist/account/default.js +23 -6
  12. package/dist/account/interface.d.ts +3 -2
  13. package/dist/contract/default.d.ts +1 -1
  14. package/dist/provider/default.d.ts +2 -6
  15. package/dist/provider/default.js +15 -11
  16. package/dist/provider/interface.d.ts +2 -5
  17. package/dist/provider/utils.js +2 -2
  18. package/dist/types/account.d.ts +5 -0
  19. package/dist/types/account.js +2 -0
  20. package/dist/types/api.d.ts +10 -2
  21. package/dist/types/lib.d.ts +1 -1
  22. package/dist/utils/address.d.ts +5 -2
  23. package/dist/utils/address.js +24 -5
  24. package/dist/utils/stark.js +1 -1
  25. package/package.json +2 -1
  26. package/provider/default.d.ts +2 -9
  27. package/provider/default.js +19 -22
  28. package/provider/interface.d.ts +2 -8
  29. package/provider/utils.js +2 -2
  30. package/src/account/default.ts +14 -6
  31. package/src/account/interface.ts +2 -2
  32. package/src/provider/default.ts +17 -15
  33. package/src/provider/interface.ts +2 -8
  34. package/src/provider/utils.ts +2 -2
  35. package/src/types/account.ts +7 -0
  36. package/src/types/api.ts +11 -2
  37. package/src/types/lib.ts +1 -1
  38. package/src/utils/address.ts +29 -8
  39. package/src/utils/stark.ts +1 -1
  40. package/types/account.d.ts +6 -0
  41. package/types/account.js +2 -0
  42. package/types/api.d.ts +11 -2
  43. package/types/lib.d.ts +1 -1
  44. package/utils/address.d.ts +5 -2
  45. package/utils/address.js +35 -5
  46. package/utils/stark.js +1 -1
  47. package/www/docs/API/changelog.md +1 -1
  48. package/www/docs/API/contract.md +1 -1
  49. package/www/docs/API/contractFacotry.md +2 -2
  50. package/www/docs/API/utils.md +34 -0
package/.releaserc CHANGED
@@ -24,5 +24,5 @@
24
24
  ],
25
25
  "@semantic-release/github"
26
26
  ],
27
- "repositoryUrl": "https://github.com/seanjameshan/starknet.js"
27
+ "repositoryUrl": "https://github.com/0xs34n/starknet.js"
28
28
  }
package/CHANGELOG.md CHANGED
@@ -1,3 +1,33 @@
1
+ ## [3.12.1](https://github.com/0xs34n/starknet.js/compare/v3.12.0...v3.12.1) (2022-05-24)
2
+
3
+ ### Bug Fixes
4
+
5
+ - update repo url ([c1312c0](https://github.com/0xs34n/starknet.js/commit/c1312c0e00e3387a49d1d7edc33e584687d607ea))
6
+
7
+ # [3.12.0](https://github.com/seanjameshan/starknet.js/compare/v3.11.0...v3.12.0) (2022-05-24)
8
+
9
+ ### Bug Fixes
10
+
11
+ - always default to latest block ([dafc575](https://github.com/seanjameshan/starknet.js/commit/dafc57550b9b175b79ec2fd728504ee14a992620))
12
+
13
+ ### Features
14
+
15
+ - add suggestedMaxFee ([8977772](https://github.com/seanjameshan/starknet.js/commit/8977772763ecd895006c00c9cbe1397429a19b6f))
16
+
17
+ # [3.11.0](https://github.com/seanjameshan/starknet.js/compare/v3.10.3...v3.11.0) (2022-05-11)
18
+
19
+ ### Bug Fixes
20
+
21
+ - review ([9ee4987](https://github.com/seanjameshan/starknet.js/commit/9ee498788185a35a75f2b429b3f1ec55dc4ee2a3))
22
+ - tests ([f535edb](https://github.com/seanjameshan/starknet.js/commit/f535edbef8da6050e54575792926488774e3ed0f))
23
+ - transaction receipt ([806eb7d](https://github.com/seanjameshan/starknet.js/commit/806eb7d63a01e158231f7b63cc4fc1fb0c30717e))
24
+ - use npm again ([3b9e176](https://github.com/seanjameshan/starknet.js/commit/3b9e176812f6401e167a207db2d9ff3686260e13))
25
+
26
+ ### Features
27
+
28
+ - add checksum addresses ([2d32ed8](https://github.com/seanjameshan/starknet.js/commit/2d32ed828f908090642a42d9f6620f050a75b43a))
29
+ - use BigNumber for estimate fee amount ([751c2ed](https://github.com/seanjameshan/starknet.js/commit/751c2edf89d019f365f5fba8123a9df0320ff543))
30
+
1
31
  ## [3.10.3](https://github.com/seanjameshan/starknet.js/compare/v3.10.2...v3.10.3) (2022-05-04)
2
32
 
3
33
  ### Bug Fixes
@@ -1,3 +1,5 @@
1
+ import { isBN } from 'bn.js';
2
+
1
3
  import typedDataExample from '../__mocks__/typedDataExample.json';
2
4
  import { Account, Contract, defaultProvider, ec, number, stark } from '../src';
3
5
  import { toBN } from '../src/utils/number';
@@ -50,7 +52,7 @@ describe('deploy and test Wallet', () => {
50
52
  entrypoint: 'transfer',
51
53
  calldata: [erc20.address, '10'],
52
54
  });
53
- expect(typeof amount).toBe('number');
55
+ expect(isBN(amount)).toBe(true);
54
56
  expect(typeof unit).toBe('string');
55
57
  });
56
58
 
@@ -76,9 +76,9 @@ describe('defaultProvider', () => {
76
76
 
77
77
  test('getTransactionReceipt', async () => {
78
78
  return expect(
79
- defaultProvider.getTransactionReceipt({
80
- txHash: '0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348',
81
- })
79
+ defaultProvider.getTransactionReceipt(
80
+ '0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348'
81
+ )
82
82
  ).resolves.not.toThrow();
83
83
  });
84
84
 
@@ -1,4 +1,9 @@
1
- import { addAddressPadding, validateAndParseAddress } from '../../src/utils/address';
1
+ import {
2
+ addAddressPadding,
3
+ getChecksumAddress,
4
+ validateAndParseAddress,
5
+ validateChecksumAddress,
6
+ } from '../../src/utils/address';
2
7
  // import { addHexPrefix, removeHexPrefix } from '../../src/utils/encode';
3
8
 
4
9
  describe('validateAndParseAddress', () => {
@@ -14,3 +19,27 @@ describe('validateAndParseAddress', () => {
14
19
  return expect(validateAndParseAddress(addr)).toEqual(`${addAddressPadding(addr)}`);
15
20
  });
16
21
  });
22
+
23
+ describe('address checksums', () => {
24
+ test('should be able to calculate checksum address', () => {
25
+ const checksumAddress = getChecksumAddress(
26
+ '0x2fd23d9182193775423497fc0c472e156c57c69e4089a1967fb288a2d84e914'
27
+ );
28
+ expect(checksumAddress).toEqual(
29
+ '0x02FD23D9182193775423497Fc0c472E156C57C69E4089a1967fb288a2D84e914'
30
+ );
31
+ });
32
+ test('should be able to verify checksum address', () => {
33
+ const isValid = validateChecksumAddress(
34
+ '0x02FD23D9182193775423497Fc0c472E156C57C69E4089a1967fb288a2D84e914'
35
+ );
36
+ expect(isValid).toEqual(true);
37
+ });
38
+ test('calculated checksum address should validate', () => {
39
+ const checksumAddress = getChecksumAddress(
40
+ '0x26cb0b500d175111341fabb53bf7fa4f5a0b8c5cbb31896cec1e8383a5edda8'
41
+ );
42
+ const isValid = validateChecksumAddress(checksumAddress);
43
+ expect(isValid).toEqual(true);
44
+ });
45
+ });
@@ -5,12 +5,12 @@ import {
5
5
  Abi,
6
6
  AddTransactionResponse,
7
7
  Call,
8
- EstimateFeeResponse,
9
8
  InvocationsDetails,
10
9
  KeyPair,
11
10
  Signature,
12
11
  Transaction,
13
12
  } from '../types';
13
+ import { EstimateFee } from '../types/account';
14
14
  import { BigNumberish } from '../utils/number';
15
15
  import { TypedData } from '../utils/typedData';
16
16
  import { AccountInterface } from './interface';
@@ -32,13 +32,15 @@ export declare class Account extends Provider implements AccountInterface {
32
32
  nonce?: BigNumberish;
33
33
  blockIdentifier?: BlockIdentifier;
34
34
  }
35
- ): Promise<EstimateFeeResponse>;
35
+ ): Promise<EstimateFee>;
36
36
  /**
37
37
  * Invoke execute function in account contract
38
38
  *
39
39
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
40
40
  *
41
- * @param transaction - transaction to be invoked
41
+ * @param calls - one or more calls to be executed
42
+ * @param abis - one or more abis which can be used to display the calls
43
+ * @param transactionsDetail - optional transaction details
42
44
  * @returns a confirmation of invoking a function on the starknet contract
43
45
  */
44
46
  execute(
@@ -24,6 +24,20 @@ var __extends =
24
24
  d.prototype = b === null ? Object.create(b) : ((__.prototype = b.prototype), new __());
25
25
  };
26
26
  })();
27
+ var __assign =
28
+ (this && this.__assign) ||
29
+ function () {
30
+ __assign =
31
+ Object.assign ||
32
+ function (t) {
33
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
34
+ s = arguments[i];
35
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
36
+ }
37
+ return t;
38
+ };
39
+ return __assign.apply(this, arguments);
40
+ };
27
41
  var __awaiter =
28
42
  (this && this.__awaiter) ||
29
43
  function (thisArg, _arguments, P, generator) {
@@ -242,7 +256,15 @@ var Account = /** @class */ (function (_super) {
242
256
  _c = _b.blockIdentifier,
243
257
  blockIdentifier = _c === void 0 ? 'pending' : _c;
244
258
  return __awaiter(this, void 0, void 0, function () {
245
- var transactions, nonce, _d, version, signerDetails, signature, calldata;
259
+ var transactions,
260
+ nonce,
261
+ _d,
262
+ version,
263
+ signerDetails,
264
+ signature,
265
+ calldata,
266
+ fetchedEstimate,
267
+ suggestedMaxFee;
246
268
  return __generator(this, function (_e) {
247
269
  switch (_e.label) {
248
270
  case 0:
@@ -270,7 +292,7 @@ var Account = /** @class */ (function (_super) {
270
292
  signature = _e.sent();
271
293
  calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
272
294
  return [
273
- 2 /*return*/,
295
+ 4 /*yield*/,
274
296
  this.fetchEndpoint(
275
297
  'estimate_fee',
276
298
  { blockIdentifier: blockIdentifier },
@@ -283,6 +305,13 @@ var Account = /** @class */ (function (_super) {
283
305
  }
284
306
  ),
285
307
  ];
308
+ case 5:
309
+ fetchedEstimate = _e.sent();
310
+ suggestedMaxFee = (0, stark_1.estimatedFeeToMaxFee)(fetchedEstimate.amount);
311
+ return [
312
+ 2 /*return*/,
313
+ __assign(__assign({}, fetchedEstimate), { suggestedMaxFee: suggestedMaxFee }),
314
+ ];
286
315
  }
287
316
  });
288
317
  });
@@ -292,7 +321,9 @@ var Account = /** @class */ (function (_super) {
292
321
  *
293
322
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
294
323
  *
295
- * @param transaction - transaction to be invoked
324
+ * @param calls - one or more calls to be executed
325
+ * @param abis - one or more abis which can be used to display the calls
326
+ * @param transactionsDetail - optional transaction details
296
327
  * @returns a confirmation of invoking a function on the starknet contract
297
328
  */
298
329
  Account.prototype.execute = function (calls, abis, transactionsDetail) {
@@ -304,7 +335,7 @@ var Account = /** @class */ (function (_super) {
304
335
  transactionsDetail = {};
305
336
  }
306
337
  return __awaiter(this, void 0, void 0, function () {
307
- var transactions, nonce, _b, _c, maxFee, estimatedFee, signerDetails, signature, calldata;
338
+ var transactions, nonce, _b, _c, maxFee, suggestedMaxFee, signerDetails, signature, calldata;
308
339
  return __generator(this, function (_d) {
309
340
  switch (_d.label) {
310
341
  case 0:
@@ -329,8 +360,8 @@ var Account = /** @class */ (function (_super) {
329
360
  case 4:
330
361
  return [4 /*yield*/, this.estimateFee(transactions, { nonce: nonce })];
331
362
  case 5:
332
- estimatedFee = _d.sent().amount;
333
- maxFee = (0, stark_1.estimatedFeeToMaxFee)(estimatedFee).toString();
363
+ suggestedMaxFee = _d.sent().suggestedMaxFee;
364
+ maxFee = suggestedMaxFee.toString();
334
365
  _d.label = 6;
335
366
  case 6:
336
367
  signerDetails = {
@@ -5,11 +5,11 @@ import {
5
5
  AddTransactionResponse,
6
6
  Call,
7
7
  DeployContractPayload,
8
- EstimateFeeResponse,
9
8
  Invocation,
10
9
  InvocationsDetails,
11
10
  Signature,
12
11
  } from '../types';
12
+ import { EstimateFee } from '../types/account';
13
13
  import { BigNumberish } from '../utils/number';
14
14
  import { TypedData } from '../utils/typedData/types';
15
15
  export declare abstract class AccountInterface extends ProviderInterface {
@@ -40,7 +40,7 @@ export declare abstract class AccountInterface extends ProviderInterface {
40
40
  *
41
41
  * @returns response from addTransaction
42
42
  */
43
- abstract estimateFee(invocation: Invocation): Promise<EstimateFeeResponse>;
43
+ abstract estimateFee(invocation: Invocation): Promise<EstimateFee>;
44
44
  /**
45
45
  * Invoke execute function in account contract
46
46
  *
@@ -148,6 +148,6 @@ export declare class Contract implements ContractInterface {
148
148
  blockIdentifier?: BlockIdentifier;
149
149
  }
150
150
  ): Promise<Result>;
151
- estimate(method: string, args?: Array<any>): Promise<import('../types').EstimateFeeResponse>;
151
+ estimate(method: string, args?: Array<any>): Promise<import('../types/account').EstimateFee>;
152
152
  populate(method: string, args?: Array<any>): Invocation;
153
153
  }
@@ -1,7 +1,8 @@
1
1
  import { Provider, ProviderInterface } from '../provider';
2
2
  import { BlockIdentifier } from '../provider/utils';
3
3
  import { SignerInterface } from '../signer';
4
- import { Abi, AddTransactionResponse, Call, EstimateFeeResponse, InvocationsDetails, KeyPair, Signature, Transaction } from '../types';
4
+ import { Abi, AddTransactionResponse, Call, InvocationsDetails, KeyPair, Signature, Transaction } from '../types';
5
+ import { EstimateFee } from '../types/account';
5
6
  import { BigNumberish } from '../utils/number';
6
7
  import { TypedData } from '../utils/typedData';
7
8
  import { AccountInterface } from './interface';
@@ -13,13 +14,15 @@ export declare class Account extends Provider implements AccountInterface {
13
14
  estimateFee(calls: Call | Call[], { nonce: providedNonce, blockIdentifier, }?: {
14
15
  nonce?: BigNumberish;
15
16
  blockIdentifier?: BlockIdentifier;
16
- }): Promise<EstimateFeeResponse>;
17
+ }): Promise<EstimateFee>;
17
18
  /**
18
19
  * Invoke execute function in account contract
19
20
  *
20
21
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
21
22
  *
22
- * @param transaction - transaction to be invoked
23
+ * @param calls - one or more calls to be executed
24
+ * @param abis - one or more abis which can be used to display the calls
25
+ * @param transactionsDetail - optional transaction details
23
26
  * @returns a confirmation of invoking a function on the starknet contract
24
27
  */
25
28
  execute(calls: Call | Call[], abis?: Abi[] | undefined, transactionsDetail?: InvocationsDetails): Promise<AddTransactionResponse>;
@@ -14,6 +14,17 @@ var __extends = (this && this.__extends) || (function () {
14
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
15
  };
16
16
  })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
17
28
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
29
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
30
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -119,7 +130,7 @@ var Account = /** @class */ (function (_super) {
119
130
  Account.prototype.estimateFee = function (calls, _a) {
120
131
  var _b = _a === void 0 ? {} : _a, providedNonce = _b.nonce, _c = _b.blockIdentifier, blockIdentifier = _c === void 0 ? 'pending' : _c;
121
132
  return __awaiter(this, void 0, void 0, function () {
122
- var transactions, nonce, _d, version, signerDetails, signature, calldata;
133
+ var transactions, nonce, _d, version, signerDetails, signature, calldata, fetchedEstimate, suggestedMaxFee;
123
134
  return __generator(this, function (_e) {
124
135
  switch (_e.label) {
125
136
  case 0:
@@ -145,13 +156,17 @@ var Account = /** @class */ (function (_super) {
145
156
  case 4:
146
157
  signature = _e.sent();
147
158
  calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
148
- return [2 /*return*/, this.fetchEndpoint('estimate_fee', { blockIdentifier: blockIdentifier }, {
159
+ return [4 /*yield*/, this.fetchEndpoint('estimate_fee', { blockIdentifier: blockIdentifier }, {
149
160
  contract_address: this.address,
150
161
  entry_point_selector: (0, hash_1.getSelectorFromName)('__execute__'),
151
162
  calldata: calldata,
152
163
  version: (0, number_1.toHex)(version),
153
164
  signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature),
154
165
  })];
166
+ case 5:
167
+ fetchedEstimate = _e.sent();
168
+ suggestedMaxFee = (0, stark_1.estimatedFeeToMaxFee)(fetchedEstimate.amount);
169
+ return [2 /*return*/, __assign(__assign({}, fetchedEstimate), { suggestedMaxFee: suggestedMaxFee })];
155
170
  }
156
171
  });
157
172
  });
@@ -161,7 +176,9 @@ var Account = /** @class */ (function (_super) {
161
176
  *
162
177
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
163
178
  *
164
- * @param transaction - transaction to be invoked
179
+ * @param calls - one or more calls to be executed
180
+ * @param abis - one or more abis which can be used to display the calls
181
+ * @param transactionsDetail - optional transaction details
165
182
  * @returns a confirmation of invoking a function on the starknet contract
166
183
  */
167
184
  Account.prototype.execute = function (calls, abis, transactionsDetail) {
@@ -169,7 +186,7 @@ var Account = /** @class */ (function (_super) {
169
186
  if (abis === void 0) { abis = undefined; }
170
187
  if (transactionsDetail === void 0) { transactionsDetail = {}; }
171
188
  return __awaiter(this, void 0, void 0, function () {
172
- var transactions, nonce, _b, _c, maxFee, estimatedFee, signerDetails, signature, calldata;
189
+ var transactions, nonce, _b, _c, maxFee, suggestedMaxFee, signerDetails, signature, calldata;
173
190
  return __generator(this, function (_d) {
174
191
  switch (_d.label) {
175
192
  case 0:
@@ -190,8 +207,8 @@ var Account = /** @class */ (function (_super) {
190
207
  return [3 /*break*/, 6];
191
208
  case 4: return [4 /*yield*/, this.estimateFee(transactions, { nonce: nonce })];
192
209
  case 5:
193
- estimatedFee = (_d.sent()).amount;
194
- maxFee = (0, stark_1.estimatedFeeToMaxFee)(estimatedFee).toString();
210
+ suggestedMaxFee = (_d.sent()).suggestedMaxFee;
211
+ maxFee = suggestedMaxFee.toString();
195
212
  _d.label = 6;
196
213
  case 6:
197
214
  signerDetails = {
@@ -1,6 +1,7 @@
1
1
  import { ProviderInterface } from '../provider';
2
2
  import { SignerInterface } from '../signer';
3
- import { Abi, AddTransactionResponse, Call, DeployContractPayload, EstimateFeeResponse, Invocation, InvocationsDetails, Signature } from '../types';
3
+ import { Abi, AddTransactionResponse, Call, DeployContractPayload, Invocation, InvocationsDetails, Signature } from '../types';
4
+ import { EstimateFee } from '../types/account';
4
5
  import { BigNumberish } from '../utils/number';
5
6
  import { TypedData } from '../utils/typedData/types';
6
7
  export declare abstract class AccountInterface extends ProviderInterface {
@@ -28,7 +29,7 @@ export declare abstract class AccountInterface extends ProviderInterface {
28
29
  *
29
30
  * @returns response from addTransaction
30
31
  */
31
- abstract estimateFee(invocation: Invocation): Promise<EstimateFeeResponse>;
32
+ abstract estimateFee(invocation: Invocation): Promise<EstimateFee>;
32
33
  /**
33
34
  * Invoke execute function in account contract
34
35
  *
@@ -119,6 +119,6 @@ export declare class Contract implements ContractInterface {
119
119
  call(method: string, args?: Array<any>, { blockIdentifier, }?: {
120
120
  blockIdentifier?: BlockIdentifier;
121
121
  }): Promise<Result>;
122
- estimate(method: string, args?: Array<any>): Promise<import("../types").EstimateFeeResponse>;
122
+ estimate(method: string, args?: Array<any>): Promise<import("../types/account").EstimateFee>;
123
123
  populate(method: string, args?: Array<any>): Invocation;
124
124
  }
@@ -1,5 +1,5 @@
1
1
  import { StarknetChainId } from '../constants';
2
- import { Abi, AddTransactionResponse, Call, CallContractResponse, DeployContractPayload, Endpoints, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, GetTransactionTraceResponse, Invocation, TransactionReceipt } from '../types';
2
+ import { Abi, AddTransactionResponse, Call, CallContractResponse, DeployContractPayload, Endpoints, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, GetTransactionTraceResponse, Invocation, TransactionReceiptResponse } from '../types';
3
3
  import { BigNumberish } from '../utils/number';
4
4
  import { ProviderInterface } from './interface';
5
5
  import { BlockIdentifier } from './utils';
@@ -90,13 +90,9 @@ export declare class Provider implements ProviderInterface {
90
90
  * [Reference] (https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L104-L111)
91
91
  *
92
92
  * @param txHash
93
- * @param txId
94
93
  * @returns the transaction receipt object
95
94
  */
96
- getTransactionReceipt({ txHash, txId, }: {
97
- txHash?: BigNumberish;
98
- txId?: BigNumberish;
99
- }): Promise<TransactionReceipt>;
95
+ getTransactionReceipt(txHash: BigNumberish): Promise<TransactionReceiptResponse>;
100
96
  /**
101
97
  * Gets the transaction information from a tx id.
102
98
  *
@@ -196,6 +196,16 @@ var Provider = /** @class */ (function () {
196
196
  _d.trys.push([1, 3, , 4]);
197
197
  return [4 /*yield*/, axios_1.default.request({
198
198
  method: method,
199
+ transformResponse: endpoint === 'estimate_fee'
200
+ ? function (res) {
201
+ return (0, json_1.parse)(res, function (_, v) {
202
+ if (v && typeof v === 'bigint') {
203
+ return (0, number_1.toBN)(v.toString());
204
+ }
205
+ return v;
206
+ });
207
+ }
208
+ : axios_1.default.defaults.transformResponse,
199
209
  url: (0, url_join_1.default)(baseUrl, endpoint, queryString),
200
210
  data: (0, json_1.stringify)(request),
201
211
  headers: headers,
@@ -330,20 +340,14 @@ var Provider = /** @class */ (function () {
330
340
  * [Reference] (https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L104-L111)
331
341
  *
332
342
  * @param txHash
333
- * @param txId
334
343
  * @returns the transaction receipt object
335
344
  */
336
- Provider.prototype.getTransactionReceipt = function (_a) {
337
- var txHash = _a.txHash, txId = _a.txId;
345
+ Provider.prototype.getTransactionReceipt = function (txHash) {
338
346
  return __awaiter(this, void 0, void 0, function () {
339
- var data;
340
- return __generator(this, function (_b) {
341
- switch (_b.label) {
342
- case 0: return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_transaction_receipt', "?" + (0, utils_1.txIdentifier)(txHash, txId)))];
343
- case 1:
344
- data = (_b.sent()).data;
345
- return [2 /*return*/, data];
346
- }
347
+ var txHashHex;
348
+ return __generator(this, function (_a) {
349
+ txHashHex = (0, number_1.toHex)((0, number_1.toBN)(txHash));
350
+ return [2 /*return*/, this.fetchEndpoint('get_transaction_receipt', { transactionHash: txHashHex })];
347
351
  });
348
352
  });
349
353
  };
@@ -1,5 +1,5 @@
1
1
  import { StarknetChainId } from '../constants';
2
- import type { AddTransactionResponse, Call, CallContractResponse, DeployContractPayload, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, Invocation, TransactionReceipt } from '../types';
2
+ import type { AddTransactionResponse, Call, CallContractResponse, DeployContractPayload, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, Invocation, TransactionReceiptResponse } from '../types';
3
3
  import type { BigNumberish } from '../utils/number';
4
4
  import { BlockIdentifier } from './utils';
5
5
  export declare abstract class ProviderInterface {
@@ -74,10 +74,7 @@ export declare abstract class ProviderInterface {
74
74
  * @returns the transacton object { transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? }
75
75
  */
76
76
  abstract getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
77
- abstract getTransactionReceipt({ txHash, txId, }: {
78
- txHash?: BigNumberish;
79
- txId?: BigNumberish;
80
- }): Promise<TransactionReceipt>;
77
+ abstract getTransactionReceipt(txHash: BigNumberish): Promise<TransactionReceiptResponse>;
81
78
  /**
82
79
  * Deploys a given compiled contract (json) to starknet
83
80
  *
@@ -36,8 +36,8 @@ exports.txIdentifier = txIdentifier;
36
36
  * @returns block identifier object
37
37
  */
38
38
  function getBlockIdentifier(blockIdentifier) {
39
- if (blockIdentifier === null) {
40
- return { type: 'BLOCK_NUMBER', data: null };
39
+ if (blockIdentifier === null || blockIdentifier === 'latest') {
40
+ return { type: 'BLOCK_NUMBER', data: 'latest' }; // default to latest block
41
41
  }
42
42
  if (blockIdentifier === 'pending') {
43
43
  return { type: 'BLOCK_NUMBER', data: 'pending' };
@@ -0,0 +1,5 @@
1
+ import BN from 'bn.js';
2
+ import { EstimateFeeResponse } from './api';
3
+ export interface EstimateFee extends EstimateFeeResponse {
4
+ suggestedMaxFee: BN;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,4 @@
1
+ import BN from 'bn.js';
1
2
  import { BlockIdentifier } from '../provider/utils';
2
3
  import { BigNumberish } from '../utils/number';
3
4
  import { Abi, BlockNumber, CompressedCompiledContract, EntryPointType, RawCalldata, Signature, Status, TransactionStatus } from './lib';
@@ -33,6 +34,13 @@ export declare type Endpoints = {
33
34
  REQUEST: never;
34
35
  RESPONSE: GetTransactionTraceResponse;
35
36
  };
37
+ get_transaction_receipt: {
38
+ QUERY: {
39
+ transactionHash: string;
40
+ };
41
+ REQUEST: never;
42
+ RESPONSE: TransactionReceiptResponse;
43
+ };
36
44
  get_storage_at: {
37
45
  QUERY: {
38
46
  contractAddress: string;
@@ -189,7 +197,7 @@ export declare type AddTransactionResponse = {
189
197
  transaction_hash: string;
190
198
  address?: string;
191
199
  };
192
- export declare type TransactionReceipt = {
200
+ export declare type TransactionReceiptResponse = {
193
201
  status: Status;
194
202
  transaction_hash: string;
195
203
  transaction_index: number;
@@ -199,7 +207,7 @@ export declare type TransactionReceipt = {
199
207
  events: string[];
200
208
  };
201
209
  export declare type EstimateFeeResponse = {
202
- amount: number;
210
+ amount: BN;
203
211
  unit: string;
204
212
  };
205
213
  export declare type RawArgs = {
@@ -47,7 +47,7 @@ export declare type StructAbi = {
47
47
  export declare type Abi = Array<FunctionAbi | StructAbi>;
48
48
  export declare type EntryPointsByType = object;
49
49
  export declare type Program = Record<any, any>;
50
- export declare type BlockNumber = 'pending' | null | number;
50
+ export declare type BlockNumber = 'pending' | 'latest' | null | number;
51
51
  export declare type CompiledContract = {
52
52
  abi: Abi;
53
53
  entry_points_by_type: EntryPointsByType;
@@ -1,2 +1,5 @@
1
- export declare function addAddressPadding(address: string): string;
2
- export declare function validateAndParseAddress(address: string): string;
1
+ import { BigNumberish } from './number';
2
+ export declare function addAddressPadding(address: BigNumberish): string;
3
+ export declare function validateAndParseAddress(address: BigNumberish): string;
4
+ export declare function getChecksumAddress(address: BigNumberish): string;
5
+ export declare function validateChecksumAddress(address: string): boolean;
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateAndParseAddress = exports.addAddressPadding = void 0;
3
+ exports.validateChecksumAddress = exports.getChecksumAddress = exports.validateAndParseAddress = exports.addAddressPadding = void 0;
4
+ /* eslint-disable no-bitwise */
5
+ var bytes_1 = require("@ethersproject/bytes");
4
6
  var constants_1 = require("../constants");
5
7
  var encode_1 = require("./encode");
8
+ var hash_1 = require("./hash");
6
9
  var number_1 = require("./number");
7
10
  function addAddressPadding(address) {
8
- return (0, encode_1.addHexPrefix)((0, encode_1.removeHexPrefix)(address).padStart(64, '0'));
11
+ return (0, encode_1.addHexPrefix)((0, encode_1.removeHexPrefix)((0, number_1.toHex)((0, number_1.toBN)(address))).padStart(64, '0'));
9
12
  }
10
13
  exports.addAddressPadding = addAddressPadding;
11
14
  function validateAndParseAddress(address) {
12
- if (typeof address !== 'string') {
13
- throw new Error('Invalid Address Type');
14
- }
15
15
  (0, number_1.assertInRange)(address, constants_1.ZERO, constants_1.MASK_251, 'Starknet Address');
16
16
  var result = addAddressPadding(address);
17
17
  if (!result.match(/^(0x)?[0-9a-fA-F]{64}$/)) {
@@ -20,3 +20,22 @@ function validateAndParseAddress(address) {
20
20
  return result;
21
21
  }
22
22
  exports.validateAndParseAddress = validateAndParseAddress;
23
+ // from https://github.com/ethers-io/ethers.js/blob/fc1e006575d59792fa97b4efb9ea2f8cca1944cf/packages/address/src.ts/index.ts#L12
24
+ function getChecksumAddress(address) {
25
+ var chars = (0, encode_1.removeHexPrefix)(validateAndParseAddress(address)).toLowerCase().split('');
26
+ var hashed = (0, bytes_1.arrayify)((0, hash_1.pedersen)([0, address]), { hexPad: 'left' }); // as the hash will be 251 bits (63 chars) we need to pad it to 64 chars without changing the number value ("left")
27
+ for (var i = 0; i < chars.length; i += 2) {
28
+ if (hashed[i >> 1] >> 4 >= 8) {
29
+ chars[i] = chars[i].toUpperCase();
30
+ }
31
+ if ((hashed[i >> 1] & 0x0f) >= 8) {
32
+ chars[i + 1] = chars[i + 1].toUpperCase();
33
+ }
34
+ }
35
+ return (0, encode_1.addHexPrefix)(chars.join(''));
36
+ }
37
+ exports.getChecksumAddress = getChecksumAddress;
38
+ function validateChecksumAddress(address) {
39
+ return getChecksumAddress(address) === address;
40
+ }
41
+ exports.validateChecksumAddress = validateChecksumAddress;
@@ -83,7 +83,7 @@ function compileCalldata(args) {
83
83
  }
84
84
  exports.compileCalldata = compileCalldata;
85
85
  function estimatedFeeToMaxFee(estimatedFee, overhead) {
86
- if (overhead === void 0) { overhead = 0.15; }
86
+ if (overhead === void 0) { overhead = 0.5; }
87
87
  // BN can only handle Integers, so we need to do all calulations with integers
88
88
  var overHeadPercent = Math.round((1 + overhead) * 100);
89
89
  return (0, number_1.toBN)(estimatedFee).mul((0, number_1.toBN)(overHeadPercent)).div((0, number_1.toBN)(100));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starknet",
3
- "version": "3.10.3",
3
+ "version": "3.12.1",
4
4
  "description": "JavaScript library for StarkNet",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -61,6 +61,7 @@
61
61
  "typescript": "^4.4.4"
62
62
  },
63
63
  "dependencies": {
64
+ "@ethersproject/bytes": "^5.6.1",
64
65
  "axios": "^0.23.0",
65
66
  "bn.js": "^5.2.0",
66
67
  "elliptic": "^6.5.4",