Mapping existing wallets to social login

I’m working on a wallet project with many pre-existing users who have created their own wallets on our app. We plan to integrate social login with Web3Auth, but we need a solution to let existing users use social login with their current wallets. Web3Auth typically generates a new private/public key pair for new sign-ups, which would force existing users to switch to new wallet addresses. Is there a way to map existing wallets to social login credentials so that users can retain their current wallets?

Hey @alextan7527 welcome aboard, can you please share more details about pre-existing user wallets. Are those external wallets like metamask, coinbase, or embedded wallet?

Not external wallets. It’s our own wallet app and user wallets are generated by mnemonic seed phrase.

Hey @alextan7527 with the PnP SDKs that’s not possible. But you can use our CoreKit SDKs to have this flow. For instance, if user already has your in app wallet, you can simply import the private key with the corresponding social login. This will not create a new wallet.

We have two solutions, one is the tKey SDK, and other one is MPC CoreKit SDK. Using tKey and MPC CoreKit SDK you can import the existing private key to the Web3Auth architecture. The only difference between two SDKs is tKey SDK is based on SSS architecture i.e. the private key can be reconstructed on the client for signing the transactions. On the other hand MPC CoreKit is based on MPC architecture where the private key is never reconstructed, and signing is done using threshold signatures.

Read more about tKey SDK.
Read more about MPC CoreKit SDK

Please let me know if you need any more help.

Thanks for your help! I’m very excited to hear that it’s possible to import existing private keys to the Web3Auth architecture. Could you provide me some code or specific functions to do that?

Hey @alextan7527 sure. If you are using the tKey SDK, once you have logged in, while initialising tKey you can pass the privateKey as a parameter, it’ll import the existing account to the Web3Auth architecture with email attached.

import { safeatob } from "@toruslabs/openlogin-utils";

const loginRes = await signInWithEmailPassword(); // Logging in via email and password
const idToken = await loginRes!.user.getIdToken(true); // Getting ID Token from the Login Provider
const parsedToken = parseToken(idToken); // Parsing the ID Token

// function to Parse Id Token
const parseToken = (token: any) => {
  try {
    const token = token.split(".")[1]; // payload
    return JSON.parse(safeatob(token));
  } catch (err) {
    console.log(err);
    return null;
  }
};

console.log("User Information:", parsedToken);

// Connecting to the service provider
const verifier = "web3auth-firebase-examples";
const verifierId = parsedToken.sub;
const OAuthShareKey = await (tKeyInstance.serviceProvider as SfaServiceProvider).connect({
  verifier,
  verifierId,
  idToken,
});

console.log("OAuth Share:", OAuthShareKey);

// You can get the BN for your private key hex. Once you get the BN you can pass it to the importKey.
await tKeyInstance.initialize(importKey: "YOUR_PRIVATEKEY_BN");

Cool, this is awesome. And what if I’m using MPC corekit sdk? Could you provide some code for that as well? And beyond that, I’d like to know if it’s possible to import the account using mnemonic seed phrase. And I noticed that web3auth is using 24-mnemonic-phrase architecture?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.