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] ## [Unreleased]
## [0.8.1] - 2020-12-20
### Fixed
- Timeout for claim verification promises
## [0.8.0] - 2020-12-11 ## [0.8.0] - 2020-12-11
### Added ### Added
- Add fallback proxy policy - Add fallback proxy policy

316
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.8.0", "version": "0.8.1",
"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": {
@ -1240,7 +1240,9 @@ module.exports={
"author": "Yarmo Mackenbach <yarmo@yarmo.eu> (https://yarmo.eu)", "author": "Yarmo Mackenbach <yarmo@yarmo.eu> (https://yarmo.eu)",
"license": "Apache-2.0", "license": "Apache-2.0",
"browserify": { "browserify": {
"transform": [ "browserify-shim" ] "transform": [
"browserify-shim"
]
}, },
"browserify-shim": { "browserify-shim": {
"openpgp": "global:openpgp" "openpgp": "global:openpgp"
@ -1368,7 +1370,6 @@ const verify = async (input, fingerprint, opts) => {
const res = await verify(user.notations, fingerprintFromKey, opts) const res = await verify(user.notations, fingerprintFromKey, opts)
resolve(res) resolve(res)
} catch (e) { } catch (e) {
console.error(`Claim verification failed: ${user.userData.id}`, e)
reject(e) reject(e)
} }
}) })
@ -1376,7 +1377,11 @@ const verify = async (input, fingerprint, opts) => {
return Promise.allSettled(promises).then((values) => { return Promise.allSettled(promises).then((values) => {
return values.map((obj, i) => { return values.map((obj, i) => {
return obj.value 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) const res = await verify(uri, fingerprint, opts)
resolve(res) resolve(res)
} catch (e) { } catch (e) {
console.error(`Claim verification failed: ${uri}`, e)
reject(e) reject(e)
} }
}) })
@ -1395,122 +1399,170 @@ const verify = async (input, fingerprint, opts) => {
return Promise.allSettled(promises).then((values) => { return Promise.allSettled(promises).then((values) => {
return values.map((obj, i) => { return values.map((obj, i) => {
return obj.value if (obj.status == 'fulfilled') {
return obj.value
} else {
return obj.reason
}
}) })
}) })
} }
const uri = input.replace(/^\s+|\s+$/g, '') const promiseClaim = new Promise(async (resolve, reject) => {
let verifErrors = [] let objResult = {
isVerified: false,
errors: [],
serviceproviderData: undefined,
}
if (!fingerprint) { const uri = input.replace(/^\s+|\s+$/g, '')
fingerprint = null
}
const defaultOpts = { if (!fingerprint) {
returnMatchesOnly: false, fingerprint = null
proxyPolicy: 'adaptive', }
doipProxyHostname: 'proxy.keyoxide.org',
}
opts = mergeOptions(defaultOpts, opts ? opts : {})
if (!validUrl.isUri(uri)) { const defaultOpts = {
throw new Error('Invalid URI') returnMatchesOnly: false,
} proxyPolicy: 'adaptive',
doipProxyHostname: 'proxy.keyoxide.org',
}
opts = mergeOptions(defaultOpts, opts ? opts : {})
const spMatches = serviceproviders.match(uri, opts) if (!validUrl.isUri(uri)) {
objResult.errors.push('invalid_uri')
reject(objResult)
return
}
if ('returnMatchesOnly' in opts && opts.returnMatchesOnly) { const spMatches = serviceproviders.match(uri, opts)
return spMatches
}
let claimVerificationDone = false, if ('returnMatchesOnly' in opts && opts.returnMatchesOnly) {
claimVerificationResult, resolve(spMatches)
sp, return
iSp = 0, }
res,
proofData,
spData
while (!claimVerificationDone && iSp < spMatches.length) { let claimVerificationDone = false,
spData = spMatches[iSp] claimVerificationResult,
spData.claim.fingerprint = fingerprint sp,
iSp = 0,
res,
proofData,
spData
res = null while (!claimVerificationDone && iSp < spMatches.length) {
spData = spMatches[iSp]
spData.claim.fingerprint = fingerprint
if (spData.customRequestHandler instanceof Function) { res = null
try {
proofData = await spData.customRequestHandler(spData, opts) if (spData.customRequestHandler instanceof Function) {
} catch (e) { try {
verifErrors.push('custom_request_handler_failed') proofData = await spData.customRequestHandler(spData, opts)
} } catch (e) {
} else { objResult.errors.push('custom_request_handler_failed')
switch (opts.proxyPolicy) { }
case 'adaptive': } else {
if (spData.proof.useProxy) { switch (opts.proxyPolicy) {
case 'adaptive':
if (spData.proof.useProxy) {
try {
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 { try {
proofData = await serviceproviders.proxyRequestHandler(spData, opts) proofData = await serviceproviders.directRequestHandler(
} catch(er) {} spData,
} else { opts
try { )
proofData = await serviceproviders.directRequestHandler(spData, opts) } catch (er) {}
} catch(er) {}
if (!proofData) { if (!proofData) {
try { try {
proofData = await serviceproviders.proxyRequestHandler(spData, opts) proofData = await serviceproviders.proxyRequestHandler(
} catch(er) {} spData,
opts
)
} catch (er) {}
} }
} break
break; case 'always':
case 'fallback':
try {
proofData = await serviceproviders.directRequestHandler(spData, opts)
} catch(er) {}
if (!proofData) {
try { try {
proofData = await serviceproviders.proxyRequestHandler(spData, opts) proofData = await serviceproviders.proxyRequestHandler(
} catch(er) {} spData,
} opts
break; )
case 'always': } catch (er) {}
try { break
proofData = await serviceproviders.proxyRequestHandler(spData, opts) case 'never':
} catch(er) {} try {
break; proofData = await serviceproviders.directRequestHandler(
case 'never': spData,
try { opts
proofData = await serviceproviders.directRequestHandler(spData, opts) )
} catch(er) {} } catch (er) {}
break; break
default: default:
verifErrors.push('invalid_proxy_policy') objResult.errors.push('invalid_proxy_policy')
}
}
if (proofData) {
claimVerificationResult = runVerification(proofData, spData)
if (claimVerificationResult.errors.length == 0) {
claimVerificationDone = true
}
} else {
objResult.errors.push('unsuccessful_claim_verification')
}
iSp++
}
if (!claimVerificationResult) {
claimVerificationResult = {
isVerified: false,
} }
} }
if (proofData) { objResult.isVerified = claimVerificationResult.isVerified
claimVerificationResult = runVerification(proofData, spData) objResult.serviceproviderData = spData
resolve(objResult)
return
})
if (claimVerificationResult.errors.length == 0) { const promiseTimeout = new Promise((resolve) => {
claimVerificationDone = true const objResult = {
}
} else {
verifErrors.push('unsuccessful_claim_verification')
}
iSp++
}
if (!claimVerificationResult) {
claimVerificationResult = {
isVerified: false, isVerified: false,
errors: ['verification_timed_out'],
serviceproviderData: undefined,
} }
} setTimeout(() => {
resolve(objResult)
return
}, 3000)
})
return { return await Promise.race([promiseClaim, promiseTimeout])
isVerified: claimVerificationResult.isVerified,
errors: verifErrors,
serviceproviderData: spData,
}
} }
exports.verify = verify exports.verify = verify
@ -1666,7 +1718,9 @@ const fetchURI = (uri) => {
switch (match[1]) { switch (match[1]) {
case 'hkp': 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 break
case 'wkd': case 'wkd':
resolve(fetchWKD(match[2])) resolve(fetchWKD(match[2]))
@ -1829,27 +1883,27 @@ const directRequestHandler = (spData, opts) => {
Accept: 'application/json', Accept: 'application/json',
'User-Agent': `doipjs/${require('../package.json').version}`, 'User-Agent': `doipjs/${require('../package.json').version}`,
}) })
.then(async (res) => { .then(async (res) => {
return await res.json() return await res.json()
}) })
.then((res) => { .then((res) => {
resolve(res) resolve(res)
}) })
.catch((e) => { .catch((e) => {
reject(e) reject(e)
}) })
break break
case 'text': case 'text':
req(url) req(url)
.then(async (res) => { .then(async (res) => {
return await res.text() return await res.text()
}) })
.then((res) => { .then((res) => {
resolve(res) resolve(res)
}) })
.catch((e) => { .catch((e) => {
reject(e) reject(e)
}) })
break break
default: default:
reject('No specified proof data format') reject('No specified proof data format')
@ -1861,20 +1915,18 @@ 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
req( req(utils.generateProxyURL(spData.proof.format, url, opts), null, {
utils.generateProxyURL(spData.proof.format, url, opts), Accept: 'application/json',
null,
{ Accept: 'application/json' }
)
.then(async (res) => {
return await res.json()
})
.then((res) => {
resolve(res.content)
})
.catch((e) => {
reject(e)
}) })
.then(async (res) => {
return await res.json()
})
.then((res) => {
resolve(res.content)
})
.catch((e) => {
reject(e)
})
}) })
} }
@ -2356,11 +2408,9 @@ const customRequestHandler = async (spData, opts) => {
try { try {
resUser = await req(urlUser, null, { Accept: 'application/json' }) resUser = await req(urlUser, null, { Accept: 'application/json' })
} catch (e) { } catch (e) {
resUser = await req( resUser = await req(utils.generateProxyURL('web', urlUser, opts), null, {
utils.generateProxyURL('web', urlUser, opts), Accept: 'application/json',
null, })
{ Accept: 'application/json' }
)
} }
const jsonUser = await resUser.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"> <img src="doip.png" width="120">

View file

@ -1,5 +1,12 @@
# Changelog # 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] ## [0.8.0]
[2020-12-11](https://codeberg.org/keyoxide/doipjs/releases/tag/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: Install on website by including the following HTML snippet:
```html ```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) 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.8.0", "version": "0.8.1",
"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": {
@ -47,7 +47,9 @@
"author": "Yarmo Mackenbach <yarmo@yarmo.eu> (https://yarmo.eu)", "author": "Yarmo Mackenbach <yarmo@yarmo.eu> (https://yarmo.eu)",
"license": "Apache-2.0", "license": "Apache-2.0",
"browserify": { "browserify": {
"transform": [ "browserify-shim" ] "transform": [
"browserify-shim"
]
}, },
"browserify-shim": { "browserify-shim": {
"openpgp": "global:openpgp" "openpgp": "global:openpgp"