Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrypt-ts: remove scryptType class, use type #211

Merged
merged 67 commits into from
Jan 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
4f6227c
add error log
Nov 17, 2022
be8178d
don't clean if output sourceMap
Nov 17, 2022
458214d
add bsv type
Nov 17, 2022
266f872
fix compileAsync
Nov 17, 2022
cadd53a
rename to isGenesis
Nov 18, 2022
720f0dc
pump version to 1.1.0-beta2
Nov 18, 2022
aa68904
add dependencies
Nov 23, 2022
e55a716
remove types/bsv
Dec 3, 2022
dc72584
update setInputScript
Dec 3, 2022
45ccc74
remove log
Dec 3, 2022
50bfd74
1.1.0-beta.4
Dec 3, 2022
21e6b96
update bsv
Dec 3, 2022
ae732c9
1.1.0-beta.5
Dec 3, 2022
3c05705
update bsv.d.ts
Dec 3, 2022
c42455b
1.1.0-beta.6
Dec 3, 2022
d635412
update bsv
Dec 4, 2022
3624991
update package-lock.json
Dec 4, 2022
40bd338
1.1.0-beta.7
Dec 4, 2022
d5c9f08
optimize cli
Dec 5, 2022
89af021
update bsv
Dec 5, 2022
10adf97
1.1.0-beta.8
Dec 5, 2022
ffc81e6
delete no use file
Dec 5, 2022
67663e7
don't exit when no compiler foud
Dec 5, 2022
42458be
1.1.0-beta.9
Dec 5, 2022
5e2b25e
Fix findcompile
Dec 5, 2022
6fab7d5
1.1.0-beta.10
Dec 5, 2022
f8f4244
bind scrypt compile version
Dec 5, 2022
fc3fab7
1.1.0-beta.11
Dec 5, 2022
9bac5f6
update bsv
Dec 5, 2022
dbceec1
rename
Dec 5, 2022
ac1696b
1.1.0-beta.12
Dec 5, 2022
95cb3cc
compile before publish
Dec 5, 2022
9817423
Fix buildtype error
Dec 6, 2022
84a9f3e
update bsv
Dec 6, 2022
502b439
add test
Dec 6, 2022
16b222d
1.1.0-beta.13
Dec 6, 2022
06e23b9
update bsv
Dec 7, 2022
a0c1437
remove FORKID from sighash flag
Dec 7, 2022
a3e87c0
add md5 function
Dec 8, 2022
3a3ad85
1.1.0-beta.14
Dec 8, 2022
60553e5
Fix ci
Dec 8, 2022
f297345
1.1.0-beta.14
Dec 8, 2022
4e6062a
Fix ci
Dec 8, 2022
00c64db
remove ScryptType class, use type
Dec 18, 2022
abbd3e9
2.0.0-beta.1
Dec 18, 2022
2fb2154
exclude findCompiler
Dec 18, 2022
bd89240
don't run boilerplate now
Dec 18, 2022
090de0d
refactor: add deserializer
Dec 19, 2022
16d6723
Fix export
Dec 19, 2022
5ee3cb7
2.0.0-beta.2
Dec 19, 2022
9878177
use param type, not argument type
Dec 20, 2022
58ac86b
2.0.0-beta.3
Dec 20, 2022
ee5d056
desc files are only contractname.json now
msinkec Dec 29, 2022
6d271a4
Renamed all occurences of desc to artifacts.
msinkec Dec 30, 2022
b6da9f8
update findKeyIndex
Jan 4, 2023
e35091a
2.0.0-beta.4
Jan 4, 2023
1be3cc1
Organized imports and some other fixes to make linting pass.
msinkec Jan 5, 2023
636c32b
Merge pull request #215 from msinkec/scrypt-ts
zhfnjust Jan 5, 2023
bb1c9fe
2.0.0-beta.5
Jan 6, 2023
736c9db
auto calc keyIndex
Jan 7, 2023
0a168e5
2.0.0-beta.6
Jan 7, 2023
b7e1d56
rename to getSortedItem
Jan 7, 2023
b64e19c
Fix genLaunchConfigFile
Jan 7, 2023
f2bcaa0
mirror fix
Jan 7, 2023
f83ad19
run bp test
Jan 8, 2023
5e87c0d
update readme
Jan 8, 2023
820ae9d
update change log
Jan 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update bsv
  • Loading branch information
hh committed Dec 4, 2022
commit d635412c0b7833c3f4c1bce72f7c75e31f6d0444
Binary file modified bsv.tar
Binary file not shown.
30 changes: 25 additions & 5 deletions patches/bsv/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,10 @@ declare module 'bsv' {
readonly satoshis: number;
readonly satoshisBN: crypto.BN;
spentTxId: string | null;
constructor(data: object);
constructor(data: {
script: Script,
satoshis: number
});

setScript(script: Script | string | Buffer): this;
inspect(): string;
Expand All @@ -362,12 +365,14 @@ declare module 'bsv' {
constructor(params: object);
isValidSignature(tx: Transaction, sig: any): boolean;
setScript(script: Script): this;
getSignatures(tx: Transaction, privateKey: PrivateKey, inputIndex: number, sigtype?: number): any;
getPreimage(tx: Transaction, inputIndex: number, sigtype?: number, isLowS?: boolean): any;
}


namespace Input {
class PublicKeyHash extends Input {

}
}

Expand Down Expand Up @@ -464,7 +469,7 @@ declare module 'bsv' {
getLockTime(): Date | number;
setLockTime(t: number): void;

verify(): string | boolean;
verify(): string | true;
isCoinbase(): boolean;

enableRBF(): this;
Expand All @@ -489,15 +494,30 @@ declare module 'bsv' {
privateKey?: PrivateKey,
sigtype?: number,
isLowS?: boolean
}, unlockingScript: Script | ((tx: Transaction, outputInPrevTx: Transaction.Output, preimage: string, signature: string) => Script)): this;
}, unlockingScript: Script | ((tx: Transaction, outputInPrevTx: Transaction.Output) => Script)): this;
setInputSequence(inputIndex: number, sequence: number): this;
setOutput(outputIndex: number, output: Transaction.Output | ((tx: Transaction) => Transaction.Output)): this;
seal(): void;
seal(): this;
isSealed(): boolean;
getChangeAmount(): number;
getEstimateFee(): number;
checkFeeRate(feePerKb?: number): boolean;
prevouts(): string;
getSignature(inputIndex: number, privateKey?: PrivateKey, sigtype?: number): string;
getPreimage(inputIndex: number, sigtype?: number, isLowS?: boolean): string;
addInputFromPrevTx(prevTx: Transaction, outputIndex?: number): this;
addDummyInput(script: Script, satoshis: number): this;
verifyInput(inputIndex: number, cb?: (execution: {
success: boolean,
error: string,
failedAt: any
}) => string): {
success: boolean,
error: string,
failedAt: any
};
getInputAmount(inputIndex: number): number;
getOutputAmount(outputIndex: number): number;
}

export class ECIES {
Expand Down
6 changes: 6 additions & 0 deletions patches/bsv/lib/errors/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ module.exports = [{
}, {
name: 'MissingPreviousOutput',
message: 'No previous output information.'
}, {
name: 'MissingInput',
message: 'Invalid inputIndex.'
}]
}, {
name: 'NeedMoreInfo',
Expand All @@ -88,6 +91,9 @@ module.exports = [{
}, {
name: 'DustOutputs',
message: 'Dust amount detected in one output'
}, {
name: 'MissingOutput',
message: 'Output not found'
}, {
name: 'InvalidSatoshis',
message: 'Output satoshis are invalid'
Expand Down
90 changes: 81 additions & 9 deletions patches/bsv/lib/transaction/input/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,32 @@ var JSUtil = require('../../util/js')
var Script = require('../../script')
var Sighash = require('../sighash')
var Output = require('../output')
var Signature = require('../../crypto/signature')
var TransactionSignature = require('../signature')
var Hash = require('../../crypto/hash')
var Interpreter = require('../../script/interpreter')
var Opcode = require('../../opcode')

var MAXINT = 0xffffffff // Math.pow(2, 32) - 1;
var DEFAULT_RBF_SEQNUMBER = MAXINT - 2
var DEFAULT_SEQNUMBER = MAXINT
var DEFAULT_LOCKTIME_SEQNUMBER = MAXINT - 1

function getLowSPreimage (tx, sigtype, inputIndex, inputLockingScript, inputAmount) {
var i = 0
do {
var preimage = Sighash.sighashPreimage(tx, sigtype, inputIndex, inputLockingScript, inputAmount)

var sighash = Hash.sha256sha256(preimage)

if (_.isPositiveNumber(sighash.readUInt8()) && _.isPositiveNumber(sighash.readUInt8(31))) {
return preimage
}

tx.nLockTime++
} while (i < Number.MAX_SAFE_INTEGER)
}

function Input (params) {
if (!(this instanceof Input)) {
return new Input(params)
Expand Down Expand Up @@ -146,17 +166,38 @@ Input.prototype.setScript = function (script) {
* @param {Transaction} transaction - the transaction to be signed
* @param {PrivateKey} privateKey - the private key to use when signing
* @param {number} inputIndex - the index of this input in the provided transaction
* @param {number} sigType - defaults to Signature.SIGHASH_ALL
* @param {Buffer} addressHash - if provided, don't calculate the hash of the
* public key associated with the private key provided
* @param {number} sigType - defaults to Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID
* @abstract
*/
Input.prototype.getSignatures = function (transaction, privateKey, inputIndex, sigtype) {
$.checkState(this.output instanceof Output)
sigtype = sigtype || (Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID)
return [new TransactionSignature({
publicKey: privateKey.publicKey,
prevTxId: this.prevTxId,
outputIndex: this.outputIndex,
inputIndex: inputIndex,
signature: Sighash.sign(transaction, privateKey, sigtype, inputIndex, this.output.script, this.output.satoshisBN),
sigtype: sigtype
})]
}

/**
* Retrieve preimage for the Input.
*
* @param {Transaction} transaction - the transaction to be signed
* @param {number} inputIndex - the index of this input in the provided transaction
* @param {number} sigType - defaults to Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID
* @param {boolean} isLowS - true if the sig hash is safe for low s.
* @abstract
*/
Input.prototype.getSignatures = function () {
// throw new errors.AbstractMethodInvoked(
// 'Trying to sign unsupported output type (only P2PKH and P2SH multisig inputs are supported)' +
// ' for input: ' + JSON.stringify(this)
// )
return []
Input.prototype.getPreimage = function (transaction, inputIndex, sigtype, isLowS) {
$.checkState(this.output instanceof Output)
sigtype = sigtype || (Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID)
isLowS = isLowS || false
return isLowS
? getLowSPreimage(transaction, sigtype, inputIndex, this.output.script, this.output.satoshisBN)
: Sighash.sighashPreimage(transaction, sigtype, inputIndex, this.output.script, this.output.satoshisBN)
}

Input.prototype.isFullySigned = function () {
Expand Down Expand Up @@ -200,4 +241,35 @@ Input.prototype._estimateSize = function () {
return this.toBufferWriter().toBuffer().length
}

Input.prototype.verify = function (transaction, inputIndex) {
$.checkState(this.output instanceof Output)
$.checkState(this.script instanceof Script)

var us = this.script
var ls = this.output.script
var inputSatoshis = this.output.satoshisBN

Interpreter.MAX_SCRIPT_ELEMENT_SIZE = Number.MAX_SAFE_INTEGER
Interpreter.MAXIMUM_ELEMENT_SIZE = Number.MAX_SAFE_INTEGER

const bsi = new Interpreter()

let failedAt = {}

bsi.stepListener = function (step) {
if (step.fExec || (Opcode.OP_IF <= step.opcode.toNumber() && step.opcode.toNumber() <= Opcode.OP_ENDIF)) {
if ((Opcode.OP_IF <= step.opcode.toNumber() && step.opcode.toNumber() <= Opcode.OP_ENDIF) || step.opcode.toNumber() === Opcode.OP_RETURN) /** Opreturn */ {
failedAt.opcode = step.opcode
} else {
failedAt = step
}
}
}

var success = bsi.verify(us, ls, transaction, inputIndex, Interpreter.DEFAULT_FLAGS, inputSatoshis)

failedAt.opcode = failedAt.opcode.toNumber()
return { success, error: bsi.errstr, failedAt: success ? {} : failedAt }
}

module.exports = Input
Loading