mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
get rid of order
This commit is contained in:
parent
8d99dba0f9
commit
20377f5aa3
@ -1,7 +1,6 @@
|
|||||||
import {Receipt} from "web3-utils"
|
import {Receipt} from "web3-utils"
|
||||||
import AccessStatus from "../../models/AccessStatus"
|
import AccessStatus from "../../models/AccessStatus"
|
||||||
import Asset from "../../ocean/Asset"
|
import Asset from "../../ocean/Asset"
|
||||||
import Order from "../../ocean/Order"
|
|
||||||
import ContractBase from "./ContractBase"
|
import ContractBase from "./ContractBase"
|
||||||
|
|
||||||
export default class OceanAuth extends ContractBase {
|
export default class OceanAuth extends ContractBase {
|
||||||
@ -31,11 +30,6 @@ export default class OceanAuth extends ContractBase {
|
|||||||
return this.send("initiateAccessRequest", buyerAddress, args)
|
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) {
|
public async getTempPubKey(orderId: string) {
|
||||||
return this.call("getTempPubKey", [orderId])
|
return this.call("getTempPubKey", [orderId])
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import BigNumber from "bignumber.js"
|
import BigNumber from "bignumber.js"
|
||||||
import {Receipt} from "web3-utils"
|
import {Receipt} from "web3-utils"
|
||||||
import Order from "../../ocean/Order"
|
|
||||||
import ContractBase from "./ContractBase"
|
import ContractBase from "./ContractBase"
|
||||||
|
|
||||||
export default class OceanMarket extends 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<Receipt> {
|
public async register(assetId: string, price: number, publisherAddress: string): Promise<Receipt> {
|
||||||
return this.send("register", publisherAddress, ["0x" + assetId, price])
|
return this.send("register", publisherAddress, ["0x" + assetId, price])
|
||||||
}
|
}
|
||||||
|
|
||||||
public async payOrder(order: Order, publisherAddress: string,
|
|
||||||
price: number, consumerAddress: string,
|
|
||||||
timeout: number): Promise<Receipt> {
|
|
||||||
return this.send("sendPayment", consumerAddress, [
|
|
||||||
order.getId(), publisherAddress, price, timeout,
|
|
||||||
])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -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<AccessStatus> {
|
|
||||||
const {auth} = await Keeper.getInstance()
|
|
||||||
return auth.getOrderStatus(this.id)
|
|
||||||
}
|
|
||||||
|
|
||||||
public async pay(consumer: Account): Promise<string> {
|
|
||||||
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<boolean> {
|
|
||||||
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<string> {
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,12 +1,12 @@
|
|||||||
import Account from "./ocean/Account"
|
import Account from "./ocean/Account"
|
||||||
import Asset from "./ocean/Asset"
|
import Asset from "./ocean/Asset"
|
||||||
import Ocean from "./ocean/Ocean"
|
import Ocean from "./ocean/Ocean"
|
||||||
import Order from "./ocean/Order"
|
import ServiceAgreement from "./ocean/ServiceAgreements/ServiceAgreement"
|
||||||
import Logger from "./utils/Logger"
|
import Logger from "./utils/Logger"
|
||||||
|
|
||||||
export {
|
export {
|
||||||
Ocean,
|
Ocean,
|
||||||
Order,
|
ServiceAgreement,
|
||||||
Asset,
|
Asset,
|
||||||
Logger,
|
Logger,
|
||||||
Account,
|
Account,
|
||||||
|
@ -17,8 +17,8 @@ describe("Squid", () => {
|
|||||||
assert(squid.Asset)
|
assert(squid.Asset)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should expose Order", async () => {
|
it("should expose ServiceAgreement", async () => {
|
||||||
assert(squid.Order)
|
assert(squid.ServiceAgreement)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user