@thurinlabs/identity-kit 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1339,6 +1339,9 @@ function keyIdToBytes(keyId) {
1339
1339
  }
1340
1340
 
1341
1341
  // src/core/pgp.ts
1342
+ function pgpConfig(openpgp) {
1343
+ return { ...openpgp.config, rejectCurves: /* @__PURE__ */ new Set() };
1344
+ }
1342
1345
  function algorithmName(keyOrSubkey) {
1343
1346
  try {
1344
1347
  const info = keyOrSubkey.getAlgorithmInfo();
@@ -1360,7 +1363,9 @@ function algorithmName(keyOrSubkey) {
1360
1363
  }
1361
1364
  async function parsePgpKey(armoredKey) {
1362
1365
  try {
1363
- const { readKey } = await import("openpgp");
1366
+ const openpgp = await import("openpgp");
1367
+ const { readKey } = openpgp;
1368
+ const config = pgpConfig(openpgp);
1364
1369
  const key = await readKey({ armoredKey });
1365
1370
  const fingerprint = key.getFingerprint().toUpperCase();
1366
1371
  const algorithm = algorithmName(key);
@@ -1379,7 +1384,12 @@ async function parsePgpKey(armoredKey) {
1379
1384
  await cert.verify(
1380
1385
  key.keyPacket,
1381
1386
  cert.signatureType,
1382
- { userID: user.userID, key: key.keyPacket }
1387
+ { userID: user.userID, key: key.keyPacket },
1388
+ void 0,
1389
+ // date: now
1390
+ void 0,
1391
+ // detached
1392
+ config
1383
1393
  );
1384
1394
  } catch {
1385
1395
  continue;
@@ -1423,15 +1433,28 @@ async function verifyAttestation({
1423
1433
  if (!pgpPublicKey || !pgpSignature) {
1424
1434
  return { verified: false, reason: "Missing PGP data" };
1425
1435
  }
1426
- const { readKey, readCleartextMessage, verify } = await import("openpgp");
1436
+ const openpgp = await import("openpgp");
1437
+ const { readKey, readCleartextMessage, LiteralDataPacket } = openpgp;
1438
+ const config = pgpConfig(openpgp);
1427
1439
  const publicKey = await readKey({ armoredKey: pgpPublicKey });
1428
1440
  const keyFingerprint = publicKey.getFingerprint().toUpperCase();
1429
1441
  if (keyFingerprint !== fingerprint.toUpperCase()) {
1430
1442
  return { verified: false, reason: "Key fingerprint mismatch" };
1431
1443
  }
1432
1444
  const message = await readCleartextMessage({ cleartextMessage: pgpSignature });
1433
- const { signatures } = await verify({ message, verificationKeys: publicKey });
1434
- await signatures[0].verified;
1445
+ const msg = message;
1446
+ const now = /* @__PURE__ */ new Date();
1447
+ let signed = false;
1448
+ for (const sig of msg.signature.packets) {
1449
+ if (!publicKey.getKeys(sig.issuerKeyID).length) continue;
1450
+ const signingKey = await publicKey.getSigningKey(sig.issuerKeyID, now, void 0, config);
1451
+ const literal = new LiteralDataPacket();
1452
+ literal.setText(msg.text ?? message.getText().replace(/\r?\n/g, "\r\n"));
1453
+ await sig.verify(signingKey.keyPacket, sig.signatureType, literal, now, true, config);
1454
+ signed = true;
1455
+ break;
1456
+ }
1457
+ if (!signed) return { verified: false, reason: "Message is not signed by this key" };
1435
1458
  const signedText = message.getText();
1436
1459
  if (!signedText.toLowerCase().includes(ethAddress.toLowerCase())) {
1437
1460
  return { verified: false, reason: "Signed message does not contain ETH address" };