starknet 4.0.1 → 4.3.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 +23 -0
- package/__tests__/defaultProvider.test.ts +5 -0
- package/__tests__/sequencerProvider.test.ts +31 -1
- package/__tests__/utils/address.test.ts +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/provider/default.d.ts +2 -1
- package/dist/provider/default.js +7 -0
- package/dist/provider/interface.d.ts +2 -1
- package/dist/provider/rpc.d.ts +1 -0
- package/dist/provider/rpc.js +13 -0
- package/dist/provider/sequencer.d.ts +1 -0
- package/dist/provider/sequencer.js +13 -5
- package/dist/types/api/sequencer.d.ts +4 -4
- package/dist/types/provider.d.ts +3 -0
- package/dist/utils/address.js +1 -1
- package/dist/utils/hash.d.ts +1 -0
- package/dist/utils/hash.js +8 -1
- package/dist/utils/responseParser/rpc.d.ts +1 -0
- package/dist/utils/responseParser/rpc.js +3 -0
- package/dist/utils/responseParser/sequencer.d.ts +1 -0
- package/dist/utils/responseParser/sequencer.js +3 -0
- package/dist/utils/url.d.ts +7 -0
- package/dist/utils/url.js +49 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +2 -4
- package/provider/default.d.ts +2 -1
- package/provider/default.js +7 -0
- package/provider/interface.d.ts +2 -1
- package/provider/rpc.d.ts +1 -0
- package/provider/rpc.js +13 -0
- package/provider/sequencer.d.ts +1 -0
- package/provider/sequencer.js +13 -5
- package/src/index.ts +1 -0
- package/src/provider/default.ts +8 -0
- package/src/provider/interface.ts +6 -0
- package/src/provider/rpc.ts +9 -0
- package/src/provider/sequencer.ts +17 -3
- package/src/types/api/sequencer.ts +5 -5
- package/src/types/provider.ts +5 -0
- package/src/utils/address.ts +2 -2
- package/src/utils/hash.ts +8 -1
- package/src/utils/responseParser/rpc.ts +4 -0
- package/src/utils/responseParser/sequencer.ts +4 -0
- package/src/utils/url.ts +53 -0
- package/types/api/sequencer.d.ts +4 -4
- package/types/provider.d.ts +3 -0
- package/utils/address.js +1 -1
- package/utils/hash.d.ts +1 -0
- package/utils/hash.js +8 -1
- package/utils/responseParser/rpc.d.ts +1 -0
- package/utils/responseParser/rpc.js +3 -0
- package/utils/responseParser/sequencer.d.ts +1 -0
- package/utils/responseParser/sequencer.js +3 -0
- package/utils/url.d.ts +7 -0
- package/utils/url.js +49 -0
- package/www/docs/API/provider.md +80 -23
- package/www/guides/account.md +24 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
# [4.3.0](https://github.com/0xs34n/starknet.js/compare/v4.2.0...v4.3.0) (2022-08-09)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
- intendations in provider.md ([4a310c6](https://github.com/0xs34n/starknet.js/commit/4a310c6c992c77f9f6729a70c1af14481cd891f7))
|
|
6
|
+
- **sequenceProvider:** feedergatewayUrl and gatewayUrl ([e236d23](https://github.com/0xs34n/starknet.js/commit/e236d2352e3fbb0f78965decac5893217347ceb7))
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- update docs ([28786ed](https://github.com/0xs34n/starknet.js/commit/28786ed550909f6a30b8cb145e93d072ed28a862))
|
|
11
|
+
|
|
12
|
+
# [4.2.0](https://github.com/0xs34n/starknet.js/compare/v4.1.0...v4.2.0) (2022-08-09)
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
- change checksum address hashing algorithm ([0f32adf](https://github.com/0xs34n/starknet.js/commit/0f32adf217b3d2e55046bbb21980648f0c8cf631))
|
|
17
|
+
|
|
18
|
+
# [4.1.0](https://github.com/0xs34n/starknet.js/compare/v4.0.1...v4.1.0) (2022-08-03)
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
- get-code ([de6e597](https://github.com/0xs34n/starknet.js/commit/de6e5971de5155925defcf9249a8160dc3fdc9b7))
|
|
23
|
+
|
|
1
24
|
## [4.0.1](https://github.com/0xs34n/starknet.js/compare/v4.0.0...v4.0.1) (2022-08-03)
|
|
2
25
|
|
|
3
26
|
### Bug Fixes
|
|
@@ -62,6 +62,11 @@ describe('defaultProvider', () => {
|
|
|
62
62
|
return expect(block).toHaveProperty('block_number');
|
|
63
63
|
});
|
|
64
64
|
|
|
65
|
+
test('getCode() -> { bytecode }', async () => {
|
|
66
|
+
const code = await testProvider.getCode(exampleContractAddress);
|
|
67
|
+
return expect(Array.isArray(code.bytecode)).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
|
|
65
70
|
describe('getStorageAt', () => {
|
|
66
71
|
test('with "key" type of number', () => {
|
|
67
72
|
return expect(testProvider.getStorageAt(exampleContractAddress, 0)).resolves.not.toThrow();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { SequencerProvider } from '../src';
|
|
1
|
+
import { Contract, Provider, SequencerProvider, stark } from '../src';
|
|
2
|
+
import { toBN } from '../src/utils/number';
|
|
2
3
|
import {
|
|
3
4
|
compiledErc20,
|
|
4
5
|
describeIfNotDevnet,
|
|
@@ -8,9 +9,17 @@ import {
|
|
|
8
9
|
|
|
9
10
|
describeIfSequencer('SequencerProvider', () => {
|
|
10
11
|
let provider: SequencerProvider;
|
|
12
|
+
let customSequencerProvider: Provider;
|
|
11
13
|
|
|
12
14
|
beforeAll(async () => {
|
|
13
15
|
provider = getTestProvider() as SequencerProvider;
|
|
16
|
+
customSequencerProvider = new Provider({
|
|
17
|
+
sequencer: {
|
|
18
|
+
baseUrl: 'https://alpha4.starknet.io',
|
|
19
|
+
feederGatewayUrl: 'feeder_gateway',
|
|
20
|
+
gatewayUrl: 'gateway',
|
|
21
|
+
}, // Similar to arguements used in docs
|
|
22
|
+
});
|
|
14
23
|
});
|
|
15
24
|
|
|
16
25
|
describe('Gateway specific methods', () => {
|
|
@@ -42,4 +51,25 @@ describeIfSequencer('SequencerProvider', () => {
|
|
|
42
51
|
});
|
|
43
52
|
});
|
|
44
53
|
});
|
|
54
|
+
|
|
55
|
+
describe('Test calls with Custom Sequencer Provider', () => {
|
|
56
|
+
let erc20: Contract;
|
|
57
|
+
const wallet = stark.randomAddress();
|
|
58
|
+
|
|
59
|
+
beforeAll(async () => {
|
|
60
|
+
const { contract_address, transaction_hash } = await customSequencerProvider.deployContract({
|
|
61
|
+
contract: compiledErc20,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
await customSequencerProvider.waitForTransaction(transaction_hash);
|
|
65
|
+
erc20 = new Contract(compiledErc20.abi, contract_address, customSequencerProvider);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('Check ERC20 balance using Custom Sequencer Provider', async () => {
|
|
69
|
+
const result = await erc20.balance_of(wallet);
|
|
70
|
+
const [res] = result;
|
|
71
|
+
expect(res).toStrictEqual(toBN(0));
|
|
72
|
+
expect(res).toStrictEqual(result.res);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
45
75
|
});
|
|
@@ -26,12 +26,12 @@ describe('address checksums', () => {
|
|
|
26
26
|
'0x2fd23d9182193775423497fc0c472e156c57c69e4089a1967fb288a2d84e914'
|
|
27
27
|
);
|
|
28
28
|
expect(checksumAddress).toEqual(
|
|
29
|
-
'
|
|
29
|
+
'0x02Fd23d9182193775423497fc0c472E156C57C69E4089A1967fb288A2d84e914'
|
|
30
30
|
);
|
|
31
31
|
});
|
|
32
32
|
test('should be able to verify checksum address', () => {
|
|
33
33
|
const isValid = validateChecksumAddress(
|
|
34
|
-
'
|
|
34
|
+
'0x02Fd23d9182193775423497fc0c472E156C57C69E4089A1967fb288A2d84e914'
|
|
35
35
|
);
|
|
36
36
|
expect(isValid).toEqual(true);
|
|
37
37
|
});
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -50,3 +50,4 @@ exports.uint256 = __importStar(require("./utils/uint256"));
|
|
|
50
50
|
exports.shortString = __importStar(require("./utils/shortString"));
|
|
51
51
|
exports.typedData = __importStar(require("./utils/typedData"));
|
|
52
52
|
__exportStar(require("./utils/address"), exports);
|
|
53
|
+
__exportStar(require("./utils/url"), exports);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
|
-
import { BlockTag, Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
|
|
2
|
+
import { BlockTag, 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';
|
|
@@ -23,5 +23,6 @@ export declare class Provider implements ProviderInterface {
|
|
|
23
23
|
invokeFunction(functionInvocation: Invocation, details: InvocationsDetails): Promise<InvokeFunctionResponse>;
|
|
24
24
|
deployContract(payload: DeployContractPayload): Promise<DeployContractResponse>;
|
|
25
25
|
declareContract(payload: DeclareContractPayload): Promise<DeclareContractResponse>;
|
|
26
|
+
getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
|
|
26
27
|
waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
27
28
|
}
|
package/dist/provider/default.js
CHANGED
|
@@ -137,6 +137,13 @@ var Provider = /** @class */ (function () {
|
|
|
137
137
|
});
|
|
138
138
|
});
|
|
139
139
|
};
|
|
140
|
+
Provider.prototype.getCode = function (contractAddress, blockIdentifier) {
|
|
141
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
142
|
+
return __generator(this, function (_a) {
|
|
143
|
+
return [2 /*return*/, this.provider.getCode(contractAddress, blockIdentifier)];
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
};
|
|
140
147
|
Provider.prototype.waitForTransaction = function (txHash, retryInterval) {
|
|
141
148
|
return __awaiter(this, void 0, void 0, function () {
|
|
142
149
|
return __generator(this, function (_a) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
|
-
import type { BlockTag, Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
|
|
2
|
+
import type { BlockTag, 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,7 @@ export declare abstract class ProviderInterface {
|
|
|
19
19
|
* @returns the block object
|
|
20
20
|
*/
|
|
21
21
|
abstract getBlock(blockIdentifier: BlockIdentifier): Promise<GetBlockResponse>;
|
|
22
|
+
abstract getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
|
|
22
23
|
/**
|
|
23
24
|
* Gets the contract class of the deployed contract.
|
|
24
25
|
*
|
package/dist/provider/rpc.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export declare class RpcProvider implements ProviderInterface {
|
|
|
24
24
|
deployContract({ contract, constructorCalldata, addressSalt, }: DeployContractPayload): Promise<DeployContractResponse>;
|
|
25
25
|
invokeFunction(functionInvocation: Invocation, details: InvocationsDetails): Promise<InvokeFunctionResponse>;
|
|
26
26
|
callContract(call: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
|
|
27
|
+
getCode(contractAddress: string, _blockIdentifier?: BlockIdentifier): Promise<RPC.GetCodeResponse>;
|
|
27
28
|
waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
28
29
|
/**
|
|
29
30
|
* Gets the transaction count from a block.
|
package/dist/provider/rpc.js
CHANGED
|
@@ -248,6 +248,19 @@ var RpcProvider = /** @class */ (function () {
|
|
|
248
248
|
});
|
|
249
249
|
});
|
|
250
250
|
};
|
|
251
|
+
RpcProvider.prototype.getCode = function (contractAddress, _blockIdentifier) {
|
|
252
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
253
|
+
var result;
|
|
254
|
+
return __generator(this, function (_a) {
|
|
255
|
+
switch (_a.label) {
|
|
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
|
+
}
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
};
|
|
251
264
|
RpcProvider.prototype.waitForTransaction = function (txHash, retryInterval) {
|
|
252
265
|
if (retryInterval === void 0) { retryInterval = 8000; }
|
|
253
266
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -37,6 +37,7 @@ export declare class SequencerProvider implements ProviderInterface {
|
|
|
37
37
|
deployContract({ contract, constructorCalldata, addressSalt, }: DeployContractPayload): Promise<DeployContractResponse>;
|
|
38
38
|
declareContract({ contract, }: DeclareContractPayload): Promise<DeclareContractResponse>;
|
|
39
39
|
getEstimateFee(invocation: Invocation, blockIdentifier?: BlockIdentifier, invocationDetails?: InvocationsDetails): Promise<EstimateFeeResponse>;
|
|
40
|
+
getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<Sequencer.GetCodeResponse>;
|
|
40
41
|
waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
41
42
|
/**
|
|
42
43
|
* Gets the status of a transaction.
|
|
@@ -65,6 +65,7 @@ var number_1 = require("../utils/number");
|
|
|
65
65
|
var provider_1 = require("../utils/provider");
|
|
66
66
|
var sequencer_1 = require("../utils/responseParser/sequencer");
|
|
67
67
|
var stark_1 = require("../utils/stark");
|
|
68
|
+
var url_1 = require("../utils/url");
|
|
68
69
|
var errors_1 = require("./errors");
|
|
69
70
|
var utils_1 = require("./utils");
|
|
70
71
|
function isEmptyQueryObject(obj) {
|
|
@@ -79,7 +80,7 @@ function isEmptyQueryObject(obj) {
|
|
|
79
80
|
var SequencerProvider = /** @class */ (function () {
|
|
80
81
|
function SequencerProvider(optionsOrProvider) {
|
|
81
82
|
if (optionsOrProvider === void 0) { optionsOrProvider = { network: 'goerli-alpha' }; }
|
|
82
|
-
var _a
|
|
83
|
+
var _a;
|
|
83
84
|
this.responseParser = new sequencer_1.SequencerAPIResponseParser();
|
|
84
85
|
if ('network' in optionsOrProvider) {
|
|
85
86
|
this.baseUrl = SequencerProvider.getNetworkFromName(optionsOrProvider.network);
|
|
@@ -89,11 +90,10 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
89
90
|
}
|
|
90
91
|
else {
|
|
91
92
|
this.baseUrl = optionsOrProvider.baseUrl;
|
|
92
|
-
this.feederGatewayUrl =
|
|
93
|
-
|
|
94
|
-
this.gatewayUrl = (_b = optionsOrProvider.gatewayUrl) !== null && _b !== void 0 ? _b : (0, url_join_1.default)(this.baseUrl, 'gateway');
|
|
93
|
+
this.feederGatewayUrl = (0, url_1.buildUrl)(this.baseUrl, 'feeder_gateway', optionsOrProvider.feederGatewayUrl);
|
|
94
|
+
this.gatewayUrl = (0, url_1.buildUrl)(this.baseUrl, 'gateway', optionsOrProvider.gatewayUrl);
|
|
95
95
|
this.chainId =
|
|
96
|
-
(
|
|
96
|
+
(_a = optionsOrProvider.chainId) !== null && _a !== void 0 ? _a : SequencerProvider.getChainIdFromBaseUrl(optionsOrProvider.baseUrl);
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
SequencerProvider.getNetworkFromName = function (name) {
|
|
@@ -355,6 +355,14 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
355
355
|
});
|
|
356
356
|
});
|
|
357
357
|
};
|
|
358
|
+
SequencerProvider.prototype.getCode = function (contractAddress, blockIdentifier) {
|
|
359
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
360
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
361
|
+
return __generator(this, function (_a) {
|
|
362
|
+
return [2 /*return*/, this.fetchEndpoint('get_code', { contractAddress: contractAddress, blockIdentifier: blockIdentifier }).then(this.responseParser.parseGetCodeResponse)];
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
};
|
|
358
366
|
SequencerProvider.prototype.waitForTransaction = function (txHash, retryInterval) {
|
|
359
367
|
if (retryInterval === void 0) { retryInterval = 8000; }
|
|
360
368
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -39,10 +39,6 @@ export declare type ExecutionResources = {
|
|
|
39
39
|
};
|
|
40
40
|
n_memory_holes: number;
|
|
41
41
|
};
|
|
42
|
-
export declare type GetCodeResponse = {
|
|
43
|
-
bytecode: string[];
|
|
44
|
-
abi: Abi;
|
|
45
|
-
};
|
|
46
42
|
export declare type GetTransactionTraceResponse = {
|
|
47
43
|
function_invocation: {
|
|
48
44
|
caller_address: string;
|
|
@@ -97,6 +93,10 @@ export declare namespace Sequencer {
|
|
|
97
93
|
address?: string;
|
|
98
94
|
class_hash?: string;
|
|
99
95
|
};
|
|
96
|
+
type GetCodeResponse = {
|
|
97
|
+
bytecode: string[];
|
|
98
|
+
abi: Abi;
|
|
99
|
+
};
|
|
100
100
|
interface InvokeFunctionTransactionResponse extends InvokeFunctionTransaction {
|
|
101
101
|
transaction_hash: string;
|
|
102
102
|
}
|
package/dist/types/provider.d.ts
CHANGED
|
@@ -13,6 +13,9 @@ export interface GetBlockResponse {
|
|
|
13
13
|
transactions: Array<string>;
|
|
14
14
|
starknet_version?: string;
|
|
15
15
|
}
|
|
16
|
+
export interface GetCodeResponse {
|
|
17
|
+
bytecode: string[];
|
|
18
|
+
}
|
|
16
19
|
export declare type GetTransactionResponse = InvokeTransactionResponse & DeclareTransactionResponse;
|
|
17
20
|
export interface CommonTransactionResponse {
|
|
18
21
|
transaction_hash?: string;
|
package/dist/utils/address.js
CHANGED
|
@@ -23,7 +23,7 @@ exports.validateAndParseAddress = validateAndParseAddress;
|
|
|
23
23
|
// from https://github.com/ethers-io/ethers.js/blob/fc1e006575d59792fa97b4efb9ea2f8cca1944cf/packages/address/src.ts/index.ts#L12
|
|
24
24
|
function getChecksumAddress(address) {
|
|
25
25
|
var chars = (0, encode_1.removeHexPrefix)(validateAndParseAddress(address)).toLowerCase().split('');
|
|
26
|
-
var hashed = (0, bytes_1.arrayify)((0, hash_1.
|
|
26
|
+
var hashed = (0, bytes_1.arrayify)((0, hash_1.keccakBn)(address), { hexPad: 'left' }); // in case the hash is 251 bits (63 chars) we need to pad it to 64 chars without changing the number value ("left")
|
|
27
27
|
for (var i = 0; i < chars.length; i += 2) {
|
|
28
28
|
if (hashed[i >> 1] >> 4 >= 8) {
|
|
29
29
|
chars[i] = chars[i].toUpperCase();
|
package/dist/utils/hash.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { RawCalldata } from '../types/lib';
|
|
|
4
4
|
import { BigNumberish } from './number';
|
|
5
5
|
export declare const transactionVersion = 0;
|
|
6
6
|
export declare const feeTransactionVersion: BN;
|
|
7
|
+
export declare function keccakBn(value: BigNumberish): string;
|
|
7
8
|
/**
|
|
8
9
|
* Function to get the starknet keccak hash from a string
|
|
9
10
|
*
|
package/dist/utils/hash.js
CHANGED
|
@@ -28,8 +28,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
29
29
|
};
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.calculateContractAddressFromHash = exports.calculcateTransactionHash = exports.calculateDeployTransactionHash = exports.calculateTransactionHashCommon = exports.computeHashOnElements = exports.pedersen = exports.getSelectorFromName = exports.starknetKeccak = exports.feeTransactionVersion = exports.transactionVersion = void 0;
|
|
31
|
+
exports.calculateContractAddressFromHash = exports.calculcateTransactionHash = exports.calculateDeployTransactionHash = exports.calculateTransactionHashCommon = exports.computeHashOnElements = exports.pedersen = exports.getSelectorFromName = exports.starknetKeccak = exports.keccakBn = exports.feeTransactionVersion = exports.transactionVersion = void 0;
|
|
32
32
|
var keccak_1 = require("ethereum-cryptography/keccak");
|
|
33
|
+
var utils_1 = require("ethereum-cryptography/utils");
|
|
33
34
|
var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
|
|
34
35
|
var constants_1 = require("../constants");
|
|
35
36
|
var ellipticCurve_1 = require("./ellipticCurve");
|
|
@@ -37,6 +38,12 @@ var encode_1 = require("./encode");
|
|
|
37
38
|
var number_1 = require("./number");
|
|
38
39
|
exports.transactionVersion = 0;
|
|
39
40
|
exports.feeTransactionVersion = (0, number_1.toBN)(2).pow((0, number_1.toBN)(128)).add((0, number_1.toBN)(exports.transactionVersion));
|
|
41
|
+
function keccakBn(value) {
|
|
42
|
+
var hexWithoutPrefix = (0, encode_1.removeHexPrefix)((0, number_1.toHex)((0, number_1.toBN)(value)));
|
|
43
|
+
var evenHex = hexWithoutPrefix.length % 2 === 0 ? hexWithoutPrefix : "0".concat(hexWithoutPrefix);
|
|
44
|
+
return (0, encode_1.addHexPrefix)((0, encode_1.buf2hex)((0, keccak_1.keccak256)((0, utils_1.hexToBytes)(evenHex))));
|
|
45
|
+
}
|
|
46
|
+
exports.keccakBn = keccakBn;
|
|
40
47
|
function keccakHex(value) {
|
|
41
48
|
return (0, encode_1.addHexPrefix)((0, encode_1.buf2hex)((0, keccak_1.keccak256)((0, encode_1.utf8ToArray)(value))));
|
|
42
49
|
}
|
|
@@ -5,6 +5,7 @@ export declare class RPCResponseParser extends ResponseParser {
|
|
|
5
5
|
parseGetBlockResponse(res: RPC.GetBlockResponse): GetBlockResponse;
|
|
6
6
|
parseGetTransactionResponse(res: RPC.GetTransactionResponse): GetTransactionResponse;
|
|
7
7
|
parseGetTransactionReceiptResponse(res: RPC.GetTransactionReceiptResponse): GetTransactionReceiptResponse;
|
|
8
|
+
parseGetCodeResponse(res: RPC.GetCodeResponse): RPC.GetCodeResponse;
|
|
8
9
|
parseFeeEstimateResponse(res: RPC.EstimateFeeResponse): EstimateFeeResponse;
|
|
9
10
|
parseCallContractResponse(res: Array<string>): CallContractResponse;
|
|
10
11
|
parseInvokeFunctionResponse(res: RPC.AddTransactionResponse): InvokeFunctionResponse;
|
|
@@ -62,6 +62,9 @@ var RPCResponseParser = /** @class */ (function (_super) {
|
|
|
62
62
|
events: res.events,
|
|
63
63
|
};
|
|
64
64
|
};
|
|
65
|
+
RPCResponseParser.prototype.parseGetCodeResponse = function (res) {
|
|
66
|
+
return res;
|
|
67
|
+
};
|
|
65
68
|
RPCResponseParser.prototype.parseFeeEstimateResponse = function (res) {
|
|
66
69
|
return {
|
|
67
70
|
overall_fee: (0, number_1.toBN)(res.overall_fee),
|
|
@@ -5,6 +5,7 @@ export declare class SequencerAPIResponseParser extends ResponseParser {
|
|
|
5
5
|
parseGetBlockResponse(res: Sequencer.GetBlockResponse): GetBlockResponse;
|
|
6
6
|
parseGetTransactionResponse(res: Sequencer.GetTransactionResponse): GetTransactionResponse;
|
|
7
7
|
parseGetTransactionReceiptResponse(res: Sequencer.TransactionReceiptResponse): GetTransactionReceiptResponse;
|
|
8
|
+
parseGetCodeResponse(res: Sequencer.GetCodeResponse): Sequencer.GetCodeResponse;
|
|
8
9
|
parseFeeEstimateResponse(res: Sequencer.EstimateFeeResponse): EstimateFeeResponse;
|
|
9
10
|
parseCallContractResponse(res: Sequencer.CallContractResponse): CallContractResponse;
|
|
10
11
|
parseInvokeFunctionResponse(res: Sequencer.AddTransactionResponse): InvokeFunctionResponse;
|
|
@@ -79,6 +79,9 @@ var SequencerAPIResponseParser = /** @class */ (function (_super) {
|
|
|
79
79
|
l1_origin_message: undefined,
|
|
80
80
|
};
|
|
81
81
|
};
|
|
82
|
+
SequencerAPIResponseParser.prototype.parseGetCodeResponse = function (res) {
|
|
83
|
+
return res;
|
|
84
|
+
};
|
|
82
85
|
SequencerAPIResponseParser.prototype.parseFeeEstimateResponse = function (res) {
|
|
83
86
|
if ('overall_fee' in res) {
|
|
84
87
|
var gasInfo = {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.buildUrl = exports.isUrl = void 0;
|
|
7
|
+
var url_join_1 = __importDefault(require("url-join"));
|
|
8
|
+
/**
|
|
9
|
+
* Inspired from https://github.com/segmentio/is-url
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* RegExps.
|
|
13
|
+
* A URL must match #1 and then at least one of #2/#3.
|
|
14
|
+
* Use two levels of REs to avoid REDOS.
|
|
15
|
+
*/
|
|
16
|
+
var protocolAndDomainRE = /^(?:\w+:)?\/\/(\S+)$/;
|
|
17
|
+
var localhostDomainRE = /^localhost[:?\d]*(?:[^:?\d]\S*)?$/;
|
|
18
|
+
var nonLocalhostDomainRE = /^[^\s.]+\.\S{2,}$/;
|
|
19
|
+
/**
|
|
20
|
+
* Loosely validate a URL `string`.
|
|
21
|
+
* @param {String} s
|
|
22
|
+
* @return {Boolean}
|
|
23
|
+
*/
|
|
24
|
+
function isUrl(s) {
|
|
25
|
+
if (!s) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
if (typeof s !== 'string') {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
var match = s.match(protocolAndDomainRE);
|
|
32
|
+
if (!match) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
var everythingAfterProtocol = match[1];
|
|
36
|
+
if (!everythingAfterProtocol) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
if (localhostDomainRE.test(everythingAfterProtocol) ||
|
|
40
|
+
nonLocalhostDomainRE.test(everythingAfterProtocol)) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
exports.isUrl = isUrl;
|
|
46
|
+
function buildUrl(baseUrl, defaultPath, urlOrPath) {
|
|
47
|
+
return isUrl(urlOrPath) ? urlOrPath : (0, url_join_1.default)(baseUrl, urlOrPath !== null && urlOrPath !== void 0 ? urlOrPath : defaultPath);
|
|
48
|
+
}
|
|
49
|
+
exports.buildUrl = buildUrl;
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -50,3 +50,4 @@ exports.uint256 = __importStar(require("./utils/uint256"));
|
|
|
50
50
|
exports.shortString = __importStar(require("./utils/shortString"));
|
|
51
51
|
exports.typedData = __importStar(require("./utils/typedData"));
|
|
52
52
|
__exportStar(require("./utils/address"), exports);
|
|
53
|
+
__exportStar(require("./utils/url"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starknet",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"description": "JavaScript library for StarkNet",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -43,7 +43,6 @@
|
|
|
43
43
|
"@types/minimalistic-assert": "^1.0.1",
|
|
44
44
|
"@types/pako": "^2.0.0",
|
|
45
45
|
"@types/url-join": "^4.0.1",
|
|
46
|
-
"@types/whatwg-fetch": "^0.0.33",
|
|
47
46
|
"@typescript-eslint/eslint-plugin": "^5.28.0",
|
|
48
47
|
"@typescript-eslint/parser": "^5.28.0",
|
|
49
48
|
"eslint": "^8.17.0",
|
|
@@ -61,8 +60,7 @@
|
|
|
61
60
|
"prettier": "^2.7.0",
|
|
62
61
|
"prettier-plugin-import-sort": "^0.0.7",
|
|
63
62
|
"typedoc": "^0.22.17",
|
|
64
|
-
"typescript": "^4.7.3"
|
|
65
|
-
"whatwg-fetch": "^3.6.2"
|
|
63
|
+
"typescript": "^4.7.3"
|
|
66
64
|
},
|
|
67
65
|
"dependencies": {
|
|
68
66
|
"@ethersproject/bytes": "^5.6.1",
|
package/provider/default.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
|
-
import { BlockTag, Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
|
|
2
|
+
import { BlockTag, 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';
|
|
@@ -23,5 +23,6 @@ export declare class Provider implements ProviderInterface {
|
|
|
23
23
|
invokeFunction(functionInvocation: Invocation, details: InvocationsDetails): Promise<InvokeFunctionResponse>;
|
|
24
24
|
deployContract(payload: DeployContractPayload): Promise<DeployContractResponse>;
|
|
25
25
|
declareContract(payload: DeclareContractPayload): Promise<DeclareContractResponse>;
|
|
26
|
+
getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
|
|
26
27
|
waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
27
28
|
}
|
package/provider/default.js
CHANGED
|
@@ -137,6 +137,13 @@ var Provider = /** @class */ (function () {
|
|
|
137
137
|
});
|
|
138
138
|
});
|
|
139
139
|
};
|
|
140
|
+
Provider.prototype.getCode = function (contractAddress, blockIdentifier) {
|
|
141
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
142
|
+
return __generator(this, function (_a) {
|
|
143
|
+
return [2 /*return*/, this.provider.getCode(contractAddress, blockIdentifier)];
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
};
|
|
140
147
|
Provider.prototype.waitForTransaction = function (txHash, retryInterval) {
|
|
141
148
|
return __awaiter(this, void 0, void 0, function () {
|
|
142
149
|
return __generator(this, function (_a) {
|
package/provider/interface.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
|
-
import type { BlockTag, Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
|
|
2
|
+
import type { BlockTag, 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,7 @@ export declare abstract class ProviderInterface {
|
|
|
19
19
|
* @returns the block object
|
|
20
20
|
*/
|
|
21
21
|
abstract getBlock(blockIdentifier: BlockIdentifier): Promise<GetBlockResponse>;
|
|
22
|
+
abstract getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
|
|
22
23
|
/**
|
|
23
24
|
* Gets the contract class of the deployed contract.
|
|
24
25
|
*
|
package/provider/rpc.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export declare class RpcProvider implements ProviderInterface {
|
|
|
24
24
|
deployContract({ contract, constructorCalldata, addressSalt, }: DeployContractPayload): Promise<DeployContractResponse>;
|
|
25
25
|
invokeFunction(functionInvocation: Invocation, details: InvocationsDetails): Promise<InvokeFunctionResponse>;
|
|
26
26
|
callContract(call: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
|
|
27
|
+
getCode(contractAddress: string, _blockIdentifier?: BlockIdentifier): Promise<RPC.GetCodeResponse>;
|
|
27
28
|
waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
28
29
|
/**
|
|
29
30
|
* Gets the transaction count from a block.
|
package/provider/rpc.js
CHANGED
|
@@ -248,6 +248,19 @@ var RpcProvider = /** @class */ (function () {
|
|
|
248
248
|
});
|
|
249
249
|
});
|
|
250
250
|
};
|
|
251
|
+
RpcProvider.prototype.getCode = function (contractAddress, _blockIdentifier) {
|
|
252
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
253
|
+
var result;
|
|
254
|
+
return __generator(this, function (_a) {
|
|
255
|
+
switch (_a.label) {
|
|
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
|
+
}
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
};
|
|
251
264
|
RpcProvider.prototype.waitForTransaction = function (txHash, retryInterval) {
|
|
252
265
|
if (retryInterval === void 0) { retryInterval = 8000; }
|
|
253
266
|
return __awaiter(this, void 0, void 0, function () {
|
package/provider/sequencer.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export declare class SequencerProvider implements ProviderInterface {
|
|
|
37
37
|
deployContract({ contract, constructorCalldata, addressSalt, }: DeployContractPayload): Promise<DeployContractResponse>;
|
|
38
38
|
declareContract({ contract, }: DeclareContractPayload): Promise<DeclareContractResponse>;
|
|
39
39
|
getEstimateFee(invocation: Invocation, blockIdentifier?: BlockIdentifier, invocationDetails?: InvocationsDetails): Promise<EstimateFeeResponse>;
|
|
40
|
+
getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<Sequencer.GetCodeResponse>;
|
|
40
41
|
waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
41
42
|
/**
|
|
42
43
|
* Gets the status of a transaction.
|
package/provider/sequencer.js
CHANGED
|
@@ -65,6 +65,7 @@ var number_1 = require("../utils/number");
|
|
|
65
65
|
var provider_1 = require("../utils/provider");
|
|
66
66
|
var sequencer_1 = require("../utils/responseParser/sequencer");
|
|
67
67
|
var stark_1 = require("../utils/stark");
|
|
68
|
+
var url_1 = require("../utils/url");
|
|
68
69
|
var errors_1 = require("./errors");
|
|
69
70
|
var utils_1 = require("./utils");
|
|
70
71
|
function isEmptyQueryObject(obj) {
|
|
@@ -79,7 +80,7 @@ function isEmptyQueryObject(obj) {
|
|
|
79
80
|
var SequencerProvider = /** @class */ (function () {
|
|
80
81
|
function SequencerProvider(optionsOrProvider) {
|
|
81
82
|
if (optionsOrProvider === void 0) { optionsOrProvider = { network: 'goerli-alpha' }; }
|
|
82
|
-
var _a
|
|
83
|
+
var _a;
|
|
83
84
|
this.responseParser = new sequencer_1.SequencerAPIResponseParser();
|
|
84
85
|
if ('network' in optionsOrProvider) {
|
|
85
86
|
this.baseUrl = SequencerProvider.getNetworkFromName(optionsOrProvider.network);
|
|
@@ -89,11 +90,10 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
89
90
|
}
|
|
90
91
|
else {
|
|
91
92
|
this.baseUrl = optionsOrProvider.baseUrl;
|
|
92
|
-
this.feederGatewayUrl =
|
|
93
|
-
|
|
94
|
-
this.gatewayUrl = (_b = optionsOrProvider.gatewayUrl) !== null && _b !== void 0 ? _b : (0, url_join_1.default)(this.baseUrl, 'gateway');
|
|
93
|
+
this.feederGatewayUrl = (0, url_1.buildUrl)(this.baseUrl, 'feeder_gateway', optionsOrProvider.feederGatewayUrl);
|
|
94
|
+
this.gatewayUrl = (0, url_1.buildUrl)(this.baseUrl, 'gateway', optionsOrProvider.gatewayUrl);
|
|
95
95
|
this.chainId =
|
|
96
|
-
(
|
|
96
|
+
(_a = optionsOrProvider.chainId) !== null && _a !== void 0 ? _a : SequencerProvider.getChainIdFromBaseUrl(optionsOrProvider.baseUrl);
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
SequencerProvider.getNetworkFromName = function (name) {
|
|
@@ -355,6 +355,14 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
355
355
|
});
|
|
356
356
|
});
|
|
357
357
|
};
|
|
358
|
+
SequencerProvider.prototype.getCode = function (contractAddress, blockIdentifier) {
|
|
359
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
360
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
361
|
+
return __generator(this, function (_a) {
|
|
362
|
+
return [2 /*return*/, this.fetchEndpoint('get_code', { contractAddress: contractAddress, blockIdentifier: blockIdentifier }).then(this.responseParser.parseGetCodeResponse)];
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
};
|
|
358
366
|
SequencerProvider.prototype.waitForTransaction = function (txHash, retryInterval) {
|
|
359
367
|
if (retryInterval === void 0) { retryInterval = 8000; }
|
|
360
368
|
return __awaiter(this, void 0, void 0, function () {
|
package/src/index.ts
CHANGED
package/src/provider/default.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
DeployContractResponse,
|
|
11
11
|
EstimateFeeResponse,
|
|
12
12
|
GetBlockResponse,
|
|
13
|
+
GetCodeResponse,
|
|
13
14
|
GetTransactionReceiptResponse,
|
|
14
15
|
GetTransactionResponse,
|
|
15
16
|
Invocation,
|
|
@@ -103,6 +104,13 @@ export class Provider implements ProviderInterface {
|
|
|
103
104
|
return this.provider.declareContract(payload);
|
|
104
105
|
}
|
|
105
106
|
|
|
107
|
+
public async getCode(
|
|
108
|
+
contractAddress: string,
|
|
109
|
+
blockIdentifier?: BlockIdentifier
|
|
110
|
+
): Promise<GetCodeResponse> {
|
|
111
|
+
return this.provider.getCode(contractAddress, blockIdentifier);
|
|
112
|
+
}
|
|
113
|
+
|
|
106
114
|
public async waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void> {
|
|
107
115
|
return this.provider.waitForTransaction(txHash, retryInterval);
|
|
108
116
|
}
|