@solana-mobile/seed-vault-lib 0.4.0 → 0.4.1
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 +12 -12
- package/README.md +10 -2
- package/android/gradlew.bat +89 -89
- package/android/src/main/AndroidManifest.xml +1 -1
- package/android/src/main/java/com/solanamobile/seedvault/model/SigningRequest.kt +44 -44
- package/android/src/main/java/com/solanamobile/seedvault/reactnative/Extensions.kt +98 -98
- package/android/src/main/java/com/solanamobile/seedvault/reactnative/SeedVaultLibReactNativePackage.kt +15 -15
- package/android/src/main/java/com/solanamobile/seedvault/reactnative/SerializationUtils.kt +80 -80
- package/android/src/main/java/com/solanamobile/seedvault/reactnative/SolanaMobileSeedVaultLibModule.kt +34 -13
- package/lib/index.d.ts +162 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +61 -0
- package/lib/index.js.map +1 -0
- package/package.json +38 -43
- package/src/index.ts +3 -0
- package/src/seedVaultEvent.ts +111 -0
- package/src/types.ts +113 -0
- package/src/useSeedVault.ts +100 -0
- package/lib/esm/index.js +0 -116
- package/lib/esm/index.native.js +0 -116
- package/lib/esm/package.json +0 -3
- package/lib/types/index.d.ts +0 -172
- package/lib/types/index.d.ts.map +0 -1
- package/lib/types/index.native.d.ts +0 -172
- package/lib/types/index.native.d.ts.map +0 -1
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
package com.solanamobile.seedvault.reactnative
|
|
2
|
-
|
|
3
|
-
import android.net.Uri
|
|
4
|
-
import com.facebook.react.bridge.*
|
|
5
|
-
import com.solanamobile.seedvault.*
|
|
6
|
-
import kotlinx.serialization.Serializable
|
|
7
|
-
|
|
8
|
-
interface RNWritable {
|
|
9
|
-
fun toWritableMap(): WritableMap
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
data class Account(
|
|
13
|
-
@WalletContractV1.AccountId val id: Long,
|
|
14
|
-
val name: String,
|
|
15
|
-
val derivationPath: Uri,
|
|
16
|
-
val publicKeyEncoded: String
|
|
17
|
-
) : RNWritable {
|
|
18
|
-
override fun toWritableMap() = Arguments.createMap().apply {
|
|
19
|
-
putString("id", "$id")
|
|
20
|
-
putString("name", name)
|
|
21
|
-
putString("derivationPath", "$derivationPath")
|
|
22
|
-
putString("publicKeyEncoded", publicKeyEncoded)
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
data class Seed(
|
|
27
|
-
@WalletContractV1.AuthToken val authToken: Long,
|
|
28
|
-
val name: String,
|
|
29
|
-
@WalletContractV1.Purpose val purpose: Int,
|
|
30
|
-
// val accounts: List<Account> = listOf()
|
|
31
|
-
) : RNWritable {
|
|
32
|
-
override fun toWritableMap() = Arguments.createMap().apply {
|
|
33
|
-
putString("authToken", "$authToken")
|
|
34
|
-
putString("name", name)
|
|
35
|
-
putInt("purpose", purpose)
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
fun List<RNWritable>.toWritableArray() = Arguments.createArray().apply {
|
|
40
|
-
forEach { writable ->
|
|
41
|
-
pushMap(writable.toWritableMap())
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
@Serializable
|
|
46
|
-
sealed interface SeedVaultEvent {
|
|
47
|
-
sealed class SeedEvent(val authToken: Long) : SeedVaultEvent
|
|
48
|
-
class SeedAuthorized(authToken: Long) : SeedEvent(authToken)
|
|
49
|
-
class NewSeedCreated(authToken: Long) : SeedEvent(authToken)
|
|
50
|
-
class ExistingSeedImported(authToken: Long) : SeedEvent(authToken)
|
|
51
|
-
|
|
52
|
-
data class PayloadsSigned(val result: List<SigningResponse>) : SeedVaultEvent
|
|
53
|
-
|
|
54
|
-
data class PublicKeysEvent(val result: List<PublicKeyResponse>) : SeedVaultEvent
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
internal fun SeedVaultEvent.toWritableMap() : WritableMap = Arguments.createMap().apply {
|
|
58
|
-
putString("__type", this@toWritableMap::class.simpleName)
|
|
59
|
-
when (this@toWritableMap) {
|
|
60
|
-
is SeedVaultEvent.SeedEvent -> {
|
|
61
|
-
putString("authToken", authToken.toString())
|
|
62
|
-
}
|
|
63
|
-
is SeedVaultEvent.PayloadsSigned -> {
|
|
64
|
-
putArray("result", Arguments.makeNativeArray(result.map { response ->
|
|
65
|
-
Arguments.createMap().apply {
|
|
66
|
-
putArray("signatures", Arguments.makeNativeArray(response.signatures.map { it.toWritableArray() }))
|
|
67
|
-
putArray("resolvedDerivationPaths", Arguments.makeNativeArray(response.resolvedDerivationPaths.map { it.toString() }))
|
|
68
|
-
}
|
|
69
|
-
}))
|
|
70
|
-
}
|
|
71
|
-
is SeedVaultEvent.PublicKeysEvent -> {
|
|
72
|
-
putArray("result", Arguments.makeNativeArray(result.map { response ->
|
|
73
|
-
Arguments.createMap().apply {
|
|
74
|
-
putArray("publicKey", response.publicKey.toWritableArray())
|
|
75
|
-
putString("publicKeyEncoded", response.publicKeyEncoded)
|
|
76
|
-
putString("resolvedDerivationPath", response.resolvedDerivationPath.toString())
|
|
77
|
-
}
|
|
78
|
-
}))
|
|
79
|
-
}
|
|
80
|
-
}
|
|
1
|
+
package com.solanamobile.seedvault.reactnative
|
|
2
|
+
|
|
3
|
+
import android.net.Uri
|
|
4
|
+
import com.facebook.react.bridge.*
|
|
5
|
+
import com.solanamobile.seedvault.*
|
|
6
|
+
import kotlinx.serialization.Serializable
|
|
7
|
+
|
|
8
|
+
interface RNWritable {
|
|
9
|
+
fun toWritableMap(): WritableMap
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
data class Account(
|
|
13
|
+
@WalletContractV1.AccountId val id: Long,
|
|
14
|
+
val name: String,
|
|
15
|
+
val derivationPath: Uri,
|
|
16
|
+
val publicKeyEncoded: String
|
|
17
|
+
) : RNWritable {
|
|
18
|
+
override fun toWritableMap() = Arguments.createMap().apply {
|
|
19
|
+
putString("id", "$id")
|
|
20
|
+
putString("name", name)
|
|
21
|
+
putString("derivationPath", "$derivationPath")
|
|
22
|
+
putString("publicKeyEncoded", publicKeyEncoded)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
data class Seed(
|
|
27
|
+
@WalletContractV1.AuthToken val authToken: Long,
|
|
28
|
+
val name: String,
|
|
29
|
+
@WalletContractV1.Purpose val purpose: Int,
|
|
30
|
+
// val accounts: List<Account> = listOf()
|
|
31
|
+
) : RNWritable {
|
|
32
|
+
override fun toWritableMap() = Arguments.createMap().apply {
|
|
33
|
+
putString("authToken", "$authToken")
|
|
34
|
+
putString("name", name)
|
|
35
|
+
putInt("purpose", purpose)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
fun List<RNWritable>.toWritableArray() = Arguments.createArray().apply {
|
|
40
|
+
forEach { writable ->
|
|
41
|
+
pushMap(writable.toWritableMap())
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@Serializable
|
|
46
|
+
sealed interface SeedVaultEvent {
|
|
47
|
+
sealed class SeedEvent(val authToken: Long) : SeedVaultEvent
|
|
48
|
+
class SeedAuthorized(authToken: Long) : SeedEvent(authToken)
|
|
49
|
+
class NewSeedCreated(authToken: Long) : SeedEvent(authToken)
|
|
50
|
+
class ExistingSeedImported(authToken: Long) : SeedEvent(authToken)
|
|
51
|
+
|
|
52
|
+
data class PayloadsSigned(val result: List<SigningResponse>) : SeedVaultEvent
|
|
53
|
+
|
|
54
|
+
data class PublicKeysEvent(val result: List<PublicKeyResponse>) : SeedVaultEvent
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
internal fun SeedVaultEvent.toWritableMap() : WritableMap = Arguments.createMap().apply {
|
|
58
|
+
putString("__type", this@toWritableMap::class.simpleName)
|
|
59
|
+
when (this@toWritableMap) {
|
|
60
|
+
is SeedVaultEvent.SeedEvent -> {
|
|
61
|
+
putString("authToken", authToken.toString())
|
|
62
|
+
}
|
|
63
|
+
is SeedVaultEvent.PayloadsSigned -> {
|
|
64
|
+
putArray("result", Arguments.makeNativeArray(result.map { response ->
|
|
65
|
+
Arguments.createMap().apply {
|
|
66
|
+
putArray("signatures", Arguments.makeNativeArray(response.signatures.map { it.toWritableArray() }))
|
|
67
|
+
putArray("resolvedDerivationPaths", Arguments.makeNativeArray(response.resolvedDerivationPaths.map { it.toString() }))
|
|
68
|
+
}
|
|
69
|
+
}))
|
|
70
|
+
}
|
|
71
|
+
is SeedVaultEvent.PublicKeysEvent -> {
|
|
72
|
+
putArray("result", Arguments.makeNativeArray(result.map { response ->
|
|
73
|
+
Arguments.createMap().apply {
|
|
74
|
+
putArray("publicKey", response.publicKey.toWritableArray())
|
|
75
|
+
putString("publicKeyEncoded", response.publicKeyEncoded)
|
|
76
|
+
putString("resolvedDerivationPath", response.resolvedDerivationPath.toString())
|
|
77
|
+
}
|
|
78
|
+
}))
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
81
|
}
|
|
@@ -52,11 +52,17 @@ class SolanaMobileSeedVaultLibModule(val reactContext: ReactApplicationContext)
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
@ReactMethod
|
|
55
|
-
fun
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
fun setActivityResultTimeout(timeoutStr: String, promise: Promise) {
|
|
56
|
+
try {
|
|
57
|
+
val timeout = timeoutStr.toLong()
|
|
58
|
+
activityResultTimeout =
|
|
59
|
+
if (timeout > MINIMUM_ACTIVITY_RESULT_TIMEOUT_MS) timeout
|
|
60
|
+
else if (timeout == 0L) null
|
|
61
|
+
else MINIMUM_ACTIVITY_RESULT_TIMEOUT_MS
|
|
62
|
+
promise.resolve(null)
|
|
63
|
+
} catch (e: NumberFormatException) {
|
|
64
|
+
promise.reject(e)
|
|
65
|
+
}
|
|
60
66
|
}
|
|
61
67
|
|
|
62
68
|
@ReactMethod
|
|
@@ -121,7 +127,7 @@ class SolanaMobileSeedVaultLibModule(val reactContext: ReactApplicationContext)
|
|
|
121
127
|
}
|
|
122
128
|
|
|
123
129
|
@ReactMethod
|
|
124
|
-
fun getAccounts(authToken: String, filterOnColumn: String
|
|
130
|
+
fun getAccounts(authToken: String, filterOnColumn: String?, value: String?, promise: Promise) {
|
|
125
131
|
val application = reactContext.currentActivity?.application!!
|
|
126
132
|
val accountsCursor = Wallet.getAccounts(application, authToken.toLong(),
|
|
127
133
|
WalletContractV1.ACCOUNTS_ALL_COLUMNS, filterOnColumn, value)!!
|
|
@@ -240,19 +246,34 @@ class SolanaMobileSeedVaultLibModule(val reactContext: ReactApplicationContext)
|
|
|
240
246
|
}
|
|
241
247
|
|
|
242
248
|
@ReactMethod
|
|
243
|
-
fun updateAccountName(authToken: String, accountId:
|
|
244
|
-
|
|
245
|
-
|
|
249
|
+
fun updateAccountName(authToken: String, accountId: String, name: String?, promise: Promise) {
|
|
250
|
+
try {
|
|
251
|
+
Wallet.updateAccountName(reactContext, authToken.toLong(), accountId.toLong(), name)
|
|
252
|
+
Log.d(TAG, "Account name updated (to '$name')")
|
|
253
|
+
promise.resolve(null)
|
|
254
|
+
} catch (e: NumberFormatException) {
|
|
255
|
+
promise.reject(e)
|
|
256
|
+
}
|
|
246
257
|
}
|
|
247
258
|
|
|
248
259
|
@ReactMethod
|
|
249
|
-
fun updateAccountIsUserWallet(authToken: String, accountId: String, isUserWallet: Boolean) {
|
|
250
|
-
|
|
260
|
+
fun updateAccountIsUserWallet(authToken: String, accountId: String, isUserWallet: Boolean, promise: Promise) {
|
|
261
|
+
try {
|
|
262
|
+
Wallet.updateAccountIsUserWallet(reactContext, authToken.toLong(), accountId.toLong(), isUserWallet)
|
|
263
|
+
promise.resolve(null)
|
|
264
|
+
} catch (e: NumberFormatException) {
|
|
265
|
+
promise.reject(e)
|
|
266
|
+
}
|
|
251
267
|
}
|
|
252
268
|
|
|
253
269
|
@ReactMethod
|
|
254
|
-
fun updateAccountIsValid(authToken: String, accountId: String, isValid: Boolean) {
|
|
255
|
-
|
|
270
|
+
fun updateAccountIsValid(authToken: String, accountId: String, isValid: Boolean, promise: Promise) {
|
|
271
|
+
try {
|
|
272
|
+
Wallet.updateAccountIsValid(reactContext, authToken.toLong(), accountId.toLong(), isValid)
|
|
273
|
+
promise.resolve(null)
|
|
274
|
+
} catch (e: NumberFormatException) {
|
|
275
|
+
promise.reject(e)
|
|
276
|
+
}
|
|
256
277
|
}
|
|
257
278
|
|
|
258
279
|
@ReactMethod
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { Permission } from "react-native";
|
|
2
|
+
|
|
3
|
+
//#region src/seedVaultEvent.d.ts
|
|
4
|
+
interface SeedVaultError {
|
|
5
|
+
message: string;
|
|
6
|
+
}
|
|
7
|
+
type ActionFailedError = SeedVaultError;
|
|
8
|
+
type NotModifiedError = SeedVaultError;
|
|
9
|
+
declare const SeedVaultEventType: {
|
|
10
|
+
readonly AuthorizeSeedAccess: "SeedAuthorized";
|
|
11
|
+
readonly CreateNewSeed: "NewSeedCreated";
|
|
12
|
+
readonly ImportExistingSeed: "ExistingSeedImported";
|
|
13
|
+
readonly PayloadsSigned: "PayloadsSigned";
|
|
14
|
+
readonly GetPublicKeys: "PublicKeysEvent";
|
|
15
|
+
readonly ContentChange: "SeedVaultContentChange";
|
|
16
|
+
readonly SeedSettingsShown: "SeedSettingsShown";
|
|
17
|
+
};
|
|
18
|
+
type SeedVaultEventType = typeof SeedVaultEventType[keyof typeof SeedVaultEventType];
|
|
19
|
+
interface ISeedVaultEvent {
|
|
20
|
+
__type: SeedVaultEventType;
|
|
21
|
+
}
|
|
22
|
+
type SeedAccessAuthorizedEvent = Readonly<{
|
|
23
|
+
__type: typeof SeedVaultEventType.AuthorizeSeedAccess;
|
|
24
|
+
authToken: string;
|
|
25
|
+
}> & ISeedVaultEvent;
|
|
26
|
+
type AuthorizeSeedAccessEvent = SeedAccessAuthorizedEvent | ActionFailedError;
|
|
27
|
+
type NewSeedCreatedEvent = Readonly<{
|
|
28
|
+
__type: typeof SeedVaultEventType.CreateNewSeed;
|
|
29
|
+
authToken: string;
|
|
30
|
+
}> & ISeedVaultEvent;
|
|
31
|
+
type CreateNewSeedEvent = NewSeedCreatedEvent | ActionFailedError;
|
|
32
|
+
type ExistingSeedImportedEvent = Readonly<{
|
|
33
|
+
__type: typeof SeedVaultEventType.ImportExistingSeed;
|
|
34
|
+
authToken: string;
|
|
35
|
+
}> & ISeedVaultEvent;
|
|
36
|
+
type ImportExistingSeedEvent = ExistingSeedImportedEvent | ActionFailedError;
|
|
37
|
+
type SeedEvent = AuthorizeSeedAccessEvent | CreateNewSeedEvent | ImportExistingSeedEvent;
|
|
38
|
+
type SigningResponse = Readonly<{
|
|
39
|
+
signatures: [[]];
|
|
40
|
+
resolvedDerivationPaths: string[];
|
|
41
|
+
}>;
|
|
42
|
+
type PayloadsSignedEvent = Readonly<{
|
|
43
|
+
__type: typeof SeedVaultEventType.PayloadsSigned;
|
|
44
|
+
result: SigningResponse[];
|
|
45
|
+
}> & ISeedVaultEvent;
|
|
46
|
+
type SignPayloadsEvent = PayloadsSignedEvent | ActionFailedError;
|
|
47
|
+
type PublicKeyResponse = Readonly<{
|
|
48
|
+
publicKey: [];
|
|
49
|
+
publicKeyEncoded: string;
|
|
50
|
+
resolvedDerivationPath: string;
|
|
51
|
+
}>;
|
|
52
|
+
type GotPublicKeyEvent = Readonly<{
|
|
53
|
+
__type: typeof SeedVaultEventType.GetPublicKeys;
|
|
54
|
+
result: PublicKeyResponse[];
|
|
55
|
+
}> & ISeedVaultEvent;
|
|
56
|
+
type PublicKeyEvent = GotPublicKeyEvent | ActionFailedError;
|
|
57
|
+
type SeedVaultContentChangeNotification = Readonly<{
|
|
58
|
+
__type: typeof SeedVaultEventType.ContentChange;
|
|
59
|
+
uris: string[];
|
|
60
|
+
}> & ISeedVaultEvent;
|
|
61
|
+
type SeedVaultContentChange = SeedVaultContentChangeNotification;
|
|
62
|
+
type SeedSettingsShownNotification = Readonly<{
|
|
63
|
+
__type: typeof SeedVaultEventType.SeedSettingsShown;
|
|
64
|
+
}> & ISeedVaultEvent;
|
|
65
|
+
type SeedSettingsShown = SeedSettingsShownNotification;
|
|
66
|
+
type SeedVaultEvent = AuthorizeSeedAccessEvent | CreateNewSeedEvent | ImportExistingSeedEvent | SignPayloadsEvent | PublicKeyEvent | SeedSettingsShown;
|
|
67
|
+
//# sourceMappingURL=seedVaultEvent.d.ts.map
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/types.d.ts
|
|
70
|
+
type AuthToken = number;
|
|
71
|
+
type Base64EncodedAddress = string;
|
|
72
|
+
type Base64EncodedSignature = string;
|
|
73
|
+
type Base64EncodedPayload = string;
|
|
74
|
+
type Base64EncodedMessage = Base64EncodedPayload;
|
|
75
|
+
type Base64EncodedTransaction = Base64EncodedPayload;
|
|
76
|
+
type DerivationPath = string;
|
|
77
|
+
type Account = Readonly<{
|
|
78
|
+
id: number;
|
|
79
|
+
name: string;
|
|
80
|
+
derivationPath: DerivationPath;
|
|
81
|
+
publicKeyEncoded: Base64EncodedAddress;
|
|
82
|
+
}>;
|
|
83
|
+
declare const SeedPurpose: {
|
|
84
|
+
readonly SignSolanaTransaction: 0;
|
|
85
|
+
};
|
|
86
|
+
type SeedPurpose = typeof SeedPurpose[keyof typeof SeedPurpose];
|
|
87
|
+
type Seed = Readonly<{
|
|
88
|
+
authToken: AuthToken;
|
|
89
|
+
name: string;
|
|
90
|
+
purpose: SeedPurpose;
|
|
91
|
+
}>;
|
|
92
|
+
type SeedPublicKey = Readonly<{
|
|
93
|
+
publicKey: Uint8Array;
|
|
94
|
+
publicKeyEncoded: Base64EncodedAddress;
|
|
95
|
+
resolvedDerivationPath: DerivationPath;
|
|
96
|
+
}>;
|
|
97
|
+
type SigningRequest = Readonly<{
|
|
98
|
+
payload: Base64EncodedPayload;
|
|
99
|
+
requestedSignatures: DerivationPath[];
|
|
100
|
+
}>;
|
|
101
|
+
type SigningResult = Readonly<{
|
|
102
|
+
signatures: Base64EncodedSignature[];
|
|
103
|
+
resolvedDerivationPaths: DerivationPath[];
|
|
104
|
+
}>;
|
|
105
|
+
interface AuthorizeSeedAPI {
|
|
106
|
+
hasUnauthorizedSeeds(): Promise<boolean>;
|
|
107
|
+
hasUnauthorizedSeedsForPurpose(purpose: SeedPurpose): Promise<boolean>;
|
|
108
|
+
getAuthorizedSeeds(): Promise<Seed[]>;
|
|
109
|
+
authorizeNewSeed(): Promise<{
|
|
110
|
+
authToken: AuthToken;
|
|
111
|
+
}>;
|
|
112
|
+
deauthorizeSeed(authToken: AuthToken): void;
|
|
113
|
+
}
|
|
114
|
+
interface AccountAPI {
|
|
115
|
+
getAccounts(authToken: AuthToken, filterOnColumn?: string, value?: string): Promise<Account[]>;
|
|
116
|
+
getUserWallets(authToken: AuthToken): Promise<Account[]>;
|
|
117
|
+
updateAccountName(authToken: AuthToken, accountId: string, name?: string): Promise<void>;
|
|
118
|
+
updateAccountIsUserWallet(authToken: AuthToken, accountId: string, isUserWallet: boolean): Promise<void>;
|
|
119
|
+
updateAccountIsValid(authToken: AuthToken, accountId: string, isValid: boolean): Promise<void>;
|
|
120
|
+
}
|
|
121
|
+
interface CreateNewSeedAPI {
|
|
122
|
+
createNewSeed(): Promise<{
|
|
123
|
+
authToken: AuthToken;
|
|
124
|
+
}>;
|
|
125
|
+
}
|
|
126
|
+
interface ImportExistingSeedAPI {
|
|
127
|
+
importExistingSeed(): Promise<{
|
|
128
|
+
authToken: AuthToken;
|
|
129
|
+
}>;
|
|
130
|
+
}
|
|
131
|
+
interface PublicKeyAPI {
|
|
132
|
+
getPublicKey(authToken: AuthToken, derivationPath: DerivationPath): Promise<SeedPublicKey>;
|
|
133
|
+
getPublicKeys(authToken: AuthToken, derivationPaths: DerivationPath[]): Promise<SeedPublicKey[]>;
|
|
134
|
+
resolveDerivationPath(derivationPath: DerivationPath): Promise<DerivationPath>;
|
|
135
|
+
resolveDerivationPathForPurpose(derivationPath: DerivationPath, purpose: SeedPurpose): Promise<DerivationPath>;
|
|
136
|
+
}
|
|
137
|
+
interface SignMessagesAPI {
|
|
138
|
+
signMessage(authToken: AuthToken, derivationPath: DerivationPath, message: Base64EncodedMessage): Promise<SigningResult>;
|
|
139
|
+
signMessages(authToken: AuthToken, signingRequests: SigningRequest[]): Promise<SigningResult[]>;
|
|
140
|
+
}
|
|
141
|
+
interface SignTransactionsAPI {
|
|
142
|
+
signTransaction(authToken: AuthToken, derivationPath: DerivationPath, transaction: Base64EncodedTransaction): Promise<SigningResult>;
|
|
143
|
+
signTransactions(authToken: AuthToken, signingRequests: SigningRequest[]): Promise<SigningResult[]>;
|
|
144
|
+
}
|
|
145
|
+
interface SeedVaultAvailabilityAPI {
|
|
146
|
+
isSeedVaultAvailable(allowSimulated: boolean): Promise<boolean>;
|
|
147
|
+
}
|
|
148
|
+
interface ShowSeedSettingsAPI {
|
|
149
|
+
showSeedSettings(authToken: AuthToken): Promise<void>;
|
|
150
|
+
}
|
|
151
|
+
interface SeedVaultAPI extends AuthorizeSeedAPI, AccountAPI, CreateNewSeedAPI, ImportExistingSeedAPI, PublicKeyAPI, SeedVaultAvailabilityAPI, SignMessagesAPI, SignTransactionsAPI, ShowSeedSettingsAPI {}
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region src/useSeedVault.d.ts
|
|
154
|
+
declare const SeedVaultPermissionAndroid: Permission;
|
|
155
|
+
declare const SeedVaultPrivilegedPermissionAndroid: Permission;
|
|
156
|
+
declare function useSeedVault(handleSeedVaultEvent: (event: SeedVaultEvent) => void, handleContentChange: (event: SeedVaultContentChange) => void): void;
|
|
157
|
+
declare const SeedVault: SeedVaultAPI;
|
|
158
|
+
//# sourceMappingURL=useSeedVault.d.ts.map
|
|
159
|
+
|
|
160
|
+
//#endregion
|
|
161
|
+
export { Account, ActionFailedError, AuthorizeSeedAccessEvent, CreateNewSeedEvent, ExistingSeedImportedEvent, GotPublicKeyEvent, ISeedVaultEvent, ImportExistingSeedEvent, NewSeedCreatedEvent, NotModifiedError, PayloadsSignedEvent, PublicKeyEvent, PublicKeyResponse, Seed, SeedAccessAuthorizedEvent, SeedEvent, SeedPublicKey, SeedPurpose, SeedSettingsShown, SeedSettingsShownNotification, SeedVault, SeedVaultAPI, SeedVaultContentChange, SeedVaultContentChangeNotification, SeedVaultError, SeedVaultEvent, SeedVaultEventType, SeedVaultPermissionAndroid, SeedVaultPrivilegedPermissionAndroid, SignPayloadsEvent, SigningRequest, SigningResponse, SigningResult, useSeedVault };
|
|
162
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/seedVaultEvent.ts","../../src/types.ts","../../src/useSeedVault.ts"],"sourcesContent":[],"mappings":";;;UAEiB,cAAA;;;AAAA,KAIL,iBAAA,GAAoB,cAJD;AAInB,KACA,gBAAA,GAAmB,cADC;AACpB,cAIC,kBAJkB,EAAA;EAIlB,SAAA,mBAQH,EAAA,gBAAA;EACE,SAAA,aAAkB,EAAA,gBAAA;EAAA,SAAA,kBAAA,EAAA,sBAAA;WAAU,cAAA,EAAA,gBAAA;WAAgC,aAAA,EAAA,iBAAA;EAAkB,SAAA,aAAA,EAAA,wBAAA;EAEzE,SAAA,iBAAe,EAAA,mBACpB;AAIZ,CAAA;AAAqC,KAPzB,kBAAA,GAOyB,OAPG,kBAOH,CAAA,MAAA,OAPmC,kBAOnC,CAAA;AAClB,UANF,eAAA,CAMqB;QADE,EAJ5B,kBAI4B;;AAIrB,KAJP,yBAAA,GAA4B,QAIrB,CAAA;EAEP,MAAA,EAAA,OALO,kBAAA,CAAmB,mBAKF;EAAA,SAAA,EAAA,MAAA;KAFhC,eAEmC;AAA4B,KAAvD,wBAAA,GAA2B,yBAA4B,GAAA,iBAAA;AAAiB,KAGxE,mBAAA,GAAsB,QAHkD,CAAA;EAGxE,MAAA,EAAA,OACO,kBAAA,CAAmB,aADP;EAAA,SAAA,EAAA,MAAA;KAI3B,eAHe;AADe,KAMtB,kBAAA,GAAqB,mBANC,GA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,EAAA,CAAA,KAAA,EEoDZ,sBFpDY,EAAA,GAAA,IAAA,CAAA,EAAA,IAAA;AAIhC,cEwFA,SFhFH,EEgFc,YFhFd;AACV"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import { NativeEventEmitter, NativeModules, PermissionsAndroid, Platform } from "react-native";
|
|
3
|
+
//#region src/seedVaultEvent.ts
|
|
4
|
+
const SeedVaultEventType = {
|
|
5
|
+
AuthorizeSeedAccess: "SeedAuthorized",
|
|
6
|
+
CreateNewSeed: "NewSeedCreated",
|
|
7
|
+
ImportExistingSeed: "ExistingSeedImported",
|
|
8
|
+
PayloadsSigned: "PayloadsSigned",
|
|
9
|
+
GetPublicKeys: "PublicKeysEvent",
|
|
10
|
+
ContentChange: "SeedVaultContentChange",
|
|
11
|
+
SeedSettingsShown: "SeedSettingsShown"
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/types.ts
|
|
15
|
+
const SeedPurpose = { SignSolanaTransaction: 0 };
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/useSeedVault.ts
|
|
18
|
+
const LINKING_ERROR = "The package 'solana-mobile-seed-vault-lib' doesn't seem to be linked. Make sure: \n\n- You rebuilt the app after installing the package\n- If you are using Lerna workspaces\n - You have added `@solana-mobile/seed-vault-lib` as an explicit dependency, and\n - You have added `@solana-mobile/seed-vault-lib` to the `nohoist` section of your package.json\n- You are not using Expo managed workflow\n";
|
|
19
|
+
const SolanaMobileSeedVaultLib = Platform.OS === "android" && NativeModules.SolanaMobileSeedVaultLib ? NativeModules.SolanaMobileSeedVaultLib : new Proxy({}, { get() {
|
|
20
|
+
throw new Error(Platform.OS !== "android" ? "The package `solana-mobile-seed-vault-lib` is only compatible with React Native Android" : LINKING_ERROR);
|
|
21
|
+
} });
|
|
22
|
+
const SeedVaultPermissionAndroid = "com.solanamobile.seedvault.ACCESS_SEED_VAULT";
|
|
23
|
+
const SeedVaultPrivilegedPermissionAndroid = "com.solanamobile.seedvault.ACCESS_SEED_VAULT_PRIVILEGED";
|
|
24
|
+
const checkSeedVaultPermission = async () => {
|
|
25
|
+
if (!(await PermissionsAndroid.check("com.solanamobile.seedvault.ACCESS_SEED_VAULT") || await PermissionsAndroid.check("com.solanamobile.seedvault.ACCESS_SEED_VAULT_PRIVILEGED"))) throw new Error("You do not have permission to access Seed Vault. You must request permission to use Seed Vault.");
|
|
26
|
+
};
|
|
27
|
+
const checkIsSeedVaultAvailable = async (allowSimulated = false) => {
|
|
28
|
+
if (!await SolanaMobileSeedVaultLib.isSeedVaultAvailable(allowSimulated)) throw new Error(allowSimulated ? "Seed Vault is not available on this device, please install the Seed Vault Simulator" : "Seed Vault is not available on this device");
|
|
29
|
+
};
|
|
30
|
+
const SEED_VAULT_EVENT_BRIDGE_NAME = "SeedVaultEventBridge";
|
|
31
|
+
function useSeedVault(handleSeedVaultEvent, handleContentChange) {
|
|
32
|
+
const seedVaultEventHandler = useRef(handleSeedVaultEvent);
|
|
33
|
+
const contentChangeHandler = useRef(handleContentChange);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
seedVaultEventHandler.current = handleSeedVaultEvent;
|
|
36
|
+
contentChangeHandler.current = handleContentChange;
|
|
37
|
+
});
|
|
38
|
+
checkIsSeedVaultAvailable(true);
|
|
39
|
+
checkSeedVaultPermission();
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
const listener = new NativeEventEmitter().addListener(SEED_VAULT_EVENT_BRIDGE_NAME, (nativeEvent) => {
|
|
42
|
+
if (isContentChangeEvent(nativeEvent)) contentChangeHandler.current(nativeEvent);
|
|
43
|
+
else if (isSeedVaultEvent(nativeEvent)) seedVaultEventHandler.current(nativeEvent);
|
|
44
|
+
else console.warn("Unexpected native event type");
|
|
45
|
+
});
|
|
46
|
+
return () => {
|
|
47
|
+
listener.remove();
|
|
48
|
+
};
|
|
49
|
+
}, []);
|
|
50
|
+
}
|
|
51
|
+
function isSeedVaultEvent(nativeEvent) {
|
|
52
|
+
return Object.values(SeedVaultEventType).includes(nativeEvent.__type);
|
|
53
|
+
}
|
|
54
|
+
function isContentChangeEvent(nativeEvent) {
|
|
55
|
+
return nativeEvent.__type == SeedVaultEventType.ContentChange;
|
|
56
|
+
}
|
|
57
|
+
const SeedVault = SolanaMobileSeedVaultLib;
|
|
58
|
+
//#endregion
|
|
59
|
+
export { SeedPurpose, SeedVault, SeedVaultEventType, SeedVaultPermissionAndroid, SeedVaultPrivilegedPermissionAndroid, useSeedVault };
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/seedVaultEvent.ts","../src/types.ts","../src/useSeedVault.ts"],"sourcesContent":["\n// ERRORS\nexport interface SeedVaultError {\n message: string;\n}\n\nexport type ActionFailedError = SeedVaultError;\nexport type NotModifiedError = SeedVaultError;\n\n// EVENTS\n// Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/\nexport const SeedVaultEventType = {\n AuthorizeSeedAccess: \"SeedAuthorized\",\n CreateNewSeed: \"NewSeedCreated\",\n ImportExistingSeed: \"ExistingSeedImported\",\n PayloadsSigned: \"PayloadsSigned\",\n GetPublicKeys: \"PublicKeysEvent\",\n ContentChange: \"SeedVaultContentChange\",\n SeedSettingsShown: \"SeedSettingsShown\"\n} as const;\nexport type SeedVaultEventType = typeof SeedVaultEventType[keyof typeof SeedVaultEventType]\n\nexport interface ISeedVaultEvent {\n __type: SeedVaultEventType;\n}\n\n// Authorize Seed Access\nexport type SeedAccessAuthorizedEvent = Readonly<{\n __type: typeof SeedVaultEventType.AuthorizeSeedAccess;\n authToken: string\n}> &\n ISeedVaultEvent;\n\nexport type AuthorizeSeedAccessEvent = SeedAccessAuthorizedEvent | ActionFailedError\n\n// Create New Seed\nexport type NewSeedCreatedEvent = Readonly<{\n __type: typeof SeedVaultEventType.CreateNewSeed;\n authToken: string\n}> &\n ISeedVaultEvent;\n\nexport type CreateNewSeedEvent = NewSeedCreatedEvent | ActionFailedError\n\n// Import Existing Seed\nexport type ExistingSeedImportedEvent = Readonly<{\n __type: typeof SeedVaultEventType.ImportExistingSeed;\n authToken: string\n}> &\n ISeedVaultEvent;\n\nexport type ImportExistingSeedEvent = ExistingSeedImportedEvent | ActionFailedError\n\nexport type SeedEvent = \n | AuthorizeSeedAccessEvent \n | CreateNewSeedEvent \n | ImportExistingSeedEvent\n\n// Sign Payloads\nexport type SigningResponse = Readonly<{\n signatures: [[]],\n resolvedDerivationPaths: string[]\n}>\n\nexport type PayloadsSignedEvent = Readonly<{\n __type: typeof SeedVaultEventType.PayloadsSigned;\n result: SigningResponse[]\n}> &\n ISeedVaultEvent;\n\nexport type SignPayloadsEvent = PayloadsSignedEvent | ActionFailedError\n\n// Get Public Keys\nexport type PublicKeyResponse = Readonly<{\n publicKey: [],\n publicKeyEncoded: string,\n resolvedDerivationPath: string\n}>\n\nexport type GotPublicKeyEvent = Readonly<{\n __type: typeof SeedVaultEventType.GetPublicKeys;\n result: PublicKeyResponse[]\n}> &\n ISeedVaultEvent;\n\nexport type PublicKeyEvent = GotPublicKeyEvent | ActionFailedError\n\n// Content Change\nexport type SeedVaultContentChangeNotification = Readonly<{\n __type: typeof SeedVaultEventType.ContentChange;\n uris: string[]\n}> &\n ISeedVaultEvent;\n\nexport type SeedVaultContentChange = SeedVaultContentChangeNotification\n\n// Show Seed Settings\nexport type SeedSettingsShownNotification = Readonly<{\n __type: typeof SeedVaultEventType.SeedSettingsShown;\n}> &\n ISeedVaultEvent;\n\nexport type SeedSettingsShown = SeedSettingsShownNotification\n\nexport type SeedVaultEvent = \n | AuthorizeSeedAccessEvent \n | CreateNewSeedEvent \n | ImportExistingSeedEvent\n | SignPayloadsEvent\n | PublicKeyEvent\n | SeedSettingsShown","type AuthToken = number;\n\ntype Base64EncodedAddress = string;\n\ntype Base64EncodedSignature = string;\n\ntype Base64EncodedPayload = string;\n\ntype Base64EncodedMessage = Base64EncodedPayload;\n\ntype Base64EncodedTransaction = Base64EncodedPayload;\n\ntype DerivationPath = string;\n\nexport type Account = Readonly<{\n id: number,\n name: string,\n derivationPath: DerivationPath,\n publicKeyEncoded: Base64EncodedAddress\n}>;\n\nexport const SeedPurpose = {\n SignSolanaTransaction: 0,\n} as const\nexport type SeedPurpose = typeof SeedPurpose[keyof typeof SeedPurpose]\n\nexport type Seed = Readonly<{\n authToken: AuthToken,\n name: string,\n purpose: SeedPurpose\n}>;\n\nexport type SeedPublicKey = Readonly<{\n publicKey: Uint8Array,\n publicKeyEncoded: Base64EncodedAddress,\n resolvedDerivationPath: DerivationPath\n}>\n\nexport type SigningRequest = Readonly<{\n payload: Base64EncodedPayload,\n requestedSignatures: DerivationPath[]\n}>;\n\nexport type SigningResult = Readonly<{\n signatures: Base64EncodedSignature[],\n resolvedDerivationPaths: DerivationPath[]\n}>;\n\ninterface AuthorizeSeedAPI {\n hasUnauthorizedSeeds(): Promise<boolean>\n hasUnauthorizedSeedsForPurpose(purpose: SeedPurpose): Promise<boolean>\n getAuthorizedSeeds(): Promise<Seed[]>\n authorizeNewSeed(): Promise<{authToken: AuthToken}>\n deauthorizeSeed(authToken: AuthToken): void\n}\n\ninterface AccountAPI {\n getAccounts(authToken: AuthToken, filterOnColumn?: string, value?: string): Promise<Account[]>\n getUserWallets(authToken: AuthToken): Promise<Account[]>\n updateAccountName(authToken: AuthToken, accountId: string, name?: string): Promise<void>\n updateAccountIsUserWallet(authToken: AuthToken, accountId: string, isUserWallet: boolean): Promise<void>\n updateAccountIsValid(authToken: AuthToken, accountId: string, isValid: boolean): Promise<void>\n}\n\ninterface CreateNewSeedAPI {\n createNewSeed(): Promise<{authToken: AuthToken}>\n}\n\n// TODO\n// interface ImplementationLimitsAPI {\n// getImplementationLimits(): void\n// getImplementationLimitsForPurpose()\n// }\n\ninterface ImportExistingSeedAPI {\n importExistingSeed(): Promise<{authToken: AuthToken}>\n}\n\ninterface PublicKeyAPI {\n getPublicKey(authToken: AuthToken, derivationPath: DerivationPath): Promise<SeedPublicKey>\n getPublicKeys(authToken: AuthToken, derivationPaths: DerivationPath[]): Promise<SeedPublicKey[]>\n resolveDerivationPath(derivationPath: DerivationPath): Promise<DerivationPath>\n resolveDerivationPathForPurpose(derivationPath: DerivationPath, purpose: SeedPurpose): Promise<DerivationPath>\n}\n\ninterface SignMessagesAPI {\n signMessage(authToken: AuthToken, derivationPath: DerivationPath, message: Base64EncodedMessage): Promise<SigningResult>\n signMessages(authToken: AuthToken, signingRequests: SigningRequest[]): Promise<SigningResult[]>\n}\n\ninterface SignTransactionsAPI {\n signTransaction(authToken: AuthToken, derivationPath: DerivationPath, transaction: Base64EncodedTransaction): Promise<SigningResult>\n signTransactions(authToken: AuthToken, signingRequests: SigningRequest[]): Promise<SigningResult[]>\n}\n\ninterface SeedVaultAvailabilityAPI {\n isSeedVaultAvailable(allowSimulated: boolean): Promise<boolean>\n}\n\ninterface ShowSeedSettingsAPI {\n showSeedSettings(authToken: AuthToken): Promise<void>\n}\n\nexport interface SeedVaultAPI \n extends AuthorizeSeedAPI,\n AccountAPI,\n CreateNewSeedAPI,\n ImportExistingSeedAPI,\n PublicKeyAPI,\n SeedVaultAvailabilityAPI,\n SignMessagesAPI, \n SignTransactionsAPI,\n ShowSeedSettingsAPI {}\n","import { useEffect, useRef } from 'react';\nimport { NativeEventEmitter, NativeModules, Permission, PermissionsAndroid, Platform } from 'react-native';\nimport { SeedVaultContentChange, SeedVaultEvent, SeedVaultEventType } from './seedVaultEvent';\nimport { SeedVaultAPI } from './types';\n\nconst LINKING_ERROR =\n `The package 'solana-mobile-seed-vault-lib' doesn't seem to be linked. Make sure: \\n\\n` +\n '- You rebuilt the app after installing the package\\n' +\n '- If you are using Lerna workspaces\\n' +\n ' - You have added `@solana-mobile/seed-vault-lib` as an explicit dependency, and\\n' +\n ' - You have added `@solana-mobile/seed-vault-lib` to the `nohoist` section of your package.json\\n' +\n '- You are not using Expo managed workflow\\n';\n\nconst SolanaMobileSeedVaultLib =\n Platform.OS === 'android' && NativeModules.SolanaMobileSeedVaultLib\n ? NativeModules.SolanaMobileSeedVaultLib\n : new Proxy(\n {},\n {\n get() {\n throw new Error(\n Platform.OS !== 'android'\n ? 'The package `solana-mobile-seed-vault-lib` is only compatible with React Native Android'\n : LINKING_ERROR,\n );\n },\n },\n );\n\nexport const SeedVaultPermissionAndroid = 'com.solanamobile.seedvault.ACCESS_SEED_VAULT' as Permission;\nexport const SeedVaultPrivilegedPermissionAndroid = 'com.solanamobile.seedvault.ACCESS_SEED_VAULT_PRIVILEGED' as Permission;\n\nconst checkSeedVaultPermission = async () => {\n const granted = await PermissionsAndroid.check(SeedVaultPermissionAndroid) \n || await PermissionsAndroid.check(SeedVaultPrivilegedPermissionAndroid);\n\n if (!granted) {\n throw new Error(\n 'You do not have permission to access Seed Vault. You must request permission to use Seed Vault.'\n )\n }\n}\n\nconst checkIsSeedVaultAvailable = async (allowSimulated: boolean = false) => {\n const seedVaultAvailable = await SolanaMobileSeedVaultLib.isSeedVaultAvailable(allowSimulated);\n\n if (!seedVaultAvailable) {\n throw new Error(\n allowSimulated \n ? 'Seed Vault is not available on this device, please install the Seed Vault Simulator' \n : 'Seed Vault is not available on this device'\n )\n }\n}\n\nconst SEED_VAULT_EVENT_BRIDGE_NAME = 'SeedVaultEventBridge';\n\nexport function useSeedVault(\n handleSeedVaultEvent: (event: SeedVaultEvent) => void,\n handleContentChange: (event: SeedVaultContentChange) => void,\n) {\n\n const seedVaultEventHandler = useRef(handleSeedVaultEvent);\n const contentChangeHandler = useRef(handleContentChange);\n useEffect(() => {\n seedVaultEventHandler.current = handleSeedVaultEvent;\n contentChangeHandler.current = handleContentChange;\n });\n\n checkIsSeedVaultAvailable(true);\n checkSeedVaultPermission();\n\n // Start native event listener\n useEffect(() => {\n const seedVaultEventEmitter = new NativeEventEmitter();\n const listener = seedVaultEventEmitter.addListener(SEED_VAULT_EVENT_BRIDGE_NAME, (nativeEvent) => {\n if (isContentChangeEvent(nativeEvent)) {\n contentChangeHandler.current(nativeEvent as SeedVaultContentChange)\n } else if (isSeedVaultEvent(nativeEvent)) {\n seedVaultEventHandler.current(nativeEvent as SeedVaultEvent)\n } else {\n console.warn('Unexpected native event type');\n }\n });\n\n return () => {\n listener.remove();\n };\n }, []);\n}\n\nfunction isSeedVaultEvent(nativeEvent: any): boolean {\n return Object.values(SeedVaultEventType).includes(nativeEvent.__type);\n}\n\nfunction isContentChangeEvent(nativeEvent: any): boolean {\n return nativeEvent.__type == SeedVaultEventType.ContentChange;\n}\n\nexport const SeedVault: SeedVaultAPI = SolanaMobileSeedVaultLib as SeedVaultAPI"],"mappings":";;;AAWA,MAAa,qBAAqB;CAC9B,qBAAqB;CACrB,eAAe;CACf,oBAAoB;CACpB,gBAAgB;CAChB,eAAe;CACf,eAAe;CACf,mBAAmB;CACtB;;;ACED,MAAa,cAAc,EACvB,uBAAuB,GAC1B;;;AClBD,MAAM,gBACF;AAOJ,MAAM,2BACF,SAAS,OAAO,aAAa,cAAc,2BACrC,cAAc,2BACd,IAAI,MACA,EAAE,EACF,EACI,MAAM;AACF,OAAM,IAAI,MACN,SAAS,OAAO,YACV,4FACA,cACT;GAER,CACJ;AAEX,MAAa,6BAA6B;AAC1C,MAAa,uCAAuC;AAEpD,MAAM,2BAA2B,YAAY;AAIzC,KAAI,EAHY,MAAM,mBAAmB,MAAA,+CAAiC,IACnE,MAAM,mBAAmB,MAAA,0DAA2C,EAGvE,OAAM,IAAI,MACN,kGACH;;AAIT,MAAM,4BAA4B,OAAO,iBAA0B,UAAU;AAGzE,KAAI,CAFuB,MAAM,yBAAyB,qBAAqB,eAAe,CAG1F,OAAM,IAAI,MACN,iBACM,wFACA,6CACT;;AAIT,MAAM,+BAA+B;AAErC,SAAgB,aACZ,sBACA,qBACF;CAEE,MAAM,wBAAwB,OAAO,qBAAqB;CAC1D,MAAM,uBAAuB,OAAO,oBAAoB;AACxD,iBAAgB;AACZ,wBAAsB,UAAU;AAChC,uBAAqB,UAAU;GACjC;AAEF,2BAA0B,KAAK;AAC/B,2BAA0B;AAG1B,iBAAgB;EAEZ,MAAM,WADwB,IAAI,oBAAoB,CACf,YAAY,+BAA+B,gBAAgB;AAC9F,OAAI,qBAAqB,YAAY,CACjC,sBAAqB,QAAQ,YAAsC;YAC5D,iBAAiB,YAAY,CACpC,uBAAsB,QAAQ,YAA8B;OAE5D,SAAQ,KAAK,+BAA+B;IAElD;AAEF,eAAa;AACT,YAAS,QAAQ;;IAEtB,EAAE,CAAC;;AAGV,SAAS,iBAAiB,aAA2B;AACjD,QAAO,OAAO,OAAO,mBAAmB,CAAC,SAAS,YAAY,OAAO;;AAGzE,SAAS,qBAAqB,aAA2B;AACrD,QAAO,YAAY,UAAU,mBAAmB;;AAGpD,MAAa,YAA0B"}
|
package/package.json
CHANGED
|
@@ -1,44 +1,39 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
},
|
|
41
|
-
"peerDependencies": {
|
|
42
|
-
"react-native": ">0.69"
|
|
43
|
-
}
|
|
44
|
-
}
|
|
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.4.1",
|
|
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/index.js",
|
|
11
|
+
"react-native": "lib/index.js",
|
|
12
|
+
"module": "lib/index.js",
|
|
13
|
+
"types": "lib/index.d.ts",
|
|
14
|
+
"files": [
|
|
15
|
+
"android",
|
|
16
|
+
"!android/build",
|
|
17
|
+
"lib",
|
|
18
|
+
"src",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@solana/web3.js": "^1.95.4",
|
|
26
|
+
"@types/react": "^18.3.12",
|
|
27
|
+
"@types/react-native": "^0.69.3",
|
|
28
|
+
"shx": "^0.3.4"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"react": ">=18",
|
|
32
|
+
"react-native": ">0.69"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"clean": "shx rm -rf lib/*",
|
|
36
|
+
"build": "tsdown",
|
|
37
|
+
"build:watch": "tsdown --watch"
|
|
38
|
+
}
|
|
39
|
+
}
|
package/src/index.ts
ADDED