@virtru/dsp-sdk 0.4.1 → 0.5.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 (48) hide show
  1. package/.rush/temp/chunked-rush-logs/dsp-sdk._phase_build.chunks.jsonl +2 -2
  2. package/.rush/temp/chunked-rush-logs/dsp-sdk._phase_test.chunks.jsonl +353 -13
  3. package/.rush/temp/package-deps__phase_build.json +16 -8
  4. package/.rush/temp/shrinkwrap-deps.json +99 -94
  5. package/CHANGELOG.json +21 -0
  6. package/CHANGELOG.md +8 -1
  7. package/dist/src/lib/fips-crypto/asymmetric.d.ts +35 -0
  8. package/dist/src/lib/fips-crypto/asymmetric.js +116 -0
  9. package/dist/src/lib/fips-crypto/key-format.d.ts +51 -0
  10. package/dist/src/lib/fips-crypto/key-format.js +233 -0
  11. package/dist/src/lib/fips-crypto/keys.d.ts +26 -0
  12. package/dist/src/lib/fips-crypto/keys.js +123 -0
  13. package/dist/src/lib/fips-crypto/primitives.d.ts +41 -0
  14. package/dist/src/lib/fips-crypto/primitives.js +105 -0
  15. package/dist/src/lib/fips-crypto/symmetric.d.ts +61 -0
  16. package/dist/src/lib/fips-crypto/symmetric.js +152 -0
  17. package/dist/src/lib/fips-crypto-service.d.ts +5 -0
  18. package/dist/src/lib/fips-crypto-service.js +44 -0
  19. package/dist/src/lib/utils.d.ts +8 -2
  20. package/dist/src/lib/utils.js +8 -9
  21. package/dist/tests/fips-crypto.unit.test.d.ts +1 -0
  22. package/dist/tests/fips-crypto.unit.test.js +258 -0
  23. package/dist/tests/setup-unit.d.ts +7 -0
  24. package/dist/tests/setup-unit.js +70 -0
  25. package/lib-commonjs/src/lib/fips-crypto/asymmetric.js +126 -0
  26. package/lib-commonjs/src/lib/fips-crypto/key-format.js +243 -0
  27. package/lib-commonjs/src/lib/fips-crypto/keys.js +134 -0
  28. package/lib-commonjs/src/lib/fips-crypto/primitives.js +112 -0
  29. package/lib-commonjs/src/lib/fips-crypto/symmetric.js +162 -0
  30. package/lib-commonjs/src/lib/fips-crypto-service.js +57 -0
  31. package/lib-commonjs/src/lib/utils.js +8 -9
  32. package/lib-commonjs/tests/fips-crypto.unit.test.js +260 -0
  33. package/lib-commonjs/tests/setup-unit.js +72 -0
  34. package/package.json +10 -5
  35. package/public/virtru.wasm +0 -0
  36. package/src/lib/fips-crypto/asymmetric.ts +162 -0
  37. package/src/lib/fips-crypto/key-format.ts +287 -0
  38. package/src/lib/fips-crypto/keys.ts +190 -0
  39. package/src/lib/fips-crypto/primitives.ts +197 -0
  40. package/src/lib/fips-crypto/symmetric.ts +213 -0
  41. package/src/lib/fips-crypto-service.ts +58 -0
  42. package/src/lib/utils.test.ts +11 -8
  43. package/src/lib/utils.ts +14 -13
  44. package/temp/build/lint/_eslint-5eVG3S6w.json +9 -1
  45. package/tests/fips-crypto.unit.test.ts +412 -0
  46. package/tests/setup-unit.ts +108 -0
  47. package/tsconfig.json +1 -1
  48. package/vitest.config.ts +22 -6
@@ -0,0 +1,105 @@
1
+ /*
2
+ * Copyright (c) Virtru Corporation. All rights reserved.
3
+ *
4
+ * Your use of this file is governed by the Virtu Terms of Service <https://www.virtru.com/terms-of-service/>.
5
+ */
6
+ import { ConfigurationError } from '@opentdf/sdk';
7
+ import {} from '@opentdf/sdk/singlecontainer';
8
+ // ─── VirtruCrypto Init ────────────────────────────────────────────────────────
9
+ let virtruCryptoInstance = null;
10
+ let virtruCryptoInitPromise = null;
11
+ // fips-crypto-js initialization is asynchronous (WASM fetch + runtime init).
12
+ // Keep this bounded so callers fail fast with a clear error if readiness never
13
+ // occurs (missing wasm, blocked fetch, or runtime init failure).
14
+ const VIRTRU_CRYPTO_INIT_TIMEOUT_MS = 10000;
15
+ // fips-crypto-js creates window.VirtruFipsWasmLib early, before the WASM
16
+ // runtime finishes wiring methods. Treat it as ready only once initialized.
17
+ function isVirtruCryptoInitialized(candidate) {
18
+ if (!candidate || typeof candidate !== 'object') {
19
+ return false;
20
+ }
21
+ const maybe = candidate;
22
+ return maybe.isInitialized === true && typeof maybe.generateKey === 'function';
23
+ }
24
+ export const getVirtruCrypto = async () => {
25
+ if (typeof window === 'undefined') {
26
+ throw new ConfigurationError('FIPS crypto requires a browser environment. VirtruCrypto WASM is not supported in Node.js or SSR contexts.');
27
+ }
28
+ if (virtruCryptoInstance)
29
+ return virtruCryptoInstance;
30
+ if (virtruCryptoInitPromise) {
31
+ await virtruCryptoInitPromise;
32
+ return virtruCryptoInstance;
33
+ }
34
+ virtruCryptoInitPromise = new Promise((resolve, reject) => {
35
+ // Fast path when another import already completed initialization.
36
+ if (isVirtruCryptoInitialized(window.VirtruFipsWasmLib)) {
37
+ resolve();
38
+ return;
39
+ }
40
+ const onReady = () => {
41
+ clearTimeout(timeout);
42
+ resolve();
43
+ };
44
+ const timeout = setTimeout(() => {
45
+ window.removeEventListener('wasmReady', onReady);
46
+ reject(new Error('Timeout waiting for VirtruCrypto WASM initialization.'));
47
+ }, VIRTRU_CRYPTO_INIT_TIMEOUT_MS);
48
+ // fips-crypto-js dispatches wasmReady on window (not document).
49
+ window.addEventListener('wasmReady', onReady, { once: true });
50
+ // Handle race: initialization may complete between the first check and the
51
+ // event listener registration above.
52
+ if (isVirtruCryptoInitialized(window.VirtruFipsWasmLib)) {
53
+ window.removeEventListener('wasmReady', onReady);
54
+ clearTimeout(timeout);
55
+ resolve();
56
+ }
57
+ });
58
+ await virtruCryptoInitPromise;
59
+ virtruCryptoInstance = window.VirtruFipsWasmLib;
60
+ if (!isVirtruCryptoInitialized(virtruCryptoInstance)) {
61
+ throw new Error('VirtruCrypto failed to initialize properly.');
62
+ }
63
+ return virtruCryptoInstance;
64
+ };
65
+ /**
66
+ * Eagerly initialize FIPS WASM (used by DSP when `useFips: true`).
67
+ * Loaded dynamically so non-FIPS consumers do not require the optional peer.
68
+ */
69
+ export const initializeFipsCrypto = () => {
70
+ // Keep specifier dynamic so Vite/Rollup does not eagerly resolve the optional
71
+ // peer in non-FIPS builds; load occurs only when FIPS mode is enabled.
72
+ const modulePath = '@virtru-private/fips-crypto-js';
73
+ void import(/* @vite-ignore */ modulePath).catch((err) => {
74
+ console.error('Virtru FIPS crypto initialization failed: @virtru-private/fips-crypto-js is not installed.', err);
75
+ });
76
+ void getVirtruCrypto().catch((err) => {
77
+ // Avoid unhandled rejections; same error appears on first crypto call too.
78
+ console.error('Virtru FIPS crypto initialization failed:', err);
79
+ });
80
+ };
81
+ // ─── Randomness / Digest ──────────────────────────────────────────────────────
82
+ /**
83
+ * Generate random bytes via WebCrypto CSPRNG.
84
+ * fips-crypto-js only exposes fixed-length IV generation.
85
+ *
86
+ * Note: this does not route through the fips-crypto-js WASM boundary.
87
+ * It should not be used when a strict "all cryptographic operations must be
88
+ * performed inside the FIPS module" requirement applies.
89
+ */
90
+ export async function randomBytes(byteLength) {
91
+ const buf = new Uint8Array(byteLength);
92
+ globalThis.crypto.getRandomValues(buf);
93
+ return buf;
94
+ }
95
+ /**
96
+ * Compute a hash digest. Only SHA-256 is supported by fips-crypto-js.
97
+ */
98
+ export async function digest(algorithm, data) {
99
+ if (algorithm !== 'SHA-256') {
100
+ throw new ConfigurationError(`Hash algorithm '${algorithm}' not supported in FIPS mode. Only SHA-256 is supported.`);
101
+ }
102
+ const crypto = await getVirtruCrypto();
103
+ const result = await crypto.digest({ name: 'SHA-256' }, data);
104
+ return new Uint8Array(result);
105
+ }
@@ -0,0 +1,61 @@
1
+ import { Binary, type SymmetricKey } from '@opentdf/sdk/singlecontainer';
2
+ type AlgorithmUrn = string;
3
+ type EncryptResult = {
4
+ payload: Binary;
5
+ authTag?: Binary;
6
+ };
7
+ type DecryptResult = {
8
+ payload: Binary;
9
+ };
10
+ /**
11
+ * Generate a random AES-256 symmetric key.
12
+ * The VirtruCryptoKey handle is kept alive inside the opaque SymmetricKey —
13
+ * key material never leaves the FIPS WASM keystore.
14
+ */
15
+ export declare function generateKey(length?: number): Promise<SymmetricKey>;
16
+ /**
17
+ * Encrypt a payload with a symmetric AES key.
18
+ * When payload is a SymmetricKey the key bytes are exported internally to
19
+ * perform key-wrapping — they are never surfaced to the caller.
20
+ */
21
+ export declare function encrypt(payload: Binary | SymmetricKey, key: SymmetricKey, iv: Binary, algorithm?: AlgorithmUrn): Promise<EncryptResult>;
22
+ /**
23
+ * Decrypt a payload with a symmetric AES key.
24
+ */
25
+ export declare function decrypt(payload: Binary, key: SymmetricKey, iv: Binary, algorithm?: AlgorithmUrn, authTag?: Binary): Promise<DecryptResult>;
26
+ /**
27
+ * Compute HMAC-SHA256.
28
+ * The SymmetricKey must have been created with extractable:true (e.g. via
29
+ * importSymmetricKey) so its bytes can be re-imported as an HMAC key.
30
+ */
31
+ export declare function hmac(data: Uint8Array, key: SymmetricKey): Promise<Uint8Array>;
32
+ /**
33
+ * Verify HMAC-SHA256 using constant-time comparison.
34
+ */
35
+ export declare function verifyHmac(data: Uint8Array, signature: Uint8Array, key: SymmetricKey): Promise<boolean>;
36
+ /**
37
+ * Import raw key bytes as an opaque SymmetricKey.
38
+ * The resulting key is extractable so it can be used for HMAC and key-wrapping.
39
+ */
40
+ export declare function importSymmetricKey(keyBytes: Uint8Array): Promise<SymmetricKey>;
41
+ /**
42
+ * Split a symmetric key into N shares using XOR secret sharing.
43
+ *
44
+ * For numShares === 1 (single-KAS), the key is returned as-is — no key
45
+ * material is exported and no splitting occurs. This is the common DSP case.
46
+ *
47
+ * For numShares > 1 (multi-KAS), XOR secret sharing requires exporting the
48
+ * raw key bytes. This is not yet implemented in FIPS mode.
49
+ */
50
+ export declare function splitSymmetricKey(key: SymmetricKey, numShares: number): Promise<SymmetricKey[]>;
51
+ /**
52
+ * Merge symmetric key shares back into the original key using XOR.
53
+ *
54
+ * For a single share (single-KAS), the share is returned as-is — no key
55
+ * material is exported and no XOR occurs. This is the common DSP case.
56
+ *
57
+ * For multiple shares (multi-KAS), XOR merging requires exporting raw key bytes.
58
+ * This is not yet implemented in FIPS mode.
59
+ */
60
+ export declare function mergeSymmetricKeys(shares: SymmetricKey[]): Promise<SymmetricKey>;
61
+ export {};
@@ -0,0 +1,152 @@
1
+ /*
2
+ * Copyright (c) Virtru Corporation. All rights reserved.
3
+ *
4
+ * Your use of this file is governed by the Virtu Terms of Service <https://www.virtru.com/terms-of-service/>.
5
+ */
6
+ import { Binary } from '@opentdf/sdk/singlecontainer';
7
+ import { ConfigurationError } from '@opentdf/sdk';
8
+ import { getVirtruCrypto } from './primitives';
9
+ import { isSymmetricKey, wrapSymmetricKey, unwrapSymmetricKey } from './keys';
10
+ const AES_CBC_URN = 'http://www.w3.org/2001/04/xmlenc#aes256-cbc';
11
+ const SYM_KEY_METHODS = ['encrypt', 'decrypt', 'sign', 'verify'];
12
+ /**
13
+ * Generate a random AES-256 symmetric key.
14
+ * The VirtruCryptoKey handle is kept alive inside the opaque SymmetricKey —
15
+ * key material never leaves the FIPS WASM keystore.
16
+ */
17
+ export async function generateKey(length) {
18
+ const crypto = await getVirtruCrypto();
19
+ const bitLen = (length || 32) * 8;
20
+ // extractable=true and internal=true: keystore-based AES key that can be exported
21
+ // for RSA key-wrapping (encryptWithPublicKey calls exportKey on the DEK).
22
+ const vKey = await crypto.generateKey({ name: 'AES-GCM', length: bitLen }, true, SYM_KEY_METHODS, true);
23
+ return wrapSymmetricKey(vKey, bitLen);
24
+ }
25
+ /**
26
+ * Encrypt a payload with a symmetric AES key.
27
+ * When payload is a SymmetricKey the key bytes are exported internally to
28
+ * perform key-wrapping — they are never surfaced to the caller.
29
+ */
30
+ export async function encrypt(payload, key, iv, algorithm) {
31
+ const crypto = await getVirtruCrypto();
32
+ const algName = algorithm === AES_CBC_URN ? 'AES-CBC' : 'AES-GCM';
33
+ let payloadBytes;
34
+ if (isSymmetricKey(payload)) {
35
+ // Key-wrapping path: export symmetric key bytes from keystore.
36
+ // Only works if the key was created with extractable:true (e.g. via importSymmetricKey).
37
+ payloadBytes = await crypto.exportKey('raw', unwrapSymmetricKey(payload));
38
+ }
39
+ else {
40
+ payloadBytes = new Uint8Array(payload.asArrayBuffer());
41
+ }
42
+ const vKey = unwrapSymmetricKey(key);
43
+ const ivBytes = new Uint8Array(iv.asArrayBuffer());
44
+ const cipherBytes = await crypto.encrypt({ name: algName, length: 256, iv: ivBytes }, vKey, payloadBytes);
45
+ if (algName === 'AES-GCM') {
46
+ return {
47
+ payload: Binary.fromArrayBuffer(cipherBytes.slice(0, -16).buffer),
48
+ authTag: Binary.fromArrayBuffer(cipherBytes.slice(-16).buffer),
49
+ };
50
+ }
51
+ return { payload: Binary.fromArrayBuffer(cipherBytes.buffer) };
52
+ }
53
+ /**
54
+ * Decrypt a payload with a symmetric AES key.
55
+ */
56
+ export async function decrypt(payload, key, iv, algorithm, authTag) {
57
+ const crypto = await getVirtruCrypto();
58
+ const algName = algorithm === AES_CBC_URN ? 'AES-CBC' : 'AES-GCM';
59
+ let payloadBytes = new Uint8Array(payload.asArrayBuffer());
60
+ const ivBytes = new Uint8Array(iv.asArrayBuffer());
61
+ if (algName === 'AES-GCM') {
62
+ if (!authTag) {
63
+ throw new Error('Missing authTag for AES-GCM decryption');
64
+ }
65
+ const tagBytes = new Uint8Array(authTag.asArrayBuffer());
66
+ const combined = new Uint8Array(payloadBytes.length + tagBytes.length);
67
+ combined.set(payloadBytes, 0);
68
+ combined.set(tagBytes, payloadBytes.length);
69
+ payloadBytes = combined;
70
+ }
71
+ const vKey = unwrapSymmetricKey(key);
72
+ const plainBytes = await crypto.decrypt({ name: algName, length: 256, iv: ivBytes }, vKey, payloadBytes);
73
+ return { payload: Binary.fromArrayBuffer(plainBytes.buffer) };
74
+ }
75
+ // ─── HMAC ─────────────────────────────────────────────────────────────────────
76
+ const HMAC_PARAMS = { name: 'HMAC', hash: 'SHA-256' };
77
+ /**
78
+ * Compute HMAC-SHA256.
79
+ * The SymmetricKey must have been created with extractable:true (e.g. via
80
+ * importSymmetricKey) so its bytes can be re-imported as an HMAC key.
81
+ */
82
+ export async function hmac(data, key) {
83
+ const crypto = await getVirtruCrypto();
84
+ const vKey = unwrapSymmetricKey(key);
85
+ // The key was imported with 'sign' usage (see importSymmetricKey).
86
+ // VirtruCrypto sign() checks usage.includes('sign') then calls the WASM
87
+ // hmac() with the slot number — the key type string is irrelevant for HMAC.
88
+ // Do NOT call release() here: the key handle must remain valid for future calls.
89
+ const sig = await crypto.sign(HMAC_PARAMS, vKey, data);
90
+ return new Uint8Array(sig);
91
+ }
92
+ /**
93
+ * Verify HMAC-SHA256 using constant-time comparison.
94
+ */
95
+ export async function verifyHmac(data, signature, key) {
96
+ const expected = await hmac(data, key);
97
+ if (signature.length !== expected.length)
98
+ return false;
99
+ let mismatch = 0;
100
+ for (let i = 0; i < signature.length; i++) {
101
+ mismatch |= signature[i] ^ expected[i];
102
+ }
103
+ return mismatch === 0;
104
+ }
105
+ // ─── Symmetric Key Import / Split / Merge ─────────────────────────────────────
106
+ /**
107
+ * Import raw key bytes as an opaque SymmetricKey.
108
+ * The resulting key is extractable so it can be used for HMAC and key-wrapping.
109
+ */
110
+ export async function importSymmetricKey(keyBytes) {
111
+ const crypto = await getVirtruCrypto();
112
+ const bitLen = keyBytes.length * 8;
113
+ // Include 'sign'/'verify' so this key can also be used for HMAC-SHA256.
114
+ // VirtruCrypto's sign() checks key.usage.includes('sign'); the underlying
115
+ // WASM hmac() takes the slot number and works with any 256-bit key material.
116
+ const vKey = await crypto.importKey('raw', keyBytes, { name: 'AES-GCM' }, true, SYM_KEY_METHODS);
117
+ return wrapSymmetricKey(vKey, bitLen);
118
+ }
119
+ /**
120
+ * Split a symmetric key into N shares using XOR secret sharing.
121
+ *
122
+ * For numShares === 1 (single-KAS), the key is returned as-is — no key
123
+ * material is exported and no splitting occurs. This is the common DSP case.
124
+ *
125
+ * For numShares > 1 (multi-KAS), XOR secret sharing requires exporting the
126
+ * raw key bytes. This is not yet implemented in FIPS mode.
127
+ */
128
+ export async function splitSymmetricKey(key, numShares) {
129
+ if (numShares === 1) {
130
+ return [key];
131
+ }
132
+ throw new ConfigurationError(`splitSymmetricKey with ${numShares} shares is not yet supported in FIPS mode. ` +
133
+ 'Multi-KAS key splitting requires raw key export which violates FIPS key boundary constraints.');
134
+ }
135
+ /**
136
+ * Merge symmetric key shares back into the original key using XOR.
137
+ *
138
+ * For a single share (single-KAS), the share is returned as-is — no key
139
+ * material is exported and no XOR occurs. This is the common DSP case.
140
+ *
141
+ * For multiple shares (multi-KAS), XOR merging requires exporting raw key bytes.
142
+ * This is not yet implemented in FIPS mode.
143
+ */
144
+ export async function mergeSymmetricKeys(shares) {
145
+ if (shares.length === 0)
146
+ throw new ConfigurationError('No shares provided to mergeSymmetricKeys');
147
+ if (shares.length === 1) {
148
+ return shares[0];
149
+ }
150
+ throw new ConfigurationError(`mergeSymmetricKeys with ${shares.length} shares is not yet supported in FIPS mode. ` +
151
+ 'Multi-KAS key merging requires raw key export which violates FIPS key boundary constraints.');
152
+ }
@@ -0,0 +1,5 @@
1
+ import { type CryptoService } from '@opentdf/sdk/singlecontainer';
2
+ export { initializeFipsCrypto } from './fips-crypto/primitives';
3
+ export { wrapPublicKey, wrapPrivateKey, wrapSymmetricKey, wrapKeyPair, unwrapPublicKey, unwrapPrivateKey, unwrapSymmetricKey, } from './fips-crypto/keys';
4
+ export { importPrivateKey, exportPrivateKeyPem } from './fips-crypto/key-format';
5
+ export declare const FipsCryptoService: CryptoService;
@@ -0,0 +1,44 @@
1
+ /*
2
+ * Copyright (c) Virtru Corporation. All rights reserved.
3
+ *
4
+ * Your use of this file is governed by the Virtu Terms of Service <https://www.virtru.com/terms-of-service/>.
5
+ */
6
+ import {} from '@opentdf/sdk/singlecontainer';
7
+ export { initializeFipsCrypto } from './fips-crypto/primitives';
8
+ export { wrapPublicKey, wrapPrivateKey, wrapSymmetricKey, wrapKeyPair, unwrapPublicKey, unwrapPrivateKey, unwrapSymmetricKey, } from './fips-crypto/keys';
9
+ import { randomBytes, digest } from './fips-crypto/primitives';
10
+ import { generateKey, encrypt, decrypt, hmac, verifyHmac, importSymmetricKey, splitSymmetricKey, mergeSymmetricKeys } from './fips-crypto/symmetric';
11
+ import { generateKeyPair, generateSigningKeyPair, encryptWithPublicKey, decryptWithPrivateKey, sign, verify, generateECKeyPair, deriveKeyFromECDH } from './fips-crypto/asymmetric';
12
+ import { importPublicKey, importPrivateKey, exportPublicKeyPem, exportPrivateKeyPem, exportPublicKeyJwk, parsePublicKeyPem, extractPublicKeyPem, jwkToPublicKeyPem } from './fips-crypto/key-format';
13
+ export { importPrivateKey, exportPrivateKeyPem } from './fips-crypto/key-format';
14
+ // ─── FipsCryptoService ────────────────────────────────────────────────────────
15
+ export const FipsCryptoService = {
16
+ name: 'FipsCryptoService',
17
+ method: 'http://www.w3.org/2001/04/xmlenc#aes256-cbc',
18
+ decrypt,
19
+ decryptWithPrivateKey,
20
+ encrypt,
21
+ encryptWithPublicKey,
22
+ generateKey,
23
+ generateKeyPair,
24
+ generateSigningKeyPair,
25
+ randomBytes,
26
+ sign,
27
+ verify,
28
+ hmac,
29
+ verifyHmac,
30
+ digest,
31
+ generateECKeyPair,
32
+ deriveKeyFromECDH,
33
+ importPublicKey,
34
+ importPrivateKey,
35
+ exportPublicKeyPem,
36
+ exportPrivateKeyPem,
37
+ exportPublicKeyJwk,
38
+ parsePublicKeyPem,
39
+ extractPublicKeyPem,
40
+ jwkToPublicKeyPem,
41
+ importSymmetricKey,
42
+ splitSymmetricKey,
43
+ mergeSymmetricKeys,
44
+ };
@@ -1,5 +1,6 @@
1
1
  import type { AuthProvider } from '@opentdf/sdk';
2
2
  import { AuthProviders, OpenTDF } from '@opentdf/sdk';
3
+ import { type CryptoService } from '@opentdf/sdk/singlecontainer';
3
4
  import type { Certificate } from '../gen/virtru/policy/objects_pb';
4
5
  import type { Interceptor as Inter } from '@connectrpc/connect';
5
6
  export type Interceptor = Inter;
@@ -27,7 +28,7 @@ export type GetUserEntitlementsResponse = {
27
28
  * @param authProvider - An instance of `AuthProvider` used to generate authentication credentials.
28
29
  * @returns An `Interceptor` function that modifies requests to include authentication headers.
29
30
  */
30
- export declare function createAuthInterceptor(authProvider: AuthProvider): Interceptor;
31
+ export declare function createAuthInterceptor(authProvider: AuthProvider, _cryptoService?: CryptoService): Interceptor;
31
32
  /** Creates a new instance of an OIDC Auth Provider consumed by the TDF Clients */
32
33
  export declare function createAuthProvider(options: {
33
34
  oidc: {
@@ -36,6 +37,7 @@ export declare function createAuthProvider(options: {
36
37
  userInfoEndpoint: string;
37
38
  };
38
39
  refreshToken: string;
40
+ cryptoService?: CryptoService;
39
41
  }): Promise<AuthProviders.OIDCRefreshTokenProvider>;
40
42
  export declare function createOpenTDFClient(options: {
41
43
  oidc: {
@@ -46,6 +48,7 @@ export declare function createOpenTDFClient(options: {
46
48
  platformEndpoint: string;
47
49
  refreshToken: string;
48
50
  obligations: string[];
51
+ cryptoService?: CryptoService;
49
52
  }): Promise<OpenTDF>;
50
53
  export declare const getObligations: (ciphertext: ArrayBuffer, options: {
51
54
  oidc: {
@@ -56,6 +59,7 @@ export declare const getObligations: (ciphertext: ArrayBuffer, options: {
56
59
  platformEndpoint: string;
57
60
  refreshToken: string;
58
61
  obligations: string[];
62
+ cryptoService?: CryptoService;
59
63
  }) => Promise<string[]>;
60
64
  export declare function getUserEntitlements(options: {
61
65
  oidc: {
@@ -65,6 +69,7 @@ export declare function getUserEntitlements(options: {
65
69
  };
66
70
  platformEndpoint: string;
67
71
  refreshToken: string;
72
+ cryptoService?: CryptoService;
68
73
  }): Promise<GetUserEntitlementsResponse>;
69
74
  export declare const flattenObligations: (obligations: SupportedObligations) => string[];
70
75
  /**
@@ -110,6 +115,7 @@ export declare function getTrustedCertificates(options: {
110
115
  };
111
116
  platformEndpoint: string;
112
117
  refreshToken: string;
118
+ cryptoService?: CryptoService;
113
119
  }): Promise<Certificate[]>;
114
120
  export type JWSValidationResult = {
115
121
  valid: boolean;
@@ -148,4 +154,4 @@ export type JWSValidationResult = {
148
154
  * }
149
155
  * ```
150
156
  */
151
- export declare function validateJWSCertificateChain(x5c: string[], trustedRootCertificates: Certificate[]): Promise<JWSValidationResult>;
157
+ export declare function validateJWSCertificateChain(x5c: string[], trustedRootCertificates: Certificate[], _cryptoService?: CryptoService): Promise<JWSValidationResult>;
@@ -4,6 +4,7 @@
4
4
  * Your use of this file is governed by the Virtu Terms of Service <https://www.virtru.com/terms-of-service/>.
5
5
  */
6
6
  import { AuthProviders, OpenTDF, PermissionDeniedError, } from '@opentdf/sdk';
7
+ import { WebCryptoService } from '@opentdf/sdk/singlecontainer';
7
8
  import { PlatformClient } from '@opentdf/sdk/platform';
8
9
  import { ActiveStateEnum } from '@opentdf/sdk/platform/common/common_pb.js';
9
10
  import * as asn1js from 'asn1js';
@@ -21,7 +22,7 @@ import { DSPClient } from './client';
21
22
  * @param authProvider - An instance of `AuthProvider` used to generate authentication credentials.
22
23
  * @returns An `Interceptor` function that modifies requests to include authentication headers.
23
24
  */
24
- export function createAuthInterceptor(authProvider) {
25
+ export function createAuthInterceptor(authProvider, _cryptoService) {
25
26
  return (next) => async (req) => {
26
27
  const url = new URL(req.url);
27
28
  const pathOnly = url.pathname;
@@ -67,6 +68,7 @@ export async function createOpenTDFClient(options) {
67
68
  noVerify: true,
68
69
  },
69
70
  disableDPoP: true,
71
+ cryptoService: options.cryptoService,
70
72
  });
71
73
  }
72
74
  export const getObligations = async (ciphertext, options) => {
@@ -92,6 +94,7 @@ export async function getUserEntitlements(options) {
92
94
  const authProvider = await createAuthProvider({
93
95
  oidc: options.oidc,
94
96
  refreshToken: options.refreshToken,
97
+ cryptoService: options.cryptoService,
95
98
  });
96
99
  const accessToken = await authProvider.oidcAuth.get();
97
100
  const userEntitlementsResponse = await fetch(`${options.platformEndpoint}/shared/entitlements`, {
@@ -174,17 +177,13 @@ async function getCertificatesForNamespace(dspClient, namespaceId) {
174
177
  * ```
175
178
  */
176
179
  export async function getTrustedCertificates(options) {
177
- function generateSigningKeyPair() {
178
- return crypto.subtle.generateKey({
179
- name: 'ECDSA',
180
- namedCurve: 'P-256',
181
- }, true, ['sign', 'verify']);
182
- }
180
+ const cs = options.cryptoService ?? WebCryptoService;
183
181
  const authProvider = await createAuthProvider({
184
182
  oidc: options.oidc,
185
183
  refreshToken: options.refreshToken,
184
+ cryptoService: options.cryptoService,
186
185
  });
187
- await authProvider.updateClientPublicKey(await generateSigningKeyPair());
186
+ await authProvider.updateClientPublicKey(await cs.generateSigningKeyPair());
188
187
  // Create both clients
189
188
  const platform = new PlatformClient({
190
189
  authProvider,
@@ -300,7 +299,7 @@ function pemToArrayBuffer(pem) {
300
299
  * }
301
300
  * ```
302
301
  */
303
- export async function validateJWSCertificateChain(x5c, trustedRootCertificates) {
302
+ export async function validateJWSCertificateChain(x5c, trustedRootCertificates, _cryptoService) {
304
303
  const warnings = [];
305
304
  try {
306
305
  // Validate inputs
@@ -0,0 +1 @@
1
+ export {};