forked from tetherto/wdk-react-native-secure-storage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreact-native-keychain.ts
More file actions
60 lines (51 loc) · 1.5 KB
/
react-native-keychain.ts
File metadata and controls
60 lines (51 loc) · 1.5 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* Mock for react-native-keychain
* Used in tests to simulate keychain operations
*/
export const ACCESSIBLE = {
WHEN_UNLOCKED: 'WHEN_UNLOCKED',
WHEN_UNLOCKED_THIS_DEVICE_ONLY: 'WHEN_UNLOCKED_THIS_DEVICE_ONLY',
}
export const ACCESS_CONTROL = {
BIOMETRY_ANY_OR_DEVICE_PASSCODE: 'BIOMETRY_ANY_OR_DEVICE_PASSCODE',
}
const mockStorage: Map<string, { username: string; password: string }> = new Map()
export function setGenericPassword(
username: string,
password: string,
options?: { service?: string }
): Promise<{ service: string; storage: string } | false> {
const service = options?.service || 'default'
mockStorage.set(service, { username, password })
return Promise.resolve({ service, storage: 'keychain' })
}
export function getGenericPassword(options?: { service?: string }): Promise<
| {
service: string
username: string
password: string
storage: string
}
| false
> {
const service = options?.service || 'default'
const stored = mockStorage.get(service)
if (stored) {
return Promise.resolve({
service,
username: stored.username,
password: stored.password,
storage: 'keychain',
})
}
return Promise.resolve(false)
}
export function resetGenericPassword(options?: { service?: string }): Promise<boolean> {
const service = options?.service || 'default'
mockStorage.delete(service)
return Promise.resolve(true)
}
// Helper for tests to reset mock storage
export function __resetMockStorage(): void {
mockStorage.clear()
}