Skip to content

Instantly share code, notes, and snippets.

@laalaguer
Last active January 13, 2020 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laalaguer/cbedc4591a13e5ef6b7e14eb1d1bcaf3 to your computer and use it in GitHub Desktop.
Save laalaguer/cbedc4591a13e5ef6b7e14eb1d1bcaf3 to your computer and use it in GitHub Desktop.
sponsor using Express framework
const express = require('express')
const cry = require('thor-devkit/dist/cry')
const Transaction = require('thor-devkit/dist/transaction').Transaction
const app = express()
app.use(express.json())
const port = 3000
app.post('/', function(req, res) {
// Re-construct the transaction from the request.
const tx = new Transaction(req.body['txBody'])
// Extract 'sender' address from request.
const sender = req.body['sender']
// Compute the sponsor hash.
const sponsorHash = tx.signingHash(sender)
// Sponsor account (with money):
// 0x126cdb344f476f25b9fb2050513f425a82f71046
const sponsorPriv = Buffer.from(
'5df5e7f22a71dfd3d032ff5eb9dfc7dbe9c950e0671745826639a0423cd45d7f',
'hex'
)
// Compute the sponsor signature with hash+private key.
const signature = cry.secp256k1.sign(sponsorHash, sponsorPriv)
// Send back the signature.
res.send({
'sponsor_signature': signature.toString('hex')
})
})
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment