Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bech32

Package Overview
Dependencies
Maintainers
3
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bech32 - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

71

index.js
'use strict'
let ALPHABET = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l'
var ALPHABET = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l'
// pre-compute lookup table
let ALPHABET_MAP = {}
for (let z = 0; z < ALPHABET.length; z++) {
let x = ALPHABET.charAt(z)
var ALPHABET_MAP = {}
for (var z = 0; z < ALPHABET.length; z++) {
var x = ALPHABET.charAt(z)

@@ -14,3 +14,3 @@ if (ALPHABET_MAP[x] !== undefined) throw new TypeError(x + ' is ambiguous')

function polymodStep (pre) {
let b = pre >> 25
var b = pre >> 25
return ((pre & 0x1FFFFFF) << 5) ^

@@ -25,5 +25,5 @@ (-((b >> 0) & 1) & 0x3b6a57b2) ^

function prefixChk (prefix) {
let chk = 1
for (let i = 0; i < prefix.length; ++i) {
let c = prefix.charCodeAt(i)
var chk = 1
for (var i = 0; i < prefix.length; ++i) {
var c = prefix.charCodeAt(i)
if (c < 33 || c > 126) throw new Error('Invalid prefix (' + prefix + ')')

@@ -35,4 +35,4 @@

for (let i = 0; i < prefix.length; ++i) {
let v = prefix.charCodeAt(i)
for (i = 0; i < prefix.length; ++i) {
var v = prefix.charCodeAt(i)
chk = polymodStep(chk) ^ (v & 0x1f)

@@ -50,6 +50,6 @@ }

// determine chk mod
let chk = prefixChk(prefix)
let result = prefix + '1'
for (let i = 0; i < words.length; ++i) {
let x = words[i]
var chk = prefixChk(prefix)
var result = prefix + '1'
for (var i = 0; i < words.length; ++i) {
var x = words[i]
if ((x >> 5) !== 0) throw new Error('Non 5-bit word')

@@ -61,3 +61,3 @@

for (let i = 0; i < 6; ++i) {
for (i = 0; i < 6; ++i) {
chk = polymodStep(chk)

@@ -67,4 +67,4 @@ }

for (let i = 0; i < 6; ++i) {
let v = (chk >> ((5 - i) * 5)) & 0x1f
for (i = 0; i < 6; ++i) {
var v = (chk >> ((5 - i) * 5)) & 0x1f
result += ALPHABET.charAt(v)

@@ -82,19 +82,19 @@ }

// don't allow mixed case
let lowered = str.toLowerCase()
let uppered = str.toUpperCase()
var lowered = str.toLowerCase()
var uppered = str.toUpperCase()
if (str !== lowered && str !== uppered) throw new Error('Mixed-case string ' + str)
str = lowered
let split = str.lastIndexOf('1')
var split = str.lastIndexOf('1')
if (split === 0) throw new Error('Missing prefix for ' + str)
let prefix = str.slice(0, split)
let wordChars = str.slice(split + 1)
var prefix = str.slice(0, split)
var wordChars = str.slice(split + 1)
if (wordChars.length < 6) throw new Error('Data too short')
let chk = prefixChk(prefix)
let words = []
for (let i = 0; i < wordChars.length; ++i) {
let c = wordChars.charAt(i)
let v = ALPHABET_MAP[c]
var chk = prefixChk(prefix)
var words = []
for (var i = 0; i < wordChars.length; ++i) {
var c = wordChars.charAt(i)
var v = ALPHABET_MAP[c]
if (v === undefined) throw new Error('Unknown character ' + c)

@@ -113,8 +113,8 @@ chk = polymodStep(chk) ^ v

function convert (data, inBits, outBits, pad) {
let value = 0
let bits = 0
let maxV = (1 << outBits) - 1
var value = 0
var bits = 0
var maxV = (1 << outBits) - 1
let result = []
for (let i = 0; i < data.length; ++i) {
var result = []
for (var i = 0; i < data.length; ++i) {
value = (value << inBits) | data[i]

@@ -149,2 +149,7 @@ bits += inBits

module.exports = { decode, encode, toWords, fromWords }
module.exports = {
decode: decode,
encode: encode,
toWords: toWords,
fromWords: fromWords
}
{
"name": "bech32",
"version": "1.1.0",
"version": "1.1.1",
"description": "Bech32 encoding / decoding",

@@ -5,0 +5,0 @@ "keywords": [

@@ -17,2 +17,6 @@ # bech32

// }
let words = bech32.toWords(Buffer.from('foobar', 'utf8'))
bech32.encode('foo', words)
// => 'foo1vehk7cnpwgry9h96'
```

@@ -19,0 +23,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc