Skip to content

Commit

Permalink
add publicKeyToETHAddress fn (#536)
Browse files Browse the repository at this point in the history
  • Loading branch information
felicio authored Mar 18, 2024
1 parent 02abf34 commit 70de4ec
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/status-js/src/utils/public-key-to-eth-address.test.ts
Original file line number Diff line number Diff line change
@@ -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')
})
12 changes: 12 additions & 0 deletions packages/status-js/src/utils/public-key-to-eth-address.ts
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 70de4ec

Please sign in to comment.