@seed-hypermedia/client 0.0.102 → 0.0.104
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/dist/auth.mjs +20 -2
- package/dist/auto-link.mjs +2 -2
- package/dist/{chunk-TLOQU4IT.mjs → chunk-P2FJTNNQ.mjs} +1 -1
- package/dist/{chunk-Z5BSKGOF.mjs → chunk-R6OYID6M.mjs} +2 -1
- package/dist/{chunk-7PB3EULG.mjs → chunk-UBBSVXFC.mjs} +20 -0
- package/dist/document-state.d.ts +2 -0
- package/dist/document-state.mjs +1 -1
- package/dist/hmauth.d.ts +17 -0
- package/dist/hmauth.mjs +5 -1
- package/dist/index.mjs +2 -2
- package/package.json +1 -1
package/dist/auth.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
PARAM_CLIENT_ID,
|
|
3
3
|
PARAM_DATA,
|
|
4
4
|
PARAM_EMAIL,
|
|
5
|
+
PARAM_EMAIL_PREVALIDATION,
|
|
5
6
|
PARAM_ERROR,
|
|
6
7
|
PARAM_PROOF,
|
|
7
8
|
PARAM_REDIRECT_URI,
|
|
@@ -9,9 +10,10 @@ import {
|
|
|
9
10
|
PARAM_SITE_NAME,
|
|
10
11
|
PARAM_STATE,
|
|
11
12
|
PARAM_TS,
|
|
13
|
+
parseEmailPrevalidation,
|
|
12
14
|
validateClientId,
|
|
13
15
|
validateRedirectUri
|
|
14
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-UBBSVXFC.mjs";
|
|
15
17
|
import {
|
|
16
18
|
decode,
|
|
17
19
|
encode
|
|
@@ -152,6 +154,7 @@ async function startAuth(config, options = {}) {
|
|
|
152
154
|
url.searchParams.set(PARAM_SESSION_KEY, session.principal);
|
|
153
155
|
url.searchParams.set(PARAM_STATE, authState);
|
|
154
156
|
url.searchParams.set(PARAM_TS, String(authStartTime));
|
|
157
|
+
if (config.requestEmailPrevalidation) url.searchParams.set(PARAM_EMAIL_PREVALIDATION, "1");
|
|
155
158
|
if (config.email) url.searchParams.set(PARAM_EMAIL, config.email);
|
|
156
159
|
if (config.siteName) url.searchParams.set(PARAM_SITE_NAME, config.siteName);
|
|
157
160
|
const signedUrl = url.toString();
|
|
@@ -161,6 +164,13 @@ async function startAuth(config, options = {}) {
|
|
|
161
164
|
}
|
|
162
165
|
async function handleCallback(config, options = {}) {
|
|
163
166
|
const url = new URL(window.location.href);
|
|
167
|
+
const fragment = new URLSearchParams(url.hash.slice(1));
|
|
168
|
+
const emailProof = fragment.get(PARAM_EMAIL_PREVALIDATION);
|
|
169
|
+
if (fragment.has(PARAM_EMAIL_PREVALIDATION)) {
|
|
170
|
+
fragment.delete(PARAM_EMAIL_PREVALIDATION);
|
|
171
|
+
url.hash = fragment.toString();
|
|
172
|
+
window.history.replaceState(window.history.state, "", url.toString());
|
|
173
|
+
}
|
|
164
174
|
const dataParam = url.searchParams.get(PARAM_DATA);
|
|
165
175
|
const stateParam = url.searchParams.get(PARAM_STATE);
|
|
166
176
|
const error = url.searchParams.get(PARAM_ERROR);
|
|
@@ -221,13 +231,21 @@ async function handleCallback(config, options = {}) {
|
|
|
221
231
|
if (callbackData.profile && !principalEqual(callbackData.account, callbackData.profile.signer)) {
|
|
222
232
|
throw new Error("Callback account does not match profile signer");
|
|
223
233
|
}
|
|
234
|
+
let emailPrevalidation;
|
|
235
|
+
if (emailProof) {
|
|
236
|
+
try {
|
|
237
|
+
emailPrevalidation = parseEmailPrevalidation(decode2(decode(emailProof)), vaultUrl);
|
|
238
|
+
} catch {
|
|
239
|
+
}
|
|
240
|
+
}
|
|
224
241
|
await store.put(vaultUrl, { ...record, authState: null, authStartTime: null });
|
|
225
242
|
return {
|
|
226
243
|
accountPrincipal: principalToString(callbackData.account),
|
|
227
244
|
capability,
|
|
228
245
|
...profile ? { profile } : {},
|
|
229
246
|
session,
|
|
230
|
-
notifyServerUrl
|
|
247
|
+
notifyServerUrl,
|
|
248
|
+
...emailPrevalidation ? { emailPrevalidation } : {}
|
|
231
249
|
};
|
|
232
250
|
}
|
|
233
251
|
async function getSession(vaultUrl, options = {}) {
|
package/dist/auto-link.mjs
CHANGED
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
documentContainsLinkToChild,
|
|
5
5
|
documentHasSelfQuery,
|
|
6
6
|
shouldAutoLinkParent
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-P2FJTNNQ.mjs";
|
|
8
8
|
import "./chunk-O5MHN2EO.mjs";
|
|
9
9
|
import "./chunk-PJ2RFT5A.mjs";
|
|
10
|
-
import "./chunk-
|
|
10
|
+
import "./chunk-R6OYID6M.mjs";
|
|
11
11
|
import "./chunk-LVAHHQIK.mjs";
|
|
12
12
|
import "./chunk-DR3HJ6BV.mjs";
|
|
13
13
|
import "./chunk-SKIKB2TP.mjs";
|
|
@@ -93,7 +93,8 @@ async function followToDocument(client, id) {
|
|
|
93
93
|
id,
|
|
94
94
|
targetId: followed.targetId,
|
|
95
95
|
document: followed.resource.document,
|
|
96
|
-
redirect: first ? { republish: first.republish, target: first.to } : null
|
|
96
|
+
redirect: first ? { republish: first.republish, target: first.to } : null,
|
|
97
|
+
redirects: followed.redirects
|
|
97
98
|
};
|
|
98
99
|
}
|
|
99
100
|
async function resolveEditableDocument(client, id) {
|
|
@@ -14,6 +14,23 @@ import {
|
|
|
14
14
|
} from "./chunk-3TPCJCVO.mjs";
|
|
15
15
|
|
|
16
16
|
// src/hmauth.ts
|
|
17
|
+
function parseEmailPrevalidation(value, vaultUrl) {
|
|
18
|
+
if (!value || typeof value !== "object") return void 0;
|
|
19
|
+
const proof = value;
|
|
20
|
+
if (typeof proof.email !== "string" || !proof.email || typeof proof.host !== "string" || typeof proof.signer !== "string" || typeof proof.sig !== "string")
|
|
21
|
+
return void 0;
|
|
22
|
+
try {
|
|
23
|
+
if (proof.host !== new URL(vaultUrl).origin) return void 0;
|
|
24
|
+
const signer = decode(proof.signer);
|
|
25
|
+
const signature = decode(proof.sig);
|
|
26
|
+
if (signer.length !== ED25519_VARINT_PREFIX.length + 32 || !ED25519_VARINT_PREFIX.every((byte, index) => signer[index] === byte) || signature.length !== 64)
|
|
27
|
+
return void 0;
|
|
28
|
+
return { email: proof.email, host: proof.host, signer: proof.signer, sig: proof.sig };
|
|
29
|
+
} catch {
|
|
30
|
+
return void 0;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
var PARAM_EMAIL_PREVALIDATION = "email_prevalidation";
|
|
17
34
|
var PARAM_CLIENT_ID = "client_id";
|
|
18
35
|
var PARAM_REDIRECT_URI = "redirect_uri";
|
|
19
36
|
var PARAM_SESSION_KEY = "session_key";
|
|
@@ -189,6 +206,7 @@ function parseDelegationRequest(url) {
|
|
|
189
206
|
const siteName = parsedUrl.searchParams.get(PARAM_SITE_NAME) || void 0;
|
|
190
207
|
return {
|
|
191
208
|
originalUrl,
|
|
209
|
+
emailPrevalidation: parsedUrl.searchParams.get(PARAM_EMAIL_PREVALIDATION) === "1",
|
|
192
210
|
clientId,
|
|
193
211
|
redirectUri,
|
|
194
212
|
sessionKeyPrincipal: sessionKey,
|
|
@@ -264,6 +282,8 @@ async function createDelegation(issuer, sessionKeyPrincipal, clientId) {
|
|
|
264
282
|
}
|
|
265
283
|
|
|
266
284
|
export {
|
|
285
|
+
parseEmailPrevalidation,
|
|
286
|
+
PARAM_EMAIL_PREVALIDATION,
|
|
267
287
|
PARAM_CLIENT_ID,
|
|
268
288
|
PARAM_REDIRECT_URI,
|
|
269
289
|
PARAM_SESSION_KEY,
|
package/dist/document-state.d.ts
CHANGED
|
@@ -39,6 +39,8 @@ export type FollowedDocument = {
|
|
|
39
39
|
republish: boolean;
|
|
40
40
|
target: UnpackedHypermediaId;
|
|
41
41
|
} | null;
|
|
42
|
+
/** Every redirect followed from `id` to `targetId`, in order. */
|
|
43
|
+
redirects: RedirectHop[];
|
|
42
44
|
};
|
|
43
45
|
/** The full baseline needed to build a new Change at an address: {@link FollowedDocument} plus DAG state. */
|
|
44
46
|
export type EditableDocumentBase = FollowedDocument & {
|
package/dist/document-state.mjs
CHANGED
package/dist/hmauth.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ export interface HypermediaAuthConfig {
|
|
|
22
22
|
email?: string;
|
|
23
23
|
/** Optional display name of this site, shown in the vault's consent UI. */
|
|
24
24
|
siteName?: string;
|
|
25
|
+
/** Ask Vault to share verified email proof after consent. Disabled by default. */
|
|
26
|
+
requestEmailPrevalidation?: boolean;
|
|
25
27
|
}
|
|
26
28
|
/** Stored session key with metadata. */
|
|
27
29
|
export interface StoredSession {
|
|
@@ -56,7 +58,20 @@ export interface AuthResult {
|
|
|
56
58
|
session: StoredSession;
|
|
57
59
|
/** Notification server URL configured by the vault (optional). */
|
|
58
60
|
notifyServerUrl?: string;
|
|
61
|
+
/** Optional Vault email proof, delivered separately from public callback data. */
|
|
62
|
+
emailPrevalidation?: EmailPrevalidation;
|
|
59
63
|
}
|
|
64
|
+
/** Vault-signed email proof; the receiving service still verifies its signature and trusted issuer. */
|
|
65
|
+
export interface EmailPrevalidation {
|
|
66
|
+
email: string;
|
|
67
|
+
signer: string;
|
|
68
|
+
host: string;
|
|
69
|
+
sig: string;
|
|
70
|
+
}
|
|
71
|
+
/** Validate optional transported email proof without turning malformed metadata into a failed sign-in. */
|
|
72
|
+
export declare function parseEmailPrevalidation(value: unknown, vaultUrl: string): EmailPrevalidation | undefined;
|
|
73
|
+
/** Signed request opt-in and callback fragment key for private email proof transport. */
|
|
74
|
+
export declare const PARAM_EMAIL_PREVALIDATION = "email_prevalidation";
|
|
60
75
|
/** URL parameter name for the client ID (origin of the requesting site). */
|
|
61
76
|
export declare const PARAM_CLIENT_ID = "client_id";
|
|
62
77
|
/** URL parameter name for the redirect URI. */
|
|
@@ -87,6 +102,8 @@ export declare function principalDecode(principal: string): Uint8Array;
|
|
|
87
102
|
export interface DelegationRequest {
|
|
88
103
|
/** Original delegation request URL as received by the vault, including `proof`. */
|
|
89
104
|
originalUrl: string;
|
|
105
|
+
/** Client can consume email proof from the callback fragment without leaking it to HTTP requests. */
|
|
106
|
+
emailPrevalidation?: boolean;
|
|
90
107
|
/** The origin of the requesting site (must be HTTPS). e.g. "https://example.com". */
|
|
91
108
|
clientId: string;
|
|
92
109
|
/** Where to redirect after delegation. Must be a strict extension of clientId. */
|
package/dist/hmauth.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
PARAM_CLIENT_ID,
|
|
4
4
|
PARAM_DATA,
|
|
5
5
|
PARAM_EMAIL,
|
|
6
|
+
PARAM_EMAIL_PREVALIDATION,
|
|
6
7
|
PARAM_ERROR,
|
|
7
8
|
PARAM_PROOF,
|
|
8
9
|
PARAM_REDIRECT_URI,
|
|
@@ -13,6 +14,7 @@ import {
|
|
|
13
14
|
buildCallbackUrl,
|
|
14
15
|
createDelegation,
|
|
15
16
|
parseDelegationRequest,
|
|
17
|
+
parseEmailPrevalidation,
|
|
16
18
|
principalDecode,
|
|
17
19
|
principalEncode,
|
|
18
20
|
validateClientId,
|
|
@@ -21,7 +23,7 @@ import {
|
|
|
21
23
|
validateSessionKeyPrincipal,
|
|
22
24
|
validateState,
|
|
23
25
|
verifyDelegationRequestProof
|
|
24
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-UBBSVXFC.mjs";
|
|
25
27
|
import "./chunk-2MD3FXKB.mjs";
|
|
26
28
|
import "./chunk-NBCHK76Q.mjs";
|
|
27
29
|
import "./chunk-DR3HJ6BV.mjs";
|
|
@@ -32,6 +34,7 @@ export {
|
|
|
32
34
|
PARAM_CLIENT_ID,
|
|
33
35
|
PARAM_DATA,
|
|
34
36
|
PARAM_EMAIL,
|
|
37
|
+
PARAM_EMAIL_PREVALIDATION,
|
|
35
38
|
PARAM_ERROR,
|
|
36
39
|
PARAM_PROOF,
|
|
37
40
|
PARAM_REDIRECT_URI,
|
|
@@ -42,6 +45,7 @@ export {
|
|
|
42
45
|
buildCallbackUrl,
|
|
43
46
|
createDelegation,
|
|
44
47
|
parseDelegationRequest,
|
|
48
|
+
parseEmailPrevalidation,
|
|
45
49
|
principalDecode,
|
|
46
50
|
principalEncode,
|
|
47
51
|
validateClientId,
|
package/dist/index.mjs
CHANGED
|
@@ -83,7 +83,7 @@ import {
|
|
|
83
83
|
documentContainsLinkToChild,
|
|
84
84
|
documentHasSelfQuery,
|
|
85
85
|
shouldAutoLinkParent
|
|
86
|
-
} from "./chunk-
|
|
86
|
+
} from "./chunk-P2FJTNNQ.mjs";
|
|
87
87
|
import {
|
|
88
88
|
createChange,
|
|
89
89
|
createChangeOps,
|
|
@@ -105,7 +105,7 @@ import {
|
|
|
105
105
|
followToDocument,
|
|
106
106
|
resolveDocumentState,
|
|
107
107
|
resolveEditableDocument
|
|
108
|
-
} from "./chunk-
|
|
108
|
+
} from "./chunk-R6OYID6M.mjs";
|
|
109
109
|
import "./chunk-2MD3FXKB.mjs";
|
|
110
110
|
import {
|
|
111
111
|
computeReplaceOps,
|