uvd-x402-sdk 2.12.0 → 2.13.1
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/index.d.mts +54 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.js +59 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -1
- package/dist/index.mjs.map +1 -1
- package/dist/providers/algorand/index.js +48 -3
- package/dist/providers/algorand/index.js.map +1 -1
- package/dist/providers/algorand/index.mjs +48 -3
- package/dist/providers/algorand/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/facilitator.ts +106 -0
- package/src/index.ts +4 -0
- package/src/providers/algorand/index.ts +10 -5
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Facilitator Configuration
|
|
3
|
+
*
|
|
4
|
+
* This module contains the known facilitator addresses for each chain.
|
|
5
|
+
* The SDK uses these automatically so users don't need to configure them.
|
|
6
|
+
*
|
|
7
|
+
* The facilitator (https://facilitator.ultravioletadao.xyz) has wallets
|
|
8
|
+
* on each supported blockchain for:
|
|
9
|
+
* - EVM: Signing EIP-3009 transferWithAuthorization transactions
|
|
10
|
+
* - Solana: Paying transaction fees (fee payer)
|
|
11
|
+
* - Algorand: Signing fee transactions in atomic groups
|
|
12
|
+
* - Stellar: Signing authorization entries
|
|
13
|
+
* - NEAR: Acting as relayer for meta-transactions
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Default facilitator URL
|
|
18
|
+
*/
|
|
19
|
+
export const DEFAULT_FACILITATOR_URL = 'https://facilitator.ultravioletadao.xyz';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Facilitator wallet addresses by chain type
|
|
23
|
+
*
|
|
24
|
+
* These are the public addresses of the facilitator's wallets.
|
|
25
|
+
* The facilitator uses these to pay fees and sign transactions.
|
|
26
|
+
*/
|
|
27
|
+
export const FACILITATOR_ADDRESSES = {
|
|
28
|
+
/**
|
|
29
|
+
* Solana facilitator address (fee payer)
|
|
30
|
+
* Used for: Paying transaction fees on Solana
|
|
31
|
+
*/
|
|
32
|
+
solana: 'F742C4VfFLQ9zRQyithoj5229ZgtX2WqKCSFKgH2EThq',
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Algorand facilitator address (fee payer)
|
|
36
|
+
* Used for: Signing Transaction 0 (fee tx) in atomic groups
|
|
37
|
+
* Note: This is derived from the facilitator's Algorand mnemonic
|
|
38
|
+
*/
|
|
39
|
+
algorand: 'SXHRBXS22SKKXHXK44DTQMWN2SXK3SFJWBDAQZGF4DRPW7PNFAUM2GYFAQ',
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Algorand testnet facilitator address
|
|
43
|
+
*/
|
|
44
|
+
'algorand-testnet': 'SXHRBXS22SKKXHXK44DTQMWN2SXK3SFJWBDAQZGF4DRPW7PNFAUM2GYFAQ',
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* EVM facilitator address
|
|
48
|
+
* Used for: Submitting EIP-3009 transferWithAuthorization transactions
|
|
49
|
+
* Note: Same address across all EVM chains
|
|
50
|
+
*/
|
|
51
|
+
evm: '0x7c5F3AdB0C7775968Bc7e7cF61b27fECf2e2b500',
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Stellar facilitator address
|
|
55
|
+
* Used for: Signing soroban authorization entries
|
|
56
|
+
*/
|
|
57
|
+
stellar: 'GDUTDNV53WQPOB2JUZPO6SXH4LVT7CJSLCMLFQ7W4CNAXGIX7XYMCNP2',
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* NEAR facilitator address
|
|
61
|
+
* Used for: Relaying meta-transactions
|
|
62
|
+
*/
|
|
63
|
+
near: 'uvd-facilitator.near',
|
|
64
|
+
} as const;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Get the facilitator address for a specific chain
|
|
68
|
+
*
|
|
69
|
+
* @param chainName - The chain name (e.g., 'algorand', 'solana', 'base')
|
|
70
|
+
* @param networkType - The network type (e.g., 'evm', 'svm', 'algorand')
|
|
71
|
+
* @returns The facilitator address for that chain, or undefined if not supported
|
|
72
|
+
*/
|
|
73
|
+
export function getFacilitatorAddress(
|
|
74
|
+
chainName: string,
|
|
75
|
+
networkType?: string
|
|
76
|
+
): string | undefined {
|
|
77
|
+
// Check for exact chain match first
|
|
78
|
+
const exactMatch = FACILITATOR_ADDRESSES[chainName as keyof typeof FACILITATOR_ADDRESSES];
|
|
79
|
+
if (exactMatch) {
|
|
80
|
+
return exactMatch;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Fall back to network type
|
|
84
|
+
if (networkType === 'evm') {
|
|
85
|
+
return FACILITATOR_ADDRESSES.evm;
|
|
86
|
+
}
|
|
87
|
+
if (networkType === 'svm' || networkType === 'solana') {
|
|
88
|
+
return FACILITATOR_ADDRESSES.solana;
|
|
89
|
+
}
|
|
90
|
+
if (networkType === 'algorand') {
|
|
91
|
+
return FACILITATOR_ADDRESSES.algorand;
|
|
92
|
+
}
|
|
93
|
+
if (networkType === 'stellar') {
|
|
94
|
+
return FACILITATOR_ADDRESSES.stellar;
|
|
95
|
+
}
|
|
96
|
+
if (networkType === 'near') {
|
|
97
|
+
return FACILITATOR_ADDRESSES.near;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Type for facilitator addresses
|
|
105
|
+
*/
|
|
106
|
+
export type FacilitatorAddresses = typeof FACILITATOR_ADDRESSES;
|
package/src/index.ts
CHANGED
|
@@ -201,3 +201,7 @@ export type {
|
|
|
201
201
|
} from './types';
|
|
202
202
|
|
|
203
203
|
export { X402Error, DEFAULT_CONFIG, CAIP2_IDENTIFIERS, CAIP2_TO_CHAIN } from './types';
|
|
204
|
+
|
|
205
|
+
// Facilitator configuration
|
|
206
|
+
export { FACILITATOR_ADDRESSES, getFacilitatorAddress } from './facilitator';
|
|
207
|
+
export type { FacilitatorAddresses } from './facilitator';
|
|
@@ -40,6 +40,7 @@ import type {
|
|
|
40
40
|
import { X402Error } from '../../types';
|
|
41
41
|
import { getChainByName } from '../../chains';
|
|
42
42
|
import { chainToCAIP2 } from '../../utils';
|
|
43
|
+
import { getFacilitatorAddress } from '../../facilitator';
|
|
43
44
|
|
|
44
45
|
/**
|
|
45
46
|
* Browser-compatible base64 encoding for Uint8Array
|
|
@@ -343,11 +344,15 @@ export class AlgorandProvider implements WalletAdapter {
|
|
|
343
344
|
const recipient = paymentInfo.recipients?.algorand || paymentInfo.recipient;
|
|
344
345
|
const assetId = parseInt(chainConfig.usdc.address, 10);
|
|
345
346
|
|
|
346
|
-
// Get facilitator address (fee payer)
|
|
347
|
-
|
|
347
|
+
// Get facilitator address (fee payer) - automatically from SDK config
|
|
348
|
+
// Priority: paymentInfo.facilitator > SDK default for chain
|
|
349
|
+
const chainName = chainConfig?.name || 'algorand';
|
|
350
|
+
const facilitatorAddress =
|
|
351
|
+
paymentInfo.facilitator || getFacilitatorAddress(chainName, 'algorand');
|
|
352
|
+
|
|
348
353
|
if (!facilitatorAddress) {
|
|
349
354
|
throw new X402Error(
|
|
350
|
-
'Facilitator address
|
|
355
|
+
'Facilitator address not configured for Algorand',
|
|
351
356
|
'PAYMENT_FAILED'
|
|
352
357
|
);
|
|
353
358
|
}
|
|
@@ -507,12 +512,12 @@ export class AlgorandProvider implements WalletAdapter {
|
|
|
507
512
|
const payload = JSON.parse(paymentPayload) as AlgorandPaymentPayload;
|
|
508
513
|
|
|
509
514
|
// Determine network name for x402
|
|
510
|
-
// Use "algorand
|
|
515
|
+
// Use "algorand" or "algorand-testnet" format for facilitator
|
|
511
516
|
let networkName: string;
|
|
512
517
|
if (chainConfig?.name === 'algorand-testnet') {
|
|
513
518
|
networkName = 'algorand-testnet';
|
|
514
519
|
} else {
|
|
515
|
-
networkName = 'algorand
|
|
520
|
+
networkName = 'algorand'; // Default to mainnet
|
|
516
521
|
}
|
|
517
522
|
|
|
518
523
|
// Build the payload data (GoPlausible x402-avm spec)
|