@calimero-network/mero-js 23.3.0 → 23.4.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
@@ -197,6 +197,7 @@ __export(index_exports, {
197
197
  subgroupCreation: () => subgroupCreation,
198
198
  subgroupVisibilitySetOp: () => subgroupVisibilitySetOp,
199
199
  subscribePresence: () => subscribePresence,
200
+ targetApplicationSetOp: () => targetApplicationSetOp,
200
201
  teeAdmissionPolicyOp: () => teeAdmissionPolicyOp,
201
202
  teeAuthoringPolicyOp: () => teeAuthoringPolicyOp,
202
203
  teeReleaseAdmissionPolicyOp: () => teeReleaseAdmissionPolicyOp,
@@ -7623,6 +7624,7 @@ var GROUP_OP = {
7623
7624
  MemberRoleSet: 4,
7624
7625
  MemberCapabilitySet: 5,
7625
7626
  DefaultCapabilitiesSet: 6,
7627
+ TargetApplicationSet: 7,
7626
7628
  ContextDetached: 9,
7627
7629
  SubgroupVisibilitySet: 10,
7628
7630
  GroupMetadataSet: 11,
@@ -7696,6 +7698,23 @@ async function createdSubgroupId(admin, parentId, restricted, salt) {
7696
7698
  ])
7697
7699
  );
7698
7700
  }
7701
+ function borshString2(value, what) {
7702
+ if (value.length === 0) throw new Error(`${what} must not be empty`);
7703
+ const bytes = new TextEncoder().encode(value);
7704
+ return concat(u32le(bytes.length), bytes);
7705
+ }
7706
+ function targetApplicationSetOp(input) {
7707
+ return {
7708
+ kind: "group",
7709
+ bytes: concat(
7710
+ tag(GROUP_OP.TargetApplicationSet),
7711
+ CLEARED_HASH,
7712
+ fromHex(input.applicationId, "applicationId", 32),
7713
+ borshString2(input.package, "package"),
7714
+ borshString2(input.version, "version")
7715
+ )
7716
+ };
7717
+ }
7699
7718
  function defaultCapabilitiesSetOp(capabilities) {
7700
7719
  if (!Number.isInteger(capabilities) || capabilities < 0 || capabilities > 4294967295) {
7701
7720
  throw new Error(`capabilities must be a u32 bit mask, got ${String(capabilities)}`);
@@ -8150,6 +8169,7 @@ var RelayClient = class {
8150
8169
  salt
8151
8170
  });
8152
8171
  const capabilitiesOp = input.defaultCapabilities === void 0 ? void 0 : defaultCapabilitiesSetOp(input.defaultCapabilities);
8172
+ const applicationOp = input.application ? targetApplicationSetOp(input.application) : void 0;
8153
8173
  const signer = await this.authorSigner();
8154
8174
  const nonce2 = await this.config.nonces.next();
8155
8175
  const ttl = this.config.ttlSeconds ?? DEFAULT_TTL_SECONDS;
@@ -8169,17 +8189,25 @@ var RelayClient = class {
8169
8189
  teeEnabled: data.teeEnabled ?? false,
8170
8190
  ...data.teeError ? { teeError: data.teeError } : {}
8171
8191
  };
8172
- if (!capabilitiesOp) return founded;
8173
- try {
8174
- await this.govern({ groupId: founded.namespaceId, op: capabilitiesOp });
8175
- return { ...founded, defaultCapabilitiesSet: true };
8176
- } catch (err) {
8177
- return {
8178
- ...founded,
8179
- defaultCapabilitiesSet: false,
8180
- defaultCapabilitiesError: err instanceof Error ? err.message : String(err)
8181
- };
8192
+ let result = founded;
8193
+ const message = (err) => err instanceof Error ? err.message : String(err);
8194
+ if (applicationOp) {
8195
+ try {
8196
+ await this.govern({ groupId: founded.namespaceId, op: applicationOp });
8197
+ result = { ...result, applicationSet: true };
8198
+ } catch (err) {
8199
+ result = { ...result, applicationSet: false, applicationError: message(err) };
8200
+ }
8201
+ }
8202
+ if (capabilitiesOp) {
8203
+ try {
8204
+ await this.govern({ groupId: founded.namespaceId, op: capabilitiesOp });
8205
+ result = { ...result, defaultCapabilitiesSet: true };
8206
+ } catch (err) {
8207
+ result = { ...result, defaultCapabilitiesSet: false, defaultCapabilitiesError: message(err) };
8208
+ }
8182
8209
  }
8210
+ return result;
8183
8211
  }
8184
8212
  async postGovernance(groupId, op, warrant) {
8185
8213
  const body = await this.json("POST", `/admin-api/groups/${encodeURIComponent(groupId)}/governance-intents`, {
@@ -10829,7 +10857,7 @@ function optionalBytes32(value, label2) {
10829
10857
  }
10830
10858
  return concat(new Uint8Array([1]), new Uint8Array(value));
10831
10859
  }
10832
- function borshString2(value) {
10860
+ function borshString3(value) {
10833
10861
  const bytes = new TextEncoder().encode(value);
10834
10862
  return concat(u32le(bytes.length), bytes);
10835
10863
  }
@@ -10843,7 +10871,7 @@ function encodeSignedInvitation(signed) {
10843
10871
  // ...then the enclosing SignedGroupOpenInvitation, in declaration order.
10844
10872
  // `inviter_account` sits between the signature and the addresses; putting it
10845
10873
  // anywhere else still encodes 32 bytes and still verifies as nothing.
10846
- borshString2(signed.inviter_signature),
10874
+ borshString3(signed.inviter_signature),
10847
10875
  signed.inviter_account ? concat(new Uint8Array([1]), fromHex(signed.inviter_account, "inviter_account", 32)) : new Uint8Array([0]),
10848
10876
  // A `Vec<String>`, so each entry is a bare borsh string. This carried an
10849
10877
  // enum until core dropped the URL variant, and an enum writes a
@@ -10851,7 +10879,7 @@ function encodeSignedInvitation(signed) {
10851
10879
  // every following byte and fail as `invalid invitation signature`, pointing
10852
10880
  // nowhere near this line.
10853
10881
  u32le(admitterAddrs.length),
10854
- ...admitterAddrs.map(borshString2),
10882
+ ...admitterAddrs.map(borshString3),
10855
10883
  optionalBytes32(signed.application_id, "application_id"),
10856
10884
  // Borsh order follows core's field order, where this is `bytecode_id`; the
10857
10885
  // JSON key is `app_key`, a rename covering both directions that core pins in
@@ -10924,12 +10952,12 @@ var te = new TextEncoder();
10924
10952
  function tag2(byte) {
10925
10953
  return new Uint8Array([byte]);
10926
10954
  }
10927
- function borshString3(value) {
10955
+ function borshString4(value) {
10928
10956
  const bytes = te.encode(value);
10929
10957
  return concat(u32le(bytes.length), bytes);
10930
10958
  }
10931
10959
  function borshStrings(values) {
10932
- return concat(u32le(values.length), ...values.map(borshString3));
10960
+ return concat(u32le(values.length), ...values.map(borshString4));
10933
10961
  }
10934
10962
  function borshBool(value) {
10935
10963
  return tag2(value ? 1 : 0);
@@ -10983,7 +11011,7 @@ function teeAdmissionPolicyOp(input) {
10983
11011
  };
10984
11012
  }
10985
11013
  function teeReleaseAdmissionPolicyOp(input) {
10986
- const minRelease = input.minReleaseVersion === void 0 ? tag2(0) : concat(tag2(1), borshString3(input.minReleaseVersion));
11014
+ const minRelease = input.minReleaseVersion === void 0 ? tag2(0) : concat(tag2(1), borshString4(input.minReleaseVersion));
10987
11015
  return {
10988
11016
  kind: "teeReleaseAdmissionPolicy",
10989
11017
  plane: "group",