mirror of
https://github.com/oceanprotocol/market.git
synced 2024-06-20 11:23:24 +02:00
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
|
import {
|
||
|
DDO,
|
||
|
Ocean,
|
||
|
ServiceComputePrivacy,
|
||
|
publisherTrustedAlgorithm as PublisherTrustedAlgorithm
|
||
|
} from '@oceanprotocol/lib'
|
||
|
import { ComputePrivacyForm } from '../models/FormEditComputeDataset'
|
||
|
|
||
|
export async function createTrustedAlgorithmList(
|
||
|
selectedAlgorithms: string[], // list of DIDs
|
||
|
ocean: Ocean
|
||
|
): Promise<PublisherTrustedAlgorithm[]> {
|
||
|
const trustedAlgorithms = []
|
||
|
|
||
|
for (const selectedAlgorithm of selectedAlgorithms) {
|
||
|
const trustedAlgorithm = await ocean.compute.createPublisherTrustedAlgorithmfromDID(
|
||
|
selectedAlgorithm
|
||
|
)
|
||
|
trustedAlgorithms.push(trustedAlgorithm)
|
||
|
}
|
||
|
return trustedAlgorithms
|
||
|
}
|
||
|
|
||
|
export async function transformComputeFormToServiceComputePrivacy(
|
||
|
values: ComputePrivacyForm,
|
||
|
ocean: Ocean
|
||
|
): Promise<ServiceComputePrivacy> {
|
||
|
const { allowAllPublishedAlgorithms } = values
|
||
|
const publisherTrustedAlgorithms = values.allowAllPublishedAlgorithms
|
||
|
? []
|
||
|
: await createTrustedAlgorithmList(values.publisherTrustedAlgorithms, ocean)
|
||
|
|
||
|
const privacy: ServiceComputePrivacy = {
|
||
|
allowNetworkAccess: false,
|
||
|
allowRawAlgorithm: false,
|
||
|
allowAllPublishedAlgorithms,
|
||
|
publisherTrustedAlgorithms
|
||
|
}
|
||
|
|
||
|
return privacy
|
||
|
}
|