starknet 3.9.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 +11 -0
- 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/account/default.js +10 -21
- package/constants.d.ts +9 -0
- package/constants.js +13 -0
- package/dist/account/default.js +9 -5
- package/dist/constants.d.ts +9 -0
- package/dist/constants.js +12 -1
- package/dist/provider/default.d.ts +3 -0
- package/dist/provider/default.js +18 -0
- package/dist/provider/interface.d.ts +2 -0
- package/dist/signer/default.js +4 -2
- package/dist/signer/ledger.js +4 -2
- package/dist/types/signer.d.ts +2 -0
- package/dist/utils/hash.d.ts +4 -3
- package/dist/utils/hash.js +24 -24
- 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 +3 -0
- package/provider/default.js +19 -0
- package/provider/interface.d.ts +2 -0
- package/signer/default.js +12 -6
- package/signer/ledger.js +12 -5
- package/src/account/default.ts +16 -9
- package/src/constants.ts +10 -0
- package/src/provider/default.ts +19 -0
- package/src/provider/interface.ts +3 -0
- package/src/signer/default.ts +10 -6
- package/src/signer/ledger.ts +10 -5
- package/src/types/signer.ts +2 -0
- package/src/utils/hash.ts +68 -26
- package/src/utils/transaction.ts +7 -0
- package/types/signer.d.ts +2 -0
- package/utils/hash.d.ts +24 -8
- package/utils/hash.js +55 -28
- 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
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { Contract, defaultProvider, ec, hash, number, stark } from '../src';
|
|
2
|
+
import { StarknetChainId } from '../src/constants';
|
|
3
|
+
import {
|
|
4
|
+
calculcateTransactionHash,
|
|
5
|
+
getSelectorFromName,
|
|
6
|
+
transactionVersion,
|
|
7
|
+
} from '../src/utils/hash';
|
|
8
|
+
import { fromCallsToExecuteCalldataWithNonce } from '../src/utils/transaction';
|
|
2
9
|
import { compiledArgentAccount, compiledErc20 } from './fixtures';
|
|
3
10
|
|
|
4
11
|
describe('getStarkAccountFromPrivateKey()', () => {
|
|
@@ -20,6 +27,41 @@ describe('getStarkAccountFromPrivateKey()', () => {
|
|
|
20
27
|
});
|
|
21
28
|
});
|
|
22
29
|
|
|
30
|
+
test('build tx', async () => {
|
|
31
|
+
const privateKey = '0x1B69B4BE052FAB1';
|
|
32
|
+
const keyPair = ec.getKeyPair(privateKey);
|
|
33
|
+
const address = ec.getStarkKey(keyPair);
|
|
34
|
+
|
|
35
|
+
expect(address).toBe('0x04024999b9574cb7623679ce049a609db62a95098982c5b28ac61abdebd1c82b');
|
|
36
|
+
|
|
37
|
+
const selector = hash.getSelectorFromName('transfer');
|
|
38
|
+
|
|
39
|
+
expect(selector).toMatchInlineSnapshot();
|
|
40
|
+
|
|
41
|
+
const calls = [{ contractAddress: '1', entrypoint: 'transfer', calldata: ['6', '7'] }];
|
|
42
|
+
const calldata = fromCallsToExecuteCalldataWithNonce(calls, 0);
|
|
43
|
+
|
|
44
|
+
const msgHash = calculcateTransactionHash(
|
|
45
|
+
address,
|
|
46
|
+
transactionVersion,
|
|
47
|
+
getSelectorFromName('__execute__'),
|
|
48
|
+
calldata,
|
|
49
|
+
0,
|
|
50
|
+
StarknetChainId.TESTNET
|
|
51
|
+
);
|
|
52
|
+
expect(number.toBN(msgHash).toString()).toMatchInlineSnapshot(
|
|
53
|
+
`"235855380881994314533025886817815774848495061484535023348790852315407085619"`
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const [r, s] = ec.sign(keyPair, msgHash);
|
|
57
|
+
expect(r.toString()).toMatchInlineSnapshot(
|
|
58
|
+
`"181489288548431284937202760565682158657883789985879744111612429574110648095"`
|
|
59
|
+
);
|
|
60
|
+
expect(s.toString()).toMatchInlineSnapshot(
|
|
61
|
+
`"2055384802167699202203509702082340762385659879831017273872106910763470114538"`
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
23
65
|
describe('deploy and test Wallet', () => {
|
|
24
66
|
const privateKey = stark.randomAddress();
|
|
25
67
|
|
|
@@ -64,35 +106,3 @@ describe('deploy and test Wallet', () => {
|
|
|
64
106
|
expect(res).toStrictEqual(number.toBN(1000));
|
|
65
107
|
});
|
|
66
108
|
});
|
|
67
|
-
|
|
68
|
-
test('build tx', async () => {
|
|
69
|
-
const privateKey = '0x1B69B4BE052FAB1';
|
|
70
|
-
const keyPair = ec.getKeyPair(privateKey);
|
|
71
|
-
const address = ec.getStarkKey(keyPair);
|
|
72
|
-
|
|
73
|
-
expect(address).toBe('0x04024999b9574cb7623679ce049a609db62a95098982c5b28ac61abdebd1c82b');
|
|
74
|
-
|
|
75
|
-
const selector = hash.getSelectorFromName('transfer');
|
|
76
|
-
|
|
77
|
-
expect(selector).toBe(
|
|
78
|
-
number.toHex(
|
|
79
|
-
number.toBN('232670485425082704932579856502088130646006032362877466777181098476241604910')
|
|
80
|
-
)
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
const calls = [{ contractAddress: '1', entrypoint: 'transfer', calldata: ['6', '7'] }];
|
|
84
|
-
const msgHash = hash.hashMulticall(address, calls, '0', '0');
|
|
85
|
-
expect(number.toBN(msgHash).toString()).toStrictEqual(
|
|
86
|
-
number
|
|
87
|
-
.toBN('533725737276146993132325070982049323585915612981489962412873515411469143806')
|
|
88
|
-
.toString()
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
const [r, s] = ec.sign(keyPair, msgHash);
|
|
92
|
-
expect(r.toString()).toBe(
|
|
93
|
-
'3081830197073374427897814075820860503521735760640862828374253887454357679197'
|
|
94
|
-
);
|
|
95
|
-
expect(s.toString()).toBe(
|
|
96
|
-
'384293936273611705317490990661155378189310283917528660618713929845936492551'
|
|
97
|
-
);
|
|
98
|
-
});
|
|
@@ -4,8 +4,12 @@ import { Account, Contract, ContractFactory, Provider, defaultProvider, ec, star
|
|
|
4
4
|
import { getSelectorFromName } from '../src/utils/hash';
|
|
5
5
|
import { BigNumberish, toBN } from '../src/utils/number';
|
|
6
6
|
import { compileCalldata } from '../src/utils/stark';
|
|
7
|
-
import {
|
|
8
|
-
|
|
7
|
+
import {
|
|
8
|
+
compiledArgentAccount,
|
|
9
|
+
compiledErc20,
|
|
10
|
+
compiledMulticall,
|
|
11
|
+
compiledTypeTransformation,
|
|
12
|
+
} from './fixtures';
|
|
9
13
|
|
|
10
14
|
describe('class Contract {}', () => {
|
|
11
15
|
const wallet = stark.randomAddress();
|
|
@@ -204,21 +208,29 @@ describe('class Contract {}', () => {
|
|
|
204
208
|
});
|
|
205
209
|
|
|
206
210
|
describe('Contract interaction with Account', () => {
|
|
207
|
-
const starkKeyPair = ec.getKeyPair(PRIVATE_KEY);
|
|
208
211
|
let account: Account;
|
|
209
212
|
let erc20: Contract;
|
|
210
213
|
let erc20Address: string;
|
|
211
214
|
|
|
212
215
|
beforeAll(async () => {
|
|
213
|
-
|
|
216
|
+
const starkKeyPair = ec.genKeyPair();
|
|
217
|
+
const starkKeyPub = ec.getStarkKey(starkKeyPair);
|
|
218
|
+
const { address } = await defaultProvider.deployContract({
|
|
219
|
+
contract: compiledArgentAccount,
|
|
220
|
+
addressSalt: starkKeyPub,
|
|
221
|
+
});
|
|
222
|
+
expect(address).toBeDefined();
|
|
223
|
+
account = new Account(defaultProvider, address, starkKeyPair);
|
|
224
|
+
const accountContract = new Contract(compiledArgentAccount.abi, address);
|
|
225
|
+
await accountContract.initialize(starkKeyPub, '0');
|
|
214
226
|
|
|
215
227
|
const erc20Response = await defaultProvider.deployContract({
|
|
216
228
|
contract: compiledErc20,
|
|
217
229
|
});
|
|
218
230
|
erc20Address = erc20Response.address;
|
|
219
231
|
erc20 = new Contract(compiledErc20.abi, erc20Address, defaultProvider);
|
|
220
|
-
await defaultProvider.waitForTransaction(erc20Response.transaction_hash);
|
|
221
232
|
expect(erc20Response.code).toBe('TRANSACTION_RECEIVED');
|
|
233
|
+
await defaultProvider.waitForTransaction(erc20Response.transaction_hash);
|
|
222
234
|
|
|
223
235
|
const mintResponse = await erc20.mint(account.address, '1000');
|
|
224
236
|
|
|
@@ -251,7 +263,9 @@ describe('class Contract {}', () => {
|
|
|
251
263
|
});
|
|
252
264
|
|
|
253
265
|
test('invoke contract by wallet owner', async () => {
|
|
254
|
-
const { transaction_hash, code } = await erc20.transfer(
|
|
266
|
+
const { transaction_hash, code } = await erc20.transfer(erc20Address, 10, {
|
|
267
|
+
maxFee: 0,
|
|
268
|
+
});
|
|
255
269
|
expect(code).toBe('TRANSACTION_RECEIVED');
|
|
256
270
|
await defaultProvider.waitForTransaction(transaction_hash);
|
|
257
271
|
const { res } = await erc20.balance_of(account.address);
|