starknet 3.15.0 → 3.15.3
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 +10 -8
- package/.github/workflows/release.yml +29 -3
- package/CHANGELOG.md +22 -0
- package/__mocks__/Account.json +1182 -1164
- package/__tests__/account.test.ts +19 -8
- package/__tests__/contract.test.ts +4 -10
- package/__tests__/fixtures.ts +25 -13
- package/__tests__/jest.setup.ts +3 -0
- package/__tests__/provider.test.ts +50 -85
- package/__tests__/utils/__snapshots__/utils.browser.test.ts.snap +2 -2
- package/__tests__/utils/__snapshots__/utils.test.ts.snap +2 -2
- package/__tests__/utils/utils.browser.test.ts +3 -5
- package/__tests__/utils/utils.test.ts +3 -5
- package/dist/provider/default.js +10 -3
- package/dist/provider/utils.js +1 -1
- package/dist/types/api.d.ts +7 -3
- package/package.json +4 -2
- package/provider/default.js +12 -2
- package/provider/utils.js +1 -1
- package/src/provider/default.ts +9 -2
- package/src/provider/utils.ts +1 -1
- package/src/types/api.ts +11 -3
- package/types/api.d.ts +10 -3
- package/www/docs/API/{contractFacotry.md → contractFactory.md} +0 -0
- package/www/docs/API/utils.md +231 -0
- package/www/guides/account.md +4 -4
- package/__mocks__/ArgentAccount.json +0 -100369
- package/__mocks__/Readme.md +0 -2
|
@@ -8,21 +8,19 @@ import { constants, json, stark } from '../../src';
|
|
|
8
8
|
|
|
9
9
|
const { IS_BROWSER } = constants;
|
|
10
10
|
|
|
11
|
-
const
|
|
12
|
-
fs.readFileSync('./__mocks__/ArgentAccount.json').toString('ascii')
|
|
13
|
-
);
|
|
11
|
+
const compiledAccount = json.parse(fs.readFileSync('./__mocks__/Account.json').toString('ascii'));
|
|
14
12
|
|
|
15
13
|
test('isBrowser', () => {
|
|
16
14
|
expect(IS_BROWSER).toBe(true);
|
|
17
15
|
});
|
|
18
16
|
describe('compressProgram()', () => {
|
|
19
17
|
test('compresses a contract program', () => {
|
|
20
|
-
const compressed = stark.compressProgram(
|
|
18
|
+
const compressed = stark.compressProgram(compiledAccount.program);
|
|
21
19
|
|
|
22
20
|
expect(compressed).toMatchSnapshot();
|
|
23
21
|
});
|
|
24
22
|
test('works with strings', () => {
|
|
25
|
-
const inputProgram = json.stringify(
|
|
23
|
+
const inputProgram = json.stringify(compiledAccount.program);
|
|
26
24
|
|
|
27
25
|
const compressed = stark.compressProgram(inputProgram);
|
|
28
26
|
|
|
@@ -5,23 +5,21 @@ import { pedersen } from '../../src/utils/hash';
|
|
|
5
5
|
|
|
6
6
|
const { IS_BROWSER } = constants;
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
fs.readFileSync('./__mocks__/ArgentAccount.json').toString('ascii')
|
|
10
|
-
);
|
|
8
|
+
const compiledAccount = json.parse(fs.readFileSync('./__mocks__/Account.json').toString('ascii'));
|
|
11
9
|
|
|
12
10
|
test('isNode', () => {
|
|
13
11
|
expect(IS_BROWSER).toBe(false);
|
|
14
12
|
});
|
|
15
13
|
describe('compressProgram()', () => {
|
|
16
14
|
test('compresses a contract program', () => {
|
|
17
|
-
const inputProgram =
|
|
15
|
+
const inputProgram = compiledAccount.program;
|
|
18
16
|
|
|
19
17
|
const compressed = stark.compressProgram(inputProgram);
|
|
20
18
|
|
|
21
19
|
expect(compressed).toMatchSnapshot();
|
|
22
20
|
});
|
|
23
21
|
test('works with strings', () => {
|
|
24
|
-
const inputProgram = json.stringify(
|
|
22
|
+
const inputProgram = json.stringify(compiledAccount.program);
|
|
25
23
|
|
|
26
24
|
const compressed = stark.compressProgram(inputProgram);
|
|
27
25
|
|
package/dist/provider/default.js
CHANGED
|
@@ -67,7 +67,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
67
67
|
};
|
|
68
68
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
69
69
|
exports.Provider = void 0;
|
|
70
|
-
var cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
71
70
|
var url_join_1 = __importDefault(require("url-join"));
|
|
72
71
|
var constants_1 = require("../constants");
|
|
73
72
|
var hash_1 = require("../utils/hash");
|
|
@@ -191,12 +190,17 @@ var Provider = /** @class */ (function () {
|
|
|
191
190
|
queryString = this.getQueryString(query);
|
|
192
191
|
headers = this.getHeaders(method);
|
|
193
192
|
url = (0, url_join_1.default)(baseUrl, endpoint, queryString);
|
|
194
|
-
return [2 /*return*/, (
|
|
193
|
+
return [2 /*return*/, fetch(url, {
|
|
195
194
|
method: method,
|
|
196
195
|
body: (0, json_1.stringify)(request),
|
|
197
196
|
headers: headers,
|
|
198
197
|
})
|
|
199
|
-
.then(function (res) {
|
|
198
|
+
.then(function (res) {
|
|
199
|
+
if (res.status >= 400) {
|
|
200
|
+
throw Error(res.statusText);
|
|
201
|
+
}
|
|
202
|
+
return res.text();
|
|
203
|
+
})
|
|
200
204
|
.then(function (res) {
|
|
201
205
|
if (endpoint === 'estimate_fee') {
|
|
202
206
|
return (0, json_1.parse)(res, function (_, v) {
|
|
@@ -207,6 +211,9 @@ var Provider = /** @class */ (function () {
|
|
|
207
211
|
});
|
|
208
212
|
}
|
|
209
213
|
return (0, json_1.parse)(res);
|
|
214
|
+
})
|
|
215
|
+
.catch(function (err) {
|
|
216
|
+
throw Error("Could not ".concat(method, " from endpoint `").concat(url, "`: ").concat(err.message));
|
|
210
217
|
})];
|
|
211
218
|
});
|
|
212
219
|
});
|
package/dist/provider/utils.js
CHANGED
|
@@ -42,7 +42,7 @@ function getBlockIdentifier(blockIdentifier) {
|
|
|
42
42
|
if (blockIdentifier === 'pending') {
|
|
43
43
|
return { type: 'BLOCK_NUMBER', data: 'pending' };
|
|
44
44
|
}
|
|
45
|
-
if (typeof blockIdentifier === 'number') {
|
|
45
|
+
if (typeof blockIdentifier === 'number' || typeof blockIdentifier === 'bigint') {
|
|
46
46
|
return { type: 'BLOCK_NUMBER', data: blockIdentifier };
|
|
47
47
|
}
|
|
48
48
|
if (typeof blockIdentifier === 'string' && blockIdentifier.startsWith('0x')) {
|
package/dist/types/api.d.ts
CHANGED
|
@@ -109,6 +109,9 @@ export declare type InvokeFunctionTransaction = {
|
|
|
109
109
|
max_fee?: BigNumberish;
|
|
110
110
|
version?: BigNumberish;
|
|
111
111
|
};
|
|
112
|
+
export interface InvokeFunctionTransactionResponse extends InvokeFunctionTransaction {
|
|
113
|
+
transaction_hash: string;
|
|
114
|
+
}
|
|
112
115
|
export declare type InvokeFunctionTrace = {
|
|
113
116
|
caller_address: string;
|
|
114
117
|
contract_address: string;
|
|
@@ -135,6 +138,7 @@ export declare type ExecutionResources = {
|
|
|
135
138
|
};
|
|
136
139
|
export declare type CallContractTransaction = Omit<InvokeFunctionTransaction, 'type' | 'entry_point_type' | 'nonce'>;
|
|
137
140
|
export declare type Transaction = DeclareTransaction | DeployTransaction | InvokeFunctionTransaction;
|
|
141
|
+
export declare type TransactionResponse = DeclareTransaction | DeployTransaction | InvokeFunctionTransactionResponse;
|
|
138
142
|
export declare type CallContractResponse = {
|
|
139
143
|
result: string[];
|
|
140
144
|
};
|
|
@@ -143,7 +147,7 @@ export declare type GetBlockResponse = {
|
|
|
143
147
|
state_root: string;
|
|
144
148
|
block_hash: string;
|
|
145
149
|
transactions: {
|
|
146
|
-
[txHash: string]:
|
|
150
|
+
[txHash: string]: TransactionResponse;
|
|
147
151
|
};
|
|
148
152
|
timestamp: number;
|
|
149
153
|
transaction_receipts: {
|
|
@@ -193,7 +197,7 @@ export declare type GetTransactionTraceResponse = {
|
|
|
193
197
|
};
|
|
194
198
|
export declare type SuccessfulTransactionResponse = {
|
|
195
199
|
status: Status;
|
|
196
|
-
transaction:
|
|
200
|
+
transaction: TransactionResponse;
|
|
197
201
|
block_hash: string;
|
|
198
202
|
block_number: BlockNumber;
|
|
199
203
|
transaction_index: number;
|
|
@@ -204,7 +208,7 @@ export declare type FailedTransactionResponse = {
|
|
|
204
208
|
code: string;
|
|
205
209
|
error_message: string;
|
|
206
210
|
};
|
|
207
|
-
transaction:
|
|
211
|
+
transaction: TransactionResponse;
|
|
208
212
|
};
|
|
209
213
|
export declare type GetTransactionResponse = SuccessfulTransactionResponse | FailedTransactionResponse;
|
|
210
214
|
export declare type AddTransactionResponse = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starknet",
|
|
3
|
-
"version": "3.15.
|
|
3
|
+
"version": "3.15.3",
|
|
4
4
|
"description": "JavaScript library for StarkNet",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -43,14 +43,17 @@
|
|
|
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",
|
|
46
47
|
"@typescript-eslint/eslint-plugin": "^5.28.0",
|
|
47
48
|
"@typescript-eslint/parser": "^5.28.0",
|
|
49
|
+
"cross-fetch": "^3.1.5",
|
|
48
50
|
"eslint": "^8.17.0",
|
|
49
51
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
50
52
|
"eslint-config-airbnb-typescript": "^17.0.0",
|
|
51
53
|
"eslint-config-prettier": "^8.5.0",
|
|
52
54
|
"eslint-plugin-import": "^2.26.0",
|
|
53
55
|
"eslint-plugin-prettier": "^4.0.0",
|
|
56
|
+
"fetch-intercept": "^2.4.0",
|
|
54
57
|
"husky": "^8.0.1",
|
|
55
58
|
"import-sort-style-module": "^6.0.0",
|
|
56
59
|
"jest": "^28.1.1",
|
|
@@ -68,7 +71,6 @@
|
|
|
68
71
|
"cross-fetch": "^3.1.5",
|
|
69
72
|
"elliptic": "^6.5.4",
|
|
70
73
|
"ethereum-cryptography": "^1.0.3",
|
|
71
|
-
"fetch-intercept": "^2.4.0",
|
|
72
74
|
"hash.js": "^1.1.7",
|
|
73
75
|
"json-bigint": "^1.0.0",
|
|
74
76
|
"minimalistic-assert": "^1.0.1",
|
package/provider/default.js
CHANGED
|
@@ -173,7 +173,6 @@ var __importDefault =
|
|
|
173
173
|
};
|
|
174
174
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
175
175
|
exports.Provider = void 0;
|
|
176
|
-
var cross_fetch_1 = __importDefault(require('cross-fetch'));
|
|
177
176
|
var url_join_1 = __importDefault(require('url-join'));
|
|
178
177
|
var constants_1 = require('../constants');
|
|
179
178
|
var hash_1 = require('../utils/hash');
|
|
@@ -308,12 +307,15 @@ var Provider = /** @class */ (function () {
|
|
|
308
307
|
url = (0, url_join_1.default)(baseUrl, endpoint, queryString);
|
|
309
308
|
return [
|
|
310
309
|
2 /*return*/,
|
|
311
|
-
(
|
|
310
|
+
fetch(url, {
|
|
312
311
|
method: method,
|
|
313
312
|
body: (0, json_1.stringify)(request),
|
|
314
313
|
headers: headers,
|
|
315
314
|
})
|
|
316
315
|
.then(function (res) {
|
|
316
|
+
if (res.status >= 400) {
|
|
317
|
+
throw Error(res.statusText);
|
|
318
|
+
}
|
|
317
319
|
return res.text();
|
|
318
320
|
})
|
|
319
321
|
.then(function (res) {
|
|
@@ -326,6 +328,14 @@ var Provider = /** @class */ (function () {
|
|
|
326
328
|
});
|
|
327
329
|
}
|
|
328
330
|
return (0, json_1.parse)(res);
|
|
331
|
+
})
|
|
332
|
+
.catch(function (err) {
|
|
333
|
+
throw Error(
|
|
334
|
+
'Could not '
|
|
335
|
+
.concat(method, ' from endpoint `')
|
|
336
|
+
.concat(url, '`: ')
|
|
337
|
+
.concat(err.message)
|
|
338
|
+
);
|
|
329
339
|
}),
|
|
330
340
|
];
|
|
331
341
|
});
|
package/provider/utils.js
CHANGED
|
@@ -45,7 +45,7 @@ function getBlockIdentifier(blockIdentifier) {
|
|
|
45
45
|
if (blockIdentifier === 'pending') {
|
|
46
46
|
return { type: 'BLOCK_NUMBER', data: 'pending' };
|
|
47
47
|
}
|
|
48
|
-
if (typeof blockIdentifier === 'number') {
|
|
48
|
+
if (typeof blockIdentifier === 'number' || typeof blockIdentifier === 'bigint') {
|
|
49
49
|
return { type: 'BLOCK_NUMBER', data: blockIdentifier };
|
|
50
50
|
}
|
|
51
51
|
if (typeof blockIdentifier === 'string' && blockIdentifier.startsWith('0x')) {
|
package/src/provider/default.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import fetch from 'cross-fetch';
|
|
2
1
|
import urljoin from 'url-join';
|
|
3
2
|
|
|
4
3
|
import { ONE, StarknetChainId, ZERO } from '../constants';
|
|
@@ -159,7 +158,12 @@ export class Provider implements ProviderInterface {
|
|
|
159
158
|
body: stringify(request),
|
|
160
159
|
headers,
|
|
161
160
|
})
|
|
162
|
-
.then((res) =>
|
|
161
|
+
.then((res) => {
|
|
162
|
+
if (res.status >= 400) {
|
|
163
|
+
throw Error(res.statusText);
|
|
164
|
+
}
|
|
165
|
+
return res.text();
|
|
166
|
+
})
|
|
163
167
|
.then((res) => {
|
|
164
168
|
if (endpoint === 'estimate_fee') {
|
|
165
169
|
return parse(res, (_, v) => {
|
|
@@ -170,6 +174,9 @@ export class Provider implements ProviderInterface {
|
|
|
170
174
|
});
|
|
171
175
|
}
|
|
172
176
|
return parse(res) as Endpoints[T]['RESPONSE'];
|
|
177
|
+
})
|
|
178
|
+
.catch((err) => {
|
|
179
|
+
throw Error(`Could not ${method} from endpoint \`${url}\`: ${err.message}`);
|
|
173
180
|
});
|
|
174
181
|
}
|
|
175
182
|
|
package/src/provider/utils.ts
CHANGED
|
@@ -49,7 +49,7 @@ export function getBlockIdentifier(blockIdentifier: BlockIdentifier): BlockIdent
|
|
|
49
49
|
if (blockIdentifier === 'pending') {
|
|
50
50
|
return { type: 'BLOCK_NUMBER', data: 'pending' };
|
|
51
51
|
}
|
|
52
|
-
if (typeof blockIdentifier === 'number') {
|
|
52
|
+
if (typeof blockIdentifier === 'number' || typeof blockIdentifier === 'bigint') {
|
|
53
53
|
return { type: 'BLOCK_NUMBER', data: blockIdentifier };
|
|
54
54
|
}
|
|
55
55
|
if (typeof blockIdentifier === 'string' && blockIdentifier.startsWith('0x')) {
|
package/src/types/api.ts
CHANGED
|
@@ -125,6 +125,10 @@ export type InvokeFunctionTransaction = {
|
|
|
125
125
|
version?: BigNumberish;
|
|
126
126
|
};
|
|
127
127
|
|
|
128
|
+
export interface InvokeFunctionTransactionResponse extends InvokeFunctionTransaction {
|
|
129
|
+
transaction_hash: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
128
132
|
export type InvokeFunctionTrace = {
|
|
129
133
|
caller_address: string;
|
|
130
134
|
contract_address: string;
|
|
@@ -157,6 +161,10 @@ export type CallContractTransaction = Omit<
|
|
|
157
161
|
>;
|
|
158
162
|
|
|
159
163
|
export type Transaction = DeclareTransaction | DeployTransaction | InvokeFunctionTransaction;
|
|
164
|
+
export type TransactionResponse =
|
|
165
|
+
| DeclareTransaction
|
|
166
|
+
| DeployTransaction
|
|
167
|
+
| InvokeFunctionTransactionResponse;
|
|
160
168
|
|
|
161
169
|
export type CallContractResponse = {
|
|
162
170
|
result: string[];
|
|
@@ -167,7 +175,7 @@ export type GetBlockResponse = {
|
|
|
167
175
|
state_root: string;
|
|
168
176
|
block_hash: string;
|
|
169
177
|
transactions: {
|
|
170
|
-
[txHash: string]:
|
|
178
|
+
[txHash: string]: TransactionResponse;
|
|
171
179
|
};
|
|
172
180
|
timestamp: number;
|
|
173
181
|
transaction_receipts: {
|
|
@@ -221,7 +229,7 @@ export type GetTransactionTraceResponse = {
|
|
|
221
229
|
|
|
222
230
|
export type SuccessfulTransactionResponse = {
|
|
223
231
|
status: Status;
|
|
224
|
-
transaction:
|
|
232
|
+
transaction: TransactionResponse;
|
|
225
233
|
block_hash: string;
|
|
226
234
|
block_number: BlockNumber;
|
|
227
235
|
transaction_index: number;
|
|
@@ -233,7 +241,7 @@ export type FailedTransactionResponse = {
|
|
|
233
241
|
code: string;
|
|
234
242
|
error_message: string;
|
|
235
243
|
};
|
|
236
|
-
transaction:
|
|
244
|
+
transaction: TransactionResponse;
|
|
237
245
|
};
|
|
238
246
|
|
|
239
247
|
export type GetTransactionResponse = SuccessfulTransactionResponse | FailedTransactionResponse;
|
package/types/api.d.ts
CHANGED
|
@@ -119,6 +119,9 @@ export declare type InvokeFunctionTransaction = {
|
|
|
119
119
|
max_fee?: BigNumberish;
|
|
120
120
|
version?: BigNumberish;
|
|
121
121
|
};
|
|
122
|
+
export interface InvokeFunctionTransactionResponse extends InvokeFunctionTransaction {
|
|
123
|
+
transaction_hash: string;
|
|
124
|
+
}
|
|
122
125
|
export declare type InvokeFunctionTrace = {
|
|
123
126
|
caller_address: string;
|
|
124
127
|
contract_address: string;
|
|
@@ -151,6 +154,10 @@ export declare type Transaction =
|
|
|
151
154
|
| DeclareTransaction
|
|
152
155
|
| DeployTransaction
|
|
153
156
|
| InvokeFunctionTransaction;
|
|
157
|
+
export declare type TransactionResponse =
|
|
158
|
+
| DeclareTransaction
|
|
159
|
+
| DeployTransaction
|
|
160
|
+
| InvokeFunctionTransactionResponse;
|
|
154
161
|
export declare type CallContractResponse = {
|
|
155
162
|
result: string[];
|
|
156
163
|
};
|
|
@@ -159,7 +166,7 @@ export declare type GetBlockResponse = {
|
|
|
159
166
|
state_root: string;
|
|
160
167
|
block_hash: string;
|
|
161
168
|
transactions: {
|
|
162
|
-
[txHash: string]:
|
|
169
|
+
[txHash: string]: TransactionResponse;
|
|
163
170
|
};
|
|
164
171
|
timestamp: number;
|
|
165
172
|
transaction_receipts: {
|
|
@@ -209,7 +216,7 @@ export declare type GetTransactionTraceResponse = {
|
|
|
209
216
|
};
|
|
210
217
|
export declare type SuccessfulTransactionResponse = {
|
|
211
218
|
status: Status;
|
|
212
|
-
transaction:
|
|
219
|
+
transaction: TransactionResponse;
|
|
213
220
|
block_hash: string;
|
|
214
221
|
block_number: BlockNumber;
|
|
215
222
|
transaction_index: number;
|
|
@@ -220,7 +227,7 @@ export declare type FailedTransactionResponse = {
|
|
|
220
227
|
code: string;
|
|
221
228
|
error_message: string;
|
|
222
229
|
};
|
|
223
|
-
transaction:
|
|
230
|
+
transaction: TransactionResponse;
|
|
224
231
|
};
|
|
225
232
|
export declare type GetTransactionResponse =
|
|
226
233
|
| SuccessfulTransactionResponse
|
|
File without changes
|
package/www/docs/API/utils.md
CHANGED
|
@@ -14,6 +14,8 @@ the address helpers can be imported using:
|
|
|
14
14
|
import { address } from 'starknet.js';
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
+
<br/>
|
|
18
|
+
|
|
17
19
|
### `getChecksumAddress(address: BigNumberish): string`
|
|
18
20
|
|
|
19
21
|
This function accepts an address as a `BigNumberish` and returns the checksummed address as a string.
|
|
@@ -29,6 +31,235 @@ const checksummedAddress = address.getChecksumAddress(addressToCheck);
|
|
|
29
31
|
console.log(checksummedAddress); // 0x02FD23D9182193775423497Fc0c472E156C57C69E4089a1967fb288a2D84e914
|
|
30
32
|
```
|
|
31
33
|
|
|
34
|
+
<br/>
|
|
35
|
+
|
|
32
36
|
### `validateChecksumAddress(address: string): boolean`
|
|
33
37
|
|
|
34
38
|
This function validates the checksum address. It returns true if the address is valid, false otherwise.
|
|
39
|
+
|
|
40
|
+
<hr />
|
|
41
|
+
|
|
42
|
+
## `stark`
|
|
43
|
+
|
|
44
|
+
Functions for stark specific manipulations.
|
|
45
|
+
|
|
46
|
+
<br/>
|
|
47
|
+
|
|
48
|
+
### `compressProgram(jsonProgram: Program | string): CompressedProgram`
|
|
49
|
+
|
|
50
|
+
Function to compress compiled cairo program. Accepts a json file representing the compiled cairo program and returns a compressed cairo program.
|
|
51
|
+
|
|
52
|
+
<br/>
|
|
53
|
+
|
|
54
|
+
### `randomAddress(): string`
|
|
55
|
+
|
|
56
|
+
Function that generates a random contract address.
|
|
57
|
+
|
|
58
|
+
<br/>
|
|
59
|
+
|
|
60
|
+
### `makeAddress(input: string): string`
|
|
61
|
+
|
|
62
|
+
Function that turns an incompatible address string into stark address format. Returns a string.
|
|
63
|
+
|
|
64
|
+
Example: `0xdFD0F27FCe99b50909de0bDD328Aed6eAbe76BC5` -> `0xdfd0f27fce99b50909de0bdd328aed6eabe76bc5`
|
|
65
|
+
|
|
66
|
+
<br/>
|
|
67
|
+
|
|
68
|
+
### `formatSignature(sig?: Signature): string[]`
|
|
69
|
+
|
|
70
|
+
Function that formats a Signature to BigNum and then to string array. Returns a string array.
|
|
71
|
+
|
|
72
|
+
<br/>
|
|
73
|
+
|
|
74
|
+
### `compileCalldata(args: RawArgs): Calldata`
|
|
75
|
+
|
|
76
|
+
Function that creates calldata that gets sent to the contract.
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
await this.callContract({
|
|
80
|
+
contractAddress: this.address,
|
|
81
|
+
entrypoint: 'is_valid_signature',
|
|
82
|
+
calldata: compileCalldata({
|
|
83
|
+
hash: toBN(hash).toString(),
|
|
84
|
+
signature: signature.map((x) => toBN(x).toString()),
|
|
85
|
+
}),
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
<br/>
|
|
90
|
+
|
|
91
|
+
### `estimatedFeeToMaxFee(estimatedFee: BigNumberish, overhead: number = 0.5): BN`
|
|
92
|
+
|
|
93
|
+
Function that calculates and returns maximum fee based on the previously estimated one.
|
|
94
|
+
|
|
95
|
+
Returns a BN.
|
|
96
|
+
|
|
97
|
+
<hr />
|
|
98
|
+
|
|
99
|
+
## `number`
|
|
100
|
+
|
|
101
|
+
Various number formatting functions.
|
|
102
|
+
|
|
103
|
+
`BN` is the `BigNum` representation imported from `bn.js` library.
|
|
104
|
+
|
|
105
|
+
```js
|
|
106
|
+
export type BigNumberish = string | number | BN;
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
<br/>
|
|
110
|
+
|
|
111
|
+
### `isHex(hex: string): boolean`
|
|
112
|
+
|
|
113
|
+
Check if number is in hex format.
|
|
114
|
+
|
|
115
|
+
<br/>
|
|
116
|
+
|
|
117
|
+
### `toBN(number: BigNumberish, base?: number | 'hex'): BN`
|
|
118
|
+
|
|
119
|
+
Converts BigNumberish to BN. Returns a BN.
|
|
120
|
+
|
|
121
|
+
<br/>
|
|
122
|
+
|
|
123
|
+
### `toHex(number: BN): string`
|
|
124
|
+
|
|
125
|
+
Converts BN to hex. Returns a string.
|
|
126
|
+
|
|
127
|
+
<br/>
|
|
128
|
+
|
|
129
|
+
### `hexToDecimalString(hex: string): string`
|
|
130
|
+
|
|
131
|
+
Converts hex string to decimal string.
|
|
132
|
+
|
|
133
|
+
<br/>
|
|
134
|
+
|
|
135
|
+
### `toFelt(num: BigNumberish): string`
|
|
136
|
+
|
|
137
|
+
Converts BN to Felt. Returns a string.
|
|
138
|
+
|
|
139
|
+
<br/>
|
|
140
|
+
|
|
141
|
+
### `assertInRange(input: BigNumberish, lowerBound: BigNumberish, upperBound: BigNumberish, inputName = '')`
|
|
142
|
+
|
|
143
|
+
Asserts input is equal to or greater then `lowerBound` and lower then `upperBound`. Assert message specifies inputName.
|
|
144
|
+
`input`, `lowerBound`, and `upperBound` should be of type BN.
|
|
145
|
+
`inputName` should be a string.
|
|
146
|
+
|
|
147
|
+
<br/>
|
|
148
|
+
|
|
149
|
+
### `bigNumberishArrayToDecimalStringArray(rawCalldata: BigNumberish[]): string[]`
|
|
150
|
+
|
|
151
|
+
Convert BigNumberish array to decimal array. Used for signature conversion.
|
|
152
|
+
|
|
153
|
+
``` js
|
|
154
|
+
const signature = await this.signer.signTransaction(transactions, signerDetails);
|
|
155
|
+
|
|
156
|
+
{
|
|
157
|
+
contract_address: this.address,
|
|
158
|
+
entry_point_selector: getSelectorFromName('__execute__'),
|
|
159
|
+
calldata,
|
|
160
|
+
version: toHex(version),
|
|
161
|
+
signature: bigNumberishArrayToDecimalStringArray(signature),
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
<hr />
|
|
166
|
+
|
|
167
|
+
## `uint256`
|
|
168
|
+
|
|
169
|
+
```js
|
|
170
|
+
// Represents an integer in the range [0, 2^256).
|
|
171
|
+
export interface Uint256 {
|
|
172
|
+
// The low 128 bits of the value.
|
|
173
|
+
low: BigNumberish;
|
|
174
|
+
// The high 128 bits of the value.
|
|
175
|
+
high: BigNumberish;
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
<br/>
|
|
180
|
+
|
|
181
|
+
### `uint256ToBN(uint256: Uint256): BN`
|
|
182
|
+
|
|
183
|
+
Function to convert `Uint256` to `BN` (big number), which uses the `bn.js` library.
|
|
184
|
+
|
|
185
|
+
<br/>
|
|
186
|
+
|
|
187
|
+
### `isUint256(bn: BigNumberish): boolean`
|
|
188
|
+
|
|
189
|
+
Function to check if `BN` is smaller or equal to `2**256-1`.
|
|
190
|
+
|
|
191
|
+
<br/>
|
|
192
|
+
|
|
193
|
+
### `bnToUint256(bignumber: BigNumberish): Uint256`
|
|
194
|
+
|
|
195
|
+
Function to convert `BN` to `Uint256`.
|
|
196
|
+
|
|
197
|
+
<hr />
|
|
198
|
+
|
|
199
|
+
## `hash`
|
|
200
|
+
|
|
201
|
+
Various hashing helpers.
|
|
202
|
+
|
|
203
|
+
### `starknetKeccak(value: string): BN`
|
|
204
|
+
|
|
205
|
+
Function to get the starknet keccak hash from a string. Returns starknet keccak hash as BigNumber.
|
|
206
|
+
nction to get the starknet keccak hash from a string. Returns starknet keccak hash as BigNumber.
|
|
207
|
+
|
|
208
|
+
<br/>
|
|
209
|
+
|
|
210
|
+
### `getSelectorFromName(funcName: string)`
|
|
211
|
+
|
|
212
|
+
Function to get the hex selector from a given function name. Returns hex selector of given abi function name.
|
|
213
|
+
|
|
214
|
+
<br/>
|
|
215
|
+
|
|
216
|
+
### `pedersen(input: [BigNumberish, BigNumberish])`
|
|
217
|
+
|
|
218
|
+
<br/>
|
|
219
|
+
|
|
220
|
+
Function to get the Pedersen hash for two arguments. Returns a string.
|
|
221
|
+
|
|
222
|
+
### `computeHashOnElements(data: BigNumberish[])`
|
|
223
|
+
|
|
224
|
+
<br/>
|
|
225
|
+
|
|
226
|
+
Function to compute a Pedersen hash on a array of elements. Returns a string.
|
|
227
|
+
|
|
228
|
+
<br/>
|
|
229
|
+
|
|
230
|
+
### `calculateTransactionHashCommon(txHashPrefix: TransactionHashPrefix, version: BigNumberish,contractAddress: BigNumberish, entryPointSelector: BigNumberish, calldata: BigNumberish[], maxFee: BigNumberish, chainId: StarknetChainId, additionalData: BigNumberish[] = []): string`
|
|
231
|
+
|
|
232
|
+
Calculates the transaction hash in the StarkNet network - a unique identifier of the transaction.
|
|
233
|
+
|
|
234
|
+
Called internally in `calculateDeployTransactionHash` and `calculcateTransactionHash`.
|
|
235
|
+
|
|
236
|
+
<br/>
|
|
237
|
+
|
|
238
|
+
### `calculateDeployTransactionHash(contractAddress: BigNumberish, constructorCalldata: BigNumberish[], version: BigNumberish, chainId: StarknetChainId): string`
|
|
239
|
+
|
|
240
|
+
Function that calculates the deployment transaction hash in the StarkNet network.
|
|
241
|
+
|
|
242
|
+
Internally calls `calculateTransactionHashCommon` with `TransactionHashPrefix.DEPLOY`.
|
|
243
|
+
|
|
244
|
+
<br/>
|
|
245
|
+
|
|
246
|
+
### `calculcateTransactionHash(contractAddress: BigNumberish, version: BigNumberish, entryPointSelector: BigNumberish, calldata: BigNumberish[], maxFee: BigNumberish, chainId: StarknetChainId): string`
|
|
247
|
+
|
|
248
|
+
Function that internally calls `calculateTransactionHashCommon`, with `TransactionHashPrefix.INVOKE`.
|
|
249
|
+
|
|
250
|
+
```js
|
|
251
|
+
const hashMsg = calculcateTransactionHash(
|
|
252
|
+
account,
|
|
253
|
+
transactionVersion,
|
|
254
|
+
getSelectorFromName('__execute__'),
|
|
255
|
+
calldata,
|
|
256
|
+
maxFee,
|
|
257
|
+
StarknetChainId.TESTNET
|
|
258
|
+
);
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
<br/>
|
|
262
|
+
|
|
263
|
+
### `calculateContractAddressFromHash(salt: BigNumberish, classHash: BigNumberish, constructorCalldata: RawCalldata, deployerAddress: BigNumberish)`
|
|
264
|
+
|
|
265
|
+
Function that calculates contract address from hash. Returns a string.
|
package/www/guides/account.md
CHANGED
|
@@ -39,11 +39,11 @@ const starkKeyPub = ec.getStarkKey(starkKeyPair);;
|
|
|
39
39
|
Deploy the Account contract and wait for it to be verified on StarkNet.
|
|
40
40
|
|
|
41
41
|
```javascript
|
|
42
|
-
const
|
|
43
|
-
fs.readFileSync("./
|
|
42
|
+
const compiledAccount = json.parse(
|
|
43
|
+
fs.readFileSync("./Account.json").toString("ascii")
|
|
44
44
|
);
|
|
45
45
|
const accountResponse = await defaultProvider.deployContract({
|
|
46
|
-
contract:
|
|
46
|
+
contract: compiledAccount,
|
|
47
47
|
addressSalt: starkKeyPub,
|
|
48
48
|
});
|
|
49
49
|
```
|
|
@@ -55,7 +55,7 @@ Wait for the deployment transaction to be accepted and assign the address of the
|
|
|
55
55
|
```javascript
|
|
56
56
|
await defaultProvider.waitForTransaction(accountResponse.transaction_hash);
|
|
57
57
|
const accountContract = new Contract(
|
|
58
|
-
|
|
58
|
+
compiledAccount.abi,
|
|
59
59
|
accountResponse.address
|
|
60
60
|
);
|
|
61
61
|
const initializeResponse = await accountContract.initialize(starkKeyPub, "0");
|