@calimero-network/mero-js 29.7.5 → 29.7.7
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/cloud-v2/client.d.ts +20 -1
- package/dist/cloud-v2/client.js +48 -19
- package/dist/cloud-v2/index.d.ts +1 -1
- package/dist/cloud-v2/passkey.d.ts +25 -7
- package/dist/cloud-v2/passkey.js +16 -5
- package/dist/index.browser.mjs +3 -3
- package/dist/index.browser.mjs.map +3 -3
- package/dist/index.cjs +49 -20
- package/dist/index.cjs.map +2 -2
- package/dist/index.mjs +49 -20
- package/dist/index.mjs.map +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1725,11 +1725,18 @@ function cancelled(message) {
|
|
|
1725
1725
|
error.name = "NotAllowedError";
|
|
1726
1726
|
return error;
|
|
1727
1727
|
}
|
|
1728
|
-
async function ask(method, options) {
|
|
1728
|
+
async function ask(method, options, signal, what) {
|
|
1729
1729
|
const container = navigator.credentials;
|
|
1730
1730
|
const own = globalThis.CredentialsContainer?.prototype?.[method];
|
|
1731
1731
|
const call = own ?? container[method];
|
|
1732
|
-
|
|
1732
|
+
try {
|
|
1733
|
+
return await call.call(container, signal ? { ...options, signal } : options);
|
|
1734
|
+
} catch (error) {
|
|
1735
|
+
if (signal?.aborted || error?.name === "AbortError") {
|
|
1736
|
+
throw Object.assign(cancelled(`${what} was cancelled`), { cause: error });
|
|
1737
|
+
}
|
|
1738
|
+
throw error;
|
|
1739
|
+
}
|
|
1733
1740
|
}
|
|
1734
1741
|
function es256First(params) {
|
|
1735
1742
|
const es256 = params.filter((p) => p.alg === -7);
|
|
@@ -1737,7 +1744,7 @@ function es256First(params) {
|
|
|
1737
1744
|
}
|
|
1738
1745
|
function browserPasskey() {
|
|
1739
1746
|
return {
|
|
1740
|
-
async create(options) {
|
|
1747
|
+
async create(options, createOptions) {
|
|
1741
1748
|
const o = options;
|
|
1742
1749
|
const cred = await ask("create", {
|
|
1743
1750
|
publicKey: {
|
|
@@ -1753,7 +1760,7 @@ function browserPasskey() {
|
|
|
1753
1760
|
attestation: "none",
|
|
1754
1761
|
timeout: o.timeout
|
|
1755
1762
|
}
|
|
1756
|
-
});
|
|
1763
|
+
}, createOptions?.signal, "passkey creation");
|
|
1757
1764
|
if (!cred) throw cancelled("passkey creation was cancelled");
|
|
1758
1765
|
const r = cred.response;
|
|
1759
1766
|
return {
|
|
@@ -1772,7 +1779,7 @@ function browserPasskey() {
|
|
|
1772
1779
|
id: buf(fromB64url(id))
|
|
1773
1780
|
}))
|
|
1774
1781
|
}
|
|
1775
|
-
});
|
|
1782
|
+
}, options?.signal, "passkey sign-in");
|
|
1776
1783
|
if (!cred) throw cancelled("passkey sign-in was cancelled");
|
|
1777
1784
|
const r = cred.response;
|
|
1778
1785
|
return {
|
|
@@ -1990,8 +1997,8 @@ function pageDeployment(href) {
|
|
|
1990
1997
|
return null;
|
|
1991
1998
|
}
|
|
1992
1999
|
}
|
|
1993
|
-
function userVerificationOf(named) {
|
|
1994
|
-
return named === "required" || named === "preferred" || named === "discouraged" ? named :
|
|
2000
|
+
function userVerificationOf(named, fallback) {
|
|
2001
|
+
return named === "required" || named === "preferred" || named === "discouraged" ? named : fallback;
|
|
1995
2002
|
}
|
|
1996
2003
|
function promptFailure(error) {
|
|
1997
2004
|
const e = error;
|
|
@@ -2377,11 +2384,16 @@ var CalimeroClient = class _CalimeroClient {
|
|
|
2377
2384
|
origin === void 0 ? { name, ...invite } : { name, origin, ...invite },
|
|
2378
2385
|
origin
|
|
2379
2386
|
);
|
|
2380
|
-
const
|
|
2381
|
-
const
|
|
2387
|
+
const signal = options.signal;
|
|
2388
|
+
const registration = await (signal ? passkey.create(begin.options, { signal }) : passkey.create(begin.options));
|
|
2389
|
+
const session = await this.confirmed(
|
|
2390
|
+
"POST",
|
|
2382
2391
|
"auth/passkey/register/finish",
|
|
2383
2392
|
{ challengeId: begin.challengeId, registration, ...invite },
|
|
2384
|
-
passkey
|
|
2393
|
+
passkey,
|
|
2394
|
+
void 0,
|
|
2395
|
+
"preferred",
|
|
2396
|
+
signal
|
|
2385
2397
|
);
|
|
2386
2398
|
this.useSession(session);
|
|
2387
2399
|
return session;
|
|
@@ -2402,7 +2414,8 @@ var CalimeroClient = class _CalimeroClient {
|
|
|
2402
2414
|
const origin = this.pageOrigin(options);
|
|
2403
2415
|
const begin = await this.begin("auth/passkey/login/begin", origin === void 0 ? void 0 : { origin }, origin);
|
|
2404
2416
|
const rpId = begin.options.rpId ?? begin.options.rp?.id ?? "";
|
|
2405
|
-
const
|
|
2417
|
+
const challenge = fromB64url(begin.options.challenge);
|
|
2418
|
+
const assertion = await (options.signal ? passkey.get(challenge, rpId, void 0, { signal: options.signal }) : passkey.get(challenge, rpId));
|
|
2406
2419
|
const session = await this.post("auth/passkey/login/finish", {
|
|
2407
2420
|
challengeId: begin.challengeId,
|
|
2408
2421
|
assertion
|
|
@@ -2471,16 +2484,31 @@ var CalimeroClient = class _CalimeroClient {
|
|
|
2471
2484
|
if (this.current === current) this.useSession(session);
|
|
2472
2485
|
return session;
|
|
2473
2486
|
}
|
|
2487
|
+
/**
|
|
2488
|
+
* End this session. The client is signed out whether or not the node
|
|
2489
|
+
* answers: the revoke (`POST /auth/logout`) is attempted, and its failure
|
|
2490
|
+
* (the node unreachable, say) is thrown after the session is dropped, so a
|
|
2491
|
+
* caller can say the server may still hold it, but no request after this
|
|
2492
|
+
* one carries its token.
|
|
2493
|
+
*/
|
|
2474
2494
|
async signOut() {
|
|
2475
|
-
await this.
|
|
2476
|
-
this.auth = void 0;
|
|
2477
|
-
this.current = void 0;
|
|
2495
|
+
await this.signingOut("auth/logout");
|
|
2478
2496
|
}
|
|
2479
|
-
/**
|
|
2497
|
+
/**
|
|
2498
|
+
* End every session of the signed-in account, on every device, this one
|
|
2499
|
+
* too. Like {@link signOut}, this client is signed out even when the
|
|
2500
|
+
* request fails, and the failure is thrown.
|
|
2501
|
+
*/
|
|
2480
2502
|
async signOutEverywhere() {
|
|
2481
|
-
await this.
|
|
2482
|
-
|
|
2483
|
-
|
|
2503
|
+
await this.signingOut("auth/logout-all");
|
|
2504
|
+
}
|
|
2505
|
+
async signingOut(path) {
|
|
2506
|
+
try {
|
|
2507
|
+
await this.post(path);
|
|
2508
|
+
} finally {
|
|
2509
|
+
this.auth = void 0;
|
|
2510
|
+
this.current = void 0;
|
|
2511
|
+
}
|
|
2484
2512
|
}
|
|
2485
2513
|
/** Who the credential is: the account, how it signed in, and the package (`app`) and `origin` a session is bound to. */
|
|
2486
2514
|
me() {
|
|
@@ -2772,7 +2800,7 @@ var CalimeroClient = class _CalimeroClient {
|
|
|
2772
2800
|
deleteConfirmed(path, passkey, body = {}) {
|
|
2773
2801
|
return this.confirmed("DELETE", path, body, passkey);
|
|
2774
2802
|
}
|
|
2775
|
-
async confirmed(method, path, body, passkey, send = (b) => this.json(method, path, b)) {
|
|
2803
|
+
async confirmed(method, path, body, passkey, send = (b) => this.json(method, path, b), userVerification = "required", signal) {
|
|
2776
2804
|
try {
|
|
2777
2805
|
return await send(body);
|
|
2778
2806
|
} catch (error) {
|
|
@@ -2781,7 +2809,8 @@ var CalimeroClient = class _CalimeroClient {
|
|
|
2781
2809
|
let assertion;
|
|
2782
2810
|
try {
|
|
2783
2811
|
assertion = await passkey.get(fromB64url(d.challenge), d.rpId, d.allowCredentials, {
|
|
2784
|
-
userVerification: userVerificationOf(d.userVerification)
|
|
2812
|
+
userVerification: userVerificationOf(d.userVerification, userVerification),
|
|
2813
|
+
...signal ? { signal } : {}
|
|
2785
2814
|
});
|
|
2786
2815
|
} catch (declined) {
|
|
2787
2816
|
throw promptFailure(declined);
|