diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c30a236..857ca62 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,6 +31,29 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} + - name: Set .npmrc for windows + run: cp .npmrc.windows ./tests-browser/.npmrc + if: matrix.os == 'windows-latest' + + - name: Set up browser tests + working-directory: tests-browser + run: pnpm install && pnpm exec playwright install chromium firefox + + - name: Install webkit browser on macos + working-directory: tests-browser + if: matrix.os == 'macos-latest' + run: pnpm exec playwright install + + - name: Run browser tests (chromium, firefox) + run: | + pnpm test:browser + pnpm test:browser -- --browser=firefox + + - name: Run browser tests (webkit) + if: matrix.os == 'macos-latest' + run: | + pnpm test:browser -- --browser=webkit + check-runtimes: runs-on: ubuntu-latest steps: @@ -54,18 +77,12 @@ jobs: - name: check main.js run: | - bun run example/runtime/main.js - deno run --allow-read example/runtime/main.js - node example/runtime/main.js + ./scripts/check-runtime.sh example/runtime/main.js - name: check import.js run: | - bun run example/runtime/import.js - deno run --allow-read example/runtime/import.js - node example/runtime/import.js + ./scripts/check-runtime.sh example/runtime/import.js - name: check require.cjs run: | - bun run example/runtime/require.cjs - deno run --allow-read example/runtime/require.cjs - node example/runtime/require.cjs + ./scripts/check-runtime.sh example/runtime/require.cjs diff --git a/.gitignore b/.gitignore index 44377bf..b00c43f 100644 --- a/.gitignore +++ b/.gitignore @@ -122,3 +122,7 @@ bun.lockb deno.lock example/browser/pnpm-lock.yaml example/runtime/pnpm-lock.yaml + +# browser tests +tests-browser/pnpm-lock.yaml +tests-browser/**/*.test.ts diff --git a/.npmrc.windows b/.npmrc.windows new file mode 100644 index 0000000..30e36b8 --- /dev/null +++ b/.npmrc.windows @@ -0,0 +1,3 @@ +# symlink does not work on windows for vite in browsers +# see: https://github.com/vitejs/vite/issues/10802 +node-linker=hoisted diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b10862..92e38ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Revamp encapsulate/decapsulate - Revamp symmetric encryption/decryption - Revamp elliptic utils +- Add browser tests ## 0.4.10 @@ -40,7 +41,7 @@ - Bump dependencies - Drop Node 14 support -## 0.3.1 ~ 0.3.18 +## 0.3.1 ~ 0.3.21 - Revamp tests - Support Node 18, 20 @@ -48,6 +49,8 @@ - Bump dependencies - Update documentation - Extract constant variables and rename some parameters +- Revamp CI +- Migrate to vitest ## 0.3.0 diff --git a/README.md b/README.md index 0f835e2..eaf93f6 100644 --- a/README.md +++ b/README.md @@ -38,12 +38,25 @@ hello world🌍 See [Configuration](#configuration) to control with more granularity. -## Browser Support +## Multi-platform Support + +### Browser This library is browser-friendly, check the [`example/browser`](./example/browser) directory for details. Currently it's necessary to polyfill `Buffer` for backward compatibility. From v0.5.0, it can run in browsers as is. If you want a WASM version to run directly in modern browsers or on some blockchains, you can also try [`ecies-wasm`](https://github.com/ecies/rs-wasm). +### Bun/Deno + +For bun/deno, see [`example/runtime`](./example/runtime). There are some limitations currently: + +- `xchacha20` does not work on bun +- Only `aes-256-gcm` with 12 bytes nonce works on deno + +### React Native + +See the [React Native demo](https://github.com/ecies/js-rn-demo). + ## API ### `encrypt(receiverRawPK: string | Uint8Array, msg: Uint8Array): Buffer` diff --git a/example/README.md b/example/README.md index ced1017..e605ee4 100644 --- a/example/README.md +++ b/example/README.md @@ -6,6 +6,10 @@ Make sure `pnpm build` under the parent directory is run before. Run `cd browser && pnpm install && pnpm dev` +> [!NOTE] +> +> You need to copy `.npmrc.windows` to `example/browser/.npmrc` on Windows before the command above + For production, run `pnpm build && pnpm preview` ## Runtime example (Node/Bun/Deno) diff --git a/example/browser/script.js b/example/browser/script.js index 465f1b6..641de11 100644 --- a/example/browser/script.js +++ b/example/browser/script.js @@ -1,6 +1,7 @@ import { bytesToHex } from "@noble/ciphers/utils"; import { Buffer } from "buffer"; import { ECIES_CONFIG, PrivateKey, decrypt, encrypt } from "eciesjs"; + import "./style.css"; globalThis.Buffer = Buffer; // polyfill manually diff --git a/package.json b/package.json index bc5702d..28cdcfd 100644 --- a/package.json +++ b/package.json @@ -52,20 +52,21 @@ }, "scripts": { "build": "npx tsc", - "test": "vitest" + "test": "vitest", + "test:browser": "node ./scripts/gen-browser-tests.mjs && cd tests-browser && pnpm test" }, "dependencies": { - "@ecies/ciphers": "^0.2.0", + "@ecies/ciphers": "^0.2.1", "@noble/ciphers": "^1.0.0", "@noble/curves": "^1.6.0", "@noble/hashes": "^1.5.0" }, "devDependencies": { - "@types/node": "^22.8.2", + "@types/node": "^22.9.0", "@vitest/coverage-v8": "^2.1.4", "typescript": "^5.6.3", "undici": "^6.20.1", "vitest": "^2.1.4" }, - "packageManager": "pnpm@9.12.2+sha512.22721b3a11f81661ae1ec68ce1a7b879425a1ca5b991c975b074ac220b187ce56c708fe5db69f4c962c989452eee76c82877f4ee80f474cebd61ee13461b6228" + "packageManager": "pnpm@9.12.3+sha512.cce0f9de9c5a7c95bef944169cc5dfe8741abfb145078c0d508b868056848a87c81e626246cb60967cbd7fd29a6c062ef73ff840d96b3c86c40ac92cf4a813ee" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e86ebb2..ca4a621 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,8 +9,8 @@ importers: .: dependencies: '@ecies/ciphers': - specifier: ^0.2.0 - version: 0.2.0(@noble/ciphers@1.0.0) + specifier: ^0.2.1 + version: 0.2.1(@noble/ciphers@1.0.0) '@noble/ciphers': specifier: ^1.0.0 version: 1.0.0 @@ -22,11 +22,11 @@ importers: version: 1.5.0 devDependencies: '@types/node': - specifier: ^22.8.2 - version: 22.8.2 + specifier: ^22.9.0 + version: 22.9.0 '@vitest/coverage-v8': specifier: ^2.1.4 - version: 2.1.4(vitest@2.1.4(@types/node@22.8.2)) + version: 2.1.4(vitest@2.1.4(@types/node@22.9.0)) typescript: specifier: ^5.6.3 version: 5.6.3 @@ -35,7 +35,7 @@ importers: version: 6.20.1 vitest: specifier: ^2.1.4 - version: 2.1.4(@types/node@22.8.2) + version: 2.1.4(@types/node@22.9.0) packages: @@ -51,8 +51,8 @@ packages: resolution: {integrity: sha512-Ed61U6XJc3CVRfkERJWDz4dJwKe7iLmmJsbOGu9wSloNSFttHV0I8g6UAgb7qnK5ly5bGLPd4oXZlxCdANBOWQ==} engines: {node: '>=6.9.0'} - '@babel/parser@7.26.1': - resolution: {integrity: sha512-reoQYNiAJreZNsJzyrDNzFQ+IQ5JFiIzAHJg9bn94S3l+4++J7RsIhNMoB+lgP/9tpmiAQqspv+xfdxTSzREOw==} + '@babel/parser@7.26.2': + resolution: {integrity: sha512-DWMCZH9WA4Maitz2q21SRKHo9QXZxkDsbNZoVD62gusNtNBBqDg9i7uOhASfTfIGNzW+O+r7+jAlM8dwphcJKQ==} engines: {node: '>=6.0.0'} hasBin: true @@ -63,8 +63,8 @@ packages: '@bcoe/v8-coverage@0.2.3': resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==} - '@ecies/ciphers@0.2.0': - resolution: {integrity: sha512-dqQk3HbyuXSdflgRMrXjEcCohKeBZQl2rm0lOcYnEC4Oue90irVMwVJ0GiM/nhjP0zzGimH8mVFF/pOzQcv+Lg==} + '@ecies/ciphers@0.2.1': + resolution: {integrity: sha512-ezMihhjW24VNK/2qQR7lH8xCQY24nk0XHF/kwJ1OuiiY5iEwQXOcKVSy47fSoHPRG8gVGXcK5SgtONDk5xMwtQ==} engines: {bun: '>=1', deno: '>=2', node: '>=16'} peerDependencies: '@noble/ciphers': ^1.0.0 @@ -249,101 +249,101 @@ packages: resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==} engines: {node: '>=14'} - '@rollup/rollup-android-arm-eabi@4.24.2': - resolution: {integrity: sha512-ufoveNTKDg9t/b7nqI3lwbCG/9IJMhADBNjjz/Jn6LxIZxD7T5L8l2uO/wD99945F1Oo8FvgbbZJRguyk/BdzA==} + '@rollup/rollup-android-arm-eabi@4.24.4': + resolution: {integrity: sha512-jfUJrFct/hTA0XDM5p/htWKoNNTbDLY0KRwEt6pyOA6k2fmk0WVwl65PdUdJZgzGEHWx+49LilkcSaumQRyNQw==} cpu: [arm] os: [android] - '@rollup/rollup-android-arm64@4.24.2': - resolution: {integrity: sha512-iZoYCiJz3Uek4NI0J06/ZxUgwAfNzqltK0MptPDO4OR0a88R4h0DSELMsflS6ibMCJ4PnLvq8f7O1d7WexUvIA==} + '@rollup/rollup-android-arm64@4.24.4': + resolution: {integrity: sha512-j4nrEO6nHU1nZUuCfRKoCcvh7PIywQPUCBa2UsootTHvTHIoIu2BzueInGJhhvQO/2FTRdNYpf63xsgEqH9IhA==} cpu: [arm64] os: [android] - '@rollup/rollup-darwin-arm64@4.24.2': - resolution: {integrity: sha512-/UhrIxobHYCBfhi5paTkUDQ0w+jckjRZDZ1kcBL132WeHZQ6+S5v9jQPVGLVrLbNUebdIRpIt00lQ+4Z7ys4Rg==} + '@rollup/rollup-darwin-arm64@4.24.4': + resolution: {integrity: sha512-GmU/QgGtBTeraKyldC7cDVVvAJEOr3dFLKneez/n7BvX57UdhOqDsVwzU7UOnYA7AAOt+Xb26lk79PldDHgMIQ==} cpu: [arm64] os: [darwin] - '@rollup/rollup-darwin-x64@4.24.2': - resolution: {integrity: sha512-1F/jrfhxJtWILusgx63WeTvGTwE4vmsT9+e/z7cZLKU8sBMddwqw3UV5ERfOV+H1FuRK3YREZ46J4Gy0aP3qDA==} + '@rollup/rollup-darwin-x64@4.24.4': + resolution: {integrity: sha512-N6oDBiZCBKlwYcsEPXGDE4g9RoxZLK6vT98M8111cW7VsVJFpNEqvJeIPfsCzbf0XEakPslh72X0gnlMi4Ddgg==} cpu: [x64] os: [darwin] - '@rollup/rollup-freebsd-arm64@4.24.2': - resolution: {integrity: sha512-1YWOpFcGuC6iGAS4EI+o3BV2/6S0H+m9kFOIlyFtp4xIX5rjSnL3AwbTBxROX0c8yWtiWM7ZI6mEPTI7VkSpZw==} + '@rollup/rollup-freebsd-arm64@4.24.4': + resolution: {integrity: sha512-py5oNShCCjCyjWXCZNrRGRpjWsF0ic8f4ieBNra5buQz0O/U6mMXCpC1LvrHuhJsNPgRt36tSYMidGzZiJF6mw==} cpu: [arm64] os: [freebsd] - '@rollup/rollup-freebsd-x64@4.24.2': - resolution: {integrity: sha512-3qAqTewYrCdnOD9Gl9yvPoAoFAVmPJsBvleabvx4bnu1Kt6DrB2OALeRVag7BdWGWLhP1yooeMLEi6r2nYSOjg==} + '@rollup/rollup-freebsd-x64@4.24.4': + resolution: {integrity: sha512-L7VVVW9FCnTTp4i7KrmHeDsDvjB4++KOBENYtNYAiYl96jeBThFfhP6HVxL74v4SiZEVDH/1ILscR5U9S4ms4g==} cpu: [x64] os: [freebsd] - '@rollup/rollup-linux-arm-gnueabihf@4.24.2': - resolution: {integrity: sha512-ArdGtPHjLqWkqQuoVQ6a5UC5ebdX8INPuJuJNWRe0RGa/YNhVvxeWmCTFQ7LdmNCSUzVZzxAvUznKaYx645Rig==} + '@rollup/rollup-linux-arm-gnueabihf@4.24.4': + resolution: {integrity: sha512-10ICosOwYChROdQoQo589N5idQIisxjaFE/PAnX2i0Zr84mY0k9zul1ArH0rnJ/fpgiqfu13TFZR5A5YJLOYZA==} cpu: [arm] os: [linux] - '@rollup/rollup-linux-arm-musleabihf@4.24.2': - resolution: {integrity: sha512-B6UHHeNnnih8xH6wRKB0mOcJGvjZTww1FV59HqJoTJ5da9LCG6R4SEBt6uPqzlawv1LoEXSS0d4fBlHNWl6iYw==} + '@rollup/rollup-linux-arm-musleabihf@4.24.4': + resolution: {integrity: sha512-ySAfWs69LYC7QhRDZNKqNhz2UKN8LDfbKSMAEtoEI0jitwfAG2iZwVqGACJT+kfYvvz3/JgsLlcBP+WWoKCLcw==} cpu: [arm] os: [linux] - '@rollup/rollup-linux-arm64-gnu@4.24.2': - resolution: {integrity: sha512-kr3gqzczJjSAncwOS6i7fpb4dlqcvLidqrX5hpGBIM1wtt0QEVtf4wFaAwVv8QygFU8iWUMYEoJZWuWxyua4GQ==} + '@rollup/rollup-linux-arm64-gnu@4.24.4': + resolution: {integrity: sha512-uHYJ0HNOI6pGEeZ/5mgm5arNVTI0nLlmrbdph+pGXpC9tFHFDQmDMOEqkmUObRfosJqpU8RliYoGz06qSdtcjg==} cpu: [arm64] os: [linux] - '@rollup/rollup-linux-arm64-musl@4.24.2': - resolution: {integrity: sha512-TDdHLKCWgPuq9vQcmyLrhg/bgbOvIQ8rtWQK7MRxJ9nvaxKx38NvY7/Lo6cYuEnNHqf6rMqnivOIPIQt6H2AoA==} + '@rollup/rollup-linux-arm64-musl@4.24.4': + resolution: {integrity: sha512-38yiWLemQf7aLHDgTg85fh3hW9stJ0Muk7+s6tIkSUOMmi4Xbv5pH/5Bofnsb6spIwD5FJiR+jg71f0CH5OzoA==} cpu: [arm64] os: [linux] - '@rollup/rollup-linux-powerpc64le-gnu@4.24.2': - resolution: {integrity: sha512-xv9vS648T3X4AxFFZGWeB5Dou8ilsv4VVqJ0+loOIgDO20zIhYfDLkk5xoQiej2RiSQkld9ijF/fhLeonrz2mw==} + '@rollup/rollup-linux-powerpc64le-gnu@4.24.4': + resolution: {integrity: sha512-q73XUPnkwt9ZNF2xRS4fvneSuaHw2BXuV5rI4cw0fWYVIWIBeDZX7c7FWhFQPNTnE24172K30I+dViWRVD9TwA==} cpu: [ppc64] os: [linux] - '@rollup/rollup-linux-riscv64-gnu@4.24.2': - resolution: {integrity: sha512-tbtXwnofRoTt223WUZYiUnbxhGAOVul/3StZ947U4A5NNjnQJV5irKMm76G0LGItWs6y+SCjUn/Q0WaMLkEskg==} + '@rollup/rollup-linux-riscv64-gnu@4.24.4': + resolution: {integrity: sha512-Aie/TbmQi6UXokJqDZdmTJuZBCU3QBDA8oTKRGtd4ABi/nHgXICulfg1KI6n9/koDsiDbvHAiQO3YAUNa/7BCw==} cpu: [riscv64] os: [linux] - '@rollup/rollup-linux-s390x-gnu@4.24.2': - resolution: {integrity: sha512-gc97UebApwdsSNT3q79glOSPdfwgwj5ELuiyuiMY3pEWMxeVqLGKfpDFoum4ujivzxn6veUPzkGuSYoh5deQ2Q==} + '@rollup/rollup-linux-s390x-gnu@4.24.4': + resolution: {integrity: sha512-P8MPErVO/y8ohWSP9JY7lLQ8+YMHfTI4bAdtCi3pC2hTeqFJco2jYspzOzTUB8hwUWIIu1xwOrJE11nP+0JFAQ==} cpu: [s390x] os: [linux] - '@rollup/rollup-linux-x64-gnu@4.24.2': - resolution: {integrity: sha512-jOG/0nXb3z+EM6SioY8RofqqmZ+9NKYvJ6QQaa9Mvd3RQxlH68/jcB/lpyVt4lCiqr04IyaC34NzhUqcXbB5FQ==} + '@rollup/rollup-linux-x64-gnu@4.24.4': + resolution: {integrity: sha512-K03TljaaoPK5FOyNMZAAEmhlyO49LaE4qCsr0lYHUKyb6QacTNF9pnfPpXnFlFD3TXuFbFbz7tJ51FujUXkXYA==} cpu: [x64] os: [linux] - '@rollup/rollup-linux-x64-musl@4.24.2': - resolution: {integrity: sha512-XAo7cJec80NWx9LlZFEJQxqKOMz/lX3geWs2iNT5CHIERLFfd90f3RYLLjiCBm1IMaQ4VOX/lTC9lWfzzQm14Q==} + '@rollup/rollup-linux-x64-musl@4.24.4': + resolution: {integrity: sha512-VJYl4xSl/wqG2D5xTYncVWW+26ICV4wubwN9Gs5NrqhJtayikwCXzPL8GDsLnaLU3WwhQ8W02IinYSFJfyo34Q==} cpu: [x64] os: [linux] - '@rollup/rollup-win32-arm64-msvc@4.24.2': - resolution: {integrity: sha512-A+JAs4+EhsTjnPQvo9XY/DC0ztaws3vfqzrMNMKlwQXuniBKOIIvAAI8M0fBYiTCxQnElYu7mLk7JrhlQ+HeOw==} + '@rollup/rollup-win32-arm64-msvc@4.24.4': + resolution: {integrity: sha512-ku2GvtPwQfCqoPFIJCqZ8o7bJcj+Y54cZSr43hHca6jLwAiCbZdBUOrqE6y29QFajNAzzpIOwsckaTFmN6/8TA==} cpu: [arm64] os: [win32] - '@rollup/rollup-win32-ia32-msvc@4.24.2': - resolution: {integrity: sha512-ZhcrakbqA1SCiJRMKSU64AZcYzlZ/9M5LaYil9QWxx9vLnkQ9Vnkve17Qn4SjlipqIIBFKjBES6Zxhnvh0EAEw==} + '@rollup/rollup-win32-ia32-msvc@4.24.4': + resolution: {integrity: sha512-V3nCe+eTt/W6UYNr/wGvO1fLpHUrnlirlypZfKCT1fG6hWfqhPgQV/K/mRBXBpxc0eKLIF18pIOFVPh0mqHjlg==} cpu: [ia32] os: [win32] - '@rollup/rollup-win32-x64-msvc@4.24.2': - resolution: {integrity: sha512-2mLH46K1u3r6uwc95hU+OR9q/ggYMpnS7pSp83Ece1HUQgF9Nh/QwTK5rcgbFnV9j+08yBrU5sA/P0RK2MSBNA==} + '@rollup/rollup-win32-x64-msvc@4.24.4': + resolution: {integrity: sha512-LTw1Dfd0mBIEqUVCxbvTE/LLo+9ZxVC9k99v1v4ahg9Aak6FpqOfNu5kRkeTAn0wphoC4JU7No1/rL+bBCEwhg==} cpu: [x64] os: [win32] '@types/estree@1.0.6': resolution: {integrity: sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==} - '@types/node@22.8.2': - resolution: {integrity: sha512-NzaRNFV+FZkvK/KLCsNdTvID0SThyrs5SHB6tsD/lajr22FGC73N2QeDPM2wHtVde8mgcXuSsHQkH5cX1pbPLw==} + '@types/node@22.9.0': + resolution: {integrity: sha512-vuyHg81vvWA1Z1ELfvLko2c8f34gyA0zaic0+Rllc5lbCnbSyuvb2Oxpm6TAUAC/2xZN3QGqxBNggD1nNR2AfQ==} '@vitest/coverage-v8@2.1.4': resolution: {integrity: sha512-FPKQuJfR6VTfcNMcGpqInmtJuVXFSCd9HQltYncfR01AzXhLucMEtQ5SinPdZxsT5x/5BK7I5qFJ5/ApGCmyTQ==} @@ -569,8 +569,8 @@ packages: resolution: {integrity: sha512-56rxCq7G/XfB4EkXq9Egn5GCqugWvDFjafDOThIdMBsI15iqPqR5r15TfSr1YPYeEI19YeaXMCbY6u88Y76GLQ==} engines: {node: ^10 || ^12 || >=14} - rollup@4.24.2: - resolution: {integrity: sha512-do/DFGq5g6rdDhdpPq5qb2ecoczeK6y+2UAjdJ5trjQJj5f1AiVdLRWRc9A9/fFukfvJRgM0UXzxBIYMovm5ww==} + rollup@4.24.4: + resolution: {integrity: sha512-vGorVWIsWfX3xbcyAS+I047kFKapHYivmkaT63Smj77XwvLSJos6M1xGqZnBPFQFBRZDOcG1QnYEIxAvTr/HjA==} engines: {node: '>=18.0.0', npm: '>=8.0.0'} hasBin: true @@ -748,7 +748,7 @@ snapshots: '@babel/helper-validator-identifier@7.25.9': {} - '@babel/parser@7.26.1': + '@babel/parser@7.26.2': dependencies: '@babel/types': 7.26.0 @@ -759,7 +759,7 @@ snapshots: '@bcoe/v8-coverage@0.2.3': {} - '@ecies/ciphers@0.2.0(@noble/ciphers@1.0.0)': + '@ecies/ciphers@0.2.1(@noble/ciphers@1.0.0)': dependencies: '@noble/ciphers': 1.0.0 @@ -871,67 +871,67 @@ snapshots: '@pkgjs/parseargs@0.11.0': optional: true - '@rollup/rollup-android-arm-eabi@4.24.2': + '@rollup/rollup-android-arm-eabi@4.24.4': optional: true - '@rollup/rollup-android-arm64@4.24.2': + '@rollup/rollup-android-arm64@4.24.4': optional: true - '@rollup/rollup-darwin-arm64@4.24.2': + '@rollup/rollup-darwin-arm64@4.24.4': optional: true - '@rollup/rollup-darwin-x64@4.24.2': + '@rollup/rollup-darwin-x64@4.24.4': optional: true - '@rollup/rollup-freebsd-arm64@4.24.2': + '@rollup/rollup-freebsd-arm64@4.24.4': optional: true - '@rollup/rollup-freebsd-x64@4.24.2': + '@rollup/rollup-freebsd-x64@4.24.4': optional: true - '@rollup/rollup-linux-arm-gnueabihf@4.24.2': + '@rollup/rollup-linux-arm-gnueabihf@4.24.4': optional: true - '@rollup/rollup-linux-arm-musleabihf@4.24.2': + '@rollup/rollup-linux-arm-musleabihf@4.24.4': optional: true - '@rollup/rollup-linux-arm64-gnu@4.24.2': + '@rollup/rollup-linux-arm64-gnu@4.24.4': optional: true - '@rollup/rollup-linux-arm64-musl@4.24.2': + '@rollup/rollup-linux-arm64-musl@4.24.4': optional: true - '@rollup/rollup-linux-powerpc64le-gnu@4.24.2': + '@rollup/rollup-linux-powerpc64le-gnu@4.24.4': optional: true - '@rollup/rollup-linux-riscv64-gnu@4.24.2': + '@rollup/rollup-linux-riscv64-gnu@4.24.4': optional: true - '@rollup/rollup-linux-s390x-gnu@4.24.2': + '@rollup/rollup-linux-s390x-gnu@4.24.4': optional: true - '@rollup/rollup-linux-x64-gnu@4.24.2': + '@rollup/rollup-linux-x64-gnu@4.24.4': optional: true - '@rollup/rollup-linux-x64-musl@4.24.2': + '@rollup/rollup-linux-x64-musl@4.24.4': optional: true - '@rollup/rollup-win32-arm64-msvc@4.24.2': + '@rollup/rollup-win32-arm64-msvc@4.24.4': optional: true - '@rollup/rollup-win32-ia32-msvc@4.24.2': + '@rollup/rollup-win32-ia32-msvc@4.24.4': optional: true - '@rollup/rollup-win32-x64-msvc@4.24.2': + '@rollup/rollup-win32-x64-msvc@4.24.4': optional: true '@types/estree@1.0.6': {} - '@types/node@22.8.2': + '@types/node@22.9.0': dependencies: undici-types: 6.19.8 - '@vitest/coverage-v8@2.1.4(vitest@2.1.4(@types/node@22.8.2))': + '@vitest/coverage-v8@2.1.4(vitest@2.1.4(@types/node@22.9.0))': dependencies: '@ampproject/remapping': 2.3.0 '@bcoe/v8-coverage': 0.2.3 @@ -945,7 +945,7 @@ snapshots: std-env: 3.7.0 test-exclude: 7.0.1 tinyrainbow: 1.2.0 - vitest: 2.1.4(@types/node@22.8.2) + vitest: 2.1.4(@types/node@22.9.0) transitivePeerDependencies: - supports-color @@ -956,13 +956,13 @@ snapshots: chai: 5.1.2 tinyrainbow: 1.2.0 - '@vitest/mocker@2.1.4(vite@5.4.10(@types/node@22.8.2))': + '@vitest/mocker@2.1.4(vite@5.4.10(@types/node@22.9.0))': dependencies: '@vitest/spy': 2.1.4 estree-walker: 3.0.3 magic-string: 0.30.12 optionalDependencies: - vite: 5.4.10(@types/node@22.8.2) + vite: 5.4.10(@types/node@22.9.0) '@vitest/pretty-format@2.1.4': dependencies: @@ -1137,7 +1137,7 @@ snapshots: magicast@0.3.5: dependencies: - '@babel/parser': 7.26.1 + '@babel/parser': 7.26.2 '@babel/types': 7.26.0 source-map-js: 1.2.1 @@ -1176,28 +1176,28 @@ snapshots: picocolors: 1.1.1 source-map-js: 1.2.1 - rollup@4.24.2: + rollup@4.24.4: dependencies: '@types/estree': 1.0.6 optionalDependencies: - '@rollup/rollup-android-arm-eabi': 4.24.2 - '@rollup/rollup-android-arm64': 4.24.2 - '@rollup/rollup-darwin-arm64': 4.24.2 - '@rollup/rollup-darwin-x64': 4.24.2 - '@rollup/rollup-freebsd-arm64': 4.24.2 - '@rollup/rollup-freebsd-x64': 4.24.2 - '@rollup/rollup-linux-arm-gnueabihf': 4.24.2 - '@rollup/rollup-linux-arm-musleabihf': 4.24.2 - '@rollup/rollup-linux-arm64-gnu': 4.24.2 - '@rollup/rollup-linux-arm64-musl': 4.24.2 - '@rollup/rollup-linux-powerpc64le-gnu': 4.24.2 - '@rollup/rollup-linux-riscv64-gnu': 4.24.2 - '@rollup/rollup-linux-s390x-gnu': 4.24.2 - '@rollup/rollup-linux-x64-gnu': 4.24.2 - '@rollup/rollup-linux-x64-musl': 4.24.2 - '@rollup/rollup-win32-arm64-msvc': 4.24.2 - '@rollup/rollup-win32-ia32-msvc': 4.24.2 - '@rollup/rollup-win32-x64-msvc': 4.24.2 + '@rollup/rollup-android-arm-eabi': 4.24.4 + '@rollup/rollup-android-arm64': 4.24.4 + '@rollup/rollup-darwin-arm64': 4.24.4 + '@rollup/rollup-darwin-x64': 4.24.4 + '@rollup/rollup-freebsd-arm64': 4.24.4 + '@rollup/rollup-freebsd-x64': 4.24.4 + '@rollup/rollup-linux-arm-gnueabihf': 4.24.4 + '@rollup/rollup-linux-arm-musleabihf': 4.24.4 + '@rollup/rollup-linux-arm64-gnu': 4.24.4 + '@rollup/rollup-linux-arm64-musl': 4.24.4 + '@rollup/rollup-linux-powerpc64le-gnu': 4.24.4 + '@rollup/rollup-linux-riscv64-gnu': 4.24.4 + '@rollup/rollup-linux-s390x-gnu': 4.24.4 + '@rollup/rollup-linux-x64-gnu': 4.24.4 + '@rollup/rollup-linux-x64-musl': 4.24.4 + '@rollup/rollup-win32-arm64-msvc': 4.24.4 + '@rollup/rollup-win32-ia32-msvc': 4.24.4 + '@rollup/rollup-win32-x64-msvc': 4.24.4 fsevents: 2.3.3 semver@7.6.3: {} @@ -1264,12 +1264,12 @@ snapshots: undici@6.20.1: {} - vite-node@2.1.4(@types/node@22.8.2): + vite-node@2.1.4(@types/node@22.9.0): dependencies: cac: 6.7.14 debug: 4.3.7 pathe: 1.1.2 - vite: 5.4.10(@types/node@22.8.2) + vite: 5.4.10(@types/node@22.9.0) transitivePeerDependencies: - '@types/node' - less @@ -1281,19 +1281,19 @@ snapshots: - supports-color - terser - vite@5.4.10(@types/node@22.8.2): + vite@5.4.10(@types/node@22.9.0): dependencies: esbuild: 0.21.5 postcss: 8.4.47 - rollup: 4.24.2 + rollup: 4.24.4 optionalDependencies: - '@types/node': 22.8.2 + '@types/node': 22.9.0 fsevents: 2.3.3 - vitest@2.1.4(@types/node@22.8.2): + vitest@2.1.4(@types/node@22.9.0): dependencies: '@vitest/expect': 2.1.4 - '@vitest/mocker': 2.1.4(vite@5.4.10(@types/node@22.8.2)) + '@vitest/mocker': 2.1.4(vite@5.4.10(@types/node@22.9.0)) '@vitest/pretty-format': 2.1.4 '@vitest/runner': 2.1.4 '@vitest/snapshot': 2.1.4 @@ -1309,11 +1309,11 @@ snapshots: tinyexec: 0.3.1 tinypool: 1.0.1 tinyrainbow: 1.2.0 - vite: 5.4.10(@types/node@22.8.2) - vite-node: 2.1.4(@types/node@22.8.2) + vite: 5.4.10(@types/node@22.9.0) + vite-node: 2.1.4(@types/node@22.9.0) why-is-node-running: 2.3.0 optionalDependencies: - '@types/node': 22.8.2 + '@types/node': 22.9.0 transitivePeerDependencies: - less - lightningcss diff --git a/scripts/check-runtime.sh b/scripts/check-runtime.sh new file mode 100755 index 0000000..749a3c8 --- /dev/null +++ b/scripts/check-runtime.sh @@ -0,0 +1,4 @@ +#!/bin/sh +bun run $1 +deno run --allow-read $1 +node $1 diff --git a/scripts/gen-browser-tests.mjs b/scripts/gen-browser-tests.mjs new file mode 100644 index 0000000..90844c1 --- /dev/null +++ b/scripts/gen-browser-tests.mjs @@ -0,0 +1,35 @@ +import fs from "node:fs"; +import path from "node:path"; + +const handleFile = (srcPath, dstPath, ...pipelines) => { + let data = fs.readFileSync(srcPath, "utf8"); + for (const f of pipelines) { + data = f(data); + } + const dstDir = path.dirname(dstPath); + if (!fs.existsSync(dstDir)) { + fs.mkdirSync(dstDir); + } + fs.writeFileSync(dstPath, data); +}; + +const polyfill = `import { Buffer } from "buffer"; +globalThis.Buffer = Buffer; + +`; + +const pipelines = [ + (data) => polyfill + data, + (data) => data.replaceAll("../../src", "eciesjs"), +]; + +handleFile( + "./tests/crypt/random.test.ts", + "./tests-browser/crypt/random.test.ts", + ...pipelines +); +handleFile( + "./tests/crypt/known.test.ts", + "./tests-browser/crypt/known.test.ts", + ...pipelines +); diff --git a/tests-browser/package.json b/tests-browser/package.json new file mode 100644 index 0000000..1601f7f --- /dev/null +++ b/tests-browser/package.json @@ -0,0 +1,18 @@ +{ + "name": "tests-browser", + "description": "Test browser compatibility", + "private": true, + "version": "0.1.0", + "scripts": { + "test": "vitest" + }, + "dependencies": { + "buffer": "^6.0.3", + "eciesjs": "file:.." + }, + "devDependencies": { + "@vitest/browser": "^2.1.4", + "playwright": "^1.48.2", + "vitest": "^2.1.4" + } +} diff --git a/vitest.config.ts b/tests-browser/vitest.config.mts similarity index 56% rename from vitest.config.ts rename to tests-browser/vitest.config.mts index 5ffaf1d..3796e43 100644 --- a/vitest.config.ts +++ b/tests-browser/vitest.config.mts @@ -2,10 +2,11 @@ import { defineConfig } from "vitest/config"; export default defineConfig({ test: { - coverage: { - include: ["src/**"], + browser: { enabled: true, - provider: "v8", + name: "chromium", + provider: "playwright", + providerOptions: {}, }, }, }); diff --git a/vitest.config.mts b/vitest.config.mts new file mode 100644 index 0000000..4381eb3 --- /dev/null +++ b/vitest.config.mts @@ -0,0 +1,12 @@ +import { configDefaults, defineConfig } from "vitest/config"; + +export default defineConfig({ + test: { + exclude: [...configDefaults.exclude, "tests-browser/**"], + coverage: { + include: ["src/**"], + enabled: true, + provider: "v8", + }, + }, +});