@calimero-network/mero-js 29.7.2 → 29.7.3

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/index.mjs CHANGED
@@ -1585,17 +1585,36 @@ function cancelled(message) {
1585
1585
  error.name = "NotAllowedError";
1586
1586
  return error;
1587
1587
  }
1588
+ async function ask(method, options) {
1589
+ const container = navigator.credentials;
1590
+ const page = container[method];
1591
+ try {
1592
+ return await page.call(container, options);
1593
+ } catch (error) {
1594
+ const own = globalThis.CredentialsContainer?.prototype?.[method];
1595
+ if (!own || own === page || !stuck(error)) throw error;
1596
+ return own.call(container, options);
1597
+ }
1598
+ }
1599
+ function stuck(error) {
1600
+ return /request is already pending/i.test(
1601
+ error?.message?.toString() ?? ""
1602
+ );
1603
+ }
1588
1604
  function browserPasskey() {
1589
1605
  return {
1590
1606
  async create(options) {
1591
1607
  const o = options;
1592
- const cred = await navigator.credentials.create({
1608
+ const cred = await ask("create", {
1593
1609
  publicKey: {
1594
1610
  challenge: buf(fromB64url(o.challenge)),
1595
1611
  rp: o.rp,
1596
1612
  user: { ...o.user, id: buf(fromB64url(o.user.id)) },
1597
1613
  pubKeyCredParams: o.pubKeyCredParams,
1598
- excludeCredentials: (o.excludeCredentials ?? []).map((c) => ({ type: c.type, id: buf(fromB64url(c.id)) })),
1614
+ excludeCredentials: (o.excludeCredentials ?? []).map((c) => ({
1615
+ type: c.type,
1616
+ id: buf(fromB64url(c.id))
1617
+ })),
1599
1618
  authenticatorSelection: o.authenticatorSelection,
1600
1619
  attestation: "none",
1601
1620
  timeout: o.timeout
@@ -1609,12 +1628,15 @@ function browserPasskey() {
1609
1628
  };
1610
1629
  },
1611
1630
  async get(challenge, rpId, allowCredentials) {
1612
- const cred = await navigator.credentials.get({
1631
+ const cred = await ask("get", {
1613
1632
  publicKey: {
1614
1633
  challenge: buf(challenge),
1615
1634
  rpId,
1616
1635
  userVerification: "preferred",
1617
- allowCredentials: (allowCredentials ?? []).map((id) => ({ type: "public-key", id: buf(fromB64url(id)) }))
1636
+ allowCredentials: (allowCredentials ?? []).map((id) => ({
1637
+ type: "public-key",
1638
+ id: buf(fromB64url(id))
1639
+ }))
1618
1640
  }
1619
1641
  });
1620
1642
  if (!cred) throw cancelled("passkey sign-in was cancelled");