2

Using JavaScript and Node.js, how can I reliably convert an ED25519 private key (used on Hedera Testnet) from hexadecimal encoded string format to DER encoded?

Example input value:

6c91776d90126ce548ac1a399cc174383483d54874297d0f8d083aaXXXXXXXX

The output should be something like this:

302e020100300506032b657004220420xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

2
  • Please may you provide example expected output and your current approach as a text-based minimal reproducible example? Commented Aug 19, 2024 at 15:21
  • 1
    Yep, I added the expected output. The answer below works for me. Commented Aug 19, 2024 at 20:21

1 Answer 1

3

Create a script: convert.js

#!/usr/bin/env node import {PrivateKey} from "@hashgraph/sdk"; let hex = process.argv[2]; console.log(hex); let x = PrivateKey.fromStringED25519(hex); let der = x.toBytesDer(); let derhex = Buffer.from(der).toString('hex'); console.log(derhex); 

Run:

npm i 

Set "type": "module" in package.json

Run:

./convert.js 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.