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

**URL:** <https://community.blockcerts.org/t/how-to-convert-my-eth-wallet-address-into-a-valid-did-format/3219>\
**Category:** Support\
**Created:** [June 16, 2022, 2:27pm UTC](https://community.blockcerts.org/t/how-to-convert-my-eth-wallet-address-into-a-valid-did-format/3219 "2022-06-16T14:27:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![koshilife](https://sea2.discourse-cdn.com/flex016/user_avatar/community.blockcerts.org/koshilife/32/848_2.png) [@koshilife](https://community.blockcerts.org/u/koshilife)\
**Post date:** [June 16, 2022, 2:27pm UTC](https://community.blockcerts.org/t/how-to-convert-my-eth-wallet-address-into-a-valid-did-format/3219/1 "2022-06-16T14:27:03Z")

</div>

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

[https://gist.githubusercontent.com/koshilife/88601d21fedc81d9f6daec92b6017648/raw/d3fce2569fdfeba9cbb950457bca2ad450c9607d/blockcerts\_v3\_with\_did-ethr.json](https://gist.githubusercontent.com/koshilife/88601d21fedc81d9f6daec92b6017648/raw/d3fce2569fdfeba9cbb950457bca2ad450c9607d/blockcerts_v3_with_did-ethr.json)

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

> Unnable to parse JSON out of issuer identification data

 ![Screen Shot 2022-06-16 at 22.25.34](https://us1.discourse-cdn.com/flex016/uploads/blockcerts/original/1X/66a9ab82f41ff9d88cad270bf3390a7038dddef8.png)

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](https://w3c.github.io/did-core/#dfn-publickeyjwk).

Is there any good tool or method for this?

---

<div class="post-metadata">

**Author:** ![koshilife](https://sea2.discourse-cdn.com/flex016/user_avatar/community.blockcerts.org/koshilife/32/848_2.png) [@koshilife](https://community.blockcerts.org/u/koshilife)\
**Post date:** [June 20, 2022, 4:15pm UTC](https://community.blockcerts.org/t/how-to-convert-my-eth-wallet-address-into-a-valid-did-format/3219/2 "2022-06-20T16:15:54Z")

</div>

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

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

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

```

refs: [JSDoc: Home](https://eternaldeiwos.github.io/keyto/1.0.0/)

---

<div class="post-metadata">

**Author:** ![koshilife](https://sea2.discourse-cdn.com/flex016/user_avatar/community.blockcerts.org/koshilife/32/848_2.png) [@koshilife](https://community.blockcerts.org/u/koshilife)\
**Post date:** [June 20, 2022, 4:32pm UTC](https://community.blockcerts.org/t/how-to-convert-my-eth-wallet-address-into-a-valid-did-format/3219/3 "2022-06-20T16:32:17Z")

</div>

(Add)

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

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

const YOUR_PRIVATE_KEY = "TODO";
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]);
  padding--;
}

// 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);

console.log(`0x${address.toString()}`);

```

I referred to [cert-verifier-js/src/inspectors/did/deriveIssuingAddressFromPublicKey.ts](https://github.com/blockchain-certificates/cert-verifier-js/blob/0ab1c12dc629dff8ce07e6c394b1688c1a38480f/src/inspectors/did/deriveIssuingAddressFromPublicKey.ts)
