1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

Fix differences between implementation on DDO generation.

This commit is contained in:
Pedro Gutiérrez 2019-04-29 13:31:03 +02:00
parent c8411e29d2
commit bb1a02a5d1
9 changed files with 23 additions and 33 deletions

View File

@ -169,7 +169,7 @@ export class Aquarius extends Instantiable {
} }
public getServiceEndpoint(did: DID) { public getServiceEndpoint(did: DID) {
return `${this.url}/api/v1/aquarius/assets/metadata/${did.getId()}` return `${this.url}/api/v1/aquarius/assets/ddo/did:op:${did.getId()}`
} }
private transformResult( private transformResult(

View File

@ -33,7 +33,7 @@ export class DDO {
return new DDO(ddo) return new DDO(ddo)
} }
public "@context": string = "https://w3id.org/future-method/v1" public "@context": string = "https://w3id.org/did/v1"
/** /**
* DID, descentralized ID. * DID, descentralized ID.
@ -102,7 +102,7 @@ export class DDO {
this.id, this.id,
] ]
return Web3Provider.getWeb3().utils.sha3(values.join("")).replace(/^0x([a-f0-9]{32}).+$/i, "$1") return Web3Provider.getWeb3().utils.sha3(values.join("")).replace(/^0x([a-f0-9]{64})(:!.+)?$/i, "$1")
} }
/** /**
@ -118,7 +118,7 @@ export class DDO {
const signature = await ocean.utils.signature.signText(checksum, publicKey, password) const signature = await ocean.utils.signature.signText(checksum, publicKey, password)
return { return {
created: (new Date()).toISOString(), created: new Date().toISOString().replace(/\.[0-9]{3}/, ""),
creator: publicKey, creator: publicKey,
type: "DDOIntegritySignature", type: "DDOIntegritySignature",
signatureValue: signature, signatureValue: signature,

View File

@ -240,7 +240,7 @@ export interface AdditionalInformation {
} }
export interface MetaData { export interface MetaData {
additionalInformation: AdditionalInformation additionalInformation?: AdditionalInformation
base: MetaDataBase base: MetaDataBase
curation: Curation curation?: Curation
} }

View File

@ -13,7 +13,7 @@ export interface PublicKey {
* Type of key. * Type of key.
* @type {string} * @type {string}
*/ */
type: "Ed25519VerificationKey2018" | "RsaVerificationKey2018" | "EdDsaSAPublicKeySecp256k1" type: "Ed25519VerificationKey2018" | "RsaVerificationKey2018" | "EdDsaSAPublicKeySecp256k1" | "EthereumECDSAKey"
/** /**
* Key owner. * Key owner.

View File

@ -15,7 +15,7 @@ export default class DIDRegistry extends ContractBase {
return this.send( return this.send(
"registerAttribute", "registerAttribute",
ownerAddress, ownerAddress,
[zeroX(did), Web3Provider.getWeb3().utils.fromAscii(checksum), providers.map(zeroX), value], [zeroX(did), zeroX(checksum), providers.map(zeroX), value],
) )
} }

View File

@ -1,6 +1,4 @@
import { AgreementTemplate } from "./AgreementTemplate.abstract" import { AgreementTemplate } from "./AgreementTemplate.abstract"
import { LockRewardCondition, EscrowReward, AccessSecretStoreCondition } from "../conditions"
import DIDRegistry from "../DIDRegistry"
import { DDO } from "../../../ddo/DDO" import { DDO } from "../../../ddo/DDO"
import { generateId, zeroX } from "../../../utils" import { generateId, zeroX } from "../../../utils"
import { InstantiableConfig } from "../../../Instantiable.abstract" import { InstantiableConfig } from "../../../Instantiable.abstract"

View File

@ -66,56 +66,45 @@ export class OceanAssets extends Instantiable {
id: did.getDid(), id: did.getDid(),
authentication: [{ authentication: [{
type: "RsaSignatureAuthentication2018", type: "RsaSignatureAuthentication2018",
publicKey: did.getDid() + "#keys-1", publicKey: did.getDid(),
}], }],
publicKey: [ publicKey: [
{ {
id: did.getDid() + "#keys-1", id: did.getDid(),
type: "Ed25519VerificationKey2018", type: "EthereumECDSAKey",
owner: did.getDid(), owner: publisher.getId(),
publicKeyBase58: await publisher.getPublicKey(),
}, },
], ],
service: [ service: [
{ {
type: "Access", type: "Access",
creator: "",
purchaseEndpoint: this.ocean.brizo.getPurchaseEndpoint(), purchaseEndpoint: this.ocean.brizo.getPurchaseEndpoint(),
serviceEndpoint: this.ocean.brizo.getConsumeEndpoint(), serviceEndpoint: this.ocean.brizo.getConsumeEndpoint(),
serviceDefinitionId: String(serviceDefinitionIdCount++), name: "dataAssetAccessServiceAgreement",
templateId: templates.escrowAccessSecretStoreTemplate.getAddress(), templateId: templates.escrowAccessSecretStoreTemplate.getAddress(),
serviceAgreementTemplate, serviceAgreementTemplate,
}, },
{
type: "Compute",
serviceEndpoint: this.ocean.brizo.getComputeEndpoint(publisher.getId(), String(serviceDefinitionIdCount), "xxx", "xxx"),
serviceDefinitionId: String(serviceDefinitionIdCount++),
},
{ {
type: "Authorization", type: "Authorization",
services: "SecretStore", service: "SecretStore",
serviceEndpoint: secretStoreUri, serviceEndpoint: secretStoreUri,
serviceDefinitionId: String(serviceDefinitionIdCount++),
}, },
{ {
type: "Metadata", type: "Metadata",
serviceEndpoint, serviceEndpoint,
serviceDefinitionId: String(serviceDefinitionIdCount++),
metadata: { metadata: {
// Default values // Default values
curation: { curation: {
rating: 0, rating: 0,
numVotes: 0, numVotes: 0,
}, },
additionalInformation: {
updateFrecuency: "yearly",
structuredMarkup: [],
},
// Overwrites defaults // Overwrites defaults
...metadata, ...metadata,
// Cleaning not needed information // Cleaning not needed information
base: { base: {
...metadata.base, ...metadata.base,
contentUrls: [], contentUrls: undefined,
encryptedFiles, encryptedFiles,
files: metadata.base.files files: metadata.base.files
.map((file, index) => ({ .map((file, index) => ({
@ -126,13 +115,14 @@ export class OceanAssets extends Instantiable {
} as any, } as any,
}, },
}, },
...services ...services,
.map((_) => ({..._, serviceDefinitionId: String(serviceDefinitionIdCount++)})),
] ]
// Remove duplications // Remove duplications
.reverse() .reverse()
.filter(({type}, i, list) => list.findIndex(({type: t}) => t === type) === i) .filter(({type}, i, list) => list.findIndex(({type: t}) => t === type) === i)
.reverse() as Service[], .reverse()
// Adding ID
.map((_) => ({..._, serviceDefinitionId: String(serviceDefinitionIdCount++)})) as Service[],
}) })
// Overwritte initial service agreement conditions // Overwritte initial service agreement conditions

View File

@ -11,6 +11,8 @@ function fillParameterWithDDO(parameter: ServiceAgreementTemplateParameter, ddo:
case "documentId": case "documentId":
case "documentKeyId": case "documentKeyId":
return ddo.shortId() return ddo.shortId()
case "rewardAddress":
return ddo.publicKey[0].owner
} }
return "" return ""

View File

@ -247,7 +247,7 @@ describe("DDO", () => {
const ddo = new DDO(testDDO) const ddo = new DDO(testDDO)
const checksum = ddo.getChecksum() const checksum = ddo.getChecksum()
assert.equal(checksum, "15f27a7a3c7b15d2b06dec7347c6b8da") assert.equal(checksum, "15f27a7a3c7b15d2b06dec7347c6b8da168adddd7df51a8ebbbe87b59b80049b")
}) })
}) })