From 1247428f3467d7c687fe6952b67717e56c9a7d00 Mon Sep 17 00:00:00 2001 From: corentinstd <corentinstd@gmail.com> Date: Tue, 30 Jan 2024 16:57:19 +0100 Subject: [PATCH] modif wallet --- src/main/java/fr/miage/Wallet.java | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/main/java/fr/miage/Wallet.java b/src/main/java/fr/miage/Wallet.java index 49d390c..53bdc4b 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; } } -- GitLab