@0xsequence/wallet-wdk 0.0.0-20250520201059

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.
Files changed (173) hide show
  1. package/.env.test +3 -0
  2. package/.turbo/turbo-build.log +5 -0
  3. package/CHANGELOG.md +11 -0
  4. package/LICENSE +202 -0
  5. package/dist/dbs/auth-commitments.d.ts +17 -0
  6. package/dist/dbs/auth-commitments.d.ts.map +1 -0
  7. package/dist/dbs/auth-commitments.js +13 -0
  8. package/dist/dbs/auth-keys.d.ts +19 -0
  9. package/dist/dbs/auth-keys.d.ts.map +1 -0
  10. package/dist/dbs/auth-keys.js +67 -0
  11. package/dist/dbs/generic.d.ts +33 -0
  12. package/dist/dbs/generic.d.ts.map +1 -0
  13. package/dist/dbs/generic.js +170 -0
  14. package/dist/dbs/index.d.ts +12 -0
  15. package/dist/dbs/index.d.ts.map +1 -0
  16. package/dist/dbs/index.js +8 -0
  17. package/dist/dbs/messages.d.ts +6 -0
  18. package/dist/dbs/messages.d.ts.map +1 -0
  19. package/dist/dbs/messages.js +13 -0
  20. package/dist/dbs/recovery.d.ts +6 -0
  21. package/dist/dbs/recovery.d.ts.map +1 -0
  22. package/dist/dbs/recovery.js +13 -0
  23. package/dist/dbs/signatures.d.ts +6 -0
  24. package/dist/dbs/signatures.d.ts.map +1 -0
  25. package/dist/dbs/signatures.js +13 -0
  26. package/dist/dbs/transactions.d.ts +6 -0
  27. package/dist/dbs/transactions.d.ts.map +1 -0
  28. package/dist/dbs/transactions.js +13 -0
  29. package/dist/dbs/wallets.d.ts +6 -0
  30. package/dist/dbs/wallets.d.ts.map +1 -0
  31. package/dist/dbs/wallets.js +13 -0
  32. package/dist/identity/signer.d.ts +17 -0
  33. package/dist/identity/signer.d.ts.map +1 -0
  34. package/dist/identity/signer.js +58 -0
  35. package/dist/index.d.ts +3 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +2 -0
  38. package/dist/sequence/cron.d.ts +19 -0
  39. package/dist/sequence/cron.d.ts.map +1 -0
  40. package/dist/sequence/cron.js +118 -0
  41. package/dist/sequence/devices.d.ts +14 -0
  42. package/dist/sequence/devices.d.ts.map +1 -0
  43. package/dist/sequence/devices.js +43 -0
  44. package/dist/sequence/handlers/authcode-pkce.d.ts +14 -0
  45. package/dist/sequence/handlers/authcode-pkce.d.ts.map +1 -0
  46. package/dist/sequence/handlers/authcode-pkce.js +48 -0
  47. package/dist/sequence/handlers/authcode.d.ts +25 -0
  48. package/dist/sequence/handlers/authcode.d.ts.map +1 -0
  49. package/dist/sequence/handlers/authcode.js +91 -0
  50. package/dist/sequence/handlers/devices.d.ts +14 -0
  51. package/dist/sequence/handlers/devices.d.ts.map +1 -0
  52. package/dist/sequence/handlers/devices.js +39 -0
  53. package/dist/sequence/handlers/handler.d.ts +8 -0
  54. package/dist/sequence/handlers/handler.d.ts.map +1 -0
  55. package/dist/sequence/handlers/handler.js +1 -0
  56. package/dist/sequence/handlers/identity.d.ts +21 -0
  57. package/dist/sequence/handlers/identity.d.ts.map +1 -0
  58. package/dist/sequence/handlers/identity.js +86 -0
  59. package/dist/sequence/handlers/index.d.ts +7 -0
  60. package/dist/sequence/handlers/index.d.ts.map +1 -0
  61. package/dist/sequence/handlers/index.js +5 -0
  62. package/dist/sequence/handlers/mnemonic.d.ts +19 -0
  63. package/dist/sequence/handlers/mnemonic.d.ts.map +1 -0
  64. package/dist/sequence/handlers/mnemonic.js +67 -0
  65. package/dist/sequence/handlers/otp.d.ts +20 -0
  66. package/dist/sequence/handlers/otp.d.ts.map +1 -0
  67. package/dist/sequence/handlers/otp.js +83 -0
  68. package/dist/sequence/handlers/passkeys.d.ts +17 -0
  69. package/dist/sequence/handlers/passkeys.d.ts.map +1 -0
  70. package/dist/sequence/handlers/passkeys.js +63 -0
  71. package/dist/sequence/handlers/recovery.d.ts +15 -0
  72. package/dist/sequence/handlers/recovery.d.ts.map +1 -0
  73. package/dist/sequence/handlers/recovery.js +72 -0
  74. package/dist/sequence/index.d.ts +12 -0
  75. package/dist/sequence/index.d.ts.map +1 -0
  76. package/dist/sequence/index.js +9 -0
  77. package/dist/sequence/logger.d.ts +7 -0
  78. package/dist/sequence/logger.d.ts.map +1 -0
  79. package/dist/sequence/logger.js +11 -0
  80. package/dist/sequence/manager.d.ts +287 -0
  81. package/dist/sequence/manager.d.ts.map +1 -0
  82. package/dist/sequence/manager.js +356 -0
  83. package/dist/sequence/messages.d.ts +18 -0
  84. package/dist/sequence/messages.d.ts.map +1 -0
  85. package/dist/sequence/messages.js +115 -0
  86. package/dist/sequence/recovery.d.ts +30 -0
  87. package/dist/sequence/recovery.d.ts.map +1 -0
  88. package/dist/sequence/recovery.js +314 -0
  89. package/dist/sequence/sessions.d.ts +26 -0
  90. package/dist/sequence/sessions.d.ts.map +1 -0
  91. package/dist/sequence/sessions.js +169 -0
  92. package/dist/sequence/signatures.d.ts +21 -0
  93. package/dist/sequence/signatures.d.ts.map +1 -0
  94. package/dist/sequence/signatures.js +192 -0
  95. package/dist/sequence/signers.d.ts +14 -0
  96. package/dist/sequence/signers.d.ts.map +1 -0
  97. package/dist/sequence/signers.js +74 -0
  98. package/dist/sequence/transactions.d.ts +26 -0
  99. package/dist/sequence/transactions.d.ts.map +1 -0
  100. package/dist/sequence/transactions.js +201 -0
  101. package/dist/sequence/types/index.d.ts +9 -0
  102. package/dist/sequence/types/index.d.ts.map +1 -0
  103. package/dist/sequence/types/index.js +2 -0
  104. package/dist/sequence/types/message-request.d.ts +23 -0
  105. package/dist/sequence/types/message-request.d.ts.map +1 -0
  106. package/dist/sequence/types/message-request.js +1 -0
  107. package/dist/sequence/types/recovery.d.ts +15 -0
  108. package/dist/sequence/types/recovery.d.ts.map +1 -0
  109. package/dist/sequence/types/recovery.js +1 -0
  110. package/dist/sequence/types/signature-request.d.ts +76 -0
  111. package/dist/sequence/types/signature-request.d.ts.map +1 -0
  112. package/dist/sequence/types/signature-request.js +11 -0
  113. package/dist/sequence/types/signer.d.ts +28 -0
  114. package/dist/sequence/types/signer.d.ts.map +1 -0
  115. package/dist/sequence/types/signer.js +10 -0
  116. package/dist/sequence/types/transaction-request.d.ts +41 -0
  117. package/dist/sequence/types/transaction-request.d.ts.map +1 -0
  118. package/dist/sequence/types/transaction-request.js +1 -0
  119. package/dist/sequence/types/wallet.d.ts +21 -0
  120. package/dist/sequence/types/wallet.d.ts.map +1 -0
  121. package/dist/sequence/types/wallet.js +1 -0
  122. package/dist/sequence/wallets.d.ts +121 -0
  123. package/dist/sequence/wallets.d.ts.map +1 -0
  124. package/dist/sequence/wallets.js +632 -0
  125. package/package.json +40 -0
  126. package/src/dbs/auth-commitments.ts +26 -0
  127. package/src/dbs/auth-keys.ts +85 -0
  128. package/src/dbs/generic.ts +194 -0
  129. package/src/dbs/index.ts +13 -0
  130. package/src/dbs/messages.ts +16 -0
  131. package/src/dbs/recovery.ts +15 -0
  132. package/src/dbs/signatures.ts +15 -0
  133. package/src/dbs/transactions.ts +16 -0
  134. package/src/dbs/wallets.ts +16 -0
  135. package/src/identity/signer.ts +78 -0
  136. package/src/index.ts +2 -0
  137. package/src/sequence/cron.ts +134 -0
  138. package/src/sequence/devices.ts +53 -0
  139. package/src/sequence/handlers/authcode-pkce.ts +70 -0
  140. package/src/sequence/handlers/authcode.ts +116 -0
  141. package/src/sequence/handlers/devices.ts +53 -0
  142. package/src/sequence/handlers/handler.ts +14 -0
  143. package/src/sequence/handlers/identity.ts +101 -0
  144. package/src/sequence/handlers/index.ts +6 -0
  145. package/src/sequence/handlers/mnemonic.ts +88 -0
  146. package/src/sequence/handlers/otp.ts +107 -0
  147. package/src/sequence/handlers/passkeys.ts +84 -0
  148. package/src/sequence/handlers/recovery.ts +88 -0
  149. package/src/sequence/index.ts +25 -0
  150. package/src/sequence/logger.ts +11 -0
  151. package/src/sequence/manager.ts +634 -0
  152. package/src/sequence/messages.ts +146 -0
  153. package/src/sequence/recovery.ts +429 -0
  154. package/src/sequence/sessions.ts +238 -0
  155. package/src/sequence/signatures.ts +263 -0
  156. package/src/sequence/signers.ts +88 -0
  157. package/src/sequence/transactions.ts +281 -0
  158. package/src/sequence/types/index.ts +27 -0
  159. package/src/sequence/types/message-request.ts +26 -0
  160. package/src/sequence/types/recovery.ts +15 -0
  161. package/src/sequence/types/signature-request.ts +89 -0
  162. package/src/sequence/types/signer.ts +32 -0
  163. package/src/sequence/types/transaction-request.ts +47 -0
  164. package/src/sequence/types/wallet.ts +24 -0
  165. package/src/sequence/wallets.ts +853 -0
  166. package/test/constants.ts +62 -0
  167. package/test/recovery.test.ts +211 -0
  168. package/test/sessions.test.ts +324 -0
  169. package/test/setup.ts +63 -0
  170. package/test/transactions.test.ts +464 -0
  171. package/test/wallets.test.ts +381 -0
  172. package/tsconfig.json +10 -0
  173. package/vitest.config.ts +11 -0
@@ -0,0 +1,281 @@
1
+ import { Payload } from '@0xsequence/wallet-primitives'
2
+ import { Envelope, Wallet } from '@0xsequence/wallet-core'
3
+ import { Address, Provider, RpcTransport } from 'ox'
4
+ import { v7 as uuidv7 } from 'uuid'
5
+ import { Shared } from './manager.js'
6
+ import {
7
+ RelayerOption,
8
+ Transaction,
9
+ TransactionFormed,
10
+ TransactionRelayed,
11
+ TransactionRequest,
12
+ } from './types/transaction-request.js'
13
+
14
+ export class Transactions {
15
+ constructor(private readonly shared: Shared) {}
16
+
17
+ public async list(): Promise<Transaction[]> {
18
+ return this.shared.databases.transactions.list()
19
+ }
20
+
21
+ public async get(transactionId: string): Promise<Transaction> {
22
+ const tx = await this.shared.databases.transactions.get(transactionId)
23
+ if (!tx) {
24
+ throw new Error(`Transaction ${transactionId} not found`)
25
+ }
26
+
27
+ return tx
28
+ }
29
+
30
+ async request(
31
+ from: Address.Address,
32
+ chainId: bigint,
33
+ txs: TransactionRequest[],
34
+ options?: {
35
+ skipDefineGas?: boolean
36
+ source?: string
37
+ noConfigUpdate?: boolean
38
+ },
39
+ ): Promise<string> {
40
+ const network = this.shared.sequence.networks.find((network) => network.chainId === chainId)
41
+ if (!network) {
42
+ throw new Error(`Network not found for ${chainId}`)
43
+ }
44
+
45
+ const transport = RpcTransport.fromHttp(network.rpc)
46
+ const provider = Provider.from(transport)
47
+ const wallet = new Wallet(from, { stateProvider: this.shared.sequence.stateProvider })
48
+
49
+ const calls = txs.map(
50
+ (tx): Payload.Call => ({
51
+ to: tx.to,
52
+ value: tx.value ?? 0n,
53
+ data: tx.data ?? '0x',
54
+ gasLimit: tx.gasLimit ?? 0n, // TODO: Add gas estimation
55
+ delegateCall: false,
56
+ onlyFallback: false,
57
+ behaviorOnError: 'revert',
58
+ }),
59
+ )
60
+
61
+ const envelope = await wallet.prepareTransaction(provider, calls, {
62
+ noConfigUpdate: options?.noConfigUpdate,
63
+ })
64
+
65
+ const id = uuidv7()
66
+ await this.shared.databases.transactions.set({
67
+ id,
68
+ wallet: from,
69
+ requests: txs,
70
+ envelope,
71
+ source: options?.source ?? 'unknown',
72
+ status: 'requested',
73
+ })
74
+
75
+ return id
76
+ }
77
+
78
+ async define(
79
+ transactionId: string,
80
+ changes?: {
81
+ nonce?: bigint
82
+ space?: bigint
83
+ calls?: Pick<Payload.Call, 'gasLimit'>[]
84
+ },
85
+ ): Promise<void> {
86
+ const tx = await this.get(transactionId)
87
+ if (tx.status !== 'requested') {
88
+ throw new Error(`Transaction ${transactionId} is not in the requested state`)
89
+ }
90
+
91
+ // Modify the envelope with the changes
92
+ if (changes?.nonce) {
93
+ tx.envelope.payload.nonce = changes.nonce
94
+ }
95
+
96
+ if (changes?.space) {
97
+ tx.envelope.payload.space = changes.space
98
+ }
99
+
100
+ if (changes?.calls) {
101
+ if (changes.calls.length !== tx.envelope.payload.calls.length) {
102
+ throw new Error(`Invalid number of calls for transaction ${transactionId}`)
103
+ }
104
+
105
+ for (let i = 0; i < changes.calls.length; i++) {
106
+ tx.envelope.payload.calls[i]!.gasLimit = changes.calls[i]!.gasLimit
107
+ }
108
+ }
109
+
110
+ // Get relayer options
111
+ const allRelayerOptions = await Promise.all(
112
+ this.shared.sequence.relayers.map(async (relayer): Promise<RelayerOption[]> => {
113
+ const feeOptions = await relayer.feeOptions(tx.wallet, tx.envelope.chainId, tx.envelope.payload.calls)
114
+
115
+ if (feeOptions.options.length === 0) {
116
+ return [
117
+ {
118
+ id: uuidv7(),
119
+ relayerId: relayer.id,
120
+ } as RelayerOption,
121
+ ]
122
+ }
123
+
124
+ return feeOptions.options.map((feeOption) => ({
125
+ id: uuidv7(),
126
+ feeOption: feeOption,
127
+ relayerId: relayer.id,
128
+ quote: feeOptions.quote,
129
+ }))
130
+ }),
131
+ )
132
+
133
+ await this.shared.databases.transactions.set({
134
+ ...tx,
135
+ relayerOptions: allRelayerOptions.flat(),
136
+ status: 'defined',
137
+ })
138
+ }
139
+
140
+ async selectRelayer(transactionId: string, relayerOptionId: string): Promise<string> {
141
+ const tx = await this.get(transactionId)
142
+ if (tx.status !== 'defined') {
143
+ throw new Error(`Transaction ${transactionId} is not in the defined state`)
144
+ }
145
+
146
+ const selection = tx.relayerOptions.find((option) => option.id === relayerOptionId)
147
+ if (!selection) {
148
+ throw new Error(`Relayer option ${relayerOptionId} not found for transaction ${transactionId}`)
149
+ }
150
+
151
+ // Pass to the signatures manager
152
+ const signatureId = await this.shared.modules.signatures.request(tx.envelope, 'send-transaction', {
153
+ origin: tx.source,
154
+ })
155
+
156
+ await this.shared.databases.transactions.set({
157
+ ...tx,
158
+ relayerOptions: undefined,
159
+ relayerOption: selection,
160
+ status: 'formed',
161
+ signatureId,
162
+ } as TransactionFormed)
163
+
164
+ return signatureId
165
+ }
166
+
167
+ async relay(transactionOrSignatureId: string) {
168
+ // First, try to get the transaction directly
169
+ let tx: Transaction | undefined
170
+ try {
171
+ tx = await this.get(transactionOrSignatureId)
172
+ } catch (e) {
173
+ // If not found, it might be a signature ID
174
+ const signature = await this.shared.modules.signatures.get(transactionOrSignatureId)
175
+ if (!signature) {
176
+ throw new Error(`Neither transaction nor signature found with ID ${transactionOrSignatureId}`)
177
+ }
178
+
179
+ // Find the transaction associated with this signature
180
+ const transactions = await this.list()
181
+ tx = transactions.find(
182
+ (t) => t.status === 'formed' && 'signatureId' in t && t.signatureId === transactionOrSignatureId,
183
+ )
184
+
185
+ if (!tx) {
186
+ throw new Error(`No transaction found for signature ${transactionOrSignatureId}`)
187
+ }
188
+ }
189
+
190
+ const transactionId = tx.id
191
+
192
+ if (tx.status !== 'formed') {
193
+ throw new Error(`Transaction ${transactionId} is not in the formed state`)
194
+ }
195
+
196
+ const signature = await this.shared.modules.signatures.get(tx.signatureId)
197
+ if (!signature) {
198
+ throw new Error(`Signature ${tx.signatureId} not found for transaction ${transactionId}`)
199
+ }
200
+
201
+ const network = this.shared.sequence.networks.find((network) => network.chainId === tx.envelope.chainId)
202
+ if (!network) {
203
+ throw new Error(`Network not found for ${tx.envelope.chainId}`)
204
+ }
205
+
206
+ const transport = RpcTransport.fromHttp(network.rpc)
207
+ const provider = Provider.from(transport)
208
+
209
+ const wallet = new Wallet(tx.wallet, { stateProvider: this.shared.sequence.stateProvider })
210
+ if (!Payload.isCalls(signature.envelope.payload)) {
211
+ throw new Error(`Signature ${tx.signatureId} is not a calls payload`)
212
+ }
213
+
214
+ if (!Envelope.isSigned(signature.envelope)) {
215
+ throw new Error(`Transaction ${transactionId} is not signed`)
216
+ }
217
+
218
+ const { weight, threshold } = Envelope.weightOf(signature.envelope)
219
+ if (weight < threshold) {
220
+ throw new Error(`Transaction ${transactionId} has insufficient weight`)
221
+ }
222
+
223
+ const transaction = await wallet.buildTransaction(provider, signature.envelope as Envelope.Signed<Payload.Calls>)
224
+ const relayer = this.shared.sequence.relayers.find((relayer) => relayer.id === tx.relayerOption.relayerId)
225
+
226
+ if (!relayer) {
227
+ throw new Error(`Relayer ${tx.relayerOption.relayerId} not found for transaction ${transactionId}`)
228
+ }
229
+
230
+ const { opHash } = await relayer.relay(
231
+ transaction.to,
232
+ transaction.data,
233
+ tx.envelope.chainId,
234
+ tx.relayerOption.quote,
235
+ )
236
+
237
+ await this.shared.databases.transactions.set({
238
+ ...tx,
239
+ status: 'relayed',
240
+ opHash,
241
+ } as TransactionRelayed)
242
+
243
+ await this.shared.modules.signatures.complete(signature.id)
244
+
245
+ return opHash
246
+ }
247
+
248
+ onTransactionsUpdate(cb: (transactions: Transaction[]) => void, trigger?: boolean) {
249
+ const undo = this.shared.databases.transactions.addListener(() => {
250
+ this.list().then((l) => cb(l))
251
+ })
252
+
253
+ if (trigger) {
254
+ this.list().then((l) => cb(l))
255
+ }
256
+
257
+ return undo
258
+ }
259
+
260
+ onTransactionUpdate(transactionId: string, cb: (transaction: Transaction) => void, trigger?: boolean) {
261
+ const undo = this.shared.databases.transactions.addListener(() => {
262
+ this.get(transactionId).then((t) => cb(t))
263
+ })
264
+
265
+ if (trigger) {
266
+ this.get(transactionId).then((t) => cb(t))
267
+ }
268
+
269
+ return undo
270
+ }
271
+
272
+ async delete(transactionId: string) {
273
+ const tx = await this.get(transactionId)
274
+ await this.shared.databases.transactions.del(transactionId)
275
+
276
+ // Cancel any signature requests associated with this transaction
277
+ if (tx.status === 'formed') {
278
+ await this.shared.modules.signatures.cancel(tx.signatureId)
279
+ }
280
+ }
281
+ }
@@ -0,0 +1,27 @@
1
+ export type { Message, MessageRequest, MessageRequested, MessageSigned } from './message-request.js'
2
+ export type { QueuedRecoveryPayload } from './recovery.js'
3
+ export { Actions } from './signature-request.js'
4
+ export type {
5
+ Action,
6
+ ActionToPayload,
7
+ BaseSignatureRequest,
8
+ SignatureRequest,
9
+ Signer,
10
+ SignerActionable,
11
+ SignerBase,
12
+ SignerReady,
13
+ SignerSigned,
14
+ SignerUnavailable,
15
+ } from './signature-request.js'
16
+ export { Kinds } from './signer.js'
17
+ export type { Kind, RecoverySigner, SignerWithKind, WitnessExtraSignerKind } from './signer.js'
18
+ export type {
19
+ RelayerOption,
20
+ Transaction,
21
+ TransactionDefined,
22
+ TransactionFormed,
23
+ TransactionRelayed,
24
+ TransactionRequest,
25
+ TransactionRequested,
26
+ } from './transaction-request.js'
27
+ export type { Wallet } from './wallet.js'
@@ -0,0 +1,26 @@
1
+ import { Envelope } from '@0xsequence/wallet-core'
2
+ import { Payload } from '@0xsequence/wallet-primitives'
3
+ import { Address, Hex } from 'ox'
4
+
5
+ export type MessageRequest = string | Hex.Hex | Payload.TypedDataToSign
6
+
7
+ type MessageBase = {
8
+ id: string
9
+ wallet: Address.Address
10
+ message: MessageRequest
11
+ source: string
12
+ signatureId: string
13
+ }
14
+
15
+ export type MessageRequested = MessageBase & {
16
+ status: 'requested'
17
+ envelope: Envelope.Envelope<Payload.Message>
18
+ }
19
+
20
+ export type MessageSigned = MessageBase & {
21
+ status: 'signed'
22
+ envelope: Envelope.Signed<Payload.Message>
23
+ messageSignature: Hex.Hex
24
+ }
25
+
26
+ export type Message = MessageRequested | MessageSigned
@@ -0,0 +1,15 @@
1
+ import { Payload } from '@0xsequence/wallet-primitives'
2
+ import { Address, Hex } from 'ox'
3
+
4
+ export type QueuedRecoveryPayload = {
5
+ id: string
6
+ index: bigint
7
+ recoveryModule: Address.Address
8
+ wallet: Address.Address
9
+ signer: Address.Address
10
+ chainId: bigint
11
+ startTimestamp: bigint
12
+ endTimestamp: bigint
13
+ payloadHash: Hex.Hex
14
+ payload?: Payload.Payload
15
+ }
@@ -0,0 +1,89 @@
1
+ import { Envelope } from '@0xsequence/wallet-core'
2
+ import { Payload } from '@0xsequence/wallet-primitives'
3
+ import { Address, Hex } from 'ox'
4
+ import { Handler } from '../handlers/handler.js'
5
+
6
+ export type ActionToPayload = {
7
+ [Actions.Logout]: Payload.ConfigUpdate
8
+ [Actions.Login]: Payload.ConfigUpdate
9
+ [Actions.SendTransaction]: Payload.Calls
10
+ [Actions.SignMessage]: Payload.Message
11
+ [Actions.SessionUpdate]: Payload.ConfigUpdate
12
+ [Actions.Recovery]: Payload.Recovery<Payload.Calls>
13
+ [Actions.AddRecoverySigner]: Payload.ConfigUpdate
14
+ [Actions.RemoveRecoverySigner]: Payload.ConfigUpdate
15
+ [Actions.SessionImplicitAuthorize]: Payload.SessionImplicitAuthorize
16
+ }
17
+
18
+ export const Actions = {
19
+ Logout: 'logout',
20
+ Login: 'login',
21
+ SendTransaction: 'send-transaction',
22
+ SignMessage: 'sign-message',
23
+ SessionUpdate: 'session-update',
24
+ Recovery: 'recovery',
25
+ AddRecoverySigner: 'add-recovery-signer',
26
+ RemoveRecoverySigner: 'remove-recovery-signer',
27
+ SessionImplicitAuthorize: 'session-implicit-authorize',
28
+ } as const
29
+
30
+ export type Action = (typeof Actions)[keyof typeof Actions]
31
+ export type BaseSignatureRequest<A extends Action = Action> =
32
+ | {
33
+ id: string
34
+ wallet: Address.Address
35
+ origin: string
36
+ createdAt: string
37
+
38
+ action: A
39
+ envelope: Envelope.Signed<ActionToPayload[A]>
40
+ status: 'pending'
41
+ }
42
+ | {
43
+ id: string
44
+ wallet: Address.Address
45
+ origin: string
46
+ createdAt: string
47
+
48
+ action: A
49
+ envelope: Envelope.Signed<ActionToPayload[A]>
50
+ status: 'cancelled' | 'completed'
51
+ scheduledPruning: number
52
+ }
53
+
54
+ export type SignerBase = {
55
+ address: Address.Address
56
+ imageHash?: Hex.Hex
57
+ }
58
+
59
+ export type SignerSigned = SignerBase & {
60
+ handler?: Handler
61
+ status: 'signed'
62
+ }
63
+
64
+ export type SignerUnavailable = SignerBase & {
65
+ handler?: Handler
66
+ reason: string
67
+ status: 'unavailable'
68
+ }
69
+
70
+ export type SignerReady = SignerBase & {
71
+ handler: Handler
72
+ status: 'ready'
73
+ handle: () => Promise<boolean>
74
+ }
75
+
76
+ export type SignerActionable = SignerBase & {
77
+ handler: Handler
78
+ status: 'actionable'
79
+ message: string // TODO: Localization?
80
+ handle: () => Promise<boolean>
81
+ }
82
+
83
+ export type Signer = SignerSigned | SignerUnavailable | SignerReady | SignerActionable
84
+
85
+ export type SignatureRequest = BaseSignatureRequest & {
86
+ weight: bigint
87
+ threshold: bigint
88
+ signers: Signer[]
89
+ }
@@ -0,0 +1,32 @@
1
+ import { Address, Hex } from 'ox'
2
+
3
+ export const Kinds = {
4
+ LocalDevice: 'local-device',
5
+ LoginPasskey: 'login-passkey',
6
+ LoginMnemonic: 'login-mnemonic', // Todo: do not name it login-mnemonic, just mnemonic
7
+ LoginEmailOtp: 'login-email-otp',
8
+ LoginGooglePkce: 'login-google-pkce',
9
+ LoginApple: 'login-apple',
10
+ Recovery: 'recovery-extension',
11
+ Unknown: 'unknown',
12
+ } as const
13
+
14
+ export type Kind = (typeof Kinds)[keyof typeof Kinds]
15
+
16
+ export type WitnessExtraSignerKind = {
17
+ signerKind: string
18
+ }
19
+
20
+ export type SignerWithKind = {
21
+ address: Address.Address
22
+ kind?: Kind
23
+ imageHash?: Hex.Hex
24
+ }
25
+
26
+ export type RecoverySigner = {
27
+ kind: Kind
28
+ isRecovery: true
29
+ address: Address.Address
30
+ minTimestamp: bigint
31
+ requiredDeltaTime: bigint
32
+ }
@@ -0,0 +1,47 @@
1
+ import { Envelope, Relayer } from '@0xsequence/wallet-core'
2
+ import { Payload } from '@0xsequence/wallet-primitives'
3
+ import { Address, Hex } from 'ox'
4
+
5
+ export type TransactionRequest = {
6
+ to: Address.Address
7
+ value?: bigint
8
+ data?: Hex.Hex
9
+ gasLimit?: bigint
10
+ }
11
+
12
+ export type RelayerOption = {
13
+ id: string
14
+ relayerId: string
15
+ feeOption?: Relayer.FeeOption
16
+ quote?: Relayer.FeeQuote
17
+ }
18
+
19
+ type TransactionBase = {
20
+ id: string
21
+ wallet: Address.Address
22
+ requests: TransactionRequest[]
23
+ source: string
24
+ envelope: Envelope.Envelope<Payload.Calls>
25
+ }
26
+
27
+ export type TransactionRequested = TransactionBase & {
28
+ status: 'requested'
29
+ }
30
+
31
+ export type TransactionDefined = TransactionBase & {
32
+ status: 'defined'
33
+ relayerOptions: RelayerOption[]
34
+ }
35
+
36
+ export type TransactionFormed = TransactionBase & {
37
+ relayerOption: RelayerOption
38
+ status: 'formed'
39
+ signatureId: string
40
+ }
41
+
42
+ export type TransactionRelayed = TransactionBase & {
43
+ status: 'relayed'
44
+ opHash: string
45
+ }
46
+
47
+ export type Transaction = TransactionRequested | TransactionDefined | TransactionFormed | TransactionRelayed
@@ -0,0 +1,24 @@
1
+ import { Address } from 'ox'
2
+
3
+ export interface Wallet {
4
+ address: Address.Address
5
+ status: 'ready' | 'logging-in' | 'logging-out'
6
+ loginDate: string
7
+ device: Address.Address
8
+ loginType: string
9
+ useGuard: boolean
10
+ }
11
+
12
+ export type WalletSelectionContext = {
13
+ isRedirect: boolean
14
+ target?: string
15
+ signupKind?: string
16
+ }
17
+
18
+ export type WalletSelectionOptions = {
19
+ existingWallets: Address.Address[]
20
+ signerAddress: Address.Address
21
+ context: WalletSelectionContext
22
+ }
23
+
24
+ export type WalletSelectionUiHandler = (options: WalletSelectionOptions) => Promise<Address.Address | undefined>