@pacspace-io/check 0.5.6 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +34 -0
  3. package/dist/cli.d.ts +5 -1
  4. package/dist/cli.js +1993 -121
  5. package/dist/index.js +196 -19
  6. package/dist/inputs.txt +11 -0
  7. package/dist/open-io.d.ts +38 -0
  8. package/dist/open.d.ts +16 -15
  9. package/dist/records-crypto-types/records/flag-threads-v1.d.ts +53 -0
  10. package/dist/records-crypto-types/records/labels.d.ts +37 -0
  11. package/dist/records-crypto-types/records/link-handle-v1.d.ts +16 -0
  12. package/dist/records-crypto-types/records/reader-crypto-v1.d.ts +198 -0
  13. package/dist/records-crypto-types/records/reader-link-v1.d.ts +164 -0
  14. package/dist/records-crypto-types/records/shared-record-ack-v2.d.ts +72 -0
  15. package/dist/records-crypto-types/records/trail-index-v1.d.ts +89 -0
  16. package/dist/records-crypto-types/records/trail-rule.d.ts +54 -0
  17. package/dist/records-crypto-types/records-crypto/asymmetric/ack-flag-notes-v1.d.ts +57 -0
  18. package/dist/records-crypto-types/records-crypto/asymmetric/flag-notes-v1.d.ts +55 -0
  19. package/dist/records-crypto-types/records-crypto/asymmetric/index.d.ts +3 -0
  20. package/dist/records-crypto-types/records-crypto/asymmetric/reader-wraps-v1.d.ts +83 -0
  21. package/dist/records-crypto-types/records-crypto/disclosure-envelope-v1.d.ts +1 -1
  22. package/dist/records-crypto-types/records-crypto/index.d.ts +1 -1
  23. package/dist/records-crypto-types/records-crypto/records-encryption-v1.d.ts +1 -0
  24. package/dist/records-crypto.js +547 -66
  25. package/dist/shared-record-link.d.ts +121 -0
  26. package/dist/shared-record-words.d.ts +97 -0
  27. package/package.json +1 -1
@@ -3066,37 +3066,37 @@ function bytesToHex(bytes2) {
3066
3066
  abytes2(bytes2);
3067
3067
  if (hasHexBuiltin)
3068
3068
  return bytes2.toHex();
3069
- let hex4 = "";
3069
+ let hex5 = "";
3070
3070
  for (let i = 0; i < bytes2.length; i++) {
3071
- hex4 += hexes[bytes2[i]];
3071
+ hex5 += hexes[bytes2[i]];
3072
3072
  }
3073
- return hex4;
3073
+ return hex5;
3074
3074
  }
3075
3075
  function asciiToBase16(ch) {
3076
3076
  return ch >= 48 && ch <= 57 ? ch - 48 : ch >= 65 && ch <= 70 ? ch - (65 - 10) : ch >= 97 && ch <= 102 ? ch - (97 - 10) : void 0;
3077
3077
  }
3078
- function hexToBytes(hex4) {
3079
- if (typeof hex4 !== "string")
3080
- throw new TypeError("hex string expected, got " + typeof hex4);
3078
+ function hexToBytes(hex5) {
3079
+ if (typeof hex5 !== "string")
3080
+ throw new TypeError("hex string expected, got " + typeof hex5);
3081
3081
  if (hasHexBuiltin) {
3082
3082
  try {
3083
- return Uint8Array.fromHex(hex4);
3083
+ return Uint8Array.fromHex(hex5);
3084
3084
  } catch (error) {
3085
3085
  if (error instanceof SyntaxError)
3086
3086
  throw new RangeError(error.message);
3087
3087
  throw error;
3088
3088
  }
3089
3089
  }
3090
- const hl = hex4.length;
3090
+ const hl = hex5.length;
3091
3091
  const al = hl / 2;
3092
3092
  if (hl % 2)
3093
3093
  throw new RangeError("hex string expected, got unpadded hex of length " + hl);
3094
3094
  const array = new Uint8Array(al);
3095
3095
  for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
3096
- const n1 = asciiToBase16(hex4.charCodeAt(hi));
3097
- const n2 = asciiToBase16(hex4.charCodeAt(hi + 1));
3096
+ const n1 = asciiToBase16(hex5.charCodeAt(hi));
3097
+ const n2 = asciiToBase16(hex5.charCodeAt(hi + 1));
3098
3098
  if (n1 === void 0 || n2 === void 0) {
3099
- const char = hex4[hi] + hex4[hi + 1];
3099
+ const char = hex5[hi] + hex5[hi + 1];
3100
3100
  throw new RangeError('hex string expected, got non-hex character "' + char + '" at index ' + hi);
3101
3101
  }
3102
3102
  array[ai] = n1 * 16 + n2;
@@ -4282,37 +4282,37 @@ function bytesToHex2(bytes2) {
4282
4282
  abytes3(bytes2);
4283
4283
  if (hasHexBuiltin2)
4284
4284
  return bytes2.toHex();
4285
- let hex4 = "";
4285
+ let hex5 = "";
4286
4286
  for (let i = 0; i < bytes2.length; i++) {
4287
- hex4 += hexes2[bytes2[i]];
4287
+ hex5 += hexes2[bytes2[i]];
4288
4288
  }
4289
- return hex4;
4289
+ return hex5;
4290
4290
  }
4291
4291
  function asciiToBase162(ch) {
4292
4292
  return ch >= 48 && ch <= 57 ? ch - 48 : ch >= 65 && ch <= 70 ? ch - (65 - 10) : ch >= 97 && ch <= 102 ? ch - (97 - 10) : void 0;
4293
4293
  }
4294
- function hexToBytes2(hex4) {
4295
- if (typeof hex4 !== "string")
4296
- throw new TypeError("hex string expected, got " + typeof hex4);
4294
+ function hexToBytes2(hex5) {
4295
+ if (typeof hex5 !== "string")
4296
+ throw new TypeError("hex string expected, got " + typeof hex5);
4297
4297
  if (hasHexBuiltin2) {
4298
4298
  try {
4299
- return Uint8Array.fromHex(hex4);
4299
+ return Uint8Array.fromHex(hex5);
4300
4300
  } catch (error) {
4301
4301
  if (error instanceof SyntaxError)
4302
4302
  throw new RangeError(error.message);
4303
4303
  throw error;
4304
4304
  }
4305
4305
  }
4306
- const hl = hex4.length;
4306
+ const hl = hex5.length;
4307
4307
  const al = hl / 2;
4308
4308
  if (hl % 2)
4309
4309
  throw new RangeError("hex string expected, got unpadded hex of length " + hl);
4310
4310
  const array = new Uint8Array(al);
4311
4311
  for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
4312
- const n1 = asciiToBase162(hex4.charCodeAt(hi));
4313
- const n2 = asciiToBase162(hex4.charCodeAt(hi + 1));
4312
+ const n1 = asciiToBase162(hex5.charCodeAt(hi));
4313
+ const n2 = asciiToBase162(hex5.charCodeAt(hi + 1));
4314
4314
  if (n1 === void 0 || n2 === void 0) {
4315
- const char = hex4[hi] + hex4[hi + 1];
4315
+ const char = hex5[hi] + hex5[hi + 1];
4316
4316
  throw new RangeError('hex string expected, got non-hex character "' + char + '" at index ' + hi);
4317
4317
  }
4318
4318
  array[ai] = n1 * 16 + n2;
@@ -4691,13 +4691,13 @@ function asafenumber(value, title = "") {
4691
4691
  }
4692
4692
  }
4693
4693
  function numberToHexUnpadded(num) {
4694
- const hex4 = abignumber(num).toString(16);
4695
- return hex4.length & 1 ? "0" + hex4 : hex4;
4694
+ const hex5 = abignumber(num).toString(16);
4695
+ return hex5.length & 1 ? "0" + hex5 : hex5;
4696
4696
  }
4697
- function hexToNumber(hex4) {
4698
- if (typeof hex4 !== "string")
4699
- throw new TypeError("hex string expected, got " + typeof hex4);
4700
- return hex4 === "" ? _0n3 : BigInt("0x" + hex4);
4697
+ function hexToNumber(hex5) {
4698
+ if (typeof hex5 !== "string")
4699
+ throw new TypeError("hex string expected, got " + typeof hex5);
4700
+ return hex5 === "" ? _0n3 : BigInt("0x" + hex5);
4701
4701
  }
4702
4702
  function bytesToNumberBE(bytes2) {
4703
4703
  return hexToNumber(bytesToHex2(bytes2));
@@ -4711,10 +4711,10 @@ function numberToBytesBE(n, len) {
4711
4711
  throw new Error("zero output length is invalid");
4712
4712
  n = abignumber(n);
4713
4713
  const expectedLen = len * 2;
4714
- const hex4 = n.toString(16);
4715
- if (hex4.length > expectedLen)
4714
+ const hex5 = n.toString(16);
4715
+ if (hex5.length > expectedLen)
4716
4716
  throw new RangeError("number is too large");
4717
- return hexToBytes2(hex4.padStart(expectedLen, "0"));
4717
+ return hexToBytes2(hex5.padStart(expectedLen, "0"));
4718
4718
  }
4719
4719
  function numberToBytesLE(n, len) {
4720
4720
  return numberToBytesBE(n, len).reverse();
@@ -4827,7 +4827,7 @@ var init_utils4 = __esm({
4827
4827
  anumber4 = anumber3;
4828
4828
  bytesToHex3 = bytesToHex2;
4829
4829
  concatBytes5 = (...arrays) => concatBytes4(...arrays);
4830
- hexToBytes3 = (hex4) => hexToBytes2(hex4);
4830
+ hexToBytes3 = (hex5) => hexToBytes2(hex5);
4831
4831
  isBytes4 = isBytes3;
4832
4832
  randomBytes5 = (bytesLength) => randomBytes4(bytesLength);
4833
4833
  _0n3 = /* @__PURE__ */ BigInt(0);
@@ -6647,8 +6647,8 @@ function edwards(params, extraOpts = {}) {
6647
6647
  x = Fp2.neg(x);
6648
6648
  return Point.fromAffine({ x, y });
6649
6649
  }
6650
- static fromHex(hex4, zip215 = false) {
6651
- return Point.fromBytes(hexToBytes3(hex4), zip215);
6650
+ static fromHex(hex5, zip215 = false) {
6651
+ return Point.fromBytes(hexToBytes3(hex5), zip215);
6652
6652
  }
6653
6653
  get x() {
6654
6654
  return this.toAffine().x;
@@ -7162,12 +7162,12 @@ var init_der = __esm({
7162
7162
  abignumber(num);
7163
7163
  if (num < _0n8)
7164
7164
  throw new E("integer: negative integers are not allowed");
7165
- let hex4 = numberToHexUnpadded(num);
7166
- if (Number.parseInt(hex4[0], 16) & 8)
7167
- hex4 = "00" + hex4;
7168
- if (hex4.length & 1)
7165
+ let hex5 = numberToHexUnpadded(num);
7166
+ if (Number.parseInt(hex5[0], 16) & 8)
7167
+ hex5 = "00" + hex5;
7168
+ if (hex5.length & 1)
7169
7169
  throw new E("unexpected DER parsing assertion: unpadded hex");
7170
- return hex4;
7170
+ return hex5;
7171
7171
  },
7172
7172
  decode(data) {
7173
7173
  const { Err: E } = _DER;
@@ -7420,8 +7420,8 @@ function weierstrass(params, extraOpts = {}) {
7420
7420
  P.assertValidity();
7421
7421
  return P;
7422
7422
  }
7423
- static fromHex(hex4) {
7424
- return Point.fromBytes(hexToBytes3(hex4));
7423
+ static fromHex(hex5) {
7424
+ return Point.fromBytes(hexToBytes3(hex5));
7425
7425
  }
7426
7426
  get x() {
7427
7427
  return this.toAffine().x;
@@ -7862,8 +7862,8 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
7862
7862
  const s = bytes2.subarray(L3, L3 * 2);
7863
7863
  return new Signature(Fn2.fromBytes(r), Fn2.fromBytes(s), recid);
7864
7864
  }
7865
- static fromHex(hex4, format) {
7866
- return this.fromBytes(hexToBytes3(hex4), format);
7865
+ static fromHex(hex5, format) {
7866
+ return this.fromBytes(hexToBytes3(hex5), format);
7867
7867
  }
7868
7868
  assertRecovery() {
7869
7869
  const { recovery } = this;
@@ -9307,13 +9307,13 @@ function asafenumber2(value, title = "") {
9307
9307
  }
9308
9308
  }
9309
9309
  function numberToHexUnpadded2(num) {
9310
- const hex4 = abignumber2(num).toString(16);
9311
- return hex4.length & 1 ? "0" + hex4 : hex4;
9310
+ const hex5 = abignumber2(num).toString(16);
9311
+ return hex5.length & 1 ? "0" + hex5 : hex5;
9312
9312
  }
9313
- function hexToNumber2(hex4) {
9314
- if (typeof hex4 !== "string")
9315
- throw new TypeError("hex string expected, got " + typeof hex4);
9316
- return hex4 === "" ? _0n11 : BigInt("0x" + hex4);
9313
+ function hexToNumber2(hex5) {
9314
+ if (typeof hex5 !== "string")
9315
+ throw new TypeError("hex string expected, got " + typeof hex5);
9316
+ return hex5 === "" ? _0n11 : BigInt("0x" + hex5);
9317
9317
  }
9318
9318
  function bytesToNumberBE2(bytes2) {
9319
9319
  return hexToNumber2(bytesToHex(bytes2));
@@ -9327,10 +9327,10 @@ function numberToBytesBE2(n, len) {
9327
9327
  throw new Error("zero output length is invalid");
9328
9328
  n = abignumber2(n);
9329
9329
  const expectedLen = len * 2;
9330
- const hex4 = n.toString(16);
9331
- if (hex4.length > expectedLen)
9330
+ const hex5 = n.toString(16);
9331
+ if (hex5.length > expectedLen)
9332
9332
  throw new RangeError("number is too large");
9333
- return hexToBytes(hex4.padStart(expectedLen, "0"));
9333
+ return hexToBytes(hex5.padStart(expectedLen, "0"));
9334
9334
  }
9335
9335
  function numberToBytesLE2(n, len) {
9336
9336
  return numberToBytesBE2(n, len).reverse();
@@ -9432,7 +9432,7 @@ var init_utils6 = __esm({
9432
9432
  anumber5 = anumber2;
9433
9433
  bytesToHex4 = bytesToHex;
9434
9434
  concatBytes6 = (...arrays) => concatBytes3(...arrays);
9435
- hexToBytes4 = (hex4) => hexToBytes(hex4);
9435
+ hexToBytes4 = (hex5) => hexToBytes(hex5);
9436
9436
  isBytes5 = isBytes2;
9437
9437
  randomBytes7 = (bytesLength) => randomBytes3(bytesLength);
9438
9438
  _0n11 = /* @__PURE__ */ BigInt(0);
@@ -10412,8 +10412,8 @@ function edwards2(params, extraOpts = {}) {
10412
10412
  x = Fp2.neg(x);
10413
10413
  return Point.fromAffine({ x, y });
10414
10414
  }
10415
- static fromHex(hex4, zip215 = false) {
10416
- return Point.fromBytes(hexToBytes4(hex4), zip215);
10415
+ static fromHex(hex5, zip215 = false) {
10416
+ return Point.fromBytes(hexToBytes4(hex5), zip215);
10417
10417
  }
10418
10418
  get x() {
10419
10419
  return this.toAffine().x;
@@ -11026,12 +11026,12 @@ var init_der2 = __esm({
11026
11026
  abignumber2(num);
11027
11027
  if (num < _0n18)
11028
11028
  throw new E("integer: negative integers are not allowed");
11029
- let hex4 = numberToHexUnpadded2(num);
11030
- if (Number.parseInt(hex4[0], 16) & 8)
11031
- hex4 = "00" + hex4;
11032
- if (hex4.length & 1)
11029
+ let hex5 = numberToHexUnpadded2(num);
11030
+ if (Number.parseInt(hex5[0], 16) & 8)
11031
+ hex5 = "00" + hex5;
11032
+ if (hex5.length & 1)
11033
11033
  throw new E("unexpected DER parsing assertion: unpadded hex");
11034
- return hex4;
11034
+ return hex5;
11035
11035
  },
11036
11036
  decode(data) {
11037
11037
  const { Err: E } = _DER2;
@@ -11284,8 +11284,8 @@ function weierstrass2(params, extraOpts = {}) {
11284
11284
  P.assertValidity();
11285
11285
  return P;
11286
11286
  }
11287
- static fromHex(hex4) {
11288
- return Point.fromBytes(hexToBytes4(hex4));
11287
+ static fromHex(hex5) {
11288
+ return Point.fromBytes(hexToBytes4(hex5));
11289
11289
  }
11290
11290
  get x() {
11291
11291
  return this.toAffine().x;
@@ -11726,8 +11726,8 @@ function ecdsa2(Point, hash, ecdsaOpts = {}) {
11726
11726
  const s = bytes2.subarray(L3, L3 * 2);
11727
11727
  return new Signature(Fn2.fromBytes(r), Fn2.fromBytes(s), recid);
11728
11728
  }
11729
- static fromHex(hex4, format) {
11730
- return this.fromBytes(hexToBytes4(hex4), format);
11729
+ static fromHex(hex5, format) {
11730
+ return this.fromBytes(hexToBytes4(hex5), format);
11731
11731
  }
11732
11732
  assertRecovery() {
11733
11733
  const { recovery } = this;
@@ -13149,6 +13149,7 @@ __export(bundle_entry_exports, {
13149
13149
  WorkspaceSeedV1: () => WorkspaceSeedV1,
13150
13150
  assertBlindingValue: () => assertBlindingValue,
13151
13151
  blindedDigest: () => blindedDigest,
13152
+ blindedLabelV1: () => blindedLabelV1,
13152
13153
  buildRecordDisclosureV1: () => buildRecordDisclosureV1,
13153
13154
  carriesSaltKeyV2: () => carriesSaltKeyV2,
13154
13155
  checkEncryptedWriteSizeV1: () => checkEncryptedWriteSizeV1,
@@ -13170,6 +13171,7 @@ __export(bundle_entry_exports, {
13170
13171
  deriveRecordsIdKeyV1: () => deriveRecordsIdKeyV1,
13171
13172
  deriveRecordsKeysFromBaseV1: () => deriveRecordsKeysFromBaseV1,
13172
13173
  deriveRecordsKeysV1: () => deriveRecordsKeysV1,
13174
+ devicePublicV1: () => devicePublicV1,
13173
13175
  disclosureDigestFragmentV2: () => disclosureDigestFragmentV2,
13174
13176
  disclosureFragmentV1: () => disclosureFragmentV1,
13175
13177
  encryptDisclosureV1: () => encryptDisclosureV1,
@@ -13186,12 +13188,17 @@ __export(bundle_entry_exports, {
13186
13188
  keyWrapInfoV1: () => keyWrapInfoV1,
13187
13189
  keyWrapInfoV2: () => keyWrapInfoV2,
13188
13190
  localRecordsKeyProviderV1: () => localRecordsKeyProviderV1,
13191
+ makeDeviceKeysV1: () => makeDeviceKeysV1,
13189
13192
  matchHeldFile: () => matchHeldFile,
13190
13193
  memberTagV3: () => memberTagV3,
13191
13194
  mldsaSigningKeyFromSeedV1: () => mldsaSigningKeyFromSeedV1,
13192
13195
  newBlindingValue: () => newBlindingValue,
13193
13196
  newDisclosureKeyV1: () => newDisclosureKeyV1,
13194
13197
  newSaltKeyV2: () => newSaltKeyV2,
13198
+ openAckFlagNoteV1: () => openAckFlagNoteV1,
13199
+ openAckNoteV1: () => openAckNoteV1,
13200
+ openFlagDraftsV1: () => openFlagDraftsV1,
13201
+ openFlagNoteV1: () => openFlagNoteV1,
13195
13202
  openRecordEntryEnvelopeV1: () => openRecordEntryEnvelopeV1,
13196
13203
  openRecordEntryV2: () => openRecordEntryV2,
13197
13204
  openRecordEntryV3: () => openRecordEntryV3,
@@ -13218,18 +13225,27 @@ __export(bundle_entry_exports, {
13218
13225
  rotationChallengeV1: () => rotationChallengeV1,
13219
13226
  rotationProofHashV1: () => rotationProofHashV1,
13220
13227
  rotationProofV1: () => rotationProofV1,
13228
+ sealAckFlagNotesV1: () => sealAckFlagNotesV1,
13229
+ sealFlagDraftsV1: () => sealFlagDraftsV1,
13230
+ sealFlagNoteV1: () => sealFlagNoteV1,
13221
13231
  sealRecordEntryV1: () => sealRecordEntryV1,
13222
13232
  sealSeedWrapV1: () => sealSeedWrapV1,
13223
13233
  serializeBlindingFile: () => serializeBlindingFile,
13224
13234
  serializeRecordsKeyringFileV1: () => serializeRecordsKeyringFileV1,
13235
+ signApprovalV1: () => signApprovalV1,
13236
+ signDeviceMessageV1: () => signDeviceMessageV1,
13225
13237
  signMldsa65V1: () => signMldsa65V1,
13238
+ unwrapAnswerKeyV1: () => unwrapAnswerKeyV1,
13226
13239
  unwrapDisclosureKeyV1: () => unwrapDisclosureKeyV1,
13227
13240
  unwrapDisclosureKeyV2: () => unwrapDisclosureKeyV2,
13241
+ unwrapLinkKeyV1: () => unwrapLinkKeyV1,
13242
+ unwrapNoteKeyV1: () => unwrapNoteKeyV1,
13228
13243
  unwrapRecordKeyV1: () => unwrapRecordKeyV1,
13229
13244
  unwrapRecordKeyV2: () => unwrapRecordKeyV2,
13230
13245
  unwrapRecordsKeyV1: () => unwrapRecordsKeyV1,
13231
13246
  unwrapRecordsKeyV2: () => unwrapRecordsKeyV2,
13232
13247
  validateRecordItemsV3: () => validateRecordItemsV3,
13248
+ verifyDeviceMessageV1: () => verifyDeviceMessageV1,
13233
13249
  verifyMldsa65V1: () => verifyMldsa65V1,
13234
13250
  verifyRecordDisclosureV1: () => verifyRecordDisclosureV1,
13235
13251
  wireRecordIdV1: () => wireRecordIdV1,
@@ -13237,8 +13253,11 @@ __export(bundle_entry_exports, {
13237
13253
  withoutSaltKeysV2: () => withoutSaltKeysV2,
13238
13254
  workspacePublicKeyIdV1: () => workspacePublicKeyIdV1,
13239
13255
  workspaceSeedFromBytesV1: () => workspaceSeedFromBytesV1,
13256
+ wrapAnswerKeyV1: () => wrapAnswerKeyV1,
13240
13257
  wrapDisclosureKeyV1: () => wrapDisclosureKeyV1,
13241
13258
  wrapDisclosureKeyV2: () => wrapDisclosureKeyV2,
13259
+ wrapLinkKeyV1: () => wrapLinkKeyV1,
13260
+ wrapNoteKeyV1: () => wrapNoteKeyV1,
13242
13261
  wrapRecordKeyV1: () => wrapRecordKeyV1,
13243
13262
  wrapRecordKeyV2: () => wrapRecordKeyV2,
13244
13263
  wrapRecordsKeyV1: () => wrapRecordsKeyV1,
@@ -14405,6 +14424,11 @@ async function aesKey(key, usage) {
14405
14424
  const subtle2 = (await platformCrypto()).subtle;
14406
14425
  return subtle2.importKey("raw", key, { name: "AES-GCM" }, false, [usage]);
14407
14426
  }
14427
+ function isDecryptKey(key) {
14428
+ if (typeof CryptoKey === "undefined" || !(key instanceof CryptoKey) || key.type !== "secret" || !key.usages.includes("decrypt")) return false;
14429
+ const algorithm = key.algorithm;
14430
+ return algorithm.name === "AES-GCM" && algorithm.length === KEY_BYTES * 8;
14431
+ }
14408
14432
  async function encryptDisclosureV1(input) {
14409
14433
  const { key, handle } = input;
14410
14434
  if (!(key instanceof Uint8Array) || key.length !== KEY_BYTES || typeof handle !== "string") {
@@ -14428,7 +14452,8 @@ async function decryptDisclosureV1(input) {
14428
14452
  if (!shape.ok) return refuse2(shape.code);
14429
14453
  const bytes2 = fromBase64Url(input.envelope);
14430
14454
  const { key, handle } = input;
14431
- if (!(key instanceof Uint8Array) || key.length !== KEY_BYTES || typeof handle !== "string") {
14455
+ const held = isDecryptKey(key);
14456
+ if (!held && (!(key instanceof Uint8Array) || key.length !== KEY_BYTES) || typeof handle !== "string") {
14432
14457
  return refuse2("DISCLOSURE_ENVELOPE_AUTH_FAILED");
14433
14458
  }
14434
14459
  let plain;
@@ -14437,7 +14462,7 @@ async function decryptDisclosureV1(input) {
14437
14462
  plain = new Uint8Array(
14438
14463
  await subtle2.decrypt(
14439
14464
  { name: "AES-GCM", iv: bytes2.subarray(1, HEADER_BYTES), additionalData: aadOf(handle), tagLength: 128 },
14440
- await aesKey(key, "decrypt"),
14465
+ held ? key : await aesKey(key, "decrypt"),
14441
14466
  bytes2.subarray(HEADER_BYTES)
14442
14467
  )
14443
14468
  );
@@ -14706,6 +14731,9 @@ async function wireRecordIdV1(idKey, recordType, entityId) {
14706
14731
  async function wireReferenceIdV1(idKey, referenceId) {
14707
14732
  return wire16(idKey, concatBytes(utf8(L.referenceId), SEP5, utf8(referenceId)));
14708
14733
  }
14734
+ async function blindedLabelV1(idKey, name, value) {
14735
+ return `b1:${toBase64Url(await hmacSha256(bytesOf2(idKey), utf8(`${name.toLowerCase()}=${value}`)))}`;
14736
+ }
14709
14737
  async function contentTagV1(idKey, input) {
14710
14738
  const message = concatBytes(
14711
14739
  utf8(L.contentTag),
@@ -14997,6 +15025,13 @@ async function newBlindingValue() {
14997
15025
  // ../shared/src/records/signed-acknowledgment-v2.ts
14998
15026
  var MLDSA65_PUBLIC_KEY_BYTES = 1952;
14999
15027
  var MLDSA65_SIGNATURE_BYTES = 3309;
15028
+ function es256PublicPointV1(key) {
15029
+ if (!key || key.kty !== "EC" || key.crv !== "P-256") return null;
15030
+ const x = typeof key.x === "string" ? fromBase64Url(key.x) : null;
15031
+ const y = typeof key.y === "string" ? fromBase64Url(key.y) : null;
15032
+ if (!x || !y || x.length !== 32 || y.length !== 32) return null;
15033
+ return concatBytes(new Uint8Array([4]), x, y);
15034
+ }
15000
15035
 
15001
15036
  // ../shared/src/records-crypto/asymmetric/records-asymmetric-v1.ts
15002
15037
  var RECORDS_ASYMMETRIC_LABELS_V1 = {
@@ -15471,6 +15506,433 @@ async function verifyMldsa65V1(publicKey, message, signature) {
15471
15506
  return false;
15472
15507
  }
15473
15508
  }
15509
+
15510
+ // ../shared/src/records/link-handle-v1.ts
15511
+ var LINK_HANDLE_PATTERN = /^cs[hl]1_[A-Za-z0-9_-]{1,80}$/;
15512
+
15513
+ // ../shared/src/records/reader-crypto-v1.ts
15514
+ var READER_CRYPTO_LABELS_V1 = {
15515
+ deviceId: "pacspace:reader-device:v1",
15516
+ proofKey: "pacspace:device-proof-key:v1",
15517
+ deviceProof: "pacspace:device-proof:v1",
15518
+ deviceConfirmed: "pacspace:device-confirmed:v1",
15519
+ deviceApproval: "pacspace:device-approval:v1",
15520
+ signedRequest: "pacspace:signed-request:v1",
15521
+ deviceDisconnect: "pacspace:device-disconnect:v1",
15522
+ sealedNote: "pacspace:sealed-note:v1",
15523
+ workspaceKey: "pacspace:workspace-key:v1"
15524
+ };
15525
+ var SEALED_NOTE_SCHEMA_V1 = "sealed-note/v1";
15526
+ var DEVICE_XWING_PUBLIC_KEY_BYTES_V1 = 1216;
15527
+ var DEVICE_P256_SPKI_BYTES_V1 = 91;
15528
+ var DEVICE_CODE_DIGITS_V1 = 40;
15529
+ var LINK_KEY_BYTES_V1 = 32;
15530
+ var SEALED_NOTE_MAX_CHARS_V1 = 65536;
15531
+ var ReaderCryptoError = class extends Error {
15532
+ constructor(code) {
15533
+ super(code);
15534
+ this.code = code;
15535
+ this.name = "ReaderCryptoError";
15536
+ }
15537
+ };
15538
+ var SEP7 = new Uint8Array([0]);
15539
+ var HEX644 = /^[0-9a-f]{64}$/;
15540
+ var P256_SPKI_PREFIX = Uint8Array.from([
15541
+ 48,
15542
+ 89,
15543
+ 48,
15544
+ 19,
15545
+ 6,
15546
+ 7,
15547
+ 42,
15548
+ 134,
15549
+ 72,
15550
+ 206,
15551
+ 61,
15552
+ 2,
15553
+ 1,
15554
+ 6,
15555
+ 8,
15556
+ 42,
15557
+ 134,
15558
+ 72,
15559
+ 206,
15560
+ 61,
15561
+ 3,
15562
+ 1,
15563
+ 7,
15564
+ 3,
15565
+ 66,
15566
+ 0
15567
+ ]);
15568
+ var hex4 = (bytes2) => Array.from(bytes2, (b) => b.toString(16).padStart(2, "0")).join("");
15569
+ var HANDLE = LINK_HANDLE_PATTERN;
15570
+ var PART = /^[\x21-\x39\x3b-\x7e]{1,128}$/;
15571
+ var KIND = /^[a-z][a-z0-9-]{0,31}$/;
15572
+ var TRAIL_ID = /^[a-z0-9]{20,32}$/;
15573
+ function check(ok) {
15574
+ if (!ok) throw new ReaderCryptoError("READER_BINDING_INVALID");
15575
+ }
15576
+ var isEpoch = (n) => Number.isSafeInteger(n) && n >= 1;
15577
+ function linkKeyBindingV1(handle, epoch) {
15578
+ check(HANDLE.test(handle) && isEpoch(epoch));
15579
+ return `link-key:${handle}:${epoch}`;
15580
+ }
15581
+ function answerKeyBindingV1(handle, requestRef) {
15582
+ check(HANDLE.test(handle) && PART.test(requestRef));
15583
+ return `answer:${handle}:${requestRef}`;
15584
+ }
15585
+ function scopeText(scope) {
15586
+ if (scope && "handle" in scope) {
15587
+ check(HANDLE.test(scope.handle));
15588
+ return scope.handle;
15589
+ }
15590
+ check(!!scope && typeof scope.trailRuleOf === "string" && TRAIL_ID.test(scope.trailRuleOf));
15591
+ return `trail-rule:${scope.trailRuleOf}`;
15592
+ }
15593
+ function noteParts(name) {
15594
+ check(!!name && KIND.test(name.kind) && PART.test(name.ref) && isEpoch(name.n));
15595
+ return `${scopeText(name.scope)}:${name.kind}:${name.ref}:${name.n}`;
15596
+ }
15597
+ function noteKeyBindingV1(name) {
15598
+ return `note:${noteParts(name)}`;
15599
+ }
15600
+ function noteAdditionalDataV1(name) {
15601
+ return `${READER_CRYPTO_LABELS_V1.sealedNote}:${noteParts(name)}`;
15602
+ }
15603
+ function ackFlagNotesKeyNameV1(handle, checkRef) {
15604
+ return { scope: { handle }, kind: "ack-flags", ref: checkRef, n: 1 };
15605
+ }
15606
+ function ackFlagNoteNameV1(handle, checkRef, record, entry) {
15607
+ check(isEpoch(record) && isEpoch(entry));
15608
+ return { scope: { handle }, kind: "ack-flag", ref: `${checkRef}.${record}.${entry}`, n: 1 };
15609
+ }
15610
+ function ackNoteNameV1(handle, checkRef) {
15611
+ return { scope: { handle }, kind: "ack-note", ref: checkRef, n: 1 };
15612
+ }
15613
+ async function p256SpkiOfJwkV1(jwk) {
15614
+ const point = es256PublicPointV1(jwk);
15615
+ if (!point) throw new ReaderCryptoError("READER_DEVICE_KEYS_INVALID");
15616
+ const { subtle: subtle2 } = await platformCrypto();
15617
+ let spki;
15618
+ try {
15619
+ const key = await subtle2.importKey("jwk", { kty: "EC", crv: "P-256", x: jwk.x, y: jwk.y, ext: true }, { name: "ECDSA", namedCurve: "P-256" }, true, ["verify"]);
15620
+ spki = new Uint8Array(await subtle2.exportKey("spki", key));
15621
+ } catch {
15622
+ throw new ReaderCryptoError("READER_DEVICE_KEYS_INVALID");
15623
+ }
15624
+ const expected = concatBytes(P256_SPKI_PREFIX, point);
15625
+ if (spki.length !== DEVICE_P256_SPKI_BYTES_V1 || spki.some((b, i) => b !== expected[i])) throw new ReaderCryptoError("READER_DEVICE_KEYS_INVALID");
15626
+ return spki;
15627
+ }
15628
+ async function deviceIdV1(keys) {
15629
+ if (!(keys?.xwingPublicKey instanceof Uint8Array) || keys.xwingPublicKey.length !== DEVICE_XWING_PUBLIC_KEY_BYTES_V1) {
15630
+ throw new ReaderCryptoError("READER_DEVICE_KEYS_INVALID");
15631
+ }
15632
+ if (!(keys.mldsaPublicKey instanceof Uint8Array) || keys.mldsaPublicKey.length !== MLDSA65_PUBLIC_KEY_BYTES) {
15633
+ throw new ReaderCryptoError("READER_DEVICE_KEYS_INVALID");
15634
+ }
15635
+ const spki = await p256SpkiOfJwkV1(keys.p256Jwk);
15636
+ return hex4(await sha256(concatBytes(utf8(READER_CRYPTO_LABELS_V1.deviceId), SEP7, keys.xwingPublicKey, SEP7, spki, SEP7, keys.mldsaPublicKey)));
15637
+ }
15638
+ function deviceCodeV1(deviceId) {
15639
+ check(typeof deviceId === "string" && HEX644.test(deviceId));
15640
+ let n = 0n;
15641
+ for (let i = 0; i < 17; i += 1) n = n << 8n | BigInt(parseInt(deviceId.slice(i * 2, i * 2 + 2), 16));
15642
+ const digits = (n % 10n ** 40n).toString().padStart(DEVICE_CODE_DIGITS_V1, "0");
15643
+ return digits.match(/.{5}/g).join(" ");
15644
+ }
15645
+ function assertKey(key) {
15646
+ if (!(key instanceof Uint8Array) || key.length !== LINK_KEY_BYTES_V1) throw new ReaderCryptoError("READER_KEY_INVALID");
15647
+ }
15648
+ function deviceMessage(label, handle, epoch, deviceId) {
15649
+ check(HANDLE.test(handle) && isEpoch(epoch) && typeof deviceId === "string" && HEX644.test(deviceId));
15650
+ return `${label}:${handle}:${epoch}:${deviceId}`;
15651
+ }
15652
+ function approvalMessageV1(handle, epoch, newDeviceId) {
15653
+ return deviceMessage(READER_CRYPTO_LABELS_V1.deviceApproval, handle, epoch, newDeviceId);
15654
+ }
15655
+ var NOTE_MEMBERS = ["schema", "iv", "ct"];
15656
+ function readSealedNoteShapeV1(value) {
15657
+ const bad = { ok: false, code: "SEALED_NOTE_MALFORMED" };
15658
+ if (!value || typeof value !== "object" || Array.isArray(value)) return bad;
15659
+ const v = value;
15660
+ if (Object.keys(v).length !== NOTE_MEMBERS.length || !NOTE_MEMBERS.every((k) => Object.prototype.hasOwnProperty.call(v, k))) return bad;
15661
+ if (v.schema !== SEALED_NOTE_SCHEMA_V1 || typeof v.iv !== "string" || typeof v.ct !== "string" || v.ct.length > SEALED_NOTE_MAX_CHARS_V1) return bad;
15662
+ const iv = fromBase64Url(v.iv);
15663
+ const ct = fromBase64Url(v.ct);
15664
+ if (!iv || iv.length !== 12 || toBase64Url(iv) !== v.iv || !ct || ct.length <= 16 || toBase64Url(ct) !== v.ct) return bad;
15665
+ return { ok: true, iv, ct };
15666
+ }
15667
+ async function noteCipher(key, usage) {
15668
+ const { subtle: subtle2 } = await platformCrypto();
15669
+ return subtle2.importKey("raw", Uint8Array.from(key), { name: "AES-GCM" }, false, [usage]);
15670
+ }
15671
+ async function sealNoteWithV1(text, name, key, iv) {
15672
+ assertKey(key);
15673
+ if (typeof text !== "string" || !(iv instanceof Uint8Array) || iv.length !== 12) throw new ReaderCryptoError("SEALED_NOTE_MALFORMED");
15674
+ const aad = utf8(noteAdditionalDataV1(name));
15675
+ const { subtle: subtle2 } = await platformCrypto();
15676
+ const ct = new Uint8Array(
15677
+ await subtle2.encrypt({ name: "AES-GCM", iv: Uint8Array.from(iv), additionalData: aad, tagLength: 128 }, await noteCipher(key, "encrypt"), utf8(text))
15678
+ );
15679
+ const note2 = { schema: SEALED_NOTE_SCHEMA_V1, iv: toBase64Url(iv), ct: toBase64Url(ct) };
15680
+ if (note2.ct.length > SEALED_NOTE_MAX_CHARS_V1) throw new ReaderCryptoError("SEALED_NOTE_MALFORMED");
15681
+ return note2;
15682
+ }
15683
+ async function sealNoteV1(text, name) {
15684
+ const key = randomBytes(LINK_KEY_BYTES_V1);
15685
+ return { note: await sealNoteWithV1(text, name, key, randomBytes(12)), key };
15686
+ }
15687
+ async function openNoteV1(input) {
15688
+ const shape = readSealedNoteShapeV1(input?.note);
15689
+ if (!shape.ok) return shape;
15690
+ try {
15691
+ assertKey(input.key);
15692
+ const aad = utf8(noteAdditionalDataV1(input.name));
15693
+ const { subtle: subtle2 } = await platformCrypto();
15694
+ const plain = await subtle2.decrypt({ name: "AES-GCM", iv: shape.iv, additionalData: aad, tagLength: 128 }, await noteCipher(input.key, "decrypt"), shape.ct);
15695
+ return { ok: true, text: new TextDecoder("utf-8", { fatal: true }).decode(plain) };
15696
+ } catch {
15697
+ return { ok: false, code: "SEALED_NOTE_AUTH_FAILED" };
15698
+ }
15699
+ }
15700
+
15701
+ // ../shared/src/records-crypto/asymmetric/reader-wraps-v1.ts
15702
+ async function makeDeviceKeysV1(input) {
15703
+ const xwing = await workspaceSeedFromBytesV1(input.xwingSeed);
15704
+ const mldsa = await mldsaSigningKeyFromSeedV1(input.mldsaSeed);
15705
+ const deviceId = await deviceIdV1({ xwingPublicKey: xwing.publicKey, p256Jwk: input.p256Jwk, mldsaPublicKey: mldsa.publicKey });
15706
+ return { xwing, mldsa, p256Jwk: input.p256Jwk, deviceId, code: deviceCodeV1(deviceId) };
15707
+ }
15708
+ function devicePublicV1(keys) {
15709
+ return { xwingPublicKey: toBase64Url(keys.xwing.publicKey), p256Jwk: keys.p256Jwk, mldsaPublicKey: toBase64Url(keys.mldsa.publicKey) };
15710
+ }
15711
+ function wrapLinkKeyV1(publicKey, linkKey, handle, epoch) {
15712
+ return wrapDisclosureKeyV1(publicKey, linkKey, linkKeyBindingV1(handle, epoch));
15713
+ }
15714
+ function unwrapLinkKeyV1(input) {
15715
+ return unwrapDisclosureKeyV1({ seed: input.seed, wrap: input.wrap, handle: linkKeyBindingV1(input.handle, input.epoch) });
15716
+ }
15717
+ function wrapAnswerKeyV1(publicKey, answerKey, handle, requestRef) {
15718
+ return wrapDisclosureKeyV1(publicKey, answerKey, answerKeyBindingV1(handle, requestRef));
15719
+ }
15720
+ function unwrapAnswerKeyV1(input) {
15721
+ return unwrapDisclosureKeyV1({ seed: input.seed, wrap: input.wrap, handle: answerKeyBindingV1(input.handle, input.requestRef) });
15722
+ }
15723
+ function wrapNoteKeyV1(publicKey, noteKey, name) {
15724
+ return wrapDisclosureKeyV1(publicKey, noteKey, noteKeyBindingV1(name));
15725
+ }
15726
+ function unwrapNoteKeyV1(input) {
15727
+ return unwrapDisclosureKeyV1({ seed: input.seed, wrap: input.wrap, handle: noteKeyBindingV1(input.name) });
15728
+ }
15729
+ function signApprovalV1(input) {
15730
+ return signDeviceMessageV1({ p256PrivateKey: input.p256PrivateKey, mldsa: input.mldsa, message: approvalMessageV1(input.handle, input.epoch, input.newDeviceId) });
15731
+ }
15732
+ async function signDeviceMessageV1(input) {
15733
+ const message = new Uint8Array(utf8(input.message));
15734
+ const { subtle: subtle2 } = await platformCrypto();
15735
+ const es256 = new Uint8Array(await subtle2.sign({ name: "ECDSA", hash: "SHA-256" }, input.p256PrivateKey, message));
15736
+ const mldsa = await signMldsa65V1(input.mldsa, message);
15737
+ return { signature: toBase64Url(es256), mldsaSignature: toBase64Url(mldsa) };
15738
+ }
15739
+ async function verifyDeviceMessageV1(input) {
15740
+ try {
15741
+ if (typeof input.signature !== "string" || typeof input.mldsaSignature !== "string") return false;
15742
+ const es256 = fromBase64Url(input.signature);
15743
+ const mldsa = fromBase64Url(input.mldsaSignature);
15744
+ const jwk = input.p256Jwk;
15745
+ if (!es256 || es256.length !== 64 || !mldsa || !jwk || jwk.kty !== "EC" || jwk.crv !== "P-256") return false;
15746
+ const message = new Uint8Array(utf8(input.message));
15747
+ const { subtle: subtle2 } = await platformCrypto();
15748
+ const key = await subtle2.importKey("jwk", { kty: "EC", crv: "P-256", x: jwk.x, y: jwk.y, ext: true }, { name: "ECDSA", namedCurve: "P-256" }, false, ["verify"]);
15749
+ const first = await subtle2.verify({ name: "ECDSA", hash: "SHA-256" }, key, es256, message);
15750
+ return first && await verifyMldsa65V1(input.mldsaPublicKey, message, mldsa);
15751
+ } catch {
15752
+ return false;
15753
+ }
15754
+ }
15755
+
15756
+ // ../shared/src/records/shared-record-ack-v2.ts
15757
+ var SHARED_RECORD_ACK_MAX_CHARS_V2 = 256 * 1024;
15758
+ var SHARED_RECORD_ACK_NOTE_MAX_V2 = 2e3;
15759
+ var SHARED_RECORD_ACK_FLAG_NOTE_MAX_V2 = 500;
15760
+ var SHARED_RECORD_ACK_SEALED_FLAG_NOTE_MAX_CHARS_V2 = Math.ceil((SHARED_RECORD_ACK_FLAG_NOTE_MAX_V2 * 3 + 16) * 4 / 3);
15761
+ var SHARED_RECORD_ACK_SEALED_NOTE_MAX_CHARS_V2 = Math.ceil((SHARED_RECORD_ACK_NOTE_MAX_V2 * 3 + 16) * 4 / 3);
15762
+ var CONTROL = /[\u0000-\u0008\u000b-\u001f\u007f]/;
15763
+ var Problem = class extends Error {
15764
+ };
15765
+ function note(value, path, max) {
15766
+ if (value === null) return null;
15767
+ if (typeof value !== "string" || value.length === 0 || value.length > max || CONTROL.test(value) || value.trim() !== value) throw new Problem(path);
15768
+ return value;
15769
+ }
15770
+ function readSharedRecordAckFlagTextV2(value) {
15771
+ try {
15772
+ return typeof value === "string" ? note(value, "note", SHARED_RECORD_ACK_FLAG_NOTE_MAX_V2) : null;
15773
+ } catch {
15774
+ return null;
15775
+ }
15776
+ }
15777
+ function readSharedRecordAckNoteTextV2(value) {
15778
+ try {
15779
+ return typeof value === "string" ? note(value, "note", SHARED_RECORD_ACK_NOTE_MAX_V2) : null;
15780
+ } catch {
15781
+ return null;
15782
+ }
15783
+ }
15784
+
15785
+ // ../shared/src/records-crypto/asymmetric/ack-flag-notes-v1.ts
15786
+ async function sealAckFlagNotesV1(input) {
15787
+ const devices = input?.devices;
15788
+ if (!Array.isArray(devices) || devices.length === 0 || new Set(devices.map((d) => d?.deviceId)).size !== devices.length || !(input.workspace instanceof Uint8Array)) {
15789
+ throw new ReaderCryptoError("READER_DEVICE_KEYS_INVALID");
15790
+ }
15791
+ const own = input.note ?? null;
15792
+ if (!Array.isArray(input.flags) || input.flags.some((f) => readSharedRecordAckFlagTextV2(f?.text) === null)) throw new ReaderCryptoError("SEALED_NOTE_MALFORMED");
15793
+ if (own !== null && readSharedRecordAckNoteTextV2(own) === null) throw new ReaderCryptoError("SEALED_NOTE_MALFORMED");
15794
+ if (input.flags.length === 0 && own === null) throw new ReaderCryptoError("SEALED_NOTE_MALFORMED");
15795
+ const keyName = ackFlagNotesKeyNameV1(input.handle, input.checkRef);
15796
+ const key = randomBytes(LINK_KEY_BYTES_V1);
15797
+ try {
15798
+ const notes = [];
15799
+ for (const f of input.flags) notes.push(await sealNoteWithV1(f.text, ackFlagNoteNameV1(input.handle, input.checkRef, f.record, f.entry), key, randomBytes(12)));
15800
+ const note2 = own === null ? null : await sealNoteWithV1(own, ackNoteNameV1(input.handle, input.checkRef), key, randomBytes(12));
15801
+ const wraps = [];
15802
+ for (const d of devices) wraps.push({ deviceId: d.deviceId, wrap: await wrapNoteKeyV1(d.xwingPublicKey, key, keyName) });
15803
+ return { notes, note: note2, keys: { devices: wraps, workspace: await wrapNoteKeyV1(input.workspace, key, keyName) } };
15804
+ } finally {
15805
+ key.fill(0);
15806
+ }
15807
+ }
15808
+ async function openAckNoteV1(input) {
15809
+ return openUnder(input, () => ackNoteNameV1(input.handle, input.checkRef));
15810
+ }
15811
+ async function openUnder(input, name) {
15812
+ try {
15813
+ const unwrapped = await unwrapNoteKeyV1({ seed: input.seed, wrap: input.wrap, name: ackFlagNotesKeyNameV1(input.handle, input.checkRef) });
15814
+ if (!unwrapped.ok) return { ok: false, code: unwrapped.code };
15815
+ try {
15816
+ return await openNoteV1({ note: input.note, key: unwrapped.disclosureKey, name: name() });
15817
+ } finally {
15818
+ unwrapped.disclosureKey.fill(0);
15819
+ }
15820
+ } catch {
15821
+ return { ok: false, code: "SEALED_NOTE_AUTH_FAILED" };
15822
+ }
15823
+ }
15824
+ async function openAckFlagNoteV1(input) {
15825
+ return openUnder(input, () => ackFlagNoteNameV1(input.handle, input.checkRef, input.record, input.entry));
15826
+ }
15827
+
15828
+ // ../shared/src/records/trail-index-v1.ts
15829
+ var import_ethers7 = require("ethers");
15830
+
15831
+ // ../shared/src/records/reader-link-v1.ts
15832
+ var SHARE_REFERENCE_PATTERN = /^SR-[0-9A-Za-z]{8}$/;
15833
+
15834
+ // ../shared/src/records/flag-threads-v1.ts
15835
+ var FLAG_TEXT_MAX_V1 = 2e3;
15836
+ var FLAG_SEALED_NOTE_MAX_CHARS_V1 = Math.ceil((FLAG_TEXT_MAX_V1 * 4 + 16) * 4 / 3);
15837
+ var FLAG_DRAFTS_MAX_V1 = 100;
15838
+ var FLAG_DRAFT_NOTE_MAX_V1 = 500;
15839
+ var FLAG_DRAFTS_SCHEMA_V1 = "flag-drafts/v1";
15840
+ var CONTROL2 = /[\u0000-\u0008\u000b-\u001f\u007f]/;
15841
+ var isPlain = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
15842
+ var exactly = (v, keys) => Object.keys(v).length === keys.length && keys.every((k) => Object.prototype.hasOwnProperty.call(v, k));
15843
+ var counting = (n, min) => Number.isSafeInteger(n) && n >= min;
15844
+ function flagDraftsNoteNameV1(input) {
15845
+ if (typeof input?.reference !== "string" || !SHARE_REFERENCE_PATTERN.test(input.reference) || !counting(input.version, 1)) {
15846
+ throw new ReaderCryptoError("READER_BINDING_INVALID");
15847
+ }
15848
+ assertHandle(input.handle);
15849
+ return { scope: { handle: input.handle }, kind: "flag-drafts", ref: input.reference, n: input.version };
15850
+ }
15851
+ function assertHandle(handle) {
15852
+ if (typeof handle !== "string" || !/^csh1_[A-Za-z0-9_-]{1,80}$/.test(handle)) throw new ReaderCryptoError("READER_BINDING_INVALID");
15853
+ }
15854
+ function readFlagTextV1(value) {
15855
+ if (typeof value !== "string") return null;
15856
+ const text = value.trim();
15857
+ if (!text || text.length > FLAG_TEXT_MAX_V1 || CONTROL2.test(text)) return null;
15858
+ return text;
15859
+ }
15860
+ function readFlagDraftsV1(value) {
15861
+ const bad = { ok: false };
15862
+ if (!isPlain(value) || !exactly(value, ["schema", "flags"]) || value.schema !== FLAG_DRAFTS_SCHEMA_V1) return bad;
15863
+ if (!Array.isArray(value.flags) || value.flags.length > FLAG_DRAFTS_MAX_V1) return bad;
15864
+ const seen = /* @__PURE__ */ new Set();
15865
+ const flags = [];
15866
+ for (const raw of value.flags) {
15867
+ if (!isPlain(raw) || !exactly(raw, ["record", "entry", "note"]) || !counting(raw.record, 1) || !counting(raw.entry, 1)) return bad;
15868
+ const key = `${raw.record}:${raw.entry}`;
15869
+ if (seen.has(key)) return bad;
15870
+ seen.add(key);
15871
+ let note2 = null;
15872
+ if (raw.note !== null) {
15873
+ if (typeof raw.note !== "string" || !raw.note || raw.note.length > FLAG_DRAFT_NOTE_MAX_V1 || CONTROL2.test(raw.note)) return bad;
15874
+ note2 = raw.note;
15875
+ }
15876
+ flags.push({ record: raw.record, entry: raw.entry, note: note2 });
15877
+ }
15878
+ return { ok: true, drafts: { schema: FLAG_DRAFTS_SCHEMA_V1, flags } };
15879
+ }
15880
+
15881
+ // ../shared/src/records-crypto/asymmetric/flag-notes-v1.ts
15882
+ async function sealTo(text, name, devices, workspace) {
15883
+ if (!Array.isArray(devices) || new Set(devices.map((d) => d?.deviceId)).size !== devices.length || devices.length === 0 && workspace === null) {
15884
+ throw new ReaderCryptoError("READER_DEVICE_KEYS_INVALID");
15885
+ }
15886
+ const { note: note2, key } = await sealNoteV1(text, name);
15887
+ try {
15888
+ const wraps = [];
15889
+ for (const d of devices) wraps.push({ deviceId: d.deviceId, wrap: await wrapNoteKeyV1(d.xwingPublicKey, key, name) });
15890
+ return { note: note2, wraps, workspace: workspace ? await wrapNoteKeyV1(workspace, key, name) : null };
15891
+ } finally {
15892
+ key.fill(0);
15893
+ }
15894
+ }
15895
+ async function sealFlagNoteV1(input) {
15896
+ const text = readFlagTextV1(input?.text);
15897
+ if (text === null) throw new ReaderCryptoError("SEALED_NOTE_MALFORMED");
15898
+ return sealTo(text, input.name, input.devices, input.workspace ?? null);
15899
+ }
15900
+ async function openFlagNoteV1(input) {
15901
+ try {
15902
+ const unwrapped = await unwrapNoteKeyV1({ seed: input.seed, wrap: input.wrap, name: input.name });
15903
+ if (!unwrapped.ok) return { ok: false, code: unwrapped.code };
15904
+ try {
15905
+ return await openNoteV1({ note: input.note, key: unwrapped.disclosureKey, name: input.name });
15906
+ } finally {
15907
+ unwrapped.disclosureKey.fill(0);
15908
+ }
15909
+ } catch {
15910
+ return { ok: false, code: "SEALED_NOTE_AUTH_FAILED" };
15911
+ }
15912
+ }
15913
+ async function sealFlagDraftsV1(input) {
15914
+ const read = readFlagDraftsV1(input?.drafts);
15915
+ if (!read.ok || !Array.isArray(input.devices) || input.devices.length === 0) throw new ReaderCryptoError("SEALED_NOTE_MALFORMED");
15916
+ const name = flagDraftsNoteNameV1({ handle: input.handle, reference: input.reference, version: input.version });
15917
+ const { note: note2, wraps } = await sealTo(JSON.stringify(read.drafts), name, input.devices, null);
15918
+ return { note: note2, wraps };
15919
+ }
15920
+ async function openFlagDraftsV1(input) {
15921
+ let name;
15922
+ try {
15923
+ name = flagDraftsNoteNameV1({ handle: input.handle, reference: input.reference, version: input.version });
15924
+ } catch {
15925
+ return { ok: false, code: "READER_BINDING_INVALID" };
15926
+ }
15927
+ const opened = await openFlagNoteV1({ note: input.note, wrap: input.wrap, seed: input.seed, name });
15928
+ if (!opened.ok) return opened;
15929
+ try {
15930
+ const read = readFlagDraftsV1(JSON.parse(opened.text));
15931
+ return read.ok ? read : { ok: false, code: "SEALED_NOTE_MALFORMED" };
15932
+ } catch {
15933
+ return { ok: false, code: "SEALED_NOTE_MALFORMED" };
15934
+ }
15935
+ }
15474
15936
  // Annotate the CommonJS export names for ESM import in node:
15475
15937
  0 && (module.exports = {
15476
15938
  BLINDING_FILE_MAX_BYTES,
@@ -15529,6 +15991,7 @@ async function verifyMldsa65V1(publicKey, message, signature) {
15529
15991
  WorkspaceSeedV1,
15530
15992
  assertBlindingValue,
15531
15993
  blindedDigest,
15994
+ blindedLabelV1,
15532
15995
  buildRecordDisclosureV1,
15533
15996
  carriesSaltKeyV2,
15534
15997
  checkEncryptedWriteSizeV1,
@@ -15550,6 +16013,7 @@ async function verifyMldsa65V1(publicKey, message, signature) {
15550
16013
  deriveRecordsIdKeyV1,
15551
16014
  deriveRecordsKeysFromBaseV1,
15552
16015
  deriveRecordsKeysV1,
16016
+ devicePublicV1,
15553
16017
  disclosureDigestFragmentV2,
15554
16018
  disclosureFragmentV1,
15555
16019
  encryptDisclosureV1,
@@ -15566,12 +16030,17 @@ async function verifyMldsa65V1(publicKey, message, signature) {
15566
16030
  keyWrapInfoV1,
15567
16031
  keyWrapInfoV2,
15568
16032
  localRecordsKeyProviderV1,
16033
+ makeDeviceKeysV1,
15569
16034
  matchHeldFile,
15570
16035
  memberTagV3,
15571
16036
  mldsaSigningKeyFromSeedV1,
15572
16037
  newBlindingValue,
15573
16038
  newDisclosureKeyV1,
15574
16039
  newSaltKeyV2,
16040
+ openAckFlagNoteV1,
16041
+ openAckNoteV1,
16042
+ openFlagDraftsV1,
16043
+ openFlagNoteV1,
15575
16044
  openRecordEntryEnvelopeV1,
15576
16045
  openRecordEntryV2,
15577
16046
  openRecordEntryV3,
@@ -15598,18 +16067,27 @@ async function verifyMldsa65V1(publicKey, message, signature) {
15598
16067
  rotationChallengeV1,
15599
16068
  rotationProofHashV1,
15600
16069
  rotationProofV1,
16070
+ sealAckFlagNotesV1,
16071
+ sealFlagDraftsV1,
16072
+ sealFlagNoteV1,
15601
16073
  sealRecordEntryV1,
15602
16074
  sealSeedWrapV1,
15603
16075
  serializeBlindingFile,
15604
16076
  serializeRecordsKeyringFileV1,
16077
+ signApprovalV1,
16078
+ signDeviceMessageV1,
15605
16079
  signMldsa65V1,
16080
+ unwrapAnswerKeyV1,
15606
16081
  unwrapDisclosureKeyV1,
15607
16082
  unwrapDisclosureKeyV2,
16083
+ unwrapLinkKeyV1,
16084
+ unwrapNoteKeyV1,
15608
16085
  unwrapRecordKeyV1,
15609
16086
  unwrapRecordKeyV2,
15610
16087
  unwrapRecordsKeyV1,
15611
16088
  unwrapRecordsKeyV2,
15612
16089
  validateRecordItemsV3,
16090
+ verifyDeviceMessageV1,
15613
16091
  verifyMldsa65V1,
15614
16092
  verifyRecordDisclosureV1,
15615
16093
  wireRecordIdV1,
@@ -15617,8 +16095,11 @@ async function verifyMldsa65V1(publicKey, message, signature) {
15617
16095
  withoutSaltKeysV2,
15618
16096
  workspacePublicKeyIdV1,
15619
16097
  workspaceSeedFromBytesV1,
16098
+ wrapAnswerKeyV1,
15620
16099
  wrapDisclosureKeyV1,
15621
16100
  wrapDisclosureKeyV2,
16101
+ wrapLinkKeyV1,
16102
+ wrapNoteKeyV1,
15622
16103
  wrapRecordKeyV1,
15623
16104
  wrapRecordKeyV2,
15624
16105
  wrapRecordsKeyV1,