From dec8cfdd3b79651f7f32d9f550cdc7c6cdd8862b Mon Sep 17 00:00:00 2001
From: Tom Weissinger <tweissin@gmail.com>
Date: Tue, 19 Nov 2024 00:36:33 -0500
Subject: [PATCH 1/3] add missing dependencies; use dotenv instead; make safer

---
 pom.xml                                       | 13 ++++-
 src/main/java/com/coinbase/examples/Main.java | 51 ++++++++++---------
 2 files changed, 39 insertions(+), 25 deletions(-)

diff --git a/pom.xml b/pom.xml
index a9ea41f..5cdb696 100644
--- a/pom.xml
+++ b/pom.xml
@@ -16,7 +16,7 @@
   -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
-  <artifactId>coinbase-advanced-sdk-java</artifactId>
+  <artifactId>coinbase-advanced-sdk-java-temp</artifactId>
   <groupId>com.coinbase.advanced</groupId>
   <name>Coinbase Advanced Trade Java SDK</name>
   <description>Sample Java SDK for the Coinbase International Exchange REST APIs</description>
@@ -207,7 +207,16 @@
       <artifactId>nimbus-jose-jwt</artifactId>
       <version>9.23</version>
     </dependency>
-
+    <dependency>
+      <groupId>io.github.cdimascio</groupId>
+      <artifactId>java-dotenv</artifactId>
+      <version>5.2.2</version>
+    </dependency>
+    <dependency>
+      <groupId>com.coinbase.core</groupId>
+      <artifactId>coinbase-core-java</artifactId>
+      <version>1.0.0</version>
+    </dependency>
 
 
 
diff --git a/src/main/java/com/coinbase/examples/Main.java b/src/main/java/com/coinbase/examples/Main.java
index 5ab79f3..746cd93 100644
--- a/src/main/java/com/coinbase/examples/Main.java
+++ b/src/main/java/com/coinbase/examples/Main.java
@@ -12,20 +12,23 @@
 import com.coinbase.advanced.orders.OrdersService;
 import com.coinbase.advanced.portfolios.PortfoliosService;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import io.github.cdimascio.dotenv.Dotenv;
 
 import java.util.UUID;
 
 public class Main {
     public static void main(String[] args) {
         try {
-            String credsStringBlob = System.getenv("ADVANCED_TRADE_CREDENTIALS");
-            if (credsStringBlob == null) {
-                throw new RuntimeException("ADVANCED_TRADE_CREDENTIALS environment variable is not set");
-            }
+            Dotenv dotenv = Dotenv.configure()
+                    .directory(System.getProperty("user.home"))
+                    .filename(".bcenv")
+                    .load();
+            String privateKeyPEM = dotenv.get("COINBASE_PRIVATE_KEY").replace("\\n", "\n");
+            String name = dotenv.get("COINBASE_API_KEY_NAME");
 
             ObjectMapper mapper = new ObjectMapper();
 
-            CoinbaseAdvancedCredentials credentials = new CoinbaseAdvancedCredentials(credsStringBlob);
+            CoinbaseAdvancedCredentials credentials = new CoinbaseAdvancedCredentials(name, privateKeyPEM);
             CoinbaseAdvancedClient client = new CoinbaseAdvancedClient(credentials);
             PortfoliosService portfolioService = CoinbaseAdvancedServiceFactory.createPortfoliosService(client);
 
@@ -39,25 +42,27 @@ public static void main(String[] args) {
 
             OrdersService ordersService = CoinbaseAdvancedServiceFactory.createOrdersService(client);
 
-            CreateOrderRequest createOrderRequest = new CreateOrderRequest.Builder()
-                    .clientOrderId(UUID.randomUUID().toString())
-                    .productId("ADA-USD")
-                    .retailPortfolioId(listResponse.getPortfolios().get(0).getUuid())
-                    .side("BUY")
-                    .orderConfiguration(
-                            new OrderConfiguration.Builder()
-                                    .marketMarketIoc(
-                                            new MarketIoc.Builder()
-                                                    .baseSize("1")
-                                                    .build())
-                                    .build()
-                    )
-                    .build();
-            CreateOrderResponse createOrderResponse = ordersService.createOrder(createOrderRequest);
+            if (false) {
+                CreateOrderRequest createOrderRequest = new CreateOrderRequest.Builder()
+                        .clientOrderId(UUID.randomUUID().toString())
+                        .productId("ADA-USD")
+                        .retailPortfolioId(listResponse.getPortfolios().get(0).getUuid())
+                        .side("BUY")
+                        .orderConfiguration(
+                                new OrderConfiguration.Builder()
+                                        .marketMarketIoc(
+                                                new MarketIoc.Builder()
+                                                        .baseSize("1")
+                                                        .build())
+                                        .build()
+                        )
+                        .build();
+                CreateOrderResponse createOrderResponse = ordersService.createOrder(createOrderRequest);
 
-            prettyJson = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(createOrderResponse);
-            System.out.println("Create Order Response");
-            System.out.println(prettyJson);
+                prettyJson = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(createOrderResponse);
+                System.out.println("Create Order Response");
+                System.out.println(prettyJson);
+            }
 
         } catch (Throwable e) {
             throw new RuntimeException("Failed to retrieve the list portfolios response", e);

From 9fac3771e1b5ef7ab11f076d3c7243a6ecd03f82 Mon Sep 17 00:00:00 2001
From: Tom Weissinger <tweissin@gmail.com>
Date: Tue, 19 Nov 2024 07:24:44 -0500
Subject: [PATCH 2/3] remove temp

---
 pom.xml | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/pom.xml b/pom.xml
index 5cdb696..9a5a8d7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -16,7 +16,7 @@
   -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
-  <artifactId>coinbase-advanced-sdk-java-temp</artifactId>
+  <artifactId>coinbase-advanced-sdk-java</artifactId>
   <groupId>com.coinbase.advanced</groupId>
   <name>Coinbase Advanced Trade Java SDK</name>
   <description>Sample Java SDK for the Coinbase International Exchange REST APIs</description>
@@ -192,20 +192,20 @@
       <version>0.11.5</version>
       <scope>runtime</scope>
     </dependency>
+<!--    <dependency>-->
+<!--      <groupId>org.bouncycastle</groupId>-->
+<!--      <artifactId>bcprov-jdk15on</artifactId>-->
+<!--      <version>1.70</version>-->
+<!--    </dependency>-->
     <dependency>
       <groupId>org.bouncycastle</groupId>
-      <artifactId>bcprov-jdk15on</artifactId>
-      <version>1.70</version>
-    </dependency>
-    <dependency>
-      <groupId>org.bouncycastle</groupId>
-      <artifactId>bcpkix-jdk15on</artifactId>
-      <version>1.70</version>
+      <artifactId>bcpkix-jdk18on</artifactId>
+      <version>1.79</version>
     </dependency>
     <dependency>
       <groupId>com.nimbusds</groupId>
       <artifactId>nimbus-jose-jwt</artifactId>
-      <version>9.23</version>
+      <version>9.46</version>
     </dependency>
     <dependency>
       <groupId>io.github.cdimascio</groupId>

From c98a9aaf69abce2885ed65c654587bfc5cd82c38 Mon Sep 17 00:00:00 2001
From: Tom Weissinger <tweissin@gmail.com>
Date: Tue, 19 Nov 2024 07:25:39 -0500
Subject: [PATCH 3/3] remove unneeded dependency

---
 pom.xml | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/pom.xml b/pom.xml
index 9a5a8d7..7bd7fa5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -192,11 +192,6 @@
       <version>0.11.5</version>
       <scope>runtime</scope>
     </dependency>
-<!--    <dependency>-->
-<!--      <groupId>org.bouncycastle</groupId>-->
-<!--      <artifactId>bcprov-jdk15on</artifactId>-->
-<!--      <version>1.70</version>-->
-<!--    </dependency>-->
     <dependency>
       <groupId>org.bouncycastle</groupId>
       <artifactId>bcpkix-jdk18on</artifactId>