starknet 2.3.0 → 2.6.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 (61) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/__tests__/account.test.ts +3 -3
  3. package/__tests__/provider.test.ts +3 -3
  4. package/__tests__/signer.test.ts +17 -0
  5. package/__tests__/utils/ellipticalCurve.test.ts +1 -1
  6. package/__tests__/utils/typedData.test.ts +72 -0
  7. package/contract.d.ts +9 -3
  8. package/contract.js +23 -5
  9. package/dist/contract.d.ts +6 -3
  10. package/dist/contract.js +19 -5
  11. package/dist/index.d.ts +1 -0
  12. package/dist/index.js +2 -1
  13. package/dist/provider/default.d.ts +17 -17
  14. package/dist/provider/default.js +37 -32
  15. package/dist/provider/interface.d.ts +16 -16
  16. package/dist/signer/default.d.ts +20 -3
  17. package/dist/signer/default.js +61 -20
  18. package/dist/signer/interface.d.ts +22 -3
  19. package/dist/types.d.ts +10 -7
  20. package/dist/utils/ellipticCurve.d.ts +8 -1
  21. package/dist/utils/ellipticCurve.js +48 -9
  22. package/dist/utils/stark.d.ts +2 -6
  23. package/dist/utils/stark.js +1 -5
  24. package/dist/utils/typedData/index.d.ts +91 -0
  25. package/dist/utils/typedData/index.js +183 -0
  26. package/dist/utils/typedData/types.d.ts +82 -0
  27. package/dist/utils/typedData/types.js +47 -0
  28. package/dist/utils/typedData/utils.d.ts +24 -0
  29. package/dist/utils/typedData/utils.js +15 -0
  30. package/index.d.ts +1 -0
  31. package/index.js +3 -1
  32. package/package.json +3 -1
  33. package/provider/default.d.ts +21 -16
  34. package/provider/default.js +50 -39
  35. package/provider/interface.d.ts +22 -16
  36. package/signer/default.d.ts +20 -3
  37. package/signer/default.js +60 -17
  38. package/signer/interface.d.ts +22 -3
  39. package/src/contract.ts +17 -14
  40. package/src/index.ts +1 -0
  41. package/src/provider/default.ts +37 -31
  42. package/src/provider/interface.ts +21 -16
  43. package/src/signer/default.ts +49 -17
  44. package/src/signer/interface.ts +26 -3
  45. package/src/types.ts +16 -7
  46. package/src/utils/ellipticCurve.ts +31 -9
  47. package/src/utils/stark.ts +4 -8
  48. package/src/utils/typedData/index.ts +176 -0
  49. package/src/utils/typedData/types.ts +82 -0
  50. package/src/utils/typedData/utils.ts +13 -0
  51. package/types.d.ts +12 -8
  52. package/utils/ellipticCurve.d.ts +12 -1
  53. package/utils/ellipticCurve.js +72 -23
  54. package/utils/stark.d.ts +2 -8
  55. package/utils/stark.js +1 -6
  56. package/utils/typedData/index.d.ts +113 -0
  57. package/utils/typedData/index.js +247 -0
  58. package/utils/typedData/types.d.ts +103 -0
  59. package/utils/typedData/types.js +57 -0
  60. package/utils/typedData/utils.d.ts +27 -0
  61. package/utils/typedData/utils.js +15 -0
@@ -1,5 +1,4 @@
1
- import { CompressedProgram, Program } from '../types';
2
- import { BigNumberish } from './number';
1
+ import { CompressedProgram, Program, Signature } from '../types';
3
2
  /**
4
3
  * Function to compress compiled cairo program
5
4
  *
@@ -18,7 +17,4 @@ export declare function compressProgram(jsonProgram: Program | string): Compress
18
17
  export declare function getSelectorFromName(funcName: string): string;
19
18
  export declare function randomAddress(): string;
20
19
  export declare function makeAddress(input: string): string;
21
- export declare function formatSignature(sig?: [BigNumberish, BigNumberish]): [string, string] | [];
22
- export declare function compileStructToCalldata<S extends {
23
- [k: string]: string;
24
- }>(struct: S): string[];
20
+ export declare function formatSignature(sig?: Signature): string[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.compileStructToCalldata = exports.formatSignature = exports.makeAddress = exports.randomAddress = exports.getSelectorFromName = exports.compressProgram = void 0;
3
+ exports.formatSignature = exports.makeAddress = exports.randomAddress = exports.getSelectorFromName = exports.compressProgram = void 0;
4
4
  var pako_1 = require("pako");
5
5
  var ellipticCurve_1 = require("./ellipticCurve");
6
6
  var encode_1 = require("./encode");
@@ -52,7 +52,3 @@ function formatSignature(sig) {
52
52
  }
53
53
  }
54
54
  exports.formatSignature = formatSignature;
55
- function compileStructToCalldata(struct) {
56
- return Object.values(struct);
57
- }
58
- exports.compileStructToCalldata = compileStructToCalldata;
@@ -0,0 +1,91 @@
1
+ import { BigNumberish } from '../number';
2
+ import { TypedData } from './types';
3
+ export * from './types';
4
+ /**
5
+ * Get the dependencies of a struct type. If a struct has the same dependency multiple times, it's only included once
6
+ * in the resulting array.
7
+ *
8
+ * @param {TypedData} typedData
9
+ * @param {string} type
10
+ * @param {string[]} [dependencies]
11
+ * @return {string[]}
12
+ */
13
+ export declare const getDependencies: (typedData: TypedData, type: string, dependencies?: string[]) => string[];
14
+ /**
15
+ * Encode a type to a string. All dependant types are alphabetically sorted.
16
+ *
17
+ * @param {TypedData} typedData
18
+ * @param {string} type
19
+ * @return {string}
20
+ */
21
+ export declare const encodeType: (typedData: TypedData, type: string) => string;
22
+ /**
23
+ * Get a type string as hash.
24
+ *
25
+ * @param {TypedData} typedData
26
+ * @param {string} type
27
+ * @return {string}
28
+ */
29
+ export declare const getTypeHash: (typedData: TypedData, type: string) => string;
30
+ /**
31
+ * Encode the data to an ABI encoded Buffer. The data should be a key -> value object with all the required values. All
32
+ * dependant types are automatically encoded.
33
+ *
34
+ * @param {TypedData} typedData
35
+ * @param {string} type
36
+ * @param {Record<string, any>} data
37
+ */
38
+ export declare const encodeData: <T extends {
39
+ types: {
40
+ StarkNetDomain: {
41
+ type: string;
42
+ name: string;
43
+ }[];
44
+ } & Record<string, {
45
+ type: string;
46
+ name: string;
47
+ }[]>;
48
+ primaryType: string;
49
+ domain: {
50
+ name?: string | undefined;
51
+ version?: string | undefined;
52
+ chainId?: string | number | undefined;
53
+ };
54
+ message: Record<string, unknown>;
55
+ }>(typedData: T, type: string, data: T["message"]) => string[][];
56
+ /**
57
+ * Get encoded data as a hash. The data should be a key -> value object with all the required values. All dependant
58
+ * types are automatically encoded.
59
+ *
60
+ * @param {TypedData} typedData
61
+ * @param {string} type
62
+ * @param {Record<string, any>} data
63
+ * @return {Buffer}
64
+ */
65
+ export declare const getStructHash: <T extends {
66
+ types: {
67
+ StarkNetDomain: {
68
+ type: string;
69
+ name: string;
70
+ }[];
71
+ } & Record<string, {
72
+ type: string;
73
+ name: string;
74
+ }[]>;
75
+ primaryType: string;
76
+ domain: {
77
+ name?: string | undefined;
78
+ version?: string | undefined;
79
+ chainId?: string | number | undefined;
80
+ };
81
+ message: Record<string, unknown>;
82
+ }>(typedData: T, type: string, data: T["message"]) => string;
83
+ /**
84
+ * Get the EIP-191 encoded message to sign, from the typedData object. If `hash` is enabled, the message will be hashed
85
+ * with Keccak256.
86
+ *
87
+ * @param {TypedData} typedData
88
+ * @param {boolean} hash
89
+ * @return {string}
90
+ */
91
+ export declare const getMessageHash: (typedData: TypedData, account: BigNumberish) => string;
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ var __read = (this && this.__read) || function (o, n) {
13
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
14
+ if (!m) return o;
15
+ var i = m.call(o), r, ar = [], e;
16
+ try {
17
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
18
+ }
19
+ catch (error) { e = { error: error }; }
20
+ finally {
21
+ try {
22
+ if (r && !r.done && (m = i["return"])) m.call(i);
23
+ }
24
+ finally { if (e) throw e.error; }
25
+ }
26
+ return ar;
27
+ };
28
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
29
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
30
+ if (ar || !(i in from)) {
31
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
32
+ ar[i] = from[i];
33
+ }
34
+ }
35
+ return to.concat(ar || Array.prototype.slice.call(from));
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.getMessageHash = exports.getStructHash = exports.encodeData = exports.getTypeHash = exports.encodeType = exports.getDependencies = void 0;
39
+ var hash_1 = require("../hash");
40
+ var number_1 = require("../number");
41
+ var shortString_1 = require("../shortString");
42
+ var stark_1 = require("../stark");
43
+ var utils_1 = require("./utils");
44
+ __exportStar(require("./types"), exports);
45
+ function getHex(value) {
46
+ try {
47
+ return (0, number_1.toHex)((0, number_1.toBN)(value));
48
+ }
49
+ catch (e) {
50
+ if (typeof value === 'string') {
51
+ return (0, number_1.toHex)((0, number_1.toBN)((0, shortString_1.encodeShortString)(value)));
52
+ }
53
+ throw new Error("Invalid BigNumberish: " + value);
54
+ }
55
+ }
56
+ /**
57
+ * Get the dependencies of a struct type. If a struct has the same dependency multiple times, it's only included once
58
+ * in the resulting array.
59
+ *
60
+ * @param {TypedData} typedData
61
+ * @param {string} type
62
+ * @param {string[]} [dependencies]
63
+ * @return {string[]}
64
+ */
65
+ var getDependencies = function (typedData, type, dependencies) {
66
+ if (dependencies === void 0) { dependencies = []; }
67
+ // `getDependencies` is called by most other functions, so we validate the JSON schema here
68
+ if (!(0, utils_1.validateTypedData)(typedData)) {
69
+ throw new Error('Typed data does not match JSON schema');
70
+ }
71
+ if (dependencies.includes(type)) {
72
+ return dependencies;
73
+ }
74
+ if (!typedData.types[type]) {
75
+ return dependencies;
76
+ }
77
+ return __spreadArray([
78
+ type
79
+ ], __read(typedData.types[type].reduce(function (previous, t) { return __spreadArray(__spreadArray([], __read(previous), false), __read((0, exports.getDependencies)(typedData, t.type, previous).filter(function (dependency) { return !previous.includes(dependency); })), false); }, [])), false);
80
+ };
81
+ exports.getDependencies = getDependencies;
82
+ /**
83
+ * Encode a type to a string. All dependant types are alphabetically sorted.
84
+ *
85
+ * @param {TypedData} typedData
86
+ * @param {string} type
87
+ * @return {string}
88
+ */
89
+ var encodeType = function (typedData, type) {
90
+ var _a = __read((0, exports.getDependencies)(typedData, type)), primary = _a[0], dependencies = _a.slice(1);
91
+ var types = __spreadArray([primary], __read(dependencies.sort()), false);
92
+ return types
93
+ .map(function (dependency) {
94
+ return dependency + "(" + typedData.types[dependency].map(function (t) { return t.name + ":" + t.type; }) + ")";
95
+ })
96
+ .join('');
97
+ };
98
+ exports.encodeType = encodeType;
99
+ /**
100
+ * Get a type string as hash.
101
+ *
102
+ * @param {TypedData} typedData
103
+ * @param {string} type
104
+ * @return {string}
105
+ */
106
+ var getTypeHash = function (typedData, type) {
107
+ return (0, stark_1.getSelectorFromName)((0, exports.encodeType)(typedData, type));
108
+ };
109
+ exports.getTypeHash = getTypeHash;
110
+ /**
111
+ * Encodes a single value to an ABI serialisable string, number or Buffer. Returns the data as tuple, which consists of
112
+ * an array of ABI compatible types, and an array of corresponding values.
113
+ *
114
+ * @param {TypedData} typedData
115
+ * @param {string} type
116
+ * @param {any} data
117
+ * @returns {[string, string]}
118
+ */
119
+ var encodeValue = function (typedData, type, data) {
120
+ if (typedData.types[type]) {
121
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
122
+ return [type, (0, exports.getStructHash)(typedData, type, data)];
123
+ }
124
+ if (type === 'felt*') {
125
+ return ['felt*', (0, hash_1.computeHashOnElements)(data)];
126
+ }
127
+ return [type, getHex(data)];
128
+ };
129
+ /**
130
+ * Encode the data to an ABI encoded Buffer. The data should be a key -> value object with all the required values. All
131
+ * dependant types are automatically encoded.
132
+ *
133
+ * @param {TypedData} typedData
134
+ * @param {string} type
135
+ * @param {Record<string, any>} data
136
+ */
137
+ var encodeData = function (typedData, type, data) {
138
+ var _a = __read(typedData.types[type].reduce(function (_a, field) {
139
+ var _b = __read(_a, 2), ts = _b[0], vs = _b[1];
140
+ if (data[field.name] === undefined || data[field.name] === null) {
141
+ throw new Error("Cannot encode data: missing data for '" + field.name + "'");
142
+ }
143
+ var value = data[field.name];
144
+ var _c = __read(encodeValue(typedData, field.type, value), 2), t = _c[0], encodedValue = _c[1];
145
+ return [
146
+ __spreadArray(__spreadArray([], __read(ts), false), [t], false),
147
+ __spreadArray(__spreadArray([], __read(vs), false), [encodedValue], false),
148
+ ];
149
+ }, [['felt'], [(0, exports.getTypeHash)(typedData, type)]]), 2), types = _a[0], values = _a[1];
150
+ return [types, values];
151
+ };
152
+ exports.encodeData = encodeData;
153
+ /**
154
+ * Get encoded data as a hash. The data should be a key -> value object with all the required values. All dependant
155
+ * types are automatically encoded.
156
+ *
157
+ * @param {TypedData} typedData
158
+ * @param {string} type
159
+ * @param {Record<string, any>} data
160
+ * @return {Buffer}
161
+ */
162
+ var getStructHash = function (typedData, type, data) {
163
+ return (0, hash_1.computeHashOnElements)((0, exports.encodeData)(typedData, type, data)[1]);
164
+ };
165
+ exports.getStructHash = getStructHash;
166
+ /**
167
+ * Get the EIP-191 encoded message to sign, from the typedData object. If `hash` is enabled, the message will be hashed
168
+ * with Keccak256.
169
+ *
170
+ * @param {TypedData} typedData
171
+ * @param {boolean} hash
172
+ * @return {string}
173
+ */
174
+ var getMessageHash = function (typedData, account) {
175
+ var message = [
176
+ (0, shortString_1.encodeShortString)('StarkNet Message'),
177
+ (0, exports.getStructHash)(typedData, 'StarkNetDomain', typedData.domain),
178
+ account,
179
+ (0, exports.getStructHash)(typedData, typedData.primaryType, typedData.message),
180
+ ];
181
+ return (0, hash_1.computeHashOnElements)(message);
182
+ };
183
+ exports.getMessageHash = getMessageHash;
@@ -0,0 +1,82 @@
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
+ type: string;
15
+ name: string;
16
+ }, {
17
+ name: import("superstruct").Struct<string, null>;
18
+ type: import("superstruct").Struct<string, null>;
19
+ }>;
20
+ /**
21
+ * A single type, as part of a struct. The `type` field can be any of the EIP-712 supported types.
22
+ *
23
+ * Note that the `uint` and `int` aliases like in Solidity, and fixed point numbers are not supported by the EIP-712
24
+ * standard.
25
+ */
26
+ export declare type StarkNetType = Infer<typeof STARKNET_TYPE>;
27
+ export declare const STARKNET_DOMAIN_TYPE: import("superstruct").Struct<{
28
+ name?: string | undefined;
29
+ version?: string | undefined;
30
+ chainId?: string | number | undefined;
31
+ }, {
32
+ name: import("superstruct").Struct<string | undefined, null>;
33
+ version: import("superstruct").Struct<string | undefined, null>;
34
+ chainId: import("superstruct").Struct<string | number | undefined, null>;
35
+ }>;
36
+ /**
37
+ * The EIP712 domain struct. Any of these fields are optional, but it must contain at least one field.
38
+ */
39
+ export declare type StarkNetDomain = Infer<typeof STARKNET_DOMAIN_TYPE>;
40
+ export declare const STARKNET_TYPED_DATA_TYPE: import("superstruct").Struct<{
41
+ types: {
42
+ StarkNetDomain: {
43
+ type: string;
44
+ name: string;
45
+ }[];
46
+ } & Record<string, {
47
+ type: string;
48
+ name: string;
49
+ }[]>;
50
+ primaryType: string;
51
+ domain: {
52
+ name?: string | undefined;
53
+ version?: string | undefined;
54
+ chainId?: string | number | undefined;
55
+ };
56
+ message: Record<string, unknown>;
57
+ }, {
58
+ types: import("superstruct").Struct<{
59
+ StarkNetDomain: {
60
+ type: string;
61
+ name: string;
62
+ }[];
63
+ } & Record<string, {
64
+ type: string;
65
+ name: string;
66
+ }[]>, null>;
67
+ primaryType: import("superstruct").Struct<string, null>;
68
+ domain: import("superstruct").Struct<{
69
+ name?: string | undefined;
70
+ version?: string | undefined;
71
+ chainId?: string | number | undefined;
72
+ }, {
73
+ name: import("superstruct").Struct<string | undefined, null>;
74
+ version: import("superstruct").Struct<string | undefined, null>;
75
+ chainId: import("superstruct").Struct<string | number | undefined, null>;
76
+ }>;
77
+ message: import("superstruct").Struct<Record<string, unknown>, null>;
78
+ }>;
79
+ /**
80
+ * The complete typed data, with all the structs, domain data, primary type of the message, and the message itself.
81
+ */
82
+ export declare type TypedData = Infer<typeof STARKNET_TYPED_DATA_TYPE>;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.STARKNET_TYPED_DATA_TYPE = exports.STARKNET_DOMAIN_TYPE = exports.STARKNET_TYPE = exports.isValidType = exports.ATOMIC_TYPES = void 0;
4
+ var superstruct_1 = require("superstruct");
5
+ exports.ATOMIC_TYPES = ['felt', 'felt*'];
6
+ // Source: https://github.com/Mrtenz/eip-712/blob/master/src/eip-712.ts
7
+ // and modified to support starknet types
8
+ /**
9
+ * Checks if a type is valid with the given `typedData`. The following types are valid:
10
+ * - Atomic types: felt, felt*
11
+ * - Reference types: struct type (e.g. SomeStruct)
12
+ *
13
+ * @param {Record<string, unknown>} types
14
+ * @param {string} type
15
+ * @return {boolean}
16
+ */
17
+ var isValidType = function (types, type) {
18
+ if (exports.ATOMIC_TYPES.includes(type)) {
19
+ return true;
20
+ }
21
+ if (types[type]) {
22
+ return true;
23
+ }
24
+ return false;
25
+ };
26
+ exports.isValidType = isValidType;
27
+ var TYPE = (0, superstruct_1.refine)((0, superstruct_1.string)(), 'Type', function (type, context) {
28
+ return (0, exports.isValidType)(context.branch[0].types, type);
29
+ });
30
+ exports.STARKNET_TYPE = (0, superstruct_1.object)({
31
+ name: (0, superstruct_1.string)(),
32
+ type: TYPE,
33
+ });
34
+ exports.STARKNET_DOMAIN_TYPE = (0, superstruct_1.object)({
35
+ name: (0, superstruct_1.optional)((0, superstruct_1.string)()),
36
+ version: (0, superstruct_1.optional)((0, superstruct_1.string)()),
37
+ chainId: (0, superstruct_1.optional)((0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.number)()])),
38
+ });
39
+ exports.STARKNET_TYPED_DATA_TYPE = (0, superstruct_1.object)({
40
+ types: (0, superstruct_1.intersection)([
41
+ (0, superstruct_1.type)({ StarkNetDomain: (0, superstruct_1.array)(exports.STARKNET_TYPE) }),
42
+ (0, superstruct_1.record)((0, superstruct_1.string)(), (0, superstruct_1.array)(exports.STARKNET_TYPE)),
43
+ ]),
44
+ primaryType: (0, superstruct_1.string)(),
45
+ domain: exports.STARKNET_DOMAIN_TYPE,
46
+ message: (0, superstruct_1.object)(),
47
+ });
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Validates that `data` matches the EIP-712 JSON schema.
3
+ *
4
+ * @param {any} data
5
+ * @return {boolean}
6
+ */
7
+ export declare const validateTypedData: (data: unknown) => data is {
8
+ types: {
9
+ StarkNetDomain: {
10
+ type: string;
11
+ name: string;
12
+ }[];
13
+ } & Record<string, {
14
+ type: string;
15
+ name: string;
16
+ }[]>;
17
+ primaryType: string;
18
+ domain: {
19
+ name?: string | undefined;
20
+ version?: string | undefined;
21
+ chainId?: string | number | undefined;
22
+ };
23
+ message: Record<string, unknown>;
24
+ };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateTypedData = void 0;
4
+ var superstruct_1 = require("superstruct");
5
+ var types_1 = require("./types");
6
+ /**
7
+ * Validates that `data` matches the EIP-712 JSON schema.
8
+ *
9
+ * @param {any} data
10
+ * @return {boolean}
11
+ */
12
+ var validateTypedData = function (data) {
13
+ return (0, superstruct_1.is)(data, types_1.STARKNET_TYPED_DATA_TYPE);
14
+ };
15
+ exports.validateTypedData = validateTypedData;
package/index.d.ts CHANGED
@@ -17,3 +17,4 @@ export * as stark from './utils/stark';
17
17
  export * as ec from './utils/ellipticCurve';
18
18
  export * as uint256 from './utils/uint256';
19
19
  export * as shortString from './utils/shortString';
20
+ export * as typedData from './utils/typedData';
package/index.js CHANGED
@@ -44,7 +44,8 @@ var __importStar =
44
44
  return result;
45
45
  };
46
46
  Object.defineProperty(exports, '__esModule', { value: true });
47
- exports.shortString =
47
+ exports.typedData =
48
+ exports.shortString =
48
49
  exports.uint256 =
49
50
  exports.ec =
50
51
  exports.stark =
@@ -73,3 +74,4 @@ exports.stark = __importStar(require('./utils/stark'));
73
74
  exports.ec = __importStar(require('./utils/ellipticCurve'));
74
75
  exports.uint256 = __importStar(require('./utils/uint256'));
75
76
  exports.shortString = __importStar(require('./utils/shortString'));
77
+ exports.typedData = __importStar(require('./utils/typedData'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starknet",
3
- "version": "2.3.0",
3
+ "version": "2.6.0",
4
4
  "description": "JavaScript library for StarkNet",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -23,6 +23,7 @@
23
23
  "zk",
24
24
  "rollup"
25
25
  ],
26
+ "repository": "github:seanjameshan/starknet.js",
26
27
  "author": "Sean Han",
27
28
  "license": "MIT",
28
29
  "devDependencies": {
@@ -67,6 +68,7 @@
67
68
  "json-bigint": "^1.0.0",
68
69
  "minimalistic-assert": "^1.0.1",
69
70
  "pako": "^2.0.4",
71
+ "superstruct": "^0.15.3",
70
72
  "url-join": "^4.0.1"
71
73
  },
72
74
  "lint-staged": {
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  AddTransactionResponse,
3
+ BlockNumber,
3
4
  CallContractResponse,
4
5
  CallContractTransaction,
5
6
  CompiledContract,
@@ -8,11 +9,12 @@ import {
8
9
  GetContractAddressesResponse,
9
10
  GetTransactionResponse,
10
11
  GetTransactionStatusResponse,
12
+ Signature,
11
13
  Transaction,
12
14
  } from '../types';
13
15
  import { BigNumberish } from '../utils/number';
14
16
  import { ProviderInterface } from './interface';
15
- declare type NetworkName = 'mainnet-alpha' | 'georli-alpha';
17
+ declare type NetworkName = 'mainnet-alpha' | 'goerli-alpha';
16
18
  declare type ProviderOptions =
17
19
  | {
18
20
  network: NetworkName;
@@ -40,30 +42,33 @@ export declare class Provider implements ProviderInterface {
40
42
  *
41
43
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
42
44
  *
43
- * @param invokeTx - transaction to be invoked
44
- * @param blockId
45
+ * @param invokeTransaction - transaction to be invoked
46
+ * @param blockNumber
45
47
  * @returns the result of the function on the smart contract.
46
48
  */
47
- callContract(invokeTx: CallContractTransaction, blockId?: number): Promise<CallContractResponse>;
49
+ callContract(
50
+ invokeTransaction: CallContractTransaction,
51
+ blockNumber?: BlockNumber
52
+ ): Promise<CallContractResponse>;
48
53
  /**
49
54
  * Gets the block information from a block ID.
50
55
  *
51
56
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L27-L31)
52
57
  *
53
- * @param blockId
54
- * @returns the block object { block_id, previous_block_id, state_root, status, timestamp, transaction_receipts, transactions }
58
+ * @param blockNumber
59
+ * @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
55
60
  */
56
- getBlock(blockId?: number): Promise<GetBlockResponse>;
61
+ getBlock(blockNumber?: BlockNumber): Promise<GetBlockResponse>;
57
62
  /**
58
63
  * Gets the code of the deployed contract.
59
64
  *
60
65
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L33-L36)
61
66
  *
62
67
  * @param contractAddress
63
- * @param blockId
68
+ * @param blockNumber
64
69
  * @returns Bytecode and ABI of compiled contract
65
70
  */
66
- getCode(contractAddress: string, blockId?: number): Promise<GetCodeResponse>;
71
+ getCode(contractAddress: string, blockNumber?: BlockNumber): Promise<GetCodeResponse>;
67
72
  /**
68
73
  * Gets the contract's storage variable at a specific key.
69
74
  *
@@ -71,17 +76,17 @@ export declare class Provider implements ProviderInterface {
71
76
  *
72
77
  * @param contractAddress
73
78
  * @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
74
- * @param blockId
79
+ * @param blockNumber
75
80
  * @returns the value of the storage variable
76
81
  */
77
- getStorageAt(contractAddress: string, key: number, blockId?: number): Promise<object>;
82
+ getStorageAt(contractAddress: string, key: number, blockNumber?: BlockNumber): Promise<object>;
78
83
  /**
79
84
  * Gets the status of a transaction.
80
85
  *
81
86
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L48-L52)
82
87
  *
83
88
  * @param txHash
84
- * @returns the transaction status object { block_id, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN }
89
+ * @returns the transaction status object { block_number, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN }
85
90
  */
86
91
  getTransactionStatus(txHash: BigNumberish): Promise<GetTransactionStatusResponse>;
87
92
  /**
@@ -90,7 +95,7 @@ export declare class Provider implements ProviderInterface {
90
95
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L54-L58)
91
96
  *
92
97
  * @param txHash
93
- * @returns the transacton object { transaction_id, status, transaction, block_id?, block_number?, transaction_index?, transaction_failure_reason? }
98
+ * @returns the transacton object { transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? }
94
99
  */
95
100
  getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
96
101
  /**
@@ -98,10 +103,10 @@ export declare class Provider implements ProviderInterface {
98
103
  *
99
104
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
100
105
  *
101
- * @param tx - transaction to be invoked
106
+ * @param transaction - transaction to be invoked
102
107
  * @returns a confirmation of invoking a function on the starknet contract
103
108
  */
104
- addTransaction(tx: Transaction): Promise<AddTransactionResponse>;
109
+ addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
105
110
  /**
106
111
  * Deploys a given compiled contract (json) to starknet
107
112
  *
@@ -127,7 +132,7 @@ export declare class Provider implements ProviderInterface {
127
132
  contractAddress: string,
128
133
  entrypointSelector: string,
129
134
  calldata?: string[],
130
- signature?: [BigNumberish, BigNumberish]
135
+ signature?: Signature
131
136
  ): Promise<AddTransactionResponse>;
132
137
  waitForTx(txHash: BigNumberish, retryInterval?: number): Promise<void>;
133
138
  }