@@ -1022,9 +1022,9 @@ export class DidDhtDocument {
1022
1022
1023
1023
// Process verification methods.
1024
1024
case dnsRecordId . startsWith ( 'k' ) : {
1025
- // Get the key type (t), Base64URL-encoded public key (k), and
1026
- // optionally, controller (c) from the decoded TXT record data.
1027
- const { t, k, c, a : parsedAlg } = DidDhtUtils . parseTxtDataToObject ( answer . data ) ;
1025
+ // Get the key type (t), Base64URL-encoded public key (k), algorithm (a), and
1026
+ // optionally, controller (c) or Verification Method ID (id) from the decoded TXT record data.
1027
+ const { id , t, k, c, a : parsedAlg } = DidDhtUtils . parseTxtDataToObject ( answer . data ) ;
1028
1028
1029
1029
// Convert the public key from Base64URL format to a byte array.
1030
1030
const publicKeyBytes = Convert . base64Url ( k ) . toUint8Array ( ) ;
@@ -1037,15 +1037,15 @@ export class DidDhtDocument {
1037
1037
1038
1038
publicKey . alg = parsedAlg || KeyTypeToDefaultAlgorithmMap [ Number ( t ) as DidDhtRegisteredKeyType ] ;
1039
1039
1040
- // Determine the Key ID (kid) : '0' for the identity key or JWK thumbprint for others.
1041
- const kid = dnsRecordId . endsWith ( '0' ) ? '0' : await computeJwkThumbprint ( { jwk : publicKey } ) ;
1042
- publicKey . kid = kid ;
1040
+ // Determine the Verification Method ID : '0' for the identity key,
1041
+ // the id from the TXT Data Object, or the JWK thumbprint if an explicity Verification Method ID not defined.
1042
+ const vmId = dnsRecordId === 'k0' ? '0' : id !== undefined ? id : await computeJwkThumbprint ( { jwk : publicKey } ) ;
1043
1043
1044
1044
// Initialize the `verificationMethod` array if it does not already exist.
1045
1045
didDocument . verificationMethod ??= [ ] ;
1046
1046
1047
1047
// Prepend the DID URI to the ID fragment to form the full verification method ID.
1048
- const methodId = `${ didUri } #${ kid } ` ;
1048
+ const methodId = `${ didUri } #${ vmId } ` ;
1049
1049
1050
1050
// Add the verification method to the DID document.
1051
1051
didDocument . verificationMethod . push ( {
@@ -1195,6 +1195,11 @@ export class DidDhtDocument {
1195
1195
1196
1196
// Define the data for the DNS TXT record.
1197
1197
const txtData = [ `t=${ keyType } ` , `k=${ publicKeyBase64Url } ` ] ;
1198
+ // if the methodId is not the identity key or a thumbprint, explicity define the id within the DNS TXT record.
1199
+ // otherwise the id can be inferred from the thumbprint.
1200
+ if ( methodId !== '0' && await computeJwkThumbprint ( { jwk : publicKey } ) !== methodId ) {
1201
+ txtData . unshift ( `id=${ methodId } ` ) ;
1202
+ }
1198
1203
1199
1204
// Only set the algorithm property (`a`) if it differs from the default algorithm for the key type.
1200
1205
if ( publicKey . alg !== KeyTypeToDefaultAlgorithmMap [ keyType ] ) {
0 commit comments