How to convert my ETH wallet address into a valid DID format

Hi, community!
I’m learning Blockcerts V3. I created the following blockchain certificate by cert-issuer==3.0.1 and chose Ethereum Ropsten.

But, when I tried to verify, I got the following error.

Unnable to parse JSON out of issuer identification data

According to the cert-issuer README, I guess the error reason that the DID document resolved from did:ethr is NOT an expected format.

So, to fix the error, I’m going to create a valid DID document and to host on did:web or to use did:key. But, I have no idea to convert my Ethreum wallet address into DID’s publicKeyJwk format.

Is there any good tool or method for this?

1 Like

I solved this.
I found a way to convert my private key instead of my wallet address into a public key(JWK).

const keyto = require('@trust/keyto')

let privateKey = '<BLOCKCHAIN-PRIVATE-KEY>'
let keyJwk = keyto.from(privateKey, 'blk').toJwk('public')

refs: JSDoc: Home


I could confirm the converted address is the same as my wallet address by the following codes.

const keyto = require('@trust/keyto');
const ec = require('elliptic').ec;
const secp256k1 = require('secp256k1');
const keccak256 = require('js-sha3').keccak256;

const keyJwk  = keyto.from(YOUR_PRIVATE_KEY, 'blk').toJwk('public');

const uncompressedPublicKey = keyto.from(keyJwk, 'jwk').toString('blk', 'public');
const compressed = secp256k1.publicKeyConvert(Buffer.from(uncompressedPublicKey, 'hex'),true);
const publicKeyHex = Buffer.from(compressed).toString('hex');

// referred to publicKeyUInt8ArrayFromJwk
let publicKeyBuffer = Buffer.from(publicKeyHex, 'hex');
let padding = 32 - publicKeyBuffer.length;
while (padding > 0) {
  publicKeyBuffer = Buffer.concat([Buffer.from('00', 'hex'), publicKeyBuffer]);

// referred to computeEthereumAddressFromPublicKey
const publicKeyString = publicKeyBuffer.toString('hex');
const ellipticCurve = new ec('secp256k1');
const decodedPublicKey = ellipticCurve.keyFromPublic(publicKeyString, 'hex');
const publicKeyUncompressed = decodedPublicKey.getPublic().encode('hex').slice(2);
const address = keccak256(Buffer.from(publicKeyUncompressed, 'hex')).slice(64 - 40);


I referred to cert-verifier-js/src/inspectors/did/deriveIssuingAddressFromPublicKey.ts