Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
olegnn committed Oct 17, 2024
1 parent e9a131f commit c32280a
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function generateAttestModuleTests(
) {
const test = itIf(filter);

test('Generates a `DIDDocument` and appends an attestation to it', async () => {
test('Generates a `DIDDocument` and appends an `Attest` to it', async () => {
const did = DID.random();

const keyPair = Ed25519Keypair.random();
Expand Down
2 changes: 1 addition & 1 deletion packages/credential-sdk/src/generate-tests/blob-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function generateBlobModuleTests(
{ did: didModule, blob: blobModule },
{ DID, BlobId },
) {
it('Generates a `DIDDocument` and creates a blob owned by this DID', async () => {
it('Generates a `DIDDocument` and creates a `Blob` owned by this DID', async () => {
const did = DID.random();

const keyPair = Ed25519Keypair.random();
Expand Down
3 changes: 1 addition & 2 deletions packages/credential-sdk/src/generate-tests/did-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function generateDIDModuleTests(
expect((await module.getDocument(did)).toJSON()).toEqual(document.toJSON());
});

test('Updates with `DIDDocument` containing BBS/BBSPlus/PS keys', async () => {
test('Updates `DIDDocument` containing BBS/BBSPlus/PS keys', async () => {
const did = DID.random();

const keyPair = Ed25519Keypair.random();
Expand Down Expand Up @@ -105,7 +105,6 @@ export default function generateDIDModuleTests(
service1,
service2,
});
console.log(document.toJSON());

await module.createDocument(document, didKeypair);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,22 @@ export const NamespaceDid = withQualifier(
);

class DockNamespaceDid extends NamespaceDid {
static Qualifier = 'did:dock:';

static Type = 'dock';

static Class = DockDidValueToString;
}
class DidNamespaceKey extends NamespaceDid {
static Qualifier = 'did:key:';

static Type = 'didMethodKey';

static Class = DidMethodKeyPublicKeyToString;
}
class CheqdNamespaceDid extends NamespaceDid {
static Qualifier = 'did:cheqd:';

static Type = 'cheqd';

static Class = CheqdDid;
Expand Down
4 changes: 3 additions & 1 deletion packages/credential-sdk/src/types/generic/with-eq.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export default function withEq(klass) {
return false;
} else if (Object.is(this, other)) {
return true;
} else if (!isEqualToOrPrototypeOf(klass, other.constructor)) {
} else if (
!isEqualToOrPrototypeOf(this.constructor, other.constructor)
) {
let compareWith;
try {
compareWith = this.constructor.from(other);
Expand Down
28 changes: 20 additions & 8 deletions packages/credential-sdk/src/types/generic/with-qualifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ export default function withQualifier(klass, wrapper = false) {
toString() {
return this.value.toString();
}

eq(other) {
return String(this) === String(other);
}
},
};

Expand All @@ -109,6 +105,19 @@ export default function withQualifier(klass, wrapper = false) {
} else {
return this.fromQualifiedString(String(value));
}
} else if (
value?.constructor?.Qualifier != null &&
!this.Qualifiers.find((qualifier) =>
value.constructor.Qualifier.startsWith(qualifier)
)
) {
throw new Error(
`Value has a different qualifier: \`${
value.constructor.Qualifier
}\` while expected one of \`${fmtIter(this.Qualifiers)}\` by \`${
this.name
}\``
);
} else {
return from(value);
}
Expand Down Expand Up @@ -169,10 +178,6 @@ export default function withQualifier(klass, wrapper = false) {
toString() {
return this.toQualifiedEncodedString();
}

eq(other) {
return String(this) === String(other);
}
},
};

Expand All @@ -191,6 +196,13 @@ export default function withQualifier(klass, wrapper = false) {
} else {
return this.fromUnqualifiedString(String(value));
}
} else if (
value?.constructor?.Qualifier != null &&
!value.constructor.Qualifier.startsWith(this.Qualifier)
) {
throw new Error(
`Value has a different qualifier: \`${value.constructor.Qualifier}\` while expected \`${this.Qualifier}\` by \`${this.name}\``
);
} else {
return from(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ exports[`\`DIDDocument\` \`DIDDocument.create\` works 4`] = `
}
`;

exports[`\`DIDDocument\` DIDDocument.from works 1`] = `
exports[`\`DIDDocument\` \`DIDDocument.from\` works 1`] = `
{
"@context": [
"test",
Expand Down
2 changes: 1 addition & 1 deletion packages/credential-sdk/tests/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("`DIDDocument`", () => {
const CAP_INV = new VerificationRelationship().setCapabilityInvocation();
const KEY_AGR = new VerificationRelationship().setKeyAgreement();

test(`DIDDocument.from works`, () => {
test(`\`DIDDocument.from\` works`, () => {
const doc = {
"@context": ["test"],
id: "did:dock:5DEHasvC9G3eVF3qCsN2VQvEbHYdQtsv74ozZ1ngQQj39Luk",
Expand Down

0 comments on commit c32280a

Please sign in to comment.