multiformats
Advanced tools
Comparing version 0.0.11 to 1.0.0
/* globals btoa, atob */ | ||
exports.encode = b => btoa([].reduce.call(b, (p, c) => p + String.fromCharCode(c), '')) | ||
exports.decode = str => Uint8Array.from(atob(str), c => c.charCodeAt(0)) | ||
const encode = b => btoa([].reduce.call(b, (p, c) => p + String.fromCharCode(c), '')) | ||
const decode = str => Uint8Array.from(atob(str), c => c.charCodeAt(0)) | ||
const __browser = true | ||
export { encode, decode, __browser } |
@@ -1,3 +0,5 @@ | ||
const { coerce } = require('../bytes') | ||
exports.encode = o => Buffer.from(o).toString('base64') | ||
exports.decode = s => coerce(Buffer.from(s, 'base64')) | ||
import { coerce } from '../bytes.js' | ||
const encode = o => Buffer.from(o).toString('base64') | ||
const decode = s => coerce(Buffer.from(s, 'base64')) | ||
const __browser = false | ||
export { encode, decode, __browser } |
@@ -1,8 +0,6 @@ | ||
'use strict' | ||
const { fromHex } = require('../bytes') | ||
const bytes = require('../bytes') | ||
import { fromHex, toHex } from '../bytes.js' | ||
const create = function base16 (alphabet) { | ||
return { | ||
encode: input => bytes.toHex(input), | ||
encode: input => toHex(input), | ||
decode (input) { | ||
@@ -19,2 +17,2 @@ for (const char of input) { | ||
module.exports = { prefix: 'f', name: 'base16', ...create('0123456789abcdef') } | ||
export default { prefix: 'f', name: 'base16', ...create('0123456789abcdef') } |
@@ -1,3 +0,1 @@ | ||
'use strict' | ||
function decode (input, alphabet) { | ||
@@ -77,3 +75,3 @@ input = input.replace(new RegExp('=', 'g'), '') | ||
module.exports = [ | ||
export default [ | ||
{ prefix: 'b', name: 'base32', ...create('abcdefghijklmnopqrstuvwxyz234567') }, | ||
@@ -80,0 +78,0 @@ { prefix: 'c', name: 'base32pad', ...create('abcdefghijklmnopqrstuvwxyz234567=') }, |
@@ -1,9 +0,8 @@ | ||
'use strict' | ||
const baseX = require('base-x') | ||
const bytes = require('../bytes') | ||
const { Buffer } = require('buffer') | ||
import baseX from 'base-x' | ||
import { coerce } from '../bytes.js' | ||
import { Buffer } from 'buffer' | ||
const wrap = obj => ({ | ||
encode: b => obj.encode(Buffer.from(b)), | ||
decode: s => bytes.coerce(obj.decode(s)) | ||
decode: s => coerce(obj.decode(s)) | ||
}) | ||
@@ -14,5 +13,5 @@ | ||
module.exports = [ | ||
export default [ | ||
{ name: 'base58btc', prefix: 'z', ...wrap(baseX(btc)) }, | ||
{ name: 'base58flickr', prefix: 'Z', ...wrap(baseX(flickr)) } | ||
] |
@@ -1,3 +0,2 @@ | ||
'use strict' | ||
const b64 = require('./_base64') | ||
import * as b64 from './_base64.js' | ||
@@ -45,3 +44,3 @@ const create = alphabet => { | ||
module.exports = [ | ||
export default [ | ||
{ prefix: 'm', name: 'base64', ...base64 }, | ||
@@ -48,0 +47,0 @@ { prefix: 'M', name: 'base64pad', ...base64pad }, |
@@ -1,8 +0,9 @@ | ||
const multiformats = require('./')() | ||
const raw = require('./codecs/raw') | ||
const json = require('./codecs/json') | ||
const base32 = require('./bases/base32') | ||
const base64 = require('./bases/base64') | ||
const sha2 = require('./hashes/sha2') | ||
import { create } from './index.js' | ||
import raw from './codecs/raw.js' | ||
import json from './codecs/json.js' | ||
import base32 from './bases/base32.js' | ||
import base64 from './bases/base64.js' | ||
import sha2 from './hashes/sha2.js' | ||
const multiformats = create() | ||
multiformats.multihash.add(sha2) | ||
@@ -12,2 +13,2 @@ multiformats.multicodec.add([raw, json]) | ||
module.exports = multiformats | ||
export default multiformats |
@@ -44,8 +44,2 @@ const toHex = d => d.reduce((hex, byte) => hex + byte.toString(16).padStart(2, '0'), '') | ||
exports.equals = equals | ||
exports.coerce = coerce | ||
exports.isBinary = isBinary | ||
exports.fromHex = fromHex | ||
exports.toHex = toHex | ||
exports.fromString = fromString | ||
exports.toString = toString | ||
export { equals, coerce, isBinary, fromHex, toHex, fromString, toString } |
@@ -1,4 +0,3 @@ | ||
'use strict' | ||
const bytes = require('./bytes') | ||
const withIs = require('class-is') | ||
import * as bytes from './bytes.js' | ||
import withIs from 'class-is' | ||
@@ -13,3 +12,3 @@ const readonly = (object, key, value) => { | ||
module.exports = multiformats => { | ||
export default multiformats => { | ||
const { multibase, varint, multihash } = multiformats | ||
@@ -16,0 +15,0 @@ const parse = buff => { |
@@ -1,2 +0,2 @@ | ||
module.exports = { | ||
export default { | ||
encode: obj => new TextEncoder().encode(JSON.stringify(obj)), | ||
@@ -3,0 +3,0 @@ decode: buff => JSON.parse(new TextDecoder().decode(buff)), |
@@ -1,6 +0,6 @@ | ||
const { coerce } = require('../bytes') | ||
import { coerce } from '../bytes.js' | ||
const raw = buff => coerce(buff) | ||
module.exports = { | ||
export default { | ||
encode: raw, | ||
@@ -7,0 +7,0 @@ decode: raw, |
const sha = name => async data => new Uint8Array(await window.crypto.subtle.digest(name, data)) | ||
module.exports = [ | ||
const hashes = [ | ||
{ | ||
@@ -15,2 +15,4 @@ name: 'sha2-256', | ||
] | ||
module.exports.___browser = true | ||
hashes.__browser = true | ||
export default hashes |
@@ -1,2 +0,2 @@ | ||
const crypto = require('crypto') | ||
import crypto from 'crypto' | ||
@@ -10,3 +10,3 @@ const bufferToUint8Array = (buffer) => { | ||
module.exports = [ | ||
const hashes = [ | ||
{ | ||
@@ -23,1 +23,3 @@ name: 'sha2-256', | ||
] | ||
hashes.__browser = false | ||
export default hashes |
11
index.js
@@ -1,4 +0,4 @@ | ||
const varints = require('varint') | ||
const createCID = require('./cid') | ||
const bytes = require('./bytes') | ||
import varints from 'varint' | ||
import createCID from './cid.js' | ||
import * as bytes from './bytes.js' | ||
@@ -108,3 +108,3 @@ const cache = new Map() | ||
module.exports = (table = []) => { | ||
const create = (table = []) => { | ||
const intMap = new Map() | ||
@@ -196,3 +196,2 @@ const nameMap = new Map() | ||
} | ||
module.exports.bytes = bytes | ||
module.exports.varint = varint | ||
export { create, bytes, varint } |
@@ -1,4 +0,4 @@ | ||
const CID = require('cids') | ||
const bytes = require('./bytes') | ||
const { Buffer } = require('buffer') | ||
import CID from 'cids' | ||
import * as bytes from './bytes.js' | ||
import { Buffer } from 'buffer' | ||
@@ -71,2 +71,2 @@ const legacy = (multiformats, name) => { | ||
module.exports = legacy | ||
export default legacy |
{ | ||
"name": "multiformats", | ||
"version": "0.0.11", | ||
"version": "1.0.0", | ||
"description": "Interface for multihash, multicodec, multibase and CID.", | ||
"main": "index.js", | ||
"type": "module", | ||
"scripts": { | ||
@@ -7,0 +8,0 @@ "pre:test": "standard", |
@@ -16,5 +16,6 @@ # multiformats | ||
```js | ||
const { multihash, multicodec, CID } = require('multiformats')() | ||
const sha2 = require('multiformats/hashes/sha2') | ||
const dagcbor = require('@ipld/dag-cbor') | ||
import { create } from 'multiformats' | ||
import sha2 from 'multiformats/hashes/sha2' | ||
import dagcbor from '@ipld/dag-cbor' | ||
const { multihash, multicodec, CID } = create() | ||
multihash.add(sha2) | ||
@@ -24,5 +25,5 @@ multicodec.add(dagcbor) | ||
const buffer = multicodec.encode({ hello, 'world' }, 'dag-cbor') | ||
const hash = await multiformats.multihash.hash(buffer, 'sha2-256') | ||
const hash = await multihash.hash(buffer, 'sha2-256') | ||
// raw codec is the only codec that is there by default | ||
const cid = new multiformats.CID(1, 'raw', hash) | ||
const cid = new CID(1, 'raw', hash) | ||
``` | ||
@@ -35,6 +36,7 @@ | ||
// Import basics package with dep-free codecs, hashes, and base encodings | ||
const multiformats = require('multiformats/basics') | ||
const dagcbor = require('@ipld/dag-cbor') | ||
import multiformats from 'multiformats/basics' | ||
import dagcbor from '@ipld/dag-cbor' | ||
import { create } from '@ipld/block' // Yet to be released Block interface | ||
multiformats.multicodec.add(dagcbor) | ||
const Block = require('@ipld/block')(multiformats) | ||
const Block = create(multiformats) | ||
const block = Block.encoder({ hello: world }, 'dag-cbor') | ||
@@ -57,6 +59,6 @@ const cid = await block.cid() | ||
--- | --- | --- | | ||
`base16` | `require('multiformats/bases/base16')` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/bases) | | ||
`base32`, `base32pad`, `base32hex`, `base32hexpad`, `base32z` | `require('multiformats/bases/base32')` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/bases) | | ||
`base64`, `base64pad`, `base64url`, `base64urlpad` | `require('multiformats/bases/base64')` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/bases) | | ||
`base58btc`, `base58flick4` | `require('multiformats/bases/base58')` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/bases) | | ||
`base16` | `'multiformats/bases/base16'` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/bases) | | ||
`base32`, `base32pad`, `base32hex`, `base32hexpad`, `base32z` | `'multiformats/bases/base32'` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/bases) | | ||
`base64`, `base64pad`, `base64url`, `base64urlpad` | `'multiformats/bases/base64'` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/bases) | | ||
`base58btc`, `base58flick4` | `'multiformats/bases/base58'` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/bases) | | ||
@@ -67,4 +69,4 @@ ## Hash Functions (multihash) | ||
| --- | --- | --- | | ||
| `sha2-256`, `sha2-512` | `require('multiformats/hashes/sha2')` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/hashes) | | ||
| `sha3-224`, `sha3-256`, `sha3-384`,`sha3-512`, `shake-128`, `shake-256`, `keccak-224`, `keccak-256`, `keccak-384`, `keccak-512` | `require('@multiformats/sha3')` | [multiformats/js-sha3](https://github.com/multiformats/js-sha3) | | ||
| `sha2-256`, `sha2-512` | `'multiformats/hashes/sha2'` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/hashes) | | ||
| `sha3-224`, `sha3-256`, `sha3-384`,`sha3-512`, `shake-128`, `shake-256`, `keccak-224`, `keccak-256`, `keccak-384`, `keccak-512` | `'@multiformats/sha3'` | [multiformats/js-sha3](https://github.com/multiformats/js-sha3) | | ||
@@ -75,5 +77,5 @@ ## Codec Implementations (multicodec) | ||
| --- | --- | --- | | ||
| `raw` | `require('multiformats/codecs/raw')` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/codecs) | | ||
| `json` | `require('multiformats/codecs/json')` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/codecs) | | ||
| `dag-cbor` | `require('@ipld/dag-cbor')` | [ipld/js-dag-cbor](https://github.com/ipld/js-dag-cbor) | | ||
| `raw` | `'multiformats/codecs/raw'` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/codecs) | | ||
| `json` | `'multiformats/codecs/json'` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/codecs) | | ||
| `dag-cbor` | `'@ipld/dag-cbor'` | [ipld/js-dag-cbor](https://github.com/ipld/js-dag-cbor) | | ||
@@ -80,0 +82,0 @@ # API |
@@ -1,4 +0,2 @@ | ||
'use strict' | ||
module.exports = [{ | ||
export default [{ | ||
code: 0x00, | ||
@@ -5,0 +3,0 @@ size: 32, |
@@ -1,4 +0,2 @@ | ||
'use strict' | ||
module.exports = [ | ||
export default [ | ||
{ | ||
@@ -5,0 +3,0 @@ encoding: { |
/* globals describe, it */ | ||
import * as bytes from '../bytes.js' | ||
import { deepStrictEqual } from 'assert' | ||
const test = it | ||
const bytes = require('../bytes') | ||
const assert = require('assert') | ||
const same = assert.deepStrictEqual | ||
const same = deepStrictEqual | ||
@@ -7,0 +7,0 @@ describe('bytes', () => { |
/* globals before, describe, it */ | ||
'use strict' | ||
const crypto = require('crypto') | ||
const OLDCID = require('cids') | ||
import crypto from 'crypto' | ||
import OLDCID from 'cids' | ||
import assert from 'assert' | ||
import { toHex } from '../bytes.js' | ||
import multiformats from '../basics.js' | ||
import base58 from '../bases/base58.js' | ||
import base32 from '../bases/base32.js' | ||
import base64 from '../bases/base64.js' | ||
import util from 'util' | ||
const test = it | ||
const assert = require('assert') | ||
const same = assert.deepStrictEqual | ||
const { toHex } = require('../bytes') | ||
@@ -29,6 +33,6 @@ const testThrow = async (fn, message) => { | ||
describe('CID', () => { | ||
const { CID, multihash, multibase, varint } = require('../basics') | ||
multibase.add(require('../bases/base58')) | ||
multibase.add(require('../bases/base32')) | ||
multibase.add(require('../bases/base64')) | ||
const { CID, multihash, multibase, varint } = multiformats | ||
multibase.add(base58) | ||
multibase.add(base32) | ||
multibase.add(base64) | ||
const hashes = [ | ||
@@ -342,3 +346,2 @@ { | ||
const cid = new CID(1, 112, hash) | ||
const util = require('util') | ||
same(util.inspect(cid), 'CID(bafybeif2pall7dybz7vecqka3zo24irdwabwdi4wc55jznaq75q7eaavvu)') | ||
@@ -345,0 +348,0 @@ }) |
/* globals describe, it */ | ||
'use strict' | ||
const assert = require('assert') | ||
const multiformat = require('../')() | ||
import assert from 'assert' | ||
import { create } from '../index.js' | ||
const multiformat = create() | ||
const test = it | ||
@@ -6,0 +6,0 @@ |
/* globals before, describe, it */ | ||
'use strict' | ||
const { Buffer } = require('buffer') | ||
const assert = require('assert') | ||
import { Buffer } from 'buffer' | ||
import assert from 'assert' | ||
import multiformats from '../basics.js' | ||
import legacy from '../legacy.js' | ||
const same = assert.deepStrictEqual | ||
const multiformats = require('../basics') | ||
const legacy = require('../legacy') | ||
const test = it | ||
@@ -9,0 +8,0 @@ |
/* globals describe, it */ | ||
'use strict' | ||
const bytes = require('../bytes') | ||
const assert = require('assert') | ||
import * as bytes from '../bytes.js' | ||
import assert from 'assert' | ||
import { create as multiformat } from '../index.js' | ||
import base16 from '../bases/base16.js' | ||
import base32 from '../bases/base32.js' | ||
import base58 from '../bases/base58.js' | ||
import base64 from '../bases/base64.js' | ||
import basics from '../basics.js' | ||
import { __browser } from '../bases/_base64.js' | ||
const basicsMultibase = basics.multibase | ||
const same = assert.deepStrictEqual | ||
const multiformat = require('../') | ||
const test = it | ||
@@ -21,6 +27,9 @@ | ||
const { multibase } = multiformat() | ||
multibase.add(require('../bases/base16')) | ||
multibase.add(require('../bases/base32')) | ||
multibase.add(require('../bases/base58')) | ||
multibase.add(require('../bases/base64')) | ||
multibase.add(base16) | ||
multibase.add(base32) | ||
multibase.add(base58) | ||
multibase.add(base64) | ||
test('browser', () => { | ||
same(__browser, !!process.browser) | ||
}) | ||
@@ -81,20 +90,19 @@ for (const base of ['base16', 'base32', 'base58btc', 'base64']) { | ||
describe('base16', () => { | ||
baseTest(require('../bases/base16')) | ||
baseTest(base16) | ||
}) | ||
describe('base32', () => { | ||
baseTest(require('../bases/base32')) | ||
baseTest(base32) | ||
}) | ||
describe('base58', () => { | ||
baseTest(require('../bases/base58')) | ||
baseTest(base58) | ||
}) | ||
describe('base64', () => { | ||
baseTest(require('../bases/base64')) | ||
baseTest(base64) | ||
}) | ||
test('has', () => { | ||
const { multibase } = require('../basics') | ||
same(multibase.has('E'), false) | ||
same(multibase.has('baseNope'), false) | ||
same(multibase.has('base32'), true) | ||
same(multibase.has('c'), true) | ||
same(basicsMultibase.has('E'), false) | ||
same(basicsMultibase.has('baseNope'), false) | ||
same(basicsMultibase.has('base32'), true) | ||
same(basicsMultibase.has('c'), true) | ||
}) | ||
}) |
/* globals describe, it */ | ||
'use strict' | ||
const bytes = require('../bytes') | ||
const assert = require('assert') | ||
import * as bytes from '../bytes.js' | ||
import assert from 'assert' | ||
import multiformats from '../basics.js' | ||
const same = assert.deepStrictEqual | ||
const multiformats = require('../basics') | ||
const test = it | ||
@@ -8,0 +7,0 @@ |
/* globals describe, it */ | ||
'use strict' | ||
const bytes = require('../bytes') | ||
const assert = require('assert') | ||
import * as bytes from '../bytes.js' | ||
import assert from 'assert' | ||
import { create as multiformat } from '../index.js' | ||
import intTable from 'multicodec/src/int-table.js' | ||
import valid from './fixtures/valid-multihash.js' | ||
import invalid from './fixtures/invalid-multihash.js' | ||
import crypto from 'crypto' | ||
import sha2 from '../hashes/sha2.js' | ||
const same = assert.deepStrictEqual | ||
const multiformat = require('../') | ||
const intTable = require('multicodec/src/int-table') | ||
const valid = require('./fixtures/valid-multihash.js') | ||
const invalid = require('./fixtures/invalid-multihash.js') | ||
const test = it | ||
const encode = name => data => bytes.coerce(crypto.createHash(name).update(data).digest()) | ||
const table = Array.from(intTable.entries()) | ||
@@ -33,8 +34,5 @@ | ||
const crypto = require('crypto') | ||
const encode = name => data => bytes.coerce(crypto.createHash(name).update(data).digest()) | ||
describe('multihash', () => { | ||
const { multihash } = multiformat(table) | ||
multihash.add(require('../hashes/sha2')) | ||
multihash.add(sha2) | ||
const { validate } = multihash | ||
@@ -108,8 +106,5 @@ const empty = new Uint8Array(0) | ||
}) | ||
if (process.browser) { | ||
test('browser bundle', () => { | ||
const mod = require('../hashes/sha2') | ||
same(mod.___browser, true) | ||
}) | ||
} | ||
test('browser', () => { | ||
same(sha2.__browser, !!process.browser) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
152
Yes
58221
1507