local-lite 2.0.4 → 2.0.5

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.
@@ -98,7 +98,7 @@ class AppleAuthClient {
98
98
  if (!this.options.redirectUri) {
99
99
  throw new Error('Apple OAuth redirectUri is required for web authorization flow.');
100
100
  }
101
- const randomBytes = this.options.randomBytes ?? crypto_js_1.getRandomBytes;
101
+ const randomBytes = this.options.randomBytes ?? crypto_js_1.requireSecureRandomBytes;
102
102
  const state = (0, crypto_js_1.base64UrlEncode)(randomBytes(32));
103
103
  const nonce = (0, crypto_js_1.base64UrlEncode)(randomBytes(32));
104
104
  const scopes = this.options.scopes && this.options.scopes.length > 0
@@ -73,7 +73,7 @@ class GitHubAuthClient {
73
73
  }
74
74
  }
75
75
  async signIn() {
76
- const randomBytes = this.options.randomBytes ?? crypto_js_1.getRandomBytes;
76
+ const randomBytes = this.options.randomBytes ?? crypto_js_1.requireSecureRandomBytes;
77
77
  const stateBytes = randomBytes(32);
78
78
  if (stateBytes.length !== 32) {
79
79
  throw new Error('The randomBytes provider returned an invalid number of bytes.');
@@ -4,9 +4,6 @@ exports.GoogleAuthClient = exports.DEFAULT_GOOGLE_AUTH_SCOPES = exports.GOOGLE_U
4
4
  exports.createInMemoryGoogleTokenStore = createInMemoryGoogleTokenStore;
5
5
  exports.createGoogleAuthTokenStore = createGoogleAuthTokenStore;
6
6
  const identity_js_1 = require("./identity.js");
7
- const sha2_js_1 = require("@noble/hashes/sha2.js");
8
- const utils_js_1 = require("@noble/hashes/utils.js");
9
- const crypto_js_1 = require("../utils/crypto.js");
10
7
  const oauth_js_1 = require("../utils/oauth.js");
11
8
  const cloud_storage_js_1 = require("../backups/cloud-storage.js");
12
9
  exports.GOOGLE_AUTHORIZATION_ENDPOINT = 'https://accounts.google.com/o/oauth2/v2/auth';
@@ -86,15 +83,7 @@ class GoogleAuthClient {
86
83
  }
87
84
  }
88
85
  async signIn() {
89
- const randomBytes = this.options.randomBytes ?? crypto_js_1.getRandomBytes;
90
- const verifierBytes = randomBytes(32);
91
- const stateBytes = randomBytes(32);
92
- if (verifierBytes.length !== 32 || stateBytes.length !== 32) {
93
- throw new Error('The randomBytes provider returned an invalid number of bytes.');
94
- }
95
- const codeVerifier = (0, crypto_js_1.base64UrlEncode)(verifierBytes);
96
- const codeChallenge = (0, crypto_js_1.base64UrlEncode)((0, sha2_js_1.sha256)((0, utils_js_1.utf8ToBytes)(codeVerifier)));
97
- const state = (0, crypto_js_1.base64UrlEncode)(stateBytes);
86
+ const { codeVerifier, codeChallenge, state } = (0, oauth_js_1.createPkceChallengePair)(this.options.randomBytes);
98
87
  const scopes = this.options.scopes && this.options.scopes.length > 0
99
88
  ? this.options.scopes
100
89
  : exports.DEFAULT_GOOGLE_AUTH_SCOPES;
@@ -13,6 +13,7 @@ const utils_js_1 = require("@noble/hashes/utils.js");
13
13
  const event_emitter_js_1 = require("../reactive/event-emitter.js");
14
14
  const uuid_js_1 = require("../utils/uuid.js");
15
15
  const sql_js_1 = require("../utils/sql.js");
16
+ const crypto_js_1 = require("../utils/crypto.js");
16
17
  const generator_js_1 = require("../keys/generator.js");
17
18
  const session_js_1 = require("./session.js");
18
19
  exports.DEFAULT_USERS_TABLE = '_local_users';
@@ -28,31 +29,7 @@ exports.DEFAULT_MIN_PASSWORD_LENGTH = 8;
28
29
  * Generates cryptographically secure random bytes across Web, Expo/React Native, and Node.js.
29
30
  */
30
31
  function getCryptoRandomBytes(length) {
31
- const cryptoObj = typeof globalThis !== 'undefined' ? globalThis.crypto : undefined;
32
- if (cryptoObj?.getRandomValues) {
33
- try {
34
- return cryptoObj.getRandomValues(new Uint8Array(length));
35
- }
36
- catch {
37
- // Fallback below
38
- }
39
- }
40
- try {
41
- const nodeCrypto = globalThis.process?.versions?.node
42
- ? globalThis.require('node:crypto')
43
- : null;
44
- if (nodeCrypto?.randomBytes) {
45
- return new Uint8Array(nodeCrypto.randomBytes(length));
46
- }
47
- }
48
- catch {
49
- // Fallback ignored
50
- }
51
- const fallback = new Uint8Array(length);
52
- for (let i = 0; i < length; i++) {
53
- fallback[i] = Math.floor(Math.random() * 256);
54
- }
55
- return fallback;
32
+ return (0, crypto_js_1.getRandomBytes)(length);
56
33
  }
57
34
  /**
58
35
  * Derives PBKDF2 keys using hardware-accelerated WebCrypto if available,
@@ -4,9 +4,6 @@ exports.MicrosoftAuthClient = exports.DEFAULT_MICROSOFT_AUTH_SCOPES = exports.MI
4
4
  exports.createInMemoryMicrosoftTokenStore = createInMemoryMicrosoftTokenStore;
5
5
  exports.createMicrosoftAuthTokenStore = createMicrosoftAuthTokenStore;
6
6
  const identity_js_1 = require("./identity.js");
7
- const sha2_js_1 = require("@noble/hashes/sha2.js");
8
- const utils_js_1 = require("@noble/hashes/utils.js");
9
- const crypto_js_1 = require("../utils/crypto.js");
10
7
  const oauth_js_1 = require("../utils/oauth.js");
11
8
  const onedrive_js_1 = require("../backups/onedrive.js");
12
9
  exports.MICROSOFT_GRAPH_ENDPOINT = 'https://graph.microsoft.com/v1.0';
@@ -91,15 +88,7 @@ class MicrosoftAuthClient {
91
88
  }
92
89
  }
93
90
  async signIn() {
94
- const randomBytes = this.options.randomBytes ?? crypto_js_1.getRandomBytes;
95
- const verifierBytes = randomBytes(32);
96
- const stateBytes = randomBytes(32);
97
- if (verifierBytes.length !== 32 || stateBytes.length !== 32) {
98
- throw new Error('The randomBytes provider returned an invalid number of bytes.');
99
- }
100
- const codeVerifier = (0, crypto_js_1.base64UrlEncode)(verifierBytes);
101
- const codeChallenge = (0, crypto_js_1.base64UrlEncode)((0, sha2_js_1.sha256)((0, utils_js_1.utf8ToBytes)(codeVerifier)));
102
- const state = (0, crypto_js_1.base64UrlEncode)(stateBytes);
91
+ const { codeVerifier, codeChallenge, state } = (0, oauth_js_1.createPkceChallengePair)(this.options.randomBytes);
103
92
  const scopes = this.options.scopes && this.options.scopes.length > 0
104
93
  ? this.options.scopes
105
94
  : exports.DEFAULT_MICROSOFT_AUTH_SCOPES;
@@ -3,10 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GoogleDriveBackupClient = exports.GoogleDriveBackupStorage = exports.GOOGLE_DRIVE_SCOPE = void 0;
4
4
  exports.createInMemoryGoogleDriveTokenStore = createInMemoryGoogleDriveTokenStore;
5
5
  exports.createGoogleDriveTokenStore = createGoogleDriveTokenStore;
6
- const sha2_js_1 = require("@noble/hashes/sha2.js");
7
- const utils_js_1 = require("@noble/hashes/utils.js");
8
6
  const operations_js_1 = require("./operations.js");
9
- const crypto_js_1 = require("../utils/crypto.js");
10
7
  const oauth_js_1 = require("../utils/oauth.js");
11
8
  const GOOGLE_API = 'https://www.googleapis.com/drive/v3';
12
9
  const GOOGLE_UPLOAD_API = 'https://www.googleapis.com/upload/drive/v3';
@@ -238,15 +235,7 @@ class GoogleDriveBackupClient {
238
235
  this.notify(connected);
239
236
  return connected;
240
237
  }
241
- const randomBytes = this.options.randomBytes ?? crypto_js_1.requireSecureRandomBytes;
242
- const verifierBytes = randomBytes(32);
243
- const stateBytes = randomBytes(32);
244
- if (verifierBytes.length !== 32 || stateBytes.length !== 32) {
245
- throw new Error('The randomBytes provider returned an invalid number of bytes.');
246
- }
247
- const codeVerifier = (0, crypto_js_1.base64UrlEncode)(verifierBytes);
248
- const codeChallenge = (0, crypto_js_1.base64UrlEncode)((0, sha2_js_1.sha256)((0, utils_js_1.utf8ToBytes)(codeVerifier)));
249
- const state = (0, crypto_js_1.base64UrlEncode)(stateBytes);
238
+ const { codeVerifier, codeChallenge, state } = (0, oauth_js_1.createPkceChallengePair)(this.options.randomBytes);
250
239
  const authorizationParams = new URLSearchParams({
251
240
  client_id: this.options.clientId,
252
241
  redirect_uri: this.options.redirectUri,
@@ -39,20 +39,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
39
39
  const react_1 = __importStar(require("react"));
40
40
  const theme_js_1 = require("../react/theme.js");
41
41
  const sql_js_1 = require("../utils/sql.js");
42
- let RN;
43
- try {
44
- RN = require('react-native');
45
- }
46
- catch {
47
- // Web / DOM environment
48
- }
49
- let RNSafeArea;
50
- try {
51
- RNSafeArea = require('react-native-safe-area-context');
52
- }
53
- catch {
54
- // Web / DOM environment or not installed
55
- }
42
+ const shared_js_1 = require("./shared.js");
56
43
  const now = () => typeof performance !== 'undefined' && typeof performance.now === 'function'
57
44
  ? performance.now()
58
45
  : Date.now();
@@ -573,7 +560,7 @@ function BenchmarkModal({ client, visible, onDismiss, theme = 'auto', }) {
573
560
  const [progress, setProgress] = (0, react_1.useState)(0);
574
561
  const [results, setResults] = (0, react_1.useState)([]);
575
562
  const [copied, setCopied] = (0, react_1.useState)(false);
576
- const systemColorScheme = RN?.useColorScheme ? RN.useColorScheme() : null;
563
+ const systemColorScheme = shared_js_1.RN?.useColorScheme ? shared_js_1.RN.useColorScheme() : null;
577
564
  const currentTheme = react_1.default.useMemo(() => (0, theme_js_1.resolveSyncTheme)(theme, systemColorScheme), [theme, systemColorScheme]);
578
565
  const startBenchmark = async () => {
579
566
  if (!client)
@@ -600,7 +587,7 @@ function BenchmarkModal({ client, visible, onDismiss, theme = 'auto', }) {
600
587
  return;
601
588
  const report = [
602
589
  '# ⚡ local-lite SQLite Benchmark Report',
603
- `- Platform: ${RN && RN.Platform ? RN.Platform.OS : 'web'}`,
590
+ `- Platform: ${shared_js_1.RN && shared_js_1.RN.Platform ? shared_js_1.RN.Platform.OS : 'web'}`,
604
591
  `- Date: ${new Date().toLocaleString()}`,
605
592
  ...(results[0]?.note ? [`- App dataset: ${results[0].note}`] : []),
606
593
  '',
@@ -610,8 +597,8 @@ function BenchmarkModal({ client, visible, onDismiss, theme = 'auto', }) {
610
597
  ].join('\n');
611
598
  let isCopied = false;
612
599
  try {
613
- if (RN && RN.Clipboard && typeof RN.Clipboard.setString === 'function') {
614
- RN.Clipboard.setString(report);
600
+ if (shared_js_1.RN && shared_js_1.RN.Clipboard && typeof shared_js_1.RN.Clipboard.setString === 'function') {
601
+ shared_js_1.RN.Clipboard.setString(report);
615
602
  isCopied = true;
616
603
  }
617
604
  }
@@ -629,9 +616,9 @@ function BenchmarkModal({ client, visible, onDismiss, theme = 'auto', }) {
629
616
  if (!visible)
630
617
  return null;
631
618
  // React Native renderer (Full-height modal)
632
- if (RN && RN.View) {
633
- const { View, Text, TouchableOpacity, ScrollView, Modal, ActivityIndicator, Platform, StatusBar, } = RN;
634
- const SafeComp = RNSafeArea?.SafeAreaView || RN.SafeAreaView || View;
619
+ if (shared_js_1.RN && shared_js_1.RN.View) {
620
+ const { View, Text, TouchableOpacity, ScrollView, Modal, ActivityIndicator, Platform, StatusBar, } = shared_js_1.RN;
621
+ const SafeComp = shared_js_1.RNSafeArea?.SafeAreaView || shared_js_1.RN.SafeAreaView || View;
635
622
  const isAndroid = Platform?.OS === 'android';
636
623
  const statusBarHeight = isAndroid ? StatusBar?.currentHeight || 24 : 0;
637
624
  return ((0, jsx_runtime_1.jsx)(Modal, { visible: visible, animationType: "slide", presentationStyle: "fullScreen", statusBarTranslucent: true, onRequestClose: onDismiss, children: (0, jsx_runtime_1.jsxs)(SafeComp, { style: [styles.fullScreenSafe, { backgroundColor: currentTheme.bg }], edges: ['top', 'bottom', 'left', 'right'], children: [(0, jsx_runtime_1.jsxs)(View, { style: [
@@ -640,7 +627,7 @@ function BenchmarkModal({ client, visible, onDismiss, theme = 'auto', }) {
640
627
  backgroundColor: currentTheme.surface,
641
628
  borderBottomColor: currentTheme.border,
642
629
  },
643
- !RNSafeArea?.SafeAreaView &&
630
+ !shared_js_1.RNSafeArea?.SafeAreaView &&
644
631
  isAndroid && { paddingTop: statusBarHeight + 10 },
645
632
  ], children: [(0, jsx_runtime_1.jsxs)(View, { style: { flex: 1 }, children: [(0, jsx_runtime_1.jsx)(Text, { style: [styles.topBarTitle, { color: currentTheme.text }], children: "\u26A1 SQLite Benchmark" }), (0, jsx_runtime_1.jsx)(Text, { style: [styles.topBarSub, { color: currentTheme.textMuted }], children: "Inbuilt local-lite throughput & ACID test suite" })] }), (0, jsx_runtime_1.jsx)(TouchableOpacity, { onPress: onDismiss, style: [
646
633
  styles.closeCircle,
@@ -718,7 +705,7 @@ function BenchmarkModal({ client, visible, onDismiss, theme = 'auto', }) {
718
705
  backgroundColor: currentTheme.surface,
719
706
  borderTopColor: currentTheme.border,
720
707
  },
721
- !RNSafeArea?.SafeAreaView && isAndroid && { paddingBottom: 32 },
708
+ !shared_js_1.RNSafeArea?.SafeAreaView && isAndroid && { paddingBottom: 32 },
722
709
  ], children: [(0, jsx_runtime_1.jsx)(TouchableOpacity, { onPress: startBenchmark, disabled: isRunning, style: [
723
710
  styles.footerBtn,
724
711
  { backgroundColor: isRunning ? '#6D28D9' : '#8B5CF6' },
@@ -869,32 +856,24 @@ function BenchmarkModal({ client, visible, onDismiss, theme = 'auto', }) {
869
856
  cursor: 'pointer',
870
857
  }, children: copied ? '✓ Copied' : 'Copy Report' }))] })] }));
871
858
  }
872
- const styles = RN && RN.StyleSheet
873
- ? RN.StyleSheet.create({
859
+ const styles = shared_js_1.RN && shared_js_1.RN.StyleSheet
860
+ ? shared_js_1.RN.StyleSheet.create({
874
861
  fullScreenSafe: {
875
- flex: 1,
876
- height: '100%',
862
+ ...shared_js_1.devtoolsBaseRNStyles.fullScreenSafe,
877
863
  backgroundColor: '#111827',
878
864
  },
879
865
  topBar: {
880
- flexDirection: 'row',
881
- alignItems: 'center',
882
- justifyContent: 'space-between',
883
- paddingHorizontal: 18,
884
- paddingVertical: 14,
866
+ ...shared_js_1.devtoolsBaseRNStyles.topBar,
885
867
  backgroundColor: '#1F2937',
886
- borderBottomWidth: 1,
887
868
  borderBottomColor: '#374151',
888
869
  },
889
870
  topBarTitle: {
871
+ ...shared_js_1.devtoolsBaseRNStyles.topBarTitle,
890
872
  color: '#F9FAFB',
891
- fontSize: 17,
892
- fontWeight: '700',
893
873
  },
894
874
  topBarSub: {
875
+ ...shared_js_1.devtoolsBaseRNStyles.topBarSub,
895
876
  color: '#9CA3AF',
896
- fontSize: 11,
897
- marginTop: 2,
898
877
  },
899
878
  closeCircle: {
900
879
  width: 32,
@@ -6,20 +6,7 @@ const react_1 = require("react");
6
6
  const status_js_1 = require("../react/status.js");
7
7
  const BenchmarkModal_js_1 = require("./BenchmarkModal.js");
8
8
  const theme_js_1 = require("../react/theme.js");
9
- let RN;
10
- try {
11
- RN = require('react-native');
12
- }
13
- catch {
14
- // Web / DOM environment
15
- }
16
- let RNSafeArea;
17
- try {
18
- RNSafeArea = require('react-native-safe-area-context');
19
- }
20
- catch {
21
- // Web / DOM environment or not installed
22
- }
9
+ const shared_js_1 = require("./shared.js");
23
10
  const BENCHMARK_DESCRIPTION = 'Runs automated stress tests directly validating local-lite client APIs: atomic batch ingestion, indexing, ACID rollback isolation, outbox queues, and non-blocking WAL concurrency.';
24
11
  /**
25
12
  * Universal Developer Inspector Component for local-lite.
@@ -32,7 +19,7 @@ function SyncInspector({ client, position = 'bottom-right', variant = 'pill', in
32
19
  const status = (0, status_js_1.useSyncStatus)(client);
33
20
  const [metrics, setMetrics] = (0, react_1.useState)(null);
34
21
  const [actionMessage, setActionMessage] = (0, react_1.useState)(null);
35
- const systemColorScheme = RN?.useColorScheme ? RN.useColorScheme() : null;
22
+ const systemColorScheme = shared_js_1.RN?.useColorScheme ? shared_js_1.RN.useColorScheme() : null;
36
23
  const currentTheme = (0, react_1.useMemo)(() => (0, theme_js_1.resolveSyncTheme)(theme, systemColorScheme), [theme, systemColorScheme]);
37
24
  (0, react_1.useEffect)(() => {
38
25
  if (!client || !isOpen)
@@ -83,8 +70,8 @@ function SyncInspector({ client, position = 'bottom-right', variant = 'pill', in
83
70
  }
84
71
  });
85
72
  const message = 'This permanently removes queued pending, processing, and failed mutations. Local database records are not deleted.';
86
- if (RN?.Alert?.alert) {
87
- RN.Alert.alert('Clear stuck outbox?', message, [
73
+ if (shared_js_1.RN?.Alert?.alert) {
74
+ shared_js_1.RN.Alert.alert('Clear stuck outbox?', message, [
88
75
  { text: 'Cancel', style: 'cancel' },
89
76
  {
90
77
  text: 'Clear outbox',
@@ -206,9 +193,9 @@ function SyncInspector({ client, position = 'bottom-right', variant = 'pill', in
206
193
  if (!client)
207
194
  return null;
208
195
  // React Native Renderer
209
- if (RN && RN.View) {
210
- const { View, Text, TouchableOpacity, ScrollView, Modal, Platform, StatusBar, } = RN;
211
- const SafeComp = RNSafeArea?.SafeAreaView || RN.SafeAreaView || View;
196
+ if (shared_js_1.RN && shared_js_1.RN.View) {
197
+ const { View, Text, TouchableOpacity, ScrollView, Modal, Platform, StatusBar, } = shared_js_1.RN;
198
+ const SafeComp = shared_js_1.RNSafeArea?.SafeAreaView || shared_js_1.RN.SafeAreaView || View;
212
199
  const isAndroid = Platform?.OS === 'android';
213
200
  const statusBarHeight = isAndroid ? StatusBar?.currentHeight || 24 : 0;
214
201
  const pillPosStyle = isInline
@@ -257,7 +244,7 @@ function SyncInspector({ client, position = 'bottom-right', variant = 'pill', in
257
244
  backgroundColor: currentTheme.surface,
258
245
  borderBottomColor: currentTheme.border,
259
246
  },
260
- !RNSafeArea?.SafeAreaView &&
247
+ !shared_js_1.RNSafeArea?.SafeAreaView &&
261
248
  isAndroid && { paddingTop: statusBarHeight + 10 },
262
249
  ], children: [(0, jsx_runtime_1.jsxs)(View, { style: { flex: 1 }, children: [(0, jsx_runtime_1.jsx)(Text, { style: [rnStyles.topBarTitle, { color: currentTheme.text }], children: title }), (0, jsx_runtime_1.jsx)(Text, { style: [
263
250
  rnStyles.topBarSub,
@@ -616,28 +603,9 @@ function SyncInspector({ client, position = 'bottom-right', variant = 'pill', in
616
603
  fontWeight: 700,
617
604
  }, children: status.pendingCount }))] })) })), enableBenchmark && !onOpenBenchmark && ((0, jsx_runtime_1.jsx)(BenchmarkModal_js_1.BenchmarkModal, { client: client, visible: isBenchmarkModalOpen, onDismiss: () => setIsBenchmarkModalOpen(false), theme: theme }))] }));
618
605
  }
619
- const rnStyles = RN && RN.StyleSheet
620
- ? RN.StyleSheet.create({
621
- fullScreenSafe: {
622
- flex: 1,
623
- height: '100%',
624
- },
625
- topBar: {
626
- flexDirection: 'row',
627
- alignItems: 'center',
628
- justifyContent: 'space-between',
629
- paddingHorizontal: 18,
630
- paddingVertical: 14,
631
- borderBottomWidth: 1,
632
- },
633
- topBarTitle: {
634
- fontSize: 17,
635
- fontWeight: '700',
636
- },
637
- topBarSub: {
638
- fontSize: 11,
639
- marginTop: 2,
640
- },
606
+ const rnStyles = shared_js_1.RN && shared_js_1.RN.StyleSheet
607
+ ? shared_js_1.RN.StyleSheet.create({
608
+ ...shared_js_1.devtoolsBaseRNStyles,
641
609
  statusBadge: {
642
610
  paddingHorizontal: 8,
643
611
  paddingVertical: 3,
@@ -0,0 +1,25 @@
1
+ declare let RN: any;
2
+ declare let RNSafeArea: any;
3
+ export { RN, RNSafeArea };
4
+ export declare const devtoolsBaseRNStyles: {
5
+ fullScreenSafe: {
6
+ flex: number;
7
+ height: string;
8
+ };
9
+ topBar: {
10
+ flexDirection: 'row';
11
+ alignItems: 'center';
12
+ justifyContent: 'space-between';
13
+ paddingHorizontal: number;
14
+ paddingVertical: number;
15
+ borderBottomWidth: number;
16
+ };
17
+ topBarTitle: {
18
+ fontSize: number;
19
+ fontWeight: '700';
20
+ };
21
+ topBarSub: {
22
+ fontSize: number;
23
+ marginTop: number;
24
+ };
25
+ };
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.devtoolsBaseRNStyles = exports.RNSafeArea = exports.RN = void 0;
4
+ let RN;
5
+ try {
6
+ exports.RN = RN = require('react-native');
7
+ }
8
+ catch {
9
+ // Web / DOM environment
10
+ }
11
+ let RNSafeArea;
12
+ try {
13
+ exports.RNSafeArea = RNSafeArea = require('react-native-safe-area-context');
14
+ }
15
+ catch {
16
+ // Web / DOM environment or not installed
17
+ }
18
+ exports.devtoolsBaseRNStyles = {
19
+ fullScreenSafe: {
20
+ flex: 1,
21
+ height: '100%',
22
+ },
23
+ topBar: {
24
+ flexDirection: 'row',
25
+ alignItems: 'center',
26
+ justifyContent: 'space-between',
27
+ paddingHorizontal: 18,
28
+ paddingVertical: 14,
29
+ borderBottomWidth: 1,
30
+ },
31
+ topBarTitle: {
32
+ fontSize: 17,
33
+ fontWeight: '700',
34
+ },
35
+ topBarSub: {
36
+ fontSize: 11,
37
+ marginTop: 2,
38
+ },
39
+ };
@@ -18,3 +18,12 @@ export interface OAuthTokenErrorPayload {
18
18
  }
19
19
  export declare function parseOAuthTokenResponse<T extends OAuthTokenErrorPayload = Record<string, any>>(response: Response, providerLabel: string): Promise<T>;
20
20
  export declare function throwOAuthError(payload: OAuthTokenErrorPayload, status: number, providerLabel: string): never;
21
+ export interface PkceChallengePair {
22
+ codeVerifier: string;
23
+ codeChallenge: string;
24
+ state: string;
25
+ }
26
+ /**
27
+ * Generates a PKCE S256 verifier/challenge pair and an OAuth state token using a CSPRNG.
28
+ */
29
+ export declare function createPkceChallengePair(randomBytes?: (length: number) => Uint8Array): PkceChallengePair;
@@ -4,6 +4,10 @@ exports.createInMemoryOAuthTokenStore = createInMemoryOAuthTokenStore;
4
4
  exports.createOAuthTokenStore = createOAuthTokenStore;
5
5
  exports.parseOAuthTokenResponse = parseOAuthTokenResponse;
6
6
  exports.throwOAuthError = throwOAuthError;
7
+ exports.createPkceChallengePair = createPkceChallengePair;
8
+ const sha2_js_1 = require("@noble/hashes/sha2.js");
9
+ const utils_js_1 = require("@noble/hashes/utils.js");
10
+ const crypto_js_1 = require("./crypto.js");
7
11
  function createInMemoryOAuthTokenStore() {
8
12
  let storedTokens = null;
9
13
  let storedUser = null;
@@ -58,3 +62,17 @@ function throwOAuthError(payload, status, providerLabel) {
58
62
  payload.error ||
59
63
  `${providerLabel} OAuth request failed (${status}).`);
60
64
  }
65
+ /**
66
+ * Generates a PKCE S256 verifier/challenge pair and an OAuth state token using a CSPRNG.
67
+ */
68
+ function createPkceChallengePair(randomBytes = crypto_js_1.requireSecureRandomBytes) {
69
+ const verifierBytes = randomBytes(32);
70
+ const stateBytes = randomBytes(32);
71
+ if (verifierBytes.length !== 32 || stateBytes.length !== 32) {
72
+ throw new Error('The randomBytes provider returned an invalid number of bytes.');
73
+ }
74
+ const codeVerifier = (0, crypto_js_1.base64UrlEncode)(verifierBytes);
75
+ const codeChallenge = (0, crypto_js_1.base64UrlEncode)((0, sha2_js_1.sha256)((0, utils_js_1.utf8ToBytes)(codeVerifier)));
76
+ const state = (0, crypto_js_1.base64UrlEncode)(stateBytes);
77
+ return { codeVerifier, codeChallenge, state };
78
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "local-lite",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "Never let a lost connection break a promise. Local-first sync that faithfully keeps data safe until you're back online.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",