From 4eb91b866fbbf577509d766375bec9d4a6d9df09 Mon Sep 17 00:00:00 2001 From: olegnn Date: Fri, 22 Nov 2024 12:15:25 +0100 Subject: [PATCH] Allow to pass `wallet` to `CheqdAPI`, misc tweaks --- examples/CHANGELOG.md | 9 +++++++ examples/package.json | 8 +++--- packages/cheqd-blockchain-api/CHANGELOG.md | 11 ++++++++ packages/cheqd-blockchain-api/package.json | 4 +-- packages/cheqd-blockchain-api/src/index.js | 27 +++++++++---------- .../cheqd-blockchain-api/src/wallet/index.js | 1 + .../cheqd-blockchain-modules/CHANGELOG.md | 11 ++++++++ .../cheqd-blockchain-modules/package.json | 6 ++--- .../tests/attest-module.test.js | 6 ++--- .../tests/blob-module.test.js | 6 ++--- .../tests/constants.js | 8 +++++- .../tests/did-module.test.js | 6 ++--- .../tests/offchain-signatures-module.test.js | 10 +++---- packages/credential-sdk/CHANGELOG.md | 6 +++++ packages/credential-sdk/package.json | 2 +- .../types/did/onchain/typed-did/cheqd-did.js | 14 ++++++++-- .../credential-sdk/src/utils/interfaces.js | 20 ++++++++------ packages/dock-blockchain-api/CHANGELOG.md | 7 +++++ packages/dock-blockchain-api/package.json | 4 +-- packages/dock-blockchain-modules/CHANGELOG.md | 11 ++++++++ packages/dock-blockchain-modules/package.json | 6 ++--- .../src/offchain-signatures/internal.js | 20 ++++++++++---- 22 files changed, 144 insertions(+), 59 deletions(-) create mode 100644 packages/cheqd-blockchain-api/src/wallet/index.js diff --git a/examples/CHANGELOG.md b/examples/CHANGELOG.md index 958c81c91..a5d979078 100644 --- a/examples/CHANGELOG.md +++ b/examples/CHANGELOG.md @@ -1,5 +1,14 @@ # @docknetwork/sdk-examples +## 0.5.1 + +### Patch Changes + +- Updated dependencies + - @docknetwork/dock-blockchain-modules@0.8.0 + - @docknetwork/credential-sdk@0.12.0 + - @docknetwork/dock-blockchain-api@0.6.1 + ## 0.5.0 ### Minor Changes diff --git a/examples/package.json b/examples/package.json index ae8fa71d2..472218460 100644 --- a/examples/package.json +++ b/examples/package.json @@ -2,7 +2,7 @@ "name": "@docknetwork/sdk-examples", "private": true, "type": "module", - "version": "0.5.0", + "version": "0.5.1", "scripts": { "bbs-dock-example": "babel-node ./bbs-dock.js", "claim-deduction-example": "babel-node ./claim-deduction.js", @@ -19,9 +19,9 @@ "lint": "eslint \"*.js\"" }, "dependencies": { - "@docknetwork/credential-sdk": "0.11.0", - "@docknetwork/dock-blockchain-api": "0.6.0", - "@docknetwork/dock-blockchain-modules": "0.7.0" + "@docknetwork/credential-sdk": "0.12.0", + "@docknetwork/dock-blockchain-api": "0.6.1", + "@docknetwork/dock-blockchain-modules": "0.8.0" }, "devDependencies": { "babel-eslint": "^10.1.0", diff --git a/packages/cheqd-blockchain-api/CHANGELOG.md b/packages/cheqd-blockchain-api/CHANGELOG.md index 4ca17dc1d..26a1b7b60 100644 --- a/packages/cheqd-blockchain-api/CHANGELOG.md +++ b/packages/cheqd-blockchain-api/CHANGELOG.md @@ -1,5 +1,16 @@ # @docknetwork/cheqd-blockchain-api +## 0.11.0 + +### Minor Changes + +- Allow to pass `wallet` to `CheqdAPI`, misc tweaks + +### Patch Changes + +- Updated dependencies + - @docknetwork/credential-sdk@0.12.0 + ## 0.10.0 ### Minor Changes diff --git a/packages/cheqd-blockchain-api/package.json b/packages/cheqd-blockchain-api/package.json index 71ba37058..97bdaaf2a 100644 --- a/packages/cheqd-blockchain-api/package.json +++ b/packages/cheqd-blockchain-api/package.json @@ -1,6 +1,6 @@ { "name": "@docknetwork/cheqd-blockchain-api", - "version": "0.10.0", + "version": "0.11.0", "license": "MIT", "main": "./dist/esm/index.js", "type": "module", @@ -34,7 +34,7 @@ }, "dependencies": { "@cheqd/sdk": "cjs", - "@docknetwork/credential-sdk": "0.11.0" + "@docknetwork/credential-sdk": "0.12.0" }, "devDependencies": { "@babel/cli": "^7.24.1", diff --git a/packages/cheqd-blockchain-api/src/index.js b/packages/cheqd-blockchain-api/src/index.js index 89f5bfb45..4298bf2b7 100644 --- a/packages/cheqd-blockchain-api/src/index.js +++ b/packages/cheqd-blockchain-api/src/index.js @@ -4,7 +4,6 @@ import { maybeToJSONString, fmtIter, } from '@docknetwork/credential-sdk/utils'; -import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing'; import { DIDModule, ResourceModule, @@ -55,28 +54,25 @@ export class CheqdAPI extends AbstractApiProvider { }; /** - * Initializes `CheqdAPI` with the supplied url and mnemonic. + * Initializes `CheqdAPI` with the supplied url, wallet and network type. * @param {object} configuration * @param {string} [configuration.url] - * @param {string} [configuration.mnemonic] + * @param {*} [configuration.wallet] * @param {string} [configuration.network] * @returns {this} */ - async init({ url, mnemonic, network } = {}) { + async init({ url, wallet, network } = {}) { if (network !== CheqdNetwork.Mainnet && network !== CheqdNetwork.Testnet) { throw new Error( `Invalid network provided: \`${network}\`, expected one of \`${fmtIter( Object.values(CheqdNetwork), )}\``, ); - } else if (!mnemonic) { - throw new Error('`mnemonic` must be provided'); + } else if (wallet == null) { + throw new Error('`wallet` must be provided'); } this.ensureNotInitialized(); - const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, { - prefix: 'cheqd', - }); const options = { modules: [DIDModule, ResourceModule], rpcUrl: url, @@ -85,8 +81,8 @@ export class CheqdAPI extends AbstractApiProvider { }; const sdk = await createCheqdSDK(options); - this.ensureNotInitialized().sdk = sdk; - this.network = network; + this.ensureNotInitialized(); + this.sdk = sdk; return this; } @@ -95,8 +91,9 @@ export class CheqdAPI extends AbstractApiProvider { * @returns {void} */ async disconnect() { + this.ensureInitialized(); + delete this.sdk; - delete this.network; } /** @@ -184,9 +181,9 @@ export class CheqdAPI extends AbstractApiProvider { if (id instanceof NamespaceDid) { if (id.isCheqd) { if (id.asCheqd.isTestnet) { - return this.network === CheqdNetwork.Testnet; + return this.sdk.options.network === CheqdNetwork.Testnet; } else if (id.asCheqd.isMainnet) { - return this.network === CheqdNetwork.Mainnet; + return this.sdk.options.network === CheqdNetwork.Mainnet; } } } else if (id instanceof DIDRef) { @@ -200,3 +197,5 @@ export class CheqdAPI extends AbstractApiProvider { return false; } } + +export { CheqdNetwork }; diff --git a/packages/cheqd-blockchain-api/src/wallet/index.js b/packages/cheqd-blockchain-api/src/wallet/index.js new file mode 100644 index 000000000..0b35aa80d --- /dev/null +++ b/packages/cheqd-blockchain-api/src/wallet/index.js @@ -0,0 +1 @@ +export * from '@cosmjs/proto-signing'; diff --git a/packages/cheqd-blockchain-modules/CHANGELOG.md b/packages/cheqd-blockchain-modules/CHANGELOG.md index e8c520b60..1b973f3e2 100644 --- a/packages/cheqd-blockchain-modules/CHANGELOG.md +++ b/packages/cheqd-blockchain-modules/CHANGELOG.md @@ -1,5 +1,16 @@ # @docknetwork/cheqd-blockchain-modules +## 0.10.0 + +### Minor Changes + +- Allow to pass `wallet` to `CheqdAPI`, misc tweaks + +### Patch Changes + +- Updated dependencies + - @docknetwork/credential-sdk@0.12.0 + ## 0.9.0 ### Minor Changes diff --git a/packages/cheqd-blockchain-modules/package.json b/packages/cheqd-blockchain-modules/package.json index 32add19f9..5565ee7ab 100644 --- a/packages/cheqd-blockchain-modules/package.json +++ b/packages/cheqd-blockchain-modules/package.json @@ -1,6 +1,6 @@ { "name": "@docknetwork/cheqd-blockchain-modules", - "version": "0.9.0", + "version": "0.10.0", "type": "module", "license": "MIT", "main": "./dist/esm/index.js", @@ -33,7 +33,7 @@ "node": ">=18.0.0" }, "dependencies": { - "@docknetwork/credential-sdk": "0.11.0" + "@docknetwork/credential-sdk": "0.12.0" }, "devDependencies": { "@babel/cli": "^7.24.1", @@ -42,7 +42,7 @@ "@babel/plugin-syntax-import-attributes": "^7.25.6", "@babel/plugin-transform-modules-commonjs": "^7.24.1", "@babel/preset-env": "^7.24.3", - "@docknetwork/cheqd-blockchain-api": "0.10.0", + "@docknetwork/cheqd-blockchain-api": "0.11.0", "@rollup/plugin-alias": "^4.0.2", "@rollup/plugin-babel": "^6.0.4", "@rollup/plugin-commonjs": "^24.0.0", diff --git a/packages/cheqd-blockchain-modules/tests/attest-module.test.js b/packages/cheqd-blockchain-modules/tests/attest-module.test.js index 8fd7fd671..d55bf9620 100644 --- a/packages/cheqd-blockchain-modules/tests/attest-module.test.js +++ b/packages/cheqd-blockchain-modules/tests/attest-module.test.js @@ -3,7 +3,7 @@ import { CheqdTestnetDid } from "@docknetwork/credential-sdk/types"; import { MultiApiDIDModule, MultiApiAttestModule } from "@docknetwork/credential-sdk/modules"; import generateAttestModuleTests from "@docknetwork/credential-sdk/modules/tests/attest-module"; import CheqdDIDModule from "../src/did/module"; -import { faucet, url } from "./constants"; +import { faucet, url, network } from "./constants"; import CheqdAttestModule from "../src/attest/module"; describe("AttestModule", () => { @@ -12,8 +12,8 @@ describe("AttestModule", () => { beforeAll(async () => { await cheqd.init({ url: url, - mnemonic: faucet.mnemonic, - network: "testnet", + wallet: await faucet.wallet(), + network, }); }); diff --git a/packages/cheqd-blockchain-modules/tests/blob-module.test.js b/packages/cheqd-blockchain-modules/tests/blob-module.test.js index 992b882cc..65025f02c 100644 --- a/packages/cheqd-blockchain-modules/tests/blob-module.test.js +++ b/packages/cheqd-blockchain-modules/tests/blob-module.test.js @@ -6,7 +6,7 @@ import { import { MultiApiBlobModule } from "@docknetwork/credential-sdk/modules"; import generateBlobModuleTests from "@docknetwork/credential-sdk/modules/tests/blob-module"; import CheqdDIDModule from "../src/did/module"; -import { faucet, url } from "./constants"; +import { faucet, url, network } from "./constants"; import CheqdBlobModule from "../src/blob/module"; import { MultiApiDIDModule } from "@docknetwork/credential-sdk/modules"; @@ -16,8 +16,8 @@ describe("BlobModule", () => { beforeAll(async () => { await cheqd.init({ url, - mnemonic: faucet.mnemonic, - network: "testnet", + wallet: await faucet.wallet(), + network, }); }); diff --git a/packages/cheqd-blockchain-modules/tests/constants.js b/packages/cheqd-blockchain-modules/tests/constants.js index 6608fe20e..6097f1b52 100644 --- a/packages/cheqd-blockchain-modules/tests/constants.js +++ b/packages/cheqd-blockchain-modules/tests/constants.js @@ -1,9 +1,15 @@ +import { DirectSecp256k1HdWallet } from '@docknetwork/cheqd-blockchain-api/wallet'; +import { CheqdNetwork } from '@docknetwork/cheqd-blockchain-api'; + export const faucet = { prefix: "cheqd", minimalDenom: "ncheq", mnemonic: process.env.CHEQD_MNEMONIC || "steak come surprise obvious remain black trouble measure design volume retreat float coach amused match album moment radio stuff crack orphan ranch dose endorse", - address: process.env.CHEQD_SENDER_ADDRESS || "cheqd1fgl67nvjdkrnaemjzg5sqvck9fcst4vt99gmma", + async wallet() { + return await DirectSecp256k1HdWallet.fromMnemonic(this.mnemonic, { prefix: 'cheqd' }) + } }; export const url = process.env.CHEQD_RPC_URL || "http://localhost:26657"; +export const network = process.env.CHEQD_NETWORK || CheqdNetwork.Testnet; diff --git a/packages/cheqd-blockchain-modules/tests/did-module.test.js b/packages/cheqd-blockchain-modules/tests/did-module.test.js index a8c2b73f3..58123545b 100644 --- a/packages/cheqd-blockchain-modules/tests/did-module.test.js +++ b/packages/cheqd-blockchain-modules/tests/did-module.test.js @@ -2,7 +2,7 @@ import { CheqdAPI } from "@docknetwork/cheqd-blockchain-api"; import { CheqdTestnetDid } from "@docknetwork/credential-sdk/types"; import didModuleTests from "@docknetwork/credential-sdk/modules/tests/did-module"; import CheqdDIDModule from "../src/did/module"; -import { faucet, url } from "./constants"; +import { faucet, url, network } from "./constants"; import { MultiApiDIDModule } from "@docknetwork/credential-sdk/modules"; describe("DIDModule", () => { @@ -11,8 +11,8 @@ describe("DIDModule", () => { beforeAll(async () => { await cheqd.init({ url, - mnemonic: faucet.mnemonic, - network: "testnet", + wallet: await faucet.wallet(), + network, }); }); diff --git a/packages/cheqd-blockchain-modules/tests/offchain-signatures-module.test.js b/packages/cheqd-blockchain-modules/tests/offchain-signatures-module.test.js index 6f1c7d5b8..0f52c919b 100644 --- a/packages/cheqd-blockchain-modules/tests/offchain-signatures-module.test.js +++ b/packages/cheqd-blockchain-modules/tests/offchain-signatures-module.test.js @@ -1,17 +1,17 @@ -import { CheqdAPI } from "@docknetwork/cheqd-blockchain-api"; +import { CheqdAPI, CheqdNetwork } from "@docknetwork/cheqd-blockchain-api"; import { CheqdTestnetDid, CheqdOffchainSignatureParamsRef, } from "@docknetwork/credential-sdk/types"; import { MultiApiOffchainSignaturesModule } from "@docknetwork/credential-sdk/modules"; import generateOffchainSignaturesModuleTests from "@docknetwork/credential-sdk/modules/tests/offchain-signatures-module"; -import { faucet, url } from "./constants"; +import { MultiApiDIDModule, MultiApiCoreModules } from "@docknetwork/credential-sdk/modules"; +import { faucet, url, network } from "./constants"; import { CheqdOffchainSignaturesModule, CheqdDIDModule, CheqdCoreModules } from "../src"; -import { MultiApiDIDModule, MultiApiCoreModules } from "@docknetwork/credential-sdk/modules"; import CheqdBBSModule from "../src/offchain-signatures/bbs"; import CheqdBBSPlusModule from "../src/offchain-signatures/bbs-plus"; import CheqdPSModule from "../src/offchain-signatures/ps"; @@ -22,8 +22,8 @@ describe("OffchainSignaturesModule", () => { beforeAll(async () => { await cheqd.init({ url, - mnemonic: faucet.mnemonic, - network: "testnet", + wallet: await faucet.wallet(), + network, }); }); diff --git a/packages/credential-sdk/CHANGELOG.md b/packages/credential-sdk/CHANGELOG.md index b7e5fe0bb..79e8967a0 100644 --- a/packages/credential-sdk/CHANGELOG.md +++ b/packages/credential-sdk/CHANGELOG.md @@ -1,5 +1,11 @@ # @docknetwork/credential-sdk +## 0.12.0 + +### Minor Changes + +- Allow to pass `wallet` to `CheqdAPI`, misc tweaks + ## 0.11.0 ### Minor Changes diff --git a/packages/credential-sdk/package.json b/packages/credential-sdk/package.json index 13bfea74a..09e59053a 100644 --- a/packages/credential-sdk/package.json +++ b/packages/credential-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@docknetwork/credential-sdk", - "version": "0.11.0", + "version": "0.12.0", "license": "MIT", "type": "module", "files": [ diff --git a/packages/credential-sdk/src/types/did/onchain/typed-did/cheqd-did.js b/packages/credential-sdk/src/types/did/onchain/typed-did/cheqd-did.js index 3af8aa51d..cbaa0a05d 100644 --- a/packages/credential-sdk/src/types/did/onchain/typed-did/cheqd-did.js +++ b/packages/credential-sdk/src/types/did/onchain/typed-did/cheqd-did.js @@ -34,8 +34,18 @@ export class CheqdDid extends withQualifier(TypedEnum, true) { return this.Class?.Qualifier; } - static random() { - return new this(this.Class.random()); + static random(network) { + if (this.Class != null) { + return new this(this.Class.random()); + } else if (network === 'testnet') { + // eslint-disable-next-line no-use-before-define + return CheqdTestnetDid.random(); + } else if (network === 'mainnet') { + // eslint-disable-next-line no-use-before-define + return CheqdMainnetDid.random(); + } else { + throw new Error(`Unknown network provided: \`${network}\`, expected \`mainnet\` or \`testnet\``); + } } toJSON() { diff --git a/packages/credential-sdk/src/utils/interfaces.js b/packages/credential-sdk/src/utils/interfaces.js index ff1718317..77089f2a1 100644 --- a/packages/credential-sdk/src/utils/interfaces.js +++ b/packages/credential-sdk/src/utils/interfaces.js @@ -1,11 +1,17 @@ /** - * Attempts to call `value.toJSON()`, returns `value` if method doesn't exist. + * Attempts to call `value.toJSON()`, returns `JSON.parse(JSON.stringify(value))` if method doesn't exist. * @template T * @param {T} value - * @returns {T | Object} + * @returns {object} */ -export const maybeToJSON = (value) => (value && typeof value.toJSON === 'function' ? value.toJSON() : value); +export const maybeToJSON = (value) => (value && typeof value.toJSON === 'function' ? value.toJSON() : JSON.parse(JSON.stringify(value))); +/** + * Attempts to call `value.toJSON()` and stringify the result, returns `String(value)` in case of failure. + * @template T + * @param {T} value + * @returns {string} + */ export const maybeToJSONString = (value) => { const json = maybeToJSON(value); @@ -29,15 +35,15 @@ export const maybeEq = (value, other) => (value && typeof value.eq === 'function * Attempts to call `value.toHuman()` or `value.toJSON`, returns `value` if methods don't exist. * @template T * @param {T} value - * @returns {T | Object} + * @returns {object} */ export const maybeToHuman = (obj) => (obj && typeof obj.toHuman === 'function' ? obj.toHuman() : maybeToJSON(obj)); /** - * Attempts to call `value.toNumber()`, returns `value` if method doesn't exist. + * Attempts to call `value.toNumber()`, returns `+value` if method doesn't exist. * @template T * @param {T} value - * @returns {T | number} + * @returns {number} */ export const maybeToNumber = (value) => (value && typeof value.toNumber === 'function' ? value.toNumber() : +value); @@ -52,7 +58,6 @@ export const NotAConstructor = Symbol.for( * Attempts to intantiate new object of the supplied class using provided arguments. * @param Class * @param args - * @returns {T | number} */ export const maybeNew = (Class, args) => (!Class[NotAConstructor] ? new Class(...args) : Class.apply(Class, args)); @@ -60,7 +65,6 @@ export const maybeNew = (Class, args) => (!Class[NotAConstructor] ? new Class(.. * Attempts to create new instance of the supplied class using `Class.from(obj)`, instantiates class if `from` doesn't exist. * @param Class * @param args - * @returns {T | number} */ export const maybeFrom = (klass, obj) => (typeof klass.from === 'function' ? klass.from(obj) : maybeNew(klass, [obj])); diff --git a/packages/dock-blockchain-api/CHANGELOG.md b/packages/dock-blockchain-api/CHANGELOG.md index f06974950..1d1a4f1b7 100644 --- a/packages/dock-blockchain-api/CHANGELOG.md +++ b/packages/dock-blockchain-api/CHANGELOG.md @@ -1,5 +1,12 @@ # @docknetwork/dock-blockchain-api +## 0.6.1 + +### Patch Changes + +- Updated dependencies + - @docknetwork/credential-sdk@0.12.0 + ## 0.6.0 ### Minor Changes diff --git a/packages/dock-blockchain-api/package.json b/packages/dock-blockchain-api/package.json index d5d65978b..f9d8ded99 100644 --- a/packages/dock-blockchain-api/package.json +++ b/packages/dock-blockchain-api/package.json @@ -1,6 +1,6 @@ { "name": "@docknetwork/dock-blockchain-api", - "version": "0.6.0", + "version": "0.6.1", "license": "MIT", "main": "./dist/esm/index.js", "type": "module", @@ -89,7 +89,7 @@ "@polkadot/api": "10.12.4" }, "dependencies": { - "@docknetwork/credential-sdk": "0.11.0", + "@docknetwork/credential-sdk": "0.12.0", "@docknetwork/node-types": "^0.17.0", "@juanelas/base64": "^1.0.5", "@polkadot/api": "10.12.4", diff --git a/packages/dock-blockchain-modules/CHANGELOG.md b/packages/dock-blockchain-modules/CHANGELOG.md index f8aa878aa..4f2597ea1 100644 --- a/packages/dock-blockchain-modules/CHANGELOG.md +++ b/packages/dock-blockchain-modules/CHANGELOG.md @@ -1,5 +1,16 @@ # @docknetwork/dock-blockchain-modules +## 0.8.0 + +### Minor Changes + +- Allow to pass `wallet` to `CheqdAPI`, misc tweaks + +### Patch Changes + +- Updated dependencies + - @docknetwork/credential-sdk@0.12.0 + ## 0.7.0 ### Minor Changes diff --git a/packages/dock-blockchain-modules/package.json b/packages/dock-blockchain-modules/package.json index 43ecef6c8..ba87f2336 100644 --- a/packages/dock-blockchain-modules/package.json +++ b/packages/dock-blockchain-modules/package.json @@ -1,6 +1,6 @@ { "name": "@docknetwork/dock-blockchain-modules", - "version": "0.7.0", + "version": "0.8.0", "license": "MIT", "type": "module", "main": "./dist/esm/index.js", @@ -33,7 +33,7 @@ "node": ">=18.0.0" }, "dependencies": { - "@docknetwork/credential-sdk": "0.11.0" + "@docknetwork/credential-sdk": "0.12.0" }, "devDependencies": { "@babel/cli": "^7.24.1", @@ -42,7 +42,7 @@ "@babel/plugin-syntax-import-attributes": "^7.25.6", "@babel/plugin-transform-modules-commonjs": "^7.24.1", "@babel/preset-env": "^7.24.3", - "@docknetwork/dock-blockchain-api": "0.6.0", + "@docknetwork/dock-blockchain-api": "0.6.1", "@rollup/plugin-alias": "^4.0.2", "@rollup/plugin-babel": "^6.0.4", "@rollup/plugin-commonjs": "^24.0.0", diff --git a/packages/dock-blockchain-modules/src/offchain-signatures/internal.js b/packages/dock-blockchain-modules/src/offchain-signatures/internal.js index 46fefe7a5..fd66b85f2 100644 --- a/packages/dock-blockchain-modules/src/offchain-signatures/internal.js +++ b/packages/dock-blockchain-modules/src/offchain-signatures/internal.js @@ -19,6 +19,12 @@ import DockDIDModuleInternal from '../did/internal'; export default class DockInternalOffchainSignaturesModule extends injectParams( injectPublicKeys(class OffchainSignatures {}), ) { + constructor(...args) { + super(...args); + + this.didModule = new DockDIDModuleInternal(this.apiProvider); + } + static Prop = 'offchainSignatures'; static MethodNameOverrides = { @@ -50,7 +56,7 @@ export default class DockInternalOffchainSignaturesModule extends injectParams( /** * Returns params counter corresponding to the supplied DID. * @param {*} did - * @returns Promise<*> + * @returns Promise */ async paramsCounter(did) { return DockParamsId.from( @@ -65,12 +71,16 @@ export default class DockInternalOffchainSignaturesModule extends injectParams( /** * Returns keys counter corresponding to the supplied DID. * @param {*} did - * @returns Promise<*> + * @returns Promise */ async keysCounter(did) { - return (await new DockDIDModuleInternal(this.apiProvider).getOnchainDidDetail( - DockDidOrDidMethodKey.from(did), - )).data.lastKeyId; + const parsedDid = DockDidOrDidMethodKey.from(did); + + const { data: { lastKeyId } } = await this.didModule.getOnchainDidDetail( + parsedDid, + ); + + return lastKeyId; } async lastPublicKeyId(did) {