Cardano JS SDK

repository·master·Indexed 42 days ago

https://github.com/input-output-hk/cardano-js-sdk

A comprehensive suite of TypeScript packages for interacting with the Cardano blockchain, providing core blockchain logic, cryptographic primitives, wallet integration, and service clients for Node.js and browser environments. Version 0.4.0 includes packages such as @cardano-sdk/core, @cardano-sdk/crypto, @cardano-sdk/dapp-connector for CIP-0030 compliance, and @cardano-sdk/cardano-services for GraphQL data access and transaction submission.

Tokens
65.1K
Snippets
138
Records
369
Agent score
53%

What's inside Cardano JS SDK

  1. Overview of Cardano JS SDK | Core

    master
    The @cardano-sdk/core package provides the fundamental building blocks for interacting with the Cardano blockchain. It contains the core data structures, types, and logic required to construct and manipulate blockchain primitives such as transactions, UTXOs, and addresses. This package serves as the foundation for higher-level services and specialized SDK packages within the Cardano JS SDK ecosystem.
  2. Overview of @cardano-sdk/dapp-connector

    master

    The @cardano-sdk/dapp-connector package provides the tools necessary to implement the concepts defined in the [CIP-0030] draft specification. It is designed to facilitate communication between dApps and Cardano wallet web extensions.

    Key capabilities include:

    • Defining TypeScript types and interfaces compliant with CIP-0030.
    • Providing utilities for implementing allow-list persistence.
    • Setting up messaging protocols for web extensions.
  3. Overview of Cardano GraphQL Services

    master

    The @cardano-sdk/cardano-services package provides libraries and program entrypoints to facilitate remote data access and transaction submission using [Provider] interfaces over HTTP.

    Key Capabilities:

    • Data Sourcing: Data is retrieved from Cardano DB Sync (PostgreSQL), Local State Queries via Ogmios, genesis files, and remote sources.
    • Transaction Submission: The TxSubmitHttpService can be configured to submit transactions via Ogmios or via the submit-api.
    • Service Discovery: Supports service port discovery via DNS resolution or static configuration.
    • Observability: Optional Prometheus metrics are available at the /metrics endpoint.
    • Fault Tolerance: Includes fault-tolerant transaction submission mechanisms.
  4. Overview of Cardano JS SDK packages

    master

    The Cardano JS SDK is a suite of TypeScript packages designed for both Node.js and browser-based development. It is distributed as both CommonJS and ESM modules.

    Core packages include:

    • @cardano-sdk/core: Core logic
    • @cardano-sdk/crypto: Cryptographic primitives
    • @cardano-sdk/input-selection: Input selection logic
    • @cardano-sdk/dapp-connector: CIP30 DApp connector
    • @cardano-sdk/governance: Governance features
    • @cardano-sdk/key-management: Key management
    • @cardano-sdk/web-extension: Web extension support
    • @cardano-sdk/wallet: Wallet functionality
    • @cardano-sdk/projection: Projection utilities
    • @cardano-sdk/util-rxjs: RxJS utilities
    • @cardano-sdk/util: General utilities
    • @cardano-sdk/util-dev: Development utilities
    • @cardano-sdk/cardano-services: Cardano GraphQL Services
    • @cardano-sdk/cardano-services-client: Client for Cardano services
  5. Overview of @cardano-sdk/crypto

    master

    The @cardano-sdk/crypto package provides high-level cryptographic primitives designed for Cardano development. It is used for common tasks such as:

    • Hashing: Performing various cryptographic hash functions.
    • Signatures: Generating and verifying digital signatures.
    • Mnemonic Management: Importing private keys from BIP39 mnemonics.
    • Key Derivation: Deriving BIP32-Ed25519 extended signing keys.

    The underlying libsodium implementation was audited in November 2023.

  6. Project Overview of Cardano JS SDK

    master

    The Cardano JS SDK is composed of two primary components:

    1. cardano-services: A backend suite consisting of:

      • Provider server: A REST API server used to query Cardano data and submit transactions.
      • Projector: A chain follower that projects blockchain blocks into a PostgreSQL database.
    2. Client Libraries: Specialized libraries for core blockchain tasks, including:

      • Key management and cryptography helpers.
      • Input selection.
      • wallet: An opinionated, ready-to-use light wallet abstraction that integrates multiple client libraries.
      • web-extension: Components for building web extensions.
  7. Use projection-typeorm to project events into PostgreSQL

    master

    The projection-typeorm package provides utilities for projecting ProjectionEvents into a PostgreSQL database using TypeORM. It is designed to work with the generic projection system in the cardano-js-sdk to maintain a consistent database state based on blockchain events.

    Key components include:

    • TypeormStabilityWindowBuffer: Implements the StabilityWindowBuffer interface required by Bootstrap.fromCardanoNode by writing block data to the block_data table.
    • createTypeormTipTracker: Queries and emits the local tip (latest block header) from the block table.
    • withTypeormTransaction: Wraps events in a PostgreSQL transaction and attaches a TypeORM context (query runner) to the event object.
    • typeormTransactionCommit: Commits the transaction started by withTypeormTransaction and cleans up the context.
    • createObservableConnection: Initializes the TypeORM data source and returns an Observable used as a dependency for other utilities.
  8. How SigningCoordinator works

    master

    The SigningCoordinator facilitates the signing process between the service worker and the UI script.

    When a Witnesser (managed by an ObservableWallet in the service worker) issues a signing request, the SigningCoordinator (acting as a proxy) issues that request in the UI script context. This allows the extension to handle user interactions, such as hardware wallet communication or manual transaction confirmation. Once signing is complete, the SigningCoordinator sends the signatures back to the Witnesser in the service worker.

  9. How WalletManager works

    master

    The WalletManager resides in the service worker and is responsible for instantiating ObservableWallets configured to track specific credentials, networks, and accounts.

    When a wallet switch is triggered (e.g., changing networks or accounts), the WalletManager:

    1. Retrieves the requested wallet data from the WalletRepository.
    2. Builds a new Witnesser using the SigningCoordinator (which is a proxy object pointing to the UI script).
    3. Creates a new ObservableWallet instance.
    4. Emits the new active wallet via the activeWallet$ observable.
  10. How WalletRepository works

    master

    The WalletRepository resides in the service worker and handles the storage and retrieval of wallet data independently. It does not participate in the transaction signing flow.

    To add and use a new wallet:

    1. Register the wallet data using a proxy object of the WalletRepository in the UI script.
    2. Use a proxy object of the WalletManager to activate the newly registered wallet.