@orangecheck/sdk 0.1.2 → 0.1.3

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
@@ -1,8 +1,8 @@
1
1
  import { Buffer } from 'buffer';
2
2
  import { Verifier } from 'bip322-js';
3
3
  import * as bitcoinMessage from 'bitcoinjs-message';
4
- import { schnorr } from '@noble/curves/secp256k1';
5
- import { sha256 } from '@noble/hashes/sha2';
4
+ import { schnorr } from '@noble/curves/secp256k1.js';
5
+ import { sha256 } from '@noble/hashes/sha2.js';
6
6
  import { bech32 } from '@scure/base';
7
7
 
8
8
  // src/canonical.ts
@@ -233,16 +233,15 @@ async function publishToRelays(event, relays = DEFAULT_RELAYS) {
233
233
  ws = new WebSocket(relayUrl);
234
234
  const wsRef = ws;
235
235
  await new Promise((resolve, reject) => {
236
- const timeout = setTimeout(() => {
236
+ const deadline = setTimeout(() => {
237
237
  wsRef.close();
238
- reject(new Error("Connection timeout"));
239
- }, 5e3);
238
+ reject(new Error("Relay publish timeout"));
239
+ }, 1e4);
240
240
  const cleanup = () => {
241
- clearTimeout(timeout);
241
+ clearTimeout(deadline);
242
242
  wsRef.close();
243
243
  };
244
244
  wsRef.onopen = () => {
245
- clearTimeout(timeout);
246
245
  wsRef.send(JSON.stringify(["EVENT", event]));
247
246
  };
248
247
  wsRef.onmessage = (msg) => {
@@ -280,7 +279,7 @@ async function publishToRelays(event, relays = DEFAULT_RELAYS) {
280
279
  reject(err);
281
280
  };
282
281
  wsRef.onclose = () => {
283
- clearTimeout(timeout);
282
+ clearTimeout(deadline);
284
283
  };
285
284
  });
286
285
  } catch (err) {
@@ -658,6 +657,24 @@ async function getAttestationsForIdentity(protocol, identifier, relays = DEFAULT
658
657
  log3.info({ protocol, identifier }, "Getting all attestations for identity");
659
658
  return discoverAttestations({ identity: { protocol, identifier }, relays });
660
659
  }
660
+ function formatIdentitiesForDisplay(identities) {
661
+ return identities.map((id) => `${id.protocol}:${id.identifier}`).join(", ");
662
+ }
663
+ function getVerificationUrl(attestationId, baseUrl = "https://ochk.io") {
664
+ return `${baseUrl}/attest/${attestationId}`;
665
+ }
666
+ function extractAttestationIdFromUrl(url) {
667
+ try {
668
+ const u = new URL(url);
669
+ const m = u.pathname.match(/^\/attest\/([0-9a-f]{64})\/?$/i);
670
+ if (m) return m[1].toLowerCase();
671
+ const q = u.searchParams.get("id");
672
+ if (q && /^[0-9a-f]{64}$/i.test(q)) return q.toLowerCase();
673
+ return null;
674
+ } catch {
675
+ return null;
676
+ }
677
+ }
661
678
 
662
679
  // src/scoring.ts
663
680
  function scoreV0(sats, days) {
@@ -684,9 +701,6 @@ function computeScore(sats, days, config) {
684
701
 
685
702
  // src/verify.ts
686
703
  var log4 = createLogger("ocp/verify");
687
- function scoreV02(sats, days) {
688
- return computeScore(sats, days, { algorithm: "v0" });
689
- }
690
704
  function looksLikeHex(s) {
691
705
  return /^[0-9a-fA-F]+$/.test(s) && s.length % 2 === 0;
692
706
  }
@@ -950,7 +964,7 @@ async function verify2(input, opts = {}) {
950
964
  const metrics = {
951
965
  sats_bonded,
952
966
  days_unspent,
953
- score: scoreV02(sats_bonded, days_unspent)
967
+ score: computeScore(sats_bonded, days_unspent, { algorithm: "v0" })
954
968
  // ≈ 55.26
955
969
  };
956
970
  codes.push("sig_ok_bip322");
@@ -1046,7 +1060,7 @@ async function verify2(input, opts = {}) {
1046
1060
  const metrics = {
1047
1061
  sats_bonded,
1048
1062
  days_unspent,
1049
- score: scoreV02(sats_bonded, days_unspent)
1063
+ score: computeScore(sats_bonded, days_unspent, { algorithm: "v0" })
1050
1064
  };
1051
1065
  return {
1052
1066
  ok: true,
@@ -1184,16 +1198,20 @@ function parseChallenge(message) {
1184
1198
  throw new Error("not an orangecheck-auth challenge");
1185
1199
  }
1186
1200
  const out = { extensions: [] };
1187
- const coreKeys = /* @__PURE__ */ new Set(["address", "nonce", "issued_at", "expires_at", "ack"]);
1188
- let seenCore = 0;
1201
+ const coreKeys = ["address", "nonce", "issued_at", "expires_at", "ack"];
1202
+ const coreKeySet = new Set(coreKeys);
1203
+ const seenCore = /* @__PURE__ */ new Set();
1189
1204
  for (let i = 1; i < lines.length; i++) {
1190
1205
  const line = lines[i] ?? "";
1191
1206
  const sep = line.indexOf(": ");
1192
1207
  if (sep === -1) continue;
1193
1208
  const key = line.slice(0, sep);
1194
1209
  const val = line.slice(sep + 2);
1195
- if (coreKeys.has(key)) {
1196
- seenCore++;
1210
+ if (coreKeySet.has(key)) {
1211
+ if (seenCore.has(key)) {
1212
+ throw new Error(`duplicate core key in challenge: ${key}`);
1213
+ }
1214
+ seenCore.add(key);
1197
1215
  if (key === "address") out.address = val;
1198
1216
  else if (key === "nonce") out.nonce = val;
1199
1217
  else if (key === "issued_at") out.issuedAt = new Date(val);
@@ -1205,8 +1223,8 @@ function parseChallenge(message) {
1205
1223
  if (key === "purpose") out.purpose = val;
1206
1224
  }
1207
1225
  }
1208
- if (seenCore !== 5) {
1209
- throw new Error(`challenge missing core lines (${seenCore}/5)`);
1226
+ if (seenCore.size !== coreKeys.length) {
1227
+ throw new Error(`challenge missing core lines (${seenCore.size}/${coreKeys.length})`);
1210
1228
  }
1211
1229
  return out;
1212
1230
  }
@@ -2066,6 +2084,6 @@ var STATUS_META = {
2066
2084
  }
2067
2085
  };
2068
2086
 
2069
- export { DEFAULT_RELAYS, STATUS_META, buildCanonicalMessage, check, computeScore, createAttestation, createAttestationEnvelope, createAttestationEvent, discoverAttestations, formatIdentities, generateAttestationId, generateGistTemplate, generateTweetText, generateWellKnownContent, getAttestationsForAddress, getAttestationsForIdentity, getDnsVerificationInstructions, getGistCreationUrl, getGitHubVerificationInstructions, getManualVerificationInstructions, getNip07Info, getNostrPublicKey, getNostrVerificationInstructions, getTweetUrl, getTwitterComposeUrl, getTwitterVerificationInstructions, getVerificationInstructions, getVerificationSummary, getWellKnownUrl, isDnsIdentityVerified, isGitHubIdentityVerified, isNip07Available, isNostrIdentityVerified, isValidDomain, isValidTweetUrl, issueChallenge, parseAttestationFromEvent, parseIdentities, publishAttestation, publishToRelays, queryByAddress, queryByAttestationId, queryByIdentity, requiresManualVerification, signNostrEvent, supportsAutomaticVerification, verify2 as verify, verifyAllIdentities, verifyAttestationById, verifyChallenge, verifyDnsIdentity, verifyGitHubIdentity, verifyIdentity, verifyNostrIdentity, verifyTwitterIdentity };
2087
+ export { DEFAULT_RELAYS, STATUS_META, buildCanonicalMessage, check, 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, parseAttestationFromEvent, parseIdentities, publishAttestation, publishToRelays, queryByAddress, queryByAttestationId, queryByIdentity, requiresManualVerification, signNostrEvent, supportsAutomaticVerification, verify2 as verify, verifyAllIdentities, verifyAttestationById, verifyChallenge, verifyDnsIdentity, verifyGitHubIdentity, verifyIdentity, verifyNostrIdentity, verifyTwitterIdentity };
2070
2088
  //# sourceMappingURL=index.mjs.map
2071
2089
  //# sourceMappingURL=index.mjs.map