Skip to content

Commit 6b3c65b

Browse files
authored
Merge pull request #8 from coinbase-samples/jc-dev-sdk
update responses, update dependencies, add data api support
2 parents 5040df1 + 2dda495 commit 6b3c65b

17 files changed

+481
-77
lines changed

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
<artifactId>coinbase-advanced-sdk-java</artifactId>
2020
<groupId>com.coinbase.advanced</groupId>
2121
<name>Coinbase Advanced Trade Java SDK</name>
22-
<description>Sample Java SDK for the Coinbase International Exchange REST APIs</description>
23-
<version>0.1.0</version>
22+
<description>Sample Java SDK for the Coinbase Advanced REST APIs</description>
23+
<version>0.2.0</version>
2424
<url>https://github.com/coinbase-samples/advanced-sdk-java</url>
2525
<licenses>
2626
<license>
@@ -48,7 +48,7 @@
4848
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
4949
<java.version>1.11</java.version>
5050
<jackson.version>2.16.1</jackson.version>
51-
<core.version>0.1.0</core.version>
51+
<core.version>1.0.1</core.version>
5252
</properties>
5353
<build>
5454
<plugins>

src/main/java/com/coinbase/advanced/credentials/CoinbaseAdvancedCredentials.java

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -102,36 +102,36 @@ public String generateJwt(String requestMethod, String host, String path) throws
102102
data.put("sub", apiKeyName);
103103
data.put("uri", uri);
104104

105-
PEMParser pemParser = new PEMParser(new StringReader(privateKey));
106-
JcaPEMKeyConverter converter = new JcaPEMKeyConverter().setProvider("BC");
107-
Object object = pemParser.readObject();
108-
PrivateKey privateKey;
109-
110-
if (object instanceof PrivateKey) {
111-
privateKey = (PrivateKey) object;
112-
} else if (object instanceof org.bouncycastle.openssl.PEMKeyPair) {
113-
privateKey = converter.getPrivateKey(((org.bouncycastle.openssl.PEMKeyPair) object).getPrivateKeyInfo());
114-
} else {
115-
throw new Exception("Unexpected private key format");
105+
try (PEMParser pemParser = new PEMParser(new StringReader(privateKey))) {
106+
JcaPEMKeyConverter converter = new JcaPEMKeyConverter().setProvider("BC");
107+
Object object = pemParser.readObject();
108+
PrivateKey privateKey;
109+
110+
if (object instanceof PrivateKey) {
111+
privateKey = (PrivateKey) object;
112+
} else if (object instanceof org.bouncycastle.openssl.PEMKeyPair) {
113+
privateKey = converter.getPrivateKey(((org.bouncycastle.openssl.PEMKeyPair) object).getPrivateKeyInfo());
114+
} else {
115+
throw new Exception("Unexpected private key format");
116+
}
117+
118+
KeyFactory keyFactory = KeyFactory.getInstance("EC");
119+
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(privateKey.getEncoded());
120+
ECPrivateKey ecPrivateKey = (ECPrivateKey) keyFactory.generatePrivate(keySpec);
121+
122+
JWTClaimsSet.Builder claimsSetBuilder = new JWTClaimsSet.Builder();
123+
for (Map.Entry<String, Object> entry : data.entrySet()) {
124+
claimsSetBuilder.claim(entry.getKey(), entry.getValue());
125+
}
126+
JWTClaimsSet claimsSet = claimsSetBuilder.build();
127+
128+
JWSHeader jwsHeader = new JWSHeader.Builder(JWSAlgorithm.ES256).customParams(header).build();
129+
SignedJWT signedJWT = new SignedJWT(jwsHeader, claimsSet);
130+
131+
JWSSigner signer = new ECDSASigner(ecPrivateKey);
132+
signedJWT.sign(signer);
133+
134+
return signedJWT.serialize();
116135
}
117-
pemParser.close();
118-
119-
KeyFactory keyFactory = KeyFactory.getInstance("EC");
120-
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(privateKey.getEncoded());
121-
ECPrivateKey ecPrivateKey = (ECPrivateKey) keyFactory.generatePrivate(keySpec);
122-
123-
JWTClaimsSet.Builder claimsSetBuilder = new JWTClaimsSet.Builder();
124-
for (Map.Entry<String, Object> entry : data.entrySet()) {
125-
claimsSetBuilder.claim(entry.getKey(), entry.getValue());
126-
}
127-
JWTClaimsSet claimsSet = claimsSetBuilder.build();
128-
129-
JWSHeader jwsHeader = new JWSHeader.Builder(JWSAlgorithm.ES256).customParams(header).build();
130-
SignedJWT signedJWT = new SignedJWT(jwsHeader, claimsSet);
131-
132-
JWSSigner signer = new ECDSASigner(ecPrivateKey);
133-
signedJWT.sign(signer);
134-
135-
return signedJWT.serialize();
136136
}
137137
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2025-present Coinbase Global, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.coinbase.advanced.dataapi;
18+
19+
import com.coinbase.advanced.errors.CoinbaseAdvancedException;
20+
import com.coinbase.advanced.model.dataapi.*;
21+
22+
public interface DataApiService {
23+
GetApiKeyPermissionsResponse getApiKeyPermissions(GetApiKeyPermissionsRequest request) throws CoinbaseAdvancedException;
24+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2025-present Coinbase Global, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
18+
package com.coinbase.advanced.dataapi;
19+
20+
import com.coinbase.advanced.client.CoinbaseAdvancedClient;
21+
import com.coinbase.advanced.errors.CoinbaseAdvancedException;
22+
import com.coinbase.advanced.model.dataapi.*;
23+
import com.coinbase.core.common.HttpMethod;
24+
import com.coinbase.core.service.CoinbaseServiceImpl;
25+
import com.fasterxml.jackson.core.type.TypeReference;
26+
27+
import java.util.List;
28+
29+
public class DataApiServiceImpl extends CoinbaseServiceImpl implements DataApiService {
30+
public DataApiServiceImpl(CoinbaseAdvancedClient client) {
31+
super(client);
32+
}
33+
34+
@Override
35+
public GetApiKeyPermissionsResponse getApiKeyPermissions(GetApiKeyPermissionsRequest request) throws CoinbaseAdvancedException {
36+
return this.request(
37+
HttpMethod.GET,
38+
"/brokerage/key_permissions",
39+
null,
40+
List.of(200),
41+
new TypeReference<GetApiKeyPermissionsResponse>() {});
42+
}
43+
}
44+

src/main/java/com/coinbase/advanced/factory/CoinbaseAdvancedServiceFactory.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.coinbase.advanced.client.CoinbaseAdvancedClient;
66
import com.coinbase.advanced.converts.ConvertsService;
77
import com.coinbase.advanced.converts.ConvertsServiceImpl;
8+
import com.coinbase.advanced.dataapi.DataApiService;
9+
import com.coinbase.advanced.dataapi.DataApiServiceImpl;
810
import com.coinbase.advanced.fees.FeesService;
911
import com.coinbase.advanced.fees.FeesServiceImpl;
1012
import com.coinbase.advanced.futures.FuturesService;
@@ -62,4 +64,8 @@ public static ProductsService createProductsService(CoinbaseAdvancedClient clien
6264
public static PublicService createPublicService(CoinbaseAdvancedClient client) {
6365
return new PublicServiceImpl(client);
6466
}
67+
68+
public static DataApiService createDataApiService(CoinbaseAdvancedClient client) {
69+
return new DataApiServiceImpl(client);
70+
}
6571
}

src/main/java/com/coinbase/advanced/model/common/DualCurrencyValue.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.coinbase.advanced.model.common;
1818

19-
import com.coinbase.advanced.model.common.Amount;
2019
import com.fasterxml.jackson.annotation.JsonProperty;
2120

2221
public class DualCurrencyValue {

src/main/java/com/coinbase/advanced/model/converts/CreateConvertQuoteRequest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
import com.coinbase.advanced.model.common.TradeIncentiveMetadata;
2020
import com.fasterxml.jackson.annotation.JsonProperty;
21-
import com.fasterxml.jackson.core.JsonProcessingException;
22-
import com.fasterxml.jackson.databind.ObjectMapper;
2321

2422
public class CreateConvertQuoteRequest {
2523
@JsonProperty("from_account")
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* Copyright 2025-present Coinbase Global, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.coinbase.advanced.model.dataapi;
18+
19+
import com.fasterxml.jackson.annotation.JsonProperty;
20+
21+
public class DataApi {
22+
23+
@JsonProperty("can_view")
24+
private boolean canView;
25+
26+
@JsonProperty("can_trade")
27+
private boolean canTrade;
28+
29+
@JsonProperty("can_transfer")
30+
private boolean canTransfer;
31+
32+
@JsonProperty("portfolio_uuid")
33+
private String portfolioUuid;
34+
35+
@JsonProperty("portfolio_type")
36+
private String portfolioType;
37+
38+
public DataApi() {}
39+
40+
private DataApi(Builder builder) {
41+
this.canView = builder.canView;
42+
this.canTrade = builder.canTrade;
43+
this.canTransfer = builder.canTransfer;
44+
this.portfolioUuid = builder.portfolioUuid;
45+
this.portfolioType = builder.portfolioType;
46+
}
47+
48+
public static class Builder {
49+
private boolean canView;
50+
private boolean canTrade;
51+
private boolean canTransfer;
52+
private String portfolioUuid;
53+
private String portfolioType;
54+
55+
public Builder() {}
56+
57+
public Builder canView(boolean canView) {
58+
this.canView = canView;
59+
return this;
60+
}
61+
62+
public Builder canTrade(boolean canTrade) {
63+
this.canTrade = canTrade;
64+
return this;
65+
}
66+
67+
public Builder canTransfer(boolean canTransfer) {
68+
this.canTransfer = canTransfer;
69+
return this;
70+
}
71+
72+
public Builder portfolioUuid(String portfolioUuid) {
73+
this.portfolioUuid = portfolioUuid;
74+
return this;
75+
}
76+
77+
public Builder portfolioType(String portfolioType) {
78+
this.portfolioType = portfolioType;
79+
return this;
80+
}
81+
82+
public DataApi build() {
83+
return new DataApi(this);
84+
}
85+
}
86+
87+
public boolean getCanView() {
88+
return canView;
89+
}
90+
91+
public boolean getCanTrade() {
92+
return canTrade;
93+
}
94+
95+
public boolean getCanTransfer() {
96+
return canTransfer;
97+
}
98+
99+
public String getPortfolioUuid() {
100+
return portfolioUuid;
101+
}
102+
103+
public String getPortfolioType() {
104+
return portfolioType;
105+
}
106+
107+
public void setCanView(boolean canView) {
108+
this.canView = canView;
109+
}
110+
111+
public void setCanTrade(boolean canTrade) {
112+
this.canTrade = canTrade;
113+
}
114+
115+
public void setCanTransfer(boolean canTransfer) {
116+
this.canTransfer = canTransfer;
117+
}
118+
119+
public void setPortfolioUuid(String portfolioUuid) {
120+
this.portfolioUuid = portfolioUuid;
121+
}
122+
123+
public void setPortfolioType(String portfolioType) {
124+
this.portfolioType = portfolioType;
125+
}
126+
}
127+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2025-present Coinbase Global, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.coinbase.advanced.model.dataapi;
18+
19+
import com.fasterxml.jackson.annotation.JsonProperty;
20+
21+
public class GetApiKeyPermissionsRequest {
22+
23+
@JsonProperty("api_key")
24+
private String apiKey;
25+
26+
public GetApiKeyPermissionsRequest() {}
27+
28+
public GetApiKeyPermissionsRequest(String apiKey) {
29+
this.apiKey = apiKey;
30+
}
31+
32+
public String getApiKey() {
33+
return apiKey;
34+
}
35+
36+
public void setApiKey(String apiKey) {
37+
this.apiKey = apiKey;
38+
}
39+
}

0 commit comments

Comments
 (0)