# bitcoin-sv/go-sdk architecture

> Architecture diagram of the GitHub repository bitcoin-sv/go-sdk, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bitcoin-sv/go-sdk
- Repository: https://github.com/bitcoin-sv/go-sdk

## Overview

##### Main Components Structure

a) Core Primitives Layer (Bottom):
- Cryptographic components (ec, ecdsa, aescbc, aesgcm)
- Key management (keyshares)
- Hash functions (hash)
- DRBG (Deterministic Random Bit Generator)

b) Protocol Layer (Middle):
- Sections for:
- 'script/' (Script interpretation and execution)
- 'transaction/' (Transaction handling)
- 'spv/' (Simple Payment Verification)
- 'chainhash/' (Blockchain hashing utilities)

c) Compatibility Layer (Top):
- 'compat/' components:
- BIP32 (HD wallets)
- BIP39 (Mnemonic codes)
- Base58 encoding
- BSM (Bitcoin Signed Messages)
- ECIES encryption

##### External Interfaces

Interfaces for:
- Transaction broadcasting (transaction/broadcaster/)
- Chain tracking (transaction/chaintracker/)
- Network interaction points

##### Specific Design Elements

a) Transaction Processing Pipeline:
**[Input Processing] → [Script Validation] → [Signature Verification] → [Output Creation]**

b) Cryptographic Operations Flow:
**[Key Generation] → [Signing] → [Verification] → [Encryption/Decryption]**

##### Important Details

- SPV verification flow
- Script interpreter component
- Fee modeling system
- Transaction template system
- Where broadcasting interfaces connect

##### Architectural Patterns to Emphasize

- Layered architecture
- Separation of concerns between cryptographic primitives and higher-level operations
- Where extension points exist for custom implementations

##### Notes for Implementation

- Use rectangles for main components
- Use hexagons for cryptographic operations
- Use clouds for external services
- Version information and supported Bitcoin SV protocol version

##### Scale and Detail Level

- Keep the high-level architecture visible at a glance
- Provide zoom-in sections for complex components like the script interpreter
- Callouts for important features like Shamir key splitting

Remember to include a reference to the documentation and examples directory structure, as these are integral parts of the SDK's architecture.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Compatibility Layer"
        BIP32["BIP32 (HD Wallets)"]:::compat
        BIP39["BIP39 (Mnemonics)"]:::compat
        Base58["Base58 Encoding"]:::compat
        BSM["Bitcoin Signed Messages"]:::compat
        ECIES["ECIES Encryption"]:::compat
    end

    subgraph "Protocol Layer"
        subgraph "Transaction Processing"
            TxHandler["Transaction Handler"]:::tx
            TxBroadcast["Transaction Broadcasting"]:::tx
            ChainTrack["Chain Tracking"]:::tx
            FeeModel["Fee Modeling"]:::tx
            TxTemplate["Transaction Templates"]:::tx
            SigHash["Signature Hashing"]:::tx
        end

        subgraph "Script Components"
            ScriptInt["Script Interpreter"]:::script
            ScriptOps["Script Operations"]:::script
            ScriptEng["Script Engine"]:::script
            ScriptDebug["Script Debug"]:::script
        end

        SPV["SPV Verification"]:::protocol
        ChainHash["Chain Hash Utilities"]:::protocol
    end

    subgraph "Core Primitives Layer"
        subgraph "Cryptographic Components"
            EC["EC Operations"]:::crypto
            ECDSA["ECDSA"]:::crypto
            AESCBC["AES CBC"]:::crypto
            AESGCM["AES GCM"]:::crypto
        end

        subgraph "Key Management"
            KeyShares["Key Shares"]:::keyMgmt
            HashFuncs["Hash Functions"]:::keyMgmt
            DRBG["DRBG"]:::keyMgmt
        end
    end

    subgraph "Message Handling"
        EncMsg["Encrypted Messages"]:::msg
        SignMsg["Signed Messages"]:::msg
    end

    %% Relationships
    BIP32 --> KeyShares
    BIP39 --> KeyShares
    ECIES --> ECDSA
    BSM --> ECDSA
    
    TxHandler --> ScriptInt
    TxHandler --> SigHash
    ScriptInt --> ScriptOps
    ScriptInt --> ScriptEng
    ScriptEng --> ScriptDebug
    
    TxBroadcast --> TxHandler
    ChainTrack --> TxHandler
    FeeModel --> TxHandler
    TxTemplate --> TxHandler
    
    SPV --> ChainHash
    SPV --> TxHandler
    
    EncMsg --> AESCBC
    EncMsg --> AESGCM
    SignMsg --> ECDSA

    %% Click Events
    click EC "https://github.com/bitcoin-sv/go-sdk/tree/master/primitives/ec/"
    click ECDSA "https://github.com/bitcoin-sv/go-sdk/tree/master/primitives/ecdsa/"
    click AESCBC "https://github.com/bitcoin-sv/go-sdk/tree/master/primitives/aescbc/"
    click AESGCM "https://github.com/bitcoin-sv/go-sdk/tree/master/primitives/aesgcm/"
    click KeyShares "https://github.com/bitcoin-sv/go-sdk/tree/master/primitives/keyshares/"
    click HashFuncs "https://github.com/bitcoin-sv/go-sdk/tree/master/primitives/hash/"
    click DRBG "https://github.com/bitcoin-sv/go-sdk/tree/master/primitives/drbg/"
    click ScriptInt "https://github.com/bitcoin-sv/go-sdk/tree/master/script/interpreter/"
    click TxHandler "https://github.com/bitcoin-sv/go-sdk/tree/master/transaction/"
    click SPV "https://github.com/bitcoin-sv/go-sdk/tree/master/spv/"
    click ChainHash "https://github.com/bitcoin-sv/go-sdk/tree/master/chainhash/"
    click BIP32 "https://github.com/bitcoin-sv/go-sdk/tree/master/compat/bip32/"
    click BIP39 "https://github.com/bitcoin-sv/go-sdk/tree/master/compat/bip39/"
    click Base58 "https://github.com/bitcoin-sv/go-sdk/tree/master/compat/base58/"
    click BSM "https://github.com/bitcoin-sv/go-sdk/tree/master/compat/bsm/"
    click ECIES "https://github.com/bitcoin-sv/go-sdk/tree/master/compat/ecies/"
    click TxBroadcast "https://github.com/bitcoin-sv/go-sdk/tree/master/transaction/broadcaster/"
    click ChainTrack "https://github.com/bitcoin-sv/go-sdk/tree/master/transaction/chaintracker/"
    click FeeModel "https://github.com/bitcoin-sv/go-sdk/tree/master/transaction/fee_model/"
    click TxTemplate "https://github.com/bitcoin-sv/go-sdk/tree/master/transaction/template/"
    click SigHash "https://github.com/bitcoin-sv/go-sdk/tree/master/transaction/sighash/"
    click ScriptOps "https://github.com/bitcoin-sv/go-sdk/blob/master/script/interpreter/operations.go"
    click ScriptEng "https://github.com/bitcoin-sv/go-sdk/blob/master/script/interpreter/engine.go"
    click ScriptDebug "https://github.com/bitcoin-sv/go-sdk/tree/master/script/interpreter/debug/"
    click EncMsg "https://github.com/bitcoin-sv/go-sdk/blob/master/message/encrypted.go"
    click SignMsg "https://github.com/bitcoin-sv/go-sdk/blob/master/message/signed.go"

    %% Styles
    classDef crypto fill:#lightblue
    classDef keyMgmt fill:#lightblue
    classDef protocol fill:#green
    classDef tx fill:#green
    classDef script fill:#yellow
    classDef compat fill:#gray
    classDef msg fill:#purple

    %% Legend
    subgraph Legend
        L1["Cryptographic Components"]:::crypto
        L2["Key Management"]:::keyMgmt
        L3["Protocol Components"]:::protocol
        L4["Transaction Components"]:::tx
        L5["Script Components"]:::script
        L6["Compatibility Components"]:::compat
        L7["Message Components"]:::msg
    end
```
