@@ -83,57 +83,44 @@ export async function validateAlgoForDataset(
8383 if ( datasetService . type !== 'compute' || ! compute ) {
8484 throw new Error ( 'Service not compute' )
8585 }
86+ const publishers = compute . publisherTrustedAlgorithmPublishers || [ ]
87+ const algorithms = compute . publisherTrustedAlgorithms || [ ]
88+
89+ // If no restrictions are set, deny by default
90+ const hasTrustedPublishers = publishers . length > 0
91+ const hasTrustedAlgorithms = algorithms . length > 0
92+ if ( ! hasTrustedPublishers && ! hasTrustedAlgorithms ) return false
8693
8794 if ( algoDID ) {
88- if (
89- // if not set deny them all
90- ( ! Array . isArray ( compute . publisherTrustedAlgorithms ) ||
91- compute . publisherTrustedAlgorithms . length === 0 ) &&
92- ( ! Array . isArray ( compute . publisherTrustedAlgorithmPublishers ) ||
93- compute . publisherTrustedAlgorithmPublishers . length === 0 )
94- ) {
95- return false
96- }
95+ // Check if algorithm is explicitly trusted
96+ const isAlgoTrusted =
97+ hasTrustedAlgorithms &&
98+ algorithms . some ( ( algo : any ) => {
99+ const didMatch = algo . did === '*' || algo . did === algoDID
100+ const filesMatch =
101+ algo . filesChecksum === '*' || algo . filesChecksum === algoChecksums . files
102+ const containerMatch =
103+ algo . containerSectionChecksum === '*' ||
104+ algo . containerSectionChecksum === algoChecksums . container
105+ return didMatch && filesMatch && containerMatch
106+ } )
97107
98- if (
99- compute . publisherTrustedAlgorithms . includes ( '*' ) &&
100- compute . publisherTrustedAlgorithmPublishers . includes ( '*' )
101- ) {
102- return true
103- }
108+ // Check if algorithm publisher is trusted
109+ let isPublisherTrusted = true
110+ if ( hasTrustedPublishers ) {
111+ if ( ! publishers . includes ( '*' ) ) {
112+ const algoDDO = await new FindDdoHandler ( oceanNode ) . findAndFormatDdo ( algoDID )
113+ if ( ! algoDDO ) return false
114+ const algoInstance = DDOManager . getDDOClass ( algoDDO )
115+ const { nftAddress } = algoInstance . getDDOFields ( )
104116
105- if (
106- Array . isArray ( compute . publisherTrustedAlgorithms ) &&
107- compute . publisherTrustedAlgorithms . length > 0 &&
108- ! compute . publisherTrustedAlgorithms . includes ( '*' )
109- ) {
110- const trustedAlgo = compute . publisherTrustedAlgorithms . find (
111- ( algo : any ) => algo . did === algoDID
112- )
113- if ( trustedAlgo ) {
114- return (
115- trustedAlgo . filesChecksum === algoChecksums . files &&
116- trustedAlgo . containerSectionChecksum === algoChecksums . container
117- )
118- }
119- return false
120- }
121- if (
122- Array . isArray ( compute . publisherTrustedAlgorithmPublishers ) &&
123- compute . publisherTrustedAlgorithmPublishers . length > 0 &&
124- ! compute . publisherTrustedAlgorithmPublishers . includes ( '*' )
125- ) {
126- const algoDDO = await new FindDdoHandler ( oceanNode ) . findAndFormatDdo ( algoDID )
127- const algoInstance = DDOManager . getDDOClass ( algoDDO )
128- const { nftAddress } = algoInstance . getDDOFields ( )
129- if ( algoDDO ) {
130- return compute . publisherTrustedAlgorithmPublishers
131- . map ( ( address : string ) => address ?. toLowerCase ( ) )
117+ isPublisherTrusted = publishers
118+ . map ( ( addr : string ) => addr ?. toLowerCase ( ) )
132119 . includes ( nftAddress ?. toLowerCase ( ) )
133120 }
134- return false
135121 }
136- return true
122+
123+ return isAlgoTrusted && isPublisherTrusted
137124 }
138125
139126 return compute . allowRawAlgorithm
0 commit comments