@synonymdev/pubky 0.9.3 → 0.10.0-alpha.0
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 +51 -40
- package/index.cjs +1247 -222
- package/index.js +1248 -223
- package/package.json +1 -1
- package/pubky.d.ts +493 -26
- package/pubky_bg.wasm +0 -0
package/pubky.d.ts
CHANGED
|
@@ -21,6 +21,21 @@ type ReadableStreamType = "bytes";
|
|
|
21
21
|
*/
|
|
22
22
|
export type PubkyErrorName = "RequestError" | "InvalidInput" | "AuthenticationError" | "PkarrError" | "ClientStateError" | "InternalError";
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Options for starting a grant-backed pubkyauth flow.
|
|
26
|
+
*/
|
|
27
|
+
export interface GrantAuthFlowOptions {
|
|
28
|
+
/**
|
|
29
|
+
* App identifier shown in the user\'s grant/session list, typically a domain.
|
|
30
|
+
*/
|
|
31
|
+
clientId: string;
|
|
32
|
+
/**
|
|
33
|
+
* Optional HTTP relay base, e.g. `\"https://demo.httprelay.io/inbox/\"`.
|
|
34
|
+
* Defaults to the default Synonym-hosted relay when omitted.
|
|
35
|
+
*/
|
|
36
|
+
relay?: string | null;
|
|
37
|
+
}
|
|
38
|
+
|
|
24
39
|
/**
|
|
25
40
|
* Pkarr Config
|
|
26
41
|
*/
|
|
@@ -160,16 +175,18 @@ export type CapabilityEntry = `${CapabilityScope}:${CapabilityAction}`;
|
|
|
160
175
|
type CapabilitiesTail = `,${CapabilityEntry}${string}`;
|
|
161
176
|
export type Capabilities = "" | CapabilityEntry | `${CapabilityEntry}${CapabilitiesTail}`;
|
|
162
177
|
|
|
163
|
-
export type Path = `/pub/${string}`;
|
|
178
|
+
export type Path = `/pub/${string}` | `/priv/${string}`;
|
|
164
179
|
|
|
165
180
|
|
|
166
181
|
/**
|
|
167
182
|
* Start and control a pubkyauth authorization flow.
|
|
168
183
|
*
|
|
169
184
|
* Typical flow:
|
|
170
|
-
* 1) `AuthFlow.start(...)` or `pubky.
|
|
185
|
+
* 1) `AuthFlow.start(...)` or `pubky.startCookieAuthFlow(...)`
|
|
171
186
|
* 2) Show `authorizationUrl()` as QR/deeplink to the user’s signing device
|
|
172
187
|
* 3) `awaitApproval()` to receive a ready `Session`
|
|
188
|
+
*
|
|
189
|
+
* @deprecated Use `GrantAuthFlow` instead.
|
|
173
190
|
*/
|
|
174
191
|
export class AuthFlow {
|
|
175
192
|
private constructor();
|
|
@@ -198,10 +215,10 @@ export class AuthFlow {
|
|
|
198
215
|
awaitToken(): Promise<AuthToken>;
|
|
199
216
|
/**
|
|
200
217
|
* Resume a previously started auth flow from its saved `authorizationUrl` (standalone).
|
|
201
|
-
* Prefer `pubky.
|
|
218
|
+
* Prefer `pubky.resumeCookieAuthFlow()` to reuse a facade client; this creates a default (mainnet) client.
|
|
202
219
|
*
|
|
203
220
|
* Relay messages expire after ~5 minutes; resume is only viable in that window.
|
|
204
|
-
* See `Pubky.
|
|
221
|
+
* See `Pubky.resumeCookieAuthFlow()` / `Pubky.startCookieAuthFlow()` for full guidance.
|
|
205
222
|
*
|
|
206
223
|
* **Security:** `authorizationUrl` contains the `client_secret`.
|
|
207
224
|
* Delete it from storage as soon as resume completes or is abandoned.
|
|
@@ -214,7 +231,7 @@ export class AuthFlow {
|
|
|
214
231
|
static resume(authorization_url: string): AuthFlow;
|
|
215
232
|
/**
|
|
216
233
|
* Start a flow (standalone).
|
|
217
|
-
* Prefer `pubky.
|
|
234
|
+
* Prefer `pubky.startCookieAuthFlow()` to reuse a facade client.
|
|
218
235
|
*
|
|
219
236
|
* @param {string} capabilities
|
|
220
237
|
* Comma-separated capabilities, e.g. `"/pub/app/:rw,/priv/foo.txt:r"`.
|
|
@@ -244,6 +261,8 @@ export class AuthFlow {
|
|
|
244
261
|
* const flow = AuthFlow.start("/pub/my-cool-app/:rw,/pub/pubky.app/:w");
|
|
245
262
|
* renderQRCode(flow.authorizationUrl());
|
|
246
263
|
* const session = await flow.awaitApproval();
|
|
264
|
+
*
|
|
265
|
+
* @deprecated Use `GrantAuthFlow.start(...)` instead.
|
|
247
266
|
*/
|
|
248
267
|
static start(capabilities: Capabilities, kind: AuthFlowKind, relay?: string | null): AuthFlow;
|
|
249
268
|
/**
|
|
@@ -257,7 +276,7 @@ export class AuthFlow {
|
|
|
257
276
|
*
|
|
258
277
|
* **Security:** This URL contains the `client_secret` in plaintext.
|
|
259
278
|
* Treat it as a short-lived secret and delete it after the flow completes.
|
|
260
|
-
* See `Pubky.
|
|
279
|
+
* See `Pubky.startCookieAuthFlow()` docs for storage guidance.
|
|
261
280
|
*
|
|
262
281
|
* @returns {string} A `pubkyauth://…` or `https://…` URL with channel info.
|
|
263
282
|
*
|
|
@@ -305,7 +324,7 @@ export class AuthFlowKind {
|
|
|
305
324
|
* ### Typical usage
|
|
306
325
|
* ```js
|
|
307
326
|
* // Start an auth-only flow (no capabilities)
|
|
308
|
-
* const flow = pubky.
|
|
327
|
+
* const flow = pubky.startCookieAuthFlow("", relay);
|
|
309
328
|
*
|
|
310
329
|
* // Wait for the signer to approve; returns an AuthToken
|
|
311
330
|
* const token = await flow.awaitToken();
|
|
@@ -367,7 +386,7 @@ export class AuthToken {
|
|
|
367
386
|
/**
|
|
368
387
|
* Returns the **capabilities** requested by the flow at the time this token was signed.
|
|
369
388
|
*
|
|
370
|
-
* Most auth-only flows pass an empty string to `
|
|
389
|
+
* Most auth-only flows pass an empty string to `startCookieAuthFlow("", relay)`, so this will
|
|
371
390
|
* commonly be an empty array.
|
|
372
391
|
*
|
|
373
392
|
* Returns: `string[]`, where each item is the canonical entry `"<scope>:<actions>"`.
|
|
@@ -450,6 +469,36 @@ export class Client {
|
|
|
450
469
|
static testnet(host?: string | null): Client;
|
|
451
470
|
}
|
|
452
471
|
|
|
472
|
+
/**
|
|
473
|
+
* Cookie-only view over a cookie-backed `Session`.
|
|
474
|
+
*
|
|
475
|
+
* Grant-backed sessions do not expose this view; use `session.cookie` and
|
|
476
|
+
* check for `undefined` before calling cookie-specific methods.
|
|
477
|
+
*/
|
|
478
|
+
export class CookieSession {
|
|
479
|
+
private constructor();
|
|
480
|
+
free(): void;
|
|
481
|
+
[Symbol.dispose](): void;
|
|
482
|
+
/**
|
|
483
|
+
* Export session metadata for legacy cookie restore.
|
|
484
|
+
*
|
|
485
|
+
* The returned string contains no secrets; the browser cookie jar must
|
|
486
|
+
* still hold the HTTP-only cookie.
|
|
487
|
+
*
|
|
488
|
+
* @returns {string}
|
|
489
|
+
*/
|
|
490
|
+
export(): string;
|
|
491
|
+
/**
|
|
492
|
+
* Export the cookie secret needed to restore this cookie session.
|
|
493
|
+
*
|
|
494
|
+
* This is available when the SDK captured the cookie secret, such as in
|
|
495
|
+
* Node.js. Browser sessions cannot read HTTP-only Set-Cookie values.
|
|
496
|
+
*
|
|
497
|
+
* @returns {Promise<string>}
|
|
498
|
+
*/
|
|
499
|
+
exportSecret(): Promise<string>;
|
|
500
|
+
}
|
|
501
|
+
|
|
453
502
|
/**
|
|
454
503
|
* A single event from the event stream.
|
|
455
504
|
*
|
|
@@ -627,6 +676,208 @@ export class EventStreamBuilder {
|
|
|
627
676
|
subscribe(): Promise<ReadableStream>;
|
|
628
677
|
}
|
|
629
678
|
|
|
679
|
+
/**
|
|
680
|
+
* Start and control a grant-backed pubkyauth authorization flow.
|
|
681
|
+
*
|
|
682
|
+
* Typical flow:
|
|
683
|
+
* 1) `GrantAuthFlow.start(...)` or `pubky.startGrantAuthFlow(...)`
|
|
684
|
+
* 2) Show `authorizationUrl()` as QR/deeplink to the user's signing device
|
|
685
|
+
* 3) `awaitApproval()` to receive a grant-backed, self-refreshing `Session`
|
|
686
|
+
*/
|
|
687
|
+
export class GrantAuthFlow {
|
|
688
|
+
private constructor();
|
|
689
|
+
free(): void;
|
|
690
|
+
[Symbol.dispose](): void;
|
|
691
|
+
/**
|
|
692
|
+
* Block until the user approves on their signer device; returns a grant-backed `Session`.
|
|
693
|
+
*/
|
|
694
|
+
awaitApproval(): Promise<Session>;
|
|
695
|
+
/**
|
|
696
|
+
* Resume a previously saved pending grant auth flow (standalone).
|
|
697
|
+
* Prefer `pubky.resumeGrantAuthFlow()` to reuse a facade client.
|
|
698
|
+
*
|
|
699
|
+
* **Security:** `savedState` contains the relay secret and PoP client private key.
|
|
700
|
+
* Store it only temporarily and delete it once the flow completes or is abandoned.
|
|
701
|
+
*
|
|
702
|
+
* @param {string} savedState A string produced by `grantFlow.save()`.
|
|
703
|
+
* @returns {GrantAuthFlow} A flow reconnected to the original relay channel.
|
|
704
|
+
*/
|
|
705
|
+
static resume(saved_state: string): GrantAuthFlow;
|
|
706
|
+
/**
|
|
707
|
+
* Save sensitive state required to resume this pending grant flow.
|
|
708
|
+
*
|
|
709
|
+
* @returns {string} Opaque state for `GrantAuthFlow.resume()` or
|
|
710
|
+
* `pubky.resumeGrantAuthFlow()`.
|
|
711
|
+
*/
|
|
712
|
+
save(): string;
|
|
713
|
+
/**
|
|
714
|
+
* Start a grant-backed flow (standalone).
|
|
715
|
+
* Prefer `pubky.startGrantAuthFlow()` to reuse a facade client.
|
|
716
|
+
*
|
|
717
|
+
* @param {string} capabilities
|
|
718
|
+
* Comma-separated capabilities, e.g. `"/pub/app/:rw,/priv/foo.txt:r"`.
|
|
719
|
+
* Empty string is allowed (no scopes).
|
|
720
|
+
*
|
|
721
|
+
* @param {AuthFlowKind} kind
|
|
722
|
+
* The kind of authentication flow to perform.
|
|
723
|
+
*
|
|
724
|
+
* @param {GrantAuthFlowOptions} options
|
|
725
|
+
* Options for the grant flow: `{ clientId, relay? }`.
|
|
726
|
+
*
|
|
727
|
+
* @returns {GrantAuthFlow}
|
|
728
|
+
* A running grant auth flow. Call `authorizationUrl()` to show the deep link,
|
|
729
|
+
* then `awaitApproval()` to receive a grant-backed `Session`.
|
|
730
|
+
*/
|
|
731
|
+
static start(capabilities: Capabilities, kind: AuthFlowKind, options: GrantAuthFlowOptions): GrantAuthFlow;
|
|
732
|
+
/**
|
|
733
|
+
* Non-blocking single poll step (advanced UIs).
|
|
734
|
+
*
|
|
735
|
+
* @returns {Promise<Session|undefined>} A session if the approval arrived, otherwise `undefined`.
|
|
736
|
+
*/
|
|
737
|
+
tryPollOnce(): Promise<Session | undefined>;
|
|
738
|
+
/**
|
|
739
|
+
* Return the authorization deep link (URL) to show as QR or open on the signer device.
|
|
740
|
+
*/
|
|
741
|
+
readonly authorizationUrl: string;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
/**
|
|
745
|
+
* Summary of an active grant returned by `GrantManager.list()`.
|
|
746
|
+
*/
|
|
747
|
+
export class GrantInfo {
|
|
748
|
+
private constructor();
|
|
749
|
+
free(): void;
|
|
750
|
+
[Symbol.dispose](): void;
|
|
751
|
+
/**
|
|
752
|
+
* Comma-separated capabilities authorized by the grant.
|
|
753
|
+
*/
|
|
754
|
+
readonly capabilities: string;
|
|
755
|
+
/**
|
|
756
|
+
* Application identifier.
|
|
757
|
+
*/
|
|
758
|
+
readonly clientId: string;
|
|
759
|
+
/**
|
|
760
|
+
* Expiry timestamp, in Unix seconds.
|
|
761
|
+
*/
|
|
762
|
+
readonly expiresAt: number;
|
|
763
|
+
/**
|
|
764
|
+
* Grant identifier used for revocation.
|
|
765
|
+
*/
|
|
766
|
+
readonly grantId: string;
|
|
767
|
+
/**
|
|
768
|
+
* Issued-at timestamp, in Unix seconds.
|
|
769
|
+
*/
|
|
770
|
+
readonly issuedAt: number;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* Account-level grant management for a signed-in user.
|
|
775
|
+
*/
|
|
776
|
+
export class GrantManager {
|
|
777
|
+
free(): void;
|
|
778
|
+
[Symbol.dispose](): void;
|
|
779
|
+
/**
|
|
780
|
+
* List all active grants for this user.
|
|
781
|
+
*
|
|
782
|
+
* Requires a root-capability session. Non-root sessions surface the
|
|
783
|
+
* homeserver `403` as the standard request error.
|
|
784
|
+
*
|
|
785
|
+
* @returns {Promise<GrantInfo[]>}
|
|
786
|
+
*/
|
|
787
|
+
list(): Promise<GrantInfo[]>;
|
|
788
|
+
/**
|
|
789
|
+
* Create a grant manager authenticated by a session.
|
|
790
|
+
*
|
|
791
|
+
* @param {Session} session
|
|
792
|
+
* @returns {GrantManager}
|
|
793
|
+
*/
|
|
794
|
+
constructor(session: Session);
|
|
795
|
+
/**
|
|
796
|
+
* Revoke a specific grant by id.
|
|
797
|
+
*
|
|
798
|
+
* Requires a root-capability session. Malformed ids throw
|
|
799
|
+
* `InvalidInput`.
|
|
800
|
+
*
|
|
801
|
+
* @param {string} grantId
|
|
802
|
+
* @returns {Promise<void>}
|
|
803
|
+
*/
|
|
804
|
+
revoke(grant_id: string): Promise<void>;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
/**
|
|
808
|
+
* Grant-only view over a grant-backed `Session`.
|
|
809
|
+
*
|
|
810
|
+
* Cookie-backed sessions do not expose this view; use `session.grant` and
|
|
811
|
+
* check for `undefined` before calling grant-session methods.
|
|
812
|
+
*/
|
|
813
|
+
export class GrantSession {
|
|
814
|
+
private constructor();
|
|
815
|
+
free(): void;
|
|
816
|
+
[Symbol.dispose](): void;
|
|
817
|
+
/**
|
|
818
|
+
* Export the durable refresh material needed to restore this grant session.
|
|
819
|
+
*
|
|
820
|
+
* Treat the returned string as bearer-equivalent secret material until the
|
|
821
|
+
* grant expires or is revoked.
|
|
822
|
+
*
|
|
823
|
+
* @returns {Promise<string>}
|
|
824
|
+
*/
|
|
825
|
+
exportSecret(): Promise<string>;
|
|
826
|
+
/**
|
|
827
|
+
* Current grant id (`jti`) backing this session.
|
|
828
|
+
*
|
|
829
|
+
* @returns {Promise<string>}
|
|
830
|
+
*/
|
|
831
|
+
grantId(): Promise<string>;
|
|
832
|
+
/**
|
|
833
|
+
* Full grant session metadata.
|
|
834
|
+
*
|
|
835
|
+
* @returns {Promise<GrantSessionInfo>}
|
|
836
|
+
*/
|
|
837
|
+
sessionInfo(): Promise<GrantSessionInfo>;
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
/**
|
|
841
|
+
* Grant-specific session metadata returned by `grant.sessionInfo()`.
|
|
842
|
+
*/
|
|
843
|
+
export class GrantSessionInfo {
|
|
844
|
+
private constructor();
|
|
845
|
+
free(): void;
|
|
846
|
+
[Symbol.dispose](): void;
|
|
847
|
+
/**
|
|
848
|
+
* Authorized capabilities for this session.
|
|
849
|
+
*/
|
|
850
|
+
readonly capabilities: string[];
|
|
851
|
+
/**
|
|
852
|
+
* Application identifier.
|
|
853
|
+
*/
|
|
854
|
+
readonly clientId: string;
|
|
855
|
+
/**
|
|
856
|
+
* Session creation timestamp, in Unix seconds.
|
|
857
|
+
*/
|
|
858
|
+
readonly createdAt: number;
|
|
859
|
+
/**
|
|
860
|
+
* Underlying grant expiry timestamp, in Unix seconds.
|
|
861
|
+
*/
|
|
862
|
+
readonly grantExpiresAt: number;
|
|
863
|
+
/**
|
|
864
|
+
* Grant id this session was minted from.
|
|
865
|
+
*/
|
|
866
|
+
readonly grantId: string;
|
|
867
|
+
/**
|
|
868
|
+
* Homeserver that issued this session.
|
|
869
|
+
*/
|
|
870
|
+
readonly homeserver: PublicKey;
|
|
871
|
+
/**
|
|
872
|
+
* User public key for this session.
|
|
873
|
+
*/
|
|
874
|
+
readonly publicKey: PublicKey;
|
|
875
|
+
/**
|
|
876
|
+
* Bearer token expiry timestamp, in Unix seconds.
|
|
877
|
+
*/
|
|
878
|
+
readonly tokenExpiresAt: number;
|
|
879
|
+
}
|
|
880
|
+
|
|
630
881
|
export class IntoUnderlyingByteSource {
|
|
631
882
|
private constructor();
|
|
632
883
|
free(): void;
|
|
@@ -816,12 +1067,13 @@ export class Pubky {
|
|
|
816
1067
|
*/
|
|
817
1068
|
constructor();
|
|
818
1069
|
/**
|
|
819
|
-
* Restore a session from a previously exported snapshot, using this instance's client.
|
|
1070
|
+
* Restore a session from a previously exported token or snapshot, using this instance's client.
|
|
820
1071
|
*
|
|
821
|
-
*
|
|
822
|
-
*
|
|
1072
|
+
* Accepts grant secret tokens from `session.exportSecret()` and legacy cookie
|
|
1073
|
+
* secret tokens. Also accepts legacy cookie metadata snapshots from `session.export()`.
|
|
1074
|
+
* Grant restore mints a fresh short-lived bearer.
|
|
823
1075
|
*
|
|
824
|
-
* @param {string} exported A string produced by `session.export()`.
|
|
1076
|
+
* @param {string} exported A string produced by `session.exportSecret()` or legacy `session.export()`.
|
|
825
1077
|
* @returns {Promise<Session>}
|
|
826
1078
|
* A rehydrated session bound to this SDK's HTTP client.
|
|
827
1079
|
*
|
|
@@ -837,7 +1089,7 @@ export class Pubky {
|
|
|
837
1089
|
*
|
|
838
1090
|
* **Security:** The URL contains the `client_secret` in plaintext.
|
|
839
1091
|
* Delete it from storage as soon as the resumed flow completes.
|
|
840
|
-
* See `
|
|
1092
|
+
* See `startCookieAuthFlow()` docs for full storage guidance.
|
|
841
1093
|
*
|
|
842
1094
|
* @param {string} authorizationUrl The `pubkyauth://…` URL from a previous flow.
|
|
843
1095
|
* @returns {AuthFlow} A flow reconnected to the original relay channel.
|
|
@@ -845,7 +1097,17 @@ export class Pubky {
|
|
|
845
1097
|
* - `{ name: "AuthenticationError" }` if the URL is invalid or not a signin/signup link
|
|
846
1098
|
* - `{ name: "RequestError" }` on network/relay failure
|
|
847
1099
|
*/
|
|
848
|
-
|
|
1100
|
+
resumeCookieAuthFlow(authorization_url: string): AuthFlow;
|
|
1101
|
+
/**
|
|
1102
|
+
* Resume a previously saved pending grant auth flow.
|
|
1103
|
+
*
|
|
1104
|
+
* **Security:** `savedState` contains the relay secret and PoP client private key.
|
|
1105
|
+
* Delete it from storage as soon as the resumed flow completes.
|
|
1106
|
+
*
|
|
1107
|
+
* @param {string} savedState A string produced by `grantFlow.save()`.
|
|
1108
|
+
* @returns {GrantAuthFlow} A flow reconnected to the original relay channel.
|
|
1109
|
+
*/
|
|
1110
|
+
resumeGrantAuthFlow(saved_state: string): GrantAuthFlow;
|
|
849
1111
|
/**
|
|
850
1112
|
* Create a `Signer` from an existing `Keypair`.
|
|
851
1113
|
*
|
|
@@ -854,7 +1116,7 @@ export class Pubky {
|
|
|
854
1116
|
*
|
|
855
1117
|
* @example
|
|
856
1118
|
* const signer = pubky.signer(Keypair.random());
|
|
857
|
-
*
|
|
1119
|
+
* await signer.signup(homeserverPk);
|
|
858
1120
|
*/
|
|
859
1121
|
signer(keypair: Keypair): Signer;
|
|
860
1122
|
/**
|
|
@@ -886,11 +1148,32 @@ export class Pubky {
|
|
|
886
1148
|
* - `{ name: "RequestError" }` if the flow cannot be started (network/relay)
|
|
887
1149
|
*
|
|
888
1150
|
* @example
|
|
889
|
-
* const flow = pubky.
|
|
1151
|
+
* const flow = pubky.startCookieAuthFlow("/pub/my-cool-app/:rw");
|
|
890
1152
|
* renderQr(flow.authorizationUrl);
|
|
891
1153
|
* const session = await flow.awaitApproval();
|
|
892
1154
|
*/
|
|
893
|
-
|
|
1155
|
+
startCookieAuthFlow(capabilities: Capabilities, kind: AuthFlowKind, relay?: string | null): AuthFlow;
|
|
1156
|
+
/**
|
|
1157
|
+
* Start a grant-backed **pubkyauth** flow.
|
|
1158
|
+
*
|
|
1159
|
+
* Grant auth uses a user-signed grant JWS plus Proof-of-Possession and
|
|
1160
|
+
* returns a self-refreshing session.
|
|
1161
|
+
*
|
|
1162
|
+
* @param {string} capabilities Comma-separated caps, e.g. `"/pub/app/:rw,/pub/foo/file:r"`.
|
|
1163
|
+
* @param {AuthFlowKind} kind The kind of authentication flow to perform.
|
|
1164
|
+
* @param {GrantAuthFlowOptions} options Options for the grant flow: `{ clientId, relay? }`.
|
|
1165
|
+
* @returns {GrantAuthFlow}
|
|
1166
|
+
* A running grant auth flow. Show `authorizationUrl` as QR/deeplink,
|
|
1167
|
+
* then `awaitApproval()` to obtain a grant-backed `Session`.
|
|
1168
|
+
*
|
|
1169
|
+
* @example
|
|
1170
|
+
* const flow = pubky.startGrantAuthFlow(
|
|
1171
|
+
* "/pub/my-cool-app/:rw",
|
|
1172
|
+
* AuthFlowKind.signin(),
|
|
1173
|
+
* { clientId: "my-cool-app.example" },
|
|
1174
|
+
* );
|
|
1175
|
+
*/
|
|
1176
|
+
startGrantAuthFlow(capabilities: Capabilities, kind: AuthFlowKind, options: GrantAuthFlowOptions): GrantAuthFlow;
|
|
894
1177
|
/**
|
|
895
1178
|
* Create a Pubky facade preconfigured for a **local testnet**.
|
|
896
1179
|
*
|
|
@@ -1103,8 +1386,24 @@ export class Session {
|
|
|
1103
1386
|
*
|
|
1104
1387
|
* @returns {string}
|
|
1105
1388
|
* A base64 string to store (e.g. in `localStorage`).
|
|
1389
|
+
*
|
|
1390
|
+
* @deprecated Prefer `exportSecret()` for grant sessions.
|
|
1106
1391
|
*/
|
|
1107
1392
|
export(): string;
|
|
1393
|
+
/**
|
|
1394
|
+
* Export the secret material needed to restore this session.
|
|
1395
|
+
*
|
|
1396
|
+
* For grant sessions this exports the grant JWS and PoP client secret; restoring
|
|
1397
|
+
* mints a fresh bearer. For legacy cookie sessions this exports the cookie secret
|
|
1398
|
+
* when the SDK owns it.
|
|
1399
|
+
*
|
|
1400
|
+
* Treat the returned string as a bearer-equivalent secret until the grant or
|
|
1401
|
+
* cookie session expires or is revoked.
|
|
1402
|
+
*
|
|
1403
|
+
* @returns {Promise<string>}
|
|
1404
|
+
* A secret token that can be passed to `pubky.restoreSession()`.
|
|
1405
|
+
*/
|
|
1406
|
+
exportSecret(): Promise<string>;
|
|
1108
1407
|
/**
|
|
1109
1408
|
* Restore a session from an `export()` string.
|
|
1110
1409
|
*
|
|
@@ -1116,6 +1415,8 @@ export class Session {
|
|
|
1116
1415
|
* @param {Client=} client
|
|
1117
1416
|
* Optional client to reuse transport configuration.
|
|
1118
1417
|
* @returns {Promise<Session>}
|
|
1418
|
+
*
|
|
1419
|
+
* @deprecated Prefer `Pubky.restoreSession(...)`.
|
|
1119
1420
|
*/
|
|
1120
1421
|
static restore(exported: string, client?: Client | null): Promise<Session>;
|
|
1121
1422
|
/**
|
|
@@ -1125,6 +1426,22 @@ export class Session {
|
|
|
1125
1426
|
* @returns {Promise<void>}
|
|
1126
1427
|
*/
|
|
1127
1428
|
signout(): Promise<void>;
|
|
1429
|
+
/**
|
|
1430
|
+
* Cookie-only view for cookie-backed sessions.
|
|
1431
|
+
*
|
|
1432
|
+
* Grant-backed sessions return `undefined`.
|
|
1433
|
+
*
|
|
1434
|
+
* @returns {CookieSession|undefined}
|
|
1435
|
+
*/
|
|
1436
|
+
readonly cookie: CookieSession | undefined;
|
|
1437
|
+
/**
|
|
1438
|
+
* Grant-only management view for grant-backed sessions.
|
|
1439
|
+
*
|
|
1440
|
+
* Cookie-backed sessions return `undefined`.
|
|
1441
|
+
*
|
|
1442
|
+
* @returns {GrantSession|undefined}
|
|
1443
|
+
*/
|
|
1444
|
+
readonly grant: GrantSession | undefined;
|
|
1128
1445
|
/**
|
|
1129
1446
|
* Retrieve immutable info about this session (user & capabilities).
|
|
1130
1447
|
*
|
|
@@ -1167,7 +1484,7 @@ export class SessionInfo {
|
|
|
1167
1484
|
}
|
|
1168
1485
|
|
|
1169
1486
|
/**
|
|
1170
|
-
* Read/write storage scoped to **your** session (absolute paths: `/pub/...`).
|
|
1487
|
+
* Read/write storage scoped to **your** session (absolute paths: `/pub/...` or `/priv/...`).
|
|
1171
1488
|
*/
|
|
1172
1489
|
export class SessionStorage {
|
|
1173
1490
|
private constructor();
|
|
@@ -1285,35 +1602,57 @@ export class Signer {
|
|
|
1285
1602
|
/**
|
|
1286
1603
|
* Fast sign-in for a returning user. Publishes PKDNS in the background.
|
|
1287
1604
|
*
|
|
1288
|
-
* Creates a valid homeserver Session with root capabilities
|
|
1605
|
+
* Creates a valid grant-backed homeserver Session with root capabilities.
|
|
1606
|
+
* `clientId` is shown in the user's grant/session list.
|
|
1607
|
+
* @param {string} clientId App identifier, typically a domain.
|
|
1289
1608
|
*
|
|
1290
1609
|
* @returns {Promise<Session>}
|
|
1291
1610
|
*
|
|
1292
1611
|
* @throws {PubkyError}
|
|
1293
1612
|
*/
|
|
1294
|
-
signin(): Promise<Session>;
|
|
1613
|
+
signin(client_id: string): Promise<Session>;
|
|
1295
1614
|
/**
|
|
1296
1615
|
* Blocking sign-in. Waits for PKDNS publish to complete (slower; safer).
|
|
1297
1616
|
*
|
|
1298
|
-
* Creates a valid homeserver Session with root capabilities
|
|
1617
|
+
* Creates a valid grant-backed homeserver Session with root capabilities.
|
|
1618
|
+
* `clientId` is shown in the user's grant/session list.
|
|
1619
|
+
* @param {string} clientId App identifier, typically a domain.
|
|
1299
1620
|
*
|
|
1300
1621
|
* @returns {Promise<Session>}
|
|
1301
1622
|
*/
|
|
1302
|
-
signinBlocking(): Promise<Session>;
|
|
1623
|
+
signinBlocking(client_id: string): Promise<Session>;
|
|
1624
|
+
/**
|
|
1625
|
+
* Legacy cookie signin. Prefer `signin(clientId)`.
|
|
1626
|
+
*
|
|
1627
|
+
* @deprecated Prefer `signin(clientId)`.
|
|
1628
|
+
*/
|
|
1629
|
+
signinCookie(): Promise<Session>;
|
|
1630
|
+
/**
|
|
1631
|
+
* Legacy cookie blocking signin. Prefer `signinBlocking(clientId)`.
|
|
1632
|
+
*
|
|
1633
|
+
* @deprecated Prefer `signinBlocking(clientId)`.
|
|
1634
|
+
*/
|
|
1635
|
+
signinCookieBlocking(): Promise<Session>;
|
|
1303
1636
|
/**
|
|
1304
|
-
* Sign up at a homeserver.
|
|
1637
|
+
* Sign up at a homeserver.
|
|
1305
1638
|
*
|
|
1306
|
-
* Creates
|
|
1639
|
+
* Creates the account and publishes PKDNS. Call `signin(clientId)` to create a session.
|
|
1307
1640
|
*
|
|
1308
1641
|
* @param {PublicKey} homeserver The homeserver’s public key.
|
|
1309
1642
|
* @param {string|null} signupToken Invite/registration token or `null`.
|
|
1310
|
-
* @returns {Promise<
|
|
1643
|
+
* @returns {Promise<void>}
|
|
1311
1644
|
*
|
|
1312
1645
|
* @throws {PubkyError}
|
|
1313
1646
|
* - `AuthenticationError` (bad/expired token)
|
|
1314
1647
|
* - `RequestError` (network/server)
|
|
1315
1648
|
*/
|
|
1316
|
-
signup(homeserver: PublicKey, signup_token?: string | null): Promise<
|
|
1649
|
+
signup(homeserver: PublicKey, signup_token?: string | null): Promise<void>;
|
|
1650
|
+
/**
|
|
1651
|
+
* Legacy cookie signup. Prefer `signup()` plus `signin(clientId)`.
|
|
1652
|
+
*
|
|
1653
|
+
* @deprecated Prefer `signup()` followed by `signin(clientId)`.
|
|
1654
|
+
*/
|
|
1655
|
+
signupCookie(homeserver: PublicKey, signup_token?: string | null): Promise<Session>;
|
|
1317
1656
|
/**
|
|
1318
1657
|
* Get a PKDNS actor bound to this signer's client & keypair (publishing enabled).
|
|
1319
1658
|
*
|
|
@@ -1342,6 +1681,64 @@ export class SigninDeepLink {
|
|
|
1342
1681
|
readonly secret: Uint8Array;
|
|
1343
1682
|
}
|
|
1344
1683
|
|
|
1684
|
+
/**
|
|
1685
|
+
* Parsed grant-based signin deeplink.
|
|
1686
|
+
*
|
|
1687
|
+
* This is useful for tools, tests, and signer UIs that need to inspect a
|
|
1688
|
+
* `pubky://signin-grant` authorization URL before approving it.
|
|
1689
|
+
*/
|
|
1690
|
+
export class SigninGrantDeepLink {
|
|
1691
|
+
private constructor();
|
|
1692
|
+
free(): void;
|
|
1693
|
+
[Symbol.dispose](): void;
|
|
1694
|
+
/**
|
|
1695
|
+
* Parse a grant signin deeplink URL.
|
|
1696
|
+
*
|
|
1697
|
+
* @param {string} url
|
|
1698
|
+
* @returns {SigninGrantDeepLink}
|
|
1699
|
+
* @throws {PubkyError} `InvalidInput` when the URL is malformed or not a grant signin link.
|
|
1700
|
+
*/
|
|
1701
|
+
static parse(url: string): SigninGrantDeepLink;
|
|
1702
|
+
/**
|
|
1703
|
+
* Serialize this parsed deeplink back to its URL form.
|
|
1704
|
+
*
|
|
1705
|
+
* @returns {string}
|
|
1706
|
+
*/
|
|
1707
|
+
toString(): string;
|
|
1708
|
+
/**
|
|
1709
|
+
* Base HTTP relay inbox URL used by this auth request.
|
|
1710
|
+
*
|
|
1711
|
+
* @returns {string}
|
|
1712
|
+
*/
|
|
1713
|
+
readonly baseRelayUrl: string;
|
|
1714
|
+
/**
|
|
1715
|
+
* Capabilities requested by the application.
|
|
1716
|
+
*
|
|
1717
|
+
* @returns {string}
|
|
1718
|
+
*/
|
|
1719
|
+
readonly capabilities: string;
|
|
1720
|
+
/**
|
|
1721
|
+
* Application identifier shown in the user's grant/session list.
|
|
1722
|
+
*
|
|
1723
|
+
* @returns {string}
|
|
1724
|
+
*/
|
|
1725
|
+
readonly clientId: string;
|
|
1726
|
+
/**
|
|
1727
|
+
* Public key for the Proof-of-Possession client created by the application.
|
|
1728
|
+
*
|
|
1729
|
+
* @returns {PublicKey}
|
|
1730
|
+
*/
|
|
1731
|
+
readonly clientPublicKey: PublicKey;
|
|
1732
|
+
/**
|
|
1733
|
+
* Relay channel secret embedded in the deeplink.
|
|
1734
|
+
*
|
|
1735
|
+
* Treat this as sensitive temporary auth-flow material.
|
|
1736
|
+
*
|
|
1737
|
+
* @returns {Uint8Array}
|
|
1738
|
+
*/
|
|
1739
|
+
readonly secret: Uint8Array;
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1345
1742
|
export class SignupDeepLink {
|
|
1346
1743
|
private constructor();
|
|
1347
1744
|
free(): void;
|
|
@@ -1355,6 +1752,76 @@ export class SignupDeepLink {
|
|
|
1355
1752
|
readonly signupToken: string | undefined;
|
|
1356
1753
|
}
|
|
1357
1754
|
|
|
1755
|
+
/**
|
|
1756
|
+
* Parsed grant-based signup deeplink.
|
|
1757
|
+
*
|
|
1758
|
+
* This is useful for tools, tests, and signer UIs that need to inspect a
|
|
1759
|
+
* `pubky://signup-grant` authorization URL before approving it.
|
|
1760
|
+
*/
|
|
1761
|
+
export class SignupGrantDeepLink {
|
|
1762
|
+
private constructor();
|
|
1763
|
+
free(): void;
|
|
1764
|
+
[Symbol.dispose](): void;
|
|
1765
|
+
/**
|
|
1766
|
+
* Parse a grant signup deeplink URL.
|
|
1767
|
+
*
|
|
1768
|
+
* @param {string} url
|
|
1769
|
+
* @returns {SignupGrantDeepLink}
|
|
1770
|
+
* @throws {PubkyError} `InvalidInput` when the URL is malformed or not a grant signup link.
|
|
1771
|
+
*/
|
|
1772
|
+
static parse(url: string): SignupGrantDeepLink;
|
|
1773
|
+
/**
|
|
1774
|
+
* Serialize this parsed deeplink back to its URL form.
|
|
1775
|
+
*
|
|
1776
|
+
* @returns {string}
|
|
1777
|
+
*/
|
|
1778
|
+
toString(): string;
|
|
1779
|
+
/**
|
|
1780
|
+
* Base HTTP relay inbox URL used by this auth request.
|
|
1781
|
+
*
|
|
1782
|
+
* @returns {string}
|
|
1783
|
+
*/
|
|
1784
|
+
readonly baseRelayUrl: string;
|
|
1785
|
+
/**
|
|
1786
|
+
* Capabilities requested by the application.
|
|
1787
|
+
*
|
|
1788
|
+
* @returns {string}
|
|
1789
|
+
*/
|
|
1790
|
+
readonly capabilities: string;
|
|
1791
|
+
/**
|
|
1792
|
+
* Application identifier shown in the user's grant/session list.
|
|
1793
|
+
*
|
|
1794
|
+
* @returns {string}
|
|
1795
|
+
*/
|
|
1796
|
+
readonly clientId: string;
|
|
1797
|
+
/**
|
|
1798
|
+
* Public key for the Proof-of-Possession client created by the application.
|
|
1799
|
+
*
|
|
1800
|
+
* @returns {PublicKey}
|
|
1801
|
+
*/
|
|
1802
|
+
readonly clientPublicKey: PublicKey;
|
|
1803
|
+
/**
|
|
1804
|
+
* Homeserver public key requested for account creation.
|
|
1805
|
+
*
|
|
1806
|
+
* @returns {PublicKey}
|
|
1807
|
+
*/
|
|
1808
|
+
readonly homeserver: PublicKey;
|
|
1809
|
+
/**
|
|
1810
|
+
* Relay channel secret embedded in the deeplink.
|
|
1811
|
+
*
|
|
1812
|
+
* Treat this as sensitive temporary auth-flow material.
|
|
1813
|
+
*
|
|
1814
|
+
* @returns {Uint8Array}
|
|
1815
|
+
*/
|
|
1816
|
+
readonly secret: Uint8Array;
|
|
1817
|
+
/**
|
|
1818
|
+
* Optional signup token included in the request.
|
|
1819
|
+
*
|
|
1820
|
+
* @returns {string|undefined}
|
|
1821
|
+
*/
|
|
1822
|
+
readonly signupToken: string | undefined;
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1358
1825
|
/**
|
|
1359
1826
|
* Resolve a `pubky://` or `pubky<pk>/…` identifier into the homeserver transport URL.
|
|
1360
1827
|
*
|
package/pubky_bg.wasm
CHANGED
|
Binary file
|