Skip to content

Getting error while calling "tKey.initialize()" ERROR: Custom require either serviceProvider or priv key in getGenericMetadataWithTransitionStates #183

@ckshitij

Description

@ckshitij

Getting below error while initializing the tKey SDK, it's working fine on the chrome browser but throwing an error on firefox and safari.

Error response

{"name":"CoreError","code":1000,"message":"Custom require either serviceProvider or priv key in getGenericMetadataWithTransitionStates"}

Code Snippet

// 1. Setup Service Provider
const directParams = {
    baseUrl: `${window.location.origin}/serviceworker`,
    enableLogging: true,
    network: "testnet" as any,
};
const serviceProvider = new TorusServiceProvider({ customAuthArgs: directParams });
  
// 2. Initializing tKey
const webStorageModule = new WebStorageModule();
const securityQuestionsModule = new SecurityQuestionsModule();
const shareTransferModule = new ShareTransferModule();
const storageLayer = new TorusStorageLayer({ hostUrl: "https://metadata.tor.us" });
  
 // Creating the ThresholdKey instance
export  const tKey = new ThresholdKey({
    serviceProvider: serviceProvider,
    storageLayer,
    modules: { webStorage: webStorageModule, securityQuestions: securityQuestionsModule, shareTransfer: shareTransferModule },
});

Actual function call using the same tKey instance:

const loginUsingLocalShare = async () => {
      try {
        await triggerLogin();
        await tKey.initialize();

        try {
           console.log("Adding local web storage share");
            const webStorageModule = tKey.modules["webStorage"] as WebStorageModule;
            await webStorageModule.inputShareFromWebStorage(); // 2/2 flow
        } catch (error) {
            console.error(error);
            await inputShareFromSecurityQuestions(); // <-- We'll address this later in this guide.
        }

        const { requiredShares } = tKey.getKeyDetails();
        if (requiredShares <= 0) {
            const indexes = tKey.getCurrentShareIndexes();
            const shares = tKey.shares;
            const reconstructedKey = await tKey.reconstructKey();
        }
        
        const reconstructedKey = await tKey.reconstructKey();
        const metaData = tKey.getMetadata();
        console.log(metaData);

        await performBlockchainOps(reconstructedKey.privKey.toString("hex"));

      } catch (error) {
        console.error(error)
      }
    };

Could anyone please suggest the root cause, initially I thought it might be caused due to blocking pop-ups, but even after disabling the pop-up blocking it wasn't working.
Does it related to the service worker scripts? I have used the same script which is mentioned in the tkey-example (service-worker.ts and serviceWorkerRegistration.ts).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions