@bsv/sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/ISSUE_TEMPLATE/bug_report.md +40 -0
- package/.github/ISSUE_TEMPLATE/discussion.md +24 -0
- package/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md +23 -0
- package/CHANGELOG.md +72 -0
- package/CONTRIBUTING.md +85 -0
- package/LICENSE.txt +28 -0
- package/README.md +87 -0
- package/ROADMAP.md +3 -0
- package/dist/cjs/mod.js +25 -0
- package/dist/cjs/mod.js.map +1 -0
- package/dist/cjs/package.json +42 -0
- package/dist/cjs/src/compat/BIP39.js +272 -0
- package/dist/cjs/src/compat/BIP39.js.map +1 -0
- package/dist/cjs/src/compat/BSM.js +77 -0
- package/dist/cjs/src/compat/BSM.js.map +1 -0
- package/dist/cjs/src/compat/ECIES.js +483 -0
- package/dist/cjs/src/compat/ECIES.js.map +1 -0
- package/dist/cjs/src/compat/HD.js +326 -0
- package/dist/cjs/src/compat/HD.js.map +1 -0
- package/dist/cjs/src/compat/Mnemonic.js +298 -0
- package/dist/cjs/src/compat/Mnemonic.js.map +1 -0
- package/dist/cjs/src/compat/bip-39-wordlist-en.js +2057 -0
- package/dist/cjs/src/compat/bip-39-wordlist-en.js.map +1 -0
- package/dist/cjs/src/compat/index.js +37 -0
- package/dist/cjs/src/compat/index.js.map +1 -0
- package/dist/cjs/src/messages/EncryptedMessage.js +69 -0
- package/dist/cjs/src/messages/EncryptedMessage.js.map +1 -0
- package/dist/cjs/src/messages/SignedMessage.js +85 -0
- package/dist/cjs/src/messages/SignedMessage.js.map +1 -0
- package/dist/cjs/src/messages/index.js +29 -0
- package/dist/cjs/src/messages/index.js.map +1 -0
- package/dist/cjs/src/primitives/AESGCM.js +384 -0
- package/dist/cjs/src/primitives/AESGCM.js.map +1 -0
- package/dist/cjs/src/primitives/BasePoint.js +19 -0
- package/dist/cjs/src/primitives/BasePoint.js.map +1 -0
- package/dist/cjs/src/primitives/BigNumber.js +4269 -0
- package/dist/cjs/src/primitives/BigNumber.js.map +1 -0
- package/dist/cjs/src/primitives/Curve.js +1126 -0
- package/dist/cjs/src/primitives/Curve.js.map +1 -0
- package/dist/cjs/src/primitives/DRBG.js +99 -0
- package/dist/cjs/src/primitives/DRBG.js.map +1 -0
- package/dist/cjs/src/primitives/ECDSA.js +169 -0
- package/dist/cjs/src/primitives/ECDSA.js.map +1 -0
- package/dist/cjs/src/primitives/Hash.js +1332 -0
- package/dist/cjs/src/primitives/Hash.js.map +1 -0
- package/dist/cjs/src/primitives/JacobianPoint.js +400 -0
- package/dist/cjs/src/primitives/JacobianPoint.js.map +1 -0
- package/dist/cjs/src/primitives/K256.js +111 -0
- package/dist/cjs/src/primitives/K256.js.map +1 -0
- package/dist/cjs/src/primitives/Mersenne.js +118 -0
- package/dist/cjs/src/primitives/Mersenne.js.map +1 -0
- package/dist/cjs/src/primitives/MontgomoryMethod.js +150 -0
- package/dist/cjs/src/primitives/MontgomoryMethod.js.map +1 -0
- package/dist/cjs/src/primitives/Point.js +819 -0
- package/dist/cjs/src/primitives/Point.js.map +1 -0
- package/dist/cjs/src/primitives/PrivateKey.js +190 -0
- package/dist/cjs/src/primitives/PrivateKey.js.map +1 -0
- package/dist/cjs/src/primitives/PublicKey.js +151 -0
- package/dist/cjs/src/primitives/PublicKey.js.map +1 -0
- package/dist/cjs/src/primitives/Random.js +57 -0
- package/dist/cjs/src/primitives/Random.js.map +1 -0
- package/dist/cjs/src/primitives/ReductionContext.js +490 -0
- package/dist/cjs/src/primitives/ReductionContext.js.map +1 -0
- package/dist/cjs/src/primitives/Signature.js +220 -0
- package/dist/cjs/src/primitives/Signature.js.map +1 -0
- package/dist/cjs/src/primitives/SymmetricKey.js +69 -0
- package/dist/cjs/src/primitives/SymmetricKey.js.map +1 -0
- package/dist/cjs/src/primitives/TransactionSignature.js +172 -0
- package/dist/cjs/src/primitives/TransactionSignature.js.map +1 -0
- package/dist/cjs/src/primitives/index.js +45 -0
- package/dist/cjs/src/primitives/index.js.map +1 -0
- package/dist/cjs/src/primitives/utils.js +615 -0
- package/dist/cjs/src/primitives/utils.js.map +1 -0
- package/dist/cjs/src/script/LockingScript.js +35 -0
- package/dist/cjs/src/script/LockingScript.js.map +1 -0
- package/dist/cjs/src/script/OP.js +208 -0
- package/dist/cjs/src/script/OP.js.map +1 -0
- package/dist/cjs/src/script/Script.js +429 -0
- package/dist/cjs/src/script/Script.js.map +1 -0
- package/dist/cjs/src/script/ScriptChunk.js +3 -0
- package/dist/cjs/src/script/ScriptChunk.js.map +1 -0
- package/dist/cjs/src/script/ScriptTemplate.js +3 -0
- package/dist/cjs/src/script/ScriptTemplate.js.map +1 -0
- package/dist/cjs/src/script/Spend.js +1252 -0
- package/dist/cjs/src/script/Spend.js.map +1 -0
- package/dist/cjs/src/script/UnlockingScript.js +35 -0
- package/dist/cjs/src/script/UnlockingScript.js.map +1 -0
- package/dist/cjs/src/script/index.js +32 -0
- package/dist/cjs/src/script/index.js.map +1 -0
- package/dist/cjs/src/script/templates/P2PKH.js +98 -0
- package/dist/cjs/src/script/templates/P2PKH.js.map +1 -0
- package/dist/cjs/src/script/templates/RPuzzle.js +125 -0
- package/dist/cjs/src/script/templates/RPuzzle.js.map +1 -0
- package/dist/cjs/src/script/templates/index.js +11 -0
- package/dist/cjs/src/script/templates/index.js.map +1 -0
- package/dist/cjs/src/transaction/Broadcaster.js +3 -0
- package/dist/cjs/src/transaction/Broadcaster.js.map +1 -0
- package/dist/cjs/src/transaction/ChainTracker.js +3 -0
- package/dist/cjs/src/transaction/ChainTracker.js.map +1 -0
- package/dist/cjs/src/transaction/FeeModel.js +3 -0
- package/dist/cjs/src/transaction/FeeModel.js.map +1 -0
- package/dist/cjs/src/transaction/MerklePath.js +239 -0
- package/dist/cjs/src/transaction/MerklePath.js.map +1 -0
- package/dist/cjs/src/transaction/Transaction.js +557 -0
- package/dist/cjs/src/transaction/Transaction.js.map +1 -0
- package/dist/cjs/src/transaction/TransactionInput.js +3 -0
- package/dist/cjs/src/transaction/TransactionInput.js.map +1 -0
- package/dist/cjs/src/transaction/TransactionOutput.js +3 -0
- package/dist/cjs/src/transaction/TransactionOutput.js.map +1 -0
- package/dist/cjs/src/transaction/broadcasters/ARC.js +101 -0
- package/dist/cjs/src/transaction/broadcasters/ARC.js.map +1 -0
- package/dist/cjs/src/transaction/broadcasters/index.js +9 -0
- package/dist/cjs/src/transaction/broadcasters/index.js.map +1 -0
- package/dist/cjs/src/transaction/fee-models/SatoshisPerKilobyte.js +69 -0
- package/dist/cjs/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -0
- package/dist/cjs/src/transaction/fee-models/index.js +9 -0
- package/dist/cjs/src/transaction/fee-models/index.js.map +1 -0
- package/dist/cjs/src/transaction/index.js +11 -0
- package/dist/cjs/src/transaction/index.js.map +1 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/esm/mod.js +9 -0
- package/dist/esm/mod.js.map +1 -0
- package/dist/esm/src/compat/BIP39.js +272 -0
- package/dist/esm/src/compat/BIP39.js.map +1 -0
- package/dist/esm/src/compat/BSM.js +45 -0
- package/dist/esm/src/compat/BSM.js.map +1 -0
- package/dist/esm/src/compat/ECIES.js +454 -0
- package/dist/esm/src/compat/ECIES.js.map +1 -0
- package/dist/esm/src/compat/HD.js +304 -0
- package/dist/esm/src/compat/HD.js.map +1 -0
- package/dist/esm/src/compat/Mnemonic.js +272 -0
- package/dist/esm/src/compat/Mnemonic.js.map +1 -0
- package/dist/esm/src/compat/bip-39-wordlist-en.js +2054 -0
- package/dist/esm/src/compat/bip-39-wordlist-en.js.map +1 -0
- package/dist/esm/src/compat/index.js +5 -0
- package/dist/esm/src/compat/index.js.map +1 -0
- package/dist/esm/src/messages/EncryptedMessage.js +61 -0
- package/dist/esm/src/messages/EncryptedMessage.js.map +1 -0
- package/dist/esm/src/messages/SignedMessage.js +77 -0
- package/dist/esm/src/messages/SignedMessage.js.map +1 -0
- package/dist/esm/src/messages/index.js +3 -0
- package/dist/esm/src/messages/index.js.map +1 -0
- package/dist/esm/src/primitives/AESGCM.js +371 -0
- package/dist/esm/src/primitives/AESGCM.js.map +1 -0
- package/dist/esm/src/primitives/BasePoint.js +16 -0
- package/dist/esm/src/primitives/BasePoint.js.map +1 -0
- package/dist/esm/src/primitives/BigNumber.js +4304 -0
- package/dist/esm/src/primitives/BigNumber.js.map +1 -0
- package/dist/esm/src/primitives/Curve.js +1141 -0
- package/dist/esm/src/primitives/Curve.js.map +1 -0
- package/dist/esm/src/primitives/DRBG.js +98 -0
- package/dist/esm/src/primitives/DRBG.js.map +1 -0
- package/dist/esm/src/primitives/ECDSA.js +161 -0
- package/dist/esm/src/primitives/ECDSA.js.map +1 -0
- package/dist/esm/src/primitives/Hash.js +1336 -0
- package/dist/esm/src/primitives/Hash.js.map +1 -0
- package/dist/esm/src/primitives/JacobianPoint.js +398 -0
- package/dist/esm/src/primitives/JacobianPoint.js.map +1 -0
- package/dist/esm/src/primitives/K256.js +105 -0
- package/dist/esm/src/primitives/K256.js.map +1 -0
- package/dist/esm/src/primitives/Mersenne.js +117 -0
- package/dist/esm/src/primitives/Mersenne.js.map +1 -0
- package/dist/esm/src/primitives/MontgomoryMethod.js +149 -0
- package/dist/esm/src/primitives/MontgomoryMethod.js.map +1 -0
- package/dist/esm/src/primitives/Point.js +816 -0
- package/dist/esm/src/primitives/Point.js.map +1 -0
- package/dist/esm/src/primitives/PrivateKey.js +184 -0
- package/dist/esm/src/primitives/PrivateKey.js.map +1 -0
- package/dist/esm/src/primitives/PublicKey.js +145 -0
- package/dist/esm/src/primitives/PublicKey.js.map +1 -0
- package/dist/esm/src/primitives/Random.js +56 -0
- package/dist/esm/src/primitives/Random.js.map +1 -0
- package/dist/esm/src/primitives/ReductionContext.js +486 -0
- package/dist/esm/src/primitives/ReductionContext.js.map +1 -0
- package/dist/esm/src/primitives/Signature.js +223 -0
- package/dist/esm/src/primitives/Signature.js.map +1 -0
- package/dist/esm/src/primitives/SymmetricKey.js +63 -0
- package/dist/esm/src/primitives/SymmetricKey.js.map +1 -0
- package/dist/esm/src/primitives/TransactionSignature.js +144 -0
- package/dist/esm/src/primitives/TransactionSignature.js.map +1 -0
- package/dist/esm/src/primitives/index.js +9 -0
- package/dist/esm/src/primitives/index.js.map +1 -0
- package/dist/esm/src/primitives/utils.js +601 -0
- package/dist/esm/src/primitives/utils.js.map +1 -0
- package/dist/esm/src/script/LockingScript.js +29 -0
- package/dist/esm/src/script/LockingScript.js.map +1 -0
- package/dist/esm/src/script/OP.js +206 -0
- package/dist/esm/src/script/OP.js.map +1 -0
- package/dist/esm/src/script/Script.js +424 -0
- package/dist/esm/src/script/Script.js.map +1 -0
- package/dist/esm/src/script/ScriptChunk.js +2 -0
- package/dist/esm/src/script/ScriptChunk.js.map +1 -0
- package/dist/esm/src/script/ScriptTemplate.js +2 -0
- package/dist/esm/src/script/ScriptTemplate.js.map +1 -0
- package/dist/esm/src/script/Spend.js +1240 -0
- package/dist/esm/src/script/Spend.js.map +1 -0
- package/dist/esm/src/script/UnlockingScript.js +29 -0
- package/dist/esm/src/script/UnlockingScript.js.map +1 -0
- package/dist/esm/src/script/index.js +7 -0
- package/dist/esm/src/script/index.js.map +1 -0
- package/dist/esm/src/script/templates/P2PKH.js +92 -0
- package/dist/esm/src/script/templates/P2PKH.js.map +1 -0
- package/dist/esm/src/script/templates/RPuzzle.js +119 -0
- package/dist/esm/src/script/templates/RPuzzle.js.map +1 -0
- package/dist/esm/src/script/templates/index.js +3 -0
- package/dist/esm/src/script/templates/index.js.map +1 -0
- package/dist/esm/src/transaction/Broadcaster.js +2 -0
- package/dist/esm/src/transaction/Broadcaster.js.map +1 -0
- package/dist/esm/src/transaction/ChainTracker.js +2 -0
- package/dist/esm/src/transaction/ChainTracker.js.map +1 -0
- package/dist/esm/src/transaction/FeeModel.js +2 -0
- package/dist/esm/src/transaction/FeeModel.js.map +1 -0
- package/dist/esm/src/transaction/MerklePath.js +237 -0
- package/dist/esm/src/transaction/MerklePath.js.map +1 -0
- package/dist/esm/src/transaction/Transaction.js +557 -0
- package/dist/esm/src/transaction/Transaction.js.map +1 -0
- package/dist/esm/src/transaction/TransactionInput.js +2 -0
- package/dist/esm/src/transaction/TransactionInput.js.map +1 -0
- package/dist/esm/src/transaction/TransactionOutput.js +2 -0
- package/dist/esm/src/transaction/TransactionOutput.js.map +1 -0
- package/dist/esm/src/transaction/broadcasters/ARC.js +100 -0
- package/dist/esm/src/transaction/broadcasters/ARC.js.map +1 -0
- package/dist/esm/src/transaction/broadcasters/index.js +2 -0
- package/dist/esm/src/transaction/broadcasters/index.js.map +1 -0
- package/dist/esm/src/transaction/fee-models/SatoshisPerKilobyte.js +71 -0
- package/dist/esm/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -0
- package/dist/esm/src/transaction/fee-models/index.js +2 -0
- package/dist/esm/src/transaction/fee-models/index.js.map +1 -0
- package/dist/esm/src/transaction/index.js +3 -0
- package/dist/esm/src/transaction/index.js.map +1 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -0
- package/dist/types/mod.d.ts +9 -0
- package/dist/types/mod.d.ts.map +1 -0
- package/dist/types/src/compat/BIP39.d.ts +132 -0
- package/dist/types/src/compat/BIP39.d.ts.map +1 -0
- package/dist/types/src/compat/BSM.d.ts +28 -0
- package/dist/types/src/compat/BSM.d.ts.map +1 -0
- package/dist/types/src/compat/ECIES.d.ts +62 -0
- package/dist/types/src/compat/ECIES.d.ts.map +1 -0
- package/dist/types/src/compat/HD.d.ts +117 -0
- package/dist/types/src/compat/HD.d.ts.map +1 -0
- package/dist/types/src/compat/Mnemonic.d.ts +132 -0
- package/dist/types/src/compat/Mnemonic.d.ts.map +1 -0
- package/dist/types/src/compat/bip-39-wordlist-en.d.ts +5 -0
- package/dist/types/src/compat/bip-39-wordlist-en.d.ts.map +1 -0
- package/dist/types/src/compat/index.d.ts +5 -0
- package/dist/types/src/compat/index.d.ts.map +1 -0
- package/dist/types/src/messages/EncryptedMessage.d.ts +20 -0
- package/dist/types/src/messages/EncryptedMessage.d.ts.map +1 -0
- package/dist/types/src/messages/SignedMessage.d.ts +21 -0
- package/dist/types/src/messages/SignedMessage.d.ts.map +1 -0
- package/dist/types/src/messages/index.d.ts +3 -0
- package/dist/types/src/messages/index.d.ts.map +1 -0
- package/dist/types/src/primitives/AESGCM.d.ts +14 -0
- package/dist/types/src/primitives/AESGCM.d.ts.map +1 -0
- package/dist/types/src/primitives/BasePoint.d.ts +22 -0
- package/dist/types/src/primitives/BasePoint.d.ts.map +1 -0
- package/dist/types/src/primitives/BigNumber.d.ts +1895 -0
- package/dist/types/src/primitives/BigNumber.d.ts.map +1 -0
- package/dist/types/src/primitives/Curve.d.ts +55 -0
- package/dist/types/src/primitives/Curve.d.ts.map +1 -0
- package/dist/types/src/primitives/DRBG.d.ts +54 -0
- package/dist/types/src/primitives/DRBG.d.ts.map +1 -0
- package/dist/types/src/primitives/ECDSA.d.ts +39 -0
- package/dist/types/src/primitives/ECDSA.d.ts.map +1 -0
- package/dist/types/src/primitives/Hash.d.ts +411 -0
- package/dist/types/src/primitives/Hash.d.ts.map +1 -0
- package/dist/types/src/primitives/JacobianPoint.d.ts +164 -0
- package/dist/types/src/primitives/JacobianPoint.d.ts.map +1 -0
- package/dist/types/src/primitives/K256.d.ts +53 -0
- package/dist/types/src/primitives/K256.d.ts.map +1 -0
- package/dist/types/src/primitives/Mersenne.d.ts +72 -0
- package/dist/types/src/primitives/Mersenne.d.ts.map +1 -0
- package/dist/types/src/primitives/MontgomoryMethod.d.ts +96 -0
- package/dist/types/src/primitives/MontgomoryMethod.d.ts.map +1 -0
- package/dist/types/src/primitives/Point.d.ts +303 -0
- package/dist/types/src/primitives/Point.d.ts.map +1 -0
- package/dist/types/src/primitives/PrivateKey.d.ts +143 -0
- package/dist/types/src/primitives/PrivateKey.d.ts.map +1 -0
- package/dist/types/src/primitives/PublicKey.d.ts +108 -0
- package/dist/types/src/primitives/PublicKey.d.ts.map +1 -0
- package/dist/types/src/primitives/Random.d.ts +14 -0
- package/dist/types/src/primitives/Random.d.ts.map +1 -0
- package/dist/types/src/primitives/ReductionContext.d.ts +308 -0
- package/dist/types/src/primitives/ReductionContext.d.ts.map +1 -0
- package/dist/types/src/primitives/Signature.d.ts +100 -0
- package/dist/types/src/primitives/Signature.d.ts.map +1 -0
- package/dist/types/src/primitives/SymmetricKey.d.ts +44 -0
- package/dist/types/src/primitives/SymmetricKey.d.ts.map +1 -0
- package/dist/types/src/primitives/TransactionSignature.d.ts +36 -0
- package/dist/types/src/primitives/TransactionSignature.d.ts.map +1 -0
- package/dist/types/src/primitives/index.d.ts +9 -0
- package/dist/types/src/primitives/index.d.ts.map +1 -0
- package/dist/types/src/primitives/utils.d.ts +118 -0
- package/dist/types/src/primitives/utils.d.ts.map +1 -0
- package/dist/types/src/script/LockingScript.d.ts +25 -0
- package/dist/types/src/script/LockingScript.d.ts.map +1 -0
- package/dist/types/src/script/OP.d.ts +193 -0
- package/dist/types/src/script/OP.d.ts.map +1 -0
- package/dist/types/src/script/Script.d.ts +148 -0
- package/dist/types/src/script/Script.d.ts.map +1 -0
- package/dist/types/src/script/ScriptChunk.d.ts +8 -0
- package/dist/types/src/script/ScriptChunk.d.ts.map +1 -0
- package/dist/types/src/script/ScriptTemplate.d.ts +33 -0
- package/dist/types/src/script/ScriptTemplate.d.ts.map +1 -0
- package/dist/types/src/script/Spend.d.ts +103 -0
- package/dist/types/src/script/Spend.d.ts.map +1 -0
- package/dist/types/src/script/UnlockingScript.d.ts +25 -0
- package/dist/types/src/script/UnlockingScript.d.ts.map +1 -0
- package/dist/types/src/script/index.d.ts +8 -0
- package/dist/types/src/script/index.d.ts.map +1 -0
- package/dist/types/src/script/templates/P2PKH.d.ts +37 -0
- package/dist/types/src/script/templates/P2PKH.d.ts.map +1 -0
- package/dist/types/src/script/templates/RPuzzle.d.ts +47 -0
- package/dist/types/src/script/templates/RPuzzle.d.ts.map +1 -0
- package/dist/types/src/script/templates/index.d.ts +3 -0
- package/dist/types/src/script/templates/index.d.ts.map +1 -0
- package/dist/types/src/transaction/Broadcaster.d.ts +39 -0
- package/dist/types/src/transaction/Broadcaster.d.ts.map +1 -0
- package/dist/types/src/transaction/ChainTracker.d.ts +23 -0
- package/dist/types/src/transaction/ChainTracker.d.ts.map +1 -0
- package/dist/types/src/transaction/FeeModel.d.ts +12 -0
- package/dist/types/src/transaction/FeeModel.d.ts.map +1 -0
- package/dist/types/src/transaction/MerklePath.d.ts +91 -0
- package/dist/types/src/transaction/MerklePath.d.ts.map +1 -0
- package/dist/types/src/transaction/Transaction.d.ts +181 -0
- package/dist/types/src/transaction/Transaction.d.ts.map +1 -0
- package/dist/types/src/transaction/TransactionInput.d.ts +63 -0
- package/dist/types/src/transaction/TransactionInput.d.ts.map +1 -0
- package/dist/types/src/transaction/TransactionOutput.d.ts +36 -0
- package/dist/types/src/transaction/TransactionOutput.d.ts.map +1 -0
- package/dist/types/src/transaction/broadcasters/ARC.d.ts +28 -0
- package/dist/types/src/transaction/broadcasters/ARC.d.ts.map +1 -0
- package/dist/types/src/transaction/broadcasters/index.d.ts +2 -0
- package/dist/types/src/transaction/broadcasters/index.d.ts.map +1 -0
- package/dist/types/src/transaction/fee-models/SatoshisPerKilobyte.d.ts +26 -0
- package/dist/types/src/transaction/fee-models/SatoshisPerKilobyte.d.ts.map +1 -0
- package/dist/types/src/transaction/fee-models/index.d.ts +2 -0
- package/dist/types/src/transaction/fee-models/index.d.ts.map +1 -0
- package/dist/types/src/transaction/index.d.ts +7 -0
- package/dist/types/src/transaction/index.d.ts.map +1 -0
- package/dist/types/tsconfig.types.tsbuildinfo +1 -0
- package/docs/README.md +9 -0
- package/docs/compat.md +2856 -0
- package/docs/getting-started/COMMONJS.md +94 -0
- package/docs/getting-started/REACT-TS.md +131 -0
- package/docs/getting-started/TS-NODE.md +106 -0
- package/docs/getting-started/VUE.md +103 -0
- package/docs/messages.md +146 -0
- package/docs/primitives.md +7440 -0
- package/docs/script.md +766 -0
- package/docs/transaction.md +741 -0
- package/jest.config.js +6 -0
- package/mod.ts +8 -0
- package/package.json +137 -0
- package/src/compat/BSM.ts +51 -0
- package/src/compat/ECIES.ts +557 -0
- package/src/compat/HD.ts +348 -0
- package/src/compat/Mnemonic.ts +295 -0
- package/src/compat/__tests/BSM.test.ts +38 -0
- package/src/compat/__tests/ECIES.test.ts +90 -0
- package/src/compat/__tests/HD.test.ts +405 -0
- package/src/compat/__tests/Mnemonic.test.ts +177 -0
- package/src/compat/__tests/Mnemonic.vectors.ts +172 -0
- package/src/compat/bip-39-wordlist-en.ts +2053 -0
- package/src/compat/index.ts +4 -0
- package/src/messages/EncryptedMessage.ts +70 -0
- package/src/messages/SignedMessage.ts +87 -0
- package/src/messages/__tests/EncryptedMessage.test.ts +36 -0
- package/src/messages/__tests/SignedMessage.test.ts +53 -0
- package/src/messages/index.ts +2 -0
- package/src/primitives/AESGCM.ts +479 -0
- package/src/primitives/BasePoint.ts +21 -0
- package/src/primitives/BigNumber.ts +4619 -0
- package/src/primitives/Curve.ts +1163 -0
- package/src/primitives/DRBG.ts +102 -0
- package/src/primitives/ECDSA.ts +164 -0
- package/src/primitives/Hash.ts +1420 -0
- package/src/primitives/JacobianPoint.ts +410 -0
- package/src/primitives/K256.ts +116 -0
- package/src/primitives/Mersenne.ts +123 -0
- package/src/primitives/MontgomoryMethod.ts +160 -0
- package/src/primitives/Point.ts +852 -0
- package/src/primitives/PrivateKey.ts +195 -0
- package/src/primitives/PublicKey.ts +154 -0
- package/src/primitives/Random.ts +55 -0
- package/src/primitives/ReductionContext.ts +528 -0
- package/src/primitives/Signature.ts +235 -0
- package/src/primitives/SymmetricKey.ts +75 -0
- package/src/primitives/TransactionSignature.ts +189 -0
- package/src/primitives/__tests/AESGCM.test.ts +338 -0
- package/src/primitives/__tests/BRC42.private.vectors.ts +33 -0
- package/src/primitives/__tests/BRC42.public.vectors.ts +33 -0
- package/src/primitives/__tests/BigNumber.arithmatic.test.ts +572 -0
- package/src/primitives/__tests/BigNumber.binary.test.ts +203 -0
- package/src/primitives/__tests/BigNumber.constructor.test.ts +176 -0
- package/src/primitives/__tests/BigNumber.dhGroup.test.ts +18 -0
- package/src/primitives/__tests/BigNumber.fixtures.ts +264 -0
- package/src/primitives/__tests/BigNumber.serializers.test.ts +157 -0
- package/src/primitives/__tests/BigNumber.utils.test.ts +347 -0
- package/src/primitives/__tests/Curve.unit.test.ts +192 -0
- package/src/primitives/__tests/DRBG.test.ts +18 -0
- package/src/primitives/__tests/DRBG.vectors.ts +167 -0
- package/src/primitives/__tests/ECDH.test.ts +31 -0
- package/src/primitives/__tests/ECDSA.test.ts +58 -0
- package/src/primitives/__tests/HMAC.test.ts +59 -0
- package/src/primitives/__tests/Hash.test.ts +121 -0
- package/src/primitives/__tests/PBKDF2.vectors.ts +119 -0
- package/src/primitives/__tests/PrivateKey.test.ts +17 -0
- package/src/primitives/__tests/PublicKey.test.ts +66 -0
- package/src/primitives/__tests/Random.test.ts +14 -0
- package/src/primitives/__tests/Reader.test.ts +296 -0
- package/src/primitives/__tests/ReductionContext.test.ts +279 -0
- package/src/primitives/__tests/SymmetricKey.test.ts +58 -0
- package/src/primitives/__tests/SymmetricKey.vectors.ts +40 -0
- package/src/primitives/__tests/Writer.test.ts +198 -0
- package/src/primitives/__tests/sighash.vectors.ts +3503 -0
- package/src/primitives/__tests/utils.test.ts +108 -0
- package/src/primitives/index.ts +8 -0
- package/src/primitives/utils.ts +665 -0
- package/src/script/LockingScript.ts +30 -0
- package/src/script/OP.ts +219 -0
- package/src/script/Script.ts +426 -0
- package/src/script/ScriptChunk.ts +7 -0
- package/src/script/ScriptTemplate.ts +36 -0
- package/src/script/Spend.ts +1379 -0
- package/src/script/UnlockingScript.ts +30 -0
- package/src/script/__tests/Script.test.ts +369 -0
- package/src/script/__tests/Spend.test.ts +248 -0
- package/src/script/__tests/script.invalid.vectors.ts +925 -0
- package/src/script/__tests/script.valid.vectors.ts +1120 -0
- package/src/script/__tests/scriptFromVector.ts +42 -0
- package/src/script/__tests/spend.valid.vectors.ts +2288 -0
- package/src/script/index.ts +7 -0
- package/src/script/templates/P2PKH.ts +109 -0
- package/src/script/templates/RPuzzle.ts +140 -0
- package/src/script/templates/index.ts +2 -0
- package/src/transaction/Broadcaster.ts +42 -0
- package/src/transaction/ChainTracker.ts +22 -0
- package/src/transaction/FeeModel.ts +13 -0
- package/src/transaction/MerklePath.ts +259 -0
- package/src/transaction/Transaction.ts +602 -0
- package/src/transaction/TransactionInput.ts +63 -0
- package/src/transaction/TransactionOutput.ts +37 -0
- package/src/transaction/__tests/MerklePath.test.ts +181 -0
- package/src/transaction/__tests/Transaction.test.ts +413 -0
- package/src/transaction/__tests/bigtx.vectors.ts +4 -0
- package/src/transaction/__tests/bump.invalid.vectors.ts +8 -0
- package/src/transaction/__tests/bump.valid.vectors.ts +4 -0
- package/src/transaction/__tests/tx.invalid.vectors.ts +281 -0
- package/src/transaction/__tests/tx.valid.vectors.ts +364 -0
- package/src/transaction/broadcasters/ARC.ts +106 -0
- package/src/transaction/broadcasters/__tests/ARC.test.ts +115 -0
- package/src/transaction/broadcasters/index.ts +1 -0
- package/src/transaction/fee-models/SatoshisPerKilobyte.ts +71 -0
- package/src/transaction/fee-models/index.ts +1 -0
- package/src/transaction/index.ts +6 -0
- package/ts2md.json +5 -0
- package/tsconfig.base.json +26 -0
- package/tsconfig.cjs.json +11 -0
- package/tsconfig.eslint.json +12 -0
- package/tsconfig.esm.json +9 -0
- package/tsconfig.json +17 -0
- package/tsconfig.types.json +11 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import Script from './Script.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The UnlockingScript class represents an unlocking script in a Bitcoin SV transaction.
|
|
5
|
+
* It extends the Script class and is used specifically for input scripts that unlock funds.
|
|
6
|
+
*
|
|
7
|
+
* Inherits all properties and methods from the Script class.
|
|
8
|
+
*
|
|
9
|
+
* @extends {Script}
|
|
10
|
+
* @see {@link Script} for more information on Script.
|
|
11
|
+
*/
|
|
12
|
+
export default class UnlockingScript extends Script {
|
|
13
|
+
/**
|
|
14
|
+
* @method isLockingScript
|
|
15
|
+
* Determines if the script is a locking script.
|
|
16
|
+
* @returns {boolean} Always returns false for an UnlockingScript instance.
|
|
17
|
+
*/
|
|
18
|
+
isLockingScript (): boolean {
|
|
19
|
+
return false
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @method isUnlockingScript
|
|
24
|
+
* Determines if the script is an unlocking script.
|
|
25
|
+
* @returns {boolean} Always returns true for an UnlockingScript instance.
|
|
26
|
+
*/
|
|
27
|
+
isUnlockingScript (): boolean {
|
|
28
|
+
return true
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
import Script from '../../../dist/cjs/src/script/Script'
|
|
2
|
+
import OP from '../../../dist/cjs/src/script/OP'
|
|
3
|
+
import { toHex } from '../../../dist/cjs/src/primitives/utils'
|
|
4
|
+
import scriptFromVector from './scriptFromVector'
|
|
5
|
+
|
|
6
|
+
import scriptInvalid from './script.invalid.vectors'
|
|
7
|
+
import scriptValid from './script.valid.vectors'
|
|
8
|
+
|
|
9
|
+
describe('Script', () => {
|
|
10
|
+
it('should make a new script', () => {
|
|
11
|
+
const script = new Script()
|
|
12
|
+
expect(script).toBeDefined()
|
|
13
|
+
expect(new Script().toASM()).toEqual('')
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
describe('fromHex', () => {
|
|
17
|
+
it('should parse this hex string containing an OP code', () => {
|
|
18
|
+
const buf = Buffer.alloc(1)
|
|
19
|
+
buf[0] = OP.OP_0
|
|
20
|
+
const script = Script.fromHex(buf.toString('hex'))
|
|
21
|
+
expect(script.chunks).toHaveLength(1)
|
|
22
|
+
expect(script.chunks[0].op).toBe(buf[0])
|
|
23
|
+
})
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
describe('fromBinary', () => {
|
|
27
|
+
it('should parse this buffer containing an OP code', () => {
|
|
28
|
+
const buf = Buffer.alloc(1)
|
|
29
|
+
buf[0] = OP.OP_0
|
|
30
|
+
const script = Script.fromBinary(buf)
|
|
31
|
+
expect(script.chunks).toHaveLength(1)
|
|
32
|
+
expect(script.chunks[0].op).toBe(buf[0])
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('should parse this buffer containing another OP code', () => {
|
|
36
|
+
const buf = Buffer.alloc(1)
|
|
37
|
+
buf[0] = OP.OP_CHECKMULTISIG
|
|
38
|
+
const script = Script.fromBinary(buf)
|
|
39
|
+
expect(script.chunks).toHaveLength(1)
|
|
40
|
+
expect(script.chunks[0].op).toBe(buf[0])
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('should parse this buffer containing three bytes of data', () => {
|
|
44
|
+
const buf = ([3, 1, 2, 3])
|
|
45
|
+
const script = Script.fromBinary(buf)
|
|
46
|
+
expect(script.chunks).toHaveLength(1)
|
|
47
|
+
expect(script.chunks[0].data).toEqual([1, 2, 3])
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it('should parse this buffer containing OP_PUSHDATA1 and zero bytes of data', () => {
|
|
51
|
+
const buf = ([0])
|
|
52
|
+
buf[0] = OP.OP_PUSHDATA1
|
|
53
|
+
const script = Script.fromBinary(buf)
|
|
54
|
+
expect(script.chunks.length).toEqual(1)
|
|
55
|
+
expect(script.chunks[0].data).toEqual([])
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('should parse this buffer containing OP_PUSHDATA2 and zero bytes of data', () => {
|
|
59
|
+
const buf = ([0])
|
|
60
|
+
buf[0] = OP.OP_PUSHDATA2
|
|
61
|
+
const script = Script.fromBinary(buf)
|
|
62
|
+
expect(script.chunks.length).toEqual(1)
|
|
63
|
+
expect(script.chunks[0].data).toEqual([])
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('should parse this buffer containing OP_PUSHDATA2 and three bytes of data', () => {
|
|
67
|
+
const buf = ([OP.OP_PUSHDATA2, 3, 0, 1, 2, 3])
|
|
68
|
+
const script = Script.fromBinary(buf)
|
|
69
|
+
expect(script.chunks.length).toEqual(1)
|
|
70
|
+
expect(script.chunks[0].data).toEqual([1, 2, 3])
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
it('should parse this buffer containing OP_PUSHDATA4 and zero bytes of data', () => {
|
|
74
|
+
const buf = ([0, 0])
|
|
75
|
+
buf[0] = OP.OP_PUSHDATA4
|
|
76
|
+
const script = Script.fromBinary(buf)
|
|
77
|
+
expect(script.chunks.length).toEqual(1)
|
|
78
|
+
expect(script.chunks[0].data).toEqual([])
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('should parse this buffer containing OP_PUSHDATA4 and three bytes of data', () => {
|
|
82
|
+
const buf = [OP.OP_PUSHDATA4, 3, 0, 0, 0, 1, 2, 3]
|
|
83
|
+
const script = Script.fromBinary(buf)
|
|
84
|
+
expect(script.chunks.length).toEqual(1)
|
|
85
|
+
expect(script.chunks[0].data).toEqual([1, 2, 3])
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('should parse this buffer an OP code, data, and another OP code', () => {
|
|
89
|
+
const buf = [OP.OP_0, OP.OP_PUSHDATA4, 3, 0, 0, 0, 1, 2, 3, OP.OP_0]
|
|
90
|
+
const script = Script.fromBinary(buf)
|
|
91
|
+
expect(script.chunks.length).toEqual(3)
|
|
92
|
+
expect(script.chunks[0].op).toEqual(buf[0])
|
|
93
|
+
expect(script.chunks[1].data).toEqual([1, 2, 3])
|
|
94
|
+
expect(script.chunks[2].op).toEqual(buf[buf.length - 1])
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('should output this hex string containing an OP code', () => {
|
|
98
|
+
const buf = Buffer.alloc(1)
|
|
99
|
+
buf[0] = OP.OP_0
|
|
100
|
+
const script = Script.fromHex(buf.toString('hex'))
|
|
101
|
+
expect(script.chunks.length).toEqual(1)
|
|
102
|
+
expect(script.chunks[0].op).toEqual(buf[0])
|
|
103
|
+
expect(script.toHex()).toEqual(buf.toString('hex'))
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
it('should output this buffer containing an OP code', () => {
|
|
107
|
+
const buf = Buffer.alloc(1)
|
|
108
|
+
buf[0] = OP.OP_0
|
|
109
|
+
const script = Script.fromBinary(buf)
|
|
110
|
+
expect(script.chunks.length).toEqual(1)
|
|
111
|
+
expect(script.chunks[0].op).toEqual(buf[0])
|
|
112
|
+
expect(script.toHex()).toEqual(buf.toString('hex'))
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
it('should output this buffer containing another OP code', () => {
|
|
116
|
+
const buf = Buffer.alloc(1)
|
|
117
|
+
buf[0] = OP.OP_CHECKMULTISIG
|
|
118
|
+
const script = Script.fromBinary(buf)
|
|
119
|
+
expect(script.chunks.length).toEqual(1)
|
|
120
|
+
expect(script.chunks[0].op).toEqual(buf[0])
|
|
121
|
+
expect(script.toHex()).toEqual(buf.toString('hex'))
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
it('should output this buffer containing three bytes of data', () => {
|
|
125
|
+
const buf = Buffer.from([3, 1, 2, 3])
|
|
126
|
+
const script = Script.fromBinary(buf)
|
|
127
|
+
expect(script.chunks.length).toEqual(1)
|
|
128
|
+
expect(script.chunks[0].data).toEqual([1, 2, 3])
|
|
129
|
+
expect(script.toHex()).toEqual(buf.toString('hex'))
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
it('should output this buffer containing OP_PUSHDATA1 and three bytes of data', () => {
|
|
133
|
+
const buf = Buffer.from([0, 0, 1, 2, 3])
|
|
134
|
+
buf[0] = OP.OP_PUSHDATA1
|
|
135
|
+
buf.writeUInt8(3, 1)
|
|
136
|
+
const script = Script.fromBinary(buf)
|
|
137
|
+
expect(script.chunks.length).toEqual(1)
|
|
138
|
+
expect(script.chunks[0].data).toEqual([1, 2, 3])
|
|
139
|
+
expect(script.toHex()).toEqual(buf.toString('hex'))
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
it('should output this buffer containing OP_PUSHDATA2 and three bytes of data', () => {
|
|
143
|
+
const buf = Buffer.from([0, 0, 0, 1, 2, 3])
|
|
144
|
+
buf[0] = OP.OP_PUSHDATA2
|
|
145
|
+
buf.writeUInt16LE(3, 1)
|
|
146
|
+
const script = Script.fromBinary(buf)
|
|
147
|
+
expect(script.chunks.length).toEqual(1)
|
|
148
|
+
expect(script.chunks[0].data).toEqual([1, 2, 3])
|
|
149
|
+
expect(script.toHex()).toEqual(buf.toString('hex'))
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
it('should output this buffer containing OP_PUSHDATA4 and three bytes of data', () => {
|
|
153
|
+
const buf = Buffer.from([0, 0, 0, 0, 0, 1, 2, 3])
|
|
154
|
+
buf[0] = OP.OP_PUSHDATA4
|
|
155
|
+
buf.writeUInt16LE(3, 1)
|
|
156
|
+
const script = Script.fromBinary(buf)
|
|
157
|
+
expect(script.chunks.length).toEqual(1)
|
|
158
|
+
expect(script.chunks[0].data).toEqual([1, 2, 3])
|
|
159
|
+
expect(script.toHex()).toEqual(buf.toString('hex'))
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
it('should output this buffer an OP code, data, and another OP code', () => {
|
|
163
|
+
const buf = Buffer.from([0, 0, 0, 0, 0, 0, 1, 2, 3, 0])
|
|
164
|
+
buf[0] = OP.OP_0
|
|
165
|
+
buf[1] = OP.OP_PUSHDATA4
|
|
166
|
+
buf.writeUInt16LE(3, 2)
|
|
167
|
+
buf[buf.length - 1] = OP.OP_0
|
|
168
|
+
const script = Script.fromBinary(buf)
|
|
169
|
+
expect(script.chunks.length).toEqual(3)
|
|
170
|
+
expect(script.chunks[0].op).toEqual(buf[0])
|
|
171
|
+
expect(script.chunks[1].data).toEqual([1, 2, 3])
|
|
172
|
+
expect(script.chunks[2].op).toEqual(buf[buf.length - 1])
|
|
173
|
+
expect(script.toHex()).toEqual(buf.toString('hex'))
|
|
174
|
+
})
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
describe('toASM', () => {
|
|
178
|
+
it('should output this buffer an OP code, data, and another OP code', () => {
|
|
179
|
+
const buf = Buffer.from([0, 0, 0, 0, 0, 0, 1, 2, 3, 0])
|
|
180
|
+
buf[0] = OP.OP_0
|
|
181
|
+
buf[1] = OP.OP_PUSHDATA4
|
|
182
|
+
buf.writeUInt16LE(3, 2)
|
|
183
|
+
buf[buf.length - 1] = OP.OP_0
|
|
184
|
+
const script = Script.fromBinary(buf)
|
|
185
|
+
expect(script.chunks.length).toEqual(3)
|
|
186
|
+
expect(script.chunks[0].op).toEqual(buf[0])
|
|
187
|
+
expect(script.chunks[1].data).toEqual([1, 2, 3])
|
|
188
|
+
expect(script.chunks[2].op).toEqual(buf[buf.length - 1])
|
|
189
|
+
expect(script.toASM()).toEqual('OP_0 010203 OP_0')
|
|
190
|
+
})
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
describe('fromASM', () => {
|
|
194
|
+
it('should parse these known scripts', () => {
|
|
195
|
+
expect(Script.fromASM('OP_0 010203 OP_0')
|
|
196
|
+
.toASM()
|
|
197
|
+
).toEqual('OP_0 010203 OP_0')
|
|
198
|
+
expect(Script.fromASM(
|
|
199
|
+
'OP_DUP OP_HASH160 1451baa3aad777144a0759998a03538018dd7b4b OP_EQUALVERIFY OP_CHECKSIG'
|
|
200
|
+
).toASM()).toEqual(
|
|
201
|
+
'OP_DUP OP_HASH160 1451baa3aad777144a0759998a03538018dd7b4b OP_EQUALVERIFY OP_CHECKSIG'
|
|
202
|
+
)
|
|
203
|
+
expect(Script.fromASM(
|
|
204
|
+
'OP_SHA256 8cc17e2a2b10e1da145488458a6edec4a1fdb1921c2d5ccbc96aa0ed31b4d5f8 OP_EQUALVERIFY OP_DUP OP_HASH160 1451baa3aad777144a0759998a03538018dd7b4b OP_EQUALVERIFY OP_CHECKSIGVERIFY OP_EQUALVERIFY OP_DUP OP_HASH160 1451baa3aad777144a0759998a03538018dd7b4b OP_EQUALVERIFY OP_CHECKSIG'
|
|
205
|
+
).toASM()).toEqual(
|
|
206
|
+
'OP_SHA256 8cc17e2a2b10e1da145488458a6edec4a1fdb1921c2d5ccbc96aa0ed31b4d5f8 OP_EQUALVERIFY OP_DUP OP_HASH160 1451baa3aad777144a0759998a03538018dd7b4b OP_EQUALVERIFY OP_CHECKSIGVERIFY OP_EQUALVERIFY OP_DUP OP_HASH160 1451baa3aad777144a0759998a03538018dd7b4b OP_EQUALVERIFY OP_CHECKSIG'
|
|
207
|
+
)
|
|
208
|
+
expect(Script.fromASM('OP_0 010203 OP_0')
|
|
209
|
+
.toASM()
|
|
210
|
+
).toEqual('OP_0 010203 OP_0')
|
|
211
|
+
expect(Script.fromASM('OP_0 010203 OP_0')
|
|
212
|
+
.toASM()
|
|
213
|
+
).toEqual('OP_0 010203 OP_0')
|
|
214
|
+
expect(Script.fromASM('OP_0 3 010203 OP_0').toASM()).toEqual('OP_0 03 010203 OP_0')
|
|
215
|
+
expect(Script.fromASM('').toASM()).toEqual('')
|
|
216
|
+
})
|
|
217
|
+
it('should parse this known script in ASM', () => {
|
|
218
|
+
const asm = 'OP_DUP OP_HASH160 f4c03610e60ad15100929cc23da2f3a799af1725 OP_EQUALVERIFY OP_CHECKSIG'
|
|
219
|
+
const script = Script.fromASM(asm)
|
|
220
|
+
expect(script.chunks[0].op).toEqual(OP.OP_DUP)
|
|
221
|
+
expect(script.chunks[1].op).toEqual(OP.OP_HASH160)
|
|
222
|
+
expect(script.chunks[2].op).toEqual(20)
|
|
223
|
+
expect(toHex(script.chunks[2].data)).toEqual('f4c03610e60ad15100929cc23da2f3a799af1725')
|
|
224
|
+
expect(script.chunks[3].op).toEqual(OP.OP_EQUALVERIFY)
|
|
225
|
+
expect(script.chunks[4].op).toEqual(OP.OP_CHECKSIG)
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
it('should parse this known problematic script in ASM', () => {
|
|
229
|
+
const asm = 'OP_RETURN 026d02 0568656c6c6f'
|
|
230
|
+
const script = Script.fromASM(asm)
|
|
231
|
+
expect(script.toASM()).toEqual(asm)
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
it('should know this is invalid hex', () => {
|
|
235
|
+
const asm = 'OP_RETURN 026d02 0568656c6c6fzz'
|
|
236
|
+
|
|
237
|
+
const createScript = () => {
|
|
238
|
+
const script = Script.fromASM(asm)
|
|
239
|
+
return script.toASM()
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Expect the function to throw an error with the specified message
|
|
243
|
+
expect(createScript).toThrow('invalid hex string in script')
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
it('should parse this long PUSHDATA1 script in ASM', () => {
|
|
247
|
+
const buf = Buffer.alloc(220, 0)
|
|
248
|
+
const asm = 'OP_RETURN ' + buf.toString('hex')
|
|
249
|
+
const script = Script.fromASM(asm)
|
|
250
|
+
expect(script.chunks[1].op).toEqual(OP.OP_PUSHDATA1)
|
|
251
|
+
expect(script.toASM()).toEqual(asm)
|
|
252
|
+
})
|
|
253
|
+
|
|
254
|
+
it('should parse this long PUSHDATA2 script in ASM', () => {
|
|
255
|
+
const buf = Buffer.alloc(1024, 0)
|
|
256
|
+
const asm = 'OP_RETURN ' + buf.toString('hex')
|
|
257
|
+
const script = Script.fromASM(asm)
|
|
258
|
+
expect(script.chunks[1].op).toEqual(OP.OP_PUSHDATA2)
|
|
259
|
+
expect(script.toASM()).toEqual(asm)
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
it('should parse this long PUSHDATA4 script in ASM', () => {
|
|
263
|
+
const buf = Buffer.alloc(Math.pow(2, 17), 0)
|
|
264
|
+
const asm = 'OP_RETURN ' + buf.toString('hex')
|
|
265
|
+
const script = Script.fromASM(asm)
|
|
266
|
+
expect(script.chunks[1].op).toEqual(OP.OP_PUSHDATA4)
|
|
267
|
+
expect(script.toASM()).toEqual(asm)
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
it('should return this script correctly', () => {
|
|
271
|
+
const asm1 = 'OP_FALSE'
|
|
272
|
+
const asm2 = 'OP_0'
|
|
273
|
+
const asm3 = '0'
|
|
274
|
+
expect(Script.fromASM(asm1).toASM()).toEqual(asm2)
|
|
275
|
+
expect(Script.fromASM(asm2).toASM()).toEqual(asm2)
|
|
276
|
+
expect(Script.fromASM(asm3).toASM()).toEqual(asm2)
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
it('should return this script correctly', () => {
|
|
280
|
+
const asm1 = 'OP_1NEGATE'
|
|
281
|
+
const asm2 = '-1'
|
|
282
|
+
expect(Script.fromASM(asm1).toASM()).toEqual(asm1)
|
|
283
|
+
expect(Script.fromASM(asm2).toASM()).toEqual(asm1)
|
|
284
|
+
})
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
describe('#removeCodeseparators', () => {
|
|
288
|
+
it('should remove any OP_CODESEPARATORs', () => {
|
|
289
|
+
expect(Script.fromASM('OP_CODESEPARATOR OP_0 OP_CODESEPARATOR')
|
|
290
|
+
.removeCodeseparators()
|
|
291
|
+
.toASM()).toEqual('OP_0')
|
|
292
|
+
})
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
describe('#isPushOnly', () => {
|
|
296
|
+
it("should know these scripts are or aren't push only", () => {
|
|
297
|
+
expect(Script.fromASM('OP_0').isPushOnly()).toEqual(true)
|
|
298
|
+
expect(Script.fromASM('OP_0 OP_RETURN').isPushOnly()).toEqual(false)
|
|
299
|
+
expect(Script.fromASM('OP_PUSHDATA1 5 1010101010').isPushOnly()).toEqual(true)
|
|
300
|
+
|
|
301
|
+
// like bitcoind, we regard OP_RESERVED as being "push only"
|
|
302
|
+
expect(Script.fromASM('OP_RESERVED').isPushOnly()).toEqual(true)
|
|
303
|
+
})
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
describe('#findAndDelete', () => {
|
|
307
|
+
it('should find and delete this buffer', () => {
|
|
308
|
+
expect(Script
|
|
309
|
+
.fromASM('OP_RETURN f0f0')
|
|
310
|
+
.findAndDelete(Script.fromASM('f0f0'))
|
|
311
|
+
.toASM()).toEqual('OP_RETURN')
|
|
312
|
+
})
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
describe('vectors', () => {
|
|
316
|
+
scriptValid.forEach((a, i) => {
|
|
317
|
+
if (a.length === 1) {
|
|
318
|
+
return
|
|
319
|
+
}
|
|
320
|
+
it(`should not fail when reading scriptValid vector ${i}`, () => {
|
|
321
|
+
expect(() => {
|
|
322
|
+
scriptFromVector(a[0]).toHex()
|
|
323
|
+
scriptFromVector(a[0]).toASM()
|
|
324
|
+
}).not.toThrow()
|
|
325
|
+
|
|
326
|
+
expect(() => {
|
|
327
|
+
scriptFromVector(a[1]).toHex()
|
|
328
|
+
scriptFromVector(a[1]).toASM()
|
|
329
|
+
}).not.toThrow()
|
|
330
|
+
|
|
331
|
+
// should be able to return the same output over and over
|
|
332
|
+
let str = scriptFromVector(a[0]).toASM()
|
|
333
|
+
expect(Script.fromASM(str).toASM()).toEqual(str)
|
|
334
|
+
str = scriptFromVector(a[1]).toASM()
|
|
335
|
+
expect(Script.fromASM(str).toASM()).toEqual(str)
|
|
336
|
+
})
|
|
337
|
+
})
|
|
338
|
+
|
|
339
|
+
scriptInvalid.forEach((a, i) => {
|
|
340
|
+
if (a.length === 1) {
|
|
341
|
+
return
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
it(`should not fail when reading scriptInvalid vector ${i}`, () => {
|
|
345
|
+
// Test that no errors are thrown for the first item
|
|
346
|
+
expect(() => {
|
|
347
|
+
const scriptA = scriptFromVector(a[0])
|
|
348
|
+
scriptA.toHex()
|
|
349
|
+
scriptA.toASM()
|
|
350
|
+
}).not.toThrow()
|
|
351
|
+
|
|
352
|
+
// Test that no errors are thrown for the second item
|
|
353
|
+
expect(() => {
|
|
354
|
+
const scriptB = scriptFromVector(a[1])
|
|
355
|
+
scriptB.toHex()
|
|
356
|
+
scriptB.toASM()
|
|
357
|
+
}).not.toThrow()
|
|
358
|
+
|
|
359
|
+
// Test that it should be able to return the same output over and over for the first item
|
|
360
|
+
const strA = scriptFromVector(a[0]).toASM()
|
|
361
|
+
expect(Script.fromASM(strA).toASM()).toEqual(strA)
|
|
362
|
+
|
|
363
|
+
// Test that it should be able to return the same output over and over for the second item
|
|
364
|
+
const strB = scriptFromVector(a[1]).toASM()
|
|
365
|
+
expect(Script.fromASM(strB).toASM()).toEqual(strB)
|
|
366
|
+
})
|
|
367
|
+
})
|
|
368
|
+
})
|
|
369
|
+
})
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import BigNumber from '../../../dist/cjs/src/primitives/BigNumber'
|
|
2
|
+
import PrivateKey from '../../../dist/cjs/src/primitives/PrivateKey'
|
|
3
|
+
import { hash160, hash256 } from '../../../dist/cjs/src/primitives/Hash'
|
|
4
|
+
import Curve from '../../../dist/cjs/src/primitives/Curve'
|
|
5
|
+
import Spend from '../../../dist/cjs/src/script/Spend'
|
|
6
|
+
import P2PKH from '../../../dist/cjs/src/script/templates/P2PKH'
|
|
7
|
+
import RPuzzle from '../../../dist/cjs/src/script/templates/RPuzzle'
|
|
8
|
+
import Transaction from '../../../dist/cjs/src/transaction/Transaction'
|
|
9
|
+
import scriptFromVector from './scriptFromVector'
|
|
10
|
+
import LockingScript from '../../../dist/cjs/src/script/LockingScript'
|
|
11
|
+
import UnlockingScript from '../../../dist/cjs/src/script/UnlockingScript'
|
|
12
|
+
|
|
13
|
+
import spendValid from './spend.valid.vectors'
|
|
14
|
+
|
|
15
|
+
describe('Spend', () => {
|
|
16
|
+
it('Successfully validates a P2PKH spend', async () => {
|
|
17
|
+
const privateKey = new PrivateKey(1)
|
|
18
|
+
const publicKey = privateKey.toPublicKey()
|
|
19
|
+
const hash = publicKey.toHash()
|
|
20
|
+
const p2pkh = new P2PKH()
|
|
21
|
+
const lockingScript = p2pkh.lock(hash)
|
|
22
|
+
const satoshis = new BigNumber(1)
|
|
23
|
+
const unlockingTemplate = p2pkh.unlock(privateKey)
|
|
24
|
+
const sourceTx = new Transaction(1, [], [{
|
|
25
|
+
lockingScript,
|
|
26
|
+
satoshis
|
|
27
|
+
}], 0)
|
|
28
|
+
const spendTx = new Transaction(1, [{
|
|
29
|
+
sourceTransaction: sourceTx,
|
|
30
|
+
sourceOutputIndex: 0,
|
|
31
|
+
sequence: 0xffffffff
|
|
32
|
+
}], [], 0)
|
|
33
|
+
const unlockingScript = await unlockingTemplate.sign(spendTx, 0)
|
|
34
|
+
const spend = new Spend({
|
|
35
|
+
sourceTXID: sourceTx.id('hex'),
|
|
36
|
+
sourceOutputIndex: 0,
|
|
37
|
+
sourceSatoshis: satoshis,
|
|
38
|
+
lockingScript,
|
|
39
|
+
transactionVersion: 1,
|
|
40
|
+
otherInputs: [],
|
|
41
|
+
inputIndex: 0,
|
|
42
|
+
unlockingScript,
|
|
43
|
+
outputs: [],
|
|
44
|
+
inputSequence: 0xffffffff,
|
|
45
|
+
lockTime: 0
|
|
46
|
+
})
|
|
47
|
+
const valid = spend.validate()
|
|
48
|
+
expect(valid).toBe(true)
|
|
49
|
+
})
|
|
50
|
+
it('Fails to verify a P2PKH spend with the wrong key', async () => {
|
|
51
|
+
const privateKey = new PrivateKey(1)
|
|
52
|
+
const publicKey = privateKey.toPublicKey()
|
|
53
|
+
const wrongPrivateKey = new PrivateKey(2)
|
|
54
|
+
const hash = publicKey.toHash()
|
|
55
|
+
const p2pkh = new P2PKH()
|
|
56
|
+
const lockingScript = p2pkh.lock(hash)
|
|
57
|
+
const satoshis = new BigNumber(1)
|
|
58
|
+
const unlockingTemplate = p2pkh.unlock(wrongPrivateKey)
|
|
59
|
+
const sourceTx = new Transaction(1, [], [{
|
|
60
|
+
lockingScript,
|
|
61
|
+
satoshis
|
|
62
|
+
}], 0)
|
|
63
|
+
const spendTx = new Transaction(1, [{
|
|
64
|
+
sourceTransaction: sourceTx,
|
|
65
|
+
sourceOutputIndex: 0,
|
|
66
|
+
sequence: 0xffffffff
|
|
67
|
+
}], [], 0)
|
|
68
|
+
const unlockingScript = await unlockingTemplate.sign(spendTx, 0)
|
|
69
|
+
const spend = new Spend({
|
|
70
|
+
sourceTXID: sourceTx.id('hex'),
|
|
71
|
+
sourceOutputIndex: 0,
|
|
72
|
+
sourceSatoshis: satoshis,
|
|
73
|
+
lockingScript,
|
|
74
|
+
transactionVersion: 1,
|
|
75
|
+
otherInputs: [],
|
|
76
|
+
inputIndex: 0,
|
|
77
|
+
unlockingScript,
|
|
78
|
+
outputs: [],
|
|
79
|
+
inputSequence: 0xffffffff,
|
|
80
|
+
lockTime: 0
|
|
81
|
+
})
|
|
82
|
+
expect(() => spend.validate()).toThrow()
|
|
83
|
+
})
|
|
84
|
+
it('Successfully validates an R-puzzle spend', async () => {
|
|
85
|
+
const k = new PrivateKey(2)
|
|
86
|
+
const c = new Curve()
|
|
87
|
+
let r = c.g.mul(k).x.umod(c.n).toArray()
|
|
88
|
+
r = r[0] > 127 ? [0, ...r] : r
|
|
89
|
+
const puz = new RPuzzle()
|
|
90
|
+
const lockingScript = puz.lock(r)
|
|
91
|
+
const satoshis = new BigNumber(1)
|
|
92
|
+
const unlockingTemplate = puz.unlock(k)
|
|
93
|
+
const sourceTx = new Transaction(1, [], [{
|
|
94
|
+
lockingScript,
|
|
95
|
+
satoshis
|
|
96
|
+
}], 0)
|
|
97
|
+
const spendTx = new Transaction(1, [{
|
|
98
|
+
sourceTransaction: sourceTx,
|
|
99
|
+
sourceOutputIndex: 0,
|
|
100
|
+
sequence: 0xffffffff
|
|
101
|
+
}], [], 0)
|
|
102
|
+
const unlockingScript = await unlockingTemplate.sign(spendTx, 0)
|
|
103
|
+
const spend = new Spend({
|
|
104
|
+
sourceTXID: sourceTx.id('hex'),
|
|
105
|
+
sourceOutputIndex: 0,
|
|
106
|
+
sourceSatoshis: satoshis,
|
|
107
|
+
lockingScript,
|
|
108
|
+
transactionVersion: 1,
|
|
109
|
+
otherInputs: [],
|
|
110
|
+
inputIndex: 0,
|
|
111
|
+
unlockingScript,
|
|
112
|
+
outputs: [],
|
|
113
|
+
inputSequence: 0xffffffff,
|
|
114
|
+
lockTime: 0
|
|
115
|
+
})
|
|
116
|
+
const valid = spend.validate()
|
|
117
|
+
expect(valid).toBe(true)
|
|
118
|
+
})
|
|
119
|
+
it('Successfully validates an R-puzzle spend (HASH256)', async () => {
|
|
120
|
+
const k = new PrivateKey(2)
|
|
121
|
+
const c = new Curve()
|
|
122
|
+
let r = c.g.mul(k).x.umod(c.n).toArray()
|
|
123
|
+
r = r[0] > 127 ? [0, ...r] : r
|
|
124
|
+
r = hash256(r)
|
|
125
|
+
const puz = new RPuzzle('HASH256')
|
|
126
|
+
const lockingScript = puz.lock(r)
|
|
127
|
+
const satoshis = new BigNumber(1)
|
|
128
|
+
const unlockingTemplate = puz.unlock(k)
|
|
129
|
+
const sourceTx = new Transaction(1, [], [{
|
|
130
|
+
lockingScript,
|
|
131
|
+
satoshis
|
|
132
|
+
}], 0)
|
|
133
|
+
const spendTx = new Transaction(1, [{
|
|
134
|
+
sourceTransaction: sourceTx,
|
|
135
|
+
sourceOutputIndex: 0,
|
|
136
|
+
sequence: 0xffffffff
|
|
137
|
+
}], [], 0)
|
|
138
|
+
const unlockingScript = await unlockingTemplate.sign(spendTx, 0)
|
|
139
|
+
const spend = new Spend({
|
|
140
|
+
sourceTXID: sourceTx.id('hex'),
|
|
141
|
+
sourceOutputIndex: 0,
|
|
142
|
+
sourceSatoshis: satoshis,
|
|
143
|
+
lockingScript,
|
|
144
|
+
transactionVersion: 1,
|
|
145
|
+
otherInputs: [],
|
|
146
|
+
inputIndex: 0,
|
|
147
|
+
unlockingScript,
|
|
148
|
+
outputs: [],
|
|
149
|
+
inputSequence: 0xffffffff,
|
|
150
|
+
lockTime: 0
|
|
151
|
+
})
|
|
152
|
+
const valid = spend.validate()
|
|
153
|
+
expect(valid).toBe(true)
|
|
154
|
+
})
|
|
155
|
+
it('Fails to validate an R-puzzle spend with the wrong K value', async () => {
|
|
156
|
+
const k = new PrivateKey(2)
|
|
157
|
+
const wrongK = new PrivateKey(5)
|
|
158
|
+
const c = new Curve()
|
|
159
|
+
let r = c.g.mul(k).x.umod(c.n).toArray()
|
|
160
|
+
r = r[0] > 127 ? [0, ...r] : r
|
|
161
|
+
r = hash256(r)
|
|
162
|
+
const puz = new RPuzzle('HASH256')
|
|
163
|
+
const lockingScript = puz.lock(r)
|
|
164
|
+
const satoshis = new BigNumber(1)
|
|
165
|
+
const unlockingTemplate = puz.unlock(wrongK)
|
|
166
|
+
const sourceTx = new Transaction(1, [], [{
|
|
167
|
+
lockingScript,
|
|
168
|
+
satoshis
|
|
169
|
+
}], 0)
|
|
170
|
+
const spendTx = new Transaction(1, [{
|
|
171
|
+
sourceTransaction: sourceTx,
|
|
172
|
+
sourceOutputIndex: 0,
|
|
173
|
+
sequence: 0xffffffff
|
|
174
|
+
}], [], 0)
|
|
175
|
+
const unlockingScript = await unlockingTemplate.sign(spendTx, 0)
|
|
176
|
+
const spend = new Spend({
|
|
177
|
+
sourceTXID: sourceTx.id('hex'),
|
|
178
|
+
sourceOutputIndex: 0,
|
|
179
|
+
sourceSatoshis: satoshis,
|
|
180
|
+
lockingScript,
|
|
181
|
+
transactionVersion: 1,
|
|
182
|
+
otherInputs: [],
|
|
183
|
+
inputIndex: 0,
|
|
184
|
+
unlockingScript,
|
|
185
|
+
outputs: [],
|
|
186
|
+
inputSequence: 0xffffffff,
|
|
187
|
+
lockTime: 0
|
|
188
|
+
})
|
|
189
|
+
expect(() => spend.validate()).toThrow()
|
|
190
|
+
})
|
|
191
|
+
it('Fails to validate an R-puzzle spend with the wrong hash', async () => {
|
|
192
|
+
const k = new PrivateKey(2)
|
|
193
|
+
const c = new Curve()
|
|
194
|
+
let r = c.g.mul(k).x.umod(c.n).toArray()
|
|
195
|
+
r = r[0] > 127 ? [0, ...r] : r
|
|
196
|
+
r = hash160(r)
|
|
197
|
+
const puz = new RPuzzle('HASH256')
|
|
198
|
+
const lockingScript = puz.lock(r)
|
|
199
|
+
const satoshis = new BigNumber(1)
|
|
200
|
+
const unlockingTemplate = puz.unlock(k)
|
|
201
|
+
const sourceTx = new Transaction(1, [], [{
|
|
202
|
+
lockingScript,
|
|
203
|
+
satoshis
|
|
204
|
+
}], 0)
|
|
205
|
+
const spendTx = new Transaction(1, [{
|
|
206
|
+
sourceTransaction: sourceTx,
|
|
207
|
+
sourceOutputIndex: 0,
|
|
208
|
+
sequence: 0xffffffff
|
|
209
|
+
}], [], 0)
|
|
210
|
+
const unlockingScript = await unlockingTemplate.sign(spendTx, 0)
|
|
211
|
+
const spend = new Spend({
|
|
212
|
+
sourceTXID: sourceTx.id('hex'),
|
|
213
|
+
sourceOutputIndex: 0,
|
|
214
|
+
sourceSatoshis: satoshis,
|
|
215
|
+
lockingScript,
|
|
216
|
+
transactionVersion: 1,
|
|
217
|
+
otherInputs: [],
|
|
218
|
+
inputIndex: 0,
|
|
219
|
+
unlockingScript,
|
|
220
|
+
outputs: [],
|
|
221
|
+
inputSequence: 0xffffffff,
|
|
222
|
+
lockTime: 0
|
|
223
|
+
})
|
|
224
|
+
expect(() => spend.validate()).toThrow()
|
|
225
|
+
})
|
|
226
|
+
for (let i = 0; i < spendValid.length; i++) {
|
|
227
|
+
const a = spendValid[i]
|
|
228
|
+
if (a.length === 1) {
|
|
229
|
+
continue
|
|
230
|
+
}
|
|
231
|
+
it(a[2], () => {
|
|
232
|
+
const spend = new Spend({
|
|
233
|
+
sourceTXID: '0000000000000000000000000000000000000000000000000000000000000000',
|
|
234
|
+
sourceOutputIndex: 0,
|
|
235
|
+
sourceSatoshis: new BigNumber(1),
|
|
236
|
+
lockingScript: new LockingScript(scriptFromVector(a[1]).chunks),
|
|
237
|
+
transactionVersion: 1,
|
|
238
|
+
otherInputs: [],
|
|
239
|
+
outputs: [],
|
|
240
|
+
inputIndex: 0,
|
|
241
|
+
unlockingScript: new UnlockingScript(scriptFromVector(a[0]).chunks),
|
|
242
|
+
inputSequence: 0xffffffff,
|
|
243
|
+
lockTime: 0
|
|
244
|
+
})
|
|
245
|
+
expect(spend.validate()).toBe(true)
|
|
246
|
+
})
|
|
247
|
+
}
|
|
248
|
+
})
|