chore: update builds

This commit is contained in:
Yarmo Mackenbach 2023-07-13 10:41:31 +02:00
parent a8a97b2d85
commit b4ac82b010
No known key found for this signature in database
GPG key ID: 3C57D093219103A3
2 changed files with 121 additions and 125 deletions

242
dist/doip.core.js vendored
View file

@ -191,6 +191,7 @@ var doip = (function (exports, fetcher, openpgp$1) {
EDDSA: 'eddsa', EDDSA: 'eddsa',
ES256: 'es256', ES256: 'es256',
OPENPGP: 'openpgp', OPENPGP: 'openpgp',
UNKNOWN: 'unknown',
NONE: 'none' NONE: 'none'
}; };
@ -313,6 +314,12 @@ var doip = (function (exports, fetcher, openpgp$1) {
* @public * @public
*/ */
keyType: PublicKeyType.NONE, keyType: PublicKeyType.NONE,
/**
* The fingerprint of the cryptographic key
* @type {string | null}
* @public
*/
fingerprint: null,
/** /**
* The encoding of the cryptographic key * The encoding of the cryptographic key
* @type {PublicKeyEncoding} * @type {PublicKeyEncoding}
@ -327,7 +334,7 @@ var doip = (function (exports, fetcher, openpgp$1) {
encodedKey: null, encodedKey: null,
/** /**
* The raw cryptographic key as object (to be removed during toJSON()) * The raw cryptographic key as object (to be removed during toJSON())
* @type {import('openpgp').PublicKey | import('jose').KeyLike | null} * @type {import('openpgp').PublicKey | import('jose').JWK | null}
* @public * @public
*/ */
key: null, key: null,
@ -374,18 +381,6 @@ var doip = (function (exports, fetcher, openpgp$1) {
this.verifiers.push({ name, url }); this.verifiers.push({ name, url });
} }
/**
* @function
* @param {import('openpgp').PublicKey} publicKey
*/
setOpenPgpPublicKey (publicKey) {}
/**
* @function
* @param {import('jose').KeyLike} publicKey
*/
setJwkPublicKey (publicKey) {}
/** /**
* Get a JSON representation of the Profile object * Get a JSON representation of the Profile object
* @function * @function
@ -400,6 +395,7 @@ var doip = (function (exports, fetcher, openpgp$1) {
primaryPersonaIndex: this.primaryPersonaIndex, primaryPersonaIndex: this.primaryPersonaIndex,
publicKey: { publicKey: {
keyType: this.publicKey.keyType, keyType: this.publicKey.keyType,
fingerprint: this.publicKey.fingerprint,
encoding: this.publicKey.encoding, encoding: this.publicKey.encoding,
encodedKey: this.publicKey.encodedKey, encodedKey: this.publicKey.encodedKey,
fetch: { fetch: {
@ -1580,7 +1576,7 @@ var doip = (function (exports, fetcher, openpgp$1) {
const scheme = opts.proxy.scheme ? opts.proxy.scheme : 'https'; const scheme = opts.proxy.scheme ? opts.proxy.scheme : 'https';
return `${scheme}://${opts.proxy.hostname}/api/2/get/${type}?${queryStrings.join( return `${scheme}://${opts.proxy.hostname}/api/3/get/${type}?${queryStrings.join(
'&' '&'
)}` )}`
} }
@ -1696,7 +1692,7 @@ var doip = (function (exports, fetcher, openpgp$1) {
return createProxyRequestPromise(data, opts) return createProxyRequestPromise(data, opts)
case ProxyPolicy.NEVER: case ProxyPolicy.NEVER:
switch (data.proof.request.access) { switch (data.proof.request.accessRestriction) {
case ProofAccessRestriction.NONE: case ProofAccessRestriction.NONE:
case ProofAccessRestriction.GRANTED: case ProofAccessRestriction.GRANTED:
return createDefaultRequestPromise(data, opts) return createDefaultRequestPromise(data, opts)
@ -1710,7 +1706,7 @@ var doip = (function (exports, fetcher, openpgp$1) {
} }
case ProxyPolicy.ADAPTIVE: case ProxyPolicy.ADAPTIVE:
switch (data.proof.request.access) { switch (data.proof.request.accessRestriction) {
case ProofAccessRestriction.NONE: case ProofAccessRestriction.NONE:
return createFallbackRequestPromise(data, opts) return createFallbackRequestPromise(data, opts)
case ProofAccessRestriction.NOCORS: case ProofAccessRestriction.NOCORS:
@ -1795,8 +1791,8 @@ var doip = (function (exports, fetcher, openpgp$1) {
const requestData = { const requestData = {
url: proxyUrl, url: proxyUrl,
format: data.proof.request.format, format: data.proof.response.format,
fetcherTimeout: fetcher__namespace[data.proof.request.fetcher].timeout fetcherTimeout: data.proof.request.fetcher in fetcher__namespace ? fetcher__namespace[data.proof.request.fetcher].timeout : 30000
}; };
fetcher__namespace.http fetcher__namespace.http
.fn(requestData, opts) .fn(requestData, opts)
@ -5666,7 +5662,7 @@ var doip = (function (exports, fetcher, openpgp$1) {
claim._uri = claimObject.uri; claim._uri = claimObject.uri;
claim._fingerprint = claimObject.fingerprint; claim._fingerprint = claimObject.fingerprint;
claim._matches = claimObject.matches; claim._matches = claimObject.matches.map(x => new ServiceProvider(x));
if (claimObject.status === 'init') { if (claimObject.status === 'init') {
claim._status = 100; claim._status = 100;
@ -5707,7 +5703,7 @@ var doip = (function (exports, fetcher, openpgp$1) {
claim._uri = claimObject.uri; claim._uri = claimObject.uri;
claim._fingerprint = claimObject.proofs[0]; claim._fingerprint = claimObject.proofs[0];
claim._matches = claimObject.matches; claim._matches = claimObject.matches.map(x => new ServiceProvider(x));
claim._status = claimObject.status; claim._status = claimObject.status;
return claim return claim
@ -7958,10 +7954,6 @@ var doip = (function (exports, fetcher, openpgp$1) {
}); });
const profile = await parsePublicKey(publicKey); const profile = await parsePublicKey(publicKey);
profile.publicKey.keyType = PublicKeyType.OPENPGP;
profile.publicKey.encoding = PublicKeyEncoding.ARMORED_PGP;
profile.publicKey.encodedKey = publicKey.armor();
profile.publicKey.key = publicKey;
profile.publicKey.fetch.method = PublicKeyFetchMethod.HKP; profile.publicKey.fetch.method = PublicKeyFetchMethod.HKP;
profile.publicKey.fetch.query = identifier; profile.publicKey.fetch.query = identifier;
@ -8000,10 +7992,6 @@ var doip = (function (exports, fetcher, openpgp$1) {
}); });
const profile = await parsePublicKey(publicKey); const profile = await parsePublicKey(publicKey);
profile.publicKey.keyType = PublicKeyType.OPENPGP;
profile.publicKey.encoding = PublicKeyEncoding.ARMORED_PGP;
profile.publicKey.encodedKey = publicKey.armor();
profile.publicKey.key = publicKey;
profile.publicKey.fetch.method = PublicKeyFetchMethod.WKD; profile.publicKey.fetch.method = PublicKeyFetchMethod.WKD;
profile.publicKey.fetch.query = identifier; profile.publicKey.fetch.query = identifier;
@ -8047,10 +8035,6 @@ var doip = (function (exports, fetcher, openpgp$1) {
}); });
const profile = await parsePublicKey(publicKey); const profile = await parsePublicKey(publicKey);
profile.publicKey.keyType = PublicKeyType.OPENPGP;
profile.publicKey.encoding = PublicKeyEncoding.ARMORED_PGP;
profile.publicKey.encodedKey = publicKey.armor();
profile.publicKey.key = publicKey;
profile.publicKey.fetch.method = PublicKeyFetchMethod.HTTP; profile.publicKey.fetch.method = PublicKeyFetchMethod.HTTP;
profile.publicKey.fetch.query = null; profile.publicKey.fetch.query = null;
profile.publicKey.fetch.resolvedUrl = keyLink; profile.publicKey.fetch.resolvedUrl = keyLink;
@ -8081,10 +8065,6 @@ var doip = (function (exports, fetcher, openpgp$1) {
}); });
const profile = await parsePublicKey(publicKey); const profile = await parsePublicKey(publicKey);
profile.publicKey.keyType = PublicKeyType.OPENPGP;
profile.publicKey.encoding = PublicKeyEncoding.ARMORED_PGP;
profile.publicKey.encodedKey = publicKey.armor();
profile.publicKey.key = publicKey;
return profile return profile
} }
@ -8178,14 +8158,14 @@ var doip = (function (exports, fetcher, openpgp$1) {
} }
/** /**
* Process a public key to get user data and claims * Process a public key to get a profile
* @function * @function
* @param {PublicKey} publicKey - The public key to process * @param {PublicKey} publicKey - The public key to parse
* @returns {Promise<Profile>} * @returns {Promise<Profile>}
* @example * @example
* const key = doip.keys.fetchURI('hkp:alice@domain.tld'); * const key = doip.keys.fetchURI('hkp:alice@domain.tld');
* const data = doip.keys.process(key); * const profile = doip.keys.parsePublicKey(key);
* data.users[0].claims.forEach(claim => { * profile.personas[0].claims.forEach(claim => {
* console.log(claim.uri); * console.log(claim.uri);
* }); * });
*/ */
@ -8226,10 +8206,16 @@ var doip = (function (exports, fetcher, openpgp$1) {
personas.push(pe); personas.push(pe);
}); });
const pr = new Profile(ProfileType.OPENPGP, `openpgp4fpr:${fingerprint}`, personas); const profile = new Profile(ProfileType.OPENPGP, `openpgp4fpr:${fingerprint}`, personas);
pr.primaryPersonaIndex = primaryUser.index; profile.primaryPersonaIndex = primaryUser.index;
return pr profile.publicKey.keyType = PublicKeyType.OPENPGP;
profile.publicKey.fingerprint = fingerprint;
profile.publicKey.encoding = PublicKeyEncoding.ARMORED_PGP;
profile.publicKey.encodedKey = publicKey.armor();
profile.publicKey.key = publicKey;
return profile
} }
var openpgp = /*#__PURE__*/Object.freeze({ var openpgp = /*#__PURE__*/Object.freeze({
@ -8239,7 +8225,8 @@ var doip = (function (exports, fetcher, openpgp$1) {
fetchKeybase: fetchKeybase, fetchKeybase: fetchKeybase,
fetchPlaintext: fetchPlaintext, fetchPlaintext: fetchPlaintext,
fetchURI: fetchURI, fetchURI: fetchURI,
fetchWKD: fetchWKD fetchWKD: fetchWKD,
parsePublicKey: parsePublicKey
}); });
var crypto$1 = crypto; var crypto$1 = crypto;
@ -8658,7 +8645,7 @@ var doip = (function (exports, fetcher, openpgp$1) {
} }
return { algorithm, keyUsages }; return { algorithm, keyUsages };
} }
const parse$1 = async (jwk) => { const parse$2 = async (jwk) => {
var _a, _b; var _a, _b;
if (!jwk.alg) { if (!jwk.alg) {
throw new TypeError('"alg" argument is required when "jwk.alg" is not present'); throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
@ -8677,7 +8664,7 @@ var doip = (function (exports, fetcher, openpgp$1) {
delete keyData.use; delete keyData.use;
return crypto$1.subtle.importKey('jwk', keyData, ...rest); return crypto$1.subtle.importKey('jwk', keyData, ...rest);
}; };
var asKeyObject = parse$1; var asKeyObject = parse$2;
async function importJWK(jwk, alg, octAsKeyObject) { async function importJWK(jwk, alg, octAsKeyObject) {
var _a; var _a;
@ -9043,7 +9030,7 @@ var doip = (function (exports, fetcher, openpgp$1) {
Object.defineProperty(lib, '__esModule', { value: true }); Object.defineProperty(lib, '__esModule', { value: true });
/* eslint-disable @typescript-eslint/strict-boolean-expressions */ /* eslint-disable @typescript-eslint/strict-boolean-expressions */
function parse(string, encoding, opts) { function parse$1(string, encoding, opts) {
var _opts$out; var _opts$out;
if (opts === void 0) { if (opts === void 0) {
@ -9171,51 +9158,51 @@ var doip = (function (exports, fetcher, openpgp$1) {
bits: 6 bits: 6
}; };
var base16 = { var base16 = {
parse: function parse$1(string, opts) { parse: function parse$1$1(string, opts) {
return parse(string.toUpperCase(), base16Encoding, opts); return parse$1(string.toUpperCase(), base16Encoding, opts);
}, },
stringify: function stringify$1(data, opts) { stringify: function stringify$1(data, opts) {
return stringify(data, base16Encoding, opts); return stringify(data, base16Encoding, opts);
} }
}; };
var base32$1 = { var base32$1 = {
parse: function parse$1(string, opts) { parse: function parse$1$1(string, opts) {
if (opts === void 0) { if (opts === void 0) {
opts = {}; opts = {};
} }
return parse(opts.loose ? string.toUpperCase().replace(/0/g, 'O').replace(/1/g, 'L').replace(/8/g, 'B') : string, base32Encoding, opts); return parse$1(opts.loose ? string.toUpperCase().replace(/0/g, 'O').replace(/1/g, 'L').replace(/8/g, 'B') : string, base32Encoding, opts);
}, },
stringify: function stringify$1(data, opts) { stringify: function stringify$1(data, opts) {
return stringify(data, base32Encoding, opts); return stringify(data, base32Encoding, opts);
} }
}; };
var base32hex = { var base32hex = {
parse: function parse$1(string, opts) { parse: function parse$1$1(string, opts) {
return parse(string, base32HexEncoding, opts); return parse$1(string, base32HexEncoding, opts);
}, },
stringify: function stringify$1(data, opts) { stringify: function stringify$1(data, opts) {
return stringify(data, base32HexEncoding, opts); return stringify(data, base32HexEncoding, opts);
} }
}; };
var base64 = { var base64 = {
parse: function parse$1(string, opts) { parse: function parse$1$1(string, opts) {
return parse(string, base64Encoding, opts); return parse$1(string, base64Encoding, opts);
}, },
stringify: function stringify$1(data, opts) { stringify: function stringify$1(data, opts) {
return stringify(data, base64Encoding, opts); return stringify(data, base64Encoding, opts);
} }
}; };
var base64url$1 = { var base64url$1 = {
parse: function parse$1(string, opts) { parse: function parse$1$1(string, opts) {
return parse(string, base64UrlEncoding, opts); return parse$1(string, base64UrlEncoding, opts);
}, },
stringify: function stringify$1(data, opts) { stringify: function stringify$1(data, opts) {
return stringify(data, base64UrlEncoding, opts); return stringify(data, base64UrlEncoding, opts);
} }
}; };
var codec = { var codec = {
parse: parse, parse: parse$1,
stringify: stringify stringify: stringify
}; };
@ -9298,7 +9285,12 @@ var doip = (function (exports, fetcher, openpgp$1) {
throw new Error(`Error fetching Keybase key: ${e.message}`) throw new Error(`Error fetching Keybase key: ${e.message}`)
} }
return await parseProfileJws(profileJws, uri) const profile = await parseProfileJws(profileJws, uri);
profile.publicKey.fetch.method = PublicKeyFetchMethod.ASPE;
profile.publicKey.fetch.query = uri;
profile.publicKey.fetch.resolvedUrl = profileUrl;
return profile
} }
/** /**
@ -9366,9 +9358,27 @@ var doip = (function (exports, fetcher, openpgp$1) {
pe.setDescription(profileDescription); pe.setDescription(profileDescription);
} }
const pr = new Profile(ProfileType.ASP, uri, [pe]); const profile = new Profile(ProfileType.ASP, uri, [pe]);
profile.publicKey.fingerprint = fp;
profile.publicKey.encoding = PublicKeyEncoding.JWK;
profile.publicKey.encodedKey = JSON.stringify(protectedHeader.jwk);
profile.publicKey.key = protectedHeader.jwk;
return pr switch (protectedHeader.alg) {
case 'ES256':
profile.publicKey.keyType = PublicKeyType.ES256;
break
case 'EdDSA':
profile.publicKey.keyType = PublicKeyType.EDDSA;
break
default:
profile.publicKey.keyType = PublicKeyType.UNKNOWN;
break
}
return profile
} }
/** /**
@ -9413,29 +9423,14 @@ var doip = (function (exports, fetcher, openpgp$1) {
*/ */
/** /**
* Extract data from a signature and fetch the associated key * Extract the profile from a signature and fetch the associated key
* @async * @async
* @param {string} signature - The plaintext signature to process * @param {string} signature - The plaintext signature to parse
* @returns {Promise<object>} * @returns {Promise<import('./profile.js').Profile>}
*/ */
async function process (signature) { async function parse (signature) {
/** @type {import('openpgp').CleartextMessage} */ /** @type {import('openpgp').CleartextMessage} */
let sigData; let sigData;
const result = {
fingerprint: null,
users: [
{
userData: {},
claims: []
}
],
primaryUserIndex: null,
key: {
data: null,
fetchMethod: null,
uri: null
}
};
// Read the signature // Read the signature
try { try {
@ -9456,6 +9451,7 @@ var doip = (function (exports, fetcher, openpgp$1) {
'https://keys.openpgp.org/'; 'https://keys.openpgp.org/';
const text = sigData.getText(); const text = sigData.getText();
const sigKeys = []; const sigKeys = [];
const claims = [];
text.split('\n').forEach((line, i) => { text.split('\n').forEach((line, i) => {
const match = line.match(/^([a-zA-Z0-9]*)=(.*)$/i); const match = line.match(/^([a-zA-Z0-9]*)=(.*)$/i);
@ -9468,44 +9464,54 @@ var doip = (function (exports, fetcher, openpgp$1) {
break break
case 'proof': case 'proof':
result.users[0].claims.push(new Claim(match[2])); claims.push(new Claim(match[2]));
break break
} }
}); });
// Try overruling key const obtainedKey = {
query: null,
data: null,
method: null
};
// Try key identifier found in the signature
if (sigKeys.length > 0) { if (sigKeys.length > 0) {
try { try {
result.key.uri = sigKeys[0]; obtainedKey.query = sigKeys[0];
result.key.data = (await fetchURI(result.key.uri)).publicKey.key; /** @type {import('openpgp').PublicKey} */
result.key.fetchMethod = result.key.uri.split(':')[0]; obtainedKey.data = (await fetchURI(obtainedKey.query)).publicKey.key;
obtainedKey.method = obtainedKey.query.split(':')[0];
} catch (e) {} } catch (e) {}
} }
// Try WKD // Try WKD
if (!result.key.data && signersUserID) { if (!obtainedKey.data && signersUserID) {
try { try {
result.key.uri = `wkd:${signersUserID}`; obtainedKey.query = signersUserID;
result.key.data = (await fetchURI(result.key.uri)).publicKey.key; obtainedKey.data = (await fetchURI(`wkd:${signersUserID}`)).publicKey.key;
result.key.fetchMethod = 'wkd'; obtainedKey.method = 'wkd';
} catch (e) {} } catch (e) {}
} }
// Try HKP // Try HKP
if (!result.key.data) { if (!obtainedKey.data) {
try { try {
const match = preferredKeyServer.match(/^(.*:\/\/)?([^/]*)(?:\/)?$/i); const match = preferredKeyServer.match(/^(.*:\/\/)?([^/]*)(?:\/)?$/i);
result.key.uri = `hkp:${match[2]}:${issuerKeyID || signersUserID}`; obtainedKey.query = issuerKeyID || signersUserID;
result.key.data = (await fetchURI(result.key.uri)).publicKey.key; obtainedKey.data = (await fetchURI(`hkp:${match[2]}:${obtainedKey.query}`)).publicKey.key;
result.key.fetchMethod = 'hkp'; obtainedKey.method = 'hkp';
} catch (e) { } catch (e) {
throw new Error('Public key not found') throw new Error('Public key not found')
} }
} }
const primaryUserData = await obtainedKey.data.getPrimaryUser();
const fingerprint = obtainedKey.data.getFingerprint();
// Verify the signature // Verify the signature
const verificationResult = await openpgp$1.verify({ const verificationResult = await openpgp$1.verify({
// @ts-ignore // @ts-ignore
message: sigData, message: sigData,
verificationKeys: result.key.data verificationKeys: obtainedKey.data
}); });
const { verified } = verificationResult.signatures[0]; const { verified } = verificationResult.signatures[0];
try { try {
@ -9514,42 +9520,32 @@ var doip = (function (exports, fetcher, openpgp$1) {
throw new Error(`Signature could not be verified (${e.message})`) throw new Error(`Signature could not be verified (${e.message})`)
} }
result.fingerprint = result.key.data.keyPacket.getFingerprint(); // Build the persona
const persona = new Persona(primaryUserData.user.userID.name, []);
persona.setIdentifier(primaryUserData.user.userID.userID);
persona.setDescription(primaryUserData.user.userID.comment || null);
persona.setEmailAddress(primaryUserData.user.userID.email || null);
persona.claims = claims
.map(
({ value }) =>
new Claim(new TextDecoder().decode(value), `openpgp4fpr:${fingerprint}`)
);
result.users[0].claims.forEach((claim) => { const profile = new Profile(ProfileType.OPENPGP, `openpgp4fpr:${fingerprint}`, [persona]);
claim.fingerprint = result.fingerprint;
});
const primaryUserData = await result.key.data.getPrimaryUser(); profile.publicKey.keyType = PublicKeyType.OPENPGP;
let userData; profile.publicKey.encoding = PublicKeyEncoding.ARMORED_PGP;
profile.publicKey.encodedKey = obtainedKey.data.armor();
profile.publicKey.key = obtainedKey.data;
profile.publicKey.fetch.method = obtainedKey.method;
profile.publicKey.fetch.query = obtainedKey.query;
if (signersUserID) { return profile
result.key.data.users.forEach((/** @type {{ userID: { email: string; }; }} */ user) => {
if (user.userID.email === signersUserID) {
userData = user;
}
});
}
if (!userData) {
userData = primaryUserData.user;
}
result.users[0].userData = {
id: userData.userID ? userData.userID.userID : null,
name: userData.userID ? userData.userID.name : null,
email: userData.userID ? userData.userID.email : null,
comment: userData.userID ? userData.userID.comment : null,
isPrimary: primaryUserData.user.userID.userID === userData.userID.userID
};
result.primaryUserIndex = result.users[0].userData.isPrimary ? 0 : null;
return result
} }
var signatures = /*#__PURE__*/Object.freeze({ var signatures = /*#__PURE__*/Object.freeze({
__proto__: null, __proto__: null,
process: process parse: parse
}); });
exports.fetcher = fetcher__namespace; exports.fetcher = fetcher__namespace;

File diff suppressed because one or more lines are too long