@solana-mobile/seed-vault-lib 0.3.3 → 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.
@@ -0,0 +1,111 @@
1
+
2
+ // ERRORS
3
+ export interface SeedVaultError {
4
+ message: string;
5
+ }
6
+
7
+ export type ActionFailedError = SeedVaultError;
8
+ export type NotModifiedError = SeedVaultError;
9
+
10
+ // EVENTS
11
+ // Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
12
+ export const SeedVaultEventType = {
13
+ AuthorizeSeedAccess: "SeedAuthorized",
14
+ CreateNewSeed: "NewSeedCreated",
15
+ ImportExistingSeed: "ExistingSeedImported",
16
+ PayloadsSigned: "PayloadsSigned",
17
+ GetPublicKeys: "PublicKeysEvent",
18
+ ContentChange: "SeedVaultContentChange",
19
+ SeedSettingsShown: "SeedSettingsShown"
20
+ } as const;
21
+ export type SeedVaultEventType = typeof SeedVaultEventType[keyof typeof SeedVaultEventType]
22
+
23
+ export interface ISeedVaultEvent {
24
+ __type: SeedVaultEventType;
25
+ }
26
+
27
+ // Authorize Seed Access
28
+ export type SeedAccessAuthorizedEvent = Readonly<{
29
+ __type: typeof SeedVaultEventType.AuthorizeSeedAccess;
30
+ authToken: string
31
+ }> &
32
+ ISeedVaultEvent;
33
+
34
+ export type AuthorizeSeedAccessEvent = SeedAccessAuthorizedEvent | ActionFailedError
35
+
36
+ // Create New Seed
37
+ export type NewSeedCreatedEvent = Readonly<{
38
+ __type: typeof SeedVaultEventType.CreateNewSeed;
39
+ authToken: string
40
+ }> &
41
+ ISeedVaultEvent;
42
+
43
+ export type CreateNewSeedEvent = NewSeedCreatedEvent | ActionFailedError
44
+
45
+ // Import Existing Seed
46
+ export type ExistingSeedImportedEvent = Readonly<{
47
+ __type: typeof SeedVaultEventType.ImportExistingSeed;
48
+ authToken: string
49
+ }> &
50
+ ISeedVaultEvent;
51
+
52
+ export type ImportExistingSeedEvent = ExistingSeedImportedEvent | ActionFailedError
53
+
54
+ export type SeedEvent =
55
+ | AuthorizeSeedAccessEvent
56
+ | CreateNewSeedEvent
57
+ | ImportExistingSeedEvent
58
+
59
+ // Sign Payloads
60
+ export type SigningResponse = Readonly<{
61
+ signatures: [[]],
62
+ resolvedDerivationPaths: string[]
63
+ }>
64
+
65
+ export type PayloadsSignedEvent = Readonly<{
66
+ __type: typeof SeedVaultEventType.PayloadsSigned;
67
+ result: SigningResponse[]
68
+ }> &
69
+ ISeedVaultEvent;
70
+
71
+ export type SignPayloadsEvent = PayloadsSignedEvent | ActionFailedError
72
+
73
+ // Get Public Keys
74
+ export type PublicKeyResponse = Readonly<{
75
+ publicKey: [],
76
+ publicKeyEncoded: string,
77
+ resolvedDerivationPath: string
78
+ }>
79
+
80
+ export type GotPublicKeyEvent = Readonly<{
81
+ __type: typeof SeedVaultEventType.GetPublicKeys;
82
+ result: PublicKeyResponse[]
83
+ }> &
84
+ ISeedVaultEvent;
85
+
86
+ export type PublicKeyEvent = GotPublicKeyEvent | ActionFailedError
87
+
88
+ // Content Change
89
+ export type SeedVaultContentChangeNotification = Readonly<{
90
+ __type: typeof SeedVaultEventType.ContentChange;
91
+ uris: string[]
92
+ }> &
93
+ ISeedVaultEvent;
94
+
95
+ export type SeedVaultContentChange = SeedVaultContentChangeNotification
96
+
97
+ // Show Seed Settings
98
+ export type SeedSettingsShownNotification = Readonly<{
99
+ __type: typeof SeedVaultEventType.SeedSettingsShown;
100
+ }> &
101
+ ISeedVaultEvent;
102
+
103
+ export type SeedSettingsShown = SeedSettingsShownNotification
104
+
105
+ export type SeedVaultEvent =
106
+ | AuthorizeSeedAccessEvent
107
+ | CreateNewSeedEvent
108
+ | ImportExistingSeedEvent
109
+ | SignPayloadsEvent
110
+ | PublicKeyEvent
111
+ | SeedSettingsShown
package/src/types.ts ADDED
@@ -0,0 +1,113 @@
1
+ type AuthToken = number;
2
+
3
+ type Base64EncodedAddress = string;
4
+
5
+ type Base64EncodedSignature = string;
6
+
7
+ type Base64EncodedPayload = string;
8
+
9
+ type Base64EncodedMessage = Base64EncodedPayload;
10
+
11
+ type Base64EncodedTransaction = Base64EncodedPayload;
12
+
13
+ type DerivationPath = string;
14
+
15
+ export type Account = Readonly<{
16
+ id: number,
17
+ name: string,
18
+ derivationPath: DerivationPath,
19
+ publicKeyEncoded: Base64EncodedAddress
20
+ }>;
21
+
22
+ export const SeedPurpose = {
23
+ SignSolanaTransaction: 0,
24
+ } as const
25
+ export type SeedPurpose = typeof SeedPurpose[keyof typeof SeedPurpose]
26
+
27
+ export type Seed = Readonly<{
28
+ authToken: AuthToken,
29
+ name: string,
30
+ purpose: SeedPurpose
31
+ }>;
32
+
33
+ export type SeedPublicKey = Readonly<{
34
+ publicKey: Uint8Array,
35
+ publicKeyEncoded: Base64EncodedAddress,
36
+ resolvedDerivationPath: DerivationPath
37
+ }>
38
+
39
+ export type SigningRequest = Readonly<{
40
+ payload: Base64EncodedPayload,
41
+ requestedSignatures: DerivationPath[]
42
+ }>;
43
+
44
+ export type SigningResult = Readonly<{
45
+ signatures: Base64EncodedSignature[],
46
+ resolvedDerivationPaths: DerivationPath[]
47
+ }>;
48
+
49
+ interface AuthorizeSeedAPI {
50
+ hasUnauthorizedSeeds(): Promise<boolean>
51
+ hasUnauthorizedSeedsForPurpose(purpose: SeedPurpose): Promise<boolean>
52
+ getAuthorizedSeeds(): Promise<Seed[]>
53
+ authorizeNewSeed(): Promise<{authToken: AuthToken}>
54
+ deauthorizeSeed(authToken: AuthToken): void
55
+ }
56
+
57
+ interface AccountAPI {
58
+ getAccounts(authToken: AuthToken, filterOnColumn?: string, value?: string): Promise<Account[]>
59
+ getUserWallets(authToken: AuthToken): Promise<Account[]>
60
+ updateAccountName(authToken: AuthToken, accountId: string, name?: string): Promise<void>
61
+ updateAccountIsUserWallet(authToken: AuthToken, accountId: string, isUserWallet: boolean): Promise<void>
62
+ updateAccountIsValid(authToken: AuthToken, accountId: string, isValid: boolean): Promise<void>
63
+ }
64
+
65
+ interface CreateNewSeedAPI {
66
+ createNewSeed(): Promise<{authToken: AuthToken}>
67
+ }
68
+
69
+ // TODO
70
+ // interface ImplementationLimitsAPI {
71
+ // getImplementationLimits(): void
72
+ // getImplementationLimitsForPurpose()
73
+ // }
74
+
75
+ interface ImportExistingSeedAPI {
76
+ importExistingSeed(): Promise<{authToken: AuthToken}>
77
+ }
78
+
79
+ interface PublicKeyAPI {
80
+ getPublicKey(authToken: AuthToken, derivationPath: DerivationPath): Promise<SeedPublicKey>
81
+ getPublicKeys(authToken: AuthToken, derivationPaths: DerivationPath[]): Promise<SeedPublicKey[]>
82
+ resolveDerivationPath(derivationPath: DerivationPath): Promise<DerivationPath>
83
+ resolveDerivationPathForPurpose(derivationPath: DerivationPath, purpose: SeedPurpose): Promise<DerivationPath>
84
+ }
85
+
86
+ interface SignMessagesAPI {
87
+ signMessage(authToken: AuthToken, derivationPath: DerivationPath, message: Base64EncodedMessage): Promise<SigningResult>
88
+ signMessages(authToken: AuthToken, signingRequests: SigningRequest[]): Promise<SigningResult[]>
89
+ }
90
+
91
+ interface SignTransactionsAPI {
92
+ signTransaction(authToken: AuthToken, derivationPath: DerivationPath, transaction: Base64EncodedTransaction): Promise<SigningResult>
93
+ signTransactions(authToken: AuthToken, signingRequests: SigningRequest[]): Promise<SigningResult[]>
94
+ }
95
+
96
+ interface SeedVaultAvailabilityAPI {
97
+ isSeedVaultAvailable(allowSimulated: boolean): Promise<boolean>
98
+ }
99
+
100
+ interface ShowSeedSettingsAPI {
101
+ showSeedSettings(authToken: AuthToken): Promise<void>
102
+ }
103
+
104
+ export interface SeedVaultAPI
105
+ extends AuthorizeSeedAPI,
106
+ AccountAPI,
107
+ CreateNewSeedAPI,
108
+ ImportExistingSeedAPI,
109
+ PublicKeyAPI,
110
+ SeedVaultAvailabilityAPI,
111
+ SignMessagesAPI,
112
+ SignTransactionsAPI,
113
+ ShowSeedSettingsAPI {}
@@ -0,0 +1,100 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import { NativeEventEmitter, NativeModules, Permission, PermissionsAndroid, Platform } from 'react-native';
3
+ import { SeedVaultContentChange, SeedVaultEvent, SeedVaultEventType } from './seedVaultEvent';
4
+ import { SeedVaultAPI } from './types';
5
+
6
+ const LINKING_ERROR =
7
+ `The package 'solana-mobile-seed-vault-lib' doesn't seem to be linked. Make sure: \n\n` +
8
+ '- You rebuilt the app after installing the package\n' +
9
+ '- If you are using Lerna workspaces\n' +
10
+ ' - You have added `@solana-mobile/seed-vault-lib` as an explicit dependency, and\n' +
11
+ ' - You have added `@solana-mobile/seed-vault-lib` to the `nohoist` section of your package.json\n' +
12
+ '- You are not using Expo managed workflow\n';
13
+
14
+ const SolanaMobileSeedVaultLib =
15
+ Platform.OS === 'android' && NativeModules.SolanaMobileSeedVaultLib
16
+ ? NativeModules.SolanaMobileSeedVaultLib
17
+ : new Proxy(
18
+ {},
19
+ {
20
+ get() {
21
+ throw new Error(
22
+ Platform.OS !== 'android'
23
+ ? 'The package `solana-mobile-seed-vault-lib` is only compatible with React Native Android'
24
+ : LINKING_ERROR,
25
+ );
26
+ },
27
+ },
28
+ );
29
+
30
+ export const SeedVaultPermissionAndroid = 'com.solanamobile.seedvault.ACCESS_SEED_VAULT' as Permission;
31
+ export const SeedVaultPrivilegedPermissionAndroid = 'com.solanamobile.seedvault.ACCESS_SEED_VAULT_PRIVILEGED' as Permission;
32
+
33
+ const checkSeedVaultPermission = async () => {
34
+ const granted = await PermissionsAndroid.check(SeedVaultPermissionAndroid)
35
+ || await PermissionsAndroid.check(SeedVaultPrivilegedPermissionAndroid);
36
+
37
+ if (!granted) {
38
+ throw new Error(
39
+ 'You do not have permission to access Seed Vault. You must request permission to use Seed Vault.'
40
+ )
41
+ }
42
+ }
43
+
44
+ const checkIsSeedVaultAvailable = async (allowSimulated: boolean = false) => {
45
+ const seedVaultAvailable = await SolanaMobileSeedVaultLib.isSeedVaultAvailable(allowSimulated);
46
+
47
+ if (!seedVaultAvailable) {
48
+ throw new Error(
49
+ allowSimulated
50
+ ? 'Seed Vault is not available on this device, please install the Seed Vault Simulator'
51
+ : 'Seed Vault is not available on this device'
52
+ )
53
+ }
54
+ }
55
+
56
+ const SEED_VAULT_EVENT_BRIDGE_NAME = 'SeedVaultEventBridge';
57
+
58
+ export function useSeedVault(
59
+ handleSeedVaultEvent: (event: SeedVaultEvent) => void,
60
+ handleContentChange: (event: SeedVaultContentChange) => void,
61
+ ) {
62
+
63
+ const seedVaultEventHandler = useRef(handleSeedVaultEvent);
64
+ const contentChangeHandler = useRef(handleContentChange);
65
+ useEffect(() => {
66
+ seedVaultEventHandler.current = handleSeedVaultEvent;
67
+ contentChangeHandler.current = handleContentChange;
68
+ });
69
+
70
+ checkIsSeedVaultAvailable(true);
71
+ checkSeedVaultPermission();
72
+
73
+ // Start native event listener
74
+ useEffect(() => {
75
+ const seedVaultEventEmitter = new NativeEventEmitter();
76
+ const listener = seedVaultEventEmitter.addListener(SEED_VAULT_EVENT_BRIDGE_NAME, (nativeEvent) => {
77
+ if (isContentChangeEvent(nativeEvent)) {
78
+ contentChangeHandler.current(nativeEvent as SeedVaultContentChange)
79
+ } else if (isSeedVaultEvent(nativeEvent)) {
80
+ seedVaultEventHandler.current(nativeEvent as SeedVaultEvent)
81
+ } else {
82
+ console.warn('Unexpected native event type');
83
+ }
84
+ });
85
+
86
+ return () => {
87
+ listener.remove();
88
+ };
89
+ }, []);
90
+ }
91
+
92
+ function isSeedVaultEvent(nativeEvent: any): boolean {
93
+ return Object.values(SeedVaultEventType).includes(nativeEvent.__type);
94
+ }
95
+
96
+ function isContentChangeEvent(nativeEvent: any): boolean {
97
+ return nativeEvent.__type == SeedVaultEventType.ContentChange;
98
+ }
99
+
100
+ export const SeedVault: SeedVaultAPI = SolanaMobileSeedVaultLib as SeedVaultAPI
@@ -1,7 +0,0 @@
1
- dependencyResolutionManagement {
2
- versionCatalogs {
3
- libs {
4
- from(files("../../../../gradle/libs.versions.toml"))
5
- }
6
- }
7
- }
package/lib/esm/index.js DELETED
@@ -1,116 +0,0 @@
1
- import { useRef, useEffect } from 'react';
2
- import { Platform, NativeModules, NativeEventEmitter, PermissionsAndroid } from 'react-native';
3
-
4
- // EVENTS
5
- // Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
6
- const SeedVaultEventType = {
7
- AuthorizeSeedAccess: "SeedAuthorized",
8
- CreateNewSeed: "NewSeedCreated",
9
- ImportExistingSeed: "ExistingSeedImported",
10
- PayloadsSigned: "PayloadsSigned",
11
- GetPublicKeys: "PublicKeysEvent",
12
- ContentChange: "SeedVaultContentChange",
13
- SeedSettingsShown: "SeedSettingsShown"
14
- };
15
-
16
- const SeedPurpose = {
17
- SignSolanaTransaction: 0,
18
- };
19
-
20
- /******************************************************************************
21
- Copyright (c) Microsoft Corporation.
22
-
23
- Permission to use, copy, modify, and/or distribute this software for any
24
- purpose with or without fee is hereby granted.
25
-
26
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
27
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
28
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
29
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
30
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
31
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
32
- PERFORMANCE OF THIS SOFTWARE.
33
- ***************************************************************************** */
34
- /* global Reflect, Promise */
35
-
36
-
37
- function __awaiter(thisArg, _arguments, P, generator) {
38
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
39
- return new (P || (P = Promise))(function (resolve, reject) {
40
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
41
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
42
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
43
- step((generator = generator.apply(thisArg, _arguments || [])).next());
44
- });
45
- }
46
-
47
- const LINKING_ERROR = `The package 'solana-mobile-seed-vault-lib' doesn't seem to be linked. Make sure: \n\n` +
48
- '- You rebuilt the app after installing the package\n' +
49
- '- If you are using Lerna workspaces\n' +
50
- ' - You have added `@solana-mobile/seed-vault-lib` as an explicit dependency, and\n' +
51
- ' - You have added `@solana-mobile/seed-vault-lib` to the `nohoist` section of your package.json\n' +
52
- '- You are not using Expo managed workflow\n';
53
- const SolanaMobileSeedVaultLib = Platform.OS === 'android' && NativeModules.SolanaMobileSeedVaultLib
54
- ? NativeModules.SolanaMobileSeedVaultLib
55
- : new Proxy({}, {
56
- get() {
57
- throw new Error(Platform.OS !== 'android'
58
- ? 'The package `solana-mobile-seed-vault-lib` is only compatible with React Native Android'
59
- : LINKING_ERROR);
60
- },
61
- });
62
- const SeedVaultPermissionAndroid = 'com.solanamobile.seedvault.ACCESS_SEED_VAULT';
63
- const SeedVaultPrivilegedPermissionAndroid = 'com.solanamobile.seedvault.ACCESS_SEED_VAULT_PRIVILEGED';
64
- const checkSeedVaultPermission = () => __awaiter(undefined, undefined, undefined, function* () {
65
- const granted = (yield PermissionsAndroid.check(SeedVaultPermissionAndroid))
66
- || (yield PermissionsAndroid.check(SeedVaultPrivilegedPermissionAndroid));
67
- if (!granted) {
68
- throw new Error('You do not have permission to access Seed Vault. You must request permission to use Seed Vault.');
69
- }
70
- });
71
- const checkIsSeedVaultAvailable = (...args_1) => __awaiter(undefined, [...args_1], undefined, function* (allowSimulated = false) {
72
- const seedVaultAvailable = yield SolanaMobileSeedVaultLib.isSeedVaultAvailable(allowSimulated);
73
- if (!seedVaultAvailable) {
74
- throw new Error(allowSimulated
75
- ? 'Seed Vault is not available on this device, please install the Seed Vault Simulator'
76
- : 'Seed Vault is not available on this device');
77
- }
78
- });
79
- const SEED_VAULT_EVENT_BRIDGE_NAME = 'SeedVaultEventBridge';
80
- function useSeedVault(handleSeedVaultEvent, handleContentChange) {
81
- const seedVaultEventHandler = useRef(handleSeedVaultEvent);
82
- const contentChangeHandler = useRef(handleContentChange);
83
- useEffect(() => {
84
- seedVaultEventHandler.current = handleSeedVaultEvent;
85
- contentChangeHandler.current = handleContentChange;
86
- });
87
- checkIsSeedVaultAvailable(true);
88
- checkSeedVaultPermission();
89
- // Start native event listener
90
- useEffect(() => {
91
- const seedVaultEventEmitter = new NativeEventEmitter();
92
- const listener = seedVaultEventEmitter.addListener(SEED_VAULT_EVENT_BRIDGE_NAME, (nativeEvent) => {
93
- if (isContentChangeEvent(nativeEvent)) {
94
- contentChangeHandler.current(nativeEvent);
95
- }
96
- else if (isSeedVaultEvent(nativeEvent)) {
97
- seedVaultEventHandler.current(nativeEvent);
98
- }
99
- else {
100
- console.warn('Unexpected native event type');
101
- }
102
- });
103
- return () => {
104
- listener.remove();
105
- };
106
- }, []);
107
- }
108
- function isSeedVaultEvent(nativeEvent) {
109
- return Object.values(SeedVaultEventType).includes(nativeEvent.__type);
110
- }
111
- function isContentChangeEvent(nativeEvent) {
112
- return nativeEvent.__type == SeedVaultEventType.ContentChange;
113
- }
114
- const SeedVault = SolanaMobileSeedVaultLib;
115
-
116
- export { SeedPurpose, SeedVault, SeedVaultEventType, SeedVaultPermissionAndroid, SeedVaultPrivilegedPermissionAndroid, useSeedVault };
@@ -1,116 +0,0 @@
1
- import { useRef, useEffect } from 'react';
2
- import { Platform, NativeModules, NativeEventEmitter, PermissionsAndroid } from 'react-native';
3
-
4
- // EVENTS
5
- // Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
6
- const SeedVaultEventType = {
7
- AuthorizeSeedAccess: "SeedAuthorized",
8
- CreateNewSeed: "NewSeedCreated",
9
- ImportExistingSeed: "ExistingSeedImported",
10
- PayloadsSigned: "PayloadsSigned",
11
- GetPublicKeys: "PublicKeysEvent",
12
- ContentChange: "SeedVaultContentChange",
13
- SeedSettingsShown: "SeedSettingsShown"
14
- };
15
-
16
- const SeedPurpose = {
17
- SignSolanaTransaction: 0,
18
- };
19
-
20
- /******************************************************************************
21
- Copyright (c) Microsoft Corporation.
22
-
23
- Permission to use, copy, modify, and/or distribute this software for any
24
- purpose with or without fee is hereby granted.
25
-
26
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
27
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
28
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
29
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
30
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
31
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
32
- PERFORMANCE OF THIS SOFTWARE.
33
- ***************************************************************************** */
34
- /* global Reflect, Promise */
35
-
36
-
37
- function __awaiter(thisArg, _arguments, P, generator) {
38
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
39
- return new (P || (P = Promise))(function (resolve, reject) {
40
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
41
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
42
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
43
- step((generator = generator.apply(thisArg, _arguments || [])).next());
44
- });
45
- }
46
-
47
- const LINKING_ERROR = `The package 'solana-mobile-seed-vault-lib' doesn't seem to be linked. Make sure: \n\n` +
48
- '- You rebuilt the app after installing the package\n' +
49
- '- If you are using Lerna workspaces\n' +
50
- ' - You have added `@solana-mobile/seed-vault-lib` as an explicit dependency, and\n' +
51
- ' - You have added `@solana-mobile/seed-vault-lib` to the `nohoist` section of your package.json\n' +
52
- '- You are not using Expo managed workflow\n';
53
- const SolanaMobileSeedVaultLib = Platform.OS === 'android' && NativeModules.SolanaMobileSeedVaultLib
54
- ? NativeModules.SolanaMobileSeedVaultLib
55
- : new Proxy({}, {
56
- get() {
57
- throw new Error(Platform.OS !== 'android'
58
- ? 'The package `solana-mobile-seed-vault-lib` is only compatible with React Native Android'
59
- : LINKING_ERROR);
60
- },
61
- });
62
- const SeedVaultPermissionAndroid = 'com.solanamobile.seedvault.ACCESS_SEED_VAULT';
63
- const SeedVaultPrivilegedPermissionAndroid = 'com.solanamobile.seedvault.ACCESS_SEED_VAULT_PRIVILEGED';
64
- const checkSeedVaultPermission = () => __awaiter(undefined, undefined, undefined, function* () {
65
- const granted = (yield PermissionsAndroid.check(SeedVaultPermissionAndroid))
66
- || (yield PermissionsAndroid.check(SeedVaultPrivilegedPermissionAndroid));
67
- if (!granted) {
68
- throw new Error('You do not have permission to access Seed Vault. You must request permission to use Seed Vault.');
69
- }
70
- });
71
- const checkIsSeedVaultAvailable = (...args_1) => __awaiter(undefined, [...args_1], undefined, function* (allowSimulated = false) {
72
- const seedVaultAvailable = yield SolanaMobileSeedVaultLib.isSeedVaultAvailable(allowSimulated);
73
- if (!seedVaultAvailable) {
74
- throw new Error(allowSimulated
75
- ? 'Seed Vault is not available on this device, please install the Seed Vault Simulator'
76
- : 'Seed Vault is not available on this device');
77
- }
78
- });
79
- const SEED_VAULT_EVENT_BRIDGE_NAME = 'SeedVaultEventBridge';
80
- function useSeedVault(handleSeedVaultEvent, handleContentChange) {
81
- const seedVaultEventHandler = useRef(handleSeedVaultEvent);
82
- const contentChangeHandler = useRef(handleContentChange);
83
- useEffect(() => {
84
- seedVaultEventHandler.current = handleSeedVaultEvent;
85
- contentChangeHandler.current = handleContentChange;
86
- });
87
- checkIsSeedVaultAvailable(true);
88
- checkSeedVaultPermission();
89
- // Start native event listener
90
- useEffect(() => {
91
- const seedVaultEventEmitter = new NativeEventEmitter();
92
- const listener = seedVaultEventEmitter.addListener(SEED_VAULT_EVENT_BRIDGE_NAME, (nativeEvent) => {
93
- if (isContentChangeEvent(nativeEvent)) {
94
- contentChangeHandler.current(nativeEvent);
95
- }
96
- else if (isSeedVaultEvent(nativeEvent)) {
97
- seedVaultEventHandler.current(nativeEvent);
98
- }
99
- else {
100
- console.warn('Unexpected native event type');
101
- }
102
- });
103
- return () => {
104
- listener.remove();
105
- };
106
- }, []);
107
- }
108
- function isSeedVaultEvent(nativeEvent) {
109
- return Object.values(SeedVaultEventType).includes(nativeEvent.__type);
110
- }
111
- function isContentChangeEvent(nativeEvent) {
112
- return nativeEvent.__type == SeedVaultEventType.ContentChange;
113
- }
114
- const SeedVault = SolanaMobileSeedVaultLib;
115
-
116
- export { SeedPurpose, SeedVault, SeedVaultEventType, SeedVaultPermissionAndroid, SeedVaultPrivilegedPermissionAndroid, useSeedVault };
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }