diff --git a/packages/did-provider-key/package.json b/packages/did-provider-key/package.json index 3b2ed34f1..d14630d0a 100644 --- a/packages/did-provider-key/package.json +++ b/packages/did-provider-key/package.json @@ -18,9 +18,7 @@ "@veramo/did-manager": "workspace:^", "@veramo/utils": "workspace:^", "debug": "^4.3.3", - "did-resolver": "^4.1.0", - "multicodec": "^3.2.1", - "multiformats": "^12.0.1" + "did-resolver": "^4.1.0" }, "devDependencies": { "@types/debug": "4.1.8", diff --git a/packages/did-provider-key/src/key-did-provider.ts b/packages/did-provider-key/src/key-did-provider.ts index 2c42df506..afab45a5f 100644 --- a/packages/did-provider-key/src/key-did-provider.ts +++ b/packages/did-provider-key/src/key-did-provider.ts @@ -1,9 +1,7 @@ import { IAgentContext, IIdentifier, IKey, IKeyManager, IService, RequireOnly } from '@veramo/core-types' import { AbstractIdentifierProvider } from '@veramo/did-manager' -import { hexToBytes } from '@veramo/utils' +import { bytesToMultibase, hexToBytes } from '@veramo/utils' import { computePublicKey } from '@ethersproject/signing-key' -import { base58btc } from 'multiformats/bases/base58' -import Multicodec from 'multicodec' import Debug from 'debug' @@ -11,11 +9,11 @@ const debug = Debug('veramo:did-key:identifier-provider') type IContext = IAgentContext type CreateKeyDidOptions = { - keyType?: keyof typeof keyOptions + keyType?: keyof typeof keyCodecs privateKeyHex?: string } -const keyOptions = { +const keyCodecs = { Ed25519: 'ed25519-pub', X25519: 'x25519-pub', Secp256k1: 'secp256k1-pub', @@ -38,7 +36,7 @@ export class KeyDIDProvider extends AbstractIdentifierProvider { { kms, options }: { kms?: string; options?: CreateKeyDidOptions }, context: IContext, ): Promise> { - const keyType = (options?.keyType && keyOptions[options?.keyType] && options.keyType) || 'Ed25519' + const keyType = (options?.keyType && keyCodecs[options?.keyType] && options.keyType) || 'Ed25519' const key = await this.importOrGenerateKey( { kms: kms || this.defaultKms, @@ -51,8 +49,7 @@ export class KeyDIDProvider extends AbstractIdentifierProvider { ) const publicKeyHex = key.type === 'Secp256k1' ? computePublicKey('0x' + key.publicKeyHex, true) : key.publicKeyHex - const multicodecEncoded = Multicodec.addPrefix(keyOptions[keyType], hexToBytes(publicKeyHex)) - const methodSpecificId: string = base58btc.encode(multicodecEncoded) + const methodSpecificId: string = bytesToMultibase(hexToBytes(publicKeyHex), 'base58btc', keyCodecs[keyType]) const identifier: Omit = { did: 'did:key:' + methodSpecificId, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 40c44b18c..6c2968951 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -947,12 +947,6 @@ importers: did-resolver: specifier: ^4.1.0 version: 4.1.0 - multicodec: - specifier: ^3.2.1 - version: 3.2.1 - multiformats: - specifier: ^12.0.1 - version: 12.0.1 devDependencies: '@types/debug': specifier: 4.1.8 @@ -981,12 +975,6 @@ importers: did-resolver: specifier: ^4.1.0 version: 4.1.0 - multicodec: - specifier: ^3.2.1 - version: 3.2.1 - multiformats: - specifier: ^12.0.1 - version: 12.0.1 devDependencies: '@types/debug': specifier: 4.1.8 @@ -1431,6 +1419,9 @@ importers: '@veramo/did-provider-key': specifier: workspace:* version: link:../did-provider-key + '@veramo/did-provider-peer': + specifier: workspace:^ + version: link:../did-provider-peer '@veramo/did-provider-pkh': specifier: workspace:* version: link:../did-provider-pkh @@ -19545,14 +19536,6 @@ packages: thunky: 1.1.0 dev: true - /multicodec@3.2.1: - resolution: {integrity: sha512-+expTPftro8VAW8kfvcuNNNBgb9gPeNYV9dn+z1kJRWF2vih+/S79f2RVeIwmrJBUJ6NT9IUPWnZDQvegEh5pw==} - deprecated: This module has been superseded by the multiformats module - dependencies: - uint8arrays: 3.1.1 - varint: 6.0.0 - dev: false - /multiformats@12.0.1: resolution: {integrity: sha512-s01wijBJoDUqESWSzePY0lvTw7J3PVO9x2Cc6ASI5AMZM2Gnhh7BC17+nlFhHKU7dDzaCaRfb+NiqNzOsgPUoQ==} engines: {node: '>=16.0.0', npm: '>=7.0.0'} @@ -25043,10 +25026,6 @@ packages: resolution: {integrity: sha512-lKxKYG6H03yCZUpAGOPOsMcGxd1RHCu1iKvEHYDPmTyq2HueGhD73ssNBqqQWfvYs04G9iUFRvmAVLW20Jw6ow==} dev: false - /varint@6.0.0: - resolution: {integrity: sha512-cXEIW6cfr15lFv563k4GuVuW/fiwjknytD37jIOLSdSWuOI6WnO/oKwmP2FQTU2l01LP8/M5TSAJpzUaGe3uWg==} - dev: false - /vary@1.1.2: resolution: {integrity: sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==} engines: {node: '>= 0.8'}