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 #557 from 3box/hotfix/v1.10.6
Browse files Browse the repository at this point in the history
Hotfix/v1.10.6
  • Loading branch information
oed authored Aug 15, 2019
2 parents 8798c91 + 1651023 commit 22c509f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 23 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ idUtils.verifyClaim(claim)
* _static_
* [.idUtils](#Box.idUtils)
* [.verifyClaim](#Box.idUtils.verifyClaim) ⇒ <code>Object</code>
* [.isMuportDID(address)](#Box.idUtils.isMuportDID) ⇒ <code>\*</code> \| <code>boolean</code>
* [.isSupportedDID(did)](#Box.idUtils.isSupportedDID) ⇒ <code>\*</code> \| <code>boolean</code>
* [.isClaim(claim, opts)](#Box.idUtils.isClaim) ⇒ <code>Promise.&lt;boolean&gt;</code>
* [.getProfile(address, opts)](#Box.getProfile) ⇒ <code>Object</code>
* [.getProfiles(address, opts)](#Box.getProfiles) ⇒ <code>Object</code>
Expand Down Expand Up @@ -451,7 +451,7 @@ A module to verify & validate claims
* [.idUtils](#Box.idUtils)
* [.verifyClaim](#Box.idUtils.verifyClaim) ⇒ <code>Object</code>
* [.isMuportDID(address)](#Box.idUtils.isMuportDID) ⇒ <code>\*</code> \| <code>boolean</code>
* [.isSupportedDID(did)](#Box.idUtils.isSupportedDID) ⇒ <code>\*</code> \| <code>boolean</code>
* [.isClaim(claim, opts)](#Box.idUtils.isClaim) ⇒ <code>Promise.&lt;boolean&gt;</code>
<a name="Box.idUtils.verifyClaim"></a>
Expand All @@ -469,17 +469,17 @@ See https://github.com/uport-project/did-jwt/ for more details.
| opts | <code>Object</code> | Optional parameters |
| opts.audience | <code>string</code> | The DID of the JWT's audience |
<a name="Box.idUtils.isMuportDID"></a>
<a name="Box.idUtils.isSupportedDID"></a>
##### idUtils.isMuportDID(address) ⇒ <code>\*</code> \| <code>boolean</code>
##### idUtils.isSupportedDID(did) ⇒ <code>\*</code> \| <code>boolean</code>
Check whether a string is a muport did or not
**Kind**: static method of [<code>idUtils</code>](#Box.idUtils)
**Returns**: <code>\*</code> \| <code>boolean</code> - Whether the address is a muport did or not
**Returns**: <code>\*</code> \| <code>boolean</code> - Whether the did is a supported did or not
| Param | Type | Description |
| --- | --- | --- |
| address | <code>String</code> | A string containing a user profile address |
| did | <code>String</code> | A string containing a user did |
<a name="Box.idUtils.isClaim"></a>
Expand Down
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.10.6 - 2019-08-13
* fix: Correctly encode DIDs on api calls

## v1.10.5 - 2019-08-02
* fix: made onSyncDone logic more robust

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "3box",
"version": "1.10.5",
"version": "1.10.6",
"description": "Interact with user data",
"main": "lib/3box.js",
"directories": {
Expand Down
11 changes: 6 additions & 5 deletions src/__tests__/idUtils.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
const { isMuportDID, isClaim, verifyClaim } = require('../utils/id')
const { isSupportedDID, isClaim, verifyClaim } = require('../utils/id')

const CLAIM_1 = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJpYXQiOjE1NTQ5NzI2MDksImV4cCI6MTk1NzQ2MzQyMSwibmFtZSI6InVQb3J0IERldmVsb3BlciIsImlzcyI6ImRpZDp1cG9ydDoyb3NuZko0V3k3TEJBbTJuUEJYaXJlMVdmUW43NVJyVjZUcyJ9.e9H1ngK7Kto_Am3N9NAJWm8kj7NetGPbOoQtKw8y-C21ytj1zjDr99w63AtlFCytYkLRcHnTHSl0eByaZww5dg'
const INVALID_CLAIM_FORMAT = '%eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJpYXQiOjE1NTQ5NzI2MDksImV4cCI6MTk1NzQ2MzQyMSwibmFtZSI6InVQb3J0IERldmVsb3BlciIsImlzcyI6ImRpZDp1cG9ydDoyb3NuZko0V3k3TEJBbTJuUEJYaXJlMVdmUW43NVJyVjZUcyJ9.e9H1ngK7Kto_Am3N9NAJWm8kj7NetGPbOoQtKw8y-C21ytj1zjDr99w63AtlFCytYkLRcHnTHSl0eByaZww5dg'
const EXPIRED_CLAIM = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJpYXQiOjE1NTQ5NzM5NDgsImV4cCI6MTk1LCJuYW1lIjoidVBvcnQgRGV2ZWxvcGVyIiwiaXNzIjoiZGlkOnVwb3J0OjJvc25mSjRXeTdMQkFtMm5QQlhpcmUxV2ZRbjc1UnJWNlRzIn0.M_HupDVb7N4TFOUg4B_PU6XQm9TTx7S0klhMLT1U3zfpThA4DAT2L8HGeBDTMuGS3-nXVo8oDYORASEX_ecGsQ'

describe('basic utils tests', () => {
test('is muport did', () => {
expect(isMuportDID('abc')).toEqual(false)
expect(isMuportDID('did:example')).toEqual(false)
expect(isMuportDID('did:muport')).toEqual(false)
expect(isMuportDID('did:muport:Qmb9E8wLqjfAqfKhideoApU5g26Yz2Q2bSp6MSZmc5WrNr')).toEqual(true)
expect(isSupportedDID('abc')).toEqual(false)
expect(isSupportedDID('did:example')).toEqual(false)
expect(isSupportedDID('did:muport')).toEqual(false)
expect(isSupportedDID('did:muport:Qmb9E8wLqjfAqfKhideoApU5g26Yz2Q2bSp6MSZmc5WrNr')).toEqual(true)
expect(isSupportedDID('did:3:Qmb9E8wLqjfAqfKhideoApU5g26Yz2Q2bSp6MSZmc5WrNr')).toEqual(true)
})

test('isClaim', async () => {
Expand Down
16 changes: 8 additions & 8 deletions src/api.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const graphQLRequest = require('graphql-request').request
const utils = require('./utils/index')
const verifier = require('./utils/verifier')
const { isMuportDID } = require('./utils/id')
const { isSupportedDID } = require('./utils/id')
const config = require('./config.js')

const GRAPHQL_SERVER_URL = config.graphql_server_url
Expand All @@ -17,8 +17,8 @@ async function getRootStoreAddress (identifier, serverUrl = ADDRESS_SERVER_URL)
async function listSpaces (address, serverUrl = PROFILE_SERVER_URL) {
try {
// we await explicitly here to make sure the error is catch'd in the correct scope
if (isMuportDID(address)) {
return await utils.fetchJson(serverUrl + '/list-spaces?did=' + encodeURIComponent(address))
if (isSupportedDID(address)) {
return await utils.fetchJson(serverUrl + '/list-spaces?did=' + address)
} else {
return await utils.fetchJson(serverUrl + '/list-spaces?address=' + encodeURIComponent(address))
}
Expand All @@ -33,8 +33,8 @@ async function getSpace (address, name, serverUrl = PROFILE_SERVER_URL, { metada

try {
// Add first parameter: address or did
if (isMuportDID(address)) {
url = `${url}?did=${encodeURIComponent(address)}`
if (isSupportedDID(address)) {
url = `${url}?did=${address}`
} else {
url = `${url}?address=${encodeURIComponent(address.toLowerCase())}`
}
Expand Down Expand Up @@ -100,8 +100,8 @@ async function getProfile (address, serverUrl = PROFILE_SERVER_URL, { metadata,

try {
// Add first parameter: address or did
if (isMuportDID(address)) {
url = `${url}?did=${encodeURIComponent(address)}`
if (isSupportedDID(address)) {
url = `${url}?did=${address}`
} else {
url = `${url}?address=${encodeURIComponent(address.toLowerCase())}`
}
Expand All @@ -125,7 +125,7 @@ async function getProfiles (addressArray, opts = {}) {

// Split addresses on ethereum / dids
addressArray.forEach(address => {
if (isMuportDID(address)) {
if (isSupportedDID(address)) {
req.didList.push(address)
} else {
req.addressList.push(address)
Expand Down
9 changes: 6 additions & 3 deletions src/utils/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
*/
const didJWT = require('did-jwt')
const DID_MUPORT_PREFIX = 'did:muport:'
const DID_3_PREFIX = 'did:3:'

module.exports = {
/**
* Check whether a string is a muport did or not
*
* @memberOf Box.idUtils
* @param {String} address A string containing a user profile address
* @return {*|boolean} Whether the address is a muport did or not
* @param {String} did A string containing a user did
* @return {*|boolean} Whether the did is a supported did or not
*/
isMuportDID: (address) => address.startsWith(DID_MUPORT_PREFIX),
isSupportedDID: did => did.startsWith(DID_MUPORT_PREFIX) || did.startsWith(DID_3_PREFIX),
// for backwards compatibility
isMuportDID: did => did.startsWith(DID_MUPORT_PREFIX),

/**
* Check whether a string is a valid claim or not
Expand Down

0 comments on commit 22c509f

Please sign in to comment.