starknet 3.18.2 → 4.0.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 +70 -0
- package/README.md +1 -2
- package/__tests__/account.test.ts +11 -56
- package/__tests__/contract.test.ts +11 -49
- package/__tests__/defaultProvider.test.ts +321 -0
- package/__tests__/fixtures.ts +32 -11
- package/__tests__/jest.setup.ts +2 -3
- package/__tests__/rpcProvider.test.ts +17 -0
- package/__tests__/sequencerProvider.test.ts +45 -0
- package/account/default.d.ts +54 -77
- package/account/default.js +271 -596
- package/account/index.js +18 -31
- package/account/interface.d.ts +66 -95
- package/account/interface.js +20 -30
- package/constants.d.ts +17 -19
- package/constants.js +2038 -2059
- package/contract/contractFactory.d.ts +25 -29
- package/contract/contractFactory.js +94 -210
- package/contract/default.d.ts +117 -146
- package/contract/default.js +582 -776
- package/contract/index.js +19 -32
- package/contract/interface.d.ts +72 -92
- package/contract/interface.js +6 -5
- package/dist/account/default.d.ts +5 -9
- package/dist/account/default.js +35 -169
- package/dist/account/interface.d.ts +3 -15
- package/dist/contract/contractFactory.js +4 -4
- package/dist/contract/default.d.ts +3 -3
- package/dist/contract/default.js +3 -2
- package/dist/contract/interface.d.ts +2 -2
- package/dist/provider/default.d.ts +18 -134
- package/dist/provider/default.js +47 -411
- package/dist/provider/index.d.ts +2 -0
- package/dist/provider/index.js +2 -0
- package/dist/provider/interface.d.ts +45 -50
- package/dist/provider/rpc.d.ts +57 -0
- package/dist/provider/rpc.js +364 -0
- package/dist/provider/sequencer.d.ts +66 -0
- package/dist/provider/sequencer.js +444 -0
- package/dist/types/account.d.ts +2 -3
- package/dist/types/api/index.d.ts +16 -0
- package/dist/types/api/index.js +18 -0
- package/dist/types/api/rpc.d.ts +221 -0
- package/dist/types/{api.js → api/rpc.js} +0 -0
- package/dist/types/api/sequencer.d.ts +289 -0
- package/dist/types/api/sequencer.js +2 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/index.js +15 -1
- package/dist/types/lib.d.ts +3 -1
- package/dist/types/provider.d.ts +86 -0
- package/dist/types/provider.js +2 -0
- package/dist/utils/fetchPonyfill.d.ts +2 -0
- package/dist/utils/fetchPonyfill.js +6 -0
- package/dist/utils/provider.d.ts +4 -0
- package/dist/utils/provider.js +38 -0
- package/dist/utils/responseParser/index.d.ts +11 -0
- package/dist/utils/responseParser/index.js +9 -0
- package/dist/utils/responseParser/rpc.d.ts +13 -0
- package/dist/utils/responseParser/rpc.js +96 -0
- package/dist/utils/responseParser/sequencer.d.ts +13 -0
- package/dist/utils/responseParser/sequencer.js +124 -0
- package/index.js +42 -75
- package/package.json +2 -3
- package/provider/default.d.ts +21 -175
- package/provider/default.js +139 -704
- package/provider/errors.d.ts +4 -4
- package/provider/errors.js +30 -40
- package/provider/index.d.ts +2 -0
- package/provider/index.js +22 -33
- package/provider/interface.d.ts +104 -131
- package/provider/interface.js +6 -5
- package/provider/rpc.d.ts +57 -0
- package/provider/rpc.js +364 -0
- package/provider/sequencer.d.ts +66 -0
- package/provider/sequencer.js +444 -0
- package/provider/utils.d.ts +7 -9
- package/provider/utils.js +39 -44
- package/signer/default.d.ts +5 -9
- package/signer/default.js +72 -177
- package/signer/index.js +18 -31
- package/signer/interface.d.ts +29 -33
- package/signer/interface.js +6 -5
- package/src/account/default.ts +26 -146
- package/src/account/interface.ts +5 -20
- package/src/contract/contractFactory.ts +3 -6
- package/src/contract/default.ts +6 -4
- package/src/contract/interface.ts +2 -2
- package/src/provider/default.ts +63 -395
- package/src/provider/index.ts +2 -0
- package/src/provider/interface.ts +68 -63
- package/src/provider/rpc.ts +299 -0
- package/src/provider/sequencer.ts +385 -0
- package/src/types/account.ts +2 -3
- package/src/types/api/index.ts +17 -0
- package/src/types/api/rpc.ts +247 -0
- package/src/types/api/sequencer.ts +331 -0
- package/src/types/index.ts +3 -1
- package/src/types/lib.ts +3 -1
- package/src/types/provider.ts +108 -0
- package/src/utils/fetchPonyfill.ts +4 -0
- package/src/utils/provider.ts +28 -0
- package/src/utils/responseParser/index.ts +28 -0
- package/src/utils/responseParser/rpc.ts +93 -0
- package/src/utils/responseParser/sequencer.ts +127 -0
- package/types/account.d.ts +5 -7
- package/types/account.js +2 -2
- package/types/api/index.d.ts +16 -0
- package/types/api/index.js +18 -0
- package/types/api/rpc.d.ts +221 -0
- package/types/api/rpc.js +2 -0
- package/types/api/sequencer.d.ts +289 -0
- package/types/api/sequencer.js +2 -0
- package/types/contract.d.ts +1 -1
- package/types/contract.js +2 -2
- package/types/index.d.ts +3 -1
- package/types/index.js +35 -34
- package/types/lib.d.ts +36 -41
- package/types/lib.js +2 -2
- package/types/provider.d.ts +86 -0
- package/types/provider.js +2 -0
- package/types/signer.d.ts +2 -2
- package/types/signer.js +2 -2
- package/utils/address.js +26 -37
- package/utils/ellipticCurve.d.ts +1 -6
- package/utils/ellipticCurve.js +73 -137
- package/utils/encode.js +49 -85
- package/utils/fetchPonyfill.d.ts +2 -0
- package/utils/fetchPonyfill.js +6 -0
- package/utils/hash.d.ts +4 -31
- package/utils/hash.js +76 -141
- package/utils/json.d.ts +13 -45
- package/utils/json.js +15 -22
- package/utils/number.d.ts +2 -9
- package/utils/number.js +47 -81
- package/utils/provider.d.ts +4 -0
- package/utils/provider.js +38 -0
- package/utils/responseParser/index.d.ts +11 -0
- package/utils/responseParser/index.js +9 -0
- package/utils/responseParser/rpc.d.ts +13 -0
- package/utils/responseParser/rpc.js +96 -0
- package/utils/responseParser/sequencer.d.ts +13 -0
- package/utils/responseParser/sequencer.js +124 -0
- package/utils/shortString.js +13 -21
- package/utils/stark.d.ts +0 -1
- package/utils/stark.js +59 -93
- package/utils/transaction.d.ts +3 -6
- package/utils/transaction.js +50 -81
- package/utils/typedData/index.d.ts +3 -15
- package/utils/typedData/index.js +109 -175
- package/utils/typedData/types.d.ts +9 -9
- package/utils/typedData/types.js +2 -2
- package/utils/typedData/utils.js +6 -6
- package/utils/uint256.d.ts +5 -5
- package/utils/uint256.js +16 -26
- package/www/docs/API/account.md +3 -4
- package/www/docs/API/contract.md +2 -2
- package/www/docs/API/contractFactory.md +2 -2
- package/www/docs/API/provider.md +185 -74
- package/www/guides/account.md +1 -8
- package/www/guides/erc20.md +3 -0
- package/__tests__/provider.test.ts +0 -168
- package/dist/types/api.d.ts +0 -261
- package/src/types/api.ts +0 -303
- package/types/api.d.ts +0 -287
- package/types/api.js +0 -2
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.RPCResponseParser = void 0;
|
|
19
|
+
var number_1 = require("../number");
|
|
20
|
+
var _1 = require(".");
|
|
21
|
+
var RPCResponseParser = /** @class */ (function (_super) {
|
|
22
|
+
__extends(RPCResponseParser, _super);
|
|
23
|
+
function RPCResponseParser() {
|
|
24
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
25
|
+
}
|
|
26
|
+
RPCResponseParser.prototype.parseGetBlockResponse = function (res) {
|
|
27
|
+
return {
|
|
28
|
+
accepted_time: res.accepted_time,
|
|
29
|
+
block_hash: res.block_hash,
|
|
30
|
+
block_number: res.block_number,
|
|
31
|
+
gas_price: res.gas_price,
|
|
32
|
+
new_root: res.new_root,
|
|
33
|
+
old_root: res.old_root,
|
|
34
|
+
parent_hash: res.parent_hash,
|
|
35
|
+
sequencer: res.sequencer,
|
|
36
|
+
status: res.status,
|
|
37
|
+
transactions: res.transactions,
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
RPCResponseParser.prototype.parseGetTransactionResponse = function (res) {
|
|
41
|
+
return {
|
|
42
|
+
calldata: res.calldata || [],
|
|
43
|
+
contract_address: res.contract_address,
|
|
44
|
+
contract_class: res.contract_class,
|
|
45
|
+
entry_point_selector: res.entry_point_selector,
|
|
46
|
+
max_fee: res.max_fee,
|
|
47
|
+
nonce: res.nonce,
|
|
48
|
+
sender_address: res.sender_address,
|
|
49
|
+
signature: res.signature || [],
|
|
50
|
+
transaction_hash: res.txn_hash,
|
|
51
|
+
version: res.version,
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
RPCResponseParser.prototype.parseGetTransactionReceiptResponse = function (res) {
|
|
55
|
+
return {
|
|
56
|
+
transaction_hash: res.txn_hash,
|
|
57
|
+
actual_fee: res.actual_fee,
|
|
58
|
+
status: res.status,
|
|
59
|
+
status_data: res.status_data,
|
|
60
|
+
messages_sent: res.messages_sent,
|
|
61
|
+
l1_origin_message: res.l1_origin_message,
|
|
62
|
+
events: res.events,
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
RPCResponseParser.prototype.parseFeeEstimateResponse = function (res) {
|
|
66
|
+
return {
|
|
67
|
+
overall_fee: (0, number_1.toBN)(res.overall_fee),
|
|
68
|
+
gas_consumed: (0, number_1.toBN)(res.gas_consumed),
|
|
69
|
+
gas_price: (0, number_1.toBN)(res.gas_price),
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
RPCResponseParser.prototype.parseCallContractResponse = function (res) {
|
|
73
|
+
return {
|
|
74
|
+
result: res,
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
RPCResponseParser.prototype.parseInvokeFunctionResponse = function (res) {
|
|
78
|
+
return {
|
|
79
|
+
transaction_hash: res.transaction_hash,
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
RPCResponseParser.prototype.parseDeployContractResponse = function (res) {
|
|
83
|
+
return {
|
|
84
|
+
transaction_hash: res.transaction_hash,
|
|
85
|
+
contract_address: res.contract_address,
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
RPCResponseParser.prototype.parseDeclareContractResponse = function (res) {
|
|
89
|
+
return {
|
|
90
|
+
transaction_hash: res.transaction_hash,
|
|
91
|
+
class_hash: res.class_hash,
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
return RPCResponseParser;
|
|
95
|
+
}(_1.ResponseParser));
|
|
96
|
+
exports.RPCResponseParser = RPCResponseParser;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CallContractResponse, DeclareContractResponse, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, InvokeFunctionResponse } from '../../types';
|
|
2
|
+
import { Sequencer } from '../../types/api';
|
|
3
|
+
import { ResponseParser } from '.';
|
|
4
|
+
export declare class SequencerAPIResponseParser extends ResponseParser {
|
|
5
|
+
parseGetBlockResponse(res: Sequencer.GetBlockResponse): GetBlockResponse;
|
|
6
|
+
parseGetTransactionResponse(res: Sequencer.GetTransactionResponse): GetTransactionResponse;
|
|
7
|
+
parseGetTransactionReceiptResponse(res: Sequencer.TransactionReceiptResponse): GetTransactionReceiptResponse;
|
|
8
|
+
parseFeeEstimateResponse(res: Sequencer.EstimateFeeResponse): EstimateFeeResponse;
|
|
9
|
+
parseCallContractResponse(res: Sequencer.CallContractResponse): CallContractResponse;
|
|
10
|
+
parseInvokeFunctionResponse(res: Sequencer.AddTransactionResponse): InvokeFunctionResponse;
|
|
11
|
+
parseDeployContractResponse(res: Sequencer.AddTransactionResponse): DeployContractResponse;
|
|
12
|
+
parseDeclareContractResponse(res: Sequencer.AddTransactionResponse): DeclareContractResponse;
|
|
13
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.SequencerAPIResponseParser = void 0;
|
|
30
|
+
var number_1 = require("../number");
|
|
31
|
+
var _1 = require(".");
|
|
32
|
+
var SequencerAPIResponseParser = /** @class */ (function (_super) {
|
|
33
|
+
__extends(SequencerAPIResponseParser, _super);
|
|
34
|
+
function SequencerAPIResponseParser() {
|
|
35
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
36
|
+
}
|
|
37
|
+
SequencerAPIResponseParser.prototype.parseGetBlockResponse = function (res) {
|
|
38
|
+
return {
|
|
39
|
+
accepted_time: res.timestamp,
|
|
40
|
+
block_hash: res.block_hash,
|
|
41
|
+
block_number: res.block_number,
|
|
42
|
+
gas_price: res.gas_price,
|
|
43
|
+
new_root: res.state_root,
|
|
44
|
+
old_root: undefined,
|
|
45
|
+
parent_hash: res.parent_block_hash,
|
|
46
|
+
sequencer: res.sequencer_address,
|
|
47
|
+
status: res.status,
|
|
48
|
+
transactions: Object.values(res.transactions)
|
|
49
|
+
.map(function (value) { return 'transaction_hash' in value && value.transaction_hash; })
|
|
50
|
+
.filter(Boolean),
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
SequencerAPIResponseParser.prototype.parseGetTransactionResponse = function (res) {
|
|
54
|
+
return {
|
|
55
|
+
calldata: 'calldata' in res.transaction ? res.transaction.calldata : [],
|
|
56
|
+
contract_address: 'contract_address' in res.transaction ? res.transaction.contract_address : undefined,
|
|
57
|
+
contract_class: 'contract_class' in res.transaction ? res.transaction.contract_class : undefined,
|
|
58
|
+
entry_point_selector: 'entry_point_selector' in res.transaction
|
|
59
|
+
? res.transaction.entry_point_selector
|
|
60
|
+
: undefined,
|
|
61
|
+
max_fee: 'max_fee' in res.transaction ? res.transaction.max_fee : undefined,
|
|
62
|
+
nonce: res.transaction.nonce,
|
|
63
|
+
sender_address: 'sender_address' in res.transaction
|
|
64
|
+
? res.transaction.sender_address
|
|
65
|
+
: undefined,
|
|
66
|
+
signature: 'signature' in res.transaction ? res.transaction.signature : undefined,
|
|
67
|
+
transaction_hash: 'transaction_hash' in res.transaction ? res.transaction.transaction_hash : undefined,
|
|
68
|
+
version: 'version' in res.transaction ? res.transaction.version : undefined,
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
SequencerAPIResponseParser.prototype.parseGetTransactionReceiptResponse = function (res) {
|
|
72
|
+
return {
|
|
73
|
+
transaction_hash: res.transaction_hash,
|
|
74
|
+
actual_fee: 'actual_fee' in res ? res.actual_fee : undefined,
|
|
75
|
+
status: res.status,
|
|
76
|
+
status_data: undefined,
|
|
77
|
+
messages_sent: res.l2_to_l1_messages,
|
|
78
|
+
events: res.events,
|
|
79
|
+
l1_origin_message: undefined,
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
SequencerAPIResponseParser.prototype.parseFeeEstimateResponse = function (res) {
|
|
83
|
+
if ('overall_fee' in res) {
|
|
84
|
+
var gasInfo = {};
|
|
85
|
+
try {
|
|
86
|
+
gasInfo = {
|
|
87
|
+
gas_consumed: (0, number_1.toBN)(res.gas_usage),
|
|
88
|
+
gas_price: (0, number_1.toBN)(res.gas_price),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
catch (_a) {
|
|
92
|
+
// do nothing
|
|
93
|
+
}
|
|
94
|
+
return __assign({ overall_fee: (0, number_1.toBN)(res.overall_fee) }, gasInfo);
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
overall_fee: (0, number_1.toBN)(res.amount),
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
SequencerAPIResponseParser.prototype.parseCallContractResponse = function (res) {
|
|
101
|
+
return {
|
|
102
|
+
result: res.result,
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
SequencerAPIResponseParser.prototype.parseInvokeFunctionResponse = function (res) {
|
|
106
|
+
return {
|
|
107
|
+
transaction_hash: res.transaction_hash,
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
SequencerAPIResponseParser.prototype.parseDeployContractResponse = function (res) {
|
|
111
|
+
return {
|
|
112
|
+
transaction_hash: res.transaction_hash,
|
|
113
|
+
contract_address: res.address,
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
SequencerAPIResponseParser.prototype.parseDeclareContractResponse = function (res) {
|
|
117
|
+
return {
|
|
118
|
+
transaction_hash: res.transaction_hash,
|
|
119
|
+
class_hash: res.class_hash,
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
return SequencerAPIResponseParser;
|
|
123
|
+
}(_1.ResponseParser));
|
|
124
|
+
exports.SequencerAPIResponseParser = SequencerAPIResponseParser;
|
package/utils/shortString.js
CHANGED
|
@@ -1,34 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
exports.decodeShortString =
|
|
4
|
-
|
|
5
|
-
exports.isShortString =
|
|
6
|
-
exports.isASCII =
|
|
7
|
-
void 0;
|
|
8
|
-
var encode_1 = require('./encode');
|
|
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");
|
|
9
5
|
function isASCII(str) {
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
// eslint-disable-next-line no-control-regex
|
|
7
|
+
return /^[\x00-\x7F]*$/.test(str);
|
|
12
8
|
}
|
|
13
9
|
exports.isASCII = isASCII;
|
|
14
10
|
// function to check if string has less or equal 31 characters
|
|
15
11
|
function isShortString(str) {
|
|
16
|
-
|
|
12
|
+
return str.length <= 31;
|
|
17
13
|
}
|
|
18
14
|
exports.isShortString = isShortString;
|
|
19
15
|
function encodeShortString(str) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
})
|
|
26
|
-
);
|
|
16
|
+
if (!isASCII(str))
|
|
17
|
+
throw new Error("".concat(str, " is not an ASCII string"));
|
|
18
|
+
if (!isShortString(str))
|
|
19
|
+
throw new Error("".concat(str, " is too long"));
|
|
20
|
+
return (0, encode_1.addHexPrefix)(str.replace(/./g, function (char) { return char.charCodeAt(0).toString(16); }));
|
|
27
21
|
}
|
|
28
22
|
exports.encodeShortString = encodeShortString;
|
|
29
23
|
function decodeShortString(str) {
|
|
30
|
-
|
|
31
|
-
return String.fromCharCode(parseInt(hex, 16));
|
|
32
|
-
});
|
|
24
|
+
return (0, encode_1.removeHexPrefix)(str).replace(/.{2}/g, function (hex) { return String.fromCharCode(parseInt(hex, 16)); });
|
|
33
25
|
}
|
|
34
26
|
exports.decodeShortString = decodeShortString;
|
package/utils/stark.d.ts
CHANGED
package/utils/stark.js
CHANGED
|
@@ -1,51 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
var __read =
|
|
3
|
-
|
|
4
|
-
function (o, n) {
|
|
5
|
-
var m = typeof Symbol === 'function' && o[Symbol.iterator];
|
|
1
|
+
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
6
4
|
if (!m) return o;
|
|
7
|
-
var i = m.call(o),
|
|
8
|
-
r,
|
|
9
|
-
ar = [],
|
|
10
|
-
e;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
11
6
|
try {
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (e) throw e.error;
|
|
20
|
-
}
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
21
15
|
}
|
|
22
16
|
return ar;
|
|
23
|
-
|
|
24
|
-
var __spreadArray =
|
|
25
|
-
|
|
26
|
-
function (to, from, pack) {
|
|
27
|
-
if (pack || arguments.length === 2)
|
|
28
|
-
for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
17
|
+
};
|
|
18
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
29
20
|
if (ar || !(i in from)) {
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
+
ar[i] = from[i];
|
|
32
23
|
}
|
|
33
|
-
|
|
24
|
+
}
|
|
34
25
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
35
|
-
|
|
36
|
-
Object.defineProperty(exports,
|
|
37
|
-
exports.estimatedFeeToMaxFee =
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
void 0;
|
|
44
|
-
var pako_1 = require('pako');
|
|
45
|
-
var ellipticCurve_1 = require('./ellipticCurve');
|
|
46
|
-
var encode_1 = require('./encode');
|
|
47
|
-
var json_1 = require('./json');
|
|
48
|
-
var number_1 = require('./number');
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.estimatedFeeToMaxFee = exports.compileCalldata = exports.formatSignature = exports.makeAddress = exports.randomAddress = exports.compressProgram = void 0;
|
|
29
|
+
var pako_1 = require("pako");
|
|
30
|
+
var ellipticCurve_1 = require("./ellipticCurve");
|
|
31
|
+
var encode_1 = require("./encode");
|
|
32
|
+
var json_1 = require("./json");
|
|
33
|
+
var number_1 = require("./number");
|
|
49
34
|
/**
|
|
50
35
|
* Function to compress compiled cairo program
|
|
51
36
|
*
|
|
@@ -54,72 +39,53 @@ var number_1 = require('./number');
|
|
|
54
39
|
* @returns Compressed cairo program
|
|
55
40
|
*/
|
|
56
41
|
function compressProgram(jsonProgram) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return (0, encode_1.btoaUniversal)(compressedProgram);
|
|
42
|
+
var stringified = typeof jsonProgram === 'string' ? jsonProgram : (0, json_1.stringify)(jsonProgram);
|
|
43
|
+
var compressedProgram = (0, pako_1.gzip)(stringified);
|
|
44
|
+
return (0, encode_1.btoaUniversal)(compressedProgram);
|
|
61
45
|
}
|
|
62
46
|
exports.compressProgram = compressProgram;
|
|
63
47
|
function randomAddress() {
|
|
64
|
-
|
|
65
|
-
|
|
48
|
+
var randomKeyPair = (0, ellipticCurve_1.genKeyPair)();
|
|
49
|
+
return (0, ellipticCurve_1.getStarkKey)(randomKeyPair);
|
|
66
50
|
}
|
|
67
51
|
exports.randomAddress = randomAddress;
|
|
68
52
|
function makeAddress(input) {
|
|
69
|
-
|
|
53
|
+
return (0, encode_1.addHexPrefix)(input).toLowerCase();
|
|
70
54
|
}
|
|
71
55
|
exports.makeAddress = makeAddress;
|
|
72
56
|
function formatSignature(sig) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
});
|
|
82
|
-
} catch (e) {
|
|
83
|
-
return [];
|
|
84
|
-
}
|
|
57
|
+
if (!sig)
|
|
58
|
+
return [];
|
|
59
|
+
try {
|
|
60
|
+
return sig.map(function (x) { return (0, number_1.toBN)(x); }).map(function (x) { return x.toString(); });
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
85
65
|
}
|
|
86
66
|
exports.formatSignature = formatSignature;
|
|
87
67
|
function compileCalldata(args) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
k = _b[0];
|
|
104
|
-
return k !== 'type';
|
|
105
|
-
})
|
|
106
|
-
.map(function (_a) {
|
|
107
|
-
var _b = __read(_a, 2),
|
|
108
|
-
v = _b[1];
|
|
109
|
-
return (0, number_1.toBN)(v).toString();
|
|
110
|
-
});
|
|
111
|
-
return (0, number_1.toBN)(value).toString();
|
|
112
|
-
});
|
|
68
|
+
return Object.values(args).flatMap(function (value) {
|
|
69
|
+
if (Array.isArray(value))
|
|
70
|
+
return __spreadArray([(0, number_1.toBN)(value.length).toString()], __read(value.map(function (x) { return (0, number_1.toBN)(x).toString(); })), false);
|
|
71
|
+
if (typeof value === 'object' && 'type' in value)
|
|
72
|
+
return Object.entries(value)
|
|
73
|
+
.filter(function (_a) {
|
|
74
|
+
var _b = __read(_a, 1), k = _b[0];
|
|
75
|
+
return k !== 'type';
|
|
76
|
+
})
|
|
77
|
+
.map(function (_a) {
|
|
78
|
+
var _b = __read(_a, 2), v = _b[1];
|
|
79
|
+
return (0, number_1.toBN)(v).toString();
|
|
80
|
+
});
|
|
81
|
+
return (0, number_1.toBN)(value).toString();
|
|
82
|
+
});
|
|
113
83
|
}
|
|
114
84
|
exports.compileCalldata = compileCalldata;
|
|
115
85
|
function estimatedFeeToMaxFee(estimatedFee, overhead) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
var overHeadPercent = Math.round((1 + overhead) * 100);
|
|
121
|
-
return (0, number_1.toBN)(estimatedFee)
|
|
122
|
-
.mul((0, number_1.toBN)(overHeadPercent))
|
|
123
|
-
.div((0, number_1.toBN)(100));
|
|
86
|
+
if (overhead === void 0) { overhead = 0.5; }
|
|
87
|
+
// BN can only handle Integers, so we need to do all calulations with integers
|
|
88
|
+
var overHeadPercent = Math.round((1 + overhead) * 100);
|
|
89
|
+
return (0, number_1.toBN)(estimatedFee).mul((0, number_1.toBN)(overHeadPercent)).div((0, number_1.toBN)(100));
|
|
124
90
|
}
|
|
125
91
|
exports.estimatedFeeToMaxFee = estimatedFeeToMaxFee;
|
package/utils/transaction.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ import { BigNumberish } from './number';
|
|
|
7
7
|
* @returns
|
|
8
8
|
*/
|
|
9
9
|
export declare const transformCallsToMulticallArrays: (calls: Call[]) => {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
callArray: ParsedStruct[];
|
|
11
|
+
calldata: string[];
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
14
|
* Transforms a list of calls in the full flattened calldata expected
|
|
@@ -17,7 +17,4 @@ export declare const transformCallsToMulticallArrays: (calls: Call[]) => {
|
|
|
17
17
|
* @returns
|
|
18
18
|
*/
|
|
19
19
|
export declare const fromCallsToExecuteCalldata: (calls: Call[]) => string[];
|
|
20
|
-
export declare const fromCallsToExecuteCalldataWithNonce: (
|
|
21
|
-
calls: Call[],
|
|
22
|
-
nonce: BigNumberish
|
|
23
|
-
) => string[];
|
|
20
|
+
export declare const fromCallsToExecuteCalldataWithNonce: (calls: Call[], nonce: BigNumberish) => string[];
|
package/utils/transaction.js
CHANGED
|
@@ -1,45 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
var __read =
|
|
3
|
-
|
|
4
|
-
function (o, n) {
|
|
5
|
-
var m = typeof Symbol === 'function' && o[Symbol.iterator];
|
|
1
|
+
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
6
4
|
if (!m) return o;
|
|
7
|
-
var i = m.call(o),
|
|
8
|
-
r,
|
|
9
|
-
ar = [],
|
|
10
|
-
e;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
11
6
|
try {
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (e) throw e.error;
|
|
20
|
-
}
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
21
15
|
}
|
|
22
16
|
return ar;
|
|
23
|
-
|
|
24
|
-
var __spreadArray =
|
|
25
|
-
|
|
26
|
-
function (to, from, pack) {
|
|
27
|
-
if (pack || arguments.length === 2)
|
|
28
|
-
for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
17
|
+
};
|
|
18
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
29
20
|
if (ar || !(i in from)) {
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
+
ar[i] = from[i];
|
|
32
23
|
}
|
|
33
|
-
|
|
24
|
+
}
|
|
34
25
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
35
|
-
|
|
36
|
-
Object.defineProperty(exports,
|
|
37
|
-
exports.fromCallsToExecuteCalldataWithNonce =
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
void 0;
|
|
41
|
-
var hash_1 = require('./hash');
|
|
42
|
-
var number_1 = require('./number');
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.fromCallsToExecuteCalldataWithNonce = exports.fromCallsToExecuteCalldata = exports.transformCallsToMulticallArrays = void 0;
|
|
29
|
+
var hash_1 = require("./hash");
|
|
30
|
+
var number_1 = require("./number");
|
|
43
31
|
/**
|
|
44
32
|
* Transforms a list of Calls, each with their own calldata, into
|
|
45
33
|
* two arrays: one with the entrypoints, and one with the concatenated calldata.
|
|
@@ -47,22 +35,22 @@ var number_1 = require('./number');
|
|
|
47
35
|
* @returns
|
|
48
36
|
*/
|
|
49
37
|
var transformCallsToMulticallArrays = function (calls) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
38
|
+
var callArray = [];
|
|
39
|
+
var calldata = [];
|
|
40
|
+
calls.forEach(function (call) {
|
|
41
|
+
var data = call.calldata || [];
|
|
42
|
+
callArray.push({
|
|
43
|
+
to: (0, number_1.toBN)(call.contractAddress).toString(10),
|
|
44
|
+
selector: (0, number_1.toBN)((0, hash_1.getSelectorFromName)(call.entrypoint)).toString(10),
|
|
45
|
+
data_offset: calldata.length.toString(),
|
|
46
|
+
data_len: data.length.toString(),
|
|
47
|
+
});
|
|
48
|
+
calldata.push.apply(calldata, __spreadArray([], __read(data), false));
|
|
59
49
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
calldata: (0, number_1.bigNumberishArrayToDecimalStringArray)(calldata),
|
|
65
|
-
};
|
|
50
|
+
return {
|
|
51
|
+
callArray: callArray,
|
|
52
|
+
calldata: (0, number_1.bigNumberishArrayToDecimalStringArray)(calldata),
|
|
53
|
+
};
|
|
66
54
|
};
|
|
67
55
|
exports.transformCallsToMulticallArrays = transformCallsToMulticallArrays;
|
|
68
56
|
/**
|
|
@@ -72,39 +60,20 @@ exports.transformCallsToMulticallArrays = transformCallsToMulticallArrays;
|
|
|
72
60
|
* @returns
|
|
73
61
|
*/
|
|
74
62
|
var fromCallsToExecuteCalldata = function (calls) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
[
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
selector = _a.selector,
|
|
87
|
-
data_offset = _a.data_offset,
|
|
88
|
-
data_len = _a.data_len;
|
|
89
|
-
return [to, selector, data_offset, data_len];
|
|
90
|
-
})
|
|
91
|
-
.flat()
|
|
92
|
-
),
|
|
93
|
-
false
|
|
94
|
-
),
|
|
95
|
-
[calldata.length.toString()],
|
|
96
|
-
false
|
|
97
|
-
),
|
|
98
|
-
__read(calldata),
|
|
99
|
-
false
|
|
100
|
-
);
|
|
63
|
+
var _a = (0, exports.transformCallsToMulticallArrays)(calls), callArray = _a.callArray, calldata = _a.calldata;
|
|
64
|
+
return __spreadArray(__spreadArray(__spreadArray([
|
|
65
|
+
callArray.length.toString()
|
|
66
|
+
], __read(callArray
|
|
67
|
+
.map(function (_a) {
|
|
68
|
+
var to = _a.to, selector = _a.selector, data_offset = _a.data_offset, data_len = _a.data_len;
|
|
69
|
+
return [to, selector, data_offset, data_len];
|
|
70
|
+
})
|
|
71
|
+
.flat()), false), [
|
|
72
|
+
calldata.length.toString()
|
|
73
|
+
], false), __read(calldata), false);
|
|
101
74
|
};
|
|
102
75
|
exports.fromCallsToExecuteCalldata = fromCallsToExecuteCalldata;
|
|
103
76
|
var fromCallsToExecuteCalldataWithNonce = function (calls, nonce) {
|
|
104
|
-
|
|
105
|
-
__spreadArray([], __read((0, exports.fromCallsToExecuteCalldata)(calls)), false),
|
|
106
|
-
[(0, number_1.toBN)(nonce).toString()],
|
|
107
|
-
false
|
|
108
|
-
);
|
|
77
|
+
return __spreadArray(__spreadArray([], __read((0, exports.fromCallsToExecuteCalldata)(calls)), false), [(0, number_1.toBN)(nonce).toString()], false);
|
|
109
78
|
};
|
|
110
79
|
exports.fromCallsToExecuteCalldataWithNonce = fromCallsToExecuteCalldataWithNonce;
|