@account-kit/react-native-signer 4.57.0 → 4.57.2-alpha.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/android/bin/build/generated/source/buildConfig/debug/com/accountkit/reactnativesigner/BuildConfig.class +0 -0
- package/android/bin/build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/AndroidManifest.xml +7 -0
- package/android/bin/build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/output-metadata.json +18 -0
- package/android/bin/build/intermediates/aar_metadata/debug/writeDebugAarMetadata/aar-metadata.properties +6 -0
- package/android/bin/build/intermediates/annotation_processor_list/debug/javaPreCompileDebug/annotationProcessors.json +1 -0
- package/android/bin/build/intermediates/compile_library_classes_jar/debug/bundleLibCompileToJarDebug/classes.jar +0 -0
- package/android/bin/build/intermediates/compile_r_class_jar/debug/generateDebugRFile/R.jar +0 -0
- package/android/bin/build/intermediates/compile_symbol_list/debug/generateDebugRFile/R.txt +0 -0
- package/android/bin/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties +1 -0
- package/android/bin/build/intermediates/incremental/debug/packageDebugResources/merger.xml +2 -0
- package/android/bin/build/intermediates/incremental/mergeDebugJniLibFolders/merger.xml +2 -0
- package/android/bin/build/intermediates/incremental/mergeDebugShaders/merger.xml +2 -0
- package/android/bin/build/intermediates/incremental/packageDebugAssets/merger.xml +2 -0
- package/android/bin/build/intermediates/java_res/debug/processDebugJavaRes/out/META-INF/account-kit_react-native-signer_debug.kotlin_module +0 -0
- package/android/bin/build/intermediates/local_only_symbol_list/debug/parseDebugLocalResources/R-def.txt +2 -0
- package/android/bin/build/intermediates/manifest_merge_blame_file/debug/processDebugManifest/manifest-merger-blame-debug-report.txt +7 -0
- package/android/bin/build/intermediates/merged_manifest/debug/processDebugManifest/AndroidManifest.xml +7 -0
- package/android/bin/build/intermediates/navigation_json/debug/extractDeepLinksDebug/navigation.json +1 -0
- package/android/bin/build/intermediates/nested_resources_validation_report/debug/generateDebugResources/nestedResourcesValidationReport.txt +1 -0
- package/android/bin/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/META-INF/account-kit_react-native-signer_debug.kotlin_module +0 -0
- package/android/bin/build/intermediates/runtime_library_classes_jar/debug/bundleLibRuntimeToJarDebug/classes.jar +0 -0
- package/android/bin/build/intermediates/symbol_list_with_package_name/debug/generateDebugRFile/package-aware-r.txt +1 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.keystream +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.keystream.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.values.at +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab_i +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab_i.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.keystream +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.keystream.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.values.at +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab_i +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab_i.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.keystream +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.keystream.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.values.at +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab_i +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab_i.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/constants.tab +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/constants.tab.keystream +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/constants.tab.keystream.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/constants.tab.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/constants.tab.values.at +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/constants.tab_i +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/constants.tab_i.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.keystream +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.keystream.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.values.at +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab_i +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab_i.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/java-sources-proto-map.tab +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/java-sources-proto-map.tab.keystream +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/java-sources-proto-map.tab.keystream.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/java-sources-proto-map.tab.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/java-sources-proto-map.tab.values.at +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/java-sources-proto-map.tab_i +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/java-sources-proto-map.tab_i.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/package-parts.tab +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/package-parts.tab.keystream +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/package-parts.tab.keystream.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/package-parts.tab.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/package-parts.tab.values.at +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/package-parts.tab_i +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/package-parts.tab_i.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.keystream +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.keystream.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.values.at +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab_i +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab_i.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.keystream +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.keystream.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.values.at +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab_i +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab_i.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.keystream +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.keystream.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.values.at +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab_i +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab_i.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.keystream +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.keystream.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.values.at +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab_i +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab_i.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/counters.tab +2 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.keystream +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.keystream.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.values.at +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab_i +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab_i.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.values.at +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab_i +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab_i.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.values.at +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab_i +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab_i.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/last-build.bin +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/classpath-snapshot/shrunk-classpath-snapshot.bin +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/local-state/build-history.bin +0 -0
- package/android/bin/build/outputs/logs/manifest-merger-debug-report.txt +16 -0
- package/android/bin/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin +0 -0
- package/android/bin/build/tmp/kotlin-classes/debug/META-INF/account-kit_react-native-signer_debug.kotlin_module +0 -0
- package/android/bin/build.gradle +192 -0
- package/android/bin/generated/java/com/accountkit/reactnativesigner/NativeTEKStamperSpec.class +0 -0
- package/android/bin/generated/jni/CMakeLists.txt +36 -0
- package/android/bin/generated/jni/NativeTEKStamperSpec-generated.cpp +56 -0
- package/android/bin/generated/jni/NativeTEKStamperSpec.h +31 -0
- package/android/bin/generated/jni/react/renderer/components/NativeTEKStamperSpec/ComponentDescriptors.cpp +22 -0
- package/android/bin/generated/jni/react/renderer/components/NativeTEKStamperSpec/ComponentDescriptors.h +24 -0
- package/android/bin/generated/jni/react/renderer/components/NativeTEKStamperSpec/EventEmitters.cpp +16 -0
- package/android/bin/generated/jni/react/renderer/components/NativeTEKStamperSpec/EventEmitters.h +17 -0
- package/android/bin/generated/jni/react/renderer/components/NativeTEKStamperSpec/NativeTEKStamperSpecJSI-generated.cpp +54 -0
- package/android/bin/generated/jni/react/renderer/components/NativeTEKStamperSpec/NativeTEKStamperSpecJSI.h +150 -0
- package/android/bin/generated/jni/react/renderer/components/NativeTEKStamperSpec/Props.cpp +19 -0
- package/android/bin/generated/jni/react/renderer/components/NativeTEKStamperSpec/Props.h +18 -0
- package/android/bin/generated/jni/react/renderer/components/NativeTEKStamperSpec/ShadowNodes.cpp +17 -0
- package/android/bin/generated/jni/react/renderer/components/NativeTEKStamperSpec/ShadowNodes.h +23 -0
- package/android/bin/generated/jni/react/renderer/components/NativeTEKStamperSpec/States.cpp +16 -0
- package/android/bin/generated/jni/react/renderer/components/NativeTEKStamperSpec/States.h +19 -0
- package/android/bin/gradle.properties +5 -0
- package/android/bin/src/main/AndroidManifest.xml +3 -0
- package/android/bin/src/main/java/com/accountkit/reactnativesigner/NativeTEKStamperModule.kt +66 -0
- package/android/bin/src/main/java/com/accountkit/reactnativesigner/ReactNativeSignerPackage.kt +33 -0
- package/android/bin/src/main/java/com/accountkit/reactnativesigner/core/KeyExtensions.kt +77 -0
- package/android/bin/src/main/java/com/accountkit/reactnativesigner/core/TEKManager.kt +89 -0
- package/android/bin/src/main/java/com/accountkit/reactnativesigner/core/TEKStamper.kt +258 -0
- package/android/bin/src/main/java/com/accountkit/reactnativesigner/core/errors/NoInjectedBundleException.kt +3 -0
- package/android/bin/src/main/java/com/accountkit/reactnativesigner/core/errors/NoTEKException.kt +3 -0
- package/android/bin/src/main/java/com/accountkit/reactnativesigner/core/errors/StamperNotInitialized.kt +3 -0
- package/package.json +4 -4
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
package com.accountkit.reactnativesigner.core
|
|
2
|
+
|
|
3
|
+
import com.google.crypto.tink.CleartextKeysetHandle
|
|
4
|
+
import com.google.crypto.tink.InsecureSecretKeyAccess
|
|
5
|
+
import com.google.crypto.tink.KeysetHandle
|
|
6
|
+
import com.google.crypto.tink.hybrid.HpkeParameters
|
|
7
|
+
import com.google.crypto.tink.hybrid.HpkePrivateKey
|
|
8
|
+
import com.google.crypto.tink.hybrid.HpkePublicKey
|
|
9
|
+
import com.google.crypto.tink.subtle.EllipticCurves
|
|
10
|
+
import com.google.crypto.tink.util.Bytes
|
|
11
|
+
import com.google.crypto.tink.util.SecretBytes
|
|
12
|
+
import java.security.interfaces.ECPublicKey
|
|
13
|
+
import javax.xml.bind.DatatypeConverter
|
|
14
|
+
import com.google.crypto.tink.proto.HpkePrivateKey as ProtoHpkePrivateKey
|
|
15
|
+
import com.google.crypto.tink.proto.HpkePublicKey as ProtoHpkePublicKey
|
|
16
|
+
|
|
17
|
+
// Keyset Handle Extensions
|
|
18
|
+
fun KeysetHandle.toHpkePublicKey(hpkeParameters: HpkeParameters): HpkePublicKey {
|
|
19
|
+
val keySet = CleartextKeysetHandle.getKeyset(this.publicKeysetHandle)
|
|
20
|
+
val protoKey = ProtoHpkePublicKey.parseFrom(keySet.keyList[0].keyData.value)
|
|
21
|
+
|
|
22
|
+
return HpkePublicKey.create(
|
|
23
|
+
hpkeParameters,
|
|
24
|
+
Bytes.copyFrom(protoKey.publicKey.toByteArray()),
|
|
25
|
+
null
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
fun KeysetHandle.toHpkePrivateKey(hpkeParams: HpkeParameters): HpkePrivateKey {
|
|
30
|
+
val publicKey = this.toHpkePublicKey(hpkeParams)
|
|
31
|
+
val pkKs = CleartextKeysetHandle.getKeyset(this)
|
|
32
|
+
val pkKeyData = pkKs.keyList[0].keyData
|
|
33
|
+
check(pkKeyData.typeUrl == "type.googleapis.com/google.crypto.tink.HpkePrivateKey") {
|
|
34
|
+
"invalid key type"
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return HpkePrivateKey.create(
|
|
38
|
+
HpkePublicKey.create(
|
|
39
|
+
hpkeParams,
|
|
40
|
+
Bytes.copyFrom(publicKey.toByteArray()),
|
|
41
|
+
null
|
|
42
|
+
),
|
|
43
|
+
SecretBytes.copyFrom(
|
|
44
|
+
ProtoHpkePrivateKey.parseFrom(pkKeyData.value).privateKey.toByteArray(),
|
|
45
|
+
InsecureSecretKeyAccess.get()
|
|
46
|
+
)
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// HPKE Public Key Extensions
|
|
51
|
+
fun HpkePublicKey.toHex(): String {
|
|
52
|
+
return this.toByteArray().toHex()
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
fun HpkePublicKey.toByteArray(): ByteArray {
|
|
56
|
+
return this.publicKeyBytes.toByteArray()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// ECPublicKey Extensions
|
|
60
|
+
fun ECPublicKey.toBytes(
|
|
61
|
+
pfType: EllipticCurves.PointFormatType
|
|
62
|
+
): ByteArray {
|
|
63
|
+
return EllipticCurves.pointEncode(
|
|
64
|
+
this.params.curve,
|
|
65
|
+
pfType,
|
|
66
|
+
this.w
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Conversions from Hex <-> byte[]
|
|
71
|
+
fun String.fromHex(): ByteArray {
|
|
72
|
+
return DatatypeConverter.parseHexBinary(this)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
fun ByteArray.toHex(): String {
|
|
76
|
+
return DatatypeConverter.printHexBinary(this)
|
|
77
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
package com.accountkit.reactnativesigner.core
|
|
2
|
+
|
|
3
|
+
import android.content.SharedPreferences
|
|
4
|
+
import com.accountkit.reactnativesigner.core.errors.NoTEKException
|
|
5
|
+
import com.google.crypto.tink.InsecureSecretKeyAccess
|
|
6
|
+
import com.google.crypto.tink.KeyTemplate
|
|
7
|
+
import com.google.crypto.tink.KeysetHandle
|
|
8
|
+
import com.google.crypto.tink.TinkJsonProtoKeysetFormat
|
|
9
|
+
import com.google.crypto.tink.hybrid.HpkeParameters
|
|
10
|
+
import com.google.crypto.tink.hybrid.HpkePublicKey
|
|
11
|
+
import com.google.crypto.tink.hybrid.internal.HpkeContext
|
|
12
|
+
import com.google.crypto.tink.hybrid.internal.HpkeKemKeyFactory
|
|
13
|
+
import com.google.crypto.tink.hybrid.internal.HpkePrimitiveFactory
|
|
14
|
+
|
|
15
|
+
private const val TEK_STORAGE_KEY = "TEK_STORAGE_KEY"
|
|
16
|
+
private val hpkeParams = HpkeParameters.builder()
|
|
17
|
+
.setKemId(HpkeParameters.KemId.DHKEM_P256_HKDF_SHA256)
|
|
18
|
+
.setKdfId(HpkeParameters.KdfId.HKDF_SHA256)
|
|
19
|
+
.setAeadId(HpkeParameters.AeadId.AES_256_GCM)
|
|
20
|
+
.setVariant(HpkeParameters.Variant.NO_PREFIX)
|
|
21
|
+
.build()
|
|
22
|
+
|
|
23
|
+
class HpkeTEKManager(private val sharedPreferences: SharedPreferences) {
|
|
24
|
+
fun hpkeDecrypt(
|
|
25
|
+
encapsulatePublicKey: ByteArray,
|
|
26
|
+
cipherText: ByteArray,
|
|
27
|
+
info: ByteArray,
|
|
28
|
+
aad: ByteArray
|
|
29
|
+
): ByteArray {
|
|
30
|
+
// Why do we hve to do all this rather than doing:
|
|
31
|
+
// val hybridDecrypt = tekHandle.getPrimitive(HybridDecrypt::class.java)
|
|
32
|
+
// val decryptedKey = hybridDecrypt.decrypt(ciphertext, "turnkey_hpke".toByteArray())
|
|
33
|
+
// the hybridDecrypt.decrypt that google exposes doesn't allow us to pass in
|
|
34
|
+
// the aad that's needed to complete decryption
|
|
35
|
+
val keyHandle = getKeysetHandle() ?: throw NoTEKException()
|
|
36
|
+
|
|
37
|
+
val recipient = HpkeContext.createRecipientContext(
|
|
38
|
+
encapsulatePublicKey,
|
|
39
|
+
HpkeKemKeyFactory.createPrivate(keyHandle.toHpkePrivateKey(hpkeParams)),
|
|
40
|
+
HpkePrimitiveFactory.createKem(hpkeParams.kemId),
|
|
41
|
+
HpkePrimitiveFactory.createKdf(hpkeParams.kdfId),
|
|
42
|
+
HpkePrimitiveFactory.createAead(hpkeParams.aeadId),
|
|
43
|
+
info
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
return recipient.open(cipherText, aad)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
fun createTEK(): HpkePublicKey {
|
|
50
|
+
val existingPublicKey = publicKey()
|
|
51
|
+
if (existingPublicKey != null) {
|
|
52
|
+
return existingPublicKey
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
val keysetHandle = KeysetHandle.generateNew(KeyTemplate.createFrom(hpkeParams))
|
|
56
|
+
|
|
57
|
+
sharedPreferences
|
|
58
|
+
.edit()
|
|
59
|
+
.putString(
|
|
60
|
+
TEK_STORAGE_KEY,
|
|
61
|
+
TinkJsonProtoKeysetFormat.serializeKeyset(
|
|
62
|
+
keysetHandle,
|
|
63
|
+
InsecureSecretKeyAccess.get()
|
|
64
|
+
)
|
|
65
|
+
)
|
|
66
|
+
.apply()
|
|
67
|
+
|
|
68
|
+
return keysetHandle.toHpkePublicKey(hpkeParams)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
fun publicKey(): HpkePublicKey? {
|
|
72
|
+
val ksHandle = getKeysetHandle() ?: return null
|
|
73
|
+
|
|
74
|
+
return ksHandle.toHpkePublicKey(hpkeParams)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
fun publicKeyHex(): String? {
|
|
78
|
+
return publicKey()?.toHex()
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private fun getKeysetHandle(): KeysetHandle? {
|
|
82
|
+
val storageVal = sharedPreferences.getString(TEK_STORAGE_KEY, null) ?: return null
|
|
83
|
+
|
|
84
|
+
return TinkJsonProtoKeysetFormat.parseKeyset(
|
|
85
|
+
storageVal,
|
|
86
|
+
InsecureSecretKeyAccess.get()
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
package com.accountkit.reactnativesigner.core
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.content.SharedPreferences
|
|
5
|
+
import androidx.security.crypto.EncryptedSharedPreferences
|
|
6
|
+
import androidx.security.crypto.MasterKey
|
|
7
|
+
import com.accountkit.reactnativesigner.core.errors.NoInjectedBundleException
|
|
8
|
+
import com.accountkit.reactnativesigner.core.errors.StamperNotInitializedException
|
|
9
|
+
import com.google.crypto.tink.config.TinkConfig
|
|
10
|
+
import com.google.crypto.tink.subtle.Base64
|
|
11
|
+
import com.google.crypto.tink.subtle.EllipticCurves
|
|
12
|
+
import kotlinx.serialization.Serializable
|
|
13
|
+
import kotlinx.serialization.encodeToString
|
|
14
|
+
import kotlinx.serialization.json.Json
|
|
15
|
+
import org.bitcoinj.core.Base58
|
|
16
|
+
import org.bouncycastle.jce.ECNamedCurveTable
|
|
17
|
+
import org.bouncycastle.jce.provider.BouncyCastleProvider
|
|
18
|
+
import org.bouncycastle.jce.spec.ECPublicKeySpec
|
|
19
|
+
import java.nio.ByteBuffer
|
|
20
|
+
import java.security.KeyFactory
|
|
21
|
+
import java.security.Security
|
|
22
|
+
import java.security.Signature
|
|
23
|
+
import java.security.KeyStore
|
|
24
|
+
import java.security.KeyStoreException
|
|
25
|
+
|
|
26
|
+
@Serializable
|
|
27
|
+
data class ApiStamp(val publicKey: String, val scheme: String, val signature: String)
|
|
28
|
+
|
|
29
|
+
data class Stamp(val stampHeaderName: String, val stampHeaderValue: String)
|
|
30
|
+
|
|
31
|
+
private const val BUNDLE_PRIVATE_KEY = "BUNDLE_PRIVATE_KEY"
|
|
32
|
+
private const val BUNDLE_PUBLIC_KEY = "BUNDLE_PUBLIC_KEY"
|
|
33
|
+
private const val MASTER_KEY_ALIAS = "tek_master_key"
|
|
34
|
+
private const val ENCRYPTED_SHARED_PREFERENCES_FILENAME = "tek_stamper_shared_prefs"
|
|
35
|
+
|
|
36
|
+
class TEKStamper(context: Context) {
|
|
37
|
+
// This is how the docs for EncryptedSharedPreferences recommend creating this setup
|
|
38
|
+
// NOTE: we can further customize the permissions around accessing this master key and the keys
|
|
39
|
+
// used to generate it by using the .setKeyGenParameterSpec() method on this builder
|
|
40
|
+
// this would allow us to further specify the access requirements to this key
|
|
41
|
+
//
|
|
42
|
+
// we should explore the best practices on how to do this once we reach a phase of further
|
|
43
|
+
// cleanup
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* We are using EncryptedSharedPreferences to store 2 pieces of data
|
|
47
|
+
* 1. the TEK keypair - this is the ephemeral key-pair that Turnkey will use to encrypt the
|
|
48
|
+
* bundle with
|
|
49
|
+
* 2. the decrypted private key for a session
|
|
50
|
+
*
|
|
51
|
+
* The reason we are not using the android key store for either of these things is because
|
|
52
|
+
* 1. For us to be able to import the private key in the bundle into the KeyStore, Turnkey has
|
|
53
|
+
* to return the key in a different format (AFAIK):
|
|
54
|
+
* https://developer.android.com/privacy-and-security/keystore#ImportingEncryptedKeys
|
|
55
|
+
* 2. If we store the TEK in the KeyStore, then we have to roll our own HPKE decrypt function as
|
|
56
|
+
* there's no off the shelf solution (that I could find) to do the HPKE decryption. Rolling our
|
|
57
|
+
* own decryption feels wrong given we are not experts on this and don't have a good way to
|
|
58
|
+
* verify our implementation (and I don't trust the ChatGPT output to be correct. Even if it is,
|
|
59
|
+
* there's no guarantee we can test all the edge cases since those are unknown unknowns)
|
|
60
|
+
*
|
|
61
|
+
* NOTE: this isn't too far off from how Turnkey recommends doing it in Swift
|
|
62
|
+
* https://github.com/tkhq/swift-sdk/blob/5817374a7cbd4c99b7ea90b170363dc2bf6c59b9/docs/email-auth.md#email-authentication
|
|
63
|
+
*
|
|
64
|
+
* The open question is if the storage of the decrypted private key is secure enough though
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
private lateinit var tekManager: HpkeTEKManager
|
|
73
|
+
private lateinit var sharedPreferences: SharedPreferences
|
|
74
|
+
|
|
75
|
+
init {
|
|
76
|
+
try {
|
|
77
|
+
TinkConfig.register()
|
|
78
|
+
|
|
79
|
+
sharedPreferences = getSharedPreferences(context)
|
|
80
|
+
tekManager = HpkeTEKManager(sharedPreferences)
|
|
81
|
+
|
|
82
|
+
if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME).javaClass !=
|
|
83
|
+
BouncyCastleProvider::class.java
|
|
84
|
+
) {
|
|
85
|
+
Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
|
|
89
|
+
Security.addProvider(BouncyCastleProvider())
|
|
90
|
+
}
|
|
91
|
+
} catch (e: Exception){
|
|
92
|
+
throw RuntimeException("Error creating master key", e)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
fun init(): String {
|
|
98
|
+
return tekManager.createTEK().toHex()
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
fun clear() {
|
|
102
|
+
sharedPreferences.edit().clear().apply()
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
fun publicKey(): String? {
|
|
106
|
+
return tekManager.publicKeyHex()
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
fun injectCredentialBundle(bundle: String) {
|
|
110
|
+
val tekPublicKey =
|
|
111
|
+
tekManager.publicKey()
|
|
112
|
+
?: throw StamperNotInitializedException()
|
|
113
|
+
|
|
114
|
+
val decodedBundle = Base58.decodeChecked(bundle)
|
|
115
|
+
val buffer = ByteBuffer.wrap(decodedBundle)
|
|
116
|
+
val ephemeralPublicKeyLength = 33
|
|
117
|
+
val ephemeralPublicKeyBytes = ByteArray(ephemeralPublicKeyLength)
|
|
118
|
+
buffer.get(ephemeralPublicKeyBytes)
|
|
119
|
+
val ephemeralPublicKey =
|
|
120
|
+
EllipticCurves.getEcPublicKey(
|
|
121
|
+
EllipticCurves.CurveType.NIST_P256,
|
|
122
|
+
EllipticCurves.PointFormatType.COMPRESSED,
|
|
123
|
+
ephemeralPublicKeyBytes,
|
|
124
|
+
)
|
|
125
|
+
.toBytes(EllipticCurves.PointFormatType.UNCOMPRESSED)
|
|
126
|
+
|
|
127
|
+
val ciphertext = ByteArray(buffer.remaining())
|
|
128
|
+
buffer.get(ciphertext)
|
|
129
|
+
|
|
130
|
+
val aad = ephemeralPublicKey + tekPublicKey.toByteArray()
|
|
131
|
+
|
|
132
|
+
val decryptedKey =
|
|
133
|
+
tekManager.hpkeDecrypt(
|
|
134
|
+
ephemeralPublicKey,
|
|
135
|
+
ciphertext,
|
|
136
|
+
"turnkey_hpke".toByteArray(),
|
|
137
|
+
aad
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
val (publicKeyBytes, privateKeyBytes) = privateKeyToKeyPair(decryptedKey)
|
|
141
|
+
|
|
142
|
+
sharedPreferences
|
|
143
|
+
.edit()
|
|
144
|
+
.putString(BUNDLE_PRIVATE_KEY, privateKeyBytes.toHex().lowercase())
|
|
145
|
+
.apply()
|
|
146
|
+
|
|
147
|
+
sharedPreferences
|
|
148
|
+
.edit()
|
|
149
|
+
.putString(BUNDLE_PUBLIC_KEY, publicKeyBytes.toHex().lowercase())
|
|
150
|
+
.apply()
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
fun stamp(payload: String): Stamp {
|
|
154
|
+
val signingKeyHex =
|
|
155
|
+
sharedPreferences.getString(BUNDLE_PRIVATE_KEY, null)
|
|
156
|
+
?: throw NoInjectedBundleException()
|
|
157
|
+
|
|
158
|
+
val publicSigningKeyHex =
|
|
159
|
+
sharedPreferences.getString(BUNDLE_PUBLIC_KEY, null)
|
|
160
|
+
?: throw NoInjectedBundleException()
|
|
161
|
+
|
|
162
|
+
val ecPrivateKey =
|
|
163
|
+
EllipticCurves.getEcPrivateKey(
|
|
164
|
+
EllipticCurves.CurveType.NIST_P256,
|
|
165
|
+
signingKeyHex.fromHex()
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
val signer = Signature.getInstance("SHA256withECDSA")
|
|
169
|
+
signer.initSign(ecPrivateKey)
|
|
170
|
+
signer.update(payload.toByteArray())
|
|
171
|
+
val signature = signer.sign()
|
|
172
|
+
|
|
173
|
+
val apiStamp =
|
|
174
|
+
ApiStamp(publicSigningKeyHex, "SIGNATURE_SCHEME_TK_API_P256", signature.toHex())
|
|
175
|
+
|
|
176
|
+
return Stamp(
|
|
177
|
+
"X-Stamp",
|
|
178
|
+
Base64.urlSafeEncode(Json.encodeToString(apiStamp).toByteArray())
|
|
179
|
+
)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
private fun privateKeyToKeyPair(privateKey: ByteArray): Pair<ByteArray, ByteArray> {
|
|
183
|
+
val ecPrivateKey =
|
|
184
|
+
EllipticCurves.getEcPrivateKey(EllipticCurves.CurveType.NIST_P256, privateKey)
|
|
185
|
+
|
|
186
|
+
// compute the public key
|
|
187
|
+
val s = ecPrivateKey.s
|
|
188
|
+
val bcSpec = ECNamedCurveTable.getParameterSpec("secp256r1")
|
|
189
|
+
val pubSpec = ECPublicKeySpec(bcSpec.g.multiply(s).normalize(), bcSpec)
|
|
190
|
+
val keyFactory = KeyFactory.getInstance("EC", BouncyCastleProvider.PROVIDER_NAME)
|
|
191
|
+
|
|
192
|
+
val ecPublicKey = EllipticCurves.getEcPublicKey(keyFactory.generatePublic(pubSpec).encoded)
|
|
193
|
+
|
|
194
|
+
// verify the key pair
|
|
195
|
+
EllipticCurves.validatePublicKey(ecPublicKey, ecPrivateKey)
|
|
196
|
+
|
|
197
|
+
// compress it to match turnkey expectations
|
|
198
|
+
val compressedPublicKey =
|
|
199
|
+
ecPublicKey.toBytes(
|
|
200
|
+
EllipticCurves.PointFormatType.COMPRESSED,
|
|
201
|
+
)
|
|
202
|
+
return Pair(compressedPublicKey, privateKey)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
private fun createSharedPreferences(masterKey: MasterKey, context: Context): SharedPreferences {
|
|
206
|
+
return EncryptedSharedPreferences.create(
|
|
207
|
+
context,
|
|
208
|
+
ENCRYPTED_SHARED_PREFERENCES_FILENAME,
|
|
209
|
+
masterKey,
|
|
210
|
+
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
|
|
211
|
+
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
|
|
212
|
+
)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
private fun createMasterKey(context: Context): MasterKey {
|
|
216
|
+
return MasterKey.Builder(context.applicationContext, MASTER_KEY_ALIAS)
|
|
217
|
+
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
|
|
218
|
+
.setUserAuthenticationRequired(false)
|
|
219
|
+
.build()
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
private fun getSharedPreferences(context: Context): SharedPreferences {
|
|
224
|
+
try {
|
|
225
|
+
// Attempt to create or load the EncryptedSharedPreferences file
|
|
226
|
+
val masterKey = createMasterKey(context)
|
|
227
|
+
|
|
228
|
+
return createSharedPreferences(masterKey, context)
|
|
229
|
+
} catch(e: Exception) {
|
|
230
|
+
// Log the Exception
|
|
231
|
+
e.printStackTrace()
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// An error occured creating or retrieving the Shared Preferences file.
|
|
235
|
+
// Delete the existing master key and EncryptedSharedPreferences
|
|
236
|
+
|
|
237
|
+
// first delete the MasterKey
|
|
238
|
+
try {
|
|
239
|
+
val keyStore = KeyStore.getInstance("AndroidKeyStore")
|
|
240
|
+
keyStore.load(null)
|
|
241
|
+
keyStore.deleteEntry(MASTER_KEY_ALIAS)
|
|
242
|
+
} catch (keyStoreDeletionException: Exception) {
|
|
243
|
+
throw RuntimeException("An error occured deleting the Master Key", keyStoreDeletionException)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// attempt to recreate a new EncryptedSharedPreferences file
|
|
247
|
+
try {
|
|
248
|
+
// Create a new MasterKey
|
|
249
|
+
val newMasterKey = createMasterKey(context)
|
|
250
|
+
context.getSharedPreferences(ENCRYPTED_SHARED_PREFERENCES_FILENAME, Context.MODE_PRIVATE).edit().clear().apply()
|
|
251
|
+
context.deleteSharedPreferences(ENCRYPTED_SHARED_PREFERENCES_FILENAME)
|
|
252
|
+
|
|
253
|
+
return createSharedPreferences(newMasterKey, context)
|
|
254
|
+
} catch(retryException: Exception) {
|
|
255
|
+
throw RuntimeException("Couldn't create the required shared preferences file. Ensure you are properly authenticated on this device.", retryException)
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@account-kit/react-native-signer",
|
|
3
|
-
"version": "4.57.0",
|
|
3
|
+
"version": "4.57.2-alpha.0",
|
|
4
4
|
"author": "Alchemy",
|
|
5
5
|
"description": "React Native compatible Smart Wallets signer",
|
|
6
6
|
"source": "./src/index.tsx",
|
|
@@ -142,11 +142,11 @@
|
|
|
142
142
|
"version": "0.42.2"
|
|
143
143
|
},
|
|
144
144
|
"dependencies": {
|
|
145
|
-
"@aa-sdk/core": "^4.57.0",
|
|
146
|
-
"@account-kit/signer": "^4.57.0",
|
|
145
|
+
"@aa-sdk/core": "^4.57.2-alpha.0",
|
|
146
|
+
"@account-kit/signer": "^4.57.2-alpha.0",
|
|
147
147
|
"@turnkey/react-native-passkey-stamper": "^1.0.14",
|
|
148
148
|
"uuid": "^11.1.0",
|
|
149
149
|
"viem": "^2.29.2"
|
|
150
150
|
},
|
|
151
|
-
"gitHead": "
|
|
151
|
+
"gitHead": "97926325edd215f1e36fe50775eb2d16f0d40fa5"
|
|
152
152
|
}
|