accounts 0.12.2 → 0.14.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 +35 -0
- package/README.md +6 -5
- package/dist/cli/adapter.d.ts.map +1 -1
- package/dist/cli/adapter.js +76 -69
- package/dist/cli/adapter.js.map +1 -1
- package/dist/core/AccessKey.d.ts +89 -106
- package/dist/core/AccessKey.d.ts.map +1 -1
- package/dist/core/AccessKey.js +230 -210
- package/dist/core/AccessKey.js.map +1 -1
- package/dist/core/Account.d.ts +0 -9
- package/dist/core/Account.d.ts.map +1 -1
- package/dist/core/Account.js +1 -13
- package/dist/core/Account.js.map +1 -1
- package/dist/core/Adapter.d.ts +24 -4
- package/dist/core/Adapter.d.ts.map +1 -1
- package/dist/core/Client.d.ts +1 -1
- package/dist/core/Client.d.ts.map +1 -1
- package/dist/core/Client.js.map +1 -1
- package/dist/core/Provider.d.ts +6 -7
- package/dist/core/Provider.d.ts.map +1 -1
- package/dist/core/Provider.js +73 -77
- package/dist/core/Provider.js.map +1 -1
- package/dist/core/Remote.d.ts +2 -0
- package/dist/core/Remote.d.ts.map +1 -1
- package/dist/core/Remote.js +3 -1
- package/dist/core/Remote.js.map +1 -1
- package/dist/core/Schema.d.ts +17 -7
- package/dist/core/Schema.d.ts.map +1 -1
- package/dist/core/adapters/dialog.d.ts.map +1 -1
- package/dist/core/adapters/dialog.js +126 -131
- package/dist/core/adapters/dialog.js.map +1 -1
- package/dist/core/adapters/local.d.ts.map +1 -1
- package/dist/core/adapters/local.js +92 -105
- package/dist/core/adapters/local.js.map +1 -1
- package/dist/core/adapters/privy.d.ts +164 -0
- package/dist/core/adapters/privy.d.ts.map +1 -0
- package/dist/core/adapters/privy.js +578 -0
- package/dist/core/adapters/privy.js.map +1 -0
- package/dist/core/adapters/turnkey.d.ts.map +1 -1
- package/dist/core/adapters/turnkey.js +136 -133
- package/dist/core/adapters/turnkey.js.map +1 -1
- package/dist/core/internal/AccessKeyTransaction.d.ts +59 -0
- package/dist/core/internal/AccessKeyTransaction.d.ts.map +1 -0
- package/dist/core/internal/AccessKeyTransaction.js +155 -0
- package/dist/core/internal/AccessKeyTransaction.js.map +1 -0
- package/dist/core/zod/rpc.d.ts +71 -4
- package/dist/core/zod/rpc.d.ts.map +1 -1
- package/dist/core/zod/rpc.js +33 -4
- package/dist/core/zod/rpc.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/react-native/adapter.d.ts.map +1 -1
- package/dist/react-native/adapter.js +86 -75
- package/dist/react-native/adapter.js.map +1 -1
- package/dist/server/CliAuth.d.ts +55 -0
- package/dist/server/CliAuth.d.ts.map +1 -1
- package/dist/server/CliAuth.js +18 -1
- package/dist/server/CliAuth.js.map +1 -1
- package/dist/server/Kv.d.ts +19 -9
- package/dist/server/Kv.d.ts.map +1 -1
- package/dist/server/Kv.js +32 -9
- package/dist/server/Kv.js.map +1 -1
- package/dist/server/internal/handlers/auth.d.ts.map +1 -1
- package/dist/server/internal/handlers/auth.js +3 -1
- package/dist/server/internal/handlers/auth.js.map +1 -1
- package/dist/server/internal/handlers/codeAuth.js +1 -1
- package/dist/server/internal/handlers/codeAuth.js.map +1 -1
- package/dist/server/internal/handlers/exchange.js +1 -1
- package/dist/server/internal/handlers/exchange.js.map +1 -1
- package/dist/server/internal/handlers/relay.d.ts +18 -12
- package/dist/server/internal/handlers/relay.d.ts.map +1 -1
- package/dist/server/internal/handlers/relay.js +116 -3
- package/dist/server/internal/handlers/relay.js.map +1 -1
- package/dist/server/internal/handlers/webAuthn.d.ts +6 -1
- package/dist/server/internal/handlers/webAuthn.d.ts.map +1 -1
- package/dist/server/internal/handlers/webAuthn.js +16 -9
- package/dist/server/internal/handlers/webAuthn.js.map +1 -1
- package/package.json +3 -3
- package/src/cli/{Provider.test.ts → Provider.localnet.test.ts} +49 -1
- package/src/cli/adapter.ts +95 -76
- package/src/core/AccessKey.test.ts +563 -560
- package/src/core/AccessKey.ts +327 -327
- package/src/core/Account.test.ts +6 -51
- package/src/core/Account.ts +1 -19
- package/src/core/Adapter.ts +22 -4
- package/src/core/Client.test.ts +1 -1
- package/src/core/Client.ts +1 -1
- package/src/core/Provider.connect.browser.test.ts +1 -1
- package/src/core/{Provider.test.ts → Provider.localnet.test.ts} +98 -32
- package/src/core/Provider.ts +118 -112
- package/src/core/Remote.test.ts +28 -0
- package/src/core/Remote.ts +4 -1
- package/src/core/Schema.test-d.ts +41 -0
- package/src/core/adapters/dialog.test.ts +335 -15
- package/src/core/adapters/dialog.ts +120 -127
- package/src/core/adapters/local.test.ts +1 -1
- package/src/core/adapters/local.ts +95 -119
- package/src/core/adapters/privy.test-d.ts +128 -0
- package/src/core/adapters/privy.test.ts +648 -0
- package/src/core/adapters/privy.ts +811 -0
- package/src/core/adapters/turnkey.test.ts +117 -13
- package/src/core/adapters/turnkey.ts +132 -149
- package/src/core/internal/AccessKeyTransaction.ts +243 -0
- package/src/core/{mppx.test.ts → mppx.localnet.test.ts} +32 -2
- package/src/core/zod/request.test.ts +36 -0
- package/src/core/zod/rpc.test.ts +139 -0
- package/src/core/zod/rpc.ts +44 -10
- package/src/index.ts +1 -1
- package/src/react-native/{Provider.test.ts → Provider.localnet.test.ts} +65 -0
- package/src/react-native/adapter.ts +107 -87
- package/src/server/CliAuth.test-d.ts +23 -0
- package/src/server/CliAuth.test.ts +47 -0
- package/src/server/CliAuth.ts +20 -1
- package/src/server/Handler.test-d.ts +1 -1
- package/src/server/Kv.test.ts +51 -0
- package/src/server/Kv.ts +43 -9
- package/src/server/internal/handlers/auth.test.ts +10 -5
- package/src/server/internal/handlers/auth.ts +4 -1
- package/src/server/internal/handlers/codeAuth.ts +1 -1
- package/src/server/internal/handlers/exchange.ts +1 -1
- package/src/server/internal/handlers/{relay.test.ts → relay.localnet.test.ts} +4 -1
- package/src/server/internal/handlers/relay.ts +139 -14
- package/src/server/internal/handlers/session.test.ts +1 -1
- package/src/server/internal/handlers/webAuthn.test.ts +20 -0
- package/src/server/internal/handlers/webAuthn.ts +24 -12
- /package/src/server/internal/handlers/{exchange.test.ts → exchange.localnet.test.ts} +0 -0
package/src/cli/adapter.ts
CHANGED
|
@@ -11,12 +11,12 @@ import {
|
|
|
11
11
|
RpcResponse,
|
|
12
12
|
} from 'ox'
|
|
13
13
|
import { KeyAuthorization } from 'ox/tempo'
|
|
14
|
-
import { prepareTransactionRequest } from 'viem/actions'
|
|
15
14
|
import { Account as TempoAccount, Secp256k1 } from 'viem/tempo'
|
|
16
15
|
import * as z from 'zod/mini'
|
|
17
16
|
|
|
18
17
|
import * as AccessKey from '../core/AccessKey.js'
|
|
19
18
|
import * as Adapter from '../core/Adapter.js'
|
|
19
|
+
import * as AccessKeyTransaction from '../core/internal/AccessKeyTransaction.js'
|
|
20
20
|
import * as CliAuth from '../server/CliAuth.js'
|
|
21
21
|
import * as Keyring from './keyring.js'
|
|
22
22
|
|
|
@@ -44,9 +44,9 @@ export function cli(options: cli.Options): Adapter.Adapter {
|
|
|
44
44
|
const deserialized = KeyAuthorization.deserialize(entry.keyAuthorization)
|
|
45
45
|
if (!deserialized.signature) throw new Error('Managed access key is missing a signature.')
|
|
46
46
|
const keyAuthorization = deserialized as KeyAuthorization.Signed
|
|
47
|
-
AccessKey.
|
|
48
|
-
address,
|
|
49
|
-
keyAuthorization,
|
|
47
|
+
AccessKey.add({
|
|
48
|
+
account: address,
|
|
49
|
+
authorization: keyAuthorization,
|
|
50
50
|
privateKey: entry.key,
|
|
51
51
|
store,
|
|
52
52
|
})
|
|
@@ -104,9 +104,9 @@ export function cli(options: cli.Options): Adapter.Adapter {
|
|
|
104
104
|
if (!managedKey) return
|
|
105
105
|
|
|
106
106
|
const signed = KeyAuthorization.fromRpc(z.encode(CliAuth.keyAuthorization, keyAuthorization))
|
|
107
|
-
AccessKey.
|
|
108
|
-
address,
|
|
109
|
-
|
|
107
|
+
AccessKey.add({
|
|
108
|
+
account: address,
|
|
109
|
+
authorization: signed,
|
|
110
110
|
privateKey: managedKey.key,
|
|
111
111
|
store,
|
|
112
112
|
})
|
|
@@ -129,29 +129,42 @@ export function cli(options: cli.Options): Adapter.Adapter {
|
|
|
129
129
|
)
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
async function
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
132
|
+
async function prepareManagedTransaction(
|
|
133
|
+
client: ReturnType<typeof getClient>,
|
|
134
|
+
parameters: AccessKeyTransaction.create.PrepareParameters,
|
|
135
|
+
options: {
|
|
136
|
+
calls?: AccessKeyTransaction.create.Options['calls'] | undefined
|
|
137
|
+
chainId?: number | undefined
|
|
138
|
+
} = {},
|
|
137
139
|
) {
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
+
const state = store.getState()
|
|
141
|
+
const address = parameters.from ?? state.accounts[state.activeAccount]?.address
|
|
142
|
+
if (!address) throw new core_Provider.DisconnectedError({ message: 'No active account.' })
|
|
143
|
+
await loadManagedKey(address)
|
|
144
|
+
const transaction = await AccessKeyTransaction.create({
|
|
145
|
+
address,
|
|
146
|
+
calls: options.calls,
|
|
147
|
+
chainId: options.chainId ?? state.chainId,
|
|
148
|
+
client,
|
|
149
|
+
store,
|
|
150
|
+
})
|
|
151
|
+
if (!transaction)
|
|
152
|
+
throw new core_Provider.UnauthorizedError({
|
|
153
|
+
message: `Account "${address}" cannot sign with an access key.`,
|
|
154
|
+
})
|
|
155
|
+
return await transaction.prepare(parameters)
|
|
156
|
+
}
|
|
140
157
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
return await fn(account, keyAuthorization ?? undefined)
|
|
145
|
-
} catch (error) {
|
|
146
|
-
AccessKey.remove(account, { store })
|
|
147
|
-
throw error
|
|
148
|
-
}
|
|
158
|
+
async function loadManagedAccount(address: Adapter.signPersonalMessage.Parameters['address']) {
|
|
159
|
+
await loadManagedKey(address)
|
|
160
|
+
return getAccount({ address, signable: true })
|
|
149
161
|
}
|
|
150
162
|
|
|
151
163
|
async function authorize(request: {
|
|
152
164
|
account?: Adapter.authorizeAccessKey.ReturnType['rootAddress'] | undefined
|
|
153
165
|
authorizeAccessKey: Adapter.authorizeAccessKey.Parameters | undefined
|
|
154
166
|
method: 'wallet_authorizeAccessKey' | 'wallet_connect'
|
|
167
|
+
showDeposit?: Adapter.createAccount.Parameters['showDeposit'] | undefined
|
|
155
168
|
}) {
|
|
156
169
|
const {
|
|
157
170
|
host,
|
|
@@ -192,6 +205,7 @@ export function cli(options: cli.Options): Adapter.Adapter {
|
|
|
192
205
|
...(keyType ? { keyType } : {}),
|
|
193
206
|
...(authorizeAccessKey?.limits ? { limits: authorizeAccessKey.limits } : {}),
|
|
194
207
|
pubKey: publicKey,
|
|
208
|
+
...(request.showDeposit !== undefined ? { showDeposit: request.showDeposit } : {}),
|
|
195
209
|
}
|
|
196
210
|
const created = await post({
|
|
197
211
|
body,
|
|
@@ -257,8 +271,27 @@ export function cli(options: cli.Options): Adapter.Adapter {
|
|
|
257
271
|
rootAddress: result.accountAddress,
|
|
258
272
|
}
|
|
259
273
|
},
|
|
260
|
-
async createAccount(
|
|
261
|
-
|
|
274
|
+
async createAccount(parameters) {
|
|
275
|
+
if (parameters?.digest)
|
|
276
|
+
throw unsupported('`wallet_connect` digest signing not supported by CLI adapter.')
|
|
277
|
+
|
|
278
|
+
const result = await authorize({
|
|
279
|
+
authorizeAccessKey: parameters?.authorizeAccessKey,
|
|
280
|
+
method: 'wallet_connect',
|
|
281
|
+
...(parameters?.showDeposit !== undefined
|
|
282
|
+
? { showDeposit: parameters.showDeposit }
|
|
283
|
+
: {}),
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
return {
|
|
287
|
+
accounts: [
|
|
288
|
+
{
|
|
289
|
+
address: result.accountAddress,
|
|
290
|
+
capabilities: {},
|
|
291
|
+
},
|
|
292
|
+
],
|
|
293
|
+
keyAuthorization: z.encode(CliAuth.keyAuthorization, result.keyAuthorization),
|
|
294
|
+
}
|
|
262
295
|
},
|
|
263
296
|
async loadAccounts(parameters) {
|
|
264
297
|
if (parameters?.digest)
|
|
@@ -267,6 +300,9 @@ export function cli(options: cli.Options): Adapter.Adapter {
|
|
|
267
300
|
const result = await authorize({
|
|
268
301
|
authorizeAccessKey: parameters?.authorizeAccessKey,
|
|
269
302
|
method: 'wallet_connect',
|
|
303
|
+
...(parameters?.showDeposit !== undefined
|
|
304
|
+
? { showDeposit: parameters.showDeposit }
|
|
305
|
+
: {}),
|
|
270
306
|
})
|
|
271
307
|
|
|
272
308
|
return {
|
|
@@ -285,74 +321,57 @@ export function cli(options: cli.Options): Adapter.Adapter {
|
|
|
285
321
|
async sendTransaction(parameters) {
|
|
286
322
|
const { feePayer, ...rest } = parameters
|
|
287
323
|
const client = getClient(typeof feePayer === 'string' ? { feePayer } : {})
|
|
288
|
-
const
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
}),
|
|
324
|
+
const prepared = await prepareManagedTransaction(
|
|
325
|
+
client,
|
|
326
|
+
{
|
|
327
|
+
...rest,
|
|
328
|
+
...(feePayer ? { feePayer: true } : {}),
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
calls: parameters.calls as AccessKeyTransaction.create.Options['calls'],
|
|
332
|
+
chainId: parameters.chainId,
|
|
333
|
+
},
|
|
299
334
|
)
|
|
300
|
-
|
|
301
|
-
const result = await client.request({
|
|
302
|
-
method: 'eth_sendRawTransaction' as never,
|
|
303
|
-
params: [signed],
|
|
304
|
-
})
|
|
305
|
-
AccessKey.removePending(account, { store })
|
|
306
|
-
return result
|
|
335
|
+
return await prepared.send()
|
|
307
336
|
},
|
|
308
337
|
async sendTransactionSync(parameters) {
|
|
309
338
|
const { feePayer, ...rest } = parameters
|
|
310
339
|
const client = getClient(typeof feePayer === 'string' ? { feePayer } : {})
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
}),
|
|
340
|
+
const prepared = await prepareManagedTransaction(
|
|
341
|
+
client,
|
|
342
|
+
{
|
|
343
|
+
...rest,
|
|
344
|
+
...(feePayer ? { feePayer: true } : {}),
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
calls: parameters.calls as AccessKeyTransaction.create.Options['calls'],
|
|
348
|
+
chainId: parameters.chainId,
|
|
349
|
+
},
|
|
322
350
|
)
|
|
323
|
-
|
|
324
|
-
const result = await client.request({
|
|
325
|
-
method: 'eth_sendRawTransactionSync' as never,
|
|
326
|
-
params: [signed],
|
|
327
|
-
})
|
|
328
|
-
AccessKey.removePending(account, { store })
|
|
329
|
-
return result
|
|
351
|
+
return await prepared.sendSync()
|
|
330
352
|
},
|
|
331
353
|
async signPersonalMessage({ address, data }) {
|
|
332
|
-
await
|
|
333
|
-
const account = getAccount({ address, signable: true })
|
|
354
|
+
const account = await loadManagedAccount(address)
|
|
334
355
|
return await account.signMessage({ message: { raw: data } })
|
|
335
356
|
},
|
|
336
357
|
async signTransaction(parameters) {
|
|
337
358
|
const { feePayer, ...rest } = parameters
|
|
338
359
|
const client = getClient(typeof feePayer === 'string' ? { feePayer } : {})
|
|
339
|
-
const
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
}),
|
|
360
|
+
const prepared = await prepareManagedTransaction(
|
|
361
|
+
client,
|
|
362
|
+
{
|
|
363
|
+
...rest,
|
|
364
|
+
...(feePayer ? { feePayer: true } : {}),
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
calls: parameters.calls as AccessKeyTransaction.create.Options['calls'],
|
|
368
|
+
chainId: parameters.chainId,
|
|
369
|
+
},
|
|
350
370
|
)
|
|
351
|
-
return await
|
|
371
|
+
return await prepared.sign()
|
|
352
372
|
},
|
|
353
373
|
async signTypedData({ address, data }) {
|
|
354
|
-
await
|
|
355
|
-
const account = getAccount({ address, signable: true })
|
|
374
|
+
const account = await loadManagedAccount(address)
|
|
356
375
|
return await account.signTypedData(JSON.parse(data) as never)
|
|
357
376
|
},
|
|
358
377
|
},
|