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

36 lines
1.4 KiB
TypeScript
Raw Normal View History

2019-02-14 11:26:12 +01:00
import Account from "./Account"
import { noDidPrefixed } from "../utils"
import { File } from "../ddo/MetaData"
import { Instantiable, InstantiableConfig } from "../Instantiable.abstract"
2019-02-14 11:26:12 +01:00
/**
* SecretStore submodule of Ocean Protocol.
*/
export class OceanSecretStore extends Instantiable {
2019-02-14 11:26:12 +01:00
/**
* Returns the instance of OceanSecretStore.
* @return {Promise<OceanSecretStore>}
*/
public static async getInstance(config: InstantiableConfig): Promise<OceanSecretStore> {
const instance = new OceanSecretStore()
instance.setInstanceConfig(config)
2019-02-14 11:26:12 +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.
*/
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
return await this.ocean.brizo.encrypt(noDidPrefixed(did), signedDid, document, publisher.getId())
2019-02-14 11:26:12 +01:00
}
}