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) {
return `${this.url}/api/v1/aquarius/assets/metadata/${did.getId()}`
return `${this.url}/api/v1/aquarius/assets/ddo/did:op:${did.getId()}`
}
private transformResult(

View File

@ -33,7 +33,7 @@ export class 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.
@ -102,7 +102,7 @@ export class DDO {
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)
return {
created: (new Date()).toISOString(),
created: new Date().toISOString().replace(/\.[0-9]{3}/, ""),
creator: publicKey,
type: "DDOIntegritySignature",
signatureValue: signature,

View File

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

View File

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

View File

@ -15,7 +15,7 @@ export default class DIDRegistry extends ContractBase {
return this.send(
"registerAttribute",
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 { LockRewardCondition, EscrowReward, AccessSecretStoreCondition } from "../conditions"
import DIDRegistry from "../DIDRegistry"
import { DDO } from "../../../ddo/DDO"
import { generateId, zeroX } from "../../../utils"
import { InstantiableConfig } from "../../../Instantiable.abstract"

View File

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

View File

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

View File

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