starknet 2.1.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,49 @@
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
+
10
+ # [2.3.0](https://github.com/seanjameshan/starknet.js/compare/v2.2.0...v2.3.0) (2021-12-01)
11
+
12
+ ### Features
13
+
14
+ - add compileStructToCalldata ([e5bdb18](https://github.com/seanjameshan/starknet.js/commit/e5bdb1890e0bc53b03d4b145069cf7fbc639e830))
15
+ - **utils:** support shortstring and uint256 ([f7ff057](https://github.com/seanjameshan/starknet.js/commit/f7ff05753d9bc39b31bdd4e7f893ee04cab77823))
16
+
17
+ # [2.2.0](https://github.com/seanjameshan/starknet.js/compare/v2.1.0...v2.2.0) (2021-11-30)
18
+
19
+ ### Bug Fixes
20
+
21
+ - bump version ([02c8d07](https://github.com/seanjameshan/starknet.js/commit/02c8d0772e42c81e35a3a841169eb25cde68716e))
22
+ - correctly parse structs in Starknet return types ([5a4a318](https://github.com/seanjameshan/starknet.js/commit/5a4a318dad4c78fe84540ad92063fc1879317ac1))
23
+ - make Typescript compiler happy with constant types ([aedd895](https://github.com/seanjameshan/starknet.js/commit/aedd895a62e6018dd1d7330b004d54360007967f))
24
+ - use urljoin ([4f1a040](https://github.com/seanjameshan/starknet.js/commit/4f1a04090f26f8e8565c516921d5d3332b6a4649))
25
+
26
+ ### Features
27
+
28
+ - bump version ([fd22f41](https://github.com/seanjameshan/starknet.js/commit/fd22f41e39ec1c7f71c32019309f82ad0f4d66a9))
29
+
30
+ ## [2.1.1](https://github.com/seanjameshan/starknet.js/compare/v2.1.0...v2.1.1) (2021-11-30)
31
+
32
+ ### Bug Fixes
33
+
34
+ - bump version ([02c8d07](https://github.com/seanjameshan/starknet.js/commit/02c8d0772e42c81e35a3a841169eb25cde68716e))
35
+ - correctly parse structs in Starknet return types ([5a4a318](https://github.com/seanjameshan/starknet.js/commit/5a4a318dad4c78fe84540ad92063fc1879317ac1))
36
+ - make Typescript compiler happy with constant types ([aedd895](https://github.com/seanjameshan/starknet.js/commit/aedd895a62e6018dd1d7330b004d54360007967f))
37
+ - use urljoin ([4f1a040](https://github.com/seanjameshan/starknet.js/commit/4f1a04090f26f8e8565c516921d5d3332b6a4649))
38
+
39
+ ## [2.1.1](https://github.com/seanjameshan/starknet.js/compare/v2.1.0...v2.1.1) (2021-11-30)
40
+
41
+ ### Bug Fixes
42
+
43
+ - correctly parse structs in Starknet return types ([5a4a318](https://github.com/seanjameshan/starknet.js/commit/5a4a318dad4c78fe84540ad92063fc1879317ac1))
44
+ - make Typescript compiler happy with constant types ([aedd895](https://github.com/seanjameshan/starknet.js/commit/aedd895a62e6018dd1d7330b004d54360007967f))
45
+ - use urljoin ([4f1a040](https://github.com/seanjameshan/starknet.js/commit/4f1a04090f26f8e8565c516921d5d3332b6a4649))
46
+
1
47
  # [2.1.0](https://github.com/seanjameshan/starknet.js/compare/v2.0.1...v2.1.0) (2021-11-30)
2
48
 
3
49
  ### Bug Fixes
@@ -9,6 +55,13 @@
9
55
 
10
56
  - support mainnet ([de07149](https://github.com/seanjameshan/starknet.js/commit/de07149ad6521edc9f79e2b0e9c82bf40f32fe02))
11
57
 
58
+ ## [2.0.2](https://github.com/seanjameshan/starknet.js/compare/v2.0.1...v2.0.2) (2021-11-22)
59
+
60
+ ### Bug Fixes
61
+
62
+ - correctly parse structs in Starknet return types ([5a4a318](https://github.com/seanjameshan/starknet.js/commit/5a4a318dad4c78fe84540ad92063fc1879317ac1))
63
+ - make Typescript compiler happy with constant types ([aedd895](https://github.com/seanjameshan/starknet.js/commit/aedd895a62e6018dd1d7330b004d54360007967f))
64
+
12
65
  ## [2.0.1](https://github.com/seanjameshan/starknet.js/compare/v2.0.0...v2.0.1) (2021-11-18)
13
66
 
14
67
  ### Bug Fixes
@@ -0,0 +1,22 @@
1
+ import { decodeShortString, encodeShortString } from '../../src/utils/shortString';
2
+
3
+ describe('shortString', () => {
4
+ test('should convert string to number', () => {
5
+ expect(encodeShortString('hello')).toMatchInlineSnapshot(`"0x68656c6c6f"`);
6
+ });
7
+ test('should convert number to string', () => {
8
+ expect(decodeShortString('0x68656c6c6f')).toMatchInlineSnapshot(`"hello"`);
9
+ });
10
+ test('should throw if string is too long', () => {
11
+ expect(() =>
12
+ encodeShortString('hello world hello world hello world hello world hello world hello world')
13
+ ).toThrowErrorMatchingInlineSnapshot(
14
+ `"hello world hello world hello world hello world hello world hello world is too long"`
15
+ );
16
+ });
17
+ test('should throw if string contains non ascii chars', () => {
18
+ expect(() => encodeShortString('hello\uD83D\uDE00')).toThrowErrorMatchingInlineSnapshot(
19
+ `"hello😀 is not an ASCII string"`
20
+ );
21
+ });
22
+ });
@@ -0,0 +1,32 @@
1
+ import { ONE } from '../../src/constants';
2
+ import { toBN } from '../../src/utils/number';
3
+ import { UINT_128_MAX, UINT_256_MAX, bnToUint256, uint256ToBN } from '../../src/utils/uint256';
4
+
5
+ describe('cairo uint256', () => {
6
+ test('should convert 0 from BN to uint256 struct', () => {
7
+ const uint256 = bnToUint256('0');
8
+ expect(uint256).toMatchInlineSnapshot(`
9
+ Object {
10
+ "high": "0x0",
11
+ "low": "0x0",
12
+ }
13
+ `);
14
+ });
15
+ test('should convert 0 from uint256 to BN', () => {
16
+ expect(uint256ToBN({ low: '0x0', high: '0x0' }).toString()).toMatchInlineSnapshot(`"0"`);
17
+ });
18
+ test('should convert BN over 2^128 to uint256 struct', () => {
19
+ const uint256 = bnToUint256(UINT_128_MAX.add(ONE));
20
+ expect(uint256).toMatchInlineSnapshot(`
21
+ Object {
22
+ "high": "0x1",
23
+ "low": "0x0",
24
+ }
25
+ `);
26
+ });
27
+ test('should throw if BN over uint256 range', () => {
28
+ expect(() => bnToUint256(UINT_256_MAX.add(toBN(1)))).toThrowErrorMatchingInlineSnapshot(
29
+ `"Number is too large"`
30
+ );
31
+ });
32
+ });
package/contract.d.ts CHANGED
@@ -1,14 +1,23 @@
1
1
  import { Provider } from './provider';
2
- import { Abi } from './types';
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;
9
15
  export declare class Contract {
10
16
  connectedTo: string | null;
11
17
  abi: Abi[];
18
+ structs: {
19
+ [name: string]: StructAbi;
20
+ };
12
21
  provider: Provider;
13
22
  /**
14
23
  * Contract class to handle contract methods
@@ -19,6 +28,7 @@ export declare class Contract {
19
28
  constructor(abi: Abi[], address?: string | null, provider?: Provider);
20
29
  connect(address: string): Contract;
21
30
  private validateMethodAndArgs;
31
+ private parseResponseField;
22
32
  private parseResponse;
23
33
  invoke(
24
34
  method: string,
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
  }
@@ -238,6 +250,14 @@ var Contract = /** @class */ (function () {
238
250
  this.connectedTo = address;
239
251
  this.provider = provider;
240
252
  this.abi = abi;
253
+ this.structs = abi
254
+ .filter(function (abiEntry) {
255
+ return abiEntry.type === 'struct';
256
+ })
257
+ .reduce(function (acc, abiEntry) {
258
+ var _a;
259
+ return __assign(__assign({}, acc), ((_a = {}), (_a[abiEntry.name] = abiEntry), _a));
260
+ }, {});
241
261
  }
242
262
  Contract.prototype.connect = function (address) {
243
263
  this.connectedTo = address;
@@ -250,9 +270,9 @@ var Contract = /** @class */ (function () {
250
270
  // ensure provided method exists
251
271
  var invokeableFunctionNames = this.abi
252
272
  .filter(function (abi) {
273
+ if (abi.type !== 'function') return false;
253
274
  var isView = abi.stateMutability === 'view';
254
- var isFunction = abi.type === 'function';
255
- return isFunction && type === 'INVOKE' ? !isView : isView;
275
+ return type === 'INVOKE' ? !isView : isView;
256
276
  })
257
277
  .map(function (abi) {
258
278
  return abi.name;
@@ -263,25 +283,31 @@ var Contract = /** @class */ (function () {
263
283
  );
264
284
  // ensure args match abi type
265
285
  var methodAbi = this.abi.find(function (abi) {
266
- return abi.name === method;
286
+ return abi.name === method && abi.type === 'function';
267
287
  });
268
288
  methodAbi.inputs.forEach(function (input) {
269
- if (args[input.name] !== undefined) {
289
+ var arg = args[input.name];
290
+ if (arg !== undefined) {
270
291
  if (input.type === 'felt') {
271
292
  (0, minimalistic_assert_1.default)(
272
- typeof args[input.name] === 'string',
293
+ typeof arg === 'string',
273
294
  'arg ' + input.name + ' should be a felt (string)'
274
295
  );
275
296
  (0, minimalistic_assert_1.default)(
276
- isFelt(args[input.name]),
297
+ isFelt(arg),
277
298
  'arg ' + input.name + ' should be decimal or hexadecimal'
278
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
+ );
279
305
  } else {
280
306
  (0, minimalistic_assert_1.default)(
281
- Array.isArray(args[input.name]),
307
+ Array.isArray(arg),
282
308
  'arg ' + input.name + ' should be a felt* (string[])'
283
309
  );
284
- args[input.name].forEach(function (felt, i) {
310
+ arg.forEach(function (felt, i) {
285
311
  (0,
286
312
  minimalistic_assert_1.default)(typeof felt === 'string', 'arg ' + input.name + '[' + i + '] should be a felt (string) as part of a felt* (string[])');
287
313
  (0,
@@ -291,14 +317,31 @@ var Contract = /** @class */ (function () {
291
317
  }
292
318
  });
293
319
  };
320
+ Contract.prototype.parseResponseField = function (element, responseIterator) {
321
+ var _this = this;
322
+ var entries = [];
323
+ if (['felt', 'felt*'].includes(element.type)) {
324
+ return responseIterator.next().value;
325
+ }
326
+ if (element.type in this.structs) {
327
+ entries = this.structs[element.type].members;
328
+ } else if ('outputs' in element) {
329
+ entries = element.outputs;
330
+ }
331
+ return entries.reduce(function (acc, member) {
332
+ var _a;
333
+ return __assign(
334
+ __assign({}, acc),
335
+ ((_a = {}), (_a[member.name] = _this.parseResponseField(member, responseIterator)), _a)
336
+ );
337
+ }, {});
338
+ };
294
339
  Contract.prototype.parseResponse = function (method, response) {
295
340
  var methodAbi = this.abi.find(function (abi) {
296
341
  return abi.name === method;
297
342
  });
298
- return methodAbi.outputs.reduce(function (acc, output, i) {
299
- var _a;
300
- return __assign(__assign({}, acc), ((_a = {}), (_a[output.name] = response[i]), _a));
301
- }, {});
343
+ var responseIterator = response.flat()[Symbol.iterator]();
344
+ return this.parseResponseField(methodAbi, responseIterator);
302
345
  };
303
346
  Contract.prototype.invoke = function (method, args, signature) {
304
347
  if (args === void 0) {
@@ -1,14 +1,20 @@
1
1
  import { Provider } from './provider';
2
- import { Abi } from './types';
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;
9
12
  export declare class Contract {
10
13
  connectedTo: string | null;
11
14
  abi: Abi[];
15
+ structs: {
16
+ [name: string]: StructAbi;
17
+ };
12
18
  provider: Provider;
13
19
  /**
14
20
  * Contract class to handle contract methods
@@ -19,6 +25,7 @@ export declare class Contract {
19
25
  constructor(abi: Abi[], address?: string | null, provider?: Provider);
20
26
  connect(address: string): Contract;
21
27
  private validateMethodAndArgs;
28
+ private parseResponseField;
22
29
  private parseResponse;
23
30
  invoke(method: string, args?: Args, signature?: [BigNumberish, BigNumberish]): Promise<import("./types").AddTransactionResponse>;
24
31
  call(method: string, args?: Args): Promise<Args>;
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
  }
@@ -119,6 +129,12 @@ var Contract = /** @class */ (function () {
119
129
  this.connectedTo = address;
120
130
  this.provider = provider;
121
131
  this.abi = abi;
132
+ this.structs = abi
133
+ .filter(function (abiEntry) { return abiEntry.type === 'struct'; })
134
+ .reduce(function (acc, abiEntry) {
135
+ var _a;
136
+ return (__assign(__assign({}, acc), (_a = {}, _a[abiEntry.name] = abiEntry, _a)));
137
+ }, {});
122
138
  }
123
139
  Contract.prototype.connect = function (address) {
124
140
  this.connectedTo = address;
@@ -129,23 +145,28 @@ var Contract = /** @class */ (function () {
129
145
  // ensure provided method exists
130
146
  var invokeableFunctionNames = this.abi
131
147
  .filter(function (abi) {
148
+ if (abi.type !== 'function')
149
+ return false;
132
150
  var isView = abi.stateMutability === 'view';
133
- var isFunction = abi.type === 'function';
134
- return isFunction && type === 'INVOKE' ? !isView : isView;
151
+ return type === 'INVOKE' ? !isView : isView;
135
152
  })
136
153
  .map(function (abi) { return abi.name; });
137
154
  (0, minimalistic_assert_1.default)(invokeableFunctionNames.includes(method), (type === 'INVOKE' ? 'invokeable' : 'viewable') + " method not found in abi");
138
155
  // ensure args match abi type
139
- var methodAbi = this.abi.find(function (abi) { return abi.name === method; });
156
+ var methodAbi = this.abi.find(function (abi) { return abi.name === method && abi.type === 'function'; });
140
157
  methodAbi.inputs.forEach(function (input) {
141
- if (args[input.name] !== undefined) {
158
+ var arg = args[input.name];
159
+ if (arg !== undefined) {
142
160
  if (input.type === 'felt') {
143
- (0, minimalistic_assert_1.default)(typeof args[input.name] === 'string', "arg " + input.name + " should be a felt (string)");
144
- (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");
145
166
  }
146
167
  else {
147
- (0, minimalistic_assert_1.default)(Array.isArray(args[input.name]), "arg " + input.name + " should be a felt* (string[])");
148
- 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) {
149
170
  (0, minimalistic_assert_1.default)(typeof felt === 'string', "arg " + input.name + "[" + i + "] should be a felt (string) as part of a felt* (string[])");
150
171
  (0, minimalistic_assert_1.default)(isFelt(felt), "arg " + input.name + "[" + i + "] should be decimal or hexadecimal as part of a felt* (string[])");
151
172
  });
@@ -153,13 +174,28 @@ var Contract = /** @class */ (function () {
153
174
  }
154
175
  });
155
176
  };
156
- Contract.prototype.parseResponse = function (method, response) {
157
- var methodAbi = this.abi.find(function (abi) { return abi.name === method; });
158
- return methodAbi.outputs.reduce(function (acc, output, i) {
177
+ Contract.prototype.parseResponseField = function (element, responseIterator) {
178
+ var _this = this;
179
+ var entries = [];
180
+ if (['felt', 'felt*'].includes(element.type)) {
181
+ return responseIterator.next().value;
182
+ }
183
+ if (element.type in this.structs) {
184
+ entries = this.structs[element.type].members;
185
+ }
186
+ else if ('outputs' in element) {
187
+ entries = element.outputs;
188
+ }
189
+ return entries.reduce(function (acc, member) {
159
190
  var _a;
160
- return __assign(__assign({}, acc), (_a = {}, _a[output.name] = response[i], _a));
191
+ return (__assign(__assign({}, acc), (_a = {}, _a[member.name] = _this.parseResponseField(member, responseIterator), _a)));
161
192
  }, {});
162
193
  };
194
+ Contract.prototype.parseResponse = function (method, response) {
195
+ var methodAbi = this.abi.find(function (abi) { return abi.name === method; });
196
+ var responseIterator = response.flat()[Symbol.iterator]();
197
+ return this.parseResponseField(methodAbi, responseIterator);
198
+ };
163
199
  Contract.prototype.invoke = function (method, args, signature) {
164
200
  if (args === void 0) { args = {}; }
165
201
  // ensure contract is connected
package/dist/index.d.ts CHANGED
@@ -15,3 +15,5 @@ export * as json from './utils/json';
15
15
  export * as number from './utils/number';
16
16
  export * as stark from './utils/stark';
17
17
  export * as ec from './utils/ellipticCurve';
18
+ export * as uint256 from './utils/uint256';
19
+ export * as shortString from './utils/shortString';
package/dist/index.js CHANGED
@@ -22,7 +22,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  return result;
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.ec = exports.stark = exports.number = exports.json = exports.hash = exports.encode = exports.constants = void 0;
25
+ exports.shortString = exports.uint256 = exports.ec = exports.stark = exports.number = exports.json = exports.hash = exports.encode = exports.constants = void 0;
26
26
  /**
27
27
  * Main
28
28
  */
@@ -40,3 +40,5 @@ exports.json = __importStar(require("./utils/json"));
40
40
  exports.number = __importStar(require("./utils/number"));
41
41
  exports.stark = __importStar(require("./utils/stark"));
42
42
  exports.ec = __importStar(require("./utils/ellipticCurve"));
43
+ exports.uint256 = __importStar(require("./utils/uint256"));
44
+ exports.shortString = __importStar(require("./utils/shortString"));
@@ -12,7 +12,7 @@ export declare class Provider implements ProviderInterface {
12
12
  feederGatewayUrl: string;
13
13
  gatewayUrl: string;
14
14
  constructor(optionsOrProvider?: ProviderOptions | Provider);
15
- protected static getNetworkFromName(name: NetworkName): "http://alpha-mainnet.starknet.io/" | "https://alpha4.starknet.io";
15
+ protected static getNetworkFromName(name: NetworkName): "https://alpha-mainnet.starknet.io" | "https://alpha4.starknet.io";
16
16
  /**
17
17
  * Gets the smart contract address on the goerli testnet.
18
18
  *
@@ -52,6 +52,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
52
52
  Object.defineProperty(exports, "__esModule", { value: true });
53
53
  exports.Provider = void 0;
54
54
  var axios_1 = __importDefault(require("axios"));
55
+ var url_join_1 = __importDefault(require("url-join"));
55
56
  var json_1 = require("../utils/json");
56
57
  var number_1 = require("../utils/number");
57
58
  var stark_1 = require("../utils/stark");
@@ -71,14 +72,14 @@ var Provider = /** @class */ (function () {
71
72
  ? optionsOrProvider.baseUrl
72
73
  : Provider.getNetworkFromName(optionsOrProvider.network);
73
74
  this.baseUrl = baseUrl;
74
- this.feederGatewayUrl = baseUrl + "/feeder_gateway";
75
- this.gatewayUrl = baseUrl + "/gateway";
75
+ this.feederGatewayUrl = (0, url_join_1.default)(baseUrl, 'feeder_gateway');
76
+ this.gatewayUrl = (0, url_join_1.default)(baseUrl, 'gateway');
76
77
  }
77
78
  }
78
79
  Provider.getNetworkFromName = function (name) {
79
80
  switch (name) {
80
81
  case 'mainnet-alpha':
81
- return 'http://alpha-mainnet.starknet.io/';
82
+ return 'https://alpha-mainnet.starknet.io';
82
83
  case 'georli-alpha':
83
84
  default:
84
85
  return 'https://alpha4.starknet.io';
@@ -95,7 +96,7 @@ var Provider = /** @class */ (function () {
95
96
  var data;
96
97
  return __generator(this, function (_a) {
97
98
  switch (_a.label) {
98
- case 0: return [4 /*yield*/, axios_1.default.get(this.feederGatewayUrl + "/get_contract_addresses")];
99
+ case 0: return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_contract_addresses'))];
99
100
  case 1:
100
101
  data = (_a.sent()).data;
101
102
  return [2 /*return*/, data];
@@ -117,7 +118,7 @@ var Provider = /** @class */ (function () {
117
118
  var data;
118
119
  return __generator(this, function (_a) {
119
120
  switch (_a.label) {
120
- case 0: return [4 /*yield*/, axios_1.default.post(this.feederGatewayUrl + "/call_contract?blockId=" + (blockId !== null && blockId !== void 0 ? blockId : 'null'), __assign({ signature: [], calldata: [] }, invokeTx))];
121
+ case 0: return [4 /*yield*/, axios_1.default.post((0, url_join_1.default)(this.feederGatewayUrl, 'call_contract', "?blockId=" + (blockId !== null && blockId !== void 0 ? blockId : 'null')), __assign({ signature: [], calldata: [] }, invokeTx))];
121
122
  case 1:
122
123
  data = (_a.sent()).data;
123
124
  return [2 /*return*/, data];
@@ -138,7 +139,7 @@ var Provider = /** @class */ (function () {
138
139
  var data;
139
140
  return __generator(this, function (_a) {
140
141
  switch (_a.label) {
141
- case 0: return [4 /*yield*/, axios_1.default.get(this.feederGatewayUrl + "/get_block?blockId=" + (blockId !== null && blockId !== void 0 ? blockId : 'null'))];
142
+ case 0: return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_block', "?blockId=" + (blockId !== null && blockId !== void 0 ? blockId : 'null')))];
142
143
  case 1:
143
144
  data = (_a.sent()).data;
144
145
  return [2 /*return*/, data];
@@ -160,7 +161,7 @@ var Provider = /** @class */ (function () {
160
161
  var data;
161
162
  return __generator(this, function (_a) {
162
163
  switch (_a.label) {
163
- case 0: return [4 /*yield*/, axios_1.default.get(this.feederGatewayUrl + "/get_code?contractAddress=" + contractAddress + "&blockId=" + (blockId !== null && blockId !== void 0 ? blockId : 'null'))];
164
+ case 0: return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_code', "?contractAddress=" + contractAddress + "&blockId=" + (blockId !== null && blockId !== void 0 ? blockId : 'null')))];
164
165
  case 1:
165
166
  data = (_a.sent()).data;
166
167
  return [2 /*return*/, data];
@@ -184,7 +185,7 @@ var Provider = /** @class */ (function () {
184
185
  var data;
185
186
  return __generator(this, function (_a) {
186
187
  switch (_a.label) {
187
- case 0: return [4 /*yield*/, axios_1.default.get(this.feederGatewayUrl + "/get_storage_at?contractAddress=" + contractAddress + "&key=" + key + "&blockId=" + (blockId !== null && blockId !== void 0 ? blockId : 'null'))];
188
+ case 0: return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_storage_at', "?contractAddress=" + contractAddress + "&key=" + key + "&blockId=" + (blockId !== null && blockId !== void 0 ? blockId : 'null')))];
188
189
  case 1:
189
190
  data = (_a.sent()).data;
190
191
  return [2 /*return*/, data];
@@ -207,7 +208,7 @@ var Provider = /** @class */ (function () {
207
208
  switch (_a.label) {
208
209
  case 0:
209
210
  txHashBn = (0, number_1.toBN)(txHash);
210
- return [4 /*yield*/, axios_1.default.get(this.feederGatewayUrl + "/get_transaction_status?transactionHash=" + (0, number_1.toHex)(txHashBn))];
211
+ return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_transaction_status', "?transactionHash=" + (0, number_1.toHex)(txHashBn)))];
211
212
  case 1:
212
213
  data = (_a.sent()).data;
213
214
  return [2 /*return*/, data];
@@ -230,7 +231,7 @@ var Provider = /** @class */ (function () {
230
231
  switch (_a.label) {
231
232
  case 0:
232
233
  txHashBn = (0, number_1.toBN)(txHash);
233
- return [4 /*yield*/, axios_1.default.get(this.feederGatewayUrl + "/get_transaction?transactionHash=" + (0, number_1.toHex)(txHashBn))];
234
+ return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_transaction', "?transactionHash=" + (0, number_1.toHex)(txHashBn)))];
234
235
  case 1:
235
236
  data = (_a.sent()).data;
236
237
  return [2 /*return*/, data];
@@ -254,7 +255,7 @@ var Provider = /** @class */ (function () {
254
255
  case 0:
255
256
  signature = tx.type === 'INVOKE_FUNCTION' && (0, stark_1.formatSignature)(tx.signature);
256
257
  contract_address_salt = tx.type === 'DEPLOY' && (0, number_1.toHex)((0, number_1.toBN)(tx.contract_address_salt));
257
- return [4 /*yield*/, axios_1.default.post(this.gatewayUrl + "/add_transaction", (0, json_1.stringify)(__assign(__assign(__assign({}, tx), (Array.isArray(signature) && { signature: signature })), (contract_address_salt && { contract_address_salt: contract_address_salt }))), { headers: { 'Content-Type': 'application/json' } })];
258
+ return [4 /*yield*/, axios_1.default.post((0, url_join_1.default)(this.gatewayUrl, 'add_transaction'), (0, json_1.stringify)(__assign(__assign(__assign({}, tx), (Array.isArray(signature) && { signature: signature })), (contract_address_salt && { contract_address_salt: contract_address_salt }))), { headers: { 'Content-Type': 'application/json' } })];
258
259
  case 1:
259
260
  data = (_a.sent()).data;
260
261
  return [2 /*return*/, data];
package/dist/types.d.ts CHANGED
@@ -11,19 +11,26 @@ export declare type TxStatus = 'TRANSACTION_RECEIVED';
11
11
  export declare type Type = 'DEPLOY' | 'INVOKE_FUNCTION';
12
12
  export declare type EntryPointType = 'EXTERNAL';
13
13
  export declare type CompressedProgram = string;
14
- export declare type Abi = {
15
- inputs: {
16
- name: string;
17
- type: 'felt' | 'felt*';
18
- }[];
14
+ export declare type AbiEntry = {
19
15
  name: string;
20
- outputs: {
21
- name: string;
22
- type: 'felt' | 'felt*';
23
- }[];
16
+ type: 'felt' | 'felt*' | string;
17
+ };
18
+ export declare type FunctionAbi = {
19
+ inputs: AbiEntry[];
20
+ name: string;
21
+ outputs: AbiEntry[];
24
22
  stateMutability?: 'view';
25
23
  type: 'function';
26
24
  };
25
+ export declare type StructAbi = {
26
+ members: (AbiEntry & {
27
+ offset: number;
28
+ })[];
29
+ name: string;
30
+ size: number;
31
+ type: 'struct';
32
+ };
33
+ export declare type Abi = FunctionAbi | StructAbi;
27
34
  export declare type EntryPointsByType = object;
28
35
  export declare type Program = object;
29
36
  export declare type CompiledContract = {
@@ -0,0 +1,4 @@
1
+ export declare function isASCII(str: string): boolean;
2
+ export declare function isShortString(str: string): boolean;
3
+ export declare function encodeShortString(str: string): string;
4
+ export declare function decodeShortString(str: string): string;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decodeShortString = exports.encodeShortString = exports.isShortString = exports.isASCII = void 0;
4
+ var encode_1 = require("./encode");
5
+ function isASCII(str) {
6
+ // eslint-disable-next-line no-control-regex
7
+ return /^[\x00-\x7F]*$/.test(str);
8
+ }
9
+ exports.isASCII = isASCII;
10
+ // function to check if string has less or equal 31 characters
11
+ function isShortString(str) {
12
+ return str.length <= 31;
13
+ }
14
+ exports.isShortString = isShortString;
15
+ function encodeShortString(str) {
16
+ if (!isASCII(str))
17
+ throw new Error(str + " is not an ASCII string");
18
+ if (!isShortString(str))
19
+ throw new Error(str + " is too long");
20
+ return (0, encode_1.addHexPrefix)(str.replace(/./g, function (char) { return char.charCodeAt(0).toString(16); }));
21
+ }
22
+ exports.encodeShortString = encodeShortString;
23
+ function decodeShortString(str) {
24
+ return (0, encode_1.removeHexPrefix)(str).replace(/.{2}/g, function (hex) { return String.fromCharCode(parseInt(hex, 16)); });
25
+ }
26
+ exports.decodeShortString = decodeShortString;
@@ -0,0 +1,11 @@
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;
@@ -0,0 +1,28 @@
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;