GithubHelp home page GithubHelp logo

pegin-address-verifier's Introduction

pegin-address-verifier

This NPM tool can be used to verify address before interacting with the two-way peg system of the RSK network.

Requirements

run npm install.

Methods

isValidAddress

Given a string representing a BTC address and the network (mainnet or testnet), will indicate with a boolean if the address is valid or not.

getAddressInformation

Given a string representing a BTC address, will return information about the address. The information includes the type and the network it belongs to. In case of a P2PKH or P2SH address type, the information also includes the script hash that can be used to obtain the address. This is useful for peg-in protocol version 1, see RSKIP 170 e.g.:

{
 type: 'p2pkh',
 network: 'mainnet',
 scriptPubKey: 'ccc198c15d8344c73da67a75509a85a8f4226636'
}

If the address is not a valid one, this method will return null

canPegIn

Given an address information (the object obtained calling getAddressInformation it will indicate if the address can operate with the RSK network peg-in system.

How to use it

NodeJs

Require the package and use the available methods.

Sample usage:

const peginAddressverifier = require('pegin-address-verifier');
let address = '12QeMLzSrB8XH8FvEzPMVoRxVAzTr5XM2y';
let addressInformation = peginAddressverifier.getAddressInformation(address);
let canPegIn = peginAddressverifier.canPegIn(addressInformation);
console.log(`can peg-in with ${address}? ${canPegIn}`);

Browser

Generate the browser bundle (UMD):

npm run build-umd

Include this file in your webpage, and interact with RskPegInAddressVerifier.

Sample usage:

//isValidAddress
RskPegInAddressVerifier.isValidAddress('mzBc4XEFSdzCDcTxAgf6EZXgsZWpztRhef', 'testnet');
// true

// getAddressInfo
RskPegInAddressVerifier.isValidAddress('mzBc4XEFSdzCDcTxAgf6EZXgsZWpztRhef');
// {"network":"testnet","type":"p2pkh"}

// canPegIn
RskPegInAddressVerifier.isValidAddress({ network: 'testnet', type: 'p2pkh' });
// true

Demo

Run the following command to server up the demo page, including the browser bundled version of this package:

npm run demo
  • Visit http://localhost:2345/.
  • Open browser dev tools and use RskPegInAddressVerifier directly if desired.
  • Alternatively enter an address, select the address type, and select a network in the fields displayed.
  • Observe the output

pegin-address-verifier's People

Contributors

bguiz avatar josedahlquist avatar marcos-iov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.