@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,90 @@
|
|
|
1
|
+
import ECIES from '../../../dist/cjs/src/compat/ECIES'
|
|
2
|
+
import * as Hash from '../../../dist/cjs/src/primitives/Hash'
|
|
3
|
+
import PrivateKey from '../../../dist/cjs/src/primitives/PrivateKey'
|
|
4
|
+
import { toArray, toHex, encode, toBase64 } from '../../../dist/cjs/src/primitives/utils'
|
|
5
|
+
|
|
6
|
+
describe('#ECIES', () => {
|
|
7
|
+
it('should make a new ECIES object', () => {
|
|
8
|
+
expect(ECIES).toBeDefined()
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
const fromkey = new PrivateKey(42)
|
|
12
|
+
const tokey = new PrivateKey(88)
|
|
13
|
+
const messageBuf = Hash.sha256(toArray('my message is the hash of this string', 'utf8'))
|
|
14
|
+
|
|
15
|
+
describe('@bitcoreEncrypt', () => {
|
|
16
|
+
it('should return a buffer', () => {
|
|
17
|
+
const encBuf = ECIES.bitcoreEncrypt(messageBuf, tokey.toPublicKey(), fromkey)
|
|
18
|
+
expect(Array.isArray(encBuf)).toEqual(true)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('should return a buffer if fromkey is not present', () => {
|
|
22
|
+
const encBuf = ECIES.bitcoreEncrypt(messageBuf, tokey.toPublicKey())
|
|
23
|
+
expect(Array.isArray(encBuf)).toEqual(true)
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
describe('@bitcoreDecrypt', () => {
|
|
28
|
+
it('should decrypt that which was encrypted', () => {
|
|
29
|
+
const encBuf = ECIES.bitcoreEncrypt(messageBuf, tokey.toPublicKey(), fromkey)
|
|
30
|
+
const messageBuf2 = ECIES.bitcoreDecrypt(encBuf, tokey)
|
|
31
|
+
expect(toHex(messageBuf2)).toEqual(toHex(messageBuf))
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('should decrypt that which was encrypted if fromPrivateKey was randomly generated', () => {
|
|
35
|
+
const encBuf = ECIES.bitcoreEncrypt(messageBuf, tokey.toPublicKey())
|
|
36
|
+
const messageBuf2 = ECIES.bitcoreDecrypt(encBuf, tokey)
|
|
37
|
+
expect(messageBuf2).toEqual(messageBuf)
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
describe('Electrum ECIES', () => {
|
|
42
|
+
// const alicePrivateKey = PrivateKey.fromString('L1Ejc5dAigm5XrM3mNptMEsNnHzS7s51YxU7J61ewGshZTKkbmzJ')
|
|
43
|
+
// const bobPrivateKey = PrivateKey.fromString('KxfxrUXSMjJQcb3JgnaaA6MqsrKQ1nBSxvhuigdKRyFiEm6BZDgG')
|
|
44
|
+
const alicePrivateKey = PrivateKey.fromString('77e06abc52bf065cb5164c5deca839d0276911991a2730be4d8d0a0307de7ceb', 16)
|
|
45
|
+
const bobPrivateKey = PrivateKey.fromString('2b57c7c5e408ce927eef5e2efb49cfdadde77961d342daa72284bb3d6590862d', 16)
|
|
46
|
+
|
|
47
|
+
it('should do these test vectors correctly', () => {
|
|
48
|
+
const message = toArray('this is my test message', 'utf8')
|
|
49
|
+
|
|
50
|
+
expect(ECIES.electrumDecrypt(
|
|
51
|
+
toArray(
|
|
52
|
+
'QklFMQOGFyMXLo9Qv047K3BYJhmnJgt58EC8skYP/R2QU/U0yXXHOt6L3tKmrXho6yj6phfoiMkBOhUldRPnEI4fSZXbiaH4FsxKIOOvzolIFVAS0FplUmib2HnlAM1yP/iiPsU=',
|
|
53
|
+
'base64'
|
|
54
|
+
),
|
|
55
|
+
alicePrivateKey
|
|
56
|
+
))
|
|
57
|
+
.toEqual(message)
|
|
58
|
+
expect(ECIES.electrumDecrypt(
|
|
59
|
+
toArray(
|
|
60
|
+
'QklFMQM55QTWSSsILaluEejwOXlrBs1IVcEB4kkqbxDz4Fap53XHOt6L3tKmrXho6yj6phfoiMkBOhUldRPnEI4fSZXbvZJHgyAzxA6SoujduvJXv+A9ri3po9veilrmc8p6dwo=',
|
|
61
|
+
'base64'
|
|
62
|
+
),
|
|
63
|
+
bobPrivateKey
|
|
64
|
+
))
|
|
65
|
+
.toEqual(message)
|
|
66
|
+
|
|
67
|
+
expect(toBase64(
|
|
68
|
+
ECIES.electrumEncrypt(message, bobPrivateKey.toPublicKey(), alicePrivateKey)
|
|
69
|
+
))
|
|
70
|
+
.toEqual(
|
|
71
|
+
'QklFMQM55QTWSSsILaluEejwOXlrBs1IVcEB4kkqbxDz4Fap53XHOt6L3tKmrXho6yj6phfoiMkBOhUldRPnEI4fSZXbvZJHgyAzxA6SoujduvJXv+A9ri3po9veilrmc8p6dwo='
|
|
72
|
+
)
|
|
73
|
+
expect(toBase64(ECIES.electrumEncrypt(message, alicePrivateKey.toPublicKey(), bobPrivateKey)))
|
|
74
|
+
.toEqual(
|
|
75
|
+
'QklFMQOGFyMXLo9Qv047K3BYJhmnJgt58EC8skYP/R2QU/U0yXXHOt6L3tKmrXho6yj6phfoiMkBOhUldRPnEI4fSZXbiaH4FsxKIOOvzolIFVAS0FplUmib2HnlAM1yP/iiPsU='
|
|
76
|
+
)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('should encrypt and decrypt symmetrically with matching strings in ECDH noKey mode', () => {
|
|
80
|
+
const message = toArray('this is my ECDH test message', 'utf8')
|
|
81
|
+
const ecdhMessageEncryptedBob = ECIES.electrumEncrypt(message, bobPrivateKey.toPublicKey(), alicePrivateKey, true)
|
|
82
|
+
const ecdhMessageEncryptedAlice = ECIES.electrumEncrypt(message, alicePrivateKey.toPublicKey(), bobPrivateKey, true)
|
|
83
|
+
expect(ecdhMessageEncryptedBob).toEqual(ecdhMessageEncryptedAlice)
|
|
84
|
+
expect(ECIES.electrumDecrypt(ecdhMessageEncryptedAlice, bobPrivateKey, alicePrivateKey.toPublicKey()))
|
|
85
|
+
.toEqual(toArray('this is my ECDH test message', 'utf8'))
|
|
86
|
+
expect(ECIES.electrumDecrypt(ecdhMessageEncryptedBob, alicePrivateKey, bobPrivateKey.toPublicKey()))
|
|
87
|
+
.toEqual(toArray('this is my ECDH test message', 'utf8'))
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
})
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
import HD from '../../../dist/cjs/src/compat/HD'
|
|
2
|
+
import { fromBase58Check, toBase58Check, toArray, toHex } from '../../../dist/cjs/src/primitives/utils'
|
|
3
|
+
|
|
4
|
+
describe('HD', () => {
|
|
5
|
+
it('should satisfy these basic API features', () => {
|
|
6
|
+
expect(HD.fromRandom().toString().slice(0, 4)).toEqual('xprv')
|
|
7
|
+
expect(HD.fromRandom().toPublic().toString().slice(0, 4)).toEqual('xpub')
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
// test vectors: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
|
|
11
|
+
const vector1master = '000102030405060708090a0b0c0d0e0f'
|
|
12
|
+
const vector1mPublic =
|
|
13
|
+
'xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8'
|
|
14
|
+
const vector1mPrivate =
|
|
15
|
+
'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi'
|
|
16
|
+
const vector1m0hPublic =
|
|
17
|
+
'xpub68Gmy5EdvgibQVfPdqkBBCHxA5htiqg55crXYuXoQRKfDBFA1WEjWgP6LHhwBZeNK1VTsfTFUHCdrfp1bgwQ9xv5ski8PX9rL2dZXvgGDnw'
|
|
18
|
+
const vector1m0hPrivate =
|
|
19
|
+
'xprv9uHRZZhk6KAJC1avXpDAp4MDc3sQKNxDiPvvkX8Br5ngLNv1TxvUxt4cV1rGL5hj6KCesnDYUhd7oWgT11eZG7XnxHrnYeSvkzY7d2bhkJ7'
|
|
20
|
+
const vector1m0h1Public =
|
|
21
|
+
'xpub6ASuArnXKPbfEwhqN6e3mwBcDTgzisQN1wXN9BJcM47sSikHjJf3UFHKkNAWbWMiGj7Wf5uMash7SyYq527Hqck2AxYysAA7xmALppuCkwQ'
|
|
22
|
+
const vector1m0h1Private =
|
|
23
|
+
'xprv9wTYmMFdV23N2TdNG573QoEsfRrWKQgWeibmLntzniatZvR9BmLnvSxqu53Kw1UmYPxLgboyZQaXwTCg8MSY3H2EU4pWcQDnRnrVA1xe8fs'
|
|
24
|
+
const vector1m0h12hPublic =
|
|
25
|
+
'xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5'
|
|
26
|
+
const vector1m0h12hPrivate =
|
|
27
|
+
'xprv9z4pot5VBttmtdRTWfWQmoH1taj2axGVzFqSb8C9xaxKymcFzXBDptWmT7FwuEzG3ryjH4ktypQSAewRiNMjANTtpgP4mLTj34bhnZX7UiM'
|
|
28
|
+
const vector1m0h12h2Public =
|
|
29
|
+
'xpub6FHa3pjLCk84BayeJxFW2SP4XRrFd1JYnxeLeU8EqN3vDfZmbqBqaGJAyiLjTAwm6ZLRQUMv1ZACTj37sR62cfN7fe5JnJ7dh8zL4fiyLHV'
|
|
30
|
+
const vector1m0h12h2Private =
|
|
31
|
+
'xprvA2JDeKCSNNZky6uBCviVfJSKyQ1mDYahRjijr5idH2WwLsEd4Hsb2Tyh8RfQMuPh7f7RtyzTtdrbdqqsunu5Mm3wDvUAKRHSC34sJ7in334'
|
|
32
|
+
const vector1m0h12h21000000000Public =
|
|
33
|
+
'xpub6H1LXWLaKsWFhvm6RVpEL9P4KfRZSW7abD2ttkWP3SSQvnyA8FSVqNTEcYFgJS2UaFcxupHiYkro49S8yGasTvXEYBVPamhGW6cFJodrTHy'
|
|
34
|
+
const vector1m0h12h21000000000Private =
|
|
35
|
+
'xprvA41z7zogVVwxVSgdKUHDy1SKmdb533PjDz7J6N6mV6uS3ze1ai8FHa8kmHScGpWmj4WggLyQjgPie1rFSruoUihUZREPSL39UNdE3BBDu76'
|
|
36
|
+
const vector2master =
|
|
37
|
+
'fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542'
|
|
38
|
+
const vector2mPublic =
|
|
39
|
+
'xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB'
|
|
40
|
+
const vector2mPrivate =
|
|
41
|
+
'xprv9s21ZrQH143K31xYSDQpPDxsXRTUcvj2iNHm5NUtrGiGG5e2DtALGdso3pGz6ssrdK4PFmM8NSpSBHNqPqm55Qn3LqFtT2emdEXVYsCzC2U'
|
|
42
|
+
const vector2m0Public =
|
|
43
|
+
'xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH'
|
|
44
|
+
const vector2m0Private =
|
|
45
|
+
'xprv9vHkqa6EV4sPZHYqZznhT2NPtPCjKuDKGY38FBWLvgaDx45zo9WQRUT3dKYnjwih2yJD9mkrocEZXo1ex8G81dwSM1fwqWpWkeS3v86pgKt'
|
|
46
|
+
const vector2m02147483647hPublic =
|
|
47
|
+
'xpub6ASAVgeehLbnwdqV6UKMHVzgqAG8Gr6riv3Fxxpj8ksbH9ebxaEyBLZ85ySDhKiLDBrQSARLq1uNRts8RuJiHjaDMBU4Zn9h8LZNnBC5y4a'
|
|
48
|
+
const vector2m02147483647hPrivate =
|
|
49
|
+
'xprv9wSp6B7kry3Vj9m1zSnLvN3xH8RdsPP1Mh7fAaR7aRLcQMKTR2vidYEeEg2mUCTAwCd6vnxVrcjfy2kRgVsFawNzmjuHc2YmYRmagcEPdU9'
|
|
50
|
+
const vector2m02147483647h1Public =
|
|
51
|
+
'xpub6DF8uhdarytz3FWdA8TvFSvvAh8dP3283MY7p2V4SeE2wyWmG5mg5EwVvmdMVCQcoNJxGoWaU9DCWh89LojfZ537wTfunKau47EL2dhHKon'
|
|
52
|
+
const vector2m02147483647h1Private =
|
|
53
|
+
'xprv9zFnWC6h2cLgpmSA46vutJzBcfJ8yaJGg8cX1e5StJh45BBciYTRXSd25UEPVuesF9yog62tGAQtHjXajPPdbRCHuWS6T8XA2ECKADdw4Ef'
|
|
54
|
+
const vector2m02147483647h12147483646hPublic =
|
|
55
|
+
'xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL'
|
|
56
|
+
const vector2m02147483647h12147483646hPrivate =
|
|
57
|
+
'xprvA1RpRA33e1JQ7ifknakTFpgNXPmW2YvmhqLQYMmrj4xJXXWYpDPS3xz7iAxn8L39njGVyuoseXzU6rcxFLJ8HFsTjSyQbLYnMpCqE2VbFWc'
|
|
58
|
+
const vector2m02147483647h12147483646h2Public =
|
|
59
|
+
'xpub6FnCn6nSzZAw5Tw7cgR9bi15UV96gLZhjDstkXXxvCLsUXBGXPdSnLFbdpq8p9HmGsApME5hQTZ3emM2rnY5agb9rXpVGyy3bdW6EEgAtqt'
|
|
60
|
+
const vector2m02147483647h12147483646h2Private =
|
|
61
|
+
'xprvA2nrNbFZABcdryreWet9Ea4LvTJcGsqrMzxHx98MMrotbir7yrKCEXw7nadnHM8Dq38EGfSh6dqA9QWTyefMLEcBYJUuekgW4BYPJcr9E7j'
|
|
62
|
+
|
|
63
|
+
it('should make a new a bip32', () => {
|
|
64
|
+
let bip32
|
|
65
|
+
bip32 = new HD()
|
|
66
|
+
expect(bip32).toBeDefined()
|
|
67
|
+
expect(new HD().fromString(vector1mPrivate).toString()).toEqual(vector1mPrivate)
|
|
68
|
+
expect(new HD()
|
|
69
|
+
.fromString(new HD().fromString(vector1mPrivate).toString())
|
|
70
|
+
.toString())
|
|
71
|
+
.toEqual(vector1mPrivate)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('should initialize test vector 1 from the extended public key', () => {
|
|
75
|
+
const bip32 = new HD().fromString(vector1mPublic)
|
|
76
|
+
expect(bip32).toBeDefined()
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('should initialize test vector 1 from the extended private key', () => {
|
|
80
|
+
const bip32 = new HD().fromString(vector1mPrivate)
|
|
81
|
+
expect(bip32).toBeDefined()
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('should get the extended public key from the extended private key for test vector 1', () => {
|
|
85
|
+
const bip32 = new HD().fromString(vector1mPrivate)
|
|
86
|
+
expect(bip32.toPublic().toString()).toEqual(vector1mPublic)
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it("should get m/0' ext. private key from test vector 1", () => {
|
|
90
|
+
const bip32 = new HD().fromString(vector1mPrivate)
|
|
91
|
+
const child = bip32.derive("m/0'")
|
|
92
|
+
expect(child).toBeDefined()
|
|
93
|
+
expect(child.toString()).toEqual(vector1m0hPrivate)
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
it("should get m/0' ext. public key from test vector 1", () => {
|
|
97
|
+
const bip32 = new HD().fromString(vector1mPrivate)
|
|
98
|
+
const child = bip32.derive("m/0'")
|
|
99
|
+
expect(child).toBeDefined()
|
|
100
|
+
expect(child.toPublic().toString()).toEqual(vector1m0hPublic)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it("should get m/0'/1 ext. private key from test vector 1", () => {
|
|
104
|
+
const bip32 = new HD().fromString(vector1mPrivate)
|
|
105
|
+
const child = bip32.derive("m/0'/1")
|
|
106
|
+
expect(child).toBeDefined()
|
|
107
|
+
expect(child.toString()).toEqual(vector1m0h1Private)
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
it("should get m/0'/1 ext. public key from test vector 1", () => {
|
|
111
|
+
const bip32 = new HD().fromString(vector1mPrivate)
|
|
112
|
+
const child = bip32.derive("m/0'/1")
|
|
113
|
+
expect(child).toBeDefined()
|
|
114
|
+
expect(child.toPublic().toString()).toEqual(vector1m0h1Public)
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
it("should get m/0'/1 ext. public key from m/0' public key from test vector 1", () => {
|
|
118
|
+
const bip32 = new HD().fromString(vector1mPrivate)
|
|
119
|
+
const child = bip32.derive("m/0'")
|
|
120
|
+
const childPub = new HD().fromString(child.toPublic().toString())
|
|
121
|
+
const child2 = childPub.derive('m/1')
|
|
122
|
+
expect(child2).toBeDefined()
|
|
123
|
+
expect(child2.toPublic().toString()).toEqual(vector1m0h1Public)
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
it("should get m/0'/1/2h ext. private key from test vector 1", () => {
|
|
127
|
+
const bip32 = new HD().fromString(vector1mPrivate)
|
|
128
|
+
const child = bip32.derive("m/0'/1/2'")
|
|
129
|
+
expect(child).toBeDefined()
|
|
130
|
+
expect(child.toString()).toEqual(vector1m0h12hPrivate)
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
it("should get m/0'/1/2h ext. public key from test vector 1", () => {
|
|
134
|
+
const bip32 = new HD().fromString(vector1mPrivate)
|
|
135
|
+
const child = bip32.derive("m/0'/1/2'")
|
|
136
|
+
expect(child).toBeDefined()
|
|
137
|
+
expect(child.toPublic().toString()).toEqual(vector1m0h12hPublic)
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
it("should get m/0'/1/2h/2 ext. private key from test vector 1", () => {
|
|
141
|
+
const bip32 = new HD().fromString(vector1mPrivate)
|
|
142
|
+
const child = bip32.derive("m/0'/1/2'/2")
|
|
143
|
+
expect(child).toBeDefined()
|
|
144
|
+
expect(child.toString()).toEqual(vector1m0h12h2Private)
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
it("should get m/0'/1/2'/2 ext. public key from m/0'/1/2' public key from test vector 1", () => {
|
|
148
|
+
const bip32 = new HD().fromString(vector1mPrivate)
|
|
149
|
+
const child = bip32.derive("m/0'/1/2'")
|
|
150
|
+
const childPub = new HD().fromString(child.toPublic().toString())
|
|
151
|
+
const child2 = childPub.derive('m/2')
|
|
152
|
+
expect(child2).toBeDefined()
|
|
153
|
+
expect(child2.toPublic().toString()).toEqual(vector1m0h12h2Public)
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
it("should get m/0'/1/2h/2 ext. public key from test vector 1", () => {
|
|
157
|
+
const bip32 = new HD().fromString(vector1mPrivate)
|
|
158
|
+
const child = bip32.derive("m/0'/1/2'/2")
|
|
159
|
+
expect(child).toBeDefined()
|
|
160
|
+
expect(child.toPublic().toString()).toEqual(vector1m0h12h2Public)
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
it("should get m/0'/1/2h/2/1000000000 ext. private key from test vector 1", () => {
|
|
164
|
+
const bip32 = new HD().fromString(vector1mPrivate)
|
|
165
|
+
const child = bip32.derive("m/0'/1/2'/2/1000000000")
|
|
166
|
+
expect(child).toBeDefined()
|
|
167
|
+
expect(child.toString()).toEqual(vector1m0h12h21000000000Private)
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
it("should get m/0'/1/2h/2/1000000000 ext. public key from test vector 1", () => {
|
|
171
|
+
const bip32 = new HD().fromString(vector1mPrivate)
|
|
172
|
+
const child = bip32.derive("m/0'/1/2'/2/1000000000")
|
|
173
|
+
expect(child).toBeDefined()
|
|
174
|
+
expect(child.toPublic().toString()).toEqual(vector1m0h12h21000000000Public)
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
it("should get m/0'/1/2'/2/1000000000 ext. public key from m/0'/1/2'/2 public key from test vector 1", () => {
|
|
178
|
+
const bip32 = new HD().fromString(vector1mPrivate)
|
|
179
|
+
const child = bip32.derive("m/0'/1/2'/2")
|
|
180
|
+
const childPub = new HD().fromString(child.toPublic().toString())
|
|
181
|
+
const child2 = childPub.derive('m/1000000000')
|
|
182
|
+
expect(child2).toBeDefined()
|
|
183
|
+
expect(child2.toPublic().toString()).toEqual(vector1m0h12h21000000000Public)
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
it('should initialize test vector 2 from the extended public key', () => {
|
|
187
|
+
const bip32 = new HD().fromString(vector2mPublic)
|
|
188
|
+
expect(bip32).toBeDefined()
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
it('should initialize test vector 2 from the extended private key', () => {
|
|
192
|
+
const bip32 = new HD().fromString(vector2mPrivate)
|
|
193
|
+
expect(bip32).toBeDefined()
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
it('should get the extended public key from the extended private key for test vector 2', () => {
|
|
197
|
+
const bip32 = new HD().fromString(vector2mPrivate)
|
|
198
|
+
expect(bip32.toPublic().toString()).toEqual(vector2mPublic)
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
it('should get m/0 ext. private key from test vector 2', () => {
|
|
202
|
+
const bip32 = new HD().fromString(vector2mPrivate)
|
|
203
|
+
const child = bip32.derive('m/0')
|
|
204
|
+
expect(child).toBeDefined()
|
|
205
|
+
expect(child.toString()).toEqual(vector2m0Private)
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
it('should get m/0 ext. public key from test vector 2', () => {
|
|
209
|
+
const bip32 = new HD().fromString(vector2mPrivate)
|
|
210
|
+
const child = bip32.derive('m/0')
|
|
211
|
+
expect(child).toBeDefined()
|
|
212
|
+
expect(child.toPublic().toString()).toEqual(vector2m0Public)
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
it('should get m/0 ext. public key from m public key from test vector 2', () => {
|
|
216
|
+
const bip32 = new HD().fromString(vector2mPrivate)
|
|
217
|
+
const child = bip32.derive('m')
|
|
218
|
+
const childPub = new HD().fromString(child.toPublic().toString())
|
|
219
|
+
const child2 = childPub.derive('m/0')
|
|
220
|
+
expect(child2).toBeDefined()
|
|
221
|
+
expect(child2.toPublic().toString()).toEqual(vector2m0Public)
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
it('should get m/0/2147483647h ext. private key from test vector 2', () => {
|
|
225
|
+
const bip32 = new HD().fromString(vector2mPrivate)
|
|
226
|
+
const child = bip32.derive("m/0/2147483647'")
|
|
227
|
+
expect(child).toBeDefined()
|
|
228
|
+
expect(child.toString()).toEqual(vector2m02147483647hPrivate)
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
it('should get m/0/2147483647h ext. public key from test vector 2', () => {
|
|
232
|
+
const bip32 = new HD().fromString(vector2mPrivate)
|
|
233
|
+
const child = bip32.derive("m/0/2147483647'")
|
|
234
|
+
expect(child).toBeDefined()
|
|
235
|
+
expect(child.toPublic().toString()).toEqual(vector2m02147483647hPublic)
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
it('should get m/0/2147483647h/1 ext. private key from test vector 2', () => {
|
|
239
|
+
const bip32 = new HD().fromString(vector2mPrivate)
|
|
240
|
+
const child = bip32.derive("m/0/2147483647'/1")
|
|
241
|
+
expect(child).toBeDefined()
|
|
242
|
+
expect(child.toString()).toEqual(vector2m02147483647h1Private)
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
it('should get m/0/2147483647h/1 ext. public key from test vector 2', () => {
|
|
246
|
+
const bip32 = new HD().fromString(vector2mPrivate)
|
|
247
|
+
const child = bip32.derive("m/0/2147483647'/1")
|
|
248
|
+
expect(child).toBeDefined()
|
|
249
|
+
expect(child.toPublic().toString()).toEqual(vector2m02147483647h1Public)
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
it('should get m/0/2147483647h/1 ext. public key from m/0/2147483647h public key from test vector 2', () => {
|
|
253
|
+
const bip32 = new HD().fromString(vector2mPrivate)
|
|
254
|
+
const child = bip32.derive("m/0/2147483647'")
|
|
255
|
+
const childPub = new HD().fromString(child.toPublic().toString())
|
|
256
|
+
const child2 = childPub.derive('m/1')
|
|
257
|
+
expect(child2).toBeDefined()
|
|
258
|
+
expect(child2.toPublic().toString()).toEqual(vector2m02147483647h1Public)
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
it('should get m/0/2147483647h/1/2147483646h ext. private key from test vector 2', () => {
|
|
262
|
+
const bip32 = new HD().fromString(vector2mPrivate)
|
|
263
|
+
const child = bip32.derive("m/0/2147483647'/1/2147483646'")
|
|
264
|
+
expect(child).toBeDefined()
|
|
265
|
+
expect(child.toString()).toEqual(vector2m02147483647h12147483646hPrivate)
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
it('should get m/0/2147483647h/1/2147483646h ext. public key from test vector 2', () => {
|
|
269
|
+
const bip32 = new HD().fromString(vector2mPrivate)
|
|
270
|
+
const child = bip32.derive("m/0/2147483647'/1/2147483646'")
|
|
271
|
+
expect(child).toBeDefined()
|
|
272
|
+
expect(child.toPublic().toString()).toEqual(vector2m02147483647h12147483646hPublic)
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
it('should get m/0/2147483647h/1/2147483646h/2 ext. private key from test vector 2', () => {
|
|
276
|
+
const bip32 = new HD().fromString(vector2mPrivate)
|
|
277
|
+
const child = bip32.derive("m/0/2147483647'/1/2147483646'/2")
|
|
278
|
+
expect(child).toBeDefined()
|
|
279
|
+
expect(child.toString()).toEqual(vector2m02147483647h12147483646h2Private)
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
it('should get m/0/2147483647h/1/2147483646h/2 ext. public key from test vector 2', () => {
|
|
283
|
+
const bip32 = new HD().fromString(vector2mPrivate)
|
|
284
|
+
const child = bip32.derive("m/0/2147483647'/1/2147483646'/2")
|
|
285
|
+
expect(child).toBeDefined()
|
|
286
|
+
expect(child.toPublic().toString()).toEqual(vector2m02147483647h12147483646h2Public)
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
it('should get m/0/2147483647h/1/2147483646h/2 ext. public key from m/0/2147483647h/2147483646h public key from test vector 2', () => {
|
|
290
|
+
const bip32 = new HD().fromString(vector2mPrivate)
|
|
291
|
+
const child = bip32.derive("m/0/2147483647'/1/2147483646'")
|
|
292
|
+
const childPub = new HD().fromString(child.toPublic().toString())
|
|
293
|
+
const child2 = childPub.derive('m/2')
|
|
294
|
+
expect(child2).toBeDefined()
|
|
295
|
+
expect(child2.toPublic().toString()).toEqual(vector2m02147483647h12147483646h2Public)
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
describe('#fromRandom', () => {
|
|
299
|
+
it('should not return the same one twice', () => {
|
|
300
|
+
const bip32a = new HD().fromRandom()
|
|
301
|
+
const bip32b = new HD().fromRandom()
|
|
302
|
+
expect(bip32a.toString()).not.toEqual(bip32b.toString())
|
|
303
|
+
})
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
describe('@fromRandom', () => {
|
|
307
|
+
it('should not return the same one twice', () => {
|
|
308
|
+
const bip32a = HD.fromRandom()
|
|
309
|
+
const bip32b = HD.fromRandom()
|
|
310
|
+
expect(bip32a.toString()).not.toEqual(bip32b.toString())
|
|
311
|
+
})
|
|
312
|
+
})
|
|
313
|
+
|
|
314
|
+
describe('#fromSeed', () => {
|
|
315
|
+
it('should initialize a new Bip32 correctly from test vector 1 seed', () => {
|
|
316
|
+
const hex = vector1master
|
|
317
|
+
const bip32 = new HD().fromSeed(toArray(hex, 'hex'))
|
|
318
|
+
expect(bip32).toBeDefined()
|
|
319
|
+
expect(bip32.toString()).toEqual(vector1mPrivate)
|
|
320
|
+
expect(bip32.toPublic().toString()).toEqual(vector1mPublic)
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
it('should initialize a new Bip32 correctly from test vector 2 seed', () => {
|
|
324
|
+
const hex = vector2master
|
|
325
|
+
const bip32 = new HD().fromSeed(toArray(hex, 'hex'))
|
|
326
|
+
expect(bip32).toBeDefined()
|
|
327
|
+
expect(bip32.toString()).toEqual(vector2mPrivate)
|
|
328
|
+
expect(bip32.toPublic().toString()).toEqual(vector2mPublic)
|
|
329
|
+
})
|
|
330
|
+
})
|
|
331
|
+
|
|
332
|
+
describe('@fromSeed', () => {
|
|
333
|
+
it('should initialize a new Bip32 correctly from test vector 1 seed', () => {
|
|
334
|
+
const hex = vector1master
|
|
335
|
+
const bip32 = HD.fromSeed(toArray(hex, 'hex'))
|
|
336
|
+
expect(bip32).toBeDefined()
|
|
337
|
+
expect(bip32.toString()).toEqual(vector1mPrivate)
|
|
338
|
+
expect(bip32.toPublic().toString()).toEqual(vector1mPublic)
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
it('should initialize a new Bip32 correctly from test vector 2 seed', () => {
|
|
342
|
+
const hex = vector2master
|
|
343
|
+
const bip32 = HD.fromSeed(toArray(hex, 'hex'))
|
|
344
|
+
expect(bip32).toBeDefined()
|
|
345
|
+
expect(bip32.toString()).toEqual(vector2mPrivate)
|
|
346
|
+
expect(bip32.toPublic().toString()).toEqual(vector2mPublic)
|
|
347
|
+
})
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
describe('#fromBinary', () => {
|
|
351
|
+
it('should make a bip32 from binary', () => {
|
|
352
|
+
const str =
|
|
353
|
+
'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi'
|
|
354
|
+
const buf = fromBase58Check(str)
|
|
355
|
+
let bip32 = new HD().fromBinary([...buf.prefix, ...buf.data])
|
|
356
|
+
expect(bip32).toBeDefined()
|
|
357
|
+
expect(bip32.toString()).toEqual(str)
|
|
358
|
+
bip32 = bip32.toPublic()
|
|
359
|
+
const xpub = bip32.toString()
|
|
360
|
+
bip32 = new HD().fromBinary(bip32.toBinary())
|
|
361
|
+
expect(bip32.toString()).toEqual(xpub)
|
|
362
|
+
})
|
|
363
|
+
})
|
|
364
|
+
|
|
365
|
+
describe('#toBinary', () => {
|
|
366
|
+
it('should return a bip32 buffer', () => {
|
|
367
|
+
const str =
|
|
368
|
+
'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi'
|
|
369
|
+
const buf = fromBase58Check(str)
|
|
370
|
+
const bip32 = new HD().fromString(str)
|
|
371
|
+
expect(toHex(bip32.toBinary())).toEqual(toHex([...buf.prefix, ...buf.data]))
|
|
372
|
+
})
|
|
373
|
+
})
|
|
374
|
+
|
|
375
|
+
describe('#fromString', () => {
|
|
376
|
+
it('should make a bip32 from a string', () => {
|
|
377
|
+
const str =
|
|
378
|
+
'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi'
|
|
379
|
+
const bip32 = new HD().fromString(str)
|
|
380
|
+
expect(bip32).toBeDefined()
|
|
381
|
+
expect(bip32.toString()).toEqual(str)
|
|
382
|
+
})
|
|
383
|
+
})
|
|
384
|
+
|
|
385
|
+
describe('#toString', () => {
|
|
386
|
+
const bip32 = new HD()
|
|
387
|
+
bip32.fromRandom()
|
|
388
|
+
it('should return an xprv string', () => {
|
|
389
|
+
expect(bip32.toString().slice(0, 4)).toEqual('xprv')
|
|
390
|
+
})
|
|
391
|
+
|
|
392
|
+
it('should return an xpub string', () => {
|
|
393
|
+
expect(bip32.toPublic().toString().slice(0, 4)).toEqual('xpub')
|
|
394
|
+
})
|
|
395
|
+
})
|
|
396
|
+
|
|
397
|
+
describe('#isPrivate', () => {
|
|
398
|
+
it('should know if this bip32 is private', () => {
|
|
399
|
+
const bip32priv = new HD().fromRandom()
|
|
400
|
+
const bip32pub = bip32priv.toPublic()
|
|
401
|
+
expect(bip32priv.isPrivate()).toEqual(true)
|
|
402
|
+
expect(bip32pub.isPrivate()).toEqual(false)
|
|
403
|
+
})
|
|
404
|
+
})
|
|
405
|
+
})
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import Mnemonic from '../../../dist/cjs/src/compat/Mnemonic'
|
|
2
|
+
import { wordList as enWordList } from '../../../dist/cjs/src/compat/bip-39-wordlist-en'
|
|
3
|
+
import Random from '../../../dist/cjs/src/primitives/Random'
|
|
4
|
+
import vectors from './Mnemonic.vectors'
|
|
5
|
+
import HD from '../../../dist/cjs/src/compat/HD'
|
|
6
|
+
import { toBase58Check, toHex, toArray } from '../../../dist/cjs/src/primitives/utils'
|
|
7
|
+
|
|
8
|
+
describe('Mnemonic', function () {
|
|
9
|
+
it('should initialize the class', () => {
|
|
10
|
+
expect(Mnemonic).toBeDefined()
|
|
11
|
+
expect(new Mnemonic()).toBeDefined()
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('should have a wordlist of length 2048', () => {
|
|
15
|
+
expect(enWordList.value.length).toEqual(2048)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('should handle this community-derived test vector', () => {
|
|
19
|
+
// There was a bug in Copay and bip32jp about deriving addresses with Mnemonic
|
|
20
|
+
// and bip44. This confirms we are handling the situation correctly and
|
|
21
|
+
// derive the correct value.
|
|
22
|
+
//
|
|
23
|
+
// More information here:
|
|
24
|
+
// https://github.com/iancoleman/bip39/issues/58
|
|
25
|
+
const seed = Mnemonic.fromString('fruit wave dwarf banana earth journey tattoo true farm silk olive fence').toSeed(
|
|
26
|
+
'banana'
|
|
27
|
+
)
|
|
28
|
+
let bip32 = HD.fromSeed(seed)
|
|
29
|
+
bip32 = bip32.derive("m/44'/0'/0'/0/0")
|
|
30
|
+
const pkh = bip32.pubKey.toHash()
|
|
31
|
+
const addr = toBase58Check(pkh)
|
|
32
|
+
expect(addr).toEqual('17rxURoF96VhmkcEGCj5LNQkmN9HVhWb7F')
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('should generate a mnemonic phrase that passes the check', () => {
|
|
36
|
+
let mnemonic
|
|
37
|
+
|
|
38
|
+
// should be able to make a mnemonic with or without the default wordlist
|
|
39
|
+
let m = new Mnemonic().fromRandom(128)
|
|
40
|
+
expect(m.check()).toEqual(true)
|
|
41
|
+
m = new Mnemonic().fromRandom(128)
|
|
42
|
+
expect(m.check()).toEqual(true)
|
|
43
|
+
|
|
44
|
+
const entropy = Array(32)
|
|
45
|
+
entropy.fill(0)
|
|
46
|
+
m = new Mnemonic().fromEntropy(entropy)
|
|
47
|
+
expect(m.check()).toEqual(true)
|
|
48
|
+
|
|
49
|
+
mnemonic = m.mnemonic
|
|
50
|
+
|
|
51
|
+
// mnemonics with extra whitespace do not pass the check
|
|
52
|
+
m = new Mnemonic().fromString(mnemonic + ' ')
|
|
53
|
+
expect(m.check()).toEqual(false)
|
|
54
|
+
|
|
55
|
+
// mnemonics with a word replaced do not pass the check
|
|
56
|
+
const words = mnemonic.split(' ')
|
|
57
|
+
expect(words[words.length - 1]).not.toEqual('zoo')
|
|
58
|
+
words[words.length - 1] = 'zoo'
|
|
59
|
+
mnemonic = words.join(' ')
|
|
60
|
+
expect(new Mnemonic().fromString(mnemonic).check()).toEqual(false)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
describe('#toBinary', () => {
|
|
64
|
+
it('should convert to a binary array', () => {
|
|
65
|
+
const m = new Mnemonic().fromRandom()
|
|
66
|
+
expect(m.seed).toBeDefined()
|
|
67
|
+
expect(m.mnemonic).toBeDefined()
|
|
68
|
+
const buf = m.toBinary()
|
|
69
|
+
expect(buf.length).toBeGreaterThan(512 / 8 + 1 + 1)
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
describe('#fromBinary', () => {
|
|
74
|
+
it('should convert from a binary array', () => {
|
|
75
|
+
const mA = new Mnemonic().fromRandom()
|
|
76
|
+
const mB = new Mnemonic().fromBinary(mA.toBinary())
|
|
77
|
+
expect(mA.mnemonic).toEqual(mB.mnemonic)
|
|
78
|
+
expect(toHex(mA.seed as number[])).toEqual(toHex(mB.seed as number[]))
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
describe('#fromRandom', () => {
|
|
83
|
+
it('should throw an error if bits is too low', () => {
|
|
84
|
+
expect(() => {
|
|
85
|
+
new Mnemonic().fromRandom(127)
|
|
86
|
+
}).toThrow('bits must be multiple of 32')
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('should throw an error if bits is not a multiple of 32', () => {
|
|
90
|
+
expect(() => {
|
|
91
|
+
new Mnemonic().fromRandom(256 - 1)
|
|
92
|
+
}).toThrow('bits must be multiple of 32')
|
|
93
|
+
})
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
describe('@fromRandom', () => {
|
|
97
|
+
it('should throw an error if bits is too low', () => {
|
|
98
|
+
expect(() => {
|
|
99
|
+
Mnemonic.fromRandom(127)
|
|
100
|
+
}).toThrow('bits must be multiple of 32')
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it('should throw an error if bits is not a multiple of 32', () => {
|
|
104
|
+
expect(() => {
|
|
105
|
+
Mnemonic.fromRandom(256 - 1)
|
|
106
|
+
}).toThrow('bits must be multiple of 32')
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
describe('#fromEntropy', () => {
|
|
111
|
+
it('should build from entropy', () => {
|
|
112
|
+
const m = new Mnemonic().fromEntropy(Random(32))
|
|
113
|
+
expect(m).toBeDefined()
|
|
114
|
+
})
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
describe('@fromEntropy', () => {
|
|
118
|
+
it('should build from entropy', () => {
|
|
119
|
+
const m = Mnemonic.fromEntropy(Random(32))
|
|
120
|
+
expect(m).toBeDefined()
|
|
121
|
+
})
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
describe('#entropy2Mnemonic', () => {
|
|
125
|
+
it('should throw an error if you do not use enough entropy', () => {
|
|
126
|
+
const buf = Buffer.alloc(128 / 8 - 1)
|
|
127
|
+
buf.fill(0)
|
|
128
|
+
expect(() => {
|
|
129
|
+
new Mnemonic().entropy2Mnemonic([...buf])
|
|
130
|
+
}).toThrow('Entropy is less than 128 bits. It must be 128 bits or more.')
|
|
131
|
+
})
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
describe('#fromString', () => {
|
|
135
|
+
it('should throw an error in invalid mnemonic', () => {
|
|
136
|
+
expect(() => {
|
|
137
|
+
new Mnemonic().fromString('invalid mnemonic').toSeed()
|
|
138
|
+
}).toThrow(
|
|
139
|
+
'Mnemonic does not pass the check - was the mnemonic typed incorrectly? Are there extra spaces?'
|
|
140
|
+
)
|
|
141
|
+
})
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
describe('@isValid', () => {
|
|
145
|
+
it('should know this is valid', () => {
|
|
146
|
+
const isValid = Mnemonic.isValid(
|
|
147
|
+
'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about',
|
|
148
|
+
'TREZOR'
|
|
149
|
+
)
|
|
150
|
+
expect(isValid).toBe(true)
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
it('should know this is invalid', () => {
|
|
154
|
+
const isValid = Mnemonic.isValid(
|
|
155
|
+
'abandonnnnnnn abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about',
|
|
156
|
+
'TREZOR'
|
|
157
|
+
)
|
|
158
|
+
expect(isValid).toEqual(false)
|
|
159
|
+
})
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
describe('vectors', () => {
|
|
163
|
+
// eslint-disable-next-line ban/ban
|
|
164
|
+
vectors.english.forEach((vector, v) => {
|
|
165
|
+
it('should pass english test vector ' + v, () => {
|
|
166
|
+
const entropy = toArray(vector.entropy, 'hex')
|
|
167
|
+
const m = new Mnemonic().fromEntropy(entropy)
|
|
168
|
+
expect(m.toString()).toEqual(vector.mnemonic)
|
|
169
|
+
expect(m.check()).toEqual(true)
|
|
170
|
+
const seed = m.toSeed(vector.passphrase)
|
|
171
|
+
expect(toHex(seed)).toEqual(vector.seed)
|
|
172
|
+
expect(HD.fromSeed(seed).toString()).toEqual(vector.bip32_xprv)
|
|
173
|
+
})
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
})
|
|
177
|
+
})
|