npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@stellar-expert/tx-signers-inspector

v1.8.2

Published

Discover required signers, weights, and build optimal signature schema for Stellar transactions.

Downloads

24

Readme

Stellar Tx signers inspector

Discover required signers, weights, and build optimal signature schema for Stellar transactions and accounts.

Usage

npm i @stellar-expert/tx-signers-inspector

Analyze transaction signers

To analyze transaction signature requirements, we need to build signers schema first:

import {inspectTransactionSigners} from '@stellar-expert/tx-signers-inspector'
//build signatures schema
const schema = await inspectTransactionSigners(tx)

Discovering all signers that can potentially sign a transaction

Method getAllPotentialSigners() returns all signers for all accounts used as source in either the transaction itself or any of its operations.

schema.getAllPotentialSigners()
//returns something like ['GA7...K0M', 'GCF...DLP', 'GA0...MMR']

Discovering optimal transaction signers

Method discoverSigners() returns the list of the optimal signers to use. It automatically detects weights and performs an advanced lookup to find the best signing schema in terms of the minimum signers count. This is especially useful for complex transactions containing multiple operations with different sources.

schema.discoverSigners()
//returns something like ['GA7...K0M']

Discovering optimal transaction signers with a restricted list of available signers

Calling discoverSigners(availableSigners) with availableSigners argument returns the optimal signature schema (just like calling it without arguments) respecting the restrictions list. Only explicitly provided signers will be used for a schema lookup.

schema.discoverSigners(['GCF...DLP', 'GA0...MMR', 'GBP...D71'])
//returns something like ['GCF...DLP', 'GA0...MMR']

Checking signing feasibility for a transaction

Method checkFeasibility(availableSigners) verifies that the transaction can be fully signed using a given set of available signers. It returns true if the total weight of the provided signers is sufficient to fully sign the transaction and false otherwise.

schema.checkFeasibility(['GCF...DLP', 'GA0...MMR', 'GBP...D71'])
//returns true
schema.checkFeasibility(['GA0...MMR', 'GBP...D71'])
//returns false

Avoiding TX_BAD_AUTH_EXTRA errors

Stellar protocol forbids transactions signed with excessive number of signers. Adding more signatures than needed for a transaction results in a TX_BAD_AUTH_EXTRA error. In complex cases it's not easy to detect such situations automatically and avoid excessive signatures. Method checkAuthExtra(availableSigners) returns a list of signers that can cause the TX_BAD_AUTH_EXTRA error.

schema.checkAuthExtra(['GCF...DLP', 'GA0...MMR'])
//returns []
schema.checkAuthExtra(['GA7...K0M', 'GCF...DLP', 'GA0...MMR'])
//returns ['GCF...DLP', 'GA0...MMR']

Analyze account signers

Accounts signing requirements can be analyzed similar to transactions.

import {inspectAccountSigners} from '@stellar-expert/tx-signers-inspector'
//build signatures schema for an account
const schema = await inspectAccountSigners('GDF...ER2')

Discovering all account signers

Method getAllPotentialSigners() returns all account signers.

schema.getAllPotentialSigners()
//returns something like ['GA7...K0M', 'GCF...DLP', 'GA0...MMR']

Discovering optimal account signers for a given threshold

Method discoverSigners(weight) returns the list of the optimal signers to match the required signatures weight.

schema.discoverSigners('low')
//returns something like ['GA7...K0M']

Discovering optimal account signers for a given threshold with a restricted list of available signers

Calling discoverSigners(weight, availableSigners) with availableSigners argument returns the optimal signature schema to match the required signatures weight (just like calling it without arguments) respecting the restrictions list. Only explicitly provided signers will be used for a schema lookup.

schema.discoverSigners('med', ['GCF...DLP', 'GA0...MMR', 'GBP...D71'])
//returns something like ['GCF...DLP', 'GA0...MMR']

Checking account signing feasibility for a given threshold

Method checkFeasibility(weight, availableSigners) verifies that the transaction with a given threshold can be fully signed using a given set of available signers. It returns true if the total weight of the provided signers is sufficient to meet the threshold requirements and false otherwise.

schema.checkFeasibility('med', ['GCF...DLP', 'GA0...MMR'])
//returns true
schema.checkFeasibility('high', ['GCF...DLP', 'GA0...MMR'])
//returns false

Avoiding TX_BAD_AUTH_EXTRA errors for a given account threshold

Method checkAuthExtra(weight, availableSigners) returns a list of signers that can cause the TX_BAD_AUTH_EXTRA error when signing a transaction the requires a given account threshold.

schema.checkAuthExtra('med', ['GCF...DLP', 'GA0...MMR'])
//returns []
schema.checkAuthExtra('med', ['GA7...K0M', 'GCF...DLP', 'GA0...MMR'])
//returns ['GCF...DLP', 'GA0...MMR']

Options

The analyzers automatically fetch the required accounts information from Horizon. By default, https://horizon.stellar.org is used. To use testnet Horizon address or you own server, provide horizon options parameter in the inspectTransactionSigners() or inspectAccountSigners() method call:

//use testnet Horizon server instead of the default address
const schema = await inspectTransactionSigners(tx, 
    {horizon: 'https://horizon-testnet.stellar.org'})

To deal with cases where some account doesn't exist yet, it's possible to provide accounts information directly:

//provide account information directly
const schema = await inspectTransactionSigners(tx, {accountsInfo: [
    {
      account_id: 'GAU...DOE',
      id: 'GAU...DOE',
      sequence: '2',
      subentry_count: 0,
      signers: [
        {
          type: 'ed25519_public_key',
          key: 'GAU...DOE',
          weight: 1
        }
      ],
      thresholds: {
        low_threshold: 0,
        med_threshold: 0,
        high_threshold: 0
      }
    }
]})

Tests

npm run test