@calimero-network/mero-js 23.1.0 → 23.2.0

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
@@ -6274,6 +6274,19 @@ var CloudClient = class {
6274
6274
  { body }
6275
6275
  );
6276
6276
  }
6277
+ /**
6278
+ * Enable HA for a namespace this ACCOUNT founded through a relay, with the
6279
+ * founder's claim (`signAccountOwnershipClaim`) instead of a node's
6280
+ * ownership proof: a nodeless account holds no node that could issue one.
6281
+ * The login must be linked to that account.
6282
+ */
6283
+ async enableFoundedNamespaceHa(namespaceId, ownershipProof) {
6284
+ return this.request(
6285
+ "POST",
6286
+ `/api/cloud/me/namespaces/${encodeURIComponent(namespaceId)}/enable-ha`,
6287
+ { body: { groups: [], ownership_proof: ownershipProof } }
6288
+ );
6289
+ }
6277
6290
  /**
6278
6291
  * Stop hosting a claimed namespace.
6279
6292
  *
@@ -8975,8 +8988,8 @@ async function hkdf2(chainingKey, inputKeyMaterial) {
8975
8988
  return [first, second];
8976
8989
  }
8977
8990
  function base64UrlDecode(value) {
8978
- const base643 = value.replace(/-/g, "+").replace(/_/g, "/");
8979
- const binary = atob(base643 + "=".repeat((4 - base643.length % 4) % 4));
8991
+ const base644 = value.replace(/-/g, "+").replace(/_/g, "/");
8992
+ const binary = atob(base644 + "=".repeat((4 - base644.length % 4) % 4));
8980
8993
  return Uint8Array.from(binary, (char) => char.charCodeAt(0));
8981
8994
  }
8982
8995
 
@@ -9632,6 +9645,43 @@ function assertSafeReturnTo(returnTo) {
9632
9645
  );
9633
9646
  }
9634
9647
 
9648
+ // src/cloud/account-ownership.ts
9649
+ var DOMAIN = new TextEncoder().encode("calimero.mdma.account-ownership-claim.v1\0");
9650
+ var DEFAULT_TTL_MS = 6e4;
9651
+ var MAX_TTL_MS = 5 * 6e4;
9652
+ function base643(bytes) {
9653
+ let binary = "";
9654
+ for (const b of bytes) binary += String.fromCharCode(b);
9655
+ return btoa(binary);
9656
+ }
9657
+ var hex32 = (value, what) => {
9658
+ if (!/^[0-9a-fA-F]{64}$/.test(value)) throw new Error(`${what} must be 64 hex characters`);
9659
+ return value.toLowerCase();
9660
+ };
9661
+ async function signAccountOwnershipClaim(input) {
9662
+ const ttl = input.ttlMs ?? DEFAULT_TTL_MS;
9663
+ if (!(ttl > 0 && ttl <= MAX_TTL_MS)) throw new Error(`ttlMs must be in (0, ${MAX_TTL_MS}]`);
9664
+ if (!input.subject) throw new Error("subject must be the cloud login email");
9665
+ const signer = await resolveSigner(input.deviceSecret, input.signer, "deviceSecret");
9666
+ const issued = (input.now ?? Date.now)();
9667
+ const nonce2 = Array.from(crypto.getRandomValues(new Uint8Array(16)), (b) => b.toString(16).padStart(2, "0")).join("");
9668
+ const payload = new TextEncoder().encode(
9669
+ JSON.stringify({
9670
+ v: 1,
9671
+ audience: "mdma:enable-ha-namespace",
9672
+ group_id: hex32(input.namespaceId, "namespaceId"),
9673
+ account_id: hex32(input.accountId, "accountId"),
9674
+ salt: hex32(input.salt, "salt"),
9675
+ subject: input.subject,
9676
+ nonce: nonce2,
9677
+ issued_at_ms: issued,
9678
+ expires_at_ms: issued + ttl
9679
+ })
9680
+ );
9681
+ const signature = await signer.sign(concat(DOMAIN, payload));
9682
+ return { kind: "account", credential: input.credential, signed_payload: base643(payload), signature: base643(signature) };
9683
+ }
9684
+
9635
9685
  // src/sealed/verify.ts
9636
9686
  var MEASUREMENT_HEX = /^[0-9a-f]{96}$/;
9637
9687
  var REGISTERS = ["mrtd", "rtmr0", "rtmr1", "rtmr2", "rtmr3"];
@@ -10984,6 +11034,7 @@ export {
10984
11034
  shouldRetain,
10985
11035
  signAccountLink,
10986
11036
  signAccountLogin,
11037
+ signAccountOwnershipClaim,
10987
11038
  signCreationWarrant,
10988
11039
  signDeviceCert,
10989
11040
  signDeviceScope,