@eth-optimism/actions-sdk 0.0.2 → 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.
- package/dist/actions.test.js +22 -2
- package/dist/actions.test.js.map +1 -1
- package/dist/constants/assets.d.ts.map +1 -1
- package/dist/constants/assets.js +2 -1
- package/dist/constants/assets.js.map +1 -1
- package/dist/constants/supportedChains.d.ts +1 -1
- package/dist/constants/supportedChains.d.ts.map +1 -1
- package/dist/constants/supportedChains.js +2 -1
- package/dist/constants/supportedChains.js.map +1 -1
- package/dist/lend/namespaces/WalletLendNamespace.d.ts +8 -2
- package/dist/lend/namespaces/WalletLendNamespace.d.ts.map +1 -1
- package/dist/lend/namespaces/WalletLendNamespace.js +8 -2
- package/dist/lend/namespaces/WalletLendNamespace.js.map +1 -1
- package/dist/lend/providers/morpho/sdk.d.ts.map +1 -1
- package/dist/lend/providers/morpho/sdk.js +0 -1
- package/dist/lend/providers/morpho/sdk.js.map +1 -1
- package/dist/services/ChainManager.d.ts +1 -1
- package/dist/test/MockPrivyClient.d.ts +10 -49
- package/dist/test/MockPrivyClient.d.ts.map +1 -1
- package/dist/test/MockPrivyClient.js +13 -72
- package/dist/test/MockPrivyClient.js.map +1 -1
- package/dist/wallet/core/namespace/WalletNamespace.d.ts +13 -13
- package/dist/wallet/core/namespace/WalletNamespace.d.ts.map +1 -1
- package/dist/wallet/core/namespace/WalletNamespace.js +13 -13
- package/dist/wallet/core/namespace/WalletNamespace.js.map +1 -1
- package/dist/wallet/core/namespace/__tests__/WalletNamespace.spec.js +55 -33
- package/dist/wallet/core/namespace/__tests__/WalletNamespace.spec.js.map +1 -1
- package/dist/wallet/core/providers/__tests__/WalletProvider.spec.js +43 -15
- package/dist/wallet/core/providers/__tests__/WalletProvider.spec.js.map +1 -1
- package/dist/wallet/core/providers/hosted/registry/__tests__/HostedWalletProviderRegistry.spec.js +14 -4
- package/dist/wallet/core/providers/hosted/registry/__tests__/HostedWalletProviderRegistry.spec.js.map +1 -1
- package/dist/wallet/node/providers/hosted/privy/PrivyHostedWalletProvider.d.ts +16 -3
- package/dist/wallet/node/providers/hosted/privy/PrivyHostedWalletProvider.d.ts.map +1 -1
- package/dist/wallet/node/providers/hosted/privy/PrivyHostedWalletProvider.js +18 -5
- package/dist/wallet/node/providers/hosted/privy/PrivyHostedWalletProvider.js.map +1 -1
- package/dist/wallet/node/providers/hosted/privy/__tests__/PrivyHostedWalletProvider.spec.js +31 -12
- package/dist/wallet/node/providers/hosted/privy/__tests__/PrivyHostedWalletProvider.spec.js.map +1 -1
- package/dist/wallet/node/providers/hosted/registry/NodeHostedWalletProviderRegistry.d.ts.map +1 -1
- package/dist/wallet/node/providers/hosted/registry/NodeHostedWalletProviderRegistry.js +6 -1
- package/dist/wallet/node/providers/hosted/registry/NodeHostedWalletProviderRegistry.js.map +1 -1
- package/dist/wallet/node/providers/hosted/registry/__tests__/NodeHostedWalletProviderRegistry.spec.js +9 -1
- package/dist/wallet/node/providers/hosted/registry/__tests__/NodeHostedWalletProviderRegistry.spec.js.map +1 -1
- package/dist/wallet/node/providers/hosted/types/index.d.ts +6 -1
- package/dist/wallet/node/providers/hosted/types/index.d.ts.map +1 -1
- package/dist/wallet/node/wallets/hosted/privy/PrivyWallet.d.ts +10 -5
- package/dist/wallet/node/wallets/hosted/privy/PrivyWallet.d.ts.map +1 -1
- package/dist/wallet/node/wallets/hosted/privy/PrivyWallet.js +11 -6
- package/dist/wallet/node/wallets/hosted/privy/PrivyWallet.js.map +1 -1
- package/dist/wallet/node/wallets/hosted/privy/__tests__/PrivyWallet.spec.js +26 -28
- package/dist/wallet/node/wallets/hosted/privy/__tests__/PrivyWallet.spec.js.map +1 -1
- package/dist/wallet/node/wallets/hosted/privy/utils/__tests__/createSigner.spec.js +12 -12
- package/dist/wallet/node/wallets/hosted/privy/utils/__tests__/createSigner.spec.js.map +1 -1
- package/dist/wallet/node/wallets/hosted/privy/utils/createSigner.d.ts +6 -2
- package/dist/wallet/node/wallets/hosted/privy/utils/createSigner.d.ts.map +1 -1
- package/dist/wallet/node/wallets/hosted/privy/utils/createSigner.js +10 -7
- package/dist/wallet/node/wallets/hosted/privy/utils/createSigner.js.map +1 -1
- package/package.json +2 -2
- package/src/actions.test.ts +24 -4
- package/src/constants/assets.ts +8 -1
- package/src/constants/supportedChains.ts +8 -1
- package/src/lend/namespaces/WalletLendNamespace.ts +8 -2
- package/src/lend/providers/morpho/sdk.ts +0 -1
- package/src/test/MockPrivyClient.ts +24 -91
- package/src/wallet/core/namespace/WalletNamespace.ts +13 -13
- package/src/wallet/core/namespace/__tests__/WalletNamespace.spec.ts +60 -61
- package/src/wallet/core/providers/__tests__/WalletProvider.spec.ts +47 -39
- package/src/wallet/core/providers/hosted/registry/__tests__/HostedWalletProviderRegistry.spec.ts +20 -7
- package/src/wallet/node/providers/hosted/privy/PrivyHostedWalletProvider.ts +27 -9
- package/src/wallet/node/providers/hosted/privy/__tests__/PrivyHostedWalletProvider.spec.ts +40 -21
- package/src/wallet/node/providers/hosted/registry/NodeHostedWalletProviderRegistry.ts +4 -3
- package/src/wallet/node/providers/hosted/registry/__tests__/NodeHostedWalletProviderRegistry.spec.ts +17 -2
- package/src/wallet/node/providers/hosted/types/index.ts +9 -2
- package/src/wallet/node/wallets/hosted/privy/PrivyWallet.ts +14 -6
- package/src/wallet/node/wallets/hosted/privy/__tests__/PrivyWallet.spec.ts +35 -40
- package/src/wallet/node/wallets/hosted/privy/utils/__tests__/createSigner.spec.ts +18 -14
- package/src/wallet/node/wallets/hosted/privy/utils/createSigner.ts +11 -9
package/src/wallet/node/providers/hosted/registry/__tests__/NodeHostedWalletProviderRegistry.spec.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import type { PrivyClient } from '@privy-io/
|
|
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 {
|
|
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/
|
|
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: {
|
|
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/
|
|
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
|
|
21
|
-
* @param
|
|
22
|
-
* @param
|
|
23
|
-
* @param
|
|
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 {
|
|
2
|
-
import { createViemAccount } from '@privy-io/
|
|
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 {
|
|
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/
|
|
35
|
+
vi.mock('@privy-io/node/viem', async () => ({
|
|
32
36
|
// @ts-ignore - importActual returns unknown
|
|
33
|
-
...(await vi.importActual('@privy-io/
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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 =
|
|
98
|
-
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
|
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/
|
|
2
|
-
import type {
|
|
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 {
|
|
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/
|
|
13
|
+
vi.mock('@privy-io/node/viem', async () => ({
|
|
10
14
|
// @ts-ignore - importActual returns unknown
|
|
11
|
-
...(await vi.importActual('@privy-io/
|
|
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',
|
|
30
|
-
const createdWallet =
|
|
31
|
-
|
|
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 =
|
|
38
|
+
const signer = createSigner({
|
|
36
39
|
privyClient: mockPrivyClient,
|
|
40
|
+
authorizationContext: authorizationContext,
|
|
37
41
|
walletId: createdWallet.id,
|
|
38
|
-
address: createdWallet.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
|
-
|
|
48
|
+
authorizationContext,
|
|
45
49
|
})
|
|
46
50
|
expect(signer).toBe(mockLocalAccount)
|
|
47
51
|
})
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
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
|
-
* @
|
|
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
|
|
24
|
+
export function createSigner(
|
|
22
25
|
params: PrivyHostedWalletToActionsWalletOptions & NodeOptionsMap['privy'],
|
|
23
|
-
):
|
|
24
|
-
const { walletId, address, privyClient } = params
|
|
25
|
-
const account =
|
|
26
|
+
): LocalAccount {
|
|
27
|
+
const { walletId, address, privyClient, authorizationContext } = params
|
|
28
|
+
const account = createViemAccount(privyClient, {
|
|
26
29
|
walletId,
|
|
27
30
|
address,
|
|
28
|
-
|
|
29
|
-
privy: privyClient as unknown as GetViemAccountInputType['privy'],
|
|
31
|
+
authorizationContext,
|
|
30
32
|
})
|
|
31
33
|
return account
|
|
32
34
|
}
|