Skip to content
Snippets Groups Projects
Select Git revision
  • 4cb43dc9483e32c6e0fc7f50f1cd61244c0f99ba
  • main default protected
  • feat-refacto
  • feat-transaction
  • feat/coinbase
5 results

Wallet.java

Blame
  • Wallet.java 1.41 KiB
    package fr.miage;
    
    import java.nio.charset.StandardCharsets;
    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;
    import java.util.ArrayList;
    import java.util.List;
    
    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;
            this.utxos = new ArrayList<>();
        }
    
        public void initWallet(byte[] data) throws NoSuchAlgorithmException {
    
        }
    
        private String hashSha256(String privateKey) throws NoSuchAlgorithmException {
            MessageDigest md = MessageDigest.getInstance("SHA-256");
            byte[] hash = md.digest(privateKey.getBytes(StandardCharsets.UTF_8));
            return new String(hash, StandardCharsets.UTF_8);
        }
    
        public String getPublicKey() {
            return this.publicKey;
        }
    
        public String getPrivateKey() {
            return this.privateKey;
        }
    
        public List<UTxO> getUtxos() {
            return this.utxos;
        }
    
        public void addUTxO(UTxO utxo) {
            this.utxos.add(utxo);
        }
        
        @Override
        public String toString() {
            return "{" +
                " publicKey='" + getPublicKey() + "'" +
                ", privateKey='" + getPrivateKey() + "'" +
                ", utxos='" + getUtxos() + "'" +
                "}";
        }
    }