local-first-auth-simulator 1.4.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Taddy Artist Database Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # Local First Auth Simulator
2
+
3
+ Development simulator for Local First Auth mini-apps. Test your mini-apps locally on a regular browser without needing Antler or another Local First Auth app.
4
+
5
+ ## What is this?
6
+
7
+ Antler is a demo Local First Auth app that lets users scan QR codes at physical locations to launch web-based mini-apps. When running inside Antler or another Local First Auth mobile app, your mini-app has access to the `window.localFirstAuth` JavaScript Object / API for getting user profile data, requesting permissions, and more.
8
+
9
+ This package injects a mock `window.localFirstAuth` API into your browser, complete with a floating debug UI for triggering events and inspecting JWTs.
10
+
11
+ ## Features
12
+
13
+ - Mock `window.localFirstAuth` API that matches the real Local First Auth behavior
14
+ - Floating debug UI for triggering API methods and events
15
+ - JWT signing with ED25519 keys using @stablelib/ed25519
16
+ - Multi-user testing support with multiple tabs using URL parameter `?test_profile=<id>`
17
+ - Simulated network delays for realistic testing
18
+ - Permission request flows
19
+ - TypeScript support with full type definitions
20
+ - Zero configuration - just import and enable
21
+ - Framework agnostic - works with React, Vue, vanilla JS, etc.
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ npm install --save-dev local-first-auth-simulator
27
+ ```
28
+
29
+ ## Quick Start
30
+
31
+ ```typescript
32
+ if (import.meta.env.DEV) {
33
+ const simulator = await import('local-first-auth-simulator')
34
+ simulator.enableLocalFirstAuthSimulator({
35
+ profile: simulator.getProfileById('alice')
36
+ })
37
+ }
38
+ ```
39
+
40
+ ## Multi-User Testing
41
+
42
+ A major usecase for a Local First Auth mini app is multiple people physically present at the same time, each with their own profile. You can simulate multiple users by opening multiple tabs with the same mini app, each with a different URL parameter `?test_profile=<id>`.
43
+
44
+ The simulator comes with 6 preset profiles for testing multi-user scenarios.
45
+
46
+ **Testing via URL:**
47
+ - Open `http://localhost:your-port?test_profile=alice` in one tab → Alice's profile
48
+ - Open `http://localhost:your-port?test_profile=bob` in another tab → Bob's profile
49
+ - Each tab simulates a different user!
50
+
51
+ **Debug UI:**
52
+ The debug UI includes buttons to quickly open new tabs with different profiles.
53
+
54
+ ## Changing the default profile
55
+ By default, the simulator will use the Paul Morphy profile. To use a different profile, pass in the ID of the profile to the `enableLocalFirstAuthSimulator` function. You can get the profile by its ID using the `getProfileById` function.
56
+
57
+ ```typescript
58
+ if (import.meta.env.DEV) {
59
+ const simulator = await import('local-first-auth-simulator')
60
+ simulator.enableLocalFirstAuthSimulator({
61
+ profile: simulator.getProfileById('alice')
62
+ })
63
+ }
64
+ ```
65
+
66
+ That's it! The simulator will:
67
+ - Inject `window.localFirstAuth` into your page
68
+ - Load a default test profile (Paul Morphy)
69
+ - Show a floating debug panel
70
+ - Automatically load the profile from the URL parameter `?test_profile=<id>`
71
+ - Test multi-user scenarios across tabs
72
+ - Be ready for your mini-app to use
73
+
74
+ ## Local First Auth Specification
75
+
76
+ See `docs/local-first-auth-specification.md` for the Local First Auth Specification, which defines how a Local First Auth app communicates and what is being mocked in this package.
77
+
78
+ ## Configuration Options
79
+
80
+ ```typescript
81
+ interface SimulatorConfig {
82
+ profile?: Profile; // Custom profile object, defaults to Paul Morphy profile if no profile is provided
83
+
84
+ jwtDetails?: {
85
+ audience?: string; // Mini-app domain (defaults to window.location.origin)
86
+ expirationOffsetSeconds?: number; // JWT expiration (defaults to 120)
87
+ };
88
+
89
+ appDetails?: {
90
+ name?: string; // defaults to "Local First Auth Simulator"
91
+ version?: string; // defaults to "1.0.0"
92
+ platform?: 'ios' | 'android' | 'browser'; // defaults to "ios"
93
+ supportedPermissions?: string[]; // defaults to ["profile"]
94
+ };
95
+
96
+ networkDelayMs?: number; // Simulated delay (defaults to 50ms)
97
+ showDebugUI?: boolean; // Show debug panel (defaults to true)
98
+ }
99
+ ```
100
+
101
+ ## Debug UI
102
+
103
+ The floating debug panel provides:
104
+ - Current profile information with color-coded badge
105
+ - Buttons to trigger API methods (getProfileDetails, getAvatar, etc.)
106
+ - Buttons to open new tabs with different user profiles
107
+ - Buttons to send events (disconnect, errors)
108
+ - Keyboard shortcut: `Ctrl+Shift+D` to toggle visibility
109
+ - Quick testing without writing code
110
+
111
+ ## Security Notes
112
+
113
+ - This is a development tool - do not use in production!
114
+ - JWTs are properly signed using @stablelib/ed25519
115
+ - All JWTs can be verified using the issuer's public key extracted from the DID