forked from Mirrors/doipjs
Make network errors not block code execution
This commit is contained in:
parent
527f19e682
commit
4f3db39b18
1 changed files with 38 additions and 13 deletions
51
src/keys.js
51
src/keys.js
|
@ -30,14 +30,25 @@ const fetchHKP = (identifier, keyserverBaseUrl) => {
|
||||||
const lookupOpts = {
|
const lookupOpts = {
|
||||||
query: identifier,
|
query: identifier,
|
||||||
}
|
}
|
||||||
let publicKey = await hkp.lookup(lookupOpts)
|
|
||||||
publicKey = (await openpgp.key.readArmored(publicKey)).keys[0]
|
|
||||||
|
|
||||||
if (publicKey == undefined) {
|
let publicKey = await hkp.lookup(lookupOpts)
|
||||||
|
.catch((error) => {
|
||||||
|
reject('Key does not exist or could not be fetched')
|
||||||
|
})
|
||||||
|
|
||||||
|
publicKey = await openpgp.key.readArmored(publicKey)
|
||||||
|
.then((result) => {
|
||||||
|
return result.keys[0]
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
|
||||||
|
if (publicKey) {
|
||||||
|
resolve(publicKey)
|
||||||
|
} else {
|
||||||
reject('Key does not exist or could not be fetched')
|
reject('Key does not exist or could not be fetched')
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve(publicKey)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,13 +58,20 @@ const fetchWKD = (identifier) => {
|
||||||
const lookupOpts = {
|
const lookupOpts = {
|
||||||
email: identifier,
|
email: identifier,
|
||||||
}
|
}
|
||||||
const publicKey = (await wkd.lookup(lookupOpts)).keys[0]
|
|
||||||
|
|
||||||
if (publicKey == undefined) {
|
const publicKey = await wkd.lookup(lookupOpts)
|
||||||
|
.then((result) => {
|
||||||
|
return result.keys[0]
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
|
||||||
|
if (publicKey) {
|
||||||
|
resolve(publicKey)
|
||||||
|
} else {
|
||||||
reject('Key does not exist or could not be fetched')
|
reject('Key does not exist or could not be fetched')
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve(publicKey)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,13 +89,20 @@ const fetchKeybase = (username, fingerprint) => {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
reject(`Error fetching Keybase key: ${e.message}`)
|
reject(`Error fetching Keybase key: ${e.message}`)
|
||||||
}
|
}
|
||||||
const publicKey = (await openpgp.key.readArmored(rawKeyContent)).keys[0]
|
|
||||||
|
|
||||||
if (publicKey == undefined) {
|
const publicKey = await openpgp.key.readArmored(rawKeyContent)
|
||||||
|
.then((result) => {
|
||||||
|
return result.keys[0]
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
|
||||||
|
if (publicKey) {
|
||||||
|
resolve(publicKey)
|
||||||
|
} else {
|
||||||
reject('Key does not exist or could not be fetched')
|
reject('Key does not exist or could not be fetched')
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve(publicKey)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue