starknet 4.8.0 → 4.10.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 +46 -0
- package/README.md +1 -3
- package/__mocks__/ERC20.json +32561 -29055
- package/__tests__/account.test.ts +32 -24
- package/__tests__/contract.test.ts +25 -14
- package/__tests__/defaultProvider.test.ts +91 -240
- package/__tests__/fixtures.ts +10 -2
- package/__tests__/rpcProvider.test.ts +8 -16
- package/__tests__/sequencerProvider.test.ts +17 -10
- package/__tests__/udc.test.ts +41 -0
- package/__tests__/utils/merkle.test.ts +98 -3
- package/__tests__/utils/typedData.test.ts +3 -3
- package/account/default.d.ts +12 -44
- package/account/default.js +305 -61
- package/account/interface.d.ts +96 -8
- package/constants.d.ts +8 -1
- package/constants.js +8 -1
- package/contract/default.d.ts +11 -27
- package/contract/default.js +105 -121
- package/contract/interface.d.ts +5 -2
- package/dist/account/default.d.ts +12 -44
- package/dist/account/default.js +305 -61
- package/dist/account/interface.d.ts +96 -8
- package/dist/constants.d.ts +8 -1
- package/dist/constants.js +8 -1
- package/dist/contract/default.d.ts +11 -27
- package/dist/contract/default.js +105 -121
- package/dist/contract/interface.d.ts +5 -2
- package/dist/provider/default.d.ts +8 -3
- package/dist/provider/default.js +31 -4
- package/dist/provider/interface.d.ts +67 -5
- package/dist/provider/rpc.d.ts +10 -3
- package/dist/provider/rpc.js +98 -10
- package/dist/provider/sequencer.d.ts +11 -4
- package/dist/provider/sequencer.js +89 -18
- package/dist/signer/default.d.ts +5 -2
- package/dist/signer/default.js +25 -3
- package/dist/signer/interface.d.ts +29 -2
- package/dist/types/api/index.d.ts +0 -6
- package/dist/types/api/openrpc.d.ts +24 -2
- package/dist/types/api/sequencer.d.ts +22 -7
- package/dist/types/index.d.ts +1 -1
- package/dist/types/lib.d.ts +36 -2
- package/dist/types/provider.d.ts +15 -10
- package/dist/types/signer.d.ts +14 -1
- package/dist/utils/hash.d.ts +2 -0
- package/dist/utils/hash.js +13 -2
- package/dist/utils/merkle.js +2 -4
- package/dist/utils/number.d.ts +1 -0
- package/dist/utils/number.js +3 -1
- package/dist/utils/responseParser/rpc.d.ts +2 -6
- package/dist/utils/responseParser/rpc.js +0 -11
- package/dist/utils/responseParser/sequencer.js +4 -14
- package/package.json +1 -1
- package/provider/default.d.ts +8 -3
- package/provider/default.js +31 -4
- package/provider/interface.d.ts +67 -5
- package/provider/rpc.d.ts +10 -3
- package/provider/rpc.js +98 -10
- package/provider/sequencer.d.ts +11 -4
- package/provider/sequencer.js +89 -18
- package/signer/default.d.ts +5 -2
- package/signer/default.js +25 -3
- package/signer/interface.d.ts +29 -2
- package/src/account/default.ts +243 -55
- package/src/account/interface.ts +132 -7
- package/src/constants.ts +8 -0
- package/src/contract/default.ts +124 -141
- package/src/contract/interface.ts +5 -2
- package/src/provider/default.ts +43 -5
- package/src/provider/interface.ts +92 -7
- package/src/provider/rpc.ts +93 -15
- package/src/provider/sequencer.ts +87 -14
- package/src/signer/default.ts +56 -4
- package/src/signer/interface.ts +33 -2
- package/src/types/api/index.ts +0 -4
- package/src/types/api/openrpc.ts +28 -2
- package/src/types/api/sequencer.ts +32 -9
- package/src/types/index.ts +1 -1
- package/src/types/lib.ts +43 -2
- package/src/types/provider.ts +27 -11
- package/src/types/signer.ts +18 -1
- package/src/utils/hash.ts +46 -1
- package/src/utils/merkle.ts +2 -4
- package/src/utils/number.ts +2 -0
- package/src/utils/responseParser/rpc.ts +4 -20
- package/src/utils/responseParser/sequencer.ts +2 -0
- package/types/api/index.d.ts +0 -6
- package/types/api/openrpc.d.ts +24 -2
- package/types/api/sequencer.d.ts +22 -7
- package/types/index.d.ts +1 -1
- package/types/lib.d.ts +36 -2
- package/types/provider.d.ts +15 -10
- package/types/signer.d.ts +14 -1
- package/utils/hash.d.ts +2 -0
- package/utils/hash.js +13 -2
- package/utils/merkle.js +2 -4
- package/utils/number.d.ts +1 -0
- package/utils/number.js +3 -1
- package/utils/responseParser/rpc.d.ts +2 -6
- package/utils/responseParser/rpc.js +0 -11
- package/utils/responseParser/sequencer.js +4 -14
- package/www/docs/API/account.md +170 -11
- package/www/docs/API/contract.md +39 -3
- package/www/docs/API/provider.md +310 -17
- package/www/docs/API/signer.md +56 -2
- package/www/guides/erc20.md +13 -7
package/provider/rpc.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -52,9 +63,10 @@ var RpcProvider = /** @class */ (function () {
|
|
|
52
63
|
function RpcProvider(optionsOrProvider) {
|
|
53
64
|
var _this = this;
|
|
54
65
|
this.responseParser = new rpc_1.RPCResponseParser();
|
|
55
|
-
var nodeUrl = optionsOrProvider.nodeUrl, retries = optionsOrProvider.retries;
|
|
66
|
+
var nodeUrl = optionsOrProvider.nodeUrl, retries = optionsOrProvider.retries, headers = optionsOrProvider.headers;
|
|
56
67
|
this.nodeUrl = nodeUrl;
|
|
57
68
|
this.retries = retries || 200;
|
|
69
|
+
this.headers = __assign({ 'Content-Type': 'application/json' }, headers);
|
|
58
70
|
this.getChainId().then(function (chainId) {
|
|
59
71
|
_this.chainId = chainId;
|
|
60
72
|
});
|
|
@@ -63,7 +75,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
63
75
|
return (0, fetchPonyfill_1.default)(this.nodeUrl, {
|
|
64
76
|
method: 'POST',
|
|
65
77
|
body: (0, json_1.stringify)({ method: method, jsonrpc: '2.0', params: params, id: 0 }),
|
|
66
|
-
headers:
|
|
78
|
+
headers: this.headers,
|
|
67
79
|
});
|
|
68
80
|
};
|
|
69
81
|
RpcProvider.prototype.errorHandler = function (error) {
|
|
@@ -231,7 +243,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
231
243
|
RpcProvider.prototype.getTransactionReceipt = function (txHash) {
|
|
232
244
|
return __awaiter(this, void 0, void 0, function () {
|
|
233
245
|
return __generator(this, function (_a) {
|
|
234
|
-
return [2 /*return*/, this.fetchEndpoint('starknet_getTransactionReceipt', { transaction_hash: txHash })
|
|
246
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getTransactionReceipt', { transaction_hash: txHash })];
|
|
235
247
|
});
|
|
236
248
|
});
|
|
237
249
|
};
|
|
@@ -243,6 +255,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
243
255
|
});
|
|
244
256
|
};
|
|
245
257
|
RpcProvider.prototype.getClassAt = function (contractAddress, blockIdentifier) {
|
|
258
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
246
259
|
return __awaiter(this, void 0, void 0, function () {
|
|
247
260
|
var block_id;
|
|
248
261
|
return __generator(this, function (_a) {
|
|
@@ -262,6 +275,14 @@ var RpcProvider = /** @class */ (function () {
|
|
|
262
275
|
});
|
|
263
276
|
};
|
|
264
277
|
RpcProvider.prototype.getEstimateFee = function (invocation, invocationDetails, blockIdentifier) {
|
|
278
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
279
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
280
|
+
return __generator(this, function (_a) {
|
|
281
|
+
return [2 /*return*/, this.getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier)];
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
};
|
|
285
|
+
RpcProvider.prototype.getInvokeEstimateFee = function (invocation, invocationDetails, blockIdentifier) {
|
|
265
286
|
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
266
287
|
return __awaiter(this, void 0, void 0, function () {
|
|
267
288
|
var block_id;
|
|
@@ -269,10 +290,12 @@ var RpcProvider = /** @class */ (function () {
|
|
|
269
290
|
block_id = new utils_1.Block(blockIdentifier).identifier;
|
|
270
291
|
return [2 /*return*/, this.fetchEndpoint('starknet_estimateFee', {
|
|
271
292
|
request: {
|
|
293
|
+
type: 'INVOKE',
|
|
272
294
|
contract_address: invocation.contractAddress,
|
|
273
295
|
calldata: (0, provider_1.parseCalldata)(invocation.calldata),
|
|
274
296
|
signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(invocation.signature || []),
|
|
275
297
|
version: (0, number_1.toHex)((0, number_1.toBN)((invocationDetails === null || invocationDetails === void 0 ? void 0 : invocationDetails.version) || 0)),
|
|
298
|
+
nonce: (0, number_1.toHex)((0, number_1.toBN)(invocationDetails.nonce)),
|
|
276
299
|
max_fee: (0, number_1.toHex)((0, number_1.toBN)((invocationDetails === null || invocationDetails === void 0 ? void 0 : invocationDetails.maxFee) || 0)),
|
|
277
300
|
},
|
|
278
301
|
block_id: block_id,
|
|
@@ -280,19 +303,72 @@ var RpcProvider = /** @class */ (function () {
|
|
|
280
303
|
});
|
|
281
304
|
});
|
|
282
305
|
};
|
|
283
|
-
|
|
284
|
-
|
|
306
|
+
// TODO: Revisit after Pathfinder release with JSON-RPC v0.2.1 RPC Spec
|
|
307
|
+
RpcProvider.prototype.getDeclareEstimateFee = function (_a, details, blockIdentifier) {
|
|
308
|
+
var senderAddress = _a.senderAddress, contractDefinition = _a.contractDefinition, signature = _a.signature;
|
|
309
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
310
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
311
|
+
var block_id;
|
|
312
|
+
return __generator(this, function (_b) {
|
|
313
|
+
block_id = new utils_1.Block(blockIdentifier).identifier;
|
|
314
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_estimateFee', {
|
|
315
|
+
request: {
|
|
316
|
+
type: 'DECLARE',
|
|
317
|
+
contract_class: {
|
|
318
|
+
program: contractDefinition.program,
|
|
319
|
+
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
320
|
+
abi: contractDefinition.abi, // rpc 2.0
|
|
321
|
+
},
|
|
322
|
+
sender_address: senderAddress,
|
|
323
|
+
signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(signature || []),
|
|
324
|
+
version: (0, number_1.toHex)((0, number_1.toBN)((details === null || details === void 0 ? void 0 : details.version) || 0)),
|
|
325
|
+
nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
|
|
326
|
+
max_fee: (0, number_1.toHex)((0, number_1.toBN)((details === null || details === void 0 ? void 0 : details.maxFee) || 0)),
|
|
327
|
+
},
|
|
328
|
+
block_id: block_id,
|
|
329
|
+
}).then(this.responseParser.parseFeeEstimateResponse)];
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
};
|
|
333
|
+
RpcProvider.prototype.getDeployAccountEstimateFee = function (_a, details, blockIdentifier) {
|
|
334
|
+
var classHash = _a.classHash, constructorCalldata = _a.constructorCalldata, addressSalt = _a.addressSalt, signature = _a.signature;
|
|
335
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
336
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
337
|
+
var block_id;
|
|
338
|
+
return __generator(this, function (_b) {
|
|
339
|
+
block_id = new utils_1.Block(blockIdentifier).identifier;
|
|
340
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_estimateFee', {
|
|
341
|
+
request: {
|
|
342
|
+
type: 'DEPLOY_ACCOUNT',
|
|
343
|
+
constructor_calldata: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(constructorCalldata || []),
|
|
344
|
+
class_hash: (0, number_1.toHex)((0, number_1.toBN)(classHash)),
|
|
345
|
+
contract_address_salt: (0, number_1.toHex)((0, number_1.toBN)(addressSalt || 0)),
|
|
346
|
+
signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(signature || []),
|
|
347
|
+
version: (0, number_1.toHex)((0, number_1.toBN)((details === null || details === void 0 ? void 0 : details.version) || 0)),
|
|
348
|
+
nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
|
|
349
|
+
max_fee: (0, number_1.toHex)((0, number_1.toBN)((details === null || details === void 0 ? void 0 : details.maxFee) || 0)),
|
|
350
|
+
},
|
|
351
|
+
block_id: block_id,
|
|
352
|
+
}).then(this.responseParser.parseFeeEstimateResponse)];
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
};
|
|
356
|
+
// TODO: Revisit after Pathfinder release with JSON-RPC v0.2.1 RPC Spec
|
|
357
|
+
RpcProvider.prototype.declareContract = function (_a, details) {
|
|
358
|
+
var contractDefinition = _a.contractDefinition, signature = _a.signature, senderAddress = _a.senderAddress;
|
|
285
359
|
return __awaiter(this, void 0, void 0, function () {
|
|
286
|
-
var contractDefinition;
|
|
287
360
|
return __generator(this, function (_b) {
|
|
288
|
-
contractDefinition = (0, provider_1.parseContract)(contract);
|
|
289
361
|
return [2 /*return*/, this.fetchEndpoint('starknet_addDeclareTransaction', {
|
|
290
362
|
contract_class: {
|
|
291
363
|
program: contractDefinition.program,
|
|
292
364
|
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
293
365
|
abi: contractDefinition.abi, // rpc 2.0
|
|
294
366
|
},
|
|
295
|
-
version: (0, number_1.toHex)((0, number_1.toBN)(version || 0)),
|
|
367
|
+
version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
|
|
368
|
+
max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
|
|
369
|
+
signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(signature || []),
|
|
370
|
+
sender_address: senderAddress,
|
|
371
|
+
nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
|
|
296
372
|
})];
|
|
297
373
|
});
|
|
298
374
|
});
|
|
@@ -315,6 +391,18 @@ var RpcProvider = /** @class */ (function () {
|
|
|
315
391
|
});
|
|
316
392
|
});
|
|
317
393
|
};
|
|
394
|
+
RpcProvider.prototype.deployAccountContract = function (_a) {
|
|
395
|
+
var classHash = _a.classHash, constructorCalldata = _a.constructorCalldata, addressSalt = _a.addressSalt;
|
|
396
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
397
|
+
return __generator(this, function (_b) {
|
|
398
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_addDeployAccountTransaction', {
|
|
399
|
+
constructor_calldata: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(constructorCalldata || []),
|
|
400
|
+
class_hash: (0, number_1.toHex)((0, number_1.toBN)(classHash)),
|
|
401
|
+
contract_address_salt: (0, number_1.toHex)((0, number_1.toBN)(addressSalt || 0)),
|
|
402
|
+
})];
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
};
|
|
318
406
|
RpcProvider.prototype.invokeFunction = function (functionInvocation, details) {
|
|
319
407
|
return __awaiter(this, void 0, void 0, function () {
|
|
320
408
|
return __generator(this, function (_a) {
|
|
@@ -393,10 +481,10 @@ var RpcProvider = /** @class */ (function () {
|
|
|
393
481
|
return [4 /*yield*/, this.getTransactionReceipt(txHash)];
|
|
394
482
|
case 4:
|
|
395
483
|
res = _a.sent();
|
|
396
|
-
if (successStates.includes(res.status)) {
|
|
484
|
+
if (res.status && successStates.includes(res.status)) {
|
|
397
485
|
onchain = true;
|
|
398
486
|
}
|
|
399
|
-
else if (errorStates.includes(res.status)) {
|
|
487
|
+
else if (res.status && errorStates.includes(res.status)) {
|
|
400
488
|
message = res.status;
|
|
401
489
|
error = new Error(message);
|
|
402
490
|
error.response = res;
|
package/provider/sequencer.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
|
-
import { Call, CallContractResponse, ContractClass,
|
|
2
|
+
import { Call, CallContractResponse, ContractClass, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
|
|
3
3
|
import { CallL1Handler, GetContractAddressesResponse, GetTransactionStatusResponse, GetTransactionTraceResponse, Sequencer } from '../types/api';
|
|
4
|
+
import { DeclareContractTransaction, DeployAccountContractTransaction } from '../types/lib';
|
|
4
5
|
import { BigNumberish } from '../utils/number';
|
|
5
6
|
import { ProviderInterface } from './interface';
|
|
6
7
|
import { BlockIdentifier } from './utils';
|
|
7
|
-
declare type NetworkName = 'mainnet-alpha' | 'goerli-alpha';
|
|
8
|
+
declare type NetworkName = 'mainnet-alpha' | 'goerli-alpha' | 'goerli-alpha-2';
|
|
8
9
|
export declare type SequencerProviderOptions = {
|
|
9
10
|
network: NetworkName;
|
|
10
11
|
} | {
|
|
@@ -12,15 +13,17 @@ export declare type SequencerProviderOptions = {
|
|
|
12
13
|
feederGatewayUrl?: string;
|
|
13
14
|
gatewayUrl?: string;
|
|
14
15
|
chainId?: StarknetChainId;
|
|
16
|
+
headers?: object;
|
|
15
17
|
};
|
|
16
18
|
export declare class SequencerProvider implements ProviderInterface {
|
|
17
19
|
baseUrl: string;
|
|
18
20
|
feederGatewayUrl: string;
|
|
19
21
|
gatewayUrl: string;
|
|
20
22
|
chainId: StarknetChainId;
|
|
23
|
+
headers: object | undefined;
|
|
21
24
|
private responseParser;
|
|
22
25
|
constructor(optionsOrProvider?: SequencerProviderOptions);
|
|
23
|
-
protected static getNetworkFromName(name: NetworkName): "https://alpha-mainnet.starknet.io" | "https://alpha4.starknet.io";
|
|
26
|
+
protected static getNetworkFromName(name: NetworkName): "https://alpha-mainnet.starknet.io" | "https://alpha4.starknet.io" | "https://alpha4-2.starknet.io";
|
|
24
27
|
protected static getChainIdFromBaseUrl(baseUrl: string): StarknetChainId;
|
|
25
28
|
private getFetchUrl;
|
|
26
29
|
private getFetchMethod;
|
|
@@ -37,8 +40,12 @@ export declare class SequencerProvider implements ProviderInterface {
|
|
|
37
40
|
getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
|
|
38
41
|
invokeFunction(functionInvocation: Invocation, details: InvocationsDetailsWithNonce): Promise<InvokeFunctionResponse>;
|
|
39
42
|
deployContract({ contract, constructorCalldata, addressSalt, }: DeployContractPayload): Promise<DeployContractResponse>;
|
|
40
|
-
|
|
43
|
+
deployAccountContract({ classHash, constructorCalldata, addressSalt, signature }: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeployContractResponse>;
|
|
44
|
+
declareContract({ senderAddress, contractDefinition, signature }: DeclareContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeclareContractResponse>;
|
|
41
45
|
getEstimateFee(invocation: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
|
|
46
|
+
getInvokeEstimateFee(invocation: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
|
|
47
|
+
getDeclareEstimateFee({ senderAddress, contractDefinition, signature }: DeclareContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
|
|
48
|
+
getDeployAccountEstimateFee({ classHash, addressSalt, constructorCalldata, signature }: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
|
|
42
49
|
getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<Sequencer.GetCodeResponse>;
|
|
43
50
|
waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
44
51
|
/**
|
package/provider/sequencer.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -79,7 +90,7 @@ function isEmptyQueryObject(obj) {
|
|
|
79
90
|
}
|
|
80
91
|
var SequencerProvider = /** @class */ (function () {
|
|
81
92
|
function SequencerProvider(optionsOrProvider) {
|
|
82
|
-
if (optionsOrProvider === void 0) { optionsOrProvider = { network: 'goerli-alpha' }; }
|
|
93
|
+
if (optionsOrProvider === void 0) { optionsOrProvider = { network: 'goerli-alpha-2' }; }
|
|
83
94
|
var _a;
|
|
84
95
|
this.responseParser = new sequencer_1.SequencerAPIResponseParser();
|
|
85
96
|
if ('network' in optionsOrProvider) {
|
|
@@ -94,6 +105,7 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
94
105
|
this.gatewayUrl = (0, url_1.buildUrl)(this.baseUrl, 'gateway', optionsOrProvider.gatewayUrl);
|
|
95
106
|
this.chainId =
|
|
96
107
|
(_a = optionsOrProvider.chainId) !== null && _a !== void 0 ? _a : SequencerProvider.getChainIdFromBaseUrl(optionsOrProvider.baseUrl);
|
|
108
|
+
this.headers = optionsOrProvider === null || optionsOrProvider === void 0 ? void 0 : optionsOrProvider.headers;
|
|
97
109
|
}
|
|
98
110
|
}
|
|
99
111
|
SequencerProvider.getNetworkFromName = function (name) {
|
|
@@ -101,6 +113,9 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
101
113
|
case 'mainnet-alpha':
|
|
102
114
|
return 'https://alpha-mainnet.starknet.io';
|
|
103
115
|
case 'goerli-alpha':
|
|
116
|
+
return 'https://alpha4.starknet.io';
|
|
117
|
+
case 'goerli-alpha-2':
|
|
118
|
+
return 'https://alpha4-2.starknet.io';
|
|
104
119
|
default:
|
|
105
120
|
return 'https://alpha4.starknet.io';
|
|
106
121
|
}
|
|
@@ -149,30 +164,28 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
149
164
|
};
|
|
150
165
|
SequencerProvider.prototype.getHeaders = function (method) {
|
|
151
166
|
if (method === 'POST') {
|
|
152
|
-
return {
|
|
153
|
-
'Content-Type': 'application/json',
|
|
154
|
-
};
|
|
167
|
+
return __assign({ 'Content-Type': 'application/json' }, this.headers);
|
|
155
168
|
}
|
|
156
|
-
return
|
|
169
|
+
return this.headers;
|
|
157
170
|
};
|
|
158
171
|
// typesafe fetch
|
|
159
172
|
SequencerProvider.prototype.fetchEndpoint = function (endpoint) {
|
|
160
|
-
// typescript type
|
|
173
|
+
// typescript type magic to create a nice fitting function interface
|
|
161
174
|
var _a = []; // when both query and request are needed, we cant omit anything
|
|
162
175
|
for (
|
|
163
|
-
// typescript type
|
|
176
|
+
// typescript type magic to create a nice fitting function interface
|
|
164
177
|
var _i = 1 // when both query and request are needed, we cant omit anything
|
|
165
178
|
;
|
|
166
|
-
// typescript type
|
|
179
|
+
// typescript type magic to create a nice fitting function interface
|
|
167
180
|
_i < arguments.length // when both query and request are needed, we cant omit anything
|
|
168
181
|
;
|
|
169
|
-
// typescript type
|
|
182
|
+
// typescript type magic to create a nice fitting function interface
|
|
170
183
|
_i++ // when both query and request are needed, we cant omit anything
|
|
171
184
|
) {
|
|
172
|
-
// typescript type
|
|
185
|
+
// typescript type magic to create a nice fitting function interface
|
|
173
186
|
_a[_i - 1] = arguments[_i]; // when both query and request are needed, we cant omit anything
|
|
174
187
|
}
|
|
175
|
-
// typescript type
|
|
188
|
+
// typescript type magic to create a nice fitting function interface
|
|
176
189
|
var _b = __read(_a, 2), query = _b[0], request = _b[1]; // when both query and request are needed, we cant omit anything
|
|
177
190
|
return __awaiter(this, void 0, void 0, function () {
|
|
178
191
|
var baseUrl, method, queryString, headers, url, res, textResponse, responseBody, errorCode, err_1;
|
|
@@ -344,23 +357,48 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
344
357
|
});
|
|
345
358
|
});
|
|
346
359
|
};
|
|
347
|
-
SequencerProvider.prototype.
|
|
348
|
-
var
|
|
360
|
+
SequencerProvider.prototype.deployAccountContract = function (_a, details) {
|
|
361
|
+
var classHash = _a.classHash, constructorCalldata = _a.constructorCalldata, addressSalt = _a.addressSalt, signature = _a.signature;
|
|
362
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
363
|
+
return __generator(this, function (_b) {
|
|
364
|
+
return [2 /*return*/, this.fetchEndpoint('add_transaction', undefined, {
|
|
365
|
+
type: 'DEPLOY_ACCOUNT',
|
|
366
|
+
contract_address_salt: addressSalt !== null && addressSalt !== void 0 ? addressSalt : (0, stark_1.randomAddress)(),
|
|
367
|
+
constructor_calldata: (0, number_1.bigNumberishArrayToDecimalStringArray)(constructorCalldata !== null && constructorCalldata !== void 0 ? constructorCalldata : []),
|
|
368
|
+
class_hash: (0, number_1.toHex)((0, number_1.toBN)(classHash)),
|
|
369
|
+
max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
|
|
370
|
+
version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
|
|
371
|
+
nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
|
|
372
|
+
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature || []),
|
|
373
|
+
}).then(this.responseParser.parseDeployContractResponse)];
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
};
|
|
377
|
+
SequencerProvider.prototype.declareContract = function (_a, details) {
|
|
378
|
+
var senderAddress = _a.senderAddress, contractDefinition = _a.contractDefinition, signature = _a.signature;
|
|
349
379
|
return __awaiter(this, void 0, void 0, function () {
|
|
350
|
-
var contractDefinition;
|
|
351
380
|
return __generator(this, function (_b) {
|
|
352
|
-
contractDefinition = (0, provider_1.parseContract)(contract);
|
|
353
381
|
return [2 /*return*/, this.fetchEndpoint('add_transaction', undefined, {
|
|
354
382
|
type: 'DECLARE',
|
|
355
383
|
contract_class: contractDefinition,
|
|
356
|
-
nonce: (0, number_1.toHex)(
|
|
357
|
-
signature: [],
|
|
358
|
-
sender_address:
|
|
384
|
+
nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
|
|
385
|
+
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature || []),
|
|
386
|
+
sender_address: senderAddress,
|
|
387
|
+
max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
|
|
388
|
+
version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 1)),
|
|
359
389
|
}).then(this.responseParser.parseDeclareContractResponse)];
|
|
360
390
|
});
|
|
361
391
|
});
|
|
362
392
|
};
|
|
363
393
|
SequencerProvider.prototype.getEstimateFee = function (invocation, invocationDetails, blockIdentifier) {
|
|
394
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
395
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
396
|
+
return __generator(this, function (_a) {
|
|
397
|
+
return [2 /*return*/, this.getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier)];
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
};
|
|
401
|
+
SequencerProvider.prototype.getInvokeEstimateFee = function (invocation, invocationDetails, blockIdentifier) {
|
|
364
402
|
var _a;
|
|
365
403
|
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
366
404
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -376,6 +414,39 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
376
414
|
});
|
|
377
415
|
});
|
|
378
416
|
};
|
|
417
|
+
SequencerProvider.prototype.getDeclareEstimateFee = function (_a, details, blockIdentifier) {
|
|
418
|
+
var senderAddress = _a.senderAddress, contractDefinition = _a.contractDefinition, signature = _a.signature;
|
|
419
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
420
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
421
|
+
return __generator(this, function (_b) {
|
|
422
|
+
return [2 /*return*/, this.fetchEndpoint('estimate_fee', { blockIdentifier: blockIdentifier }, {
|
|
423
|
+
type: 'DECLARE',
|
|
424
|
+
sender_address: senderAddress,
|
|
425
|
+
contract_class: contractDefinition,
|
|
426
|
+
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature || []),
|
|
427
|
+
version: (0, number_1.toHex)((0, number_1.toBN)((details === null || details === void 0 ? void 0 : details.version) || 1)),
|
|
428
|
+
nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
|
|
429
|
+
}).then(this.responseParser.parseFeeEstimateResponse)];
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
};
|
|
433
|
+
SequencerProvider.prototype.getDeployAccountEstimateFee = function (_a, details, blockIdentifier) {
|
|
434
|
+
var classHash = _a.classHash, addressSalt = _a.addressSalt, constructorCalldata = _a.constructorCalldata, signature = _a.signature;
|
|
435
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
436
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
437
|
+
return __generator(this, function (_b) {
|
|
438
|
+
return [2 /*return*/, this.fetchEndpoint('estimate_fee', { blockIdentifier: blockIdentifier }, {
|
|
439
|
+
type: 'DEPLOY_ACCOUNT',
|
|
440
|
+
class_hash: (0, number_1.toHex)((0, number_1.toBN)(classHash)),
|
|
441
|
+
constructor_calldata: (0, number_1.bigNumberishArrayToDecimalStringArray)(constructorCalldata || []),
|
|
442
|
+
contract_address_salt: (0, number_1.toHex)((0, number_1.toBN)(addressSalt || 0)),
|
|
443
|
+
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature || []),
|
|
444
|
+
version: (0, number_1.toHex)((0, number_1.toBN)((details === null || details === void 0 ? void 0 : details.version) || 0)),
|
|
445
|
+
nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
|
|
446
|
+
}).then(this.responseParser.parseFeeEstimateResponse)];
|
|
447
|
+
});
|
|
448
|
+
});
|
|
449
|
+
};
|
|
379
450
|
SequencerProvider.prototype.getCode = function (contractAddress, blockIdentifier) {
|
|
380
451
|
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
381
452
|
return __awaiter(this, void 0, void 0, function () {
|
package/signer/default.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { Abi, Call, InvocationsSignerDetails, KeyPair, Signature } from '../types';
|
|
1
|
+
import { Abi, Call, DeclareSignerDetails, InvocationsSignerDetails, KeyPair, Signature } from '../types';
|
|
2
|
+
import { DeployAccountSignerDetails } from '../types/signer';
|
|
2
3
|
import { TypedData } from '../utils/typedData';
|
|
3
4
|
import { SignerInterface } from './interface';
|
|
4
5
|
export declare class Signer implements SignerInterface {
|
|
5
6
|
protected keyPair: KeyPair;
|
|
6
7
|
constructor(keyPair?: KeyPair);
|
|
7
8
|
getPubKey(): Promise<string>;
|
|
8
|
-
signTransaction(transactions: Call[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): Promise<Signature>;
|
|
9
9
|
signMessage(typedData: TypedData, accountAddress: string): Promise<Signature>;
|
|
10
|
+
signTransaction(transactions: Call[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): Promise<Signature>;
|
|
11
|
+
signDeployAccountTransaction({ classHash, contractAddress, constructorCalldata, addressSalt, maxFee, version, chainId, nonce, }: DeployAccountSignerDetails): Promise<Signature>;
|
|
12
|
+
signDeclareTransaction({ classHash, senderAddress, chainId, maxFee, version, nonce }: DeclareSignerDetails): Promise<Signature>;
|
|
10
13
|
}
|
package/signer/default.js
CHANGED
|
@@ -53,6 +53,15 @@ var Signer = /** @class */ (function () {
|
|
|
53
53
|
});
|
|
54
54
|
});
|
|
55
55
|
};
|
|
56
|
+
Signer.prototype.signMessage = function (typedData, accountAddress) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
58
|
+
var msgHash;
|
|
59
|
+
return __generator(this, function (_a) {
|
|
60
|
+
msgHash = (0, typedData_1.getMessageHash)(typedData, accountAddress);
|
|
61
|
+
return [2 /*return*/, (0, ellipticCurve_1.sign)(this.keyPair, msgHash)];
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
};
|
|
56
65
|
Signer.prototype.signTransaction = function (transactions, transactionsDetail, abis) {
|
|
57
66
|
return __awaiter(this, void 0, void 0, function () {
|
|
58
67
|
var calldata, msgHash;
|
|
@@ -66,11 +75,24 @@ var Signer = /** @class */ (function () {
|
|
|
66
75
|
});
|
|
67
76
|
});
|
|
68
77
|
};
|
|
69
|
-
Signer.prototype.
|
|
78
|
+
Signer.prototype.signDeployAccountTransaction = function (_a) {
|
|
79
|
+
var classHash = _a.classHash, contractAddress = _a.contractAddress, constructorCalldata = _a.constructorCalldata, addressSalt = _a.addressSalt, maxFee = _a.maxFee, version = _a.version, chainId = _a.chainId, nonce = _a.nonce;
|
|
70
80
|
return __awaiter(this, void 0, void 0, function () {
|
|
71
81
|
var msgHash;
|
|
72
|
-
return __generator(this, function (
|
|
73
|
-
msgHash = (0,
|
|
82
|
+
return __generator(this, function (_b) {
|
|
83
|
+
msgHash = (0, hash_1.calculateDeployAccountTransactionHash)(contractAddress, classHash, constructorCalldata, addressSalt, version, maxFee, chainId, nonce);
|
|
84
|
+
return [2 /*return*/, (0, ellipticCurve_1.sign)(this.keyPair, msgHash)];
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
Signer.prototype.signDeclareTransaction = function (
|
|
89
|
+
// contractClass: ContractClass, // Should be used once class hash is present in ContractClass
|
|
90
|
+
_a) {
|
|
91
|
+
var classHash = _a.classHash, senderAddress = _a.senderAddress, chainId = _a.chainId, maxFee = _a.maxFee, version = _a.version, nonce = _a.nonce;
|
|
92
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
93
|
+
var msgHash;
|
|
94
|
+
return __generator(this, function (_b) {
|
|
95
|
+
msgHash = (0, hash_1.calculateDeclareTransactionHash)(classHash, senderAddress, version, maxFee, chainId, nonce);
|
|
74
96
|
return [2 /*return*/, (0, ellipticCurve_1.sign)(this.keyPair, msgHash)];
|
|
75
97
|
});
|
|
76
98
|
});
|
package/signer/interface.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Abi, Call, InvocationsSignerDetails, Signature } from '../types';
|
|
1
|
+
import { Abi, Call, DeclareSignerDetails, InvocationsSignerDetails, Signature } from '../types';
|
|
2
|
+
import { DeployAccountSignerDetails } from '../types/signer';
|
|
2
3
|
import { TypedData } from '../utils/typedData';
|
|
3
4
|
export declare abstract class SignerInterface {
|
|
4
5
|
/**
|
|
@@ -24,10 +25,36 @@ export declare abstract class SignerInterface {
|
|
|
24
25
|
* - contractAddress - the address of the contract
|
|
25
26
|
* - entrypoint - the entrypoint of the contract
|
|
26
27
|
* - calldata - (defaults to []) the calldata
|
|
27
|
-
* - signature - (defaults to []) the signature
|
|
28
28
|
* @param abi (optional) the abi of the contract for better displaying
|
|
29
29
|
*
|
|
30
30
|
* @returns signature
|
|
31
31
|
*/
|
|
32
32
|
abstract signTransaction(transactions: Call[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): Promise<Signature>;
|
|
33
|
+
/**
|
|
34
|
+
* Signs a DEPLOY_ACCOUNT transaction with the starknet private key and returns the signature
|
|
35
|
+
*
|
|
36
|
+
* @param transaction
|
|
37
|
+
* - contractAddress - the computed address of the contract
|
|
38
|
+
* - constructorCalldata - calldata to be passed in deploy constructor
|
|
39
|
+
* - addressSalt - contract address salt
|
|
40
|
+
* - chainId - the chainId to declare contract on
|
|
41
|
+
* - maxFee - maxFee for the declare transaction
|
|
42
|
+
* - version - transaction version
|
|
43
|
+
* - nonce - Nonce of the declare transaction
|
|
44
|
+
* @returns signature
|
|
45
|
+
*/
|
|
46
|
+
abstract signDeployAccountTransaction(transaction: DeployAccountSignerDetails): Promise<Signature>;
|
|
47
|
+
/**
|
|
48
|
+
* Signs a DECLARE transaction with the starknet private key and returns the signature
|
|
49
|
+
*
|
|
50
|
+
* @param transaction
|
|
51
|
+
* - classHash - computed class hash. Will be replaced by ContractClass in future once class hash is present in CompiledContract
|
|
52
|
+
* - senderAddress - the address of the sender
|
|
53
|
+
* - chainId - the chainId to declare contract on
|
|
54
|
+
* - maxFee - maxFee for the declare transaction
|
|
55
|
+
* - version - transaction version
|
|
56
|
+
* - nonce - Nonce of the declare transaction
|
|
57
|
+
* @returns signature
|
|
58
|
+
*/
|
|
59
|
+
abstract signDeclareTransaction(transaction: DeclareSignerDetails): Promise<Signature>;
|
|
33
60
|
}
|