@orangecheck/sdk 1.17.0 → 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/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 issuedAtMatch = message.match(/issued_at: ([^\n]+)/);
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());
@@ -317,13 +322,7 @@ async function signatureIsValid(input) {
317
322
  }
318
323
  function parseCanonicalMessage(msg) {
319
324
  const lines = msg.split("\n").map((l) => l.trim());
320
- const getVal = (prefix) => {
321
- const needle = prefix + ":";
322
- const hit = lines.find((l) => l.toLowerCase().startsWith(needle));
323
- if (!hit) return void 0;
324
- const idx = hit.indexOf(":");
325
- return hit.slice(idx + 1).trim();
326
- };
325
+ const getVal = (key) => readMessageValue(msg, key);
327
326
  const address = getVal("address") || "";
328
327
  const identitiesStr = getVal("identities") || "";
329
328
  const issued_at = getVal("issued_at") || "";