Skip to content

Commit ec01db3

Browse files
feat: added TON support + performance improvements (#240)
1 parent 5d9ce23 commit ec01db3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1639
-1235
lines changed

.github/workflows/release-android-base.yaml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,23 @@ jobs:
8282
google-services-file: ${{ secrets.google-services-file }}
8383
if: ${{ env.google-services-file != '' }}
8484
run: echo ${{ env.google-services-file }} | base64 --decode >> ${{ inputs.root-path }}/android/app/google-services.json
85-
85+
86+
- name: Optimize Gradle for CI
87+
run: |
88+
echo "org.gradle.jvmargs=-Xmx4096m -XX:MaxMetaspaceSize=1024m" >> ${{ inputs.root-path }}/android/gradle.properties
89+
echo "org.gradle.parallel=true" >> ${{ inputs.root-path }}/android/gradle.properties
90+
echo "org.gradle.caching=true" >> ${{ inputs.root-path }}/android/gradle.properties
91+
92+
- name: Cache Gradle
93+
uses: actions/cache@v3
94+
with:
95+
path: |
96+
~/.gradle/caches
97+
~/.gradle/wrapper
98+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
99+
restore-keys: |
100+
${{ runner.os }}-gradle-
101+
86102
- name: Build APK
87103
run: |
88104
if [ ${{ inputs.release-type }} = 'internal' ]; then

dapps/W3MEthers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"private": true,
44
"scripts": {
55
"android": "react-native run-android",
6-
"android:build": "cd android && ./gradlew clean && ./gradlew assembleRelease",
6+
"android:build": "cd android && ./gradlew clean && ./gradlew assembleRelease -PreactNativeArchitectures=arm64-v8a",
77
"ios": "react-native run-ios",
88
"lint": "eslint .",
99
"start": "react-native start",

dapps/W3MEthers5/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"private": true,
44
"scripts": {
55
"android": "react-native run-android",
6-
"android:build": "cd android && ./gradlew clean && ./gradlew assembleRelease",
6+
"android:build": "cd android && ./gradlew clean && ./gradlew assembleRelease -PreactNativeArchitectures=arm64-v8a",
77
"ios": "react-native run-ios",
88
"lint": "eslint .",
99
"start": "react-native start",

dapps/W3MWagmi/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"private": true,
44
"scripts": {
55
"android": "yarn run copy:debug && react-native run-android --appId com.walletconnect.web3modal.rnsample.debug",
6-
"android:build": "yarn run copy:production && cd android && ./gradlew clean && ./gradlew assembleRelease",
7-
"android:build:internal": "yarn run copy:internal && cd android && ./gradlew clean && ./gradlew assembleInternal",
6+
"android:build": "yarn run copy:production && cd android && ./gradlew clean && ./gradlew assembleRelease -PreactNativeArchitectures=arm64-v8a",
7+
"android:build:internal": "yarn run copy:internal && cd android && ./gradlew clean && ./gradlew assembleInternal -PreactNativeArchitectures=arm64-v8a",
88
"ios": "react-native run-ios",
99
"ios:internal": "react-native run-ios --scheme 'W3MWagmi Internal' ",
1010
"lint": "eslint .",

wallets/rn_cli_wallet/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
ENV_PROJECT_ID='39bc93c...'
44
ENV_RELAY_URL='wss://relay.walletconnect.org'
55
ENV_SENTRY_DSN=''
6+
ENV_TON_CENTER_API_KEY=''
67

78
# for android builds. for iOS check xcode.env file
89
SENTRY_DISABLE_AUTO_UPLOAD=true
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
diff --git a/dist/native/getSecureRandom.js b/dist/native/getSecureRandom.js
2+
index b769fd9ad676132979c406b5c77bea98838a2104..b3a153661498e349dd502295cf61075d29892fb6 100644
3+
--- a/dist/native/getSecureRandom.js
4+
+++ b/dist/native/getSecureRandom.js
5+
@@ -8,9 +8,10 @@
6+
*/
7+
Object.defineProperty(exports, "__esModule", { value: true });
8+
exports.getSecureRandomWords = exports.getSecureRandomBytes = void 0;
9+
-const getRandomBytes = require('expo-crypto').getRandomBytes;
10+
function getSecureRandomBytes(size) {
11+
- return Buffer.from(getRandomBytes(size));
12+
+ const bytes = new Uint8Array(size);
13+
+ crypto.getRandomValues(bytes);
14+
+ return Buffer.from(bytes);
15+
}
16+
exports.getSecureRandomBytes = getSecureRandomBytes;
17+
function getSecureRandomWords(size) {
18+
diff --git a/dist/native/pbkdf2_sha512.js b/dist/native/pbkdf2_sha512.js
19+
index fe733396a95b9374665953bb102cdaa0f4d69e9c..4eecb6bb5f46c796316ae3cd5a461aaa5b4862fe 100644
20+
--- a/dist/native/pbkdf2_sha512.js
21+
+++ b/dist/native/pbkdf2_sha512.js
22+
@@ -11,7 +11,8 @@ exports.pbkdf2_sha512 = void 0;
23+
async function pbkdf2_sha512(key, salt, iterations, keyLen) {
24+
const keyBuffer = typeof key === 'string' ? Buffer.from(key, 'utf-8') : key;
25+
const saltBuffer = typeof salt === 'string' ? Buffer.from(salt, 'utf-8') : salt;
26+
- let pbkdf2 = require('react-native-fast-pbkdf2').default;
27+
+ var crypto = require("crypto");
28+
+ let pbkdf2 = crypto.pbkdf2Sync;
29+
- let res = await pbkdf2.derive(keyBuffer.toString('base64'), saltBuffer.toString('base64'), iterations, keyLen, 'sha-512');
30+
+ let res = crypto.pbkdf2Sync(keyBuffer, saltBuffer, iterations, keyLen, 'sha512');
31+
- return Buffer.from(res, 'base64');
32+
+ return res;
33+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
diff --git a/src/index.js b/src/index.js
2+
index b83863f4b3d09df1159eb2c05d43e20a05d55767..926895a1f697905d48bf32f32fc538de3ce1b252 100644
3+
--- a/src/index.js
4+
+++ b/src/index.js
5+
@@ -38,20 +38,68 @@ function salt(password) {
6+
function mnemonicToSeedSync(mnemonic, password) {
7+
const mnemonicBuffer = Uint8Array.from(Buffer.from(normalize(mnemonic), 'utf8'));
8+
const saltBuffer = Uint8Array.from(Buffer.from(salt(normalize(password)), 'utf8'));
9+
- const res = pbkdf2_1.pbkdf2(sha512_1.sha512, mnemonicBuffer, saltBuffer, {
10+
- c: 2048,
11+
- dkLen: 64,
12+
- });
13+
- return Buffer.from(res);
14+
+
15+
+ // Use react-native-quick-crypto's native PBKDF2
16+
+ try {
17+
+ var crypto = require("crypto");
18+
+ const res = crypto.pbkdf2Sync(
19+
+ mnemonicBuffer,
20+
+ saltBuffer,
21+
+ 2048, // iterations
22+
+ 64, // key length
23+
+ 'sha512'
24+
+ );
25+
+ return Buffer.from(res);
26+
+ } catch (e) {
27+
+ console.warn('Native pbkdf2Sync failed, falling back to JS implementation', e);
28+
+ // Fallback to original implementation
29+
+ const res = pbkdf2_1.pbkdf2(sha512_1.sha512, mnemonicBuffer, saltBuffer, {
30+
+ c: 2048,
31+
+ dkLen: 64,
32+
+ });
33+
+ return Buffer.from(res);
34+
+ }
35+
}
36+
exports.mnemonicToSeedSync = mnemonicToSeedSync;
37+
+
38+
function mnemonicToSeed(mnemonic, password) {
39+
const mnemonicBuffer = Uint8Array.from(Buffer.from(normalize(mnemonic), 'utf8'));
40+
const saltBuffer = Uint8Array.from(Buffer.from(salt(normalize(password)), 'utf8'));
41+
- return pbkdf2_1.pbkdf2Async(sha512_1.sha512, mnemonicBuffer, saltBuffer, {
42+
- c: 2048,
43+
- dkLen: 64,
44+
- }).then((res) => Buffer.from(res));
45+
+
46+
+ // Use react-native-quick-crypto's native PBKDF2
47+
+ try {
48+
+ var crypto = require("crypto");
49+
+ return new Promise((resolve, reject) => {
50+
+ crypto.pbkdf2(
51+
+ mnemonicBuffer,
52+
+ saltBuffer,
53+
+ 2048, // iterations
54+
+ 64, // key length
55+
+ 'sha512',
56+
+ (err, res) => {
57+
+ if (err) {
58+
+ reject(err);
59+
+ } else {
60+
+ resolve(Buffer.from(res));
61+
+ }
62+
+ }
63+
+ );
64+
+ }).catch((err) => {
65+
+ console.warn('Native pbkdf2 failed, falling back to JS implementation', err);
66+
+ // Fallback to original implementation
67+
+ return pbkdf2_1.pbkdf2Async(sha512_1.sha512, mnemonicBuffer, saltBuffer, {
68+
+ c: 2048,
69+
+ dkLen: 64,
70+
+ }).then((res) => Buffer.from(res));
71+
+ });
72+
+ } catch (e) {
73+
+ console.warn('Native pbkdf2 not available, using JS implementation', e);
74+
+ // Fallback to original implementation
75+
+ return pbkdf2_1.pbkdf2Async(sha512_1.sha512, mnemonicBuffer, saltBuffer, {
76+
+ c: 2048,
77+
+ dkLen: 64,
78+
+ }).then((res) => Buffer.from(res));
79+
+ }
80+
}
81+
exports.mnemonicToSeed = mnemonicToSeed;
82+
function mnemonicToEntropy(mnemonic, wordlist) {

wallets/rn_cli_wallet/declarations.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ declare module 'react-native-config' {
77
ENV_RELAY_URL: string;
88
ENV_SENTRY_DSN: string;
99
ENV_SENTRY_TAG: string;
10+
ENV_TON_CENTER_API_KEY: string;
1011
}
1112

1213
export const Config: NativeConfig;

wallets/rn_cli_wallet/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import 'react-native-gesture-handler';
22
import '@walletconnect/react-native-compat';
33
import {AppRegistry} from 'react-native';
44
import {name as appName} from './app.json';
5-
import crypto from 'react-native-quick-crypto';
5+
import crypto, { install } from 'react-native-quick-crypto';
66

7-
import App from './src/screens/App';
7+
install();
88

99
const polyfillDigest = async (algorithm, data) => {
1010
const algo = algorithm.replace('-', '').toLowerCase();
@@ -13,11 +13,10 @@ const polyfillDigest = async (algorithm, data) => {
1313
return hash.digest();
1414
};
1515

16-
// eslint-disable-next-line no-undef
17-
globalThis.crypto = crypto;
1816
// eslint-disable-next-line no-undef
1917
globalThis.crypto.subtle = {
2018
digest: polyfillDigest,
2119
};
2220

21+
import App from './src/screens/App';
2322
AppRegistry.registerComponent(appName, () => App);

0 commit comments

Comments
 (0)