Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue#20 #97

Merged
merged 7 commits into from
May 4, 2023
Merged

Issue#20 #97

merged 7 commits into from
May 4, 2023

Conversation

Ansonhkg
Copy link
Collaborator

@Ansonhkg Ansonhkg commented May 4, 2023

What

Resolved issue #20 with a previous attempt in PR #37, but it led to unexpected behavior when combining shares in Node.js. As a result, the changes were reverted in PR #50 to address the problem more effectively.

Error

warn  - ./node_modules/@lit-protocol/ecdsa-sdk/src/lib/ecdsa-sdk.js
Critical dependency: the request of a dependency is an expression

Import trace for requested module:
./node_modules/@lit-protocol/ecdsa-sdk/src/lib/ecdsa-sdk.js
./node_modules/@lit-protocol/ecdsa-sdk/src/index.js
./node_modules/@lit-protocol/crypto/src/lib/crypto.js
./node_modules/@lit-protocol/crypto/src/index.js
./node_modules/@lit-protocol/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.js
./node_modules/@lit-protocol/lit-node-client-nodejs/src/index.js
./node_modules/@lit-protocol/lit-node-client/src/index.js
./adapters/litProtocol/hooks/useLitProtocol.tsx

Problem

webpack can’t resolve the require statically and imports the entire package due to:

  imports.wbg.__wbg_require_edfaedd93e302925 = function () {
    console.warn('[ECDSA-SDK NodeJS] __wbg_require_edfaedd93e302925');
    return handleError(function (arg0, arg1, arg2) {
      var ret = require(getStringFromWasm0(arg1, arg2)); **<-- THIS LINE **
      return addHeapObject(_crypto);
    }, arguments);
  };

Solution

Find out what the String is from WASM

  imports.wbg.__wbg_require_edfaedd93e302925 = function () {
    console.warn('[ECDSA-SDK NodeJS] __wbg_require_edfaedd93e302925');
    return handleError(function (arg0, arg1, arg2) {

      const uint8Memory = getUint8Memory0().subarray(arg1, arg1 + arg2);
      console.log("uint8Memory:", uint8Memory);
      const decodedText = (new TextDecoder()).decode(uint8Memory);
      console.log("decodedText:", decodedText)
      // the decoded string is "crypto" **<-- (1) **

      var ret = require(getStringFromWasm0(arg1, arg2)); 
      return addHeapObject(_crypto);
    }, arguments);
  };

Figured out iscrypto which is needed in nodejs but for browser we could just use the browser crypto, so

  imports.wbg.__wbg_require_edfaedd93e302925 = function () {
    console.warn('[ECDSA-SDK NodeJS] __wbg_require_edfaedd93e302925');
    return handleError(function (arg0, arg1, arg2) {
      let _crypto;

      try {
       // nodejs
        _crypto = require('crypto');
      } catch (e) {
       // browser
        _crypto = globalThis.crypto;
      }
      return addHeapObject(_crypto);
    }, arguments);
  };

@vercel
Copy link

vercel bot commented May 4, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
html-test-app-lit-js-sdk-v2 ✅ Ready (Inspect) Visit Preview May 4, 2023 1:04pm

@Ansonhkg Ansonhkg merged commit 3c3f51b into master May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant