Skip to content

[Dev]: Dev<->Master #4315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open

[Dev]: Dev<->Master #4315

wants to merge 36 commits into from

Conversation

satoshiotomakan
Copy link
Collaborator

@satoshiotomakan satoshiotomakan commented Mar 18, 2025

Description

This PR introduces significant changes for C++ to Rust migration in Wallet Core:

  1. A PrivateKey can no longer be constructed without a specific curve. This curve is then used for all signing calls.
  2. PrivateKey and PublicKey implementations have been migrated from TrezorCrypto to Rust via FFIs
  3. Zilliqa schnorr has been implemented in Rust here
  4. PrivateKey/PublicKey validations have been made more robust
  5. Scrypt, PBKDF2 and AES CTR/CBC have been migrated to Rust
  6. Mnemonic creation/validations have been migrated to Rust
    a. Uses bip39 crated with version 2.1.0
  7. Key derivation is being migrated to Rust
    a. Uses bip32with version 0.5.3
    b. Uses ed25519-bip32 with version 0.4.1

Progress

Breaking changes

  • PrivateKey construction now requires a curve to be provided.
TW_EXPORT_STATIC_METHOD
-struct TWPrivateKey* _Nullable TWPrivateKeyCreateWithData(TWData* _Nonnull data);
+struct TWPrivateKey* _Nullable TWPrivateKeyCreateWithData(TWData* _Nonnull data, enum TWCurve curve);
  • Signing APIs no longer require a curve. The one provided at the time of construction is used instead.
TW_EXPORT_METHOD
-TWData* _Nullable TWPrivateKeySign(struct TWPrivateKey* _Nonnull pk, TWData* _Nonnull digest, enum TWCurve curve);
+TWData* _Nullable TWPrivateKeySign(struct TWPrivateKey* _Nonnull pk, TWData* _Nonnull digest);
  • A new curve type TWCurveZILLIQASchnorr has been introduced. Accordingly, the special APIs for zilliqa signing and verification have been removed. The standard APIs can be used instead with the new curve.
enum TWCurve {
+ TWCurveZILLIQASchnorr
}

enum TWPublicKeyType {
+TWPublicKeyTypeZILLIQASchnorr = 10,
}

-TW_EXPORT_METHOD
-TWData* _Nullable TWPrivateKeySignZilliqaSchnorr(struct TWPrivateKey* _Nonnull pk, TWData* _Nonnull message);

-TW_EXPORT_METHOD
-bool TWPublicKeyVerifyZilliqaSchnorr(struct TWPublicKey *_Nonnull pk, TWData *_Nonnull signature, TWData *_Nonnull message);
  • Zilliqa schnorr pubkey can be retrived from a private key similar to other APIs:
+TW_EXPORT_METHOD
+struct TWPublicKey *_Nonnull TWPrivateKeyGetPublicKeyZilliqaSchnorr(struct TWPrivateKey *_Nonnull pk);
  • isValid checks for both PrivateKey and PublicKey have been made stricter by ensuring that they can actually be constructed from the provided data.
  • If invalid data is still provided at the construction of PrivateKey/PublicKey, an exception is now thrown.
  • TWHDWalletGetMasterKey now returns a nullable private key.
/// \return Corresponding private key. Returns null for `TWCurveED25519ExtendedCardano`.
TW_EXPORT_METHOD
-struct TWPrivateKey* _Nonnull TWHDWalletGetMasterKey(struct TWHDWallet* _Nonnull wallet, enum TWCurve curve);
+struct TWPrivateKey* _Nullable TWHDWalletGetMasterKey(struct TWHDWallet* _Nonnull wallet, enum TWCurve curve);

vcoolish and others added 22 commits October 1, 2024 12:18
* Add deinit for KMP iOS and JVM targets

* Add deinit for JS target

* Add deinit for JS target

* Fix JVM native name

* Reuse one thread on JVM

---------

Co-authored-by: satoshiotomakan <[email protected]>
* Fix kmp issue: memory leak found in Base58.decode in iOS

* Remove unused functions

* Fix failed test cases

* Revert "Fix failed test cases"

This reverts commit 57eee39.

* Revert val -> value argument name refactoring

* Output better indentation

* Revert changes in TWEthereumAbiFunction.h

* Fix inconsistent naming

---------

Co-authored-by: satoshiotomakan <[email protected]>
* feat(ton): Add support for TON 24-words mnemonic in Rust

* feat(ton): Add tw_ton_wallet FFIs

* feat(ton): Add TWTONWallet FFI in C++

* feat(ton): Add tonMnemonic StoredKey type

* feat(ton): Add StoredKey TON tests

* feat(ton): Add TWStoredKey TON tests

* feat(ton): Add TONWallet support in Swift

* TODO add iOS tests

* feat(ton): Add `KeyStore` iOS tests

* feat(ton): Add TONWallet support in JavaScript

* Add `KeyStore` TypeScript tests

* feat(ton): Remove `TonMnemonic` structure, replace with a `validate_mnemonic_words` function

* [CI] Trigger CI

* feat(ton): Fix rustfmt

* feat(ton): Fix C++ build

* feat(ton): Fix C++ build

* feat(ton): Fix C++ build

* feat(ton): Fix C++ address analyzer

* feat(ton): Fix C++ tests

* feat(ton): Add Android tests

* feat(ton): Bump `actions/upload-artifact` to v4

* Bump `dawidd6/action-download-artifact` to v6

* feat(eth): Fix PR comments
* [Chore]: Add GenericPhantomReference.java

* [Chore]: Fix unnecessary null assertion in WalletCoreLibLoader.kt
* Fix Java JVM leak

* clean

* apply to jni

* [Misc]: Upgrade Rust toolchain to `nightly-2025-01-16`

* [Misc]: Fix Clippy warnings

---------

Co-authored-by: Satoshi Otomakan <[email protected]>
Copy link

github-actions bot commented Mar 18, 2025

Binary size comparison

➡️ aarch64-apple-ios:

- 13.93 MB
+ 13.97 MB 	 +41 KB

➡️ aarch64-apple-ios-sim:

- 13.93 MB
+ 13.97 MB 	 +41 KB

➡️ aarch64-linux-android:

- 18.35 MB
+ 18.42 MB 	 +70 KB

➡️ armv7-linux-androideabi:

- 15.37 MB
+ 15.42 MB 	 +47 KB

➡️ wasm32-unknown-emscripten:

- 13.06 MB
+ 13.12 MB 	 +54 KB

* Generate FFI headers in include/TrustWalletCore/Generated folder

* Adds is_generated flag in type_decl and use that for jni generation

* Trigger Build

* Minor fix

* Fix in CPP code gen as well

* Fix for wasm

* Fix for kotlin

* Handle Generated folder in kotlin build

---------

Co-authored-by: Sergei Boiko <[email protected]>
gupnik and others added 2 commits March 20, 2025 10:11
* Use Path API

* Tries to fix cocoa pods release

* Uses include paths

* Fixes cocoapods build as well

* Bumps docker version
* feat(eip7702): Add Biz Smart Contract Account Type (#4319)

* fix(eip7702): Add `UserOperationMode`

* Add `erc4337.biz_account.abi.json` ABI

* fix(eip7702): Add `test_barz_transfer_erc7702_eoa` test

* fix(eip7702): Fix `Biz.execute4337Ops()`

* fix(eip7702): Minor changes

* fix(eip7702): Rename `UserOperationMode` to `SCAccountType`

* fix: tron message sign (#4326)

* Adds ability to specify the curve while constructing Private Key (#4324)

* Adds ability to specify the curve while constructing Private Key

* Adds signing functions without a curve

* Migrates to new API

* Use TWCoinTypeCurve

* Adds Curve

* Adds FFI Tests for Private Key V2 APIs

* Migrates Swift tests to new API

* Migrates Kotlin tests to V2 API

* Migrates WASM tests

* Migrates C++ tests to V2 APIs

* Removes deprecated APIs and migrates all to new ones

---------

Co-authored-by: Sergei Boiko <[email protected]>
Co-authored-by: Yeferson Licet <[email protected]>
gupnik and others added 9 commits March 28, 2025 11:17
* feat(eip7702): Add Biz Smart Contract Account Type (#4319)

* fix(eip7702): Add `UserOperationMode`

* Add `erc4337.biz_account.abi.json` ABI

* fix(eip7702): Add `test_barz_transfer_erc7702_eoa` test

* fix(eip7702): Fix `Biz.execute4337Ops()`

* fix(eip7702): Minor changes

* fix(eip7702): Rename `UserOperationMode` to `SCAccountType`

* fix: tron message sign (#4326)

* Adds ability to specify the curve while constructing Private Key (#4324)

* Adds ability to specify the curve while constructing Private Key

* Adds signing functions without a curve

* Migrates to new API

* Use TWCoinTypeCurve

* Adds Curve

---------

Co-authored-by: Sergei Boiko <[email protected]>
Co-authored-by: Yeferson Licet <[email protected]>
* feat(eip7702): Add Biz Smart Contract Account Type (#4319)

* fix(eip7702): Add `UserOperationMode`

* Add `erc4337.biz_account.abi.json` ABI

* fix(eip7702): Add `test_barz_transfer_erc7702_eoa` test

* fix(eip7702): Fix `Biz.execute4337Ops()`

* fix(eip7702): Minor changes

* fix(eip7702): Rename `UserOperationMode` to `SCAccountType`

* fix: tron message sign (#4326)

* Adds ability to specify the curve while constructing Private Key (#4324)

* Adds ability to specify the curve while constructing Private Key

* Adds signing functions without a curve

* Migrates to new API

* Use TWCoinTypeCurve

* Adds Curve

* feat(eip7702): Add `SetCode` transaction type (#4336)

* fix(eip7702): Add `SetCode` transaction type

* fix(eip7702): Add `Biz.executeBatch` function call

* Add `AuthorizationSigner`

* fix(eip7702): Fix Authorization list RLP encoding

* fix(eip7702): Add `Biz.execute` and `Biz.executeBatch` tests

* fix(eip7702): Add android test

* [CI] Trigger CI

* feat(biz): Adjust `Barz.getEncodedHash` according to the latest changes in Biz contract (#4342)

* fix(biz): Adjust `Barz.getEncodedHash` according to the latest Biz changes

* fix(biz): Adjust Android test

* chore(dependencies): Update `gtest` to 1.16.0 (#4343)

* [ETH]: Makes factory and paymaster optional while serialising UserOpV07 (#4345)

* Uses updated API

---------

Co-authored-by: Sergei Boiko <[email protected]>
Co-authored-by: Yeferson Licet <[email protected]>
* Migrates PrivateKey and PublicKey implementation to Rust

* Migrates PublicKey zilliqa schnorr to rust

* Migrates Zillqa Private Key to rust

* Removes todo

* Makes clippy happy

* Minor fix

* Adds Rust Tests

* Fixes address santization issue

* Fixes doctests

* Adds Zilliqa Schnorr as a separate curve and remove separate signing/verifying APIs for zillqa

* FMT

* Addresses review comments

* Fixes C++ Tests

* Derive ZeroizeOnDrop trait on Zillqa Private Key

* Cleanup public key data

* Adds Tests

* FMT

* Use CByteArrayWrapper

* Addresses review comments

* Addresses review comment

* Removes doc test

* Only allow valid Cardano keys and make TWHDWalletGetMasterKey return an optional
* feat(eip7702): Add Biz Smart Contract Account Type (#4319)

* fix(eip7702): Add `UserOperationMode`

* Add `erc4337.biz_account.abi.json` ABI

* fix(eip7702): Add `test_barz_transfer_erc7702_eoa` test

* fix(eip7702): Fix `Biz.execute4337Ops()`

* fix(eip7702): Minor changes

* fix(eip7702): Rename `UserOperationMode` to `SCAccountType`

* fix: tron message sign (#4326)

* Adds ability to specify the curve while constructing Private Key (#4324)

* Adds ability to specify the curve while constructing Private Key

* Adds signing functions without a curve

* Migrates to new API

* Use TWCoinTypeCurve

* Adds Curve

* feat(eip7702): Add `SetCode` transaction type (#4336)

* fix(eip7702): Add `SetCode` transaction type

* fix(eip7702): Add `Biz.executeBatch` function call

* Add `AuthorizationSigner`

* fix(eip7702): Fix Authorization list RLP encoding

* fix(eip7702): Add `Biz.execute` and `Biz.executeBatch` tests

* fix(eip7702): Add android test

* [CI] Trigger CI

* feat(biz): Adjust `Barz.getEncodedHash` according to the latest changes in Biz contract (#4342)

* fix(biz): Adjust `Barz.getEncodedHash` according to the latest Biz changes

* fix(biz): Adjust Android test

* chore(dependencies): Update `gtest` to 1.16.0 (#4343)

* [ETH]: Makes factory and paymaster optional while serialising UserOpV07 (#4345)

* feat(biz): Allow to call `Biz.execute` when EOA is delegated already (#4351)

* fix(biz): Allow to call `Biz.execute` when EOA is delegated already

* feature(biz): Adopt C++ tests

* feat(biz): Add and fix android tests

* feat(biz): Fix ios tests

* chore(aa): Rename `Execute` and `Batch` to `AAExecute` and `AABatch` correspondingly

* chore(scw): Rename `AABatch` and `AAExecute` to `SCWalletBatch` and `SCWalletExecute`

* chore(uov7): Serialize UserOperation numbers as hex 0x prefixed (#4353)

---------

Co-authored-by: Sergei Boiko <[email protected]>
Co-authored-by: Yeferson Licet <[email protected]>
* Migrates `scrypt.c` to Rust

* Migrates to v4 cache

* Revert "Migrates to v4 cache"

This reverts commit 6113eb5.

* Updates sccache action

* Uses correct version

* Fixes FFI test

* Adds keystore to default

* Fixes Tests

* Clippy fix

* Updates memory for wasm

* Actually use the config

* Renames tw_keystore to tw_crypto and updates test

* FMT
* Migrates `scrypt.c` to Rust

* Migrates to v4 cache

* Revert "Migrates to v4 cache"

This reverts commit 6113eb5.

* Updates sccache action

* Uses correct version

* Fixes FFI test

* Adds keystore to default

* Fixes Tests

* Clippy fix

* Updates memory for wasm

* Actually use the config

* Renames tw_keystore to tw_crypto and updates test

* FMT

* Migrates `pbkdf2.c` to rust

* Addresses review comment

* Minor

* Use tw_ffi to expose FFIs

* Use FFI generator

* Trigger Build

* Uses non null data

* Renames
* Replaces `aeskey.c` with Rust implementation via FFI

* Migrates TWAES as well

* Adds AES CBC

* Trigger Build

* Fixes tests

* Adds tests

* Add C++ tests for CBC

* Adds more C++ Tests

* Addresses review comments

* Addresses remaining review comments

* Minor

* Fix iOS Tests

* Fix API
* Replaces `bip39.c` with Rust implementation via FFI

* Makes clippy happy and minor fix

* Minor fix

* Minor

* Adds support for Nonnull<TWString> in code generator

* Fixes sample go

* Tries to fix memory leak

* Use `toStringOrDefault()`

* Addresses review comments

* Further changes

* Uses reference from BIP32 crate to obtain the seed

* Minor

* Minor
gupnik added 2 commits May 19, 2025 22:03
* Adds derivation for various curves

* Adds FFI integration

* Adds ability to provide hashers in FFI

* Trigger Build

* FMT

* Fix clippy

* Fixes ffi issues

* FMT

* Minor fix

* Minor

* Fixes sonar cube issues

* More sonarqube fixes

* Fix memory leaks

* Fixes another memory leak

* Minor

* Minor

* Addresses review comments and adds tests

* FMT

* Makes clippy happy

* Addresses review comments

* Minor

* Uses zeroize for tweak

* Addresses review comment

* Clippy fix
* Adds derivation for various curves

* Adds FFI integration

* Adds ability to provide hashers in FFI

* Trigger Build

* FMT

* Fix clippy

* Fixes ffi issues

* FMT

* Minor fix

* Minor

* Fixes sonar cube issues

* More sonarqube fixes

* Fix memory leaks

* Fixes another memory leak

* Minor

* Minor

* Addresses review comments and adds tests

* FMT

* Makes clippy happy

* Initial setup

* Remove from scripts

* Removes trezor crypto

* Minor

* Minor

* Fixes test

* Fixes

* Fixes

* Minor

* Fix sonarqube issue

* Fix sonarqube issues

* Address review comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants