From 44162811bd57afb89e5d052a2d9db25007cc1463 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Fri, 26 Jan 2018 09:40:42 -0800 Subject: Add order signing and dispensing ability to faucet --- packages/testnet-faucets/src/ts/id_management.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'packages/testnet-faucets/src/ts/id_management.ts') diff --git a/packages/testnet-faucets/src/ts/id_management.ts b/packages/testnet-faucets/src/ts/id_management.ts index db9b610a3..b088e6cf8 100644 --- a/packages/testnet-faucets/src/ts/id_management.ts +++ b/packages/testnet-faucets/src/ts/id_management.ts @@ -1,8 +1,10 @@ import EthereumTx = require('ethereumjs-tx'); +import * as ethUtil from 'ethereumjs-util'; +import * as _ from 'lodash'; import { configs } from './configs'; -type Callback = (err: Error | null, accounts: any) => void; +type Callback = (err: Error | null, result: any) => void; export const idManagement = { getAccounts(callback: Callback) { @@ -18,4 +20,16 @@ export const idManagement = { const rawTx = `0x${tx.serialize().toString('hex')}`; callback(null, rawTx); }, + signMessage(message: object, callback: Callback) { + const data = _.get(message, 'data'); + if (_.isUndefined(data)) { + callback(new Error('No data to sign'), null); + } + const privateKeyBuffer = new Buffer(configs.DISPENSER_PRIVATE_KEY as string, 'hex'); + const dataBuff = ethUtil.toBuffer(data); + const msgHashBuff = ethUtil.hashPersonalMessage(dataBuff); + const sig = ethUtil.ecsign(msgHashBuff, privateKeyBuffer); + const rpcSig = ethUtil.toRpcSig(sig.v, sig.r, sig.s); + callback(null, rpcSig); + }, }; -- cgit