starknet 3.7.0 → 3.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/README.md +18 -53
- package/__mocks__/ArgentAccount.json +32022 -38726
- package/__tests__/accountContract.test.ts +42 -32
- package/__tests__/contract.test.ts +20 -6
- package/__tests__/utils/__snapshots__/utils.browser.test.ts.snap +2 -2
- package/__tests__/utils/__snapshots__/utils.test.ts.snap +2 -2
- package/__tests__/utils/ellipticalCurve.test.ts +26 -8
- package/__tests__/utils/transactionHash.test.ts +17 -0
- package/__tests__/utils/utils.test.ts +10 -0
- package/account/default.d.ts +11 -1
- package/account/default.js +58 -50
- package/constants.d.ts +9 -0
- package/constants.js +13 -0
- package/contract/default.d.ts +12 -2
- package/contract/default.js +27 -20
- package/contract/interface.d.ts +21 -3
- package/dist/account/default.d.ts +5 -1
- package/dist/account/default.js +46 -30
- package/dist/constants.d.ts +9 -0
- package/dist/constants.js +12 -1
- package/dist/contract/default.d.ts +6 -3
- package/dist/contract/default.js +23 -20
- package/dist/contract/interface.d.ts +9 -4
- package/dist/provider/default.d.ts +5 -2
- package/dist/provider/default.js +36 -19
- package/dist/provider/interface.d.ts +2 -0
- package/dist/provider/utils.d.ts +1 -2
- package/dist/provider/utils.js +7 -8
- package/dist/signer/default.js +4 -2
- package/dist/signer/ledger.js +4 -2
- package/dist/types/api.d.ts +4 -1
- package/dist/types/lib.d.ts +1 -0
- package/dist/types/signer.d.ts +2 -0
- package/dist/utils/hash.d.ts +5 -3
- package/dist/utils/hash.js +25 -23
- package/dist/utils/stark.d.ts +3 -0
- package/dist/utils/stark.js +8 -1
- package/dist/utils/transaction.d.ts +2 -0
- package/dist/utils/transaction.js +5 -1
- package/dist/utils/typedData/index.d.ts +2 -2
- package/dist/utils/typedData/types.d.ts +3 -3
- package/dist/utils/typedData/utils.d.ts +1 -1
- package/package.json +1 -1
- package/provider/default.d.ts +7 -2
- package/provider/default.js +49 -27
- package/provider/interface.d.ts +2 -0
- package/provider/utils.d.ts +1 -2
- package/provider/utils.js +7 -8
- package/signer/default.js +12 -5
- package/signer/ledger.js +12 -5
- package/src/account/default.ts +47 -18
- package/src/constants.ts +10 -0
- package/src/contract/default.ts +32 -19
- package/src/contract/interface.ts +21 -3
- package/src/provider/default.ts +37 -12
- package/src/provider/interface.ts +3 -0
- package/src/provider/utils.ts +7 -8
- package/src/signer/default.ts +10 -5
- package/src/signer/ledger.ts +10 -5
- package/src/types/api.ts +4 -1
- package/src/types/lib.ts +1 -0
- package/src/types/signer.ts +2 -0
- package/src/utils/hash.ts +70 -26
- package/src/utils/stark.ts +8 -1
- package/src/utils/transaction.ts +7 -0
- package/types/api.d.ts +4 -1
- package/types/lib.d.ts +1 -0
- package/types/signer.d.ts +2 -0
- package/utils/hash.d.ts +25 -7
- package/utils/hash.js +60 -26
- package/utils/stark.d.ts +4 -0
- package/utils/stark.js +13 -1
- package/utils/transaction.d.ts +5 -0
- package/utils/transaction.js +12 -1
- package/utils/typedData/index.d.ts +2 -2
- package/utils/typedData/types.d.ts +3 -3
- package/utils/typedData/utils.d.ts +1 -1
- package/__tests__/constancts.ts +0 -2
package/dist/utils/hash.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import BN from 'bn.js';
|
|
2
|
-
import {
|
|
2
|
+
import { StarknetChainId, TransactionHashPrefix } from '../constants';
|
|
3
3
|
import { BigNumberish } from './number';
|
|
4
|
-
export declare const transactionPrefix: string;
|
|
5
4
|
export declare const transactionVersion = 0;
|
|
5
|
+
export declare const feeTransactionVersion: BN;
|
|
6
6
|
/**
|
|
7
7
|
* Function to get the starknet keccak hash from a string
|
|
8
8
|
*
|
|
@@ -21,4 +21,6 @@ export declare function starknetKeccak(value: string): BN;
|
|
|
21
21
|
export declare function getSelectorFromName(funcName: string): string;
|
|
22
22
|
export declare function pedersen(input: [BigNumberish, BigNumberish]): string;
|
|
23
23
|
export declare function computeHashOnElements(data: BigNumberish[]): string;
|
|
24
|
-
export declare function
|
|
24
|
+
export declare function calculateTransactionHashCommon(txHashPrefix: TransactionHashPrefix, version: BigNumberish, contractAddress: BigNumberish, entryPointSelector: BigNumberish, calldata: BigNumberish[], maxFee: BigNumberish, chainId: StarknetChainId, additionalData?: BigNumberish[]): string;
|
|
25
|
+
export declare function calculateDeployTransactionHash(contractAddress: BigNumberish, constructorCalldata: BigNumberish[], version: BigNumberish, chainId: StarknetChainId): string;
|
|
26
|
+
export declare function calculcateTransactionHash(contractAddress: BigNumberish, version: BigNumberish, entryPointSelector: BigNumberish, calldata: BigNumberish[], maxFee: BigNumberish, chainId: StarknetChainId): string;
|
package/dist/utils/hash.js
CHANGED
|
@@ -28,16 +28,15 @@ 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.
|
|
31
|
+
exports.calculcateTransactionHash = exports.calculateDeployTransactionHash = exports.calculateTransactionHashCommon = exports.computeHashOnElements = exports.pedersen = exports.getSelectorFromName = exports.starknetKeccak = exports.feeTransactionVersion = exports.transactionVersion = void 0;
|
|
32
32
|
var keccak_1 = require("ethereum-cryptography/keccak");
|
|
33
33
|
var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
|
|
34
34
|
var constants_1 = require("../constants");
|
|
35
35
|
var ellipticCurve_1 = require("./ellipticCurve");
|
|
36
36
|
var encode_1 = require("./encode");
|
|
37
37
|
var number_1 = require("./number");
|
|
38
|
-
var shortString_1 = require("./shortString");
|
|
39
|
-
exports.transactionPrefix = (0, shortString_1.encodeShortString)('StarkNet Transaction');
|
|
40
38
|
exports.transactionVersion = 0;
|
|
39
|
+
exports.feeTransactionVersion = (0, number_1.toBN)(2).pow((0, number_1.toBN)(128)).add((0, number_1.toBN)(exports.transactionVersion));
|
|
41
40
|
function keccakHex(value) {
|
|
42
41
|
return (0, encode_1.addHexPrefix)((0, encode_1.buf2hex)((0, keccak_1.keccak256)((0, encode_1.utf8ToArray)(value))));
|
|
43
42
|
}
|
|
@@ -88,25 +87,28 @@ function computeHashOnElements(data) {
|
|
|
88
87
|
return __spreadArray(__spreadArray([], __read(data), false), [data.length], false).reduce(function (x, y) { return pedersen([x, y]); }, 0).toString();
|
|
89
88
|
}
|
|
90
89
|
exports.computeHashOnElements = computeHashOnElements;
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
.map(computeHashOnElements);
|
|
103
|
-
return computeHashOnElements([
|
|
104
|
-
exports.transactionPrefix,
|
|
105
|
-
account,
|
|
106
|
-
computeHashOnElements(hashArray),
|
|
107
|
-
nonce,
|
|
90
|
+
// following implementation is based on this python implementation:
|
|
91
|
+
// https://github.com/starkware-libs/cairo-lang/blob/b614d1867c64f3fb2cf4a4879348cfcf87c3a5a7/src/starkware/starknet/core/os/transaction_hash/transaction_hash.py
|
|
92
|
+
function calculateTransactionHashCommon(txHashPrefix, version, contractAddress, entryPointSelector, calldata, maxFee, chainId, additionalData) {
|
|
93
|
+
if (additionalData === void 0) { additionalData = []; }
|
|
94
|
+
var calldataHash = computeHashOnElements(calldata);
|
|
95
|
+
var dataToHash = __spreadArray([
|
|
96
|
+
txHashPrefix,
|
|
97
|
+
version,
|
|
98
|
+
contractAddress,
|
|
99
|
+
entryPointSelector,
|
|
100
|
+
calldataHash,
|
|
108
101
|
maxFee,
|
|
109
|
-
|
|
110
|
-
]);
|
|
102
|
+
chainId
|
|
103
|
+
], __read(additionalData), false);
|
|
104
|
+
return computeHashOnElements(dataToHash);
|
|
111
105
|
}
|
|
112
|
-
exports.
|
|
106
|
+
exports.calculateTransactionHashCommon = calculateTransactionHashCommon;
|
|
107
|
+
function calculateDeployTransactionHash(contractAddress, constructorCalldata, version, chainId) {
|
|
108
|
+
return calculateTransactionHashCommon(constants_1.TransactionHashPrefix.DEPLOY, version, contractAddress, getSelectorFromName('constructor'), constructorCalldata, constants_1.ZERO, chainId);
|
|
109
|
+
}
|
|
110
|
+
exports.calculateDeployTransactionHash = calculateDeployTransactionHash;
|
|
111
|
+
function calculcateTransactionHash(contractAddress, version, entryPointSelector, calldata, maxFee, chainId) {
|
|
112
|
+
return calculateTransactionHashCommon(constants_1.TransactionHashPrefix.INVOKE, version, contractAddress, entryPointSelector, calldata, maxFee, chainId);
|
|
113
|
+
}
|
|
114
|
+
exports.calculcateTransactionHash = calculcateTransactionHash;
|
package/dist/utils/stark.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import BN from 'bn.js';
|
|
1
2
|
import { Calldata, CompressedProgram, Program, RawArgs, Signature } from '../types';
|
|
3
|
+
import { BigNumberish } from './number';
|
|
2
4
|
/**
|
|
3
5
|
* Function to compress compiled cairo program
|
|
4
6
|
*
|
|
@@ -11,3 +13,4 @@ export declare function randomAddress(): string;
|
|
|
11
13
|
export declare function makeAddress(input: string): string;
|
|
12
14
|
export declare function formatSignature(sig?: Signature): string[];
|
|
13
15
|
export declare function compileCalldata(args: RawArgs): Calldata;
|
|
16
|
+
export declare function estimatedFeeToMaxFee(estimatedFee: BigNumberish, overhead?: number): BN;
|
package/dist/utils/stark.js
CHANGED
|
@@ -25,7 +25,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
25
25
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
26
|
};
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.compileCalldata = exports.formatSignature = exports.makeAddress = exports.randomAddress = exports.compressProgram = void 0;
|
|
28
|
+
exports.estimatedFeeToMaxFee = exports.compileCalldata = exports.formatSignature = exports.makeAddress = exports.randomAddress = exports.compressProgram = void 0;
|
|
29
29
|
var pako_1 = require("pako");
|
|
30
30
|
var ellipticCurve_1 = require("./ellipticCurve");
|
|
31
31
|
var encode_1 = require("./encode");
|
|
@@ -82,3 +82,10 @@ function compileCalldata(args) {
|
|
|
82
82
|
});
|
|
83
83
|
}
|
|
84
84
|
exports.compileCalldata = compileCalldata;
|
|
85
|
+
function estimatedFeeToMaxFee(estimatedFee, overhead) {
|
|
86
|
+
if (overhead === void 0) { overhead = 0.15; }
|
|
87
|
+
// BN can only handle Integers, so we need to do all calulations with integers
|
|
88
|
+
var overHeadPercent = Math.round((1 + overhead) * 100);
|
|
89
|
+
return (0, number_1.toBN)(estimatedFee).mul((0, number_1.toBN)(overHeadPercent)).div((0, number_1.toBN)(100));
|
|
90
|
+
}
|
|
91
|
+
exports.estimatedFeeToMaxFee = estimatedFeeToMaxFee;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Call, ParsedStruct } from '../types';
|
|
2
|
+
import { BigNumberish } from './number';
|
|
2
3
|
/**
|
|
3
4
|
* Transforms a list of Calls, each with their own calldata, into
|
|
4
5
|
* two arrays: one with the entrypoints, and one with the concatenated calldata.
|
|
@@ -16,3 +17,4 @@ export declare const transformCallsToMulticallArrays: (calls: Call[]) => {
|
|
|
16
17
|
* @returns
|
|
17
18
|
*/
|
|
18
19
|
export declare const fromCallsToExecuteCalldata: (calls: Call[]) => string[];
|
|
20
|
+
export declare const fromCallsToExecuteCalldataWithNonce: (calls: Call[], nonce: BigNumberish) => string[];
|
|
@@ -25,7 +25,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
25
25
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
26
|
};
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.fromCallsToExecuteCalldata = exports.transformCallsToMulticallArrays = void 0;
|
|
28
|
+
exports.fromCallsToExecuteCalldataWithNonce = exports.fromCallsToExecuteCalldata = exports.transformCallsToMulticallArrays = void 0;
|
|
29
29
|
var hash_1 = require("./hash");
|
|
30
30
|
var number_1 = require("./number");
|
|
31
31
|
/**
|
|
@@ -73,3 +73,7 @@ var fromCallsToExecuteCalldata = function (calls) {
|
|
|
73
73
|
], false), __read(calldata), false);
|
|
74
74
|
};
|
|
75
75
|
exports.fromCallsToExecuteCalldata = fromCallsToExecuteCalldata;
|
|
76
|
+
var fromCallsToExecuteCalldataWithNonce = function (calls, nonce) {
|
|
77
|
+
return __spreadArray(__spreadArray([], __read((0, exports.fromCallsToExecuteCalldata)(calls)), false), [(0, number_1.toBN)(nonce).toString()], false);
|
|
78
|
+
};
|
|
79
|
+
exports.fromCallsToExecuteCalldataWithNonce = fromCallsToExecuteCalldataWithNonce;
|
|
@@ -47,9 +47,9 @@ export declare const encodeData: <T extends {
|
|
|
47
47
|
}[]>;
|
|
48
48
|
primaryType: string;
|
|
49
49
|
domain: {
|
|
50
|
-
name?: string | undefined;
|
|
51
50
|
version?: string | undefined;
|
|
52
51
|
chainId?: string | number | undefined;
|
|
52
|
+
name?: string | undefined;
|
|
53
53
|
};
|
|
54
54
|
message: Record<string, unknown>;
|
|
55
55
|
}>(typedData: T, type: string, data: T["message"]) => string[][];
|
|
@@ -74,9 +74,9 @@ export declare const getStructHash: <T extends {
|
|
|
74
74
|
}[]>;
|
|
75
75
|
primaryType: string;
|
|
76
76
|
domain: {
|
|
77
|
-
name?: string | undefined;
|
|
78
77
|
version?: string | undefined;
|
|
79
78
|
chainId?: string | number | undefined;
|
|
79
|
+
name?: string | undefined;
|
|
80
80
|
};
|
|
81
81
|
message: Record<string, unknown>;
|
|
82
82
|
}>(typedData: T, type: string, data: T["message"]) => string;
|
|
@@ -25,9 +25,9 @@ export declare const STARKNET_TYPE: import("superstruct").Struct<{
|
|
|
25
25
|
*/
|
|
26
26
|
export declare type StarkNetType = Infer<typeof STARKNET_TYPE>;
|
|
27
27
|
export declare const STARKNET_DOMAIN_TYPE: import("superstruct").Struct<{
|
|
28
|
-
name?: string | undefined;
|
|
29
28
|
version?: string | undefined;
|
|
30
29
|
chainId?: string | number | undefined;
|
|
30
|
+
name?: string | undefined;
|
|
31
31
|
}, {
|
|
32
32
|
name: import("superstruct").Struct<string | undefined, null>;
|
|
33
33
|
version: import("superstruct").Struct<string | undefined, null>;
|
|
@@ -49,9 +49,9 @@ export declare const STARKNET_TYPED_DATA_TYPE: import("superstruct").Struct<{
|
|
|
49
49
|
}[]>;
|
|
50
50
|
primaryType: string;
|
|
51
51
|
domain: {
|
|
52
|
-
name?: string | undefined;
|
|
53
52
|
version?: string | undefined;
|
|
54
53
|
chainId?: string | number | undefined;
|
|
54
|
+
name?: string | undefined;
|
|
55
55
|
};
|
|
56
56
|
message: Record<string, unknown>;
|
|
57
57
|
}, {
|
|
@@ -66,9 +66,9 @@ export declare const STARKNET_TYPED_DATA_TYPE: import("superstruct").Struct<{
|
|
|
66
66
|
}[]>, null>;
|
|
67
67
|
primaryType: import("superstruct").Struct<string, null>;
|
|
68
68
|
domain: import("superstruct").Struct<{
|
|
69
|
-
name?: string | undefined;
|
|
70
69
|
version?: string | undefined;
|
|
71
70
|
chainId?: string | number | undefined;
|
|
71
|
+
name?: string | undefined;
|
|
72
72
|
}, {
|
|
73
73
|
name: import("superstruct").Struct<string | undefined, null>;
|
|
74
74
|
version: import("superstruct").Struct<string | undefined, null>;
|
|
@@ -16,9 +16,9 @@ export declare const validateTypedData: (data: unknown) => data is {
|
|
|
16
16
|
}[]>;
|
|
17
17
|
primaryType: string;
|
|
18
18
|
domain: {
|
|
19
|
-
name?: string | undefined;
|
|
20
19
|
version?: string | undefined;
|
|
21
20
|
chainId?: string | number | undefined;
|
|
21
|
+
name?: string | undefined;
|
|
22
22
|
};
|
|
23
23
|
message: Record<string, unknown>;
|
|
24
24
|
};
|
package/package.json
CHANGED
package/provider/default.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { StarknetChainId } from '../constants';
|
|
1
2
|
import {
|
|
2
3
|
Abi,
|
|
3
4
|
AddTransactionResponse,
|
|
@@ -29,10 +30,12 @@ export declare class Provider implements ProviderInterface {
|
|
|
29
30
|
baseUrl: string;
|
|
30
31
|
feederGatewayUrl: string;
|
|
31
32
|
gatewayUrl: string;
|
|
33
|
+
chainId: StarknetChainId;
|
|
32
34
|
constructor(optionsOrProvider?: ProviderOptions | Provider);
|
|
33
35
|
protected static getNetworkFromName(
|
|
34
36
|
name: NetworkName
|
|
35
37
|
): 'https://alpha-mainnet.starknet.io' | 'https://alpha4.starknet.io';
|
|
38
|
+
protected static getChainIdFromBaseUrl(baseUrl: string): StarknetChainId;
|
|
36
39
|
private getFetchUrl;
|
|
37
40
|
private getFetchMethod;
|
|
38
41
|
private getQueryString;
|
|
@@ -66,8 +69,10 @@ export declare class Provider implements ProviderInterface {
|
|
|
66
69
|
*/
|
|
67
70
|
callContract(
|
|
68
71
|
{ contractAddress, entrypoint, calldata }: Call,
|
|
69
|
-
|
|
70
|
-
blockIdentifier
|
|
72
|
+
{
|
|
73
|
+
blockIdentifier,
|
|
74
|
+
}?: {
|
|
75
|
+
blockIdentifier?: BlockIdentifier;
|
|
71
76
|
}
|
|
72
77
|
): Promise<CallContractResponse>;
|
|
73
78
|
/**
|
package/provider/default.js
CHANGED
|
@@ -175,6 +175,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
175
175
|
exports.Provider = void 0;
|
|
176
176
|
var axios_1 = __importDefault(require('axios'));
|
|
177
177
|
var url_join_1 = __importDefault(require('url-join'));
|
|
178
|
+
var constants_1 = require('../constants');
|
|
178
179
|
var hash_1 = require('../utils/hash');
|
|
179
180
|
var json_1 = require('../utils/json');
|
|
180
181
|
var number_1 = require('../utils/number');
|
|
@@ -203,16 +204,22 @@ var Provider = /** @class */ (function () {
|
|
|
203
204
|
if (optionsOrProvider === void 0) {
|
|
204
205
|
optionsOrProvider = { network: 'goerli-alpha' };
|
|
205
206
|
}
|
|
207
|
+
var _a;
|
|
206
208
|
if (optionsOrProvider instanceof Provider) {
|
|
207
209
|
this.baseUrl = optionsOrProvider.baseUrl;
|
|
208
210
|
this.feederGatewayUrl = optionsOrProvider.feederGatewayUrl;
|
|
209
211
|
this.gatewayUrl = optionsOrProvider.gatewayUrl;
|
|
212
|
+
this.chainId =
|
|
213
|
+
(_a = optionsOrProvider.chainId) !== null && _a !== void 0
|
|
214
|
+
? _a
|
|
215
|
+
: Provider.getChainIdFromBaseUrl(optionsOrProvider.baseUrl);
|
|
210
216
|
} else {
|
|
211
217
|
var baseUrl =
|
|
212
218
|
'baseUrl' in optionsOrProvider
|
|
213
219
|
? optionsOrProvider.baseUrl
|
|
214
220
|
: Provider.getNetworkFromName(optionsOrProvider.network);
|
|
215
221
|
this.baseUrl = baseUrl;
|
|
222
|
+
this.chainId = Provider.getChainIdFromBaseUrl(baseUrl);
|
|
216
223
|
this.feederGatewayUrl = (0, url_join_1.default)(baseUrl, 'feeder_gateway');
|
|
217
224
|
this.gatewayUrl = (0, url_join_1.default)(baseUrl, 'gateway');
|
|
218
225
|
}
|
|
@@ -226,6 +233,18 @@ var Provider = /** @class */ (function () {
|
|
|
226
233
|
return 'https://alpha4.starknet.io';
|
|
227
234
|
}
|
|
228
235
|
};
|
|
236
|
+
Provider.getChainIdFromBaseUrl = function (baseUrl) {
|
|
237
|
+
try {
|
|
238
|
+
var url = new URL(baseUrl);
|
|
239
|
+
if (url.host.includes('mainnet.starknet.io')) {
|
|
240
|
+
return constants_1.StarknetChainId.MAINNET;
|
|
241
|
+
}
|
|
242
|
+
} catch (_a) {
|
|
243
|
+
// eslint-disable-next-line no-console
|
|
244
|
+
console.error('Could not parse baseUrl: ' + baseUrl);
|
|
245
|
+
}
|
|
246
|
+
return constants_1.StarknetChainId.TESTNET;
|
|
247
|
+
};
|
|
229
248
|
Provider.prototype.getFetchUrl = function (endpoint) {
|
|
230
249
|
var gatewayUrlEndpoints = ['add_transaction'];
|
|
231
250
|
return gatewayUrlEndpoints.includes(endpoint) ? this.gatewayUrl : this.feederGatewayUrl;
|
|
@@ -343,24 +362,28 @@ var Provider = /** @class */ (function () {
|
|
|
343
362
|
* @param blockNumber
|
|
344
363
|
* @returns the result of the function on the smart contract.
|
|
345
364
|
*/
|
|
346
|
-
Provider.prototype.callContract = function (_a,
|
|
365
|
+
Provider.prototype.callContract = function (_a, _b) {
|
|
347
366
|
var contractAddress = _a.contractAddress,
|
|
348
367
|
entrypoint = _a.entrypoint,
|
|
349
|
-
|
|
350
|
-
calldata =
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
368
|
+
_c = _a.calldata,
|
|
369
|
+
calldata = _c === void 0 ? [] : _c;
|
|
370
|
+
var _d = _b === void 0 ? {} : _b,
|
|
371
|
+
_e = _d.blockIdentifier,
|
|
372
|
+
blockIdentifier = _e === void 0 ? 'pending' : _e;
|
|
354
373
|
return __awaiter(this, void 0, void 0, function () {
|
|
355
|
-
return __generator(this, function (
|
|
374
|
+
return __generator(this, function (_f) {
|
|
356
375
|
return [
|
|
357
376
|
2 /*return*/,
|
|
358
|
-
this.fetchEndpoint(
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
377
|
+
this.fetchEndpoint(
|
|
378
|
+
'call_contract',
|
|
379
|
+
{ blockIdentifier: blockIdentifier },
|
|
380
|
+
{
|
|
381
|
+
signature: [],
|
|
382
|
+
contract_address: contractAddress,
|
|
383
|
+
entry_point_selector: (0, hash_1.getSelectorFromName)(entrypoint),
|
|
384
|
+
calldata: calldata,
|
|
385
|
+
}
|
|
386
|
+
),
|
|
364
387
|
];
|
|
365
388
|
});
|
|
366
389
|
});
|
|
@@ -399,7 +422,7 @@ var Provider = /** @class */ (function () {
|
|
|
399
422
|
*/
|
|
400
423
|
Provider.prototype.getCode = function (contractAddress, blockIdentifier) {
|
|
401
424
|
if (blockIdentifier === void 0) {
|
|
402
|
-
blockIdentifier =
|
|
425
|
+
blockIdentifier = 'pending';
|
|
403
426
|
}
|
|
404
427
|
return __awaiter(this, void 0, void 0, function () {
|
|
405
428
|
return __generator(this, function (_a) {
|
|
@@ -427,7 +450,7 @@ var Provider = /** @class */ (function () {
|
|
|
427
450
|
*/
|
|
428
451
|
Provider.prototype.getStorageAt = function (contractAddress, key, blockIdentifier) {
|
|
429
452
|
if (blockIdentifier === void 0) {
|
|
430
|
-
blockIdentifier =
|
|
453
|
+
blockIdentifier = 'pending';
|
|
431
454
|
}
|
|
432
455
|
return __awaiter(this, void 0, void 0, function () {
|
|
433
456
|
return __generator(this, function (_a) {
|
|
@@ -586,28 +609,27 @@ var Provider = /** @class */ (function () {
|
|
|
586
609
|
retryInterval = 8000;
|
|
587
610
|
}
|
|
588
611
|
return __awaiter(this, void 0, void 0, function () {
|
|
589
|
-
var onchain, res, message, error;
|
|
612
|
+
var onchain, res, successStates, errorStates, message, error;
|
|
590
613
|
return __generator(this, function (_a) {
|
|
591
614
|
switch (_a.label) {
|
|
592
615
|
case 0:
|
|
593
616
|
onchain = false;
|
|
594
|
-
|
|
617
|
+
_a.label = 1;
|
|
595
618
|
case 1:
|
|
596
|
-
|
|
597
|
-
_a.label = 2;
|
|
598
|
-
case 2:
|
|
599
|
-
if (!!onchain) return [3 /*break*/, 5];
|
|
619
|
+
if (!!onchain) return [3 /*break*/, 4];
|
|
600
620
|
// eslint-disable-next-line no-await-in-loop
|
|
601
621
|
return [4 /*yield*/, wait(retryInterval)];
|
|
602
|
-
case
|
|
622
|
+
case 2:
|
|
603
623
|
// eslint-disable-next-line no-await-in-loop
|
|
604
624
|
_a.sent();
|
|
605
625
|
return [4 /*yield*/, this.getTransactionStatus(txHash)];
|
|
606
|
-
case
|
|
626
|
+
case 3:
|
|
607
627
|
res = _a.sent();
|
|
608
|
-
|
|
628
|
+
successStates = ['ACCEPTED_ON_L1', 'ACCEPTED_ON_L2', 'PENDING'];
|
|
629
|
+
errorStates = ['REJECTED', 'NOT_RECEIVED'];
|
|
630
|
+
if (successStates.includes(res.tx_status)) {
|
|
609
631
|
onchain = true;
|
|
610
|
-
} else if (
|
|
632
|
+
} else if (errorStates.includes(res.tx_status)) {
|
|
611
633
|
message = res.tx_failure_reason
|
|
612
634
|
? res.tx_status +
|
|
613
635
|
': ' +
|
|
@@ -619,8 +641,8 @@ var Provider = /** @class */ (function () {
|
|
|
619
641
|
error.response = res;
|
|
620
642
|
throw error;
|
|
621
643
|
}
|
|
622
|
-
return [3 /*break*/,
|
|
623
|
-
case
|
|
644
|
+
return [3 /*break*/, 1];
|
|
645
|
+
case 4:
|
|
624
646
|
return [2 /*return*/];
|
|
625
647
|
}
|
|
626
648
|
});
|
package/provider/interface.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { StarknetChainId } from '../constants';
|
|
1
2
|
import type {
|
|
2
3
|
AddTransactionResponse,
|
|
3
4
|
Call,
|
|
@@ -17,6 +18,7 @@ export declare abstract class ProviderInterface {
|
|
|
17
18
|
abstract baseUrl: string;
|
|
18
19
|
abstract feederGatewayUrl: string;
|
|
19
20
|
abstract gatewayUrl: string;
|
|
21
|
+
abstract chainId: StarknetChainId;
|
|
20
22
|
/**
|
|
21
23
|
* Gets the smart contract address on the goerli testnet.
|
|
22
24
|
*
|
package/provider/utils.d.ts
CHANGED
|
@@ -37,8 +37,7 @@ export declare function getBlockIdentifier(blockIdentifier: BlockIdentifier): Bl
|
|
|
37
37
|
*
|
|
38
38
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L164-L173)
|
|
39
39
|
*
|
|
40
|
-
* @param
|
|
41
|
-
* @param blockHash
|
|
40
|
+
* @param blockIdentifier
|
|
42
41
|
* @returns block identifier for API request
|
|
43
42
|
*/
|
|
44
43
|
export declare function getFormattedBlockIdentifier(blockIdentifier?: BlockIdentifier): string;
|
package/provider/utils.js
CHANGED
|
@@ -39,6 +39,12 @@ exports.txIdentifier = txIdentifier;
|
|
|
39
39
|
* @returns block identifier object
|
|
40
40
|
*/
|
|
41
41
|
function getBlockIdentifier(blockIdentifier) {
|
|
42
|
+
if (blockIdentifier === null) {
|
|
43
|
+
return { type: 'BLOCK_NUMBER', data: null };
|
|
44
|
+
}
|
|
45
|
+
if (blockIdentifier === 'pending') {
|
|
46
|
+
return { type: 'BLOCK_NUMBER', data: 'pending' };
|
|
47
|
+
}
|
|
42
48
|
if (typeof blockIdentifier === 'number') {
|
|
43
49
|
return { type: 'BLOCK_NUMBER', data: blockIdentifier };
|
|
44
50
|
}
|
|
@@ -48,12 +54,6 @@ function getBlockIdentifier(blockIdentifier) {
|
|
|
48
54
|
if (typeof blockIdentifier === 'string' && !Number.isNaN(parseInt(blockIdentifier, 10))) {
|
|
49
55
|
return { type: 'BLOCK_NUMBER', data: parseInt(blockIdentifier, 10) };
|
|
50
56
|
}
|
|
51
|
-
if (blockIdentifier === null) {
|
|
52
|
-
return { type: 'BLOCK_NUMBER', data: null };
|
|
53
|
-
}
|
|
54
|
-
if (blockIdentifier === 'pending') {
|
|
55
|
-
return { type: 'BLOCK_NUMBER', data: 'pending' };
|
|
56
|
-
}
|
|
57
57
|
if (typeof blockIdentifier === 'string') {
|
|
58
58
|
throw new Error('Invalid block identifier: ' + blockIdentifier);
|
|
59
59
|
}
|
|
@@ -65,8 +65,7 @@ exports.getBlockIdentifier = getBlockIdentifier;
|
|
|
65
65
|
*
|
|
66
66
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L164-L173)
|
|
67
67
|
*
|
|
68
|
-
* @param
|
|
69
|
-
* @param blockHash
|
|
68
|
+
* @param blockIdentifier
|
|
70
69
|
* @returns block identifier for API request
|
|
71
70
|
*/
|
|
72
71
|
function getFormattedBlockIdentifier(blockIdentifier) {
|
package/signer/default.js
CHANGED
|
@@ -134,6 +134,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
134
134
|
exports.Signer = void 0;
|
|
135
135
|
var ellipticCurve_1 = require('../utils/ellipticCurve');
|
|
136
136
|
var hash_1 = require('../utils/hash');
|
|
137
|
+
var transaction_1 = require('../utils/transaction');
|
|
137
138
|
var typedData_1 = require('../utils/typedData');
|
|
138
139
|
var Signer = /** @class */ (function () {
|
|
139
140
|
function Signer(keyPair) {
|
|
@@ -148,16 +149,22 @@ var Signer = /** @class */ (function () {
|
|
|
148
149
|
};
|
|
149
150
|
Signer.prototype.signTransaction = function (transactions, transactionsDetail, abis) {
|
|
150
151
|
return __awaiter(this, void 0, void 0, function () {
|
|
151
|
-
var msgHash;
|
|
152
|
+
var calldata, msgHash;
|
|
152
153
|
return __generator(this, function (_a) {
|
|
153
154
|
if (abis && abis.length !== transactions.length) {
|
|
154
155
|
throw new Error('ABI must be provided for each transaction or no transaction');
|
|
155
156
|
}
|
|
156
|
-
|
|
157
|
-
transactionsDetail.walletAddress,
|
|
157
|
+
calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(
|
|
158
158
|
transactions,
|
|
159
|
-
transactionsDetail.nonce
|
|
160
|
-
|
|
159
|
+
transactionsDetail.nonce
|
|
160
|
+
);
|
|
161
|
+
msgHash = (0, hash_1.calculcateTransactionHash)(
|
|
162
|
+
transactionsDetail.walletAddress,
|
|
163
|
+
transactionsDetail.version,
|
|
164
|
+
(0, hash_1.getSelectorFromName)('__execute__'),
|
|
165
|
+
calldata,
|
|
166
|
+
transactionsDetail.maxFee,
|
|
167
|
+
transactionsDetail.chainId
|
|
161
168
|
);
|
|
162
169
|
return [2 /*return*/, (0, ellipticCurve_1.sign)(this.keyPair, msgHash)];
|
|
163
170
|
});
|
package/signer/ledger.js
CHANGED
|
@@ -141,6 +141,7 @@ var hw_app_eth_1 = __importDefault(require('@ledgerhq/hw-app-eth'));
|
|
|
141
141
|
var hw_transport_webhid_1 = __importDefault(require('@ledgerhq/hw-transport-webhid'));
|
|
142
142
|
var encode_1 = require('../utils/encode');
|
|
143
143
|
var hash_1 = require('../utils/hash');
|
|
144
|
+
var transaction_1 = require('../utils/transaction');
|
|
144
145
|
var typedData_1 = require('../utils/typedData');
|
|
145
146
|
function hexZeroPad(hash, length) {
|
|
146
147
|
var value = hash;
|
|
@@ -200,13 +201,19 @@ var LedgerBlindSigner = /** @class */ (function () {
|
|
|
200
201
|
};
|
|
201
202
|
LedgerBlindSigner.prototype.signTransaction = function (transactions, transactionsDetail) {
|
|
202
203
|
return __awaiter(this, void 0, void 0, function () {
|
|
203
|
-
var msgHash;
|
|
204
|
+
var calldata, msgHash;
|
|
204
205
|
return __generator(this, function (_a) {
|
|
205
|
-
|
|
206
|
-
transactionsDetail.walletAddress,
|
|
206
|
+
calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(
|
|
207
207
|
transactions,
|
|
208
|
-
transactionsDetail.nonce
|
|
209
|
-
|
|
208
|
+
transactionsDetail.nonce
|
|
209
|
+
);
|
|
210
|
+
msgHash = (0, hash_1.calculcateTransactionHash)(
|
|
211
|
+
transactionsDetail.walletAddress,
|
|
212
|
+
transactionsDetail.version,
|
|
213
|
+
(0, hash_1.getSelectorFromName)('__execute__'),
|
|
214
|
+
calldata,
|
|
215
|
+
transactionsDetail.maxFee,
|
|
216
|
+
transactionsDetail.chainId
|
|
210
217
|
);
|
|
211
218
|
return [2 /*return*/, this.sign(msgHash)];
|
|
212
219
|
});
|