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/provider/interface.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AddTransactionResponse,
|
|
3
|
-
|
|
3
|
+
Call,
|
|
4
4
|
CallContractResponse,
|
|
5
|
-
|
|
6
|
-
CompiledContract,
|
|
5
|
+
DeployContractPayload,
|
|
7
6
|
GetBlockResponse,
|
|
8
7
|
GetCodeResponse,
|
|
9
8
|
GetContractAddressesResponse,
|
|
10
9
|
GetTransactionResponse,
|
|
11
10
|
GetTransactionStatusResponse,
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
Invocation,
|
|
12
|
+
TransactionReceipt,
|
|
14
13
|
} from '../types';
|
|
15
14
|
import type { BigNumberish } from '../utils/number';
|
|
15
|
+
import { BlockIdentifier } from './utils';
|
|
16
16
|
export declare abstract class ProviderInterface {
|
|
17
17
|
abstract baseUrl: string;
|
|
18
18
|
abstract feederGatewayUrl: string;
|
|
@@ -29,40 +29,35 @@ export declare abstract class ProviderInterface {
|
|
|
29
29
|
*
|
|
30
30
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L25-L39)
|
|
31
31
|
*
|
|
32
|
-
* @param invokeTransaction
|
|
33
|
-
* @param
|
|
34
|
-
* @param blockNumber
|
|
32
|
+
* @param invokeTransaction transaction to be invoked
|
|
33
|
+
* @param blockIdentifier block identifier
|
|
35
34
|
* @returns the result of the function on the smart contract.
|
|
36
35
|
*/
|
|
37
36
|
abstract callContract(
|
|
38
|
-
invokeTransaction:
|
|
39
|
-
|
|
40
|
-
blockNumber?: BlockNumber
|
|
37
|
+
invokeTransaction: Call,
|
|
38
|
+
blockIdentifier?: BlockIdentifier
|
|
41
39
|
): Promise<CallContractResponse>;
|
|
42
40
|
/**
|
|
43
41
|
* Gets the block information
|
|
44
42
|
*
|
|
45
43
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L41-L53)
|
|
46
44
|
*
|
|
47
|
-
* @param
|
|
48
|
-
* @param blockNumber
|
|
45
|
+
* @param blockIdentifier block identifier
|
|
49
46
|
* @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
|
|
50
47
|
*/
|
|
51
|
-
abstract getBlock(
|
|
48
|
+
abstract getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
|
|
52
49
|
/**
|
|
53
50
|
* Gets the code of the deployed contract.
|
|
54
51
|
*
|
|
55
52
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L55-L68)
|
|
56
53
|
*
|
|
57
|
-
* @param contractAddress
|
|
58
|
-
* @param
|
|
59
|
-
* @param blockNumber
|
|
54
|
+
* @param contractAddress - contract address
|
|
55
|
+
* @param blockIdentifier - block identifier
|
|
60
56
|
* @returns Bytecode and ABI of compiled contract
|
|
61
57
|
*/
|
|
62
58
|
abstract getCode(
|
|
63
59
|
contractAddress: string,
|
|
64
|
-
|
|
65
|
-
blockNumber?: BlockNumber
|
|
60
|
+
blockIdentifier?: BlockIdentifier
|
|
66
61
|
): Promise<GetCodeResponse>;
|
|
67
62
|
/**
|
|
68
63
|
* Gets the contract's storage variable at a specific key.
|
|
@@ -71,15 +66,13 @@ export declare abstract class ProviderInterface {
|
|
|
71
66
|
*
|
|
72
67
|
* @param contractAddress
|
|
73
68
|
* @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
|
|
74
|
-
* @param
|
|
75
|
-
* @param blockNumber
|
|
69
|
+
* @param blockIdentifier - block identifier
|
|
76
70
|
* @returns the value of the storage variable
|
|
77
71
|
*/
|
|
78
72
|
abstract getStorageAt(
|
|
79
73
|
contractAddress: string,
|
|
80
74
|
key: number,
|
|
81
|
-
|
|
82
|
-
blockNumber?: BlockNumber
|
|
75
|
+
blockIdentifier?: BlockIdentifier
|
|
83
76
|
): Promise<object>;
|
|
84
77
|
/**
|
|
85
78
|
* Gets the status of a transaction.
|
|
@@ -99,41 +92,35 @@ export declare abstract class ProviderInterface {
|
|
|
99
92
|
* @returns the transacton object { transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? }
|
|
100
93
|
*/
|
|
101
94
|
abstract getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
*/
|
|
110
|
-
abstract addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
|
|
95
|
+
abstract getTransactionReceipt({
|
|
96
|
+
txHash,
|
|
97
|
+
txId,
|
|
98
|
+
}: {
|
|
99
|
+
txHash?: BigNumberish;
|
|
100
|
+
txId?: BigNumberish;
|
|
101
|
+
}): Promise<TransactionReceipt>;
|
|
111
102
|
/**
|
|
112
103
|
* Deploys a given compiled contract (json) to starknet
|
|
113
104
|
*
|
|
114
|
-
* @param
|
|
115
|
-
*
|
|
105
|
+
* @param payload payload to be deployed containing:
|
|
106
|
+
* - compiled contract code
|
|
107
|
+
* - constructor calldata
|
|
108
|
+
* - address salt
|
|
116
109
|
* @returns a confirmation of sending a transaction on the starknet contract
|
|
117
110
|
*/
|
|
118
|
-
abstract deployContract(
|
|
119
|
-
contract: CompiledContract | string,
|
|
120
|
-
constructorCalldata: string[],
|
|
121
|
-
addressSalt: BigNumberish
|
|
122
|
-
): Promise<AddTransactionResponse>;
|
|
111
|
+
abstract deployContract(payload: DeployContractPayload): Promise<AddTransactionResponse>;
|
|
123
112
|
/**
|
|
124
113
|
* Invokes a function on starknet
|
|
114
|
+
* @deprecated This method wont be supported as soon as fees are mandatory
|
|
115
|
+
*
|
|
116
|
+
* @param invocation the invocation object containing:
|
|
117
|
+
* - contractAddress - the address of the contract
|
|
118
|
+
* - entrypoint - the entrypoint of the contract
|
|
119
|
+
* - calldata - (defaults to []) the calldata
|
|
120
|
+
* - signature - (defaults to []) the signature
|
|
125
121
|
*
|
|
126
|
-
* @param contractAddress - target contract address for invoke
|
|
127
|
-
* @param entrypointSelector - target entrypoint selector for
|
|
128
|
-
* @param calldata - (optional, default []) calldata
|
|
129
|
-
* @param signature - (optional) signature to send along
|
|
130
122
|
* @returns response from addTransaction
|
|
131
123
|
*/
|
|
132
|
-
abstract invokeFunction(
|
|
133
|
-
contractAddress: string,
|
|
134
|
-
entrypointSelector: string,
|
|
135
|
-
calldata?: string[],
|
|
136
|
-
signature?: Signature
|
|
137
|
-
): Promise<AddTransactionResponse>;
|
|
124
|
+
abstract invokeFunction(invocation: Invocation): Promise<AddTransactionResponse>;
|
|
138
125
|
abstract waitForTx(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
139
126
|
}
|
package/provider/utils.d.ts
CHANGED
|
@@ -1,20 +1,37 @@
|
|
|
1
1
|
import type { BlockNumber } from '../types';
|
|
2
2
|
import { BigNumberish } from '../utils/number';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
*
|
|
5
5
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L148-L153)
|
|
6
6
|
*
|
|
7
7
|
* @param hashValue
|
|
8
8
|
* @param hashField
|
|
9
9
|
*/
|
|
10
|
-
export declare function formatHash():
|
|
10
|
+
export declare function formatHash(hashValue: BigNumberish): string;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
*
|
|
13
13
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L156-L161)
|
|
14
14
|
* @param txHash
|
|
15
15
|
* @param txId
|
|
16
16
|
*/
|
|
17
|
-
export declare function txIdentifier():
|
|
17
|
+
export declare function txIdentifier(txHash?: BigNumberish, txId?: BigNumberish): string;
|
|
18
|
+
export declare type BlockIdentifier = BlockNumber | BigNumberish;
|
|
19
|
+
declare type BlockIdentifierObject =
|
|
20
|
+
| {
|
|
21
|
+
type: 'BLOCK_NUMBER';
|
|
22
|
+
data: BlockNumber;
|
|
23
|
+
}
|
|
24
|
+
| {
|
|
25
|
+
type: 'BLOCK_HASH';
|
|
26
|
+
data: BigNumberish;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Identifies the block to be queried.
|
|
30
|
+
*
|
|
31
|
+
* @param blockIdentifier - block identifier
|
|
32
|
+
* @returns block identifier object
|
|
33
|
+
*/
|
|
34
|
+
export declare function getBlockIdentifier(blockIdentifier: BlockIdentifier): BlockIdentifierObject;
|
|
18
35
|
/**
|
|
19
36
|
* Gets the block identifier for API request
|
|
20
37
|
*
|
|
@@ -24,7 +41,5 @@ export declare function txIdentifier(): void;
|
|
|
24
41
|
* @param blockHash
|
|
25
42
|
* @returns block identifier for API request
|
|
26
43
|
*/
|
|
27
|
-
export declare function getFormattedBlockIdentifier(
|
|
28
|
-
|
|
29
|
-
blockNumber?: BlockNumber
|
|
30
|
-
): string;
|
|
44
|
+
export declare function getFormattedBlockIdentifier(blockIdentifier?: BlockIdentifier): string;
|
|
45
|
+
export {};
|
package/provider/utils.js
CHANGED
|
@@ -1,23 +1,65 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
-
exports.getFormattedBlockIdentifier =
|
|
3
|
+
exports.getFormattedBlockIdentifier =
|
|
4
|
+
exports.getBlockIdentifier =
|
|
5
|
+
exports.txIdentifier =
|
|
6
|
+
exports.formatHash =
|
|
7
|
+
void 0;
|
|
8
|
+
var number_1 = require('../utils/number');
|
|
4
9
|
/**
|
|
5
|
-
*
|
|
10
|
+
*
|
|
6
11
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L148-L153)
|
|
7
12
|
*
|
|
8
13
|
* @param hashValue
|
|
9
14
|
* @param hashField
|
|
10
15
|
*/
|
|
11
|
-
function formatHash() {
|
|
16
|
+
function formatHash(hashValue) {
|
|
17
|
+
if (typeof hashValue === 'string') return hashValue;
|
|
18
|
+
return (0, number_1.toHex)((0, number_1.toBN)(hashValue));
|
|
19
|
+
}
|
|
12
20
|
exports.formatHash = formatHash;
|
|
13
21
|
/**
|
|
14
|
-
*
|
|
22
|
+
*
|
|
15
23
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L156-L161)
|
|
16
24
|
* @param txHash
|
|
17
25
|
* @param txId
|
|
18
26
|
*/
|
|
19
|
-
function txIdentifier() {
|
|
27
|
+
function txIdentifier(txHash, txId) {
|
|
28
|
+
if (!txHash) {
|
|
29
|
+
return 'transactionId=' + JSON.stringify(txId);
|
|
30
|
+
}
|
|
31
|
+
var hashString = formatHash(txHash);
|
|
32
|
+
return 'transactionHash=' + hashString;
|
|
33
|
+
}
|
|
20
34
|
exports.txIdentifier = txIdentifier;
|
|
35
|
+
/**
|
|
36
|
+
* Identifies the block to be queried.
|
|
37
|
+
*
|
|
38
|
+
* @param blockIdentifier - block identifier
|
|
39
|
+
* @returns block identifier object
|
|
40
|
+
*/
|
|
41
|
+
function getBlockIdentifier(blockIdentifier) {
|
|
42
|
+
if (typeof blockIdentifier === 'number') {
|
|
43
|
+
return { type: 'BLOCK_NUMBER', data: blockIdentifier };
|
|
44
|
+
}
|
|
45
|
+
if (typeof blockIdentifier === 'string' && blockIdentifier.startsWith('0x')) {
|
|
46
|
+
return { type: 'BLOCK_HASH', data: blockIdentifier };
|
|
47
|
+
}
|
|
48
|
+
if (typeof blockIdentifier === 'string' && !Number.isNaN(parseInt(blockIdentifier, 10))) {
|
|
49
|
+
return { type: 'BLOCK_NUMBER', data: parseInt(blockIdentifier, 10) };
|
|
50
|
+
}
|
|
51
|
+
if (blockIdentifier === null) {
|
|
52
|
+
return { type: 'BLOCK_NUMBER', data: null };
|
|
53
|
+
}
|
|
54
|
+
if (blockIdentifier === 'pending') {
|
|
55
|
+
return { type: 'BLOCK_NUMBER', data: 'pending' };
|
|
56
|
+
}
|
|
57
|
+
if (typeof blockIdentifier === 'string') {
|
|
58
|
+
throw new Error('Invalid block identifier: ' + blockIdentifier);
|
|
59
|
+
}
|
|
60
|
+
return { type: 'BLOCK_HASH', data: blockIdentifier };
|
|
61
|
+
}
|
|
62
|
+
exports.getBlockIdentifier = getBlockIdentifier;
|
|
21
63
|
/**
|
|
22
64
|
* Gets the block identifier for API request
|
|
23
65
|
*
|
|
@@ -27,13 +69,17 @@ exports.txIdentifier = txIdentifier;
|
|
|
27
69
|
* @param blockHash
|
|
28
70
|
* @returns block identifier for API request
|
|
29
71
|
*/
|
|
30
|
-
function getFormattedBlockIdentifier(
|
|
31
|
-
if (
|
|
32
|
-
|
|
72
|
+
function getFormattedBlockIdentifier(blockIdentifier) {
|
|
73
|
+
if (blockIdentifier === void 0) {
|
|
74
|
+
blockIdentifier = null;
|
|
75
|
+
}
|
|
76
|
+
var blockIdentifierObject = getBlockIdentifier(blockIdentifier);
|
|
77
|
+
if (blockIdentifierObject.type === 'BLOCK_NUMBER' && blockIdentifierObject.data === null) {
|
|
78
|
+
return '';
|
|
33
79
|
}
|
|
34
|
-
if (
|
|
35
|
-
return '
|
|
80
|
+
if (blockIdentifierObject.type === 'BLOCK_NUMBER') {
|
|
81
|
+
return 'blockNumber=' + blockIdentifierObject.data;
|
|
36
82
|
}
|
|
37
|
-
return '
|
|
83
|
+
return 'blockHash=' + (0, number_1.toHex)((0, number_1.toBN)(blockIdentifierObject.data));
|
|
38
84
|
}
|
|
39
85
|
exports.getFormattedBlockIdentifier = getFormattedBlockIdentifier;
|
package/signer/default.d.ts
CHANGED
|
@@ -1,34 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AddTransactionResponse, KeyPair, Signature, Transaction } from '../types';
|
|
1
|
+
import { Abi, Invocation, InvocationsSignerDetails, KeyPair, Signature } from '../types';
|
|
3
2
|
import { TypedData } from '../utils/typedData';
|
|
4
3
|
import { SignerInterface } from './interface';
|
|
5
|
-
export declare class Signer
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* @returns a confirmation of invoking a function on the starknet contract
|
|
16
|
-
*/
|
|
17
|
-
addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
|
|
18
|
-
/**
|
|
19
|
-
* Sign an JSON object with the starknet private key and return the signature
|
|
20
|
-
*
|
|
21
|
-
* @param json - JSON object to be signed
|
|
22
|
-
* @returns the signature of the JSON object
|
|
23
|
-
* @throws {Error} if the JSON object is not a valid JSON
|
|
24
|
-
*/
|
|
25
|
-
signMessage(typedData: TypedData): Promise<Signature>;
|
|
26
|
-
/**
|
|
27
|
-
* Hash a JSON object with pederson hash and return the hash
|
|
28
|
-
*
|
|
29
|
-
* @param json - JSON object to be hashed
|
|
30
|
-
* @returns the hash of the JSON object
|
|
31
|
-
* @throws {Error} if the JSON object is not a valid JSON
|
|
32
|
-
*/
|
|
33
|
-
hashMessage(typedData: TypedData): Promise<string>;
|
|
4
|
+
export declare class Signer implements SignerInterface {
|
|
5
|
+
protected keyPair: KeyPair;
|
|
6
|
+
constructor(keyPair: KeyPair);
|
|
7
|
+
getPubKey(): Promise<string>;
|
|
8
|
+
signTransaction(
|
|
9
|
+
transactions: Invocation[],
|
|
10
|
+
transactionsDetail: InvocationsSignerDetails,
|
|
11
|
+
abis?: Abi[]
|
|
12
|
+
): Promise<Signature>;
|
|
13
|
+
signMessage(typedData: TypedData, walletAddress: string): Promise<Signature>;
|
|
34
14
|
}
|
package/signer/default.js
CHANGED
|
@@ -1,29 +1,4 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
var __extends =
|
|
3
|
-
(this && this.__extends) ||
|
|
4
|
-
(function () {
|
|
5
|
-
var extendStatics = function (d, b) {
|
|
6
|
-
extendStatics =
|
|
7
|
-
Object.setPrototypeOf ||
|
|
8
|
-
({ __proto__: [] } instanceof Array &&
|
|
9
|
-
function (d, b) {
|
|
10
|
-
d.__proto__ = b;
|
|
11
|
-
}) ||
|
|
12
|
-
function (d, b) {
|
|
13
|
-
for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
|
14
|
-
};
|
|
15
|
-
return extendStatics(d, b);
|
|
16
|
-
};
|
|
17
|
-
return function (d, b) {
|
|
18
|
-
if (typeof b !== 'function' && b !== null)
|
|
19
|
-
throw new TypeError('Class extends value ' + String(b) + ' is not a constructor or null');
|
|
20
|
-
extendStatics(d, b);
|
|
21
|
-
function __() {
|
|
22
|
-
this.constructor = d;
|
|
23
|
-
}
|
|
24
|
-
d.prototype = b === null ? Object.create(b) : ((__.prototype = b.prototype), new __());
|
|
25
|
-
};
|
|
26
|
-
})();
|
|
27
2
|
var __awaiter =
|
|
28
3
|
(this && this.__awaiter) ||
|
|
29
4
|
function (thisArg, _arguments, P, generator) {
|
|
@@ -155,174 +130,82 @@ var __generator =
|
|
|
155
130
|
return { value: op[0] ? op[1] : void 0, done: true };
|
|
156
131
|
}
|
|
157
132
|
};
|
|
158
|
-
var __read =
|
|
159
|
-
(this && this.__read) ||
|
|
160
|
-
function (o, n) {
|
|
161
|
-
var m = typeof Symbol === 'function' && o[Symbol.iterator];
|
|
162
|
-
if (!m) return o;
|
|
163
|
-
var i = m.call(o),
|
|
164
|
-
r,
|
|
165
|
-
ar = [],
|
|
166
|
-
e;
|
|
167
|
-
try {
|
|
168
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
169
|
-
} catch (error) {
|
|
170
|
-
e = { error: error };
|
|
171
|
-
} finally {
|
|
172
|
-
try {
|
|
173
|
-
if (r && !r.done && (m = i['return'])) m.call(i);
|
|
174
|
-
} finally {
|
|
175
|
-
if (e) throw e.error;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return ar;
|
|
179
|
-
};
|
|
180
|
-
var __spreadArray =
|
|
181
|
-
(this && this.__spreadArray) ||
|
|
182
|
-
function (to, from, pack) {
|
|
183
|
-
if (pack || arguments.length === 2)
|
|
184
|
-
for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
185
|
-
if (ar || !(i in from)) {
|
|
186
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
187
|
-
ar[i] = from[i];
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
191
|
-
};
|
|
192
|
-
var __importDefault =
|
|
193
|
-
(this && this.__importDefault) ||
|
|
194
|
-
function (mod) {
|
|
195
|
-
return mod && mod.__esModule ? mod : { default: mod };
|
|
196
|
-
};
|
|
197
133
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
198
134
|
exports.Signer = void 0;
|
|
199
|
-
var minimalistic_assert_1 = __importDefault(require('minimalistic-assert'));
|
|
200
|
-
var provider_1 = require('../provider');
|
|
201
135
|
var ellipticCurve_1 = require('../utils/ellipticCurve');
|
|
202
136
|
var encode_1 = require('../utils/encode');
|
|
203
137
|
var hash_1 = require('../utils/hash');
|
|
204
138
|
var number_1 = require('../utils/number');
|
|
205
139
|
var stark_1 = require('../utils/stark');
|
|
206
140
|
var typedData_1 = require('../utils/typedData');
|
|
207
|
-
var Signer = /** @class */ (function (
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
var _this = _super.call(this, provider) || this;
|
|
211
|
-
_this.keyPair = keyPair;
|
|
212
|
-
_this.address = address;
|
|
213
|
-
return _this;
|
|
141
|
+
var Signer = /** @class */ (function () {
|
|
142
|
+
function Signer(keyPair) {
|
|
143
|
+
this.keyPair = keyPair;
|
|
214
144
|
}
|
|
215
|
-
|
|
216
|
-
* Invoke a function on the starknet contract
|
|
217
|
-
*
|
|
218
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
|
|
219
|
-
*
|
|
220
|
-
* @param transaction - transaction to be invoked
|
|
221
|
-
* @returns a confirmation of invoking a function on the starknet contract
|
|
222
|
-
*/
|
|
223
|
-
Signer.prototype.addTransaction = function (transaction) {
|
|
145
|
+
Signer.prototype.getPubKey = function () {
|
|
224
146
|
return __awaiter(this, void 0, void 0, function () {
|
|
225
|
-
var nonceBn, result, calldataDecimal, msgHash, signature;
|
|
226
147
|
return __generator(this, function (_a) {
|
|
227
|
-
|
|
228
|
-
case 0:
|
|
229
|
-
if (transaction.type === 'DEPLOY')
|
|
230
|
-
return [2 /*return*/, _super.prototype.addTransaction.call(this, transaction)];
|
|
231
|
-
(0,
|
|
232
|
-
minimalistic_assert_1.default)(!transaction.signature, "Adding signatures to a signer transaction currently isn't supported");
|
|
233
|
-
if (!transaction.nonce) return [3 /*break*/, 1];
|
|
234
|
-
nonceBn = (0, number_1.toBN)(transaction.nonce);
|
|
235
|
-
return [3 /*break*/, 3];
|
|
236
|
-
case 1:
|
|
237
|
-
return [
|
|
238
|
-
4 /*yield*/,
|
|
239
|
-
this.callContract({
|
|
240
|
-
contract_address: this.address,
|
|
241
|
-
entry_point_selector: (0, stark_1.getSelectorFromName)('get_nonce'),
|
|
242
|
-
}),
|
|
243
|
-
];
|
|
244
|
-
case 2:
|
|
245
|
-
result = _a.sent().result;
|
|
246
|
-
nonceBn = (0, number_1.toBN)(result[0]);
|
|
247
|
-
_a.label = 3;
|
|
248
|
-
case 3:
|
|
249
|
-
calldataDecimal = (transaction.calldata || []).map(function (x) {
|
|
250
|
-
return (0, number_1.toBN)(x).toString();
|
|
251
|
-
});
|
|
252
|
-
msgHash = (0, encode_1.addHexPrefix)(
|
|
253
|
-
(0, hash_1.hashMessage)(
|
|
254
|
-
this.address,
|
|
255
|
-
transaction.contract_address,
|
|
256
|
-
transaction.entry_point_selector,
|
|
257
|
-
calldataDecimal,
|
|
258
|
-
nonceBn.toString()
|
|
259
|
-
)
|
|
260
|
-
);
|
|
261
|
-
signature = (0, ellipticCurve_1.sign)(this.keyPair, msgHash);
|
|
262
|
-
return [
|
|
263
|
-
2 /*return*/,
|
|
264
|
-
_super.prototype.addTransaction.call(this, {
|
|
265
|
-
type: 'INVOKE_FUNCTION',
|
|
266
|
-
entry_point_selector: (0, stark_1.getSelectorFromName)('execute'),
|
|
267
|
-
calldata: __spreadArray(
|
|
268
|
-
__spreadArray(
|
|
269
|
-
[
|
|
270
|
-
transaction.contract_address,
|
|
271
|
-
transaction.entry_point_selector,
|
|
272
|
-
calldataDecimal.length.toString(),
|
|
273
|
-
],
|
|
274
|
-
__read(calldataDecimal),
|
|
275
|
-
false
|
|
276
|
-
),
|
|
277
|
-
[nonceBn.toString()],
|
|
278
|
-
false
|
|
279
|
-
).map(function (x) {
|
|
280
|
-
return (0, number_1.toBN)(x).toString();
|
|
281
|
-
}),
|
|
282
|
-
contract_address: this.address,
|
|
283
|
-
signature: signature,
|
|
284
|
-
}),
|
|
285
|
-
];
|
|
286
|
-
}
|
|
148
|
+
return [2 /*return*/, (0, ellipticCurve_1.getStarkKey)(this.keyPair)];
|
|
287
149
|
});
|
|
288
150
|
});
|
|
289
151
|
};
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
* @returns the signature of the JSON object
|
|
295
|
-
* @throws {Error} if the JSON object is not a valid JSON
|
|
296
|
-
*/
|
|
297
|
-
Signer.prototype.signMessage = function (typedData) {
|
|
152
|
+
Signer.prototype.signTransaction = function (transactions, transactionsDetail, abis) {
|
|
153
|
+
if (abis === void 0) {
|
|
154
|
+
abis = [];
|
|
155
|
+
}
|
|
298
156
|
return __awaiter(this, void 0, void 0, function () {
|
|
299
|
-
var _a,
|
|
157
|
+
var _a,
|
|
158
|
+
contractAddress,
|
|
159
|
+
entrypoint,
|
|
160
|
+
_b,
|
|
161
|
+
calldata,
|
|
162
|
+
nonce,
|
|
163
|
+
walletAddress,
|
|
164
|
+
nonceBn,
|
|
165
|
+
entrypointSelector,
|
|
166
|
+
calldataDecimal,
|
|
167
|
+
msgHash;
|
|
300
168
|
return __generator(this, function (_c) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
169
|
+
if (transactions.length !== 1) {
|
|
170
|
+
throw new Error('Only one transaction at a time is currently supported by this signer');
|
|
171
|
+
}
|
|
172
|
+
if (
|
|
173
|
+
(abis === null || abis === void 0 ? void 0 : abis.length) !== 0 &&
|
|
174
|
+
abis.length !== transactions.length
|
|
175
|
+
) {
|
|
176
|
+
throw new Error('ABI must be provided for each transaction or no transaction');
|
|
308
177
|
}
|
|
178
|
+
(_a = transactions[0]),
|
|
179
|
+
(contractAddress = _a.contractAddress),
|
|
180
|
+
(entrypoint = _a.entrypoint),
|
|
181
|
+
(_b = _a.calldata),
|
|
182
|
+
(calldata = _b === void 0 ? [] : _b);
|
|
183
|
+
(nonce = transactionsDetail.nonce), (walletAddress = transactionsDetail.walletAddress);
|
|
184
|
+
nonceBn = (0, number_1.toBN)(nonce);
|
|
185
|
+
entrypointSelector = (0, stark_1.getSelectorFromName)(entrypoint);
|
|
186
|
+
calldataDecimal = (0, number_1.bigNumberishArrayToDecimalStringArray)(calldata);
|
|
187
|
+
msgHash = (0, encode_1.addHexPrefix)(
|
|
188
|
+
(0, hash_1.hashMessage)(
|
|
189
|
+
walletAddress,
|
|
190
|
+
contractAddress,
|
|
191
|
+
entrypointSelector,
|
|
192
|
+
calldataDecimal,
|
|
193
|
+
nonceBn.toString()
|
|
194
|
+
)
|
|
195
|
+
);
|
|
196
|
+
return [2 /*return*/, (0, ellipticCurve_1.sign)(this.keyPair, msgHash)];
|
|
309
197
|
});
|
|
310
198
|
});
|
|
311
199
|
};
|
|
312
|
-
|
|
313
|
-
* Hash a JSON object with pederson hash and return the hash
|
|
314
|
-
*
|
|
315
|
-
* @param json - JSON object to be hashed
|
|
316
|
-
* @returns the hash of the JSON object
|
|
317
|
-
* @throws {Error} if the JSON object is not a valid JSON
|
|
318
|
-
*/
|
|
319
|
-
Signer.prototype.hashMessage = function (typedData) {
|
|
200
|
+
Signer.prototype.signMessage = function (typedData, walletAddress) {
|
|
320
201
|
return __awaiter(this, void 0, void 0, function () {
|
|
202
|
+
var msgHash;
|
|
321
203
|
return __generator(this, function (_a) {
|
|
322
|
-
|
|
204
|
+
msgHash = (0, typedData_1.getMessageHash)(typedData, walletAddress);
|
|
205
|
+
return [2 /*return*/, (0, ellipticCurve_1.sign)(this.keyPair, msgHash)];
|
|
323
206
|
});
|
|
324
207
|
});
|
|
325
208
|
};
|
|
326
209
|
return Signer;
|
|
327
|
-
})(
|
|
210
|
+
})();
|
|
328
211
|
exports.Signer = Signer;
|
package/signer/index.d.ts
CHANGED
package/signer/index.js
CHANGED
|
@@ -23,5 +23,5 @@ var __exportStar =
|
|
|
23
23
|
__createBinding(exports, m, p);
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
26
|
-
__exportStar(require('./default'), exports);
|
|
27
26
|
__exportStar(require('./interface'), exports);
|
|
27
|
+
__exportStar(require('./default'), exports);
|
package/signer/interface.d.ts
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export declare abstract class SignerInterface extends Provider {
|
|
5
|
-
abstract address: string;
|
|
1
|
+
import { Abi, Invocation, InvocationsSignerDetails, Signature } from '../types';
|
|
2
|
+
import { TypedData } from '../utils/typedData';
|
|
3
|
+
export declare abstract class SignerInterface {
|
|
6
4
|
/**
|
|
7
|
-
*
|
|
5
|
+
* Method to get the public key of the signer
|
|
8
6
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* @param transaction - transaction to be invoked
|
|
12
|
-
* @returns a confirmation of invoking a function on the starknet contract
|
|
7
|
+
* @returns public key of signer as hex string with 0x prefix
|
|
13
8
|
*/
|
|
14
|
-
abstract
|
|
9
|
+
abstract getPubKey(): Promise<string>;
|
|
15
10
|
/**
|
|
16
11
|
* Sign an JSON object for off-chain usage with the starknet private key and return the signature
|
|
17
12
|
* This adds a message prefix so it cant be interchanged with transactions
|
|
@@ -20,14 +15,22 @@ export declare abstract class SignerInterface extends Provider {
|
|
|
20
15
|
* @returns the signature of the JSON object
|
|
21
16
|
* @throws {Error} if the JSON object is not a valid JSON
|
|
22
17
|
*/
|
|
23
|
-
abstract signMessage(typedData: TypedData): Promise<Signature>;
|
|
18
|
+
abstract signMessage(typedData: TypedData, walletAddress: string): Promise<Signature>;
|
|
24
19
|
/**
|
|
25
|
-
*
|
|
26
|
-
* This adds a message prefix so it cant be interchanged with transactions
|
|
20
|
+
* Signs a transaction with the starknet private key and returns the signature
|
|
27
21
|
*
|
|
28
|
-
* @param
|
|
29
|
-
*
|
|
30
|
-
*
|
|
22
|
+
* @param invocation the invocation object containing:
|
|
23
|
+
* - contractAddress - the address of the contract
|
|
24
|
+
* - entrypoint - the entrypoint of the contract
|
|
25
|
+
* - calldata - (defaults to []) the calldata
|
|
26
|
+
* - signature - (defaults to []) the signature
|
|
27
|
+
* @param abi (optional) the abi of the contract for better displaying
|
|
28
|
+
*
|
|
29
|
+
* @returns signature
|
|
31
30
|
*/
|
|
32
|
-
abstract
|
|
31
|
+
abstract signTransaction(
|
|
32
|
+
transactions: Invocation[],
|
|
33
|
+
transactionsDetail: InvocationsSignerDetails,
|
|
34
|
+
abis?: Abi[]
|
|
35
|
+
): Promise<Signature>;
|
|
33
36
|
}
|