-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
213 provide hd wallet implementation (#363)
* #213 rough sketch of needed functionality as a discussion basis * still work in progress * basic transaction working now. Still need to refactor a lot! But first good step. * #213 added WalletUtxoSupplier and removed getUtxo functionalities from Wallet.java Need to rework signing to get addresses. * #213 added stakekey registrations and address caching to wallet * #213 added Tests, WalletUtxoSupplier interface and DefaultWalletUtxoSupplier.java * #213 implemented signing with wallet. A UTXOSupplier will be passed. Thus removing the unneeded utxosupplier value in Wallet. * Refactor Tx sender wallet handling and clean up AbstractTx. Changed the sender wallet handling to return null instead of throwing an exception in Tx.java to allow flexibility in error management. Also, removed redundant 'amounts' field and its initialization from AbstractTx.java for a cleaner codebase. * Refactor TxBuilderContext and QuickTxBuilder Move the transaction building logic into a dedicated private method in `TxBuilderContext`. Refactor `QuickTxBuilder` to use the new build method and streamline the signing process, eliminating redundant code and improving code readability. * Refactor TxSigner to include TxBuilderContext * Normalize mnemonic phrase whitespaces * Update logging dependency to reload4j in build.gradle * Refactor: Change MnemonicUtil import path * Refactor Wallet signing and UTXO handling * Refactor Wallet class and update related tests Refactor Wallet methods and variables for better naming consistency. Remove unused methods and annotations. Add new test for scanning specific indexes in DefaultWalletUtxoSupplier. Update existing tests to align with the refactored method names and structures. * fix: changes to fix SonarQube errors --------- Co-authored-by: Satya <satran004@gmail.com>
- Loading branch information
Showing
26 changed files
with
1,648 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
crypto/src/main/java/com/bloxbean/cardano/client/crypto/MnemonicUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.bloxbean.cardano.client.crypto; | ||
|
||
import com.bloxbean.cardano.client.crypto.bip39.MnemonicCode; | ||
import com.bloxbean.cardano.client.crypto.bip39.MnemonicException; | ||
import com.bloxbean.cardano.client.crypto.bip39.Words; | ||
import com.bloxbean.cardano.client.exception.AddressRuntimeException; | ||
|
||
import java.util.Arrays; | ||
import java.util.stream.Collectors; | ||
|
||
public class MnemonicUtil { | ||
|
||
private MnemonicUtil() { | ||
|
||
} | ||
|
||
public static void validateMnemonic(String mnemonic) { | ||
if (mnemonic == null) { | ||
throw new AddressRuntimeException("Mnemonic cannot be null"); | ||
} | ||
|
||
mnemonic = mnemonic.replaceAll("\\s+", " "); | ||
String[] words = mnemonic.split("\\s+"); | ||
|
||
try { | ||
MnemonicCode.INSTANCE.check(Arrays.asList(words)); | ||
} catch (MnemonicException e) { | ||
throw new AddressRuntimeException("Invalid mnemonic phrase", e); | ||
} | ||
} | ||
|
||
public static String generateNew(Words noOfWords) { | ||
String mnemonic = null; | ||
try { | ||
mnemonic = MnemonicCode.INSTANCE.createMnemonic(noOfWords).stream().collect(Collectors.joining(" ")); | ||
} catch (MnemonicException.MnemonicLengthException e) { | ||
throw new AddressRuntimeException("Mnemonic generation failed", e); | ||
} | ||
return mnemonic; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
dependencies { | ||
api project(':core') | ||
api project(':hd-wallet') | ||
} | ||
|
||
publishing { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
dependencies { | ||
api project(':core-api') | ||
api project(':core') | ||
api project(':common') | ||
api project(':crypto') | ||
api project(':backend') | ||
implementation(libs.bouncycastle.bcprov) | ||
|
||
integrationTestImplementation(libs.slf4j.reload4j) | ||
integrationTestImplementation(libs.aiken.java.binding) | ||
integrationTestImplementation project(':') | ||
integrationTestImplementation project(':backend-modules:blockfrost') | ||
integrationTestImplementation project(':backend-modules:koios') | ||
integrationTestImplementation project(':backend-modules:ogmios') | ||
integrationTestImplementation project(':backend-modules:ogmios') | ||
|
||
integrationTestAnnotationProcessor project(':annotation-processor') | ||
} | ||
|
||
publishing { | ||
publications { | ||
mavenJava(MavenPublication) { | ||
pom { | ||
name = 'Cardano Client HD Wallet' | ||
description = 'Cardano Client Lib - HD Wallet Integration' | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.