@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,94 @@
|
|
|
1
|
+
# Getting Started with BSV SDK in Node.js (CommonJS)
|
|
2
|
+
|
|
3
|
+
Welcome to the quick start guide for the BSV SDK, tailored for Node.js applications using CommonJS syntax. This guide will walk you through the steps to install the SDK, set up your project, and run a simple example that leverages the BSV Blockchain Libraries Project for creating and signing a transaction. Whether you're working on an existing Node.js project or starting a new one, this guide will get you up and running with the BSV SDK in no time.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
Before you begin, ensure you have the following:
|
|
8
|
+
|
|
9
|
+
- Node.js installed on your machine. The BSV SDK is compatible with Node.js version 10 or later.
|
|
10
|
+
- An understanding of JavaScript or TypeScript.
|
|
11
|
+
- A basic familiarity with blockchain concepts, particularly those related to Bitcoin SV (BSV).
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
First, you'll need to install the BSV SDK in your Node.js project. If you haven't already created a project, you can do so by running `npm init` in your project directory and following the prompts.
|
|
16
|
+
|
|
17
|
+
To install the SDK, open your terminal, navigate to your project directory, and run:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @bsv/sdk
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
This command will download and install the BSV SDK and its dependencies into your project.
|
|
24
|
+
|
|
25
|
+
## Setting Up Your Project
|
|
26
|
+
|
|
27
|
+
To use the SDK in a Node.js project with CommonJS syntax, you'll need to require the SDK modules in your JavaScript files. Here's how to set up a basic project structure and include the BSV SDK:
|
|
28
|
+
|
|
29
|
+
1. **Create a New JavaScript File:** In your project directory, create a new file named `index.js` or any other name you prefer for your main application file.
|
|
30
|
+
|
|
31
|
+
2. **Require the BSV SDK:** At the top of your `index.js` file, require the BSV SDK modules you plan to use. For example, to work with transactions, you might start with:
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
const { Transaction } = require('@bsv/sdk');
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
3. **Configure Your Environment:** If your project involves interacting with the BSV blockchain network (e.g., sending transactions, querying blockchain data), ensure you have the necessary network configurations and API keys set up if required by the SDK or any third-party services you're using.
|
|
38
|
+
|
|
39
|
+
## Example: Creating and Signing a Transaction
|
|
40
|
+
|
|
41
|
+
Let's walk through a simple example of using the BSV SDK to create and sign a transaction. This example will demonstrate how to construct a transaction, add inputs and outputs, and sign it using a private key.
|
|
42
|
+
|
|
43
|
+
1. **Prepare Your Script:** In your `index.js`, start by requiring the necessary modules from the SDK. For this example, we'll need `Transaction`, `PrivateKey`, and possibly other modules depending on the complexity of your transaction.
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
const { Transaction, PrivateKey } = require('@bsv/sdk');
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
2. **Create a New Transaction:** Initialize a new `Transaction` object.
|
|
50
|
+
|
|
51
|
+
```javascript
|
|
52
|
+
let tx = new Transaction();
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
3. **Add Inputs and Outputs:** For this example, we'll add a dummy input and output. In a real-world scenario, you would fetch UTXO (Unspent Transaction Output) data from a blockchain explorer or your wallet.
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
// Dummy input and output, replace with real data
|
|
59
|
+
tx.from({
|
|
60
|
+
txId: 'your_utxo_txid',
|
|
61
|
+
outputIndex: 0,
|
|
62
|
+
address: 'your_address',
|
|
63
|
+
satoshis: 1000
|
|
64
|
+
});
|
|
65
|
+
tx.to('recipient_address', 500); // Send 500 satoshis to recipient
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
4. **Sign the Transaction:** Use a `PrivateKey` instance to sign the transaction. Replace `'your_private_key'` with your actual private key.
|
|
69
|
+
|
|
70
|
+
```javascript
|
|
71
|
+
const privateKey = new PrivateKey('your_private_key');
|
|
72
|
+
tx.sign(privateKey);
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
5. **Broadcast the Transaction:** The SDK may provide a method to broadcast the transaction to the BSV network. This step varies depending on the SDK's capabilities and your setup.
|
|
76
|
+
|
|
77
|
+
```javascript
|
|
78
|
+
// This is a conceptual step; refer to the SDK documentation for actual broadcasting
|
|
79
|
+
tx.broadcast();
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Running Your Project
|
|
83
|
+
|
|
84
|
+
After setting up your project and writing the example code, you can run your project by executing:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
node index.js
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
This command will run your `index.js` file, which includes the BSV SDK transaction creation and signing logic.
|
|
91
|
+
|
|
92
|
+
## Conclusion
|
|
93
|
+
|
|
94
|
+
You've now seen how to get started with the BSV SDK in a Node.js (CommonJS) environment, from installation to running a simple transaction example. This guide aimed to provide a straightforward path for integrating the B
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Getting Started with BSV SDK in a React TypeScript Project
|
|
2
|
+
|
|
3
|
+
Welcome to a quick start guide designed to get you up and running with the BSV SDK in your React TypeScript projects. The BSV SDK offers a comprehensive set of tools for developing applications on the BSV Blockchain, and integrating it into a React application is straightforward. Follow these steps to begin building scalable blockchain applications with ease.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
Before you start, ensure you have the following installed:
|
|
8
|
+
- Node.js (preferably the latest LTS version)
|
|
9
|
+
- npm (comes with Node.js) or Yarn
|
|
10
|
+
- A code editor of your choice (VSCode is recommended for TypeScript projects)
|
|
11
|
+
|
|
12
|
+
## Step 1: Setting Up Your React TypeScript Project
|
|
13
|
+
|
|
14
|
+
If you're starting from scratch, create a new React TypeScript project by running the following command in your terminal:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npx create-react-app my-bsv-app --template typescript
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
This command creates a new React application named `my-bsv-app` with TypeScript setup. If you already have a React TypeScript project, you can skip this step.
|
|
21
|
+
|
|
22
|
+
## Step 2: Installing the BSV SDK
|
|
23
|
+
|
|
24
|
+
Navigate to your project directory in the terminal and install the BSV SDK by running:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install @bsv/sdk
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
or if you're using Yarn:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
yarn add @bsv/sdk
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
This command adds the BSV SDK to your project, allowing you to interact with the BSV Blockchain.
|
|
37
|
+
|
|
38
|
+
## Step 3: Using the BSV SDK in Your React Application
|
|
39
|
+
|
|
40
|
+
Now that you've installed the SDK, let's use it to create and sign a transaction. First, create a new component where you'll implement your blockchain logic.
|
|
41
|
+
|
|
42
|
+
### Create a New Component
|
|
43
|
+
|
|
44
|
+
In your project's `src` directory, create a new file named `BlockchainExample.tsx`. This component will demonstrate a simple usage of the BSV SDK.
|
|
45
|
+
|
|
46
|
+
### Implementing the Component
|
|
47
|
+
|
|
48
|
+
Paste the following code into `BlockchainExample.tsx`:
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import React from 'react';
|
|
52
|
+
// Import necessary modules from the SDK
|
|
53
|
+
import { PrivateKey, Transaction } from '@bsv/sdk';
|
|
54
|
+
|
|
55
|
+
const BlockchainExample: React.FC = () => {
|
|
56
|
+
// Example function to create and sign a transaction
|
|
57
|
+
const createTransaction = async () => {
|
|
58
|
+
try {
|
|
59
|
+
// Replace with actual private key and addresses
|
|
60
|
+
const privateKey = new PrivateKey('<your-private-key>');
|
|
61
|
+
const fromAddress = '<from-address>';
|
|
62
|
+
const toAddress = '<to-address>';
|
|
63
|
+
const satoshis = 1000; // Amount to send
|
|
64
|
+
|
|
65
|
+
// Create a new transaction
|
|
66
|
+
let tx = new Transaction();
|
|
67
|
+
tx.from(fromAddress) // Specify the sender's address
|
|
68
|
+
.to(toAddress, satoshis) // Specify the recipient and amount
|
|
69
|
+
.sign(privateKey); // Sign the transaction with the private key
|
|
70
|
+
|
|
71
|
+
console.log('Transaction created:', tx.toString());
|
|
72
|
+
// Add logic to broadcast the transaction
|
|
73
|
+
} catch (error) {
|
|
74
|
+
console.error('Error creating transaction:', error);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<div>
|
|
80
|
+
<h2>Blockchain Example</h2>
|
|
81
|
+
<button onClick={createTransaction}>Create Transaction</button>
|
|
82
|
+
</div>
|
|
83
|
+
);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export default BlockchainExample;
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**Note:** This is a simplified example for educational purposes. Replace placeholder values with actual private keys and addresses, and implement proper error handling and security measures in your real-world applications.
|
|
90
|
+
|
|
91
|
+
### Add the Component to Your App
|
|
92
|
+
|
|
93
|
+
Open `src/App.tsx` and import `BlockchainExample`. Include it in your application's render method:
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import React from 'react';
|
|
97
|
+
import './App.css';
|
|
98
|
+
import BlockchainExample from './BlockchainExample';
|
|
99
|
+
|
|
100
|
+
function App() {
|
|
101
|
+
return (
|
|
102
|
+
<div className="App">
|
|
103
|
+
<header className="App-header">
|
|
104
|
+
<BlockchainExample />
|
|
105
|
+
</header>
|
|
106
|
+
</div>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export default App;
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Step 4: Running Your Application
|
|
114
|
+
|
|
115
|
+
Now that everything is set up, start your application by running:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
npm start
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
or if you're using Yarn:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
yarn start
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Your application will open in your default web browser. You'll see a button labeled "Create Transaction" that, when clicked, will run the logic to create and sign a transaction using the BSV SDK.
|
|
128
|
+
|
|
129
|
+
## Next Steps
|
|
130
|
+
|
|
131
|
+
This guide covered the basics to get you started with the BSV SDK in a React TypeScript project. Explore the SDK's comprehensive documentation to learn more about its capabilities, such as cryptographic primitives, script-level constructs, transaction construction, and much more. Happy coding!
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
To get started with the BSV SDK in a Node.js TypeScript project, follow these steps to install, configure, and use the library efficiently. This guide will help you set up a basic project structure, install the SDK, and create a simple application that uses BSV SDK functionalities.
|
|
2
|
+
|
|
3
|
+
### Prerequisites
|
|
4
|
+
|
|
5
|
+
Before you begin, ensure you have the following installed on your system:
|
|
6
|
+
|
|
7
|
+
- Node.js (version 12.x or higher)
|
|
8
|
+
- npm (usually comes with Node.js)
|
|
9
|
+
- TypeScript (version 3.8 or higher)
|
|
10
|
+
|
|
11
|
+
You can check the versions by running `node -v` and `npm -v` in your terminal.
|
|
12
|
+
|
|
13
|
+
### Step 1: Setting Up Your Project
|
|
14
|
+
|
|
15
|
+
If you're starting a new project, create a new directory for your project and initialize it with npm:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
mkdir my-bsv-project
|
|
19
|
+
cd my-bsv-project
|
|
20
|
+
npm init -y
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Install TypeScript and ts-node (for executing TypeScript files directly) as dev dependencies:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install typescript ts-node --save-dev
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Create a `tsconfig.json` file to configure TypeScript options:
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"compilerOptions": {
|
|
34
|
+
"target": "es2018",
|
|
35
|
+
"module": "commonjs",
|
|
36
|
+
"strict": true,
|
|
37
|
+
"esModuleInterop": true,
|
|
38
|
+
"skipLibCheck": true,
|
|
39
|
+
"forceConsistentCasingInFileNames": true,
|
|
40
|
+
"outDir": "./dist"
|
|
41
|
+
},
|
|
42
|
+
"include": ["src/**/*"]
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
This configuration is a good starting point for Node.js projects. Adjust it as necessary for your project needs.
|
|
47
|
+
|
|
48
|
+
### Step 2: Installing BSV SDK
|
|
49
|
+
|
|
50
|
+
Install the BSV SDK using npm:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm install @bsv/sdk
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
This command installs the SDK and adds it to your project's `package.json` dependencies.
|
|
57
|
+
|
|
58
|
+
### Step 3: Creating a TypeScript File
|
|
59
|
+
|
|
60
|
+
In your project directory, create a `src` folder to hold your TypeScript files:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
mkdir src
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Inside the `src` folder, create a file named `index.ts`. This file will contain your code to interact with the BSV blockchain using the SDK.
|
|
67
|
+
|
|
68
|
+
### Step 4: Using BSV SDK in Your Project
|
|
69
|
+
|
|
70
|
+
Now, let's use the SDK to create and sign a transaction as an example. Open `src/index.ts` and add the following TypeScript code:
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { PrivateKey, Transaction } from '@bsv/sdk';
|
|
74
|
+
|
|
75
|
+
async function createAndSignTransaction() {
|
|
76
|
+
const privateKey = new PrivateKey();
|
|
77
|
+
const address = privateKey.toAddress();
|
|
78
|
+
|
|
79
|
+
const tx = new Transaction();
|
|
80
|
+
tx.from(/* UTXO details here */);
|
|
81
|
+
tx.to(address, 1000); // Send 1000 satoshis to our address
|
|
82
|
+
tx.change(address); // Return the change to our address
|
|
83
|
+
await tx.sign(privateKey);
|
|
84
|
+
|
|
85
|
+
console.log(`Transaction ID: ${tx.id()}`);
|
|
86
|
+
console.log(`Raw Transaction: ${tx.serialize()}`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
createAndSignTransaction().catch(console.error);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Note: Replace `/* UTXO details here */` with actual UTXO (Unspent Transaction Output) details. This example assumes you have some UTXOs to spend.
|
|
93
|
+
|
|
94
|
+
### Step 5: Running Your Code
|
|
95
|
+
|
|
96
|
+
Finally, run your TypeScript file with `ts-node`:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
npx ts-node src/index.ts
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
This command compiles your TypeScript code to JavaScript and executes it, displaying the transaction ID and raw transaction in the console.
|
|
103
|
+
|
|
104
|
+
### Conclusion
|
|
105
|
+
|
|
106
|
+
You've now set up a basic Node.js TypeScript project using the BSV SDK. This guide covered project initialization, SDK installation, and a simple application to create and sign transactions. Explore the SDK's extensive documentation to learn more about its features and capabilities for developing on the BSV blockchain.
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# Getting Started with BSV SDK in a Vue TypeScript Project
|
|
2
|
+
|
|
3
|
+
Welcome to the quick start guide for integrating the BSV SDK into your Vue TypeScript project. This guide will walk you through the setup and basic usage of the BSV SDK, enabling you to build scalable applications on the BSV Blockchain. Let’s dive into how you can add blockchain capabilities to your Vue application.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
Before starting, ensure you have the following installed:
|
|
8
|
+
- Node.js (12.x or later)
|
|
9
|
+
- npm (6.x or later)
|
|
10
|
+
- Vue CLI (3.x or later)
|
|
11
|
+
|
|
12
|
+
If you're new to Vue or TypeScript, it might be helpful to familiarize yourself with the basics of creating a Vue project with TypeScript support.
|
|
13
|
+
|
|
14
|
+
## Step 1: Create Your Vue Project
|
|
15
|
+
|
|
16
|
+
If you haven't already, start by creating a new Vue project. Open your terminal and run:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
vue create my-bsv-app
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
During the setup, choose "Manually select features" to select TypeScript. Follow the prompts to set up TypeScript with Vue.
|
|
23
|
+
|
|
24
|
+
## Step 2: Install the BSV SDK
|
|
25
|
+
|
|
26
|
+
Navigate to your project directory in the terminal and install the BSV SDK by running:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @bsv/sdk
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
This command will add the BSV SDK as a dependency to your project, making its functionality available for use in your Vue components.
|
|
33
|
+
|
|
34
|
+
## Step 3: Initialize the SDK in Your Vue Application
|
|
35
|
+
|
|
36
|
+
Create a new file `bsvPlugin.ts` in your project's `src` directory. This file will set up the BSV SDK so that it can be easily used throughout your application.
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
// src/bsvPlugin.ts
|
|
40
|
+
|
|
41
|
+
import { createApp } from 'vue';
|
|
42
|
+
import App from './App.vue';
|
|
43
|
+
|
|
44
|
+
// Import the SDK
|
|
45
|
+
import * as BSV from '@bsv/sdk';
|
|
46
|
+
|
|
47
|
+
const app = createApp(App);
|
|
48
|
+
|
|
49
|
+
// Here you can add BSV SDK to Vue's global properties for easy access in components
|
|
50
|
+
app.config.globalProperties.$bsv = BSV;
|
|
51
|
+
|
|
52
|
+
app.mount('#app');
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Update your `main.ts` to use this new setup:
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
// src/main.ts
|
|
59
|
+
|
|
60
|
+
import './bsvPlugin';
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Step 4: Using the BSV SDK in Your Components
|
|
64
|
+
|
|
65
|
+
Now that you have the BSV SDK integrated into your Vue application, you can start using it in your components. Here's an example of how to create and sign a transaction within a Vue component:
|
|
66
|
+
|
|
67
|
+
1. **Create a new Vue component** `TransactionComponent.vue` in your `src/components` directory.
|
|
68
|
+
2. **Implement the BSV SDK logic** within your component:
|
|
69
|
+
|
|
70
|
+
```vue
|
|
71
|
+
<template>
|
|
72
|
+
<div>
|
|
73
|
+
<h1>Create and Sign a Transaction</h1>
|
|
74
|
+
<!-- Transaction form and submission button will go here -->
|
|
75
|
+
</div>
|
|
76
|
+
</template>
|
|
77
|
+
|
|
78
|
+
<script lang="ts">
|
|
79
|
+
import { defineComponent } from 'vue';
|
|
80
|
+
|
|
81
|
+
export default defineComponent({
|
|
82
|
+
name: 'TransactionComponent',
|
|
83
|
+
methods: {
|
|
84
|
+
async createAndSignTransaction() {
|
|
85
|
+
// Access the BSV SDK from the global properties
|
|
86
|
+
const BSV = this.$bsv;
|
|
87
|
+
|
|
88
|
+
// Example: Creating a new PublicKey
|
|
89
|
+
const privateKey = BSV.PrivateKey.fromRandom();
|
|
90
|
+
const publicKey = privateKey.toPublicKey();
|
|
91
|
+
|
|
92
|
+
console.log('PublicKey:', publicKey.toString());
|
|
93
|
+
|
|
94
|
+
// Add your transaction logic here
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
</script>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Step 5: Interacting with the Blockchain
|
|
102
|
+
|
|
103
|
+
With the BSV SDK now part of your Vue application, you can extend the functionality as needed to interact with the BSV Blockchain. Use the SDK's comprehensive API to create transactions, manage keys, verify signatures, and much more.
|
package/docs/messages.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# API
|
|
2
|
+
|
|
3
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
4
|
+
|
|
5
|
+
## Classes
|
|
6
|
+
|
|
7
|
+
## Functions
|
|
8
|
+
|
|
9
|
+
## Variables
|
|
10
|
+
|
|
11
|
+
| |
|
|
12
|
+
| --- |
|
|
13
|
+
| [decrypt](#variable-decrypt) |
|
|
14
|
+
| [encrypt](#variable-encrypt) |
|
|
15
|
+
| [sign](#variable-sign) |
|
|
16
|
+
| [verify](#variable-verify) |
|
|
17
|
+
|
|
18
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
### Variable: sign
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
sign = (message: number[], signer: PrivateKey, verifier?: PublicKey): number[] => {
|
|
26
|
+
const recipientAnyone = typeof verifier !== "object";
|
|
27
|
+
if (recipientAnyone) {
|
|
28
|
+
const curve = new Curve();
|
|
29
|
+
const anyone = new PrivateKey(1);
|
|
30
|
+
const anyonePoint = curve.g.mul(anyone);
|
|
31
|
+
verifier = new PublicKey(anyonePoint.x, anyonePoint.y);
|
|
32
|
+
}
|
|
33
|
+
const keyID = Random(32);
|
|
34
|
+
const keyIDBase64 = toBase64(keyID);
|
|
35
|
+
const invoiceNumber = `2-message signing-${keyIDBase64}`;
|
|
36
|
+
const signingKey = signer.deriveChild(verifier, invoiceNumber);
|
|
37
|
+
const signature = signingKey.sign(message).toDER();
|
|
38
|
+
const senderPublicKey = signer.toPublicKey().encode(true);
|
|
39
|
+
const version = toArray(VERSION, "hex");
|
|
40
|
+
return [
|
|
41
|
+
...version,
|
|
42
|
+
...senderPublicKey,
|
|
43
|
+
...(recipientAnyone ? [0] : verifier.encode(true)),
|
|
44
|
+
...keyID,
|
|
45
|
+
...signature
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
### Variable: verify
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
verify = (message: number[], sig: number[], recipient?: PrivateKey): boolean => {
|
|
57
|
+
const reader = new Reader(sig);
|
|
58
|
+
const messageVersion = toHex(reader.read(4));
|
|
59
|
+
if (messageVersion !== VERSION) {
|
|
60
|
+
throw new Error(`Message version mismatch: Expected ${VERSION}, received ${messageVersion}`);
|
|
61
|
+
}
|
|
62
|
+
const signer = PublicKey.fromString(toHex(reader.read(33)));
|
|
63
|
+
const [verifierFirst] = reader.read(1);
|
|
64
|
+
if (verifierFirst === 0) {
|
|
65
|
+
recipient = new PrivateKey(1);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const verifierRest = reader.read(32);
|
|
69
|
+
const verifierDER = toHex([verifierFirst, ...verifierRest]);
|
|
70
|
+
if (typeof recipient !== "object") {
|
|
71
|
+
throw new Error(`This signature can only be verified with knowledge of a specific private key. The associated public key is: ${verifierDER}`);
|
|
72
|
+
}
|
|
73
|
+
const recipientDER = recipient.toPublicKey().encode(true, "hex") as string;
|
|
74
|
+
if (verifierDER !== recipientDER) {
|
|
75
|
+
throw new Error(`The recipient public key is ${recipientDER} but the signature requres the recipient to have public key ${verifierDER}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const keyID = toBase64(reader.read(32));
|
|
79
|
+
const signatureDER = toHex(reader.read(reader.bin.length - reader.pos));
|
|
80
|
+
const signature = Signature.fromDER(signatureDER, "hex");
|
|
81
|
+
const invoiceNumber = `2-message signing-${keyID}`;
|
|
82
|
+
const signingKey = signer.deriveChild(recipient, invoiceNumber);
|
|
83
|
+
const verified = signingKey.verify(message, signature);
|
|
84
|
+
return verified;
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
### Variable: encrypt
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
encrypt = (message: number[], sender: PrivateKey, recipient: PublicKey): number[] => {
|
|
95
|
+
const keyID = Random(32);
|
|
96
|
+
const keyIDBase64 = toBase64(keyID);
|
|
97
|
+
const invoiceNumber = `2-message encryption-${keyIDBase64}`;
|
|
98
|
+
const signingPriv = sender.deriveChild(recipient, invoiceNumber);
|
|
99
|
+
const recipientPub = recipient.deriveChild(sender, invoiceNumber);
|
|
100
|
+
const sharedSecret = signingPriv.deriveSharedSecret(recipientPub);
|
|
101
|
+
const symmetricKey = new SymmetricKey(sharedSecret.encode(true).slice(1));
|
|
102
|
+
const encrypted = symmetricKey.encrypt(message) as number[];
|
|
103
|
+
const senderPublicKey = sender.toPublicKey().encode(true);
|
|
104
|
+
const version = toArray(VERSION, "hex");
|
|
105
|
+
return [
|
|
106
|
+
...version,
|
|
107
|
+
...senderPublicKey,
|
|
108
|
+
...recipient.encode(true),
|
|
109
|
+
...keyID,
|
|
110
|
+
...encrypted
|
|
111
|
+
];
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
### Variable: decrypt
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
decrypt = (message: number[], recipient: PrivateKey): number[] => {
|
|
122
|
+
const reader = new Reader(message);
|
|
123
|
+
const messageVersion = toHex(reader.read(4));
|
|
124
|
+
if (messageVersion !== VERSION) {
|
|
125
|
+
throw new Error(`Message version mismatch: Expected ${VERSION}, received ${messageVersion}`);
|
|
126
|
+
}
|
|
127
|
+
const sender = PublicKey.fromString(toHex(reader.read(33)));
|
|
128
|
+
const expectedRecipientDER = toHex(reader.read(33));
|
|
129
|
+
const actualRecipientDER = recipient.toPublicKey().encode(true, "hex") as string;
|
|
130
|
+
if (expectedRecipientDER !== actualRecipientDER) {
|
|
131
|
+
throw new Error(`The encrypted message expects a recipient public key of ${expectedRecipientDER}, but the provided key is ${actualRecipientDER}`);
|
|
132
|
+
}
|
|
133
|
+
const keyID = toBase64(reader.read(32));
|
|
134
|
+
const encrypted = reader.read(reader.bin.length - reader.pos);
|
|
135
|
+
const invoiceNumber = `2-message encryption-${keyID}`;
|
|
136
|
+
const signingPriv = sender.deriveChild(recipient, invoiceNumber);
|
|
137
|
+
const recipientPub = recipient.deriveChild(sender, invoiceNumber);
|
|
138
|
+
const sharedSecret = signingPriv.deriveSharedSecret(recipientPub);
|
|
139
|
+
const symmetricKey = new SymmetricKey(sharedSecret.encode(true).slice(1));
|
|
140
|
+
return symmetricKey.decrypt(encrypted) as number[];
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
145
|
+
|
|
146
|
+
---
|