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

expansejs-icap

v0.3.1

Published

Utilities for handling ICAP (Expanse in IBAN) encoding

Downloads

2

Readme

expansejs-icap

NPM Package Build Status Coverage Status

Utilities for handling ICAP addresses.

It works in Node.js as well as in the browser via browserify. When minified for a browser, it should be less than 4K in size.

API

  • fromAddress(address, print, nonstd) - try encoding an address into an IBAN
  • fromAsset(asset, print) - try encoding an asset description into an IBAN
  • toAddress(iban) - try decoding an IBAN into an address
  • toAsset(iban) - try decoding an IBAN into an asset description
  • encode(address/asset) - encode an address or asset description into an IBAN
  • decode(iban) - decode an IBAN into an address or asset description
  • encodeBBAN(address/asset) - encode an address or asset description into a BBAN
  • decodeBBAN(bban) - decode a BBAN into an address or asset description
  • isICAP(iban) - return true if input is a valid ICAP, otherwise false
  • isAddress(iban) - return true if the input is a valid ICAP with an address, otherwise false
  • isAsset(iban) - return true if the input is a valid ICAP with an asset description, otherwise false

All of the above methods will throw exceptions on invalid inputs. The to* and from* method will also check for the expected inputs and outputs.

The print parameter above, when set to true, will create an IBAN in the print format, which is space delimited groups of four characters: XE73 38O0 73KY GTWW ZN0F 2WZ0 R8PX 5ZPP ZS

The address parameter only supports 0x prefixed input and will include that in the output.

The nonstd parameter of fromAddress, when set to true, will turn on support for the basic ICAP format generating an invalid IBAN, but encoding the entire 160 bits of an Ethereum address.

Examples

ICAP.fromAsset({
  asset: 'ETH',
  institution: 'XREG',
  client: 'GAVOFYORK'
})
// returns 'XE81ETHXREGGAVOFYORK'

ICAP.fromAddress('0x00c5496aee77c1ba1f0854206a26dda82a81d6d8')
// returns 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS'

ICAP.toAsset('XE81ETHXREGGAVOFYORK')
// returns {
//   asset: 'ETH',
//   institution: 'XREG',
//   client: 'GAVOFYORK'
// }

ICAP.toAddress('XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS')
// returns '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8'

Direct address generation

A direct address ICAP is an address less than 155 bits of length and therefore it safely fits into the length restrictions of IBAN (and the checksum method used). That upper limit is 0x03ffffffffffffffffffffffffffffffffffffff or XE91GTJRJEU5043IEF993XWE21DBF0BVGF.

The following simple bruteforce code can be used to generate such addresses:

const ethUtil = require('expansejs-util')
function generateDirectAddress () {
  while(true) {
    var privateKey = crypto.randomBytes(32) // or your favourite other random method
    if (ethUtil.privateToAddress(privateKey)[0] <= 3) {
      return privateKey
    }
  }
}

Alternatively expansejs-wallet can be used to generate compatible addresses.