mirror of
https://codeberg.org/keyoxide/doipjs.git
synced 2024-12-22 22:49:28 -07:00
Release 0.8.1
This commit is contained in:
parent
347c48ff4e
commit
47e538770c
7 changed files with 201 additions and 138 deletions
|
@ -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
|
||||||
|
|
136
dist/doip.js
vendored
136
dist/doip.js
vendored
|
@ -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) => {
|
||||||
|
if (obj.status == 'fulfilled') {
|
||||||
return obj.value
|
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,13 +1399,23 @@ 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) => {
|
||||||
|
if (obj.status == 'fulfilled') {
|
||||||
return obj.value
|
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, '')
|
const uri = input.replace(/^\s+|\s+$/g, '')
|
||||||
let verifErrors = []
|
|
||||||
|
|
||||||
if (!fingerprint) {
|
if (!fingerprint) {
|
||||||
fingerprint = null
|
fingerprint = null
|
||||||
|
@ -1415,13 +1429,16 @@ const verify = async (input, fingerprint, opts) => {
|
||||||
opts = mergeOptions(defaultOpts, opts ? opts : {})
|
opts = mergeOptions(defaultOpts, opts ? opts : {})
|
||||||
|
|
||||||
if (!validUrl.isUri(uri)) {
|
if (!validUrl.isUri(uri)) {
|
||||||
throw new Error('Invalid URI')
|
objResult.errors.push('invalid_uri')
|
||||||
|
reject(objResult)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const spMatches = serviceproviders.match(uri, opts)
|
const spMatches = serviceproviders.match(uri, opts)
|
||||||
|
|
||||||
if ('returnMatchesOnly' in opts && opts.returnMatchesOnly) {
|
if ('returnMatchesOnly' in opts && opts.returnMatchesOnly) {
|
||||||
return spMatches
|
resolve(spMatches)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let claimVerificationDone = false,
|
let claimVerificationDone = false,
|
||||||
|
@ -1442,48 +1459,69 @@ const verify = async (input, fingerprint, opts) => {
|
||||||
try {
|
try {
|
||||||
proofData = await spData.customRequestHandler(spData, opts)
|
proofData = await spData.customRequestHandler(spData, opts)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
verifErrors.push('custom_request_handler_failed')
|
objResult.errors.push('custom_request_handler_failed')
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (opts.proxyPolicy) {
|
switch (opts.proxyPolicy) {
|
||||||
case 'adaptive':
|
case 'adaptive':
|
||||||
if (spData.proof.useProxy) {
|
if (spData.proof.useProxy) {
|
||||||
try {
|
try {
|
||||||
proofData = await serviceproviders.proxyRequestHandler(spData, opts)
|
proofData = await serviceproviders.proxyRequestHandler(
|
||||||
} catch(er) {}
|
spData,
|
||||||
|
opts
|
||||||
|
)
|
||||||
|
} catch (er) {}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
proofData = await serviceproviders.directRequestHandler(spData, opts)
|
proofData = await serviceproviders.directRequestHandler(
|
||||||
} catch(er) {}
|
spData,
|
||||||
|
opts
|
||||||
|
)
|
||||||
|
} 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 'fallback':
|
case 'fallback':
|
||||||
try {
|
try {
|
||||||
proofData = await serviceproviders.directRequestHandler(spData, opts)
|
proofData = await serviceproviders.directRequestHandler(
|
||||||
} catch(er) {}
|
spData,
|
||||||
|
opts
|
||||||
|
)
|
||||||
|
} 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 'always':
|
||||||
try {
|
try {
|
||||||
proofData = await serviceproviders.proxyRequestHandler(spData, opts)
|
proofData = await serviceproviders.proxyRequestHandler(
|
||||||
} catch(er) {}
|
spData,
|
||||||
break;
|
opts
|
||||||
|
)
|
||||||
|
} catch (er) {}
|
||||||
|
break
|
||||||
case 'never':
|
case 'never':
|
||||||
try {
|
try {
|
||||||
proofData = await serviceproviders.directRequestHandler(spData, opts)
|
proofData = await serviceproviders.directRequestHandler(
|
||||||
} catch(er) {}
|
spData,
|
||||||
break;
|
opts
|
||||||
|
)
|
||||||
|
} catch (er) {}
|
||||||
|
break
|
||||||
default:
|
default:
|
||||||
verifErrors.push('invalid_proxy_policy')
|
objResult.errors.push('invalid_proxy_policy')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1494,7 +1532,7 @@ const verify = async (input, fingerprint, opts) => {
|
||||||
claimVerificationDone = true
|
claimVerificationDone = true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
verifErrors.push('unsuccessful_claim_verification')
|
objResult.errors.push('unsuccessful_claim_verification')
|
||||||
}
|
}
|
||||||
|
|
||||||
iSp++
|
iSp++
|
||||||
|
@ -1506,11 +1544,25 @@ const verify = async (input, fingerprint, opts) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
objResult.isVerified = claimVerificationResult.isVerified
|
||||||
isVerified: claimVerificationResult.isVerified,
|
objResult.serviceproviderData = spData
|
||||||
errors: verifErrors,
|
resolve(objResult)
|
||||||
serviceproviderData: spData,
|
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
|
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]))
|
||||||
|
@ -1861,11 +1915,9 @@ 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) => {
|
.then(async (res) => {
|
||||||
return await res.json()
|
return await res.json()
|
||||||
})
|
})
|
||||||
|
@ -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
2
dist/doip.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -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">
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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"
|
||||||
|
|
Loading…
Reference in a new issue