diff --git a/core/src/main/java/org/bitcorej/chain/ChainStateProxy.java b/core/src/main/java/org/bitcorej/chain/ChainStateProxy.java index ccc4ed9..2bbbac7 100644 --- a/core/src/main/java/org/bitcorej/chain/ChainStateProxy.java +++ b/core/src/main/java/org/bitcorej/chain/ChainStateProxy.java @@ -59,6 +59,7 @@ import org.bitcorej.chain.stellar.StellarStateProvider; import org.bitcorej.chain.stg.STGStateProvider; import org.bitcorej.chain.trx.TRXStateProvider; +import org.bitcorej.chain.umi.UMIStateProvider; import org.bitcorej.chain.usdt.USDTStateProvider; import org.bitcorej.chain.vet.VETStateProvider; import org.bitcorej.chain.vrsc.VRSCStateProvider; @@ -244,6 +245,9 @@ public class ChainStateProxy implements ChainState, UTXOState, USDTState, XMRSta SPRKStateProvider sprk = new SPRKStateProvider(Network.MAIN); services.put("SPRK", sprk); services.put("SPRK_MAIN", sprk); + UMIStateProvider umi = new UMIStateProvider(); + services.put("UMI", umi); + services.put("UMI_MAIN", umi); } private ChainState provider; diff --git a/core/src/main/java/org/bitcorej/chain/umi/UMIStateProvider.java b/core/src/main/java/org/bitcorej/chain/umi/UMIStateProvider.java new file mode 100644 index 0000000..1359723 --- /dev/null +++ b/core/src/main/java/org/bitcorej/chain/umi/UMIStateProvider.java @@ -0,0 +1,49 @@ +package org.bitcorej.chain.umi; + +import iost.crypto.Ed25519; +import iost.model.transaction.Signature; +import org.bitcorej.chain.ChainState; +import org.bitcorej.chain.KeyPair; +import org.bitcorej.chain.Transaction; +import org.bitcorej.crypto.Bech32; +import org.bitcorej.utils.NumericUtil; +import org.json.JSONObject; + +import java.util.List; + +public class UMIStateProvider implements ChainState { + @Override + public KeyPair generateKeyPair(String secret) { + Ed25519 keyPair = new Ed25519(NumericUtil.hexToBytes(secret)); + return new KeyPair(NumericUtil.bytesToHex(keyPair.seckey()), Bech32.encode("umi", Bech32.toWords(keyPair.pubkey()))); + } + + @Override + public KeyPair generateKeyPair() { + return this.generateKeyPair(NumericUtil.bytesToHex(new Ed25519().seckey())); + } + + @Override + public Boolean validateTx(String rawTx, String requestTx) { + return null; + } + + @Override + public Transaction decodeRawTransaction(String rawTx) { + return null; + } + + @Override + public String signRawTransaction(String rawTx, List keys) { + JSONObject json = new JSONObject(rawTx); + String raw = json.getString("serialized"); + String signData = json.getString("signatureHash"); + Ed25519 keyPair = new Ed25519(NumericUtil.hexToBytes(keys.get(0))); + Signature sig = keyPair.sign(NumericUtil.hexToBytes(signData)); + String signature = NumericUtil.bytesToHex(sig.signature); + JSONObject packedTx = new JSONObject(); + packedTx.put("serialized", raw); + packedTx.put("signature", signature); + return packedTx.toString(); + } +} diff --git a/examples/src/main/java/org/bitcorej/examples/ExampleUMIWallet.java b/examples/src/main/java/org/bitcorej/examples/ExampleUMIWallet.java new file mode 100644 index 0000000..3bdfc12 --- /dev/null +++ b/examples/src/main/java/org/bitcorej/examples/ExampleUMIWallet.java @@ -0,0 +1,2 @@ +package org.bitcorej.examples;public class ExampleUMIWallet { +}