starknet 4.9.0 → 4.11.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 (81) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/README.md +1 -3
  3. package/__tests__/account.test.ts +5 -1
  4. package/__tests__/defaultProvider.test.ts +97 -210
  5. package/__tests__/fixtures.ts +2 -2
  6. package/__tests__/rpcProvider.test.ts +7 -4
  7. package/__tests__/udc.test.ts +41 -0
  8. package/account/default.d.ts +3 -1
  9. package/account/default.js +53 -3
  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 +53 -3
  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/default.d.ts +4 -2
  25. package/dist/provider/default.js +13 -2
  26. package/dist/provider/interface.d.ts +18 -3
  27. package/dist/provider/rpc.d.ts +15 -10
  28. package/dist/provider/rpc.js +71 -31
  29. package/dist/provider/sequencer.d.ts +6 -2
  30. package/dist/provider/sequencer.js +33 -5
  31. package/dist/signer/default.d.ts +2 -2
  32. package/dist/signer/default.js +15 -15
  33. package/dist/signer/interface.d.ts +2 -0
  34. package/dist/types/api/index.d.ts +0 -6
  35. package/dist/types/api/openrpc.d.ts +147 -98
  36. package/dist/types/api/openrpc.js +22 -4
  37. package/dist/types/index.d.ts +1 -1
  38. package/dist/types/lib.d.ts +22 -2
  39. package/dist/types/lib.js +6 -0
  40. package/dist/utils/number.d.ts +1 -0
  41. package/dist/utils/number.js +3 -1
  42. package/package.json +1 -1
  43. package/provider/default.d.ts +4 -2
  44. package/provider/default.js +13 -2
  45. package/provider/interface.d.ts +18 -3
  46. package/provider/rpc.d.ts +15 -10
  47. package/provider/rpc.js +71 -31
  48. package/provider/sequencer.d.ts +6 -2
  49. package/provider/sequencer.js +33 -5
  50. package/signer/default.d.ts +2 -2
  51. package/signer/default.js +15 -15
  52. package/signer/interface.d.ts +2 -0
  53. package/src/account/default.ts +51 -7
  54. package/src/account/interface.ts +34 -7
  55. package/src/constants.ts +7 -0
  56. package/src/contract/default.ts +123 -140
  57. package/src/contract/interface.ts +5 -2
  58. package/src/provider/default.ts +21 -3
  59. package/src/provider/interface.ts +26 -2
  60. package/src/provider/rpc.ts +73 -45
  61. package/src/provider/sequencer.ts +24 -4
  62. package/src/signer/default.ts +18 -18
  63. package/src/signer/interface.ts +2 -0
  64. package/src/types/api/index.ts +0 -4
  65. package/src/types/api/openrpc.ts +193 -105
  66. package/src/types/api/rpc.ts +0 -1
  67. package/src/types/index.ts +1 -1
  68. package/src/types/lib.ts +23 -2
  69. package/src/utils/number.ts +2 -0
  70. package/types/api/index.d.ts +0 -6
  71. package/types/api/openrpc.d.ts +147 -98
  72. package/types/api/openrpc.js +22 -4
  73. package/types/index.d.ts +1 -1
  74. package/types/lib.d.ts +22 -2
  75. package/types/lib.js +6 -0
  76. package/utils/number.d.ts +1 -0
  77. package/utils/number.js +3 -1
  78. package/www/docs/API/account.md +122 -22
  79. package/www/docs/API/contract.md +39 -3
  80. package/www/docs/API/provider.md +4 -0
  81. package/www/docs/API/signer.md +56 -2
@@ -84,6 +84,17 @@ var Provider = /** @class */ (function () {
84
84
  });
85
85
  });
86
86
  };
87
+ Provider.prototype.getClassHashAt = function (contractAddress, blockIdentifier) {
88
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
89
+ return __awaiter(this, void 0, void 0, function () {
90
+ return __generator(this, function (_a) {
91
+ return [2 /*return*/, this.provider.getClassHashAt(contractAddress, blockIdentifier)];
92
+ });
93
+ });
94
+ };
95
+ Provider.prototype.getClass = function (classHash) {
96
+ return this.provider.getClass(classHash);
97
+ };
87
98
  Provider.prototype.getEstimateFee = function (invocationWithTxType, invocationDetails, blockIdentifier) {
88
99
  if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
89
100
  return __awaiter(this, void 0, void 0, function () {
@@ -144,10 +155,10 @@ var Provider = /** @class */ (function () {
144
155
  });
145
156
  });
146
157
  };
147
- Provider.prototype.deployContract = function (payload) {
158
+ Provider.prototype.deployContract = function (payload, details) {
148
159
  return __awaiter(this, void 0, void 0, function () {
149
160
  return __generator(this, function (_a) {
150
- return [2 /*return*/, this.provider.deployContract(payload)];
161
+ return [2 /*return*/, this.provider.deployContract(payload, details)];
151
162
  });
152
163
  });
153
164
  };
@@ -1,6 +1,6 @@
1
1
  import { StarknetChainId } from '../constants';
2
2
  import type { Call, CallContractResponse, ContractClass, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
3
- import { DeclareContractTransaction, DeployAccountContractPayload, DeployAccountContractTransaction } from '../types/lib';
3
+ import { DeclareContractTransaction, DeployAccountContractPayload, DeployAccountContractTransaction, InvocationsDetails } from '../types/lib';
4
4
  import type { BigNumberish } from '../utils/number';
5
5
  import { BlockIdentifier } from './utils';
6
6
  export declare abstract class ProviderInterface {
@@ -38,6 +38,21 @@ export declare abstract class ProviderInterface {
38
38
  * @returns Contract class of compiled contract
39
39
  */
40
40
  abstract getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
41
+ /**
42
+ * Returns the class hash deployed under the given address.
43
+ *
44
+ * @param contractAddress - contract address
45
+ * @param blockIdentifier - block identifier
46
+ * @returns Class hash
47
+ */
48
+ abstract getClassHashAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<string>;
49
+ /**
50
+ * Returns the contract class deployed under the given class hash.
51
+ *
52
+ * @param classHash - class hash
53
+ * @returns Contract class of compiled contract
54
+ */
55
+ abstract getClass(classHash: string): Promise<ContractClass>;
41
56
  /**
42
57
  * Gets the nonce of a contract with respect to a specific block
43
58
  *
@@ -53,7 +68,7 @@ export declare abstract class ProviderInterface {
53
68
  * @param blockIdentifier - block identifier
54
69
  * @returns the value of the storage variable
55
70
  */
56
- abstract getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier: BlockIdentifier): Promise<BigNumberish>;
71
+ abstract getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
57
72
  /**
58
73
  * Gets the transaction information from a tx id.
59
74
  *
@@ -77,7 +92,7 @@ export declare abstract class ProviderInterface {
77
92
  * - address salt
78
93
  * @returns a confirmation of sending a transaction on the starknet contract
79
94
  */
80
- abstract deployContract(payload: DeployContractPayload): Promise<DeployContractResponse>;
95
+ abstract deployContract(payload: DeployContractPayload, details?: InvocationsDetails): Promise<DeployContractResponse>;
81
96
  /**
82
97
  * Deploys a given compiled Account contract (json) to starknet
83
98
  *
package/provider/rpc.d.ts CHANGED
@@ -1,17 +1,19 @@
1
1
  import { StarknetChainId } from '../constants';
2
- import { Call, CallContractResponse, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
2
+ import { Call, CallContractResponse, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
3
3
  import { RPC } from '../types/api';
4
- import { DeclareContractTransaction, DeployAccountContractPayload, DeployAccountContractTransaction } from '../types/lib';
4
+ import { DeclareContractTransaction, DeployAccountContractTransaction, InvocationsDetails } from '../types/lib';
5
5
  import { BigNumberish } from '../utils/number';
6
6
  import { ProviderInterface } from './interface';
7
7
  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);
@@ -23,26 +25,29 @@ export declare class RpcProvider implements ProviderInterface {
23
25
  getBlockHashAndNumber(): Promise<RPC.BlockHashAndNumber>;
24
26
  getBlockWithTxHashes(blockIdentifier?: BlockIdentifier): Promise<RPC.GetBlockWithTxHashesResponse>;
25
27
  getBlockWithTxs(blockIdentifier?: BlockIdentifier): Promise<RPC.GetBlockWithTxs>;
26
- getClassHashAt(blockIdentifier: BlockIdentifier, contractAddress: RPC.ContractAddress): Promise<RPC.Felt>;
28
+ getClassHashAt(contractAddress: RPC.ContractAddress, blockIdentifier?: BlockIdentifier): Promise<RPC.Felt>;
27
29
  getNonce(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<RPC.Nonce>;
28
30
  getPendingTransactions(): Promise<RPC.PendingTransactions>;
29
31
  getProtocolVersion(): Promise<Error>;
30
- getStateUpdate(blockIdentifier: BlockIdentifier): Promise<RPC.StateUpdate>;
32
+ getStateUpdate(blockIdentifier?: BlockIdentifier): Promise<RPC.StateUpdate>;
31
33
  getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
32
34
  getTransaction(txHash: string): Promise<GetTransactionResponse>;
33
35
  getTransactionByHash(txHash: string): Promise<RPC.GetTransactionByHashResponse>;
34
36
  getTransactionByBlockIdAndIndex(blockIdentifier: BlockIdentifier, index: number): Promise<RPC.GetTransactionByBlockIdAndIndex>;
35
- getTransactionReceipt(txHash: string): Promise<GetTransactionReceiptResponse>;
36
- getClass(classHash: RPC.Felt): Promise<RPC.ContractClass>;
37
- getClassAt(contractAddress: string, blockIdentifier: BlockIdentifier): Promise<RPC.ContractClass>;
37
+ getTransactionReceipt(txHash: string): Promise<RPC.TransactionReceipt>;
38
+ getClass(classHash: RPC.Felt, 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>;
41
43
  getDeclareEstimateFee({ senderAddress, contractDefinition, signature }: DeclareContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
42
44
  getDeployAccountEstimateFee({ classHash, constructorCalldata, addressSalt, signature }: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
43
45
  declareContract({ contractDefinition, signature, senderAddress }: DeclareContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeclareContractResponse>;
44
- deployContract({ contract, constructorCalldata, addressSalt, }: DeployContractPayload): Promise<DeployContractResponse>;
45
- deployAccountContract({ classHash, constructorCalldata, addressSalt, }: DeployAccountContractPayload): Promise<DeployContractResponse>;
46
+ /**
47
+ * @deprecated This method wont be supported soon, use Account.deploy instead
48
+ */
49
+ deployContract({ contract, constructorCalldata, addressSalt }: DeployContractPayload, details?: InvocationsDetails): Promise<DeployContractResponse>;
50
+ deployAccountContract({ classHash, constructorCalldata, addressSalt, signature }: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeployContractResponse>;
46
51
  invokeFunction(functionInvocation: Invocation, details: InvocationsDetailsWithNonce): Promise<InvokeFunctionResponse>;
47
52
  callContract(call: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
48
53
  traceTransaction(transactionHash: RPC.TransactionHash): Promise<RPC.Trace>;
@@ -55,7 +60,7 @@ export declare class RpcProvider implements ProviderInterface {
55
60
  * @param blockIdentifier
56
61
  * @returns Number of transactions
57
62
  */
58
- getTransactionCount(blockIdentifier: BlockIdentifier): Promise<RPC.GetTransactionCountResponse>;
63
+ getTransactionCount(blockIdentifier?: BlockIdentifier): Promise<RPC.GetTransactionCountResponse>;
59
64
  /**
60
65
  * Gets the latest block number
61
66
  *
package/provider/rpc.js CHANGED
@@ -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,18 +63,19 @@ 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
  });
61
73
  }
62
74
  RpcProvider.prototype.fetch = function (method, params) {
63
- return (0, fetchPonyfill_1.default)(this.nodeUrl, {
75
+ return (0, fetchPonyfill_1.default)("".concat(this.nodeUrl, "/rpc/v0.2"), {
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) {
@@ -141,7 +153,8 @@ var RpcProvider = /** @class */ (function () {
141
153
  });
142
154
  });
143
155
  };
144
- RpcProvider.prototype.getClassHashAt = function (blockIdentifier, contractAddress) {
156
+ RpcProvider.prototype.getClassHashAt = function (contractAddress, blockIdentifier) {
157
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
145
158
  return __awaiter(this, void 0, void 0, function () {
146
159
  var block_id;
147
160
  return __generator(this, function (_a) {
@@ -181,6 +194,7 @@ var RpcProvider = /** @class */ (function () {
181
194
  });
182
195
  };
183
196
  RpcProvider.prototype.getStateUpdate = function (blockIdentifier) {
197
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
184
198
  return __awaiter(this, void 0, void 0, function () {
185
199
  var block_id;
186
200
  return __generator(this, function (_a) {
@@ -235,14 +249,18 @@ var RpcProvider = /** @class */ (function () {
235
249
  });
236
250
  });
237
251
  };
238
- RpcProvider.prototype.getClass = function (classHash) {
252
+ RpcProvider.prototype.getClass = function (classHash, blockIdentifier) {
253
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
239
254
  return __awaiter(this, void 0, void 0, function () {
255
+ var block_id;
240
256
  return __generator(this, function (_a) {
241
- return [2 /*return*/, this.fetchEndpoint('starknet_getClass', { class_hash: classHash })];
257
+ block_id = new utils_1.Block(blockIdentifier).identifier;
258
+ return [2 /*return*/, this.fetchEndpoint('starknet_getClass', { class_hash: classHash, block_id: block_id })];
242
259
  });
243
260
  });
244
261
  };
245
262
  RpcProvider.prototype.getClassAt = function (contractAddress, blockIdentifier) {
263
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
246
264
  return __awaiter(this, void 0, void 0, function () {
247
265
  var block_id;
248
266
  return __generator(this, function (_a) {
@@ -257,7 +275,7 @@ var RpcProvider = /** @class */ (function () {
257
275
  RpcProvider.prototype.getCode = function (_contractAddress, _blockIdentifier) {
258
276
  return __awaiter(this, void 0, void 0, function () {
259
277
  return __generator(this, function (_a) {
260
- throw new Error('RPC 0.1.0 does not implement getCode function');
278
+ throw new Error('RPC does not implement getCode function');
261
279
  });
262
280
  });
263
281
  };
@@ -346,46 +364,61 @@ var RpcProvider = /** @class */ (function () {
346
364
  return __awaiter(this, void 0, void 0, function () {
347
365
  return __generator(this, function (_b) {
348
366
  return [2 /*return*/, this.fetchEndpoint('starknet_addDeclareTransaction', {
349
- contract_class: {
350
- program: contractDefinition.program,
351
- entry_points_by_type: contractDefinition.entry_points_by_type,
352
- abi: contractDefinition.abi, // rpc 2.0
367
+ declare_transaction: {
368
+ contract_class: {
369
+ program: contractDefinition.program,
370
+ entry_points_by_type: contractDefinition.entry_points_by_type,
371
+ abi: contractDefinition.abi, // rpc 2.0
372
+ },
373
+ type: 'DECLARE',
374
+ version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
375
+ max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
376
+ signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(signature || []),
377
+ sender_address: senderAddress,
378
+ nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
353
379
  },
354
- version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
355
- max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
356
- signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(signature || []),
357
- sender_address: senderAddress,
358
- nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
359
380
  })];
360
381
  });
361
382
  });
362
383
  };
363
- RpcProvider.prototype.deployContract = function (_a) {
384
+ /**
385
+ * @deprecated This method wont be supported soon, use Account.deploy instead
386
+ */
387
+ RpcProvider.prototype.deployContract = function (_a, details) {
364
388
  var contract = _a.contract, constructorCalldata = _a.constructorCalldata, addressSalt = _a.addressSalt;
365
389
  return __awaiter(this, void 0, void 0, function () {
366
390
  var contractDefinition;
367
391
  return __generator(this, function (_b) {
368
392
  contractDefinition = (0, provider_1.parseContract)(contract);
369
393
  return [2 /*return*/, this.fetchEndpoint('starknet_addDeployTransaction', {
370
- contract_address_salt: addressSalt !== null && addressSalt !== void 0 ? addressSalt : (0, stark_1.randomAddress)(),
371
- constructor_calldata: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(constructorCalldata !== null && constructorCalldata !== void 0 ? constructorCalldata : []),
372
- contract_definition: {
373
- program: contractDefinition.program,
374
- entry_points_by_type: contractDefinition.entry_points_by_type,
375
- abi: contractDefinition.abi, // rpc 2.0
394
+ deploy_transaction: {
395
+ contract_address_salt: addressSalt !== null && addressSalt !== void 0 ? addressSalt : (0, stark_1.randomAddress)(),
396
+ constructor_calldata: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(constructorCalldata !== null && constructorCalldata !== void 0 ? constructorCalldata : []),
397
+ contract_class: {
398
+ program: contractDefinition.program,
399
+ entry_points_by_type: contractDefinition.entry_points_by_type,
400
+ abi: contractDefinition.abi,
401
+ },
402
+ type: 'DEPLOY',
403
+ version: (0, number_1.toHex)((0, number_1.toBN)((details === null || details === void 0 ? void 0 : details.version) || 0)),
376
404
  },
377
405
  })];
378
406
  });
379
407
  });
380
408
  };
381
- RpcProvider.prototype.deployAccountContract = function (_a) {
382
- var classHash = _a.classHash, constructorCalldata = _a.constructorCalldata, addressSalt = _a.addressSalt;
409
+ RpcProvider.prototype.deployAccountContract = function (_a, details) {
410
+ var classHash = _a.classHash, constructorCalldata = _a.constructorCalldata, addressSalt = _a.addressSalt, signature = _a.signature;
383
411
  return __awaiter(this, void 0, void 0, function () {
384
412
  return __generator(this, function (_b) {
385
413
  return [2 /*return*/, this.fetchEndpoint('starknet_addDeployAccountTransaction', {
386
414
  constructor_calldata: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(constructorCalldata || []),
387
415
  class_hash: (0, number_1.toHex)((0, number_1.toBN)(classHash)),
388
416
  contract_address_salt: (0, number_1.toHex)((0, number_1.toBN)(addressSalt || 0)),
417
+ type: 'DEPLOY',
418
+ max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
419
+ version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
420
+ signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(signature || []),
421
+ nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
389
422
  })];
390
423
  });
391
424
  });
@@ -394,13 +427,15 @@ var RpcProvider = /** @class */ (function () {
394
427
  return __awaiter(this, void 0, void 0, function () {
395
428
  return __generator(this, function (_a) {
396
429
  return [2 /*return*/, this.fetchEndpoint('starknet_addInvokeTransaction', {
397
- function_invocation: {
398
- contract_address: functionInvocation.contractAddress,
430
+ invoke_transaction: {
431
+ sender_address: functionInvocation.contractAddress,
399
432
  calldata: (0, provider_1.parseCalldata)(functionInvocation.calldata),
433
+ type: 'INVOKE',
434
+ max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
435
+ version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
436
+ signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(functionInvocation.signature || []),
437
+ nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
400
438
  },
401
- signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(functionInvocation.signature || []),
402
- max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
403
- version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
404
439
  })];
405
440
  });
406
441
  });
@@ -446,7 +481,7 @@ var RpcProvider = /** @class */ (function () {
446
481
  RpcProvider.prototype.waitForTransaction = function (txHash, retryInterval) {
447
482
  if (retryInterval === void 0) { retryInterval = 8000; }
448
483
  return __awaiter(this, void 0, void 0, function () {
449
- var retries, onchain, successStates, errorStates, res, message, error, error_2;
484
+ var retries, onchain, successStates, errorStates, res, error, message, error, error_2;
450
485
  return __generator(this, function (_a) {
451
486
  switch (_a.label) {
452
487
  case 0:
@@ -468,6 +503,10 @@ var RpcProvider = /** @class */ (function () {
468
503
  return [4 /*yield*/, this.getTransactionReceipt(txHash)];
469
504
  case 4:
470
505
  res = _a.sent();
506
+ if (!('status' in res)) {
507
+ error = new Error('pending transaction');
508
+ throw error;
509
+ }
471
510
  if (res.status && successStates.includes(res.status)) {
472
511
  onchain = true;
473
512
  }
@@ -506,6 +545,7 @@ var RpcProvider = /** @class */ (function () {
506
545
  * @returns Number of transactions
507
546
  */
508
547
  RpcProvider.prototype.getTransactionCount = function (blockIdentifier) {
548
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
509
549
  return __awaiter(this, void 0, void 0, function () {
510
550
  var block_id;
511
551
  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;
@@ -36,6 +38,8 @@ export declare class SequencerProvider implements ProviderInterface {
36
38
  getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
37
39
  getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse>;
38
40
  getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
41
+ getClassHashAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<string>;
42
+ getClass(classHash: string): Promise<ContractClass>;
39
43
  invokeFunction(functionInvocation: Invocation, details: InvocationsDetailsWithNonce): Promise<InvokeFunctionResponse>;
40
44
  deployContract({ contract, constructorCalldata, addressSalt, }: DeployContractPayload): Promise<DeployContractResponse>;
41
45
  deployAccountContract({ classHash, constructorCalldata, addressSalt, signature }: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeployContractResponse>;
@@ -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) {
@@ -313,6 +326,21 @@ var SequencerProvider = /** @class */ (function () {
313
326
  });
314
327
  });
315
328
  };
329
+ SequencerProvider.prototype.getClassHashAt = function (contractAddress, blockIdentifier) {
330
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
331
+ return __awaiter(this, void 0, void 0, function () {
332
+ return __generator(this, function (_a) {
333
+ return [2 /*return*/, this.fetchEndpoint('get_class_hash_at', { blockIdentifier: blockIdentifier, contractAddress: contractAddress })];
334
+ });
335
+ });
336
+ };
337
+ SequencerProvider.prototype.getClass = function (classHash) {
338
+ return __awaiter(this, void 0, void 0, function () {
339
+ return __generator(this, function (_a) {
340
+ return [2 /*return*/, this.fetchEndpoint('get_class_by_hash', { classHash: classHash }).then(provider_1.parseContract)];
341
+ });
342
+ });
343
+ };
316
344
  SequencerProvider.prototype.invokeFunction = function (functionInvocation, details) {
317
345
  var _a, _b;
318
346
  return __awaiter(this, void 0, void 0, function () {
@@ -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
  }
package/signer/default.js CHANGED
@@ -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