@prson/login-sdk 0.1.0 → 0.2.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 +18 -2
- package/dist/api.js +3 -2
- package/dist/csp.d.ts +39 -0
- package/dist/csp.js +125 -0
- package/dist/errors.d.ts +40 -0
- package/dist/errors.js +28 -0
- package/dist/index.d.ts +32 -14
- package/dist/index.js +207 -31
- package/dist/index.js.map +3 -3
- package/dist/point_phone_overlay.js +4 -0
- package/dist/select_overlay.js +4 -0
- package/dist/session.d.ts +8 -2
- package/dist/session.js +21 -2
- package/dist/signaling.d.ts +0 -10
- package/dist/signaling.js +4 -3
- package/dist/transport.d.ts +17 -12
- package/dist/transport.js +39 -10
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2871,8 +2871,11 @@ var PrsonLoginSession = class {
|
|
|
2871
2871
|
* True when the sign-in presentation didn't bind a session key (a
|
|
2872
2872
|
* wallet older than envelope v2). The sender of inbound envelopes
|
|
2873
2873
|
* can't be checked then, so envelopes that act on the page (`nav`,
|
|
2874
|
-
* `value`, `mouse-update`, file transfer)
|
|
2875
|
-
*
|
|
2874
|
+
* `value`, `mouse-update`, file transfer) and request replies
|
|
2875
|
+
* (`response`) are ignored, `request()` resolves with
|
|
2876
|
+
* `{ ok: false, error: "unsupported" }` and no field values are sent
|
|
2877
|
+
* (`focus`). Sign-in, renewals and claim updates (all verified
|
|
2878
|
+
* presentations) and sign-out still work. See SECURITY.md §4.
|
|
2876
2879
|
*/
|
|
2877
2880
|
this._legacyChannel = false;
|
|
2878
2881
|
/** `iat` of the newest verified presentation (sign-in or renewal).
|
|
@@ -3137,6 +3140,9 @@ var PrsonLoginSession = class {
|
|
|
3137
3140
|
* replied. Defaults to 60 s.
|
|
3138
3141
|
* * `session-closed` — the session shut down with this request
|
|
3139
3142
|
* in flight.
|
|
3143
|
+
* * `unsupported` — the wallet predates envelope v2 (it bound no
|
|
3144
|
+
* session key into the sign-in), so its replies couldn't be told
|
|
3145
|
+
* apart from anyone else's. Nothing is sent to it.
|
|
3140
3146
|
*
|
|
3141
3147
|
* Wire grammar: outbound envelope shape is
|
|
3142
3148
|
* `{ v, msg: "request", issuedAt, domain, requestId, kind, ...kindFields }`,
|
|
@@ -3178,6 +3184,7 @@ var PrsonLoginSession = class {
|
|
|
3178
3184
|
async _sendFocus(focus) {
|
|
3179
3185
|
if (this._closed) return;
|
|
3180
3186
|
if (!this._walletSessionPk) return;
|
|
3187
|
+
if (this._legacyChannel) return;
|
|
3181
3188
|
await this._sendWithAck({
|
|
3182
3189
|
msg: "focus",
|
|
3183
3190
|
focus
|
|
@@ -3294,6 +3301,7 @@ var PrsonLoginSession = class {
|
|
|
3294
3301
|
}
|
|
3295
3302
|
async _sendRequest(req, opts, onMouseFrame) {
|
|
3296
3303
|
if (this._closed) return { ok: false, error: "session-closed" };
|
|
3304
|
+
if (this._legacyChannel) return { ok: false, error: "unsupported" };
|
|
3297
3305
|
const recipientPk = this._walletSessionPk;
|
|
3298
3306
|
if (!recipientPk) return { ok: false, error: "no-active-session" };
|
|
3299
3307
|
const timeoutMs = opts?.timeoutMs ?? 6e4;
|
|
@@ -3634,6 +3642,7 @@ var PrsonLoginSession = class {
|
|
|
3634
3642
|
this._handleCredentialRevoked(envelope);
|
|
3635
3643
|
return;
|
|
3636
3644
|
case "response":
|
|
3645
|
+
if (this._legacyChannel) return;
|
|
3637
3646
|
this._requestController.resolve(envelope);
|
|
3638
3647
|
if (envelope.requestId) this._mouseSubscribers.delete(envelope.requestId);
|
|
3639
3648
|
return;
|
|
@@ -3910,6 +3919,26 @@ function _deepEqual(a, b) {
|
|
|
3910
3919
|
}
|
|
3911
3920
|
}
|
|
3912
3921
|
|
|
3922
|
+
// src/errors.ts
|
|
3923
|
+
var PrsonLoginError = class extends Error {
|
|
3924
|
+
constructor(code, message, reason, cause) {
|
|
3925
|
+
super(message);
|
|
3926
|
+
this.name = "PrsonLoginError";
|
|
3927
|
+
this.code = code;
|
|
3928
|
+
if (reason !== void 0) this.reason = reason;
|
|
3929
|
+
if (cause !== void 0) this.cause = cause;
|
|
3930
|
+
}
|
|
3931
|
+
};
|
|
3932
|
+
function closedCode(reason) {
|
|
3933
|
+
return /expir/i.test(reason) ? "expired" : "network";
|
|
3934
|
+
}
|
|
3935
|
+
function asLoginError(e) {
|
|
3936
|
+
if (e instanceof PrsonLoginError) return e;
|
|
3937
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
3938
|
+
const code = /Failed to fetch|NetworkError|Load failed/i.test(message) ? "network" : "unknown";
|
|
3939
|
+
return new PrsonLoginError(code, message, void 0, e);
|
|
3940
|
+
}
|
|
3941
|
+
|
|
3913
3942
|
// src/api.ts
|
|
3914
3943
|
async function createDraft(request, opts = {}) {
|
|
3915
3944
|
const base = opts.signalingBase ?? SIGNALING_BASE;
|
|
@@ -3923,9 +3952,9 @@ async function createDraft(request, opts = {}) {
|
|
|
3923
3952
|
if (!res.ok) {
|
|
3924
3953
|
const text = await safeText(res);
|
|
3925
3954
|
if (res.status === 429) {
|
|
3926
|
-
throw new
|
|
3955
|
+
throw new PrsonLoginError("rate_limited", "Too many login sessions from this network \u2014 please retry shortly.");
|
|
3927
3956
|
}
|
|
3928
|
-
throw new
|
|
3957
|
+
throw new PrsonLoginError("network", `createDraft failed: HTTP ${res.status} ${text || res.statusText}`);
|
|
3929
3958
|
}
|
|
3930
3959
|
return await res.json();
|
|
3931
3960
|
}
|
|
@@ -3955,7 +3984,7 @@ async function connectSignaling(opts) {
|
|
|
3955
3984
|
const onErrorBefore = () => {
|
|
3956
3985
|
ws.removeEventListener("open", onOpen);
|
|
3957
3986
|
ws.removeEventListener("error", onErrorBefore);
|
|
3958
|
-
reject(new
|
|
3987
|
+
reject(new PrsonLoginError("network", "signaling: WS upgrade failed (auth?)"));
|
|
3959
3988
|
};
|
|
3960
3989
|
ws.addEventListener("open", onOpen);
|
|
3961
3990
|
ws.addEventListener("error", onErrorBefore);
|
|
@@ -3980,7 +4009,7 @@ async function connectSignaling(opts) {
|
|
|
3980
4009
|
ws.addEventListener("close", (evt) => {
|
|
3981
4010
|
const reason = evt.reason || `code-${evt.code}`;
|
|
3982
4011
|
closedReason = reason;
|
|
3983
|
-
for (const w of iceWaiters.splice(0)) w.reject(new
|
|
4012
|
+
for (const w of iceWaiters.splice(0)) w.reject(new PrsonLoginError(closedCode(reason), `signaling: closed before the code was claimed (${reason})`));
|
|
3984
4013
|
for (const cb of closeListeners) cb(reason);
|
|
3985
4014
|
});
|
|
3986
4015
|
return {
|
|
@@ -3997,7 +4026,7 @@ async function connectSignaling(opts) {
|
|
|
3997
4026
|
awaitIce() {
|
|
3998
4027
|
if (ice) return Promise.resolve(ice);
|
|
3999
4028
|
if (closedReason !== null) {
|
|
4000
|
-
return Promise.reject(new
|
|
4029
|
+
return Promise.reject(new PrsonLoginError(closedCode(closedReason), `signaling: closed before the code was claimed (${closedReason})`));
|
|
4001
4030
|
}
|
|
4002
4031
|
return new Promise((resolve, reject) => iceWaiters.push({ resolve, reject }));
|
|
4003
4032
|
},
|
|
@@ -4011,16 +4040,28 @@ async function connectSignaling(opts) {
|
|
|
4011
4040
|
}
|
|
4012
4041
|
|
|
4013
4042
|
// src/transport.ts
|
|
4014
|
-
function rtcConfigFor(iceServers) {
|
|
4043
|
+
function rtcConfigFor(iceServers, opts) {
|
|
4015
4044
|
const urls = (s) => Array.isArray(s.urls) ? s.urls : [s.urls];
|
|
4016
4045
|
const isTurn = (u) => /^turns?:/i.test(u);
|
|
4017
4046
|
const turn = iceServers.map((s) => ({ ...s, urls: urls(s).filter(isTurn) })).filter((s) => s.urls.length > 0);
|
|
4018
4047
|
if (turn.length > 0) return { iceServers: turn, iceTransportPolicy: "relay" };
|
|
4019
|
-
return { iceServers, iceTransportPolicy: "all" };
|
|
4048
|
+
if (opts?.allowDirect === true) return { iceServers, iceTransportPolicy: "all" };
|
|
4049
|
+
throw new PrsonLoginError("network", "transport: the relay sent no TURN server; refusing a direct connection");
|
|
4050
|
+
}
|
|
4051
|
+
function isLoopbackHost(hostname) {
|
|
4052
|
+
if (!hostname) return false;
|
|
4053
|
+
const h = hostname.toLowerCase().replace(/^\[|\]$/g, "");
|
|
4054
|
+
if (h === "localhost" || h.endsWith(".localhost")) return true;
|
|
4055
|
+
if (h === "::1") return true;
|
|
4056
|
+
return /^127(?:\.\d{1,3}){3}$/.test(h);
|
|
4057
|
+
}
|
|
4058
|
+
function pageIsLoopback() {
|
|
4059
|
+
const loc = globalThis.location;
|
|
4060
|
+
return isLoopbackHost(loc?.hostname);
|
|
4020
4061
|
}
|
|
4021
4062
|
var PEER_GONE_CONFIRM_MS = 6e3;
|
|
4022
4063
|
async function establishTransport(opts) {
|
|
4023
|
-
const pc = new RTCPeerConnection(rtcConfigFor(opts.iceServers));
|
|
4064
|
+
const pc = new RTCPeerConnection(rtcConfigFor(opts.iceServers, { allowDirect: pageIsLoopback() }));
|
|
4024
4065
|
const dc = pc.createDataChannel("prson-login", { ordered: true });
|
|
4025
4066
|
pc.addEventListener("icecandidate", (e) => {
|
|
4026
4067
|
if (e.candidate) opts.signaling.send({ msg: "candidate", candidate: e.candidate.toJSON() });
|
|
@@ -4073,7 +4114,7 @@ async function establishTransport(opts) {
|
|
|
4073
4114
|
const onError = () => {
|
|
4074
4115
|
dc.removeEventListener("open", onOpen);
|
|
4075
4116
|
dc.removeEventListener("error", onError);
|
|
4076
|
-
reject(new
|
|
4117
|
+
reject(new PrsonLoginError("network", "transport: data channel failed to open"));
|
|
4077
4118
|
};
|
|
4078
4119
|
dc.addEventListener("open", onOpen);
|
|
4079
4120
|
dc.addEventListener("error", onError);
|
|
@@ -4230,6 +4271,95 @@ function renderLoginQr(url, mount, theme, context) {
|
|
|
4230
4271
|
};
|
|
4231
4272
|
}
|
|
4232
4273
|
|
|
4274
|
+
// src/csp.ts
|
|
4275
|
+
var PRSON_CONNECT_SRC = [
|
|
4276
|
+
"https://signaling.prson.net",
|
|
4277
|
+
"wss://signaling.prson.net",
|
|
4278
|
+
"https://app.prson.net",
|
|
4279
|
+
"https://api.prson.net"
|
|
4280
|
+
];
|
|
4281
|
+
var PrsonCspError = class extends PrsonLoginError {
|
|
4282
|
+
constructor(directive, blockedUri, allow) {
|
|
4283
|
+
super(
|
|
4284
|
+
"csp_blocked",
|
|
4285
|
+
`This page's Content-Security-Policy blocked Prson sign-in: ${directive} doesn't allow ${blockedUri}. Add to connect-src: ${allow.join(" ")}`
|
|
4286
|
+
);
|
|
4287
|
+
this.name = "PrsonCspError";
|
|
4288
|
+
this.directive = directive;
|
|
4289
|
+
this.blockedUri = blockedUri;
|
|
4290
|
+
this.allow = allow;
|
|
4291
|
+
}
|
|
4292
|
+
};
|
|
4293
|
+
function connectSourcesFor(signalingBase, issuerJwksUri) {
|
|
4294
|
+
const out = /* @__PURE__ */ new Set();
|
|
4295
|
+
try {
|
|
4296
|
+
const u = new URL(signalingBase);
|
|
4297
|
+
out.add(u.origin);
|
|
4298
|
+
out.add(`${u.protocol === "http:" ? "ws" : "wss"}://${u.host}`);
|
|
4299
|
+
} catch {
|
|
4300
|
+
}
|
|
4301
|
+
if (issuerJwksUri) {
|
|
4302
|
+
try {
|
|
4303
|
+
out.add(new URL(issuerJwksUri).origin);
|
|
4304
|
+
} catch {
|
|
4305
|
+
}
|
|
4306
|
+
} else {
|
|
4307
|
+
out.add("https://app.prson.net");
|
|
4308
|
+
out.add("https://api.prson.net");
|
|
4309
|
+
}
|
|
4310
|
+
return [...out];
|
|
4311
|
+
}
|
|
4312
|
+
function hostOf(uri) {
|
|
4313
|
+
try {
|
|
4314
|
+
return new URL(uri).host;
|
|
4315
|
+
} catch {
|
|
4316
|
+
return null;
|
|
4317
|
+
}
|
|
4318
|
+
}
|
|
4319
|
+
function originOf(uri) {
|
|
4320
|
+
try {
|
|
4321
|
+
const u = new URL(uri);
|
|
4322
|
+
return `${u.protocol}//${u.host}`;
|
|
4323
|
+
} catch {
|
|
4324
|
+
return "(unknown)";
|
|
4325
|
+
}
|
|
4326
|
+
}
|
|
4327
|
+
function watchCsp(signalingBase, issuerJwksUri) {
|
|
4328
|
+
if (typeof document === "undefined" || typeof document.addEventListener !== "function") {
|
|
4329
|
+
return { explain: async (e) => e, stop: () => {
|
|
4330
|
+
} };
|
|
4331
|
+
}
|
|
4332
|
+
const allow = connectSourcesFor(signalingBase, issuerJwksUri);
|
|
4333
|
+
const prsonHosts = new Set(allow.map(hostOf).filter((h) => !!h));
|
|
4334
|
+
let seen = null;
|
|
4335
|
+
const onViolation = (ev) => {
|
|
4336
|
+
if (!ev.isTrusted) return;
|
|
4337
|
+
const e = ev;
|
|
4338
|
+
const host = hostOf(e.blockedURI);
|
|
4339
|
+
if (!seen && host && (prsonHosts.has(host) || host.endsWith(".prson.net"))) {
|
|
4340
|
+
seen = { directive: e.effectiveDirective || e.violatedDirective, blockedUri: originOf(e.blockedURI) };
|
|
4341
|
+
}
|
|
4342
|
+
};
|
|
4343
|
+
document.addEventListener("securitypolicyviolation", onViolation);
|
|
4344
|
+
return {
|
|
4345
|
+
async explain(err) {
|
|
4346
|
+
if (!seen) await new Promise((r) => setTimeout(r, 0));
|
|
4347
|
+
if (!seen) return err;
|
|
4348
|
+
const s = seen;
|
|
4349
|
+
return new PrsonCspError(s.directive, s.blockedUri, allow);
|
|
4350
|
+
},
|
|
4351
|
+
stop() {
|
|
4352
|
+
document.removeEventListener("securitypolicyviolation", onViolation);
|
|
4353
|
+
}
|
|
4354
|
+
};
|
|
4355
|
+
}
|
|
4356
|
+
function cspStyleNonce() {
|
|
4357
|
+
if (typeof document === "undefined") return void 0;
|
|
4358
|
+
const m = document.querySelector('meta[property="csp-nonce"]');
|
|
4359
|
+
if (!m) return void 0;
|
|
4360
|
+
return m.nonce || m.getAttribute("nonce") || void 0;
|
|
4361
|
+
}
|
|
4362
|
+
|
|
4233
4363
|
// src/notify.ts
|
|
4234
4364
|
var NOTIFY_HANDLE = /^nh_[A-Za-z0-9_-]{43}$/;
|
|
4235
4365
|
function notifyHandleFrom(envelope) {
|
|
@@ -4256,6 +4386,8 @@ function openSelectOverlay(select) {
|
|
|
4256
4386
|
document.body.appendChild(host);
|
|
4257
4387
|
const shadow = host.attachShadow({ mode: "open" });
|
|
4258
4388
|
const style = document.createElement("style");
|
|
4389
|
+
const nonce = cspStyleNonce();
|
|
4390
|
+
if (nonce) style.nonce = nonce;
|
|
4259
4391
|
style.textContent = OVERLAY_CSS;
|
|
4260
4392
|
shadow.appendChild(style);
|
|
4261
4393
|
const title = pickTitle(select);
|
|
@@ -4574,6 +4706,8 @@ function openPointPhoneOverlay() {
|
|
|
4574
4706
|
document.body.appendChild(host);
|
|
4575
4707
|
const shadow = host.attachShadow({ mode: "open" });
|
|
4576
4708
|
const style = document.createElement("style");
|
|
4709
|
+
const nonce = cspStyleNonce();
|
|
4710
|
+
if (nonce) style.nonce = nonce;
|
|
4577
4711
|
style.textContent = OVERLAY_CSS2;
|
|
4578
4712
|
shadow.appendChild(style);
|
|
4579
4713
|
const glow = document.createElement("div");
|
|
@@ -5650,6 +5784,11 @@ async function awaitVerification(opts) {
|
|
|
5650
5784
|
var PROTOCOL_VERSION = "prson_vp_v1";
|
|
5651
5785
|
var ENVELOPE_VERSION = 2;
|
|
5652
5786
|
var TRUSTED_ISSUER = "did:web:app.prson.net";
|
|
5787
|
+
var TRUSTED_ISSUER_DEV = "did:web:prson-app-dev.web.app:.well-known:dev";
|
|
5788
|
+
var ISSUER_JWKS_DEV = "https://prson-api-dev.powerhouse.workers.dev/.well-known/jwt-vc-issuer";
|
|
5789
|
+
function issuerFor(opts) {
|
|
5790
|
+
return opts.environment === "dev" ? { trustedIssuer: TRUSTED_ISSUER_DEV, jwksUri: ISSUER_JWKS_DEV } : { trustedIssuer: TRUSTED_ISSUER };
|
|
5791
|
+
}
|
|
5653
5792
|
var KNOWN_VCTS = [
|
|
5654
5793
|
"https://app.prson.net/credentials/verified-human/v1",
|
|
5655
5794
|
"https://app.prson.net/credentials/verified-identity/v1"
|
|
@@ -5663,9 +5802,9 @@ function resolveSignalingBase(opts) {
|
|
|
5663
5802
|
if (opts.signalingBase) return opts.signalingBase;
|
|
5664
5803
|
return opts.environment === "dev" ? SIGNALING_BASE_DEV : SIGNALING_BASE;
|
|
5665
5804
|
}
|
|
5666
|
-
var LoginAbortedError = class extends
|
|
5805
|
+
var LoginAbortedError = class extends PrsonLoginError {
|
|
5667
5806
|
constructor(message = "sign-in aborted by a newer signIn() call") {
|
|
5668
|
-
super(message);
|
|
5807
|
+
super("aborted", message);
|
|
5669
5808
|
this.name = "LoginAbortedError";
|
|
5670
5809
|
}
|
|
5671
5810
|
};
|
|
@@ -5717,6 +5856,11 @@ var PrsonLogin = class {
|
|
|
5717
5856
|
if (prior) await prior.abort();
|
|
5718
5857
|
const me = makeInflight();
|
|
5719
5858
|
_inflight = me;
|
|
5859
|
+
const csp = watchCsp(resolveSignalingBase(opts), issuerFor(opts).jwksUri);
|
|
5860
|
+
if (opts.environment === "dev" && typeof location !== "undefined" && !/^(localhost|127\.0\.0\.1|\[::1\])$|\.localhost$|\.test$/.test(location.hostname)) {
|
|
5861
|
+
console.warn(`Prson sign-in is in dev mode on ${location.hostname}: it accepts dev credentials. Remove environment: "dev" before going live.`);
|
|
5862
|
+
}
|
|
5863
|
+
me.pushTeardown(() => csp.stop());
|
|
5720
5864
|
try {
|
|
5721
5865
|
const domain = opts.domain ?? window.location.origin.replace(/^https?:\/\//, "");
|
|
5722
5866
|
const theme = opts.ui?.theme ?? "auto";
|
|
@@ -5765,8 +5909,10 @@ var PrsonLogin = class {
|
|
|
5765
5909
|
ui.handle?.dispose();
|
|
5766
5910
|
dialog.current?.dispose();
|
|
5767
5911
|
return out;
|
|
5768
|
-
} catch (
|
|
5769
|
-
if (
|
|
5912
|
+
} catch (caught) {
|
|
5913
|
+
if (caught instanceof LoginAbortedError) throw caught;
|
|
5914
|
+
const err = asLoginError(await csp.explain(caught));
|
|
5915
|
+
if (err instanceof PrsonCspError && typeof console !== "undefined") console.error(err.message);
|
|
5770
5916
|
ui.handle?.update?.({ state: "error", message: friendlyError(err) });
|
|
5771
5917
|
if (!dialog.current || !ui.handle?.update) {
|
|
5772
5918
|
if (dialog.current) await me.abort();
|
|
@@ -5781,6 +5927,7 @@ var PrsonLogin = class {
|
|
|
5781
5927
|
}
|
|
5782
5928
|
}
|
|
5783
5929
|
} finally {
|
|
5930
|
+
csp.stop();
|
|
5784
5931
|
if (_inflight === me) _inflight = null;
|
|
5785
5932
|
}
|
|
5786
5933
|
}
|
|
@@ -5810,7 +5957,7 @@ async function runAttempt(opts, env) {
|
|
|
5810
5957
|
const given = typeof opts.nonce === "function" ? await guard(Promise.resolve(opts.nonce())) : opts.nonce;
|
|
5811
5958
|
checkAborted();
|
|
5812
5959
|
if (given !== void 0 && (typeof given !== "string" || !/^[A-Za-z0-9_-]{22,128}$/.test(given))) {
|
|
5813
|
-
throw new
|
|
5960
|
+
throw new PrsonLoginError("invalid_options", "nonce must be 22-128 base64url characters (at least 16 random bytes)");
|
|
5814
5961
|
}
|
|
5815
5962
|
const nonce = given ?? b64u(crypto.getRandomValues(new Uint8Array(32)));
|
|
5816
5963
|
const request = {
|
|
@@ -5825,9 +5972,9 @@ async function runAttempt(opts, env) {
|
|
|
5825
5972
|
// Sponsorship offer (advisory on the wire — the server enforces
|
|
5826
5973
|
// the stored grant's domain/caps/budget at charge time).
|
|
5827
5974
|
...opts.sponsorship?.grantId ? { sponsorship: { grantId: opts.sponsorship.grantId } } : {},
|
|
5828
|
-
// If set,
|
|
5829
|
-
//
|
|
5830
|
-
//
|
|
5975
|
+
// If set, the wallet signs in with a random, device-only key for
|
|
5976
|
+
// this site (kept on that phone and reused there; not derived from
|
|
5977
|
+
// the recovery phrase). Closes M-5; see SignInOptions.ephemeralIdentity.
|
|
5831
5978
|
ephemeralIdentity: opts.ephemeralIdentity === true,
|
|
5832
5979
|
// QR-mode remote navigation — wallet surfaces Prev / Next /
|
|
5833
5980
|
// Submit / Logout / Mouse on a persistent banner. See
|
|
@@ -5911,29 +6058,29 @@ async function runAttempt(opts, env) {
|
|
|
5911
6058
|
show({ state: "verifying" });
|
|
5912
6059
|
const { envelope, senderPk } = await openEnvelope(first, ephKeys);
|
|
5913
6060
|
if (envelope.v !== PROTOCOL_VERSION || envelope.msg !== "presentation") {
|
|
5914
|
-
throw new
|
|
6061
|
+
throw new PrsonLoginError("protocol", `Unexpected first message: ${envelope.v}/${envelope.msg}`);
|
|
5915
6062
|
}
|
|
5916
6063
|
const presentationStr = envelope.presentation;
|
|
5917
6064
|
if (!presentationStr) {
|
|
5918
|
-
throw new
|
|
6065
|
+
throw new PrsonLoginError("protocol", "Initial presentation envelope had no presentation field");
|
|
5919
6066
|
}
|
|
5920
6067
|
const acceptedVcts = opts.allowAnonymous ? [...KNOWN_VCTS, ANONYMOUS_WALLET_VCT2] : [...KNOWN_VCTS];
|
|
5921
6068
|
const verified = await verifyPresentation(presentationStr, {
|
|
5922
6069
|
expectedAudience: `https://${domain}`,
|
|
5923
6070
|
expectedNonce: nonce,
|
|
5924
6071
|
acceptedVcts,
|
|
5925
|
-
|
|
6072
|
+
...issuerFor(opts)
|
|
5926
6073
|
});
|
|
5927
6074
|
if (!verified.ok) {
|
|
5928
|
-
throw new
|
|
6075
|
+
throw new PrsonLoginError("presentation_rejected", `Presentation rejected: ${verified.reason}`, verified.reason);
|
|
5929
6076
|
}
|
|
5930
6077
|
const boundKey = verified.binding.walletSessionPk;
|
|
5931
6078
|
if (boundKey) {
|
|
5932
6079
|
if (senderPk !== boundKey) {
|
|
5933
|
-
throw new
|
|
6080
|
+
throw new PrsonLoginError("presentation_rejected", "Presentation rejected: envelope not sent by the wallet's signed session key", "session_key_mismatch");
|
|
5934
6081
|
}
|
|
5935
6082
|
if (envelope.walletSessionPk !== void 0 && envelope.walletSessionPk !== boundKey) {
|
|
5936
|
-
throw new
|
|
6083
|
+
throw new PrsonLoginError("presentation_rejected", "Presentation rejected: walletSessionPk differs from the signed one", "session_key_mismatch");
|
|
5937
6084
|
}
|
|
5938
6085
|
} else if (typeof console !== "undefined") {
|
|
5939
6086
|
console.warn(
|
|
@@ -5944,14 +6091,15 @@ async function runAttempt(opts, env) {
|
|
|
5944
6091
|
const minLevel = opts.required?.minVerificationLevel ?? 1;
|
|
5945
6092
|
const claimedLevel = typeof verified.claims.verification_level === "number" ? verified.claims.verification_level : 0;
|
|
5946
6093
|
if (claimedLevel < minLevel) {
|
|
5947
|
-
throw new
|
|
6094
|
+
throw new PrsonLoginError(
|
|
6095
|
+
"level_too_low",
|
|
5948
6096
|
`Presentation rejected: verification_level ${claimedLevel} below required ${minLevel}`
|
|
5949
6097
|
);
|
|
5950
6098
|
}
|
|
5951
6099
|
}
|
|
5952
6100
|
const uniqueHumanId = envelope.uniqueHumanId ?? null;
|
|
5953
6101
|
if (opts.required?.uniqueHumanId === true && !uniqueHumanId) {
|
|
5954
|
-
throw new
|
|
6102
|
+
throw new PrsonLoginError("unique_human_missing", "Presentation rejected: required uniqueHumanId credential missing");
|
|
5955
6103
|
}
|
|
5956
6104
|
const notifyHandle = opts.notifications === true ? notifyHandleFrom(envelope) : null;
|
|
5957
6105
|
checkAborted();
|
|
@@ -5984,7 +6132,7 @@ async function runAttempt(opts, env) {
|
|
|
5984
6132
|
// renewals carry a fresh nonce; see session.ts
|
|
5985
6133
|
// The same set as the sign-in, so an anonymous session can renew.
|
|
5986
6134
|
acceptedVcts,
|
|
5987
|
-
|
|
6135
|
+
...issuerFor(opts)
|
|
5988
6136
|
},
|
|
5989
6137
|
// Renewal anti-replay baseline: a renewal must be strictly newer.
|
|
5990
6138
|
initialPresentation: { presentation: presentationStr, iat: verified.binding.iat },
|
|
@@ -6020,6 +6168,24 @@ async function runAttempt(opts, env) {
|
|
|
6020
6168
|
return result;
|
|
6021
6169
|
}
|
|
6022
6170
|
function friendlyError(err) {
|
|
6171
|
+
if (err instanceof PrsonLoginError) {
|
|
6172
|
+
switch (err.code) {
|
|
6173
|
+
case "csp_blocked":
|
|
6174
|
+
return "This site's security settings blocked Prson. The site's owner needs to allow Prson in its Content-Security-Policy.";
|
|
6175
|
+
case "rate_limited":
|
|
6176
|
+
return "Too many sign-ins from this network. Wait a moment and try again.";
|
|
6177
|
+
case "network":
|
|
6178
|
+
return "Couldn't reach Prson. Check your connection and try again.";
|
|
6179
|
+
case "expired":
|
|
6180
|
+
return "This code expired. Get a new code and try again.";
|
|
6181
|
+
case "unique_human_missing":
|
|
6182
|
+
return "This site needs a passport or ID card verified in the Prson app.";
|
|
6183
|
+
case "level_too_low":
|
|
6184
|
+
return "This site needs a more verified identity than the one chosen.";
|
|
6185
|
+
default:
|
|
6186
|
+
break;
|
|
6187
|
+
}
|
|
6188
|
+
}
|
|
6023
6189
|
const m = err instanceof Error ? err.message : String(err);
|
|
6024
6190
|
if (/Too many login sessions/i.test(m)) return "Too many sign-ins from this network. Wait a moment and try again.";
|
|
6025
6191
|
if (/createDraft failed|Failed to fetch|NetworkError|signaling: WS/i.test(m)) {
|
|
@@ -6040,15 +6206,17 @@ function validateReturnUrl(returnUrl, domain) {
|
|
|
6040
6206
|
try {
|
|
6041
6207
|
parsed = new URL(returnUrl);
|
|
6042
6208
|
} catch {
|
|
6043
|
-
throw new
|
|
6209
|
+
throw new PrsonLoginError("invalid_options", `returnUrl is not a valid URL: ${returnUrl}`);
|
|
6044
6210
|
}
|
|
6045
6211
|
if (parsed.protocol !== "https:") {
|
|
6046
|
-
throw new
|
|
6212
|
+
throw new PrsonLoginError(
|
|
6213
|
+
"invalid_options",
|
|
6047
6214
|
"returnUrl must be https:// (custom schemes are refused \u2014 any app could claim them; use a Universal Link / App Link on your domain)"
|
|
6048
6215
|
);
|
|
6049
6216
|
}
|
|
6050
6217
|
if (parsed.host.toLowerCase() !== domain.toLowerCase()) {
|
|
6051
|
-
throw new
|
|
6218
|
+
throw new PrsonLoginError(
|
|
6219
|
+
"invalid_options",
|
|
6052
6220
|
`returnUrl host (${parsed.host}) must equal the login domain (${domain})`
|
|
6053
6221
|
);
|
|
6054
6222
|
}
|
|
@@ -6078,24 +6246,32 @@ export {
|
|
|
6078
6246
|
DEFAULT_TTL_MINUTES,
|
|
6079
6247
|
ENVELOPE_VERSION,
|
|
6080
6248
|
GET_APP_URL,
|
|
6249
|
+
ISSUER_JWKS_DEV,
|
|
6081
6250
|
KNOWN_VCTS,
|
|
6082
6251
|
LoginAbortedError,
|
|
6083
6252
|
MAX_TTL_MINUTES,
|
|
6084
6253
|
NOTIFY_HANDLE,
|
|
6085
6254
|
PROTOCOL_VERSION,
|
|
6255
|
+
PRSON_CONNECT_SRC,
|
|
6256
|
+
PrsonCspError,
|
|
6086
6257
|
PrsonLogin,
|
|
6258
|
+
PrsonLoginError,
|
|
6087
6259
|
PrsonLoginSession,
|
|
6088
6260
|
SIGNALING_BASE,
|
|
6089
6261
|
SIGNALING_BASE_DEV,
|
|
6090
6262
|
TRUSTED_ISSUER,
|
|
6263
|
+
TRUSTED_ISSUER_DEV,
|
|
6091
6264
|
VerificationAbortedError,
|
|
6092
6265
|
VerificationClosedError,
|
|
6093
6266
|
awaitVerification,
|
|
6094
6267
|
bindForm,
|
|
6095
6268
|
bindInput,
|
|
6096
6269
|
bindMouse,
|
|
6270
|
+
connectSourcesFor,
|
|
6271
|
+
cspStyleNonce,
|
|
6097
6272
|
enableRemoteNavigation,
|
|
6098
6273
|
isSensitiveField,
|
|
6274
|
+
issuerFor,
|
|
6099
6275
|
notifyHandleFrom,
|
|
6100
6276
|
resolveSignalingBase
|
|
6101
6277
|
};
|