Skip to content

Commit

Permalink
Mock globalThis.crypto
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrtenz committed Nov 22, 2024
1 parent fb9a252 commit 5ea04e3
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/cryptography.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { bytesToHex } from '@metamask/utils';
import { webcrypto } from 'crypto';

import {
hmacSha512,
Expand All @@ -9,6 +10,10 @@ import {
} from './cryptography';
import * as utils from './utils';

// Node.js <20 doesn't have `globalThis.crypto`, so we need to define it.
// TODO: Remove this once we drop support for Node.js <20.
Object.defineProperty(globalThis, 'crypto', webcrypto);

describe('hmacSha512', () => {
it('returns the HMAC-SHA-512 when using a custom implementation', async () => {
const key = new Uint8Array(32);
Expand Down

0 comments on commit 5ea04e3

Please sign in to comment.