diff --git a/src/main/java/fr/miage/Wallet.java b/src/main/java/fr/miage/Wallet.java index 49d390cdfc7df0d7eeec4c79b345fb945c6fe159..53bdc4bf4330f564fc7d2f7647c1acbfcb961771 100644 --- a/src/main/java/fr/miage/Wallet.java +++ b/src/main/java/fr/miage/Wallet.java @@ -9,21 +9,33 @@ public class Wallet { private String publicKey; private String privateKey; // pour la signature + private double solde; private List<UTxO> utxos; - public Wallet(String publicKey, String privateKey) { - this.publicKey = publicKey; - this.privateKey = privateKey; + public Wallet(String privateKey) throws NoSuchAlgorithmException { + this.init(privateKey); } - public void initWallet(byte[] data) throws NoSuchAlgorithmException{ - - } - private String hashSha256(String privateKey) throws NoSuchAlgorithmException{ + private void init(String privateKey) throws NoSuchAlgorithmException{ MessageDigest md = MessageDigest.getInstance("SHA-256"); byte[] hash = md.digest(privateKey.getBytes(StandardCharsets.UTF_8)); + StringBuilder hashedByte = new StringBuilder(); + for(byte b : hash){ + hashedByte.append(String.format("%02x", b)); + } + this.publicKey = hashedByte.toString(); + this.privateKey = privateKey; + this.solde = 20; + this.utxos.add(new UTxO(this, null, solde)) + } + + public String getPrivateKey() { + return privateKey; + } + public String getPublicKey() { + return publicKey; } }