diff --git a/src/resolver.ts b/src/resolver.ts index a1e2c84..9c3331b 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -3,7 +3,7 @@ import { APIError, PublicKey } from '@wharfkit/antelope'; import { AccountObject } from '@wharfkit/antelope/src/api/v1/types'; import { PermissionLevelWeight } from '@wharfkit/antelope/src/chain/authority'; import { Entry, Registry, MethodId, VerificationMethod, AntelopeDIDResolutionOptions } from './types'; -import { createJWK, getCurveNamesFromType } from './utils'; +import { createJWK, getCurveNamesFromType, toPublicKeyHex } from './utils'; import antelopeChainRegistry from './antelope-did-chain-registry.json'; import { getApi } from './api'; @@ -108,20 +108,24 @@ function findServices(service: Array, type: string): Array (Array.isArray(s.type) ? s.type.includes(type) : s.type === type)); } -function createKeyMethod(baseId: string, i: number, did: string, key: PublicKey): VerificationMethod { - const pubKey = key; - - const publicKeyJwk = createJWK(pubKey); +function createKeyMethod(baseId: string, i: number, did: string, pubKey: PublicKey): VerificationMethod { const { verificationMethodType } = getCurveNamesFromType(pubKey); - const keyMethod: VerificationMethod = { - id: baseId + '-' + i, - controller: did, - type: verificationMethodType, - publicKeyJwk, - }; - - return keyMethod; + if (verificationMethodType === 'JsonWebKey2020') { + return { + id: baseId + '-' + i, + controller: did, + type: verificationMethodType, + publicKeyJwk: createJWK(pubKey), + }; + } else { + return { + id: baseId + '-' + i, + controller: did, + type: verificationMethodType, + publicKeyHex: toPublicKeyHex(pubKey), + }; + } } function createAccountMethod( diff --git a/src/utils.ts b/src/utils.ts index 912b5db..9d60cf0 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -2,7 +2,7 @@ import { PublicKey, KeyType, PrivateKey } from '@wharfkit/antelope'; import { secp256k1 } from '@noble/curves/secp256k1' import { p256 } from '@noble/curves/p256' import { ProjPointType } from '@noble/curves/abstract/weierstrass'; -import { bytesToBase64url, ES256KSigner, ES256Signer, hexToBytes, Signer } from 'did-jwt'; +import { bytesToBase64url, bytesToHex, ES256KSigner, ES256Signer, hexToBytes, Signer } from 'did-jwt'; import { Issuer } from 'did-jwt-vc'; export function createSigner(privateKey: PrivateKey): Signer { @@ -25,6 +25,10 @@ export function createIssuer(did: string, privateKey: PrivateKey): Issuer { } } +export function toPublicKeyHex(publicKey: PublicKey): string { + return bytesToHex(publicKey.data.array); +} + // Cannot import the following, so copying here // import { bigintToBytes } from '../node_modules/did-jwt/src/util'; function bigintToBytes(n: bigint, minLength?: number): Uint8Array {