@orangecheck/sdk 1.18.0 → 1.18.2

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
@@ -263,6 +263,10 @@ function refuseUnknown(where, opts, known) {
263
263
  `@orangecheck/sdk: ${where}: unknown option ${unknown.join(", ")}. It reads only ${[...known].join(", ")}.`
264
264
  );
265
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
+ }
266
270
  }
267
271
  function checkCheckParams(params) {
268
272
  refuseUnknown("check()", params, CHECK_OPTIONS);
@@ -271,6 +275,21 @@ function checkCheckParams(params) {
271
275
  function checkVerifyOptions(opts, where = "verify()") {
272
276
  refuseUnknown(where, opts, VERIFY_OPTIONS);
273
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
+ }
274
293
 
275
294
  // src/scoring.ts
276
295
  function scoreV0(sats, days) {
@@ -285,6 +304,7 @@ function scoreTier(sats, days) {
285
304
  return "none";
286
305
  }
287
306
  function computeScore(sats, days, config) {
307
+ checkScoringConfig(config);
288
308
  switch (config.algorithm) {
289
309
  case "v0":
290
310
  return scoreV0(sats, days);
@@ -1293,6 +1313,7 @@ function iso(date) {
1293
1313
  return date.toISOString().replace(/\.\d{3}Z$/, "Z");
1294
1314
  }
1295
1315
  function issueChallenge(opts) {
1316
+ checkChallengeOptions(opts);
1296
1317
  const now = opts.now ?? /* @__PURE__ */ new Date();
1297
1318
  const ttl = opts.ttlSeconds ?? 300;
1298
1319
  const expiresAt = new Date(now.getTime() + ttl * 1e3);