@solana-mobile/seed-vault-lib 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +13 -0
- package/README.md +3 -0
- package/android/build.gradle +150 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/android/gradle.properties +5 -0
- package/android/gradlew +185 -0
- package/android/gradlew.bat +89 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/com/solanamobile/seedvault/model/SigningRequest.kt +43 -0
- package/android/src/main/java/com/solanamobile/seedvault/reactnative/Extensions.kt +18 -0
- package/android/src/main/java/com/solanamobile/seedvault/reactnative/SeedVaultLibReactNativePackage.kt +16 -0
- package/android/src/main/java/com/solanamobile/seedvault/reactnative/SolanaMobileSeedVaultLibModule.kt +392 -0
- package/lib/esm/index.native.js +108 -0
- package/lib/esm/package.json +3 -0
- package/lib/types/index.native.d.ts +87 -0
- package/lib/types/index.native.d.ts.map +1 -0
- package/package.json +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2022 Solana Mobile Inc.
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
|
|
3
|
+
def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['SolanaMobileSeedVaultLibModule_kotlinVersion']
|
|
4
|
+
|
|
5
|
+
repositories {
|
|
6
|
+
google()
|
|
7
|
+
mavenCentral()
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
dependencies {
|
|
11
|
+
classpath 'com.android.tools.build:gradle:7.4.2'
|
|
12
|
+
// noinspection DifferentKotlinGradleVersion
|
|
13
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
14
|
+
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
def isNewArchitectureEnabled() {
|
|
19
|
+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
apply plugin: 'com.android.library'
|
|
23
|
+
apply plugin: 'kotlin-android'
|
|
24
|
+
apply plugin: 'kotlinx-serialization'
|
|
25
|
+
|
|
26
|
+
if (isNewArchitectureEnabled()) {
|
|
27
|
+
apply plugin: 'com.facebook.react'
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
def getExtOrDefault(name) {
|
|
31
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['SolanaMobileSeedVaultLibModule_' + name]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
def getExtOrIntegerDefault(name) {
|
|
35
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['SolanaMobileSeedVaultLibModule_' + name]).toInteger()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
android {
|
|
39
|
+
namespace "com.solanamobile.seedvault.reactnative"
|
|
40
|
+
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
|
|
41
|
+
|
|
42
|
+
defaultConfig {
|
|
43
|
+
minSdkVersion getExtOrIntegerDefault('minSdkVersion')
|
|
44
|
+
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
|
|
45
|
+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
46
|
+
}
|
|
47
|
+
buildTypes {
|
|
48
|
+
release {
|
|
49
|
+
minifyEnabled false
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
lintOptions {
|
|
54
|
+
disable 'GradleCompatible'
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
compileOptions {
|
|
58
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
59
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
repositories {
|
|
64
|
+
mavenCentral()
|
|
65
|
+
google()
|
|
66
|
+
|
|
67
|
+
def found = false
|
|
68
|
+
def defaultDir = null
|
|
69
|
+
def androidSourcesName = 'React Native sources'
|
|
70
|
+
|
|
71
|
+
if (rootProject.ext.has('reactNativeAndroidRoot')) {
|
|
72
|
+
defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
|
|
73
|
+
} else {
|
|
74
|
+
defaultDir = new File(
|
|
75
|
+
projectDir,
|
|
76
|
+
'/../../../node_modules/react-native/android'
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (defaultDir.exists()) {
|
|
81
|
+
maven {
|
|
82
|
+
url defaultDir.toString()
|
|
83
|
+
name androidSourcesName
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
|
|
87
|
+
found = true
|
|
88
|
+
} else {
|
|
89
|
+
def parentDir = rootProject.projectDir
|
|
90
|
+
|
|
91
|
+
1.upto(5, {
|
|
92
|
+
if (found) return true
|
|
93
|
+
parentDir = parentDir.parentFile
|
|
94
|
+
|
|
95
|
+
def androidSourcesDir = new File(
|
|
96
|
+
parentDir,
|
|
97
|
+
'node_modules/react-native'
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
def androidPrebuiltBinaryDir = new File(
|
|
101
|
+
parentDir,
|
|
102
|
+
'node_modules/react-native/android'
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
if (androidPrebuiltBinaryDir.exists()) {
|
|
106
|
+
maven {
|
|
107
|
+
url androidPrebuiltBinaryDir.toString()
|
|
108
|
+
name androidSourcesName
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
|
|
112
|
+
found = true
|
|
113
|
+
} else if (androidSourcesDir.exists()) {
|
|
114
|
+
maven {
|
|
115
|
+
url androidSourcesDir.toString()
|
|
116
|
+
name androidSourcesName
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
|
|
120
|
+
found = true
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (!found) {
|
|
126
|
+
throw new GradleException(
|
|
127
|
+
"${project.name}: unable to locate React Native android sources. " +
|
|
128
|
+
"Ensure you have you installed React Native as a dependency in your project and try again."
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
def kotlin_version = getExtOrDefault('kotlinVersion')
|
|
134
|
+
|
|
135
|
+
dependencies {
|
|
136
|
+
//noinspection GradleDynamicVersion
|
|
137
|
+
implementation "com.facebook.react:react-native:+" // From node_modules
|
|
138
|
+
implementation 'com.solanamobile:seedvault-wallet-sdk:0.2.8'
|
|
139
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
140
|
+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4"
|
|
141
|
+
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1"
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (isNewArchitectureEnabled()) {
|
|
145
|
+
react {
|
|
146
|
+
jsRootDir = file("../src/")
|
|
147
|
+
libraryName = "SolanaMobileWSeedVaultLibModule"
|
|
148
|
+
codegenJavaPackageName = "com.solanamobile.SeedVault.reactnative"
|
|
149
|
+
}
|
|
150
|
+
}
|
|
Binary file
|
package/android/gradlew
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
#!/usr/bin/env sh
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
# Copyright 2015 the original author or authors.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
|
|
19
|
+
##############################################################################
|
|
20
|
+
##
|
|
21
|
+
## Gradle start up script for UN*X
|
|
22
|
+
##
|
|
23
|
+
##############################################################################
|
|
24
|
+
|
|
25
|
+
# Attempt to set APP_HOME
|
|
26
|
+
# Resolve links: $0 may be a link
|
|
27
|
+
PRG="$0"
|
|
28
|
+
# Need this for relative symlinks.
|
|
29
|
+
while [ -h "$PRG" ] ; do
|
|
30
|
+
ls=`ls -ld "$PRG"`
|
|
31
|
+
link=`expr "$ls" : '.*-> \(.*\)$'`
|
|
32
|
+
if expr "$link" : '/.*' > /dev/null; then
|
|
33
|
+
PRG="$link"
|
|
34
|
+
else
|
|
35
|
+
PRG=`dirname "$PRG"`"/$link"
|
|
36
|
+
fi
|
|
37
|
+
done
|
|
38
|
+
SAVED="`pwd`"
|
|
39
|
+
cd "`dirname \"$PRG\"`/" >/dev/null
|
|
40
|
+
APP_HOME="`pwd -P`"
|
|
41
|
+
cd "$SAVED" >/dev/null
|
|
42
|
+
|
|
43
|
+
APP_NAME="Gradle"
|
|
44
|
+
APP_BASE_NAME=`basename "$0"`
|
|
45
|
+
|
|
46
|
+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
47
|
+
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
|
48
|
+
|
|
49
|
+
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
|
50
|
+
MAX_FD="maximum"
|
|
51
|
+
|
|
52
|
+
warn () {
|
|
53
|
+
echo "$*"
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
die () {
|
|
57
|
+
echo
|
|
58
|
+
echo "$*"
|
|
59
|
+
echo
|
|
60
|
+
exit 1
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
# OS specific support (must be 'true' or 'false').
|
|
64
|
+
cygwin=false
|
|
65
|
+
msys=false
|
|
66
|
+
darwin=false
|
|
67
|
+
nonstop=false
|
|
68
|
+
case "`uname`" in
|
|
69
|
+
CYGWIN* )
|
|
70
|
+
cygwin=true
|
|
71
|
+
;;
|
|
72
|
+
Darwin* )
|
|
73
|
+
darwin=true
|
|
74
|
+
;;
|
|
75
|
+
MSYS* | MINGW* )
|
|
76
|
+
msys=true
|
|
77
|
+
;;
|
|
78
|
+
NONSTOP* )
|
|
79
|
+
nonstop=true
|
|
80
|
+
;;
|
|
81
|
+
esac
|
|
82
|
+
|
|
83
|
+
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
# Determine the Java command to use to start the JVM.
|
|
87
|
+
if [ -n "$JAVA_HOME" ] ; then
|
|
88
|
+
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
|
89
|
+
# IBM's JDK on AIX uses strange locations for the executables
|
|
90
|
+
JAVACMD="$JAVA_HOME/jre/sh/java"
|
|
91
|
+
else
|
|
92
|
+
JAVACMD="$JAVA_HOME/bin/java"
|
|
93
|
+
fi
|
|
94
|
+
if [ ! -x "$JAVACMD" ] ; then
|
|
95
|
+
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
|
96
|
+
|
|
97
|
+
Please set the JAVA_HOME variable in your environment to match the
|
|
98
|
+
location of your Java installation."
|
|
99
|
+
fi
|
|
100
|
+
else
|
|
101
|
+
JAVACMD="java"
|
|
102
|
+
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
103
|
+
|
|
104
|
+
Please set the JAVA_HOME variable in your environment to match the
|
|
105
|
+
location of your Java installation."
|
|
106
|
+
fi
|
|
107
|
+
|
|
108
|
+
# Increase the maximum file descriptors if we can.
|
|
109
|
+
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
|
110
|
+
MAX_FD_LIMIT=`ulimit -H -n`
|
|
111
|
+
if [ $? -eq 0 ] ; then
|
|
112
|
+
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
|
113
|
+
MAX_FD="$MAX_FD_LIMIT"
|
|
114
|
+
fi
|
|
115
|
+
ulimit -n $MAX_FD
|
|
116
|
+
if [ $? -ne 0 ] ; then
|
|
117
|
+
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
|
118
|
+
fi
|
|
119
|
+
else
|
|
120
|
+
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
|
121
|
+
fi
|
|
122
|
+
fi
|
|
123
|
+
|
|
124
|
+
# For Darwin, add options to specify how the application appears in the dock
|
|
125
|
+
if $darwin; then
|
|
126
|
+
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
|
127
|
+
fi
|
|
128
|
+
|
|
129
|
+
# For Cygwin or MSYS, switch paths to Windows format before running java
|
|
130
|
+
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
|
131
|
+
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
|
132
|
+
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
|
133
|
+
|
|
134
|
+
JAVACMD=`cygpath --unix "$JAVACMD"`
|
|
135
|
+
|
|
136
|
+
# We build the pattern for arguments to be converted via cygpath
|
|
137
|
+
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
|
138
|
+
SEP=""
|
|
139
|
+
for dir in $ROOTDIRSRAW ; do
|
|
140
|
+
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
|
141
|
+
SEP="|"
|
|
142
|
+
done
|
|
143
|
+
OURCYGPATTERN="(^($ROOTDIRS))"
|
|
144
|
+
# Add a user-defined pattern to the cygpath arguments
|
|
145
|
+
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
|
146
|
+
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
|
147
|
+
fi
|
|
148
|
+
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
|
149
|
+
i=0
|
|
150
|
+
for arg in "$@" ; do
|
|
151
|
+
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
|
152
|
+
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
|
153
|
+
|
|
154
|
+
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
|
155
|
+
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
|
156
|
+
else
|
|
157
|
+
eval `echo args$i`="\"$arg\""
|
|
158
|
+
fi
|
|
159
|
+
i=`expr $i + 1`
|
|
160
|
+
done
|
|
161
|
+
case $i in
|
|
162
|
+
0) set -- ;;
|
|
163
|
+
1) set -- "$args0" ;;
|
|
164
|
+
2) set -- "$args0" "$args1" ;;
|
|
165
|
+
3) set -- "$args0" "$args1" "$args2" ;;
|
|
166
|
+
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
|
167
|
+
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
|
168
|
+
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
|
169
|
+
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
|
170
|
+
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
|
171
|
+
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
|
172
|
+
esac
|
|
173
|
+
fi
|
|
174
|
+
|
|
175
|
+
# Escape application args
|
|
176
|
+
save () {
|
|
177
|
+
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
|
178
|
+
echo " "
|
|
179
|
+
}
|
|
180
|
+
APP_ARGS=`save "$@"`
|
|
181
|
+
|
|
182
|
+
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
|
183
|
+
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
|
184
|
+
|
|
185
|
+
exec "$JAVACMD" "$@"
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
@rem
|
|
2
|
+
@rem Copyright 2015 the original author or authors.
|
|
3
|
+
@rem
|
|
4
|
+
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
@rem you may not use this file except in compliance with the License.
|
|
6
|
+
@rem You may obtain a copy of the License at
|
|
7
|
+
@rem
|
|
8
|
+
@rem https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
@rem
|
|
10
|
+
@rem Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
@rem See the License for the specific language governing permissions and
|
|
14
|
+
@rem limitations under the License.
|
|
15
|
+
@rem
|
|
16
|
+
|
|
17
|
+
@if "%DEBUG%" == "" @echo off
|
|
18
|
+
@rem ##########################################################################
|
|
19
|
+
@rem
|
|
20
|
+
@rem Gradle startup script for Windows
|
|
21
|
+
@rem
|
|
22
|
+
@rem ##########################################################################
|
|
23
|
+
|
|
24
|
+
@rem Set local scope for the variables with windows NT shell
|
|
25
|
+
if "%OS%"=="Windows_NT" setlocal
|
|
26
|
+
|
|
27
|
+
set DIRNAME=%~dp0
|
|
28
|
+
if "%DIRNAME%" == "" set DIRNAME=.
|
|
29
|
+
set APP_BASE_NAME=%~n0
|
|
30
|
+
set APP_HOME=%DIRNAME%
|
|
31
|
+
|
|
32
|
+
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
|
33
|
+
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
|
34
|
+
|
|
35
|
+
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
36
|
+
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
|
37
|
+
|
|
38
|
+
@rem Find java.exe
|
|
39
|
+
if defined JAVA_HOME goto findJavaFromJavaHome
|
|
40
|
+
|
|
41
|
+
set JAVA_EXE=java.exe
|
|
42
|
+
%JAVA_EXE% -version >NUL 2>&1
|
|
43
|
+
if "%ERRORLEVEL%" == "0" goto execute
|
|
44
|
+
|
|
45
|
+
echo.
|
|
46
|
+
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
47
|
+
echo.
|
|
48
|
+
echo Please set the JAVA_HOME variable in your environment to match the
|
|
49
|
+
echo location of your Java installation.
|
|
50
|
+
|
|
51
|
+
goto fail
|
|
52
|
+
|
|
53
|
+
:findJavaFromJavaHome
|
|
54
|
+
set JAVA_HOME=%JAVA_HOME:"=%
|
|
55
|
+
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
|
56
|
+
|
|
57
|
+
if exist "%JAVA_EXE%" goto execute
|
|
58
|
+
|
|
59
|
+
echo.
|
|
60
|
+
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
|
61
|
+
echo.
|
|
62
|
+
echo Please set the JAVA_HOME variable in your environment to match the
|
|
63
|
+
echo location of your Java installation.
|
|
64
|
+
|
|
65
|
+
goto fail
|
|
66
|
+
|
|
67
|
+
:execute
|
|
68
|
+
@rem Setup the command line
|
|
69
|
+
|
|
70
|
+
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@rem Execute Gradle
|
|
74
|
+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
|
75
|
+
|
|
76
|
+
:end
|
|
77
|
+
@rem End local scope for the variables with windows NT shell
|
|
78
|
+
if "%ERRORLEVEL%"=="0" goto mainEnd
|
|
79
|
+
|
|
80
|
+
:fail
|
|
81
|
+
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
|
82
|
+
rem the _cmd.exe /c_ return code!
|
|
83
|
+
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
|
84
|
+
exit /b 1
|
|
85
|
+
|
|
86
|
+
:mainEnd
|
|
87
|
+
if "%OS%"=="Windows_NT" endlocal
|
|
88
|
+
|
|
89
|
+
:omega
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"/>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
package com.solanamobile.seedvault.model
|
|
2
|
+
|
|
3
|
+
import android.net.Uri
|
|
4
|
+
import com.solanamobile.seedvault.SigningRequest
|
|
5
|
+
import kotlinx.serialization.KSerializer
|
|
6
|
+
import kotlinx.serialization.Serializable
|
|
7
|
+
import kotlinx.serialization.builtins.serializer
|
|
8
|
+
import kotlinx.serialization.descriptors.SerialDescriptor
|
|
9
|
+
import kotlinx.serialization.encoding.Decoder
|
|
10
|
+
import kotlinx.serialization.encoding.Encoder
|
|
11
|
+
|
|
12
|
+
@Serializable
|
|
13
|
+
data class SigningRequestSurrogate(
|
|
14
|
+
val payload: ByteArray,
|
|
15
|
+
val requestedSignatures: List<@Serializable(with = UriAsStringSerializer::class) Uri>
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
object SigningRequestSerializer : KSerializer<SigningRequest> {
|
|
19
|
+
override val descriptor: SerialDescriptor = SigningRequestSurrogate.serializer().descriptor
|
|
20
|
+
|
|
21
|
+
override fun serialize(encoder: Encoder, value: SigningRequest) {
|
|
22
|
+
encoder.encodeSerializableValue(SigningRequestSurrogate.serializer(),
|
|
23
|
+
SigningRequestSurrogate(value.payload, value.requestedSignatures)
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
override fun deserialize(decoder: Decoder): SigningRequest =
|
|
28
|
+
decoder.decodeSerializableValue(SigningRequestSurrogate.serializer()).let {
|
|
29
|
+
SigningRequest(it.payload, ArrayList(it.requestedSignatures))
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
object UriAsStringSerializer : KSerializer<Uri> {
|
|
34
|
+
override val descriptor: SerialDescriptor
|
|
35
|
+
get() = String.serializer().descriptor
|
|
36
|
+
|
|
37
|
+
override fun serialize(encoder: Encoder, value: Uri) {
|
|
38
|
+
encoder.encodeString(value.toString())
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
override fun deserialize(decoder: Decoder): Uri =
|
|
42
|
+
Uri.parse(decoder.decodeString())
|
|
43
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
package com.solanamobile.seedvault.reactnative
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.*
|
|
4
|
+
|
|
5
|
+
// Converts a React ReadableArray into a Kotlin ByteArray.
|
|
6
|
+
// Expects ReadableArray to be an Array of ints, where each int represents a byte.
|
|
7
|
+
internal fun ReadableArray.toByteArray(): ByteArray =
|
|
8
|
+
ByteArray(size()) { index ->
|
|
9
|
+
getInt(index).toByte()
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Converts a Kotlin ByteArray into a React ReadableArray of ints.
|
|
13
|
+
internal fun ByteArray.toWritableArray(): ReadableArray =
|
|
14
|
+
Arguments.createArray().apply {
|
|
15
|
+
forEach {
|
|
16
|
+
this.pushInt(it.toInt())
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
package com.solanamobile.seedvault.reactnative
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.ReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.uimanager.ViewManager
|
|
7
|
+
|
|
8
|
+
class SeedVaultLibReactNativePackage : ReactPackage {
|
|
9
|
+
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
10
|
+
return listOf(SolanaMobileSeedVaultLibModule(reactContext))
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
14
|
+
return emptyList()
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
package com.solanamobile.seedvault.reactnative
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.content.Intent;
|
|
5
|
+
import android.database.ContentObserver
|
|
6
|
+
import android.net.Uri
|
|
7
|
+
import android.os.Bundle
|
|
8
|
+
import android.os.Handler
|
|
9
|
+
import android.util.Log
|
|
10
|
+
import com.facebook.react.bridge.*
|
|
11
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
12
|
+
import com.solanamobile.seedvault.*
|
|
13
|
+
import kotlinx.serialization.Serializable
|
|
14
|
+
import kotlinx.serialization.builtins.ListSerializer
|
|
15
|
+
import kotlinx.serialization.builtins.serializer
|
|
16
|
+
import kotlinx.serialization.json.Json
|
|
17
|
+
|
|
18
|
+
import com.solanamobile.seedvault.model.SigningRequestSerializer
|
|
19
|
+
|
|
20
|
+
class SolanaMobileSeedVaultLibModule(val reactContext: ReactApplicationContext) :
|
|
21
|
+
ReactContextBaseJavaModule(reactContext) {
|
|
22
|
+
|
|
23
|
+
// Sets the name of the module in React, accessible at ReactNative.NativeModules.SeedVaultLib
|
|
24
|
+
override fun getName() = "SolanaMobileSeedVaultLib"
|
|
25
|
+
|
|
26
|
+
private val json = Json { ignoreUnknownKeys = true }
|
|
27
|
+
|
|
28
|
+
private val mActivityEventListener: ActivityEventListener =
|
|
29
|
+
object : BaseActivityEventListener() {
|
|
30
|
+
override fun onActivityResult(
|
|
31
|
+
activity: Activity?,
|
|
32
|
+
requestCode: Int,
|
|
33
|
+
resultCode: Int,
|
|
34
|
+
data: Intent?
|
|
35
|
+
) {
|
|
36
|
+
handleActivityResult(requestCode, resultCode, data)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
init {
|
|
41
|
+
reactContext.addActivityEventListener(mActivityEventListener)
|
|
42
|
+
|
|
43
|
+
observeSeedVaultContentChanges()
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@ReactMethod
|
|
47
|
+
fun isSeedVaultAvailable(allowSimulated: Boolean = false, promise: Promise) {
|
|
48
|
+
val seedVaultAvailable = SeedVault.isAvailable(reactContext, allowSimulated)
|
|
49
|
+
promise.resolve(seedVaultAvailable)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@ReactMethod
|
|
53
|
+
fun hasUnauthorizedSeeds(promise: Promise) {
|
|
54
|
+
val application = reactContext.currentActivity?.application!!
|
|
55
|
+
val hasUnauthorizedSeeds = Wallet.hasUnauthorizedSeedsForPurpose(application,
|
|
56
|
+
WalletContractV1.PURPOSE_SIGN_SOLANA_TRANSACTION)
|
|
57
|
+
promise.resolve(hasUnauthorizedSeeds)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@ReactMethod
|
|
61
|
+
fun getAuthorizedSeeds(promise: Promise) {
|
|
62
|
+
val application = reactContext.currentActivity?.application!!
|
|
63
|
+
val authorizedSeedsCursor = Wallet.getAuthorizedSeeds(application,
|
|
64
|
+
WalletContractV1.AUTHORIZED_SEEDS_ALL_COLUMNS)!!
|
|
65
|
+
|
|
66
|
+
val seeds = mutableListOf<Seed>()
|
|
67
|
+
|
|
68
|
+
while (authorizedSeedsCursor.moveToNext()) {
|
|
69
|
+
val authToken = authorizedSeedsCursor.getLong(0)
|
|
70
|
+
val authPurpose = authorizedSeedsCursor.getInt(1)
|
|
71
|
+
val seedName = authorizedSeedsCursor.getString(2)
|
|
72
|
+
|
|
73
|
+
seeds.add(
|
|
74
|
+
Seed(authToken, seedName.ifBlank { authToken.toString() }, authPurpose)
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
promise.resolve(seeds.toWritableArray())
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@ReactMethod
|
|
82
|
+
fun getUnauthorizedSeeds(promise: Promise) {
|
|
83
|
+
val application = reactContext.currentActivity?.application!!
|
|
84
|
+
val unauthorizedSeedsCursor = Wallet.getUnauthorizedSeeds(application,
|
|
85
|
+
WalletContractV1.UNAUTHORIZED_SEEDS_ALL_COLUMNS)!!
|
|
86
|
+
|
|
87
|
+
val unauthorizedSeedsByPurpose = Arguments.createMap()
|
|
88
|
+
|
|
89
|
+
while (unauthorizedSeedsCursor.moveToNext()) {
|
|
90
|
+
val authPurpose = unauthorizedSeedsCursor.getInt(0)
|
|
91
|
+
val hasUnauthorizedSeeds = unauthorizedSeedsCursor.getInt(1) == 1
|
|
92
|
+
|
|
93
|
+
unauthorizedSeedsByPurpose.putBoolean("$authPurpose", hasUnauthorizedSeeds)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
promise.resolve(unauthorizedSeedsByPurpose)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@ReactMethod
|
|
100
|
+
fun getAccounts(authToken: String, promise: Promise) {
|
|
101
|
+
val application = reactContext.currentActivity?.application!!
|
|
102
|
+
val accountsCursor = Wallet.getAccounts(application, authToken.toLong(),
|
|
103
|
+
WalletContractV1.ACCOUNTS_ALL_COLUMNS,
|
|
104
|
+
WalletContractV1.ACCOUNTS_ACCOUNT_IS_USER_WALLET, "1")!!
|
|
105
|
+
|
|
106
|
+
val accounts = mutableListOf<Account>()
|
|
107
|
+
|
|
108
|
+
while (accountsCursor.moveToNext()) {
|
|
109
|
+
val accountId = accountsCursor.getLong(0)
|
|
110
|
+
val derivationPath = Uri.parse(accountsCursor.getString(1))
|
|
111
|
+
val publicKeyEncoded = accountsCursor.getString(3)
|
|
112
|
+
val accountName = accountsCursor.getString(4)
|
|
113
|
+
|
|
114
|
+
accounts.add(
|
|
115
|
+
Account(accountId,
|
|
116
|
+
accountName.ifBlank { publicKeyEncoded.substring(0, 10) },
|
|
117
|
+
derivationPath, publicKeyEncoded)
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
promise.resolve(accounts.toWritableArray())
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@ReactMethod
|
|
125
|
+
fun authorizeNewSeed() {
|
|
126
|
+
Log.d(TAG, "Requesting authorization for a new seed...")
|
|
127
|
+
val intent = Wallet.authorizeSeed(WalletContractV1.PURPOSE_SIGN_SOLANA_TRANSACTION)
|
|
128
|
+
reactContext.currentActivity?.startActivityForResult(intent, REQUEST_AUTHORIZE_SEED_ACCESS);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
@ReactMethod
|
|
132
|
+
fun createNewSeed() {
|
|
133
|
+
Log.d(TAG, "Requesting creation of a new seed...")
|
|
134
|
+
val intent = Wallet.createSeed(WalletContractV1.PURPOSE_SIGN_SOLANA_TRANSACTION)
|
|
135
|
+
reactContext.currentActivity?.startActivityForResult(intent, REQUEST_CREATE_NEW_SEED);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
@ReactMethod
|
|
139
|
+
fun importExistingSeed() {
|
|
140
|
+
Log.d(TAG, "Requesting import of an existing seed...")
|
|
141
|
+
val intent = Wallet.importSeed(WalletContractV1.PURPOSE_SIGN_SOLANA_TRANSACTION)
|
|
142
|
+
reactContext.currentActivity?.startActivityForResult(intent, REQUEST_IMPORT_EXISTING_SEED);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
@ReactMethod
|
|
146
|
+
fun deauthorizeSeed(authToken: String) {
|
|
147
|
+
Wallet.deauthorizeSeed(reactContext, authToken.toLong())
|
|
148
|
+
Log.d(TAG, "Seed $authToken deauthorized")
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
@ReactMethod
|
|
152
|
+
fun updateAccountName(authToken: String, accountId: Long, name: String?) {
|
|
153
|
+
Wallet.updateAccountName(reactContext, authToken.toLong(), accountId, name)
|
|
154
|
+
Log.d(TAG, "Account name updated (to '$name')")
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
@ReactMethod
|
|
158
|
+
fun signMessage(authToken: String, derivationPath: String, message: ReadableArray) {
|
|
159
|
+
signMessages(authToken, listOf(SigningRequest(message.toByteArray(), arrayListOf(Uri.parse(derivationPath)))))
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
@ReactMethod
|
|
163
|
+
fun signMessages(authToken: String, signingRequestsJson: String) {
|
|
164
|
+
val signingRequests: List<SigningRequest> = json.decodeFromString(ListSerializer(SigningRequestSerializer), signingRequestsJson)
|
|
165
|
+
signMessages(authToken, signingRequests)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
private fun signMessages(authToken: String, signingRequests: List<SigningRequest>) {
|
|
169
|
+
Log.d(TAG, "Requesting provided messages to be signed...")
|
|
170
|
+
val intent = Wallet.signMessages(authToken.toLong(), ArrayList(signingRequests))
|
|
171
|
+
reactContext.currentActivity?.startActivityForResult(intent, REQUEST_SIGN_MESSAGES);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
@ReactMethod
|
|
175
|
+
fun signTransaction(authToken: String, derivationPath: String, transaction: ReadableArray) {
|
|
176
|
+
signTransactions(authToken, listOf(SigningRequest(transaction.toByteArray(), arrayListOf(Uri.parse(derivationPath)))))
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
@ReactMethod
|
|
180
|
+
fun signTransactions(authToken: String, signingRequestsJson: String) {
|
|
181
|
+
val signingRequests: List<SigningRequest> = json.decodeFromString(ListSerializer(SigningRequestSerializer), signingRequestsJson)
|
|
182
|
+
signTransactions(authToken, signingRequests)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private fun signTransactions(authToken: String, signingRequests: List<SigningRequest>) {
|
|
186
|
+
Log.d(TAG, "Requesting provided transactions to be signed...")
|
|
187
|
+
val intent = Wallet.signTransactions(authToken.toLong(), ArrayList(signingRequests))
|
|
188
|
+
reactContext.currentActivity?.startActivityForResult(intent, REQUEST_SIGN_TRANSACTIONS);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
@ReactMethod
|
|
192
|
+
fun requestPublicKey(authToken: String, derivationPath: String) {
|
|
193
|
+
requestPublicKeys(authToken, Arguments.createArray().apply {
|
|
194
|
+
pushString(derivationPath)
|
|
195
|
+
})
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
@ReactMethod
|
|
199
|
+
fun requestPublicKeys(authToken: String, derivationPaths: ReadableArray) {
|
|
200
|
+
Log.d(TAG, "Requesting public keys for provided derviation paths...")
|
|
201
|
+
val intent = Wallet.requestPublicKeys(authToken.toLong(), Arguments.toList(derivationPaths)?.mapNotNull {
|
|
202
|
+
(it as? String)?.let { uriString -> Uri.parse(uriString) }
|
|
203
|
+
} as ArrayList ?: arrayListOf())
|
|
204
|
+
reactContext.currentActivity?.startActivityForResult(intent, REQUEST_GET_PUBLIC_KEYS);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
private fun sendEvent(reactContext: ReactContext, eventName: String, params: WritableMap? = null) {
|
|
208
|
+
reactContext
|
|
209
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
210
|
+
.emit(eventName, params)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
private fun sendSeedVaultEvent(event: SeedVaultEvent) {
|
|
214
|
+
sendEvent(reactContext, Companion.SEED_VAULT_EVENT_BRIDGE_NAME, event.toWritableMap())
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
private fun observeSeedVaultContentChanges() {
|
|
218
|
+
reactContext.contentResolver.registerContentObserver(
|
|
219
|
+
WalletContractV1.WALLET_PROVIDER_CONTENT_URI_BASE,
|
|
220
|
+
true,
|
|
221
|
+
object : ContentObserver(Handler(reactContext.mainLooper)) {
|
|
222
|
+
override fun onChange(selfChange: Boolean) =
|
|
223
|
+
throw NotImplementedError("Stub for legacy onChange")
|
|
224
|
+
override fun onChange(selfChange: Boolean, uri: Uri?) =
|
|
225
|
+
throw NotImplementedError("Stub for legacy onChange")
|
|
226
|
+
override fun onChange(selfChange: Boolean, uri: Uri?, flags: Int) =
|
|
227
|
+
throw NotImplementedError("Stub for legacy onChange")
|
|
228
|
+
|
|
229
|
+
override fun onChange(selfChange: Boolean, uris: Collection<Uri>, flags: Int) {
|
|
230
|
+
Log.d(TAG, "Received change notification for $uris (flags=$flags); refreshing viewmodel")
|
|
231
|
+
sendEvent(reactContext, SEED_VAULT_CONTENT_CHANGE_EVENT_BRIDGE_NAME,
|
|
232
|
+
params = Arguments.createMap().apply {
|
|
233
|
+
putString("__type", "SeedVaultContentChange")
|
|
234
|
+
putArray("uris", Arguments.createArray().apply {
|
|
235
|
+
uris.forEach { uri ->
|
|
236
|
+
pushString(uri.toString())
|
|
237
|
+
}
|
|
238
|
+
})
|
|
239
|
+
}
|
|
240
|
+
)
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
private fun handleActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
|
247
|
+
when (requestCode) {
|
|
248
|
+
REQUEST_AUTHORIZE_SEED_ACCESS -> {
|
|
249
|
+
try {
|
|
250
|
+
val authToken = Wallet.onAuthorizeSeedResult(resultCode, data)
|
|
251
|
+
Log.d(TAG, "Seed authorized, AuthToken=$authToken")
|
|
252
|
+
sendSeedVaultEvent(SeedVaultEvent.SeedAuthorized(authToken))
|
|
253
|
+
} catch (e: Wallet.ActionFailedException) {
|
|
254
|
+
Log.e(TAG, "Seed authorization failed", e)
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
REQUEST_CREATE_NEW_SEED -> {
|
|
258
|
+
try {
|
|
259
|
+
val authToken = Wallet.onCreateSeedResult(resultCode, data)
|
|
260
|
+
Log.d(TAG, "Seed created, AuthToken=$authToken")
|
|
261
|
+
sendSeedVaultEvent(SeedVaultEvent.NewSeedCreated(authToken))
|
|
262
|
+
} catch (e: Wallet.ActionFailedException) {
|
|
263
|
+
Log.e(TAG, "Seed creation failed", e)
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
REQUEST_IMPORT_EXISTING_SEED -> {
|
|
267
|
+
try {
|
|
268
|
+
val authToken = Wallet.onImportSeedResult(resultCode, data)
|
|
269
|
+
Log.d(TAG, "Seed imported, AuthToken=$authToken")
|
|
270
|
+
sendSeedVaultEvent(SeedVaultEvent.ExistingSeedImported(authToken))
|
|
271
|
+
} catch (e: Wallet.ActionFailedException) {
|
|
272
|
+
Log.e(TAG, "Seed import failed", e)
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
REQUEST_SIGN_TRANSACTIONS -> {
|
|
276
|
+
try {
|
|
277
|
+
val result = Wallet.onSignTransactionsResult(resultCode, data)
|
|
278
|
+
Log.d(TAG, "Transaction signed: signatures=$result")
|
|
279
|
+
sendSeedVaultEvent(SeedVaultEvent.PayloadsSigned(result))
|
|
280
|
+
} catch (e: Wallet.ActionFailedException) {
|
|
281
|
+
Log.e(TAG, "Transaction signing failed", e)
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
REQUEST_SIGN_MESSAGES -> {
|
|
285
|
+
try {
|
|
286
|
+
val result = Wallet.onSignMessagesResult(resultCode, data)
|
|
287
|
+
Log.d(TAG, "Message signed: signatures=$result")
|
|
288
|
+
sendSeedVaultEvent(SeedVaultEvent.PayloadsSigned(result))
|
|
289
|
+
} catch (e: Wallet.ActionFailedException) {
|
|
290
|
+
Log.e(TAG, "Message signing failed", e)
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
REQUEST_GET_PUBLIC_KEYS -> {
|
|
294
|
+
try {
|
|
295
|
+
val result = Wallet.onRequestPublicKeysResult(resultCode, data)
|
|
296
|
+
Log.d(TAG, "Public key retrieved: publicKey=$result")
|
|
297
|
+
sendSeedVaultEvent(SeedVaultEvent.PublicKeysEvent(result))
|
|
298
|
+
} catch (e: Wallet.ActionFailedException) {
|
|
299
|
+
Log.e(TAG, "Public Key retrieval failed", e)
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
companion object {
|
|
306
|
+
private val TAG = SolanaMobileSeedVaultLibModule::class.simpleName
|
|
307
|
+
private const val SEED_VAULT_EVENT_BRIDGE_NAME = "SeedVaultEventBridge"
|
|
308
|
+
private const val SEED_VAULT_CONTENT_CHANGE_EVENT_BRIDGE_NAME = "SeedVaultContentChangeEventBridge"
|
|
309
|
+
private const val REQUEST_AUTHORIZE_SEED_ACCESS = 0
|
|
310
|
+
private const val REQUEST_CREATE_NEW_SEED = 1
|
|
311
|
+
private const val REQUEST_IMPORT_EXISTING_SEED = 2
|
|
312
|
+
private const val REQUEST_SIGN_TRANSACTIONS = 3
|
|
313
|
+
private const val REQUEST_SIGN_MESSAGES = 4
|
|
314
|
+
private const val REQUEST_GET_PUBLIC_KEYS = 5
|
|
315
|
+
private const val KEY_PENDING_EVENT = "pendingEvent"
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
interface RNWritable {
|
|
320
|
+
fun toWritableMap(): WritableMap
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
data class Account(
|
|
324
|
+
@WalletContractV1.AccountId val id: Long,
|
|
325
|
+
val name: String,
|
|
326
|
+
val derivationPath: Uri,
|
|
327
|
+
val publicKeyEncoded: String
|
|
328
|
+
) : RNWritable {
|
|
329
|
+
override fun toWritableMap() = Arguments.createMap().apply {
|
|
330
|
+
putString("id", "$id")
|
|
331
|
+
putString("name", name)
|
|
332
|
+
putString("derivationPath", "$derivationPath")
|
|
333
|
+
putString("publicKeyEncoded", publicKeyEncoded)
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
data class Seed(
|
|
338
|
+
@WalletContractV1.AuthToken val authToken: Long,
|
|
339
|
+
val name: String,
|
|
340
|
+
@WalletContractV1.Purpose val purpose: Int,
|
|
341
|
+
// val accounts: List<Account> = listOf()
|
|
342
|
+
) : RNWritable {
|
|
343
|
+
override fun toWritableMap() = Arguments.createMap().apply {
|
|
344
|
+
putString("authToken", "$authToken")
|
|
345
|
+
putString("name", name)
|
|
346
|
+
putInt("purpose", purpose)
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
fun List<RNWritable>.toWritableArray() = Arguments.createArray().apply {
|
|
351
|
+
forEach { writable ->
|
|
352
|
+
pushMap(writable.toWritableMap())
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
@Serializable
|
|
357
|
+
sealed interface SeedVaultEvent {
|
|
358
|
+
sealed class SeedEvent(val authToken: Long) : SeedVaultEvent
|
|
359
|
+
class SeedAuthorized(authToken: Long) : SeedEvent(authToken)
|
|
360
|
+
class NewSeedCreated(authToken: Long) : SeedEvent(authToken)
|
|
361
|
+
class ExistingSeedImported(authToken: Long) : SeedEvent(authToken)
|
|
362
|
+
|
|
363
|
+
data class PayloadsSigned(val result: List<SigningResponse>) : SeedVaultEvent
|
|
364
|
+
|
|
365
|
+
data class PublicKeysEvent(val result: List<PublicKeyResponse>) : SeedVaultEvent
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
internal fun SeedVaultEvent.toWritableMap() : WritableMap = Arguments.createMap().apply {
|
|
369
|
+
putString("__type", this@toWritableMap::class.simpleName)
|
|
370
|
+
when (this@toWritableMap) {
|
|
371
|
+
is SeedVaultEvent.SeedEvent -> {
|
|
372
|
+
putString("authToken", authToken.toString())
|
|
373
|
+
}
|
|
374
|
+
is SeedVaultEvent.PayloadsSigned -> {
|
|
375
|
+
putArray("result", Arguments.makeNativeArray(result.map { response ->
|
|
376
|
+
Arguments.createMap().apply {
|
|
377
|
+
putArray("signatures", Arguments.makeNativeArray(response.signatures.map { it.toWritableArray() }))
|
|
378
|
+
putArray("resolvedDerivationPaths", Arguments.makeNativeArray(response.resolvedDerivationPaths.map { it.toString() }))
|
|
379
|
+
}
|
|
380
|
+
}))
|
|
381
|
+
}
|
|
382
|
+
is SeedVaultEvent.PublicKeysEvent -> {
|
|
383
|
+
putArray("result", Arguments.makeNativeArray(result.map { response ->
|
|
384
|
+
Arguments.createMap().apply {
|
|
385
|
+
putArray("publicKey", response.publicKey.toWritableArray())
|
|
386
|
+
putString("publicKeyEncoded", response.publicKeyEncoded)
|
|
387
|
+
putString("resolvedDerviationPath", response.resolvedDerivationPath.toString())
|
|
388
|
+
}
|
|
389
|
+
}))
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { useRef, useEffect } from 'react';
|
|
2
|
+
import { Platform, NativeModules, PermissionsAndroid, NativeEventEmitter } from 'react-native';
|
|
3
|
+
|
|
4
|
+
// EVENTS
|
|
5
|
+
// Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
|
|
6
|
+
const SeedVaultEventType = {
|
|
7
|
+
AuthorizeSeedAccess: "SeedAuthorized",
|
|
8
|
+
CreateNewSeed: "NewSeedCreated",
|
|
9
|
+
ImportExistingSeed: "ExistingSeedImported",
|
|
10
|
+
PayloadsSigned: "PayloadsSigned",
|
|
11
|
+
GetPublicKeys: "PublicKeysEvent",
|
|
12
|
+
ContentChange: "SeedVaultContentChange"
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/******************************************************************************
|
|
16
|
+
Copyright (c) Microsoft Corporation.
|
|
17
|
+
|
|
18
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
19
|
+
purpose with or without fee is hereby granted.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
22
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
23
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
24
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
25
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
26
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
27
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
28
|
+
***************************************************************************** */
|
|
29
|
+
|
|
30
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
31
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
32
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
33
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
34
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
35
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
36
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const LINKING_ERROR = `The package 'solana-mobile-seed-vault-lib' doesn't seem to be linked. Make sure: \n\n` +
|
|
41
|
+
'- You rebuilt the app after installing the package\n' +
|
|
42
|
+
'- If you are using Lerna workspaces\n' +
|
|
43
|
+
' - You have added `@solana-mobile/seed-vault-lib` as an explicit dependency, and\n' +
|
|
44
|
+
' - You have added `@solana-mobile/seed-vault-lib` to the `nohoist` section of your package.json\n' +
|
|
45
|
+
'- You are not using Expo managed workflow\n';
|
|
46
|
+
const SolanaMobileSeedVaultLib = Platform.OS === 'android' && NativeModules.SolanaMobileSeedVaultLib
|
|
47
|
+
? NativeModules.SolanaMobileSeedVaultLib
|
|
48
|
+
: new Proxy({}, {
|
|
49
|
+
get() {
|
|
50
|
+
throw new Error(Platform.OS !== 'android'
|
|
51
|
+
? 'The package `solana-mobile-seed-vault-lib` is only compatible with React Native Android'
|
|
52
|
+
: LINKING_ERROR);
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
const SeedVaultPermissionAndroid = 'com.solanamobile.seedvault.ACCESS_SEED_VAULT';
|
|
56
|
+
const checkSeedVaultPermission = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
+
const granted = yield PermissionsAndroid.check(SeedVaultPermissionAndroid);
|
|
58
|
+
if (!granted) {
|
|
59
|
+
throw new Error('You do not have permission to access Seed Vault. You must request permission to use Seed Vault.');
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
const checkIsSeedVaultAvailable = (allowSimulated = false) => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
+
const seedVaultAvailable = yield SolanaMobileSeedVaultLib.isSeedVaultAvailable(allowSimulated);
|
|
64
|
+
if (!seedVaultAvailable) {
|
|
65
|
+
throw new Error(allowSimulated
|
|
66
|
+
? 'Seed Vault is not available on this device, please install the Seed Vault Simulator'
|
|
67
|
+
: 'Seed Vault is not available on this device');
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
const SEED_VAULT_EVENT_BRIDGE_NAME = 'SeedVaultEventBridge';
|
|
71
|
+
function useSeedVault(handleSeedVaultEvent, handleContentChange) {
|
|
72
|
+
const seedVaultEventHandler = useRef(handleSeedVaultEvent);
|
|
73
|
+
const contentChangeHandler = useRef(handleContentChange);
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
seedVaultEventHandler.current = handleSeedVaultEvent;
|
|
76
|
+
contentChangeHandler.current = handleContentChange;
|
|
77
|
+
});
|
|
78
|
+
checkIsSeedVaultAvailable(true);
|
|
79
|
+
checkSeedVaultPermission();
|
|
80
|
+
// Start native event listener
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
const seedVaultEventEmitter = new NativeEventEmitter();
|
|
83
|
+
const listener = seedVaultEventEmitter.addListener(SEED_VAULT_EVENT_BRIDGE_NAME, (nativeEvent) => {
|
|
84
|
+
if (isContentChangeEvent(nativeEvent)) {
|
|
85
|
+
contentChangeHandler.current(nativeEvent);
|
|
86
|
+
handleContentChange(nativeEvent);
|
|
87
|
+
}
|
|
88
|
+
else if (isSeedVaultEvent(nativeEvent)) {
|
|
89
|
+
handleSeedVaultEvent(nativeEvent);
|
|
90
|
+
seedVaultEventHandler.current(nativeEvent);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
console.warn('Unexpected native event type');
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
return () => {
|
|
97
|
+
listener.remove();
|
|
98
|
+
};
|
|
99
|
+
}, []);
|
|
100
|
+
}
|
|
101
|
+
function isSeedVaultEvent(nativeEvent) {
|
|
102
|
+
return Object.values(SeedVaultEventType).includes(nativeEvent.__type);
|
|
103
|
+
}
|
|
104
|
+
function isContentChangeEvent(nativeEvent) {
|
|
105
|
+
return nativeEvent.__type == SeedVaultEventType.ContentChange;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export { SeedVaultEventType, SeedVaultPermissionAndroid, useSeedVault };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Permission } from "react-native";
|
|
2
|
+
// ERRORS
|
|
3
|
+
interface SeedVaultError {
|
|
4
|
+
message: string;
|
|
5
|
+
}
|
|
6
|
+
type ActionFailedError = SeedVaultError;
|
|
7
|
+
type NotModifiedError = SeedVaultError;
|
|
8
|
+
// EVENTS
|
|
9
|
+
// Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
|
|
10
|
+
declare const SeedVaultEventType: {
|
|
11
|
+
readonly AuthorizeSeedAccess: "SeedAuthorized";
|
|
12
|
+
readonly CreateNewSeed: "NewSeedCreated";
|
|
13
|
+
readonly ImportExistingSeed: "ExistingSeedImported";
|
|
14
|
+
readonly PayloadsSigned: "PayloadsSigned";
|
|
15
|
+
readonly GetPublicKeys: "PublicKeysEvent";
|
|
16
|
+
readonly ContentChange: "SeedVaultContentChange";
|
|
17
|
+
};
|
|
18
|
+
type SeedVaultEventType = (typeof SeedVaultEventType)[keyof typeof SeedVaultEventType];
|
|
19
|
+
interface ISeedVaultEvent {
|
|
20
|
+
__type: SeedVaultEventType;
|
|
21
|
+
}
|
|
22
|
+
// Authorize Seed Access
|
|
23
|
+
type SeedAccessAuthorizedEvent = Readonly<{
|
|
24
|
+
__type: typeof SeedVaultEventType.AuthorizeSeedAccess;
|
|
25
|
+
authToken: string;
|
|
26
|
+
}> & ISeedVaultEvent;
|
|
27
|
+
type AuthorizeSeedAccessEvent = SeedAccessAuthorizedEvent | ActionFailedError;
|
|
28
|
+
// Create New Seed
|
|
29
|
+
type NewSeedCreatedEvent = Readonly<{
|
|
30
|
+
__type: typeof SeedVaultEventType.CreateNewSeed;
|
|
31
|
+
authToken: string;
|
|
32
|
+
}> & ISeedVaultEvent;
|
|
33
|
+
type CreateNewSeedEvent = NewSeedCreatedEvent | ActionFailedError;
|
|
34
|
+
// Import Existing Seed
|
|
35
|
+
type ExistingSeedImportedEvent = Readonly<{
|
|
36
|
+
__type: typeof SeedVaultEventType.ImportExistingSeed;
|
|
37
|
+
authToken: string;
|
|
38
|
+
}> & ISeedVaultEvent;
|
|
39
|
+
type ImportExistingSeedEvent = ExistingSeedImportedEvent | ActionFailedError;
|
|
40
|
+
type SeedEvent = AuthorizeSeedAccessEvent | CreateNewSeedEvent | ImportExistingSeedEvent;
|
|
41
|
+
// Sign Payloads
|
|
42
|
+
type SigningResponse = Readonly<{
|
|
43
|
+
signatures: [
|
|
44
|
+
[
|
|
45
|
+
]
|
|
46
|
+
];
|
|
47
|
+
resolvedDerivationPaths: string[];
|
|
48
|
+
}>;
|
|
49
|
+
type PayloadsSignedEvent = Readonly<{
|
|
50
|
+
__type: typeof SeedVaultEventType.PayloadsSigned;
|
|
51
|
+
result: SigningResponse[];
|
|
52
|
+
}> & ISeedVaultEvent;
|
|
53
|
+
type SignPayloadsEvent = PayloadsSignedEvent | ActionFailedError;
|
|
54
|
+
// Get Public Keys
|
|
55
|
+
type PublicKeyResponse = Readonly<{
|
|
56
|
+
publicKey: [
|
|
57
|
+
];
|
|
58
|
+
publicKeyEncoded: string;
|
|
59
|
+
resolvedDerivationPath: string;
|
|
60
|
+
}>;
|
|
61
|
+
type GotPublicKeyEvent = Readonly<{
|
|
62
|
+
__type: typeof SeedVaultEventType.GetPublicKeys;
|
|
63
|
+
result: PublicKeyResponse[];
|
|
64
|
+
}> & ISeedVaultEvent;
|
|
65
|
+
type PublicKeyEvent = GotPublicKeyEvent | ActionFailedError;
|
|
66
|
+
// Content Change
|
|
67
|
+
type SeedVaultContentChangeNotification = Readonly<{
|
|
68
|
+
__type: typeof SeedVaultEventType.ContentChange;
|
|
69
|
+
uris: string[];
|
|
70
|
+
}> & ISeedVaultEvent;
|
|
71
|
+
type SeedVaultContentChange = SeedVaultContentChangeNotification;
|
|
72
|
+
type SeedVaultEvent = AuthorizeSeedAccessEvent | CreateNewSeedEvent | ImportExistingSeedEvent | SignPayloadsEvent | PublicKeyEvent;
|
|
73
|
+
declare const SeedVaultPermissionAndroid: Permission;
|
|
74
|
+
declare function useSeedVault(handleSeedVaultEvent: (event: SeedVaultEvent) => void, handleContentChange: (event: SeedVaultContentChange) => void): void;
|
|
75
|
+
type Account = Readonly<{
|
|
76
|
+
id: number;
|
|
77
|
+
name: string;
|
|
78
|
+
derivationPath: string;
|
|
79
|
+
publicKeyEncoded: string;
|
|
80
|
+
}>;
|
|
81
|
+
type Seed = Readonly<{
|
|
82
|
+
authToken: number;
|
|
83
|
+
name: string;
|
|
84
|
+
purpose: number;
|
|
85
|
+
}>;
|
|
86
|
+
export { SeedVaultError, ActionFailedError, NotModifiedError, SeedVaultEventType, ISeedVaultEvent, SeedAccessAuthorizedEvent, AuthorizeSeedAccessEvent, NewSeedCreatedEvent, CreateNewSeedEvent, ExistingSeedImportedEvent, ImportExistingSeedEvent, SeedEvent, SigningResponse, PayloadsSignedEvent, SignPayloadsEvent, PublicKeyResponse, GotPublicKeyEvent, PublicKeyEvent, SeedVaultContentChangeNotification, SeedVaultContentChange, SeedVaultEvent, SeedVaultPermissionAndroid, useSeedVault, Account, Seed };
|
|
87
|
+
//# sourceMappingURL=index.native.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.native.d.ts","sourceRoot":"","sources":["../../src/index.ts","../../src/seedVaultEvent.ts","../../src/useSeedVault.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@solana-mobile/seed-vault-lib",
|
|
3
|
+
"description": "A React Native wrapper of the Solana Mobile, Seed Vault SDK. Apps can use this to interact with seed vault implementations on Android",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"author": "Marco Martinez <marco.martinez@solanamobile.com>",
|
|
6
|
+
"repository": "https://github.com/solana-mobile/seed-vault-sdk",
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"main": "lib/esm/index.native.js",
|
|
11
|
+
"react-native": "lib/esm/index.native.js",
|
|
12
|
+
"module": "lib/esm/index.native.js",
|
|
13
|
+
"types": "lib/types/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
"./package.json": "./package.json",
|
|
16
|
+
".": {
|
|
17
|
+
"import": "./lib/esm/index.native.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"android",
|
|
22
|
+
"!android/build",
|
|
23
|
+
"lib",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"clean": "shx rm -rf lib/*",
|
|
31
|
+
"build": "yarn clean && rollup --config ../../rollup.config.ts --configPlugin rollup-plugin-ts",
|
|
32
|
+
"build:watch": "yarn clean && rollup --config ../../rollup.config.ts --configPlugin rollup-plugin-ts --watch",
|
|
33
|
+
"postbuild": "cross-env echo {\\\"type\\\":\\\"module\\\"} | npx json > lib/esm/package.json"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@solana/web3.js": "^1.58.0",
|
|
37
|
+
"@types/react-native": "^0.69.3",
|
|
38
|
+
"cross-env": "^7.0.3",
|
|
39
|
+
"shx": "^0.3.4"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"react-native": ">0.69"
|
|
43
|
+
}
|
|
44
|
+
}
|