remove privateKeyToAddress util

This commit is contained in:
Pavel Prichodko 2022-06-03 17:45:07 +02:00 committed by Felicio Mununga
parent 085906398a
commit 0bf7d05344
No known key found for this signature in database
GPG Key ID: 0EB8D75C775AB6F1
2 changed files with 0 additions and 23 deletions

View File

@ -1,10 +0,0 @@
import { privateKeyToAddress } from './private-key-to-address'
describe('privateKeyToAddress', () => {
it('should return public address', () => {
const privateKey =
'0x348ce564d427a3311b6536bbcff9390d69395b06ed6c486954e971d960fe8709'
const address = privateKeyToAddress(privateKey)
expect(address).toEqual('0xb8CE9ab6943e0eCED004cDe8e3bBed6568B2Fa01')
})
})

View File

@ -1,13 +0,0 @@
import { keccak256 } from 'ethereum-cryptography/keccak'
import { getPublicKey } from 'ethereum-cryptography/secp256k1'
import { bytesToHex } from 'ethereum-cryptography/utils'
export function privateKeyToAddress(privateKey: string): string {
const publicKey = getPublicKey(privateKey)
const publicKeyWithoutPrefix = publicKey.slice(1) // uncompressed public key has 04 prefix
const hash = keccak256(publicKeyWithoutPrefix)
const address = bytesToHex(hash.slice(12))
// TODO: add checksum
return address
}