Skip to content

Commit dbea5de

Browse files
authored
fix: clean & avoid duplication (#39)
* 🗑️ Clean & avoid duplication * 🚨 Fix lint
1 parent 89aa7fb commit dbea5de

File tree

4 files changed

+78
-101
lines changed

4 files changed

+78
-101
lines changed

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/snip-29/components.ts

Lines changed: 10 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { ADDRESS, FELT, SIGNATURE, TXN_HASH } from '../api/components';
1+
import { ADDRESS, FELT, SIGNATURE } from '../api/components';
2+
import { OutsideExecutionTypedData, TIME_BOUNDS } from '../wallet-api';
23

34
// ******************
45
// * PRIMITIVES
@@ -9,15 +10,7 @@ import { ADDRESS, FELT, SIGNATURE, TXN_HASH } from '../api/components';
910
* @pattern ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,63})$
1011
*/
1112
export type u256 = string;
12-
/**
13-
* A string representing an unsigned integer
14-
* @pattern ^(0|[1-9]{1}[0-9]*)$
15-
*/
16-
export type NUMERIC = string;
17-
/**
18-
* UNIX time
19-
*/
20-
export type TIMESTAMP = NUMERIC;
13+
2114
/**
2215
* The object that defines an invocation of a function in a contract
2316
*/
@@ -26,87 +19,15 @@ export type CALL = {
2619
selector: FELT;
2720
calldata: FELT[];
2821
};
29-
/**
30-
* The transaction hash
31-
*/
32-
export type TRANSACTION_HASH = TXN_HASH;
22+
3323
/**
3424
* A unique identifier corresponding to an `execute` request to the paymaster
3525
*/
3626
export type TRACKING_ID = FELT;
37-
/**
38-
* "A typed data object (in the sense of SNIP-12) which represents an outside execution payload, according to SNIP-9
39-
*/
40-
export type OUTSIDE_EXECUTION_TYPED_DATA =
41-
| OUTSIDE_EXECUTION_TYPED_DATA_V1
42-
| OUTSIDE_EXECUTION_TYPED_DATA_V2;
43-
export type OUTSIDE_EXECUTION_TYPED_DATA_V1 = {
44-
types: Record<string, STARKNET_TYPE[]>;
45-
primaryType: string;
46-
domain: STARKNET_DOMAIN;
47-
message: OUTSIDE_EXECUTION_MESSAGE_V1;
48-
};
49-
export type OUTSIDE_EXECUTION_TYPED_DATA_V2 = {
50-
types: Record<string, STARKNET_TYPE[]>;
51-
primaryType: string;
52-
domain: STARKNET_DOMAIN;
53-
message: OUTSIDE_EXECUTION_MESSAGE_V2;
54-
};
55-
/**
56-
* A single type, as part of a struct. The `type` field can be any of the EIP-712 supported types
57-
*/
58-
export type STARKNET_TYPE =
59-
| {
60-
name: string;
61-
type: string;
62-
}
63-
| STARKNET_ENUM_TYPE
64-
| STARKNET_MERKLE_TYPE;
65-
export type STARKNET_ENUM_TYPE = {
66-
name: string;
67-
type: 'enum';
68-
contains: string;
69-
};
70-
export type STARKNET_MERKLE_TYPE = {
71-
name: string;
72-
type: 'merkletree';
73-
contains: string;
74-
};
75-
/**
76-
* A single type, as part of a struct. The `type` field can be any of the EIP-712 supported types
77-
*/
78-
export type STARKNET_DOMAIN = {
79-
name?: string;
80-
version?: string;
81-
chainId?: string | number;
82-
revision?: string | number;
83-
};
84-
export type OUTSIDE_EXECUTION_MESSAGE_V1 = {
85-
caller: FELT;
86-
nonce: FELT;
87-
execute_after: FELT;
88-
execute_before: FELT;
89-
calls_len: FELT;
90-
calls: OUTSIDE_CALL_V1[];
91-
};
92-
export type OUTSIDE_CALL_V1 = {
93-
to: ADDRESS;
94-
selector: FELT;
95-
calldata_len: FELT[];
96-
calldata: FELT[];
97-
};
98-
export type OUTSIDE_EXECUTION_MESSAGE_V2 = {
99-
Caller: FELT;
100-
Nonce: FELT;
101-
'Execute After': FELT;
102-
'Execute Before': FELT;
103-
Calls: OUTSIDE_CALL_V2[];
104-
};
105-
export type OUTSIDE_CALL_V2 = {
106-
To: ADDRESS;
107-
Selector: FELT;
108-
Calldata: FELT[];
109-
};
27+
28+
// ******************
29+
// * SNIP-29
30+
// ******************
11031

11132
/**
11233
* User transaction
@@ -146,7 +67,7 @@ export type EXECUTABLE_USER_INVOKE_TRANSACTION = {
14667
};
14768
export type EXECUTABLE_USER_INVOKE = {
14869
user_address: ADDRESS;
149-
typed_data: OUTSIDE_EXECUTION_TYPED_DATA;
70+
typed_data: OutsideExecutionTypedData;
15071
signature: SIGNATURE;
15172
};
15273
export type EXECUTABLE_USER_DEPLOY_AND_INVOKE_TRANSACTION = {
@@ -187,13 +108,7 @@ export type ACCOUNT_DEPLOYMENT_DATA = {
187108
sigdata?: FELT[];
188109
version: 1;
189110
};
190-
/**
191-
* Object containing timestamps corresponding to `Execute After` and `Execute Before`
192-
*/
193-
export type TIME_BOUNDS = {
194-
execute_after: TIMESTAMP;
195-
execute_before: TIMESTAMP;
196-
};
111+
197112
/**
198113
* Object containing data about the token: contract address, number of decimals and current price in STRK
199114
*/

src/snip-29/nonspec.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/**
22
* Types that are not in spec but required for UX
33
*/
4+
import { TXN_HASH } from '../api';
5+
import { OutsideExecutionTypedData } from '../wallet-api';
46
import {
57
ACCOUNT_DEPLOYMENT_DATA,
68
EXECUTION_PARAMETERS,
79
FEE_ESTIMATE,
8-
OUTSIDE_EXECUTION_TYPED_DATA,
910
TRACKING_ID,
10-
TRANSACTION_HASH,
1111
} from './components';
1212

1313
// METHOD RESPONSES
@@ -20,14 +20,14 @@ export type BuildDeployTransactionResponse = {
2020
};
2121
export type BuildInvokeTransactionResponse = {
2222
type: 'invoke';
23-
typed_data: OUTSIDE_EXECUTION_TYPED_DATA;
23+
typed_data: OutsideExecutionTypedData;
2424
parameters: EXECUTION_PARAMETERS;
2525
fee: FEE_ESTIMATE;
2626
};
2727
export type BuildDeployAndInvokeTransactionResponse = {
2828
type: 'deploy_and_invoke';
2929
deployment: ACCOUNT_DEPLOYMENT_DATA;
30-
typed_data: OUTSIDE_EXECUTION_TYPED_DATA;
30+
typed_data: OutsideExecutionTypedData;
3131
parameters: EXECUTION_PARAMETERS;
3232
fee: FEE_ESTIMATE;
3333
};
@@ -39,8 +39,7 @@ export type BuildTransactionResponse =
3939
// response paymaster_execute
4040
export type ExecuteResponse = {
4141
tracking_id: TRACKING_ID;
42-
transaction_hash: TRANSACTION_HASH;
42+
transaction_hash: TXN_HASH;
4343
};
4444

4545
export type AccountDeploymentData = ACCOUNT_DEPLOYMENT_DATA;
46-
export type OutsideExecutionTypedData = OUTSIDE_EXECUTION_TYPED_DATA;

src/wallet-api/typedData.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
1+
import { ADDRESS, FELT } from '../api/components.js';
12
import type { ABI_TYPE_ENUM } from '../api/constants.js';
23

4+
/**
5+
* A string representing an unsigned integer
6+
* @pattern ^(0|[1-9]{1}[0-9]*)$
7+
*/
8+
export type NUMERIC = string;
9+
/**
10+
* UNIX time
11+
*/
12+
export type TIMESTAMP = NUMERIC;
13+
14+
/**
15+
* Object containing timestamps corresponding to `Execute After` and `Execute Before`
16+
*/
17+
export type TIME_BOUNDS = {
18+
execute_after: TIMESTAMP;
19+
execute_before: TIMESTAMP;
20+
};
21+
322
export const TypedDataRevision = {
423
ACTIVE: '1',
524
LEGACY: '0',
@@ -54,3 +73,46 @@ export interface TypedData {
5473
domain: StarknetDomain;
5574
message: object;
5675
}
76+
77+
/**
78+
* "A typed data object (in the sense of SNIP-12) which represents an outside execution payload, according to SNIP-9
79+
*/
80+
export type OutsideExecutionTypedData = OutsideExecutionTypedDataV1 | OutsideExecutionTypedDataV2;
81+
export type OutsideExecutionTypedDataV1 = {
82+
types: Record<string, StarknetType[]>;
83+
primaryType: string;
84+
domain: StarknetDomain;
85+
message: OutsideExecutionMessageV1;
86+
};
87+
export type OutsideExecutionTypedDataV2 = {
88+
types: Record<string, StarknetType[]>;
89+
primaryType: string;
90+
domain: StarknetDomain;
91+
message: OutsideExecutionMessageV2;
92+
};
93+
export type OutsideExecutionMessageV1 = {
94+
caller: FELT;
95+
nonce: FELT;
96+
execute_after: FELT;
97+
execute_before: FELT;
98+
calls_len: FELT;
99+
calls: OutsideCallV1[];
100+
};
101+
export type OutsideCallV1 = {
102+
to: ADDRESS;
103+
selector: FELT;
104+
calldata_len: FELT[];
105+
calldata: FELT[];
106+
};
107+
export type OutsideExecutionMessageV2 = {
108+
Caller: FELT;
109+
Nonce: FELT;
110+
'Execute After': FELT;
111+
'Execute Before': FELT;
112+
Calls: OutsideCallV2[];
113+
};
114+
export type OutsideCallV2 = {
115+
To: ADDRESS;
116+
Selector: FELT;
117+
Calldata: FELT[];
118+
};

0 commit comments

Comments
 (0)