Giter Club home page Giter Club logo

bech32's Introduction

bech32

build status Version

A BIP173/BIP350 compatible Bech32/Bech32m encoding/decoding library.

Example

let { bech32, bech32m } = require('bech32')

bech32.decode('abcdef1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw')
// => {
// 	 prefix: 'abcdef',
// 	 words: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]
// }
bech32m.decode('abcdef1l7aum6echk45nj3s0wdvt2fg8x9yrzpqzd3ryx')
// => {
// 	 prefix: 'abcdef',
// 	 words: [31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0]
// }

// toWords etc. are available on both bech32 and bech32m objects
let words = bech32.toWords(Buffer.from('foobar', 'utf8'))
bech32.encode('foo', words)
// => 'foo1vehk7cnpwgry9h96'
bech32m.encode('foo', words)
// => 'foo1vehk7cnpwgkc4mqc'

Advanced

BIP173 enforces a limitation of 90 characters, if extend the LIMIT parameter beyond this, be aware that the effectiveness of checksum decreases as the length increases.

It is highly recommended NOT exceed 1023 characters, as the module could only guarantee detecting 1 error.

Credits

License MIT

bech32's People

Contributors

andrewtoth avatar d-yokoi avatar dcousens avatar dependabot[bot] avatar fanatid avatar junderw avatar kabutosamourai avatar nesopie avatar paulmillr avatar webmaster128 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bech32's Issues

Code fails to minify

I'm using create-react-app to build an app and the build process is failing if bech32 (e.g. bitcoinjs-lib) is part of dependencies.

Error from npm run build:

Failed to minify the code from this file:

 	./node_modules/bech32/index.js:1

I've tried to debug it but couldn't pinpoint the issue - one thing that I did confirm that if the index file in bech32 is empty from the original code the build process goes through without issues.

P2PKH to bech32

Sry if this is a dumb questions. But as title says.

I have for example 1LKp8CTu2b4VDvybY9iMn3DoV1cm6ZLsrR address created from bitcoinjs-lib/coinjs-lib/bip39 and i want to convert it to bech32?

How can i do it? Thanks for the responses in advance <3

Add (encode/decode)As5bits

Rather than inlining the address encoding/decoding into the same module, I think it'd be better to put that elsewhere (eg bitcoinjs-lib).

Would still provide bech32.encode/decode for generic encoding/decoding.

package.json does not reference index.d.ts

Running npm install --save bitcoinjs/bech32 does not download the index.d.ts file, required for TypeScript. The current package.json contains this:

"files": [
    "index.js"
  ],

Should it rather contain this, instead?

"files": [
    "index.js",
    "index.d.ts"
  ],

This library seems to fail some bip350 test vectors

According to bip350:

The following list gives valid segwit addresses and the scriptPubKey that they translate to in hex.
...
tb1pqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesf3hn0c: 5120000000c4a5cad46221b2a187905e5266362b99d5e91c6ce24d165dab93e86433
bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqzk5jj0: 512079be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798

I tried these test vectors in the bech32 library and this is what I got:

var words = bech32.bech32m.decode( "tb1pqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesf3hn0c" ).words;
console.log( bytesToHex( bech32.bech32m.fromWords( words ) ) );
//08000006252e56a3110d950c3c82f29331b15cceaf48e3671268b2ed5c9f432198
var words = bech32.bech32m.decode( "bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqzk5jj0" ).words;
console.log( bytesToHex( bech32.bech32m.fromWords( words ) ) );
//0bcdf333f7cee5dd62ad0314ae7438583814dfe6d96e7146cacf940ad8b7c0bcc0

I used version 2.0.0 available for the browser here: <script src="https://bundle.run/[email protected]"></script>

Publish transpiled version of package

Hi, could you please transpile code before publishing? Otherwise old browsers that only supports es5 get's broken.
Currently to workaround it, it should be transpiled by users of this lib.

{
          test: /\.jsx?$/,
          include: [path.resolve(__dirname, 'src'), /node_modules\/bech32/],
          use: 'babel-loader',
}

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.