scryptlib
Advanced tools
Comparing version 2.0.3 to 2.0.4
# CHANGELOG | ||
## 2.0.4 | ||
- [Add `setInputScriptAsync`](https://github.com/sCrypt-Inc/scryptlib/blob/f2d269149002314c28fcdd1b15557e710e9a7a49/patches/bsv/index.d.ts#L511) | ||
- [Add `sealAsync`](https://github.com/sCrypt-Inc/scryptlib/blob/f2d269149002314c28fcdd1b15557e710e9a7a49/patches/bsv/index.d.ts#L519) | ||
## 2.0.3 | ||
@@ -5,0 +11,0 @@ |
export { buildContractClass, compile, compileAsync, compileContract, doCompileAsync, getPreimage, signTx, handleCompilerOutput, compileContractAsync, CompilingSettings } from './internal'; | ||
export { bsv, toHex, bin2num, int2Asm, bytes2Literal, bytesToHexString, getValidatedHexString, findStructByType, findStructByName, isArrayType, arrayTypeAndSize, newCall, getNameByType, genLaunchConfigFile, subArrayType, isGenericType, parseGenericType, readLaunchJson, getLowSPreimage, parseAbiFromUnlockingScript, findConstStatic, findStatic, resolveConstValue, arrayTypeAndSizeStr, toLiteralArrayType, librarySign, structSign, resolveGenericType, buildTypeResolver, getStructDeclaration, getABIDeclaration, typeOfArg, compilerVersion, parseLiteral, isEmpty, JSONParser, getFullFilePath, path2uri, uri2path, md5, FunctionCall, stringToBytes, isScryptType, isSubBytes, toJSON, getSortedItem } from './internal'; | ||
export { Int, Bool, Bytes, PrivKey, PubKey, Sig, Ripemd160, Sha1, Sha256, SigHashType, SigHashPreimage, OpCodeType, SupportedParamType, PubKeyHash, TxContext, ContractClass, Contract, SortedItem, HashedMap, HashedSet, StructObject, TypeResolver, PrimitiveTypes, AsmVarValues, Arguments, Argument, StructEntity, LibraryEntity, ABIEntity, ABIEntityType, ABI, ParamEntity, BuildType, RelatedInformation, ContractArtifact, VerifyResult, VerifyError, AbstractContract, DebugInfo, DebugModeTag, ContractEntity, TypeInfo, SymbolType, DEFAULT_FLAGS } from './internal'; | ||
export { Int, Bool, Bytes, PrivKey, PubKey, Sig, Ripemd160, Sha1, Sha256, SigHashType, SigHashPreimage, OpCodeType, SupportedParamType, PubKeyHash, TxContext, ContractClass, Contract, SortedItem, HashedMap, HashedSet, StructObject, TypeResolver, PrimitiveTypes, AsmVarValues, Arguments, Argument, StructEntity, LibraryEntity, ABIEntity, ABIEntityType, ABI, ParamEntity, BuildType, RelatedInformation, ContractArtifact, VerifyResult, VerifyError, AbstractContract, DebugInfo, DebugModeTag, ContractEntity, TypeInfo, SymbolType, DEFAULT_FLAGS, ScryptType } from './internal'; | ||
export { hash160, sha256, hash256, and, or, xor, invert, num2bin, buildOpreturnScript, len, buildPublicKeyHashScript, writeVarint, toLEUnsigned } from './internal'; | ||
export { getPlatformScryptc, findCompiler } from './internal'; | ||
export { partialSha256, sha256ByPartialHash } from './internal'; |
@@ -82,2 +82,3 @@ "use strict"; | ||
Object.defineProperty(exports, "DEFAULT_FLAGS", { enumerable: true, get: function () { return internal_3.DEFAULT_FLAGS; } }); | ||
Object.defineProperty(exports, "ScryptType", { enumerable: true, get: function () { return internal_3.ScryptType; } }); | ||
//Equivalent to the built-in functions | ||
@@ -84,0 +85,0 @@ var internal_4 = require("./internal"); |
@@ -96,7 +96,7 @@ "use strict"; | ||
function SigHashPreimage(b) { | ||
return getValidatedHexString(b); | ||
return getValidatedHexString(b, false); | ||
} | ||
exports.SigHashPreimage = SigHashPreimage; | ||
function OpCodeType(b) { | ||
return getValidatedHexString(b); | ||
return getValidatedHexString(b, false); | ||
} | ||
@@ -134,3 +134,3 @@ exports.OpCodeType = OpCodeType; | ||
// eslint-disable-next-line indent | ||
ScryptType.SIGHASHPREIMAGE, ScryptType.SIGHASHTYPE].map(t => t.toString()).includes(type); | ||
ScryptType.SIGHASHPREIMAGE, ScryptType.SIGHASHTYPE, 'PubKeyHash'].map(t => t.toString()).includes(type); | ||
} | ||
@@ -137,0 +137,0 @@ exports.isSubBytes = isSubBytes; |
{ | ||
"name": "scryptlib", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "Javascript SDK for integration of Bitcoin SV Smart Contracts written in sCrypt language.", | ||
@@ -5,0 +5,0 @@ "engines": { |
@@ -368,3 +368,3 @@ /* eslint-disable @typescript-eslint/ban-types */ | ||
toBufferWriter(writer?: encoding.BufferWriter): encoding.BufferWriter; | ||
static fromBufferReader(reader: encoding.BufferReader): Output; | ||
static fromBufferReader(reader: encoding.BufferReader): Output | ||
} | ||
@@ -511,6 +511,12 @@ | ||
isLowS?: boolean | ||
}, unlockingScript: Script | ((tx: Transaction, outputInPrevTx: Transaction.Output) => Script)): this; | ||
}, unlockingScript: Script | ((tx: Transaction, outputInPrevTx: Transaction.Output) => Script )): this; | ||
setInputScriptAsync(inputIndex: number | { | ||
inputIndex: number, | ||
sigtype?: number, | ||
isLowS?: boolean | ||
}, callback: (tx: Transaction, outputInPrevTx: Transaction.Output) => Promise<Script>): Promise<this>; | ||
setInputSequence(inputIndex: number, sequence: number): this; | ||
setOutput(outputIndex: number, output: Transaction.Output | ((tx: Transaction) => Transaction.Output)): this; | ||
seal(): this; | ||
sealAsync(): Promise<this>; | ||
isSealed(): boolean; | ||
@@ -517,0 +523,0 @@ getChangeAmount(): number; |
@@ -1282,2 +1282,44 @@ 'use strict' | ||
/** | ||
* | ||
* @param {number | object} inputIndex or option | ||
* @param {(tx, output) => Promise<Script>} callback a callback returns a unlocking script | ||
* @returns A promise which resolves to unlockScript of the special input | ||
*/ | ||
Transaction.prototype.setInputScriptAsync = async function (options, callback) { | ||
var inputIndex = 0 | ||
var sigtype | ||
var isLowS = false | ||
if (typeof options === 'number') { | ||
inputIndex = options | ||
sigtype = Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID | ||
} else { | ||
inputIndex = options.inputIndex || 0 | ||
sigtype = options.sigtype || (Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID) | ||
isLowS = options.isLowS || false | ||
} | ||
if (callback instanceof Function) { | ||
var outputInPrevTx = this.inputs[inputIndex].output | ||
var preimage = this.inputs[inputIndex].getPreimage(this, inputIndex, options.sigtype, isLowS) | ||
this._preimagesMap.set(inputIndex, preimage) | ||
this._inputsMap.set(inputIndex, { | ||
sigtype, | ||
isLowS, | ||
callback | ||
}) | ||
var self = this | ||
var unlockScript = await callback(self, outputInPrevTx) | ||
this.inputs[inputIndex].setScript(unlockScript) | ||
} else { | ||
throw new errors.InvalidArgument('Must provide a callback returns a unlocking script') | ||
} | ||
this._updateChangeOutput() | ||
return this | ||
} | ||
Transaction.prototype.setInputSequence = function (inputIndex, sequence) { | ||
@@ -1342,2 +1384,43 @@ this.inputs[inputIndex].sequenceNumber = sequence | ||
/** | ||
* Seal a transaction asynchronously. After the transaction is sealed, except for the unlock script entered, | ||
* other attributes of the transaction cannot be modified | ||
*/ | ||
Transaction.prototype.sealAsync = async function () { | ||
var self = this | ||
this._outputsMap.forEach(function (callback, key) { | ||
self.outputs[key] = callback(self) | ||
}) | ||
var promises = [] | ||
this._inputsMap.forEach(function (options, key) { | ||
var outputInPrevTx = self.inputs[key].output | ||
var preimage = self.inputs[key].getPreimage(self, key, options.sigtype, options.isLowS) | ||
self._preimagesMap.set(key, preimage) | ||
promises.push( | ||
Promise.resolve(options.callback(self, outputInPrevTx)).then(unlockScript => { | ||
return { key, unlockScript } | ||
}) | ||
) | ||
}) | ||
await Promise.all(promises).then(items => { | ||
items.forEach(({ key, unlockScript }) => { | ||
self.inputs[key].setScript(unlockScript) | ||
}) | ||
}) | ||
if (this._privateKey) { | ||
this.sign(this._privateKey, this._sigType) | ||
} | ||
this.sealed = true | ||
return this | ||
} | ||
Transaction.prototype.setLockTime = function (nLockTime) { | ||
@@ -1344,0 +1427,0 @@ this.nLockTime = nLockTime |
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
927952
22697