Skip to content

Commit

Permalink
Rename Did to BearerDid (#396)
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Hinek <[email protected]>
  • Loading branch information
frankhinek authored Feb 3, 2024
1 parent 54e7d0d commit ab117f1
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 71 deletions.
34 changes: 17 additions & 17 deletions packages/dids/src/methods/did-dht.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Convert } from '@web5/common';
import { CryptoApi, computeJwkThumbprint, Ed25519, LocalKeyManager, Secp256k1, Secp256r1 } from '@web5/crypto';
import { AUTHORITATIVE_ANSWER, decode as dnsPacketDecode, encode as dnsPacketEncode } from '@dnsquery/dns-packet';

import type { Did, DidCreateOptions, DidCreateVerificationMethod, DidMetadata, PortableDid } from './did-method.js';
import type { BearerDid, DidCreateOptions, DidCreateVerificationMethod, DidMetadata, PortableDid } from './did-method.js';
import type {
DidService,
DidDocument,
Expand Down Expand Up @@ -496,15 +496,15 @@ export class DidDht extends DidMethod {
* @param params.keyManager - Optionally specify a Key Management System (KMS) used to generate
* keys and sign data.
* @param params.options - Optional parameters that can be specified when creating a new DID.
* @returns A Promise resolving to a {@link Did} object representing the new DID.
* @returns A Promise resolving to a {@link BearerDid} object representing the new DID.
*/
public static async create<TKms extends CryptoApi | undefined = undefined>({
keyManager = new LocalKeyManager(),
options = {}
}: {
keyManager?: TKms;
options?: DidDhtCreateOptions<TKms>;
} = {}): Promise<Did> {
} = {}): Promise<BearerDid> {
// Before processing the create operation, validate DID-method-specific requirements to prevent
// keys from being generated unnecessarily.

Expand Down Expand Up @@ -538,12 +538,12 @@ export class DidDht extends DidMethod {
}

/**
* Instantiates a `Did` object for the DID DHT method from a given {@link PortableDid}.
* Instantiates a {@link BearerDid} object for the DID DHT method from a given {@link PortableDid}.
*
* This method allows for the creation of a `Did` object using pre-existing key material,
* This method allows for the creation of a `BearerDid` object using pre-existing key material,
* encapsulated within the `verificationMethods` array of the `PortableDid`. This is particularly
* useful when the key material is already available and you want to construct a `Did` object
* based on these keys, instead of generating new keys.
* useful when the key material is already available and you want to construct a `BearerDid`
* object based on these keys, instead of generating new keys.
*
* @remarks
* The key material (both public and private keys) should be provided in JWK format. The method
Expand All @@ -565,7 +565,7 @@ export class DidDht extends DidMethod {
* @param params.keyManager - Optionally specify an external Key Management System (KMS) used to
* generate keys and sign data. If not given, a new
* {@link @web5/crypto#LocalKeyManager} instance will be created and used.
* @returns A Promise resolving to a `Did` object representing the DID formed from the provided keys.
* @returns A Promise resolving to a `BearerDid` object representing the DID formed from the provided keys.
* @throws An error if the `verificationMethods` array does not contain any keys, lacks an
* Identity Key, or any verification method is missing a public or private key.
*/
Expand All @@ -577,7 +577,7 @@ export class DidDht extends DidMethod {
}: {
keyManager?: CryptoApi & KeyImporterExporter<KmsImportKeyParams, KeyIdentifier, KmsExportKeyParams>;
options?: DidDhtCreateOptions<TKms>;
} & PortableDid): Promise<Did> {
} & PortableDid): Promise<BearerDid> {
if (!(verificationMethods && Array.isArray(verificationMethods) && verificationMethods.length > 0)) {
throw new Error(`At least one verification method is required but 0 were given`);
}
Expand Down Expand Up @@ -652,7 +652,7 @@ export class DidDht extends DidMethod {
* - The method relies on the specified Pkarr relay server to interface with the DHT network.
*
* @param params - The parameters for the `publish` operation.
* @param params.did - The `Did` object representing the DID to be published.
* @param params.did - The `BearerDid` object representing the DID to be published.
* @param params.gatewayUri - Optional. The URI of a server involved in executing DID
* method operations. In the context of publishing, the
* endpoint is expected to be a Pkarr relay. If not specified,
Expand All @@ -669,7 +669,7 @@ export class DidDht extends DidMethod {
* ```
*/
public static async publish({ did, gatewayUri = DEFAULT_PKARR_RELAY }: {
did: Did;
did: BearerDid;
gatewayUri?: string;
}): Promise<boolean> {
const isPublished = await DidDhtDocument.put({ did, relay: gatewayUri });
Expand Down Expand Up @@ -733,22 +733,22 @@ export class DidDht extends DidMethod {
}

/**
* Instantiates a `Did` object for the DID DHT method using an array of public keys.
* Instantiates a `BearerDid` object for the DID DHT method using an array of public keys.
*
* This method is used to create a `Did` object from a set of public keys, typically after
* This method is used to create a `BearerDid` object from a set of public keys, typically after
* these keys have been generated or provided. It constructs the DID document, metadata, and
* other necessary components for the DID based on the provided public keys and any additional
* options specified.
*
* @param params - The parameters for the DID object creation.
* @param params.keyManager - The Key Management System to manage keys.
* @param params.options - Additional options for DID creation.
* @returns A Promise resolving to a `Did` object.
* @returns A Promise resolving to a `BearerDid` object.
*/
private static async fromPublicKeys({ keyManager, verificationMethods, options }: {
keyManager: CryptoApi;
options: DidDhtCreateOptions<CryptoApi | undefined>;
} & PortableDid): Promise<Did> {
} & PortableDid): Promise<BearerDid> {
// Validate that the given verification methods contain an Identity Key.
const identityKey = verificationMethods?.find(vm => vm.id?.split('#').pop() === '0')?.publicKeyJwk;
if (!identityKey) {
Expand Down Expand Up @@ -818,7 +818,7 @@ export class DidDht extends DidMethod {
}

/**
* Generates a set of keys for use in creating a `Did` object for the `did:dht` method.
* Generates a set of keys for use in creating a `BearerDid` object for the `did:dht` method.
*
* This method is responsible for generating the cryptographic keys necessary for the DID. It
* supports generating keys for the specified verification methods.
Expand Down Expand Up @@ -914,7 +914,7 @@ class DidDhtDocument {
* If publishing fails, `false` is returned.
*/
public static async put({ did, relay }: {
did: Did;
did: BearerDid;
relay: string;
}): Promise<boolean> {
// Convert the DID document and DID metadata (such as DID types) to a DNS packet.
Expand Down
20 changes: 10 additions & 10 deletions packages/dids/src/methods/did-ion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {
DidVerificationMethod,
} from '../types/did-core.js';
import type {
Did,
BearerDid,
DidMetadata,
PortableDid,
DidCreateOptions,
Expand Down Expand Up @@ -282,15 +282,15 @@ export class DidIon extends DidMethod {
* @param params.keyManager - Optionally specify a Key Management System (KMS) used to generate
* keys and sign data.
* @param params.options - Optional parameters that can be specified when creating a new DID.
* @returns A Promise resolving to a {@link Did} object representing the new DID.
* @returns A Promise resolving to a {@link BearerDid} object representing the new DID.
*/
public static async create<TKms extends CryptoApi | undefined = undefined>({
keyManager = new LocalKeyManager(),
options = {}
}: {
keyManager?: TKms;
options?: DidIonCreateOptions<TKms>;
} = {}): Promise<Did> {
} = {}): Promise<BearerDid> {
// Before processing the create operation, validate DID-method-specific requirements to prevent
// keys from being generated unnecessarily.

Expand Down Expand Up @@ -369,7 +369,7 @@ export class DidIon extends DidMethod {
* - The method relies on the specified Sidetree node to interface with the network.
*
* @param params - The parameters for the `publish` operation.
* @param params.did - The `Did` object representing the DID to be published.
* @param params.did - The `BearerDid` object representing the DID to be published.
* @param params.gatewayUri - Optional. The URI of a server involved in executing DID
* method operations. In the context of publishing, the
* endpoint is expected to be a Sidetree node. If not
Expand All @@ -386,7 +386,7 @@ export class DidIon extends DidMethod {
* ```
*/
public static async publish({ did, gatewayUri = DEFAULT_GATEWAY_URI }: {
did: Did;
did: BearerDid;
gatewayUri?: string;
}): Promise<boolean> {
// Create the ION document.
Expand Down Expand Up @@ -512,22 +512,22 @@ export class DidIon extends DidMethod {
}

/**
* Instantiates a `Did` object for the DID ION method using an array of public keys.
* Instantiates a `BearerDid` object for the DID ION method using an array of public keys.
*
* This method is used to create a `Did` object from a set of public keys, typically after
* This method is used to create a `BearerDid` object from a set of public keys, typically after
* these keys have been generated or provided. It constructs the DID document, metadata, and
* other necessary components for the DID based on the provided public keys and any additional
* options specified.
*
* @param params - The parameters for the DID object creation.
* @param params.keyManager - The Key Management System to manage keys.
* @param params.options - Additional options for DID creation.
* @returns A Promise resolving to a `Did` object.
* @returns A Promise resolving to a `BearerDid` object.
*/
private static async fromPublicKeys({ keyManager, recoveryKey, updateKey, verificationMethods, options }: {
keyManager: CryptoApi;
options: DidIonCreateOptions<CryptoApi | undefined>;
} & IonPortableDid): Promise<Did> {
} & IonPortableDid): Promise<BearerDid> {
// Validate an ION Recovery Key was generated or provided.
if (!recoveryKey) {
throw new Error('Missing required input: ION Recovery Key');
Expand Down Expand Up @@ -570,7 +570,7 @@ export class DidIon extends DidMethod {
}

/**
* Generates a set of keys for use in creating a `Did` object for the DID ION method.
* Generates a set of keys for use in creating a `BearerDid` object for the DID ION method.
*
* This method is responsible for generating the cryptographic keys necessary for the DID,
* including the ION Update and Recovery keys and any verification methods specified in the
Expand Down
25 changes: 13 additions & 12 deletions packages/dids/src/methods/did-jwk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
import { Convert } from '@web5/common';
import { LocalKeyManager } from '@web5/crypto';

import type { Did, DidCreateOptions, DidCreateVerificationMethod, DidMetadata, PortableDid } from './did-method.js';
import type { BearerDid, DidCreateOptions, DidCreateVerificationMethod, DidMetadata, PortableDid } from './did-method.js';
import type { DidDocument, DidResolutionOptions, DidResolutionResult, DidVerificationMethod } from '../types/did-core.js';

import { DidUri } from '../did-uri.js';
Expand Down Expand Up @@ -167,15 +167,15 @@ export class DidJwk extends DidMethod {
* @param params.keyManager - Optionally specify a Key Management System (KMS) used to generate
* keys and sign data.
* @param params.options - Optional parameters that can be specified when creating a new DID.
* @returns A Promise resolving to a {@link Did} object representing the new DID.
* @returns A Promise resolving to a {@link BearerDid} object representing the new DID.
*/
public static async create<TKms extends CryptoApi | undefined = undefined>({
keyManager = new LocalKeyManager(),
options = {}
}: {
keyManager?: TKms;
options?: DidJwkCreateOptions<TKms>;
} = {}): Promise<Did> {
} = {}): Promise<BearerDid> {
if (options.algorithm && options.verificationMethods) {
throw new Error(`The 'algorithm' and 'verificationMethods' options are mutually exclusive`);
}
Expand All @@ -195,12 +195,13 @@ export class DidJwk extends DidMethod {
}

/**
* Instantiates a `Did` object for the `did:jwk` method from a given {@link PortableDid}.
* Instantiates a {@link BearerDid} object for the `did:jwk` method from a given
* {@link PortableDid}.
*
* This method allows for the creation of a `Did` object using pre-existing key material,
* This method allows for the creation of a `BearerDid` object using pre-existing key material,
* encapsulated within the `verificationMethods` array of the `PortableDid`. This is particularly
* useful when the key material is already available and you want to construct a `Did` object
* based on these keys, instead of generating new keys.
* useful when the key material is already available and you want to construct a `BearerDid`
* object based on these keys, instead of generating new keys.
*
* @remarks
* The `verificationMethods` array must contain exactly one key since the `did:jwk` method only
Expand All @@ -224,7 +225,7 @@ export class DidJwk extends DidMethod {
* @param params.keyManager - Optionally specify an external Key Management System (KMS) used to
* generate keys and sign data. If not given, a new
* {@link @web5/crypto#LocalKeyManager} instance will be created and used.
* @returns A Promise resolving to a `Did` object representing the DID formed from the provided keys.
* @returns A Promise resolving to a `BearerDid` object representing the DID formed from the provided keys.
* @throws An error if the `verificationMethods` array does not contain exactly one entry.
*/
public static async fromKeys({
Expand All @@ -233,7 +234,7 @@ export class DidJwk extends DidMethod {
}: {
keyManager?: CryptoApi & KeyImporterExporter<KmsImportKeyParams, KeyIdentifier, KmsExportKeyParams>;
options?: unknown;
} & PortableDid): Promise<Did> {
} & PortableDid): Promise<BearerDid> {
if (!verificationMethods || verificationMethods.length !== 1) {
throw new Error(`Only one verification method can be specified but ${verificationMethods?.length ?? 0} were given`);
}
Expand Down Expand Up @@ -368,18 +369,18 @@ export class DidJwk extends DidMethod {
}

/**
* Instantiates a `Did` object for the DID JWK method from a given public key.
* Instantiates a {@link BearerDid} object for the DID JWK method from a given public key.
*
* @param params - The parameters for the operation.
* @param params.keyManager - A Key Management System (KMS) instance for managing keys and
* performing cryptographic operations.
* @param params.publicKey - The public key of the DID in JWK format.
* @returns A Promise resolving to a `Did` object representing the DID formed from the provided public key.
* @returns A Promise resolving to a `BearerDid` object representing the DID formed from the provided public key.
*/
private static async fromPublicKey({ keyManager, publicKey }: {
keyManager: CryptoApi;
publicKey: Jwk;
}): Promise<Did> {
}): Promise<BearerDid> {
// Serialize the public key JWK to a UTF-8 string and encode to Base64URL format.
const base64UrlEncoded = Convert.object(publicKey).toBase64Url();

Expand Down
21 changes: 11 additions & 10 deletions packages/dids/src/methods/did-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
LocalKeyManager,
} from '@web5/crypto';

import type { Did, DidCreateOptions, DidCreateVerificationMethod, DidMetadata, PortableDid } from './did-method.js';
import type { BearerDid, DidCreateOptions, DidCreateVerificationMethod, DidMetadata, PortableDid } from './did-method.js';
import type { DidDocument, DidResolutionOptions, DidResolutionResult, DidVerificationMethod } from '../types/did-core.js';

import { DidUri } from '../did-uri.js';
Expand Down Expand Up @@ -336,15 +336,15 @@ export class DidKey extends DidMethod {
* @param params - The parameters for the create operation.
* @param params.keyManager - Key Management System (KMS) used to generate keys and sign data.
* @param params.options - Optional parameters that can be specified when creating a new DID.
* @returns A Promise resolving to a {@link Did} object representing the new DID.
* @returns A Promise resolving to a {@link BearerDid} object representing the new DID.
*/
public static async create<TKms extends CryptoApi | undefined = undefined>({
keyManager = new LocalKeyManager(),
options = {}
}: {
keyManager?: TKms;
options?: DidKeyCreateOptions<TKms>;
} = {}): Promise<Did> {
} = {}): Promise<BearerDid> {
if (options.algorithm && options.verificationMethods) {
throw new Error(`The 'algorithm' and 'verificationMethods' options are mutually exclusive`);
}
Expand All @@ -364,12 +364,13 @@ export class DidKey extends DidMethod {
}

/**
* Instantiates a `Did` object for the `did:jwk` method from a given {@link PortableDid}.
* Instantiates a {@link BearerDid} object for the `did:jwk` method from a given
* {@link PortableDid}.
*
* This method allows for the creation of a `Did` object using pre-existing key material,
* This method allows for the creation of a `BearerDid` object using pre-existing key material,
* encapsulated within the `verificationMethods` array of the `PortableDid`. This is particularly
* useful when the key material is already available and you want to construct a `Did` object
* based on these keys, instead of generating new keys.
* useful when the key material is already available and you want to construct a `BearerDid`
* object based on these keys, instead of generating new keys.
*
* @remarks
* The `verificationMethods` array must contain exactly one key since the `did:jwk` method only
Expand All @@ -393,7 +394,7 @@ export class DidKey extends DidMethod {
* @param params.keyManager - Optionally specify an external Key Management System (KMS) used to
* generate keys and sign data. If not given, a new
* {@link @web5/crypto#LocalKeyManager} instance will be created and used.
* @returns A Promise resolving to a `Did` object representing the DID formed from the provided keys.
* @returns A Promise resolving to a `BearerDid` object representing the DID formed from the provided keys.
* @throws An error if the `verificationMethods` array does not contain exactly one entry.
*/
public static async fromKeys<TKms extends CryptoApi | undefined = undefined>({
Expand All @@ -403,7 +404,7 @@ export class DidKey extends DidMethod {
}: {
keyManager?: CryptoApi & KeyImporterExporter<KmsImportKeyParams, KeyIdentifier, KmsExportKeyParams>;
options?: DidKeyCreateOptions<TKms>;
} & PortableDid): Promise<Did> {
} & PortableDid): Promise<BearerDid> {
if (!verificationMethods || verificationMethods.length !== 1) {
throw new Error(`Only one verification method can be specified but ${verificationMethods?.length ?? 0} were given`);
}
Expand Down Expand Up @@ -972,7 +973,7 @@ export class DidKey extends DidMethod {
keyManager: CryptoApi;
publicKey: Jwk;
options: DidKeyCreateOptions<CryptoApi | undefined>;
}): Promise<Did> {
}): Promise<BearerDid> {
// Convert the public key to a byte array and encode to Base64URL format.
const multibaseId = await DidKeyUtils.publicKeyToMultibaseId({ publicKey });

Expand Down
Loading

0 comments on commit ab117f1

Please sign in to comment.