Class Wallet
java.lang.Object
com.codename1.crypto.wallet.Wallet
One wallet across chains, over a Signer. It knows the standard derivation paths, so the
addresses it answers are the ones other wallets restore from the same mnemonic:
- EVM:
m/44'/60'/account'/0/index, as MetaMask and Ledger derive - Bitcoin:
m/purpose'/coin'/account'/change/indexwith purpose 44 (P2PKH), 49 (P2SH-P2WPKH), 84 (P2WPKH) or 86 (P2TR), and the coin type of the network - Solana:
m/44'/501'/account'/0', as Phantom and Solflare derive
String words = Mnemonic.generate(128);
Wallet w = Wallet.fromMnemonic(words, "");
EvmAddress eth = w.getEvmAddress(0, 0);
BitcoinAddress btc = w.getBitcoinAddress(BitcoinNetwork.MAINNET, Wallet.BIP84, 0, 0, 0);
SolanaAddress sol = w.getSolanaAddress(0);
EvmTransaction tx = EvmTransaction.eip1559(1, 0, UInt256.parseUnits("1", 9),
UInt256.parseUnits("30", 9), 21000, eth, UInt256.ZERO, null);
EvmTransaction signed = w.signEvmTransaction(tx, Wallet.evmPath(0, 0));
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DerivationPathbitcoinPath(BitcoinNetwork network, int purpose, int account, int change, int index) m/purpose'/coin'/account'/change/indexfor a network.static DerivationPathevmPath(int account, int index) m/44'/60'/account'/0/index.static WalletfromMnemonic(String mnemonic, String passphrase) A wallet over an in-memorySeedSignerfor a mnemonic.getBitcoinAddress(BitcoinNetwork network, int purpose, int account, int change, int index) The address of the output type a purpose implies, at a path under it.getBitcoinKey(DerivationPath path) The key at a path, forPsbt.sign(int, BitcoinKey); it signs through the signer.getEvmAddress(int account, int index) The EVM address at an account and index.getEvmAddress(DerivationPath path) The EVM address at a path.The signer.getSolanaAddress(int account) The Solana address of an account.The Solana address at a path.byte[]personalSign(byte[] message, DerivationPath path) An EIP-191personal_signsignature,r || s || vwith v 27 or 28.byte[]personalSign(String message, DerivationPath path) An EIP-191 signature of UTF-8 text.signEvmTransaction(EvmTransaction tx, DerivationPath path) Signs a transaction with the key at a path, answering the signed transaction.intSigns every PSBT input whose recorded BIP-32 origin is this wallet's master, answering how many inputs were signed.voidsignSolanaTransaction(SolanaTransaction tx, int account) Adds the signature of an account's key.voidAdds the signature of the key at a path to a transaction it must sign.byte[]signTypedData(TypedData data, DerivationPath path) An EIP-712 signature,r || s || vwith v 27 or 28.static DerivationPathsolanaPath(int account) m/44'/501'/account'/0'.
-
Field Details
-
BIP44
public static final int BIP44BIP-44 legacy P2PKH accounts.- See Also:
-
BIP49
public static final int BIP49BIP-49 P2SH-wrapped SegWit accounts.- See Also:
-
BIP84
public static final int BIP84BIP-84 native SegWit accounts.- See Also:
-
BIP86
public static final int BIP86BIP-86 Taproot accounts.- See Also:
-
-
Constructor Details
-
Wallet
A wallet over a signer.
-
-
Method Details
-
fromMnemonic
A wallet over an in-memorySeedSignerfor a mnemonic. -
getSigner
The signer. -
evmPath
m/44'/60'/account'/0/index. -
getEvmAddress
The EVM address at an account and index. -
getEvmAddress
The EVM address at a path. -
signEvmTransaction
Signs a transaction with the key at a path, answering the signed transaction. -
personalSign
An EIP-191personal_signsignature,r || s || vwith v 27 or 28. -
personalSign
An EIP-191 signature of UTF-8 text. -
signTypedData
An EIP-712 signature,r || s || vwith v 27 or 28. -
bitcoinPath
public static DerivationPath bitcoinPath(BitcoinNetwork network, int purpose, int account, int change, int index) m/purpose'/coin'/account'/change/indexfor a network. -
getBitcoinAddress
public BitcoinAddress getBitcoinAddress(BitcoinNetwork network, int purpose, int account, int change, int index) The address of the output type a purpose implies, at a path under it.
Throws
IllegalArgumentException: for a purpose other than 44, 49, 84 or 86
-
getBitcoinKey
The key at a path, forPsbt.sign(int, BitcoinKey); it signs through the signer. -
signPsbt
Signs every PSBT input whose recorded BIP-32 origin is this wallet's master, answering how many inputs were signed. The PSBT's creator records the origins (Psbt.addBip32Derivation(int, byte[], int, long[]),Psbt.addTapBip32Derivation(int, byte[], int, long[])), as every wallet does. -
solanaPath
m/44'/501'/account'/0'. -
getSolanaAddress
The Solana address of an account. -
getSolanaAddress
The Solana address at a path. -
signSolanaTransaction
Adds the signature of the key at a path to a transaction it must sign. -
signSolanaTransaction
Adds the signature of an account's key.
-