Skip to content

Commit 0667d48

Browse files
authored
Merge pull request #32 from unicitynetwork/issue-30
Update SDK to work with Android 12
2 parents 725c700 + 01bbfac commit 0667d48

14 files changed

Lines changed: 39 additions & 33 deletions

‎build.gradle.kts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,19 @@ dependencies {
3939
"android"("com.google.guava:guava:33.0.0-android")
4040
"jvm"("com.google.guava:guava:33.0.0-jre")
4141

42-
// Animal Sniffer signatures
43-
signature("com.toasttab.android:gummy-bears-api-34:0.7.0@signature")
42+
// Animal Sniffer signature for Android API 31
43+
// Note: This SDK uses Java 9-11 APIs (List.of, Map.of, Stream enhancements, etc.)
44+
// which require core library desugaring to be enabled in consuming Android apps.
45+
// Apps using this SDK must add to their build.gradle:
46+
// android {
47+
// compileOptions {
48+
// coreLibraryDesugaringEnabled true
49+
// }
50+
// }
51+
// dependencies {
52+
// coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'
53+
// }
54+
signature("com.toasttab.android:gummy-bears-api-31:0.11.0@signature")
4455

4556
// Testing
4657
testImplementation(platform("org.junit:junit-bom:5.10.2"))

‎config/checkstyle/checkstyle.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
<module name="LineLength">
5656
<property name="fileExtensions" value="java"/>
57-
<property name="max" value="100"/>
57+
<property name="max" value="120"/>
5858
<property name="ignorePattern"
5959
value="^package.*|^import.*|href\s*=\s*&quot;[^&quot;]*&quot;|http://|https://|ftp://"/>
6060
</module>

‎src/main/java/org/unicitylabs/sdk/address/ProxyAddress.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public static Address resolve(Address inputAddress, List<Token<?>> nametags) {
8585
Address targetAddress = inputAddress;
8686
while (targetAddress.getScheme() != AddressScheme.DIRECT) {
8787
Token<?> nametag = nametagMap.get(targetAddress);
88-
if (nametag == null || nametag.getData().isEmpty()) {
88+
if (nametag == null || !nametag.getData().isPresent()) {
8989
return null;
9090
}
9191

‎src/main/java/org/unicitylabs/sdk/api/JsonRpcAggregatorClient.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static com.google.common.net.HttpHeaders.AUTHORIZATION;
44

5-
import java.util.Collections;
65
import java.util.List;
76
import java.util.Map;
87
import java.util.concurrent.CompletableFuture;
@@ -89,8 +88,7 @@ public CompletableFuture<InclusionProofResponse> getInclusionProof(RequestId req
8988
* @return block height
9089
*/
9190
public CompletableFuture<Long> getBlockHeight() {
92-
return this.transport.request("get_block_height", Collections.emptyMap(),
93-
BlockHeightResponse.class)
91+
return this.transport.request("get_block_height", Map.of(), BlockHeightResponse.class)
9492
.thenApply(BlockHeightResponse::getBlockNumber);
9593
}
9694
}

‎src/main/java/org/unicitylabs/sdk/bft/RootTrustBase.java‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,10 @@ public class RootTrustBase {
5656
? null
5757
: Arrays.copyOf(previousEntryHash, previousEntryHash.length);
5858
this.signatures = signatures.entrySet().stream()
59-
.collect(
60-
Collectors.toUnmodifiableMap(
61-
Map.Entry::getKey,
62-
e -> Arrays.copyOf(e.getValue(), e.getValue().length)
63-
)
64-
);
59+
.collect(Collectors.toMap(
60+
Map.Entry::getKey,
61+
e -> Arrays.copyOf(e.getValue(), e.getValue().length)
62+
));
6563
}
6664

6765
/**
@@ -159,13 +157,13 @@ public byte[] getPreviousEntryHash() {
159157
* @return signatures
160158
*/
161159
public Map<String, byte[]> getSignatures() {
162-
return this.signatures.entrySet().stream()
163-
.collect(
164-
Collectors.toUnmodifiableMap(
160+
return Map.copyOf(
161+
this.signatures.entrySet().stream()
162+
.collect(Collectors.toMap(
165163
Map.Entry::getKey,
166164
e -> Arrays.copyOf(e.getValue(), e.getValue().length)
167-
)
168-
);
165+
))
166+
);
169167
}
170168

171169
/**

‎src/main/java/org/unicitylabs/sdk/bft/verification/rule/UnicitySealHashMatchesWithRootHashRule.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.nio.ByteBuffer;
44
import java.nio.ByteOrder;
55
import java.util.Arrays;
6+
7+
import com.google.common.primitives.UnsignedBytes;
68
import org.unicitylabs.sdk.bft.UnicityCertificate;
79
import org.unicitylabs.sdk.bft.UnicityTreeCertificate;
810
import org.unicitylabs.sdk.bft.verification.UnicityCertificateVerificationContext;
@@ -89,7 +91,7 @@ public VerificationResult verify(UnicityCertificateVerificationContext context)
8991
.update(CborSerializer.encodeByteString(new byte[]{(byte) 0x00})) // NODE
9092
.update(CborSerializer.encodeByteString(stepKey));
9193

92-
if (Arrays.compare(key, stepKey) > 0) {
94+
if (UnsignedBytes.lexicographicalComparator().compare(key, stepKey) > 0) {
9395
hasher
9496
.update(CborSerializer.encodeByteString(step.getHash()))
9597
.update(CborSerializer.encodeByteString(result.getData()));
@@ -104,7 +106,8 @@ public VerificationResult verify(UnicityCertificateVerificationContext context)
104106

105107
byte[] unicitySealHash = context.getUnicityCertificate().getUnicitySeal().getHash();
106108

107-
if (Arrays.compare(unicitySealHash, result.getData()) != 0) {
109+
if (UnsignedBytes.lexicographicalComparator().compare(unicitySealHash, result.getData())
110+
!= 0) {
108111
return VerificationResult.fail("Unicity seal hash does not match tree root.");
109112
}
110113

‎src/main/java/org/unicitylabs/sdk/mtree/plain/SparseMerkleTreePath.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ public List<SparseMerkleTreePathStep> getSteps() {
6262
* Verify merkle tree path against given path.
6363
*
6464
* @param requestId path
65-
* @return true if successful
65+
* @return MerkleTreePathVerificationResult
6666
*/
6767
public MerkleTreePathVerificationResult verify(BigInteger requestId) {
68-
if (this.steps.size() == 0) {
68+
if (this.steps.isEmpty()) {
6969
return new MerkleTreePathVerificationResult(false, false);
7070
}
7171

‎src/main/java/org/unicitylabs/sdk/mtree/plain/SparseMerkleTreeRootNode.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.math.BigInteger;
44
import java.util.ArrayList;
5-
import java.util.Collections;
65
import java.util.List;
76
import java.util.Objects;
87
import org.unicitylabs.sdk.hash.DataHash;
@@ -127,6 +126,6 @@ private static List<SparseMerkleTreePathStep> generatePath(
127126
)
128127
);
129128

130-
return Collections.unmodifiableList(list);
129+
return List.copyOf(list);
131130
}
132131
}

‎src/main/java/org/unicitylabs/sdk/mtree/sum/SparseMerkleSumTreeRootNode.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ private static List<SparseMerkleSumTreePathStep> generatePath(
129129
FinalizedNodeBranch nodeBranch = (FinalizedNodeBranch) branch;
130130

131131
if (remainingPath.shiftRight(commonPath.getLength()).compareTo(BigInteger.ONE) == 0) {
132-
return List.of(
133-
new SparseMerkleSumTreePathStep(branch.getPath(), siblingBranch, nodeBranch));
132+
return List.of(new SparseMerkleSumTreePathStep(branch.getPath(), siblingBranch, nodeBranch));
134133
}
135134

136135
return List.copyOf(

‎src/main/java/org/unicitylabs/sdk/serializer/json/BigIntegerAsStringSerializer.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.fasterxml.jackson.core.JsonGenerator;
44
import com.fasterxml.jackson.databind.JsonSerializer;
55
import com.fasterxml.jackson.databind.SerializerProvider;
6-
76
import java.io.IOException;
87
import java.math.BigInteger;
98

0 commit comments

Comments
 (0)