@@ -3,15 +3,6 @@ import type { CommandModule } from 'yargs'
3
3
import { Payload } from '@0xsequence/wallet-primitives'
4
4
import { fromPosOrStdin } from '../utils.js'
5
5
6
- export const KIND_TRANSACTIONS = 0x00
7
- const KIND_MESSAGE = 0x01
8
- const KIND_CONFIG_UPDATE = 0x02
9
- const KIND_DIGEST = 0x03
10
-
11
- const BEHAVIOR_IGNORE_ERROR = 0x00
12
- const BEHAVIOR_REVERT_ON_ERROR = 0x01
13
- const BEHAVIOR_ABORT_ON_ERROR = 0x02
14
-
15
6
const CallAbi = [
16
7
{ type : 'address' , name : 'to' } ,
17
8
{ type : 'uint256' , name : 'value' } ,
@@ -38,98 +29,17 @@ export const DecodedAbi = [
38
29
{ type : 'address[]' , name : 'parentWallets' } ,
39
30
]
40
31
41
- export interface SolidityDecoded {
42
- kind : number
43
- noChainId : boolean
44
- calls : SolidityCall [ ]
45
- space : bigint
46
- nonce : bigint
47
- message : string
48
- imageHash : string
49
- digest : string
50
- parentWallets : string [ ]
51
- }
52
-
53
- interface SolidityCall {
54
- to : string
55
- value : bigint
56
- data : string
57
- gasLimit : bigint
58
- delegateCall : boolean
59
- onlyFallback : boolean
60
- behaviorOnError : bigint
61
- }
62
-
63
- function behaviorOnError ( behavior : number ) : 'ignore' | 'revert' | 'abort' {
64
- switch ( behavior ) {
65
- case BEHAVIOR_IGNORE_ERROR :
66
- return 'ignore'
67
- case BEHAVIOR_REVERT_ON_ERROR :
68
- return 'revert'
69
- case BEHAVIOR_ABORT_ON_ERROR :
70
- return 'abort'
71
- default :
72
- throw new Error ( `Unknown behavior: ${ behavior } ` )
73
- }
74
- }
75
-
76
32
export async function doConvertToAbi ( _payload : string ) : Promise < string > {
77
33
// Not implemented yet, but following the pattern
78
34
throw new Error ( 'Not implemented' )
79
35
}
80
36
81
- export function solidityEncodedToParentedPayload ( decoded : SolidityDecoded ) : Payload . Parented {
82
- if ( decoded . kind === KIND_TRANSACTIONS ) {
83
- return {
84
- type : 'call' ,
85
- nonce : decoded . nonce ,
86
- space : decoded . space ,
87
- calls : decoded . calls . map ( ( call ) => ( {
88
- to : Address . from ( call . to ) ,
89
- value : call . value ,
90
- data : call . data as `0x${string } `,
91
- gasLimit : call . gasLimit ,
92
- delegateCall : call . delegateCall ,
93
- onlyFallback : call . onlyFallback ,
94
- behaviorOnError : behaviorOnError ( Number ( call . behaviorOnError ) ) ,
95
- } ) ) ,
96
- parentWallets : decoded . parentWallets . map ( ( wallet ) => Address . from ( wallet ) ) ,
97
- }
98
- }
99
-
100
- if ( decoded . kind === KIND_MESSAGE ) {
101
- return {
102
- type : 'message' ,
103
- message : decoded . message as `0x${string } `,
104
- parentWallets : decoded . parentWallets . map ( ( wallet ) => Address . from ( wallet ) ) ,
105
- }
106
- }
107
-
108
- if ( decoded . kind === KIND_CONFIG_UPDATE ) {
109
- return {
110
- type : 'config-update' ,
111
- imageHash : decoded . imageHash as `0x${string } `,
112
- parentWallets : decoded . parentWallets . map ( ( wallet ) => Address . from ( wallet ) ) ,
113
- }
114
- }
115
-
116
- if ( decoded . kind === KIND_DIGEST ) {
117
- return {
118
- type : 'digest' ,
119
- digest : decoded . digest as `0x${string } `,
120
- parentWallets : decoded . parentWallets . map ( ( wallet ) => Address . from ( wallet ) ) ,
121
- }
122
- }
123
-
124
- throw new Error ( 'Not implemented' )
125
- }
126
-
127
37
export async function doConvertToPacked ( payload : string , wallet ?: string ) : Promise < string > {
128
- const decodedPayload = solidityEncodedToParentedPayload (
38
+ const decodedPayload = Payload . fromAbiFormat (
129
39
AbiParameters . decode (
130
40
[ { type : 'tuple' , name : 'payload' , components : DecodedAbi } ] ,
131
41
payload as Hex . Hex ,
132
- ) [ 0 ] as unknown as SolidityDecoded ,
42
+ ) [ 0 ] as unknown as Payload . SolidityDecoded ,
133
43
)
134
44
135
45
if ( Payload . isCalls ( decodedPayload ) ) {
@@ -144,7 +54,7 @@ export async function doConvertToJson(payload: string): Promise<string> {
144
54
const decoded = AbiParameters . decode (
145
55
[ { type : 'tuple' , name : 'payload' , components : DecodedAbi } ] ,
146
56
payload as Hex . Hex ,
147
- ) [ 0 ] as unknown as SolidityDecoded
57
+ ) [ 0 ] as unknown as Payload . SolidityDecoded
148
58
149
59
const json = JSON . stringify ( decoded )
150
60
return json
@@ -154,9 +64,9 @@ export async function doHash(wallet: string, chainId: bigint, payload: string):
154
64
const decoded = AbiParameters . decode (
155
65
[ { type : 'tuple' , name : 'payload' , components : DecodedAbi } ] ,
156
66
payload as Hex . Hex ,
157
- ) [ 0 ] as unknown as SolidityDecoded
67
+ ) [ 0 ] as unknown as Payload . SolidityDecoded
158
68
159
- return Hex . from ( Payload . hash ( Address . from ( wallet ) , chainId , solidityEncodedToParentedPayload ( decoded ) ) )
69
+ return Hex . from ( Payload . hash ( Address . from ( wallet ) , chainId , Payload . fromAbiFormat ( decoded ) ) )
160
70
}
161
71
162
72
const payloadCommand : CommandModule = {
0 commit comments