diff --git a/android/.gitignore b/android/.gitignore
new file mode 100644
index 0000000..603b140
--- /dev/null
+++ b/android/.gitignore
@@ -0,0 +1,14 @@
+*.iml
+.gradle
+/local.properties
+/.idea/caches
+/.idea/libraries
+/.idea/modules.xml
+/.idea/workspace.xml
+/.idea/navEditor.xml
+/.idea/assetWizardSettings.xml
+.DS_Store
+/build
+/captures
+.externalNativeBuild
+.cxx
diff --git a/android/.gradle/5.6.4/fileHashes/fileHashes.lock b/android/.gradle/5.6.4/fileHashes/fileHashes.lock
new file mode 100644
index 0000000..c3bd737
Binary files /dev/null and b/android/.gradle/5.6.4/fileHashes/fileHashes.lock differ
diff --git a/android/.idea/.name b/android/.idea/.name
new file mode 100644
index 0000000..696dada
--- /dev/null
+++ b/android/.idea/.name
@@ -0,0 +1 @@
+Backup
\ No newline at end of file
diff --git a/android/.idea/codeStyles/Project.xml b/android/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..681f41a
--- /dev/null
+++ b/android/.idea/codeStyles/Project.xml
@@ -0,0 +1,116 @@
+
+
+
+
+
+
+
+
+
+
+
+
+ xmlns:android
+
+ ^$
+
+
+
+
+
+
+
+
+ xmlns:.*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*:id
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:name
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ name
+
+ ^$
+
+
+
+
+
+
+
+
+ style
+
+ ^$
+
+
+
+
+
+
+
+
+ .*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*
+
+ http://schemas.android.com/apk/res/android
+
+
+ ANDROID_ATTRIBUTE_ORDER
+
+
+
+
+
+
+ .*
+
+ .*
+
+
+ BY_NAME
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/.idea/gradle.xml b/android/.idea/gradle.xml
new file mode 100644
index 0000000..5cd135a
--- /dev/null
+++ b/android/.idea/gradle.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/.idea/misc.xml b/android/.idea/misc.xml
new file mode 100644
index 0000000..37a7509
--- /dev/null
+++ b/android/.idea/misc.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/.idea/runConfigurations.xml b/android/.idea/runConfigurations.xml
new file mode 100644
index 0000000..7f68460
--- /dev/null
+++ b/android/.idea/runConfigurations.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/.idea/vcs.xml b/android/.idea/vcs.xml
new file mode 100644
index 0000000..6c0b863
--- /dev/null
+++ b/android/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/README.md b/android/README.md
new file mode 100644
index 0000000..0e788dd
--- /dev/null
+++ b/android/README.md
@@ -0,0 +1,40 @@
+## Gomobile instalation
+```
+$ go get golang.org/x/mobile/cmd/gomobile
+$ gomobile init
+```
+## Install Android Studio (on Ubuntu 20.04):
+```
+$ sudo apt install openjdk-11-jdk
+$ sudo snap install android-studio --classic
+```
+## Install Android NDK:
+
+https://developer.android.com/ndk
+
+You may need to configure these enviroment variables:
+```
+export GOPATH=~/go
+export PATH=$PATH:$GOPATH/bin
+export ANDROID_NDK_HOME= {PATH to Android NDK}
+export ANDROID_HOME= {PATH to Android SDK}
+```
+## aar generation
+```
+$ gomobile bind -o app/backup.aar -target=android ../wrapper/
+```
+## Use of .aar in Android project
+
+Edit android\app\build.gradle adding:
+```
++ repositories {
++ flatDir {
++ dirs '.'
++ }
++ }
+
+dependencies {
+...
++ implementation (name:'backup', ext:'aar')
+}
+```
diff --git a/android/app/.gitignore b/android/app/.gitignore
new file mode 100644
index 0000000..796b96d
--- /dev/null
+++ b/android/app/.gitignore
@@ -0,0 +1 @@
+/build
diff --git a/android/app/backup-sources.jar b/android/app/backup-sources.jar
new file mode 100644
index 0000000..e84ca8e
Binary files /dev/null and b/android/app/backup-sources.jar differ
diff --git a/android/app/backup.aar b/android/app/backup.aar
new file mode 100644
index 0000000..1bb3c14
Binary files /dev/null and b/android/app/backup.aar differ
diff --git a/android/app/build.gradle b/android/app/build.gradle
new file mode 100644
index 0000000..062692b
--- /dev/null
+++ b/android/app/build.gradle
@@ -0,0 +1,45 @@
+apply plugin: 'com.android.application'
+
+android {
+ compileSdkVersion 29
+ buildToolsVersion "29.0.3"
+
+ defaultConfig {
+ applicationId "io.iden3.backup"
+ minSdkVersion 16
+ targetSdkVersion 29
+ versionCode 1
+ versionName "1.0"
+
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+ }
+
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+ }
+ }
+
+}
+
+repositories {
+ flatDir {
+ dirs '.'
+ }
+}
+
+dependencies {
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
+
+ implementation 'androidx.appcompat:appcompat:1.1.0'
+ implementation 'com.google.android.material:material:1.1.0'
+ implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
+ implementation 'androidx.navigation:navigation-fragment:2.2.2'
+ implementation 'androidx.navigation:navigation-ui:2.2.2'
+ testImplementation 'junit:junit:4.12'
+ androidTestImplementation 'androidx.test.ext:junit:1.1.1'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
+ implementation (name:'backup', ext:'aar')
+
+}
diff --git a/android/app/proguard-rules.pro b/android/app/proguard-rules.pro
new file mode 100644
index 0000000..f1b4245
--- /dev/null
+++ b/android/app/proguard-rules.pro
@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
diff --git a/android/app/src/androidTest/java/io/iden3/backup/ExampleInstrumentedTest.java b/android/app/src/androidTest/java/io/iden3/backup/ExampleInstrumentedTest.java
new file mode 100644
index 0000000..904b2d7
--- /dev/null
+++ b/android/app/src/androidTest/java/io/iden3/backup/ExampleInstrumentedTest.java
@@ -0,0 +1,27 @@
+package io.iden3.backup;
+
+import android.content.Context;
+
+import androidx.test.platform.app.InstrumentationRegistry;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.*;
+
+/**
+ * Instrumented test, which will execute on an Android device.
+ *
+ * @see Testing documentation
+ */
+@RunWith(AndroidJUnit4.class)
+public class ExampleInstrumentedTest {
+ @Test
+ public void useAppContext() {
+ // Context of the app under test.
+ Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
+
+ assertEquals("io.iden3.backup", appContext.getPackageName());
+ }
+}
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..211b947
--- /dev/null
+++ b/android/app/src/main/AndroidManifest.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/app/src/main/java/io/iden3/backup/FirstFragment.java b/android/app/src/main/java/io/iden3/backup/FirstFragment.java
new file mode 100644
index 0000000..8677cec
--- /dev/null
+++ b/android/app/src/main/java/io/iden3/backup/FirstFragment.java
@@ -0,0 +1,34 @@
+package io.iden3.backup;
+
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import androidx.annotation.NonNull;
+import androidx.fragment.app.Fragment;
+import androidx.navigation.fragment.NavHostFragment;
+
+public class FirstFragment extends Fragment {
+
+ @Override
+ public View onCreateView(
+ LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState
+ ) {
+ // Inflate the layout for this fragment
+ return inflater.inflate(R.layout.fragment_first, container, false);
+ }
+
+ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+
+ view.findViewById(R.id.button_first).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ NavHostFragment.findNavController(FirstFragment.this)
+ .navigate(R.id.action_FirstFragment_to_SecondFragment);
+ }
+ });
+ }
+}
diff --git a/android/app/src/main/java/io/iden3/backup/MainActivity.java b/android/app/src/main/java/io/iden3/backup/MainActivity.java
new file mode 100644
index 0000000..1a7d0cd
--- /dev/null
+++ b/android/app/src/main/java/io/iden3/backup/MainActivity.java
@@ -0,0 +1,61 @@
+package io.iden3.backup;
+
+import android.os.Bundle;
+
+import com.google.android.material.floatingactionbutton.FloatingActionButton;
+import com.google.android.material.snackbar.Snackbar;
+
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.appcompat.widget.Toolbar;
+
+import android.view.View;
+import android.view.Menu;
+import android.view.MenuItem;
+import wrapper.*;
+import android.util.Log;
+
+public class MainActivity extends AppCompatActivity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+ Toolbar toolbar = findViewById(R.id.toolbar);
+ setSupportActionBar(toolbar);
+
+ FloatingActionButton fab = findViewById(R.id.fab);
+ fab.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
+ .setAction("Action", null).show();
+ }
+ });
+
+ String kOp = new String(Wrapper.keyOperational());
+
+ Log.d("KOP", kOp);
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.menu_main, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ // Handle action bar item clicks here. The action bar will
+ // automatically handle clicks on the Home/Up button, so long
+ // as you specify a parent activity in AndroidManifest.xml.
+ int id = item.getItemId();
+
+ //noinspection SimplifiableIfStatement
+ if (id == R.id.action_settings) {
+ return true;
+ }
+
+ return super.onOptionsItemSelected(item);
+ }
+}
diff --git a/android/app/src/main/java/io/iden3/backup/SecondFragment.java b/android/app/src/main/java/io/iden3/backup/SecondFragment.java
new file mode 100644
index 0000000..b1a79eb
--- /dev/null
+++ b/android/app/src/main/java/io/iden3/backup/SecondFragment.java
@@ -0,0 +1,34 @@
+package io.iden3.backup;
+
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import androidx.annotation.NonNull;
+import androidx.fragment.app.Fragment;
+import androidx.navigation.fragment.NavHostFragment;
+
+public class SecondFragment extends Fragment {
+
+ @Override
+ public View onCreateView(
+ LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState
+ ) {
+ // Inflate the layout for this fragment
+ return inflater.inflate(R.layout.fragment_second, container, false);
+ }
+
+ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+
+ view.findViewById(R.id.button_second).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ NavHostFragment.findNavController(SecondFragment.this)
+ .navigate(R.id.action_SecondFragment_to_FirstFragment);
+ }
+ });
+ }
+}
diff --git a/android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml
new file mode 100644
index 0000000..2b068d1
--- /dev/null
+++ b/android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/app/src/main/res/drawable/ic_launcher_background.xml b/android/app/src/main/res/drawable/ic_launcher_background.xml
new file mode 100644
index 0000000..07d5da9
--- /dev/null
+++ b/android/app/src/main/res/drawable/ic_launcher_background.xml
@@ -0,0 +1,170 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/android/app/src/main/res/layout/activity_main.xml b/android/app/src/main/res/layout/activity_main.xml
new file mode 100644
index 0000000..e9fa907
--- /dev/null
+++ b/android/app/src/main/res/layout/activity_main.xml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/app/src/main/res/layout/content_main.xml b/android/app/src/main/res/layout/content_main.xml
new file mode 100644
index 0000000..d825cbb
--- /dev/null
+++ b/android/app/src/main/res/layout/content_main.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
diff --git a/android/app/src/main/res/layout/fragment_first.xml b/android/app/src/main/res/layout/fragment_first.xml
new file mode 100644
index 0000000..fb44a3d
--- /dev/null
+++ b/android/app/src/main/res/layout/fragment_first.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/app/src/main/res/layout/fragment_second.xml b/android/app/src/main/res/layout/fragment_second.xml
new file mode 100644
index 0000000..bd90524
--- /dev/null
+++ b/android/app/src/main/res/layout/fragment_second.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/app/src/main/res/menu/menu_main.xml b/android/app/src/main/res/menu/menu_main.xml
new file mode 100644
index 0000000..634e01a
--- /dev/null
+++ b/android/app/src/main/res/menu/menu_main.xml
@@ -0,0 +1,10 @@
+
diff --git a/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
new file mode 100644
index 0000000..eca70cf
--- /dev/null
+++ b/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
new file mode 100644
index 0000000..eca70cf
--- /dev/null
+++ b/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
new file mode 100644
index 0000000..a571e60
Binary files /dev/null and b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ
diff --git a/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
new file mode 100644
index 0000000..61da551
Binary files /dev/null and b/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ
diff --git a/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
new file mode 100644
index 0000000..c41dd28
Binary files /dev/null and b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ
diff --git a/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
new file mode 100644
index 0000000..db5080a
Binary files /dev/null and b/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ
diff --git a/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..6dba46d
Binary files /dev/null and b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ
diff --git a/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
new file mode 100644
index 0000000..da31a87
Binary files /dev/null and b/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ
diff --git a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..15ac681
Binary files /dev/null and b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ
diff --git a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
new file mode 100644
index 0000000..b216f2d
Binary files /dev/null and b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ
diff --git a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
new file mode 100644
index 0000000..f25a419
Binary files /dev/null and b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ
diff --git a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
new file mode 100644
index 0000000..e96783c
Binary files /dev/null and b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ
diff --git a/android/app/src/main/res/navigation/nav_graph.xml b/android/app/src/main/res/navigation/nav_graph.xml
new file mode 100644
index 0000000..e842083
--- /dev/null
+++ b/android/app/src/main/res/navigation/nav_graph.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/android/app/src/main/res/values/colors.xml b/android/app/src/main/res/values/colors.xml
new file mode 100644
index 0000000..030098f
--- /dev/null
+++ b/android/app/src/main/res/values/colors.xml
@@ -0,0 +1,6 @@
+
+
+ #6200EE
+ #3700B3
+ #03DAC5
+
diff --git a/android/app/src/main/res/values/dimens.xml b/android/app/src/main/res/values/dimens.xml
new file mode 100644
index 0000000..59a0b0c
--- /dev/null
+++ b/android/app/src/main/res/values/dimens.xml
@@ -0,0 +1,3 @@
+
+ 16dp
+
diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml
new file mode 100644
index 0000000..5be45f1
--- /dev/null
+++ b/android/app/src/main/res/values/strings.xml
@@ -0,0 +1,12 @@
+
+ Backup
+ Settings
+
+ First Fragment
+ Second Fragment
+ Next
+ Previous
+
+ Hello first fragment
+ Hello second fragment. Arg: %1$s
+
diff --git a/android/app/src/main/res/values/styles.xml b/android/app/src/main/res/values/styles.xml
new file mode 100644
index 0000000..545b9c6
--- /dev/null
+++ b/android/app/src/main/res/values/styles.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/android/app/src/test/java/io/iden3/backup/ExampleUnitTest.java b/android/app/src/test/java/io/iden3/backup/ExampleUnitTest.java
new file mode 100644
index 0000000..d61dca3
--- /dev/null
+++ b/android/app/src/test/java/io/iden3/backup/ExampleUnitTest.java
@@ -0,0 +1,17 @@
+package io.iden3.backup;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Example local unit test, which will execute on the development machine (host).
+ *
+ * @see Testing documentation
+ */
+public class ExampleUnitTest {
+ @Test
+ public void addition_isCorrect() {
+ assertEquals(4, 2 + 2);
+ }
+}
\ No newline at end of file
diff --git a/android/backup/backup.aar b/android/backup/backup.aar
new file mode 100644
index 0000000..1bb3c14
Binary files /dev/null and b/android/backup/backup.aar differ
diff --git a/android/backup/build.gradle b/android/backup/build.gradle
new file mode 100644
index 0000000..1799fd2
--- /dev/null
+++ b/android/backup/build.gradle
@@ -0,0 +1,2 @@
+configurations.maybeCreate("default")
+artifacts.add("default", file('backup.aar'))
\ No newline at end of file
diff --git a/android/build.gradle b/android/build.gradle
new file mode 100644
index 0000000..a88f623
--- /dev/null
+++ b/android/build.gradle
@@ -0,0 +1,29 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+
+buildscript {
+
+ repositories {
+ google()
+ jcenter()
+
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:3.6.3'
+
+
+ // NOTE: Do not place your application dependencies here; they belong
+ // in the individual module build.gradle files
+ }
+}
+
+allprojects {
+ repositories {
+ google()
+ jcenter()
+
+ }
+}
+
+task clean(type: Delete) {
+ delete rootProject.buildDir
+}
diff --git a/android/gradle.properties b/android/gradle.properties
new file mode 100644
index 0000000..199d16e
--- /dev/null
+++ b/android/gradle.properties
@@ -0,0 +1,20 @@
+# Project-wide Gradle settings.
+# IDE (e.g. Android Studio) users:
+# Gradle settings configured through the IDE *will override*
+# any settings specified in this file.
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+org.gradle.jvmargs=-Xmx1536m
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
+# AndroidX package structure to make it clearer which packages are bundled with the
+# Android operating system, and which are packaged with your app's APK
+# https://developer.android.com/topic/libraries/support-library/androidx-rn
+android.useAndroidX=true
+# Automatically convert third-party libraries to use AndroidX
+android.enableJetifier=true
+
diff --git a/android/gradle/wrapper/gradle-wrapper.jar b/android/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..f6b961f
Binary files /dev/null and b/android/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..8c51cba
--- /dev/null
+++ b/android/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Tue May 05 16:17:06 CEST 2020
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
diff --git a/android/gradlew b/android/gradlew
new file mode 100755
index 0000000..cccdd3d
--- /dev/null
+++ b/android/gradlew
@@ -0,0 +1,172 @@
+#!/usr/bin/env sh
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn () {
+ echo "$*"
+}
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+ NONSTOP* )
+ nonstop=true
+ ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+ JAVACMD=`cygpath --unix "$JAVACMD"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Escape application args
+save () {
+ for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
+ echo " "
+}
+APP_ARGS=$(save "$@")
+
+# Collect all arguments for the java command, following the shell quoting and substitution rules
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+
+# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
+if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
+ cd "$(dirname "$0")"
+fi
+
+exec "$JAVACMD" "$@"
diff --git a/android/gradlew.bat b/android/gradlew.bat
new file mode 100644
index 0000000..e95643d
--- /dev/null
+++ b/android/gradlew.bat
@@ -0,0 +1,84 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windows variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/android/settings.gradle b/android/settings.gradle
new file mode 100644
index 0000000..abf2476
--- /dev/null
+++ b/android/settings.gradle
@@ -0,0 +1,2 @@
+rootProject.name='Backup'
+include ':app'
diff --git a/go.mod b/go.mod
index ac0bdc8..3f24f5a 100644
--- a/go.mod
+++ b/go.mod
@@ -7,6 +7,7 @@ require (
github.com/skip2/go-qrcode v0.0.0-20191027152451-9434209cb086
github.com/tuotoo/qrcode v0.0.0-20190222102259-ac9c44189bf2
golang.org/x/crypto v0.0.0-20200414173820-0848c9571904
+ golang.org/x/mobile v0.0.0-20200329125638-4c31acba0007 // indirect
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4
golang.org/x/tools v0.0.0-20200417140056-c07e33ef3290 // indirect
)
diff --git a/go.sum b/go.sum
index 9bd90d9..bdcef9f 100644
--- a/go.sum
+++ b/go.sum
@@ -1,3 +1,4 @@
+github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/uuid v1.1.0 h1:Jf4mxPC/ziBnoPIdpQdPJ9OeiomAUHLvxmPRSPH9m4s=
github.com/google/uuid v1.1.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
@@ -15,11 +16,22 @@ github.com/tuotoo/qrcode v0.0.0-20190222102259-ac9c44189bf2/go.mod h1:lPnW9HVS0v
github.com/yuin/goldmark v1.1.27 h1:nqDD4MMMQA0lmWq03Z2/myGPYLQoXtmi0rGVs95ntbo=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200414173820-0848c9571904 h1:bXoxMPcSLOq08zI3/c5dEBT6lE4eh+jOh886GHrn6V8=
golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
+golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4=
+golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
+golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
+golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
+golang.org/x/mobile v0.0.0-20200329125638-4c31acba0007 h1:JxsyO7zPDWn1rBZW8FV5RFwCKqYeXnyaS/VQPLpXu6I=
+golang.org/x/mobile v0.0.0-20200329125638-4c31acba0007/go.mod h1:skQtrUTUwhdJvXM/2KKJzY8pDgNr9I/FOMqDVRPBUS4=
+golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
+golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
+golang.org/x/mod v0.1.1-0.20191209134235-331c550502dd/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
+golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
@@ -34,7 +46,9 @@ golang.org/x/sys v0.0.0-20200413165638-669c56c373c4 h1:opSr2sbRXk5X5/givKrrKj9HX
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/tools v0.0.0-20200117012304-6edc0a871e69/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200417140056-c07e33ef3290 h1:NXNmtp0ToD36cui5IqWy95LC4Y6vT/4y3RnPxlQPinU=
golang.org/x/tools v0.0.0-20200417140056-c07e33ef3290/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
diff --git a/wrapper/corelibs.go b/wrapper/corelibs.go
new file mode 100644
index 0000000..9784343
--- /dev/null
+++ b/wrapper/corelibs.go
@@ -0,0 +1,61 @@
+/*
+ Collection of support functions that emulate go-iden3-core functionality
+*/
+package wrapper
+
+import (
+ "github.com/iden3/go-backup/ff"
+)
+
+// Auxiliary information emulating claims, ZKP and Merkle Tree (these types are defined
+// somewhere in core library)
+// Strcuture and contents are not important. Just deinfing some arbitrary data structures
+// to do backup
+type Claim struct {
+ Data [N_ELEMENTS]uint64
+}
+
+type ZKP struct {
+ R *Claim
+ L *WalletConfig
+}
+
+type MT struct {
+ Y [N_ELEMENTS]*Claim
+}
+
+var claims *Claim
+var zKPData *ZKP
+var merkleTree *MT
+
+// Generate Key
+func KeyOperational() []byte {
+ key, _ := ff.NewElement(PRIME)
+ key.SetRandom().ToMont()
+
+ return key.ToByte()
+}
+
+// Generate Genesis ID
+func NewID() []byte {
+ id, err := genRandomBytes(ID_LEN)
+ if err != nil {
+ panic(err)
+ }
+ return id
+}
+
+// Retrieve MerkleTree
+func GetMerkleTreeSnapshot() *MT {
+ return merkleTree
+}
+
+// Retrieve claims (received, not part form Merkle Tree)
+func GetRxClaims() *Claim {
+ return claims
+}
+
+// Retrieve generated ZKP
+func GetZKP() *ZKP {
+ return zKPData
+}
diff --git a/wrapper/utils.go b/wrapper/utils.go
new file mode 100644
index 0000000..70aded2
--- /dev/null
+++ b/wrapper/utils.go
@@ -0,0 +1,599 @@
+/* Aux functions to initialize claim, mk, zkp wallet config data.
+* It also includes very simplified functionality from other modules that should be part of backup package
+ but are still not implemented, like custodians, ....
+
+*/
+
+package wrapper
+
+import (
+ "bufio"
+ "bytes"
+ crand "crypto/rand"
+ "encoding/gob"
+ "errors"
+ "image"
+ _ "image/jpeg"
+ _ "image/png"
+ "io"
+ "io/ioutil"
+ "math/rand"
+ "os"
+ "path/filepath"
+ "reflect"
+
+ "github.com/iden3/go-backup/ff"
+ fc "github.com/iden3/go-backup/filecrypt"
+ "github.com/iden3/go-backup/secret"
+ qrdec "github.com/liyue201/goqr"
+ qrgen "github.com/skip2/go-qrcode"
+)
+
+// Configuration constants
+const (
+ N_ELEMENTS = 1000
+ ID_LEN = 31
+ MIN_N_SHARES = 4
+ MAX_N_SHARES = 10
+ PRIME = ff.FF_BN256_PRIME
+ BACKUP_DIR = "./testdata/"
+ BACKUP_FILE = "backup.bk"
+ QR_DIR = "./testdata/"
+ PBKDF2_NITER = 60000
+ PBKDF2_SALTLEN = 12
+)
+
+var wallet *WalletConfig
+
+// Auxiliary information emulating Wallet Config
+// Struxture and contents are not important. Just deinfing some arbitrary data structures
+// to do backup
+type WalletConfig struct {
+ Config map[string][]byte
+}
+
+// Dummy data init functions
+func initClaims() *Claim {
+ var test_data Claim
+ for i := 0; i < N_ELEMENTS; i++ {
+ test_data.Data[i] = uint64(rand.Intn(1234567)) //1234567123453
+ }
+ return &test_data
+}
+
+const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
+
+func randStringBytes(n int) string {
+ b := make([]byte, n)
+ for i := range b {
+ b[i] = letterBytes[rand.Intn(len(letterBytes))]
+ }
+ return string(b)
+}
+
+func initWalletConfig() *WalletConfig {
+ var data WalletConfig
+ data.Config = make(map[string][]byte)
+ for i := 0; i < N_ELEMENTS; i++ {
+ st := randStringBytes(13)
+ data.Config[st], _ = genRandomBytes((i % 14) + 1)
+ }
+ return &data
+}
+
+func initZKP() *ZKP {
+ var zkp ZKP
+ zkp.R = initClaims()
+ zkp.L = initWalletConfig()
+
+ return &zkp
+}
+
+func initMerkleTree() *MT {
+ var mt MT
+ for i := 0; i < N_ELEMENTS; i++ {
+ mt.Y[i] = initClaims()
+ }
+
+ return &mt
+}
+
+///// Secret Sharing Wrapper
+// Utility functions to convert between types.
+// secret sharing package needs to be improved to
+// support more convenient data types and avoid so much conversion
+
+var secret_cfg secret.Shamir
+
+// Generate shares from secret
+func GenerateShares(secret []byte) []secret.Share {
+ // convert secret to right format
+ secret_ff, _ := ff.NewElement(PRIME)
+ secret_ff.FromByte(secret)
+ new_shares, _ := secret_cfg.GenerateShares(secret_ff)
+
+ return new_shares
+
+}
+
+// Generate secret from shares
+func GenerateKey(shares []secret.Share, sharing_cfg secret.SecretSharer) []byte {
+ shares_pool := make([]secret.Share, 0)
+ for _, share := range shares {
+ shares_pool = append(shares_pool, share)
+ if len(shares_pool) == sharing_cfg.GetMinShares() {
+ break
+ }
+ }
+ secret, err := sharing_cfg.GenerateSecret(shares_pool)
+ if err != nil {
+ panic(err)
+ }
+
+ return secret.ToByte()
+}
+
+//////
+// Custodian
+
+// Simplified custodian version. Holds nickname and number of keys stored. We keep a copy
+// of Custodian in backup so that we remember to whom we distributed key shares and can reclaim
+// them later on.
+
+// Attempts to emulate how we could exchage shares. QR and NONE the only one working in this demo
+const (
+ EMAIL = iota
+ PHONE
+ TELEGRAM
+ QR // Generate QR
+ NONE // send raw data directly
+)
+
+type Custodian struct {
+ Nickname string
+ N_shares int // number of shares provided
+ Fname string
+}
+
+var custodians []Custodian
+
+// Add new Custodian and simulate the distribution of N shares
+func AddCustodian(nickname string, method int, shares []secret.Share, start_idx, nshares int) error {
+ // add info to custodian
+ new_custodian := Custodian{
+ Nickname: nickname,
+ N_shares: nshares,
+ }
+
+ // encode share information to stream of bytes.
+ shares_array := make([]secret.Share, 0)
+ shares_array = append(shares_array, shares[start_idx:start_idx+nshares]...)
+
+ // generate QR
+ if method == QR {
+ share_string := encodeShareToString(shares_array)
+ qrfile := QR_DIR + "qr-" + nickname + ".png"
+ new_custodian.Fname = qrfile
+ err := qrgen.WriteFile(share_string, qrgen.High, 256, qrfile)
+ if err == nil {
+ custodians = append(custodians, new_custodian)
+ }
+ return err
+
+ // generate Raw data
+ } else if method == NONE {
+ share_bytes := encodeShareToByte(shares_array)
+ fname := QR_DIR + "byte-" + nickname + ".dat"
+ new_custodian.Fname = fname
+ file, _ := os.Create(fname)
+ file.Write(share_bytes)
+ file.Close()
+ custodians = append(custodians, new_custodian)
+ return nil
+
+ } else {
+ return errors.New("Invalid Method to distriburt Shares")
+ }
+}
+
+// Decode QR that includes a share, and return it a slice of maps with the index and the share
+func ScanQRShare(cust *Custodian) []secret.Share {
+ var tmp_fname string
+ if filepath.Ext(cust.Fname) == ".png" {
+ tmp_fname = QR_DIR + "tmp_f"
+ imgdata, err := ioutil.ReadFile(cust.Fname)
+ if err != nil {
+ panic(err)
+ }
+
+ img, _, err := image.Decode(bytes.NewReader(imgdata))
+ if err != nil {
+ panic(err)
+ }
+ qrCodes, err := qrdec.Recognize(img)
+ if err != nil {
+ panic(err)
+ }
+ file, err := os.Create(tmp_fname)
+ if err != nil {
+ panic(err)
+ }
+ file.Write(qrCodes[0].Payload)
+ file.Close()
+
+ } else {
+ tmp_fname = cust.Fname
+ }
+
+ // tmp_fname is a file including the encoded share.
+ qrinfo := Decode(tmp_fname, nil)
+
+ share := RetrieveShares(qrinfo)
+ return share
+}
+
+///// Encoding Layer
+
+// Types of data we can include in the backup. Needed to register the data strcuture
+const (
+ CLAIMS = iota
+ WALLET_CONFIG
+ ZKP_INFO
+ MERKLE_TREE
+ CUSTODIAN
+ GENID
+ SSHARING
+ SHARES
+ // Add other possible data types that we need encoding
+)
+
+// Register data strucrure
+func encodeType(dtype int) {
+ switch dtype {
+ case CLAIMS:
+ gob.Register(&Claim{})
+
+ case WALLET_CONFIG:
+ gob.Register(&WalletConfig{})
+
+ case ZKP_INFO:
+ gob.Register(&ZKP{})
+
+ case MERKLE_TREE:
+ gob.Register(&MT{})
+
+ case CUSTODIAN:
+ gob.Register(&Custodian{})
+ var el []Custodian
+ gob.Register(el)
+
+ case GENID:
+ var el []byte
+ gob.Register(el)
+
+ case SSHARING:
+ gob.Register(&secret.Shamir{})
+
+ case SHARES:
+ el1, _ := ff.NewElement(PRIME)
+ var el2 secret.Share
+ var el3 []secret.Share
+ gob.Register(el1)
+ gob.Register(el2)
+ gob.Register(el3)
+ }
+}
+
+// Transform share encoding to string
+func encodeShareToString(shares []secret.Share) string {
+ tmp_fname := QR_DIR + "share-tmp.dat"
+ encodeShare(shares)
+ defer os.Remove(tmp_fname)
+
+ // Read file with share as as a bytestream and convert it to string
+ share_bytes, err := ioutil.ReadFile(tmp_fname)
+ if err != nil {
+ panic(err)
+ }
+ share_string := string(share_bytes)
+
+ return share_string
+}
+
+// Transform share encoding to []byte
+func encodeShareToByte(shares []secret.Share) []byte {
+ tmp_fname := QR_DIR + "share-tmp.dat"
+ encodeShare(shares)
+ defer os.Remove(tmp_fname)
+ data := readBinaryFile(tmp_fname)
+
+ return data
+}
+
+// Read file
+func readBinaryFile(tmp_fname string) []byte {
+ file, err := os.Open(tmp_fname)
+ defer file.Close()
+
+ if err != nil {
+ panic(err)
+ }
+
+ stats, err := file.Stat()
+ if err != nil {
+ panic(err)
+ }
+
+ var size int64 = stats.Size()
+ bytes := make([]byte, size)
+
+ bufr := bufio.NewReader(file)
+ _, err = bufr.Read(bytes)
+
+ return bytes
+}
+
+// Generate share blocks to distribure via secret sharing and return
+// filecrpyt bytestream
+func encodeShare(shares []secret.Share) {
+ encodeType(SHARES)
+
+ // Key header -> no key
+ hdr_k := &fc.NoKeyFc{}
+ err := hdr_k.FillHdr(fc.FC_HDR_VERSION_1, fc.FC_KEY_T_NOKEY)
+ if err != nil {
+ panic(err)
+ }
+ // Encryption header -> not encrypted
+ hdr_e := &fc.ClearFc{}
+ err = hdr_e.FillHdr(fc.FC_HDR_VERSION_1, fc.FC_CLEAR,
+ fc.FC_BSIZE_BYTES_256, fc.FC_HDR_BIDX_SINGLE)
+ if err != nil {
+ panic(err)
+ }
+ // filecrypt only outputs a file. At some point, functionality should be extended
+ // to also generate a string
+ tmp_fname := QR_DIR + "share-tmp.dat"
+
+ err = fc.Encrypt(hdr_k, hdr_e, tmp_fname, shares)
+ if err != nil {
+ panic(err)
+ }
+}
+
+// Decode and decrypt file using provided key
+func Decode(fname string, key []byte) []interface{} {
+ results, _ := fc.Decrypt(fname, key)
+ return results
+}
+
+// Retrieve functions return a specific data type from a generic type
+
+// retrieve Custodian data structure
+func RetrieveCustodians(info []interface{}) []Custodian {
+ var r []Custodian
+ for _, el := range info {
+ switch el.(type) {
+ case []Custodian:
+ r = el.([]Custodian)
+ return r
+ }
+ }
+ return nil
+}
+
+// retrieve Secret Sharing config data structure
+func RetrieveSSharing(info []interface{}) secret.SecretSharer {
+ var r secret.SecretSharer
+ for _, el := range info {
+ switch el.(type) {
+ case *secret.Shamir:
+ r = el.(*secret.Shamir)
+ return r
+ }
+ }
+ return nil
+}
+
+// Retrieve Genesis ID
+func RetrieveID(info []interface{}) []byte {
+ var r []byte
+ for _, el := range info {
+ switch el.(type) {
+ case []byte:
+ r = el.([]byte)
+ return r
+ }
+ }
+ return nil
+
+}
+
+// Retrieve Claim data structure
+func RetrieveClaims(info []interface{}) *Claim {
+ var r *Claim
+ for _, el := range info {
+ switch el.(type) {
+ case *Claim:
+ r = el.(*Claim)
+ return r
+ }
+ }
+ return nil
+}
+
+// Retreive wallet config
+func RetrieveWallet(info []interface{}) *WalletConfig {
+ var r *WalletConfig
+ for _, el := range info {
+ switch el.(type) {
+ case *WalletConfig:
+ r = el.(*WalletConfig)
+ return r
+ }
+ }
+ return nil
+}
+
+// retreive ZKP data
+func RetrieveZKP(info []interface{}) *ZKP {
+ var r *ZKP
+ for _, el := range info {
+ switch el.(type) {
+ case *ZKP:
+ r = el.(*ZKP)
+ return r
+ }
+ }
+ return nil
+}
+
+// Retrieve MT data structure
+func RetrieveMT(info []interface{}) *MT {
+ var r *MT
+ for _, el := range info {
+ switch el.(type) {
+ case *MT:
+ r = el.(*MT)
+ return r
+ }
+ }
+ return nil
+}
+
+// Retrieve shares data structure
+func RetrieveShares(info []interface{}) []secret.Share {
+ r := make([]secret.Share, 0)
+ for _, el := range info {
+ switch el.(type) {
+ case []secret.Share:
+ r = el.([]secret.Share)
+ return r
+ case secret.Share:
+ r = append(r, el.(secret.Share))
+ return r
+ }
+ }
+ return nil
+}
+
+// Backup layer
+///// Backup Layer
+
+const (
+ ENCRYPT = iota
+ DONT_ENCRYPT
+)
+
+type Backup struct {
+ data interface{}
+ mode int
+}
+
+// Summary of contents of backup file
+var backup_registry map[int]Backup
+
+// Record and register backup data structures
+func AddToBackup(t int, d interface{}, action int) {
+ // check for duplicates
+ for idx, _ := range backup_registry {
+ if idx == t {
+ return
+ }
+ }
+ // encode type
+ encodeType(t)
+
+ // Add to backup registry
+ backup_el := Backup{data: d,
+ mode: action,
+ }
+ backup_registry[t] = backup_el
+}
+
+// Generate backup file
+func CreateBackup(key_t, hash_t, enc_t int, fname string, key []byte) {
+ // Add Key -> for now, only PBKDF2 + GCM supported, but it can be expanded easily
+ // Assume fixed PBKDF2 config. Header shared for both encrypted and non encrpyted blocks
+ hdr_k := &fc.Pbkdf2Fc{}
+ err := hdr_k.FillHdr(fc.FC_HDR_VERSION_1, key_t, hash_t,
+ PBKDF2_NITER, fc.FC_BSIZE_BYTES_256, PBKDF2_SALTLEN, key)
+ if err != nil {
+ panic(err)
+ }
+
+ n_blocks := len(backup_registry)
+ var block_idx, bctr = 0, 0
+
+ // There are two types of blcks defined for now:
+ // Encrypted -> PBKDF2 Key Header + GCM Enc Header
+ // Not Encrypted -> PBKDF2 Key HEader + ClearFC Enc Header
+ for _, el := range backup_registry {
+ // Check block index
+ if n_blocks == 1 {
+ block_idx = fc.FC_HDR_BIDX_SINGLE
+ } else if n_blocks == bctr+1 {
+ block_idx = fc.FC_HDR_BIDX_LAST
+ } else if bctr == 0 {
+ block_idx = fc.FC_HDR_BIDX_FIRST
+ } else {
+ block_idx = fc.FC_HDR_BIDX_MID
+ }
+
+ // Add Enc Header
+ if el.mode == DONT_ENCRYPT {
+ hdr_ne := &fc.ClearFc{}
+ err = hdr_ne.FillHdr(fc.FC_HDR_VERSION_1, fc.FC_CLEAR, fc.FC_BSIZE_BYTES_256, block_idx)
+ err = fc.Encrypt(hdr_k, hdr_ne, BACKUP_DIR+BACKUP_FILE, el.data)
+ } else if el.mode == ENCRYPT {
+ hdr_gcm := &fc.GcmFc{}
+ err = hdr_gcm.FillHdr(fc.FC_HDR_VERSION_1, fc.FC_GCM, fc.FC_BSIZE_BYTES_256, block_idx)
+ err = fc.Encrypt(hdr_k, hdr_gcm, BACKUP_DIR+BACKUP_FILE, el.data)
+ }
+ if err != nil {
+ panic(err)
+ }
+ bctr += 1
+ }
+}
+
+///// Aux
+// Generate N random bytes.
+func genRandomBytes(noncesize int) ([]byte, error) {
+ nonce := make([]byte, noncesize)
+ if _, err := io.ReadFull(crand.Reader, nonce); err != nil {
+ return nil, err
+ }
+ return nonce, nil
+}
+
+////
+func init() {
+ //init aux data
+ claims = initClaims()
+ wallet = initWalletConfig()
+ zKPData = initZKP()
+ merkleTree = initMerkleTree()
+
+ // init Secret Sharing
+ err := secret_cfg.NewConfig(MIN_N_SHARES, MAX_N_SHARES, PRIME)
+ if err != nil {
+ panic(err)
+ }
+ backup_registry = make(map[int]Backup)
+
+}
+
+func CheckEqual(expected, obtained interface{}) bool {
+ flag := false
+
+ switch obtained.(type) {
+ case []map[uint64]ff.Element:
+ o := obtained.([]map[uint64]ff.Element)
+ flag = reflect.DeepEqual(expected, o[0])
+
+ default:
+ flag = reflect.DeepEqual(expected, obtained)
+ }
+ return flag
+}