@calimero-network/mero-js 29.7.6 → 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 +32 -11
- package/dist/cloud-v2/index.d.ts +1 -1
- package/dist/cloud-v2/passkey.d.ts +18 -2
- 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 +43 -17
- package/dist/index.cjs.map +2 -2
- package/dist/index.mjs +43 -17
- package/dist/index.mjs.map +2 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1592,11 +1592,18 @@ function cancelled(message) {
|
|
|
1592
1592
|
error.name = "NotAllowedError";
|
|
1593
1593
|
return error;
|
|
1594
1594
|
}
|
|
1595
|
-
async function ask(method, options) {
|
|
1595
|
+
async function ask(method, options, signal, what) {
|
|
1596
1596
|
const container = navigator.credentials;
|
|
1597
1597
|
const own = globalThis.CredentialsContainer?.prototype?.[method];
|
|
1598
1598
|
const call = own ?? container[method];
|
|
1599
|
-
|
|
1599
|
+
try {
|
|
1600
|
+
return await call.call(container, signal ? { ...options, signal } : options);
|
|
1601
|
+
} catch (error) {
|
|
1602
|
+
if (signal?.aborted || error?.name === "AbortError") {
|
|
1603
|
+
throw Object.assign(cancelled(`${what} was cancelled`), { cause: error });
|
|
1604
|
+
}
|
|
1605
|
+
throw error;
|
|
1606
|
+
}
|
|
1600
1607
|
}
|
|
1601
1608
|
function es256First(params) {
|
|
1602
1609
|
const es256 = params.filter((p) => p.alg === -7);
|
|
@@ -1604,7 +1611,7 @@ function es256First(params) {
|
|
|
1604
1611
|
}
|
|
1605
1612
|
function browserPasskey() {
|
|
1606
1613
|
return {
|
|
1607
|
-
async create(options) {
|
|
1614
|
+
async create(options, createOptions) {
|
|
1608
1615
|
const o = options;
|
|
1609
1616
|
const cred = await ask("create", {
|
|
1610
1617
|
publicKey: {
|
|
@@ -1620,7 +1627,7 @@ function browserPasskey() {
|
|
|
1620
1627
|
attestation: "none",
|
|
1621
1628
|
timeout: o.timeout
|
|
1622
1629
|
}
|
|
1623
|
-
});
|
|
1630
|
+
}, createOptions?.signal, "passkey creation");
|
|
1624
1631
|
if (!cred) throw cancelled("passkey creation was cancelled");
|
|
1625
1632
|
const r = cred.response;
|
|
1626
1633
|
return {
|
|
@@ -1639,7 +1646,7 @@ function browserPasskey() {
|
|
|
1639
1646
|
id: buf(fromB64url(id))
|
|
1640
1647
|
}))
|
|
1641
1648
|
}
|
|
1642
|
-
});
|
|
1649
|
+
}, options?.signal, "passkey sign-in");
|
|
1643
1650
|
if (!cred) throw cancelled("passkey sign-in was cancelled");
|
|
1644
1651
|
const r = cred.response;
|
|
1645
1652
|
return {
|
|
@@ -2244,14 +2251,16 @@ var CalimeroClient = class _CalimeroClient {
|
|
|
2244
2251
|
origin === void 0 ? { name, ...invite } : { name, origin, ...invite },
|
|
2245
2252
|
origin
|
|
2246
2253
|
);
|
|
2247
|
-
const
|
|
2254
|
+
const signal = options.signal;
|
|
2255
|
+
const registration = await (signal ? passkey.create(begin.options, { signal }) : passkey.create(begin.options));
|
|
2248
2256
|
const session = await this.confirmed(
|
|
2249
2257
|
"POST",
|
|
2250
2258
|
"auth/passkey/register/finish",
|
|
2251
2259
|
{ challengeId: begin.challengeId, registration, ...invite },
|
|
2252
2260
|
passkey,
|
|
2253
2261
|
void 0,
|
|
2254
|
-
"preferred"
|
|
2262
|
+
"preferred",
|
|
2263
|
+
signal
|
|
2255
2264
|
);
|
|
2256
2265
|
this.useSession(session);
|
|
2257
2266
|
return session;
|
|
@@ -2272,7 +2281,8 @@ var CalimeroClient = class _CalimeroClient {
|
|
|
2272
2281
|
const origin = this.pageOrigin(options);
|
|
2273
2282
|
const begin = await this.begin("auth/passkey/login/begin", origin === void 0 ? void 0 : { origin }, origin);
|
|
2274
2283
|
const rpId = begin.options.rpId ?? begin.options.rp?.id ?? "";
|
|
2275
|
-
const
|
|
2284
|
+
const challenge = fromB64url(begin.options.challenge);
|
|
2285
|
+
const assertion = await (options.signal ? passkey.get(challenge, rpId, void 0, { signal: options.signal }) : passkey.get(challenge, rpId));
|
|
2276
2286
|
const session = await this.post("auth/passkey/login/finish", {
|
|
2277
2287
|
challengeId: begin.challengeId,
|
|
2278
2288
|
assertion
|
|
@@ -2341,16 +2351,31 @@ var CalimeroClient = class _CalimeroClient {
|
|
|
2341
2351
|
if (this.current === current) this.useSession(session);
|
|
2342
2352
|
return session;
|
|
2343
2353
|
}
|
|
2354
|
+
/**
|
|
2355
|
+
* End this session. The client is signed out whether or not the node
|
|
2356
|
+
* answers: the revoke (`POST /auth/logout`) is attempted, and its failure
|
|
2357
|
+
* (the node unreachable, say) is thrown after the session is dropped, so a
|
|
2358
|
+
* caller can say the server may still hold it, but no request after this
|
|
2359
|
+
* one carries its token.
|
|
2360
|
+
*/
|
|
2344
2361
|
async signOut() {
|
|
2345
|
-
await this.
|
|
2346
|
-
this.auth = void 0;
|
|
2347
|
-
this.current = void 0;
|
|
2362
|
+
await this.signingOut("auth/logout");
|
|
2348
2363
|
}
|
|
2349
|
-
/**
|
|
2364
|
+
/**
|
|
2365
|
+
* End every session of the signed-in account, on every device, this one
|
|
2366
|
+
* too. Like {@link signOut}, this client is signed out even when the
|
|
2367
|
+
* request fails, and the failure is thrown.
|
|
2368
|
+
*/
|
|
2350
2369
|
async signOutEverywhere() {
|
|
2351
|
-
await this.
|
|
2352
|
-
|
|
2353
|
-
|
|
2370
|
+
await this.signingOut("auth/logout-all");
|
|
2371
|
+
}
|
|
2372
|
+
async signingOut(path) {
|
|
2373
|
+
try {
|
|
2374
|
+
await this.post(path);
|
|
2375
|
+
} finally {
|
|
2376
|
+
this.auth = void 0;
|
|
2377
|
+
this.current = void 0;
|
|
2378
|
+
}
|
|
2354
2379
|
}
|
|
2355
2380
|
/** Who the credential is: the account, how it signed in, and the package (`app`) and `origin` a session is bound to. */
|
|
2356
2381
|
me() {
|
|
@@ -2642,7 +2667,7 @@ var CalimeroClient = class _CalimeroClient {
|
|
|
2642
2667
|
deleteConfirmed(path, passkey, body = {}) {
|
|
2643
2668
|
return this.confirmed("DELETE", path, body, passkey);
|
|
2644
2669
|
}
|
|
2645
|
-
async confirmed(method, path, body, passkey, send = (b) => this.json(method, path, b), userVerification = "required") {
|
|
2670
|
+
async confirmed(method, path, body, passkey, send = (b) => this.json(method, path, b), userVerification = "required", signal) {
|
|
2646
2671
|
try {
|
|
2647
2672
|
return await send(body);
|
|
2648
2673
|
} catch (error) {
|
|
@@ -2651,7 +2676,8 @@ var CalimeroClient = class _CalimeroClient {
|
|
|
2651
2676
|
let assertion;
|
|
2652
2677
|
try {
|
|
2653
2678
|
assertion = await passkey.get(fromB64url(d.challenge), d.rpId, d.allowCredentials, {
|
|
2654
|
-
userVerification: userVerificationOf(d.userVerification, userVerification)
|
|
2679
|
+
userVerification: userVerificationOf(d.userVerification, userVerification),
|
|
2680
|
+
...signal ? { signal } : {}
|
|
2655
2681
|
});
|
|
2656
2682
|
} catch (declined) {
|
|
2657
2683
|
throw promptFailure(declined);
|