starknet 4.4.0 → 4.4.1
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 +6 -0
- package/__tests__/rpcProvider.test.ts +29 -2
- package/dist/provider/rpc.js +3 -3
- package/dist/utils/number.d.ts +1 -0
- package/dist/utils/number.js +5 -1
- package/package.json +1 -1
- package/provider/rpc.js +3 -3
- package/src/provider/rpc.ts +9 -4
- package/src/utils/number.ts +4 -0
- package/utils/number.d.ts +1 -0
- package/utils/number.js +5 -1
- package/www/docs/API/utils.md +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## [4.4.1](https://github.com/0xs34n/starknet.js/compare/v4.4.0...v4.4.1) (2022-09-01)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
- supply calldata as hexadecimal string array ([44cb4c5](https://github.com/0xs34n/starknet.js/commit/44cb4c5f108a2ea8fcd77147f053e068189d4f33))
|
|
6
|
+
|
|
1
7
|
# [4.4.0](https://github.com/0xs34n/starknet.js/compare/v4.3.1...v4.4.0) (2022-09-01)
|
|
2
8
|
|
|
3
9
|
### Bug Fixes
|
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
import { RpcProvider } from '../src';
|
|
2
|
-
import {
|
|
1
|
+
import { Account, RpcProvider, ec } from '../src';
|
|
2
|
+
import {
|
|
3
|
+
compiledOpenZeppelinAccount,
|
|
4
|
+
describeIfRpc,
|
|
5
|
+
getTestAccount,
|
|
6
|
+
getTestProvider,
|
|
7
|
+
} from './fixtures';
|
|
3
8
|
|
|
4
9
|
describeIfRpc('RPCProvider', () => {
|
|
5
10
|
let rpcProvider: RpcProvider;
|
|
11
|
+
let accountPublicKey: string;
|
|
6
12
|
|
|
7
13
|
beforeAll(async () => {
|
|
8
14
|
rpcProvider = getTestProvider() as RpcProvider;
|
|
15
|
+
const account = getTestAccount(rpcProvider);
|
|
16
|
+
|
|
17
|
+
expect(account).toBeInstanceOf(Account);
|
|
18
|
+
|
|
19
|
+
const accountKeyPair = ec.genKeyPair();
|
|
20
|
+
accountPublicKey = ec.getStarkKey(accountKeyPair);
|
|
9
21
|
});
|
|
10
22
|
|
|
11
23
|
describe('RPC methods', () => {
|
|
@@ -13,5 +25,20 @@ describeIfRpc('RPCProvider', () => {
|
|
|
13
25
|
const chainId = await rpcProvider.getChainId();
|
|
14
26
|
expect(chainId).toBe('0x534e5f474f45524c49');
|
|
15
27
|
});
|
|
28
|
+
|
|
29
|
+
test('deployContract', async () => {
|
|
30
|
+
const { contract_address, transaction_hash } = await rpcProvider.deployContract({
|
|
31
|
+
contract: compiledOpenZeppelinAccount,
|
|
32
|
+
constructorCalldata: [accountPublicKey],
|
|
33
|
+
addressSalt: accountPublicKey,
|
|
34
|
+
});
|
|
35
|
+
await rpcProvider.waitForTransaction(transaction_hash);
|
|
36
|
+
expect(contract_address).toBeTruthy();
|
|
37
|
+
expect(transaction_hash).toBeTruthy();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test.todo('getEstimateFee');
|
|
41
|
+
|
|
42
|
+
test.todo('invokeFunction');
|
|
16
43
|
});
|
|
17
44
|
});
|
package/dist/provider/rpc.js
CHANGED
|
@@ -217,7 +217,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
217
217
|
contract_address: invocation.contractAddress,
|
|
218
218
|
entry_point_selector: (0, hash_1.getSelectorFromName)(invocation.entrypoint),
|
|
219
219
|
calldata: (0, provider_1.parseCalldata)(invocation.calldata),
|
|
220
|
-
signature: (0, number_1.
|
|
220
|
+
signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(invocation.signature || []),
|
|
221
221
|
version: (0, number_1.toHex)((0, number_1.toBN)((invocationDetails === null || invocationDetails === void 0 ? void 0 : invocationDetails.version) || 0)),
|
|
222
222
|
},
|
|
223
223
|
blockIdentifier,
|
|
@@ -249,7 +249,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
249
249
|
contractDefinition = (0, provider_1.parseContract)(contract);
|
|
250
250
|
return [2 /*return*/, this.fetchEndpoint('starknet_addDeployTransaction', [
|
|
251
251
|
addressSalt !== null && addressSalt !== void 0 ? addressSalt : (0, stark_1.randomAddress)(),
|
|
252
|
-
(0, number_1.
|
|
252
|
+
(0, number_1.bigNumberishArrayToHexadecimalStringArray)(constructorCalldata !== null && constructorCalldata !== void 0 ? constructorCalldata : []),
|
|
253
253
|
{
|
|
254
254
|
program: contractDefinition.program,
|
|
255
255
|
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
@@ -267,7 +267,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
267
267
|
entry_point_selector: (0, hash_1.getSelectorFromName)(functionInvocation.entrypoint),
|
|
268
268
|
calldata: (0, provider_1.parseCalldata)(functionInvocation.calldata),
|
|
269
269
|
},
|
|
270
|
-
(0, number_1.
|
|
270
|
+
(0, number_1.bigNumberishArrayToHexadecimalStringArray)(functionInvocation.signature || []),
|
|
271
271
|
(0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
|
|
272
272
|
(0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
|
|
273
273
|
]).then(this.responseParser.parseInvokeFunctionResponse)];
|
package/dist/utils/number.d.ts
CHANGED
|
@@ -7,3 +7,4 @@ export declare function hexToDecimalString(hex: string): string;
|
|
|
7
7
|
export declare function toFelt(num: BigNumberish): string;
|
|
8
8
|
export declare function assertInRange(input: BigNumberish, lowerBound: BigNumberish, upperBound: BigNumberish, inputName?: string): void;
|
|
9
9
|
export declare function bigNumberishArrayToDecimalStringArray(rawCalldata: BigNumberish[]): string[];
|
|
10
|
+
export declare function bigNumberishArrayToHexadecimalStringArray(rawCalldata: BigNumberish[]): string[];
|
package/dist/utils/number.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.bigNumberishArrayToDecimalStringArray = exports.assertInRange = exports.toFelt = exports.hexToDecimalString = exports.toHex = exports.toBN = exports.isHex = void 0;
|
|
29
|
+
exports.bigNumberishArrayToHexadecimalStringArray = exports.bigNumberishArrayToDecimalStringArray = exports.assertInRange = exports.toFelt = exports.hexToDecimalString = exports.toHex = exports.toBN = exports.isHex = void 0;
|
|
30
30
|
var bn_js_1 = __importStar(require("bn.js"));
|
|
31
31
|
var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
|
|
32
32
|
var encode_1 = require("./encode");
|
|
@@ -76,3 +76,7 @@ function bigNumberishArrayToDecimalStringArray(rawCalldata) {
|
|
|
76
76
|
return rawCalldata.map(function (x) { return toBN(x).toString(10); });
|
|
77
77
|
}
|
|
78
78
|
exports.bigNumberishArrayToDecimalStringArray = bigNumberishArrayToDecimalStringArray;
|
|
79
|
+
function bigNumberishArrayToHexadecimalStringArray(rawCalldata) {
|
|
80
|
+
return rawCalldata.map(function (x) { return toHex(toBN(x)); });
|
|
81
|
+
}
|
|
82
|
+
exports.bigNumberishArrayToHexadecimalStringArray = bigNumberishArrayToHexadecimalStringArray;
|
package/package.json
CHANGED
package/provider/rpc.js
CHANGED
|
@@ -217,7 +217,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
217
217
|
contract_address: invocation.contractAddress,
|
|
218
218
|
entry_point_selector: (0, hash_1.getSelectorFromName)(invocation.entrypoint),
|
|
219
219
|
calldata: (0, provider_1.parseCalldata)(invocation.calldata),
|
|
220
|
-
signature: (0, number_1.
|
|
220
|
+
signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(invocation.signature || []),
|
|
221
221
|
version: (0, number_1.toHex)((0, number_1.toBN)((invocationDetails === null || invocationDetails === void 0 ? void 0 : invocationDetails.version) || 0)),
|
|
222
222
|
},
|
|
223
223
|
blockIdentifier,
|
|
@@ -249,7 +249,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
249
249
|
contractDefinition = (0, provider_1.parseContract)(contract);
|
|
250
250
|
return [2 /*return*/, this.fetchEndpoint('starknet_addDeployTransaction', [
|
|
251
251
|
addressSalt !== null && addressSalt !== void 0 ? addressSalt : (0, stark_1.randomAddress)(),
|
|
252
|
-
(0, number_1.
|
|
252
|
+
(0, number_1.bigNumberishArrayToHexadecimalStringArray)(constructorCalldata !== null && constructorCalldata !== void 0 ? constructorCalldata : []),
|
|
253
253
|
{
|
|
254
254
|
program: contractDefinition.program,
|
|
255
255
|
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
@@ -267,7 +267,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
267
267
|
entry_point_selector: (0, hash_1.getSelectorFromName)(functionInvocation.entrypoint),
|
|
268
268
|
calldata: (0, provider_1.parseCalldata)(functionInvocation.calldata),
|
|
269
269
|
},
|
|
270
|
-
(0, number_1.
|
|
270
|
+
(0, number_1.bigNumberishArrayToHexadecimalStringArray)(functionInvocation.signature || []),
|
|
271
271
|
(0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
|
|
272
272
|
(0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
|
|
273
273
|
]).then(this.responseParser.parseInvokeFunctionResponse)];
|
package/src/provider/rpc.ts
CHANGED
|
@@ -19,7 +19,12 @@ import { RPC } from '../types/api';
|
|
|
19
19
|
import fetch from '../utils/fetchPonyfill';
|
|
20
20
|
import { getSelectorFromName } from '../utils/hash';
|
|
21
21
|
import { stringify } from '../utils/json';
|
|
22
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
BigNumberish,
|
|
24
|
+
bigNumberishArrayToHexadecimalStringArray,
|
|
25
|
+
toBN,
|
|
26
|
+
toHex,
|
|
27
|
+
} from '../utils/number';
|
|
23
28
|
import { parseCalldata, parseContract, wait } from '../utils/provider';
|
|
24
29
|
import { RPCResponseParser } from '../utils/responseParser/rpc';
|
|
25
30
|
import { randomAddress } from '../utils/stark';
|
|
@@ -166,7 +171,7 @@ export class RpcProvider implements ProviderInterface {
|
|
|
166
171
|
contract_address: invocation.contractAddress,
|
|
167
172
|
entry_point_selector: getSelectorFromName(invocation.entrypoint),
|
|
168
173
|
calldata: parseCalldata(invocation.calldata),
|
|
169
|
-
signature:
|
|
174
|
+
signature: bigNumberishArrayToHexadecimalStringArray(invocation.signature || []),
|
|
170
175
|
version: toHex(toBN(invocationDetails?.version || 0)),
|
|
171
176
|
},
|
|
172
177
|
blockIdentifier,
|
|
@@ -197,7 +202,7 @@ export class RpcProvider implements ProviderInterface {
|
|
|
197
202
|
|
|
198
203
|
return this.fetchEndpoint('starknet_addDeployTransaction', [
|
|
199
204
|
addressSalt ?? randomAddress(),
|
|
200
|
-
|
|
205
|
+
bigNumberishArrayToHexadecimalStringArray(constructorCalldata ?? []),
|
|
201
206
|
{
|
|
202
207
|
program: contractDefinition.program,
|
|
203
208
|
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
@@ -215,7 +220,7 @@ export class RpcProvider implements ProviderInterface {
|
|
|
215
220
|
entry_point_selector: getSelectorFromName(functionInvocation.entrypoint),
|
|
216
221
|
calldata: parseCalldata(functionInvocation.calldata),
|
|
217
222
|
},
|
|
218
|
-
|
|
223
|
+
bigNumberishArrayToHexadecimalStringArray(functionInvocation.signature || []),
|
|
219
224
|
toHex(toBN(details.maxFee || 0)),
|
|
220
225
|
toHex(toBN(details.version || 0)),
|
|
221
226
|
]).then(this.responseParser.parseInvokeFunctionResponse);
|
package/src/utils/number.ts
CHANGED
|
@@ -57,3 +57,7 @@ export function assertInRange(
|
|
|
57
57
|
export function bigNumberishArrayToDecimalStringArray(rawCalldata: BigNumberish[]): string[] {
|
|
58
58
|
return rawCalldata.map((x) => toBN(x).toString(10));
|
|
59
59
|
}
|
|
60
|
+
|
|
61
|
+
export function bigNumberishArrayToHexadecimalStringArray(rawCalldata: BigNumberish[]): string[] {
|
|
62
|
+
return rawCalldata.map((x) => toHex(toBN(x)));
|
|
63
|
+
}
|
package/utils/number.d.ts
CHANGED
|
@@ -7,3 +7,4 @@ export declare function hexToDecimalString(hex: string): string;
|
|
|
7
7
|
export declare function toFelt(num: BigNumberish): string;
|
|
8
8
|
export declare function assertInRange(input: BigNumberish, lowerBound: BigNumberish, upperBound: BigNumberish, inputName?: string): void;
|
|
9
9
|
export declare function bigNumberishArrayToDecimalStringArray(rawCalldata: BigNumberish[]): string[];
|
|
10
|
+
export declare function bigNumberishArrayToHexadecimalStringArray(rawCalldata: BigNumberish[]): string[];
|
package/utils/number.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.bigNumberishArrayToDecimalStringArray = exports.assertInRange = exports.toFelt = exports.hexToDecimalString = exports.toHex = exports.toBN = exports.isHex = void 0;
|
|
29
|
+
exports.bigNumberishArrayToHexadecimalStringArray = exports.bigNumberishArrayToDecimalStringArray = exports.assertInRange = exports.toFelt = exports.hexToDecimalString = exports.toHex = exports.toBN = exports.isHex = void 0;
|
|
30
30
|
var bn_js_1 = __importStar(require("bn.js"));
|
|
31
31
|
var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
|
|
32
32
|
var encode_1 = require("./encode");
|
|
@@ -76,3 +76,7 @@ function bigNumberishArrayToDecimalStringArray(rawCalldata) {
|
|
|
76
76
|
return rawCalldata.map(function (x) { return toBN(x).toString(10); });
|
|
77
77
|
}
|
|
78
78
|
exports.bigNumberishArrayToDecimalStringArray = bigNumberishArrayToDecimalStringArray;
|
|
79
|
+
function bigNumberishArrayToHexadecimalStringArray(rawCalldata) {
|
|
80
|
+
return rawCalldata.map(function (x) { return toHex(toBN(x)); });
|
|
81
|
+
}
|
|
82
|
+
exports.bigNumberishArrayToHexadecimalStringArray = bigNumberishArrayToHexadecimalStringArray;
|
package/www/docs/API/utils.md
CHANGED
|
@@ -176,6 +176,12 @@ const signature = await this.signer.signTransaction(transactions, signerDetails)
|
|
|
176
176
|
}
|
|
177
177
|
```
|
|
178
178
|
|
|
179
|
+
### bigNumberishArrayToHexadecimalStringArray
|
|
180
|
+
|
|
181
|
+
`bigNumberishArrayToHexadecimalStringArray(rawCalldata: BigNumberish[]): string[]`
|
|
182
|
+
|
|
183
|
+
Convert BigNumberish array to hexadecimal string array. Used for signature conversion.
|
|
184
|
+
|
|
179
185
|
<hr />
|
|
180
186
|
|
|
181
187
|
## **uint256**
|