@tetherto/wdk-react-native-secure-storage 1.0.0-beta.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 +180 -0
- package/README.md +472 -0
- package/package.json +72 -0
- package/src/__tests__/__mocks__/expo-crypto.ts +35 -0
- package/src/__tests__/__mocks__/expo-local-authentication.ts +40 -0
- package/src/__tests__/__mocks__/react-native-keychain.ts +60 -0
- package/src/__tests__/errors.test.ts +78 -0
- package/src/__tests__/logger.test.ts +131 -0
- package/src/__tests__/secureStorage.test.ts +1073 -0
- package/src/__tests__/utils.test.ts +182 -0
- package/src/__tests__/validation.test.ts +222 -0
- package/src/constants.ts +12 -0
- package/src/errors.ts +97 -0
- package/src/index.ts +41 -0
- package/src/keychainHelpers.ts +34 -0
- package/src/logger.ts +125 -0
- package/src/secureStorage.ts +707 -0
- package/src/utils.ts +176 -0
- package/src/validation.ts +160 -0
- package/tsconfig.json +24 -0
package/src/logger.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Log levels in order of severity
|
|
3
|
+
*/
|
|
4
|
+
export enum LogLevel {
|
|
5
|
+
DEBUG = 0,
|
|
6
|
+
INFO = 1,
|
|
7
|
+
WARN = 2,
|
|
8
|
+
ERROR = 3,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Log entry structure
|
|
13
|
+
*/
|
|
14
|
+
export interface LogEntry {
|
|
15
|
+
level: LogLevel
|
|
16
|
+
message: string
|
|
17
|
+
timestamp: number
|
|
18
|
+
context?: Record<string, unknown>
|
|
19
|
+
error?: Error
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Logger interface for structured logging
|
|
24
|
+
*/
|
|
25
|
+
export interface Logger {
|
|
26
|
+
debug(message: string, context?: Record<string, unknown>): void
|
|
27
|
+
info(message: string, context?: Record<string, unknown>): void
|
|
28
|
+
warn(message: string, context?: Record<string, unknown>): void
|
|
29
|
+
error(message: string, error?: Error, context?: Record<string, unknown>): void
|
|
30
|
+
/**
|
|
31
|
+
* Set the minimum log level
|
|
32
|
+
* Logs below this level will be ignored
|
|
33
|
+
*/
|
|
34
|
+
setLevel?(level: LogLevel): void
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Default logger implementation
|
|
39
|
+
* Uses console methods but provides structured logging interface
|
|
40
|
+
*
|
|
41
|
+
* **Default Log Level:** ERROR
|
|
42
|
+
*
|
|
43
|
+
* The default log level is set to ERROR to minimize log noise in production.
|
|
44
|
+
* This ensures that only critical errors are logged by default, which is appropriate
|
|
45
|
+
* for production environments where excessive logging can impact performance and
|
|
46
|
+
* expose sensitive information.
|
|
47
|
+
*
|
|
48
|
+
* For development or debugging, you can change the log level:
|
|
49
|
+
* ```typescript
|
|
50
|
+
* defaultLogger.setLevel(LogLevel.DEBUG)
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* For production monitoring of security events, consider setting to WARN:
|
|
54
|
+
* ```typescript
|
|
55
|
+
* defaultLogger.setLevel(LogLevel.WARN)
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
class DefaultLogger implements Logger {
|
|
59
|
+
private minLevel: LogLevel = LogLevel.ERROR
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Set the minimum log level
|
|
63
|
+
*/
|
|
64
|
+
setLevel(level: LogLevel): void {
|
|
65
|
+
this.minLevel = level
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Internal log method
|
|
70
|
+
*/
|
|
71
|
+
private log(
|
|
72
|
+
level: LogLevel,
|
|
73
|
+
message: string,
|
|
74
|
+
error?: Error,
|
|
75
|
+
context?: Record<string, unknown>
|
|
76
|
+
): void {
|
|
77
|
+
if (level < this.minLevel) {
|
|
78
|
+
return
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const entry: LogEntry = {
|
|
82
|
+
level,
|
|
83
|
+
message,
|
|
84
|
+
timestamp: Date.now(),
|
|
85
|
+
context,
|
|
86
|
+
error,
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// In production, this could send to a logging service
|
|
90
|
+
// For now, use console with structured output
|
|
91
|
+
// Note: Sensitive data (encryption keys, seeds, etc.) should never be logged
|
|
92
|
+
// The logger only logs error messages and metadata, never the actual stored values
|
|
93
|
+
const logMessage = JSON.stringify(entry, null, 2)
|
|
94
|
+
|
|
95
|
+
if (level >= LogLevel.ERROR) {
|
|
96
|
+
console.error(logMessage)
|
|
97
|
+
} else if (level >= LogLevel.WARN) {
|
|
98
|
+
console.warn(logMessage)
|
|
99
|
+
} else {
|
|
100
|
+
console.log(logMessage)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
debug(message: string, context?: Record<string, unknown>): void {
|
|
105
|
+
this.log(LogLevel.DEBUG, message, undefined, context)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
info(message: string, context?: Record<string, unknown>): void {
|
|
109
|
+
this.log(LogLevel.INFO, message, undefined, context)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
warn(message: string, context?: Record<string, unknown>): void {
|
|
113
|
+
this.log(LogLevel.WARN, message, undefined, context)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
error(message: string, error?: Error, context?: Record<string, unknown>): void {
|
|
117
|
+
this.log(LogLevel.ERROR, message, error, context)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Default logger instance
|
|
123
|
+
*/
|
|
124
|
+
export const defaultLogger = new DefaultLogger()
|
|
125
|
+
|