starknet 2.3.0 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/contract.d.ts +7 -1
- package/contract.js +23 -5
- package/dist/contract.d.ts +4 -1
- package/dist/contract.js +19 -5
- package/dist/utils/stark.d.ts +0 -3
- package/dist/utils/stark.js +1 -5
- package/package.json +1 -1
- package/src/contract.ts +15 -12
- package/src/utils/stark.ts +0 -4
- package/utils/stark.d.ts +0 -5
- package/utils/stark.js +1 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
## [2.3.1](https://github.com/seanjameshan/starknet.js/compare/v2.3.0...v2.3.1) (2021-12-01)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
- allow structs in calldata ([fd2bdc0](https://github.com/seanjameshan/starknet.js/commit/fd2bdc0a1756544e4162fa5baaa7d3aec6f97bee))
|
|
6
|
+
- struct compiling ([84617ae](https://github.com/seanjameshan/starknet.js/commit/84617aefe1218f421ca446b2a3c9959252d326e6))
|
|
7
|
+
- struct data ([313dff5](https://github.com/seanjameshan/starknet.js/commit/313dff57f54050747c65b32b3378762c349d9c8c))
|
|
8
|
+
- uint256 type ([2e05902](https://github.com/seanjameshan/starknet.js/commit/2e05902268f76bda2ae9b4e75782fa78876c2f00))
|
|
9
|
+
|
|
1
10
|
# [2.3.0](https://github.com/seanjameshan/starknet.js/compare/v2.2.0...v2.3.0) (2021-12-01)
|
|
2
11
|
|
|
3
12
|
### Features
|
package/contract.d.ts
CHANGED
|
@@ -2,7 +2,13 @@ import { Provider } from './provider';
|
|
|
2
2
|
import { Abi, StructAbi } from './types';
|
|
3
3
|
import { BigNumberish } from './utils/number';
|
|
4
4
|
export declare type Args = {
|
|
5
|
-
[inputName: string]:
|
|
5
|
+
[inputName: string]:
|
|
6
|
+
| string
|
|
7
|
+
| string[]
|
|
8
|
+
| {
|
|
9
|
+
type: 'struct';
|
|
10
|
+
[k: string]: BigNumberish;
|
|
11
|
+
};
|
|
6
12
|
};
|
|
7
13
|
export declare type Calldata = string[];
|
|
8
14
|
export declare function compileCalldata(args: Args): Calldata;
|
package/contract.js
CHANGED
|
@@ -216,6 +216,18 @@ function compileCalldata(args) {
|
|
|
216
216
|
),
|
|
217
217
|
false
|
|
218
218
|
);
|
|
219
|
+
if (typeof value === 'object' && 'type' in value)
|
|
220
|
+
return Object.entries(value)
|
|
221
|
+
.filter(function (_a) {
|
|
222
|
+
var _b = __read(_a, 1),
|
|
223
|
+
k = _b[0];
|
|
224
|
+
return k !== 'type';
|
|
225
|
+
})
|
|
226
|
+
.map(function (_a) {
|
|
227
|
+
var _b = __read(_a, 2),
|
|
228
|
+
v = _b[1];
|
|
229
|
+
return (0, number_1.toBN)(v).toString();
|
|
230
|
+
});
|
|
219
231
|
return (0, number_1.toBN)(value).toString();
|
|
220
232
|
});
|
|
221
233
|
}
|
|
@@ -274,22 +286,28 @@ var Contract = /** @class */ (function () {
|
|
|
274
286
|
return abi.name === method && abi.type === 'function';
|
|
275
287
|
});
|
|
276
288
|
methodAbi.inputs.forEach(function (input) {
|
|
277
|
-
|
|
289
|
+
var arg = args[input.name];
|
|
290
|
+
if (arg !== undefined) {
|
|
278
291
|
if (input.type === 'felt') {
|
|
279
292
|
(0, minimalistic_assert_1.default)(
|
|
280
|
-
typeof
|
|
293
|
+
typeof arg === 'string',
|
|
281
294
|
'arg ' + input.name + ' should be a felt (string)'
|
|
282
295
|
);
|
|
283
296
|
(0, minimalistic_assert_1.default)(
|
|
284
|
-
isFelt(
|
|
297
|
+
isFelt(arg),
|
|
285
298
|
'arg ' + input.name + ' should be decimal or hexadecimal'
|
|
286
299
|
);
|
|
300
|
+
} else if (typeof arg === 'object' && 'type' in arg) {
|
|
301
|
+
(0, minimalistic_assert_1.default)(
|
|
302
|
+
arg.type === 'struct',
|
|
303
|
+
'arg ' + input.name + ' should be a struct'
|
|
304
|
+
);
|
|
287
305
|
} else {
|
|
288
306
|
(0, minimalistic_assert_1.default)(
|
|
289
|
-
Array.isArray(
|
|
307
|
+
Array.isArray(arg),
|
|
290
308
|
'arg ' + input.name + ' should be a felt* (string[])'
|
|
291
309
|
);
|
|
292
|
-
|
|
310
|
+
arg.forEach(function (felt, i) {
|
|
293
311
|
(0,
|
|
294
312
|
minimalistic_assert_1.default)(typeof felt === 'string', 'arg ' + input.name + '[' + i + '] should be a felt (string) as part of a felt* (string[])');
|
|
295
313
|
(0,
|
package/dist/contract.d.ts
CHANGED
|
@@ -2,7 +2,10 @@ import { Provider } from './provider';
|
|
|
2
2
|
import { Abi, StructAbi } from './types';
|
|
3
3
|
import { BigNumberish } from './utils/number';
|
|
4
4
|
export declare type Args = {
|
|
5
|
-
[inputName: string]: string | string[]
|
|
5
|
+
[inputName: string]: string | string[] | {
|
|
6
|
+
type: 'struct';
|
|
7
|
+
[k: string]: BigNumberish;
|
|
8
|
+
};
|
|
6
9
|
};
|
|
7
10
|
export declare type Calldata = string[];
|
|
8
11
|
export declare function compileCalldata(args: Args): Calldata;
|
package/dist/contract.js
CHANGED
|
@@ -101,6 +101,16 @@ function compileCalldata(args) {
|
|
|
101
101
|
return Object.values(args).flatMap(function (value) {
|
|
102
102
|
if (Array.isArray(value))
|
|
103
103
|
return __spreadArray([(0, number_1.toBN)(value.length).toString()], __read(value.map(function (x) { return (0, number_1.toBN)(x).toString(); })), false);
|
|
104
|
+
if (typeof value === 'object' && 'type' in value)
|
|
105
|
+
return Object.entries(value)
|
|
106
|
+
.filter(function (_a) {
|
|
107
|
+
var _b = __read(_a, 1), k = _b[0];
|
|
108
|
+
return k !== 'type';
|
|
109
|
+
})
|
|
110
|
+
.map(function (_a) {
|
|
111
|
+
var _b = __read(_a, 2), v = _b[1];
|
|
112
|
+
return (0, number_1.toBN)(v).toString();
|
|
113
|
+
});
|
|
104
114
|
return (0, number_1.toBN)(value).toString();
|
|
105
115
|
});
|
|
106
116
|
}
|
|
@@ -145,14 +155,18 @@ var Contract = /** @class */ (function () {
|
|
|
145
155
|
// ensure args match abi type
|
|
146
156
|
var methodAbi = this.abi.find(function (abi) { return abi.name === method && abi.type === 'function'; });
|
|
147
157
|
methodAbi.inputs.forEach(function (input) {
|
|
148
|
-
|
|
158
|
+
var arg = args[input.name];
|
|
159
|
+
if (arg !== undefined) {
|
|
149
160
|
if (input.type === 'felt') {
|
|
150
|
-
(0, minimalistic_assert_1.default)(typeof
|
|
151
|
-
(0, minimalistic_assert_1.default)(isFelt(
|
|
161
|
+
(0, minimalistic_assert_1.default)(typeof arg === 'string', "arg " + input.name + " should be a felt (string)");
|
|
162
|
+
(0, minimalistic_assert_1.default)(isFelt(arg), "arg " + input.name + " should be decimal or hexadecimal");
|
|
163
|
+
}
|
|
164
|
+
else if (typeof arg === 'object' && 'type' in arg) {
|
|
165
|
+
(0, minimalistic_assert_1.default)(arg.type === 'struct', "arg " + input.name + " should be a struct");
|
|
152
166
|
}
|
|
153
167
|
else {
|
|
154
|
-
(0, minimalistic_assert_1.default)(Array.isArray(
|
|
155
|
-
|
|
168
|
+
(0, minimalistic_assert_1.default)(Array.isArray(arg), "arg " + input.name + " should be a felt* (string[])");
|
|
169
|
+
arg.forEach(function (felt, i) {
|
|
156
170
|
(0, minimalistic_assert_1.default)(typeof felt === 'string', "arg " + input.name + "[" + i + "] should be a felt (string) as part of a felt* (string[])");
|
|
157
171
|
(0, minimalistic_assert_1.default)(isFelt(felt), "arg " + input.name + "[" + i + "] should be decimal or hexadecimal as part of a felt* (string[])");
|
|
158
172
|
});
|
package/dist/utils/stark.d.ts
CHANGED
|
@@ -19,6 +19,3 @@ export declare function getSelectorFromName(funcName: string): string;
|
|
|
19
19
|
export declare function randomAddress(): string;
|
|
20
20
|
export declare function makeAddress(input: string): string;
|
|
21
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[];
|
package/dist/utils/stark.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
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;
|
package/package.json
CHANGED
package/src/contract.ts
CHANGED
|
@@ -6,7 +6,9 @@ import { Abi, AbiEntry, FunctionAbi, StructAbi } from './types';
|
|
|
6
6
|
import { BigNumberish, toBN } from './utils/number';
|
|
7
7
|
import { getSelectorFromName } from './utils/stark';
|
|
8
8
|
|
|
9
|
-
export type Args = {
|
|
9
|
+
export type Args = {
|
|
10
|
+
[inputName: string]: string | string[] | { type: 'struct'; [k: string]: BigNumberish };
|
|
11
|
+
};
|
|
10
12
|
export type Calldata = string[];
|
|
11
13
|
|
|
12
14
|
function parseFelt(candidate: string): BN {
|
|
@@ -30,6 +32,10 @@ export function compileCalldata(args: Args): Calldata {
|
|
|
30
32
|
return Object.values(args).flatMap((value) => {
|
|
31
33
|
if (Array.isArray(value))
|
|
32
34
|
return [toBN(value.length).toString(), ...value.map((x) => toBN(x).toString())];
|
|
35
|
+
if (typeof value === 'object' && 'type' in value)
|
|
36
|
+
return Object.entries(value)
|
|
37
|
+
.filter(([k]) => k !== 'type')
|
|
38
|
+
.map(([, v]) => toBN(v).toString());
|
|
33
39
|
return toBN(value).toString();
|
|
34
40
|
});
|
|
35
41
|
}
|
|
@@ -88,19 +94,16 @@ export class Contract {
|
|
|
88
94
|
(abi) => abi.name === method && abi.type === 'function'
|
|
89
95
|
) as FunctionAbi;
|
|
90
96
|
methodAbi.inputs.forEach((input) => {
|
|
91
|
-
|
|
97
|
+
const arg = args[input.name];
|
|
98
|
+
if (arg !== undefined) {
|
|
92
99
|
if (input.type === 'felt') {
|
|
93
|
-
assert(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
);
|
|
97
|
-
assert(
|
|
98
|
-
isFelt(args[input.name] as string),
|
|
99
|
-
`arg ${input.name} should be decimal or hexadecimal`
|
|
100
|
-
);
|
|
100
|
+
assert(typeof arg === 'string', `arg ${input.name} should be a felt (string)`);
|
|
101
|
+
assert(isFelt(arg as string), `arg ${input.name} should be decimal or hexadecimal`);
|
|
102
|
+
} else if (typeof arg === 'object' && 'type' in arg) {
|
|
103
|
+
assert(arg.type === 'struct', `arg ${input.name} should be a struct`);
|
|
101
104
|
} else {
|
|
102
|
-
assert(Array.isArray(
|
|
103
|
-
(
|
|
105
|
+
assert(Array.isArray(arg), `arg ${input.name} should be a felt* (string[])`);
|
|
106
|
+
(arg as string[]).forEach((felt, i) => {
|
|
104
107
|
assert(
|
|
105
108
|
typeof felt === 'string',
|
|
106
109
|
`arg ${input.name}[${i}] should be a felt (string) as part of a felt* (string[])`
|
package/src/utils/stark.ts
CHANGED
package/utils/stark.d.ts
CHANGED
|
@@ -19,8 +19,3 @@ export declare function getSelectorFromName(funcName: string): string;
|
|
|
19
19
|
export declare function randomAddress(): string;
|
|
20
20
|
export declare function makeAddress(input: string): string;
|
|
21
21
|
export declare function formatSignature(sig?: [BigNumberish, BigNumberish]): [string, string] | [];
|
|
22
|
-
export declare function compileStructToCalldata<
|
|
23
|
-
S extends {
|
|
24
|
-
[k: string]: string;
|
|
25
|
-
}
|
|
26
|
-
>(struct: S): string[];
|
package/utils/stark.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.formatSignature =
|
|
3
|
+
exports.formatSignature =
|
|
5
4
|
exports.makeAddress =
|
|
6
5
|
exports.randomAddress =
|
|
7
6
|
exports.getSelectorFromName =
|
|
@@ -63,7 +62,3 @@ function formatSignature(sig) {
|
|
|
63
62
|
}
|
|
64
63
|
}
|
|
65
64
|
exports.formatSignature = formatSignature;
|
|
66
|
-
function compileStructToCalldata(struct) {
|
|
67
|
-
return Object.values(struct);
|
|
68
|
-
}
|
|
69
|
-
exports.compileStructToCalldata = compileStructToCalldata;
|