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

linter fixes

This commit is contained in:
Pedro Gutiérrez 2019-02-04 18:13:54 +01:00 committed by Pedro Gutiérrez
parent 749e77cf53
commit f82b99792f
23 changed files with 105 additions and 105 deletions

View File

@ -1,4 +1,4 @@
export interface Authentication { export interface Authentication {
public type: string type: string
public publicKey: string publicKey: string
} }

View File

@ -1,4 +1,4 @@
import Event from "./Event" import { Event } from "./Event"
export interface Contract { export interface Contract {
contractName: string contractName: string

View File

@ -1,9 +1,9 @@
import Web3Provider from "../keeper/Web3Provider"
import * as signatureHelpers from "../utils/SignatureHelpers"
import { Authentication } from "./Authentication" import { Authentication } from "./Authentication"
import { Proof } from "./Proof"
import { PublicKey } from "./PublicKey" import { PublicKey } from "./PublicKey"
import { Service } from "./Service" import { Service } from "./Service"
import { Proof } from "./Proof"
import Web3Provider from '../keeper/Web3Provider'
import * as signatureHelpers from "../utils/SignatureHelpers"
/** /**
* DID Descriptor Object. * DID Descriptor Object.
@ -86,20 +86,20 @@ export class DDO {
*/ */
public getChecksum(): string { public getChecksum(): string {
const web3 = Web3Provider.getWeb3() const web3 = Web3Provider.getWeb3()
const {metadata} = this.findServiceByType('Metadata') const {metadata} = this.findServiceByType("Metadata")
const {files, name, author, license} = metadata.base const {files, name, author, license} = metadata.base
const values = [ const values = [
...(files || []) ...(files || [])
.map(({checksum}) => checksum) .map(({checksum}) => checksum)
.filter(_ => !!_), .filter((_) => !!_),
name, name,
author, author,
license, license,
this.id, this.id,
] ]
return web3.utils.sha3(values.join('')) return web3.utils.sha3(values.join(""))
} }
/** /**
@ -109,7 +109,7 @@ export class DDO {
* @return {Promise<Proof>} Proof object. * @return {Promise<Proof>} Proof object.
*/ */
public async generateProof(publicKey: string, password?: string): Promise<Proof> { public async generateProof(publicKey: string, password?: string): Promise<Proof> {
const checksum = this.getChecksum(); const checksum = this.getChecksum()
const signature = await signatureHelpers.signText(checksum, publicKey, password) const signature = await signatureHelpers.signText(checksum, publicKey, password)
@ -125,9 +125,9 @@ 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 = this.findServiceByType("Metadata")
if (metadataService.metadata.base.checksum) { if (metadataService.metadata.base.checksum) {
throw new Error('Checksum already exists') throw new Error("Checksum already exists")
} }
metadataService.metadata.base.checksum = this.getChecksum() metadataService.metadata.base.checksum = this.getChecksum()
} }
@ -140,7 +140,7 @@ export class DDO {
*/ */
public async addProof(publicKey: string, password?: string): Promise<void> { public async addProof(publicKey: string, password?: string): Promise<void> {
if (this.proof) { if (this.proof) {
throw new Error('Proof already exists') throw new Error("Proof already exists")
} }
this.proof = await this.generateProof(publicKey, password) this.proof = await this.generateProof(publicKey, password)
} }

View File

@ -17,7 +17,7 @@ export class MetaDataBase {
* @type {string} * @type {string}
* @example "UK Weather information 2011" * @example "UK Weather information 2011"
*/ */
name: string public name: string
/** /**
* Type of the Asset. Helps to filter by the type of asset, * Type of the Asset. Helps to filter by the type of asset,
@ -25,7 +25,7 @@ export class MetaDataBase {
* @type {string} * @type {string}
* @example "dataset" * @example "dataset"
*/ */
type: "dataset" | "algorithm" | "container" | "workflow" | "other" public type: "dataset" | "algorithm" | "container" | "workflow" | "other"
/** /**
* Details of what the resource is. For a dataset, this attribute * Details of what the resource is. For a dataset, this attribute
@ -33,28 +33,28 @@ export class MetaDataBase {
* @type {string} * @type {string}
* @example "Weather information of UK including temperature and humidity" * @example "Weather information of UK including temperature and humidity"
*/ */
description?: string public description?: string
/** /**
* The date on which the asset was created or was added. * The date on which the asset was created or was added.
* @type {string} * @type {string}
* @example "2012-10-10T17:00:000Z" * @example "2012-10-10T17:00:000Z"
*/ */
dateCreated: string public dateCreated: string
/** /**
* Size of the asset (e.g. 18MB). In the absence of a unit (MB, kB etc.), kB will be assumed. * Size of the asset (e.g. 18MB). In the absence of a unit (MB, kB etc.), kB will be assumed.
* @type {string} * @type {string}
* @example "3.1gb" * @example "3.1gb"
*/ */
size: string public size: string
/** /**
* Name of the entity generating this data (e.g. Tfl, Disney Corp, etc.). * Name of the entity generating this data (e.g. Tfl, Disney Corp, etc.).
* @type {string} * @type {string}
* @example "Met Office" * @example "Met Office"
*/ */
author: string public author: string
/** /**
* Short name referencing the license of the asset (e.g. Public Domain, CC-0, CC-BY, No License Specified, etc. ). * Short name referencing the license of the asset (e.g. Public Domain, CC-0, CC-BY, No License Specified, etc. ).
@ -62,35 +62,35 @@ export class MetaDataBase {
* @type {string} * @type {string}
* @example "CC-BY" * @example "CC-BY"
*/ */
license: string public license: string
/** /**
* The party holding the legal copyright. Empty by default. * The party holding the legal copyright. Empty by default.
* @type {string} * @type {string}
* @example "Met Office" * @example "Met Office"
*/ */
copyrightHolder?: string public copyrightHolder?: string
/** /**
* File encoding. * File encoding.
* @type {string} * @type {string}
* @example "UTF-8" * @example "UTF-8"
*/ */
encoding?: string public encoding?: string
/** /**
* File compression (e.g. no, gzip, bzip2, etc). * File compression (e.g. no, gzip, bzip2, etc).
* @type {string} * @type {string}
* @example "zip" * @example "zip"
*/ */
compression?: string public compression?: string
/** /**
* File format, if applicable. * File format, if applicable.
* @type {string} * @type {string}
* @example "text/csv" * @example "text/csv"
*/ */
contentType: string public contentType: string
/** /**
* Example of the concept of this asset. This example is part * Example of the concept of this asset. This example is part
@ -98,14 +98,14 @@ export class MetaDataBase {
* @type {string} * @type {string}
* @example "423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68" * @example "423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68"
*/ */
workExample?: string public workExample?: string
/** /**
* List of content URLs resolving the Asset files. * List of content URLs resolving the Asset files.
* @type {string | string[]} * @type {string | string[]}
* @example "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip" * @example "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip"
*/ */
contentUrls: string | string[] public contentUrls: string | string[]
/** /**
* Mapping of links for data samples, or links to find out more information. * Mapping of links for data samples, or links to find out more information.
@ -124,7 +124,7 @@ export class MetaDataBase {
* }, * },
* ] * ]
*/ */
links?: {[name: string]: string}[] public links?: Array<{[name: string]: string}>
/** /**
* The language of the content. Please use one of the language * The language of the content. Please use one of the language
@ -132,7 +132,7 @@ export class MetaDataBase {
* @type {String} * @type {String}
* @example "en" * @example "en"
*/ */
inLanguage?: string public inLanguage?: string
/** /**
* Keywords or tags used to describe this content. Multiple entries in a keyword * Keywords or tags used to describe this content. Multiple entries in a keyword
@ -140,28 +140,28 @@ export class MetaDataBase {
* @type {String} * @type {String}
* @example "weather, uk, 2011, temperature, humidity" * @example "weather, uk, 2011, temperature, humidity"
*/ */
tags?: string public tags?: string
/** /**
* Price of the asset. * Price of the asset.
* @type {String} * @type {String}
* @example 10 * @example 10
*/ */
price: number public price: number
/** /**
* Array of File objects including the encrypted file urls and some additional information. * Array of File objects including the encrypted file urls and some additional information.
* @type {File[]} * @type {File[]}
*/ */
files: File[] public files: File[]
/** /**
* SHA3 hash of concatenated values: [list of all file checksums] + name + author + license + did * SHA3 hash of concatenated values: [list of all file checksums] + name + author + license + did
* @type {string} * @type {string}
*/ */
checksum: string public checksum: string
encryptedFiles?: any public encryptedFiles?: any
} }
/** /**
@ -210,10 +210,10 @@ export interface AdditionalInformation {
* describing the dataset. * describing the dataset.
* @type {StructuredMarkup[]} * @type {StructuredMarkup[]}
*/ */
structuredMarkup: { structuredMarkup: Array<{
uri: string uri: string
mediaType: string mediaType: string,
}[] }>
/** /**
* Checksum of attributes to be able to compare if there are changes in * Checksum of attributes to be able to compare if there are changes in

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"
/** /**
* Key owner. * Key owner.

View File

@ -10,10 +10,10 @@ async function exec() {
const ocean: Ocean = await Ocean.getInstance(config) const ocean: Ocean = await Ocean.getInstance(config)
const publisher: Account = (await ocean.getAccounts())[0] const publisher: Account = (await ocean.getAccounts())[0]
publisher.setPassword('node0') publisher.setPassword("node0")
const consumer: Account = (await ocean.getAccounts())[1] const consumer: Account = (await ocean.getAccounts())[1]
const metaData: Partial<MetaData> = <any>{ const metaData: Partial<MetaData> = <any> {
base: { base: {
name: "Office Humidity", name: "Office Humidity",
type: "dataset", type: "dataset",
@ -43,7 +43,7 @@ async function exec() {
}, },
} }
const ddo: DDO = await ocean.registerAsset(<any>metaData, publisher) const ddo: DDO = await ocean.registerAsset(metaData as any, publisher)
Logger.log("did", ddo.id) Logger.log("did", ddo.id)
const did: DID = DID.parse(ddo.id) const did: DID = DID.parse(ddo.id)

View File

@ -9,10 +9,10 @@ async function exec() {
const ocean: Ocean = await Ocean.getInstance(config) const ocean: Ocean = await Ocean.getInstance(config)
const publisher: Account = (await ocean.getAccounts())[0] const publisher: Account = (await ocean.getAccounts())[0]
publisher.setPassword('node0') publisher.setPassword("node0")
const consumer: Account = (await ocean.getAccounts())[1] const consumer: Account = (await ocean.getAccounts())[1]
const metaData: Partial<MetaData> = <any>{ const metaData: Partial<MetaData> = <any> {
base: { base: {
name: "Office Humidity", name: "Office Humidity",
type: "dataset", type: "dataset",
@ -42,7 +42,7 @@ async function exec() {
}, },
} }
const ddo: DDO = await ocean.registerAsset(<any>metaData, publisher) const ddo: DDO = await ocean.registerAsset(metaData as any, publisher)
Logger.log("did", ddo.id) Logger.log("did", ddo.id)
const accessService = ddo.findServiceByType("Access") const accessService = ddo.findServiceByType("Access")

View File

@ -10,10 +10,10 @@ async function exec() {
const ocean: Ocean = await Ocean.getInstance(config) const ocean: Ocean = await Ocean.getInstance(config)
const publisher: Account = (await ocean.getAccounts())[0] const publisher: Account = (await ocean.getAccounts())[0]
publisher.setPassword('node0') publisher.setPassword("node0")
const consumer: Account = (await ocean.getAccounts())[1] const consumer: Account = (await ocean.getAccounts())[1]
const metaData: Partial<MetaData> = <any>{ const metaData: Partial<MetaData> = <any> {
base: { base: {
name: "Office Humidity", name: "Office Humidity",
type: "dataset", type: "dataset",
@ -43,7 +43,7 @@ async function exec() {
}, },
} }
const ddo: DDO = await ocean.registerAsset(<any>metaData, publisher) const ddo: DDO = await ocean.registerAsset(metaData as any, publisher)
Logger.log("did", ddo.id) Logger.log("did", ddo.id)
const did: DID = DID.parse(ddo.id) const did: DID = DID.parse(ddo.id)
@ -70,7 +70,7 @@ async function exec() {
const paid = await serviceAgreement.payAsset(did.getId(), metaData.base.price, consumer) const paid = await serviceAgreement.payAsset(did.getId(), metaData.base.price, consumer)
Logger.log(`Asset paid: ${paid}`) Logger.log(`Asset paid: ${paid}`)
const accessGranted = await serviceAgreement.grantAccess(did.getId(), did.getId(), publisher) const accessGranted = await serviceAgreement.grantAccess(did.getId(), publisher)
Logger.log(`Asset access granted: ${accessGranted}`) Logger.log(`Asset access granted: ${accessGranted}`)
} }

View File

@ -11,7 +11,7 @@ async function exec() {
const publisher: Account = (await ocean.getAccounts())[1] const publisher: Account = (await ocean.getAccounts())[1]
const consumer: Account = (await ocean.getAccounts())[1] const consumer: Account = (await ocean.getAccounts())[1]
const metaData: Partial<MetaData> = <any>{ const metaData: Partial<MetaData> = <any> {
base: { base: {
name: "Office Humidity", name: "Office Humidity",
type: "dataset", type: "dataset",
@ -40,7 +40,7 @@ async function exec() {
}, },
} }
const ddo: DDO = await ocean.registerAsset(<any>metaData, publisher) const ddo: DDO = await ocean.registerAsset(metaData as any, publisher)
Logger.log("Registered asset with did:", ddo.id) Logger.log("Registered asset with did:", ddo.id)
const accessService = ddo.findServiceByType("Access") const accessService = ddo.findServiceByType("Access")

View File

@ -8,9 +8,9 @@ async function exec() {
const ocean: Ocean = await Ocean.getInstance(config) const ocean: Ocean = await Ocean.getInstance(config)
const publisher: Account = (await ocean.getAccounts())[0] const publisher: Account = (await ocean.getAccounts())[0]
publisher.setPassword('node0') publisher.setPassword("node0")
const metaData: Partial<MetaData> = <any>{ const metaData: Partial<MetaData> = <any> {
base: { base: {
name: "Office Humidity", name: "Office Humidity",
type: "dataset", type: "dataset",
@ -40,7 +40,7 @@ async function exec() {
}, },
} }
const ddo: DDO = await ocean.registerAsset(<any>metaData, publisher) const ddo: DDO = await ocean.registerAsset(metaData as any, publisher)
Logger.log(ddo.id) Logger.log(ddo.id)
} }

View File

@ -26,7 +26,7 @@ async function exec() {
updateFrecuency: "yearly", updateFrecuency: "yearly",
checksum: "efdd14d39feb726e321931f408b3454d26f1a4899bcc608a68b5397f23203174", checksum: "efdd14d39feb726e321931f408b3454d26f1a4899bcc608a68b5397f23203174",
}, },
base: <any>{ base: <any> {
name: "Office Humidity", name: "Office Humidity",
type: "dataset", type: "dataset",
description: "Weather information of UK including temperature and humidity", description: "Weather information of UK including temperature and humidity",

View File

@ -1,6 +1,6 @@
{ {
"nodeUri": "http://localhost:8545", "nodeUri": "http://localhost:8545",
"aquariusUri": "http://localhost:5000", "aquariusUri": "https://nginx-aquarius.dev-ocean.com",
"brizoUri": "http://localhost:8030", "brizoUri": "http://localhost:8030",
"parityUri": "http://localhost:9545", "parityUri": "http://localhost:9545",
"secretStoreUri": "http://localhost:12001", "secretStoreUri": "http://localhost:12001",

View File

@ -18,7 +18,7 @@ export default class Account extends OceanBase {
* Set account password. * Set account password.
* @param {string} password Password for account. * @param {string} password Password for account.
*/ */
setPassword(password: string): void { public setPassword(password: string): void {
this.password = password this.password = password
} }
@ -26,7 +26,7 @@ export default class Account extends OceanBase {
* Returns account password. * Returns account password.
* @return {string} Account password. * @return {string} Account password.
*/ */
getPassword(): string { public getPassword(): string {
return this.password return this.password
} }

View File

@ -69,7 +69,7 @@ export default class OceanAssets {
metadata.base.encryptedFiles = [ metadata.base.encryptedFiles = [
await SecretStoreProvider.getSecretStore() await SecretStoreProvider.getSecretStore()
.encryptDocument(did.getId(), metadata.base.contentUrls) .encryptDocument(did.getId(), metadata.base.contentUrls),
] ]
const template = new Access() const template = new Access()

View File

@ -48,7 +48,6 @@ export default class ServiceAgreement extends OceanBase {
Logger.log("Executing SA with serviceAgreementId", serviceAgreementId) Logger.log("Executing SA with serviceAgreementId", serviceAgreementId)
} }
const service: Service = ddo.findServiceById(serviceDefinitionId) const service: Service = ddo.findServiceById(serviceDefinitionId)
const values: ValuePair[][] = ServiceAgreement.getValuesFromService(service, serviceAgreementId) const values: ValuePair[][] = ServiceAgreement.getValuesFromService(service, serviceAgreementId)
const valueHashes: string[] = ServiceAgreement.createValueHashes(values) const valueHashes: string[] = ServiceAgreement.createValueHashes(values)
@ -64,10 +63,10 @@ export default class ServiceAgreement extends OceanBase {
private static async createSAHashSignature( private static async createSAHashSignature(
service: Service, service: Service,
serviceAgreementId: string, serviceAgreementId: string,
valueHashes: string[], valueHashes: string[],
timeoutValues: number[], timeoutValues: number[],
consumer: Account, consumer: Account,
): Promise<string> { ): Promise<string> {
if (!service.templateId) { if (!service.templateId) {

View File

@ -1,4 +1,4 @@
import Web3Provider from '../keeper/Web3Provider' import Web3Provider from "../keeper/Web3Provider"
import Logger from "./Logger" import Logger from "./Logger"
export async function signText(text: string, publicKey: string, password?: string): Promise<string> { export async function signText(text: string, publicKey: string, password?: string): Promise<string> {
@ -8,7 +8,7 @@ export async function signText(text: string, publicKey: string, password?: strin
return await web3.eth.personal.sign(text, publicKey, password) return await web3.eth.personal.sign(text, publicKey, password)
} catch (e) { } catch (e) {
Logger.error(e.message) Logger.error(e.message)
throw new Error('Error execution personal sign') throw new Error("Error execution personal sign")
} }
} }

View File

@ -41,7 +41,7 @@ describe("Aquarius", () => {
WebServiceConnectorProvider.setConnector(new WebServiceConnectorMock([new DDO()])) WebServiceConnectorProvider.setConnector(new WebServiceConnectorMock([new DDO()]))
const result: DDO[] = await aquarius.queryMetadata(query) const result: DDO[] = await aquarius.queryMetadata(query)
console.log(result)
assert(result) assert(result)
assert(result[0].findServiceById) assert(result[0].findServiceById)
}) })

View File

@ -1,15 +1,15 @@
import { assert, expect, use, spy } from "chai" import { assert, expect, spy, use } from "chai"
import * as spies from "chai-spies" import * as spies from "chai-spies"
import ConfigProvider from "../../src/ConfigProvider"
import { DDO } from "../../src/ddo/DDO" import { DDO } from "../../src/ddo/DDO"
import { Service } from "../../src/ddo/Service" import { Service } from "../../src/ddo/Service"
import ConfigProvider from "../../src/ConfigProvider"
import config from "../config"
import * as signatureHelpers from "../../src/utils/SignatureHelpers" import * as signatureHelpers from "../../src/utils/SignatureHelpers"
import config from "../config"
import * as jsonDDO from "../testdata/ddo.json" import * as jsonDDO from "../testdata/ddo.json"
use(spies); use(spies)
describe("DDO", () => { describe("DDO", () => {
@ -60,7 +60,7 @@ describe("DDO", () => {
type: "MessagingService", type: "MessagingService",
serviceEndpoint: "https://example.com/messages/8377464", serviceEndpoint: "https://example.com/messages/8377464",
}, },
<any>{ {
type: "SocialWebInboxService", type: "SocialWebInboxService",
serviceEndpoint: "https://social.example.com/83hfh37dj", serviceEndpoint: "https://social.example.com/83hfh37dj",
description: "My public social inbox", description: "My public social inbox",
@ -68,7 +68,7 @@ describe("DDO", () => {
amount: "0.50", amount: "0.50",
currency: "USD", currency: "USD",
}, },
}, } as any,
{ {
id: "did:op:123456789abcdefghi;bops", id: "did:op:123456789abcdefghi;bops",
type: "BopsService", type: "BopsService",
@ -126,18 +126,18 @@ describe("DDO", () => {
url: "234ab87234acbd09543085340abffh21983ddhiiee982143827423421", url: "234ab87234acbd09543085340abffh21983ddhiiee982143827423421",
checksum: "efb2c764274b745f5fc37f97c6b0e761", checksum: "efb2c764274b745f5fc37f97c6b0e761",
contentLength: "4535431", contentLength: "4535431",
resourceId: "access-log2018-02-13-15-17-29-18386C502CAEA932" resourceId: "access-log2018-02-13-15-17-29-18386C502CAEA932",
}, },
{ {
url: "234ab87234acbd6894237582309543085340abffh21983ddhiiee982143827423421", url: "234ab87234acbd6894237582309543085340abffh21983ddhiiee982143827423421",
checksum: "085340abffh21495345af97c6b0e761", checksum: "085340abffh21495345af97c6b0e761",
contentLength: "12324" contentLength: "12324",
}, },
{ {
url: "80684089027358963495379879a543085340abffh21983ddhiiee982143827abcc2" url: "80684089027358963495379879a543085340abffh21983ddhiiee982143827abcc2",
} },
], ],
checksum: "" checksum: "",
}, },
curation: { curation: {
rating: 0.93, rating: 0.93,
@ -200,7 +200,7 @@ describe("DDO", () => {
} }
const ddo = new DDO({ const ddo = new DDO({
service: [<any>service], service: [service as any],
}) })
assert(ddo) assert(ddo)
@ -217,7 +217,7 @@ describe("DDO", () => {
it("should properly deserialize from serialized object", async () => { it("should properly deserialize from serialized object", async () => {
const ddoString = DDO.serialize(testDDO) const ddoString = DDO.serialize(testDDO)
assert.typeOf(ddoString, 'string') assert.typeOf(ddoString, "string")
const ddo: DDO = DDO.deserialize(ddoString) const ddo: DDO = DDO.deserialize(ddoString)
assert.instanceOf(ddo, DDO) assert.instanceOf(ddo, DDO)
@ -247,18 +247,18 @@ describe("DDO", () => {
describe("#generateProof()", () => { describe("#generateProof()", () => {
const publicKey = `0x${'a'.repeat(40)}` const publicKey = `0x${"a".repeat(40)}`
const signature = `0x${'a'.repeat(130)}` const signature = `0x${"a".repeat(130)}`
it("should properly generate the proof", async () => { it("should properly generate the proof", async () => {
const signTextSpy = spy.on(signatureHelpers, 'signText', () => signature) const signTextSpy = spy.on(signatureHelpers, "signText", () => signature)
const ddo = new DDO(testDDO) const ddo = new DDO(testDDO)
const checksum = ddo.getChecksum() const checksum = ddo.getChecksum()
const proof = await ddo.generateProof(publicKey) const proof = await ddo.generateProof(publicKey)
assert.include(<any>proof, { assert.include(proof as any, {
creator: publicKey, creator: publicKey,
type: 'DDOIntegritySignature', type: "DDOIntegritySignature",
signatureValue: signature, signatureValue: signature,
}) })
expect(signTextSpy).to.have.been.called.with(checksum, publicKey) expect(signTextSpy).to.have.been.called.with(checksum, publicKey)
@ -267,17 +267,17 @@ describe("DDO", () => {
describe("#addProof()", () => { describe("#addProof()", () => {
const publicKey = `0x${'a'.repeat(40)}` const publicKey = `0x${"a".repeat(40)}`
it("should properly add the proof on the DDO", async () => { it("should properly add the proof on the DDO", async () => {
const fakeProof = <any>{ const fakeProof = {
creation: Date.now(), creation: Date.now(),
creator: 'test', creator: "test",
type: 'test', type: "test",
signaturValue: 'test' signaturValue: "test",
} } as any
const ddo = new DDO(testDDO) const ddo = new DDO(testDDO)
const generateProofSpy = spy.on(ddo, 'generateProof', () => fakeProof) const generateProofSpy = spy.on(ddo, "generateProof", () => fakeProof)
await ddo.addProof(publicKey) await ddo.addProof(publicKey)
assert.equal(ddo.proof, fakeProof) assert.equal(ddo.proof, fakeProof)

View File

@ -16,7 +16,6 @@ import TestContractHandler from "../keeper/TestContractHandler"
import WebServiceConnectorMock from "../mocks/WebServiceConnector.mock" import WebServiceConnectorMock from "../mocks/WebServiceConnector.mock"
import { metadataMock } from "../testdata/MetaData" import { metadataMock } from "../testdata/MetaData"
let ocean: Ocean let ocean: Ocean
let accounts: Account[] let accounts: Account[]
let publisherAccount: Account let publisherAccount: Account

View File

@ -7,9 +7,8 @@ import Access from "../../src/ocean/ServiceAgreements/Templates/Access"
import TemplateBase from "../../src/ocean/ServiceAgreements/Templates/TemplateBase" import TemplateBase from "../../src/ocean/ServiceAgreements/Templates/TemplateBase"
import config from "../config" import config from "../config"
import TestContractHandler from "../keeper/TestContractHandler" import TestContractHandler from "../keeper/TestContractHandler"
import TestIdGenerator from "../TestIdGenerator"
import { metadataMock } from "../testdata/MetaData" import { metadataMock } from "../testdata/MetaData"
import TestIdGenerator from "../TestIdGenerator"
let ocean: Ocean let ocean: Ocean
let accounts: Account[] let accounts: Account[]

View File

@ -35,7 +35,7 @@ export const metadataMock: MetaData = {
tags: "weather, uk, 2011, temperature, humidity", tags: "weather, uk, 2011, temperature, humidity",
price: 10, price: 10,
files: [], files: [],
checksum: "" checksum: "",
}, },
curation: { curation: {
rating: 0.93, rating: 0.93,
@ -54,5 +54,6 @@ export const metadataMock: MetaData = {
mediaType: "text/turtle", mediaType: "text/turtle",
}, },
], ],
checksum: "",
}, },
} }

View File

@ -1,18 +1,18 @@
import { assert, expect, use, spy } from "chai" import { assert, expect, spy, use } from "chai"
import * as spies from "chai-spies" import * as spies from "chai-spies"
import { signText, verifyText } from "../../src/utils/SignatureHelpers"
import Web3Provider from '../../src/keeper/Web3Provider'
import ConfigProvider from "../../src/ConfigProvider" import ConfigProvider from "../../src/ConfigProvider"
import Web3Provider from "../../src/keeper/Web3Provider"
import { signText, verifyText } from "../../src/utils/SignatureHelpers"
import config from "../config" import config from "../config"
use(spies); use(spies)
describe("SignatureHelpers", () => { describe("SignatureHelpers", () => {
const publicKey = `0x${'a'.repeat(40)}` const publicKey = `0x${"a".repeat(40)}`
const text = "0123456789abcde" const text = "0123456789abcde"
const signature = `0x${'a'.repeat(130)}` const signature = `0x${"a".repeat(130)}`
before(async () => { before(async () => {
ConfigProvider.setConfig(config) ConfigProvider.setConfig(config)
@ -26,7 +26,7 @@ describe("SignatureHelpers", () => {
beforeEach(() => { beforeEach(() => {
const web3 = Web3Provider.getWeb3() const web3 = Web3Provider.getWeb3()
personalSignSpy = spy.on(web3.eth.personal, 'sign', () => signature) personalSignSpy = spy.on(web3.eth.personal, "sign", () => signature)
}) })
it("should sign a text as expected", async () => { it("should sign a text as expected", async () => {
@ -37,17 +37,17 @@ describe("SignatureHelpers", () => {
}) })
it("should sign a text as expected using password", async () => { it("should sign a text as expected using password", async () => {
const signed = await signText(text, publicKey, 'test') const signed = await signText(text, publicKey, "test")
assert.equal(signed, signature) assert.equal(signed, signature)
expect(personalSignSpy).to.have.been.called.with(text, publicKey, 'test') expect(personalSignSpy).to.have.been.called.with(text, publicKey, "test")
}) })
}) })
describe("#verifyText", () => { describe("#verifyText", () => {
it("should recover the privateKey of a signed message", async () => { it("should recover the privateKey of a signed message", async () => {
const web3 = Web3Provider.getWeb3() const web3 = Web3Provider.getWeb3()
const personalRecoverSpy = spy.on(web3.eth.personal, 'ecRecover', () => publicKey) const personalRecoverSpy = spy.on(web3.eth.personal, "ecRecover", () => publicKey)
const verifiedPublicKey = await verifyText(text, signature) const verifiedPublicKey = await verifyText(text, signature)

View File

@ -6,6 +6,8 @@
"jsRules": {}, "jsRules": {},
"rules": { "rules": {
"object-literal-sort-keys": false, "object-literal-sort-keys": false,
"interface-name": [true, "never-prefix"],
"max-line-length": [true, 140],
"semicolon": [ "semicolon": [
true, true,
"never" "never"