forked from x402-foundation/x402
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfacilitator.go
More file actions
697 lines (593 loc) · 21 KB
/
Copy pathfacilitator.go
File metadata and controls
697 lines (593 loc) · 21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
package x402
import (
"context"
"fmt"
"strings"
"sync"
"github.com/x402-foundation/x402/go/v2/types"
)
// schemeData stores facilitator and its registered networks
type schemeData struct {
facilitator interface{} // Either SchemeNetworkFacilitator or SchemeNetworkFacilitatorV1
networks map[Network]bool
pattern Network
}
// x402Facilitator manages payment verification and settlement
// Supports both V1 and V2 for legacy interoperability
type x402Facilitator struct {
mu sync.RWMutex
// Separate arrays for V1 and V2 (V2 uses default name, no suffix)
// Arrays support multiple facilitators with same scheme name
schemesV1 []*schemeData
schemes []*schemeData // V2 (default)
extensions map[string]FacilitatorExtension
// Lifecycle hooks
beforeVerifyHooks []FacilitatorBeforeVerifyHook
afterVerifyHooks []FacilitatorAfterVerifyHook
onVerifyFailureHooks []FacilitatorOnVerifyFailureHook
beforeSettleHooks []FacilitatorBeforeSettleHook
afterSettleHooks []FacilitatorAfterSettleHook
onSettleFailureHooks []FacilitatorOnSettleFailureHook
}
func Newx402Facilitator() *x402Facilitator {
return &x402Facilitator{
schemesV1: []*schemeData{},
schemes: []*schemeData{},
extensions: make(map[string]FacilitatorExtension),
}
}
// RegisterV1 registers a V1 facilitator mechanism for multiple networks (legacy)
// Networks are stored and used for GetSupported() - no need to specify them later.
func (f *x402Facilitator) RegisterV1(networks []Network, facilitator SchemeNetworkFacilitatorV1) *x402Facilitator {
f.mu.Lock()
defer f.mu.Unlock()
// Create network set
networkSet := make(map[Network]bool)
for _, network := range networks {
networkSet[network] = true
}
// Append to array (supports multiple facilitators with same scheme name)
f.schemesV1 = append(f.schemesV1, &schemeData{
facilitator: facilitator,
networks: networkSet,
pattern: derivePattern(networks),
})
return f
}
// Register registers a facilitator mechanism for multiple networks (V2, default)
// Networks are stored and used for GetSupported() - no need to specify them later.
func (f *x402Facilitator) Register(networks []Network, facilitator SchemeNetworkFacilitator) *x402Facilitator {
f.mu.Lock()
defer f.mu.Unlock()
// Create network set
networkSet := make(map[Network]bool)
for _, network := range networks {
networkSet[network] = true
}
// Append to array (supports multiple facilitators with same scheme name)
f.schemes = append(f.schemes, &schemeData{
facilitator: facilitator,
networks: networkSet,
pattern: derivePattern(networks),
})
return f
}
// RegisterExtension registers a protocol extension.
func (f *x402Facilitator) RegisterExtension(extension FacilitatorExtension) *x402Facilitator {
f.mu.Lock()
defer f.mu.Unlock()
f.extensions[extension.Key()] = extension
return f
}
// GetExtension returns the extension registered under the given key, or nil.
func (f *x402Facilitator) GetExtension(key string) FacilitatorExtension {
f.mu.RLock()
defer f.mu.RUnlock()
return f.extensions[key]
}
// ============================================================================
// Hook Registration Methods
// ============================================================================
func (f *x402Facilitator) OnBeforeVerify(hook FacilitatorBeforeVerifyHook) *x402Facilitator {
f.mu.Lock()
defer f.mu.Unlock()
f.beforeVerifyHooks = append(f.beforeVerifyHooks, hook)
return f
}
func (f *x402Facilitator) OnAfterVerify(hook FacilitatorAfterVerifyHook) *x402Facilitator {
f.mu.Lock()
defer f.mu.Unlock()
f.afterVerifyHooks = append(f.afterVerifyHooks, hook)
return f
}
func (f *x402Facilitator) OnVerifyFailure(hook FacilitatorOnVerifyFailureHook) *x402Facilitator {
f.mu.Lock()
defer f.mu.Unlock()
f.onVerifyFailureHooks = append(f.onVerifyFailureHooks, hook)
return f
}
func (f *x402Facilitator) OnBeforeSettle(hook FacilitatorBeforeSettleHook) *x402Facilitator {
f.mu.Lock()
defer f.mu.Unlock()
f.beforeSettleHooks = append(f.beforeSettleHooks, hook)
return f
}
func (f *x402Facilitator) OnAfterSettle(hook FacilitatorAfterSettleHook) *x402Facilitator {
f.mu.Lock()
defer f.mu.Unlock()
f.afterSettleHooks = append(f.afterSettleHooks, hook)
return f
}
func (f *x402Facilitator) OnSettleFailure(hook FacilitatorOnSettleFailureHook) *x402Facilitator {
f.mu.Lock()
defer f.mu.Unlock()
f.onSettleFailureHooks = append(f.onSettleFailureHooks, hook)
return f
}
// ============================================================================
// Core Payment Methods (Network Boundary - uses bytes, routes internally)
// ============================================================================
// Verify verifies a payment (detects version from bytes, routes to typed mechanism)
func (f *x402Facilitator) Verify(ctx context.Context, payloadBytes []byte, requirementsBytes []byte) (*VerifyResponse, error) {
// Detect version
version, err := types.DetectVersion(payloadBytes)
if err != nil {
return nil, NewVerifyError(ErrInvalidVersion, "", fmt.Sprintf("failed to detect version: %s", err.Error()))
}
// Unmarshal to typed structs for hooks
var hookPayload PaymentPayloadView
var hookRequirements PaymentRequirementsView
// Route to version-specific method
switch version {
case 1:
payload, err := types.ToPaymentPayloadV1(payloadBytes)
if err != nil {
return nil, NewVerifyError(ErrInvalidV1Payload, "", err.Error())
}
requirements, err := types.ToPaymentRequirementsV1(requirementsBytes)
if err != nil {
return nil, NewVerifyError(ErrInvalidV1Requirements, "", err.Error())
}
hookPayload = *payload
hookRequirements = *requirements
// Execute beforeVerify hooks
hookCtx := FacilitatorVerifyContext{
Ctx: ctx,
Payload: hookPayload,
Requirements: hookRequirements,
PayloadBytes: payloadBytes,
RequirementsBytes: requirementsBytes,
}
for _, hook := range f.beforeVerifyHooks {
result, err := hook(hookCtx)
if err != nil {
return nil, err
}
if result != nil && result.Abort {
return nil, NewVerifyError(result.Reason, "", result.Message)
}
}
// Call mechanism
verifyResult, verifyErr := f.verifyV1(ctx, *payload, *requirements)
// Handle failure
if verifyErr != nil {
failureCtx := FacilitatorVerifyFailureContext{FacilitatorVerifyContext: hookCtx, Error: verifyErr}
for _, hook := range f.onVerifyFailureHooks {
result, _ := hook(failureCtx)
if result != nil && result.Recovered {
return result.Result, nil
}
}
return nil, verifyErr
}
// Execute afterVerify hooks
resultCtx := FacilitatorVerifyResultContext{FacilitatorVerifyContext: hookCtx, Result: verifyResult}
for _, hook := range f.afterVerifyHooks {
_ = hook(resultCtx) // Log errors but don't fail
}
return verifyResult, nil
case 2:
payload, err := types.ToPaymentPayload(payloadBytes)
if err != nil {
return nil, NewVerifyError(ErrInvalidV2Payload, "", err.Error())
}
requirements, err := types.ToPaymentRequirements(requirementsBytes)
if err != nil {
return nil, NewVerifyError(ErrInvalidV2Requirements, "", err.Error())
}
hookPayload = *payload
hookRequirements = *requirements
// Execute beforeVerify hooks
hookCtx := FacilitatorVerifyContext{
Ctx: ctx,
Payload: hookPayload,
Requirements: hookRequirements,
PayloadBytes: payloadBytes,
RequirementsBytes: requirementsBytes,
}
for _, hook := range f.beforeVerifyHooks {
result, err := hook(hookCtx)
if err != nil {
return nil, err
}
if result != nil && result.Abort {
return nil, NewVerifyError(result.Reason, "", "")
}
}
// Call mechanism
verifyResult, verifyErr := f.verifyV2(ctx, *payload, *requirements)
// Handle failure
if verifyErr != nil {
failureCtx := FacilitatorVerifyFailureContext{FacilitatorVerifyContext: hookCtx, Error: verifyErr}
for _, hook := range f.onVerifyFailureHooks {
result, _ := hook(failureCtx)
if result != nil && result.Recovered {
return result.Result, nil
}
}
return nil, verifyErr
}
// Execute afterVerify hooks
resultCtx := FacilitatorVerifyResultContext{FacilitatorVerifyContext: hookCtx, Result: verifyResult}
for _, hook := range f.afterVerifyHooks {
_ = hook(resultCtx) // Log errors but don't fail
}
return verifyResult, nil
default:
return nil, NewVerifyError(ErrInvalidVersion, "", fmt.Sprintf("unsupported version: %d", version))
}
}
// Settle settles a payment (detects version from bytes, routes to typed mechanism)
func (f *x402Facilitator) Settle(ctx context.Context, payloadBytes []byte, requirementsBytes []byte) (*SettleResponse, error) {
// Detect version
version, err := types.DetectVersion(payloadBytes)
if err != nil {
return nil, NewSettleError(ErrInvalidVersion, "", "", "", err.Error())
}
// Unmarshal to typed structs for hooks
var hookPayload PaymentPayloadView
var hookRequirements PaymentRequirementsView
// Route to version-specific method
switch version {
case 1:
payload, err := types.ToPaymentPayloadV1(payloadBytes)
if err != nil {
return nil, NewSettleError(ErrInvalidV1Payload, "", "", "", err.Error())
}
requirements, err := types.ToPaymentRequirementsV1(requirementsBytes)
if err != nil {
return nil, NewSettleError(ErrInvalidV1Requirements, "", "", "", err.Error())
}
hookPayload = *payload
hookRequirements = *requirements
// Execute beforeSettle hooks
hookCtx := FacilitatorSettleContext{
Ctx: ctx,
Payload: hookPayload,
Requirements: hookRequirements,
PayloadBytes: payloadBytes,
RequirementsBytes: requirementsBytes,
}
for _, hook := range f.beforeSettleHooks {
result, err := hook(hookCtx)
if err != nil {
return nil, err
}
if result != nil && result.Abort {
return nil, NewSettleError(result.Reason, "", "", "", result.Message)
}
}
// Call mechanism
settleResult, settleErr := f.settleV1(ctx, *payload, *requirements)
// Handle failure
if settleErr != nil {
failureCtx := FacilitatorSettleFailureContext{FacilitatorSettleContext: hookCtx, Error: settleErr}
for _, hook := range f.onSettleFailureHooks {
result, _ := hook(failureCtx)
if result != nil && result.Recovered {
return result.Result, nil
}
}
return nil, settleErr
}
// Execute afterSettle hooks
resultCtx := FacilitatorSettleResultContext{FacilitatorSettleContext: hookCtx, Result: settleResult}
for _, hook := range f.afterSettleHooks {
_ = hook(resultCtx) // Log errors but don't fail
}
return settleResult, nil
case 2:
payload, err := types.ToPaymentPayload(payloadBytes)
if err != nil {
return nil, NewSettleError(ErrInvalidV2Payload, "", "", "", err.Error())
}
requirements, err := types.ToPaymentRequirements(requirementsBytes)
if err != nil {
return nil, NewSettleError(ErrInvalidV2Requirements, "", "", "", err.Error())
}
hookPayload = *payload
hookRequirements = *requirements
// Execute beforeSettle hooks
hookCtx := FacilitatorSettleContext{
Ctx: ctx,
Payload: hookPayload,
Requirements: hookRequirements,
PayloadBytes: payloadBytes,
RequirementsBytes: requirementsBytes,
}
for _, hook := range f.beforeSettleHooks {
result, err := hook(hookCtx)
if err != nil {
return nil, err
}
if result != nil && result.Abort {
return nil, NewSettleError(result.Reason, "", "", "", "")
}
}
// Call mechanism
settleResult, settleErr := f.settleV2(ctx, *payload, *requirements)
// Handle failure
if settleErr != nil {
failureCtx := FacilitatorSettleFailureContext{FacilitatorSettleContext: hookCtx, Error: settleErr}
for _, hook := range f.onSettleFailureHooks {
result, _ := hook(failureCtx)
if result != nil && result.Recovered {
return result.Result, nil
}
}
return nil, settleErr
}
// Execute afterSettle hooks
resultCtx := FacilitatorSettleResultContext{FacilitatorSettleContext: hookCtx, Result: settleResult}
for _, hook := range f.afterSettleHooks {
_ = hook(resultCtx) // Log errors but don't fail
}
return settleResult, nil
default:
return nil, NewSettleError(fmt.Sprintf("unsupported_version_%d", version), "", "", "", "")
}
}
// ============================================================================
// Internal Typed Methods (called after version detection)
// ============================================================================
// verifyV1 verifies a V1 payment (internal, typed)
func (f *x402Facilitator) verifyV1(ctx context.Context, payload types.PaymentPayloadV1, requirements types.PaymentRequirementsV1) (*VerifyResponse, error) {
f.mu.RLock()
defer f.mu.RUnlock()
scheme := requirements.Scheme
network := Network(requirements.Network)
fctx := NewFacilitatorContext(f.extensions)
// Find matching facilitator from array
for _, data := range f.schemesV1 {
facilitator := data.facilitator.(SchemeNetworkFacilitatorV1)
if facilitator.Scheme() != scheme {
continue
}
// Check if network matches (exact or pattern)
if matchesSchemeData(data, network) {
return facilitator.Verify(ctx, payload, requirements, fctx)
}
}
registered := f.registeredV1Summary()
return nil, NewVerifyError(ErrNoFacilitatorForNetwork, "", fmt.Sprintf("no facilitator for scheme %q on network %q; registered: %s", scheme, network, registered))
}
// verifyV2 verifies a V2 payment (internal, typed)
func (f *x402Facilitator) verifyV2(ctx context.Context, payload types.PaymentPayload, requirements types.PaymentRequirements) (*VerifyResponse, error) {
f.mu.RLock()
defer f.mu.RUnlock()
scheme := requirements.Scheme
network := Network(requirements.Network)
fctx := NewFacilitatorContext(f.extensions)
// Find matching facilitator from array
for _, data := range f.schemes {
facilitator := data.facilitator.(SchemeNetworkFacilitator)
if facilitator.Scheme() != scheme {
continue
}
// Check if network matches (exact or pattern)
if matchesSchemeData(data, network) {
return facilitator.Verify(ctx, payload, requirements, fctx)
}
}
registered := f.registeredV2Summary()
return nil, NewVerifyError(ErrNoFacilitatorForNetwork, "", fmt.Sprintf("no facilitator for scheme %q on network %q; registered: %s", scheme, network, registered))
}
// settleV1 settles a V1 payment (internal, typed)
func (f *x402Facilitator) settleV1(ctx context.Context, payload types.PaymentPayloadV1, requirements types.PaymentRequirementsV1) (*SettleResponse, error) {
f.mu.RLock()
defer f.mu.RUnlock()
scheme := requirements.Scheme
network := Network(requirements.Network)
fctx := NewFacilitatorContext(f.extensions)
// Find matching facilitator from array
for _, data := range f.schemesV1 {
facilitator := data.facilitator.(SchemeNetworkFacilitatorV1)
if facilitator.Scheme() != scheme {
continue
}
// Check if network matches (exact or pattern)
if matchesSchemeData(data, network) {
return facilitator.Settle(ctx, payload, requirements, fctx)
}
}
registered := f.registeredV1Summary()
return nil, NewSettleError(ErrNoFacilitatorForNetwork, "", network, "", fmt.Sprintf("no facilitator for scheme %q on network %q; registered: %s", scheme, network, registered))
}
// settleV2 settles a V2 payment (internal, typed)
func (f *x402Facilitator) settleV2(ctx context.Context, payload types.PaymentPayload, requirements types.PaymentRequirements) (*SettleResponse, error) {
f.mu.RLock()
defer f.mu.RUnlock()
scheme := requirements.Scheme
network := Network(requirements.Network)
fctx := NewFacilitatorContext(f.extensions)
// Find matching facilitator from array
for _, data := range f.schemes {
facilitator := data.facilitator.(SchemeNetworkFacilitator)
if facilitator.Scheme() != scheme {
continue
}
// Check if network matches (exact or pattern)
if matchesSchemeData(data, network) {
return facilitator.Settle(ctx, payload, requirements, fctx)
}
}
registered := f.registeredV2Summary()
return nil, NewSettleError(ErrNoFacilitatorForNetwork, "", network, "", fmt.Sprintf("no facilitator for scheme %q on network %q; registered: %s", scheme, network, registered))
}
// registeredV1Summary returns a human-readable list of registered V1 scheme/network pairs.
func (f *x402Facilitator) registeredV1Summary() string {
if len(f.schemesV1) == 0 {
return "(none)"
}
var parts []string
for _, data := range f.schemesV1 {
facilitator := data.facilitator.(SchemeNetworkFacilitatorV1)
for network := range data.networks {
parts = append(parts, fmt.Sprintf("%s@%s", facilitator.Scheme(), network))
}
}
return strings.Join(parts, ", ")
}
// registeredV2Summary returns a human-readable list of registered V2 scheme/network pairs.
func (f *x402Facilitator) registeredV2Summary() string {
if len(f.schemes) == 0 {
return "(none)"
}
var parts []string
for _, data := range f.schemes {
facilitator := data.facilitator.(SchemeNetworkFacilitator)
for network := range data.networks {
parts = append(parts, fmt.Sprintf("%s@%s", facilitator.Scheme(), network))
}
}
return strings.Join(parts, ", ")
}
// GetSupported returns supported payment kinds
// Uses networks registered during Register() calls - no parameters needed.
// Returns flat array format for backward compatibility with V1 clients.
//
// Returns:
//
// SupportedResponse with kinds as array (with version in each element), extensions, and signers
func (f *x402Facilitator) GetSupported() SupportedResponse {
f.mu.RLock()
defer f.mu.RUnlock()
kinds := []SupportedKind{}
signersByFamily := make(map[string]map[string]bool) // family → set of signers
// V1 schemes
for _, data := range f.schemesV1 {
facilitator := data.facilitator.(SchemeNetworkFacilitatorV1)
scheme := facilitator.Scheme()
for network := range data.networks {
kind := SupportedKind{
X402Version: 1,
Scheme: scheme,
Network: string(network),
}
if extra := facilitator.GetExtra(network); extra != nil {
kind.Extra = extra
}
kinds = append(kinds, kind)
// Collect signers by CAIP family for this network
family := facilitator.CaipFamily()
if signersByFamily[family] == nil {
signersByFamily[family] = make(map[string]bool)
}
for _, signer := range facilitator.GetSigners(network) {
signersByFamily[family][signer] = true
}
}
}
// V2 schemes
for _, data := range f.schemes {
facilitator := data.facilitator.(SchemeNetworkFacilitator)
scheme := facilitator.Scheme()
for network := range data.networks {
kind := SupportedKind{
X402Version: 2,
Scheme: scheme,
Network: string(network),
}
if extra := facilitator.GetExtra(network); extra != nil {
kind.Extra = extra
}
kinds = append(kinds, kind)
// Collect signers by CAIP family for this network
family := facilitator.CaipFamily()
if signersByFamily[family] == nil {
signersByFamily[family] = make(map[string]bool)
}
for _, signer := range facilitator.GetSigners(network) {
signersByFamily[family][signer] = true
}
}
}
// Convert signer sets to arrays
signers := make(map[string][]string)
for family, signerSet := range signersByFamily {
signerList := make([]string, 0, len(signerSet))
for signer := range signerSet {
signerList = append(signerList, signer)
}
signers[family] = signerList
}
extensionKeys := make([]string, 0, len(f.extensions))
for key := range f.extensions {
extensionKeys = append(extensionKeys, key)
}
return SupportedResponse{
Kinds: kinds,
Extensions: extensionKeys,
Signers: signers,
}
}
// derivePattern creates a wildcard pattern from an array of networks
// If all networks share the same namespace, returns wildcard pattern
// Otherwise returns the first network for exact matching
func derivePattern(networks []Network) Network {
if len(networks) == 0 {
return ""
}
if len(networks) == 1 {
return networks[0]
}
// Extract namespaces (e.g., "eip155" from "eip155:84532")
namespaces := make(map[string]bool)
for _, network := range networks {
parts := strings.Split(string(network), ":")
if len(parts) == 2 {
namespaces[parts[0]] = true
}
}
// If all same namespace, use wildcard
if len(namespaces) == 1 {
for namespace := range namespaces {
return Network(namespace + ":*")
}
}
// Mixed namespaces - use first network for exact matching
return networks[0]
}
// matchesSchemeData checks if a network matches the scheme data
// Returns true if network is in registered networks or matches the pattern
func matchesSchemeData(data *schemeData, network Network) bool {
// Check exact match first
if data.networks[network] {
return true
}
// Try pattern matching
return matchesNetworkPattern(string(network), string(data.pattern))
}
// matchesNetworkPattern checks if a concrete network matches a registered pattern
// Supports wildcards like "eip155:*" or exact matches
func matchesNetworkPattern(concreteNetwork, pattern string) bool {
if pattern == concreteNetwork {
return true // Exact match
}
// Handle wildcard patterns (e.g., "eip155:*", "solana:*")
if len(pattern) > 0 && pattern[len(pattern)-1] == '*' {
prefix := pattern[:len(pattern)-1]
return len(concreteNetwork) >= len(prefix) && concreteNetwork[:len(prefix)] == prefix
}
return false
}