@opentdf/sdk 0.4.0-beta.27 → 0.4.0-beta.29

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.
@@ -51,6 +51,7 @@ export type EncryptParams = {
51
51
  splitPlan?: SplitStep[];
52
52
  streamMiddleware?: EncryptStreamMiddleware;
53
53
  assertionConfigs?: AssertionConfig[];
54
+ systemMetadataAssertion?: boolean;
54
55
  defaultKASEndpoint?: string;
55
56
 
56
57
  // Preferred wrapping key algorithm. Used when KID resolution is not available.
@@ -500,6 +501,19 @@ class EncryptParamsBuilder {
500
501
  this._params.assertionConfigs = assertionConfigs;
501
502
  return this;
502
503
  }
504
+
505
+ /**
506
+ * Specifies whether a default system metadata assertion should be automatically
507
+ * included during the encryption process.
508
+ *
509
+ * @param {boolean} systemMetadataAssertion - True to include the system metadata assertion, false otherwise.
510
+ * @returns {EncryptParamsBuilder} The current instance of the EncryptParamsBuilder for method chaining.
511
+ * @see {@link getSystemMetadataAssertionConfig}
512
+ */
513
+ withSystemMetadataAssertion(systemMetadataAssertion: boolean): EncryptParamsBuilder {
514
+ this._params.systemMetadataAssertion = systemMetadataAssertion;
515
+ return this;
516
+ }
503
517
  }
504
518
 
505
519
  export type DecryptKeyMiddleware = (key: Binary) => Promise<Binary>;
@@ -721,6 +721,7 @@ export class Client {
721
721
  keyForEncryption,
722
722
  keyForManifest,
723
723
  assertionConfigs: opts.assertionConfigs,
724
+ systemMetadataAssertion: opts.systemMetadataAssertion,
724
725
  tdfSpecVersion,
725
726
  };
726
727
 
package/tdf3/src/tdf.ts CHANGED
@@ -147,6 +147,7 @@ export type EncryptConfiguration = {
147
147
  keyForEncryption: KeyInfo;
148
148
  keyForManifest: KeyInfo;
149
149
  assertionConfigs?: AssertionConfig[];
150
+ systemMetadataAssertion?: boolean;
150
151
  tdfSpecVersion?: string;
151
152
  };
152
153
 
@@ -534,8 +535,24 @@ export async function writeStream(cfg: EncryptConfiguration): Promise<DecoratedR
534
535
  manifest.encryptionInformation.integrityInformation.segments = segmentInfos;
535
536
 
536
537
  manifest.encryptionInformation.method.isStreamable = true;
537
-
538
538
  const signedAssertions: assertions.Assertion[] = [];
539
+ if (cfg.systemMetadataAssertion) {
540
+ const systemMetadataConfigBase = assertions.getSystemMetadataAssertionConfig();
541
+ const signingKeyForSystemMetadata: AssertionKey = {
542
+ alg: 'HS256', // Default algorithm, can be configured if needed
543
+ key: new Uint8Array(cfg.keyForEncryption.unwrappedKeyBinary.asArrayBuffer()),
544
+ };
545
+ signedAssertions.push(
546
+ await assertions.CreateAssertion(
547
+ aggregateHash,
548
+ {
549
+ ...systemMetadataConfigBase, // Spread the properties from the base config
550
+ signingKey: signingKeyForSystemMetadata, // Add the signing key
551
+ },
552
+ cfg.tdfSpecVersion // Pass the TDF spec version
553
+ )
554
+ );
555
+ }
539
556
  if (cfg.assertionConfigs && cfg.assertionConfigs.length > 0) {
540
557
  await Promise.all(
541
558
  cfg.assertionConfigs.map(async (assertionConfig) => {
@@ -3,7 +3,8 @@ import { InvalidFileError } from '../../../src/errors.js';
3
3
 
4
4
  export function unwrapHtml(htmlPayload: Uint8Array): Uint8Array {
5
5
  const html = new TextDecoder().decode(htmlPayload);
6
- const payloadRe = /<input id=['"]?data-input['"]?[^>]*?value=['"]?([a-zA-Z0-9+/=]+)['"]?/;
6
+ const payloadRe =
7
+ /<input\s+[^>]*id=(?:['"]?)data-input(?:['"]?)[^>]*value=(?:['"]?)([a-zA-Z0-9+/=\-_]+)(?:['"]?)/;
7
8
  const reResult = payloadRe.exec(html);
8
9
  if (!reResult) {
9
10
  throw new InvalidFileError('Payload is missing');