Importing private key on devnet fails on one of the nodes

Hi, I’m trying to import a private key to a shared verifier deployed on sapphire devnet and it seems to work fine on most nodes except one which causes the operation to fail, namely https://node-4.dev-node.web3auth.io/sss/jrpc

Here’s the code relevant code snippet I used:

import {
  WEB3_AUTH_LOGIN_PROVIDERS,
  Web3AuthLoginProvider,
  Web3AuthNetworkType,
} from './types'
import Torus, {
  legacyKeyLookup,
  GetPubKeyOrKeyAssign,
  keccak256,
} from '@toruslabs/torus.js'

...

const authInstance = new Torus({
    clientId: web3AuthClientId,
    enableOneKey: true,
    network: web3AuthNetwork,
})
...

type ImportPrivateKeyParams = {
  authInstance: Torus
  network: Web3AuthNetworkType
  verifier: string
  subVerifier?: string
  verifierId: string
  idToken: string
  privateKey: Buffer
}
export const importPrivateKey = async ({
  authInstance,
  network,
  verifier,
  subVerifier,
  verifierId,
  idToken,
  privateKey,
}: ImportPrivateKeyParams) => {
  const keyAlreadyExists = await verifierIdExists({
    verifier,
    verifierId,
    network,
  })
  // not strictly necessary but we really want to make sure we don't overwrite an existing key
  if (keyAlreadyExists) throw new Error('Cannot import: key already exists')

  const fetchNodeDetails = new NodeDetailsManager({network})
  const {torusNodeEndpoints, torusIndexes, torusNodePub} =
    await fetchNodeDetails.getNodeDetails({
      verifier,
      verifierId,
    })
  return await authInstance.importPrivateKey(
    torusNodeEndpoints,
    torusIndexes,
    torusNodePub,
    verifier,
    // got structure from aggregate login logic: https://github.com/torusresearch/CustomAuth/blob/6749a2bc0ff222bf74122f046c74929c4b386bae/src/login.ts#L268
    subVerifier
      ? {
          verifier_id: verifierId,
          verify_params: [{verifier_id: verifierId, idtoken: idToken}],
          sub_verifier_ids: [subVerifier],
        }
      : {verifier_id: verifierId},
    subVerifier ? keccak256(Buffer.from(idToken, 'utf8')).slice(2) : idToken,
    privateKey.toString('hex'),
  )
}

This is the actual network request I made :

curl 'https://node-4.dev-node.web3auth.io/sss/jrpc' \
  -H 'authority: node-4.dev-node.web3auth.io' \
  -H 'accept: */*' \
  -H 'accept-language: en-US,en;q=0.9' \
  -H 'content-type: application/json; charset=utf-8' \
  -H 'origin: https://localhost:8090' \
  -H 'referer: https://localhost:8090/' \
  -H 'sec-ch-ua: "Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "macOS"' \
  -H 'sec-fetch-dest: empty' \
  -H 'sec-fetch-mode: cors' \
  -H 'sec-fetch-site: cross-site' \
  -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36' \
  --data-raw '{"jsonrpc":"2.0","method":"ImportShare","id":10,"params":{"encrypted":"yes","use_temp":true,"distributed_metadata":true,"item":[{"verifier_id":"rafael@nu.fi","verify_params":[{"verifier_id":"rafael@nu.fi","idtoken":"eyJhbGciOiJSUzI1NiIsImtpZCI6IjA5YmNmODAyOGUwNjUzN2Q0ZDNhZTRkODRmNWM1YmFiY2YyYzBmMGEiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20iLCJhenAiOiIxMDk4MDY5MjQ2ODk1LTd2Y2lkdXVndHBuZWdmZ3VzZDZtNmRpcG84cWJ0MjUxLmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29tIiwiYXVkIjoiMTA5ODA2OTI0Njg5NS03dmNpZHV1Z3RwbmVnZmd1c2Q2bTZkaXBvOHFidDI1MS5hcHBzLmdvb2dsZXVzZXJjb250ZW50LmNvbSIsInN1YiI6IjExNDgzMjgwNDg1Mjk5MDY4ODUxMiIsImhkIjoibnUuZmkiLCJlbWFpbCI6InJhZmFlbEBudS5maSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJhdF9oYXNoIjoiRVZ5c3ctbVNhNFptcjA1XzQ0UUhYQSIsIm5vbmNlIjoiOG1hdGt2bThwZHYiLCJuYmYiOjE3MTA0OTM4NDIsIm5hbWUiOiJSYWZhZWwgS29yYmFzIiwicGljdHVyZSI6Imh0dHBzOi8vbGgzLmdvb2dsZXVzZXJjb250ZW50LmNvbS9hL0FDZzhvY0pmelVzMjdYT0cyWTNVYktGbjNWYnBVay1GdnVySlZNNEx6YnJDdzBVdlRnPXM5Ni1jIiwiZ2l2ZW5fbmFtZSI6IlJhZmFlbCIsImZhbWlseV9uYW1lIjoiS29yYmFzIiwibG9jYWxlIjoiZW4iLCJpYXQiOjE3MTA0OTQxNDIsImV4cCI6MTcxMDQ5Nzc0MiwianRpIjoiYjFhODE3OWJjMWU5MGMxMmU2Y2FiNTc2OTQ4NzcyMTNlMGQ5ZjJiZCJ9.sAQjAsQOSpAed1wEANeZGYq8C8_J9bydZz26hiXB7KrAth8hxQuxBYrSFceiZGuMMH1HpVPWhpJsol0dX5i35hNH0eBtUHT4TL74SrBBXgVpmXTFqWecMiow81rg08QK8J30tAowdKkYn3iYlRGiFyePahN6iO2ilFuT_GKsUYaMqW9gE0uPFkuM8JXFQ2Ce2SrWxFkDSgLR2B9OwQxbATXDNtT0GOx_2qFT7rz1EZXaV-N4az8Tt1R46Z_TJgw55LsAOpLx52SKk-FqNw18297CwA9XKBh6Q_s8SRHd8vfgxISto7xGpOdMEAEumiiVNkvz_KTAcoFHpA9Adyj8Ng"}],"sub_verifier_ids":["nufi-w3a-google-shared-vvvv-testt"],"idtoken":"e6e381b72c72ffcb08d7f0442a28c1d6f7cd26aa344f7d9e0e1955124b95fc2d","nodesignatures":[{"signature":"37cc72f91425aa64c4be2f93809c74ea7e0bbdcf639ca8621922557d5f71023f0553291c891a81a7cebd637e61501b55b8b8429f5104c287cb9aa803d6aa304b1c","data":"mug00\u001c27722e9c8c24687986bbbcae0e350cad2194573c381450a7e0fb2f23abbfb5f0\u001c02ebc53b45477f54664ea210c0555291ee92e5e40b411c3ace161046c60e6080\u001c9ca3ec63033ef4fd29176a893c5f744fcedbbdaaa0954a12dee359224204e368\u001cw3a-nufi-google-shared-testttttt\u001c1710494163","nodepubx":"f74389b0a4c8d10d2a687ae575f69b20f412d41ab7f1fe6b358aa14871327247","nodepuby":"54e3a73098ed9bced3ef8821736e9794f9264a1420c0c7ad15d2fa617ba35ef7","nodeindex":"1","pub_key_x":""},{"signature":"b4aacb134155f8640aabd6eb3ace81e93b5161d248ac51f2d2efd1827e285172503b510b98f5335f22c4172519f3e9f76887384569fdf93b7028141d36f18d391c","data":"mug00\u001c27722e9c8c24687986bbbcae0e350cad2194573c381450a7e0fb2f23abbfb5f0\u001c02ebc53b45477f54664ea210c0555291ee92e5e40b411c3ace161046c60e6080\u001c9ca3ec63033ef4fd29176a893c5f744fcedbbdaaa0954a12dee359224204e368\u001cw3a-nufi-google-shared-testttttt\u001c1710494163","nodepubx":"bc38813a6873e526087918507c78fc3a61624670ee851ecfb4f3bef55d027b5a","nodepuby":"ac4b21229f662a0aefdfdac21cf17c3261a392c74a8790db218b34e3e4c1d56a","nodeindex":"2","pub_key_x":""},{"signature":"ce000277004d452c6e431ae1e0e2f438f163bb0d23726558d9cb7eb47384b50e101390615d0ef579ce9b422631e904724665c7b0dfcf45cafeebd84e1003b0181b","data":"mug00\u001c27722e9c8c24687986bbbcae0e350cad2194573c381450a7e0fb2f23abbfb5f0\u001c02ebc53b45477f54664ea210c0555291ee92e5e40b411c3ace161046c60e6080\u001c9ca3ec63033ef4fd29176a893c5f744fcedbbdaaa0954a12dee359224204e368\u001cw3a-nufi-google-shared-testttttt\u001c1710494163","nodepubx":"b56541684ea5fa40c8337b7688d502f0e9e092098962ad344c34e94f06d293fb","nodepuby":"759a998cef79d389082f9a75061a29190eec0cac99b8c25ddcf6b58569dad55c","nodeindex":"3","pub_key_x":""},{"signature":"09bc3fac1e083e036b61e6933d827f3f6f55219e012664f54555a689f02c8ba537b390a228636355dfecfd042f4b3c33994359cd33d61906692e8c2ab78125a41c","data":"mug00\u001c27722e9c8c24687986bbbcae0e350cad2194573c381450a7e0fb2f23abbfb5f0\u001c02ebc53b45477f54664ea210c0555291ee92e5e40b411c3ace161046c60e6080\u001c9ca3ec63033ef4fd29176a893c5f744fcedbbdaaa0954a12dee359224204e368\u001cw3a-nufi-google-shared-testttttt\u001c1710494163","nodepubx":"7bcb058d4c6ffc6ba4bfdfd93d141af35a66338a62c7c27cdad2ae3f8289b767","nodepuby":"336ab1935e41ed4719e162587f0ab55518db4207a1eb36cc72303f1b86689d2b","nodeindex":"4","pub_key_x":""},{"signature":"33edf8d99aa77d4b97ad8c7253cad3efc5f86af0327f2cb626f93a03bd6fb9085d4b3fd0cee8d13d50fbe1492cb1d6e861ca16bfca70bc586fb8ec133131d5261c","data":"mug00\u001c27722e9c8c24687986bbbcae0e350cad2194573c381450a7e0fb2f23abbfb5f0\u001c02ebc53b45477f54664ea210c0555291ee92e5e40b411c3ace161046c60e6080\u001c9ca3ec63033ef4fd29176a893c5f744fcedbbdaaa0954a12dee359224204e368\u001cw3a-nufi-google-shared-testttttt\u001c1710494163","nodepubx":"bf12a136ef94399ea098f926f04e26a4ec4ac70f69cce274e8893704c4951773","nodepuby":"bdd44828020f52ce510e026338216ada184a6867eb4e19fb4c2d495d4a7e15e4","nodeindex":"5","pub_key_x":""}],"verifieridentifier":"w3a-nufi-google-shared-testttttt","pub_key_x":"201619c57f06a6bfd94f92bec3a857c427193f7d5ad7f097fe4717f2c0c79757","pub_key_y":"a999c2f981110082c09112687272771e1e3737594b2eedb1fe33bc5209dff867","encrypted_share":"d6651f618488a286d643a3f9e8796e7f9b1d02793a276b54c60f9f3655f7813d53fc94a9cfc72ee0ca77dc9272074672","encrypted_share_metadata":{"iv":"09631014cc1795af0779af61ad9b2a3a","ephemPublicKey":"047db77da40be7833c14823b5793aa81d0356733249252897696f899b94517c50951f6bcc269832431ce09fc6d1f878759ceb93f13c4c9e7fc34a6345f9b0d38ae","ciphertext":"d6651f618488a286d643a3f9e8796e7f9b1d02793a276b54c60f9f3655f7813d53fc94a9cfc72ee0ca77dc9272074672","mac":"31ff0b1d9513865c5387fecec731c3fc3bdf6aa74c9e6b93a5bfef9693c6dea8","mode":"AES256"},"node_index":4,"key_type":"secp256k1","nonce_data":"eyJkYXRhIjoiOTY2YjQzOTBlZDZmZmExZGQ2N2JkNmYyMjk3NjdkYjUyNjhhNWY3YWU1ZDdiMGY5OTlmZjA3MmVlN2RmY2JkNyIsIm9wZXJhdGlvbiI6ImdldE9yU2V0Tm9uY2UiLCJ0aW1lc3RhbXAiOiI2NWY0MTFkMiJ9","nonce_signature":"ugAMd3PbBr3mOJCNR69g7AGybrg0dCELPNQuyoAetQN7cMJ10mbfcgKKPhutfmtE7zivx2HEOToPNsV8Ed4XiwA=","session_token_exp_second":86400}],"one_key_flow":true}}'

And from that specific node (https://node-4.dev-node.web3auth.io/sss/jrpc) I’m getting the following error response:

{"jsonrpc":"2.0","error":{"code":-32603,"message":"Internal error","data":"Couldn't found keyIndexes for imported share"},"id":10}

Whereas the rest of the nodes replied back apparently without issues. The same node keeps failing even if I tried importing several different keys for several different accounts. Interestingly, for some accounts, when I log in through the target verifier after the “failed” import, the recovered key is the same as the one I intended to import, however for some other accounts it differs, as if sometimes the import went through fine regardless and sometimes it resulted in a corrupted key.

I’m using the 12.2.0 (latest) version of the @toruslabs/torus.js lib.

Do you know what can be causing this issue? Is there some issue with that particular node?

Hi, we have fixed this issue in our latest sdk pre-release which is in alpha right now.
Can you please try out torus.js version, 13.0.0-alpha.1 and let me know if you face any issues while using the latest version.

Thanks

Thanks! Seems to work fine now

2 Likes

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