Overview
VeChain Chip Verify SDK can provide VeChain NFC SDK for VeChain NFC chips verification, VeChain RFID SDK for VeChain RFID chips verification and VeChain Sensor SDk for collect temperature, humidity and acceleration data according to your settings and ensure that the temperature, humidity and acceleration data is reliable and can be verified.
For first time users
Step 1: Register the app
Login in with ToolChain account and register your app. Contact toolchainsupport@vechain.com for more support.
-
“Android Package name" field - This ID uniquely identifies your app on the device. Your application ID is defined with the
applicationId
property in your module'sbuild.gradle
file, as shown here:android { defaultConfig { applicationId "com.vechain.user" minSdkVersion 19 targetSdkVersion 28 versionCode 1 versionName "1.0" } ... }
-
“Android Signature" field - enter your APP Signature(download the "Signature Tool" to get the APP Signature installed on your phone).
Record Verify ID for SDK registration.
VeChainNFCSDK.registerSDK("Verify ID");
Step 2: Upload CSR file
- Generate a CSR file: How to generate a csr file.
- Upload your CSR file.
Step 3: Download certificate
This certificate would be used as the parameter in SDK later on.
More Details see : Appendix A: FAQ # How to Sign ChallengeID
Get Started
Requirements
The minimum Android API level this SDK will run on is 19 (= Android 5.0), and an Android device with NFC features.
Manual Import
1 > Unzip the VeChainVerifySDK.zip and you can see the list as below.
put vechain-verify-sdk.aar under the libs folder.
2 > You also need to add followings to your app/build.gradle file.
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
implementation(name: 'vechain-verify-sdk', ext: 'aar')
}
Packing confusion instructions
Add the following lines to the proguard-rules.pro:
#sdk
-keep class com.vechain.** { *; }
-dontwarn com.vechain.**
-keep class com.baidu.** { *;}
-keep class com.google.android.gms.** { *;}
-keep class com.google.firebase.** { *;}
-keep class com.tbruyelle.**
# aliyun
-keep class com.aliyun.** { *; }
-keep class org.bouncycastle.jcajce.provider.** { *; }
-keep class org.bouncycastle.jce.provider.** { *; }
##---------------Begin: proguard configuration for Okhttp ----------
# Okhttp3
# JSR 305 annotations are for embedding nullability information.
-dontwarn javax.annotation.**
# A resource is loaded with a relative path so the package of this class must be preserved.
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java.
-dontwarn org.codehaus.mojo.animal_sniffer.*
# OkHttp platform used only on JVM and when Conscrypt dependency is available.
-dontwarn okhttp3.internal.platform.ConscryptPlatform
-keep class okio.** { *; }
-keep class okhttp3.** { *; }
##---------------end: proguard configuration for Okhttp ----------
##---------------Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature
# For using GSON @Expose annotation
-keepattributes *Annotation*
# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }
# Prevent proguard from stripping interface information from TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer
-keep class com.google.gson.** { *;}
##---------------End: proguard configuration for Gson ----------
##---------------Begin: proguard configuration for Retrofit ----------
# Retrofit does reflection on generic parameters. InnerClasses is required to use Signature and
# EnclosingMethod is required to use InnerClasses.
-keepattributes Signature, InnerClasses, EnclosingMethod
# Retain service method parameters when optimizing.
-keepclassmembers,allowshrinking,allowobfuscation interface * {
@retrofit2.http.* <methods>;
}
# Ignore annotation used for build tooling.
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
# Ignore JSR 305 annotations for embedding nullability information.
-dontwarn javax.annotation.**
-keep class retrofit2.** { *; }
##---------------End: proguard configuration for Retrofit ----------
##---------------Begin: proguard configuration for RxJava ----------
#rxbinding
-keep class com.jakewharton.**
-keep class com.squareup.**
-keep class com.tbruyelle.**
-keep class com.trello.**
-keep class io.reactivex.** { *;}
-keep class org.hamcrest.**
-keep class org.reactivestreams.**
#-keepattributes Signature-keepattributes Exceptions
#RxJava RxAndroid
-keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
long producerIndex;
long consumerIndex;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
rx.internal.util.atomic.LinkedQueueNode producerNode;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef {
rx.internal.util.atomic.LinkedQueueNode consumerNode;
}
##---------------End: proguard configuration for RxJava ----------
Appendix A: FAQ
1. How to sign ChallengeID
You have two ways to sign the ChallengeID
Parameter
1. certString : Open your certificate (xxx.pem file) download from VeChain Developer Certer, copy the content between begin & end line.
2. certKey : Open the Terminal and input below commands: openssl ec -noout -text -in yourkey.key
Remove all the colons of priv. Sometimes, OpenSSL is adding a null byte (0x00) in front of the private part, you have to trim any leading zero bytes.
The private key must be 32 bytes and not begin with 0x00.
cdab7b2f80d0114ab8a55463a84df26ead9b2c87ff9df2fbb7b8842c63479360
3. challengeId : VeChain Service provides in the callback SignAction#sign().
Option 1:
Sign ChallengeId local - download Signlib from Sample Application and call method com.vechain.tools.signlib.CertUtils.getSignature(String certString, String certKey, String challengeId) to get signature.
package com.vechain.tools.signlib.cert;
public class CertUtils {
/**
* build signature
* @param certString
* @param certKey
* @param challengeId
* @return signature
*/
public static String getSignature(String certString, String certKey, String challengeId) {
return signature;
}
}
public class MySignAction implements SignAction {
@Override
public void sign(Context context, String challengeId, SignNotifier signNotifier) {
String certString = "Your certificate string";
String privateKeyString = "Your private key";
//More Detail about how to sign the challengeId and get signature, refers to Appendix A: FAQ - How to Sign ChallengeID
String signature = CertUtils.getSignInfo(certString, privateKeyString, challengeId);
signNotifier.onSignResult(signature, "");
}
}
Option 2:
Sign ChallengeId from your server - save your certification & private key on your own server, then return signature that signed on server.
Notice: Even you failed to get the signature from your server, please still call this function SignNotifier.onSignResult("");
public class MySignAction implements SignAction {
@Override
public void sign(Context context, String challengeId, SignNotifier signNotifier) {
Api.sign(challengeId, new NetCallBack() {
@Override
public void onSuccess(Object result) {
HttpResult signHttpResult = (HttpResult) result;
String signature = signHttpResult.getSignInfo();
signNotifier.onSignResult(signature, "");
}
@Override
public void onError(Throwable throwable) {
super.onError(throwable);
}
});
}
}
2. Check for NFC avalailbility
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
if (nfcAdapter == null) return; // NFC not available on this device
}
3. Check if NFC is enabled
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
if (nfcAdapter != null) {
//Applications can use this to check if NFC is enabled. Applications can request Settings UI allowing the user to toggle NFC using:
boolean isEnabled = nfcAdapter.isEnabled();
};
}
Comments
0 comments
Please sign in to leave a comment.