@thurinlabs/identity-kit 1.2.1 → 1.3.1

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.
@@ -31233,6 +31233,28 @@ ${prettyStateOverride(stateOverride)}`;
31233
31233
  return null;
31234
31234
  }
31235
31235
  }
31236
+ async function verifyClearsigned({ armoredKey, clearsigned }) {
31237
+ try {
31238
+ const openpgp = await Promise.resolve().then(() => (init_openpgp_min(), openpgp_min_exports));
31239
+ const { readKey, readCleartextMessage, LiteralDataPacket } = openpgp;
31240
+ const config = pgpConfig(openpgp);
31241
+ const publicKey = await readKey({ armoredKey });
31242
+ const message = await readCleartextMessage({ cleartextMessage: clearsigned });
31243
+ const msg = message;
31244
+ const now = /* @__PURE__ */ new Date();
31245
+ for (const sig of msg.signature.packets) {
31246
+ if (!publicKey.getKeys(sig.issuerKeyID).length) continue;
31247
+ const signingKey = await publicKey.getSigningKey(sig.issuerKeyID, now, void 0, config);
31248
+ const literal = new LiteralDataPacket();
31249
+ literal.setText(msg.text ?? message.getText().replace(/\r?\n/g, "\r\n"));
31250
+ await sig.verify(signingKey.keyPacket, sig.signatureType, literal, now, true, config);
31251
+ return { verified: true, text: message.getText() };
31252
+ }
31253
+ return { verified: false, reason: "Message is not signed by this key", text: message.getText() };
31254
+ } catch (err) {
31255
+ return { verified: false, reason: err instanceof Error ? err.message : "Verification failed", text: "" };
31256
+ }
31257
+ }
31236
31258
  async function verifyAttestation({
31237
31259
  pgpPublicKey,
31238
31260
  pgpSignature,
@@ -31244,28 +31266,15 @@ ${prettyStateOverride(stateOverride)}`;
31244
31266
  return { verified: false, reason: "Missing PGP data" };
31245
31267
  }
31246
31268
  const openpgp = await Promise.resolve().then(() => (init_openpgp_min(), openpgp_min_exports));
31247
- const { readKey, readCleartextMessage, LiteralDataPacket } = openpgp;
31248
- const config = pgpConfig(openpgp);
31269
+ const { readKey } = openpgp;
31249
31270
  const publicKey = await readKey({ armoredKey: pgpPublicKey });
31250
31271
  const keyFingerprint = publicKey.getFingerprint().toUpperCase();
31251
31272
  if (keyFingerprint !== fingerprint.toUpperCase()) {
31252
31273
  return { verified: false, reason: "Key fingerprint mismatch" };
31253
31274
  }
31254
- const message = await readCleartextMessage({ cleartextMessage: pgpSignature });
31255
- const msg = message;
31256
- const now = /* @__PURE__ */ new Date();
31257
- let signed2 = false;
31258
- for (const sig of msg.signature.packets) {
31259
- if (!publicKey.getKeys(sig.issuerKeyID).length) continue;
31260
- const signingKey = await publicKey.getSigningKey(sig.issuerKeyID, now, void 0, config);
31261
- const literal = new LiteralDataPacket();
31262
- literal.setText(msg.text ?? message.getText().replace(/\r?\n/g, "\r\n"));
31263
- await sig.verify(signingKey.keyPacket, sig.signatureType, literal, now, true, config);
31264
- signed2 = true;
31265
- break;
31266
- }
31267
- if (!signed2) return { verified: false, reason: "Message is not signed by this key" };
31268
- const signedText = message.getText();
31275
+ const v2 = await verifyClearsigned({ armoredKey: pgpPublicKey, clearsigned: pgpSignature });
31276
+ if (!v2.verified) return { verified: false, reason: v2.reason };
31277
+ const signedText = v2.text;
31269
31278
  if (!signedText.toLowerCase().includes(ethAddress.toLowerCase())) {
31270
31279
  return { verified: false, reason: "Signed message does not contain ETH address" };
31271
31280
  }