diff --git a/bun.lock b/bun.lock index 402bc55e..8439323b 100644 --- a/bun.lock +++ b/bun.lock @@ -90,7 +90,6 @@ "example-nitro": { "name": "react-native-quick-crypto-example-nitro", "dependencies": { - "base64-js": "1.5.1", "buffer": "6.0.3", "event-target-polyfill": "0.0.4", "nitro-ui-cli": "0.1.0", @@ -110,8 +109,7 @@ "name": "react-native-quick-crypto", "version": "2.0.0-alpha.0", "dependencies": { - "@craftzdog/react-native-buffer": "^6.1.2", - "base64-js": "1.5.1", + "@craftzdog/react-native-buffer": "^6.1.3", "events": "3.3.0", "readable-stream": "4.7.0", "safe-buffer": "^5.2.1", @@ -424,7 +422,7 @@ "@conventional-changelog/git-client": ["@conventional-changelog/git-client@1.0.1", "", { "dependencies": { "@types/semver": "^7.5.5", "semver": "^7.5.2" }, "peerDependencies": { "conventional-commits-filter": "^5.0.0", "conventional-commits-parser": "^6.0.0" }, "optionalPeers": ["conventional-commits-filter", "conventional-commits-parser"] }, "sha512-PJEqBwAleffCMETaVm/fUgHldzBE35JFk3/9LL6NUA5EXa3qednu+UT6M7E5iBu3zIQZCULYIiZ90fBYHt6xUw=="], - "@craftzdog/react-native-buffer": ["@craftzdog/react-native-buffer@6.1.2", "", { "dependencies": { "ieee754": "^1.2.1", "react-native-quick-base64": "^3.0.0" } }, "sha512-KV1HitN05FHLLDG7Zb/yftDsa+mKBYBzFMQ0PMldvUicq6vWOtAvz9mDavt7Fzozh+WNqORE+yFDkkdWysZ/SA=="], + "@craftzdog/react-native-buffer": ["@craftzdog/react-native-buffer@6.1.3", "", { "dependencies": { "base64-js": "^1.5.1", "ieee754": "^1.2.1", "react-native-quick-base64": "^3.0.0" } }, "sha512-vDIdi27iRDrP6u7eUT9zis67Yhz+zSdBXbRDL3EP0thnOqZdRsX1z0F2mzCImzLvJIs1cOwr5+vIth3BOBNhyw=="], "@eslint-community/eslint-utils": ["@eslint-community/eslint-utils@4.9.1", "", { "dependencies": { "eslint-visitor-keys": "^3.4.3" }, "peerDependencies": { "eslint": "^6.0.0 || ^7.0.0 || >=8.0.0" } }, "sha512-phrYmNiYppR7znFEdqgfWHXR6NCkZEK7hwWDHZUjit/2/U0r6XvkDl0SYnoM51Hq7FhCGdLDT6zxCCOY1hexsQ=="], diff --git a/docs/content/docs/guides/bare-host.mdx b/docs/content/docs/guides/bare-host.mdx index 686c8e15..27b19aed 100644 --- a/docs/content/docs/guides/bare-host.mdx +++ b/docs/content/docs/guides/bare-host.mdx @@ -85,7 +85,7 @@ Bundle for your host without the `react-native` export condition. RNQC's `export Hermes does not support async generators, so run your bundle through a transform such as `@babel/plugin-transform-async-generator-functions`. The bundle also needs runtime globals such as `global`, `setImmediate`, `process` and `AbortController`. -The shared entry uses `@craftzdog/react-native-buffer`. Off React Native it uses `base64-js`, but your bundler still has to resolve its React Native branch. Alias `react-native-quick-base64` to `base64-js` in your bundler. The shared entry also imports `util` and `string_decoder`, so your host needs polyfills for them. +The shared entry uses `@craftzdog/react-native-buffer` 6.1.3 or newer, which uses `base64-js` unless a React Native bundler redirects it through its `react-native` field, so no base64 alias is needed. The shared entry also imports `util` and `string_decoder`, so your host needs polyfills for them. If your bundler honors the `browser` condition, packages such as `multiformats` resolve to builds that call `crypto.subtle` instead of `createHash`. Alias those subpaths to their Node builds if you want them to use RNQC's `crypto` export. @@ -112,6 +112,5 @@ The pieces a bare host needs, as the script wires them: 1. `margelo::nitro::install(runtime, dispatcher)` before any JavaScript loads RNQC. 2. Registration: `System.loadLibrary("QuickCrypto")` on Android after Nitro core is loaded, and a single `registerHybridClasses()` call on Apple (guard it with `std::call_once` if the runtime is created more than once). -3. A bundle with `react-native-quick-base64` aliased to `base64-js`. -4. A prelude that defines the globals bare Hermes lacks: `global`, `self`, `console`, `AbortController`/`AbortSignal`, and `kCustomPromisifiedSymbol` (read by the bundled `util` polyfill). See `example/test/bare/prelude.ts`. -5. An async-generator transform (`@babel/plugin-transform-async-generator-functions`) over the finished bundle, because Hermes rejects async generators and `for await`. See `example/test/bare/host/hermes-transform.mjs`. +3. A prelude that defines the globals bare Hermes lacks: `global`, `self`, `console`, `AbortController`/`AbortSignal`, and `kCustomPromisifiedSymbol` (read by the bundled `util` polyfill). See `example/test/bare/prelude.ts`. +4. An async-generator transform (`@babel/plugin-transform-async-generator-functions`) over the finished bundle, because Hermes rejects async generators and `for await`. See `example/test/bare/host/hermes-transform.mjs`. diff --git a/example-nitro/app.json b/example-nitro/app.json index 026eb35a..8126f1d4 100644 --- a/example-nitro/app.json +++ b/example-nitro/app.json @@ -3,7 +3,6 @@ "alias": { "react-native-quick-crypto": "../packages/react-native-quick-crypto/src/index.ts", "crypto": "../packages/react-native-quick-crypto/src/index.ts", - "stream": "readable-stream", - "react-native-quick-base64": "base64-js" + "stream": "readable-stream" } } diff --git a/example-nitro/package.json b/example-nitro/package.json index 0fd66d1e..f552549e 100644 --- a/example-nitro/package.json +++ b/example-nitro/package.json @@ -11,7 +11,6 @@ "typescript": "tsc --noEmit" }, "dependencies": { - "base64-js": "1.5.1", "buffer": "6.0.3", "event-target-polyfill": "0.0.4", "nitro-ui-cli": "0.1.0", diff --git a/example-nitro/src/polyfills.ts b/example-nitro/src/polyfills.ts index f03a5146..3fe8cca5 100644 --- a/example-nitro/src/polyfills.ts +++ b/example-nitro/src/polyfills.ts @@ -24,20 +24,4 @@ class TextDecoderPolyfill { const g = globalThis as Record; g.TextEncoder ??= TextEncoderPolyfill; g.TextDecoder ??= TextDecoderPolyfill; -// RNQC's React Native install() sets these from react-native-quick-base64. Assigned, not -// ??=, because a single-script bundle hoists same-named test helpers onto globalThis. -g.base64ToArrayBuffer = (s: string, removeLinebreaks = false): ArrayBuffer => { - const b = Buffer.from( - removeLinebreaks ? s.replace(/[\r\n]/g, '') : s, - 'base64', - ); - return b.buffer.slice( - b.byteOffset, - b.byteOffset + b.byteLength, - ) as ArrayBuffer; -}; -g.base64FromArrayBuffer = (b: ArrayBuffer, urlSafe = false): string => { - const s = Buffer.from(b).toString('base64'); - return urlSafe ? s.replace(/\+/g, '-').replace(/\//g, '_') : s; -}; g.structuredClone ??= (obj: T): T => JSON.parse(JSON.stringify(obj)) as T; diff --git a/example/test/bare/aliases.mjs b/example/test/bare/aliases.mjs index cb9efc47..2b0050cc 100644 --- a/example/test/bare/aliases.mjs +++ b/example/test/bare/aliases.mjs @@ -7,7 +7,6 @@ const rnqcEntry = fileURLToPath( ), ); const aliases = { - 'react-native-quick-base64': fileURLToPath(import.meta.resolve('base64-js')), 'react-native-quick-crypto': rnqcEntry, crypto: rnqcEntry, 'node:crypto': rnqcEntry, diff --git a/packages/react-native-quick-crypto/package.json b/packages/react-native-quick-crypto/package.json index ed99b66f..6ab1e080 100644 --- a/packages/react-native-quick-crypto/package.json +++ b/packages/react-native-quick-crypto/package.json @@ -135,8 +135,7 @@ "registry": "https://registry.npmjs.org/" }, "dependencies": { - "@craftzdog/react-native-buffer": "^6.1.2", - "base64-js": "1.5.1", + "@craftzdog/react-native-buffer": "^6.1.3", "events": "3.3.0", "readable-stream": "4.7.0", "safe-buffer": "^5.2.1", diff --git a/scripts/bare-host.sh b/scripts/bare-host.sh index ef0934c6..033252c0 100755 --- a/scripts/bare-host.sh +++ b/scripts/bare-host.sh @@ -23,7 +23,7 @@ # # Prerequisites: Xcode (iphonesimulator SDK and a simulator runtime), bun, cmake, # ninja, git, rsync, a bun-installed repo (example/node_modules provides the -# base64-js and multiformats packages that aliases.mjs resolves), and network +# multiformats package that aliases.mjs resolves), and network # access on first run # (Nitro, Hermes, OpenSSL binary target, simdutf-swift). #