Socket
Socket
Sign inDemoInstall

multibase

Package Overview
Dependencies
Maintainers
5
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multibase - npm Package Compare versions

Comparing version 3.0.1 to 3.0.2-rc.0

dist/src/base.d.ts

9

CHANGELOG.md

@@ -0,1 +1,10 @@

## [3.0.2-rc.0](https://github.com/multiformats/js-multibase/compare/v3.0.1...v3.0.2-rc.0) (2020-11-18)
### Features
* add ts types ([53f0001](https://github.com/multiformats/js-multibase/commit/53f00013b8e61279bc7c0ea223a9a36bc29d3b00))
<a name="3.0.1"></a>

@@ -2,0 +11,0 @@ ## [3.0.1](https://github.com/multiformats/js-multibase/compare/v3.0.0...v3.0.1) (2020-09-18)

2

dist/index.min.js

@@ -1,1 +0,1 @@

!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.Multibase=r():e.Multibase=r()}(window,(function(){return function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=1)}([function(e,r,t){"use strict";const{TextEncoder:n,TextDecoder:o}=t(6),c=new o,a=new n;e.exports={decodeText:e=>c.decode(e),encodeText:e=>a.encode(e),concat:function(e,r){const t=new Uint8Array(r);let n=0;for(const o of e)t.set(o,n),n+=o.length;return t}}},function(e,r,t){e.exports=t(2)},function(e,r,t){"use strict";const n=t(3),{encodeText:o,decodeText:c,concat:a}=t(0);function i(e){if(n.names[e])return n.names[e];if(n.codes[e])return n.codes[e];throw new Error("Unsupported encoding: "+e)}(r=e.exports=function(e,r){if(!r)throw new Error("requires an encoded Uint8Array");const{name:t,codeBuf:n}=i(e);return function(e,r){i(e).decode(c(r))}(t,r),a([n,r],n.length+r.length)}).encode=function(e,r){const t=i(e),n=o(t.encode(r));return a([t.codeBuf,n],t.codeBuf.length+n.length)},r.decode=function(e){e instanceof Uint8Array&&(e=c(e));const r=e[0];return["f","F","v","V","t","T","b","B","c","C","h","k","K"].includes(r)&&(e=e.toLowerCase()),i(e[0]).decode(e.substring(1))},r.isEncoded=function(e){if(e instanceof Uint8Array&&(e=c(e)),"[object String]"!==Object.prototype.toString.call(e))return!1;try{return i(e[0]).name}catch(r){return!1}},r.encoding=i,r.encodingFromData=function(e){return e instanceof Uint8Array&&(e=c(e)),i(e[0])},r.names=Object.freeze(n.names),r.codes=Object.freeze(n.codes)},function(e,r,t){"use strict";const n=t(4),o=t(5),c=t(7),{decodeText:a,encodeText:i}=t(0),f=[["identity","\0",()=>({encode:a,decode:i}),""],["base2","0",c(1),"01"],["base8","7",c(3),"01234567"],["base10","9",n,"0123456789"],["base16","f",c(4),"0123456789abcdef"],["base16upper","F",c(4),"0123456789ABCDEF"],["base32hex","v",c(5),"0123456789abcdefghijklmnopqrstuv"],["base32hexupper","V",c(5),"0123456789ABCDEFGHIJKLMNOPQRSTUV"],["base32hexpad","t",c(5),"0123456789abcdefghijklmnopqrstuv="],["base32hexpadupper","T",c(5),"0123456789ABCDEFGHIJKLMNOPQRSTUV="],["base32","b",c(5),"abcdefghijklmnopqrstuvwxyz234567"],["base32upper","B",c(5),"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"],["base32pad","c",c(5),"abcdefghijklmnopqrstuvwxyz234567="],["base32padupper","C",c(5),"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567="],["base32z","h",c(5),"ybndrfg8ejkmcpqxot1uwisza345h769"],["base36","k",n,"0123456789abcdefghijklmnopqrstuvwxyz"],["base36upper","K",n,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"],["base58btc","z",n,"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"],["base58flickr","Z",n,"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"],["base64","m",c(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"],["base64pad","M",c(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="],["base64url","u",c(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"],["base64urlpad","U",c(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_="]],s=f.reduce((e,r)=>(e[r[0]]=new o(r[0],r[1],r[2],r[3]),e),{}),u=f.reduce((e,r)=>(e[r[1]]=s[r[0]],e),{});e.exports={names:s,codes:u}},function(e,r,t){"use strict";e.exports=function(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),t=0;t<r.length;t++)r[t]=255;for(var n=0;n<e.length;n++){var o=e.charAt(n),c=o.charCodeAt(0);if(255!==r[c])throw new TypeError(o+" is ambiguous");r[c]=n}var a=e.length,i=e.charAt(0),f=Math.log(a)/Math.log(256),s=Math.log(256)/Math.log(a);function u(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return new Uint8Array;var t=0;if(" "!==e[t]){for(var n=0,o=0;e[t]===i;)n++,t++;for(var c=(e.length-t)*f+1>>>0,s=new Uint8Array(c);e[t];){var u=r[e.charCodeAt(t)];if(255===u)return;for(var d=0,l=c-1;(0!==u||d<o)&&-1!==l;l--,d++)u+=a*s[l]>>>0,s[l]=u%256>>>0,u=u/256>>>0;if(0!==u)throw new Error("Non-zero carry");o=d,t++}if(" "!==e[t]){for(var p=c-o;p!==c&&0===s[p];)p++;for(var h=new Uint8Array(n+(c-p)),b=n;p!==c;)h[b++]=s[p++];return h}}}return{encode:function(r){if(r instanceof Uint8Array||(ArrayBuffer.isView(r)?r=new Uint8Array(r.buffer,r.byteOffset,r.byteLength):Array.isArray(r)&&(r=Uint8Array.from(r))),!(r instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===r.length)return"";for(var t=0,n=0,o=0,c=r.length;o!==c&&0===r[o];)o++,t++;for(var f=(c-o)*s+1>>>0,u=new Uint8Array(f);o!==c;){for(var d=r[o],l=0,p=f-1;(0!==d||l<n)&&-1!==p;p--,l++)d+=256*u[p]>>>0,u[p]=d%a>>>0,d=d/a>>>0;if(0!==d)throw new Error("Non-zero carry");n=l,o++}for(var h=f-n;h!==f&&0===u[h];)h++;for(var b=i.repeat(t);h<f;++h)b+=e.charAt(u[h]);return b},decodeUnsafe:u,decode:function(e){var r=u(e);if(r)return r;throw new Error("Non-base"+a+" character")}}}},function(e,r,t){"use strict";const{encodeText:n}=t(0);e.exports=class{constructor(e,r,t,o){this.name=e,this.code=r,this.codeBuf=n(this.code),this.alphabet=o,this.engine=t(o)}encode(e){return this.engine.encode(e)}decode(e){for(const r of e)if(this.alphabet&&this.alphabet.indexOf(r)<0)throw new Error(`invalid character '${r}' in '${e}'`);return this.engine.decode(e)}}},function(e,r,t){"use strict";r.TextEncoder=TextEncoder,r.TextDecoder=TextDecoder},function(e,r,t){"use strict";e.exports=e=>r=>({encode:t=>((e,r,t)=>{const n="="===r[r.length-1],o=(1<<t)-1;let c="",a=0,i=0;for(let f=0;f<e.length;++f)for(i=i<<8|e[f],a+=8;a>t;)a-=t,c+=r[o&i>>a];if(a&&(c+=r[o&i<<t-a]),n)for(;c.length*t&7;)c+="=";return c})(t,r,e),decode:t=>((e,r,t)=>{const n={};for(let s=0;s<r.length;++s)n[r[s]]=s;let o=e.length;for(;"="===e[o-1];)--o;const c=new Uint8Array(o*t/8|0);let a=0,i=0,f=0;for(let s=0;s<o;++s){const r=n[e[s]];if(void 0===r)throw new SyntaxError("Invalid character "+e[s]);i=i<<t|r,a+=t,a>=8&&(a-=8,c[f++]=255&i>>a)}if(a>=t||255&i<<8-a)throw new SyntaxError("Unexpected end of data");return c})(t,r,e)})}])}));
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.Multibase=r():e.Multibase=r()}(self,(function(){return function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=1)}([function(e,r,t){"use strict";const{TextEncoder:n,TextDecoder:o}=t(6),c=new o,a=new n;e.exports={decodeText:e=>c.decode(e),encodeText:e=>a.encode(e),concat:function(e,r){const t=new Uint8Array(r);let n=0;for(const o of e)t.set(o,n),n+=o.length;return t}}},function(e,r,t){e.exports=t(2)},function(e,r,t){"use strict";const n=t(3),{encodeText:o,decodeText:c,concat:a}=t(0);function i(e){if(n.names[e])return n.names[e];if(n.codes[e])return n.codes[e];throw new Error("Unsupported encoding: "+e)}(r=e.exports=function(e,r){if(!r)throw new Error("requires an encoded Uint8Array");const{name:t,codeBuf:n}=i(e);return function(e,r){i(e).decode(c(r))}(t,r),a([n,r],n.length+r.length)}).encode=function(e,r){const t=i(e),n=o(t.encode(r));return a([t.codeBuf,n],t.codeBuf.length+n.length)},r.decode=function(e){e instanceof Uint8Array&&(e=c(e));const r=e[0];return["f","F","v","V","t","T","b","B","c","C","h","k","K"].includes(r)&&(e=e.toLowerCase()),i(e[0]).decode(e.substring(1))},r.isEncoded=function(e){if(e instanceof Uint8Array&&(e=c(e)),"[object String]"!==Object.prototype.toString.call(e))return!1;try{return i(e[0]).name}catch(r){return!1}},r.encoding=i,r.encodingFromData=function(e){return e instanceof Uint8Array&&(e=c(e)),i(e[0])},r.names=Object.freeze(n.names),r.codes=Object.freeze(n.codes)},function(e,r,t){"use strict";const n=t(4),o=t(5),{rfc4648:c}=t(7),{decodeText:a,encodeText:i}=t(0),f=[["identity","\0",()=>({encode:a,decode:i}),""],["base2","0",c(1),"01"],["base8","7",c(3),"01234567"],["base10","9",n,"0123456789"],["base16","f",c(4),"0123456789abcdef"],["base16upper","F",c(4),"0123456789ABCDEF"],["base32hex","v",c(5),"0123456789abcdefghijklmnopqrstuv"],["base32hexupper","V",c(5),"0123456789ABCDEFGHIJKLMNOPQRSTUV"],["base32hexpad","t",c(5),"0123456789abcdefghijklmnopqrstuv="],["base32hexpadupper","T",c(5),"0123456789ABCDEFGHIJKLMNOPQRSTUV="],["base32","b",c(5),"abcdefghijklmnopqrstuvwxyz234567"],["base32upper","B",c(5),"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"],["base32pad","c",c(5),"abcdefghijklmnopqrstuvwxyz234567="],["base32padupper","C",c(5),"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567="],["base32z","h",c(5),"ybndrfg8ejkmcpqxot1uwisza345h769"],["base36","k",n,"0123456789abcdefghijklmnopqrstuvwxyz"],["base36upper","K",n,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"],["base58btc","z",n,"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"],["base58flickr","Z",n,"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"],["base64","m",c(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"],["base64pad","M",c(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="],["base64url","u",c(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"],["base64urlpad","U",c(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_="]],s=f.reduce((e,r)=>(e[r[0]]=new o(r[0],r[1],r[2],r[3]),e),{}),u=f.reduce((e,r)=>(e[r[1]]=s[r[0]],e),{});e.exports={names:s,codes:u}},function(e,r,t){"use strict";e.exports=function(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),t=0;t<r.length;t++)r[t]=255;for(var n=0;n<e.length;n++){var o=e.charAt(n),c=o.charCodeAt(0);if(255!==r[c])throw new TypeError(o+" is ambiguous");r[c]=n}var a=e.length,i=e.charAt(0),f=Math.log(a)/Math.log(256),s=Math.log(256)/Math.log(a);function u(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return new Uint8Array;var t=0;if(" "!==e[t]){for(var n=0,o=0;e[t]===i;)n++,t++;for(var c=(e.length-t)*f+1>>>0,s=new Uint8Array(c);e[t];){var u=r[e.charCodeAt(t)];if(255===u)return;for(var d=0,l=c-1;(0!==u||d<o)&&-1!==l;l--,d++)u+=a*s[l]>>>0,s[l]=u%256>>>0,u=u/256>>>0;if(0!==u)throw new Error("Non-zero carry");o=d,t++}if(" "!==e[t]){for(var p=c-o;p!==c&&0===s[p];)p++;for(var h=new Uint8Array(n+(c-p)),b=n;p!==c;)h[b++]=s[p++];return h}}}return{encode:function(r){if(r instanceof Uint8Array||(ArrayBuffer.isView(r)?r=new Uint8Array(r.buffer,r.byteOffset,r.byteLength):Array.isArray(r)&&(r=Uint8Array.from(r))),!(r instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===r.length)return"";for(var t=0,n=0,o=0,c=r.length;o!==c&&0===r[o];)o++,t++;for(var f=(c-o)*s+1>>>0,u=new Uint8Array(f);o!==c;){for(var d=r[o],l=0,p=f-1;(0!==d||l<n)&&-1!==p;p--,l++)d+=256*u[p]>>>0,u[p]=d%a>>>0,d=d/a>>>0;if(0!==d)throw new Error("Non-zero carry");n=l,o++}for(var h=f-n;h!==f&&0===u[h];)h++;for(var b=i.repeat(t);h<f;++h)b+=e.charAt(u[h]);return b},decodeUnsafe:u,decode:function(e){var r=u(e);if(r)return r;throw new Error("Non-base"+a+" character")}}}},function(e,r,t){"use strict";const{encodeText:n}=t(0);e.exports=class{constructor(e,r,t,o){this.name=e,this.code=r,this.codeBuf=n(this.code),this.alphabet=o,this.codec=t(o)}encode(e){return this.codec.encode(e)}decode(e){for(const r of e)if(this.alphabet&&this.alphabet.indexOf(r)<0)throw new Error(`invalid character '${r}' in '${e}'`);return this.codec.decode(e)}}},function(e,r,t){"use strict";r.TextEncoder=TextEncoder,r.TextDecoder=TextDecoder},function(e,r,t){"use strict";e.exports={rfc4648:e=>r=>({encode:t=>((e,r,t)=>{const n="="===r[r.length-1],o=(1<<t)-1;let c="",a=0,i=0;for(let f=0;f<e.length;++f)for(i=i<<8|e[f],a+=8;a>t;)a-=t,c+=r[o&i>>a];if(a&&(c+=r[o&i<<t-a]),n)for(;c.length*t&7;)c+="=";return c})(t,r,e),decode:t=>((e,r,t)=>{const n={};for(let s=0;s<r.length;++s)n[r[s]]=s;let o=e.length;for(;"="===e[o-1];)--o;const c=new Uint8Array(o*t/8|0);let a=0,i=0,f=0;for(let s=0;s<o;++s){const r=n[e[s]];if(void 0===r)throw new SyntaxError("Invalid character "+e[s]);i=i<<t|r,a+=t,a>=8&&(a-=8,c[f++]=255&i>>a)}if(a>=t||255&i<<8-a)throw new SyntaxError("Unexpected end of data");return c})(t,r,e)})}}])}));
{
"name": "multibase",
"version": "3.0.1",
"version": "3.0.2-rc.0",
"description": "JavaScript implementation of the multibase specification",

@@ -38,6 +38,6 @@ "keywords": [

"@multiformats/base-x": "^4.0.1",
"web-encoding": "^1.0.2"
"web-encoding": "^1.0.4"
},
"devDependencies": {
"aegir": "^26.0.0",
"aegir": "github:ipfs/aegir#feat/ts-cmd",
"benchmark": "^2.1.4"

@@ -50,4 +50,12 @@ },

"eslintConfig": {
"extends": "./node_modules/aegir/src/config/eslintrc.js"
"extends": "ipfs"
},
"types": "./dist/src/index.d.ts",
"typesVersions": {
"*": {
"src/*": [
"dist/src/*"
]
}
},
"contributors": [

@@ -58,13 +66,13 @@ "David Dias <daviddias.p@gmail.com>",

"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
"Volker Mische <volker.mische@gmail.com>",
"Alan Shaw <alan.shaw@protocol.ai>",
"Alex Potsides <alex@achingbrain.net>",
"Irakli Gozalishvili <contact@gozala.io>",
"Volker Mische <volker.mische@gmail.com>",
"victorbjelkholm <victorbjelkholm@gmail.com>",
"Bora M. Alper <boramalper@gmail.com>",
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>",
"Richard Littauer <richard.littauer@gmail.com>",
"theobat <theophile.batoz@gmail.com>",
"Henrique Dias <hacdias@gmail.com>",
"Carson Farmer <carson.farmer@gmail.com>",
"Henrique Dias <hacdias@gmail.com>",
"Richard Littauer <richard.littauer@gmail.com>",
"theobat <theophile.batoz@gmail.com>"
"Bora M. Alper <boramalper@gmail.com>"
]
}

@@ -1,2 +0,2 @@

js-multibase
js-multibase <!-- omit in toc -->
============

@@ -7,29 +7,20 @@

[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](https://webchat.freenode.net/?channels=%23ipfs)
[![Dependency Status](https://david-dm.org/multiformats/js-multibase.svg?style=flat-square)](https://david-dm.org/multiformats/js-multibase)
[![codecov](https://img.shields.io/codecov/c/github/multiformats/js-multibase.svg?style=flat-square)](https://codecov.io/gh/multiformats/js-multibase)
[![Travis CI](https://flat.badgen.net/travis/multiformats/js-multibase)](https://travis-ci.com/multiformats/js-multibase)
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/multiformats/js-multibase/ci?label=ci&style=flat-square)](https://github.com/multiformats/js-multibase/actions?query=branch%3Amaster+workflow%3Aci+)
> JavaScript implementation of the [multibase](https://github.com/multiformats/multibase) specification
## Lead Maintainer
## Lead Maintainer <!-- omit in toc -->
[Hugo Dias](https://github.com/hugomrdias)
## Table of Contents
## Table of Contents <!-- omit in toc -->
- [Install](#install)
- [NPM](#npm)
- [In the Browser through `<script>` tag](#in-the-browser-through-script-tag)
- [Browser through `<script>` tag](#browser-through-script-tag)
- [Usage](#usage)
- [Example](#example)
- [API](#api)
- [`multibase` - Prefixes an encoded Uint8Array with its multibase code](#multibase---prefixes-an-encoded-Uint8Array-with-its-multibase-code)
- [`multibase.encode` - Encodes Uint8Array into one of the supported encodings, prefixing it with the multibase code](#multibaseencode---encodes-Uint8Array-into-one-of-the-supported-encodings-prefixing-it-with-the-multibase-code)
- [`multibase.decode` - Decodes Uint8Array or string](#multibasedecode---decodes-Uint8Array-or-string)
- [`multibase.isEncoded` - Checks if Uint8Array or string is encoded](#multibaseisencoded---checks-if-Uint8Array-or-string-is-encoded)
- [`multibase.names` - Supported base encoding names](#multibasenames)
- [`multibase.codes` - Supported base encoding codes](#multibasecodes)
- [Supported Encodings, see `src/constants.js`](#supported-encodings-see-srcconstantsjs)
- [Architecture and Encoding/Decoding](#architecture-and-encodingdecoding)
- [Adding additional bases](#adding-additional-bases)
- [Contribute](#contribute)
- [License](#license)

@@ -45,10 +36,4 @@

The type definitions for this package are available on http://definitelytyped.org/. To install just use:
### Browser through `<script>` tag
```sh
$ npm install -D @types/multibase
```
### In the Browser through `<script>` tag
Loading this module through a script tag will make the ```Multibase``` obj available in the global namespace.

@@ -77,51 +62,2 @@

#### `multibase` - Prefixes an encoded Uint8Array with its multibase code
```
const multibased = multibase(<nameOrCode>, encodedBytes)
```
#### `multibase.encode` - Encodes Uint8Array into one of the supported encodings, prefixing it with the multibase code
```JavaScript
const encodedBuf = multibase.encode(<nameOrCode>, <bytes>)
```
#### `multibase.decode` - Decodes Uint8Array or string
```JavaScript
const decodedBuf = multibase.decode(bufOrString)
```
#### `multibase.isEncoded` - Checks if Uint8Array or string is encoded
```JavaScript
const value = multibase.isEncoded(bytesOrString)
// value is the name of the encoding if it is encoded, false otherwise
```
#### `multibase.encoding` - Get the encoding by name or code
```JavaScript
const value = multibase.encoding(nameOrCode)
// value is an instance of the corresponding `Base`
```
#### `multibase.encodingFromData` - Get the encoding from data either a `string` or `Uint8Array`
```JavaScript
const value = multibase.encodingFromData(data)
// value is an instance of the corresponding `Base`
```
#### `multibase.names`
A frozen `Object` of supported base encoding names mapped to the corresponding `Base` instance.
#### `multibase.codes`
A frozen `Object` of supported base encoding codes mapped to the corresponding `Base` instance.
### Supported Encodings, see [`src/constants.js`](/src/constants.js)
## Contribute

@@ -128,0 +64,0 @@

@@ -1,2 +0,1 @@

// @ts-check
'use strict'

@@ -6,18 +5,18 @@

/** @typedef {import('./types').CodecFactory} CodecFactory */
/** @typedef {import("./types").BaseNames} BaseNames */
/** @typedef {import("./types").BaseCodes} BaseCodes */
/**
* @typedef {Object} Codec
* @property {function(Uint8Array):string} encode
* @property {function(string):Uint8Array} decode
* Class
*
* @typedef {function(string):Codec} CodecFactory
*/
class Base {
/**
* @param {string} name
* @param {string} code
* @param {CodecFactory} implementation
* @param {BaseNames} name
* @param {BaseCodes} code
* @param {CodecFactory} factory
* @param {string} alphabet
*/
constructor (name, code, implementation, alphabet) {
constructor (name, code, factory, alphabet) {
this.name = name

@@ -27,3 +26,3 @@ this.code = code

this.alphabet = alphabet
this.engine = implementation(alphabet)
this.codec = factory(alphabet)
}

@@ -36,3 +35,3 @@

encode (buf) {
return this.engine.encode(buf)
return this.codec.encode(buf)
}

@@ -50,3 +49,3 @@

}
return this.engine.decode(string)
return this.codec.decode(string)
}

@@ -53,0 +52,0 @@ }

@@ -1,2 +0,1 @@

// @ts-check
'use strict'

@@ -6,5 +5,11 @@

const Base = require('./base.js')
const rfc4648 = require('./rfc4648')
const { rfc4648 } = require('./rfc4648')
const { decodeText, encodeText } = require('./util')
/** @typedef {import('./types').CodecFactory} CodecFactory */
/** @typedef {import('./types').Codec} Codec */
/** @typedef {import('./types').BaseNames} BaseNames */
/** @typedef {import('./types').BaseCodes} BaseCodes */
/** @type {CodecFactory} */
const identity = () => {

@@ -18,6 +23,6 @@ return {

/**
* @typedef {import('./base').CodecFactory} CodecFactory
*
* name, code, implementation, alphabet
* @type {Array<[string, string, CodecFactory, string]>}
*
* @type {Array<[BaseNames, BaseCodes, CodecFactory, string]>}
*/

@@ -50,11 +55,13 @@ const constants = [

/** @type {Record<BaseNames,Base>} */
const names = constants.reduce((prev, tupple) => {
prev[tupple[0]] = new Base(tupple[0], tupple[1], tupple[2], tupple[3])
return prev
}, {})
}, /** @type {Record<BaseNames,Base>} */({}))
/** @type {Record<BaseCodes,Base>} */
const codes = constants.reduce((prev, tupple) => {
prev[tupple[1]] = names[tupple[0]]
return prev
}, {})
}, /** @type {Record<BaseCodes,Base>} */({}))

@@ -61,0 +68,0 @@ module.exports = {

@@ -1,6 +0,4 @@

// @ts-check
/**
* Implementation of the [multibase](https://github.com/multiformats/multibase) specification.
*
* @module Multibase
*/

@@ -12,3 +10,5 @@ 'use strict'

/** @typedef {import("./base")} Base */
/** @typedef {import('./base')} Base */
/** @typedef {import("./types").BaseNamesCodes} BaseNamesCodes */
/** @typedef {import("./types").BaseCodes} BaseCodes */

@@ -18,3 +18,3 @@ /**

*
* @param {string|number} nameOrCode - The multibase name or code number.
* @param {BaseNamesCodes} nameOrCode - The multibase name or code number.
* @param {Uint8Array} buf - The data to be prefixed with multibase.

@@ -37,3 +37,3 @@ * @returns {Uint8Array}

*
* @param {string|number} nameOrCode - The multibase name or code number.
* @param {BaseNamesCodes} nameOrCode - The multibase name or code number.
* @param {Uint8Array} buf - The data to be encoded.

@@ -70,3 +70,3 @@ * @returns {Uint8Array}

}
const enc = encoding(data[0])
const enc = encoding(/** @type {BaseCodes} */(data[0]))
return enc.decode(data.substring(1))

@@ -79,3 +79,3 @@ }

* @param {Uint8Array|string} data
* @returns {false|string}
* @returns {boolean | string}
*/

@@ -93,3 +93,3 @@ function isEncoded (data) {

try {
const enc = encoding(data[0])
const enc = encoding(/** @type {BaseCodes} */(data[0]))
return enc.name

@@ -104,3 +104,3 @@ } catch (err) {

*
* @param {string} name
* @param {BaseNamesCodes} name
* @param {Uint8Array} buf

@@ -118,3 +118,3 @@ * @returns {void}

*
* @param {string|number} nameOrCode
* @param {BaseNamesCodes} nameOrCode
* @returns {Base}

@@ -145,3 +145,3 @@ * @throws {Error} Will throw if the encoding is not supported

return encoding(data[0])
return encoding(/** @type {BaseCodes} */(data[0]))
}

@@ -148,0 +148,0 @@

@@ -1,5 +0,4 @@

// @ts-check
'use strict'
/** @typedef {import('./base').CodecFactory} CodecFactory */
/** @typedef {import('./types').CodecFactory} CodecFactory */

@@ -99,6 +98,8 @@ /**

/**
* RFC4648 Factory
*
* @param {number} bitsPerChar
* @returns {CodecFactory}
*/
module.exports = (bitsPerChar) => (alphabet) => {
const rfc4648 = (bitsPerChar) => (alphabet) => {
return {

@@ -121,1 +122,3 @@ /**

}
module.exports = { rfc4648 }

@@ -1,4 +0,4 @@

// @ts-check
'use strict'
// @ts-ignore
const { TextEncoder, TextDecoder } = require('web-encoding')

@@ -23,4 +23,4 @@

*
* @param {Array<ArrayLike<Number>>} arrs
* @param {Number} length
* @param {Array<ArrayLike<number>>} arrs
* @param {number} length
* @returns {Uint8Array}

@@ -27,0 +27,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