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
|
@@ -1,110 +0,0 @@
|
|
|
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';
|
|
9
|
-
import { compiledArgentAccount, compiledErc20 } from './fixtures';
|
|
10
|
-
|
|
11
|
-
describe('getStarkAccountFromPrivateKey()', () => {
|
|
12
|
-
test('it works with valid privateKey', () => {
|
|
13
|
-
const privateKey = '0xb696427c0d79c5d28a1fa6f748bae1b98b3f4b86bd1a2505bab144673c856fa9';
|
|
14
|
-
|
|
15
|
-
const starkKeyPair = ec.getKeyPair(privateKey);
|
|
16
|
-
const starkKey = ec.getStarkKey(starkKeyPair);
|
|
17
|
-
|
|
18
|
-
expect(starkKey).toBe('0x060d46f8d7ef3d83ed05f3ed9beb91e22f9529289b9d863683fd71eafaf28035');
|
|
19
|
-
});
|
|
20
|
-
test('it works with valid privateKey', () => {
|
|
21
|
-
const privateKey = '0x5f65099e269b080000000000000000000000000000000000000000000000000';
|
|
22
|
-
|
|
23
|
-
const starkKeyPair = ec.getKeyPair(privateKey);
|
|
24
|
-
const starkKey = ec.getStarkKey(starkKeyPair);
|
|
25
|
-
|
|
26
|
-
expect(starkKey).toBe('0xf321e59b257a577836d8313150aabd21f412491358c329966218df76bab591');
|
|
27
|
-
});
|
|
28
|
-
});
|
|
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
|
-
`"0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e"`
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
const calls = [{ contractAddress: '1', entrypoint: 'transfer', calldata: ['6', '7'] }];
|
|
44
|
-
const calldata = fromCallsToExecuteCalldataWithNonce(calls, 0);
|
|
45
|
-
|
|
46
|
-
const msgHash = calculcateTransactionHash(
|
|
47
|
-
address,
|
|
48
|
-
transactionVersion,
|
|
49
|
-
getSelectorFromName('__execute__'),
|
|
50
|
-
calldata,
|
|
51
|
-
0,
|
|
52
|
-
StarknetChainId.TESTNET
|
|
53
|
-
);
|
|
54
|
-
expect(number.toBN(msgHash).toString()).toMatchInlineSnapshot(
|
|
55
|
-
`"235855380881994314533025886817815774848495061484535023348790852315407085619"`
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
const [r, s] = ec.sign(keyPair, msgHash);
|
|
59
|
-
expect(r.toString()).toMatchInlineSnapshot(
|
|
60
|
-
`"181489288548431284937202760565682158657883789985879744111612429574110648095"`
|
|
61
|
-
);
|
|
62
|
-
expect(s.toString()).toMatchInlineSnapshot(
|
|
63
|
-
`"2055384802167699202203509702082340762385659879831017273872106910763470114538"`
|
|
64
|
-
);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe('deploy and test Wallet', () => {
|
|
68
|
-
const privateKey = stark.randomAddress();
|
|
69
|
-
|
|
70
|
-
const starkKeyPair = ec.getKeyPair(privateKey);
|
|
71
|
-
const starkKeyPub = ec.getStarkKey(starkKeyPair);
|
|
72
|
-
let accountContract: Contract;
|
|
73
|
-
let erc20: Contract;
|
|
74
|
-
let erc20Address: string;
|
|
75
|
-
|
|
76
|
-
beforeAll(async () => {
|
|
77
|
-
const accountResponse = await defaultProvider.deployContract({
|
|
78
|
-
contract: compiledArgentAccount,
|
|
79
|
-
addressSalt: starkKeyPub,
|
|
80
|
-
});
|
|
81
|
-
accountContract = new Contract(compiledArgentAccount.abi, accountResponse.address);
|
|
82
|
-
expect(accountResponse.code).toBe('TRANSACTION_RECEIVED');
|
|
83
|
-
|
|
84
|
-
const initializeResponse = await accountContract.initialize(starkKeyPub, '0');
|
|
85
|
-
expect(initializeResponse.code).toBe('TRANSACTION_RECEIVED');
|
|
86
|
-
|
|
87
|
-
const erc20Response = await defaultProvider.deployContract({
|
|
88
|
-
contract: compiledErc20,
|
|
89
|
-
});
|
|
90
|
-
erc20Address = erc20Response.address;
|
|
91
|
-
erc20 = new Contract(compiledErc20.abi, erc20Address);
|
|
92
|
-
expect(erc20Response.code).toBe('TRANSACTION_RECEIVED');
|
|
93
|
-
|
|
94
|
-
const mintResponse = await erc20.mint(accountContract.address, '1000');
|
|
95
|
-
expect(mintResponse.code).toBe('TRANSACTION_RECEIVED');
|
|
96
|
-
await defaultProvider.waitForTransaction(mintResponse.transaction_hash);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
test('read nonce', async () => {
|
|
100
|
-
const { nonce } = await accountContract.get_nonce();
|
|
101
|
-
|
|
102
|
-
expect(number.toBN(nonce as string).toString()).toStrictEqual(number.toBN(0).toString());
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
test('read balance of wallet', async () => {
|
|
106
|
-
const { res } = await erc20.balance_of(accountContract.address);
|
|
107
|
-
|
|
108
|
-
expect(res).toStrictEqual(number.toBN(1000));
|
|
109
|
-
});
|
|
110
|
-
});
|