@bsv/sdk 1.0.29 → 1.0.31
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/dist/cjs/mod.js +25 -0
- package/dist/cjs/mod.js.map +1 -0
- package/dist/cjs/package.json +49 -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 +512 -0
- package/dist/cjs/src/compat/ECIES.js.map +1 -0
- package/dist/cjs/src/compat/HD.js +344 -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 +4272 -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 +1387 -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 +246 -0
- package/dist/cjs/src/primitives/PrivateKey.js.map +1 -0
- package/dist/cjs/src/primitives/PublicKey.js +168 -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 +357 -0
- package/dist/cjs/src/primitives/Signature.js.map +1 -0
- package/dist/cjs/src/primitives/SymmetricKey.js +82 -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 +51 -0
- package/dist/cjs/src/primitives/index.js.map +1 -0
- package/dist/cjs/src/primitives/utils.js +624 -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 +207 -0
- package/dist/cjs/src/script/OP.js.map +1 -0
- package/dist/cjs/src/script/Script.js +435 -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 +120 -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 +616 -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 +112 -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/BSM.js +45 -0
- package/dist/esm/src/compat/BSM.js.map +1 -0
- package/dist/esm/src/compat/ECIES.js +483 -0
- package/dist/esm/src/compat/ECIES.js.map +1 -0
- package/dist/esm/src/compat/HD.js +322 -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 +4307 -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 +1391 -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 +240 -0
- package/dist/esm/src/primitives/PrivateKey.js.map +1 -0
- package/dist/esm/src/primitives/PublicKey.js +162 -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 +360 -0
- package/dist/esm/src/primitives/Signature.js.map +1 -0
- package/dist/esm/src/primitives/SymmetricKey.js +76 -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 +13 -0
- package/dist/esm/src/primitives/index.js.map +1 -0
- package/dist/esm/src/primitives/utils.js +609 -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 +205 -0
- package/dist/esm/src/script/OP.js.map +1 -0
- package/dist/esm/src/script/Script.js +430 -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 +113 -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 +617 -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 +111 -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/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 +131 -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 +450 -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 +174 -0
- package/dist/types/src/primitives/PrivateKey.d.ts.map +1 -0
- package/dist/types/src/primitives/PublicKey.d.ts +120 -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 +162 -0
- package/dist/types/src/primitives/Signature.d.ts.map +1 -0
- package/dist/types/src/primitives/SymmetricKey.d.ts +55 -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 +13 -0
- package/dist/types/src/primitives/index.d.ts.map +1 -0
- package/dist/types/src/primitives/utils.d.ts +124 -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 +40 -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 +215 -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/package.json +1 -1
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import BasePoint from './BasePoint.js';
|
|
2
|
+
import JPoint from './JacobianPoint.js';
|
|
3
|
+
import BigNumber from './BigNumber.js';
|
|
4
|
+
/**
|
|
5
|
+
* `Point` class is a representation of an elliptic curve point with affine coordinates.
|
|
6
|
+
* It extends the functionality of BasePoint and carries x, y coordinates of point on the curve.
|
|
7
|
+
* It also introduces new methods for handling Point operations in elliptic curve.
|
|
8
|
+
*
|
|
9
|
+
* @class Point
|
|
10
|
+
* @extends {BasePoint}
|
|
11
|
+
*
|
|
12
|
+
* @property x - The x-coordinate of the point.
|
|
13
|
+
* @property y - The y-coordinate of the point.
|
|
14
|
+
* @property inf - Flag to record if the point is at infinity in the Elliptic Curve.
|
|
15
|
+
*/
|
|
16
|
+
export default class Point extends BasePoint {
|
|
17
|
+
x: BigNumber | null;
|
|
18
|
+
y: BigNumber | null;
|
|
19
|
+
inf: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a point object from a given string. This string can represent coordinates in hex format, or points
|
|
22
|
+
* in multiple established formats.
|
|
23
|
+
* The function verifies the integrity of the provided data and throws errors if inconsistencies are found.
|
|
24
|
+
*
|
|
25
|
+
* @method fromString
|
|
26
|
+
* @static
|
|
27
|
+
* @param str - The point representation string.
|
|
28
|
+
* @returns Returns a new point representing the given string.
|
|
29
|
+
* @throws `Error` If the point string value has a wrong length.
|
|
30
|
+
* @throws `Error` If the point format is unknown.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* const pointStr = 'abcdef';
|
|
34
|
+
* const point = Point.fromString(pointStr);
|
|
35
|
+
*/
|
|
36
|
+
static fromString(str: string): Point;
|
|
37
|
+
/**
|
|
38
|
+
* Generates a point from an x coordinate and a boolean indicating whether the corresponding
|
|
39
|
+
* y coordinate is odd.
|
|
40
|
+
*
|
|
41
|
+
* @method fromX
|
|
42
|
+
* @static
|
|
43
|
+
* @param x - The x coordinate of the point.
|
|
44
|
+
* @param odd - Boolean indicating whether the corresponding y coordinate is odd or not.
|
|
45
|
+
* @returns Returns the new point.
|
|
46
|
+
* @throws `Error` If the point is invalid.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const xCoordinate = new BigNumber('10');
|
|
50
|
+
* const point = Point.fromX(xCoordinate, true);
|
|
51
|
+
*/
|
|
52
|
+
static fromX(x: BigNumber | number | number[] | string, odd: boolean): Point;
|
|
53
|
+
/**
|
|
54
|
+
* Generates a point from a serialized JSON object. The function accounts for different options in the JSON object,
|
|
55
|
+
* including precomputed values for optimization of EC operations, and calls another helper function to turn nested
|
|
56
|
+
* JSON points into proper Point objects.
|
|
57
|
+
*
|
|
58
|
+
* @method fromJSON
|
|
59
|
+
* @static
|
|
60
|
+
* @param obj - An object or array that holds the data for the point.
|
|
61
|
+
* @param isRed - A boolean to direct how the Point is constructed from the JSON object.
|
|
62
|
+
* @returns Returns a new point based on the deserialized JSON object.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* const serializedPoint = '{"x":52,"y":15}';
|
|
66
|
+
* const point = Point.fromJSON(serializedPoint, true);
|
|
67
|
+
*/
|
|
68
|
+
static fromJSON(obj: string | any[], isRed: boolean): Point;
|
|
69
|
+
/**
|
|
70
|
+
* @constructor
|
|
71
|
+
* @param x - The x-coordinate of the point. May be a number, a BigNumber, a string (which will be interpreted as hex), a number array, or null. If null, an "Infinity" point is constructed.
|
|
72
|
+
* @param y - The y-coordinate of the point, similar to x.
|
|
73
|
+
* @param isRed - A boolean indicating if the point is a member of the field of integers modulo the k256 prime. Default is true.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* new Point('abc123', 'def456');
|
|
77
|
+
* new Point(null, null); // Generates Infinity point.
|
|
78
|
+
*/
|
|
79
|
+
constructor(x: BigNumber | number | number[] | string | null, y: BigNumber | number | number[] | string | null, isRed?: boolean);
|
|
80
|
+
/**
|
|
81
|
+
* Validates if a point belongs to the curve. Follows the short Weierstrass
|
|
82
|
+
* equation for elliptic curves: y^2 = x^3 + ax + b.
|
|
83
|
+
*
|
|
84
|
+
* @method validate
|
|
85
|
+
* @returns {boolean} true if the point is on the curve, false otherwise.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* const aPoint = new Point(x, y);
|
|
89
|
+
* const isValid = aPoint.validate();
|
|
90
|
+
*/
|
|
91
|
+
validate(): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Encodes the coordinates of a point into an array or a hexadecimal string.
|
|
94
|
+
* The details of encoding are determined by the optional compact and enc parameters.
|
|
95
|
+
*
|
|
96
|
+
* @method encode
|
|
97
|
+
* @param compact - If true, an additional prefix byte 0x02 or 0x03 based on the 'y' coordinate being even or odd respectively is used. If false, byte 0x04 is used.
|
|
98
|
+
* @param enc - Expects the string 'hex' if hexadecimal string encoding is required instead of an array of numbers.
|
|
99
|
+
* @throws Will throw an error if the specified encoding method is not recognized. Expects 'hex'.
|
|
100
|
+
* @returns If enc is undefined, a byte array representation of the point will be returned. if enc is 'hex', a hexadecimal string representation of the point will be returned.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* const aPoint = new Point(x, y);
|
|
104
|
+
* const encodedPointArray = aPoint.encode();
|
|
105
|
+
* const encodedPointHex = aPoint.encode(true, 'hex');
|
|
106
|
+
*/
|
|
107
|
+
encode(compact?: boolean, enc?: 'hex'): number[] | string;
|
|
108
|
+
/**
|
|
109
|
+
* Converts the point coordinates to a hexadecimal string. A wrapper method
|
|
110
|
+
* for encode. Byte 0x02 or 0x03 is used as prefix based on the 'y' coordinate being even or odd respectively.
|
|
111
|
+
*
|
|
112
|
+
* @method toString
|
|
113
|
+
* @returns {string} A hexadecimal string representation of the point coordinates.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* const aPoint = new Point(x, y);
|
|
117
|
+
* const stringPoint = aPoint.toString();
|
|
118
|
+
*/
|
|
119
|
+
toString(): string;
|
|
120
|
+
/**
|
|
121
|
+
* Exports the x and y coordinates of the point, and the precomputed doubles and non-adjacent form (NAF) for optimization. The output is an array.
|
|
122
|
+
*
|
|
123
|
+
* @method toJSON
|
|
124
|
+
* @returns An Array where first two elements are the coordinates of the point and optional third element is an object with doubles and NAF points.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* const aPoint = new Point(x, y);
|
|
128
|
+
* const jsonPoint = aPoint.toJSON();
|
|
129
|
+
*/
|
|
130
|
+
toJSON(): [BigNumber | null, BigNumber | null, {
|
|
131
|
+
doubles: {
|
|
132
|
+
step: any;
|
|
133
|
+
points: any[];
|
|
134
|
+
} | undefined;
|
|
135
|
+
naf: {
|
|
136
|
+
wnd: any;
|
|
137
|
+
points: any[];
|
|
138
|
+
} | undefined;
|
|
139
|
+
}?];
|
|
140
|
+
/**
|
|
141
|
+
* Provides the point coordinates in a human-readable string format for debugging purposes.
|
|
142
|
+
*
|
|
143
|
+
* @method inspect
|
|
144
|
+
* @returns String of the format '<EC Point x: x-coordinate y: y-coordinate>', or '<EC Point Infinity>' if the point is at infinity.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* const aPoint = new Point(x, y);
|
|
148
|
+
* console.log(aPoint.inspect());
|
|
149
|
+
*/
|
|
150
|
+
inspect(): string;
|
|
151
|
+
/**
|
|
152
|
+
* Checks if the point is at infinity.
|
|
153
|
+
* @method isInfinity
|
|
154
|
+
* @returns Returns whether or not the point is at infinity.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* const p = new Point(null, null);
|
|
158
|
+
* console.log(p.isInfinity()); // outputs: true
|
|
159
|
+
*/
|
|
160
|
+
isInfinity(): boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Adds another Point to this Point, returning a new Point.
|
|
163
|
+
*
|
|
164
|
+
* @method add
|
|
165
|
+
* @param p - The Point to add to this one.
|
|
166
|
+
* @returns A new Point that results from the addition.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* const p1 = new Point(1, 2);
|
|
170
|
+
* const p2 = new Point(2, 3);
|
|
171
|
+
* const result = p1.add(p2);
|
|
172
|
+
*/
|
|
173
|
+
add(p: Point): Point;
|
|
174
|
+
/**
|
|
175
|
+
* Doubles the current point.
|
|
176
|
+
*
|
|
177
|
+
* @method dbl
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* const P = new Point('123', '456');
|
|
181
|
+
* const result = P.dbl();
|
|
182
|
+
* */
|
|
183
|
+
dbl(): Point;
|
|
184
|
+
/**
|
|
185
|
+
* Returns X coordinate of point
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* const P = new Point('123', '456');
|
|
189
|
+
* const x = P.getX();
|
|
190
|
+
*/
|
|
191
|
+
getX(): BigNumber;
|
|
192
|
+
/**
|
|
193
|
+
* Returns X coordinate of point
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* const P = new Point('123', '456');
|
|
197
|
+
* const x = P.getX();
|
|
198
|
+
*/
|
|
199
|
+
getY(): BigNumber;
|
|
200
|
+
/**
|
|
201
|
+
* Multiplies this Point by a scalar value, returning a new Point.
|
|
202
|
+
*
|
|
203
|
+
* @method mul
|
|
204
|
+
* @param k - The scalar value to multiply this Point by.
|
|
205
|
+
* @returns A new Point that results from the multiplication.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* const p = new Point(1, 2);
|
|
209
|
+
* const result = p.mul(2); // this doubles the Point
|
|
210
|
+
*/
|
|
211
|
+
mul(k: BigNumber | number | number[] | string): Point;
|
|
212
|
+
/**
|
|
213
|
+
* Performs a multiplication and addition operation in a single step.
|
|
214
|
+
* Multiplies this Point by k1, adds the resulting Point to the result of p2 multiplied by k2.
|
|
215
|
+
*
|
|
216
|
+
* @method mulAdd
|
|
217
|
+
* @param k1 - The scalar value to multiply this Point by.
|
|
218
|
+
* @param p2 - The other Point to be involved in the operation.
|
|
219
|
+
* @param k2 - The scalar value to multiply the Point p2 by.
|
|
220
|
+
* @returns A Point that results from the combined multiplication and addition operations.
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* const p1 = new Point(1, 2);
|
|
224
|
+
* const p2 = new Point(2, 3);
|
|
225
|
+
* const result = p1.mulAdd(2, p2, 3);
|
|
226
|
+
*/
|
|
227
|
+
mulAdd(k1: BigNumber, p2: Point, k2: BigNumber): Point;
|
|
228
|
+
/**
|
|
229
|
+
* Performs the Jacobian multiplication and addition operation in a single
|
|
230
|
+
* step. Instead of returning a regular Point, the result is a JacobianPoint.
|
|
231
|
+
*
|
|
232
|
+
* @method jmulAdd
|
|
233
|
+
* @param k1 - The scalar value to multiply this Point by.
|
|
234
|
+
* @param p2 - The other Point to be involved in the operation
|
|
235
|
+
* @param k2 - The scalar value to multiply the Point p2 by.
|
|
236
|
+
* @returns A JacobianPoint that results from the combined multiplication and addition operation.
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* const p1 = new Point(1, 2);
|
|
240
|
+
* const p2 = new Point(2, 3);
|
|
241
|
+
* const result = p1.jmulAdd(2, p2, 3);
|
|
242
|
+
*/
|
|
243
|
+
jmulAdd(k1: BigNumber, p2: Point, k2: BigNumber): JPoint;
|
|
244
|
+
/**
|
|
245
|
+
* Checks if the Point instance is equal to another given Point.
|
|
246
|
+
*
|
|
247
|
+
* @method eq
|
|
248
|
+
* @param p - The Point to be checked if equal to the current instance.
|
|
249
|
+
*
|
|
250
|
+
* @returns Whether the two Point instances are equal. Both the 'x' and 'y' coordinates have to match, and both points have to either be valid or at infinity for equality. If both conditions are true, it returns true, else it returns false.
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* const p1 = new Point(5, 20);
|
|
254
|
+
* const p2 = new Point(5, 20);
|
|
255
|
+
* const areEqual = p1.eq(p2); // returns true
|
|
256
|
+
*/
|
|
257
|
+
eq(p: Point): boolean;
|
|
258
|
+
/**
|
|
259
|
+
* Negate a point. The negation of a point P is the mirror of P about x-axis.
|
|
260
|
+
*
|
|
261
|
+
* @method neg
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* const P = new Point('123', '456');
|
|
265
|
+
* const result = P.neg();
|
|
266
|
+
*/
|
|
267
|
+
neg(_precompute?: boolean): Point;
|
|
268
|
+
/**
|
|
269
|
+
* Performs the "doubling" operation on the Point a given number of times.
|
|
270
|
+
* This is used in elliptic curve operations to perform multiplication by 2, multiple times.
|
|
271
|
+
* If the point is at infinity, it simply returns the point because doubling
|
|
272
|
+
* a point at infinity is still infinity.
|
|
273
|
+
*
|
|
274
|
+
* @method dblp
|
|
275
|
+
* @param k - The number of times the "doubling" operation is to be performed on the Point.
|
|
276
|
+
* @returns The Point after 'k' "doubling" operations have been performed.
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* const p = new Point(5, 20);
|
|
280
|
+
* const doubledPoint = p.dblp(10); // returns the point after "doubled" 10 times
|
|
281
|
+
*/
|
|
282
|
+
dblp(k: number): Point;
|
|
283
|
+
/**
|
|
284
|
+
* Converts the point to a Jacobian point. If the point is at infinity, the corresponding Jacobian point
|
|
285
|
+
* will also be at infinity.
|
|
286
|
+
*
|
|
287
|
+
* @method toJ
|
|
288
|
+
* @returns Returns a new Jacobian point based on the current point.
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
* const point = new Point(xCoordinate, yCoordinate);
|
|
292
|
+
* const jacobianPoint = point.toJ();
|
|
293
|
+
*/
|
|
294
|
+
toJ(): JPoint;
|
|
295
|
+
private _getBeta;
|
|
296
|
+
private _fixedNafMul;
|
|
297
|
+
private _wnafMulAdd;
|
|
298
|
+
private _endoWnafMulAdd;
|
|
299
|
+
private _hasDoubles;
|
|
300
|
+
private _getDoubles;
|
|
301
|
+
private _getNAFPoints;
|
|
302
|
+
}
|
|
303
|
+
//# sourceMappingURL=Point.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Point.d.ts","sourceRoot":"","sources":["../../../../src/primitives/Point.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAA;AACtC,OAAO,MAAM,MAAM,oBAAoB,CAAA;AACvC,OAAO,SAAS,MAAM,gBAAgB,CAAA;AAItC;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,OAAO,KAAM,SAAQ,SAAS;IAC1C,CAAC,EAAE,SAAS,GAAG,IAAI,CAAA;IACnB,CAAC,EAAE,SAAS,GAAG,IAAI,CAAA;IACnB,GAAG,EAAE,OAAO,CAAA;IAEZ;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,UAAU,CAAE,GAAG,EAAE,MAAM,GAAG,KAAK;IA+BtC;;;;;;;;;;;;;;OAcG;IAEH,MAAM,CAAC,KAAK,CAAE,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,KAAK;IA6B7E;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,QAAQ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K;IActD;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,GAAG,KAAK;IAMvD;;;;;;;;;;;;;;OAcG;IACH,OAAO,CAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,GAAG,MAAM;IAMzD;;;;;;;;;;;;OAYG;IACH,EAAE,CAAE,CAAC,EAAE,KAAK,GAAG,OAAO;IAMtB;;;;;;;;OAQG;IACH,GAAG,CAAE,WAAW,CAAC,EAAE,OAAO,GAAG,KAAK;IAsBlC;;;;;;;;;;;;;OAaG;IACH,IAAI,CAAE,CAAC,EAAE,MAAM,GAAG,KAAK;IAOvB;;;;;;;;;;OAUG;IACH,GAAG,IAAK,MAAM;IAQd,OAAO,CAAC,QAAQ;IAkChB,OAAO,CAAC,YAAY;IAoCpB,OAAO,CAAC,WAAW;IA8HnB,OAAO,CAAC,eAAe;IAiCvB,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,WAAW;IAyBnB,OAAO,CAAC,aAAa;CAiBtB"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import BigNumber from './BigNumber.js';
|
|
2
|
+
import Signature from './Signature.js';
|
|
3
|
+
import PublicKey from './PublicKey.js';
|
|
4
|
+
import Point from './Point.js';
|
|
5
|
+
/**
|
|
6
|
+
* Represents a Private Key, which is a secret that can be used to generate signatures in a cryptographic system.
|
|
7
|
+
*
|
|
8
|
+
* The `PrivateKey` class extends from the `BigNumber` class. It offers methods to create signatures, verify them,
|
|
9
|
+
* create a corresponding public key and derive a shared secret from a public key.
|
|
10
|
+
*
|
|
11
|
+
* @extends {BigNumber}
|
|
12
|
+
* @see {@link BigNumber} for more information on BigNumber.
|
|
13
|
+
*/
|
|
14
|
+
export default class PrivateKey extends BigNumber {
|
|
15
|
+
/**
|
|
16
|
+
* Generates a private key randomly.
|
|
17
|
+
*
|
|
18
|
+
* @method fromRandom
|
|
19
|
+
* @static
|
|
20
|
+
* @returns The newly generated Private Key.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const privateKey = PrivateKey.fromRandom();
|
|
24
|
+
*/
|
|
25
|
+
static fromRandom(): PrivateKey;
|
|
26
|
+
/**
|
|
27
|
+
* Generates a private key from a string.
|
|
28
|
+
*
|
|
29
|
+
* @method fromString
|
|
30
|
+
* @static
|
|
31
|
+
* @param str - The string to generate the private key from.
|
|
32
|
+
* @param base - The base of the string.
|
|
33
|
+
* @returns The generated Private Key.
|
|
34
|
+
* @throws Will throw an error if the string is not valid.
|
|
35
|
+
**/
|
|
36
|
+
static fromString(str: string, base: number | 'hex'): PrivateKey;
|
|
37
|
+
/**
|
|
38
|
+
* Generates a private key from a WIF (Wallet Import Format) string.
|
|
39
|
+
*
|
|
40
|
+
* @method fromWif
|
|
41
|
+
* @static
|
|
42
|
+
* @param wif - The WIF string to generate the private key from.
|
|
43
|
+
* @param base - The base of the string.
|
|
44
|
+
* @returns The generated Private Key.
|
|
45
|
+
* @throws Will throw an error if the string is not a valid WIF.
|
|
46
|
+
**/
|
|
47
|
+
static fromWif(wif: string, prefixLength?: number): PrivateKey;
|
|
48
|
+
/**
|
|
49
|
+
* @constructor
|
|
50
|
+
*
|
|
51
|
+
* @param number - The number (various types accepted) to construct a BigNumber from. Default is 0.
|
|
52
|
+
*
|
|
53
|
+
* @param base - The base of number provided. By default is 10. Ignored if number is BigNumber.
|
|
54
|
+
*
|
|
55
|
+
* @param endian - The endianness provided. By default is 'big endian'. Ignored if number is BigNumber.
|
|
56
|
+
*
|
|
57
|
+
* @param modN - Optional. Default 'apply. If 'apply', apply modN to input to guarantee a valid PrivateKey. If 'error', if input is out of field throw Error('Input is out of field'). If 'nocheck', assumes input is in field.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* import PrivateKey from './PrivateKey';
|
|
61
|
+
* import BigNumber from './BigNumber';
|
|
62
|
+
* const privKey = new PrivateKey(new BigNumber('123456', 10, 'be'));
|
|
63
|
+
*/
|
|
64
|
+
constructor(number?: BigNumber | number | string | number[], base?: number | 'be' | 'le' | 'hex', endian?: 'be' | 'le', modN?: 'apply' | 'nocheck' | 'error');
|
|
65
|
+
/**
|
|
66
|
+
* A utility function to check that the value of this PrivateKey lies in the field limited by curve.n
|
|
67
|
+
* @returns { inField, modN } where modN is this PrivateKey's current BigNumber value mod curve.n, and inField is true only if modN equals current BigNumber value.
|
|
68
|
+
*/
|
|
69
|
+
checkInField(): {
|
|
70
|
+
inField: boolean;
|
|
71
|
+
modN: BigNumber;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* @returns true if the PrivateKey's current BigNumber value lies in the field limited by curve.n
|
|
75
|
+
*/
|
|
76
|
+
isValid(): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Signs a message using the private key.
|
|
79
|
+
*
|
|
80
|
+
* @method sign
|
|
81
|
+
* @param msg - The message (array of numbers or string) to be signed.
|
|
82
|
+
* @param enc - If 'hex' the string will be treated as hex, utf8 otherwise.
|
|
83
|
+
* @param forceLowS - If true (the default), the signature will be forced to have a low S value.
|
|
84
|
+
* @param customK — If provided, uses a custom K-value for the signature. Provie a function that returns a BigNumber, or the BigNumber itself.
|
|
85
|
+
* @returns A digital signature generated from the hash of the message and the private key.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* const privateKey = PrivateKey.fromRandom();
|
|
89
|
+
* const signature = privateKey.sign('Hello, World!');
|
|
90
|
+
*/
|
|
91
|
+
sign(msg: number[] | string, enc?: 'hex' | 'utf8', forceLowS?: boolean, customK?: Function | BigNumber): Signature;
|
|
92
|
+
/**
|
|
93
|
+
* Verifies a message's signature using the public key associated with this private key.
|
|
94
|
+
*
|
|
95
|
+
* @method verify
|
|
96
|
+
* @param msg - The original message which has been signed.
|
|
97
|
+
* @param sig - The signature to be verified.
|
|
98
|
+
* @param enc - The data encoding method.
|
|
99
|
+
* @returns Whether or not the signature is valid.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* const privateKey = PrivateKey.fromRandom();
|
|
103
|
+
* const signature = privateKey.sign('Hello, World!');
|
|
104
|
+
* const isSignatureValid = privateKey.verify('Hello, World!', signature);
|
|
105
|
+
*/
|
|
106
|
+
verify(msg: number[] | string, sig: Signature, enc?: 'hex'): boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Converts the private key to its corresponding public key.
|
|
109
|
+
*
|
|
110
|
+
* The public key is generated by multiplying the base point G of the curve and the private key.
|
|
111
|
+
*
|
|
112
|
+
* @method toPublicKey
|
|
113
|
+
* @returns The generated PublicKey.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* const privateKey = PrivateKey.fromRandom();
|
|
117
|
+
* const publicKey = privateKey.toPublicKey();
|
|
118
|
+
*/
|
|
119
|
+
toPublicKey(): PublicKey;
|
|
120
|
+
/**
|
|
121
|
+
* Converts the private key to a Wallet Import Format (WIF) string.
|
|
122
|
+
*
|
|
123
|
+
* Base58Check encoding is used for encoding the private key.
|
|
124
|
+
* The prefix
|
|
125
|
+
*
|
|
126
|
+
* @method toWif
|
|
127
|
+
* @returns The WIF string.
|
|
128
|
+
*
|
|
129
|
+
* @param prefix defaults to [0x80] for mainnet, set it to [0xef] for testnet.
|
|
130
|
+
*
|
|
131
|
+
* @throws Error('Value is out of field') if current BigNumber value is out of field limited by curve.n
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* const privateKey = PrivateKey.fromRandom();
|
|
135
|
+
* const wif = privateKey.toWif();
|
|
136
|
+
* const testnetWif = privateKey.toWif([0xef]);
|
|
137
|
+
*/
|
|
138
|
+
toWif(prefix?: number[]): string;
|
|
139
|
+
/**
|
|
140
|
+
* Base58Check encodes the hash of the public key associated with this private key with a prefix to indicate locking script type.
|
|
141
|
+
* Defaults to P2PKH for mainnet, otherwise known as a "Bitcoin Address".
|
|
142
|
+
*
|
|
143
|
+
* @param prefix defaults to [0x00] for mainnet, set to [0x6f] for testnet.
|
|
144
|
+
*
|
|
145
|
+
* @returns Returns the address encoding associated with the hash of the public key associated with this private key.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* const address = pubkey.toAddress()
|
|
149
|
+
* const testnetAddress = pubkey.toAddress([0x6f])
|
|
150
|
+
*/
|
|
151
|
+
toAddress(prefix?: number[]): string;
|
|
152
|
+
/**
|
|
153
|
+
* Derives a shared secret from the public key.
|
|
154
|
+
*
|
|
155
|
+
* @method deriveSharedSecret
|
|
156
|
+
* @param key - The public key to derive the shared secret from.
|
|
157
|
+
* @returns The derived shared secret (a point on the curve).
|
|
158
|
+
* @throws Will throw an error if the public key is not valid.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* const privateKey = PrivateKey.fromRandom();
|
|
162
|
+
* const publicKey = privateKey.toPublicKey();
|
|
163
|
+
* const sharedSecret = privateKey.deriveSharedSecret(publicKey);
|
|
164
|
+
*/
|
|
165
|
+
deriveSharedSecret(key: PublicKey): Point;
|
|
166
|
+
/**
|
|
167
|
+
* Derives a child key with BRC-42.
|
|
168
|
+
* @param publicKey The public key of the other party
|
|
169
|
+
* @param invoiceNumber The invoice number used to derive the child key
|
|
170
|
+
* @returns The derived child key.
|
|
171
|
+
*/
|
|
172
|
+
deriveChild(publicKey: PublicKey, invoiceNumber: string): PrivateKey;
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=PrivateKey.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrivateKey.d.ts","sourceRoot":"","sources":["../../../../src/primitives/PrivateKey.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAA;AACtC,OAAO,SAAS,MAAM,gBAAgB,CAAA;AACtC,OAAO,SAAS,MAAM,gBAAgB,CAAA;AACtC,OAAO,KAAK,MAAM,YAAY,CAAA;AAO9B;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,OAAO,U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,MAAM;IAI7C;;;;;;;;;;;;OAYG;IACH,kBAAkB,CAAE,GAAG,EAAE,SAAS,GAAG,KAAK;IAO1C;;;;;OAKG;IACH,WAAW,CAAE,SAAS,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,GAAG,UAAU;CAOtE"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import Point from './Point.js';
|
|
2
|
+
import PrivateKey from './PrivateKey.js';
|
|
3
|
+
import BigNumber from './BigNumber.js';
|
|
4
|
+
import Signature from './Signature.js';
|
|
5
|
+
/**
|
|
6
|
+
* The PublicKey class extends the Point class. It is used in public-key cryptography to derive shared secret, verify message signatures, and encode the public key in the DER format.
|
|
7
|
+
* The class comes with static methods to generate PublicKey instances from private keys or from strings.
|
|
8
|
+
*
|
|
9
|
+
* @extends {Point}
|
|
10
|
+
* @see {@link Point} for more information on Point.
|
|
11
|
+
*/
|
|
12
|
+
export default class PublicKey extends Point {
|
|
13
|
+
/**
|
|
14
|
+
* Static factory method to derive a public key from a private key.
|
|
15
|
+
* It multiplies the generator point 'g' on the elliptic curve by the private key.
|
|
16
|
+
*
|
|
17
|
+
* @static
|
|
18
|
+
* @method fromPrivateKey
|
|
19
|
+
*
|
|
20
|
+
* @param key - The private key from which to derive the public key.
|
|
21
|
+
*
|
|
22
|
+
* @returns Returns the PublicKey derived from the given PrivateKey.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* const myPrivKey = new PrivateKey(...)
|
|
26
|
+
* const myPubKey = PublicKey.fromPrivateKey(myPrivKey)
|
|
27
|
+
*/
|
|
28
|
+
static fromPrivateKey(key: PrivateKey): PublicKey;
|
|
29
|
+
/**
|
|
30
|
+
* Static factory method to create a PublicKey instance from a string.
|
|
31
|
+
*
|
|
32
|
+
* @param str - A string representing a public key.
|
|
33
|
+
*
|
|
34
|
+
* @returns Returns the PublicKey created from the string.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* const myPubKey = PublicKey.fromString("03....")
|
|
38
|
+
*/
|
|
39
|
+
static fromString(str: string): PublicKey;
|
|
40
|
+
/**
|
|
41
|
+
* @constructor
|
|
42
|
+
* @param x - A point or the x-coordinate of the point. May be a number, a BigNumber, a string (which will be interpreted as hex), a number array, or null. If null, an "Infinity" point is constructed.
|
|
43
|
+
* @param y - If x is not a point, the y-coordinate of the point, similar to x.
|
|
44
|
+
* @param isRed - A boolean indicating if the point is a member of the field of integers modulo the k256 prime. Default is true.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* new PublicKey(point1);
|
|
48
|
+
* new PublicKey('abc123', 'def456');
|
|
49
|
+
*/
|
|
50
|
+
constructor(x: Point | BigNumber | number | number[] | string | null, y?: BigNumber | number | number[] | string | null, isRed?: boolean);
|
|
51
|
+
/**
|
|
52
|
+
* Derive a shared secret from a public key and a private key for use in symmetric encryption.
|
|
53
|
+
* This method multiplies the public key (an instance of Point) with a private key.
|
|
54
|
+
*
|
|
55
|
+
* @param priv - The private key to use in deriving the shared secret.
|
|
56
|
+
*
|
|
57
|
+
* @returns Returns the Point representing the shared secret.
|
|
58
|
+
*
|
|
59
|
+
* @throws Will throw an error if the public key is not valid for ECDH secret derivation.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* const myPrivKey = new PrivateKey(...)
|
|
63
|
+
* const sharedSecret = myPubKey.deriveSharedSecret(myPrivKey)
|
|
64
|
+
*/
|
|
65
|
+
deriveSharedSecret(priv: PrivateKey): Point;
|
|
66
|
+
/**
|
|
67
|
+
* Verify a signature of a message using this public key.
|
|
68
|
+
*
|
|
69
|
+
* @param msg - The message to verify. It can be a string or an array of numbers.
|
|
70
|
+
* @param sig - The Signature of the message that needs verification.
|
|
71
|
+
* @param enc - The encoding of the message. It defaults to 'utf8'.
|
|
72
|
+
*
|
|
73
|
+
* @returns Returns true if the signature is verified successfully, otherwise false.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* const myMessage = "Hello, world!"
|
|
77
|
+
* const mySignature = new Signature(...)
|
|
78
|
+
* const isVerified = myPubKey.verify(myMessage, mySignature)
|
|
79
|
+
*/
|
|
80
|
+
verify(msg: number[] | string, sig: Signature, enc?: 'hex' | 'utf8'): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Encode the public key to DER (Distinguished Encoding Rules) format.
|
|
83
|
+
*
|
|
84
|
+
* @returns Returns the DER-encoded string of this public key.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* const derPublicKey = myPubKey.toDER()
|
|
88
|
+
*/
|
|
89
|
+
toDER(): string;
|
|
90
|
+
/**
|
|
91
|
+
* Hash sha256 and ripemd160 of the public key.
|
|
92
|
+
*
|
|
93
|
+
* @returns Returns the hash of the public key.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* const publicKeyHash = pubkey.toHash()
|
|
97
|
+
*/
|
|
98
|
+
toHash(enc?: 'hex'): number[] | string;
|
|
99
|
+
/**
|
|
100
|
+
* Base58Check encodes the hash of the public key with a prefix to indicate locking script type.
|
|
101
|
+
* Defaults to P2PKH for mainnet, otherwise known as a "Bitcoin Address".
|
|
102
|
+
*
|
|
103
|
+
* @param prefix defaults to [0x00] for mainnet, set to [0x6f] for testnet.
|
|
104
|
+
*
|
|
105
|
+
* @returns Returns the address encoding associated with the hash of the public key.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* const address = pubkey.toAddress()
|
|
109
|
+
* const testnetAddress = pubkey.toAddress([0x6f])
|
|
110
|
+
*/
|
|
111
|
+
toAddress(prefix?: number[]): string;
|
|
112
|
+
/**
|
|
113
|
+
* Derives a child key with BRC-42.
|
|
114
|
+
* @param privateKey The private key of the other party
|
|
115
|
+
* @param invoiceNumber The invoice number used to derive the child key
|
|
116
|
+
* @returns The derived child key.
|
|
117
|
+
*/
|
|
118
|
+
deriveChild(privateKey: PrivateKey, invoiceNumber: string): PublicKey;
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=PublicKey.d.ts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Aa,EAAE,MAAM,GAAG,SAAS;CASvE"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a sequence of pseudo-random bytes with the given length.
|
|
3
|
+
*
|
|
4
|
+
* @param len - The number of bytes to generate
|
|
5
|
+
*
|
|
6
|
+
* @returns The generated bytes
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* import Random from '@bsv/sdk/primitives/Random'
|
|
10
|
+
* const bytes = Random(32) // Produces 32 random bytes
|
|
11
|
+
*/
|
|
12
|
+
declare const _default: (len: number) => number[];
|
|
13
|
+
export default _default;
|
|
14
|
+
//# sourceMappingURL=Random.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Random.d.ts","sourceRoot":"","sources":["../../../../src/primitives/Random.ts"],"names":[],"mappings":"AAsCA;;;;;;;;;;GAUG;8BACkB,MAAM,KAAG,MAAM,EAAE;AAAtC,wBAKC"}
|