From 725b60db521ff02227f0608c2babc7449c640263 Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Tue, 26 May 2020 11:38:00 +0300 Subject: [PATCH 01/17] Delete add-vendors-plugin.js --- plugins/add-vendors-plugin.js | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 plugins/add-vendors-plugin.js diff --git a/plugins/add-vendors-plugin.js b/plugins/add-vendors-plugin.js deleted file mode 100644 index be75bcd5..00000000 --- a/plugins/add-vendors-plugin.js +++ /dev/null @@ -1,31 +0,0 @@ -const { ConcatSource } = require('webpack-sources') - -module.exports = class AddVendorsPlugin { - constructor(base) { - this.base = base - } - - apply(compiler) { - compiler.hooks.emit.tapAsync( - `AddVendorsPlugin ${this.base}`, - (compilation, callback) => { - const main = compilation.assets[`main.${this.base}`] - const mainMap = compilation.assets[`main.${this.base}.map`] - const vendor = compilation.assets[`vendors.${this.base}`] - - if (main && vendor) { - const compiledAsset = new ConcatSource(main.children[0]) - compiledAsset.add(vendor) - compiledAsset.add(main.children[1]) - compilation.assets = {} - compilation.assets[this.base] = compiledAsset - } else if (main && mainMap) { - compilation.assets = {} - compilation.assets[this.base] = main - compilation.assets[`${this.base}.map`] = mainMap - } - callback() - } - ) - } -} From a531c0040fe3963798154670e9788d2f300ef032 Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Tue, 26 May 2020 11:39:55 +0300 Subject: [PATCH 02/17] Delete AccessStatus.ts --- src/models/AccessStatus.ts | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 src/models/AccessStatus.ts diff --git a/src/models/AccessStatus.ts b/src/models/AccessStatus.ts deleted file mode 100644 index a42f4da2..00000000 --- a/src/models/AccessStatus.ts +++ /dev/null @@ -1,9 +0,0 @@ -enum AccessStatus { - Requested, - Committed, - Delivered, - Verified, - Revoked -} - -export default AccessStatus From 8adda9cf2453472bb9a41c8839ac8b11f5718ab6 Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Tue, 26 May 2020 11:40:06 +0300 Subject: [PATCH 03/17] Delete Balance.ts --- src/models/Balance.ts | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 src/models/Balance.ts diff --git a/src/models/Balance.ts b/src/models/Balance.ts deleted file mode 100644 index f3a67aaa..00000000 --- a/src/models/Balance.ts +++ /dev/null @@ -1,5 +0,0 @@ -export default class Balance { - public eth: number - - public ocn: number -} From 8d9beece48eeffd90eeecb67a5a4e4943ea0a65c Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Tue, 26 May 2020 11:40:45 +0300 Subject: [PATCH 04/17] Delete InputType.ts --- src/models/InputType.ts | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 src/models/InputType.ts diff --git a/src/models/InputType.ts b/src/models/InputType.ts deleted file mode 100644 index 04bb103a..00000000 --- a/src/models/InputType.ts +++ /dev/null @@ -1,5 +0,0 @@ -export default class InputType { - public name: string - - public type: string -} From bab0f2e8a1dac57ee5ee33d18a076d8e7630a1fb Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Tue, 26 May 2020 11:40:52 +0300 Subject: [PATCH 05/17] Delete MethodReflection.ts --- src/models/MethodReflection.ts | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 src/models/MethodReflection.ts diff --git a/src/models/MethodReflection.ts b/src/models/MethodReflection.ts deleted file mode 100644 index 58bd4886..00000000 --- a/src/models/MethodReflection.ts +++ /dev/null @@ -1,13 +0,0 @@ -import InputType from './InputType' - -export default class MethodReflection { - public contractName: string - - public methodName: string - - public address: string - - public signature: string - - public inputs: InputType[] -} From 057234744a110e97e561a0feb78a36629185a0a8 Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Tue, 26 May 2020 11:41:11 +0300 Subject: [PATCH 06/17] Delete ValuePair.ts --- src/models/ValuePair.ts | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 src/models/ValuePair.ts diff --git a/src/models/ValuePair.ts b/src/models/ValuePair.ts deleted file mode 100644 index cd69d5b3..00000000 --- a/src/models/ValuePair.ts +++ /dev/null @@ -1,5 +0,0 @@ -export default class ValuePair { - public type: string - - public value: any -} From fcd1b8718822db52d11635be882ff176fad9626f Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Tue, 26 May 2020 11:41:25 +0300 Subject: [PATCH 07/17] Delete ValueType.ts --- src/models/ValueType.ts | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 src/models/ValueType.ts diff --git a/src/models/ValueType.ts b/src/models/ValueType.ts deleted file mode 100644 index 42b85d64..00000000 --- a/src/models/ValueType.ts +++ /dev/null @@ -1,8 +0,0 @@ -enum ValueType { - DID, // DID string e.g. 'did:op:xxx' - DIDRef, // hash of DID same as in parameter (bytes32 _did) in text 0x0123abc.. or 0123abc.. - URL, // URL string e.g. 'http(s)://xx' - DDO // DDO string in JSON e.g. '{ "id": "did:op:xxx"... -} - -export default ValueType From 260a4d9a9cae1e7784d100d56327fa0ce6716308 Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Tue, 26 May 2020 11:51:04 +0300 Subject: [PATCH 08/17] Update Account.ts --- src/ocean/Account.ts | 54 +++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/src/ocean/Account.ts b/src/ocean/Account.ts index b33e4ec7..e7e3e991 100644 --- a/src/ocean/Account.ts +++ b/src/ocean/Account.ts @@ -42,6 +42,8 @@ export default class Account extends Instantiable { return this.password } + //TODO - Check with Samer if authentificate is still needed or we can use sign + /** * Set account token. * @param {string} token Token for account. @@ -73,13 +75,24 @@ export default class Account extends Instantiable { return this.ocean.auth.store(this) } + + + + /** * Balance of Ocean Token. * @return {Promise} */ - public async getOceanBalance(): Promise { - const { token } = this.ocean.keeper - return (await token.balanceOf(this.id)) / 10 ** (await token.decimals()) + public async getTokenBalance(TokenAdress:string): Promise { + //TO DO + } + + /** + * Symbol of a Token + * @return {Promise} + */ + public async getTokenSymbol(TokenAdress:string): Promise { + //TO DO } /** @@ -87,40 +100,25 @@ export default class Account extends Instantiable { * @return {Promise} */ public async getEtherBalance(): Promise { - return this.web3.eth + //TO DO + /*return this.web3.eth .getBalance(this.id, 'latest') .then((balance: string): number => { return new BigNumber(balance).toNumber() }) + } /** * Balances of Ether and Ocean Token. * @return {Promise} */ - public async getBalance(): Promise { - return { - eth: await this.getEtherBalance(), - ocn: await this.getOceanBalance() - } - } - - /** - * Request Ocean Tokens. - * @param {number} amount Tokens to be requested. - * @return {Promise} - */ - public async requestTokens(amount: number | string): Promise { - amount = String(amount) - if (!this.ocean.keeper.dispenser) { - throw new Error('Dispenser not available on this network.') - } - try { - await this.ocean.keeper.dispenser.requestTokens(amount, this.id) - } catch (e) { - this.logger.error(e) - throw new Error('Error requesting tokens') - } - return amount + public async getBalance(TokenAddress:string): Promise { + let symbol = await getTokenSymbol(TokenAddress) + let balance = [] + balance['eth'] = await this.getEtherBalance() + balance[symbol] = await this.getTokenBalance(TokenAdress) + return(balance) + } } From 38234a219520057c23ba6a4b153268d250243d67 Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Tue, 26 May 2020 11:54:04 +0300 Subject: [PATCH 09/17] Delete OceanAccounts.ts --- src/ocean/OceanAccounts.ts | 57 -------------------------------------- 1 file changed, 57 deletions(-) delete mode 100644 src/ocean/OceanAccounts.ts diff --git a/src/ocean/OceanAccounts.ts b/src/ocean/OceanAccounts.ts deleted file mode 100644 index e3465510..00000000 --- a/src/ocean/OceanAccounts.ts +++ /dev/null @@ -1,57 +0,0 @@ -import Balance from '../models/Balance' -import Account from './Account' -import { Instantiable, InstantiableConfig } from '../Instantiable.abstract' - -/** - * Account submodule of Ocean Protocol. - */ -export class OceanAccounts extends Instantiable { - /** - * Returns the instance of OceanAccounts. - * @return {Promise} - */ - public static async getInstance(config: InstantiableConfig): Promise { - const instance = new OceanAccounts() - instance.setInstanceConfig(config) - - return instance - } - - /** - * Returns the list of accounts. - * @return {Promise} - */ - public async list(): Promise { - // retrieve eth accounts - const ethAccounts: string[] = await this.web3.eth.getAccounts() - - const accountPromises = ethAccounts.map( - address => new Account(address, this.instanceConfig) - ) - return Promise.all(accountPromises) - } - - /** - * Return account balance. - * @param {Account} account Account instance. - * @return {Promise} Ether and Ocean Token balance. - */ - public balance(account: Account): Promise { - return account.getBalance() - } - - /** - * Request tokens for an account. - * @param {Account} account Account instance. - * @param {number} amount Token amount. - * @return {Promise} Success. - */ - public async requestTokens(account: Account, amount: number): Promise { - try { - await account.requestTokens(amount) - return true - } catch (e) { - return false - } - } -} From 4a727c6466c6ee589cf99c66112fe62da9277bec Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Tue, 26 May 2020 11:54:43 +0300 Subject: [PATCH 10/17] Rename OceanAssets.ts to Assets.ts --- src/ocean/{OceanAssets.ts => Assets.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/ocean/{OceanAssets.ts => Assets.ts} (100%) diff --git a/src/ocean/OceanAssets.ts b/src/ocean/Assets.ts similarity index 100% rename from src/ocean/OceanAssets.ts rename to src/ocean/Assets.ts From b54b21224887cd78b79674cc10f5849423229703 Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Tue, 26 May 2020 11:55:00 +0300 Subject: [PATCH 11/17] Update Ocean.ts --- src/ocean/Ocean.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index 2dd6a47a..9124a27d 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -1,6 +1,6 @@ import { OceanAccounts } from './OceanAccounts' -import { OceanAssets } from './OceanAssets' +import { Assets } from './Assets' import { OceanAuth } from './OceanAuth' import { OceanCompute } from './OceanCompute' From 6e0d298267cca29c1993079cebd0d478b5662d32 Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Tue, 26 May 2020 11:57:00 +0300 Subject: [PATCH 12/17] Delete OceanTokens.ts --- src/ocean/OceanTokens.ts | 45 ---------------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 src/ocean/OceanTokens.ts diff --git a/src/ocean/OceanTokens.ts b/src/ocean/OceanTokens.ts deleted file mode 100644 index b5bb4326..00000000 --- a/src/ocean/OceanTokens.ts +++ /dev/null @@ -1,45 +0,0 @@ -import Account from './Account' -import { Instantiable, InstantiableConfig } from '../Instantiable.abstract' - -/** - * Tokens submodule of Ocean Protocol. - */ -export class OceanTokens extends Instantiable { - /** - * Returns the instance of OceanTokens. - * @return {Promise} - */ - public static async getInstance(config: InstantiableConfig): Promise { - const instance = new OceanTokens() - instance.setInstanceConfig(config) - - return instance - } - - /** - * Transfer a number of tokens to the mentioned account. - * @param {string} to Address that receives the tokens. - * @param {number} amount Tokens to transfer. - * @param {Account} from Sender account address. - * @return {Promise} Success, - */ - public async transfer(to: string, amount: number, from: Account): Promise { - this.ocean.keeper.token.transfer(to, amount, from.getId()) - return true - } - - /** - * Request tokens for an account. - * @param {Account} account Account instance. - * @param {number} amount Token amount. - * @return {Promise} Success. - */ - public async request(account: Account, amount: number): Promise { - try { - await account.requestTokens(amount) - return true - } catch (e) { - return false - } - } -} From d47f09f4c57bce526a26056cb68b1a4e41714485 Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Tue, 26 May 2020 11:59:21 +0300 Subject: [PATCH 13/17] Delete OceanUtils.ts --- src/ocean/utils/OceanUtils.ts | 55 ----------------------------------- 1 file changed, 55 deletions(-) delete mode 100644 src/ocean/utils/OceanUtils.ts diff --git a/src/ocean/utils/OceanUtils.ts b/src/ocean/utils/OceanUtils.ts deleted file mode 100644 index 5fda8426..00000000 --- a/src/ocean/utils/OceanUtils.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { Instantiable, InstantiableConfig } from '../../Instantiable.abstract' - -import { ServiceUtils } from './ServiceUtils' -import { ServiceAgreement } from './ServiceAgreement' -import { SignatureUtils } from './SignatureUtils' -import { WebServiceConnector } from './WebServiceConnector' - -/** - * Utils internal submodule of Ocean Protocol. - */ -export class OceanUtils extends Instantiable { - /** - * Returns the instance of OceanUtils. - * @return {Promise} - */ - public static async getInstance(config: InstantiableConfig): Promise { - const instance = new OceanUtils() - instance.setInstanceConfig(config) - - instance.agreements = new ServiceAgreement( - config.ocean, - config.logger, - config.web3 - ) - instance.services = new ServiceUtils(config.ocean, config.logger) - instance.signature = new SignatureUtils(config.web3, config.logger) - instance.fetch = new WebServiceConnector(config.logger) - - return instance - } - - /** - * Agreement utils. - * @type {ServiceAgreement} - */ - public agreements: ServiceAgreement - - /** - * Service utils. - * @type {ServiceUtils} - */ - public services: ServiceUtils - - /** - * Signature utils. - * @type {SignatureUtils} - */ - public signature: SignatureUtils - - /** - * Fetch utils. - * @type {WebServiceConnector} - */ - public fetch: WebServiceConnector -} From 271f451d1daf112a324e747203a5570e396529f9 Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Tue, 26 May 2020 11:59:27 +0300 Subject: [PATCH 14/17] Delete ServiceAgreement.ts --- src/ocean/utils/ServiceAgreement.ts | 104 ---------------------------- 1 file changed, 104 deletions(-) delete mode 100644 src/ocean/utils/ServiceAgreement.ts diff --git a/src/ocean/utils/ServiceAgreement.ts b/src/ocean/utils/ServiceAgreement.ts deleted file mode 100644 index 55995e19..00000000 --- a/src/ocean/utils/ServiceAgreement.ts +++ /dev/null @@ -1,104 +0,0 @@ -import { ServiceAgreementTemplateCondition } from '../../ddo/ServiceAgreementTemplate' -import { DDO } from '../../ddo/DDO' -import { ServiceAccess } from '../../ddo/Service' -import Account from '../Account' -import { zeroX, Logger } from '../../utils' -import { Ocean } from '../../squid' -import Web3 from 'web3' - -export class ServiceAgreement { - private ocean: Ocean - private logger: Logger - private web3: Web3 - constructor(ocean: Ocean, logger: Logger, web3: Web3) { - this.ocean = ocean - this.logger = logger - this.web3 = web3 - } - - public async signServiceAgreement( - ddo: DDO, - index: number, - serviceAgreementId: string, - agreementConditionsIds: string[], - consumer: Account - ): Promise { - const service = ddo.findServiceById<'access'>(index) - const timelockValues: number[] = this.getTimeValuesFromService( - service, - 'timelock' - ) - const timeoutValues: number[] = this.getTimeValuesFromService(service, 'timeout') - - if (!service.templateId) { - throw new Error('TemplateId not found in DDO.') - } - - const serviceAgreementHashSignature = await this.createHashSignature( - service.templateId, - serviceAgreementId, - agreementConditionsIds, - timelockValues, - timeoutValues, - consumer - ) - - this.logger.debug('SA hash signature:', serviceAgreementHashSignature) - - return zeroX(serviceAgreementHashSignature) - } - - public async createHashSignature( - templateId: string, - serviceAgreementId: string, - valueHashes: string[], - timelockValues: number[], - timeoutValues: number[], - consumer: Account - ): Promise { - const serviceAgreementHash = this.hashServiceAgreement( - templateId, - serviceAgreementId, - valueHashes, - timelockValues, - timeoutValues - ) - - const serviceAgreementHashSignature = await this.ocean.utils.signature.signText( - serviceAgreementHash, - consumer.getId(), - consumer.getPassword() - ) - - return serviceAgreementHashSignature - } - - public hashServiceAgreement( - serviceAgreementTemplateId: string, - serviceAgreementId: string, - valueHashes: string[], - timelocks: number[], - timeouts: number[] - ): string { - const args: any = [ - { type: 'bytes32', value: zeroX(serviceAgreementTemplateId) }, - { type: 'bytes32[]', value: valueHashes.map(zeroX) }, - { type: 'uint256[]', value: timelocks }, - { type: 'uint256[]', value: timeouts }, - { type: 'bytes32', value: zeroX(serviceAgreementId) } - ] - - return this.web3.utils.soliditySha3(...args) - } - - private getTimeValuesFromService( - service: ServiceAccess, - type: 'timeout' | 'timelock' - ): number[] { - const timeoutValues: number[] = service.attributes.serviceAgreementTemplate.conditions.map( - (condition: ServiceAgreementTemplateCondition) => condition[type] - ) - - return timeoutValues - } -} From 83fa8a704d70b3c9955392c30ae3cc336601d878 Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Tue, 26 May 2020 11:59:45 +0300 Subject: [PATCH 15/17] Delete ServiceUtils.ts --- src/ocean/utils/ServiceUtils.ts | 115 -------------------------------- 1 file changed, 115 deletions(-) delete mode 100644 src/ocean/utils/ServiceUtils.ts diff --git a/src/ocean/utils/ServiceUtils.ts b/src/ocean/utils/ServiceUtils.ts deleted file mode 100644 index f4997577..00000000 --- a/src/ocean/utils/ServiceUtils.ts +++ /dev/null @@ -1,115 +0,0 @@ -import { DDO } from '../../ddo/DDO' -import Account from '../Account' -import { zeroX, Logger, generateId } from '../../utils' -import { Ocean } from '../../squid' -import { Condition } from '../../keeper/contracts/conditions' -import { ServiceType, Service } from '../../ddo/Service' - -export enum OrderProgressStep { - CreatingAgreement, - AgreementInitialized, - LockingPayment, - LockedPayment -} - -export class ServiceUtils { - private ocean: Ocean - private logger: Logger - - constructor(ocean: Ocean, logger: Logger) { - this.ocean = ocean - this.logger = logger - } - - public async order( - type: ServiceType, - condition: Condition, - observer: any, - consumerAccount: Account, - ddo: DDO, - provider?: string - ): Promise { - const { keeper, agreements } = this.ocean - - const agreementId = zeroX(generateId()) - const service: Service = ddo.findServiceByType(type) - const metadata = ddo.findServiceByType('metadata') - - const templateName = service.attributes.serviceAgreementTemplate.contractName - const template = keeper.getTemplateByName(templateName) - - // use price from compute service, - // otherwise always take the price from metadata - const price = - type === 'compute' - ? service.attributes.main.price - : metadata.attributes.main.price - - // eslint-disable-next-line no-async-promise-executor - const paymentFlow = new Promise(async (resolve, reject) => { - await template.getAgreementCreatedEvent(agreementId).once() - - this.logger.log('Agreement initialized') - observer.next(OrderProgressStep.AgreementInitialized) - - this.logger.log('Locking payment') - - const serviceGranted = condition - .getConditionFulfilledEvent(agreementId) - .once() - - observer.next(OrderProgressStep.LockingPayment) - const paid = await agreements.conditions.lockReward( - agreementId, - price, - consumerAccount - ) - observer.next(OrderProgressStep.LockedPayment) - - if (paid) { - this.logger.log('Payment was OK') - } else { - this.logger.error('Payment was KO') - this.logger.error('Agreement ID: ', agreementId) - this.logger.error('DID: ', ddo.id) - reject(new Error('Error on payment')) - } - - await serviceGranted - - this.logger.log(`Service ${type} granted`) - resolve() - }) - - observer.next(OrderProgressStep.CreatingAgreement) - this.logger.log('Creating agreement') - - // Get provider from didRegistry if not given in arguments - let _provider = provider - if (!provider) { - const providers = await keeper.didRegistry.getDIDProviders(ddo.shortId()) - if (providers) { - _provider = providers[0] - } - } - - await agreements.create( - ddo.id, - agreementId, - service.index, - undefined, - consumerAccount, - _provider, - consumerAccount - ) - this.logger.log('Agreement created') - - try { - await paymentFlow - } catch (e) { - throw new Error(`Error paying the ${type} service.`) - } - - return agreementId - } -} From 58ebd23b8f440112966d28cd83d06b10f85ccfae Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Tue, 26 May 2020 11:59:54 +0300 Subject: [PATCH 16/17] Delete SignatureUtils.ts --- src/ocean/utils/SignatureUtils.ts | 103 ------------------------------ 1 file changed, 103 deletions(-) delete mode 100644 src/ocean/utils/SignatureUtils.ts diff --git a/src/ocean/utils/SignatureUtils.ts b/src/ocean/utils/SignatureUtils.ts deleted file mode 100644 index 04cf97ed..00000000 --- a/src/ocean/utils/SignatureUtils.ts +++ /dev/null @@ -1,103 +0,0 @@ -import Web3 from 'web3' -import { Logger } from '../../utils' -import { Account } from '../../squid' - -export class SignatureUtils { - private web3: Web3 - private logger: Logger - - constructor(web3: Web3, logger: Logger) { - this.web3 = web3 - this.logger = logger - } - - public async signText( - text: string, - publicKey: string, - password?: string - ): Promise { - const isMetaMask = - this.web3 && - this.web3.currentProvider && - (this.web3.currentProvider as any).isMetaMask - try { - return await this.web3.eth.personal.sign(text, publicKey, password) - } catch (e) { - if (isMetaMask) { - throw e - } - this.logger.warn('Error on personal sign.') - this.logger.warn(e) - try { - return await this.web3.eth.sign(text, publicKey) - } catch (e2) { - this.logger.error('Error on sign.') - this.logger.error(e2) - throw new Error('Error executing personal sign') - } - } - } - - public async signWithHash( - text: string, - publicKey: string, - password?: string - ): Promise { - const hash = this.web3.utils.utf8ToHex(text) - const isMetaMask = - this.web3 && - this.web3.currentProvider && - (this.web3.currentProvider as any).isMetaMask - try { - return await this.web3.eth.personal.sign(hash, publicKey, password) - } catch (e) { - if (isMetaMask) { - throw e - } - this.logger.warn('Error on personal sign.') - this.logger.warn(e) - try { - return await this.web3.eth.sign(hash, publicKey) - } catch (e2) { - this.logger.error('Error on sign.') - this.logger.error(e2) - throw new Error('Error executing personal sign') - } - } - } - - public async verifyText(text: string, signature: string): Promise { - return this.web3.eth.personal.ecRecover(text, signature) - } - - public async getHash(message: string): Promise { - let hex = '' - for (let i = 0; i < message.length; i++) { - hex += '' + message.charCodeAt(i).toString(16) - } - const hexMessage = '0x' + hex - return hexMessage as string - } - - public async signForAquarius(message: string, account: Account): Promise { - const hash = await this.getHash(message) - const isMetaMask = - this.web3 && - this.web3.currentProvider && - (this.web3.currentProvider as any).isMetaMask - try { - return this.web3.eth.personal.sign( - hash, - account.getId(), - account.getPassword() - ) - } catch (e) { - if (isMetaMask) { - throw e - } - this.logger.warn('Error on personal sign.') - this.logger.warn(e) - return null - } - } -} From 9764743920da876ec7d382f6bc9fcd3d16bf4a48 Mon Sep 17 00:00:00 2001 From: arsenyjin Date: Tue, 26 May 2020 12:18:17 +0200 Subject: [PATCH 17/17] fix rename OceanCompute to Compute --- src/brizo/Brizo.ts | 2 +- src/lib.ts | 2 +- src/ocean/{OceanCompute.ts => Compute.ts} | 10 +++++----- src/ocean/Ocean.ts | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) rename src/ocean/{OceanCompute.ts => Compute.ts} (98%) diff --git a/src/brizo/Brizo.ts b/src/brizo/Brizo.ts index b92918f6..69b38d34 100644 --- a/src/brizo/Brizo.ts +++ b/src/brizo/Brizo.ts @@ -4,7 +4,7 @@ import { noZeroX } from '../utils' import { Instantiable, InstantiableConfig } from '../Instantiable.abstract' import { DDO } from '../ddo/DDO' import { ServiceType } from '../ddo/Service' -import { ComputeJob, Output } from '../ocean/OceanCompute' +import { ComputeJob, Output } from '../ocean/Compute' const apiPath = '/api/v1/brizo/services' diff --git a/src/lib.ts b/src/lib.ts index 629396ae..8961c189 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -13,7 +13,7 @@ export * from './ddo/DDO' export * from './ddo/MetaData' export { CreateProgressStep } from './ocean/OceanAssets' -export { ComputeJob, ComputeJobStatus } from './ocean/OceanCompute' +export { ComputeJob, ComputeJobStatus } from './ocean/Compute' export { OrderProgressStep } from './ocean/utils/ServiceUtils' export { OceanPlatformTechStatus, diff --git a/src/ocean/OceanCompute.ts b/src/ocean/Compute.ts similarity index 98% rename from src/ocean/OceanCompute.ts rename to src/ocean/Compute.ts index 694b8057..06c93c51 100644 --- a/src/ocean/OceanCompute.ts +++ b/src/ocean/Compute.ts @@ -50,13 +50,13 @@ export interface ComputeJob { /** * Compute submodule of Ocean Protocol. */ -export class OceanCompute extends Instantiable { +export class Compute extends Instantiable { /** - * Returns the instance of OceanCompute. - * @return {Promise} + * Returns the instance of Compute. + * @return {Promise} */ - public static async getInstance(config: InstantiableConfig): Promise { - const instance = new OceanCompute() + public static async getInstance(config: InstantiableConfig): Promise { + const instance = new Compute() instance.setInstanceConfig(config) return instance diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index 9124a27d..9a57b4ce 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -2,7 +2,7 @@ import { OceanAccounts } from './OceanAccounts' import { Assets } from './Assets' import { OceanAuth } from './OceanAuth' -import { OceanCompute } from './OceanCompute' +import { Compute } from './Compute' import { OceanTokens } from './OceanTokens' import { OceanVersions } from './OceanVersions' @@ -48,7 +48,7 @@ export class Ocean extends Instantiable { instance.accounts = await OceanAccounts.getInstance(instanceConfig) instance.auth = await OceanAuth.getInstance(instanceConfig) instance.assets = await OceanAssets.getInstance(instanceConfig) - instance.compute = await OceanCompute.getInstance(instanceConfig) + instance.compute = await Compute.getInstance(instanceConfig) instance.datatokens = new DataTokens( instanceConfig.config.factoryAddress, instanceConfig.config.factoryABI, @@ -93,9 +93,9 @@ export class Ocean extends Instantiable { /** * Ocean compute submodule - * @type {OceanCompute} + * @type {Compute} */ - public compute: OceanCompute + public compute: Compute /** * Ocean secretStore submodule