Skip to content

Commit

Permalink
fix(did-provider-peer): remove multicodec and multiformats in favor o…
Browse files Browse the repository at this point in the history
…f local utils

closes #1245
  • Loading branch information
mirceanis committed Sep 27, 2023
1 parent 52c3aef commit 49e7324
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
4 changes: 1 addition & 3 deletions packages/did-provider-peer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,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",
Expand Down
18 changes: 7 additions & 11 deletions packages/did-provider-peer/src/peer-did-provider.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { IAgentContext, IIdentifier, IKey, IKeyManager, IService } from '@veramo/core-types'
import { AbstractIdentifierProvider } from '@veramo/did-manager'
import { base58btc } from 'multiformats/bases/base58'
import Multicodec from 'multicodec'
import { bytesToBase64url, hexToBytes, stringToUtf8Bytes } from '@veramo/utils'
import { bytesToBase64url, bytesToMultibase, hexToBytes, stringToUtf8Bytes } from '@veramo/utils'

import Debug from 'debug'

Expand Down Expand Up @@ -45,9 +43,7 @@ export class PeerDIDProvider extends AbstractIdentifierProvider {
): Promise<Omit<IIdentifier, 'provider'>> {
if (options.num_algo == 0) {
const key = await context.agent.keyManagerCreate({ kms: kms || this.defaultKms, type: 'Ed25519' })
const methodSpecificId = base58btc.encode(
Multicodec.addPrefix('ed25519-pub', hexToBytes(key.publicKeyHex)),
)
const methodSpecificId = bytesToMultibase(hexToBytes(key.publicKeyHex), 'base58btc', 'ed25519-pub')

const identifier: Omit<IIdentifier, 'provider'> = {
did: 'did:peer:0' + methodSpecificId,
Expand All @@ -67,12 +63,12 @@ export class PeerDIDProvider extends AbstractIdentifierProvider {
type: 'X25519',
})

const authKeyText = base58btc.encode(
Multicodec.addPrefix('ed25519-pub', hexToBytes(authKey.publicKeyHex)),
)
const authKeyText = bytesToMultibase(hexToBytes(authKey.publicKeyHex), 'base58btc', 'ed25519-pub')

const agreementKeyText = base58btc.encode(
Multicodec.addPrefix('x25519-pub', hexToBytes(agreementKey.publicKeyHex)),
const agreementKeyText = bytesToMultibase(
hexToBytes(agreementKey.publicKeyHex),
'base58btc',
'x25519-pub',
)

const ServiceEncoded = encodeService(options.service)
Expand Down

0 comments on commit 49e7324

Please sign in to comment.