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 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]: string | 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
- if (args[input.name] !== undefined) {
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 args[input.name] === 'string',
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(args[input.name]),
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(args[input.name]),
307
+ Array.isArray(arg),
290
308
  'arg ' + input.name + ' should be a felt* (string[])'
291
309
  );
292
- args[input.name].forEach(function (felt, i) {
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,
@@ -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
- if (args[input.name] !== undefined) {
158
+ var arg = args[input.name];
159
+ if (arg !== undefined) {
149
160
  if (input.type === 'felt') {
150
- (0, minimalistic_assert_1.default)(typeof args[input.name] === 'string', "arg " + input.name + " should be a felt (string)");
151
- (0, minimalistic_assert_1.default)(isFelt(args[input.name]), "arg " + input.name + " should be decimal or hexadecimal");
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(args[input.name]), "arg " + input.name + " should be a felt* (string[])");
155
- args[input.name].forEach(function (felt, i) {
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
  });
@@ -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[];
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starknet",
3
- "version": "2.3.0",
3
+ "version": "2.3.1",
4
4
  "description": "JavaScript library for StarkNet",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
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 = { [inputName: string]: string | string[] };
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
- if (args[input.name] !== undefined) {
97
+ const arg = args[input.name];
98
+ if (arg !== undefined) {
92
99
  if (input.type === 'felt') {
93
- assert(
94
- typeof args[input.name] === 'string',
95
- `arg ${input.name} should be a felt (string)`
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(args[input.name]), `arg ${input.name} should be a felt* (string[])`);
103
- (args[input.name] as string[]).forEach((felt, i) => {
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[])`
@@ -49,7 +49,3 @@ export function formatSignature(sig?: [BigNumberish, BigNumberish]): [string, st
49
49
  return [];
50
50
  }
51
51
  }
52
-
53
- export function compileStructToCalldata<S extends { [k: string]: string }>(struct: S): string[] {
54
- return Object.values(struct);
55
- }
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.compileStructToCalldata =
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;