MCPcopy Index your code
hub / github.com/GustavoStingelin/tanos

github.com/GustavoStingelin/tanos @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
73 symbols 439 edges 14 files 70 documented · 96%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

TANOS: Taproot Adaptor for Nostr-Orchestrated Swaps

TANOS is a library implementing atomic swaps between Bitcoin and Nostr, using Taproot and Schnorr adaptor signatures, developed for the MIT Bitcoin Hackathon.

Overview

TANOS allows atomic swaps between: - Bitcoin transactions using Taproot P2TR addresses - Nostr events with Schnorr signatures

The protocol uses adaptor signatures to ensure atomicity: the buyer only gets the signed Nostr event if they pay with Bitcoin, and the seller only gets the Bitcoin if they reveal the secret from the Nostr signature.

Inspiration

This project is inspired by NIP 455: Atomic Signature Swaps, which proposes a standard for performing atomic swaps of cryptographic signatures over Nostr.

Features

  • BIP340-compliant Schnorr adaptor signatures
  • Taproot address creation and transaction handling
  • Nostr event creation and signing
  • Complete atomic swap protocol implementation
  • Pure Go implementation

Project Structure

The project is organized into the following packages:

  • pkg/adaptor - Adaptor signature implementation using Schnorr
  • pkg/bitcoin - Bitcoin-related functionality (Taproot, transactions)
  • pkg/crypto - Common cryptographic utilities
  • pkg/nostr - Nostr-related functionality
  • pkg/tanos - High-level swap protocol implementation
  • examples/swap - Example implementation of a complete swap

Getting Started

Prerequisites

  • Go 1.24.1 or later
  • Bitcoin and Nostr dependencies

Installation

git clone https://github.com/GustavoStingelin/tanos.git
cd tanos
go mod download

Running the Example

go run examples/swap/main.go

The Swap Protocol

  1. Setup:
  2. Seller has a Nostr private key
  3. Buyer has Bitcoin

  4. Commitment:

  5. Seller creates and signs a Nostr event
  6. Seller extracts the nonce (R) from the signature
  7. Seller computes the commitment T = R + e*P

  8. Locking:

  9. Buyer creates a Bitcoin transaction locking funds to a P2TR address
  10. Buyer creates an adaptor signature using the commitment T
  11. Buyer sends the adaptor signature to the seller

  12. Revealing:

  13. Seller completes the adaptor signature using the secret from the Nostr signature
  14. Seller broadcasts the Bitcoin transaction with the completed signature

  15. Verification:

  16. Buyer extracts the secret from the completed signature
  17. Buyer verifies that the secret matches the one in the Nostr signature

Security Considerations

BIP340 Parity Rules

TANOS carefully implements BIP340 parity rules for Schnorr signatures. According to the specification:

  • Schnorr signatures in BIP340 require the Y-coordinate of the nonce point (R) to be even
  • When the Y-coordinate is odd, the signature value 's' must be negated
  • This affects how secrets are extracted from completed signatures

This implementation automatically handles these parity adjustments, ensuring that: 1. Generated Bitcoin signatures are valid according to BIP340 2. Secrets extracted from signatures are correctly recovered, even after parity adjustments

Tagged Hashes

For enhanced security, the library uses BIP340-style tagged hashes for all signature challenges, ensuring signatures from different contexts cannot be reused.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Core symbols most depended-on inside this repo

WrapError
called by 25
pkg/tanos/validation.go
SerializeModNScalar
called by 14
pkg/crypto/utils.go
GeneratePrivateKey
called by 10
pkg/nostr/event.go
NewBuyer
called by 10
pkg/tanos/buyer.go
NewSeller
called by 10
pkg/tanos/seller.go
CreateEvent
called by 10
pkg/tanos/seller.go
Verify
called by 9
pkg/adaptor/signature.go
WrapErrorf
called by 8
pkg/tanos/validation.go

Shape

Function 42
Method 23
Struct 8

Languages

Go100%

Modules by API surface

pkg/tanos/regtest_test.go18 symbols
pkg/adaptor/signature.go9 symbols
pkg/tanos/buyer.go8 symbols
pkg/tanos/transactions.go6 symbols
pkg/tanos/validation.go5 symbols
pkg/crypto/utils.go5 symbols
pkg/nostr/event.go4 symbols
pkg/bitcoin/taproot.go4 symbols
pkg/adaptor/signature_test.go4 symbols
pkg/tanos/validation_test.go3 symbols
pkg/tanos/seller.go3 symbols
pkg/tanos/swap_test.go2 symbols

For agents

$ claude mcp add tanos \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact