starknet 3.18.2 → 3.19.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 +53 -0
- package/__tests__/account.test.ts +11 -56
- package/__tests__/contract.test.ts +11 -49
- package/__tests__/defaultProvider.test.ts +321 -0
- package/__tests__/fixtures.ts +32 -11
- package/__tests__/rpcProvider.test.ts +17 -0
- package/__tests__/sequencerProvider.test.ts +45 -0
- package/account/default.d.ts +54 -77
- package/account/default.js +271 -596
- package/account/index.js +18 -31
- package/account/interface.d.ts +66 -95
- package/account/interface.js +20 -30
- package/constants.d.ts +17 -19
- package/constants.js +2038 -2059
- package/contract/contractFactory.d.ts +25 -29
- package/contract/contractFactory.js +94 -210
- package/contract/default.d.ts +117 -146
- package/contract/default.js +582 -776
- package/contract/index.js +19 -32
- package/contract/interface.d.ts +72 -92
- package/contract/interface.js +6 -5
- package/dist/account/default.d.ts +5 -9
- package/dist/account/default.js +35 -169
- package/dist/account/interface.d.ts +3 -15
- package/dist/contract/contractFactory.js +4 -4
- package/dist/contract/default.d.ts +3 -3
- package/dist/contract/default.js +3 -2
- package/dist/contract/interface.d.ts +2 -2
- package/dist/provider/default.d.ts +18 -134
- package/dist/provider/default.js +47 -411
- package/dist/provider/index.d.ts +2 -0
- package/dist/provider/index.js +2 -0
- package/dist/provider/interface.d.ts +45 -50
- package/dist/provider/rpc.d.ts +57 -0
- package/dist/provider/rpc.js +364 -0
- package/dist/provider/sequencer.d.ts +66 -0
- package/dist/provider/sequencer.js +443 -0
- package/dist/types/account.d.ts +2 -3
- package/dist/types/api/index.d.ts +16 -0
- package/dist/types/api/index.js +18 -0
- package/dist/types/api/rpc.d.ts +221 -0
- package/dist/types/{api.js → api/rpc.js} +0 -0
- package/dist/types/api/sequencer.d.ts +289 -0
- package/dist/types/api/sequencer.js +2 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/index.js +15 -1
- package/dist/types/lib.d.ts +3 -1
- package/dist/types/provider.d.ts +86 -0
- package/dist/types/provider.js +2 -0
- package/dist/utils/provider.d.ts +4 -0
- package/dist/utils/provider.js +38 -0
- package/dist/utils/responseParser/index.d.ts +11 -0
- package/dist/utils/responseParser/index.js +9 -0
- package/dist/utils/responseParser/rpc.d.ts +13 -0
- package/dist/utils/responseParser/rpc.js +96 -0
- package/dist/utils/responseParser/sequencer.d.ts +13 -0
- package/dist/utils/responseParser/sequencer.js +124 -0
- package/index.js +42 -75
- package/package.json +1 -1
- package/provider/default.d.ts +21 -175
- package/provider/default.js +139 -704
- package/provider/errors.d.ts +4 -4
- package/provider/errors.js +30 -40
- package/provider/index.d.ts +2 -0
- package/provider/index.js +22 -33
- package/provider/interface.d.ts +104 -131
- package/provider/interface.js +6 -5
- package/provider/rpc.d.ts +57 -0
- package/provider/rpc.js +364 -0
- package/provider/sequencer.d.ts +66 -0
- package/provider/sequencer.js +443 -0
- package/provider/utils.d.ts +7 -9
- package/provider/utils.js +39 -44
- package/signer/default.d.ts +5 -9
- package/signer/default.js +72 -177
- package/signer/index.js +18 -31
- package/signer/interface.d.ts +29 -33
- package/signer/interface.js +6 -5
- package/src/account/default.ts +26 -146
- package/src/account/interface.ts +5 -20
- package/src/contract/contractFactory.ts +3 -6
- package/src/contract/default.ts +6 -4
- package/src/contract/interface.ts +2 -2
- package/src/provider/default.ts +63 -395
- package/src/provider/index.ts +2 -0
- package/src/provider/interface.ts +68 -63
- package/src/provider/rpc.ts +300 -0
- package/src/provider/sequencer.ts +384 -0
- package/src/types/account.ts +2 -3
- package/src/types/api/index.ts +17 -0
- package/src/types/api/rpc.ts +247 -0
- package/src/types/api/sequencer.ts +331 -0
- package/src/types/index.ts +3 -1
- package/src/types/lib.ts +3 -1
- package/src/types/provider.ts +108 -0
- package/src/utils/provider.ts +28 -0
- package/src/utils/responseParser/index.ts +28 -0
- package/src/utils/responseParser/rpc.ts +93 -0
- package/src/utils/responseParser/sequencer.ts +127 -0
- package/types/account.d.ts +5 -7
- package/types/account.js +2 -2
- package/types/api/index.d.ts +16 -0
- package/types/api/index.js +18 -0
- package/types/api/rpc.d.ts +221 -0
- package/types/api/rpc.js +2 -0
- package/types/api/sequencer.d.ts +289 -0
- package/types/api/sequencer.js +2 -0
- package/types/contract.d.ts +1 -1
- package/types/contract.js +2 -2
- package/types/index.d.ts +3 -1
- package/types/index.js +35 -34
- package/types/lib.d.ts +36 -41
- package/types/lib.js +2 -2
- package/types/provider.d.ts +86 -0
- package/types/provider.js +2 -0
- package/types/signer.d.ts +2 -2
- package/types/signer.js +2 -2
- package/utils/address.js +26 -37
- package/utils/ellipticCurve.d.ts +1 -6
- package/utils/ellipticCurve.js +73 -137
- package/utils/encode.js +49 -85
- package/utils/hash.d.ts +4 -31
- package/utils/hash.js +76 -141
- package/utils/json.d.ts +13 -45
- package/utils/json.js +15 -22
- package/utils/number.d.ts +2 -9
- package/utils/number.js +47 -81
- package/utils/provider.d.ts +4 -0
- package/utils/provider.js +38 -0
- package/utils/responseParser/index.d.ts +11 -0
- package/utils/responseParser/index.js +9 -0
- package/utils/responseParser/rpc.d.ts +13 -0
- package/utils/responseParser/rpc.js +96 -0
- package/utils/responseParser/sequencer.d.ts +13 -0
- package/utils/responseParser/sequencer.js +124 -0
- package/utils/shortString.js +13 -21
- package/utils/stark.d.ts +0 -1
- package/utils/stark.js +59 -93
- package/utils/transaction.d.ts +3 -6
- package/utils/transaction.js +50 -81
- package/utils/typedData/index.d.ts +3 -15
- package/utils/typedData/index.js +109 -175
- package/utils/typedData/types.d.ts +9 -9
- package/utils/typedData/types.js +2 -2
- package/utils/typedData/utils.js +6 -6
- package/utils/uint256.d.ts +5 -5
- package/utils/uint256.js +16 -26
- package/www/docs/API/account.md +3 -4
- package/www/docs/API/contract.md +2 -2
- package/www/docs/API/contractFactory.md +2 -2
- package/www/docs/API/provider.md +185 -74
- package/www/guides/account.md +1 -8
- package/www/guides/erc20.md +3 -0
- package/__tests__/provider.test.ts +0 -168
- package/dist/types/api.d.ts +0 -261
- package/src/types/api.ts +0 -303
- package/types/api.d.ts +0 -287
- package/types/api.js +0 -2
package/__tests__/fixtures.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
|
|
3
|
-
import { Account,
|
|
3
|
+
import { Account, ProviderInterface, RpcProvider, SequencerProvider, ec, json } from '../src';
|
|
4
4
|
import { CompiledContract } from '../src/types';
|
|
5
5
|
|
|
6
6
|
const readContract = (name: string): CompiledContract =>
|
|
@@ -18,10 +18,20 @@ const DEFAULT_TEST_ACCOUNT_ADDRESS = // run `starknet-devnet --seed 0` and this
|
|
|
18
18
|
const DEFAULT_TEST_ACCOUNT_PRIVATE_KEY = '0xe3e70682c2094cac629f6fbed82c07cd';
|
|
19
19
|
|
|
20
20
|
const BASE_URL = process.env.TEST_PROVIDER_BASE_URL || DEFAULT_TEST_PROVIDER_BASE_URL;
|
|
21
|
-
|
|
21
|
+
const RPC_URL = process.env.TEST_RPC_URL;
|
|
22
|
+
|
|
23
|
+
const IS_RPC = !!RPC_URL;
|
|
24
|
+
const IS_RPC_DEVNET = Boolean(
|
|
25
|
+
RPC_URL && (RPC_URL.includes('localhost') || RPC_URL.includes('127.0.0.1'))
|
|
26
|
+
);
|
|
27
|
+
const IS_SEQUENCER = !IS_RPC;
|
|
28
|
+
const IS_SEQUENCER_DEVNET = !BASE_URL.includes('starknet.io');
|
|
29
|
+
export const IS_DEVNET = IS_SEQUENCER ? IS_SEQUENCER_DEVNET : IS_RPC_DEVNET;
|
|
22
30
|
|
|
23
31
|
export const getTestProvider = () => {
|
|
24
|
-
const provider =
|
|
32
|
+
const provider = RPC_URL
|
|
33
|
+
? new RpcProvider({ nodeUrl: RPC_URL })
|
|
34
|
+
: new SequencerProvider({ baseUrl: BASE_URL });
|
|
25
35
|
|
|
26
36
|
if (IS_DEVNET) {
|
|
27
37
|
// accelerate the tests when running locally
|
|
@@ -35,16 +45,27 @@ export const getTestProvider = () => {
|
|
|
35
45
|
};
|
|
36
46
|
|
|
37
47
|
// test account with fee token balance
|
|
38
|
-
export const getTestAccount = () => {
|
|
39
|
-
|
|
48
|
+
export const getTestAccount = (provider: ProviderInterface) => {
|
|
49
|
+
let testAccountAddress = process.env.TEST_ACCOUNT_ADDRESS;
|
|
50
|
+
let testAccountPrivateKey = process.env.TEST_ACCOUNT_PRIVATE_KEY;
|
|
51
|
+
|
|
52
|
+
if (!IS_DEVNET) {
|
|
53
|
+
if (!testAccountPrivateKey) {
|
|
54
|
+
throw new Error('TEST_ACCOUNT_PRIVATE_KEY is not set');
|
|
55
|
+
}
|
|
40
56
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
57
|
+
if (!testAccountAddress) {
|
|
58
|
+
throw new Error('TEST_ACCOUNT_ADDRESS is not set');
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
testAccountAddress = DEFAULT_TEST_ACCOUNT_ADDRESS;
|
|
62
|
+
testAccountPrivateKey = DEFAULT_TEST_ACCOUNT_PRIVATE_KEY;
|
|
63
|
+
}
|
|
44
64
|
|
|
45
65
|
return new Account(provider, testAccountAddress, ec.getKeyPair(testAccountPrivateKey));
|
|
46
66
|
};
|
|
47
67
|
|
|
48
|
-
|
|
49
|
-
export const
|
|
50
|
-
export const
|
|
68
|
+
const describeIf = (condition: boolean) => (condition ? describe : describe.skip);
|
|
69
|
+
export const describeIfSequencer = describeIf(IS_DEVNET);
|
|
70
|
+
export const describeIfRpc = describeIf(IS_RPC);
|
|
71
|
+
export const describeIfNotDevnet = describeIf(!IS_DEVNET);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { RpcProvider } from '../src';
|
|
2
|
+
import { describeIfRpc, getTestProvider } from './fixtures';
|
|
3
|
+
|
|
4
|
+
describeIfRpc('RPCProvider', () => {
|
|
5
|
+
let provider: RpcProvider;
|
|
6
|
+
|
|
7
|
+
beforeAll(async () => {
|
|
8
|
+
provider = getTestProvider() as RpcProvider;
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
describe('RPC methods', () => {
|
|
12
|
+
test('getChainId', async () => {
|
|
13
|
+
const chainId = await provider.getChainId();
|
|
14
|
+
expect(chainId).toBe('0x534e5f474f45524c49');
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { SequencerProvider } from '../src';
|
|
2
|
+
import {
|
|
3
|
+
compiledErc20,
|
|
4
|
+
describeIfNotDevnet,
|
|
5
|
+
describeIfSequencer,
|
|
6
|
+
getTestProvider,
|
|
7
|
+
} from './fixtures';
|
|
8
|
+
|
|
9
|
+
describeIfSequencer('SequencerProvider', () => {
|
|
10
|
+
let provider: SequencerProvider;
|
|
11
|
+
|
|
12
|
+
beforeAll(async () => {
|
|
13
|
+
provider = getTestProvider() as SequencerProvider;
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
describe('Gateway specific methods', () => {
|
|
17
|
+
let exampleTransactionHash: string;
|
|
18
|
+
|
|
19
|
+
beforeAll(async () => {
|
|
20
|
+
const { transaction_hash } = await provider.deployContract({
|
|
21
|
+
contract: compiledErc20,
|
|
22
|
+
});
|
|
23
|
+
await provider.waitForTransaction(transaction_hash);
|
|
24
|
+
exampleTransactionHash = transaction_hash;
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('getTransactionStatus()', async () => {
|
|
28
|
+
return expect(provider.getTransactionStatus(exampleTransactionHash)).resolves.not.toThrow();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('transaction trace', async () => {
|
|
32
|
+
const transactionTrace = await provider.getTransactionTrace(exampleTransactionHash);
|
|
33
|
+
expect(transactionTrace).toHaveProperty('function_invocation');
|
|
34
|
+
expect(transactionTrace).toHaveProperty('signature');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describeIfNotDevnet('which are not available on devnet', () => {
|
|
38
|
+
test('getContractAddresses()', async () => {
|
|
39
|
+
const { GpsStatementVerifier, Starknet } = await provider.getContractAddresses();
|
|
40
|
+
expect(typeof GpsStatementVerifier).toBe('string');
|
|
41
|
+
expect(typeof Starknet).toBe('string');
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
});
|
package/account/default.d.ts
CHANGED
|
@@ -1,84 +1,61 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProviderInterface, ProviderOptions } from '../provider';
|
|
2
|
+
import { Provider } from '../provider/default';
|
|
2
3
|
import { SignerInterface } from '../signer';
|
|
3
|
-
import {
|
|
4
|
-
Abi,
|
|
5
|
-
AddTransactionResponse,
|
|
6
|
-
Call,
|
|
7
|
-
InvocationsDetails,
|
|
8
|
-
KeyPair,
|
|
9
|
-
Signature,
|
|
10
|
-
Transaction,
|
|
11
|
-
} from '../types';
|
|
4
|
+
import { Abi, Call, InvocationsDetails, InvokeFunctionResponse, KeyPair, Signature } from '../types';
|
|
12
5
|
import { EstimateFee, EstimateFeeDetails } from '../types/account';
|
|
13
6
|
import { BigNumberish } from '../utils/number';
|
|
14
7
|
import { TypedData } from '../utils/typedData';
|
|
15
8
|
import { AccountInterface } from './interface';
|
|
16
9
|
export declare class Account extends Provider implements AccountInterface {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
*
|
|
69
|
-
* @param hash - JSON object to be verified
|
|
70
|
-
* @param signature - signature of the JSON object
|
|
71
|
-
* @returns true if the signature is valid, false otherwise
|
|
72
|
-
* @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
|
|
73
|
-
*/
|
|
74
|
-
verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
|
|
75
|
-
/**
|
|
76
|
-
* Verify a signature of a JSON object
|
|
77
|
-
*
|
|
78
|
-
* @param hash - hash to be verified
|
|
79
|
-
* @param signature - signature of the hash
|
|
80
|
-
* @returns true if the signature is valid, false otherwise
|
|
81
|
-
* @throws {Error} if the signature is not a valid signature
|
|
82
|
-
*/
|
|
83
|
-
verifyMessage(typedData: TypedData, signature: Signature): Promise<boolean>;
|
|
10
|
+
address: string;
|
|
11
|
+
signer: SignerInterface;
|
|
12
|
+
constructor(providerOrOptions: ProviderOptions | ProviderInterface, address: string, keyPairOrSigner: KeyPair | SignerInterface);
|
|
13
|
+
getNonce(): Promise<string>;
|
|
14
|
+
estimateFee(calls: Call | Call[], { nonce: providedNonce, blockIdentifier }?: EstimateFeeDetails): Promise<EstimateFee>;
|
|
15
|
+
/**
|
|
16
|
+
* Invoke execute function in account contract
|
|
17
|
+
*
|
|
18
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
|
|
19
|
+
*
|
|
20
|
+
* @param calls - one or more calls to be executed
|
|
21
|
+
* @param abis - one or more abis which can be used to display the calls
|
|
22
|
+
* @param transactionsDetail - optional transaction details
|
|
23
|
+
* @returns a confirmation of invoking a function on the starknet contract
|
|
24
|
+
*/
|
|
25
|
+
execute(calls: Call | Call[], abis?: Abi[] | undefined, transactionsDetail?: InvocationsDetails): Promise<InvokeFunctionResponse>;
|
|
26
|
+
/**
|
|
27
|
+
* Sign an JSON object with the starknet private key and return the signature
|
|
28
|
+
*
|
|
29
|
+
* @param json - JSON object to be signed
|
|
30
|
+
* @returns the signature of the JSON object
|
|
31
|
+
* @throws {Error} if the JSON object is not a valid JSON
|
|
32
|
+
*/
|
|
33
|
+
signMessage(typedData: TypedData): Promise<Signature>;
|
|
34
|
+
/**
|
|
35
|
+
* Hash a JSON object with pederson hash and return the hash
|
|
36
|
+
*
|
|
37
|
+
* @param json - JSON object to be hashed
|
|
38
|
+
* @returns the hash of the JSON object
|
|
39
|
+
* @throws {Error} if the JSON object is not a valid JSON
|
|
40
|
+
*/
|
|
41
|
+
hashMessage(typedData: TypedData): Promise<string>;
|
|
42
|
+
/**
|
|
43
|
+
* Verify a signature of a given hash
|
|
44
|
+
* @warning This method is not recommended, use verifyMessage instead
|
|
45
|
+
*
|
|
46
|
+
* @param hash - JSON object to be verified
|
|
47
|
+
* @param signature - signature of the JSON object
|
|
48
|
+
* @returns true if the signature is valid, false otherwise
|
|
49
|
+
* @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
|
|
50
|
+
*/
|
|
51
|
+
verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
|
|
52
|
+
/**
|
|
53
|
+
* Verify a signature of a JSON object
|
|
54
|
+
*
|
|
55
|
+
* @param hash - hash to be verified
|
|
56
|
+
* @param signature - signature of the hash
|
|
57
|
+
* @returns true if the signature is valid, false otherwise
|
|
58
|
+
* @throws {Error} if the signature is not a valid signature
|
|
59
|
+
*/
|
|
60
|
+
verifyMessage(typedData: TypedData, signature: Signature): Promise<boolean>;
|
|
84
61
|
}
|