scryptlib
Advanced tools
Comparing version 2.1.41 to 2.1.42
@@ -25,3 +25,3 @@ /// <reference types="node" /> | ||
export declare function hexStringToBytes(hex: string): number[]; | ||
export declare function signTx(tx: bsv.Transaction, privateKey: bsv.PrivateKey, lockingScript: Script, inputAmount: number, inputIndex?: number, sighashType?: number, flags?: number): string; | ||
export declare function signTx(tx: bsv.Transaction, privateKey: bsv.PrivateKey, lockingScript: Script, inputAmount: number, inputIndex?: number, sighashType?: number, flags?: number, hashCache?: bsv.HashCache): string; | ||
export declare function getPreimage(tx: bsv.Transaction, lockingScript: Script, inputAmount: number, inputIndex?: number, sighashType?: number, flags?: number): string; | ||
@@ -28,0 +28,0 @@ export declare function hashIsPositiveNumber(sighash: Buffer): boolean; |
@@ -202,3 +202,3 @@ "use strict"; | ||
exports.hexStringToBytes = hexStringToBytes; | ||
function signTx(tx, privateKey, lockingScript, inputAmount, inputIndex, sighashType, flags) { | ||
function signTx(tx, privateKey, lockingScript, inputAmount, inputIndex, sighashType, flags, hashCache) { | ||
if (inputIndex === void 0) { inputIndex = 0; } | ||
@@ -222,3 +222,3 @@ if (sighashType === void 0) { sighashType = exports.DEFAULT_SIGHASH_TYPE; } | ||
} | ||
return toHex(bsv.Transaction.Sighash.sign(tx, privateKey, sighashType, inputIndex, lockingScript, new bsv.crypto.BN(inputAmount), flags).toTxFormat()); | ||
return toHex(bsv.Transaction.Sighash.sign(tx, privateKey, sighashType, inputIndex, lockingScript, new bsv.crypto.BN(inputAmount), flags, hashCache).toTxFormat()); | ||
} | ||
@@ -225,0 +225,0 @@ exports.signTx = signTx; |
{ | ||
"name": "scryptlib", | ||
"version": "2.1.41", | ||
"version": "2.1.42", | ||
"description": "Javascript SDK for integration of Bitcoin SV Smart Contracts written in sCrypt language.", | ||
@@ -79,2 +79,2 @@ "engines": { | ||
} | ||
} | ||
} |
@@ -756,6 +756,2 @@ /* eslint-disable @typescript-eslint/ban-types */ | ||
class Point { | ||
constructor(x: crypto.BN | string, | ||
y: crypto.BN | string, | ||
isRed: boolean); | ||
static fromX(odd: boolean, x: crypto.BN | string): Point; | ||
@@ -768,9 +764,5 @@ static getG(): any; | ||
mul(n: crypto.BN): Point; | ||
add(n: crypto.Point): Point; | ||
neg(): Point; | ||
} | ||
class Signature { | ||
constructor(r: crypto.BN, s: crypto.BN); | ||
static fromDER(sig: Buffer): Signature; | ||
@@ -878,3 +870,4 @@ static fromTxFormat(buf: Buffer): Signature; | ||
satoshisBN: crypto.BN, | ||
flags?: number | ||
flags?: number, | ||
hashCache?: HashCache | ||
): Buffer; | ||
@@ -887,3 +880,4 @@ function sighash( | ||
satoshisBN: crypto.BN, | ||
flags?: number | ||
flags?: number, | ||
hashCache?: HashCache | ||
): Buffer; | ||
@@ -897,3 +891,4 @@ function sign( | ||
satoshisBN: crypto.BN, | ||
flags?: number | ||
flags?: number, | ||
hashCache?: HashCache | ||
): crypto.Signature; | ||
@@ -907,3 +902,4 @@ function verify( | ||
satoshisBN: crypto.BN, | ||
flags?: number | ||
flags?: number, | ||
hashCache?: HashCache | ||
): boolean; | ||
@@ -1495,2 +1491,18 @@ } | ||
} | ||
} | ||
export class HashCache { | ||
constructor( | ||
prevoutsHashBuf?: Buffer, | ||
sequenceHashBuf?: Buffer, | ||
outputsHashBuf?: Buffer | ||
) | ||
static fromBuffer(buf: Buffer): HashCache | ||
static fromJSON(json: object): HashCache | ||
static fromHex(hex: string): HashCache | ||
toBuffer(): HashCache | ||
toJSON(): HashCache | ||
toHex(): HashCache | ||
} | ||
} |
@@ -58,2 +58,3 @@ 'use strict' | ||
bsv.ECIES = require('./lib/ecies') | ||
bsv.HashCache = require('./lib/hash-cache') | ||
@@ -60,0 +61,0 @@ // dependencies, subject to change |
@@ -16,2 +16,3 @@ 'use strict' | ||
var _ = require('../util/_') | ||
var HashCache = require('../hash-cache') | ||
@@ -24,3 +25,3 @@ var SIGHASH_SINGLE_BUG = Buffer.from('0000000000000000000000000000000000000000000000000000000000000001', 'hex') | ||
var sighashPreimageForForkId = function (transaction, sighashType, inputNumber, subscript, satoshisBN) { | ||
var sighashPreimageForForkId = function (transaction, sighashType, inputNumber, subscript, satoshisBN, hashCache = new HashCache()) { | ||
var input = transaction.inputs[inputNumber] | ||
@@ -78,3 +79,3 @@ $.checkArgument( | ||
if (!(sighashType & Signature.SIGHASH_ANYONECANPAY)) { | ||
hashPrevouts = GetPrevoutHash(transaction) | ||
hashPrevouts = hashCache.prevoutsHashBuf ? hashCache.prevoutsHashBuf : hashCache.prevoutsHashBuf = GetPrevoutHash(transaction) | ||
} | ||
@@ -85,7 +86,7 @@ | ||
(sighashType & 31) !== Signature.SIGHASH_NONE) { | ||
hashSequence = GetSequenceHash(transaction) | ||
hashSequence = hashCache.sequenceHashBuf ? hashCache.sequenceHashBuf : hashCache.sequenceHashBuf = GetSequenceHash(transaction) | ||
} | ||
if ((sighashType & 31) !== Signature.SIGHASH_SINGLE && (sighashType & 31) !== Signature.SIGHASH_NONE) { | ||
hashOutputs = GetOutputsHash(transaction) | ||
hashOutputs = hashCache.outputsHashBuf ? hashCache.outputsHashBuf : hashCache.outputsHashBuf = GetOutputsHash(transaction) | ||
} else if ((sighashType & 31) === Signature.SIGHASH_SINGLE && inputNumber < transaction.outputs.length) { | ||
@@ -143,3 +144,3 @@ hashOutputs = GetOutputsHash(transaction, inputNumber) | ||
*/ | ||
var sighashPreimage = function sighashPreimage (transaction, sighashType, inputNumber, subscript, satoshisBN, flags) { | ||
var sighashPreimage = function sighashPreimage (transaction, sighashType, inputNumber, subscript, satoshisBN, flags, hashCache = new HashCache()) { | ||
var Transaction = require('./transaction') | ||
@@ -235,4 +236,4 @@ var Input = require('./input') | ||
*/ | ||
var sighash = function sighash (transaction, sighashType, inputNumber, subscript, satoshisBN, flags) { | ||
var preimage = sighashPreimage(transaction, sighashType, inputNumber, subscript, satoshisBN, flags) | ||
var sighash = function sighash (transaction, sighashType, inputNumber, subscript, satoshisBN, flags, hashCache = new HashCache()) { | ||
var preimage = sighashPreimage(transaction, sighashType, inputNumber, subscript, satoshisBN, flags, hashCache) | ||
if (preimage.compare(SIGHASH_SINGLE_BUG) === 0) return preimage | ||
@@ -256,4 +257,4 @@ var ret = Hash.sha256sha256(preimage) | ||
*/ | ||
function sign (transaction, privateKey, sighashType, inputIndex, subscript, satoshisBN, flags) { | ||
var hashbuf = sighash(transaction, sighashType, inputIndex, subscript, satoshisBN, flags) | ||
function sign (transaction, privateKey, sighashType, inputIndex, subscript, satoshisBN, flags, hashCache = new HashCache()) { | ||
var hashbuf = sighash(transaction, sighashType, inputIndex, subscript, satoshisBN, flags, hashCache) | ||
@@ -279,6 +280,6 @@ var sig = ECDSA.sign(hashbuf, privateKey, 'little').set({ | ||
*/ | ||
function verify (transaction, signature, publicKey, inputIndex, subscript, satoshisBN, flags) { | ||
function verify (transaction, signature, publicKey, inputIndex, subscript, satoshisBN, flags, hashCache = new HashCache()) { | ||
$.checkArgument(!_.isUndefined(transaction)) | ||
$.checkArgument(!_.isUndefined(signature) && !_.isUndefined(signature.nhashtype)) | ||
var hashbuf = sighash(transaction, signature.nhashtype, inputIndex, subscript, satoshisBN, flags) | ||
var hashbuf = sighash(transaction, signature.nhashtype, inputIndex, subscript, satoshisBN, flags, hashCache) | ||
return ECDSA.verify(hashbuf, signature, publicKey, 'little') | ||
@@ -285,0 +286,0 @@ } |
@@ -65,3 +65,2 @@ 'use strict' | ||
var DEFAULT_NLOCKTIME = 0 | ||
var MAX_BLOCK_SIZE = 1000000 | ||
@@ -1205,7 +1204,2 @@ // Minimum amount for an output for it not to be considered a dust output | ||
// Size limits | ||
if (this.toBuffer().length > MAX_BLOCK_SIZE) { | ||
return 'transaction over the maximum block size' | ||
} | ||
// Check for duplicate inputs | ||
@@ -1212,0 +1206,0 @@ var txinmap = {} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
978436
119
24118