diff --git a/src/keeper/contracts/Auth.ts b/src/keeper/contracts/Auth.ts index 92d8b58..92f7398 100644 --- a/src/keeper/contracts/Auth.ts +++ b/src/keeper/contracts/Auth.ts @@ -1,7 +1,6 @@ import {Receipt} from "web3-utils" import AccessStatus from "../../models/AccessStatus" import Asset from "../../ocean/Asset" -import Order from "../../ocean/Order" import ContractBase from "./ContractBase" export default class OceanAuth extends ContractBase { @@ -31,11 +30,6 @@ export default class OceanAuth extends ContractBase { return this.send("initiateAccessRequest", buyerAddress, args) } - public async commitAccessRequest(order: Order, publisherAddress: string) { - const args = [order.getId(), true, 9999999999, "discovery", "read", "slaLink", "slaType"] - return this.send("commitAccessRequest", publisherAddress, args) - } - public async getTempPubKey(orderId: string) { return this.call("getTempPubKey", [orderId]) } diff --git a/src/keeper/contracts/Market.ts b/src/keeper/contracts/Market.ts index bee7d32..688fd8b 100644 --- a/src/keeper/contracts/Market.ts +++ b/src/keeper/contracts/Market.ts @@ -1,6 +1,5 @@ import BigNumber from "bignumber.js" import {Receipt} from "web3-utils" -import Order from "../../ocean/Order" import ContractBase from "./ContractBase" export default class OceanMarket extends ContractBase { @@ -36,12 +35,4 @@ export default class OceanMarket extends ContractBase { public async register(assetId: string, price: number, publisherAddress: string): Promise { return this.send("register", publisherAddress, ["0x" + assetId, price]) } - - public async payOrder(order: Order, publisherAddress: string, - price: number, consumerAddress: string, - timeout: number): Promise { - return this.send("sendPayment", consumerAddress, [ - order.getId(), publisherAddress, price, timeout, - ]) - } } diff --git a/src/ocean/Order.ts b/src/ocean/Order.ts deleted file mode 100644 index 1e061cb..0000000 --- a/src/ocean/Order.ts +++ /dev/null @@ -1,97 +0,0 @@ -import * as EthEcies from "eth-ecies" -import * as JWT from "jsonwebtoken" -import AquariusProvider from "../aquarius/AquariusProvider" -import Keeper from "../keeper/Keeper" -import Web3Provider from "../keeper/Web3Provider" -import AccessStatus from "../models/AccessStatus" -import Logger from "../utils/Logger" -import Account from "./Account" -import Asset from "./Asset" -import OceanBase from "./OceanBase" - -export default class Order extends OceanBase { - - constructor(private asset: Asset, private timeout: number, - private pubkey: string, private key: any) { - super() - } - - public async getStatus(): Promise { - const {auth} = await Keeper.getInstance() - return auth.getOrderStatus(this.id) - } - - public async pay(consumer: Account): Promise { - const {market} = await Keeper.getInstance() - Logger.log( - `Sending payment: ${this.getId()} ${this.asset.publisher.getId()} ${this.asset.price} ${this.timeout}`, - ) - const payReceipt = - await market.payOrder(this, this.asset.publisher.getId(), this.asset.price, consumer.getId(), this.timeout) - - return payReceipt.events.PaymentReceived.returnValues._paymentId - } - - public async commit(accessToken: string): Promise { - const {auth} = await Keeper.getInstance() - const commitAccessRequestReceipt = await auth.commitAccessRequest(this, this.asset.publisher.getId()) - if (commitAccessRequestReceipt.events.AccessRequestRejected) { - - const {returnValues} = commitAccessRequestReceipt.events.AccessRequestRejected - throw new Error(`commitAccessRequest failed ${JSON.stringify(returnValues, null, 2)}`) - } - - const pubKey = await auth.getTempPubKey(this.getId()) - - if (this.pubkey !== pubKey) { - throw new Error("Pubkey missmatch") - } - - const encryptedAccessToken = - EthEcies.encrypt(new Buffer(pubKey, "hex"), new Buffer(accessToken)).toString("hex") - - await auth.deliverAccessToken(this.getId(), `0x${encryptedAccessToken}`, this.asset.publisher.getId()) - - return true - } - - public async consume(consumer: Account): Promise { - const {auth} = await Keeper.getInstance() - - const encryptedAccessToken = await auth.getEncryptedAccessToken(this.getId(), consumer.getId()) - - // grab the access token from acl contract - const tokenNo0x = encryptedAccessToken.slice(2) - const encryptedTokenBuffer = Buffer.from(tokenNo0x, "hex") - - const privateKey = this.key.privateKey.slice(2) - const accessTokenEncoded: string = - EthEcies.decrypt(Buffer.from(privateKey, "hex"), encryptedTokenBuffer).toString() - const accessToken = JWT.decode(accessTokenEncoded) // Returns a json object - - if (!accessToken) { - throw new Error(`AccessToken is not an jwt: ${accessTokenEncoded}`) - } - - const signature = Web3Provider.getWeb3().eth.sign(encryptedAccessToken, consumer.getId()) - const encryptedAccessTokenSha3 = Web3Provider.getWeb3().utils.sha3(encryptedAccessToken) - - // Download the data set from the provider using the url in the access token - // decode the access token, grab the service_endpoint, request_id, - - // payload keys: ['consumerId', 'fixed_msg', 'sigEncJWT', 'jwt'] - const payload = JSON.stringify({ - consumerId: consumer.getId(), - fixed_msg: encryptedAccessTokenSha3, - sigEncJWT: signature, - jwt: accessTokenEncoded, - }) - - const accessUrl = await AquariusProvider.getAquarius().getAccessUrl(accessToken, payload) - - Logger.log("consume url: ", accessUrl) - - return accessUrl - } - -} diff --git a/src/squid.ts b/src/squid.ts index 6ef2c31..81462ad 100644 --- a/src/squid.ts +++ b/src/squid.ts @@ -1,12 +1,12 @@ import Account from "./ocean/Account" import Asset from "./ocean/Asset" import Ocean from "./ocean/Ocean" -import Order from "./ocean/Order" +import ServiceAgreement from "./ocean/ServiceAgreements/ServiceAgreement" import Logger from "./utils/Logger" export { Ocean, - Order, + ServiceAgreement, Asset, Logger, Account, diff --git a/test/Squid.test.ts b/test/Squid.test.ts index 9224b5a..1d41f7d 100644 --- a/test/Squid.test.ts +++ b/test/Squid.test.ts @@ -17,8 +17,8 @@ describe("Squid", () => { assert(squid.Asset) }) - it("should expose Order", async () => { - assert(squid.Order) + it("should expose ServiceAgreement", async () => { + assert(squid.ServiceAgreement) }) })