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

regulated-assets

v1.0.2

Published

An express middleware adding SEP-8 compliance to your project by specifying your own ruleset. For more information on how this works see the blog post [TBD].

Downloads

4

Readme

Regulated Assets Bridge Server

An express middleware adding SEP-8 compliance to your project by specifying your own ruleset. For more information on how this works see the blog post [TBD].

Usage

See the example project for a full implementation that implements a simple "Transaction must be less than an amount of 50, and accounts can hold a maximum of 1000 tokens" ruleset.

Env Vars

Add ASSET_CODE and ISSUER_SECRET environment variables so that the bridge can sign approval transactions. BRIDGE_HOSTNAME is required if you use the TOML middleware, and should contain the hostname the approval server will be located at. HOME_DOMAIN is required if you want to use the included scripts to set up your issuer account. HOME_DOMAIN should be where your TOML is hosted, and doesn't necessarily need to be the same domain as the bridge.

Issuing an asset

To quickly set up an issuer account, use the scripts/setup-issuer.js script. Ensure your env vars are set up and run:

$ node scripts/setup-issuer.js

This will set up the issuer account with the proper flags. To actually issue an asset, use the scripts/issue-asset-to-address.js script. This can be used to either issue a batch amount to a distribution account, or ad-hoc issuance to clients.

$ node scripts/issue-asset-to-address.js <amount> <wallet address>

Implementation

const regulatedAssetBridge = require("regulated-assets");
const app = express();
app.use(regulatedAssetBridge(rules));
// Optionally add the toml handler
app.use(regulatedAssetBridge.toml);
app.listen(PORT);

The bridge can be used by providing a set of rules. The rules should be an async function that takes in a StellarSdk.Transaction, and returns an object with an allowed boolean and optional error string message. You can do whatever you need inside this rules function to validate whether the proposed transaction should be allowed, including querying the stellar ledger via horizon, external API calls to talk to another part of your service, or just a set of basic rules.

Once you return that a transaction is allowed, the bridge takes care of the rest of the communication with the new sandwiched transaction.

TOML

The bridge provides an optional toml route handler. If you already have a toml file for your service you can just not use the toml middleware, but make sure that your currency has the approval_server and approval_criteria added.

Wallets

Currently there is a branch that adds support for regulated assets here: https://github.com/msfeldstein/stellar-demo-wallet/tree/AddRegAssets. The features will be added to the main project shortly.

Notes

Controlling Asset Holders using AUTHORIZATION_REQUIRED: https://www.stellar.org/developers/guides/concepts/assets.html#controlling-asset-holders