@calimero-network/mero-js 23.0.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.cjs CHANGED
@@ -81,6 +81,10 @@ __export(index_exports, {
81
81
  completeDeviceEnrolment: () => completeDeviceEnrolment,
82
82
  connectCloud: () => connectCloud,
83
83
  connectCloudWithAccount: () => connectCloudWithAccount,
84
+ contextCapabilityGrantedOp: () => contextCapabilityGrantedOp,
85
+ contextCapabilityRevokedOp: () => contextCapabilityRevokedOp,
86
+ contextDetachedOp: () => contextDetachedOp,
87
+ contextMetadataSetOp: () => contextMetadataSetOp,
84
88
  createAccountRootSigner: () => createAccountRootSigner,
85
89
  createAdminApiClient: () => createAdminApiClient,
86
90
  createAdminApiClientFromHttpClient: () => createAdminApiClientFromHttpClient,
@@ -130,6 +134,7 @@ __export(index_exports, {
130
134
  groupDeleteOp: () => groupDeleteOp,
131
135
  groupDeletedOp: () => groupDeletedOp,
132
136
  groupInvitationHash: () => groupInvitationHash,
137
+ groupMetadataSetOp: () => groupMetadataSetOp,
133
138
  groupReparentedOp: () => groupReparentedOp,
134
139
  hasCap: () => hasCap,
135
140
  hexEncodeUtf8: () => hexEncodeUtf8,
@@ -139,7 +144,10 @@ __export(index_exports, {
139
144
  localNodeUrl: () => localNodeUrl,
140
145
  login: () => login,
141
146
  memberAddedOp: () => memberAddedOp,
147
+ memberCapabilitySetOp: () => memberCapabilitySetOp,
148
+ memberJoinedOpenOp: () => memberJoinedOpenOp,
142
149
  memberLeftOp: () => memberLeftOp,
150
+ memberMetadataSetOp: () => memberMetadataSetOp,
143
151
  memberRemovedOp: () => memberRemovedOp,
144
152
  memberRoleSetOp: () => memberRoleSetOp,
145
153
  mintDeviceId: () => mintDeviceId,
@@ -166,6 +174,7 @@ __export(index_exports, {
166
174
  shouldRetain: () => shouldRetain,
167
175
  signAccountLink: () => signAccountLink,
168
176
  signAccountLogin: () => signAccountLogin,
177
+ signAccountOwnershipClaim: () => signAccountOwnershipClaim,
169
178
  signCreationWarrant: () => signCreationWarrant,
170
179
  signDeviceCert: () => signDeviceCert,
171
180
  signDeviceScope: () => signDeviceScope,
@@ -182,6 +191,7 @@ __export(index_exports, {
182
191
  signerFromCryptoKey: () => signerFromCryptoKey,
183
192
  signerFromSecret: () => signerFromSecret,
184
193
  subgroupCreation: () => subgroupCreation,
194
+ subgroupVisibilitySetOp: () => subgroupVisibilitySetOp,
185
195
  teeAdmissionPolicyOp: () => teeAdmissionPolicyOp,
186
196
  teeAuthoringPolicyOp: () => teeAuthoringPolicyOp,
187
197
  teeReleaseAdmissionPolicyOp: () => teeReleaseAdmissionPolicyOp,
@@ -6473,6 +6483,19 @@ var CloudClient = class {
6473
6483
  { body }
6474
6484
  );
6475
6485
  }
6486
+ /**
6487
+ * Enable HA for a namespace this ACCOUNT founded through a relay, with the
6488
+ * founder's claim (`signAccountOwnershipClaim`) instead of a node's
6489
+ * ownership proof: a nodeless account holds no node that could issue one.
6490
+ * The login must be linked to that account.
6491
+ */
6492
+ async enableFoundedNamespaceHa(namespaceId, ownershipProof) {
6493
+ return this.request(
6494
+ "POST",
6495
+ `/api/cloud/me/namespaces/${encodeURIComponent(namespaceId)}/enable-ha`,
6496
+ { body: { groups: [], ownership_proof: ownershipProof } }
6497
+ );
6498
+ }
6476
6499
  /**
6477
6500
  * Stop hosting a claimed namespace.
6478
6501
  *
@@ -7589,12 +7612,21 @@ var GROUP_OP = {
7589
7612
  MemberRemoved: 2,
7590
7613
  MemberLeft: 3,
7591
7614
  MemberRoleSet: 4,
7592
- DefaultCapabilitiesSet: 6
7615
+ MemberCapabilitySet: 5,
7616
+ DefaultCapabilitiesSet: 6,
7617
+ ContextDetached: 9,
7618
+ SubgroupVisibilitySet: 10,
7619
+ GroupMetadataSet: 11,
7620
+ MemberMetadataSet: 12,
7621
+ ContextMetadataSet: 13,
7622
+ ContextCapabilityGranted: 16,
7623
+ ContextCapabilityRevoked: 17
7593
7624
  };
7594
7625
  var ROOT_OP = {
7595
7626
  GroupCreated: 0,
7596
7627
  GroupReparented: 1,
7597
7628
  GroupDeleted: 2,
7629
+ MemberJoinedOpen: 7,
7598
7630
  NamespaceCreatedV2: 9
7599
7631
  };
7600
7632
  var NAMESPACE_ID_DOMAIN = new TextEncoder().encode("calimero.namespace.id.v1");
@@ -7726,6 +7758,87 @@ function namespaceCreatedOp(input) {
7726
7758
  )
7727
7759
  };
7728
7760
  }
7761
+ function str(value) {
7762
+ const bytes = new TextEncoder().encode(value);
7763
+ return concat(u32le(bytes.length), bytes);
7764
+ }
7765
+ function optionalStr(value) {
7766
+ return value === void 0 ? tag(0) : concat(tag(1), str(value));
7767
+ }
7768
+ function stringMap(data = {}) {
7769
+ const enc = new TextEncoder();
7770
+ const entries = Object.entries(data).map(([k, v]) => [enc.encode(k), v, k]).sort(([a], [b]) => {
7771
+ for (let i = 0; i < Math.min(a.length, b.length); i++) if (a[i] !== b[i]) return a[i] - b[i];
7772
+ return a.length - b.length;
7773
+ });
7774
+ return concat(u32le(entries.length), ...entries.flatMap(([, v, k]) => [str(k), str(v)]));
7775
+ }
7776
+ function relayableMask(capabilities, what) {
7777
+ if (!Number.isInteger(capabilities) || capabilities < 0 || capabilities > 4294967295) {
7778
+ throw new Error(`${what} must be a u32 bit mask, got ${String(capabilities)}`);
7779
+ }
7780
+ if (hasCap(capabilities, CAPABILITIES.CAN_AUTHOR_ON_BEHALF)) {
7781
+ throw new Error(`${what} may not include CAN_AUTHOR_ON_BEHALF (512): a relay never carries a change to it`);
7782
+ }
7783
+ return capabilities;
7784
+ }
7785
+ function memberCapabilitySetOp(member, capabilities) {
7786
+ return {
7787
+ kind: "group",
7788
+ bytes: concat(tag(GROUP_OP.MemberCapabilitySet), fromHex(member, "member", 32), u32le(relayableMask(capabilities, "capabilities")))
7789
+ };
7790
+ }
7791
+ function contextDetachedOp(contextId) {
7792
+ return { kind: "group", bytes: concat(tag(GROUP_OP.ContextDetached), fromHex(contextId, "contextId", 32)) };
7793
+ }
7794
+ function subgroupVisibilitySetOp(mode) {
7795
+ if (mode !== "open" && mode !== "restricted") throw new Error(`mode must be open or restricted, got ${String(mode)}`);
7796
+ return { kind: "group", bytes: concat(tag(GROUP_OP.SubgroupVisibilitySet), tag(mode === "open" ? 0 : 1)) };
7797
+ }
7798
+ function groupMetadataSetOp(input = {}) {
7799
+ return { kind: "group", bytes: concat(tag(GROUP_OP.GroupMetadataSet), optionalStr(input.name), stringMap(input.data)) };
7800
+ }
7801
+ function memberMetadataSetOp(member, input = {}) {
7802
+ return {
7803
+ kind: "group",
7804
+ bytes: concat(tag(GROUP_OP.MemberMetadataSet), fromHex(member, "member", 32), optionalStr(input.name), stringMap(input.data))
7805
+ };
7806
+ }
7807
+ function contextMetadataSetOp(contextId, input = {}) {
7808
+ return {
7809
+ kind: "group",
7810
+ bytes: concat(tag(GROUP_OP.ContextMetadataSet), fromHex(contextId, "contextId", 32), optionalStr(input.name), stringMap(input.data))
7811
+ };
7812
+ }
7813
+ function contextCapability(capability) {
7814
+ if (!Number.isInteger(capability) || capability < 1 || capability > 255) {
7815
+ throw new Error(`capability must be a non-zero u8, got ${String(capability)}`);
7816
+ }
7817
+ return tag(capability);
7818
+ }
7819
+ function contextCapabilityGrantedOp(contextId, member, capability) {
7820
+ return {
7821
+ kind: "group",
7822
+ bytes: concat(tag(GROUP_OP.ContextCapabilityGranted), fromHex(contextId, "contextId", 32), fromHex(member, "member", 32), contextCapability(capability))
7823
+ };
7824
+ }
7825
+ function contextCapabilityRevokedOp(contextId, member, capability) {
7826
+ return {
7827
+ kind: "group",
7828
+ bytes: concat(tag(GROUP_OP.ContextCapabilityRevoked), fromHex(contextId, "contextId", 32), fromHex(member, "member", 32), contextCapability(capability))
7829
+ };
7830
+ }
7831
+ function memberJoinedOpenOp(input) {
7832
+ return {
7833
+ kind: "root",
7834
+ bytes: concat(
7835
+ tag(ROOT_OP.MemberJoinedOpen),
7836
+ fromHex(input.member, "member", 32),
7837
+ fromHex(input.groupId, "groupId", 32),
7838
+ fromHexUnsized(input.credential, "credential")
7839
+ )
7840
+ };
7841
+ }
7729
7842
 
7730
7843
  // src/relay/relay-client.ts
7731
7844
  var DEFAULT_TTL_SECONDS = 300;
@@ -9084,8 +9197,8 @@ async function hkdf2(chainingKey, inputKeyMaterial) {
9084
9197
  return [first, second];
9085
9198
  }
9086
9199
  function base64UrlDecode(value) {
9087
- const base643 = value.replace(/-/g, "+").replace(/_/g, "/");
9088
- const binary = atob(base643 + "=".repeat((4 - base643.length % 4) % 4));
9200
+ const base644 = value.replace(/-/g, "+").replace(/_/g, "/");
9201
+ const binary = atob(base644 + "=".repeat((4 - base644.length % 4) % 4));
9089
9202
  return Uint8Array.from(binary, (char) => char.charCodeAt(0));
9090
9203
  }
9091
9204
 
@@ -9741,6 +9854,43 @@ function assertSafeReturnTo(returnTo) {
9741
9854
  );
9742
9855
  }
9743
9856
 
9857
+ // src/cloud/account-ownership.ts
9858
+ var DOMAIN = new TextEncoder().encode("calimero.mdma.account-ownership-claim.v1\0");
9859
+ var DEFAULT_TTL_MS = 6e4;
9860
+ var MAX_TTL_MS = 5 * 6e4;
9861
+ function base643(bytes) {
9862
+ let binary = "";
9863
+ for (const b of bytes) binary += String.fromCharCode(b);
9864
+ return btoa(binary);
9865
+ }
9866
+ var hex32 = (value, what) => {
9867
+ if (!/^[0-9a-fA-F]{64}$/.test(value)) throw new Error(`${what} must be 64 hex characters`);
9868
+ return value.toLowerCase();
9869
+ };
9870
+ async function signAccountOwnershipClaim(input) {
9871
+ const ttl = input.ttlMs ?? DEFAULT_TTL_MS;
9872
+ if (!(ttl > 0 && ttl <= MAX_TTL_MS)) throw new Error(`ttlMs must be in (0, ${MAX_TTL_MS}]`);
9873
+ if (!input.subject) throw new Error("subject must be the cloud login email");
9874
+ const signer = await resolveSigner(input.deviceSecret, input.signer, "deviceSecret");
9875
+ const issued = (input.now ?? Date.now)();
9876
+ const nonce2 = Array.from(crypto.getRandomValues(new Uint8Array(16)), (b) => b.toString(16).padStart(2, "0")).join("");
9877
+ const payload = new TextEncoder().encode(
9878
+ JSON.stringify({
9879
+ v: 1,
9880
+ audience: "mdma:enable-ha-namespace",
9881
+ group_id: hex32(input.namespaceId, "namespaceId"),
9882
+ account_id: hex32(input.accountId, "accountId"),
9883
+ salt: hex32(input.salt, "salt"),
9884
+ subject: input.subject,
9885
+ nonce: nonce2,
9886
+ issued_at_ms: issued,
9887
+ expires_at_ms: issued + ttl
9888
+ })
9889
+ );
9890
+ const signature = await signer.sign(concat(DOMAIN, payload));
9891
+ return { kind: "account", credential: input.credential, signed_payload: base643(payload), signature: base643(signature) };
9892
+ }
9893
+
9744
9894
  // src/sealed/verify.ts
9745
9895
  var MEASUREMENT_HEX = /^[0-9a-f]{96}$/;
9746
9896
  var REGISTERS = ["mrtd", "rtmr0", "rtmr1", "rtmr2", "rtmr3"];