@oxyhq/services 5.17.8 → 5.17.9

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.
Files changed (91) hide show
  1. package/lib/commonjs/crypto/index.js +0 -23
  2. package/lib/commonjs/crypto/index.js.map +1 -1
  3. package/lib/commonjs/index.js +0 -15
  4. package/lib/commonjs/index.js.map +1 -1
  5. package/lib/commonjs/ui/components/Icon.js.map +1 -1
  6. package/lib/commonjs/ui/components/IconButton/utils.js.map +1 -1
  7. package/lib/commonjs/ui/components/TextField/Adornment/utils.js.map +1 -1
  8. package/lib/commonjs/ui/components/TextField/helpers.js.map +1 -1
  9. package/lib/commonjs/ui/components/TouchableRipple/utils.js.map +1 -1
  10. package/lib/commonjs/ui/components/Typography/AnimatedText.js.map +1 -1
  11. package/lib/commonjs/ui/context/OxyContext.js +23 -15
  12. package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
  13. package/lib/commonjs/ui/context/hooks/useAuthOperations.js +63 -111
  14. package/lib/commonjs/ui/context/hooks/useAuthOperations.js.map +1 -1
  15. package/lib/commonjs/ui/screens/OxyAuthScreen.js +0 -1
  16. package/lib/commonjs/ui/screens/OxyAuthScreen.js.map +1 -1
  17. package/lib/commonjs/ui/stores/authStore.js +52 -15
  18. package/lib/commonjs/ui/stores/authStore.js.map +1 -1
  19. package/lib/commonjs/ui/utils/avatarUtils.js +2 -32
  20. package/lib/commonjs/ui/utils/avatarUtils.js.map +1 -1
  21. package/lib/module/crypto/index.js +4 -6
  22. package/lib/module/crypto/index.js.map +1 -1
  23. package/lib/module/index.js +6 -3
  24. package/lib/module/index.js.map +1 -1
  25. package/lib/module/ui/components/Icon.js.map +1 -1
  26. package/lib/module/ui/components/IconButton/utils.js.map +1 -1
  27. package/lib/module/ui/components/TextField/Adornment/utils.js.map +1 -1
  28. package/lib/module/ui/components/TextField/helpers.js.map +1 -1
  29. package/lib/module/ui/components/TouchableRipple/utils.js.map +1 -1
  30. package/lib/module/ui/components/Typography/AnimatedText.js.map +1 -1
  31. package/lib/module/ui/context/OxyContext.js +23 -15
  32. package/lib/module/ui/context/OxyContext.js.map +1 -1
  33. package/lib/module/ui/context/hooks/useAuthOperations.js +63 -111
  34. package/lib/module/ui/context/hooks/useAuthOperations.js.map +1 -1
  35. package/lib/module/ui/screens/OxyAuthScreen.js +0 -1
  36. package/lib/module/ui/screens/OxyAuthScreen.js.map +1 -1
  37. package/lib/module/ui/stores/authStore.js +52 -15
  38. package/lib/module/ui/stores/authStore.js.map +1 -1
  39. package/lib/module/ui/utils/avatarUtils.js +2 -32
  40. package/lib/module/ui/utils/avatarUtils.js.map +1 -1
  41. package/lib/typescript/crypto/index.d.ts +2 -5
  42. package/lib/typescript/crypto/index.d.ts.map +1 -1
  43. package/lib/typescript/crypto/types.d.ts +2 -2
  44. package/lib/typescript/index.d.ts +4 -2
  45. package/lib/typescript/index.d.ts.map +1 -1
  46. package/lib/typescript/ui/components/IconButton/utils.d.ts +1 -1
  47. package/lib/typescript/ui/components/TextField/Adornment/utils.d.ts +1 -1
  48. package/lib/typescript/ui/components/TextField/Adornment/utils.d.ts.map +1 -1
  49. package/lib/typescript/ui/components/TextField/helpers.d.ts +6 -6
  50. package/lib/typescript/ui/components/types.d.ts +0 -4
  51. package/lib/typescript/ui/components/types.d.ts.map +1 -1
  52. package/lib/typescript/ui/context/OxyContext.d.ts.map +1 -1
  53. package/lib/typescript/ui/context/OxyContextBase.d.ts +2 -2
  54. package/lib/typescript/ui/context/OxyContextBase.d.ts.map +1 -1
  55. package/lib/typescript/ui/context/hooks/useAuthOperations.d.ts +9 -5
  56. package/lib/typescript/ui/context/hooks/useAuthOperations.d.ts.map +1 -1
  57. package/lib/typescript/ui/stores/authStore.d.ts +27 -4
  58. package/lib/typescript/ui/stores/authStore.d.ts.map +1 -1
  59. package/lib/typescript/ui/utils/avatarUtils.d.ts +0 -2
  60. package/lib/typescript/ui/utils/avatarUtils.d.ts.map +1 -1
  61. package/package.json +2 -2
  62. package/src/crypto/index.ts +3 -11
  63. package/src/crypto/types.ts +2 -2
  64. package/src/index.ts +6 -11
  65. package/src/ui/components/Icon.tsx +1 -1
  66. package/src/ui/components/IconButton/utils.ts +1 -1
  67. package/src/ui/components/TextField/Adornment/utils.ts +2 -2
  68. package/src/ui/components/TextField/helpers.tsx +8 -8
  69. package/src/ui/components/TouchableRipple/utils.ts +2 -2
  70. package/src/ui/components/Typography/AnimatedText.tsx +2 -2
  71. package/src/ui/components/types.tsx +0 -6
  72. package/src/ui/context/OxyContext.tsx +23 -14
  73. package/src/ui/context/OxyContextBase.tsx +4 -4
  74. package/src/ui/context/hooks/useAuthOperations.ts +83 -134
  75. package/src/ui/screens/OxyAuthScreen.tsx +1 -1
  76. package/src/ui/stores/authStore.ts +57 -18
  77. package/src/ui/utils/avatarUtils.ts +4 -36
  78. package/lib/commonjs/crypto/keyManager.js +0 -356
  79. package/lib/commonjs/crypto/keyManager.js.map +0 -1
  80. package/lib/commonjs/crypto/signatureService.js +0 -269
  81. package/lib/commonjs/crypto/signatureService.js.map +0 -1
  82. package/lib/module/crypto/keyManager.js +0 -353
  83. package/lib/module/crypto/keyManager.js.map +0 -1
  84. package/lib/module/crypto/signatureService.js +0 -266
  85. package/lib/module/crypto/signatureService.js.map +0 -1
  86. package/lib/typescript/crypto/keyManager.d.ts +0 -80
  87. package/lib/typescript/crypto/keyManager.d.ts.map +0 -1
  88. package/lib/typescript/crypto/signatureService.d.ts +0 -77
  89. package/lib/typescript/crypto/signatureService.d.ts.map +0 -1
  90. package/src/crypto/keyManager.ts +0 -379
  91. package/src/crypto/signatureService.ts +0 -301
@@ -1,353 +0,0 @@
1
- "use strict";
2
-
3
- /**
4
- * Key Manager - ECDSA secp256k1 Key Generation and Storage
5
- *
6
- * Handles secure generation, storage, and retrieval of cryptographic keys.
7
- * Private keys are stored securely using expo-secure-store and never leave the device.
8
- */
9
-
10
- import { ec as EC } from 'elliptic';
11
- import { Platform } from 'react-native';
12
-
13
- // Lazy imports for React Native specific modules
14
- let SecureStore = null;
15
- let ExpoCrypto = null;
16
- const ec = new EC('secp256k1');
17
- const STORAGE_KEYS = {
18
- PRIVATE_KEY: 'oxy_identity_private_key',
19
- PUBLIC_KEY: 'oxy_identity_public_key'
20
- };
21
-
22
- /**
23
- * Initialize React Native specific modules
24
- * This allows the module to work in both Node.js and React Native environments
25
- */
26
- async function initSecureStore() {
27
- if (!SecureStore) {
28
- try {
29
- SecureStore = await import('expo-secure-store');
30
- } catch (error) {
31
- const errorMessage = error instanceof Error ? error.message : String(error);
32
- throw new Error(`Failed to load expo-secure-store: ${errorMessage}. Make sure expo-secure-store is installed and properly configured.`);
33
- }
34
- }
35
- if (!SecureStore) {
36
- throw new Error('expo-secure-store module is not available');
37
- }
38
- return SecureStore;
39
- }
40
-
41
- /**
42
- * Check if we're in a React Native environment
43
- */
44
- function isReactNative() {
45
- return typeof navigator !== 'undefined' && navigator.product === 'ReactNative';
46
- }
47
-
48
- /**
49
- * Check if we're in a Node.js environment
50
- */
51
- function isNodeJS() {
52
- return typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
53
- }
54
-
55
- /**
56
- * Check if we're on web platform
57
- * Identity storage is only available on native platforms (iOS/Android)
58
- */
59
- function isWebPlatform() {
60
- try {
61
- return Platform.OS === 'web';
62
- } catch {
63
- // Fallback if Platform is not available
64
- return typeof window !== 'undefined' && typeof navigator !== 'undefined' && navigator.product !== 'ReactNative';
65
- }
66
- }
67
- async function initExpoCrypto() {
68
- if (!ExpoCrypto) {
69
- ExpoCrypto = await import('expo-crypto');
70
- }
71
- return ExpoCrypto;
72
- }
73
-
74
- /**
75
- * Convert Uint8Array to hexadecimal string
76
- * Works in both Node.js and React Native
77
- */
78
- function uint8ArrayToHex(bytes) {
79
- return Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('');
80
- }
81
-
82
- /**
83
- * Generate cryptographically secure random bytes
84
- */
85
- async function getSecureRandomBytes(length) {
86
- // In React Native, always use expo-crypto
87
- if (isReactNative() || !isNodeJS()) {
88
- const Crypto = await initExpoCrypto();
89
- return Crypto.getRandomBytes(length);
90
- }
91
-
92
- // In Node.js, use Node's crypto module
93
- // Use Function constructor to prevent Metro bundler from statically analyzing this require
94
- // This ensures the require is only evaluated in Node.js runtime, not during Metro bundling
95
- try {
96
- // eslint-disable-next-line @typescript-eslint/no-implied-eval
97
- const getCrypto = new Function('return require("crypto")');
98
- const crypto = getCrypto();
99
- return new Uint8Array(crypto.randomBytes(length));
100
- } catch (error) {
101
- // Fallback to expo-crypto if Node crypto fails
102
- const Crypto = await initExpoCrypto();
103
- return Crypto.getRandomBytes(length);
104
- }
105
- }
106
- export class KeyManager {
107
- /**
108
- * Generate a new ECDSA secp256k1 key pair
109
- * Returns the keys in hexadecimal format
110
- */
111
- static generateKeyPairSync() {
112
- const keyPair = ec.genKeyPair();
113
- return {
114
- privateKey: keyPair.getPrivate('hex'),
115
- publicKey: keyPair.getPublic('hex')
116
- };
117
- }
118
-
119
- /**
120
- * Generate a new key pair using secure random bytes
121
- */
122
- static async generateKeyPair() {
123
- const randomBytes = await getSecureRandomBytes(32);
124
- const privateKeyHex = uint8ArrayToHex(randomBytes);
125
- const keyPair = ec.keyFromPrivate(privateKeyHex);
126
- return {
127
- privateKey: keyPair.getPrivate('hex'),
128
- publicKey: keyPair.getPublic('hex')
129
- };
130
- }
131
-
132
- /**
133
- * Generate and securely store a new key pair on the device
134
- * Returns only the public key (private key is stored securely)
135
- */
136
- static async createIdentity() {
137
- if (isWebPlatform()) {
138
- throw new Error('Identity creation is only available on native platforms (iOS/Android). Please use the native app to create your identity.');
139
- }
140
- const store = await initSecureStore();
141
- const {
142
- privateKey,
143
- publicKey
144
- } = await KeyManager.generateKeyPair();
145
- await store.setItemAsync(STORAGE_KEYS.PRIVATE_KEY, privateKey, {
146
- keychainAccessible: store.WHEN_UNLOCKED_THIS_DEVICE_ONLY
147
- });
148
- await store.setItemAsync(STORAGE_KEYS.PUBLIC_KEY, publicKey);
149
- return publicKey;
150
- }
151
-
152
- /**
153
- * Import an existing key pair (e.g., from backup file)
154
- */
155
- static async importKeyPair(privateKey) {
156
- if (isWebPlatform()) {
157
- throw new Error('Identity import is only available on native platforms (iOS/Android). Please use the native app to import your identity.');
158
- }
159
- const store = await initSecureStore();
160
- const keyPair = ec.keyFromPrivate(privateKey);
161
- const publicKey = keyPair.getPublic('hex');
162
- await store.setItemAsync(STORAGE_KEYS.PRIVATE_KEY, privateKey, {
163
- keychainAccessible: store.WHEN_UNLOCKED_THIS_DEVICE_ONLY
164
- });
165
- await store.setItemAsync(STORAGE_KEYS.PUBLIC_KEY, publicKey);
166
- return publicKey;
167
- }
168
-
169
- /**
170
- * Get the stored private key
171
- * WARNING: Only use this for signing operations within the app
172
- */
173
- static async getPrivateKey() {
174
- if (isWebPlatform()) {
175
- return null; // Identity storage is only available on native platforms
176
- }
177
- try {
178
- const store = await initSecureStore();
179
- return await store.getItemAsync(STORAGE_KEYS.PRIVATE_KEY);
180
- } catch (error) {
181
- // If secure store is not available, return null (no identity)
182
- // This allows the app to continue functioning even if secure store fails to load
183
- if (__DEV__) {
184
- console.warn('[KeyManager] Failed to access secure store:', error);
185
- }
186
- return null;
187
- }
188
- }
189
-
190
- /**
191
- * Get the stored public key
192
- */
193
- static async getPublicKey() {
194
- if (isWebPlatform()) {
195
- return null; // Identity storage is only available on native platforms
196
- }
197
- try {
198
- const store = await initSecureStore();
199
- return await store.getItemAsync(STORAGE_KEYS.PUBLIC_KEY);
200
- } catch (error) {
201
- if (__DEV__) {
202
- console.warn('[KeyManager] Failed to access secure store:', error);
203
- }
204
- return null;
205
- }
206
- }
207
-
208
- /**
209
- * Check if an identity (key pair) exists on this device
210
- */
211
- static async hasIdentity() {
212
- if (isWebPlatform()) {
213
- return false; // Identity storage is only available on native platforms
214
- }
215
- try {
216
- const privateKey = await KeyManager.getPrivateKey();
217
- return privateKey !== null;
218
- } catch (error) {
219
- if (__DEV__) {
220
- console.warn('[KeyManager] Failed to check identity:', error);
221
- }
222
- return false;
223
- }
224
- }
225
-
226
- /**
227
- * Delete the stored identity (both keys)
228
- * Use with EXTREME caution - this is irreversible without a backup file
229
- * This should ONLY be called when explicitly requested by the user
230
- * @param force - If true, skip confirmation checks (default: false)
231
- * @param userConfirmed - If true, user has explicitly confirmed deletion (default: false)
232
- */
233
- static async deleteIdentity(force = false, userConfirmed = false) {
234
- if (isWebPlatform()) {
235
- return; // Identity storage is only available on native platforms, nothing to delete
236
- }
237
- // CRITICAL SAFEGUARD: Require explicit user confirmation unless force is true
238
- if (!force && !userConfirmed) {
239
- throw new Error('Identity deletion requires explicit user confirmation. This is a safety measure to prevent accidental data loss.');
240
- }
241
- if (!force) {
242
- const hasIdentity = await KeyManager.hasIdentity();
243
- if (!hasIdentity) {
244
- return; // Nothing to delete
245
- }
246
- }
247
- const store = await initSecureStore();
248
- await store.deleteItemAsync(STORAGE_KEYS.PRIVATE_KEY);
249
- await store.deleteItemAsync(STORAGE_KEYS.PUBLIC_KEY);
250
- }
251
-
252
- /**
253
- * Verify identity integrity - checks if keys are valid and accessible
254
- */
255
- static async verifyIdentityIntegrity() {
256
- if (isWebPlatform()) {
257
- return false; // Identity storage is only available on native platforms
258
- }
259
- try {
260
- const privateKey = await KeyManager.getPrivateKey();
261
- const publicKey = await KeyManager.getPublicKey();
262
- if (!privateKey || !publicKey) {
263
- return false;
264
- }
265
-
266
- // Validate private key format
267
- if (!KeyManager.isValidPrivateKey(privateKey)) {
268
- return false;
269
- }
270
-
271
- // Validate public key format
272
- if (!KeyManager.isValidPublicKey(publicKey)) {
273
- return false;
274
- }
275
-
276
- // Verify public key can be derived from private key
277
- const derivedPublicKey = KeyManager.derivePublicKey(privateKey);
278
- if (derivedPublicKey !== publicKey) {
279
- return false; // Keys don't match
280
- }
281
-
282
- // Verify we can create a key pair object (tests elliptic curve operations)
283
- const keyPair = await KeyManager.getKeyPairObject();
284
- if (!keyPair) {
285
- return false;
286
- }
287
- return true;
288
- } catch (error) {
289
- if (typeof __DEV__ !== 'undefined' && __DEV__) {
290
- console.error('[KeyManager] Identity integrity check failed:', error);
291
- }
292
- return false;
293
- }
294
- }
295
-
296
- /**
297
- * Get the elliptic curve key object from the stored private key
298
- * Used internally for signing operations
299
- */
300
- static async getKeyPairObject() {
301
- if (isWebPlatform()) {
302
- return null; // Identity storage is only available on native platforms
303
- }
304
- const privateKey = await KeyManager.getPrivateKey();
305
- if (!privateKey) return null;
306
- return ec.keyFromPrivate(privateKey);
307
- }
308
-
309
- /**
310
- * Derive public key from a private key (without storing)
311
- */
312
- static derivePublicKey(privateKey) {
313
- const keyPair = ec.keyFromPrivate(privateKey);
314
- return keyPair.getPublic('hex');
315
- }
316
-
317
- /**
318
- * Validate that a string is a valid public key
319
- */
320
- static isValidPublicKey(publicKey) {
321
- try {
322
- ec.keyFromPublic(publicKey, 'hex');
323
- return true;
324
- } catch {
325
- return false;
326
- }
327
- }
328
-
329
- /**
330
- * Validate that a string is a valid private key
331
- */
332
- static isValidPrivateKey(privateKey) {
333
- try {
334
- const keyPair = ec.keyFromPrivate(privateKey);
335
- // Verify it can derive a public key
336
- keyPair.getPublic('hex');
337
- return true;
338
- } catch {
339
- return false;
340
- }
341
- }
342
-
343
- /**
344
- * Get a shortened version of the public key for display
345
- * Format: first 8 chars...last 8 chars
346
- */
347
- static shortenPublicKey(publicKey) {
348
- if (publicKey.length <= 20) return publicKey;
349
- return `${publicKey.slice(0, 8)}...${publicKey.slice(-8)}`;
350
- }
351
- }
352
- export default KeyManager;
353
- //# sourceMappingURL=keyManager.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["ec","EC","Platform","SecureStore","ExpoCrypto","STORAGE_KEYS","PRIVATE_KEY","PUBLIC_KEY","initSecureStore","error","errorMessage","Error","message","String","isReactNative","navigator","product","isNodeJS","process","versions","node","isWebPlatform","OS","window","initExpoCrypto","uint8ArrayToHex","bytes","Array","from","map","b","toString","padStart","join","getSecureRandomBytes","length","Crypto","getRandomBytes","getCrypto","Function","crypto","Uint8Array","randomBytes","KeyManager","generateKeyPairSync","keyPair","genKeyPair","privateKey","getPrivate","publicKey","getPublic","generateKeyPair","privateKeyHex","keyFromPrivate","createIdentity","store","setItemAsync","keychainAccessible","WHEN_UNLOCKED_THIS_DEVICE_ONLY","importKeyPair","getPrivateKey","getItemAsync","__DEV__","console","warn","getPublicKey","hasIdentity","deleteIdentity","force","userConfirmed","deleteItemAsync","verifyIdentityIntegrity","isValidPrivateKey","isValidPublicKey","derivedPublicKey","derivePublicKey","getKeyPairObject","keyFromPublic","shortenPublicKey","slice"],"sourceRoot":"../../../src","sources":["crypto/keyManager.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,EAAE,IAAIC,EAAE,QAAQ,UAAU;AAEnC,SAASC,QAAQ,QAAQ,cAAc;;AAEvC;AACA,IAAIC,WAAsD,GAAG,IAAI;AACjE,IAAIC,UAA+C,GAAG,IAAI;AAE1D,MAAMJ,EAAE,GAAG,IAAIC,EAAE,CAAC,WAAW,CAAC;AAE9B,MAAMI,YAAY,GAAG;EACnBC,WAAW,EAAE,0BAA0B;EACvCC,UAAU,EAAE;AACd,CAAU;;AAEV;AACA;AACA;AACA;AACA,eAAeC,eAAeA,CAAA,EAAgD;EAC5E,IAAI,CAACL,WAAW,EAAE;IAChB,IAAI;MACFA,WAAW,GAAG,MAAM,MAAM,CAAC,mBAAmB,CAAC;IACjD,CAAC,CAAC,OAAOM,KAAK,EAAE;MACd,MAAMC,YAAY,GAAGD,KAAK,YAAYE,KAAK,GAAGF,KAAK,CAACG,OAAO,GAAGC,MAAM,CAACJ,KAAK,CAAC;MAC3E,MAAM,IAAIE,KAAK,CAAC,qCAAqCD,YAAY,qEAAqE,CAAC;IACzI;EACF;EACA,IAAI,CAACP,WAAW,EAAE;IAChB,MAAM,IAAIQ,KAAK,CAAC,2CAA2C,CAAC;EAC9D;EACA,OAAOR,WAAW;AACpB;;AAEA;AACA;AACA;AACA,SAASW,aAAaA,CAAA,EAAY;E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,0 @@
1
- "use strict";
2
-
3
- /**
4
- * Signature Service - ECDSA Digital Signatures
5
- *
6
- * Handles signing and verification of messages using ECDSA secp256k1.
7
- * Used for authenticating requests and proving identity ownership.
8
- */
9
-
10
- import { ec as EC } from 'elliptic';
11
- import { KeyManager } from './keyManager';
12
-
13
- // Lazy import for expo-crypto
14
- let ExpoCrypto = null;
15
- const ec = new EC('secp256k1');
16
-
17
- /**
18
- * Check if we're in a React Native environment
19
- */
20
- function isReactNative() {
21
- return typeof navigator !== 'undefined' && navigator.product === 'ReactNative';
22
- }
23
-
24
- /**
25
- * Check if we're in a Node.js environment
26
- */
27
- function isNodeJS() {
28
- return typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
29
- }
30
-
31
- /**
32
- * Initialize expo-crypto module
33
- */
34
- async function initExpoCrypto() {
35
- if (!ExpoCrypto) {
36
- ExpoCrypto = await import('expo-crypto');
37
- }
38
- return ExpoCrypto;
39
- }
40
-
41
- /**
42
- * Compute SHA-256 hash of a string
43
- */
44
- async function sha256(message) {
45
- // In React Native, always use expo-crypto
46
- if (isReactNative() || !isNodeJS()) {
47
- const Crypto = await initExpoCrypto();
48
- return Crypto.digestStringAsync(Crypto.CryptoDigestAlgorithm.SHA256, message);
49
- }
50
-
51
- // In Node.js, use Node's crypto module
52
- // Use Function constructor to prevent Metro bundler from statically analyzing this require
53
- // This ensures the require is only evaluated in Node.js runtime, not during Metro bundling
54
- try {
55
- // eslint-disable-next-line @typescript-eslint/no-implied-eval
56
- const getCrypto = new Function('return require("crypto")');
57
- const crypto = getCrypto();
58
- return crypto.createHash('sha256').update(message).digest('hex');
59
- } catch (error) {
60
- // Fallback to expo-crypto if Node crypto fails
61
- const Crypto = await initExpoCrypto();
62
- return Crypto.digestStringAsync(Crypto.CryptoDigestAlgorithm.SHA256, message);
63
- }
64
- }
65
- export class SignatureService {
66
- /**
67
- * Generate a random challenge string (for offline use)
68
- * Uses expo-crypto in React Native, crypto.randomBytes in Node.js
69
- */
70
- static async generateChallenge() {
71
- if (isReactNative() || !isNodeJS()) {
72
- // Use expo-crypto for React Native (expo-random is deprecated)
73
- const Crypto = await initExpoCrypto();
74
- const randomBytes = await Crypto.getRandomBytesAsync(32);
75
- return Array.from(randomBytes).map(b => b.toString(16).padStart(2, '0')).join('');
76
- }
77
-
78
- // Node.js fallback
79
- try {
80
- // eslint-disable-next-line @typescript-eslint/no-implied-eval
81
- const getCrypto = new Function('return require("crypto")');
82
- const crypto = getCrypto();
83
- return crypto.randomBytes(32).toString('hex');
84
- } catch (error) {
85
- // Fallback to expo-crypto if Node crypto fails
86
- const Crypto = await initExpoCrypto();
87
- const randomBytes = await Crypto.getRandomBytesAsync(32);
88
- return Array.from(randomBytes).map(b => b.toString(16).padStart(2, '0')).join('');
89
- }
90
- }
91
-
92
- /**
93
- * Hash a message using SHA-256
94
- */
95
- static async hashMessage(message) {
96
- return sha256(message);
97
- }
98
-
99
- /**
100
- * Sign a message using the stored private key
101
- * Returns the signature in DER format (hex encoded)
102
- */
103
- static async sign(message) {
104
- const keyPair = await KeyManager.getKeyPairObject();
105
- if (!keyPair) {
106
- throw new Error('No identity found. Please create or import an identity first.');
107
- }
108
- const messageHash = await sha256(message);
109
- const signature = keyPair.sign(messageHash);
110
- return signature.toDER('hex');
111
- }
112
-
113
- /**
114
- * Sign a message with an explicit private key (without storing)
115
- * Useful for one-time operations or testing
116
- */
117
- static async signWithKey(message, privateKey) {
118
- const keyPair = ec.keyFromPrivate(privateKey);
119
- const messageHash = await sha256(message);
120
- const signature = keyPair.sign(messageHash);
121
- return signature.toDER('hex');
122
- }
123
-
124
- /**
125
- * Verify a signature against a message and public key
126
- */
127
- static async verify(message, signature, publicKey) {
128
- try {
129
- const key = ec.keyFromPublic(publicKey, 'hex');
130
- const messageHash = await sha256(message);
131
- return key.verify(messageHash, signature);
132
- } catch {
133
- return false;
134
- }
135
- }
136
-
137
- /**
138
- * Synchronous verification (for Node.js backend)
139
- * Uses crypto module directly for hashing
140
- * Note: This method should only be used in Node.js environments
141
- */
142
- static verifySync(message, signature, publicKey) {
143
- try {
144
- if (!isNodeJS()) {
145
- // In React Native, use async verify instead
146
- throw new Error('verifySync should only be used in Node.js. Use verify() in React Native.');
147
- }
148
- // Use Function constructor to prevent Metro bundler from statically analyzing this require
149
- // eslint-disable-next-line @typescript-eslint/no-implied-eval
150
- const getCrypto = new Function('return require("crypto")');
151
- const crypto = getCrypto();
152
- const key = ec.keyFromPublic(publicKey, 'hex');
153
- const messageHash = crypto.createHash('sha256').update(message).digest('hex');
154
- return key.verify(messageHash, signature);
155
- } catch {
156
- return false;
157
- }
158
- }
159
-
160
- /**
161
- * Create a signed message object with metadata
162
- */
163
- static async createSignedMessage(message) {
164
- const publicKey = await KeyManager.getPublicKey();
165
- if (!publicKey) {
166
- throw new Error('No identity found. Please create or import an identity first.');
167
- }
168
- const timestamp = Date.now();
169
- const messageWithTimestamp = `${message}:${timestamp}`;
170
- const signature = await SignatureService.sign(messageWithTimestamp);
171
- return {
172
- message,
173
- signature,
174
- publicKey,
175
- timestamp
176
- };
177
- }
178
-
179
- /**
180
- * Verify a signed message object
181
- * Checks both signature validity and timestamp freshness
182
- */
183
- static async verifySignedMessage(signedMessage, maxAgeMs = 5 * 60 * 1000 // 5 minutes default
184
- ) {
185
- const {
186
- message,
187
- signature,
188
- publicKey,
189
- timestamp
190
- } = signedMessage;
191
-
192
- // Check timestamp freshness
193
- const now = Date.now();
194
- if (now - timestamp > maxAgeMs) {
195
- return false;
196
- }
197
-
198
- // Verify signature
199
- const messageWithTimestamp = `${message}:${timestamp}`;
200
- return SignatureService.verify(messageWithTimestamp, signature, publicKey);
201
- }
202
-
203
- /**
204
- * Create a signed authentication challenge response
205
- * Used for challenge-response authentication
206
- */
207
- static async signChallenge(challenge) {
208
- const publicKey = await KeyManager.getPublicKey();
209
- if (!publicKey) {
210
- throw new Error('No identity found. Please create or import an identity first.');
211
- }
212
- const timestamp = Date.now();
213
- const message = `auth:${publicKey}:${challenge}:${timestamp}`;
214
- const signature = await SignatureService.sign(message);
215
- return {
216
- challenge: signature,
217
- publicKey,
218
- timestamp
219
- };
220
- }
221
-
222
- /**
223
- * Verify a challenge response
224
- */
225
- static async verifyChallengeResponse(originalChallenge, response, maxAgeMs = 5 * 60 * 1000) {
226
- const {
227
- challenge: signature,
228
- publicKey,
229
- timestamp
230
- } = response;
231
-
232
- // Check timestamp freshness
233
- const now = Date.now();
234
- if (now - timestamp > maxAgeMs) {
235
- return false;
236
- }
237
- const message = `auth:${publicKey}:${originalChallenge}:${timestamp}`;
238
- return SignatureService.verify(message, signature, publicKey);
239
- }
240
-
241
- /**
242
- * Sign arbitrary data for API requests
243
- * Creates a canonical string representation and signs it
244
- */
245
- static async signRequestData(data) {
246
- const publicKey = await KeyManager.getPublicKey();
247
- if (!publicKey) {
248
- throw new Error('No identity found. Please create or import an identity first.');
249
- }
250
- const timestamp = Date.now();
251
-
252
- // Create canonical string representation
253
- const sortedKeys = Object.keys(data).sort();
254
- const canonicalParts = sortedKeys.map(key => `${key}:${JSON.stringify(data[key])}`);
255
- const canonicalString = canonicalParts.join('|');
256
- const message = `request:${publicKey}:${timestamp}:${canonicalString}`;
257
- const signature = await SignatureService.sign(message);
258
- return {
259
- signature,
260
- publicKey,
261
- timestamp
262
- };
263
- }
264
- }
265
- export default SignatureService;
266
- //# sourceMappingURL=signatureService.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["ec","EC","KeyManager","ExpoCrypto","isReactNative","navigator","product","isNodeJS","process","versions","node","initExpoCrypto","sha256","message","Crypto","digestStringAsync","CryptoDigestAlgorithm","SHA256","getCrypto","Function","crypto","createHash","update","digest","error","SignatureService","generateChallenge","randomBytes","getRandomBytesAsync","Array","from","map","b","toString","padStart","join","hashMessage","sign","keyPair","getKeyPairObject","Error","messageHash","signature","toDER","signWithKey","privateKey","keyFromPrivate","verify","publicKey","key","keyFromPublic","verifySync","createSignedMessage","getPublicKey","timestamp","Date","now","messageWithTimestamp","verifySignedMessage","signedMessage","maxAgeMs","signChallenge","challenge","verifyChallengeResponse","originalChallenge","response","signRequestData","data","sortedKeys","Object","keys","sort","canonicalParts","JSON","stringify","canonicalString"],"sourceRoot":"../../../src","sources":["crypto/signatureService.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,EAAE,IAAIC,EAAE,QAAQ,UAAU;AACnC,SAASC,UAAU,QAAQ,cAAc;;AAEzC;AACA,IAAIC,UAA+C,GAAG,IAAI;AAE1D,MAAMH,EAAE,GAAG,IAAIC,EAAE,CAAC,WAAW,CAAC;;AAE9B;AACA;AACA;AACA,SAASG,aAAaA,CAAA,EAAY;EAChC,OAAO,OAAOC,SAAS,KAAK,WAAW,IAAIA,SAAS,CAACC,OAAO,KAAK,aAAa;AAChF;;AAEA;AACA;AACA;AACA,SAASC,QAAQA,CAAA,EAAY;EAC3B,OAAO,OAAOC,OAAO,KAAK,WAAW,IAAIA,OAAO,CAACC,QAAQ,IAAI,IAAI,IAAID,OAAO,CAACC,QAAQ,CAACC,IAAI,IAAI,IAAI;AACpG;;AAEA;AACA;AACA;AACA,eAAeC,cAAcA,CAAA,EAA0C;EACrE,IAAI,CAACR,UAAU,EAAE;IACfA,UAAU,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC;EAC1C;EACA,OAAOA,UAAU;AACnB;;AAEA;AACA;AACA;AACA,eAAeS,MAAMA,CAACC,OAAe,EAAmB;EACtD;EACA,IAAIT,aAAa,CAAC,CAAC,IAAI,CAACG,QAAQ,CAAC,CAAC,EAAE;IAClC,MAAMO,MAAM,GAAG,MAAMH,cAAc,CAAC,CAAC;IACrC,OAAOG,MAAM,CAACC,iBAAiB,CAC7BD,MAAM,CAACE,qBAAqB,CAACC,MAAM,EACnCJ,OACF,CAAC;EACH;;EAEA;EACA;EACA;EACA,IAAI;IACF;IACA,MAAMK,SAAS,GAAG,IAAIC,QAAQ,CAAC,0BAA0B,CAAC;IAC1D,MAAMC,MAAM,GAAGF,SAAS,CAAC,CAAC;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