Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix several minor issues in @web5/dids #414

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
frankhinek marked this conversation as resolved.
Show resolved Hide resolved
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', () => {
});
});
});
});
});
Loading