@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.
Files changed (6) hide show
  1. package/README.md +51 -40
  2. package/index.cjs +1247 -222
  3. package/index.js +1248 -223
  4. package/package.json +1 -1
  5. package/pubky.d.ts +493 -26
  6. package/pubky_bg.wasm +0 -0
package/index.cjs CHANGED
@@ -9,9 +9,11 @@ globalThis.fetch = makeFetchCookie(originalFetch);
9
9
  * Start and control a pubkyauth authorization flow.
10
10
  *
11
11
  * Typical flow:
12
- * 1) `AuthFlow.start(...)` or `pubky.startAuthFlow(...)`
12
+ * 1) `AuthFlow.start(...)` or `pubky.startCookieAuthFlow(...)`
13
13
  * 2) Show `authorizationUrl()` as QR/deeplink to the user’s signing device
14
14
  * 3) `awaitApproval()` to receive a ready `Session`
15
+ *
16
+ * @deprecated Use `GrantAuthFlow` instead.
15
17
  */
16
18
  class AuthFlow {
17
19
  static __wrap(ptr) {
@@ -36,7 +38,7 @@ class AuthFlow {
36
38
  *
37
39
  * **Security:** This URL contains the `client_secret` in plaintext.
38
40
  * Treat it as a short-lived secret and delete it after the flow completes.
39
- * See `Pubky.startAuthFlow()` docs for storage guidance.
41
+ * See `Pubky.startCookieAuthFlow()` docs for storage guidance.
40
42
  *
41
43
  * @returns {string} A `pubkyauth://…` or `https://…` URL with channel info.
42
44
  *
@@ -87,10 +89,10 @@ class AuthFlow {
87
89
  }
88
90
  /**
89
91
  * Resume a previously started auth flow from its saved `authorizationUrl` (standalone).
90
- * Prefer `pubky.resumeAuthFlow()` to reuse a facade client; this creates a default (mainnet) client.
92
+ * Prefer `pubky.resumeCookieAuthFlow()` to reuse a facade client; this creates a default (mainnet) client.
91
93
  *
92
94
  * Relay messages expire after ~5 minutes; resume is only viable in that window.
93
- * See `Pubky.resumeAuthFlow()` / `Pubky.startAuthFlow()` for full guidance.
95
+ * See `Pubky.resumeCookieAuthFlow()` / `Pubky.startCookieAuthFlow()` for full guidance.
94
96
  *
95
97
  * **Security:** `authorizationUrl` contains the `client_secret`.
96
98
  * Delete it from storage as soon as resume completes or is abandoned.
@@ -113,7 +115,7 @@ class AuthFlow {
113
115
  }
114
116
  /**
115
117
  * Start a flow (standalone).
116
- * Prefer `pubky.startAuthFlow()` to reuse a facade client.
118
+ * Prefer `pubky.startCookieAuthFlow()` to reuse a facade client.
117
119
  *
118
120
  * @param {string} capabilities
119
121
  * Comma-separated capabilities, e.g. `"/pub/app/:rw,/priv/foo.txt:r"`.
@@ -143,6 +145,8 @@ class AuthFlow {
143
145
  * const flow = AuthFlow.start("/pub/my-cool-app/:rw,/pub/pubky.app/:w");
144
146
  * renderQRCode(flow.authorizationUrl());
145
147
  * const session = await flow.awaitApproval();
148
+ *
149
+ * @deprecated Use `GrantAuthFlow.start(...)` instead.
146
150
  * @param {Capabilities} capabilities
147
151
  * @param {AuthFlowKind} kind
148
152
  * @param {string | null} [relay]
@@ -254,7 +258,7 @@ exports.AuthFlowKind = AuthFlowKind;
254
258
  * ### Typical usage
255
259
  * ```js
256
260
  * // Start an auth-only flow (no capabilities)
257
- * const flow = pubky.startAuthFlow("", relay);
261
+ * const flow = pubky.startCookieAuthFlow("", relay);
258
262
  *
259
263
  * // Wait for the signer to approve; returns an AuthToken
260
264
  * const token = await flow.awaitToken();
@@ -291,7 +295,7 @@ class AuthToken {
291
295
  /**
292
296
  * Returns the **capabilities** requested by the flow at the time this token was signed.
293
297
  *
294
- * Most auth-only flows pass an empty string to `startAuthFlow("", relay)`, so this will
298
+ * Most auth-only flows pass an empty string to `startCookieAuthFlow("", relay)`, so this will
295
299
  * commonly be an empty array.
296
300
  *
297
301
  * Returns: `string[]`, where each item is the canonical entry `"<scope>:<actions>"`.
@@ -489,6 +493,74 @@ class Client {
489
493
  if (Symbol.dispose) Client.prototype[Symbol.dispose] = Client.prototype.free;
490
494
  exports.Client = Client;
491
495
 
496
+ /**
497
+ * Cookie-only view over a cookie-backed `Session`.
498
+ *
499
+ * Grant-backed sessions do not expose this view; use `session.cookie` and
500
+ * check for `undefined` before calling cookie-specific methods.
501
+ */
502
+ class CookieSession {
503
+ static __wrap(ptr) {
504
+ ptr = ptr >>> 0;
505
+ const obj = Object.create(CookieSession.prototype);
506
+ obj.__wbg_ptr = ptr;
507
+ CookieSessionFinalization.register(obj, obj.__wbg_ptr, obj);
508
+ return obj;
509
+ }
510
+ __destroy_into_raw() {
511
+ const ptr = this.__wbg_ptr;
512
+ this.__wbg_ptr = 0;
513
+ CookieSessionFinalization.unregister(this);
514
+ return ptr;
515
+ }
516
+ free() {
517
+ const ptr = this.__destroy_into_raw();
518
+ wasm.__wbg_cookiesession_free(ptr, 0);
519
+ }
520
+ /**
521
+ * Export session metadata for legacy cookie restore.
522
+ *
523
+ * The returned string contains no secrets; the browser cookie jar must
524
+ * still hold the HTTP-only cookie.
525
+ *
526
+ * @returns {string}
527
+ * @returns {string}
528
+ */
529
+ export() {
530
+ let deferred2_0;
531
+ let deferred2_1;
532
+ try {
533
+ const ret = wasm.cookiesession_export(this.__wbg_ptr);
534
+ var ptr1 = ret[0];
535
+ var len1 = ret[1];
536
+ if (ret[3]) {
537
+ ptr1 = 0; len1 = 0;
538
+ throw takeFromExternrefTable0(ret[2]);
539
+ }
540
+ deferred2_0 = ptr1;
541
+ deferred2_1 = len1;
542
+ return getStringFromWasm0(ptr1, len1);
543
+ } finally {
544
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
545
+ }
546
+ }
547
+ /**
548
+ * Export the cookie secret needed to restore this cookie session.
549
+ *
550
+ * This is available when the SDK captured the cookie secret, such as in
551
+ * Node.js. Browser sessions cannot read HTTP-only Set-Cookie values.
552
+ *
553
+ * @returns {Promise<string>}
554
+ * @returns {Promise<string>}
555
+ */
556
+ exportSecret() {
557
+ const ret = wasm.cookiesession_exportSecret(this.__wbg_ptr);
558
+ return ret;
559
+ }
560
+ }
561
+ if (Symbol.dispose) CookieSession.prototype[Symbol.dispose] = CookieSession.prototype.free;
562
+ exports.CookieSession = CookieSession;
563
+
492
564
  /**
493
565
  * A single event from the event stream.
494
566
  *
@@ -773,161 +845,623 @@ class EventStreamBuilder {
773
845
  if (Symbol.dispose) EventStreamBuilder.prototype[Symbol.dispose] = EventStreamBuilder.prototype.free;
774
846
  exports.EventStreamBuilder = EventStreamBuilder;
775
847
 
776
- class IntoUnderlyingByteSource {
848
+ /**
849
+ * Start and control a grant-backed pubkyauth authorization flow.
850
+ *
851
+ * Typical flow:
852
+ * 1) `GrantAuthFlow.start(...)` or `pubky.startGrantAuthFlow(...)`
853
+ * 2) Show `authorizationUrl()` as QR/deeplink to the user's signing device
854
+ * 3) `awaitApproval()` to receive a grant-backed, self-refreshing `Session`
855
+ */
856
+ class GrantAuthFlow {
857
+ static __wrap(ptr) {
858
+ ptr = ptr >>> 0;
859
+ const obj = Object.create(GrantAuthFlow.prototype);
860
+ obj.__wbg_ptr = ptr;
861
+ GrantAuthFlowFinalization.register(obj, obj.__wbg_ptr, obj);
862
+ return obj;
863
+ }
777
864
  __destroy_into_raw() {
778
865
  const ptr = this.__wbg_ptr;
779
866
  this.__wbg_ptr = 0;
780
- IntoUnderlyingByteSourceFinalization.unregister(this);
867
+ GrantAuthFlowFinalization.unregister(this);
781
868
  return ptr;
782
869
  }
783
870
  free() {
784
871
  const ptr = this.__destroy_into_raw();
785
- wasm.__wbg_intounderlyingbytesource_free(ptr, 0);
872
+ wasm.__wbg_grantauthflow_free(ptr, 0);
786
873
  }
787
874
  /**
788
- * @returns {number}
875
+ * Return the authorization deep link (URL) to show as QR or open on the signer device.
876
+ * @returns {string}
789
877
  */
790
- get autoAllocateChunkSize() {
791
- const ret = wasm.intounderlyingbytesource_autoAllocateChunkSize(this.__wbg_ptr);
792
- return ret >>> 0;
793
- }
794
- cancel() {
795
- const ptr = this.__destroy_into_raw();
796
- wasm.intounderlyingbytesource_cancel(ptr);
878
+ get authorizationUrl() {
879
+ let deferred1_0;
880
+ let deferred1_1;
881
+ try {
882
+ const ret = wasm.grantauthflow_authorizationUrl(this.__wbg_ptr);
883
+ deferred1_0 = ret[0];
884
+ deferred1_1 = ret[1];
885
+ return getStringFromWasm0(ret[0], ret[1]);
886
+ } finally {
887
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
888
+ }
797
889
  }
798
890
  /**
799
- * @param {ReadableByteStreamController} controller
800
- * @returns {Promise<any>}
891
+ * Block until the user approves on their signer device; returns a grant-backed `Session`.
892
+ * @returns {Promise<Session>}
801
893
  */
802
- pull(controller) {
803
- const ret = wasm.intounderlyingbytesource_pull(this.__wbg_ptr, controller);
894
+ awaitApproval() {
895
+ const ret = wasm.grantauthflow_awaitApproval(this.__wbg_ptr);
804
896
  return ret;
805
897
  }
806
898
  /**
807
- * @param {ReadableByteStreamController} controller
899
+ * Resume a previously saved pending grant auth flow (standalone).
900
+ * Prefer `pubky.resumeGrantAuthFlow()` to reuse a facade client.
901
+ *
902
+ * **Security:** `savedState` contains the relay secret and PoP client private key.
903
+ * Store it only temporarily and delete it once the flow completes or is abandoned.
904
+ *
905
+ * @param {string} savedState A string produced by `grantFlow.save()`.
906
+ * @returns {GrantAuthFlow} A flow reconnected to the original relay channel.
907
+ * @param {string} saved_state
908
+ * @returns {GrantAuthFlow}
808
909
  */
809
- start(controller) {
810
- wasm.intounderlyingbytesource_start(this.__wbg_ptr, controller);
910
+ static resume(saved_state) {
911
+ const ptr0 = passStringToWasm0(saved_state, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
912
+ const len0 = WASM_VECTOR_LEN;
913
+ const ret = wasm.grantauthflow_resume(ptr0, len0);
914
+ if (ret[2]) {
915
+ throw takeFromExternrefTable0(ret[1]);
916
+ }
917
+ return GrantAuthFlow.__wrap(ret[0]);
811
918
  }
812
919
  /**
813
- * @returns {ReadableStreamType}
920
+ * Save sensitive state required to resume this pending grant flow.
921
+ *
922
+ * @returns {string} Opaque state for `GrantAuthFlow.resume()` or
923
+ * `pubky.resumeGrantAuthFlow()`.
924
+ * @returns {string}
814
925
  */
815
- get type() {
816
- const ret = wasm.intounderlyingbytesource_type(this.__wbg_ptr);
817
- return __wbindgen_enum_ReadableStreamType[ret];
926
+ save() {
927
+ let deferred2_0;
928
+ let deferred2_1;
929
+ try {
930
+ const ret = wasm.grantauthflow_save(this.__wbg_ptr);
931
+ var ptr1 = ret[0];
932
+ var len1 = ret[1];
933
+ if (ret[3]) {
934
+ ptr1 = 0; len1 = 0;
935
+ throw takeFromExternrefTable0(ret[2]);
936
+ }
937
+ deferred2_0 = ptr1;
938
+ deferred2_1 = len1;
939
+ return getStringFromWasm0(ptr1, len1);
940
+ } finally {
941
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
942
+ }
943
+ }
944
+ /**
945
+ * Start a grant-backed flow (standalone).
946
+ * Prefer `pubky.startGrantAuthFlow()` to reuse a facade client.
947
+ *
948
+ * @param {string} capabilities
949
+ * Comma-separated capabilities, e.g. `"/pub/app/:rw,/priv/foo.txt:r"`.
950
+ * Empty string is allowed (no scopes).
951
+ *
952
+ * @param {AuthFlowKind} kind
953
+ * The kind of authentication flow to perform.
954
+ *
955
+ * @param {GrantAuthFlowOptions} options
956
+ * Options for the grant flow: `{ clientId, relay? }`.
957
+ *
958
+ * @returns {GrantAuthFlow}
959
+ * A running grant auth flow. Call `authorizationUrl()` to show the deep link,
960
+ * then `awaitApproval()` to receive a grant-backed `Session`.
961
+ * @param {Capabilities} capabilities
962
+ * @param {AuthFlowKind} kind
963
+ * @param {GrantAuthFlowOptions} options
964
+ * @returns {GrantAuthFlow}
965
+ */
966
+ static start(capabilities, kind, options) {
967
+ const ptr0 = passStringToWasm0(capabilities, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
968
+ const len0 = WASM_VECTOR_LEN;
969
+ _assertClass(kind, AuthFlowKind);
970
+ var ptr1 = kind.__destroy_into_raw();
971
+ const ret = wasm.grantauthflow_start(ptr0, len0, ptr1, options);
972
+ if (ret[2]) {
973
+ throw takeFromExternrefTable0(ret[1]);
974
+ }
975
+ return GrantAuthFlow.__wrap(ret[0]);
976
+ }
977
+ /**
978
+ * Non-blocking single poll step (advanced UIs).
979
+ *
980
+ * @returns {Promise<Session|undefined>} A session if the approval arrived, otherwise `undefined`.
981
+ * @returns {Promise<Session | undefined>}
982
+ */
983
+ tryPollOnce() {
984
+ const ret = wasm.grantauthflow_tryPollOnce(this.__wbg_ptr);
985
+ return ret;
818
986
  }
819
987
  }
820
- if (Symbol.dispose) IntoUnderlyingByteSource.prototype[Symbol.dispose] = IntoUnderlyingByteSource.prototype.free;
821
- exports.IntoUnderlyingByteSource = IntoUnderlyingByteSource;
988
+ if (Symbol.dispose) GrantAuthFlow.prototype[Symbol.dispose] = GrantAuthFlow.prototype.free;
989
+ exports.GrantAuthFlow = GrantAuthFlow;
822
990
 
823
- class IntoUnderlyingSink {
991
+ /**
992
+ * Summary of an active grant returned by `GrantManager.list()`.
993
+ */
994
+ class GrantInfo {
995
+ static __wrap(ptr) {
996
+ ptr = ptr >>> 0;
997
+ const obj = Object.create(GrantInfo.prototype);
998
+ obj.__wbg_ptr = ptr;
999
+ GrantInfoFinalization.register(obj, obj.__wbg_ptr, obj);
1000
+ return obj;
1001
+ }
824
1002
  __destroy_into_raw() {
825
1003
  const ptr = this.__wbg_ptr;
826
1004
  this.__wbg_ptr = 0;
827
- IntoUnderlyingSinkFinalization.unregister(this);
1005
+ GrantInfoFinalization.unregister(this);
828
1006
  return ptr;
829
1007
  }
830
1008
  free() {
831
1009
  const ptr = this.__destroy_into_raw();
832
- wasm.__wbg_intounderlyingsink_free(ptr, 0);
1010
+ wasm.__wbg_grantinfo_free(ptr, 0);
833
1011
  }
834
1012
  /**
835
- * @param {any} reason
836
- * @returns {Promise<any>}
1013
+ * Comma-separated capabilities authorized by the grant.
1014
+ * @returns {string}
837
1015
  */
838
- abort(reason) {
839
- const ptr = this.__destroy_into_raw();
840
- const ret = wasm.intounderlyingsink_abort(ptr, reason);
841
- return ret;
1016
+ get capabilities() {
1017
+ let deferred1_0;
1018
+ let deferred1_1;
1019
+ try {
1020
+ const ret = wasm.grantinfo_capabilities(this.__wbg_ptr);
1021
+ deferred1_0 = ret[0];
1022
+ deferred1_1 = ret[1];
1023
+ return getStringFromWasm0(ret[0], ret[1]);
1024
+ } finally {
1025
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
1026
+ }
842
1027
  }
843
1028
  /**
844
- * @returns {Promise<any>}
1029
+ * Application identifier.
1030
+ * @returns {string}
845
1031
  */
846
- close() {
847
- const ptr = this.__destroy_into_raw();
848
- const ret = wasm.intounderlyingsink_close(ptr);
1032
+ get clientId() {
1033
+ let deferred1_0;
1034
+ let deferred1_1;
1035
+ try {
1036
+ const ret = wasm.grantinfo_clientId(this.__wbg_ptr);
1037
+ deferred1_0 = ret[0];
1038
+ deferred1_1 = ret[1];
1039
+ return getStringFromWasm0(ret[0], ret[1]);
1040
+ } finally {
1041
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
1042
+ }
1043
+ }
1044
+ /**
1045
+ * Expiry timestamp, in Unix seconds.
1046
+ * @returns {number}
1047
+ */
1048
+ get expiresAt() {
1049
+ const ret = wasm.grantinfo_expiresAt(this.__wbg_ptr);
849
1050
  return ret;
850
1051
  }
851
1052
  /**
852
- * @param {any} chunk
853
- * @returns {Promise<any>}
1053
+ * Grant identifier used for revocation.
1054
+ * @returns {string}
854
1055
  */
855
- write(chunk) {
856
- const ret = wasm.intounderlyingsink_write(this.__wbg_ptr, chunk);
1056
+ get grantId() {
1057
+ let deferred1_0;
1058
+ let deferred1_1;
1059
+ try {
1060
+ const ret = wasm.grantinfo_grantId(this.__wbg_ptr);
1061
+ deferred1_0 = ret[0];
1062
+ deferred1_1 = ret[1];
1063
+ return getStringFromWasm0(ret[0], ret[1]);
1064
+ } finally {
1065
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
1066
+ }
1067
+ }
1068
+ /**
1069
+ * Issued-at timestamp, in Unix seconds.
1070
+ * @returns {number}
1071
+ */
1072
+ get issuedAt() {
1073
+ const ret = wasm.grantinfo_issuedAt(this.__wbg_ptr);
857
1074
  return ret;
858
1075
  }
859
1076
  }
860
- if (Symbol.dispose) IntoUnderlyingSink.prototype[Symbol.dispose] = IntoUnderlyingSink.prototype.free;
861
- exports.IntoUnderlyingSink = IntoUnderlyingSink;
1077
+ if (Symbol.dispose) GrantInfo.prototype[Symbol.dispose] = GrantInfo.prototype.free;
1078
+ exports.GrantInfo = GrantInfo;
862
1079
 
863
- class IntoUnderlyingSource {
864
- static __wrap(ptr) {
865
- ptr = ptr >>> 0;
866
- const obj = Object.create(IntoUnderlyingSource.prototype);
867
- obj.__wbg_ptr = ptr;
868
- IntoUnderlyingSourceFinalization.register(obj, obj.__wbg_ptr, obj);
869
- return obj;
870
- }
1080
+ /**
1081
+ * Account-level grant management for a signed-in user.
1082
+ */
1083
+ class GrantManager {
871
1084
  __destroy_into_raw() {
872
1085
  const ptr = this.__wbg_ptr;
873
1086
  this.__wbg_ptr = 0;
874
- IntoUnderlyingSourceFinalization.unregister(this);
1087
+ GrantManagerFinalization.unregister(this);
875
1088
  return ptr;
876
1089
  }
877
1090
  free() {
878
1091
  const ptr = this.__destroy_into_raw();
879
- wasm.__wbg_intounderlyingsource_free(ptr, 0);
1092
+ wasm.__wbg_grantmanager_free(ptr, 0);
880
1093
  }
881
- cancel() {
882
- const ptr = this.__destroy_into_raw();
883
- wasm.intounderlyingsource_cancel(ptr);
1094
+ /**
1095
+ * List all active grants for this user.
1096
+ *
1097
+ * Requires a root-capability session. Non-root sessions surface the
1098
+ * homeserver `403` as the standard request error.
1099
+ *
1100
+ * @returns {Promise<GrantInfo[]>}
1101
+ * @returns {Promise<GrantInfo[]>}
1102
+ */
1103
+ list() {
1104
+ const ret = wasm.grantmanager_list(this.__wbg_ptr);
1105
+ return ret;
884
1106
  }
885
1107
  /**
886
- * @param {ReadableStreamDefaultController} controller
887
- * @returns {Promise<any>}
1108
+ * Create a grant manager authenticated by a session.
1109
+ *
1110
+ * @param {Session} session
1111
+ * @returns {GrantManager}
1112
+ * @param {Session} session
888
1113
  */
889
- pull(controller) {
890
- const ret = wasm.intounderlyingsource_pull(this.__wbg_ptr, controller);
1114
+ constructor(session) {
1115
+ _assertClass(session, Session);
1116
+ const ret = wasm.grantmanager_new(session.__wbg_ptr);
1117
+ this.__wbg_ptr = ret >>> 0;
1118
+ GrantManagerFinalization.register(this, this.__wbg_ptr, this);
1119
+ return this;
1120
+ }
1121
+ /**
1122
+ * Revoke a specific grant by id.
1123
+ *
1124
+ * Requires a root-capability session. Malformed ids throw
1125
+ * `InvalidInput`.
1126
+ *
1127
+ * @param {string} grantId
1128
+ * @returns {Promise<void>}
1129
+ * @param {string} grant_id
1130
+ * @returns {Promise<void>}
1131
+ */
1132
+ revoke(grant_id) {
1133
+ const ptr0 = passStringToWasm0(grant_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1134
+ const len0 = WASM_VECTOR_LEN;
1135
+ const ret = wasm.grantmanager_revoke(this.__wbg_ptr, ptr0, len0);
891
1136
  return ret;
892
1137
  }
893
1138
  }
894
- if (Symbol.dispose) IntoUnderlyingSource.prototype[Symbol.dispose] = IntoUnderlyingSource.prototype.free;
895
- exports.IntoUnderlyingSource = IntoUnderlyingSource;
1139
+ if (Symbol.dispose) GrantManager.prototype[Symbol.dispose] = GrantManager.prototype.free;
1140
+ exports.GrantManager = GrantManager;
896
1141
 
897
- class Keypair {
1142
+ /**
1143
+ * Grant-only view over a grant-backed `Session`.
1144
+ *
1145
+ * Cookie-backed sessions do not expose this view; use `session.grant` and
1146
+ * check for `undefined` before calling grant-session methods.
1147
+ */
1148
+ class GrantSession {
898
1149
  static __wrap(ptr) {
899
1150
  ptr = ptr >>> 0;
900
- const obj = Object.create(Keypair.prototype);
1151
+ const obj = Object.create(GrantSession.prototype);
901
1152
  obj.__wbg_ptr = ptr;
902
- KeypairFinalization.register(obj, obj.__wbg_ptr, obj);
1153
+ GrantSessionFinalization.register(obj, obj.__wbg_ptr, obj);
903
1154
  return obj;
904
1155
  }
905
1156
  __destroy_into_raw() {
906
1157
  const ptr = this.__wbg_ptr;
907
1158
  this.__wbg_ptr = 0;
908
- KeypairFinalization.unregister(this);
1159
+ GrantSessionFinalization.unregister(this);
909
1160
  return ptr;
910
1161
  }
911
1162
  free() {
912
1163
  const ptr = this.__destroy_into_raw();
913
- wasm.__wbg_keypair_free(ptr, 0);
1164
+ wasm.__wbg_grantsession_free(ptr, 0);
914
1165
  }
915
1166
  /**
916
- * Create a recovery file for this keypair (encrypted with the given passphrase).
917
- * @param {string} passphrase
918
- * @returns {Uint8Array}
1167
+ * Export the durable refresh material needed to restore this grant session.
1168
+ *
1169
+ * Treat the returned string as bearer-equivalent secret material until the
1170
+ * grant expires or is revoked.
1171
+ *
1172
+ * @returns {Promise<string>}
1173
+ * @returns {Promise<string>}
919
1174
  */
920
- createRecoveryFile(passphrase) {
921
- const ptr0 = passStringToWasm0(passphrase, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
922
- const len0 = WASM_VECTOR_LEN;
923
- const ret = wasm.keypair_createRecoveryFile(this.__wbg_ptr, ptr0, len0);
1175
+ exportSecret() {
1176
+ const ret = wasm.grantsession_exportSecret(this.__wbg_ptr);
924
1177
  return ret;
925
1178
  }
926
1179
  /**
927
- * Decrypt a recovery file and return a Keypair (decrypted with the given passphrase).
928
- * @param {Uint8Array} recovery_file
929
- * @param {string} passphrase
930
- * @returns {Keypair}
1180
+ * Current grant id (`jti`) backing this session.
1181
+ *
1182
+ * @returns {Promise<string>}
1183
+ * @returns {Promise<string>}
1184
+ */
1185
+ grantId() {
1186
+ const ret = wasm.grantsession_grantId(this.__wbg_ptr);
1187
+ return ret;
1188
+ }
1189
+ /**
1190
+ * Full grant session metadata.
1191
+ *
1192
+ * @returns {Promise<GrantSessionInfo>}
1193
+ * @returns {Promise<GrantSessionInfo>}
1194
+ */
1195
+ sessionInfo() {
1196
+ const ret = wasm.grantsession_sessionInfo(this.__wbg_ptr);
1197
+ return ret;
1198
+ }
1199
+ }
1200
+ if (Symbol.dispose) GrantSession.prototype[Symbol.dispose] = GrantSession.prototype.free;
1201
+ exports.GrantSession = GrantSession;
1202
+
1203
+ /**
1204
+ * Grant-specific session metadata returned by `grant.sessionInfo()`.
1205
+ */
1206
+ class GrantSessionInfo {
1207
+ static __wrap(ptr) {
1208
+ ptr = ptr >>> 0;
1209
+ const obj = Object.create(GrantSessionInfo.prototype);
1210
+ obj.__wbg_ptr = ptr;
1211
+ GrantSessionInfoFinalization.register(obj, obj.__wbg_ptr, obj);
1212
+ return obj;
1213
+ }
1214
+ __destroy_into_raw() {
1215
+ const ptr = this.__wbg_ptr;
1216
+ this.__wbg_ptr = 0;
1217
+ GrantSessionInfoFinalization.unregister(this);
1218
+ return ptr;
1219
+ }
1220
+ free() {
1221
+ const ptr = this.__destroy_into_raw();
1222
+ wasm.__wbg_grantsessioninfo_free(ptr, 0);
1223
+ }
1224
+ /**
1225
+ * Authorized capabilities for this session.
1226
+ * @returns {string[]}
1227
+ */
1228
+ get capabilities() {
1229
+ const ret = wasm.grantsessioninfo_capabilities(this.__wbg_ptr);
1230
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
1231
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
1232
+ return v1;
1233
+ }
1234
+ /**
1235
+ * Application identifier.
1236
+ * @returns {string}
1237
+ */
1238
+ get clientId() {
1239
+ let deferred1_0;
1240
+ let deferred1_1;
1241
+ try {
1242
+ const ret = wasm.grantsessioninfo_clientId(this.__wbg_ptr);
1243
+ deferred1_0 = ret[0];
1244
+ deferred1_1 = ret[1];
1245
+ return getStringFromWasm0(ret[0], ret[1]);
1246
+ } finally {
1247
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
1248
+ }
1249
+ }
1250
+ /**
1251
+ * Session creation timestamp, in Unix seconds.
1252
+ * @returns {number}
1253
+ */
1254
+ get createdAt() {
1255
+ const ret = wasm.grantsessioninfo_createdAt(this.__wbg_ptr);
1256
+ return ret;
1257
+ }
1258
+ /**
1259
+ * Underlying grant expiry timestamp, in Unix seconds.
1260
+ * @returns {number}
1261
+ */
1262
+ get grantExpiresAt() {
1263
+ const ret = wasm.grantsessioninfo_grantExpiresAt(this.__wbg_ptr);
1264
+ return ret;
1265
+ }
1266
+ /**
1267
+ * Grant id this session was minted from.
1268
+ * @returns {string}
1269
+ */
1270
+ get grantId() {
1271
+ let deferred1_0;
1272
+ let deferred1_1;
1273
+ try {
1274
+ const ret = wasm.grantsessioninfo_grantId(this.__wbg_ptr);
1275
+ deferred1_0 = ret[0];
1276
+ deferred1_1 = ret[1];
1277
+ return getStringFromWasm0(ret[0], ret[1]);
1278
+ } finally {
1279
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
1280
+ }
1281
+ }
1282
+ /**
1283
+ * Homeserver that issued this session.
1284
+ * @returns {PublicKey}
1285
+ */
1286
+ get homeserver() {
1287
+ const ret = wasm.grantsessioninfo_homeserver(this.__wbg_ptr);
1288
+ return PublicKey.__wrap(ret);
1289
+ }
1290
+ /**
1291
+ * User public key for this session.
1292
+ * @returns {PublicKey}
1293
+ */
1294
+ get publicKey() {
1295
+ const ret = wasm.grantsessioninfo_publicKey(this.__wbg_ptr);
1296
+ return PublicKey.__wrap(ret);
1297
+ }
1298
+ /**
1299
+ * Bearer token expiry timestamp, in Unix seconds.
1300
+ * @returns {number}
1301
+ */
1302
+ get tokenExpiresAt() {
1303
+ const ret = wasm.grantsessioninfo_tokenExpiresAt(this.__wbg_ptr);
1304
+ return ret;
1305
+ }
1306
+ }
1307
+ if (Symbol.dispose) GrantSessionInfo.prototype[Symbol.dispose] = GrantSessionInfo.prototype.free;
1308
+ exports.GrantSessionInfo = GrantSessionInfo;
1309
+
1310
+ class IntoUnderlyingByteSource {
1311
+ __destroy_into_raw() {
1312
+ const ptr = this.__wbg_ptr;
1313
+ this.__wbg_ptr = 0;
1314
+ IntoUnderlyingByteSourceFinalization.unregister(this);
1315
+ return ptr;
1316
+ }
1317
+ free() {
1318
+ const ptr = this.__destroy_into_raw();
1319
+ wasm.__wbg_intounderlyingbytesource_free(ptr, 0);
1320
+ }
1321
+ /**
1322
+ * @returns {number}
1323
+ */
1324
+ get autoAllocateChunkSize() {
1325
+ const ret = wasm.intounderlyingbytesource_autoAllocateChunkSize(this.__wbg_ptr);
1326
+ return ret >>> 0;
1327
+ }
1328
+ cancel() {
1329
+ const ptr = this.__destroy_into_raw();
1330
+ wasm.intounderlyingbytesource_cancel(ptr);
1331
+ }
1332
+ /**
1333
+ * @param {ReadableByteStreamController} controller
1334
+ * @returns {Promise<any>}
1335
+ */
1336
+ pull(controller) {
1337
+ const ret = wasm.intounderlyingbytesource_pull(this.__wbg_ptr, controller);
1338
+ return ret;
1339
+ }
1340
+ /**
1341
+ * @param {ReadableByteStreamController} controller
1342
+ */
1343
+ start(controller) {
1344
+ wasm.intounderlyingbytesource_start(this.__wbg_ptr, controller);
1345
+ }
1346
+ /**
1347
+ * @returns {ReadableStreamType}
1348
+ */
1349
+ get type() {
1350
+ const ret = wasm.intounderlyingbytesource_type(this.__wbg_ptr);
1351
+ return __wbindgen_enum_ReadableStreamType[ret];
1352
+ }
1353
+ }
1354
+ if (Symbol.dispose) IntoUnderlyingByteSource.prototype[Symbol.dispose] = IntoUnderlyingByteSource.prototype.free;
1355
+ exports.IntoUnderlyingByteSource = IntoUnderlyingByteSource;
1356
+
1357
+ class IntoUnderlyingSink {
1358
+ __destroy_into_raw() {
1359
+ const ptr = this.__wbg_ptr;
1360
+ this.__wbg_ptr = 0;
1361
+ IntoUnderlyingSinkFinalization.unregister(this);
1362
+ return ptr;
1363
+ }
1364
+ free() {
1365
+ const ptr = this.__destroy_into_raw();
1366
+ wasm.__wbg_intounderlyingsink_free(ptr, 0);
1367
+ }
1368
+ /**
1369
+ * @param {any} reason
1370
+ * @returns {Promise<any>}
1371
+ */
1372
+ abort(reason) {
1373
+ const ptr = this.__destroy_into_raw();
1374
+ const ret = wasm.intounderlyingsink_abort(ptr, reason);
1375
+ return ret;
1376
+ }
1377
+ /**
1378
+ * @returns {Promise<any>}
1379
+ */
1380
+ close() {
1381
+ const ptr = this.__destroy_into_raw();
1382
+ const ret = wasm.intounderlyingsink_close(ptr);
1383
+ return ret;
1384
+ }
1385
+ /**
1386
+ * @param {any} chunk
1387
+ * @returns {Promise<any>}
1388
+ */
1389
+ write(chunk) {
1390
+ const ret = wasm.intounderlyingsink_write(this.__wbg_ptr, chunk);
1391
+ return ret;
1392
+ }
1393
+ }
1394
+ if (Symbol.dispose) IntoUnderlyingSink.prototype[Symbol.dispose] = IntoUnderlyingSink.prototype.free;
1395
+ exports.IntoUnderlyingSink = IntoUnderlyingSink;
1396
+
1397
+ class IntoUnderlyingSource {
1398
+ static __wrap(ptr) {
1399
+ ptr = ptr >>> 0;
1400
+ const obj = Object.create(IntoUnderlyingSource.prototype);
1401
+ obj.__wbg_ptr = ptr;
1402
+ IntoUnderlyingSourceFinalization.register(obj, obj.__wbg_ptr, obj);
1403
+ return obj;
1404
+ }
1405
+ __destroy_into_raw() {
1406
+ const ptr = this.__wbg_ptr;
1407
+ this.__wbg_ptr = 0;
1408
+ IntoUnderlyingSourceFinalization.unregister(this);
1409
+ return ptr;
1410
+ }
1411
+ free() {
1412
+ const ptr = this.__destroy_into_raw();
1413
+ wasm.__wbg_intounderlyingsource_free(ptr, 0);
1414
+ }
1415
+ cancel() {
1416
+ const ptr = this.__destroy_into_raw();
1417
+ wasm.intounderlyingsource_cancel(ptr);
1418
+ }
1419
+ /**
1420
+ * @param {ReadableStreamDefaultController} controller
1421
+ * @returns {Promise<any>}
1422
+ */
1423
+ pull(controller) {
1424
+ const ret = wasm.intounderlyingsource_pull(this.__wbg_ptr, controller);
1425
+ return ret;
1426
+ }
1427
+ }
1428
+ if (Symbol.dispose) IntoUnderlyingSource.prototype[Symbol.dispose] = IntoUnderlyingSource.prototype.free;
1429
+ exports.IntoUnderlyingSource = IntoUnderlyingSource;
1430
+
1431
+ class Keypair {
1432
+ static __wrap(ptr) {
1433
+ ptr = ptr >>> 0;
1434
+ const obj = Object.create(Keypair.prototype);
1435
+ obj.__wbg_ptr = ptr;
1436
+ KeypairFinalization.register(obj, obj.__wbg_ptr, obj);
1437
+ return obj;
1438
+ }
1439
+ __destroy_into_raw() {
1440
+ const ptr = this.__wbg_ptr;
1441
+ this.__wbg_ptr = 0;
1442
+ KeypairFinalization.unregister(this);
1443
+ return ptr;
1444
+ }
1445
+ free() {
1446
+ const ptr = this.__destroy_into_raw();
1447
+ wasm.__wbg_keypair_free(ptr, 0);
1448
+ }
1449
+ /**
1450
+ * Create a recovery file for this keypair (encrypted with the given passphrase).
1451
+ * @param {string} passphrase
1452
+ * @returns {Uint8Array}
1453
+ */
1454
+ createRecoveryFile(passphrase) {
1455
+ const ptr0 = passStringToWasm0(passphrase, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1456
+ const len0 = WASM_VECTOR_LEN;
1457
+ const ret = wasm.keypair_createRecoveryFile(this.__wbg_ptr, ptr0, len0);
1458
+ return ret;
1459
+ }
1460
+ /**
1461
+ * Decrypt a recovery file and return a Keypair (decrypted with the given passphrase).
1462
+ * @param {Uint8Array} recovery_file
1463
+ * @param {string} passphrase
1464
+ * @returns {Keypair}
931
1465
  */
932
1466
  static fromRecoveryFile(recovery_file, passphrase) {
933
1467
  const ptr0 = passArray8ToWasm0(recovery_file, wasm.__wbindgen_malloc);
@@ -1254,12 +1788,13 @@ class Pubky {
1254
1788
  return PublicStorage.__wrap(ret);
1255
1789
  }
1256
1790
  /**
1257
- * Restore a session from a previously exported snapshot, using this instance's client.
1791
+ * Restore a session from a previously exported token or snapshot, using this instance's client.
1258
1792
  *
1259
- * This does **not** read or write any secrets. It revalidates the session metadata with
1260
- * the server using the browser-managed HTTP-only cookie that must still be present.
1793
+ * Accepts grant secret tokens from `session.exportSecret()` and legacy cookie
1794
+ * secret tokens. Also accepts legacy cookie metadata snapshots from `session.export()`.
1795
+ * Grant restore mints a fresh short-lived bearer.
1261
1796
  *
1262
- * @param {string} exported A string produced by `session.export()`.
1797
+ * @param {string} exported A string produced by `session.exportSecret()` or legacy `session.export()`.
1263
1798
  * @returns {Promise<Session>}
1264
1799
  * A rehydrated session bound to this SDK's HTTP client.
1265
1800
  *
@@ -1282,7 +1817,7 @@ class Pubky {
1282
1817
  *
1283
1818
  * **Security:** The URL contains the `client_secret` in plaintext.
1284
1819
  * Delete it from storage as soon as the resumed flow completes.
1285
- * See `startAuthFlow()` docs for full storage guidance.
1820
+ * See `startCookieAuthFlow()` docs for full storage guidance.
1286
1821
  *
1287
1822
  * @param {string} authorizationUrl The `pubkyauth://…` URL from a previous flow.
1288
1823
  * @returns {AuthFlow} A flow reconnected to the original relay channel.
@@ -1292,15 +1827,35 @@ class Pubky {
1292
1827
  * @param {string} authorization_url
1293
1828
  * @returns {AuthFlow}
1294
1829
  */
1295
- resumeAuthFlow(authorization_url) {
1830
+ resumeCookieAuthFlow(authorization_url) {
1296
1831
  const ptr0 = passStringToWasm0(authorization_url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1297
1832
  const len0 = WASM_VECTOR_LEN;
1298
- const ret = wasm.pubky_resumeAuthFlow(this.__wbg_ptr, ptr0, len0);
1833
+ const ret = wasm.pubky_resumeCookieAuthFlow(this.__wbg_ptr, ptr0, len0);
1299
1834
  if (ret[2]) {
1300
1835
  throw takeFromExternrefTable0(ret[1]);
1301
1836
  }
1302
1837
  return AuthFlow.__wrap(ret[0]);
1303
1838
  }
1839
+ /**
1840
+ * Resume a previously saved pending grant auth flow.
1841
+ *
1842
+ * **Security:** `savedState` contains the relay secret and PoP client private key.
1843
+ * Delete it from storage as soon as the resumed flow completes.
1844
+ *
1845
+ * @param {string} savedState A string produced by `grantFlow.save()`.
1846
+ * @returns {GrantAuthFlow} A flow reconnected to the original relay channel.
1847
+ * @param {string} saved_state
1848
+ * @returns {GrantAuthFlow}
1849
+ */
1850
+ resumeGrantAuthFlow(saved_state) {
1851
+ const ptr0 = passStringToWasm0(saved_state, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1852
+ const len0 = WASM_VECTOR_LEN;
1853
+ const ret = wasm.pubky_resumeGrantAuthFlow(this.__wbg_ptr, ptr0, len0);
1854
+ if (ret[2]) {
1855
+ throw takeFromExternrefTable0(ret[1]);
1856
+ }
1857
+ return GrantAuthFlow.__wrap(ret[0]);
1858
+ }
1304
1859
  /**
1305
1860
  * Create a `Signer` from an existing `Keypair`.
1306
1861
  *
@@ -1309,7 +1864,7 @@ class Pubky {
1309
1864
  *
1310
1865
  * @example
1311
1866
  * const signer = pubky.signer(Keypair.random());
1312
- * const session = await signer.signup(homeserverPk, null);
1867
+ * await signer.signup(homeserverPk);
1313
1868
  * @param {Keypair} keypair
1314
1869
  * @returns {Signer}
1315
1870
  */
@@ -1347,26 +1902,61 @@ class Pubky {
1347
1902
  * - `{ name: "RequestError" }` if the flow cannot be started (network/relay)
1348
1903
  *
1349
1904
  * @example
1350
- * const flow = pubky.startAuthFlow("/pub/my-cool-app/:rw");
1351
- * renderQr(flow.authorizationUrl);
1352
- * const session = await flow.awaitApproval();
1905
+ * const flow = pubky.startCookieAuthFlow("/pub/my-cool-app/:rw");
1906
+ * renderQr(flow.authorizationUrl);
1907
+ * const session = await flow.awaitApproval();
1908
+ * @param {Capabilities} capabilities
1909
+ * @param {AuthFlowKind} kind
1910
+ * @param {string | null} [relay]
1911
+ * @returns {AuthFlow}
1912
+ */
1913
+ startCookieAuthFlow(capabilities, kind, relay) {
1914
+ const ptr0 = passStringToWasm0(capabilities, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1915
+ const len0 = WASM_VECTOR_LEN;
1916
+ _assertClass(kind, AuthFlowKind);
1917
+ var ptr1 = kind.__destroy_into_raw();
1918
+ var ptr2 = isLikeNone(relay) ? 0 : passStringToWasm0(relay, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1919
+ var len2 = WASM_VECTOR_LEN;
1920
+ const ret = wasm.pubky_startCookieAuthFlow(this.__wbg_ptr, ptr0, len0, ptr1, ptr2, len2);
1921
+ if (ret[2]) {
1922
+ throw takeFromExternrefTable0(ret[1]);
1923
+ }
1924
+ return AuthFlow.__wrap(ret[0]);
1925
+ }
1926
+ /**
1927
+ * Start a grant-backed **pubkyauth** flow.
1928
+ *
1929
+ * Grant auth uses a user-signed grant JWS plus Proof-of-Possession and
1930
+ * returns a self-refreshing session.
1931
+ *
1932
+ * @param {string} capabilities Comma-separated caps, e.g. `"/pub/app/:rw,/pub/foo/file:r"`.
1933
+ * @param {AuthFlowKind} kind The kind of authentication flow to perform.
1934
+ * @param {GrantAuthFlowOptions} options Options for the grant flow: `{ clientId, relay? }`.
1935
+ * @returns {GrantAuthFlow}
1936
+ * A running grant auth flow. Show `authorizationUrl` as QR/deeplink,
1937
+ * then `awaitApproval()` to obtain a grant-backed `Session`.
1938
+ *
1939
+ * @example
1940
+ * const flow = pubky.startGrantAuthFlow(
1941
+ * "/pub/my-cool-app/:rw",
1942
+ * AuthFlowKind.signin(),
1943
+ * { clientId: "my-cool-app.example" },
1944
+ * );
1353
1945
  * @param {Capabilities} capabilities
1354
1946
  * @param {AuthFlowKind} kind
1355
- * @param {string | null} [relay]
1356
- * @returns {AuthFlow}
1947
+ * @param {GrantAuthFlowOptions} options
1948
+ * @returns {GrantAuthFlow}
1357
1949
  */
1358
- startAuthFlow(capabilities, kind, relay) {
1950
+ startGrantAuthFlow(capabilities, kind, options) {
1359
1951
  const ptr0 = passStringToWasm0(capabilities, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1360
1952
  const len0 = WASM_VECTOR_LEN;
1361
1953
  _assertClass(kind, AuthFlowKind);
1362
1954
  var ptr1 = kind.__destroy_into_raw();
1363
- var ptr2 = isLikeNone(relay) ? 0 : passStringToWasm0(relay, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1364
- var len2 = WASM_VECTOR_LEN;
1365
- const ret = wasm.pubky_startAuthFlow(this.__wbg_ptr, ptr0, len0, ptr1, ptr2, len2);
1955
+ const ret = wasm.pubky_startGrantAuthFlow(this.__wbg_ptr, ptr0, len0, ptr1, options);
1366
1956
  if (ret[2]) {
1367
1957
  throw takeFromExternrefTable0(ret[1]);
1368
1958
  }
1369
- return AuthFlow.__wrap(ret[0]);
1959
+ return GrantAuthFlow.__wrap(ret[0]);
1370
1960
  }
1371
1961
  /**
1372
1962
  * Create a Pubky facade preconfigured for a **local testnet**.
@@ -1830,6 +2420,18 @@ class Session {
1830
2420
  const ptr = this.__destroy_into_raw();
1831
2421
  wasm.__wbg_session_free(ptr, 0);
1832
2422
  }
2423
+ /**
2424
+ * Cookie-only view for cookie-backed sessions.
2425
+ *
2426
+ * Grant-backed sessions return `undefined`.
2427
+ *
2428
+ * @returns {CookieSession|undefined}
2429
+ * @returns {CookieSession | undefined}
2430
+ */
2431
+ get cookie() {
2432
+ const ret = wasm.session_cookie(this.__wbg_ptr);
2433
+ return ret === 0 ? undefined : CookieSession.__wrap(ret);
2434
+ }
1833
2435
  /**
1834
2436
  * Export the session metadata so it can be restored after a tab refresh.
1835
2437
  *
@@ -1838,6 +2440,8 @@ class Session {
1838
2440
  *
1839
2441
  * @returns {string}
1840
2442
  * A base64 string to store (e.g. in `localStorage`).
2443
+ *
2444
+ * @deprecated Prefer `exportSecret()` for grant sessions.
1841
2445
  * @returns {string}
1842
2446
  */
1843
2447
  export() {
@@ -1852,6 +2456,36 @@ class Session {
1852
2456
  wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
1853
2457
  }
1854
2458
  }
2459
+ /**
2460
+ * Export the secret material needed to restore this session.
2461
+ *
2462
+ * For grant sessions this exports the grant JWS and PoP client secret; restoring
2463
+ * mints a fresh bearer. For legacy cookie sessions this exports the cookie secret
2464
+ * when the SDK owns it.
2465
+ *
2466
+ * Treat the returned string as a bearer-equivalent secret until the grant or
2467
+ * cookie session expires or is revoked.
2468
+ *
2469
+ * @returns {Promise<string>}
2470
+ * A secret token that can be passed to `pubky.restoreSession()`.
2471
+ * @returns {Promise<string>}
2472
+ */
2473
+ exportSecret() {
2474
+ const ret = wasm.session_exportSecret(this.__wbg_ptr);
2475
+ return ret;
2476
+ }
2477
+ /**
2478
+ * Grant-only management view for grant-backed sessions.
2479
+ *
2480
+ * Cookie-backed sessions return `undefined`.
2481
+ *
2482
+ * @returns {GrantSession|undefined}
2483
+ * @returns {GrantSession | undefined}
2484
+ */
2485
+ get grant() {
2486
+ const ret = wasm.session_grant(this.__wbg_ptr);
2487
+ return ret === 0 ? undefined : GrantSession.__wrap(ret);
2488
+ }
1855
2489
  /**
1856
2490
  * Retrieve immutable info about this session (user & capabilities).
1857
2491
  *
@@ -1873,6 +2507,8 @@ class Session {
1873
2507
  * @param {Client=} client
1874
2508
  * Optional client to reuse transport configuration.
1875
2509
  * @returns {Promise<Session>}
2510
+ *
2511
+ * @deprecated Prefer `Pubky.restoreSession(...)`.
1876
2512
  * @param {string} exported
1877
2513
  * @param {Client | null} [client]
1878
2514
  * @returns {Promise<Session>}
@@ -1967,7 +2603,7 @@ if (Symbol.dispose) SessionInfo.prototype[Symbol.dispose] = SessionInfo.prototyp
1967
2603
  exports.SessionInfo = SessionInfo;
1968
2604
 
1969
2605
  /**
1970
- * Read/write storage scoped to **your** session (absolute paths: `/pub/...`).
2606
+ * Read/write storage scoped to **your** session (absolute paths: `/pub/...` or `/priv/...`).
1971
2607
  */
1972
2608
  class SessionStorage {
1973
2609
  static __wrap(ptr) {
@@ -2173,144 +2809,416 @@ exports.SessionStorage = SessionStorage;
2173
2809
  * - Approve pubkyauth requests
2174
2810
  * - Publish PKDNS when signer-bound
2175
2811
  */
2176
- class Signer {
2812
+ class Signer {
2813
+ static __wrap(ptr) {
2814
+ ptr = ptr >>> 0;
2815
+ const obj = Object.create(Signer.prototype);
2816
+ obj.__wbg_ptr = ptr;
2817
+ SignerFinalization.register(obj, obj.__wbg_ptr, obj);
2818
+ return obj;
2819
+ }
2820
+ __destroy_into_raw() {
2821
+ const ptr = this.__wbg_ptr;
2822
+ this.__wbg_ptr = 0;
2823
+ SignerFinalization.unregister(this);
2824
+ return ptr;
2825
+ }
2826
+ free() {
2827
+ const ptr = this.__destroy_into_raw();
2828
+ wasm.__wbg_signer_free(ptr, 0);
2829
+ }
2830
+ /**
2831
+ * Approve a `pubkyauth://` request URL (encrypts & POSTs the signed AuthToken).
2832
+ * @param {string} pubkyauth_url
2833
+ * @returns {Promise<void>}
2834
+ */
2835
+ approveAuthRequest(pubkyauth_url) {
2836
+ const ptr0 = passStringToWasm0(pubkyauth_url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
2837
+ const len0 = WASM_VECTOR_LEN;
2838
+ const ret = wasm.signer_approveAuthRequest(this.__wbg_ptr, ptr0, len0);
2839
+ return ret;
2840
+ }
2841
+ /**
2842
+ * Create a signer from a `Keypair` (prefer `pubky.signer(kp)`).
2843
+ *
2844
+ * @param {Keypair} keypair
2845
+ * @returns {Signer}
2846
+ * @param {Keypair} keypair
2847
+ * @returns {Signer}
2848
+ */
2849
+ static fromKeypair(keypair) {
2850
+ _assertClass(keypair, Keypair);
2851
+ const ret = wasm.signer_fromKeypair(keypair.__wbg_ptr);
2852
+ if (ret[2]) {
2853
+ throw takeFromExternrefTable0(ret[1]);
2854
+ }
2855
+ return Signer.__wrap(ret[0]);
2856
+ }
2857
+ /**
2858
+ * Get a PKDNS actor bound to this signer's client & keypair (publishing enabled).
2859
+ *
2860
+ * @returns {Pkdns}
2861
+ *
2862
+ * @example
2863
+ * await signer.pkdns.publishHomeserverIfStale(homeserverPk);
2864
+ * @returns {Pkdns}
2865
+ */
2866
+ get pkdns() {
2867
+ const ret = wasm.signer_pkdns(this.__wbg_ptr);
2868
+ return Pkdns.__wrap(ret);
2869
+ }
2870
+ /**
2871
+ * Get the public key of this signer.
2872
+ *
2873
+ * @returns {PublicKey}
2874
+ * @returns {PublicKey}
2875
+ */
2876
+ get publicKey() {
2877
+ const ret = wasm.signer_publicKey(this.__wbg_ptr);
2878
+ return PublicKey.__wrap(ret);
2879
+ }
2880
+ /**
2881
+ * Fast sign-in for a returning user. Publishes PKDNS in the background.
2882
+ *
2883
+ * Creates a valid grant-backed homeserver Session with root capabilities.
2884
+ * `clientId` is shown in the user's grant/session list.
2885
+ * @param {string} clientId App identifier, typically a domain.
2886
+ *
2887
+ * @returns {Promise<Session>}
2888
+ *
2889
+ * @throws {PubkyError}
2890
+ * @param {string} client_id
2891
+ * @returns {Promise<Session>}
2892
+ */
2893
+ signin(client_id) {
2894
+ const ptr0 = passStringToWasm0(client_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
2895
+ const len0 = WASM_VECTOR_LEN;
2896
+ const ret = wasm.signer_signin(this.__wbg_ptr, ptr0, len0);
2897
+ return ret;
2898
+ }
2899
+ /**
2900
+ * Blocking sign-in. Waits for PKDNS publish to complete (slower; safer).
2901
+ *
2902
+ * Creates a valid grant-backed homeserver Session with root capabilities.
2903
+ * `clientId` is shown in the user's grant/session list.
2904
+ * @param {string} clientId App identifier, typically a domain.
2905
+ *
2906
+ * @returns {Promise<Session>}
2907
+ * @param {string} client_id
2908
+ * @returns {Promise<Session>}
2909
+ */
2910
+ signinBlocking(client_id) {
2911
+ const ptr0 = passStringToWasm0(client_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
2912
+ const len0 = WASM_VECTOR_LEN;
2913
+ const ret = wasm.signer_signinBlocking(this.__wbg_ptr, ptr0, len0);
2914
+ return ret;
2915
+ }
2916
+ /**
2917
+ * Legacy cookie signin. Prefer `signin(clientId)`.
2918
+ *
2919
+ * @deprecated Prefer `signin(clientId)`.
2920
+ * @returns {Promise<Session>}
2921
+ */
2922
+ signinCookie() {
2923
+ const ret = wasm.signer_signinCookie(this.__wbg_ptr);
2924
+ return ret;
2925
+ }
2926
+ /**
2927
+ * Legacy cookie blocking signin. Prefer `signinBlocking(clientId)`.
2928
+ *
2929
+ * @deprecated Prefer `signinBlocking(clientId)`.
2930
+ * @returns {Promise<Session>}
2931
+ */
2932
+ signinCookieBlocking() {
2933
+ const ret = wasm.signer_signinCookieBlocking(this.__wbg_ptr);
2934
+ return ret;
2935
+ }
2936
+ /**
2937
+ * Sign up at a homeserver.
2938
+ *
2939
+ * Creates the account and publishes PKDNS. Call `signin(clientId)` to create a session.
2940
+ *
2941
+ * @param {PublicKey} homeserver The homeserver’s public key.
2942
+ * @param {string|null} signupToken Invite/registration token or `null`.
2943
+ * @returns {Promise<void>}
2944
+ *
2945
+ * @throws {PubkyError}
2946
+ * - `AuthenticationError` (bad/expired token)
2947
+ * - `RequestError` (network/server)
2948
+ * @param {PublicKey} homeserver
2949
+ * @param {string | null} [signup_token]
2950
+ * @returns {Promise<void>}
2951
+ */
2952
+ signup(homeserver, signup_token) {
2953
+ _assertClass(homeserver, PublicKey);
2954
+ var ptr0 = isLikeNone(signup_token) ? 0 : passStringToWasm0(signup_token, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
2955
+ var len0 = WASM_VECTOR_LEN;
2956
+ const ret = wasm.signer_signup(this.__wbg_ptr, homeserver.__wbg_ptr, ptr0, len0);
2957
+ return ret;
2958
+ }
2959
+ /**
2960
+ * Legacy cookie signup. Prefer `signup()` plus `signin(clientId)`.
2961
+ *
2962
+ * @deprecated Prefer `signup()` followed by `signin(clientId)`.
2963
+ * @param {PublicKey} homeserver
2964
+ * @param {string | null} [signup_token]
2965
+ * @returns {Promise<Session>}
2966
+ */
2967
+ signupCookie(homeserver, signup_token) {
2968
+ _assertClass(homeserver, PublicKey);
2969
+ var ptr0 = isLikeNone(signup_token) ? 0 : passStringToWasm0(signup_token, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
2970
+ var len0 = WASM_VECTOR_LEN;
2971
+ const ret = wasm.signer_signupCookie(this.__wbg_ptr, homeserver.__wbg_ptr, ptr0, len0);
2972
+ return ret;
2973
+ }
2974
+ }
2975
+ if (Symbol.dispose) Signer.prototype[Symbol.dispose] = Signer.prototype.free;
2976
+ exports.Signer = Signer;
2977
+
2978
+ class SigninDeepLink {
2979
+ static __wrap(ptr) {
2980
+ ptr = ptr >>> 0;
2981
+ const obj = Object.create(SigninDeepLink.prototype);
2982
+ obj.__wbg_ptr = ptr;
2983
+ SigninDeepLinkFinalization.register(obj, obj.__wbg_ptr, obj);
2984
+ return obj;
2985
+ }
2986
+ __destroy_into_raw() {
2987
+ const ptr = this.__wbg_ptr;
2988
+ this.__wbg_ptr = 0;
2989
+ SigninDeepLinkFinalization.unregister(this);
2990
+ return ptr;
2991
+ }
2992
+ free() {
2993
+ const ptr = this.__destroy_into_raw();
2994
+ wasm.__wbg_signindeeplink_free(ptr, 0);
2995
+ }
2996
+ /**
2997
+ * @returns {string}
2998
+ */
2999
+ get baseRelayUrl() {
3000
+ let deferred1_0;
3001
+ let deferred1_1;
3002
+ try {
3003
+ const ret = wasm.signindeeplink_baseRelayUrl(this.__wbg_ptr);
3004
+ deferred1_0 = ret[0];
3005
+ deferred1_1 = ret[1];
3006
+ return getStringFromWasm0(ret[0], ret[1]);
3007
+ } finally {
3008
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
3009
+ }
3010
+ }
3011
+ /**
3012
+ * @returns {string}
3013
+ */
3014
+ get capabilities() {
3015
+ let deferred1_0;
3016
+ let deferred1_1;
3017
+ try {
3018
+ const ret = wasm.signindeeplink_capabilities(this.__wbg_ptr);
3019
+ deferred1_0 = ret[0];
3020
+ deferred1_1 = ret[1];
3021
+ return getStringFromWasm0(ret[0], ret[1]);
3022
+ } finally {
3023
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
3024
+ }
3025
+ }
3026
+ /**
3027
+ * @param {string} url
3028
+ * @returns {SigninDeepLink}
3029
+ */
3030
+ static parse(url) {
3031
+ const ptr0 = passStringToWasm0(url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
3032
+ const len0 = WASM_VECTOR_LEN;
3033
+ const ret = wasm.signindeeplink_parse(ptr0, len0);
3034
+ if (ret[2]) {
3035
+ throw takeFromExternrefTable0(ret[1]);
3036
+ }
3037
+ return SigninDeepLink.__wrap(ret[0]);
3038
+ }
3039
+ /**
3040
+ * @returns {Uint8Array}
3041
+ */
3042
+ get secret() {
3043
+ const ret = wasm.signindeeplink_secret(this.__wbg_ptr);
3044
+ return ret;
3045
+ }
3046
+ /**
3047
+ * @returns {string}
3048
+ */
3049
+ toString() {
3050
+ let deferred1_0;
3051
+ let deferred1_1;
3052
+ try {
3053
+ const ret = wasm.signindeeplink_toString(this.__wbg_ptr);
3054
+ deferred1_0 = ret[0];
3055
+ deferred1_1 = ret[1];
3056
+ return getStringFromWasm0(ret[0], ret[1]);
3057
+ } finally {
3058
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
3059
+ }
3060
+ }
3061
+ }
3062
+ if (Symbol.dispose) SigninDeepLink.prototype[Symbol.dispose] = SigninDeepLink.prototype.free;
3063
+ exports.SigninDeepLink = SigninDeepLink;
3064
+
3065
+ /**
3066
+ * Parsed grant-based signin deeplink.
3067
+ *
3068
+ * This is useful for tools, tests, and signer UIs that need to inspect a
3069
+ * `pubky://signin-grant` authorization URL before approving it.
3070
+ */
3071
+ class SigninGrantDeepLink {
2177
3072
  static __wrap(ptr) {
2178
3073
  ptr = ptr >>> 0;
2179
- const obj = Object.create(Signer.prototype);
3074
+ const obj = Object.create(SigninGrantDeepLink.prototype);
2180
3075
  obj.__wbg_ptr = ptr;
2181
- SignerFinalization.register(obj, obj.__wbg_ptr, obj);
3076
+ SigninGrantDeepLinkFinalization.register(obj, obj.__wbg_ptr, obj);
2182
3077
  return obj;
2183
3078
  }
2184
3079
  __destroy_into_raw() {
2185
3080
  const ptr = this.__wbg_ptr;
2186
3081
  this.__wbg_ptr = 0;
2187
- SignerFinalization.unregister(this);
3082
+ SigninGrantDeepLinkFinalization.unregister(this);
2188
3083
  return ptr;
2189
3084
  }
2190
3085
  free() {
2191
3086
  const ptr = this.__destroy_into_raw();
2192
- wasm.__wbg_signer_free(ptr, 0);
3087
+ wasm.__wbg_signingrantdeeplink_free(ptr, 0);
2193
3088
  }
2194
3089
  /**
2195
- * Approve a `pubkyauth://` request URL (encrypts & POSTs the signed AuthToken).
2196
- * @param {string} pubkyauth_url
2197
- * @returns {Promise<void>}
3090
+ * Base HTTP relay inbox URL used by this auth request.
3091
+ *
3092
+ * @returns {string}
3093
+ * @returns {string}
2198
3094
  */
2199
- approveAuthRequest(pubkyauth_url) {
2200
- const ptr0 = passStringToWasm0(pubkyauth_url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
2201
- const len0 = WASM_VECTOR_LEN;
2202
- const ret = wasm.signer_approveAuthRequest(this.__wbg_ptr, ptr0, len0);
2203
- return ret;
3095
+ get baseRelayUrl() {
3096
+ let deferred1_0;
3097
+ let deferred1_1;
3098
+ try {
3099
+ const ret = wasm.signingrantdeeplink_baseRelayUrl(this.__wbg_ptr);
3100
+ deferred1_0 = ret[0];
3101
+ deferred1_1 = ret[1];
3102
+ return getStringFromWasm0(ret[0], ret[1]);
3103
+ } finally {
3104
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
3105
+ }
2204
3106
  }
2205
3107
  /**
2206
- * Create a signer from a `Keypair` (prefer `pubky.signer(kp)`).
3108
+ * Capabilities requested by the application.
2207
3109
  *
2208
- * @param {Keypair} keypair
2209
- * @returns {Signer}
2210
- * @param {Keypair} keypair
2211
- * @returns {Signer}
3110
+ * @returns {string}
3111
+ * @returns {string}
2212
3112
  */
2213
- static fromKeypair(keypair) {
2214
- _assertClass(keypair, Keypair);
2215
- const ret = wasm.signer_fromKeypair(keypair.__wbg_ptr);
2216
- if (ret[2]) {
2217
- throw takeFromExternrefTable0(ret[1]);
3113
+ get capabilities() {
3114
+ let deferred1_0;
3115
+ let deferred1_1;
3116
+ try {
3117
+ const ret = wasm.signingrantdeeplink_capabilities(this.__wbg_ptr);
3118
+ deferred1_0 = ret[0];
3119
+ deferred1_1 = ret[1];
3120
+ return getStringFromWasm0(ret[0], ret[1]);
3121
+ } finally {
3122
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
2218
3123
  }
2219
- return Signer.__wrap(ret[0]);
2220
3124
  }
2221
3125
  /**
2222
- * Get a PKDNS actor bound to this signer's client & keypair (publishing enabled).
2223
- *
2224
- * @returns {Pkdns}
3126
+ * Application identifier shown in the user's grant/session list.
2225
3127
  *
2226
- * @example
2227
- * await signer.pkdns.publishHomeserverIfStale(homeserverPk);
2228
- * @returns {Pkdns}
3128
+ * @returns {string}
3129
+ * @returns {string}
2229
3130
  */
2230
- get pkdns() {
2231
- const ret = wasm.signer_pkdns(this.__wbg_ptr);
2232
- return Pkdns.__wrap(ret);
3131
+ get clientId() {
3132
+ let deferred1_0;
3133
+ let deferred1_1;
3134
+ try {
3135
+ const ret = wasm.signingrantdeeplink_clientId(this.__wbg_ptr);
3136
+ deferred1_0 = ret[0];
3137
+ deferred1_1 = ret[1];
3138
+ return getStringFromWasm0(ret[0], ret[1]);
3139
+ } finally {
3140
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
3141
+ }
2233
3142
  }
2234
3143
  /**
2235
- * Get the public key of this signer.
3144
+ * Public key for the Proof-of-Possession client created by the application.
2236
3145
  *
2237
3146
  * @returns {PublicKey}
2238
3147
  * @returns {PublicKey}
2239
3148
  */
2240
- get publicKey() {
2241
- const ret = wasm.signer_publicKey(this.__wbg_ptr);
3149
+ get clientPublicKey() {
3150
+ const ret = wasm.signingrantdeeplink_clientPublicKey(this.__wbg_ptr);
2242
3151
  return PublicKey.__wrap(ret);
2243
3152
  }
2244
3153
  /**
2245
- * Fast sign-in for a returning user. Publishes PKDNS in the background.
3154
+ * Parse a grant signin deeplink URL.
2246
3155
  *
2247
- * Creates a valid homeserver Session with root capabilities
2248
- *
2249
- * @returns {Promise<Session>}
2250
- *
2251
- * @throws {PubkyError}
2252
- * @returns {Promise<Session>}
3156
+ * @param {string} url
3157
+ * @returns {SigninGrantDeepLink}
3158
+ * @throws {PubkyError} `InvalidInput` when the URL is malformed or not a grant signin link.
3159
+ * @param {string} url
3160
+ * @returns {SigninGrantDeepLink}
2253
3161
  */
2254
- signin() {
2255
- const ret = wasm.signer_signin(this.__wbg_ptr);
2256
- return ret;
3162
+ static parse(url) {
3163
+ const ptr0 = passStringToWasm0(url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
3164
+ const len0 = WASM_VECTOR_LEN;
3165
+ const ret = wasm.signingrantdeeplink_parse(ptr0, len0);
3166
+ if (ret[2]) {
3167
+ throw takeFromExternrefTable0(ret[1]);
3168
+ }
3169
+ return SigninGrantDeepLink.__wrap(ret[0]);
2257
3170
  }
2258
3171
  /**
2259
- * Blocking sign-in. Waits for PKDNS publish to complete (slower; safer).
3172
+ * Relay channel secret embedded in the deeplink.
2260
3173
  *
2261
- * Creates a valid homeserver Session with root capabilities
3174
+ * Treat this as sensitive temporary auth-flow material.
2262
3175
  *
2263
- * @returns {Promise<Session>}
2264
- * @returns {Promise<Session>}
3176
+ * @returns {Uint8Array}
3177
+ * @returns {Uint8Array}
2265
3178
  */
2266
- signinBlocking() {
2267
- const ret = wasm.signer_signinBlocking(this.__wbg_ptr);
3179
+ get secret() {
3180
+ const ret = wasm.signingrantdeeplink_secret(this.__wbg_ptr);
2268
3181
  return ret;
2269
3182
  }
2270
3183
  /**
2271
- * Sign up at a homeserver. Returns a ready `Session`.
3184
+ * Serialize this parsed deeplink back to its URL form.
2272
3185
  *
2273
- * Creates a valid homeserver Session with root capabilities
2274
- *
2275
- * @param {PublicKey} homeserver The homeserver’s public key.
2276
- * @param {string|null} signupToken Invite/registration token or `null`.
2277
- * @returns {Promise<Session>}
2278
- *
2279
- * @throws {PubkyError}
2280
- * - `AuthenticationError` (bad/expired token)
2281
- * - `RequestError` (network/server)
2282
- * @param {PublicKey} homeserver
2283
- * @param {string | null} [signup_token]
2284
- * @returns {Promise<Session>}
3186
+ * @returns {string}
3187
+ * @returns {string}
2285
3188
  */
2286
- signup(homeserver, signup_token) {
2287
- _assertClass(homeserver, PublicKey);
2288
- var ptr0 = isLikeNone(signup_token) ? 0 : passStringToWasm0(signup_token, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
2289
- var len0 = WASM_VECTOR_LEN;
2290
- const ret = wasm.signer_signup(this.__wbg_ptr, homeserver.__wbg_ptr, ptr0, len0);
2291
- return ret;
3189
+ toString() {
3190
+ let deferred1_0;
3191
+ let deferred1_1;
3192
+ try {
3193
+ const ret = wasm.signingrantdeeplink_toString(this.__wbg_ptr);
3194
+ deferred1_0 = ret[0];
3195
+ deferred1_1 = ret[1];
3196
+ return getStringFromWasm0(ret[0], ret[1]);
3197
+ } finally {
3198
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
3199
+ }
2292
3200
  }
2293
3201
  }
2294
- if (Symbol.dispose) Signer.prototype[Symbol.dispose] = Signer.prototype.free;
2295
- exports.Signer = Signer;
3202
+ if (Symbol.dispose) SigninGrantDeepLink.prototype[Symbol.dispose] = SigninGrantDeepLink.prototype.free;
3203
+ exports.SigninGrantDeepLink = SigninGrantDeepLink;
2296
3204
 
2297
- class SigninDeepLink {
3205
+ class SignupDeepLink {
2298
3206
  static __wrap(ptr) {
2299
3207
  ptr = ptr >>> 0;
2300
- const obj = Object.create(SigninDeepLink.prototype);
3208
+ const obj = Object.create(SignupDeepLink.prototype);
2301
3209
  obj.__wbg_ptr = ptr;
2302
- SigninDeepLinkFinalization.register(obj, obj.__wbg_ptr, obj);
3210
+ SignupDeepLinkFinalization.register(obj, obj.__wbg_ptr, obj);
2303
3211
  return obj;
2304
3212
  }
2305
3213
  __destroy_into_raw() {
2306
3214
  const ptr = this.__wbg_ptr;
2307
3215
  this.__wbg_ptr = 0;
2308
- SigninDeepLinkFinalization.unregister(this);
3216
+ SignupDeepLinkFinalization.unregister(this);
2309
3217
  return ptr;
2310
3218
  }
2311
3219
  free() {
2312
3220
  const ptr = this.__destroy_into_raw();
2313
- wasm.__wbg_signindeeplink_free(ptr, 0);
3221
+ wasm.__wbg_signupdeeplink_free(ptr, 0);
2314
3222
  }
2315
3223
  /**
2316
3224
  * @returns {string}
@@ -2319,7 +3227,7 @@ class SigninDeepLink {
2319
3227
  let deferred1_0;
2320
3228
  let deferred1_1;
2321
3229
  try {
2322
- const ret = wasm.signindeeplink_baseRelayUrl(this.__wbg_ptr);
3230
+ const ret = wasm.signupdeeplink_baseRelayUrl(this.__wbg_ptr);
2323
3231
  deferred1_0 = ret[0];
2324
3232
  deferred1_1 = ret[1];
2325
3233
  return getStringFromWasm0(ret[0], ret[1]);
@@ -2334,7 +3242,7 @@ class SigninDeepLink {
2334
3242
  let deferred1_0;
2335
3243
  let deferred1_1;
2336
3244
  try {
2337
- const ret = wasm.signindeeplink_capabilities(this.__wbg_ptr);
3245
+ const ret = wasm.signupdeeplink_capabilities(this.__wbg_ptr);
2338
3246
  deferred1_0 = ret[0];
2339
3247
  deferred1_1 = ret[1];
2340
3248
  return getStringFromWasm0(ret[0], ret[1]);
@@ -2342,26 +3250,45 @@ class SigninDeepLink {
2342
3250
  wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
2343
3251
  }
2344
3252
  }
3253
+ /**
3254
+ * @returns {PublicKey}
3255
+ */
3256
+ get homeserver() {
3257
+ const ret = wasm.signupdeeplink_homeserver(this.__wbg_ptr);
3258
+ return PublicKey.__wrap(ret);
3259
+ }
2345
3260
  /**
2346
3261
  * @param {string} url
2347
- * @returns {SigninDeepLink}
3262
+ * @returns {SignupDeepLink}
2348
3263
  */
2349
3264
  static parse(url) {
2350
3265
  const ptr0 = passStringToWasm0(url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
2351
3266
  const len0 = WASM_VECTOR_LEN;
2352
- const ret = wasm.signindeeplink_parse(ptr0, len0);
3267
+ const ret = wasm.signupdeeplink_parse(ptr0, len0);
2353
3268
  if (ret[2]) {
2354
3269
  throw takeFromExternrefTable0(ret[1]);
2355
3270
  }
2356
- return SigninDeepLink.__wrap(ret[0]);
3271
+ return SignupDeepLink.__wrap(ret[0]);
2357
3272
  }
2358
3273
  /**
2359
3274
  * @returns {Uint8Array}
2360
3275
  */
2361
3276
  get secret() {
2362
- const ret = wasm.signindeeplink_secret(this.__wbg_ptr);
3277
+ const ret = wasm.signupdeeplink_secret(this.__wbg_ptr);
2363
3278
  return ret;
2364
3279
  }
3280
+ /**
3281
+ * @returns {string | undefined}
3282
+ */
3283
+ get signupToken() {
3284
+ const ret = wasm.signupdeeplink_signupToken(this.__wbg_ptr);
3285
+ let v1;
3286
+ if (ret[0] !== 0) {
3287
+ v1 = getStringFromWasm0(ret[0], ret[1]).slice();
3288
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
3289
+ }
3290
+ return v1;
3291
+ }
2365
3292
  /**
2366
3293
  * @returns {string}
2367
3294
  */
@@ -2369,7 +3296,7 @@ class SigninDeepLink {
2369
3296
  let deferred1_0;
2370
3297
  let deferred1_1;
2371
3298
  try {
2372
- const ret = wasm.signindeeplink_toString(this.__wbg_ptr);
3299
+ const ret = wasm.signupdeeplink_toString(this.__wbg_ptr);
2373
3300
  deferred1_0 = ret[0];
2374
3301
  deferred1_1 = ret[1];
2375
3302
  return getStringFromWasm0(ret[0], ret[1]);
@@ -2378,35 +3305,44 @@ class SigninDeepLink {
2378
3305
  }
2379
3306
  }
2380
3307
  }
2381
- if (Symbol.dispose) SigninDeepLink.prototype[Symbol.dispose] = SigninDeepLink.prototype.free;
2382
- exports.SigninDeepLink = SigninDeepLink;
3308
+ if (Symbol.dispose) SignupDeepLink.prototype[Symbol.dispose] = SignupDeepLink.prototype.free;
3309
+ exports.SignupDeepLink = SignupDeepLink;
2383
3310
 
2384
- class SignupDeepLink {
3311
+ /**
3312
+ * Parsed grant-based signup deeplink.
3313
+ *
3314
+ * This is useful for tools, tests, and signer UIs that need to inspect a
3315
+ * `pubky://signup-grant` authorization URL before approving it.
3316
+ */
3317
+ class SignupGrantDeepLink {
2385
3318
  static __wrap(ptr) {
2386
3319
  ptr = ptr >>> 0;
2387
- const obj = Object.create(SignupDeepLink.prototype);
3320
+ const obj = Object.create(SignupGrantDeepLink.prototype);
2388
3321
  obj.__wbg_ptr = ptr;
2389
- SignupDeepLinkFinalization.register(obj, obj.__wbg_ptr, obj);
3322
+ SignupGrantDeepLinkFinalization.register(obj, obj.__wbg_ptr, obj);
2390
3323
  return obj;
2391
3324
  }
2392
3325
  __destroy_into_raw() {
2393
3326
  const ptr = this.__wbg_ptr;
2394
3327
  this.__wbg_ptr = 0;
2395
- SignupDeepLinkFinalization.unregister(this);
3328
+ SignupGrantDeepLinkFinalization.unregister(this);
2396
3329
  return ptr;
2397
3330
  }
2398
3331
  free() {
2399
3332
  const ptr = this.__destroy_into_raw();
2400
- wasm.__wbg_signupdeeplink_free(ptr, 0);
3333
+ wasm.__wbg_signupgrantdeeplink_free(ptr, 0);
2401
3334
  }
2402
3335
  /**
3336
+ * Base HTTP relay inbox URL used by this auth request.
3337
+ *
3338
+ * @returns {string}
2403
3339
  * @returns {string}
2404
3340
  */
2405
3341
  get baseRelayUrl() {
2406
3342
  let deferred1_0;
2407
3343
  let deferred1_1;
2408
3344
  try {
2409
- const ret = wasm.signupdeeplink_baseRelayUrl(this.__wbg_ptr);
3345
+ const ret = wasm.signupgrantdeeplink_baseRelayUrl(this.__wbg_ptr);
2410
3346
  deferred1_0 = ret[0];
2411
3347
  deferred1_1 = ret[1];
2412
3348
  return getStringFromWasm0(ret[0], ret[1]);
@@ -2415,13 +3351,34 @@ class SignupDeepLink {
2415
3351
  }
2416
3352
  }
2417
3353
  /**
3354
+ * Capabilities requested by the application.
3355
+ *
3356
+ * @returns {string}
2418
3357
  * @returns {string}
2419
3358
  */
2420
3359
  get capabilities() {
2421
3360
  let deferred1_0;
2422
3361
  let deferred1_1;
2423
3362
  try {
2424
- const ret = wasm.signupdeeplink_capabilities(this.__wbg_ptr);
3363
+ const ret = wasm.signupgrantdeeplink_capabilities(this.__wbg_ptr);
3364
+ deferred1_0 = ret[0];
3365
+ deferred1_1 = ret[1];
3366
+ return getStringFromWasm0(ret[0], ret[1]);
3367
+ } finally {
3368
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
3369
+ }
3370
+ }
3371
+ /**
3372
+ * Application identifier shown in the user's grant/session list.
3373
+ *
3374
+ * @returns {string}
3375
+ * @returns {string}
3376
+ */
3377
+ get clientId() {
3378
+ let deferred1_0;
3379
+ let deferred1_1;
3380
+ try {
3381
+ const ret = wasm.signupgrantdeeplink_clientId(this.__wbg_ptr);
2425
3382
  deferred1_0 = ret[0];
2426
3383
  deferred1_1 = ret[1];
2427
3384
  return getStringFromWasm0(ret[0], ret[1]);
@@ -2430,37 +3387,63 @@ class SignupDeepLink {
2430
3387
  }
2431
3388
  }
2432
3389
  /**
3390
+ * Public key for the Proof-of-Possession client created by the application.
3391
+ *
3392
+ * @returns {PublicKey}
3393
+ * @returns {PublicKey}
3394
+ */
3395
+ get clientPublicKey() {
3396
+ const ret = wasm.signupgrantdeeplink_clientPublicKey(this.__wbg_ptr);
3397
+ return PublicKey.__wrap(ret);
3398
+ }
3399
+ /**
3400
+ * Homeserver public key requested for account creation.
3401
+ *
3402
+ * @returns {PublicKey}
2433
3403
  * @returns {PublicKey}
2434
3404
  */
2435
3405
  get homeserver() {
2436
- const ret = wasm.signupdeeplink_homeserver(this.__wbg_ptr);
3406
+ const ret = wasm.signupgrantdeeplink_homeserver(this.__wbg_ptr);
2437
3407
  return PublicKey.__wrap(ret);
2438
3408
  }
2439
3409
  /**
3410
+ * Parse a grant signup deeplink URL.
3411
+ *
2440
3412
  * @param {string} url
2441
- * @returns {SignupDeepLink}
3413
+ * @returns {SignupGrantDeepLink}
3414
+ * @throws {PubkyError} `InvalidInput` when the URL is malformed or not a grant signup link.
3415
+ * @param {string} url
3416
+ * @returns {SignupGrantDeepLink}
2442
3417
  */
2443
3418
  static parse(url) {
2444
3419
  const ptr0 = passStringToWasm0(url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
2445
3420
  const len0 = WASM_VECTOR_LEN;
2446
- const ret = wasm.signupdeeplink_parse(ptr0, len0);
3421
+ const ret = wasm.signupgrantdeeplink_parse(ptr0, len0);
2447
3422
  if (ret[2]) {
2448
3423
  throw takeFromExternrefTable0(ret[1]);
2449
3424
  }
2450
- return SignupDeepLink.__wrap(ret[0]);
3425
+ return SignupGrantDeepLink.__wrap(ret[0]);
2451
3426
  }
2452
3427
  /**
3428
+ * Relay channel secret embedded in the deeplink.
3429
+ *
3430
+ * Treat this as sensitive temporary auth-flow material.
3431
+ *
3432
+ * @returns {Uint8Array}
2453
3433
  * @returns {Uint8Array}
2454
3434
  */
2455
3435
  get secret() {
2456
- const ret = wasm.signupdeeplink_secret(this.__wbg_ptr);
3436
+ const ret = wasm.signupgrantdeeplink_secret(this.__wbg_ptr);
2457
3437
  return ret;
2458
3438
  }
2459
3439
  /**
3440
+ * Optional signup token included in the request.
3441
+ *
3442
+ * @returns {string|undefined}
2460
3443
  * @returns {string | undefined}
2461
3444
  */
2462
3445
  get signupToken() {
2463
- const ret = wasm.signupdeeplink_signupToken(this.__wbg_ptr);
3446
+ const ret = wasm.signupgrantdeeplink_signupToken(this.__wbg_ptr);
2464
3447
  let v1;
2465
3448
  if (ret[0] !== 0) {
2466
3449
  v1 = getStringFromWasm0(ret[0], ret[1]).slice();
@@ -2469,13 +3452,16 @@ class SignupDeepLink {
2469
3452
  return v1;
2470
3453
  }
2471
3454
  /**
3455
+ * Serialize this parsed deeplink back to its URL form.
3456
+ *
3457
+ * @returns {string}
2472
3458
  * @returns {string}
2473
3459
  */
2474
3460
  toString() {
2475
3461
  let deferred1_0;
2476
3462
  let deferred1_1;
2477
3463
  try {
2478
- const ret = wasm.signupdeeplink_toString(this.__wbg_ptr);
3464
+ const ret = wasm.signupgrantdeeplink_toString(this.__wbg_ptr);
2479
3465
  deferred1_0 = ret[0];
2480
3466
  deferred1_1 = ret[1];
2481
3467
  return getStringFromWasm0(ret[0], ret[1]);
@@ -2484,8 +3470,8 @@ class SignupDeepLink {
2484
3470
  }
2485
3471
  }
2486
3472
  }
2487
- if (Symbol.dispose) SignupDeepLink.prototype[Symbol.dispose] = SignupDeepLink.prototype.free;
2488
- exports.SignupDeepLink = SignupDeepLink;
3473
+ if (Symbol.dispose) SignupGrantDeepLink.prototype[Symbol.dispose] = SignupGrantDeepLink.prototype.free;
3474
+ exports.SignupGrantDeepLink = SignupGrantDeepLink;
2489
3475
 
2490
3476
  /**
2491
3477
  * Resolve a `pubky://` or `pubky<pk>/…` identifier into the homeserver transport URL.
@@ -2723,7 +3709,7 @@ function __wbg_get_imports() {
2723
3709
  const ret = arg0.catch(arg1);
2724
3710
  return ret;
2725
3711
  },
2726
- __wbg_clearTimeout_2256f1e7b94ef517: function(arg0) {
3712
+ __wbg_clearTimeout_333bba87532ab9d3: function(arg0) {
2727
3713
  const ret = clearTimeout(arg0);
2728
3714
  return ret;
2729
3715
  },
@@ -2762,15 +3748,15 @@ function __wbg_get_imports() {
2762
3748
  const ret = Event.__wrap(arg0);
2763
3749
  return ret;
2764
3750
  },
2765
- __wbg_fetch_0d322c0aed196b8b: function(arg0, arg1) {
2766
- const ret = arg0.fetch(arg1);
3751
+ __wbg_fetch_074561c3e313c86f: function(arg0) {
3752
+ const ret = fetch(arg0);
2767
3753
  return ret;
2768
3754
  },
2769
- __wbg_fetch_2886d266cfda795f: function(arg0) {
2770
- const ret = fetch(arg0);
3755
+ __wbg_fetch_0d322c0aed196b8b: function(arg0, arg1) {
3756
+ const ret = arg0.fetch(arg1);
2771
3757
  return ret;
2772
3758
  },
2773
- __wbg_fetch_43b2f110608a59ff: function(arg0) {
3759
+ __wbg_fetch_95042ac3d1e49f53: function(arg0) {
2774
3760
  const ret = fetch(arg0);
2775
3761
  return ret;
2776
3762
  },
@@ -2812,6 +3798,14 @@ function __wbg_get_imports() {
2812
3798
  const ret = arg0.value;
2813
3799
  return ret;
2814
3800
  },
3801
+ __wbg_grantinfo_new: function(arg0) {
3802
+ const ret = GrantInfo.__wrap(arg0);
3803
+ return ret;
3804
+ },
3805
+ __wbg_grantsessioninfo_new: function(arg0) {
3806
+ const ret = GrantSessionInfo.__wrap(arg0);
3807
+ return ret;
3808
+ },
2815
3809
  __wbg_has_880f1d472f7cecba: function() { return handleError(function (arg0, arg1) {
2816
3810
  const ret = Reflect.has(arg0, arg1);
2817
3811
  return ret;
@@ -3051,7 +4045,7 @@ function __wbg_get_imports() {
3051
4045
  const ret = Session.__wrap(arg0);
3052
4046
  return ret;
3053
4047
  },
3054
- __wbg_setTimeout_b188b3bcc8977c7d: function(arg0, arg1) {
4048
+ __wbg_setTimeout_3a808dd861dd3c12: function(arg0, arg1) {
3055
4049
  const ret = setTimeout(arg0, arg1);
3056
4050
  return ret;
3057
4051
  },
@@ -3182,18 +4176,18 @@ function __wbg_get_imports() {
3182
4176
  console.warn(arg0, arg1, arg2, arg3);
3183
4177
  },
3184
4178
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
3185
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 209, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
3186
- const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__hde4a3c4bb985e67d);
4179
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 127, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
4180
+ const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__ha6e3ae977799a830);
3187
4181
  return ret;
3188
4182
  },
3189
4183
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
3190
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 99, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
3191
- const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__ha6e3ae977799a830);
4184
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 240, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
4185
+ const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__hde4a3c4bb985e67d);
3192
4186
  return ret;
3193
4187
  },
3194
4188
  __wbindgen_cast_0000000000000003: function(arg0, arg1) {
3195
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 206, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
3196
- const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__hde4b18e0209e0218);
4189
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 237, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
4190
+ const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h8579194ccdaf276b);
3197
4191
  return ret;
3198
4192
  },
3199
4193
  __wbindgen_cast_0000000000000004: function(arg0) {
@@ -3222,6 +4216,13 @@ function __wbg_get_imports() {
3222
4216
  return ret;
3223
4217
  },
3224
4218
  __wbindgen_cast_0000000000000009: function(arg0, arg1) {
4219
+ var v0 = getArrayJsValueFromWasm0(arg0, arg1).slice();
4220
+ wasm.__wbindgen_free(arg0, arg1 * 4, 4);
4221
+ // Cast intrinsic for `Vector(NamedExternref("GrantInfo")) -> Externref`.
4222
+ const ret = v0;
4223
+ return ret;
4224
+ },
4225
+ __wbindgen_cast_000000000000000a: function(arg0, arg1) {
3225
4226
  var v0 = getArrayJsValueFromWasm0(arg0, arg1).slice();
3226
4227
  wasm.__wbindgen_free(arg0, arg1 * 4, 4);
3227
4228
  // Cast intrinsic for `Vector(NamedExternref("string")) -> Externref`.
@@ -3244,8 +4245,8 @@ function __wbg_get_imports() {
3244
4245
  };
3245
4246
  }
3246
4247
 
3247
- function wasm_bindgen__convert__closures_____invoke__hde4b18e0209e0218(arg0, arg1) {
3248
- wasm.wasm_bindgen__convert__closures_____invoke__hde4b18e0209e0218(arg0, arg1);
4248
+ function wasm_bindgen__convert__closures_____invoke__h8579194ccdaf276b(arg0, arg1) {
4249
+ wasm.wasm_bindgen__convert__closures_____invoke__h8579194ccdaf276b(arg0, arg1);
3249
4250
  }
3250
4251
 
3251
4252
  function wasm_bindgen__convert__closures_____invoke__hde4a3c4bb985e67d(arg0, arg1, arg2) {
@@ -3289,12 +4290,30 @@ const AuthTokenFinalization = (typeof FinalizationRegistry === 'undefined')
3289
4290
  const ClientFinalization = (typeof FinalizationRegistry === 'undefined')
3290
4291
  ? { register: () => {}, unregister: () => {} }
3291
4292
  : new FinalizationRegistry(ptr => wasm.__wbg_client_free(ptr >>> 0, 1));
4293
+ const CookieSessionFinalization = (typeof FinalizationRegistry === 'undefined')
4294
+ ? { register: () => {}, unregister: () => {} }
4295
+ : new FinalizationRegistry(ptr => wasm.__wbg_cookiesession_free(ptr >>> 0, 1));
3292
4296
  const EventFinalization = (typeof FinalizationRegistry === 'undefined')
3293
4297
  ? { register: () => {}, unregister: () => {} }
3294
4298
  : new FinalizationRegistry(ptr => wasm.__wbg_event_free(ptr >>> 0, 1));
3295
4299
  const EventStreamBuilderFinalization = (typeof FinalizationRegistry === 'undefined')
3296
4300
  ? { register: () => {}, unregister: () => {} }
3297
4301
  : new FinalizationRegistry(ptr => wasm.__wbg_eventstreambuilder_free(ptr >>> 0, 1));
4302
+ const GrantAuthFlowFinalization = (typeof FinalizationRegistry === 'undefined')
4303
+ ? { register: () => {}, unregister: () => {} }
4304
+ : new FinalizationRegistry(ptr => wasm.__wbg_grantauthflow_free(ptr >>> 0, 1));
4305
+ const GrantInfoFinalization = (typeof FinalizationRegistry === 'undefined')
4306
+ ? { register: () => {}, unregister: () => {} }
4307
+ : new FinalizationRegistry(ptr => wasm.__wbg_grantinfo_free(ptr >>> 0, 1));
4308
+ const GrantManagerFinalization = (typeof FinalizationRegistry === 'undefined')
4309
+ ? { register: () => {}, unregister: () => {} }
4310
+ : new FinalizationRegistry(ptr => wasm.__wbg_grantmanager_free(ptr >>> 0, 1));
4311
+ const GrantSessionFinalization = (typeof FinalizationRegistry === 'undefined')
4312
+ ? { register: () => {}, unregister: () => {} }
4313
+ : new FinalizationRegistry(ptr => wasm.__wbg_grantsession_free(ptr >>> 0, 1));
4314
+ const GrantSessionInfoFinalization = (typeof FinalizationRegistry === 'undefined')
4315
+ ? { register: () => {}, unregister: () => {} }
4316
+ : new FinalizationRegistry(ptr => wasm.__wbg_grantsessioninfo_free(ptr >>> 0, 1));
3298
4317
  const IntoUnderlyingByteSourceFinalization = (typeof FinalizationRegistry === 'undefined')
3299
4318
  ? { register: () => {}, unregister: () => {} }
3300
4319
  : new FinalizationRegistry(ptr => wasm.__wbg_intounderlyingbytesource_free(ptr >>> 0, 1));
@@ -3340,9 +4359,15 @@ const SignerFinalization = (typeof FinalizationRegistry === 'undefined')
3340
4359
  const SigninDeepLinkFinalization = (typeof FinalizationRegistry === 'undefined')
3341
4360
  ? { register: () => {}, unregister: () => {} }
3342
4361
  : new FinalizationRegistry(ptr => wasm.__wbg_signindeeplink_free(ptr >>> 0, 1));
4362
+ const SigninGrantDeepLinkFinalization = (typeof FinalizationRegistry === 'undefined')
4363
+ ? { register: () => {}, unregister: () => {} }
4364
+ : new FinalizationRegistry(ptr => wasm.__wbg_signingrantdeeplink_free(ptr >>> 0, 1));
3343
4365
  const SignupDeepLinkFinalization = (typeof FinalizationRegistry === 'undefined')
3344
4366
  ? { register: () => {}, unregister: () => {} }
3345
4367
  : new FinalizationRegistry(ptr => wasm.__wbg_signupdeeplink_free(ptr >>> 0, 1));
4368
+ const SignupGrantDeepLinkFinalization = (typeof FinalizationRegistry === 'undefined')
4369
+ ? { register: () => {}, unregister: () => {} }
4370
+ : new FinalizationRegistry(ptr => wasm.__wbg_signupgrantdeeplink_free(ptr >>> 0, 1));
3346
4371
 
3347
4372
  function addToExternrefTable0(obj) {
3348
4373
  const idx = wasm.__externref_table_alloc();