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

Restore decryption feature on Secret Store submodule.

This commit is contained in:
Pedro Gutiérrez 2019-07-11 15:55:08 +02:00 committed by Pedro Gutiérrez
parent a629a04dd4
commit ccbd0daead
4 changed files with 62 additions and 31 deletions

51
package-lock.json generated
View File

@ -173,6 +173,14 @@
"resolved": "https://registry.npmjs.org/@oceanprotocol/keeper-contracts/-/keeper-contracts-0.10.3.tgz", "resolved": "https://registry.npmjs.org/@oceanprotocol/keeper-contracts/-/keeper-contracts-0.10.3.tgz",
"integrity": "sha512-Nvnk9nNWMmfXz38bHRHHNgc8MGmFPZTkXPBWbEXR9+maJq5/kRFx8OckroKqmYXX4QBEh5frwd77omNOL2MUNw==" "integrity": "sha512-Nvnk9nNWMmfXz38bHRHHNgc8MGmFPZTkXPBWbEXR9+maJq5/kRFx8OckroKqmYXX4QBEh5frwd77omNOL2MUNw=="
}, },
"@oceanprotocol/secret-store-client": {
"version": "0.0.15",
"resolved": "https://registry.npmjs.org/@oceanprotocol/secret-store-client/-/secret-store-client-0.0.15.tgz",
"integrity": "sha512-5yNNA+qdjut9/nMiFKJd4D4io+GhzdfvdqVd5YMkgT9RV1qDosGj6NVsKArYay6g+tQH7pCJ6Y1FiAbhaaFB9g==",
"requires": {
"node-fetch": "^2.6.0"
}
},
"@octokit/endpoint": { "@octokit/endpoint": {
"version": "4.2.2", "version": "4.2.2",
"resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-4.2.2.tgz", "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-4.2.2.tgz",
@ -3797,8 +3805,7 @@
"ansi-regex": { "ansi-regex": {
"version": "2.1.1", "version": "2.1.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"aproba": { "aproba": {
"version": "1.2.0", "version": "1.2.0",
@ -3819,14 +3826,12 @@
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"brace-expansion": { "brace-expansion": {
"version": "1.1.11", "version": "1.1.11",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"balanced-match": "^1.0.0", "balanced-match": "^1.0.0",
"concat-map": "0.0.1" "concat-map": "0.0.1"
@ -3841,20 +3846,17 @@
"code-point-at": { "code-point-at": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"console-control-strings": { "console-control-strings": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"core-util-is": { "core-util-is": {
"version": "1.0.2", "version": "1.0.2",
@ -3971,8 +3973,7 @@
"inherits": { "inherits": {
"version": "2.0.3", "version": "2.0.3",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"ini": { "ini": {
"version": "1.3.5", "version": "1.3.5",
@ -3984,7 +3985,6 @@
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"number-is-nan": "^1.0.0" "number-is-nan": "^1.0.0"
} }
@ -3999,7 +3999,6 @@
"version": "3.0.4", "version": "3.0.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }
@ -4007,14 +4006,12 @@
"minimist": { "minimist": {
"version": "0.0.8", "version": "0.0.8",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"minipass": { "minipass": {
"version": "2.3.5", "version": "2.3.5",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"safe-buffer": "^5.1.2", "safe-buffer": "^5.1.2",
"yallist": "^3.0.0" "yallist": "^3.0.0"
@ -4033,7 +4030,6 @@
"version": "0.5.1", "version": "0.5.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"minimist": "0.0.8" "minimist": "0.0.8"
} }
@ -4114,8 +4110,7 @@
"number-is-nan": { "number-is-nan": {
"version": "1.0.1", "version": "1.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"object-assign": { "object-assign": {
"version": "4.1.1", "version": "4.1.1",
@ -4127,7 +4122,6 @@
"version": "1.4.0", "version": "1.4.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"wrappy": "1" "wrappy": "1"
} }
@ -4213,8 +4207,7 @@
"safe-buffer": { "safe-buffer": {
"version": "5.1.2", "version": "5.1.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"safer-buffer": { "safer-buffer": {
"version": "2.1.2", "version": "2.1.2",
@ -4250,7 +4243,6 @@
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"code-point-at": "^1.0.0", "code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0", "is-fullwidth-code-point": "^1.0.0",
@ -4270,7 +4262,6 @@
"version": "3.0.1", "version": "3.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"ansi-regex": "^2.0.0" "ansi-regex": "^2.0.0"
} }
@ -4314,14 +4305,12 @@
"wrappy": { "wrappy": {
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"yallist": { "yallist": {
"version": "3.0.3", "version": "3.0.3",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
} }
} }
}, },
@ -9724,7 +9713,7 @@
"requires": { "requires": {
"underscore": "1.8.3", "underscore": "1.8.3",
"web3-core-helpers": "1.0.0-beta.37", "web3-core-helpers": "1.0.0-beta.37",
"websocket": "git://github.com/frozeman/WebSocket-Node.git#browserifyCompatible" "websocket": "git://github.com/frozeman/WebSocket-Node.git#6c72925e3f8aaaea8dc8450f97627e85263999f2"
} }
}, },
"web3-shh": { "web3-shh": {

View File

@ -53,6 +53,7 @@
}, },
"dependencies": { "dependencies": {
"@oceanprotocol/keeper-contracts": "^0.10.3", "@oceanprotocol/keeper-contracts": "^0.10.3",
"@oceanprotocol/secret-store-client": "0.0.15",
"bignumber.js": "^8.1.1", "bignumber.js": "^8.1.1",
"deprecated-decorator": "^0.1.6", "deprecated-decorator": "^0.1.6",
"node-fetch": "^2.6.0", "node-fetch": "^2.6.0",

View File

@ -53,6 +53,10 @@ export class Config {
* @type {number} * @type {number}
*/ */
public authTokenExpiration?: number public authTokenExpiration?: number
// Parity config
public parityUri?: string
public threshold?: number
} }
export default Config export default Config

View File

@ -1,3 +1,6 @@
import SecretStore from "@oceanprotocol/secret-store-client"
import SecretStoreConfig from "@oceanprotocol/secret-store-client/dist/models/SecretStoreConfig"
import Account from './Account' import Account from './Account'
import { noDidPrefixed } from '../utils' import { noDidPrefixed } from '../utils'
import { Instantiable, InstantiableConfig } from '../Instantiable.abstract' import { Instantiable, InstantiableConfig } from '../Instantiable.abstract'
@ -47,4 +50,38 @@ export class OceanSecretStore extends Instantiable {
publisher.getId() publisher.getId()
) )
} }
/**
* Decrypt an encrypted text using the stored encryption keys associated with the `did`.
* Decryption requires that the account owner has access permissions for this `did`
* @param {string} did Decentralized ID.
* @param {string} content Content to be encrypted.
* @param {string} consumer cONSUMER account.
* @return {Promise<string>} Encrypted text.
*/
public async decrypt(did: string, content: string, consumer?: Account, secretStoreUrl?: string): Promise<any> {
return await this.getSecretStoreByAccount(consumer, secretStoreUrl)
.decryptDocument(noDidPrefixed(did), content)
}
private getSecretStoreByAccount(account: Account, secretStoreUrl?: string) {
const config: any = {...this.config}
if (account) {
config.address = account.getId()
}
if (account && account.getPassword()) {
config.password = account.getPassword()
}
if (secretStoreUrl) {
config.secretStoreUri = secretStoreUrl
}
return this.getSecretStore(config)
}
private getSecretStore(config: SecretStoreConfig): SecretStore {
const {secretStoreUri, parityUri, password, address, threshold} = config
config = {secretStoreUri, parityUri, password, address, threshold}
return new SecretStore(config)
}
} }