diff --git a/SQUID_INTERFACE.md b/SQUID_INTERFACE.md new file mode 100644 index 0000000..f1c7e36 --- /dev/null +++ b/SQUID_INTERFACE.md @@ -0,0 +1,92 @@ +## Ocean +- Ocean(config(web3Provider, nodeURI, gas, network, providerURI)) +- getInstance() +- getMessageHash(message) => hash of the given message +- createDIDRecord(content) => ocean specific DID with an id based on hash of the given string message +- registerProvider(url, provider_address) +- getProviders() + +## Account +- getAccounts() => list of accounts along with token and eth balances +- getTokenBalance() +- getEthBalance() +- requestTokens(amount) => bool + +## Order +- purchaseAsset(assetDID, price, timeout, conditions) +- getOrderStatus(orderId) => integer representing the order status as defined in the keeper +- getOrders() => list of orders +- verifyOrderPayment(orderId) => true / false + +## Asset / Metadata +- publishAsset(assetDID, assetDDO, price) +- updateAsset(assetDDO) +- retireAsset(assetDID) +- getAssetPrice(assetDID) +- getAssetMetadata(assetDID) => asset DDO +- getAssetsMetadata() => list of assets DDOs +- resolveAssetDID(did) => DDO of the given DID +- getAssets() => asset ids from keeper +- checkAsset(assetDID) => true / false +- getAssetConditions + + +####################################################### +####################################################### +####################################################### +## Keeper API: +* register tribe actor +* publish service agreement conditions +* setup/execute service agreement +* fulfill condition +* dispute service delivery, quality, content, results +* submit proof of service delivery +* query transaction history +* verify actor + +####################################################### +## Use cases: + +### Publisher +* publish one service + * squid.publishService(metadata) => serviceDID, didDocument +* view my published services + * squid.listServices(type, matchStr, labels, tags, publishers)) +* view my sold services + * squid.listSoldServices(actorAddress) +* update service + * squid.updateService(serviceDID, metadata, price) +* revoke service + * squid.revokeService(serviceDID, reason) + +### Consumer +* view / find services + * squid.listServices(type, matchStr, labels, tags, publishers) +* buy/access service + * squid.buyService(serviceId, ) => orderId, service ? +* view my purchased services + * squid.listPurchasedServices(actorAddress) +* checkPurchaseStatus(orderId) +* dispute purchased service + * squid.openServiceDispute(orderId) +* rate service + * squid.rateService(orderId, rating) + +### Tribe / Marketplace +* register on ocean with an `ethereum` address and DID Record + * Uses `squid` or directly access keeper contracts +* provide API to allow the following interactions: + * publish a service + * update a service + * revoke a service + * buy/use/access a service + * search available services + * +* tribe admin: + * view publishers + * view disputes + +### Curator + +### Verifier + diff --git a/src/account.js b/src/account.js new file mode 100644 index 0000000..cb84b7f --- /dev/null +++ b/src/account.js @@ -0,0 +1,37 @@ +import KeeperBase from './keeper/keeper-base' + +export default class Account extends KeeperBase { + constructor(web3Helper, token) { + super(web3Helper) + this.token = token + return (async () => { + return this + })() + } + + async list() { + return Promise.all((await this.helper.getAccounts()).map(async (account) => { + // await ocean.market.requestTokens(account, 1000) + + return { + name: account, + balance: { + ocn: await this.token.getTokenBalance(account), + eth: await this.token.getEthBalance(account) + } + } + })) + } + + currentAccount() { + return this.helper.getCurrentAccount() + } + + tokenBalance() { + return this.token.getTokenBalance() + } + + ethBalance() { + return this.token.getEthBalance() + } +} diff --git a/src/order.js b/src/order.js new file mode 100644 index 0000000..2e35693 --- /dev/null +++ b/src/order.js @@ -0,0 +1,52 @@ +import KeeperBase from './keeper/keeper-base' + +export default class Order extends KeeperBase { + constructor(web3Helper, market, token, auth) { + super(web3Helper) + this.market = market + this.token = token + this.auth = auth + return (async () => { + return this + })() + } + + buyService(serviceDID, publisherId, price, timeout, senderAddress, initialRequestEventHandler, + accessCommittedEventHandler, tokenPublishedEventHandler) { + // Allow market contract to transfer funds on the consumer's behalf + const { token, market, auth } = this + token.contract.approve(market.address, price, { from: senderAddress, gas: 2000000 }) + // Submit the access request + auth.contract.initiateAccessRequest( + serviceDID, publisherId, timeout, { from: senderAddress, gas: 1000000 } + ) + + const resourceFilter = { _resourceId: serviceDID, _consumer: senderAddress } + const initRequestEvent = auth.contract.AccessConsentRequested(resourceFilter) + let order = {} + this._listenOnce( + initRequestEvent, + 'AccessConsentRequested', + (result, error) => { + order = initialRequestEventHandler(result, error) + const requestIdFilter = { _id: order.id } + const accessCommittedEvent = auth.contract.AccessRequestCommitted(requestIdFilter) + const tokenPublishedEvent = auth.contract.EncryptedTokenPublished(requestIdFilter) + this._listenOnce( + accessCommittedEvent, + 'AccessRequestCommitted', + (result, error) => { + accessCommittedEventHandler(result, order, error) + } + ) + this._listenOnce( + tokenPublishedEvent, + 'EncryptedTokenPublished', + (result, error) => { + tokenPublishedEventHandler(result, order, error) + } + ) + }) + return order + } +} diff --git a/src/service.js b/src/service.js new file mode 100644 index 0000000..f1a05b4 --- /dev/null +++ b/src/service.js @@ -0,0 +1,36 @@ +import KeeperBase from './keeper/keeper-base' +import MetaData from './metadata' + +export default class Service extends KeeperBase { + constructor(web3Helper, market) { + super(web3Helper) + this.market = market + return (async () => { + return this + })() + } + + serviceMetadata(assetDID) { + return '' + } + serviceTribe() { + return '' + } + + createDDO(did, metadata) { + return { + '@context': 'https://w3id.org/did/v1', + id: did, + publicKey: [], + authentication: [], + service: [], + metadata: metadata + } + } + + resolveDID(did) { + const providerURL = this.market.resolveDID(did) + const metadataGuy = new MetaData(providerURL) + return metadataGuy.getAssetDDO(did) + } +} diff --git a/src/tribe.js b/src/tribe.js new file mode 100644 index 0000000..995609b --- /dev/null +++ b/src/tribe.js @@ -0,0 +1,25 @@ +import KeeperBase from './keeper/keeper-base' + +export default class Tribe extends KeeperBase { + constructor(web3Helper) { + super(web3Helper) + + return (async () => { + return this + })() + } + + // did ddo for tribes/marketplaces + registerTribe() { + return '' + } + + tribessList() { + return '' + } + + resolveTribeDID() { + // verify DDO + return 'DDO' + } +}