2

I have a toy example : My keypair is ed25519

const seed = [
   40, 246, 184,  64,  69, 145, 132, 131,
  231,  66, 112, 159, 162,  36,  79, 197,
   62,  54, 222, 103, 122, 190,   7, 143,
   94, 190, 180,  76,  87, 182, 115, 236
]

seed is Uint8Array(32) type

How I convert seed into private key in Substrate with polkadotjs api

1 Answer 1

1

You can get the Keypair and with it you can obtain the Public Key, the Address and sign transactions.

But the keyring does not expose the private key. It manages all signing operations on your behalf.

A code example to do that from your seed:

const keyring = new Keyring({ type: 'ed25519' })
const seed = [
    40, 246, 184,  64,  69, 145, 132, 131,
   231,  66, 112, 159, 162,  36,  79, 197,
    62,  54, 222, 103, 122, 190,   7, 143,
    94, 190, 180,  76,  87, 182, 115, 236
 ]
// add the account, encrypting it, override to ed25519
const keys = keyring.addFromSeed(Uint8Array.from(seed), { name: 'hex seed acc' },'ed25519');
console.log(keys.publicKey);
console.log(keys.address);
const signature = keys.sign("message");
console.log(signature);
1
  • Dont we have another way to expose our private key from raw seed/mnemonic phrase?
    – CocDap
    Commented Dec 22, 2022 at 8:28

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.