@calimero-network/mero-js 16.0.0 → 17.0.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.
@@ -15,7 +15,7 @@
15
15
  */
16
16
  import type { SignedGroupOpenInvitation } from '../admin-api/admin-types.js';
17
17
  /** Core's `SIGNED_NAMESPACE_OP_SCHEMA_VERSION`. A node refuses any other value. */
18
- export declare const SIGNED_NAMESPACE_OP_SCHEMA_VERSION = 7;
18
+ export declare const SIGNED_NAMESPACE_OP_SCHEMA_VERSION = 8;
19
19
  /**
20
20
  * Borsh-encode a `SignedGroupOpenInvitation`.
21
21
  *
@@ -1,6 +1,6 @@
1
1
  import { concat, derivePublicKey, fromHex, hex, importSigningKey, u32le, u64le, } from '../crypto/internal.js';
2
2
  /** Core's `SIGNED_NAMESPACE_OP_SCHEMA_VERSION`. A node refuses any other value. */
3
- export const SIGNED_NAMESPACE_OP_SCHEMA_VERSION = 7;
3
+ export const SIGNED_NAMESPACE_OP_SCHEMA_VERSION = 8;
4
4
  /** Domain prefixed to the signable bytes; core's `NAMESPACE_GOVERNANCE_SIGN_DOMAIN`. */
5
5
  const NAMESPACE_SIGN_DOMAIN = new TextEncoder().encode('calimero.namespace.v1');
6
6
  /** `NamespaceOp::Root` is the first variant. */
@@ -51,12 +51,6 @@ function borshString(value) {
51
51
  const bytes = new TextEncoder().encode(value);
52
52
  return concat(u32le(bytes.length), bytes);
53
53
  }
54
- function encodeAdmitterHint(hint) {
55
- if ('multiaddr' in hint) {
56
- return concat(new Uint8Array([0]), borshString(hint.multiaddr));
57
- }
58
- return concat(new Uint8Array([1]), borshString(hint.url));
59
- }
60
54
  /**
61
55
  * Borsh-encode a `SignedGroupOpenInvitation`.
62
56
  *
@@ -70,7 +64,7 @@ function encodeAdmitterHint(hint) {
70
64
  export function encodeSignedInvitation(signed) {
71
65
  const body = signed.invitation;
72
66
  const admitters = body.admitters ?? [];
73
- const hints = signed.admitter_hints ?? [];
67
+ const admitterAddrs = signed.admitter_addrs ?? [];
74
68
  return concat(
75
69
  // GroupInvitationFromAdmin.
76
70
  //
@@ -79,11 +73,17 @@ export function encodeSignedInvitation(signed) {
79
73
  // wrong way yields 32 bytes that encode cleanly and verify as nothing.
80
74
  bytes32(body.inviter_identity, 'inviter_identity'), bytes32(body.group_id, 'group_id'), u64le(body.expiration_timestamp), bytes32(body.secret_salt, 'secret_salt'), new Uint8Array([body.invited_role]), u32le(admitters.length), ...admitters.map((a, i) => fromHex(a, `admitters[${i}]`, 32)),
81
75
  // ...then the enclosing SignedGroupOpenInvitation, in declaration order.
82
- // `inviter_account` sits between the signature and the hints; putting it
76
+ // `inviter_account` sits between the signature and the addresses; putting it
83
77
  // anywhere else still encodes 32 bytes and still verifies as nothing.
84
78
  borshString(signed.inviter_signature), signed.inviter_account
85
79
  ? concat(new Uint8Array([1]), fromHex(signed.inviter_account, 'inviter_account', 32))
86
- : new Uint8Array([0]), u32le(hints.length), ...hints.map(encodeAdmitterHint), optionalBytes32(signed.application_id, 'application_id'),
80
+ : new Uint8Array([0]),
81
+ // A `Vec<String>`, so each entry is a bare borsh string. This carried an
82
+ // enum until core dropped the URL variant, and an enum writes a
83
+ // discriminant byte ahead of each entry — encoding one here now would shift
84
+ // every following byte and fail as `invalid invitation signature`, pointing
85
+ // nowhere near this line.
86
+ u32le(admitterAddrs.length), ...admitterAddrs.map(borshString), optionalBytes32(signed.application_id, 'application_id'),
87
87
  // Borsh order follows core's field order, where this is `bytecode_id`; the
88
88
  // JSON key is `app_key`, a rename covering both directions that core pins in
89
89
  // a test. Encoding by the Rust name would read `undefined` and emit a None
@@ -112,7 +112,19 @@ export async function signMemberJoinOp(input) {
112
112
  const signer = await derivePublicKey(input.deviceSecret);
113
113
  const signable = concat(new Uint8Array([SIGNED_NAMESPACE_OP_SCHEMA_VERSION]), fromHex(input.namespaceId, 'namespaceId', 32), u32le(parents.length), ...parents.map((p, i) => fromHex(p, `parentOpHashes[${i}]`, 32)), signer, u64le(input.nonce), op);
114
114
  const signature = new Uint8Array(await crypto.subtle.sign('Ed25519', key, concat(NAMESPACE_SIGN_DOMAIN, signable)));
115
- // The signed struct repeats the signable fields, then the signature. The domain
116
- // is a signing prefix only and is never part of the encoded op.
117
- return hex(concat(signable, signature));
115
+ // The signed struct repeats the signable fields, then the signature, then the
116
+ // admitter endorsement. The domain is a signing prefix only and is never part
117
+ // of the encoded op.
118
+ //
119
+ // The endorsement is written as borsh `None` — a single `0x00` — and that is
120
+ // the correct value from here, not a placeholder. It authorises the membership
121
+ // and can only be signed by an account the invitation named as an admitter,
122
+ // which a keyholder is not. The admitter attaches its own as it relays the op
123
+ // through `admitJoin`.
124
+ //
125
+ // It sits outside `signable`, so it is outside this signature and outside the
126
+ // op's id. That is what makes attaching it possible: the admitter changes
127
+ // neither what was signed here nor which op this is.
128
+ const unendorsed = new Uint8Array([0]);
129
+ return hex(concat(signable, signature, unendorsed));
118
130
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calimero-network/mero-js",
3
- "version": "16.0.0",
3
+ "version": "17.0.0",
4
4
  "description": "Pure JavaScript SDK for Calimero",
5
5
  "type": "module",
6
6
  "exports": {