2018-10-05 12:34:31 +02:00
|
|
|
import {Receipt} from "web3-utils"
|
2018-10-17 18:24:01 +02:00
|
|
|
import AccessStatus from "../models/AccessStatus"
|
2018-10-16 14:56:18 +02:00
|
|
|
import Asset from "../ocean/Asset"
|
2018-10-17 18:24:01 +02:00
|
|
|
import Order from "../ocean/Order"
|
2018-10-02 10:06:26 +02:00
|
|
|
import ContractBaseWrapper from "./ContractWrapperBase"
|
2018-10-01 18:10:26 +02:00
|
|
|
|
|
|
|
export default class OceanAuth extends ContractBaseWrapper {
|
|
|
|
|
2018-10-16 14:56:18 +02:00
|
|
|
public static async getInstance(): Promise<OceanAuth> {
|
|
|
|
const auth: OceanAuth = new OceanAuth("OceanAuth")
|
2018-10-02 10:06:26 +02:00
|
|
|
await auth.init()
|
|
|
|
return auth
|
2018-10-01 18:10:26 +02:00
|
|
|
}
|
|
|
|
|
2018-10-17 18:24:01 +02:00
|
|
|
public async getOrderStatus(orderId: string): Promise<AccessStatus> {
|
|
|
|
return this.call("statusOfAccessRequest", [orderId])
|
|
|
|
.then((status: string) => {
|
|
|
|
const statusInt = parseInt(status, 10)
|
|
|
|
const statusString = AccessStatus[statusInt]
|
|
|
|
return AccessStatus[statusString]
|
2018-10-05 12:34:31 +02:00
|
|
|
})
|
2018-10-01 18:10:26 +02:00
|
|
|
}
|
|
|
|
|
2018-10-17 18:24:01 +02:00
|
|
|
public async getEncryptedAccessToken(orderId: string, consumerAddress: string): Promise<Receipt> {
|
|
|
|
return this.call("getEncryptedAccessToken", [orderId], consumerAddress)
|
2018-10-01 18:10:26 +02:00
|
|
|
}
|
|
|
|
|
2018-10-05 12:34:31 +02:00
|
|
|
public async initiateAccessRequest(asset: Asset, publicKey: string,
|
2018-10-10 11:02:00 +02:00
|
|
|
timeout: number, buyerAddress: string): Promise<Receipt> {
|
2018-10-16 14:56:18 +02:00
|
|
|
const args = [asset.getId(), asset.publisher.getId(), publicKey, timeout]
|
|
|
|
return this.sendTransaction("initiateAccessRequest", buyerAddress, args)
|
|
|
|
}
|
|
|
|
|
2018-10-17 18:24:01 +02:00
|
|
|
public async commitAccessRequest(order: Order, publisherAddress: string) {
|
|
|
|
const args = [order.getId(), true, 9999999999, "discovery", "read", "slaLink", "slaType"]
|
|
|
|
return this.sendTransaction("commitAccessRequest", publisherAddress, args)
|
2018-10-01 18:10:26 +02:00
|
|
|
}
|
2018-10-17 18:24:01 +02:00
|
|
|
|
|
|
|
public async getTempPubKey(orderId: string) {
|
|
|
|
return this.call("getTempPubKey", [orderId])
|
|
|
|
}
|
|
|
|
|
|
|
|
public async deliverAccessToken(orderId: string, accessToken: string, publisherAddress: string) {
|
|
|
|
return this.sendTransaction("deliverAccessToken", publisherAddress, [orderId, accessToken])
|
|
|
|
}
|
|
|
|
|
2018-10-01 18:10:26 +02:00
|
|
|
}
|