@orangecheck/sdk 1.7.0 → 1.9.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/index.mjs CHANGED
@@ -527,6 +527,70 @@ async function queryByIdentity(protocol, identifier, relays = DEFAULT_RELAYS) {
527
527
  log.info({ eventCount: events.length }, "Query complete");
528
528
  return events;
529
529
  }
530
+ async function queryRecent(relays = DEFAULT_RELAYS, limit = 200) {
531
+ const events = [];
532
+ log.info({ relayCount: relays.length, limit }, "Querying relays for recent attestations");
533
+ const deadlineAt = Date.now() + FANOUT_DEADLINE_MS;
534
+ const queryPromises = relays.map(async (relayUrl) => {
535
+ try {
536
+ const ws = new WebSocket(relayUrl);
537
+ await new Promise((resolve, reject) => {
538
+ const timeout = setTimeout(() => {
539
+ ws.close();
540
+ reject(new Error("Query timeout"));
541
+ }, budgetFor(deadlineAt));
542
+ ws.onopen = () => {
543
+ const subscriptionId = `ochk_recent_${Date.now()}`;
544
+ ws.send(
545
+ JSON.stringify([
546
+ "REQ",
547
+ subscriptionId,
548
+ { kinds: [ATTESTATION_EVENT_KIND], "#t": ["oc-attest"], limit }
549
+ ])
550
+ );
551
+ };
552
+ ws.onmessage = (msg) => {
553
+ try {
554
+ const data = JSON.parse(msg.data);
555
+ if (data[0] === "EVENT") {
556
+ const ev = data[2];
557
+ const scheme = ev.tags?.find((t) => t[0] === "scheme")?.[1];
558
+ const dTag = ev.tags?.find((t) => t[0] === "d")?.[1];
559
+ if ((scheme === "bip322" || scheme === "legacy") && dTag) {
560
+ events.push(ev);
561
+ }
562
+ } else if (data[0] === "EOSE") {
563
+ clearTimeout(timeout);
564
+ ws.close();
565
+ resolve();
566
+ }
567
+ } catch (err) {
568
+ log.error({ relay: relayUrl, error: err }, "Failed to parse event");
569
+ }
570
+ };
571
+ ws.onerror = (err) => {
572
+ clearTimeout(timeout);
573
+ log.error({ relay: relayUrl, error: err }, "WebSocket error during query");
574
+ reject(err);
575
+ };
576
+ });
577
+ } catch (err) {
578
+ log.error({ relay: relayUrl, error: err }, "Failed to query relay");
579
+ }
580
+ });
581
+ await Promise.allSettled(queryPromises);
582
+ const seen = /* @__PURE__ */ new Set();
583
+ const envelopes = [];
584
+ for (const ev of events) {
585
+ const envelope = parseAttestationFromEvent(ev);
586
+ if (!envelope || seen.has(envelope.attestation_id)) continue;
587
+ if (!await verifyAttestationEnvelope(envelope)) continue;
588
+ seen.add(envelope.attestation_id);
589
+ envelopes.push(envelope);
590
+ }
591
+ log.info({ eventCount: events.length, unique: envelopes.length }, "Recent query complete");
592
+ return envelopes;
593
+ }
530
594
  async function verifyAttestationEnvelope(envelope) {
531
595
  try {
532
596
  const encoder = new TextEncoder();
@@ -798,10 +862,6 @@ async function verifySignature({
798
862
  scheme
799
863
  }) {
800
864
  try {
801
- if (sig === "demo_signature") {
802
- log4.warn("Demo signature detected in verifySignature - should be handled by demo mode");
803
- return "sig_invalid";
804
- }
805
865
  const detectedScheme = scheme || detectSignatureScheme(addr, sig);
806
866
  log4.debug(
807
867
  { addr, msgLength: msg.length, sigLength: sig.length, scheme: detectedScheme },
@@ -1027,26 +1087,6 @@ async function verify2(input, opts = {}) {
1027
1087
  codes.push("bad_request");
1028
1088
  return { ok: false, codes, network, attestation_id };
1029
1089
  }
1030
- if (opts.demoMode) {
1031
- const sats_bonded = 1e6;
1032
- const days_unspent = 90;
1033
- const metrics = {
1034
- sats_bonded,
1035
- days_unspent,
1036
- score: computeScore(sats_bonded, days_unspent, { algorithm: "v0" })
1037
- // ≈ 55.26
1038
- };
1039
- codes.push("sig_ok_bip322");
1040
- codes.push("bond_confirmed");
1041
- return {
1042
- ok: true,
1043
- codes,
1044
- network,
1045
- attestation_id,
1046
- identities: parsed.core.identities,
1047
- metrics
1048
- };
1049
- }
1050
1090
  if ((network === "testnet" || network === "signet") && !opts.testMode) {
1051
1091
  codes.push("network_testmode");
1052
1092
  return { ok: false, codes, network, attestation_id };
@@ -2133,12 +2173,12 @@ var STATUS_META = {
2133
2173
  },
2134
2174
  bond_zero: {
2135
2175
  label: "No confirmed bitcoin found",
2136
- detail: "This address has no confirmed UTXOs. Send some bitcoin to this address and wait for confirmation to establish a reputation score.",
2176
+ detail: "This address has no confirmed UTXOs. Send some bitcoin to this address and wait for confirmation to establish a stake.",
2137
2177
  severity: "warn"
2138
2178
  },
2139
2179
  bond_pending: {
2140
2180
  label: "Pending transactions detected",
2141
- detail: "This address has unconfirmed transactions. Wait for confirmations before they count toward your reputation score.",
2181
+ detail: "This address has unconfirmed transactions. Wait for confirmations before they count toward your stake.",
2142
2182
  severity: "info"
2143
2183
  },
2144
2184
  bond_insufficient: {
@@ -2183,6 +2223,6 @@ var STATUS_META = {
2183
2223
  }
2184
2224
  };
2185
2225
 
2186
- export { DEFAULT_RELAYS, FANOUT_DEADLINE_MS, STATUS_META, buildCanonicalMessage, check, computeAllScores, computeScore, createAttestation, createAttestationEnvelope, createAttestationEvent, discoverAttestations, extractAttestationIdFromUrl, formatIdentities, formatIdentitiesForDisplay, generateAttestationId, generateGistTemplate, generateTweetText, generateWellKnownContent, getAttestationsForAddress, getAttestationsForIdentity, getDnsVerificationInstructions, getGistCreationUrl, getGitHubVerificationInstructions, getManualVerificationInstructions, getNip07Info, getNostrPublicKey, getNostrVerificationInstructions, getTweetUrl, getTwitterComposeUrl, getTwitterVerificationInstructions, getVerificationInstructions, getVerificationSummary, getVerificationUrl, getWellKnownUrl, isDnsIdentityVerified, isGitHubIdentityVerified, isNip07Available, isNostrIdentityVerified, isValidDomain, isValidTweetUrl, issueChallenge, nostrIdentifierForms, nostrPubkeyToHex, parseAttestationFromEvent, parseIdentities, publishAttestation, publishToRelays, queryByAddress, queryByAttestationId, queryByIdentity, requiresManualVerification, signNostrEvent, supportsAutomaticVerification, verify2 as verify, verifyAllIdentities, verifyAttestationById, verifyChallenge, verifyDnsIdentity, verifyGitHubIdentity, verifyIdentity, verifyNostrIdentity, verifyTwitterIdentity };
2226
+ export { DEFAULT_RELAYS, FANOUT_DEADLINE_MS, STATUS_META, buildCanonicalMessage, check, computeAllScores, computeScore, createAttestation, createAttestationEnvelope, createAttestationEvent, discoverAttestations, extractAttestationIdFromUrl, formatIdentities, formatIdentitiesForDisplay, generateAttestationId, generateGistTemplate, generateTweetText, generateWellKnownContent, getAttestationsForAddress, getAttestationsForIdentity, getDnsVerificationInstructions, getGistCreationUrl, getGitHubVerificationInstructions, getManualVerificationInstructions, getNip07Info, getNostrPublicKey, getNostrVerificationInstructions, getTweetUrl, getTwitterComposeUrl, getTwitterVerificationInstructions, getVerificationInstructions, getVerificationSummary, getVerificationUrl, getWellKnownUrl, isDnsIdentityVerified, isGitHubIdentityVerified, isNip07Available, isNostrIdentityVerified, isValidDomain, isValidTweetUrl, issueChallenge, nostrIdentifierForms, nostrPubkeyToHex, parseAttestationFromEvent, parseIdentities, publishAttestation, publishToRelays, queryByAddress, queryByAttestationId, queryByIdentity, queryRecent, requiresManualVerification, signNostrEvent, supportsAutomaticVerification, verify2 as verify, verifyAllIdentities, verifyAttestationById, verifyChallenge, verifyDnsIdentity, verifyGitHubIdentity, verifyIdentity, verifyNostrIdentity, verifyTwitterIdentity };
2187
2227
  //# sourceMappingURL=index.mjs.map
2188
2228
  //# sourceMappingURL=index.mjs.map