starknet 3.12.2 → 3.13.1

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 (78) hide show
  1. package/.github/workflows/pr.yml +3 -0
  2. package/.github/workflows/release.yml +4 -0
  3. package/CHANGELOG.md +38 -0
  4. package/__mocks__/Account.json +25468 -0
  5. package/__tests__/account.test.ts +102 -65
  6. package/__tests__/contract.test.ts +23 -65
  7. package/__tests__/fixtures.ts +21 -1
  8. package/__tests__/provider.test.ts +20 -1
  9. package/account/default.d.ts +2 -9
  10. package/account/index.js +10 -6
  11. package/account/interface.d.ts +5 -3
  12. package/contract/default.d.ts +1 -1
  13. package/contract/default.js +20 -21
  14. package/contract/index.js +10 -6
  15. package/dist/account/default.d.ts +2 -6
  16. package/dist/account/index.js +5 -1
  17. package/dist/account/interface.d.ts +3 -3
  18. package/dist/contract/default.d.ts +1 -1
  19. package/dist/contract/default.js +18 -18
  20. package/dist/contract/index.js +5 -1
  21. package/dist/index.js +5 -1
  22. package/dist/provider/default.d.ts +3 -3
  23. package/dist/provider/default.js +10 -8
  24. package/dist/provider/index.js +5 -1
  25. package/dist/provider/interface.d.ts +9 -1
  26. package/dist/provider/utils.js +5 -5
  27. package/dist/signer/index.js +5 -1
  28. package/dist/types/account.d.ts +6 -0
  29. package/dist/types/api.d.ts +1 -1
  30. package/dist/types/index.d.ts +1 -0
  31. package/dist/types/index.js +6 -1
  32. package/dist/utils/ellipticCurve.js +1 -1
  33. package/dist/utils/encode.js +1 -1
  34. package/dist/utils/hash.js +1 -1
  35. package/dist/utils/number.js +8 -4
  36. package/dist/utils/shortString.js +2 -2
  37. package/dist/utils/typedData/index.d.ts +2 -36
  38. package/dist/utils/typedData/index.js +8 -4
  39. package/dist/utils/typedData/types.d.ts +15 -70
  40. package/dist/utils/typedData/types.js +0 -45
  41. package/dist/utils/typedData/utils.d.ts +2 -18
  42. package/dist/utils/typedData/utils.js +4 -3
  43. package/index.js +10 -6
  44. package/package.json +30 -29
  45. package/provider/default.d.ts +3 -3
  46. package/provider/default.js +11 -12
  47. package/provider/index.js +10 -6
  48. package/provider/interface.d.ts +9 -1
  49. package/provider/utils.js +5 -5
  50. package/signer/index.js +10 -6
  51. package/src/account/default.ts +2 -6
  52. package/src/account/interface.ts +5 -3
  53. package/src/provider/default.ts +6 -5
  54. package/src/provider/interface.ts +9 -1
  55. package/src/types/account.ts +7 -0
  56. package/src/types/api.ts +1 -1
  57. package/src/types/index.ts +1 -0
  58. package/src/utils/typedData/types.ts +15 -68
  59. package/src/utils/typedData/utils.ts +7 -4
  60. package/types/account.d.ts +6 -0
  61. package/types/api.d.ts +1 -1
  62. package/types/index.d.ts +1 -0
  63. package/types/index.js +11 -6
  64. package/utils/ellipticCurve.js +1 -1
  65. package/utils/encode.js +1 -1
  66. package/utils/hash.js +1 -1
  67. package/utils/number.js +13 -9
  68. package/utils/shortString.js +2 -2
  69. package/utils/typedData/index.d.ts +2 -46
  70. package/utils/typedData/index.js +15 -13
  71. package/utils/typedData/types.d.ts +15 -91
  72. package/utils/typedData/types.js +0 -55
  73. package/utils/typedData/utils.d.ts +2 -21
  74. package/utils/typedData/utils.js +4 -3
  75. package/www/docs/API/provider.md +2 -2
  76. package/www/guides/account.md +21 -7
  77. package/www/guides/erc20.md +15 -27
  78. package/__tests__/accountContract.test.ts +0 -110
@@ -2,7 +2,6 @@ import assert from 'minimalistic-assert';
2
2
 
3
3
  import { ZERO } from '../constants';
4
4
  import { Provider, ProviderInterface } from '../provider';
5
- import { BlockIdentifier } from '../provider/utils';
6
5
  import { Signer, SignerInterface } from '../signer';
7
6
  import {
8
7
  Abi,
@@ -15,7 +14,7 @@ import {
15
14
  Signature,
16
15
  Transaction,
17
16
  } from '../types';
18
- import { EstimateFee } from '../types/account';
17
+ import { EstimateFee, EstimateFeeDetails } from '../types/account';
19
18
  import { sign } from '../utils/ellipticCurve';
20
19
  import {
21
20
  computeHashOnElements,
@@ -56,10 +55,7 @@ export class Account extends Provider implements AccountInterface {
56
55
 
57
56
  public async estimateFee(
58
57
  calls: Call | Call[],
59
- {
60
- nonce: providedNonce,
61
- blockIdentifier = 'pending',
62
- }: { nonce?: BigNumberish; blockIdentifier?: BlockIdentifier } = {}
58
+ { nonce: providedNonce, blockIdentifier = 'pending' }: EstimateFeeDetails = {}
63
59
  ): Promise<EstimateFee> {
64
60
  const transactions = Array.isArray(calls) ? calls : [calls];
65
61
  const nonce = providedNonce ?? (await this.getNonce());
@@ -5,11 +5,10 @@ import {
5
5
  AddTransactionResponse,
6
6
  Call,
7
7
  DeployContractPayload,
8
- Invocation,
9
8
  InvocationsDetails,
10
9
  Signature,
11
10
  } from '../types';
12
- import { EstimateFee } from '../types/account';
11
+ import { EstimateFee, EstimateFeeDetails } from '../types/account';
13
12
  import { BigNumberish } from '../utils/number';
14
13
  import { TypedData } from '../utils/typedData/types';
15
14
 
@@ -44,7 +43,10 @@ export abstract class AccountInterface extends ProviderInterface {
44
43
  *
45
44
  * @returns response from addTransaction
46
45
  */
47
- public abstract estimateFee(invocation: Invocation): Promise<EstimateFee>;
46
+ public abstract estimateFee(
47
+ calls: Call | Call[],
48
+ estimateFeeDetails?: EstimateFeeDetails
49
+ ): Promise<EstimateFee>;
48
50
 
49
51
  /**
50
52
  * Invoke execute function in account contract
@@ -31,7 +31,9 @@ type NetworkName = 'mainnet-alpha' | 'goerli-alpha';
31
31
  type ProviderOptions = { network: NetworkName } | { baseUrl: string };
32
32
 
33
33
  function wait(delay: number) {
34
- return new Promise((res) => setTimeout(res, delay));
34
+ return new Promise((res) => {
35
+ setTimeout(res, delay);
36
+ });
35
37
  }
36
38
 
37
39
  function isEmptyQueryObject(obj?: Record<any, any>): obj is undefined {
@@ -250,7 +252,7 @@ export class Provider implements ProviderInterface {
250
252
  */
251
253
  public async getStorageAt(
252
254
  contractAddress: string,
253
- key: number,
255
+ key: BigNumberish,
254
256
  blockIdentifier: BlockIdentifier = 'pending'
255
257
  ): Promise<object> {
256
258
  return this.fetchEndpoint('get_storage_at', { blockIdentifier, contractAddress, key });
@@ -270,14 +272,13 @@ export class Provider implements ProviderInterface {
270
272
  }
271
273
 
272
274
  /**
273
- * Gets the transaction receipt from a tx hash or tx id.
275
+ * Gets the transaction receipt from a tx hash.
274
276
  *
275
- * [Reference] (https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L104-L111)
277
+ * [Reference] (https://github.com/starkware-libs/cairo-lang/blob/167b28bcd940fd25ea3816204fa882a0b0a49603/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L183)
276
278
  *
277
279
  * @param txHash
278
280
  * @returns the transaction receipt object
279
281
  */
280
-
281
282
  public async getTransactionReceipt(txHash: BigNumberish): Promise<TransactionReceiptResponse> {
282
283
  const txHashHex = toHex(toBN(txHash));
283
284
  return this.fetchEndpoint('get_transaction_receipt', { transactionHash: txHashHex });
@@ -85,7 +85,7 @@ export abstract class ProviderInterface {
85
85
  */
86
86
  public abstract getStorageAt(
87
87
  contractAddress: string,
88
- key: number,
88
+ key: BigNumberish,
89
89
  blockIdentifier?: BlockIdentifier
90
90
  ): Promise<object>;
91
91
 
@@ -109,6 +109,14 @@ export abstract class ProviderInterface {
109
109
  */
110
110
  public abstract getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
111
111
 
112
+ /**
113
+ * Gets the transaction receipt from a tx hash.
114
+ *
115
+ * [Reference] (https://github.com/starkware-libs/cairo-lang/blob/167b28bcd940fd25ea3816204fa882a0b0a49603/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L183)
116
+ *
117
+ * @param txHash
118
+ * @returns the transaction receipt object
119
+ */
112
120
  public abstract getTransactionReceipt(txHash: BigNumberish): Promise<TransactionReceiptResponse>;
113
121
 
114
122
  /**
@@ -1,7 +1,14 @@
1
1
  import BN from 'bn.js';
2
2
 
3
+ import { BlockIdentifier } from '../provider/utils';
4
+ import { BigNumberish } from '../utils/number';
3
5
  import { EstimateFeeResponse } from './api';
4
6
 
5
7
  export interface EstimateFee extends EstimateFeeResponse {
6
8
  suggestedMaxFee: BN;
7
9
  }
10
+
11
+ export interface EstimateFeeDetails {
12
+ nonce?: BigNumberish;
13
+ blockIdentifier?: BlockIdentifier;
14
+ }
package/src/types/api.ts CHANGED
@@ -55,7 +55,7 @@ export type Endpoints = {
55
55
  get_storage_at: {
56
56
  QUERY: {
57
57
  contractAddress: string;
58
- key: number;
58
+ key: BigNumberish;
59
59
  blockIdentifier: BlockIdentifier;
60
60
  };
61
61
  REQUEST: never;
@@ -2,3 +2,4 @@ export * from './lib';
2
2
  export * from './api';
3
3
  export * from './signer';
4
4
  export * from './contract';
5
+ export * from './account';
@@ -1,82 +1,29 @@
1
- import {
2
- Infer,
3
- array,
4
- intersection,
5
- number,
6
- object,
7
- optional,
8
- record,
9
- refine,
10
- string,
11
- type as t,
12
- union,
13
- } from 'superstruct';
14
-
15
- export const ATOMIC_TYPES = ['felt', 'felt*'];
16
-
17
- // Source: https://github.com/Mrtenz/eip-712/blob/master/src/eip-712.ts
18
- // and modified to support starknet types
19
-
20
- /**
21
- * Checks if a type is valid with the given `typedData`. The following types are valid:
22
- * - Atomic types: felt, felt*
23
- * - Reference types: struct type (e.g. SomeStruct)
24
- *
25
- * @param {Record<string, unknown>} types
26
- * @param {string} type
27
- * @return {boolean}
28
- */
29
- export const isValidType = (types: Record<string, unknown>, type: string): boolean => {
30
- if (ATOMIC_TYPES.includes(type as string)) {
31
- return true;
32
- }
33
-
34
- if (types[type]) {
35
- return true;
36
- }
37
-
38
- return false;
39
- };
40
-
41
- const TYPE = refine(string(), 'Type', (type, context) => {
42
- return isValidType(context.branch[0].types, type);
43
- });
44
-
45
- export const STARKNET_TYPE = object({
46
- name: string(),
47
- type: TYPE,
48
- });
49
-
50
1
  /**
51
2
  * A single type, as part of a struct. The `type` field can be any of the EIP-712 supported types.
52
3
  *
53
4
  * Note that the `uint` and `int` aliases like in Solidity, and fixed point numbers are not supported by the EIP-712
54
5
  * standard.
55
6
  */
56
- export type StarkNetType = Infer<typeof STARKNET_TYPE>;
57
-
58
- export const STARKNET_DOMAIN_TYPE = object({
59
- name: optional(string()),
60
- version: optional(string()),
61
- chainId: optional(union([string(), number()])),
62
- });
7
+ export interface StarkNetType {
8
+ name: string;
9
+ type: 'felt' | 'felt*' | string;
10
+ }
63
11
 
64
12
  /**
65
13
  * The EIP712 domain struct. Any of these fields are optional, but it must contain at least one field.
66
14
  */
67
- export type StarkNetDomain = Infer<typeof STARKNET_DOMAIN_TYPE>;
68
-
69
- export const STARKNET_TYPED_DATA_TYPE = object({
70
- types: intersection([
71
- t({ StarkNetDomain: array(STARKNET_TYPE) }),
72
- record(string(), array(STARKNET_TYPE)),
73
- ]),
74
- primaryType: string(),
75
- domain: STARKNET_DOMAIN_TYPE,
76
- message: object(),
77
- });
15
+ export interface StarkNetDomain extends Record<string, unknown> {
16
+ name?: string;
17
+ version?: string;
18
+ chainId?: string | number;
19
+ }
78
20
 
79
21
  /**
80
22
  * The complete typed data, with all the structs, domain data, primary type of the message, and the message itself.
81
23
  */
82
- export type TypedData = Infer<typeof STARKNET_TYPED_DATA_TYPE>;
24
+ export interface TypedData {
25
+ types: Record<string, StarkNetType[]>;
26
+ primaryType: string;
27
+ domain: StarkNetDomain;
28
+ message: Record<string, unknown>;
29
+ }
@@ -1,6 +1,4 @@
1
- import { is } from 'superstruct';
2
-
3
- import { STARKNET_TYPED_DATA_TYPE, TypedData } from './types';
1
+ import { TypedData } from './types';
4
2
 
5
3
  /**
6
4
  * Validates that `data` matches the EIP-712 JSON schema.
@@ -9,5 +7,10 @@ import { STARKNET_TYPED_DATA_TYPE, TypedData } from './types';
9
7
  * @return {boolean}
10
8
  */
11
9
  export const validateTypedData = (data: unknown): data is TypedData => {
12
- return is(data, STARKNET_TYPED_DATA_TYPE);
10
+ const typedData = data as TypedData;
11
+
12
+ // Validate that the data matches the EIP-712 JSON schema
13
+ const valid = Boolean(typedData.types && typedData.primaryType && typedData.message);
14
+
15
+ return valid;
13
16
  };
@@ -1,6 +1,12 @@
1
1
  import BN from 'bn.js';
2
2
 
3
+ import { BlockIdentifier } from '../provider/utils';
4
+ import { BigNumberish } from '../utils/number';
3
5
  import { EstimateFeeResponse } from './api';
4
6
  export interface EstimateFee extends EstimateFeeResponse {
5
7
  suggestedMaxFee: BN;
6
8
  }
9
+ export interface EstimateFeeDetails {
10
+ nonce?: BigNumberish;
11
+ blockIdentifier?: BlockIdentifier;
12
+ }
package/types/api.d.ts CHANGED
@@ -54,7 +54,7 @@ export declare type Endpoints = {
54
54
  get_storage_at: {
55
55
  QUERY: {
56
56
  contractAddress: string;
57
- key: number;
57
+ key: BigNumberish;
58
58
  blockIdentifier: BlockIdentifier;
59
59
  };
60
60
  REQUEST: never;
package/types/index.d.ts CHANGED
@@ -2,3 +2,4 @@ export * from './lib';
2
2
  export * from './api';
3
3
  export * from './signer';
4
4
  export * from './contract';
5
+ export * from './account';
package/types/index.js CHANGED
@@ -4,12 +4,16 @@ var __createBinding =
4
4
  (Object.create
5
5
  ? function (o, m, k, k2) {
6
6
  if (k2 === undefined) k2 = k;
7
- Object.defineProperty(o, k2, {
8
- enumerable: true,
9
- get: function () {
10
- return m[k];
11
- },
12
- });
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = {
10
+ enumerable: true,
11
+ get: function () {
12
+ return m[k];
13
+ },
14
+ };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
13
17
  }
14
18
  : function (o, m, k, k2) {
15
19
  if (k2 === undefined) k2 = k;
@@ -27,3 +31,4 @@ __exportStar(require('./lib'), exports);
27
31
  __exportStar(require('./api'), exports);
28
32
  __exportStar(require('./signer'), exports);
29
33
  __exportStar(require('./contract'), exports);
34
+ __exportStar(require('./account'), exports);
@@ -68,7 +68,7 @@ function fixMessage(msg) {
68
68
  }
69
69
  (0, minimalistic_assert_1.default)(pureHex.length === 63);
70
70
  // In this case delta will be 4 so we perform a shift-left of 4 bits by adding a ZERO_BN.
71
- return pureHex + '0';
71
+ return ''.concat(pureHex, '0');
72
72
  }
73
73
  exports.genKeyPair = exports.ec.genKeyPair.bind(exports.ec);
74
74
  function getKeyPair(pk) {
package/utils/encode.js CHANGED
@@ -76,7 +76,7 @@ function removeHexPrefix(hex) {
76
76
  }
77
77
  exports.removeHexPrefix = removeHexPrefix;
78
78
  function addHexPrefix(hex) {
79
- return '0x' + removeHexPrefix(hex);
79
+ return '0x'.concat(removeHexPrefix(hex));
80
80
  }
81
81
  exports.addHexPrefix = addHexPrefix;
82
82
  function padString(str, length, left, padding) {
package/utils/hash.js CHANGED
@@ -97,7 +97,7 @@ function pedersen(input) {
97
97
  (0, minimalistic_assert_1.default)(
98
98
  x.gte(constants_1.ZERO) &&
99
99
  x.lt((0, number_1.toBN)((0, encode_1.addHexPrefix)(constants_1.FIELD_PRIME))),
100
- 'Invalid input: ' + input[i]
100
+ 'Invalid input: '.concat(input[i])
101
101
  );
102
102
  for (var j = 0; j < 252; j += 1) {
103
103
  var pt = constantPoints[2 + i * 252 + j];
package/utils/number.js CHANGED
@@ -4,12 +4,16 @@ var __createBinding =
4
4
  (Object.create
5
5
  ? function (o, m, k, k2) {
6
6
  if (k2 === undefined) k2 = k;
7
- Object.defineProperty(o, k2, {
8
- enumerable: true,
9
- get: function () {
10
- return m[k];
11
- },
12
- });
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = {
10
+ enumerable: true,
11
+ get: function () {
12
+ return m[k];
13
+ },
14
+ };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
13
17
  }
14
18
  : function (o, m, k, k2) {
15
19
  if (k2 === undefined) k2 = k;
@@ -68,7 +72,7 @@ function toHex(number) {
68
72
  }
69
73
  exports.toHex = toHex;
70
74
  function hexToDecimalString(hex) {
71
- return toBN('0x' + hex.replace(/^0x/, '')).toString();
75
+ return toBN('0x'.concat(hex.replace(/^0x/, ''))).toString();
72
76
  }
73
77
  exports.hexToDecimalString = hexToDecimalString;
74
78
  function toFelt(num) {
@@ -88,11 +92,11 @@ function assertInRange(input, lowerBound, upperBound, inputName) {
88
92
  if (inputName === void 0) {
89
93
  inputName = '';
90
94
  }
91
- var messageSuffix = inputName === '' ? 'invalid length' : 'invalid ' + inputName + ' length';
95
+ var messageSuffix = inputName === '' ? 'invalid length' : 'invalid '.concat(inputName, ' length');
92
96
  var inputBn = toBN(input);
93
97
  (0, minimalistic_assert_1.default)(
94
98
  inputBn.gte(toBN(lowerBound)) && inputBn.lt(toBN(upperBound)),
95
- 'Message not signable, ' + messageSuffix + '.'
99
+ 'Message not signable, '.concat(messageSuffix, '.')
96
100
  );
97
101
  }
98
102
  exports.assertInRange = assertInRange;
@@ -17,8 +17,8 @@ function isShortString(str) {
17
17
  }
18
18
  exports.isShortString = isShortString;
19
19
  function encodeShortString(str) {
20
- if (!isASCII(str)) throw new Error(str + ' is not an ASCII string');
21
- if (!isShortString(str)) throw new Error(str + ' is too long');
20
+ if (!isASCII(str)) throw new Error(''.concat(str, ' is not an ASCII string'));
21
+ if (!isShortString(str)) throw new Error(''.concat(str, ' is too long'));
22
22
  return (0, encode_1.addHexPrefix)(
23
23
  str.replace(/./g, function (char) {
24
24
  return char.charCodeAt(0).toString(16);
@@ -39,29 +39,7 @@ export declare const getTypeHash: (typedData: TypedData, type: string) => string
39
39
  * @param {string} type
40
40
  * @param {Record<string, any>} data
41
41
  */
42
- export declare const encodeData: <
43
- T extends {
44
- types: {
45
- StarkNetDomain: {
46
- type: string;
47
- name: string;
48
- }[];
49
- } & Record<
50
- string,
51
- {
52
- type: string;
53
- name: string;
54
- }[]
55
- >;
56
- primaryType: string;
57
- domain: {
58
- version?: string | undefined;
59
- chainId?: string | number | undefined;
60
- name?: string | undefined;
61
- };
62
- message: Record<string, unknown>;
63
- }
64
- >(
42
+ export declare const encodeData: <T extends TypedData>(
65
43
  typedData: T,
66
44
  type: string,
67
45
  data: T['message']
@@ -75,29 +53,7 @@ export declare const encodeData: <
75
53
  * @param {Record<string, any>} data
76
54
  * @return {Buffer}
77
55
  */
78
- export declare const getStructHash: <
79
- T extends {
80
- types: {
81
- StarkNetDomain: {
82
- type: string;
83
- name: string;
84
- }[];
85
- } & Record<
86
- string,
87
- {
88
- type: string;
89
- name: string;
90
- }[]
91
- >;
92
- primaryType: string;
93
- domain: {
94
- version?: string | undefined;
95
- chainId?: string | number | undefined;
96
- name?: string | undefined;
97
- };
98
- message: Record<string, unknown>;
99
- }
100
- >(
56
+ export declare const getStructHash: <T extends TypedData>(
101
57
  typedData: T,
102
58
  type: string,
103
59
  data: T['message']
@@ -4,12 +4,16 @@ var __createBinding =
4
4
  (Object.create
5
5
  ? function (o, m, k, k2) {
6
6
  if (k2 === undefined) k2 = k;
7
- Object.defineProperty(o, k2, {
8
- enumerable: true,
9
- get: function () {
10
- return m[k];
11
- },
12
- });
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = {
10
+ enumerable: true,
11
+ get: function () {
12
+ return m[k];
13
+ },
14
+ };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
13
17
  }
14
18
  : function (o, m, k, k2) {
15
19
  if (k2 === undefined) k2 = k;
@@ -76,7 +80,7 @@ function getHex(value) {
76
80
  if (typeof value === 'string') {
77
81
  return (0, number_1.toHex)((0, number_1.toBN)((0, shortString_1.encodeShortString)(value)));
78
82
  }
79
- throw new Error('Invalid BigNumberish: ' + value);
83
+ throw new Error('Invalid BigNumberish: '.concat(value));
80
84
  }
81
85
  }
82
86
  /**
@@ -135,12 +139,10 @@ var encodeType = function (typedData, type) {
135
139
  var types = __spreadArray([primary], __read(dependencies.sort()), false);
136
140
  return types
137
141
  .map(function (dependency) {
138
- return (
139
- dependency +
140
- '(' +
142
+ return ''.concat(dependency, '(').concat(
141
143
  typedData.types[dependency].map(function (t) {
142
- return t.name + ':' + t.type;
143
- }) +
144
+ return ''.concat(t.name, ':').concat(t.type);
145
+ }),
144
146
  ')'
145
147
  );
146
148
  })
@@ -193,7 +195,7 @@ var encodeData = function (typedData, type, data) {
193
195
  ts = _b[0],
194
196
  vs = _b[1];
195
197
  if (data[field.name] === undefined || data[field.name] === null) {
196
- throw new Error("Cannot encode data: missing data for '" + field.name + "'");
198
+ throw new Error("Cannot encode data: missing data for '".concat(field.name, "'"));
197
199
  }
198
200
  var value = data[field.name];
199
201
  var _c = __read(encodeValue(typedData, field.type, value), 2),
@@ -1,103 +1,27 @@
1
- import { Infer } from 'superstruct';
2
- export declare const ATOMIC_TYPES: string[];
3
- /**
4
- * Checks if a type is valid with the given `typedData`. The following types are valid:
5
- * - Atomic types: felt, felt*
6
- * - Reference types: struct type (e.g. SomeStruct)
7
- *
8
- * @param {Record<string, unknown>} types
9
- * @param {string} type
10
- * @return {boolean}
11
- */
12
- export declare const isValidType: (types: Record<string, unknown>, type: string) => boolean;
13
- export declare const STARKNET_TYPE: import('superstruct').Struct<
14
- {
15
- type: string;
16
- name: string;
17
- },
18
- {
19
- name: import('superstruct').Struct<string, null>;
20
- type: import('superstruct').Struct<string, null>;
21
- }
22
- >;
23
1
  /**
24
2
  * A single type, as part of a struct. The `type` field can be any of the EIP-712 supported types.
25
3
  *
26
4
  * Note that the `uint` and `int` aliases like in Solidity, and fixed point numbers are not supported by the EIP-712
27
5
  * standard.
28
6
  */
29
- export declare type StarkNetType = Infer<typeof STARKNET_TYPE>;
30
- export declare const STARKNET_DOMAIN_TYPE: import('superstruct').Struct<
31
- {
32
- version?: string | undefined;
33
- chainId?: string | number | undefined;
34
- name?: string | undefined;
35
- },
36
- {
37
- name: import('superstruct').Struct<string | undefined, null>;
38
- version: import('superstruct').Struct<string | undefined, null>;
39
- chainId: import('superstruct').Struct<string | number | undefined, null>;
40
- }
41
- >;
7
+ export interface StarkNetType {
8
+ name: string;
9
+ type: 'felt' | 'felt*' | string;
10
+ }
42
11
  /**
43
12
  * The EIP712 domain struct. Any of these fields are optional, but it must contain at least one field.
44
13
  */
45
- export declare type StarkNetDomain = Infer<typeof STARKNET_DOMAIN_TYPE>;
46
- export declare const STARKNET_TYPED_DATA_TYPE: import('superstruct').Struct<
47
- {
48
- types: {
49
- StarkNetDomain: {
50
- type: string;
51
- name: string;
52
- }[];
53
- } & Record<
54
- string,
55
- {
56
- type: string;
57
- name: string;
58
- }[]
59
- >;
60
- primaryType: string;
61
- domain: {
62
- version?: string | undefined;
63
- chainId?: string | number | undefined;
64
- name?: string | undefined;
65
- };
66
- message: Record<string, unknown>;
67
- },
68
- {
69
- types: import('superstruct').Struct<
70
- {
71
- StarkNetDomain: {
72
- type: string;
73
- name: string;
74
- }[];
75
- } & Record<
76
- string,
77
- {
78
- type: string;
79
- name: string;
80
- }[]
81
- >,
82
- null
83
- >;
84
- primaryType: import('superstruct').Struct<string, null>;
85
- domain: import('superstruct').Struct<
86
- {
87
- version?: string | undefined;
88
- chainId?: string | number | undefined;
89
- name?: string | undefined;
90
- },
91
- {
92
- name: import('superstruct').Struct<string | undefined, null>;
93
- version: import('superstruct').Struct<string | undefined, null>;
94
- chainId: import('superstruct').Struct<string | number | undefined, null>;
95
- }
96
- >;
97
- message: import('superstruct').Struct<Record<string, unknown>, null>;
98
- }
99
- >;
14
+ export interface StarkNetDomain extends Record<string, unknown> {
15
+ name?: string;
16
+ version?: string;
17
+ chainId?: string | number;
18
+ }
100
19
  /**
101
20
  * The complete typed data, with all the structs, domain data, primary type of the message, and the message itself.
102
21
  */
103
- export declare type TypedData = Infer<typeof STARKNET_TYPED_DATA_TYPE>;
22
+ export interface TypedData {
23
+ types: Record<string, StarkNetType[]>;
24
+ primaryType: string;
25
+ domain: StarkNetDomain;
26
+ message: Record<string, unknown>;
27
+ }