starknet 3.18.2 → 3.19.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 (158) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/__tests__/account.test.ts +11 -56
  3. package/__tests__/contract.test.ts +11 -49
  4. package/__tests__/defaultProvider.test.ts +321 -0
  5. package/__tests__/fixtures.ts +32 -11
  6. package/__tests__/rpcProvider.test.ts +17 -0
  7. package/__tests__/sequencerProvider.test.ts +45 -0
  8. package/account/default.d.ts +54 -77
  9. package/account/default.js +271 -596
  10. package/account/index.js +18 -31
  11. package/account/interface.d.ts +66 -95
  12. package/account/interface.js +20 -30
  13. package/constants.d.ts +17 -19
  14. package/constants.js +2038 -2059
  15. package/contract/contractFactory.d.ts +25 -29
  16. package/contract/contractFactory.js +94 -210
  17. package/contract/default.d.ts +117 -146
  18. package/contract/default.js +582 -776
  19. package/contract/index.js +19 -32
  20. package/contract/interface.d.ts +72 -92
  21. package/contract/interface.js +6 -5
  22. package/dist/account/default.d.ts +5 -9
  23. package/dist/account/default.js +35 -169
  24. package/dist/account/interface.d.ts +3 -15
  25. package/dist/contract/contractFactory.js +4 -4
  26. package/dist/contract/default.d.ts +3 -3
  27. package/dist/contract/default.js +3 -2
  28. package/dist/contract/interface.d.ts +2 -2
  29. package/dist/provider/default.d.ts +18 -134
  30. package/dist/provider/default.js +47 -411
  31. package/dist/provider/index.d.ts +2 -0
  32. package/dist/provider/index.js +2 -0
  33. package/dist/provider/interface.d.ts +45 -50
  34. package/dist/provider/rpc.d.ts +57 -0
  35. package/dist/provider/rpc.js +364 -0
  36. package/dist/provider/sequencer.d.ts +66 -0
  37. package/dist/provider/sequencer.js +443 -0
  38. package/dist/types/account.d.ts +2 -3
  39. package/dist/types/api/index.d.ts +16 -0
  40. package/dist/types/api/index.js +18 -0
  41. package/dist/types/api/rpc.d.ts +221 -0
  42. package/dist/types/{api.js → api/rpc.js} +0 -0
  43. package/dist/types/api/sequencer.d.ts +289 -0
  44. package/dist/types/api/sequencer.js +2 -0
  45. package/dist/types/index.d.ts +3 -1
  46. package/dist/types/index.js +15 -1
  47. package/dist/types/lib.d.ts +3 -1
  48. package/dist/types/provider.d.ts +86 -0
  49. package/dist/types/provider.js +2 -0
  50. package/dist/utils/provider.d.ts +4 -0
  51. package/dist/utils/provider.js +38 -0
  52. package/dist/utils/responseParser/index.d.ts +11 -0
  53. package/dist/utils/responseParser/index.js +9 -0
  54. package/dist/utils/responseParser/rpc.d.ts +13 -0
  55. package/dist/utils/responseParser/rpc.js +96 -0
  56. package/dist/utils/responseParser/sequencer.d.ts +13 -0
  57. package/dist/utils/responseParser/sequencer.js +124 -0
  58. package/index.js +42 -75
  59. package/package.json +1 -1
  60. package/provider/default.d.ts +21 -175
  61. package/provider/default.js +139 -704
  62. package/provider/errors.d.ts +4 -4
  63. package/provider/errors.js +30 -40
  64. package/provider/index.d.ts +2 -0
  65. package/provider/index.js +22 -33
  66. package/provider/interface.d.ts +104 -131
  67. package/provider/interface.js +6 -5
  68. package/provider/rpc.d.ts +57 -0
  69. package/provider/rpc.js +364 -0
  70. package/provider/sequencer.d.ts +66 -0
  71. package/provider/sequencer.js +443 -0
  72. package/provider/utils.d.ts +7 -9
  73. package/provider/utils.js +39 -44
  74. package/signer/default.d.ts +5 -9
  75. package/signer/default.js +72 -177
  76. package/signer/index.js +18 -31
  77. package/signer/interface.d.ts +29 -33
  78. package/signer/interface.js +6 -5
  79. package/src/account/default.ts +26 -146
  80. package/src/account/interface.ts +5 -20
  81. package/src/contract/contractFactory.ts +3 -6
  82. package/src/contract/default.ts +6 -4
  83. package/src/contract/interface.ts +2 -2
  84. package/src/provider/default.ts +63 -395
  85. package/src/provider/index.ts +2 -0
  86. package/src/provider/interface.ts +68 -63
  87. package/src/provider/rpc.ts +300 -0
  88. package/src/provider/sequencer.ts +384 -0
  89. package/src/types/account.ts +2 -3
  90. package/src/types/api/index.ts +17 -0
  91. package/src/types/api/rpc.ts +247 -0
  92. package/src/types/api/sequencer.ts +331 -0
  93. package/src/types/index.ts +3 -1
  94. package/src/types/lib.ts +3 -1
  95. package/src/types/provider.ts +108 -0
  96. package/src/utils/provider.ts +28 -0
  97. package/src/utils/responseParser/index.ts +28 -0
  98. package/src/utils/responseParser/rpc.ts +93 -0
  99. package/src/utils/responseParser/sequencer.ts +127 -0
  100. package/types/account.d.ts +5 -7
  101. package/types/account.js +2 -2
  102. package/types/api/index.d.ts +16 -0
  103. package/types/api/index.js +18 -0
  104. package/types/api/rpc.d.ts +221 -0
  105. package/types/api/rpc.js +2 -0
  106. package/types/api/sequencer.d.ts +289 -0
  107. package/types/api/sequencer.js +2 -0
  108. package/types/contract.d.ts +1 -1
  109. package/types/contract.js +2 -2
  110. package/types/index.d.ts +3 -1
  111. package/types/index.js +35 -34
  112. package/types/lib.d.ts +36 -41
  113. package/types/lib.js +2 -2
  114. package/types/provider.d.ts +86 -0
  115. package/types/provider.js +2 -0
  116. package/types/signer.d.ts +2 -2
  117. package/types/signer.js +2 -2
  118. package/utils/address.js +26 -37
  119. package/utils/ellipticCurve.d.ts +1 -6
  120. package/utils/ellipticCurve.js +73 -137
  121. package/utils/encode.js +49 -85
  122. package/utils/hash.d.ts +4 -31
  123. package/utils/hash.js +76 -141
  124. package/utils/json.d.ts +13 -45
  125. package/utils/json.js +15 -22
  126. package/utils/number.d.ts +2 -9
  127. package/utils/number.js +47 -81
  128. package/utils/provider.d.ts +4 -0
  129. package/utils/provider.js +38 -0
  130. package/utils/responseParser/index.d.ts +11 -0
  131. package/utils/responseParser/index.js +9 -0
  132. package/utils/responseParser/rpc.d.ts +13 -0
  133. package/utils/responseParser/rpc.js +96 -0
  134. package/utils/responseParser/sequencer.d.ts +13 -0
  135. package/utils/responseParser/sequencer.js +124 -0
  136. package/utils/shortString.js +13 -21
  137. package/utils/stark.d.ts +0 -1
  138. package/utils/stark.js +59 -93
  139. package/utils/transaction.d.ts +3 -6
  140. package/utils/transaction.js +50 -81
  141. package/utils/typedData/index.d.ts +3 -15
  142. package/utils/typedData/index.js +109 -175
  143. package/utils/typedData/types.d.ts +9 -9
  144. package/utils/typedData/types.js +2 -2
  145. package/utils/typedData/utils.js +6 -6
  146. package/utils/uint256.d.ts +5 -5
  147. package/utils/uint256.js +16 -26
  148. package/www/docs/API/account.md +3 -4
  149. package/www/docs/API/contract.md +2 -2
  150. package/www/docs/API/contractFactory.md +2 -2
  151. package/www/docs/API/provider.md +185 -74
  152. package/www/guides/account.md +1 -8
  153. package/www/guides/erc20.md +3 -0
  154. package/__tests__/provider.test.ts +0 -168
  155. package/dist/types/api.d.ts +0 -261
  156. package/src/types/api.ts +0 -303
  157. package/types/api.d.ts +0 -287
  158. package/types/api.js +0 -2
package/account/index.js CHANGED
@@ -1,31 +1,18 @@
1
- 'use strict';
2
- var __createBinding =
3
- (this && this.__createBinding) ||
4
- (Object.create
5
- ? function (o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
- desc = {
10
- enumerable: true,
11
- get: function () {
12
- return m[k];
13
- },
14
- };
15
- }
16
- Object.defineProperty(o, k2, desc);
17
- }
18
- : function (o, m, k, k2) {
19
- if (k2 === undefined) k2 = k;
20
- o[k2] = m[k];
21
- });
22
- var __exportStar =
23
- (this && this.__exportStar) ||
24
- function (m, exports) {
25
- for (var p in m)
26
- if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p))
27
- __createBinding(exports, m, p);
28
- };
29
- Object.defineProperty(exports, '__esModule', { value: true });
30
- __exportStar(require('./default'), exports);
31
- __exportStar(require('./interface'), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./default"), exports);
18
+ __exportStar(require("./interface"), exports);
@@ -1,101 +1,72 @@
1
1
  import { ProviderInterface } from '../provider';
2
2
  import { SignerInterface } from '../signer';
3
- import {
4
- Abi,
5
- AddTransactionResponse,
6
- Call,
7
- DeployContractPayload,
8
- InvocationsDetails,
9
- Signature,
10
- } from '../types';
11
- import { EstimateFee, EstimateFeeDetails } from '../types/account';
3
+ import { Abi, Call, EstimateFeeDetails, EstimateFeeResponse, InvocationsDetails, InvokeFunctionResponse, Signature } from '../types';
12
4
  import { BigNumberish } from '../utils/number';
13
5
  import { TypedData } from '../utils/typedData/types';
14
6
  export declare abstract class AccountInterface extends ProviderInterface {
15
- abstract address: string;
16
- abstract signer: SignerInterface;
17
- /**
18
- * Deploys a given compiled contract (json) to starknet
19
- *
20
- * @param payload payload to be deployed containing:
21
- * - compiled contract code
22
- * - constructor calldata
23
- * - address salt
24
- * @param abi the abi of the contract
25
- * @returns a confirmation of sending a transaction on the starknet contract
26
- */
27
- abstract deployContract(
28
- payload: DeployContractPayload,
29
- abi?: Abi
30
- ): Promise<AddTransactionResponse>;
31
- /**
32
- * Estimate Fee for a method on starknet
33
- *
34
- * @param invocation the invocation object containing:
35
- * - contractAddress - the address of the contract
36
- * - entrypoint - the entrypoint of the contract
37
- * - calldata - (defaults to []) the calldata
38
- * - signature - (defaults to []) the signature
39
- *
40
- * @returns response from addTransaction
41
- */
42
- abstract estimateFee(
43
- calls: Call | Call[],
44
- estimateFeeDetails?: EstimateFeeDetails
45
- ): Promise<EstimateFee>;
46
- /**
47
- * Invoke execute function in account contract
48
- *
49
- * @param transactions the invocation object or an array of them, containing:
50
- * - contractAddress - the address of the contract
51
- * - entrypoint - the entrypoint of the contract
52
- * - calldata - (defaults to []) the calldata
53
- * - signature - (defaults to []) the signature
54
- * @param abi (optional) the abi of the contract for better displaying
55
- *
56
- * @returns response from addTransaction
57
- */
58
- abstract execute(
59
- transactions: Call | Call[],
60
- abis?: Abi[],
61
- transactionsDetail?: InvocationsDetails
62
- ): Promise<AddTransactionResponse>;
63
- /**
64
- * Sign an JSON object for off-chain usage with the starknet private key and return the signature
65
- * This adds a message prefix so it cant be interchanged with transactions
66
- *
67
- * @param json - JSON object to be signed
68
- * @returns the signature of the JSON object
69
- * @throws {Error} if the JSON object is not a valid JSON
70
- */
71
- abstract signMessage(typedData: TypedData): Promise<Signature>;
72
- /**
73
- * Hash a JSON object with pederson hash and return the hash
74
- * This adds a message prefix so it cant be interchanged with transactions
75
- *
76
- * @param json - JSON object to be hashed
77
- * @returns the hash of the JSON object
78
- * @throws {Error} if the JSON object is not a valid JSON
79
- */
80
- abstract hashMessage(typedData: TypedData): Promise<string>;
81
- /**
82
- * Verify a signature of a JSON object
83
- *
84
- * @param json - JSON object to be verified
85
- * @param signature - signature of the JSON object
86
- * @returns true if the signature is valid, false otherwise
87
- * @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
88
- */
89
- abstract verifyMessage(typedData: TypedData, signature: Signature): Promise<boolean>;
90
- /**
91
- * Verify a signature of a given hash
92
- * @warning This method is not recommended, use verifyMessage instead
93
- *
94
- * @param hash - hash to be verified
95
- * @param signature - signature of the hash
96
- * @returns true if the signature is valid, false otherwise
97
- * @throws {Error} if the signature is not a valid signature
98
- */
99
- abstract verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
100
- abstract getNonce(): Promise<string>;
7
+ abstract address: string;
8
+ abstract signer: SignerInterface;
9
+ /**
10
+ * Estimate Fee for a method on starknet
11
+ *
12
+ * @param invocation the invocation object containing:
13
+ * - contractAddress - the address of the contract
14
+ * - entrypoint - the entrypoint of the contract
15
+ * - calldata - (defaults to []) the calldata
16
+ * - signature - (defaults to []) the signature
17
+ *
18
+ * @returns response from addTransaction
19
+ */
20
+ abstract estimateFee(calls: Call | Call[], estimateFeeDetails?: EstimateFeeDetails): Promise<EstimateFeeResponse>;
21
+ /**
22
+ * Invoke execute function in account contract
23
+ *
24
+ * @param transactions the invocation object or an array of them, containing:
25
+ * - contractAddress - the address of the contract
26
+ * - entrypoint - the entrypoint of the contract
27
+ * - calldata - (defaults to []) the calldata
28
+ * - signature - (defaults to []) the signature
29
+ * @param abi (optional) the abi of the contract for better displaying
30
+ *
31
+ * @returns response from addTransaction
32
+ */
33
+ abstract execute(transactions: Call | Call[], abis?: Abi[], transactionsDetail?: InvocationsDetails): Promise<InvokeFunctionResponse>;
34
+ /**
35
+ * Sign an JSON object for off-chain usage with the starknet private key and return the signature
36
+ * This adds a message prefix so it cant be interchanged with transactions
37
+ *
38
+ * @param json - JSON object to be signed
39
+ * @returns the signature of the JSON object
40
+ * @throws {Error} if the JSON object is not a valid JSON
41
+ */
42
+ abstract signMessage(typedData: TypedData): Promise<Signature>;
43
+ /**
44
+ * Hash a JSON object with pederson hash and return the hash
45
+ * This adds a message prefix so it cant be interchanged with transactions
46
+ *
47
+ * @param json - JSON object to be hashed
48
+ * @returns the hash of the JSON object
49
+ * @throws {Error} if the JSON object is not a valid JSON
50
+ */
51
+ abstract hashMessage(typedData: TypedData): Promise<string>;
52
+ /**
53
+ * Verify a signature of a JSON object
54
+ *
55
+ * @param json - JSON object to be verified
56
+ * @param signature - signature of the JSON object
57
+ * @returns true if the signature is valid, false otherwise
58
+ * @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
59
+ */
60
+ abstract verifyMessage(typedData: TypedData, signature: Signature): Promise<boolean>;
61
+ /**
62
+ * Verify a signature of a given hash
63
+ * @warning This method is not recommended, use verifyMessage instead
64
+ *
65
+ * @param hash - hash to be verified
66
+ * @param signature - signature of the hash
67
+ * @returns true if the signature is valid, false otherwise
68
+ * @throws {Error} if the signature is not a valid signature
69
+ */
70
+ abstract verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
71
+ abstract getNonce(): Promise<string>;
101
72
  }
@@ -1,37 +1,27 @@
1
- 'use strict';
2
- var __extends =
3
- (this && this.__extends) ||
4
- (function () {
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
5
3
  var extendStatics = function (d, b) {
6
- extendStatics =
7
- Object.setPrototypeOf ||
8
- ({ __proto__: [] } instanceof Array &&
9
- function (d, b) {
10
- d.__proto__ = b;
11
- }) ||
12
- function (d, b) {
13
- for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
14
- };
15
- return extendStatics(d, b);
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
16
8
  };
17
9
  return function (d, b) {
18
- if (typeof b !== 'function' && b !== null)
19
- throw new TypeError('Class extends value ' + String(b) + ' is not a constructor or null');
20
- extendStatics(d, b);
21
- function __() {
22
- this.constructor = d;
23
- }
24
- d.prototype = b === null ? Object.create(b) : ((__.prototype = b.prototype), new __());
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
25
15
  };
26
- })();
27
- Object.defineProperty(exports, '__esModule', { value: true });
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
28
18
  exports.AccountInterface = void 0;
29
- var provider_1 = require('../provider');
19
+ var provider_1 = require("../provider");
30
20
  var AccountInterface = /** @class */ (function (_super) {
31
- __extends(AccountInterface, _super);
32
- function AccountInterface() {
33
- return (_super !== null && _super.apply(this, arguments)) || this;
34
- }
35
- return AccountInterface;
36
- })(provider_1.ProviderInterface);
21
+ __extends(AccountInterface, _super);
22
+ function AccountInterface() {
23
+ return _super !== null && _super.apply(this, arguments) || this;
24
+ }
25
+ return AccountInterface;
26
+ }(provider_1.ProviderInterface));
37
27
  exports.AccountInterface = AccountInterface;
package/constants.d.ts CHANGED
@@ -1,31 +1,29 @@
1
1
  /// <reference types="bn.js" />
2
2
  export { IS_BROWSER } from './utils/encode';
3
- export declare const ZERO: import('bn.js');
4
- export declare const ONE: import('bn.js');
5
- export declare const TWO: import('bn.js');
6
- export declare const MASK_250: import('bn.js');
7
- export declare const MASK_251: import('bn.js');
3
+ export declare const ZERO: import("bn.js");
4
+ export declare const ONE: import("bn.js");
5
+ export declare const TWO: import("bn.js");
6
+ export declare const MASK_250: import("bn.js");
7
+ export declare const MASK_251: import("bn.js");
8
8
  export declare enum StarknetChainId {
9
- MAINNET = '0x534e5f4d41494e',
10
- TESTNET = '0x534e5f474f45524c49',
9
+ MAINNET = "0x534e5f4d41494e",
10
+ TESTNET = "0x534e5f474f45524c49"
11
11
  }
12
12
  export declare enum TransactionHashPrefix {
13
- DECLARE = '0x6465636c617265',
14
- DEPLOY = '0x6465706c6f79',
15
- INVOKE = '0x696e766f6b65',
16
- L1_HANDLER = '0x6c315f68616e646c6572',
13
+ DECLARE = "0x6465636c617265",
14
+ DEPLOY = "0x6465706c6f79",
15
+ INVOKE = "0x696e766f6b65",
16
+ L1_HANDLER = "0x6c315f68616e646c6572"
17
17
  }
18
18
  /**
19
19
  * The following is taken from https://github.com/starkware-libs/starkex-resources/blob/master/crypto/starkware/crypto/signature/pedersen_params.json but converted to hex, because JS is very bad handling big integers by default
20
20
  * Please do not edit until the JSON changes.
21
21
  */
22
- export declare const FIELD_PRIME =
23
- '800000000000011000000000000000000000000000000000000000000000001';
24
- export declare const FIELD_GEN = '3';
22
+ export declare const FIELD_PRIME = "800000000000011000000000000000000000000000000000000000000000001";
23
+ export declare const FIELD_GEN = "3";
25
24
  export declare const FIELD_SIZE = 251;
26
- export declare const EC_ORDER = '800000000000010FFFFFFFFFFFFFFFFB781126DCAE7B2321E66A241ADC64D2F';
27
- export declare const ALPHA = '1';
28
- export declare const BETA = '6F21413EFBE40DE150E596D72F7A8C5609AD26C15C915C1F4CDFCB99CEE9E89';
29
- export declare const MAX_ECDSA_VAL =
30
- '800000000000000000000000000000000000000000000000000000000000000';
25
+ export declare const EC_ORDER = "800000000000010FFFFFFFFFFFFFFFFB781126DCAE7B2321E66A241ADC64D2F";
26
+ export declare const ALPHA = "1";
27
+ export declare const BETA = "6F21413EFBE40DE150E596D72F7A8C5609AD26C15C915C1F4CDFCB99CEE9E89";
28
+ export declare const MAX_ECDSA_VAL = "800000000000000000000000000000000000000000000000000000000000000";
31
29
  export declare const CONSTANT_POINTS: string[][];