starknet 4.8.0 → 4.9.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 (87) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/__mocks__/ERC20.json +32561 -29055
  3. package/__tests__/account.test.ts +32 -24
  4. package/__tests__/contract.test.ts +25 -14
  5. package/__tests__/defaultProvider.test.ts +19 -43
  6. package/__tests__/fixtures.ts +9 -1
  7. package/__tests__/rpcProvider.test.ts +6 -15
  8. package/__tests__/sequencerProvider.test.ts +17 -10
  9. package/__tests__/utils/merkle.test.ts +98 -3
  10. package/__tests__/utils/typedData.test.ts +3 -3
  11. package/account/default.d.ts +10 -44
  12. package/account/default.js +255 -61
  13. package/account/interface.d.ts +78 -7
  14. package/constants.d.ts +1 -0
  15. package/constants.js +1 -0
  16. package/contract/default.js +6 -6
  17. package/dist/account/default.d.ts +10 -44
  18. package/dist/account/default.js +255 -61
  19. package/dist/account/interface.d.ts +78 -7
  20. package/dist/constants.d.ts +1 -0
  21. package/dist/constants.js +1 -0
  22. package/dist/contract/default.js +6 -6
  23. package/dist/provider/default.d.ts +8 -3
  24. package/dist/provider/default.js +31 -4
  25. package/dist/provider/interface.d.ts +67 -5
  26. package/dist/provider/rpc.d.ts +7 -2
  27. package/dist/provider/rpc.js +83 -8
  28. package/dist/provider/sequencer.d.ts +7 -2
  29. package/dist/provider/sequencer.js +71 -13
  30. package/dist/signer/default.d.ts +4 -1
  31. package/dist/signer/default.js +22 -0
  32. package/dist/signer/interface.d.ts +27 -2
  33. package/dist/types/api/openrpc.d.ts +24 -2
  34. package/dist/types/api/sequencer.d.ts +22 -7
  35. package/dist/types/lib.d.ts +23 -2
  36. package/dist/types/provider.d.ts +15 -10
  37. package/dist/types/signer.d.ts +14 -1
  38. package/dist/utils/hash.d.ts +2 -0
  39. package/dist/utils/hash.js +13 -2
  40. package/dist/utils/merkle.js +2 -4
  41. package/dist/utils/responseParser/rpc.d.ts +2 -6
  42. package/dist/utils/responseParser/rpc.js +0 -11
  43. package/dist/utils/responseParser/sequencer.js +4 -14
  44. package/package.json +1 -1
  45. package/provider/default.d.ts +8 -3
  46. package/provider/default.js +31 -4
  47. package/provider/interface.d.ts +67 -5
  48. package/provider/rpc.d.ts +7 -2
  49. package/provider/rpc.js +83 -8
  50. package/provider/sequencer.d.ts +7 -2
  51. package/provider/sequencer.js +71 -13
  52. package/signer/default.d.ts +4 -1
  53. package/signer/default.js +22 -0
  54. package/signer/interface.d.ts +27 -2
  55. package/src/account/default.ts +201 -53
  56. package/src/account/interface.ts +104 -6
  57. package/src/constants.ts +1 -0
  58. package/src/contract/default.ts +6 -6
  59. package/src/provider/default.ts +43 -5
  60. package/src/provider/interface.ts +92 -7
  61. package/src/provider/rpc.ts +86 -12
  62. package/src/provider/sequencer.ts +74 -10
  63. package/src/signer/default.ts +54 -2
  64. package/src/signer/interface.ts +31 -2
  65. package/src/types/api/openrpc.ts +28 -2
  66. package/src/types/api/sequencer.ts +32 -9
  67. package/src/types/lib.ts +30 -2
  68. package/src/types/provider.ts +27 -11
  69. package/src/types/signer.ts +18 -1
  70. package/src/utils/hash.ts +46 -1
  71. package/src/utils/merkle.ts +2 -4
  72. package/src/utils/responseParser/rpc.ts +4 -20
  73. package/src/utils/responseParser/sequencer.ts +2 -0
  74. package/types/api/openrpc.d.ts +24 -2
  75. package/types/api/sequencer.d.ts +22 -7
  76. package/types/lib.d.ts +23 -2
  77. package/types/provider.d.ts +15 -10
  78. package/types/signer.d.ts +14 -1
  79. package/utils/hash.d.ts +2 -0
  80. package/utils/hash.js +13 -2
  81. package/utils/merkle.js +2 -4
  82. package/utils/responseParser/rpc.d.ts +2 -6
  83. package/utils/responseParser/rpc.js +0 -11
  84. package/utils/responseParser/sequencer.js +4 -14
  85. package/www/docs/API/account.md +60 -1
  86. package/www/docs/API/provider.md +306 -17
  87. package/www/guides/erc20.md +13 -7
package/provider/rpc.js CHANGED
@@ -231,7 +231,7 @@ var RpcProvider = /** @class */ (function () {
231
231
  RpcProvider.prototype.getTransactionReceipt = function (txHash) {
232
232
  return __awaiter(this, void 0, void 0, function () {
233
233
  return __generator(this, function (_a) {
234
- return [2 /*return*/, this.fetchEndpoint('starknet_getTransactionReceipt', { transaction_hash: txHash }).then(this.responseParser.parseGetTransactionReceiptResponse)];
234
+ return [2 /*return*/, this.fetchEndpoint('starknet_getTransactionReceipt', { transaction_hash: txHash })];
235
235
  });
236
236
  });
237
237
  };
@@ -262,6 +262,14 @@ var RpcProvider = /** @class */ (function () {
262
262
  });
263
263
  };
264
264
  RpcProvider.prototype.getEstimateFee = function (invocation, invocationDetails, blockIdentifier) {
265
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
266
+ return __awaiter(this, void 0, void 0, function () {
267
+ return __generator(this, function (_a) {
268
+ return [2 /*return*/, this.getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier)];
269
+ });
270
+ });
271
+ };
272
+ RpcProvider.prototype.getInvokeEstimateFee = function (invocation, invocationDetails, blockIdentifier) {
265
273
  if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
266
274
  return __awaiter(this, void 0, void 0, function () {
267
275
  var block_id;
@@ -269,10 +277,12 @@ var RpcProvider = /** @class */ (function () {
269
277
  block_id = new utils_1.Block(blockIdentifier).identifier;
270
278
  return [2 /*return*/, this.fetchEndpoint('starknet_estimateFee', {
271
279
  request: {
280
+ type: 'INVOKE',
272
281
  contract_address: invocation.contractAddress,
273
282
  calldata: (0, provider_1.parseCalldata)(invocation.calldata),
274
283
  signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(invocation.signature || []),
275
284
  version: (0, number_1.toHex)((0, number_1.toBN)((invocationDetails === null || invocationDetails === void 0 ? void 0 : invocationDetails.version) || 0)),
285
+ nonce: (0, number_1.toHex)((0, number_1.toBN)(invocationDetails.nonce)),
276
286
  max_fee: (0, number_1.toHex)((0, number_1.toBN)((invocationDetails === null || invocationDetails === void 0 ? void 0 : invocationDetails.maxFee) || 0)),
277
287
  },
278
288
  block_id: block_id,
@@ -280,19 +290,72 @@ var RpcProvider = /** @class */ (function () {
280
290
  });
281
291
  });
282
292
  };
283
- RpcProvider.prototype.declareContract = function (_a) {
284
- var contract = _a.contract, version = _a.version;
293
+ // TODO: Revisit after Pathfinder release with JSON-RPC v0.2.1 RPC Spec
294
+ RpcProvider.prototype.getDeclareEstimateFee = function (_a, details, blockIdentifier) {
295
+ var senderAddress = _a.senderAddress, contractDefinition = _a.contractDefinition, signature = _a.signature;
296
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
297
+ return __awaiter(this, void 0, void 0, function () {
298
+ var block_id;
299
+ return __generator(this, function (_b) {
300
+ block_id = new utils_1.Block(blockIdentifier).identifier;
301
+ return [2 /*return*/, this.fetchEndpoint('starknet_estimateFee', {
302
+ request: {
303
+ type: 'DECLARE',
304
+ contract_class: {
305
+ program: contractDefinition.program,
306
+ entry_points_by_type: contractDefinition.entry_points_by_type,
307
+ abi: contractDefinition.abi, // rpc 2.0
308
+ },
309
+ sender_address: senderAddress,
310
+ signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(signature || []),
311
+ version: (0, number_1.toHex)((0, number_1.toBN)((details === null || details === void 0 ? void 0 : details.version) || 0)),
312
+ nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
313
+ max_fee: (0, number_1.toHex)((0, number_1.toBN)((details === null || details === void 0 ? void 0 : details.maxFee) || 0)),
314
+ },
315
+ block_id: block_id,
316
+ }).then(this.responseParser.parseFeeEstimateResponse)];
317
+ });
318
+ });
319
+ };
320
+ RpcProvider.prototype.getDeployAccountEstimateFee = function (_a, details, blockIdentifier) {
321
+ var classHash = _a.classHash, constructorCalldata = _a.constructorCalldata, addressSalt = _a.addressSalt, signature = _a.signature;
322
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
323
+ return __awaiter(this, void 0, void 0, function () {
324
+ var block_id;
325
+ return __generator(this, function (_b) {
326
+ block_id = new utils_1.Block(blockIdentifier).identifier;
327
+ return [2 /*return*/, this.fetchEndpoint('starknet_estimateFee', {
328
+ request: {
329
+ type: 'DEPLOY_ACCOUNT',
330
+ constructor_calldata: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(constructorCalldata || []),
331
+ class_hash: (0, number_1.toHex)((0, number_1.toBN)(classHash)),
332
+ contract_address_salt: (0, number_1.toHex)((0, number_1.toBN)(addressSalt || 0)),
333
+ signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(signature || []),
334
+ version: (0, number_1.toHex)((0, number_1.toBN)((details === null || details === void 0 ? void 0 : details.version) || 0)),
335
+ nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
336
+ max_fee: (0, number_1.toHex)((0, number_1.toBN)((details === null || details === void 0 ? void 0 : details.maxFee) || 0)),
337
+ },
338
+ block_id: block_id,
339
+ }).then(this.responseParser.parseFeeEstimateResponse)];
340
+ });
341
+ });
342
+ };
343
+ // TODO: Revisit after Pathfinder release with JSON-RPC v0.2.1 RPC Spec
344
+ RpcProvider.prototype.declareContract = function (_a, details) {
345
+ var contractDefinition = _a.contractDefinition, signature = _a.signature, senderAddress = _a.senderAddress;
285
346
  return __awaiter(this, void 0, void 0, function () {
286
- var contractDefinition;
287
347
  return __generator(this, function (_b) {
288
- contractDefinition = (0, provider_1.parseContract)(contract);
289
348
  return [2 /*return*/, this.fetchEndpoint('starknet_addDeclareTransaction', {
290
349
  contract_class: {
291
350
  program: contractDefinition.program,
292
351
  entry_points_by_type: contractDefinition.entry_points_by_type,
293
352
  abi: contractDefinition.abi, // rpc 2.0
294
353
  },
295
- version: (0, number_1.toHex)((0, number_1.toBN)(version || 0)),
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)),
296
359
  })];
297
360
  });
298
361
  });
@@ -315,6 +378,18 @@ var RpcProvider = /** @class */ (function () {
315
378
  });
316
379
  });
317
380
  };
381
+ RpcProvider.prototype.deployAccountContract = function (_a) {
382
+ var classHash = _a.classHash, constructorCalldata = _a.constructorCalldata, addressSalt = _a.addressSalt;
383
+ return __awaiter(this, void 0, void 0, function () {
384
+ return __generator(this, function (_b) {
385
+ return [2 /*return*/, this.fetchEndpoint('starknet_addDeployAccountTransaction', {
386
+ constructor_calldata: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(constructorCalldata || []),
387
+ class_hash: (0, number_1.toHex)((0, number_1.toBN)(classHash)),
388
+ contract_address_salt: (0, number_1.toHex)((0, number_1.toBN)(addressSalt || 0)),
389
+ })];
390
+ });
391
+ });
392
+ };
318
393
  RpcProvider.prototype.invokeFunction = function (functionInvocation, details) {
319
394
  return __awaiter(this, void 0, void 0, function () {
320
395
  return __generator(this, function (_a) {
@@ -393,10 +468,10 @@ var RpcProvider = /** @class */ (function () {
393
468
  return [4 /*yield*/, this.getTransactionReceipt(txHash)];
394
469
  case 4:
395
470
  res = _a.sent();
396
- if (successStates.includes(res.status)) {
471
+ if (res.status && successStates.includes(res.status)) {
397
472
  onchain = true;
398
473
  }
399
- else if (errorStates.includes(res.status)) {
474
+ else if (res.status && errorStates.includes(res.status)) {
400
475
  message = res.status;
401
476
  error = new Error(message);
402
477
  error.response = res;
@@ -1,6 +1,7 @@
1
1
  import { StarknetChainId } from '../constants';
2
- import { Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
2
+ import { Call, CallContractResponse, ContractClass, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
3
3
  import { CallL1Handler, GetContractAddressesResponse, GetTransactionStatusResponse, GetTransactionTraceResponse, Sequencer } from '../types/api';
4
+ import { DeclareContractTransaction, DeployAccountContractTransaction } from '../types/lib';
4
5
  import { BigNumberish } from '../utils/number';
5
6
  import { ProviderInterface } from './interface';
6
7
  import { BlockIdentifier } from './utils';
@@ -37,8 +38,12 @@ export declare class SequencerProvider implements ProviderInterface {
37
38
  getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
38
39
  invokeFunction(functionInvocation: Invocation, details: InvocationsDetailsWithNonce): Promise<InvokeFunctionResponse>;
39
40
  deployContract({ contract, constructorCalldata, addressSalt, }: DeployContractPayload): Promise<DeployContractResponse>;
40
- declareContract({ contract, }: DeclareContractPayload): Promise<DeclareContractResponse>;
41
+ deployAccountContract({ classHash, constructorCalldata, addressSalt, signature }: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeployContractResponse>;
42
+ declareContract({ senderAddress, contractDefinition, signature }: DeclareContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeclareContractResponse>;
41
43
  getEstimateFee(invocation: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
44
+ getInvokeEstimateFee(invocation: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
45
+ getDeclareEstimateFee({ senderAddress, contractDefinition, signature }: DeclareContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
46
+ getDeployAccountEstimateFee({ classHash, addressSalt, constructorCalldata, signature }: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
42
47
  getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<Sequencer.GetCodeResponse>;
43
48
  waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
44
49
  /**
@@ -157,22 +157,22 @@ var SequencerProvider = /** @class */ (function () {
157
157
  };
158
158
  // typesafe fetch
159
159
  SequencerProvider.prototype.fetchEndpoint = function (endpoint) {
160
- // typescript type magiuc to create a nice fitting function interface
160
+ // typescript type magic to create a nice fitting function interface
161
161
  var _a = []; // when both query and request are needed, we cant omit anything
162
162
  for (
163
- // typescript type magiuc to create a nice fitting function interface
163
+ // typescript type magic to create a nice fitting function interface
164
164
  var _i = 1 // when both query and request are needed, we cant omit anything
165
165
  ;
166
- // typescript type magiuc to create a nice fitting function interface
166
+ // typescript type magic to create a nice fitting function interface
167
167
  _i < arguments.length // when both query and request are needed, we cant omit anything
168
168
  ;
169
- // typescript type magiuc to create a nice fitting function interface
169
+ // typescript type magic to create a nice fitting function interface
170
170
  _i++ // when both query and request are needed, we cant omit anything
171
171
  ) {
172
- // typescript type magiuc to create a nice fitting function interface
172
+ // typescript type magic to create a nice fitting function interface
173
173
  _a[_i - 1] = arguments[_i]; // when both query and request are needed, we cant omit anything
174
174
  }
175
- // typescript type magiuc to create a nice fitting function interface
175
+ // typescript type magic to create a nice fitting function interface
176
176
  var _b = __read(_a, 2), query = _b[0], request = _b[1]; // when both query and request are needed, we cant omit anything
177
177
  return __awaiter(this, void 0, void 0, function () {
178
178
  var baseUrl, method, queryString, headers, url, res, textResponse, responseBody, errorCode, err_1;
@@ -344,23 +344,48 @@ var SequencerProvider = /** @class */ (function () {
344
344
  });
345
345
  });
346
346
  };
347
- SequencerProvider.prototype.declareContract = function (_a) {
348
- var contract = _a.contract;
347
+ SequencerProvider.prototype.deployAccountContract = function (_a, details) {
348
+ var classHash = _a.classHash, constructorCalldata = _a.constructorCalldata, addressSalt = _a.addressSalt, signature = _a.signature;
349
+ return __awaiter(this, void 0, void 0, function () {
350
+ return __generator(this, function (_b) {
351
+ return [2 /*return*/, this.fetchEndpoint('add_transaction', undefined, {
352
+ type: 'DEPLOY_ACCOUNT',
353
+ contract_address_salt: addressSalt !== null && addressSalt !== void 0 ? addressSalt : (0, stark_1.randomAddress)(),
354
+ constructor_calldata: (0, number_1.bigNumberishArrayToDecimalStringArray)(constructorCalldata !== null && constructorCalldata !== void 0 ? constructorCalldata : []),
355
+ class_hash: (0, number_1.toHex)((0, number_1.toBN)(classHash)),
356
+ max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
357
+ version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
358
+ nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
359
+ signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature || []),
360
+ }).then(this.responseParser.parseDeployContractResponse)];
361
+ });
362
+ });
363
+ };
364
+ SequencerProvider.prototype.declareContract = function (_a, details) {
365
+ var senderAddress = _a.senderAddress, contractDefinition = _a.contractDefinition, signature = _a.signature;
349
366
  return __awaiter(this, void 0, void 0, function () {
350
- var contractDefinition;
351
367
  return __generator(this, function (_b) {
352
- contractDefinition = (0, provider_1.parseContract)(contract);
353
368
  return [2 /*return*/, this.fetchEndpoint('add_transaction', undefined, {
354
369
  type: 'DECLARE',
355
370
  contract_class: contractDefinition,
356
- nonce: (0, number_1.toHex)(constants_1.ZERO),
357
- signature: [],
358
- sender_address: (0, number_1.toHex)(constants_1.ONE),
371
+ nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
372
+ signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature || []),
373
+ sender_address: senderAddress,
374
+ max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
375
+ version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 1)),
359
376
  }).then(this.responseParser.parseDeclareContractResponse)];
360
377
  });
361
378
  });
362
379
  };
363
380
  SequencerProvider.prototype.getEstimateFee = function (invocation, invocationDetails, blockIdentifier) {
381
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
382
+ return __awaiter(this, void 0, void 0, function () {
383
+ return __generator(this, function (_a) {
384
+ return [2 /*return*/, this.getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier)];
385
+ });
386
+ });
387
+ };
388
+ SequencerProvider.prototype.getInvokeEstimateFee = function (invocation, invocationDetails, blockIdentifier) {
364
389
  var _a;
365
390
  if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
366
391
  return __awaiter(this, void 0, void 0, function () {
@@ -376,6 +401,39 @@ var SequencerProvider = /** @class */ (function () {
376
401
  });
377
402
  });
378
403
  };
404
+ SequencerProvider.prototype.getDeclareEstimateFee = function (_a, details, blockIdentifier) {
405
+ var senderAddress = _a.senderAddress, contractDefinition = _a.contractDefinition, signature = _a.signature;
406
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
407
+ return __awaiter(this, void 0, void 0, function () {
408
+ return __generator(this, function (_b) {
409
+ return [2 /*return*/, this.fetchEndpoint('estimate_fee', { blockIdentifier: blockIdentifier }, {
410
+ type: 'DECLARE',
411
+ sender_address: senderAddress,
412
+ contract_class: contractDefinition,
413
+ signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature || []),
414
+ version: (0, number_1.toHex)((0, number_1.toBN)((details === null || details === void 0 ? void 0 : details.version) || 1)),
415
+ nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
416
+ }).then(this.responseParser.parseFeeEstimateResponse)];
417
+ });
418
+ });
419
+ };
420
+ SequencerProvider.prototype.getDeployAccountEstimateFee = function (_a, details, blockIdentifier) {
421
+ var classHash = _a.classHash, addressSalt = _a.addressSalt, constructorCalldata = _a.constructorCalldata, signature = _a.signature;
422
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
423
+ return __awaiter(this, void 0, void 0, function () {
424
+ return __generator(this, function (_b) {
425
+ return [2 /*return*/, this.fetchEndpoint('estimate_fee', { blockIdentifier: blockIdentifier }, {
426
+ type: 'DEPLOY_ACCOUNT',
427
+ class_hash: (0, number_1.toHex)((0, number_1.toBN)(classHash)),
428
+ constructor_calldata: (0, number_1.bigNumberishArrayToDecimalStringArray)(constructorCalldata || []),
429
+ contract_address_salt: (0, number_1.toHex)((0, number_1.toBN)(addressSalt || 0)),
430
+ signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature || []),
431
+ version: (0, number_1.toHex)((0, number_1.toBN)((details === null || details === void 0 ? void 0 : details.version) || 0)),
432
+ nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
433
+ }).then(this.responseParser.parseFeeEstimateResponse)];
434
+ });
435
+ });
436
+ };
379
437
  SequencerProvider.prototype.getCode = function (contractAddress, blockIdentifier) {
380
438
  if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
381
439
  return __awaiter(this, void 0, void 0, function () {
@@ -1,4 +1,5 @@
1
- import { Abi, Call, InvocationsSignerDetails, KeyPair, Signature } from '../types';
1
+ import { Abi, Call, DeclareSignerDetails, InvocationsSignerDetails, KeyPair, Signature } from '../types';
2
+ import { DeployAccountSignerDetails } from '../types/signer';
2
3
  import { TypedData } from '../utils/typedData';
3
4
  import { SignerInterface } from './interface';
4
5
  export declare class Signer implements SignerInterface {
@@ -6,5 +7,7 @@ export declare class Signer implements SignerInterface {
6
7
  constructor(keyPair?: KeyPair);
7
8
  getPubKey(): Promise<string>;
8
9
  signTransaction(transactions: Call[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): Promise<Signature>;
10
+ signDeclareTransaction({ classHash, senderAddress, chainId, maxFee, version, nonce }: DeclareSignerDetails): Promise<Signature>;
11
+ signDeployAccountTransaction({ classHash, contractAddress, constructorCalldata, addressSalt, maxFee, version, chainId, nonce, }: DeployAccountSignerDetails): Promise<Signature>;
9
12
  signMessage(typedData: TypedData, accountAddress: string): Promise<Signature>;
10
13
  }
package/signer/default.js CHANGED
@@ -66,6 +66,28 @@ var Signer = /** @class */ (function () {
66
66
  });
67
67
  });
68
68
  };
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
+ Signer.prototype.signDeployAccountTransaction = function (_a) {
82
+ 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
+ return __awaiter(this, void 0, void 0, function () {
84
+ var msgHash;
85
+ return __generator(this, function (_b) {
86
+ msgHash = (0, hash_1.calculateDeployAccountTransactionHash)(contractAddress, classHash, constructorCalldata, addressSalt, version, maxFee, chainId, nonce);
87
+ return [2 /*return*/, (0, ellipticCurve_1.sign)(this.keyPair, msgHash)];
88
+ });
89
+ });
90
+ };
69
91
  Signer.prototype.signMessage = function (typedData, accountAddress) {
70
92
  return __awaiter(this, void 0, void 0, function () {
71
93
  var msgHash;
@@ -1,4 +1,5 @@
1
- import { Abi, Call, InvocationsSignerDetails, Signature } from '../types';
1
+ import { Abi, Call, DeclareSignerDetails, InvocationsSignerDetails, Signature } from '../types';
2
+ import { DeployAccountSignerDetails } from '../types/signer';
2
3
  import { TypedData } from '../utils/typedData';
3
4
  export declare abstract class SignerInterface {
4
5
  /**
@@ -24,10 +25,34 @@ export declare abstract class SignerInterface {
24
25
  * - contractAddress - the address of the contract
25
26
  * - entrypoint - the entrypoint of the contract
26
27
  * - calldata - (defaults to []) the calldata
27
- * - signature - (defaults to []) the signature
28
28
  * @param abi (optional) the abi of the contract for better displaying
29
29
  *
30
30
  * @returns signature
31
31
  */
32
32
  abstract signTransaction(transactions: Call[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): Promise<Signature>;
33
+ /**
34
+ * Signs a DEPLOY_ACCOUNT transaction with the starknet private key and returns the signature
35
+ * @param transaction
36
+ * - contractAddress - the computed address of the contract
37
+ * - constructorCalldata - calldata to be passed in deploy constructor
38
+ * - addressSalt - contract address salt
39
+ * - chainId - the chainId to declare contract on
40
+ * - maxFee - maxFee for the declare transaction
41
+ * - version - transaction version
42
+ * - nonce - Nonce of the declare transaction
43
+ * @returns signature
44
+ */
45
+ abstract signDeployAccountTransaction(transaction: DeployAccountSignerDetails): Promise<Signature>;
46
+ /**
47
+ * Signs a DECLARE transaction with the starknet private key and returns the signature
48
+ * @param transaction
49
+ * - classHash - computed class hash. Will be replaced by ContractClass in future once class hash is present in CompiledContract
50
+ * - senderAddress - the address of the sender
51
+ * - chainId - the chainId to declare contract on
52
+ * - maxFee - maxFee for the declare transaction
53
+ * - version - transaction version
54
+ * - nonce - Nonce of the declare transaction
55
+ * @returns signature
56
+ */
57
+ abstract signDeclareTransaction(transaction: DeclareSignerDetails): Promise<Signature>;
33
58
  }