@orangecheck/sdk 1.17.1 → 1.18.1

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.
Files changed (45) hide show
  1. package/dist/attestation.d.mts +1 -1
  2. package/dist/attestation.d.ts +1 -1
  3. package/dist/attestation.js +8 -2
  4. package/dist/attestation.js.map +1 -1
  5. package/dist/attestation.mjs +8 -2
  6. package/dist/attestation.mjs.map +1 -1
  7. package/dist/canonical.d.mts +3 -2
  8. package/dist/canonical.d.ts +3 -2
  9. package/dist/canonical.js +9 -0
  10. package/dist/canonical.js.map +1 -1
  11. package/dist/canonical.mjs +9 -1
  12. package/dist/canonical.mjs.map +1 -1
  13. package/dist/challenge.d.mts +1 -1
  14. package/dist/challenge.d.ts +1 -1
  15. package/dist/challenge.js +29 -0
  16. package/dist/challenge.js.map +1 -1
  17. package/dist/challenge.mjs +29 -0
  18. package/dist/challenge.mjs.map +1 -1
  19. package/dist/identity.d.mts +1 -1
  20. package/dist/identity.d.ts +1 -1
  21. package/dist/index.d.mts +3 -3
  22. package/dist/index.d.ts +3 -3
  23. package/dist/index.js +48 -2
  24. package/dist/index.js.map +1 -1
  25. package/dist/index.mjs +48 -3
  26. package/dist/index.mjs.map +1 -1
  27. package/dist/nostr.d.mts +1 -1
  28. package/dist/nostr.d.ts +1 -1
  29. package/dist/nostr.js +8 -2
  30. package/dist/nostr.js.map +1 -1
  31. package/dist/nostr.mjs +8 -2
  32. package/dist/nostr.mjs.map +1 -1
  33. package/dist/scoring.js +22 -0
  34. package/dist/scoring.js.map +1 -1
  35. package/dist/scoring.mjs +22 -0
  36. package/dist/scoring.mjs.map +1 -1
  37. package/dist/{types-DsrYs3EB.d.mts → types-BdJoNWgs.d.mts} +1 -1
  38. package/dist/{types-DsrYs3EB.d.ts → types-BdJoNWgs.d.ts} +1 -1
  39. package/dist/verify.d.mts +2 -1
  40. package/dist/verify.d.ts +2 -1
  41. package/dist/verify.js +27 -2
  42. package/dist/verify.js.map +1 -1
  43. package/dist/verify.mjs +27 -2
  44. package/dist/verify.mjs.map +1 -1
  45. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -68,6 +68,11 @@ function parseIdentities(identitiesStr) {
68
68
  }
69
69
  return bindings;
70
70
  }
71
+ function readBondExtension(value) {
72
+ if (!/^[0-9]+$/.test(value)) return null;
73
+ const n = Number(value);
74
+ return Number.isSafeInteger(n) ? n : null;
75
+ }
71
76
  function buildCanonicalMessage({ address, identities }, extensions = {}, options = {}) {
72
77
  const nonce = options.nonce ?? randomNonce16BHexLower();
73
78
  if (!/^[0-9a-f]{32}$/.test(nonce)) {
@@ -90,6 +95,9 @@ function buildCanonicalMessage({ address, identities }, extensions = {}, options
90
95
  continue;
91
96
  }
92
97
  const key = k.toLowerCase();
98
+ if (key === "bond" && readBondExtension(String(v)) === null) {
99
+ throw new Error(`invalid bond: ${String(v)} is not a whole number of sats up to 2^53 - 1`);
100
+ }
93
101
  normExt[key] = String(v);
94
102
  }
95
103
  const extLines = Object.keys(normExt).sort().map((k) => `${k}: ${normExt[k]}`);
@@ -255,6 +263,10 @@ function refuseUnknown(where, opts, known) {
255
263
  `@orangecheck/sdk: ${where}: unknown option ${unknown.join(", ")}. It reads only ${[...known].join(", ")}.`
256
264
  );
257
265
  }
266
+ const inherited = [...known].filter((k) => k in opts && !Object.prototype.hasOwnProperty.call(opts, k));
267
+ if (inherited.length > 0) {
268
+ throw new TypeError(`@orangecheck/sdk: ${where}: option ${inherited.join(", ")} is inherited, not set by the caller`);
269
+ }
258
270
  }
259
271
  function checkCheckParams(params) {
260
272
  refuseUnknown("check()", params, CHECK_OPTIONS);
@@ -263,6 +275,21 @@ function checkCheckParams(params) {
263
275
  function checkVerifyOptions(opts, where = "verify()") {
264
276
  refuseUnknown(where, opts, VERIFY_OPTIONS);
265
277
  }
278
+ var CHALLENGE_OPTIONS = /* @__PURE__ */ new Set([
279
+ "address",
280
+ "ttlSeconds",
281
+ "nonce",
282
+ "audience",
283
+ "purpose",
284
+ "now"
285
+ ]);
286
+ function checkChallengeOptions(opts) {
287
+ refuseUnknown("issueChallenge()", opts, CHALLENGE_OPTIONS);
288
+ }
289
+ var SCORING_OPTIONS = /* @__PURE__ */ new Set(["algorithm"]);
290
+ function checkScoringConfig(config) {
291
+ refuseUnknown("computeScore()", config, SCORING_OPTIONS);
292
+ }
266
293
 
267
294
  // src/scoring.ts
268
295
  function scoreV0(sats, days) {
@@ -277,6 +304,7 @@ function scoreTier(sats, days) {
277
304
  return "none";
278
305
  }
279
306
  function computeScore(sats, days, config) {
307
+ checkScoringConfig(config);
280
308
  switch (config.algorithm) {
281
309
  case "v0":
282
310
  return scoreV0(sats, days);
@@ -356,14 +384,15 @@ function parseCanonicalMessage(msg) {
356
384
  }
357
385
  const network = extensions["network"] || "mainnet";
358
386
  const bondStr = extensions["bond"];
359
- const bond = bondStr ? parseInt(bondStr, 10) : void 0;
387
+ const bond = bondStr ? readBondExtension(bondStr) : void 0;
360
388
  return {
361
389
  core: { address, identities, issued_at },
362
390
  expires,
363
391
  repeated,
364
392
  network,
365
393
  extensions,
366
- bond: bond !== void 0 && !isNaN(bond) && bond > 0 ? bond : void 0
394
+ bond: bond !== void 0 && bond !== null && bond > 0 ? bond : void 0,
395
+ bondMalformed: bond === null
367
396
  };
368
397
  }
369
398
  async function getAddressUtxos(address, network, opts) {
@@ -532,6 +561,16 @@ async function verify(input, opts = {}) {
532
561
  identities: parsed.core.identities
533
562
  };
534
563
  }
564
+ if (parsed.bondMalformed) {
565
+ codes.push("bond_malformed");
566
+ return {
567
+ ok: false,
568
+ codes,
569
+ network,
570
+ attestation_id,
571
+ identities: parsed.core.identities
572
+ };
573
+ }
535
574
  try {
536
575
  const utxos = await getAddressUtxos(input.addr, network, {
537
576
  esploraMainnetBase: opts.esploraMainnetBase,
@@ -1274,6 +1313,7 @@ function iso(date) {
1274
1313
  return date.toISOString().replace(/\.\d{3}Z$/, "Z");
1275
1314
  }
1276
1315
  function issueChallenge(opts) {
1316
+ checkChallengeOptions(opts);
1277
1317
  const now = opts.now ?? /* @__PURE__ */ new Date();
1278
1318
  const ttl = opts.ttlSeconds ?? 300;
1279
1319
  const expiresAt = new Date(now.getTime() + ttl * 1e3);
@@ -2316,6 +2356,11 @@ var STATUS_META = {
2316
2356
  detail: "The confirmed balance is less than the declared bond amount. The bond extension requires the address to hold at least the specified amount in confirmed UTXOs.",
2317
2357
  severity: "error"
2318
2358
  },
2359
+ bond_malformed: {
2360
+ label: "Bond amount not readable",
2361
+ detail: "The signed bond line is not a whole number of sats written in plain digits, so the attestation does not say how much it bonds.",
2362
+ severity: "error"
2363
+ },
2319
2364
  aud_mismatch: {
2320
2365
  label: "Audience mismatch",
2321
2366
  detail: "The message was signed for a different audience than expected. This may be intentional or indicate the signature is being used in the wrong context.",
@@ -2358,6 +2403,6 @@ var STATUS_META = {
2358
2403
  }
2359
2404
  };
2360
2405
 
2361
- export { BOND_DAYS_FLOORS, BOND_MAX_WINDOW_SECONDS, BOND_MIN_CONFIRMATIONS, BOND_SATS_FLOORS, DEFAULT_RELAYS, FANOUT_DEADLINE_MS, STATUS_META, bondFloors, bondId, bondNullifier, buildBondMessage, buildCanonicalMessage, check, checkBondCoin, computeAllScores, computeScore, createAttestation, createAttestationEnvelope, createAttestationEvent, discoverAttestations, esploraSource, 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, issueBondMessage, issueChallenge, nostrIdentifierForms, nostrPubkeyToHex, parseAttestationFromEvent, parseBondMessage, parseIdentities, publishAttestation, publishToRelays, queryByAddress, queryByAttestationId, queryByIdentity, queryRecent, requiresManualVerification, signNostrEvent, signatureIsValid, signedEnvelope, supportsAutomaticVerification, verify, verifyAllIdentities, verifyAttestationById, verifyBond, verifyBondSignature, verifyChallenge, verifyDnsIdentity, verifyGitHubIdentity, verifyIdentity, verifyNostrIdentity, verifyTwitterIdentity };
2406
+ export { BOND_DAYS_FLOORS, BOND_MAX_WINDOW_SECONDS, BOND_MIN_CONFIRMATIONS, BOND_SATS_FLOORS, DEFAULT_RELAYS, FANOUT_DEADLINE_MS, STATUS_META, bondFloors, bondId, bondNullifier, buildBondMessage, buildCanonicalMessage, check, checkBondCoin, computeAllScores, computeScore, createAttestation, createAttestationEnvelope, createAttestationEvent, discoverAttestations, esploraSource, 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, issueBondMessage, issueChallenge, nostrIdentifierForms, nostrPubkeyToHex, parseAttestationFromEvent, parseBondMessage, parseIdentities, publishAttestation, publishToRelays, queryByAddress, queryByAttestationId, queryByIdentity, queryRecent, readBondExtension, requiresManualVerification, signNostrEvent, signatureIsValid, signedEnvelope, supportsAutomaticVerification, verify, verifyAllIdentities, verifyAttestationById, verifyBond, verifyBondSignature, verifyChallenge, verifyDnsIdentity, verifyGitHubIdentity, verifyIdentity, verifyNostrIdentity, verifyTwitterIdentity };
2362
2407
  //# sourceMappingURL=index.mjs.map
2363
2408
  //# sourceMappingURL=index.mjs.map