@canonmsg/agent-sdk 12.5.1 → 12.6.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.
Files changed (34) hide show
  1. package/README.md +34 -3
  2. package/dist/chunks/{chunk-TFSURFF6.js → chunk-5J4YPLNW.js} +349 -1684
  3. package/dist/chunks/{chunk-3KFVBOVI.js → chunk-DAJ7L7TN.js} +751 -371
  4. package/dist/chunks/chunk-FVYKLH6I.js +1475 -0
  5. package/dist/chunks/chunk-HH7KR22P.js +406 -0
  6. package/dist/chunks/chunk-QK37HAHC.js +118 -0
  7. package/dist/chunks/{chunk-C2WJT3VX.js → chunk-S7BV74DN.js} +719 -813
  8. package/dist/chunks/{mls-crypto-Y44BOSEM.js → mls-crypto-4DZT2UFH.js} +2 -1
  9. package/dist/cli.js +67 -25
  10. package/dist/drivers/acp.d.ts +56 -0
  11. package/dist/drivers/codex.d.ts +1 -2
  12. package/dist/drivers/subprocess.d.ts +35 -0
  13. package/dist/index.d.ts +3 -1
  14. package/dist/index.js +12 -3
  15. package/dist/internal/backend-contracts/endpointContentPolicy.d.ts +2 -2
  16. package/dist/internal/backend-contracts/index.d.ts +1 -0
  17. package/dist/internal/backend-contracts/loggedOutSessions.d.ts +7 -0
  18. package/dist/internal/backend-contracts/mlsDevCredential.d.ts +3 -0
  19. package/dist/internal/endpoint/engine.d.ts +3 -0
  20. package/dist/internal/endpoint/mls-dev-client.d.ts +2 -0
  21. package/dist/internal/endpoint/mls-dev-text.d.ts +3 -0
  22. package/dist/internal/endpoint/node-mls-custody-protocol.d.ts +5 -0
  23. package/dist/internal/endpoint/node.d.ts +1 -0
  24. package/dist/media.js +4 -2
  25. package/dist/mls/darwin-arm64/canon-mls-custody +0 -0
  26. package/dist/mls/linux-arm64/canon-mls-custody +0 -0
  27. package/dist/mls/linux-x64/canon-mls-custody +0 -0
  28. package/dist/mls/wasm/canon_mls_wasm.js +363 -0
  29. package/dist/mls/wasm/canon_mls_wasm_bg.wasm +0 -0
  30. package/dist/mls-wasm-host.js +258 -0
  31. package/dist/runner/mls-bundled.d.ts +15 -2
  32. package/dist/runner/mls-managed.d.ts +6 -3
  33. package/dist/runner/types.d.ts +6 -1
  34. package/package.json +1 -1
@@ -1,32 +1,6 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
- // ../endpoint/src/mls-crypto.ts
5
- import { ed25519 } from "@noble/curves/ed25519.js";
6
-
7
- // ../backend-contracts/src/environment.ts
8
- var CANON_ENVIRONMENT_CONTRACTS = Object.freeze({
9
- "canon-dev-v1": Object.freeze({
10
- name: "dev",
11
- projectId: "canonmail-dev",
12
- region: "europe-west1"
13
- }),
14
- "canon-prod-v1": Object.freeze({
15
- name: "prod",
16
- projectId: "canonmail-prod",
17
- region: "europe-west1"
18
- })
19
- });
20
- function getCanonEnvironmentContract(value) {
21
- const environmentId = value.trim();
22
- const contract = CANON_ENVIRONMENT_CONTRACTS[environmentId];
23
- if (!contract) {
24
- throw new Error(`Unsupported Canon environment ID: ${value}`);
25
- }
26
- return Object.freeze({ environmentId, ...contract });
27
- }
28
- __name(getCanonEnvironmentContract, "getCanonEnvironmentContract");
29
-
30
4
  // ../backend-contracts/src/clientFloor.ts
31
5
  var CANON_CLIENT_HEADER = "X-Canon-Client";
32
6
  var CLIENT_UPDATE_REQUIRED = "CLIENT_UPDATE_REQUIRED";
@@ -76,6 +50,29 @@ var MEDIA_ORIGINS = {
76
50
  "canonmail-prod.firebasestorage.app": "https://api.canonmail.com"
77
51
  };
78
52
 
53
+ // ../backend-contracts/src/environment.ts
54
+ var CANON_ENVIRONMENT_CONTRACTS = Object.freeze({
55
+ "canon-dev-v1": Object.freeze({
56
+ name: "dev",
57
+ projectId: "canonmail-dev",
58
+ region: "europe-west1"
59
+ }),
60
+ "canon-prod-v1": Object.freeze({
61
+ name: "prod",
62
+ projectId: "canonmail-prod",
63
+ region: "europe-west1"
64
+ })
65
+ });
66
+ function getCanonEnvironmentContract(value) {
67
+ const environmentId = value.trim();
68
+ const contract = CANON_ENVIRONMENT_CONTRACTS[environmentId];
69
+ if (!contract) {
70
+ throw new Error(`Unsupported Canon environment ID: ${value}`);
71
+ }
72
+ return Object.freeze({ environmentId, ...contract });
73
+ }
74
+ __name(getCanonEnvironmentContract, "getCanonEnvironmentContract");
75
+
79
76
  // ../backend-contracts/src/media-url.ts
80
77
  function validMediaPath(path) {
81
78
  const parts = path.split("/");
@@ -123,131 +120,50 @@ function isCanonUploadUrl(url, input) {
123
120
  }
124
121
  __name(isCanonUploadUrl, "isCanonUploadUrl");
125
122
 
126
- // ../backend-contracts/src/upload-mime-types.ts
127
- var MIME_TYPE_RE = /^[a-z0-9.+-]+\/[a-z0-9.+-]+$/i;
128
- var SAFE_IMAGE_MIME_TYPES = /* @__PURE__ */ new Set([
129
- "image/jpeg",
130
- "image/png",
131
- "image/webp",
132
- "image/gif"
133
- ]);
134
- var SAFE_AUDIO_MIME_TYPES = /* @__PURE__ */ new Set([
135
- "audio/mp4",
136
- "audio/x-m4a",
137
- "audio/mpeg",
138
- "audio/webm",
139
- "audio/ogg",
140
- "audio/wav",
141
- // ADTS AAC — the future Android streamable-memo lane; harmless standalone.
142
- "audio/aac"
143
- ]);
144
- var SAFE_VIDEO_MIME_TYPES = /* @__PURE__ */ new Set([
145
- "video/mp4",
146
- "video/quicktime",
147
- "video/webm",
148
- "video/x-m4v"
149
- ]);
150
- var SAFE_FILE_MIME_TYPES = /* @__PURE__ */ new Set([
151
- "application/pdf",
152
- "text/plain",
153
- "text/markdown",
154
- "text/x-markdown",
155
- "text/csv",
156
- "application/csv",
157
- "application/json",
158
- "application/zip",
159
- "application/vnd.ms-excel",
160
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
161
- ]);
162
- var SAFE_FILE_MIME_BY_EXTENSION = {
163
- csv: "text/csv",
164
- json: "application/json",
165
- md: "text/markdown",
166
- markdown: "text/markdown",
167
- pdf: "application/pdf",
168
- txt: "text/plain",
169
- xls: "application/vnd.ms-excel",
170
- xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
171
- zip: "application/zip"
172
- };
173
- var SAFE_VIDEO_MIME_BY_EXTENSION = {
174
- m4v: "video/x-m4v",
175
- mov: "video/quicktime",
176
- mp4: "video/mp4",
177
- webm: "video/webm"
178
- };
179
- var SAFE_AUDIO_MIME_BY_EXTENSION = {
180
- aac: "audio/aac",
181
- m4a: "audio/x-m4a",
182
- mp3: "audio/mpeg",
183
- oga: "audio/ogg",
184
- ogg: "audio/ogg",
185
- wav: "audio/wav"
186
- };
187
- function normalizeMimeType(value) {
188
- if (typeof value !== "string") return null;
189
- const normalized = value.split(";")[0].trim().toLowerCase();
190
- if (!MIME_TYPE_RE.test(normalized)) return null;
191
- if (normalized === "image/jpg") return "image/jpeg";
192
- return normalized;
193
- }
194
- __name(normalizeMimeType, "normalizeMimeType");
195
- function inferSafeFileMimeTypeFromName(value) {
196
- if (typeof value !== "string") return null;
197
- const extension = value.trim().split(/[\\/]/).pop()?.split(".").pop()?.toLowerCase() ?? "";
198
- return SAFE_FILE_MIME_BY_EXTENSION[extension] ?? null;
123
+ // ../backend-contracts/src/mlsEnvironment.ts
124
+ var MLS_ENVIRONMENT_PROFILES = Object.freeze({
125
+ "canon-dev-v1": Object.freeze({
126
+ issuer: "canon-mls-dev-v1",
127
+ credentialType: "canon-mls-dev-credential+jws",
128
+ issuerKeyPath: "projects/canonmail-dev/locations/europe-west1/keyRings/canon-mls/cryptoKeys/device-issuer",
129
+ receiptKeyPath: "projects/canonmail-dev/locations/europe-west1/keyRings/canon-mls/cryptoKeys/feed-receipt"
130
+ }),
131
+ "canon-prod-v1": Object.freeze({
132
+ issuer: "canon-mls-prod-v1",
133
+ credentialType: "canon-mls-prod-credential+jws",
134
+ issuerKeyPath: "projects/canonmail-prod/locations/europe-west1/keyRings/canon-mls/cryptoKeys/device-issuer",
135
+ receiptKeyPath: "projects/canonmail-prod/locations/europe-west1/keyRings/canon-mls/cryptoKeys/feed-receipt"
136
+ })
137
+ });
138
+ function requireMlsEnvironmentId(value) {
139
+ if (!isMlsEnvironmentId(value)) throw new Error("INVALID_MLS_DATA");
140
+ return value;
199
141
  }
200
- __name(inferSafeFileMimeTypeFromName, "inferSafeFileMimeTypeFromName");
201
- function inferSafeVideoMimeTypeFromName(value) {
202
- if (typeof value !== "string") return null;
203
- const extension = value.trim().split(/[\\/]/).pop()?.split(".").pop()?.toLowerCase() ?? "";
204
- return SAFE_VIDEO_MIME_BY_EXTENSION[extension] ?? null;
142
+ __name(requireMlsEnvironmentId, "requireMlsEnvironmentId");
143
+ function isMlsEnvironmentId(value) {
144
+ return typeof value === "string" && Object.hasOwn(MLS_ENVIRONMENT_PROFILES, value);
205
145
  }
206
- __name(inferSafeVideoMimeTypeFromName, "inferSafeVideoMimeTypeFromName");
207
- function inferSafeAudioMimeTypeFromName(value) {
208
- if (typeof value !== "string") return null;
209
- const extension = value.trim().split(/[\\/]/).pop()?.split(".").pop()?.toLowerCase() ?? "";
210
- return SAFE_AUDIO_MIME_BY_EXTENSION[extension] ?? null;
146
+ __name(isMlsEnvironmentId, "isMlsEnvironmentId");
147
+ function mlsEnvironmentProfile(environmentId) {
148
+ return MLS_ENVIRONMENT_PROFILES[environmentId];
211
149
  }
212
- __name(inferSafeAudioMimeTypeFromName, "inferSafeAudioMimeTypeFromName");
213
- function shouldTrustSafeFileName(mimeType) {
214
- return !mimeType || mimeType === "application/octet-stream" || mimeType === "application/vnd.ms-excel" || mimeType === "text/plain";
150
+ __name(mlsEnvironmentProfile, "mlsEnvironmentProfile");
151
+ function mlsEnvironmentOfIssuerKeyVersion(value) {
152
+ return environmentOfKeyVersion(value, "issuerKeyPath");
215
153
  }
216
- __name(shouldTrustSafeFileName, "shouldTrustSafeFileName");
217
- function classifyAllowedUploadMimeType(value) {
218
- const mimeType = normalizeMimeType(value);
219
- if (!mimeType) return null;
220
- if (SAFE_IMAGE_MIME_TYPES.has(mimeType)) return "image";
221
- if (SAFE_AUDIO_MIME_TYPES.has(mimeType)) return "audio";
222
- if (SAFE_VIDEO_MIME_TYPES.has(mimeType)) return "video";
223
- if (SAFE_FILE_MIME_TYPES.has(mimeType)) return "file";
224
- return null;
154
+ __name(mlsEnvironmentOfIssuerKeyVersion, "mlsEnvironmentOfIssuerKeyVersion");
155
+ function mlsEnvironmentOfReceiptKeyVersion(value) {
156
+ return environmentOfKeyVersion(value, "receiptKeyPath");
225
157
  }
226
- __name(classifyAllowedUploadMimeType, "classifyAllowedUploadMimeType");
227
- function resolveAllowedUploadMimeType(input) {
228
- const normalizedMimeType = normalizeMimeType(input.mimeType);
229
- const hasExplicitMimeType = typeof input.mimeType === "string" && input.mimeType.trim().length > 0;
230
- const inferredVideoMimeType = inferSafeVideoMimeTypeFromName(input.fileName);
231
- const inferredAudioMimeType = inferSafeAudioMimeTypeFromName(input.fileName);
232
- const inferredFileMimeType = inferSafeFileMimeTypeFromName(input.fileName);
233
- if (hasExplicitMimeType && !normalizedMimeType) {
234
- return null;
235
- }
236
- if (inferredVideoMimeType && (!normalizedMimeType || normalizedMimeType === "application/octet-stream")) {
237
- return inferredVideoMimeType;
238
- }
239
- if (inferredAudioMimeType && (!normalizedMimeType || normalizedMimeType === "application/octet-stream")) {
240
- return inferredAudioMimeType;
241
- }
242
- if (inferredFileMimeType && shouldTrustSafeFileName(normalizedMimeType)) {
243
- return inferredFileMimeType;
244
- }
245
- if (normalizedMimeType && classifyAllowedUploadMimeType(normalizedMimeType)) {
246
- return normalizedMimeType;
158
+ __name(mlsEnvironmentOfReceiptKeyVersion, "mlsEnvironmentOfReceiptKeyVersion");
159
+ function environmentOfKeyVersion(value, key) {
160
+ for (const [environmentId, profile] of Object.entries(MLS_ENVIRONMENT_PROFILES)) {
161
+ const prefix = profile[key] + "/cryptoKeyVersions/";
162
+ if (value.startsWith(prefix) && /^[1-9][0-9]{0,9}$/.test(value.slice(prefix.length))) return environmentId;
247
163
  }
248
- return normalizedMimeType ? null : inferredFileMimeType;
164
+ return void 0;
249
165
  }
250
- __name(resolveAllowedUploadMimeType, "resolveAllowedUploadMimeType");
166
+ __name(environmentOfKeyVersion, "environmentOfKeyVersion");
251
167
 
252
168
  // ../backend-contracts/src/mlsDevValidation.ts
253
169
  function invalid() {
@@ -288,51 +204,6 @@ function requireMlsUuid(value) {
288
204
  }
289
205
  __name(requireMlsUuid, "requireMlsUuid");
290
206
 
291
- // ../backend-contracts/src/mlsEnvironment.ts
292
- var MLS_ENVIRONMENT_PROFILES = Object.freeze({
293
- "canon-dev-v1": Object.freeze({
294
- issuer: "canon-mls-dev-v1",
295
- credentialType: "canon-mls-dev-credential+jws",
296
- issuerKeyPath: "projects/canonmail-dev/locations/europe-west1/keyRings/canon-mls/cryptoKeys/device-issuer",
297
- receiptKeyPath: "projects/canonmail-dev/locations/europe-west1/keyRings/canon-mls/cryptoKeys/feed-receipt"
298
- }),
299
- "canon-prod-v1": Object.freeze({
300
- issuer: "canon-mls-prod-v1",
301
- credentialType: "canon-mls-prod-credential+jws",
302
- issuerKeyPath: "projects/canonmail-prod/locations/europe-west1/keyRings/canon-mls/cryptoKeys/device-issuer",
303
- receiptKeyPath: "projects/canonmail-prod/locations/europe-west1/keyRings/canon-mls/cryptoKeys/feed-receipt"
304
- })
305
- });
306
- function requireMlsEnvironmentId(value) {
307
- if (!isMlsEnvironmentId(value)) throw new Error("INVALID_MLS_DATA");
308
- return value;
309
- }
310
- __name(requireMlsEnvironmentId, "requireMlsEnvironmentId");
311
- function isMlsEnvironmentId(value) {
312
- return typeof value === "string" && Object.hasOwn(MLS_ENVIRONMENT_PROFILES, value);
313
- }
314
- __name(isMlsEnvironmentId, "isMlsEnvironmentId");
315
- function mlsEnvironmentProfile(environmentId) {
316
- return MLS_ENVIRONMENT_PROFILES[environmentId];
317
- }
318
- __name(mlsEnvironmentProfile, "mlsEnvironmentProfile");
319
- function mlsEnvironmentOfIssuerKeyVersion(value) {
320
- return environmentOfKeyVersion(value, "issuerKeyPath");
321
- }
322
- __name(mlsEnvironmentOfIssuerKeyVersion, "mlsEnvironmentOfIssuerKeyVersion");
323
- function mlsEnvironmentOfReceiptKeyVersion(value) {
324
- return environmentOfKeyVersion(value, "receiptKeyPath");
325
- }
326
- __name(mlsEnvironmentOfReceiptKeyVersion, "mlsEnvironmentOfReceiptKeyVersion");
327
- function environmentOfKeyVersion(value, key) {
328
- for (const [environmentId, profile] of Object.entries(MLS_ENVIRONMENT_PROFILES)) {
329
- const prefix = profile[key] + "/cryptoKeyVersions/";
330
- if (value.startsWith(prefix) && /^[1-9][0-9]{0,9}$/.test(value.slice(prefix.length))) return environmentId;
331
- }
332
- return void 0;
333
- }
334
- __name(environmentOfKeyVersion, "environmentOfKeyVersion");
335
-
336
207
  // ../backend-contracts/src/mlsDevEnrollment.ts
337
208
  var MLS_DEV_ENROLLMENT_CHALLENGE_TTL_MS = 3e5;
338
209
  var MLS_DEV_ENROLLMENT_MAX_BYTES = 4096;
@@ -540,6 +411,7 @@ __name(decodeCanonicalMlsBase64Url, "decodeCanonicalMlsBase64Url");
540
411
 
541
412
  // ../backend-contracts/src/mlsDevCredential.ts
542
413
  var MLS_DEV_CREDENTIAL_TTL_MS = 864e5;
414
+ var MLS_DEV_CREDENTIAL_LONG_TTL_MS = 14 * MLS_DEV_CREDENTIAL_TTL_MS;
543
415
  var MLS_DEV_CREDENTIAL_CHALLENGE_TTL_MS = 3e5;
544
416
  var MLS_DEV_CREDENTIAL_MAX_BYTES = 8192;
545
417
  var MlsDevCredentialValidationError = class extends Error {
@@ -591,8 +463,9 @@ function parseMlsDevCredentialClaims(value) {
591
463
  const input = readMlsDataRecord(value, ["version", "credentialId", "issuer", "device", "generation", "issuedAtMs", "expiresAtMs"]);
592
464
  const issuedAtMs = requireMlsInteger(input.issuedAtMs);
593
465
  const expiresAtMs = requireMlsInteger(input.expiresAtMs);
594
- if (expiresAtMs - issuedAtMs !== MLS_DEV_CREDENTIAL_TTL_MS) invalid3();
595
466
  const device = parseMlsDevEnrollmentResult({ version: 1, authorization: "registration_only", device: input.device }).device;
467
+ const lifetimeMs = expiresAtMs - issuedAtMs;
468
+ if (lifetimeMs !== MLS_DEV_CREDENTIAL_TTL_MS && (lifetimeMs !== MLS_DEV_CREDENTIAL_LONG_TTL_MS || device.principal.type !== "human")) invalid3();
596
469
  return bounded2({
597
470
  version: requireMlsLiteral(input.version, 1),
598
471
  credentialId: requireMlsUuid(input.credentialId),
@@ -723,19 +596,21 @@ function parseMlsDevCredentialReceipt(value) {
723
596
  }
724
597
  __name(parseMlsDevCredentialReceipt, "parseMlsDevCredentialReceipt");
725
598
 
726
- // ../backend-contracts/src/mlsDevFeedReceipt.ts
727
- var MlsDevFeedReceiptValidationError = class extends Error {
599
+ // ../backend-contracts/src/mlsDevGroupFeed.ts
600
+ var MLS_DEV_GROUP_FEED_MAX_ENTRIES = 4;
601
+ var MLS_DEV_GROUP_FEED_MAX_BYTES = 4 * 1024 * 1024;
602
+ var MlsDevGroupFeedValidationError = class extends Error {
728
603
  static {
729
- __name(this, "MlsDevFeedReceiptValidationError");
604
+ __name(this, "MlsDevGroupFeedValidationError");
730
605
  }
731
- code = "INVALID_MLS_DEV_FEED_RECEIPT";
606
+ code = "INVALID_MLS_DEV_GROUP_FEED";
732
607
  constructor() {
733
- super("INVALID_MLS_DEV_FEED_RECEIPT");
734
- this.name = "MlsDevFeedReceiptValidationError";
608
+ super("INVALID_MLS_DEV_GROUP_FEED");
609
+ this.name = "MlsDevGroupFeedValidationError";
735
610
  }
736
611
  };
737
612
  function invalid4() {
738
- throw new MlsDevFeedReceiptValidationError();
613
+ throw new MlsDevGroupFeedValidationError();
739
614
  }
740
615
  __name(invalid4, "invalid");
741
616
  function boundary3(read) {
@@ -746,139 +621,89 @@ function boundary3(read) {
746
621
  }
747
622
  }
748
623
  __name(boundary3, "boundary");
749
- function parseMlsDevReceiptKeyVersion(value, environmentId) {
750
- return boundary3(() => {
751
- if (typeof value !== "string" || value.length > 200) invalid4();
752
- const owner = mlsEnvironmentOfReceiptKeyVersion(value);
753
- if (!owner || environmentId !== void 0 && owner !== environmentId) invalid4();
754
- return value;
755
- });
756
- }
757
- __name(parseMlsDevReceiptKeyVersion, "parseMlsDevReceiptKeyVersion");
758
- function parseMlsDevFeedReceiptProof(value) {
759
- return boundary3(() => {
760
- const input = readMlsDataRecord(value, ["keyVersion", "signature"]);
761
- decodeCanonicalMlsBase64Url(input.signature, 64);
762
- return Object.freeze({ keyVersion: parseMlsDevReceiptKeyVersion(input.keyVersion), signature: input.signature });
763
- });
764
- }
765
- __name(parseMlsDevFeedReceiptProof, "parseMlsDevFeedReceiptProof");
766
- var MLS_DEV_GROUP_RECEIPT_CLOCK_SKEW = "MLS_DEV_GROUP_RECEIPT_CLOCK_SKEW";
767
- function isMlsDevReceiptClockSkew(value) {
768
- if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
769
- const keys2 = Object.keys(value).sort().join(), input = value;
770
- return (keys2 === "error,ok,retryable" || keys2 === "error,ok,retryable,version" && input.version === 1) && input.ok === false && input.error === MLS_DEV_GROUP_RECEIPT_CLOCK_SKEW && input.retryable === true;
771
- }
772
- __name(isMlsDevReceiptClockSkew, "isMlsDevReceiptClockSkew");
773
-
774
- // ../backend-contracts/src/mlsDevGroupFeed.ts
775
- var MLS_DEV_GROUP_FEED_MAX_ENTRIES = 4;
776
- var MLS_DEV_GROUP_FEED_MAX_BYTES = 4 * 1024 * 1024;
777
- var MlsDevGroupFeedValidationError = class extends Error {
778
- static {
779
- __name(this, "MlsDevGroupFeedValidationError");
780
- }
781
- code = "INVALID_MLS_DEV_GROUP_FEED";
782
- constructor() {
783
- super("INVALID_MLS_DEV_GROUP_FEED");
784
- this.name = "MlsDevGroupFeedValidationError";
785
- }
786
- };
787
- function invalid5() {
788
- throw new MlsDevGroupFeedValidationError();
789
- }
790
- __name(invalid5, "invalid");
791
- function boundary4(read) {
792
- try {
793
- return read();
794
- } catch {
795
- return invalid5();
796
- }
797
- }
798
- __name(boundary4, "boundary");
799
624
  function id(value) {
800
625
  if (typeof value !== "string" || !/^[A-Za-z0-9_.:~-]{1,200}$/.test(value) || value === "." || value === "..")
801
- invalid5();
626
+ invalid4();
802
627
  return value;
803
628
  }
804
629
  __name(id, "id");
805
630
  function boolean(value) {
806
631
  if (typeof value !== "boolean")
807
- invalid5();
632
+ invalid4();
808
633
  return value;
809
634
  }
810
635
  __name(boolean, "boolean");
811
636
  function bounded3(value) {
812
637
  if (new TextEncoder().encode(JSON.stringify(value)).length > MLS_DEV_GROUP_FEED_MAX_BYTES)
813
- invalid5();
638
+ invalid4();
814
639
  return Object.freeze(value);
815
640
  }
816
641
  __name(bounded3, "bounded");
817
642
  function array(value) {
818
643
  if (!Array.isArray(value) || Object.getPrototypeOf(value) !== Array.prototype || value.length > MLS_DEV_GROUP_FEED_MAX_ENTRIES)
819
- invalid5();
644
+ invalid4();
820
645
  const descriptors = Object.getOwnPropertyDescriptors(value);
821
646
  if (Reflect.ownKeys(descriptors).length !== value.length + 1)
822
- invalid5();
647
+ invalid4();
823
648
  return Array.from({ length: value.length }, (_, index) => {
824
649
  const field = descriptors[index];
825
650
  if (!field || !field.enumerable || !Object.hasOwn(field, "value"))
826
- invalid5();
651
+ invalid4();
827
652
  return field.value;
828
653
  });
829
654
  }
830
655
  __name(array, "array");
831
656
  function parseMlsDevGroupFeedEntry(value) {
832
- return boundary4(() => {
657
+ return boundary3(() => {
833
658
  const signed = value !== null && typeof value === "object" && Object.hasOwn(value, "receiptProof") ? ["receiptProof"] : [];
834
659
  const input = readMlsDataRecord(value, ["version", "ordinal", "kind", "accepted", ...signed], ["version", "ordinal", "kind", "receipt", "envelope", ...signed]);
835
660
  const version = requireMlsLiteral(input.version, 1), ordinal = requireMlsInteger(input.ordinal, 1);
836
661
  const proof = signed.length ? { receiptProof: parseMlsDevFeedReceiptProof(input.receiptProof) } : {};
837
662
  if (input.kind === "control") {
838
663
  if (!Object.hasOwn(input, "accepted"))
839
- invalid5();
664
+ invalid4();
840
665
  return bounded3({ version, ordinal, kind: "control", accepted: parseMlsDevGroupAcceptedControl(input.accepted), ...proof });
841
666
  }
842
667
  const kind = requireMlsLiteral(input.kind, "application"), receipt = parseMlsDevApplicationReceipt(input.receipt), envelope = parseMlsDevApplicationEnvelope(input.envelope);
843
668
  if (ordinal !== receipt.feedOrdinal || receipt.conversationId !== envelope.conversationId || receipt.groupId !== envelope.groupId || receipt.messageId !== envelope.messageId || JSON.stringify(receipt.head) !== JSON.stringify(envelope.expectedHead))
844
- invalid5();
669
+ invalid4();
845
670
  return bounded3({ version, ordinal, kind, receipt, envelope, ...proof });
846
671
  });
847
672
  }
848
673
  __name(parseMlsDevGroupFeedEntry, "parseMlsDevGroupFeedEntry");
849
674
  function parseMlsDevGroupFeedQuery(value) {
850
- return boundary4(() => {
675
+ return boundary3(() => {
851
676
  const input = readMlsDataRecord(value, ["version", "conversationId", "credential", "afterOrdinal", "limit"]);
852
677
  const limit2 = requireMlsInteger(input.limit, 1);
853
678
  if (limit2 > MLS_DEV_GROUP_FEED_MAX_ENTRIES)
854
- invalid5();
679
+ invalid4();
855
680
  parseMlsDevCredentialToken(input.credential);
856
681
  return Object.freeze({ version: requireMlsLiteral(input.version, 1), conversationId: id(input.conversationId), credential: input.credential, afterOrdinal: requireMlsInteger(input.afterOrdinal), limit: limit2 });
857
682
  });
858
683
  }
859
684
  __name(parseMlsDevGroupFeedQuery, "parseMlsDevGroupFeedQuery");
860
685
  function parseMlsDevGroupFeedResult(value) {
861
- return boundary4(() => {
686
+ return boundary3(() => {
862
687
  const input = readMlsDataRecord(value, ["version", "protocol", "conversationId", "marker", "membershipRevision", "admissionId", "roster", "minimumOrdinal", "latestOrdinal", "nextOrdinal", "entries", "hasMore", "terminal"]);
863
688
  const conversationId = id(input.conversationId), marker = input.marker === null ? null : parseMlsDevGroupMarker(input.marker);
864
689
  const minimumOrdinal = input.minimumOrdinal === null ? null : requireMlsInteger(input.minimumOrdinal, 1);
865
690
  const latestOrdinal = requireMlsInteger(input.latestOrdinal), nextOrdinal = requireMlsInteger(input.nextOrdinal);
866
691
  const entries = array(input.entries).map(parseMlsDevGroupFeedEntry), hasMore = boolean(input.hasMore), terminal = boolean(input.terminal);
867
692
  if (nextOrdinal > latestOrdinal || minimumOrdinal !== null && minimumOrdinal > latestOrdinal || minimumOrdinal === null && (entries.length || nextOrdinal || hasMore || terminal) || !marker && (latestOrdinal || minimumOrdinal !== null || entries.length || terminal))
868
- invalid5();
869
- const protocol = isMlsDevTextProtocol(input.protocol) ? input.protocol : invalid5();
693
+ invalid4();
694
+ const protocol = isMlsDevTextProtocol(input.protocol) ? input.protocol : invalid4();
870
695
  for (let i = 0; i < entries.length; i++) {
871
696
  const entry = entries[i], subject = entry.kind === "control" ? entry.accepted.control : entry.envelope;
872
697
  if (entry.kind === "application" && entry.envelope.interaction && !mlsDevProtocolCarriesCards(protocol))
873
- invalid5();
698
+ invalid4();
874
699
  if (!marker || minimumOrdinal === null || entry.ordinal < minimumOrdinal || entry.ordinal > latestOrdinal || subject.conversationId !== conversationId || subject.groupId !== marker.groupId || i > 0 && entry.ordinal !== entries[i - 1].ordinal + 1)
875
- invalid5();
700
+ invalid4();
876
701
  const head = entry.kind === "control" ? entry.accepted.head : entry.receipt.head;
877
702
  if (head.sequence > marker.head.sequence || head.epoch > marker.head.epoch)
878
- invalid5();
703
+ invalid4();
879
704
  }
880
705
  if (entries.length && entries.at(-1).ordinal !== nextOrdinal || hasMore !== (minimumOrdinal !== null && nextOrdinal < latestOrdinal))
881
- invalid5();
706
+ invalid4();
882
707
  return bounded3({
883
708
  version: requireMlsLiteral(input.version, 1),
884
709
  protocol,
@@ -911,25 +736,25 @@ var MlsDevKeyPackagesValidationError = class extends Error {
911
736
  this.name = "MlsDevKeyPackagesValidationError";
912
737
  }
913
738
  };
914
- function invalid6() {
739
+ function invalid5() {
915
740
  throw new MlsDevKeyPackagesValidationError();
916
741
  }
917
- __name(invalid6, "invalid");
918
- function boundary5(read) {
742
+ __name(invalid5, "invalid");
743
+ function boundary4(read) {
919
744
  try {
920
745
  return read();
921
746
  } catch {
922
- return invalid6();
747
+ return invalid5();
923
748
  }
924
749
  }
925
- __name(boundary5, "boundary");
750
+ __name(boundary4, "boundary");
926
751
  function bounded4(value) {
927
- if (new TextEncoder().encode(JSON.stringify(value)).length > MLS_DEV_KEY_PACKAGES_MAX_BYTES) invalid6();
752
+ if (new TextEncoder().encode(JSON.stringify(value)).length > MLS_DEV_KEY_PACKAGES_MAX_BYTES) invalid5();
928
753
  return Object.freeze(value);
929
754
  }
930
755
  __name(bounded4, "bounded");
931
756
  function id2(value) {
932
- if (typeof value !== "string" || !/^[A-Za-z0-9_.:~-]{1,200}$/.test(value) || value === "." || value === "..") invalid6();
757
+ if (typeof value !== "string" || !/^[A-Za-z0-9_.:~-]{1,200}$/.test(value) || value === "." || value === "..") invalid5();
933
758
  return value;
934
759
  }
935
760
  __name(id2, "id");
@@ -939,18 +764,18 @@ function ref(value) {
939
764
  }
940
765
  __name(ref, "ref");
941
766
  function parseMlsDevKeyPackageWire(value) {
942
- return boundary5(() => {
943
- if (typeof value !== "string" || value.length < 2 || value.length > Math.ceil(MLS_DEV_KEY_PACKAGE_TLS_MAX_BYTES * 4 / 3)) invalid6();
767
+ return boundary4(() => {
768
+ if (typeof value !== "string" || value.length < 2 || value.length > Math.ceil(MLS_DEV_KEY_PACKAGE_TLS_MAX_BYTES * 4 / 3)) invalid5();
944
769
  const bytes = Math.floor(value.length * 3 / 4);
945
- if (bytes < 1 || bytes > MLS_DEV_KEY_PACKAGE_TLS_MAX_BYTES || value.length !== Math.ceil(bytes * 4 / 3) || !/^[A-Za-z0-9_-]+$/.test(value)) invalid6();
770
+ if (bytes < 1 || bytes > MLS_DEV_KEY_PACKAGE_TLS_MAX_BYTES || value.length !== Math.ceil(bytes * 4 / 3) || !/^[A-Za-z0-9_-]+$/.test(value)) invalid5();
946
771
  const last = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".indexOf(value.at(-1));
947
- if (value.length % 4 === 2 && (last & 15) !== 0 || value.length % 4 === 3 && (last & 3) !== 0) invalid6();
772
+ if (value.length % 4 === 2 && (last & 15) !== 0 || value.length % 4 === 3 && (last & 3) !== 0) invalid5();
948
773
  return value;
949
774
  });
950
775
  }
951
776
  __name(parseMlsDevKeyPackageWire, "parseMlsDevKeyPackageWire");
952
777
  function parseMlsDevKeyPackageClaimPreconditions(value) {
953
- return boundary5(() => {
778
+ return boundary4(() => {
954
779
  const input = readMlsDataRecord(value, ["conversationId", "membershipRevision", "admissionId", "targetAdmissionId"]);
955
780
  return Object.freeze({
956
781
  conversationId: id2(input.conversationId),
@@ -962,17 +787,17 @@ function parseMlsDevKeyPackageClaimPreconditions(value) {
962
787
  }
963
788
  __name(parseMlsDevKeyPackageClaimPreconditions, "parseMlsDevKeyPackageClaimPreconditions");
964
789
  function parseMlsDevKeyPackagePublish(value) {
965
- return boundary5(() => {
790
+ return boundary4(() => {
966
791
  const input = readMlsDataRecord(value, ["version", "requestId", "keyPackage"]);
967
792
  return bounded4({ version: requireMlsLiteral(input.version, 1), requestId: requireMlsUuid(input.requestId), keyPackage: parseMlsDevKeyPackageWire(input.keyPackage) });
968
793
  });
969
794
  }
970
795
  __name(parseMlsDevKeyPackagePublish, "parseMlsDevKeyPackagePublish");
971
796
  function parseMlsDevKeyPackagePublicationReceipt(value) {
972
- return boundary5(() => {
797
+ return boundary4(() => {
973
798
  const input = readMlsDataRecord(value, ["version", "authorization", "requestId", "keyPackageRef", "deviceId", "publishedAtMs", "expiresAtMs"]);
974
799
  const publishedAtMs = requireMlsInteger(input.publishedAtMs), expiresAtMs = requireMlsInteger(input.expiresAtMs);
975
- if (publishedAtMs >= expiresAtMs) invalid6();
800
+ if (publishedAtMs >= expiresAtMs) invalid5();
976
801
  return bounded4({
977
802
  version: requireMlsLiteral(input.version, 1),
978
803
  authorization: requireMlsLiteral(input.authorization, "key_package_publication_only"),
@@ -986,7 +811,7 @@ function parseMlsDevKeyPackagePublicationReceipt(value) {
986
811
  }
987
812
  __name(parseMlsDevKeyPackagePublicationReceipt, "parseMlsDevKeyPackagePublicationReceipt");
988
813
  function parseMlsDevKeyPackageClaim(value) {
989
- return boundary5(() => {
814
+ return boundary4(() => {
990
815
  const input = readMlsDataRecord(value, ["version", "requestId", "claimantCredential", "recipientDeviceId", "preconditions"]);
991
816
  parseMlsDevCredentialToken(input.claimantCredential);
992
817
  return bounded4({
@@ -1000,7 +825,7 @@ function parseMlsDevKeyPackageClaim(value) {
1000
825
  }
1001
826
  __name(parseMlsDevKeyPackageClaim, "parseMlsDevKeyPackageClaim");
1002
827
  function parseMlsDevKeyPackageClaimReceipt(value) {
1003
- return boundary5(() => {
828
+ return boundary4(() => {
1004
829
  const input = readMlsDataRecord(value, [
1005
830
  "version",
1006
831
  "authorization",
@@ -1013,7 +838,7 @@ function parseMlsDevKeyPackageClaimReceipt(value) {
1013
838
  "claimedAtMs"
1014
839
  ]);
1015
840
  const claimantDeviceId = requireMlsUuid(input.claimantDeviceId), recipientDeviceId = requireMlsUuid(input.recipientDeviceId);
1016
- if (claimantDeviceId === recipientDeviceId) invalid6();
841
+ if (claimantDeviceId === recipientDeviceId) invalid5();
1017
842
  return bounded4({
1018
843
  version: requireMlsLiteral(input.version, 1),
1019
844
  authorization: requireMlsLiteral(input.authorization, "key_package_claim_only"),
@@ -1044,25 +869,25 @@ var MlsDevInteractionValidationError = class extends Error {
1044
869
  }
1045
870
  };
1046
871
  var utf83 = new TextEncoder();
1047
- function invalid7() {
872
+ function invalid6() {
1048
873
  throw new MlsDevInteractionValidationError();
1049
874
  }
1050
- __name(invalid7, "invalid");
1051
- function boundary6(read) {
875
+ __name(invalid6, "invalid");
876
+ function boundary5(read) {
1052
877
  try {
1053
878
  return read();
1054
879
  } catch {
1055
- return invalid7();
880
+ return invalid6();
1056
881
  }
1057
882
  }
1058
- __name(boundary6, "boundary");
883
+ __name(boundary5, "boundary");
1059
884
  function id3(value) {
1060
- if (typeof value !== "string" || !/^[A-Za-z0-9_.:~-]{1,200}$/.test(value) || value === "." || value === "..") invalid7();
885
+ if (typeof value !== "string" || !/^[A-Za-z0-9_.:~-]{1,200}$/.test(value) || value === "." || value === "..") invalid6();
1061
886
  return value;
1062
887
  }
1063
888
  __name(id3, "id");
1064
889
  function interactionId(value) {
1065
- if (typeof value !== "string" || !MLS_DEV_INTERACTION_ID_PATTERN.test(value) || value === "." || value === "..") invalid7();
890
+ if (typeof value !== "string" || !MLS_DEV_INTERACTION_ID_PATTERN.test(value) || value === "." || value === "..") invalid6();
1066
891
  return value;
1067
892
  }
1068
893
  __name(interactionId, "interactionId");
@@ -1072,39 +897,39 @@ function encoded3(value, bytes) {
1072
897
  }
1073
898
  __name(encoded3, "encoded");
1074
899
  function wire(value, min, max) {
1075
- if (typeof value !== "string" || !/^[A-Za-z0-9_-]*$/.test(value) || value.length % 4 === 1) invalid7();
900
+ if (typeof value !== "string" || !/^[A-Za-z0-9_-]*$/.test(value) || value.length % 4 === 1) invalid6();
1076
901
  const bytes = Math.floor(value.length * 3 / 4);
1077
- if (bytes < min || bytes > max) invalid7();
902
+ if (bytes < min || bytes > max) invalid6();
1078
903
  const last = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".indexOf(value.at(-1));
1079
- if (value.length % 4 === 2 && (last & 15) !== 0 || value.length % 4 === 3 && (last & 3) !== 0) invalid7();
904
+ if (value.length % 4 === 2 && (last & 15) !== 0 || value.length % 4 === 3 && (last & 3) !== 0) invalid6();
1080
905
  return value;
1081
906
  }
1082
907
  __name(wire, "wire");
1083
908
  function text(value, max) {
1084
- if (typeof value !== "string" || !value.trim() || [...value].length > max || new TextDecoder("utf-8", { fatal: true }).decode(utf83.encode(value)) !== value) invalid7();
909
+ if (typeof value !== "string" || !value.trim() || [...value].length > max || new TextDecoder("utf-8", { fatal: true }).decode(utf83.encode(value)) !== value) invalid6();
1085
910
  return value;
1086
911
  }
1087
912
  __name(text, "text");
1088
913
  function boolean2(value) {
1089
- if (typeof value !== "boolean") invalid7();
914
+ if (typeof value !== "boolean") invalid6();
1090
915
  return value;
1091
916
  }
1092
917
  __name(boolean2, "boolean");
1093
918
  function array2(value, min, max) {
1094
- if (!Array.isArray(value) || Object.getPrototypeOf(value) !== Array.prototype || value.length < min || value.length > max) invalid7();
919
+ if (!Array.isArray(value) || Object.getPrototypeOf(value) !== Array.prototype || value.length < min || value.length > max) invalid6();
1095
920
  const descriptors = Object.getOwnPropertyDescriptors(value);
1096
- if (Reflect.ownKeys(descriptors).length !== value.length + 1) invalid7();
921
+ if (Reflect.ownKeys(descriptors).length !== value.length + 1) invalid6();
1097
922
  return Array.from({ length: value.length }, (_, index) => {
1098
923
  const field = descriptors[index];
1099
- if (!field || !field.enumerable || !Object.hasOwn(field, "value")) invalid7();
924
+ if (!field || !field.enumerable || !Object.hasOwn(field, "value")) invalid6();
1100
925
  return field.value;
1101
926
  });
1102
927
  }
1103
928
  __name(array2, "array");
1104
929
  function closed(value, required, optional) {
1105
- if (value === null || typeof value !== "object" || Array.isArray(value)) invalid7();
930
+ if (value === null || typeof value !== "object" || Array.isArray(value)) invalid6();
1106
931
  const present2 = Reflect.ownKeys(value);
1107
- if (present2.some((key) => typeof key !== "string" || !required.includes(key) && !optional.includes(key))) invalid7();
932
+ if (present2.some((key) => typeof key !== "string" || !required.includes(key) && !optional.includes(key))) invalid6();
1108
933
  return readMlsDataRecord(value, present2);
1109
934
  }
1110
935
  __name(closed, "closed");
@@ -1113,31 +938,31 @@ function ordered(value) {
1113
938
  }
1114
939
  __name(ordered, "ordered");
1115
940
  function parseMlsDevInteractionRequestBody(value) {
1116
- return boundary6(() => {
941
+ return boundary5(() => {
1117
942
  const input = closed(
1118
943
  value,
1119
944
  ["requestId", "kind", "title", "responderIds", "expiresAtMs"],
1120
945
  ["details", "options", "multiple", "risk", "allowSession", "scopeKey", "secretKey"]
1121
946
  );
1122
947
  const kind = input.kind;
1123
- if (typeof kind !== "string" || !MLS_DEV_INTERACTION_KINDS.includes(kind)) invalid7();
948
+ if (typeof kind !== "string" || !MLS_DEV_INTERACTION_KINDS.includes(kind)) invalid6();
1124
949
  const has = /* @__PURE__ */ __name((key) => Object.hasOwn(input, key), "has");
1125
950
  const options = has("options") ? array2(input.options, 1, MLS_DEV_INTERACTION_LIMITS.options).map((option) => {
1126
951
  const fields2 = readMlsDataRecord(option, ["id", "label"]);
1127
- if (typeof fields2.id !== "string" || !/^[A-Za-z0-9_.:-]{1,64}$/.test(fields2.id)) invalid7();
952
+ if (typeof fields2.id !== "string" || !/^[A-Za-z0-9_.:-]{1,64}$/.test(fields2.id)) invalid6();
1128
953
  return Object.freeze({ id: fields2.id, label: text(fields2.label, MLS_DEV_INTERACTION_LIMITS.optionLabel) });
1129
954
  }) : void 0;
1130
- if (options && new Set(options.map((option) => option.id)).size !== options.length) invalid7();
955
+ if (options && new Set(options.map((option) => option.id)).size !== options.length) invalid6();
1131
956
  const binding3 = parseMlsDevInteractionBinding({ role: "request", requestId: input.requestId, kind, responderIds: input.responderIds, expiresAtMs: input.expiresAtMs });
1132
- if (binding3.role !== "request") invalid7();
1133
- if (kind !== "approval" && ["risk", "allowSession", "scopeKey"].some(has)) invalid7();
1134
- if (kind !== "question" && (has("options") || has("multiple"))) invalid7();
1135
- if (has("multiple") && !options) invalid7();
1136
- if (kind === "secret" !== has("secretKey")) invalid7();
957
+ if (binding3.role !== "request") invalid6();
958
+ if (kind !== "approval" && ["risk", "allowSession", "scopeKey"].some(has)) invalid6();
959
+ if (kind !== "question" && (has("options") || has("multiple"))) invalid6();
960
+ if (has("multiple") && !options) invalid6();
961
+ if (kind === "secret" !== has("secretKey")) invalid6();
1137
962
  const allowSession = has("allowSession") ? boolean2(input.allowSession) : void 0;
1138
- if (has("scopeKey") && (typeof input.scopeKey !== "string" || !/^[A-Za-z0-9_:-]{1,64}$/.test(input.scopeKey))) invalid7();
1139
- if (allowSession === true && !has("scopeKey")) invalid7();
1140
- if (has("risk") && input.risk !== "normal" && input.risk !== "destructive") invalid7();
963
+ if (has("scopeKey") && (typeof input.scopeKey !== "string" || !/^[A-Za-z0-9_:-]{1,64}$/.test(input.scopeKey))) invalid6();
964
+ if (allowSession === true && !has("scopeKey")) invalid6();
965
+ if (has("risk") && input.risk !== "normal" && input.risk !== "destructive") invalid6();
1141
966
  const secretKey = has("secretKey") ? (() => {
1142
967
  const key = readMlsDataRecord(input.secretKey, ["kem", "publicKey"]);
1143
968
  return Object.freeze({ kem: requireMlsLiteral(key.kem, "x25519"), publicKey: encoded3(key.publicKey, 32) });
@@ -1160,20 +985,20 @@ function parseMlsDevInteractionRequestBody(value) {
1160
985
  }
1161
986
  __name(parseMlsDevInteractionRequestBody, "parseMlsDevInteractionRequestBody");
1162
987
  function parseMlsDevInteractionAnswer(value) {
1163
- return boundary6(() => {
1164
- if (value === null || typeof value !== "object" || Array.isArray(value)) invalid7();
988
+ return boundary5(() => {
989
+ if (value === null || typeof value !== "object" || Array.isArray(value)) invalid6();
1165
990
  const keys2 = Reflect.ownKeys(value);
1166
991
  if (keys2.includes("decision")) {
1167
992
  const input = readMlsDataRecord(value, ["decision", "scope"]);
1168
- if (input.decision !== "allow" && input.decision !== "deny" || input.scope !== "once" && input.scope !== "session") invalid7();
993
+ if (input.decision !== "allow" && input.decision !== "deny" || input.scope !== "once" && input.scope !== "session") invalid6();
1169
994
  return Object.freeze({ decision: input.decision, scope: input.scope });
1170
995
  }
1171
996
  if (keys2.includes("choices")) {
1172
997
  const choices = array2(readMlsDataRecord(value, ["choices"]).choices, 1, MLS_DEV_INTERACTION_LIMITS.options).map((choice) => {
1173
- if (typeof choice !== "string" || !/^[A-Za-z0-9_.:-]{1,64}$/.test(choice)) invalid7();
998
+ if (typeof choice !== "string" || !/^[A-Za-z0-9_.:-]{1,64}$/.test(choice)) invalid6();
1174
999
  return choice;
1175
1000
  });
1176
- if (new Set(choices).size !== choices.length) invalid7();
1001
+ if (new Set(choices).size !== choices.length) invalid6();
1177
1002
  return Object.freeze({ choices: Object.freeze(choices) });
1178
1003
  }
1179
1004
  if (keys2.includes("text")) return Object.freeze({ text: text(readMlsDataRecord(value, ["text"]).text, MLS_DEV_INTERACTION_LIMITS.text) });
@@ -1181,31 +1006,31 @@ function parseMlsDevInteractionAnswer(value) {
1181
1006
  const sealed = readMlsDataRecord(readMlsDataRecord(value, ["sealed"]).sealed, ["enc", "ciphertext"]);
1182
1007
  return Object.freeze({ sealed: Object.freeze({ enc: encoded3(sealed.enc, 32), ciphertext: wire(sealed.ciphertext, 17, MLS_DEV_SECRET_ANSWER_MAX_BYTES) }) });
1183
1008
  }
1184
- if (readMlsDataRecord(value, ["cancelled"]).cancelled !== true) invalid7();
1009
+ if (readMlsDataRecord(value, ["cancelled"]).cancelled !== true) invalid6();
1185
1010
  return Object.freeze({ cancelled: true });
1186
1011
  });
1187
1012
  }
1188
1013
  __name(parseMlsDevInteractionAnswer, "parseMlsDevInteractionAnswer");
1189
1014
  function parseMlsDevInteractionResponseBody(value) {
1190
- return boundary6(() => {
1015
+ return boundary5(() => {
1191
1016
  const input = readMlsDataRecord(value, ["requestId", "agentId", "answer"]);
1192
1017
  return Object.freeze({ requestId: interactionId(input.requestId), agentId: id3(input.agentId), answer: parseMlsDevInteractionAnswer(input.answer) });
1193
1018
  });
1194
1019
  }
1195
1020
  __name(parseMlsDevInteractionResponseBody, "parseMlsDevInteractionResponseBody");
1196
1021
  function parseMlsDevInteractionWithdrawBody(value) {
1197
- return boundary6(() => {
1022
+ return boundary5(() => {
1198
1023
  const input = readMlsDataRecord(value, ["requestId", "reason"]);
1199
- if (!MLS_DEV_INTERACTION_WITHDRAW_REASONS.includes(input.reason)) invalid7();
1024
+ if (!MLS_DEV_INTERACTION_WITHDRAW_REASONS.includes(input.reason)) invalid6();
1200
1025
  return Object.freeze({ requestId: interactionId(input.requestId), reason: input.reason });
1201
1026
  });
1202
1027
  }
1203
1028
  __name(parseMlsDevInteractionWithdrawBody, "parseMlsDevInteractionWithdrawBody");
1204
1029
  var payloadFields = ["version", "kind", "conversationId", "groupId", "messageId", "operationId", "senderDeviceId"];
1205
1030
  function parseMlsDevApplicationPayload(value) {
1206
- return boundary6(() => {
1031
+ return boundary5(() => {
1207
1032
  const kind = value && typeof value === "object" ? Object.getOwnPropertyDescriptor(value, "kind") : void 0;
1208
- if (!kind || !Object.hasOwn(kind, "value")) invalid7();
1033
+ if (!kind || !Object.hasOwn(kind, "value")) invalid6();
1209
1034
  if (kind.value === "text") return parseMlsDevTextPayload(value);
1210
1035
  if (kind.value === "item") return parseMlsDevItemPayload(value);
1211
1036
  const input = readMlsDataRecord(value, [...payloadFields, "interaction"]);
@@ -1218,26 +1043,26 @@ function parseMlsDevApplicationPayload(value) {
1218
1043
  operationId: id3(input.operationId),
1219
1044
  senderDeviceId: requireMlsUuid(input.senderDeviceId)
1220
1045
  };
1221
- if (ids.messageId.startsWith("membership-")) invalid7();
1222
- const interaction = kind.value === "interaction.request" ? parseMlsDevInteractionRequestBody(input.interaction) : kind.value === "interaction.response" ? parseMlsDevInteractionResponseBody(input.interaction) : kind.value === "interaction.withdraw" ? parseMlsDevInteractionWithdrawBody(input.interaction) : invalid7();
1046
+ if (ids.messageId.startsWith("membership-")) invalid6();
1047
+ const interaction = kind.value === "interaction.request" ? parseMlsDevInteractionRequestBody(input.interaction) : kind.value === "interaction.response" ? parseMlsDevInteractionResponseBody(input.interaction) : kind.value === "interaction.withdraw" ? parseMlsDevInteractionWithdrawBody(input.interaction) : invalid6();
1223
1048
  const payload = Object.freeze({ ...ids, interaction });
1224
- if (utf83.encode(JSON.stringify(payload)).length > MLS_DEV_TEXT_MAX_BYTES) invalid7();
1049
+ if (utf83.encode(JSON.stringify(payload)).length > MLS_DEV_TEXT_MAX_BYTES) invalid6();
1225
1050
  return payload;
1226
1051
  });
1227
1052
  }
1228
1053
  __name(parseMlsDevApplicationPayload, "parseMlsDevApplicationPayload");
1229
1054
  function assertMlsDevInteractionPayloadBinding(payload, binding3) {
1230
- boundary6(() => {
1055
+ boundary5(() => {
1231
1056
  if (payload.kind === "text" || payload.kind === "item") {
1232
- if (binding3 !== void 0) invalid7();
1057
+ if (binding3 !== void 0) invalid6();
1233
1058
  return;
1234
1059
  }
1235
- if (!binding3 || payload.interaction.requestId !== binding3.requestId) invalid7();
1060
+ if (!binding3 || payload.interaction.requestId !== binding3.requestId) invalid6();
1236
1061
  if (payload.kind === "interaction.request") {
1237
- if (binding3.role !== "request" || payload.interaction.kind !== binding3.kind || payload.interaction.expiresAtMs !== binding3.expiresAtMs || payload.interaction.responderIds.length !== 1 || payload.interaction.responderIds[0] !== binding3.responderIds[0]) invalid7();
1062
+ if (binding3.role !== "request" || payload.interaction.kind !== binding3.kind || payload.interaction.expiresAtMs !== binding3.expiresAtMs || payload.interaction.responderIds.length !== 1 || payload.interaction.responderIds[0] !== binding3.responderIds[0]) invalid6();
1238
1063
  } else if (payload.kind === "interaction.response") {
1239
- if (binding3.role !== "response" || payload.interaction.agentId !== binding3.agentId) invalid7();
1240
- } else if (binding3.role !== "withdraw") invalid7();
1064
+ if (binding3.role !== "response" || payload.interaction.agentId !== binding3.agentId) invalid6();
1065
+ } else if (binding3.role !== "withdraw") invalid6();
1241
1066
  });
1242
1067
  }
1243
1068
  __name(assertMlsDevInteractionPayloadBinding, "assertMlsDevInteractionPayloadBinding");
@@ -1271,27 +1096,27 @@ var MlsDevGroupValidationError = class extends Error {
1271
1096
  }
1272
1097
  };
1273
1098
  var utf84 = new TextEncoder();
1274
- function invalid8() {
1099
+ function invalid7() {
1275
1100
  throw new MlsDevGroupValidationError();
1276
1101
  }
1277
- __name(invalid8, "invalid");
1278
- function boundary7(read) {
1102
+ __name(invalid7, "invalid");
1103
+ function boundary6(read) {
1279
1104
  try {
1280
1105
  return read();
1281
1106
  } catch {
1282
- return invalid8();
1107
+ return invalid7();
1283
1108
  }
1284
1109
  }
1285
- __name(boundary7, "boundary");
1110
+ __name(boundary6, "boundary");
1286
1111
  function bounded5(value, maximum = MLS_DEV_GROUP_CONTROL_MAX_BYTES) {
1287
1112
  if (utf84.encode(JSON.stringify(value)).length > maximum)
1288
- invalid8();
1113
+ invalid7();
1289
1114
  return Object.freeze(value);
1290
1115
  }
1291
1116
  __name(bounded5, "bounded");
1292
1117
  function id4(value) {
1293
1118
  if (typeof value !== "string" || !/^[A-Za-z0-9_.:~-]{1,200}$/.test(value) || value === "." || value === "..")
1294
- invalid8();
1119
+ invalid7();
1295
1120
  return value;
1296
1121
  }
1297
1122
  __name(id4, "id");
@@ -1302,13 +1127,13 @@ function encoded4(value, bytes) {
1302
1127
  __name(encoded4, "encoded");
1303
1128
  function boolean3(value) {
1304
1129
  if (typeof value !== "boolean")
1305
- invalid8();
1130
+ invalid7();
1306
1131
  return value;
1307
1132
  }
1308
1133
  __name(boolean3, "boolean");
1309
1134
  function textProtocol(value) {
1310
1135
  if (!isMlsDevTextProtocol(value))
1311
- invalid8();
1136
+ invalid7();
1312
1137
  return value;
1313
1138
  }
1314
1139
  __name(textProtocol, "textProtocol");
@@ -1319,19 +1144,19 @@ function token(value) {
1319
1144
  __name(token, "token");
1320
1145
  function wire2(value) {
1321
1146
  if (typeof value !== "string" || value.length < 2 || value.length > Math.ceil(MLS_DEV_GROUP_TLS_MAX_BYTES * 4 / 3))
1322
- invalid8();
1147
+ invalid7();
1323
1148
  const bytes = Math.floor(value.length * 3 / 4);
1324
1149
  if (value.length !== Math.ceil(bytes * 4 / 3) || !/^[A-Za-z0-9_-]+$/.test(value))
1325
- invalid8();
1150
+ invalid7();
1326
1151
  const last = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".indexOf(value.at(-1));
1327
1152
  if (value.length % 4 === 2 && (last & 15) !== 0 || value.length % 4 === 3 && (last & 3) !== 0)
1328
- invalid8();
1153
+ invalid7();
1329
1154
  return value;
1330
1155
  }
1331
1156
  __name(wire2, "wire");
1332
1157
  function plaintextJson(value) {
1333
1158
  if (typeof value !== "string" || !value || utf84.encode(value).length > MLS_DEV_TEXT_MAX_BYTES || new TextDecoder("utf-8", { fatal: true }).decode(utf84.encode(value)) !== value)
1334
- invalid8();
1159
+ invalid7();
1335
1160
  return value;
1336
1161
  }
1337
1162
  __name(plaintextJson, "plaintextJson");
@@ -1342,92 +1167,92 @@ __name(present, "present");
1342
1167
  var pick = /* @__PURE__ */ __name((value, keys2) => Object.fromEntries(keys2.map((key) => [key, value[key]])), "pick");
1343
1168
  var textExtras = /* @__PURE__ */ __name((text5) => ({ ...text5.replyTo ? { replyTo: text5.replyTo } : {}, ...text5.mentions ? { mentions: text5.mentions } : {} }), "textExtras");
1344
1169
  function sealedCiphertext(value) {
1345
- if (typeof value !== "string" || !/^[A-Za-z0-9_-]+$/.test(value) || value.length % 4 === 1) invalid8();
1170
+ if (typeof value !== "string" || !/^[A-Za-z0-9_-]+$/.test(value) || value.length % 4 === 1) invalid7();
1346
1171
  const bytes = Math.floor(value.length * 3 / 4);
1347
- if (bytes < 17 || bytes > MLS_DEV_SECRET_ANSWER_MAX_BYTES) invalid8();
1172
+ if (bytes < 17 || bytes > MLS_DEV_SECRET_ANSWER_MAX_BYTES) invalid7();
1348
1173
  const last = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".indexOf(value.at(-1));
1349
- if (value.length % 4 === 2 && (last & 15) !== 0 || value.length % 4 === 3 && (last & 3) !== 0) invalid8();
1174
+ if (value.length % 4 === 2 && (last & 15) !== 0 || value.length % 4 === 3 && (last & 3) !== 0) invalid7();
1350
1175
  return value;
1351
1176
  }
1352
1177
  __name(sealedCiphertext, "sealedCiphertext");
1353
1178
  function array3(value, maximum) {
1354
1179
  if (!Array.isArray(value) || Object.getPrototypeOf(value) !== Array.prototype || value.length > maximum)
1355
- invalid8();
1180
+ invalid7();
1356
1181
  const descriptors = Object.getOwnPropertyDescriptors(value);
1357
1182
  if (Reflect.ownKeys(descriptors).length !== value.length + 1)
1358
- invalid8();
1183
+ invalid7();
1359
1184
  return Array.from({ length: value.length }, (_, index) => {
1360
1185
  const descriptor = descriptors[index];
1361
1186
  if (!descriptor || !descriptor.enumerable || !Object.hasOwn(descriptor, "value"))
1362
- invalid8();
1187
+ invalid7();
1363
1188
  return descriptor.value;
1364
1189
  });
1365
1190
  }
1366
1191
  __name(array3, "array");
1367
1192
  function parseMlsDevGroupCreateConversation(value) {
1368
- return boundary7(() => {
1193
+ return boundary6(() => {
1369
1194
  const input = readMlsDataRecord(value, ["name", "memberIds", "mlsDev"]), config = readMlsDataRecord(input.mlsDev, ["version", "conversationId", "credential"], ["version", "conversationId", "credential", "protocol"]);
1370
1195
  if (typeof input.name !== "string" || input.name.trim().length > 100)
1371
- invalid8();
1196
+ invalid7();
1372
1197
  const memberIds = array3(input.memberIds, 31).map((value2) => parseMlsDevEnrollmentPrincipal({ type: "human", id: value2 }).id);
1373
1198
  if (!memberIds.length || new Set(memberIds).size !== memberIds.length || memberIds.some((value2) => value2.includes("/") || value2 === "." || value2 === ".."))
1374
- invalid8();
1199
+ invalid7();
1375
1200
  return bounded5({ name: input.name, memberIds: Object.freeze(memberIds), mlsDev: Object.freeze({ version: requireMlsLiteral(config.version, 1), conversationId: id4(config.conversationId), credential: token(config.credential), ...Object.hasOwn(config, "protocol") ? { protocol: textProtocol(config.protocol) } : {} }) }, 16 * 1024);
1376
1201
  });
1377
1202
  }
1378
1203
  __name(parseMlsDevGroupCreateConversation, "parseMlsDevGroupCreateConversation");
1379
1204
  function parseMlsDevGroupHead(value) {
1380
- return boundary7(() => {
1205
+ return boundary6(() => {
1381
1206
  const input = readMlsDataRecord(value, ["sequence", "epoch", "hash"]);
1382
1207
  return Object.freeze({ sequence: requireMlsInteger(input.sequence, 1), epoch: requireMlsInteger(input.epoch), hash: encoded4(input.hash, 32) });
1383
1208
  });
1384
1209
  }
1385
1210
  __name(parseMlsDevGroupHead, "parseMlsDevGroupHead");
1386
1211
  function parseMlsDevGroupMarker(value) {
1387
- return boundary7(() => {
1212
+ return boundary6(() => {
1388
1213
  const input = readMlsDataRecord(value, ["version", "groupId", "head"]);
1389
1214
  return Object.freeze({ version: requireMlsLiteral(input.version, 1), groupId: encoded4(input.groupId, 32), head: parseMlsDevGroupHead(input.head) });
1390
1215
  });
1391
1216
  }
1392
1217
  __name(parseMlsDevGroupMarker, "parseMlsDevGroupMarker");
1393
1218
  function parseMlsDevGroupRoster(value) {
1394
- return boundary7(() => {
1219
+ return boundary6(() => {
1395
1220
  const values = array3(value, MLS_DEV_GROUP_ROSTER_MAX).map((item2) => {
1396
1221
  const entry = readMlsDataRecord(item2, ["device", "admissionId"]);
1397
1222
  return Object.freeze({ device: parseMlsDevEnrollmentResult({ version: 1, authorization: "registration_only", device: entry.device }).device, admissionId: id4(entry.admissionId) });
1398
1223
  });
1399
1224
  for (let i = 1; i < values.length; i++)
1400
1225
  if (values[i - 1].device.deviceId >= values[i].device.deviceId)
1401
- invalid8();
1226
+ invalid7();
1402
1227
  return Object.freeze(values);
1403
1228
  });
1404
1229
  }
1405
1230
  __name(parseMlsDevGroupRoster, "parseMlsDevGroupRoster");
1406
1231
  var MLS_DEV_ROOM_REMOVAL_DEADLINE_MS = 72 * 60 * 60 * 1e3;
1407
1232
  function parseMlsDevRoomRemoval(value) {
1408
- return boundary7(() => {
1233
+ return boundary6(() => {
1409
1234
  const input = readMlsDataRecord(value, ["version", "status", "pending", "closedAtMs"]), devices = /* @__PURE__ */ new Set(), principals = /* @__PURE__ */ new Set();
1410
- const status = ["pending", "closing", "closed"].includes(input.status) ? input.status : invalid8();
1235
+ const status = ["pending", "closing", "closed"].includes(input.status) ? input.status : invalid7();
1411
1236
  const pending = array3(input.pending, MLS_DEV_GROUP_ROSTER_MAX).map((item2) => {
1412
1237
  const entry = readMlsDataRecord(item2, ["principalId", "deviceIds", "deadlineAtMs"]);
1413
1238
  const principalId2 = parseMlsDevEnrollmentPrincipal({ type: "human", id: entry.principalId }).id;
1414
1239
  const deviceIds = array3(entry.deviceIds, MLS_DEV_GROUP_ROSTER_MAX).map(requireMlsUuid);
1415
- if (principals.has(principalId2)) invalid8();
1240
+ if (principals.has(principalId2)) invalid7();
1416
1241
  principals.add(principalId2);
1417
1242
  for (const deviceId of deviceIds) {
1418
- if (devices.has(deviceId)) invalid8();
1243
+ if (devices.has(deviceId)) invalid7();
1419
1244
  devices.add(deviceId);
1420
1245
  }
1421
1246
  return Object.freeze({ principalId: principalId2, deviceIds: Object.freeze(deviceIds), deadlineAtMs: requireMlsInteger(entry.deadlineAtMs, 1) });
1422
1247
  });
1423
1248
  const closedAtMs = input.closedAtMs === null ? null : requireMlsInteger(input.closedAtMs, 1);
1424
- if (status === "pending" ? !pending.length || closedAtMs !== null : closedAtMs === null || status === "closed" && pending.length) invalid8();
1249
+ if (status === "pending" ? !pending.length || closedAtMs !== null : closedAtMs === null || status === "closed" && pending.length) invalid7();
1425
1250
  return Object.freeze({ version: requireMlsLiteral(input.version, 1), status, pending: Object.freeze(pending), closedAtMs });
1426
1251
  });
1427
1252
  }
1428
1253
  __name(parseMlsDevRoomRemoval, "parseMlsDevRoomRemoval");
1429
1254
  function parseMlsDevGroupPreconditions(value) {
1430
- return boundary7(() => {
1255
+ return boundary6(() => {
1431
1256
  const input = readMlsDataRecord(value, ["membershipRevision", "admissionId", "targetAdmissionId"]);
1432
1257
  return Object.freeze({
1433
1258
  membershipRevision: requireMlsInteger(input.membershipRevision),
@@ -1456,33 +1281,33 @@ var unsignedFields = [
1456
1281
  ];
1457
1282
  function unsigned(input) {
1458
1283
  if (typeof input.kind !== "string" || !["create", "add", "remove"].includes(input.kind))
1459
- invalid8();
1284
+ invalid7();
1460
1285
  const kind = input.kind;
1461
1286
  const senderCredential = token(input.senderCredential), sender = parseMlsDevCredentialToken(senderCredential).unsigned.claims.device;
1462
1287
  const expectedHead = input.expectedHead === null ? null : parseMlsDevGroupHead(input.expectedHead);
1463
1288
  const epoch = requireMlsInteger(input.epoch), preconditions = parseMlsDevGroupPreconditions(input.preconditions), roster = parseMlsDevGroupRoster(input.roster);
1464
1289
  const environmentId = requireMlsEnvironmentId(input.environmentId);
1465
1290
  if (sender.environmentId !== environmentId || roster.some((entry) => entry.device.environmentId !== environmentId))
1466
- invalid8();
1291
+ invalid7();
1467
1292
  const groupInfo = input.groupInfo === null ? null : wire2(input.groupInfo), commit = input.commit === null ? null : wire2(input.commit);
1468
1293
  const welcome = input.welcome === null ? null : wire2(input.welcome);
1469
1294
  const keyPackageClaim = input.keyPackageClaim === null ? null : parseMlsDevKeyPackageClaimReceipt(input.keyPackageClaim);
1470
1295
  const removedDeviceId = input.removedDeviceId === null ? null : requireMlsUuid(input.removedDeviceId);
1471
1296
  const own = roster.find((entry) => entry.device.deviceId === sender.deviceId);
1472
1297
  if (!own || JSON.stringify(own.device) !== JSON.stringify(sender) || own.admissionId !== preconditions.admissionId)
1473
- invalid8();
1298
+ invalid7();
1474
1299
  if (kind === "create") {
1475
1300
  if (expectedHead !== null || epoch !== 0 || roster.length !== 1 || !groupInfo || commit !== null || welcome !== null || keyPackageClaim !== null || removedDeviceId !== null || preconditions.targetAdmissionId !== null)
1476
- invalid8();
1301
+ invalid7();
1477
1302
  } else {
1478
1303
  if (!expectedHead || expectedHead.sequence >= Number.MAX_SAFE_INTEGER || expectedHead.epoch >= Number.MAX_SAFE_INTEGER || epoch !== expectedHead.epoch + 1 || !commit || preconditions.targetAdmissionId === null)
1479
- invalid8();
1304
+ invalid7();
1480
1305
  if (kind === "add") {
1481
1306
  const target = roster.find((entry) => entry.device.deviceId === keyPackageClaim?.recipientDeviceId);
1482
1307
  if (!welcome || !keyPackageClaim || removedDeviceId !== null || !target || keyPackageClaim.claimantDeviceId !== sender.deviceId || keyPackageClaim.preconditions.conversationId !== input.conversationId || keyPackageClaim.preconditions.membershipRevision !== preconditions.membershipRevision || keyPackageClaim.preconditions.admissionId !== preconditions.admissionId || keyPackageClaim.preconditions.targetAdmissionId !== preconditions.targetAdmissionId || target.admissionId !== preconditions.targetAdmissionId)
1483
- invalid8();
1308
+ invalid7();
1484
1309
  } else if (!removedDeviceId || removedDeviceId === sender.deviceId || roster.some((entry) => entry.device.deviceId === removedDeviceId) || welcome !== null || keyPackageClaim !== null)
1485
- invalid8();
1310
+ invalid7();
1486
1311
  }
1487
1312
  return bounded5({
1488
1313
  version: requireMlsLiteral(input.version, 1),
@@ -1504,21 +1329,21 @@ function unsigned(input) {
1504
1329
  }
1505
1330
  __name(unsigned, "unsigned");
1506
1331
  function parseMlsDevGroupControl(value) {
1507
- return boundary7(() => {
1332
+ return boundary6(() => {
1508
1333
  const input = readMlsDataRecord(value, [...unsignedFields, "proof"]);
1509
1334
  return bounded5({ ...unsigned(input), proof: encoded4(input.proof, 64) });
1510
1335
  });
1511
1336
  }
1512
1337
  __name(parseMlsDevGroupControl, "parseMlsDevGroupControl");
1513
1338
  function parseMlsDevGroupAcceptedControl(value) {
1514
- return boundary7(() => {
1339
+ return boundary6(() => {
1515
1340
  const input = readMlsDataRecord(value, ["version", "authorization", "operationId", "control", "head", "acceptedAtMs", "membershipRevision"]);
1516
1341
  const control = parseMlsDevGroupControl(input.control), head = parseMlsDevGroupHead(input.head);
1517
1342
  if (head.sequence !== (control.expectedHead?.sequence ?? 0) + 1 || head.epoch !== control.epoch)
1518
- invalid8();
1343
+ invalid7();
1519
1344
  const membershipRevision = requireMlsInteger(input.membershipRevision);
1520
1345
  if (membershipRevision !== control.preconditions.membershipRevision && !(control.kind === "remove" && membershipRevision === control.preconditions.membershipRevision + 1))
1521
- invalid8();
1346
+ invalid7();
1522
1347
  return bounded5({
1523
1348
  version: requireMlsLiteral(input.version, 1),
1524
1349
  authorization: requireMlsLiteral(input.authorization, "group_control_only"),
@@ -1532,20 +1357,20 @@ function parseMlsDevGroupAcceptedControl(value) {
1532
1357
  }
1533
1358
  __name(parseMlsDevGroupAcceptedControl, "parseMlsDevGroupAcceptedControl");
1534
1359
  function parseMlsDevGroupAdmissionsResult(value) {
1535
- return boundary7(() => {
1360
+ return boundary6(() => {
1536
1361
  const input = readMlsDataRecord(value, ["version", "conversationId", "membershipRevision", "candidates", "waitingPrincipalIds"]);
1537
1362
  const candidates = array3(input.candidates, MLS_DEV_GROUP_ADMISSION_MAX_CANDIDATES).map((raw) => {
1538
1363
  const entry = readMlsDataRecord(raw, ["principal", "deviceId", "targetAdmissionId"]), principal2 = readMlsDataRecord(entry.principal, ["type", "id"]);
1539
- if (principal2.type !== "human" && principal2.type !== "ai_agent") invalid8();
1364
+ if (principal2.type !== "human" && principal2.type !== "ai_agent") invalid7();
1540
1365
  return Object.freeze({
1541
1366
  principal: Object.freeze({ type: principal2.type, id: id4(principal2.id) }),
1542
1367
  deviceId: requireMlsUuid(entry.deviceId),
1543
1368
  targetAdmissionId: id4(entry.targetAdmissionId)
1544
1369
  });
1545
1370
  });
1546
- if (new Set(candidates.map((entry) => entry.deviceId)).size !== candidates.length) invalid8();
1371
+ if (new Set(candidates.map((entry) => entry.deviceId)).size !== candidates.length) invalid7();
1547
1372
  const waiting = array3(input.waitingPrincipalIds, 32).map(id4);
1548
- if (new Set(waiting).size !== waiting.length) invalid8();
1373
+ if (new Set(waiting).size !== waiting.length) invalid7();
1549
1374
  return bounded5(Object.freeze({
1550
1375
  version: requireMlsLiteral(input.version, 1),
1551
1376
  conversationId: id4(input.conversationId),
@@ -1557,11 +1382,11 @@ function parseMlsDevGroupAdmissionsResult(value) {
1557
1382
  }
1558
1383
  __name(parseMlsDevGroupAdmissionsResult, "parseMlsDevGroupAdmissionsResult");
1559
1384
  function parseMlsDevGroupQuery(value) {
1560
- return boundary7(() => {
1385
+ return boundary6(() => {
1561
1386
  const input = readMlsDataRecord(value, ["version", "conversationId", "credential", "afterSequence", "limit"]);
1562
1387
  const limit2 = requireMlsInteger(input.limit, 1);
1563
1388
  if (limit2 > MLS_DEV_GROUP_QUERY_MAX_CONTROLS)
1564
- invalid8();
1389
+ invalid7();
1565
1390
  return bounded5({
1566
1391
  version: requireMlsLiteral(input.version, 1),
1567
1392
  conversationId: id4(input.conversationId),
@@ -1573,17 +1398,17 @@ function parseMlsDevGroupQuery(value) {
1573
1398
  }
1574
1399
  __name(parseMlsDevGroupQuery, "parseMlsDevGroupQuery");
1575
1400
  function parseMlsDevGroupQueryResult(value) {
1576
- return boundary7(() => {
1401
+ return boundary6(() => {
1577
1402
  const input = readMlsDataRecord(value, ["version", "conversationId", "marker", "membershipRevision", "admissionId", "roster", "controls", "nextSequence", "hasMore", "terminal"]);
1578
1403
  const conversationId = id4(input.conversationId), marker = input.marker === null ? null : parseMlsDevGroupMarker(input.marker);
1579
1404
  const controls = array3(input.controls, MLS_DEV_GROUP_QUERY_MAX_CONTROLS).map(parseMlsDevGroupAcceptedControl);
1580
1405
  const nextSequence = requireMlsInteger(input.nextSequence), terminal = boolean3(input.terminal), hasMore = boolean3(input.hasMore);
1581
1406
  for (let i = 0; i < controls.length; i++) {
1582
1407
  if (!marker || controls[i].control.conversationId !== conversationId || controls[i].control.groupId !== marker.groupId || controls[i].head.sequence > marker.head.sequence || i > 0 && controls[i].head.sequence !== controls[i - 1].head.sequence + 1)
1583
- invalid8();
1408
+ invalid7();
1584
1409
  }
1585
1410
  if (controls.length && controls.at(-1).head.sequence !== nextSequence || marker && nextSequence > marker.head.sequence || !marker && (controls.length || nextSequence || terminal || hasMore))
1586
- invalid8();
1411
+ invalid7();
1587
1412
  return bounded5({
1588
1413
  version: requireMlsLiteral(input.version, 1),
1589
1414
  conversationId,
@@ -1600,11 +1425,11 @@ function parseMlsDevGroupQueryResult(value) {
1600
1425
  }
1601
1426
  __name(parseMlsDevGroupQueryResult, "parseMlsDevGroupQueryResult");
1602
1427
  function parseMlsDevGroupContext(value) {
1603
- return boundary7(() => {
1428
+ return boundary6(() => {
1604
1429
  const input = readMlsDataRecord(value, ["version", "environmentId", "conversationId", "groupId", "deviceId", "installationId", "revision"], ["version", "environmentId", "conversationId", "groupId", "deviceId", "installationId", "revision", "protocol"]);
1605
1430
  const revision2 = requireMlsInteger(input.revision);
1606
1431
  if (revision2 >= Number.MAX_SAFE_INTEGER)
1607
- invalid8();
1432
+ invalid7();
1608
1433
  return Object.freeze({
1609
1434
  version: requireMlsLiteral(input.version, 1),
1610
1435
  environmentId: requireMlsEnvironmentId(input.environmentId),
@@ -1619,17 +1444,17 @@ function parseMlsDevGroupContext(value) {
1619
1444
  }
1620
1445
  __name(parseMlsDevGroupContext, "parseMlsDevGroupContext");
1621
1446
  function parseMlsDevGroupCommand(value) {
1622
- return boundary7(() => {
1447
+ return boundary6(() => {
1623
1448
  if (!value || typeof value !== "object")
1624
- invalid8();
1449
+ invalid7();
1625
1450
  const descriptor = Object.getOwnPropertyDescriptor(value, "op");
1626
1451
  if (!descriptor || !Object.hasOwn(descriptor, "value"))
1627
- invalid8();
1452
+ invalid7();
1628
1453
  const op = descriptor.value;
1629
1454
  if (op === "process_application") {
1630
1455
  const input2 = readMlsDataRecord(value, ["op", "entry"]), entry = parseMlsDevGroupFeedEntry(input2.entry);
1631
1456
  if (entry.kind !== "application" || !entry.receiptProof)
1632
- invalid8();
1457
+ invalid7();
1633
1458
  return bounded5({ op, entry });
1634
1459
  }
1635
1460
  if (op === "encrypt_text") {
@@ -1688,23 +1513,23 @@ function parseMlsDevGroupCommand(value) {
1688
1513
  let seal = null;
1689
1514
  if (interaction.role === "request") {
1690
1515
  if (Object.hasOwn(body, "secretKey") || input2.seal !== null)
1691
- invalid8();
1516
+ invalid7();
1692
1517
  const parsed = parseMlsDevInteractionRequestBody(interaction.kind === "secret" ? { ...body, secretKey: { kem: "x25519", publicKey: "A".repeat(43) } } : body);
1693
1518
  if (parsed.requestId !== interaction.requestId || parsed.kind !== interaction.kind || parsed.expiresAtMs !== interaction.expiresAtMs || parsed.responderIds[0] !== interaction.responderIds[0])
1694
- invalid8();
1519
+ invalid7();
1695
1520
  } else if (interaction.role === "response") {
1696
1521
  if (input2.seal === null) {
1697
1522
  const parsed = parseMlsDevInteractionResponseBody(body);
1698
1523
  if (parsed.requestId !== interaction.requestId || parsed.agentId !== interaction.agentId || "sealed" in parsed.answer)
1699
- invalid8();
1524
+ invalid7();
1700
1525
  } else {
1701
1526
  const fields3 = readMlsDataRecord(input2.seal, ["text", "publicKey", "requesterDeviceId"]), ids2 = readMlsDataRecord(body, ["requestId", "agentId"]);
1702
1527
  if (ids2.requestId !== interaction.requestId || ids2.agentId !== interaction.agentId || typeof fields3.text !== "string" || !fields3.text.trim() || [...fields3.text].length > MLS_DEV_INTERACTION_LIMITS.text || utf84.encode(fields3.text).length > MLS_DEV_SECRET_ANSWER_MAX_BYTES - 16 || new TextDecoder("utf-8", { fatal: true }).decode(utf84.encode(fields3.text)) !== fields3.text)
1703
- invalid8();
1528
+ invalid7();
1704
1529
  seal = Object.freeze({ text: fields3.text, publicKey: encoded4(fields3.publicKey, 32), requesterDeviceId: requireMlsUuid(fields3.requesterDeviceId) });
1705
1530
  }
1706
1531
  } else if (input2.seal !== null || parseMlsDevInteractionWithdrawBody(body).requestId !== interaction.requestId)
1707
- invalid8();
1532
+ invalid7();
1708
1533
  const ids = parseMlsDevTextPayload({
1709
1534
  version: 1,
1710
1535
  kind: "text",
@@ -1716,7 +1541,7 @@ function parseMlsDevGroupCommand(value) {
1716
1541
  text: "x"
1717
1542
  });
1718
1543
  if (utf84.encode(JSON.stringify(body)).length > MLS_DEV_TEXT_MAX_BYTES)
1719
- invalid8();
1544
+ invalid7();
1720
1545
  return bounded5({
1721
1546
  op,
1722
1547
  operationId: ids.operationId,
@@ -1758,7 +1583,7 @@ function parseMlsDevGroupCommand(value) {
1758
1583
  };
1759
1584
  if (op === "join") {
1760
1585
  if (common2.accepted.control.kind !== "add")
1761
- invalid8();
1586
+ invalid7();
1762
1587
  return bounded5({ op, ...common2, keyPackageId: requireMlsUuid(input2.keyPackageId) });
1763
1588
  }
1764
1589
  return bounded5({ op, ...common2 });
@@ -1768,11 +1593,11 @@ function parseMlsDevGroupCommand(value) {
1768
1593
  const fields2 = { operationId: id4(input.operationId), credential: token(input.credential), preconditions: parseMlsDevGroupPreconditions(input.preconditions) };
1769
1594
  if (op === "create") {
1770
1595
  if (fields2.preconditions.targetAdmissionId !== null)
1771
- invalid8();
1596
+ invalid7();
1772
1597
  return bounded5({ op, ...fields2 });
1773
1598
  }
1774
1599
  if (fields2.preconditions.targetAdmissionId === null)
1775
- invalid8();
1600
+ invalid7();
1776
1601
  const expectedHead = parseMlsDevGroupHead(input.expectedHead);
1777
1602
  if (op === "add")
1778
1603
  return bounded5({
@@ -1788,24 +1613,24 @@ function parseMlsDevGroupCommand(value) {
1788
1613
  expectedHead,
1789
1614
  removedDeviceId: requireMlsUuid(input.removedDeviceId)
1790
1615
  });
1791
- return invalid8();
1616
+ return invalid7();
1792
1617
  });
1793
1618
  }
1794
1619
  __name(parseMlsDevGroupCommand, "parseMlsDevGroupCommand");
1795
1620
  function parseMlsDevGroupPreparation(value) {
1796
- return boundary7(() => {
1621
+ return boundary6(() => {
1797
1622
  const input = readMlsDataRecord(value, ["wrappedState", "payload"]);
1798
1623
  if (typeof input.wrappedState !== "string" || input.wrappedState.length > MLS_DEV_GROUP_WRAPPED_MAX_BYTES || !input.wrappedState.startsWith("v1:"))
1799
- invalid8();
1624
+ invalid7();
1800
1625
  const body = input.wrappedState.slice(3);
1801
1626
  if (body.length < 40 || body.length % 4 !== 0 || !/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(body))
1802
- invalid8();
1627
+ invalid7();
1803
1628
  const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1804
1629
  if (body.endsWith("==") && (alphabet.indexOf(body.at(-3)) & 15) !== 0 || !body.endsWith("==") && body.endsWith("=") && (alphabet.indexOf(body.at(-2)) & 3) !== 0)
1805
- invalid8();
1630
+ invalid7();
1806
1631
  const kind = Object.getOwnPropertyDescriptor(input.payload ?? {}, "kind");
1807
1632
  if (!kind || !Object.hasOwn(kind, "value"))
1808
- invalid8();
1633
+ invalid7();
1809
1634
  let payload;
1810
1635
  if (kind.value === "application") {
1811
1636
  const fields2 = readMlsDataRecord(input.payload, ["kind", "envelope", ...present(input.payload, ["payload"])]);
@@ -1861,7 +1686,7 @@ function parseMlsDevGroupPreparation(value) {
1861
1686
  const fields2 = readMlsDataRecord(input.payload, ["kind", "envelope", "payload"]);
1862
1687
  payload = Object.freeze({ kind: "interaction_application", envelope: parseMlsDevApplicationEnvelope(fields2.envelope), payload: plaintextJson(fields2.payload) });
1863
1688
  if (!payload.envelope.interaction)
1864
- invalid8();
1689
+ invalid7();
1865
1690
  } else if (kind.value === "interaction") {
1866
1691
  const fields2 = readMlsDataRecord(input.payload, ["kind", "messageId", "operationId", "senderDeviceId", "payload", "feedOrdinal"]);
1867
1692
  const ids = parseMlsDevTextPayload({
@@ -1905,7 +1730,7 @@ function parseMlsDevGroupPreparation(value) {
1905
1730
  const fields2 = readMlsDataRecord(input.payload, ["kind", "requestId", "text"]);
1906
1731
  const binding3 = parseMlsDevInteractionBinding({ role: "withdraw", requestId: fields2.requestId });
1907
1732
  if (typeof fields2.text !== "string" || !fields2.text.trim() || [...fields2.text].length > MLS_DEV_INTERACTION_LIMITS.text || new TextDecoder("utf-8", { fatal: true }).decode(utf84.encode(fields2.text)) !== fields2.text)
1908
- invalid8();
1733
+ invalid7();
1909
1734
  payload = Object.freeze({ kind: "secret", requestId: binding3.requestId, text: fields2.text });
1910
1735
  } else if (kind.value === "control") {
1911
1736
  const fields2 = readMlsDataRecord(input.payload, ["kind", "control"]);
@@ -1960,27 +1785,27 @@ var MlsDevApplicationValidationError = class extends Error {
1960
1785
  }
1961
1786
  };
1962
1787
  var utf85 = new TextEncoder();
1963
- function invalid9() {
1788
+ function invalid8() {
1964
1789
  throw new MlsDevApplicationValidationError();
1965
1790
  }
1966
- __name(invalid9, "invalid");
1967
- function boundary8(read) {
1791
+ __name(invalid8, "invalid");
1792
+ function boundary7(read) {
1968
1793
  try {
1969
1794
  return read();
1970
1795
  } catch {
1971
- return invalid9();
1796
+ return invalid8();
1972
1797
  }
1973
1798
  }
1974
- __name(boundary8, "boundary");
1799
+ __name(boundary7, "boundary");
1975
1800
  function bounded6(value) {
1976
1801
  if (utf85.encode(JSON.stringify(value)).length > MLS_DEV_APPLICATION_MAX_BYTES)
1977
- invalid9();
1802
+ invalid8();
1978
1803
  return Object.freeze(value);
1979
1804
  }
1980
1805
  __name(bounded6, "bounded");
1981
1806
  function id5(value) {
1982
1807
  if (typeof value !== "string" || !/^[A-Za-z0-9_.:~-]{1,200}$/.test(value) || value === "." || value === "..")
1983
- invalid9();
1808
+ invalid8();
1984
1809
  return value;
1985
1810
  }
1986
1811
  __name(id5, "id");
@@ -1990,31 +1815,31 @@ function isMlsDevMessageId(value) {
1990
1815
  __name(isMlsDevMessageId, "isMlsDevMessageId");
1991
1816
  function messageId(value) {
1992
1817
  if (!isMlsDevMessageId(value))
1993
- invalid9();
1818
+ invalid8();
1994
1819
  return value;
1995
1820
  }
1996
1821
  __name(messageId, "messageId");
1997
1822
  function interactionId2(value) {
1998
1823
  if (typeof value !== "string" || !MLS_DEV_INTERACTION_ID_PATTERN.test(value) || value === "." || value === "..")
1999
- invalid9();
1824
+ invalid8();
2000
1825
  return value;
2001
1826
  }
2002
1827
  __name(interactionId2, "interactionId");
2003
1828
  function parseMlsDevInteractionBinding(value) {
2004
- return boundary8(() => {
1829
+ return boundary7(() => {
2005
1830
  const role = value && typeof value === "object" ? Object.getOwnPropertyDescriptor(value, "role") : void 0;
2006
1831
  if (!role || !Object.hasOwn(role, "value"))
2007
- invalid9();
1832
+ invalid8();
2008
1833
  if (role.value === "request") {
2009
1834
  const input2 = readMlsDataRecord(value, ["role", "requestId", "kind", "responderIds", "expiresAtMs"]);
2010
1835
  if (typeof input2.kind !== "string" || !MLS_DEV_INTERACTION_KINDS.includes(input2.kind))
2011
- invalid9();
1836
+ invalid8();
2012
1837
  const responders = input2.responderIds;
2013
1838
  if (!Array.isArray(responders) || Object.getPrototypeOf(responders) !== Array.prototype || responders.length !== 1 || Reflect.ownKeys(Object.getOwnPropertyDescriptors(responders)).length !== 2)
2014
- invalid9();
1839
+ invalid8();
2015
1840
  const only = Object.getOwnPropertyDescriptor(responders, 0);
2016
1841
  if (!only || !only.enumerable || !Object.hasOwn(only, "value"))
2017
- invalid9();
1842
+ invalid8();
2018
1843
  const expiresAtMs = requireMlsInteger(input2.expiresAtMs, 1);
2019
1844
  return Object.freeze({
2020
1845
  role: "request",
@@ -2039,21 +1864,21 @@ function encoded5(value, bytes) {
2039
1864
  }
2040
1865
  __name(encoded5, "encoded");
2041
1866
  function parseMlsDevApplicationWire(value) {
2042
- return boundary8(() => {
1867
+ return boundary7(() => {
2043
1868
  if (typeof value !== "string" || value.length < 2 || value.length > Math.ceil(MLS_DEV_APPLICATION_TLS_MAX_BYTES * 4 / 3))
2044
- invalid9();
1869
+ invalid8();
2045
1870
  const bytes = Math.floor(value.length * 3 / 4);
2046
1871
  if (bytes > MLS_DEV_APPLICATION_TLS_MAX_BYTES || value.length !== Math.ceil(bytes * 4 / 3) || !/^[A-Za-z0-9_-]+$/.test(value))
2047
- invalid9();
1872
+ invalid8();
2048
1873
  const last = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".indexOf(value.at(-1));
2049
1874
  if (value.length % 4 === 2 && (last & 15) !== 0 || value.length % 4 === 3 && (last & 3) !== 0)
2050
- invalid9();
1875
+ invalid8();
2051
1876
  return value;
2052
1877
  });
2053
1878
  }
2054
1879
  __name(parseMlsDevApplicationWire, "parseMlsDevApplicationWire");
2055
1880
  function parseMlsDevApplicationPreconditions(value) {
2056
- return boundary8(() => {
1881
+ return boundary7(() => {
2057
1882
  const input = readMlsDataRecord(value, ["membershipRevision", "admissionId"]);
2058
1883
  return Object.freeze({ membershipRevision: requireMlsInteger(input.membershipRevision), admissionId: id5(input.admissionId) });
2059
1884
  });
@@ -2063,7 +1888,7 @@ var bindingFields = ["version", "environmentId", "conversationId", "groupId", "m
2063
1888
  var interactionBindingFields = [...bindingFields, "interaction"];
2064
1889
  function binding(input) {
2065
1890
  const environmentId = requireMlsEnvironmentId(input.environmentId);
2066
- if (parseMlsDevCredentialToken(input.senderCredential).unsigned.claims.device.environmentId !== environmentId) invalid9();
1891
+ if (parseMlsDevCredentialToken(input.senderCredential).unsigned.claims.device.environmentId !== environmentId) invalid8();
2067
1892
  return {
2068
1893
  version: requireMlsLiteral(input.version, 1),
2069
1894
  environmentId,
@@ -2082,14 +1907,14 @@ function fields(value, extra) {
2082
1907
  }
2083
1908
  __name(fields, "fields");
2084
1909
  function parseMlsDevApplicationEnvelope(value) {
2085
- return boundary8(() => {
1910
+ return boundary7(() => {
2086
1911
  const input = fields(value, ["ciphertext", "proof"]);
2087
1912
  return bounded6({ ...binding(input), ciphertext: parseMlsDevApplicationWire(input.ciphertext), proof: encoded5(input.proof, 64) });
2088
1913
  });
2089
1914
  }
2090
1915
  __name(parseMlsDevApplicationEnvelope, "parseMlsDevApplicationEnvelope");
2091
1916
  function parseMlsDevApplicationReceipt(value) {
2092
- return boundary8(() => {
1917
+ return boundary7(() => {
2093
1918
  const input = readMlsDataRecord(value, ["version", "authorization", "operationId", "conversationId", "groupId", "messageId", "feedOrdinal", "head", "acceptedAtMs", "envelopeHash"]);
2094
1919
  return bounded6({
2095
1920
  version: requireMlsLiteral(input.version, 1),
@@ -2108,7 +1933,7 @@ function parseMlsDevApplicationReceipt(value) {
2108
1933
  __name(parseMlsDevApplicationReceipt, "parseMlsDevApplicationReceipt");
2109
1934
  function text2(value) {
2110
1935
  if (typeof value !== "string" || !value.trim() || utf85.encode(value).length > MLS_DEV_TEXT_MAX_BYTES || new TextDecoder("utf-8", { fatal: true }).decode(utf85.encode(value)) !== value)
2111
- invalid9();
1936
+ invalid8();
2112
1937
  return value;
2113
1938
  }
2114
1939
  __name(text2, "text");
@@ -2117,13 +1942,13 @@ function textExtras2(value) {
2117
1942
  if (Object.hasOwn(value, "replyTo")) {
2118
1943
  const reply = readMlsDataRecord(value.replyTo, ["messageId", "quote"]);
2119
1944
  if ([...text2(reply.quote)].length > MLS_DEV_REPLY_QUOTE_MAX_CHARACTERS)
2120
- invalid9();
1945
+ invalid8();
2121
1946
  extras.replyTo = Object.freeze({ messageId: messageId(reply.messageId), quote: reply.quote });
2122
1947
  }
2123
1948
  if (Object.hasOwn(value, "mentions")) {
2124
1949
  const mentions = value.mentions;
2125
1950
  if (!Array.isArray(mentions) || mentions.length < 1 || mentions.length > MLS_DEV_MENTIONS_MAX || new Set(mentions).size !== mentions.length)
2126
- invalid9();
1951
+ invalid8();
2127
1952
  extras.mentions = Object.freeze(mentions.map(id5));
2128
1953
  }
2129
1954
  return extras;
@@ -2131,7 +1956,7 @@ function textExtras2(value) {
2131
1956
  __name(textExtras2, "textExtras");
2132
1957
  var optionalKeys = /* @__PURE__ */ __name((value, keys2) => value && typeof value === "object" ? keys2.filter((key) => Object.hasOwn(value, key)) : [], "optionalKeys");
2133
1958
  function parseMlsDevTextPayload(value) {
2134
- return boundary8(() => {
1959
+ return boundary7(() => {
2135
1960
  const input = readMlsDataRecord(value, ["version", "kind", "conversationId", "groupId", "messageId", "operationId", "senderDeviceId", "text", ...optionalKeys(value, ["replyTo", "mentions"])]);
2136
1961
  return bounded6({
2137
1962
  version: requireMlsLiteral(input.version, 1),
@@ -2149,19 +1974,19 @@ function parseMlsDevTextPayload(value) {
2149
1974
  __name(parseMlsDevTextPayload, "parseMlsDevTextPayload");
2150
1975
  var itemFields = ["type", "uploadId", "url", "mimeType", "sizeBytes", "fileName", "width", "height", "durationMs", "thumbnailUrl", "caption", "replyTo", "mentions"];
2151
1976
  function httpsUrl(value) {
2152
- if (typeof value !== "string" || value.length > 2048) invalid9();
2153
- const url = boundary8(() => new URL(value));
2154
- if (url.protocol !== "https:" || url.username || url.password) invalid9();
1977
+ if (typeof value !== "string" || value.length > 2048) invalid8();
1978
+ const url = boundary7(() => new URL(value));
1979
+ if (url.protocol !== "https:" || url.username || url.password) invalid8();
2155
1980
  return value;
2156
1981
  }
2157
1982
  __name(httpsUrl, "httpsUrl");
2158
- var dimension = /* @__PURE__ */ __name((value) => requireMlsInteger(value, 0) <= 1e5 ? value : invalid9(), "dimension");
1983
+ var dimension = /* @__PURE__ */ __name((value) => requireMlsInteger(value, 0) <= 1e5 ? value : invalid8(), "dimension");
2159
1984
  function item(value) {
2160
1985
  const input = readMlsDataRecord(value, ["type", "uploadId", "url", "mimeType", "sizeBytes", ...optionalKeys(value, itemFields.slice(5))]);
2161
1986
  if (!MLS_DEV_ITEM_TYPES.some((type) => type === input.type) || typeof input.mimeType !== "string" || !/^[a-z0-9.+-]{1,64}\/[a-z0-9.+-]{1,128}$/i.test(input.mimeType))
2162
- invalid9();
1987
+ invalid8();
2163
1988
  if (input.fileName !== void 0 && (typeof input.fileName !== "string" || !input.fileName.trim() || [...input.fileName].length > 240))
2164
- invalid9();
1989
+ invalid8();
2165
1990
  return Object.freeze({
2166
1991
  type: input.type,
2167
1992
  uploadId: requireMlsUuid(input.uploadId),
@@ -2177,7 +2002,7 @@ function item(value) {
2177
2002
  }
2178
2003
  __name(item, "item");
2179
2004
  function parseMlsDevItemPayload(value) {
2180
- return boundary8(() => {
2005
+ return boundary7(() => {
2181
2006
  const input = readMlsDataRecord(value, ["version", "kind", "conversationId", "groupId", "messageId", "operationId", "senderDeviceId", "item"]);
2182
2007
  const payload = {
2183
2008
  version: requireMlsLiteral(input.version, 1),
@@ -2190,7 +2015,7 @@ function parseMlsDevItemPayload(value) {
2190
2015
  item: item(input.item)
2191
2016
  };
2192
2017
  if (utf85.encode(JSON.stringify(payload)).length > MLS_DEV_TEXT_MAX_BYTES)
2193
- invalid9();
2018
+ invalid8();
2194
2019
  return bounded6(payload);
2195
2020
  });
2196
2021
  }
@@ -2212,9 +2037,408 @@ function framed(domain4, value, operationId) {
2212
2037
  }
2213
2038
  __name(framed, "framed");
2214
2039
  function encodeMlsDevApplicationEnvelopeHash(value, operationId) {
2215
- return boundary8(() => framed("canon.mls.dev-application-envelope.v1\0", parseMlsDevApplicationEnvelope(value), operationId));
2040
+ return boundary7(() => framed("canon.mls.dev-application-envelope.v1\0", parseMlsDevApplicationEnvelope(value), operationId));
2041
+ }
2042
+ __name(encodeMlsDevApplicationEnvelopeHash, "encodeMlsDevApplicationEnvelopeHash");
2043
+
2044
+ // ../backend-contracts/src/mlsDevFeedReceipt.ts
2045
+ var MlsDevFeedReceiptValidationError = class extends Error {
2046
+ static {
2047
+ __name(this, "MlsDevFeedReceiptValidationError");
2048
+ }
2049
+ code = "INVALID_MLS_DEV_FEED_RECEIPT";
2050
+ constructor() {
2051
+ super("INVALID_MLS_DEV_FEED_RECEIPT");
2052
+ this.name = "MlsDevFeedReceiptValidationError";
2053
+ }
2054
+ };
2055
+ function invalid9() {
2056
+ throw new MlsDevFeedReceiptValidationError();
2057
+ }
2058
+ __name(invalid9, "invalid");
2059
+ function boundary8(read) {
2060
+ try {
2061
+ return read();
2062
+ } catch {
2063
+ return invalid9();
2064
+ }
2065
+ }
2066
+ __name(boundary8, "boundary");
2067
+ function parseMlsDevReceiptKeyVersion(value, environmentId) {
2068
+ return boundary8(() => {
2069
+ if (typeof value !== "string" || value.length > 200) invalid9();
2070
+ const owner = mlsEnvironmentOfReceiptKeyVersion(value);
2071
+ if (!owner || environmentId !== void 0 && owner !== environmentId) invalid9();
2072
+ return value;
2073
+ });
2074
+ }
2075
+ __name(parseMlsDevReceiptKeyVersion, "parseMlsDevReceiptKeyVersion");
2076
+ function parseMlsDevFeedReceiptProof(value) {
2077
+ return boundary8(() => {
2078
+ const input = readMlsDataRecord(value, ["keyVersion", "signature"]);
2079
+ decodeCanonicalMlsBase64Url(input.signature, 64);
2080
+ return Object.freeze({ keyVersion: parseMlsDevReceiptKeyVersion(input.keyVersion), signature: input.signature });
2081
+ });
2082
+ }
2083
+ __name(parseMlsDevFeedReceiptProof, "parseMlsDevFeedReceiptProof");
2084
+ var MLS_DEV_GROUP_RECEIPT_CLOCK_SKEW = "MLS_DEV_GROUP_RECEIPT_CLOCK_SKEW";
2085
+ function isMlsDevReceiptClockSkew(value) {
2086
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
2087
+ const keys2 = Object.keys(value).sort().join(), input = value;
2088
+ return (keys2 === "error,ok,retryable" || keys2 === "error,ok,retryable,version" && input.version === 1) && input.ok === false && input.error === MLS_DEV_GROUP_RECEIPT_CLOCK_SKEW && input.retryable === true;
2089
+ }
2090
+ __name(isMlsDevReceiptClockSkew, "isMlsDevReceiptClockSkew");
2091
+
2092
+ // ../backend-contracts/src/mlsDevCredentialReconciliation.ts
2093
+ var MLS_DEV_CREDENTIAL_RECONCILIATION_CHALLENGE_TTL_MS = 3e5;
2094
+ var MLS_DEV_CREDENTIAL_RECONCILIATION_MAX_BYTES = 8192;
2095
+ var MlsDevCredentialReconciliationValidationError = class extends Error {
2096
+ static {
2097
+ __name(this, "MlsDevCredentialReconciliationValidationError");
2098
+ }
2099
+ code = "INVALID_MLS_DEV_CREDENTIAL_RECONCILIATION";
2100
+ constructor() {
2101
+ super("INVALID_MLS_DEV_CREDENTIAL_RECONCILIATION");
2102
+ this.name = "MlsDevCredentialReconciliationValidationError";
2103
+ }
2104
+ };
2105
+ var utf86 = new TextEncoder();
2106
+ var domain2 = utf86.encode("canon.mls.credential-reconciliation-proof.v1\0");
2107
+ function invalid10() {
2108
+ throw new MlsDevCredentialReconciliationValidationError();
2109
+ }
2110
+ __name(invalid10, "invalid");
2111
+ function boundary9(read) {
2112
+ try {
2113
+ return read();
2114
+ } catch {
2115
+ return invalid10();
2116
+ }
2117
+ }
2118
+ __name(boundary9, "boundary");
2119
+ function bounded7(value) {
2120
+ if (utf86.encode(JSON.stringify(value)).length > MLS_DEV_CREDENTIAL_RECONCILIATION_MAX_BYTES) invalid10();
2121
+ return Object.freeze(value);
2122
+ }
2123
+ __name(bounded7, "bounded");
2124
+ function encoded6(value, bytes) {
2125
+ decodeCanonicalMlsBase64Url(value, bytes);
2126
+ return value;
2127
+ }
2128
+ __name(encoded6, "encoded");
2129
+ function parseMlsDevCredentialReconciliationBegin(value) {
2130
+ return boundary9(() => {
2131
+ const input = readMlsDataRecord(value, ["version", "deviceId", "requestId", "expectedCredentialGeneration"]);
2132
+ return bounded7({
2133
+ version: requireMlsLiteral(input.version, 1),
2134
+ deviceId: requireMlsUuid(input.deviceId),
2135
+ requestId: requireMlsUuid(input.requestId),
2136
+ expectedCredentialGeneration: requireMlsInteger(input.expectedCredentialGeneration)
2137
+ });
2138
+ });
2139
+ }
2140
+ __name(parseMlsDevCredentialReconciliationBegin, "parseMlsDevCredentialReconciliationBegin");
2141
+ function parseMlsDevCredentialReconciliationChallenge(value) {
2142
+ return boundary9(() => {
2143
+ const input = readMlsDataRecord(value, [
2144
+ "version",
2145
+ "challengeId",
2146
+ "requestId",
2147
+ "nonce",
2148
+ "device",
2149
+ "expectedCredentialGeneration",
2150
+ "issuedAtMs",
2151
+ "expiresAtMs"
2152
+ ]);
2153
+ const device = parseMlsDevEnrollmentResult({ version: 1, authorization: "registration_only", device: input.device }).device;
2154
+ const issuedAtMs = requireMlsInteger(input.issuedAtMs), expiresAtMs = requireMlsInteger(input.expiresAtMs);
2155
+ if (issuedAtMs < device.registeredAtMs || expiresAtMs - issuedAtMs !== MLS_DEV_CREDENTIAL_RECONCILIATION_CHALLENGE_TTL_MS) invalid10();
2156
+ return bounded7({
2157
+ version: requireMlsLiteral(input.version, 1),
2158
+ challengeId: requireMlsUuid(input.challengeId),
2159
+ requestId: requireMlsUuid(input.requestId),
2160
+ nonce: encoded6(input.nonce, 32),
2161
+ device,
2162
+ expectedCredentialGeneration: requireMlsInteger(input.expectedCredentialGeneration),
2163
+ issuedAtMs,
2164
+ expiresAtMs
2165
+ });
2166
+ });
2167
+ }
2168
+ __name(parseMlsDevCredentialReconciliationChallenge, "parseMlsDevCredentialReconciliationChallenge");
2169
+ function parseMlsDevCredentialReconciliationComplete(value) {
2170
+ return boundary9(() => {
2171
+ const input = readMlsDataRecord(value, ["version", "challengeId", "proof"]);
2172
+ return bounded7({ version: requireMlsLiteral(input.version, 1), challengeId: requireMlsUuid(input.challengeId), proof: encoded6(input.proof, 64) });
2173
+ });
2174
+ }
2175
+ __name(parseMlsDevCredentialReconciliationComplete, "parseMlsDevCredentialReconciliationComplete");
2176
+ function parseMlsDevCredentialReconciliationReceipt(value) {
2177
+ return boundary9(() => {
2178
+ const input = readMlsDataRecord(value, ["version", "authorization", "challenge", "observedCredentialGeneration", "observedAtMs"]);
2179
+ const challenge = parseMlsDevCredentialReconciliationChallenge(input.challenge);
2180
+ const observedCredentialGeneration = requireMlsInteger(input.observedCredentialGeneration), observedAtMs = requireMlsInteger(input.observedAtMs);
2181
+ if (observedCredentialGeneration < challenge.expectedCredentialGeneration || observedAtMs < challenge.issuedAtMs || observedAtMs >= challenge.expiresAtMs) invalid10();
2182
+ return bounded7({
2183
+ version: requireMlsLiteral(input.version, 1),
2184
+ authorization: requireMlsLiteral(input.authorization, "credential_generation_observation_only"),
2185
+ challenge,
2186
+ observedCredentialGeneration,
2187
+ observedAtMs
2188
+ });
2189
+ });
2190
+ }
2191
+ __name(parseMlsDevCredentialReconciliationReceipt, "parseMlsDevCredentialReconciliationReceipt");
2192
+
2193
+ // ../backend-contracts/src/mlsDevDeviceCustody.ts
2194
+ var MLS_DEV_DEVICE_CONTEXT_MAX_BYTES = 2048;
2195
+ var MLS_DEV_DEVICE_COMMAND_MAX_BYTES = 16384;
2196
+ var MLS_DEV_DEVICE_WRAPPED_STATE_MAX_BYTES = 6144;
2197
+ var MlsDevDeviceCustodyValidationError = class extends Error {
2198
+ static {
2199
+ __name(this, "MlsDevDeviceCustodyValidationError");
2200
+ }
2201
+ code = "INVALID_MLS_DEV_DEVICE_CUSTODY";
2202
+ constructor() {
2203
+ super("INVALID_MLS_DEV_DEVICE_CUSTODY");
2204
+ this.name = "MlsDevDeviceCustodyValidationError";
2205
+ }
2206
+ };
2207
+ var utf87 = new TextEncoder();
2208
+ function invalid11() {
2209
+ throw new MlsDevDeviceCustodyValidationError();
2210
+ }
2211
+ __name(invalid11, "invalid");
2212
+ function boundary10(read) {
2213
+ try {
2214
+ return read();
2215
+ } catch {
2216
+ return invalid11();
2217
+ }
2218
+ }
2219
+ __name(boundary10, "boundary");
2220
+ function bounded8(value, limit2) {
2221
+ if (utf87.encode(JSON.stringify(value)).length > limit2) invalid11();
2222
+ return Object.freeze(value);
2223
+ }
2224
+ __name(bounded8, "bounded");
2225
+ function binding2(input) {
2226
+ return {
2227
+ version: requireMlsLiteral(input.version, 1),
2228
+ environmentId: requireMlsEnvironmentId(input.environmentId),
2229
+ principal: parseMlsDevEnrollmentPrincipal(input.principal),
2230
+ installationId: parseMlsDevInstallationId(input.installationId)
2231
+ };
2232
+ }
2233
+ __name(binding2, "binding");
2234
+ function parseMlsDevDeviceBinding(value) {
2235
+ return boundary10(() => bounded8(binding2(readMlsDataRecord(value, ["version", "environmentId", "principal", "installationId"])), MLS_DEV_DEVICE_CONTEXT_MAX_BYTES));
2236
+ }
2237
+ __name(parseMlsDevDeviceBinding, "parseMlsDevDeviceBinding");
2238
+ function parseMlsDevDeviceContext(value) {
2239
+ return boundary10(() => {
2240
+ const input = readMlsDataRecord(value, ["version", "environmentId", "principal", "installationId", "revision"]);
2241
+ const revision2 = requireMlsInteger(input.revision);
2242
+ if (revision2 >= Number.MAX_SAFE_INTEGER) invalid11();
2243
+ return bounded8({ ...binding2(input), revision: revision2 }, MLS_DEV_DEVICE_CONTEXT_MAX_BYTES);
2244
+ });
2245
+ }
2246
+ __name(parseMlsDevDeviceContext, "parseMlsDevDeviceContext");
2247
+ function parseMlsDevDeviceCommand(value) {
2248
+ return boundary10(() => {
2249
+ if (value === null || typeof value !== "object") invalid11();
2250
+ const descriptor = Object.getOwnPropertyDescriptor(value, "op");
2251
+ if (!descriptor || !Object.hasOwn(descriptor, "value")) invalid11();
2252
+ if (descriptor.value === "create") {
2253
+ const input2 = readMlsDataRecord(value, ["op"]);
2254
+ return Object.freeze({ op: requireMlsLiteral(input2.op, "create") });
2255
+ }
2256
+ if (descriptor.value === "enrollment_proof") {
2257
+ const input2 = readMlsDataRecord(value, ["op", "challenge"]);
2258
+ return bounded8({
2259
+ op: requireMlsLiteral(input2.op, "enrollment_proof"),
2260
+ challenge: parseMlsDevEnrollmentChallenge(input2.challenge)
2261
+ }, MLS_DEV_DEVICE_COMMAND_MAX_BYTES);
2262
+ }
2263
+ if (descriptor.value === "credential_reconciliation_proof") {
2264
+ const input2 = readMlsDataRecord(value, ["op", "challenge", "expectedCredentialGeneration"]);
2265
+ const challenge2 = parseMlsDevCredentialReconciliationChallenge(input2.challenge);
2266
+ const expectedCredentialGeneration2 = requireMlsInteger(input2.expectedCredentialGeneration);
2267
+ if (challenge2.expectedCredentialGeneration !== expectedCredentialGeneration2) invalid11();
2268
+ return bounded8({
2269
+ op: requireMlsLiteral(input2.op, "credential_reconciliation_proof"),
2270
+ challenge: challenge2,
2271
+ expectedCredentialGeneration: expectedCredentialGeneration2
2272
+ }, MLS_DEV_DEVICE_COMMAND_MAX_BYTES);
2273
+ }
2274
+ if (descriptor.value !== "credential_proof") invalid11();
2275
+ const input = readMlsDataRecord(value, ["op", "challenge", "registrationResult", "expectedCredentialGeneration"]);
2276
+ const challenge = parseMlsDevCredentialChallenge(input.challenge);
2277
+ const registrationResult = parseMlsDevEnrollmentResult(input.registrationResult);
2278
+ const expectedCredentialGeneration = requireMlsInteger(input.expectedCredentialGeneration);
2279
+ if (expectedCredentialGeneration >= Number.MAX_SAFE_INTEGER || challenge.credential.claims.generation !== expectedCredentialGeneration + 1 || JSON.stringify(challenge.credential.claims.device) !== JSON.stringify(registrationResult.device)) invalid11();
2280
+ return bounded8({
2281
+ op: requireMlsLiteral(input.op, "credential_proof"),
2282
+ challenge,
2283
+ registrationResult,
2284
+ expectedCredentialGeneration
2285
+ }, MLS_DEV_DEVICE_COMMAND_MAX_BYTES);
2286
+ });
2287
+ }
2288
+ __name(parseMlsDevDeviceCommand, "parseMlsDevDeviceCommand");
2289
+ function encoded7(value, bytes) {
2290
+ decodeCanonicalMlsBase64Url(value, bytes);
2291
+ return value;
2292
+ }
2293
+ __name(encoded7, "encoded");
2294
+ function wrapped(value) {
2295
+ if (typeof value !== "string" || value.length > MLS_DEV_DEVICE_WRAPPED_STATE_MAX_BYTES || !value.startsWith("v1:")) invalid11();
2296
+ const body = value.slice(3);
2297
+ if (body.length < 40 || body.length % 4 !== 0 || !/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(body)) invalid11();
2298
+ const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
2299
+ if (body.endsWith("==") && (alphabet.indexOf(body.at(-3)) & 15) !== 0) invalid11();
2300
+ if (!body.endsWith("==") && body.endsWith("=") && (alphabet.indexOf(body.at(-2)) & 3) !== 0) invalid11();
2301
+ return value;
2302
+ }
2303
+ __name(wrapped, "wrapped");
2304
+ function parseMlsDevDevicePreparation(value, op) {
2305
+ return boundary10(() => {
2306
+ if (!["create", "enrollment_proof", "credential_proof", "credential_reconciliation_proof"].includes(op)) invalid11();
2307
+ const input = readMlsDataRecord(value, ["wrappedState", "payload"]);
2308
+ const payload = readMlsDataRecord(input.payload, op === "create" ? ["signaturePublicKey"] : ["signaturePublicKey", "proof"]);
2309
+ return bounded8({ wrappedState: wrapped(input.wrappedState), payload: Object.freeze({
2310
+ signaturePublicKey: encoded7(payload.signaturePublicKey, 32),
2311
+ ...op === "create" ? {} : { proof: encoded7(payload.proof, 64) }
2312
+ }) }, MLS_DEV_DEVICE_COMMAND_MAX_BYTES);
2313
+ });
2314
+ }
2315
+ __name(parseMlsDevDevicePreparation, "parseMlsDevDevicePreparation");
2316
+
2317
+ // ../backend-contracts/src/upload-mime-types.ts
2318
+ var MIME_TYPE_RE = /^[a-z0-9.+-]+\/[a-z0-9.+-]+$/i;
2319
+ var SAFE_IMAGE_MIME_TYPES = /* @__PURE__ */ new Set([
2320
+ "image/jpeg",
2321
+ "image/png",
2322
+ "image/webp",
2323
+ "image/gif"
2324
+ ]);
2325
+ var SAFE_AUDIO_MIME_TYPES = /* @__PURE__ */ new Set([
2326
+ "audio/mp4",
2327
+ "audio/x-m4a",
2328
+ "audio/mpeg",
2329
+ "audio/webm",
2330
+ "audio/ogg",
2331
+ "audio/wav",
2332
+ // ADTS AAC — the future Android streamable-memo lane; harmless standalone.
2333
+ "audio/aac"
2334
+ ]);
2335
+ var SAFE_VIDEO_MIME_TYPES = /* @__PURE__ */ new Set([
2336
+ "video/mp4",
2337
+ "video/quicktime",
2338
+ "video/webm",
2339
+ "video/x-m4v"
2340
+ ]);
2341
+ var SAFE_FILE_MIME_TYPES = /* @__PURE__ */ new Set([
2342
+ "application/pdf",
2343
+ "text/plain",
2344
+ "text/markdown",
2345
+ "text/x-markdown",
2346
+ "text/csv",
2347
+ "application/csv",
2348
+ "application/json",
2349
+ "application/zip",
2350
+ "application/vnd.ms-excel",
2351
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
2352
+ ]);
2353
+ var SAFE_FILE_MIME_BY_EXTENSION = {
2354
+ csv: "text/csv",
2355
+ json: "application/json",
2356
+ md: "text/markdown",
2357
+ markdown: "text/markdown",
2358
+ pdf: "application/pdf",
2359
+ txt: "text/plain",
2360
+ xls: "application/vnd.ms-excel",
2361
+ xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
2362
+ zip: "application/zip"
2363
+ };
2364
+ var SAFE_VIDEO_MIME_BY_EXTENSION = {
2365
+ m4v: "video/x-m4v",
2366
+ mov: "video/quicktime",
2367
+ mp4: "video/mp4",
2368
+ webm: "video/webm"
2369
+ };
2370
+ var SAFE_AUDIO_MIME_BY_EXTENSION = {
2371
+ aac: "audio/aac",
2372
+ m4a: "audio/x-m4a",
2373
+ mp3: "audio/mpeg",
2374
+ oga: "audio/ogg",
2375
+ ogg: "audio/ogg",
2376
+ wav: "audio/wav"
2377
+ };
2378
+ function normalizeMimeType(value) {
2379
+ if (typeof value !== "string") return null;
2380
+ const normalized = value.split(";")[0].trim().toLowerCase();
2381
+ if (!MIME_TYPE_RE.test(normalized)) return null;
2382
+ if (normalized === "image/jpg") return "image/jpeg";
2383
+ return normalized;
2384
+ }
2385
+ __name(normalizeMimeType, "normalizeMimeType");
2386
+ function inferSafeFileMimeTypeFromName(value) {
2387
+ if (typeof value !== "string") return null;
2388
+ const extension = value.trim().split(/[\\/]/).pop()?.split(".").pop()?.toLowerCase() ?? "";
2389
+ return SAFE_FILE_MIME_BY_EXTENSION[extension] ?? null;
2390
+ }
2391
+ __name(inferSafeFileMimeTypeFromName, "inferSafeFileMimeTypeFromName");
2392
+ function inferSafeVideoMimeTypeFromName(value) {
2393
+ if (typeof value !== "string") return null;
2394
+ const extension = value.trim().split(/[\\/]/).pop()?.split(".").pop()?.toLowerCase() ?? "";
2395
+ return SAFE_VIDEO_MIME_BY_EXTENSION[extension] ?? null;
2396
+ }
2397
+ __name(inferSafeVideoMimeTypeFromName, "inferSafeVideoMimeTypeFromName");
2398
+ function inferSafeAudioMimeTypeFromName(value) {
2399
+ if (typeof value !== "string") return null;
2400
+ const extension = value.trim().split(/[\\/]/).pop()?.split(".").pop()?.toLowerCase() ?? "";
2401
+ return SAFE_AUDIO_MIME_BY_EXTENSION[extension] ?? null;
2402
+ }
2403
+ __name(inferSafeAudioMimeTypeFromName, "inferSafeAudioMimeTypeFromName");
2404
+ function shouldTrustSafeFileName(mimeType) {
2405
+ return !mimeType || mimeType === "application/octet-stream" || mimeType === "application/vnd.ms-excel" || mimeType === "text/plain";
2406
+ }
2407
+ __name(shouldTrustSafeFileName, "shouldTrustSafeFileName");
2408
+ function classifyAllowedUploadMimeType(value) {
2409
+ const mimeType = normalizeMimeType(value);
2410
+ if (!mimeType) return null;
2411
+ if (SAFE_IMAGE_MIME_TYPES.has(mimeType)) return "image";
2412
+ if (SAFE_AUDIO_MIME_TYPES.has(mimeType)) return "audio";
2413
+ if (SAFE_VIDEO_MIME_TYPES.has(mimeType)) return "video";
2414
+ if (SAFE_FILE_MIME_TYPES.has(mimeType)) return "file";
2415
+ return null;
2416
+ }
2417
+ __name(classifyAllowedUploadMimeType, "classifyAllowedUploadMimeType");
2418
+ function resolveAllowedUploadMimeType(input) {
2419
+ const normalizedMimeType = normalizeMimeType(input.mimeType);
2420
+ const hasExplicitMimeType = typeof input.mimeType === "string" && input.mimeType.trim().length > 0;
2421
+ const inferredVideoMimeType = inferSafeVideoMimeTypeFromName(input.fileName);
2422
+ const inferredAudioMimeType = inferSafeAudioMimeTypeFromName(input.fileName);
2423
+ const inferredFileMimeType = inferSafeFileMimeTypeFromName(input.fileName);
2424
+ if (hasExplicitMimeType && !normalizedMimeType) {
2425
+ return null;
2426
+ }
2427
+ if (inferredVideoMimeType && (!normalizedMimeType || normalizedMimeType === "application/octet-stream")) {
2428
+ return inferredVideoMimeType;
2429
+ }
2430
+ if (inferredAudioMimeType && (!normalizedMimeType || normalizedMimeType === "application/octet-stream")) {
2431
+ return inferredAudioMimeType;
2432
+ }
2433
+ if (inferredFileMimeType && shouldTrustSafeFileName(normalizedMimeType)) {
2434
+ return inferredFileMimeType;
2435
+ }
2436
+ if (normalizedMimeType && classifyAllowedUploadMimeType(normalizedMimeType)) {
2437
+ return normalizedMimeType;
2438
+ }
2439
+ return normalizedMimeType ? null : inferredFileMimeType;
2216
2440
  }
2217
- __name(encodeMlsDevApplicationEnvelopeHash, "encodeMlsDevApplicationEnvelopeHash");
2441
+ __name(resolveAllowedUploadMimeType, "resolveAllowedUploadMimeType");
2218
2442
 
2219
2443
  // ../backend-contracts/src/messageText.ts
2220
2444
  var HUMAN_MESSAGE_TEXT_MAX_BYTES = 32 * 1024;
@@ -3681,9 +3905,9 @@ function splitTurnMetadata(metadata) {
3681
3905
  };
3682
3906
  }
3683
3907
  __name(splitTurnMetadata, "splitTurnMetadata");
3684
- function compact(record5) {
3908
+ function compact(record4) {
3685
3909
  const out = {};
3686
- for (const [key, value] of Object.entries(record5)) {
3910
+ for (const [key, value] of Object.entries(record4)) {
3687
3911
  if (value !== void 0) out[key] = value;
3688
3912
  }
3689
3913
  return out;
@@ -3864,12 +4088,12 @@ function parseDirectConversationSelection(value) {
3864
4088
  if (!value || typeof value !== "object" || Array.isArray(value)) {
3865
4089
  throw new Error("selection must be an object");
3866
4090
  }
3867
- const record5 = value;
3868
- if (record5.mode === "latest_or_new" || record5.mode === "new") {
3869
- return { mode: record5.mode };
4091
+ const record4 = value;
4092
+ if (record4.mode === "latest_or_new" || record4.mode === "new") {
4093
+ return { mode: record4.mode };
3870
4094
  }
3871
- if (record5.mode === "specific") {
3872
- const conversationId = typeof record5.conversationId === "string" ? record5.conversationId.trim() : "";
4095
+ if (record4.mode === "specific") {
4096
+ const conversationId = typeof record4.conversationId === "string" ? record4.conversationId.trim() : "";
3873
4097
  if (!conversationId) throw new Error("selection.conversationId is required");
3874
4098
  return { mode: "specific", conversationId };
3875
4099
  }
@@ -4129,6 +4353,7 @@ var ENDPOINT_CONTENT_FUNCTION_QUERIES = [
4129
4353
  "mls_group_controls",
4130
4354
  "mls_group_admissions",
4131
4355
  "mls_interactions",
4356
+ "mls_devices",
4132
4357
  "list_artifacts",
4133
4358
  "get_artifact_log",
4134
4359
  "get_artifact_asset",
@@ -4327,6 +4552,7 @@ var actionRouting = {
4327
4552
  };
4328
4553
  var queryRouting = {
4329
4554
  mls_interactions: ["version", "conversationId"],
4555
+ mls_devices: [],
4330
4556
  list_artifacts: ["conversationId", "cursor", "limit"],
4331
4557
  get_artifact_log: ["conversationId", "artifactId", "afterSequence", "cursor", "limit"],
4332
4558
  get_artifact_asset: ["conversationId", "artifactId", "assetId"],
@@ -4428,8 +4654,8 @@ function endpointOperationRequestRetention(action, body, envelope) {
4428
4654
  __name(endpointOperationRequestRetention, "endpointOperationRequestRetention");
4429
4655
  function endpointContentBoundary(lane, name, payload) {
4430
4656
  if (!namesForLane[lane]?.includes(name)) throw new EndpointContentPolicyError(lane, name);
4431
- const record5 = payload && typeof payload === "object" ? payload : void 0;
4432
- if (lane === "query.request" && name === "get_ephemeral" && record5 && !ENDPOINT_CONTENT_EPHEMERAL_FAMILIES.includes(record5.family)) {
4657
+ const record4 = payload && typeof payload === "object" ? payload : void 0;
4658
+ if (lane === "query.request" && name === "get_ephemeral" && record4 && !ENDPOINT_CONTENT_EPHEMERAL_FAMILIES.includes(record4.family)) {
4433
4659
  throw new EndpointContentPolicyError(lane, `${name}/unknown-family`);
4434
4660
  }
4435
4661
  const requestRoutingPaths = (actionRouting[name] ?? []).flatMap((field) => [`body.value.${field}`, `envelope.${field}`]);
@@ -4437,7 +4663,7 @@ function endpointContentBoundary(lane, name, payload) {
4437
4663
  if (path.some((part) => secretSegments.has(part))) return "restricted-secret";
4438
4664
  if (lane === "operation.request" && ["respond_interaction", "sync_phone_contacts"].includes(name) && matches(path, "preparedContent.payload")) return "restricted-secret";
4439
4665
  if (lane === "operation.request" && ["respond_interaction", "sync_phone_contacts"].includes(name) && path[0] === "body" && path[1] === "value" && !publicMatch(path, requestRoutingPaths)) return "restricted-secret";
4440
- if (lane === "operation.receipt" && path[0] === "result" && (["consume_interaction", "respond_interaction"].includes(name) || record5?.resultReference?.kind === "interaction")) return "restricted-secret";
4666
+ if (lane === "operation.receipt" && path[0] === "result" && (["consume_interaction", "respond_interaction"].includes(name) || record4?.resultReference?.kind === "interaction")) return "restricted-secret";
4441
4667
  let selected = payload;
4442
4668
  for (const part of path) selected = selected && typeof selected === "object" && Object.hasOwn(selected, part) ? selected[part] : void 0;
4443
4669
  if (selected !== null && typeof selected === "object") return "private-content";
@@ -4446,7 +4672,7 @@ function endpointContentBoundary(lane, name, payload) {
4446
4672
  if (name === "respond_interaction" && path[0] === "body" && path[1] === "value") return "restricted-secret";
4447
4673
  if (name === "sync_phone_contacts" && path[0] === "body" && path[1] === "value") return "restricted-secret";
4448
4674
  if (name === "verb_execute") {
4449
- const wire4 = record5?.body?.value;
4675
+ const wire4 = record4?.body?.value;
4450
4676
  const spec = VERB_WIRE_ENVELOPE_FIELDS[wire4?.verb];
4451
4677
  if (path[0] === "body" && path[1] === "value") {
4452
4678
  if (path.length === 3 && ["wire", "verb"].includes(path[2])) return "public-metadata";
@@ -4459,7 +4685,7 @@ function endpointContentBoundary(lane, name, payload) {
4459
4685
  }
4460
4686
  } else if (lane === "operation.receipt") {
4461
4687
  if (publicMatch(path, [...protocolPaths, "status", "createdAt", "updatedAt", "error.code", "error.status", "error.retryable", "error.retryAfterMs", "resultError.code", "resultError.status", "resultReference.kind", "resultReference.conversationId", "resultReference.artifactId", "resultReference.assetId", "resultReference.uploadId", "resultReference.sessionId", "resultReference.requestId"])) return "public-metadata";
4462
- if (path[0] === "result" && (name === "consume_interaction" || name === "respond_interaction" || record5?.resultReference?.kind === "interaction")) return "restricted-secret";
4688
+ if (path[0] === "result" && (name === "consume_interaction" || name === "respond_interaction" || record4?.resultReference?.kind === "interaction")) return "restricted-secret";
4463
4689
  } else if (lane === "query.request") {
4464
4690
  if (publicMatch(path, queryRouting[name] ?? [])) return "public-metadata";
4465
4691
  } else if (lane === "query.result" || lane === "ephemeral.result") {
@@ -4491,10 +4717,10 @@ var PreparedContentError = class extends Error {
4491
4717
  __name(this, "PreparedContentError");
4492
4718
  }
4493
4719
  };
4494
- function invalid10() {
4720
+ function invalid12() {
4495
4721
  throw new PreparedContentError("INVALID_PREPARED_CONTENT");
4496
4722
  }
4497
- __name(invalid10, "invalid");
4723
+ __name(invalid12, "invalid");
4498
4724
  var record2 = /* @__PURE__ */ __name((value) => !!value && typeof value === "object" && !Array.isArray(value), "record");
4499
4725
  var keys = /* @__PURE__ */ __name((value, allowed) => Object.keys(value).every((key) => allowed.includes(key)), "keys");
4500
4726
  var revision = /* @__PURE__ */ __name((value) => Number.isSafeInteger(value) && value >= 0, "revision");
@@ -4515,25 +4741,25 @@ function canonicalEndpointJson(value) {
4515
4741
  }
4516
4742
  __name(canonicalEndpointJson, "canonicalEndpointJson");
4517
4743
  function validateMetadata(value) {
4518
- if (!record2(value)) invalid10();
4744
+ if (!record2(value)) invalid12();
4519
4745
  if (value.version !== PREPARED_CONTENT_VERSION) throw new PreparedContentError("UNSUPPORTED_PREPARED_CONTENT_VERSION");
4520
4746
  if (value.codec !== PREPARED_JSON_CODEC) throw new PreparedContentError("UNSUPPORTED_PREPARED_CONTENT_CODEC");
4521
- if (!keys(value, ["version", "context", "codec", "payload", "blobs", "expected"])) invalid10();
4747
+ if (!keys(value, ["version", "context", "codec", "payload", "blobs", "expected"])) invalid12();
4522
4748
  const context = value.context;
4523
- if (!record2(context) || !keys(context, ["action", "conversationId", "messageId"]) || typeof context.action !== "string" || !ENDPOINT_ACTION_PATTERN.test(context.action) || context.conversationId !== void 0 && !identity(context.conversationId) || context.messageId !== void 0 && !identity(context.messageId)) invalid10();
4749
+ if (!record2(context) || !keys(context, ["action", "conversationId", "messageId"]) || typeof context.action !== "string" || !ENDPOINT_ACTION_PATTERN.test(context.action) || context.conversationId !== void 0 && !identity(context.conversationId) || context.messageId !== void 0 && !identity(context.messageId)) invalid12();
4524
4750
  const expected = value.expected;
4525
- if (!record2(expected) || !keys(expected, ["installationGeneration", "protocolRevision", "admission"]) || !revision(expected.installationGeneration) || !revision(expected.protocolRevision)) invalid10();
4751
+ if (!record2(expected) || !keys(expected, ["installationGeneration", "protocolRevision", "admission"]) || !revision(expected.installationGeneration) || !revision(expected.protocolRevision)) invalid12();
4526
4752
  if (expected.admission !== void 0) {
4527
4753
  const admission = expected.admission;
4528
- if (!record2(admission) || !keys(admission, ["conversationId", "membershipRevision", "admissionId", "targetAdmissionId"]) || ["conversationId", "admissionId", "targetAdmissionId"].some((key) => admission[key] !== void 0 && !identity(admission[key])) || admission.membershipRevision !== void 0 && !revision(admission.membershipRevision) || context.conversationId !== void 0 && admission.conversationId !== void 0 && admission.conversationId !== context.conversationId) invalid10();
4754
+ if (!record2(admission) || !keys(admission, ["conversationId", "membershipRevision", "admissionId", "targetAdmissionId"]) || ["conversationId", "admissionId", "targetAdmissionId"].some((key) => admission[key] !== void 0 && !identity(admission[key])) || admission.membershipRevision !== void 0 && !revision(admission.membershipRevision) || context.conversationId !== void 0 && admission.conversationId !== void 0 && admission.conversationId !== context.conversationId) invalid12();
4529
4755
  }
4530
- if (!Array.isArray(value.blobs)) invalid10();
4756
+ if (!Array.isArray(value.blobs)) invalid12();
4531
4757
  const ids = /* @__PURE__ */ new Set();
4532
4758
  for (const [index, blob] of value.blobs.entries()) {
4533
- if (!record2(blob) || !keys(blob, ["id", "index"]) || !blobIdentity(blob.id) || blob.index !== index || ids.has(blob.id)) invalid10();
4759
+ if (!record2(blob) || !keys(blob, ["id", "index"]) || !blobIdentity(blob.id) || blob.index !== index || ids.has(blob.id)) invalid12();
4534
4760
  ids.add(blob.id);
4535
4761
  }
4536
- if (typeof value.payload !== "string") invalid10();
4762
+ if (typeof value.payload !== "string") invalid12();
4537
4763
  }
4538
4764
  __name(validateMetadata, "validateMetadata");
4539
4765
  function decodePreparedJsonContent(value) {
@@ -4542,10 +4768,10 @@ function decodePreparedJsonContent(value) {
4542
4768
  try {
4543
4769
  decoded = JSON.parse(value.payload);
4544
4770
  } catch {
4545
- invalid10();
4771
+ invalid12();
4546
4772
  }
4547
- if (!record2(decoded) || !keys(decoded, ["body", "envelope"]) || !record2(decoded.body) || decoded.envelope !== void 0 && !record2(decoded.envelope)) invalid10();
4548
- if (canonicalEndpointJson(decoded) !== value.payload) invalid10();
4773
+ if (!record2(decoded) || !keys(decoded, ["body", "envelope"]) || !record2(decoded.body) || decoded.envelope !== void 0 && !record2(decoded.envelope)) invalid12();
4774
+ if (canonicalEndpointJson(decoded) !== value.payload) invalid12();
4549
4775
  const { body, envelope } = decoded;
4550
4776
  if (endpointOperationRequestRetention(value.context.action, body, envelope) === "memory") {
4551
4777
  throw new PreparedContentError("PREPARED_CONTENT_MEMORY_ONLY");
@@ -4553,7 +4779,7 @@ function decodePreparedJsonContent(value) {
4553
4779
  const effective = { ...body, ...envelope };
4554
4780
  for (const key of ["conversationId", "messageId"]) {
4555
4781
  const bound = value.context[key];
4556
- if (bound !== void 0 && effective[key] !== void 0 && effective[key] !== bound) invalid10();
4782
+ if (bound !== void 0 && effective[key] !== void 0 && effective[key] !== bound) invalid12();
4557
4783
  }
4558
4784
  return envelope === void 0 ? { body } : { body, envelope };
4559
4785
  }
@@ -4583,7 +4809,7 @@ function prepareJsonContent(input) {
4583
4809
  }
4584
4810
  __name(prepareJsonContent, "prepareJsonContent");
4585
4811
  function logicalMediaBlobId(conversationId, messageId2, index) {
4586
- if (!identity(conversationId) || !identity(messageId2) || !revision(index)) invalid10();
4812
+ if (!identity(conversationId) || !identity(messageId2) || !revision(index)) invalid12();
4587
4813
  return JSON.stringify([conversationId, messageId2, index]);
4588
4814
  }
4589
4815
  __name(logicalMediaBlobId, "logicalMediaBlobId");
@@ -4626,31 +4852,31 @@ var ConnectorRelayRequestError = class extends Error {
4626
4852
  }
4627
4853
  name = "ConnectorRelayRequestError";
4628
4854
  };
4629
- function invalid11(what) {
4855
+ function invalid13(what) {
4630
4856
  throw new ConnectorRelayRequestError(`Invalid relay request: ${what}`);
4631
4857
  }
4632
- __name(invalid11, "invalid");
4858
+ __name(invalid13, "invalid");
4633
4859
  function record3(value, required, optional = []) {
4634
- if (!value || typeof value !== "object" || Array.isArray(value)) invalid11("expected an object");
4860
+ if (!value || typeof value !== "object" || Array.isArray(value)) invalid13("expected an object");
4635
4861
  const result = value;
4636
- for (const key of Object.keys(result)) if (!required.includes(key) && !optional.includes(key)) invalid11(`unexpected ${key}`);
4637
- for (const key of required) if (!Object.hasOwn(result, key)) invalid11(`missing ${key}`);
4862
+ for (const key of Object.keys(result)) if (!required.includes(key) && !optional.includes(key)) invalid13(`unexpected ${key}`);
4863
+ for (const key of required) if (!Object.hasOwn(result, key)) invalid13(`missing ${key}`);
4638
4864
  return result;
4639
4865
  }
4640
4866
  __name(record3, "record");
4641
4867
  function id6(value, what, pattern = ENDPOINT_ID_PATTERN) {
4642
- if (typeof value !== "string" || !pattern.test(value)) invalid11(what);
4868
+ if (typeof value !== "string" || !pattern.test(value)) invalid13(what);
4643
4869
  return value;
4644
4870
  }
4645
4871
  __name(id6, "id");
4646
4872
  function doc(value, what) {
4647
- if (typeof value !== "string" || !value || value.length > 200 || value.includes("/")) invalid11(what);
4873
+ if (typeof value !== "string" || !value || value.length > 200 || value.includes("/")) invalid13(what);
4648
4874
  return value;
4649
4875
  }
4650
4876
  __name(doc, "doc");
4651
4877
  var room = /* @__PURE__ */ __name((value) => doc(value, "conversationId"), "room");
4652
4878
  function text4(value) {
4653
- if (typeof value !== "string" || !value.trim() || new TextEncoder().encode(value).length > CONNECTOR_RELAY_MAX_TEXT_BYTES) invalid11("text");
4879
+ if (typeof value !== "string" || !value.trim() || new TextEncoder().encode(value).length > CONNECTOR_RELAY_MAX_TEXT_BYTES) invalid13("text");
4654
4880
  return value;
4655
4881
  }
4656
4882
  __name(text4, "text");
@@ -4658,18 +4884,18 @@ function selection(value) {
4658
4884
  const args = record3(value, ["mode"], ["conversationId"]);
4659
4885
  if ((args.mode === "new" || args.mode === "latest_or_new") && args.conversationId === void 0) return { mode: args.mode };
4660
4886
  if (args.mode === "specific") return { mode: "specific", conversationId: room(args.conversationId) };
4661
- return invalid11("selection");
4887
+ return invalid13("selection");
4662
4888
  }
4663
4889
  __name(selection, "selection");
4664
4890
  function limit(value) {
4665
4891
  if (value === void 0) return void 0;
4666
- if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 1 || value > 100) invalid11("limit");
4892
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 1 || value > 100) invalid13("limit");
4667
4893
  return value;
4668
4894
  }
4669
4895
  __name(limit, "limit");
4670
4896
  function parseConnectorRelayRequest(value) {
4671
4897
  const body = record3(value, ["version", "agentId", "grantId", "op", "args"]);
4672
- if (body.version !== 1) invalid11("version");
4898
+ if (body.version !== 1) invalid13("version");
4673
4899
  const head = { version: 1, agentId: doc(body.agentId, "agentId"), grantId: id6(body.grantId, "grantId") };
4674
4900
  switch (body.op) {
4675
4901
  case "pending": {
@@ -4690,7 +4916,7 @@ function parseConnectorRelayRequest(value) {
4690
4916
  }
4691
4917
  case "settle": {
4692
4918
  const args = record3(body.args, ["inputId", "requestId", "outcome"]);
4693
- if (!["completed", "no_reply", "failed"].includes(args.outcome)) invalid11("outcome");
4919
+ if (!["completed", "no_reply", "failed"].includes(args.outcome)) invalid13("outcome");
4694
4920
  return { ...head, op: "settle", args: {
4695
4921
  inputId: id6(args.inputId, "inputId", CONNECTOR_RELAY_INPUT_ID_PATTERN),
4696
4922
  requestId: id6(args.requestId, "requestId"),
@@ -4699,7 +4925,7 @@ function parseConnectorRelayRequest(value) {
4699
4925
  }
4700
4926
  case "read": {
4701
4927
  const args = record3(body.args, ["conversationId"], ["limit", "before"]);
4702
- if (args.before !== void 0 && (typeof args.before !== "string" || !/^[1-9][0-9]{0,15}$/.test(args.before))) invalid11("before");
4928
+ if (args.before !== void 0 && (typeof args.before !== "string" || !/^[1-9][0-9]{0,15}$/.test(args.before))) invalid13("before");
4703
4929
  return { ...head, op: "read", args: {
4704
4930
  conversationId: room(args.conversationId),
4705
4931
  ...args.limit === void 0 ? {} : { limit: limit(args.limit) },
@@ -4721,8 +4947,8 @@ function parseConnectorRelayRequest(value) {
4721
4947
  }
4722
4948
  case "credential": {
4723
4949
  const args = record3(body.args, ["installationId", "generation", "credential"]);
4724
- if (!Number.isSafeInteger(args.generation) || args.generation < 1) invalid11("generation");
4725
- if (!isConnectorRelayCredential(args.credential)) invalid11("credential");
4950
+ if (!Number.isSafeInteger(args.generation) || args.generation < 1) invalid13("generation");
4951
+ if (!isConnectorRelayCredential(args.credential)) invalid13("credential");
4726
4952
  return { ...head, op: "credential", args: {
4727
4953
  installationId: id6(args.installationId, "installationId", CONNECTOR_RELAY_INSTALLATION_PATTERN),
4728
4954
  generation: args.generation,
@@ -4730,7 +4956,7 @@ function parseConnectorRelayRequest(value) {
4730
4956
  } };
4731
4957
  }
4732
4958
  default:
4733
- return invalid11("op");
4959
+ return invalid13("op");
4734
4960
  }
4735
4961
  }
4736
4962
  __name(parseConnectorRelayRequest, "parseConnectorRelayRequest");
@@ -4804,231 +5030,6 @@ var ARTIFACT_LIMITS = Object.freeze({
4804
5030
  });
4805
5031
  var NUMBER_MAX_TEXT = String(ARTIFACT_LIMITS.formNumberMax).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
4806
5032
 
4807
- // ../backend-contracts/src/mlsDevCredentialReconciliation.ts
4808
- var MLS_DEV_CREDENTIAL_RECONCILIATION_CHALLENGE_TTL_MS = 3e5;
4809
- var MLS_DEV_CREDENTIAL_RECONCILIATION_MAX_BYTES = 8192;
4810
- var MlsDevCredentialReconciliationValidationError = class extends Error {
4811
- static {
4812
- __name(this, "MlsDevCredentialReconciliationValidationError");
4813
- }
4814
- code = "INVALID_MLS_DEV_CREDENTIAL_RECONCILIATION";
4815
- constructor() {
4816
- super("INVALID_MLS_DEV_CREDENTIAL_RECONCILIATION");
4817
- this.name = "MlsDevCredentialReconciliationValidationError";
4818
- }
4819
- };
4820
- var utf86 = new TextEncoder();
4821
- var domain2 = utf86.encode("canon.mls.credential-reconciliation-proof.v1\0");
4822
- function invalid12() {
4823
- throw new MlsDevCredentialReconciliationValidationError();
4824
- }
4825
- __name(invalid12, "invalid");
4826
- function boundary9(read) {
4827
- try {
4828
- return read();
4829
- } catch {
4830
- return invalid12();
4831
- }
4832
- }
4833
- __name(boundary9, "boundary");
4834
- function bounded7(value) {
4835
- if (utf86.encode(JSON.stringify(value)).length > MLS_DEV_CREDENTIAL_RECONCILIATION_MAX_BYTES) invalid12();
4836
- return Object.freeze(value);
4837
- }
4838
- __name(bounded7, "bounded");
4839
- function encoded6(value, bytes) {
4840
- decodeCanonicalMlsBase64Url(value, bytes);
4841
- return value;
4842
- }
4843
- __name(encoded6, "encoded");
4844
- function parseMlsDevCredentialReconciliationBegin(value) {
4845
- return boundary9(() => {
4846
- const input = readMlsDataRecord(value, ["version", "deviceId", "requestId", "expectedCredentialGeneration"]);
4847
- return bounded7({
4848
- version: requireMlsLiteral(input.version, 1),
4849
- deviceId: requireMlsUuid(input.deviceId),
4850
- requestId: requireMlsUuid(input.requestId),
4851
- expectedCredentialGeneration: requireMlsInteger(input.expectedCredentialGeneration)
4852
- });
4853
- });
4854
- }
4855
- __name(parseMlsDevCredentialReconciliationBegin, "parseMlsDevCredentialReconciliationBegin");
4856
- function parseMlsDevCredentialReconciliationChallenge(value) {
4857
- return boundary9(() => {
4858
- const input = readMlsDataRecord(value, [
4859
- "version",
4860
- "challengeId",
4861
- "requestId",
4862
- "nonce",
4863
- "device",
4864
- "expectedCredentialGeneration",
4865
- "issuedAtMs",
4866
- "expiresAtMs"
4867
- ]);
4868
- const device = parseMlsDevEnrollmentResult({ version: 1, authorization: "registration_only", device: input.device }).device;
4869
- const issuedAtMs = requireMlsInteger(input.issuedAtMs), expiresAtMs = requireMlsInteger(input.expiresAtMs);
4870
- if (issuedAtMs < device.registeredAtMs || expiresAtMs - issuedAtMs !== MLS_DEV_CREDENTIAL_RECONCILIATION_CHALLENGE_TTL_MS) invalid12();
4871
- return bounded7({
4872
- version: requireMlsLiteral(input.version, 1),
4873
- challengeId: requireMlsUuid(input.challengeId),
4874
- requestId: requireMlsUuid(input.requestId),
4875
- nonce: encoded6(input.nonce, 32),
4876
- device,
4877
- expectedCredentialGeneration: requireMlsInteger(input.expectedCredentialGeneration),
4878
- issuedAtMs,
4879
- expiresAtMs
4880
- });
4881
- });
4882
- }
4883
- __name(parseMlsDevCredentialReconciliationChallenge, "parseMlsDevCredentialReconciliationChallenge");
4884
- function parseMlsDevCredentialReconciliationComplete(value) {
4885
- return boundary9(() => {
4886
- const input = readMlsDataRecord(value, ["version", "challengeId", "proof"]);
4887
- return bounded7({ version: requireMlsLiteral(input.version, 1), challengeId: requireMlsUuid(input.challengeId), proof: encoded6(input.proof, 64) });
4888
- });
4889
- }
4890
- __name(parseMlsDevCredentialReconciliationComplete, "parseMlsDevCredentialReconciliationComplete");
4891
- function parseMlsDevCredentialReconciliationReceipt(value) {
4892
- return boundary9(() => {
4893
- const input = readMlsDataRecord(value, ["version", "authorization", "challenge", "observedCredentialGeneration", "observedAtMs"]);
4894
- const challenge = parseMlsDevCredentialReconciliationChallenge(input.challenge);
4895
- const observedCredentialGeneration = requireMlsInteger(input.observedCredentialGeneration), observedAtMs = requireMlsInteger(input.observedAtMs);
4896
- if (observedCredentialGeneration < challenge.expectedCredentialGeneration || observedAtMs < challenge.issuedAtMs || observedAtMs >= challenge.expiresAtMs) invalid12();
4897
- return bounded7({
4898
- version: requireMlsLiteral(input.version, 1),
4899
- authorization: requireMlsLiteral(input.authorization, "credential_generation_observation_only"),
4900
- challenge,
4901
- observedCredentialGeneration,
4902
- observedAtMs
4903
- });
4904
- });
4905
- }
4906
- __name(parseMlsDevCredentialReconciliationReceipt, "parseMlsDevCredentialReconciliationReceipt");
4907
-
4908
- // ../backend-contracts/src/mlsDevDeviceCustody.ts
4909
- var MLS_DEV_DEVICE_CONTEXT_MAX_BYTES = 2048;
4910
- var MLS_DEV_DEVICE_COMMAND_MAX_BYTES = 16384;
4911
- var MLS_DEV_DEVICE_WRAPPED_STATE_MAX_BYTES = 6144;
4912
- var MlsDevDeviceCustodyValidationError = class extends Error {
4913
- static {
4914
- __name(this, "MlsDevDeviceCustodyValidationError");
4915
- }
4916
- code = "INVALID_MLS_DEV_DEVICE_CUSTODY";
4917
- constructor() {
4918
- super("INVALID_MLS_DEV_DEVICE_CUSTODY");
4919
- this.name = "MlsDevDeviceCustodyValidationError";
4920
- }
4921
- };
4922
- var utf87 = new TextEncoder();
4923
- function invalid13() {
4924
- throw new MlsDevDeviceCustodyValidationError();
4925
- }
4926
- __name(invalid13, "invalid");
4927
- function boundary10(read) {
4928
- try {
4929
- return read();
4930
- } catch {
4931
- return invalid13();
4932
- }
4933
- }
4934
- __name(boundary10, "boundary");
4935
- function bounded8(value, limit2) {
4936
- if (utf87.encode(JSON.stringify(value)).length > limit2) invalid13();
4937
- return Object.freeze(value);
4938
- }
4939
- __name(bounded8, "bounded");
4940
- function binding2(input) {
4941
- return {
4942
- version: requireMlsLiteral(input.version, 1),
4943
- environmentId: requireMlsEnvironmentId(input.environmentId),
4944
- principal: parseMlsDevEnrollmentPrincipal(input.principal),
4945
- installationId: parseMlsDevInstallationId(input.installationId)
4946
- };
4947
- }
4948
- __name(binding2, "binding");
4949
- function parseMlsDevDeviceBinding(value) {
4950
- return boundary10(() => bounded8(binding2(readMlsDataRecord(value, ["version", "environmentId", "principal", "installationId"])), MLS_DEV_DEVICE_CONTEXT_MAX_BYTES));
4951
- }
4952
- __name(parseMlsDevDeviceBinding, "parseMlsDevDeviceBinding");
4953
- function parseMlsDevDeviceContext(value) {
4954
- return boundary10(() => {
4955
- const input = readMlsDataRecord(value, ["version", "environmentId", "principal", "installationId", "revision"]);
4956
- const revision2 = requireMlsInteger(input.revision);
4957
- if (revision2 >= Number.MAX_SAFE_INTEGER) invalid13();
4958
- return bounded8({ ...binding2(input), revision: revision2 }, MLS_DEV_DEVICE_CONTEXT_MAX_BYTES);
4959
- });
4960
- }
4961
- __name(parseMlsDevDeviceContext, "parseMlsDevDeviceContext");
4962
- function parseMlsDevDeviceCommand(value) {
4963
- return boundary10(() => {
4964
- if (value === null || typeof value !== "object") invalid13();
4965
- const descriptor = Object.getOwnPropertyDescriptor(value, "op");
4966
- if (!descriptor || !Object.hasOwn(descriptor, "value")) invalid13();
4967
- if (descriptor.value === "create") {
4968
- const input2 = readMlsDataRecord(value, ["op"]);
4969
- return Object.freeze({ op: requireMlsLiteral(input2.op, "create") });
4970
- }
4971
- if (descriptor.value === "enrollment_proof") {
4972
- const input2 = readMlsDataRecord(value, ["op", "challenge"]);
4973
- return bounded8({
4974
- op: requireMlsLiteral(input2.op, "enrollment_proof"),
4975
- challenge: parseMlsDevEnrollmentChallenge(input2.challenge)
4976
- }, MLS_DEV_DEVICE_COMMAND_MAX_BYTES);
4977
- }
4978
- if (descriptor.value === "credential_reconciliation_proof") {
4979
- const input2 = readMlsDataRecord(value, ["op", "challenge", "expectedCredentialGeneration"]);
4980
- const challenge2 = parseMlsDevCredentialReconciliationChallenge(input2.challenge);
4981
- const expectedCredentialGeneration2 = requireMlsInteger(input2.expectedCredentialGeneration);
4982
- if (challenge2.expectedCredentialGeneration !== expectedCredentialGeneration2) invalid13();
4983
- return bounded8({
4984
- op: requireMlsLiteral(input2.op, "credential_reconciliation_proof"),
4985
- challenge: challenge2,
4986
- expectedCredentialGeneration: expectedCredentialGeneration2
4987
- }, MLS_DEV_DEVICE_COMMAND_MAX_BYTES);
4988
- }
4989
- if (descriptor.value !== "credential_proof") invalid13();
4990
- const input = readMlsDataRecord(value, ["op", "challenge", "registrationResult", "expectedCredentialGeneration"]);
4991
- const challenge = parseMlsDevCredentialChallenge(input.challenge);
4992
- const registrationResult = parseMlsDevEnrollmentResult(input.registrationResult);
4993
- const expectedCredentialGeneration = requireMlsInteger(input.expectedCredentialGeneration);
4994
- if (expectedCredentialGeneration >= Number.MAX_SAFE_INTEGER || challenge.credential.claims.generation !== expectedCredentialGeneration + 1 || JSON.stringify(challenge.credential.claims.device) !== JSON.stringify(registrationResult.device)) invalid13();
4995
- return bounded8({
4996
- op: requireMlsLiteral(input.op, "credential_proof"),
4997
- challenge,
4998
- registrationResult,
4999
- expectedCredentialGeneration
5000
- }, MLS_DEV_DEVICE_COMMAND_MAX_BYTES);
5001
- });
5002
- }
5003
- __name(parseMlsDevDeviceCommand, "parseMlsDevDeviceCommand");
5004
- function encoded7(value, bytes) {
5005
- decodeCanonicalMlsBase64Url(value, bytes);
5006
- return value;
5007
- }
5008
- __name(encoded7, "encoded");
5009
- function wrapped(value) {
5010
- if (typeof value !== "string" || value.length > MLS_DEV_DEVICE_WRAPPED_STATE_MAX_BYTES || !value.startsWith("v1:")) invalid13();
5011
- const body = value.slice(3);
5012
- if (body.length < 40 || body.length % 4 !== 0 || !/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(body)) invalid13();
5013
- const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
5014
- if (body.endsWith("==") && (alphabet.indexOf(body.at(-3)) & 15) !== 0) invalid13();
5015
- if (!body.endsWith("==") && body.endsWith("=") && (alphabet.indexOf(body.at(-2)) & 3) !== 0) invalid13();
5016
- return value;
5017
- }
5018
- __name(wrapped, "wrapped");
5019
- function parseMlsDevDevicePreparation(value, op) {
5020
- return boundary10(() => {
5021
- if (!["create", "enrollment_proof", "credential_proof", "credential_reconciliation_proof"].includes(op)) invalid13();
5022
- const input = readMlsDataRecord(value, ["wrappedState", "payload"]);
5023
- const payload = readMlsDataRecord(input.payload, op === "create" ? ["signaturePublicKey"] : ["signaturePublicKey", "proof"]);
5024
- return bounded8({ wrappedState: wrapped(input.wrappedState), payload: Object.freeze({
5025
- signaturePublicKey: encoded7(payload.signaturePublicKey, 32),
5026
- ...op === "create" ? {} : { proof: encoded7(payload.proof, 64) }
5027
- }) }, MLS_DEV_DEVICE_COMMAND_MAX_BYTES);
5028
- });
5029
- }
5030
- __name(parseMlsDevDevicePreparation, "parseMlsDevDevicePreparation");
5031
-
5032
5033
  // ../backend-contracts/src/mlsDevKeyPackage.ts
5033
5034
  var MLS_DEV_KEY_PACKAGE_COMMAND_MAX_BYTES = 16384;
5034
5035
  var MLS_DEV_KEY_PACKAGE_WIRE_MAX_BYTES = 16384;
@@ -5122,7 +5123,7 @@ function parseMlsDevKeyPackagePayload(value) {
5122
5123
  "expiresAtMs"
5123
5124
  ]);
5124
5125
  const notBeforeMs = requireMlsInteger(input.notBeforeMs), expiresAtMs = requireMlsInteger(input.expiresAtMs);
5125
- if (notBeforeMs % 1e3 !== 0 || expiresAtMs % 1e3 !== 0 || expiresAtMs <= notBeforeMs || expiresAtMs - notBeforeMs > 864e5) invalid14();
5126
+ if (notBeforeMs % 1e3 !== 0 || expiresAtMs % 1e3 !== 0 || expiresAtMs <= notBeforeMs || expiresAtMs - notBeforeMs > MLS_DEV_CREDENTIAL_LONG_TTL_MS) invalid14();
5126
5127
  return bounded9({
5127
5128
  version: requireMlsLiteral(input.version, 1),
5128
5129
  keyPackageId: requireMlsUuid(input.keyPackageId),
@@ -5218,103 +5219,6 @@ function parseMlsRoomIdentities(value) {
5218
5219
  }
5219
5220
  __name(parseMlsRoomIdentities, "parseMlsRoomIdentities");
5220
5221
 
5221
- // ../endpoint/src/runtime-api-origins.generated.ts
5222
- var RUNTIME_API_ORIGINS = {
5223
- "canon-dev-v1": "https://dev.api.canonmail.com",
5224
- "canon-prod-v1": "https://api.canonmail.com"
5225
- };
5226
-
5227
- // ../endpoint/src/mls-crypto.ts
5228
- function mlsDevDeviceHttpConfiguration(environmentId) {
5229
- if (!isMlsEnvironmentId(environmentId)) invalid16();
5230
- const origin = RUNTIME_API_ORIGINS[environmentId];
5231
- return Object.freeze({
5232
- enrollmentUrl: `${origin}/mls/enrollment`,
5233
- credentialUrl: `${origin}/mls/credential`,
5234
- reconciliationUrl: `${origin}/mls/reconciliation`,
5235
- keyPackagesUrl: `${origin}/mls/key-packages`,
5236
- trustedOrigins: Object.freeze([origin])
5237
- });
5238
- }
5239
- __name(mlsDevDeviceHttpConfiguration, "mlsDevDeviceHttpConfiguration");
5240
- function invalid16() {
5241
- throw new Error("MLS_DEV_CLIENT_CONFIGURATION_INVALID");
5242
- }
5243
- __name(invalid16, "invalid");
5244
- function record4(value, keys2) {
5245
- if (!value || typeof value !== "object" || Array.isArray(value) || ![Object.prototype, null].includes(Object.getPrototypeOf(value))) invalid16();
5246
- const fields2 = Object.getOwnPropertyDescriptors(value);
5247
- if (Reflect.ownKeys(fields2).length !== keys2.length || keys2.some((key) => !Object.hasOwn(fields2, key) || !Object.hasOwn(fields2[key], "value"))) invalid16();
5248
- return value;
5249
- }
5250
- __name(record4, "record");
5251
- function primeOrderPoint(value) {
5252
- const point = ed25519.Point.fromBytes(value, false);
5253
- return !point.isSmallOrder() && point.isTorsionFree();
5254
- }
5255
- __name(primeOrderPoint, "primeOrderPoint");
5256
- function issuerKeys(value, environmentId, receipt = false) {
5257
- if (!Array.isArray(value) || value.length < 1 || value.length > 8) invalid16();
5258
- const seen = /* @__PURE__ */ new Set();
5259
- let environment = environmentId;
5260
- return Object.freeze(Array.from(value, (item2) => {
5261
- const key = record4(item2, ["keyVersion", "signaturePublicKey"]);
5262
- const keyVersion = receipt ? parseMlsDevReceiptKeyVersion(key.keyVersion, environment) : parseMlsDevIssuerKeyVersion(key.keyVersion, environment);
5263
- environment ??= receipt ? mlsEnvironmentOfReceiptKeyVersion(keyVersion) : mlsEnvironmentOfIssuerKeyVersion(keyVersion);
5264
- if (seen.has(keyVersion) || typeof key.signaturePublicKey !== "string" || !primeOrderPoint(decodeCanonicalMlsBase64Url(key.signaturePublicKey, 32))) invalid16();
5265
- seen.add(keyVersion);
5266
- return Object.freeze({ keyVersion, signaturePublicKey: key.signaturePublicKey });
5267
- }));
5268
- }
5269
- __name(issuerKeys, "issuerKeys");
5270
- function parseMlsDevClientConfiguration(value) {
5271
- try {
5272
- const listed = !!value && typeof value === "object" && Object.hasOwn(value, "principalIds");
5273
- const input = record4(value, ["version", "environmentId", "enabled", ...listed ? ["principalIds"] : [], "issuerKeys", "receiptKeys"]);
5274
- if (input.version !== 1 || !isMlsEnvironmentId(input.environmentId) || input.enabled !== true || listed && (!Array.isArray(input.principalIds) || input.principalIds.length < 1 || input.principalIds.length > 100)) invalid16();
5275
- const environmentId = input.environmentId;
5276
- const principalIds = listed ? Array.from(input.principalIds, (id7) => parseMlsDevEnrollmentPrincipal({ type: "human", id: id7 }).id) : void 0;
5277
- if (principalIds && new Set(principalIds).size !== principalIds.length) invalid16();
5278
- return Object.freeze({
5279
- version: 1,
5280
- environmentId,
5281
- enabled: true,
5282
- ...principalIds ? { principalIds: Object.freeze(principalIds) } : {},
5283
- issuerKeys: issuerKeys(input.issuerKeys, environmentId),
5284
- receiptKeys: issuerKeys(input.receiptKeys, environmentId, true)
5285
- });
5286
- } catch {
5287
- return invalid16();
5288
- }
5289
- }
5290
- __name(parseMlsDevClientConfiguration, "parseMlsDevClientConfiguration");
5291
- function createMlsDevCredentialVerifier(options) {
5292
- let trusted;
5293
- try {
5294
- trusted = new Map(issuerKeys(options.issuerKeys).map((key) => [key.keyVersion, key.signaturePublicKey]));
5295
- } catch {
5296
- return invalid16();
5297
- }
5298
- const clock = options.clock ?? Date.now;
5299
- return async (value) => {
5300
- try {
5301
- const receipt = parseMlsDevCredentialReceipt(value);
5302
- const parsed = parseMlsDevCredentialToken(receipt.credential);
5303
- const key = trusted.get(parsed.unsigned.keyVersion);
5304
- const now = clock();
5305
- const { issuedAtMs, expiresAtMs } = parsed.unsigned.claims;
5306
- if (!key || !Number.isSafeInteger(now) || now < issuedAtMs || now >= expiresAtMs) return false;
5307
- const publicKey = decodeCanonicalMlsBase64Url(key, 32);
5308
- const signature = decodeCanonicalMlsBase64Url(parsed.signature, 64);
5309
- if (!primeOrderPoint(publicKey) || !primeOrderPoint(signature.subarray(0, 32))) return false;
5310
- return ed25519.verify(signature, new TextEncoder().encode(parsed.signingInput), publicKey, { zip215: false });
5311
- } catch {
5312
- return false;
5313
- }
5314
- };
5315
- }
5316
- __name(createMlsDevCredentialVerifier, "createMlsDevCredentialVerifier");
5317
-
5318
5222
  export {
5319
5223
  __name,
5320
5224
  getCanonEnvironmentContract,
@@ -5328,6 +5232,8 @@ export {
5328
5232
  isCanonUploadUrl,
5329
5233
  resolveAllowedUploadMimeType,
5330
5234
  isMlsEnvironmentId,
5235
+ mlsEnvironmentOfIssuerKeyVersion,
5236
+ mlsEnvironmentOfReceiptKeyVersion,
5331
5237
  MLS_DEV_ENROLLMENT_MAX_BYTES,
5332
5238
  parseMlsDevEnrollmentPrincipal,
5333
5239
  parseMlsDevEnrollmentBegin,
@@ -5335,7 +5241,9 @@ export {
5335
5241
  parseMlsDevEnrollmentChallenge,
5336
5242
  parseMlsDevEnrollmentResult,
5337
5243
  encodeCanonicalMlsBase64Url,
5244
+ decodeCanonicalMlsBase64Url,
5338
5245
  MLS_DEV_CREDENTIAL_MAX_BYTES,
5246
+ parseMlsDevIssuerKeyVersion,
5339
5247
  parseMlsDevCredentialChallenge,
5340
5248
  parseMlsDevCredentialBegin,
5341
5249
  parseMlsDevCredentialComplete,
@@ -5344,6 +5252,7 @@ export {
5344
5252
  createMlsDevCredentialSigningInput,
5345
5253
  parseMlsDevCredentialToken,
5346
5254
  parseMlsDevCredentialReceipt,
5255
+ parseMlsDevReceiptKeyVersion,
5347
5256
  MLS_DEV_GROUP_RECEIPT_CLOCK_SKEW,
5348
5257
  isMlsDevReceiptClockSkew,
5349
5258
  parseMlsDevGroupFeedEntry,
@@ -5442,8 +5351,5 @@ export {
5442
5351
  isMlsPrincipalAlias,
5443
5352
  parseMlsPrincipalOpening,
5444
5353
  encodeMlsPrincipalAliasInput,
5445
- parseMlsRoomIdentities,
5446
- mlsDevDeviceHttpConfiguration,
5447
- parseMlsDevClientConfiguration,
5448
- createMlsDevCredentialVerifier
5354
+ parseMlsRoomIdentities
5449
5355
  };