mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
added secret store
This commit is contained in:
parent
dd227e74ed
commit
fb5dcaf522
34
package-lock.json
generated
34
package-lock.json
generated
@ -125,9 +125,9 @@
|
|||||||
"integrity": "sha512-UVt9m9WmFm4mTDWmMekT8lhBh2hWr2baEVnF0dEN3OL5BDAWoynFQeeKtUqTepVuOVgNy5bHYKLiHkCWzbOEqA=="
|
"integrity": "sha512-UVt9m9WmFm4mTDWmMekT8lhBh2hWr2baEVnF0dEN3OL5BDAWoynFQeeKtUqTepVuOVgNy5bHYKLiHkCWzbOEqA=="
|
||||||
},
|
},
|
||||||
"@oceanprotocol/secret-store-client": {
|
"@oceanprotocol/secret-store-client": {
|
||||||
"version": "0.0.4",
|
"version": "0.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/secret-store-client/-/secret-store-client-0.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/@oceanprotocol/secret-store-client/-/secret-store-client-0.0.6.tgz",
|
||||||
"integrity": "sha512-VHzcBkZ5ZKVdLKERshvT48jlWeZTX1x1tDgbqhc1x0nH8H6HC8SZ+Ak834S2t8XTswgTVWygxn8g51jtPy5+BQ==",
|
"integrity": "sha512-dJQ7rWQdAkrM79gvLYrT8vm5ZOrjW7XbQR/d2IBIQNS6t09826wZW3Y9kwaiQvKBUIOI9LhbwVuD4Hc0IuXJnQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"jayson": "^2.0.6",
|
"jayson": "^2.0.6",
|
||||||
"node-fetch": "^2.2.0"
|
"node-fetch": "^2.2.0"
|
||||||
@ -2002,6 +2002,11 @@
|
|||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz",
|
||||||
"integrity": "sha1-sX0I0ya0Qj5Wjv9xn5GwscvfafE="
|
"integrity": "sha1-sX0I0ya0Qj5Wjv9xn5GwscvfafE="
|
||||||
|
},
|
||||||
|
"uuid": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "http://registry.npmjs.org/uuid/-/uuid-2.0.1.tgz",
|
||||||
|
"integrity": "sha1-wqMN7bPlNdcsz4LjQ5QaULqFM6w="
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -3644,11 +3649,6 @@
|
|||||||
"version": "10.12.0",
|
"version": "10.12.0",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.0.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.0.tgz",
|
||||||
"integrity": "sha512-3TUHC3jsBAB7qVRGxT6lWyYo2v96BMmD2PTcl47H25Lu7UXtFH/2qqmKiVrnel6Ne//0TFYf6uvNX+HW2FRkLQ=="
|
"integrity": "sha512-3TUHC3jsBAB7qVRGxT6lWyYo2v96BMmD2PTcl47H25Lu7UXtFH/2qqmKiVrnel6Ne//0TFYf6uvNX+HW2FRkLQ=="
|
||||||
},
|
|
||||||
"uuid": {
|
|
||||||
"version": "3.3.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz",
|
|
||||||
"integrity": "sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA=="
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -7411,9 +7411,9 @@
|
|||||||
"integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM="
|
"integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM="
|
||||||
},
|
},
|
||||||
"uuid": {
|
"uuid": {
|
||||||
"version": "2.0.1",
|
"version": "3.3.2",
|
||||||
"resolved": "http://registry.npmjs.org/uuid/-/uuid-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz",
|
||||||
"integrity": "sha1-wqMN7bPlNdcsz4LjQ5QaULqFM6w="
|
"integrity": "sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA=="
|
||||||
},
|
},
|
||||||
"v8-compile-cache": {
|
"v8-compile-cache": {
|
||||||
"version": "2.0.2",
|
"version": "2.0.2",
|
||||||
@ -7602,6 +7602,13 @@
|
|||||||
"setimmediate": "1.0.4",
|
"setimmediate": "1.0.4",
|
||||||
"uuid": "2.0.1",
|
"uuid": "2.0.1",
|
||||||
"xmlhttprequest": "1.8.0"
|
"xmlhttprequest": "1.8.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"uuid": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "http://registry.npmjs.org/uuid/-/uuid-2.0.1.tgz",
|
||||||
|
"integrity": "sha1-wqMN7bPlNdcsz4LjQ5QaULqFM6w="
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"hash.js": {
|
"hash.js": {
|
||||||
@ -7641,6 +7648,11 @@
|
|||||||
"elliptic": "^6.4.0",
|
"elliptic": "^6.4.0",
|
||||||
"xhr-request-promise": "^0.1.2"
|
"xhr-request-promise": "^0.1.2"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"uuid": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "http://registry.npmjs.org/uuid/-/uuid-2.0.1.tgz",
|
||||||
|
"integrity": "sha1-wqMN7bPlNdcsz4LjQ5QaULqFM6w="
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -50,13 +50,14 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@oceanprotocol/keeper-contracts": "^0.3.3",
|
"@oceanprotocol/keeper-contracts": "^0.3.3",
|
||||||
"@oceanprotocol/secret-store-client": "^0.0.4",
|
"@oceanprotocol/secret-store-client": "^0.0.6",
|
||||||
"bignumber.js": "^7.2.1",
|
"bignumber.js": "^7.2.1",
|
||||||
"eth-crypto": "^1.2.4",
|
"eth-crypto": "^1.2.4",
|
||||||
"eth-ecies": "^1.0.3",
|
"eth-ecies": "^1.0.3",
|
||||||
"ethereumjs-util": "^6.0.0",
|
"ethereumjs-util": "^6.0.0",
|
||||||
"jsonwebtoken": "^8.3.0",
|
"jsonwebtoken": "^8.3.0",
|
||||||
"node-fetch": "^2.2.0",
|
"node-fetch": "^2.2.0",
|
||||||
|
"uuid": "^3.3.2",
|
||||||
"web3": "1.0.0-beta.36",
|
"web3": "1.0.0-beta.36",
|
||||||
"web3-utils": "1.0.0-beta.36"
|
"web3-utils": "1.0.0-beta.36"
|
||||||
},
|
},
|
||||||
|
@ -15,7 +15,6 @@ export default class AquariusConnectorProvider {
|
|||||||
if (!AquariusConnectorProvider.connector) {
|
if (!AquariusConnectorProvider.connector) {
|
||||||
AquariusConnectorProvider.connector = new AquariusConnector()
|
AquariusConnectorProvider.connector = new AquariusConnector()
|
||||||
}
|
}
|
||||||
Logger.log("getting", typeof AquariusConnectorProvider.connector.constructor.name)
|
|
||||||
return AquariusConnectorProvider.connector
|
return AquariusConnectorProvider.connector
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ export default class OceanAuth extends ContractBase {
|
|||||||
|
|
||||||
public async initiateAccessRequest(asset: Asset, publicKey: string,
|
public async initiateAccessRequest(asset: Asset, publicKey: string,
|
||||||
timeout: number, buyerAddress: string): Promise<Receipt> {
|
timeout: number, buyerAddress: string): Promise<Receipt> {
|
||||||
const args = [asset.getId(), asset.publisher.getId(), publicKey, timeout]
|
const args = ["0x" + asset.getId(), asset.publisher.getId(), publicKey, timeout]
|
||||||
return this.sendTransaction("initiateAccessRequest", buyerAddress, args)
|
return this.sendTransaction("initiateAccessRequest", buyerAddress, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ export default class OceanMarket extends ContractBase {
|
|||||||
|
|
||||||
// call functions (costs no gas)
|
// call functions (costs no gas)
|
||||||
public async isAssetActive(assetId: string): Promise<boolean> {
|
public async isAssetActive(assetId: string): Promise<boolean> {
|
||||||
return this.call("checkAsset", [assetId])
|
return this.call("checkAsset", ["0x" + assetId])
|
||||||
}
|
}
|
||||||
|
|
||||||
public async verifyOrderPayment(orderId: string): Promise<boolean> {
|
public async verifyOrderPayment(orderId: string): Promise<boolean> {
|
||||||
@ -21,7 +21,7 @@ export default class OceanMarket extends ContractBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async getAssetPrice(assetId: string): Promise<number> {
|
public async getAssetPrice(assetId: string): Promise<number> {
|
||||||
return this.call("getAssetPrice", [assetId])
|
return this.call("getAssetPrice", ["0x" + assetId])
|
||||||
.then((price: string) => new BigNumber(price).toNumber())
|
.then((price: string) => new BigNumber(price).toNumber())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ export default class OceanMarket extends ContractBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async register(assetId: string, price: number, publisherAddress: string): Promise<Receipt> {
|
public async register(assetId: string, price: number, publisherAddress: string): Promise<Receipt> {
|
||||||
return this.sendTransaction("register", publisherAddress, [assetId, price])
|
return this.sendTransaction("register", publisherAddress, ["0x" + assetId, price])
|
||||||
}
|
}
|
||||||
|
|
||||||
public async payOrder(order: Order, publisherAddress: string,
|
public async payOrder(order: Order, publisherAddress: string,
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
import * as Web3 from "web3"
|
import * as Web3 from "web3"
|
||||||
import ConfigProvider from "../ConfigProvider"
|
import ConfigProvider from "../ConfigProvider"
|
||||||
import Logger from "../utils/Logger"
|
|
||||||
|
|
||||||
Logger.log("using web3", Web3.version)
|
|
||||||
|
|
||||||
export default class Web3Provider {
|
export default class Web3Provider {
|
||||||
|
|
||||||
|
8
src/ocean/IdGenerator.ts
Normal file
8
src/ocean/IdGenerator.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import * as v4 from "uuid/v4"
|
||||||
|
|
||||||
|
export default class IdGenerator {
|
||||||
|
public static generateId(): string {
|
||||||
|
const id = `${v4()}${v4()}`
|
||||||
|
return id.replace(/-/g, "")
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,7 @@ import Logger from "../utils/Logger"
|
|||||||
import Account from "./Account"
|
import Account from "./Account"
|
||||||
import Asset from "./Asset"
|
import Asset from "./Asset"
|
||||||
import Order from "./Order"
|
import Order from "./Order"
|
||||||
|
import IdGenerator from "./IdGenerator"
|
||||||
|
|
||||||
export default class Ocean {
|
export default class Ocean {
|
||||||
|
|
||||||
@ -15,7 +16,6 @@ export default class Ocean {
|
|||||||
|
|
||||||
if (!Ocean.instance) {
|
if (!Ocean.instance) {
|
||||||
ConfigProvider.setConfig(config)
|
ConfigProvider.setConfig(config)
|
||||||
SecretStoreProvider.configure(config)
|
|
||||||
Ocean.instance = new Ocean(await Keeper.getInstance())
|
Ocean.instance = new Ocean(await Keeper.getInstance())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,12 +42,8 @@ export default class Ocean {
|
|||||||
|
|
||||||
const secretStore = SecretStoreProvider.getSecretStore()
|
const secretStore = SecretStoreProvider.getSecretStore()
|
||||||
|
|
||||||
const id = Math.random().toString(10)
|
const assetId = IdGenerator.generateId()
|
||||||
Logger.log("id", id)
|
|
||||||
|
|
||||||
const assetId = (await market.generateId(id)).replace("0x", "")
|
|
||||||
|
|
||||||
Logger.log(assetId.length)
|
|
||||||
const encryptedDocument = await secretStore.encryptDocument(assetId, asset)
|
const encryptedDocument = await secretStore.encryptDocument(assetId, asset)
|
||||||
|
|
||||||
const decryptedDocument = await secretStore.decryptDocument(assetId, encryptedDocument)
|
const decryptedDocument = await secretStore.decryptDocument(assetId, encryptedDocument)
|
||||||
|
@ -1,24 +1,21 @@
|
|||||||
import SecretStore from "@oceanprotocol/secret-store-client"
|
import SecretStore from "@oceanprotocol/secret-store-client"
|
||||||
|
import ConfigProvider from "../ConfigProvider"
|
||||||
|
|
||||||
export default class SecretStoreProvider {
|
export default class SecretStoreProvider {
|
||||||
|
|
||||||
|
public static setSecretStore(secretStore: SecretStore) {
|
||||||
|
|
||||||
|
SecretStoreProvider.secretStore = secretStore
|
||||||
|
}
|
||||||
|
|
||||||
public static getSecretStore() {
|
public static getSecretStore() {
|
||||||
|
|
||||||
if (!SecretStoreProvider.secretStore) {
|
if (!SecretStoreProvider.secretStore) {
|
||||||
SecretStoreProvider.secretStore = new SecretStore(SecretStoreProvider.config)
|
SecretStoreProvider.secretStore = new SecretStore(ConfigProvider.getConfig())
|
||||||
}
|
}
|
||||||
|
|
||||||
return SecretStoreProvider.secretStore
|
return SecretStoreProvider.secretStore
|
||||||
}
|
}
|
||||||
|
|
||||||
public static configure(config: {
|
|
||||||
secretStoreUri: string, parityUri: string,
|
|
||||||
address: string, password: string, threshold?: number,
|
|
||||||
}) {
|
|
||||||
|
|
||||||
SecretStoreProvider.config = config
|
|
||||||
}
|
|
||||||
|
|
||||||
private static config: any
|
|
||||||
private static secretStore: SecretStore
|
private static secretStore: SecretStore
|
||||||
}
|
}
|
||||||
|
@ -4,30 +4,32 @@ import AquariusConnectorProvider from "../../src/aquarius/AquariusConnectorProvi
|
|||||||
import config from "../config"
|
import config from "../config"
|
||||||
import AquariusConnectorMock from "../mocks/AquariusConnector.mock"
|
import AquariusConnectorMock from "../mocks/AquariusConnector.mock"
|
||||||
|
|
||||||
before(() => {
|
|
||||||
AquariusConnectorProvider.setConnector(new AquariusConnectorMock())
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("Aquarius", () => {
|
describe("Aquarius", () => {
|
||||||
|
|
||||||
describe("#queryMetadata()", async () => {
|
before(() => {
|
||||||
|
AquariusConnectorProvider.setConnector(new AquariusConnectorMock())
|
||||||
|
})
|
||||||
|
|
||||||
const aquarius: Aquarius = new Aquarius(config)
|
describe("#queryMetadata()", () => {
|
||||||
|
|
||||||
const query = {
|
it("should query metadata", async () => {
|
||||||
offset: 100,
|
const aquarius: Aquarius = new Aquarius(config)
|
||||||
page: 0,
|
|
||||||
query: {
|
|
||||||
value: 1,
|
|
||||||
},
|
|
||||||
sort: {
|
|
||||||
value: 1,
|
|
||||||
},
|
|
||||||
text: "Office",
|
|
||||||
}
|
|
||||||
|
|
||||||
const result: any[] = await aquarius.queryMetadata(query)
|
const query = {
|
||||||
assert(result)
|
offset: 100,
|
||||||
|
page: 0,
|
||||||
|
query: {
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
sort: {
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
text: "Office",
|
||||||
|
}
|
||||||
|
|
||||||
|
const result: any[] = await aquarius.queryMetadata(query)
|
||||||
|
assert(result)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
16
test/mocks/SecretStore.mock.ts
Normal file
16
test/mocks/SecretStore.mock.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import SecretStore from "@oceanprotocol/secret-store-client"
|
||||||
|
|
||||||
|
export default class SecretStoreMock extends SecretStore {
|
||||||
|
|
||||||
|
public async encryptDocument(documentId, document: any) {
|
||||||
|
|
||||||
|
return "0x283asdgahd1t371t23h"
|
||||||
|
}
|
||||||
|
|
||||||
|
public async decryptDocument(documentId, encryptedDocument: any) {
|
||||||
|
|
||||||
|
return {
|
||||||
|
doc: "test",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
26
test/ocean/IdGenerator.test.ts
Normal file
26
test/ocean/IdGenerator.test.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import * as assert from "assert"
|
||||||
|
import IdGenerator from "../../src/ocean/IdGenerator"
|
||||||
|
|
||||||
|
describe("IdGenerator", () => {
|
||||||
|
|
||||||
|
describe("#generateId()", () => {
|
||||||
|
|
||||||
|
it("should generate an id", async () => {
|
||||||
|
|
||||||
|
const id = IdGenerator.generateId()
|
||||||
|
assert(id)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should generate an id that is 64 chars long", async () => {
|
||||||
|
|
||||||
|
const id: string = IdGenerator.generateId()
|
||||||
|
assert(id.length === 64, id)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should not contain -", async () => {
|
||||||
|
|
||||||
|
const id: string = IdGenerator.generateId()
|
||||||
|
assert(id.indexOf("-") === -1)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
@ -6,8 +6,10 @@ import Account from "../../src/ocean/Account"
|
|||||||
import Asset from "../../src/ocean/Asset"
|
import Asset from "../../src/ocean/Asset"
|
||||||
import Ocean from "../../src/ocean/Ocean"
|
import Ocean from "../../src/ocean/Ocean"
|
||||||
import Order from "../../src/ocean/Order"
|
import Order from "../../src/ocean/Order"
|
||||||
|
import SecretStoreProvider from "../../src/secretstore/SecretStoreProvider"
|
||||||
import config from "../config"
|
import config from "../config"
|
||||||
import AquariusMock from "../mocks/Aquarius.mock"
|
import AquariusMock from "../mocks/Aquarius.mock"
|
||||||
|
import SecretStoreMock from "../mocks/SecretStore.mock"
|
||||||
|
|
||||||
let ocean: Ocean
|
let ocean: Ocean
|
||||||
let accounts: Account[]
|
let accounts: Account[]
|
||||||
@ -24,6 +26,7 @@ describe("Ocean", () => {
|
|||||||
before(async () => {
|
before(async () => {
|
||||||
ConfigProvider.setConfig(config)
|
ConfigProvider.setConfig(config)
|
||||||
AquariusProvider.setAquarius(new AquariusMock(config))
|
AquariusProvider.setAquarius(new AquariusMock(config))
|
||||||
|
SecretStoreProvider.setSecretStore(new SecretStoreMock(config))
|
||||||
await ContractHandler.deployContracts()
|
await ContractHandler.deployContracts()
|
||||||
ocean = await Ocean.getInstance(config)
|
ocean = await Ocean.getInstance(config)
|
||||||
accounts = await ocean.getAccounts()
|
accounts = await ocean.getAccounts()
|
||||||
@ -62,10 +65,9 @@ describe("Ocean", () => {
|
|||||||
|
|
||||||
const assetId: string = await ocean.register(testAsset)
|
const assetId: string = await ocean.register(testAsset)
|
||||||
|
|
||||||
assert(assetId.length === 66)
|
assert(assetId.length === 64)
|
||||||
assert(assetId.startsWith("0x"))
|
assert(!assetId.startsWith("0x"))
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("#getOrdersByConsumer()", () => {
|
describe("#getOrdersByConsumer()", () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user