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

Commit

Permalink
fix: force 3id existing state to expected form
Browse files Browse the repository at this point in the history
  • Loading branch information
zachferland committed Mar 20, 2019
1 parent 6c34e56 commit 1ea5e8e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/3id/__tests__/3id.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const ThreeId = require('../index')
const localstorage = require('store')

jest.mock('../../utils/index', () => {
const sha256 = require('js-sha256').sha256
Expand All @@ -13,6 +14,11 @@ jest.mock('../../utils/index', () => {
}
})

const STORAGE_KEY = 'serialized3id_'
const clearLocalStorage3id = (address) => {
localstorage.remove(STORAGE_KEY + address)
}

const ADDR_1 = '0x12345'
const ADDR_2 = '0xabcde'
const ADDR_1_STATE_1 = '{"managementAddress":"0x12345","seed":"0xbc95bb0aeb7e5c7a9519ef066d4b60a944373ba1163b0c962a043bebec1579ef33e0ef4f63c0888d7a8ec95df34ada58fb739b2a4d3b44362747e6b193db9af2","spaceSeeds":{}}'
Expand Down Expand Up @@ -48,6 +54,14 @@ describe('3id', () => {
expect(mockedUtils.openBoxConsent).toHaveBeenCalledTimes(1)
})

it('should create the same identity given the same address', async () => {
// did is mocked, so compares serialized state
const threeId1 = await ThreeId.getIdFromEthAddress('0xabcde1', ETHEREUM, ipfsMock)
clearLocalStorage3id('0xabcde1')
const threeId2 = await ThreeId.getIdFromEthAddress('0xABCDE1', ETHEREUM, ipfsMock)
expect(threeId1.serializeState()).toEqual(threeId2.serializeState())
})

it('should create a new identity for other eth addr', async () => {
const opts = { consentCallback: jest.fn() }
threeId = await ThreeId.getIdFromEthAddress(ADDR_2, ETHEREUM, ipfsMock, opts)
Expand Down Expand Up @@ -117,4 +131,3 @@ describe('3id', () => {
})
})
})

5 changes: 4 additions & 1 deletion src/3id/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ class ThreeId {

_init3id (serializeState) {
const state = JSON.parse(serializeState)
this.managementAddress = state.managementAddress
// TODO remove toLowerCase() in future, should be sanitized elsewhere
// this forces existing state to correct state so that address <->
// rootstore relation holds
this.managementAddress = state.managementAddress.toLowerCase()
this._mainKeyring = new Keyring(state.seed)
Object.keys(state.spaceSeeds).map(name => {
this._keyrings[name] = new Keyring(state.spaceSeeds[name])
Expand Down

0 comments on commit 1ea5e8e

Please sign in to comment.