Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import {refundP2SHContract} from "../contract/refund-P2SH-contract"
const Script = require('bitcore').Script;
const Address = require('bitcore').Address;
import {getRawChangeAddress} from './rawRequest';
const Transaction = require('bitcore').Transaction;
import {extractAtomicSwapContract} from '../contract/extract-atomic-swap-contract';
import {createSig} from './createSig';
import {AddressUtil} from './address-util';
import {configuration} from "../config/config"
import {publishTx} from "./public-tx.js"
import {getFeePerKb} from './fee-per-kb';
import {feeForSerializeSize, estimateRefundSerializeSize} from './sizeest';
const BufferReader = require('bitcore').encoding.BufferReader;
export const buildRefund = async (strCt, strCtTx, privateKey) => {
console.log('buildRefund');
// TODO: change strCt, strCtTx to ct, ctTx
const contract = new Script(strCt);
const pushes = extractAtomicSwapContract(strCt)
if(!pushes){
console.log("contract is not an atomic swap script recognized by this tool");
return
}
const ctTx = new Transaction(strCtTx)
'use strict';
var bitcore = require('bitcore');
var BufferReader = bitcore.encoding.BufferReader;
var BufferWriter = bitcore.encoding.BufferWriter;
var Hash = bitcore.crypto.Hash;
//TODO: use bitcore.Block
function Block(obj) {
/* jshint maxstatements: 25 */
if (!(this instanceof Block)) {
return new Block(obj);
}
this.version = obj.version || 1;
this.prevHash = obj.prevHash;
if (!obj.hasOwnProperty('prevHash')) {
throw new TypeError('"prevHash" is expected');
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var Script = require('bitcore').Script;
var BufferReader = require('bitcore').encoding.BufferReader;
// redeemAtomicSwapSigScriptSize is the worst case (largest) serialize size
// of a transaction input script to redeem the atomic swap contract. This
// does not include final push for the contract itself.
//
// - OP_DATA_73
// - 72 bytes DER signature + 1 byte sighash
// - OP_DATA_33
// - 33 bytes serialized compressed pubkey
// - OP_DATA_32
// - 32 bytes secret
// - OP_TRUE
var redeemAtomicSwapSigScriptSize = 1 + 73 + 1 + 33 + 1 + 32 + 1;
// refundAtomicSwapSigScriptSize is the worst case (largest) serialize size
// of a transaction input script that refunds a P2SH atomic swap output.
import axios, {AxiosResponse} from "axios";
import * as RpcClient from "bitcoind-rpc";
import * as bitcore from "bitcore";
import {BtcRefundData} from "./atomic-swap";
import {BtcAtomicSwapContractData} from "./atomic-swap/btc-atomic-swap-contract-data";
import {BtcContractBuilder} from "./btc-contract-builder";
import {Util} from "./util";
import {BtcRpcConfiguration} from "../config/config";
const UnspentOutput = bitcore.Transaction.UnspentOutput;
const PrivateKey = bitcore.PrivateKey;
const Transaction = bitcore.Transaction;
const Address = bitcore.Address;
const Script = bitcore.Script;
const BufferReader = bitcore.encoding.BufferReader;
export class BtcTransaction {
protected configuration: any;
private rpc: any;
constructor(net) {
if (net === "testnet") {
this.configuration = BtcRpcConfiguration;
this.rpc = new RpcClient(BtcRpcConfiguration);
} else if (net === "mainnet") {
// TODO
}
}
/**
* Call RPC generic procedure with parameters
var _ = require('lodash');
var Bitcore = require('bitcore');
var PrivateKey = Bitcore.PrivateKey;
var PublicKey = Bitcore.PublicKey;
var Signature = Bitcore.crypto.Signature;
var ECDSA = Bitcore.crypto.ECDSA;
var Hash = Bitcore.crypto.Hash;
var BufferReader = Bitcore.encoding.BufferReader;
var SignUtils = function() {};
/* TODO: It would be nice to be compatible with bitcoind signmessage. How
* the hash is calculated there? */
SignUtils.hash = function(text) {
var buf = new Buffer(text);
var ret = Hash.sha256sha256(buf);
ret = new BufferReader(ret).readReverse();
return ret;
};
SignUtils.sign = function(text, privKey) {
'use strict';
var _ = require('lodash');
var $ = require('preconditions').singleton();
var sjcl = require('sjcl');
var Bitcore = require('bitcore');
var Address = Bitcore.Address;
var PrivateKey = Bitcore.PrivateKey;
var PublicKey = Bitcore.PublicKey;
var crypto = Bitcore.crypto;
var encoding = Bitcore.encoding;
var Utils = require('./utils');
function WalletUtils() {};
/* TODO: It would be nice to be compatible with bitcoind signmessage. How
* the hash is calculated there? */
WalletUtils.hashMessage = function(text) {
$.checkArgument(text);
var buf = new Buffer(text);
var ret = crypto.Hash.sha256sha256(buf);
ret = new Bitcore.encoding.BufferReader(ret).readReverse();
return ret;
};
WalletUtils.signMessage = function(text, privKey) {
'use strict';
var chai = require('chai');
var should = chai.should();
var sinon = require('sinon');
var bitcore = require('bitcore');
var BN = bitcore.crypto.BN;
var BufferWriter = bitcore.encoding.BufferWriter;
var BufferReader = bitcore.encoding.BufferReader;
var bitcoindjs = require('../');
var Block = bitcoindjs.Block;
var chainData = require('./data/pow-chain.json');
describe('Bitcoin Block', function() {
describe('@constructor', function() {
it('set bits and nonce', function() {
var block = new Block(chainData[1]);
should.exist(block.bits);
block.bits.should.equal(chainData[1].bits);
should.exist(block.nonce);
block.nonce.should.equal(chainData[1].nonce);
});
});
import {hash160Buffer} from './secret-hash';
const buffer = require('buffer');
const Base58Check = require('bitcore').encoding.Base58Check;
const Address = require('bitcore').Address;
export class AddressUtil {
static NewAddressPubKeyHash(hash, net) {
let netBuffer;
if (net === 'testnet') {
netBuffer = buffer.Buffer.from([0x6F]);
} else {
netBuffer = buffer.Buffer.from([0x00]);
}
const pkhBuffer = buffer.Buffer.from(hash, "hex");
const versionPayload = buffer.Buffer.concat([netBuffer, pkhBuffer], 21);
const encoded = Base58Check.encode(versionPayload);
return Address.fromString(encoded);
}
'use strict';
var bitcore = require('bitcore');
var BufferWriter = bitcore.encoding.BufferWriter;
var Hash = bitcore.crypto.Hash;
/**
* Base message that can be inherited to add an additional
* `getPayload` method to modify the message payload.
* @param {Object=} options
* @param {String=} options.command
* @param {Number=} options.magicNumber
* @constructor
*/
function Message(arg, options) {
this.command = options.command;
this.magicNumber = options.magicNumber;
}
/**
WalletUtils.hashMessage = function(text) {
$.checkArgument(text);
var buf = new Buffer(text);
var ret = crypto.Hash.sha256sha256(buf);
ret = new Bitcore.encoding.BufferReader(ret).readReverse();
return ret;
};