@oasisprotocol/privana-sdk 0.5.2 → 0.5.4

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 CHANGED
@@ -54,17 +54,7 @@ function App() {
54
54
  `accountingContract` must be the deployed Privana accounting contract address for the same
55
55
  environment as `apiUrl`.
56
56
 
57
- ### 2. Use the PrivanaButton
58
-
59
- ```tsx
60
- import { PrivanaButton } from '@oasisprotocol/privana-sdk'
61
-
62
- function MyComponent() {
63
- return <PrivanaButton />
64
- }
65
- ```
66
-
67
- ### 3. Or build custom UI with hooks
57
+ ### 2. Or build custom UI with hooks
68
58
 
69
59
  ```tsx
70
60
  import {
@@ -117,6 +107,40 @@ The hooks cache the returned `X-SIWE-Token`, dedupe concurrent auth so a group o
117
107
  private-read hooks only triggers one sign prompt, and retry once on `401` by re-authenticating
118
108
  through the same shared in-flight auth request.
119
109
 
110
+ ### Direct in-app SIWE auth (`siweAuth`)
111
+
112
+ For same-origin apps that want an explicit authenticated session (and JWT-authenticated writes),
113
+ enable `siweAuth` on `PrivanaProvider`. The connected wallet signs an EIP-4361 message in-app and
114
+ `useSiweAuth()` exposes `login`, `logout`, `session`, and the raw `tokens`:
115
+
116
+ ```tsx
117
+ import { PrivanaProvider, useSiweAuth } from '@oasisprotocol/privana-sdk'
118
+ ;<PrivanaProvider siweAuth={{ autoLogin: true }}>
119
+ <AuthGate />
120
+ </PrivanaProvider>
121
+ ```
122
+
123
+ `siweAuth` accepts `true`, or an object with `autoLogin` (default `true`) and `persistJwt`
124
+ (default `false`). It is mutually exclusive with `hostedAuth`.
125
+
126
+ #### Persistent JWT sessions (`persistJwt`)
127
+
128
+ Set `persistJwt: true` to mirror the session in `localStorage` (key scoped by API URL and chain ID)
129
+ so a page reload restores an active session without another signature prompt:
130
+
131
+ ```tsx
132
+ ;<PrivanaProvider siweAuth={{ autoLogin: true, persistJwt: true }}>
133
+ <App />
134
+ </PrivanaProvider>
135
+ ```
136
+
137
+ Logout captures the refresh token, clears local and cross-tab state immediately, suppresses
138
+ automatic re-login, and attempts server-side revocation.
139
+
140
+ > **Security note:** storing long-lived refresh credentials in `localStorage` makes them reachable
141
+ > from any JavaScript running on the page. An XSS vulnerability could exfiltrate them and forge a
142
+ > session, so only enable `persistJwt` on origins you fully control.
143
+
120
144
  ### Hosted redirect auth for cross-domain apps
121
145
 
122
146
  For widget or cross-domain frontends, configure `hostedAuth` on `PrivanaProvider` and use
@@ -191,33 +215,6 @@ Notes:
191
215
  - staging end-to-end verification requires that registration on the staging deployment.
192
216
  - the standalone localhost popup page used during Firefox debugging was diagnostic only; it is not part of the supported SDK integration path.
193
217
 
194
- ## Components
195
-
196
- ### PrivanaButton
197
-
198
- A customizable button that opens the wallet modal.
199
-
200
- ```tsx
201
- // Basic usage
202
- <PrivanaButton />
203
-
204
- // Custom text
205
- <PrivanaButton>Open Wallet</PrivanaButton>
206
-
207
- // Custom styling
208
- <PrivanaButton variant="default" size="lg" className="my-class" />
209
-
210
- // Full control with render prop
211
- <PrivanaButton
212
- renderButton={({ onClick, isOpen }) => (
213
- <MyButton onClick={onClick}>Custom Button</MyButton>
214
- )}
215
- />
216
-
217
- // Show when wallet disconnected (disabled state)
218
- <PrivanaButton hideWhenDisconnected={false} />
219
- ```
220
-
221
218
  ## Hooks
222
219
 
223
220
  | Hook | Description |