starknet 3.1.0 → 3.4.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 +19 -0
- package/__mocks__/ArgentAccount.json +68548 -51944
- package/__mocks__/TestDapp.json +12962 -0
- package/__tests__/account.test.ts +63 -50
- package/__tests__/accountContract.test.ts +51 -71
- package/__tests__/contract.test.ts +32 -20
- package/__tests__/fixtures.ts +13 -0
- package/__tests__/provider.test.ts +3 -15
- 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 +20 -13
- package/__tests__/utils/utils.test.ts +3 -3
- package/account/default.d.ts +10 -4
- package/account/default.js +165 -84
- package/account/interface.d.ts +2 -2
- package/dist/account/default.d.ts +8 -3
- package/dist/account/default.js +129 -55
- package/dist/account/interface.d.ts +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/provider/default.d.ts +6 -4
- package/dist/provider/default.js +42 -17
- package/dist/provider/interface.d.ts +5 -1
- package/dist/signer/default.d.ts +1 -1
- package/dist/signer/default.js +6 -18
- package/dist/signer/interface.d.ts +3 -2
- package/dist/types/api.d.ts +5 -0
- package/dist/types/lib.d.ts +3 -3
- package/dist/utils/ellipticCurve.js +1 -1
- package/dist/utils/hash.d.ts +12 -2
- package/dist/utils/hash.js +37 -9
- package/dist/utils/stark.d.ts +0 -8
- package/dist/utils/stark.js +1 -14
- package/dist/utils/transaction.d.ts +19 -0
- package/dist/utils/transaction.js +75 -0
- package/dist/utils/typedData/index.d.ts +1 -1
- package/dist/utils/typedData/index.js +2 -3
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +1 -1
- package/provider/default.d.ts +6 -4
- package/provider/default.js +55 -19
- package/provider/interface.d.ts +5 -1
- package/signer/default.d.ts +1 -1
- package/signer/default.js +10 -44
- package/signer/interface.d.ts +3 -2
- package/src/account/default.ts +129 -42
- package/src/account/interface.ts +2 -2
- package/src/index.ts +1 -0
- package/src/provider/default.ts +32 -22
- package/src/provider/interface.ts +6 -1
- package/src/signer/default.ts +10 -26
- package/src/signer/interface.ts +3 -2
- package/src/types/api.ts +5 -0
- package/src/types/lib.ts +3 -4
- package/src/utils/ellipticCurve.ts +1 -1
- package/src/utils/hash.ts +39 -12
- package/src/utils/stark.ts +1 -14
- package/src/utils/transaction.ts +50 -0
- package/src/utils/typedData/index.ts +2 -3
- package/types/api.d.ts +5 -0
- package/types/lib.d.ts +3 -3
- package/utils/ellipticCurve.js +1 -1
- package/utils/hash.d.ts +15 -6
- package/utils/hash.js +42 -10
- package/utils/stark.d.ts +0 -8
- package/utils/stark.js +0 -14
- package/utils/transaction.d.ts +19 -0
- package/utils/transaction.js +99 -0
- package/utils/typedData/index.d.ts +1 -1
- package/utils/typedData/index.js +2 -3
package/types/lib.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { ec as EC } from 'elliptic';
|
|
|
2
2
|
|
|
3
3
|
import type { BigNumberish } from '../utils/number';
|
|
4
4
|
export declare type KeyPair = EC.KeyPair;
|
|
5
|
-
export declare type Signature =
|
|
5
|
+
export declare type Signature = string[];
|
|
6
6
|
export declare type RawCalldata = BigNumberish[];
|
|
7
7
|
export declare type DeployContractPayload = {
|
|
8
8
|
contract: CompiledContract | string;
|
|
@@ -15,11 +15,11 @@ export declare type Invocation = {
|
|
|
15
15
|
calldata?: RawCalldata;
|
|
16
16
|
signature?: Signature;
|
|
17
17
|
};
|
|
18
|
-
export declare type
|
|
18
|
+
export declare type Call = Omit<Invocation, 'signature'>;
|
|
19
19
|
export declare type InvocationsDetails = {
|
|
20
20
|
nonce?: BigNumberish;
|
|
21
|
+
maxFee?: BigNumberish;
|
|
21
22
|
};
|
|
22
|
-
export declare type Call = Omit<Invocation, 'signature' | 'nonce'>;
|
|
23
23
|
export declare type Status =
|
|
24
24
|
| 'NOT_RECEIVED'
|
|
25
25
|
| 'RECEIVED'
|
package/utils/ellipticCurve.js
CHANGED
|
@@ -136,7 +136,7 @@ function sign(keyPair, msgHash) {
|
|
|
136
136
|
(0, number_1.toBN)((0, encode_1.addHexPrefix)(constants_1.MAX_ECDSA_VAL)),
|
|
137
137
|
'w'
|
|
138
138
|
);
|
|
139
|
-
return [r, s];
|
|
139
|
+
return [r.toString(), s.toString()];
|
|
140
140
|
}
|
|
141
141
|
exports.sign = sign;
|
|
142
142
|
function chunkArray(arr, n) {
|
package/utils/hash.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import BN from 'bn.js';
|
|
2
2
|
|
|
3
|
+
import { Call } from '../types';
|
|
3
4
|
import { BigNumberish } from './number';
|
|
5
|
+
export declare const transactionPrefix: string;
|
|
6
|
+
export declare const transactionVersion = 0;
|
|
4
7
|
/**
|
|
5
8
|
* Function to get the starknet keccak hash from a string
|
|
6
9
|
*
|
|
@@ -9,13 +12,19 @@ import { BigNumberish } from './number';
|
|
|
9
12
|
* @returns starknet keccak hash as BigNumber
|
|
10
13
|
*/
|
|
11
14
|
export declare function starknetKeccak(value: string): BN;
|
|
15
|
+
/**
|
|
16
|
+
* Function to get the hex selector from a given function name
|
|
17
|
+
*
|
|
18
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/public/abi.py#L25-L26)
|
|
19
|
+
* @param funcName - selectors abi function name
|
|
20
|
+
* @returns hex selector of given abi function name
|
|
21
|
+
*/
|
|
22
|
+
export declare function getSelectorFromName(funcName: string): string;
|
|
12
23
|
export declare function pedersen(input: [BigNumberish, BigNumberish]): string;
|
|
13
24
|
export declare function computeHashOnElements(data: BigNumberish[]): string;
|
|
14
|
-
export declare function
|
|
15
|
-
export declare function hashMessage(
|
|
25
|
+
export declare function hashMulticall(
|
|
16
26
|
account: string,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
nonce: string
|
|
27
|
+
transactions: Call[],
|
|
28
|
+
nonce: string,
|
|
29
|
+
maxFee: string
|
|
21
30
|
): string;
|
package/utils/hash.js
CHANGED
|
@@ -39,11 +39,13 @@ var __importDefault =
|
|
|
39
39
|
return mod && mod.__esModule ? mod : { default: mod };
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
42
|
-
exports.
|
|
43
|
-
exports.hashCalldata =
|
|
42
|
+
exports.hashMulticall =
|
|
44
43
|
exports.computeHashOnElements =
|
|
45
44
|
exports.pedersen =
|
|
45
|
+
exports.getSelectorFromName =
|
|
46
46
|
exports.starknetKeccak =
|
|
47
|
+
exports.transactionVersion =
|
|
48
|
+
exports.transactionPrefix =
|
|
47
49
|
void 0;
|
|
48
50
|
var keccak_1 = require('ethereum-cryptography/keccak');
|
|
49
51
|
var minimalistic_assert_1 = __importDefault(require('minimalistic-assert'));
|
|
@@ -51,6 +53,9 @@ var constants_1 = require('../constants');
|
|
|
51
53
|
var ellipticCurve_1 = require('./ellipticCurve');
|
|
52
54
|
var encode_1 = require('./encode');
|
|
53
55
|
var number_1 = require('./number');
|
|
56
|
+
var shortString_1 = require('./shortString');
|
|
57
|
+
exports.transactionPrefix = (0, shortString_1.encodeShortString)('StarkNet Transaction');
|
|
58
|
+
exports.transactionVersion = 0;
|
|
54
59
|
function keccakHex(value) {
|
|
55
60
|
return (0, encode_1.addHexPrefix)(
|
|
56
61
|
(0, encode_1.buf2hex)((0, keccak_1.keccak256)((0, encode_1.utf8ToArray)(value)))
|
|
@@ -67,6 +72,18 @@ function starknetKeccak(value) {
|
|
|
67
72
|
return (0, number_1.toBN)(keccakHex(value)).and(constants_1.MASK_250);
|
|
68
73
|
}
|
|
69
74
|
exports.starknetKeccak = starknetKeccak;
|
|
75
|
+
/**
|
|
76
|
+
* Function to get the hex selector from a given function name
|
|
77
|
+
*
|
|
78
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/public/abi.py#L25-L26)
|
|
79
|
+
* @param funcName - selectors abi function name
|
|
80
|
+
* @returns hex selector of given abi function name
|
|
81
|
+
*/
|
|
82
|
+
function getSelectorFromName(funcName) {
|
|
83
|
+
// sometimes BigInteger pads the hex string with zeros, which isnt allowed in the starknet api
|
|
84
|
+
return (0, number_1.toHex)(starknetKeccak(funcName));
|
|
85
|
+
}
|
|
86
|
+
exports.getSelectorFromName = getSelectorFromName;
|
|
70
87
|
var constantPoints = constants_1.CONSTANT_POINTS.map(function (coords) {
|
|
71
88
|
return ellipticCurve_1.ec.curve.point(coords[0], coords[1]);
|
|
72
89
|
});
|
|
@@ -99,12 +116,27 @@ function computeHashOnElements(data) {
|
|
|
99
116
|
.toString();
|
|
100
117
|
}
|
|
101
118
|
exports.computeHashOnElements = computeHashOnElements;
|
|
102
|
-
function
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
119
|
+
function hashMulticall(account, transactions, nonce, maxFee) {
|
|
120
|
+
var hashArray = transactions
|
|
121
|
+
.map(function (_a) {
|
|
122
|
+
var contractAddress = _a.contractAddress,
|
|
123
|
+
entrypoint = _a.entrypoint,
|
|
124
|
+
calldata = _a.calldata;
|
|
125
|
+
return [
|
|
126
|
+
contractAddress,
|
|
127
|
+
getSelectorFromName(entrypoint),
|
|
128
|
+
computeHashOnElements(calldata || []),
|
|
129
|
+
];
|
|
130
|
+
})
|
|
131
|
+
.map(number_1.bigNumberishArrayToDecimalStringArray)
|
|
132
|
+
.map(computeHashOnElements);
|
|
133
|
+
return computeHashOnElements([
|
|
134
|
+
exports.transactionPrefix,
|
|
135
|
+
account,
|
|
136
|
+
computeHashOnElements(hashArray),
|
|
137
|
+
nonce,
|
|
138
|
+
maxFee,
|
|
139
|
+
exports.transactionVersion,
|
|
140
|
+
]);
|
|
109
141
|
}
|
|
110
|
-
exports.
|
|
142
|
+
exports.hashMulticall = hashMulticall;
|
package/utils/stark.d.ts
CHANGED
|
@@ -7,14 +7,6 @@ import { Calldata, CompressedProgram, Program, RawArgs, Signature } from '../typ
|
|
|
7
7
|
* @returns Compressed cairo program
|
|
8
8
|
*/
|
|
9
9
|
export declare function compressProgram(jsonProgram: Program | string): CompressedProgram;
|
|
10
|
-
/**
|
|
11
|
-
* Function to get the hex selector from a given function name
|
|
12
|
-
*
|
|
13
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/public/abi.py#L25-L26)
|
|
14
|
-
* @param funcName - selectors abi function name
|
|
15
|
-
* @returns hex selector of given abi function name
|
|
16
|
-
*/
|
|
17
|
-
export declare function getSelectorFromName(funcName: string): string;
|
|
18
10
|
export declare function randomAddress(): string;
|
|
19
11
|
export declare function makeAddress(input: string): string;
|
|
20
12
|
export declare function formatSignature(sig?: Signature): string[];
|
package/utils/stark.js
CHANGED
|
@@ -38,13 +38,11 @@ exports.compileCalldata =
|
|
|
38
38
|
exports.formatSignature =
|
|
39
39
|
exports.makeAddress =
|
|
40
40
|
exports.randomAddress =
|
|
41
|
-
exports.getSelectorFromName =
|
|
42
41
|
exports.compressProgram =
|
|
43
42
|
void 0;
|
|
44
43
|
var pako_1 = require('pako');
|
|
45
44
|
var ellipticCurve_1 = require('./ellipticCurve');
|
|
46
45
|
var encode_1 = require('./encode');
|
|
47
|
-
var hash_1 = require('./hash');
|
|
48
46
|
var json_1 = require('./json');
|
|
49
47
|
var number_1 = require('./number');
|
|
50
48
|
/**
|
|
@@ -61,18 +59,6 @@ function compressProgram(jsonProgram) {
|
|
|
61
59
|
return (0, encode_1.btoaUniversal)(compressedProgram);
|
|
62
60
|
}
|
|
63
61
|
exports.compressProgram = compressProgram;
|
|
64
|
-
/**
|
|
65
|
-
* Function to get the hex selector from a given function name
|
|
66
|
-
*
|
|
67
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/public/abi.py#L25-L26)
|
|
68
|
-
* @param funcName - selectors abi function name
|
|
69
|
-
* @returns hex selector of given abi function name
|
|
70
|
-
*/
|
|
71
|
-
function getSelectorFromName(funcName) {
|
|
72
|
-
// sometimes BigInteger pads the hex string with zeros, which isnt allowed in the starknet api
|
|
73
|
-
return (0, number_1.toHex)((0, hash_1.starknetKeccak)(funcName));
|
|
74
|
-
}
|
|
75
|
-
exports.getSelectorFromName = getSelectorFromName;
|
|
76
62
|
function randomAddress() {
|
|
77
63
|
var randomKeyPair = (0, ellipticCurve_1.genKeyPair)();
|
|
78
64
|
return (0, ellipticCurve_1.getStarkKey)(randomKeyPair);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ParsedStruct } from '../contract';
|
|
2
|
+
import { Call } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Transforms a list of Calls, each with their own calldata, into
|
|
5
|
+
* two arrays: one with the entrypoints, and one with the concatenated calldata.
|
|
6
|
+
* @param calls
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare const transformCallsToMulticallArrays: (calls: Call[]) => {
|
|
10
|
+
callArray: ParsedStruct[];
|
|
11
|
+
calldata: string[];
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Transforms a list of calls in the full flattened calldata expected
|
|
15
|
+
* by the __execute__ protocol.
|
|
16
|
+
* @param calls
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
export declare const fromCallsToExecuteCalldata: (calls: Call[]) => string[];
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __read =
|
|
3
|
+
(this && this.__read) ||
|
|
4
|
+
function (o, n) {
|
|
5
|
+
var m = typeof Symbol === 'function' && o[Symbol.iterator];
|
|
6
|
+
if (!m) return o;
|
|
7
|
+
var i = m.call(o),
|
|
8
|
+
r,
|
|
9
|
+
ar = [],
|
|
10
|
+
e;
|
|
11
|
+
try {
|
|
12
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
13
|
+
} catch (error) {
|
|
14
|
+
e = { error: error };
|
|
15
|
+
} finally {
|
|
16
|
+
try {
|
|
17
|
+
if (r && !r.done && (m = i['return'])) m.call(i);
|
|
18
|
+
} finally {
|
|
19
|
+
if (e) throw e.error;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return ar;
|
|
23
|
+
};
|
|
24
|
+
var __spreadArray =
|
|
25
|
+
(this && this.__spreadArray) ||
|
|
26
|
+
function (to, from, pack) {
|
|
27
|
+
if (pack || arguments.length === 2)
|
|
28
|
+
for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
29
|
+
if (ar || !(i in from)) {
|
|
30
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
31
|
+
ar[i] = from[i];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
35
|
+
};
|
|
36
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
37
|
+
exports.fromCallsToExecuteCalldata = exports.transformCallsToMulticallArrays = void 0;
|
|
38
|
+
var hash_1 = require('./hash');
|
|
39
|
+
var number_1 = require('./number');
|
|
40
|
+
/**
|
|
41
|
+
* Transforms a list of Calls, each with their own calldata, into
|
|
42
|
+
* two arrays: one with the entrypoints, and one with the concatenated calldata.
|
|
43
|
+
* @param calls
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
var transformCallsToMulticallArrays = function (calls) {
|
|
47
|
+
var callArray = [];
|
|
48
|
+
var calldata = [];
|
|
49
|
+
calls.forEach(function (call) {
|
|
50
|
+
var data = call.calldata || [];
|
|
51
|
+
callArray.push({
|
|
52
|
+
to: (0, number_1.toBN)(call.contractAddress).toString(10),
|
|
53
|
+
selector: (0, number_1.toBN)((0, hash_1.getSelectorFromName)(call.entrypoint)).toString(10),
|
|
54
|
+
data_offset: calldata.length.toString(),
|
|
55
|
+
data_len: data.length.toString(),
|
|
56
|
+
});
|
|
57
|
+
calldata.push.apply(calldata, __spreadArray([], __read(data), false));
|
|
58
|
+
});
|
|
59
|
+
return {
|
|
60
|
+
callArray: callArray,
|
|
61
|
+
calldata: (0, number_1.bigNumberishArrayToDecimalStringArray)(calldata),
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
exports.transformCallsToMulticallArrays = transformCallsToMulticallArrays;
|
|
65
|
+
/**
|
|
66
|
+
* Transforms a list of calls in the full flattened calldata expected
|
|
67
|
+
* by the __execute__ protocol.
|
|
68
|
+
* @param calls
|
|
69
|
+
* @returns
|
|
70
|
+
*/
|
|
71
|
+
var fromCallsToExecuteCalldata = function (calls) {
|
|
72
|
+
var _a = (0, exports.transformCallsToMulticallArrays)(calls),
|
|
73
|
+
callArray = _a.callArray,
|
|
74
|
+
calldata = _a.calldata;
|
|
75
|
+
return __spreadArray(
|
|
76
|
+
__spreadArray(
|
|
77
|
+
__spreadArray(
|
|
78
|
+
[callArray.length.toString()],
|
|
79
|
+
__read(
|
|
80
|
+
callArray
|
|
81
|
+
.map(function (_a) {
|
|
82
|
+
var to = _a.to,
|
|
83
|
+
selector = _a.selector,
|
|
84
|
+
data_offset = _a.data_offset,
|
|
85
|
+
data_len = _a.data_len;
|
|
86
|
+
return [to, selector, data_offset, data_len];
|
|
87
|
+
})
|
|
88
|
+
.flat()
|
|
89
|
+
),
|
|
90
|
+
false
|
|
91
|
+
),
|
|
92
|
+
[calldata.length.toString()],
|
|
93
|
+
false
|
|
94
|
+
),
|
|
95
|
+
__read(calldata),
|
|
96
|
+
false
|
|
97
|
+
);
|
|
98
|
+
};
|
|
99
|
+
exports.fromCallsToExecuteCalldata = fromCallsToExecuteCalldata;
|
|
@@ -107,7 +107,7 @@ export declare const getStructHash: <
|
|
|
107
107
|
* with Keccak256.
|
|
108
108
|
*
|
|
109
109
|
* @param {TypedData} typedData
|
|
110
|
-
* @param {
|
|
110
|
+
* @param {BigNumberish} account
|
|
111
111
|
* @return {string}
|
|
112
112
|
*/
|
|
113
113
|
export declare const getMessageHash: (typedData: TypedData, account: BigNumberish) => string;
|
package/utils/typedData/index.js
CHANGED
|
@@ -67,7 +67,6 @@ exports.getMessageHash =
|
|
|
67
67
|
var hash_1 = require('../hash');
|
|
68
68
|
var number_1 = require('../number');
|
|
69
69
|
var shortString_1 = require('../shortString');
|
|
70
|
-
var stark_1 = require('../stark');
|
|
71
70
|
var utils_1 = require('./utils');
|
|
72
71
|
__exportStar(require('./types'), exports);
|
|
73
72
|
function getHex(value) {
|
|
@@ -156,7 +155,7 @@ exports.encodeType = encodeType;
|
|
|
156
155
|
* @return {string}
|
|
157
156
|
*/
|
|
158
157
|
var getTypeHash = function (typedData, type) {
|
|
159
|
-
return (0,
|
|
158
|
+
return (0, hash_1.getSelectorFromName)((0, exports.encodeType)(typedData, type));
|
|
160
159
|
};
|
|
161
160
|
exports.getTypeHash = getTypeHash;
|
|
162
161
|
/**
|
|
@@ -232,7 +231,7 @@ exports.getStructHash = getStructHash;
|
|
|
232
231
|
* with Keccak256.
|
|
233
232
|
*
|
|
234
233
|
* @param {TypedData} typedData
|
|
235
|
-
* @param {
|
|
234
|
+
* @param {BigNumberish} account
|
|
236
235
|
* @return {string}
|
|
237
236
|
*/
|
|
238
237
|
var getMessageHash = function (typedData, account) {
|