Commit Graph

86 Commits

Author SHA1 Message Date
Chris Stewart
67bb3ceabd
2024 10 31 taproot signing (#5767)
* core: Implement TaprootKeyPath signing

* core: Rebase, remove isDummySignature

* Empty commit to run CI
2024-11-18 09:43:29 -06:00
Chris Stewart
bb0e40f05b
2024 11 16 rm isdummysig (#5771)
* WIP: Remove isDummySignature

* Add ECDigitalSignature.LOW_R_SIZE, use it in ECDigitalSignature.dummyLowR

* Regenerated dlc_test.json and dlc_tx_test.json to add hash type to dummy ecdsa signatures in static test vectors

* Regenerated dlc_test.json and dlc_tx_test.json to add hash type to dummy ecdsa signatures in static test vectors

* Fix InputInfoTest maxWitnessLengths checks to be >=

* Fix docs
2024-11-17 07:45:24 -06:00
Chris Stewart
cccaa582bd
Add Sign.{schnorrSign(),schnorrSignWithNonce()} to Sign interface (#5754)
* Add Sign.{schnorrSign(),schnorrSignWithNonce} to Sign interface

* Add schnorrSignWithHashType()
2024-11-13 10:42:45 -06:00
Chris Stewart
17f965fd45
2024 11 09 schnorrsig hashtype (#5764)
* Add SchnorrDigitalSignature.hashTypeOpt, add DigitalSignature.{hashTypeOpt,appendHashType}

* Remove TaprootKeyPath.hashTypeOpt param
2024-11-09 12:52:45 -06:00
Chris Stewart
d255914765
refactor: Use ECDigitalSignature.appendHashType() throughout codebase (#5761) 2024-11-09 09:15:37 -06:00
Chris Stewart
4e8d5ecc7f
Add Sign.{signWithHashType(),signLowRWithHashType} (#5757)
* Add Sign.{signWithHashType(),signLowRWithHashType}, integrate it throughout the codebase

* Remove deprecated SignerUtils.doSign()
2024-11-07 09:07:41 -06:00
Chris Stewart
e69e1e5ad1
2024 10 31 digitalsignature (#5752)
* Add DigitalSignature, extend it with ECDigitaSignature,SchnorrDigitalSignature

* WIP: Remove EmptyDigitalSignature case object in favor of val

* Fix byte representation of ECDigitalSignature.emptyDigitalSignature

* Simplify names to ECDigitalSignature.{empty, dummy, dummyLowR}

* Fix docs
2024-11-01 11:46:26 -05:00
Chris Stewart
29f10d046c
Turn on -Xlint (#5728)
Get entire codebase compiling

Fix DLCDAO

Revert .jvmopts

Finish rebase
2024-10-24 06:59:50 -05:00
Chris Stewart
654d4086b9
2024 05 08 scala3 core (#5580)
* Pull over scala3 compatible code for crypto/ project from https://github.com/bitcoin-s/bitcoin-s/pull/3497

* Pull over scala3 compatible code for core/ project from https://github.com/bitcoin-s/bitcoin-s/pull/3497

* Add -Xsource:3 to core/

* Get coreJVM/compile working

* restore files lost from master when checking out core/ from 2021-06-30

* Get entire codebase compiling

* Get bitcoindRpcTest/test:compile working

* Restore P2SHDescriptor constructor

* scalafmt

* Fix UInt8.toByte

* Get all merkle block tests working

* Fix GCS bug

* Add -Xsource:3 to cryptoTest/
2024-05-10 11:10:45 -05:00
Chris Stewart
3af204e74d
Pull over scala3 compatible code for crypto/ project (#5575)
* Pull over scala3 compatible code for crypto/ project from https://github.com/bitcoin-s/bitcoin-s/pull/3497

* Add -Xsource:3 flag to crypto/

* Remove tests for constructors
2024-05-09 17:07:05 -05:00
Scala Steward
afddf73c48
Update scalafmt-core to 3.8.1 (#5501)
* Update scalafmt-core to 3.8.1

* Update .scalafmt.conf settings to be factory default settings

* Fix typo

* scalafmt

* Empty commit to re-run CI

* Revert some scalafmt back to original scalafmt.conf

---------

Co-authored-by: Chris Stewart <stewart.chris1234@gmail.com>
2024-04-20 19:55:49 -05:00
Chris Stewart
2536fd3138
TapscriptTree, TapBranch, TapLeaf (#5520)
* Add taproot wallet test vectors

* Get parsing logic working

* Get first test case passing

* Add TapLeaf

* Get test cases working with two TapLeaf

* Add TapscriptTree as the top level type for a recursive data structure for TapscriptPath's

* Remove control block parsing for now until we actually test control blocks

* scalafmt
2024-04-12 11:16:14 -05:00
Chris Stewart
b83661e73f
Repurpose PublicKey trait, extend it with {SchnorrPublicKey, ECPublicKeyApi, XOnlyPubKey} (#5517)
Re-add PublicKey trait, extend it with {ECPublicKeyApi, SchnorrPublicKey, XOnlyPublicKey}
2024-04-10 12:55:39 -05:00
Chris Stewart
41c835761c
Make ECPublicKey return bytes that were passed as a parameter (#5502)
* Make ECPublicKey return bytes that were passed as a parameter rather than always returning compressed byte representation

Cleanup, add invariant

Use proper generator for isCompressed flag in BouncyCastleSecp256k1Test

* Try doing docs last to see if something fails in cryptoTestJVM/coreTestJVM

* Fix BouncyCastleUtil.computePubKey() where we weren't passing isCompressed
2024-04-05 09:21:53 -05:00
Chris Stewart
eb5310f312
Use ByteVector.compare rather than rolling our own (#4814) 2022-10-03 13:11:30 -05:00
Chris Stewart
ecf2d2ba2c
Fix bug where we were generating too many nonces (#4805) 2022-09-27 12:01:43 -05:00
Chris Stewart
9c506b639f
Add OrderedSchnorrSignatures, use it in OracleAttestment (#4803)
* Add OrderedSchnorrSignatures, use it in OracleAttestment, propagate it threw the codebase

* Small cleanups

* Add SortedVecFactory

* Fix test case with out of order nonces
2022-09-26 19:35:04 -05:00
benthecarman
e5545cb3b9
Improve toString functions for schnorr data types (#4644) 2022-08-23 07:05:04 -05:00
benthecarman
59732809d0
Represent and handle SIGHASH_DEFAULT correctly in TaprootKeyPath (#4488)
* Represent and handle SIGHASH_DEFAULT correctly in TaprootKeyPath

* Prevent construction of invalid TaprootKeyPath, fix tests

* Have SIGHASH_DEFAULT be SIGHASH_ALL in preTaproot cases
2022-07-11 07:22:08 -05:00
Chris Stewart
211339f344
Add static test vectors for Taproot (#3769)
* Add static test vectors for Taproot and the ability to parse those test cases

Add TaprootWitness data structure, get parsing working for first static test case

WIP: Distinguish between TaprootKeyPath and TaprootScriptPath

Remove invariants and make val to method in TaprootScriptPath so we can parse test cases

Add TaprootTestCase.{txSigComponents, programs} methods

Try to run test case

WIP

Wrap failure case in Try

Get first test case passing

Fix building of sig component for p2sh

WIP test case legacy/pk-wrongkey

Get more test cases passing

Move where MAX_PUSH_SIZE is checked for segwit

Get another test case passing

Add links to bitcoin core in test case

Fix stack parsing for witness

Get success test cases passing (without signature verification?)

Add failure test cases

Fix basic compile failures except in javascript projects

Get basic TaprootKeyPath parsing working from ScriptWitness

Get invariants implemented correctly for TaprootScriptPath

WIP

WIP

Get first taproot signature serialization test working

Get tagged hash working correctly

Rework test framework, get 2nd success test case passing

Get compile working with rebase

Implement computeTapleafHash with a unit test case

Add scaffolding of computing merkle root test case

Implement computeTaprootMerkleRoot() with a unit test

Implement computeTapTweakHash() with a unit test

WIP: checkTapTweak()

WIP

Implement computeTapTweakHash() unit test

Rebase onto master

Get verifyTaprootCommitment() passing unit test

Refactors to be more readable

* WIP: Tapscript signature checking

* Get taproot script path signature serialization working for unit test

* Add carve out for unknown public key types

* WIP: OP_CHECKSIGADD

* Add test case to detect annex and compute its hash

* Get test case passing when using upgradable public keys with an annex on the stack

* Fix missing pattern match

* Fix bug with tapscript SIGHASH_ALL and add test case

* Add check if taproot flag is enabled

* Get signature verification working with annex hash

* Implement correct handling of fail case for OP_CHECKSIGADD

* Get test case passing

* DRY

* Fix bug, now we only allow tapscript sig checking when pubkey is 32 bytes in size

* Refactor evalChecksigTapscript to use XOnlyPubKey

* Get signature serialization working with OP_CODESEPARATOR

* Get SIGHASH_ANYONECANPAY|SINGLE example working

* Fix bug in BIP342 impl where we don't count op codes if the version is taproot

* Fix OP_CODESEPARATOR bug

* Implement calculating of OP_CODESEPARATOR idx relative to other opcodes, not push operations

* Fix OP_CHECKSIG tapscript bug where we didn't push OP_FALSE onto stack in case of signature validation failure

* Add annex to TaprootKeyPath

* Get signature chcking working with tapscript keypath annex

* Cleanup test framework code a bit to avoid casting exceptions

* Implement handling of OP_SUCCESS

* WIP: Segwit v0 serialization with nonstandard sighash flag

* Fix hash bug in segwit v0 serialization

* WIP

* Fix bug where we weren't defaulting to SIGHASH_DEFAULT when using tapscript

* Add disabled opcodes to OP_SUCCESS case

* Fix parsing for witnesses in test case

* Get a SIGHASH_SINGLE test case working

* Clean up rebase

* Fix default hash type in TaprootKeyPath

* Implement opCodeSeparator counting that does NOT work when OP_CODESEPARATOR is is not executed inside of an OP_IF, otherwise is very simple for the base case

* Cherry-pick ben's commits & rebase

* Remove script size limit for tap scripts

* Fix incorrect handling of unassigned spk

* Fix invariant

* get correct test case failing

* WIP: SIGHASH_ALL_ANYONECANPAY test case

* Cleanup logging/println

* Refactors & fix regressions in some simple unit tests

* Remove logback in core to get the entire project compiling again

* Make TapscriptPath.hasAnnex() more robust against exceptions

* Add validation of XOnlyPubKey to control block

* Implement known leaf versions in the control block

* Add TaprootUnknownPath and UnknownControlBlock

* Fix rebase

* Fix interpreter bug where v0 segwit wasn't failing when a wrong program was used

* Cleanup println

* Clean up println pt2

* Re-enable -Xfatal-warnings

* Turn off logback-test.xml

* Parallelize taproot success test cases

* Try to bump timeout

* Optimization: Reduce number of intersections in ScriptInterpreter.run()

* Ben's code review

* Take ben's clean stack bugfix

Co-authored-by: benthecarman <benthecarman@live.com>
2022-07-07 14:53:28 -05:00
Chris Stewart
2b60bbb1c3
Remove .map() and use .foreach() with buffer in CryptoBytesUtil.toByteVector() (#4454) 2022-07-06 18:23:14 -05:00
Nadav Kohen
ae0962d7ed
Musig2 Implementation (#4418)
* An initial (not yet working) implementation with test

* Added custom (non-bip-340) verification for now

* Made KeySet a case class

* Got MuSig2 working with BIP340 verification passing

* Responds to Ben's review

* Fixed hash tags and added parital signature verification

* Added point multiplication that allows infinity and did some refactoring

* Refactored type defs into case classes

* Added tests for more signers and fixed single-party bug

* Added key aggregation test vectors from BIP

* Added nonce generation test vectors from BIP

* Added nonce aggregation test vectors from BIP

* Made nonce aggregation test vectors pass by having MultiNoncePub wrap SecpPoints

* Added remaining static test vectors from BIP

* Implements tweaking support and adds tests, including all of the remaining BIP tests

* Added factory objects for nonce types

* Refactored things into multiple files with renaming and restructuring

* Some minor renaming

* Introduced ParityMultiplier ADT to remove unneccesary computations

* Added scaladocs

* Added messages to invariants

* Fixed a typo

* Nonce generation now takes a SchnorrPublicKey instead of raw bytes

* Made point multiplication more robust

* Responded to Ben nits

* Added musig.md
2022-07-06 12:59:13 -05:00
Chris Stewart
a680f03c04
Implement BIP341 (#4409)
* Implement BIP341

Get coreTest working

* REmove logger

* scalafmt

* Cleanup

* Make checkSigTapScrip() take a SchnorrPublicKey

* Address ben's code review

* Adjust error type on WitenssVersionV1.rebuild()
2022-06-22 09:36:55 -05:00
benthecarman
c2f0762028
Add hmac256 to CryptoUtil (#4395) 2022-06-15 07:32:17 -05:00
Chris Stewart
9769fbcbb6
Add TaprootWitness, new methods to XOnlyPubKey (#4394)
* Add TaprootWitness, new methods to XOnlyPubKey

* Address codereview
2022-06-14 20:27:01 -05:00
Nadav Kohen
ad8802164c
ECPublicKey.tweakMultiply -> multiply and Added CryptoParams.getG (#4391)
* Renamed ECPublicKey.tweakMultiply to just multiply and added CryptoParams.getG

* Used decompressed G in FieldElement.G

* Removed G from FieldElement altogether
2022-06-14 13:11:21 -05:00
Chris Stewart
ddbdde495d
2022 06 13 taprootspk xonlypubkey (#4388)
* Implement XOnlyPubKey inside of TaprootScriptPubKey

* Add ECPrivateKey.toXOnly

* Address code review
2022-06-13 18:43:43 -05:00
Nadav Kohen
7e2ecd9d6a
Added data structure for x-only public keys with undetermined parity (#4387) 2022-06-13 16:02:37 -05:00
Nadav Kohen
b80bf4649e
Add HashType to ECDigitalSignature API (#4320)
* HashType now uses Int instead of Int32

* Moved HashType from core to crypto

* Added HashType helper functions to ECDigitalSignature

* Added tests

* Fixed compile
2022-05-29 18:25:22 -05:00
Nadav Kohen
f42d7ae8e7
Added validation to signature methods to avoid corruption edge cases (#4214) 2022-04-19 08:12:27 -05:00
Chris Stewart
21de609ed8
2022 01 22 cetsignatures refactor (#4004)
* Get refactor working where we decouple CETSignatures and the partial refund signature

* Add DLCAcceptWithCetSigs() for the case where we have a refund sig, but no cet signatures

* Fix bugs

* Fix sighash parsing bugs
2022-01-23 16:13:36 -06:00
Shreyansh
a58ef1cd02
Storing peers in database (#3773)
* rebase

* fix

* fix

* remove unwanted diffs

* fix

* formatting

* changes from comments

* Revert "changes from comments"

This reverts commit eb8a795718dc590802a19c7ce4cce4501bd2de1f.

* changes from comments

* add PeerManager

* add sha3-256

* add NetworkUtilTest

* formatting
2022-01-09 07:21:59 -06:00
benthecarman
f4a2ec8554
Make AesEncryptedData a network element / factory (#3952) 2021-12-30 06:30:31 -06:00
Chris Stewart
132479d271
Implement ability to provide external entropy to bitcoin-s (#3672)
* Encapsulate initialization of DLCOracle.start() method

* Use internal WalletAppConfig.kmConf rather than passing in custom key manager parameters

* Add KeyManagerAppConfig.defaultAccountType

* Get all tests passing besides TrezorAddressTest

* Get TrezorAddressTest passing with provided entropy

* Add unit test to make sure we can always derive the seed

* Get docs compiling

* Fix dlcWalletTest test cases

* Add more test cases to keymanager

* Add the new configuration to the example configuration

* Add more test cases

* Remove coverage on 2.12 as it isn't accurate

* Rework DLCOracleAppConfig.start() to call kmConf.start() so the oracle can use entropy provided via bitcoin-s.conf
2021-09-18 09:49:11 -05:00
benthecarman
f2a2874177
Add new invalid BIP 32 test vectors (#3634)
* Add new invalid BIP 32 test vectors

* Make sure priv key isn't zero

* Add comments
2021-08-31 07:59:34 -05:00
benthecarman
be8e965367
DLC Wallet pulldown (#3138)
* DLC Wallet pulldown

* Respond to review
2021-05-25 17:31:01 -05:00
Nadav Kohen
745e4c89fa
Removed point multiplication from ECPrivateKey.freshPrivateKey (#3116)
* Removed point multiplication from ECPrivateKey.freshPrivateKey

* Responded to review
2021-05-21 00:46:20 -06:00
Nadav Kohen
ac3bae403b
Pulled down all remaining non-wallet non-gui code on adaptor-dlc (#3101) 2021-05-18 06:29:46 -05:00
Nadav Kohen
6bc0943a62
Call decompression on public keys less (#2988)
* Removed type parameter from PublicKey

* Deduplicated call to public key decompression in isFullyValid

* Fixed FieldElement

* Added CurveCoordinate to replace FieldElement in places where it was being misused

* Added edge case tests
2021-05-07 02:05:10 -05:00
Nadav Kohen
78f4dfb8c6
Pubkey Refactor (#2936)
* Removed ExecutionContext from ECKey

* Refactored ECPublicKey to remove compression state and introduced ECPublicKeyBytes to handle cases where serialization of input is important

* Fixed the rest of bitcoin-s so that it passes all tests

* Made all ECKeys into case classes

* Successfully added isFullyValid invariant to ECPublicKey!

* Fixed docs

* Added scaladocs and fixed a RpcPsbtResult bug

* Reject private keys of length < 32 and fix WIF parsing bug
2021-05-06 13:19:52 -05:00
Nadav Kohen
63a6f9309d
Introduced AsyncAdaptorSign and AdaptorSign traits (#3037) 2021-05-05 09:34:03 -05:00
Nadav Kohen
7fd9aca304 Add Schnorr and Adaptor Secp Bindings and Update Adaptor (#2885)
* Replaced secp256k1 with secp256k1-zkp as submodule pointing to my java-bindings branch

* Built new binaries for schnorr signing and adaptor signing and integrated into LibSecp256k1CryptoRuntime

* Added public key compression function with tests, removed old adaptor signature point serializers

* Implemented ECDSA adaptor signatures in scala according to the most recent spec

* Added static test vectors for adaptor signing from spec

* Moved bouncy castle adaptor signing tests to .jvm

* Added scaladocs and responded to nits

* Added scaladocs with legends to spec naming

* Responded to Ben's review

* Fixed scala 2.12 compile issue

* Fixed BouncyCastle secKeyVerify

* Updated add-to-jni build instructions

* Updated secp256k1-zkp to target bitcoin-s-master

* Add windows binary (#14)

* Added Mac OS binaries

Co-authored-by: benthecarman <benthecarman@live.com>
2021-04-21 09:42:43 -05:00
benthecarman
fa80f36d2f Get all of Core working with JS (#2826)
* core-test-js-json

* Add SigPointComputer cross compile
Co-authored-by: Nadav Kohen <nadavk25@gmail.com>

* Fix java.time for scalajs

* InetAddress for scalajs

* Fix linking errors in coreTestJS

* Easy fixes

* InetAddress Tests

* Update micropickle, fix exact functions

* Get BigSizeUIntTest working with upickle

* Fix exact funcs

* Update Base58Test with upickle

* Update ScriptSignatureTest with upickle

* Update TransactionTest with upickle

* Update BlockFilterTest with upickle

* Update ScriptInterpreterTest with upickle

* Update MnemonicCodeTest with upickle

* Add InetAddress unit tests

* Fix compile errors

* Get core tests running, not passing

* Sign with js

* Fix PSBTUnitTest

* Fix PBKDF2 for JS

* Use bcrypto's secp256k1 instead of ecdsa

* Fix 2.12.12 compile

* Core tests passing :)

* Test corejs
2021-03-31 15:04:30 -05:00
Chris Stewart
c2409b46c4 Silence scalajs warnings for org.bitcoins.crypto package (#2822)
* Silence scalajs warnings for org.bitcoins.crypto package

* Add comments

* Create 'facades' package, move all js facades into that package. Make the new -Wconf flags work with only scala 2.13.x

* Small cleanups
2021-03-28 08:28:21 -05:00
Nadav Kohen
e6899b20b1 Made ECPrivateKey signing synchronous and got src compiling (#2652)
Fixed tests

De-futured tx buidling, finalizing and signing

Responded to review
2021-03-23 17:05:58 -05:00
rorp
85f6ee889c Adaptor signatures for Scala.js (#2794)
* Schnorr sigs for Scala.js

* fix build

* put BIP340 test vectors in a shared space

* remove teskit dependency, fix point edge cases

* fix build

* Adaptor signatures for Scala.jsr

* add some more tests

* add unit tests for point addition

* scaladoc

* add more public keys tests

* Add scaladoc

* Remove extra isCompressed flag on CryptoRuntime.toPublicKey() as it is inside of ECPrivateKey already

Co-authored-by: christewart <stewart.chris1234@gmail.com>
2021-03-22 16:50:04 -05:00
rorp
911fca5825 Schnorr js (#2805)
* Schnorr sigs for Scala.js

* fix build

* put BIP340 test vectors in a shared space

* remove teskit dependency, fix point edge cases

* fix build

* add unit tests for point addition

* scaladoc

* cleanup

* respond to the comments

* Fix usage of BitcoinSLogger

Co-authored-by: christewart <stewart.chris1234@gmail.com>
2021-03-22 12:56:40 -05:00
Chris Stewart
78448b277c Revert "Schnorr sigs for Scala.js (#2784)" (#2802)
This reverts commit 8e7bde0ed9.
2021-03-16 13:19:16 -05:00
rorp
8e7bde0ed9 Schnorr sigs for Scala.js (#2784) 2021-03-16 10:21:47 -07:00
rorp
7e23eecb20 SipHash for Scala.js (#2797) 2021-03-16 09:43:50 -05:00