├── orchid ├── README ├── .gitignore ├── data │ ├── GeoIP.dat │ └── README ├── src │ └── com │ │ └── subgraph │ │ └── orchid │ │ ├── events │ │ ├── Event.java │ │ ├── EventHandler.java │ │ └── EventManager.java │ │ ├── RouterMicrodescriptor.java │ │ ├── SocksPortListener.java │ │ ├── sockets │ │ ├── sslengine │ │ │ ├── HandshakeCallbackHandler.java │ │ │ ├── SSLEngineOutputStream.java │ │ │ └── SSLEngineInputStream.java │ │ └── OrchidSocketImplFactory.java │ │ ├── circuits │ │ ├── path │ │ │ ├── RouterFilter.java │ │ │ └── PathSelectionFailedException.java │ │ ├── hs │ │ │ ├── HSAuthenticationException.java │ │ │ ├── HSDescriptorDirectory.java │ │ │ ├── HSDescriptorCookie.java │ │ │ ├── IntroductionPointKeyword.java │ │ │ ├── HSDescriptorKeyword.java │ │ │ └── IntroductionPoint.java │ │ ├── PredictedPortTarget.java │ │ ├── DirectoryCircuitImpl.java │ │ └── guards │ │ │ └── GuardProbeTask.java │ │ ├── directory │ │ ├── parsing │ │ │ ├── DocumentParsingHandler.java │ │ │ ├── DocumentParser.java │ │ │ ├── DocumentParsingResultHandler.java │ │ │ ├── DocumentParsingResult.java │ │ │ ├── NameIntegerParameter.java │ │ │ ├── DocumentParserFactory.java │ │ │ ├── DocumentObject.java │ │ │ └── BasicDocumentParsingResult.java │ │ ├── downloader │ │ │ ├── DirectoryRequestFailedException.java │ │ │ ├── BridgeDescriptorFetcher.java │ │ │ ├── ConsensusFetcher.java │ │ │ ├── CertificateFetcher.java │ │ │ ├── RouterDescriptorFetcher.java │ │ │ └── MicrodescriptorFetcher.java │ │ ├── router │ │ │ ├── MicrodescriptorCacheLocation.java │ │ │ ├── RouterMicrodescriptorKeyword.java │ │ │ └── RouterDescriptorKeyword.java │ │ ├── consensus │ │ │ ├── DirectorySignature.java │ │ │ └── ConsensusDocumentSectionParser.java │ │ ├── certificate │ │ │ └── KeyCertificateKeyword.java │ │ └── DocumentParserFactoryImpl.java │ │ ├── TorInitializationListener.java │ │ ├── Document.java │ │ ├── BridgeRouter.java │ │ ├── crypto │ │ ├── TorKeyAgreement.java │ │ ├── TorKeyDerivation.java │ │ ├── TorRandom.java │ │ └── TorPrivateKey.java │ │ ├── dashboard │ │ ├── DashboardRenderer.java │ │ └── DashboardRenderable.java │ │ ├── data │ │ ├── exitpolicy │ │ │ ├── ExitTarget.java │ │ │ ├── ExitPorts.java │ │ │ ├── ExitPolicy.java │ │ │ └── Network.java │ │ ├── BandwidthHistory.java │ │ ├── Timestamp.java │ │ └── RandomSet.java │ │ ├── InternalCircuit.java │ │ ├── HiddenServiceCircuit.java │ │ ├── ConnectionFailedException.java │ │ ├── ConnectionHandshakeException.java │ │ ├── OpenFailedException.java │ │ ├── ConnectionIOException.java │ │ ├── misc │ │ ├── Utils.java │ │ ├── NotThreadSafe.java │ │ ├── ThreadSafe.java │ │ ├── Immutable.java │ │ └── GuardedBy.java │ │ ├── ConnectionTimeoutException.java │ │ ├── TorParsingException.java │ │ ├── socks │ │ └── SocksRequestException.java │ │ ├── GuardEntry.java │ │ ├── encoders │ │ ├── DecoderException.java │ │ ├── EncoderException.java │ │ └── Encoder.java │ │ ├── TorException.java │ │ ├── VoteAuthorityEntry.java │ │ ├── DirectoryCircuit.java │ │ ├── DirectoryServer.java │ │ ├── config │ │ └── TorConfigBridgeLine.java │ │ ├── RouterStatus.java │ │ ├── Revision.java │ │ ├── StreamConnectFailedException.java │ │ ├── DirectoryStore.java │ │ ├── ConnectionCache.java │ │ ├── Stream.java │ │ ├── Router.java │ │ ├── ConsensusDocument.java │ │ └── DirectoryDownloader.java ├── logging.properties ├── opt │ └── xmlrpc │ │ └── com │ │ └── subgraph │ │ └── orchid │ │ └── xmlrpc │ │ └── OrchidXmlRpcTransportFactory.java ├── test │ └── com │ │ └── subgraph │ │ └── orchid │ │ └── geoip │ │ └── CountryCodeServiceTest.java └── LICENSE ├── .gitattributes ├── misc └── bitcoinjlogo.png ├── .gitignore ├── core ├── src │ ├── main │ │ ├── resources │ │ │ ├── org.bitcoin.test.checkpoints │ │ │ ├── org │ │ │ │ └── bitcoinj │ │ │ │ │ └── crypto │ │ │ │ │ └── cacerts │ │ │ └── org.bitcoin.production.checkpoints │ │ └── java │ │ │ └── org │ │ │ └── bitcoinj │ │ │ ├── uri │ │ │ ├── package-info.java │ │ │ ├── OptionalFieldValidationException.java │ │ │ ├── RequiredFieldValidationException.java │ │ │ └── BitcoinURIParseException.java │ │ │ ├── script │ │ │ └── package-info.java │ │ │ ├── net │ │ │ ├── discovery │ │ │ │ ├── package-info.java │ │ │ │ ├── PeerDiscoveryException.java │ │ │ │ └── PeerDiscovery.java │ │ │ ├── package-info.java │ │ │ ├── StreamConnectionFactory.java │ │ │ └── MessageWriteTarget.java │ │ │ ├── kits │ │ │ └── package-info.java │ │ │ ├── protocols │ │ │ ├── payments │ │ │ │ └── package-info.java │ │ │ ├── channels │ │ │ │ ├── package-info.java │ │ │ │ ├── PaymentIncrementAck.java │ │ │ │ └── ValueOutOfRangeException.java │ │ │ └── package-info.java │ │ │ ├── params │ │ │ └── package-info.java │ │ │ ├── utils │ │ │ ├── package-info.java │ │ │ ├── DaemonThreadFactory.java │ │ │ ├── BaseTaggableObject.java │ │ │ ├── ContextPropagatingThreadFactory.java │ │ │ └── ListenerRegistration.java │ │ │ ├── signers │ │ │ ├── package-info.java │ │ │ └── StatelessTransactionSigner.java │ │ │ ├── wallet │ │ │ ├── AbstractKeyChainEventListener.java │ │ │ ├── AllRandomKeysRotating.java │ │ │ ├── DeterministicUpgradeRequiredException.java │ │ │ ├── package-info.java │ │ │ ├── DeterministicUpgradeRequiresPassword.java │ │ │ ├── CoinSelection.java │ │ │ ├── AllowUnconfirmedCoinSelector.java │ │ │ ├── CoinSelector.java │ │ │ ├── KeyChainEventListener.java │ │ │ ├── WalletTransaction.java │ │ │ └── RiskAnalysis.java │ │ │ ├── testing │ │ │ ├── package-info.java │ │ │ ├── FooWalletExtension.java │ │ │ ├── NopTransactionSigner.java │ │ │ └── InboundMessageQueuer.java │ │ │ ├── core │ │ │ ├── listeners │ │ │ │ ├── BlockChainListener.java │ │ │ │ ├── OnTransactionBroadcastListener.java │ │ │ │ ├── WalletEventListener.java │ │ │ │ ├── AbstractBlockChainListener.java │ │ │ │ ├── AbstractPeerConnectionEventListener.java │ │ │ │ ├── AbstractPeerDataEventListener.java │ │ │ │ ├── ReorganizeListener.java │ │ │ │ └── NewBestBlockListener.java │ │ │ ├── package-info.java │ │ │ ├── ScriptException.java │ │ │ ├── AddressFormatException.java │ │ │ ├── TransactionBroadcaster.java │ │ │ ├── VersionAck.java │ │ │ ├── GetAddrMessage.java │ │ │ ├── ProtocolException.java │ │ │ ├── PeerException.java │ │ │ ├── UTXOProviderException.java │ │ │ ├── UnknownMessage.java │ │ │ ├── Monetary.java │ │ │ ├── PrunedException.java │ │ │ ├── NotFoundMessage.java │ │ │ ├── MemoryPoolMessage.java │ │ │ ├── InsufficientMoneyException.java │ │ │ ├── RejectedTransactionException.java │ │ │ ├── Pong.java │ │ │ ├── WrongNetworkException.java │ │ │ ├── TransactionBag.java │ │ │ └── InventoryItem.java │ │ │ ├── store │ │ │ ├── ChainFileLockedException.java │ │ │ ├── package-info.java │ │ │ ├── WindowsMMapHack.java │ │ │ ├── BlockStoreException.java │ │ │ └── UnreadableWalletException.java │ │ │ ├── crypto │ │ │ ├── package-info.java │ │ │ ├── KeyCrypterException.java │ │ │ └── HDDerivationException.java │ │ │ └── jni │ │ │ ├── NativePaymentChannelHandlerFactory.java │ │ │ ├── NativePaymentChannelServerConnectionEventHandler.java │ │ │ ├── NativeFutureCallback.java │ │ │ └── NativeTransactionConfidenceListener.java │ ├── test │ │ ├── resources │ │ │ └── org │ │ │ │ └── bitcoinj │ │ │ │ ├── core │ │ │ │ ├── block169482.dat │ │ │ │ ├── first-100k-blocks.dat │ │ │ │ └── sig_canonical.json │ │ │ │ └── protocols │ │ │ │ └── payments │ │ │ │ ├── test-cacerts │ │ │ │ ├── test-expired-cert │ │ │ │ ├── test-valid-cert │ │ │ │ ├── pki_test.bitcoinpaymentrequest │ │ │ │ └── README │ │ └── java │ │ │ └── org │ │ │ └── bitcoinj │ │ │ ├── core │ │ │ ├── MemoryFullPrunedBlockChainTest.java │ │ │ ├── WalletExtensionsTest.java │ │ │ ├── H2FullPrunedBlockChainTest.java │ │ │ └── PeerAddressTest.java │ │ │ ├── utils │ │ │ └── BaseTaggableObjectTest.java │ │ │ ├── crypto │ │ │ └── X509UtilsTest.java │ │ │ └── store │ │ │ └── LevelDBBlockStoreTest.java │ ├── peerseeds.proto │ └── storedserverpaymentchannel.proto └── findbugs.xml ├── wallettemplate └── src │ └── main │ ├── resources │ └── wallettemplate │ │ ├── checkpoints │ │ ├── checkpoints.testnet │ │ ├── 200px-Padlock.svg.png │ │ ├── bitcoin_logo_plain.png │ │ ├── utils │ │ └── text-validation.css │ │ ├── wallet.css │ │ └── controls │ │ └── bitcoin_address.fxml │ └── java │ └── wallettemplate │ ├── utils │ ├── easing │ │ └── EasingMode.java │ ├── AlertWindowController.java │ └── TextFieldValidator.java │ └── controls │ └── BitcoinAddressValidator.java ├── tools ├── build-checkpoints ├── wallet-tool ├── build-checkpoints.cmd ├── wallet-tool.cmd └── src │ └── main │ ├── resources │ └── org │ │ └── bitcoinj │ │ └── tools │ │ └── build-checkpoints-help.txt │ └── java │ └── org │ └── bitcoinj │ └── tools │ └── NetworkEnum.java ├── .travis.yml ├── examples └── src │ └── main │ ├── javascript │ ├── tor.js │ ├── payprotocol.js │ └── forwarding.js │ └── java │ └── org │ └── bitcoinj │ └── examples │ └── DumpWallet.java └── AUTHORS /orchid/README: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.ai -crlf -diff -merge 2 | -------------------------------------------------------------------------------- /orchid/.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | orchid-*.jar 3 | orchid-*.zip 4 | build-revision 5 | lib/xmlrpc-* 6 | -------------------------------------------------------------------------------- /misc/bitcoinjlogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MultiChain/sample-bitcoinj/HEAD/misc/bitcoinjlogo.png -------------------------------------------------------------------------------- /orchid/data/GeoIP.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MultiChain/sample-bitcoinj/HEAD/orchid/data/GeoIP.dat -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/events/Event.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.events; 2 | 3 | public interface Event {} 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | .project 3 | .classpath 4 | .settings 5 | .idea 6 | *.iml 7 | *.chain 8 | *.spvchain 9 | *.wallet 10 | 11 | -------------------------------------------------------------------------------- /core/src/main/resources/org.bitcoin.test.checkpoints: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MultiChain/sample-bitcoinj/HEAD/core/src/main/resources/org.bitcoin.test.checkpoints -------------------------------------------------------------------------------- /core/src/main/resources/org/bitcoinj/crypto/cacerts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MultiChain/sample-bitcoinj/HEAD/core/src/main/resources/org/bitcoinj/crypto/cacerts -------------------------------------------------------------------------------- /core/src/main/resources/org.bitcoin.production.checkpoints: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MultiChain/sample-bitcoinj/HEAD/core/src/main/resources/org.bitcoin.production.checkpoints -------------------------------------------------------------------------------- /core/src/test/resources/org/bitcoinj/core/block169482.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MultiChain/sample-bitcoinj/HEAD/core/src/test/resources/org/bitcoinj/core/block169482.dat -------------------------------------------------------------------------------- /orchid/data/README: -------------------------------------------------------------------------------- 1 | GeoIP.dat GeoLite Country database downloaded September, 2013 2 | 3 | http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz 4 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/RouterMicrodescriptor.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid; 2 | 3 | 4 | public interface RouterMicrodescriptor extends Descriptor { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/events/EventHandler.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.events; 2 | 3 | public interface EventHandler { 4 | void handleEvent(Event event); 5 | } 6 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/uri/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Parsing and handling of bitcoin: textual URIs as found in qr codes and web links. 3 | */ 4 | package org.bitcoinj.uri; -------------------------------------------------------------------------------- /wallettemplate/src/main/resources/wallettemplate/checkpoints: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MultiChain/sample-bitcoinj/HEAD/wallettemplate/src/main/resources/wallettemplate/checkpoints -------------------------------------------------------------------------------- /core/src/test/resources/org/bitcoinj/core/first-100k-blocks.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MultiChain/sample-bitcoinj/HEAD/core/src/test/resources/org/bitcoinj/core/first-100k-blocks.dat -------------------------------------------------------------------------------- /core/src/test/resources/org/bitcoinj/protocols/payments/test-cacerts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MultiChain/sample-bitcoinj/HEAD/core/src/test/resources/org/bitcoinj/protocols/payments/test-cacerts -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/SocksPortListener.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid; 2 | 3 | public interface SocksPortListener { 4 | void addListeningPort(int port); 5 | void stop(); 6 | } 7 | -------------------------------------------------------------------------------- /wallettemplate/src/main/resources/wallettemplate/checkpoints.testnet: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MultiChain/sample-bitcoinj/HEAD/wallettemplate/src/main/resources/wallettemplate/checkpoints.testnet -------------------------------------------------------------------------------- /wallettemplate/src/main/resources/wallettemplate/200px-Padlock.svg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MultiChain/sample-bitcoinj/HEAD/wallettemplate/src/main/resources/wallettemplate/200px-Padlock.svg.png -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/script/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Classes for working with and executing Bitcoin script programs, as embedded in inputs and outputs. 3 | */ 4 | package org.bitcoinj.script; -------------------------------------------------------------------------------- /core/src/test/resources/org/bitcoinj/protocols/payments/test-expired-cert: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MultiChain/sample-bitcoinj/HEAD/core/src/test/resources/org/bitcoinj/protocols/payments/test-expired-cert -------------------------------------------------------------------------------- /core/src/test/resources/org/bitcoinj/protocols/payments/test-valid-cert: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MultiChain/sample-bitcoinj/HEAD/core/src/test/resources/org/bitcoinj/protocols/payments/test-valid-cert -------------------------------------------------------------------------------- /wallettemplate/src/main/resources/wallettemplate/bitcoin_logo_plain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MultiChain/sample-bitcoinj/HEAD/wallettemplate/src/main/resources/wallettemplate/bitcoin_logo_plain.png -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/net/discovery/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Classes that know how to discover peers in the P2P network using DNS, IRC or DNS via Tor (orchid). 3 | */ 4 | package org.bitcoinj.net.discovery; -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/sockets/sslengine/HandshakeCallbackHandler.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.sockets.sslengine; 2 | 3 | public interface HandshakeCallbackHandler { 4 | void handshakeCompleted(); 5 | } 6 | -------------------------------------------------------------------------------- /core/src/test/resources/org/bitcoinj/protocols/payments/pki_test.bitcoinpaymentrequest: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MultiChain/sample-bitcoinj/HEAD/core/src/test/resources/org/bitcoinj/protocols/payments/pki_test.bitcoinpaymentrequest -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/circuits/path/RouterFilter.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.circuits.path; 2 | 3 | import com.subgraph.orchid.Router; 4 | 5 | public interface RouterFilter { 6 | boolean filter(Router router); 7 | } 8 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/directory/parsing/DocumentParsingHandler.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.directory.parsing; 2 | 3 | public interface DocumentParsingHandler { 4 | void parseKeywordLine(); 5 | void endOfDocument(); 6 | } 7 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/kits/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * High level wrapper APIs around the bitcoinj building blocks. WalletAppKit is suitable for many different types of 3 | * apps that require an SPV wallet. 4 | */ 5 | package org.bitcoinj.kits; -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/TorInitializationListener.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid; 2 | 3 | public interface TorInitializationListener { 4 | void initializationProgress(String message, int percent); 5 | void initializationCompleted(); 6 | } 7 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/Document.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid; 2 | 3 | import java.nio.ByteBuffer; 4 | 5 | public interface Document { 6 | ByteBuffer getRawDocumentBytes(); 7 | String getRawDocumentData(); 8 | boolean isValidDocument(); 9 | } 10 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/protocols/payments/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The BIP70 payment protocol wraps Bitcoin transactions and adds various useful features like memos, refund addresses 3 | * and authentication. 4 | */ 5 | package org.bitcoinj.protocols.payments; -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/directory/parsing/DocumentParser.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.directory.parsing; 2 | 3 | 4 | public interface DocumentParser { 5 | boolean parse(DocumentParsingResultHandler resultHandler); 6 | DocumentParsingResult parse(); 7 | } 8 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/params/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Network parameters encapsulate some of the differences between different Bitcoin networks such as the main 3 | * network, the testnet, regtest mode, unit testing params and so on. 4 | */ 5 | package org.bitcoinj.params; -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/BridgeRouter.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid; 2 | 3 | import com.subgraph.orchid.data.HexDigest; 4 | 5 | public interface BridgeRouter extends Router { 6 | void setIdentity(HexDigest identity); 7 | void setDescriptor(RouterDescriptor descriptor); 8 | } 9 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/crypto/TorKeyAgreement.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.crypto; 2 | 3 | public interface TorKeyAgreement { 4 | byte[] createOnionSkin(); 5 | boolean deriveKeysFromHandshakeResponse(byte[] handshakeResponse, byte[] keyMaterialOut, byte[] verifyHashOut); 6 | } 7 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/protocols/channels/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Micropayment channels allow for rapid tiny payments to be made to a third party once a channel has been set up, using 3 | * some of the advanced features of the Bitcoin protocol. 4 | */ 5 | package org.bitcoinj.protocols.channels; -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/protocols/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * High level protocols that build on top of Bitcoin go here: we have the payment protocol for sending transactions 3 | * from sender to receiver with metadata, and a micropayment channels implementation. 4 | */ 5 | package org.bitcoinj.protocols; -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/dashboard/DashboardRenderer.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.dashboard; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | public interface DashboardRenderer { 7 | void renderComponent(PrintWriter writer, int flags, Object component) throws IOException; 8 | } 9 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/utils/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Formatting monetary amounts, representing exchange rates, a program for loading Bitcoin Core saved block files, 3 | * a class to control how bitcoinj uses threads and misc other utility classes that don't fit anywhere else. 4 | */ 5 | package org.bitcoinj.utils; -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/data/exitpolicy/ExitTarget.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.data.exitpolicy; 2 | 3 | import com.subgraph.orchid.data.IPv4Address; 4 | 5 | public interface ExitTarget { 6 | boolean isAddressTarget(); 7 | IPv4Address getAddress(); 8 | String getHostname(); 9 | int getPort(); 10 | } 11 | -------------------------------------------------------------------------------- /tools/build-checkpoints: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | # Check if the jar has been built. 6 | if [ ! -e target/build-checkpoints.jar ]; then 7 | echo "Compiling BuildCheckpoints to a JAR" 8 | cd .. 9 | mvn package -DskipTests 10 | cd tools 11 | fi 12 | 13 | java -jar target/build-checkpoints.jar "$@" 14 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/InternalCircuit.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid; 2 | 3 | public interface InternalCircuit extends Circuit { 4 | DirectoryCircuit cannibalizeToDirectory(Router target); 5 | Circuit cannibalizeToIntroductionPoint(Router target); 6 | HiddenServiceCircuit connectHiddenService(CircuitNode node); 7 | } 8 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/directory/parsing/DocumentParsingResultHandler.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.directory.parsing; 2 | 3 | 4 | public interface DocumentParsingResultHandler { 5 | void documentParsed(T document); 6 | void documentInvalid(T document, String message); 7 | void parsingError(String message); 8 | } 9 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/HiddenServiceCircuit.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid; 2 | 3 | import java.util.concurrent.TimeoutException; 4 | 5 | 6 | public interface HiddenServiceCircuit extends Circuit { 7 | Stream openStream(int port, long timeout) throws InterruptedException, TimeoutException, StreamConnectFailedException; 8 | } 9 | -------------------------------------------------------------------------------- /tools/wallet-tool: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | # Check if the jar has been built. 6 | if [ ! -e target/wallet-tool.jar ] || [[ "$ALWAYS_BUILD_WALLETTOOL" != "" ]]; then 7 | echo "Compiling WalletTool to a JAR" 8 | cd .. 9 | mvn package -DskipTests 10 | cd tools 11 | fi 12 | 13 | java -jar target/wallet-tool.jar "$@" 14 | -------------------------------------------------------------------------------- /wallettemplate/src/main/java/wallettemplate/utils/easing/EasingMode.java: -------------------------------------------------------------------------------- 1 | package wallettemplate.utils.easing; 2 | 3 | /** 4 | * Defines the three easing modes, ease-in, ease-out and ease-both. 5 | * 6 | * @author Christian Schudt 7 | */ 8 | public enum EasingMode { 9 | EASE_IN, 10 | EASE_OUT, 11 | EASE_BOTH 12 | } 13 | -------------------------------------------------------------------------------- /orchid/logging.properties: -------------------------------------------------------------------------------- 1 | handlers=java.util.logging.ConsoleHandler 2 | .level = INFO 3 | 4 | java.util.logging.ConsoleHandler.level = FINEST 5 | java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter 6 | java.util.logging.SimpleFormatter.format =[%1$tT] %4$s: %5$s%6$s%n 7 | 8 | # com.subgraph.orchid.circuits.level=FINE 9 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/signers/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Transaction signers know how to calculate signatures over transactions in different contexts, for example, using 3 | * local private keys or fetching them from remote servers. The {@link org.bitcoinj.core.Wallet} class uses these 4 | * when sending money. 5 | */ 6 | package org.bitcoinj.signers; -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/wallet/AbstractKeyChainEventListener.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.wallet; 2 | 3 | import org.bitcoinj.core.ECKey; 4 | 5 | import java.util.List; 6 | 7 | public class AbstractKeyChainEventListener implements KeyChainEventListener { 8 | @Override 9 | public void onKeysAdded(List keys) { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/ConnectionFailedException.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid; 2 | 3 | public class ConnectionFailedException extends ConnectionIOException { 4 | 5 | private static final long serialVersionUID = -4484347156587613574L; 6 | 7 | public ConnectionFailedException(String message) { 8 | super(message); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/ConnectionHandshakeException.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid; 2 | 3 | public class ConnectionHandshakeException extends ConnectionIOException { 4 | 5 | private static final long serialVersionUID = -2544633445932967966L; 6 | 7 | public ConnectionHandshakeException(String message) { 8 | super(message); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/testing/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Various utilities for writing unit tests: also useful for testing your own code and apps that build on top of 3 | * bitcoinj. Some of these are junit4 classes you can subclass, and others are static utility methods for building 4 | * fake transactions and so on. 5 | */ 6 | package org.bitcoinj.testing; -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/core/listeners/BlockChainListener.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.core.listeners; 2 | 3 | /** 4 | * Old interface for backwards compatibility. Implement the more specific interfaces instead. 5 | */ 6 | @Deprecated 7 | public interface BlockChainListener extends NewBestBlockListener, TransactionReceivedInBlockListener, ReorganizeListener { 8 | } 9 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/OpenFailedException.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid; 2 | 3 | public class OpenFailedException extends Exception { 4 | 5 | private static final long serialVersionUID = 1989001056577214666L; 6 | 7 | public OpenFailedException() { 8 | } 9 | 10 | public OpenFailedException(String message) { 11 | super(message); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/wallet/AllRandomKeysRotating.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.wallet; 2 | 3 | /** 4 | * Indicates that an attempt was made to upgrade a random wallet to deterministic, but there were no non-rotating 5 | * random keys to use as source material for the seed. Add a non-compromised key first! 6 | */ 7 | public class AllRandomKeysRotating extends RuntimeException {} 8 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/ConnectionIOException.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid; 2 | 3 | public class ConnectionIOException extends Exception { 4 | 5 | private static final long serialVersionUID = -5537650738995969203L; 6 | 7 | public ConnectionIOException() { 8 | super(); 9 | } 10 | 11 | public ConnectionIOException(String message) { 12 | super(message); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/net/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Classes handling low level network management using either NIO (async io) or older style blocking sockets (useful for 3 | * using SOCKS proxies, Tor, SSL etc). The code in this package implements a simple network abstraction a little like 4 | * what the Netty library provides, but with only what bitcoinj needs. 5 | */ 6 | package org.bitcoinj.net; -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/wallet/DeterministicUpgradeRequiredException.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.wallet; 2 | 3 | /** 4 | * Indicates that an attempt was made to use HD wallet features on a wallet that was deserialized from an old, 5 | * pre-HD random wallet without calling upgradeToDeterministic() beforehand. 6 | */ 7 | public class DeterministicUpgradeRequiredException extends RuntimeException {} 8 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/directory/parsing/DocumentParsingResult.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.directory.parsing; 2 | 3 | import java.util.List; 4 | 5 | public interface DocumentParsingResult { 6 | T getDocument(); 7 | List getParsedDocuments(); 8 | boolean isOkay(); 9 | boolean isInvalid(); 10 | T getInvalidDocument(); 11 | boolean isError(); 12 | String getMessage(); 13 | } 14 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/wallet/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Classes that support the {@link org.bitcoinj.core.Wallet}, which knows how to find and save transactions relevant to 3 | * a set of keys or scripts, calculate balances, and spend money: the wallet has many features and can be extended 4 | * in various ways, please refer to the website for documentation on how to use it. 5 | */ 6 | package org.bitcoinj.wallet; -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/circuits/path/PathSelectionFailedException.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.circuits.path; 2 | 3 | public class PathSelectionFailedException extends Exception { 4 | private static final long serialVersionUID = -8855252756021674268L; 5 | 6 | public PathSelectionFailedException() {} 7 | 8 | public PathSelectionFailedException(String message) { 9 | super(message); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/misc/Utils.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.misc; 2 | 3 | public class Utils { 4 | public static boolean constantTimeArrayEquals(byte[] a1, byte[] a2) { 5 | if(a1.length != a2.length) { 6 | return false; 7 | } 8 | int result = 0; 9 | for(int i = 0; i < a1.length; i++) { 10 | result += (a1[i] & 0xFF) ^ (a2[i] & 0xFF); 11 | } 12 | return result == 0; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/ConnectionTimeoutException.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid; 2 | 3 | public class ConnectionTimeoutException extends ConnectionIOException { 4 | 5 | private static final long serialVersionUID = -6098661610150140151L; 6 | 7 | public ConnectionTimeoutException() { 8 | super(); 9 | } 10 | 11 | public ConnectionTimeoutException(String message) { 12 | super(message); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/TorParsingException.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid; 2 | 3 | 4 | public class TorParsingException extends TorException { 5 | public TorParsingException(String string) { 6 | super(string); 7 | } 8 | 9 | public TorParsingException(String string, Throwable ex) { 10 | super(string, ex); 11 | } 12 | 13 | private static final long serialVersionUID = -4997757416476363399L; 14 | } 15 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/socks/SocksRequestException.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.socks; 2 | 3 | public class SocksRequestException extends Exception { 4 | 5 | private static final long serialVersionUID = 844055056337565049L; 6 | 7 | SocksRequestException() {} 8 | SocksRequestException(String msg) { 9 | super(msg); 10 | } 11 | 12 | SocksRequestException(Throwable ex) { 13 | super(ex); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/circuits/hs/HSAuthenticationException.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.circuits.hs; 2 | 3 | public class HSAuthenticationException extends Exception { 4 | 5 | private static final long serialVersionUID = 1L; 6 | 7 | HSAuthenticationException(String message) { 8 | super(message); 9 | } 10 | 11 | HSAuthenticationException(String message, Throwable cause) { 12 | super(message, cause); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/core/listeners/OnTransactionBroadcastListener.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.core.listeners; 2 | 3 | import org.bitcoinj.core.*; 4 | 5 | /** 6 | * Called when a new transaction is broadcast over the network. 7 | */ 8 | public interface OnTransactionBroadcastListener { 9 | /** 10 | * Called when a new transaction is broadcast over the network. 11 | */ 12 | void onTransaction(Peer peer, Transaction t); 13 | } 14 | -------------------------------------------------------------------------------- /tools/build-checkpoints.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem Check if the jar has been built. 3 | set TARGET_JAR=build-checkpoints.jar 4 | 5 | if not exist "target/%TARGET_JAR%" goto BUILD 6 | goto RUN 7 | 8 | :BUILD 9 | 10 | echo Compiling BuildCheckpoints to a JAR 11 | cd .. 12 | call mvn package -DskipTests 13 | cd tools 14 | 15 | :RUN 16 | 17 | for /R "target/" %%F in (%TARGET_JAR%) do set JAR_NAME=%%~nxF 18 | java -jar "target/%JAR_NAME%" %1 %2 %3 %4 %5 %6 %7 %8 -------------------------------------------------------------------------------- /tools/wallet-tool.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem Check if the jar has been built. 3 | set TARGET_JAR=wallet-tool.jar 4 | 5 | if not exist "target/%TARGET_JAR%" goto BUILD 6 | if defined ALWAYS_BUILD_WALLETTOOL goto BUILD 7 | goto RUN 8 | 9 | :BUILD 10 | 11 | echo Compiling WalletTool to a JAR 12 | cd .. 13 | call mvn package -DskipTests 14 | cd tools 15 | 16 | :RUN 17 | 18 | for /R "target/" %%F in (%TARGET_JAR%) do set JAR_NAME=%%~nxF 19 | java -jar "target/%JAR_NAME%" %1 %2 %3 %4 %5 %6 %7 %8 -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/store/ChainFileLockedException.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.store; 2 | 3 | /** 4 | * Thrown by {@link SPVBlockStore} when the process cannot gain exclusive access to the chain file. 5 | */ 6 | public class ChainFileLockedException extends BlockStoreException { 7 | public ChainFileLockedException(String message) { 8 | super(message); 9 | } 10 | 11 | public ChainFileLockedException(Throwable t) { 12 | super(t); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tools/src/main/resources/org/bitcoinj/tools/build-checkpoints-help.txt: -------------------------------------------------------------------------------- 1 | BuildCheckpoints: create checkpoint files to use with CheckpointManager 2 | 3 | Usage: build-checkpoints --flags 4 | 5 | >>> OPTIONS 6 | --net=XXX Which network to connect to, defaults to MAIN, can also be TEST or REGTEST. 7 | --peer=1.2.3.4 IP address/domain name for connection instead of localhost. 8 | --days= How many days to keep as a safety margin. Checkpointing will be done up to this many days ago. -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/GuardEntry.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid; 2 | 3 | import java.util.Date; 4 | 5 | public interface GuardEntry { 6 | boolean isAdded(); 7 | void markAsDown(); 8 | void clearDownSince(); 9 | String getNickname(); 10 | String getIdentity(); 11 | String getVersion(); 12 | Date getCreatedTime(); 13 | Date getDownSince(); 14 | Date getLastConnectAttempt(); 15 | Date getUnlistedSince(); 16 | boolean testCurrentlyUsable(); 17 | Router getRouterForEntry(); 18 | } 19 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/directory/downloader/DirectoryRequestFailedException.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.directory.downloader; 2 | 3 | public class DirectoryRequestFailedException extends Exception { 4 | 5 | private static final long serialVersionUID = 1L; 6 | 7 | public DirectoryRequestFailedException(String message) { 8 | super(message); 9 | } 10 | 11 | public DirectoryRequestFailedException(String message, Throwable cause) { 12 | super(message, cause); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/store/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Block stores persist blockchain data downloaded from remote peers. There is an SPV block store which preserves a ring 3 | * buffer of headers on disk and is suitable for lightweight user wallets, a store that's backed by Postgres and which 4 | * can calculate a full indexed UTXO set (i.e. it can query address balances), a store that's backed by the embedded H2 5 | * database, and a memory only store useful for unit tests. 6 | */ 7 | package org.bitcoinj.store; -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/wallet/DeterministicUpgradeRequiresPassword.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.wallet; 2 | 3 | /** 4 | * Indicates that the pre-HD random wallet is encrypted, so you should try the upgrade again after getting the 5 | * users password. This is required because HD wallets are upgraded from random using the private key bytes of 6 | * the oldest non-rotating key, in order to make the upgrade process itself deterministic. 7 | */ 8 | public class DeterministicUpgradeRequiresPassword extends RuntimeException {} 9 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/encoders/DecoderException.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.encoders; 2 | 3 | public class DecoderException 4 | extends IllegalStateException 5 | { 6 | private static final long serialVersionUID = 4997418733670548381L; 7 | private Throwable cause; 8 | 9 | DecoderException(String msg, Throwable cause) 10 | { 11 | super(msg); 12 | 13 | this.cause = cause; 14 | } 15 | 16 | public Throwable getCause() 17 | { 18 | return cause; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/encoders/EncoderException.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.encoders; 2 | 3 | public class EncoderException 4 | extends IllegalStateException 5 | { 6 | private static final long serialVersionUID = 6589388628939318400L; 7 | private Throwable cause; 8 | 9 | EncoderException(String msg, Throwable cause) 10 | { 11 | super(msg); 12 | 13 | this.cause = cause; 14 | } 15 | 16 | public Throwable getCause() 17 | { 18 | return cause; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/TorException.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid; 2 | 3 | public class TorException extends RuntimeException { 4 | 5 | private static final long serialVersionUID = 2462760291055303580L; 6 | 7 | public TorException() { 8 | super(); 9 | } 10 | 11 | public TorException(String message) { 12 | super(message); 13 | } 14 | 15 | public TorException(String message, Throwable ex) { 16 | super(message, ex); 17 | } 18 | 19 | public TorException(Throwable ex) { 20 | super(ex); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/core/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The core package contains classes for network messages like {@link org.bitcoinj.core.Block} and 3 | * {@link org.bitcoinj.core.Transaction}, peer connectivity via {@link org.bitcoinj.core.PeerGroup}, 4 | * block chain management and the {@link org.bitcoinj.core.Wallet} class. 5 | * If what you're doing can be described as basic bitcoin tasks, the code is probably found here. 6 | * To learn more please consult the documentation on the website. 7 | */ 8 | package org.bitcoinj.core; -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # configuration for https://travis-ci.org/bitcoinj/bitcoinj 2 | sudo: false 3 | language: java 4 | jdk: oraclejdk8 5 | install: true # remove default 6 | script: 7 | - mvn -q clean install -Pno-network 8 | - jdk_switcher use openjdk6 9 | - cd orchid 10 | - mvn -q clean package 11 | - cd ../core 12 | - mvn -q clean package -Pno-network 13 | 14 | after_success: 15 | - cd ../core 16 | - mvn jacoco:report coveralls:report 17 | 18 | notifications: 19 | irc: 20 | channels: "irc.freenode.net#bitcoinj" 21 | skip_join: true 22 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/sockets/OrchidSocketImplFactory.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.sockets; 2 | 3 | import java.net.SocketImpl; 4 | import java.net.SocketImplFactory; 5 | 6 | import com.subgraph.orchid.TorClient; 7 | 8 | public class OrchidSocketImplFactory implements SocketImplFactory { 9 | private final TorClient torClient; 10 | 11 | public OrchidSocketImplFactory(TorClient torClient) { 12 | this.torClient = torClient; 13 | } 14 | 15 | public SocketImpl createSocketImpl() { 16 | return new OrchidSocketImpl(torClient); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/directory/parsing/NameIntegerParameter.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.directory.parsing; 2 | 3 | public class NameIntegerParameter { 4 | 5 | private final String name; 6 | private final int value; 7 | 8 | public NameIntegerParameter(String name, int value) { 9 | this.name = name; 10 | this.value = value; 11 | } 12 | 13 | public String getName() { 14 | return name; 15 | } 16 | 17 | public int getValue() { 18 | return value; 19 | } 20 | 21 | public String toString() { 22 | return name +"="+ value; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /core/src/test/resources/org/bitcoinj/core/sig_canonical.json: -------------------------------------------------------------------------------- 1 | [ 2 | "300602010002010001", 3 | "3008020200ff020200ff01", 4 | "304402203932c892e2e550f3af8ee4ce9c215a87f9bb831dcac87b2838e2c2eaa891df0c022030b61dd36543125d56b9f9f3a1f9353189e5af33cdda8d77a5209aec03978fa001", 5 | "30450220076045be6f9eca28ff1ec606b833d0b87e70b2a630f5e3a496b110967a40f90a0221008fffd599910eefe00bc803c688c2eca1d2ba7f6b180620eaa03488e6585db6ba01", 6 | "3046022100876045be6f9eca28ff1ec606b833d0b87e70b2a630f5e3a496b110967a40f90a0221008fffd599910eefe00bc803c688c2eca1d2ba7f6b180620eaa03488e6585db6ba01" 7 | ] 8 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/encoders/Encoder.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.encoders; 2 | 3 | import java.io.IOException; 4 | import java.io.OutputStream; 5 | 6 | /** 7 | * Encode and decode byte arrays (typically from binary to 7-bit ASCII 8 | * encodings). 9 | */ 10 | public interface Encoder 11 | { 12 | int encode(byte[] data, int off, int length, OutputStream out) throws IOException; 13 | 14 | int decode(byte[] data, int off, int length, OutputStream out) throws IOException; 15 | 16 | int decode(String data, OutputStream out) throws IOException; 17 | } 18 | -------------------------------------------------------------------------------- /core/src/test/resources/org/bitcoinj/protocols/payments/README: -------------------------------------------------------------------------------- 1 | # Create key store for CA certificate 2 | keytool -keystore test-cacerts -importcert -file test-cacert.pem -alias test-cacert -deststorepass password 3 | 4 | # Create key store for certificate and private key 5 | openssl pkcs12 -export -in test-valid-cert.pem -inkey test-valid-key.pem -passin pass:password -out test-valid.p12 -passout pass:password -name test-valid 6 | keytool -importkeystore -deststorepass password -destkeypass password -destkeystore test-valid-cert -srckeystore test-valid.p12 -srcstoretype PKCS12 -srcstorepass password -alias test-valid 7 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/crypto/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The crypto package contains classes that work with key derivation algorithms like scrypt (passwords to AES keys), 3 | * BIP 32 hierarchies (chains of keys from a root seed), X.509 utilities for the payment protocol and other general 4 | * cryptography tasks. It also contains a class that can disable the (long since obsolete) DRM Java/US Govt imposes 5 | * on strong crypto. This is legal because Oracle got permission to ship strong AES to everyone years ago but hasn't 6 | * bothered to actually remove the logic barriers. 7 | */ 8 | package org.bitcoinj.crypto; -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/VoteAuthorityEntry.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid; 2 | 3 | import java.util.List; 4 | 5 | import com.subgraph.orchid.data.HexDigest; 6 | import com.subgraph.orchid.data.IPv4Address; 7 | import com.subgraph.orchid.directory.consensus.DirectorySignature; 8 | 9 | public interface VoteAuthorityEntry { 10 | String getNickname(); 11 | HexDigest getIdentity(); 12 | String getHostname(); 13 | IPv4Address getAddress(); 14 | int getDirectoryPort(); 15 | int getRouterPort(); 16 | String getContact(); 17 | HexDigest getVoteDigest(); 18 | List getSignatures(); 19 | } 20 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/dashboard/DashboardRenderable.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.dashboard; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | public interface DashboardRenderable { 7 | 8 | static int DASHBOARD_CONNECTIONS = 1 << 0; 9 | static int DASHBOARD_CONNECTIONS_VERBOSE = 1 << 1; 10 | static int DASHBOARD_PREDICTED_PORTS = 1 << 2; 11 | static int DASHBOARD_CIRCUITS = 1 << 3; 12 | static int DASHBOARD_STREAMS = 1 << 4; 13 | 14 | void dashboardRender(DashboardRenderer renderer, PrintWriter writer, int flags) throws IOException; 15 | } 16 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/directory/router/MicrodescriptorCacheLocation.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.directory.router; 2 | 3 | public class MicrodescriptorCacheLocation { 4 | 5 | private final int offset; 6 | private final int length; 7 | 8 | public MicrodescriptorCacheLocation(int offset, int length) { 9 | this.offset = offset; 10 | this.length = length; 11 | } 12 | 13 | public int getOffset() { 14 | return offset; 15 | } 16 | 17 | public int getLength() { 18 | return length; 19 | } 20 | 21 | public String toString() { 22 | return "MD Cache offset: "+ offset + " length: "+ length; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/directory/downloader/BridgeDescriptorFetcher.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.directory.downloader; 2 | 3 | import java.nio.ByteBuffer; 4 | 5 | import com.subgraph.orchid.RouterDescriptor; 6 | import com.subgraph.orchid.directory.parsing.DocumentParser; 7 | 8 | public class BridgeDescriptorFetcher extends DocumentFetcher{ 9 | 10 | @Override 11 | String getRequestPath() { 12 | return "/tor/server/authority"; 13 | } 14 | 15 | @Override 16 | DocumentParser createParser(ByteBuffer response) { 17 | return PARSER_FACTORY.createRouterDescriptorParser(response, true); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/circuits/PredictedPortTarget.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.circuits; 2 | 3 | import com.subgraph.orchid.data.IPv4Address; 4 | import com.subgraph.orchid.data.exitpolicy.ExitTarget; 5 | 6 | public class PredictedPortTarget implements ExitTarget { 7 | 8 | final int port; 9 | 10 | public PredictedPortTarget(int port) { 11 | this.port = port; 12 | } 13 | 14 | public boolean isAddressTarget() { 15 | return false; 16 | } 17 | 18 | public IPv4Address getAddress() { 19 | return new IPv4Address(0); 20 | } 21 | 22 | public String getHostname() { 23 | return ""; 24 | } 25 | 26 | public int getPort() { 27 | return port; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/DirectoryCircuit.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid; 2 | 3 | import java.util.concurrent.TimeoutException; 4 | 5 | public interface DirectoryCircuit extends Circuit { 6 | /** 7 | * Open an anonymous connection to the directory service running on the 8 | * final node in this circuit. 9 | * 10 | * @param timeout in milliseconds 11 | * @param autoclose if set to true, closing stream also marks this circuit for close 12 | * 13 | * @return The status response returned by trying to open the stream. 14 | */ 15 | Stream openDirectoryStream(long timeout, boolean autoclose) throws InterruptedException, TimeoutException, StreamConnectFailedException; 16 | } 17 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/DirectoryServer.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid; 2 | 3 | import java.util.List; 4 | 5 | import com.subgraph.orchid.data.HexDigest; 6 | 7 | /** 8 | * Represents a directory authority server or a directory cache. 9 | */ 10 | public interface DirectoryServer extends Router { 11 | int getDirectoryPort(); 12 | boolean isV2Authority(); 13 | boolean isV3Authority(); 14 | HexDigest getV3Identity(); 15 | boolean isHiddenServiceAuthority(); 16 | boolean isBridgeAuthority(); 17 | boolean isExtraInfoCache(); 18 | 19 | KeyCertificate getCertificateByFingerprint(HexDigest fingerprint); 20 | List getCertificates(); 21 | void addCertificate(KeyCertificate certificate); 22 | } 23 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/circuits/hs/HSDescriptorDirectory.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.circuits.hs; 2 | 3 | import com.subgraph.orchid.Router; 4 | import com.subgraph.orchid.data.HexDigest; 5 | 6 | public class HSDescriptorDirectory { 7 | 8 | private final HexDigest descriptorId; 9 | private final Router directory; 10 | 11 | HSDescriptorDirectory(HexDigest descriptorId, Router directory) { 12 | this.descriptorId = descriptorId; 13 | this.directory = directory; 14 | } 15 | 16 | Router getDirectory() { 17 | return directory; 18 | } 19 | 20 | HexDigest getDescriptorId() { 21 | return descriptorId; 22 | } 23 | 24 | public String toString() { 25 | return descriptorId + " : " + directory; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/protocols/channels/PaymentIncrementAck.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.protocols.channels; 2 | 3 | import org.bitcoinj.core.Coin; 4 | import com.google.protobuf.ByteString; 5 | 6 | import javax.annotation.Nullable; 7 | 8 | /** 9 | * An acknowledgement of a payment increase 10 | */ 11 | public class PaymentIncrementAck { 12 | private final Coin value; 13 | @Nullable private final ByteString info; 14 | 15 | public PaymentIncrementAck(Coin value, @Nullable ByteString info) { 16 | this.value = value; 17 | this.info = info; 18 | } 19 | 20 | public Coin getValue() { 21 | return value; 22 | } 23 | 24 | @Nullable 25 | public ByteString getInfo() { 26 | return info; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/config/TorConfigBridgeLine.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.config; 2 | 3 | import com.subgraph.orchid.data.HexDigest; 4 | import com.subgraph.orchid.data.IPv4Address; 5 | 6 | public class TorConfigBridgeLine { 7 | 8 | private final IPv4Address address; 9 | private final int port; 10 | private final HexDigest fingerprint; 11 | 12 | TorConfigBridgeLine(IPv4Address address, int port, HexDigest fingerprint) { 13 | this.address = address; 14 | this.port = port; 15 | this.fingerprint = fingerprint; 16 | } 17 | 18 | public IPv4Address getAddress() { 19 | return address; 20 | } 21 | 22 | public int getPort() { 23 | return port; 24 | } 25 | 26 | public HexDigest getFingerprint() { 27 | return fingerprint; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /core/src/peerseeds.proto: -------------------------------------------------------------------------------- 1 | package org.bitcoin.crawler; 2 | 3 | // 4 | // A simple protocol for describing signed sets of IP addresses. Intended to be distributed via HTTP[S] or in files. 5 | // 6 | 7 | option java_package = "org.bitcoin.crawler"; 8 | option java_outer_classname = "PeerSeedProtos"; 9 | 10 | message PeerSeedData { 11 | required string ip_address = 1; 12 | required uint32 port = 2; 13 | required uint32 services = 3; 14 | } 15 | 16 | message PeerSeeds { 17 | repeated PeerSeedData seed = 1; 18 | required uint64 timestamp = 2; // seconds since UNIX epoch 19 | required string net = 3; 20 | } 21 | 22 | message SignedPeerSeeds { 23 | required bytes peer_seeds = 1; 24 | required bytes signature = 2; 25 | required bytes pubkey = 3; 26 | } -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/circuits/hs/HSDescriptorCookie.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.circuits.hs; 2 | 3 | public class HSDescriptorCookie { 4 | 5 | public enum CookieType { COOKIE_BASIC, COOKIE_STEALTH }; 6 | 7 | private final CookieType type; 8 | private final byte[] value; 9 | 10 | public HSDescriptorCookie(CookieType type, byte[] value) { 11 | this.type = type; 12 | this.value = value; 13 | } 14 | 15 | public byte getAuthTypeByte() { 16 | switch(type) { 17 | case COOKIE_BASIC: 18 | return 1; 19 | case COOKIE_STEALTH: 20 | return 2; 21 | default: 22 | throw new IllegalStateException(); 23 | } 24 | } 25 | 26 | public CookieType getType() { 27 | return type; 28 | } 29 | 30 | public byte[] getValue() { 31 | return value; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/RouterStatus.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid; 2 | 3 | import com.subgraph.orchid.data.HexDigest; 4 | import com.subgraph.orchid.data.IPv4Address; 5 | import com.subgraph.orchid.data.Timestamp; 6 | import com.subgraph.orchid.data.exitpolicy.ExitPorts; 7 | 8 | public interface RouterStatus { 9 | String getNickname(); 10 | HexDigest getIdentity(); 11 | HexDigest getDescriptorDigest(); 12 | HexDigest getMicrodescriptorDigest(); 13 | Timestamp getPublicationTime(); 14 | IPv4Address getAddress(); 15 | int getRouterPort(); 16 | boolean isDirectory(); 17 | int getDirectoryPort(); 18 | boolean hasFlag(String flag); 19 | String getVersion(); 20 | boolean hasBandwidth(); 21 | int getEstimatedBandwidth(); 22 | int getMeasuredBandwidth(); 23 | ExitPorts getExitPorts(); 24 | } 25 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/data/BandwidthHistory.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.data; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class BandwidthHistory { 7 | 8 | private final Timestamp reportingTime; 9 | private final int reportingInterval; 10 | private final List samples = new ArrayList(); 11 | 12 | public BandwidthHistory(Timestamp reportingTime, int reportingInterval) { 13 | this.reportingTime = reportingTime; 14 | this.reportingInterval = reportingInterval; 15 | } 16 | 17 | public int getReportingInterval() { 18 | return reportingInterval; 19 | } 20 | 21 | public Timestamp getReportingTime() { 22 | return reportingTime; 23 | } 24 | 25 | public void addSample(int value) { 26 | samples.add(value); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/directory/parsing/DocumentParserFactory.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.directory.parsing; 2 | 3 | import java.nio.ByteBuffer; 4 | 5 | import com.subgraph.orchid.ConsensusDocument; 6 | import com.subgraph.orchid.KeyCertificate; 7 | import com.subgraph.orchid.RouterDescriptor; 8 | import com.subgraph.orchid.RouterMicrodescriptor; 9 | 10 | public interface DocumentParserFactory { 11 | DocumentParser createRouterDescriptorParser(ByteBuffer buffer, boolean verifySignatures); 12 | 13 | DocumentParser createRouterMicrodescriptorParser(ByteBuffer buffer); 14 | 15 | DocumentParser createKeyCertificateParser(ByteBuffer buffer); 16 | 17 | DocumentParser createConsensusDocumentParser(ByteBuffer buffer); 18 | } 19 | -------------------------------------------------------------------------------- /examples/src/main/javascript/tor.js: -------------------------------------------------------------------------------- 1 | // Example of how to connect to a Tor hidden service and use it as a peer. 2 | // See demo.js to learn how to invoke this program. 3 | 4 | var bcj = org.bitcoinj; 5 | var params = bcj.params.MainNetParams.get(); 6 | var context = new bcj.core.Context(params); 7 | bcj.utils.BriefLogFormatter.init(); 8 | 9 | var PeerAddress = Java.type("org.bitcoinj.core.PeerAddress"); 10 | var pg = bcj.core.PeerGroup.newWithTor(context, null, new com.subgraph.orchid.TorClient(), false); 11 | pg.addAddress(new PeerAddress("nkf5e6b7pl4jfd4a.onion", params.port)); 12 | pg.start(); 13 | 14 | pg.waitForPeers(1).get(); 15 | print("Connected to: " + pg.connectedPeers); 16 | 17 | for each (var peer in pg.connectedPeers) { 18 | print(peer.peerVersionMessage.subVer); 19 | peer.ping().get() 20 | } 21 | 22 | pg.stop(); -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/uri/OptionalFieldValidationException.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.uri; 2 | 3 | /** 4 | *

Exception to provide the following to {@link org.bitcoinj.uri.BitcoinURI}:

5 | *
    6 | *
  • Provision of parsing error messages
  • 7 | *
8 | *

This exception occurs when an optional field is detected (under the Bitcoin URI scheme) and fails 9 | * to pass the associated test (such as {@code amount} not being a valid number).

10 | * 11 | * @since 0.3.0 12 | *   13 | */ 14 | public class OptionalFieldValidationException extends BitcoinURIParseException { 15 | 16 | public OptionalFieldValidationException(String s) { 17 | super(s); 18 | } 19 | 20 | public OptionalFieldValidationException(String s, Throwable throwable) { 21 | super(s, throwable); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tools/src/main/java/org/bitcoinj/tools/NetworkEnum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Mike Hearn 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.tools; 18 | 19 | public enum NetworkEnum { 20 | MAIN, 21 | PROD, // alias for MAIN 22 | TEST, 23 | REGTEST 24 | } 25 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/jni/NativePaymentChannelHandlerFactory.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.jni; 2 | 3 | import org.bitcoinj.protocols.channels.PaymentChannelServerListener; 4 | import org.bitcoinj.protocols.channels.ServerConnectionEventHandler; 5 | 6 | import javax.annotation.Nullable; 7 | import java.net.SocketAddress; 8 | 9 | /** 10 | * An event listener that relays events to a native C++ object. A pointer to that object is stored in 11 | * this class using JNI on the native side, thus several instances of this can point to different actual 12 | * native implementations. 13 | */ 14 | public class NativePaymentChannelHandlerFactory implements PaymentChannelServerListener.HandlerFactory { 15 | public long ptr; 16 | 17 | @Nullable 18 | @Override 19 | public native ServerConnectionEventHandler onNewConnection(SocketAddress clientAddress); 20 | } 21 | -------------------------------------------------------------------------------- /core/src/test/java/org/bitcoinj/core/MemoryFullPrunedBlockChainTest.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.core; 2 | 3 | import org.bitcoinj.store.BlockStoreException; 4 | import org.bitcoinj.store.FullPrunedBlockStore; 5 | import org.bitcoinj.store.MemoryFullPrunedBlockStore; 6 | 7 | /** 8 | * A MemoryStore implementation of the FullPrunedBlockStoreTest 9 | */ 10 | public class MemoryFullPrunedBlockChainTest extends AbstractFullPrunedBlockChainTest 11 | { 12 | @Override 13 | public FullPrunedBlockStore createStore(NetworkParameters params, int blockCount) throws BlockStoreException 14 | { 15 | return new MemoryFullPrunedBlockStore(params, blockCount); 16 | } 17 | 18 | @Override 19 | public void resetStore(FullPrunedBlockStore store) throws BlockStoreException 20 | { 21 | //No-op for memory store, because it's not persistent 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/crypto/KeyCrypterException.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.crypto; 2 | 3 | /** 4 | *

Exception to provide the following:

5 | *
    6 | *
  • Provision of encryption / decryption exception
  • 7 | *
8 | *

This base exception acts as a general failure mode not attributable to a specific cause (other than 9 | * that reported in the exception message). Since this is in English, it may not be worth reporting directly 10 | * to the user other than as part of a "general failure to parse" response.

11 | */ 12 | public class KeyCrypterException extends RuntimeException { 13 | private static final long serialVersionUID = -4441989608332681377L; 14 | 15 | public KeyCrypterException(String s) { 16 | super(s); 17 | } 18 | 19 | public KeyCrypterException(String s, Throwable throwable) { 20 | super(s, throwable); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/events/EventManager.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.events; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class EventManager { 7 | private final List handlers = new ArrayList(); 8 | 9 | public void addListener(final EventHandler listener) { 10 | synchronized(this) { 11 | handlers.add(listener); 12 | } 13 | } 14 | 15 | public void removeListener(final EventHandler listener) { 16 | synchronized(this) { 17 | handlers.remove(listener); 18 | } 19 | } 20 | 21 | public void fireEvent(final Event event) { 22 | EventHandler[] handlersCopy; 23 | 24 | synchronized(this) { 25 | handlersCopy = new EventHandler[handlers.size()]; 26 | handlers.toArray(handlersCopy); 27 | } 28 | for(EventHandler handler : handlersCopy) { 29 | handler.handleEvent(event); 30 | } 31 | 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /core/src/test/java/org/bitcoinj/core/WalletExtensionsTest.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.core; 2 | 3 | import org.bitcoinj.testing.FooWalletExtension; 4 | import org.bitcoinj.testing.TestWithWallet; 5 | import org.junit.After; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | 9 | public class WalletExtensionsTest extends TestWithWallet { 10 | 11 | @Before 12 | @Override 13 | public void setUp() throws Exception { 14 | super.setUp(); 15 | } 16 | 17 | @After 18 | @Override 19 | public void tearDown() throws Exception { 20 | super.tearDown(); 21 | } 22 | 23 | @Test(expected = java.lang.IllegalStateException.class) 24 | public void duplicateWalletExtensionTest() { 25 | wallet.addExtension(new FooWalletExtension("com.whatever.required", true)); 26 | wallet.addExtension(new FooWalletExtension("com.whatever.required", true)); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/crypto/HDDerivationException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Matija Mazi. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.crypto; 18 | 19 | public class HDDerivationException extends RuntimeException { 20 | public HDDerivationException(String message) { 21 | super(message); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/wallet/CoinSelection.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.wallet; 2 | 3 | import org.bitcoinj.core.Coin; 4 | import org.bitcoinj.core.TransactionOutput; 5 | 6 | import java.util.Collection; 7 | 8 | /** 9 | * Represents the results of a 10 | * {@link CoinSelector#select(Coin, java.util.List)} operation. A 11 | * coin selection represents a list of spendable transaction outputs that sum together to give valueGathered. 12 | * Different coin selections could be produced by different coin selectors from the same input set, according 13 | * to their varying policies. 14 | */ 15 | public class CoinSelection { 16 | public Coin valueGathered; 17 | public Collection gathered; 18 | 19 | public CoinSelection(Coin valueGathered, Collection gathered) { 20 | this.valueGathered = valueGathered; 21 | this.gathered = gathered; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /core/src/test/java/org/bitcoinj/utils/BaseTaggableObjectTest.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.utils; 2 | 3 | import com.google.protobuf.ByteString; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | 7 | import static org.junit.Assert.assertEquals; 8 | import static org.junit.Assert.assertNull; 9 | 10 | public class BaseTaggableObjectTest { 11 | private BaseTaggableObject obj; 12 | 13 | @Before 14 | public void setUp() throws Exception { 15 | obj = new BaseTaggableObject(); 16 | } 17 | 18 | @Test 19 | public void tags() throws Exception { 20 | assertNull(obj.maybeGetTag("foo")); 21 | obj.setTag("foo", ByteString.copyFromUtf8("bar")); 22 | assertEquals("bar", obj.getTag("foo").toStringUtf8()); 23 | } 24 | 25 | @Test(expected = IllegalArgumentException.class) 26 | public void exception() throws Exception { 27 | obj.getTag("non existent"); 28 | } 29 | } -------------------------------------------------------------------------------- /wallettemplate/src/main/resources/wallettemplate/utils/text-validation.css: -------------------------------------------------------------------------------- 1 | .validation_error { 2 | -fx-background-color: red, 3 | linear-gradient( 4 | to bottom, 5 | derive(red,70%) 5%, 6 | derive(red,90%) 40% 7 | ); 8 | } 9 | 10 | .text-area.validation_error .content { 11 | -fx-background-color: red, 12 | linear-gradient( 13 | to bottom, 14 | derive(red,70%) 5%, 15 | derive(red,90%) 40% 16 | ); 17 | } 18 | 19 | .date-picker.validation_error > .text-field { 20 | -fx-background-color: red, 21 | linear-gradient( 22 | to bottom, 23 | derive(red,70%) 5%, 24 | derive(red,90%) 40% 25 | ); 26 | } 27 | 28 | .validation_warning { 29 | -fx-background-color: orange, 30 | linear-gradient( 31 | to bottom, 32 | derive(orange,70%) 5%, 33 | derive(orange,90%) 40% 34 | ); 35 | } 36 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/uri/RequiredFieldValidationException.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.uri; 2 | 3 | /** 4 | *

Exception to provide the following to {@link BitcoinURI}:

5 | *
    6 | *
  • Provision of parsing error messages
  • 7 | *
8 | *

This exception occurs when a required field is detected (under the BIP21 rules) and fails 9 | * to pass the associated test (such as {@code req-expires} being out of date), or the required field is unknown 10 | * to this version of the client in which case it should fail for security reasons.

11 | * 12 | * @since 0.3.0 13 | *   14 | */ 15 | public class RequiredFieldValidationException extends BitcoinURIParseException { 16 | 17 | public RequiredFieldValidationException(String s) { 18 | super(s); 19 | } 20 | 21 | public RequiredFieldValidationException(String s, Throwable throwable) { 22 | super(s, throwable); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/utils/DaemonThreadFactory.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.utils; 2 | 3 | import javax.annotation.Nonnull; 4 | import javax.annotation.Nullable; 5 | import java.util.concurrent.Executors; 6 | import java.util.concurrent.ThreadFactory; 7 | 8 | /** Thread factory whose threads are marked as daemon and won't prevent process exit. */ 9 | public class DaemonThreadFactory implements ThreadFactory { 10 | @Nullable private final String name; 11 | 12 | public DaemonThreadFactory(@Nullable String name) { 13 | this.name = name; 14 | } 15 | 16 | public DaemonThreadFactory() { 17 | this(null); 18 | } 19 | 20 | @Override 21 | public Thread newThread(@Nonnull Runnable runnable) { 22 | Thread thread = Executors.defaultThreadFactory().newThread(runnable); 23 | thread.setDaemon(true); 24 | if (name != null) 25 | thread.setName(name); 26 | return thread; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/directory/downloader/ConsensusFetcher.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.directory.downloader; 2 | 3 | import java.nio.ByteBuffer; 4 | 5 | import com.subgraph.orchid.ConsensusDocument; 6 | import com.subgraph.orchid.directory.parsing.DocumentParser; 7 | 8 | public class ConsensusFetcher extends DocumentFetcher{ 9 | 10 | private final static String CONSENSUS_BASE_PATH = "/tor/status-vote/current/"; 11 | 12 | private final boolean useMicrodescriptors; 13 | 14 | 15 | public ConsensusFetcher(boolean useMicrodescriptors) { 16 | this.useMicrodescriptors = useMicrodescriptors; 17 | } 18 | 19 | @Override 20 | String getRequestPath() { 21 | return CONSENSUS_BASE_PATH + ((useMicrodescriptors) ? 22 | ("consensus-microdesc") : ("consensus")); 23 | } 24 | 25 | @Override 26 | DocumentParser createParser(ByteBuffer response) { 27 | return PARSER_FACTORY.createConsensusDocumentParser(response); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/Revision.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.io.InputStreamReader; 7 | 8 | public class Revision { 9 | private final static String REVISION_FILE_PATH = "/build-revision"; 10 | 11 | public static String getBuildRevision() { 12 | final InputStream input = tryResourceOpen(); 13 | if(input == null) { 14 | return ""; 15 | } 16 | try { 17 | return readFirstLine(input); 18 | } catch (IOException e) { 19 | return ""; 20 | } 21 | } 22 | 23 | private static InputStream tryResourceOpen() { 24 | return Revision.class.getResourceAsStream(REVISION_FILE_PATH); 25 | } 26 | 27 | private static String readFirstLine(InputStream input) throws IOException { 28 | try { 29 | final BufferedReader reader = new BufferedReader(new InputStreamReader(input)); 30 | return reader.readLine(); 31 | } finally { 32 | input.close(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/wallet/AllowUnconfirmedCoinSelector.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.wallet; 2 | 3 | import org.bitcoinj.core.Transaction; 4 | 5 | /** 6 | * This coin selector will select any transaction at all, regardless of where it came from or whether it was 7 | * confirmed yet. However immature coinbases will not be included (would be a protocol violation). 8 | */ 9 | public class AllowUnconfirmedCoinSelector extends DefaultCoinSelector { 10 | @Override protected boolean shouldSelect(Transaction tx) { 11 | return true; 12 | } 13 | 14 | private static AllowUnconfirmedCoinSelector instance; 15 | 16 | /** Returns a global static instance of the selector. */ 17 | public static AllowUnconfirmedCoinSelector get() { 18 | // This doesn't have to be thread safe as the object has no state, so discarded duplicates are harmless. 19 | if (instance == null) 20 | instance = new AllowUnconfirmedCoinSelector(); 21 | return instance; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/core/listeners/WalletEventListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.core.listeners; 18 | 19 | /** 20 | *

Common interface for wallet changes and transactions. For fine-grain 21 | * events please use the super-interfaces.

22 | */ 23 | public interface WalletEventListener extends WalletChangeEventListener, WalletCoinEventListener { 24 | } 25 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/wallet/CoinSelector.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.wallet; 2 | 3 | import org.bitcoinj.core.Coin; 4 | import org.bitcoinj.core.TransactionOutput; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * A CoinSelector is responsible for picking some outputs to spend, from the list of all possible outputs. It 10 | * allows you to customize the policies for creation of transactions to suit your needs. The select operation 11 | * may return a {@link CoinSelection} that has a valueGathered lower than the requested target, if there's not 12 | * enough money in the wallet. 13 | */ 14 | public interface CoinSelector { 15 | /** 16 | * Creates a CoinSelection that tries to meet the target amount of value. The candidates list is given to 17 | * this call and can be edited freely. See the docs for CoinSelection to learn more, or look a the implementation 18 | * of {@link DefaultCoinSelector}. 19 | */ 20 | CoinSelection select(Coin target, List candidates); 21 | } 22 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/StreamConnectFailedException.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid; 2 | 3 | 4 | public class StreamConnectFailedException extends Exception { 5 | 6 | private static final long serialVersionUID = 8103571310659595097L; 7 | private final int reason; 8 | 9 | public StreamConnectFailedException(int reason) { 10 | this.reason = reason; 11 | } 12 | 13 | public int getReason() { 14 | return reason; 15 | } 16 | 17 | public boolean isReasonRetryable() { 18 | return isRetryableReason(reason); 19 | } 20 | 21 | /* Copied from edge_reason_is_retriable() since this is not specified */ 22 | private static boolean isRetryableReason(int reasonCode) { 23 | switch(reasonCode) { 24 | case RelayCell.REASON_HIBERNATING: 25 | case RelayCell.REASON_RESOURCELIMIT: 26 | case RelayCell.REASON_RESOLVEFAILED: 27 | case RelayCell.REASON_EXITPOLICY: 28 | case RelayCell.REASON_MISC: 29 | case RelayCell.REASON_NOROUTE: 30 | return true; 31 | default: 32 | return false; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/core/ScriptException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.core; 18 | 19 | @SuppressWarnings("serial") 20 | public class ScriptException extends VerificationException { 21 | 22 | public ScriptException(String msg) { 23 | super(msg); 24 | } 25 | 26 | public ScriptException(String msg, Exception e) { 27 | super(msg, e); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/protocols/channels/ValueOutOfRangeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.protocols.channels; 18 | 19 | /** 20 | * Used when a given value is either too large too afford or too small for the network to accept. 21 | */ 22 | public class ValueOutOfRangeException extends Exception { 23 | public ValueOutOfRangeException(String message) { 24 | super(message); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/core/AddressFormatException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Google Inc. 3 | * Copyright 2015 Andreas Schildbach 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.bitcoinj.core; 19 | 20 | @SuppressWarnings("serial") 21 | public class AddressFormatException extends IllegalArgumentException { 22 | public AddressFormatException() { 23 | super(); 24 | } 25 | 26 | public AddressFormatException(String message) { 27 | super(message); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/directory/consensus/DirectorySignature.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.directory.consensus; 2 | 3 | import com.subgraph.orchid.crypto.TorSignature; 4 | import com.subgraph.orchid.data.HexDigest; 5 | 6 | public class DirectorySignature { 7 | 8 | private final HexDigest identityDigest; 9 | private final HexDigest signingKeyDigest; 10 | private final TorSignature signature; 11 | private final boolean useSha256; 12 | 13 | DirectorySignature(HexDigest identityDigest, HexDigest signingKeyDigest, TorSignature signature, boolean useSha256) { 14 | this.identityDigest = identityDigest; 15 | this.signingKeyDigest = signingKeyDigest; 16 | this.signature = signature; 17 | this.useSha256 = useSha256; 18 | } 19 | 20 | public HexDigest getIdentityDigest() { 21 | return identityDigest; 22 | } 23 | 24 | public HexDigest getSigningKeyDigest() { 25 | return signingKeyDigest; 26 | } 27 | 28 | public TorSignature getSignature() { 29 | return signature; 30 | } 31 | 32 | public boolean useSha256() { 33 | return useSha256; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/store/WindowsMMapHack.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.store; 2 | 3 | import sun.misc.*; 4 | import sun.nio.ch.*; 5 | 6 | import java.nio.*; 7 | 8 | /** 9 | *

This class knows how to force an mmap'd ByteBuffer to reliquish its file handles before it becomes garbage collected, 10 | * by exploiting implementation details of the HotSpot JVM implementation.

11 | * 12 | *

This is required on Windows because otherwise an attempt to delete a file that is still mmapped will fail. This can 13 | * happen when a user requests a "restore from seed" function, which involves deleting and recreating the chain file. 14 | * At some point we should stop using mmap in SPVBlockStore and we can then delete this class.

15 | * 16 | *

It is a separate class to avoid hitting unknown imports when running on other JVMs.

17 | */ 18 | public class WindowsMMapHack { 19 | public static void forceRelease(MappedByteBuffer buffer) { 20 | Cleaner cleaner = ((DirectBuffer) buffer).cleaner(); 21 | if (cleaner != null) cleaner.clean(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/core/TransactionBroadcaster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.core; 18 | 19 | /** 20 | * A general interface which declares the ability to broadcast transactions. This is implemented 21 | * by {@link org.bitcoinj.core.PeerGroup}. 22 | */ 23 | public interface TransactionBroadcaster { 24 | /** Broadcast the given transaction on the network */ 25 | TransactionBroadcast broadcastTransaction(final Transaction tx); 26 | } 27 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/store/BlockStoreException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.store; 18 | 19 | /** 20 | * Thrown when something goes wrong with storing a block. Examples: out of disk space. 21 | */ 22 | public class BlockStoreException extends Exception { 23 | public BlockStoreException(String message) { 24 | super(message); 25 | } 26 | 27 | public BlockStoreException(Throwable t) { 28 | super(t); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /examples/src/main/javascript/payprotocol.js: -------------------------------------------------------------------------------- 1 | // Example app that creates a minimal BIP70 payment request with a multisig output, and then prints it to base64. 2 | 3 | var bcj = org.bitcoinj; 4 | var protos = org.bitcoin.protocols.payments.Protos; 5 | var pbuf = com.google.protobuf; 6 | 7 | var details = protos.PaymentDetails.newBuilder(); 8 | details.time = new Date().value; 9 | var output = protos.Output.newBuilder(); 10 | 11 | var scriptBytes = bcj.script.ScriptBuilder.createMultiSigOutputScript(2, [new bcj.core.ECKey(), new bcj.core.ECKey()]).program; 12 | // ... or to a regular address output: 13 | // var scriptBytes = bcj.script.ScriptBuilder.createOutputScript(new bcj.core.ECKey().toAddress(bcj.params.MainNetParams.get())).program; 14 | 15 | output.script = pbuf.ByteString.copyFrom(scriptBytes); 16 | details.addOutputs(output); 17 | 18 | var request = protos.PaymentRequest.newBuilder(); 19 | request.serializedPaymentDetails = details.build().toByteString(); 20 | 21 | var bits = request.build().toByteArray(); 22 | var b64 = java.util.Base64.getEncoder().encodeToString(bits); 23 | print(b64); 24 | 25 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/core/VersionAck.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2011 Noa Resare. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.core; 18 | 19 | /** 20 | * The verack message, sent by a client accepting the version message they 21 | * received from their peer. 22 | */ 23 | public class VersionAck extends EmptyMessage { 24 | public VersionAck() { 25 | } 26 | 27 | // this is needed by the BitcoinSerializer 28 | public VersionAck(NetworkParameters params, byte[] payload) { 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/signers/StatelessTransactionSigner.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Kosta Korenkov 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.bitcoinj.signers; 17 | 18 | /** 19 | * A signer that doesn't have any state to be serialized. 20 | */ 21 | public abstract class StatelessTransactionSigner implements TransactionSigner { 22 | @Override 23 | public void deserialize(byte[] data) { 24 | } 25 | 26 | @Override 27 | public byte[] serialize() { 28 | return new byte[0]; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/store/UnreadableWalletException.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.store; 2 | 3 | /** 4 | * Thrown by the {@link WalletProtobufSerializer} when the serialized protocol buffer is either corrupted, 5 | * internally inconsistent or appears to be from the future. 6 | */ 7 | public class UnreadableWalletException extends Exception { 8 | public UnreadableWalletException(String s) { 9 | super(s); 10 | } 11 | 12 | public UnreadableWalletException(String s, Throwable t) { 13 | super(s, t); 14 | } 15 | 16 | public static class BadPassword extends UnreadableWalletException { 17 | public BadPassword() { 18 | super("Password incorrect"); 19 | } 20 | } 21 | 22 | public static class FutureVersion extends UnreadableWalletException { 23 | public FutureVersion() { super("Unknown wallet version from the future."); } 24 | } 25 | 26 | public static class WrongNetwork extends UnreadableWalletException { 27 | public WrongNetwork() { 28 | super("Mismatched network ID"); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/circuits/hs/IntroductionPointKeyword.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.circuits.hs; 2 | 3 | public enum IntroductionPointKeyword { 4 | SERVICE_AUTHENTICATION("service-authentication", 2), 5 | INTRODUCTION_POINT("introduction-point", 1), 6 | IP_ADDRESS("ip-address", 1), 7 | ONION_PORT("onion-port", 1), 8 | ONION_KEY("onion-key", 0), 9 | SERVICE_KEY("service-key", 0), 10 | INTRO_AUTHENTICATION("intro-authentication", 2), 11 | UNKNOWN_KEYWORD("KEYWORD NOT FOUND", 0); 12 | 13 | private final String keyword; 14 | private final int argumentCount; 15 | 16 | IntroductionPointKeyword(String keyword, int argumentCount) { 17 | this.keyword = keyword; 18 | this.argumentCount = argumentCount; 19 | } 20 | 21 | String getKeyword() { 22 | return keyword; 23 | } 24 | 25 | int getArgumentCount() { 26 | return argumentCount; 27 | } 28 | 29 | static IntroductionPointKeyword findKeyword(String keyword) { 30 | for(IntroductionPointKeyword k: values()) { 31 | if(k.getKeyword().equals(keyword)) { 32 | return k; 33 | } 34 | } 35 | return UNKNOWN_KEYWORD; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/core/GetAddrMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.core; 18 | 19 | /** 20 | * Represents the "getaddr" P2P protocol message, which requests network {@link AddressMessage}s from a peer. Not to 21 | * be confused with {@link Address} which is sort of like an account number. 22 | */ 23 | public class GetAddrMessage extends EmptyMessage { 24 | 25 | public GetAddrMessage(NetworkParameters params) { 26 | super(params); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/jni/NativePaymentChannelServerConnectionEventHandler.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.jni; 2 | 3 | import org.bitcoinj.core.*; 4 | import org.bitcoinj.protocols.channels.PaymentChannelCloseException; 5 | import org.bitcoinj.protocols.channels.ServerConnectionEventHandler; 6 | import com.google.common.util.concurrent.ListenableFuture; 7 | import com.google.protobuf.ByteString; 8 | 9 | /** 10 | * An event listener that relays events to a native C++ object. A pointer to that object is stored in 11 | * this class using JNI on the native side, thus several instances of this can point to different actual 12 | * native implementations. 13 | */ 14 | public class NativePaymentChannelServerConnectionEventHandler extends ServerConnectionEventHandler { 15 | public long ptr; 16 | 17 | @Override 18 | public native void channelOpen(Sha256Hash channelId); 19 | 20 | @Override 21 | public native ListenableFuture paymentIncrease(Coin by, Coin to, ByteString info); 22 | 23 | @Override 24 | public native void channelClosed(PaymentChannelCloseException.CloseReason reason); 25 | } 26 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/core/ProtocolException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.core; 18 | 19 | @SuppressWarnings("serial") 20 | public class ProtocolException extends VerificationException { 21 | 22 | public ProtocolException(String msg) { 23 | super(msg); 24 | } 25 | 26 | public ProtocolException(Exception e) { 27 | super(e); 28 | } 29 | 30 | public ProtocolException(String msg, Exception e) { 31 | super(msg, e); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/testing/FooWalletExtension.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.testing; 2 | 3 | import org.bitcoinj.core.Wallet; 4 | import org.bitcoinj.core.WalletExtension; 5 | 6 | import java.util.Arrays; 7 | 8 | import static com.google.common.base.Preconditions.checkArgument; 9 | 10 | public class FooWalletExtension implements WalletExtension { 11 | private final byte[] data = {1, 2, 3}; 12 | 13 | private final boolean isMandatory; 14 | private final String id; 15 | 16 | public FooWalletExtension(String id, boolean isMandatory) { 17 | this.isMandatory = isMandatory; 18 | this.id = id; 19 | } 20 | 21 | @Override 22 | public String getWalletExtensionID() { 23 | return id; 24 | } 25 | 26 | @Override 27 | public boolean isWalletExtensionMandatory() { 28 | return isMandatory; 29 | } 30 | 31 | @Override 32 | public byte[] serializeWalletExtension() { 33 | return data; 34 | } 35 | 36 | @Override 37 | public void deserializeWalletExtension(Wallet wallet, byte[] data) { 38 | checkArgument(Arrays.equals(this.data, data)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/directory/router/RouterMicrodescriptorKeyword.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.directory.router; 2 | 3 | public enum RouterMicrodescriptorKeyword { 4 | ONION_KEY("onion-key", 0), 5 | NTOR_ONION_KEY("ntor-onion-key", 1), 6 | A("a", 1), 7 | FAMILY("family"), 8 | P("p", 2), 9 | UNKNOWN_KEYWORD("KEYWORD NOT FOUNE"); 10 | 11 | public final static int VARIABLE_ARGUMENT_COUNT = -1; 12 | 13 | private final String keyword; 14 | private final int argumentCount; 15 | 16 | RouterMicrodescriptorKeyword(String keyword) { 17 | this(keyword, VARIABLE_ARGUMENT_COUNT); 18 | } 19 | 20 | RouterMicrodescriptorKeyword(String keyword, int argumentCount) { 21 | this.keyword = keyword; 22 | this.argumentCount = argumentCount; 23 | } 24 | 25 | String getKeyword() { 26 | return keyword; 27 | } 28 | 29 | int getArgumentCount() { 30 | return argumentCount; 31 | } 32 | 33 | static RouterMicrodescriptorKeyword findKeyword(String keyword) { 34 | for(RouterMicrodescriptorKeyword k: values()) { 35 | if(k.getKeyword().equals(keyword)) { 36 | return k; 37 | } 38 | } 39 | return UNKNOWN_KEYWORD; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/core/listeners/AbstractBlockChainListener.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.core.listeners; 2 | 3 | import org.bitcoinj.core.*; 4 | 5 | import java.util.*; 6 | 7 | /** 8 | * For backwards compatibility only. Implements the block chain listener interfaces. Use the more specific interfaces 9 | * instead. 10 | */ 11 | @Deprecated 12 | public class AbstractBlockChainListener implements BlockChainListener { 13 | @Override 14 | public void notifyNewBestBlock(StoredBlock block) throws VerificationException { 15 | } 16 | 17 | @Override 18 | public void reorganize(StoredBlock splitPoint, List oldBlocks, List newBlocks) throws VerificationException { 19 | } 20 | 21 | @Override 22 | public void receiveFromBlock(Transaction tx, StoredBlock block, BlockChain.NewBlockType blockType, int relativityOffset) throws VerificationException { 23 | } 24 | 25 | @Override 26 | public boolean notifyTransactionIsInBlock(Sha256Hash txHash, StoredBlock block, BlockChain.NewBlockType blockType, int relativityOffset) throws VerificationException { 27 | return false; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/circuits/hs/HSDescriptorKeyword.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.circuits.hs; 2 | 3 | public enum HSDescriptorKeyword { 4 | RENDEZVOUS_SERVICE_DESCRIPTOR("rendezvous-service-descriptor", 1), 5 | VERSION("version", 1), 6 | PERMANENT_KEY("permanent-key", 0), 7 | SECRET_ID_PART("secret-id-part", 1), 8 | PUBLICATION_TIME("publication-time", 2), 9 | PROTOCOL_VERSIONS("protocol-versions", 2), 10 | INTRODUCTION_POINTS("introduction-points", 0), 11 | SIGNATURE("signature", 0), 12 | UNKNOWN_KEYWORD("KEYWORD NOT FOUND", 0); 13 | 14 | private final String keyword; 15 | private final int argumentCount; 16 | 17 | HSDescriptorKeyword(String keyword, int argumentCount) { 18 | this.keyword = keyword; 19 | this.argumentCount = argumentCount; 20 | } 21 | 22 | String getKeyword() { 23 | return keyword; 24 | } 25 | 26 | int getArgumentCount() { 27 | return argumentCount; 28 | } 29 | 30 | static HSDescriptorKeyword findKeyword(String keyword) { 31 | for(HSDescriptorKeyword k: values()) { 32 | if(k.getKeyword().equals(keyword)) { 33 | return k; 34 | } 35 | } 36 | return UNKNOWN_KEYWORD; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/directory/parsing/DocumentObject.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.directory.parsing; 2 | 3 | public class DocumentObject { 4 | 5 | final private String keyword; 6 | final private String headerLine; 7 | private String footerLine; 8 | private String bodyContent; 9 | final private StringBuilder stringContent; 10 | 11 | public DocumentObject(String keyword, String headerLine) { 12 | this.keyword = keyword; 13 | this.headerLine = headerLine; 14 | this.stringContent = new StringBuilder(); 15 | } 16 | 17 | public String getKeyword() { 18 | return keyword; 19 | } 20 | 21 | public void addContent(String content) { 22 | stringContent.append(content); 23 | stringContent.append("\n"); 24 | } 25 | 26 | public void addFooterLine(String footer) { 27 | footerLine = footer; 28 | bodyContent = stringContent.toString(); 29 | } 30 | 31 | public String getContent() { 32 | return getContent(true); 33 | } 34 | 35 | public String getContent(boolean includeHeaders) { 36 | if(includeHeaders) { 37 | return headerLine + "\n" + bodyContent + footerLine + "\n"; 38 | } else { 39 | return bodyContent; 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /orchid/opt/xmlrpc/com/subgraph/orchid/xmlrpc/OrchidXmlRpcTransportFactory.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.xmlrpc; 2 | 3 | import javax.net.SocketFactory; 4 | import javax.net.ssl.SSLContext; 5 | 6 | import org.apache.xmlrpc.client.XmlRpcClient; 7 | import org.apache.xmlrpc.client.XmlRpcTransport; 8 | import org.apache.xmlrpc.client.XmlRpcTransportFactory; 9 | import com.subgraph.orchid.TorClient; 10 | import com.subgraph.orchid.sockets.OrchidSocketFactory; 11 | 12 | public class OrchidXmlRpcTransportFactory implements XmlRpcTransportFactory { 13 | private final XmlRpcClient client; 14 | private final SSLContext sslContext; 15 | private final SocketFactory socketFactory; 16 | 17 | public OrchidXmlRpcTransportFactory(XmlRpcClient client, TorClient torClient) { 18 | this(client, torClient, null); 19 | } 20 | 21 | public OrchidXmlRpcTransportFactory(XmlRpcClient client, TorClient torClient, SSLContext sslContext) { 22 | this.client = client; 23 | this.socketFactory = new OrchidSocketFactory(torClient); 24 | this.sslContext = sslContext; 25 | } 26 | 27 | public XmlRpcTransport getTransport() { 28 | return new OrchidXmlRpcTransport(client, socketFactory, sslContext); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/misc/NotThreadSafe.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.misc; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /* 10 | * Copyright (c) 2005 Brian Goetz and Tim Peierls 11 | * Released under the Creative Commons Attribution License 12 | * (http://creativecommons.org/licenses/by/2.5) 13 | * Official home: http://www.jcip.net 14 | * 15 | * Any republication or derived work distributed in source code form 16 | * must include this copyright and license notice. 17 | */ 18 | 19 | 20 | /** 21 | * The class to which this annotation is applied is not thread-safe. 22 | * This annotation primarily exists for clarifying the non-thread-safety of a class 23 | * that might otherwise be assumed to be thread-safe, despite the fact that it is a bad 24 | * idea to assume a class is thread-safe without good reason. 25 | * @see ThreadSafe 26 | */ 27 | @Documented 28 | @Target(ElementType.TYPE) 29 | @Retention(RetentionPolicy.RUNTIME) 30 | public @interface NotThreadSafe { 31 | } 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/core/PeerException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.core; 18 | 19 | /** 20 | * Thrown when a problem occurs in communicating with a peer, and we should 21 | * retry. 22 | */ 23 | @SuppressWarnings("serial") 24 | public class PeerException extends Exception { 25 | public PeerException(String msg) { 26 | super(msg); 27 | } 28 | 29 | public PeerException(Exception e) { 30 | super(e); 31 | } 32 | 33 | public PeerException(String msg, Exception e) { 34 | super(msg, e); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/DirectoryStore.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid; 2 | 3 | import java.nio.ByteBuffer; 4 | import java.util.List; 5 | 6 | public interface DirectoryStore { 7 | enum CacheFile { 8 | CERTIFICATES("certificates"), 9 | CONSENSUS("consensus"), 10 | CONSENSUS_MICRODESC("consensus-microdesc"), 11 | MICRODESCRIPTOR_CACHE("cached-microdescs"), 12 | MICRODESCRIPTOR_JOURNAL("cached-microdescs.new"), 13 | DESCRIPTOR_CACHE("cached-descriptors"), 14 | DESCRIPTOR_JOURNAL("cached-descriptors.new"), 15 | STATE("state"); 16 | 17 | final private String filename; 18 | 19 | CacheFile(String filename) { 20 | this.filename = filename; 21 | } 22 | 23 | public String getFilename() { 24 | return filename; 25 | } 26 | } 27 | 28 | ByteBuffer loadCacheFile(CacheFile cacheFile); 29 | void writeData(CacheFile cacheFile, ByteBuffer data); 30 | void writeDocument(CacheFile cacheFile, Document document); 31 | void writeDocumentList(CacheFile cacheFile, List documents); 32 | void appendDocumentList(CacheFile cacheFile, List documents); 33 | 34 | void removeCacheFile(CacheFile cacheFile); 35 | void removeAllCacheFiles(); 36 | } 37 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/core/UTXOProviderException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Kalpesh Parmar. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.bitcoinj.core; 17 | 18 | public class UTXOProviderException extends Exception { 19 | public UTXOProviderException() { 20 | super(); 21 | } 22 | 23 | public UTXOProviderException(String message) { 24 | super(message); 25 | } 26 | 27 | public UTXOProviderException(String message, Throwable cause) { 28 | super(message, cause); 29 | } 30 | 31 | public UTXOProviderException(Throwable cause) { 32 | super(cause); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/ConnectionCache.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid; 2 | 3 | 4 | public interface ConnectionCache { 5 | /** 6 | * Returns a completed connection to the specified router. If an open connection 7 | * to the requested router already exists it is returned, otherwise a new connection 8 | * is opened. 9 | * 10 | * @param router The router to which a connection is requested. 11 | * @param isDirectoryConnection Is this going to be used as a directory connection. 12 | * @return a completed connection to the specified router. 13 | * @throws InterruptedException if thread is interrupted while waiting for connection to complete. 14 | * @throws ConnectionTimeoutException if timeout expires before connection completes. 15 | * @throws ConnectionFailedException if connection fails due to I/O error 16 | * @throws ConnectionHandshakeException if connection fails because an error occurred during handshake phase 17 | */ 18 | Connection getConnectionTo(Router router, boolean isDirectoryConnection) throws InterruptedException, ConnectionTimeoutException, ConnectionFailedException, ConnectionHandshakeException; 19 | 20 | void close(); 21 | 22 | boolean isClosed(); 23 | } 24 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | $ git log --format='%aN' | sort -u 2 | 3 | Aaron Voisine 4 | Adam Mackler 5 | Alexander Lolis 6 | Alex Taylor 7 | Alon Muroch 8 | Amichai Rothman 9 | Andreas Schildbach 10 | Bennett Hoffman 11 | Carlos Lopez-Camey 12 | Carsten Otto 13 | cyberzac 14 | Dave Collins 15 | Diego Basch 16 | elbandi 17 | eleetas 18 | En-Ran Zhou 19 | Erik Tierney 20 | Fireduck 21 | freak 22 | Gary Rowe 23 | Giannis Dzegoutanis 24 | gubatron 25 | Harald Hoyer 26 | Jakob Stuber 27 | Jameson Lopp 28 | Jarl Fransson 29 | Jim Burton 30 | Jiri Peinlich 31 | Johnathan 32 | Jonny Heggheim 33 | Justas 34 | Kalpesh Parmar 35 | Ken Sedgwick 36 | Kevin Greene 37 | Kosta Korenkov 38 | Loco 39 | Manfred Karrer 40 | Martin Zachrison 41 | matija.mazi@gmail.com 42 | Matt Corallo 43 | Michael Bell 44 | Michael Bumann 45 | Mike Hearn 46 | Mike Rosseel 47 | Miron Cuperman 48 | monk 49 | Mora Zyx 50 | ollekullberg 51 | Oscar Guindzberg 52 | Pavol Rusnak 53 | Peter Dettman 54 | Peter Stockli 55 | Peter Todd 56 | Piotr Włodarek 57 | Richard Green 58 | Ross Nicoll 59 | Sean Gilligan 60 | Sebastian Ortega 61 | Simon de la Rouviere 62 | Simon Vermeersch 63 | Stephen Reed 64 | troggy 65 | Tyler Houlihan 66 | Wojciech Langiewicz 67 | Xiaofeng Guo 68 | Ximo Guanter 69 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/wallet/KeyChainEventListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.bitcoinj.wallet; 17 | 18 | import org.bitcoinj.core.ECKey; 19 | 20 | import java.util.List; 21 | 22 | public interface KeyChainEventListener { 23 | /** 24 | * Called whenever a new key is added to the key chain, whether that be via an explicit addition or due to some 25 | * other automatic derivation. See the documentation for your {@link KeyChain} implementation for details on what 26 | * can trigger this event. 27 | */ 28 | void onKeysAdded(List keys); 29 | } 30 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/misc/ThreadSafe.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.misc; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /* 10 | * Copyright (c) 2005 Brian Goetz and Tim Peierls 11 | * Released under the Creative Commons Attribution License 12 | * (http://creativecommons.org/licenses/by/2.5) 13 | * Official home: http://www.jcip.net 14 | * 15 | * Any republication or derived work distributed in source code form 16 | * must include this copyright and license notice. 17 | */ 18 | 19 | 20 | 21 | /** 22 | * The class to which this annotation is applied is thread-safe. This means that 23 | * no sequences of accesses (reads and writes to public fields, calls to public methods) 24 | * may put the object into an invalid state, regardless of the interleaving of those actions 25 | * by the runtime, and without requiring any additional synchronization or coordination on the 26 | * part of the caller. 27 | */ 28 | @Documented 29 | @Target(ElementType.TYPE) 30 | @Retention(RetentionPolicy.RUNTIME) 31 | public @interface ThreadSafe { 32 | } 33 | 34 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/core/UnknownMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Google Inc. 3 | * Copyright 2014 Andreas Schildbach 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.bitcoinj.core; 19 | 20 | public class UnknownMessage extends EmptyMessage { 21 | 22 | private String name; 23 | 24 | public UnknownMessage(NetworkParameters params, String name, byte[] payloadBytes) throws ProtocolException { 25 | super(params, payloadBytes, 0); 26 | this.name = name; 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | return "Unknown message [" + name + "]: " + (payload == null ? "" : Utils.HEX.encode(payload)); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /orchid/test/com/subgraph/orchid/geoip/CountryCodeServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.geoip; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.io.IOException; 6 | 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | 10 | import com.subgraph.orchid.data.IPv4Address; 11 | import com.subgraph.orchid.geoip.CountryCodeService; 12 | 13 | public class CountryCodeServiceTest { 14 | 15 | private CountryCodeService ccs; 16 | 17 | @Before 18 | public void before() { 19 | ccs = CountryCodeService.getInstance(); 20 | } 21 | 22 | @Test 23 | public void test() throws IOException { 24 | testAddress("FR", "217.70.184.1"); // www.gandi.net 25 | testAddress("DE", "213.165.65.50"); // www.gmx.de 26 | testAddress("AR", "200.42.136.212"); // www.clarin.com 27 | testAddress("GB", "77.91.248.30"); // www.guardian.co.uk 28 | testAddress("CA", "132.216.177.160"); // www.mcgill.ca 29 | testAddress("US", "38.229.72.14"); // www.torproject.net 30 | } 31 | 32 | private void testAddress(String expectedCC, String address) { 33 | IPv4Address a = IPv4Address.createFromString(address); 34 | String cc = ccs.getCountryCodeForAddress(a); 35 | assertEquals("Country Code lookup for "+ address, expectedCC, cc); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/net/StreamConnectionFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.net; 18 | 19 | import java.net.InetAddress; 20 | import javax.annotation.Nullable; 21 | 22 | /** 23 | * A factory which generates new {@link StreamConnection}s when a new connection is opened. 24 | */ 25 | public interface StreamConnectionFactory { 26 | /** 27 | * Returns a new handler or null to have the connection close. 28 | * @param inetAddress The client's (IP) address 29 | * @param port The remote port on the client side 30 | */ 31 | @Nullable 32 | StreamConnection getNewConnection(InetAddress inetAddress, int port); 33 | } 34 | -------------------------------------------------------------------------------- /core/src/test/java/org/bitcoinj/core/H2FullPrunedBlockChainTest.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.core; 2 | 3 | import org.bitcoinj.store.BlockStoreException; 4 | import org.bitcoinj.store.FullPrunedBlockStore; 5 | import org.bitcoinj.store.H2FullPrunedBlockStore; 6 | import org.junit.After; 7 | 8 | import java.io.File; 9 | 10 | /** 11 | * An H2 implementation of the FullPrunedBlockStoreTest 12 | */ 13 | public class H2FullPrunedBlockChainTest extends AbstractFullPrunedBlockChainTest { 14 | @After 15 | public void tearDown() throws Exception { 16 | deleteFiles(); 17 | } 18 | 19 | @Override 20 | public FullPrunedBlockStore createStore(NetworkParameters params, int blockCount) throws BlockStoreException { 21 | deleteFiles(); 22 | return new H2FullPrunedBlockStore(params, "test", blockCount); 23 | } 24 | 25 | private void deleteFiles() { 26 | maybeDelete("test.h2.db"); 27 | maybeDelete("test.trace.db"); 28 | maybeDelete("test.lock.db"); 29 | } 30 | 31 | private void maybeDelete(String s) { 32 | new File(s).delete(); 33 | } 34 | 35 | @Override 36 | public void resetStore(FullPrunedBlockStore store) throws BlockStoreException { 37 | ((H2FullPrunedBlockStore)store).resetStore(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/sockets/sslengine/SSLEngineOutputStream.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.sockets.sslengine; 2 | 3 | import java.io.IOException; 4 | import java.io.OutputStream; 5 | import java.nio.ByteBuffer; 6 | 7 | public class SSLEngineOutputStream extends OutputStream { 8 | 9 | private final SSLEngineManager manager; 10 | private final ByteBuffer outputBuffer; 11 | 12 | public SSLEngineOutputStream(SSLEngineManager manager) { 13 | this.manager = manager; 14 | this.outputBuffer = manager.getSendBuffer(); 15 | } 16 | 17 | @Override 18 | public void write(int b) throws IOException { 19 | outputBuffer.put((byte) b); 20 | manager.write(); 21 | } 22 | 23 | @Override 24 | public void write(byte b[], int off, int len) throws IOException { 25 | int written = 0; 26 | 27 | while(written < len) { 28 | int n = doWrite(b, off + written, len - written); 29 | 30 | written += n; 31 | } 32 | } 33 | 34 | @Override 35 | public void close() throws IOException { 36 | manager.close(); 37 | } 38 | 39 | private int doWrite(byte[] b, int off, int len) throws IOException { 40 | int putLength = Math.min(len, outputBuffer.remaining()); 41 | outputBuffer.put(b, off, putLength); 42 | manager.write(); 43 | return putLength; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/net/MessageWriteTarget.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.net; 18 | 19 | import java.io.IOException; 20 | 21 | /** 22 | * A target to which messages can be written/connection can be closed 23 | */ 24 | public interface MessageWriteTarget { 25 | /** 26 | * Writes the given bytes to the remote server. 27 | */ 28 | void writeBytes(byte[] message) throws IOException; 29 | /** 30 | * Closes the connection to the server, triggering the {@link StreamConnection#connectionClosed()} 31 | * event on the network-handling thread where all callbacks occur. 32 | */ 33 | void closeConnection(); 34 | } 35 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/crypto/TorKeyDerivation.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.crypto; 2 | 3 | import java.nio.ByteBuffer; 4 | 5 | public class TorKeyDerivation { 6 | 7 | private final byte[] kdfBuffer; 8 | private int round; 9 | 10 | public TorKeyDerivation(byte[] seed) { 11 | this.kdfBuffer = new byte[seed.length + 1]; 12 | System.arraycopy(seed, 0, kdfBuffer, 0, seed.length); 13 | } 14 | public void deriveKeys(byte[] keyMaterialOut, byte[] verifyHashOut) { 15 | final ByteBuffer keyData = deriveKeys(keyMaterialOut.length + verifyHashOut.length); 16 | keyData.get(verifyHashOut); 17 | keyData.get(keyMaterialOut); 18 | } 19 | 20 | public ByteBuffer deriveKeys(int length) { 21 | final ByteBuffer outputBuffer = ByteBuffer.allocate(length); 22 | round = 0; 23 | while(outputBuffer.hasRemaining()) { 24 | byte[] bs = calculateRoundData(); 25 | int n = Math.min(outputBuffer.remaining(), bs.length); 26 | outputBuffer.put(bs, 0, n); 27 | } 28 | 29 | outputBuffer.flip(); 30 | return outputBuffer; 31 | } 32 | 33 | private byte[] calculateRoundData() { 34 | final TorMessageDigest md = new TorMessageDigest(); 35 | kdfBuffer[kdfBuffer.length - 1] = (byte) round; 36 | round += 1; 37 | md.update(kdfBuffer); 38 | return md.getDigestBytes(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/net/discovery/PeerDiscoveryException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.net.discovery; 18 | 19 | public class PeerDiscoveryException extends Exception { 20 | private static final long serialVersionUID = -2863411151549391392L; 21 | 22 | public PeerDiscoveryException() { 23 | super(); 24 | } 25 | 26 | public PeerDiscoveryException(String message) { 27 | super(message); 28 | } 29 | 30 | public PeerDiscoveryException(Throwable arg0) { 31 | super(arg0); 32 | } 33 | 34 | public PeerDiscoveryException(String message, Throwable arg0) { 35 | super(message, arg0); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /examples/src/main/java/org/bitcoinj/examples/DumpWallet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.examples; 18 | 19 | import org.bitcoinj.core.Wallet; 20 | 21 | import java.io.File; 22 | 23 | /** 24 | * DumpWallet loads a serialized wallet and prints information about what it contains. 25 | */ 26 | public class DumpWallet { 27 | public static void main(String[] args) throws Exception { 28 | if (args.length != 1) { 29 | System.out.println("Usage: java DumpWallet "); 30 | return; 31 | } 32 | 33 | Wallet wallet = Wallet.loadFromFile(new File(args[0])); 34 | System.out.println(wallet.toString()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/directory/certificate/KeyCertificateKeyword.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.directory.certificate; 2 | 3 | public enum KeyCertificateKeyword { 4 | /* 5 | * See dir-spec.txt 6 | * Section 3.1 Key certificates 7 | */ 8 | DIR_KEY_CERTIFICATE_VERSION("dir-key-certificate-version", 1), 9 | DIR_ADDRESS("dir-address", 1), 10 | FINGERPRINT("fingerprint", 1), 11 | DIR_IDENTITY_KEY("dir-identity-key", 0), 12 | DIR_KEY_PUBLISHED("dir-key-published", 2), 13 | DIR_KEY_EXPIRES("dir-key-expires", 2), 14 | DIR_SIGNING_KEY("dir-signing-key", 0), 15 | DIR_KEY_CROSSCERT("dir-key-crosscert", 0), 16 | DIR_KEY_CERTIFICATION("dir-key-certification", 0), 17 | UNKNOWN_KEYWORD("KEYWORD NOT FOUND", 0); 18 | 19 | private final String keyword; 20 | private final int argumentCount; 21 | 22 | KeyCertificateKeyword(String keyword, int argumentCount) { 23 | this.keyword = keyword; 24 | this.argumentCount = argumentCount; 25 | } 26 | 27 | String getKeyword() { 28 | return keyword; 29 | } 30 | 31 | int getArgumentCount() { 32 | return argumentCount; 33 | } 34 | 35 | static KeyCertificateKeyword findKeyword(String keyword) { 36 | for(KeyCertificateKeyword k: values()) 37 | if(k.getKeyword().equals(keyword)) 38 | return k; 39 | return UNKNOWN_KEYWORD; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/jni/NativeFutureCallback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.jni; 18 | 19 | import com.google.common.util.concurrent.FutureCallback; 20 | 21 | /** 22 | * An event listener that relays events to a native C++ object. A pointer to that object is stored in 23 | * this class using JNI on the native side, thus several instances of this can point to different actual 24 | * native implementations. 25 | */ 26 | public class NativeFutureCallback implements FutureCallback { 27 | public long ptr; 28 | 29 | @Override 30 | public native void onSuccess(Object o); 31 | 32 | @Override 33 | public native void onFailure(Throwable throwable); 34 | } 35 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/jni/NativeTransactionConfidenceListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.jni; 18 | 19 | import org.bitcoinj.core.TransactionConfidence; 20 | 21 | /** 22 | * An event listener that relays events to a native C++ object. A pointer to that object is stored in 23 | * this class using JNI on the native side, thus several instances of this can point to different actual 24 | * native implementations. 25 | */ 26 | public class NativeTransactionConfidenceListener implements TransactionConfidence.Listener { 27 | public long ptr; 28 | 29 | @Override 30 | public native void onConfidenceChanged(TransactionConfidence confidence, ChangeReason reason); 31 | } 32 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/Stream.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid; 2 | 3 | import java.io.InputStream; 4 | import java.io.OutputStream; 5 | 6 | public interface Stream { 7 | /** 8 | * Returns the {@link Circuit} this stream belongs to. 9 | * 10 | * @return The {@link Circuit} this stream belongs to. 11 | */ 12 | Circuit getCircuit(); 13 | 14 | /** 15 | * Returns the stream id value of this stream. 16 | * 17 | * @return The stream id value of this stream. 18 | */ 19 | int getStreamId(); 20 | 21 | 22 | CircuitNode getTargetNode(); 23 | 24 | /** 25 | * Close this stream. 26 | */ 27 | void close(); 28 | 29 | /** 30 | * Returns an {@link InputStream} for sending data on this stream. 31 | * 32 | * @return An {@link InputStream} for transferring data on this stream. 33 | */ 34 | InputStream getInputStream(); 35 | 36 | /** 37 | * Returns an {@link OutputStream} for receiving data from this stream. 38 | * 39 | * @return An {@link OutputStream} for receiving data from this stream. 40 | */ 41 | OutputStream getOutputStream(); 42 | 43 | /** 44 | * If the circuit and stream level packaging windows are open for this stream 45 | * this method returns immediately, otherwise it blocks until both windows are 46 | * open or the stream is closed. 47 | */ 48 | void waitForSendWindow(); 49 | } 50 | -------------------------------------------------------------------------------- /wallettemplate/src/main/java/wallettemplate/utils/AlertWindowController.java: -------------------------------------------------------------------------------- 1 | package wallettemplate.utils; 2 | 3 | import javafx.scene.control.Button; 4 | import javafx.scene.control.Label; 5 | import javafx.stage.Stage; 6 | 7 | public class AlertWindowController { 8 | public Label messageLabel; 9 | public Label detailsLabel; 10 | public Button okButton; 11 | public Button cancelButton; 12 | public Button actionButton; 13 | 14 | /** Initialize this alert dialog for information about a crash. */ 15 | public void crashAlert(Stage stage, String crashMessage) { 16 | messageLabel.setText("Unfortunately, we screwed up and the app crashed. Sorry about that!"); 17 | detailsLabel.setText(crashMessage); 18 | 19 | cancelButton.setVisible(false); 20 | actionButton.setVisible(false); 21 | okButton.setOnAction(actionEvent -> stage.close()); 22 | } 23 | 24 | /** Initialize this alert for general information: OK button only, nothing happens on dismissal. */ 25 | public void informational(Stage stage, String message, String details) { 26 | messageLabel.setText(message); 27 | detailsLabel.setText(details); 28 | cancelButton.setVisible(false); 29 | actionButton.setVisible(false); 30 | okButton.setOnAction(actionEvent -> stage.close()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/data/Timestamp.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.data; 2 | 3 | import java.text.ParseException; 4 | import java.text.SimpleDateFormat; 5 | import java.util.Date; 6 | import java.util.TimeZone; 7 | 8 | import com.subgraph.orchid.TorParsingException; 9 | 10 | public class Timestamp { 11 | private final Date date; 12 | 13 | public static Timestamp createFromDateAndTimeString(String dateAndTime) { 14 | final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 15 | format.setTimeZone(TimeZone.getTimeZone("GMT")); 16 | format.setLenient(false); 17 | try { 18 | Timestamp ts = new Timestamp(format.parse(dateAndTime)); 19 | return ts; 20 | } catch (ParseException e) { 21 | throw new TorParsingException("Could not parse timestamp string: "+ dateAndTime); 22 | } 23 | } 24 | 25 | public Timestamp(Date date) { 26 | this.date = date; 27 | } 28 | 29 | public long getTime() { 30 | return date.getTime(); 31 | } 32 | 33 | public Date getDate() { 34 | return new Date(date.getTime()); 35 | } 36 | 37 | public boolean hasPassed() { 38 | final Date now = new Date(); 39 | return date.before(now); 40 | } 41 | 42 | public boolean isBefore(Timestamp ts) { 43 | return date.before(ts.getDate()); 44 | } 45 | 46 | public String toString() { 47 | return date.toString(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/Router.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid; 2 | 3 | import java.util.Set; 4 | 5 | import com.subgraph.orchid.crypto.TorPublicKey; 6 | import com.subgraph.orchid.data.HexDigest; 7 | import com.subgraph.orchid.data.IPv4Address; 8 | 9 | public interface Router { 10 | 11 | String getNickname(); 12 | String getCountryCode(); 13 | IPv4Address getAddress(); 14 | int getOnionPort(); 15 | int getDirectoryPort(); 16 | TorPublicKey getIdentityKey(); 17 | HexDigest getIdentityHash(); 18 | boolean isDescriptorDownloadable(); 19 | 20 | String getVersion(); 21 | Descriptor getCurrentDescriptor(); 22 | HexDigest getDescriptorDigest(); 23 | HexDigest getMicrodescriptorDigest(); 24 | 25 | TorPublicKey getOnionKey(); 26 | byte[] getNTorOnionKey(); 27 | 28 | boolean hasBandwidth(); 29 | int getEstimatedBandwidth(); 30 | int getMeasuredBandwidth(); 31 | 32 | Set getFamilyMembers(); 33 | int getAverageBandwidth(); 34 | int getBurstBandwidth(); 35 | int getObservedBandwidth(); 36 | boolean isHibernating(); 37 | boolean isRunning(); 38 | boolean isValid(); 39 | boolean isBadExit(); 40 | boolean isPossibleGuard(); 41 | boolean isExit(); 42 | boolean isFast(); 43 | boolean isStable(); 44 | boolean isHSDirectory(); 45 | boolean exitPolicyAccepts(IPv4Address address, int port); 46 | boolean exitPolicyAccepts(int port); 47 | } 48 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/ConsensusDocument.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid; 2 | 3 | import java.util.List; 4 | import java.util.Set; 5 | 6 | import com.subgraph.orchid.data.HexDigest; 7 | import com.subgraph.orchid.data.Timestamp; 8 | 9 | public interface ConsensusDocument extends Document { 10 | enum ConsensusFlavor { NS, MICRODESC }; 11 | enum SignatureStatus { STATUS_VERIFIED, STATUS_FAILED, STATUS_NEED_CERTS }; 12 | 13 | interface RequiredCertificate { 14 | int getDownloadFailureCount(); 15 | void incrementDownloadFailureCount(); 16 | HexDigest getAuthorityIdentity(); 17 | HexDigest getSigningKey(); 18 | } 19 | 20 | ConsensusFlavor getFlavor(); 21 | Timestamp getValidAfterTime(); 22 | Timestamp getFreshUntilTime(); 23 | Timestamp getValidUntilTime(); 24 | int getConsensusMethod(); 25 | int getVoteSeconds(); 26 | int getDistSeconds(); 27 | Set getClientVersions(); 28 | Set getServerVersions(); 29 | boolean isLive(); 30 | List getRouterStatusEntries(); 31 | 32 | SignatureStatus verifySignatures(); 33 | Set getRequiredCertificates(); 34 | 35 | HexDigest getSigningHash(); 36 | HexDigest getSigningHash256(); 37 | 38 | int getCircWindowParameter(); 39 | int getWeightScaleParameter(); 40 | 41 | int getBandwidthWeight(String tag); 42 | 43 | boolean getUseNTorHandshake(); 44 | } 45 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/directory/downloader/CertificateFetcher.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.directory.downloader; 2 | 3 | import java.nio.ByteBuffer; 4 | import java.util.Set; 5 | 6 | import com.subgraph.orchid.KeyCertificate; 7 | import com.subgraph.orchid.ConsensusDocument.RequiredCertificate; 8 | import com.subgraph.orchid.directory.parsing.DocumentParser; 9 | 10 | public class CertificateFetcher extends DocumentFetcher{ 11 | 12 | private final Set requiredCertificates; 13 | 14 | public CertificateFetcher(Set requiredCertificates) { 15 | this.requiredCertificates = requiredCertificates; 16 | } 17 | 18 | @Override 19 | String getRequestPath() { 20 | return "/tor/keys/fp-sk/"+ getRequiredCertificatesRequestString(); 21 | } 22 | 23 | private String getRequiredCertificatesRequestString() { 24 | final StringBuilder sb = new StringBuilder(); 25 | for(RequiredCertificate rc: requiredCertificates) { 26 | if(sb.length() > 0) { 27 | sb.append("+"); 28 | } 29 | sb.append(rc.getAuthorityIdentity().toString()); 30 | sb.append("-"); 31 | sb.append(rc.getSigningKey().toString()); 32 | } 33 | return sb.toString(); 34 | } 35 | 36 | @Override 37 | DocumentParser createParser(ByteBuffer response) { 38 | return PARSER_FACTORY.createKeyCertificateParser(response); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/crypto/TorRandom.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.crypto; 2 | 3 | import java.security.NoSuchAlgorithmException; 4 | import java.security.SecureRandom; 5 | 6 | import com.subgraph.orchid.TorException; 7 | 8 | public class TorRandom { 9 | 10 | private final SecureRandom random; 11 | 12 | public TorRandom() { 13 | random = createRandom(); 14 | } 15 | 16 | private static SecureRandom createRandom() { 17 | try { 18 | return SecureRandom.getInstance("SHA1PRNG"); 19 | } catch (NoSuchAlgorithmException e) { 20 | throw new TorException(e); 21 | } 22 | } 23 | 24 | public byte[] getBytes(int n) { 25 | final byte[] bs = new byte[n]; 26 | random.nextBytes(bs); 27 | return bs; 28 | } 29 | 30 | public long nextLong(long n) { 31 | long bits, val; 32 | do { 33 | bits = nextLong(); 34 | val = bits % n; 35 | } while(bits - val + (n - 1) < 0); 36 | return val; 37 | } 38 | 39 | public int nextInt(int n) { 40 | return random.nextInt(n); 41 | } 42 | 43 | public int nextInt() { 44 | return random.nextInt() & Integer.MAX_VALUE; 45 | } 46 | 47 | /** 48 | * Return a uniformly distributed positive random value between 0 and Long.MAX_VALUE 49 | * 50 | * @return A positive random value between 0 and Long.MAX_VALUE. 51 | */ 52 | public long nextLong() { 53 | return random.nextLong() & Long.MAX_VALUE; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/core/Monetary.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Andreas Schildbach 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.core; 18 | 19 | import java.io.Serializable; 20 | 21 | /** 22 | * Classes implementing this interface represent a monetary value, such as a Bitcoin or fiat amount. 23 | */ 24 | public interface Monetary extends Serializable { 25 | 26 | /** 27 | * Returns the absolute value of exponent of the value of a "smallest unit" in scientific notation. For Bitcoin, a 28 | * satoshi is worth 1E-8 so this would be 8. 29 | */ 30 | int smallestUnitExponent(); 31 | 32 | /** 33 | * Returns the number of "smallest units" of this monetary value. For Bitcoin, this would be the number of satoshis. 34 | */ 35 | long getValue(); 36 | 37 | int signum(); 38 | } 39 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/directory/downloader/RouterDescriptorFetcher.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.directory.downloader; 2 | 3 | import java.nio.ByteBuffer; 4 | import java.util.ArrayList; 5 | import java.util.Collection; 6 | import java.util.List; 7 | 8 | import com.subgraph.orchid.RouterDescriptor; 9 | import com.subgraph.orchid.data.HexDigest; 10 | import com.subgraph.orchid.directory.parsing.DocumentParser; 11 | 12 | public class RouterDescriptorFetcher extends DocumentFetcher{ 13 | 14 | private final List fingerprints; 15 | 16 | public RouterDescriptorFetcher(Collection fingerprints) { 17 | this.fingerprints = new ArrayList(fingerprints); 18 | } 19 | 20 | @Override 21 | String getRequestPath() { 22 | return "/tor/server/d/"+ fingerprintsToRequestString(); 23 | } 24 | 25 | private String fingerprintsToRequestString() { 26 | final StringBuilder sb = new StringBuilder(); 27 | for(HexDigest fp: fingerprints) { 28 | appendFingerprint(sb, fp); 29 | } 30 | return sb.toString(); 31 | } 32 | private void appendFingerprint(StringBuilder sb, HexDigest fp) { 33 | if(sb.length() > 0) { 34 | sb.append("+"); 35 | } 36 | sb.append(fp.toString()); 37 | } 38 | 39 | @Override 40 | DocumentParser createParser(ByteBuffer response) { 41 | return PARSER_FACTORY.createRouterDescriptorParser(response, true); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /wallettemplate/src/main/resources/wallettemplate/wallet.css: -------------------------------------------------------------------------------- 1 | .mnemonic-area *.text { 2 | -fx-text-alignment: center; 3 | } 4 | 5 | .title-banner { 6 | -fx-background-color: #b3fbc4; 7 | } 8 | 9 | .title-label { 10 | -fx-background-color: darkseagreen; 11 | -fx-text-fill: white; 12 | } 13 | 14 | .root-pane { 15 | -fx-background-color: white; 16 | } 17 | 18 | .info-bar { 19 | -fx-background-color: linear-gradient(to bottom, black, darkslategray); 20 | -fx-padding: 10; 21 | } 22 | .info-bar > Label { 23 | -fx-text-fill: white; 24 | -fx-font-weight: bold; 25 | } 26 | .info-bar > .progress-bar > .bar { 27 | -fx-padding: 8; 28 | } 29 | .info-bar > .progress-bar > .track { 30 | -fx-opacity: 0.0; 31 | } 32 | 33 | 34 | .fat-button { 35 | -fx-padding: 10 15 10 15; 36 | -fx-min-width: 100; 37 | -fx-base: whitesmoke; 38 | } 39 | 40 | .fat-button:default { 41 | -fx-base: orange; 42 | -fx-text-fill: white; 43 | } 44 | 45 | .fat-button:cancel { 46 | -fx-background-color: lightgray, white; 47 | -fx-background-insets: 0, 1; 48 | -fx-background-radius: 3; 49 | -fx-text-fill: black; 50 | } 51 | 52 | .fat-button:cancel:hover { 53 | -fx-base: white; 54 | -fx-background-insets: -1, 0, 1, 2; 55 | -fx-background-color: -fx-shadow-highlight-color, -fx-outer-border, -fx-inner-border, -fx-body-color; 56 | -fx-background-radius: 3; 57 | -fx-text-fill: black; 58 | } 59 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/directory/downloader/MicrodescriptorFetcher.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.directory.downloader; 2 | 3 | import java.nio.ByteBuffer; 4 | import java.util.ArrayList; 5 | import java.util.Collection; 6 | import java.util.List; 7 | 8 | import com.subgraph.orchid.RouterMicrodescriptor; 9 | import com.subgraph.orchid.data.HexDigest; 10 | import com.subgraph.orchid.directory.parsing.DocumentParser; 11 | 12 | public class MicrodescriptorFetcher extends DocumentFetcher{ 13 | 14 | private final List fingerprints; 15 | 16 | public MicrodescriptorFetcher(Collection fingerprints) { 17 | this.fingerprints = new ArrayList(fingerprints); 18 | } 19 | 20 | @Override 21 | String getRequestPath() { 22 | return "/tor/micro/d/"+ fingerprintsToRequestString(); 23 | } 24 | 25 | private String fingerprintsToRequestString() { 26 | final StringBuilder sb = new StringBuilder(); 27 | for(HexDigest fp: fingerprints) { 28 | appendFingerprint(sb, fp); 29 | } 30 | return sb.toString(); 31 | } 32 | 33 | private void appendFingerprint(StringBuilder sb, HexDigest fp) { 34 | if(sb.length() > 0) { 35 | sb.append("-"); 36 | } 37 | sb.append(fp.toBase64(true)); 38 | } 39 | 40 | @Override 41 | DocumentParser createParser(ByteBuffer response) { 42 | return PARSER_FACTORY.createRouterMicrodescriptorParser(response); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/circuits/hs/IntroductionPoint.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.circuits.hs; 2 | 3 | import com.subgraph.orchid.crypto.TorPublicKey; 4 | import com.subgraph.orchid.data.HexDigest; 5 | import com.subgraph.orchid.data.IPv4Address; 6 | 7 | public class IntroductionPoint { 8 | 9 | private HexDigest identity; 10 | private IPv4Address address; 11 | private int onionPort; 12 | private TorPublicKey onionKey; 13 | private TorPublicKey serviceKey; 14 | 15 | IntroductionPoint(HexDigest identity) { 16 | this.identity = identity; 17 | } 18 | 19 | void setAddress(IPv4Address address) { 20 | this.address = address; 21 | } 22 | 23 | void setOnionPort(int onionPort) { 24 | this.onionPort = onionPort; 25 | } 26 | 27 | void setOnionKey(TorPublicKey onionKey) { 28 | this.onionKey = onionKey; 29 | } 30 | 31 | void setServiceKey(TorPublicKey serviceKey) { 32 | this.serviceKey = serviceKey; 33 | } 34 | 35 | boolean isValidDocument() { 36 | return identity != null && address != null && onionPort != 0 && onionKey != null && serviceKey != null; 37 | } 38 | 39 | public HexDigest getIdentity() { 40 | return identity; 41 | } 42 | 43 | public IPv4Address getAddress() { 44 | return address; 45 | } 46 | 47 | public int getPort() { 48 | return onionPort; 49 | } 50 | 51 | public TorPublicKey getOnionKey() { 52 | return onionKey; 53 | } 54 | 55 | public TorPublicKey getServiceKey() { 56 | return serviceKey; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/core/listeners/AbstractPeerConnectionEventListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.core.listeners; 18 | 19 | import org.bitcoinj.core.*; 20 | 21 | import java.util.*; 22 | 23 | /** 24 | * Deprecated: implement the more specific event listener interfaces instead to fill out only what you need 25 | */ 26 | @Deprecated 27 | public abstract class AbstractPeerConnectionEventListener implements PeerConnectionEventListener { 28 | @Override 29 | public void onPeersDiscovered(Set peerAddresses) { 30 | // Do nothing 31 | } 32 | 33 | @Override 34 | public void onPeerConnected(Peer peer, int peerCount) { 35 | // Do nothing 36 | } 37 | 38 | @Override 39 | public void onPeerDisconnected(Peer peer, int peerCount) { 40 | // Do nothing 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/directory/consensus/ConsensusDocumentSectionParser.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.directory.consensus; 2 | 3 | import com.subgraph.orchid.directory.consensus.ConsensusDocumentParser.DocumentSection; 4 | import com.subgraph.orchid.directory.parsing.DocumentFieldParser; 5 | 6 | public abstract class ConsensusDocumentSectionParser { 7 | 8 | protected final ConsensusDocumentImpl document; 9 | protected final DocumentFieldParser fieldParser; 10 | 11 | 12 | ConsensusDocumentSectionParser(DocumentFieldParser parser, ConsensusDocumentImpl document) { 13 | this.fieldParser = parser; 14 | this.document = document; 15 | } 16 | 17 | DocumentSection parseKeywordLine() { 18 | String keywordString = fieldParser.getCurrentKeyword(); 19 | if(getNextStateKeyword() != null && getNextStateKeyword().equals(keywordString)) 20 | return nextSection(); 21 | 22 | final DocumentKeyword keyword = DocumentKeyword.findKeyword(keywordString, getSection()); 23 | /* 24 | * dirspec.txt (1.2) 25 | * When interpreting a Document, software MUST ignore any KeywordLine that 26 | * starts with a keyword it doesn't recognize; 27 | */ 28 | if(!keyword.equals(DocumentKeyword.UNKNOWN_KEYWORD)) 29 | parseLine(keyword); 30 | 31 | return getSection(); 32 | } 33 | 34 | abstract void parseLine(DocumentKeyword keyword); 35 | abstract String getNextStateKeyword(); 36 | abstract DocumentSection getSection(); 37 | abstract DocumentSection nextSection(); 38 | } 39 | -------------------------------------------------------------------------------- /wallettemplate/src/main/java/wallettemplate/utils/TextFieldValidator.java: -------------------------------------------------------------------------------- 1 | package wallettemplate.utils; 2 | 3 | import javafx.beans.property.BooleanProperty; 4 | import javafx.beans.property.SimpleBooleanProperty; 5 | import javafx.scene.Scene; 6 | import javafx.scene.control.TextInputControl; 7 | 8 | import java.util.function.Predicate; 9 | 10 | public class TextFieldValidator { 11 | public final BooleanProperty valid = new SimpleBooleanProperty(false); 12 | 13 | public TextFieldValidator(TextInputControl control, Predicate validator) { 14 | this.valid.set(validator.test(control.getText())); 15 | apply(control, valid.get()); 16 | control.textProperty().addListener((observableValue, prev, current) -> { 17 | boolean nowValid = validator.test(current); 18 | if (nowValid == valid.get()) return; 19 | valid.set(nowValid); 20 | }); 21 | valid.addListener(o -> apply(control, valid.get())); 22 | } 23 | 24 | private static void apply(TextInputControl textField, boolean nowValid) { 25 | if (nowValid) { 26 | textField.getStyleClass().remove("validation_error"); 27 | } else { 28 | textField.getStyleClass().add("validation_error"); 29 | } 30 | } 31 | 32 | public static void configureScene(Scene scene) { 33 | final String file = TextFieldValidator.class.getResource("text-validation.css").toString(); 34 | scene.getStylesheets().add(file); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/uri/BitcoinURIParseException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.uri; 18 | 19 | /** 20 | *

Exception to provide the following to {@link BitcoinURI}:

21 | *
    22 | *
  • Provision of parsing error messages
  • 23 | *
24 | *

This base exception acts as a general failure mode not attributable to a specific cause (other than 25 | * that reported in the exception message). Since this is in English, it may not be worth reporting directly 26 | * to the user other than as part of a "general failure to parse" response.

27 | */ 28 | public class BitcoinURIParseException extends Exception { 29 | public BitcoinURIParseException(String s) { 30 | super(s); 31 | } 32 | 33 | public BitcoinURIParseException(String s, Throwable throwable) { 34 | super(s, throwable); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/data/exitpolicy/ExitPorts.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.data.exitpolicy; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | 7 | /** 8 | * Used by router status entries in consensus documents 9 | */ 10 | public class ExitPorts { 11 | public static ExitPorts createAcceptExitPorts(String ports) { 12 | final ExitPorts exitPorts = new ExitPorts(true); 13 | exitPorts.parsePortRanges(ports); 14 | return exitPorts; 15 | } 16 | 17 | public static ExitPorts createRejectExitPorts(String ports) { 18 | final ExitPorts exitPorts = new ExitPorts(false); 19 | exitPorts.parsePortRanges(ports); 20 | return exitPorts; 21 | } 22 | 23 | private final List ranges = new ArrayList(); 24 | private final boolean areAcceptPorts; 25 | 26 | private ExitPorts(boolean acceptPorts) { 27 | this.areAcceptPorts = acceptPorts; 28 | } 29 | 30 | public boolean areAcceptPorts() { 31 | return areAcceptPorts; 32 | } 33 | 34 | public boolean acceptsPort(int port) { 35 | if(areAcceptPorts) 36 | return contains(port); 37 | else 38 | return !contains(port); 39 | } 40 | public boolean contains(int port) { 41 | for(PortRange r: ranges) 42 | if(r.rangeContains(port)) 43 | return true; 44 | return false; 45 | } 46 | 47 | private void parsePortRanges(String portRanges) { 48 | final String[] args = portRanges.split(","); 49 | for(String arg: args) 50 | ranges.add(PortRange.createFromString(arg)); 51 | } 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/crypto/TorPrivateKey.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.crypto; 2 | 3 | import java.security.KeyPair; 4 | import java.security.KeyPairGenerator; 5 | import java.security.NoSuchAlgorithmException; 6 | import java.security.SecureRandom; 7 | import java.security.interfaces.RSAPrivateKey; 8 | import java.security.interfaces.RSAPublicKey; 9 | 10 | import com.subgraph.orchid.TorException; 11 | 12 | public class TorPrivateKey { 13 | 14 | static public TorPrivateKey generateNewKeypair() { 15 | KeyPairGenerator generator = createGenerator(); 16 | generator.initialize(1024, new SecureRandom()); 17 | KeyPair pair = generator.generateKeyPair(); 18 | return new TorPrivateKey((RSAPrivateKey)pair.getPrivate(), (RSAPublicKey)pair.getPublic()); 19 | } 20 | 21 | static KeyPairGenerator createGenerator() { 22 | try { 23 | return KeyPairGenerator.getInstance("RSA"); 24 | } catch (NoSuchAlgorithmException e) { 25 | throw new TorException(e); 26 | } 27 | } 28 | 29 | private final TorPublicKey publicKey; 30 | private final RSAPrivateKey privateKey; 31 | 32 | TorPrivateKey(RSAPrivateKey privateKey, RSAPublicKey publicKey) { 33 | this.privateKey = privateKey; 34 | this.publicKey = new TorPublicKey(publicKey); 35 | } 36 | 37 | public TorPublicKey getPublicKey() { 38 | return publicKey; 39 | } 40 | 41 | public RSAPublicKey getRSAPublicKey() { 42 | return publicKey.getRSAPublicKey(); 43 | } 44 | 45 | public RSAPrivateKey getRSAPrivateKey() { 46 | return privateKey; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/sockets/sslengine/SSLEngineInputStream.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.sockets.sslengine; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.nio.ByteBuffer; 6 | 7 | public class SSLEngineInputStream extends InputStream { 8 | 9 | private final SSLEngineManager manager; 10 | private final ByteBuffer recvBuffer; 11 | private boolean isEOF; 12 | 13 | SSLEngineInputStream(SSLEngineManager manager) { 14 | this.manager = manager; 15 | this.recvBuffer = manager.getRecvBuffer(); 16 | } 17 | 18 | @Override 19 | public int read() throws IOException { 20 | if(!fillRecvBufferIfEmpty()) { 21 | return -1; 22 | } 23 | final int b = recvBuffer.get() & 0xFF; 24 | recvBuffer.compact(); 25 | return b; 26 | } 27 | 28 | @Override 29 | public int read(byte b[], int off, int len) throws IOException { 30 | if(!fillRecvBufferIfEmpty()) { 31 | return -1; 32 | } 33 | final int copyLen = Math.min(recvBuffer.remaining(), len); 34 | recvBuffer.get(b, off, copyLen); 35 | recvBuffer.compact(); 36 | return copyLen; 37 | } 38 | 39 | @Override 40 | public void close() throws IOException { 41 | manager.close(); 42 | } 43 | 44 | private boolean fillRecvBufferIfEmpty() throws IOException { 45 | if(isEOF) { 46 | return false; 47 | } 48 | if(recvBuffer.position() == 0) { 49 | if(manager.read() < 0) { 50 | isEOF = true; 51 | return false; 52 | } 53 | } 54 | recvBuffer.flip(); 55 | return recvBuffer.hasRemaining(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/core/PrunedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.core; 18 | 19 | // TODO: Rename PrunedException to something like RequiredDataWasPrunedException 20 | 21 | /** 22 | * PrunedException is thrown in cases where a fully verifying node has deleted (pruned) old block data that turned 23 | * out to be necessary for handling a re-org. Normally this should never happen unless you're playing with the testnet 24 | * as the pruning parameters should be set very conservatively, such that an absolutely enormous re-org would be 25 | * required to trigger it. 26 | */ 27 | @SuppressWarnings("serial") 28 | public class PrunedException extends Exception { 29 | private Sha256Hash hash; 30 | public PrunedException(Sha256Hash hash) { 31 | super(hash.toString()); 32 | this.hash = hash; 33 | } 34 | public Sha256Hash getHash() { 35 | return hash; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/circuits/DirectoryCircuitImpl.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.circuits; 2 | 3 | import java.util.List; 4 | import java.util.concurrent.TimeoutException; 5 | 6 | import com.subgraph.orchid.DirectoryCircuit; 7 | import com.subgraph.orchid.Router; 8 | import com.subgraph.orchid.Stream; 9 | import com.subgraph.orchid.StreamConnectFailedException; 10 | import com.subgraph.orchid.circuits.path.CircuitPathChooser; 11 | import com.subgraph.orchid.circuits.path.PathSelectionFailedException; 12 | 13 | public class DirectoryCircuitImpl extends CircuitImpl implements DirectoryCircuit { 14 | 15 | protected DirectoryCircuitImpl(CircuitManagerImpl circuitManager, List prechosenPath) { 16 | super(circuitManager, prechosenPath); 17 | } 18 | 19 | public Stream openDirectoryStream(long timeout, boolean autoclose) throws InterruptedException, TimeoutException, StreamConnectFailedException { 20 | final StreamImpl stream = createNewStream(autoclose); 21 | try { 22 | stream.openDirectory(timeout); 23 | return stream; 24 | } catch (Exception e) { 25 | removeStream(stream); 26 | return processStreamOpenException(e); 27 | } 28 | } 29 | 30 | @Override 31 | protected List choosePathForCircuit(CircuitPathChooser pathChooser) throws InterruptedException, PathSelectionFailedException { 32 | if(prechosenPath != null) { 33 | return prechosenPath; 34 | } 35 | return pathChooser.chooseDirectoryPath(); 36 | } 37 | 38 | @Override 39 | protected String getCircuitTypeLabel() { 40 | return "Directory"; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /orchid/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009-2011, Bruce Leidl 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the author nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | 26 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/data/exitpolicy/ExitPolicy.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.data.exitpolicy; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import com.subgraph.orchid.data.IPv4Address; 7 | 8 | public class ExitPolicy { 9 | private final List rules = new ArrayList(); 10 | 11 | public void addAcceptRule(String rule) { 12 | rules.add(PolicyRule.createAcceptFromString(rule)); 13 | } 14 | 15 | public void addRejectRule(String rule) { 16 | rules.add(PolicyRule.createRejectFromString(rule)); 17 | } 18 | 19 | public boolean acceptsTarget(ExitTarget target) { 20 | if(target.isAddressTarget()) 21 | return acceptsDestination(target.getAddress(), target.getPort()); 22 | else 23 | return acceptsPort(target.getPort()); 24 | } 25 | 26 | public boolean acceptsDestination(IPv4Address address, int port) { 27 | if(address == null) 28 | return acceptsPort(port); 29 | 30 | for(PolicyRule r: rules) { 31 | if(r.matchesDestination(address, port)) 32 | return r.isAcceptRule(); 33 | } 34 | // Default accept (see dir-spec.txt section 2.1, 'accept'/'reject' keywords) 35 | return true; 36 | } 37 | 38 | public boolean acceptsPort(int port) { 39 | for(PolicyRule r: rules) { 40 | if(r.matchesPort(port)) 41 | return r.isAcceptRule(); 42 | } 43 | return false; 44 | } 45 | 46 | public String toString() { 47 | final StringBuilder sb = new StringBuilder(); 48 | for(PolicyRule r: rules) { 49 | sb.append(r); 50 | sb.append("\n"); 51 | } 52 | return sb.toString(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/core/NotFoundMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.core; 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | /** 23 | * Sent by a peer when a getdata request doesn't find the requested data in the mempool. It has the same format 24 | * as an inventory message and lists the hashes of the missing items. 25 | */ 26 | public class NotFoundMessage extends InventoryMessage { 27 | public static int MIN_PROTOCOL_VERSION = 70001; 28 | 29 | public NotFoundMessage(NetworkParameters params) { 30 | super(params); 31 | } 32 | 33 | public NotFoundMessage(NetworkParameters params, byte[] payloadBytes) throws ProtocolException { 34 | super(params, payloadBytes); 35 | } 36 | 37 | public NotFoundMessage(NetworkParameters params, List items) { 38 | super(params); 39 | this.items = new ArrayList(items); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/circuits/guards/GuardProbeTask.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.circuits.guards; 2 | 3 | import java.util.logging.Level; 4 | import java.util.logging.Logger; 5 | 6 | import com.subgraph.orchid.ConnectionCache; 7 | import com.subgraph.orchid.ConnectionIOException; 8 | import com.subgraph.orchid.GuardEntry; 9 | import com.subgraph.orchid.Router; 10 | 11 | public class GuardProbeTask implements Runnable{ 12 | private final static Logger logger = Logger.getLogger(GuardProbeTask.class.getName()); 13 | private final ConnectionCache connectionCache; 14 | private final EntryGuards entryGuards; 15 | private final GuardEntry entry; 16 | 17 | public GuardProbeTask(ConnectionCache connectionCache, EntryGuards entryGuards, GuardEntry entry) { 18 | this.connectionCache = connectionCache; 19 | this.entryGuards = entryGuards; 20 | this.entry = entry; 21 | } 22 | 23 | public void run() { 24 | final Router router = entry.getRouterForEntry(); 25 | if(router == null) { 26 | entryGuards.probeConnectionFailed(entry); 27 | return; 28 | } 29 | try { 30 | connectionCache.getConnectionTo(router, false); 31 | entryGuards.probeConnectionSucceeded(entry); 32 | return; 33 | } catch (ConnectionIOException e) { 34 | logger.fine("IO exception probing entry guard "+ router + " : "+ e); 35 | } catch (InterruptedException e) { 36 | Thread.currentThread().interrupt(); 37 | } catch(Exception e) { 38 | logger.log(Level.WARNING, "Unexpected exception probing entry guard: "+ e, e); 39 | } 40 | entryGuards.probeConnectionFailed(entry); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/core/MemoryPoolMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Google Inc. 3 | * Copyright 2015 Andreas Schildbach 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.bitcoinj.core; 19 | 20 | import java.io.IOException; 21 | import java.io.OutputStream; 22 | 23 | /** 24 | * The "mempool" message asks a remote peer to announce all transactions in its memory pool, possibly restricted by 25 | * any Bloom filter set on the connection. The list of transaction hashes comes back in an inv message. Note that 26 | * this is different to the {@link TxConfidenceTable} object which doesn't try to keep track of all pending transactions, 27 | * it's just a holding area for transactions that a part of the app may find interesting. The mempool message has 28 | * no fields. 29 | */ 30 | public class MemoryPoolMessage extends Message { 31 | @Override 32 | protected void parse() throws ProtocolException {} 33 | 34 | @Override 35 | void bitcoinSerializeToStream(OutputStream stream) throws IOException {} 36 | } 37 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/data/RandomSet.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.data; 2 | 3 | import java.security.NoSuchAlgorithmException; 4 | import java.security.SecureRandom; 5 | import java.util.ArrayList; 6 | import java.util.HashSet; 7 | import java.util.List; 8 | import java.util.Set; 9 | 10 | import com.subgraph.orchid.TorException; 11 | 12 | public class RandomSet { 13 | 14 | private final Set set; 15 | private final List list; 16 | private final SecureRandom random; 17 | 18 | public RandomSet() { 19 | set = new HashSet(); 20 | list = new ArrayList(); 21 | random = createRandom(); 22 | } 23 | 24 | private static SecureRandom createRandom() { 25 | try { 26 | return SecureRandom.getInstance("SHA1PRNG"); 27 | } catch (NoSuchAlgorithmException e) { 28 | throw new TorException(e); 29 | } 30 | } 31 | 32 | public boolean add(E o) { 33 | if(set.add(o)) { 34 | list.add(o); 35 | return true; 36 | } else { 37 | return false; 38 | } 39 | } 40 | 41 | public boolean contains(Object o) { 42 | return set.contains(o); 43 | } 44 | 45 | public boolean isEmpty() { 46 | return set.isEmpty(); 47 | } 48 | 49 | public void clear() { 50 | set.clear(); 51 | list.clear(); 52 | } 53 | 54 | public boolean remove(Object o) { 55 | if(set.remove(o)) { 56 | list.remove(o); 57 | return true; 58 | } else { 59 | return false; 60 | } 61 | } 62 | 63 | public int size() { 64 | return set.size(); 65 | } 66 | 67 | public E getRandomElement() { 68 | int idx = random.nextInt(list.size()); 69 | return list.get(idx); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/net/discovery/PeerDiscovery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 John Sample. 3 | * Copyright 2015 Andreas Schildbach 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.bitcoinj.net.discovery; 19 | 20 | import java.net.InetSocketAddress; 21 | import java.util.concurrent.TimeUnit; 22 | 23 | /** 24 | * A PeerDiscovery object is responsible for finding addresses of other nodes in the Bitcoin P2P network. Note that 25 | * the addresses returned may or may not be accepting connections. 26 | */ 27 | public interface PeerDiscovery { 28 | // TODO: Flesh out this interface a lot more. 29 | 30 | /** 31 | * Returns an array of addresses. This method may block. 32 | * @param services Required services as a bitmask, e.g. {@link VersionMessage#NODE_NETWORK}. 33 | */ 34 | InetSocketAddress[] getPeers(long services, long timeoutValue, TimeUnit timeoutUnit) throws PeerDiscoveryException; 35 | 36 | /** Stops any discovery in progress when we want to shut down quickly. */ 37 | void shutdown(); 38 | } 39 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/testing/NopTransactionSigner.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Kosta Korenkov 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.bitcoinj.testing; 17 | 18 | import org.bitcoinj.signers.TransactionSigner; 19 | import org.bitcoinj.wallet.KeyBag; 20 | 21 | public class NopTransactionSigner implements TransactionSigner { 22 | private boolean isReady; 23 | 24 | public NopTransactionSigner() { 25 | } 26 | 27 | public NopTransactionSigner(boolean ready) { 28 | this.isReady = ready; 29 | } 30 | 31 | @Override 32 | public boolean isReady() { 33 | return isReady; 34 | } 35 | 36 | @Override 37 | public byte[] serialize() { 38 | return isReady ? new byte[]{1} : new byte[]{0}; 39 | } 40 | 41 | @Override 42 | public void deserialize(byte[] data) { 43 | if (data.length > 0) 44 | isReady = data[0] == 1; 45 | } 46 | 47 | @Override 48 | public boolean signInputs(ProposedTransaction t, KeyBag keyBag) { 49 | return false; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/core/InsufficientMoneyException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.core; 18 | 19 | import javax.annotation.Nullable; 20 | 21 | import static com.google.common.base.Preconditions.checkNotNull; 22 | 23 | /** 24 | * Thrown to indicate that you don't have enough money available to perform the requested operation. 25 | */ 26 | public class InsufficientMoneyException extends Exception { 27 | /** Contains the number of satoshis that would have been required to complete the operation. */ 28 | @Nullable 29 | public final Coin missing; 30 | 31 | protected InsufficientMoneyException() { 32 | this.missing = null; 33 | } 34 | 35 | public InsufficientMoneyException(Coin missing) { 36 | this(missing, "Insufficient money, missing " + missing + " satoshis"); 37 | } 38 | 39 | public InsufficientMoneyException(Coin missing, String message) { 40 | super(message); 41 | this.missing = checkNotNull(missing); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /core/src/storedserverpaymentchannel.proto: -------------------------------------------------------------------------------- 1 | /** Copyright 2013 Google Inc. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | /* 17 | * Authors: Mike Hearn, Matt Corallo 18 | */ 19 | 20 | /* Notes: 21 | * - Endianness: All byte arrays that represent numbers (such as hashes and private keys) are Big Endian 22 | * - To regenerate after editing, run mvn clean package -DupdateProtobuf 23 | */ 24 | 25 | package paymentchannels; 26 | 27 | option java_package = "org.bitcoinj.protocols.channels"; 28 | option java_outer_classname = "ServerState"; 29 | 30 | 31 | // A set of StoredPaymentChannel's 32 | message StoredServerPaymentChannels { 33 | repeated StoredServerPaymentChannel channels = 1; 34 | } 35 | 36 | // A server-side payment channel in serialized form, which can be reloaded later if the server restarts 37 | message StoredServerPaymentChannel { 38 | required uint64 bestValueToMe = 1; 39 | optional bytes bestValueSignature = 2; 40 | required uint64 refundTransactionUnlockTimeSecs = 3; 41 | required bytes contractTransaction = 4; 42 | required bytes clientOutput = 5; 43 | required bytes myKey = 6; 44 | } -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/DirectoryDownloader.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid; 2 | 3 | import java.util.List; 4 | import java.util.Set; 5 | 6 | import com.subgraph.orchid.ConsensusDocument.RequiredCertificate; 7 | import com.subgraph.orchid.data.HexDigest; 8 | import com.subgraph.orchid.directory.downloader.DirectoryRequestFailedException; 9 | 10 | public interface DirectoryDownloader { 11 | void start(Directory directory); 12 | void stop(); 13 | 14 | RouterDescriptor downloadBridgeDescriptor(Router bridge) throws DirectoryRequestFailedException; 15 | 16 | ConsensusDocument downloadCurrentConsensus(boolean useMicrodescriptors) throws DirectoryRequestFailedException; 17 | ConsensusDocument downloadCurrentConsensus(boolean useMicrodescriptors, DirectoryCircuit circuit) throws DirectoryRequestFailedException; 18 | 19 | List downloadKeyCertificates(Set required) throws DirectoryRequestFailedException; 20 | List downloadKeyCertificates(Set required, DirectoryCircuit circuit) throws DirectoryRequestFailedException; 21 | 22 | List downloadRouterDescriptors(Set fingerprints) throws DirectoryRequestFailedException; 23 | List downloadRouterDescriptors(Set fingerprints, DirectoryCircuit circuit) throws DirectoryRequestFailedException; 24 | 25 | List downloadRouterMicrodescriptors(Set fingerprints) throws DirectoryRequestFailedException; 26 | List downloadRouterMicrodescriptors(Set fingerprints, DirectoryCircuit circuit) throws DirectoryRequestFailedException; 27 | } 28 | -------------------------------------------------------------------------------- /wallettemplate/src/main/resources/wallettemplate/controls/bitcoin_address.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 29 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /core/src/test/java/org/bitcoinj/crypto/X509UtilsTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Andreas Schildbach 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.crypto; 18 | 19 | import org.junit.Test; 20 | 21 | import java.security.cert.CertificateFactory; 22 | import java.security.cert.X509Certificate; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | 26 | public class X509UtilsTest { 27 | 28 | @Test 29 | public void testDisplayName() throws Exception { 30 | CertificateFactory cf = CertificateFactory.getInstance("X.509"); 31 | 32 | X509Certificate clientCert = (X509Certificate) cf.generateCertificate(getClass().getResourceAsStream( 33 | "startssl-client.crt")); 34 | assertEquals("Andreas Schildbach", X509Utils.getDisplayNameFromCertificate(clientCert, false)); 35 | 36 | X509Certificate comodoCert = (X509Certificate) cf.generateCertificate(getClass().getResourceAsStream( 37 | "comodo-smime.crt")); 38 | assertEquals("comodo.com@schildbach.de", X509Utils.getDisplayNameFromCertificate(comodoCert, true)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/core/listeners/AbstractPeerDataEventListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.core.listeners; 18 | 19 | import org.bitcoinj.core.*; 20 | 21 | import javax.annotation.*; 22 | import java.util.*; 23 | 24 | /** 25 | * Deprecated: implement the more specific event listener interfaces instead to fill out only what you need 26 | */ 27 | @Deprecated 28 | public abstract class AbstractPeerDataEventListener implements PeerDataEventListener { 29 | @Override 30 | public void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int blocksLeft) { 31 | } 32 | 33 | @Override 34 | public void onChainDownloadStarted(Peer peer, int blocksLeft) { 35 | } 36 | 37 | @Override 38 | public Message onPreMessageReceived(Peer peer, Message m) { 39 | // Just pass the message right through for further processing. 40 | return m; 41 | } 42 | 43 | @Override 44 | public List getData(Peer peer, GetDataMessage m) { 45 | return null; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/misc/Immutable.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.misc; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /* 10 | * Copyright (c) 2005 Brian Goetz and Tim Peierls 11 | * Released under the Creative Commons Attribution License 12 | * (http://creativecommons.org/licenses/by/2.5) 13 | * Official home: http://www.jcip.net 14 | * 15 | * Any republication or derived work distributed in source code form 16 | * must include this copyright and license notice. 17 | */ 18 | 19 | 20 | /** 21 | * The class to which this annotation is applied is immutable. This means that 22 | * its state cannot be seen to change by callers, which implies that 23 | *
    24 | *
  • all public fields are final,
  • 25 | *
  • all public final reference fields refer to other immutable objects, and
  • 26 | *
  • constructors and methods do not publish references to any internal state 27 | * which is potentially mutable by the implementation.
  • 28 | *
29 | * Immutable objects may still have internal mutable state for purposes of performance 30 | * optimization; some state variables may be lazily computed, so long as they are computed 31 | * from immutable state and that callers cannot tell the difference. 32 | *

33 | * Immutable objects are inherently thread-safe; they may be passed between threads or 34 | * published without synchronization. 35 | */ 36 | @Documented 37 | @Target(ElementType.TYPE) 38 | @Retention(RetentionPolicy.RUNTIME) 39 | public @interface Immutable { 40 | 41 | } 42 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/core/listeners/ReorganizeListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.bitcoinj.core.listeners; 17 | 18 | import java.util.List; 19 | import org.bitcoinj.core.StoredBlock; 20 | import org.bitcoinj.core.VerificationException; 21 | 22 | /** 23 | * Listener interface for when the best chain has changed. 24 | */ 25 | public interface ReorganizeListener { 26 | 27 | /** 28 | * Called by the {@link BlockChain} when the best chain (representing total work done) has changed. In this case, 29 | * we need to go through our transactions and find out if any have become invalid. It's possible for our balance 30 | * to go down in this case: money we thought we had can suddenly vanish if the rest of the network agrees it 31 | * should be so.

32 | * 33 | * The oldBlocks/newBlocks lists are ordered height-wise from top first to bottom last (i.e. newest blocks first). 34 | */ 35 | void reorganize(StoredBlock splitPoint, List oldBlocks, 36 | List newBlocks) throws VerificationException; 37 | } 38 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/wallet/WalletTransaction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.wallet; 18 | 19 | import org.bitcoinj.core.Transaction; 20 | 21 | import static com.google.common.base.Preconditions.checkNotNull; 22 | 23 | /** 24 | * Stores data about a transaction that is only relevant to the {@link org.bitcoinj.core.Wallet} class. 25 | */ 26 | public class WalletTransaction { 27 | public enum Pool { 28 | UNSPENT, // unspent in best chain 29 | SPENT, // spent in best chain 30 | DEAD, // double-spend in alt chain 31 | PENDING, // a pending tx we would like to go into the best chain 32 | } 33 | private final Transaction transaction; 34 | private final Pool pool; 35 | 36 | public WalletTransaction(Pool pool, Transaction transaction) { 37 | this.pool = checkNotNull(pool); 38 | this.transaction = transaction; 39 | } 40 | 41 | public Transaction getTransaction() { 42 | return transaction; 43 | } 44 | 45 | public Pool getPool() { 46 | return pool; 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/data/exitpolicy/Network.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.data.exitpolicy; 2 | 3 | import com.subgraph.orchid.TorParsingException; 4 | import com.subgraph.orchid.data.IPv4Address; 5 | 6 | public class Network { 7 | public static final Network ALL_ADDRESSES = new Network(IPv4Address.createFromString("0.0.0.0"), 0, "*"); 8 | public static Network createFromString(String networkString) { 9 | final String[] parts = networkString.split("/"); 10 | final IPv4Address network = IPv4Address.createFromString(parts[0]); 11 | if(parts.length == 1) 12 | return new Network(network, 32, networkString); 13 | 14 | if(parts.length != 2) 15 | throw new TorParsingException("Invalid network CIDR notation: " + networkString); 16 | 17 | try { 18 | final int maskBits = Integer.parseInt(parts[1]); 19 | return new Network(network, maskBits, networkString); 20 | } catch(NumberFormatException e) { 21 | throw new TorParsingException("Invalid netblock mask bit value: " + parts[1]); 22 | } 23 | } 24 | 25 | private final IPv4Address network; 26 | private final int maskValue; 27 | private final String originalString; 28 | 29 | Network(IPv4Address network, int bits, String originalString) { 30 | this.network = network; 31 | this.maskValue = createMask(bits); 32 | this.originalString = originalString; 33 | } 34 | 35 | private static int createMask(int maskBits) { 36 | return maskBits == 0 ? 0 : (1 << 31) >> (maskBits - 1); 37 | } 38 | 39 | public boolean contains(IPv4Address address) { 40 | return (address.getAddressData() & maskValue) == (network.getAddressData() & maskValue); 41 | } 42 | 43 | public String toString() { 44 | return originalString; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/directory/parsing/BasicDocumentParsingResult.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.directory.parsing; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class BasicDocumentParsingResult implements DocumentParsingResultHandler, DocumentParsingResult { 7 | 8 | private final List documents; 9 | private T invalidDocument; 10 | private boolean isOkay; 11 | private boolean isInvalid; 12 | private boolean isError; 13 | private String message; 14 | 15 | public BasicDocumentParsingResult() { 16 | documents = new ArrayList(); 17 | isOkay = true; 18 | isInvalid = false; 19 | isError = false; 20 | message = ""; 21 | } 22 | 23 | public T getDocument() { 24 | if(documents.size() != 1) { 25 | throw new IllegalStateException(); 26 | } 27 | return documents.get(0); 28 | } 29 | 30 | public List getParsedDocuments() { 31 | return new ArrayList(documents); 32 | } 33 | 34 | public boolean isOkay() { 35 | return isOkay; 36 | } 37 | 38 | public boolean isInvalid() { 39 | return isInvalid; 40 | } 41 | 42 | public T getInvalidDocument() { 43 | return invalidDocument; 44 | } 45 | 46 | public boolean isError() { 47 | return isError; 48 | } 49 | 50 | public String getMessage() { 51 | return message; 52 | } 53 | 54 | public void documentParsed(T document) { 55 | documents.add(document); 56 | } 57 | 58 | public void documentInvalid(T document, String message) { 59 | isOkay = false; 60 | isInvalid = true; 61 | invalidDocument = document; 62 | this.message = message; 63 | } 64 | 65 | public void parsingError(String message) { 66 | isOkay = false; 67 | isError = true; 68 | this.message = message; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /examples/src/main/javascript/forwarding.js: -------------------------------------------------------------------------------- 1 | // For more info on how to run/control logging look at demo.js 2 | // 3 | // This example shows how to implement the forwarding service demo from the Getting Started tutorial. 4 | 5 | var bcj = org.bitcoinj; 6 | var params = bcj.params.TestNet3Params.get(); 7 | 8 | // Address where we'll send received coins (minus the miner fee) 9 | var FORWARD_TO = "mfZCyhQUQXy2S91hnGepdaJxfaNjMg15AV"; // faucet.xeno-genesis.com 10 | 11 | // Make logging more compact. 12 | bcj.utils.BriefLogFormatter.init(); 13 | 14 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 15 | 16 | var forwardingAddr = new bcj.core.Address(params, FORWARD_TO); 17 | 18 | var kit = new bcj.kits.WalletAppKit(params, new java.io.File("/tmp"), "forwarding-demo"); 19 | print("Starting up ..."); 20 | kit.startAsync() 21 | kit.awaitRunning() 22 | 23 | var wallet = kit.wallet(); 24 | var myAddr = wallet.currentReceiveAddress() 25 | var uri = "bitcoin:" + myAddr; 26 | print("Send coins to: " + myAddr); 27 | print("QRcode: http://qrickit.com/api/qr?d=" + uri); 28 | 29 | wallet.allowSpendingUnconfirmedTransactions() 30 | 31 | var listener = Java.extend(bcj.core.AbstractWalletEventListener); 32 | wallet.addEventListener(new listener() { 33 | onCoinsReceived: function(wallet, tx, prevBalance, newBalance) { 34 | print("Received money! " + newBalance.toFriendlyString()); 35 | var sendReq = bcj.core.Wallet.SendRequest.emptyWallet(forwardingAddr); 36 | var sendResult = wallet.sendCoins(sendReq); 37 | print("Sending back in tx " + sendResult.tx.hash); 38 | } 39 | }); 40 | 41 | print("Press Ctrl-C to stop"); 42 | java.lang.Thread.sleep(1000 * 60 * 60); // One hour. -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/core/RejectedTransactionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Adam Mackler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.core; 18 | 19 | /** 20 | * This exception is used by the TransactionBroadcast class to indicate that a broadcast 21 | * Transaction has been rejected by the network, for example because it violates a 22 | * protocol rule. Note that not all invalid transactions generate a reject message, and 23 | * some peers may never do so. 24 | */ 25 | public class RejectedTransactionException extends Exception { 26 | private Transaction tx; 27 | private RejectMessage rejectMessage; 28 | 29 | public RejectedTransactionException(Transaction tx, RejectMessage rejectMessage) { 30 | super(rejectMessage.toString()); 31 | this.tx = tx; 32 | this.rejectMessage = rejectMessage; 33 | } 34 | 35 | /** Return the original Transaction object whose broadcast was rejected. */ 36 | public Transaction getTransaction() { return tx; } 37 | 38 | /** Return the RejectMessage object representing the broadcast rejection. */ 39 | public RejectMessage getRejectMessage() { return rejectMessage; } 40 | } 41 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/core/Pong.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Matt Corallo 3 | * Copyright 2015 Andreas Schildbach 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.bitcoinj.core; 19 | 20 | import java.io.IOException; 21 | import java.io.OutputStream; 22 | 23 | public class Pong extends Message { 24 | private long nonce; 25 | 26 | public Pong(NetworkParameters params, byte[] payloadBytes) throws ProtocolException { 27 | super(params, payloadBytes, 0); 28 | } 29 | 30 | /** 31 | * Create a Pong with a nonce value. 32 | * Only use this if the remote node has a protocol version > 60000 33 | */ 34 | public Pong(long nonce) { 35 | this.nonce = nonce; 36 | } 37 | 38 | @Override 39 | protected void parse() throws ProtocolException { 40 | nonce = readInt64(); 41 | length = 8; 42 | } 43 | 44 | @Override 45 | public void bitcoinSerializeToStream(OutputStream stream) throws IOException { 46 | Utils.int64ToByteStreamLE(nonce, stream); 47 | } 48 | 49 | /** Returns the nonce sent by the remote peer. */ 50 | public long getNonce() { 51 | return nonce; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/utils/BaseTaggableObject.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.utils; 2 | 3 | import com.google.common.collect.Maps; 4 | import com.google.protobuf.ByteString; 5 | 6 | import javax.annotation.Nullable; 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | import static com.google.common.base.Preconditions.checkNotNull; 11 | 12 | /** 13 | * A simple implementation of {@link TaggableObject} that just uses a lazily created hashmap that is 14 | * synchronized on this objects Java monitor. 15 | */ 16 | public class BaseTaggableObject implements TaggableObject { 17 | @Nullable protected Map tags; 18 | 19 | /** {@inheritDoc} */ 20 | @Override 21 | @Nullable 22 | public synchronized ByteString maybeGetTag(String tag) { 23 | if (tags == null) 24 | return null; 25 | else 26 | return tags.get(tag); 27 | } 28 | 29 | /** {@inheritDoc} */ 30 | @Override 31 | public ByteString getTag(String tag) { 32 | ByteString b = maybeGetTag(tag); 33 | if (b == null) 34 | throw new IllegalArgumentException("Unknown tag " + tag); 35 | return b; 36 | } 37 | 38 | /** {@inheritDoc} */ 39 | @Override 40 | public synchronized void setTag(String tag, ByteString value) { 41 | checkNotNull(tag); 42 | checkNotNull(value); 43 | if (tags == null) 44 | tags = new HashMap(); 45 | tags.put(tag, value); 46 | } 47 | 48 | /** {@inheritDoc} */ 49 | @Override 50 | public synchronized Map getTags() { 51 | if (tags != null) 52 | return Maps.newHashMap(tags); 53 | else 54 | return Maps.newHashMap(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/core/WrongNetworkException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.core; 18 | 19 | import java.util.Arrays; 20 | 21 | /** 22 | * This exception is thrown by the Address class when you try and decode an address with a version code that isn't 23 | * used by that network. You shouldn't allow the user to proceed in this case as they are trying to send money across 24 | * different chains, an operation that is guaranteed to destroy the money. 25 | */ 26 | public class WrongNetworkException extends AddressFormatException { 27 | /** The version code that was provided in the address. */ 28 | public int verCode; 29 | /** The list of acceptable versions that were expected given the addresses network parameters. */ 30 | public int[] acceptableVersions; 31 | 32 | public WrongNetworkException(int verCode, int[] acceptableVersions) { 33 | super("Version code of address did not match acceptable versions for network: " + verCode + " not in " + 34 | Arrays.toString(acceptableVersions)); 35 | this.verCode = verCode; 36 | this.acceptableVersions = acceptableVersions; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/directory/DocumentParserFactoryImpl.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.directory; 2 | 3 | import java.nio.ByteBuffer; 4 | 5 | import com.subgraph.orchid.ConsensusDocument; 6 | import com.subgraph.orchid.KeyCertificate; 7 | import com.subgraph.orchid.RouterDescriptor; 8 | import com.subgraph.orchid.RouterMicrodescriptor; 9 | import com.subgraph.orchid.directory.certificate.KeyCertificateParser; 10 | import com.subgraph.orchid.directory.consensus.ConsensusDocumentParser; 11 | import com.subgraph.orchid.directory.parsing.DocumentFieldParser; 12 | import com.subgraph.orchid.directory.parsing.DocumentParser; 13 | import com.subgraph.orchid.directory.parsing.DocumentParserFactory; 14 | import com.subgraph.orchid.directory.router.RouterDescriptorParser; 15 | import com.subgraph.orchid.directory.router.RouterMicrodescriptorParser; 16 | 17 | public class DocumentParserFactoryImpl implements DocumentParserFactory { 18 | 19 | public DocumentParser createKeyCertificateParser(ByteBuffer buffer) { 20 | return new KeyCertificateParser(new DocumentFieldParserImpl(buffer)); 21 | } 22 | 23 | public DocumentParser createRouterDescriptorParser(ByteBuffer buffer, boolean verifySignatures) { 24 | return new RouterDescriptorParser(new DocumentFieldParserImpl(buffer), verifySignatures); 25 | } 26 | 27 | public DocumentParser createRouterMicrodescriptorParser(ByteBuffer buffer) { 28 | buffer.rewind(); 29 | DocumentFieldParser dfp = new DocumentFieldParserImpl(buffer); 30 | return new RouterMicrodescriptorParser(dfp); 31 | } 32 | 33 | public DocumentParser createConsensusDocumentParser(ByteBuffer buffer) { 34 | return new ConsensusDocumentParser(new DocumentFieldParserImpl(buffer)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/core/TransactionBag.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Giannis Dzegoutanis 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.core; 18 | 19 | import org.bitcoinj.script.Script; 20 | import org.bitcoinj.wallet.WalletTransaction; 21 | 22 | import java.util.Map; 23 | 24 | /** 25 | * This interface is used to abstract the {@link org.bitcoinj.core.Wallet} and the {@link org.bitcoinj.core.Transaction} 26 | */ 27 | public interface TransactionBag { 28 | /** Returns true if this wallet contains a public key which hashes to the given hash. */ 29 | boolean isPubKeyHashMine(byte[] pubkeyHash); 30 | 31 | /** Returns true if this wallet is watching transactions for outputs with the script. */ 32 | boolean isWatchedScript(Script script); 33 | 34 | /** Returns true if this wallet contains a keypair with the given public key. */ 35 | boolean isPubKeyMine(byte[] pubkey); 36 | 37 | /** Returns true if this wallet knows the script corresponding to the given hash. */ 38 | boolean isPayToScriptHashMine(byte[] payToScriptHash); 39 | 40 | /** Returns transactions from a specific pool. */ 41 | Map getTransactionPool(WalletTransaction.Pool pool); 42 | } 43 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/testing/InboundMessageQueuer.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.testing; 2 | 3 | import org.bitcoinj.core.*; 4 | import com.google.common.util.concurrent.SettableFuture; 5 | 6 | import java.net.InetSocketAddress; 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | import java.util.concurrent.ArrayBlockingQueue; 10 | import java.util.concurrent.BlockingQueue; 11 | 12 | /** 13 | * An extension of {@link org.bitcoinj.core.PeerSocketHandler} that keeps inbound messages in a queue for later processing 14 | */ 15 | public abstract class InboundMessageQueuer extends PeerSocketHandler { 16 | public final BlockingQueue inboundMessages = new ArrayBlockingQueue(1000); 17 | public final Map> mapPingFutures = new HashMap>(); 18 | 19 | public Peer peer; 20 | public BloomFilter lastReceivedFilter; 21 | 22 | protected InboundMessageQueuer(NetworkParameters params) { 23 | super(params, new InetSocketAddress("127.0.0.1", 2000)); 24 | } 25 | 26 | public Message nextMessage() { 27 | return inboundMessages.poll(); 28 | } 29 | 30 | public Message nextMessageBlocking() throws InterruptedException { 31 | return inboundMessages.take(); 32 | } 33 | 34 | @Override 35 | protected void processMessage(Message m) throws Exception { 36 | if (m instanceof Ping) { 37 | SettableFuture future = mapPingFutures.get(((Ping) m).getNonce()); 38 | if (future != null) { 39 | future.set(null); 40 | return; 41 | } 42 | } 43 | if (m instanceof BloomFilter) { 44 | lastReceivedFilter = (BloomFilter) m; 45 | } 46 | inboundMessages.offer(m); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /core/src/test/java/org/bitcoinj/store/LevelDBBlockStoreTest.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.store; 2 | 3 | import org.bitcoinj.core.*; 4 | import org.bitcoinj.params.*; 5 | import org.junit.*; 6 | 7 | import java.io.*; 8 | 9 | import static org.junit.Assert.assertEquals; 10 | 11 | public class LevelDBBlockStoreTest { 12 | @Test 13 | public void basics() throws Exception { 14 | File f = File.createTempFile("leveldbblockstore", null); 15 | f.delete(); 16 | 17 | NetworkParameters params = UnitTestParams.get(); 18 | Context context = new Context(params); 19 | LevelDBBlockStore store = new LevelDBBlockStore(context, f); 20 | store.reset(); 21 | 22 | // Check the first block in a new store is the genesis block. 23 | StoredBlock genesis = store.getChainHead(); 24 | assertEquals(params.getGenesisBlock(), genesis.getHeader()); 25 | assertEquals(0, genesis.getHeight()); 26 | 27 | // Build a new block. 28 | Address to = Address.fromBase58(params, "mrj2K6txjo2QBcSmuAzHj4nD1oXSEJE1Qo"); 29 | StoredBlock b1 = genesis.build(genesis.getHeader().createNextBlock(to).cloneAsHeader()); 30 | store.put(b1); 31 | store.setChainHead(b1); 32 | store.close(); 33 | 34 | // Check we can get it back out again if we rebuild the store object. 35 | store = new LevelDBBlockStore(context, f); 36 | try { 37 | StoredBlock b2 = store.get(b1.getHeader().getHash()); 38 | assertEquals(b1, b2); 39 | // Check the chain head was stored correctly also. 40 | StoredBlock chainHead = store.getChainHead(); 41 | assertEquals(b1, chainHead); 42 | } finally { 43 | store.close(); 44 | store.destroy(); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/core/listeners/NewBestBlockListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.bitcoinj.core.listeners; 17 | 18 | import org.bitcoinj.core.StoredBlock; 19 | import org.bitcoinj.core.VerificationException; 20 | 21 | /** 22 | * Listener interface for when a new block on the best chain is seen. 23 | */ 24 | public interface NewBestBlockListener { 25 | /** 26 | * Called when a new block on the best chain is seen, after relevant 27 | * transactions are extracted and sent to us via either 28 | * {@link ReceiveFromBlockListener#receiveFromBlock(Transaction, StoredBlock, org.bitcoinj.core.BlockChain.NewBlockType, int)} 29 | * or {@link TransactionIsInBlockListener#notifyTransactionIsInBlock(Sha256Hash, StoredBlock, org.bitcoinj.core.BlockChain.NewBlockType, int)}. 30 | * If this block is causing a re-organise to a new chain, this method is NOT 31 | * called even though the block may be the new best block: your reorganize 32 | * implementation is expected to do whatever would normally be done do for a 33 | * new best block in this case. 34 | */ 35 | void notifyNewBestBlock(final StoredBlock block) throws VerificationException; 36 | } 37 | -------------------------------------------------------------------------------- /core/findbugs.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/misc/GuardedBy.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.misc; 2 | 3 | 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /** 10 | * The field or method to which this annotation is applied can only be accessed 11 | * when holding a particular lock, which may be a built-in (synchronization) lock, 12 | * or may be an explicit java.util.concurrent.Lock. 13 | * 14 | * The argument determines which lock guards the annotated field or method: 15 | *

    16 | *
  • 17 | * this : The intrinsic lock of the object in whose class the field is defined. 18 | *
  • 19 | *
  • 20 | * class-name.this : For inner classes, it may be necessary to disambiguate 'this'; 21 | * the class-name.this designation allows you to specify which 'this' reference is intended 22 | *
  • 23 | *
  • 24 | * itself : For reference fields only; the object to which the field refers. 25 | *
  • 26 | *
  • 27 | * field-name : The lock object is referenced by the (instance or static) field 28 | * specified by field-name. 29 | *
  • 30 | *
  • 31 | * class-name.field-name : The lock object is reference by the static field specified 32 | * by class-name.field-name. 33 | *
  • 34 | *
  • 35 | * method-name() : The lock object is returned by calling the named nil-ary method. 36 | *
  • 37 | *
  • 38 | * class-name.class : The Class object for the specified class should be used as the lock object. 39 | *
  • 40 | */ 41 | @Target({ElementType.FIELD, ElementType.METHOD}) 42 | @Retention(RetentionPolicy.RUNTIME) 43 | public @interface GuardedBy { 44 | String value(); 45 | } 46 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/core/InventoryItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.core; 18 | 19 | import com.google.common.base.Objects; 20 | 21 | public class InventoryItem { 22 | 23 | /** 24 | * 4 byte uint32 type field + 32 byte hash 25 | */ 26 | static final int MESSAGE_LENGTH = 36; 27 | 28 | public enum Type { 29 | Error, 30 | Transaction, 31 | Block, 32 | FilteredBlock 33 | } 34 | 35 | public final Type type; 36 | public final Sha256Hash hash; 37 | 38 | public InventoryItem(Type type, Sha256Hash hash) { 39 | this.type = type; 40 | this.hash = hash; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return type + ": " + hash; 46 | } 47 | 48 | @Override 49 | public boolean equals(Object o) { 50 | if (this == o) return true; 51 | if (o == null || getClass() != o.getClass()) return false; 52 | InventoryItem other = (InventoryItem) o; 53 | return type == other.type && hash.equals(other.hash); 54 | } 55 | 56 | @Override 57 | public int hashCode() { 58 | return Objects.hashCode(type, hash); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/wallet/RiskAnalysis.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.wallet; 18 | 19 | import org.bitcoinj.core.Transaction; 20 | import org.bitcoinj.core.Wallet; 21 | 22 | import java.util.List; 23 | 24 | /** 25 | *

    A RiskAnalysis represents an analysis of how likely it is that a transaction (and its dependencies) represents a 26 | * possible double spending attack. The wallet will create these to decide whether or not to accept a pending 27 | * transaction. Look at {@link DefaultRiskAnalysis} to see what is currently considered risky.

    28 | * 29 | *

    The intention here is that implementing classes can expose more information and detail about the result, for 30 | * app developers. The core code needs only to know whether it's OK or not.

    31 | * 32 | *

    A factory interface is provided. The wallet will use this to analyze new pending transactions.

    33 | */ 34 | public interface RiskAnalysis { 35 | enum Result { 36 | OK, 37 | NON_FINAL, 38 | NON_STANDARD 39 | } 40 | 41 | Result analyze(); 42 | 43 | interface Analyzer { 44 | RiskAnalysis create(Wallet wallet, Transaction tx, List dependencies); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/utils/ContextPropagatingThreadFactory.java: -------------------------------------------------------------------------------- 1 | package org.bitcoinj.utils; 2 | 3 | import com.google.common.base.*; 4 | import org.bitcoinj.core.*; 5 | import org.slf4j.*; 6 | 7 | import java.util.concurrent.*; 8 | 9 | /** 10 | * A {@link java.util.concurrent.ThreadFactory} that propagates a {@link org.bitcoinj.core.Context} from the creating 11 | * thread into the new thread. This factory creates daemon threads. 12 | */ 13 | public class ContextPropagatingThreadFactory implements ThreadFactory { 14 | private static final Logger log = LoggerFactory.getLogger(ContextPropagatingThreadFactory.class); 15 | private final String name; 16 | private final int priority; 17 | 18 | public ContextPropagatingThreadFactory(String name, int priority) { 19 | this.name = name; 20 | this.priority = priority; 21 | } 22 | 23 | public ContextPropagatingThreadFactory(String name) { 24 | this(name, Thread.NORM_PRIORITY); 25 | } 26 | 27 | @Override 28 | public Thread newThread(final Runnable r) { 29 | final Context context = Context.get(); 30 | Thread thread = new Thread(new Runnable() { 31 | @Override 32 | public void run() { 33 | try { 34 | Context.propagate(context); 35 | r.run(); 36 | } catch (Exception e) { 37 | log.error("Exception in thread", e); 38 | Throwables.propagate(e); 39 | } 40 | } 41 | }, name); 42 | thread.setPriority(priority); 43 | thread.setDaemon(true); 44 | Thread.UncaughtExceptionHandler handler = Threading.uncaughtExceptionHandler; 45 | if (handler != null) 46 | thread.setUncaughtExceptionHandler(handler); 47 | return thread; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /core/src/main/java/org/bitcoinj/utils/ListenerRegistration.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoinj.utils; 18 | 19 | import java.util.List; 20 | import java.util.concurrent.Executor; 21 | 22 | import static com.google.common.base.Preconditions.checkNotNull; 23 | 24 | /** 25 | * A simple wrapper around a listener and an executor, with some utility methods. 26 | */ 27 | public class ListenerRegistration { 28 | public final T listener; 29 | public final Executor executor; 30 | 31 | public ListenerRegistration(T listener, Executor executor) { 32 | this.listener = checkNotNull(listener); 33 | this.executor = checkNotNull(executor); 34 | } 35 | 36 | /** Returns true if the listener was removed, else false. */ 37 | public static boolean removeFromList(T listener, List> list) { 38 | checkNotNull(listener); 39 | 40 | ListenerRegistration item = null; 41 | for (ListenerRegistration registration : list) { 42 | if (registration.listener == listener) { 43 | item = registration; 44 | break; 45 | } 46 | } 47 | return item != null && list.remove(item); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /core/src/test/java/org/bitcoinj/core/PeerAddressTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Google Inc. 3 | * Copyright 2014 Andreas Schildbach 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.bitcoinj.core; 19 | 20 | import org.bitcoinj.params.MainNetParams; 21 | import org.junit.Test; 22 | 23 | import java.net.InetAddress; 24 | 25 | import static org.bitcoinj.core.Utils.HEX; 26 | import static org.junit.Assert.assertEquals; 27 | 28 | public class PeerAddressTest 29 | { 30 | @Test 31 | public void testPeerAddressRoundtrip() throws Exception { 32 | // copied verbatim from https://en.bitcoin.it/wiki/Protocol_specification#Network_address 33 | String fromSpec = "010000000000000000000000000000000000ffff0a000001208d"; 34 | PeerAddress pa = new PeerAddress(MainNetParams.get(), 35 | HEX.decode(fromSpec), 0, 0); 36 | String reserialized = Utils.HEX.encode(pa.bitcoinSerialize()); 37 | assertEquals(reserialized,fromSpec ); 38 | } 39 | 40 | @Test 41 | public void testBitcoinSerialize() throws Exception { 42 | PeerAddress pa = new PeerAddress(InetAddress.getByName(null), 8333, 0); 43 | assertEquals("000000000000000000000000000000000000ffff7f000001208d", 44 | Utils.HEX.encode(pa.bitcoinSerialize())); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /wallettemplate/src/main/java/wallettemplate/controls/BitcoinAddressValidator.java: -------------------------------------------------------------------------------- 1 | package wallettemplate.controls; 2 | 3 | import org.bitcoinj.core.Address; 4 | import org.bitcoinj.core.AddressFormatException; 5 | import org.bitcoinj.core.NetworkParameters; 6 | import javafx.scene.Node; 7 | import javafx.scene.control.TextField; 8 | import wallettemplate.utils.TextFieldValidator; 9 | 10 | /** 11 | * Given a text field, some network params and optionally some nodes, will make the text field an angry red colour 12 | * if the address is invalid for those params, and enable/disable the nodes. 13 | */ 14 | public class BitcoinAddressValidator { 15 | private NetworkParameters params; 16 | private Node[] nodes; 17 | 18 | public BitcoinAddressValidator(NetworkParameters params, TextField field, Node... nodes) { 19 | this.params = params; 20 | this.nodes = nodes; 21 | 22 | // Handle the red highlighting, but don't highlight in red just when the field is empty because that makes 23 | // the example/prompt address hard to read. 24 | new TextFieldValidator(field, text -> text.isEmpty() || testAddr(text)); 25 | // However we do want the buttons to be disabled when empty so we apply a different test there. 26 | field.textProperty().addListener((observableValue, prev, current) -> { 27 | toggleButtons(current); 28 | }); 29 | toggleButtons(field.getText()); 30 | } 31 | 32 | private void toggleButtons(String current) { 33 | boolean valid = testAddr(current); 34 | for (Node n : nodes) n.setDisable(!valid); 35 | } 36 | 37 | private boolean testAddr(String text) { 38 | try { 39 | Address.fromBase58(params, text); 40 | return true; 41 | } catch (AddressFormatException e) { 42 | return false; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /orchid/src/com/subgraph/orchid/directory/router/RouterDescriptorKeyword.java: -------------------------------------------------------------------------------- 1 | package com.subgraph.orchid.directory.router; 2 | 3 | public enum RouterDescriptorKeyword { 4 | /* 5 | * See dir-spec.txt 6 | * Section 2.1. Router descriptor format 7 | */ 8 | ROUTER("router", 5), 9 | BANDWIDTH("bandwidth", 3), 10 | PLATFORM("platform"), 11 | PUBLISHED("published", 2), 12 | FINGERPRINT("fingerprint", 10), 13 | HIBERNATING("hibernating", 1), 14 | UPTIME("uptime", 1), 15 | ONION_KEY("onion-key", 0), 16 | NTOR_ONION_KEY("ntor-onion-key", 1), 17 | SIGNING_KEY("signing-key", 0), 18 | ACCEPT("accept", 1), 19 | REJECT("reject", 1), 20 | ROUTER_SIGNATURE("router-signature", 0), 21 | CONTACT("contact"), 22 | FAMILY("family"), 23 | READ_HISTORY("read-history"), 24 | WRITE_HISTORY("write-history"), 25 | EVENTDNS("eventdns", 1), 26 | CACHES_EXTRA_INFO("caches-extra-info", 0), 27 | EXTRA_INFO_DIGEST("extra-info-digest", 1), 28 | HIDDEN_SERVICE_DIR("hidden-service-dir"), 29 | PROTOCOLS("protocols"), 30 | ALLOW_SINGLE_HOP_EXITS("allow-single-hop-exits", 0), 31 | UNKNOWN_KEYWORD("KEYWORD NOT FOUND"); 32 | 33 | public final static int VARIABLE_ARGUMENT_COUNT = -1; 34 | 35 | private final String keyword; 36 | private final int argumentCount; 37 | 38 | RouterDescriptorKeyword(String keyword) { 39 | this(keyword, VARIABLE_ARGUMENT_COUNT); 40 | } 41 | 42 | RouterDescriptorKeyword(String keyword, int argumentCount) { 43 | this.keyword = keyword; 44 | this.argumentCount = argumentCount; 45 | } 46 | 47 | String getKeyword() { 48 | return keyword; 49 | } 50 | 51 | int getArgumentCount() { 52 | return argumentCount; 53 | } 54 | 55 | static RouterDescriptorKeyword findKeyword(String keyword) { 56 | for(RouterDescriptorKeyword k: values()) 57 | if(k.getKeyword().equals(keyword)) 58 | return k; 59 | 60 | return UNKNOWN_KEYWORD; 61 | } 62 | 63 | } 64 | --------------------------------------------------------------------------------