@account-kit/react-native-signer 4.53.2-alpha.0 → 4.53.3-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/lib/commonjs/client.js +0 -12
- package/lib/commonjs/client.js.map +1 -1
- package/lib/module/client.js +0 -12
- package/lib/module/client.js.map +1 -1
- package/lib/typescript/commonjs/src/client.d.ts +1 -2
- package/lib/typescript/commonjs/src/client.d.ts.map +1 -1
- package/lib/typescript/module/src/client.d.ts +1 -2
- package/lib/typescript/module/src/client.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/client.ts +0 -16
- 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 +0 -7
- package/android/bin/build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/output-metadata.json +0 -18
- package/android/bin/build/intermediates/aar_metadata/debug/writeDebugAarMetadata/aar-metadata.properties +0 -6
- package/android/bin/build/intermediates/annotation_processor_list/debug/javaPreCompileDebug/annotationProcessors.json +0 -1
- 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 +0 -1
- package/android/bin/build/intermediates/incremental/debug/packageDebugResources/merger.xml +0 -2
- package/android/bin/build/intermediates/incremental/mergeDebugJniLibFolders/merger.xml +0 -2
- package/android/bin/build/intermediates/incremental/mergeDebugShaders/merger.xml +0 -2
- package/android/bin/build/intermediates/incremental/packageDebugAssets/merger.xml +0 -2
- 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 +0 -2
- package/android/bin/build/intermediates/manifest_merge_blame_file/debug/processDebugManifest/manifest-merger-blame-debug-report.txt +0 -7
- package/android/bin/build/intermediates/merged_manifest/debug/processDebugManifest/AndroidManifest.xml +0 -7
- package/android/bin/build/intermediates/navigation_json/debug/extractDeepLinksDebug/navigation.json +0 -1
- package/android/bin/build/intermediates/nested_resources_validation_report/debug/generateDebugResources/nestedResourcesValidationReport.txt +0 -1
- 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 +0 -1
- 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 +0 -2
- 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 +0 -16
- 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 +0 -192
- package/android/bin/generated/java/com/accountkit/reactnativesigner/NativeTEKStamperSpec.class +0 -0
- package/android/bin/generated/jni/CMakeLists.txt +0 -36
- package/android/bin/generated/jni/NativeTEKStamperSpec-generated.cpp +0 -56
- package/android/bin/generated/jni/NativeTEKStamperSpec.h +0 -31
- package/android/bin/generated/jni/react/renderer/components/NativeTEKStamperSpec/ComponentDescriptors.cpp +0 -22
- package/android/bin/generated/jni/react/renderer/components/NativeTEKStamperSpec/ComponentDescriptors.h +0 -24
- package/android/bin/generated/jni/react/renderer/components/NativeTEKStamperSpec/EventEmitters.cpp +0 -16
- package/android/bin/generated/jni/react/renderer/components/NativeTEKStamperSpec/EventEmitters.h +0 -17
- package/android/bin/generated/jni/react/renderer/components/NativeTEKStamperSpec/NativeTEKStamperSpecJSI-generated.cpp +0 -54
- package/android/bin/generated/jni/react/renderer/components/NativeTEKStamperSpec/NativeTEKStamperSpecJSI.h +0 -150
- package/android/bin/generated/jni/react/renderer/components/NativeTEKStamperSpec/Props.cpp +0 -19
- package/android/bin/generated/jni/react/renderer/components/NativeTEKStamperSpec/Props.h +0 -18
- package/android/bin/generated/jni/react/renderer/components/NativeTEKStamperSpec/ShadowNodes.cpp +0 -17
- package/android/bin/generated/jni/react/renderer/components/NativeTEKStamperSpec/ShadowNodes.h +0 -23
- package/android/bin/generated/jni/react/renderer/components/NativeTEKStamperSpec/States.cpp +0 -16
- package/android/bin/generated/jni/react/renderer/components/NativeTEKStamperSpec/States.h +0 -19
- package/android/bin/gradle.properties +0 -5
- package/android/bin/src/main/AndroidManifest.xml +0 -3
- package/android/bin/src/main/java/com/accountkit/reactnativesigner/NativeTEKStamperModule.kt +0 -66
- package/android/bin/src/main/java/com/accountkit/reactnativesigner/ReactNativeSignerPackage.kt +0 -33
- package/android/bin/src/main/java/com/accountkit/reactnativesigner/core/KeyExtensions.kt +0 -77
- package/android/bin/src/main/java/com/accountkit/reactnativesigner/core/TEKManager.kt +0 -89
- package/android/bin/src/main/java/com/accountkit/reactnativesigner/core/TEKStamper.kt +0 -258
- package/android/bin/src/main/java/com/accountkit/reactnativesigner/core/errors/NoInjectedBundleException.kt +0 -3
- package/android/bin/src/main/java/com/accountkit/reactnativesigner/core/errors/NoTEKException.kt +0 -3
- package/android/bin/src/main/java/com/accountkit/reactnativesigner/core/errors/StamperNotInitialized.kt +0 -3
|
@@ -1,258 +0,0 @@
|
|
|
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
|
-
}
|