@@ -228,20 +228,57 @@ export class EthereumLedgerService {
228228
229229 const blockchainAccountId = getPreferredKey ( didRecord . didDocument . verificationMethod )
230230
231- const keyObj = didRecord . didDocument . verificationMethod . find ( ( obj ) => obj . publicKeyHex )
231+ // Look for publicKeyBase58 (new format) or fallback to publicKeyHex (legacy)
232+ const keyObj = didRecord . didDocument . verificationMethod . find ( ( obj ) => obj . publicKeyBase58 || obj . publicKeyHex )
232233
233- if ( ! keyObj || ! keyObj . publicKeyHex ) {
234- throw new CredoError ( 'Public Key hex not found in wallet for did: ' + did )
234+ if ( ! keyObj ) {
235+ throw new CredoError ( 'Public Key not found in wallet for did: ' + did )
235236 }
236237
237- const publicKey = TypedArrayEncoder . fromHex ( keyObj . publicKeyHex )
238+ let publicKeyBase58 : string
238239
239- const publicKeyBase58 = TypedArrayEncoder . toBase58 ( publicKey )
240+ if ( keyObj . publicKeyBase58 ) {
241+ publicKeyBase58 = keyObj . publicKeyBase58
242+ } else if ( keyObj . publicKeyHex ) {
243+ // Legacy support: convert hex to base58
244+ const publicKey = TypedArrayEncoder . fromHex ( keyObj . publicKeyHex )
245+ publicKeyBase58 = TypedArrayEncoder . toBase58 ( publicKey )
246+ } else {
247+ throw new CredoError ( 'Public Key not found in wallet for did: ' + did )
248+ }
240249
241250 return { publicKeyBase58, blockchainAccountId }
242251 }
243252
244253 public async resolveDID ( did : string ) {
245- return await this . resolver . resolve ( did )
254+ const result = await this . resolver . resolve ( did )
255+
256+ // Update context to include secp256k1-2019/v1
257+ if ( result . didDocument ) {
258+ result . didDocument [ '@context' ] = [
259+ 'https://www.w3.org/ns/did/v1' ,
260+ 'https://w3id.org/security/suites/secp256k1recovery-2020/v2' ,
261+ 'https://w3id.org/security/suites/secp256k1-2019/v1' ,
262+ ]
263+
264+ // Transform verification methods from publicKeyHex to publicKeyBase58
265+ if ( result . didDocument . verificationMethod ) {
266+ result . didDocument . verificationMethod = result . didDocument . verificationMethod . map ( ( vm ) => {
267+ if ( vm . publicKeyHex ) {
268+ const publicKey = TypedArrayEncoder . fromHex ( vm . publicKeyHex )
269+ const publicKeyBase58 = TypedArrayEncoder . toBase58 ( publicKey )
270+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
271+ const { publicKeyHex, ...rest } = vm
272+ return {
273+ ...rest ,
274+ publicKeyBase58,
275+ }
276+ }
277+ return vm
278+ } )
279+ }
280+ }
281+
282+ return result
246283 }
247284}
0 commit comments