@eth-optimism/actions-sdk 0.0.3 → 0.0.4

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 (76) hide show
  1. package/dist/actions.test.js +22 -2
  2. package/dist/actions.test.js.map +1 -1
  3. package/dist/constants/assets.d.ts.map +1 -1
  4. package/dist/constants/assets.js +2 -1
  5. package/dist/constants/assets.js.map +1 -1
  6. package/dist/constants/supportedChains.d.ts +1 -1
  7. package/dist/constants/supportedChains.d.ts.map +1 -1
  8. package/dist/constants/supportedChains.js +2 -1
  9. package/dist/constants/supportedChains.js.map +1 -1
  10. package/dist/lend/namespaces/WalletLendNamespace.d.ts +8 -2
  11. package/dist/lend/namespaces/WalletLendNamespace.d.ts.map +1 -1
  12. package/dist/lend/namespaces/WalletLendNamespace.js +8 -2
  13. package/dist/lend/namespaces/WalletLendNamespace.js.map +1 -1
  14. package/dist/lend/providers/morpho/sdk.d.ts.map +1 -1
  15. package/dist/lend/providers/morpho/sdk.js +0 -1
  16. package/dist/lend/providers/morpho/sdk.js.map +1 -1
  17. package/dist/services/ChainManager.d.ts +1 -1
  18. package/dist/test/MockPrivyClient.d.ts +10 -49
  19. package/dist/test/MockPrivyClient.d.ts.map +1 -1
  20. package/dist/test/MockPrivyClient.js +13 -72
  21. package/dist/test/MockPrivyClient.js.map +1 -1
  22. package/dist/wallet/core/namespace/WalletNamespace.d.ts +13 -13
  23. package/dist/wallet/core/namespace/WalletNamespace.d.ts.map +1 -1
  24. package/dist/wallet/core/namespace/WalletNamespace.js +13 -13
  25. package/dist/wallet/core/namespace/WalletNamespace.js.map +1 -1
  26. package/dist/wallet/core/namespace/__tests__/WalletNamespace.spec.js +55 -33
  27. package/dist/wallet/core/namespace/__tests__/WalletNamespace.spec.js.map +1 -1
  28. package/dist/wallet/core/providers/__tests__/WalletProvider.spec.js +43 -15
  29. package/dist/wallet/core/providers/__tests__/WalletProvider.spec.js.map +1 -1
  30. package/dist/wallet/core/providers/hosted/registry/__tests__/HostedWalletProviderRegistry.spec.js +14 -4
  31. package/dist/wallet/core/providers/hosted/registry/__tests__/HostedWalletProviderRegistry.spec.js.map +1 -1
  32. package/dist/wallet/node/providers/hosted/privy/PrivyHostedWalletProvider.d.ts +16 -3
  33. package/dist/wallet/node/providers/hosted/privy/PrivyHostedWalletProvider.d.ts.map +1 -1
  34. package/dist/wallet/node/providers/hosted/privy/PrivyHostedWalletProvider.js +18 -5
  35. package/dist/wallet/node/providers/hosted/privy/PrivyHostedWalletProvider.js.map +1 -1
  36. package/dist/wallet/node/providers/hosted/privy/__tests__/PrivyHostedWalletProvider.spec.js +31 -12
  37. package/dist/wallet/node/providers/hosted/privy/__tests__/PrivyHostedWalletProvider.spec.js.map +1 -1
  38. package/dist/wallet/node/providers/hosted/registry/NodeHostedWalletProviderRegistry.d.ts.map +1 -1
  39. package/dist/wallet/node/providers/hosted/registry/NodeHostedWalletProviderRegistry.js +6 -1
  40. package/dist/wallet/node/providers/hosted/registry/NodeHostedWalletProviderRegistry.js.map +1 -1
  41. package/dist/wallet/node/providers/hosted/registry/__tests__/NodeHostedWalletProviderRegistry.spec.js +9 -1
  42. package/dist/wallet/node/providers/hosted/registry/__tests__/NodeHostedWalletProviderRegistry.spec.js.map +1 -1
  43. package/dist/wallet/node/providers/hosted/types/index.d.ts +6 -1
  44. package/dist/wallet/node/providers/hosted/types/index.d.ts.map +1 -1
  45. package/dist/wallet/node/wallets/hosted/privy/PrivyWallet.d.ts +10 -5
  46. package/dist/wallet/node/wallets/hosted/privy/PrivyWallet.d.ts.map +1 -1
  47. package/dist/wallet/node/wallets/hosted/privy/PrivyWallet.js +11 -6
  48. package/dist/wallet/node/wallets/hosted/privy/PrivyWallet.js.map +1 -1
  49. package/dist/wallet/node/wallets/hosted/privy/__tests__/PrivyWallet.spec.js +26 -28
  50. package/dist/wallet/node/wallets/hosted/privy/__tests__/PrivyWallet.spec.js.map +1 -1
  51. package/dist/wallet/node/wallets/hosted/privy/utils/__tests__/createSigner.spec.js +12 -12
  52. package/dist/wallet/node/wallets/hosted/privy/utils/__tests__/createSigner.spec.js.map +1 -1
  53. package/dist/wallet/node/wallets/hosted/privy/utils/createSigner.d.ts +6 -2
  54. package/dist/wallet/node/wallets/hosted/privy/utils/createSigner.d.ts.map +1 -1
  55. package/dist/wallet/node/wallets/hosted/privy/utils/createSigner.js +10 -7
  56. package/dist/wallet/node/wallets/hosted/privy/utils/createSigner.js.map +1 -1
  57. package/package.json +2 -2
  58. package/src/actions.test.ts +24 -4
  59. package/src/constants/assets.ts +8 -1
  60. package/src/constants/supportedChains.ts +8 -1
  61. package/src/lend/namespaces/WalletLendNamespace.ts +8 -2
  62. package/src/lend/providers/morpho/sdk.ts +0 -1
  63. package/src/test/MockPrivyClient.ts +24 -91
  64. package/src/wallet/core/namespace/WalletNamespace.ts +13 -13
  65. package/src/wallet/core/namespace/__tests__/WalletNamespace.spec.ts +60 -61
  66. package/src/wallet/core/providers/__tests__/WalletProvider.spec.ts +47 -39
  67. package/src/wallet/core/providers/hosted/registry/__tests__/HostedWalletProviderRegistry.spec.ts +20 -7
  68. package/src/wallet/node/providers/hosted/privy/PrivyHostedWalletProvider.ts +27 -9
  69. package/src/wallet/node/providers/hosted/privy/__tests__/PrivyHostedWalletProvider.spec.ts +40 -21
  70. package/src/wallet/node/providers/hosted/registry/NodeHostedWalletProviderRegistry.ts +4 -3
  71. package/src/wallet/node/providers/hosted/registry/__tests__/NodeHostedWalletProviderRegistry.spec.ts +17 -2
  72. package/src/wallet/node/providers/hosted/types/index.ts +9 -2
  73. package/src/wallet/node/wallets/hosted/privy/PrivyWallet.ts +14 -6
  74. package/src/wallet/node/wallets/hosted/privy/__tests__/PrivyWallet.spec.ts +35 -40
  75. package/src/wallet/node/wallets/hosted/privy/utils/__tests__/createSigner.spec.ts +18 -14
  76. package/src/wallet/node/wallets/hosted/privy/utils/createSigner.ts +11 -9
@@ -1,11 +1,14 @@
1
- import type { PrivyClient } from '@privy-io/server-auth'
1
+ import type { PrivyClient } from '@privy-io/node'
2
2
  import type { TurnkeyClient } from '@turnkey/http'
3
3
  import { unichain } from 'viem/chains'
4
4
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
5
5
 
6
6
  import type { ChainManager } from '@/services/ChainManager.js'
7
7
  import { MockChainManager } from '@/test/MockChainManager.js'
8
- import { createMockPrivyClient } from '@/test/MockPrivyClient.js'
8
+ import {
9
+ createMockPrivyClient,
10
+ getMockAuthorizationContext,
11
+ } from '@/test/MockPrivyClient.js'
9
12
  import { PrivyHostedWalletProvider } from '@/wallet/node/providers/hosted/privy/PrivyHostedWalletProvider.js'
10
13
  import { NodeHostedWalletProviderRegistry } from '@/wallet/node/providers/hosted/registry/NodeHostedWalletProviderRegistry.js'
11
14
  import { TurnkeyHostedWalletProvider } from '@/wallet/node/providers/hosted/turnkey/TurnkeyHostedWalletProvider.js'
@@ -31,6 +34,12 @@ describe('NodeHostedWalletProviderRegistry', () => {
31
34
  const factory = registry.getFactory('privy')
32
35
 
33
36
  expect(factory.type).toBe('privy')
37
+ expect(
38
+ factory.validateOptions?.({
39
+ privyClient: mockPrivyClient,
40
+ authorizationContext: getMockAuthorizationContext(),
41
+ } as NodeOptionsMap['privy']),
42
+ ).toBe(true)
34
43
  expect(
35
44
  factory.validateOptions?.({
36
45
  privyClient: mockPrivyClient,
@@ -38,6 +47,11 @@ describe('NodeHostedWalletProviderRegistry', () => {
38
47
  ).toBe(true)
39
48
  // Invalid shape should not pass validation
40
49
  expect(factory.validateOptions?.({})).toBe(false)
50
+ expect(
51
+ factory.validateOptions?.({
52
+ authorizationContext: getMockAuthorizationContext(),
53
+ } as NodeOptionsMap['privy']),
54
+ ).toBe(false)
41
55
  })
42
56
 
43
57
  it('creates a PrivyHostedWalletProvider instance', () => {
@@ -46,6 +60,7 @@ describe('NodeHostedWalletProviderRegistry', () => {
46
60
 
47
61
  const provider = factory.create({ chainManager: mockChainManager }, {
48
62
  privyClient: mockPrivyClient,
63
+ authorizationContext: getMockAuthorizationContext(),
49
64
  } as NodeOptionsMap['privy'])
50
65
 
51
66
  expect(provider).toBeInstanceOf(PrivyHostedWalletProvider)
@@ -1,4 +1,4 @@
1
- import type { PrivyClient } from '@privy-io/server-auth'
1
+ import type { AuthorizationContext, PrivyClient } from '@privy-io/node'
2
2
  import type { TurnkeySDKClientBase } from '@turnkey/core'
3
3
  import type { TurnkeyClient as TurnkeyHttpClient } from '@turnkey/http'
4
4
  import type { TurnkeyServerClient } from '@turnkey/sdk-server'
@@ -29,8 +29,15 @@ export interface NodeOptionsMap {
29
29
  /**
30
30
  * Privy provider configuration
31
31
  * @property privyClient Server-side Privy client instance used to query/create wallets
32
+ * @property authorizationContext Optional authorization context for the Privy client.
33
+ * Used when Privy needs to sign requests.
34
+ * See https://docs.privy.io/controls/authorization-keys/using-owners/sign/automatic#using-the-authorization-context
35
+ * for more information on building and using the authorization context.
32
36
  */
33
- privy: { privyClient: PrivyClient }
37
+ privy: {
38
+ privyClient: PrivyClient
39
+ authorizationContext?: AuthorizationContext
40
+ }
34
41
  /**
35
42
  * Turnkey provider configuration
36
43
  * @property client Turnkey SDK/HTTP client used to sign and manage keys
@@ -1,4 +1,4 @@
1
- import type { PrivyClient } from '@privy-io/server-auth'
1
+ import type { AuthorizationContext, PrivyClient } from '@privy-io/node'
2
2
  import { type Address, type LocalAccount } from 'viem'
3
3
 
4
4
  import type { ChainManager } from '@/services/ChainManager.js'
@@ -15,12 +15,15 @@ export class PrivyWallet extends EOAWallet {
15
15
  public signer!: LocalAccount
16
16
  public readonly address: Address
17
17
  private privyClient: PrivyClient
18
-
18
+ private authorizationContext?: AuthorizationContext
19
19
  /**
20
- * Create a new Privy wallet provider
21
- * @param appId - Privy application ID
22
- * @param appSecret - Privy application secret
23
- * @param actions - Actions instance for accessing configured providers
20
+ * Create a new Privy wallet instance
21
+ * @param privyClient - Privy client instance for wallet operations
22
+ * @param authorizationContext - Authorization context for signing requests
23
+ * @param walletId - Privy wallet identifier
24
+ * @param address - Ethereum address of the wallet
25
+ * @param chainManager - Chain manager for multi-chain operations
26
+ * @param lendProvider - Optional lend provider for DeFi operations
24
27
  */
25
28
  private constructor(
26
29
  privyClient: PrivyClient,
@@ -28,15 +31,18 @@ export class PrivyWallet extends EOAWallet {
28
31
  address: Address,
29
32
  chainManager: ChainManager,
30
33
  lendProvider?: LendProvider<LendConfig>,
34
+ authorizationContext?: AuthorizationContext,
31
35
  ) {
32
36
  super(chainManager, lendProvider)
33
37
  this.privyClient = privyClient
38
+ this.authorizationContext = authorizationContext
34
39
  this.walletId = walletId
35
40
  this.address = address
36
41
  }
37
42
 
38
43
  static async create(params: {
39
44
  privyClient: PrivyClient
45
+ authorizationContext?: AuthorizationContext
40
46
  walletId: string
41
47
  address: Address
42
48
  chainManager: ChainManager
@@ -48,6 +54,7 @@ export class PrivyWallet extends EOAWallet {
48
54
  params.address,
49
55
  params.chainManager,
50
56
  params.lendProvider,
57
+ params.authorizationContext,
51
58
  )
52
59
  await wallet.initialize()
53
60
  return wallet
@@ -73,6 +80,7 @@ export class PrivyWallet extends EOAWallet {
73
80
  walletId: this.walletId,
74
81
  address: this.address,
75
82
  privyClient: this.privyClient,
83
+ authorizationContext: this.authorizationContext,
76
84
  })
77
85
  }
78
86
  }
@@ -1,5 +1,5 @@
1
- import type { PrivyClient } from '@privy-io/server-auth'
2
- import { createViemAccount } from '@privy-io/server-auth/viem'
1
+ import type { AuthorizationContext } from '@privy-io/node'
2
+ import { createViemAccount } from '@privy-io/node/viem'
3
3
  import {
4
4
  type Address,
5
5
  createWalletClient,
@@ -8,11 +8,15 @@ import {
8
8
  type WalletClient,
9
9
  } from 'viem'
10
10
  import { unichain } from 'viem/chains'
11
- import { describe, expect, it, vi } from 'vitest'
11
+ import { beforeEach, describe, expect, it, vi } from 'vitest'
12
12
 
13
13
  import type { ChainManager } from '@/services/ChainManager.js'
14
14
  import { MockChainManager } from '@/test/MockChainManager.js'
15
- import { createMockPrivyClient } from '@/test/MockPrivyClient.js'
15
+ import {
16
+ createMockPrivyClient,
17
+ createMockPrivyWallet,
18
+ getMockAuthorizationContext,
19
+ } from '@/test/MockPrivyClient.js'
16
20
  import { getRandomAddress } from '@/test/utils.js'
17
21
  import { PrivyWallet } from '@/wallet/node/wallets/hosted/privy/PrivyWallet.js'
18
22
 
@@ -28,9 +32,9 @@ vi.mock('viem/accounts', async () => ({
28
32
  toAccount: vi.fn(),
29
33
  }))
30
34
 
31
- vi.mock('@privy-io/server-auth/viem', async () => ({
35
+ vi.mock('@privy-io/node/viem', async () => ({
32
36
  // @ts-ignore - importActual returns unknown
33
- ...(await vi.importActual('@privy-io/server-auth/viem')),
37
+ ...(await vi.importActual('@privy-io/node/viem')),
34
38
  createViemAccount: vi.fn(),
35
39
  }))
36
40
 
@@ -48,10 +52,12 @@ const mockLocalAccount = {
48
52
  } as unknown as LocalAccount
49
53
 
50
54
  describe('PrivyWallet', () => {
55
+ beforeEach(() => {
56
+ vi.clearAllMocks()
57
+ })
58
+
51
59
  it('should return the correct wallet ID', async () => {
52
- const createdWallet = await mockPrivyClient.walletApi.createWallet({
53
- chainType: 'ethereum',
54
- })
60
+ const createdWallet = createMockPrivyWallet()
55
61
 
56
62
  const wallet = await createAndInitPrivyWallet({
57
63
  address: getAddress(createdWallet.address),
@@ -62,9 +68,7 @@ describe('PrivyWallet', () => {
62
68
  })
63
69
 
64
70
  it('should return the correct address', async () => {
65
- const createdWallet = await mockPrivyClient.walletApi.createWallet({
66
- chainType: 'ethereum',
67
- })
71
+ const createdWallet = createMockPrivyWallet()
68
72
 
69
73
  const wallet = await createAndInitPrivyWallet({
70
74
  address: getAddress(createdWallet.address),
@@ -76,28 +80,29 @@ describe('PrivyWallet', () => {
76
80
 
77
81
  it('should create an account with correct configuration', async () => {
78
82
  // Create a wallet using the mock client first
79
- const createdWallet = await mockPrivyClient.walletApi.createWallet({
80
- chainType: 'ethereum',
81
- })
83
+ const createdWallet = createMockPrivyWallet()
82
84
  vi.mocked(createViemAccount).mockResolvedValue(mockLocalAccount)
85
+ const authorizationContext = getMockAuthorizationContext()
83
86
  const wallet = await createAndInitPrivyWallet({
84
87
  address: getAddress(createdWallet.address),
85
88
  walletId: createdWallet.id,
89
+ authorizationContext,
86
90
  })
87
91
 
88
- expect(createViemAccount).toHaveBeenCalledWith({
92
+ expect(createViemAccount).toHaveBeenCalledWith(mockPrivyClient, {
89
93
  walletId: createdWallet.id,
90
94
  address: createdWallet.address,
91
- privy: mockPrivyClient,
95
+ authorizationContext,
92
96
  })
93
97
  expect(wallet.signer).toBe(mockLocalAccount)
94
98
  })
95
99
 
96
100
  it('should create a wallet client with correct configuration', async () => {
97
- const createdWallet = await mockPrivyClient.walletApi.createWallet({
98
- chainType: 'ethereum',
101
+ const createdWallet = createMockPrivyWallet()
102
+ const wallet = await createAndInitPrivyWallet({
103
+ walletId: createdWallet.id,
104
+ address: createdWallet.address,
99
105
  })
100
- const wallet = await createAndInitPrivyWallet()
101
106
 
102
107
  const mockWalletClient = {
103
108
  account: mockLocalAccount,
@@ -116,27 +121,17 @@ describe('PrivyWallet', () => {
116
121
  })
117
122
  })
118
123
 
119
- async function createAndInitPrivyWallet(
120
- params: {
121
- privyClient?: PrivyClient
122
- walletId?: string
123
- address?: Address
124
- chainManager?: ChainManager
125
- } = {},
126
- ) {
127
- const {
128
- privyClient = mockPrivyClient,
124
+ async function createAndInitPrivyWallet(params: {
125
+ walletId: string
126
+ address: Address
127
+ authorizationContext?: AuthorizationContext
128
+ }) {
129
+ const { walletId, address, authorizationContext } = params
130
+ return PrivyWallet.create({
131
+ privyClient: mockPrivyClient,
132
+ authorizationContext: authorizationContext ?? getMockAuthorizationContext(),
129
133
  walletId,
130
134
  address,
131
- chainManager = mockChainManager,
132
- } = params
133
- const createdWallet = await privyClient.walletApi.createWallet({
134
- chainType: 'ethereum',
135
- })
136
- return PrivyWallet.create({
137
- privyClient,
138
- walletId: walletId ?? createdWallet.id,
139
- address: address ?? getAddress(createdWallet.address),
140
- chainManager,
135
+ chainManager: mockChainManager,
141
136
  })
142
137
  }
@@ -1,14 +1,18 @@
1
- import { createViemAccount } from '@privy-io/server-auth/viem'
2
- import type { Address, LocalAccount } from 'viem'
1
+ import { createViemAccount } from '@privy-io/node/viem'
2
+ import type { LocalAccount } from 'viem'
3
3
  import { describe, expect, it, vi } from 'vitest'
4
4
 
5
- import { createMockPrivyClient } from '@/test/MockPrivyClient.js'
5
+ import {
6
+ createMockPrivyClient,
7
+ createMockPrivyWallet,
8
+ getMockAuthorizationContext,
9
+ } from '@/test/MockPrivyClient.js'
6
10
  import { getRandomAddress } from '@/test/utils.js'
7
11
  import { createSigner } from '@/wallet/node/wallets/hosted/privy/utils/createSigner.js'
8
12
 
9
- vi.mock('@privy-io/server-auth/viem', async () => ({
13
+ vi.mock('@privy-io/node/viem', async () => ({
10
14
  // @ts-ignore - importActual returns unknown
11
- ...(await vi.importActual('@privy-io/server-auth/viem')),
15
+ ...(await vi.importActual('@privy-io/node/viem')),
12
16
  createViemAccount: vi.fn(),
13
17
  }))
14
18
 
@@ -26,22 +30,22 @@ describe('createSigner (Node Privy)', () => {
26
30
  signTypedData: vi.fn(),
27
31
  } as unknown as LocalAccount
28
32
 
29
- it('should create a LocalAccount with correct configuration', async () => {
30
- const createdWallet = await mockPrivyClient.walletApi.createWallet({
31
- chainType: 'ethereum',
32
- })
33
- vi.mocked(createViemAccount).mockResolvedValue(mockLocalAccount)
33
+ it('should create a LocalAccount with correct configuration', () => {
34
+ const createdWallet = createMockPrivyWallet()
35
+ vi.mocked(createViemAccount).mockReturnValue(mockLocalAccount)
36
+ const authorizationContext = getMockAuthorizationContext()
34
37
 
35
- const signer = await createSigner({
38
+ const signer = createSigner({
36
39
  privyClient: mockPrivyClient,
40
+ authorizationContext: authorizationContext,
37
41
  walletId: createdWallet.id,
38
- address: createdWallet.address as Address,
42
+ address: createdWallet.address,
39
43
  })
40
44
 
41
- expect(createViemAccount).toHaveBeenCalledWith({
45
+ expect(createViemAccount).toHaveBeenCalledWith(mockPrivyClient, {
42
46
  walletId: createdWallet.id,
43
47
  address: createdWallet.address,
44
- privy: mockPrivyClient,
48
+ authorizationContext,
45
49
  })
46
50
  expect(signer).toBe(mockLocalAccount)
47
51
  })
@@ -1,5 +1,4 @@
1
- import type { GetViemAccountInputType } from '@privy-io/server-auth/viem'
2
- import { createViemAccount } from '@privy-io/server-auth/viem'
1
+ import { createViemAccount } from '@privy-io/node/viem'
3
2
  import type { LocalAccount } from 'viem'
4
3
 
5
4
  import type {
@@ -15,18 +14,21 @@ import type {
15
14
  * @param params.walletId - Privy wallet identifier
16
15
  * @param params.address - Ethereum address of the wallet
17
16
  * @param params.privyClient - Privy client instance
18
- * @returns Promise resolving to a LocalAccount configured for signing operations
17
+ * @param params.authorizationContext - Optional authorization context for the Privy client.
18
+ * Used when Privy needs to sign requests.
19
+ * See https://docs.privy.io/controls/authorization-keys/using-owners/sign/automatic#using-the-authorization-context
20
+ * for more information on building and using the authorization context.
21
+ * @returns LocalAccount configured for signing operations
19
22
  * @throws Error if wallet retrieval fails or signing operations are not supported
20
23
  */
21
- export async function createSigner(
24
+ export function createSigner(
22
25
  params: PrivyHostedWalletToActionsWalletOptions & NodeOptionsMap['privy'],
23
- ): Promise<LocalAccount> {
24
- const { walletId, address, privyClient } = params
25
- const account = await createViemAccount({
26
+ ): LocalAccount {
27
+ const { walletId, address, privyClient, authorizationContext } = params
28
+ const account = createViemAccount(privyClient, {
26
29
  walletId,
27
30
  address,
28
- // TODO: Fix this type error
29
- privy: privyClient as unknown as GetViemAccountInputType['privy'],
31
+ authorizationContext,
30
32
  })
31
33
  return account
32
34
  }