@privy-io/node 0.8.0 → 0.9.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 +43 -0
- package/client.d.mts +17 -10
- package/client.d.mts.map +1 -1
- package/client.d.ts +17 -10
- package/client.d.ts.map +1 -1
- package/client.js +17 -3
- package/client.js.map +1 -1
- package/client.mjs +17 -3
- package/client.mjs.map +1 -1
- package/internal/parse.d.mts.map +1 -1
- package/internal/parse.d.ts.map +1 -1
- package/internal/parse.js +5 -0
- package/internal/parse.js.map +1 -1
- package/internal/parse.mjs +5 -0
- package/internal/parse.mjs.map +1 -1
- package/package.json +21 -1
- package/resources/aggregations.d.mts +213 -2
- package/resources/aggregations.d.mts.map +1 -1
- package/resources/aggregations.d.ts +213 -2
- package/resources/aggregations.d.ts.map +1 -1
- package/resources/client-auth.d.mts +168 -2
- package/resources/client-auth.d.mts.map +1 -1
- package/resources/client-auth.d.ts +168 -2
- package/resources/client-auth.d.ts.map +1 -1
- package/resources/index.d.mts +6 -4
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +6 -4
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +5 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +2 -0
- package/resources/index.mjs.map +1 -1
- package/resources/policies.d.mts +2 -4
- package/resources/policies.d.mts.map +1 -1
- package/resources/policies.d.ts +2 -4
- package/resources/policies.d.ts.map +1 -1
- package/resources/users.d.mts +16 -6
- package/resources/users.d.mts.map +1 -1
- package/resources/users.d.ts +16 -6
- package/resources/users.d.ts.map +1 -1
- package/resources/wallets/balance.d.mts +10 -5
- package/resources/wallets/balance.d.mts.map +1 -1
- package/resources/wallets/balance.d.ts +10 -5
- package/resources/wallets/balance.d.ts.map +1 -1
- package/resources/wallets/balance.js +1 -2
- package/resources/wallets/balance.js.map +1 -1
- package/resources/wallets/balance.mjs +1 -2
- package/resources/wallets/balance.mjs.map +1 -1
- package/resources/wallets/index.d.mts +1 -1
- package/resources/wallets/index.d.mts.map +1 -1
- package/resources/wallets/index.d.ts +1 -1
- package/resources/wallets/index.d.ts.map +1 -1
- package/resources/wallets/index.js.map +1 -1
- package/resources/wallets/index.mjs.map +1 -1
- package/resources/wallets/transactions.d.mts +2 -2
- package/resources/wallets/transactions.d.mts.map +1 -1
- package/resources/wallets/transactions.d.ts +2 -2
- package/resources/wallets/transactions.d.ts.map +1 -1
- package/resources/wallets/wallets.d.mts +133 -13
- package/resources/wallets/wallets.d.mts.map +1 -1
- package/resources/wallets/wallets.d.ts +133 -13
- package/resources/wallets/wallets.d.ts.map +1 -1
- package/resources/wallets/wallets.js.map +1 -1
- package/resources/wallets/wallets.mjs.map +1 -1
- package/resources/webhooks.d.mts +940 -0
- package/resources/webhooks.d.mts.map +1 -0
- package/resources/webhooks.d.ts +940 -0
- package/resources/webhooks.d.ts.map +1 -0
- package/resources/webhooks.js +9 -0
- package/resources/webhooks.js.map +1 -0
- package/resources/webhooks.mjs +5 -0
- package/resources/webhooks.mjs.map +1 -0
- package/resources/yield.d.mts +264 -0
- package/resources/yield.d.mts.map +1 -0
- package/resources/yield.d.ts +264 -0
- package/resources/yield.d.ts.map +1 -0
- package/resources/yield.js +9 -0
- package/resources/yield.js.map +1 -0
- package/resources/yield.mjs +5 -0
- package/resources/yield.mjs.map +1 -0
- package/src/client.ts +179 -9
- package/src/internal/parse.ts +6 -0
- package/src/resources/aggregations.ts +361 -5
- package/src/resources/client-auth.ts +288 -1
- package/src/resources/index.ts +79 -3
- package/src/resources/policies.ts +2 -4
- package/src/resources/users.ts +52 -35
- package/src/resources/wallets/balance.ts +15 -5
- package/src/resources/wallets/index.ts +6 -2
- package/src/resources/wallets/transactions.ts +2 -2
- package/src/resources/wallets/wallets.ts +176 -30
- package/src/resources/webhooks.ts +1287 -0
- package/src/resources/yield.ts +330 -0
- package/src/types/x402.d.ts +18 -0
- package/src/version.ts +1 -1
- package/src/x402.ts +87 -0
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
- package/x402.d.mts +54 -0
- package/x402.d.mts.map +1 -0
- package/x402.d.ts +54 -0
- package/x402.d.ts.map +1 -0
- package/x402.js +75 -0
- package/x402.js.map +1 -0
- package/x402.mjs +72 -0
- package/x402.mjs.map +1 -0
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { APIResource } from '../core/resource';
|
|
4
|
+
|
|
5
|
+
export class Yield extends APIResource {}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Supported yield/lending protocol providers.
|
|
9
|
+
*/
|
|
10
|
+
export type EthereumYieldProvider = 'morpho' | 'aave';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Type of yield sweep.
|
|
14
|
+
*/
|
|
15
|
+
export type EthereumYieldSweepType = 'deposit' | 'withdraw';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Status of a yield sweep.
|
|
19
|
+
*/
|
|
20
|
+
export type EthereumYieldSweepStatus = 'pending' | 'confirmed' | 'failed';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Input for depositing assets into an ERC-4626 vault.
|
|
24
|
+
*/
|
|
25
|
+
export interface EthereumYieldDepositInput {
|
|
26
|
+
/**
|
|
27
|
+
* The amount of the underlying asset to deposit, in the smallest unit (e.g., wei
|
|
28
|
+
* for ETH, 6 decimals for USDC). Must be a non-negative integer string.
|
|
29
|
+
*/
|
|
30
|
+
asset_amount: string;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The ID of the vault to deposit into.
|
|
34
|
+
*/
|
|
35
|
+
vault_id: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Input for withdrawing assets from an ERC-4626 vault.
|
|
40
|
+
*/
|
|
41
|
+
export interface EthereumYieldWithdrawInput {
|
|
42
|
+
/**
|
|
43
|
+
* The amount of the underlying asset to withdraw, in the smallest unit (e.g., wei
|
|
44
|
+
* for ETH, 6 decimals for USDC). Must be a non-negative integer string.
|
|
45
|
+
*/
|
|
46
|
+
asset_amount: string;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The ID of the vault to withdraw from.
|
|
50
|
+
*/
|
|
51
|
+
vault_id: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* A yield sweep record representing a deposit or withdrawal.
|
|
56
|
+
*/
|
|
57
|
+
export interface EthereumYieldSweepResponse {
|
|
58
|
+
/**
|
|
59
|
+
* Unique identifier for the yield sweep.
|
|
60
|
+
*/
|
|
61
|
+
id: string;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The ID of the ERC-20 approval transaction (for deposits).
|
|
65
|
+
*/
|
|
66
|
+
approval_transaction_id: string | null;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The amount of underlying assets involved. Set after the sweep is confirmed
|
|
70
|
+
* on-chain.
|
|
71
|
+
*/
|
|
72
|
+
asset_amount: string | null;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Unix timestamp of when the sweep was created, in milliseconds.
|
|
76
|
+
*/
|
|
77
|
+
created_at: number;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The amount of vault shares involved. Set after the sweep is confirmed on-chain.
|
|
81
|
+
*/
|
|
82
|
+
share_amount: string | null;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Status of a yield sweep.
|
|
86
|
+
*/
|
|
87
|
+
status: EthereumYieldSweepStatus;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The ID of the underlying blockchain transaction (deposit/withdraw).
|
|
91
|
+
*/
|
|
92
|
+
transaction_id: string | null;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Type of yield sweep.
|
|
96
|
+
*/
|
|
97
|
+
type: EthereumYieldSweepType;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Unix timestamp of when the sweep was last updated, in milliseconds.
|
|
101
|
+
*/
|
|
102
|
+
updated_at: number;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The ID of the vault involved in the sweep.
|
|
106
|
+
*/
|
|
107
|
+
vault_id: string;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The ID of the wallet involved in the sweep.
|
|
111
|
+
*/
|
|
112
|
+
wallet_id: string;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Input for fetching vault details.
|
|
117
|
+
*/
|
|
118
|
+
export interface EthereumVaultDetailsInput {
|
|
119
|
+
/**
|
|
120
|
+
* The Privy vault ID.
|
|
121
|
+
*/
|
|
122
|
+
vault_id: string;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Input for fetching a yield sweep by ID.
|
|
127
|
+
*/
|
|
128
|
+
export interface EthereumYieldSweepIDInput {
|
|
129
|
+
/**
|
|
130
|
+
* The yield sweep ID.
|
|
131
|
+
*/
|
|
132
|
+
id: string;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* A vault configuration for yield features.
|
|
137
|
+
*/
|
|
138
|
+
export interface EthereumVaultResponse {
|
|
139
|
+
/**
|
|
140
|
+
* Unique identifier for the vault.
|
|
141
|
+
*/
|
|
142
|
+
id: string;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* The address of the underlying asset token (e.g., USDC).
|
|
146
|
+
*/
|
|
147
|
+
asset_address: string;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* The CAIP-2 chain identifier.
|
|
151
|
+
*/
|
|
152
|
+
caip2: string;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Unix timestamp of when the vault was created, in milliseconds.
|
|
156
|
+
*/
|
|
157
|
+
created_at: number;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Supported yield/lending protocol providers.
|
|
161
|
+
*/
|
|
162
|
+
provider: EthereumYieldProvider;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* The address of the underlying vault that the fee vault wraps. If this is not a
|
|
166
|
+
* fee vault, this equals vault_address.
|
|
167
|
+
*/
|
|
168
|
+
underlying_vault_address: string;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* The on-chain address of the ERC-4626 vault contract.
|
|
172
|
+
*/
|
|
173
|
+
vault_address: string;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Detailed vault information including current APY and liquidity.
|
|
178
|
+
*/
|
|
179
|
+
export interface EthereumVaultDetailsResponse {
|
|
180
|
+
/**
|
|
181
|
+
* Vault identifier.
|
|
182
|
+
*/
|
|
183
|
+
id: string;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Underlying asset token address.
|
|
187
|
+
*/
|
|
188
|
+
asset_address: string;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Assets available for instant withdrawal in USD.
|
|
192
|
+
*/
|
|
193
|
+
available_liquidity_usd: number | null;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Chain identifier (e.g., eip155:8453).
|
|
197
|
+
*/
|
|
198
|
+
caip2: string;
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Supported yield/lending protocol providers.
|
|
202
|
+
*/
|
|
203
|
+
provider: EthereumYieldProvider;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Total value locked in USD.
|
|
207
|
+
*/
|
|
208
|
+
tvl_usd: number | null;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Current annual percentage yield in basis points (e.g., 500 for 5%). 1 basis
|
|
212
|
+
* point = 0.01%.
|
|
213
|
+
*/
|
|
214
|
+
user_apy: number | null;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* On-chain vault contract address.
|
|
218
|
+
*/
|
|
219
|
+
vault_address: string;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Input for fetching yield positions.
|
|
224
|
+
*/
|
|
225
|
+
export interface EthereumYieldPositionsInput {
|
|
226
|
+
/**
|
|
227
|
+
* The vault ID to get position for.
|
|
228
|
+
*/
|
|
229
|
+
vault_id: string;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* A user's position in a DeFi vault.
|
|
234
|
+
*/
|
|
235
|
+
export interface EthereumVaultPosition {
|
|
236
|
+
asset: EthereumVaultPosition.Asset;
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Current asset value in the vault (realtime from ERC4626), in smallest unit.
|
|
240
|
+
*/
|
|
241
|
+
assets_in_vault: string;
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Current vault shares held (realtime from ERC4626).
|
|
245
|
+
*/
|
|
246
|
+
shares_in_vault: string;
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Total amount deposited into the vault, in smallest unit.
|
|
250
|
+
*/
|
|
251
|
+
total_deposited: string;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Total amount withdrawn from the vault, in smallest unit.
|
|
255
|
+
*/
|
|
256
|
+
total_withdrawn: string;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export namespace EthereumVaultPosition {
|
|
260
|
+
export interface Asset {
|
|
261
|
+
/**
|
|
262
|
+
* Token contract address.
|
|
263
|
+
*/
|
|
264
|
+
address: string;
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Token symbol (e.g., "USDC").
|
|
268
|
+
*/
|
|
269
|
+
symbol: string;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* A user's position in a yield vault.
|
|
275
|
+
*/
|
|
276
|
+
export interface EthereumYieldPositionResponse {
|
|
277
|
+
asset: EthereumYieldPositionResponse.Asset;
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Current asset value in the vault (realtime from ERC4626), in smallest unit.
|
|
281
|
+
*/
|
|
282
|
+
assets_in_vault: string;
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Current vault shares held (realtime from ERC4626).
|
|
286
|
+
*/
|
|
287
|
+
shares_in_vault: string;
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Total amount deposited into the vault, in smallest unit.
|
|
291
|
+
*/
|
|
292
|
+
total_deposited: string;
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Total amount withdrawn from the vault, in smallest unit.
|
|
296
|
+
*/
|
|
297
|
+
total_withdrawn: string;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export namespace EthereumYieldPositionResponse {
|
|
301
|
+
export interface Asset {
|
|
302
|
+
/**
|
|
303
|
+
* Token contract address.
|
|
304
|
+
*/
|
|
305
|
+
address: string;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Token symbol (e.g., "USDC").
|
|
309
|
+
*/
|
|
310
|
+
symbol: string;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export declare namespace Yield {
|
|
315
|
+
export {
|
|
316
|
+
type EthereumYieldProvider as EthereumYieldProvider,
|
|
317
|
+
type EthereumYieldSweepType as EthereumYieldSweepType,
|
|
318
|
+
type EthereumYieldSweepStatus as EthereumYieldSweepStatus,
|
|
319
|
+
type EthereumYieldDepositInput as EthereumYieldDepositInput,
|
|
320
|
+
type EthereumYieldWithdrawInput as EthereumYieldWithdrawInput,
|
|
321
|
+
type EthereumYieldSweepResponse as EthereumYieldSweepResponse,
|
|
322
|
+
type EthereumVaultDetailsInput as EthereumVaultDetailsInput,
|
|
323
|
+
type EthereumYieldSweepIDInput as EthereumYieldSweepIDInput,
|
|
324
|
+
type EthereumVaultResponse as EthereumVaultResponse,
|
|
325
|
+
type EthereumVaultDetailsResponse as EthereumVaultDetailsResponse,
|
|
326
|
+
type EthereumYieldPositionsInput as EthereumYieldPositionsInput,
|
|
327
|
+
type EthereumVaultPosition as EthereumVaultPosition,
|
|
328
|
+
type EthereumYieldPositionResponse as EthereumYieldPositionResponse,
|
|
329
|
+
};
|
|
330
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare module '@x402/fetch' {
|
|
2
|
+
export class x402Client {}
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
declare module '@x402/evm/exact/client' {
|
|
6
|
+
import type { x402Client } from '@x402/fetch';
|
|
7
|
+
import type { LocalAccount } from 'viem';
|
|
8
|
+
export function registerExactEvmScheme(client: x402Client, options: { signer: LocalAccount }): x402Client;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare module '@x402/svm/exact/client' {
|
|
12
|
+
import type { x402Client } from '@x402/fetch';
|
|
13
|
+
import type { TransactionSigner } from '@solana/kit';
|
|
14
|
+
export function registerExactSvmScheme(
|
|
15
|
+
client: x402Client,
|
|
16
|
+
options: { signer: TransactionSigner },
|
|
17
|
+
): x402Client;
|
|
18
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.9.0'; // x-release-please-version
|
package/src/x402.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { isAddress as isEvmAddress, type Hex } from 'viem';
|
|
2
|
+
import { isAddress as isSolanaAddress, type Address } from '@solana/kit';
|
|
3
|
+
import { x402Client } from '@x402/fetch';
|
|
4
|
+
import { registerExactEvmScheme } from '@x402/evm/exact/client';
|
|
5
|
+
import { registerExactSvmScheme } from '@x402/svm/exact/client';
|
|
6
|
+
|
|
7
|
+
import { createViemAccount } from './viem';
|
|
8
|
+
import { createSolanaKitSigner } from './solana-kit';
|
|
9
|
+
import type { AuthorizationContext } from './lib/authorization';
|
|
10
|
+
import type { PrivyClient } from './public-api/PrivyClient';
|
|
11
|
+
|
|
12
|
+
export interface CreateX402ClientInput {
|
|
13
|
+
/** ID for the wallet. */
|
|
14
|
+
walletId: string;
|
|
15
|
+
/** Address for the wallet. */
|
|
16
|
+
address: string;
|
|
17
|
+
/** Authorization context for the wallet. */
|
|
18
|
+
authorizationContext?: AuthorizationContext;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Creates an x402 client configured with a Privy wallet for automatic payment handling.
|
|
23
|
+
*
|
|
24
|
+
* The returned client can be used with x402's `wrapFetchWithPayment` or `wrapAxiosWithPayment`
|
|
25
|
+
* to automatically handle HTTP 402 Payment Required responses.
|
|
26
|
+
*
|
|
27
|
+
* @experimental This API is experimental and may change in future versions.
|
|
28
|
+
*
|
|
29
|
+
* @param client - The Privy client instance
|
|
30
|
+
* @param input - Configuration for the x402 client
|
|
31
|
+
* @param input.walletId - ID of the Privy wallet to use for payments
|
|
32
|
+
* @param input.address - Address of the wallet
|
|
33
|
+
* @param input.authorizationContext - Authorization context for the wallet
|
|
34
|
+
* @returns A configured x402Client instance
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* import { PrivyClient } from '@privy-io/node';
|
|
39
|
+
* import { createX402Client } from '@privy-io/node/x402';
|
|
40
|
+
* import { wrapFetchWithPayment } from '@x402/fetch';
|
|
41
|
+
*
|
|
42
|
+
* const privyClient = new PrivyClient({ appId, appSecret });
|
|
43
|
+
*
|
|
44
|
+
* // Get wallet details
|
|
45
|
+
* const wallet = await privyClient.wallets().get('walletId');
|
|
46
|
+
*
|
|
47
|
+
* // Create x402 client
|
|
48
|
+
* const x402client = createX402Client(privyClient, {
|
|
49
|
+
* walletId: wallet.id,
|
|
50
|
+
* address: wallet.address,
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* // Use with fetch
|
|
54
|
+
* const fetchWithPayment = wrapFetchWithPayment(fetch, x402client);
|
|
55
|
+
* const response = await fetchWithPayment('https://api.example.com/premium');
|
|
56
|
+
*
|
|
57
|
+
* // Or use with axios
|
|
58
|
+
* // import { wrapAxiosWithPayment } from '@x402/axios';
|
|
59
|
+
* // const axiosWithPayment = wrapAxiosWithPayment(axios, x402client);
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export function createX402Client(
|
|
63
|
+
client: PrivyClient,
|
|
64
|
+
{ walletId, address, authorizationContext }: CreateX402ClientInput,
|
|
65
|
+
): x402Client {
|
|
66
|
+
const x402client = new x402Client();
|
|
67
|
+
|
|
68
|
+
if (isEvmAddress(address)) {
|
|
69
|
+
const evmSigner = createViemAccount(client, {
|
|
70
|
+
walletId,
|
|
71
|
+
address: address as Hex,
|
|
72
|
+
...(authorizationContext ? { authorizationContext } : {}),
|
|
73
|
+
});
|
|
74
|
+
registerExactEvmScheme(x402client, { signer: evmSigner });
|
|
75
|
+
} else if (isSolanaAddress(address)) {
|
|
76
|
+
const solanaSigner = createSolanaKitSigner(client, {
|
|
77
|
+
walletId,
|
|
78
|
+
address: address as Address,
|
|
79
|
+
...(authorizationContext ? { authorizationContext } : {}),
|
|
80
|
+
});
|
|
81
|
+
registerExactSvmScheme(x402client, { signer: solanaSigner });
|
|
82
|
+
} else {
|
|
83
|
+
throw new Error(`Invalid wallet address: ${address}. Address must be a valid EVM or Solana address.`);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return x402client;
|
|
87
|
+
}
|
package/version.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.9.0";
|
|
2
2
|
//# sourceMappingURL=version.d.mts.map
|
package/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.9.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/version.js
CHANGED
package/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.9.0'; // x-release-please-version
|
|
2
2
|
//# sourceMappingURL=version.mjs.map
|
package/x402.d.mts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { x402Client } from '@x402/fetch';
|
|
2
|
+
import type { AuthorizationContext } from "./lib/authorization.mjs";
|
|
3
|
+
import type { PrivyClient } from "./public-api/PrivyClient.mjs";
|
|
4
|
+
export interface CreateX402ClientInput {
|
|
5
|
+
/** ID for the wallet. */
|
|
6
|
+
walletId: string;
|
|
7
|
+
/** Address for the wallet. */
|
|
8
|
+
address: string;
|
|
9
|
+
/** Authorization context for the wallet. */
|
|
10
|
+
authorizationContext?: AuthorizationContext;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Creates an x402 client configured with a Privy wallet for automatic payment handling.
|
|
14
|
+
*
|
|
15
|
+
* The returned client can be used with x402's `wrapFetchWithPayment` or `wrapAxiosWithPayment`
|
|
16
|
+
* to automatically handle HTTP 402 Payment Required responses.
|
|
17
|
+
*
|
|
18
|
+
* @experimental This API is experimental and may change in future versions.
|
|
19
|
+
*
|
|
20
|
+
* @param client - The Privy client instance
|
|
21
|
+
* @param input - Configuration for the x402 client
|
|
22
|
+
* @param input.walletId - ID of the Privy wallet to use for payments
|
|
23
|
+
* @param input.address - Address of the wallet
|
|
24
|
+
* @param input.authorizationContext - Authorization context for the wallet
|
|
25
|
+
* @returns A configured x402Client instance
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { PrivyClient } from '@privy-io/node';
|
|
30
|
+
* import { createX402Client } from '@privy-io/node/x402';
|
|
31
|
+
* import { wrapFetchWithPayment } from '@x402/fetch';
|
|
32
|
+
*
|
|
33
|
+
* const privyClient = new PrivyClient({ appId, appSecret });
|
|
34
|
+
*
|
|
35
|
+
* // Get wallet details
|
|
36
|
+
* const wallet = await privyClient.wallets().get('walletId');
|
|
37
|
+
*
|
|
38
|
+
* // Create x402 client
|
|
39
|
+
* const x402client = createX402Client(privyClient, {
|
|
40
|
+
* walletId: wallet.id,
|
|
41
|
+
* address: wallet.address,
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* // Use with fetch
|
|
45
|
+
* const fetchWithPayment = wrapFetchWithPayment(fetch, x402client);
|
|
46
|
+
* const response = await fetchWithPayment('https://api.example.com/premium');
|
|
47
|
+
*
|
|
48
|
+
* // Or use with axios
|
|
49
|
+
* // import { wrapAxiosWithPayment } from '@x402/axios';
|
|
50
|
+
* // const axiosWithPayment = wrapAxiosWithPayment(axios, x402client);
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function createX402Client(client: PrivyClient, { walletId, address, authorizationContext }: CreateX402ClientInput): x402Client;
|
|
54
|
+
//# sourceMappingURL=x402.d.mts.map
|
package/x402.d.mts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x402.d.mts","sourceRoot":"","sources":["src/x402.ts"],"names":[],"mappings":"OAEO,EAAE,UAAU,EAAE,MAAM,aAAa;OAMjC,KAAK,EAAE,oBAAoB,EAAE;OAC7B,KAAK,EAAE,WAAW,EAAE;AAE3B,MAAM,WAAW,qBAAqB;IACpC,yBAAyB;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;CAC7C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,WAAW,EACnB,EAAE,QAAQ,EAAE,OAAO,EAAE,oBAAoB,EAAE,EAAE,qBAAqB,GACjE,UAAU,CAsBZ"}
|
package/x402.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { x402Client } from '@x402/fetch';
|
|
2
|
+
import type { AuthorizationContext } from "./lib/authorization.js";
|
|
3
|
+
import type { PrivyClient } from "./public-api/PrivyClient.js";
|
|
4
|
+
export interface CreateX402ClientInput {
|
|
5
|
+
/** ID for the wallet. */
|
|
6
|
+
walletId: string;
|
|
7
|
+
/** Address for the wallet. */
|
|
8
|
+
address: string;
|
|
9
|
+
/** Authorization context for the wallet. */
|
|
10
|
+
authorizationContext?: AuthorizationContext;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Creates an x402 client configured with a Privy wallet for automatic payment handling.
|
|
14
|
+
*
|
|
15
|
+
* The returned client can be used with x402's `wrapFetchWithPayment` or `wrapAxiosWithPayment`
|
|
16
|
+
* to automatically handle HTTP 402 Payment Required responses.
|
|
17
|
+
*
|
|
18
|
+
* @experimental This API is experimental and may change in future versions.
|
|
19
|
+
*
|
|
20
|
+
* @param client - The Privy client instance
|
|
21
|
+
* @param input - Configuration for the x402 client
|
|
22
|
+
* @param input.walletId - ID of the Privy wallet to use for payments
|
|
23
|
+
* @param input.address - Address of the wallet
|
|
24
|
+
* @param input.authorizationContext - Authorization context for the wallet
|
|
25
|
+
* @returns A configured x402Client instance
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { PrivyClient } from '@privy-io/node';
|
|
30
|
+
* import { createX402Client } from '@privy-io/node/x402';
|
|
31
|
+
* import { wrapFetchWithPayment } from '@x402/fetch';
|
|
32
|
+
*
|
|
33
|
+
* const privyClient = new PrivyClient({ appId, appSecret });
|
|
34
|
+
*
|
|
35
|
+
* // Get wallet details
|
|
36
|
+
* const wallet = await privyClient.wallets().get('walletId');
|
|
37
|
+
*
|
|
38
|
+
* // Create x402 client
|
|
39
|
+
* const x402client = createX402Client(privyClient, {
|
|
40
|
+
* walletId: wallet.id,
|
|
41
|
+
* address: wallet.address,
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* // Use with fetch
|
|
45
|
+
* const fetchWithPayment = wrapFetchWithPayment(fetch, x402client);
|
|
46
|
+
* const response = await fetchWithPayment('https://api.example.com/premium');
|
|
47
|
+
*
|
|
48
|
+
* // Or use with axios
|
|
49
|
+
* // import { wrapAxiosWithPayment } from '@x402/axios';
|
|
50
|
+
* // const axiosWithPayment = wrapAxiosWithPayment(axios, x402client);
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function createX402Client(client: PrivyClient, { walletId, address, authorizationContext }: CreateX402ClientInput): x402Client;
|
|
54
|
+
//# sourceMappingURL=x402.d.ts.map
|
package/x402.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x402.d.ts","sourceRoot":"","sources":["src/x402.ts"],"names":[],"mappings":"OAEO,EAAE,UAAU,EAAE,MAAM,aAAa;OAMjC,KAAK,EAAE,oBAAoB,EAAE;OAC7B,KAAK,EAAE,WAAW,EAAE;AAE3B,MAAM,WAAW,qBAAqB;IACpC,yBAAyB;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;CAC7C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,WAAW,EACnB,EAAE,QAAQ,EAAE,OAAO,EAAE,oBAAoB,EAAE,EAAE,qBAAqB,GACjE,UAAU,CAsBZ"}
|
package/x402.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createX402Client = createX402Client;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const kit_1 = require("@solana/kit");
|
|
6
|
+
const fetch_1 = require("@x402/fetch");
|
|
7
|
+
const client_1 = require("@x402/evm/exact/client");
|
|
8
|
+
const client_2 = require("@x402/svm/exact/client");
|
|
9
|
+
const viem_2 = require("./viem.js");
|
|
10
|
+
const solana_kit_1 = require("./solana-kit.js");
|
|
11
|
+
/**
|
|
12
|
+
* Creates an x402 client configured with a Privy wallet for automatic payment handling.
|
|
13
|
+
*
|
|
14
|
+
* The returned client can be used with x402's `wrapFetchWithPayment` or `wrapAxiosWithPayment`
|
|
15
|
+
* to automatically handle HTTP 402 Payment Required responses.
|
|
16
|
+
*
|
|
17
|
+
* @experimental This API is experimental and may change in future versions.
|
|
18
|
+
*
|
|
19
|
+
* @param client - The Privy client instance
|
|
20
|
+
* @param input - Configuration for the x402 client
|
|
21
|
+
* @param input.walletId - ID of the Privy wallet to use for payments
|
|
22
|
+
* @param input.address - Address of the wallet
|
|
23
|
+
* @param input.authorizationContext - Authorization context for the wallet
|
|
24
|
+
* @returns A configured x402Client instance
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { PrivyClient } from '@privy-io/node';
|
|
29
|
+
* import { createX402Client } from '@privy-io/node/x402';
|
|
30
|
+
* import { wrapFetchWithPayment } from '@x402/fetch';
|
|
31
|
+
*
|
|
32
|
+
* const privyClient = new PrivyClient({ appId, appSecret });
|
|
33
|
+
*
|
|
34
|
+
* // Get wallet details
|
|
35
|
+
* const wallet = await privyClient.wallets().get('walletId');
|
|
36
|
+
*
|
|
37
|
+
* // Create x402 client
|
|
38
|
+
* const x402client = createX402Client(privyClient, {
|
|
39
|
+
* walletId: wallet.id,
|
|
40
|
+
* address: wallet.address,
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* // Use with fetch
|
|
44
|
+
* const fetchWithPayment = wrapFetchWithPayment(fetch, x402client);
|
|
45
|
+
* const response = await fetchWithPayment('https://api.example.com/premium');
|
|
46
|
+
*
|
|
47
|
+
* // Or use with axios
|
|
48
|
+
* // import { wrapAxiosWithPayment } from '@x402/axios';
|
|
49
|
+
* // const axiosWithPayment = wrapAxiosWithPayment(axios, x402client);
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
function createX402Client(client, { walletId, address, authorizationContext }) {
|
|
53
|
+
const x402client = new fetch_1.x402Client();
|
|
54
|
+
if ((0, viem_1.isAddress)(address)) {
|
|
55
|
+
const evmSigner = (0, viem_2.createViemAccount)(client, {
|
|
56
|
+
walletId,
|
|
57
|
+
address: address,
|
|
58
|
+
...(authorizationContext ? { authorizationContext } : {}),
|
|
59
|
+
});
|
|
60
|
+
(0, client_1.registerExactEvmScheme)(x402client, { signer: evmSigner });
|
|
61
|
+
}
|
|
62
|
+
else if ((0, kit_1.isAddress)(address)) {
|
|
63
|
+
const solanaSigner = (0, solana_kit_1.createSolanaKitSigner)(client, {
|
|
64
|
+
walletId,
|
|
65
|
+
address: address,
|
|
66
|
+
...(authorizationContext ? { authorizationContext } : {}),
|
|
67
|
+
});
|
|
68
|
+
(0, client_2.registerExactSvmScheme)(x402client, { signer: solanaSigner });
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
throw new Error(`Invalid wallet address: ${address}. Address must be a valid EVM or Solana address.`);
|
|
72
|
+
}
|
|
73
|
+
return x402client;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=x402.js.map
|
package/x402.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x402.js","sourceRoot":"","sources":["src/x402.ts"],"names":[],"mappings":";;AA6DA,4CAyBC;AAtFD,+BAA2D;AAC3D,qCAAyE;AACzE,uCAAyC;AACzC,mDAAgE;AAChE,mDAAgE;AAEhE,oCAA2C;AAC3C,gDAAqD;AAarD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,SAAgB,gBAAgB,CAC9B,MAAmB,EACnB,EAAE,QAAQ,EAAE,OAAO,EAAE,oBAAoB,EAAyB;IAElE,MAAM,UAAU,GAAG,IAAI,kBAAU,EAAE,CAAC;IAEpC,IAAI,IAAA,gBAAY,EAAC,OAAO,CAAC,EAAE,CAAC;QAC1B,MAAM,SAAS,GAAG,IAAA,wBAAiB,EAAC,MAAM,EAAE;YAC1C,QAAQ;YACR,OAAO,EAAE,OAAc;YACvB,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,oBAAoB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC1D,CAAC,CAAC;QACH,IAAA,+BAAsB,EAAC,UAAU,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;IAC5D,CAAC;SAAM,IAAI,IAAA,eAAe,EAAC,OAAO,CAAC,EAAE,CAAC;QACpC,MAAM,YAAY,GAAG,IAAA,kCAAqB,EAAC,MAAM,EAAE;YACjD,QAAQ;YACR,OAAO,EAAE,OAAkB;YAC3B,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,oBAAoB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC1D,CAAC,CAAC;QACH,IAAA,+BAAsB,EAAC,UAAU,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;IAC/D,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,2BAA2B,OAAO,kDAAkD,CAAC,CAAC;IACxG,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC"}
|