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 {
public type: string
public publicKey: string
type: string
publicKey: string
}

View File

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

View File

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

View File

@ -17,7 +17,7 @@ export class MetaDataBase {
* @type {string}
* @example "UK Weather information 2011"
*/
name: string
public name: string
/**
* Type of the Asset. Helps to filter by the type of asset,
@ -25,7 +25,7 @@ export class MetaDataBase {
* @type {string}
* @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
@ -33,28 +33,28 @@ export class MetaDataBase {
* @type {string}
* @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.
* @type {string}
* @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.
* @type {string}
* @example "3.1gb"
*/
size: string
public size: string
/**
* Name of the entity generating this data (e.g. Tfl, Disney Corp, etc.).
* @type {string}
* @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. ).
@ -62,35 +62,35 @@ export class MetaDataBase {
* @type {string}
* @example "CC-BY"
*/
license: string
public license: string
/**
* The party holding the legal copyright. Empty by default.
* @type {string}
* @example "Met Office"
*/
copyrightHolder?: string
public copyrightHolder?: string
/**
* File encoding.
* @type {string}
* @example "UTF-8"
*/
encoding?: string
public encoding?: string
/**
* File compression (e.g. no, gzip, bzip2, etc).
* @type {string}
* @example "zip"
*/
compression?: string
public compression?: string
/**
* File format, if applicable.
* @type {string}
* @example "text/csv"
*/
contentType: string
public contentType: string
/**
* Example of the concept of this asset. This example is part
@ -98,14 +98,14 @@ export class MetaDataBase {
* @type {string}
* @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.
* @type {string | string[]}
* @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.
@ -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
@ -132,7 +132,7 @@ export class MetaDataBase {
* @type {String}
* @example "en"
*/
inLanguage?: string
public inLanguage?: string
/**
* Keywords or tags used to describe this content. Multiple entries in a keyword
@ -140,28 +140,28 @@ export class MetaDataBase {
* @type {String}
* @example "weather, uk, 2011, temperature, humidity"
*/
tags?: string
public tags?: string
/**
* Price of the asset.
* @type {String}
* @example 10
*/
price: number
public price: number
/**
* Array of File objects including the encrypted file urls and some additional information.
* @type {File[]}
*/
files: File[]
public files: File[]
/**
* SHA3 hash of concatenated values: [list of all file checksums] + name + author + license + did
* @type {string}
*/
checksum: string
public checksum: string
encryptedFiles?: any
public encryptedFiles?: any
}
/**
@ -210,10 +210,10 @@ export interface AdditionalInformation {
* describing the dataset.
* @type {StructuredMarkup[]}
*/
structuredMarkup: {
structuredMarkup: Array<{
uri: string
mediaType: string
}[]
mediaType: string,
}>
/**
* 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 {string}
*/
type: 'Ed25519VerificationKey2018' | 'RsaVerificationKey2018' | 'EdDsaSAPublicKeySecp256k1'
type: "Ed25519VerificationKey2018" | "RsaVerificationKey2018" | "EdDsaSAPublicKeySecp256k1"
/**
* Key owner.

View File

@ -10,10 +10,10 @@ async function exec() {
const ocean: Ocean = await Ocean.getInstance(config)
const publisher: Account = (await ocean.getAccounts())[0]
publisher.setPassword('node0')
publisher.setPassword("node0")
const consumer: Account = (await ocean.getAccounts())[1]
const metaData: Partial<MetaData> = <any>{
const metaData: Partial<MetaData> = <any> {
base: {
name: "Office Humidity",
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)
const did: DID = DID.parse(ddo.id)

View File

@ -9,10 +9,10 @@ async function exec() {
const ocean: Ocean = await Ocean.getInstance(config)
const publisher: Account = (await ocean.getAccounts())[0]
publisher.setPassword('node0')
publisher.setPassword("node0")
const consumer: Account = (await ocean.getAccounts())[1]
const metaData: Partial<MetaData> = <any>{
const metaData: Partial<MetaData> = <any> {
base: {
name: "Office Humidity",
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)
const accessService = ddo.findServiceByType("Access")

View File

@ -10,10 +10,10 @@ async function exec() {
const ocean: Ocean = await Ocean.getInstance(config)
const publisher: Account = (await ocean.getAccounts())[0]
publisher.setPassword('node0')
publisher.setPassword("node0")
const consumer: Account = (await ocean.getAccounts())[1]
const metaData: Partial<MetaData> = <any>{
const metaData: Partial<MetaData> = <any> {
base: {
name: "Office Humidity",
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)
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)
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}`)
}

View File

@ -11,7 +11,7 @@ async function exec() {
const publisher: Account = (await ocean.getAccounts())[1]
const consumer: Account = (await ocean.getAccounts())[1]
const metaData: Partial<MetaData> = <any>{
const metaData: Partial<MetaData> = <any> {
base: {
name: "Office Humidity",
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)
const accessService = ddo.findServiceByType("Access")

View File

@ -8,9 +8,9 @@ async function exec() {
const ocean: Ocean = await Ocean.getInstance(config)
const publisher: Account = (await ocean.getAccounts())[0]
publisher.setPassword('node0')
publisher.setPassword("node0")
const metaData: Partial<MetaData> = <any>{
const metaData: Partial<MetaData> = <any> {
base: {
name: "Office Humidity",
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)
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -16,7 +16,6 @@ import TestContractHandler from "../keeper/TestContractHandler"
import WebServiceConnectorMock from "../mocks/WebServiceConnector.mock"
import { metadataMock } from "../testdata/MetaData"
let ocean: Ocean
let accounts: 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 config from "../config"
import TestContractHandler from "../keeper/TestContractHandler"
import TestIdGenerator from "../TestIdGenerator"
import { metadataMock } from "../testdata/MetaData"
import TestIdGenerator from "../TestIdGenerator"
let ocean: Ocean
let accounts: Account[]

View File

@ -35,7 +35,7 @@ export const metadataMock: MetaData = {
tags: "weather, uk, 2011, temperature, humidity",
price: 10,
files: [],
checksum: ""
checksum: "",
},
curation: {
rating: 0.93,
@ -54,5 +54,6 @@ export const metadataMock: MetaData = {
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 { signText, verifyText } from "../../src/utils/SignatureHelpers"
import Web3Provider from '../../src/keeper/Web3Provider'
import ConfigProvider from "../../src/ConfigProvider"
import Web3Provider from "../../src/keeper/Web3Provider"
import { signText, verifyText } from "../../src/utils/SignatureHelpers"
import config from "../config"
use(spies);
use(spies)
describe("SignatureHelpers", () => {
const publicKey = `0x${'a'.repeat(40)}`
const publicKey = `0x${"a".repeat(40)}`
const text = "0123456789abcde"
const signature = `0x${'a'.repeat(130)}`
const signature = `0x${"a".repeat(130)}`
before(async () => {
ConfigProvider.setConfig(config)
@ -26,7 +26,7 @@ describe("SignatureHelpers", () => {
beforeEach(() => {
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 () => {
@ -37,17 +37,17 @@ describe("SignatureHelpers", () => {
})
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)
expect(personalSignSpy).to.have.been.called.with(text, publicKey, 'test')
expect(personalSignSpy).to.have.been.called.with(text, publicKey, "test")
})
})
describe("#verifyText", () => {
it("should recover the privateKey of a signed message", async () => {
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)

View File

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