@orangecheck/sdk 1.14.0 → 1.15.0
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/attestation.js +307 -61
- package/dist/attestation.js.map +1 -1
- package/dist/attestation.mjs +307 -61
- package/dist/attestation.mjs.map +1 -1
- package/dist/identity.js +19 -17
- package/dist/identity.js.map +1 -1
- package/dist/identity.mjs +19 -17
- package/dist/identity.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +676 -615
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +675 -616
- package/dist/index.mjs.map +1 -1
- package/dist/nostr.d.mts +3 -1
- package/dist/nostr.d.ts +3 -1
- package/dist/nostr.js +294 -38
- package/dist/nostr.js.map +1 -1
- package/dist/nostr.mjs +293 -39
- package/dist/nostr.mjs.map +1 -1
- package/dist/verify.d.mts +11 -2
- package/dist/verify.d.ts +11 -2
- package/dist/verify.js +24 -4
- package/dist/verify.js.map +1 -1
- package/dist/verify.mjs +24 -5
- package/dist/verify.mjs.map +1 -1
- package/package.json +1 -1
package/dist/identity.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
var secp256k1_js = require('@noble/curves/secp256k1.js');
|
|
4
4
|
var sha2_js = require('@noble/hashes/sha2.js');
|
|
5
5
|
var base = require('@scure/base');
|
|
6
|
+
require('buffer');
|
|
7
|
+
require('@orangecheck/bip322');
|
|
6
8
|
|
|
7
9
|
// src/utils/logger.ts
|
|
8
10
|
function createLogger(namespace) {
|
|
@@ -408,7 +410,7 @@ var DEFAULT_RELAYS = [
|
|
|
408
410
|
];
|
|
409
411
|
|
|
410
412
|
// src/identity/nostr.ts
|
|
411
|
-
var
|
|
413
|
+
var log5 = createLogger("identity-verification/nostr");
|
|
412
414
|
var HEX_64_RE2 = /^[0-9a-f]{64}$/;
|
|
413
415
|
function toHex2(bytes) {
|
|
414
416
|
let out = "";
|
|
@@ -431,7 +433,7 @@ function npubToHex(npub) {
|
|
|
431
433
|
async function queryNostrEvents(options) {
|
|
432
434
|
const { authors, kinds, search, relays = DEFAULT_RELAYS, limit = 100 } = options;
|
|
433
435
|
const events = [];
|
|
434
|
-
|
|
436
|
+
log5.info({ authors, kinds, relayCount: relays.length }, "Querying Nostr for events");
|
|
435
437
|
const queryPromises = relays.map(async (relayUrl) => {
|
|
436
438
|
let ws = null;
|
|
437
439
|
try {
|
|
@@ -472,11 +474,11 @@ async function queryNostrEvents(options) {
|
|
|
472
474
|
resolve();
|
|
473
475
|
}
|
|
474
476
|
} catch (err) {
|
|
475
|
-
|
|
477
|
+
log5.error({ relay: relayUrl, error: err }, "Failed to parse event");
|
|
476
478
|
}
|
|
477
479
|
};
|
|
478
480
|
wsRef.onerror = (err) => {
|
|
479
|
-
|
|
481
|
+
log5.error({ relay: relayUrl, error: err }, "WebSocket error during query");
|
|
480
482
|
cleanup();
|
|
481
483
|
reject(err);
|
|
482
484
|
};
|
|
@@ -485,7 +487,7 @@ async function queryNostrEvents(options) {
|
|
|
485
487
|
};
|
|
486
488
|
});
|
|
487
489
|
} catch (err) {
|
|
488
|
-
|
|
490
|
+
log5.error({ relay: relayUrl, error: err }, "Failed to query relay");
|
|
489
491
|
} finally {
|
|
490
492
|
if (ws && ws.readyState !== WebSocket.CLOSED) {
|
|
491
493
|
ws.close();
|
|
@@ -493,7 +495,7 @@ async function queryNostrEvents(options) {
|
|
|
493
495
|
}
|
|
494
496
|
});
|
|
495
497
|
await Promise.allSettled(queryPromises);
|
|
496
|
-
|
|
498
|
+
log5.info({ eventCount: events.length }, "Query complete");
|
|
497
499
|
return events;
|
|
498
500
|
}
|
|
499
501
|
async function verifyNostrEventSignature(event) {
|
|
@@ -514,7 +516,7 @@ function nostrEventSignatureValid(event) {
|
|
|
514
516
|
]);
|
|
515
517
|
const computedId = toHex2(sha2_js.sha256(new TextEncoder().encode(preimage)));
|
|
516
518
|
if (computedId !== event.id.toLowerCase()) {
|
|
517
|
-
|
|
519
|
+
log5.warn(
|
|
518
520
|
{ eventId: event.id, computedId },
|
|
519
521
|
"nostr event id does not match its content"
|
|
520
522
|
);
|
|
@@ -522,12 +524,12 @@ function nostrEventSignatureValid(event) {
|
|
|
522
524
|
}
|
|
523
525
|
return secp256k1_js.schnorr.verify(fromHex(event.sig), fromHex(event.id), fromHex(event.pubkey));
|
|
524
526
|
} catch (err) {
|
|
525
|
-
|
|
527
|
+
log5.warn({ err }, "schnorr verify threw");
|
|
526
528
|
return false;
|
|
527
529
|
}
|
|
528
530
|
}
|
|
529
531
|
async function verifyNostrIdentity(attestationId, npub, relays) {
|
|
530
|
-
|
|
532
|
+
log5.info({ attestationId, npub }, "Verifying Nostr identity");
|
|
531
533
|
try {
|
|
532
534
|
const pubkeyHex = npubToHex(npub);
|
|
533
535
|
const events = await queryNostrEvents({
|
|
@@ -538,7 +540,7 @@ async function verifyNostrIdentity(attestationId, npub, relays) {
|
|
|
538
540
|
relays
|
|
539
541
|
});
|
|
540
542
|
if (events.length === 0) {
|
|
541
|
-
|
|
543
|
+
log5.info({ npub }, "No verification events found");
|
|
542
544
|
return {
|
|
543
545
|
verified: false,
|
|
544
546
|
error: "No verification event found. User must post a note containing the attestation ID."
|
|
@@ -548,13 +550,13 @@ async function verifyNostrIdentity(attestationId, npub, relays) {
|
|
|
548
550
|
if (event.content.includes(attestationId)) {
|
|
549
551
|
const isValid = await verifyNostrEventSignature(event);
|
|
550
552
|
if (isValid) {
|
|
551
|
-
|
|
553
|
+
log5.info({ npub, eventId: event.id }, "Nostr identity verified");
|
|
552
554
|
return {
|
|
553
555
|
verified: true,
|
|
554
556
|
event
|
|
555
557
|
};
|
|
556
558
|
} else {
|
|
557
|
-
|
|
559
|
+
log5.warn({ npub, eventId: event.id }, "Invalid event signature");
|
|
558
560
|
}
|
|
559
561
|
}
|
|
560
562
|
}
|
|
@@ -563,7 +565,7 @@ async function verifyNostrIdentity(attestationId, npub, relays) {
|
|
|
563
565
|
error: "Found events but none had valid signatures"
|
|
564
566
|
};
|
|
565
567
|
} catch (err) {
|
|
566
|
-
|
|
568
|
+
log5.error({ error: err, npub }, "Failed to verify Nostr identity");
|
|
567
569
|
return {
|
|
568
570
|
verified: false,
|
|
569
571
|
error: err instanceof Error ? err.message : "Unknown error"
|
|
@@ -591,9 +593,9 @@ function isNostrIdentityVerified(attestationId, npub, cachedEvents) {
|
|
|
591
593
|
}
|
|
592
594
|
|
|
593
595
|
// src/identity/twitter.ts
|
|
594
|
-
var
|
|
596
|
+
var log6 = createLogger("identity-verification/twitter");
|
|
595
597
|
async function verifyTwitterIdentity(attestationId, handle, tweetUrl) {
|
|
596
|
-
|
|
598
|
+
log6.info({ attestationId, handle, tweetUrl }, "Verifying Twitter identity");
|
|
597
599
|
if (!tweetUrl) {
|
|
598
600
|
return {
|
|
599
601
|
verified: false,
|
|
@@ -608,7 +610,7 @@ async function verifyTwitterIdentity(attestationId, handle, tweetUrl) {
|
|
|
608
610
|
error: "Invalid tweet URL format"
|
|
609
611
|
};
|
|
610
612
|
}
|
|
611
|
-
|
|
613
|
+
log6.info({ handle, tweetId }, "Manual verification required");
|
|
612
614
|
return {
|
|
613
615
|
verified: false,
|
|
614
616
|
tweetUrl,
|
|
@@ -616,7 +618,7 @@ async function verifyTwitterIdentity(attestationId, handle, tweetUrl) {
|
|
|
616
618
|
error: "Automatic verification not available. Please verify manually by checking the tweet."
|
|
617
619
|
};
|
|
618
620
|
} catch (err) {
|
|
619
|
-
|
|
621
|
+
log6.error({ error: err, handle }, "Failed to verify Twitter identity");
|
|
620
622
|
return {
|
|
621
623
|
verified: false,
|
|
622
624
|
error: err instanceof Error ? err.message : "Unknown error"
|