From c0eb781baf955e4a2f737214d179d97c77885a3d Mon Sep 17 00:00:00 2001 From: Neal Date: Mon, 29 Apr 2024 11:29:33 -0700 Subject: [PATCH 01/16] Always set alg and kid on expansion --- packages/dids/src/methods/did-dht.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/dids/src/methods/did-dht.ts b/packages/dids/src/methods/did-dht.ts index ce2bd1468..b9946866f 100644 --- a/packages/dids/src/methods/did-dht.ts +++ b/packages/dids/src/methods/did-dht.ts @@ -1031,12 +1031,16 @@ export class DidDhtDocument { // Prepend the DID URI to the ID fragment to form the full verification method ID. const methodId = `${didUri}#${id}`; - // Add the verification method to the DID document. + // Add the verification method to the DID document and always set alg and kid on expansion didDocument.verificationMethod.push({ id : methodId, type : 'JsonWebKey', controller : c ?? didUri, - publicKeyJwk : publicKey, + publicKeyJwk : { + ...publicKey, + alg : namedCurve, // Set algorithm in JWK + kid : id // Set key ID in JWK + } }); // Add a mapping from the DNS record ID (e.g., 'k0', 'k1', etc.) to the verification From 3e71313e106bbc65d9da39aadf5bf3d2b9f43117 Mon Sep 17 00:00:00 2001 From: Neal Date: Mon, 29 Apr 2024 11:30:35 -0700 Subject: [PATCH 02/16] update --- packages/dids/src/methods/did-dht.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dids/src/methods/did-dht.ts b/packages/dids/src/methods/did-dht.ts index b9946866f..837fb26e5 100644 --- a/packages/dids/src/methods/did-dht.ts +++ b/packages/dids/src/methods/did-dht.ts @@ -1031,7 +1031,7 @@ export class DidDhtDocument { // Prepend the DID URI to the ID fragment to form the full verification method ID. const methodId = `${didUri}#${id}`; - // Add the verification method to the DID document and always set alg and kid on expansion + // Add the verification method to the DID document and always set alg and kid on expansion. didDocument.verificationMethod.push({ id : methodId, type : 'JsonWebKey', From ab67df89299cf9cd56521f2859d0c601c475a614 Mon Sep 17 00:00:00 2001 From: Neal Date: Mon, 29 Apr 2024 11:51:03 -0700 Subject: [PATCH 03/16] update --- packages/dids/src/methods/did-dht.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/dids/src/methods/did-dht.ts b/packages/dids/src/methods/did-dht.ts index 837fb26e5..068c16d16 100644 --- a/packages/dids/src/methods/did-dht.ts +++ b/packages/dids/src/methods/did-dht.ts @@ -1014,7 +1014,8 @@ export class DidDhtDocument { case dnsRecordId.startsWith('k'): { // Get the method ID fragment (id), key type (t), Base64URL-encoded public key (k), and // optionally, controller (c) from the decoded TXT record data. - const { id, t, k, c } = DidDhtUtils.parseTxtDataToObject(answer.data); + const { id, t, k, c, alg } = DidDhtUtils.parseTxtDataToObject(answer.data); + // Convert the public key from Base64URL format to a byte array. const publicKeyBytes = Convert.base64Url(k).toUint8Array(); @@ -1031,6 +1032,12 @@ export class DidDhtDocument { // Prepend the DID URI to the ID fragment to form the full verification method ID. const methodId = `${didUri}#${id}`; + // Determine the Key ID (kid): '0' for the identity key or JWK thumbprint for others. + let kid = id; + if (kid !== '0') { + kid = await computeJwkThumbprint({ jwk: publicKey }); + } + // Add the verification method to the DID document and always set alg and kid on expansion. didDocument.verificationMethod.push({ id : methodId, @@ -1038,8 +1045,8 @@ export class DidDhtDocument { controller : c ?? didUri, publicKeyJwk : { ...publicKey, - alg : namedCurve, // Set algorithm in JWK - kid : id // Set key ID in JWK + alg : namedCurve, + kid : kid } }); From 7f8fd7d1fdb6f814e0d614b6e3b50d8fb268cb0d Mon Sep 17 00:00:00 2001 From: Neal Date: Mon, 29 Apr 2024 13:42:20 -0700 Subject: [PATCH 04/16] update --- packages/dids/src/methods/did-dht.ts | 35 ++++++++++++++++------------ 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/packages/dids/src/methods/did-dht.ts b/packages/dids/src/methods/did-dht.ts index 068c16d16..fe27fdea9 100644 --- a/packages/dids/src/methods/did-dht.ts +++ b/packages/dids/src/methods/did-dht.ts @@ -1014,17 +1014,26 @@ export class DidDhtDocument { case dnsRecordId.startsWith('k'): { // Get the method ID fragment (id), key type (t), Base64URL-encoded public key (k), and // optionally, controller (c) from the decoded TXT record data. - const { id, t, k, c, alg } = DidDhtUtils.parseTxtDataToObject(answer.data); - + const { id, t, k, c, alg: parsedAlg } = DidDhtUtils.parseTxtDataToObject(answer.data); // Convert the public key from Base64URL format to a byte array. const publicKeyBytes = Convert.base64Url(k).toUint8Array(); - // Use the key type integer to look up the cryptographic curve name. - const namedCurve = DidDhtRegisteredKeyType[Number(t)]; + // Determine the algorithm from the key type or use the initial algorithm if provided. + const alg = parsedAlg || DidDhtRegisteredKeyType[Number(t)]; // Convert the public key from a byte array to JWK format. - let publicKey = await DidDhtUtils.keyConverter(namedCurve).bytesToPublicKey({ publicKeyBytes }); + let publicKey = await DidDhtUtils.keyConverter(alg).bytesToPublicKey({ publicKeyBytes }); + + // Always set the algorithm on did:dht expansion. + publicKey.alg = alg; + + // Determine the Key ID (kid): '0' for the identity key or JWK thumbprint for others. Always set alg on expansion. + if (id !== '0' && publicKey.kid === undefined) { + publicKey.kid = await computeJwkThumbprint({ jwk: publicKey }); + } else { + publicKey.kid = '0'; + } // Initialize the `verificationMethod` array if it does not already exist. didDocument.verificationMethod ??= []; @@ -1032,21 +1041,13 @@ export class DidDhtDocument { // Prepend the DID URI to the ID fragment to form the full verification method ID. const methodId = `${didUri}#${id}`; - // Determine the Key ID (kid): '0' for the identity key or JWK thumbprint for others. - let kid = id; - if (kid !== '0') { - kid = await computeJwkThumbprint({ jwk: publicKey }); - } - - // Add the verification method to the DID document and always set alg and kid on expansion. + // Add the verification method to the DID document. didDocument.verificationMethod.push({ id : methodId, type : 'JsonWebKey', controller : c ?? didUri, publicKeyJwk : { ...publicKey, - alg : namedCurve, - kid : kid } }); @@ -1170,7 +1171,11 @@ export class DidDhtDocument { let methodId = vm.id.split('#').pop()!; // Remove fragment prefix, if any. idLookup.set(methodId, dnsRecordId); - const publicKey = vm.publicKeyJwk; + const publicKey = vm.publicKeyJwk!; + + if(methodId === '0') { + publicKey.kid = '0'; + } if (!(publicKey?.crv && publicKey.crv in AlgorithmToKeyTypeMap)) { throw new DidError(DidErrorCode.InvalidPublicKeyType, `Verification method '${vm.id}' contains an unsupported key type: ${publicKey?.crv ?? 'undefined'}`); From 24f308e3a099bfce12c4e2af5dcd610dac0cbb36 Mon Sep 17 00:00:00 2001 From: Neal Date: Mon, 29 Apr 2024 13:47:05 -0700 Subject: [PATCH 05/16] update --- packages/dids/src/methods/did-dht.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/dids/src/methods/did-dht.ts b/packages/dids/src/methods/did-dht.ts index fe27fdea9..c137ffd05 100644 --- a/packages/dids/src/methods/did-dht.ts +++ b/packages/dids/src/methods/did-dht.ts @@ -1031,7 +1031,7 @@ export class DidDhtDocument { // Determine the Key ID (kid): '0' for the identity key or JWK thumbprint for others. Always set alg on expansion. if (id !== '0' && publicKey.kid === undefined) { publicKey.kid = await computeJwkThumbprint({ jwk: publicKey }); - } else { + } else if (id === '0') { publicKey.kid = '0'; } @@ -1046,9 +1046,7 @@ export class DidDhtDocument { id : methodId, type : 'JsonWebKey', controller : c ?? didUri, - publicKeyJwk : { - ...publicKey, - } + publicKeyJwk : publicKey, }); // Add a mapping from the DNS record ID (e.g., 'k0', 'k1', etc.) to the verification From ec1c91005bd3a74d93431a30f425cbe0aace1ef7 Mon Sep 17 00:00:00 2001 From: Neal Date: Tue, 30 Apr 2024 11:15:55 -0700 Subject: [PATCH 06/16] update --- packages/dids/src/methods/did-dht.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/dids/src/methods/did-dht.ts b/packages/dids/src/methods/did-dht.ts index c137ffd05..bcb548045 100644 --- a/packages/dids/src/methods/did-dht.ts +++ b/packages/dids/src/methods/did-dht.ts @@ -32,6 +32,7 @@ import { extractDidFragment } from '../utils.js'; import { DidError, DidErrorCode } from '../did-error.js'; import { DidVerificationRelationship } from '../types/did-core.js'; import { EMPTY_DID_RESOLUTION_RESULT } from '../types/did-resolution.js'; +import { getJoseSignatureAlgorithmFromPublicKey } from '@web5/crypto/utils'; /** * Represents a BEP44 message, which is used for storing and retrieving data in the Mainline DHT @@ -347,6 +348,15 @@ export enum DidDhtRegisteredKeyType { secp256r1 = 2 } +/** + * Private helper that maps did dht registered key types to their corresponding default algorithm identifiers. + */ +const KeyTypeToDefaultAlgorithmMap = { + [DidDhtRegisteredKeyType.Ed25519] : 'EdDSA', + [DidDhtRegisteredKeyType.secp256k1] : 'ES256K', + [DidDhtRegisteredKeyType.secp256r1] : 'ES256', +} as const; + /** * Maps {@link https://www.w3.org/TR/did-core/#verification-relationships | DID Core Verification Relationship} * values to the corresponding record name in the DNS packet representation of a DHT DID document. @@ -1182,6 +1192,12 @@ export class DidDhtDocument { // Use the public key's `crv` property to get the DID DHT key type. const keyType = DidDhtRegisteredKeyType[publicKey.crv as keyof typeof DidDhtRegisteredKeyType]; + let alg; + if(KeyTypeToDefaultAlgorithmMap[keyType] !== getJoseSignatureAlgorithmFromPublicKey(publicKey)) + { + alg = getJoseSignatureAlgorithmFromPublicKey(publicKey); + } + // Convert the public key from JWK format to a byte array. const publicKeyBytes = await DidDhtUtils.keyConverter(publicKey.crv).publicKeyToBytes({ publicKey }); @@ -1189,7 +1205,7 @@ export class DidDhtDocument { const publicKeyBase64Url = Convert.uint8Array(publicKeyBytes).toBase64Url(); // Define the data for the DNS TXT record. - const txtData = [`id=${methodId}`, `t=${keyType}`, `k=${publicKeyBase64Url}`]; + const txtData = [`id=${methodId}`, `t=${keyType}`, `k=${publicKeyBase64Url}`, ...(alg ? [`alg=${alg}`] : [])]; // Add the controller property, if set to a value other than the Identity Key (DID Subject). if (vm.controller !== didDocument.id) txtData.push(`c=${vm.controller}`); From 0c54f879d8fcfc5332f8546a6a5974ad0a76cd54 Mon Sep 17 00:00:00 2001 From: Neal Date: Tue, 30 Apr 2024 11:47:52 -0700 Subject: [PATCH 07/16] update --- packages/dids/src/methods/did-dht.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/dids/src/methods/did-dht.ts b/packages/dids/src/methods/did-dht.ts index bcb548045..8873747c9 100644 --- a/packages/dids/src/methods/did-dht.ts +++ b/packages/dids/src/methods/did-dht.ts @@ -1029,14 +1029,18 @@ export class DidDhtDocument { // Convert the public key from Base64URL format to a byte array. const publicKeyBytes = Convert.base64Url(k).toUint8Array(); + // Use the key type integer to look up the cryptographic curve name. + const namedCurve = DidDhtRegisteredKeyType[Number(t)]; + + // TODO: Remove after testing // Determine the algorithm from the key type or use the initial algorithm if provided. - const alg = parsedAlg || DidDhtRegisteredKeyType[Number(t)]; + // const alg = parsedAlg || DidDhtRegisteredKeyType[Number(t)]; // Convert the public key from a byte array to JWK format. - let publicKey = await DidDhtUtils.keyConverter(alg).bytesToPublicKey({ publicKeyBytes }); + let publicKey = await DidDhtUtils.keyConverter(namedCurve).bytesToPublicKey({ publicKeyBytes }); // Always set the algorithm on did:dht expansion. - publicKey.alg = alg; + publicKey.alg = parsedAlg || getJoseSignatureAlgorithmFromPublicKey(publicKey); // Determine the Key ID (kid): '0' for the identity key or JWK thumbprint for others. Always set alg on expansion. if (id !== '0' && publicKey.kid === undefined) { From 62cdc2fc38b0d5ea8356b46ac5ad85d2dafc5d5e Mon Sep 17 00:00:00 2001 From: nitro-neal <5314059+nitro-neal@users.noreply.github.com> Date: Wed, 1 May 2024 11:05:14 -0700 Subject: [PATCH 08/16] Update packages/dids/src/methods/did-dht.ts Co-authored-by: Gabe <7622243+decentralgabe@users.noreply.github.com> --- packages/dids/src/methods/did-dht.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dids/src/methods/did-dht.ts b/packages/dids/src/methods/did-dht.ts index 8873747c9..74d4fbe8c 100644 --- a/packages/dids/src/methods/did-dht.ts +++ b/packages/dids/src/methods/did-dht.ts @@ -1209,7 +1209,7 @@ export class DidDhtDocument { const publicKeyBase64Url = Convert.uint8Array(publicKeyBytes).toBase64Url(); // Define the data for the DNS TXT record. - const txtData = [`id=${methodId}`, `t=${keyType}`, `k=${publicKeyBase64Url}`, ...(alg ? [`alg=${alg}`] : [])]; + const txtData = [`id=${methodId}`, `t=${keyType}`, `k=${publicKeyBase64Url}`, ...(alg ? [`a=${alg}`] : [])]; // Add the controller property, if set to a value other than the Identity Key (DID Subject). if (vm.controller !== didDocument.id) txtData.push(`c=${vm.controller}`); From 44b12b6bb036003aa4c7afd63f43e96ab0dbc47f Mon Sep 17 00:00:00 2001 From: Neal Date: Wed, 1 May 2024 11:09:04 -0700 Subject: [PATCH 09/16] update --- packages/dids/src/methods/did-dht.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/dids/src/methods/did-dht.ts b/packages/dids/src/methods/did-dht.ts index 74d4fbe8c..0ecf9b0d9 100644 --- a/packages/dids/src/methods/did-dht.ts +++ b/packages/dids/src/methods/did-dht.ts @@ -1023,8 +1023,8 @@ export class DidDhtDocument { // Process verification methods. case dnsRecordId.startsWith('k'): { // Get the method ID fragment (id), key type (t), Base64URL-encoded public key (k), and - // optionally, controller (c) from the decoded TXT record data. - const { id, t, k, c, alg: parsedAlg } = DidDhtUtils.parseTxtDataToObject(answer.data); + // optionally, controller (c) and alg (a) from the decoded TXT record data. + const { id, t, k, c, a: parsedAlg } = DidDhtUtils.parseTxtDataToObject(answer.data); // Convert the public key from Base64URL format to a byte array. const publicKeyBytes = Convert.base64Url(k).toUint8Array(); @@ -1032,10 +1032,6 @@ export class DidDhtDocument { // Use the key type integer to look up the cryptographic curve name. const namedCurve = DidDhtRegisteredKeyType[Number(t)]; - // TODO: Remove after testing - // Determine the algorithm from the key type or use the initial algorithm if provided. - // const alg = parsedAlg || DidDhtRegisteredKeyType[Number(t)]; - // Convert the public key from a byte array to JWK format. let publicKey = await DidDhtUtils.keyConverter(namedCurve).bytesToPublicKey({ publicKeyBytes }); From e4093483b534d818f0a730eca7101c84cf6d75db Mon Sep 17 00:00:00 2001 From: nitro-neal <5314059+nitro-neal@users.noreply.github.com> Date: Thu, 2 May 2024 15:51:17 -0700 Subject: [PATCH 10/16] Update packages/dids/src/methods/did-dht.ts Co-authored-by: Henry Tsai --- packages/dids/src/methods/did-dht.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dids/src/methods/did-dht.ts b/packages/dids/src/methods/did-dht.ts index 0ecf9b0d9..4ac20a114 100644 --- a/packages/dids/src/methods/did-dht.ts +++ b/packages/dids/src/methods/did-dht.ts @@ -355,7 +355,7 @@ const KeyTypeToDefaultAlgorithmMap = { [DidDhtRegisteredKeyType.Ed25519] : 'EdDSA', [DidDhtRegisteredKeyType.secp256k1] : 'ES256K', [DidDhtRegisteredKeyType.secp256r1] : 'ES256', -} as const; +} /** * Maps {@link https://www.w3.org/TR/did-core/#verification-relationships | DID Core Verification Relationship} From d9608f16fbc4fe8b670e85e8774b4a76cbdeb857 Mon Sep 17 00:00:00 2001 From: nitro-neal <5314059+nitro-neal@users.noreply.github.com> Date: Thu, 2 May 2024 15:51:23 -0700 Subject: [PATCH 11/16] Update packages/dids/src/methods/did-dht.ts Co-authored-by: Henry Tsai --- packages/dids/src/methods/did-dht.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dids/src/methods/did-dht.ts b/packages/dids/src/methods/did-dht.ts index 4ac20a114..c63c23aa5 100644 --- a/packages/dids/src/methods/did-dht.ts +++ b/packages/dids/src/methods/did-dht.ts @@ -1035,7 +1035,7 @@ export class DidDhtDocument { // Convert the public key from a byte array to JWK format. let publicKey = await DidDhtUtils.keyConverter(namedCurve).bytesToPublicKey({ publicKeyBytes }); - // Always set the algorithm on did:dht expansion. + // DID DHT spec requires `alg` in keys in the DID document publicKey.alg = parsedAlg || getJoseSignatureAlgorithmFromPublicKey(publicKey); // Determine the Key ID (kid): '0' for the identity key or JWK thumbprint for others. Always set alg on expansion. From a62c204dbb8bb893aef8f052c5586e3eedc52c5f Mon Sep 17 00:00:00 2001 From: nitro-neal <5314059+nitro-neal@users.noreply.github.com> Date: Thu, 2 May 2024 15:51:47 -0700 Subject: [PATCH 12/16] Update packages/dids/src/methods/did-dht.ts Co-authored-by: Henry Tsai --- packages/dids/src/methods/did-dht.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dids/src/methods/did-dht.ts b/packages/dids/src/methods/did-dht.ts index c63c23aa5..203105566 100644 --- a/packages/dids/src/methods/did-dht.ts +++ b/packages/dids/src/methods/did-dht.ts @@ -1038,7 +1038,7 @@ export class DidDhtDocument { // DID DHT spec requires `alg` in keys in the DID document publicKey.alg = parsedAlg || getJoseSignatureAlgorithmFromPublicKey(publicKey); - // Determine the Key ID (kid): '0' for the identity key or JWK thumbprint for others. Always set alg on expansion. + // Determine the Key ID (kid): '0' for the identity key or JWK thumbprint for others. if (id !== '0' && publicKey.kid === undefined) { publicKey.kid = await computeJwkThumbprint({ jwk: publicKey }); } else if (id === '0') { From 07dea7eff4e92ca8bfb0146c9c023078cdd6489c Mon Sep 17 00:00:00 2001 From: nitro-neal <5314059+nitro-neal@users.noreply.github.com> Date: Thu, 2 May 2024 15:52:20 -0700 Subject: [PATCH 13/16] Update packages/dids/src/methods/did-dht.ts Co-authored-by: Henry Tsai --- packages/dids/src/methods/did-dht.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/dids/src/methods/did-dht.ts b/packages/dids/src/methods/did-dht.ts index 203105566..8262aea7c 100644 --- a/packages/dids/src/methods/did-dht.ts +++ b/packages/dids/src/methods/did-dht.ts @@ -1181,6 +1181,7 @@ export class DidDhtDocument { const publicKey = vm.publicKeyJwk!; + // Always set `kid` to `0` if `methodId` is `0`, even if `kid` is not given, as a caller/user convenience. if(methodId === '0') { publicKey.kid = '0'; } From 847ecb132a3fbd8022db235d3d023aabc7137e85 Mon Sep 17 00:00:00 2001 From: nitro-neal <5314059+nitro-neal@users.noreply.github.com> Date: Thu, 2 May 2024 15:53:28 -0700 Subject: [PATCH 14/16] Update packages/dids/src/methods/did-dht.ts Co-authored-by: Henry Tsai --- packages/dids/src/methods/did-dht.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/dids/src/methods/did-dht.ts b/packages/dids/src/methods/did-dht.ts index 8262aea7c..efb4d9552 100644 --- a/packages/dids/src/methods/did-dht.ts +++ b/packages/dids/src/methods/did-dht.ts @@ -1206,7 +1206,13 @@ export class DidDhtDocument { const publicKeyBase64Url = Convert.uint8Array(publicKeyBytes).toBase64Url(); // Define the data for the DNS TXT record. - const txtData = [`id=${methodId}`, `t=${keyType}`, `k=${publicKeyBase64Url}`, ...(alg ? [`a=${alg}`] : [])]; + const txtData = [`id=${methodId}`, `t=${keyType}`, `k=${publicKeyBase64Url}`]; + + // Only set the algorithm property (`a`) if it differs from the default algorithm for the key type. + const algorithmUsedByKey = getJoseSignatureAlgorithmFromPublicKey(publicKey); + if(algorithmUsedByKey !== KeyTypeToDefaultAlgorithmMap[keyType]) { + txtData.push(`a=${algorithmUsedByKey}`); + } // Add the controller property, if set to a value other than the Identity Key (DID Subject). if (vm.controller !== didDocument.id) txtData.push(`c=${vm.controller}`); From fe5d87f1ecfc396eac8a24b4954f26cd63656787 Mon Sep 17 00:00:00 2001 From: Neal Date: Thu, 2 May 2024 16:01:05 -0700 Subject: [PATCH 15/16] updating for simpler logic --- packages/dids/src/methods/did-dht.ts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/packages/dids/src/methods/did-dht.ts b/packages/dids/src/methods/did-dht.ts index efb4d9552..ae11226bc 100644 --- a/packages/dids/src/methods/did-dht.ts +++ b/packages/dids/src/methods/did-dht.ts @@ -352,7 +352,7 @@ export enum DidDhtRegisteredKeyType { * Private helper that maps did dht registered key types to their corresponding default algorithm identifiers. */ const KeyTypeToDefaultAlgorithmMap = { - [DidDhtRegisteredKeyType.Ed25519] : 'EdDSA', + [DidDhtRegisteredKeyType.Ed25519] : 'Ed25519', [DidDhtRegisteredKeyType.secp256k1] : 'ES256K', [DidDhtRegisteredKeyType.secp256r1] : 'ES256', } @@ -1039,10 +1039,10 @@ export class DidDhtDocument { publicKey.alg = parsedAlg || getJoseSignatureAlgorithmFromPublicKey(publicKey); // Determine the Key ID (kid): '0' for the identity key or JWK thumbprint for others. - if (id !== '0' && publicKey.kid === undefined) { - publicKey.kid = await computeJwkThumbprint({ jwk: publicKey }); - } else if (id === '0') { + if (id === '0') { publicKey.kid = '0'; + } else if (publicKey.kid === undefined) { + publicKey.kid = await computeJwkThumbprint({ jwk: publicKey }); } // Initialize the `verificationMethod` array if it does not already exist. @@ -1193,12 +1193,6 @@ export class DidDhtDocument { // Use the public key's `crv` property to get the DID DHT key type. const keyType = DidDhtRegisteredKeyType[publicKey.crv as keyof typeof DidDhtRegisteredKeyType]; - let alg; - if(KeyTypeToDefaultAlgorithmMap[keyType] !== getJoseSignatureAlgorithmFromPublicKey(publicKey)) - { - alg = getJoseSignatureAlgorithmFromPublicKey(publicKey); - } - // Convert the public key from JWK format to a byte array. const publicKeyBytes = await DidDhtUtils.keyConverter(publicKey.crv).publicKeyToBytes({ publicKey }); From c9493ff4f4dfbccd8d04cba28b335a69720c41d3 Mon Sep 17 00:00:00 2001 From: Neal Date: Mon, 6 May 2024 15:43:40 -0700 Subject: [PATCH 16/16] fix lint --- packages/dids/src/methods/did-dht.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dids/src/methods/did-dht.ts b/packages/dids/src/methods/did-dht.ts index ae11226bc..20494033e 100644 --- a/packages/dids/src/methods/did-dht.ts +++ b/packages/dids/src/methods/did-dht.ts @@ -355,7 +355,7 @@ const KeyTypeToDefaultAlgorithmMap = { [DidDhtRegisteredKeyType.Ed25519] : 'Ed25519', [DidDhtRegisteredKeyType.secp256k1] : 'ES256K', [DidDhtRegisteredKeyType.secp256r1] : 'ES256', -} +}; /** * Maps {@link https://www.w3.org/TR/did-core/#verification-relationships | DID Core Verification Relationship}