starknet 2.7.2 → 3.1.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/.eslintrc +3 -1
- package/CHANGELOG.md +54 -0
- package/README.md +16 -14
- package/__mocks__/contract.json +33191 -0
- package/__mocks__/multicall.json +8139 -0
- package/__mocks__/typedDataExample.json +35 -0
- package/__tests__/account.test.ts +53 -87
- package/__tests__/accountContract.test.ts +161 -0
- package/__tests__/contract.test.ts +167 -30
- package/__tests__/jest.setup.ts +9 -0
- package/__tests__/provider.test.ts +19 -34
- package/__tests__/utils/address.test.ts +16 -0
- package/__tests__/utils/typedData.test.ts +1 -36
- package/account/default.d.ts +66 -0
- package/account/default.js +439 -0
- package/account/index.d.ts +2 -0
- package/account/index.js +27 -0
- package/account/interface.d.ts +83 -0
- package/account/interface.js +37 -0
- package/constants.d.ts +2 -0
- package/constants.js +4 -0
- package/contract.d.ts +71 -12
- package/contract.js +243 -89
- package/dist/account/default.d.ts +55 -0
- package/dist/account/default.js +271 -0
- package/dist/account/index.d.ts +2 -0
- package/dist/account/index.js +14 -0
- package/dist/account/interface.d.ts +69 -0
- package/dist/account/interface.js +27 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +3 -1
- package/dist/contract.d.ts +71 -9
- package/dist/contract.js +214 -65
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/provider/default.d.ts +27 -16
- package/dist/provider/default.js +157 -100
- package/dist/provider/interface.d.ts +29 -32
- package/dist/provider/utils.d.ts +21 -5
- package/dist/provider/utils.js +53 -10
- package/dist/signer/default.d.ts +7 -31
- package/dist/signer/default.js +25 -121
- package/dist/signer/index.d.ts +1 -1
- package/dist/signer/index.js +1 -1
- package/dist/signer/interface.d.ts +17 -18
- package/dist/signer/interface.js +2 -20
- package/dist/types/api.d.ts +147 -0
- package/dist/{types.js → types/api.js} +0 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +15 -0
- package/dist/types/lib.d.ts +57 -0
- package/dist/types/lib.js +2 -0
- package/dist/types/signer.d.ts +4 -0
- package/dist/types/signer.js +2 -0
- package/dist/utils/address.d.ts +2 -0
- package/dist/utils/address.js +22 -0
- package/dist/utils/number.d.ts +2 -0
- package/dist/utils/number.js +32 -2
- package/dist/utils/stark.d.ts +2 -1
- package/dist/utils/stark.js +44 -1
- package/index.d.ts +2 -1
- package/index.js +2 -1
- package/package.json +9 -3
- package/provider/default.d.ts +45 -36
- package/provider/default.js +216 -201
- package/provider/interface.d.ts +36 -49
- package/provider/utils.d.ts +23 -8
- package/provider/utils.js +57 -11
- package/signer/default.d.ts +11 -31
- package/signer/default.js +52 -169
- package/signer/index.d.ts +1 -1
- package/signer/index.js +1 -1
- package/signer/interface.d.ts +21 -18
- package/signer/interface.js +3 -32
- package/src/account/default.ts +151 -0
- package/src/account/index.ts +2 -0
- package/src/account/interface.ts +91 -0
- package/src/constants.ts +2 -0
- package/src/contract.ts +246 -77
- package/src/index.ts +2 -1
- package/src/provider/default.ts +141 -110
- package/src/provider/interface.ts +36 -52
- package/src/provider/utils.ts +60 -13
- package/src/signer/default.ts +33 -76
- package/src/signer/index.ts +1 -1
- package/src/signer/interface.ts +21 -20
- package/src/types/api.ts +171 -0
- package/src/types/index.ts +3 -0
- package/src/types/lib.ts +73 -0
- package/src/types/signer.ts +5 -0
- package/src/utils/address.ts +23 -0
- package/src/utils/number.ts +12 -1
- package/src/utils/stark.ts +13 -1
- package/types/api.d.ts +162 -0
- package/{types.js → types/api.js} +0 -0
- package/types/index.d.ts +3 -0
- package/types/index.js +28 -0
- package/types/lib.d.ts +64 -0
- package/types/lib.js +2 -0
- package/types/signer.d.ts +4 -0
- package/types/signer.js +2 -0
- package/utils/address.d.ts +2 -0
- package/utils/address.js +22 -0
- package/utils/number.d.ts +4 -0
- package/utils/number.js +54 -2
- package/utils/stark.d.ts +2 -1
- package/utils/stark.js +64 -1
- package/__tests__/signer.test.ts +0 -119
- package/dist/types.d.ts +0 -109
- package/src/types.ts +0 -131
- package/types.d.ts +0 -116
package/dist/utils/stark.js
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
18
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
+
if (ar || !(i in from)) {
|
|
21
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
+
ar[i] = from[i];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
+
};
|
|
2
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatSignature = exports.makeAddress = exports.randomAddress = exports.getSelectorFromName = exports.compressProgram = void 0;
|
|
28
|
+
exports.compileCalldata = exports.formatSignature = exports.makeAddress = exports.randomAddress = exports.getSelectorFromName = exports.compressProgram = void 0;
|
|
4
29
|
var pako_1 = require("pako");
|
|
5
30
|
var ellipticCurve_1 = require("./ellipticCurve");
|
|
6
31
|
var encode_1 = require("./encode");
|
|
@@ -52,3 +77,21 @@ function formatSignature(sig) {
|
|
|
52
77
|
}
|
|
53
78
|
}
|
|
54
79
|
exports.formatSignature = formatSignature;
|
|
80
|
+
function compileCalldata(args) {
|
|
81
|
+
return Object.values(args).flatMap(function (value) {
|
|
82
|
+
if (Array.isArray(value))
|
|
83
|
+
return __spreadArray([(0, number_1.toBN)(value.length).toString()], __read(value.map(function (x) { return (0, number_1.toBN)(x).toString(); })), false);
|
|
84
|
+
if (typeof value === 'object' && 'type' in value)
|
|
85
|
+
return Object.entries(value)
|
|
86
|
+
.filter(function (_a) {
|
|
87
|
+
var _b = __read(_a, 1), k = _b[0];
|
|
88
|
+
return k !== 'type';
|
|
89
|
+
})
|
|
90
|
+
.map(function (_a) {
|
|
91
|
+
var _b = __read(_a, 2), v = _b[1];
|
|
92
|
+
return (0, number_1.toBN)(v).toString();
|
|
93
|
+
});
|
|
94
|
+
return (0, number_1.toBN)(value).toString();
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
exports.compileCalldata = compileCalldata;
|
package/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
export * from './types';
|
|
5
5
|
export * from './contract';
|
|
6
6
|
export * from './provider';
|
|
7
|
-
export * from './
|
|
7
|
+
export * from './account';
|
|
8
8
|
/**
|
|
9
9
|
* Utils
|
|
10
10
|
*/
|
|
@@ -18,3 +18,4 @@ export * as ec from './utils/ellipticCurve';
|
|
|
18
18
|
export * as uint256 from './utils/uint256';
|
|
19
19
|
export * as shortString from './utils/shortString';
|
|
20
20
|
export * as typedData from './utils/typedData';
|
|
21
|
+
export * from './utils/address';
|
package/index.js
CHANGED
|
@@ -61,7 +61,7 @@ exports.typedData =
|
|
|
61
61
|
__exportStar(require('./types'), exports);
|
|
62
62
|
__exportStar(require('./contract'), exports);
|
|
63
63
|
__exportStar(require('./provider'), exports);
|
|
64
|
-
__exportStar(require('./
|
|
64
|
+
__exportStar(require('./account'), exports);
|
|
65
65
|
/**
|
|
66
66
|
* Utils
|
|
67
67
|
*/
|
|
@@ -75,3 +75,4 @@ exports.ec = __importStar(require('./utils/ellipticCurve'));
|
|
|
75
75
|
exports.uint256 = __importStar(require('./utils/uint256'));
|
|
76
76
|
exports.shortString = __importStar(require('./utils/shortString'));
|
|
77
77
|
exports.typedData = __importStar(require('./utils/typedData'));
|
|
78
|
+
__exportStar(require('./utils/address'), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starknet",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "JavaScript library for StarkNet",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"zk",
|
|
24
24
|
"rollup"
|
|
25
25
|
],
|
|
26
|
-
"repository": "github:
|
|
26
|
+
"repository": "github:0xs34n/starknet.js",
|
|
27
27
|
"author": "Sean Han",
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"devDependencies": {
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"@types/url-join": "^4.0.1",
|
|
45
45
|
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
46
46
|
"@typescript-eslint/parser": "^5.0.0",
|
|
47
|
+
"axios-logger": "^2.6.0",
|
|
47
48
|
"eslint": "^7.32.0",
|
|
48
49
|
"eslint-config-airbnb-base": "^14.2.1",
|
|
49
50
|
"eslint-config-airbnb-typescript": "^14.0.1",
|
|
@@ -76,7 +77,12 @@
|
|
|
76
77
|
"*.{ts,js,md,yml,json}": "prettier --write"
|
|
77
78
|
},
|
|
78
79
|
"jest": {
|
|
79
|
-
"
|
|
80
|
+
"testMatch": [
|
|
81
|
+
"**/__tests__/**/(*.)+(spec|test).[jt]s?(x)"
|
|
82
|
+
],
|
|
83
|
+
"setupFilesAfterEnv": [
|
|
84
|
+
"./__tests__/jest.setup.ts"
|
|
85
|
+
]
|
|
80
86
|
},
|
|
81
87
|
"importSort": {
|
|
82
88
|
".js, .jsx, .ts, .tsx": {
|
package/provider/default.d.ts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Abi,
|
|
2
3
|
AddTransactionResponse,
|
|
3
|
-
|
|
4
|
+
Call,
|
|
4
5
|
CallContractResponse,
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
DeployContractPayload,
|
|
7
|
+
Endpoints,
|
|
7
8
|
GetBlockResponse,
|
|
8
9
|
GetCodeResponse,
|
|
9
10
|
GetContractAddressesResponse,
|
|
10
11
|
GetTransactionResponse,
|
|
11
12
|
GetTransactionStatusResponse,
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
Invocation,
|
|
14
|
+
TransactionReceipt,
|
|
14
15
|
} from '../types';
|
|
15
16
|
import { BigNumberish } from '../utils/number';
|
|
16
17
|
import { ProviderInterface } from './interface';
|
|
18
|
+
import { BlockIdentifier } from './utils';
|
|
17
19
|
declare type NetworkName = 'mainnet-alpha' | 'goerli-alpha';
|
|
18
20
|
declare type ProviderOptions =
|
|
19
21
|
| {
|
|
@@ -30,6 +32,20 @@ export declare class Provider implements ProviderInterface {
|
|
|
30
32
|
protected static getNetworkFromName(
|
|
31
33
|
name: NetworkName
|
|
32
34
|
): 'https://alpha-mainnet.starknet.io' | 'https://alpha4.starknet.io';
|
|
35
|
+
private getFetchUrl;
|
|
36
|
+
private getFetchMethod;
|
|
37
|
+
private getQueryString;
|
|
38
|
+
private getHeaders;
|
|
39
|
+
protected fetchEndpoint<T extends keyof Endpoints>(
|
|
40
|
+
endpoint: T,
|
|
41
|
+
...[query, request]: Endpoints[T]['QUERY'] extends never
|
|
42
|
+
? Endpoints[T]['REQUEST'] extends never
|
|
43
|
+
? []
|
|
44
|
+
: [undefined, Endpoints[T]['REQUEST']]
|
|
45
|
+
: Endpoints[T]['REQUEST'] extends never
|
|
46
|
+
? [Endpoints[T]['QUERY']]
|
|
47
|
+
: [Endpoints[T]['QUERY'], Endpoints[T]['REQUEST']]
|
|
48
|
+
): Promise<Endpoints[T]['RESPONSE']>;
|
|
33
49
|
/**
|
|
34
50
|
* Gets the smart contract address on the goerli testnet.
|
|
35
51
|
*
|
|
@@ -48,9 +64,8 @@ export declare class Provider implements ProviderInterface {
|
|
|
48
64
|
* @returns the result of the function on the smart contract.
|
|
49
65
|
*/
|
|
50
66
|
callContract(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
blockNumber?: BlockNumber
|
|
67
|
+
{ contractAddress, entrypoint, calldata }: Call,
|
|
68
|
+
blockIdentifier?: BlockIdentifier
|
|
54
69
|
): Promise<CallContractResponse>;
|
|
55
70
|
/**
|
|
56
71
|
* Gets the block information
|
|
@@ -61,7 +76,7 @@ export declare class Provider implements ProviderInterface {
|
|
|
61
76
|
* @param blockNumber
|
|
62
77
|
* @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
|
|
63
78
|
*/
|
|
64
|
-
getBlock(
|
|
79
|
+
getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
|
|
65
80
|
/**
|
|
66
81
|
* Gets the code of the deployed contract.
|
|
67
82
|
*
|
|
@@ -72,11 +87,7 @@ export declare class Provider implements ProviderInterface {
|
|
|
72
87
|
* @param blockNumber
|
|
73
88
|
* @returns Bytecode and ABI of compiled contract
|
|
74
89
|
*/
|
|
75
|
-
getCode(
|
|
76
|
-
contractAddress: string,
|
|
77
|
-
blockHash?: BigNumberish,
|
|
78
|
-
blockNumber?: BlockNumber
|
|
79
|
-
): Promise<GetCodeResponse>;
|
|
90
|
+
getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
|
|
80
91
|
/**
|
|
81
92
|
* Gets the contract's storage variable at a specific key.
|
|
82
93
|
*
|
|
@@ -91,8 +102,7 @@ export declare class Provider implements ProviderInterface {
|
|
|
91
102
|
getStorageAt(
|
|
92
103
|
contractAddress: string,
|
|
93
104
|
key: number,
|
|
94
|
-
|
|
95
|
-
blockNumber?: BlockNumber
|
|
105
|
+
blockIdentifier?: BlockIdentifier
|
|
96
106
|
): Promise<object>;
|
|
97
107
|
/**
|
|
98
108
|
* Gets the status of a transaction.
|
|
@@ -104,23 +114,30 @@ export declare class Provider implements ProviderInterface {
|
|
|
104
114
|
*/
|
|
105
115
|
getTransactionStatus(txHash: BigNumberish): Promise<GetTransactionStatusResponse>;
|
|
106
116
|
/**
|
|
107
|
-
* Gets the transaction
|
|
117
|
+
* Gets the transaction receipt from a tx hash or tx id.
|
|
108
118
|
*
|
|
109
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
119
|
+
* [Reference] (https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L104-L111)
|
|
110
120
|
*
|
|
111
121
|
* @param txHash
|
|
112
|
-
* @
|
|
122
|
+
* @param txId
|
|
123
|
+
* @returns the transaction receipt object
|
|
113
124
|
*/
|
|
114
|
-
|
|
125
|
+
getTransactionReceipt({
|
|
126
|
+
txHash,
|
|
127
|
+
txId,
|
|
128
|
+
}: {
|
|
129
|
+
txHash?: BigNumberish;
|
|
130
|
+
txId?: BigNumberish;
|
|
131
|
+
}): Promise<TransactionReceipt>;
|
|
115
132
|
/**
|
|
116
|
-
*
|
|
133
|
+
* Gets the transaction information from a tx id.
|
|
117
134
|
*
|
|
118
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/
|
|
135
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L54-L58)
|
|
119
136
|
*
|
|
120
|
-
* @param
|
|
121
|
-
* @returns
|
|
137
|
+
* @param txHash
|
|
138
|
+
* @returns the transacton object { transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? }
|
|
122
139
|
*/
|
|
123
|
-
|
|
140
|
+
getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
|
|
124
141
|
/**
|
|
125
142
|
* Deploys a given compiled contract (json) to starknet
|
|
126
143
|
*
|
|
@@ -128,13 +145,10 @@ export declare class Provider implements ProviderInterface {
|
|
|
128
145
|
* @param address - (optional, defaults to a random address) the address where the contract should be deployed (alpha)
|
|
129
146
|
* @returns a confirmation of sending a transaction on the starknet contract
|
|
130
147
|
*/
|
|
131
|
-
deployContract(
|
|
132
|
-
contract: CompiledContract | string,
|
|
133
|
-
constructorCalldata?: string[],
|
|
134
|
-
addressSalt?: BigNumberish
|
|
135
|
-
): Promise<AddTransactionResponse>;
|
|
148
|
+
deployContract(payload: DeployContractPayload, _abi?: Abi): Promise<AddTransactionResponse>;
|
|
136
149
|
/**
|
|
137
150
|
* Invokes a function on starknet
|
|
151
|
+
* @deprecated This method wont be supported as soon as fees are mandatory
|
|
138
152
|
*
|
|
139
153
|
* @param contractAddress - target contract address for invoke
|
|
140
154
|
* @param entrypointSelector - target entrypoint selector for
|
|
@@ -142,12 +156,7 @@ export declare class Provider implements ProviderInterface {
|
|
|
142
156
|
* @param signature - (optional) signature to send along
|
|
143
157
|
* @returns response from addTransaction
|
|
144
158
|
*/
|
|
145
|
-
invokeFunction(
|
|
146
|
-
contractAddress: string,
|
|
147
|
-
entrypointSelector: string,
|
|
148
|
-
calldata?: string[],
|
|
149
|
-
signature?: Signature
|
|
150
|
-
): Promise<AddTransactionResponse>;
|
|
159
|
+
invokeFunction(invocation: Invocation, _abi?: Abi): Promise<AddTransactionResponse>;
|
|
151
160
|
waitForTx(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
152
161
|
}
|
|
153
162
|
export {};
|