Reputation: 98
I need to set a public key for my multisignature but I'm unsure how to access the public key from a Key object in my frontend code?
I tried converting the object but couldn't get the public key?
Upvotes: 1
Views: 242
Reputation: 513
I assume you are using Javascript SDK. You can derive public key from private key object. Hedera Javascript SDK allows you to generate both ECDSA and ED25519 key pairs. Please take a look at the following example
const { PrivateKey } = require("@hashgraph/sdk");
async function main() {
const privateKeyED = PrivateKey.generateED25519();
const publicKeyED = privateKeyED.publicKey;
console.log("- Generated ED25519 Key");
console.log("Private Key (ED25519, DER)", privateKeyED.toStringDer());
console.log("Private Key (ED25519, RAW)", privateKeyED.toStringRaw());
console.log("Public Key (ED25519, DER)", publicKeyED.toStringDer());
console.log("Public Key (ED25519, RAW)", publicKeyED.toStringRaw());
console.log("------------------------");
console.log("- Generated ECDSA Key");
const privateKeyEC = PrivateKey.generateECDSA();
const publicKeyEC = privateKeyEC.publicKey;
console.log("Private Key (ECDSA, DER)", privateKeyEC.toStringDer());
console.log("Private Key (ECDSA, RAW)", privateKeyEC.toStringRaw());
console.log("Public Key (ECDSA, DER)", publicKeyEC.toStringDer());
console.log("Public Key (ECDSA, RAW)", publicKeyEC.toStringRaw());
console.log("Ethereum Address", publicKeyEC.toEthereumAddress().toString());
}
main();
Upvotes: 2