0

I'm using this code sample from here to extract my public key from my Dot address. I just want to verify that this is in fact converting my address to the public key.

const { decodeAddress } = require('@polkadot/util-crypto');
const { u8aToHex } = require('@polkadot/util');
const publicKey = decodeAddress('5DSaSznmKRjt9Lvg4478V54UU8kdNyZKSQM8brSiczFR1S1H');
const hexPublicKey = u8aToHex(publicKey);
console.log(hexPublicKey);
1
  • It is impossible to extract the Private Key from the Public Key, otherwise it would not be secure. Commented Dec 22, 2022 at 15:51

1 Answer 1

1

Following this code you mention I guess you have generated already the Keypair of your account, or you can sign a message using the private key of this account.

You can verify a signed message using your public key or using the address. To verify that you have the correct address you can verify the signature using both methods and see if both are valid.

Code example using Alice testing account:

// create Alice based on the development seed
const alice = keyring.addFromUri('//Alice');

// create the message and sign it
const message = stringToU8a('this is our message');
const signature = alice.sign(message);

// verify the message using Alice's address
const { isValid } = signatureVerify(message, signature, alice.address);
// verify the message using Alice's public key
const isValidWithPublicKey = alice.verify(message, signature, alice.publicKey);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.