Skip to content

Commit 6f34111

Browse files
committed
fix(sdk/js): patch crypto polyfill for browser tests
1 parent 7cd6a3b commit 6f34111

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

sdk/js/src/__tests__/browser-compatibility.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77

88
import { describe, it, expect } from 'vitest'
99

10+
// Polyfill crypto for Node.js test environment
11+
if (typeof globalThis.crypto === 'undefined') {
12+
const { webcrypto } = require('crypto')
13+
globalThis.crypto = webcrypto
14+
}
15+
1016
// Import Node.js versions
1117
import * as nodeEncryptEnvVars from '../encrypt-env-vars'
1218
import * as nodeGetComposeHash from '../get-compose-hash'

sdk/js/src/encrypt-env-vars.browser.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { x25519 } from "@noble/curves/ed25519"
2-
import crypto from 'crypto'
32

43
// Convert hex string to Uint8Array
54
function hexToUint8Array(hex: string) {
@@ -36,7 +35,7 @@ export async function encryptEnvVars(envs: EnvVar[], publicKeyHex: string) {
3635
// Import shared key for AES-GCM
3736
const importedShared = await crypto.subtle.importKey(
3837
"raw",
39-
shared,
38+
new Uint8Array(shared),
4039
{ name: "AES-GCM", length: 256 },
4140
true,
4241
["encrypt"],

0 commit comments

Comments
 (0)