@@ -12,18 +12,20 @@ import { zHex } from './schemas.ts'
1212 *
1313 * @see https://github.com/FilOzone/filecoin-services/blob/a86e4a5018133f17a25b4bb6b5b99da4d34fe664/service_contracts/src/ServiceProviderRegistry.sol#L14
1414 */
15- export const PDPOfferingSchema = z . object ( {
16- serviceURL : zHex ,
17- minPieceSizeInBytes : zHex ,
18- maxPieceSizeInBytes : zHex ,
19- storagePricePerTibPerDay : zHex ,
20- minProvingPeriodInEpochs : zHex ,
21- location : zHex ,
22- paymentTokenAddress : zHex ,
23- ipniPiece : zHex . optional ( ) ,
24- ipniIpfs : zHex . optional ( ) ,
25- ipniPeerId : zHex . optional ( ) ,
26- } )
15+ export const PDPOfferingSchema = z
16+ . object ( {
17+ serviceURL : zHex ,
18+ minPieceSizeInBytes : zHex ,
19+ maxPieceSizeInBytes : zHex ,
20+ storagePricePerTibPerDay : zHex ,
21+ minProvingPeriodInEpochs : zHex ,
22+ location : zHex ,
23+ paymentTokenAddress : zHex ,
24+ ipniPiece : zHex . optional ( ) ,
25+ ipniIpfs : zHex . optional ( ) ,
26+ ipniPeerId : zHex . optional ( ) ,
27+ } )
28+ . catchall ( zHex )
2729// Standard capability keys for PDP product type (must match ServiceProviderRegistry.sol REQUIRED_PDP_KEYS)
2830export const CAP_SERVICE_URL = 'serviceURL'
2931export const CAP_MIN_PIECE_SIZE = 'minPieceSizeInBytes'
@@ -47,6 +49,9 @@ export function decodePDPOffering(provider: ProviderWithProduct): PDPOffering {
4749 return decodePDPCapabilities ( parsed . data )
4850}
4951
52+ /** Capability keys that are decoded into typed PDPOffering fields, derived from the schema */
53+ const KNOWN_CAPABILITY_KEYS = new Set ( [ ...Object . keys ( PDPOfferingSchema . shape ) , CAP_IPNI_PEER_ID_LEGACY ] )
54+
5055/**
5156 * Decode PDP capabilities from keys/values arrays into a PDPOffering object.
5257 * Based on Curio's capabilitiesToOffering function.
@@ -71,7 +76,15 @@ export function decodePDPCapabilities(capabilities: Record<string, Hex>): PDPOff
7176 ? base58btc . encode ( fromHex ( capabilities [ CAP_IPNI_PEER_ID_LEGACY ] , 'bytes' ) )
7277 : undefined ,
7378 }
74- return { ...required , ...optional }
79+
80+ const extraCapabilities : Record < string , Hex > = Object . create ( null )
81+ for ( const key of Object . keys ( capabilities ) ) {
82+ if ( ! KNOWN_CAPABILITY_KEYS . has ( key ) ) {
83+ extraCapabilities [ key ] = capabilities [ key ]
84+ }
85+ }
86+
87+ return { ...required , ...optional , extraCapabilities }
7588}
7689
7790/**
0 commit comments