@thru/passkey 0.2.12 → 0.2.14

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 (71) hide show
  1. package/README.md +73 -90
  2. package/dist/auth.cjs +672 -0
  3. package/dist/auth.cjs.map +1 -0
  4. package/dist/auth.d.cts +60 -0
  5. package/dist/auth.d.ts +60 -0
  6. package/dist/auth.js +422 -0
  7. package/dist/auth.js.map +1 -0
  8. package/dist/chunk-2JHC7OOH.js +250 -0
  9. package/dist/chunk-2JHC7OOH.js.map +1 -0
  10. package/dist/chunk-75G2FPYW.js +54 -0
  11. package/dist/chunk-75G2FPYW.js.map +1 -0
  12. package/dist/chunk-B5SN7AS7.js +586 -0
  13. package/dist/chunk-B5SN7AS7.js.map +1 -0
  14. package/dist/chunk-LNDWK3FA.js +163 -0
  15. package/dist/chunk-LNDWK3FA.js.map +1 -0
  16. package/dist/index.cjs +27 -94
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +4 -187
  19. package/dist/index.d.ts +4 -187
  20. package/dist/index.js +47 -810
  21. package/dist/index.js.map +1 -1
  22. package/dist/mobile.cjs +301 -0
  23. package/dist/mobile.cjs.map +1 -0
  24. package/dist/mobile.d.cts +49 -0
  25. package/dist/mobile.d.ts +49 -0
  26. package/dist/mobile.js +41 -0
  27. package/dist/mobile.js.map +1 -0
  28. package/dist/popup.cjs +247 -0
  29. package/dist/popup.cjs.map +1 -0
  30. package/dist/popup.d.cts +22 -0
  31. package/dist/popup.d.ts +22 -0
  32. package/dist/popup.js +31 -0
  33. package/dist/popup.js.map +1 -0
  34. package/dist/server.cjs +351 -0
  35. package/dist/server.cjs.map +1 -0
  36. package/dist/server.d.cts +119 -0
  37. package/dist/server.d.ts +119 -0
  38. package/dist/server.js +340 -0
  39. package/dist/server.js.map +1 -0
  40. package/dist/types-_HRzmn-j.d.cts +125 -0
  41. package/dist/types-_HRzmn-j.d.ts +125 -0
  42. package/dist/web.cjs +758 -0
  43. package/dist/web.cjs.map +1 -0
  44. package/dist/web.d.cts +32 -0
  45. package/dist/web.d.ts +32 -0
  46. package/dist/web.js +60 -0
  47. package/dist/web.js.map +1 -0
  48. package/package.json +47 -2
  49. package/src/auth/execute-tx.ts +87 -0
  50. package/src/auth/index.ts +18 -0
  51. package/src/auth/types.ts +56 -0
  52. package/src/auth/use-passkey-auth.ts +428 -0
  53. package/src/index.ts +37 -39
  54. package/src/mobile/errors.ts +31 -0
  55. package/src/mobile/index.ts +33 -0
  56. package/src/mobile/passkey.ts +154 -0
  57. package/src/mobile/storage.ts +115 -0
  58. package/src/mobile/types.ts +24 -0
  59. package/src/popup-entry.ts +33 -0
  60. package/src/popup-service.ts +0 -103
  61. package/src/server/challenge.ts +26 -0
  62. package/src/server/create-wallet.ts +149 -0
  63. package/src/server/handlers.ts +93 -0
  64. package/src/server/index.ts +13 -0
  65. package/src/server/submit.ts +47 -0
  66. package/src/server/types.ts +70 -0
  67. package/src/server/utils.ts +69 -0
  68. package/src/types.ts +1 -0
  69. package/src/web.ts +51 -0
  70. package/tsconfig.json +6 -1
  71. package/tsup.config.ts +9 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @thru/passkey
2
2
 
3
- Browser-only WebAuthn package for passkey registration, signing, and popup-based flows. Built on top of `@thru/passkey-manager` for platform-agnostic crypto and encoding utilities.
3
+ Cross-platform passkey helpers for Thru applications.
4
4
 
5
5
  ## Installation
6
6
 
@@ -8,82 +8,74 @@ Browser-only WebAuthn package for passkey registration, signing, and popup-based
8
8
  npm install @thru/passkey
9
9
  ```
10
10
 
11
- This package requires a browser environment with WebAuthn support (`navigator.credentials`).
11
+ ## Entry Points
12
12
 
13
- ## Basic Usage
13
+ - `@thru/passkey/web` - browser/WebAuthn registration and signing
14
+ - `@thru/passkey/popup` - popup bridge/protocol helpers for embedded browser flows
15
+ - `@thru/passkey/mobile` - React Native/mobile passkey and secure-storage helpers
16
+ - `@thru/passkey/auth` - higher-level app auth/store helpers
17
+ - `@thru/passkey/server` - backend wallet/challenge/submit helpers
14
18
 
15
- ### Register a Passkey
19
+ ## Deprecated Root Import
16
20
 
17
- Create a new P-256 credential bound to the user's platform authenticator:
21
+ The root import path is deprecated:
18
22
 
19
23
  ```typescript
20
24
  import { registerPasskey } from '@thru/passkey';
25
+ ```
26
+
27
+ Use explicit entry points instead:
28
+
29
+ ```typescript
30
+ import { registerPasskey } from '@thru/passkey/web';
31
+ ```
32
+
33
+ The root path remains as a temporary compatibility shim and will be removed after downstream consumers migrate.
34
+
35
+ ## Browser Usage
36
+
37
+ This package requires a browser environment with WebAuthn support (`navigator.credentials`).
38
+
39
+ ### Register a Passkey
40
+
41
+ ```typescript
42
+ import { registerPasskey } from '@thru/passkey/web';
21
43
 
22
44
  const result = await registerPasskey('alice', 'user-id-123', 'example.com');
23
- // result.credentialId - base64url credential ID
24
- // result.publicKeyX - hex-encoded P-256 X coordinate
25
- // result.publicKeyY - hex-encoded P-256 Y coordinate
26
- // result.rpId - relying party ID
27
45
  ```
28
46
 
29
47
  ### Sign with a Known Credential
30
48
 
31
- Sign a challenge using a specific credential ID:
32
-
33
49
  ```typescript
34
- import { signWithPasskey } from '@thru/passkey';
50
+ import { signWithPasskey } from '@thru/passkey/web';
35
51
 
36
- const challenge = new Uint8Array(32); // your challenge bytes
52
+ const challenge = new Uint8Array(32);
37
53
  const result = await signWithPasskey(credentialId, challenge, 'example.com');
38
- // result.signature - 64-byte concatenated r||s (low-S normalized)
39
- // result.signatureR - 32-byte r component
40
- // result.signatureS - 32-byte s component
41
- // result.authenticatorData - raw authenticator data
42
- // result.clientDataJSON - raw client data JSON
43
54
  ```
44
55
 
45
56
  ### Sign with a Stored Passkey
46
57
 
47
- For embedded or iframe contexts where you have stored passkey metadata. Automatically falls back to a popup window when inline WebAuthn is restricted:
48
-
49
58
  ```typescript
50
- import { signWithStoredPasskey } from '@thru/passkey';
51
- import type { PasskeyMetadata } from '@thru/passkey';
59
+ import { signWithStoredPasskey } from '@thru/passkey/web';
60
+ import type { PasskeyMetadata, PasskeyPopupContext } from '@thru/passkey/web';
61
+
62
+ const preferredPasskey: PasskeyMetadata | null = null;
63
+ const allPasskeys: PasskeyMetadata[] = [];
64
+ const context: PasskeyPopupContext = {
65
+ appName: 'My App',
66
+ origin: 'https://app.example.com',
67
+ };
52
68
 
53
69
  const result = await signWithStoredPasskey(
54
70
  challenge,
55
71
  'example.com',
56
- preferredPasskey, // PasskeyMetadata | null
57
- allPasskeys, // PasskeyMetadata[]
58
- { appName: 'My App', origin: 'https://app.example.com' }
72
+ preferredPasskey,
73
+ allPasskeys,
74
+ context
59
75
  );
60
- // result includes .passkey metadata for the credential that signed
61
76
  ```
62
77
 
63
- ### Sign with a Discoverable Passkey
64
-
65
- Let the browser prompt the user to choose from their available passkeys:
66
-
67
- ```typescript
68
- import { signWithDiscoverablePasskey } from '@thru/passkey';
69
-
70
- const result = await signWithDiscoverablePasskey(challenge, 'example.com');
71
- // result.credentialId - the credential the user selected
72
- // result.rpId - relying party ID
73
- ```
74
-
75
- ## Key Capabilities
76
-
77
- - **P-256 (ES256) credential creation** via `navigator.credentials.create` with platform authenticator selection, resident key, and user verification required
78
- - **Three signing modes**: known credential, stored passkey with fallback, and discoverable (browser-prompted)
79
- - **Automatic popup fallback** for iframe/embedded contexts where the Permissions Policy blocks inline WebAuthn
80
- - **Low-S signature normalization** applied to all signing results for protocol compatibility
81
- - **Capability detection** to query WebAuthn support, client capabilities, and determine the optimal prompt mode before signing
82
- - **Re-exports** encoding and crypto utilities from `@thru/passkey-manager` for backward compatibility
83
-
84
- ## Capability Detection
85
-
86
- Check browser support and determine the best prompt mode ahead of time:
78
+ ### Capability Detection
87
79
 
88
80
  ```typescript
89
81
  import {
@@ -91,27 +83,12 @@ import {
91
83
  preloadPasskeyClientCapabilities,
92
84
  getPasskeyClientCapabilities,
93
85
  shouldUsePasskeyPopup,
94
- isInIframe,
95
- } from '@thru/passkey';
96
-
97
- // Quick synchronous check
98
- if (!isWebAuthnSupported()) {
99
- // WebAuthn not available
100
- }
101
-
102
- // Preload capabilities early (e.g., on app init)
103
- preloadPasskeyClientCapabilities();
104
-
105
- // Later, read cached or await capabilities
106
- const capabilities = await getPasskeyClientCapabilities();
107
-
108
- // Check if a popup is needed for a given action
109
- const needsPopup = await shouldUsePasskeyPopup('get');
86
+ } from '@thru/passkey/web';
110
87
  ```
111
88
 
112
89
  ## Popup Bridge
113
90
 
114
- For applications that host the passkey popup window (e.g., the wallet app), the package provides both the parent-side and popup-side APIs:
91
+ Use the popup helpers when your browser app needs a separate approval window for embedded or iframe-based passkey flows.
115
92
 
116
93
  ### Parent Side
117
94
 
@@ -122,44 +99,50 @@ import {
122
99
  closePopup,
123
100
  PASSKEY_POPUP_PATH,
124
101
  PASSKEY_POPUP_CHANNEL,
125
- } from '@thru/passkey';
102
+ } from '@thru/passkey/popup';
126
103
  ```
127
104
 
128
105
  ### Popup Window Side
129
106
 
130
107
  ```typescript
131
108
  import {
132
- toPopupSigningResult,
133
109
  buildSuccessResponse,
134
110
  decodeChallenge,
135
- getPopupDisplayInfo,
136
111
  getResponseError,
137
- signWithPreferredPasskey,
138
- buildStoredPasskeyResult,
139
- } from '@thru/passkey';
112
+ toPopupSigningResult,
113
+ } from '@thru/passkey/popup';
140
114
  ```
141
115
 
142
116
  Communication between parent and popup uses `postMessage` with `BroadcastChannel` as a fallback. The popup path defaults to `/passkey/popup`.
143
117
 
144
- ## Re-exported Utilities
118
+ ## Browser Convenience Exports
145
119
 
146
- The following are re-exported from `@thru/passkey-manager` for convenience:
120
+ `@thru/passkey/web` re-exports the browser-side encoding and crypto helpers used by the wallet today, including:
147
121
 
148
- **Crypto**: `parseDerSignature`, `normalizeLowS`, `normalizeSignatureComponent`, `P256_N`, `P256_HALF_N`, `bytesToBigIntBE`, `bigIntToBytesBE`
149
-
150
- **Encoding**: `arrayBufferToBase64Url`, `base64UrlToArrayBuffer`, `bytesToBase64Url`, `base64UrlToBytes`, `bytesToHex`, `hexToBytes`, `bytesEqual`, `compareBytes`, `uniqueAccounts`
122
+ - `bytesToHex`
123
+ - `hexToBytes`
124
+ - `bytesToBase64`
125
+ - `bytesToBase64Url`
126
+ - `base64UrlToBytes`
127
+ - `arrayBufferToBase64Url`
128
+ - `base64UrlToArrayBuffer`
151
129
 
152
130
  ## Types
153
131
 
154
- Key types exported from this package:
155
-
156
- | Type | Description |
157
- |------|-------------|
158
- | `PasskeyRegistrationResult` | Credential ID and P-256 public key coordinates |
159
- | `PasskeySigningResult` | Signature bytes, authenticator data, and client data |
160
- | `PasskeyDiscoverableSigningResult` | Signing result with credential ID and rpId |
161
- | `PasskeyStoredSigningResult` | Signing result with attached passkey metadata |
162
- | `PasskeyMetadata` | Stored passkey info (credential ID, public key, rpId, timestamps) |
163
- | `PasskeyClientCapabilities` | WebAuthn client capability flags |
164
- | `PasskeyPopupContext` | App context passed to popup for display |
165
- | `PasskeyPopupAccount` | Account info passed through popup bridge |
132
+ Key web types exported from `@thru/passkey/web`:
133
+
134
+ - `PasskeyRegistrationResult`
135
+ - `PasskeySigningResult`
136
+ - `PasskeyDiscoverableSigningResult`
137
+ - `PasskeyStoredSigningResult`
138
+ - `PasskeyMetadata`
139
+ - `PasskeyClientCapabilities`
140
+ - `PasskeyPopupContext`
141
+
142
+ Key popup types exported from `@thru/passkey/popup`:
143
+
144
+ - `PasskeyPopupRequest`
145
+ - `PasskeyPopupResponse`
146
+ - `PasskeyPopupSigningResult`
147
+ - `PasskeyPopupStoredSigningResult`
148
+ - `PasskeyPopupAccount`