diff --git a/src/ocean/Account.ts b/src/ocean/Account.ts index f85dcf1..4a44188 100644 --- a/src/ocean/Account.ts +++ b/src/ocean/Account.ts @@ -5,13 +5,24 @@ import Web3Provider from "../keeper/Web3Provider" import Balance from "../models/Balance" import OceanBase from "./OceanBase" +/** + * Account information. + */ export default class Account extends OceanBase { private balance: Balance + /** + * Balance of Ocean Token. + * @return {Promise} + */ public async getOceanBalance(): Promise { return (await Keeper.getInstance()).token.balanceOf(this.id) } + /** + * Balance of Ether. + * @return {Promise} + */ public async getEtherBalance(): Promise { // Logger.log("getting balance for", account); return Web3Provider @@ -24,6 +35,10 @@ export default class Account extends OceanBase { }) } + /** + * Balances of Ether and Ocean Token. + * @return {Promise} + */ public async getBalance(): Promise { if (!this.balance) { @@ -36,6 +51,11 @@ export default class Account extends OceanBase { return this.balance } + /** + * Request Ocean Tokens. + * @param {number} amount Tokens to be requested. + * @return {Promise} + */ public async requestTokens(amount: number): Promise { await (await Keeper.getInstance()) .market @@ -43,6 +63,10 @@ export default class Account extends OceanBase { return amount } + /** + * Returns the account public key. + * @return {Promise} + */ public async getPublicKey(): Promise { const web3 = Web3Provider.getWeb3() diff --git a/src/ocean/DID.ts b/src/ocean/DID.ts index 608ec37..ef3d13f 100644 --- a/src/ocean/DID.ts +++ b/src/ocean/DID.ts @@ -2,8 +2,16 @@ import IdGenerator from "./IdGenerator" const prefix = "did:op:" +/** + * Decentralized ID. + */ export default class DID { + /** + * Parses a DID from a string. + * @param {string} didString DID in string. + * @return {DID} + */ public static parse(didString: string): DID { let did: DID if (didString.startsWith(prefix)) { @@ -20,21 +28,36 @@ export default class DID { return did } + /** + * Returns a new DID. + * @return {DID} + */ public static generate(): DID { return new DID(IdGenerator.generateId()) } + /** + * ID. + * @type {string} + */ private id: string private constructor(id: string) { - this.id = id } + /** + * Returns the DID. + * @return {string} + */ public getDid(): string { return `${prefix}${this.id}` } + /** + * Returns the ID. + * @return {string} + */ public getId(): string { return this.id } diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index 841ab18..9141bc6 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -27,10 +27,17 @@ import Access from "./ServiceAgreements/Templates/Access" import EventListener from "../keeper/EventListener" +/** + * Main interface for Ocean Protocol. + */ export default class Ocean { - public static async getInstance(config: Config) { - + /** + * Returns the instance of Ocean. + * @param {Config} config Ocean instance configuration. + * @return {Promise} + */ + public static async getInstance(config: Config): Promise { if (!Ocean.instance) { ConfigProvider.setConfig(config) Ocean.instance = new Ocean() @@ -40,13 +47,25 @@ export default class Ocean { return Ocean.instance } - private static instance = null + /** + * Ocean instance. + * @type {Ocean} + */ + private static instance: Ocean = null + /** + * Keeper instance. + * @type {Keeper} + */ private keeper: Keeper private constructor() { } + /** + * Returns the list of accounts. + * @return {Promise} + */ public async getAccounts(): Promise { // retrieve eth accounts @@ -55,12 +74,22 @@ export default class Ocean { return ethAccounts.map((address: string) => new Account(address)) } + /** + * Returns a DDO by DID. + * @param {string} did Decentralized ID. + * @return {Promise} + */ public async resolveDID(did: string): Promise { - const d: DID = DID.parse(did) return AquariusProvider.getAquarius().retrieveDDO(d) } + /** + * Registers a new DDO. + * @param {MetaData} metadata DDO metadata. + * @param {Account} publisher Publicher account. + * @return {Promise} + */ public async registerAsset(metadata: MetaData, publisher: Account): Promise { const {didRegistry} = this.keeper @@ -153,6 +182,13 @@ export default class Ocean { return storedDdo } + /** + * Signs a service agreement by DID. + * @param {string} did Decentralized ID. + * @param {string} serviceDefinitionId Service definition ID. + * @param {Account} consumer Consumer account. + * @return {Promise} + */ public async signServiceAgreement(did: string, serviceDefinitionId: string, consumer: Account): Promise { @@ -201,6 +237,15 @@ export default class Ocean { } } + /** + * Creates a new service agreement. + * @param {string} did Decentralized ID. + * @param {string} serviceDefinitionId Service definition ID. + * @param {string} serviceAgreementId Service agreement ID. + * @param {string} serviceAgreementSignature Service agreement signature. + * @param {Function} cb Callback executen when the access is granted. + * @param {Account} consumer Consumer account. + */ public async initializeServiceAgreement(did: string, serviceDefinitionId: string, serviceAgreementId: string, @@ -247,6 +292,16 @@ export default class Ocean { consumer.getId()) } + /** + * Executes a service agreement. + * @param {string} did Decentralized ID. + * @param {string} serviceDefinitionId Service definition ID. + * @param {string} serviceAgreementId Service agreement ID. + * @param {string} serviceAgreementSignature Service agreement signature. + * @param {Account} consumer Consumer account. + * @param {Account} publisher Publisher account. + * @return {Promise} + */ public async executeServiceAgreement(did: string, serviceDefinitionId: string, serviceAgreementId: string, @@ -270,10 +325,21 @@ export default class Ocean { return serviceAgreement } + /** + * Search over the assets using a query. + * @param {SearchQuery} query Query to filter the assets. + * @return {Promise} + */ public async searchAssets(query: SearchQuery): Promise { return AquariusProvider.getAquarius().queryMetadata(query) } + + /** + * Search over the assets using a keyword. + * @param {SearchQuery} text Text to filter the assets. + * @return {Promise} + */ public async searchAssetsByText(text: string): Promise { return AquariusProvider.getAquarius().queryMetadataByText({ text,