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

Commit

Permalink
ref(api): Move getVerifiedAccounts to api
Browse files Browse the repository at this point in the history
  • Loading branch information
oed authored and Joel Torstensson committed Feb 5, 2019
1 parent 1039ac1 commit 6abc2fa
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ This runs a simple server at `http://localhost:3000/` that serves the static `ex
If you only want to fetch profile data from 3Box's profile APIs you can optimize by importing only those functions or the API specific dist file. Since this includes minimal dependencies, file size is ~ 80kb vs 4+mb for the full build.

```js
const { profileGraphQL, getProfile, getProfiles } = require('3box/lib/api')
const { profileGraphQL, getProfile, getProfiles, getVerifiedAccounts } = require('3box/lib/api')
```
```html
<script src="https://unpkg.com/3box/dist/3box.api.min.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion readme-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ This runs a simple server at `http://localhost:3000/` that serves the static `ex
If you only want to fetch profile data from 3Box's profile APIs you can optimize by importing only those functions or the API specific dist file. Since this includes minimal dependencies, file size is ~ 80kb vs 4+mb for the full build.

```js
const { profileGraphQL, getProfile, getProfiles } = require('3box/lib/api')
const { profileGraphQL, getProfile, getProfiles, getVerifiedAccounts } = require('3box/lib/api')
```
```html
<script src="https://unpkg.com/3box/dist/3box.api.min.js"></script>
Expand Down
23 changes: 1 addition & 22 deletions src/3box.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const PrivateStore = require('./privateStore')
const Verified = require('./verified')
const Space = require('./space')
const utils = require('./utils/index')
const verifier = require('./utils/verifier')
const config = require('./config.js')
const API = require('./api')

Expand Down Expand Up @@ -281,27 +280,7 @@ class Box {
* @return {Object} An object containing the accounts that have been verified
*/
static async getVerifiedAccounts (profile) {
let verifs = {}
try {
const did = await verifier.verifyDID(profile.proof_did)
if (profile.proof_github) {
try {
verifs.github = await verifier.verifyGithub(did, profile.proof_github)
} catch (err) {
// Invalid github verification
}
}
if (profile.proof_twitter) {
try {
verifs.twitter = await verifier.verifyTwitter(did, profile.proof_twitter)
} catch (err) {
// Invalid twitter verification
}
}
} catch (err) {
// Invalid proof for DID return an empty profile
}
return verifs
return API.getVerifiedAccounts(profile)
}

/**
Expand Down
27 changes: 26 additions & 1 deletion src/api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const graphQLRequest = require('graphql-request').request
const utils = require('./utils/index')
const verifier = require('./utils/verifier')
const config = require('./config.js')

const GRAPHQL_SERVER_URL = config.graphql_server_url
Expand Down Expand Up @@ -39,4 +40,28 @@ async function profileGraphQL (query, opts = {}) {
return graphQLRequest(opts.graphqlServer, query)
}

module.exports = { profileGraphQL, getProfile, getRootStoreAddress, getProfiles }
async function getVerifiedAccounts (profile) {
let verifs = {}
try {
const did = await verifier.verifyDID(profile.proof_did)
if (profile.proof_github) {
try {
verifs.github = await verifier.verifyGithub(did, profile.proof_github)
} catch (err) {
// Invalid github verification
}
}
if (profile.proof_twitter) {
try {
verifs.twitter = await verifier.verifyTwitter(did, profile.proof_twitter)
} catch (err) {
// Invalid twitter verification
}
}
} catch (err) {
// Invalid proof for DID return an empty profile
}
return verifs
}

module.exports = { profileGraphQL, getProfile, getRootStoreAddress, getProfiles, getVerifiedAccounts }

0 comments on commit 6abc2fa

Please sign in to comment.