Add support for advanced WKD lookup (#1115)
This commit is contained in:
parent
00c5f38689
commit
4af9b51915
15
src/wkd.js
15
src/wkd.js
|
@ -57,12 +57,23 @@ WKD.prototype.lookup = async function(options) {
|
||||||
const [, localPart, domain] = /(.*)@(.*)/.exec(options.email);
|
const [, localPart, domain] = /(.*)@(.*)/.exec(options.email);
|
||||||
const localEncoded = util.encodeZBase32(await crypto.hash.sha1(util.str_to_Uint8Array(localPart.toLowerCase())));
|
const localEncoded = util.encodeZBase32(await crypto.hash.sha1(util.str_to_Uint8Array(localPart.toLowerCase())));
|
||||||
|
|
||||||
const url = `https://${domain}/.well-known/openpgpkey/hu/${localEncoded}`;
|
const urlAdvanced = `https://openpgpkey.${domain}/.well-known/openpgpkey/${domain}/hu/${localEncoded}`;
|
||||||
|
const urlDirect = `https://${domain}/.well-known/openpgpkey/hu/${localEncoded}`;
|
||||||
|
|
||||||
return fetch(url).then(function(response) {
|
return fetch(urlAdvanced).then(function(response) {
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
return response.arrayBuffer();
|
return response.arrayBuffer();
|
||||||
}
|
}
|
||||||
|
}).then(function(publicKey) {
|
||||||
|
if (publicKey) {
|
||||||
|
return publicKey;
|
||||||
|
} else {
|
||||||
|
return fetch(urlDirect).then(function(response) {
|
||||||
|
if (response.status === 200) {
|
||||||
|
return response.arrayBuffer();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}).then(function(publicKey) {
|
}).then(function(publicKey) {
|
||||||
if (publicKey) {
|
if (publicKey) {
|
||||||
const rawBytes = new Uint8Array(publicKey);
|
const rawBytes = new Uint8Array(publicKey);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user