starknet 4.12.0 → 4.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 (224) hide show
  1. package/.eslintrc +1 -0
  2. package/CHANGELOG.md +14 -0
  3. package/__tests__/account.test.ts +0 -2
  4. package/dist/index.d.ts +2683 -24
  5. package/dist/index.global.js +22994 -0
  6. package/dist/index.global.js.map +1 -0
  7. package/dist/index.js +4713 -53
  8. package/dist/index.js.map +1 -0
  9. package/dist/index.mjs +4655 -0
  10. package/dist/index.mjs.map +1 -0
  11. package/index.d.ts +2683 -24
  12. package/index.global.js +22994 -0
  13. package/index.global.js.map +1 -0
  14. package/index.js +4713 -53
  15. package/index.js.map +1 -0
  16. package/index.mjs +4655 -0
  17. package/index.mjs.map +1 -0
  18. package/package.json +8 -2
  19. package/src/account/default.ts +43 -8
  20. package/src/account/interface.ts +25 -2
  21. package/src/constants.ts +0 -1
  22. package/src/provider/default.ts +3 -0
  23. package/src/provider/interface.ts +2 -0
  24. package/src/provider/rpc.ts +4 -4
  25. package/src/provider/sequencer.ts +4 -1
  26. package/src/types/lib.ts +1 -1
  27. package/src/types/provider.ts +5 -0
  28. package/src/utils/ellipticCurve.ts +3 -1
  29. package/src/utils/fetchPonyfill.ts +3 -2
  30. package/src/utils/hash.ts +3 -2
  31. package/src/utils/number.ts +2 -2
  32. package/tsup.config.ts +10 -0
  33. package/account/default.d.ts +0 -30
  34. package/account/default.js +0 -526
  35. package/account/index.d.ts +0 -2
  36. package/account/index.js +0 -18
  37. package/account/interface.d.ts +0 -161
  38. package/account/interface.js +0 -27
  39. package/constants.d.ts +0 -36
  40. package/constants.js +0 -2067
  41. package/contract/contractFactory.d.ts +0 -31
  42. package/contract/contractFactory.js +0 -102
  43. package/contract/default.d.ts +0 -108
  44. package/contract/default.js +0 -640
  45. package/contract/index.d.ts +0 -3
  46. package/contract/index.js +0 -19
  47. package/contract/interface.d.ts +0 -80
  48. package/contract/interface.js +0 -9
  49. package/dist/account/default.d.ts +0 -30
  50. package/dist/account/default.js +0 -526
  51. package/dist/account/index.d.ts +0 -2
  52. package/dist/account/index.js +0 -18
  53. package/dist/account/interface.d.ts +0 -161
  54. package/dist/account/interface.js +0 -27
  55. package/dist/constants.d.ts +0 -36
  56. package/dist/constants.js +0 -2067
  57. package/dist/contract/contractFactory.d.ts +0 -31
  58. package/dist/contract/contractFactory.js +0 -102
  59. package/dist/contract/default.d.ts +0 -108
  60. package/dist/contract/default.js +0 -640
  61. package/dist/contract/index.d.ts +0 -3
  62. package/dist/contract/index.js +0 -19
  63. package/dist/contract/interface.d.ts +0 -80
  64. package/dist/contract/interface.js +0 -9
  65. package/dist/provider/default.d.ts +0 -37
  66. package/dist/provider/default.js +0 -207
  67. package/dist/provider/errors.d.ts +0 -9
  68. package/dist/provider/errors.js +0 -40
  69. package/dist/provider/index.d.ts +0 -7
  70. package/dist/provider/index.js +0 -24
  71. package/dist/provider/interface.d.ts +0 -203
  72. package/dist/provider/interface.js +0 -9
  73. package/dist/provider/rpc.d.ts +0 -86
  74. package/dist/provider/rpc.js +0 -605
  75. package/dist/provider/sequencer.d.ts +0 -79
  76. package/dist/provider/sequencer.js +0 -575
  77. package/dist/provider/utils.d.ts +0 -30
  78. package/dist/provider/utils.js +0 -84
  79. package/dist/signer/default.d.ts +0 -13
  80. package/dist/signer/default.js +0 -102
  81. package/dist/signer/index.d.ts +0 -2
  82. package/dist/signer/index.js +0 -18
  83. package/dist/signer/interface.d.ts +0 -60
  84. package/dist/signer/interface.js +0 -9
  85. package/dist/types/account.d.ts +0 -11
  86. package/dist/types/account.js +0 -2
  87. package/dist/types/api/index.d.ts +0 -10
  88. package/dist/types/api/index.js +0 -18
  89. package/dist/types/api/openrpc.d.ts +0 -572
  90. package/dist/types/api/openrpc.js +0 -45
  91. package/dist/types/api/rpc.d.ts +0 -43
  92. package/dist/types/api/rpc.js +0 -2
  93. package/dist/types/api/sequencer.d.ts +0 -320
  94. package/dist/types/api/sequencer.js +0 -2
  95. package/dist/types/contract.d.ts +0 -5
  96. package/dist/types/contract.js +0 -2
  97. package/dist/types/index.d.ts +0 -7
  98. package/dist/types/index.js +0 -35
  99. package/dist/types/lib.d.ts +0 -120
  100. package/dist/types/lib.js +0 -8
  101. package/dist/types/provider.d.ts +0 -99
  102. package/dist/types/provider.js +0 -2
  103. package/dist/types/signer.d.ts +0 -19
  104. package/dist/types/signer.js +0 -2
  105. package/dist/utils/address.d.ts +0 -5
  106. package/dist/utils/address.js +0 -41
  107. package/dist/utils/ellipticCurve.d.ts +0 -29
  108. package/dist/utils/ellipticCurve.js +0 -132
  109. package/dist/utils/encode.d.ts +0 -15
  110. package/dist/utils/encode.js +0 -96
  111. package/dist/utils/fetchPonyfill.d.ts +0 -2
  112. package/dist/utils/fetchPonyfill.js +0 -6
  113. package/dist/utils/hash.d.ts +0 -37
  114. package/dist/utils/hash.js +0 -162
  115. package/dist/utils/json.d.ts +0 -16
  116. package/dist/utils/json.js +0 -19
  117. package/dist/utils/merkle.d.ts +0 -10
  118. package/dist/utils/merkle.js +0 -89
  119. package/dist/utils/number.d.ts +0 -16
  120. package/dist/utils/number.js +0 -112
  121. package/dist/utils/provider.d.ts +0 -4
  122. package/dist/utils/provider.js +0 -38
  123. package/dist/utils/responseParser/index.d.ts +0 -11
  124. package/dist/utils/responseParser/index.js +0 -9
  125. package/dist/utils/responseParser/rpc.d.ts +0 -20
  126. package/dist/utils/responseParser/rpc.js +0 -44
  127. package/dist/utils/responseParser/sequencer.d.ts +0 -17
  128. package/dist/utils/responseParser/sequencer.js +0 -99
  129. package/dist/utils/shortString.d.ts +0 -4
  130. package/dist/utils/shortString.js +0 -26
  131. package/dist/utils/stark.d.ts +0 -16
  132. package/dist/utils/stark.js +0 -91
  133. package/dist/utils/transaction.d.ts +0 -20
  134. package/dist/utils/transaction.js +0 -79
  135. package/dist/utils/typedData/index.d.ts +0 -72
  136. package/dist/utils/typedData/index.js +0 -239
  137. package/dist/utils/typedData/types.d.ts +0 -32
  138. package/dist/utils/typedData/types.js +0 -2
  139. package/dist/utils/typedData/utils.d.ts +0 -8
  140. package/dist/utils/typedData/utils.js +0 -16
  141. package/dist/utils/uint256.d.ts +0 -11
  142. package/dist/utils/uint256.js +0 -28
  143. package/dist/utils/url.d.ts +0 -7
  144. package/dist/utils/url.js +0 -49
  145. package/provider/default.d.ts +0 -37
  146. package/provider/default.js +0 -207
  147. package/provider/errors.d.ts +0 -9
  148. package/provider/errors.js +0 -40
  149. package/provider/index.d.ts +0 -7
  150. package/provider/index.js +0 -24
  151. package/provider/interface.d.ts +0 -203
  152. package/provider/interface.js +0 -9
  153. package/provider/rpc.d.ts +0 -86
  154. package/provider/rpc.js +0 -605
  155. package/provider/sequencer.d.ts +0 -79
  156. package/provider/sequencer.js +0 -575
  157. package/provider/utils.d.ts +0 -30
  158. package/provider/utils.js +0 -84
  159. package/signer/default.d.ts +0 -13
  160. package/signer/default.js +0 -102
  161. package/signer/index.d.ts +0 -2
  162. package/signer/index.js +0 -18
  163. package/signer/interface.d.ts +0 -60
  164. package/signer/interface.js +0 -9
  165. package/types/account.d.ts +0 -11
  166. package/types/account.js +0 -2
  167. package/types/api/index.d.ts +0 -10
  168. package/types/api/index.js +0 -18
  169. package/types/api/openrpc.d.ts +0 -572
  170. package/types/api/openrpc.js +0 -45
  171. package/types/api/rpc.d.ts +0 -43
  172. package/types/api/rpc.js +0 -2
  173. package/types/api/sequencer.d.ts +0 -320
  174. package/types/api/sequencer.js +0 -2
  175. package/types/contract.d.ts +0 -5
  176. package/types/contract.js +0 -2
  177. package/types/index.d.ts +0 -7
  178. package/types/index.js +0 -35
  179. package/types/lib.d.ts +0 -120
  180. package/types/lib.js +0 -8
  181. package/types/provider.d.ts +0 -99
  182. package/types/provider.js +0 -2
  183. package/types/signer.d.ts +0 -19
  184. package/types/signer.js +0 -2
  185. package/utils/address.d.ts +0 -5
  186. package/utils/address.js +0 -41
  187. package/utils/ellipticCurve.d.ts +0 -29
  188. package/utils/ellipticCurve.js +0 -132
  189. package/utils/encode.d.ts +0 -15
  190. package/utils/encode.js +0 -96
  191. package/utils/fetchPonyfill.d.ts +0 -2
  192. package/utils/fetchPonyfill.js +0 -6
  193. package/utils/hash.d.ts +0 -37
  194. package/utils/hash.js +0 -162
  195. package/utils/json.d.ts +0 -16
  196. package/utils/json.js +0 -19
  197. package/utils/merkle.d.ts +0 -10
  198. package/utils/merkle.js +0 -89
  199. package/utils/number.d.ts +0 -16
  200. package/utils/number.js +0 -112
  201. package/utils/provider.d.ts +0 -4
  202. package/utils/provider.js +0 -38
  203. package/utils/responseParser/index.d.ts +0 -11
  204. package/utils/responseParser/index.js +0 -9
  205. package/utils/responseParser/rpc.d.ts +0 -20
  206. package/utils/responseParser/rpc.js +0 -44
  207. package/utils/responseParser/sequencer.d.ts +0 -17
  208. package/utils/responseParser/sequencer.js +0 -99
  209. package/utils/shortString.d.ts +0 -4
  210. package/utils/shortString.js +0 -26
  211. package/utils/stark.d.ts +0 -16
  212. package/utils/stark.js +0 -91
  213. package/utils/transaction.d.ts +0 -20
  214. package/utils/transaction.js +0 -79
  215. package/utils/typedData/index.d.ts +0 -72
  216. package/utils/typedData/index.js +0 -239
  217. package/utils/typedData/types.d.ts +0 -32
  218. package/utils/typedData/types.js +0 -2
  219. package/utils/typedData/utils.d.ts +0 -8
  220. package/utils/typedData/utils.js +0 -16
  221. package/utils/uint256.d.ts +0 -11
  222. package/utils/uint256.js +0 -28
  223. package/utils/url.d.ts +0 -7
  224. package/utils/url.js +0 -49
@@ -1,72 +0,0 @@
1
- import { BigNumberish } from '../number';
2
- import { StarkNetMerkleType, StarkNetType, TypedData } from './types';
3
- export * from './types';
4
- export declare function prepareSelector(selector: string): string;
5
- export declare function isMerkleTreeType(type: StarkNetType): type is StarkNetMerkleType;
6
- interface Context {
7
- parent?: string;
8
- key?: string;
9
- }
10
- /**
11
- * Get the dependencies of a struct type. If a struct has the same dependency multiple times, it's only included once
12
- * in the resulting array.
13
- *
14
- * @param {TypedData} typedData
15
- * @param {string} type
16
- * @param {string[]} [dependencies]
17
- * @return {string[]}
18
- */
19
- export declare const getDependencies: (types: TypedData['types'], type: string, dependencies?: string[]) => string[];
20
- /**
21
- * Encode a type to a string. All dependant types are alphabetically sorted.
22
- *
23
- * @param {TypedData} typedData
24
- * @param {string} type
25
- * @return {string}
26
- */
27
- export declare const encodeType: (types: TypedData['types'], type: string) => string;
28
- /**
29
- * Get a type string as hash.
30
- *
31
- * @param {TypedData} typedData
32
- * @param {string} type
33
- * @return {string}
34
- */
35
- export declare const getTypeHash: (types: TypedData['types'], type: string) => string;
36
- /**
37
- * Encodes a single value to an ABI serialisable string, number or Buffer. Returns the data as tuple, which consists of
38
- * an array of ABI compatible types, and an array of corresponding values.
39
- *
40
- * @param {TypedData} typedData
41
- * @param {string} type
42
- * @param {any} data
43
- * @returns {[string, string]}
44
- */
45
- export declare const encodeValue: (types: TypedData['types'], type: string, data: unknown, ctx?: Context) => [string, string];
46
- /**
47
- * Encode the data to an ABI encoded Buffer. The data should be a key -> value object with all the required values. All
48
- * dependant types are automatically encoded.
49
- *
50
- * @param {TypedData} typedData
51
- * @param {string} type
52
- * @param {Record<string, any>} data
53
- */
54
- export declare const encodeData: <T extends TypedData>(types: T["types"], type: string, data: T["message"]) => string[][];
55
- /**
56
- * Get encoded data as a hash. The data should be a key -> value object with all the required values. All dependant
57
- * types are automatically encoded.
58
- *
59
- * @param {TypedData} typedData
60
- * @param {string} type
61
- * @param {Record<string, any>} data
62
- * @return {Buffer}
63
- */
64
- export declare const getStructHash: <T extends TypedData>(types: T["types"], type: string, data: T["message"]) => string;
65
- /**
66
- * Get the EIP-191 encoded message to sign, from the typedData object.
67
- *
68
- * @param {TypedData} typedData
69
- * @param {BigNumberish} account
70
- * @return {string}
71
- */
72
- export declare const getMessageHash: (typedData: TypedData, account: BigNumberish) => string;
@@ -1,239 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- var __read = (this && this.__read) || function (o, n) {
17
- var m = typeof Symbol === "function" && o[Symbol.iterator];
18
- if (!m) return o;
19
- var i = m.call(o), r, ar = [], e;
20
- try {
21
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
22
- }
23
- catch (error) { e = { error: error }; }
24
- finally {
25
- try {
26
- if (r && !r.done && (m = i["return"])) m.call(i);
27
- }
28
- finally { if (e) throw e.error; }
29
- }
30
- return ar;
31
- };
32
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
33
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
34
- if (ar || !(i in from)) {
35
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
36
- ar[i] = from[i];
37
- }
38
- }
39
- return to.concat(ar || Array.prototype.slice.call(from));
40
- };
41
- Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.getMessageHash = exports.getStructHash = exports.encodeData = exports.encodeValue = exports.getTypeHash = exports.encodeType = exports.getDependencies = exports.isMerkleTreeType = exports.prepareSelector = void 0;
43
- var hash_1 = require("../hash");
44
- var merkle_1 = require("../merkle");
45
- var number_1 = require("../number");
46
- var shortString_1 = require("../shortString");
47
- var utils_1 = require("./utils");
48
- __exportStar(require("./types"), exports);
49
- function getHex(value) {
50
- try {
51
- return (0, number_1.toHex)((0, number_1.toBN)(value));
52
- }
53
- catch (e) {
54
- if (typeof value === 'string') {
55
- return (0, number_1.toHex)((0, number_1.toBN)((0, shortString_1.encodeShortString)(value)));
56
- }
57
- throw new Error("Invalid BigNumberish: ".concat(value));
58
- }
59
- }
60
- function prepareSelector(selector) {
61
- return (0, number_1.isHex)(selector) ? selector : (0, hash_1.getSelectorFromName)(selector);
62
- }
63
- exports.prepareSelector = prepareSelector;
64
- function isMerkleTreeType(type) {
65
- return type.type === 'merkletree';
66
- }
67
- exports.isMerkleTreeType = isMerkleTreeType;
68
- /**
69
- * Get the dependencies of a struct type. If a struct has the same dependency multiple times, it's only included once
70
- * in the resulting array.
71
- *
72
- * @param {TypedData} typedData
73
- * @param {string} type
74
- * @param {string[]} [dependencies]
75
- * @return {string[]}
76
- */
77
- var getDependencies = function (types, type, dependencies) {
78
- if (dependencies === void 0) { dependencies = []; }
79
- // Include pointers (struct arrays)
80
- if (type[type.length - 1] === '*') {
81
- // eslint-disable-next-line no-param-reassign
82
- type = type.slice(0, -1);
83
- }
84
- if (dependencies.includes(type)) {
85
- return dependencies;
86
- }
87
- if (!types[type]) {
88
- return dependencies;
89
- }
90
- return __spreadArray([
91
- type
92
- ], __read(types[type].reduce(function (previous, t) { return __spreadArray(__spreadArray([], __read(previous), false), __read((0, exports.getDependencies)(types, t.type, previous).filter(function (dependency) { return !previous.includes(dependency); })), false); }, [])), false);
93
- };
94
- exports.getDependencies = getDependencies;
95
- function getMerkleTreeType(types, ctx) {
96
- if (ctx.parent && ctx.key) {
97
- var parentType = types[ctx.parent];
98
- var merkleType = parentType.find(function (t) { return t.name === ctx.key; });
99
- var isMerkleTree = isMerkleTreeType(merkleType);
100
- if (!isMerkleTree) {
101
- throw new Error("".concat(ctx.key, " is not a merkle tree"));
102
- }
103
- if (merkleType.contains.endsWith('*')) {
104
- throw new Error("Merkle tree contain property must not be an array but was given ".concat(ctx.key));
105
- }
106
- return merkleType.contains;
107
- }
108
- return 'raw';
109
- }
110
- /**
111
- * Encode a type to a string. All dependant types are alphabetically sorted.
112
- *
113
- * @param {TypedData} typedData
114
- * @param {string} type
115
- * @return {string}
116
- */
117
- var encodeType = function (types, type) {
118
- var _a = __read((0, exports.getDependencies)(types, type)), primary = _a[0], dependencies = _a.slice(1);
119
- var newTypes = !primary ? [] : __spreadArray([primary], __read(dependencies.sort()), false);
120
- return newTypes
121
- .map(function (dependency) {
122
- return "".concat(dependency, "(").concat(types[dependency].map(function (t) { return "".concat(t.name, ":").concat(t.type); }), ")");
123
- })
124
- .join('');
125
- };
126
- exports.encodeType = encodeType;
127
- /**
128
- * Get a type string as hash.
129
- *
130
- * @param {TypedData} typedData
131
- * @param {string} type
132
- * @return {string}
133
- */
134
- var getTypeHash = function (types, type) {
135
- return (0, hash_1.getSelectorFromName)((0, exports.encodeType)(types, type));
136
- };
137
- exports.getTypeHash = getTypeHash;
138
- /**
139
- * Encodes a single value to an ABI serialisable string, number or Buffer. Returns the data as tuple, which consists of
140
- * an array of ABI compatible types, and an array of corresponding values.
141
- *
142
- * @param {TypedData} typedData
143
- * @param {string} type
144
- * @param {any} data
145
- * @returns {[string, string]}
146
- */
147
- var encodeValue = function (types, type, data, ctx) {
148
- if (ctx === void 0) { ctx = {}; }
149
- if (types[type]) {
150
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
151
- return [type, (0, exports.getStructHash)(types, type, data)];
152
- }
153
- if (Object.keys(types)
154
- .map(function (x) { return "".concat(x, "*"); })
155
- .includes(type)) {
156
- var structHashes = data.map(function (struct) {
157
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
158
- return (0, exports.getStructHash)(types, type.slice(0, -1), struct);
159
- });
160
- return [type, (0, hash_1.computeHashOnElements)(structHashes)];
161
- }
162
- if (type === 'merkletree') {
163
- var merkleTreeType_1 = getMerkleTreeType(types, ctx);
164
- var structHashes = data.map(function (struct) {
165
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
166
- return (0, exports.encodeValue)(types, merkleTreeType_1, struct)[1];
167
- });
168
- var root = new merkle_1.MerkleTree(structHashes).root;
169
- return ['felt', root];
170
- }
171
- if (type === 'felt*') {
172
- return ['felt*', (0, hash_1.computeHashOnElements)(data)];
173
- }
174
- if (type === 'selector') {
175
- return ['felt', prepareSelector(data)];
176
- }
177
- return [type, getHex(data)];
178
- };
179
- exports.encodeValue = encodeValue;
180
- /**
181
- * Encode the data to an ABI encoded Buffer. The data should be a key -> value object with all the required values. All
182
- * dependant types are automatically encoded.
183
- *
184
- * @param {TypedData} typedData
185
- * @param {string} type
186
- * @param {Record<string, any>} data
187
- */
188
- var encodeData = function (types, type, data) {
189
- var _a = __read(types[type].reduce(function (_a, field) {
190
- var _b = __read(_a, 2), ts = _b[0], vs = _b[1];
191
- if (data[field.name] === undefined || data[field.name] === null) {
192
- throw new Error("Cannot encode data: missing data for '".concat(field.name, "'"));
193
- }
194
- var value = data[field.name];
195
- var _c = __read((0, exports.encodeValue)(types, field.type, value, {
196
- parent: type,
197
- key: field.name,
198
- }), 2), t = _c[0], encodedValue = _c[1];
199
- return [
200
- __spreadArray(__spreadArray([], __read(ts), false), [t], false),
201
- __spreadArray(__spreadArray([], __read(vs), false), [encodedValue], false),
202
- ];
203
- }, [['felt'], [(0, exports.getTypeHash)(types, type)]]), 2), returnTypes = _a[0], values = _a[1];
204
- return [returnTypes, values];
205
- };
206
- exports.encodeData = encodeData;
207
- /**
208
- * Get encoded data as a hash. The data should be a key -> value object with all the required values. All dependant
209
- * types are automatically encoded.
210
- *
211
- * @param {TypedData} typedData
212
- * @param {string} type
213
- * @param {Record<string, any>} data
214
- * @return {Buffer}
215
- */
216
- var getStructHash = function (types, type, data) {
217
- return (0, hash_1.computeHashOnElements)((0, exports.encodeData)(types, type, data)[1]);
218
- };
219
- exports.getStructHash = getStructHash;
220
- /**
221
- * Get the EIP-191 encoded message to sign, from the typedData object.
222
- *
223
- * @param {TypedData} typedData
224
- * @param {BigNumberish} account
225
- * @return {string}
226
- */
227
- var getMessageHash = function (typedData, account) {
228
- if (!(0, utils_1.validateTypedData)(typedData)) {
229
- throw new Error('Typed data does not match JSON schema');
230
- }
231
- var message = [
232
- (0, shortString_1.encodeShortString)('StarkNet Message'),
233
- (0, exports.getStructHash)(typedData.types, 'StarkNetDomain', typedData.domain),
234
- account,
235
- (0, exports.getStructHash)(typedData.types, typedData.primaryType, typedData.message),
236
- ];
237
- return (0, hash_1.computeHashOnElements)(message);
238
- };
239
- exports.getMessageHash = getMessageHash;
@@ -1,32 +0,0 @@
1
- export declare type StarkNetMerkleType = {
2
- name: string;
3
- type: 'merkletree';
4
- contains: string;
5
- };
6
- /**
7
- * A single type, as part of a struct. The `type` field can be any of the EIP-712 supported types.
8
- *
9
- * Note that the `uint` and `int` aliases like in Solidity, and fixed point numbers are not supported by the EIP-712
10
- * standard.
11
- */
12
- export declare type StarkNetType = {
13
- name: string;
14
- type: string;
15
- } | StarkNetMerkleType;
16
- /**
17
- * The EIP712 domain struct. Any of these fields are optional, but it must contain at least one field.
18
- */
19
- export interface StarkNetDomain extends Record<string, unknown> {
20
- name?: string;
21
- version?: string;
22
- chainId?: string | number;
23
- }
24
- /**
25
- * The complete typed data, with all the structs, domain data, primary type of the message, and the message itself.
26
- */
27
- export interface TypedData {
28
- types: Record<string, StarkNetType[]>;
29
- primaryType: string;
30
- domain: StarkNetDomain;
31
- message: Record<string, unknown>;
32
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,8 +0,0 @@
1
- import { TypedData } from './types';
2
- /**
3
- * Validates that `data` matches the EIP-712 JSON schema.
4
- *
5
- * @param {any} data
6
- * @return {boolean}
7
- */
8
- export declare const validateTypedData: (data: unknown) => data is TypedData;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateTypedData = void 0;
4
- /**
5
- * Validates that `data` matches the EIP-712 JSON schema.
6
- *
7
- * @param {any} data
8
- * @return {boolean}
9
- */
10
- var validateTypedData = function (data) {
11
- var typedData = data;
12
- // Validate that the data matches the EIP-712 JSON schema
13
- var valid = Boolean(typedData.types && typedData.primaryType && typedData.message);
14
- return valid;
15
- };
16
- exports.validateTypedData = validateTypedData;
@@ -1,11 +0,0 @@
1
- /// <reference types="bn.js" />
2
- import { BigNumberish } from './number';
3
- export interface Uint256 {
4
- low: BigNumberish;
5
- high: BigNumberish;
6
- }
7
- export declare function uint256ToBN(uint256: Uint256): import("bn.js");
8
- export declare const UINT_128_MAX: import("bn.js");
9
- export declare const UINT_256_MAX: import("bn.js");
10
- export declare function isUint256(bn: BigNumberish): boolean;
11
- export declare function bnToUint256(bignumber: BigNumberish): Uint256;
package/utils/uint256.js DELETED
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.bnToUint256 = exports.isUint256 = exports.UINT_256_MAX = exports.UINT_128_MAX = exports.uint256ToBN = void 0;
4
- var encode_1 = require("./encode");
5
- var number_1 = require("./number");
6
- // function to convert Uint256 to BN
7
- function uint256ToBN(uint256) {
8
- return (0, number_1.toBN)(uint256.high).shln(128).add((0, number_1.toBN)(uint256.low));
9
- }
10
- exports.uint256ToBN = uint256ToBN;
11
- exports.UINT_128_MAX = (0, number_1.toBN)(1).shln(128).sub((0, number_1.toBN)(1));
12
- exports.UINT_256_MAX = (0, number_1.toBN)(1).shln(256).sub((0, number_1.toBN)(1));
13
- // function to check if BN is smaller or equal 2**256-1
14
- function isUint256(bn) {
15
- return (0, number_1.toBN)(bn).lte(exports.UINT_256_MAX);
16
- }
17
- exports.isUint256 = isUint256;
18
- // function to convert BN to Uint256
19
- function bnToUint256(bignumber) {
20
- var bn = (0, number_1.toBN)(bignumber);
21
- if (!isUint256(bn))
22
- throw new Error('Number is too large');
23
- return {
24
- low: (0, encode_1.addHexPrefix)(bn.maskn(128).toString(16)),
25
- high: (0, encode_1.addHexPrefix)(bn.shrn(128).toString(16)),
26
- };
27
- }
28
- exports.bnToUint256 = bnToUint256;
package/utils/url.d.ts DELETED
@@ -1,7 +0,0 @@
1
- /**
2
- * Loosely validate a URL `string`.
3
- * @param {String} s
4
- * @return {Boolean}
5
- */
6
- export declare function isUrl(s?: string): boolean;
7
- export declare function buildUrl(baseUrl: string, defaultPath: string, urlOrPath?: string): string;
package/utils/url.js DELETED
@@ -1,49 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.buildUrl = exports.isUrl = void 0;
7
- var url_join_1 = __importDefault(require("url-join"));
8
- /**
9
- * Inspired from https://github.com/segmentio/is-url
10
- */
11
- /**
12
- * RegExps.
13
- * A URL must match #1 and then at least one of #2/#3.
14
- * Use two levels of REs to avoid REDOS.
15
- */
16
- var protocolAndDomainRE = /^(?:\w+:)?\/\/(\S+)$/;
17
- var localhostDomainRE = /^localhost[:?\d]*(?:[^:?\d]\S*)?$/;
18
- var nonLocalhostDomainRE = /^[^\s.]+\.\S{2,}$/;
19
- /**
20
- * Loosely validate a URL `string`.
21
- * @param {String} s
22
- * @return {Boolean}
23
- */
24
- function isUrl(s) {
25
- if (!s) {
26
- return false;
27
- }
28
- if (typeof s !== 'string') {
29
- return false;
30
- }
31
- var match = s.match(protocolAndDomainRE);
32
- if (!match) {
33
- return false;
34
- }
35
- var everythingAfterProtocol = match[1];
36
- if (!everythingAfterProtocol) {
37
- return false;
38
- }
39
- if (localhostDomainRE.test(everythingAfterProtocol) ||
40
- nonLocalhostDomainRE.test(everythingAfterProtocol)) {
41
- return true;
42
- }
43
- return false;
44
- }
45
- exports.isUrl = isUrl;
46
- function buildUrl(baseUrl, defaultPath, urlOrPath) {
47
- return isUrl(urlOrPath) ? urlOrPath : (0, url_join_1.default)(baseUrl, urlOrPath !== null && urlOrPath !== void 0 ? urlOrPath : defaultPath);
48
- }
49
- exports.buildUrl = buildUrl;