@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/attestation.js.map +1 -1
- package/dist/attestation.mjs.map +1 -1
- package/dist/identity.js.map +1 -1
- package/dist/identity.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +67 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -27
- package/dist/index.mjs.map +1 -1
- package/dist/nostr.d.mts +2 -1
- package/dist/nostr.d.ts +2 -1
- package/dist/nostr.js +65 -0
- package/dist/nostr.js.map +1 -1
- package/dist/nostr.mjs +65 -1
- package/dist/nostr.mjs.map +1 -1
- package/dist/verify.js +0 -24
- package/dist/verify.js.map +1 -1
- package/dist/verify.mjs +0 -24
- package/dist/verify.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -549,6 +549,70 @@ async function queryByIdentity(protocol, identifier, relays = DEFAULT_RELAYS) {
|
|
|
549
549
|
log.info({ eventCount: events.length }, "Query complete");
|
|
550
550
|
return events;
|
|
551
551
|
}
|
|
552
|
+
async function queryRecent(relays = DEFAULT_RELAYS, limit = 200) {
|
|
553
|
+
const events = [];
|
|
554
|
+
log.info({ relayCount: relays.length, limit }, "Querying relays for recent attestations");
|
|
555
|
+
const deadlineAt = Date.now() + FANOUT_DEADLINE_MS;
|
|
556
|
+
const queryPromises = relays.map(async (relayUrl) => {
|
|
557
|
+
try {
|
|
558
|
+
const ws = new WebSocket(relayUrl);
|
|
559
|
+
await new Promise((resolve, reject) => {
|
|
560
|
+
const timeout = setTimeout(() => {
|
|
561
|
+
ws.close();
|
|
562
|
+
reject(new Error("Query timeout"));
|
|
563
|
+
}, budgetFor(deadlineAt));
|
|
564
|
+
ws.onopen = () => {
|
|
565
|
+
const subscriptionId = `ochk_recent_${Date.now()}`;
|
|
566
|
+
ws.send(
|
|
567
|
+
JSON.stringify([
|
|
568
|
+
"REQ",
|
|
569
|
+
subscriptionId,
|
|
570
|
+
{ kinds: [ATTESTATION_EVENT_KIND], "#t": ["oc-attest"], limit }
|
|
571
|
+
])
|
|
572
|
+
);
|
|
573
|
+
};
|
|
574
|
+
ws.onmessage = (msg) => {
|
|
575
|
+
try {
|
|
576
|
+
const data = JSON.parse(msg.data);
|
|
577
|
+
if (data[0] === "EVENT") {
|
|
578
|
+
const ev = data[2];
|
|
579
|
+
const scheme = ev.tags?.find((t) => t[0] === "scheme")?.[1];
|
|
580
|
+
const dTag = ev.tags?.find((t) => t[0] === "d")?.[1];
|
|
581
|
+
if ((scheme === "bip322" || scheme === "legacy") && dTag) {
|
|
582
|
+
events.push(ev);
|
|
583
|
+
}
|
|
584
|
+
} else if (data[0] === "EOSE") {
|
|
585
|
+
clearTimeout(timeout);
|
|
586
|
+
ws.close();
|
|
587
|
+
resolve();
|
|
588
|
+
}
|
|
589
|
+
} catch (err) {
|
|
590
|
+
log.error({ relay: relayUrl, error: err }, "Failed to parse event");
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
ws.onerror = (err) => {
|
|
594
|
+
clearTimeout(timeout);
|
|
595
|
+
log.error({ relay: relayUrl, error: err }, "WebSocket error during query");
|
|
596
|
+
reject(err);
|
|
597
|
+
};
|
|
598
|
+
});
|
|
599
|
+
} catch (err) {
|
|
600
|
+
log.error({ relay: relayUrl, error: err }, "Failed to query relay");
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
await Promise.allSettled(queryPromises);
|
|
604
|
+
const seen = /* @__PURE__ */ new Set();
|
|
605
|
+
const envelopes = [];
|
|
606
|
+
for (const ev of events) {
|
|
607
|
+
const envelope = parseAttestationFromEvent(ev);
|
|
608
|
+
if (!envelope || seen.has(envelope.attestation_id)) continue;
|
|
609
|
+
if (!await verifyAttestationEnvelope(envelope)) continue;
|
|
610
|
+
seen.add(envelope.attestation_id);
|
|
611
|
+
envelopes.push(envelope);
|
|
612
|
+
}
|
|
613
|
+
log.info({ eventCount: events.length, unique: envelopes.length }, "Recent query complete");
|
|
614
|
+
return envelopes;
|
|
615
|
+
}
|
|
552
616
|
async function verifyAttestationEnvelope(envelope) {
|
|
553
617
|
try {
|
|
554
618
|
const encoder = new TextEncoder();
|
|
@@ -820,10 +884,6 @@ async function verifySignature({
|
|
|
820
884
|
scheme
|
|
821
885
|
}) {
|
|
822
886
|
try {
|
|
823
|
-
if (sig === "demo_signature") {
|
|
824
|
-
log4.warn("Demo signature detected in verifySignature - should be handled by demo mode");
|
|
825
|
-
return "sig_invalid";
|
|
826
|
-
}
|
|
827
887
|
const detectedScheme = scheme || detectSignatureScheme(addr, sig);
|
|
828
888
|
log4.debug(
|
|
829
889
|
{ addr, msgLength: msg.length, sigLength: sig.length, scheme: detectedScheme },
|
|
@@ -1049,26 +1109,6 @@ async function verify2(input, opts = {}) {
|
|
|
1049
1109
|
codes.push("bad_request");
|
|
1050
1110
|
return { ok: false, codes, network, attestation_id };
|
|
1051
1111
|
}
|
|
1052
|
-
if (opts.demoMode) {
|
|
1053
|
-
const sats_bonded = 1e6;
|
|
1054
|
-
const days_unspent = 90;
|
|
1055
|
-
const metrics = {
|
|
1056
|
-
sats_bonded,
|
|
1057
|
-
days_unspent,
|
|
1058
|
-
score: computeScore(sats_bonded, days_unspent, { algorithm: "v0" })
|
|
1059
|
-
// ≈ 55.26
|
|
1060
|
-
};
|
|
1061
|
-
codes.push("sig_ok_bip322");
|
|
1062
|
-
codes.push("bond_confirmed");
|
|
1063
|
-
return {
|
|
1064
|
-
ok: true,
|
|
1065
|
-
codes,
|
|
1066
|
-
network,
|
|
1067
|
-
attestation_id,
|
|
1068
|
-
identities: parsed.core.identities,
|
|
1069
|
-
metrics
|
|
1070
|
-
};
|
|
1071
|
-
}
|
|
1072
1112
|
if ((network === "testnet" || network === "signet") && !opts.testMode) {
|
|
1073
1113
|
codes.push("network_testmode");
|
|
1074
1114
|
return { ok: false, codes, network, attestation_id };
|
|
@@ -2155,12 +2195,12 @@ var STATUS_META = {
|
|
|
2155
2195
|
},
|
|
2156
2196
|
bond_zero: {
|
|
2157
2197
|
label: "No confirmed bitcoin found",
|
|
2158
|
-
detail: "This address has no confirmed UTXOs. Send some bitcoin to this address and wait for confirmation to establish a
|
|
2198
|
+
detail: "This address has no confirmed UTXOs. Send some bitcoin to this address and wait for confirmation to establish a stake.",
|
|
2159
2199
|
severity: "warn"
|
|
2160
2200
|
},
|
|
2161
2201
|
bond_pending: {
|
|
2162
2202
|
label: "Pending transactions detected",
|
|
2163
|
-
detail: "This address has unconfirmed transactions. Wait for confirmations before they count toward your
|
|
2203
|
+
detail: "This address has unconfirmed transactions. Wait for confirmations before they count toward your stake.",
|
|
2164
2204
|
severity: "info"
|
|
2165
2205
|
},
|
|
2166
2206
|
bond_insufficient: {
|
|
@@ -2255,6 +2295,7 @@ exports.publishToRelays = publishToRelays;
|
|
|
2255
2295
|
exports.queryByAddress = queryByAddress;
|
|
2256
2296
|
exports.queryByAttestationId = queryByAttestationId;
|
|
2257
2297
|
exports.queryByIdentity = queryByIdentity;
|
|
2298
|
+
exports.queryRecent = queryRecent;
|
|
2258
2299
|
exports.requiresManualVerification = requiresManualVerification;
|
|
2259
2300
|
exports.signNostrEvent = signNostrEvent;
|
|
2260
2301
|
exports.supportsAutomaticVerification = supportsAutomaticVerification;
|