1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00
squid-js/src/keeper/Auth.ts

48 lines
1.9 KiB
TypeScript
Raw Normal View History

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-18 13:12:23 +02:00
import ContractBase from "./ContractBase"
2018-10-18 13:12:23 +02:00
export default class OceanAuth extends ContractBase {
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-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-17 18:24:01 +02:00
public async getEncryptedAccessToken(orderId: string, consumerAddress: string): Promise<Receipt> {
return this.call("getEncryptedAccessToken", [orderId], consumerAddress)
}
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-26 13:37:09 +02:00
const args = ["0x" + asset.getId(), asset.publisher.getId(), publicKey, timeout]
2018-10-16 14:56:18 +02:00
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-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])
}
}