@@ -6,6 +6,52 @@ export type x402Erc7710ServerConfig = {
66 allowAssetTransferMethodOverride ?: boolean ;
77} ;
88
9+ function validateFacilitatorAddresses (
10+ publishedAddresses : unknown ,
11+ ) : string [ ] | undefined {
12+ if ( publishedAddresses === undefined ) {
13+ return undefined ;
14+ }
15+
16+ if ( ! Array . isArray ( publishedAddresses ) ) {
17+ throw new Error (
18+ 'Invalid facilitatorAddresses specified: expected an array of addresses' ,
19+ ) ;
20+ }
21+
22+ if ( publishedAddresses . length === 0 ) {
23+ throw new Error (
24+ 'Invalid facilitatorAddresses specified: expected at least one address' ,
25+ ) ;
26+ }
27+
28+ const normalizedAddresses : string [ ] = [ ] ;
29+ const validationErrors : string [ ] = [ ] ;
30+
31+ publishedAddresses . forEach ( ( address , index ) => {
32+ if ( typeof address !== 'string' ) {
33+ validationErrors . push ( `facilitatorAddresses[${ index } ] must be a string` ) ;
34+ return ;
35+ }
36+
37+ try {
38+ normalizedAddresses . push ( getAddress ( address ) ) ;
39+ } catch {
40+ validationErrors . push (
41+ `facilitatorAddresses[${ index } ] is not a valid address: "${ address } "` ,
42+ ) ;
43+ }
44+ } ) ;
45+
46+ if ( validationErrors . length > 0 ) {
47+ throw new Error (
48+ `Invalid facilitatorAddresses specified: ${ validationErrors . join ( '; ' ) } ` ,
49+ ) ;
50+ }
51+
52+ return normalizedAddresses ;
53+ }
54+
955/**
1056 * x402 `SchemeNetworkServer`-compatible implementation for publishing
1157 * `assetTransferMethod: "erc7710"` in payment requirements.
@@ -41,24 +87,15 @@ export class x402Erc7710Server {
4187 ) ;
4288 }
4389
44- const facilitatorAddress = ( ( ) => {
45- const publishedAddress = supportedKind . extra ?. facilitatorAddress ;
46- if ( typeof publishedAddress !== 'string' ) {
47- return undefined ;
48- }
49-
50- try {
51- return getAddress ( publishedAddress ) ;
52- } catch {
53- return undefined ;
54- }
55- } ) ( ) ;
90+ const facilitatorAddresses = validateFacilitatorAddresses (
91+ supportedKind . extra ?. facilitatorAddresses ,
92+ ) ;
5693
5794 return {
5895 ...paymentRequirements ,
5996 extra : {
6097 ...( paymentRequirements . extra ?? { } ) ,
61- ...( facilitatorAddress ? { facilitatorAddress } : { } ) ,
98+ ...( facilitatorAddresses ? { facilitatorAddresses } : { } ) ,
6299 assetTransferMethod : 'erc7710' ,
63100 } ,
64101 } ;
0 commit comments