Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cardano-sdk/cip2

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cardano-sdk/cip2

TypeScript definitions for CIP2 (Coin Selection Algorithms for Cardano)

  • 0.5.0-nightly.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
32
Maintainers
1
Weekly downloads
 
Created
Source

Cardano JS SDK | CIP2 | Input Selection

This package implements concepts from the draft specification being developed in CIP-0002.

Currently there is only 1 input selection algorithm: RoundRobinRandomImprove, which is a Random-Improve adaptation that handles asset selection.

Usage Example

import { roundRobinRandomImprove, defaultSelectionConstraints, InputSelector, SelectionResult, SelectionSkeleton } from '@cardano-sdk/cip2';
import { loadCardanoSerializationLib, CSL, CardanoSerializationLib, ProtocolParametersRequiredByWallet } from '@cardano-sdk/core';

const demo = async (protocolParameters: ProtocolParametersRequiredByWallet): Promise<SelectionResult> => {
  const csl: CardanoSerializationLib = await loadCardanoSerializationLib();
  const selector: InputSelector = roundRobinRandomImprove(coinsPerUtxoWord);
  // It is important that you use the same instance of cardano-serialization-lib across your application.
  // Bad: TransactionUnspentOutput.new(...)
  // Good: CSL.TransactionUnspentOutput.new(...)
  const utxo: CSL.TransactionUnspentOutput[] = [CSL.TransactionUnspentOutput.new(...), ...];
  const outputs: CSL.TransactionOutput[] = [CSL.TransactionOutput.new(...), ...];
  // Used to estimate min fee and validate transaction size
  const buildTx = (inputSelection: SelectionSkeleton): Promise<CSL.Transaction> => {...};
  const constraints = defaultSelectionConstraints({
    protocolParameters, buildTx,
  });

  return selector.select({
    utxo,
    outputs,
    constraints,
  });
};

Tests

Input selection is tested with property-based tests using fast-check, as well as a few regular example-based tests.

Due to nature of property-based tests, code coverage report is slightly different on each build.

RoundRobinRandomImprove has 100% code coverage when using high numRuns option (e.g. 100_000).

Note that to run it with high numRuns you need to increase Jest and fast-check timeout.

See code coverage report.

FAQs

Package last updated on 08 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc