-
-
Save fede-rodes/985c389af69e9711aae619018b4506af to your computer and use it in GitHub Desktop.
sponsor using Express framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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