starknet 4.11.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 (227) hide show
  1. package/.eslintrc +1 -0
  2. package/CHANGELOG.md +25 -0
  3. package/__tests__/account.test.ts +36 -0
  4. package/__tests__/defaultProvider.test.ts +15 -17
  5. package/__tests__/fixtures.ts +2 -0
  6. package/dist/index.d.ts +2683 -24
  7. package/dist/index.global.js +22994 -0
  8. package/dist/index.global.js.map +1 -0
  9. package/dist/index.js +4713 -53
  10. package/dist/index.js.map +1 -0
  11. package/dist/index.mjs +4655 -0
  12. package/dist/index.mjs.map +1 -0
  13. package/index.d.ts +2683 -24
  14. package/index.global.js +22994 -0
  15. package/index.global.js.map +1 -0
  16. package/index.js +4713 -53
  17. package/index.js.map +1 -0
  18. package/index.mjs +4655 -0
  19. package/index.mjs.map +1 -0
  20. package/package.json +8 -2
  21. package/src/account/default.ts +43 -8
  22. package/src/account/interface.ts +25 -2
  23. package/src/constants.ts +0 -1
  24. package/src/provider/default.ts +5 -2
  25. package/src/provider/interface.ts +3 -1
  26. package/src/provider/rpc.ts +8 -4
  27. package/src/provider/sequencer.ts +5 -2
  28. package/src/types/lib.ts +1 -1
  29. package/src/types/provider.ts +5 -0
  30. package/src/utils/ellipticCurve.ts +3 -1
  31. package/src/utils/fetchPonyfill.ts +3 -2
  32. package/src/utils/hash.ts +3 -2
  33. package/src/utils/number.ts +2 -2
  34. package/tsup.config.ts +10 -0
  35. package/__tests__/udc.test.ts +0 -41
  36. package/account/default.d.ts +0 -30
  37. package/account/default.js +0 -526
  38. package/account/index.d.ts +0 -2
  39. package/account/index.js +0 -18
  40. package/account/interface.d.ts +0 -161
  41. package/account/interface.js +0 -27
  42. package/constants.d.ts +0 -36
  43. package/constants.js +0 -2067
  44. package/contract/contractFactory.d.ts +0 -31
  45. package/contract/contractFactory.js +0 -102
  46. package/contract/default.d.ts +0 -108
  47. package/contract/default.js +0 -640
  48. package/contract/index.d.ts +0 -3
  49. package/contract/index.js +0 -19
  50. package/contract/interface.d.ts +0 -80
  51. package/contract/interface.js +0 -9
  52. package/dist/account/default.d.ts +0 -30
  53. package/dist/account/default.js +0 -526
  54. package/dist/account/index.d.ts +0 -2
  55. package/dist/account/index.js +0 -18
  56. package/dist/account/interface.d.ts +0 -161
  57. package/dist/account/interface.js +0 -27
  58. package/dist/constants.d.ts +0 -36
  59. package/dist/constants.js +0 -2067
  60. package/dist/contract/contractFactory.d.ts +0 -31
  61. package/dist/contract/contractFactory.js +0 -102
  62. package/dist/contract/default.d.ts +0 -108
  63. package/dist/contract/default.js +0 -640
  64. package/dist/contract/index.d.ts +0 -3
  65. package/dist/contract/index.js +0 -19
  66. package/dist/contract/interface.d.ts +0 -80
  67. package/dist/contract/interface.js +0 -9
  68. package/dist/provider/default.d.ts +0 -37
  69. package/dist/provider/default.js +0 -207
  70. package/dist/provider/errors.d.ts +0 -9
  71. package/dist/provider/errors.js +0 -40
  72. package/dist/provider/index.d.ts +0 -7
  73. package/dist/provider/index.js +0 -24
  74. package/dist/provider/interface.d.ts +0 -203
  75. package/dist/provider/interface.js +0 -9
  76. package/dist/provider/rpc.d.ts +0 -85
  77. package/dist/provider/rpc.js +0 -598
  78. package/dist/provider/sequencer.d.ts +0 -79
  79. package/dist/provider/sequencer.js +0 -575
  80. package/dist/provider/utils.d.ts +0 -30
  81. package/dist/provider/utils.js +0 -84
  82. package/dist/signer/default.d.ts +0 -13
  83. package/dist/signer/default.js +0 -102
  84. package/dist/signer/index.d.ts +0 -2
  85. package/dist/signer/index.js +0 -18
  86. package/dist/signer/interface.d.ts +0 -60
  87. package/dist/signer/interface.js +0 -9
  88. package/dist/types/account.d.ts +0 -11
  89. package/dist/types/account.js +0 -2
  90. package/dist/types/api/index.d.ts +0 -10
  91. package/dist/types/api/index.js +0 -18
  92. package/dist/types/api/openrpc.d.ts +0 -572
  93. package/dist/types/api/openrpc.js +0 -45
  94. package/dist/types/api/rpc.d.ts +0 -43
  95. package/dist/types/api/rpc.js +0 -2
  96. package/dist/types/api/sequencer.d.ts +0 -320
  97. package/dist/types/api/sequencer.js +0 -2
  98. package/dist/types/contract.d.ts +0 -5
  99. package/dist/types/contract.js +0 -2
  100. package/dist/types/index.d.ts +0 -7
  101. package/dist/types/index.js +0 -35
  102. package/dist/types/lib.d.ts +0 -120
  103. package/dist/types/lib.js +0 -8
  104. package/dist/types/provider.d.ts +0 -99
  105. package/dist/types/provider.js +0 -2
  106. package/dist/types/signer.d.ts +0 -19
  107. package/dist/types/signer.js +0 -2
  108. package/dist/utils/address.d.ts +0 -5
  109. package/dist/utils/address.js +0 -41
  110. package/dist/utils/ellipticCurve.d.ts +0 -29
  111. package/dist/utils/ellipticCurve.js +0 -132
  112. package/dist/utils/encode.d.ts +0 -15
  113. package/dist/utils/encode.js +0 -96
  114. package/dist/utils/fetchPonyfill.d.ts +0 -2
  115. package/dist/utils/fetchPonyfill.js +0 -6
  116. package/dist/utils/hash.d.ts +0 -37
  117. package/dist/utils/hash.js +0 -162
  118. package/dist/utils/json.d.ts +0 -16
  119. package/dist/utils/json.js +0 -19
  120. package/dist/utils/merkle.d.ts +0 -10
  121. package/dist/utils/merkle.js +0 -89
  122. package/dist/utils/number.d.ts +0 -16
  123. package/dist/utils/number.js +0 -112
  124. package/dist/utils/provider.d.ts +0 -4
  125. package/dist/utils/provider.js +0 -38
  126. package/dist/utils/responseParser/index.d.ts +0 -11
  127. package/dist/utils/responseParser/index.js +0 -9
  128. package/dist/utils/responseParser/rpc.d.ts +0 -20
  129. package/dist/utils/responseParser/rpc.js +0 -44
  130. package/dist/utils/responseParser/sequencer.d.ts +0 -17
  131. package/dist/utils/responseParser/sequencer.js +0 -99
  132. package/dist/utils/shortString.d.ts +0 -4
  133. package/dist/utils/shortString.js +0 -26
  134. package/dist/utils/stark.d.ts +0 -16
  135. package/dist/utils/stark.js +0 -91
  136. package/dist/utils/transaction.d.ts +0 -20
  137. package/dist/utils/transaction.js +0 -79
  138. package/dist/utils/typedData/index.d.ts +0 -72
  139. package/dist/utils/typedData/index.js +0 -239
  140. package/dist/utils/typedData/types.d.ts +0 -32
  141. package/dist/utils/typedData/types.js +0 -2
  142. package/dist/utils/typedData/utils.d.ts +0 -8
  143. package/dist/utils/typedData/utils.js +0 -16
  144. package/dist/utils/uint256.d.ts +0 -11
  145. package/dist/utils/uint256.js +0 -28
  146. package/dist/utils/url.d.ts +0 -7
  147. package/dist/utils/url.js +0 -49
  148. package/provider/default.d.ts +0 -37
  149. package/provider/default.js +0 -207
  150. package/provider/errors.d.ts +0 -9
  151. package/provider/errors.js +0 -40
  152. package/provider/index.d.ts +0 -7
  153. package/provider/index.js +0 -24
  154. package/provider/interface.d.ts +0 -203
  155. package/provider/interface.js +0 -9
  156. package/provider/rpc.d.ts +0 -85
  157. package/provider/rpc.js +0 -598
  158. package/provider/sequencer.d.ts +0 -79
  159. package/provider/sequencer.js +0 -575
  160. package/provider/utils.d.ts +0 -30
  161. package/provider/utils.js +0 -84
  162. package/signer/default.d.ts +0 -13
  163. package/signer/default.js +0 -102
  164. package/signer/index.d.ts +0 -2
  165. package/signer/index.js +0 -18
  166. package/signer/interface.d.ts +0 -60
  167. package/signer/interface.js +0 -9
  168. package/types/account.d.ts +0 -11
  169. package/types/account.js +0 -2
  170. package/types/api/index.d.ts +0 -10
  171. package/types/api/index.js +0 -18
  172. package/types/api/openrpc.d.ts +0 -572
  173. package/types/api/openrpc.js +0 -45
  174. package/types/api/rpc.d.ts +0 -43
  175. package/types/api/rpc.js +0 -2
  176. package/types/api/sequencer.d.ts +0 -320
  177. package/types/api/sequencer.js +0 -2
  178. package/types/contract.d.ts +0 -5
  179. package/types/contract.js +0 -2
  180. package/types/index.d.ts +0 -7
  181. package/types/index.js +0 -35
  182. package/types/lib.d.ts +0 -120
  183. package/types/lib.js +0 -8
  184. package/types/provider.d.ts +0 -99
  185. package/types/provider.js +0 -2
  186. package/types/signer.d.ts +0 -19
  187. package/types/signer.js +0 -2
  188. package/utils/address.d.ts +0 -5
  189. package/utils/address.js +0 -41
  190. package/utils/ellipticCurve.d.ts +0 -29
  191. package/utils/ellipticCurve.js +0 -132
  192. package/utils/encode.d.ts +0 -15
  193. package/utils/encode.js +0 -96
  194. package/utils/fetchPonyfill.d.ts +0 -2
  195. package/utils/fetchPonyfill.js +0 -6
  196. package/utils/hash.d.ts +0 -37
  197. package/utils/hash.js +0 -162
  198. package/utils/json.d.ts +0 -16
  199. package/utils/json.js +0 -19
  200. package/utils/merkle.d.ts +0 -10
  201. package/utils/merkle.js +0 -89
  202. package/utils/number.d.ts +0 -16
  203. package/utils/number.js +0 -112
  204. package/utils/provider.d.ts +0 -4
  205. package/utils/provider.js +0 -38
  206. package/utils/responseParser/index.d.ts +0 -11
  207. package/utils/responseParser/index.js +0 -9
  208. package/utils/responseParser/rpc.d.ts +0 -20
  209. package/utils/responseParser/rpc.js +0 -44
  210. package/utils/responseParser/sequencer.d.ts +0 -17
  211. package/utils/responseParser/sequencer.js +0 -99
  212. package/utils/shortString.d.ts +0 -4
  213. package/utils/shortString.js +0 -26
  214. package/utils/stark.d.ts +0 -16
  215. package/utils/stark.js +0 -91
  216. package/utils/transaction.d.ts +0 -20
  217. package/utils/transaction.js +0 -79
  218. package/utils/typedData/index.d.ts +0 -72
  219. package/utils/typedData/index.js +0 -239
  220. package/utils/typedData/types.d.ts +0 -32
  221. package/utils/typedData/types.js +0 -2
  222. package/utils/typedData/utils.d.ts +0 -8
  223. package/utils/typedData/utils.js +0 -16
  224. package/utils/uint256.d.ts +0 -11
  225. package/utils/uint256.js +0 -28
  226. package/utils/url.d.ts +0 -7
  227. 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;