starknet 4.6.0 → 4.8.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 (94) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/CONTRIBUTING.md +2 -2
  3. package/__mocks__/l1l2_compiled.json +10107 -0
  4. package/__tests__/account.test.ts +2 -5
  5. package/__tests__/contract.test.ts +0 -1
  6. package/__tests__/defaultProvider.test.ts +5 -3
  7. package/__tests__/fixtures.ts +2 -0
  8. package/__tests__/sequencerProvider.test.ts +50 -9
  9. package/__tests__/utils/ellipticalCurve.test.ts +7 -8
  10. package/__tests__/utils/merkle.test.ts +15 -0
  11. package/account/default.d.ts +3 -2
  12. package/account/default.js +22 -29
  13. package/account/interface.d.ts +2 -1
  14. package/contract/contractFactory.d.ts +1 -2
  15. package/contract/default.d.ts +2 -2
  16. package/contract/default.js +7 -3
  17. package/dist/account/default.d.ts +3 -2
  18. package/dist/account/default.js +22 -29
  19. package/dist/account/interface.d.ts +2 -1
  20. package/dist/contract/contractFactory.d.ts +1 -2
  21. package/dist/contract/default.d.ts +2 -2
  22. package/dist/contract/default.js +7 -3
  23. package/dist/provider/default.d.ts +4 -3
  24. package/dist/provider/default.js +9 -3
  25. package/dist/provider/interface.d.ts +10 -3
  26. package/dist/provider/rpc.d.ts +12 -10
  27. package/dist/provider/rpc.js +80 -72
  28. package/dist/provider/sequencer.d.ts +6 -4
  29. package/dist/provider/sequencer.js +36 -7
  30. package/dist/signer/default.d.ts +2 -2
  31. package/dist/signer/default.js +2 -2
  32. package/dist/signer/interface.d.ts +2 -2
  33. package/dist/types/api/openrpc.d.ts +17 -27
  34. package/dist/types/api/rpc.d.ts +4 -128
  35. package/dist/types/api/sequencer.d.ts +36 -20
  36. package/dist/types/lib.d.ts +10 -4
  37. package/dist/types/provider.d.ts +7 -2
  38. package/dist/utils/hash.d.ts +8 -2
  39. package/dist/utils/hash.js +20 -5
  40. package/dist/utils/merkle.js +2 -1
  41. package/dist/utils/number.d.ts +5 -0
  42. package/dist/utils/number.js +29 -1
  43. package/dist/utils/responseParser/rpc.d.ts +2 -5
  44. package/dist/utils/responseParser/rpc.js +2 -38
  45. package/dist/utils/responseParser/sequencer.js +7 -19
  46. package/package.json +1 -1
  47. package/provider/default.d.ts +4 -3
  48. package/provider/default.js +9 -3
  49. package/provider/interface.d.ts +10 -3
  50. package/provider/rpc.d.ts +12 -10
  51. package/provider/rpc.js +80 -72
  52. package/provider/sequencer.d.ts +6 -4
  53. package/provider/sequencer.js +36 -7
  54. package/signer/default.d.ts +2 -2
  55. package/signer/default.js +2 -2
  56. package/signer/interface.d.ts +2 -2
  57. package/src/account/default.ts +21 -20
  58. package/src/account/interface.ts +2 -1
  59. package/src/contract/contractFactory.ts +1 -2
  60. package/src/contract/default.ts +16 -8
  61. package/src/provider/default.ts +12 -5
  62. package/src/provider/interface.ts +15 -4
  63. package/src/provider/rpc.ts +89 -73
  64. package/src/provider/sequencer.ts +47 -11
  65. package/src/signer/default.ts +8 -8
  66. package/src/signer/interface.ts +2 -2
  67. package/src/types/api/openrpc.ts +20 -25
  68. package/src/types/api/rpc.ts +4 -128
  69. package/src/types/api/sequencer.ts +39 -20
  70. package/src/types/lib.ts +7 -5
  71. package/src/types/provider.ts +7 -2
  72. package/src/utils/hash.ts +32 -8
  73. package/src/utils/merkle.ts +2 -1
  74. package/src/utils/number.ts +27 -0
  75. package/src/utils/responseParser/rpc.ts +7 -25
  76. package/src/utils/responseParser/sequencer.ts +12 -7
  77. package/types/api/openrpc.d.ts +17 -27
  78. package/types/api/rpc.d.ts +4 -128
  79. package/types/api/sequencer.d.ts +36 -20
  80. package/types/lib.d.ts +10 -4
  81. package/types/provider.d.ts +7 -2
  82. package/utils/hash.d.ts +8 -2
  83. package/utils/hash.js +20 -5
  84. package/utils/merkle.js +2 -1
  85. package/utils/number.d.ts +5 -0
  86. package/utils/number.js +29 -1
  87. package/utils/responseParser/rpc.d.ts +2 -5
  88. package/utils/responseParser/rpc.js +2 -38
  89. package/utils/responseParser/sequencer.js +7 -19
  90. package/www/docs/API/account.md +3 -3
  91. package/www/docs/API/contract.md +2 -2
  92. package/www/docs/API/provider.md +20 -6
  93. package/www/docs/API/utils.md +2 -2
  94. package/www/guides/account.md +1 -1
@@ -76,11 +76,8 @@ describe('deploy and test Wallet', () => {
76
76
  });
77
77
 
78
78
  test('execute with custom nonce', async () => {
79
- const { result } = await account.callContract({
80
- contractAddress: account.address,
81
- entrypoint: 'get_nonce',
82
- });
83
- const nonce = toBN(result[0]).toNumber();
79
+ const result = await account.getNonce();
80
+ const nonce = toBN(result).toNumber();
84
81
  const { transaction_hash } = await account.execute(
85
82
  {
86
83
  contractAddress: erc20Address,
@@ -43,7 +43,6 @@ describe('class Contract {}', () => {
43
43
  expect(res).toHaveProperty('contractAddress');
44
44
  expect(res).toHaveProperty('entrypoint');
45
45
  expect(res).toHaveProperty('calldata');
46
- expect(res).toHaveProperty('signature');
47
46
  });
48
47
 
49
48
  test('estimate gas fee for `mint` should fail when connected to the provider', async () => {
@@ -62,6 +62,11 @@ describe('defaultProvider', () => {
62
62
  return expect(block).toHaveProperty('block_number');
63
63
  });
64
64
 
65
+ test('getNonce()', async () => {
66
+ const nonce = await testProvider.getNonce(exampleContractAddress);
67
+ return expect(nonce).toEqual('0x0');
68
+ });
69
+
65
70
  describe('getStorageAt', () => {
66
71
  test('with "key" type of number', () => {
67
72
  return expect(testProvider.getStorageAt(exampleContractAddress, 0)).resolves.not.toThrow();
@@ -216,7 +221,6 @@ describe('defaultProvider', () => {
216
221
  expect(transaction.transaction_hash).toBeTruthy();
217
222
  expect(transaction.contract_address).toBeTruthy();
218
223
  expect(Array.isArray(transaction.calldata)).toBe(true);
219
- expect(transaction.entry_point_selector).toBeTruthy();
220
224
  expect(Array.isArray(transaction.signature)).toBe(true);
221
225
  expect(transaction.max_fee).toBeTruthy();
222
226
  });
@@ -241,9 +245,7 @@ describe('defaultProvider', () => {
241
245
 
242
246
  expect(receipt).toHaveProperty('transaction_hash');
243
247
  expect(receipt).toHaveProperty('status');
244
- expect(receipt).toHaveProperty('status_data');
245
248
  expect(receipt).toHaveProperty('messages_sent');
246
- expect(receipt).toHaveProperty('l1_origin_message');
247
249
  expect(receipt).toHaveProperty('events');
248
250
  });
249
251
  });
@@ -8,6 +8,7 @@ const readContract = (name: string): CompiledContract =>
8
8
 
9
9
  export const compiledOpenZeppelinAccount = readContract('Account');
10
10
  export const compiledErc20 = readContract('ERC20');
11
+ export const compiledL1L2 = readContract('l1l2_compiled');
11
12
  export const compiledTypeTransformation = readContract('contract');
12
13
  export const compiledMulticall = readContract('multicall');
13
14
  export const compiledTestDapp = readContract('TestDapp');
@@ -26,6 +27,7 @@ const IS_RPC_DEVNET = Boolean(
26
27
  );
27
28
  const IS_SEQUENCER = !IS_RPC;
28
29
  const IS_SEQUENCER_DEVNET = !BASE_URL.includes('starknet.io');
30
+ export const IS_SEQUENCER_GOERLI = BASE_URL === 'https://alpha4.starknet.io';
29
31
  export const IS_DEVNET = IS_SEQUENCER ? IS_SEQUENCER_DEVNET : IS_RPC_DEVNET;
30
32
 
31
33
  export const getTestProvider = () => {
@@ -1,7 +1,9 @@
1
1
  import { Contract, Provider, SequencerProvider, stark } from '../src';
2
2
  import { toBN } from '../src/utils/number';
3
3
  import {
4
+ IS_SEQUENCER_GOERLI,
4
5
  compiledErc20,
6
+ compiledL1L2,
5
7
  describeIfNotDevnet,
6
8
  describeIfSequencer,
7
9
  getTestProvider,
@@ -9,12 +11,12 @@ import {
9
11
 
10
12
  // Run only if Devnet Sequencer
11
13
  describeIfSequencer('SequencerProvider', () => {
12
- let provider: SequencerProvider;
14
+ let sequencerProvider: SequencerProvider;
13
15
  let customSequencerProvider: Provider;
14
16
  let exampleContractAddress: string;
15
17
 
16
18
  beforeAll(async () => {
17
- provider = getTestProvider() as SequencerProvider;
19
+ sequencerProvider = getTestProvider() as SequencerProvider;
18
20
  customSequencerProvider = new Provider({
19
21
  sequencer: {
20
22
  baseUrl: 'https://alpha4.starknet.io',
@@ -28,32 +30,34 @@ describeIfSequencer('SequencerProvider', () => {
28
30
  let exampleTransactionHash: string;
29
31
 
30
32
  beforeAll(async () => {
31
- const { transaction_hash, contract_address } = await provider.deployContract({
33
+ const { transaction_hash, contract_address } = await sequencerProvider.deployContract({
32
34
  contract: compiledErc20,
33
35
  });
34
- await provider.waitForTransaction(transaction_hash);
36
+ await sequencerProvider.waitForTransaction(transaction_hash);
35
37
  exampleTransactionHash = transaction_hash;
36
38
  exampleContractAddress = contract_address;
37
39
  });
38
40
 
39
41
  test('getTransactionStatus()', async () => {
40
- return expect(provider.getTransactionStatus(exampleTransactionHash)).resolves.not.toThrow();
42
+ return expect(
43
+ sequencerProvider.getTransactionStatus(exampleTransactionHash)
44
+ ).resolves.not.toThrow();
41
45
  });
42
46
 
43
47
  test('transaction trace', async () => {
44
- const transactionTrace = await provider.getTransactionTrace(exampleTransactionHash);
45
- expect(transactionTrace).toHaveProperty('function_invocation');
48
+ const transactionTrace = await sequencerProvider.getTransactionTrace(exampleTransactionHash);
49
+ // TODO test optional properties
46
50
  expect(transactionTrace).toHaveProperty('signature');
47
51
  });
48
52
 
49
53
  test('getCode() -> { bytecode }', async () => {
50
- const code = await provider.getCode(exampleContractAddress);
54
+ const code = await sequencerProvider.getCode(exampleContractAddress);
51
55
  return expect(Array.isArray(code.bytecode)).toBe(true);
52
56
  });
53
57
 
54
58
  describeIfNotDevnet('which are not available on devnet', () => {
55
59
  test('getContractAddresses()', async () => {
56
- const { GpsStatementVerifier, Starknet } = await provider.getContractAddresses();
60
+ const { GpsStatementVerifier, Starknet } = await sequencerProvider.getContractAddresses();
57
61
  expect(typeof GpsStatementVerifier).toBe('string');
58
62
  expect(typeof Starknet).toBe('string');
59
63
  });
@@ -80,4 +84,41 @@ describeIfSequencer('SequencerProvider', () => {
80
84
  expect(res).toStrictEqual(result.res);
81
85
  });
82
86
  });
87
+
88
+ describe('Test Estimate message fee', () => {
89
+ const L1_ADDRESS = '0x8359E4B0152ed5A731162D3c7B0D8D56edB165A0';
90
+ let l1l2ContractAddress: string;
91
+
92
+ beforeAll(async () => {
93
+ if (IS_SEQUENCER_GOERLI) {
94
+ l1l2ContractAddress = '0x2863141e0d9a74e9b484c1f5b1e3a2f6cbb6b84df8233c7c1cbe31334d9aed8';
95
+ } else {
96
+ const { transaction_hash, contract_address } = await sequencerProvider.deployContract({
97
+ contract: compiledL1L2,
98
+ });
99
+ await sequencerProvider.waitForTransaction(transaction_hash);
100
+ l1l2ContractAddress = contract_address;
101
+ }
102
+ });
103
+
104
+ test('estimate message fee', async () => {
105
+ const estimation = await sequencerProvider.estimateMessageFee(
106
+ {
107
+ from_address: L1_ADDRESS,
108
+ to_address: l1l2ContractAddress,
109
+ entry_point_selector: 'deposit',
110
+ payload: ['556', '123'],
111
+ },
112
+ 'latest'
113
+ );
114
+ expect(estimation).toEqual(
115
+ expect.objectContaining({
116
+ overall_fee: expect.anything(),
117
+ gas_price: expect.anything(),
118
+ gas_usage: expect.anything(),
119
+ unit: 'wei',
120
+ })
121
+ );
122
+ });
123
+ });
83
124
  });
@@ -2,9 +2,8 @@ import { StarknetChainId } from '../../src/constants';
2
2
  import { ec, getKeyPair, getStarkKey, sign, verify } from '../../src/utils/ellipticCurve';
3
3
  import { removeHexPrefix } from '../../src/utils/encode';
4
4
  import {
5
- calculcateTransactionHash,
5
+ calculateTransactionHash,
6
6
  computeHashOnElements,
7
- getSelectorFromName,
8
7
  pedersen,
9
8
  transactionVersion,
10
9
  } from '../../src/utils/hash';
@@ -57,25 +56,25 @@ test('hashMessage()', () => {
57
56
  const maxFee = '0';
58
57
  const calldata = fromCallsToExecuteCalldataWithNonce(transactions, nonce);
59
58
 
60
- const hashMsg = calculcateTransactionHash(
59
+ const hashMsg = calculateTransactionHash(
61
60
  account,
62
61
  transactionVersion,
63
- getSelectorFromName('__execute__'),
64
62
  calldata,
65
63
  maxFee,
66
- StarknetChainId.TESTNET
64
+ StarknetChainId.TESTNET,
65
+ nonce
67
66
  );
68
67
 
69
68
  expect(hashMsg).toMatchInlineSnapshot(
70
- `"0x4c337c6bf32b2cf2b8ae54064e4b982c214660e8d0423b431a3fde10b9b9c02"`
69
+ `"0x6d1706bd3d1ba7c517be2a2a335996f63d4738e2f182144d078a1dd9997062e"`
71
70
  );
72
71
  const keyPair = getKeyPair(privateKey);
73
72
  const [r, s] = sign(keyPair, removeHexPrefix(hashMsg));
74
73
  expect(r.toString()).toMatchInlineSnapshot(
75
- `"1944132633844378384908742523072599391732300777648030785844673145513474741467"`
74
+ `"1427981024487605678086498726488552139932400435436186597196374630267616399345"`
76
75
  );
77
76
  expect(s.toString()).toMatchInlineSnapshot(
78
- `"1067771353159635307522498807851959257107695451405842425488451092336556917559"`
77
+ `"1853664302719670721837677288395394946745467311923401353018029119631574115563"`
79
78
  );
80
79
  });
81
80
 
@@ -1,6 +1,21 @@
1
+ import { pedersen } from '../../src/utils/hash';
1
2
  import { MerkleTree, proofMerklePath } from '../../src/utils/merkle';
3
+ import { toBN } from '../../src/utils/number';
2
4
 
3
5
  describe('MerkleTree class', () => {
6
+ describe('calculate hashes', () => {
7
+ test('should generate hash with sorted arguments', async () => {
8
+ let leaves = ['0x12', '0xa']; // 18, 10
9
+ let merkleHash = MerkleTree.hash(leaves[0], leaves[1]);
10
+ let rawHash = pedersen([toBN(leaves[1]), toBN(leaves[0])]);
11
+ expect(merkleHash).toBe(rawHash);
12
+
13
+ leaves = ['0x5bb9440e27889a364bcb678b1f679ecd1347acdedcbf36e83494f857cc58026', '0x3'];
14
+ merkleHash = MerkleTree.hash(leaves[0], leaves[1]);
15
+ rawHash = pedersen([toBN(leaves[1]), toBN(leaves[0])]);
16
+ expect(merkleHash).toBe(rawHash);
17
+ });
18
+ });
4
19
  describe('generate roots', () => {
5
20
  test('should generate valid root for 1 elements', async () => {
6
21
  const leaves = ['0x1'];
@@ -1,5 +1,6 @@
1
1
  import { ProviderInterface, ProviderOptions } from '../provider';
2
2
  import { Provider } from '../provider/default';
3
+ import { BlockIdentifier } from '../provider/utils';
3
4
  import { SignerInterface } from '../signer';
4
5
  import { Abi, Call, InvocationsDetails, InvokeFunctionResponse, KeyPair, Signature } from '../types';
5
6
  import { EstimateFee, EstimateFeeDetails } from '../types/account';
@@ -7,10 +8,10 @@ import { BigNumberish } from '../utils/number';
7
8
  import { TypedData } from '../utils/typedData';
8
9
  import { AccountInterface } from './interface';
9
10
  export declare class Account extends Provider implements AccountInterface {
10
- address: string;
11
11
  signer: SignerInterface;
12
+ address: string;
12
13
  constructor(providerOrOptions: ProviderOptions | ProviderInterface, address: string, keyPairOrSigner: KeyPair | SignerInterface);
13
- getNonce(): Promise<string>;
14
+ getNonce(blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
14
15
  estimateFee(calls: Call | Call[], { nonce: providedNonce, blockIdentifier }?: EstimateFeeDetails): Promise<EstimateFee>;
15
16
  /**
16
17
  * Invoke execute function in account contract
@@ -75,62 +75,54 @@ var Account = /** @class */ (function (_super) {
75
75
  __extends(Account, _super);
76
76
  function Account(providerOrOptions, address, keyPairOrSigner) {
77
77
  var _this = _super.call(this, providerOrOptions) || this;
78
- _this.address = address;
78
+ _this.address = address.toLowerCase();
79
79
  _this.signer =
80
80
  'getPubKey' in keyPairOrSigner ? keyPairOrSigner : new signer_1.Signer(keyPairOrSigner);
81
81
  return _this;
82
82
  }
83
- Account.prototype.getNonce = function () {
83
+ Account.prototype.getNonce = function (blockIdentifier) {
84
84
  return __awaiter(this, void 0, void 0, function () {
85
- var result;
86
85
  return __generator(this, function (_a) {
87
- switch (_a.label) {
88
- case 0: return [4 /*yield*/, this.callContract({
89
- contractAddress: this.address,
90
- entrypoint: 'get_nonce',
91
- })];
92
- case 1:
93
- result = (_a.sent()).result;
94
- return [2 /*return*/, (0, number_1.toHex)((0, number_1.toBN)(result[0]))];
95
- }
86
+ return [2 /*return*/, _super.prototype.getNonce.call(this, this.address, blockIdentifier)];
96
87
  });
97
88
  });
98
89
  };
99
90
  Account.prototype.estimateFee = function (calls, _a) {
100
91
  var _b = _a === void 0 ? {} : _a, providedNonce = _b.nonce, blockIdentifier = _b.blockIdentifier;
101
92
  return __awaiter(this, void 0, void 0, function () {
102
- var transactions, nonce, _c, version, chainId, signerDetails, signature, calldata, response, suggestedMaxFee;
103
- return __generator(this, function (_d) {
104
- switch (_d.label) {
93
+ var transactions, nonce, _c, _d, version, chainId, signerDetails, signature, calldata, response, suggestedMaxFee;
94
+ return __generator(this, function (_e) {
95
+ switch (_e.label) {
105
96
  case 0:
106
97
  transactions = Array.isArray(calls) ? calls : [calls];
98
+ _c = number_1.toBN;
107
99
  if (!(providedNonce !== null && providedNonce !== void 0)) return [3 /*break*/, 1];
108
- _c = providedNonce;
100
+ _d = providedNonce;
109
101
  return [3 /*break*/, 3];
110
102
  case 1: return [4 /*yield*/, this.getNonce()];
111
103
  case 2:
112
- _c = (_d.sent());
113
- _d.label = 3;
104
+ _d = (_e.sent());
105
+ _e.label = 3;
114
106
  case 3:
115
- nonce = _c;
116
- version = (0, number_1.toBN)(hash_1.feeTransactionVersion);
107
+ nonce = _c.apply(void 0, [_d]);
108
+ version = (0, number_1.toBN)(hash_1.transactionVersion);
117
109
  return [4 /*yield*/, this.getChainId()];
118
110
  case 4:
119
- chainId = _d.sent();
111
+ chainId = _e.sent();
120
112
  signerDetails = {
121
113
  walletAddress: this.address,
122
- nonce: (0, number_1.toBN)(nonce),
114
+ nonce: nonce,
123
115
  maxFee: constants_1.ZERO,
124
116
  version: version,
125
117
  chainId: chainId,
126
118
  };
127
119
  return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails)];
128
120
  case 5:
129
- signature = _d.sent();
130
- calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
131
- return [4 /*yield*/, _super.prototype.getEstimateFee.call(this, { contractAddress: this.address, entrypoint: '__execute__', calldata: calldata, signature: signature }, blockIdentifier, { version: version })];
121
+ signature = _e.sent();
122
+ calldata = (0, transaction_1.fromCallsToExecuteCalldata)(transactions);
123
+ return [4 /*yield*/, _super.prototype.getEstimateFee.call(this, { contractAddress: this.address, calldata: calldata, signature: signature }, { version: version, nonce: nonce }, blockIdentifier)];
132
124
  case 6:
133
- response = _d.sent();
125
+ response = _e.sent();
134
126
  suggestedMaxFee = (0, stark_1.estimatedFeeToMaxFee)(response.overall_fee);
135
127
  return [2 /*return*/, __assign(__assign({}, response), { suggestedMaxFee: suggestedMaxFee })];
136
128
  }
@@ -191,8 +183,9 @@ var Account = /** @class */ (function (_super) {
191
183
  return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails, abis)];
192
184
  case 8:
193
185
  signature = _d.sent();
194
- calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
195
- return [2 /*return*/, this.invokeFunction({ contractAddress: this.address, entrypoint: '__execute__', calldata: calldata, signature: signature }, {
186
+ calldata = (0, transaction_1.fromCallsToExecuteCalldata)(transactions);
187
+ return [2 /*return*/, this.invokeFunction({ contractAddress: this.address, calldata: calldata, signature: signature }, {
188
+ nonce: nonce,
196
189
  maxFee: maxFee,
197
190
  version: version,
198
191
  })];
@@ -246,7 +239,7 @@ var Account = /** @class */ (function (_super) {
246
239
  _b.trys.push([0, 2, , 3]);
247
240
  return [4 /*yield*/, this.callContract({
248
241
  contractAddress: this.address,
249
- entrypoint: 'is_valid_signature',
242
+ entrypoint: 'isValidSignature',
250
243
  calldata: (0, stark_1.compileCalldata)({
251
244
  hash: (0, number_1.toBN)(hash).toString(),
252
245
  signature: signature.map(function (x) { return (0, number_1.toBN)(x).toString(); }),
@@ -1,4 +1,5 @@
1
1
  import { ProviderInterface } from '../provider';
2
+ import { BlockIdentifier } from '../provider/utils';
2
3
  import { SignerInterface } from '../signer';
3
4
  import { Abi, Call, EstimateFeeDetails, EstimateFeeResponse, InvocationsDetails, InvokeFunctionResponse, Signature } from '../types';
4
5
  import { BigNumberish } from '../utils/number';
@@ -68,5 +69,5 @@ export declare abstract class AccountInterface extends ProviderInterface {
68
69
  * @throws {Error} if the signature is not a valid signature
69
70
  */
70
71
  abstract verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
71
- abstract getNonce(): Promise<string>;
72
+ abstract getNonce(blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
72
73
  }
@@ -1,7 +1,6 @@
1
1
  import { AccountInterface } from '../account';
2
2
  import { ProviderInterface } from '../provider';
3
3
  import { Abi, CompiledContract, RawCalldata } from '../types';
4
- import { BigNumberish } from '../utils/number';
5
4
  import { Contract } from './default';
6
5
  export declare class ContractFactory {
7
6
  abi: Abi;
@@ -15,7 +14,7 @@ export declare class ContractFactory {
15
14
  * @param addressSalt (optional) - Address Salt for deployment
16
15
  * @returns deployed Contract
17
16
  */
18
- deploy(constructorCalldata?: RawCalldata, addressSalt?: BigNumberish): Promise<Contract>;
17
+ deploy(constructorCalldata?: RawCalldata, addressSalt?: string | undefined): Promise<Contract>;
19
18
  /**
20
19
  * Attaches to new Provider or Account
21
20
  *
@@ -1,7 +1,7 @@
1
1
  import { AccountInterface } from '../account';
2
2
  import { ProviderInterface } from '../provider';
3
3
  import { BlockIdentifier } from '../provider/utils';
4
- import { Abi, AbiEntry, Args, AsyncContractFunction, Calldata, ContractFunction, Invocation, InvokeFunctionResponse, Overrides, ParsedStruct, Result, StructAbi } from '../types';
4
+ import { Abi, AbiEntry, Args, AsyncContractFunction, Call, Calldata, ContractFunction, InvokeFunctionResponse, Overrides, ParsedStruct, Result, StructAbi } from '../types';
5
5
  import { BigNumberish } from '../utils/number';
6
6
  import { ContractInterface } from './interface';
7
7
  export declare class Contract implements ContractInterface {
@@ -120,5 +120,5 @@ export declare class Contract implements ContractInterface {
120
120
  blockIdentifier?: BlockIdentifier;
121
121
  }): Promise<Result>;
122
122
  estimate(method: string, args?: Array<any>): Promise<import("../types").EstimateFeeResponse>;
123
- populate(method: string, args?: Array<any>): Invocation;
123
+ populate(method: string, args?: Array<any>): Call;
124
124
  }
@@ -181,7 +181,7 @@ var Contract = /** @class */ (function () {
181
181
  function Contract(abi, address, providerOrAccount) {
182
182
  if (providerOrAccount === void 0) { providerOrAccount = provider_1.defaultProvider; }
183
183
  var _this = this;
184
- this.address = address;
184
+ this.address = address.toLowerCase();
185
185
  this.providerOrAccount = providerOrAccount;
186
186
  this.abi = abi;
187
187
  this.structs = abi
@@ -592,9 +592,14 @@ var Contract = /** @class */ (function () {
592
592
  nonce: options.nonce,
593
593
  });
594
594
  }
595
+ if (!options.nonce) {
596
+ throw new Error("Nonce is required when invoking a function without an account");
597
+ }
595
598
  // eslint-disable-next-line no-console
596
599
  console.warn("Invoking ".concat(method, " without an account. This will not work on a public node."));
597
- return this.providerOrAccount.invokeFunction(__assign(__assign({}, invocation), { signature: options.signature || [] }));
600
+ return this.providerOrAccount.invokeFunction(__assign(__assign({}, invocation), { signature: options.signature || [] }), {
601
+ nonce: options.nonce,
602
+ });
598
603
  };
599
604
  Contract.prototype.call = function (method, args, _a) {
600
605
  if (args === void 0) { args = []; }
@@ -644,7 +649,6 @@ var Contract = /** @class */ (function () {
644
649
  contractAddress: this.address,
645
650
  entrypoint: method,
646
651
  calldata: this.compileCalldata(args, inputs),
647
- signature: [],
648
652
  };
649
653
  };
650
654
  return Contract;
@@ -1,5 +1,6 @@
1
1
  import { ProviderInterface, ProviderOptions } from '../provider';
2
2
  import { Provider } from '../provider/default';
3
+ import { BlockIdentifier } from '../provider/utils';
3
4
  import { SignerInterface } from '../signer';
4
5
  import { Abi, Call, InvocationsDetails, InvokeFunctionResponse, KeyPair, Signature } from '../types';
5
6
  import { EstimateFee, EstimateFeeDetails } from '../types/account';
@@ -7,10 +8,10 @@ import { BigNumberish } from '../utils/number';
7
8
  import { TypedData } from '../utils/typedData';
8
9
  import { AccountInterface } from './interface';
9
10
  export declare class Account extends Provider implements AccountInterface {
10
- address: string;
11
11
  signer: SignerInterface;
12
+ address: string;
12
13
  constructor(providerOrOptions: ProviderOptions | ProviderInterface, address: string, keyPairOrSigner: KeyPair | SignerInterface);
13
- getNonce(): Promise<string>;
14
+ getNonce(blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
14
15
  estimateFee(calls: Call | Call[], { nonce: providedNonce, blockIdentifier }?: EstimateFeeDetails): Promise<EstimateFee>;
15
16
  /**
16
17
  * Invoke execute function in account contract
@@ -75,62 +75,54 @@ var Account = /** @class */ (function (_super) {
75
75
  __extends(Account, _super);
76
76
  function Account(providerOrOptions, address, keyPairOrSigner) {
77
77
  var _this = _super.call(this, providerOrOptions) || this;
78
- _this.address = address;
78
+ _this.address = address.toLowerCase();
79
79
  _this.signer =
80
80
  'getPubKey' in keyPairOrSigner ? keyPairOrSigner : new signer_1.Signer(keyPairOrSigner);
81
81
  return _this;
82
82
  }
83
- Account.prototype.getNonce = function () {
83
+ Account.prototype.getNonce = function (blockIdentifier) {
84
84
  return __awaiter(this, void 0, void 0, function () {
85
- var result;
86
85
  return __generator(this, function (_a) {
87
- switch (_a.label) {
88
- case 0: return [4 /*yield*/, this.callContract({
89
- contractAddress: this.address,
90
- entrypoint: 'get_nonce',
91
- })];
92
- case 1:
93
- result = (_a.sent()).result;
94
- return [2 /*return*/, (0, number_1.toHex)((0, number_1.toBN)(result[0]))];
95
- }
86
+ return [2 /*return*/, _super.prototype.getNonce.call(this, this.address, blockIdentifier)];
96
87
  });
97
88
  });
98
89
  };
99
90
  Account.prototype.estimateFee = function (calls, _a) {
100
91
  var _b = _a === void 0 ? {} : _a, providedNonce = _b.nonce, blockIdentifier = _b.blockIdentifier;
101
92
  return __awaiter(this, void 0, void 0, function () {
102
- var transactions, nonce, _c, version, chainId, signerDetails, signature, calldata, response, suggestedMaxFee;
103
- return __generator(this, function (_d) {
104
- switch (_d.label) {
93
+ var transactions, nonce, _c, _d, version, chainId, signerDetails, signature, calldata, response, suggestedMaxFee;
94
+ return __generator(this, function (_e) {
95
+ switch (_e.label) {
105
96
  case 0:
106
97
  transactions = Array.isArray(calls) ? calls : [calls];
98
+ _c = number_1.toBN;
107
99
  if (!(providedNonce !== null && providedNonce !== void 0)) return [3 /*break*/, 1];
108
- _c = providedNonce;
100
+ _d = providedNonce;
109
101
  return [3 /*break*/, 3];
110
102
  case 1: return [4 /*yield*/, this.getNonce()];
111
103
  case 2:
112
- _c = (_d.sent());
113
- _d.label = 3;
104
+ _d = (_e.sent());
105
+ _e.label = 3;
114
106
  case 3:
115
- nonce = _c;
116
- version = (0, number_1.toBN)(hash_1.feeTransactionVersion);
107
+ nonce = _c.apply(void 0, [_d]);
108
+ version = (0, number_1.toBN)(hash_1.transactionVersion);
117
109
  return [4 /*yield*/, this.getChainId()];
118
110
  case 4:
119
- chainId = _d.sent();
111
+ chainId = _e.sent();
120
112
  signerDetails = {
121
113
  walletAddress: this.address,
122
- nonce: (0, number_1.toBN)(nonce),
114
+ nonce: nonce,
123
115
  maxFee: constants_1.ZERO,
124
116
  version: version,
125
117
  chainId: chainId,
126
118
  };
127
119
  return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails)];
128
120
  case 5:
129
- signature = _d.sent();
130
- calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
131
- return [4 /*yield*/, _super.prototype.getEstimateFee.call(this, { contractAddress: this.address, entrypoint: '__execute__', calldata: calldata, signature: signature }, blockIdentifier, { version: version })];
121
+ signature = _e.sent();
122
+ calldata = (0, transaction_1.fromCallsToExecuteCalldata)(transactions);
123
+ return [4 /*yield*/, _super.prototype.getEstimateFee.call(this, { contractAddress: this.address, calldata: calldata, signature: signature }, { version: version, nonce: nonce }, blockIdentifier)];
132
124
  case 6:
133
- response = _d.sent();
125
+ response = _e.sent();
134
126
  suggestedMaxFee = (0, stark_1.estimatedFeeToMaxFee)(response.overall_fee);
135
127
  return [2 /*return*/, __assign(__assign({}, response), { suggestedMaxFee: suggestedMaxFee })];
136
128
  }
@@ -191,8 +183,9 @@ var Account = /** @class */ (function (_super) {
191
183
  return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails, abis)];
192
184
  case 8:
193
185
  signature = _d.sent();
194
- calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
195
- return [2 /*return*/, this.invokeFunction({ contractAddress: this.address, entrypoint: '__execute__', calldata: calldata, signature: signature }, {
186
+ calldata = (0, transaction_1.fromCallsToExecuteCalldata)(transactions);
187
+ return [2 /*return*/, this.invokeFunction({ contractAddress: this.address, calldata: calldata, signature: signature }, {
188
+ nonce: nonce,
196
189
  maxFee: maxFee,
197
190
  version: version,
198
191
  })];
@@ -246,7 +239,7 @@ var Account = /** @class */ (function (_super) {
246
239
  _b.trys.push([0, 2, , 3]);
247
240
  return [4 /*yield*/, this.callContract({
248
241
  contractAddress: this.address,
249
- entrypoint: 'is_valid_signature',
242
+ entrypoint: 'isValidSignature',
250
243
  calldata: (0, stark_1.compileCalldata)({
251
244
  hash: (0, number_1.toBN)(hash).toString(),
252
245
  signature: signature.map(function (x) { return (0, number_1.toBN)(x).toString(); }),
@@ -1,4 +1,5 @@
1
1
  import { ProviderInterface } from '../provider';
2
+ import { BlockIdentifier } from '../provider/utils';
2
3
  import { SignerInterface } from '../signer';
3
4
  import { Abi, Call, EstimateFeeDetails, EstimateFeeResponse, InvocationsDetails, InvokeFunctionResponse, Signature } from '../types';
4
5
  import { BigNumberish } from '../utils/number';
@@ -68,5 +69,5 @@ export declare abstract class AccountInterface extends ProviderInterface {
68
69
  * @throws {Error} if the signature is not a valid signature
69
70
  */
70
71
  abstract verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
71
- abstract getNonce(): Promise<string>;
72
+ abstract getNonce(blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
72
73
  }
@@ -1,7 +1,6 @@
1
1
  import { AccountInterface } from '../account';
2
2
  import { ProviderInterface } from '../provider';
3
3
  import { Abi, CompiledContract, RawCalldata } from '../types';
4
- import { BigNumberish } from '../utils/number';
5
4
  import { Contract } from './default';
6
5
  export declare class ContractFactory {
7
6
  abi: Abi;
@@ -15,7 +14,7 @@ export declare class ContractFactory {
15
14
  * @param addressSalt (optional) - Address Salt for deployment
16
15
  * @returns deployed Contract
17
16
  */
18
- deploy(constructorCalldata?: RawCalldata, addressSalt?: BigNumberish): Promise<Contract>;
17
+ deploy(constructorCalldata?: RawCalldata, addressSalt?: string | undefined): Promise<Contract>;
19
18
  /**
20
19
  * Attaches to new Provider or Account
21
20
  *
@@ -1,7 +1,7 @@
1
1
  import { AccountInterface } from '../account';
2
2
  import { ProviderInterface } from '../provider';
3
3
  import { BlockIdentifier } from '../provider/utils';
4
- import { Abi, AbiEntry, Args, AsyncContractFunction, Calldata, ContractFunction, Invocation, InvokeFunctionResponse, Overrides, ParsedStruct, Result, StructAbi } from '../types';
4
+ import { Abi, AbiEntry, Args, AsyncContractFunction, Call, Calldata, ContractFunction, InvokeFunctionResponse, Overrides, ParsedStruct, Result, StructAbi } from '../types';
5
5
  import { BigNumberish } from '../utils/number';
6
6
  import { ContractInterface } from './interface';
7
7
  export declare class Contract implements ContractInterface {
@@ -120,5 +120,5 @@ export declare class Contract implements ContractInterface {
120
120
  blockIdentifier?: BlockIdentifier;
121
121
  }): Promise<Result>;
122
122
  estimate(method: string, args?: Array<any>): Promise<import("../types").EstimateFeeResponse>;
123
- populate(method: string, args?: Array<any>): Invocation;
123
+ populate(method: string, args?: Array<any>): Call;
124
124
  }