2019-02-14 11:26:12 +01:00
|
|
|
import Account from "./Account"
|
2019-03-21 02:56:58 +01:00
|
|
|
import { noDidPrefixed } from "../utils"
|
2019-04-01 12:40:45 +02:00
|
|
|
import { File } from "../ddo/MetaData"
|
2019-03-21 02:56:58 +01:00
|
|
|
import { Instantiable, InstantiableConfig } from "../Instantiable.abstract"
|
2019-02-14 11:26:12 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SecretStore submodule of Ocean Protocol.
|
|
|
|
*/
|
2019-03-21 02:56:58 +01:00
|
|
|
export class OceanSecretStore extends Instantiable {
|
2019-02-14 11:26:12 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the instance of OceanSecretStore.
|
|
|
|
* @return {Promise<OceanSecretStore>}
|
|
|
|
*/
|
2019-03-21 02:56:58 +01:00
|
|
|
public static async getInstance(config: InstantiableConfig): Promise<OceanSecretStore> {
|
|
|
|
const instance = new OceanSecretStore()
|
|
|
|
instance.setInstanceConfig(config)
|
2019-02-14 11:26:12 +01:00
|
|
|
|
2019-03-21 02:56:58 +01:00
|
|
|
return instance
|
2019-02-14 11:26:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Encrypt the given text and store the encryption keys using the `did`.
|
|
|
|
* The encrypted text can be decrypted using the same keys identified by the `did`.
|
|
|
|
* @param {string} did Decentralized ID.
|
|
|
|
* @param {string} content Content to be encrypted.
|
|
|
|
* @param {string} publisher Publisher account.
|
|
|
|
* @return {Promise<string>} Encrypted text.
|
|
|
|
*/
|
2019-04-01 12:40:45 +02:00
|
|
|
public async encrypt(did: string, document: any, publisher: Account): Promise<string> {
|
|
|
|
const signedDid = await this.ocean.utils.signature.signText(noDidPrefixed(did), publisher.getId(), publisher.getPassword())
|
2019-02-14 11:26:12 +01:00
|
|
|
|
2019-04-01 12:40:45 +02:00
|
|
|
return await this.ocean.brizo.encrypt(noDidPrefixed(did), signedDid, document, publisher.getId())
|
2019-02-14 11:26:12 +01:00
|
|
|
}
|
|
|
|
}
|