Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration free implementation #36

Merged
merged 27 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a04a8f6
pkg: drop period
mikeal Aug 20, 2020
fd0ce17
invalidate cache
Gozala Sep 9, 2020
edbc56c
fix: vendor varint for pure ESM
mikeal Sep 16, 2020
b7aa2a6
fix: pass encode offset
Gozala Sep 16, 2020
70cd8ce
fix: remove unecessary ImplicitSha256Digest
Gozala Sep 16, 2020
66682df
chore: add links, tree and get APIs to Block
Gozala Sep 16, 2020
04030cb
fix: typo in template literal
Gozala Sep 16, 2020
655860e
fix: vendor base-x for pure ESM
Gozala Sep 17, 2020
783bce4
feat: bundle base58btc and base32 encoders
Gozala Sep 17, 2020
5e9a433
chore: add code type info
Gozala Sep 18, 2020
8bcdb5d
fix: switch to field base check over instanceof
Gozala Sep 19, 2020
0c2ac57
core: export ByteView type
Gozala Sep 19, 2020
005cb52
fix: browser polyfill for deepStrictEquals doesn't supprot Uint8Arrays
mikeal Sep 23, 2020
e43c0d3
fix: coverage for cid
Gozala Sep 23, 2020
262ba31
fix: hashes coverage
Gozala Sep 23, 2020
a2d6763
chore: disable coverage for vendor
Gozala Sep 23, 2020
64d3977
chore: improve test coverage
Gozala Sep 23, 2020
4baa102
chore: remove dead code
Gozala Sep 23, 2020
7d2fda3
chore: remove block.js
Gozala Sep 23, 2020
d9b92be
fix: drop old npm ignore
mikeal Sep 23, 2020
a5d58ac
fix: moving excludes to package.json
mikeal Sep 23, 2020
cd3ffc6
fix: browser same handles uint8arrays terribly
mikeal Sep 23, 2020
49c0fc6
fix: clearing out old docs
mikeal Sep 23, 2020
c012a2f
chore: update readme
Gozala Sep 24, 2020
2654958
doc: fix typo
mikeal Sep 25, 2020
a826851
fix: drop basics exports
mikeal Sep 25, 2020
6f633a3
fix: tests off of basics interface
mikeal Sep 25, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 20 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,31 @@ This allows you to pass around an interface containing only the code you need
which can greatly reduce dependencies and bundle size.

```js
import { create } from 'multiformats'
import sha2 from 'multiformats/hashes/sha2'
import * as CID from 'multiformats/cid'
import { sha256 } from 'multiformats/hashes/sha2'
import dagcbor from '@ipld/dag-cbor'
const { multihash, multicodec, CID } = create()
multihash.add(sha2)
multicodec.add(dagcbor)
import { base32 } from 'multiformats/bases/base32'
import { base58btc } from 'multiformats/bases/base58'

const buffer = multicodec.encode({ hello, 'world' }, 'dag-cbor')
const hash = await multihash.hash(buffer, 'sha2-256')
const bytes = dagcbor.encode({ hello: 'world' })

const hash = await sha256.digest(bytes)
// raw codec is the only codec that is there by default
const cid = new CID(1, 'raw', hash)
const cid = CID.create(1, dagcbor.code, hash)
```

However, if you're doing this much you should probably use multiformats
with the `Block` API.

```js
// Import basics package with dep-free codecs, hashes, and base encodings
import multiformats from 'multiformats/basics'
import { block } from 'multiformats/basics'
import { sha256 } from 'multiformats/hashes/sha2'
import dagcbor from '@ipld/dag-cbor'
import { create } from '@ipld/block' // Yet to be released Block interface
multiformats.multicodec.add(dagcbor)
const Block = create(multiformats)
const block = Block.encoder({ hello: world }, 'dag-cbor')
const cid = await block.cid()

const encoder = block.encoder(dagcbor, { hasher: sha256 })
const hello = encoder.encode({ hello: 'world' })
const cid = await hello.cid()
```

# Plugins
Expand Down Expand Up @@ -83,35 +83,17 @@ Returns a new multiformats interface.

Can optionally pass in a table of multiformat entries.

# multihash

## multihash.encode

## multihash.decode

## multihash.validate

## multihash.add

## multihash.hash

# multicodec

## multicodec.encode

## multicodec.decode

## multicodec.add
## multiformats.configure

# multibase
## multiformats.varint

## multibase.encode
## multiformats.bytes

## multibase.decode
## multiformats.digest

## multibase.add
## multiformats.hasher

# CID
# multiformats.CID

Changes from `cids`:

Expand Down
18 changes: 14 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
"name": "multiformats",
"version": "0.0.0-dev",
"description": "Interface for multihash, multicodec, multibase and CID.",
"description": "Interface for multihash, multicodec, multibase and CID",
"main": "index.js",
"type": "module",
"scripts": {
"build": "npm_config_yes=true npx ipjs@latest build --tests",
"build:vendor": "npm run build:vendor:varint && npm run build:vendor:base-x",
"build:vendor:varint": "npx brrp -x varint > vendor/varint.js",
"build:vendor:base-x": "npx brrp -x @multiformats/base-x > vendor/base-x.js",
"publish": "npm_config_yes=true npx ipjs@latest publish",
"lint": "standard",
"test:cjs": "npm run build && mocha dist/cjs/node-test/test-*.js && npm run test:cjs:browser",
Expand Down Expand Up @@ -45,10 +48,19 @@
"import": "./src/bases/base64-import.js",
"browser": "./src/bases/base64-browser.js"
},
"./hashes/hasher": {
"import": "./src/hashes/hasher.js"
},
"./hashes/digest": {
"import": "./src/hashes/digest.js"
},
"./hashes/sha2": {
"browser": "./src/hashes/sha2-browser.js",
"import": "./src/hashes/sha2.js"
},
"./codecs/codec": {
"import": "./src/codecs/codec.js"
},
"./codecs/json": {
"import": "./src/codecs/json.js"
},
Expand All @@ -69,10 +81,8 @@
]
},
"dependencies": {
"base-x": "^3.0.8",
"buffer": "^5.6.0",
"cids": "^1.0.0",
"varint": "^5.0.0"
"cids": "^1.0.0"
},
"directories": {
"test": "test"
Expand Down
Loading