From 94bb641e50a47b8de09e8a7338a0b83079898b18 Mon Sep 17 00:00:00 2001 From: nedsalk Date: Thu, 4 Jan 2024 15:19:06 +0100 Subject: [PATCH 1/9] feat: replace uuid package with crypto --- packages/wallet/package.json | 6 +----- packages/wallet/src/keystore-wallet.ts | 3 +-- pnpm-lock.yaml | 16 ---------------- 3 files changed, 2 insertions(+), 23 deletions(-) diff --git a/packages/wallet/package.json b/packages/wallet/package.json index a9bd292c8a2..89f1bd7a558 100644 --- a/packages/wallet/package.json +++ b/packages/wallet/package.json @@ -62,10 +62,6 @@ "@fuel-ts/errors": "workspace:*", "ethers": "^6.7.1", "portfinder": "^1.0.32", - "tree-kill": "^1.2.2", - "uuid": "^9.0.0" - }, - "devDependencies": { - "@types/uuid": "^9.0.1" + "tree-kill": "^1.2.2" } } diff --git a/packages/wallet/src/keystore-wallet.ts b/packages/wallet/src/keystore-wallet.ts index 145c43c9de1..96ac4d33e3f 100644 --- a/packages/wallet/src/keystore-wallet.ts +++ b/packages/wallet/src/keystore-wallet.ts @@ -11,7 +11,6 @@ import { import { ErrorCode, FuelError } from '@fuel-ts/errors'; import type { AbstractAddress } from '@fuel-ts/interfaces'; import { hexlify } from 'ethers'; -import { v4 as uuidv4 } from 'uuid'; export type KeystoreWallet = { id: string; @@ -90,7 +89,7 @@ export async function encryptKeystoreWallet( // Construct keystore. const keystore: KeystoreWallet = { - id: uuidv4(), + id: crypto.randomUUID(), version: 3, address: removeHexPrefix(ownerAddress.toHexString()), crypto: { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 43aea01f8ba..e236112b56b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1227,13 +1227,6 @@ importers: tree-kill: specifier: ^1.2.2 version: 1.2.2 - uuid: - specifier: ^9.0.0 - version: 9.0.0 - devDependencies: - '@types/uuid': - specifier: ^9.0.1 - version: 9.0.1 packages/wallet-manager: dependencies: @@ -9174,10 +9167,6 @@ packages: resolution: {integrity: sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ==} dev: true - /@types/uuid@9.0.1: - resolution: {integrity: sha512-rFT3ak0/2trgvp4yYZo5iKFEPsET7vKydKF+VRCxlQ9bpheehyAJH89dAkaLEq/j/RZXJIqcgsmPJKUP1Z28HA==} - dev: true - /@types/web-bluetooth@0.0.16: resolution: {integrity: sha512-oh8q2Zc32S6gd/j50GowEjKLoOVOwHP/bWVjKJInBwQqdOYMdPrf1oVlelTlyfFK3CKxL1uahMDAr+vy8T7yMQ==} dev: true @@ -22289,11 +22278,6 @@ packages: resolution: {integrity: sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==} hasBin: true - /uuid@9.0.0: - resolution: {integrity: sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==} - hasBin: true - dev: false - /v8-compile-cache-lib@3.0.1: resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==} dev: true From cc964d6b521917b25ea6047afaae211dc87ed5f7 Mon Sep 17 00:00:00 2001 From: nedsalk Date: Thu, 4 Jan 2024 15:25:18 +0100 Subject: [PATCH 2/9] chore: empty changeset --- .changeset/new-rats-return.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changeset/new-rats-return.md diff --git a/.changeset/new-rats-return.md b/.changeset/new-rats-return.md new file mode 100644 index 00000000000..a845151cc84 --- /dev/null +++ b/.changeset/new-rats-return.md @@ -0,0 +1,2 @@ +--- +--- From 2cb31dc4fc4956174a840ccde45fd4bdc08f44d6 Mon Sep 17 00:00:00 2001 From: nedsalk Date: Thu, 4 Jan 2024 15:42:54 +0100 Subject: [PATCH 3/9] fix: use internal crypto library --- packages/crypto/src/browser/index.ts | 1 + packages/crypto/src/index.browser.ts | 1 + packages/crypto/src/index.ts | 1 + packages/crypto/src/node/index.ts | 3 +++ packages/crypto/src/types.ts | 1 + packages/wallet/src/keystore-wallet.ts | 3 ++- 6 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/crypto/src/browser/index.ts b/packages/crypto/src/browser/index.ts index b60afdfbe2a..fc884602c5f 100644 --- a/packages/crypto/src/browser/index.ts +++ b/packages/crypto/src/browser/index.ts @@ -18,6 +18,7 @@ const api: CryptoApi = { keccak256, decryptJsonWalletData, encryptJsonWalletData, + randomUUID: crypto.randomUUID, }; export default api; diff --git a/packages/crypto/src/index.browser.ts b/packages/crypto/src/index.browser.ts index d461ad391ff..fc599597aab 100644 --- a/packages/crypto/src/index.browser.ts +++ b/packages/crypto/src/index.browser.ts @@ -13,4 +13,5 @@ export const { keccak256, decryptJsonWalletData, encryptJsonWalletData, + randomUUID, } = cryptoApi; diff --git a/packages/crypto/src/index.ts b/packages/crypto/src/index.ts index b8ce4fc2412..10443ebf31a 100644 --- a/packages/crypto/src/index.ts +++ b/packages/crypto/src/index.ts @@ -13,4 +13,5 @@ export const { keccak256, decryptJsonWalletData, encryptJsonWalletData, + randomUUID, } = cryptoApi; diff --git a/packages/crypto/src/node/index.ts b/packages/crypto/src/node/index.ts index b60afdfbe2a..ecef378e44e 100644 --- a/packages/crypto/src/node/index.ts +++ b/packages/crypto/src/node/index.ts @@ -1,3 +1,5 @@ +import crypto from 'crypto'; + import { scrypt, keccak256 } from '../shared'; import type { CryptoApi } from '../types'; @@ -18,6 +20,7 @@ const api: CryptoApi = { keccak256, decryptJsonWalletData, encryptJsonWalletData, + randomUUID: crypto.randomUUID, }; export default api; diff --git a/packages/crypto/src/types.ts b/packages/crypto/src/types.ts index 83f0493cb62..a273e84fb0c 100644 --- a/packages/crypto/src/types.ts +++ b/packages/crypto/src/types.ts @@ -26,4 +26,5 @@ export interface CryptoApi { keccak256(data: Uint8Array): Uint8Array; encryptJsonWalletData(data: Uint8Array, key: Uint8Array, iv: Uint8Array): Promise; decryptJsonWalletData(data: Uint8Array, key: Uint8Array, iv: Uint8Array): Promise; + randomUUID(): string; } diff --git a/packages/wallet/src/keystore-wallet.ts b/packages/wallet/src/keystore-wallet.ts index 96ac4d33e3f..19a060076ef 100644 --- a/packages/wallet/src/keystore-wallet.ts +++ b/packages/wallet/src/keystore-wallet.ts @@ -7,6 +7,7 @@ import { stringFromBuffer, decryptJsonWalletData, encryptJsonWalletData, + randomUUID, } from '@fuel-ts/crypto'; import { ErrorCode, FuelError } from '@fuel-ts/errors'; import type { AbstractAddress } from '@fuel-ts/interfaces'; @@ -89,7 +90,7 @@ export async function encryptKeystoreWallet( // Construct keystore. const keystore: KeystoreWallet = { - id: crypto.randomUUID(), + id: randomUUID(), version: 3, address: removeHexPrefix(ownerAddress.toHexString()), crypto: { From cbed7c4041e37ba80c3396884997fac3993fd245 Mon Sep 17 00:00:00 2001 From: nedsalk Date: Thu, 4 Jan 2024 16:46:30 +0100 Subject: [PATCH 4/9] chore: updated changeset --- .changeset/hot-hairs-sit.md | 5 +++++ .changeset/new-rats-return.md | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 .changeset/hot-hairs-sit.md delete mode 100644 .changeset/new-rats-return.md diff --git a/.changeset/hot-hairs-sit.md b/.changeset/hot-hairs-sit.md new file mode 100644 index 00000000000..093d6ce17da --- /dev/null +++ b/.changeset/hot-hairs-sit.md @@ -0,0 +1,5 @@ +--- +"@fuel-ts/crypto": minor +--- + +Now exporting `randomUUID` from the package diff --git a/.changeset/new-rats-return.md b/.changeset/new-rats-return.md deleted file mode 100644 index a845151cc84..00000000000 --- a/.changeset/new-rats-return.md +++ /dev/null @@ -1,2 +0,0 @@ ---- ---- From 6f6b856a22581e2e3acb6c6a84555fa66c74d6c6 Mon Sep 17 00:00:00 2001 From: nedsalk Date: Fri, 5 Jan 2024 08:39:20 +0100 Subject: [PATCH 5/9] feat: throw errors when parts of global `crypto` not supported --- packages/crypto/src/browser/crypto.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/packages/crypto/src/browser/crypto.ts b/packages/crypto/src/browser/crypto.ts index b0dcb8f078a..0f803b32bc5 100644 --- a/packages/crypto/src/browser/crypto.ts +++ b/packages/crypto/src/browser/crypto.ts @@ -9,6 +9,27 @@ if (!crypto) { ); } +if (!crypto.randomUUID) { + throw new FuelError( + ErrorCode.ENV_DEPENDENCY_MISSING, + `Could not find 'crypto.randomUUID' in current browser environment.` + ); +} + +if (!crypto.subtle) { + throw new FuelError( + ErrorCode.ENV_DEPENDENCY_MISSING, + `Could not find 'crypto.subtle' in current browser environment.` + ); +} + +if (!crypto.getRandomValues) { + throw new FuelError( + ErrorCode.ENV_DEPENDENCY_MISSING, + `Could not find 'crypto.getRandomValues' in current browser environment.` + ); +} + if (!btoa) { throw new FuelError( ErrorCode.ENV_DEPENDENCY_MISSING, From 732d8f9ff2d86e42aa0de35db519e9eb258e01a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nedim=20Salki=C4=87?= Date: Fri, 5 Jan 2024 13:55:33 +0100 Subject: [PATCH 6/9] chore: update changeset --- .changeset/hot-hairs-sit.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.changeset/hot-hairs-sit.md b/.changeset/hot-hairs-sit.md index 093d6ce17da..3c4e127d1dd 100644 --- a/.changeset/hot-hairs-sit.md +++ b/.changeset/hot-hairs-sit.md @@ -1,5 +1,7 @@ --- "@fuel-ts/crypto": minor +"@fuel-ts/wallet": minor --- -Now exporting `randomUUID` from the package +- Now exporting `randomUUID` from `@fuel-ts/crypto` +- Bumping `@fuel-ts/wallet` because it's consuming `randomUUID` From 7b18afc366b9553025ecf5c9664956994fc900ca Mon Sep 17 00:00:00 2001 From: nedsalk Date: Mon, 8 Jan 2024 13:00:49 +0100 Subject: [PATCH 7/9] test: add tests for missing crypto features --- .../crypto-browser/btoa-undefined.test.ts | 19 +++++++++++++++++ .../crypto-getRandomValues-undefined.test.ts | 21 +++++++++++++++++++ .../crypto/test/crypto-browser/crypto-mock.ts | 20 ++++++++++++++++++ .../crypto-randomUUID-undefined.test.ts | 21 +++++++++++++++++++ .../crypto-subtle-undefined.test.ts | 21 +++++++++++++++++++ .../crypto-browser/crypto-undefined.test.ts | 19 +++++++++++++++++ 6 files changed, 121 insertions(+) create mode 100644 packages/crypto/test/crypto-browser/btoa-undefined.test.ts create mode 100644 packages/crypto/test/crypto-browser/crypto-getRandomValues-undefined.test.ts create mode 100644 packages/crypto/test/crypto-browser/crypto-mock.ts create mode 100644 packages/crypto/test/crypto-browser/crypto-randomUUID-undefined.test.ts create mode 100644 packages/crypto/test/crypto-browser/crypto-subtle-undefined.test.ts create mode 100644 packages/crypto/test/crypto-browser/crypto-undefined.test.ts diff --git a/packages/crypto/test/crypto-browser/btoa-undefined.test.ts b/packages/crypto/test/crypto-browser/btoa-undefined.test.ts new file mode 100644 index 00000000000..962968079cf --- /dev/null +++ b/packages/crypto/test/crypto-browser/btoa-undefined.test.ts @@ -0,0 +1,19 @@ +import { ErrorCode, FuelError } from '@fuel-ts/errors'; +import { expectToThrowFuelError } from '@fuel-ts/errors/test-utils'; + +/** + * @group crypto + */ +describe('throws when btoa is unavailable', () => { + test('btoa is undefined', async () => { + vi.stubGlobal('btoa', undefined); + + await expectToThrowFuelError( + () => import('../../src/browser/crypto'), + new FuelError( + ErrorCode.ENV_DEPENDENCY_MISSING, + `Could not find 'btoa' in current browser environment.` + ) + ); + }); +}); diff --git a/packages/crypto/test/crypto-browser/crypto-getRandomValues-undefined.test.ts b/packages/crypto/test/crypto-browser/crypto-getRandomValues-undefined.test.ts new file mode 100644 index 00000000000..c7244dd380d --- /dev/null +++ b/packages/crypto/test/crypto-browser/crypto-getRandomValues-undefined.test.ts @@ -0,0 +1,21 @@ +import { ErrorCode, FuelError } from '@fuel-ts/errors'; +import { expectToThrowFuelError } from '@fuel-ts/errors/test-utils'; + +import { CryptoMock } from './crypto-mock'; + +/** + * @group crypto + */ +describe('throws when crypto.getRandomValues is unavailable', () => { + test('crypto.getRandomValues is undefined', async () => { + vi.stubGlobal('crypto', new CryptoMock('getRandomValues')); + + await expectToThrowFuelError( + () => import('../../src/browser/crypto'), + new FuelError( + ErrorCode.ENV_DEPENDENCY_MISSING, + `Could not find 'crypto.getRandomValues' in current browser environment.` + ) + ); + }); +}); diff --git a/packages/crypto/test/crypto-browser/crypto-mock.ts b/packages/crypto/test/crypto-browser/crypto-mock.ts new file mode 100644 index 00000000000..1451b209de5 --- /dev/null +++ b/packages/crypto/test/crypto-browser/crypto-mock.ts @@ -0,0 +1,20 @@ +import * as cr from 'crypto'; + +export class CryptoMock { + /** + * + */ + constructor(private toUndefined: 'subtle' | 'randomUUID' | 'getRandomValues') {} + + get subtle() { + return this.toUndefined === 'subtle' ? undefined : cr.subtle; + } + + get randomUUID() { + return this.toUndefined === 'randomUUID' ? undefined : cr.randomUUID; + } + + get getRandomValues() { + return this.toUndefined === 'getRandomValues' ? undefined : cr.getRandomValues; + } +} diff --git a/packages/crypto/test/crypto-browser/crypto-randomUUID-undefined.test.ts b/packages/crypto/test/crypto-browser/crypto-randomUUID-undefined.test.ts new file mode 100644 index 00000000000..8c266ab24d3 --- /dev/null +++ b/packages/crypto/test/crypto-browser/crypto-randomUUID-undefined.test.ts @@ -0,0 +1,21 @@ +import { ErrorCode, FuelError } from '@fuel-ts/errors'; +import { expectToThrowFuelError } from '@fuel-ts/errors/test-utils'; + +import { CryptoMock } from './crypto-mock'; + +/** + * @group crypto + */ +describe('throws when crypto.randomUUID is unavailable', () => { + test('crypto.randomUUID is undefined', async () => { + vi.stubGlobal('crypto', new CryptoMock('randomUUID')); + + await expectToThrowFuelError( + () => import('../../src/browser/crypto'), + new FuelError( + ErrorCode.ENV_DEPENDENCY_MISSING, + `Could not find 'crypto.randomUUID' in current browser environment.` + ) + ); + }); +}); diff --git a/packages/crypto/test/crypto-browser/crypto-subtle-undefined.test.ts b/packages/crypto/test/crypto-browser/crypto-subtle-undefined.test.ts new file mode 100644 index 00000000000..0ee3e64605d --- /dev/null +++ b/packages/crypto/test/crypto-browser/crypto-subtle-undefined.test.ts @@ -0,0 +1,21 @@ +import { ErrorCode, FuelError } from '@fuel-ts/errors'; +import { expectToThrowFuelError } from '@fuel-ts/errors/test-utils'; + +import { CryptoMock } from './crypto-mock'; + +/** + * @group crypto + */ +describe('throws when crypto.subtle is unavailable', () => { + test('crypto.subtle is undefined', async () => { + vi.stubGlobal('crypto', new CryptoMock('subtle')); + + await expectToThrowFuelError( + () => import('../../src/browser/crypto'), + new FuelError( + ErrorCode.ENV_DEPENDENCY_MISSING, + `Could not find 'crypto.subtle' in current browser environment.` + ) + ); + }); +}); diff --git a/packages/crypto/test/crypto-browser/crypto-undefined.test.ts b/packages/crypto/test/crypto-browser/crypto-undefined.test.ts new file mode 100644 index 00000000000..b109ebc198c --- /dev/null +++ b/packages/crypto/test/crypto-browser/crypto-undefined.test.ts @@ -0,0 +1,19 @@ +import { ErrorCode, FuelError } from '@fuel-ts/errors'; +import { expectToThrowFuelError } from '@fuel-ts/errors/test-utils'; + +/** + * @group crypto + */ +describe('throws when crypto is unavailable', () => { + test('crypto is undefined', async () => { + vi.stubGlobal('crypto', undefined); + + await expectToThrowFuelError( + () => import('../../src/browser/crypto'), + new FuelError( + ErrorCode.ENV_DEPENDENCY_MISSING, + `Could not find 'crypto' in current browser environment.` + ) + ); + }); +}); From 1b656bead9f334f9bb7e34565d7dc21f6ca3bd97 Mon Sep 17 00:00:00 2001 From: nedsalk Date: Mon, 8 Jan 2024 13:07:58 +0100 Subject: [PATCH 8/9] fix: test files' wrong environment config --- packages/crypto/test/crypto-browser/btoa-undefined.test.ts | 2 +- .../crypto-browser/crypto-getRandomValues-undefined.test.ts | 2 +- .../test/crypto-browser/crypto-randomUUID-undefined.test.ts | 2 +- .../crypto/test/crypto-browser/crypto-subtle-undefined.test.ts | 2 +- packages/crypto/test/crypto-browser/crypto-undefined.test.ts | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/crypto/test/crypto-browser/btoa-undefined.test.ts b/packages/crypto/test/crypto-browser/btoa-undefined.test.ts index 962968079cf..81b0e98ad04 100644 --- a/packages/crypto/test/crypto-browser/btoa-undefined.test.ts +++ b/packages/crypto/test/crypto-browser/btoa-undefined.test.ts @@ -2,7 +2,7 @@ import { ErrorCode, FuelError } from '@fuel-ts/errors'; import { expectToThrowFuelError } from '@fuel-ts/errors/test-utils'; /** - * @group crypto + * @group node */ describe('throws when btoa is unavailable', () => { test('btoa is undefined', async () => { diff --git a/packages/crypto/test/crypto-browser/crypto-getRandomValues-undefined.test.ts b/packages/crypto/test/crypto-browser/crypto-getRandomValues-undefined.test.ts index c7244dd380d..d16344b92c9 100644 --- a/packages/crypto/test/crypto-browser/crypto-getRandomValues-undefined.test.ts +++ b/packages/crypto/test/crypto-browser/crypto-getRandomValues-undefined.test.ts @@ -4,7 +4,7 @@ import { expectToThrowFuelError } from '@fuel-ts/errors/test-utils'; import { CryptoMock } from './crypto-mock'; /** - * @group crypto + * @group node */ describe('throws when crypto.getRandomValues is unavailable', () => { test('crypto.getRandomValues is undefined', async () => { diff --git a/packages/crypto/test/crypto-browser/crypto-randomUUID-undefined.test.ts b/packages/crypto/test/crypto-browser/crypto-randomUUID-undefined.test.ts index 8c266ab24d3..fa71c97f1ab 100644 --- a/packages/crypto/test/crypto-browser/crypto-randomUUID-undefined.test.ts +++ b/packages/crypto/test/crypto-browser/crypto-randomUUID-undefined.test.ts @@ -4,7 +4,7 @@ import { expectToThrowFuelError } from '@fuel-ts/errors/test-utils'; import { CryptoMock } from './crypto-mock'; /** - * @group crypto + * @group node */ describe('throws when crypto.randomUUID is unavailable', () => { test('crypto.randomUUID is undefined', async () => { diff --git a/packages/crypto/test/crypto-browser/crypto-subtle-undefined.test.ts b/packages/crypto/test/crypto-browser/crypto-subtle-undefined.test.ts index 0ee3e64605d..a8f7b491f27 100644 --- a/packages/crypto/test/crypto-browser/crypto-subtle-undefined.test.ts +++ b/packages/crypto/test/crypto-browser/crypto-subtle-undefined.test.ts @@ -4,7 +4,7 @@ import { expectToThrowFuelError } from '@fuel-ts/errors/test-utils'; import { CryptoMock } from './crypto-mock'; /** - * @group crypto + * @group node */ describe('throws when crypto.subtle is unavailable', () => { test('crypto.subtle is undefined', async () => { diff --git a/packages/crypto/test/crypto-browser/crypto-undefined.test.ts b/packages/crypto/test/crypto-browser/crypto-undefined.test.ts index b109ebc198c..1f46406d623 100644 --- a/packages/crypto/test/crypto-browser/crypto-undefined.test.ts +++ b/packages/crypto/test/crypto-browser/crypto-undefined.test.ts @@ -2,7 +2,7 @@ import { ErrorCode, FuelError } from '@fuel-ts/errors'; import { expectToThrowFuelError } from '@fuel-ts/errors/test-utils'; /** - * @group crypto + * @group node */ describe('throws when crypto is unavailable', () => { test('crypto is undefined', async () => { From 3631cab8ca8d09db8f7b3f76dbd436757c4b8150 Mon Sep 17 00:00:00 2001 From: nedsalk Date: Mon, 8 Jan 2024 13:58:47 +0100 Subject: [PATCH 9/9] fix: failing btoa test --- packages/crypto/test/crypto-browser/btoa-undefined.test.ts | 7 +++++++ packages/crypto/test/crypto-browser/crypto-mock.ts | 5 +---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/crypto/test/crypto-browser/btoa-undefined.test.ts b/packages/crypto/test/crypto-browser/btoa-undefined.test.ts index 81b0e98ad04..de955cb16e5 100644 --- a/packages/crypto/test/crypto-browser/btoa-undefined.test.ts +++ b/packages/crypto/test/crypto-browser/btoa-undefined.test.ts @@ -1,11 +1,18 @@ import { ErrorCode, FuelError } from '@fuel-ts/errors'; import { expectToThrowFuelError } from '@fuel-ts/errors/test-utils'; +import { CryptoMock } from './crypto-mock'; + /** * @group node */ describe('throws when btoa is unavailable', () => { test('btoa is undefined', async () => { + if (!globalThis.crypto) { + // this is for node v18 where globalThis.crypto is undefined + // these are tests for the browser environment anyways so doing this is okay + vi.stubGlobal('crypto', new CryptoMock()); + } vi.stubGlobal('btoa', undefined); await expectToThrowFuelError( diff --git a/packages/crypto/test/crypto-browser/crypto-mock.ts b/packages/crypto/test/crypto-browser/crypto-mock.ts index 1451b209de5..6f7d9ddc65d 100644 --- a/packages/crypto/test/crypto-browser/crypto-mock.ts +++ b/packages/crypto/test/crypto-browser/crypto-mock.ts @@ -1,10 +1,7 @@ import * as cr from 'crypto'; export class CryptoMock { - /** - * - */ - constructor(private toUndefined: 'subtle' | 'randomUUID' | 'getRandomValues') {} + constructor(private toUndefined?: 'subtle' | 'randomUUID' | 'getRandomValues') {} get subtle() { return this.toUndefined === 'subtle' ? undefined : cr.subtle;