@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,164 @@
|
|
|
1
|
+
import BasePoint from './BasePoint.js';
|
|
2
|
+
import BigNumber from './BigNumber.js';
|
|
3
|
+
import Point from './Point.js';
|
|
4
|
+
/**
|
|
5
|
+
* The `JacobianPoint` class extends the `BasePoint` class for handling Jacobian coordinates on an Elliptic Curve.
|
|
6
|
+
* This class defines the properties and the methods needed to work with points in Jacobian coordinates.
|
|
7
|
+
*
|
|
8
|
+
* The Jacobian coordinates represent a point (x, y, z) on an Elliptic Curve such that the usual (x, y) coordinates are given by (x/z^2, y/z^3).
|
|
9
|
+
*
|
|
10
|
+
* @property x - The `x` coordinate of the point in the Jacobian form.
|
|
11
|
+
* @property y - The `y` coordinate of the point in the Jacobian form.
|
|
12
|
+
* @property z - The `z` coordinate of the point in the Jacobian form.
|
|
13
|
+
* @property zOne - Flag that indicates if the `z` coordinate is one.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const pointJ = new JacobianPoint('3', '4', '1');
|
|
17
|
+
*/
|
|
18
|
+
export default class JacobianPoint extends BasePoint {
|
|
19
|
+
x: BigNumber;
|
|
20
|
+
y: BigNumber;
|
|
21
|
+
z: BigNumber;
|
|
22
|
+
zOne: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Constructs a new `JacobianPoint` instance.
|
|
25
|
+
*
|
|
26
|
+
* @param x - If `null`, the x-coordinate will default to the curve's defined 'one' constant.
|
|
27
|
+
* If `x` is not a BigNumber, `x` will be converted to a `BigNumber` assuming it is a hex string.
|
|
28
|
+
*
|
|
29
|
+
* @param y - If `null`, the y-coordinate will default to the curve's defined 'one' constant.
|
|
30
|
+
* If `y` is not a BigNumber, `y` will be converted to a `BigNumber` assuming it is a hex string.
|
|
31
|
+
*
|
|
32
|
+
* @param z - If `null`, the z-coordinate will default to 0.
|
|
33
|
+
* If `z` is not a BigNumber, `z` will be converted to a `BigNumber` assuming it is a hex string.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* const pointJ1 = new JacobianPoint(null, null, null); // creates point at infinity
|
|
37
|
+
* const pointJ2 = new JacobianPoint('3', '4', '1'); // creates point (3, 4, 1)
|
|
38
|
+
*/
|
|
39
|
+
constructor(x: string | BigNumber | null, y: string | BigNumber | null, z: string | BigNumber | null);
|
|
40
|
+
/**
|
|
41
|
+
* Converts the `JacobianPoint` object instance to standard affine `Point` format and returns `Point` type.
|
|
42
|
+
*
|
|
43
|
+
* @returns The `Point`(affine) object representing the same point as the original `JacobianPoint`.
|
|
44
|
+
*
|
|
45
|
+
* If the initial `JacobianPoint` represents point at infinity, an instance of `Point` at infinity is returned.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* const pointJ = new JacobianPoint('3', '4', '1');
|
|
49
|
+
* const pointP = pointJ.toP(); // The point in affine coordinates.
|
|
50
|
+
*/
|
|
51
|
+
toP(): Point;
|
|
52
|
+
/**
|
|
53
|
+
* Negation operation. It returns the additive inverse of the Jacobian point.
|
|
54
|
+
*
|
|
55
|
+
* @method neg
|
|
56
|
+
* @returns Returns a new Jacobian point as the result of the negation.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* const jp = new JacobianPoint(x, y, z)
|
|
60
|
+
* const result = jp.neg()
|
|
61
|
+
*/
|
|
62
|
+
neg(): JacobianPoint;
|
|
63
|
+
/**
|
|
64
|
+
* Addition operation in the Jacobian coordinates. It takes a Jacobian point as an argument
|
|
65
|
+
* and returns a new Jacobian point as a result of the addition. In the special cases,
|
|
66
|
+
* when either one of the points is the point at infinity, it will return the other point.
|
|
67
|
+
*
|
|
68
|
+
* @method add
|
|
69
|
+
* @param p - The Jacobian point to be added.
|
|
70
|
+
* @returns Returns a new Jacobian point as the result of the addition.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* const p1 = new JacobianPoint(x1, y1, z1)
|
|
74
|
+
* const p2 = new JacobianPoint(x2, y2, z2)
|
|
75
|
+
* const result = p1.add(p2)
|
|
76
|
+
*/
|
|
77
|
+
add(p: JacobianPoint): JacobianPoint;
|
|
78
|
+
/**
|
|
79
|
+
* Mixed addition operation. This function combines the standard point addition with
|
|
80
|
+
* the transformation from the affine to Jacobian coordinates. It first converts
|
|
81
|
+
* the affine point to Jacobian, and then preforms the addition.
|
|
82
|
+
*
|
|
83
|
+
* @method mixedAdd
|
|
84
|
+
* @param p - The affine point to be added.
|
|
85
|
+
* @returns Returns the result of the mixed addition as a new Jacobian point.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* const jp = new JacobianPoint(x1, y1, z1)
|
|
89
|
+
* const ap = new Point(x2, y2)
|
|
90
|
+
* const result = jp.mixedAdd(ap)
|
|
91
|
+
*/
|
|
92
|
+
mixedAdd(p: Point): JacobianPoint;
|
|
93
|
+
/**
|
|
94
|
+
* Multiple doubling operation. It doubles the Jacobian point as many times as the pow parameter specifies. If pow is 0 or the point is the point at infinity, it will return the point itself.
|
|
95
|
+
*
|
|
96
|
+
* @method dblp
|
|
97
|
+
* @param pow - The number of times the point should be doubled.
|
|
98
|
+
* @returns Returns a new Jacobian point as the result of multiple doublings.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* const jp = new JacobianPoint(x, y, z)
|
|
102
|
+
* const result = jp.dblp(3)
|
|
103
|
+
*/
|
|
104
|
+
dblp(pow: number): JacobianPoint;
|
|
105
|
+
/**
|
|
106
|
+
* Point doubling operation in the Jacobian coordinates. A special case is when the point is the point at infinity, in this case, this function will return the point itself.
|
|
107
|
+
*
|
|
108
|
+
* @method dbl
|
|
109
|
+
* @returns Returns a new Jacobian point as the result of the doubling.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* const jp = new JacobianPoint(x, y, z)
|
|
113
|
+
* const result = jp.dbl()
|
|
114
|
+
*/
|
|
115
|
+
dbl(): JacobianPoint;
|
|
116
|
+
/**
|
|
117
|
+
* Equality check operation. It checks whether the affine or Jacobian point is equal to this Jacobian point.
|
|
118
|
+
*
|
|
119
|
+
* @method eq
|
|
120
|
+
* @param p - The affine or Jacobian point to compare with.
|
|
121
|
+
* @returns Returns true if the points are equal, otherwise returns false.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* const jp1 = new JacobianPoint(x1, y1, z1)
|
|
125
|
+
* const jp2 = new JacobianPoint(x2, y2, z2)
|
|
126
|
+
* const areEqual = jp1.eq(jp2)
|
|
127
|
+
*/
|
|
128
|
+
eq(p: Point | JacobianPoint): boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Equality check operation in relation to an x coordinate of a point in projective coordinates.
|
|
131
|
+
* It checks whether the x coordinate of the Jacobian point is equal to the provided x coordinate
|
|
132
|
+
* of a point in projective coordinates.
|
|
133
|
+
*
|
|
134
|
+
* @method eqXToP
|
|
135
|
+
* @param x - The x coordinate of a point in projective coordinates.
|
|
136
|
+
* @returns Returns true if the x coordinates are equal, otherwise returns false.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* const jp = new JacobianPoint(x1, y1, z1)
|
|
140
|
+
* const isXEqual = jp.eqXToP(x2)
|
|
141
|
+
*/
|
|
142
|
+
eqXToP(x: BigNumber): boolean;
|
|
143
|
+
/**
|
|
144
|
+
* Returns the string representation of the JacobianPoint instance.
|
|
145
|
+
* @method inspect
|
|
146
|
+
* @returns Returns the string description of the JacobianPoint. If the JacobianPoint represents a point at infinity, the return value of this function is '<EC JPoint Infinity>'. For a normal point, it returns the string description format as '<EC JPoint x: x-coordinate y: y-coordinate z: z-coordinate>'.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* const point = new JacobianPoint('5', '6', '1');
|
|
150
|
+
* console.log(point.inspect()); // Output: '<EC JPoint x: 5 y: 6 z: 1>'
|
|
151
|
+
*/
|
|
152
|
+
inspect(): string;
|
|
153
|
+
/**
|
|
154
|
+
* Checks whether the JacobianPoint instance represents a point at infinity.
|
|
155
|
+
* @method isInfinity
|
|
156
|
+
* @returns Returns true if the JacobianPoint's z-coordinate equals to zero (which represents the point at infinity in Jacobian coordinates). Returns false otherwise.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* const point = new JacobianPoint('5', '6', '0');
|
|
160
|
+
* console.log(point.isInfinity()); // Output: true
|
|
161
|
+
*/
|
|
162
|
+
isInfinity(): boolean;
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=JacobianPoint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JacobianPoint.d.ts","sourceRoot":"","sources":["../../../../src/primitives/JacobianPoint.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAA;AACtC,OAAO,SAAS,MAAM,gBAAgB,CAAA;AACtC,OAAO,KAAK,MAAM,YAAY,CAAA;AAE9B;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,SAAS;IAClD,CAAC,EAAE,SAAS,CAAA;IACZ,CAAC,EAAE,SAAS,CAAA;IACZ,CAAC,EAAE,SAAS,CAAA;IACZ,IAAI,EAAE,OAAO,CAAA;IAEb;;;;;;;;;;;;;;;OAeG;gBAED,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,EAC5B,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,EAC5B,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IA4B9B;;;;;;;;;;OAUG;IACH,GAAG,IAAK,KAAK;IAab;;;;;;;;;OASG;IACH,GAAG,IAAK,aAAa;IAIrB;;;;;;;;;;;;;OAaG;IACH,GAAG,CAAE,CAAC,EAAE,aAAa,GAAG,aAAa;IAoCrC;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAE,CAAC,EAAE,KAAK,GAAG,aAAa;IAmClC;;;;;;;;;;OAUG;IACH,IAAI,CAAE,GAAG,EAAE,MAAM,GAAG,aAAa;IAiBjC;;;;;;;;;OASG;IACH,GAAG,IAAK,aAAa;IA2ErB;;;;;;;;;;;OAWG;IACH,EAAE,CAAE,CAAC,EAAE,KAAK,GAAG,aAAa,GAAG,OAAO;IAmBtC;;;;;;;;;;;;OAYG;IACH,MAAM,CAAE,CAAC,EAAE,SAAS,GAAG,OAAO;IAgB9B;;;;;;;;OAQG;IACH,OAAO,IAAK,MAAM;IAOlB;;;;;;;;OAQG;IACH,UAAU,IAAK,OAAO;CAGvB"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import Mersenne from './Mersenne.js';
|
|
2
|
+
import BigNumber from './BigNumber.js';
|
|
3
|
+
/**
|
|
4
|
+
* A class representing K-256, a prime number with optimizations, specifically used in the secp256k1 curve.
|
|
5
|
+
* It extends the functionalities of the Mersenne class.
|
|
6
|
+
* K-256 prime is represented as 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f'
|
|
7
|
+
*
|
|
8
|
+
* @class K256
|
|
9
|
+
* @extends {Mersenne}
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const k256 = new K256();
|
|
13
|
+
*/
|
|
14
|
+
export default class K256 extends Mersenne {
|
|
15
|
+
/**
|
|
16
|
+
* Constructor for the K256 class.
|
|
17
|
+
* Creates an instance of K256 using the super constructor from Mersenne.
|
|
18
|
+
*
|
|
19
|
+
* @constructor
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const k256 = new K256();
|
|
23
|
+
*/
|
|
24
|
+
constructor();
|
|
25
|
+
/**
|
|
26
|
+
* Splits a BigNumber into a new BigNumber based on specific computation
|
|
27
|
+
* rules. This method modifies the input and output big numbers.
|
|
28
|
+
*
|
|
29
|
+
* @method split
|
|
30
|
+
* @param input - The BigNumber to be split.
|
|
31
|
+
* @param output - The BigNumber that results from the split.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* const input = new BigNumber(3456);
|
|
35
|
+
* const output = new BigNumber(0);
|
|
36
|
+
* k256.split(input, output);
|
|
37
|
+
*/
|
|
38
|
+
split(input: BigNumber, output: BigNumber): void;
|
|
39
|
+
/**
|
|
40
|
+
* Multiplies a BigNumber ('num') with the constant 'K' in-place and returns the result.
|
|
41
|
+
* 'K' is equal to 0x1000003d1 or in decimal representation: [ 64, 977 ].
|
|
42
|
+
*
|
|
43
|
+
* @method imulK
|
|
44
|
+
* @param num - The BigNumber to multiply with K.
|
|
45
|
+
* @returns Returns the mutated BigNumber after multiplication.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* const number = new BigNumber(12345);
|
|
49
|
+
* const result = k256.imulK(number);
|
|
50
|
+
*/
|
|
51
|
+
imulK(num: BigNumber): BigNumber;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=K256.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"K256.d.ts","sourceRoot":"","sources":["../../../../src/primitives/K256.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,eAAe,CAAA;AACpC,OAAO,SAAS,MAAM,gBAAgB,CAAA;AAEtC;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,QAAQ;IACxC;;;;;;;;OAQG;;IAQH;;;;;;;;;;;;OAYG;IACH,KAAK,CAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,GAAG,IAAI;IAmCjD;;;;;;;;;;;OAWG;IACH,KAAK,CAAE,GAAG,EAAE,SAAS,GAAG,SAAS;CAwBlC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import BigNumber from './BigNumber.js';
|
|
2
|
+
/**
|
|
3
|
+
* A representation of a pseudo-Mersenne prime.
|
|
4
|
+
* A pseudo-Mersenne prime has the general form 2^n - k, where n and k are integers.
|
|
5
|
+
*
|
|
6
|
+
* @class Mersenne
|
|
7
|
+
*
|
|
8
|
+
* @property name - The identifier for the Mersenne instance.
|
|
9
|
+
* @property p - BigNumber equivalent to 2^n - k.
|
|
10
|
+
* @property k - The constant subtracted from 2^n to derive a pseudo-Mersenne prime.
|
|
11
|
+
* @property n - The exponent which determines the magnitude of the prime.
|
|
12
|
+
*/
|
|
13
|
+
export default class Mersenne {
|
|
14
|
+
name: string;
|
|
15
|
+
p: BigNumber;
|
|
16
|
+
k: BigNumber;
|
|
17
|
+
n: number;
|
|
18
|
+
private readonly tmp;
|
|
19
|
+
/**
|
|
20
|
+
* @constructor
|
|
21
|
+
* @param name - An identifier for the Mersenne instance.
|
|
22
|
+
* @param p - A string representation of the pseudo-Mersenne prime, expressed in hexadecimal.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* const mersenne = new Mersenne('M31', '7FFFFFFF');
|
|
26
|
+
*/
|
|
27
|
+
constructor(name: string, p: string);
|
|
28
|
+
/**
|
|
29
|
+
* Creates a temporary BigNumber structure for computations,
|
|
30
|
+
* ensuring the appropriate number of words are initially allocated.
|
|
31
|
+
*
|
|
32
|
+
* @method _tmp
|
|
33
|
+
* @returns A BigNumber with scaled size depending on prime magnitude.
|
|
34
|
+
*/
|
|
35
|
+
private _tmp;
|
|
36
|
+
/**
|
|
37
|
+
* Reduces an input BigNumber in place, under the assumption that
|
|
38
|
+
* it is less than the square of the pseudo-Mersenne prime.
|
|
39
|
+
*
|
|
40
|
+
* @method ireduce
|
|
41
|
+
* @param num - The BigNumber to be reduced.
|
|
42
|
+
* @returns The reduced BigNumber.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* const reduced = mersenne.ireduce(new BigNumber('2345', 16));
|
|
46
|
+
*/
|
|
47
|
+
ireduce(num: BigNumber): BigNumber;
|
|
48
|
+
/**
|
|
49
|
+
* Shifts bits of the input BigNumber to the right, in place,
|
|
50
|
+
* to meet the magnitude of the pseudo-Mersenne prime.
|
|
51
|
+
*
|
|
52
|
+
* @method split
|
|
53
|
+
* @param input - The BigNumber to be shifted.
|
|
54
|
+
* @param out - The BigNumber to hold the shifted result.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* mersenne.split(new BigNumber('2345', 16), new BigNumber());
|
|
58
|
+
*/
|
|
59
|
+
split(input: BigNumber, out: BigNumber): void;
|
|
60
|
+
/**
|
|
61
|
+
* Performs an in-place multiplication of the parameter by constant k.
|
|
62
|
+
*
|
|
63
|
+
* @method imulK
|
|
64
|
+
* @param num - The BigNumber to multiply with k.
|
|
65
|
+
* @returns The result of the multiplication, in BigNumber format.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* const multiplied = mersenne.imulK(new BigNumber('2345', 16));
|
|
69
|
+
*/
|
|
70
|
+
imulK(num: BigNumber): BigNumber;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=Mersenne.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Mersenne.d.ts","sourceRoot":"","sources":["../../../../src/primitives/Mersenne.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAA;AAEtC;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,CAAC,EAAE,SAAS,CAAA;IACZ,CAAC,EAAE,SAAS,CAAA;IACZ,CAAC,EAAE,MAAM,CAAA;IACT,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAW;IAE/B;;;;;;;OAOG;gBACU,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM;IAUpC;;;;;;OAMG;IACH,OAAO,CAAC,IAAI;IAMZ;;;;;;;;;;OAUG;IACH,OAAO,CAAE,GAAG,EAAE,SAAS,GAAG,SAAS;IAgCnC;;;;;;;;;;OAUG;IACH,KAAK,CAAE,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,GAAG,IAAI;IAI9C;;;;;;;;;OASG;IACH,KAAK,CAAE,GAAG,EAAE,SAAS,GAAG,SAAS;CAGlC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import ReductionContext from './ReductionContext.js';
|
|
2
|
+
import BigNumber from './BigNumber.js';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a Montgomery reduction context, which is a mathematical method
|
|
5
|
+
* for performing modular multiplication without division.
|
|
6
|
+
*
|
|
7
|
+
* Montgomery reduction is an algorithm used mainly in cryptography which can
|
|
8
|
+
* help to speed up calculations in contexts where there are many repeated
|
|
9
|
+
* computations.
|
|
10
|
+
*
|
|
11
|
+
* This class extends the `ReductionContext` class.
|
|
12
|
+
*
|
|
13
|
+
* @class MontgomoryMethod
|
|
14
|
+
* @extends {ReductionContext}
|
|
15
|
+
*
|
|
16
|
+
* @property shift - The number of bits in the modulus.
|
|
17
|
+
* @property r - The 2^shift, shifted left by the bit length of modulus `m`.
|
|
18
|
+
* @property r2 - The square of `r` modulo `m`.
|
|
19
|
+
* @property rinv - The modular multiplicative inverse of `r` mod `m`.
|
|
20
|
+
* @property minv - The modular multiplicative inverse of `m` mod `r`.
|
|
21
|
+
*/
|
|
22
|
+
export default class MontgomoryMethod extends ReductionContext {
|
|
23
|
+
shift: number;
|
|
24
|
+
r: BigNumber;
|
|
25
|
+
r2: BigNumber;
|
|
26
|
+
rinv: BigNumber;
|
|
27
|
+
minv: BigNumber;
|
|
28
|
+
/**
|
|
29
|
+
* @constructor
|
|
30
|
+
* @param m - The modulus to be used for the Montgomery method reductions.
|
|
31
|
+
*/
|
|
32
|
+
constructor(m: BigNumber | 'k256');
|
|
33
|
+
/**
|
|
34
|
+
* Converts a number into the Montgomery domain.
|
|
35
|
+
*
|
|
36
|
+
* @method convertTo
|
|
37
|
+
* @param num - The number to be converted into the Montgomery domain.
|
|
38
|
+
* @returns The result of the conversion into the Montgomery domain.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* const montMethod = new MontgomoryMethod(m);
|
|
42
|
+
* const convertedNum = montMethod.convertTo(num);
|
|
43
|
+
*/
|
|
44
|
+
convertTo(num: BigNumber): BigNumber;
|
|
45
|
+
/**
|
|
46
|
+
* Converts a number from the Montgomery domain back to the original domain.
|
|
47
|
+
*
|
|
48
|
+
* @method convertFrom
|
|
49
|
+
* @param num - The number to be converted from the Montgomery domain.
|
|
50
|
+
* @returns The result of the conversion from the Montgomery domain.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* const montMethod = new MontgomoryMethod(m);
|
|
54
|
+
* const convertedNum = montMethod.convertFrom(num);
|
|
55
|
+
*/
|
|
56
|
+
convertFrom(num: BigNumber): BigNumber;
|
|
57
|
+
/**
|
|
58
|
+
* Performs an in-place multiplication of two numbers in the Montgomery domain.
|
|
59
|
+
*
|
|
60
|
+
* @method imul
|
|
61
|
+
* @param a - The first number to multiply.
|
|
62
|
+
* @param b - The second number to multiply.
|
|
63
|
+
* @returns The result of the in-place multiplication.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* const montMethod = new MontgomoryMethod(m);
|
|
67
|
+
* const product = montMethod.imul(a, b);
|
|
68
|
+
*/
|
|
69
|
+
imul(a: BigNumber, b: BigNumber): BigNumber;
|
|
70
|
+
/**
|
|
71
|
+
* Performs the multiplication of two numbers in the Montgomery domain.
|
|
72
|
+
*
|
|
73
|
+
* @method mul
|
|
74
|
+
* @param a - The first number to multiply.
|
|
75
|
+
* @param b - The second number to multiply.
|
|
76
|
+
* @returns The result of the multiplication.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* const montMethod = new MontgomoryMethod(m);
|
|
80
|
+
* const product = montMethod.mul(a, b);
|
|
81
|
+
*/
|
|
82
|
+
mul(a: BigNumber, b: BigNumber): BigNumber;
|
|
83
|
+
/**
|
|
84
|
+
* Calculates the modular multiplicative inverse of a number in the Montgomery domain.
|
|
85
|
+
*
|
|
86
|
+
* @method invm
|
|
87
|
+
* @param a - The number to compute the modular multiplicative inverse of.
|
|
88
|
+
* @returns The modular multiplicative inverse of 'a'.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* const montMethod = new MontgomoryMethod(m);
|
|
92
|
+
* const inverse = montMethod.invm(a);
|
|
93
|
+
*/
|
|
94
|
+
invm(a: BigNumber): BigNumber;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=MontgomoryMethod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MontgomoryMethod.d.ts","sourceRoot":"","sources":["../../../../src/primitives/MontgomoryMethod.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,uBAAuB,CAAA;AACpD,OAAO,SAAS,MAAM,gBAAgB,CAAA;AAEtC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,gBAAgB;IAC5D,KAAK,EAAE,MAAM,CAAA;IACb,CAAC,EAAE,SAAS,CAAA;IACZ,EAAE,EAAE,SAAS,CAAA;IACb,IAAI,EAAE,SAAS,CAAA;IACf,IAAI,EAAE,SAAS,CAAA;IAEf;;;OAGG;gBACU,CAAC,EAAE,SAAS,GAAG,MAAM;IAiBlC;;;;;;;;;;OAUG;IACH,SAAS,CAAE,GAAG,EAAE,SAAS,GAAG,SAAS;IAIrC;;;;;;;;;;OAUG;IACH,WAAW,CAAE,GAAG,EAAE,SAAS,GAAG,SAAS;IAMvC;;;;;;;;;;;OAWG;IACH,IAAI,CAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,GAAG,SAAS;IAqB5C;;;;;;;;;;;OAWG;IACH,GAAG,CAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,GAAG,SAAS;IAgB3C;;;;;;;;;;OAUG;IACH,IAAI,CAAE,CAAC,EAAE,SAAS,GAAG,SAAS;CAK/B"}
|