mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
add trusted algo
This commit is contained in:
parent
49b61b5590
commit
59e2accf68
@ -23,7 +23,7 @@ before_script:
|
|||||||
- ganache-cli --port 18545 > ganache-cli.log &
|
- ganache-cli --port 18545 > ganache-cli.log &
|
||||||
- git clone https://github.com/oceanprotocol/barge
|
- git clone https://github.com/oceanprotocol/barge
|
||||||
- cd barge
|
- cd barge
|
||||||
- export AQUARIUS_VERSION=unstable
|
- export AQUARIUS_VERSION=ctd_trusted_algo
|
||||||
- export BRIZO_VERSION=v0.9.5
|
- export BRIZO_VERSION=v0.9.5
|
||||||
- export KEEPER_VERSION=v0.13.2
|
- export KEEPER_VERSION=v0.13.2
|
||||||
- export EVENTS_HANDLER_VERSION=v0.4.7
|
- export EVENTS_HANDLER_VERSION=v0.4.7
|
||||||
|
@ -261,6 +261,60 @@ export class Aquarius {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update Compute Privacy
|
||||||
|
* @param {DID | string} did DID of the asset to update.
|
||||||
|
* @param {number } serviceIndex Service index
|
||||||
|
* @param {boolean} allowRawAlgorithm Allow Raw Algorithms
|
||||||
|
* @param {boolean} allowNetworkAccess Allow Raw Algorithms
|
||||||
|
* @param {String[]} trustedAlgorithms Allow Raw Algorithms
|
||||||
|
* @param {String} updated Updated field of the DDO
|
||||||
|
* @param {String} signature Signature using updated field to verify that the consumer has rights
|
||||||
|
* @return {Promise<String>} Result.
|
||||||
|
*/
|
||||||
|
public async updateComputePrivacy(
|
||||||
|
did: DID | string,
|
||||||
|
serviceIndex: number,
|
||||||
|
allowRawAlgorithm: boolean,
|
||||||
|
allowNetworkAccess: boolean,
|
||||||
|
trustedAlgorithms: string[],
|
||||||
|
updated: string,
|
||||||
|
signature: string
|
||||||
|
): Promise<string> {
|
||||||
|
did = did && DID.parse(did)
|
||||||
|
const fullUrl = `${this.url}${apiPath}/computePrivacy/update/${did.getDid()}`
|
||||||
|
const result = await this.fetch
|
||||||
|
.put(
|
||||||
|
fullUrl,
|
||||||
|
JSON.stringify({
|
||||||
|
signature: signature,
|
||||||
|
updated: updated,
|
||||||
|
serviceIndex: serviceIndex,
|
||||||
|
allowRawAlgorithm: allowRawAlgorithm,
|
||||||
|
allowNetworkAccess: allowNetworkAccess,
|
||||||
|
trustedAlgorithms: trustedAlgorithms
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.then((response: any) => {
|
||||||
|
if (response.ok) {
|
||||||
|
return response.text
|
||||||
|
}
|
||||||
|
this.logger.log(
|
||||||
|
'update compute privacy failed:',
|
||||||
|
response.status,
|
||||||
|
response.statusText
|
||||||
|
)
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
|
||||||
|
.catch(error => {
|
||||||
|
this.logger.error('Error updating compute privacy: ', error)
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Edit Metadata for a DDO.
|
* Edit Metadata for a DDO.
|
||||||
* @param {did} string DID.
|
* @param {did} string DID.
|
||||||
|
@ -25,6 +25,12 @@ export interface ServiceAccessAttributes extends ServiceCommonAttributes {
|
|||||||
timeout: number
|
timeout: number
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
export interface ServiceComputePrivacy{
|
||||||
|
allowRawAlgorithm: boolean,
|
||||||
|
allowNetworkAccess: boolean,
|
||||||
|
trustedAlgorithms: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export interface ServiceComputeAttributes extends ServiceCommonAttributes {
|
export interface ServiceComputeAttributes extends ServiceCommonAttributes {
|
||||||
main: {
|
main: {
|
||||||
@ -34,6 +40,7 @@ export interface ServiceComputeAttributes extends ServiceCommonAttributes {
|
|||||||
timeout: number
|
timeout: number
|
||||||
provider?: ServiceComputeProvider
|
provider?: ServiceComputeProvider
|
||||||
name: string
|
name: string
|
||||||
|
privacy?: ServiceComputePrivacy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import { TransactionReceipt } from 'web3-core'
|
|||||||
import { SearchQuery } from '../aquarius/Aquarius'
|
import { SearchQuery } from '../aquarius/Aquarius'
|
||||||
import { DDO } from '../ddo/DDO'
|
import { DDO } from '../ddo/DDO'
|
||||||
import { MetaData, EditableMetaData } from '../ddo/MetaData'
|
import { MetaData, EditableMetaData } from '../ddo/MetaData'
|
||||||
import { Service, ServiceAccess } from '../ddo/Service'
|
import { Service, ServiceAccess, ServiceComputePrivacy } from '../ddo/Service'
|
||||||
import Account from './Account'
|
import Account from './Account'
|
||||||
import DID from './DID'
|
import DID from './DID'
|
||||||
import { fillConditionsWithDDO, SubscribablePromise, didZeroX } from '../utils'
|
import { fillConditionsWithDDO, SubscribablePromise, didZeroX } from '../utils'
|
||||||
@ -414,6 +414,41 @@ export class OceanAssets extends Instantiable {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update Compute Privacy
|
||||||
|
* @param {did} string DID.
|
||||||
|
* @param {number} serviceIndex Index of the compute service in the DDO
|
||||||
|
* @param {ServiceComputePrivacy} computePrivacy ComputePrivacy fields & new values.
|
||||||
|
* @param {Account} account Ethereum account of owner to sign and prove the ownership.
|
||||||
|
* @return {Promise<string>}
|
||||||
|
*/
|
||||||
|
public async updateComputePrivacy(
|
||||||
|
did: string,
|
||||||
|
serviceIndex: number,
|
||||||
|
computePrivacy: ServiceComputePrivacy,
|
||||||
|
account: Account
|
||||||
|
): Promise<string> {
|
||||||
|
const oldDdo = await this.ocean.aquarius.retrieveDDO(did)
|
||||||
|
// get a signature
|
||||||
|
const signature = await this.ocean.utils.signature.signForAquarius(
|
||||||
|
oldDdo.updated,
|
||||||
|
account
|
||||||
|
)
|
||||||
|
let result = null
|
||||||
|
if (signature != null)
|
||||||
|
result = await this.ocean.aquarius.updateComputePrivacy(
|
||||||
|
did,
|
||||||
|
serviceIndex,
|
||||||
|
computePrivacy.allowRawAlgorithm,
|
||||||
|
computePrivacy.allowNetworkAccess,
|
||||||
|
computePrivacy.trustedAlgorithms,
|
||||||
|
oldDdo.updated,
|
||||||
|
signature
|
||||||
|
)
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retire a DDO (Delete)
|
* Retire a DDO (Delete)
|
||||||
* @param {did} string DID.
|
* @param {did} string DID.
|
||||||
|
@ -5,7 +5,7 @@ import { DDO } from '../ddo/DDO'
|
|||||||
import { SubscribablePromise } from '../utils'
|
import { SubscribablePromise } from '../utils'
|
||||||
import { OrderProgressStep } from './utils/ServiceUtils'
|
import { OrderProgressStep } from './utils/ServiceUtils'
|
||||||
import { DID } from '../squid'
|
import { DID } from '../squid'
|
||||||
import { ServiceCompute } from '../ddo/Service'
|
import { ServiceCompute, ServiceComputePrivacy } from '../ddo/Service'
|
||||||
|
|
||||||
export const ComputeJobStatus = Object.freeze({
|
export const ComputeJobStatus = Object.freeze({
|
||||||
Started: 10,
|
Started: 10,
|
||||||
@ -266,12 +266,13 @@ export class OceanCompute extends Instantiable {
|
|||||||
public async createComputeServiceAttributes(
|
public async createComputeServiceAttributes(
|
||||||
consumerAccount: Account,
|
consumerAccount: Account,
|
||||||
price: string,
|
price: string,
|
||||||
datePublished: string
|
datePublished: string,
|
||||||
|
computePrivacy?: ServiceComputePrivacy
|
||||||
): Promise<ServiceCompute> {
|
): Promise<ServiceCompute> {
|
||||||
const { templates } = this.ocean.keeper
|
const { templates } = this.ocean.keeper
|
||||||
const serviceAgreementTemplate = await templates.escrowComputeExecutionTemplate.getServiceAgreementTemplate()
|
const serviceAgreementTemplate = await templates.escrowComputeExecutionTemplate.getServiceAgreementTemplate()
|
||||||
const name = 'dataAssetComputingServiceAgreement'
|
const name = 'dataAssetComputingServiceAgreement'
|
||||||
return {
|
let service={
|
||||||
type: 'compute',
|
type: 'compute',
|
||||||
index: 3,
|
index: 3,
|
||||||
serviceEndpoint: this.ocean.brizo.getComputeEndpoint(),
|
serviceEndpoint: this.ocean.brizo.getComputeEndpoint(),
|
||||||
@ -287,5 +288,8 @@ export class OceanCompute extends Instantiable {
|
|||||||
serviceAgreementTemplate
|
serviceAgreementTemplate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (computePrivacy)
|
||||||
|
service['attributes']['main']['privacy'] = computePrivacy
|
||||||
|
return service as ServiceCompute
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ import { assert } from 'chai'
|
|||||||
import { config } from '../config'
|
import { config } from '../config'
|
||||||
import { getMetadata } from '../utils'
|
import { getMetadata } from '../utils'
|
||||||
import { Ocean, Account, EditableMetaData } from '../../../src' // @oceanprotocol/squid
|
import { Ocean, Account, EditableMetaData } from '../../../src' // @oceanprotocol/squid
|
||||||
|
import { ServiceComputePrivacy } from '../../../src/ddo/Service'
|
||||||
|
|
||||||
describe('Asset Owners', () => {
|
describe('Asset Owners', () => {
|
||||||
let ocean: Ocean
|
let ocean: Ocean
|
||||||
@ -202,4 +203,56 @@ describe('Asset Owners', () => {
|
|||||||
assert.equal(-1, remList.indexOf(consumer1.getId()))
|
assert.equal(-1, remList.indexOf(consumer1.getId()))
|
||||||
assert.notEqual(-1, remList.indexOf(consumer2.getId()))
|
assert.notEqual(-1, remList.indexOf(consumer2.getId()))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should be able to update computePrivacy', async () => {
|
||||||
|
const origComputePrivacy = {
|
||||||
|
allowRawAlgorithm: true,
|
||||||
|
allowNetworkAccess: true,
|
||||||
|
trustedAlgorithms: []
|
||||||
|
}
|
||||||
|
|
||||||
|
const newComputePrivacy = {
|
||||||
|
allowRawAlgorithm: false,
|
||||||
|
allowNetworkAccess: false,
|
||||||
|
trustedAlgorithms: ['did:op:123', 'did:op:1234']
|
||||||
|
}
|
||||||
|
const computeService = await ocean.compute.createComputeServiceAttributes(
|
||||||
|
account1,
|
||||||
|
'0',
|
||||||
|
'2020-03-10T10:00:00Z',
|
||||||
|
origComputePrivacy as ServiceComputePrivacy
|
||||||
|
)
|
||||||
|
const { id } = await ocean.assets.create(metadata as any, account1, [
|
||||||
|
computeService
|
||||||
|
])
|
||||||
|
|
||||||
|
const oldDDO = await ocean.assets.resolve(id)
|
||||||
|
let serviceIndex = null
|
||||||
|
|
||||||
|
for (let index = 0; index < oldDDO.service.length; index++) {
|
||||||
|
if (oldDDO.service[index].type == 'compute') serviceIndex = index
|
||||||
|
}
|
||||||
|
|
||||||
|
await ocean.assets.updateComputePrivacy(
|
||||||
|
id,
|
||||||
|
serviceIndex,
|
||||||
|
newComputePrivacy as ServiceComputePrivacy,
|
||||||
|
account1
|
||||||
|
)
|
||||||
|
|
||||||
|
const newDDO = await ocean.assets.resolve(id)
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
newDDO.service[serviceIndex].attributes.main.privacy.allowRawAlgorithm,
|
||||||
|
newComputePrivacy.allowRawAlgorithm
|
||||||
|
)
|
||||||
|
assert.equal(
|
||||||
|
newDDO.service[serviceIndex].attributes.main.privacy.allowNetworkAccess,
|
||||||
|
newComputePrivacy.allowNetworkAccess
|
||||||
|
)
|
||||||
|
assert.equal(
|
||||||
|
newDDO.service[serviceIndex].attributes.main.privacy.trustedAlgorithms,
|
||||||
|
newComputePrivacy.trustedAlgorithms
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user