From 15fa5e995eeea546796b46acfa0694227e622a66 Mon Sep 17 00:00:00 2001 From: Oleg Date: Tue, 17 Dec 2024 12:19:52 +0400 Subject: [PATCH 1/4] Fix unresolved imports --- examples/CHANGELOG.md | 9 +++++++++ examples/package.json | 8 ++++---- package.json | 2 +- packages/cheqd-blockchain-api/CHANGELOG.md | 7 +++++++ packages/cheqd-blockchain-api/package.json | 4 ++-- packages/cheqd-blockchain-modules/CHANGELOG.md | 7 +++++++ packages/cheqd-blockchain-modules/package.json | 6 +++--- packages/credential-sdk/CHANGELOG.md | 6 ++++++ packages/credential-sdk/package.json | 2 +- .../credential-sdk/src/types/generic/typed-number.js | 4 ++++ .../src/types/offchain-signatures/public-keys/id.js | 5 +++++ .../types/offchain-signatures/public-keys/index.js | 1 + 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 | 9 +++++---- 17 files changed, 78 insertions(+), 20 deletions(-) create mode 100644 packages/credential-sdk/src/types/offchain-signatures/public-keys/id.js diff --git a/examples/CHANGELOG.md b/examples/CHANGELOG.md index daa1dd339..174947c4b 100644 --- a/examples/CHANGELOG.md +++ b/examples/CHANGELOG.md @@ -1,5 +1,14 @@ # @docknetwork/sdk-examples +## 0.6.5 + +### Patch Changes + +- Updated dependencies + - @docknetwork/dock-blockchain-modules@0.11.0 + - @docknetwork/credential-sdk@0.19.0 + - @docknetwork/dock-blockchain-api@0.8.5 + ## 0.6.4 ### Patch Changes diff --git a/examples/package.json b/examples/package.json index b3671d8b7..4d749ee3b 100644 --- a/examples/package.json +++ b/examples/package.json @@ -2,7 +2,7 @@ "name": "@docknetwork/sdk-examples", "private": true, "type": "module", - "version": "0.6.4", + "version": "0.6.5", "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.18.0", - "@docknetwork/dock-blockchain-api": "0.8.4", - "@docknetwork/dock-blockchain-modules": "0.10.0" + "@docknetwork/credential-sdk": "0.19.0", + "@docknetwork/dock-blockchain-api": "0.8.5", + "@docknetwork/dock-blockchain-modules": "0.11.0" }, "devDependencies": { "babel-eslint": "^10.1.0", diff --git a/package.json b/package.json index 97979028e..2fb59dd6b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "root", - "version": "0.19.0", + "version": "0.21.0", "private": true, "workspaces": [ "packages/*", diff --git a/packages/cheqd-blockchain-api/CHANGELOG.md b/packages/cheqd-blockchain-api/CHANGELOG.md index cc392fee0..ca1857531 100644 --- a/packages/cheqd-blockchain-api/CHANGELOG.md +++ b/packages/cheqd-blockchain-api/CHANGELOG.md @@ -1,5 +1,12 @@ # @docknetwork/cheqd-blockchain-api +## 0.14.4 + +### Patch Changes + +- Updated dependencies + - @docknetwork/credential-sdk@0.19.0 + ## 0.14.3 ### Patch Changes diff --git a/packages/cheqd-blockchain-api/package.json b/packages/cheqd-blockchain-api/package.json index 205dad99c..7d71afa22 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.14.3", + "version": "0.14.4", "license": "MIT", "main": "./dist/esm/index.js", "type": "module", @@ -34,7 +34,7 @@ }, "dependencies": { "@cheqd/sdk": "cjs", - "@docknetwork/credential-sdk": "0.18.0" + "@docknetwork/credential-sdk": "0.19.0" }, "devDependencies": { "@babel/cli": "^7.24.1", diff --git a/packages/cheqd-blockchain-modules/CHANGELOG.md b/packages/cheqd-blockchain-modules/CHANGELOG.md index 5b1acb986..59bb3fc2a 100644 --- a/packages/cheqd-blockchain-modules/CHANGELOG.md +++ b/packages/cheqd-blockchain-modules/CHANGELOG.md @@ -1,5 +1,12 @@ # @docknetwork/cheqd-blockchain-modules +## 0.13.1 + +### Patch Changes + +- Updated dependencies + - @docknetwork/credential-sdk@0.19.0 + ## 0.13.0 ### Minor Changes diff --git a/packages/cheqd-blockchain-modules/package.json b/packages/cheqd-blockchain-modules/package.json index af1510e6d..ac164a5c4 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.13.0", + "version": "0.13.1", "type": "module", "license": "MIT", "main": "./dist/esm/index.js", @@ -33,7 +33,7 @@ "node": ">=18.0.0" }, "dependencies": { - "@docknetwork/credential-sdk": "0.18.0" + "@docknetwork/credential-sdk": "0.19.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.14.3", + "@docknetwork/cheqd-blockchain-api": "0.14.4", "@rollup/plugin-alias": "^4.0.2", "@rollup/plugin-babel": "^6.0.4", "@rollup/plugin-commonjs": "^24.0.0", diff --git a/packages/credential-sdk/CHANGELOG.md b/packages/credential-sdk/CHANGELOG.md index 61f5c7c5d..2f97c1c36 100644 --- a/packages/credential-sdk/CHANGELOG.md +++ b/packages/credential-sdk/CHANGELOG.md @@ -1,5 +1,11 @@ # @docknetwork/credential-sdk +## 0.19.0 + +### Minor Changes + +- Fix unresolved imports + ## 0.18.0 ### Minor Changes diff --git a/packages/credential-sdk/package.json b/packages/credential-sdk/package.json index 66b03c207..9a14477c3 100644 --- a/packages/credential-sdk/package.json +++ b/packages/credential-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@docknetwork/credential-sdk", - "version": "0.18.0", + "version": "0.19.0", "license": "MIT", "type": "module", "files": [ diff --git a/packages/credential-sdk/src/types/generic/typed-number.js b/packages/credential-sdk/src/types/generic/typed-number.js index aac792b1c..d9a89cb26 100644 --- a/packages/credential-sdk/src/types/generic/typed-number.js +++ b/packages/credential-sdk/src/types/generic/typed-number.js @@ -12,6 +12,10 @@ class TypedNumber extends withBase(class NumberBase {}) { throw new Error( `Invalid number provided: \`${value}\`, parsed as \`${num}\` by \`${this.constructor.name}\``, ); + } else if (!Number.isSafeInteger(num)) { + throw new Error( + `Number must be a safe integer, received: \`${num}\` by \`${this.constructor.name}\``, + ); } this.value = num; diff --git a/packages/credential-sdk/src/types/offchain-signatures/public-keys/id.js b/packages/credential-sdk/src/types/offchain-signatures/public-keys/id.js new file mode 100644 index 000000000..a2e431d21 --- /dev/null +++ b/packages/credential-sdk/src/types/offchain-signatures/public-keys/id.js @@ -0,0 +1,5 @@ +import { TypedNumber, TypedUUID } from '../../generic'; + +export class DockPublicKeyId extends TypedNumber {} + +export class CheqdPublicKeyId extends TypedUUID {} diff --git a/packages/credential-sdk/src/types/offchain-signatures/public-keys/index.js b/packages/credential-sdk/src/types/offchain-signatures/public-keys/index.js index 435351778..98ed74121 100644 --- a/packages/credential-sdk/src/types/offchain-signatures/public-keys/index.js +++ b/packages/credential-sdk/src/types/offchain-signatures/public-keys/index.js @@ -129,3 +129,4 @@ export class CheqdOffchainSignaturePublicKey extends withProp( export * from './value'; export * from './ref'; +export * from './id'; diff --git a/packages/dock-blockchain-api/CHANGELOG.md b/packages/dock-blockchain-api/CHANGELOG.md index 02ba5ae50..f03edc5ef 100644 --- a/packages/dock-blockchain-api/CHANGELOG.md +++ b/packages/dock-blockchain-api/CHANGELOG.md @@ -1,5 +1,12 @@ # @docknetwork/dock-blockchain-api +## 0.8.5 + +### Patch Changes + +- Updated dependencies + - @docknetwork/credential-sdk@0.19.0 + ## 0.8.4 ### Patch Changes diff --git a/packages/dock-blockchain-api/package.json b/packages/dock-blockchain-api/package.json index fcf788023..fa8818b8b 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.8.4", + "version": "0.8.5", "license": "MIT", "main": "./dist/esm/index.js", "type": "module", @@ -89,7 +89,7 @@ "@polkadot/api": "10.12.4" }, "dependencies": { - "@docknetwork/credential-sdk": "0.18.0", + "@docknetwork/credential-sdk": "0.19.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 6c392b625..02e1966c4 100644 --- a/packages/dock-blockchain-modules/CHANGELOG.md +++ b/packages/dock-blockchain-modules/CHANGELOG.md @@ -1,5 +1,16 @@ # @docknetwork/dock-blockchain-modules +## 0.11.0 + +### Minor Changes + +- Fix unresolved imports + +### Patch Changes + +- Updated dependencies + - @docknetwork/credential-sdk@0.19.0 + ## 0.10.0 ### Minor Changes diff --git a/packages/dock-blockchain-modules/package.json b/packages/dock-blockchain-modules/package.json index 5f377b556..ae2107451 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.10.0", + "version": "0.11.0", "license": "MIT", "type": "module", "main": "./dist/esm/index.js", @@ -33,7 +33,7 @@ "node": ">=18.0.0" }, "dependencies": { - "@docknetwork/credential-sdk": "0.18.0" + "@docknetwork/credential-sdk": "0.19.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.8.4", + "@docknetwork/dock-blockchain-api": "0.8.5", "@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 fd66b85f2..732c86cee 100644 --- a/packages/dock-blockchain-modules/src/offchain-signatures/internal.js +++ b/packages/dock-blockchain-modules/src/offchain-signatures/internal.js @@ -5,6 +5,7 @@ import { DockDidValue, DockOffchainSignatureParamsRef, DockParamsId, + DockPublicKeyId, } from '@docknetwork/credential-sdk/types'; import { AddOffchainSignatureParams, @@ -76,14 +77,14 @@ export default class DockInternalOffchainSignaturesModule extends injectParams( async keysCounter(did) { const parsedDid = DockDidOrDidMethodKey.from(did); - const { data: { lastKeyId } } = await this.didModule.getOnchainDidDetail( - parsedDid, - ); + const { + data: { lastKeyId }, + } = await this.didModule.getOnchainDidDetail(parsedDid); return lastKeyId; } async lastPublicKeyId(did) { - return await this.keysCounter(did); + return DockPublicKeyId.from(await this.keysCounter(did)); } } From 4f5531d8c4f7fcbe3b336b212863c871edb28fa4 Mon Sep 17 00:00:00 2001 From: Oleg Date: Tue, 17 Dec 2024 17:20:37 +0400 Subject: [PATCH 2/4] Improve tests --- .../src/common/inject-public-keys.js | 5 +++- .../src/modules/tests/accumulator-module.js | 29 ++++++++++++++++++- packages/credential-sdk/src/utils/bytes.js | 2 +- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/packages/cheqd-blockchain-modules/src/common/inject-public-keys.js b/packages/cheqd-blockchain-modules/src/common/inject-public-keys.js index c9cdb887c..333932394 100644 --- a/packages/cheqd-blockchain-modules/src/common/inject-public-keys.js +++ b/packages/cheqd-blockchain-modules/src/common/inject-public-keys.js @@ -94,7 +94,10 @@ export default function injectPublicKeys(klass) { return new PublicKeyMap( await Promise.all( - metas.map(({ id }) => this.getPublicKey(did, id, includeParams)), + metas.map(async ({ id }) => [ + id, + await this.getPublicKey(did, id, includeParams), + ]), ), ); } diff --git a/packages/credential-sdk/src/modules/tests/accumulator-module.js b/packages/credential-sdk/src/modules/tests/accumulator-module.js index 5e6fafc77..afdcbba92 100644 --- a/packages/credential-sdk/src/modules/tests/accumulator-module.js +++ b/packages/credential-sdk/src/modules/tests/accumulator-module.js @@ -11,7 +11,10 @@ import { VBMembershipWitness, } from '../../crypto'; import { AccumulatorType } from '../abstract/accumulator/module'; -import { DIDDocument } from '../../types'; +import { + DIDDocument, + AccumulatorParams as AccumulatorParamsType, +} from '../../types'; import { Ed25519Keypair, DidKeypair } from '../../keypairs'; // eslint-disable-next-line jest/no-export @@ -65,12 +68,36 @@ export default function generateAccumulatorTests( params1Id = await accumulatorModule.nextParamsId(did); await accumulatorModule.addParams(params1Id, params1, did, pair); + expect( + (await accumulatorModule.getParams(did, params1Id)).toJSON(), + ).toEqual(AccumulatorParamsType.from(params1).toJSON()); + expect((await accumulatorModule.getAllParamsByDid(did)).toJSON()).toEqual( + [[params1Id.toJSON(), AccumulatorParamsType.from(params1).toJSON()]], + ); + keypair = Accumulator.generateKeypair(params, seedAccum); const bytes2 = u8aToHex(keypair.publicKey.bytes); const pk1 = new PublicKey(bytes2, [did, params1Id]); pk1Id = await accumulatorModule.nextPublicKeyId(did); await accumulatorModule.addPublicKey(pk1Id, pk1, did, pair); + expect( + (await accumulatorModule.getPublicKey(did, pk1Id)).toJSON(), + ).toEqual(pk1.toJSON()); + expect( + (await accumulatorModule.getAllPublicKeysByDid(did)).toJSON(), + ).toEqual([[pk1Id.toJSON(), pk1.toJSON()]]); + + const pk1WithParams = await pk1.withParams(accumulatorModule); + expect(pk1WithParams.params).toBeInstanceOf(AccumulatorParamsType); + + expect( + (await accumulatorModule.getPublicKey(did, pk1Id, true)).toJSON(), + ).toEqual(pk1WithParams.toJSON()); + expect( + (await accumulatorModule.getAllPublicKeysByDid(did, true)).toJSON(), + ).toEqual([[pk1Id.toJSON(), pk1WithParams.toJSON()]]); + accumulator = PositiveAccumulator.initialize(params, keypair.secretKey); for (let i = 1; i <= totalMembers; i++) { diff --git a/packages/credential-sdk/src/utils/bytes.js b/packages/credential-sdk/src/utils/bytes.js index de8ebd9fe..a3ab74665 100644 --- a/packages/credential-sdk/src/utils/bytes.js +++ b/packages/credential-sdk/src/utils/bytes.js @@ -45,7 +45,7 @@ export const u8aToHex = (bytes) => `0x${Buffer.from(ensureBytes(bytes)).toString * @param {number} length * @returns {Uint8Array} */ -export const randomAsU8a = (length) => Uint8Array.from({ length }, () => (Math.random() * 255) | 0); // eslint-disable-line no-bitwise +export const randomAsU8a = (length) => Uint8Array.from({ length }, () => Math.floor(Math.random() * 256) | 0); // eslint-disable-line no-bitwise /** * Creates random hex string of supplied byte length. From 9fab5e75465f3ba1e3acaea3ff611f8bfa87cfe4 Mon Sep 17 00:00:00 2001 From: Oleg Date: Tue, 17 Dec 2024 17:37:44 +0400 Subject: [PATCH 3/4] `MultiApi` tweaks --- .../src/modules/multi-api/accumulator.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/credential-sdk/src/modules/multi-api/accumulator.js b/packages/credential-sdk/src/modules/multi-api/accumulator.js index 3a911ab4f..c6e13e483 100644 --- a/packages/credential-sdk/src/modules/multi-api/accumulator.js +++ b/packages/credential-sdk/src/modules/multi-api/accumulator.js @@ -250,10 +250,14 @@ export default class MultiApiAccumulatorModule extends injectModuleRouter( ); } - async getPublicKey(did, id) { + async getPublicKey(did, id, includeParams) { const parsedDid = NamespaceDid.from(did); - return await this.moduleById(parsedDid).getPublicKey(parsedDid, id); + return await this.moduleById(parsedDid).getPublicKey( + parsedDid, + id, + includeParams, + ); } /** @@ -261,10 +265,10 @@ export default class MultiApiAccumulatorModule extends injectModuleRouter( * @param {*} did * @returns {Promise>} */ - async getAllPublicKeysByDid(did) { + async getAllPublicKeysByDid(did, includeParams) { const id = NamespaceDid.from(did); - return await this.moduleById(id).getAllPublicKeysByDid(did); + return await this.moduleById(id).getAllPublicKeysByDid(did, includeParams); } async addPublicKeyTx(...args) { From df9e3ccd90db19c4491f24b07bc3b1739dad5f1b Mon Sep 17 00:00:00 2001 From: Oleg Date: Tue, 17 Dec 2024 17:42:59 +0400 Subject: [PATCH 4/4] Remove redundant comment --- packages/credential-sdk/src/utils/bytes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/credential-sdk/src/utils/bytes.js b/packages/credential-sdk/src/utils/bytes.js index a3ab74665..d28dd0812 100644 --- a/packages/credential-sdk/src/utils/bytes.js +++ b/packages/credential-sdk/src/utils/bytes.js @@ -45,7 +45,7 @@ export const u8aToHex = (bytes) => `0x${Buffer.from(ensureBytes(bytes)).toString * @param {number} length * @returns {Uint8Array} */ -export const randomAsU8a = (length) => Uint8Array.from({ length }, () => Math.floor(Math.random() * 256) | 0); // eslint-disable-line no-bitwise +export const randomAsU8a = (length) => Uint8Array.from({ length }, () => Math.floor(Math.random() * 256)); /** * Creates random hex string of supplied byte length.