starknet 3.12.1 → 3.13.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 (65) hide show
  1. package/.github/workflows/pr.yml +3 -0
  2. package/.github/workflows/release.yml +4 -0
  3. package/CHANGELOG.md +39 -0
  4. package/README.md +2 -0
  5. package/__mocks__/Account.json +25468 -0
  6. package/__tests__/account.test.ts +102 -65
  7. package/__tests__/contract.test.ts +23 -65
  8. package/__tests__/fixtures.ts +21 -1
  9. package/__tests__/jest.setup.ts +23 -4
  10. package/__tests__/provider.test.ts +20 -1
  11. package/account/index.js +10 -6
  12. package/contract/default.js +20 -21
  13. package/contract/index.js +10 -6
  14. package/dist/account/index.js +5 -1
  15. package/dist/contract/default.js +18 -18
  16. package/dist/contract/index.js +5 -1
  17. package/dist/index.js +5 -1
  18. package/dist/provider/default.d.ts +1 -1
  19. package/dist/provider/default.js +35 -49
  20. package/dist/provider/index.js +5 -1
  21. package/dist/provider/interface.d.ts +1 -1
  22. package/dist/provider/utils.js +5 -5
  23. package/dist/signer/index.js +5 -1
  24. package/dist/types/api.d.ts +1 -1
  25. package/dist/types/index.js +5 -1
  26. package/dist/utils/ellipticCurve.js +1 -1
  27. package/dist/utils/encode.js +1 -1
  28. package/dist/utils/hash.js +1 -1
  29. package/dist/utils/number.js +8 -4
  30. package/dist/utils/shortString.js +2 -2
  31. package/dist/utils/typedData/index.d.ts +2 -36
  32. package/dist/utils/typedData/index.js +8 -4
  33. package/dist/utils/typedData/types.d.ts +15 -70
  34. package/dist/utils/typedData/types.js +0 -45
  35. package/dist/utils/typedData/utils.d.ts +2 -18
  36. package/dist/utils/typedData/utils.js +4 -3
  37. package/index.js +10 -6
  38. package/package.json +33 -31
  39. package/provider/default.d.ts +1 -1
  40. package/provider/default.js +44 -65
  41. package/provider/index.js +10 -6
  42. package/provider/interface.d.ts +1 -1
  43. package/provider/utils.js +5 -5
  44. package/signer/index.js +10 -6
  45. package/src/provider/default.ts +24 -31
  46. package/src/provider/interface.ts +1 -1
  47. package/src/types/api.ts +1 -1
  48. package/src/utils/typedData/types.ts +15 -68
  49. package/src/utils/typedData/utils.ts +7 -4
  50. package/types/api.d.ts +1 -1
  51. package/types/index.js +10 -6
  52. package/utils/ellipticCurve.js +1 -1
  53. package/utils/encode.js +1 -1
  54. package/utils/hash.js +1 -1
  55. package/utils/number.js +13 -9
  56. package/utils/shortString.js +2 -2
  57. package/utils/typedData/index.d.ts +2 -46
  58. package/utils/typedData/index.js +15 -13
  59. package/utils/typedData/types.d.ts +15 -91
  60. package/utils/typedData/types.js +0 -55
  61. package/utils/typedData/utils.d.ts +2 -21
  62. package/utils/typedData/utils.js +4 -3
  63. package/www/guides/account.md +21 -7
  64. package/www/guides/erc20.md +15 -27
  65. package/__tests__/accountContract.test.ts +0 -110
@@ -1,4 +1,4 @@
1
- import axios, { AxiosRequestHeaders } from 'axios';
1
+ import fetch from 'cross-fetch';
2
2
  import urljoin from 'url-join';
3
3
 
4
4
  import { StarknetChainId } from '../constants';
@@ -10,7 +10,6 @@ import {
10
10
  CompiledContract,
11
11
  DeployContractPayload,
12
12
  Endpoints,
13
- EstimateFeeResponse,
14
13
  GetBlockResponse,
15
14
  GetCodeResponse,
16
15
  GetContractAddressesResponse,
@@ -32,7 +31,9 @@ type NetworkName = 'mainnet-alpha' | 'goerli-alpha';
32
31
  type ProviderOptions = { network: NetworkName } | { baseUrl: string };
33
32
 
34
33
  function wait(delay: number) {
35
- return new Promise((res) => setTimeout(res, delay));
34
+ return new Promise((res) => {
35
+ setTimeout(res, delay);
36
+ });
36
37
  }
37
38
 
38
39
  function isEmptyQueryObject(obj?: Record<any, any>): obj is undefined {
@@ -125,7 +126,7 @@ export class Provider implements ProviderInterface {
125
126
  return `?${queryString}`;
126
127
  }
127
128
 
128
- private getHeaders(method: 'POST' | 'GET'): AxiosRequestHeaders | undefined {
129
+ private getHeaders(method: 'POST' | 'GET'): Record<string, string> | undefined {
129
130
  if (method === 'POST') {
130
131
  return {
131
132
  'Content-Type': 'application/json',
@@ -150,33 +151,25 @@ export class Provider implements ProviderInterface {
150
151
  const method = this.getFetchMethod(endpoint);
151
152
  const queryString = this.getQueryString(query);
152
153
  const headers = this.getHeaders(method);
153
-
154
- try {
155
- const { data } = await axios.request<Endpoints[T]['RESPONSE']>({
156
- method,
157
- transformResponse:
158
- endpoint === 'estimate_fee'
159
- ? (res): EstimateFeeResponse => {
160
- return parse(res, (_, v) => {
161
- if (v && typeof v === 'bigint') {
162
- return toBN(v.toString());
163
- }
164
- return v;
165
- });
166
- }
167
- : axios.defaults.transformResponse,
168
- url: urljoin(baseUrl, endpoint, queryString),
169
- data: stringify(request),
170
- headers,
154
+ const url = urljoin(baseUrl, endpoint, queryString);
155
+
156
+ return fetch(url, {
157
+ method,
158
+ body: stringify(request),
159
+ headers,
160
+ })
161
+ .then((res) => res.text())
162
+ .then((res) => {
163
+ if (endpoint === 'estimate_fee') {
164
+ return parse(res, (_, v) => {
165
+ if (v && typeof v === 'bigint') {
166
+ return toBN(v.toString());
167
+ }
168
+ return v;
169
+ });
170
+ }
171
+ return parse(res) as Endpoints[T]['RESPONSE'];
171
172
  });
172
- return data;
173
- } catch (error: any) {
174
- const data = error?.response?.data;
175
- if (data?.message) {
176
- throw new Error(`${data.code}: ${data.message}`);
177
- }
178
- throw error;
179
- }
180
173
  }
181
174
 
182
175
  /**
@@ -259,7 +252,7 @@ export class Provider implements ProviderInterface {
259
252
  */
260
253
  public async getStorageAt(
261
254
  contractAddress: string,
262
- key: number,
255
+ key: BigNumberish,
263
256
  blockIdentifier: BlockIdentifier = 'pending'
264
257
  ): Promise<object> {
265
258
  return this.fetchEndpoint('get_storage_at', { blockIdentifier, contractAddress, key });
@@ -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
 
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;
@@ -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
  };
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.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 +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
+ }
@@ -1,57 +1,2 @@
1
1
  'use strict';
2
2
  Object.defineProperty(exports, '__esModule', { value: true });
3
- exports.STARKNET_TYPED_DATA_TYPE =
4
- exports.STARKNET_DOMAIN_TYPE =
5
- exports.STARKNET_TYPE =
6
- exports.isValidType =
7
- exports.ATOMIC_TYPES =
8
- void 0;
9
- var superstruct_1 = require('superstruct');
10
- exports.ATOMIC_TYPES = ['felt', 'felt*'];
11
- // Source: https://github.com/Mrtenz/eip-712/blob/master/src/eip-712.ts
12
- // and modified to support starknet types
13
- /**
14
- * Checks if a type is valid with the given `typedData`. The following types are valid:
15
- * - Atomic types: felt, felt*
16
- * - Reference types: struct type (e.g. SomeStruct)
17
- *
18
- * @param {Record<string, unknown>} types
19
- * @param {string} type
20
- * @return {boolean}
21
- */
22
- var isValidType = function (types, type) {
23
- if (exports.ATOMIC_TYPES.includes(type)) {
24
- return true;
25
- }
26
- if (types[type]) {
27
- return true;
28
- }
29
- return false;
30
- };
31
- exports.isValidType = isValidType;
32
- var TYPE = (0, superstruct_1.refine)((0, superstruct_1.string)(), 'Type', function (type, context) {
33
- return (0, exports.isValidType)(context.branch[0].types, type);
34
- });
35
- exports.STARKNET_TYPE = (0, superstruct_1.object)({
36
- name: (0, superstruct_1.string)(),
37
- type: TYPE,
38
- });
39
- exports.STARKNET_DOMAIN_TYPE = (0, superstruct_1.object)({
40
- name: (0, superstruct_1.optional)((0, superstruct_1.string)()),
41
- version: (0, superstruct_1.optional)((0, superstruct_1.string)()),
42
- chainId: (0, superstruct_1.optional)(
43
- (0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.number)()])
44
- ),
45
- });
46
- exports.STARKNET_TYPED_DATA_TYPE = (0, superstruct_1.object)({
47
- types: (0, superstruct_1.intersection)([
48
- (0, superstruct_1.type)({ StarkNetDomain: (0, superstruct_1.array)(exports.STARKNET_TYPE) }),
49
- (0, superstruct_1.record)(
50
- (0, superstruct_1.string)(),
51
- (0, superstruct_1.array)(exports.STARKNET_TYPE)
52
- ),
53
- ]),
54
- primaryType: (0, superstruct_1.string)(),
55
- domain: exports.STARKNET_DOMAIN_TYPE,
56
- message: (0, superstruct_1.object)(),
57
- });
@@ -1,27 +1,8 @@
1
+ import { TypedData } from './types';
1
2
  /**
2
3
  * Validates that `data` matches the EIP-712 JSON schema.
3
4
  *
4
5
  * @param {any} data
5
6
  * @return {boolean}
6
7
  */
7
- export declare const validateTypedData: (data: unknown) => data is {
8
- types: {
9
- StarkNetDomain: {
10
- type: string;
11
- name: string;
12
- }[];
13
- } & Record<
14
- string,
15
- {
16
- type: string;
17
- name: string;
18
- }[]
19
- >;
20
- primaryType: string;
21
- domain: {
22
- version?: string | undefined;
23
- chainId?: string | number | undefined;
24
- name?: string | undefined;
25
- };
26
- message: Record<string, unknown>;
27
- };
8
+ export declare const validateTypedData: (data: unknown) => data is TypedData;