starknet 2.1.1 → 2.4.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.
- package/CHANGELOG.md +45 -0
- package/__tests__/signer.test.ts +17 -0
- package/__tests__/utils/shortString.test.ts +22 -0
- package/__tests__/utils/uint256.test.ts +32 -0
- package/constants.d.ts +5 -5
- package/contract.d.ts +7 -1
- package/contract.js +23 -5
- package/dist/constants.d.ts +5 -5
- package/dist/contract.d.ts +4 -1
- package/dist/contract.js +19 -5
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -1
- package/dist/provider/default.d.ts +5 -5
- package/dist/provider/default.js +18 -17
- package/dist/provider/interface.d.ts +4 -4
- package/dist/signer/default.d.ts +2 -2
- package/dist/signer/default.js +20 -15
- package/dist/signer/interface.d.ts +2 -2
- package/dist/types.d.ts +4 -2
- package/dist/utils/shortString.d.ts +4 -0
- package/dist/utils/shortString.js +26 -0
- package/dist/utils/uint256.d.ts +11 -0
- package/dist/utils/uint256.js +28 -0
- package/index.d.ts +2 -0
- package/index.js +5 -1
- package/package.json +5 -2
- package/provider/default.d.ts +8 -5
- package/provider/default.js +57 -38
- package/provider/interface.d.ts +4 -4
- package/signer/default.d.ts +2 -2
- package/signer/default.js +18 -12
- package/signer/interface.d.ts +2 -2
- package/src/constants.ts +4 -6
- package/src/contract.ts +15 -12
- package/src/index.ts +2 -0
- package/src/provider/default.ts +34 -23
- package/src/provider/interface.ts +4 -4
- package/src/signer/default.ts +23 -14
- package/src/signer/interface.ts +4 -2
- package/src/types.ts +4 -2
- package/src/utils/shortString.ts +21 -0
- package/src/utils/uint256.ts +32 -0
- package/types.d.ts +4 -2
- package/utils/shortString.d.ts +4 -0
- package/utils/shortString.js +34 -0
- package/utils/uint256.d.ts +11 -0
- package/utils/uint256.js +38 -0
|
@@ -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;
|
package/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/index.js
CHANGED
|
@@ -44,7 +44,9 @@ var __importStar =
|
|
|
44
44
|
return result;
|
|
45
45
|
};
|
|
46
46
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
47
|
-
exports.
|
|
47
|
+
exports.shortString =
|
|
48
|
+
exports.uint256 =
|
|
49
|
+
exports.ec =
|
|
48
50
|
exports.stark =
|
|
49
51
|
exports.number =
|
|
50
52
|
exports.json =
|
|
@@ -69,3 +71,5 @@ exports.json = __importStar(require('./utils/json'));
|
|
|
69
71
|
exports.number = __importStar(require('./utils/number'));
|
|
70
72
|
exports.stark = __importStar(require('./utils/stark'));
|
|
71
73
|
exports.ec = __importStar(require('./utils/ellipticCurve'));
|
|
74
|
+
exports.uint256 = __importStar(require('./utils/uint256'));
|
|
75
|
+
exports.shortString = __importStar(require('./utils/shortString'));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starknet",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.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": {
|
|
@@ -40,6 +41,7 @@
|
|
|
40
41
|
"@types/json-bigint": "^1.0.1",
|
|
41
42
|
"@types/minimalistic-assert": "^1.0.1",
|
|
42
43
|
"@types/pako": "^1.0.2",
|
|
44
|
+
"@types/url-join": "^4.0.1",
|
|
43
45
|
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
44
46
|
"@typescript-eslint/parser": "^5.0.0",
|
|
45
47
|
"eslint": "^7.32.0",
|
|
@@ -65,7 +67,8 @@
|
|
|
65
67
|
"hash.js": "^1.1.7",
|
|
66
68
|
"json-bigint": "^1.0.0",
|
|
67
69
|
"minimalistic-assert": "^1.0.1",
|
|
68
|
-
"pako": "^2.0.4"
|
|
70
|
+
"pako": "^2.0.4",
|
|
71
|
+
"url-join": "^4.0.1"
|
|
69
72
|
},
|
|
70
73
|
"lint-staged": {
|
|
71
74
|
"*.ts": "eslint --cache --fix",
|
package/provider/default.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export declare class Provider implements ProviderInterface {
|
|
|
27
27
|
constructor(optionsOrProvider?: ProviderOptions | Provider);
|
|
28
28
|
protected static getNetworkFromName(
|
|
29
29
|
name: NetworkName
|
|
30
|
-
): '
|
|
30
|
+
): 'https://alpha-mainnet.starknet.io' | 'https://alpha4.starknet.io';
|
|
31
31
|
/**
|
|
32
32
|
* Gets the smart contract address on the goerli testnet.
|
|
33
33
|
*
|
|
@@ -40,11 +40,14 @@ export declare class Provider implements ProviderInterface {
|
|
|
40
40
|
*
|
|
41
41
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
|
|
42
42
|
*
|
|
43
|
-
* @param
|
|
43
|
+
* @param invokeTransaction - transaction to be invoked
|
|
44
44
|
* @param blockId
|
|
45
45
|
* @returns the result of the function on the smart contract.
|
|
46
46
|
*/
|
|
47
|
-
callContract(
|
|
47
|
+
callContract(
|
|
48
|
+
invokeTransaction: CallContractTransaction,
|
|
49
|
+
blockId?: number
|
|
50
|
+
): Promise<CallContractResponse>;
|
|
48
51
|
/**
|
|
49
52
|
* Gets the block information from a block ID.
|
|
50
53
|
*
|
|
@@ -98,10 +101,10 @@ export declare class Provider implements ProviderInterface {
|
|
|
98
101
|
*
|
|
99
102
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
|
|
100
103
|
*
|
|
101
|
-
* @param
|
|
104
|
+
* @param transaction - transaction to be invoked
|
|
102
105
|
* @returns a confirmation of invoking a function on the starknet contract
|
|
103
106
|
*/
|
|
104
|
-
addTransaction(
|
|
107
|
+
addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
|
|
105
108
|
/**
|
|
106
109
|
* Deploys a given compiled contract (json) to starknet
|
|
107
110
|
*
|
package/provider/default.js
CHANGED
|
@@ -152,6 +152,7 @@ var __importDefault =
|
|
|
152
152
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
153
153
|
exports.Provider = void 0;
|
|
154
154
|
var axios_1 = __importDefault(require('axios'));
|
|
155
|
+
var url_join_1 = __importDefault(require('url-join'));
|
|
155
156
|
var json_1 = require('../utils/json');
|
|
156
157
|
var number_1 = require('../utils/number');
|
|
157
158
|
var stark_1 = require('../utils/stark');
|
|
@@ -175,14 +176,14 @@ var Provider = /** @class */ (function () {
|
|
|
175
176
|
? optionsOrProvider.baseUrl
|
|
176
177
|
: Provider.getNetworkFromName(optionsOrProvider.network);
|
|
177
178
|
this.baseUrl = baseUrl;
|
|
178
|
-
this.feederGatewayUrl = baseUrl
|
|
179
|
-
this.gatewayUrl = baseUrl
|
|
179
|
+
this.feederGatewayUrl = (0, url_join_1.default)(baseUrl, 'feeder_gateway');
|
|
180
|
+
this.gatewayUrl = (0, url_join_1.default)(baseUrl, 'gateway');
|
|
180
181
|
}
|
|
181
182
|
}
|
|
182
183
|
Provider.getNetworkFromName = function (name) {
|
|
183
184
|
switch (name) {
|
|
184
185
|
case 'mainnet-alpha':
|
|
185
|
-
return '
|
|
186
|
+
return 'https://alpha-mainnet.starknet.io';
|
|
186
187
|
case 'georli-alpha':
|
|
187
188
|
default:
|
|
188
189
|
return 'https://alpha4.starknet.io';
|
|
@@ -202,7 +203,9 @@ var Provider = /** @class */ (function () {
|
|
|
202
203
|
case 0:
|
|
203
204
|
return [
|
|
204
205
|
4 /*yield*/,
|
|
205
|
-
axios_1.default.get(
|
|
206
|
+
axios_1.default.get(
|
|
207
|
+
(0, url_join_1.default)(this.feederGatewayUrl, 'get_contract_addresses')
|
|
208
|
+
),
|
|
206
209
|
];
|
|
207
210
|
case 1:
|
|
208
211
|
data = _a.sent().data;
|
|
@@ -216,11 +219,11 @@ var Provider = /** @class */ (function () {
|
|
|
216
219
|
*
|
|
217
220
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
|
|
218
221
|
*
|
|
219
|
-
* @param
|
|
222
|
+
* @param invokeTransaction - transaction to be invoked
|
|
220
223
|
* @param blockId
|
|
221
224
|
* @returns the result of the function on the smart contract.
|
|
222
225
|
*/
|
|
223
|
-
Provider.prototype.callContract = function (
|
|
226
|
+
Provider.prototype.callContract = function (invokeTransaction, blockId) {
|
|
224
227
|
return __awaiter(this, void 0, void 0, function () {
|
|
225
228
|
var data;
|
|
226
229
|
return __generator(this, function (_a) {
|
|
@@ -229,10 +232,12 @@ var Provider = /** @class */ (function () {
|
|
|
229
232
|
return [
|
|
230
233
|
4 /*yield*/,
|
|
231
234
|
axios_1.default.post(
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
235
|
+
(0, url_join_1.default)(
|
|
236
|
+
this.feederGatewayUrl,
|
|
237
|
+
'call_contract',
|
|
238
|
+
'?blockId=' + (blockId !== null && blockId !== void 0 ? blockId : 'null')
|
|
239
|
+
),
|
|
240
|
+
__assign({ signature: [], calldata: [] }, invokeTransaction)
|
|
236
241
|
),
|
|
237
242
|
];
|
|
238
243
|
case 1:
|
|
@@ -259,9 +264,11 @@ var Provider = /** @class */ (function () {
|
|
|
259
264
|
return [
|
|
260
265
|
4 /*yield*/,
|
|
261
266
|
axios_1.default.get(
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
267
|
+
(0, url_join_1.default)(
|
|
268
|
+
this.feederGatewayUrl,
|
|
269
|
+
'get_block',
|
|
270
|
+
'?blockId=' + (blockId !== null && blockId !== void 0 ? blockId : 'null')
|
|
271
|
+
)
|
|
265
272
|
),
|
|
266
273
|
];
|
|
267
274
|
case 1:
|
|
@@ -289,11 +296,14 @@ var Provider = /** @class */ (function () {
|
|
|
289
296
|
return [
|
|
290
297
|
4 /*yield*/,
|
|
291
298
|
axios_1.default.get(
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
'
|
|
296
|
-
|
|
299
|
+
(0, url_join_1.default)(
|
|
300
|
+
this.feederGatewayUrl,
|
|
301
|
+
'get_code',
|
|
302
|
+
'?contractAddress=' +
|
|
303
|
+
contractAddress +
|
|
304
|
+
'&blockId=' +
|
|
305
|
+
(blockId !== null && blockId !== void 0 ? blockId : 'null')
|
|
306
|
+
)
|
|
297
307
|
),
|
|
298
308
|
];
|
|
299
309
|
case 1:
|
|
@@ -323,13 +333,16 @@ var Provider = /** @class */ (function () {
|
|
|
323
333
|
return [
|
|
324
334
|
4 /*yield*/,
|
|
325
335
|
axios_1.default.get(
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
'
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
336
|
+
(0, url_join_1.default)(
|
|
337
|
+
this.feederGatewayUrl,
|
|
338
|
+
'get_storage_at',
|
|
339
|
+
'?contractAddress=' +
|
|
340
|
+
contractAddress +
|
|
341
|
+
'&key=' +
|
|
342
|
+
key +
|
|
343
|
+
'&blockId=' +
|
|
344
|
+
(blockId !== null && blockId !== void 0 ? blockId : 'null')
|
|
345
|
+
)
|
|
333
346
|
),
|
|
334
347
|
];
|
|
335
348
|
case 1:
|
|
@@ -357,9 +370,11 @@ var Provider = /** @class */ (function () {
|
|
|
357
370
|
return [
|
|
358
371
|
4 /*yield*/,
|
|
359
372
|
axios_1.default.get(
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
373
|
+
(0, url_join_1.default)(
|
|
374
|
+
this.feederGatewayUrl,
|
|
375
|
+
'get_transaction_status',
|
|
376
|
+
'?transactionHash=' + (0, number_1.toHex)(txHashBn)
|
|
377
|
+
)
|
|
363
378
|
),
|
|
364
379
|
];
|
|
365
380
|
case 1:
|
|
@@ -387,9 +402,11 @@ var Provider = /** @class */ (function () {
|
|
|
387
402
|
return [
|
|
388
403
|
4 /*yield*/,
|
|
389
404
|
axios_1.default.get(
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
405
|
+
(0, url_join_1.default)(
|
|
406
|
+
this.feederGatewayUrl,
|
|
407
|
+
'get_transaction',
|
|
408
|
+
'?transactionHash=' + (0, number_1.toHex)(txHashBn)
|
|
409
|
+
)
|
|
393
410
|
),
|
|
394
411
|
];
|
|
395
412
|
case 1:
|
|
@@ -404,27 +421,29 @@ var Provider = /** @class */ (function () {
|
|
|
404
421
|
*
|
|
405
422
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
|
|
406
423
|
*
|
|
407
|
-
* @param
|
|
424
|
+
* @param transaction - transaction to be invoked
|
|
408
425
|
* @returns a confirmation of invoking a function on the starknet contract
|
|
409
426
|
*/
|
|
410
|
-
Provider.prototype.addTransaction = function (
|
|
427
|
+
Provider.prototype.addTransaction = function (transaction) {
|
|
411
428
|
return __awaiter(this, void 0, void 0, function () {
|
|
412
429
|
var signature, contract_address_salt, data;
|
|
413
430
|
return __generator(this, function (_a) {
|
|
414
431
|
switch (_a.label) {
|
|
415
432
|
case 0:
|
|
416
|
-
signature =
|
|
433
|
+
signature =
|
|
434
|
+
transaction.type === 'INVOKE_FUNCTION' &&
|
|
435
|
+
(0, stark_1.formatSignature)(transaction.signature);
|
|
417
436
|
contract_address_salt =
|
|
418
|
-
|
|
419
|
-
(0, number_1.toHex)((0, number_1.toBN)(
|
|
437
|
+
transaction.type === 'DEPLOY' &&
|
|
438
|
+
(0, number_1.toHex)((0, number_1.toBN)(transaction.contract_address_salt));
|
|
420
439
|
return [
|
|
421
440
|
4 /*yield*/,
|
|
422
441
|
axios_1.default.post(
|
|
423
|
-
this.gatewayUrl
|
|
442
|
+
(0, url_join_1.default)(this.gatewayUrl, 'add_transaction'),
|
|
424
443
|
(0, json_1.stringify)(
|
|
425
444
|
__assign(
|
|
426
445
|
__assign(
|
|
427
|
-
__assign({},
|
|
446
|
+
__assign({}, transaction),
|
|
428
447
|
Array.isArray(signature) && { signature: signature }
|
|
429
448
|
),
|
|
430
449
|
contract_address_salt && { contract_address_salt: contract_address_salt }
|
package/provider/interface.d.ts
CHANGED
|
@@ -27,12 +27,12 @@ export declare abstract class ProviderInterface {
|
|
|
27
27
|
*
|
|
28
28
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
|
|
29
29
|
*
|
|
30
|
-
* @param
|
|
30
|
+
* @param invokeTransaction - transaction to be invoked
|
|
31
31
|
* @param blockId
|
|
32
32
|
* @returns the result of the function on the smart contract.
|
|
33
33
|
*/
|
|
34
34
|
abstract callContract(
|
|
35
|
-
|
|
35
|
+
invokeTransaction: CallContractTransaction,
|
|
36
36
|
blockId?: number
|
|
37
37
|
): Promise<CallContractResponse>;
|
|
38
38
|
/**
|
|
@@ -88,10 +88,10 @@ export declare abstract class ProviderInterface {
|
|
|
88
88
|
*
|
|
89
89
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
|
|
90
90
|
*
|
|
91
|
-
* @param
|
|
91
|
+
* @param transaction - transaction to be invoked
|
|
92
92
|
* @returns a confirmation of invoking a function on the starknet contract
|
|
93
93
|
*/
|
|
94
|
-
abstract addTransaction(
|
|
94
|
+
abstract addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
|
|
95
95
|
/**
|
|
96
96
|
* Deploys a given compiled contract (json) to starknet
|
|
97
97
|
*
|
package/signer/default.d.ts
CHANGED
|
@@ -10,8 +10,8 @@ export declare class Signer extends Provider implements SignerInterface {
|
|
|
10
10
|
*
|
|
11
11
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
|
|
12
12
|
*
|
|
13
|
-
* @param
|
|
13
|
+
* @param transaction - transaction to be invoked
|
|
14
14
|
* @returns a confirmation of invoking a function on the starknet contract
|
|
15
15
|
*/
|
|
16
|
-
addTransaction(
|
|
16
|
+
addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
|
|
17
17
|
}
|
package/signer/default.js
CHANGED
|
@@ -216,19 +216,23 @@ var Signer = /** @class */ (function (_super) {
|
|
|
216
216
|
*
|
|
217
217
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
|
|
218
218
|
*
|
|
219
|
-
* @param
|
|
219
|
+
* @param transaction - transaction to be invoked
|
|
220
220
|
* @returns a confirmation of invoking a function on the starknet contract
|
|
221
221
|
*/
|
|
222
|
-
Signer.prototype.addTransaction = function (
|
|
222
|
+
Signer.prototype.addTransaction = function (transaction) {
|
|
223
223
|
return __awaiter(this, void 0, void 0, function () {
|
|
224
|
-
var
|
|
224
|
+
var nonceBn, result, calldataDecimal, msgHash, _a, r, s;
|
|
225
225
|
return __generator(this, function (_b) {
|
|
226
226
|
switch (_b.label) {
|
|
227
227
|
case 0:
|
|
228
|
-
if (
|
|
229
|
-
return [2 /*return*/, _super.prototype.addTransaction.call(this,
|
|
228
|
+
if (transaction.type === 'DEPLOY')
|
|
229
|
+
return [2 /*return*/, _super.prototype.addTransaction.call(this, transaction)];
|
|
230
230
|
(0,
|
|
231
|
-
minimalistic_assert_1.default)(!
|
|
231
|
+
minimalistic_assert_1.default)(!transaction.signature, "Adding signatures to a signer transaction currently isn't supported");
|
|
232
|
+
if (!transaction.nonce) return [3 /*break*/, 1];
|
|
233
|
+
nonceBn = (0, number_1.toBN)(transaction.nonce);
|
|
234
|
+
return [3 /*break*/, 3];
|
|
235
|
+
case 1:
|
|
232
236
|
return [
|
|
233
237
|
4 /*yield*/,
|
|
234
238
|
this.callContract({
|
|
@@ -236,17 +240,19 @@ var Signer = /** @class */ (function (_super) {
|
|
|
236
240
|
entry_point_selector: (0, stark_1.getSelectorFromName)('get_nonce'),
|
|
237
241
|
}),
|
|
238
242
|
];
|
|
239
|
-
case
|
|
243
|
+
case 2:
|
|
240
244
|
result = _b.sent().result;
|
|
241
245
|
nonceBn = (0, number_1.toBN)(result[0]);
|
|
242
|
-
|
|
246
|
+
_b.label = 3;
|
|
247
|
+
case 3:
|
|
248
|
+
calldataDecimal = (transaction.calldata || []).map(function (x) {
|
|
243
249
|
return (0, number_1.toBN)(x).toString();
|
|
244
250
|
});
|
|
245
251
|
msgHash = (0, encode_1.addHexPrefix)(
|
|
246
252
|
(0, hash_1.hashMessage)(
|
|
247
253
|
this.address,
|
|
248
|
-
|
|
249
|
-
|
|
254
|
+
transaction.contract_address,
|
|
255
|
+
transaction.entry_point_selector,
|
|
250
256
|
calldataDecimal,
|
|
251
257
|
nonceBn.toString()
|
|
252
258
|
)
|
|
@@ -260,8 +266,8 @@ var Signer = /** @class */ (function (_super) {
|
|
|
260
266
|
calldata: __spreadArray(
|
|
261
267
|
__spreadArray(
|
|
262
268
|
[
|
|
263
|
-
|
|
264
|
-
|
|
269
|
+
transaction.contract_address,
|
|
270
|
+
transaction.entry_point_selector,
|
|
265
271
|
calldataDecimal.length.toString(),
|
|
266
272
|
],
|
|
267
273
|
__read(calldataDecimal),
|
package/signer/interface.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ export declare abstract class SignerInterface extends Provider {
|
|
|
7
7
|
*
|
|
8
8
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
|
|
9
9
|
*
|
|
10
|
-
* @param
|
|
10
|
+
* @param transaction - transaction to be invoked
|
|
11
11
|
* @returns a confirmation of invoking a function on the starknet contract
|
|
12
12
|
*/
|
|
13
|
-
abstract addTransaction(
|
|
13
|
+
abstract addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
|
|
14
14
|
}
|
package/src/constants.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import BN from 'bn.js';
|
|
2
|
-
|
|
3
1
|
import { toBN } from './utils/number';
|
|
4
2
|
|
|
5
3
|
export { IS_BROWSER } from './utils/encode';
|
|
6
4
|
|
|
7
|
-
export const ZERO
|
|
8
|
-
export const ONE
|
|
9
|
-
export const TWO
|
|
10
|
-
export const MASK_250
|
|
5
|
+
export const ZERO = toBN(0);
|
|
6
|
+
export const ONE = toBN(1);
|
|
7
|
+
export const TWO = toBN(2);
|
|
8
|
+
export const MASK_250 = TWO.pow(toBN(250)).sub(ONE); // 2 ** 250 - 1
|
|
11
9
|
|
|
12
10
|
/**
|
|
13
11
|
* The following is taken from https://github.com/starkware-libs/starkex-resources/blob/master/crypto/starkware/crypto/signature/pedersen_params.json but converted to hex, because JS is very bad handling big integers by default
|
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/index.ts
CHANGED
|
@@ -16,3 +16,5 @@ export * as json from './utils/json';
|
|
|
16
16
|
export * as number from './utils/number';
|
|
17
17
|
export * as stark from './utils/stark';
|
|
18
18
|
export * as ec from './utils/ellipticCurve';
|
|
19
|
+
export * as uint256 from './utils/uint256';
|
|
20
|
+
export * as shortString from './utils/shortString';
|