Skip to content

Commit 7048bae

Browse files
committed
fix(rn): TON crypto deps, Buffer subarray polyfill, migrate on Vercel dev
- Add expo-crypto and react-native-fast-pbkdf2 for @ton/crypto-primitives on React Native. - Patch Buffer.prototype.subarray so Hermes slices are real buffer Buffers with .copy() (fixes @ton/core BitBuilder). - Remove SKIP_DB_MIGRATE from dev:vercel and start-expo-managed so local Vercel runs DB migrations. Made-with: Cursor
1 parent cbe4036 commit 7048bae

4 files changed

Lines changed: 45 additions & 4 deletions

File tree

package-lock.json

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"android": "expo start --android",
3636
"ios": "expo start --ios",
3737
"web": "expo start --web",
38-
"dev:vercel": "cross-env SKIP_DB_MIGRATE=1 TS_NODE_PROJECT=api/tsconfig.json npx vercel dev --yes",
38+
"dev:vercel": "cross-env TS_NODE_PROJECT=api/tsconfig.json npx vercel dev --yes",
3939
"lint": "expo lint",
4040
"draft": "npx eas-cli@latest workflow:run create-draft.yml",
4141
"development-builds": "npx eas-cli@latest workflow:run create-development-builds.yml",
@@ -148,6 +148,7 @@
148148
"expo": "~54.0.0",
149149
"expo-blur": "~15.0.8",
150150
"expo-constants": "~18.0.13",
151+
"expo-crypto": "~15.0.8",
151152
"expo-font": "~14.0.11",
152153
"expo-haptics": "~15.0.8",
153154
"expo-image": "~3.0.11",
@@ -165,6 +166,7 @@
165166
"react": "19.1.0",
166167
"react-dom": "19.1.0",
167168
"react-native": "0.81.5",
169+
"react-native-fast-pbkdf2": "^0.3.1",
168170
"react-native-gesture-handler": "~2.28.0",
169171
"react-native-reanimated": "~4.1.1",
170172
"react-native-safe-area-context": "~5.6.2",

polyfills/buffer.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
/**
22
* Load before any module that touches Node's `Buffer` at evaluation time (e.g. @ton/*).
33
* Browsers and Telegram WebView do not define `globalThis.Buffer`.
4+
*
5+
* Hermes / RN: `Buffer.prototype.subarray` can follow `Uint8Array` and return a slice
6+
* without `.copy()`. `@ton/core` BitBuilder.buffer() does `this._buffer.subarray(...).copy(...)`.
7+
* Always return a real `buffer` package Buffer from subarray.
48
*/
59
import { Buffer } from "buffer";
610

7-
if (typeof globalThis !== "undefined" && !(globalThis as { Buffer?: unknown }).Buffer) {
8-
(globalThis as { Buffer: typeof Buffer }).Buffer = Buffer;
11+
const BufferImpl = Buffer;
12+
const uint8Subarray = Uint8Array.prototype.subarray;
13+
14+
if (typeof globalThis !== "undefined") {
15+
(globalThis as { Buffer: typeof BufferImpl }).Buffer = BufferImpl;
16+
17+
BufferImpl.prototype.subarray = function subarrayPatched(
18+
this: Buffer,
19+
start?: number,
20+
end?: number,
21+
): Buffer {
22+
const slice = uint8Subarray.call(this, start, end);
23+
return BufferImpl.from(slice);
24+
};
925
}

scripts/start-expo-managed.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ async function main() {
5555
stdio: "inherit",
5656
env: {
5757
...process.env,
58-
SKIP_DB_MIGRATE: "1",
5958
TS_NODE_PROJECT: "api/tsconfig.json",
6059
},
6160
});

0 commit comments

Comments
 (0)