diff --git a/src/brizo/Brizo.ts b/src/brizo/Brizo.ts index 23add94..be8265d 100644 --- a/src/brizo/Brizo.ts +++ b/src/brizo/Brizo.ts @@ -1,9 +1,9 @@ -import Config from "../models/Config" +import save = require("save-file") import { File } from "../ddo/MetaData" +import Config from "../models/Config" import Account from "../ocean/Account" +import Logger from "../utils/Logger" import WebServiceConnectorProvider from "../utils/WebServiceConnectorProvider" -import Logger from '../utils/Logger' -const { save } = require('save-file') const apiPath = "/api/v1/brizo/services" @@ -76,7 +76,7 @@ export default class Brizo { try { await this.downloadFile( consumeUrl, - url.split('/').pop() || `file-${i}`, + url.split("/").pop() || `file-${i}`, destination, ) } catch (e) { diff --git a/src/ddo/DDO.ts b/src/ddo/DDO.ts index 66a8f58..c2ef1aa 100644 --- a/src/ddo/DDO.ts +++ b/src/ddo/DDO.ts @@ -53,7 +53,6 @@ export class DDO { this.service = (ddo && ddo.service) || [] } - public shortId(): string { return this.id.replace("did:op:", "") } diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index 14f0d91..2cad4de 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -38,7 +38,7 @@ export default class Ocean { Logger.setLevel( typeof config.verbose !== "number" ? (config.verbose ? LogLevel.Log : LogLevel.None) - : config.verbose + : config.verbose as LogLevel, ) ConfigProvider.setConfig(config) diff --git a/src/ocean/OceanAccounts.ts b/src/ocean/OceanAccounts.ts index c289874..a1a64c6 100644 --- a/src/ocean/OceanAccounts.ts +++ b/src/ocean/OceanAccounts.ts @@ -56,7 +56,7 @@ export default class OceanAccounts { try { await account.requestTokens(amount) return true - } catch(e) { + } catch (e) { return false } } diff --git a/src/ocean/OceanAgreements.ts b/src/ocean/OceanAgreements.ts index 45b257b..9f2c885 100644 --- a/src/ocean/OceanAgreements.ts +++ b/src/ocean/OceanAgreements.ts @@ -1,7 +1,7 @@ import AquariusProvider from "../aquarius/AquariusProvider" import BrizoProvider from "../brizo/BrizoProvider" -import Account from "./Account" import { generateId } from "../utils/GeneratorHelpers" +import Account from "./Account" import DID from "./DID" import ServiceAgreement from "./ServiceAgreements/ServiceAgreement" diff --git a/src/ocean/OceanAssets.ts b/src/ocean/OceanAssets.ts index ae71b85..e76593f 100644 --- a/src/ocean/OceanAssets.ts +++ b/src/ocean/OceanAssets.ts @@ -6,16 +6,16 @@ import { Condition } from "../ddo/Condition" import { DDO } from "../ddo/DDO" import { MetaData } from "../ddo/MetaData" import { Service, ServiceAuthorization } from "../ddo/Service" +import EventListener from "../keeper/EventListener" import Keeper from "../keeper/Keeper" import SecretStoreProvider from "../secretstore/SecretStoreProvider" +import Logger from "../utils/Logger" import Account from "./Account" import DID from "./DID" import OceanAgreements from "./OceanAgreements" +import ServiceAgreement from "./ServiceAgreements/ServiceAgreement" import ServiceAgreementTemplate from "./ServiceAgreements/ServiceAgreementTemplate" import Access from "./ServiceAgreements/Templates/Access" -import EventListener from "../keeper/EventListener" -import ServiceAgreement from "./ServiceAgreements/ServiceAgreement" -import Logger from '../utils/Logger' /** * Assets submodule of Ocean Protocol. @@ -128,7 +128,7 @@ export default class OceanAssets { }, { type: "Authorization", - services: 'SecretStore', + services: "SecretStore", serviceEndpoint: secretStoreUri, serviceDefinitionId: String(serviceDefinitionIdCount++), }, @@ -181,9 +181,10 @@ export default class OceanAssets { return storedDdo } - public async consume (agreementId: string, did: string, serviceDefinitionId: string, consumerAccount: Account, resultPath: string): Promise - public async consume (agreementId: string, did: string, serviceDefinitionId: string, consumerAccount: Account): Promise - public async consume ( + // tslint:disable-next-line + public async consume(agreementId: string, did: string, serviceDefinitionId: string, consumerAccount: Account, resultPath: string): Promise + public async consume(agreementId: string, did: string, serviceDefinitionId: string, consumerAccount: Account): Promise + public async consume( agreementId: string, did: string, serviceDefinitionId: string, @@ -193,9 +194,9 @@ export default class OceanAssets { const brizo = BrizoProvider.getBrizo() const ddo = await this.resolve(did) - const {metadata} = ddo.findServiceByType('Metadata') + const {metadata} = ddo.findServiceByType("Metadata") - const authorizationService = ddo.findServiceByType('Authorization') + const authorizationService = ddo.findServiceByType("Authorization") const accessService = ddo.findServiceById(serviceDefinitionId) const files = metadata.base.encryptedFiles @@ -203,7 +204,7 @@ export default class OceanAssets { const {serviceEndpoint} = accessService if (!serviceEndpoint) { - throw new Error('Consume asset failed, service definition is missing the `serviceEndpoint`.') + throw new Error("Consume asset failed, service definition is missing the `serviceEndpoint`.") } const secretStoreUrl = authorizationService.service === "SecretStore" && authorizationService.serviceEndpoint diff --git a/src/ocean/OceanTokens.ts b/src/ocean/OceanTokens.ts index 8c23435..049b978 100644 --- a/src/ocean/OceanTokens.ts +++ b/src/ocean/OceanTokens.ts @@ -47,7 +47,7 @@ export default class OceanTokens { try { await account.requestTokens(amount) return true - } catch(e) { + } catch (e) { return false } } diff --git a/src/ocean/ServiceAgreements/ServiceAgreement.ts b/src/ocean/ServiceAgreements/ServiceAgreement.ts index 0a43e14..21f40e0 100644 --- a/src/ocean/ServiceAgreements/ServiceAgreement.ts +++ b/src/ocean/ServiceAgreements/ServiceAgreement.ts @@ -26,7 +26,13 @@ export default class ServiceAgreement extends OceanBase { const valueHashes: string[] = ServiceAgreement.createValueHashes(values) const timeoutValues: number[] = ServiceAgreement.getTimeoutValuesFromService(service) - const serviceAgreementHashSignature = await ServiceAgreement.createSAHashSignature(service, serviceAgreementId, valueHashes, timeoutValues, consumer) + const serviceAgreementHashSignature = await ServiceAgreement.createSAHashSignature( + service, + serviceAgreementId, + valueHashes, + timeoutValues, + consumer, + ) Logger.log("SA hash signature:", serviceAgreementHashSignature) diff --git a/src/secretstore/SecretStoreProvider.ts b/src/secretstore/SecretStoreProvider.ts index b195021..d7ef684 100644 --- a/src/secretstore/SecretStoreProvider.ts +++ b/src/secretstore/SecretStoreProvider.ts @@ -14,7 +14,7 @@ export default class SecretStoreProvider { config = {...config} // Cleaning undefined parameters Object.keys(config) - .forEach(key => config[key] || delete config[key]) + .forEach((key) => config[key] || delete config[key]) if (!Object.keys(config).length) { if (!SecretStoreProvider.secretStore) { diff --git a/src/utils/GeneratorHelpers.ts b/src/utils/GeneratorHelpers.ts index cd92f8c..39ca490 100644 --- a/src/utils/GeneratorHelpers.ts +++ b/src/utils/GeneratorHelpers.ts @@ -1,8 +1,8 @@ import {v4} from "uuid" export function generateId(length = 64) { - let id = '' - while(id.length < length) { + let id = "" + while (id.length < length) { id += v4().replace(/-/g, "") } return id.substr(0, length) diff --git a/src/utils/Logger.ts b/src/utils/Logger.ts index 1c78d4b..e8c4531 100644 --- a/src/utils/Logger.ts +++ b/src/utils/Logger.ts @@ -7,7 +7,6 @@ export enum LogLevel { } export default class Logger { - private static logLevel: LogLevel = LogLevel.Verbose public static setLevel(level: LogLevel) { this.logLevel = level @@ -28,6 +27,7 @@ export default class Logger { public static error(...args: any[]) { Logger.dispatch("error", LogLevel.Error, ...args) } + private static logLevel: LogLevel = LogLevel.Verbose private static dispatch(verb: string, level: LogLevel, ...args: any[]) { if (this.logLevel >= level) { diff --git a/test/keeper/DIDRegistry.test.ts b/test/keeper/DIDRegistry.test.ts index 5244cf8..b0cb92f 100644 --- a/test/keeper/DIDRegistry.test.ts +++ b/test/keeper/DIDRegistry.test.ts @@ -2,8 +2,8 @@ import {assert} from "chai" import ConfigProvider from "../../src/ConfigProvider" import DIDRegistry from "../../src/keeper/contracts/DIDRegistry" import Account from "../../src/ocean/Account" -import { generateId } from "../../src/utils/GeneratorHelpers" import Ocean from "../../src/ocean/Ocean" +import { generateId } from "../../src/utils/GeneratorHelpers" import Logger from "../../src/utils/Logger" import config from "../config" import TestContractHandler from "./TestContractHandler" diff --git a/test/ocean/OceanAccounts.test.ts b/test/ocean/OceanAccounts.test.ts index 0b78be1..ddd0081 100644 --- a/test/ocean/OceanAccounts.test.ts +++ b/test/ocean/OceanAccounts.test.ts @@ -20,9 +20,9 @@ describe("OceanAccounts", () => { describe("#getInstance()", () => { it("should get an instance of OceanAccounts", async () => { - const oceanAccounts: OceanAccounts = await OceanAccounts.getInstance() + const oceanAccountsInstance: OceanAccounts = await OceanAccounts.getInstance() - assert.instanceOf(oceanAccounts, OceanAccounts, "No returned OceanAccounts instance") + assert.instanceOf(oceanAccountsInstance, OceanAccounts, "No returned OceanAccounts instance") }) }) @@ -30,14 +30,14 @@ describe("OceanAccounts", () => { it("should return the list of accounts", async () => { const accounts = await oceanAccounts.list() - accounts.map(account => assert.instanceOf(account, Account)) + accounts.map((account) => assert.instanceOf(account, Account)) }) }) describe("#balance()", () => { it("should return the balance of an account", async () => { const [account] = await oceanAccounts.list() - spy.on(account, 'getBalance', () => ({eth: 1, ocn: 5})) + spy.on(account, "getBalance", () => ({eth: 1, ocn: 5})) const balance = await oceanAccounts.balance(account) assert.deepEqual(balance, {eth: 1, ocn: 5}) @@ -47,7 +47,7 @@ describe("OceanAccounts", () => { describe("#requestTokens()", () => { it("should return the balance of an account", async () => { const [account] = await oceanAccounts.list() - spy.on(account, 'requestTokens', () => 10) + spy.on(account, "requestTokens", () => 10) const success = await oceanAccounts.requestTokens(account, 10) assert.isTrue(success) diff --git a/test/ocean/OceanSecretStore.test.ts b/test/ocean/OceanSecretStore.test.ts index b9a2c3e..5b32ed0 100644 --- a/test/ocean/OceanSecretStore.test.ts +++ b/test/ocean/OceanSecretStore.test.ts @@ -31,9 +31,9 @@ describe("OceanSecretStore", () => { describe("#getInstance()", () => { it("should get an instance of OceanSecretStore", async () => { - const oceanSecretStore: OceanSecretStore = await OceanSecretStore.getInstance() + const oceanSecretStoreInstance: OceanSecretStore = await OceanSecretStore.getInstance() - assert.instanceOf(oceanSecretStore, OceanSecretStore, "No returned OceanSecretStore instance") + assert.instanceOf(oceanSecretStoreInstance, OceanSecretStore, "No returned OceanSecretStore instance") }) }) diff --git a/test/ocean/ServiceAgreement.test.ts b/test/ocean/ServiceAgreement.test.ts index 0e3aae6..706166b 100644 --- a/test/ocean/ServiceAgreement.test.ts +++ b/test/ocean/ServiceAgreement.test.ts @@ -5,11 +5,11 @@ import { DDO } from "../../src/ddo/DDO" import { Service } from "../../src/ddo/Service" import Account from "../../src/ocean/Account" import DID from "../../src/ocean/DID" -import { generateId } from "../../src/utils/GeneratorHelpers" import Ocean from "../../src/ocean/Ocean" import ServiceAgreement from "../../src/ocean/ServiceAgreements/ServiceAgreement" import ServiceAgreementTemplate from "../../src/ocean/ServiceAgreements/ServiceAgreementTemplate" import Access from "../../src/ocean/ServiceAgreements/Templates/Access" +import { generateId } from "../../src/utils/GeneratorHelpers" import WebServiceConnectorProvider from "../../src/utils/WebServiceConnectorProvider" import config from "../config" import TestContractHandler from "../keeper/TestContractHandler" @@ -164,7 +164,7 @@ describe("ServiceAgreement", () => { try { // Allowing 1 more retry await consumerAccount.requestTokens(metaDataService.metadata.base.price) - } catch(e) { + } catch (e) { await consumerAccount.requestTokens(metaDataService.metadata.base.price) }