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

HcsDid creation throws 'unmatched constructor' on indirect call from HcsIdentityNetwork.generateDid #23

Open
hippeus opened this issue Sep 30, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@hippeus
Copy link

hippeus commented Sep 30, 2021

Description

HcsDid throws Error: Couldn't find constructor when called from an instance of HcsIdentityNetwork through generateDid() method. This happens ONLY when HcsIdentityNetwork object is created via fromAddressBookFile or fromAddressBook static methods, both create AddressBook object without private property fileId set accordingly.

The workaround which returns AddressBook from HcsIdentityNetwork instance through getAddressBoook() to set manually fileId on AddressBook with setFileId API does not solve the issue either, as HcsDid constructor still fails on args[2] instanceof sdk_1.FileId condition. This is weird, as args[2] resolves to FileId {shard: Long, realm: Long, num: Long, _checksum: null}, which is precisely what sdk_1.FileId type.

NOTE: If HcsIdentityNetwork object is bootstrapped through HcsIdentityNetworkBuilder() API everything works fine.

NOTE 2: Call to HcsIdentityNetwork.fromAddressBookFile() API with fileId already submitted to HFS fetches properly AddressBook file (just not instantiates the fileId property on AddressBook Object).

Steps to reproduce

  1. Submit AddressBook to Hedera File Service (out-of-bound), keep the fileId reference number as FID.

  2. Create new IDENTITY_NETWORK object though HcsIdentityNetwork.fromAddressBookFile(CLIENT, 'testnet', new FileId(FID))

  3. Confirm that IDENTITY_NETWORK.getAddressBook() return object without fileId set to FID.

  4. Try to generate DID by calling IDENTITY_NETWORK.generateDid(PUBKEY, true)

  5. Operation should thrown an error from HcsDid constructor

  6. Retry step 4, but first manually set fileId property on IDENTITY_NETWORK address book.

  7. Operation still thrown the same error as in step 5.

Additional context

ENV:
node: v14.17.6
ts-node: v10.2.1
npm: 6.14.15
macOS: Darwin Kernel Version 20.5.0: Sat May 8 05:10:33 PDT 2021; root:xnu-7195.121.3~9/RELEASE_X86_64 x86_64

tsconfig.json:

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2019",
    "sourceMap": true,
    "rootDir": ".",
    "outDir": "./dist",
    "baseUrl": "./",
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "allowJs": true,
    "incremental": true,
    "skipLibCheck": true
  }
}

package-lock.json:

....
   "@grpc/grpc-js": {
      "version": "1.3.7",
      "resolved": "https://registry.npmjs.org/@grpc/grpc-js/-/grpc-js-1.3.7.tgz",
      "integrity": "sha512-CKQVuwuSPh40tgOkR7c0ZisxYRiN05PcKPW72mQL5y++qd7CwBRoaJZvU5xfXnCJDFBmS3qZGQ71Frx6Ofo2XA==",
      "requires": {
        "@types/node": ">=12.12.47"
      }
    },
    "@hashgraph/cryptography": {
      "version": "1.0.20",
      "resolved": "https://registry.npmjs.org/@hashgraph/cryptography/-/cryptography-1.0.20.tgz",
      "integrity": "sha512-rdKKnENJfs0gsqAtY+7nzpG9TQshtnf+F3/PdH8z+qdy4mo4RSULBMc55FkWWNZLnoA4/34wEW8kohjFEzsLRA==",
      "requires": {
        "@types/crypto-js": "^4.0.2",
        "@types/utf8": "^3.0.0",
        "bignumber.js": "^9.0.1",
        "crypto-js": "^4.0.0",
        "expo-crypto": "^9.2.0",
        "expo-random": "^11.2.0",
        "fastestsmallesttextencoderdecoder": "^1.0.22",
        "js-base64": "^3.6.1",
        "tweetnacl": "^1.0.3"
      }
    },
    "@hashgraph/did-sdk-js": {
      "version": "0.1.1",
      "resolved": "https://registry.npmjs.org/@hashgraph/did-sdk-js/-/did-sdk-js-0.1.1.tgz",
      "integrity": "sha512-YL+8pB8RqkUfvCKowuYEJ6RNexfHFv+RESD7UBn/CMvk70ECIjTb4oBVcqbtPgmDrt/Ayz4itueCob37GTAglw==",
      "requires": {
        "@hashgraph/sdk": "^2.0.20",
        "bs58": "^4.0.1",
        "js-base64": "^3.6.1",
        "moment": "^2.29.1"
      },
      "dependencies": {
        "@hashgraph/proto": {
          "version": "2.0.0",
          "resolved": "https://registry.npmjs.org/@hashgraph/proto/-/proto-2.0.0.tgz",
          "integrity": "sha512-SgvtrTgZXpAk9c8LuOoOEs4RNqmSZX8/fYu8oDcqpRxAi5mnyChCkLcSneOyWPDJZmaEV1mz+HeO1HJAJUURAw==",
          "requires": {
            "protobufjs": "^6.11.2"
          }
        },
        "@hashgraph/sdk": {
          "version": "2.0.30",
          "resolved": "https://registry.npmjs.org/@hashgraph/sdk/-/sdk-2.0.30.tgz",
          "integrity": "sha512-aTAeOtnn6EBYTrkXcoE0dfEalHyEOg9fj79hruRHTdZb+tNRVRPr8XYriRy8CUZEIknJYQTFSfvrSEc7C8b6Zw==",
          "requires": {
            "@grpc/grpc-js": "^1.3.4",
            "@hashgraph/cryptography": "^1.0.20",
            "@hashgraph/proto": "2.0.0",
            "@types/crypto-js": "^4.0.2",
            "@types/utf8": "^3.0.0",
            "bignumber.js": "^9.0.1",
            "crypto-js": "^4.0.0",
            "js-base64": "^3.6.1",
            "long": "^4.0.0",
            "protobufjs": "^6.11.2",
            "utf8": "^3.0.0"
          }
        }
      }
    },
    "@hashgraph/proto": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/@hashgraph/proto/-/proto-2.0.0.tgz",
      "integrity": "sha512-SgvtrTgZXpAk9c8LuOoOEs4RNqmSZX8/fYu8oDcqpRxAi5mnyChCkLcSneOyWPDJZmaEV1mz+HeO1HJAJUURAw==",
      "requires": {
        "protobufjs": "^6.11.2"
      }
    },
    "@hashgraph/sdk": {
      "version": "2.0.30",
      "resolved": "https://registry.npmjs.org/@hashgraph/sdk/-/sdk-2.0.30.tgz",
      "integrity": "sha512-aTAeOtnn6EBYTrkXcoE0dfEalHyEOg9fj79hruRHTdZb+tNRVRPr8XYriRy8CUZEIknJYQTFSfvrSEc7C8b6Zw==",
      "requires": {
        "@grpc/grpc-js": "^1.3.4",
        "@hashgraph/cryptography": "^1.0.20",
        "@hashgraph/proto": "2.0.0",
        "@types/crypto-js": "^4.0.2",
        "@types/utf8": "^3.0.0",
        "bignumber.js": "^9.0.1",
        "crypto-js": "^4.0.0",
        "js-base64": "^3.6.1",
        "long": "^4.0.0",
        "protobufjs": "^6.11.2",
        "utf8": "^3.0.0"
      }
    },
....

Hedera network

testnet

Version

v0.1.1

Operating system

macOS

@hippeus hippeus added the bug Something isn't working label Sep 30, 2021
@linasi
Copy link

linasi commented Jan 18, 2022

Hey, the problem here is the dependency tree. Project duplicates @hashgraph/sdk package. @hashgraph/did-sdk-js has it's own nested dependency that is only used inside the scope of the package.
When instance is created by using one copy of the package and later used in conditions like:

if (
  (args[1] instanceof sdk_1.PrivateKey) &&
  (args[2] instanceof sdk_1.FileId) &&
  (args[4] instanceof sdk_1.TopicId) 
) { ... }

where sdk_1.PrivateKey loaded from another copy of the package - instanceof returns false.

Removing nested dependencies from package-lock.json:

    "@hashgraph/did-sdk-js": {
      "version": "0.1.1",
      "resolved": "https://registry.npmjs.org/@hashgraph/did-sdk-js/-/did-sdk-js-0.1.1.tgz",
      "integrity": "sha512-YL+8pB8RqkUfvCKowuYEJ6RNexfHFv+RESD7UBn/CMvk70ECIjTb4oBVcqbtPgmDrt/Ayz4itueCob37GTAglw==",
      "requires": {
        "@hashgraph/sdk": "^2.0.20",
        "bs58": "^4.0.1",
        "js-base64": "^3.6.1",
        "moment": "^2.29.1"
      },
    },
    "@hashgraph/proto": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/@hashgraph/proto/-/proto-2.0.0.tgz",
      "integrity": "sha512-SgvtrTgZXpAk9c8LuOoOEs4RNqmSZX8/fYu8oDcqpRxAi5mnyChCkLcSneOyWPDJZmaEV1mz+HeO1HJAJUURAw==",
      "requires": {
        "protobufjs": "^6.11.2"
      }
    },
    "@hashgraph/sdk": {
      "version": "2.0.30",
      "resolved": "https://registry.npmjs.org/@hashgraph/sdk/-/sdk-2.0.30.tgz",
      "integrity": "sha512-aTAeOtnn6EBYTrkXcoE0dfEalHyEOg9fj79hruRHTdZb+tNRVRPr8XYriRy8CUZEIknJYQTFSfvrSEc7C8b6Zw==",
      "requires": {
        "@grpc/grpc-js": "^1.3.4",
        "@hashgraph/cryptography": "^1.0.20",
        "@hashgraph/proto": "2.0.0",
        "@types/crypto-js": "^4.0.2",
        "@types/utf8": "^3.0.0",
        "bignumber.js": "^9.0.1",
        "crypto-js": "^4.0.0",
        "js-base64": "^3.6.1",
        "long": "^4.0.0",
        "protobufjs": "^6.11.2",
        "utf8": "^3.0.0"
      }
    },

and reinstalling packages solves the problem.

I think the issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants