@thru/passkey 0.2.13 → 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.
- package/README.md +73 -90
- package/dist/auth.cjs +672 -0
- package/dist/auth.cjs.map +1 -0
- package/dist/auth.d.cts +60 -0
- package/dist/auth.d.ts +60 -0
- package/dist/auth.js +422 -0
- package/dist/auth.js.map +1 -0
- package/dist/chunk-2JHC7OOH.js +250 -0
- package/dist/chunk-2JHC7OOH.js.map +1 -0
- package/dist/chunk-75G2FPYW.js +54 -0
- package/dist/chunk-75G2FPYW.js.map +1 -0
- package/dist/chunk-B5SN7AS7.js +586 -0
- package/dist/chunk-B5SN7AS7.js.map +1 -0
- package/dist/chunk-LNDWK3FA.js +163 -0
- package/dist/chunk-LNDWK3FA.js.map +1 -0
- package/dist/index.cjs +27 -94
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -187
- package/dist/index.d.ts +4 -187
- package/dist/index.js +47 -810
- package/dist/index.js.map +1 -1
- package/dist/mobile.cjs +301 -0
- package/dist/mobile.cjs.map +1 -0
- package/dist/mobile.d.cts +49 -0
- package/dist/mobile.d.ts +49 -0
- package/dist/mobile.js +41 -0
- package/dist/mobile.js.map +1 -0
- package/dist/popup.cjs +247 -0
- package/dist/popup.cjs.map +1 -0
- package/dist/popup.d.cts +22 -0
- package/dist/popup.d.ts +22 -0
- package/dist/popup.js +31 -0
- package/dist/popup.js.map +1 -0
- package/dist/server.cjs +351 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +119 -0
- package/dist/server.d.ts +119 -0
- package/dist/server.js +340 -0
- package/dist/server.js.map +1 -0
- package/dist/types-_HRzmn-j.d.cts +125 -0
- package/dist/types-_HRzmn-j.d.ts +125 -0
- package/dist/web.cjs +758 -0
- package/dist/web.cjs.map +1 -0
- package/dist/web.d.cts +32 -0
- package/dist/web.d.ts +32 -0
- package/dist/web.js +60 -0
- package/dist/web.js.map +1 -0
- package/package.json +47 -2
- package/src/auth/execute-tx.ts +87 -0
- package/src/auth/index.ts +18 -0
- package/src/auth/types.ts +56 -0
- package/src/auth/use-passkey-auth.ts +428 -0
- package/src/index.ts +37 -39
- package/src/mobile/errors.ts +31 -0
- package/src/mobile/index.ts +33 -0
- package/src/mobile/passkey.ts +154 -0
- package/src/mobile/storage.ts +115 -0
- package/src/mobile/types.ts +24 -0
- package/src/popup-entry.ts +33 -0
- package/src/popup-service.ts +0 -103
- package/src/server/challenge.ts +26 -0
- package/src/server/create-wallet.ts +149 -0
- package/src/server/handlers.ts +93 -0
- package/src/server/index.ts +13 -0
- package/src/server/submit.ts +47 -0
- package/src/server/types.ts +70 -0
- package/src/server/utils.ts +69 -0
- package/src/types.ts +1 -0
- package/src/web.ts +51 -0
- package/tsconfig.json +6 -1
- package/tsup.config.ts +9 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @thru/passkey
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
11
|
+
## Entry Points
|
|
12
12
|
|
|
13
|
-
|
|
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
|
-
|
|
19
|
+
## Deprecated Root Import
|
|
16
20
|
|
|
17
|
-
|
|
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);
|
|
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,
|
|
57
|
-
allPasskeys,
|
|
58
|
-
|
|
72
|
+
preferredPasskey,
|
|
73
|
+
allPasskeys,
|
|
74
|
+
context
|
|
59
75
|
);
|
|
60
|
-
// result includes .passkey metadata for the credential that signed
|
|
61
76
|
```
|
|
62
77
|
|
|
63
|
-
###
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
138
|
-
|
|
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
|
-
##
|
|
118
|
+
## Browser Convenience Exports
|
|
145
119
|
|
|
146
|
-
|
|
120
|
+
`@thru/passkey/web` re-exports the browser-side encoding and crypto helpers used by the wallet today, including:
|
|
147
121
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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`
|