跳至主要內容

Address

用於壓縮公鑰的工具。

從**@kaiachain/ethers-ext軟件包中導入getCompressedPublicKey**。

要將公鑰從{x, y}格式壓縮為十六進制,請使用 getCompressedPublicKey 並將公鑰對象作為參數

否則,如果要壓縮未壓縮十六進制公鑰**,請使用 getCompressedPublicKey 並將未壓縮公鑰作為參數

addressUtils.js

const { getCompressedPublicKey } = require('@kaiachain/ethers-ext/v5')
async function main() {
const publicKeyObject = {
x: '0xdc9dccbd788c00fa98f7f4082f2f714e799bc0c29d63f04d48b54fe6250453cd',
y: '0xaf06ca34ae8714cf3dae06bacdb78c7c2d4054bd38961d40853cd5f15955da79',
}
console.log(
'pubkey from { x, y } object =',
getCompressedPublicKey(publicKeyObject)
)
const uncompressedPublicKeyString =
'0x04dc9dccbd788c00fa98f7f4082f2f714e799bc0c29d63f04d48b54fe6250453cdaf06ca34ae8714cf3dae06bacdb78c7c2d4054bd38961d40853cd5f15955da79'
console.log(
'pubkey from uncompressed format =',
getCompressedPublicKey(uncompressedPublicKeyString)
)
}
main()

output

❯ node addressUtils.js
pubkey from { x, y } object = 0x03dc9dccbd788c00fa98f7f4082f2f714e799bc0c29d63f04d48b54fe6250453cd
pubkey from uncompressed format = 0x03dc9dccbd788c00fa98f7f4082f2f714e799bc0c29d63f04d48b54fe6250453cd

讓這個頁面變得更好