starknet 3.12.3 → 3.14.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/.github/workflows/pr.yml +3 -0
- package/.github/workflows/release.yml +4 -0
- package/CHANGELOG.md +42 -0
- package/__mocks__/Account.json +25468 -0
- package/__tests__/account.test.ts +102 -65
- package/__tests__/contract.test.ts +23 -65
- package/__tests__/fixtures.ts +21 -1
- package/__tests__/provider.test.ts +31 -2
- package/account/default.d.ts +2 -9
- package/account/default.js +1 -0
- package/account/index.js +10 -6
- package/account/interface.d.ts +5 -3
- package/constants.d.ts +1 -0
- package/constants.js +1 -0
- package/contract/default.d.ts +1 -1
- package/contract/default.js +20 -21
- package/contract/index.js +10 -6
- package/dist/account/default.d.ts +2 -6
- package/dist/account/default.js +2 -0
- package/dist/account/index.js +5 -1
- package/dist/account/interface.d.ts +3 -3
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/contract/default.d.ts +1 -1
- package/dist/contract/default.js +18 -18
- package/dist/contract/index.js +5 -1
- package/dist/index.js +5 -1
- package/dist/provider/default.d.ts +11 -4
- package/dist/provider/default.js +29 -8
- package/dist/provider/index.js +5 -1
- package/dist/provider/interface.d.ts +9 -1
- package/dist/provider/utils.js +5 -5
- package/dist/signer/index.js +5 -1
- package/dist/types/account.d.ts +6 -0
- package/dist/types/api.d.ts +10 -2
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +6 -1
- package/dist/types/lib.d.ts +4 -1
- package/dist/utils/ellipticCurve.js +1 -1
- package/dist/utils/encode.js +1 -1
- package/dist/utils/hash.js +1 -1
- package/dist/utils/number.js +8 -4
- package/dist/utils/shortString.js +2 -2
- package/dist/utils/typedData/index.js +8 -4
- package/index.js +10 -6
- package/package.json +30 -28
- package/provider/default.d.ts +11 -3
- package/provider/default.js +31 -12
- package/provider/index.js +10 -6
- package/provider/interface.d.ts +9 -1
- package/provider/utils.js +5 -5
- package/signer/index.js +10 -6
- package/src/account/default.ts +3 -6
- package/src/account/interface.ts +5 -3
- package/src/constants.ts +1 -0
- package/src/provider/default.ts +33 -6
- package/src/provider/interface.ts +9 -1
- package/src/types/account.ts +7 -0
- package/src/types/api.ts +11 -2
- package/src/types/index.ts +1 -0
- package/src/types/lib.ts +5 -1
- package/types/account.d.ts +6 -0
- package/types/api.d.ts +13 -2
- package/types/index.d.ts +1 -0
- package/types/index.js +11 -6
- package/types/lib.d.ts +4 -1
- package/utils/ellipticCurve.js +1 -1
- package/utils/encode.js +1 -1
- package/utils/hash.js +1 -1
- package/utils/number.js +13 -9
- package/utils/shortString.js +2 -2
- package/utils/typedData/index.js +15 -13
- package/www/docs/API/provider.md +20 -3
- package/www/guides/account.md +21 -7
- package/www/guides/erc20.md +15 -27
- package/__tests__/accountContract.test.ts +0 -110
package/dist/types/api.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ export declare type Endpoints = {
|
|
|
44
44
|
get_storage_at: {
|
|
45
45
|
QUERY: {
|
|
46
46
|
contractAddress: string;
|
|
47
|
-
key:
|
|
47
|
+
key: BigNumberish;
|
|
48
48
|
blockIdentifier: BlockIdentifier;
|
|
49
49
|
};
|
|
50
50
|
REQUEST: never;
|
|
@@ -84,6 +84,13 @@ export declare type GetContractAddressesResponse = {
|
|
|
84
84
|
Starknet: string;
|
|
85
85
|
GpsStatementVerifier: string;
|
|
86
86
|
};
|
|
87
|
+
export declare type DeclareTransaction = {
|
|
88
|
+
type: 'DECLARE';
|
|
89
|
+
contract_class: CompressedCompiledContract;
|
|
90
|
+
nonce: BigNumberish;
|
|
91
|
+
sender_address: BigNumberish;
|
|
92
|
+
signature: Signature;
|
|
93
|
+
};
|
|
87
94
|
export declare type DeployTransaction = {
|
|
88
95
|
type: 'DEPLOY';
|
|
89
96
|
contract_definition: CompressedCompiledContract;
|
|
@@ -127,7 +134,7 @@ export declare type ExecutionResources = {
|
|
|
127
134
|
n_memory_holes: number;
|
|
128
135
|
};
|
|
129
136
|
export declare type CallContractTransaction = Omit<InvokeFunctionTransaction, 'type' | 'entry_point_type' | 'nonce'>;
|
|
130
|
-
export declare type Transaction = DeployTransaction | InvokeFunctionTransaction;
|
|
137
|
+
export declare type Transaction = DeclareTransaction | DeployTransaction | InvokeFunctionTransaction;
|
|
131
138
|
export declare type CallContractResponse = {
|
|
132
139
|
result: string[];
|
|
133
140
|
};
|
|
@@ -196,6 +203,7 @@ export declare type AddTransactionResponse = {
|
|
|
196
203
|
code: TransactionStatus;
|
|
197
204
|
transaction_hash: string;
|
|
198
205
|
address?: string;
|
|
206
|
+
class_hash?: string;
|
|
199
207
|
};
|
|
200
208
|
export declare type TransactionReceiptResponse = {
|
|
201
209
|
status: Status;
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -14,3 +18,4 @@ __exportStar(require("./lib"), exports);
|
|
|
14
18
|
__exportStar(require("./api"), exports);
|
|
15
19
|
__exportStar(require("./signer"), exports);
|
|
16
20
|
__exportStar(require("./contract"), exports);
|
|
21
|
+
__exportStar(require("./account"), exports);
|
package/dist/types/lib.d.ts
CHANGED
|
@@ -8,6 +8,9 @@ export declare type DeployContractPayload = {
|
|
|
8
8
|
constructorCalldata?: RawCalldata;
|
|
9
9
|
addressSalt?: BigNumberish;
|
|
10
10
|
};
|
|
11
|
+
export declare type DeclareContractPayload = {
|
|
12
|
+
contract: CompiledContract | string;
|
|
13
|
+
};
|
|
11
14
|
export declare type Invocation = {
|
|
12
15
|
contractAddress: string;
|
|
13
16
|
entrypoint: string;
|
|
@@ -22,7 +25,7 @@ export declare type InvocationsDetails = {
|
|
|
22
25
|
};
|
|
23
26
|
export declare type Status = 'NOT_RECEIVED' | 'RECEIVED' | 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
|
|
24
27
|
export declare type TransactionStatus = 'TRANSACTION_RECEIVED';
|
|
25
|
-
export declare type Type = 'DEPLOY' | 'INVOKE_FUNCTION';
|
|
28
|
+
export declare type Type = 'DECLARE' | 'DEPLOY' | 'INVOKE_FUNCTION';
|
|
26
29
|
export declare type EntryPointType = 'EXTERNAL';
|
|
27
30
|
export declare type CompressedProgram = string;
|
|
28
31
|
export declare type AbiEntry = {
|
|
@@ -51,7 +51,7 @@ function fixMessage(msg) {
|
|
|
51
51
|
}
|
|
52
52
|
(0, minimalistic_assert_1.default)(pureHex.length === 63);
|
|
53
53
|
// In this case delta will be 4 so we perform a shift-left of 4 bits by adding a ZERO_BN.
|
|
54
|
-
return pureHex
|
|
54
|
+
return "".concat(pureHex, "0");
|
|
55
55
|
}
|
|
56
56
|
exports.genKeyPair = exports.ec.genKeyPair.bind(exports.ec);
|
|
57
57
|
function getKeyPair(pk) {
|
package/dist/utils/encode.js
CHANGED
|
@@ -50,7 +50,7 @@ function removeHexPrefix(hex) {
|
|
|
50
50
|
}
|
|
51
51
|
exports.removeHexPrefix = removeHexPrefix;
|
|
52
52
|
function addHexPrefix(hex) {
|
|
53
|
-
return "0x"
|
|
53
|
+
return "0x".concat(removeHexPrefix(hex));
|
|
54
54
|
}
|
|
55
55
|
exports.addHexPrefix = addHexPrefix;
|
|
56
56
|
function padString(str, length, left, padding) {
|
package/dist/utils/hash.js
CHANGED
|
@@ -70,7 +70,7 @@ function pedersen(input) {
|
|
|
70
70
|
var point = constantPoints[0];
|
|
71
71
|
for (var i = 0; i < input.length; i += 1) {
|
|
72
72
|
var x = (0, number_1.toBN)(input[i]);
|
|
73
|
-
(0, minimalistic_assert_1.default)(x.gte(constants_1.ZERO) && x.lt((0, number_1.toBN)((0, encode_1.addHexPrefix)(constants_1.FIELD_PRIME))), "Invalid input: "
|
|
73
|
+
(0, minimalistic_assert_1.default)(x.gte(constants_1.ZERO) && x.lt((0, number_1.toBN)((0, encode_1.addHexPrefix)(constants_1.FIELD_PRIME))), "Invalid input: ".concat(input[i]));
|
|
74
74
|
for (var j = 0; j < 252; j += 1) {
|
|
75
75
|
var pt = constantPoints[2 + i * 252 + j];
|
|
76
76
|
(0, minimalistic_assert_1.default)(!point.getX().eq(pt.getX()));
|
package/dist/utils/number.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -41,7 +45,7 @@ function toHex(number) {
|
|
|
41
45
|
}
|
|
42
46
|
exports.toHex = toHex;
|
|
43
47
|
function hexToDecimalString(hex) {
|
|
44
|
-
return toBN("0x"
|
|
48
|
+
return toBN("0x".concat(hex.replace(/^0x/, ''))).toString();
|
|
45
49
|
}
|
|
46
50
|
exports.hexToDecimalString = hexToDecimalString;
|
|
47
51
|
function toFelt(num) {
|
|
@@ -59,9 +63,9 @@ exports.toFelt = toFelt;
|
|
|
59
63
|
*/
|
|
60
64
|
function assertInRange(input, lowerBound, upperBound, inputName) {
|
|
61
65
|
if (inputName === void 0) { inputName = ''; }
|
|
62
|
-
var messageSuffix = inputName === '' ? 'invalid length' : "invalid "
|
|
66
|
+
var messageSuffix = inputName === '' ? 'invalid length' : "invalid ".concat(inputName, " length");
|
|
63
67
|
var inputBn = toBN(input);
|
|
64
|
-
(0, minimalistic_assert_1.default)(inputBn.gte(toBN(lowerBound)) && inputBn.lt(toBN(upperBound)), "Message not signable, "
|
|
68
|
+
(0, minimalistic_assert_1.default)(inputBn.gte(toBN(lowerBound)) && inputBn.lt(toBN(upperBound)), "Message not signable, ".concat(messageSuffix, "."));
|
|
65
69
|
}
|
|
66
70
|
exports.assertInRange = assertInRange;
|
|
67
71
|
function bigNumberishArrayToDecimalStringArray(rawCalldata) {
|
|
@@ -14,9 +14,9 @@ function isShortString(str) {
|
|
|
14
14
|
exports.isShortString = isShortString;
|
|
15
15
|
function encodeShortString(str) {
|
|
16
16
|
if (!isASCII(str))
|
|
17
|
-
throw new Error(str
|
|
17
|
+
throw new Error("".concat(str, " is not an ASCII string"));
|
|
18
18
|
if (!isShortString(str))
|
|
19
|
-
throw new Error(str
|
|
19
|
+
throw new Error("".concat(str, " is too long"));
|
|
20
20
|
return (0, encode_1.addHexPrefix)(str.replace(/./g, function (char) { return char.charCodeAt(0).toString(16); }));
|
|
21
21
|
}
|
|
22
22
|
exports.encodeShortString = encodeShortString;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -49,7 +53,7 @@ function getHex(value) {
|
|
|
49
53
|
if (typeof value === 'string') {
|
|
50
54
|
return (0, number_1.toHex)((0, number_1.toBN)((0, shortString_1.encodeShortString)(value)));
|
|
51
55
|
}
|
|
52
|
-
throw new Error("Invalid BigNumberish: "
|
|
56
|
+
throw new Error("Invalid BigNumberish: ".concat(value));
|
|
53
57
|
}
|
|
54
58
|
}
|
|
55
59
|
/**
|
|
@@ -90,7 +94,7 @@ var encodeType = function (typedData, type) {
|
|
|
90
94
|
var types = __spreadArray([primary], __read(dependencies.sort()), false);
|
|
91
95
|
return types
|
|
92
96
|
.map(function (dependency) {
|
|
93
|
-
return dependency
|
|
97
|
+
return "".concat(dependency, "(").concat(typedData.types[dependency].map(function (t) { return "".concat(t.name, ":").concat(t.type); }), ")");
|
|
94
98
|
})
|
|
95
99
|
.join('');
|
|
96
100
|
};
|
|
@@ -137,7 +141,7 @@ var encodeData = function (typedData, type, data) {
|
|
|
137
141
|
var _a = __read(typedData.types[type].reduce(function (_a, field) {
|
|
138
142
|
var _b = __read(_a, 2), ts = _b[0], vs = _b[1];
|
|
139
143
|
if (data[field.name] === undefined || data[field.name] === null) {
|
|
140
|
-
throw new Error("Cannot encode data: missing data for '"
|
|
144
|
+
throw new Error("Cannot encode data: missing data for '".concat(field.name, "'"));
|
|
141
145
|
}
|
|
142
146
|
var value = data[field.name];
|
|
143
147
|
var _c = __read(encodeValue(typedData, field.type, value), 2), t = _c[0], encodedValue = _c[1];
|
package/index.js
CHANGED
|
@@ -4,12 +4,16 @@ var __createBinding =
|
|
|
4
4
|
(Object.create
|
|
5
5
|
? function (o, m, k, k2) {
|
|
6
6
|
if (k2 === undefined) k2 = k;
|
|
7
|
-
Object.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return m[k];
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
13
17
|
}
|
|
14
18
|
: function (o, m, k, k2) {
|
|
15
19
|
if (k2 === undefined) k2 = k;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starknet",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.14.0",
|
|
4
4
|
"description": "JavaScript library for StarkNet",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -27,45 +27,47 @@
|
|
|
27
27
|
"author": "Sean Han",
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@babel/
|
|
31
|
-
"@babel/preset-
|
|
32
|
-
"@
|
|
33
|
-
"@commitlint/
|
|
34
|
-
"@
|
|
35
|
-
"@semantic-release/
|
|
36
|
-
"@semantic-release/
|
|
37
|
-
"@semantic-release/
|
|
38
|
-
"@semantic-release/
|
|
39
|
-
"@
|
|
40
|
-
"@types/
|
|
30
|
+
"@babel/plugin-transform-modules-commonjs": "^7.18.2",
|
|
31
|
+
"@babel/preset-env": "^7.18.2",
|
|
32
|
+
"@babel/preset-typescript": "^7.17.12",
|
|
33
|
+
"@commitlint/cli": "^17.0.2",
|
|
34
|
+
"@commitlint/config-conventional": "^17.0.2",
|
|
35
|
+
"@semantic-release/changelog": "^6.0.1",
|
|
36
|
+
"@semantic-release/commit-analyzer": "^9.0.2",
|
|
37
|
+
"@semantic-release/git": "^10.0.1",
|
|
38
|
+
"@semantic-release/npm": "^9.0.1",
|
|
39
|
+
"@semantic-release/release-notes-generator": "^10.0.3",
|
|
40
|
+
"@types/elliptic": "^6.4.14",
|
|
41
|
+
"@types/jest": "^28.1.1",
|
|
41
42
|
"@types/json-bigint": "^1.0.1",
|
|
42
43
|
"@types/minimalistic-assert": "^1.0.1",
|
|
43
|
-
"@types/pako": "^
|
|
44
|
+
"@types/pako": "^2.0.0",
|
|
44
45
|
"@types/url-join": "^4.0.1",
|
|
45
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
46
|
-
"@typescript-eslint/parser": "^5.
|
|
47
|
-
"eslint": "^
|
|
48
|
-
"eslint-config-airbnb-base": "^
|
|
49
|
-
"eslint-config-airbnb-typescript": "^
|
|
50
|
-
"eslint-config-prettier": "^8.
|
|
51
|
-
"eslint-plugin-import": "^2.
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "^5.28.0",
|
|
47
|
+
"@typescript-eslint/parser": "^5.28.0",
|
|
48
|
+
"eslint": "^8.17.0",
|
|
49
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
50
|
+
"eslint-config-airbnb-typescript": "^17.0.0",
|
|
51
|
+
"eslint-config-prettier": "^8.5.0",
|
|
52
|
+
"eslint-plugin-import": "^2.26.0",
|
|
52
53
|
"eslint-plugin-prettier": "^4.0.0",
|
|
53
|
-
"husky": "^
|
|
54
|
+
"husky": "^8.0.1",
|
|
54
55
|
"import-sort-style-module": "^6.0.0",
|
|
55
|
-
"jest": "^
|
|
56
|
-
"
|
|
57
|
-
"
|
|
56
|
+
"jest": "^28.1.1",
|
|
57
|
+
"jest-environment-jsdom": "^28.1.1",
|
|
58
|
+
"lint-staged": "^13.0.1",
|
|
59
|
+
"prettier": "^2.7.0",
|
|
58
60
|
"prettier-plugin-import-sort": "^0.0.7",
|
|
59
|
-
"typedoc": "^0.22.
|
|
60
|
-
"typescript": "^4.
|
|
61
|
+
"typedoc": "^0.22.17",
|
|
62
|
+
"typescript": "^4.7.3",
|
|
61
63
|
"whatwg-fetch": "^3.6.2"
|
|
62
64
|
},
|
|
63
65
|
"dependencies": {
|
|
64
66
|
"@ethersproject/bytes": "^5.6.1",
|
|
65
|
-
"bn.js": "^5.2.
|
|
67
|
+
"bn.js": "^5.2.1",
|
|
66
68
|
"cross-fetch": "^3.1.5",
|
|
67
69
|
"elliptic": "^6.5.4",
|
|
68
|
-
"ethereum-cryptography": "^0.
|
|
70
|
+
"ethereum-cryptography": "^1.0.3",
|
|
69
71
|
"fetch-intercept": "^2.4.0",
|
|
70
72
|
"hash.js": "^1.1.7",
|
|
71
73
|
"json-bigint": "^1.0.0",
|
package/provider/default.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
AddTransactionResponse,
|
|
5
5
|
Call,
|
|
6
6
|
CallContractResponse,
|
|
7
|
+
DeclareContractPayload,
|
|
7
8
|
DeployContractPayload,
|
|
8
9
|
Endpoints,
|
|
9
10
|
GetBlockResponse,
|
|
@@ -109,7 +110,7 @@ export declare class Provider implements ProviderInterface {
|
|
|
109
110
|
*/
|
|
110
111
|
getStorageAt(
|
|
111
112
|
contractAddress: string,
|
|
112
|
-
key:
|
|
113
|
+
key: BigNumberish,
|
|
113
114
|
blockIdentifier?: BlockIdentifier
|
|
114
115
|
): Promise<object>;
|
|
115
116
|
/**
|
|
@@ -122,9 +123,9 @@ export declare class Provider implements ProviderInterface {
|
|
|
122
123
|
*/
|
|
123
124
|
getTransactionStatus(txHash: BigNumberish): Promise<GetTransactionStatusResponse>;
|
|
124
125
|
/**
|
|
125
|
-
* Gets the transaction receipt from a tx hash
|
|
126
|
+
* Gets the transaction receipt from a tx hash.
|
|
126
127
|
*
|
|
127
|
-
* [Reference] (https://github.com/starkware-libs/cairo-lang/blob/
|
|
128
|
+
* [Reference] (https://github.com/starkware-libs/cairo-lang/blob/167b28bcd940fd25ea3816204fa882a0b0a49603/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L183)
|
|
128
129
|
*
|
|
129
130
|
* @param txHash
|
|
130
131
|
* @returns the transaction receipt object
|
|
@@ -147,6 +148,13 @@ export declare class Provider implements ProviderInterface {
|
|
|
147
148
|
* @returns the transaction trace
|
|
148
149
|
*/
|
|
149
150
|
getTransactionTrace(txHash: BigNumberish): Promise<GetTransactionTraceResponse>;
|
|
151
|
+
/**
|
|
152
|
+
* Declare a given compiled contract (json) on starknet
|
|
153
|
+
*
|
|
154
|
+
* @param contract - a json object containing the compiled contract
|
|
155
|
+
* @returns a confirmation of sending a transaction on the starknet contract
|
|
156
|
+
*/
|
|
157
|
+
declareContract(payload: DeclareContractPayload): Promise<AddTransactionResponse>;
|
|
150
158
|
/**
|
|
151
159
|
* Deploys a given compiled contract (json) to starknet
|
|
152
160
|
*
|
package/provider/default.js
CHANGED
|
@@ -184,7 +184,7 @@ var interface_1 = require('./interface');
|
|
|
184
184
|
var utils_1 = require('./utils');
|
|
185
185
|
function wait(delay) {
|
|
186
186
|
return new Promise(function (res) {
|
|
187
|
-
|
|
187
|
+
setTimeout(res, delay);
|
|
188
188
|
});
|
|
189
189
|
}
|
|
190
190
|
function isEmptyQueryObject(obj) {
|
|
@@ -242,7 +242,7 @@ var Provider = /** @class */ (function () {
|
|
|
242
242
|
}
|
|
243
243
|
} catch (_a) {
|
|
244
244
|
// eslint-disable-next-line no-console
|
|
245
|
-
console.error('Could not parse baseUrl: '
|
|
245
|
+
console.error('Could not parse baseUrl: '.concat(baseUrl));
|
|
246
246
|
}
|
|
247
247
|
return constants_1.StarknetChainId.TESTNET;
|
|
248
248
|
};
|
|
@@ -264,12 +264,12 @@ var Provider = /** @class */ (function () {
|
|
|
264
264
|
key = _b[0],
|
|
265
265
|
value = _b[1];
|
|
266
266
|
if (key === 'blockIdentifier') {
|
|
267
|
-
return ''
|
|
267
|
+
return ''.concat((0, utils_1.getFormattedBlockIdentifier)(value));
|
|
268
268
|
}
|
|
269
|
-
return key
|
|
269
|
+
return ''.concat(key, '=').concat(value);
|
|
270
270
|
})
|
|
271
271
|
.join('&');
|
|
272
|
-
return '?'
|
|
272
|
+
return '?'.concat(queryString);
|
|
273
273
|
};
|
|
274
274
|
Provider.prototype.getHeaders = function (method) {
|
|
275
275
|
if (method === 'POST') {
|
|
@@ -478,9 +478,9 @@ var Provider = /** @class */ (function () {
|
|
|
478
478
|
});
|
|
479
479
|
};
|
|
480
480
|
/**
|
|
481
|
-
* Gets the transaction receipt from a tx hash
|
|
481
|
+
* Gets the transaction receipt from a tx hash.
|
|
482
482
|
*
|
|
483
|
-
* [Reference] (https://github.com/starkware-libs/cairo-lang/blob/
|
|
483
|
+
* [Reference] (https://github.com/starkware-libs/cairo-lang/blob/167b28bcd940fd25ea3816204fa882a0b0a49603/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L183)
|
|
484
484
|
*
|
|
485
485
|
* @param txHash
|
|
486
486
|
* @returns the transaction receipt object
|
|
@@ -536,6 +536,26 @@ var Provider = /** @class */ (function () {
|
|
|
536
536
|
});
|
|
537
537
|
});
|
|
538
538
|
};
|
|
539
|
+
/**
|
|
540
|
+
* Declare a given compiled contract (json) on starknet
|
|
541
|
+
*
|
|
542
|
+
* @param contract - a json object containing the compiled contract
|
|
543
|
+
* @returns a confirmation of sending a transaction on the starknet contract
|
|
544
|
+
*/
|
|
545
|
+
Provider.prototype.declareContract = function (payload) {
|
|
546
|
+
var parsedContract =
|
|
547
|
+
typeof payload.contract === 'string' ? (0, json_1.parse)(payload.contract) : payload.contract;
|
|
548
|
+
var contractDefinition = __assign(__assign({}, parsedContract), {
|
|
549
|
+
program: (0, stark_1.compressProgram)(parsedContract.program),
|
|
550
|
+
});
|
|
551
|
+
return this.fetchEndpoint('add_transaction', undefined, {
|
|
552
|
+
type: 'DECLARE',
|
|
553
|
+
contract_class: contractDefinition,
|
|
554
|
+
nonce: (0, number_1.toHex)(constants_1.ZERO),
|
|
555
|
+
signature: [],
|
|
556
|
+
sender_address: (0, number_1.toHex)(constants_1.ONE),
|
|
557
|
+
});
|
|
558
|
+
};
|
|
539
559
|
/**
|
|
540
560
|
* Deploys a given compiled contract (json) to starknet
|
|
541
561
|
*
|
|
@@ -609,11 +629,10 @@ var Provider = /** @class */ (function () {
|
|
|
609
629
|
onchain = true;
|
|
610
630
|
} else if (errorStates.includes(res.tx_status)) {
|
|
611
631
|
message = res.tx_failure_reason
|
|
612
|
-
?
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
res.tx_failure_reason.error_message
|
|
632
|
+
? ''
|
|
633
|
+
.concat(res.tx_status, ': ')
|
|
634
|
+
.concat(res.tx_failure_reason.code, '\n')
|
|
635
|
+
.concat(res.tx_failure_reason.error_message)
|
|
617
636
|
: res.tx_status;
|
|
618
637
|
error = new Error(message);
|
|
619
638
|
error.response = res;
|
package/provider/index.js
CHANGED
|
@@ -4,12 +4,16 @@ var __createBinding =
|
|
|
4
4
|
(Object.create
|
|
5
5
|
? function (o, m, k, k2) {
|
|
6
6
|
if (k2 === undefined) k2 = k;
|
|
7
|
-
Object.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return m[k];
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
13
17
|
}
|
|
14
18
|
: function (o, m, k, k2) {
|
|
15
19
|
if (k2 === undefined) k2 = k;
|
package/provider/interface.d.ts
CHANGED
|
@@ -75,7 +75,7 @@ export declare abstract class ProviderInterface {
|
|
|
75
75
|
*/
|
|
76
76
|
abstract getStorageAt(
|
|
77
77
|
contractAddress: string,
|
|
78
|
-
key:
|
|
78
|
+
key: BigNumberish,
|
|
79
79
|
blockIdentifier?: BlockIdentifier
|
|
80
80
|
): Promise<object>;
|
|
81
81
|
/**
|
|
@@ -96,6 +96,14 @@ export declare abstract class ProviderInterface {
|
|
|
96
96
|
* @returns the transacton object { transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? }
|
|
97
97
|
*/
|
|
98
98
|
abstract getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
|
|
99
|
+
/**
|
|
100
|
+
* Gets the transaction receipt from a tx hash.
|
|
101
|
+
*
|
|
102
|
+
* [Reference] (https://github.com/starkware-libs/cairo-lang/blob/167b28bcd940fd25ea3816204fa882a0b0a49603/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L183)
|
|
103
|
+
*
|
|
104
|
+
* @param txHash
|
|
105
|
+
* @returns the transaction receipt object
|
|
106
|
+
*/
|
|
99
107
|
abstract getTransactionReceipt(txHash: BigNumberish): Promise<TransactionReceiptResponse>;
|
|
100
108
|
/**
|
|
101
109
|
* Deploys a given compiled contract (json) to starknet
|
package/provider/utils.js
CHANGED
|
@@ -26,10 +26,10 @@ exports.formatHash = formatHash;
|
|
|
26
26
|
*/
|
|
27
27
|
function txIdentifier(txHash, txId) {
|
|
28
28
|
if (!txHash) {
|
|
29
|
-
return 'transactionId='
|
|
29
|
+
return 'transactionId='.concat(JSON.stringify(txId));
|
|
30
30
|
}
|
|
31
31
|
var hashString = formatHash(txHash);
|
|
32
|
-
return 'transactionHash='
|
|
32
|
+
return 'transactionHash='.concat(hashString);
|
|
33
33
|
}
|
|
34
34
|
exports.txIdentifier = txIdentifier;
|
|
35
35
|
/**
|
|
@@ -55,7 +55,7 @@ function getBlockIdentifier(blockIdentifier) {
|
|
|
55
55
|
return { type: 'BLOCK_NUMBER', data: parseInt(blockIdentifier, 10) };
|
|
56
56
|
}
|
|
57
57
|
if (typeof blockIdentifier === 'string') {
|
|
58
|
-
throw new Error('Invalid block identifier: '
|
|
58
|
+
throw new Error('Invalid block identifier: '.concat(blockIdentifier));
|
|
59
59
|
}
|
|
60
60
|
return { type: 'BLOCK_HASH', data: blockIdentifier };
|
|
61
61
|
}
|
|
@@ -77,8 +77,8 @@ function getFormattedBlockIdentifier(blockIdentifier) {
|
|
|
77
77
|
return '';
|
|
78
78
|
}
|
|
79
79
|
if (blockIdentifierObject.type === 'BLOCK_NUMBER') {
|
|
80
|
-
return 'blockNumber='
|
|
80
|
+
return 'blockNumber='.concat(blockIdentifierObject.data);
|
|
81
81
|
}
|
|
82
|
-
return 'blockHash='
|
|
82
|
+
return 'blockHash='.concat((0, number_1.toHex)((0, number_1.toBN)(blockIdentifierObject.data)));
|
|
83
83
|
}
|
|
84
84
|
exports.getFormattedBlockIdentifier = getFormattedBlockIdentifier;
|
package/signer/index.js
CHANGED
|
@@ -4,12 +4,16 @@ var __createBinding =
|
|
|
4
4
|
(Object.create
|
|
5
5
|
? function (o, m, k, k2) {
|
|
6
6
|
if (k2 === undefined) k2 = k;
|
|
7
|
-
Object.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return m[k];
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
13
17
|
}
|
|
14
18
|
: function (o, m, k, k2) {
|
|
15
19
|
if (k2 === undefined) k2 = k;
|
package/src/account/default.ts
CHANGED
|
@@ -2,7 +2,6 @@ import assert from 'minimalistic-assert';
|
|
|
2
2
|
|
|
3
3
|
import { ZERO } from '../constants';
|
|
4
4
|
import { Provider, ProviderInterface } from '../provider';
|
|
5
|
-
import { BlockIdentifier } from '../provider/utils';
|
|
6
5
|
import { Signer, SignerInterface } from '../signer';
|
|
7
6
|
import {
|
|
8
7
|
Abi,
|
|
@@ -15,7 +14,7 @@ import {
|
|
|
15
14
|
Signature,
|
|
16
15
|
Transaction,
|
|
17
16
|
} from '../types';
|
|
18
|
-
import { EstimateFee } from '../types/account';
|
|
17
|
+
import { EstimateFee, EstimateFeeDetails } from '../types/account';
|
|
19
18
|
import { sign } from '../utils/ellipticCurve';
|
|
20
19
|
import {
|
|
21
20
|
computeHashOnElements,
|
|
@@ -56,10 +55,7 @@ export class Account extends Provider implements AccountInterface {
|
|
|
56
55
|
|
|
57
56
|
public async estimateFee(
|
|
58
57
|
calls: Call | Call[],
|
|
59
|
-
{
|
|
60
|
-
nonce: providedNonce,
|
|
61
|
-
blockIdentifier = 'pending',
|
|
62
|
-
}: { nonce?: BigNumberish; blockIdentifier?: BlockIdentifier } = {}
|
|
58
|
+
{ nonce: providedNonce, blockIdentifier = 'pending' }: EstimateFeeDetails = {}
|
|
63
59
|
): Promise<EstimateFee> {
|
|
64
60
|
const transactions = Array.isArray(calls) ? calls : [calls];
|
|
65
61
|
const nonce = providedNonce ?? (await this.getNonce());
|
|
@@ -147,6 +143,7 @@ export class Account extends Provider implements AccountInterface {
|
|
|
147
143
|
*/
|
|
148
144
|
public async LEGACY_addTransaction(transaction: Transaction): Promise<AddTransactionResponse> {
|
|
149
145
|
if (transaction.type === 'DEPLOY') throw new Error('No DEPLOYS');
|
|
146
|
+
if (transaction.type === 'DECLARE') throw new Error('No DECLARES');
|
|
150
147
|
|
|
151
148
|
assert(
|
|
152
149
|
!transaction.signature,
|
package/src/account/interface.ts
CHANGED
|
@@ -5,11 +5,10 @@ import {
|
|
|
5
5
|
AddTransactionResponse,
|
|
6
6
|
Call,
|
|
7
7
|
DeployContractPayload,
|
|
8
|
-
Invocation,
|
|
9
8
|
InvocationsDetails,
|
|
10
9
|
Signature,
|
|
11
10
|
} from '../types';
|
|
12
|
-
import { EstimateFee } from '../types/account';
|
|
11
|
+
import { EstimateFee, EstimateFeeDetails } from '../types/account';
|
|
13
12
|
import { BigNumberish } from '../utils/number';
|
|
14
13
|
import { TypedData } from '../utils/typedData/types';
|
|
15
14
|
|
|
@@ -44,7 +43,10 @@ export abstract class AccountInterface extends ProviderInterface {
|
|
|
44
43
|
*
|
|
45
44
|
* @returns response from addTransaction
|
|
46
45
|
*/
|
|
47
|
-
public abstract estimateFee(
|
|
46
|
+
public abstract estimateFee(
|
|
47
|
+
calls: Call | Call[],
|
|
48
|
+
estimateFeeDetails?: EstimateFeeDetails
|
|
49
|
+
): Promise<EstimateFee>;
|
|
48
50
|
|
|
49
51
|
/**
|
|
50
52
|
* Invoke execute function in account contract
|
package/src/constants.ts
CHANGED
|
@@ -13,6 +13,7 @@ export enum StarknetChainId {
|
|
|
13
13
|
TESTNET = '0x534e5f474f45524c49', // encodeShortString('SN_GOERLI'),
|
|
14
14
|
}
|
|
15
15
|
export enum TransactionHashPrefix {
|
|
16
|
+
DECLARE = '0x6465636c617265', // encodeShortString('declare'),
|
|
16
17
|
DEPLOY = '0x6465706c6f79', // encodeShortString('deploy'),
|
|
17
18
|
INVOKE = '0x696e766f6b65', // encodeShortString('invoke'),
|
|
18
19
|
L1_HANDLER = '0x6c315f68616e646c6572', // encodeShortString('l1_handler'),
|