hashgraph / hashgraph/did-sdk-js

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

Open
#23 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
43
Forks
21
PR merge metrics
No merged PRs in 30d

Description

### 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.
6. 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.