mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
improved Service definition
This commit is contained in:
parent
15f8ce8da1
commit
8fb465fc5b
@ -4,7 +4,7 @@ import * as signatureHelpers from "../utils/SignatureHelpers"
|
||||
import { Authentication } from "./Authentication"
|
||||
import { Proof } from "./Proof"
|
||||
import { PublicKey } from "./PublicKey"
|
||||
import { Service } from "./Service"
|
||||
import { Service, ServiceMetadata } from "./Service"
|
||||
|
||||
/**
|
||||
* DID Descriptor Object.
|
||||
@ -89,7 +89,7 @@ export class DDO {
|
||||
*/
|
||||
public getChecksum(): string {
|
||||
const web3 = Web3Provider.getWeb3()
|
||||
const {metadata} = this.findServiceByType("Metadata")
|
||||
const {metadata} = <ServiceMetadata>this.findServiceByType("Metadata")
|
||||
const {files, name, author, license} = metadata.base
|
||||
|
||||
const values = [
|
||||
@ -128,7 +128,7 @@ export class DDO {
|
||||
* Generated and adds the checksum.
|
||||
*/
|
||||
public addChecksum(): void {
|
||||
const metadataService = this.findServiceByType("Metadata")
|
||||
const metadataService = <ServiceMetadata>this.findServiceByType("Metadata")
|
||||
if (metadataService.metadata.base.checksum) {
|
||||
Logger.log("Checksum already exists")
|
||||
return
|
||||
|
@ -2,14 +2,29 @@ import { Condition } from "./Condition"
|
||||
import { Contract } from "./Contract"
|
||||
import { MetaData } from "./MetaData"
|
||||
|
||||
export interface Service {
|
||||
export interface ServiceCommon {
|
||||
type: string
|
||||
serviceEndpoint?: string
|
||||
serviceDefinitionId?: string
|
||||
}
|
||||
|
||||
export interface ServiceAuthorization extends ServiceCommon {
|
||||
type: "Authorization"
|
||||
service: "SecretStore" | "None" | "RSAES-OAEP"
|
||||
}
|
||||
|
||||
export interface ServiceMetadata extends ServiceCommon {
|
||||
type: "Metadata"
|
||||
metadata: MetaData
|
||||
}
|
||||
|
||||
export interface ServiceBase extends ServiceCommon {
|
||||
templateId?: string
|
||||
serviceEndpoint: string
|
||||
purchaseEndpoint?: string
|
||||
description?: string
|
||||
metadata?: MetaData
|
||||
serviceAgreementContract?: Contract
|
||||
conditions?: Condition[]
|
||||
}
|
||||
|
||||
export type Service = ServiceBase | ServiceAuthorization | ServiceMetadata
|
||||
|
@ -61,9 +61,6 @@ export default class OceanAssets {
|
||||
const brizo = BrizoProvider.getBrizo()
|
||||
|
||||
const did: DID = DID.generate()
|
||||
const accessServiceDefinitionId: string = "0"
|
||||
const computeServiceDefintionId: string = "1"
|
||||
const metadataServiceDefinitionId: string = "2"
|
||||
|
||||
metadata.base.encryptedFiles = await SecretStoreProvider.getSecretStore()
|
||||
.encryptDocument(did.getId(), metadata.base.files)
|
||||
@ -75,6 +72,7 @@ export default class OceanAssets {
|
||||
|
||||
const serviceEndpoint = aquarius.getServiceEndpoint(did)
|
||||
|
||||
let serviceDefinitionIdCount = 0
|
||||
// create ddo itself
|
||||
const ddo: DDO = new DDO({
|
||||
authentication: [{
|
||||
@ -96,7 +94,7 @@ export default class OceanAssets {
|
||||
purchaseEndpoint: brizo.getPurchaseEndpoint(),
|
||||
serviceEndpoint: brizo.getConsumeEndpoint(),
|
||||
// the id of the service agreement?
|
||||
serviceDefinitionId: accessServiceDefinitionId,
|
||||
serviceDefinitionId: String(serviceDefinitionIdCount++),
|
||||
// the id of the service agreement template
|
||||
templateId: serviceAgreementTemplate.getId(),
|
||||
serviceAgreementContract: {
|
||||
@ -118,14 +116,13 @@ export default class OceanAssets {
|
||||
},
|
||||
{
|
||||
type: "Compute",
|
||||
serviceEndpoint: brizo.getComputeEndpoint(publisher.getId(),
|
||||
computeServiceDefintionId, "xxx", "xxx"),
|
||||
serviceDefinitionId: computeServiceDefintionId,
|
||||
serviceEndpoint: brizo.getComputeEndpoint(publisher.getId(), String(serviceDefinitionIdCount), "xxx", "xxx"),
|
||||
serviceDefinitionId: String(serviceDefinitionIdCount++),
|
||||
},
|
||||
{
|
||||
type: "Metadata",
|
||||
serviceEndpoint,
|
||||
serviceDefinitionId: metadataServiceDefinitionId,
|
||||
serviceDefinitionId: String(serviceDefinitionIdCount++),
|
||||
metadata: {
|
||||
// Default values
|
||||
curation: {
|
||||
|
Loading…
Reference in New Issue
Block a user