Skip to content

Instantly share code, notes, and snippets.

@laalaguer
Created January 13, 2020 06:15
Show Gist options
  • Save laalaguer/1eaea9354eb2deba769a92296814e4f1 to your computer and use it in GitHub Desktop.
Save laalaguer/1eaea9354eb2deba769a92296814e4f1 to your computer and use it in GitHub Desktop.
How to generate a user signature
// Import library
const cry = require('thor-devkit/dist/cry')
const Transaction = require('thor-devkit/dist/transaction').Transaction
// User private key.
const originPriv = Buffer.from(
'2a0cbfe49ea7c18e89b87be4237e1717823fc16b52dc02e91fb30af122fba9b3',
'hex'
)
// User public address: 0x881Ab2380017870C49a9A114806C05F3CFE406e2
const originAddress = cry.publicKeyToAddress(cry.secp256k1.derivePublicKey(originPriv))
// Construct the hash for signing.
const originHash = tx.signingHash()
// Construct the user signature.
const originSignature = cry.secp256k1.sign(originHash, originPriv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment