starknet 4.9.0 → 4.11.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 +43 -0
- package/README.md +1 -3
- package/__tests__/account.test.ts +5 -1
- package/__tests__/defaultProvider.test.ts +97 -210
- package/__tests__/fixtures.ts +2 -2
- package/__tests__/rpcProvider.test.ts +7 -4
- package/__tests__/udc.test.ts +41 -0
- package/account/default.d.ts +3 -1
- package/account/default.js +53 -3
- package/account/interface.d.ts +24 -7
- package/constants.d.ts +7 -1
- package/constants.js +7 -1
- package/contract/default.d.ts +11 -27
- package/contract/default.js +104 -120
- package/contract/interface.d.ts +5 -2
- package/dist/account/default.d.ts +3 -1
- package/dist/account/default.js +53 -3
- package/dist/account/interface.d.ts +24 -7
- package/dist/constants.d.ts +7 -1
- package/dist/constants.js +7 -1
- package/dist/contract/default.d.ts +11 -27
- package/dist/contract/default.js +104 -120
- package/dist/contract/interface.d.ts +5 -2
- package/dist/provider/default.d.ts +4 -2
- package/dist/provider/default.js +13 -2
- package/dist/provider/interface.d.ts +18 -3
- package/dist/provider/rpc.d.ts +15 -10
- package/dist/provider/rpc.js +71 -31
- package/dist/provider/sequencer.d.ts +6 -2
- package/dist/provider/sequencer.js +33 -5
- package/dist/signer/default.d.ts +2 -2
- package/dist/signer/default.js +15 -15
- package/dist/signer/interface.d.ts +2 -0
- package/dist/types/api/index.d.ts +0 -6
- package/dist/types/api/openrpc.d.ts +147 -98
- package/dist/types/api/openrpc.js +22 -4
- package/dist/types/index.d.ts +1 -1
- package/dist/types/lib.d.ts +22 -2
- package/dist/types/lib.js +6 -0
- package/dist/utils/number.d.ts +1 -0
- package/dist/utils/number.js +3 -1
- package/package.json +1 -1
- package/provider/default.d.ts +4 -2
- package/provider/default.js +13 -2
- package/provider/interface.d.ts +18 -3
- package/provider/rpc.d.ts +15 -10
- package/provider/rpc.js +71 -31
- package/provider/sequencer.d.ts +6 -2
- package/provider/sequencer.js +33 -5
- package/signer/default.d.ts +2 -2
- package/signer/default.js +15 -15
- package/signer/interface.d.ts +2 -0
- package/src/account/default.ts +51 -7
- package/src/account/interface.ts +34 -7
- package/src/constants.ts +7 -0
- package/src/contract/default.ts +123 -140
- package/src/contract/interface.ts +5 -2
- package/src/provider/default.ts +21 -3
- package/src/provider/interface.ts +26 -2
- package/src/provider/rpc.ts +73 -45
- package/src/provider/sequencer.ts +24 -4
- package/src/signer/default.ts +18 -18
- package/src/signer/interface.ts +2 -0
- package/src/types/api/index.ts +0 -4
- package/src/types/api/openrpc.ts +193 -105
- package/src/types/api/rpc.ts +0 -1
- package/src/types/index.ts +1 -1
- package/src/types/lib.ts +23 -2
- package/src/utils/number.ts +2 -0
- package/types/api/index.d.ts +0 -6
- package/types/api/openrpc.d.ts +147 -98
- package/types/api/openrpc.js +22 -4
- package/types/index.d.ts +1 -1
- package/types/lib.d.ts +22 -2
- package/types/lib.js +6 -0
- package/utils/number.d.ts +1 -0
- package/utils/number.js +3 -1
- package/www/docs/API/account.md +122 -22
- package/www/docs/API/contract.md +39 -3
- package/www/docs/API/provider.md +4 -0
- package/www/docs/API/signer.md +56 -2
package/dist/provider/rpc.d.ts
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
|
-
import { Call, CallContractResponse, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse,
|
|
2
|
+
import { Call, CallContractResponse, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
|
|
3
3
|
import { RPC } from '../types/api';
|
|
4
|
-
import { DeclareContractTransaction,
|
|
4
|
+
import { DeclareContractTransaction, DeployAccountContractTransaction, InvocationsDetails } from '../types/lib';
|
|
5
5
|
import { BigNumberish } from '../utils/number';
|
|
6
6
|
import { ProviderInterface } from './interface';
|
|
7
7
|
import { BlockIdentifier } from './utils';
|
|
8
8
|
export declare type RpcProviderOptions = {
|
|
9
9
|
nodeUrl: string;
|
|
10
10
|
retries?: number;
|
|
11
|
+
headers?: object;
|
|
11
12
|
};
|
|
12
13
|
export declare class RpcProvider implements ProviderInterface {
|
|
13
14
|
nodeUrl: string;
|
|
14
15
|
chainId: StarknetChainId;
|
|
16
|
+
headers: object;
|
|
15
17
|
private responseParser;
|
|
16
18
|
private retries;
|
|
17
19
|
constructor(optionsOrProvider: RpcProviderOptions);
|
|
@@ -23,26 +25,29 @@ export declare class RpcProvider implements ProviderInterface {
|
|
|
23
25
|
getBlockHashAndNumber(): Promise<RPC.BlockHashAndNumber>;
|
|
24
26
|
getBlockWithTxHashes(blockIdentifier?: BlockIdentifier): Promise<RPC.GetBlockWithTxHashesResponse>;
|
|
25
27
|
getBlockWithTxs(blockIdentifier?: BlockIdentifier): Promise<RPC.GetBlockWithTxs>;
|
|
26
|
-
getClassHashAt(
|
|
28
|
+
getClassHashAt(contractAddress: RPC.ContractAddress, blockIdentifier?: BlockIdentifier): Promise<RPC.Felt>;
|
|
27
29
|
getNonce(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<RPC.Nonce>;
|
|
28
30
|
getPendingTransactions(): Promise<RPC.PendingTransactions>;
|
|
29
31
|
getProtocolVersion(): Promise<Error>;
|
|
30
|
-
getStateUpdate(blockIdentifier
|
|
32
|
+
getStateUpdate(blockIdentifier?: BlockIdentifier): Promise<RPC.StateUpdate>;
|
|
31
33
|
getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
32
34
|
getTransaction(txHash: string): Promise<GetTransactionResponse>;
|
|
33
35
|
getTransactionByHash(txHash: string): Promise<RPC.GetTransactionByHashResponse>;
|
|
34
36
|
getTransactionByBlockIdAndIndex(blockIdentifier: BlockIdentifier, index: number): Promise<RPC.GetTransactionByBlockIdAndIndex>;
|
|
35
|
-
getTransactionReceipt(txHash: string): Promise<
|
|
36
|
-
getClass(classHash: RPC.Felt): Promise<RPC.ContractClass>;
|
|
37
|
-
getClassAt(contractAddress: string, blockIdentifier
|
|
37
|
+
getTransactionReceipt(txHash: string): Promise<RPC.TransactionReceipt>;
|
|
38
|
+
getClass(classHash: RPC.Felt, blockIdentifier?: BlockIdentifier): Promise<RPC.ContractClass>;
|
|
39
|
+
getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<RPC.ContractClass>;
|
|
38
40
|
getCode(_contractAddress: string, _blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
|
|
39
41
|
getEstimateFee(invocation: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
|
|
40
42
|
getInvokeEstimateFee(invocation: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
|
|
41
43
|
getDeclareEstimateFee({ senderAddress, contractDefinition, signature }: DeclareContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
|
|
42
44
|
getDeployAccountEstimateFee({ classHash, constructorCalldata, addressSalt, signature }: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
|
|
43
45
|
declareContract({ contractDefinition, signature, senderAddress }: DeclareContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeclareContractResponse>;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated This method wont be supported soon, use Account.deploy instead
|
|
48
|
+
*/
|
|
49
|
+
deployContract({ contract, constructorCalldata, addressSalt }: DeployContractPayload, details?: InvocationsDetails): Promise<DeployContractResponse>;
|
|
50
|
+
deployAccountContract({ classHash, constructorCalldata, addressSalt, signature }: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeployContractResponse>;
|
|
46
51
|
invokeFunction(functionInvocation: Invocation, details: InvocationsDetailsWithNonce): Promise<InvokeFunctionResponse>;
|
|
47
52
|
callContract(call: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
|
|
48
53
|
traceTransaction(transactionHash: RPC.TransactionHash): Promise<RPC.Trace>;
|
|
@@ -55,7 +60,7 @@ export declare class RpcProvider implements ProviderInterface {
|
|
|
55
60
|
* @param blockIdentifier
|
|
56
61
|
* @returns Number of transactions
|
|
57
62
|
*/
|
|
58
|
-
getTransactionCount(blockIdentifier
|
|
63
|
+
getTransactionCount(blockIdentifier?: BlockIdentifier): Promise<RPC.GetTransactionCountResponse>;
|
|
59
64
|
/**
|
|
60
65
|
* Gets the latest block number
|
|
61
66
|
*
|
package/dist/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,18 +63,19 @@ 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
|
});
|
|
61
73
|
}
|
|
62
74
|
RpcProvider.prototype.fetch = function (method, params) {
|
|
63
|
-
return (0, fetchPonyfill_1.default)(this.nodeUrl, {
|
|
75
|
+
return (0, fetchPonyfill_1.default)("".concat(this.nodeUrl, "/rpc/v0.2"), {
|
|
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) {
|
|
@@ -141,7 +153,8 @@ var RpcProvider = /** @class */ (function () {
|
|
|
141
153
|
});
|
|
142
154
|
});
|
|
143
155
|
};
|
|
144
|
-
RpcProvider.prototype.getClassHashAt = function (
|
|
156
|
+
RpcProvider.prototype.getClassHashAt = function (contractAddress, blockIdentifier) {
|
|
157
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
145
158
|
return __awaiter(this, void 0, void 0, function () {
|
|
146
159
|
var block_id;
|
|
147
160
|
return __generator(this, function (_a) {
|
|
@@ -181,6 +194,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
181
194
|
});
|
|
182
195
|
};
|
|
183
196
|
RpcProvider.prototype.getStateUpdate = function (blockIdentifier) {
|
|
197
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
184
198
|
return __awaiter(this, void 0, void 0, function () {
|
|
185
199
|
var block_id;
|
|
186
200
|
return __generator(this, function (_a) {
|
|
@@ -235,14 +249,18 @@ var RpcProvider = /** @class */ (function () {
|
|
|
235
249
|
});
|
|
236
250
|
});
|
|
237
251
|
};
|
|
238
|
-
RpcProvider.prototype.getClass = function (classHash) {
|
|
252
|
+
RpcProvider.prototype.getClass = function (classHash, blockIdentifier) {
|
|
253
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
239
254
|
return __awaiter(this, void 0, void 0, function () {
|
|
255
|
+
var block_id;
|
|
240
256
|
return __generator(this, function (_a) {
|
|
241
|
-
|
|
257
|
+
block_id = new utils_1.Block(blockIdentifier).identifier;
|
|
258
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getClass', { class_hash: classHash, block_id: block_id })];
|
|
242
259
|
});
|
|
243
260
|
});
|
|
244
261
|
};
|
|
245
262
|
RpcProvider.prototype.getClassAt = function (contractAddress, blockIdentifier) {
|
|
263
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
246
264
|
return __awaiter(this, void 0, void 0, function () {
|
|
247
265
|
var block_id;
|
|
248
266
|
return __generator(this, function (_a) {
|
|
@@ -257,7 +275,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
257
275
|
RpcProvider.prototype.getCode = function (_contractAddress, _blockIdentifier) {
|
|
258
276
|
return __awaiter(this, void 0, void 0, function () {
|
|
259
277
|
return __generator(this, function (_a) {
|
|
260
|
-
throw new Error('RPC
|
|
278
|
+
throw new Error('RPC does not implement getCode function');
|
|
261
279
|
});
|
|
262
280
|
});
|
|
263
281
|
};
|
|
@@ -346,46 +364,61 @@ var RpcProvider = /** @class */ (function () {
|
|
|
346
364
|
return __awaiter(this, void 0, void 0, function () {
|
|
347
365
|
return __generator(this, function (_b) {
|
|
348
366
|
return [2 /*return*/, this.fetchEndpoint('starknet_addDeclareTransaction', {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
367
|
+
declare_transaction: {
|
|
368
|
+
contract_class: {
|
|
369
|
+
program: contractDefinition.program,
|
|
370
|
+
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
371
|
+
abi: contractDefinition.abi, // rpc 2.0
|
|
372
|
+
},
|
|
373
|
+
type: 'DECLARE',
|
|
374
|
+
version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
|
|
375
|
+
max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
|
|
376
|
+
signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(signature || []),
|
|
377
|
+
sender_address: senderAddress,
|
|
378
|
+
nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
|
|
353
379
|
},
|
|
354
|
-
version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
|
|
355
|
-
max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
|
|
356
|
-
signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(signature || []),
|
|
357
|
-
sender_address: senderAddress,
|
|
358
|
-
nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
|
|
359
380
|
})];
|
|
360
381
|
});
|
|
361
382
|
});
|
|
362
383
|
};
|
|
363
|
-
|
|
384
|
+
/**
|
|
385
|
+
* @deprecated This method wont be supported soon, use Account.deploy instead
|
|
386
|
+
*/
|
|
387
|
+
RpcProvider.prototype.deployContract = function (_a, details) {
|
|
364
388
|
var contract = _a.contract, constructorCalldata = _a.constructorCalldata, addressSalt = _a.addressSalt;
|
|
365
389
|
return __awaiter(this, void 0, void 0, function () {
|
|
366
390
|
var contractDefinition;
|
|
367
391
|
return __generator(this, function (_b) {
|
|
368
392
|
contractDefinition = (0, provider_1.parseContract)(contract);
|
|
369
393
|
return [2 /*return*/, this.fetchEndpoint('starknet_addDeployTransaction', {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
394
|
+
deploy_transaction: {
|
|
395
|
+
contract_address_salt: addressSalt !== null && addressSalt !== void 0 ? addressSalt : (0, stark_1.randomAddress)(),
|
|
396
|
+
constructor_calldata: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(constructorCalldata !== null && constructorCalldata !== void 0 ? constructorCalldata : []),
|
|
397
|
+
contract_class: {
|
|
398
|
+
program: contractDefinition.program,
|
|
399
|
+
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
400
|
+
abi: contractDefinition.abi,
|
|
401
|
+
},
|
|
402
|
+
type: 'DEPLOY',
|
|
403
|
+
version: (0, number_1.toHex)((0, number_1.toBN)((details === null || details === void 0 ? void 0 : details.version) || 0)),
|
|
376
404
|
},
|
|
377
405
|
})];
|
|
378
406
|
});
|
|
379
407
|
});
|
|
380
408
|
};
|
|
381
|
-
RpcProvider.prototype.deployAccountContract = function (_a) {
|
|
382
|
-
var classHash = _a.classHash, constructorCalldata = _a.constructorCalldata, addressSalt = _a.addressSalt;
|
|
409
|
+
RpcProvider.prototype.deployAccountContract = function (_a, details) {
|
|
410
|
+
var classHash = _a.classHash, constructorCalldata = _a.constructorCalldata, addressSalt = _a.addressSalt, signature = _a.signature;
|
|
383
411
|
return __awaiter(this, void 0, void 0, function () {
|
|
384
412
|
return __generator(this, function (_b) {
|
|
385
413
|
return [2 /*return*/, this.fetchEndpoint('starknet_addDeployAccountTransaction', {
|
|
386
414
|
constructor_calldata: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(constructorCalldata || []),
|
|
387
415
|
class_hash: (0, number_1.toHex)((0, number_1.toBN)(classHash)),
|
|
388
416
|
contract_address_salt: (0, number_1.toHex)((0, number_1.toBN)(addressSalt || 0)),
|
|
417
|
+
type: 'DEPLOY',
|
|
418
|
+
max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
|
|
419
|
+
version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
|
|
420
|
+
signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(signature || []),
|
|
421
|
+
nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
|
|
389
422
|
})];
|
|
390
423
|
});
|
|
391
424
|
});
|
|
@@ -394,13 +427,15 @@ var RpcProvider = /** @class */ (function () {
|
|
|
394
427
|
return __awaiter(this, void 0, void 0, function () {
|
|
395
428
|
return __generator(this, function (_a) {
|
|
396
429
|
return [2 /*return*/, this.fetchEndpoint('starknet_addInvokeTransaction', {
|
|
397
|
-
|
|
398
|
-
|
|
430
|
+
invoke_transaction: {
|
|
431
|
+
sender_address: functionInvocation.contractAddress,
|
|
399
432
|
calldata: (0, provider_1.parseCalldata)(functionInvocation.calldata),
|
|
433
|
+
type: 'INVOKE',
|
|
434
|
+
max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
|
|
435
|
+
version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
|
|
436
|
+
signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(functionInvocation.signature || []),
|
|
437
|
+
nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
|
|
400
438
|
},
|
|
401
|
-
signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(functionInvocation.signature || []),
|
|
402
|
-
max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
|
|
403
|
-
version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
|
|
404
439
|
})];
|
|
405
440
|
});
|
|
406
441
|
});
|
|
@@ -446,7 +481,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
446
481
|
RpcProvider.prototype.waitForTransaction = function (txHash, retryInterval) {
|
|
447
482
|
if (retryInterval === void 0) { retryInterval = 8000; }
|
|
448
483
|
return __awaiter(this, void 0, void 0, function () {
|
|
449
|
-
var retries, onchain, successStates, errorStates, res, message, error, error_2;
|
|
484
|
+
var retries, onchain, successStates, errorStates, res, error, message, error, error_2;
|
|
450
485
|
return __generator(this, function (_a) {
|
|
451
486
|
switch (_a.label) {
|
|
452
487
|
case 0:
|
|
@@ -468,6 +503,10 @@ var RpcProvider = /** @class */ (function () {
|
|
|
468
503
|
return [4 /*yield*/, this.getTransactionReceipt(txHash)];
|
|
469
504
|
case 4:
|
|
470
505
|
res = _a.sent();
|
|
506
|
+
if (!('status' in res)) {
|
|
507
|
+
error = new Error('pending transaction');
|
|
508
|
+
throw error;
|
|
509
|
+
}
|
|
471
510
|
if (res.status && successStates.includes(res.status)) {
|
|
472
511
|
onchain = true;
|
|
473
512
|
}
|
|
@@ -506,6 +545,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
506
545
|
* @returns Number of transactions
|
|
507
546
|
*/
|
|
508
547
|
RpcProvider.prototype.getTransactionCount = function (blockIdentifier) {
|
|
548
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
509
549
|
return __awaiter(this, void 0, void 0, function () {
|
|
510
550
|
var block_id;
|
|
511
551
|
return __generator(this, function (_a) {
|
|
@@ -5,7 +5,7 @@ import { DeclareContractTransaction, DeployAccountContractTransaction } from '..
|
|
|
5
5
|
import { BigNumberish } from '../utils/number';
|
|
6
6
|
import { ProviderInterface } from './interface';
|
|
7
7
|
import { BlockIdentifier } from './utils';
|
|
8
|
-
declare type NetworkName = 'mainnet-alpha' | 'goerli-alpha';
|
|
8
|
+
declare type NetworkName = 'mainnet-alpha' | 'goerli-alpha' | 'goerli-alpha-2';
|
|
9
9
|
export declare type SequencerProviderOptions = {
|
|
10
10
|
network: NetworkName;
|
|
11
11
|
} | {
|
|
@@ -13,15 +13,17 @@ export declare type SequencerProviderOptions = {
|
|
|
13
13
|
feederGatewayUrl?: string;
|
|
14
14
|
gatewayUrl?: string;
|
|
15
15
|
chainId?: StarknetChainId;
|
|
16
|
+
headers?: object;
|
|
16
17
|
};
|
|
17
18
|
export declare class SequencerProvider implements ProviderInterface {
|
|
18
19
|
baseUrl: string;
|
|
19
20
|
feederGatewayUrl: string;
|
|
20
21
|
gatewayUrl: string;
|
|
21
22
|
chainId: StarknetChainId;
|
|
23
|
+
headers: object | undefined;
|
|
22
24
|
private responseParser;
|
|
23
25
|
constructor(optionsOrProvider?: SequencerProviderOptions);
|
|
24
|
-
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";
|
|
25
27
|
protected static getChainIdFromBaseUrl(baseUrl: string): StarknetChainId;
|
|
26
28
|
private getFetchUrl;
|
|
27
29
|
private getFetchMethod;
|
|
@@ -36,6 +38,8 @@ export declare class SequencerProvider implements ProviderInterface {
|
|
|
36
38
|
getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
|
|
37
39
|
getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse>;
|
|
38
40
|
getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
|
|
41
|
+
getClassHashAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<string>;
|
|
42
|
+
getClass(classHash: string): Promise<ContractClass>;
|
|
39
43
|
invokeFunction(functionInvocation: Invocation, details: InvocationsDetailsWithNonce): Promise<InvokeFunctionResponse>;
|
|
40
44
|
deployContract({ contract, constructorCalldata, addressSalt, }: DeployContractPayload): Promise<DeployContractResponse>;
|
|
41
45
|
deployAccountContract({ classHash, constructorCalldata, addressSalt, signature }: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeployContractResponse>;
|
|
@@ -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,11 +164,9 @@ 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) {
|
|
@@ -313,6 +326,21 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
313
326
|
});
|
|
314
327
|
});
|
|
315
328
|
};
|
|
329
|
+
SequencerProvider.prototype.getClassHashAt = function (contractAddress, blockIdentifier) {
|
|
330
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
331
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
332
|
+
return __generator(this, function (_a) {
|
|
333
|
+
return [2 /*return*/, this.fetchEndpoint('get_class_hash_at', { blockIdentifier: blockIdentifier, contractAddress: contractAddress })];
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
};
|
|
337
|
+
SequencerProvider.prototype.getClass = function (classHash) {
|
|
338
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
339
|
+
return __generator(this, function (_a) {
|
|
340
|
+
return [2 /*return*/, this.fetchEndpoint('get_class_by_hash', { classHash: classHash }).then(provider_1.parseContract)];
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
};
|
|
316
344
|
SequencerProvider.prototype.invokeFunction = function (functionInvocation, details) {
|
|
317
345
|
var _a, _b;
|
|
318
346
|
return __awaiter(this, void 0, void 0, function () {
|
package/dist/signer/default.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ export declare class Signer implements SignerInterface {
|
|
|
6
6
|
protected keyPair: KeyPair;
|
|
7
7
|
constructor(keyPair?: KeyPair);
|
|
8
8
|
getPubKey(): Promise<string>;
|
|
9
|
+
signMessage(typedData: TypedData, accountAddress: string): Promise<Signature>;
|
|
9
10
|
signTransaction(transactions: Call[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): Promise<Signature>;
|
|
10
|
-
signDeclareTransaction({ classHash, senderAddress, chainId, maxFee, version, nonce }: DeclareSignerDetails): Promise<Signature>;
|
|
11
11
|
signDeployAccountTransaction({ classHash, contractAddress, constructorCalldata, addressSalt, maxFee, version, chainId, nonce, }: DeployAccountSignerDetails): Promise<Signature>;
|
|
12
|
-
|
|
12
|
+
signDeclareTransaction({ classHash, senderAddress, chainId, maxFee, version, nonce }: DeclareSignerDetails): Promise<Signature>;
|
|
13
13
|
}
|
package/dist/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,18 +75,6 @@ var Signer = /** @class */ (function () {
|
|
|
66
75
|
});
|
|
67
76
|
});
|
|
68
77
|
};
|
|
69
|
-
Signer.prototype.signDeclareTransaction = function (
|
|
70
|
-
// contractClass: ContractClass, // Should be used once class hash is present in ContractClass
|
|
71
|
-
_a) {
|
|
72
|
-
var classHash = _a.classHash, senderAddress = _a.senderAddress, chainId = _a.chainId, maxFee = _a.maxFee, version = _a.version, nonce = _a.nonce;
|
|
73
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
74
|
-
var msgHash;
|
|
75
|
-
return __generator(this, function (_b) {
|
|
76
|
-
msgHash = (0, hash_1.calculateDeclareTransactionHash)(classHash, senderAddress, version, maxFee, chainId, nonce);
|
|
77
|
-
return [2 /*return*/, (0, ellipticCurve_1.sign)(this.keyPair, msgHash)];
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
78
|
Signer.prototype.signDeployAccountTransaction = function (_a) {
|
|
82
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;
|
|
83
80
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -88,11 +85,14 @@ var Signer = /** @class */ (function () {
|
|
|
88
85
|
});
|
|
89
86
|
});
|
|
90
87
|
};
|
|
91
|
-
Signer.prototype.
|
|
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
92
|
return __awaiter(this, void 0, void 0, function () {
|
|
93
93
|
var msgHash;
|
|
94
|
-
return __generator(this, function (
|
|
95
|
-
msgHash = (0,
|
|
94
|
+
return __generator(this, function (_b) {
|
|
95
|
+
msgHash = (0, hash_1.calculateDeclareTransactionHash)(classHash, senderAddress, version, maxFee, chainId, nonce);
|
|
96
96
|
return [2 /*return*/, (0, ellipticCurve_1.sign)(this.keyPair, msgHash)];
|
|
97
97
|
});
|
|
98
98
|
});
|
|
@@ -32,6 +32,7 @@ export declare abstract class SignerInterface {
|
|
|
32
32
|
abstract signTransaction(transactions: Call[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): Promise<Signature>;
|
|
33
33
|
/**
|
|
34
34
|
* Signs a DEPLOY_ACCOUNT transaction with the starknet private key and returns the signature
|
|
35
|
+
*
|
|
35
36
|
* @param transaction
|
|
36
37
|
* - contractAddress - the computed address of the contract
|
|
37
38
|
* - constructorCalldata - calldata to be passed in deploy constructor
|
|
@@ -45,6 +46,7 @@ export declare abstract class SignerInterface {
|
|
|
45
46
|
abstract signDeployAccountTransaction(transaction: DeployAccountSignerDetails): Promise<Signature>;
|
|
46
47
|
/**
|
|
47
48
|
* Signs a DECLARE transaction with the starknet private key and returns the signature
|
|
49
|
+
*
|
|
48
50
|
* @param transaction
|
|
49
51
|
* - classHash - computed class hash. Will be replaced by ContractClass in future once class hash is present in CompiledContract
|
|
50
52
|
* - senderAddress - the address of the sender
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { BigNumberish } from '../../utils/number';
|
|
2
2
|
import { Signature } from '../lib';
|
|
3
|
-
export declare type RawArgs = {
|
|
4
|
-
[inputName: string]: string | string[] | {
|
|
5
|
-
type: 'struct';
|
|
6
|
-
[k: string]: BigNumberish;
|
|
7
|
-
};
|
|
8
|
-
};
|
|
9
3
|
export declare type Calldata = string[];
|
|
10
4
|
export declare type Overrides = {
|
|
11
5
|
maxFee?: BigNumberish;
|