Beta 7 with some repo names changed.

This commit is contained in:
Luis Fernando Molina committed 2020-11-15 13:05:19 +01:00
1 parent 0f7b40cca7
commit 963c19493a
3408 files changed
+462217 -15516

No files matched your search

+4273
View File
File diff suppressed because it is too large. Load diff
+3
View File
@@ -0,0 +1,3 @@
/*! For license information please see index.min.js.LICENSE.txt */
!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.Multihashes=n():e.Multihashes=n()}(window,(function(){return function(e){var n={};function t(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,t),i.l=!0,i.exports}return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},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,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var i in e)t.d(r,i,function(n){return e[n]}.bind(null,i));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=1)}([function(e,n,t){"use strict";(function(e){var r=t(4),i=t(5),o=t(6);function a(){return f.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function s(e,n){if(a()<n)throw new RangeError("Invalid typed array length");return f.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(n)).__proto__=f.prototype:(null===e&&(e=new f(n)),e.length=n),e}function f(e,n,t){if(!(f.TYPED_ARRAY_SUPPORT||this instanceof f))return new f(e,n,t);if("number"==typeof e){if("string"==typeof n)throw new Error("If encoding is specified then the first argument must be a string");return h(this,e)}return u(this,e,n,t)}function u(e,n,t,r){if("number"==typeof n)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&n instanceof ArrayBuffer?function(e,n,t,r){if(n.byteLength,t<0||n.byteLength<t)throw new RangeError("'offset' is out of bounds");if(n.byteLength<t+(r||0))throw new RangeError("'length' is out of bounds");n=void 0===t&&void 0===r?new Uint8Array(n):void 0===r?new Uint8Array(n,t):new Uint8Array(n,t,r);f.TYPED_ARRAY_SUPPORT?(e=n).__proto__=f.prototype:e=l(e,n);return e}(e,n,t,r):"string"==typeof n?function(e,n,t){"string"==typeof t&&""!==t||(t="utf8");if(!f.isEncoding(t))throw new TypeError('"encoding" must be a valid string encoding');var r=0|S(n,t),i=(e=s(e,r)).write(n,t);i!==r&&(e=e.slice(0,i));return e}(e,n,t):function(e,n){if(f.isBuffer(n)){var t=0|c(n.length);return 0===(e=s(e,t)).length||n.copy(e,0,0,t),e}if(n){if("undefined"!=typeof ArrayBuffer&&n.buffer instanceof ArrayBuffer||"length"in n)return"number"!=typeof n.length||(r=n.length)!=r?s(e,0):l(e,n);if("Buffer"===n.type&&o(n.data))return l(e,n.data)}var r;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,n)}function k(e){if("number"!=typeof e)throw new TypeError('"size" argument must be a number');if(e<0)throw new RangeError('"size" argument must not be negative')}function h(e,n){if(k(n),e=s(e,n<0?0:0|c(n)),!f.TYPED_ARRAY_SUPPORT)for(var t=0;t<n;++t)e[t]=0;return e}function l(e,n){var t=n.length<0?0:0|c(n.length);e=s(e,t);for(var r=0;r<t;r+=1)e[r]=255&n[r];return e}function c(e){if(e>=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|e}function S(e,n){if(f.isBuffer(e))return e.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;"string"!=typeof e&&(e=""+e);var t=e.length;if(0===t)return 0;for(var r=!1;;)switch(n){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":case void 0:return z(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*t;case"hex":return t>>>1;case"base64":return N(e).length;default:if(r)return z(e).length;n=(""+n).toLowerCase(),r=!0}}function b(e,n,t){var r=!1;if((void 0===n||n<0)&&(n=0),n>this.length)return"";if((void 0===t||t>this.length)&&(t=this.length),t<=0)return"";if((t>>>=0)<=(n>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return P(this,n,t);case"utf8":case"utf-8":return R(this,n,t);case"ascii":return B(this,n,t);case"latin1":case"binary":return T(this,n,t);case"base64":return _(this,n,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return U(this,n,t);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),r=!0}}function p(e,n,t){var r=e[n];e[n]=e[t],e[t]=r}function g(e,n,t,r,i){if(0===e.length)return-1;if("string"==typeof t?(r=t,t=0):t>2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,isNaN(t)&&(t=i?0:e.length-1),t<0&&(t=e.length+t),t>=e.length){if(i)return-1;t=e.length-1}else if(t<0){if(!i)return-1;t=0}if("string"==typeof n&&(n=f.from(n,r)),f.isBuffer(n))return 0===n.length?-1:d(e,n,t,r,i);if("number"==typeof n)return n&=255,f.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.iLine truncated
//# sourceMappingURL=index.min.js.map
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,3 @@
/*! For license information please see index.min.js.LICENSE.txt */
!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.Multibase=r():t.Multibase=r()}(window,(function(){return function(t){var r={};function e(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:n})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,r){if(1&r&&(t=e(t)),8&r)return t;if(4&r&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var o in t)e.d(n,o,function(r){return t[r]}.bind(null,o));return n},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},e.p="",e(e.s=1)}([function(t,r,e){"use strict";(function(t){var n=e(4),o=e(5),i=e(6);function f(){return s.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function u(t,r){if(f()<r)throw new RangeError("Invalid typed array length");return s.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(r)).__proto__=s.prototype:(null===t&&(t=new s(r)),t.length=r),t}function s(t,r,e){if(!(s.TYPED_ARRAY_SUPPORT||this instanceof s))return new s(t,r,e);if("number"==typeof t){if("string"==typeof r)throw new Error("If encoding is specified then the first argument must be a string");return c(this,t)}return a(this,t,r,e)}function a(t,r,e,n){if("number"==typeof r)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&r instanceof ArrayBuffer?function(t,r,e,n){if(r.byteLength,e<0||r.byteLength<e)throw new RangeError("'offset' is out of bounds");if(r.byteLength<e+(n||0))throw new RangeError("'length' is out of bounds");r=void 0===e&&void 0===n?new Uint8Array(r):void 0===n?new Uint8Array(r,e):new Uint8Array(r,e,n);s.TYPED_ARRAY_SUPPORT?(t=r).__proto__=s.prototype:t=l(t,r);return t}(t,r,e,n):"string"==typeof r?function(t,r,e){"string"==typeof e&&""!==e||(e="utf8");if(!s.isEncoding(e))throw new TypeError('"encoding" must be a valid string encoding');var n=0|g(r,e),o=(t=u(t,n)).write(r,e);o!==n&&(t=t.slice(0,o));return t}(t,r,e):function(t,r){if(s.isBuffer(r)){var e=0|p(r.length);return 0===(t=u(t,e)).length||r.copy(t,0,0,e),t}if(r){if("undefined"!=typeof ArrayBuffer&&r.buffer instanceof ArrayBuffer||"length"in r)return"number"!=typeof r.length||(n=r.length)!=n?u(t,0):l(t,r);if("Buffer"===r.type&&i(r.data))return l(t,r.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,r)}function h(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function c(t,r){if(h(r),t=u(t,r<0?0:0|p(r)),!s.TYPED_ARRAY_SUPPORT)for(var e=0;e<r;++e)t[e]=0;return t}function l(t,r){var e=r.length<0?0:0|p(r.length);t=u(t,e);for(var n=0;n<e;n+=1)t[n]=255&r[n];return t}function p(t){if(t>=f())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+f().toString(16)+" bytes");return 0|t}function g(t,r){if(s.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var e=t.length;if(0===e)return 0;for(var n=!1;;)switch(r){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":case void 0:return N(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*e;case"hex":return e>>>1;case"base64":return z(t).length;default:if(n)return N(t).length;r=(""+r).toLowerCase(),n=!0}}function y(t,r,e){var n=!1;if((void 0===r||r<0)&&(r=0),r>this.length)return"";if((void 0===e||e>this.length)&&(e=this.length),e<=0)return"";if((e>>>=0)<=(r>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return S(this,r,e);case"utf8":case"utf-8":return T(this,r,e);case"ascii":return P(this,r,e);case"latin1":case"binary":return U(this,r,e);case"base64":return B(this,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return x(this,r,e);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function d(t,r,e){var n=t[r];t[r]=t[e],t[e]=n}function w(t,r,e,n,o){if(0===t.length)return-1;if("string"==typeof e?(n=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),e=+e,isNaN(e)&&(e=o?0:t.length-1),e<0&&(e=t.length+e),e>=t.length){if(o)return-1;e=t.length-1}else if(e<0){if(!o)return-1;e=0}if("string"==typeof r&&(r=s.from(r,n)),s.isBuffer(r))return 0===r.length?-1:b(t,r,e,n,o);if("number"==typeof r)return r&=255,s.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexLine truncated
//# sourceMappingURL=index.min.js.map
+68
View File
@@ -0,0 +1,68 @@
{
"name": "multibase",
"version": "0.7.0",
"description": "JavaScript implementation of the multibase specification",
"leadMaintainer": "Oli Evans <oli@tableflip.io>",
"main": "src/index.js",
"scripts": {
"lint": "aegir lint",
"test": "aegir test",
"test:node": "aegir test -t node",
"test:browser": "aegir test -t browser",
"build": "aegir build",
"docs": "aegir docs",
"release": "aegir release --docs",
"release-minor": "aegir release --type minor --docs",
"release-major": "aegir release --type major --docs",
"coverage": "aegir coverage",
"coverage-publish": "aegir coverage publish"
},
"files": [
"src",
"dist"
],
"repository": {
"type": "git",
"url": "git+https://github.com/multiformats/js-multibase.git"
},
"keywords": [
"IPFS",
"multiformats",
"multibase",
"encode",
"decode",
"formats"
],
"devDependencies": {
"aegir": "^21.3.0",
"chai": "^4.1.2",
"dirty-chai": "^2.0.1",
"pre-commit": "^1.2.2"
},
"dependencies": {
"base-x": "^3.0.8",
"buffer": "^5.5.0"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/multiformats/js-multibase/issues"
},
"homepage": "https://github.com/multiformats/js-multibase#readme",
"contributors": [
"David Dias <daviddias.p@gmail.com>",
"Oli Evans <oli@tableflip.io>",
"Hugo Dias <hugomrdias@gmail.com>",
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
"Alan Shaw <alan.shaw@protocol.ai>",
"victorbjelkholm <victorbjelkholm@gmail.com>",
"achingbrain <alex@achingbrain.net>",
"theobat <theophile.batoz@gmail.com>",
"Bora M. Alper <boramalper@gmail.com>",
"Henrique Dias <hacdias@gmail.com>",
"Richard Littauer <richard.littauer@gmail.com>"
]
,"_resolved": "https://registry.npmjs.org/multibase/-/multibase-0.7.0.tgz"
,"_integrity": "sha512-TW8q03O0f6PNFTQDvh3xxH03c8CjGaaYrjkl9UQPG6rz53TQzzxJVCIWVjzcbN/Q5Y53Zd0IBQBMVktVgNx4Fg=="
,"_from": "multibase@^0.7.0"
}
+26
View File
@@ -0,0 +1,26 @@
'use strict'
class Base {
constructor (name, code, implementation, alphabet) {
this.name = name
this.code = code
this.alphabet = alphabet
if (implementation && alphabet) {
this.engine = implementation(alphabet)
}
}
encode (stringOrBuffer) {
return this.engine.encode(stringOrBuffer)
}
decode (stringOrBuffer) {
return this.engine.decode(stringOrBuffer)
}
isImplemented () {
return this.engine
}
}
module.exports = Base
+21
View File
@@ -0,0 +1,21 @@
'use strict'
const { Buffer } = require('buffer')
module.exports = function base16 (alphabet) {
return {
encode (input) {
if (typeof input === 'string') {
return Buffer.from(input).toString('hex')
}
return input.toString('hex')
},
decode (input) {
for (const char of input) {
if (alphabet.indexOf(char) < 0) {
throw new Error('invalid base16 character')
}
}
return Buffer.from(input, 'hex')
}
}
}
+81
View File
@@ -0,0 +1,81 @@
'use strict'
function decode (input, alphabet) {
input = input.replace(new RegExp('=', 'g'), '')
const length = input.length
let bits = 0
let value = 0
let index = 0
const output = new Uint8Array((length * 5 / 8) | 0)
for (let i = 0; i < length; i++) {
value = (value << 5) | alphabet.indexOf(input[i])
bits += 5
if (bits >= 8) {
output[index++] = (value >>> (bits - 8)) & 255
bits -= 8
}
}
return output.buffer
}
function encode (buffer, alphabet) {
const length = buffer.byteLength
const view = new Uint8Array(buffer)
const padding = alphabet.indexOf('=') === alphabet.length - 1
if (padding) {
alphabet = alphabet.substring(0, alphabet.length - 1)
}
let bits = 0
let value = 0
let output = ''
for (let i = 0; i < length; i++) {
value = (value << 8) | view[i]
bits += 8
while (bits >= 5) {
output += alphabet[(value >>> (bits - 5)) & 31]
bits -= 5
}
}
if (bits > 0) {
output += alphabet[(value << (5 - bits)) & 31]
}
if (padding) {
while ((output.length % 8) !== 0) {
output += '='
}
}
return output
}
module.exports = function base32 (alphabet) {
return {
encode (input) {
if (typeof input === 'string') {
return encode(Uint8Array.from(input), alphabet)
}
return encode(input, alphabet)
},
decode (input) {
for (const char of input) {
if (alphabet.indexOf(char) < 0) {
throw new Error('invalid base32 character')
}
}
return decode(input, alphabet)
}
}
}
+44
View File
@@ -0,0 +1,44 @@
'use strict'
const { Buffer } = require('buffer')
module.exports = function base64 (alphabet) {
// The alphabet is only used to know:
// 1. If padding is enabled (must contain '=')
// 2. If the output must be url-safe (must contain '-' and '_')
// 3. If the input of the output function is valid
// The alphabets from RFC 4648 are always used.
const padding = alphabet.indexOf('=') > -1
const url = alphabet.indexOf('-') > -1 && alphabet.indexOf('_') > -1
return {
encode (input) {
let output = ''
if (typeof input === 'string') {
output = Buffer.from(input).toString('base64')
} else {
output = input.toString('base64')
}
if (url) {
output = output.replace(/\+/g, '-').replace(/\//g, '_')
}
const pad = output.indexOf('=')
if (pad > 0 && !padding) {
output = output.substring(0, pad)
}
return output
},
decode (input) {
for (const char of input) {
if (alphabet.indexOf(char) < 0) {
throw new Error('invalid base64 character')
}
}
return Buffer.from(input, 'base64')
}
}
}
@@ -0,0 +1,42 @@
'use strict'
const Base = require('./base.js')
const baseX = require('base-x')
const base16 = require('./base16')
const base32 = require('./base32')
const base64 = require('./base64')
// name, code, implementation, alphabet
const constants = [
['base1', '1', '', '1'],
['base2', '0', baseX, '01'],
['base8', '7', baseX, '01234567'],
['base10', '9', baseX, '0123456789'],
['base16', 'f', base16, '0123456789abcdef'],
['base32', 'b', base32, 'abcdefghijklmnopqrstuvwxyz234567'],
['base32pad', 'c', base32, 'abcdefghijklmnopqrstuvwxyz234567='],
['base32hex', 'v', base32, '0123456789abcdefghijklmnopqrstuv'],
['base32hexpad', 't', base32, '0123456789abcdefghijklmnopqrstuv='],
['base32z', 'h', base32, 'ybndrfg8ejkmcpqxot1uwisza345h769'],
['base58flickr', 'Z', baseX, '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'],
['base58btc', 'z', baseX, '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'],
['base64', 'm', base64, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'],
['base64pad', 'M', base64, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='],
['base64url', 'u', base64, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'],
['base64urlpad', 'U', base64, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=']
]
const names = constants.reduce((prev, tupple) => {
prev[tupple[0]] = new Base(tupple[0], tupple[1], tupple[2], tupple[3])
return prev
}, {})
const codes = constants.reduce((prev, tupple) => {
prev[tupple[1]] = names[tupple[0]]
return prev
}, {})
module.exports = {
names: names,
codes: codes
}
+130
View File
@@ -0,0 +1,130 @@
/**
* Implementation of the [multibase](https://github.com/multiformats/multibase) specification.
* @module Multibase
*/
'use strict'
const { Buffer } = require('buffer')
const constants = require('./constants')
exports = module.exports = multibase
exports.encode = encode
exports.decode = decode
exports.isEncoded = isEncoded
exports.names = Object.freeze(Object.keys(constants.names))
exports.codes = Object.freeze(Object.keys(constants.codes))
/**
* Create a new buffer with the multibase varint+code.
*
* @param {string|number} nameOrCode - The multibase name or code number.
* @param {Buffer} buf - The data to be prefixed with multibase.
* @memberof Multibase
* @returns {Buffer}
*/
function multibase (nameOrCode, buf) {
if (!buf) {
throw new Error('requires an encoded buffer')
}
const base = getBase(nameOrCode)
const codeBuf = Buffer.from(base.code)
const name = base.name
validEncode(name, buf)
return Buffer.concat([codeBuf, buf])
}
/**
* Encode data with the specified base and add the multibase prefix.
*
* @param {string|number} nameOrCode - The multibase name or code number.
* @param {Buffer} buf - The data to be encoded.
* @returns {Buffer}
* @memberof Multibase
*/
function encode (nameOrCode, buf) {
const base = getBase(nameOrCode)
const name = base.name
return multibase(name, Buffer.from(base.encode(buf)))
}
/**
* Takes a buffer or string encoded with multibase header, decodes it and
* returns the decoded buffer
*
* @param {Buffer|string} bufOrString
* @returns {Buffer}
* @memberof Multibase
*
*/
function decode (bufOrString) {
if (Buffer.isBuffer(bufOrString)) {
bufOrString = bufOrString.toString()
}
const code = bufOrString.substring(0, 1)
bufOrString = bufOrString.substring(1, bufOrString.length)
if (typeof bufOrString === 'string') {
bufOrString = Buffer.from(bufOrString)
}
const base = getBase(code)
return Buffer.from(base.decode(bufOrString.toString()))
}
/**
* Is the given data multibase encoded?
*
* @param {Buffer|string} bufOrString
* @returns {boolean}
* @memberof Multibase
*/
function isEncoded (bufOrString) {
if (Buffer.isBuffer(bufOrString)) {
bufOrString = bufOrString.toString()
}
// Ensure bufOrString is a string
if (Object.prototype.toString.call(bufOrString) !== '[object String]') {
return false
}
const code = bufOrString.substring(0, 1)
try {
const base = getBase(code)
return base.name
} catch (err) {
return false
}
}
/**
* @param {string} name
* @param {Buffer} buf
* @private
* @returns {undefined}
*/
function validEncode (name, buf) {
const base = getBase(name)
base.decode(buf.toString())
}
function getBase (nameOrCode) {
let base
if (constants.names[nameOrCode]) {
base = constants.names[nameOrCode]
} else if (constants.codes[nameOrCode]) {
base = constants.codes[nameOrCode]
} else {
throw new Error('Unsupported encoding')
}
if (!base.isImplemented()) {
throw new Error('Base ' + nameOrCode + ' is not implemented yet')
}
return base
}
+158
View File
@@ -0,0 +1,158 @@
{
"_from": "multihashes@^0.4.15",
"_id": "multihashes@0.4.21",
"_inBundle": false,
"_integrity": "sha512-uVSvmeCWf36pU2nB4/1kzYZjsXD9vofZKpgudqkceYY5g2aZZXJ5r9lxuzoRLl1OAp28XljXsEJ/X/85ZsKmKw==",
"_location": "/multihashes",
"_phantomChildren": {
"base-x": "3.0.8",
"buffer": "5.7.1"
},
"_requested": {
"type": "range",
"registry": true,
"raw": "multihashes@^0.4.15",
"name": "multihashes",
"escapedName": "multihashes",
"rawSpec": "^0.4.15",
"saveSpec": null,
"fetchSpec": "^0.4.15"
},
"_requiredBy": [
"/cids",
"/content-hash"
],
"_resolved": "https://registry.npmjs.org/multihashes/-/multihashes-0.4.21.tgz",
"_shasum": "dc02d525579f334a7909ade8a122dabb58ccfcb5",
"_spec": "multihashes@^0.4.15",
"_where": "C:\\Users\\Luis\\source\\repos\\AAMasters\\BackendServers\\node_modules\\content-hash",
"bugs": {
"url": "https://github.com/multiformats/js-multihash/issues"
},
"bundleDependencies": false,
"contributors": [
{
"name": "David Dias",
"email": "daviddias.p@gmail.com"
},
{
"name": "Juan Benet",
"email": "juan@benet.ai"
},
{
"name": "Jacob Heun",
"email": "jacobheun@gmail.com"
},
{
"name": "Friedel Ziegelmayer",
"email": "dignifiedquire@gmail.com"
},
{
"name": "Richard Littauer",
"email": "richard.littauer@gmail.com"
},
{
"name": "Hugo Dias",
"email": "hugomrdias@gmail.com"
},
{
"name": "ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ",
"email": "victorbjelkholm@gmail.com"
},
{
"name": "Rod Vagg",
"email": "rod@vagg.org"
},
{
"name": "Pedro Teixeira",
"email": "i@pgte.me"
},
{
"name": "kumavis",
"email": "aaron@kumavis.me"
},
{
"name": "Alan Shaw",
"email": "alan@tableflip.io"
},
{
"name": "Fil",
"email": "fil@rezo.net"
},
{
"name": "Donald Tsang",
"email": "brandonknlee@gmail.com"
},
{
"name": "Trond Arne Bråthen",
"email": "tabrath@gmail.com"
},
{
"name": "Vasco Santos",
"email": "vasco.santos@moxy.studio"
},
{
"name": "Volker Mische",
"email": "volker.mische@gmail.com"
},
{
"name": "William Cotton",
"email": "williamcotton@gmail.com"
},
{
"name": "nginnever",
"email": "ginneversource@gmail.com"
},
{
"name": "Linus Unnebäck",
"email": "linus@folkdatorn.se"
},
{
"name": "Nate Foss",
"email": "npfoss@gmail.com"
}
],
"dependencies": {
"buffer": "^5.5.0",
"multibase": "^0.7.0",
"varint": "^5.0.0"
},
"deprecated": false,
"description": "multihash implementation",
"devDependencies": {
"aegir": "^21.4.4",
"chai": "^4.1.2",
"dirty-chai": "^2.0.1",
"pre-commit": "^1.2.2"
},
"files": [
"src",
"dist"
],
"homepage": "https://github.com/multiformats/js-multihash#readme",
"keywords": [
"multihash"
],
"leadMaintainer": "David Dias <daviddias@ipfs.io>",
"license": "MIT",
"main": "src/index.js",
"name": "multihashes",
"repository": {
"type": "git",
"url": "git://github.com/multiformats/js-multihash.git"
},
"scripts": {
"build": "aegir build",
"coverage": "aegir coverage",
"coverage-publish": "aegir coverage --provider coveralls",
"docs": "aegir docs",
"lint": "aegir lint",
"release": "aegir release --docs",
"release-major": "aegir release --type major --docs",
"release-minor": "aegir release --type minor --docs",
"test": "aegir test",
"test:browser": "aegir test --target browser",
"test:node": "aegir test --target node"
},
"version": "0.4.21"
}
+1034
View File
File diff suppressed because it is too large. Load diff
+224
View File
@@ -0,0 +1,224 @@
/**
* Multihash implementation in JavaScript.
*
* @module multihash
*/
'use strict'
const { Buffer } = require('buffer')
const multibase = require('multibase')
const varint = require('varint')
const cs = require('./constants')
exports.names = cs.names
exports.codes = cs.codes
exports.defaultLengths = cs.defaultLengths
/**
* Convert the given multihash to a hex encoded string.
*
* @param {Buffer} hash
* @returns {string}
*/
exports.toHexString = function toHexString (hash) {
if (!Buffer.isBuffer(hash)) {
throw new Error('must be passed a buffer')
}
return hash.toString('hex')
}
/**
* Convert the given hex encoded string to a multihash.
*
* @param {string} hash
* @returns {Buffer}
*/
exports.fromHexString = function fromHexString (hash) {
return Buffer.from(hash, 'hex')
}
/**
* Convert the given multihash to a base58 encoded string.
*
* @param {Buffer} hash
* @returns {string}
*/
exports.toB58String = function toB58String (hash) {
if (!Buffer.isBuffer(hash)) {
throw new Error('must be passed a buffer')
}
return multibase.encode('base58btc', hash).toString().slice(1)
}
/**
* Convert the given base58 encoded string to a multihash.
*
* @param {string|Buffer} hash
* @returns {Buffer}
*/
exports.fromB58String = function fromB58String (hash) {
let encoded = hash
if (Buffer.isBuffer(hash)) {
encoded = hash.toString()
}
return multibase.decode('z' + encoded)
}
/**
* Decode a hash from the given multihash.
*
* @param {Buffer} buf
* @returns {{code: number, name: string, length: number, digest: Buffer}} result
*/
exports.decode = function decode (buf) {
if (!(Buffer.isBuffer(buf))) {
throw new Error('multihash must be a Buffer')
}
if (buf.length < 2) {
throw new Error('multihash too short. must be > 2 bytes.')
}
const code = varint.decode(buf)
if (!exports.isValidCode(code)) {
throw new Error(`multihash unknown function code: 0x${code.toString(16)}`)
}
buf = buf.slice(varint.decode.bytes)
const len = varint.decode(buf)
if (len < 0) {
throw new Error(`multihash invalid length: ${len}`)
}
buf = buf.slice(varint.decode.bytes)
if (buf.length !== len) {
throw new Error(`multihash length inconsistent: 0x${buf.toString('hex')}`)
}
return {
code: code,
name: cs.codes[code],
length: len,
digest: buf
}
}
/**
* Encode a hash digest along with the specified function code.
*
* > **Note:** the length is derived from the length of the digest itself.
*
* @param {Buffer} digest
* @param {string|number} code
* @param {number} [length]
* @returns {Buffer}
*/
exports.encode = function encode (digest, code, length) {
if (!digest || code === undefined) {
throw new Error('multihash encode requires at least two args: digest, code')
}
// ensure it's a hashfunction code.
const hashfn = exports.coerceCode(code)
if (!(Buffer.isBuffer(digest))) {
throw new Error('digest should be a Buffer')
}
if (length == null) {
length = digest.length
}
if (length && digest.length !== length) {
throw new Error('digest length should be equal to specified length.')
}
return Buffer.concat([
Buffer.from(varint.encode(hashfn)),
Buffer.from(varint.encode(length)),
digest
])
}
/**
* Converts a hash function name into the matching code.
* If passed a number it will return the number if it's a valid code.
* @param {string|number} name
* @returns {number}
*/
exports.coerceCode = function coerceCode (name) {
let code = name
if (typeof name === 'string') {
if (cs.names[name] === undefined) {
throw new Error(`Unrecognized hash function named: ${name}`)
}
code = cs.names[name]
}
if (typeof code !== 'number') {
throw new Error(`Hash function code should be a number. Got: ${code}`)
}
if (cs.codes[code] === undefined && !exports.isAppCode(code)) {
throw new Error(`Unrecognized function code: ${code}`)
}
return code
}
/**
* Checks wether a code is part of the app range
*
* @param {number} code
* @returns {boolean}
*/
exports.isAppCode = function appCode (code) {
return code > 0 && code < 0x10
}
/**
* Checks whether a multihash code is valid.
*
* @param {number} code
* @returns {boolean}
*/
exports.isValidCode = function validCode (code) {
if (exports.isAppCode(code)) {
return true
}
if (cs.codes[code]) {
return true
}
return false
}
/**
* Check if the given buffer is a valid multihash. Throws an error if it is not valid.
*
* @param {Buffer} multihash
* @returns {undefined}
* @throws {Error}
*/
function validate (multihash) {
exports.decode(multihash) // throws if bad.
}
exports.validate = validate
/**
* Returns a prefix from a valid multihash. Throws an error if it is not valid.
*
* @param {Buffer} multihash
* @returns {undefined}
* @throws {Error}
*/
exports.prefix = function prefix (multihash) {
validate(multihash)
return multihash.slice(0, 2)
}