zerodevapp/sdk

getOrCreatePasskeyOwner is always creating a new passkey

Closed this issue · 3 comments

Hi guys! How is it going? Hope you are doing well :)

I'm playing a little bit with different SDKs and really like the experience and the interactive documentation of the ZeroDev team, but now I'm struggling with the getOrCreatePasskeyOwner method.

When I use createPasskeyOwner always creates a new one and with getPasskeyOwner always get the same but if I use getOrCreatePasskeyOwner is not using my last passkey but instead of it creates a new one every time I call it.

Do you know what could be? Please and thank you :)

Minimal example

import { ECDSAProvider } from "@zerodev/sdk";
import { getOrCreatePasskeyOwner } from "@zerodev/sdk/passkey";
import { useState } from "react";

const projectId = ""; // Your project ID

function Passkey() {
  const [isPasskeyLoading, setIsPasskeyLoading] = useState(false);
  const [address, setAddress] = useState("");

  const getOrCreatePasskey = async () => {
    setIsPasskeyLoading(true);

    try {
      const passkeyOwner = await getOrCreatePasskeyOwner({
        projectId: projectId,
        name: "ZeroDev",
      });

      if (passkeyOwner) {
        const ecdsaProvider = await ECDSAProvider.init({
          projectId,
          owner: passkeyOwner,
        });

        setAddress(await ecdsaProvider.getAddress());
      }
    } catch (_) {}

    setIsPasskeyLoading(false);
  };

  return (
    <>
      <button onClick={isPasskeyLoading ? undefined : getOrCreatePasskey}>
        {isPasskeyLoading ? "..." : "Get or create passkey owner"}
      </button>
      {address && <p>Your address: {address}</p>}
    </>
  );
}

export default Passkey;

If I am not wrong the expected flow is calling createPasskeyOwner and then the fallback that is getPasskeyOwner but the desired is calling createPasskeyOwner only if there is no previous passkey for the project selected. Am I right?

export async function getOrCreatePasskeyOwner({
name,
projectId,
apiUrl = API_URL,
}: {
name: string;
projectId: string;
apiUrl?: string;
}): Promise<SmartAccountSigner | undefined> {
return await createPasskeyOwner({
name,
projectId,
apiUrl,
fallback: () => getPasskeyOwner({ projectId, apiUrl }),
});
}

Just to keep it updated.

Captura de pantalla 2023-10-01 a la(s) 22 41 47

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs