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"
|
|
|
|
|
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-11-26 15:24:59 +01:00
|
|
|
return `${this.url}${apiPath}/access/purchase?`
|
2018-11-09 10:43:29 +01:00
|
|
|
}
|
|
|
|
|
2018-11-09 11:16:22 +01:00
|
|
|
public getConsumeEndpoint(pubKey: string, serviceId: string, url: string) {
|
2018-11-26 15:24:59 +01:00
|
|
|
return `${this.url}${apiPath}/consume?pubKey=${pubKey}&serviceId=${serviceId}&url=${url}`
|
2018-11-09 10:43:29 +01:00
|
|
|
}
|
2018-11-09 11:16:22 +01:00
|
|
|
|
|
|
|
public getComputeEndpoint(pubKey: string, serviceId: string, algo: string, container: string) {
|
|
|
|
// tslint:disable-next-line
|
2018-11-26 15:24:59 +01:00
|
|
|
return `${this.url}${apiPath}/compute?pubKey=${pubKey}&serviceId=${serviceId}&algo=${algo}&container=${container}"`
|
2018-11-09 11:16:22 +01:00
|
|
|
}
|
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,
|
|
|
|
}
|
|
|
|
|
2018-11-26 15:24:59 +01:00
|
|
|
return WebServiceConnectorProvider
|
|
|
|
.getConnector()
|
|
|
|
.post(
|
|
|
|
`${this.url}${apiPath}/access/initialize`,
|
2018-11-29 08:45:10 +01:00
|
|
|
decodeURI(JSON.stringify(args)),
|
2018-11-26 15:24:59 +01:00
|
|
|
)
|
2018-11-19 12:16:11 +01:00
|
|
|
|
|
|
|
}
|
2018-11-09 10:43:29 +01:00
|
|
|
}
|