Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
fix(3id): Use is3idProvider property to check for 3id rpc support
Browse files Browse the repository at this point in the history
  • Loading branch information
oed committed Nov 14, 2019
1 parent 18990f7 commit ec77bc0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
11 changes: 5 additions & 6 deletions src/3box.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion src/3id/__tests__/3id.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 1 addition & 11 deletions src/3id/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
20 changes: 16 additions & 4 deletions src/__tests__/idWallet.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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()
Expand Down

0 comments on commit ec77bc0

Please sign in to comment.