Skip to content

Commit

Permalink
feat: using publicKeyHex
Browse files Browse the repository at this point in the history
  • Loading branch information
theblockstalk committed Jul 7, 2024
1 parent e17923f commit 4816ebd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
30 changes: 17 additions & 13 deletions src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -108,20 +108,24 @@ function findServices(service: Array<ServiceEndpoint>, type: string): Array<Serv
return service.filter((s: any) => (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(
Expand Down
6 changes: 5 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 4816ebd

Please sign in to comment.