From 4309c4754cd2bc3af9b0edaf9ef29ecb3ee0ed6c Mon Sep 17 00:00:00 2001 From: Oleg Nosov Date: Wed, 5 Feb 2025 00:09:02 +0400 Subject: [PATCH] Use newest DID document format for `cheqd` `mainnet` (#515) * Use newest DID document format for `cheqd` `mainnet` * Deduplicate * Fix imports --- .github/workflows/cheqd-sdk-tests.yml | 4 +- 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 | 7 ++ .../cheqd-blockchain-modules/package.json | 6 +- packages/credential-sdk/CHANGELOG.md | 6 ++ packages/credential-sdk/package.json | 2 +- .../accumulator/{accumulator-id.js => id.js} | 48 +--------- .../src/types/accumulator/index.js | 2 +- .../src/types/blob/{blob-id.js => id.js} | 44 +-------- .../credential-sdk/src/types/blob/index.js | 16 +++- .../src/types/did/document/index.js | 92 +------------------ ...method-ref-or-cheqd-verification-method.js | 5 +- .../types/did/document/verification-method.js | 16 +++- .../src/types/did/onchain/typed-did/index.js | 33 +++++++ .../src/types/status-list-credential/id.js | 44 +-------- .../tests/__snapshots__/document.test.js.snap | 89 ------------------ .../credential-sdk/tests/document.test.js | 85 +++++++++++++---- 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 +- 24 files changed, 202 insertions(+), 349 deletions(-) rename packages/credential-sdk/src/types/accumulator/{accumulator-id.js => id.js} (70%) rename packages/credential-sdk/src/types/blob/{blob-id.js => id.js} (67%) diff --git a/.github/workflows/cheqd-sdk-tests.yml b/.github/workflows/cheqd-sdk-tests.yml index 0f1f2e8d7..459268436 100644 --- a/.github/workflows/cheqd-sdk-tests.yml +++ b/.github/workflows/cheqd-sdk-tests.yml @@ -6,7 +6,7 @@ jobs: runs-on: ubuntu-latest 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" - CHEQD_IMAGE_TAG: 3.1.4 + CHEQD_IMAGE_TAG: 3.1.5 CHEQD_NETWORK: "testnet" steps: - uses: actions/checkout@v2 @@ -22,7 +22,7 @@ jobs: runs-on: ubuntu-latest 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" - CHEQD_IMAGE_TAG: 3.0.2 + CHEQD_IMAGE_TAG: 3.1.5 CHEQD_NETWORK: "mainnet" steps: - uses: actions/checkout@v2 diff --git a/examples/CHANGELOG.md b/examples/CHANGELOG.md index 544519b06..c8bc05b8d 100644 --- a/examples/CHANGELOG.md +++ b/examples/CHANGELOG.md @@ -1,5 +1,14 @@ # @docknetwork/sdk-examples +## 0.17.1 + +### Patch Changes + +- Updated dependencies + - @docknetwork/credential-sdk@0.36.0 + - @docknetwork/dock-blockchain-api@0.19.1 + - @docknetwork/dock-blockchain-modules@0.24.1 + ## 0.17.0 ### Minor Changes diff --git a/examples/package.json b/examples/package.json index 01cb19f5c..7f989f286 100644 --- a/examples/package.json +++ b/examples/package.json @@ -2,7 +2,7 @@ "name": "@docknetwork/sdk-examples", "private": true, "type": "module", - "version": "0.17.0", + "version": "0.17.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.35.0", - "@docknetwork/dock-blockchain-api": "0.19.0", - "@docknetwork/dock-blockchain-modules": "0.24.0" + "@docknetwork/credential-sdk": "0.36.0", + "@docknetwork/dock-blockchain-api": "0.19.1", + "@docknetwork/dock-blockchain-modules": "0.24.1" }, "devDependencies": { "babel-eslint": "^10.1.0", diff --git a/packages/cheqd-blockchain-api/CHANGELOG.md b/packages/cheqd-blockchain-api/CHANGELOG.md index 847c33750..e05a71932 100644 --- a/packages/cheqd-blockchain-api/CHANGELOG.md +++ b/packages/cheqd-blockchain-api/CHANGELOG.md @@ -1,5 +1,12 @@ # @docknetwork/cheqd-blockchain-api +## 0.28.1 + +### Patch Changes + +- Updated dependencies + - @docknetwork/credential-sdk@0.36.0 + ## 0.28.0 ### Minor Changes diff --git a/packages/cheqd-blockchain-api/package.json b/packages/cheqd-blockchain-api/package.json index eaaec5be7..0c573e796 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.28.0", + "version": "0.28.1", "license": "MIT", "main": "./dist/esm/index.js", "type": "module", @@ -34,7 +34,7 @@ }, "dependencies": { "@cheqd/sdk": "cjs", - "@docknetwork/credential-sdk": "0.35.0" + "@docknetwork/credential-sdk": "0.36.0" }, "devDependencies": { "@babel/cli": "^7.24.1", diff --git a/packages/cheqd-blockchain-modules/CHANGELOG.md b/packages/cheqd-blockchain-modules/CHANGELOG.md index f24f0d851..4f8845f02 100644 --- a/packages/cheqd-blockchain-modules/CHANGELOG.md +++ b/packages/cheqd-blockchain-modules/CHANGELOG.md @@ -1,5 +1,12 @@ # @docknetwork/cheqd-blockchain-modules +## 0.27.1 + +### Patch Changes + +- Updated dependencies + - @docknetwork/credential-sdk@0.36.0 + ## 0.27.0 ### Minor Changes diff --git a/packages/cheqd-blockchain-modules/package.json b/packages/cheqd-blockchain-modules/package.json index 131f2caf6..fbae6dcbd 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.27.0", + "version": "0.27.1", "type": "module", "license": "MIT", "main": "./dist/esm/index.js", @@ -33,7 +33,7 @@ "node": ">=18.0.0" }, "dependencies": { - "@docknetwork/credential-sdk": "0.35.0" + "@docknetwork/credential-sdk": "0.36.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.28.0", + "@docknetwork/cheqd-blockchain-api": "0.28.1", "@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 c227c0770..34dc89a92 100644 --- a/packages/credential-sdk/CHANGELOG.md +++ b/packages/credential-sdk/CHANGELOG.md @@ -1,5 +1,11 @@ # @docknetwork/credential-sdk +## 0.36.0 + +### Minor Changes + +- Use newest DID document format for `cheqd` `mainnet` + ## 0.35.0 ### Minor Changes diff --git a/packages/credential-sdk/package.json b/packages/credential-sdk/package.json index 40d559207..bc128643f 100644 --- a/packages/credential-sdk/package.json +++ b/packages/credential-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@docknetwork/credential-sdk", - "version": "0.35.0", + "version": "0.36.0", "license": "MIT", "type": "module", "files": [ diff --git a/packages/credential-sdk/src/types/accumulator/accumulator-id.js b/packages/credential-sdk/src/types/accumulator/id.js similarity index 70% rename from packages/credential-sdk/src/types/accumulator/accumulator-id.js rename to packages/credential-sdk/src/types/accumulator/id.js index 0de91dbb0..f42b11a05 100644 --- a/packages/credential-sdk/src/types/accumulator/accumulator-id.js +++ b/packages/credential-sdk/src/types/accumulator/id.js @@ -1,5 +1,5 @@ import { valueBytes } from '../../utils'; -import { CheqdMainnetDid, CheqdTestnetDid, DidRef } from '../did'; +import { CheqdDidRef, CheqdMainnetDid, CheqdTestnetDid } from '../did'; import { TypedBytes, TypedEnum, @@ -66,7 +66,7 @@ export class DockAccumulatorId extends AccumulatorId { } } -export class CheqdAccumulatorIdValue extends withQualifier(DidRef) { +export class CheqdAccumulatorIdValue extends CheqdDidRef { static Qualifier = 'accumulator:cheqd:'; static Ident = withFromDockId( @@ -74,58 +74,14 @@ export class CheqdAccumulatorIdValue extends withQualifier(DidRef) { DockAccumulatorId, 'accumulator:cheqd:', ); - - static cheqdDid(did) { - return did.value; - } - - static fromUnqualifiedString(str) { - const lastColon = str.lastIndexOf(':'); - const did = `did:cheqd:${str.slice(0, lastColon)}`; - const id = str.slice(lastColon + 1); - - return new this(did, id); - } - - toJSON() { - return String(this); - } - - toEncodedString() { - const { did, value, constructor } = this; - const { cheqdDid } = constructor; - - let prefix = ''; - if (cheqdDid(did) instanceof CheqdTestnetDid) { - prefix = 'testnet'; - } else if (cheqdDid(did) instanceof CheqdMainnetDid) { - prefix = 'mainnet'; - } else { - throw new Error( - `Can't determine DID type: \`${cheqdDid(did)}\`, instance of \`${ - cheqdDid(did).constructor.name - }\``, - ); - } - - return `${prefix}:${did.toEncodedString()}:${value}`; - } } export class CheqdTestnetAccumulatorIdValue extends CheqdAccumulatorIdValue { static Did = CheqdTestnetDid; - - static cheqdDid(did) { - return did; - } } export class CheqdMainnetAccumulatorIdValue extends CheqdAccumulatorIdValue { static Did = CheqdMainnetDid; - - static cheqdDid(did) { - return did; - } } export class CheqdAccumulatorId extends AccumulatorId { diff --git a/packages/credential-sdk/src/types/accumulator/index.js b/packages/credential-sdk/src/types/accumulator/index.js index 628f8868c..d5e97b6ef 100644 --- a/packages/credential-sdk/src/types/accumulator/index.js +++ b/packages/credential-sdk/src/types/accumulator/index.js @@ -3,4 +3,4 @@ export * from './params'; export * from './public-key'; export * from './accumulator'; export * from './counters'; -export * from './accumulator-id'; +export * from './id'; diff --git a/packages/credential-sdk/src/types/blob/blob-id.js b/packages/credential-sdk/src/types/blob/id.js similarity index 67% rename from packages/credential-sdk/src/types/blob/blob-id.js rename to packages/credential-sdk/src/types/blob/id.js index 376f03cc1..5688b13ed 100644 --- a/packages/credential-sdk/src/types/blob/blob-id.js +++ b/packages/credential-sdk/src/types/blob/id.js @@ -12,7 +12,7 @@ import withFromDockId, { patchWithFromDock, } from '../generic/with-from-dock-id'; import { CheqdBlobQualifier, DockBlobQualifier } from './const'; -import { CheqdMainnetDid, CheqdTestnetDid, DidRef } from '../did'; +import { CheqdDidRef, CheqdMainnetDid, CheqdTestnetDid } from '../did'; import dockDidById from '../../utils/dock-did-by-id'; export class BlobId extends withFrom( @@ -59,58 +59,18 @@ export class DockBlobId extends BlobId { } } -export class CheqdBlobIdValue extends withQualifier(DidRef) { +export class CheqdBlobIdValue extends CheqdDidRef { static Qualifier = CheqdBlobQualifier; static Ident = withFromDockId(TypedUUID, DockBlobId, 'blob:cheqd:'); - - static fromUnqualifiedString(str) { - const lastColon = str.lastIndexOf(':'); - const did = `did:cheqd:${str.slice(0, lastColon)}`; - const id = str.slice(lastColon + 1); - - return new this(did, id); - } - - static cheqdDid(did) { - return did.value; - } - - toEncodedString() { - const { did, value, constructor } = this; - const cheqdDid = constructor.cheqdDid(did); - - let prefix = ''; - if (cheqdDid instanceof CheqdTestnetDid) { - prefix = 'testnet'; - } else if (cheqdDid instanceof CheqdMainnetDid) { - prefix = 'mainnet'; - } else { - throw new Error( - `Can't determine DID type: \`${cheqdDid(did)}\`, instance of \`${ - cheqdDid(did).constructor.name - }\``, - ); - } - - return `${prefix}:${did.toEncodedString()}:${value}`; - } } export class CheqdTestnetBlobIdValue extends CheqdBlobIdValue { static Did = CheqdTestnetDid; - - static cheqdDid(did) { - return did; - } } export class CheqdMainnetBlobIdValue extends CheqdBlobIdValue { static Did = CheqdMainnetDid; - - static cheqdDid(did) { - return did; - } } export class CheqdBlobId extends BlobId { diff --git a/packages/credential-sdk/src/types/blob/index.js b/packages/credential-sdk/src/types/blob/index.js index 9348618d3..c78404ba3 100644 --- a/packages/credential-sdk/src/types/blob/index.js +++ b/packages/credential-sdk/src/types/blob/index.js @@ -1,8 +1,8 @@ import { TypedStruct, withProp } from '../generic'; -import { BlobId, CheqdBlobIdValue, DockBlobIdValue } from './blob-id'; +import { BlobId, CheqdBlobIdValue, DockBlobIdValue } from './id'; import Blob from './blob'; -export * from './blob-id'; +export * from './id'; export { default as Blob } from './blob'; export class BlobWithId extends TypedStruct { @@ -12,5 +12,13 @@ export class BlobWithId extends TypedStruct { }; } -export class CheqdBlobWithId extends withProp(BlobWithId, 'id', CheqdBlobIdValue) {} -export class DockBlobWithId extends withProp(BlobWithId, 'id', DockBlobIdValue) {} +export class CheqdBlobWithId extends withProp( + BlobWithId, + 'id', + CheqdBlobIdValue, +) {} +export class DockBlobWithId extends withProp( + BlobWithId, + 'id', + DockBlobIdValue, +) {} diff --git a/packages/credential-sdk/src/types/did/document/index.js b/packages/credential-sdk/src/types/did/document/index.js index 6228d1e12..576e36161 100644 --- a/packages/credential-sdk/src/types/did/document/index.js +++ b/packages/credential-sdk/src/types/did/document/index.js @@ -1,6 +1,5 @@ import { TypedArray, - TypedMap, TypedNumber, TypedSet, TypedString, @@ -23,7 +22,6 @@ import { CheqdVerificationMethod, CheqdTestnetVerificationMethod, CheqdMainnetVerificationMethod, - CheqdMainnetVerificationMethodAssertion, } from './verification-method'; import { CheqdVerificationMethodRefOrCheqdVerificationMethod, @@ -38,7 +36,6 @@ import { } from './verification-method-ref'; import { ATTESTS_IRI, CONTEXT_URI } from './const'; import { ensureEqualToOrPrototypeOf } from '../../../utils'; -import { Ed25519Verification2018Method } from './verification-method-type'; class Context extends TypedArray { static Class = TypedString; @@ -399,7 +396,8 @@ export class CheqdDIDDocument extends TypedStruct { const { verificationMethod } = this; this.verificationMethod = verificationMethod.filter( - (verMethod) => !verMethod.isOffchain(), + (verMethod) => !verMethod.isOffchain() + && !verMethod.verificationMaterial.bytes.every((item) => !item), ); const offchainVerMethod = verificationMethod.filter((verMethod) => verMethod.isOffchain()); @@ -469,15 +467,6 @@ export class CheqdTestnetDIDDocument extends CheqdDIDDocument { capabilityDelegation: CheqdTestnetVerificationMethodReferences, versionId: option(VersionId), }; - - constructor(...args) { - super(...args); - const { verificationMethod } = this; - - this.verificationMethod = verificationMethod.filter( - (verMethod) => !verMethod.verificationMaterial.bytes.every((item) => !item), - ); - } } export class CheqdMainnetDIDDocument extends CheqdDIDDocument { @@ -495,83 +484,6 @@ export class CheqdMainnetDIDDocument extends CheqdDIDDocument { capabilityDelegation: CheqdMainnetVerificationMethodReferences, versionId: option(VersionId), }; - - constructor(...args) { - super(...args); - - const { verificationMethod, assertionMethod } = this; - - this.verificationMethod = [ - ...verificationMethod, - ...[...assertionMethod] - .filter( - (keyOrRef) => keyOrRef.id - && !verificationMethod.some((verMethod) => verMethod.id.eq(keyOrRef.id)), - ) - .map( - (verMethod) => new CheqdMainnetVerificationMethod( - verMethod.id, - verMethod.controller, - new Ed25519Verification2018Method(), - Array(32).fill(0), - ), - ), - ]; - } - - toDIDDocument() { - const { - context, - id, - alsoKnownAs, - controller, - verificationMethod, - authentication, - assertionMethod, - capabilityInvocation, - capabilityDelegation, - keyAgreement, - service, - } = this; - - const assertionMethodOffchainKeys = new (class extends TypedMap { - static KeyClass = CheqdMainnetVerificationMethodRef; - - static ValueClass = CheqdMainnetVerificationMethodAssertion; - })( - [...assertionMethod] - .map((keyRefOrKey) => (keyRefOrKey.id ? [keyRefOrKey.id, keyRefOrKey] : null)) - .filter(Boolean), - ); - const verificationMethodWithOffchainKeys = [...verificationMethod].map( - (verMethod) => { - const offchain = assertionMethodOffchainKeys.get(verMethod.id); - if (offchain != null) { - return offchain.toVerificationMethod(); - } - - return verMethod; - }, - ); - const assertionMethodOnlyRefs = [...assertionMethod].map( - (keyRefOrKey) => keyRefOrKey.id ?? keyRefOrKey, - ); - - return new DIDDocument( - context, - id, - alsoKnownAs, - controller, - verificationMethodWithOffchainKeys, - service, - authentication, - assertionMethodOnlyRefs, - keyAgreement, - capabilityInvocation, - capabilityDelegation, - null, - ); - } } export * from './const'; diff --git a/packages/credential-sdk/src/types/did/document/verification-method-ref-or-cheqd-verification-method.js b/packages/credential-sdk/src/types/did/document/verification-method-ref-or-cheqd-verification-method.js index 97c65c0ff..841bc4af6 100644 --- a/packages/credential-sdk/src/types/did/document/verification-method-ref-or-cheqd-verification-method.js +++ b/packages/credential-sdk/src/types/did/document/verification-method-ref-or-cheqd-verification-method.js @@ -4,6 +4,7 @@ import { CheqdTestnetVerificationMethodAssertion, CheqdVerificationMethodAssertionLegacy, CheqdTestnetVerificationMethodAssertionLegacy, + CheqdMainnetVerificationMethodAssertionLegacy, } from './verification-method'; import { CheqdMainnetVerificationMethodRef, @@ -55,5 +56,7 @@ export class CheqdVerificationMethodRefOrCheqdTestnetVerificationMethod extends export class CheqdVerificationMethodRefOrCheqdMainnetVerificationMethod extends CheqdVerificationMethodRefOrCheqdVerificationMethod { static First = CheqdMainnetVerificationMethodAssertion; - static Second = CheqdMainnetVerificationMethodRef; + static Second = CheqdMainnetVerificationMethodAssertionLegacy; + + static Third = CheqdMainnetVerificationMethodRef; } diff --git a/packages/credential-sdk/src/types/did/document/verification-method.js b/packages/credential-sdk/src/types/did/document/verification-method.js index 8d665c87b..da0d498f1 100644 --- a/packages/credential-sdk/src/types/did/document/verification-method.js +++ b/packages/credential-sdk/src/types/did/document/verification-method.js @@ -323,6 +323,20 @@ export class CheqdMainnetVerificationMethod extends withProp( option(CheqdMainnetPublicKeyMetadata), ) {} +export class CheqdMainnetVerificationMethodAssertion extends withProp( + withProp( + withProp( + CheqdVerificationMethodAssertion, + 'id', + CheqdTestnetVerificationMethodRef, + ), + 'controller', + CheqdTestnetDid, + ), + 'metadata', + option(CheqdTestnetPublicKeyMetadata), +) {} + export class CheqdTestnetVerificationMethodAssertion extends withProp( withProp( withProp( @@ -386,7 +400,7 @@ export class CheqdVerificationMethodAssertionLegacy extends withFrom( } } -export class CheqdMainnetVerificationMethodAssertion extends withProp( +export class CheqdMainnetVerificationMethodAssertionLegacy extends withProp( withProp( withProp( CheqdVerificationMethodAssertionLegacy, diff --git a/packages/credential-sdk/src/types/did/onchain/typed-did/index.js b/packages/credential-sdk/src/types/did/onchain/typed-did/index.js index 51c1dc369..3e30d0027 100644 --- a/packages/credential-sdk/src/types/did/onchain/typed-did/index.js +++ b/packages/credential-sdk/src/types/did/onchain/typed-did/index.js @@ -235,6 +235,39 @@ export class DidRef extends withExtendedStaticProperties( } } +export class CheqdDidRef extends withQualifier(DidRef) { + static Did = CheqdDid; + + static fromUnqualifiedString(str) { + const lastColon = str.lastIndexOf(':'); + const did = `did:cheqd:${str.slice(0, lastColon)}`; + const id = str.slice(lastColon + 1); + + return new this(did, id); + } + + toJSON() { + return String(this); + } + + toEncodedString() { + const { did, value } = this; + + let prefix = ''; + if (did.isTestnet) { + prefix = 'testnet'; + } else if (did.isMainnet) { + prefix = 'mainnet'; + } else { + throw new Error( + `Can't determine DID type: \`${did}\`, instance of \`${did.constructor.name}\``, + ); + } + + return `${prefix}:${did.toEncodedString()}:${value}`; + } +} + DidOrDidMethodKeySignature.bindVariants( DockDidSignature, DidMethodKeySignature, diff --git a/packages/credential-sdk/src/types/status-list-credential/id.js b/packages/credential-sdk/src/types/status-list-credential/id.js index 6aa211d2d..992c5aab3 100644 --- a/packages/credential-sdk/src/types/status-list-credential/id.js +++ b/packages/credential-sdk/src/types/status-list-credential/id.js @@ -9,7 +9,7 @@ import { import withFromDockId, { patchWithFromDock, } from '../generic/with-from-dock-id'; -import { CheqdMainnetDid, CheqdTestnetDid, DidRef } from '../did'; +import { CheqdDidRef, CheqdMainnetDid, CheqdTestnetDid } from '../did'; import { DockStatusList2021Qualifier, CheqdStatusList2021Qualifier, @@ -64,7 +64,7 @@ export class DockStatusListCredentialId extends StatusListCredentialId { } } -export class CheqdStatusListCredentialIdValue extends withQualifier(DidRef) { +export class CheqdStatusListCredentialIdValue extends CheqdDidRef { static Qualifier = CheqdStatusList2021Qualifier; static Ident = withFromDockId( @@ -72,54 +72,14 @@ export class CheqdStatusListCredentialIdValue extends withQualifier(DidRef) { DockStatusListCredentialId, 'status-list2021:cheqd:', ); - - static fromUnqualifiedString(str) { - const lastColon = str.lastIndexOf(':'); - const did = `did:cheqd:${str.slice(0, lastColon)}`; - const id = str.slice(lastColon + 1); - - return new this(did, id); - } - - static cheqdDid(did) { - return did.value; - } - - toEncodedString() { - const { did, value, constructor } = this; - const { cheqdDid } = constructor; - - let prefix = ''; - if (cheqdDid(did) instanceof CheqdTestnetDid) { - prefix = 'testnet'; - } else if (cheqdDid(did) instanceof CheqdMainnetDid) { - prefix = 'mainnet'; - } else { - throw new Error( - `Can't determine DID type: \`${cheqdDid(did)}\`, instance of \`${ - cheqdDid(did).constructor.name - }\``, - ); - } - - return `${prefix}:${cheqdDid(did).toEncodedString()}:${value}`; - } } class CheqdTestnetStatusListCredentialIdValue extends CheqdStatusListCredentialIdValue { static Did = CheqdTestnetDid; - - static cheqdDid(did) { - return did; - } } class CheqdMainnetStatusListCredentialIdValue extends CheqdStatusListCredentialIdValue { static Did = CheqdMainnetDid; - - static cheqdDid(did) { - return did; - } } export class CheqdStatusListCredentialId extends StatusListCredentialId { diff --git a/packages/credential-sdk/tests/__snapshots__/document.test.js.snap b/packages/credential-sdk/tests/__snapshots__/document.test.js.snap index 91e167d28..377fa5106 100644 --- a/packages/credential-sdk/tests/__snapshots__/document.test.js.snap +++ b/packages/credential-sdk/tests/__snapshots__/document.test.js.snap @@ -377,12 +377,6 @@ exports[`DID document workflow \`CheqdMainnetDIDDocument\` 1`] = ` "verificationMaterial": "Bt5Mafvpcqou1pBF8SnW1BJMvpkSzZnPEgWunTUFwHZm", "verificationMethodType": "Ed25519VerificationKey2018", }, - { - "controller": "did:cheqd:mainnet:ed3a581d-b968-423e-afd1-64239a086165", - "id": "did:cheqd:mainnet:ed3a581d-b968-423e-afd1-64239a086165#keys-2", - "verificationMaterial": "11111111111111111111111111111111", - "verificationMethodType": "Ed25519VerificationKey2018", - }, ], "versionId": "0557d7da-8dea-45cb-8f30-7370b59eab71", } @@ -413,12 +407,6 @@ exports[`DID document workflow \`CheqdMainnetDIDDocument\` 2`] = ` "verificationMaterial": "Bt5Mafvpcqou1pBF8SnW1BJMvpkSzZnPEgWunTUFwHZm", "verificationMethodType": "Ed25519VerificationKey2018", }, - { - "controller": "did:cheqd:mainnet:ed3a581d-b968-423e-afd1-64239a086165", - "id": "did:cheqd:mainnet:ed3a581d-b968-423e-afd1-64239a086165#keys-2", - "verificationMaterial": "11111111111111111111111111111111", - "verificationMethodType": "Ed25519VerificationKey2018", - }, ], "versionId": "0557d7da-8dea-45cb-8f30-7370b59eab71", } @@ -559,83 +547,6 @@ exports[`DID document workflow \`CheqdTestnetDIDDocument\` 4`] = ` } `; -exports[`DID document workflow \`CheqdTestnetDIDDocument\` 5`] = ` -{ - "alsoKnownAs": [], - "assertionMethod": [ - { - "controller": "did:cheqd:mainnet:ed3a581d-b968-423e-afd1-64239a086165", - "id": "did:cheqd:mainnet:ed3a581d-b968-423e-afd1-64239a086165#keys-2", - "verificationMaterial": "CeEf4Q1kvLo66eSbTSujuasf2mv1rTQEpK8rnuyqMxpP", - "verificationMethodType": "Bls12381BBSVerificationKeyDock2023", - }, - ], - "authentication": [ - "did:cheqd:mainnet:ed3a581d-b968-423e-afd1-64239a086165#keys-1", - ], - "capabilityDelegation": [], - "capabilityInvocation": [], - "context": [ - "https://www.w3.org/ns/did/v1", - ], - "controller": [], - "id": "did:cheqd:mainnet:ed3a581d-b968-423e-afd1-64239a086165", - "keyAgreement": [], - "service": [], - "verificationMethod": [ - { - "controller": "did:cheqd:mainnet:ed3a581d-b968-423e-afd1-64239a086165", - "id": "did:cheqd:mainnet:ed3a581d-b968-423e-afd1-64239a086165#keys-1", - "verificationMaterial": "Bt5Mafvpcqou1pBF8SnW1BJMvpkSzZnPEgWunTUFwHZm", - "verificationMethodType": "Ed25519VerificationKey2018", - }, - { - "controller": "did:cheqd:mainnet:ed3a581d-b968-423e-afd1-64239a086165", - "id": "did:cheqd:mainnet:ed3a581d-b968-423e-afd1-64239a086165#keys-2", - "verificationMaterial": "11111111111111111111111111111111", - "verificationMethodType": "Ed25519VerificationKey2018", - }, - ], - "versionId": "0557d7da-8dea-45cb-8f30-7370b59eab71", -} -`; - -exports[`DID document workflow \`CheqdTestnetDIDDocument\` 6`] = ` -{ - "alsoKnownAs": [], - "assertionMethod": [ - ""{\\"id\\":\\"did:cheqd:mainnet:ed3a581d-b968-423e-afd1-64239a086165#keys-2\\",\\"controller\\":\\"did:cheqd:mainnet:ed3a581d-b968-423e-afd1-64239a086165\\",\\"verificationMethodType\\":\\"Bls12381BBSVerificationKeyDock2023\\",\\"verificationMaterial\\":\\"CeEf4Q1kvLo66eSbTSujuasf2mv1rTQEpK8rnuyqMxpP\\"}"", - ], - "authentication": [ - "did:cheqd:mainnet:ed3a581d-b968-423e-afd1-64239a086165#keys-1", - ], - "capabilityDelegation": [], - "capabilityInvocation": [], - "context": [ - "https://www.w3.org/ns/did/v1", - ], - "controller": [], - "id": "did:cheqd:mainnet:ed3a581d-b968-423e-afd1-64239a086165", - "keyAgreement": [], - "service": [], - "verificationMethod": [ - { - "controller": "did:cheqd:mainnet:ed3a581d-b968-423e-afd1-64239a086165", - "id": "did:cheqd:mainnet:ed3a581d-b968-423e-afd1-64239a086165#keys-1", - "verificationMaterial": "Bt5Mafvpcqou1pBF8SnW1BJMvpkSzZnPEgWunTUFwHZm", - "verificationMethodType": "Ed25519VerificationKey2018", - }, - { - "controller": "did:cheqd:mainnet:ed3a581d-b968-423e-afd1-64239a086165", - "id": "did:cheqd:mainnet:ed3a581d-b968-423e-afd1-64239a086165#keys-2", - "verificationMaterial": "11111111111111111111111111111111", - "verificationMethodType": "Ed25519VerificationKey2018", - }, - ], - "versionId": "0557d7da-8dea-45cb-8f30-7370b59eab71", -} -`; - exports[`DID document workflow \`DIDDocument.from\` works 1`] = ` { "@context": [ diff --git a/packages/credential-sdk/tests/document.test.js b/packages/credential-sdk/tests/document.test.js index 0787f6c97..d4dec846b 100644 --- a/packages/credential-sdk/tests/document.test.js +++ b/packages/credential-sdk/tests/document.test.js @@ -25,6 +25,70 @@ import { hexToU8a, maybeToCheqdPayloadOrJSON } from "../src/utils"; import { verMethodRefsEqual } from "../src/vc"; import { CheqdTestnetVerificationMethodRef } from "../src/types/did/document/verification-method-ref"; +const LEGACY_TESTNET_DOC = { + context: ["https://www.w3.org/ns/did/v1"], + id: "did:cheqd:testnet:ed3a581d-b968-423e-afd1-64239a086165", + alsoKnownAs: [], + controller: [], + verificationMethod: [ + { + id: "did:cheqd:testnet:ed3a581d-b968-423e-afd1-64239a086165#keys-1", + controller: "did:cheqd:testnet:ed3a581d-b968-423e-afd1-64239a086165", + verificationMethodType: "Ed25519VerificationKey2018", + verificationMaterial: "Bt5Mafvpcqou1pBF8SnW1BJMvpkSzZnPEgWunTUFwHZm", + }, + { + id: "did:cheqd:testnet:ed3a581d-b968-423e-afd1-64239a086165#keys-2", + controller: "did:cheqd:testnet:ed3a581d-b968-423e-afd1-64239a086165", + verificationMethodType: "Ed25519VerificationKey2018", + verificationMaterial: "11111111111111111111111111111111", + }, + ], + service: [], + authentication: [ + "did:cheqd:testnet:ed3a581d-b968-423e-afd1-64239a086165#keys-1", + ], + assertionMethod: [ + '"{\\"id\\":\\"did:cheqd:testnet:ed3a581d-b968-423e-afd1-64239a086165#keys-2\\",\\"controller\\":\\"did:cheqd:testnet:ed3a581d-b968-423e-afd1-64239a086165\\",\\"verificationMethodType\\":\\"Bls12381BBSVerificationKeyDock2023\\",\\"verificationMaterial\\":\\"CeEf4Q1kvLo66eSbTSujuasf2mv1rTQEpK8rnuyqMxpP\\"}"', + ], + keyAgreement: [], + capabilityInvocation: [], + capabilityDelegation: [], + versionId: "0557d7da-8dea-45cb-8f30-7370b59eab71", +}; + +const LEGACY_MAINNET_DOC = { + context: ["https://www.w3.org/ns/did/v1"], + id: "did:cheqd:mainnet:ed3a581d-b968-423e-afd1-64239a086165", + alsoKnownAs: [], + controller: [], + verificationMethod: [ + { + id: "did:cheqd:mainnet:ed3a581d-b968-423e-afd1-64239a086165#keys-1", + controller: "did:cheqd:mainnet:ed3a581d-b968-423e-afd1-64239a086165", + verificationMethodType: "Ed25519VerificationKey2018", + verificationMaterial: "Bt5Mafvpcqou1pBF8SnW1BJMvpkSzZnPEgWunTUFwHZm", + }, + { + id: "did:cheqd:mainnet:ed3a581d-b968-423e-afd1-64239a086165#keys-2", + controller: "did:cheqd:mainnet:ed3a581d-b968-423e-afd1-64239a086165", + verificationMethodType: "Ed25519VerificationKey2018", + verificationMaterial: "11111111111111111111111111111111", + }, + ], + service: [], + authentication: [ + "did:cheqd:mainnet:ed3a581d-b968-423e-afd1-64239a086165#keys-1", + ], + assertionMethod: [ + '"{\\"id\\":\\"did:cheqd:mainnet:ed3a581d-b968-423e-afd1-64239a086165#keys-2\\",\\"controller\\":\\"did:cheqd:mainnet:ed3a581d-b968-423e-afd1-64239a086165\\",\\"verificationMethodType\\":\\"Bls12381BBSVerificationKeyDock2023\\",\\"verificationMaterial\\":\\"CeEf4Q1kvLo66eSbTSujuasf2mv1rTQEpK8rnuyqMxpP\\"}"', + ], + keyAgreement: [], + capabilityInvocation: [], + capabilityDelegation: [], + versionId: "0557d7da-8dea-45cb-8f30-7370b59eab71", +}; + const RANDOM_PKS = [ "0xa1aa6a2058dd190e284a64e72adaf4e16a9ae9fbf0673d7575924e6aca3b21dc", "0xed28a616e8f8cfd2232b62dac57281b24fc0d538150f8f5d91a0b6c3255cc2c9", @@ -275,22 +339,9 @@ describe("DID document workflow", () => { ] ).toCheqd(CheqdTestnetDIDDocument, "0557d7da-8dea-45cb-8f30-7370b59eab71"); - const legacyDoc = DIDDocument.create( - "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk", - [ - new DidKey(RANDOM_PKS[0], AUTH), - new DidKey( - new BBSPublicKey(new BBSPublicKeyValue(RANDOM_OFFCHAIN_PKS[0])) - ), - ] - ).toCheqd(CheqdMainnetDIDDocument, "0557d7da-8dea-45cb-8f30-7370b59eab71"); - const strLegacyDoc = JSON.stringify( - maybeToCheqdPayloadOrJSON(legacyDoc) - ).replace(/mainnet/g, "testnet"); + const fromLegacy = CheqdTestnetDIDDocument.from(LEGACY_TESTNET_DOC); - const fromLegacy = CheqdTestnetDIDDocument.from(JSON.parse(strLegacyDoc)); - - checkDocs(testnetDoc, fromLegacy, legacyDoc); + checkDocs(testnetDoc, fromLegacy); }); test(`\`CheqdMainnetDIDDocument\``, () => { @@ -302,6 +353,8 @@ describe("DID document workflow", () => { ] ).toCheqd(CheqdMainnetDIDDocument, "0557d7da-8dea-45cb-8f30-7370b59eab71"); - checkDoc(mainnetDoc); + const fromLegacy = CheqdMainnetDIDDocument.from(LEGACY_MAINNET_DOC); + + checkDoc(mainnetDoc, fromLegacy); }); }); diff --git a/packages/dock-blockchain-api/CHANGELOG.md b/packages/dock-blockchain-api/CHANGELOG.md index 90152c5b5..e00349778 100644 --- a/packages/dock-blockchain-api/CHANGELOG.md +++ b/packages/dock-blockchain-api/CHANGELOG.md @@ -1,5 +1,12 @@ # @docknetwork/dock-blockchain-api +## 0.19.1 + +### Patch Changes + +- Updated dependencies + - @docknetwork/credential-sdk@0.36.0 + ## 0.19.0 ### Minor Changes diff --git a/packages/dock-blockchain-api/package.json b/packages/dock-blockchain-api/package.json index 05d7d6e85..5a26945c8 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.19.0", + "version": "0.19.1", "license": "MIT", "main": "./dist/esm/index.js", "type": "module", @@ -89,7 +89,7 @@ "@polkadot/api": "10.12.4" }, "dependencies": { - "@docknetwork/credential-sdk": "0.35.0", + "@docknetwork/credential-sdk": "0.36.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 fffdf6f1d..163fcb838 100644 --- a/packages/dock-blockchain-modules/CHANGELOG.md +++ b/packages/dock-blockchain-modules/CHANGELOG.md @@ -1,5 +1,12 @@ # @docknetwork/dock-blockchain-modules +## 0.24.1 + +### Patch Changes + +- Updated dependencies + - @docknetwork/credential-sdk@0.36.0 + ## 0.24.0 ### Minor Changes diff --git a/packages/dock-blockchain-modules/package.json b/packages/dock-blockchain-modules/package.json index cf02a07ef..1afe2640a 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.24.0", + "version": "0.24.1", "license": "MIT", "type": "module", "main": "./dist/esm/index.js", @@ -33,7 +33,7 @@ "node": ">=18.0.0" }, "dependencies": { - "@docknetwork/credential-sdk": "0.35.0" + "@docknetwork/credential-sdk": "0.36.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.19.0", + "@docknetwork/dock-blockchain-api": "0.19.1", "@rollup/plugin-alias": "^4.0.2", "@rollup/plugin-babel": "^6.0.4", "@rollup/plugin-commonjs": "^24.0.0",