Giter Site home page Giter Site logo

laksaj's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

laksaj's Issues

build instructions / jar

Hello,

can you write some build instructions and generate a jar from the files ?

I'm having a hard time building this because of small thinks like import com.sun.tools.javac.util.Assert;, setting up lombok etc.

Thanks

Specified Private key does't pass the sign / verify unit test

I use the kaya account-fixture.json specified private key, but it doesn't pass the sign / verify unit test.
The hex encode private key is 'db11cfa086b92497c8ed5a4cc6edb3a5bfe3a640c43ffb9fc6aa0873c56f2ee3' ,you can find at here

 String tx;
 ECKey ecKey;

    @Before
    public void set() {
        tx = "080110f4021a14d90f2e538ce0df89c8273cad3b63ec44a3c4ed8222230a2103d8e6450e260f80983bcd4fadb6cbc132ae7feb552dda45f94b48c80b86c6c3be2a120a100000000000000000000000000000037832120a100000000000000000000000003b9aca00380a42004aa4027b225f746167223a226e65774c6f636b222c22706172616d73223a5b7b22766e616d65223a227265636569766572222c2274797065223a2242795374723230222c2276616c7565223a22307831323334353637383930313233343536373839303132333435363738393031323334353637383930227d2c7b22766e616d65223a226856616c7565222c2274797065223a2242795374723332222c2276616c756522202020203a22307863613937383131326361316262646361666163323331623339613233646334646137383665666638313437633465373262393830373738356166656534376262227d2c7b22766e616d65223a226e4c6f636b4e756d222c2274797065223a2255696e74313238222c2276616c7565223a22313030303030227d5d7d";
        //  String privateKey = "0F494B8312E8D257E51730C78F8FE3B47B6840C59AAAEC7C2EBE404A2DE8B25A";
        String privateKey = "db11cfa086b92497c8ed5a4cc6edb3a5bfe3a640c43ffb9fc6aa0873c56f2ee3";

        //ecKey = new ECKey();
        ecKey = ECKey.fromPrivate(HexUtils.fromHexString(privateKey));
    }

    @Test
    public void sign() throws NoSuchAlgorithmException {
        String k = "5dca09e2032c464d9df7d4fce942026245de5f0afc593ece31eaddba2b2bc0e0";
        Schnorr.Signature signature = Schnorr.sign(HexUtils.fromHexString(tx), ecKey.getPrivKeyBytes(), ecKey.getPubKey(), new BigInteger(k, 16));

    }

    @Test
    public void verify() throws NoSuchAlgorithmException {
        String R = "67EB3FED0398B3BF7DA3AEDF8F58B7DFD7B8C1508D24631D40B03B4368D230A8";
        String S = "41F7EED0F9508F4315D77A57EB238FB7615A37613D2F38B638BC9DFF65FE6FA0";
        List<Integer> messageList = new ArrayList<>();
        for (byte m : HexUtils.fromHexString(tx)) {
            messageList.add((int) m);
        }
        boolean result = Schnorr.verify(messageList, new Schnorr.Signature(new BigInteger(R, 16), new BigInteger(S, 16)), ecKey.getPubKey());
        System.out.println(result);
    }```

Possible issue in KeyTools

PROBLEM: The if condition in the following function (crypto/KeyTools.java) seems incorrect. Comparing the bitLength() of two values should not be the criterion to do a modulo.

private static ECPoint getPublicPointFromPrivate(BigInteger privateKeyPoint) {
        if (privateKeyPoint.bitLength() > CURVE.getN().bitLength()) {
            privateKeyPoint = privateKeyPoint.mod(CURVE.getN());
        }
        return new FixedPointCombMultiplier().multiply(CURVE.getG(), privateKeyPoint);
}

SOLUTION: Instead of comparing the bitLength(), one should compare the actual values. In fact, one could throw an error if the input is larger than CURVE.N. Since this function is used to generate a public key from a private key, one should also do some extra checks on the input such as the input is 1) positive 2) not equal to 0. @nickcen @iantanwx

Could not sign the transaction withXYZ as it does not exist

           Transaction transaction = Transaction.builder()
            .version(String.valueOf(pack(2, 8)))
            .toAddr("0x4baf5fada8e5db92c3d3242618c5b47133ae003c".toLowerCase())
            .senderPubKey(pubKeyAsHex)
            .amount(amountToSendInQA)
            .gasPrice(gasPriceToSendInQA)
            .gasLimit("1")
            .code("")
            .data("")
            .provider(new HttpProvider("https://dev-api.zilliqa.com"))
            .build();

        Wallet xwallet = new Wallet();
        xwallet.setProvider(new HttpProvider("https://dev-api.zilliqa.com"));
        xwallet.addByPrivateKey(preferencesHelper.getPrivateKey());


        //sign transaction
        transaction = xwallet.sign(transaction);
        System.out.println("signature is: " + transaction.getSignature());

this is what I get -> java.lang.IllegalArgumentException: Could not sign the transaction with01534624A79863C28420E1AD1E2C3B1B628F74FB as it does not exist

Cannot get error message on failure on HttpProvider.createTransaction()

Cannot get error message such like "invalid CHAIN_ID" or "insufficient gas".
When the function has failed, getResult() returns just null and I don't know what the error message was.

example #1 :
{"error":{"code":-26,"data":null,"message":"CHAIN_ID incorrect"},"id":"1","jsonrpc":"2.0"}

example #2 :
{"error":{"code":-26,"data":null,"message":"GasPrice 1 lower than minimum allowable 1000000000"},"id":"1","jsonrpc":"2.0"}

Please add codes to raise exception to get error messsage for each function.
code example here :
(similar to function HttpProvider.getTransaction())

    public Rep<CreateTxResult> createTransaction(TransactionPayload payload) throws IOException {
        Req req = Req.builder().id("1").jsonrpc("2.0").method("CreateTransaction").params(new Object[]{payload}).build();
        Response response = client.newCall(buildRequest(req)).execute();
        String resultString = Objects.requireNonNull(response.body()).string();
        Type type = new TypeToken<Rep<CreateTxResult>>() {
        }.getType();
        Rep<CreateTxResult> rep = gson.fromJson(resultString, type);
+        if (rep.getResult() == null) {
+            throw new IOException("get result error = " + resultString);
+        }
        return rep;
    }

Please remove redundant output message.

HttpProvider.getBalance() writes system output.
We are suffering from this log messages.
Please remove it.

(I'm using version laksaj-0.4.6)


    public Rep<BalanceResult> getBalance(String address) throws IOException {
        Req req = Req.builder().id("1").jsonrpc("2.0").method("GetBalance").params(new String[]{address}).build();
        Response response = client.newCall(buildRequest(req)).execute();
        String resultString = Objects.requireNonNull(response.body()).string();
// remove it ---->         System.out.println(resultString);
        Type type = new TypeToken<Rep<BalanceResult>>() {
        }.getType();
        Rep<BalanceResult> rep = gson.fromJson(resultString, type);

//        Assert.assertNotNull("result is null, check your account address!", rep.getResult());
        if (null == rep.getResult()) {
            BalanceResult balanceResult = new BalanceResult();
            balanceResult.setBalance("0");
            balanceResult.setNonce("0");
            rep.setResult(balanceResult);
        }
        return rep;
    }

cannot be used in android

upon importing it into an android project I get the following error:

2019-02-25 11:43:28.299 6546-6546/wallet.zilliqa E/System: ******** DEPRECATED FUNCTIONALITY ******** 2019-02-25 11:43:28.299 6546-6546/wallet.zilliqa E/System: * The implementation of the KeyPairGenerator.EC algorithm from 2019-02-25 11:43:28.299 6546-6546/wallet.zilliqa E/System: * the BC provider is deprecated in this version of Android. 2019-02-25 11:43:28.299 6546-6546/wallet.zilliqa E/System: * It will be removed in a future version of Android and your 2019-02-25 11:43:28.299 6546-6546/wallet.zilliqa E/System: * application will no longer be able to request it. Please see 2019-02-25 11:43:28.299 6546-6546/wallet.zilliqa E/System: * https://android-developers.googleblog.com/2018/03/cryptography-changes-in-android-p.html 2019-02-25 11:43:28.299 6546-6546/wallet.zilliqa E/System: * for more details. 2019-02-25 11:43:28.304 6546-6546/wallet.zilliqa W/System.err: java.security.InvalidAlgorithmParameterException: parameter object not a ECParameterSpec 2019-02-25 11:43:28.305 6546-6546/wallet.zilliqa W/System.err: at com.android.org.bouncycastle.jcajce.provider.asymmetric.ec.KeyPairGeneratorSpi$EC.initialize(KeyPairGeneratorSpi.java:156) 2019-02-25 11:43:28.305 6546-6546/wallet.zilliqa W/System.err: at java.security.KeyPairGenerator.initialize(KeyPairGenerator.java:438) 2019-02-25 11:43:28.305 6546-6546/wallet.zilliqa W/System.err: at com.firestack.laksaj.crypto.Schnorr.generateKeyPair(Schnorr.java:39) 2019-02-25 11:43:28.305 6546-6546/wallet.zilliqa W/System.err: at com.firestack.laksaj.crypto.KeyTools.generateKeyPair(KeyTools.java:38)

searching some fixes I came across

Android included a shortened version of Bouncycastle, and there is no full support for ECDSA. You can see in the link that algorithm KeyPairGenerator/ECDSA is not supported, which is the required one to generate ethereum keys.

You can not include directly the bouncycastle library because there is a conflict with the package name org.bouncycastle. I suggest to include spongycastle in your project, which it is a repackaged version of bouncycastle for Android org.spongycastle.

so in android

KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("EC", "BC");

is not supported.

so the way to transform this into "android" is to

import org.spongycastle.jce.provider.BouncyCastleProvider;
  static {
    Security.addProvider(new BouncyCastleProvider());
  }

but it gives me the same error

any ideas how to make it work in android ?

mnemonic support

hello,

is it possible to add in util maybe support for generating mnemonic and importing a mnemonic seed

thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.