@solana-mobile/seed-vault-lib 0.2.1 → 0.3.3

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.
@@ -1,98 +0,0 @@
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
-
32
- const checkSeedVaultPermission = async () => {
33
- const granted = await PermissionsAndroid.check(SeedVaultPermissionAndroid)
34
-
35
- if (!granted) {
36
- throw new Error(
37
- 'You do not have permission to access Seed Vault. You must request permission to use Seed Vault.'
38
- )
39
- }
40
- }
41
-
42
- const checkIsSeedVaultAvailable = async (allowSimulated: boolean = false) => {
43
- const seedVaultAvailable = await SolanaMobileSeedVaultLib.isSeedVaultAvailable(allowSimulated);
44
-
45
- if (!seedVaultAvailable) {
46
- throw new Error(
47
- allowSimulated
48
- ? 'Seed Vault is not available on this device, please install the Seed Vault Simulator'
49
- : 'Seed Vault is not available on this device'
50
- )
51
- }
52
- }
53
-
54
- const SEED_VAULT_EVENT_BRIDGE_NAME = 'SeedVaultEventBridge';
55
-
56
- export function useSeedVault(
57
- handleSeedVaultEvent: (event: SeedVaultEvent) => void,
58
- handleContentChange: (event: SeedVaultContentChange) => void,
59
- ) {
60
-
61
- const seedVaultEventHandler = useRef(handleSeedVaultEvent);
62
- const contentChangeHandler = useRef(handleContentChange);
63
- useEffect(() => {
64
- seedVaultEventHandler.current = handleSeedVaultEvent;
65
- contentChangeHandler.current = handleContentChange;
66
- });
67
-
68
- checkIsSeedVaultAvailable(true);
69
- checkSeedVaultPermission();
70
-
71
- // Start native event listener
72
- useEffect(() => {
73
- const seedVaultEventEmitter = new NativeEventEmitter();
74
- const listener = seedVaultEventEmitter.addListener(SEED_VAULT_EVENT_BRIDGE_NAME, (nativeEvent) => {
75
- if (isContentChangeEvent(nativeEvent)) {
76
- contentChangeHandler.current(nativeEvent as SeedVaultContentChange)
77
- } else if (isSeedVaultEvent(nativeEvent)) {
78
- seedVaultEventHandler.current(nativeEvent as SeedVaultEvent)
79
- } else {
80
- console.warn('Unexpected native event type');
81
- }
82
- });
83
-
84
- return () => {
85
- listener.remove();
86
- };
87
- }, []);
88
- }
89
-
90
- function isSeedVaultEvent(nativeEvent: any): boolean {
91
- return Object.values(SeedVaultEventType).includes(nativeEvent.__type);
92
- }
93
-
94
- function isContentChangeEvent(nativeEvent: any): boolean {
95
- return nativeEvent.__type == SeedVaultEventType.ContentChange;
96
- }
97
-
98
- export const SeedVault: SeedVaultAPI = SolanaMobileSeedVaultLib as SeedVaultAPI
package/tsconfig.cjs.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "module": "commonjs",
5
- "outDir": "lib/cjs"
6
- }
7
- }
package/tsconfig.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "include": ["src"],
4
- "compilerOptions": {
5
- "declarationDir": "./lib/types",
6
- "outDir": "lib/esm"
7
- }
8
- }