diff --git a/packages/status-js/src/utils/public-key-to-eth-address.test.ts b/packages/status-js/src/utils/public-key-to-eth-address.test.ts new file mode 100644 index 00000000..11f582fa --- /dev/null +++ b/packages/status-js/src/utils/public-key-to-eth-address.test.ts @@ -0,0 +1,11 @@ +import { expect, test } from 'vitest' + +import { publicKeyToETHAddress } from './public-key-to-eth-address' + +test('should return ETH address from public key', () => { + expect( + publicKeyToETHAddress( + '0x02bcbe39785b55a22383f82ac631ea7500e204627369c4ea01d9296af0ea573f57' + ) + ).toEqual('0x0A1ec0002dDB927B03049F1aD8D589aBEA4Ba4b3') +}) diff --git a/packages/status-js/src/utils/public-key-to-eth-address.ts b/packages/status-js/src/utils/public-key-to-eth-address.ts new file mode 100644 index 00000000..b1ed58cf --- /dev/null +++ b/packages/status-js/src/utils/public-key-to-eth-address.ts @@ -0,0 +1,12 @@ +import { ethers } from 'ethers' + +import { deserializePublicKey } from './deserialize-public-key' + +export function publicKeyToETHAddress(publicKey: string): string { + const key = deserializePublicKey(publicKey, { + compress: false, + }) + const address = ethers.computeAddress(key) + + return address +}