MetaMask / MetaMask/tkey

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

Open
#183 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
181
Forks
53
PR merge metrics
No merged PRs in 30d

Description

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

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

### Code Snippet
```js

// 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:

```js
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)](https://github.com/tkey/tkey-example/tree/main/src).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with tKey.initialize() and the getGenericMetadataWithTransitionStates error, then compare the service-worker.ts and serviceWorkerRegistration.ts files from tkey-example across Chrome, Firefox, and Safari. Reproduce the supplied initialization flow and inspect browser-specific service-worker or storage behavior; done means initialization succeeds without the reported error in the affected browsers.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
authentication, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.