starknet 4.3.0 → 4.4.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 +40 -1
- package/__mocks__/typedDataSessionExample.json +42 -0
- package/__tests__/defaultProvider.test.ts +11 -24
- package/__tests__/rpcProvider.test.ts +32 -5
- package/__tests__/sequencerProvider.test.ts +9 -1
- package/__tests__/utils/__snapshots__/ellipticalCurve.test.ts.snap +2 -0
- package/__tests__/utils/ellipticalCurve.test.ts +5 -0
- package/__tests__/utils/merkle.test.ts +146 -0
- package/__tests__/utils/typedData.test.ts +107 -9
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/provider/default.d.ts +2 -2
- package/dist/provider/default.js +3 -3
- package/dist/provider/interface.d.ts +6 -3
- package/dist/provider/rpc.d.ts +9 -4
- package/dist/provider/rpc.js +70 -28
- package/dist/provider/sequencer.d.ts +2 -2
- package/dist/provider/sequencer.js +4 -4
- package/dist/provider/utils.d.ts +12 -0
- package/dist/provider/utils.js +17 -1
- package/dist/signer/default.d.ts +1 -1
- package/dist/signer/default.js +1 -0
- package/dist/types/api/openrpc.d.ts +151 -0
- package/dist/types/api/openrpc.js +9 -0
- package/dist/types/api/rpc.d.ts +22 -43
- package/dist/types/provider.d.ts +5 -5
- package/dist/utils/ellipticCurve.d.ts +13 -0
- package/dist/utils/ellipticCurve.js +20 -16
- package/dist/utils/hash.js +8 -6
- package/dist/utils/merkle.d.ts +10 -0
- package/dist/utils/merkle.js +90 -0
- package/dist/utils/number.d.ts +1 -0
- package/dist/utils/number.js +6 -2
- package/dist/utils/responseParser/rpc.d.ts +13 -3
- package/dist/utils/responseParser/rpc.js +2 -10
- package/dist/utils/responseParser/sequencer.d.ts +4 -1
- package/dist/utils/responseParser/sequencer.js +1 -7
- package/dist/utils/typedData/index.d.ts +23 -8
- package/dist/utils/typedData/index.js +70 -31
- package/dist/utils/typedData/types.d.ts +8 -3
- package/index.d.ts +1 -0
- package/index.js +2 -1
- package/package.json +1 -1
- package/provider/default.d.ts +2 -2
- package/provider/default.js +3 -3
- package/provider/interface.d.ts +6 -3
- package/provider/rpc.d.ts +9 -4
- package/provider/rpc.js +70 -28
- package/provider/sequencer.d.ts +2 -2
- package/provider/sequencer.js +4 -4
- package/provider/utils.d.ts +12 -0
- package/provider/utils.js +17 -1
- package/signer/default.d.ts +1 -1
- package/signer/default.js +1 -0
- package/src/index.ts +1 -0
- package/src/provider/default.ts +2 -3
- package/src/provider/interface.ts +5 -3
- package/src/provider/rpc.ts +59 -32
- package/src/provider/sequencer.ts +3 -6
- package/src/provider/utils.ts +22 -1
- package/src/signer/default.ts +2 -2
- package/src/types/api/openrpc.ts +168 -0
- package/src/types/api/rpc.ts +22 -45
- package/src/types/provider.ts +5 -5
- package/src/utils/ellipticCurve.ts +20 -16
- package/src/utils/hash.ts +8 -6
- package/src/utils/merkle.ts +70 -0
- package/src/utils/number.ts +5 -1
- package/src/utils/responseParser/rpc.ts +16 -13
- package/src/utils/responseParser/sequencer.ts +5 -8
- package/src/utils/typedData/index.ts +88 -34
- package/src/utils/typedData/types.ts +12 -4
- package/types/api/openrpc.d.ts +151 -0
- package/types/api/openrpc.js +9 -0
- package/types/api/rpc.d.ts +22 -43
- package/types/provider.d.ts +5 -5
- package/utils/ellipticCurve.d.ts +13 -0
- package/utils/ellipticCurve.js +20 -16
- package/utils/hash.js +8 -6
- package/utils/merkle.d.ts +10 -0
- package/utils/merkle.js +90 -0
- package/utils/number.d.ts +1 -0
- package/utils/number.js +6 -2
- package/utils/responseParser/rpc.d.ts +13 -3
- package/utils/responseParser/rpc.js +2 -10
- package/utils/responseParser/sequencer.d.ts +4 -1
- package/utils/responseParser/sequencer.js +1 -7
- package/utils/typedData/index.d.ts +23 -8
- package/utils/typedData/index.js +70 -31
- package/utils/typedData/types.d.ts +8 -3
- package/www/docs/API/account.md +20 -18
- package/www/docs/API/contract.md +10 -10
- package/www/docs/API/contractFactory.md +14 -11
- package/www/docs/API/provider.md +29 -63
- package/www/docs/API/signer.md +8 -10
- package/www/docs/API/utils.md +157 -74
- package/www/guides/account.md +12 -12
- package/www/guides/erc20.md +19 -4
- package/www/guides/intro.md +3 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
|
-
import {
|
|
2
|
+
import { Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
|
|
3
3
|
import { BigNumberish } from '../utils/number';
|
|
4
4
|
import { ProviderInterface } from './interface';
|
|
5
5
|
import { RpcProviderOptions } from './rpc';
|
|
@@ -16,7 +16,7 @@ export declare class Provider implements ProviderInterface {
|
|
|
16
16
|
getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
|
|
17
17
|
getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
|
|
18
18
|
getEstimateFee(invocation: Invocation, blockIdentifier?: BlockIdentifier, invocationDetails?: InvocationsDetails): Promise<EstimateFeeResponse>;
|
|
19
|
-
getStorageAt(contractAddress: string, key: BigNumberish,
|
|
19
|
+
getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
20
20
|
getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
|
|
21
21
|
getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse>;
|
|
22
22
|
callContract(request: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
|
package/dist/provider/default.js
CHANGED
|
@@ -86,11 +86,11 @@ var Provider = /** @class */ (function () {
|
|
|
86
86
|
});
|
|
87
87
|
});
|
|
88
88
|
};
|
|
89
|
-
Provider.prototype.getStorageAt = function (contractAddress, key,
|
|
90
|
-
if (
|
|
89
|
+
Provider.prototype.getStorageAt = function (contractAddress, key, blockIdentifier) {
|
|
90
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
91
91
|
return __awaiter(this, void 0, void 0, function () {
|
|
92
92
|
return __generator(this, function (_a) {
|
|
93
|
-
return [2 /*return*/, this.provider.getStorageAt(contractAddress, key,
|
|
93
|
+
return [2 /*return*/, this.provider.getStorageAt(contractAddress, key, blockIdentifier)];
|
|
94
94
|
});
|
|
95
95
|
});
|
|
96
96
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
|
|
3
3
|
import type { BigNumberish } from '../utils/number';
|
|
4
4
|
import { BlockIdentifier } from './utils';
|
|
5
5
|
export declare abstract class ProviderInterface {
|
|
@@ -19,6 +19,9 @@ export declare abstract class ProviderInterface {
|
|
|
19
19
|
* @returns the block object
|
|
20
20
|
*/
|
|
21
21
|
abstract getBlock(blockIdentifier: BlockIdentifier): Promise<GetBlockResponse>;
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated The method should not be used
|
|
24
|
+
*/
|
|
22
25
|
abstract getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
|
|
23
26
|
/**
|
|
24
27
|
* Gets the contract class of the deployed contract.
|
|
@@ -33,10 +36,10 @@ export declare abstract class ProviderInterface {
|
|
|
33
36
|
*
|
|
34
37
|
* @param contractAddress
|
|
35
38
|
* @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
|
|
36
|
-
* @param
|
|
39
|
+
* @param blockIdentifier - block identifier
|
|
37
40
|
* @returns the value of the storage variable
|
|
38
41
|
*/
|
|
39
|
-
abstract getStorageAt(contractAddress: string, key: BigNumberish,
|
|
42
|
+
abstract getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier: BlockIdentifier): Promise<BigNumberish>;
|
|
40
43
|
/**
|
|
41
44
|
* Gets the transaction information from a tx id.
|
|
42
45
|
*
|
package/dist/provider/rpc.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
|
-
import {
|
|
2
|
+
import { Call, CallContractResponse, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
|
|
3
3
|
import { RPC } from '../types/api';
|
|
4
4
|
import { BigNumberish } from '../utils/number';
|
|
5
5
|
import { ProviderInterface } from './interface';
|
|
@@ -15,16 +15,21 @@ export declare class RpcProvider implements ProviderInterface {
|
|
|
15
15
|
protected fetchEndpoint<T extends keyof RPC.Methods>(method: T, request?: RPC.Methods[T]['REQUEST']): Promise<RPC.Methods[T]['RESPONSE']>;
|
|
16
16
|
getChainId(): Promise<StarknetChainId>;
|
|
17
17
|
getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
|
|
18
|
-
|
|
18
|
+
getBlockWithTxHashes(blockIdentifier?: BlockIdentifier): Promise<RPC.GetBlockWithTxHashesResponse>;
|
|
19
|
+
getBlockWithTxs(blockIdentifier?: BlockIdentifier): Promise<RPC.GetBlockWithTxs>;
|
|
20
|
+
getNonce(contractAddress: string): Promise<any>;
|
|
21
|
+
getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
19
22
|
getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
|
|
23
|
+
getTransactionByHash(txHash: BigNumberish): Promise<RPC.GetTransactionByHashResponse>;
|
|
24
|
+
getTransactionByBlockIdAndIndex(blockIdentifier: BlockIdentifier, index: number): Promise<RPC.GetTransactionByBlockIdAndIndex>;
|
|
20
25
|
getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse>;
|
|
21
|
-
getClassAt(contractAddress: string,
|
|
26
|
+
getClassAt(contractAddress: string, blockIdentifier: BlockIdentifier): Promise<any>;
|
|
22
27
|
getEstimateFee(invocation: Invocation, blockIdentifier?: BlockIdentifier, invocationDetails?: InvocationsDetails): Promise<EstimateFeeResponse>;
|
|
23
28
|
declareContract({ contract, version, }: DeclareContractPayload): Promise<DeclareContractResponse>;
|
|
24
29
|
deployContract({ contract, constructorCalldata, addressSalt, }: DeployContractPayload): Promise<DeployContractResponse>;
|
|
25
30
|
invokeFunction(functionInvocation: Invocation, details: InvocationsDetails): Promise<InvokeFunctionResponse>;
|
|
26
31
|
callContract(call: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
|
|
27
|
-
getCode(
|
|
32
|
+
getCode(_contractAddress: string, _blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
|
|
28
33
|
waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
29
34
|
/**
|
|
30
35
|
* Gets the transaction count from a block.
|
package/dist/provider/rpc.js
CHANGED
|
@@ -47,6 +47,7 @@ var number_1 = require("../utils/number");
|
|
|
47
47
|
var provider_1 = require("../utils/provider");
|
|
48
48
|
var rpc_1 = require("../utils/responseParser/rpc");
|
|
49
49
|
var stark_1 = require("../utils/stark");
|
|
50
|
+
var utils_1 = require("./utils");
|
|
50
51
|
var RpcProvider = /** @class */ (function () {
|
|
51
52
|
function RpcProvider(optionsOrProvider) {
|
|
52
53
|
var _this = this;
|
|
@@ -112,36 +113,78 @@ var RpcProvider = /** @class */ (function () {
|
|
|
112
113
|
});
|
|
113
114
|
});
|
|
114
115
|
};
|
|
116
|
+
// Common Interface
|
|
115
117
|
RpcProvider.prototype.getBlock = function (blockIdentifier) {
|
|
116
118
|
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
117
119
|
return __awaiter(this, void 0, void 0, function () {
|
|
118
|
-
var method;
|
|
119
120
|
return __generator(this, function (_a) {
|
|
120
|
-
|
|
121
|
-
? 'starknet_getBlockByHash'
|
|
122
|
-
: 'starknet_getBlockByNumber';
|
|
123
|
-
return [2 /*return*/, this.fetchEndpoint(method, [blockIdentifier]).then(this.responseParser.parseGetBlockResponse)];
|
|
121
|
+
return [2 /*return*/, this.getBlockWithTxHashes(blockIdentifier).then(this.responseParser.parseGetBlockResponse)];
|
|
124
122
|
});
|
|
125
123
|
});
|
|
126
124
|
};
|
|
127
|
-
RpcProvider.prototype.
|
|
128
|
-
if (
|
|
125
|
+
RpcProvider.prototype.getBlockWithTxHashes = function (blockIdentifier) {
|
|
126
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
127
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
128
|
+
var blockIdentifierGetter;
|
|
129
|
+
return __generator(this, function (_a) {
|
|
130
|
+
blockIdentifierGetter = new utils_1.BlockIdentifierClass(blockIdentifier);
|
|
131
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getBlockWithTxHashes', [
|
|
132
|
+
blockIdentifierGetter.getIdentifier(),
|
|
133
|
+
])];
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
RpcProvider.prototype.getBlockWithTxs = function (blockIdentifier) {
|
|
138
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
139
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
140
|
+
var blockIdentifierGetter;
|
|
141
|
+
return __generator(this, function (_a) {
|
|
142
|
+
blockIdentifierGetter = new utils_1.BlockIdentifierClass(blockIdentifier);
|
|
143
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getBlockWithTxs', [blockIdentifierGetter.getIdentifier()])];
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
RpcProvider.prototype.getNonce = function (contractAddress) {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
149
|
+
return __generator(this, function (_a) {
|
|
150
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getNonce', [contractAddress])];
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
RpcProvider.prototype.getStorageAt = function (contractAddress, key, blockIdentifier) {
|
|
155
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
129
156
|
return __awaiter(this, void 0, void 0, function () {
|
|
130
|
-
var parsedKey;
|
|
157
|
+
var parsedKey, blockIdentifierGetter;
|
|
131
158
|
return __generator(this, function (_a) {
|
|
132
159
|
parsedKey = (0, number_1.toHex)((0, number_1.toBN)(key));
|
|
160
|
+
blockIdentifierGetter = new utils_1.BlockIdentifierClass(blockIdentifier);
|
|
133
161
|
return [2 /*return*/, this.fetchEndpoint('starknet_getStorageAt', [
|
|
134
162
|
contractAddress,
|
|
135
163
|
parsedKey,
|
|
136
|
-
|
|
164
|
+
blockIdentifierGetter.getIdentifier(),
|
|
137
165
|
])];
|
|
138
166
|
});
|
|
139
167
|
});
|
|
140
168
|
};
|
|
169
|
+
// common interface
|
|
141
170
|
RpcProvider.prototype.getTransaction = function (txHash) {
|
|
142
171
|
return __awaiter(this, void 0, void 0, function () {
|
|
143
172
|
return __generator(this, function (_a) {
|
|
144
|
-
return [2 /*return*/, this.
|
|
173
|
+
return [2 /*return*/, this.getTransactionByHash(txHash).then(this.responseParser.parseGetTransactionResponse)];
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
RpcProvider.prototype.getTransactionByHash = function (txHash) {
|
|
178
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
179
|
+
return __generator(this, function (_a) {
|
|
180
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getTransactionByHash', [txHash])];
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
|
+
RpcProvider.prototype.getTransactionByBlockIdAndIndex = function (blockIdentifier, index) {
|
|
185
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
186
|
+
return __generator(this, function (_a) {
|
|
187
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getTransactionByHash', [blockIdentifier, index])];
|
|
145
188
|
});
|
|
146
189
|
});
|
|
147
190
|
};
|
|
@@ -152,11 +195,15 @@ var RpcProvider = /** @class */ (function () {
|
|
|
152
195
|
});
|
|
153
196
|
});
|
|
154
197
|
};
|
|
155
|
-
RpcProvider.prototype.getClassAt = function (contractAddress,
|
|
156
|
-
if (_blockIdentifier === void 0) { _blockIdentifier = 'pending'; }
|
|
198
|
+
RpcProvider.prototype.getClassAt = function (contractAddress, blockIdentifier) {
|
|
157
199
|
return __awaiter(this, void 0, void 0, function () {
|
|
200
|
+
var blockIdentifierGetter;
|
|
158
201
|
return __generator(this, function (_a) {
|
|
159
|
-
|
|
202
|
+
blockIdentifierGetter = new utils_1.BlockIdentifierClass(blockIdentifier);
|
|
203
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getClassAt', [
|
|
204
|
+
blockIdentifierGetter.getIdentifier(),
|
|
205
|
+
contractAddress,
|
|
206
|
+
])];
|
|
160
207
|
});
|
|
161
208
|
});
|
|
162
209
|
};
|
|
@@ -170,7 +217,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
170
217
|
contract_address: invocation.contractAddress,
|
|
171
218
|
entry_point_selector: (0, hash_1.getSelectorFromName)(invocation.entrypoint),
|
|
172
219
|
calldata: (0, provider_1.parseCalldata)(invocation.calldata),
|
|
173
|
-
signature: (0, number_1.
|
|
220
|
+
signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(invocation.signature || []),
|
|
174
221
|
version: (0, number_1.toHex)((0, number_1.toBN)((invocationDetails === null || invocationDetails === void 0 ? void 0 : invocationDetails.version) || 0)),
|
|
175
222
|
},
|
|
176
223
|
blockIdentifier,
|
|
@@ -202,7 +249,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
202
249
|
contractDefinition = (0, provider_1.parseContract)(contract);
|
|
203
250
|
return [2 /*return*/, this.fetchEndpoint('starknet_addDeployTransaction', [
|
|
204
251
|
addressSalt !== null && addressSalt !== void 0 ? addressSalt : (0, stark_1.randomAddress)(),
|
|
205
|
-
(0, number_1.
|
|
252
|
+
(0, number_1.bigNumberishArrayToHexadecimalStringArray)(constructorCalldata !== null && constructorCalldata !== void 0 ? constructorCalldata : []),
|
|
206
253
|
{
|
|
207
254
|
program: contractDefinition.program,
|
|
208
255
|
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
@@ -220,7 +267,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
220
267
|
entry_point_selector: (0, hash_1.getSelectorFromName)(functionInvocation.entrypoint),
|
|
221
268
|
calldata: (0, provider_1.parseCalldata)(functionInvocation.calldata),
|
|
222
269
|
},
|
|
223
|
-
(0, number_1.
|
|
270
|
+
(0, number_1.bigNumberishArrayToHexadecimalStringArray)(functionInvocation.signature || []),
|
|
224
271
|
(0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
|
|
225
272
|
(0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
|
|
226
273
|
]).then(this.responseParser.parseInvokeFunctionResponse)];
|
|
@@ -248,16 +295,10 @@ var RpcProvider = /** @class */ (function () {
|
|
|
248
295
|
});
|
|
249
296
|
});
|
|
250
297
|
};
|
|
251
|
-
RpcProvider.prototype.getCode = function (
|
|
298
|
+
RpcProvider.prototype.getCode = function (_contractAddress, _blockIdentifier) {
|
|
252
299
|
return __awaiter(this, void 0, void 0, function () {
|
|
253
|
-
var result;
|
|
254
300
|
return __generator(this, function (_a) {
|
|
255
|
-
|
|
256
|
-
case 0: return [4 /*yield*/, this.fetchEndpoint('starknet_getCode', [contractAddress])];
|
|
257
|
-
case 1:
|
|
258
|
-
result = _a.sent();
|
|
259
|
-
return [2 /*return*/, this.responseParser.parseGetCodeResponse(result)];
|
|
260
|
-
}
|
|
301
|
+
throw new Error('RPC 0.1.0 does not implement getCode function');
|
|
261
302
|
});
|
|
262
303
|
});
|
|
263
304
|
};
|
|
@@ -325,11 +366,12 @@ var RpcProvider = /** @class */ (function () {
|
|
|
325
366
|
*/
|
|
326
367
|
RpcProvider.prototype.getTransactionCount = function (blockIdentifier) {
|
|
327
368
|
return __awaiter(this, void 0, void 0, function () {
|
|
369
|
+
var blockIdentifierGetter;
|
|
328
370
|
return __generator(this, function (_a) {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
371
|
+
blockIdentifierGetter = new utils_1.BlockIdentifierClass(blockIdentifier);
|
|
372
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getBlockTransactionCount', [
|
|
373
|
+
blockIdentifierGetter.getIdentifier(),
|
|
374
|
+
])];
|
|
333
375
|
});
|
|
334
376
|
});
|
|
335
377
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
|
-
import {
|
|
2
|
+
import { Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
|
|
3
3
|
import { GetContractAddressesResponse, GetTransactionStatusResponse, GetTransactionTraceResponse, Sequencer } from '../types/api';
|
|
4
4
|
import { BigNumberish } from '../utils/number';
|
|
5
5
|
import { ProviderInterface } from './interface';
|
|
@@ -29,7 +29,7 @@ export declare class SequencerProvider implements ProviderInterface {
|
|
|
29
29
|
protected fetchEndpoint<T extends keyof Sequencer.Endpoints>(endpoint: T, ...[query, request]: Sequencer.Endpoints[T]['QUERY'] extends never ? Sequencer.Endpoints[T]['REQUEST'] extends never ? [] : [undefined, Sequencer.Endpoints[T]['REQUEST']] : Sequencer.Endpoints[T]['REQUEST'] extends never ? [Sequencer.Endpoints[T]['QUERY']] : [Sequencer.Endpoints[T]['QUERY'], Sequencer.Endpoints[T]['REQUEST']]): Promise<Sequencer.Endpoints[T]['RESPONSE']>;
|
|
30
30
|
callContract({ contractAddress, entrypoint: entryPointSelector, calldata }: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
|
|
31
31
|
getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
|
|
32
|
-
getStorageAt(contractAddress: string, key: BigNumberish,
|
|
32
|
+
getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
33
33
|
getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
|
|
34
34
|
getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse>;
|
|
35
35
|
getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
|
|
@@ -249,14 +249,14 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
249
249
|
});
|
|
250
250
|
});
|
|
251
251
|
};
|
|
252
|
-
SequencerProvider.prototype.getStorageAt = function (contractAddress, key,
|
|
253
|
-
if (
|
|
252
|
+
SequencerProvider.prototype.getStorageAt = function (contractAddress, key, blockIdentifier) {
|
|
253
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
254
254
|
return __awaiter(this, void 0, void 0, function () {
|
|
255
255
|
var parsedKey;
|
|
256
256
|
return __generator(this, function (_a) {
|
|
257
257
|
parsedKey = (0, number_1.toBN)(key).toString(10);
|
|
258
258
|
return [2 /*return*/, this.fetchEndpoint('get_storage_at', {
|
|
259
|
-
blockIdentifier:
|
|
259
|
+
blockIdentifier: blockIdentifier,
|
|
260
260
|
contractAddress: contractAddress,
|
|
261
261
|
key: parsedKey,
|
|
262
262
|
})];
|
|
@@ -359,7 +359,7 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
359
359
|
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
360
360
|
return __awaiter(this, void 0, void 0, function () {
|
|
361
361
|
return __generator(this, function (_a) {
|
|
362
|
-
return [2 /*return*/, this.fetchEndpoint('get_code', { contractAddress: contractAddress, blockIdentifier: blockIdentifier })
|
|
362
|
+
return [2 /*return*/, this.fetchEndpoint('get_code', { contractAddress: contractAddress, blockIdentifier: blockIdentifier })];
|
|
363
363
|
});
|
|
364
364
|
});
|
|
365
365
|
};
|
package/dist/provider/utils.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
1
2
|
import type { BlockNumber } from '../types';
|
|
2
3
|
import { BigNumberish } from '../utils/number';
|
|
3
4
|
/**
|
|
@@ -23,6 +24,17 @@ declare type BlockIdentifierObject = {
|
|
|
23
24
|
type: 'BLOCK_HASH';
|
|
24
25
|
data: BigNumberish;
|
|
25
26
|
};
|
|
27
|
+
export declare class BlockIdentifierClass {
|
|
28
|
+
blockIdentifier: BlockIdentifier;
|
|
29
|
+
constructor(blockIdentifier: BlockIdentifier);
|
|
30
|
+
getIdentifier(): string | import("bn.js") | {
|
|
31
|
+
block_hash: string;
|
|
32
|
+
block_number?: undefined;
|
|
33
|
+
} | {
|
|
34
|
+
block_number: number;
|
|
35
|
+
block_hash?: undefined;
|
|
36
|
+
} | null;
|
|
37
|
+
}
|
|
26
38
|
/**
|
|
27
39
|
* Identifies the block to be queried.
|
|
28
40
|
*
|
package/dist/provider/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getFormattedBlockIdentifier = exports.getBlockIdentifier = exports.txIdentifier = exports.formatHash = void 0;
|
|
3
|
+
exports.getFormattedBlockIdentifier = exports.getBlockIdentifier = exports.BlockIdentifierClass = exports.txIdentifier = exports.formatHash = void 0;
|
|
4
4
|
var number_1 = require("../utils/number");
|
|
5
5
|
/**
|
|
6
6
|
*
|
|
@@ -29,6 +29,22 @@ function txIdentifier(txHash, txId) {
|
|
|
29
29
|
return "transactionHash=".concat(hashString);
|
|
30
30
|
}
|
|
31
31
|
exports.txIdentifier = txIdentifier;
|
|
32
|
+
var BlockIdentifierClass = /** @class */ (function () {
|
|
33
|
+
function BlockIdentifierClass(blockIdentifier) {
|
|
34
|
+
this.blockIdentifier = blockIdentifier;
|
|
35
|
+
}
|
|
36
|
+
BlockIdentifierClass.prototype.getIdentifier = function () {
|
|
37
|
+
if (typeof this.blockIdentifier === 'string' && (0, number_1.isHex)(this.blockIdentifier)) {
|
|
38
|
+
return { block_hash: this.blockIdentifier };
|
|
39
|
+
}
|
|
40
|
+
if (typeof this.blockIdentifier === 'number') {
|
|
41
|
+
return { block_number: this.blockIdentifier };
|
|
42
|
+
}
|
|
43
|
+
return this.blockIdentifier;
|
|
44
|
+
};
|
|
45
|
+
return BlockIdentifierClass;
|
|
46
|
+
}());
|
|
47
|
+
exports.BlockIdentifierClass = BlockIdentifierClass;
|
|
32
48
|
/**
|
|
33
49
|
* Identifies the block to be queried.
|
|
34
50
|
*
|
package/dist/signer/default.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { TypedData } from '../utils/typedData';
|
|
|
3
3
|
import { SignerInterface } from './interface';
|
|
4
4
|
export declare class Signer implements SignerInterface {
|
|
5
5
|
protected keyPair: KeyPair;
|
|
6
|
-
constructor(keyPair
|
|
6
|
+
constructor(keyPair?: KeyPair);
|
|
7
7
|
getPubKey(): Promise<string>;
|
|
8
8
|
signTransaction(transactions: Invocation[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): Promise<Signature>;
|
|
9
9
|
signMessage(typedData: TypedData, accountAddress: string): Promise<Signature>;
|
package/dist/signer/default.js
CHANGED
|
@@ -43,6 +43,7 @@ var transaction_1 = require("../utils/transaction");
|
|
|
43
43
|
var typedData_1 = require("../utils/typedData");
|
|
44
44
|
var Signer = /** @class */ (function () {
|
|
45
45
|
function Signer(keyPair) {
|
|
46
|
+
if (keyPair === void 0) { keyPair = (0, ellipticCurve_1.genKeyPair)(); }
|
|
46
47
|
this.keyPair = keyPair;
|
|
47
48
|
}
|
|
48
49
|
Signer.prototype.getPubKey = function () {
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Starknet RPC version 0.1.0
|
|
3
|
+
* starknet_api_openrpc version 0.31.0
|
|
4
|
+
*
|
|
5
|
+
* TypeScript Representation of OpenRpc protocol types | results
|
|
6
|
+
* errors are not implemented here only results
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* "type": "string",
|
|
10
|
+
* "title": "Field element",
|
|
11
|
+
* "$comment": "A field element, represented as a string of hex digits",
|
|
12
|
+
* "description": "A field element. Represented as up to 63 hex digits and leading 4 bits zeroed.",
|
|
13
|
+
* "pattern": "^0x0[a-fA-F0-9]{1,63}$"
|
|
14
|
+
*/
|
|
15
|
+
declare type FELT = string;
|
|
16
|
+
declare type BLOCK_NUMBER = number;
|
|
17
|
+
declare type BLOCK_HASH = FELT;
|
|
18
|
+
declare type TXN_HASH = FELT;
|
|
19
|
+
declare type TXN_STATUS = 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
|
|
20
|
+
declare type TXN_TYPE = 'DECLARE' | 'DEPLOY' | 'INVOKE' | 'L1_HANDLER';
|
|
21
|
+
declare type MSG_TO_L1 = {
|
|
22
|
+
to_address: FELT;
|
|
23
|
+
payload: Array<FELT>;
|
|
24
|
+
};
|
|
25
|
+
declare type EVENT = {
|
|
26
|
+
from_address: FELT;
|
|
27
|
+
keys: Array<FELT>;
|
|
28
|
+
data: Array<FELT>;
|
|
29
|
+
};
|
|
30
|
+
declare type COMMON_RECEIPT_PROPERTIES = {
|
|
31
|
+
transaction_hash: TXN_HASH;
|
|
32
|
+
actual_fee: FELT;
|
|
33
|
+
status: TXN_STATUS;
|
|
34
|
+
block_hash: BLOCK_HASH;
|
|
35
|
+
block_number: BLOCK_NUMBER;
|
|
36
|
+
type?: TXN_TYPE;
|
|
37
|
+
};
|
|
38
|
+
declare type INVOKE_TXN_RECEIPT_PROPERTIES = {
|
|
39
|
+
messages_sent: MSG_TO_L1;
|
|
40
|
+
events: EVENT;
|
|
41
|
+
};
|
|
42
|
+
declare type PENDING_COMMON_RECEIPT_PROPERTIES = {
|
|
43
|
+
transaction_hash: TXN_HASH;
|
|
44
|
+
actual_fee: FELT;
|
|
45
|
+
type?: TXN_TYPE;
|
|
46
|
+
};
|
|
47
|
+
declare type INVOKE_TXN_RECEIPT = COMMON_RECEIPT_PROPERTIES & INVOKE_TXN_RECEIPT_PROPERTIES;
|
|
48
|
+
declare type L1_HANDLER_TXN_RECEIPT = COMMON_RECEIPT_PROPERTIES;
|
|
49
|
+
declare type DECLARE_TXN_RECEIPT = COMMON_RECEIPT_PROPERTIES;
|
|
50
|
+
declare type DEPLOY_TXN_RECEIPT = COMMON_RECEIPT_PROPERTIES;
|
|
51
|
+
declare type PENDING_INVOKE_TXN_RECEIPT = PENDING_COMMON_RECEIPT_PROPERTIES & INVOKE_TXN_RECEIPT_PROPERTIES;
|
|
52
|
+
declare type PENDING_TXN_RECEIPT = PENDING_INVOKE_TXN_RECEIPT | PENDING_COMMON_RECEIPT_PROPERTIES;
|
|
53
|
+
declare type TXN_RECEIPT = INVOKE_TXN_RECEIPT | L1_HANDLER_TXN_RECEIPT | DECLARE_TXN_RECEIPT | DEPLOY_TXN_RECEIPT | PENDING_TXN_RECEIPT;
|
|
54
|
+
export declare namespace RPC_1 {
|
|
55
|
+
type GetTransactionReceiptResponse = TXN_RECEIPT;
|
|
56
|
+
type Methods = {
|
|
57
|
+
starknet_getTransactionReceipt: {
|
|
58
|
+
QUERY: never;
|
|
59
|
+
REQUEST: any[];
|
|
60
|
+
RESPONSE: GetTransactionReceiptResponse;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
declare type BLOCK_HEADER = {
|
|
65
|
+
block_hash: BLOCK_HASH;
|
|
66
|
+
parent_hash: BLOCK_HASH;
|
|
67
|
+
block_number: BLOCK_NUMBER;
|
|
68
|
+
new_root: FELT;
|
|
69
|
+
timestamp: number;
|
|
70
|
+
sequencer_address: FELT;
|
|
71
|
+
};
|
|
72
|
+
declare type BLOCK_BODY_WITH_TX_HASHES = {
|
|
73
|
+
transactions: Array<TXN_HASH>;
|
|
74
|
+
};
|
|
75
|
+
declare type BLOCK_WITH_TX_HASHES = {
|
|
76
|
+
status: TXN_STATUS;
|
|
77
|
+
} & BLOCK_HEADER & BLOCK_BODY_WITH_TX_HASHES;
|
|
78
|
+
declare type PENDING_BLOCK_WITH_TX_HASHES = BLOCK_BODY_WITH_TX_HASHES & {
|
|
79
|
+
timestamp: number;
|
|
80
|
+
sequencer_address: FELT;
|
|
81
|
+
parent_hash: BLOCK_HASH;
|
|
82
|
+
};
|
|
83
|
+
declare type BLOCK_STATUS = 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
|
|
84
|
+
/**
|
|
85
|
+
* "title": "An integer number in hex format (0x...)",
|
|
86
|
+
* "pattern": "^0x[a-fA-F0-9]+$"
|
|
87
|
+
*/
|
|
88
|
+
declare type NUM_AS_HEX = string;
|
|
89
|
+
declare type SIGNATURE = Array<FELT>;
|
|
90
|
+
declare type COMMON_TXN_PROPERTIES = {
|
|
91
|
+
transaction_hash: TXN_HASH;
|
|
92
|
+
max_fee: FELT;
|
|
93
|
+
version: NUM_AS_HEX;
|
|
94
|
+
signature: SIGNATURE;
|
|
95
|
+
nonce: FELT;
|
|
96
|
+
type: TXN_TYPE;
|
|
97
|
+
};
|
|
98
|
+
declare type ADDRESS = FELT;
|
|
99
|
+
declare type FUNCTION_CALL = {
|
|
100
|
+
contract_address: ADDRESS;
|
|
101
|
+
entry_point_selector: FELT;
|
|
102
|
+
calldata: Array<FELT>;
|
|
103
|
+
};
|
|
104
|
+
declare type INVOKE_TXN = COMMON_TXN_PROPERTIES & FUNCTION_CALL;
|
|
105
|
+
declare type DECLARE_TXN = COMMON_TXN_PROPERTIES & {
|
|
106
|
+
class_hash: FELT;
|
|
107
|
+
sender_address: ADDRESS;
|
|
108
|
+
};
|
|
109
|
+
declare type DEPLOY_TXN = {
|
|
110
|
+
transaction_hash: TXN_HASH;
|
|
111
|
+
class_hash: FELT;
|
|
112
|
+
version: NUM_AS_HEX;
|
|
113
|
+
type: TXN_TYPE;
|
|
114
|
+
contract_address: FELT;
|
|
115
|
+
contract_address_salt: FELT;
|
|
116
|
+
constructor_calldata: Array<FELT>;
|
|
117
|
+
};
|
|
118
|
+
declare type TXN = INVOKE_TXN | DECLARE_TXN | DEPLOY_TXN;
|
|
119
|
+
declare type BLOCK_BODY_WITH_TXS = {
|
|
120
|
+
transactions: Array<TXN>;
|
|
121
|
+
};
|
|
122
|
+
declare type BLOCK_WITH_TXS = {
|
|
123
|
+
status: BLOCK_STATUS;
|
|
124
|
+
} & BLOCK_HEADER & BLOCK_BODY_WITH_TXS;
|
|
125
|
+
declare type PENDING_BLOCK_WITH_TXS = BLOCK_BODY_WITH_TXS & {
|
|
126
|
+
timestamp: number;
|
|
127
|
+
sequencer_address: FELT;
|
|
128
|
+
parent_hash: BLOCK_HASH;
|
|
129
|
+
};
|
|
130
|
+
declare type CONTRACT_CLASS = {
|
|
131
|
+
program: string;
|
|
132
|
+
entry_points_by_type: {
|
|
133
|
+
CONSTRUCTOR: CONTRACT_ENTRY_POINT_LIST;
|
|
134
|
+
EXTERNAL: CONTRACT_ENTRY_POINT_LIST;
|
|
135
|
+
L1_HANDLER: CONTRACT_ENTRY_POINT_LIST;
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
declare type CONTRACT_ENTRY_POINT_LIST = Array<CONTRACT_ENTRY_POINT>;
|
|
139
|
+
declare type CONTRACT_ENTRY_POINT = {
|
|
140
|
+
offset: NUM_AS_HEX;
|
|
141
|
+
selector: FELT;
|
|
142
|
+
};
|
|
143
|
+
export declare namespace OPENRPC {
|
|
144
|
+
type GetBlockWithTxHashesResponse = BLOCK_WITH_TX_HASHES | PENDING_BLOCK_WITH_TX_HASHES;
|
|
145
|
+
type GetBlockWithTxs = BLOCK_WITH_TXS | PENDING_BLOCK_WITH_TXS;
|
|
146
|
+
type GetStorageAtResponse = FELT;
|
|
147
|
+
type GetTransactionByHashResponse = TXN;
|
|
148
|
+
type GetTransactionByBlockIdAndIndex = TXN;
|
|
149
|
+
type GetClassResponse = CONTRACT_CLASS;
|
|
150
|
+
}
|
|
151
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Starknet RPC version 0.1.0
|
|
4
|
+
* starknet_api_openrpc version 0.31.0
|
|
5
|
+
*
|
|
6
|
+
* TypeScript Representation of OpenRpc protocol types | results
|
|
7
|
+
* errors are not implemented here only results
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|