-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/go wrapper litecoin #4
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
Conversation
make basic structure for go-wrapper
Feat/go wrapper cardano
Feat/update go module
WalkthroughThis update introduces a comprehensive Go wrapper for the TrustWalletCore library, adding Go bindings for various wallet, coin, key, and transaction operations. It also adds numerous generated C header files for protocol buffer types, new C interfaces for blockchain-specific utilities, Go sample programs, build scripts, and documentation for Go integration and usage. Changes
Sequence Diagram(s)sequenceDiagram
participant GoApp as Go Application
participant GoWrapper as Go Wrapper (cgo)
participant TrustWalletCore as TrustWalletCore C Library
participant Proto as Protobuf Types
GoApp->>GoWrapper: CreateWalletWithMnemonic(mnemonic, coinType)
GoWrapper->>TrustWalletCore: TWMnemonicIsValid(mnemonic)
TrustWalletCore-->>GoWrapper: bool
GoWrapper->>TrustWalletCore: TWHDWalletCreateWithMnemonic(mnemonic, passphrase)
TrustWalletCore-->>GoWrapper: walletPtr
GoWrapper->>TrustWalletCore: TWHDWalletGetKey(walletPtr, coinType)
TrustWalletCore-->>GoWrapper: privateKeyPtr
GoWrapper->>TrustWalletCore: TWPrivateKeyGetPublicKey(privateKeyPtr, curve)
TrustWalletCore-->>GoWrapper: publicKeyPtr
GoWrapper->>TrustWalletCore: TWHDWalletGetAddressForCoin(walletPtr, coinType)
TrustWalletCore-->>GoWrapper: address
GoWrapper-->>GoApp: Wallet struct
GoApp->>GoWrapper: CreateSignedTx(inputProto, coinType, outputProto)
GoWrapper->>Proto: Marshal(inputProto)
GoWrapper->>TrustWalletCore: TWAnySignerSign(inputBytes, coinType)
TrustWalletCore-->>GoWrapper: signedBytes
GoWrapper->>Proto: Unmarshal(signedBytes, outputProto)
GoWrapper-->>GoApp: Signed transaction
Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 18
🔭 Outside diff range comments (1)
samples/cpp/sample.cpp (1)
53-111
: 🛠️ Refactor suggestion
⚠️ Potential issueInconsistent coin type – sample will malfunction
coinType
is switched to Bitcoin, but the derivation path (m/44'/60'…
), receiver address, andTWAnySignerSignJSON(..., TWCoinTypeEthereum)
remain Ethereum-specific.
Running this sample now produces a Bitcoin address but signs an Ethereum transaction, which is invalid.- const TWCoinType coinType = TWCoinType::TWCoinTypeBitcoin; // TWCoinTypeBitcoin, TWCoinTypeEthereum + const TWCoinType coinType = TWCoinType::TWCoinTypeBitcoin; @@ - auto customDerivationPath = TWStringCreateWithUTF8Bytes("m/44'/60'/1'/0/0"); + auto customDerivationPath = TWStringCreateWithUTF8Bytes("m/44'/0'/1'/0/0"); // BIP-44 for BTC @@ - const string dummyReceiverAddress = "0xC37054b3b48C3317082E7ba872d7753D13da4986"; + const string dummyReceiverAddress = "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh"; // any testnet/mainnet BTC addr @@ - auto result = TWAnySignerSignJSON(json, secretPrivKey, TWCoinTypeEthereum); + auto result = TWAnySignerSignJSON(json, secretPrivKey, coinType);Alternatively, revert
coinType
toTWCoinTypeEthereum
and keep the rest untouched—just make the sample self-consistent.
🧹 Nitpick comments (24)
main.go (1)
1-9
: Keep example binaries out of module rootPlacing a
main
package at repo root meansgo install ./...
builds two binaries (./
andwrapper/go-wrapper
).
Move this demo tosamples/go/
(or add a//go:build demo
tag) to avoid polluting the default build.-mv main.go samples/go/demo.go +//go:build demo + package main ....gitignore (1)
83-84
: Clarify.gitignore
entry formain
Ignoringmain
will exclude any file named “main” anywhere in the repo. If the intent is only to ignore the built executable, consider specifying a path or extension (e.g.,/*.main
ormain.exe
).wrapper/go-wrapper/core/mnemonic.go (1)
3-6
: Hard-coded include/library paths hurt portability
The#cgo
directives embed absolute-ish paths (../../../libs/linux-amd64
). This will break when cross-compiling or when the repository is checked out in a different layout. Prefer using build tags or environment variables (e.g.CGO_LDFLAGS
passed from the build system) so the wrapper can be reused on macOS/Windows and for multiple CPU architectures.wrapper/go-wrapper/core/curve.go (1)
1-15
: Add missing license header.To align with the repository’s source file conventions, please add the SPDX license identifier and copyright header above the
package core
declaration:+// SPDX-License-Identifier: Apache-2.0 +// Copyright © 2017 Trust Walletinclude/TrustWalletCore/TWWalletConnectRequest.h (2)
13-15
: Remove or utilize the unused struct declaration.
The forward declaration ofstruct TWWalletConnectRequest
is not referenced here—either remove it or provide a full definition if it’s part of the public API.
16-20
: Clarify the documentation block.
The summary line mentions returning aSigningInput
, but the method takes aParseRequestInput
and returns aParseRequestOutput
. Please align the docstring with the actual types.include/TrustWalletCore/TWEthereumChainID.h (1)
16-73
: Consider documenting enum-value duplicates & generation source.A few numeric IDs (e.g., 60 = GoChain vs. 1 = Ethereum) already exist in
TWCoinType
; the overlap is harmless but could confuse maintainers scanning the header. A brief comment such as “Values may duplicate CoinType; list is purely convenience” right above the enum would reduce ambiguity when this file is viewed out of context.
No functional issues detected.include/TrustWalletCore/TWTONMessageSigner.h (1)
11-24
: Clarify memory-management contract in the comment.The docstring correctly states that the caller must delete the returned
TWString*
, but it doesn’t name the helper (TWStringDelete
). Adding it avoids guesswork and ensures bindings do the right thing.-/// \returns the signature, Hex-encoded. On invalid input null is returned. Returned object needs to be deleted after use. +/// \returns the signature, Hex-encoded. On invalid input null is returned. +/// Use `TWStringDelete` to free the returned object.wrapper/go-wrapper/core/wallet.go (1)
16-21
: Naming nit – usePrivKey
orPrivateKey
PriKey
is non-idiomatic Go and easy to mis-read.
Consider renaming for clarity:- PriKey string + PrivKey stringwrapper/go-wrapper/compile.sh (2)
1-4
: Add robust shell options.
Recommend enabling strict error handling and making the script safer:#!/bin/bash +set -euo pipefail
9-13
: Resolve PROTO_PATH relative to script location.
Hardcoding a relative path can break if the script is invoked from another directory. Use the script’s directory:-PROTO_PATH=../../src/proto +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" +PROTO_PATH="$SCRIPT_DIR/../../src/proto"wrapper/go-wrapper/README.md (3)
65-66
: Clarify build instruction phrasing.
Use a gerund and include the definite article for clarity:-2. Compile it by `go build -o main`. Relevant source file is `main.go`. +2. Compile it by running the `go build -o main` command. The relevant source file is `main.go`.🧰 Tools
🪛 LanguageTool
[uncategorized] ~65-~65: A determiner appears to be missing. Consider inserting it.
Context: ... 2. Compile it bygo build -o main
. Relevant source file ismain.go
. 3. Run `./ma...(AI_EN_LECTOR_MISSING_DETERMINER)
74-74
: Simplify phrasing by removing redundancy.
Replace “outside of” with “outside”:-* You might want to copy and run `main` outside of the docker container, make sure you have... +* You might want to copy and run `main` outside the Docker container; make sure you have...🧰 Tools
🪛 LanguageTool
[style] ~74-~74: This phrase is redundant. Consider using “outside”.
Context: ...* You might want to copy and runmain
outside of the docker container, make sure you hav...(OUTSIDE_OF)
76-76
: Fix noun usage and punctuation.
Add the missing article and comma, and split into two clear sentences:-* 5. *(optional)* If you want to make transaction on other networks you need to compile `src/proto` proto files and to do that, just run the `./compile.sh` . you can also modify it based on your project. +* 5. *(optional)* If you want to make a transaction on other networks, you need to compile the `src/proto` files. To do that, run `./compile.sh`. You can also modify the script to fit your project.🧰 Tools
🪛 LanguageTool
[uncategorized] ~76-~76: The grammatical number of this noun doesn’t look right. Consider replacing it.
Context: ...u. 5. (optional) If you want to make transaction on other networks you need to compile `...(AI_EN_LECTOR_REPLACEMENT_NOUN_NUMBER)
[uncategorized] ~76-~76: A comma might be missing here.
Context: ...f you want to make transaction on other networks you need to compilesrc/proto
proto f...(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)
[style] ~76-~76: Consider a more expressive alternative.
Context: ... compilesrc/proto
proto files and to do that, just run the./compile.sh
. you...(DO_ACHIEVE)
include/TrustWalletCore/TWTONWallet.h (1)
16-21
: Fix mismatched Doxygen parameter names
The\param
tags usepublic_key
andwallet_id
, but the function signature usespublicKey
andwalletId
. Update the doc comments to match the parameter names.Apply this diff within the selected ranges:
--- a/include/TrustWalletCore/TWTONWallet.h +++ b/include/TrustWalletCore/TWTONWallet.h @@ -18,7 +18,7 @@ -/// \param public_key wallet's public key. +/// \param publicKey wallet's public key. /// \param workchain TON workchain to which the wallet belongs. Usually, base chain is used (0). -/// \param wallet_id wallet's ID allows to create multiple wallets for the same private key. +/// \param walletId wallet's ID allows to create multiple wallets for the same private key. @@ -25,7 +25,7 @@ -/// \param public_key wallet's public key. +/// \param publicKey wallet's public key. /// \param workchain TON workchain to which the wallet belongs. Usually, base chain is used (0). -/// \param wallet_id wallet's ID allows to create multiple wallets for the same private key. +/// \param walletId wallet's ID allows to create multiple wallets for the same private key.Also applies to: 24-28
include/TrustWalletCore/TWHRP.h (1)
18-104
: Inconsistent naming between enum and constant for MultiversX
The enum entryTWHRPMultiversX
corresponds to the static constantHRP_ELROND
. To avoid confusion after the chain’s rename, consider renamingHRP_ELROND
toHRP_MULTIVERSX
.wrapper/go-wrapper/main.go (1)
110-118
:ByteFee: 1
implies 1 sat/B — extremely lowMain-net mempools usually reject < 2–5 sat/B today; consider making the byte-fee configurable or documenting that this is a test-net/demo constant.
include/TrustWalletCore/TWTONAddressConverter.h (1)
10-39
: Public C interface is clear; add ownership note?Functions return
TWString*
; for consistency with other TW APIs consider adding a brief note that the caller owns the returned pointer and must callTWStringDelete
. Not critical but improves usability.include/TrustWalletCore/TWCryptoBoxPublicKey.h (1)
21-37
: Doxygen comment mismatches API namesThe note and parameter names in the comments do not correspond to the exported function identifiers, which is confusing for users of the C interface.
-/// \note Should be deleted with \tw_crypto_box_public_key_delete. +/// \note Should be deleted with \ref TWCryptoBoxPublicKeyDelete. ... -/// \param public_key *non-null* pointer to a public key. +/// \param publicKey *non-null* pointer to a public key. ... -/// \param public_key *non-null* pointer to public key. +/// \param publicKey *non-null* pointer to a public key.Updating the Doxygen comments keeps the generated documentation accurate and prevents broken cross-references.
wrapper/go-wrapper/core/privateKey.go (1)
31-33
: Missing lifecycle helper for thesign
result
PrivateKeySign
returns a rawTWData*
. Go callers must remember toC.TWDataDelete
it, otherwise they leak. Provide a thin helper (e.g.TWDataToBytesAndFree
) or document the requirement in a comment.include/TrustWalletCore/TWMessageSigner.h (1)
30-34
: Docstring copy-paste error – “sign” vs “verify”
The parameter description still says “to sign the message for”, but this method verifies a signature.include/TrustWalletCore/TWCryptoBoxSecretKey.h (1)
22-33
: Docstring references nonexistenttw_crypto_box_secret_key_delete
function
Both notes should referenceTWCryptoBoxSecretKeyDelete
, otherwise generated docs will mislead users.wrapper/go-wrapper/core/publicKey.go (1)
3-6
: Hard-coded linux-amd64 linker flags limit portabilityThe
#cgo LDFLAGS
path is pinned tolibs/linux-amd64
. This breaks builds on Darwin/ARM and Windows. Consider platform-conditional build tags or environment-driven paths.include/TrustWalletCore/TWSolanaTransaction.h (1)
44-58
: Doxygen\param
tag typos (\price
,\limit
)The comment blocks for
TWSolanaTransactionSetComputeUnitPrice
andTWSolanaTransactionSetComputeUnitLimit
use\price
/\limit
instead of the standard\param
tag, so parameter documentation may be dropped by Doxygen.-/// \price Unit Price as a decimal string. +/// \param price Unit Price as a decimal string. ... -/// \limit Unit Limit as a decimal string. +/// \param limit Unit Limit as a decimal string.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (57)
go.sum
is excluded by!**/*.sum
src/Generated/CryptoBoxPublicKey.h
is excluded by!**/generated/**
src/Generated/CryptoBoxSecretKey.h
is excluded by!**/generated/**
wrapper/go-wrapper/protos/aeternity/Aeternity.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/aion/Aion.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/algorand/Algorand.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/aptos/Aptos.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/babylonstaking/BabylonStaking.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/barz/Barz.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/binance/Binance.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/bitcoin/Bitcoin.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/bitcoinv2/BitcoinV2.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/cardano/Cardano.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/common/Common.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/cosmos/Cosmos.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/decred/Decred.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/decredv2/DecredV2.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/eos/EOS.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/ethereum/Ethereum.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/ethereumabi/EthereumAbi.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/ethereumrlp/EthereumRlp.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/everscale/Everscale.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/filecoin/Filecoin.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/fio/FIO.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/greenfield/Greenfield.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/harmony/Harmony.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/hedera/Hedera.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/icon/Icon.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/internetcomputer/InternetComputer.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/iost/IOST.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/iotex/IoTeX.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/multiversx/MultiversX.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/nano/Nano.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/near/NEAR.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/nebulas/Nebulas.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/neo/NEO.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/nervos/Nervos.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/nimiq/Nimiq.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/nuls/NULS.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/oasis/Oasis.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/ontology/Ontology.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/pactus/Pactus.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/polkadot/Polkadot.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/ripple/Ripple.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/solana/Solana.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/stellar/Stellar.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/sui/Sui.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/tezos/Tezos.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/theopennetwork/TheOpenNetwork.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/theta/Theta.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/transactioncompiler/TransactionCompiler.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/tron/Tron.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/utxo/Utxo.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/vechain/VeChain.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/waves/Waves.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/zcash/Zcash.pb.go
is excluded by!**/*.pb.go
wrapper/go-wrapper/protos/zilliqa/Zilliqa.pb.go
is excluded by!**/*.pb.go
📒 Files selected for processing (85)
.gitignore
(2 hunks)go.mod
(1 hunks)include/TrustWalletCore/TWAeternityProto.h
(1 hunks)include/TrustWalletCore/TWAionProto.h
(1 hunks)include/TrustWalletCore/TWAlgorandProto.h
(1 hunks)include/TrustWalletCore/TWAptosProto.h
(1 hunks)include/TrustWalletCore/TWBabylonStakingProto.h
(1 hunks)include/TrustWalletCore/TWBarzProto.h
(1 hunks)include/TrustWalletCore/TWBinanceProto.h
(1 hunks)include/TrustWalletCore/TWBitcoinProto.h
(1 hunks)include/TrustWalletCore/TWBitcoinV2Proto.h
(1 hunks)include/TrustWalletCore/TWCardanoProto.h
(1 hunks)include/TrustWalletCore/TWCommonProto.h
(1 hunks)include/TrustWalletCore/TWCosmosProto.h
(1 hunks)include/TrustWalletCore/TWCryptoBoxPublicKey.h
(1 hunks)include/TrustWalletCore/TWCryptoBoxSecretKey.h
(1 hunks)include/TrustWalletCore/TWDecredProto.h
(1 hunks)include/TrustWalletCore/TWDecredV2Proto.h
(1 hunks)include/TrustWalletCore/TWEOSProto.h
(1 hunks)include/TrustWalletCore/TWEthereumAbiProto.h
(1 hunks)include/TrustWalletCore/TWEthereumChainID.h
(1 hunks)include/TrustWalletCore/TWEthereumProto.h
(1 hunks)include/TrustWalletCore/TWEthereumRlpProto.h
(1 hunks)include/TrustWalletCore/TWEverscaleProto.h
(1 hunks)include/TrustWalletCore/TWFIOProto.h
(1 hunks)include/TrustWalletCore/TWFilecoinProto.h
(1 hunks)include/TrustWalletCore/TWGreenfieldProto.h
(1 hunks)include/TrustWalletCore/TWHRP.h
(1 hunks)include/TrustWalletCore/TWHarmonyProto.h
(1 hunks)include/TrustWalletCore/TWHederaProto.h
(1 hunks)include/TrustWalletCore/TWIOSTProto.h
(1 hunks)include/TrustWalletCore/TWIconProto.h
(1 hunks)include/TrustWalletCore/TWInternetComputerProto.h
(1 hunks)include/TrustWalletCore/TWIoTeXProto.h
(1 hunks)include/TrustWalletCore/TWLiquidStakingProto.h
(1 hunks)include/TrustWalletCore/TWMessageSigner.h
(1 hunks)include/TrustWalletCore/TWMultiversXProto.h
(1 hunks)include/TrustWalletCore/TWNEARProto.h
(1 hunks)include/TrustWalletCore/TWNEOProto.h
(1 hunks)include/TrustWalletCore/TWNULSProto.h
(1 hunks)include/TrustWalletCore/TWNanoProto.h
(1 hunks)include/TrustWalletCore/TWNebulasProto.h
(1 hunks)include/TrustWalletCore/TWNervosProto.h
(1 hunks)include/TrustWalletCore/TWNimiqProto.h
(1 hunks)include/TrustWalletCore/TWOasisProto.h
(1 hunks)include/TrustWalletCore/TWOntologyProto.h
(1 hunks)include/TrustWalletCore/TWPactusProto.h
(1 hunks)include/TrustWalletCore/TWPolkadotProto.h
(1 hunks)include/TrustWalletCore/TWPolymeshProto.h
(1 hunks)include/TrustWalletCore/TWRippleProto.h
(1 hunks)include/TrustWalletCore/TWSolanaProto.h
(1 hunks)include/TrustWalletCore/TWSolanaTransaction.h
(1 hunks)include/TrustWalletCore/TWStellarProto.h
(1 hunks)include/TrustWalletCore/TWSuiProto.h
(1 hunks)include/TrustWalletCore/TWTHORChainSwapProto.h
(1 hunks)include/TrustWalletCore/TWTONAddressConverter.h
(1 hunks)include/TrustWalletCore/TWTONMessageSigner.h
(1 hunks)include/TrustWalletCore/TWTONWallet.h
(1 hunks)include/TrustWalletCore/TWTezosProto.h
(1 hunks)include/TrustWalletCore/TWTheOpenNetworkProto.h
(1 hunks)include/TrustWalletCore/TWThetaProto.h
(1 hunks)include/TrustWalletCore/TWTransactionCompilerProto.h
(1 hunks)include/TrustWalletCore/TWTronProto.h
(1 hunks)include/TrustWalletCore/TWUtxoProto.h
(1 hunks)include/TrustWalletCore/TWVeChainProto.h
(1 hunks)include/TrustWalletCore/TWWalletConnectProto.h
(1 hunks)include/TrustWalletCore/TWWalletConnectRequest.h
(1 hunks)include/TrustWalletCore/TWWavesProto.h
(1 hunks)include/TrustWalletCore/TWZcashProto.h
(1 hunks)include/TrustWalletCore/TWZilliqaProto.h
(1 hunks)main.go
(1 hunks)samples/cpp/sample.cpp
(1 hunks)wrapper/go-wrapper/README.md
(1 hunks)wrapper/go-wrapper/compile.sh
(1 hunks)wrapper/go-wrapper/core/bitcoin.go
(1 hunks)wrapper/go-wrapper/core/coin.go
(1 hunks)wrapper/go-wrapper/core/curve.go
(1 hunks)wrapper/go-wrapper/core/datavector.go
(1 hunks)wrapper/go-wrapper/core/mnemonic.go
(1 hunks)wrapper/go-wrapper/core/privateKey.go
(1 hunks)wrapper/go-wrapper/core/publicKey.go
(1 hunks)wrapper/go-wrapper/core/transaction.go
(1 hunks)wrapper/go-wrapper/core/transactionHelper.go
(1 hunks)wrapper/go-wrapper/core/wallet.go
(1 hunks)wrapper/go-wrapper/main.go
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (10)
wrapper/go-wrapper/core/mnemonic.go (1)
wrapper/go-wrapper/types/twstring.go (1)
TWStringCreateWithGoString
(18-23)
wrapper/go-wrapper/core/wallet.go (4)
wrapper/go-wrapper/core/coin.go (1)
CoinType
(11-11)wrapper/go-wrapper/core/mnemonic.go (1)
IsMnemonicValid
(10-14)wrapper/go-wrapper/types/twstring.go (2)
TWStringCreateWithGoString
(18-23)TWStringGoString
(13-15)wrapper/go-wrapper/types/twdata.go (1)
TWDataHexString
(29-31)
wrapper/go-wrapper/core/transaction.go (2)
wrapper/go-wrapper/core/coin.go (1)
CoinType
(11-11)wrapper/go-wrapper/types/twdata.go (2)
TWDataCreateWithGoBytes
(21-26)TWDataGoBytes
(14-18)
wrapper/go-wrapper/core/transactionHelper.go (3)
wrapper/go-wrapper/core/coin.go (1)
CoinType
(11-11)wrapper/go-wrapper/types/twdata.go (2)
TWDataCreateWithGoBytes
(21-26)TWDataGoBytes
(14-18)wrapper/go-wrapper/core/datavector.go (1)
TWDataVectorCreateWithGoBytes
(12-19)
wrapper/go-wrapper/core/coin.go (1)
wrapper/go-wrapper/types/twstring.go (1)
TWStringGoString
(13-15)
wrapper/go-wrapper/core/datavector.go (1)
wrapper/go-wrapper/types/twdata.go (2)
TWDataCreateWithGoBytes
(21-26)TWDataGoBytes
(14-18)
wrapper/go-wrapper/main.go (10)
wrapper/go-wrapper/core/mnemonic.go (1)
IsMnemonicValid
(10-14)wrapper/go-wrapper/core/wallet.go (2)
CreateWalletWithMnemonic
(24-56)Wallet
(16-21)wrapper/go-wrapper/core/coin.go (4)
CoinTypeBitcoin
(14-14)CoinTypeEthereum
(16-16)CoinTypeTron
(17-17)CoinType
(11-11)wrapper/go-wrapper/sample/external_signing.go (1)
ExternalSigningDemo
(19-25)wrapper/go-wrapper/sample/cardano.go (1)
TestCardano
(16-104)wrapper/go-wrapper/protos/bitcoin/Bitcoin.pb.go (15)
SigningInput
(538-599)SigningInput
(612-612)SigningInput
(627-629)Transaction
(82-94)Transaction
(107-107)Transaction
(122-124)SigningOutput
(947-964)SigningOutput
(977-977)SigningOutput
(992-994)UnspentTransaction
(356-370)UnspentTransaction
(383-383)UnspentTransaction
(398-400)OutPoint
(219-231)OutPoint
(244-244)OutPoint
(259-261)wrapper/go-wrapper/protos/ethereum/Ethereum.pb.go (6)
Transaction
(203-220)Transaction
(233-233)Transaction
(248-250)Transaction_Transfer
(1333-1341)Transaction_Transfer
(1354-1354)Transaction_Transfer
(1369-1371)wrapper/go-wrapper/core/transaction.go (1)
CreateSignedTx
(15-28)wrapper/go-wrapper/core/bitcoin.go (2)
BitcoinScriptLockScriptForAddress
(25-35)BitcoinSigHashTypeAll
(17-17)wrapper/go-wrapper/protos/common/Common.pb.go (1)
SigningError_OK
(29-29)
wrapper/go-wrapper/core/privateKey.go (4)
wrapper/go-wrapper/types/twdata.go (1)
TWDataCreateWithGoBytes
(21-26)wrapper/go-wrapper/core/curve.go (1)
CurveType
(7-7)wrapper/go-wrapper/core/publicKey.go (1)
TWPublicKey
(18-18)wrapper/go-wrapper/core/coin.go (1)
CoinType
(11-11)
wrapper/go-wrapper/core/bitcoin.go (3)
wrapper/go-wrapper/core/coin.go (1)
CoinType
(11-11)wrapper/go-wrapper/types/twstring.go (1)
TWStringCreateWithGoString
(18-23)wrapper/go-wrapper/types/twdata.go (2)
TWDataGoBytes
(14-18)TWDataCreateWithGoBytes
(21-26)
wrapper/go-wrapper/core/publicKey.go (2)
wrapper/go-wrapper/types/twdata.go (1)
TWDataCreateWithGoBytes
(21-26)wrapper/go-wrapper/types/twstring.go (1)
TWStringGoString
(13-15)
🪛 LanguageTool
wrapper/go-wrapper/README.md
[duplication] ~32-~32: Possible typo: you repeated a word.
Context: ...l cmake* Boost
brew install boost* Xcode * Xcode command line tools:
xcode-select --ins...
(ENGLISH_WORD_REPEAT_RULE)
[uncategorized] ~65-~65: A determiner appears to be missing. Consider inserting it.
Context: ... 2. Compile it by go build -o main
. Relevant source file is main.go
. 3. Run `./ma...
(AI_EN_LECTOR_MISSING_DETERMINER)
[style] ~74-~74: This phrase is redundant. Consider using “outside”.
Context: ...* You might want to copy and run main
outside of the docker container, make sure you hav...
(OUTSIDE_OF)
[uncategorized] ~76-~76: The grammatical number of this noun doesn’t look right. Consider replacing it.
Context: ...u. 5. (optional) If you want to make transaction on other networks you need to compile `...
(AI_EN_LECTOR_REPLACEMENT_NOUN_NUMBER)
[uncategorized] ~76-~76: A comma might be missing here.
Context: ...f you want to make transaction on other networks you need to compile src/proto
proto f...
(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)
[style] ~76-~76: Consider a more expressive alternative.
Context: ... compile src/proto
proto files and to do that, just run the ./compile.sh
. you...
(DO_ACHIEVE)
🪛 golangci-lint (1.64.8)
wrapper/go-wrapper/main.go
9-9: could not import github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/core (-: build constraints exclude all Go files in wrapper/go-wrapper/core)
(typecheck)
⏰ Context from checks skipped due to timeout of 90000ms (6)
- GitHub Check: test
- GitHub Check: build
- GitHub Check: build-and-test
- GitHub Check: test-wasm
- GitHub Check: build
- GitHub Check: build
🔇 Additional comments (69)
go.mod (1)
3-5
:✅ Verification successful
Verify Go toolchain & protobuf module versions
go 1.22.5
andgoogle.golang.org/protobuf v1.36.6
do not exist at the time of writing (latest tags are 1.22.4 & 1.34.x respectively). CI will fail as the proxy cannot resolve these versions.
Either downgrade to the latest published patch releases or pin to a tagged commit hash.
🏁 Script executed:
#!/usr/bin/env bash # Check what versions are actually available go list -m -versions google.golang.org/protobufLength of output: 337
🌐 Web query:
Is Go version 1.22.5 released and available for download on golang.org/dl?
💡 Result:
Yes, Go version 1.22.5 was released on July 2, 2024, and is available for download on the official Go website. (groups.google.com) This release includes security fixes for the
net/http
package and various bug fixes across the compiler, cgo, thego
command, the linker, the runtime, and several other packages. (go.dev)You can download the appropriate version for your operating system and architecture from the Go Downloads page. (go.dev)
Citations:
- 1: https://groups.google.com/g/golang-nuts/c/8sDFMuD65FM?utm_source=openai
- 2: https://go.dev/doc/devel/release?utm_source=openai
- 3: https://go.dev/dl/?opt_id=undefined&utm_source=openai
No action needed: version pins are valid
Both Go 1.22.5 and google.golang.org/protobuf v1.36.6 are officially released and resolvable, so CI will succeed as-is.
• File: go.mod (lines 3–4)
include/TrustWalletCore/TWEverscaleProto.h (1)
7-13
: Header looks good – follows existing generated-file patternNothing to flag; consistent with other proto wrappers.
include/TrustWalletCore/TWGreenfieldProto.h (1)
7-15
: Header looks good – follows existing generated-file patternNo issues observed.
.gitignore (2)
38-43
: Confirm inclusion of generated headers
The ignore patterns forsrc/Generated/*.h
andinclude/TrustWalletCore/TW*Proto.h
have been commented out, so these generated protobuf headers will now be tracked in version control. Please verify this is intentional given the size and frequency of changes to generated files.
45-54
: Ensure consistency of commented ignore rules
Similar to the above, several protocol-specific header ignore rules (e.g.,TWTONAddressConverter.h
,TWSolanaTransaction.h
) are now disabled. Confirm that all these generated headers should be versioned and that your CI/build pipeline accommodates their presence.include/TrustWalletCore/TWTransactionCompilerProto.h (1)
1-12
: Generated protobuf typedef – consistent style
The header follows the established pattern (#pragma once, license, includeTWData.h
, typedef). No issues detected.include/TrustWalletCore/TWCommonProto.h (1)
1-10
: Common protobuf header – looks good
This generated file correctly includesTWData.h
and provides a common foundation.include/TrustWalletCore/TWAeternityProto.h (1)
1-13
: Aeternity proto typedefs added
The new typedefs for Aeternity signing input/output are consistent with other protocol headers.include/TrustWalletCore/TWZcashProto.h (1)
1-13
: Zcash proto typedefs added
The Zcash-specific typedefs follow the same generated-file conventions and are implemented correctly.include/TrustWalletCore/TWNimiqProto.h (1)
11-12
: No issues – generated typedefs conform to existing pattern
The typedefs mirror the style used for every other *Proto header in the codebase and introduce no functional risk.include/TrustWalletCore/TWAionProto.h (1)
11-12
: Generated header accepted as-is
Consistent with the rest of the proto wrappers; nothing to flag.include/TrustWalletCore/TWOntologyProto.h (1)
11-12
: Looks good – matches established generated pattern
No additional feedback.include/TrustWalletCore/TWFilecoinProto.h (1)
11-12
: Header is fine
Aligns with other generated proto typedefs.include/TrustWalletCore/TWIconProto.h (1)
1-13
: Approve generated protobuf typedefs.The new typedefs for
TW_Icon_Proto_SigningInput
andTW_Icon_Proto_SigningOutput
correctly wrap protobuf messages as opaqueTWData
pointers, consistent with existing generated headers and project conventions.include/TrustWalletCore/TWNanoProto.h (1)
1-13
: Approve generated protobuf typedefs.The new typedefs for
TW_Nano_Proto_SigningInput
andTW_Nano_Proto_SigningOutput
adhere to the project’s pattern for protobuf message wrappers.include/TrustWalletCore/TWWalletConnectProto.h (1)
1-13
: Approve generated protobuf typedefs.The new typedefs for
TW_WalletConnect_Proto_ParseRequestInput
andTW_WalletConnect_Proto_ParseRequestOutput
match the existing naming and use of opaqueTWData
pointers.include/TrustWalletCore/TWThetaProto.h (1)
1-13
: Approve generated protobuf typedefs.The
TW_Theta_Proto_SigningInput
andTW_Theta_Proto_SigningOutput
typedefs are consistent with the generated header pattern and the project’s protobuf interface design.include/TrustWalletCore/TWNebulasProto.h (1)
1-15
: New generated protobuf header is correct and consistent with existing patterns. No issues found.include/TrustWalletCore/TWTheOpenNetworkProto.h (1)
1-15
: New generated protobuf header is correct and consistent with existing patterns. No issues found.include/TrustWalletCore/TWBarzProto.h (1)
1-14
: New generated protobuf header is correct and consistent with existing patterns. No issues found.include/TrustWalletCore/TWZilliqaProto.h (1)
1-14
: New generated protobuf header is correct and consistent with existing patterns. No issues found.include/TrustWalletCore/TWWalletConnectRequest.h (3)
1-6
: Standard license header and file metadata; no review needed.
7-10
: Includes and macros are correct and complete.
21-21
: Exported static method signature is correct.
TheTWWalletConnectRequestParse
declaration follows established API conventions.include/TrustWalletCore/TWEthereumRlpProto.h (1)
11-14
: Generated typedefs look fine – no action needed.The aliases follow the established pattern (
TWData*
+_Nonnull
) used across Trust Wallet Core for opaque protobuf blobs. No correctness, naming, or portability issues spotted.include/TrustWalletCore/TWVeChainProto.h (1)
11-13
: Consistent with existing proto headers.Nothing to flag; the VeChain typedefs mirror the style of other generated files.
include/TrustWalletCore/TWWavesProto.h (1)
11-15
: No issues – header matches proto pattern.Typedefs are correct and naming aligns with other generated protobuf wrappers.
include/TrustWalletCore/TWEOSProto.h (1)
7-13
: Generated header looks fineOpaque typedefs follow the convention used across the code-base; nothing to flag here.
include/TrustWalletCore/TWFIOProto.h (1)
7-16
: Generated header looks fineSame pattern as the other proto headers – no issues detected.
include/TrustWalletCore/TWInternetComputerProto.h (1)
7-13
: Generated header looks fineTypedefs are consistent with the existing style.
include/TrustWalletCore/TWNULSProto.h (1)
7-16
: Generated header looks fineNo functional logic; typedefs match the established pattern.
wrapper/go-wrapper/core/wallet.go (1)
24-56
: Good memory hygiene & error handlingNice job:
- All C allocations (
TWString
,TWHDWallet
, keys, data) are paired with the correctdefer
frees.- Mnemonic validation occurs up-front.
- Returned struct is fully populated.
Only the boolean cast issue blocks compilation; fix that and the function is solid.
include/TrustWalletCore/TWUtxoProto.h (1)
1-14
: Skip auto-generated protobuf header.
This file is machine-generated (// This is a GENERATED FILE
) and should not be manually edited.include/TrustWalletCore/TWAlgorandProto.h (1)
1-15
: Skip auto-generated protobuf header.
This file is machine-generated (// This is a GENERATED FILE
) and should not be manually edited.include/TrustWalletCore/TWIoTeXProto.h (1)
1-17
: Skip auto-generated protobuf header.
This file is machine-generated (// This is a GENERATED FILE
) and should not be manually edited.include/TrustWalletCore/TWDecredV2Proto.h (1)
1-14
: Skip auto-generated protobuf header.
This file is machine-generated (// This is a GENERATED FILE
) and should not be manually edited.include/TrustWalletCore/TWPolkadotProto.h (1)
1-17
: Skip auto-generated protobuf header.
This file is machine-generated (// This is a GENERATED FILE
) and should not be manually edited.include/TrustWalletCore/TWDecredProto.h (1)
1-14
: Skip review for generated header.
This file is auto-generated; manual inspection isn’t necessary as changes will be overwritten.include/TrustWalletCore/TWLiquidStakingProto.h (1)
1-18
: Skip review for generated header.
This file is auto-generated; manual inspection isn’t necessary as changes will be overwritten.include/TrustWalletCore/TWIOSTProto.h (1)
1-17
: Skip review for generated header.
This file is auto-generated; manual inspection isn’t necessary as changes will be overwritten.include/TrustWalletCore/TWNEOProto.h (1)
1-20
: Generated file – no manual review required.include/TrustWalletCore/TWBabylonStakingProto.h (1)
1-15
: Generated file – no manual review required.include/TrustWalletCore/TWCosmosProto.h (1)
1-20
: Generated file – no manual review required.include/TrustWalletCore/TWPactusProto.h (1)
1-15
: Approve generated Pactus protobuf typedefs
The file follows the established pattern for protobuf headers and will be regenerated automatically.include/TrustWalletCore/TWOasisProto.h (1)
1-15
: Approve generated Oasis protobuf typedefs
Consistent with otherTW*Proto
headers and correctly defines Oasis message types asTWData
pointers.include/TrustWalletCore/TWPolymeshProto.h (1)
1-21
: Approve generated Polymesh protobuf typedefs
Header adheres to the pattern for protobuf message aliasing. Nothing to adjust in this generated file.include/TrustWalletCore/TWAptosProto.h (1)
1-29
: Approve generated Aptos protobuf typedefs
The typedefs cover all Aptos message types and match the project's conventions.include/TrustWalletCore/TWTronProto.h (1)
1-30
: Generated proto typedefs – no issues foundStandard generated header that only introduces opaque
TWData*
aliases. Naming and include-guard usage are consistent with the rest of the project.include/TrustWalletCore/TWHederaProto.h (1)
1-17
: Generated proto typedefs – no issues foundEverything follows the established pattern for generated proto headers.
include/TrustWalletCore/TWTHORChainSwapProto.h (1)
1-16
: Generated proto typedefs – no issues foundHeader matches conventions; nothing to block.
include/TrustWalletCore/TWStellarProto.h (1)
1-24
: Generated proto typedefs – no issues foundConsistent with other generated headers; ready to ship.
include/TrustWalletCore/TWHRP.h (2)
1-7
: Confirmed license header and inclusion guard
The SPDX license declaration and#pragma once
directive are correctly applied for this generated header.
34-54
: Verify duplicate HRP for Terra & TerraV2
BothTWHRPTerra
andTWHRPTerraV2
are mapped to the same string"terra"
. Please confirm this is intentional and thatstringForHRP
/hrpForString
can correctly distinguish between the two variants.include/TrustWalletCore/TWMultiversXProto.h (1)
1-17
: Generated protobuf typedefs look good
The license header, include guard, and type aliases for MultiversX protocol buffers follow the standard pattern and are consistent with other generated headers.include/TrustWalletCore/TWBitcoinProto.h (1)
1-23
: Generated Bitcoin protobuf typedefs are correct
This file adheres to the project’s conventions for generated protocol buffer headers and requires no modifications.include/TrustWalletCore/TWBitcoinV2Proto.h (1)
1-22
: Generated Bitcoin V2 protobuf typedefs are consistent
The licensing, include guard, and type definitions align with other protobuf headers in Trust Wallet Core.include/TrustWalletCore/TWHarmonyProto.h (1)
1-23
: Generated Harmony protobuf typedefs are correct
Harmony-specific type aliases match the established pattern for generated protocol headers. Ready to merge.wrapper/go-wrapper/main.go (1)
63-63
:Decimals()
not part of the publishedCoinType
API?
ew.CoinType.Decimals()
is called here but no such method exists in the providedcore/coin.go
snippet. Unless generated elsewhere this will not compile. Please verify or add the helper.include/TrustWalletCore/TWRippleProto.h (1)
7-23
: Generated header looks consistent with existing patternIncludes license,
#pragma once
, and opaque typedefs. No issues spotted.include/TrustWalletCore/TWNervosProto.h (1)
7-24
: Header follows established generated-code conventionsSame pattern as other *_Proto.h files; nothing to flag.
include/TrustWalletCore/TWBinanceProto.h (1)
7-35
: Generated typedefs look OKLicensing header, include guard, and typedefs align with other blockchain proto headers.
include/TrustWalletCore/TWSuiProto.h (1)
7-25
: Typedef-only header looks fineGenerated file contains only
TWData*
aliases, matches style of the other proto headers. No issues spotted.include/TrustWalletCore/TWSolanaProto.h (1)
7-35
: Typedef-only header looks fineSame generated pattern as the other protobuf headers – nothing to fix here.
include/TrustWalletCore/TWNEARProto.h (1)
7-27
: Typedef-only header looks fineConsistent with the other generated proto headers.
wrapper/go-wrapper/core/bitcoin.go (1)
25-35
: All good – locking script wrapper handles C memory correctly
TWString/TWData are freed withdefer
, andGoBytes
copies the data before deletion.include/TrustWalletCore/TWEthereumAbiProto.h (1)
1-36
: Generated file – nothing to review.include/TrustWalletCore/TWTezosProto.h (1)
11-22
: Generated header looks fine – no manual issues detected
All typedefs follow the established pattern used across the other generated*_Proto.h
headers, and the file compiles as-is.include/TrustWalletCore/TWEthereumProto.h (1)
11-23
: Consistent with other generated protobuf typedef headers
No functional or stylistic problems spotted; the declarations match the naming scheme used in the rest of the code-gen output.include/TrustWalletCore/TWCardanoProto.h (1)
11-24
: Header conforms to the established proto-alias convention
Nothing to flag here – the typedefs are mechanically generated and look correct.
func IsMnemonicValid(mn string) bool { | ||
str := types.TWStringCreateWithGoString(mn) | ||
defer C.TWStringDelete(str) | ||
return bool(C.TWMnemonicIsValid(str)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type mismatch will fail to compile – cast unsafe.Pointer
back to *C.TWString
types.TWStringCreateWithGoString
returns unsafe.Pointer
. Passing it directly to
C.TWStringDelete
and C.TWMnemonicIsValid
(both expect *C.struct_TWString
) leads to:
cannot use str (variable of type unsafe.Pointer) as *C.struct_TWString value in argument to C.TWStringDelete
A minimal fix:
func IsMnemonicValid(mn string) bool {
- str := types.TWStringCreateWithGoString(mn)
- defer C.TWStringDelete(str)
- return bool(C.TWMnemonicIsValid(str))
+ str := types.TWStringCreateWithGoString(mn)
+ twStr := (*C.TWString)(str)
+ defer C.TWStringDelete(twStr)
+ return bool(C.TWMnemonicIsValid(twStr))
}
You may also consider returning *C.TWString
directly from TWStringCreateWithGoString
to avoid unsafe casts in every call site.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
func IsMnemonicValid(mn string) bool { | |
str := types.TWStringCreateWithGoString(mn) | |
defer C.TWStringDelete(str) | |
return bool(C.TWMnemonicIsValid(str)) | |
} | |
func IsMnemonicValid(mn string) bool { | |
str := types.TWStringCreateWithGoString(mn) | |
twStr := (*C.TWString)(str) | |
defer C.TWStringDelete(twStr) | |
return bool(C.TWMnemonicIsValid(twStr)) | |
} |
🤖 Prompt for AI Agents
In wrapper/go-wrapper/core/mnemonic.go around lines 10 to 14, the variable 'str'
is assigned an unsafe.Pointer from types.TWStringCreateWithGoString but is
passed directly to C functions expecting *C.TWString, causing a type mismatch
compilation error. Fix this by casting 'str' from unsafe.Pointer to *C.TWString
before passing it to C.TWStringDelete and C.TWMnemonicIsValid. Alternatively,
modify TWStringCreateWithGoString to return *C.TWString directly to avoid
repeated unsafe casts.
pubKey := C.TWPrivateKeyGetPublicKeySecp256k1(priKey, true) | ||
defer C.TWPublicKeyDelete(pubKey) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix CGO boolean type mismatch
TWPrivateKeyGetPublicKeySecp256k1
expects a C.bool
.
Passing the Go literal true
breaks the build (cannot use true (untyped bool) as _Ctype_bool value in argument
).
- pubKey := C.TWPrivateKeyGetPublicKeySecp256k1(priKey, true)
+ pubKey := C.TWPrivateKeyGetPublicKeySecp256k1(priKey, C.bool(true))
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
pubKey := C.TWPrivateKeyGetPublicKeySecp256k1(priKey, true) | |
defer C.TWPublicKeyDelete(pubKey) | |
- pubKey := C.TWPrivateKeyGetPublicKeySecp256k1(priKey, true) | |
+ pubKey := C.TWPrivateKeyGetPublicKeySecp256k1(priKey, C.bool(true)) | |
defer C.TWPublicKeyDelete(pubKey) |
🤖 Prompt for AI Agents
In wrapper/go-wrapper/core/wallet.go at lines 42-43, the call to
TWPrivateKeyGetPublicKeySecp256k1 passes the Go boolean literal true, causing a
CGO type mismatch error. Replace the literal true with C.bool(true) to match the
expected C.bool type and fix the build error.
../../build/local/bin/protoc -I=$PROTO_PATH --go_out=protos/"$PKG" \ | ||
--go_opt=paths=source_relative \ | ||
--go_opt=M"$FILE_NAME"=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/"$PKG" \ | ||
--go_opt=MCommon.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/common \ | ||
--go_opt=MDecredV2.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/decredv2 \ | ||
--go_opt=MBabylonStaking.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/babylonstaking \ | ||
--go_opt=MBitcoin.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/bitcoin \ | ||
--go_opt=MUtxo.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/utxo \ | ||
--go_opt=MZcash.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/zcash \ | ||
--go_opt=MBitcoinV2.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/bitcoinv2 \ | ||
--go_opt=MEthereum.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/ethereum \ | ||
--go_opt=MBinance.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/binance \ | ||
--go_opt=MCardano.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/cardano \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing --go_opt
mapping for Litecoin.proto.
Without a manual mapping for Litecoin.proto
, protoc
may fail to resolve imports when generating Go bindings. Add:
--go_opt=MCardano.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/cardano \
+ --go_opt=MLitecoin.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/litecoin \
"$PROTO_PATH"/"$FILE_NAME"
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
../../build/local/bin/protoc -I=$PROTO_PATH --go_out=protos/"$PKG" \ | |
--go_opt=paths=source_relative \ | |
--go_opt=M"$FILE_NAME"=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/"$PKG" \ | |
--go_opt=MCommon.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/common \ | |
--go_opt=MDecredV2.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/decredv2 \ | |
--go_opt=MBabylonStaking.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/babylonstaking \ | |
--go_opt=MBitcoin.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/bitcoin \ | |
--go_opt=MUtxo.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/utxo \ | |
--go_opt=MZcash.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/zcash \ | |
--go_opt=MBitcoinV2.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/bitcoinv2 \ | |
--go_opt=MEthereum.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/ethereum \ | |
--go_opt=MBinance.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/binance \ | |
--go_opt=MCardano.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/cardano \ | |
../../build/local/bin/protoc -I=$PROTO_PATH --go_out=protos/"$PKG" \ | |
--go_opt=paths=source_relative \ | |
--go_opt=M"$FILE_NAME"=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/"$PKG" \ | |
--go_opt=MCommon.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/common \ | |
--go_opt=MDecredV2.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/decredv2 \ | |
--go_opt=MBabylonStaking.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/babylonstaking \ | |
--go_opt=MBitcoin.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/bitcoin \ | |
--go_opt=MUtxo.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/utxo \ | |
--go_opt=MZcash.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/zcash \ | |
--go_opt=MBitcoinV2.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/bitcoinv2 \ | |
--go_opt=MEthereum.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/ethereum \ | |
--go_opt=MBinance.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/binance \ | |
--go_opt=MCardano.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/cardano \ | |
--go_opt=MLitecoin.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/litecoin \ | |
"$PROTO_PATH"/"$FILE_NAME" |
🤖 Prompt for AI Agents
In wrapper/go-wrapper/compile.sh between lines 20 and 32, the protoc command is
missing a --go_opt mapping for Litecoin.proto, which can cause import resolution
failures during Go bindings generation. Add a line with
--go_opt=MLitecoin.proto=github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/litecoin
to the protoc command to properly map Litecoin.proto imports.
odata := C.TWAnySignerSign(idata, C.enum_TWCoinType(ct)) | ||
defer C.TWDataDelete(odata) | ||
|
||
err := proto.Unmarshal(types.TWDataGoBytes(odata), outputData) | ||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing nil-pointer check for TWAnySignerSign
result
TWAnySignerSign
returns nullptr
on failure (e.g. unsupported coin type, invalid input).
Dereferencing that pointer in TWDataGoBytes
will seg-fault the Go program.
odata := C.TWAnySignerSign(idata, C.enum_TWCoinType(ct))
- defer C.TWDataDelete(odata)
+ if odata == nil {
+ return errors.New("TWAnySignerSign returned nil")
+ }
+ defer C.TWDataDelete(odata)
Remember to import errors
at the top if you do this change.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
odata := C.TWAnySignerSign(idata, C.enum_TWCoinType(ct)) | |
defer C.TWDataDelete(odata) | |
err := proto.Unmarshal(types.TWDataGoBytes(odata), outputData) | |
if err != nil { | |
odata := C.TWAnySignerSign(idata, C.enum_TWCoinType(ct)) | |
if odata == nil { | |
return errors.New("TWAnySignerSign returned nil") | |
} | |
defer C.TWDataDelete(odata) | |
err := proto.Unmarshal(types.TWDataGoBytes(odata), outputData) | |
if err != nil { | |
// … | |
} |
🤖 Prompt for AI Agents
In wrapper/go-wrapper/core/transaction.go around lines 20 to 24, the result of
TWAnySignerSign is not checked for nil before use, which can cause a
segmentation fault if it returns nullptr. Add a nil-pointer check immediately
after calling TWAnySignerSign; if the result is nil, return an appropriate error
using the errors package. Only proceed to defer TWDataDelete and call
TWDataGoBytes if the pointer is non-nil.
func CreateSignedTx(inputData proto.Message, ct CoinType, outputData proto.Message) error { | ||
ibytes, _ := proto.Marshal(inputData) | ||
idata := types.TWDataCreateWithGoBytes(ibytes) | ||
defer C.TWDataDelete(idata) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marshal error is silently discarded
proto.Marshal
returns an error that is being ignored. If the input message is invalid (or not fully-initialized when proto
safety checks are enabled) the function will proceed with an empty/partial byte slice and the signer will happily produce garbage or panic down the line.
- ibytes, _ := proto.Marshal(inputData)
+ ibytes, err := proto.Marshal(inputData)
+ if err != nil {
+ return err
+ }
🤖 Prompt for AI Agents
In wrapper/go-wrapper/core/transaction.go around lines 15 to 18, the error
returned by proto.Marshal is currently ignored, which can lead to using invalid
or partial data. Modify the code to capture the error from proto.Marshal, check
if it is non-nil, and return it immediately to prevent further processing with
invalid data.
func CompileWithSignatures(c CoinType, txInputData []byte, signatures [][]byte, publicKeyHashes [][]byte) []byte { | ||
input := types.TWDataCreateWithGoBytes(txInputData) | ||
defer C.TWDataDelete(input) | ||
|
||
sigs := TWDataVectorCreateWithGoBytes(signatures) | ||
defer C.TWDataVectorDelete(sigs) | ||
pubkeyhashes := TWDataVectorCreateWithGoBytes(publicKeyHashes) | ||
defer C.TWDataVectorDelete(pubkeyhashes) | ||
|
||
result := C.TWTransactionCompilerCompileWithSignatures(C.enum_TWCoinType(c), input, sigs, pubkeyhashes) | ||
defer C.TWDataDelete(result) | ||
return types.TWDataGoBytes(result) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Same NULL-check & early-return needed for compiled transaction
Mirror the safeguard in CompileWithSignatures
:
result := C.TWTransactionCompilerCompileWithSignatures(C.enum_TWCoinType(c), input, sigs, pubkeyhashes)
-if result == nil {
- return nil
-}
defer C.TWDataDelete(result)
-return types.TWDataGoBytes(result)
+if result == nil {
+ return nil
+}
+return types.TWDataGoBytes(result)
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In wrapper/go-wrapper/core/transactionHelper.go around lines 18 to 30, the
function CompileWithSignatures lacks a NULL-check on the result of the
C.TWTransactionCompilerCompileWithSignatures call. Add a check immediately after
this call to verify if result is NULL, and if so, return nil or an empty byte
slice early to prevent dereferencing a NULL pointer. This mirrors the safeguard
pattern used elsewhere to ensure safe handling of failed compilation results.
// #cgo CFLAGS: -I../../../include | ||
// #cgo LDFLAGS: -L../../../libs/linux-amd64 -lTrustWalletCore -lwallet_core_rs -lprotobuf -lTrezorCrypto -lstdc++ -lm | ||
// #include <TrustWalletCore/TWPrivateKey.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Hard-coded Linux-only linker flags hurt cross-platform builds
-L../../../libs/linux-amd64
and the static list of -l*
libraries compile only on glibc Linux.
Consider conditional #cgo
blocks or using environment variables to select the correct lib directory (e.g. darwin
, windows
) so the Go wrapper builds on multiple platforms.
🤖 Prompt for AI Agents
In wrapper/go-wrapper/core/privateKey.go around lines 3 to 5, the cgo linker
flags are hard-coded for Linux only, which breaks cross-platform builds. Modify
the file to use conditional #cgo directives based on the target OS (e.g., linux,
darwin, windows) to specify the appropriate library paths and linker flags for
each platform. Alternatively, use environment variables to dynamically select
the correct library directory and flags so the Go wrapper can build on multiple
platforms.
func PrivateKeyDelete(key TWPrivateKey) { | ||
C.TWPrivateKeyDelete(nil) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PrivateKeyDelete()
ignores its argument – memory leak & possible double-free
The function always deletes a nil
pointer instead of the key
that the caller passes in, so the underlying TWPrivateKey
is never released.
-func PrivateKeyDelete(key TWPrivateKey) {
- C.TWPrivateKeyDelete(nil)
+func PrivateKeyDelete(key TWPrivateKey) {
+ if key == nil {
+ return
+ }
+ C.TWPrivateKeyDelete(key)
}
🤖 Prompt for AI Agents
In wrapper/go-wrapper/core/privateKey.go at lines 27 to 29, the function
PrivateKeyDelete incorrectly calls C.TWPrivateKeyDelete with nil instead of the
provided key argument. To fix this, modify the function to pass the actual key
pointer to C.TWPrivateKeyDelete, ensuring the correct memory is freed and
preventing memory leaks or double-free errors.
func PublicKeyVerify(key []byte, keyType PublicKeyType, signature []byte, message []byte) bool { | ||
keyData := types.TWDataCreateWithGoBytes(key) | ||
defer C.TWDataDelete(keyData) | ||
publicKey := C.TWPublicKeyCreateWithData(keyData, C.enum_TWPublicKeyType(keyType)) | ||
defer C.TWPublicKeyDelete(publicKey) | ||
sig := types.TWDataCreateWithGoBytes(signature) | ||
defer C.TWDataDelete(sig) | ||
msg := types.TWDataCreateWithGoBytes(message) | ||
defer C.TWDataDelete(msg) | ||
|
||
return bool(C.TWPublicKeyVerify(publicKey, sig, msg)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Nil-return guard for TWPublicKeyCreateWithData
C.TWPublicKeyCreateWithData
can return NULL
on malformed input. Calling TWPublicKeyVerify
on a NULL
pointer is undefined behaviour. Add a check:
publicKey := C.TWPublicKeyCreateWithData(keyData, C.enum_TWPublicKeyType(keyType))
if publicKey == nil {
return false
}
defer C.TWPublicKeyDelete(publicKey)
🤖 Prompt for AI Agents
In wrapper/go-wrapper/core/publicKey.go around lines 27 to 38, the function
calls C.TWPublicKeyCreateWithData which can return NULL for malformed input,
leading to undefined behavior when passed to TWPublicKeyVerify. Add a nil check
immediately after calling TWPublicKeyCreateWithData: if the returned publicKey
is nil, return false before deferring TWPublicKeyDelete. This prevents calling
TWPublicKeyVerify with a null pointer.
func PublicKeyBytes(key TWPublicKey) ([]byte, error) { | ||
pubValue := PublicKeyDescription(key) | ||
if pubValue == nil { | ||
return nil, errors.New("invalid public key") | ||
} | ||
return hex.DecodeString(types.TWStringGoString(pubValue)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Memory leak & potential decode failure in PublicKeyBytes
- The TWString returned by
C.TWPublicKeyDescription
is never freed – leaking every time this helper is called. hex.DecodeString
will error if the description string contains any prefix (e.g."PublicKey("
) or whitespace. Trust Wallet Core currently returns a pure hex string, but guarding against parse failure is safer.
func PublicKeyBytes(key TWPublicKey) ([]byte, error) {
- pubValue := PublicKeyDescription(key)
- if pubValue == nil {
- return nil, errors.New("invalid public key")
- }
- return hex.DecodeString(types.TWStringGoString(pubValue))
+ desc := C.TWPublicKeyDescription(key)
+ if desc == nil {
+ return nil, errors.New("invalid public key")
+ }
+ // Make sure we free the TWString returned by the C layer.
+ defer C.TWStringDelete(desc)
+
+ raw := types.TWStringGoString(unsafe.Pointer(desc))
+ b, err := hex.DecodeString(raw)
+ if err != nil {
+ return nil, fmt.Errorf("cannot decode public key hex: %w", err)
+ }
+ return b, nil
}
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In wrapper/go-wrapper/core/publicKey.go around lines 57 to 63, the TWString
returned by PublicKeyDescription is not freed, causing a memory leak, and
hex.DecodeString may fail if the string contains unexpected characters. To fix
this, ensure you explicitly free the TWString after extracting the Go string,
and add validation or sanitization to the string before decoding to handle any
prefixes or whitespace safely.
Update go-wrapper for Litecoin
Thank you!
Summary by CodeRabbit
New Features
Documentation
Chores