mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
added SecretStore integration test
This commit is contained in:
parent
dd5c90eb9f
commit
fce88aa528
36
integration/ocean/SecretStore.test.ts
Normal file
36
integration/ocean/SecretStore.test.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import { assert } from "chai"
|
||||||
|
|
||||||
|
import { config } from "../config"
|
||||||
|
|
||||||
|
import { Ocean, Account, DID } from "../../src" // @oceanprotocol/squid
|
||||||
|
|
||||||
|
describe("Secret Store", () => {
|
||||||
|
let ocean: Ocean
|
||||||
|
|
||||||
|
let account: Account
|
||||||
|
|
||||||
|
const did: DID = DID.generate()
|
||||||
|
const content = {content: "Test 123"}
|
||||||
|
let encryptedContent
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
ocean = await Ocean.getInstance(config)
|
||||||
|
|
||||||
|
// Accounts
|
||||||
|
account = new Account("0xa99d43d86a0758d5632313b8fa3972b6088a21bb")
|
||||||
|
account.setPassword("secret")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should encrypt a text", async () => {
|
||||||
|
encryptedContent = await ocean.secretStore.encrypt(did.getId(), content, account)
|
||||||
|
|
||||||
|
assert.isDefined(encryptedContent)
|
||||||
|
assert.match(encryptedContent, /^0x[a-f0-9]{86}$/i)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should decrypt a text", async () => {
|
||||||
|
const decryptedContent = await ocean.secretStore.decrypt(did.getId(), encryptedContent, account)
|
||||||
|
|
||||||
|
assert.deepEqual(decryptedContent, content)
|
||||||
|
})
|
||||||
|
})
|
@ -32,8 +32,7 @@ export default class OceanSecretStore {
|
|||||||
* @param {string} publisher Publisher account.
|
* @param {string} publisher Publisher account.
|
||||||
* @return {Promise<string>} Encrypted text.
|
* @return {Promise<string>} Encrypted text.
|
||||||
*/
|
*/
|
||||||
public async encrypt(did: string, content: string, publisher: Account): Promise<string> {
|
public async encrypt(did: string, content: any, publisher: Account): Promise<string> {
|
||||||
console.warn("TODO")
|
|
||||||
return await this.getSecretStoreByAccount(publisher)
|
return await this.getSecretStoreByAccount(publisher)
|
||||||
// TODO did to id
|
// TODO did to id
|
||||||
.encryptDocument(did, content)
|
.encryptDocument(did, content)
|
||||||
@ -47,8 +46,7 @@ export default class OceanSecretStore {
|
|||||||
* @param {string} consumer cONSUMER account.
|
* @param {string} consumer cONSUMER account.
|
||||||
* @return {Promise<string>} Encrypted text.
|
* @return {Promise<string>} Encrypted text.
|
||||||
*/
|
*/
|
||||||
public async decrypt(did: string, content: string, consumer: Account): Promise<string> {
|
public async decrypt(did: string, content: string, consumer: Account): Promise<any> {
|
||||||
console.warn("TODO")
|
|
||||||
return await this.getSecretStoreByAccount(consumer)
|
return await this.getSecretStoreByAccount(consumer)
|
||||||
// TODO did to id
|
// TODO did to id
|
||||||
.decryptDocument(did, content)
|
.decryptDocument(did, content)
|
||||||
|
@ -24,8 +24,8 @@ export default class SecretStoreProvider {
|
|||||||
return SecretStoreProvider.secretStore
|
return SecretStoreProvider.secretStore
|
||||||
} else {
|
} else {
|
||||||
const configRef = JSON.stringify(config)
|
const configRef = JSON.stringify(config)
|
||||||
if (!SecretStoreProvider.secretStoreByUrl.get(configRef)) {
|
if (!SecretStoreProvider.secretStoreWithConfig.get(configRef)) {
|
||||||
SecretStoreProvider.secretStoreByUrl.set(configRef,
|
SecretStoreProvider.secretStoreWithConfig.set(configRef,
|
||||||
new SecretStore({
|
new SecretStore({
|
||||||
...ConfigProvider.getConfig(),
|
...ConfigProvider.getConfig(),
|
||||||
...config,
|
...config,
|
||||||
@ -33,10 +33,10 @@ export default class SecretStoreProvider {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return SecretStoreProvider.secretStoreByUrl.get(configRef)
|
return SecretStoreProvider.secretStoreWithConfig.get(configRef)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static secretStore: SecretStore
|
private static secretStore: SecretStore
|
||||||
private static secretStoreByUrl = new Map<string, SecretStore>()
|
private static secretStoreWithConfig = new Map<string, SecretStore>()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user