This example shows how to sign a transaction with your private key.
hash, signature, err := SignTx(key, address, amountStr, expire, seqId)
Params:
key
- ECDSA private key in hex. See belowaddress
- recipient address in0x1234...
formatamountStr
- transaction amount, as integerexpire
- timestamp when transaction should expire, see BigGo documentationseqId
- internal transaction sequence number, received fromtx/build
Result:
hash
- operationHash, hash of recipient, amount, expire and seqIdsignature
- signature of hash with the key
BitGo gives a key for Ethereum in "wallet" format. It is encrypted with password and looks like this:
{"iv":"XJSKS29eLUoF5FDCdg2g2Q==","v":1,"iter":10000,"ks":256,"ts":64,"mode"
:"ccm","adata":"","cipher":"aes","salt":"m2F+tC4jtTs=","ct":"XXfuUJD4XOvQTz
x0tJGye3T7TtNbiqFTwaLBNInukGdEoXeLZSpIcWWfhLg6LVmTdwz3tk41aqW9fbX2zh8/l/B1h
zXngBVf4QWM5Q2ZQHswva6LBhBzpGGcy6auRVDyxNcXm59db/oHUvw+59pdV2ZKpwogRh0="}
First we need to convert it to "xprv" format. We can do it with following JS code:
import { BitGoAPI } from '@bitgo/sdk-api';
const bitgo = new BitGoAPI({});
const key = '{"iv":"XJSKS29eLUoF5FDCdg2g2Q==","v":1,...';
const password = "secret-password";
const prv = bitgo.decrypt({ input: key, password });
Second, convert "xprv" to "raw" key
const { bip32 } = require('@bitgo/utxo-lib');
const ethUtil = require('ethereumjs-util');
const xprv = "xprv9s...";
const node = bip32.fromBase58(xprv);
const key = node.privateKey.toString('hex');