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

57 lines
1.5 KiB
TypeScript
Raw Normal View History

2018-11-09 10:43:29 +01:00
import Config from "../models/Config"
2018-11-19 12:16:11 +01:00
import WebServiceConnectorProvider from "../utils/WebServiceConnectorProvider"
2018-11-09 10:43:29 +01:00
2018-11-26 15:24:59 +01:00
const apiPath = "/api/v1/brizo/services"
/**
* Provides a interface with Brizo.
* Brizo is the technical component executed by the Publishers allowing to them to provide extended data services.
*/
2018-11-09 10:43:29 +01:00
export default class Brizo {
private url: string
constructor(config: Config) {
this.url = config.brizoUri
}
public getPurchaseEndpoint() {
2018-12-12 20:52:11 +01:00
return `${this.url}${apiPath}/access/initialize`
2018-11-09 10:43:29 +01:00
}
public getConsumeEndpoint() {
return `${this.url}${apiPath}/consume`
2018-11-09 10:43:29 +01:00
}
public getComputeEndpoint(pubKey: string, serviceId: string, algo: string, container: string) {
// tslint:disable-next-line
2018-12-12 20:52:11 +01:00
return `${this.url}${apiPath}/compute`
}
2018-11-19 12:16:11 +01:00
2018-11-21 14:59:22 +01:00
public async initializeServiceAgreement(
did: string,
serviceAgreementId: string,
serviceDefinitionId: string,
signature: string,
2018-11-26 15:24:59 +01:00
consumerAddress: string): Promise<any> {
2018-11-29 08:45:10 +01:00
const args = {
did,
serviceAgreementId,
serviceDefinitionId,
signature,
consumerAddress,
}
try {
return await WebServiceConnectorProvider
.getConnector()
.post(
this.getPurchaseEndpoint(),
decodeURI(JSON.stringify(args)),
)
2019-01-24 10:58:05 +01:00
} catch (e) {
throw new Error("HTTP request failed")
}
2018-11-19 12:16:11 +01:00
}
2018-11-09 10:43:29 +01:00
}