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

Commit

Permalink
Merge pull request #789 from 3box/release/v1.19.0
Browse files Browse the repository at this point in the history
Release/v1.19.0
  • Loading branch information
msterle authored May 13, 2020
2 parents d14d8e3 + 82e3e71 commit 2581795
Show file tree
Hide file tree
Showing 18 changed files with 3,070 additions and 1,869 deletions.
3 changes: 3 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Release Notes

## v1.19.0 - 2020-05-12
* chore: upgrade did-jwt and did resolver libraries

## v1.18.1 - 2020-04-21
* fix: address recover signature check

Expand Down
4,562 changes: 2,844 additions & 1,718 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "3box",
"version": "1.18.1",
"version": "1.19.0",
"description": "Interact with user data",
"main": "lib/3box.js",
"directories": {
Expand Down Expand Up @@ -43,17 +43,18 @@
},
"homepage": "https://github.com/3box/3box-js#readme",
"dependencies": {
"3box-orbitdb-plugins": "^1.1.0",
"3box-orbitdb-plugins": "^2.0.0",
"3id-blockchain-utils": "^0.3.3",
"3id-connect": "0.0.1",
"3id-resolver": "^0.0.5",
"3id-connect": "0.0.2",
"3id-resolver": "^1.0.0",
"@babel/runtime": "^7.4.5",
"@ethersproject/hdnode": "5.0.0-beta.137",
"@ethersproject/wallet": "5.0.0-beta.136",
"did-jwt": "^0.2.0",
"did-jwt": "^4.2.0",
"did-resolver": "^1.1.0",
"events": "^3.0.0",
"graphql-request": "^1.8.2",
"https-did-resolver": "^0.1.0",
"https-did-resolver": "^1.0.0",
"ipfs": "^0.40.0",
"ipfs-did-document": "^1.2.3",
"ipfs-log": "^4.5.5",
Expand All @@ -62,7 +63,8 @@
"ipfs-repo": "^0.30.1",
"is-ipfs": "^0.6.3",
"js-sha256": "^0.9.0",
"muport-did-resolver": "^0.3.0",
"lodash.merge": "^4.6.2",
"muport-did-resolver": "^1.0.1",
"node-fetch": "^2.6.0",
"orbit-db": "^0.23.1",
"orbit-db-cache": "^0.3.0",
Expand Down
2 changes: 0 additions & 2 deletions src/3box.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const localstorage = require('store')
const IPFS = require('ipfs')
const registerResolver = require('3id-resolver')
const { createLink, validateLink } = require('3id-blockchain-utils')

const ThreeId = require('./3id')
Expand Down Expand Up @@ -39,7 +38,6 @@ class Box extends BoxApi {
super()
this._provider = provider
this._ipfs = ipfs
registerResolver(this._ipfs, { pin: true })
this._serverUrl = opts.addressServer || ADDRESS_SERVER_URL
/**
* @property {KeyValueStore} public access the profile store of the users 3Box
Expand Down
31 changes: 16 additions & 15 deletions src/3id/__tests__/3id.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const ThreeId = require('../index')
const testUtils = require('../../__tests__/testUtils')
const localstorage = require('store')
const { verifyJWT } = require('did-jwt')
const resolve = require('did-resolver').default
const registerResolver = require('3id-resolver')
const { Resolver } = require('did-resolver')
const get3IdResolver = require('3id-resolver').getResolver
const IdentityWallet = require('identity-wallet')
const OdbStorage = require('orbit-db-storage-adapter')
const OdbKeystore = require('orbit-db-keystore')
Expand Down Expand Up @@ -45,11 +45,12 @@ const mockedUtils = require('../../utils/index')

describe('3id', () => {

let threeId, ipfs, idw3id, keystore
let threeId, ipfs, idw3id, keystore, resolver

beforeAll(async () => {
ipfs = await testUtils.initIPFS(6)
registerResolver(ipfs)
const threeIdResolver = get3IdResolver(ipfs)
resolver = new Resolver(threeIdResolver)
const levelDown = OdbStorage(null, {})
const keystorePath = path.join('./tmp', `/${utils.randInt(1000000)}`, '/keystore')
const keyStorage = await levelDown.createStore(keystorePath)
Expand All @@ -73,7 +74,7 @@ describe('3id', () => {
expect(threeId.DID).toMatchSnapshot()
expect(opts.consentCallback).toHaveBeenCalledWith(true)
expect(mockedUtils.openBoxConsent).toHaveBeenCalledTimes(1)
expect(await resolve(threeId.DID)).toMatchSnapshot()
expect(await resolver.resolve(threeId.DID)).toMatchSnapshot()
})

it('should create the same identity given the same address', async () => {
Expand Down Expand Up @@ -107,7 +108,7 @@ describe('3id', () => {
expect(contentSignatureThreeId.DID).toMatchSnapshot()
expect(opts.consentCallback).toHaveBeenCalledWith(true)
expect(mockedUtils.openBoxConsent).toHaveBeenCalledTimes(0)
expect(await resolve(contentSignatureThreeId.DID)).toMatchSnapshot()
expect(await resolver.resolve(contentSignatureThreeId.DID)).toMatchSnapshot()
})

it('should create the same identity given the same address and contentSignature', async () => {
Expand Down Expand Up @@ -139,7 +140,7 @@ describe('3id', () => {
expect(mockedUtils.openSpaceConsent).toHaveBeenCalledWith(ADDR_1, ETHEREUM, SPACE_1)
let subDid = threeId.getSubDID(SPACE_1)
expect(subDid).toMatchSnapshot()
expect(await resolve(subDid)).toMatchSnapshot()
expect(await resolver.resolve(subDid)).toMatchSnapshot()

authenticated = await threeId.isAuthenticated([SPACE_1])
expect(authenticated).toEqual(true)
Expand All @@ -153,7 +154,7 @@ describe('3id', () => {
expect(mockedUtils.openSpaceConsent).toHaveBeenCalledWith(ADDR_1, ETHEREUM, SPACE_2)
subDid = threeId.getSubDID(SPACE_2)
expect(subDid).toMatchSnapshot()
expect(await resolve(subDid)).toMatchSnapshot()
expect(await resolver.resolve(subDid)).toMatchSnapshot()

authenticated = await threeId.isAuthenticated([SPACE_2])
expect(authenticated).toEqual(true)
Expand Down Expand Up @@ -203,15 +204,15 @@ describe('3id', () => {
iat: null,
data: 'some data'
})
await expect(verifyJWT(jwt)).resolves.toMatchSnapshot()
await expect(verifyJWT(jwt, { resolver })).resolves.toMatchSnapshot()
})

it('should sign jwts correctly with subDID', async () => {
const jwt = await threeId.signJWT({
iat: null,
data: 'some data'
}, { space: SPACE_1 })
await expect(verifyJWT(jwt, { auth: true })).resolves.toMatchSnapshot()
await expect(verifyJWT(jwt, { resolver, auth: true })).resolves.toMatchSnapshot()
})
})

Expand All @@ -237,20 +238,20 @@ describe('3id', () => {
expect(idw3id.DID).toMatchSnapshot()
expect(await idw3id.getPublicKeys()).toMatchSnapshot()
expect(await idw3id.getPublicKeys(null, true)).toMatchSnapshot()
expect(await resolve(idw3id.DID)).toMatchSnapshot()
expect(await resolver.resolve(idw3id.DID)).toMatchSnapshot()
})

describe('keyring logic', () => {
it('should init space keyrings correctly', async () => {
await idw3id.authenticate([SPACE_1])
let subDid = idw3id.getSubDID(SPACE_1)
expect(subDid).toMatchSnapshot()
expect(await resolve(subDid)).toMatchSnapshot()
expect(await resolver.resolve(subDid)).toMatchSnapshot()

await idw3id.authenticate([SPACE_2])
subDid = idw3id.getSubDID(SPACE_2)
expect(subDid).toMatchSnapshot()
expect(await resolve(subDid)).toMatchSnapshot()
expect(await resolver.resolve(subDid)).toMatchSnapshot()
})

it('should get public keys correctly', async () => {
Expand Down Expand Up @@ -289,15 +290,15 @@ describe('3id', () => {
iat: null,
data: 'some data'
})
await expect(verifyJWT(jwt)).resolves.toMatchSnapshot()
await expect(verifyJWT(jwt, { resolver })).resolves.toMatchSnapshot()
})

it('should sign jwts correctly with subDID', async () => {
const jwt = await idw3id.signJWT({
iat: null,
data: 'some data'
}, { space: SPACE_1 })
await expect(verifyJWT(jwt, { auth: true })).resolves.toMatchSnapshot()
await expect(verifyJWT(jwt, { resolver, auth: true })).resolves.toMatchSnapshot()
})
})
})
Expand Down
7 changes: 7 additions & 0 deletions src/3id/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const { mnemonicToSeed, entropyToMnemonic } = require('@ethersproject/hdnode')
const EventEmitter = require('events')
const didJWT = require('did-jwt')
const { Resolver } = require('did-resolver')
const get3IdResolver = require('3id-resolver').getResolver
const getMuportResolver = require('muport-did-resolver').getResolver
const DidDocument = require('ipfs-did-document')
const localstorage = require('store')
const Identities = require('orbit-db-identity-provider')
Expand All @@ -26,6 +29,10 @@ class ThreeId {
this._muportIpfs = opts.muportIpfs || MUPORT_IPFS
this._pubkeys = { spaces: {} }
this._keystore = keystore
const threeIdResolver = get3IdResolver(ipfs, { pin: true })
const muportResolver = getMuportResolver(ipfs)
const resolver = new Resolver({...threeIdResolver, ...muportResolver})
OdbIdentityProvider.setDidResolver(resolver)
}

startUpdatePolling () {
Expand Down
8 changes: 7 additions & 1 deletion src/__mocks__/3ID.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const didJWT = require('did-jwt')
const { Resolver } = require('did-resolver')
const Identities = require('orbit-db-identity-provider')
const { OdbIdentityProvider } = require('3box-orbitdb-plugins')
Identities.addIdentityProvider(OdbIdentityProvider)
Expand All @@ -24,6 +25,11 @@ const didResolverMock = async (did) => {
}
}

const mockDidResolver = new Resolver({
'3': didResolverMock,
muport: didResolverMock
})

const threeIDMockFactory = (did) => {
const signJWT = (payload) => {
return didJWT.createJWT(payload, {
Expand Down Expand Up @@ -57,4 +63,4 @@ const threeIDMockFactory = (did) => {
}
}

module.exports = { threeIDMockFactory, didResolverMock }
module.exports = { threeIDMockFactory, didResolverMock, mockDidResolver }
68 changes: 42 additions & 26 deletions src/__tests__/3box.test.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
const testUtils = require('./testUtils')
const OrbitDB = require('orbit-db')
const jsdom = require('jsdom')
const didJWT = require('did-jwt')
const Box = require('../3box')
global.window = new jsdom.JSDOM().window
const { registerMethod } = require('did-resolver')
const AccessControllers = require('orbit-db-access-controllers')
const { LegacyIPFS3BoxAccessController } = require('3box-orbitdb-plugins')
AccessControllers.addAccessController({ AccessController: LegacyIPFS3BoxAccessController })
const { threeIDMockFactory, didResolverMock } = require('../__mocks__/3ID')

registerMethod('3', didResolverMock)
registerMethod('muport', didResolverMock)

const DID1 = 'did:3:zdpuAsaK9YsqpphSBeQvfrKAjs8kF7vUX4Y3kMkMRgEQigzCt'
const DID2 = 'did:3:zdpuB2DcKQKNBDz3difEYxjTupsho5VuPCLgRbRunXqhmrJaX'

const randomStr = () => `${Math.floor(Math.random() * 1000000)}`

jest.mock('3id-resolver')
jest.mock('../3id', () => {
const randomStr = () => `${Math.floor(Math.random() * 1000000)}`
const { threeIDMockFactory, didResolverMock } = require('../__mocks__/3ID')
Expand Down Expand Up @@ -51,6 +30,7 @@ jest.mock('../3id', () => {
isLoggedIn: jest.fn(() => { return loggedIn })
}
})

jest.mock('../publicStore', () => {
return jest.fn(() => {
return {
Expand All @@ -63,6 +43,7 @@ jest.mock('../publicStore', () => {
}
})
})

jest.mock('../privateStore', () => {
return jest.fn(() => {
return {
Expand All @@ -71,6 +52,7 @@ jest.mock('../privateStore', () => {
}
})
})

jest.mock('../space', () => {
return jest.fn(name => {
let isOpen = false
Expand All @@ -85,6 +67,7 @@ jest.mock('../space', () => {
}
})
})

jest.mock('../replicator', () => {
const randInt = max => Math.floor(Math.random() * max)

Expand Down Expand Up @@ -141,13 +124,20 @@ jest.mock('3id-blockchain-utils', () => ({
}))

jest.mock('../utils/verifier')

jest.mock('../utils/index', () => {
const actualUtils = jest.requireActual('../utils/index')
const { didResolverMock } = require('../__mocks__/3ID')
const { Resolver } = require('did-resolver')
const sha256 = require('js-sha256').sha256
const { verifyJWT } = require('did-jwt')
let addressMap = {}
let linkmap = {}
let linkNum = 0
const resolver = new Resolver({
'3': didResolverMock,
muport: didResolverMock
})
return {
getMessageConsent: actualUtils.getMessageConsent,
openBoxConsent: jest.fn(async () => '0x8726348762348723487238476238746827364872634876234876234'),
Expand All @@ -157,7 +147,7 @@ jest.mock('../utils/index', () => {
let x, hash, did
switch (lastPart) {
case 'odbAddress': // put odbAddress
const payload = (await verifyJWT(body.address_token)).payload
const payload = (await verifyJWT(body.address_token, { resolver })).payload
addressMap[payload.iss] = payload.rootStoreAddress
return { status: 'success', data: {} }
case 'link': // make a link
Expand Down Expand Up @@ -197,6 +187,36 @@ jest.mock('../utils/index', () => {
}
})

jest.mock('3id-resolver', () => {
const { didResolverMock } = require('../__mocks__/3ID')
return {
getResolver: () => ({'3': didResolverMock})
}
})

jest.mock('muport-did-resolver', () => {
const { didResolverMock } = require('../__mocks__/3ID')
return {
getResolver: () => ({'muport': didResolverMock})
}
})

const testUtils = require('./testUtils')
const OrbitDB = require('orbit-db')
const jsdom = require('jsdom')
const didJWT = require('did-jwt')
const Box = require('../3box')
global.window = new jsdom.JSDOM().window
const { Resolver } = require('did-resolver')
const AccessControllers = require('orbit-db-access-controllers')
const { LegacyIPFS3BoxAccessController } = require('3box-orbitdb-plugins')
AccessControllers.addAccessController({ AccessController: LegacyIPFS3BoxAccessController })

const DID1 = 'did:3:zdpuAsaK9YsqpphSBeQvfrKAjs8kF7vUX4Y3kMkMRgEQigzCt'
const DID2 = 'did:3:zdpuB2DcKQKNBDz3difEYxjTupsho5VuPCLgRbRunXqhmrJaX'

const randomStr = () => `${Math.floor(Math.random() * 1000000)}`

const mockedUtils = require('../utils/index')
const { createLink } = require('3id-blockchain-utils')
const mocked3id = require('../3id')
Expand Down Expand Up @@ -523,10 +543,6 @@ describe('3Box', () => {

describe('verify eth', () => {
let verifier = jest.requireActual('../utils/verifier')
// re register mock resolvers, as the real ones are registered in verifier module
registerMethod('3', didResolverMock)
registerMethod('muport', didResolverMock)


const ethProof = {
consent_msg: 'Create a new 3Box profile\n\n- \nYour unique profile ID is did:muport:Qmb9E8wLqjfAqfKhideoApU5g26Yz2Q2bSp6MSZmc5WrNr',
Expand Down
Loading

0 comments on commit 2581795

Please sign in to comment.