From 3cc21886bf281041b27015609ef413292c47a7bc Mon Sep 17 00:00:00 2001 From: Oleg Nosov Date: Fri, 6 Dec 2024 13:59:59 +0400 Subject: [PATCH] `cheqd` payloads (#491) * Fix `toJSON`/`fromJSON` for `cheqd` payloads * Versions --- examples/CHANGELOG.md | 9 +++ examples/package.json | 8 +-- packages/cheqd-blockchain-api/CHANGELOG.md | 7 ++ packages/cheqd-blockchain-api/package.json | 4 +- .../cheqd-blockchain-modules/CHANGELOG.md | 11 ++++ .../cheqd-blockchain-modules/package.json | 6 +- .../common/create-internal-cheqd-module.js | 3 +- .../src/common/payload.js | 64 +++++++++++++++---- .../src/did/internal.js | 10 +-- packages/credential-sdk/CHANGELOG.md | 6 ++ packages/credential-sdk/package.json | 2 +- packages/credential-sdk/src/utils/bytes.js | 4 +- packages/dock-blockchain-api/CHANGELOG.md | 7 ++ packages/dock-blockchain-api/package.json | 4 +- packages/dock-blockchain-modules/CHANGELOG.md | 7 ++ packages/dock-blockchain-modules/package.json | 6 +- 16 files changed, 117 insertions(+), 41 deletions(-) diff --git a/examples/CHANGELOG.md b/examples/CHANGELOG.md index b9ddad7e3..ace7ba762 100644 --- a/examples/CHANGELOG.md +++ b/examples/CHANGELOG.md @@ -1,5 +1,14 @@ # @docknetwork/sdk-examples +## 0.6.3 + +### Patch Changes + +- Updated dependencies + - @docknetwork/credential-sdk@0.17.0 + - @docknetwork/dock-blockchain-api@0.8.3 + - @docknetwork/dock-blockchain-modules@0.9.3 + ## 0.6.2 ### Patch Changes diff --git a/examples/package.json b/examples/package.json index 40bedf1c5..a62762663 100644 --- a/examples/package.json +++ b/examples/package.json @@ -2,7 +2,7 @@ "name": "@docknetwork/sdk-examples", "private": true, "type": "module", - "version": "0.6.2", + "version": "0.6.3", "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.16.0", - "@docknetwork/dock-blockchain-api": "0.8.2", - "@docknetwork/dock-blockchain-modules": "0.9.2" + "@docknetwork/credential-sdk": "0.17.0", + "@docknetwork/dock-blockchain-api": "0.8.3", + "@docknetwork/dock-blockchain-modules": "0.9.3" }, "devDependencies": { "babel-eslint": "^10.1.0", diff --git a/packages/cheqd-blockchain-api/CHANGELOG.md b/packages/cheqd-blockchain-api/CHANGELOG.md index 3adbf15b8..675a8e487 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.2 + +### Patch Changes + +- Updated dependencies + - @docknetwork/credential-sdk@0.17.0 + ## 0.14.1 ### Patch Changes diff --git a/packages/cheqd-blockchain-api/package.json b/packages/cheqd-blockchain-api/package.json index a8915a6d7..1dfd485a8 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.1", + "version": "0.14.2", "license": "MIT", "main": "./dist/esm/index.js", "type": "module", @@ -34,7 +34,7 @@ }, "dependencies": { "@cheqd/sdk": "cjs", - "@docknetwork/credential-sdk": "0.16.0" + "@docknetwork/credential-sdk": "0.17.0" }, "devDependencies": { "@babel/cli": "^7.24.1", diff --git a/packages/cheqd-blockchain-modules/CHANGELOG.md b/packages/cheqd-blockchain-modules/CHANGELOG.md index 8b0be89ef..4c7b329f6 100644 --- a/packages/cheqd-blockchain-modules/CHANGELOG.md +++ b/packages/cheqd-blockchain-modules/CHANGELOG.md @@ -1,5 +1,16 @@ # @docknetwork/cheqd-blockchain-modules +## 0.12.0 + +### Minor Changes + +- Fix `toJSON`/`fromJSON` for `cheqd` payloads + +### Patch Changes + +- Updated dependencies + - @docknetwork/credential-sdk@0.17.0 + ## 0.11.2 ### Patch Changes diff --git a/packages/cheqd-blockchain-modules/package.json b/packages/cheqd-blockchain-modules/package.json index 3b6c17c55..2b3bd012f 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.11.2", + "version": "0.12.0", "type": "module", "license": "MIT", "main": "./dist/esm/index.js", @@ -33,7 +33,7 @@ "node": ">=18.0.0" }, "dependencies": { - "@docknetwork/credential-sdk": "0.16.0" + "@docknetwork/credential-sdk": "0.17.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.1", + "@docknetwork/cheqd-blockchain-api": "0.14.2", "@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/src/common/create-internal-cheqd-module.js b/packages/cheqd-blockchain-modules/src/common/create-internal-cheqd-module.js index 4cd8f8b1e..c12c2ef0a 100644 --- a/packages/cheqd-blockchain-modules/src/common/create-internal-cheqd-module.js +++ b/packages/cheqd-blockchain-modules/src/common/create-internal-cheqd-module.js @@ -3,7 +3,6 @@ import { CheqdDid, } from '@docknetwork/credential-sdk/types'; import { TypedUUID } from '@docknetwork/credential-sdk/types/generic'; -import { CheqdPayloadWithTypeUrl } from './payload'; /** * Creates DID transaction constructor. @@ -30,7 +29,7 @@ const createDIDMethodTx = (fnName) => { signatures, }; - return new CheqdPayloadWithTypeUrl( + return new payload.constructor.ResourcePayloadWithTypeUrlAndSignatures( root.constructor.MsgNames[fnName], value, ); diff --git a/packages/cheqd-blockchain-modules/src/common/payload.js b/packages/cheqd-blockchain-modules/src/common/payload.js index 2fc6b215c..5c7cefee4 100644 --- a/packages/cheqd-blockchain-modules/src/common/payload.js +++ b/packages/cheqd-blockchain-modules/src/common/payload.js @@ -1,9 +1,9 @@ import { VerificationMethodSignature, CheqdDid, + CheqdDIDDocument, } from '@docknetwork/credential-sdk/types'; import { - Any, TypedArray, TypedString, TypedStruct, @@ -11,21 +11,37 @@ import { TypedUUID, } from '@docknetwork/credential-sdk/types/generic'; -export class CheqdPayloadAndSignatures extends TypedStruct { - static Classes = { - payload: Any, - signatures: class Signatures extends TypedArray { - static Class = VerificationMethodSignature; +const createTypes = (Payload) => { + const payloadWithSigsName = `CheqdPayloadWithSignatures(${Payload.name})`; + const payloadWithTypeUrlAndSigsName = `CheqdPayloadWithTypeUrlAndSignatures(${Payload.name})`; + + const obj1 = { + [payloadWithSigsName]: class extends TypedStruct { + static Classes = { + payload: Payload, + signatures: class Signatures extends TypedArray { + static Class = VerificationMethodSignature; + }, + }; }, }; -} - -export class CheqdPayloadWithTypeUrl extends TypedStruct { - static Classes = { - typeUrl: class TypeURL extends TypedString {}, - value: CheqdPayloadAndSignatures, + const obj2 = { + [payloadWithTypeUrlAndSigsName]: class extends TypedStruct { + static Classes = { + typeUrl: class TypeURL extends TypedString {}, + value: obj1[payloadWithSigsName], + }; + }, }; -} + + // eslint-disable-next-line + Payload.ResourcePayloadWithTypeUrlAndSignatures = obj2[payloadWithTypeUrlAndSigsName]; + + return [ + obj1[payloadWithSigsName], + obj2[payloadWithTypeUrlAndSigsName], + ]; +}; export class CheqdCreateResource extends TypedStruct { static Classes = { @@ -40,3 +56,25 @@ export class CheqdCreateResource extends TypedStruct { data: class Data extends TypedBytesArray {}, }; } + +export class DeactivateDidDocument extends TypedStruct { + static Classes = { + id: CheqdDid, + versionId: TypedUUID, + }; +} + +export const [ + CheqdCreateResourcePayloadWithSignatures, + CheqdCreateResourcePayloadWithTypeUrlAndSignatures, +] = createTypes(CheqdCreateResource); + +export const [ + CheqdSetDidDocumentPayloadWithSignatures, + CheqdSetDidDocumentPayloadWithTypeUrlAndSignatures, +] = createTypes(CheqdDIDDocument); + +export const [ + CheqdDeactivateDidDocumentPayloadWithSignatures, + CheqdDeactivateDidDocumentPayloadWithTypeUrlAndSignatures, +] = createTypes(DeactivateDidDocument); diff --git a/packages/cheqd-blockchain-modules/src/did/internal.js b/packages/cheqd-blockchain-modules/src/did/internal.js index 4ac3ce7ca..e416428c7 100644 --- a/packages/cheqd-blockchain-modules/src/did/internal.js +++ b/packages/cheqd-blockchain-modules/src/did/internal.js @@ -1,20 +1,12 @@ import { CheqdDid } from '@docknetwork/credential-sdk/types/did/onchain/typed-did'; import { TypedUUID, - TypedStruct, } from '@docknetwork/credential-sdk/types/generic'; import { DIDDocument } from '@docknetwork/credential-sdk/types/did'; -import { createInternalCheqdModule } from '../common'; +import { createInternalCheqdModule, DeactivateDidDocument } from '../common'; const parseDocument = (document) => DIDDocument.from(document).toCheqd(); -class DeactivateDidDocument extends TypedStruct { - static Classes = { - id: CheqdDid, - versionId: TypedUUID, - }; -} - const methods = { createDidDocument: parseDocument, updateDidDocument: parseDocument, diff --git a/packages/credential-sdk/CHANGELOG.md b/packages/credential-sdk/CHANGELOG.md index 4a4c067e3..119b0f959 100644 --- a/packages/credential-sdk/CHANGELOG.md +++ b/packages/credential-sdk/CHANGELOG.md @@ -1,5 +1,11 @@ # @docknetwork/credential-sdk +## 0.17.0 + +### Minor Changes + +- Fix `toJSON`/`fromJSON` for `cheqd` payloads + ## 0.16.0 ### Minor Changes diff --git a/packages/credential-sdk/package.json b/packages/credential-sdk/package.json index 6862df0bf..cb6d01216 100644 --- a/packages/credential-sdk/package.json +++ b/packages/credential-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@docknetwork/credential-sdk", - "version": "0.16.0", + "version": "0.17.0", "license": "MIT", "type": "module", "files": [ diff --git a/packages/credential-sdk/src/utils/bytes.js b/packages/credential-sdk/src/utils/bytes.js index b5d0dd261..3740bbe06 100644 --- a/packages/credential-sdk/src/utils/bytes.js +++ b/packages/credential-sdk/src/utils/bytes.js @@ -1,5 +1,5 @@ import { applyToValue } from './interfaces'; -import { ensureBytes, ensureString } from './type-helpers'; +import { ensureBytes, ensureString, isBytes } from './type-helpers'; /** * Check if the given input is hexadecimal or not. Optionally checks for the byte size of the hex. Case-insensitive on hex chars @@ -125,7 +125,7 @@ export const stringToHex = (str) => u8aToHex(stringToBuffer(str)); export const normalizeToU8a = (bytes) => { if (bytes instanceof Uint8Array) { return bytes; - } else if (bytes instanceof Buffer || Array.isArray(bytes)) { + } else if (isBytes(bytes)) { return u8aToU8a(bytes); } else if (isHex(bytes)) { return hexToU8a(bytes); diff --git a/packages/dock-blockchain-api/CHANGELOG.md b/packages/dock-blockchain-api/CHANGELOG.md index d67e7f018..9e3a0340b 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.3 + +### Patch Changes + +- Updated dependencies + - @docknetwork/credential-sdk@0.17.0 + ## 0.8.2 ### Patch Changes diff --git a/packages/dock-blockchain-api/package.json b/packages/dock-blockchain-api/package.json index 8d6258987..a7ad68e4b 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.2", + "version": "0.8.3", "license": "MIT", "main": "./dist/esm/index.js", "type": "module", @@ -89,7 +89,7 @@ "@polkadot/api": "10.12.4" }, "dependencies": { - "@docknetwork/credential-sdk": "0.16.0", + "@docknetwork/credential-sdk": "0.17.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 737050cc3..a35b77b13 100644 --- a/packages/dock-blockchain-modules/CHANGELOG.md +++ b/packages/dock-blockchain-modules/CHANGELOG.md @@ -1,5 +1,12 @@ # @docknetwork/dock-blockchain-modules +## 0.9.3 + +### Patch Changes + +- Updated dependencies + - @docknetwork/credential-sdk@0.17.0 + ## 0.9.2 ### Patch Changes diff --git a/packages/dock-blockchain-modules/package.json b/packages/dock-blockchain-modules/package.json index 1bec68b33..92fd8d16d 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.9.2", + "version": "0.9.3", "license": "MIT", "type": "module", "main": "./dist/esm/index.js", @@ -33,7 +33,7 @@ "node": ">=18.0.0" }, "dependencies": { - "@docknetwork/credential-sdk": "0.16.0" + "@docknetwork/credential-sdk": "0.17.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.2", + "@docknetwork/dock-blockchain-api": "0.8.3", "@rollup/plugin-alias": "^4.0.2", "@rollup/plugin-babel": "^6.0.4", "@rollup/plugin-commonjs": "^24.0.0",