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