From ec77bc0f270881e69aa68eec07e975f647dd69e8 Mon Sep 17 00:00:00 2001 From: Joel Torstensson Date: Thu, 14 Nov 2019 21:31:36 +0100 Subject: [PATCH] fix(3id): Use is3idProvider property to check for 3id rpc support --- src/3box.js | 11 +++++------ src/3id/__tests__/3id.test.js | 5 ++++- src/3id/index.js | 12 +----------- src/__tests__/idWallet.integration.js | 20 ++++++++++++++++---- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/3box.js b/src/3box.js index 0ba3c5c1..091f0e0f 100644 --- a/src/3box.js +++ b/src/3box.js @@ -463,14 +463,13 @@ class Box { let consent try { // TODO - this should be handled in the 3ID class - consent = await utils.callRpc(this._web3provider, '3id_linkManagementKey', { did }) - } catch (e) { - // an error most likely means that the provider doesn't support 3id - try { + if (this._web3provider.is3idProvider) { + consent = await utils.callRpc(this._web3provider, '3id_linkManagementKey', { did }) + } else { consent = await utils.getLinkConsent(address, did, this._web3provider) - } catch (e) { - throw new Error('Link consent message must be signed before adding data, to link address to store') } + } catch (e) { + throw new Error('Link consent message must be signed before adding data, to link address to store') } const addressType = await this._detectAddressType(address) diff --git a/src/3id/__tests__/3id.test.js b/src/3id/__tests__/3id.test.js index dc438f57..45b04340 100644 --- a/src/3id/__tests__/3id.test.js +++ b/src/3id/__tests__/3id.test.js @@ -215,7 +215,10 @@ describe('3id', () => { describe('get 3ID using IdentityWallet', () => { it('instantiate threeId with IdentityWallet', async () => { const idWallet = new IdentityWallet({ seed: ID_WALLET_SEED }) - idw3id = await ThreeId.getIdFromEthAddress(null, idWallet.get3idProvider(), ipfs) + const provider = idWallet.get3idProvider() + // monkey patch because we're not using latest version of idwallet + provider.is3idProvider = true + idw3id = await ThreeId.getIdFromEthAddress(null, provider, ipfs) expect(idw3id.DID).toBeUndefined() await idw3id.authenticate() expect(idw3id.DID).toMatchSnapshot() diff --git a/src/3id/index.js b/src/3id/index.js index a4cc05f5..701fc03f 100644 --- a/src/3id/index.js +++ b/src/3id/index.js @@ -271,7 +271,7 @@ class ThreeId { } static async getIdFromEthAddress (address, provider, ipfs, opts = {}) { - opts.has3idProv = await has3idSupport(provider) + opts.has3idProv = Boolean(provider.is3idProvider) if (opts.has3idProv) { return new ThreeId(provider, ipfs, opts) } else { @@ -304,16 +304,6 @@ class ThreeId { } } -const has3idSupport = async provider => { - if (provider.isMetaMask) return false - try { - await utils.callRpc(provider, '3id_getLink') - // no error thrown, provider has 3id support - return true - } catch (e) {} - return false -} - const createMuportDocument = (signingKey, managementKey, asymEncryptionKey) => { return { version: 1, diff --git a/src/__tests__/idWallet.integration.js b/src/__tests__/idWallet.integration.js index f9c03582..13029f65 100644 --- a/src/__tests__/idWallet.integration.js +++ b/src/__tests__/idWallet.integration.js @@ -95,7 +95,10 @@ describe('Integration Test: IdentityWallet', () => { }) it('should openBox correctly when idWallet is passed', async () => { - const box = await Box.openBox(null, idWallet.get3idProvider(), opts) + const provider = idWallet.get3idProvider() + // monkey patch because we're not using latest version of idwallet + provider.is3idProvider = true + const box = await Box.openBox(null, provider, opts) await box.syncDone await box.public.set('a', 1) await box.public.set('b', 2) @@ -109,7 +112,10 @@ describe('Integration Test: IdentityWallet', () => { it('should get same state on second openBox', async () => { publishHasEntries() - const box = await Box.openBox(null, idWallet.get3idProvider(), opts) + const provider = idWallet.get3idProvider() + // monkey patch because we're not using latest version of idwallet + provider.is3idProvider = true + const box = await Box.openBox(null, provider, opts) await box.syncDone expect(await box.public.all()).toEqual(pubState) @@ -124,7 +130,10 @@ describe('Integration Test: IdentityWallet', () => { it('should get same state on openBox with IdentityWallet opened using first authSecret', async () => { publishHasEntries() idWallet = new IdentityWallet({ authSecret: AUTH_1, ethereumAddress: ADDRESS }) - const box = await Box.openBox(null, idWallet.get3idProvider(), opts) + const provider = idWallet.get3idProvider() + // monkey patch because we're not using latest version of idwallet + provider.is3idProvider = true + const box = await Box.openBox(null, provider, opts) await box.syncDone expect(await box.public.all()).toEqual(pubState) @@ -139,7 +148,10 @@ describe('Integration Test: IdentityWallet', () => { it('should get same state on openBox with IdentityWallet opened using second authSecret', async () => { publishHasEntries() idWallet = new IdentityWallet({ authSecret: AUTH_2, ethereumAddress: ADDRESS }) - const box = await Box.openBox(null, idWallet.get3idProvider(), opts) + const provider = idWallet.get3idProvider() + // monkey patch because we're not using latest version of idwallet + provider.is3idProvider = true + const box = await Box.openBox(null, provider, opts) await box.syncDone expect(await box.public.all()).toEqual(pubState) await box.close()