mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
add initialize to provider
This commit is contained in:
parent
9be591a067
commit
ece08c6963
@ -90,8 +90,7 @@ export class Assets extends Instantiable {
|
|||||||
const encryptedFiles = await this.ocean.provider.encrypt(
|
const encryptedFiles = await this.ocean.provider.encrypt(
|
||||||
did.getId(),
|
did.getId(),
|
||||||
metadata.main.files,
|
metadata.main.files,
|
||||||
publisher,
|
publisher
|
||||||
dtAddress
|
|
||||||
)
|
)
|
||||||
this.logger.log('Files encrypted')
|
this.logger.log('Files encrypted')
|
||||||
observer.next(CreateProgressStep.FilesEncrypted)
|
observer.next(CreateProgressStep.FilesEncrypted)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import Account from '../ocean/Account'
|
import Account from '../ocean/Account'
|
||||||
import { noZeroX } from '../utils'
|
import { noZeroX } from '../utils'
|
||||||
import { Instantiable, InstantiableConfig } from '../Instantiable.abstract'
|
import { Instantiable, InstantiableConfig } from '../Instantiable.abstract'
|
||||||
|
import { DDO } from '../ddo/DDO'
|
||||||
|
|
||||||
const apiPath = '/api/v1/services/'
|
const apiPath = '/api/v1/services/'
|
||||||
|
|
||||||
@ -20,34 +21,6 @@ export class Provider extends Instantiable {
|
|||||||
this.setInstanceConfig(config)
|
this.setInstanceConfig(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getVersionInfo() {
|
|
||||||
return (await this.ocean.utils.fetch.get(this.url)).json()
|
|
||||||
}
|
|
||||||
|
|
||||||
public getURI() {
|
|
||||||
return `${this.url}`
|
|
||||||
}
|
|
||||||
|
|
||||||
public getPurchaseEndpoint() {
|
|
||||||
return `${this.url}${apiPath}/access/initialize`
|
|
||||||
}
|
|
||||||
|
|
||||||
public getConsumeEndpoint() {
|
|
||||||
return `${this.url}${apiPath}/consume`
|
|
||||||
}
|
|
||||||
|
|
||||||
public getEncryptEndpoint() {
|
|
||||||
return `${this.url}${apiPath}/encrypt`
|
|
||||||
}
|
|
||||||
|
|
||||||
public getPublishEndpoint() {
|
|
||||||
return `${this.url}${apiPath}/publish`
|
|
||||||
}
|
|
||||||
|
|
||||||
public getComputeEndpoint() {
|
|
||||||
return `${this.url}${apiPath}/compute`
|
|
||||||
}
|
|
||||||
|
|
||||||
public async createSignature(account: Account, agreementId: string): Promise<string> {
|
public async createSignature(account: Account, agreementId: string): Promise<string> {
|
||||||
const signature = await this.ocean.utils.signature.signText(
|
const signature = await this.ocean.utils.signature.signText(
|
||||||
noZeroX(agreementId),
|
noZeroX(agreementId),
|
||||||
@ -66,12 +39,7 @@ export class Provider extends Instantiable {
|
|||||||
return signature
|
return signature
|
||||||
}
|
}
|
||||||
|
|
||||||
public async encrypt(
|
public async encrypt(did: string, document: any, account: Account): Promise<string> {
|
||||||
did: string,
|
|
||||||
document: any,
|
|
||||||
account: Account,
|
|
||||||
dtAddress: string
|
|
||||||
): Promise<string> {
|
|
||||||
const signature = this.ocean.utils.signature.signWithHash(
|
const signature = this.ocean.utils.signature.signWithHash(
|
||||||
did,
|
did,
|
||||||
account.getId(),
|
account.getId(),
|
||||||
@ -99,4 +67,63 @@ export class Provider extends Instantiable {
|
|||||||
throw new Error('HTTP request failed')
|
throw new Error('HTTP request failed')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async initialize(
|
||||||
|
did: string,
|
||||||
|
serviceIndex: number,
|
||||||
|
serviceType: string,
|
||||||
|
consumerAddress: string
|
||||||
|
): Promise<any> {
|
||||||
|
const DDO = await this.ocean.assets.resolve(did)
|
||||||
|
const { dtAddress } = DDO
|
||||||
|
const args = {
|
||||||
|
did,
|
||||||
|
dtAddress,
|
||||||
|
serviceIndex,
|
||||||
|
serviceType,
|
||||||
|
consumerAddress
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return await this.ocean.utils.fetch.post(
|
||||||
|
this.getInitializeEndpoint(),
|
||||||
|
decodeURI(JSON.stringify(args))
|
||||||
|
)
|
||||||
|
} catch (e) {
|
||||||
|
this.logger.error(e)
|
||||||
|
throw new Error('HTTP request failed')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getVersionInfo() {
|
||||||
|
return (await this.ocean.utils.fetch.get(this.url)).json()
|
||||||
|
}
|
||||||
|
|
||||||
|
public getURI() {
|
||||||
|
return `${this.url}`
|
||||||
|
}
|
||||||
|
|
||||||
|
public getInitializeEndpoint() {
|
||||||
|
return `${this.url}${apiPath}/initialize`
|
||||||
|
}
|
||||||
|
|
||||||
|
public getConsumeEndpoint() {
|
||||||
|
return `${this.url}${apiPath}/consume`
|
||||||
|
}
|
||||||
|
|
||||||
|
public getEncryptEndpoint() {
|
||||||
|
return `${this.url}${apiPath}/encrypt`
|
||||||
|
}
|
||||||
|
|
||||||
|
public getPublishEndpoint() {
|
||||||
|
return `${this.url}${apiPath}/publish`
|
||||||
|
}
|
||||||
|
|
||||||
|
public getComputeEndpoint() {
|
||||||
|
return `${this.url}${apiPath}/compute`
|
||||||
|
}
|
||||||
|
|
||||||
|
public getDownloadEndpoint() {
|
||||||
|
return `${this.url}${apiPath}/download`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user