starknet 4.0.0 → 4.2.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 +19 -0
- package/__tests__/defaultProvider.test.ts +5 -0
- package/__tests__/jest.setup.ts +2 -3
- package/__tests__/utils/address.test.ts +2 -2
- 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 +15 -2
- package/dist/provider/sequencer.d.ts +1 -0
- package/dist/provider/sequencer.js +10 -1
- 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/fetchPonyfill.d.ts +2 -0
- package/dist/utils/fetchPonyfill.js +6 -0
- 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/package.json +3 -6
- 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 +15 -2
- package/provider/sequencer.d.ts +1 -0
- package/provider/sequencer.js +10 -1
- package/src/provider/default.ts +8 -0
- package/src/provider/interface.ts +6 -0
- package/src/provider/rpc.ts +10 -2
- package/src/provider/sequencer.ts +10 -0
- 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/fetchPonyfill.ts +4 -0
- package/src/utils/hash.ts +8 -1
- package/src/utils/responseParser/rpc.ts +4 -0
- package/src/utils/responseParser/sequencer.ts +4 -0
- package/types/api/sequencer.d.ts +4 -4
- package/types/provider.d.ts +3 -0
- package/utils/address.js +1 -1
- package/utils/fetchPonyfill.d.ts +2 -0
- package/utils/fetchPonyfill.js +6 -0
- 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/www/docs/API/contract.md +1 -1
- package/www/docs/API/provider.md +1 -1
- package/www/guides/account.md +24 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
# [4.2.0](https://github.com/0xs34n/starknet.js/compare/v4.1.0...v4.2.0) (2022-08-09)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
- change checksum address hashing algorithm ([0f32adf](https://github.com/0xs34n/starknet.js/commit/0f32adf217b3d2e55046bbb21980648f0c8cf631))
|
|
6
|
+
|
|
7
|
+
# [4.1.0](https://github.com/0xs34n/starknet.js/compare/v4.0.1...v4.1.0) (2022-08-03)
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
- get-code ([de6e597](https://github.com/0xs34n/starknet.js/commit/de6e5971de5155925defcf9249a8160dc3fdc9b7))
|
|
12
|
+
|
|
13
|
+
## [4.0.1](https://github.com/0xs34n/starknet.js/compare/v4.0.0...v4.0.1) (2022-08-03)
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
- use custom fetch ponyfill ([16e9a53](https://github.com/0xs34n/starknet.js/commit/16e9a530d62942da75ed1bc30d0048a35f9f0152))
|
|
18
|
+
- use isomorphic-unfetch ([aa7af66](https://github.com/0xs34n/starknet.js/commit/aa7af6622d918ad0d17fe28bf1e73635895537c5))
|
|
19
|
+
|
|
1
20
|
# [4.0.0](https://github.com/0xs34n/starknet.js/compare/v3.19.0...v4.0.0) (2022-07-27)
|
|
2
21
|
|
|
3
22
|
### Documentation
|
|
@@ -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();
|
package/__tests__/jest.setup.ts
CHANGED
|
@@ -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
|
});
|
|
@@ -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
|
@@ -40,7 +40,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
42
|
exports.RpcProvider = void 0;
|
|
43
|
-
var
|
|
43
|
+
var fetchPonyfill_1 = __importDefault(require("../utils/fetchPonyfill"));
|
|
44
44
|
var hash_1 = require("../utils/hash");
|
|
45
45
|
var json_1 = require("../utils/json");
|
|
46
46
|
var number_1 = require("../utils/number");
|
|
@@ -73,7 +73,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
73
73
|
_c.label = 1;
|
|
74
74
|
case 1:
|
|
75
75
|
_c.trys.push([1, 4, , 5]);
|
|
76
|
-
return [4 /*yield*/, (0,
|
|
76
|
+
return [4 /*yield*/, (0, fetchPonyfill_1.default)(this.nodeUrl, {
|
|
77
77
|
method: 'POST',
|
|
78
78
|
body: (0, json_1.stringify)(requestData),
|
|
79
79
|
headers: {
|
|
@@ -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.
|
|
@@ -58,6 +58,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
58
58
|
exports.SequencerProvider = void 0;
|
|
59
59
|
var url_join_1 = __importDefault(require("url-join"));
|
|
60
60
|
var constants_1 = require("../constants");
|
|
61
|
+
var fetchPonyfill_1 = __importDefault(require("../utils/fetchPonyfill"));
|
|
61
62
|
var hash_1 = require("../utils/hash");
|
|
62
63
|
var json_1 = require("../utils/json");
|
|
63
64
|
var number_1 = require("../utils/number");
|
|
@@ -180,7 +181,7 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
180
181
|
_c.label = 1;
|
|
181
182
|
case 1:
|
|
182
183
|
_c.trys.push([1, 4, , 5]);
|
|
183
|
-
return [4 /*yield*/,
|
|
184
|
+
return [4 /*yield*/, (0, fetchPonyfill_1.default)(url, {
|
|
184
185
|
method: method,
|
|
185
186
|
body: (0, json_1.stringify)(request),
|
|
186
187
|
headers: headers,
|
|
@@ -354,6 +355,14 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
354
355
|
});
|
|
355
356
|
});
|
|
356
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
|
+
};
|
|
357
366
|
SequencerProvider.prototype.waitForTransaction = function (txHash, retryInterval) {
|
|
358
367
|
if (retryInterval === void 0) { retryInterval = 8000; }
|
|
359
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();
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = (typeof window !== 'undefined' && window.fetch) || // use buildin fetch in browser if available
|
|
4
|
+
(typeof global !== 'undefined' && global.fetch) || // use buildin fetch in node, react-native and service worker if available
|
|
5
|
+
// eslint-disable-next-line global-require
|
|
6
|
+
require('isomorphic-fetch'); // ponyfill fetch in node and browsers that don't have it
|
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 = {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starknet",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "JavaScript library for StarkNet",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -43,10 +43,8 @@
|
|
|
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
|
-
"cross-fetch": "^3.1.5",
|
|
50
48
|
"eslint": "^8.17.0",
|
|
51
49
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
52
50
|
"eslint-config-airbnb-typescript": "^17.0.0",
|
|
@@ -62,16 +60,15 @@
|
|
|
62
60
|
"prettier": "^2.7.0",
|
|
63
61
|
"prettier-plugin-import-sort": "^0.0.7",
|
|
64
62
|
"typedoc": "^0.22.17",
|
|
65
|
-
"typescript": "^4.7.3"
|
|
66
|
-
"whatwg-fetch": "^3.6.2"
|
|
63
|
+
"typescript": "^4.7.3"
|
|
67
64
|
},
|
|
68
65
|
"dependencies": {
|
|
69
66
|
"@ethersproject/bytes": "^5.6.1",
|
|
70
67
|
"bn.js": "^5.2.1",
|
|
71
|
-
"cross-fetch": "^3.1.5",
|
|
72
68
|
"elliptic": "^6.5.4",
|
|
73
69
|
"ethereum-cryptography": "^1.0.3",
|
|
74
70
|
"hash.js": "^1.1.7",
|
|
71
|
+
"isomorphic-fetch": "^3.0.0",
|
|
75
72
|
"json-bigint": "^1.0.0",
|
|
76
73
|
"minimalistic-assert": "^1.0.1",
|
|
77
74
|
"pako": "^2.0.4",
|
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
|
@@ -40,7 +40,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
42
|
exports.RpcProvider = void 0;
|
|
43
|
-
var
|
|
43
|
+
var fetchPonyfill_1 = __importDefault(require("../utils/fetchPonyfill"));
|
|
44
44
|
var hash_1 = require("../utils/hash");
|
|
45
45
|
var json_1 = require("../utils/json");
|
|
46
46
|
var number_1 = require("../utils/number");
|
|
@@ -73,7 +73,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
73
73
|
_c.label = 1;
|
|
74
74
|
case 1:
|
|
75
75
|
_c.trys.push([1, 4, , 5]);
|
|
76
|
-
return [4 /*yield*/, (0,
|
|
76
|
+
return [4 /*yield*/, (0, fetchPonyfill_1.default)(this.nodeUrl, {
|
|
77
77
|
method: 'POST',
|
|
78
78
|
body: (0, json_1.stringify)(requestData),
|
|
79
79
|
headers: {
|
|
@@ -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
|
@@ -58,6 +58,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
58
58
|
exports.SequencerProvider = void 0;
|
|
59
59
|
var url_join_1 = __importDefault(require("url-join"));
|
|
60
60
|
var constants_1 = require("../constants");
|
|
61
|
+
var fetchPonyfill_1 = __importDefault(require("../utils/fetchPonyfill"));
|
|
61
62
|
var hash_1 = require("../utils/hash");
|
|
62
63
|
var json_1 = require("../utils/json");
|
|
63
64
|
var number_1 = require("../utils/number");
|
|
@@ -180,7 +181,7 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
180
181
|
_c.label = 1;
|
|
181
182
|
case 1:
|
|
182
183
|
_c.trys.push([1, 4, , 5]);
|
|
183
|
-
return [4 /*yield*/,
|
|
184
|
+
return [4 /*yield*/, (0, fetchPonyfill_1.default)(url, {
|
|
184
185
|
method: method,
|
|
185
186
|
body: (0, json_1.stringify)(request),
|
|
186
187
|
headers: headers,
|
|
@@ -354,6 +355,14 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
354
355
|
});
|
|
355
356
|
});
|
|
356
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
|
+
};
|
|
357
366
|
SequencerProvider.prototype.waitForTransaction = function (txHash, retryInterval) {
|
|
358
367
|
if (retryInterval === void 0) { retryInterval = 8000; }
|
|
359
368
|
return __awaiter(this, void 0, void 0, function () {
|
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
|
}
|
|
@@ -10,6 +10,7 @@ import type {
|
|
|
10
10
|
DeployContractResponse,
|
|
11
11
|
EstimateFeeResponse,
|
|
12
12
|
GetBlockResponse,
|
|
13
|
+
GetCodeResponse,
|
|
13
14
|
GetTransactionReceiptResponse,
|
|
14
15
|
GetTransactionResponse,
|
|
15
16
|
Invocation,
|
|
@@ -42,6 +43,11 @@ export abstract class ProviderInterface {
|
|
|
42
43
|
*/
|
|
43
44
|
public abstract getBlock(blockIdentifier: BlockIdentifier): Promise<GetBlockResponse>;
|
|
44
45
|
|
|
46
|
+
public abstract getCode(
|
|
47
|
+
contractAddress: string,
|
|
48
|
+
blockIdentifier?: BlockIdentifier
|
|
49
|
+
): Promise<GetCodeResponse>;
|
|
50
|
+
|
|
45
51
|
/**
|
|
46
52
|
* Gets the contract class of the deployed contract.
|
|
47
53
|
*
|
package/src/provider/rpc.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import fetch from 'cross-fetch';
|
|
2
|
-
|
|
3
1
|
import { StarknetChainId } from '../constants';
|
|
4
2
|
import {
|
|
5
3
|
BlockTag,
|
|
@@ -18,6 +16,7 @@ import {
|
|
|
18
16
|
InvokeFunctionResponse,
|
|
19
17
|
} from '../types';
|
|
20
18
|
import { RPC } from '../types/api';
|
|
19
|
+
import fetch from '../utils/fetchPonyfill';
|
|
21
20
|
import { getSelectorFromName } from '../utils/hash';
|
|
22
21
|
import { stringify } from '../utils/json';
|
|
23
22
|
import {
|
|
@@ -214,6 +213,15 @@ export class RpcProvider implements ProviderInterface {
|
|
|
214
213
|
return this.responseParser.parseCallContractResponse(result);
|
|
215
214
|
}
|
|
216
215
|
|
|
216
|
+
public async getCode(
|
|
217
|
+
contractAddress: string,
|
|
218
|
+
_blockIdentifier?: BlockIdentifier
|
|
219
|
+
): Promise<RPC.GetCodeResponse> {
|
|
220
|
+
const result = await this.fetchEndpoint('starknet_getCode', [contractAddress]);
|
|
221
|
+
|
|
222
|
+
return this.responseParser.parseGetCodeResponse(result);
|
|
223
|
+
}
|
|
224
|
+
|
|
217
225
|
public async waitForTransaction(txHash: BigNumberish, retryInterval: number = 8000) {
|
|
218
226
|
let onchain = false;
|
|
219
227
|
let retries = 100;
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
GetTransactionTraceResponse,
|
|
25
25
|
Sequencer,
|
|
26
26
|
} from '../types/api';
|
|
27
|
+
import fetch from '../utils/fetchPonyfill';
|
|
27
28
|
import { getSelectorFromName } from '../utils/hash';
|
|
28
29
|
import { parse, parseAlwaysAsBig, stringify } from '../utils/json';
|
|
29
30
|
import { BigNumberish, bigNumberishArrayToDecimalStringArray, toBN, toHex } from '../utils/number';
|
|
@@ -322,6 +323,15 @@ export class SequencerProvider implements ProviderInterface {
|
|
|
322
323
|
).then(this.responseParser.parseFeeEstimateResponse);
|
|
323
324
|
}
|
|
324
325
|
|
|
326
|
+
public async getCode(
|
|
327
|
+
contractAddress: string,
|
|
328
|
+
blockIdentifier: BlockIdentifier = 'pending'
|
|
329
|
+
): Promise<Sequencer.GetCodeResponse> {
|
|
330
|
+
return this.fetchEndpoint('get_code', { contractAddress, blockIdentifier }).then(
|
|
331
|
+
this.responseParser.parseGetCodeResponse
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
|
|
325
335
|
public async waitForTransaction(txHash: BigNumberish, retryInterval: number = 8000) {
|
|
326
336
|
let onchain = false;
|
|
327
337
|
|
|
@@ -53,11 +53,6 @@ export type ExecutionResources = {
|
|
|
53
53
|
n_memory_holes: number;
|
|
54
54
|
};
|
|
55
55
|
|
|
56
|
-
export type GetCodeResponse = {
|
|
57
|
-
bytecode: string[];
|
|
58
|
-
abi: Abi;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
56
|
export type GetTransactionTraceResponse = {
|
|
62
57
|
function_invocation: {
|
|
63
58
|
caller_address: string;
|
|
@@ -116,6 +111,11 @@ export namespace Sequencer {
|
|
|
116
111
|
class_hash?: string;
|
|
117
112
|
};
|
|
118
113
|
|
|
114
|
+
export type GetCodeResponse = {
|
|
115
|
+
bytecode: string[];
|
|
116
|
+
abi: Abi;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
119
|
export interface InvokeFunctionTransactionResponse extends InvokeFunctionTransaction {
|
|
120
120
|
transaction_hash: string;
|
|
121
121
|
}
|
package/src/types/provider.ts
CHANGED
|
@@ -16,6 +16,11 @@ export interface GetBlockResponse {
|
|
|
16
16
|
starknet_version?: string;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
export interface GetCodeResponse {
|
|
20
|
+
bytecode: string[];
|
|
21
|
+
// abi: string; // is not consistent between rpc and sequencer (is it?), therefore not included in the provider interface
|
|
22
|
+
}
|
|
23
|
+
|
|
19
24
|
export type GetTransactionResponse = InvokeTransactionResponse & DeclareTransactionResponse;
|
|
20
25
|
|
|
21
26
|
export interface CommonTransactionResponse {
|
package/src/utils/address.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { arrayify } from '@ethersproject/bytes';
|
|
|
3
3
|
|
|
4
4
|
import { MASK_251, ZERO } from '../constants';
|
|
5
5
|
import { addHexPrefix, removeHexPrefix } from './encode';
|
|
6
|
-
import {
|
|
6
|
+
import { keccakBn } from './hash';
|
|
7
7
|
import { BigNumberish, assertInRange, toBN, toHex } from './number';
|
|
8
8
|
|
|
9
9
|
export function addAddressPadding(address: BigNumberish): string {
|
|
@@ -25,7 +25,7 @@ export function validateAndParseAddress(address: BigNumberish): string {
|
|
|
25
25
|
// from https://github.com/ethers-io/ethers.js/blob/fc1e006575d59792fa97b4efb9ea2f8cca1944cf/packages/address/src.ts/index.ts#L12
|
|
26
26
|
export function getChecksumAddress(address: BigNumberish): string {
|
|
27
27
|
const chars = removeHexPrefix(validateAndParseAddress(address)).toLowerCase().split('');
|
|
28
|
-
const hashed = arrayify(
|
|
28
|
+
const hashed = arrayify(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")
|
|
29
29
|
|
|
30
30
|
for (let i = 0; i < chars.length; i += 2) {
|
|
31
31
|
if (hashed[i >> 1] >> 4 >= 8) {
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export default (typeof window !== 'undefined' && window.fetch) || // use buildin fetch in browser if available
|
|
2
|
+
(typeof global !== 'undefined' && global.fetch) || // use buildin fetch in node, react-native and service worker if available
|
|
3
|
+
// eslint-disable-next-line global-require
|
|
4
|
+
require('isomorphic-fetch'); // ponyfill fetch in node and browsers that don't have it
|
package/src/utils/hash.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import BN from 'bn.js';
|
|
2
2
|
import { keccak256 } from 'ethereum-cryptography/keccak';
|
|
3
|
+
import { hexToBytes } from 'ethereum-cryptography/utils';
|
|
3
4
|
import assert from 'minimalistic-assert';
|
|
4
5
|
|
|
5
6
|
import {
|
|
@@ -13,12 +14,18 @@ import {
|
|
|
13
14
|
} from '../constants';
|
|
14
15
|
import { RawCalldata } from '../types/lib';
|
|
15
16
|
import { ec } from './ellipticCurve';
|
|
16
|
-
import { addHexPrefix, buf2hex, utf8ToArray } from './encode';
|
|
17
|
+
import { addHexPrefix, buf2hex, removeHexPrefix, utf8ToArray } from './encode';
|
|
17
18
|
import { BigNumberish, toBN, toFelt, toHex } from './number';
|
|
18
19
|
|
|
19
20
|
export const transactionVersion = 0;
|
|
20
21
|
export const feeTransactionVersion = toBN(2).pow(toBN(128)).add(toBN(transactionVersion));
|
|
21
22
|
|
|
23
|
+
export function keccakBn(value: BigNumberish): string {
|
|
24
|
+
const hexWithoutPrefix = removeHexPrefix(toHex(toBN(value)));
|
|
25
|
+
const evenHex = hexWithoutPrefix.length % 2 === 0 ? hexWithoutPrefix : `0${hexWithoutPrefix}`;
|
|
26
|
+
return addHexPrefix(buf2hex(keccak256(hexToBytes(evenHex))));
|
|
27
|
+
}
|
|
28
|
+
|
|
22
29
|
function keccakHex(value: string): string {
|
|
23
30
|
return addHexPrefix(buf2hex(keccak256(utf8ToArray(value))));
|
|
24
31
|
}
|
|
@@ -57,6 +57,10 @@ export class RPCResponseParser extends ResponseParser {
|
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
public parseGetCodeResponse(res: RPC.GetCodeResponse): RPC.GetCodeResponse {
|
|
61
|
+
return res;
|
|
62
|
+
}
|
|
63
|
+
|
|
60
64
|
public parseFeeEstimateResponse(res: RPC.EstimateFeeResponse): EstimateFeeResponse {
|
|
61
65
|
return {
|
|
62
66
|
overall_fee: toBN(res.overall_fee),
|
|
@@ -70,6 +70,10 @@ export class SequencerAPIResponseParser extends ResponseParser {
|
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
public parseGetCodeResponse(res: Sequencer.GetCodeResponse): Sequencer.GetCodeResponse {
|
|
74
|
+
return res;
|
|
75
|
+
}
|
|
76
|
+
|
|
73
77
|
public parseFeeEstimateResponse(res: Sequencer.EstimateFeeResponse): EstimateFeeResponse {
|
|
74
78
|
if ('overall_fee' in res) {
|
|
75
79
|
let gasInfo = {};
|
package/types/api/sequencer.d.ts
CHANGED
|
@@ -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/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/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();
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = (typeof window !== 'undefined' && window.fetch) || // use buildin fetch in browser if available
|
|
4
|
+
(typeof global !== 'undefined' && global.fetch) || // use buildin fetch in node, react-native and service worker if available
|
|
5
|
+
// eslint-disable-next-line global-require
|
|
6
|
+
require('isomorphic-fetch'); // ponyfill fetch in node and browsers that don't have it
|
package/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/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 = {};
|
package/www/docs/API/contract.md
CHANGED
|
@@ -22,7 +22,7 @@ contract.**address** => _string_
|
|
|
22
22
|
|
|
23
23
|
The address the contract was constructed/connected with
|
|
24
24
|
|
|
25
|
-
contract.**
|
|
25
|
+
contract.**providerOrAccount** => _ProviderInterface | AccountInterface_
|
|
26
26
|
|
|
27
27
|
Provider or account that are used to interact with the network
|
|
28
28
|
|
package/www/docs/API/provider.md
CHANGED
|
@@ -175,7 +175,7 @@ Deploys a contract on Starknet
|
|
|
175
175
|
|
|
176
176
|
<hr/>
|
|
177
177
|
|
|
178
|
-
provider
|
|
178
|
+
provider.**waitForTransaction**(txHash [ , retryInterval]) => _Promise < void >_
|
|
179
179
|
|
|
180
180
|
Wait for the transaction to be accepted on L2 or L1.
|
|
181
181
|
|
package/www/guides/account.md
CHANGED
|
@@ -14,7 +14,6 @@ Install the latest version of starknet with `npm install starknet@next`
|
|
|
14
14
|
|
|
15
15
|
```javascript
|
|
16
16
|
import fs from "fs";
|
|
17
|
-
import fs from "fs";
|
|
18
17
|
import {
|
|
19
18
|
Account,
|
|
20
19
|
Contract,
|
|
@@ -42,12 +41,31 @@ Deploy the Account contract and wait for it to be verified on StarkNet.
|
|
|
42
41
|
const compiledAccount = json.parse(
|
|
43
42
|
fs.readFileSync("./Account.json").toString("ascii")
|
|
44
43
|
);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
> **Note**
|
|
47
|
+
>
|
|
48
|
+
> below example uses [Argent's](https://github.com/argentlabs/argent-contracts-starknet/blob/develop/contracts/ArgentAccount.cairo) account contract
|
|
49
|
+
|
|
50
|
+
```javascript
|
|
45
51
|
const accountResponse = await defaultProvider.deployContract({
|
|
46
52
|
contract: compiledAccount,
|
|
47
53
|
addressSalt: starkKeyPub,
|
|
48
54
|
});
|
|
49
55
|
```
|
|
50
56
|
|
|
57
|
+
> **Note**
|
|
58
|
+
>
|
|
59
|
+
> below example uses [OpenZeppelin's](https://github.com/OpenZeppelin/cairo-contracts/blob/main/src/openzeppelin/account/presets/Account.cairo) account contract
|
|
60
|
+
|
|
61
|
+
```javascript
|
|
62
|
+
const accountResponse = await defaultProvider.deployContract({
|
|
63
|
+
contract: compiledAccount,
|
|
64
|
+
constructorCalldata: [starkKeyPub],
|
|
65
|
+
addressSalt: starkKeyPub,
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
51
69
|
## Use your new account
|
|
52
70
|
|
|
53
71
|
Wait for the deployment transaction to be accepted and assign the address of the deployed account to the Account object.
|
|
@@ -56,7 +74,11 @@ Wait for the deployment transaction to be accepted and assign the address of the
|
|
|
56
74
|
await defaultProvider.waitForTransaction(accountResponse.transaction_hash);
|
|
57
75
|
```
|
|
58
76
|
|
|
59
|
-
Once account contract is deployed [Account](../docs/API/account.md) instance can be created. Use your new account instance to sign transactions, messages or verify signatures!
|
|
77
|
+
Once account contract is deployed [Account](../docs/API/account.md) instance can be created. Use your new account instance to sign transactions, messages or verify signatures!
|
|
78
|
+
|
|
79
|
+
> **Note**
|
|
80
|
+
>
|
|
81
|
+
> Make sure your Account has enough funds to execute invocations. Use this [faucet](https://faucet.goerli.starknet.io/) for funding on testnet.
|
|
60
82
|
|
|
61
83
|
```js
|
|
62
84
|
const account = new Account(
|