12

I found this post about BitPay but it's not very clear how I can use it.

https://help.bitpay.com/development/how-do-i-use-the-bitpay-java-client-library

I implemented this code:

public void createInvoice() throws BitPayException
    {
        ECKey key = KeyUtils.createEcKey();
        BitPay bitpay = new BitPay(key);
        InvoiceBuyer buyer = new InvoiceBuyer();
        buyer.setName("Satoshi");
        buyer.setEmail("satoshi@bitpay.com");

        Invoice invoice = new Invoice(100.0, "USD");
        invoice.setBuyer(buyer);
        invoice.setFullNotifications(true);
        invoice.setNotificationEmail("satoshi@bitpay.com");
        invoice.setPosData("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890");

        Invoice createInvoice = bitpay.createInvoice(invoice);
    }

How should I implement the private key?

Hubert Grzeskowiak
  • 15,137
  • 5
  • 57
  • 74
Peter Penzov
  • 1,126
  • 134
  • 430
  • 808

1 Answers1

-1

That answer, I believe, is found in the following file: https://github.com/bitpay/java-bitpay-client/blob/master/src/main/java/controller/BitPay.java - that is to say, you would set your private key on the BitPay client instance. There you can find the appropriate constructor for your needs. You will want to use one or more of the following fields depending on your specific needs:

private ECKey _ecKey = null;
private String _identity = "";
private String _clientName = "";
private Hashtable<String, String> _tokenCache;

Edit: encryption and decryption of your private key exists here: https://github.com/bitpay/java-bitpay-client/blob/master/src/main/java/controller/KeyUtils.java

If, for instance, you used the following constructor:

public BitPay(URI privateKey) throws BitPayException, URISyntaxException,        IOException {
    this(KeyUtils.loadEcKey(privateKey), BITPAY_PLUGIN_INFO, BITPAY_URL);
}

You would pass in the URI for your private key.

Specific instructions on this available here: https://github.com/bitpay/java-bitpay-client/blob/master/GUIDE.md

Two very simple examples:

BitPay bitpay = new BitPay();
ECKey key = KeyUtils.createEcKey();
this.bitpay = new BitPay(key);

Number two:

// Create the private key external to the SDK, store it in a file, and inject    the private key into the SDK.
String privateKey = KeyUtils.getKeyStringFromFile(privateKeyFile);
ECKey key = KeyUtils.createEcKeyFromHexString(privateKey);
this.bitpay = new BitPay(key);

After implementing the private key, you'd till need to initialize the client and connect to the server.

Adam Gerard
  • 708
  • 2
  • 8
  • 23