Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion com/raugfer/crypto/coins.java
Original file line number Diff line number Diff line change
Expand Up @@ -579,14 +579,46 @@ public class coins {
attrs.put("transaction.version", 0x80000004);
attrs.put("transaction.groupid", 0x892f2085);
attrs.put("signature.hashing", "blake2b256");
attrs.put("signature.hashing.prefix", bytes.concat("ZcashSigHash".getBytes(), new byte[]{ (byte)0xbb, (byte)0x09, (byte)0xb8, (byte)0x76 }));
attrs.put("signature.hashing.prefix", bytes.concat("ZcashSigHash".getBytes(), new byte[]{ (byte)0x60, (byte)0x0e, (byte)0xb4, (byte)0x2b }));
attrs.put("sighash.method", "sapling");
attrs.put("confirmations", 20);
attrs.put("block.time", 5 * 30);
attrs.put("decimals", 8);
coins.put("zcash", attrs);
}

static {
dict attrs = new dict();
attrs.put("overloads", "neo");
attrs.put("transaction.format", "ontologytx");
attrs.put("signature.hashing", "sha256hash256");
attrs.put("confirmations", 10);
attrs.put("block.time", 15);
attrs.put("decimals", 0);
attrs.put("transfer.gaslimit", 20000);
attrs.put("transfer.gasprice", 500);
attrs.put("contract.address", new byte[]{
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01
});
coins.put("ontology", attrs);
}

static {
dict attrs = new dict();
attrs.put("overloads", "ontology");
attrs.put("decimals", 9);
attrs.put("contract.address", new byte[]{
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02
});
coins.put("ontologygas", attrs);
}

static {
dict attrs = new dict();
attrs.put("overloads", "ethereum");
Expand Down
2 changes: 1 addition & 1 deletion com/raugfer/crypto/nist256p1.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public static BigInteger[] rec(BigInteger h, Object[] S) {
boolean odd = (boolean) S[2];
if (!rng(r)) throw new IllegalArgumentException("Out of range");
if (!rng(s)) throw new IllegalArgumentException("Out of range");
if (s.compareTo(n.shiftRight(2)) > 0) throw new IllegalArgumentException("Out of range");
if (s.compareTo(n.shiftRight(1)) > 0) throw new IllegalArgumentException("Out of range");
BigInteger[] R = { r, fnd(r, odd) };
BigInteger z = h.negate().mod(n);
BigInteger invr = r.modPow(n.subtract(BigInteger.valueOf(2)), n);
Expand Down
2 changes: 1 addition & 1 deletion com/raugfer/crypto/secp256k1.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public static BigInteger[] rec(BigInteger h, Object[] S) {
boolean odd = (boolean) S[2];
if (!rng(r)) throw new IllegalArgumentException("Out of range");
if (!rng(s)) throw new IllegalArgumentException("Out of range");
if (s.compareTo(n.shiftRight(2)) > 0) throw new IllegalArgumentException("Out of range");
if (s.compareTo(n.shiftRight(1)) > 0) throw new IllegalArgumentException("Out of range");
BigInteger[] R = { r, fnd(r, odd) };
BigInteger z = h.negate().mod(n);
BigInteger invr = r.modPow(n.subtract(BigInteger.valueOf(2)), n);
Expand Down
27 changes: 27 additions & 0 deletions com/raugfer/crypto/service.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

public class service {

Expand Down Expand Up @@ -113,6 +114,11 @@ public static BigInteger estimate_fee(Object _source_addresses, BigInteger amoun
if (fmt.equals("protobuf")) {
return BigInteger.ZERO;
}
if (fmt.equals("ontologytx")) {
BigInteger gaslimit = BigInteger.valueOf(coins.attr("transfer.gaslimit", 0, coin, testnet));
BigInteger gasprice = BigInteger.valueOf(coins.attr("transfer.gasprice", 0, coin, testnet));
return gaslimit.multiply(gasprice);
}
throw new IllegalArgumentException("Unknown format");
}

Expand Down Expand Up @@ -536,6 +542,27 @@ public static pair<byte[][], context> create_rawtxn(Object _source_addresses, St
byte[] txn = transaction.transaction_encode(fields, coin, testnet);
return new pair<>(new byte[][]{ txn }, f);
}
if (fmt.equals("ontologytx")) {
String source_address = source_addresses[0];
context f = (lookup) -> lookup.call(source_address);
int gas = coins.attr("transfer.gaslimit", coin, testnet);
BigInteger gaslimit = BigInteger.valueOf(gas);
BigInteger gasprice = fee.divide(gaslimit);
BigInteger nonce = BigInteger.valueOf(BigInteger.valueOf(new Random().nextInt()).intValue()).abs();
byte[] contract = coins.attr("contract.address", new byte[]{}, coin, testnet);
dict fields = new dict();
fields.put("nonce", nonce);
fields.put("gasprice", gasprice);
fields.put("gaslimit", gaslimit);
fields.put("payer", source_addresses.length > 1? source_addresses[1] : source_addresses[0]);
fields.put("from", source_addresses[0]);
fields.put("to", address);
fields.put("amount", amount);
fields.put("contract", contract);
byte[] txn = transaction.transaction_encode(fields, coin, testnet);
return new pair<>(new byte[][]{txn}, f);

}
throw new IllegalArgumentException("Unknown format");
}

Expand Down
1 change: 1 addition & 0 deletions com/raugfer/crypto/signing.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public static byte[] signature_create(String privatekey, byte[] data, BigInteger
case "sha512h": b = hashing.sha512h(bytes.concat(prefix, data)); break;
case "blake1s": b = hashing.blake1s(bytes.concat(prefix, data)); break;
case "blake2b256": b = hashing.blake2b(data, prefix, 32); break;
case "sha256hash256": b = hashing.sha256(hashing.hash256(bytes.concat(prefix, data))); break;
default: throw new IllegalStateException("Unknown hash function");
}
byte[] envelop_prefix = coins.attr("signature.hashing.envelop.prefix", new byte[]{ }, coin, testnet);
Expand Down
Loading