From d41ecff7ae328abb560d9e57f82b56b5984abf5f Mon Sep 17 00:00:00 2001 From: olegnn Date: Mon, 2 Dec 2024 15:19:24 +0400 Subject: [PATCH] Tweaks --- .../src/common/inject-params.js | 2 +- .../src/types/did/document/index.js | 47 ++- .../did/document/verification-method copy.js | 186 ------------ .../types/did/document/verification-method.js | 4 +- .../src/types/generic/with-base58.js | 79 ++++-- .../src/types/generic/with-base64.js | 79 ++++-- .../credential-sdk/src/types/policy/index.js | 6 +- .../src/types/policy/one-of-policy-value.js | 11 +- .../src/types/status-list-credential/id.js | 11 +- packages/credential-sdk/src/utils/base-x.js | 22 +- packages/credential-sdk/src/vc/credentials.js | 6 +- .../tests/__snapshots__/document.test.js.snap | 267 ++++++++++++++---- .../credential-sdk/tests/document.test.js | 155 +++++++--- packages/credential-sdk/tests/issuing.test.js | 1 + .../src/status-list-credential/internal.js | 6 +- .../src/status-list-credential/module.js | 4 +- .../status-list-credential-module.test.js | 53 +--- .../status-list-credential.test.js | 5 +- 18 files changed, 518 insertions(+), 426 deletions(-) delete mode 100644 packages/credential-sdk/src/types/did/document/verification-method copy.js diff --git a/packages/cheqd-blockchain-modules/src/common/inject-params.js b/packages/cheqd-blockchain-modules/src/common/inject-params.js index a5e6db53a..b9aa33953 100644 --- a/packages/cheqd-blockchain-modules/src/common/inject-params.js +++ b/packages/cheqd-blockchain-modules/src/common/inject-params.js @@ -5,7 +5,7 @@ import { u8aToString, } from '@docknetwork/credential-sdk/utils'; import { CheqdParamsId } from '@docknetwork/credential-sdk/types'; -import { createInternalCheqdModule } from './builders'; +import createInternalCheqdModule from './create-internal-cheqd-module'; import { CheqdCreateResource } from './payload'; const methods = { diff --git a/packages/credential-sdk/src/types/did/document/index.js b/packages/credential-sdk/src/types/did/document/index.js index ef9a91757..0824b4d43 100644 --- a/packages/credential-sdk/src/types/did/document/index.js +++ b/packages/credential-sdk/src/types/did/document/index.js @@ -309,20 +309,43 @@ export class CheqdDIDDocument extends TypedStruct { versionId: option(VersionId), }; - constructor(...args) { - super(...args); + constructor( + context, + id, + alsoKnownAs, + controller, + rawVerificationMethodWithOffchainKeys, + service, + authentication, + assertionMethodWithOffchainKeys, + keyAgreement, + capabilityInvocation, + capabilityDelegation, + versionId = TypedUUID.random(), + ) { + const verificationMethodWithOffchainKeys = [...rawVerificationMethodWithOffchainKeys].map((verMethod) => CheqdVerificationMethod.from(verMethod)); - const offchainVerMethod = [ - ...this.verificationMethod.filter((verMethod) => verMethod.isOffchain()), - ].map((verMethod) => verMethod.toVerificationMethod()); - this.verificationMethod = this.verificationMethod.filter( + const offchainVerMethod = verificationMethodWithOffchainKeys.filter((verMethod) => verMethod.isOffchain()); + const verificationMethod = verificationMethodWithOffchainKeys.filter( (verMethod) => !verMethod.isOffchain(), ); - - this.assertionMethod = [ - ...this.assertionMethod, - ...[...offchainVerMethod].map((verMethod) => verMethod.toVerificationMethodRefWithDidKey()), + const assertionMethod = [ + ...AssertionMethod.from(assertionMethodWithOffchainKeys).filter((ref) => !offchainVerMethod.some((verMethod) => verMethod.id.eq(ref))), + ...[...offchainVerMethod].map((verMethod) => verMethod.toVerificationMethod().toVerificationMethodRefWithDidKey()), ]; + + super(context, + id, + alsoKnownAs, + controller, + verificationMethod, + service, + authentication, + assertionMethod, + keyAgreement, + capabilityInvocation, + capabilityDelegation, + versionId); } toDIDDocument() { @@ -345,8 +368,8 @@ export class CheqdDIDDocument extends TypedStruct { (keyRefOrKey) => keyRefOrKey instanceof VerificationMethodRefWithDidKey, ), ].map((verMethod) => verMethod.toVerificationMethod()); - const assertionMethodWithoutOffchainKeys = assertionMethod.filter( - (keyRefOrKey) => !(keyRefOrKey instanceof VerificationMethodRefWithDidKey), + const assertionMethodWithoutOffchainKeys = [...assertionMethod].map( + (keyRefOrKey) => (keyRefOrKey instanceof VerificationMethodRefWithDidKey ? keyRefOrKey.ref : keyRefOrKey), ); return new DIDDocument( diff --git a/packages/credential-sdk/src/types/did/document/verification-method copy.js b/packages/credential-sdk/src/types/did/document/verification-method copy.js deleted file mode 100644 index 1fac9d1ce..000000000 --- a/packages/credential-sdk/src/types/did/document/verification-method copy.js +++ /dev/null @@ -1,186 +0,0 @@ -import { - withFrom, TypedStruct, withBase58, TypedBytes, option, TypedString, -} from '../../generic'; -import { - BBDT16PublicKey, - BBDT16PublicKeyValue, - BBSPlusPublicKey, - BBSPlusPublicKeyValue, - BBSPublicKey, - BBSPublicKeyValue, - PSPublicKey, - PSPublicKeyValue, -} from '../../offchain-signatures'; -import { - PublicKeyEd25519, - PublicKeySecp256k1, - PublicKeySr25519, -} from '../../public-keys'; -import { - EcdsaSecp256k1VerKeyName, - Ed255192020VerKeyName, - Ed25519VerKeyName, - Sr25519VerKeyName, - Bls12381BBSDockVerKeyName, - Bls12381BBS23DockVerKeyName, - Bls12381PSDockVerKeyName, - Bls12381BBDT16DockVerKeyName, -} from '../../../vc/crypto'; -import { Ed25519Verification2018Method, Ed25519Verification2020Method, VerificationMethodType } from './verification-method-type'; -import VerificationMethodRef from './verification-method-ref'; -import { NamespaceDid } from '../onchain/typed-did'; -import { fmtIter, valueBytes } from '../../../utils'; -import { DidKeyValue } from '../onchain/did-key'; - -export class PublicKeyBase58 extends withBase58(TypedBytes) {} - -// eslint-disable-next-line no-use-before-define -export class VerificationMethod extends withFrom(TypedStruct, (value, from) => (value instanceof CheqdVerificationMethod - ? value.toVerificationMethod() - : from(value))) { - static Classes = { - id: VerificationMethodRef, - type: VerificationMethodType, - controller: NamespaceDid, - publicKeyBase58: option(PublicKeyBase58), - publicKeyBase64: option(TypedBytes), - publicKeyJwk: option(TypedString), - publicKeyHex: option(TypedBytes), - }; - - isOffchain() { - return !( - this.type instanceof Ed25519Verification2018Method - || this.type instanceof Ed25519Verification2020Method - ); - } - - publicKey() { - const bytes = ( - this.publicKeyBase58 - || this.publicKeyBase64 - || this.publicKeyJwk - || this.publicKeyHex - )?.bytes; - - if (bytes == null) { - throw new Error( - `Expected either of ${fmtIter([ - 'publicKeyBase58', - 'publicKeyBase64', - 'publicKeyJwk', - 'publicKeyHex', - ])} to be specified`, - ); - } - - switch (this.type.type) { - case Ed25519VerKeyName: - return new PublicKeyEd25519(bytes); - case Sr25519VerKeyName: - return new PublicKeySr25519(bytes); - case Ed255192020VerKeyName: - return new PublicKeyEd25519(bytes); - case EcdsaSecp256k1VerKeyName: - return new PublicKeySecp256k1(bytes); - case Bls12381BBSDockVerKeyName: - return new BBSPlusPublicKey(new BBSPlusPublicKeyValue(bytes)); - case Bls12381BBS23DockVerKeyName: - return new BBSPublicKey(new BBSPublicKeyValue(bytes)); - case Bls12381PSDockVerKeyName: - return new PSPublicKey(new PSPublicKeyValue(bytes)); - case Bls12381BBDT16DockVerKeyName: - return new BBDT16PublicKey(new BBDT16PublicKeyValue(bytes)); - default: - throw new Error(`Unknown key type ${this.type.type}`); - } - } - - static fromDidKey(keyRef, didKey) { - const ref = VerificationMethodRef.from(keyRef); - - return new this( - ref, - didKey.publicKey.constructor.VerKeyType, - ref[0], - valueBytes(didKey.publicKey), - ); - } - - toCheqdVerificationMethod() { - // eslint-disable-next-line no-use-before-define - return new CheqdVerificationMethod( - this.id, - this.controller, - this.type, - valueBytes(this.publicKey()), - ); - } - - toVerificationMethodRefWithDidKey() { - // eslint-disable-next-line no-use-before-define - return new VerificationMethodRefWithDidKey(this.id, this.publicKey()); - } -} - -export class CheqdVerificationMethod extends withFrom( - TypedStruct, - (value, from) => (value instanceof VerificationMethod - ? value.toCheqdVerificationMethod() - : from(value)), -) { - static Classes = { - id: VerificationMethodRef, - controller: NamespaceDid, - verificationMethodType: VerificationMethodType, - verificationMaterial: PublicKeyBase58, - }; - - isOffchain() { - return !( - this.verificationMethodType instanceof Ed25519Verification2018Method - || this.verificationMethodType instanceof Ed25519Verification2020Method - ); - } - - toVerificationMethod() { - return new VerificationMethod( - this.id, - this.verificationMethodType, - this.controller, - this.verificationMaterial, - ); - } -} - -export class VerificationMethodRefWithDidKey extends withFrom( - TypedStruct, - function from(value, fromFn) { - if (typeof value === 'string') { - return new this(...value.split('=')); - } else { - return fromFn(value); - } - }, -) { - static Classes = { - ref: VerificationMethodRef, - key: withBase58(DidKeyValue), - }; - - toVerificationMethod() { - // eslint-disable-next-line no-use-before-define - return new VerificationMethod( - this.ref, - this.key.constructor.VerKeyType, - this.ref.did, - this.key.value.bytes, - ); - } - - toJSON() { - const { ref, key } = this; - - return `${ref}=${key}`; - } -} 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 1fac9d1ce..5687a7ca8 100644 --- a/packages/credential-sdk/src/types/did/document/verification-method.js +++ b/packages/credential-sdk/src/types/did/document/verification-method.js @@ -29,7 +29,9 @@ import { import { Ed25519Verification2018Method, Ed25519Verification2020Method, VerificationMethodType } from './verification-method-type'; import VerificationMethodRef from './verification-method-ref'; import { NamespaceDid } from '../onchain/typed-did'; -import { fmtIter, valueBytes } from '../../../utils'; +import { + fmtIter, valueBytes, +} from '../../../utils'; import { DidKeyValue } from '../onchain/did-key'; export class PublicKeyBase58 extends withBase58(TypedBytes) {} diff --git a/packages/credential-sdk/src/types/generic/with-base58.js b/packages/credential-sdk/src/types/generic/with-base58.js index 9bd1761d6..54c52fb4f 100644 --- a/packages/credential-sdk/src/types/generic/with-base58.js +++ b/packages/credential-sdk/src/types/generic/with-base58.js @@ -1,27 +1,62 @@ import withFrom from './with-from'; -import { decodeFromBase58, encodeAsBase58 } from '../../utils/base-x'; +import { + decodeFromBase58, encodeAsBase58, isEqualToOrPrototypeOf, u8aToString, stringToU8a, maybeToJSONString, +} from '../../utils'; +import TypedEnum from './typed-enum'; export default function withBase58(klass) { const name = `withBase58(${klass.name})`; - const obj = { - [name]: class extends klass { - toString() { - return this.toBase58(); - } - - toJSON() { - return String(this); - } - - static fromBase58(str) { - return this.from(decodeFromBase58(str)); - } - - toBase58() { - return encodeAsBase58(this.bytes); - } - }, - }; - - return withFrom(obj[name], function from(value, fromFn) { return (typeof value === 'string' ? this.fromBase58(value) : fromFn(value)); }); + let res; + + if (!isEqualToOrPrototypeOf(TypedEnum, klass)) { + const obj = { + [name]: class extends klass { + toString() { + return this.toBase58(); + } + + toJSON() { + return String(this); + } + + static fromBase58(str) { + return this.from(decodeFromBase58(str)); + } + + toBase58() { + return encodeAsBase58(this.bytes); + } + }, + }; + + res = obj[name]; + } else { + const obj = { + [name]: class extends klass { + static Class = klass.Class; + + static Variants = !klass.Class ? klass.Variants?.map(withBase58) : klass.Variants; + + toString() { + return this.toBase58(); + } + + static fromBase58(str) { + return this.fromJSON(JSON.parse(u8aToString(decodeFromBase58(str)))); + } + + toBase58() { + return encodeAsBase58(this.bytes); + } + + get bytes() { + return stringToU8a(maybeToJSONString(this)); + } + }, + }; + + res = obj[name]; + } + + return withFrom(res, function from(value, fromFn) { return (typeof value === 'string' ? this.fromBase58(value) : fromFn(value)); }); } diff --git a/packages/credential-sdk/src/types/generic/with-base64.js b/packages/credential-sdk/src/types/generic/with-base64.js index 9976530a6..c0f499364 100644 --- a/packages/credential-sdk/src/types/generic/with-base64.js +++ b/packages/credential-sdk/src/types/generic/with-base64.js @@ -1,27 +1,62 @@ import withFrom from './with-from'; -import { decodeFromBase64, encodeAsBase64 } from '../../utils/base-x'; +import { + decodeFromBase64, encodeAsBase64, isEqualToOrPrototypeOf, u8aToString, stringToU8a, maybeToJSONString, +} from '../../utils'; +import TypedEnum from './typed-enum'; export default function withBase64(klass) { const name = `withBase64(${klass.name})`; - const obj = { - [name]: class extends klass { - toString() { - return this.toBase64(); - } - - toJSON() { - return String(this); - } - - static fromBase64(str) { - return this.from(decodeFromBase64(str)); - } - - toBase64() { - return encodeAsBase64(this.bytes); - } - }, - }; - - return withFrom(obj[name], function from(value, fromFn) { return typeof value === 'string' ? this.fromBase64(value) : fromFn(value); }); + let res; + + if (!isEqualToOrPrototypeOf(TypedEnum, klass)) { + const obj = { + [name]: class extends klass { + toString() { + return this.toBase64(); + } + + toJSON() { + return String(this); + } + + static fromBase64(str) { + return this.from(decodeFromBase64(str)); + } + + toBase64() { + return encodeAsBase64(this.bytes); + } + }, + }; + + res = obj[name]; + } else { + const obj = { + [name]: class extends klass { + static Class = klass.Class; + + static Variants = !klass.Class ? klass.Variants?.map(withBase64) : klass.Variants; + + toString() { + return this.toBase64(); + } + + static fromBase64(str) { + return this.fromJSON(JSON.parse(u8aToString(decodeFromBase64(str)))); + } + + toBase64() { + return encodeAsBase64(this.bytes); + } + + get bytes() { + return stringToU8a(maybeToJSONString(this)); + } + }, + }; + + res = obj[name]; + } + + return withFrom(res, function from(value, fromFn) { return (typeof value === 'string' ? this.fromBase64(value) : fromFn(value)); }); } diff --git a/packages/credential-sdk/src/types/policy/index.js b/packages/credential-sdk/src/types/policy/index.js index 9c42871be..61b681467 100644 --- a/packages/credential-sdk/src/types/policy/index.js +++ b/packages/credential-sdk/src/types/policy/index.js @@ -5,8 +5,12 @@ export class Policy extends TypedEnum {} export class OneOfPolicy extends Policy { static Class = OneOfPolicyValue; + /** + * Add a owner to the policy + * @param {*} ownerDID - Owner's DID + */ addOwner(ownerDID) { - return this.value.addOwner(ownerDID); + return this.value.add(ownerDID); } } diff --git a/packages/credential-sdk/src/types/policy/one-of-policy-value.js b/packages/credential-sdk/src/types/policy/one-of-policy-value.js index 19246f886..09e51c630 100644 --- a/packages/credential-sdk/src/types/policy/one-of-policy-value.js +++ b/packages/credential-sdk/src/types/policy/one-of-policy-value.js @@ -3,20 +3,11 @@ import { DockDidOrDidMethodKey } from '../did/onchain/typed-did'; /** * Constructs a OneOfPolicy with given controllers - * @param {any} [controllers] - Controller set + * @param {Iterable<*>} [controllers] - Controller set * @constructor */ - export default class OneOfPolicyValue extends TypedSet { static Type = 'oneOf'; static Class = DockDidOrDidMethodKey; - - /** - * Add a owner to the policy - * @param {string} ownerDID - Owner's DID - */ - addOwner(ownerDID) { - this.add(this.constructor.Class.from(ownerDID)); - } } 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 8a56e4fb2..3e693bc8b 100644 --- a/packages/credential-sdk/src/types/status-list-credential/id.js +++ b/packages/credential-sdk/src/types/status-list-credential/id.js @@ -14,13 +14,13 @@ export class StatusListCredentialId extends withFrom( (value, from) => { try { // eslint-disable-next-line no-use-before-define - return DockStatusListCredentialId.from(value); + return from(DockStatusListCredentialIdValue.from(value)); } catch { return from(value); } }, ) { - static Qualifier = 'status-list2021'; + static Qualifier = 'status-list2021:'; toJSON() { return String(this); @@ -53,7 +53,8 @@ export class CheqdStatusListCredentialIdValue extends withQualifier(DidRef) { } } -export class DockStatusListCredentialIdValue extends sized(withQualifier(TypedBytes)) { +// eslint-disable-next-line no-use-before-define +export class DockStatusListCredentialIdValue extends withFrom(sized(withQualifier(TypedBytes)), (value, from) => (value instanceof DockStatusListCredentialId ? value[1] : from(value))) { static Qualifier = DockStatusList2021Qualifier; static Size = 32; @@ -68,8 +69,6 @@ export class DockStatusListCredentialIdValue extends sized(withQualifier(TypedBy } export class CheqdStatusListCredentialId extends StatusListCredentialId { - static Qualifier = CheqdStatusList2021Qualifier; - static Class = CheqdStatusListCredentialIdValue; static Type = 'cheqd'; @@ -80,8 +79,6 @@ export class CheqdStatusListCredentialId extends StatusListCredentialId { } export class DockStatusListCredentialId extends StatusListCredentialId { - static Qualifier = DockStatusList2021Qualifier; - static Class = DockStatusListCredentialIdValue; static Type = 'dock'; diff --git a/packages/credential-sdk/src/utils/base-x.js b/packages/credential-sdk/src/utils/base-x.js index 58fef2db9..8e310758a 100644 --- a/packages/credential-sdk/src/utils/base-x.js +++ b/packages/credential-sdk/src/utils/base-x.js @@ -15,7 +15,15 @@ export const encodeAsBase58 = (bytes) => bs58.encode(normalizeToU8a(bytes)); * @param {string} string * @returns {Uint8Array} */ -export const decodeFromBase58 = (string) => bs58.decode(ensureString(string)); +export const decodeFromBase58 = (string) => { + try { + return bs58.decode(ensureString(string)); + } catch (err) { + err.message = `Failed to decode base58 string \`${string}\`:\n${err.message}`; + + throw err; + } +}; /** * Encodes supplied bytes as base58btc string using given prefix. @@ -44,10 +52,16 @@ export const encodeAsBase58btc = (prefix, value) => { * @returns {Uint8Array} */ export const decodeFromBase58btc = (string) => { + try { // Decode base58btc multibase string - const decoded = base58btc.decode(ensureString(string)); - varint.decode(decoded); // Decode to get byte length - return decoded.slice(varint.decode.bytes); + const decoded = base58btc.decode(ensureString(string)); + varint.decode(decoded); // Decode to get byte length + return decoded.slice(varint.decode.bytes); + } catch (err) { + err.message = `Failed to decode base58btc string \`${string}\`:\n${err.message}`; + + throw err; + } }; /** diff --git a/packages/credential-sdk/src/vc/credentials.js b/packages/credential-sdk/src/vc/credentials.js index 2bc594587..300470011 100644 --- a/packages/credential-sdk/src/vc/credentials.js +++ b/packages/credential-sdk/src/vc/credentials.js @@ -25,7 +25,6 @@ import { DEFAULT_CONTEXT_V1_URL, credentialContextField, PrivateStatusList2021EntryType, - DockStatusList2021Qualifier, StatusList2021EntryType, PrivateStatusList2021Qualifier, } from './constants'; @@ -695,13 +694,14 @@ export function addStatusList21EntryToCredential( purpose, ) { validateStatusPurpose(purpose); + return { ...cred, credentialStatus: { - id: `${DockStatusList2021Qualifier}${statusListCredentialId}#${statusListCredentialIndex}`, + id: `${statusListCredentialId}#${statusListCredentialIndex}`, type: StatusList2021EntryType, statusListIndex: String(statusListCredentialIndex), - statusListCredential: `${DockStatusList2021Qualifier}${statusListCredentialId}`, + statusListCredential: String(statusListCredentialId), statusPurpose: purpose, }, }; diff --git a/packages/credential-sdk/tests/__snapshots__/document.test.js.snap b/packages/credential-sdk/tests/__snapshots__/document.test.js.snap index e3e8252fc..ec764409b 100644 --- a/packages/credential-sdk/tests/__snapshots__/document.test.js.snap +++ b/packages/credential-sdk/tests/__snapshots__/document.test.js.snap @@ -1,32 +1,30 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`\`DIDDocument\` \`DIDDocument.create\` works 1`] = ` +exports[`DID document workflow \`CheqdDIDDocument\` 1`] = ` { - "@context": [ - "https://www.w3.org/ns/did/v1", - ], "alsoKnownAs": [], "assertionMethod": [], "authentication": [], "capabilityDelegation": [], "capabilityInvocation": [], + "context": [ + "https://www.w3.org/ns/did/v1", + ], "controller": [], - "https://rdf.dock.io/alpha/2021#attestsDocumentContents": null, - "id": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk", + "id": "did:cheqd:testnet:6ec66297-f55e-4744-b8cd-bd043bc45767", "keyAgreement": [], "service": [], "verificationMethod": [], + "versionId": "0557d7da-8dea-45cb-8f30-7370b59eab71", } `; -exports[`\`DIDDocument\` \`DIDDocument.create\` works 2`] = ` +exports[`DID document workflow \`CheqdDIDDocument\` 2`] = ` { - "@context": [ - "https://www.w3.org/ns/did/v1", - ], "alsoKnownAs": [], "assertionMethod": [ "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-1", + "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-2=BBXr5GktzTvvVhRsbmYdJw2Tw3LHbkL8GBewX7KoKTZC8cVhbtbm23jCSmkiqnLEs2vwJDQWFFb5FvNJhDuCHPaZkVobYByLv57KQYVriE7CwrzjXPcp61RVq6sChaE3hQ7SvDVyF55zrZ7xZTyXYKDMLvhYKmHwL8kJ1o9KAq5ZNBFJFSqhCJvejjkPXHg5YXPHAvFKS", ], "authentication": [ "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-1", @@ -35,10 +33,12 @@ exports[`\`DIDDocument\` \`DIDDocument.create\` works 2`] = ` "capabilityInvocation": [ "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-1", ], + "context": [ + "https://www.w3.org/ns/did/v1", + ], "controller": [ "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54", ], - "https://rdf.dock.io/alpha/2021#attestsDocumentContents": null, "id": "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54", "keyAgreement": [], "service": [], @@ -46,7 +46,128 @@ exports[`\`DIDDocument\` \`DIDDocument.create\` works 2`] = ` { "controller": "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54", "id": "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-1", - "publicKeyBase58": "Bt5Mafvpcqou1pBF8SnW1BJMvpkSzZnPEgWunTUFwHZm", + "verificationMaterial": "Bt5Mafvpcqou1pBF8SnW1BJMvpkSzZnPEgWunTUFwHZm", + "verificationMethodType": "Ed25519VerificationKey2018", + }, + ], + "versionId": "28edc043-872b-4ab7-9cb8-b01d1bd677c5", +} +`; + +exports[`DID document workflow \`CheqdDIDDocument\` 3`] = ` +{ + "alsoKnownAs": [], + "assertionMethod": [ + "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-3", + "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-6", + "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-8", + "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-9", + "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-2=BBXr5GktzTvvVhRsbmYdJw2Tw3LHbkL8GBewX7KoKTZC8cVhbtbm23jCSmkiqnLEs2vwJDQWFFb5FvNJhDuCHPaZkVobYByLv57KQYVriE7CwrzjXPcp61RVq6sChaE3hQ7SvDVyF55zrZ7xZTyXYKDMLvhYKmHwL8kJ1o9KAq5ZNBFJFSqhCJvejjkPXHg5YXPHAvFKS", + "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-5=BBXr5GktzTvvVhRsbmYdJw2Tw3G5BoeByaj9iFtGToMCQHXwjsjRvLUpz94VaiJVAYrs4uyKBmBoMN89tbo4dzX5nizBn6MjwbZXKHEKd2ZBzXaVg4TTdw6VHXT9nWYs5PXBEZBWEncp5mZ4pUMwhLk6XQUgSXgYHN9PHik8vszRLLrN1TkWSKn1D2VAm2aGmHyu6Mtnp", + "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-11=BBXr5GktzTvvVhRsbmYdJw2Tw3GBAjToki5h3osi8WMS3RF4QLNS1D3atcFAHFFFFbXfETadaeApWKZsx5jF1WTtngunVo67bFhrd3KxFWtoYUoxtxNABmZpYPTP6HWeadskCqZFZeKVmCu2uu9TtuNjgBA5shwVHcc5cbmEsYavv4nq8oenCzMwjQ4cCxDE2KNHyFXL8", + "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-12=BBXr5GktzTvvVhRsbmYdJw2Tw3LUVjBmqG8HFzgouT6CmR8j6gN1hRg9wg6eBBNoffP4D42hRbzknBxiTSxZAPri5yrWHGKwohGZtirDvLDunXcVA1a4ATw4WdLsfJxK4ayTSqtBhWRJJ8Gcp6yKZBUY96K7242JRcBWP4gzgQsCtdf1AUDEWc5CKsGZ5LfSuTgfKrUQt", + ], + "authentication": [ + "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-1", + "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-6", + "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-7", + "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-9", + ], + "capabilityDelegation": [], + "capabilityInvocation": [ + "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-4", + "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-7", + "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-8", + "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-9", + ], + "context": [ + "https://www.w3.org/ns/did/v1", + ], + "controller": [ + "did:cheqd:mainnet:f1749383-d9dd-479f-82aa-e52fe8f59c54", + "did:cheqd:testnet:df3ba823-c1e2-46e0-bb54-056f9c506e90", + ], + "id": "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54", + "keyAgreement": [ + "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-10", + ], + "service": [], + "verificationMethod": [ + { + "controller": "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54", + "id": "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-1", + "verificationMaterial": "Bt5Mafvpcqou1pBF8SnW1BJMvpkSzZnPEgWunTUFwHZm", + "verificationMethodType": "Ed25519VerificationKey2018", + }, + { + "controller": "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54", + "id": "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-3", + "verificationMaterial": "GxmaKA52SZGQtZS3Usa6Az48gky2AZRKzRKxsXM6ystc", + "verificationMethodType": "Ed25519VerificationKey2018", + }, + { + "controller": "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54", + "id": "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-4", + "verificationMaterial": "5FBSa4xAs54osiMs75JcepL695v1XhccQmQePBZQaad9", + "verificationMethodType": "Ed25519VerificationKey2018", + }, + { + "controller": "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54", + "id": "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-6", + "verificationMaterial": "EaNp37NGpe8KViTKxAdknyvUP44doH1fHnFpYqEcfUjE", + "verificationMethodType": "Ed25519VerificationKey2018", + }, + { + "controller": "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54", + "id": "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-7", + "verificationMaterial": "A462rFkYENhY6kf9zLVPg6qvtQhXJ6RuL8CNdHTWzNqa", + "verificationMethodType": "Ed25519VerificationKey2018", + }, + { + "controller": "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54", + "id": "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-8", + "verificationMaterial": "Amb3kf4if5Av1sz6UdYtEw2iy6DzufRAtch6hiXEWHcw", + "verificationMethodType": "Ed25519VerificationKey2018", + }, + { + "controller": "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54", + "id": "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-9", + "verificationMaterial": "FwUvnTThdnNPv23Rbq2SXtxxYAT21Atvdd1cZBHPYue4", + "verificationMethodType": "Ed25519VerificationKey2018", + }, + { + "controller": "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54", + "id": "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54#keys-10", + "verificationMaterial": "BaGbEav6KzvWhgBWPyZK2vWX5EDDFc4a8rfUwAZ3x8Jn", + "verificationMethodType": "Ed25519VerificationKey2018", + }, + ], + "versionId": "47b4d97b-1ebe-4d81-a3ed-12eb63baaeb9", +} +`; + +exports[`DID document workflow \`DIDDocument.from\` works 1`] = ` +{ + "@context": [ + "test", + ], + "alsoKnownAs": null, + "assertionMethod": null, + "authentication": null, + "capabilityDelegation": null, + "capabilityInvocation": null, + "controller": [ + "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk", + ], + "https://rdf.dock.io/alpha/2021#attestsDocumentContents": null, + "id": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk", + "keyAgreement": null, + "service": null, + "verificationMethod": [ + { + "controller": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk", + "id": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-3", + "publicKeyBase58": "EaNp37NGpe8KViTKxAdknyvUP44doH1fHnFpYqEcfUjE", "publicKeyBase64": null, "publicKeyHex": null, "publicKeyJwk": null, @@ -56,7 +177,26 @@ exports[`\`DIDDocument\` \`DIDDocument.create\` works 2`] = ` } `; -exports[`\`DIDDocument\` \`DIDDocument.create\` works 3`] = ` +exports[`DID document workflow \`DIDDocument\` 1`] = ` +{ + "@context": [ + "https://www.w3.org/ns/did/v1", + ], + "alsoKnownAs": [], + "assertionMethod": [], + "authentication": [], + "capabilityDelegation": [], + "capabilityInvocation": [], + "controller": [], + "https://rdf.dock.io/alpha/2021#attestsDocumentContents": null, + "id": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk", + "keyAgreement": [], + "service": [], + "verificationMethod": [], +} +`; + +exports[`DID document workflow \`DIDDocument\` 2`] = ` { "@context": [ "https://www.w3.org/ns/did/v1", @@ -64,22 +204,26 @@ exports[`\`DIDDocument\` \`DIDDocument.create\` works 3`] = ` "alsoKnownAs": [], "assertionMethod": [ "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-2", - "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-4", + "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-3", + "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-5", "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-6", - "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-7", + "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-8", + "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-9", + "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-11", + "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-12", ], "authentication": [ "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-1", - "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-4", - "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-5", + "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-6", "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-7", + "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-9", ], "capabilityDelegation": [], "capabilityInvocation": [ - "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-3", - "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-5", - "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-6", + "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-4", "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-7", + "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-8", + "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-9", ], "controller": [ "did:key:z6MktvqCyLxTsXUH1tUZncNdVeEZ7hNh7npPRbUU27GTrYb8", @@ -88,7 +232,7 @@ exports[`\`DIDDocument\` \`DIDDocument.create\` works 3`] = ` "https://rdf.dock.io/alpha/2021#attestsDocumentContents": null, "id": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk", "keyAgreement": [ - "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-8", + "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-10", ], "service": [], "verificationMethod": [ @@ -104,6 +248,15 @@ exports[`\`DIDDocument\` \`DIDDocument.create\` works 3`] = ` { "controller": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk", "id": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-2", + "publicKeyBase58": "CeEf4Q1kvLo66eSbTSujuasf2mv1rTQEpK8rnuyqMxpP", + "publicKeyBase64": null, + "publicKeyHex": null, + "publicKeyJwk": null, + "type": "Bls12381BBSVerificationKeyDock2023", + }, + { + "controller": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk", + "id": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-3", "publicKeyBase58": "GxmaKA52SZGQtZS3Usa6Az48gky2AZRKzRKxsXM6ystc", "publicKeyBase64": null, "publicKeyHex": null, @@ -112,7 +265,7 @@ exports[`\`DIDDocument\` \`DIDDocument.create\` works 3`] = ` }, { "controller": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk", - "id": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-3", + "id": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-4", "publicKeyBase58": "5FBSa4xAs54osiMs75JcepL695v1XhccQmQePBZQaad9", "publicKeyBase64": null, "publicKeyHex": null, @@ -121,7 +274,16 @@ exports[`\`DIDDocument\` \`DIDDocument.create\` works 3`] = ` }, { "controller": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk", - "id": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-4", + "id": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-5", + "publicKeyBase58": "9y4gScRXDQJahd1gKbf1pYf9mwcRKnUqzstR3Bn7ydYz", + "publicKeyBase64": null, + "publicKeyHex": null, + "publicKeyJwk": null, + "type": "Bls12381BBSVerificationKeyDock2023", + }, + { + "controller": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk", + "id": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-6", "publicKeyBase58": "EaNp37NGpe8KViTKxAdknyvUP44doH1fHnFpYqEcfUjE", "publicKeyBase64": null, "publicKeyHex": null, @@ -130,7 +292,7 @@ exports[`\`DIDDocument\` \`DIDDocument.create\` works 3`] = ` }, { "controller": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk", - "id": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-5", + "id": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-7", "publicKeyBase58": "A462rFkYENhY6kf9zLVPg6qvtQhXJ6RuL8CNdHTWzNqa", "publicKeyBase64": null, "publicKeyHex": null, @@ -139,7 +301,7 @@ exports[`\`DIDDocument\` \`DIDDocument.create\` works 3`] = ` }, { "controller": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk", - "id": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-6", + "id": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-8", "publicKeyBase58": "Amb3kf4if5Av1sz6UdYtEw2iy6DzufRAtch6hiXEWHcw", "publicKeyBase64": null, "publicKeyHex": null, @@ -148,7 +310,7 @@ exports[`\`DIDDocument\` \`DIDDocument.create\` works 3`] = ` }, { "controller": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk", - "id": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-7", + "id": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-9", "publicKeyBase58": "FwUvnTThdnNPv23Rbq2SXtxxYAT21Atvdd1cZBHPYue4", "publicKeyBase64": null, "publicKeyHex": null, @@ -157,18 +319,36 @@ exports[`\`DIDDocument\` \`DIDDocument.create\` works 3`] = ` }, { "controller": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk", - "id": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-8", + "id": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-10", "publicKeyBase58": "BaGbEav6KzvWhgBWPyZK2vWX5EDDFc4a8rfUwAZ3x8Jn", "publicKeyBase64": null, "publicKeyHex": null, "publicKeyJwk": null, "type": "Ed25519VerificationKey2018", }, + { + "controller": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk", + "id": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-11", + "publicKeyBase58": "BBF5rtFSaWt4s4PxMEswkothcPJNLhdsQpggZyUozSdZ", + "publicKeyBase64": null, + "publicKeyHex": null, + "publicKeyJwk": null, + "type": "Bls12381BBSVerificationKeyDock2023", + }, + { + "controller": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk", + "id": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-12", + "publicKeyBase58": "EaNp37NGpe8KViTKxAdknyvUP44doH1fHnFpYqEcfUjE", + "publicKeyBase64": null, + "publicKeyHex": null, + "publicKeyJwk": null, + "type": "Bls12381BBSVerificationKeyDock2023", + }, ], } `; -exports[`\`DIDDocument\` \`DIDDocument.create\` works 4`] = ` +exports[`DID document workflow \`DIDDocument\` 3`] = ` { "@context": [ "overriden", @@ -186,34 +366,3 @@ exports[`\`DIDDocument\` \`DIDDocument.create\` works 4`] = ` "verificationMethod": [], } `; - -exports[`\`DIDDocument\` \`DIDDocument.from\` works 1`] = ` -{ - "@context": [ - "test", - ], - "alsoKnownAs": null, - "assertionMethod": null, - "authentication": null, - "capabilityDelegation": null, - "capabilityInvocation": null, - "controller": [ - "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk", - ], - "https://rdf.dock.io/alpha/2021#attestsDocumentContents": null, - "id": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk", - "keyAgreement": null, - "service": null, - "verificationMethod": [ - { - "controller": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk", - "id": "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk#keys-3", - "publicKeyBase58": "EaNp37NGpe8KViTKxAdknyvUP44doH1fHnFpYqEcfUjE", - "publicKeyBase64": null, - "publicKeyHex": null, - "publicKeyJwk": null, - "type": "Ed25519VerificationKey2018", - }, - ], -} -`; diff --git a/packages/credential-sdk/tests/document.test.js b/packages/credential-sdk/tests/document.test.js index 0b25b05af..2fe542221 100644 --- a/packages/credential-sdk/tests/document.test.js +++ b/packages/credential-sdk/tests/document.test.js @@ -4,7 +4,7 @@ import { CheqdTestnetDid, } from "../src/types/did"; import { DIDDocument } from "../src/types/did/document"; -import { PublicKeyEd25519 } from "../src/types"; +import { PublicKeyEd25519, BBSPublicKey, BBSPublicKeyValue } from "../src/types"; const RANDOM_PKS = [ "0xa1aa6a2058dd190e284a64e72adaf4e16a9ae9fbf0673d7575924e6aca3b21dc", @@ -14,13 +14,44 @@ const RANDOM_PKS = [ "0x86839d44e6f15cd21ede6e4db64c60b57cb4c5f6030212f48468090c1ed823ed", "0x91253c4b3401eade456953934325153c908444b8ea2705f8ee71e600bee6b0bc", "0xddf88ee3d89f5890ab0b14d37b9189e62cf88baf375557f917994edaec8b296d", - "0x9d1aa9f5f7990737f670accdbdb8808ab4cbf256e6aaac73cba8bd89aa04befb", + "0x9d1aa9f5f7990737f670accdbdb8808ab4cbf256e6aaac73cba8bd89aa04befb", +].map((bytes) => new PublicKeyEd25519(bytes)); + +const RANDOM_OFFCHAIN_PKS = [ "0xacfa7cba73ee6d09d280c157b5e25c4354da462103568f3c2036f714de1a8b18", "0x853a2e866edb66d965326c019f039bc9c3b83d02ee5aa316fbe41edf55c45e0f", "0x97349a1977e401a9472587c2f81473fb20967c0f24b6dd1d1c8fb2a3833f6374", -].map((bytes) => new PublicKeyEd25519(bytes)); + "0xc9b4c22c2f5738b0adaf605a8233cdc2451c5ece045c25a3bc2b4c840fe9b11d", +].map(bytes => new BBSPublicKey(new BBSPublicKeyValue(bytes))); + +const catchErrorWith = (fn, message) => { + try { + return fn(); + } catch(err) { + err.message = `${message}:\n${err.message}`; + + throw err; + } +} + +const checkDoc = doc => { + catchErrorWith(() => expect(doc).toMatchSnapshot(), 'Failed snapshot check'); + const jsonDoc = catchErrorWith(() => doc.toJSON(), 'Failed `toJSON` conversion'); + const newDoc = catchErrorWith(() => doc.constructor.from(jsonDoc), 'Failed `fromJSON` conversion'); + catchErrorWith(() => expect(newDoc.toJSON()).toEqual(jsonDoc), 'Failed equality check'); +} -describe("`DIDDocument`", () => { +const checkDocs = (...docs) => { + let idx = 0; + for (const doc of docs) { + catchErrorWith(() => { + checkDoc(doc); + idx++; + }, `Error for docs[${idx}]`) + } +} + +describe("DID document workflow", () => { const AUTH = new VerificationRelationship().setAuthentication(); const ASSERT = new VerificationRelationship().setAssertion(); const CAP_INV = new VerificationRelationship().setCapabilityInvocation(); @@ -45,53 +76,85 @@ describe("`DIDDocument`", () => { expect(DIDDocument.from(doc)).toMatchSnapshot(); }); - test("`DIDDocument.create` works", () => { - expect( - DIDDocument.create( + test("`DIDDocument`", () => { + const doc1 = DIDDocument.create( + "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk", + [], + [], + [] + ); + + const doc2 = DIDDocument.create( + "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk", + [ + new DidKey(RANDOM_PKS[0], AUTH), + new DidKey(RANDOM_OFFCHAIN_PKS[0]), + new DidKey(RANDOM_PKS[1], ASSERT), + new DidKey(RANDOM_PKS[2], CAP_INV), + new DidKey(RANDOM_OFFCHAIN_PKS[1]), + new DidKey(RANDOM_PKS[3], AUTH | ASSERT), + new DidKey(RANDOM_PKS[4], AUTH | CAP_INV), + new DidKey(RANDOM_PKS[5], ASSERT | CAP_INV), + new DidKey(RANDOM_PKS[6], AUTH | ASSERT | CAP_INV), + new DidKey(RANDOM_PKS[7], KEY_AGR), + new DidKey(RANDOM_OFFCHAIN_PKS[2]), + new DidKey(RANDOM_OFFCHAIN_PKS[3]), + ], + [ + "did:key:z6MktvqCyLxTsXUH1tUZncNdVeEZ7hNh7npPRbUU27GTrYb8", "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk", - [], - [], - [] - ) - ).toMatchSnapshot(); + ], + [] + ); + const doc3 = DIDDocument.create( + "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk", + [], + [], + [], + { context: ["overriden"] } + ); + + checkDocs(doc1, doc2, doc3); + }); + + test("`CheqdDIDDocument`", () => { const cheqdDid = CheqdTestnetDid.from( "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54" ); - expect( - DIDDocument.create(cheqdDid, [new DidKey(RANDOM_PKS[0])], [cheqdDid], []) - ).toMatchSnapshot(); + const doc1 = DIDDocument.create( + "did:cheqd:testnet:6ec66297-f55e-4744-b8cd-bd043bc45767", + [], + [], + [] + ).toCheqd('0557d7da-8dea-45cb-8f30-7370b59eab71'); - expect( - DIDDocument.create( - "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk", - [ - new DidKey(RANDOM_PKS[0], AUTH), - new DidKey(RANDOM_PKS[1], ASSERT), - new DidKey(RANDOM_PKS[2], CAP_INV), - new DidKey(RANDOM_PKS[3], AUTH | ASSERT), - new DidKey(RANDOM_PKS[4], AUTH | CAP_INV), - new DidKey(RANDOM_PKS[5], ASSERT | CAP_INV), - new DidKey(RANDOM_PKS[6], AUTH | ASSERT | CAP_INV), - new DidKey(RANDOM_PKS[7], KEY_AGR), - ], - [ - "did:key:z6MktvqCyLxTsXUH1tUZncNdVeEZ7hNh7npPRbUU27GTrYb8", - "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk", - ], - [] - ) - ).toMatchSnapshot(); - - expect( - DIDDocument.create( - "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk", - [], - [], - [], - { context: ["overriden"] } - ) - ).toMatchSnapshot(); - }); + const doc2 = DIDDocument.create(cheqdDid, [new DidKey(RANDOM_PKS[0]), new DidKey(RANDOM_OFFCHAIN_PKS[0])], [cheqdDid], []).toCheqd('28edc043-872b-4ab7-9cb8-b01d1bd677c5'); + + const doc3 = DIDDocument.create( + "did:cheqd:testnet:f1749383-d9dd-479f-82aa-e52fe8f59c54", + [ + new DidKey(RANDOM_PKS[0], AUTH), + new DidKey(RANDOM_OFFCHAIN_PKS[0]), + new DidKey(RANDOM_PKS[1], ASSERT), + new DidKey(RANDOM_PKS[2], CAP_INV), + new DidKey(RANDOM_OFFCHAIN_PKS[1]), + new DidKey(RANDOM_PKS[3], AUTH | ASSERT), + new DidKey(RANDOM_PKS[4], AUTH | CAP_INV), + new DidKey(RANDOM_PKS[5], ASSERT | CAP_INV), + new DidKey(RANDOM_PKS[6], AUTH | ASSERT | CAP_INV), + new DidKey(RANDOM_PKS[7], KEY_AGR), + new DidKey(RANDOM_OFFCHAIN_PKS[2]), + new DidKey(RANDOM_OFFCHAIN_PKS[3]), + ], + [ + "did:cheqd:mainnet:f1749383-d9dd-479f-82aa-e52fe8f59c54", + "did:cheqd:testnet:df3ba823-c1e2-46e0-bb54-056f9c506e90", + ], + [] + ).toCheqd('47b4d97b-1ebe-4d81-a3ed-12eb63baaeb9'); + + checkDocs(doc1, doc2, doc3) + }) }); diff --git a/packages/credential-sdk/tests/issuing.test.js b/packages/credential-sdk/tests/issuing.test.js index 149d42d03..ad3f79e4d 100644 --- a/packages/credential-sdk/tests/issuing.test.js +++ b/packages/credential-sdk/tests/issuing.test.js @@ -79,6 +79,7 @@ testingKeys.forEach((testKey) => { expect(credential.proof.verificationMethod).toBe(keyUrl); const result = await verifyCredential(credential); + console.log(result.errors); expect(result.verified).toBe(true); expect(result.results[0].proof).toBeDefined(); expect(result.results[0].proof.proofPurpose).toBe("assertionMethod"); diff --git a/packages/dock-blockchain-modules/src/status-list-credential/internal.js b/packages/dock-blockchain-modules/src/status-list-credential/internal.js index 909d5ec05..89c24cd90 100644 --- a/packages/dock-blockchain-modules/src/status-list-credential/internal.js +++ b/packages/dock-blockchain-modules/src/status-list-credential/internal.js @@ -28,13 +28,13 @@ const accountMethods = { const didMethodsWithPolicy = { update(id, statusListCredential, _, __, nonce) { return new UpdateStatusListCredential( - new DockStatusList2021CredentialWithId(id, statusListCredential), + new DockStatusList2021CredentialWithId(DockStatusListCredentialId.from(id), statusListCredential), nonce, ); }, - remove(statusListCredentialId, _, __, nonce) { + remove(id, _, __, nonce) { return new RemoveStatusListCredential( - new DockStatusListCredentialWrappedId(statusListCredentialId), + new DockStatusListCredentialWrappedId(DockStatusListCredentialId.from(id)), nonce, ); }, diff --git a/packages/dock-blockchain-modules/src/status-list-credential/module.js b/packages/dock-blockchain-modules/src/status-list-credential/module.js index 597375863..862a466ee 100644 --- a/packages/dock-blockchain-modules/src/status-list-credential/module.js +++ b/packages/dock-blockchain-modules/src/status-list-credential/module.js @@ -16,10 +16,10 @@ export default class DockStatusListCredentialModule extends injectDock( * @param {*} statusListCredentialId * @returns {Promise} */ - async getStatusListCredential(statusListCredentialId) { + async getStatusListCredential(id) { return ( option(DockStatusList2021CredentialWithPolicy).from( - await this.dockOnly.query.statusListCredentials(DockStatusListCredentialId.from(statusListCredentialId).value), + await this.dockOnly.query.statusListCredentials(DockStatusListCredentialId.from(id).value), )?.statusListCredential?.value?.list ?? null ); } diff --git a/packages/dock-blockchain-modules/tests/integration/status-list-credential-module.test.js b/packages/dock-blockchain-modules/tests/integration/status-list-credential-module.test.js index 2c1f875ba..75d24ae1b 100644 --- a/packages/dock-blockchain-modules/tests/integration/status-list-credential-module.test.js +++ b/packages/dock-blockchain-modules/tests/integration/status-list-credential-module.test.js @@ -13,17 +13,16 @@ import { Ed25519Keypair, DidKeypair, } from "@docknetwork/credential-sdk/keypairs"; -import { DockDid } from "@docknetwork/credential-sdk/types"; +import { DockDid, DockStatusListCredentialId } from "@docknetwork/credential-sdk/types"; import { registerNewDIDUsingPair } from "./helpers"; import { getKeyDoc } from "@docknetwork/credential-sdk/vc/helpers"; import { DockStatusList2021Credential } from "@docknetwork/credential-sdk/types/status-list-credential"; -const expectEqualCreds = (cred1, cred2) => { - expect(cred1.eq(cred2)).toBe(true); - expect(cred1.toJSON()).toEqual(cred2.toJSON()); - expect(DockStatusList2021Credential.fromJSON(cred1.toJSON())).toEqual( - DockStatusList2021Credential.fromJSON(cred2.toJSON()) - ); +const expectEqualCreds = (c1, c2) => { + const cred1 = DockStatusList2021Credential.from(c1); + const cred2 = DockStatusList2021Credential.from(c2); + + expect(cred1.value.list.toJSON()).toEqual(cred2.value.list.toJSON()); }; describe("StatusListCredential Module", () => { @@ -32,9 +31,9 @@ describe("StatusListCredential Module", () => { let pair; // Create a random status list id - const statusListCredId = randomAsHex(32); + const statusListCredId = String(DockStatusListCredentialId.random()); // Create a random status list id - const multipleControllerstatusListCredID = randomAsHex(32); + const multipleControllerstatusListCredID = String(DockStatusListCredentialId.random()); // Create a new owner DID, the DID will be registered on the network and own the status list const ownerDID = DockDid.random(); @@ -176,40 +175,4 @@ describe("StatusListCredential Module", () => { ) ).toBe(null); }, 40000); - - test("Can create a status list with multiple owners", async () => { - const cred = await DockStatusList2021Credential.create( - ownerKey, - multipleControllerstatusListCredID, - { statusPurpose: "suspension" } - ); - - await expect( - modules.statusListCredential.createStatusListCredential( - multipleControllerstatusListCredID, - cred, - pair - ) - ).resolves.toBeDefined(); - const fetchedCred = ( - await dock.api.query.statusListCredential.statusListCredentials( - multipleControllerstatusListCredID - ) - ).unwrap(); - expect(fetchedCred.policy.isOneOf).toBe(true); - - const controllerSet = fetchedCred.policy.asOneOf; - expect(controllerSet.toJSON().length).toBe(1); - - let hasFirstDID = false; - [...controllerSet.entries()] - .flatMap((v) => v) - .map((cnt) => DockDid.from(cnt)) - .forEach((controller) => { - if (controller.toString() === DockDid.from(ownerDID).toString()) { - hasFirstDID = true; - } - }); - expect(hasFirstDID).toBe(true); - }, 40000); }); diff --git a/packages/dock-blockchain-modules/tests/integration/status-list-credential.test.js b/packages/dock-blockchain-modules/tests/integration/status-list-credential.test.js index 44fbd41bb..b5d633f98 100644 --- a/packages/dock-blockchain-modules/tests/integration/status-list-credential.test.js +++ b/packages/dock-blockchain-modules/tests/integration/status-list-credential.test.js @@ -21,7 +21,7 @@ import { DockCoreModules } from "../../src"; import { getUnsignedCred, registerNewDIDUsingPair } from "./helpers"; import { getKeyDoc } from "@docknetwork/credential-sdk/vc/helpers"; import { DockDid } from "@docknetwork/credential-sdk/types"; -import { DockStatusList2021Credential } from "@docknetwork/credential-sdk/types"; +import { DockStatusList2021Credential, DockStatusListCredentialId } from "@docknetwork/credential-sdk/types"; import { addStatusList21EntryToCredential } from "@docknetwork/credential-sdk/vc/credentials"; import { Ed25519Keypair, @@ -36,7 +36,7 @@ describe("DockStatusList2021Credential", () => { const resolver = new CoreResolver(modules); // Create a random status list id - const statusListCredentialId = randomAsHex(32); + const statusListCredentialId = String(DockStatusListCredentialId.random()); const statusListCredentialIndex = (Math.random() * 10e3) | 0; // Register a new DID for issuer @@ -135,6 +135,7 @@ describe("DockStatusList2021Credential", () => { compactProof: true, }); + console.log(result.error); expect(result.verified).toBe(true); // Revoke the credential