Release 0.8.0

This commit is contained in:
Yarmo Mackenbach 2020-12-11 11:07:13 +01:00
parent 4657ad3956
commit 7daececb99
7 changed files with 141 additions and 29 deletions

View file

@ -6,6 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
## [0.8.0] - 2020-12-11
### Added
- Add fallback proxy policy
### Fixed
- Handling of failed network requests
- Handling of rejected promises
- DNS proxy URL generation
- Twitter & Dev.to service provider
## [0.7.5] - 2020-12-08 ## [0.7.5] - 2020-12-08
### Fixed ### Fixed
- Browser bundling - Browser bundling

135
dist/doip.js vendored
View file

@ -1193,7 +1193,7 @@ process.umask = function() { return 0; };
},{}],9:[function(require,module,exports){ },{}],9:[function(require,module,exports){
module.exports={ module.exports={
"name": "doipjs", "name": "doipjs",
"version": "0.7.5", "version": "0.8.0",
"description": "Decentralized OpenPGP Identity Proofs library in Node.js", "description": "Decentralized OpenPGP Identity Proofs library in Node.js",
"main": "src/index.js", "main": "src/index.js",
"dependencies": { "dependencies": {
@ -1374,8 +1374,10 @@ const verify = async (input, fingerprint, opts) => {
}) })
}) })
return Promise.all(promises).then((values) => { return Promise.allSettled(promises).then((values) => {
return values return values.map((obj, i) => {
return obj.value
})
}) })
} }
if (input instanceof Array) { if (input instanceof Array) {
@ -1391,12 +1393,15 @@ const verify = async (input, fingerprint, opts) => {
}) })
}) })
return Promise.all(promises).then((values) => { return Promise.allSettled(promises).then((values) => {
return values return values.map((obj, i) => {
return obj.value
})
}) })
} }
const uri = input const uri = input.replace(/^\s+|\s+$/g, '')
let verifErrors = []
if (!fingerprint) { if (!fingerprint) {
fingerprint = null fingerprint = null
@ -1418,6 +1423,7 @@ const verify = async (input, fingerprint, opts) => {
if ('returnMatchesOnly' in opts && opts.returnMatchesOnly) { if ('returnMatchesOnly' in opts && opts.returnMatchesOnly) {
return spMatches return spMatches
} }
let claimVerificationDone = false, let claimVerificationDone = false,
claimVerificationResult, claimVerificationResult,
sp, sp,
@ -1425,6 +1431,7 @@ const verify = async (input, fingerprint, opts) => {
res, res,
proofData, proofData,
spData spData
while (!claimVerificationDone && iSp < spMatches.length) { while (!claimVerificationDone && iSp < spMatches.length) {
spData = spMatches[iSp] spData = spMatches[iSp]
spData.claim.fingerprint = fingerprint spData.claim.fingerprint = fingerprint
@ -1432,14 +1439,52 @@ const verify = async (input, fingerprint, opts) => {
res = null res = null
if (spData.customRequestHandler instanceof Function) { if (spData.customRequestHandler instanceof Function) {
try {
proofData = await spData.customRequestHandler(spData, opts) proofData = await spData.customRequestHandler(spData, opts)
} else if ( } catch (e) {
!spData.proof.useProxy || verifErrors.push('custom_request_handler_failed')
('proxyPolicy' in opts && !opts.useProxyWhenNeeded) }
) {
proofData = await serviceproviders.directRequestHandler(spData, opts)
} else { } else {
switch (opts.proxyPolicy) {
case 'adaptive':
if (spData.proof.useProxy) {
try {
proofData = await serviceproviders.proxyRequestHandler(spData, opts) proofData = await serviceproviders.proxyRequestHandler(spData, opts)
} catch(er) {}
} else {
try {
proofData = await serviceproviders.directRequestHandler(spData, opts)
} catch(er) {}
if (!proofData) {
try {
proofData = await serviceproviders.proxyRequestHandler(spData, opts)
} catch(er) {}
}
}
break;
case 'fallback':
try {
proofData = await serviceproviders.directRequestHandler(spData, opts)
} catch(er) {}
if (!proofData) {
try {
proofData = await serviceproviders.proxyRequestHandler(spData, opts)
} catch(er) {}
}
break;
case 'always':
try {
proofData = await serviceproviders.proxyRequestHandler(spData, opts)
} catch(er) {}
break;
case 'never':
try {
proofData = await serviceproviders.directRequestHandler(spData, opts)
} catch(er) {}
break;
default:
verifErrors.push('invalid_proxy_policy')
}
} }
if (proofData) { if (proofData) {
@ -1448,6 +1493,8 @@ const verify = async (input, fingerprint, opts) => {
if (claimVerificationResult.errors.length == 0) { if (claimVerificationResult.errors.length == 0) {
claimVerificationDone = true claimVerificationDone = true
} }
} else {
verifErrors.push('unsuccessful_claim_verification')
} }
iSp++ iSp++
@ -1461,6 +1508,7 @@ const verify = async (input, fingerprint, opts) => {
return { return {
isVerified: claimVerificationResult.isVerified, isVerified: claimVerificationResult.isVerified,
errors: verifErrors,
serviceproviderData: spData, serviceproviderData: spData,
} }
} }
@ -1777,15 +1825,31 @@ const directRequestHandler = (spData, opts) => {
switch (spData.proof.format) { switch (spData.proof.format) {
case 'json': case 'json':
res = await req(url, null, { req(url, null, {
Accept: 'application/json', Accept: 'application/json',
'User-Agent': `doipjs/${require('../package.json').version}`, 'User-Agent': `doipjs/${require('../package.json').version}`,
}) })
resolve(await res.json()) .then(async (res) => {
return await res.json()
})
.then((res) => {
resolve(res)
})
.catch((e) => {
reject(e)
})
break break
case 'text': case 'text':
res = await req(url) req(url)
resolve(await res.text()) .then(async (res) => {
return await res.text()
})
.then((res) => {
resolve(res)
})
.catch((e) => {
reject(e)
})
break break
default: default:
reject('No specified proof data format') reject('No specified proof data format')
@ -1797,13 +1861,20 @@ const directRequestHandler = (spData, opts) => {
const proxyRequestHandler = (spData, opts) => { const proxyRequestHandler = (spData, opts) => {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
const url = spData.proof.fetch ? spData.proof.fetch : spData.proof.uri const url = spData.proof.fetch ? spData.proof.fetch : spData.proof.uri
const res = await req( req(
utils.generateProxyURL(spData.proof.format, url, opts), utils.generateProxyURL(spData.proof.format, url, opts),
null, null,
{ Accept: 'application/json' } { Accept: 'application/json' }
) )
const json = await res.json() .then(async (res) => {
resolve(json.content) return await res.json()
})
.then((res) => {
resolve(res.content)
})
.catch((e) => {
reject(e)
})
}) })
} }
@ -1850,7 +1921,7 @@ const processURI = (uri, opts) => {
proof: { proof: {
uri: uri, uri: uri,
fetch: `https://dev.to/api/articles/${match[1]}/${match[2]}`, fetch: `https://dev.to/api/articles/${match[1]}/${match[2]}`,
useProxy: false, useProxy: true,
format: 'json', format: 'json',
}, },
claim: { claim: {
@ -2015,7 +2086,7 @@ const processURI = (uri, opts) => {
qr: null, qr: null,
}, },
proof: { proof: {
uri: utils.generateProxyURL('dns', match[1]), uri: utils.generateProxyURL('dns', match[1], opts),
fetch: null, fetch: null,
useProxy: false, useProxy: false,
format: 'json', format: 'json',
@ -2281,7 +2352,16 @@ const customRequestHandler = async (spData, opts) => {
const match = spData.proof.uri.match(reURI) const match = spData.proof.uri.match(reURI)
const urlUser = `https://${match[1]}/api/v4/users?username=${match[2]}` const urlUser = `https://${match[1]}/api/v4/users?username=${match[2]}`
const resUser = await req(urlUser, 'json', { Accept: 'application/json' }) let resUser
try {
resUser = await req(urlUser, null, { Accept: 'application/json' })
} catch (e) {
resUser = await req(
utils.generateProxyURL('web', urlUser, opts),
null,
{ Accept: 'application/json' }
)
}
const jsonUser = await resUser.json() const jsonUser = await resUser.json()
const user = jsonUser.find((user) => user.username === match[2]) const user = jsonUser.find((user) => user.username === match[2])
@ -2290,7 +2370,16 @@ const customRequestHandler = async (spData, opts) => {
} }
const urlProject = `https://${match[1]}/api/v4/users/${user.id}/projects` const urlProject = `https://${match[1]}/api/v4/users/${user.id}/projects`
const resProject = await req(urlProject, {}, { Accept: 'application/json' }) let resProject
try {
resProject = await req(urlProject, null, { Accept: 'application/json' })
} catch (e) {
resProject = await req(
utils.generateProxyURL('web', urlProject, opts),
null,
{ Accept: 'application/json' }
)
}
const jsonProject = await resProject.json() const jsonProject = await resProject.json()
const project = jsonProject.find((proj) => proj.path === 'gitlab_proof') const project = jsonProject.find((proj) => proj.path === 'gitlab_proof')
@ -2742,7 +2831,7 @@ const processURI = (uri, opts) => {
proof: { proof: {
uri: uri, uri: uri,
fetch: `https://mobile.twitter.com/${match[1]}/status/${match[2]}`, fetch: `https://mobile.twitter.com/${match[1]}/status/${match[2]}`,
useProxy: false, useProxy: true,
format: 'text', format: 'text',
}, },
claim: { claim: {

2
dist/doip.min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -1,4 +1,4 @@
# doip.js <small>0.7.5</small> # doip.js <small>0.8.0</small>
<img src="doip.png" width="120"> <img src="doip.png" width="120">

View file

@ -1,5 +1,18 @@
# Changelog # Changelog
## [0.8.0]
[2020-12-11](https://codeberg.org/keyoxide/doipjs/releases/tag/0.8.0)
### Added
- Add fallback proxy policy
### Fixed
- Handling of failed network requests
- Handling of rejected promises
- DNS proxy URL generation
- Twitter & Dev.to service provider
## [0.7.5] ## [0.7.5]
[2020-12-10](https://codeberg.org/keyoxide/doipjs/releases/tag/0.7.5) [2020-12-10](https://codeberg.org/keyoxide/doipjs/releases/tag/0.7.5)

View file

@ -15,7 +15,7 @@ npm install --save doipjs
Install on website by including the following HTML snippet: Install on website by including the following HTML snippet:
```html ```html
<script src="https://cdn.jsdelivr.net/npm/doipjs@0.7.5/dist/doip.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/doipjs@0.8.0/dist/doip.min.js"></script>
``` ```
Next step: [quick start (Node.js)](quickstart-nodejs.md) and [quick start (browser)](quickstart-browser.md) Next step: [quick start (Node.js)](quickstart-nodejs.md) and [quick start (browser)](quickstart-browser.md)

View file

@ -1,6 +1,6 @@
{ {
"name": "doipjs", "name": "doipjs",
"version": "0.7.5", "version": "0.8.0",
"description": "Decentralized OpenPGP Identity Proofs library in Node.js", "description": "Decentralized OpenPGP Identity Proofs library in Node.js",
"main": "src/index.js", "main": "src/index.js",
"dependencies": { "dependencies": {