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 { Authentication } from "./Authentication"
|
||||||
import { Proof } from "./Proof"
|
import { Proof } from "./Proof"
|
||||||
import { PublicKey } from "./PublicKey"
|
import { PublicKey } from "./PublicKey"
|
||||||
import { Service } from "./Service"
|
import { Service, ServiceMetadata } from "./Service"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DID Descriptor Object.
|
* DID Descriptor Object.
|
||||||
@ -89,7 +89,7 @@ export class DDO {
|
|||||||
*/
|
*/
|
||||||
public getChecksum(): string {
|
public getChecksum(): string {
|
||||||
const web3 = Web3Provider.getWeb3()
|
const web3 = Web3Provider.getWeb3()
|
||||||
const {metadata} = this.findServiceByType("Metadata")
|
const {metadata} = <ServiceMetadata>this.findServiceByType("Metadata")
|
||||||
const {files, name, author, license} = metadata.base
|
const {files, name, author, license} = metadata.base
|
||||||
|
|
||||||
const values = [
|
const values = [
|
||||||
@ -128,7 +128,7 @@ export class DDO {
|
|||||||
* Generated and adds the checksum.
|
* Generated and adds the checksum.
|
||||||
*/
|
*/
|
||||||
public addChecksum(): void {
|
public addChecksum(): void {
|
||||||
const metadataService = this.findServiceByType("Metadata")
|
const metadataService = <ServiceMetadata>this.findServiceByType("Metadata")
|
||||||
if (metadataService.metadata.base.checksum) {
|
if (metadataService.metadata.base.checksum) {
|
||||||
Logger.log("Checksum already exists")
|
Logger.log("Checksum already exists")
|
||||||
return
|
return
|
||||||
|
@ -2,14 +2,29 @@ import { Condition } from "./Condition"
|
|||||||
import { Contract } from "./Contract"
|
import { Contract } from "./Contract"
|
||||||
import { MetaData } from "./MetaData"
|
import { MetaData } from "./MetaData"
|
||||||
|
|
||||||
export interface Service {
|
export interface ServiceCommon {
|
||||||
type: string
|
type: string
|
||||||
|
serviceEndpoint?: string
|
||||||
serviceDefinitionId?: 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
|
templateId?: string
|
||||||
serviceEndpoint: string
|
serviceEndpoint: string
|
||||||
purchaseEndpoint?: string
|
purchaseEndpoint?: string
|
||||||
description?: string
|
description?: string
|
||||||
metadata?: MetaData
|
|
||||||
serviceAgreementContract?: Contract
|
serviceAgreementContract?: Contract
|
||||||
conditions?: Condition[]
|
conditions?: Condition[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type Service = ServiceBase | ServiceAuthorization | ServiceMetadata
|
||||||
|
@ -61,9 +61,6 @@ export default class OceanAssets {
|
|||||||
const brizo = BrizoProvider.getBrizo()
|
const brizo = BrizoProvider.getBrizo()
|
||||||
|
|
||||||
const did: DID = DID.generate()
|
const did: DID = DID.generate()
|
||||||
const accessServiceDefinitionId: string = "0"
|
|
||||||
const computeServiceDefintionId: string = "1"
|
|
||||||
const metadataServiceDefinitionId: string = "2"
|
|
||||||
|
|
||||||
metadata.base.encryptedFiles = await SecretStoreProvider.getSecretStore()
|
metadata.base.encryptedFiles = await SecretStoreProvider.getSecretStore()
|
||||||
.encryptDocument(did.getId(), metadata.base.files)
|
.encryptDocument(did.getId(), metadata.base.files)
|
||||||
@ -75,6 +72,7 @@ export default class OceanAssets {
|
|||||||
|
|
||||||
const serviceEndpoint = aquarius.getServiceEndpoint(did)
|
const serviceEndpoint = aquarius.getServiceEndpoint(did)
|
||||||
|
|
||||||
|
let serviceDefinitionIdCount = 0
|
||||||
// create ddo itself
|
// create ddo itself
|
||||||
const ddo: DDO = new DDO({
|
const ddo: DDO = new DDO({
|
||||||
authentication: [{
|
authentication: [{
|
||||||
@ -96,7 +94,7 @@ export default class OceanAssets {
|
|||||||
purchaseEndpoint: brizo.getPurchaseEndpoint(),
|
purchaseEndpoint: brizo.getPurchaseEndpoint(),
|
||||||
serviceEndpoint: brizo.getConsumeEndpoint(),
|
serviceEndpoint: brizo.getConsumeEndpoint(),
|
||||||
// the id of the service agreement?
|
// the id of the service agreement?
|
||||||
serviceDefinitionId: accessServiceDefinitionId,
|
serviceDefinitionId: String(serviceDefinitionIdCount++),
|
||||||
// the id of the service agreement template
|
// the id of the service agreement template
|
||||||
templateId: serviceAgreementTemplate.getId(),
|
templateId: serviceAgreementTemplate.getId(),
|
||||||
serviceAgreementContract: {
|
serviceAgreementContract: {
|
||||||
@ -118,14 +116,13 @@ export default class OceanAssets {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "Compute",
|
type: "Compute",
|
||||||
serviceEndpoint: brizo.getComputeEndpoint(publisher.getId(),
|
serviceEndpoint: brizo.getComputeEndpoint(publisher.getId(), String(serviceDefinitionIdCount), "xxx", "xxx"),
|
||||||
computeServiceDefintionId, "xxx", "xxx"),
|
serviceDefinitionId: String(serviceDefinitionIdCount++),
|
||||||
serviceDefinitionId: computeServiceDefintionId,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "Metadata",
|
type: "Metadata",
|
||||||
serviceEndpoint,
|
serviceEndpoint,
|
||||||
serviceDefinitionId: metadataServiceDefinitionId,
|
serviceDefinitionId: String(serviceDefinitionIdCount++),
|
||||||
metadata: {
|
metadata: {
|
||||||
// Default values
|
// Default values
|
||||||
curation: {
|
curation: {
|
||||||
|
Loading…
Reference in New Issue
Block a user