@orangecheck/sdk 1.16.2 → 1.17.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.
- package/README.md +1 -0
- package/dist/attestation.js +8 -9
- package/dist/attestation.js.map +1 -1
- package/dist/attestation.mjs +8 -9
- package/dist/attestation.mjs.map +1 -1
- package/dist/canonical.d.mts +2 -1
- package/dist/canonical.d.ts +2 -1
- package/dist/canonical.js +8 -2
- package/dist/canonical.js.map +1 -1
- package/dist/canonical.mjs +8 -3
- package/dist/canonical.mjs.map +1 -1
- package/dist/index.js +48 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48 -9
- package/dist/index.mjs.map +1 -1
- package/dist/nostr.js +7 -7
- package/dist/nostr.js.map +1 -1
- package/dist/nostr.mjs +7 -7
- package/dist/nostr.mjs.map +1 -1
- package/dist/verify.js +33 -7
- package/dist/verify.js.map +1 -1
- package/dist/verify.mjs +33 -7
- package/dist/verify.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -102,10 +102,15 @@ async function generateAttestationId(message) {
|
|
|
102
102
|
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
103
103
|
return toLowerHex(new Uint8Array(hashBuffer));
|
|
104
104
|
}
|
|
105
|
+
function readMessageValue(message, key) {
|
|
106
|
+
const needle = key + ":";
|
|
107
|
+
const hit = message.split("\n").map((l) => l.trim()).find((l) => l.toLowerCase().startsWith(needle));
|
|
108
|
+
if (!hit) return void 0;
|
|
109
|
+
return hit.slice(hit.indexOf(":") + 1).trim();
|
|
110
|
+
}
|
|
105
111
|
async function createAttestationEnvelope(message, signature, scheme, address, identities, extensions = {}) {
|
|
106
112
|
const attestation_id = await generateAttestationId(message);
|
|
107
|
-
const
|
|
108
|
-
const issued_at = issuedAtMatch?.[1] ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
113
|
+
const issued_at = readMessageValue(message, "issued_at") ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
109
114
|
const expires_at = extensions.expires;
|
|
110
115
|
const relay_hints = extensions.relay_hints?.split(",").map((r) => r.trim());
|
|
111
116
|
const publish_targets = extensions.publish?.split(",").map((t) => t.trim());
|
|
@@ -221,6 +226,44 @@ function rfc3339Ms(value) {
|
|
|
221
226
|
return Number.isNaN(ms) ? null : ms;
|
|
222
227
|
}
|
|
223
228
|
|
|
229
|
+
// src/options.ts
|
|
230
|
+
var CHECK_OPTIONS = /* @__PURE__ */ new Set([
|
|
231
|
+
"addr",
|
|
232
|
+
"id",
|
|
233
|
+
"identity",
|
|
234
|
+
"minSats",
|
|
235
|
+
"minDays",
|
|
236
|
+
"relays",
|
|
237
|
+
"verifyOptions"
|
|
238
|
+
]);
|
|
239
|
+
var VERIFY_OPTIONS = /* @__PURE__ */ new Set([
|
|
240
|
+
"testMode",
|
|
241
|
+
"demoMode",
|
|
242
|
+
"expectedAud",
|
|
243
|
+
"esploraMainnetBase",
|
|
244
|
+
"esploraSignetBase",
|
|
245
|
+
"esploraTestnetBase",
|
|
246
|
+
"coverSats"
|
|
247
|
+
]);
|
|
248
|
+
function refuseUnknown(where, opts, known) {
|
|
249
|
+
if (opts === null || typeof opts !== "object") {
|
|
250
|
+
throw new TypeError(`@orangecheck/sdk: ${where} must be an object`);
|
|
251
|
+
}
|
|
252
|
+
const unknown = Object.keys(opts).filter((k) => !known.has(k));
|
|
253
|
+
if (unknown.length > 0) {
|
|
254
|
+
throw new TypeError(
|
|
255
|
+
`@orangecheck/sdk: ${where}: unknown option ${unknown.join(", ")}. It reads only ${[...known].join(", ")}.`
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function checkCheckParams(params) {
|
|
260
|
+
refuseUnknown("check()", params, CHECK_OPTIONS);
|
|
261
|
+
if (params.verifyOptions !== void 0) checkVerifyOptions(params.verifyOptions, "verifyOptions");
|
|
262
|
+
}
|
|
263
|
+
function checkVerifyOptions(opts, where = "verify()") {
|
|
264
|
+
refuseUnknown(where, opts, VERIFY_OPTIONS);
|
|
265
|
+
}
|
|
266
|
+
|
|
224
267
|
// src/scoring.ts
|
|
225
268
|
function scoreV0(sats, days) {
|
|
226
269
|
if (sats <= 0 || days <= 0) return 0;
|
|
@@ -279,13 +322,7 @@ async function signatureIsValid(input) {
|
|
|
279
322
|
}
|
|
280
323
|
function parseCanonicalMessage(msg) {
|
|
281
324
|
const lines = msg.split("\n").map((l) => l.trim());
|
|
282
|
-
const getVal = (
|
|
283
|
-
const needle = prefix + ":";
|
|
284
|
-
const hit = lines.find((l) => l.toLowerCase().startsWith(needle));
|
|
285
|
-
if (!hit) return void 0;
|
|
286
|
-
const idx = hit.indexOf(":");
|
|
287
|
-
return hit.slice(idx + 1).trim();
|
|
288
|
-
};
|
|
325
|
+
const getVal = (key) => readMessageValue(msg, key);
|
|
289
326
|
const address = getVal("address") || "";
|
|
290
327
|
const identitiesStr = getVal("identities") || "";
|
|
291
328
|
const issued_at = getVal("issued_at") || "";
|
|
@@ -432,6 +469,7 @@ function computeMetrics(utxos, bondAmount, coverSats) {
|
|
|
432
469
|
return { sats_bonded, days_unspent, confirmed_balance };
|
|
433
470
|
}
|
|
434
471
|
async function verify(input, opts = {}) {
|
|
472
|
+
checkVerifyOptions(opts);
|
|
435
473
|
const codes = [];
|
|
436
474
|
let network = "mainnet";
|
|
437
475
|
try {
|
|
@@ -1110,6 +1148,7 @@ function extractAttestationIdFromUrl(url) {
|
|
|
1110
1148
|
|
|
1111
1149
|
// src/check.ts
|
|
1112
1150
|
async function check(params) {
|
|
1151
|
+
checkCheckParams(params);
|
|
1113
1152
|
const {
|
|
1114
1153
|
addr,
|
|
1115
1154
|
id,
|