Skip to content

Commit

Permalink
Fix several minor issues in @web5/dids (#414)
Browse files Browse the repository at this point in the history
* Fix several minor issues
* Bump @web5/dids to 0.4.1

---------

Signed-off-by: Frank Hinek <[email protected]>
  • Loading branch information
frankhinek authored Feb 16, 2024
1 parent b2cbe7b commit 1d595e1
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 16 deletions.
21 changes: 19 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/dids/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@web5/dids",
"version": "0.4.0",
"version": "0.4.1",
"description": "TBD DIDs library",
"type": "module",
"main": "./dist/cjs/index.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/dids/src/bearer-did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export class BearerDid {
}

/**
* Instantiates a {@link BearerDid} object for the DID DHT method from a given {@link PortableDid}.
* Instantiates a {@link BearerDid} object from a given {@link PortableDid}.
*
* This method allows for the creation of a `BearerDid` object using a previously created DID's
* key material, DID document, and metadata.
Expand All @@ -208,7 +208,7 @@ export class BearerDid {
* // Export an existing BearerDid to PortableDid format.
* const portableDid = await did.export();
* // Reconstruct a BearerDid object from the PortableDid.
* const did = await DidDht.import({ portableDid });
* const did = await BearerDid.import({ portableDid });
* ```
*
* @param params - The parameters for the import operation.
Expand Down
2 changes: 1 addition & 1 deletion packages/dids/src/methods/did-jwk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export interface DidJwkCreateOptions<TKms> extends DidCreateOptions<TKms> {
* Alternatively, specify the algorithm to be used for key generation of the single verification
* method in the DID Document.
*/
verificationMethods?: [DidCreateVerificationMethod<TKms>];
verificationMethods?: DidCreateVerificationMethod<TKms>[];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/dids/src/methods/did-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export interface DidKeyCreateOptions<TKms> extends DidCreateOptions<TKms> {
* Alternatively, specify the algorithm to be used for key generation of the single verification
* method in the DID Document.
*/
verificationMethods?: [DidCreateVerificationMethod<TKms>];
verificationMethods?: DidCreateVerificationMethod<TKms>[];
}

/**
Expand Down
28 changes: 24 additions & 4 deletions packages/dids/src/methods/did-method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ export interface DidCreateVerificationMethod<TKms> extends Pick<Partial<DidVerif
* @typeparam O - The type of the options used for creating the DID.
*/
export interface DidMethodApi<
TDid extends BearerDid,
TOptions extends DidCreateOptions<TKms>,
TKms extends CryptoApi | undefined = undefined
TKms extends CryptoApi | undefined = CryptoApi,
TDid extends BearerDid = BearerDid,
TOptions extends DidCreateOptions<TKms> = DidCreateOptions<TKms>
> extends DidMethodResolver {
/**
* The name of the DID method.
Expand All @@ -106,7 +106,27 @@ export interface DidMethodApi<
* @param params.options - Optional. The options used for creating the DID.
* @returns A promise that resolves to the newly created DID instance.
*/
create(params: { keyManager?: TKms, options?: TOptions }): Promise<TDid>;
create(params: {
keyManager?: TKms;
options?: TOptions;
}): Promise<TDid>;

/**
* Given a DID Document, return the verification method that will be used for signing messages and
* credentials.
*
* If given, the `methodId` parameter is used to select the verification method. If not given, a
* DID method specific approach is taken to selecting the verification method to return.
*
* @param params - The parameters for the `getSigningMethod` operation.
* @param params.didDocument - DID Document to get the verification method from.
* @param params.methodId - ID of the verification method to use for signing.
* @returns A promise that resolves to the erification method to use for signing.
*/
getSigningMethod(params: {
didDocument: DidDocument;
methodId?: string;
}): Promise<DidVerificationMethod>;
}

/**
Expand Down
2 changes: 0 additions & 2 deletions packages/dids/tests/methods/did-jwk.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ describe('DidJwk', () => {

it('throws an error if zero verificationMethods are given', async () => {
try {
// @ts-expect-error - Test case where verificationMethods is undefined.
await DidJwk.create({ keyManager, options: { verificationMethods: [] } });
expect.fail('Expected an error to be thrown.');
} catch (error: any) {
Expand All @@ -117,7 +116,6 @@ describe('DidJwk', () => {
try {
await DidJwk.create({
keyManager,
// @ts-expect-error - Test case where verificationMethods has too many entries.
options: { verificationMethods: [{ algorithm: 'secp256k1' }, { algorithm: 'Ed25519' }] }
});
expect.fail('Expected an error to be thrown.');
Expand Down
4 changes: 1 addition & 3 deletions packages/dids/tests/methods/did-key.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ describe('DidKey', () => {

it('throws an error if zero verificationMethods are given', async () => {
try {
// @ts-expect-error - Test case where verificationMethods is undefined.
await DidKey.create({ keyManager, options: { verificationMethods: [] } });
expect.fail('Expected an error to be thrown.');
} catch (error: any) {
Expand All @@ -137,7 +136,6 @@ describe('DidKey', () => {
try {
await DidKey.create({
keyManager,
// @ts-expect-error - Test case where verificationMethods has too many entries.
options: { verificationMethods: [{ algorithm: 'secp256k1' }, { algorithm: 'Ed25519' }] }
});
expect.fail('Expected an error to be thrown.');
Expand Down Expand Up @@ -685,4 +683,4 @@ describe('DidKey', () => {
});
});
});
});
});

0 comments on commit 1d595e1

Please sign in to comment.