Extending MPC COre Kit with transfer module

Hello dear web3auth team,

I’m trying to to achieve to implement the share module into your MPC SDK, but am failing and wanted to reach out to you.

So I want to send the request, approve the request and create a new factor and the device, so it’s the user stays logged in.

I’m not sure If I even need WebStorage for this to work, but this current state of the code. It’s placed in the mpcCoreKit.ts file.

I’m called enableMFA on Device A, and Device B calls requestShare() on COREKIT_STATUS.REQUIRED_SHARE. Device A than approves the share, but device B fails in reconstruction and “registering” Device B.

Do you have any suggestions in how to incoperate those function correctly into your MPC Core Kit? I really would love to have the benefits of you MPC Core Package.

Thank you in advance!!

  async requestShare(): Promise<void> {
    try {
      const result = await (
        this.tKey.modules.shareTransfer as ShareTransferModule
      ).requestNewShare(
        navigator.userAgent,
        this.tKey.getCurrentShareIndexes()
      );
      console.log("Share request result:", result);
    } catch (err) {
      log.error(err);
    }
  }

  async approveShareRequest(): Promise<void> {
    console.log("Approving All Share Requests");
    try {
      const result = await (
        this.tKey.modules.shareTransfer as ShareTransferModule
      ).getShareTransferStore();

      const pubkeys = Object.keys(result);

      await (
        this.tKey.modules.shareTransfer as ShareTransferModule
      ).approveRequest(pubkeys[0]);

      await this.commitChanges();
      console.log("Finished approving all share transfer requests");
    } catch (err) {
      console.error("Failed to process share transfer store:", err);
    }
  }

  async reconstructKey(): Promise<void> {
    try {
      console.log("Starting key reconstruction process...");

      const result = await (
        this.tkey!.modules.shareTransfer as ShareTransferModule
      ).getShareTransferStore();
      console.log("Share transfer store retrieved:", result);

      const pubKeys = Object.keys(result);
      console.log("Extracted public keys:", pubKeys);

      await (
        this.tkey!.modules.shareTransfer as ShareTransferModule
      ).startRequestStatusCheck(pubKeys[0], true);

      await this.tKey.reconstructKey();

      const generateShareResult = await this.tKey.generateNewShare();
      const share = this.tKey.outputShareStore(
        generateShareResult.newShareIndex
      );
      await (this.tKey.modules.webStorage as WebStorageModule).storeDeviceShare(
        share
      );

      await (
        this.tKey.modules.webStorage as WebStorageModule
      ).inputShareFromWebStorage();

      await this.commitChanges();
    } catch (err) {
      console.error("Failed to reconstruct key:", err);
    }
  }

Hi Michal,

Thank you for reaching out! It looks like you’re trying to incorporate the share module into the tKey JS SDK’s MPC Core Kit without much success. Let’s break down your request:

  • SDK Details: tKey JS SDK
  • Issue: Extending MPC Core Kit with the transfer module
  • Process: Implementing sharing requests, approvals, and device registration
  • Platform: It seems you’re handling it through custom code and likely web-based (considering usage of navigator.userAgent).

From your code snippets, it appears you’re handling share requests and approvals correctly. However, device B fails during reconstruction and registration.

A few things you might want to double-check:

  1. WebStorage Use: Ensure that WebStorage modules are initialized correctly as you will need to store and retrieve shares during the process.
  2. Request-Approve Flow: Ensure the flow between Device A and B is well synchronized and both devices are using the latest states available.
  3. Error Handling: Logs provided don’t specify the errors. Check .catch in promises to see if there are errors not being logged.
  4. Commit Changes: Make sure each commit is properly executed and reviewed.

If you’re still experiencing issues, checking error messages in the console might give us more insight into the failure during reconciliation. Also, ensure you have the latest version of the SDK, as updates sometimes resolve ongoing issues.

If you encounter any specific error messages or need further help, feel free to share more details. The support team will be able to dive deeper with a closer look at the error context.

I hope this helps!

Note: This response was generated by an AI bot and may require further verification. The Web3Auth support team has tracked this issue and will be responding as soon as possible.

Additionally, we would recommend you to join our biweekly Office Hours to get this resolved even faster. Web3Auth Developer Office Hours