@@ -16,23 +16,31 @@ import {
1616 SupportedPaymentKind ,
1717 isSvmSignerWallet ,
1818 type X402Config ,
19+ SupportedStellarNetworks ,
20+ StellarConnectedClient ,
1921} from "x402/types" ;
2022
2123config ( ) ;
2224
2325const EVM_PRIVATE_KEY = process . env . EVM_PRIVATE_KEY || "" ;
2426const SVM_PRIVATE_KEY = process . env . SVM_PRIVATE_KEY || "" ;
2527const SVM_RPC_URL = process . env . SVM_RPC_URL || "" ;
28+ const STELLAR_PRIVATE_KEY = process . env . STELLAR_PRIVATE_KEY || "" ;
29+ const STELLAR_RPC_URL = process . env . STELLAR_RPC_URL || "" ;
2630
27- if ( ! EVM_PRIVATE_KEY && ! SVM_PRIVATE_KEY ) {
31+ if ( ! EVM_PRIVATE_KEY && ! SVM_PRIVATE_KEY && ! STELLAR_PRIVATE_KEY ) {
2832 console . error ( "Missing required environment variables" ) ;
2933 process . exit ( 1 ) ;
3034}
3135
3236// Create X402 config with custom RPC URL if provided
33- const x402Config : X402Config | undefined = SVM_RPC_URL
34- ? { svmConfig : { rpcUrl : SVM_RPC_URL } }
35- : undefined ;
37+ const x402Config : X402Config | undefined =
38+ SVM_RPC_URL || STELLAR_RPC_URL
39+ ? {
40+ svmConfig : { rpcUrl : SVM_RPC_URL } ,
41+ stellarConfig : { rpcUrl : STELLAR_RPC_URL } ,
42+ }
43+ : undefined ;
3644
3745const app = express ( ) ;
3846
@@ -73,6 +81,8 @@ app.post("/verify", async (req: Request, res: Response) => {
7381 client = createConnectedClient ( paymentRequirements . network ) ;
7482 } else if ( SupportedSVMNetworks . includes ( paymentRequirements . network ) ) {
7583 client = await createSigner ( paymentRequirements . network , SVM_PRIVATE_KEY ) ;
84+ } else if ( SupportedStellarNetworks . includes ( paymentRequirements . network ) ) {
85+ client = await createSigner ( paymentRequirements . network , STELLAR_PRIVATE_KEY ) ;
7686 } else {
7787 throw new Error ( "Invalid network" ) ;
7888 }
@@ -123,6 +133,22 @@ app.get("/supported", async (req: Request, res: Response) => {
123133 } ,
124134 } ) ;
125135 }
136+
137+ // stellar
138+ if ( STELLAR_PRIVATE_KEY ) {
139+ const client = createConnectedClient ( "stellar-testnet" , x402Config ) as StellarConnectedClient ;
140+ const latestLedgerNumber = ( await client . getLatestLedger ( ) ) . sequence ;
141+
142+ kinds . push ( {
143+ x402Version : 1 ,
144+ scheme : "exact" ,
145+ network : "stellar-testnet" ,
146+ extra : {
147+ maxLedger : latestLedgerNumber + 12 ,
148+ } ,
149+ } ) ;
150+ }
151+
126152 res . json ( {
127153 kinds,
128154 } ) ;
@@ -140,6 +166,8 @@ app.post("/settle", async (req: Request, res: Response) => {
140166 signer = await createSigner ( paymentRequirements . network , EVM_PRIVATE_KEY ) ;
141167 } else if ( SupportedSVMNetworks . includes ( paymentRequirements . network ) ) {
142168 signer = await createSigner ( paymentRequirements . network , SVM_PRIVATE_KEY ) ;
169+ } else if ( SupportedStellarNetworks . includes ( paymentRequirements . network ) ) {
170+ signer = await createSigner ( paymentRequirements . network , STELLAR_PRIVATE_KEY ) ;
143171 } else {
144172 throw new Error ( "Invalid network" ) ;
145173 }
0 commit comments