Release 0.8.1

This commit is contained in:
Yarmo Mackenbach 2020-12-20 23:20:32 +01:00
parent 347c48ff4e
commit 47e538770c
7 changed files with 201 additions and 138 deletions

View file

@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [0.8.1] - 2020-12-20
### Fixed
- Timeout for claim verification promises
## [0.8.0] - 2020-12-11
### Added
- Add fallback proxy policy

136
dist/doip.js vendored
View file

@ -1193,7 +1193,7 @@ process.umask = function() { return 0; };
},{}],9:[function(require,module,exports){
module.exports={
"name": "doipjs",
"version": "0.8.0",
"version": "0.8.1",
"description": "Decentralized OpenPGP Identity Proofs library in Node.js",
"main": "src/index.js",
"dependencies": {
@ -1240,7 +1240,9 @@ module.exports={
"author": "Yarmo Mackenbach <yarmo@yarmo.eu> (https://yarmo.eu)",
"license": "Apache-2.0",
"browserify": {
"transform": [ "browserify-shim" ]
"transform": [
"browserify-shim"
]
},
"browserify-shim": {
"openpgp": "global:openpgp"
@ -1368,7 +1370,6 @@ const verify = async (input, fingerprint, opts) => {
const res = await verify(user.notations, fingerprintFromKey, opts)
resolve(res)
} catch (e) {
console.error(`Claim verification failed: ${user.userData.id}`, e)
reject(e)
}
})
@ -1376,7 +1377,11 @@ const verify = async (input, fingerprint, opts) => {
return Promise.allSettled(promises).then((values) => {
return values.map((obj, i) => {
if (obj.status == 'fulfilled') {
return obj.value
} else {
return obj.reason
}
})
})
}
@ -1387,7 +1392,6 @@ const verify = async (input, fingerprint, opts) => {
const res = await verify(uri, fingerprint, opts)
resolve(res)
} catch (e) {
console.error(`Claim verification failed: ${uri}`, e)
reject(e)
}
})
@ -1395,13 +1399,23 @@ const verify = async (input, fingerprint, opts) => {
return Promise.allSettled(promises).then((values) => {
return values.map((obj, i) => {
if (obj.status == 'fulfilled') {
return obj.value
} else {
return obj.reason
}
})
})
}
const promiseClaim = new Promise(async (resolve, reject) => {
let objResult = {
isVerified: false,
errors: [],
serviceproviderData: undefined,
}
const uri = input.replace(/^\s+|\s+$/g, '')
let verifErrors = []
if (!fingerprint) {
fingerprint = null
@ -1415,13 +1429,16 @@ const verify = async (input, fingerprint, opts) => {
opts = mergeOptions(defaultOpts, opts ? opts : {})
if (!validUrl.isUri(uri)) {
throw new Error('Invalid URI')
objResult.errors.push('invalid_uri')
reject(objResult)
return
}
const spMatches = serviceproviders.match(uri, opts)
if ('returnMatchesOnly' in opts && opts.returnMatchesOnly) {
return spMatches
resolve(spMatches)
return
}
let claimVerificationDone = false,
@ -1442,48 +1459,69 @@ const verify = async (input, fingerprint, opts) => {
try {
proofData = await spData.customRequestHandler(spData, opts)
} catch (e) {
verifErrors.push('custom_request_handler_failed')
objResult.errors.push('custom_request_handler_failed')
}
} else {
switch (opts.proxyPolicy) {
case 'adaptive':
if (spData.proof.useProxy) {
try {
proofData = await serviceproviders.proxyRequestHandler(spData, opts)
} catch(er) {}
proofData = await serviceproviders.proxyRequestHandler(
spData,
opts
)
} catch (er) {}
} else {
try {
proofData = await serviceproviders.directRequestHandler(spData, opts)
} catch(er) {}
proofData = await serviceproviders.directRequestHandler(
spData,
opts
)
} catch (er) {}
if (!proofData) {
try {
proofData = await serviceproviders.proxyRequestHandler(spData, opts)
} catch(er) {}
proofData = await serviceproviders.proxyRequestHandler(
spData,
opts
)
} catch (er) {}
}
}
break;
break
case 'fallback':
try {
proofData = await serviceproviders.directRequestHandler(spData, opts)
} catch(er) {}
proofData = await serviceproviders.directRequestHandler(
spData,
opts
)
} catch (er) {}
if (!proofData) {
try {
proofData = await serviceproviders.proxyRequestHandler(spData, opts)
} catch(er) {}
proofData = await serviceproviders.proxyRequestHandler(
spData,
opts
)
} catch (er) {}
}
break;
break
case 'always':
try {
proofData = await serviceproviders.proxyRequestHandler(spData, opts)
} catch(er) {}
break;
proofData = await serviceproviders.proxyRequestHandler(
spData,
opts
)
} catch (er) {}
break
case 'never':
try {
proofData = await serviceproviders.directRequestHandler(spData, opts)
} catch(er) {}
break;
proofData = await serviceproviders.directRequestHandler(
spData,
opts
)
} catch (er) {}
break
default:
verifErrors.push('invalid_proxy_policy')
objResult.errors.push('invalid_proxy_policy')
}
}
@ -1494,7 +1532,7 @@ const verify = async (input, fingerprint, opts) => {
claimVerificationDone = true
}
} else {
verifErrors.push('unsuccessful_claim_verification')
objResult.errors.push('unsuccessful_claim_verification')
}
iSp++
@ -1506,11 +1544,25 @@ const verify = async (input, fingerprint, opts) => {
}
}
return {
isVerified: claimVerificationResult.isVerified,
errors: verifErrors,
serviceproviderData: spData,
objResult.isVerified = claimVerificationResult.isVerified
objResult.serviceproviderData = spData
resolve(objResult)
return
})
const promiseTimeout = new Promise((resolve) => {
const objResult = {
isVerified: false,
errors: ['verification_timed_out'],
serviceproviderData: undefined,
}
setTimeout(() => {
resolve(objResult)
return
}, 3000)
})
return await Promise.race([promiseClaim, promiseTimeout])
}
exports.verify = verify
@ -1666,7 +1718,9 @@ const fetchURI = (uri) => {
switch (match[1]) {
case 'hkp':
resolve(fetchHKP(match[3] ? match[3] : match[2], match[3] ? match[2] : null))
resolve(
fetchHKP(match[3] ? match[3] : match[2], match[3] ? match[2] : null)
)
break
case 'wkd':
resolve(fetchWKD(match[2]))
@ -1861,11 +1915,9 @@ const directRequestHandler = (spData, opts) => {
const proxyRequestHandler = (spData, opts) => {
return new Promise(async (resolve, reject) => {
const url = spData.proof.fetch ? spData.proof.fetch : spData.proof.uri
req(
utils.generateProxyURL(spData.proof.format, url, opts),
null,
{ Accept: 'application/json' }
)
req(utils.generateProxyURL(spData.proof.format, url, opts), null, {
Accept: 'application/json',
})
.then(async (res) => {
return await res.json()
})
@ -2356,11 +2408,9 @@ const customRequestHandler = async (spData, opts) => {
try {
resUser = await req(urlUser, null, { Accept: 'application/json' })
} catch (e) {
resUser = await req(
utils.generateProxyURL('web', urlUser, opts),
null,
{ Accept: 'application/json' }
)
resUser = await req(utils.generateProxyURL('web', urlUser, opts), null, {
Accept: 'application/json',
})
}
const jsonUser = await resUser.json()

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.8.0</small>
# doip.js <small>0.8.1</small>
<img src="doip.png" width="120">

View file

@ -1,5 +1,12 @@
# Changelog
## [0.8.1]
[2020-12-20](https://codeberg.org/keyoxide/doipjs/releases/tag/0.8.1)
### Fixed
- Timeout for claim verification promises
## [0.8.0]
[2020-12-11](https://codeberg.org/keyoxide/doipjs/releases/tag/0.8.0)

View file

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

View file

@ -1,6 +1,6 @@
{
"name": "doipjs",
"version": "0.8.0",
"version": "0.8.1",
"description": "Decentralized OpenPGP Identity Proofs library in Node.js",
"main": "src/index.js",
"dependencies": {
@ -47,7 +47,9 @@
"author": "Yarmo Mackenbach <yarmo@yarmo.eu> (https://yarmo.eu)",
"license": "Apache-2.0",
"browserify": {
"transform": [ "browserify-shim" ]
"transform": [
"browserify-shim"
]
},
"browserify-shim": {
"openpgp": "global:openpgp"