Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!args.spend_transaction_id) {
throw new Error('ExpectedOutpointTxIdToSpend');
}
if (args.spend_vout === undefined) {
throw new Error('ExpectedOutpointVoutToSpend');
}
if (!args.tokens) {
throw new Error('ExpectedTokenCountToSend');
}
const network = networks[defaultNetwork];
const keyPair = ECPair.fromWIF(args.private_key, network);
const outputScript = toOutputScript(args.destination, network);
const tx = new Transaction();
const outpointHash = Buffer.from(args.spend_transaction_id, 'hex').reverse();
tx.addInput(outpointHash, args.spend_vout);
try {
tx.addOutput(outputScript, (args.tokens - (args.fee || 0)));
} catch (err) {
throw new Error('ErrorAddingOutputToSendOnChainTransaction');
}
const sigHashAll = parseInt(SIGHASH_ALL, hexBase);
[keyPair].forEach((signingKey, vin) => {
test('PrivateKeychain', function(t) {
t.plan(18)
let privateKeychain = new PrivateKeychain()
t.ok(privateKeychain instanceof PrivateKeychain, 'PrivateKeychain should have been created')
let privateKeychain2 = new PrivateKeychain('5Kd3NBUAdUnhyzenEwVLy9pBKxSwXvE9FMPyR4UKZvpe6E3AgLr')
t.ok(privateKeychain2, 'PrivateKeychain should have been created')
let privateKeychain3 = new PrivateKeychain(new ECPair.fromWIF('5Kd3NBUAdUnhyzenEwVLy9pBKxSwXvE9FMPyR4UKZvpe6E3AgLr'))
t.ok(privateKeychain3, 'PrivateKeychain should have been created')
t.equal(privateKeychain2.privateKey('hex'), privateKeychain3.privateKey('hex'), 'Private keys should be equal')
t.ok(privateKeychain.privateKey(), 'Private key should have been created')
t.ok(privateKeychain.wif(), 'Private key WIF should have been created')
let publicKeychain = privateKeychain.publicKeychain()
t.ok(publicKeychain instanceof PublicKeychain, 'Public Keychain should have been created')
let message = 'Hello, World!'
let signature = privateKeychain.sign(message)
t.ok(signature, 'Signature should have been created')
let messageVerified = publicKeychain.verify(message, signature)
t.ok(messageVerified, 'Message should have been verified')
export const importKeyPair = (s: string, networkName?: string): ECPair => ECPair.fromWIF(s, selectNetwork(networkName));
constructor(privateKey) {
if (!privateKey) {
this.ecPair = new ECPair.makeRandom({ rng: getEntropy })
} else {
if (privateKey instanceof ECPair) {
this.ecPair = privateKey
} else if (isWIF(privateKey)) {
this.ecPair = new ECPair.fromWIF(privateKey)
} else {
this.ecPair = new ECPair(privateKey, null, {})
}
}
}