-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e776f73
commit ce9100a
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
core/src/main/java/org/bitcorej/chain/umi/UMIStateProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
examples/src/main/java/org/bitcorej/examples/ExampleUMIWallet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
package org.bitcorej.examples;public class ExampleUMIWallet { | ||
} |