starknet 3.10.0 → 3.10.3

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 (56) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/__tests__/accountContract.test.ts +3 -1
  3. package/__tests__/provider.test.ts +4 -4
  4. package/account/default.d.ts +10 -6
  5. package/account/default.js +3 -3
  6. package/account/interface.d.ts +2 -0
  7. package/contract/contractFactory.d.ts +5 -5
  8. package/contract/default.js +1 -1
  9. package/dist/account/default.d.ts +6 -6
  10. package/dist/account/default.js +3 -3
  11. package/dist/account/interface.d.ts +2 -0
  12. package/dist/contract/contractFactory.d.ts +5 -5
  13. package/dist/contract/default.js +1 -1
  14. package/dist/index.d.ts +1 -0
  15. package/dist/index.js +2 -1
  16. package/dist/provider/default.d.ts +1 -1
  17. package/dist/provider/default.js +2 -1
  18. package/dist/signer/index.d.ts +0 -1
  19. package/dist/signer/index.js +0 -1
  20. package/dist/utils/encode.js +1 -1
  21. package/index.d.ts +1 -0
  22. package/index.js +2 -0
  23. package/package.json +1 -4
  24. package/provider/default.d.ts +1 -1
  25. package/provider/default.js +2 -1
  26. package/signer/index.d.ts +0 -1
  27. package/signer/index.js +0 -1
  28. package/src/account/default.ts +10 -6
  29. package/src/account/interface.ts +3 -0
  30. package/src/contract/contractFactory.ts +5 -5
  31. package/src/contract/default.ts +1 -1
  32. package/src/index.ts +1 -0
  33. package/src/provider/default.ts +4 -2
  34. package/src/signer/index.ts +0 -1
  35. package/src/utils/encode.ts +1 -1
  36. package/utils/encode.js +3 -1
  37. package/www/code-examples/account.js +8 -5
  38. package/www/code-examples/amm.js +13 -18
  39. package/www/code-examples/erc20.js +6 -3
  40. package/www/docs/API/account.md +94 -0
  41. package/www/docs/API/changelog.md +15 -0
  42. package/www/docs/API/contract.md +73 -2
  43. package/www/docs/API/contractFacotry.md +42 -0
  44. package/www/docs/API/index.md +0 -1
  45. package/www/docs/API/provider.md +204 -1
  46. package/www/docs/API/signer.md +35 -0
  47. package/www/docusaurus.config.js +3 -4
  48. package/www/guides/account.md +1 -1
  49. package/www/guides/erc20.md +7 -0
  50. package/www/guides/intro.md +1 -0
  51. package/www/sidebars.js +1 -1
  52. package/dist/signer/ledger.d.ts +0 -12
  53. package/dist/signer/ledger.js +0 -140
  54. package/signer/ledger.d.ts +0 -15
  55. package/signer/ledger.js +0 -250
  56. package/src/signer/ledger.ts +0 -86
package/CHANGELOG.md CHANGED
@@ -1,3 +1,25 @@
1
+ ## [3.10.3](https://github.com/seanjameshan/starknet.js/compare/v3.10.2...v3.10.3) (2022-05-04)
2
+
3
+ ### Bug Fixes
4
+
5
+ - **encode:** maximum call stack size exceeded ([3cd8195](https://github.com/seanjameshan/starknet.js/commit/3cd8195d0fcde7d2cf6460959bb2c9f45ef7d066))
6
+
7
+ ## [3.10.2](https://github.com/seanjameshan/starknet.js/compare/v3.10.1...v3.10.2) (2022-04-27)
8
+
9
+ ### Bug Fixes
10
+
11
+ - **tests:** fix getBlock blocks ([c0422b7](https://github.com/seanjameshan/starknet.js/commit/c0422b7d963639d34082731f6efbe3f0dd2c3c4d))
12
+
13
+ ## [3.10.1](https://github.com/seanjameshan/starknet.js/compare/v3.10.0...v3.10.1) (2022-04-20)
14
+
15
+ ### Bug Fixes
16
+
17
+ - **account:** function documentation fix ([34a9779](https://github.com/seanjameshan/starknet.js/commit/34a977953c2bfea53f9cd1157809919b1dd2ed04))
18
+ - **contractFactory:** wrong prop type ([598bcd0](https://github.com/seanjameshan/starknet.js/commit/598bcd0d589c00e2219522d4a342316598678d4e))
19
+ - **contract:** recursion function name fix ([803b6dc](https://github.com/seanjameshan/starknet.js/commit/803b6dcf5cad5cdfd8258a53e176bcd96300cef3))
20
+ - typings ([1fadf41](https://github.com/seanjameshan/starknet.js/commit/1fadf418b04d96ced8d994b35699f40be9a8c898))
21
+ - **utils:** adding transaction utils to the utils export ([6429179](https://github.com/seanjameshan/starknet.js/commit/642917922a5d5278e8c575a2b4ffd60fff53cf42))
22
+
1
23
  # [3.10.0](https://github.com/seanjameshan/starknet.js/compare/v3.9.0...v3.10.0) (2022-04-20)
2
24
 
3
25
  ### Bug Fixes
@@ -36,7 +36,9 @@ test('build tx', async () => {
36
36
 
37
37
  const selector = hash.getSelectorFromName('transfer');
38
38
 
39
- expect(selector).toMatchInlineSnapshot();
39
+ expect(selector).toMatchInlineSnapshot(
40
+ `"0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e"`
41
+ );
40
42
 
41
43
  const calls = [{ contractAddress: '1', entrypoint: 'transfer', calldata: ['6', '7'] }];
42
44
  const calldata = fromCallsToExecuteCalldataWithNonce(calls, 0);
@@ -10,15 +10,15 @@ describe('defaultProvider', () => {
10
10
  expect(typeof GpsStatementVerifier).toBe('string');
11
11
  expect(typeof Starknet).toBe('string');
12
12
  });
13
- test('getBlock(blockHash=0x3bca19c3d5983e21e9537669b15f951f0664f0747a083dc714e0b9648b8575d, blockNumber=undefined)', () => {
13
+ test('getBlock(blockHash=0x26e33ad2807590b93e98a04e703d7d64d4ead13591b50984ae558bdbe8fbcd2, blockNumber=undefined)', () => {
14
14
  return expect(
15
15
  defaultProvider.getBlock(
16
- '0x3bca19c3d5983e21e9537669b15f951f0664f0747a083dc714e0b9648b8575d'
16
+ '0x26e33ad2807590b93e98a04e703d7d64d4ead13591b50984ae558bdbe8fbcd2'
17
17
  )
18
18
  ).resolves.not.toThrow();
19
19
  });
20
- test('getBlock(blockHash=undefined, blockNumber=36657)', () => {
21
- return expect(defaultProvider.getBlock(36657)).resolves.not.toThrow();
20
+ test('getBlock(blockHash=undefined, blockNumber=168890)', () => {
21
+ return expect(defaultProvider.getBlock(168890)).resolves.not.toThrow();
22
22
  });
23
23
  test('getBlock(blockHash=undefined, blockNumber=null)', () => {
24
24
  return expect(defaultProvider.getBlock()).resolves.not.toThrow();
@@ -1,4 +1,4 @@
1
- import { Provider } from '../provider';
1
+ import { Provider, ProviderInterface } from '../provider';
2
2
  import { BlockIdentifier } from '../provider/utils';
3
3
  import { SignerInterface } from '../signer';
4
4
  import {
@@ -16,8 +16,12 @@ import { TypedData } from '../utils/typedData';
16
16
  import { AccountInterface } from './interface';
17
17
  export declare class Account extends Provider implements AccountInterface {
18
18
  address: string;
19
- private signer;
20
- constructor(provider: Provider, address: string, keyPairOrSigner: KeyPair | SignerInterface);
19
+ signer: SignerInterface;
20
+ constructor(
21
+ provider: ProviderInterface,
22
+ address: string,
23
+ keyPairOrSigner: KeyPair | SignerInterface
24
+ );
21
25
  getNonce(): Promise<string>;
22
26
  estimateFee(
23
27
  calls: Call | Call[],
@@ -64,7 +68,8 @@ export declare class Account extends Provider implements AccountInterface {
64
68
  */
65
69
  hashMessage(typedData: TypedData): Promise<string>;
66
70
  /**
67
- * Verify a signature of a JSON object
71
+ * Verify a signature of a given hash
72
+ * @warning This method is not recommended, use verifyMessage instead
68
73
  *
69
74
  * @param hash - JSON object to be verified
70
75
  * @param signature - signature of the JSON object
@@ -73,8 +78,7 @@ export declare class Account extends Provider implements AccountInterface {
73
78
  */
74
79
  verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
75
80
  /**
76
- * Verify a signature of a given hash
77
- * @warning This method is not recommended, use verifyMessage instead
81
+ * Verify a signature of a JSON object
78
82
  *
79
83
  * @param hash - hash to be verified
80
84
  * @param signature - signature of the hash
@@ -510,7 +510,8 @@ var Account = /** @class */ (function (_super) {
510
510
  });
511
511
  };
512
512
  /**
513
- * Verify a signature of a JSON object
513
+ * Verify a signature of a given hash
514
+ * @warning This method is not recommended, use verifyMessage instead
514
515
  *
515
516
  * @param hash - JSON object to be verified
516
517
  * @param signature - signature of the JSON object
@@ -550,8 +551,7 @@ var Account = /** @class */ (function (_super) {
550
551
  });
551
552
  };
552
553
  /**
553
- * Verify a signature of a given hash
554
- * @warning This method is not recommended, use verifyMessage instead
554
+ * Verify a signature of a JSON object
555
555
  *
556
556
  * @param hash - hash to be verified
557
557
  * @param signature - signature of the hash
@@ -1,4 +1,5 @@
1
1
  import { ProviderInterface } from '../provider';
2
+ import { SignerInterface } from '../signer';
2
3
  import {
3
4
  Abi,
4
5
  AddTransactionResponse,
@@ -13,6 +14,7 @@ import { BigNumberish } from '../utils/number';
13
14
  import { TypedData } from '../utils/typedData/types';
14
15
  export declare abstract class AccountInterface extends ProviderInterface {
15
16
  abstract address: string;
17
+ abstract signer: SignerInterface;
16
18
  /**
17
19
  * Deploys a given compiled contract (json) to starknet
18
20
  *
@@ -1,15 +1,15 @@
1
- import { Account } from '../account';
2
- import { Provider } from '../provider';
1
+ import { AccountInterface } from '../account';
2
+ import { ProviderInterface } from '../provider';
3
3
  import { Abi, CompiledContract, RawCalldata } from '../types';
4
4
  import { BigNumberish } from '../utils/number';
5
5
  import { Contract } from './default';
6
6
  export declare class ContractFactory {
7
7
  abi: Abi;
8
8
  compiledContract: CompiledContract;
9
- providerOrAccount: Provider | Account;
9
+ providerOrAccount: ProviderInterface | AccountInterface;
10
10
  constructor(
11
11
  compiledContract: CompiledContract,
12
- providerOrAccount?: Provider | Account,
12
+ providerOrAccount?: ProviderInterface | AccountInterface,
13
13
  abi?: Abi
14
14
  );
15
15
  /**
@@ -25,7 +25,7 @@ export declare class ContractFactory {
25
25
  *
26
26
  * @param providerOrAccount - new Provider or Account to attach to
27
27
  */
28
- connect(providerOrAccount: Provider | Account): ContractFactory;
28
+ connect(providerOrAccount: ProviderInterface | AccountInterface): ContractFactory;
29
29
  /**
30
30
  * Attaches current abi and provider or account to the new address
31
31
  *
@@ -522,7 +522,7 @@ var Contract = /** @class */ (function () {
522
522
  if (member.type === 'felt') {
523
523
  return acc + 1;
524
524
  }
525
- return acc + _this.structMemberNum(member.type);
525
+ return acc + _this.calculateStructMembers(member.type);
526
526
  }, 0);
527
527
  };
528
528
  /**
@@ -1,4 +1,4 @@
1
- import { Provider } from '../provider';
1
+ import { Provider, ProviderInterface } from '../provider';
2
2
  import { BlockIdentifier } from '../provider/utils';
3
3
  import { SignerInterface } from '../signer';
4
4
  import { Abi, AddTransactionResponse, Call, EstimateFeeResponse, InvocationsDetails, KeyPair, Signature, Transaction } from '../types';
@@ -7,8 +7,8 @@ import { TypedData } from '../utils/typedData';
7
7
  import { AccountInterface } from './interface';
8
8
  export declare class Account extends Provider implements AccountInterface {
9
9
  address: string;
10
- private signer;
11
- constructor(provider: Provider, address: string, keyPairOrSigner: KeyPair | SignerInterface);
10
+ signer: SignerInterface;
11
+ constructor(provider: ProviderInterface, address: string, keyPairOrSigner: KeyPair | SignerInterface);
12
12
  getNonce(): Promise<string>;
13
13
  estimateFee(calls: Call | Call[], { nonce: providedNonce, blockIdentifier, }?: {
14
14
  nonce?: BigNumberish;
@@ -45,7 +45,8 @@ export declare class Account extends Provider implements AccountInterface {
45
45
  */
46
46
  hashMessage(typedData: TypedData): Promise<string>;
47
47
  /**
48
- * Verify a signature of a JSON object
48
+ * Verify a signature of a given hash
49
+ * @warning This method is not recommended, use verifyMessage instead
49
50
  *
50
51
  * @param hash - JSON object to be verified
51
52
  * @param signature - signature of the JSON object
@@ -54,8 +55,7 @@ export declare class Account extends Provider implements AccountInterface {
54
55
  */
55
56
  verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
56
57
  /**
57
- * Verify a signature of a given hash
58
- * @warning This method is not recommended, use verifyMessage instead
58
+ * Verify a signature of a JSON object
59
59
  *
60
60
  * @param hash - hash to be verified
61
61
  * @param signature - signature of the hash
@@ -340,7 +340,8 @@ var Account = /** @class */ (function (_super) {
340
340
  });
341
341
  };
342
342
  /**
343
- * Verify a signature of a JSON object
343
+ * Verify a signature of a given hash
344
+ * @warning This method is not recommended, use verifyMessage instead
344
345
  *
345
346
  * @param hash - JSON object to be verified
346
347
  * @param signature - signature of the JSON object
@@ -374,8 +375,7 @@ var Account = /** @class */ (function (_super) {
374
375
  });
375
376
  };
376
377
  /**
377
- * Verify a signature of a given hash
378
- * @warning This method is not recommended, use verifyMessage instead
378
+ * Verify a signature of a JSON object
379
379
  *
380
380
  * @param hash - hash to be verified
381
381
  * @param signature - signature of the hash
@@ -1,9 +1,11 @@
1
1
  import { ProviderInterface } from '../provider';
2
+ import { SignerInterface } from '../signer';
2
3
  import { Abi, AddTransactionResponse, Call, DeployContractPayload, EstimateFeeResponse, Invocation, InvocationsDetails, Signature } from '../types';
3
4
  import { BigNumberish } from '../utils/number';
4
5
  import { TypedData } from '../utils/typedData/types';
5
6
  export declare abstract class AccountInterface extends ProviderInterface {
6
7
  abstract address: string;
8
+ abstract signer: SignerInterface;
7
9
  /**
8
10
  * Deploys a given compiled contract (json) to starknet
9
11
  *
@@ -1,13 +1,13 @@
1
- import { Account } from '../account';
2
- import { Provider } from '../provider';
1
+ import { AccountInterface } from '../account';
2
+ import { ProviderInterface } from '../provider';
3
3
  import { Abi, CompiledContract, RawCalldata } from '../types';
4
4
  import { BigNumberish } from '../utils/number';
5
5
  import { Contract } from './default';
6
6
  export declare class ContractFactory {
7
7
  abi: Abi;
8
8
  compiledContract: CompiledContract;
9
- providerOrAccount: Provider | Account;
10
- constructor(compiledContract: CompiledContract, providerOrAccount?: Provider | Account, abi?: Abi);
9
+ providerOrAccount: ProviderInterface | AccountInterface;
10
+ constructor(compiledContract: CompiledContract, providerOrAccount?: ProviderInterface | AccountInterface, abi?: Abi);
11
11
  /**
12
12
  * Deploys contract and returns new instance of the Contract
13
13
  *
@@ -21,7 +21,7 @@ export declare class ContractFactory {
21
21
  *
22
22
  * @param providerOrAccount - new Provider or Account to attach to
23
23
  */
24
- connect(providerOrAccount: Provider | Account): ContractFactory;
24
+ connect(providerOrAccount: ProviderInterface | AccountInterface): ContractFactory;
25
25
  /**
26
26
  * Attaches current abi and provider or account to the new address
27
27
  *
@@ -383,7 +383,7 @@ var Contract = /** @class */ (function () {
383
383
  if (member.type === 'felt') {
384
384
  return acc + 1;
385
385
  }
386
- return acc + _this.structMemberNum(member.type);
386
+ return acc + _this.calculateStructMembers(member.type);
387
387
  }, 0);
388
388
  };
389
389
  /**
package/dist/index.d.ts CHANGED
@@ -14,6 +14,7 @@ export * as encode from './utils/encode';
14
14
  export * as hash from './utils/hash';
15
15
  export * as json from './utils/json';
16
16
  export * as number from './utils/number';
17
+ export * as transaction from './utils/transaction';
17
18
  export * as stark from './utils/stark';
18
19
  export * as ec from './utils/ellipticCurve';
19
20
  export * as uint256 from './utils/uint256';
package/dist/index.js CHANGED
@@ -22,7 +22,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  return result;
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.typedData = exports.shortString = exports.uint256 = exports.ec = exports.stark = exports.number = exports.json = exports.hash = exports.encode = exports.constants = void 0;
25
+ exports.typedData = exports.shortString = exports.uint256 = exports.ec = exports.stark = exports.transaction = exports.number = exports.json = exports.hash = exports.encode = exports.constants = void 0;
26
26
  /**
27
27
  * Main
28
28
  */
@@ -39,6 +39,7 @@ exports.encode = __importStar(require("./utils/encode"));
39
39
  exports.hash = __importStar(require("./utils/hash"));
40
40
  exports.json = __importStar(require("./utils/json"));
41
41
  exports.number = __importStar(require("./utils/number"));
42
+ exports.transaction = __importStar(require("./utils/transaction"));
42
43
  exports.stark = __importStar(require("./utils/stark"));
43
44
  exports.ec = __importStar(require("./utils/ellipticCurve"));
44
45
  exports.uint256 = __importStar(require("./utils/uint256"));
@@ -14,7 +14,7 @@ export declare class Provider implements ProviderInterface {
14
14
  feederGatewayUrl: string;
15
15
  gatewayUrl: string;
16
16
  chainId: StarknetChainId;
17
- constructor(optionsOrProvider?: ProviderOptions | Provider);
17
+ constructor(optionsOrProvider?: ProviderOptions | ProviderInterface);
18
18
  protected static getNetworkFromName(name: NetworkName): "https://alpha-mainnet.starknet.io" | "https://alpha4.starknet.io";
19
19
  protected static getChainIdFromBaseUrl(baseUrl: string): StarknetChainId;
20
20
  private getFetchUrl;
@@ -74,6 +74,7 @@ var hash_1 = require("../utils/hash");
74
74
  var json_1 = require("../utils/json");
75
75
  var number_1 = require("../utils/number");
76
76
  var stark_1 = require("../utils/stark");
77
+ var interface_1 = require("./interface");
77
78
  var utils_1 = require("./utils");
78
79
  function wait(delay) {
79
80
  return new Promise(function (res) { return setTimeout(res, delay); });
@@ -91,7 +92,7 @@ var Provider = /** @class */ (function () {
91
92
  function Provider(optionsOrProvider) {
92
93
  if (optionsOrProvider === void 0) { optionsOrProvider = { network: 'goerli-alpha' }; }
93
94
  var _a;
94
- if (optionsOrProvider instanceof Provider) {
95
+ if (optionsOrProvider instanceof interface_1.ProviderInterface) {
95
96
  this.baseUrl = optionsOrProvider.baseUrl;
96
97
  this.feederGatewayUrl = optionsOrProvider.feederGatewayUrl;
97
98
  this.gatewayUrl = optionsOrProvider.gatewayUrl;
@@ -1,3 +1,2 @@
1
1
  export * from './interface';
2
2
  export * from './default';
3
- export * from './ledger';
@@ -12,4 +12,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./interface"), exports);
14
14
  __exportStar(require("./default"), exports);
15
- __exportStar(require("./ledger"), exports);
@@ -30,7 +30,7 @@ exports.utf8ToArray = exports.sanitizeHex = exports.sanitizeBytes = exports.calc
30
30
  exports.IS_BROWSER = typeof window !== 'undefined';
31
31
  var STRING_ZERO = '0';
32
32
  function arrayBufferToString(array) {
33
- return String.fromCharCode.apply(null, array);
33
+ return new Uint8Array(array).reduce(function (data, byte) { return data + String.fromCharCode(byte); }, '');
34
34
  }
35
35
  exports.arrayBufferToString = arrayBufferToString;
36
36
  function btoaUniversal(b) {
package/index.d.ts CHANGED
@@ -14,6 +14,7 @@ export * as encode from './utils/encode';
14
14
  export * as hash from './utils/hash';
15
15
  export * as json from './utils/json';
16
16
  export * as number from './utils/number';
17
+ export * as transaction from './utils/transaction';
17
18
  export * as stark from './utils/stark';
18
19
  export * as ec from './utils/ellipticCurve';
19
20
  export * as uint256 from './utils/uint256';
package/index.js CHANGED
@@ -49,6 +49,7 @@ exports.typedData =
49
49
  exports.uint256 =
50
50
  exports.ec =
51
51
  exports.stark =
52
+ exports.transaction =
52
53
  exports.number =
53
54
  exports.json =
54
55
  exports.hash =
@@ -71,6 +72,7 @@ exports.encode = __importStar(require('./utils/encode'));
71
72
  exports.hash = __importStar(require('./utils/hash'));
72
73
  exports.json = __importStar(require('./utils/json'));
73
74
  exports.number = __importStar(require('./utils/number'));
75
+ exports.transaction = __importStar(require('./utils/transaction'));
74
76
  exports.stark = __importStar(require('./utils/stark'));
75
77
  exports.ec = __importStar(require('./utils/ellipticCurve'));
76
78
  exports.uint256 = __importStar(require('./utils/uint256'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starknet",
3
- "version": "3.10.0",
3
+ "version": "3.10.3",
4
4
  "description": "JavaScript library for StarkNet",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -61,9 +61,6 @@
61
61
  "typescript": "^4.4.4"
62
62
  },
63
63
  "dependencies": {
64
- "@ledgerhq/hw-app-eth": "^6.26.0",
65
- "@ledgerhq/hw-transport": "^6.24.1",
66
- "@ledgerhq/hw-transport-webhid": "^6.24.1",
67
64
  "axios": "^0.23.0",
68
65
  "bn.js": "^5.2.0",
69
66
  "elliptic": "^6.5.4",
@@ -31,7 +31,7 @@ export declare class Provider implements ProviderInterface {
31
31
  feederGatewayUrl: string;
32
32
  gatewayUrl: string;
33
33
  chainId: StarknetChainId;
34
- constructor(optionsOrProvider?: ProviderOptions | Provider);
34
+ constructor(optionsOrProvider?: ProviderOptions | ProviderInterface);
35
35
  protected static getNetworkFromName(
36
36
  name: NetworkName
37
37
  ): 'https://alpha-mainnet.starknet.io' | 'https://alpha4.starknet.io';
@@ -180,6 +180,7 @@ var hash_1 = require('../utils/hash');
180
180
  var json_1 = require('../utils/json');
181
181
  var number_1 = require('../utils/number');
182
182
  var stark_1 = require('../utils/stark');
183
+ var interface_1 = require('./interface');
183
184
  var utils_1 = require('./utils');
184
185
  function wait(delay) {
185
186
  return new Promise(function (res) {
@@ -205,7 +206,7 @@ var Provider = /** @class */ (function () {
205
206
  optionsOrProvider = { network: 'goerli-alpha' };
206
207
  }
207
208
  var _a;
208
- if (optionsOrProvider instanceof Provider) {
209
+ if (optionsOrProvider instanceof interface_1.ProviderInterface) {
209
210
  this.baseUrl = optionsOrProvider.baseUrl;
210
211
  this.feederGatewayUrl = optionsOrProvider.feederGatewayUrl;
211
212
  this.gatewayUrl = optionsOrProvider.gatewayUrl;
package/signer/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from './interface';
2
2
  export * from './default';
3
- export * from './ledger';
package/signer/index.js CHANGED
@@ -25,4 +25,3 @@ var __exportStar =
25
25
  Object.defineProperty(exports, '__esModule', { value: true });
26
26
  __exportStar(require('./interface'), exports);
27
27
  __exportStar(require('./default'), exports);
28
- __exportStar(require('./ledger'), exports);
@@ -1,7 +1,7 @@
1
1
  import assert from 'minimalistic-assert';
2
2
 
3
3
  import { ZERO } from '../constants';
4
- import { Provider } from '../provider';
4
+ import { Provider, ProviderInterface } from '../provider';
5
5
  import { BlockIdentifier } from '../provider/utils';
6
6
  import { Signer, SignerInterface } from '../signer';
7
7
  import {
@@ -33,9 +33,13 @@ import { AccountInterface } from './interface';
33
33
  export class Account extends Provider implements AccountInterface {
34
34
  public address: string;
35
35
 
36
- private signer: SignerInterface;
36
+ public signer: SignerInterface;
37
37
 
38
- constructor(provider: Provider, address: string, keyPairOrSigner: KeyPair | SignerInterface) {
38
+ constructor(
39
+ provider: ProviderInterface,
40
+ address: string,
41
+ keyPairOrSigner: KeyPair | SignerInterface
42
+ ) {
39
43
  super(provider);
40
44
  this.signer =
41
45
  'getPubKey' in keyPairOrSigner ? keyPairOrSigner : new Signer(keyPairOrSigner as KeyPair);
@@ -250,7 +254,8 @@ export class Account extends Provider implements AccountInterface {
250
254
  }
251
255
 
252
256
  /**
253
- * Verify a signature of a JSON object
257
+ * Verify a signature of a given hash
258
+ * @warning This method is not recommended, use verifyMessage instead
254
259
  *
255
260
  * @param hash - JSON object to be verified
256
261
  * @param signature - signature of the JSON object
@@ -274,8 +279,7 @@ export class Account extends Provider implements AccountInterface {
274
279
  }
275
280
 
276
281
  /**
277
- * Verify a signature of a given hash
278
- * @warning This method is not recommended, use verifyMessage instead
282
+ * Verify a signature of a JSON object
279
283
  *
280
284
  * @param hash - hash to be verified
281
285
  * @param signature - signature of the hash
@@ -1,4 +1,5 @@
1
1
  import { ProviderInterface } from '../provider';
2
+ import { SignerInterface } from '../signer';
2
3
  import {
3
4
  Abi,
4
5
  AddTransactionResponse,
@@ -15,6 +16,8 @@ import { TypedData } from '../utils/typedData/types';
15
16
  export abstract class AccountInterface extends ProviderInterface {
16
17
  public abstract address: string;
17
18
 
19
+ public abstract signer: SignerInterface;
20
+
18
21
  /**
19
22
  * Deploys a given compiled contract (json) to starknet
20
23
  *
@@ -1,7 +1,7 @@
1
1
  import assert from 'minimalistic-assert';
2
2
 
3
- import { Account } from '../account';
4
- import { Provider, defaultProvider } from '../provider';
3
+ import { AccountInterface } from '../account';
4
+ import { ProviderInterface, defaultProvider } from '../provider';
5
5
  import { Abi, CompiledContract, RawCalldata } from '../types';
6
6
  import { BigNumberish } from '../utils/number';
7
7
  import { Contract } from './default';
@@ -11,11 +11,11 @@ export class ContractFactory {
11
11
 
12
12
  compiledContract: CompiledContract;
13
13
 
14
- providerOrAccount: Provider | Account;
14
+ providerOrAccount: ProviderInterface | AccountInterface;
15
15
 
16
16
  constructor(
17
17
  compiledContract: CompiledContract,
18
- providerOrAccount: Provider | Account = defaultProvider,
18
+ providerOrAccount: ProviderInterface | AccountInterface = defaultProvider,
19
19
  abi: Abi = compiledContract.abi // abi can be different from the deployed contract ie for proxy contracts
20
20
  ) {
21
21
  this.abi = abi;
@@ -59,7 +59,7 @@ export class ContractFactory {
59
59
  *
60
60
  * @param providerOrAccount - new Provider or Account to attach to
61
61
  */
62
- connect(providerOrAccount: Provider | Account): ContractFactory {
62
+ connect(providerOrAccount: ProviderInterface | AccountInterface): ContractFactory {
63
63
  this.providerOrAccount = providerOrAccount;
64
64
  return this;
65
65
  }
@@ -349,7 +349,7 @@ export class Contract implements ContractInterface {
349
349
  if (member.type === 'felt') {
350
350
  return acc + 1;
351
351
  }
352
- return acc + this.structMemberNum(member.type);
352
+ return acc + this.calculateStructMembers(member.type);
353
353
  }, 0);
354
354
  }
355
355
 
package/src/index.ts CHANGED
@@ -15,6 +15,7 @@ export * as encode from './utils/encode';
15
15
  export * as hash from './utils/hash';
16
16
  export * as json from './utils/json';
17
17
  export * as number from './utils/number';
18
+ export * as transaction from './utils/transaction';
18
19
  export * as stark from './utils/stark';
19
20
  export * as ec from './utils/ellipticCurve';
20
21
  export * as uint256 from './utils/uint256';
@@ -52,8 +52,10 @@ export class Provider implements ProviderInterface {
52
52
 
53
53
  public chainId: StarknetChainId;
54
54
 
55
- constructor(optionsOrProvider: ProviderOptions | Provider = { network: 'goerli-alpha' }) {
56
- if (optionsOrProvider instanceof Provider) {
55
+ constructor(
56
+ optionsOrProvider: ProviderOptions | ProviderInterface = { network: 'goerli-alpha' }
57
+ ) {
58
+ if (optionsOrProvider instanceof ProviderInterface) {
57
59
  this.baseUrl = optionsOrProvider.baseUrl;
58
60
  this.feederGatewayUrl = optionsOrProvider.feederGatewayUrl;
59
61
  this.gatewayUrl = optionsOrProvider.gatewayUrl;
@@ -1,3 +1,2 @@
1
1
  export * from './interface';
2
2
  export * from './default';
3
- export * from './ledger';
@@ -4,7 +4,7 @@ export const IS_BROWSER = typeof window !== 'undefined';
4
4
  const STRING_ZERO = '0';
5
5
 
6
6
  export function arrayBufferToString(array: ArrayBuffer): string {
7
- return String.fromCharCode.apply(null, array as unknown as number[]);
7
+ return new Uint8Array(array).reduce((data, byte) => data + String.fromCharCode(byte), '');
8
8
  }
9
9
 
10
10
  export function btoaUniversal(b: ArrayBuffer): string {
package/utils/encode.js CHANGED
@@ -50,7 +50,9 @@ exports.utf8ToArray =
50
50
  exports.IS_BROWSER = typeof window !== 'undefined';
51
51
  var STRING_ZERO = '0';
52
52
  function arrayBufferToString(array) {
53
- return String.fromCharCode.apply(null, array);
53
+ return new Uint8Array(array).reduce(function (data, byte) {
54
+ return data + String.fromCharCode(byte);
55
+ }, '');
54
56
  }
55
57
  exports.arrayBufferToString = arrayBufferToString;
56
58
  function btoaUniversal(b) {
@@ -1,6 +1,5 @@
1
-
2
1
  // Install the latest version of starknet with npm install starknet@next and import starknet
3
- import * as starknet from "starknet";
2
+ import * as starknet from 'starknet';
4
3
 
5
4
  // Generate public and private key pair.
6
5
 
@@ -8,7 +7,11 @@ const keyPair = starknet.ec.genKeyPair();
8
7
  const starkKey = starknet.ec.getStarkKey(keyPair);
9
8
  const starkKeyInt = starknet.number.toBN(starknet.encode.removeHexPrefix(starkKey), 16);
10
9
 
11
- const { address: walletAddressLocal } = await provider.deployContract({contract: COMPILED_WALLET_CONTRACT_JSON, constructorCallData: [starkKeyInt], addressSalt: 0});
10
+ const { address: walletAddressLocal } = await provider.deployContract({
11
+ contract: COMPILED_WALLET_CONTRACT_JSON,
12
+ constructorCallData: [starkKeyInt],
13
+ addressSalt: 0,
14
+ });
12
15
 
13
16
  walletAddress = walletAddressLocal;
14
17
 
@@ -28,7 +31,7 @@ const balanceBeforeTransfer = await erc20.call('balance_of', {
28
31
  user: walletAddress,
29
32
  }).res;
30
33
 
31
- console.log(number.toBN(res).toString())
34
+ console.log(number.toBN(res).toString());
32
35
 
33
36
  const { nonce } = await wallet.call('get_nonce');
34
37
  const msgHash = encode.addHexPrefix(
@@ -59,4 +62,4 @@ const balanceAfterTransfer = await erc20.call('balance_of', {
59
62
  user: walletAddress,
60
63
  }).res;
61
64
 
62
- console.log('Balance after transfer', balanceAfterTransfer)
65
+ console.log('Balance after transfer', balanceAfterTransfer);