Skip to content

Commit

Permalink
sup umi
Browse files Browse the repository at this point in the history
  • Loading branch information
pengpengliu committed Nov 4, 2021
1 parent e776f73 commit ce9100a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/src/main/java/org/bitcorej/chain/ChainStateProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
49 changes: 49 additions & 0 deletions core/src/main/java/org/bitcorej/chain/umi/UMIStateProvider.java
Original file line number Diff line number Diff line change
@@ -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<String> 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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package org.bitcorej.examples;public class ExampleUMIWallet {
}

0 comments on commit ce9100a

Please sign in to comment.