Add comprehensive installation and setup documentation

- Add GETTING_STARTED.md with quick start guide and development modes
- Add INSTALL.sh automated installation script
- Add INSTALLATION_CHECKLIST.md, INSTALLATION_SUCCESS.md, and INSTALLATION_SUMMARY.md
- Add QUICK_REFERENCE.md for common commands
- Add SETUP_GUIDE.md with detailed setup instructions
- Update README.md with improved project overview
- Add did-wallet app dependencies and node_modules
This commit is contained in:
Dorian
2026-01-27 17:18:21 +00:00
parent a81f655133
commit 0d073fa89e
22658 changed files with 4494151 additions and 6 deletions
+267
View File
@@ -0,0 +1,267 @@
## [11.0.2](https://github.com/multiformats/js-multiformats/compare/v11.0.1...v11.0.2) (2023-03-09)
### Bug Fixes
* add interface files to the exports map ([#246](https://github.com/multiformats/js-multiformats/issues/246)) ([a58a398](https://github.com/multiformats/js-multiformats/commit/a58a39896d7264ba0bcbaf737cce7f3a65c644ba)), closes [/github.com/ipld/js-dag-cbor/blob/master/src/index.js#L9](https://github.com/multiformats//github.com/ipld/js-dag-cbor/blob/master/src/index.js/issues/L9)
## [11.0.1](https://github.com/multiformats/js-multiformats/compare/v11.0.0...v11.0.1) (2023-01-18)
### Bug Fixes
* throw on CID.parse v0 string with multibase prefix ([258a0be](https://github.com/multiformats/js-multiformats/commit/258a0be344ddd5d08e08e55b3e088212df0c409a))
## [11.0.0](https://github.com/multiformats/js-multiformats/compare/v10.0.3...v11.0.0) (2023-01-02)
### ⚠ BREAKING CHANGES
* Make link.toJSON return a DAG-JSON link
### Features
* Make link.toJSON return a DAG-JSON link ([9e087d6](https://github.com/multiformats/js-multiformats/commit/9e087d64ee3c90d8b019dd48989936b17b1cb2f3))
### Bug Fixes
* build browser bundle ([2ee6012](https://github.com/multiformats/js-multiformats/commit/2ee6012dbb702cff2425668c16fe101fdf79517d)), closes [#234](https://github.com/multiformats/js-multiformats/issues/234)
* list links of a block that _is a_ CID ([#226](https://github.com/multiformats/js-multiformats/issues/226)) ([c17673d](https://github.com/multiformats/js-multiformats/commit/c17673d9e15bd5a4df074c9f73267a257e0dcfad))
### Documentation
* fix typos in jsdoc comments ([a246054](https://github.com/multiformats/js-multiformats/commit/a246054653cf588e92d76f8161b0a6cd6035533b))
## [10.0.3](https://github.com/multiformats/js-multiformats/compare/v10.0.2...v10.0.3) (2022-12-16)
### Documentation
* publish typedocs in gh-pages branch ([#233](https://github.com/multiformats/js-multiformats/issues/233)) ([3a6d3ed](https://github.com/multiformats/js-multiformats/commit/3a6d3ed1f653d62e30d72d7bd00dc5815a17ffe3))
## [10.0.2](https://github.com/multiformats/js-multiformats/compare/v10.0.1...v10.0.2) (2022-10-19)
### Bug Fixes
* use slash as flag that an object is a CID ([#217](https://github.com/multiformats/js-multiformats/issues/217)) ([1cec619](https://github.com/multiformats/js-multiformats/commit/1cec619e2818d893292323539f397324ace82280)), closes [#212](https://github.com/multiformats/js-multiformats/issues/212) [#213](https://github.com/multiformats/js-multiformats/issues/213)
### Trivial Changes
* **no-release:** rename varint test file so it is run ([#209](https://github.com/multiformats/js-multiformats/issues/209)) ([e32fe47](https://github.com/multiformats/js-multiformats/commit/e32fe4703ee0c48100af89f9c9c7181f65935176))
* remove unnecessary dev deps ([#218](https://github.com/multiformats/js-multiformats/issues/218)) ([a43ffff](https://github.com/multiformats/js-multiformats/commit/a43ffff672495ba86486be47084697df4e1ecacc))
## [10.0.1](https://github.com/multiformats/js-multiformats/compare/v10.0.0...v10.0.1) (2022-10-17)
### Bug Fixes
* convert byteOffset and byteLength to getters ([#215](https://github.com/multiformats/js-multiformats/issues/215)) ([4e09490](https://github.com/multiformats/js-multiformats/commit/4e09490beeba0e0a47432a7bb51112ab5f556e3f)), closes [#208](https://github.com/multiformats/js-multiformats/issues/208) [#210](https://github.com/multiformats/js-multiformats/issues/210)
## [10.0.0](https://github.com/multiformats/js-multiformats/compare/v9.9.0...v10.0.0) (2022-10-12)
### ⚠ BREAKING CHANGES
* remove use of Object.defineProperties in CID class
* use aegir for ESM-only build/testing/release
### Features
* add complete set of aegir-based scripts ([1190bc6](https://github.com/multiformats/js-multiformats/commit/1190bc6fcc2d11a317979538692940d6b8085874))
* define Link interface for CID ([88e29ea](https://github.com/multiformats/js-multiformats/commit/88e29ea7a8c1a1a284c654311cfb1d67cbfd8e6c))
* remove deprecated CID properties & methods ([ffc4e6f](https://github.com/multiformats/js-multiformats/commit/ffc4e6fac0b9f755a141f5e7fea61950d195b4fa))
* use aegir for ESM-only build/testing/release ([163d463](https://github.com/multiformats/js-multiformats/commit/163d4632708b874b60c5a8de0f77811034557f74))
### Bug Fixes
* --no-cov for all but chrome main ([b92f25f](https://github.com/multiformats/js-multiformats/commit/b92f25fe6f3ca9ed9c9468a209bf1101a3005a3d))
* add "browser" field, remove named local imports ([d60ea06](https://github.com/multiformats/js-multiformats/commit/d60ea06f0c1d3145200138548e71677d0007f9ef))
* additional lint items from Link interface work ([91f677b](https://github.com/multiformats/js-multiformats/commit/91f677be1bc6304b066d4c6aaeea2b1af94876b7))
* address JS & TS linting complaints ([c12db2a](https://github.com/multiformats/js-multiformats/commit/c12db2a53a11f701fbfbd04f5f977580c37af54b))
* changes for new lint rules ([e6c9957](https://github.com/multiformats/js-multiformats/commit/e6c9957383d6023291fafaa1f6718bd903539e43))
* distribute types in dist/types/ ([c6defdb](https://github.com/multiformats/js-multiformats/commit/c6defdb039520e4e7dd0e279b212b72683ceac85))
* ensure "master" as release branch ([16f8d9e](https://github.com/multiformats/js-multiformats/commit/16f8d9e1215caaa00cc7d708058f01dc6d10b824))
* make CID#asCID a regular property ([a74f1c7](https://github.com/multiformats/js-multiformats/commit/a74f1c75b73c6d019614ecbf8f06ab97a232a48b))
* only release on master ([d15f26f](https://github.com/multiformats/js-multiformats/commit/d15f26fbcf51bd9d382e27ca9099af71c217bb25))
* properly export types, build more complete pack ([8172ea8](https://github.com/multiformats/js-multiformats/commit/8172ea8977296ece7a1b9d165caa99c284b604fd))
* remove "main" ([ad3306c](https://github.com/multiformats/js-multiformats/commit/ad3306c459e0e4f22184963c151bf3cc737ec9b0))
* remove use of Object.defineProperties in CID class ([6149fae](https://github.com/multiformats/js-multiformats/commit/6149fae84b74b7a6b0ca8f9e21e731ac9fabcf3a)), closes [#200](https://github.com/multiformats/js-multiformats/issues/200)
* run coverage only where it's supposed to ([872d121](https://github.com/multiformats/js-multiformats/commit/872d12126132a38677f623b87699b6fbff968cfd))
* test on all branches and pull requests ([f2ae077](https://github.com/multiformats/js-multiformats/commit/f2ae07760739c2f16e2eb5c83a2fad15a877243f))
* ts-use import path ([53651c1](https://github.com/multiformats/js-multiformats/commit/53651c1fae60b0bf9424c5f8f688d42959835480))
* use extensions for relative ts imports ([451998a](https://github.com/multiformats/js-multiformats/commit/451998a43516d7d5c468a18fe074ea1b53ac883e)), closes [/github.com/multiformats/js-multiformats/pull/199#issuecomment-1252793515](https://github.com/multiformats//github.com/multiformats/js-multiformats/pull/199/issues/issuecomment-1252793515)
* use parent `tsc` in ts-use ([85a9296](https://github.com/multiformats/js-multiformats/commit/85a9296f54118ff676bf1deb107d65c4c892186d))
### Tests
* check for non-enumerability of asCID property ([b4ba07d](https://github.com/multiformats/js-multiformats/commit/b4ba07db92e4610a55101f7dd17505f21a341a85))
### Trivial Changes
* add test for structural copying ([#206](https://github.com/multiformats/js-multiformats/issues/206)) ([e8def36](https://github.com/multiformats/js-multiformats/commit/e8def3663cd328023fbf7e4e88c9e47e71846d06))
* **no-release:** bump @types/mocha from 9.1.1 to 10.0.0 ([#205](https://github.com/multiformats/js-multiformats/issues/205)) ([a9a9347](https://github.com/multiformats/js-multiformats/commit/a9a9347789ee720d1de9508598d8879abf443baf))
* **no-release:** bump actions/setup-node from 3.4.1 to 3.5.0 ([#204](https://github.com/multiformats/js-multiformats/issues/204)) ([604ca1f](https://github.com/multiformats/js-multiformats/commit/604ca1fe498864a32851294317d76f0aaa13d280))
## [9.9.0](https://github.com/multiformats/js-multiformats/compare/v9.8.1...v9.9.0) (2022-09-20)
### Features
* add optional offset param to varint.decode ([#201](https://github.com/multiformats/js-multiformats/issues/201)) ([1e1b583](https://github.com/multiformats/js-multiformats/commit/1e1b583893bc0c984dcbeaf321c17f6637629b4e))
## [9.7.1](https://github.com/multiformats/js-multiformats/compare/v9.7.0...v9.7.1) (2022-07-26)
### Bug Fixes
* typo ([#192](https://github.com/multiformats/js-multiformats/issues/192)) ([b602f63](https://github.com/multiformats/js-multiformats/commit/b602f6315d35ee5c83d6f0b9995988f065f47ec8))
### Trivial Changes
* **no-release:** bump actions/setup-node from 3.3.0 to 3.4.0 ([#189](https://github.com/multiformats/js-multiformats/issues/189)) ([362b167](https://github.com/multiformats/js-multiformats/commit/362b167c939066b1e3217db4442a7652fba38e85))
* **no-release:** bump actions/setup-node from 3.4.0 to 3.4.1 ([#190](https://github.com/multiformats/js-multiformats/issues/190)) ([67f22c4](https://github.com/multiformats/js-multiformats/commit/67f22c4696777529d3871ee1e2fdbd436ad55fc0))
## [9.7.0](https://github.com/multiformats/js-multiformats/compare/v9.6.5...v9.7.0) (2022-06-23)
### Features
* add base256emoji ([#187](https://github.com/multiformats/js-multiformats/issues/187)) ([c6c5c46](https://github.com/multiformats/js-multiformats/commit/c6c5c46b12686c48db741836c5957dbc72f4bbd4))
### Trivial Changes
* **no-release:** bump @types/node from 17.0.45 to 18.0.0 ([#188](https://github.com/multiformats/js-multiformats/issues/188)) ([99e94ed](https://github.com/multiformats/js-multiformats/commit/99e94ed8025aabae64e58c2f2d2fff6b24dddfcb))
* **no-release:** bump actions/setup-node from 3.1.0 to 3.2.0 ([#182](https://github.com/multiformats/js-multiformats/issues/182)) ([86ec43d](https://github.com/multiformats/js-multiformats/commit/86ec43d89d60c6c4be0e001c06d1e28570a3d36a))
* **no-release:** bump actions/setup-node from 3.2.0 to 3.3.0 ([#186](https://github.com/multiformats/js-multiformats/issues/186)) ([712c1c4](https://github.com/multiformats/js-multiformats/commit/712c1c4fe5066d0a6fdc89b53a7943bb67edf0b8))
* **no-release:** fix typo implemnetation -> implementation ([#184](https://github.com/multiformats/js-multiformats/issues/184)) ([3d4ae50](https://github.com/multiformats/js-multiformats/commit/3d4ae504928b372886d1021e48a39c06ecbf8fde))
### [9.6.5](https://github.com/multiformats/js-multiformats/compare/v9.6.4...v9.6.5) (2022-05-06)
### Trivial Changes
* **no-release:** bump actions/checkout from 2.4.0 to 3 ([#172](https://github.com/multiformats/js-multiformats/issues/172)) ([a1b38c2](https://github.com/multiformats/js-multiformats/commit/a1b38c235809287e284c7bde80634e669e6d1ac6))
* **no-release:** bump actions/setup-node from 2.5.1 to 3.0.0 ([#169](https://github.com/multiformats/js-multiformats/issues/169)) ([8deb4d5](https://github.com/multiformats/js-multiformats/commit/8deb4d5dae2e01d8fd60f2dd6e944747c4ee2ef1))
* **no-release:** bump actions/setup-node from 3.0.0 to 3.1.0 ([#174](https://github.com/multiformats/js-multiformats/issues/174)) ([9bcd7fe](https://github.com/multiformats/js-multiformats/commit/9bcd7fef62888d7cefe8e4f5e929d4e3c9dadda9))
* **no-release:** bump mocha from 9.2.2 to 10.0.0 ([#179](https://github.com/multiformats/js-multiformats/issues/179)) ([b2951dc](https://github.com/multiformats/js-multiformats/commit/b2951dcbee5812522f2336bbf7c28eab9babdfa9))
* **no-release:** bump polendina from 2.0.15 to 3.0.0 ([#180](https://github.com/multiformats/js-multiformats/issues/180)) ([659516b](https://github.com/multiformats/js-multiformats/commit/659516bb231bcc8332d93ded03ebcfa8e675f2dc))
* **no-release:** bump standard from 16.0.4 to 17.0.0 ([#178](https://github.com/multiformats/js-multiformats/issues/178)) ([2683344](https://github.com/multiformats/js-multiformats/commit/268334426ca97f38a8c2eab0c834943c6e1a04d0))
* update tsdoc for CID `code` param to clarify "what kind of code?" ([#181](https://github.com/multiformats/js-multiformats/issues/181)) ([adec0c4](https://github.com/multiformats/js-multiformats/commit/adec0c4714ef39879c3b059dc9a4882e19406420))
### [9.6.4](https://github.com/multiformats/js-multiformats/compare/v9.6.3...v9.6.4) (2022-02-14)
### Trivial Changes
* clean typos and formatting ([0d976fd](https://github.com/multiformats/js-multiformats/commit/0d976fd33923e8b9cbe1535d3bc269affe151d66))
### [9.6.3](https://github.com/multiformats/js-multiformats/compare/v9.6.2...v9.6.3) (2022-02-04)
### Bug Fixes
* run test:ci in CI, fix package.json keywords ([#139](https://github.com/multiformats/js-multiformats/issues/139)) ([8ec8eb0](https://github.com/multiformats/js-multiformats/commit/8ec8eb0ca29ed51d244495a0d6c7d7a08a31ac39))
### [9.6.2](https://github.com/multiformats/js-multiformats/compare/v9.6.1...v9.6.2) (2022-01-20)
### Bug Fixes
* add encode to identity ([2724f8a](https://github.com/multiformats/js-multiformats/commit/2724f8aa8e0e7c24db7594eb29f683b1c01f3e42)), closes [#160](https://github.com/multiformats/js-multiformats/issues/160)
* coverage by using encode ([132d829](https://github.com/multiformats/js-multiformats/commit/132d829eb84776afd3820788df024a7a9f6d8834))
### [9.6.1](https://github.com/multiformats/js-multiformats/compare/v9.6.0...v9.6.1) (2022-01-20)
### Bug Fixes
* export only `identity` hasher const ([330082a](https://github.com/multiformats/js-multiformats/commit/330082aeaf2f493e351c413411ce9a4db25ebe5f))
## [9.6.0](https://github.com/multiformats/js-multiformats/compare/v9.5.9...v9.6.0) (2022-01-19)
### Features
* add sync multihash hasher ([#160](https://github.com/multiformats/js-multiformats/issues/160)) ([c3a650c](https://github.com/multiformats/js-multiformats/commit/c3a650c8b48989ea52045d85eb06eebee8bb59d1))
### [9.5.9](https://github.com/multiformats/js-multiformats/compare/v9.5.8...v9.5.9) (2022-01-18)
### Trivial Changes
* Reanable tsc action and reconfigure project slightly ([#157](https://github.com/multiformats/js-multiformats/issues/157)) ([c936a6d](https://github.com/multiformats/js-multiformats/commit/c936a6d3f125b6032358ffcc0e9c71e2bf986bf3))
### [9.5.8](https://github.com/multiformats/js-multiformats/compare/v9.5.7...v9.5.8) (2022-01-07)
### Trivial Changes
* **test:** use chai throws() & chai-as-promised isRejected() ([6e4ba86](https://github.com/multiformats/js-multiformats/commit/6e4ba86a59ef1f5a93b1869f1650073da184ebe4))
### [9.5.7](https://github.com/multiformats/js-multiformats/compare/v9.5.6...v9.5.7) (2022-01-07)
### Bug Fixes
* **types:** combine composite tsconfigs ([18c5734](https://github.com/multiformats/js-multiformats/commit/18c5734060c972cbcb45d6acea1642b2d09fde13))
### Trivial Changes
* **types:** re-enable typechecks for tests by split tsconfig ([4c017dc](https://github.com/multiformats/js-multiformats/commit/4c017dc80280bb42b0e2da07eb5f5da58c2efd76))
* **types:** remove explicit typecheck action ([b0467e5](https://github.com/multiformats/js-multiformats/commit/b0467e52870a91f3fc3122afb969505a31dc3210))
### [9.5.6](https://github.com/multiformats/js-multiformats/compare/v9.5.5...v9.5.6) (2022-01-04)
### Bug Fixes
* **types:** fix publishing of types ([58b5604](https://github.com/multiformats/js-multiformats/commit/58b5604fff734ca997dbedf0d8309247f4e518e4)), closes [#150](https://github.com/multiformats/js-multiformats/issues/150)
### [9.5.5](https://github.com/multiformats/js-multiformats/compare/v9.5.4...v9.5.5) (2022-01-04)
### Bug Fixes
* enable ts on tests ([62774c2](https://github.com/multiformats/js-multiformats/commit/62774c2bca1b2c4eb7c125bd092f6f9dcadb19e5))
* type inference for base32 ([b912ecc](https://github.com/multiformats/js-multiformats/commit/b912ecc136908eaa8dd4f9e5fae48b7b52132651))
### Trivial Changes
* **no-release:** bump @types/node from 16.11.14 to 17.0.0 ([#145](https://github.com/multiformats/js-multiformats/issues/145)) ([66aaf0f](https://github.com/multiformats/js-multiformats/commit/66aaf0fa8cfb6d0a41e12e3f3463147a0bbda0ea))
* **no-release:** bump actions/setup-node from 2.5.0 to 2.5.1 ([#147](https://github.com/multiformats/js-multiformats/issues/147)) ([32cf7bd](https://github.com/multiformats/js-multiformats/commit/32cf7bd9709173683e194c7c0e7b8f4acf49e9a5))
### [9.5.4](https://github.com/multiformats/js-multiformats/compare/v9.5.3...v9.5.4) (2021-12-09)
### Bug Fixes
* remove publish script ([da1d722](https://github.com/multiformats/js-multiformats/commit/da1d7228aca1eebf749f0a922a3f7e90b805009d))
### [9.5.3](https://github.com/multiformats/js-multiformats/compare/v9.5.2...v9.5.3) (2021-12-09)
### Bug Fixes
* add windows CI support (replace hundreds with c8 direct) ([5da242c](https://github.com/multiformats/js-multiformats/commit/5da242c65d39845ab869e027219c06510d700b6e))
* ipjs windows fix, add windows back in to CI ([196e404](https://github.com/multiformats/js-multiformats/commit/196e4041a9aaefd2309e87b372e2efe8febd11fc))
* prepare auto-release from dist dir & w/ build ([90693dd](https://github.com/multiformats/js-multiformats/commit/90693dd4e3b95099e834c15dcfd8090bb0a8367a))
### Trivial Changes
* drop test support for 12.x ([a7a2110](https://github.com/multiformats/js-multiformats/commit/a7a2110559e7cf66c3741ade42cea80d8a12a82a))
* remove windows from CI pending ipjs fix ([2ab914b](https://github.com/multiformats/js-multiformats/commit/2ab914b1943fb8fc4e0aeead0fb7ce5dc979514e))
* update auto-release work w/ semantic-release ([db86f48](https://github.com/multiformats/js-multiformats/commit/db86f487dcba790522908583c6f4a9c7ce504dea))
* update devDeps ([55b9856](https://github.com/multiformats/js-multiformats/commit/55b98569017a647fd070bb699d453df9bb482715))
* upgrade polendina, test esm & cjs in browser ([852f1a5](https://github.com/multiformats/js-multiformats/commit/852f1a5dfecf0489679dfb24f9d2dc48ec21e95a))
+4
View File
@@ -0,0 +1,4 @@
This project is dual licensed under MIT and Apache-2.0.
MIT: https://www.opensource.org/licenses/mit
Apache-2.0: https://www.apache.org/licenses/license-2.0
+5
View File
@@ -0,0 +1,5 @@
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
+19
View File
@@ -0,0 +1,19 @@
The MIT License (MIT)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+259
View File
@@ -0,0 +1,259 @@
# multiformats <!-- omit in toc -->
[![multiformats.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://multiformats.io)
[![codecov](https://img.shields.io/codecov/c/github/multiformats/js-multiformats.svg?style=flat-square)](https://codecov.io/gh/multiformats/js-multiformats)
[![CI](https://img.shields.io/github/actions/workflow/status/multiformats/js-multiformats/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/multiformats/js-multiformats/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)
> Interface for multihash, multicodec, multibase and CID
## Table of contents <!-- omit in toc -->
- [Install](#install)
- [Browser `<script>` tag](#browser-script-tag)
- [Interfaces](#interfaces)
- [Creating Blocks](#creating-blocks)
- [Multibase Encoders / Decoders / Codecs](#multibase-encoders--decoders--codecs)
- [Multicodec Encoders / Decoders / Codecs](#multicodec-encoders--decoders--codecs)
- [Multihash Hashers](#multihash-hashers)
- [Traversal](#traversal)
- [Legacy interface](#legacy-interface)
- [Implementations](#implementations)
- [Multibase codecs](#multibase-codecs)
- [Multihash hashers](#multihash-hashers-1)
- [IPLD codecs (multicodec)](#ipld-codecs-multicodec)
- [API Docs](#api-docs)
- [License](#license)
- [Contribution](#contribution)
## Install
```console
$ npm i multiformats
```
### Browser `<script>` tag
Loading this module through a script tag will make it's exports available as `Multiformats` in the global namespace.
```html
<script src="https://unpkg.com/multiformats/dist/index.min.js"></script>
```
## Interfaces
This library defines common interfaces and low level building blocks for various interrelated multiformat technologies (multicodec, multihash, multibase, and CID). They can be used to implement custom base encoders / decoders / codecs, codec encoders /decoders and multihash hashers that comply to the interface that layers above assume.
This library provides implementations for most basics and many others can be found in linked repositories.
```js
import { CID } from 'multiformats/cid'
import * as json from 'multiformats/codecs/json'
import { sha256 } from 'multiformats/hashes/sha2'
const bytes = json.encode({ hello: 'world' })
const hash = await sha256.digest(bytes)
const cid = CID.create(1, json.code, hash)
//> CID(bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea)
```
### Creating Blocks
```js
import * as Block from 'multiformats/block'
import * as codec from '@ipld/dag-cbor'
import { sha256 as hasher } from 'multiformats/hashes/sha2'
const value = { hello: 'world' }
// encode a block
let block = await Block.encode({ value, codec, hasher })
block.value // { hello: 'world' }
block.bytes // Uint8Array
block.cid // CID() w/ sha2-256 hash address and dag-cbor codec
// you can also decode blocks from their binary state
block = await Block.decode({ bytes: block.bytes, codec, hasher })
// if you have the cid you can also verify the hash on decode
block = await Block.create({ bytes: block.bytes, cid: block.cid, codec, hasher })
```
### Multibase Encoders / Decoders / Codecs
CIDs can be serialized to string representation using multibase encoders that implement [`MultibaseEncoder`](https://github.com/multiformats/js-multiformats/blob/master/src/bases/interface.ts) interface. This library provides quite a few implementations that can be imported:
```js
import { base64 } from "multiformats/bases/base64"
cid.toString(base64.encoder)
//> 'mAYAEEiCTojlxqRTl6svwqNJRVM2jCcPBxy+7mRTUfGDzy2gViA'
```
Parsing CID string serialized CIDs requires multibase decoder that implements [`MultibaseDecoder`](https://github.com/multiformats/js-multiformats/blob/master/src/bases/interface.ts) interface. This library provides a decoder for every encoder it provides:
```js
CID.parse('mAYAEEiCTojlxqRTl6svwqNJRVM2jCcPBxy+7mRTUfGDzy2gViA', base64.decoder)
//> CID(bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea)
```
Dual of multibase encoder & decoder is defined as multibase codec and it exposes
them as `encoder` and `decoder` properties. For added convenience codecs also
implement `MultibaseEncoder` and `MultibaseDecoder` interfaces so they could be
used as either or both:
```js
cid.toString(base64)
CID.parse(cid.toString(base64), base64)
```
**Note:** CID implementation comes bundled with `base32` and `base58btc`
multibase codecs so that CIDs can be base serialized to (version specific)
default base encoding and parsed without having to supply base encoders/decoders:
```js
const v1 = CID.parse('bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea')
v1.toString()
//> 'bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea'
const v0 = CID.parse('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')
v0.toString()
//> 'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n'
v0.toV1().toString()
//> 'bafybeihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku'
```
### Multicodec Encoders / Decoders / Codecs
This library defines [`BlockEncoder`, `BlockDecoder` and `BlockCodec` interfaces](https://github.com/multiformats/js-multiformats/blob/master/src/codecs/interface.ts).
Codec implementations should conform to the `BlockCodec` interface which implements both `BlockEncoder` and `BlockDecoder`.
Here is an example implementation of JSON `BlockCodec`.
```js
/**
* @template T
* @type {BlockCodec<0x0200, T>}
*/
export const { name, code, encode, decode } = {
name: 'json',
code: 0x0200,
encode: json => new TextEncoder().encode(JSON.stringify(json)),
decode: bytes => JSON.parse(new TextDecoder().decode(bytes))
}
```
### Multihash Hashers
This library defines [`MultihashHasher` and `MultihashDigest` interfaces](https://github.com/multiformats/js-multiformats/blob/master/src/hashes/interface.ts) and convinient function for implementing them:
```js
import * as hasher from 'multiformats/hashes/hasher'
const sha256 = hasher.from({
// As per multiformats table
// https://github.com/multiformats/multicodec/blob/master/table.csv#L9
name: 'sha2-256',
code: 0x12,
encode: (input) => new Uint8Array(crypto.createHash('sha256').update(input).digest())
})
const hash = await sha256.digest(json.encode({ hello: 'world' }))
CID.create(1, json.code, hash)
//> CID(bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea)
```
### Traversal
This library contains higher-order functions for traversing graphs of data easily.
`walk()` walks through the links in each block of a DAG calling a user-supplied loader function for each one, in depth-first order with no duplicate block visits. The loader should return a `Block` object and can be used to inspect and collect block ordering for a full DAG walk. The loader should `throw` on error, and return `null` if a block should be skipped by `walk()`.
```js
import { walk } from 'multiformats/traversal'
import * as Block from 'multiformats/block'
import * as codec from 'multiformats/codecs/json'
import { sha256 as hasher } from 'multiformats/hashes/sha2'
// build a DAG (a single block for this simple example)
const value = { hello: 'world' }
const block = await Block.encode({ value, codec, hasher })
const { cid } = block
console.log(cid)
//> CID(bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea)
// create a loader function that also collects CIDs of blocks in
// their traversal order
const load = (cid, blocks) => async (cid) => {
// fetch a block using its cid
// e.g.: const block = await fetchBlockByCID(cid)
blocks.push(cid)
return block
}
// collect blocks in this DAG starting from the root `cid`
const blocks = []
await walk({ cid, load: load(cid, blocks) })
console.log(blocks)
//> [CID(bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea)]
```
## Legacy interface
[`blockcodec-to-ipld-format`](https://github.com/ipld/js-blockcodec-to-ipld-format) converts a multiformats [`BlockCodec`](https://github.com/multiformats/js-multiformats/blob/master/src/codecs/interface.ts#L21) into an
[`interface-ipld-format`](https://github.com/ipld/interface-ipld-format) for use with the [`ipld`](https://github.com/ipld/ipld) package. This can help bridge IPLD codecs implemented using the structure and interfaces defined here to existing code that assumes, or requires `interface-ipld-format`. This bridge also includes the relevant TypeScript definitions.
## Implementations
By default, no base encodings (other than base32 & base58btc), hash functions,
or codec implementations are exposed by `multiformats`, you need to
import the ones you need yourself.
### Multibase codecs
| bases | import | repo |
| ------------------------------------------------------------- | --------------------------- | ------------------------------------------------------------------------------------------------- |
| `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) |
Other (less useful) bases implemented in [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/bases) include: `base2`, `base8`, `base10`, `base36` and `base256emoji`.
### Multihash hashers
| hashes | import | repo |
| ------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------ |
| `sha2-256`, `sha2-512` | `multiformats/hashes/sha2` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/src/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) |
| `identity` | `multiformats/hashes/identity` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/src/hashes/identity.js) |
| `murmur3-128`, `murmur3-32` | `@multiformats/murmur3` | [multiformats/js-murmur3](https://github.com/multiformats/js-murmur3) |
| `blake2b-*`, `blake2s-*` | `@multiformats/blake2` | [multiformats/js-blake2](https://github.com/multiformats/js-blake2) |
### IPLD codecs (multicodec)
| codec | import | repo |
| ---------- | -------------------------- | ------------------------------------------------------------------------------------------------------ |
| `raw` | `multiformats/codecs/raw` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/src/codecs) |
| `json` | `multiformats/codecs/json` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/src/codecs) |
| `dag-cbor` | `@ipld/dag-cbor` | [ipld/js-dag-cbor](https://github.com/ipld/js-dag-cbor) |
| `dag-json` | `@ipld/dag-json` | [ipld/js-dag-json](https://github.com/ipld/js-dag-json) |
| `dag-pb` | `@ipld/dag-pb` | [ipld/js-dag-pb](https://github.com/ipld/js-dag-pb) |
| `dag-jose` | `dag-jose` | [ceramicnetwork/js-dag-jose](https://github.com/ceramicnetwork/js-dag-jose) |
## API Docs
- <https://multiformats.github.io/js-multiformats>
## License
Licensed under either of
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
## Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
File diff suppressed because one or more lines are too long
+92
View File
@@ -0,0 +1,92 @@
{
"Codec": "https://multiformats.github.io/js-multiformats/classes/bases_base10._internal_.Codec.html",
"ComposedDecoder": "https://multiformats.github.io/js-multiformats/classes/bases_base10._internal_.ComposedDecoder.html",
"Decoder": "https://multiformats.github.io/js-multiformats/classes/bases_base10._internal_.Decoder.html",
"Encoder": "https://multiformats.github.io/js-multiformats/classes/bases_base10._internal_.Encoder.html",
"Decoders": "https://multiformats.github.io/js-multiformats/types/bases_base10._internal_.Decoders.html",
"base10": "https://multiformats.github.io/js-multiformats/variables/bases_base10.base10.html",
"base16": "https://multiformats.github.io/js-multiformats/variables/bases_base16.base16.html",
"base16upper": "https://multiformats.github.io/js-multiformats/variables/bases_base16.base16upper.html",
"base2": "https://multiformats.github.io/js-multiformats/variables/bases_base2.base2.html",
"base256emoji": "https://multiformats.github.io/js-multiformats/variables/bases_base256emoji.base256emoji.html",
"base32": "https://multiformats.github.io/js-multiformats/variables/bases_base32.base32.html",
"base32hex": "https://multiformats.github.io/js-multiformats/variables/bases_base32.base32hex.html",
"base32hexpad": "https://multiformats.github.io/js-multiformats/variables/bases_base32.base32hexpad.html",
"base32hexpadupper": "https://multiformats.github.io/js-multiformats/variables/bases_base32.base32hexpadupper.html",
"base32hexupper": "https://multiformats.github.io/js-multiformats/variables/bases_base32.base32hexupper.html",
"base32pad": "https://multiformats.github.io/js-multiformats/variables/bases_base32.base32pad.html",
"base32padupper": "https://multiformats.github.io/js-multiformats/variables/bases_base32.base32padupper.html",
"base32upper": "https://multiformats.github.io/js-multiformats/variables/bases_base32.base32upper.html",
"base32z": "https://multiformats.github.io/js-multiformats/variables/bases_base32.base32z.html",
"base36": "https://multiformats.github.io/js-multiformats/variables/bases_base36.base36.html",
"base36upper": "https://multiformats.github.io/js-multiformats/variables/bases_base36.base36upper.html",
"base58btc": "https://multiformats.github.io/js-multiformats/variables/bases_base58.base58btc.html",
"base58flickr": "https://multiformats.github.io/js-multiformats/variables/bases_base58.base58flickr.html",
"base64": "https://multiformats.github.io/js-multiformats/variables/bases_base64.base64.html",
"base64pad": "https://multiformats.github.io/js-multiformats/variables/bases_base64.base64pad.html",
"base64url": "https://multiformats.github.io/js-multiformats/variables/bases_base64.base64url.html",
"base64urlpad": "https://multiformats.github.io/js-multiformats/variables/bases_base64.base64urlpad.html",
"base8": "https://multiformats.github.io/js-multiformats/variables/bases_base8.base8.html",
"identity": "https://multiformats.github.io/js-multiformats/variables/bases_identity.identity.html",
"bases": "https://multiformats.github.io/js-multiformats/variables/basics.bases.html",
"codecs": "https://multiformats.github.io/js-multiformats/variables/basics.codecs.html",
"hashes": "https://multiformats.github.io/js-multiformats/variables/basics.hashes.html",
"Block": "https://multiformats.github.io/js-multiformats/classes/block.Block.html",
"RequiredCreateOptions": "https://multiformats.github.io/js-multiformats/interfaces/block.RequiredCreateOptions.html",
"create": "https://multiformats.github.io/js-multiformats/functions/block.create.html",
"createUnsafe": "https://multiformats.github.io/js-multiformats/functions/block.createUnsafe.html",
"decode": "https://multiformats.github.io/js-multiformats/functions/block.decode.html",
"encode": "https://multiformats.github.io/js-multiformats/functions/block.encode.html",
"empty": "https://multiformats.github.io/js-multiformats/variables/bytes.empty.html",
"coerce": "https://multiformats.github.io/js-multiformats/functions/bytes.coerce.html",
"equals": "https://multiformats.github.io/js-multiformats/functions/bytes.equals.html",
"fromHex": "https://multiformats.github.io/js-multiformats/functions/bytes.fromHex.html",
"fromString": "https://multiformats.github.io/js-multiformats/functions/bytes.fromString.html",
"isBinary": "https://multiformats.github.io/js-multiformats/functions/bytes.isBinary.html",
"toHex": "https://multiformats.github.io/js-multiformats/functions/bytes.toHex.html",
"CID": "https://multiformats.github.io/js-multiformats/classes/cid.CID.html",
"format": "https://multiformats.github.io/js-multiformats/functions/cid.format.html",
"fromJSON": "https://multiformats.github.io/js-multiformats/functions/cid.fromJSON.html",
"toJSON": "https://multiformats.github.io/js-multiformats/functions/cid.toJSON.html",
"ByteView": "https://multiformats.github.io/js-multiformats/types/codecs_json.ByteView.html",
"code": "https://multiformats.github.io/js-multiformats/variables/codecs_json.code.html",
"name": "https://multiformats.github.io/js-multiformats/variables/codecs_json.name.html",
"Digest": "https://multiformats.github.io/js-multiformats/classes/hashes_digest.Digest.html",
"MultihashDigest": "https://multiformats.github.io/js-multiformats/types/hashes_digest.MultihashDigest.html",
"Hasher": "https://multiformats.github.io/js-multiformats/classes/hashes_hasher.Hasher.html",
"MultihashHasher": "https://multiformats.github.io/js-multiformats/interfaces/hashes_hasher.MultihashHasher.html",
"Await": "https://multiformats.github.io/js-multiformats/types/hashes_hasher.Await.html",
"from": "https://multiformats.github.io/js-multiformats/functions/hashes_hasher.from.html",
"sha256": "https://multiformats.github.io/js-multiformats/variables/hashes_sha2.sha256.html",
"sha512": "https://multiformats.github.io/js-multiformats/variables/hashes_sha2.sha512.html",
"encodeTo": "https://multiformats.github.io/js-multiformats/functions/index.varint.encodeTo.html",
"encodingLength": "https://multiformats.github.io/js-multiformats/functions/index.varint.encodingLength.html",
"BaseCodec": "https://multiformats.github.io/js-multiformats/interfaces/index.BaseCodec.html",
"BaseDecoder": "https://multiformats.github.io/js-multiformats/interfaces/index.BaseDecoder.html",
"BaseEncoder": "https://multiformats.github.io/js-multiformats/interfaces/index.BaseEncoder.html",
"BlockCodec": "https://multiformats.github.io/js-multiformats/interfaces/index.BlockCodec.html",
"BlockDecoder": "https://multiformats.github.io/js-multiformats/interfaces/index.BlockDecoder.html",
"BlockEncoder": "https://multiformats.github.io/js-multiformats/interfaces/index.BlockEncoder.html",
"CombobaseDecoder": "https://multiformats.github.io/js-multiformats/interfaces/index.CombobaseDecoder.html",
"LegacyLink": "https://multiformats.github.io/js-multiformats/interfaces/index.LegacyLink.html",
"Link": "https://multiformats.github.io/js-multiformats/interfaces/index.Link.html",
"LinkJSON": "https://multiformats.github.io/js-multiformats/interfaces/index.LinkJSON.html",
"MultibaseCodec": "https://multiformats.github.io/js-multiformats/interfaces/index.MultibaseCodec.html",
"MultibaseDecoder": "https://multiformats.github.io/js-multiformats/interfaces/index.MultibaseDecoder.html",
"MultibaseEncoder": "https://multiformats.github.io/js-multiformats/interfaces/index.MultibaseEncoder.html",
"Phantom": "https://multiformats.github.io/js-multiformats/interfaces/index.Phantom.html",
"SyncMultihashHasher": "https://multiformats.github.io/js-multiformats/interfaces/index.SyncMultihashHasher.html",
"UnibaseDecoder": "https://multiformats.github.io/js-multiformats/interfaces/index.UnibaseDecoder.html",
"BlockCursorView": "https://multiformats.github.io/js-multiformats/types/index.BlockCursorView.html",
"DAG_PB": "https://multiformats.github.io/js-multiformats/types/index.DAG_PB.html",
"Multibase": "https://multiformats.github.io/js-multiformats/types/index.Multibase.html",
"SHA_256": "https://multiformats.github.io/js-multiformats/types/index.SHA_256.html",
"ToString": "https://multiformats.github.io/js-multiformats/types/index.ToString.html",
"UnknownLink": "https://multiformats.github.io/js-multiformats/types/index.UnknownLink.html",
"Version": "https://multiformats.github.io/js-multiformats/types/index.Version.html",
"createLegacy": "https://multiformats.github.io/js-multiformats/functions/link.createLegacy.html",
"isLink": "https://multiformats.github.io/js-multiformats/functions/link.isLink.html",
"parse": "https://multiformats.github.io/js-multiformats/functions/link.parse.html",
"BlockView": "https://multiformats.github.io/js-multiformats/interfaces/traversal.BlockView.html",
"walk": "https://multiformats.github.io/js-multiformats/functions/traversal.walk.html"
}
+148
View File
@@ -0,0 +1,148 @@
export function or<L extends string, R extends string>(left: API.UnibaseDecoder<L> | API.CombobaseDecoder<L>, right: API.UnibaseDecoder<R> | API.CombobaseDecoder<R>): ComposedDecoder<L | R>;
/**
* @class
* @template {string} Base
* @template {string} Prefix
* @implements {API.MultibaseCodec<Prefix>}
* @implements {API.MultibaseEncoder<Prefix>}
* @implements {API.MultibaseDecoder<Prefix>}
* @implements {API.BaseCodec}
* @implements {API.BaseEncoder}
* @implements {API.BaseDecoder}
*/
export class Codec<Base extends string, Prefix extends string> implements API.MultibaseCodec<Prefix>, API.MultibaseEncoder<Prefix>, API.MultibaseDecoder<Prefix>, API.BaseCodec, API.BaseEncoder, API.BaseDecoder {
/**
* @param {Base} name
* @param {Prefix} prefix
* @param {(bytes:Uint8Array) => string} baseEncode
* @param {(text:string) => Uint8Array} baseDecode
*/
constructor(name: Base, prefix: Prefix, baseEncode: (bytes: Uint8Array) => string, baseDecode: (text: string) => Uint8Array);
name: Base;
prefix: Prefix;
baseEncode: (bytes: Uint8Array) => string;
baseDecode: (text: string) => Uint8Array;
encoder: Encoder<Base, Prefix>;
decoder: Decoder<Base, Prefix>;
/**
* @param {Uint8Array} input
*/
encode(input: Uint8Array): API.Multibase<Prefix>;
/**
* @param {string} input
*/
decode(input: string): Uint8Array;
}
export function from<Base extends string, Prefix extends string>({ name, prefix, encode, decode }: {
name: Base;
prefix: Prefix;
encode: (bytes: Uint8Array) => string;
decode: (input: string) => Uint8Array;
}): Codec<Base, Prefix>;
export function baseX<Base extends string, Prefix extends string>({ prefix, name, alphabet }: {
name: Base;
prefix: Prefix;
alphabet: string;
}): Codec<Base, Prefix>;
export function rfc4648<Base extends string, Prefix extends string>({ name, prefix, bitsPerChar, alphabet }: {
name: Base;
prefix: Prefix;
alphabet: string;
bitsPerChar: number;
}): Codec<Base, Prefix>;
export type Decoders<Prefix extends string> = Record<Prefix, API.UnibaseDecoder<Prefix>>;
import * as API from "./interface.js";
/**
* @template {string} Prefix
* @typedef {Record<Prefix, API.UnibaseDecoder<Prefix>>} Decoders
*/
/**
* @template {string} Prefix
* @implements {API.MultibaseDecoder<Prefix>}
* @implements {API.CombobaseDecoder<Prefix>}
*/
declare class ComposedDecoder<Prefix extends string> implements API.MultibaseDecoder<Prefix>, API.CombobaseDecoder<Prefix> {
/**
* @param {Decoders<Prefix>} decoders
*/
constructor(decoders: Decoders<Prefix>);
decoders: Decoders<Prefix>;
/**
* @template {string} OtherPrefix
* @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix>} decoder
* @returns {ComposedDecoder<Prefix|OtherPrefix>}
*/
or<OtherPrefix extends string>(decoder: API.UnibaseDecoder<OtherPrefix> | ComposedDecoder<OtherPrefix>): ComposedDecoder<Prefix | OtherPrefix>;
/**
* @param {string} input
* @returns {Uint8Array}
*/
decode(input: string): Uint8Array;
}
/**
* Class represents both BaseEncoder and MultibaseEncoder meaning it
* can be used to encode to multibase or base encode without multibase
* prefix.
*
* @class
* @template {string} Base
* @template {string} Prefix
* @implements {API.MultibaseEncoder<Prefix>}
* @implements {API.BaseEncoder}
*/
declare class Encoder<Base extends string, Prefix extends string> implements API.MultibaseEncoder<Prefix>, API.BaseEncoder {
/**
* @param {Base} name
* @param {Prefix} prefix
* @param {(bytes:Uint8Array) => string} baseEncode
*/
constructor(name: Base, prefix: Prefix, baseEncode: (bytes: Uint8Array) => string);
name: Base;
prefix: Prefix;
baseEncode: (bytes: Uint8Array) => string;
/**
* @param {Uint8Array} bytes
* @returns {API.Multibase<Prefix>}
*/
encode(bytes: Uint8Array): API.Multibase<Prefix>;
}
/**
* @template {string} Prefix
*/
/**
* Class represents both BaseDecoder and MultibaseDecoder so it could be used
* to decode multibases (with matching prefix) or just base decode strings
* with corresponding base encoding.
*
* @class
* @template {string} Base
* @template {string} Prefix
* @implements {API.MultibaseDecoder<Prefix>}
* @implements {API.UnibaseDecoder<Prefix>}
* @implements {API.BaseDecoder}
*/
declare class Decoder<Base extends string, Prefix extends string> implements API.MultibaseDecoder<Prefix>, API.UnibaseDecoder<Prefix>, API.BaseDecoder {
/**
* @param {Base} name
* @param {Prefix} prefix
* @param {(text:string) => Uint8Array} baseDecode
*/
constructor(name: Base, prefix: Prefix, baseDecode: (text: string) => Uint8Array);
name: Base;
prefix: Prefix;
/** @private */
private prefixCodePoint;
baseDecode: (text: string) => Uint8Array;
/**
* @param {string} text
*/
decode(text: string): Uint8Array;
/**
* @template {string} OtherPrefix
* @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix>} decoder
* @returns {ComposedDecoder<Prefix|OtherPrefix>}
*/
or<OtherPrefix extends string>(decoder: API.UnibaseDecoder<OtherPrefix> | ComposedDecoder<OtherPrefix>): ComposedDecoder<Prefix | OtherPrefix>;
}
export {};
//# sourceMappingURL=base.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../src/bases/base.js"],"names":[],"mappings":"AAoJO,8LAGJ;AAEH;;;;;;;;;;GAUG;AACH,0EAPgB,GAAG,CAAC,cAAc,CAAC,MAAM,GACzB,GAAG,CAAC,gBAAgB,CAAC,MAAM,GAC3B,GAAG,CAAC,gBAAgB,CAAC,MAAM,GAC3B,GAAG,CAAC,SAAS,EACb,GAAG,CAAC,WAAW,EACf,GAAG,CAAC,WAAW;IAG7B;;;;;OAKG;IACH,kBALW,IAAI,UACJ,MAAM,sBACC,UAAU,KAAK,MAAM,qBACtB,MAAM,KAAK,UAAU,EASrC;IANC,WAAgB;IAChB,eAAoB;IACpB,oBANgB,UAAU,KAAK,MAAM,CAMT;IAC5B,mBANe,MAAM,KAAK,UAAU,CAMR;IAC5B,+BAAoD;IACpD,+BAAoD;IAGtD;;OAEG;IACH,cAFW,UAAU,yBAIpB;IAED;;OAEG;IACH,cAFW,MAAM,cAIhB;CACF;AAYM;;;oBAJW,UAAU,KAAK,MAAM;oBACrB,MAAM,KAAK,UAAU;wBAIE;AAWlC;;;cAHI,MAAM;wBAchB;AA2GM;;;cAHI,MAAM;iBACN,MAAM;wBAahB;8CArPY,OAAO,MAAM,EAAE,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC;;AAFvD;;;GAGG;AAEH;;;;GAIG;AACH,gEAHgB,GAAG,CAAC,gBAAgB,CAAC,MAAM,GAC3B,GAAG,CAAC,gBAAgB,CAAC,MAAM;IAGzC;;OAEG;IACH,sBAFW,SAAS,MAAM,CAAC,EAI1B;IADC,2BAAwB;IAG1B;;;;OAIG;IACH,+IAEC;IAED;;;OAGG;IACH,cAHW,MAAM,GACJ,UAAU,CAUtB;CACF;AArID;;;;;;;;;;GAUG;AACH,6EAHgB,GAAG,CAAC,gBAAgB,CAAC,MAAM,GAC3B,GAAG,CAAC,WAAW;IAG7B;;;;OAIG;IACH,kBAJW,IAAI,UACJ,MAAM,sBACC,UAAU,KAAK,MAAM,EAMtC;IAHC,WAAgB;IAChB,eAAoB;IACpB,oBALgB,UAAU,KAAK,MAAM,CAKT;IAG9B;;;OAGG;IACH,cAHW,UAAU,GACR,IAAI,SAAS,CAAC,MAAM,CAAC,CAQjC;CACF;AAED;;GAEG;AACH;;;;;;;;;;;GAWG;AACH,6EAJgB,GAAG,CAAC,gBAAgB,CAAC,MAAM,GAC3B,GAAG,CAAC,cAAc,CAAC,MAAM,GACzB,GAAG,CAAC,WAAW;IAG7B;;;;OAIG;IACH,kBAJW,IAAI,UACJ,MAAM,qBACA,MAAM,KAAK,UAAU,EAYrC;IATC,WAAgB;IAChB,eAAoB;IAKpB,eAAe;IACf,wBAAoE;IACpE,mBAXe,MAAM,KAAK,UAAU,CAWR;IAG9B;;OAEG;IACH,aAFW,MAAM,cAWhB;IAED;;;;OAIG;IACH,+IAEC;CACF"}
@@ -0,0 +1,2 @@
export const base10: import("./base.js").Codec<"base10", "9">;
//# sourceMappingURL=base10.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"base10.d.ts","sourceRoot":"","sources":["../../../../src/bases/base10.js"],"names":[],"mappings":"AAEA,8DAIE"}
@@ -0,0 +1,3 @@
export const base16: import("./base.js").Codec<"base16", "f">;
export const base16upper: import("./base.js").Codec<"base16upper", "F">;
//# sourceMappingURL=base16.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"base16.d.ts","sourceRoot":"","sources":["../../../../src/bases/base16.js"],"names":[],"mappings":"AAIA,8DAKE;AAEF,wEAKE"}
@@ -0,0 +1,2 @@
export const base2: import("./base.js").Codec<"base2", "0">;
//# sourceMappingURL=base2.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"base2.d.ts","sourceRoot":"","sources":["../../../../src/bases/base2.js"],"names":[],"mappings":"AAIA,4DAKE"}
@@ -0,0 +1,2 @@
export const base256emoji: import("./base.js").Codec<"base256emoji", "🚀">;
//# sourceMappingURL=base256emoji.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"base256emoji.d.ts","sourceRoot":"","sources":["../../../../src/bases/base256emoji.js"],"names":[],"mappings":"AAiCA,2EAKE"}
@@ -0,0 +1,10 @@
export const base32: import("./base.js").Codec<"base32", "b">;
export const base32upper: import("./base.js").Codec<"base32upper", "B">;
export const base32pad: import("./base.js").Codec<"base32pad", "c">;
export const base32padupper: import("./base.js").Codec<"base32padupper", "C">;
export const base32hex: import("./base.js").Codec<"base32hex", "v">;
export const base32hexupper: import("./base.js").Codec<"base32hexupper", "V">;
export const base32hexpad: import("./base.js").Codec<"base32hexpad", "t">;
export const base32hexpadupper: import("./base.js").Codec<"base32hexpadupper", "T">;
export const base32z: import("./base.js").Codec<"base32z", "h">;
//# sourceMappingURL=base32.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"base32.d.ts","sourceRoot":"","sources":["../../../../src/bases/base32.js"],"names":[],"mappings":"AAEA,8DAKE;AAEF,wEAKE;AAEF,oEAKE;AAEF,8EAKE;AAEF,oEAKE;AAEF,8EAKE;AAEF,0EAKE;AAEF,oFAKE;AAEF,gEAKE"}
@@ -0,0 +1,3 @@
export const base36: import("./base.js").Codec<"base36", "k">;
export const base36upper: import("./base.js").Codec<"base36upper", "K">;
//# sourceMappingURL=base36.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"base36.d.ts","sourceRoot":"","sources":["../../../../src/bases/base36.js"],"names":[],"mappings":"AAEA,8DAIE;AAEF,wEAIE"}
@@ -0,0 +1,3 @@
export const base58btc: import("./base.js").Codec<"base58btc", "z">;
export const base58flickr: import("./base.js").Codec<"base58flickr", "Z">;
//# sourceMappingURL=base58.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"base58.d.ts","sourceRoot":"","sources":["../../../../src/bases/base58.js"],"names":[],"mappings":"AAEA,oEAIE;AAEF,0EAIE"}
@@ -0,0 +1,5 @@
export const base64: import("./base.js").Codec<"base64", "m">;
export const base64pad: import("./base.js").Codec<"base64pad", "M">;
export const base64url: import("./base.js").Codec<"base64url", "u">;
export const base64urlpad: import("./base.js").Codec<"base64urlpad", "U">;
//# sourceMappingURL=base64.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../../../src/bases/base64.js"],"names":[],"mappings":"AAIA,8DAKE;AAEF,oEAKE;AAEF,oEAKE;AAEF,0EAKE"}
@@ -0,0 +1,2 @@
export const base8: import("./base.js").Codec<"base8", "7">;
//# sourceMappingURL=base8.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"base8.d.ts","sourceRoot":"","sources":["../../../../src/bases/base8.js"],"names":[],"mappings":"AAIA,4DAKE"}
@@ -0,0 +1,2 @@
export const identity: import("./base.js").Codec<"identity", "\0">;
//# sourceMappingURL=identity.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../../../src/bases/identity.js"],"names":[],"mappings":"AAKA,mEAKE"}
@@ -0,0 +1,89 @@
/**
* Base encoder just encodes bytes into base encoded string.
*/
export interface BaseEncoder {
/**
* Base encodes to a **plain** (and not a multibase) string. Unlike
* `encode` no multibase prefix is added.
*
* @param bytes
*/
baseEncode: (bytes: Uint8Array) => string;
}
/**
* Base decoder decodes encoded with matching base encoding into bytes.
*/
export interface BaseDecoder {
/**
* Decodes **plain** (and not a multibase) string. Unlike
* decode
*
* @param text
*/
baseDecode: (text: string) => Uint8Array;
}
/**
* Base codec is just dual of encoder and decoder.
*/
export interface BaseCodec {
encoder: BaseEncoder;
decoder: BaseDecoder;
}
/**
* Multibase represents base encoded strings with a prefix first character
* describing it's encoding.
*/
export type Multibase<Prefix extends string> = string | string & {
[0]: Prefix;
};
/**
* Multibase encoder for the specific base encoding encodes bytes into
* multibase of that encoding.
*/
export interface MultibaseEncoder<Prefix extends string> {
/**
* Name of the encoding.
*/
name: string;
/**
* Prefix character for that base encoding.
*/
prefix: Prefix;
/**
* Encodes binary data into **multibase** string (which will have a
* prefix added).
*/
encode: (bytes: Uint8Array) => Multibase<Prefix>;
}
/**
* Interface implemented by multibase decoder, that takes multibase strings
* to bytes. It may support single encoding like base32 or multiple encodings
* like base32, base58btc, base64. If passed multibase is incompatible it will
* throw an exception.
*/
export interface MultibaseDecoder<Prefix extends string> {
/**
* Decodes **multibase** string (which must have a multibase prefix added).
* If prefix does not match
*
* @param multibase
*/
decode: (multibase: Multibase<Prefix>) => Uint8Array;
}
/**
* Dual of multibase encoder and decoder.
*/
export interface MultibaseCodec<Prefix extends string> {
name: string;
prefix: Prefix;
encoder: MultibaseEncoder<Prefix>;
decoder: MultibaseDecoder<Prefix>;
}
export interface UnibaseDecoder<Prefix extends string> extends MultibaseDecoder<Prefix> {
readonly decoders?: null;
readonly prefix: Prefix;
}
export interface CombobaseDecoder<Prefix extends string> extends MultibaseDecoder<Prefix> {
readonly decoders: Record<Prefix, UnibaseDecoder<Prefix>>;
}
//# sourceMappingURL=interface.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../../src/bases/interface.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;;OAKG;IACH,UAAU,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,MAAM,CAAA;CAC1C;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;;OAKG;IACH,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,UAAU,CAAA;CACzC;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,WAAW,CAAA;IACpB,OAAO,EAAE,WAAW,CAAA;CACrB;AAED;;;GAGG;AACH,MAAM,MAAM,SAAS,CAAC,MAAM,SAAS,MAAM,IACvC,MAAM,GACN,MAAM,GAAG;IAAE,CAAC,CAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAE5B;;;GAGG;AACH,MAAM,WAAW,gBAAgB,CAAC,MAAM,SAAS,MAAM;IACrD;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IACd;;;OAGG;IACH,MAAM,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,SAAS,CAAC,MAAM,CAAC,CAAA;CACjD;AAED;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB,CAAC,MAAM,SAAS,MAAM;IACrD;;;;;OAKG;IACH,MAAM,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,UAAU,CAAA;CACrD;AAED;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,MAAM,SAAS,MAAM;IACnD,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAA;IACjC,OAAO,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAA;CAClC;AAED,MAAM,WAAW,cAAc,CAAC,MAAM,SAAS,MAAM,CAAE,SAAQ,gBAAgB,CAAC,MAAM,CAAC;IAErF,QAAQ,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAA;IAExB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,gBAAgB,CAAC,MAAM,SAAS,MAAM,CAAE,SAAQ,gBAAgB,CAAC,MAAM,CAAC;IACvF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC,CAAA;CAC1D"}
+49
View File
@@ -0,0 +1,49 @@
import { CID } from "./index.js";
import { hasher } from "./index.js";
import { digest } from "./index.js";
import { varint } from "./index.js";
import { bytes } from "./index.js";
export const hashes: {
identity: {
code: number;
name: string;
encode: (input: Uint8Array) => Uint8Array;
digest: (input: Uint8Array) => digest.Digest<0, number>;
};
sha256: hasher.Hasher<"sha2-256", 18>;
sha512: hasher.Hasher<"sha2-512", 19>;
};
export const bases: {
base256emoji: import("./bases/base.js").Codec<"base256emoji", "🚀">;
base64: import("./bases/base.js").Codec<"base64", "m">;
base64pad: import("./bases/base.js").Codec<"base64pad", "M">;
base64url: import("./bases/base.js").Codec<"base64url", "u">;
base64urlpad: import("./bases/base.js").Codec<"base64urlpad", "U">;
base58btc: import("./bases/base.js").Codec<"base58btc", "z">;
base58flickr: import("./bases/base.js").Codec<"base58flickr", "Z">;
base36: import("./bases/base.js").Codec<"base36", "k">;
base36upper: import("./bases/base.js").Codec<"base36upper", "K">;
base32: import("./bases/base.js").Codec<"base32", "b">;
base32upper: import("./bases/base.js").Codec<"base32upper", "B">;
base32pad: import("./bases/base.js").Codec<"base32pad", "c">;
base32padupper: import("./bases/base.js").Codec<"base32padupper", "C">;
base32hex: import("./bases/base.js").Codec<"base32hex", "v">;
base32hexupper: import("./bases/base.js").Codec<"base32hexupper", "V">;
base32hexpad: import("./bases/base.js").Codec<"base32hexpad", "t">;
base32hexpadupper: import("./bases/base.js").Codec<"base32hexpadupper", "T">;
base32z: import("./bases/base.js").Codec<"base32z", "h">;
base16: import("./bases/base.js").Codec<"base16", "f">;
base16upper: import("./bases/base.js").Codec<"base16upper", "F">;
base10: import("./bases/base.js").Codec<"base10", "9">;
base8: import("./bases/base.js").Codec<"base8", "7">;
base2: import("./bases/base.js").Codec<"base2", "0">;
identity: import("./bases/base.js").Codec<"identity", "\0">;
};
export namespace codecs {
export { raw };
export { json };
}
import * as raw from "./codecs/raw.js";
import * as json from "./codecs/json.js";
export { CID, hasher, digest, varint, bytes };
//# sourceMappingURL=basics.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"basics.d.ts","sourceRoot":"","sources":["../../../src/basics.js"],"names":[],"mappings":";;;;;AAqBA;;;;;;;;;EAAuC;AADvC;;;;;;;;;;;;;;;;;;;;;;;;;EAAwI"}
+109
View File
@@ -0,0 +1,109 @@
export type RequiredCreateOptions = {
cid: CID;
};
/**
* @template {unknown} T - Logical type of the data encoded in the block
* @template {number} Code - multicodec code corresponding to codec used to encode the block
* @template {number} Alg - multicodec code corresponding to the hashing algorithm used in CID creation.
* @param {object} options
* @param {T} options.value
* @param {API.BlockEncoder<Code, T>} options.codec
* @param {API.MultihashHasher<Alg>} options.hasher
* @returns {Promise<API.BlockView<T, Code, Alg>>}
*/
export function encode<T extends unknown, Code extends number, Alg extends number>({ value, codec, hasher }: {
value: T;
codec: API.BlockEncoder<Code, T>;
hasher: API.MultihashHasher<Alg>;
}): Promise<API.BlockView<T, Code, Alg, 1>>;
/**
* @template {unknown} T - Logical type of the data encoded in the block
* @template {number} Code - multicodec code corresponding to codec used to encode the block
* @template {number} Alg - multicodec code corresponding to the hashing algorithm used in CID creation.
* @param {object} options
* @param {API.ByteView<T>} options.bytes
* @param {API.BlockDecoder<Code, T>} options.codec
* @param {API.MultihashHasher<Alg>} options.hasher
* @returns {Promise<API.BlockView<T, Code, Alg>>}
*/
export function decode<T extends unknown, Code extends number, Alg extends number>({ bytes, codec, hasher }: {
bytes: API.ByteView<T>;
codec: API.BlockDecoder<Code, T>;
hasher: API.MultihashHasher<Alg>;
}): Promise<API.BlockView<T, Code, Alg, 1>>;
/**
* @template {unknown} T - Logical type of the data encoded in the block
* @template {number} Code - multicodec code corresponding to codec used to encode the block
* @template {number} Alg - multicodec code corresponding to the hashing algorithm used in CID creation.
* @template {API.Version} V - CID version
* @param {object} options
* @param {API.Link<T, Code, Alg, V>} options.cid
* @param {API.ByteView<T>} options.bytes
* @param {API.BlockDecoder<Code, T>} options.codec
* @param {API.MultihashHasher<Alg>} options.hasher
* @returns {Promise<API.BlockView<T, Code, Alg, V>>}
*/
export function create<T extends unknown, Code extends number, Alg extends number, V extends API.Version>({ bytes, cid, hasher, codec }: {
cid: API.Link<T, Code, Alg, V>;
bytes: API.ByteView<T>;
codec: API.BlockDecoder<Code, T>;
hasher: API.MultihashHasher<Alg>;
}): Promise<API.BlockView<T, Code, Alg, V>>;
/**
* @typedef {object} RequiredCreateOptions
* @property {CID} options.cid
*/
/**
* @template {unknown} T - Logical type of the data encoded in the block
* @template {number} Code - multicodec code corresponding to codec used to encode the block
* @template {number} Alg - multicodec code corresponding to the hashing algorithm used in CID creation.
* @template {API.Version} V - CID version
* @param {{ cid: API.Link<T, Code, Alg, V>, value:T, codec?: API.BlockDecoder<Code, T>, bytes: API.ByteView<T> }|{cid:API.Link<T, Code, Alg, V>, bytes:API.ByteView<T>, value?:void, codec:API.BlockDecoder<Code, T>}} options
* @returns {API.BlockView<T, Code, Alg, V>}
*/
export function createUnsafe<T extends unknown, Code extends number, Alg extends number, V extends API.Version>({ bytes, cid, value: maybeValue, codec }: {
cid: API.Link<T, Code, Alg, V>;
value: T;
codec?: API.BlockDecoder<Code, T> | undefined;
bytes: API.ByteView<T>;
} | {
cid: API.Link<T, Code, Alg, V>;
bytes: API.ByteView<T>;
value?: void | undefined;
codec: API.BlockDecoder<Code, T>;
}): API.BlockView<T, Code, Alg, V>;
/**
* @template {unknown} T - Logical type of the data encoded in the block
* @template {number} C - multicodec code corresponding to codec used to encode the block
* @template {number} A - multicodec code corresponding to the hashing algorithm used in CID creation.
* @template {API.Version} V - CID version
* @implements {API.BlockView<T, C, A, V>}
*/
export class Block<T extends unknown, C extends number, A extends number, V extends API.Version> implements API.BlockView<T, C, A, V> {
/**
* @param {object} options
* @param {CID<T, C, A, V>} options.cid
* @param {API.ByteView<T>} options.bytes
* @param {T} options.value
*/
constructor({ cid, bytes, value }: {
cid: CID<T, C, A, V>;
bytes: API.ByteView<T>;
value: T;
});
cid: CID<T, C, A, V>;
bytes: API.ByteView<T>;
value: T;
asBlock: Block<T, C, A, V>;
links(): Iterable<[string, CID<any, number, number, API.Version>]>;
tree(): Iterable<string>;
/**
*
* @param {string} [path]
* @returns {API.BlockCursorView<unknown>}
*/
get(path?: string | undefined): API.BlockCursorView<unknown>;
}
import * as API from "./interface.js";
import { CID } from "./index.js";
//# sourceMappingURL=block.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../../src/block.js"],"names":[],"mappings":";SAwNc,GAAG;;AAlDjB;;;;;;;;;GASG;AACH;;;;4CAcC;AAED;;;;;;;;;GASG;AACH;;;;4CAUC;AA8BD;;;;;;;;;;;GAWG;AACH;;;;;4CAeC;AAvDD;;;GAGG;AAEH;;;;;;;GAOG;AACH;;;;;;;;;;mCAaC;AA3HD;;;;;;GAMG;AACH,4GAFgB,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IAGtC;;;;;OAKG;IACH;QAJoC,GAAG,EAA5B,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QACU,KAAK,EAA9B,IAAI,QAAQ,CAAC,CAAC,CAAC;QACJ,KAAK,EAAhB,CAAC;OAiBX;IAZC,qBAAc;IACd,uBAAkB;IAClB,SAAkB;IAClB,2BAAmB;IAWrB,mEAEC;IAED,yBAEC;IAED;;;;OAIG;IACH,gCAFa,IAAI,eAAe,CAAC,OAAO,CAAC,CAIxC;CACF"}
@@ -0,0 +1,58 @@
import { Link, Version } from '../link/interface.js';
import { CID } from '../cid.js';
/**
* A byte-encoded representation of some type of `Data`.
*
* A `ByteView` is essentially a `Uint8Array` that's been "tagged" with
* a `Data` type parameter indicating the type of encoded data.
*
* For example, a `ByteView<{ hello: "world" }>` is a `Uint8Array` containing a
* binary representation of a `{hello: "world"}`.
*/
export interface ByteView<Data> extends Uint8Array, Phantom<Data> {
}
declare const Marker: unique symbol;
/**
* A utility type to retain an unused type parameter `T`.
* Similar to [phantom type parameters in Rust](https://doc.rust-lang.org/rust-by-example/generics/phantom.html).
*
* Capturing unused type parameters allows us to define "nominal types," which
* TypeScript does not natively support. Nominal types in turn allow us to capture
* semantics not represented in the actual type structure, without requiring us to define
* new classes or pay additional runtime costs.
*
* For a concrete example, see {@link ByteView}, which extends the `Uint8Array` type to capture
* type information about the structure of the data encoded into the array.
*/
export interface Phantom<T> {
[Marker]?: T;
}
/**
* Represents an IPLD block (including its CID) that can be decoded to data of
* type `T`.
*
* @template T - Logical type of the data encoded in the block
* @template C - multicodec code corresponding to codec used to encode the block
* @template A - multicodec code corresponding to the hashing algorithm used in CID creation.
* @template V - CID version
*/
export interface Block<T = unknown, C extends number = number, A extends number = number, V extends Version = 1> {
bytes: ByteView<T>;
cid: Link<T, C, A, V>;
}
export type BlockCursorView<T extends unknown = unknown> = {
value: T;
remaining?: undefined;
} | {
value: CID;
remaining: string;
};
export interface BlockView<T = unknown, C extends number = number, A extends number = number, V extends Version = 1> extends Block<T, C, A, V> {
cid: CID<T, C, A, V>;
value: T;
links: () => Iterable<[string, CID]>;
tree: () => Iterable<string>;
get: (path: string) => BlockCursorView<unknown>;
}
export {};
//# sourceMappingURL=interface.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../../src/block/interface.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAE/B;;;;;;;;GAQG;AACH,MAAM,WAAW,QAAQ,CAAC,IAAI,CAAE,SAAQ,UAAU,EAAE,OAAO,CAAC,IAAI,CAAC;CAAG;AAEpE,OAAO,CAAC,MAAM,MAAM,EAAE,OAAO,MAAM,CAAA;AAEnC;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,OAAO,CAAC,CAAC;IAIxB,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAA;CACb;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,KAAK,CACpB,CAAC,GAAG,OAAO,EACX,CAAC,SAAS,MAAM,GAAG,MAAM,EACzB,CAAC,SAAS,MAAM,GAAG,MAAM,EACzB,CAAC,SAAS,OAAO,GAAG,CAAC;IAErB,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;IAClB,GAAG,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;CACtB;AAED,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IACnD;IAAE,KAAK,EAAE,CAAC,CAAC;IAAC,SAAS,CAAC,EAAE,SAAS,CAAA;CAAE,GACnC;IAAE,KAAK,EAAE,GAAG,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAA;AAErC,MAAM,WAAW,SAAS,CACxB,CAAC,GAAG,OAAO,EACX,CAAC,SAAS,MAAM,GAAG,MAAM,EACzB,CAAC,SAAS,MAAM,GAAG,MAAM,EACzB,CAAC,SAAS,OAAO,GAAG,CAAC,CACrB,SAAQ,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACzB,GAAG,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;IACpB,KAAK,EAAE,CAAC,CAAA;IAER,KAAK,EAAE,MAAM,QAAQ,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAA;IACpC,IAAI,EAAE,MAAM,QAAQ,CAAC,MAAM,CAAC,CAAA;IAC5B,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,eAAe,CAAC,OAAO,CAAC,CAAA;CAChD"}
+35
View File
@@ -0,0 +1,35 @@
/**
* @param {Uint8Array} aa
* @param {Uint8Array} bb
*/
export function equals(aa: Uint8Array, bb: Uint8Array): boolean;
/**
* @param {ArrayBufferView|ArrayBuffer|Uint8Array} o
* @returns {Uint8Array}
*/
export function coerce(o: ArrayBufferView | ArrayBuffer | Uint8Array): Uint8Array;
/**
* @param {any} o
* @returns {o is ArrayBuffer|ArrayBufferView}
*/
export function isBinary(o: any): o is ArrayBufferView | ArrayBuffer;
/**
* @param {string} hex
*/
export function fromHex(hex: string): Uint8Array;
/**
* @param {Uint8Array} d
*/
export function toHex(d: Uint8Array): string;
/**
* @param {string} str
* @returns {Uint8Array}
*/
export function fromString(str: string): Uint8Array;
/**
* @param {Uint8Array} b
* @returns {string}
*/
export function toString(b: Uint8Array): string;
export const empty: Uint8Array;
//# sourceMappingURL=bytes.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../../src/bytes.js"],"names":[],"mappings":"AAeA;;;GAGG;AACH,2BAHW,UAAU,MACV,UAAU,WAepB;AAED;;;GAGG;AACH,0BAHW,eAAe,GAAC,WAAW,GAAC,UAAU,GACpC,UAAU,CAStB;AAED;;;GAGG;AACH,4BAHW,GAAG,sCAIqC;AA7CnD;;GAEG;AACH,6BAFW,MAAM,cAKhB;AAXD;;GAEG;AACH,yBAFW,UAAU,UAEmE;AAiDxF;;;GAGG;AACH,gCAHW,MAAM,GACJ,UAAU,CAEkC;AAEzD;;;GAGG;AACH,4BAHW,UAAU,GACR,MAAM,CAEgC;AAhEnD,+BAA+B"}
+199
View File
@@ -0,0 +1,199 @@
export * from "./link/interface.js";
export function format<T extends API.Link<unknown, number, number, API.Version>, Prefix extends string>(link: T, base?: API.MultibaseEncoder<Prefix> | undefined): API.ToString<T, Prefix>;
export function toJSON<Link extends API.UnknownLink>(link: Link): API.LinkJSON<Link>;
export function fromJSON<Link extends API.UnknownLink>(json: API.LinkJSON<Link>): CID<unknown, number, number, API.Version>;
/**
* @template {unknown} [Data=unknown]
* @template {number} [Format=number]
* @template {number} [Alg=number]
* @template {API.Version} [Version=API.Version]
* @implements {API.Link<Data, Format, Alg, Version>}
*/
export class CID<Data extends unknown = unknown, Format extends number = number, Alg extends number = number, Version extends API.Version = API.Version> implements API.Link<Data, Format, Alg, Version> {
/**
* @template {unknown} Data
* @template {number} Format
* @template {number} Alg
* @template {API.Version} Version
* @param {API.Link<Data, Format, Alg, Version>} self
* @param {unknown} other
* @returns {other is CID}
*/
static equals<Data_1 extends unknown, Format_1 extends number, Alg_1 extends number, Version_1 extends API.Version>(self: API.Link<Data_1, Format_1, Alg_1, Version_1>, other: unknown): other is CID<any, number, number, API.Version>;
/**
* Takes any input `value` and returns a `CID` instance if it was
* a `CID` otherwise returns `null`. If `value` is instanceof `CID`
* it will return value back. If `value` is not instance of this CID
* class, but is compatible CID it will return new instance of this
* `CID` class. Otherwise returns null.
*
* This allows two different incompatible versions of CID library to
* co-exist and interop as long as binary interface is compatible.
*
* @template {unknown} Data
* @template {number} Format
* @template {number} Alg
* @template {API.Version} Version
* @template {unknown} U
* @param {API.Link<Data, Format, Alg, Version>|U} input
* @returns {CID<Data, Format, Alg, Version>|null}
*/
static asCID<Data_2 extends unknown, Format_2 extends number, Alg_2 extends number, Version_2 extends API.Version, U extends unknown>(input: U | API.Link<Data_2, Format_2, Alg_2, Version_2>): CID<Data_2, Format_2, Alg_2, Version_2> | null;
/**
*
* @template {unknown} Data
* @template {number} Format
* @template {number} Alg
* @template {API.Version} Version
* @param {Version} version - Version of the CID
* @param {Format} code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
* @param {API.MultihashDigest<Alg>} digest - (Multi)hash of the of the content.
* @returns {CID<Data, Format, Alg, Version>}
*/
static create<Data_3 extends unknown, Format_3 extends number, Alg_3 extends number, Version_3 extends API.Version>(version: Version_3, code: Format_3, digest: API.MultihashDigest<Alg_3>): CID<Data_3, Format_3, Alg_3, Version_3>;
/**
* Simplified version of `create` for CIDv0.
*
* @template {unknown} [T=unknown]
* @param {API.MultihashDigest<typeof SHA_256_CODE>} digest - Multihash.
* @returns {CID<T, typeof DAG_PB_CODE, typeof SHA_256_CODE, 0>}
*/
static createV0<T extends unknown = unknown>(digest: API.MultihashDigest<typeof SHA_256_CODE>): CID<T, 112, 18, 0>;
/**
* Simplified version of `create` for CIDv1.
*
* @template {unknown} Data
* @template {number} Code
* @template {number} Alg
* @param {Code} code - Content encoding format code.
* @param {API.MultihashDigest<Alg>} digest - Miltihash of the content.
* @returns {CID<Data, Code, Alg, 1>}
*/
static createV1<Data_4 extends unknown, Code extends number, Alg_4 extends number>(code: Code, digest: API.MultihashDigest<Alg_4>): CID<Data_4, Code, Alg_4, 1>;
/**
* Decoded a CID from its binary representation. The byte array must contain
* only the CID with no additional bytes.
*
* An error will be thrown if the bytes provided do not contain a valid
* binary representation of a CID.
*
* @template {unknown} Data
* @template {number} Code
* @template {number} Alg
* @template {API.Version} Ver
* @param {API.ByteView<API.Link<Data, Code, Alg, Ver>>} bytes
* @returns {CID<Data, Code, Alg, Ver>}
*/
static decode<Data_5 extends unknown, Code_1 extends number, Alg_5 extends number, Ver extends API.Version>(bytes: API.ByteView<API.Link<Data_5, Code_1, Alg_5, Ver>>): CID<Data_5, Code_1, Alg_5, Ver>;
/**
* Decoded a CID from its binary representation at the beginning of a byte
* array.
*
* Returns an array with the first element containing the CID and the second
* element containing the remainder of the original byte array. The remainder
* will be a zero-length byte array if the provided bytes only contained a
* binary CID representation.
*
* @template {unknown} T
* @template {number} C
* @template {number} A
* @template {API.Version} V
* @param {API.ByteView<API.Link<T, C, A, V>>} bytes
* @returns {[CID<T, C, A, V>, Uint8Array]}
*/
static decodeFirst<T_1 extends unknown, C extends number, A extends number, V extends API.Version>(bytes: API.ByteView<API.Link<T_1, C, A, V>>): [CID<T_1, C, A, V>, Uint8Array];
/**
* Inspect the initial bytes of a CID to determine its properties.
*
* Involves decoding up to 4 varints. Typically this will require only 4 to 6
* bytes but for larger multicodec code values and larger multihash digest
* lengths these varints can be quite large. It is recommended that at least
* 10 bytes be made available in the `initialBytes` argument for a complete
* inspection.
*
* @template {unknown} T
* @template {number} C
* @template {number} A
* @template {API.Version} V
* @param {API.ByteView<API.Link<T, C, A, V>>} initialBytes
* @returns {{ version:V, codec:C, multihashCode:A, digestSize:number, multihashSize:number, size:number }}
*/
static inspectBytes<T_2 extends unknown, C_1 extends number, A_1 extends number, V_1 extends API.Version>(initialBytes: API.ByteView<API.Link<T_2, C_1, A_1, V_1>>): {
version: V_1;
codec: C_1;
multihashCode: A_1;
digestSize: number;
multihashSize: number;
size: number;
};
/**
* Takes cid in a string representation and creates an instance. If `base`
* decoder is not provided will use a default from the configuration. It will
* throw an error if encoding of the CID is not compatible with supplied (or
* a default decoder).
*
* @template {string} Prefix
* @template {unknown} Data
* @template {number} Code
* @template {number} Alg
* @template {API.Version} Ver
* @param {API.ToString<API.Link<Data, Code, Alg, Ver>, Prefix>} source
* @param {API.MultibaseDecoder<Prefix>} [base]
* @returns {CID<Data, Code, Alg, Ver>}
*/
static parse<Prefix extends string, Data_6 extends unknown, Code_2 extends number, Alg_6 extends number, Ver_1 extends API.Version>(source: API.ToString<API.Link<Data_6, Code_2, Alg_6, Ver_1>, Prefix>, base?: API.MultibaseDecoder<Prefix> | undefined): CID<Data_6, Code_2, Alg_6, Ver_1>;
/**
* @param {Version} version - Version of the CID
* @param {Format} code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
* @param {API.MultihashDigest<Alg>} multihash - (Multi)hash of the of the content.
* @param {Uint8Array} bytes
*
*/
constructor(version: Version, code: Format, multihash: API.MultihashDigest<Alg>, bytes: Uint8Array);
/** @readonly */
readonly code: Format;
/** @readonly */
readonly version: Version;
/** @readonly */
readonly multihash: API.MultihashDigest<Alg>;
/** @readonly */
readonly bytes: Uint8Array;
/** @readonly */
readonly '/': Uint8Array;
/**
* Signalling `cid.asCID === cid` has been replaced with `cid['/'] === cid.bytes`
* please either use `CID.asCID(cid)` or switch to new signalling mechanism
*
* @deprecated
*/
get asCID(): CID<Data, Format, Alg, Version>;
get byteOffset(): number;
get byteLength(): number;
/**
* @returns {CID<Data, API.DAG_PB, API.SHA_256, 0>}
*/
toV0(): CID<Data, API.DAG_PB, API.SHA_256, 0>;
/**
* @returns {CID<Data, Format, Alg, 1>}
*/
toV1(): CID<Data, Format, Alg, 1>;
/**
* @param {unknown} other
* @returns {other is CID<Data, Format, Alg, Version>}
*/
equals(other: unknown): other is CID<Data, Format, Alg, Version>;
/**
* @param {API.MultibaseEncoder<string>} [base]
* @returns {string}
*/
toString(base?: API.MultibaseEncoder<string> | undefined): string;
toJSON(): {
'/': API.ToString<CID<Data, Format, Alg, Version>, string>;
};
link(): CID<Data, Format, Alg, Version>;
get [Symbol.toStringTag](): string;
}
import * as API from "./link/interface.js";
declare const SHA_256_CODE: 18;
declare const DAG_PB_CODE: 112;
//# sourceMappingURL=cid.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"cid.d.ts","sourceRoot":"","sources":["../../../src/cid.js"],"names":[],"mappings":";AAmBO,2LAgBN;AAOM,qFAEL;AAMK,4HACe;AAmBtB;;;;;;GAMG;AAEH,oKAHgB,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO;IAgHjD;;;;;;;;OAQG;IACH,+KAHW,OAAO,kDAcjB;IA4BD;;;;;;;;;;;;;;;;;OAiBG;IACH,+OAoCC;IAED;;;;;;;;;;OAUG;IACH,qOA2BC;IAED;;;;;;OAMG;IACH,qDAHW,IAAI,eAAe,CAAC,mBAAmB,CAAC,sBAKlD;IAED;;;;;;;;;OASG;IACH,gKAEC;IAED;;;;;;;;;;;;;OAaG;IACH,wMAMC;IAED;;;;;;;;;;;;;;;OAeG;IACH,iLAuBC;IAED;;;;;;;;;;;;;;;OAeG;IACH;;;;oBAF+D,MAAM;uBAAgB,MAAM;cAAO,MAAM;MA+BvG;IAED;;;;;;;;;;;;;;OAcG;IACH,8RAaC;IA/ZD;;;;;;OAMG;IACH,qBANW,OAAO,QACP,MAAM,aACN,IAAI,eAAe,CAAC,GAAG,CAAC,SACxB,UAAU,EAiBpB;IAbC,gBAAgB;IAChB,sBAAgB;IAChB,gBAAgB;IAChB,0BAAsB;IACtB,gBAAgB;IAChB,6CAA0B;IAC1B,gBAAgB;IAChB,2BAAkB;IAIlB,gBAAgB;IAChB,yBAAiB;IAGnB;;;;;OAKG;IACH,6CAEC;IAGD,yBAEC;IAGD,yBAEC;IAED;;OAEG;IACH,QAFa,IAAI,IAAI,EAAE,IAAI,MAAM,EAAE,IAAI,OAAO,EAAE,CAAC,CAAC,CA+BjD;IAED;;OAEG;IACH,QAFa,IAAI,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,CAoBrC;IAED;;;OAGG;IACH,cAHW,OAAO,4CAKjB;IAwBD;;;OAGG;IACH,2DAFa,MAAM,CAIlB;IAED;;MAEC;IAED,wCAEC;IAED,mCAEC;CA4QF;;AAkFD,+BAAyB;AADzB,+BAAwB"}
@@ -0,0 +1,23 @@
import type { ByteView } from '../block/interface.js';
/**
* IPLD encoder part of the codec.
*/
export interface BlockEncoder<Code extends number, T> {
name: string;
code: Code;
encode: (data: T) => ByteView<T>;
}
/**
* IPLD decoder part of the codec.
*/
export interface BlockDecoder<Code extends number, T> {
code: Code;
decode: (bytes: ByteView<T>) => T;
}
/**
* An IPLD codec is a combination of both encoder and decoder.
*/
export interface BlockCodec<Code extends number, T> extends BlockEncoder<Code, T>, BlockDecoder<Code, T> {
}
export type { ByteView };
//# sourceMappingURL=interface.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../../src/codecs/interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAErD;;GAEG;AACH,MAAM,WAAW,YAAY,CAAC,IAAI,SAAS,MAAM,EAAE,CAAC;IAClD,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,IAAI,CAAA;IACV,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAA;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,YAAY,CAAC,IAAI,SAAS,MAAM,EAAE,CAAC;IAClD,IAAI,EAAE,IAAI,CAAA;IACV,MAAM,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,UAAU,CAAC,IAAI,SAAS,MAAM,EAAE,CAAC,CAAE,SAAQ,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC;CAAG;AAE3G,YAAY,EAAE,QAAQ,EAAE,CAAA"}
@@ -0,0 +1,6 @@
export const name: "json";
export const code: 512;
export function encode<T>(node: T): import("./interface.js").ByteView<T>;
export function decode<T>(data: import("./interface.js").ByteView<T>): T;
export type ByteView<T> = import('./interface.js').ByteView<T>;
//# sourceMappingURL=json.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../../../src/codecs/json.js"],"names":[],"mappings":"AAUA,0BAA0B;AAC1B,uBAA0B;AAOnB,yEAAiE;AAOjE,yEAA6D;0BArBvD,OAAO,gBAAgB,EAAE,QAAQ,CAAC,CAAC,CAAC"}
+10
View File
@@ -0,0 +1,10 @@
/**
* @template T
* @typedef {import('./interface.js').ByteView<T>} ByteView
*/
export const name: "raw";
export const code: 85;
export function encode(node: Uint8Array): ByteView<Uint8Array>;
export function decode(data: ByteView<Uint8Array>): Uint8Array;
export type ByteView<T> = import('./interface.js').ByteView<T>;
//# sourceMappingURL=raw.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"raw.d.ts","sourceRoot":"","sources":["../../../../src/codecs/raw.js"],"names":[],"mappings":"AAIA;;;GAGG;AAEH,yBAAyB;AACzB,sBAAwB;AAMjB,6BAHI,UAAU,GACR,SAAS,UAAU,CAAC,CAEW;AAMrC,6BAHI,SAAS,UAAU,CAAC,GAClB,UAAU,CAEqB;0BAhB/B,OAAO,gBAAgB,EAAE,QAAQ,CAAC,CAAC,CAAC"}
@@ -0,0 +1,32 @@
export function create<Code extends number>(code: Code, digest: Uint8Array): Digest<Code, number>;
export function decode(multihash: Uint8Array): MultihashDigest;
export function equals(a: MultihashDigest, b: unknown): b is import("./interface.js").MultihashDigest<number>;
/**
* @typedef {import('./interface.js').MultihashDigest} MultihashDigest
*/
/**
* Represents a multihash digest which carries information about the
* hashing algorithm and an actual hash digest.
*
* @template {number} Code
* @template {number} Size
* @class
* @implements {MultihashDigest}
*/
export class Digest<Code extends number, Size extends number> implements MultihashDigest {
/**
* Creates a multihash digest.
*
* @param {Code} code
* @param {Size} size
* @param {Uint8Array} digest
* @param {Uint8Array} bytes
*/
constructor(code: Code, size: Size, digest: Uint8Array, bytes: Uint8Array);
code: Code;
size: Size;
digest: Uint8Array;
bytes: Uint8Array;
}
export type MultihashDigest = import('./interface.js').MultihashDigest;
//# sourceMappingURL=digest.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"digest.d.ts","sourceRoot":"","sources":["../../../../src/hashes/digest.js"],"names":[],"mappings":"AAUO,gEAFI,UAAU,wBAapB;AAQM,kCAHI,UAAU,GACR,eAAe,CAa3B;AAOM,0BAJI,eAAe,KACf,OAAO,yDAgBjB;AAED;;GAEG;AAEH;;;;;;;;GAQG;AACH;IACE;;;;;;;OAOG;IACH,kBALW,IAAI,QACJ,IAAI,UACJ,UAAU,SACV,UAAU,EAOpB;IAJC,WAAgB;IAChB,WAAgB;IAChB,mBAAoB;IACpB,kBAAkB;CAErB;8BA3BY,OAAO,gBAAgB,EAAE,eAAe"}
@@ -0,0 +1,35 @@
export function from<Name extends string, Code extends number>({ name, code, encode }: {
name: Name;
code: Code;
encode: (input: Uint8Array) => Await<Uint8Array>;
}): Hasher<Name, Code>;
/**
* Hasher represents a hashing algorithm implementation that produces as
* `MultihashDigest`.
*
* @template {string} Name
* @template {number} Code
* @class
* @implements {MultihashHasher<Code>}
*/
export class Hasher<Name extends string, Code extends number> implements MultihashHasher<Code> {
/**
*
* @param {Name} name
* @param {Code} code
* @param {(input: Uint8Array) => Await<Uint8Array>} encode
*/
constructor(name: Name, code: Code, encode: (input: Uint8Array) => Await<Uint8Array>);
name: Name;
code: Code;
encode: (input: Uint8Array) => Await<Uint8Array>;
/**
* @param {Uint8Array} input
* @returns {Await<Digest.Digest<Code, number>>}
*/
digest(input: Uint8Array): Await<Digest.Digest<Code, number>>;
}
export type MultihashHasher<Alg extends number> = import('./interface.js').MultihashHasher;
export type Await<T> = Promise<T> | T;
import * as Digest from "./digest.js";
//# sourceMappingURL=hasher.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"hasher.d.ts","sourceRoot":"","sources":["../../../../src/hashes/hasher.js"],"names":[],"mappings":"AAUO;;;oBAFY,UAAU,KAAK,MAAM,UAAU,CAAC;uBAE2B;AAE9E;;;;;;;;GAQG;AACH,yFAFgC,IAAI;IAGlC;;;;;OAKG;IACH,kBAJW,IAAI,QACJ,IAAI,kBACI,UAAU,KAAK,MAAM,UAAU,CAAC,EAMlD;IAHC,WAAgB;IAChB,WAAgB;IAChB,gBALiB,UAAU,KAAK,MAAM,UAAU,CAAC,CAK7B;IAGtB;;;OAGG;IACH,cAHW,UAAU,GACR,MAAM,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAa9C;CACF;kDAIY,OAAO,gBAAgB,EAAE,eAAe;uBAKxC,QAAQ,CAAC,CAAC,GAAC,CAAC"}
@@ -0,0 +1,18 @@
export namespace identity {
export { code };
export { name };
export { encode };
export { digest };
}
declare const code: 0;
declare const name: "identity";
/** @type {(input:Uint8Array) => Uint8Array} */
declare const encode: (input: Uint8Array) => Uint8Array;
/**
* @param {Uint8Array} input
* @returns {Digest.Digest<typeof code, number>}
*/
declare function digest(input: Uint8Array): Digest.Digest<typeof code, number>;
import * as Digest from "./digest.js";
export {};
//# sourceMappingURL=identity.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../../../src/hashes/identity.js"],"names":[],"mappings":";;;;;;AAGA,sBAAgB;AAChB,+BAAuB;AAEvB,+CAA+C;AAC/C,8BADkB,UAAU,KAAK,UAAU,CACtB;AAErB;;;GAGG;AACH,+BAHW,UAAU,GACR,aAAa,CAAC,WAAW,EAAE,MAAM,CAAC,CAEa"}
@@ -0,0 +1,59 @@
/**
* Represents a multihash digest which carries information about the
* hashing algorithm and an actual hash digest.
*/
export interface MultihashDigest<Code extends number = number> {
/**
* Code of the multihash
*/
code: Code;
/**
* Raw digest (without a hashing algorithm info)
*/
digest: Uint8Array;
/**
* byte length of the `this.digest`
*/
size: number;
/**
* Binary representation of this multihash digest.
*/
bytes: Uint8Array;
}
/**
* Hasher represents a hashing algorithm implementation that produces as
* `MultihashDigest`.
*/
export interface MultihashHasher<Code extends number = number> {
/**
* Takes binary `input` and returns it (multi) hash digest. Return value is
* either promise of a digest or a digest. This way general use can `await`
* while performance critical code may asses return value to decide whether
* await is needed.
*
* @param {Uint8Array} input
*/
digest: (input: Uint8Array) => Promise<MultihashDigest<Code>> | MultihashDigest<Code>;
/**
* Name of the multihash
*/
name: string;
/**
* Code of the multihash
*/
code: Code;
}
/**
* Sync variant of `MultihashHasher` that refines return type of the `digest`
* to `MultihashDigest`. It is subtype of `MultihashHasher` so implementations
* of this interface can be passed anywhere `MultihashHasher` is expected,
* allowing consumer to either `await` or check the return type to decide
* whether to await or proceed with return value.
*
* `SyncMultihashHasher` is useful in certain APIs where async hashing would be
* impractical e.g. implementation of Hash Array Mapped Trie (HAMT).
*/
export interface SyncMultihashHasher<Code extends number = number> extends MultihashHasher<Code> {
digest: (input: Uint8Array) => MultihashDigest<Code>;
}
//# sourceMappingURL=interface.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../../src/hashes/interface.ts"],"names":[],"mappings":"AAEA;;;GAGG;AAMH,MAAM,WAAW,eAAe,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM;IAC3D;;OAEG;IACH,IAAI,EAAE,IAAI,CAAA;IAEV;;OAEG;IACH,MAAM,EAAE,UAAU,CAAA;IAElB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,KAAK,EAAE,UAAU,CAAA;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM;IAC3D;;;;;;;OAOG;IACH,MAAM,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,GAAG,eAAe,CAAC,IAAI,CAAC,CAAA;IAErF;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,IAAI,EAAE,IAAI,CAAA;CACX;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,mBAAmB,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,eAAe,CAAC,IAAI,CAAC;IAC9F,MAAM,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,eAAe,CAAC,IAAI,CAAC,CAAA;CACrD"}
@@ -0,0 +1,3 @@
export const sha256: import("./hasher.js").Hasher<"sha2-256", 18>;
export const sha512: import("./hasher.js").Hasher<"sha2-512", 19>;
//# sourceMappingURL=sha2-browser.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"sha2-browser.d.ts","sourceRoot":"","sources":["../../../../src/hashes/sha2-browser.js"],"names":[],"mappings":"AAaA,kEAIE;AAEF,kEAIE"}
@@ -0,0 +1,3 @@
export const sha256: import("./hasher.js").Hasher<"sha2-256", 18>;
export const sha512: import("./hasher.js").Hasher<"sha2-512", 19>;
//# sourceMappingURL=sha2.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"sha2.d.ts","sourceRoot":"","sources":["../../../../src/hashes/sha2.js"],"names":[],"mappings":"AAMA,kEAIE;AAEF,kEAIE"}
+8
View File
@@ -0,0 +1,8 @@
export * from "./interface.js";
import { CID } from "./cid.js";
import * as hasher from "./hashes/hasher.js";
import * as digest from "./hashes/digest.js";
import * as varint from "./varint.js";
import * as bytes from "./bytes.js";
export { CID, hasher, digest, varint, bytes };
//# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.js"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
export * from './bases/interface.js';
export * from './hashes/interface.js';
export * from './codecs/interface.js';
export * from './link/interface.js';
export * from './block/interface.js';
//# sourceMappingURL=interface.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/interface.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA;AACpC,cAAc,uBAAuB,CAAA;AACrC,cAAc,uBAAuB,CAAA;AACrC,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA"}
+14
View File
@@ -0,0 +1,14 @@
export * from "./link/interface.js";
export function createLegacy(digest: API.MultihashDigest<typeof SHA_256_CODE>): API.LegacyLink;
export function create<Data extends unknown, Code extends number, Alg extends number>(code: Code, digest: API.MultihashDigest<Alg>): API.Link<Data, Code, Alg, 1>;
export function isLink<L extends API.Link<unknown, number, number, 0 | 1>>(value: unknown): value is L & CID<any, number, number, API.Version>;
export function parse<Prefix extends string, Data extends unknown, Code extends number, Alg extends number, Ver extends API.Version>(source: API.ToString<API.Link<Data, Code, Alg, Ver>, Prefix>, base?: API.MultibaseDecoder<Prefix> | undefined): API.Link<Data, Code, Alg, Ver>;
export function decode<Data extends unknown, Code extends number, Alg extends number, Ver extends API.Version>(bytes: API.ByteView<API.Link<Data, Code, Alg, Ver>>): API.Link<Data, Code, Alg, Ver>;
import * as API from "./link/interface.js";
declare const SHA_256_CODE: 18;
import { CID } from "./cid.js";
import { format } from "./cid.js";
import { toJSON } from "./cid.js";
import { fromJSON } from "./cid.js";
export { format, toJSON, fromJSON };
//# sourceMappingURL=link.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../../src/link.js"],"names":[],"mappings":";AAiBO,qCAHI,IAAI,eAAe,CAAC,mBAAmB,CAAC,GACtC,IAAI,UAAU,CAE6C;AAYjE,kKAA4D;AAS5D,+IAkBN;AAiBM,oRAAuD;AAkBvD,oMAAyC;;AAlFhD,+BAAyB"}
@@ -0,0 +1,36 @@
import type { MultihashDigest } from '../hashes/interface.js';
import type { MultibaseEncoder, MultibaseDecoder, Multibase } from '../bases/interface.js';
import type { Phantom, ByteView } from '../block/interface.js';
export type { MultihashDigest, MultibaseEncoder, MultibaseDecoder };
export type Version = 0 | 1;
export type DAG_PB = 0x70;
export type SHA_256 = 0x12;
/**
* Represents an IPLD link to a specific data of type `T`.
*
* @template T - Logical type of the data being linked to.
* @template C - multicodec code corresponding to a codec linked data is encoded with
* @template A - multicodec code corresponding to the hashing algorithm of the CID
* @template V - CID version
*/
export interface Link<Data extends unknown = unknown, Format extends number = number, Alg extends number = number, V extends Version = 1> extends Phantom<Data> {
readonly version: V;
readonly code: Format;
readonly multihash: MultihashDigest<Alg>;
readonly byteOffset: number;
readonly byteLength: number;
readonly bytes: ByteView<Link<Data, Format, Alg, V>>;
equals: (other: unknown) => other is Link<Data, Format, Alg, Version>;
toString: <Prefix extends string>(base?: MultibaseEncoder<Prefix>) => ToString<Link<Data, Format, Alg, Version>, Prefix>;
link: () => Link<Data, Format, Alg, V>;
toV1: () => Link<Data, Format, Alg, 1>;
}
export interface LinkJSON<T extends UnknownLink = UnknownLink> {
'/': ToString<T>;
}
export interface LegacyLink<T extends unknown = unknown> extends Link<T, DAG_PB, SHA_256, 0> {
}
export type UnknownLink = LegacyLink<unknown> | Link<unknown, number, number, Version>;
export type ToString<T, Prefix extends string = string> = Multibase<Prefix> & Phantom<T>;
export type { ByteView };
//# sourceMappingURL=interface.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../../src/link/interface.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAC1F,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAE9D,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,CAAA;AACnE,MAAM,MAAM,OAAO,GAAG,CAAC,GAAG,CAAC,CAAA;AAE3B,MAAM,MAAM,MAAM,GAAG,IAAI,CAAA;AACzB,MAAM,MAAM,OAAO,GAAG,IAAI,CAAA;AAE1B;;;;;;;GAOG;AACH,MAAM,WAAW,IAAI,CACnB,IAAI,SAAS,OAAO,GAAG,OAAO,EAC9B,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,GAAG,SAAS,MAAM,GAAG,MAAM,EAC3B,CAAC,SAAS,OAAO,GAAG,CAAC,CACnB,SAAQ,OAAO,CAAC,IAAI,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAA;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,SAAS,EAAE,eAAe,CAAC,GAAG,CAAC,CAAA;IAExC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAA;IAEpD,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,CAAA;IAErE,QAAQ,EAAE,CAAC,MAAM,SAAS,MAAM,EAAE,IAAI,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,KAAK,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,CAAA;IACxH,IAAI,EAAE,MAAM,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,CAAA;IAEtC,IAAI,EAAE,MAAM,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,CAAA;CACvC;AAED,MAAM,WAAW,QAAQ,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW;IAC3D,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;CACjB;AAED,MAAM,WAAW,UAAU,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,CAAE,SAAQ,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;CAC3F;AAED,MAAM,MAAM,WAAW,GACnB,UAAU,CAAC,OAAO,CAAC,GACnB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;AAE1C,MAAM,MAAM,QAAQ,CAAC,CAAC,EAAE,MAAM,SAAS,MAAM,GAAG,MAAM,IAAI,SAAS,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;AAExF,YAAY,EAAE,QAAQ,EAAE,CAAA"}
+27
View File
@@ -0,0 +1,27 @@
export type CID<C = number, A = number, V = 0 | 1> = import('./cid').CID<unknown, C, A, V>;
export type BlockView<T = unknown, C = number, A = number, V = 0 | 1> = import('./block/interface.js').BlockView<T, C, A, V>;
/**
* @template [C=number] - multicodec code corresponding to codec used to encode the block
* @template [A=number] - multicodec code corresponding to the hashing algorithm used in CID creation.
* @template [V=0|1] - CID version
* @typedef {import('./cid').CID<unknown, C, A, V>} CID
*/
/**
* @template [T=unknown] - Logical type of the data encoded in the block
* @template [C=number] - multicodec code corresponding to codec used to encode the block
* @template [A=number] - multicodec code corresponding to the hashing algorithm used in CID creation.
* @template [V=0|1] - CID version
* @typedef {import('./block/interface.js').BlockView<T, C, A, V>} BlockView
*/
/**
* @param {object} options
* @param {CID} options.cid
* @param {(cid: CID) => Promise<BlockView|null>} options.load
* @param {Set<string>} [options.seen]
*/
export function walk({ cid, load, seen }: {
cid: CID;
load: (cid: CID) => Promise<BlockView | null>;
seen?: Set<string> | undefined;
}): Promise<void>;
//# sourceMappingURL=traversal.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"traversal.d.ts","sourceRoot":"","sources":["../../../src/traversal.js"],"names":[],"mappings":"qDAMa,OAAO,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;wEAQrC,OAAO,sBAAsB,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;AAZjE;;;;;GAKG;AAEH;;;;;;GAMG;AAEH;;;;;GAKG;AACH;SAJW,GAAG;gBACG,GAAG,KAAK,QAAQ,SAAS,GAAC,IAAI,CAAC;;kBAoB/C"}
+4
View File
@@ -0,0 +1,4 @@
export function decode(data: Uint8Array, offset?: number | undefined): [number, number];
export function encodeTo(int: number, target: Uint8Array, offset?: number | undefined): Uint8Array;
export function encodingLength(int: number): number;
//# sourceMappingURL=varint.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"varint.d.ts","sourceRoot":"","sources":["../../../src/varint.js"],"names":[],"mappings":"AAOO,6BAJI,UAAU,gCAER,CAAC,MAAM,EAAE,MAAM,CAAC,CAK5B;AAOM,8BAJI,MAAM,UACN,UAAU,2CAMpB;AAMM,oCAHI,MAAM,GACJ,MAAM,CAIlB"}
@@ -0,0 +1,8 @@
declare const _default: {
code: number;
size: number;
hex: string;
message: string;
}[];
export default _default;
//# sourceMappingURL=invalid-multihash.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"invalid-multihash.d.ts","sourceRoot":"","sources":["../../../../test/fixtures/invalid-multihash.js"],"names":[],"mappings":""}
@@ -0,0 +1,19 @@
declare const _default: ({
encoding: {
code: number;
name: string;
varint?: undefined;
};
hex: string;
size: number;
} | {
encoding: {
code: number;
name: string;
varint: string;
};
hex: string;
size: number;
})[];
export default _default;
//# sourceMappingURL=valid-multihash.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"valid-multihash.d.ts","sourceRoot":"","sources":["../../../../test/fixtures/valid-multihash.js"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=test-block.spec.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"test-block.spec.d.ts","sourceRoot":"","sources":["../../../test/test-block.spec.js"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=test-bytes.spec.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"test-bytes.spec.d.ts","sourceRoot":"","sources":["../../../test/test-bytes.spec.js"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=test-cid.spec.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"test-cid.spec.d.ts","sourceRoot":"","sources":["../../../test/test-cid.spec.js"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=test-link.spec.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"test-link.spec.d.ts","sourceRoot":"","sources":["../../../test/test-link.spec.js"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=test-multibase-spec.spec.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"test-multibase-spec.spec.d.ts","sourceRoot":"","sources":["../../../test/test-multibase-spec.spec.js"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=test-multibase.spec.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"test-multibase.spec.d.ts","sourceRoot":"","sources":["../../../test/test-multibase.spec.js"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=test-multicodec.spec.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"test-multicodec.spec.d.ts","sourceRoot":"","sources":["../../../test/test-multicodec.spec.js"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=test-multihash.spec.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"test-multihash.spec.d.ts","sourceRoot":"","sources":["../../../test/test-multihash.spec.js"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
export type CID = import('../src/cid.js').CID;
//# sourceMappingURL=test-traversal.spec.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"test-traversal.spec.d.ts","sourceRoot":"","sources":["../../../test/test-traversal.spec.js"],"names":[],"mappings":"kBAQc,OAAO,eAAe,EAAE,GAAG"}
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=test-varint.spec.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"test-varint.spec.d.ts","sourceRoot":"","sources":["../../../test/test-varint.spec.js"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
declare const main: () => Promise<void>;
export default main;
//# sourceMappingURL=main.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../../../../test/ts-use/src/main.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,IAAI,qBAST,CAAA;AAED,eAAe,IAAI,CAAA"}
+31
View File
@@ -0,0 +1,31 @@
import * as Block from 'multiformats/block'
import * as codec from '@ipld/dag-cbor'
import { sha256 as hasher } from 'multiformats/hashes/sha2'
async function run () {
const value = { hello: 'world' }
// encode a block
const block = await Block.encode({ value, codec, hasher })
// block.value --> { hello: 'world' }
// block.bytes --> Uint8Array
// block.cid --> CID() w/ sha2-256 hash address and dag-cbor codec
console.log('Example block CID: ' + block.cid.toString())
// you can also decode blocks from their binary state
const block2 = await Block.decode({ bytes: block.bytes, codec, hasher })
// check for equivalency using cid interface
console.log('Example block CID equal to decoded binary block: ' + block.cid.equals(block2.cid))
// if you have the cid you can also verify the hash on decode
const block3 = await Block.create({ bytes: block.bytes, cid: block.cid, codec, hasher })
console.log('Example block CID equal to block created from CID + bytes: ' + block.cid.equals(block3.cid))
}
run().catch((err) => {
console.error(err)
process.exit(1)
})
+66
View File
@@ -0,0 +1,66 @@
import assert from 'assert'
import { CID } from 'multiformats/cid'
import * as json from 'multiformats/codecs/json'
import { sha256 } from 'multiformats/hashes/sha2'
import { base64 } from 'multiformats/bases/base64'
async function run () {
// ** PART 1: CREATING A NEW CID **
// Arbitrary input value
const value = { hello: 'world' }
// Encoded Uint8array representation of `value` using the plain JSON IPLD codec
const bytes = json.encode(value)
// Hash Uint8array representation
const hash = await sha256.digest(bytes)
// Create CID (default base32)
const cid = CID.create(1, json.code, hash)
// cid.code --> 512 (0x0200) JSON IPLD codec)
// cid.version --> 1
// cid.multihash --> digest, including code (18 for sha2-256), digest size (32 bytes)
// cid.bytes --> byte representation`
console.log('Example CID: ' + cid.toString())
// 'bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea'
// ** PART 2: MULTIBASE ENCODERS / DECODERS / CODECS **
// Encode CID from part 1 to base64, decode back to base32
const cidBase64 = cid.toString(base64.encoder)
console.log('base64 encoded CID: ' + cidBase64)
// 'mAYAEEiCTojlxqRTl6svwqNJRVM2jCcPBxy+7mRTUfGDzy2gViA'
const cidBase32 = CID.parse(cidBase64, base64.decoder)
// 'bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea'
// test decoded CID against original
assert.strictEqual(cidBase32.toString(), cid.toString(), 'Warning: decoded base32 CID does not match original')
console.log('Decoded CID equal to original base32: ' + cidBase32.equals(cid)) // alternatively, use more robust built-in function to test equivalence
// Multibase codec exposes both encoder and decoder properties
cid.toString(base64)
CID.parse(cid.toString(base64), base64)
// ** PART 3: CID BASE CONFIGURATIONS **
// CID v1 default encoding is base32
const v1 = CID.parse('bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea')
v1.toString()
// 'bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea'
// CID v0 default encoding is base58btc
const v0 = CID.parse('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')
v0.toString()
// 'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n'
v0.toV1().toString()
// 'bafybeihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku'
}
run().catch((err) => {
console.error(err)
process.exit(1)
})
@@ -0,0 +1,13 @@
// Example of multicodec implementation for JSON (UTF-8-encoded)
// Codec implementations should conform to the BlockCodec interface which implements both BlockEncoder and BlockDecoder
/**
* @template T
* @type {BlockCodec<0x0200, T>}
*/
export const { name, code, encode, decode } = {
name: 'json',
code: 0x0200,
encode: json => new TextEncoder().encode(JSON.stringify(json)),
decode: bytes => JSON.parse(new TextDecoder().decode(bytes))
}

Some files were not shown because too many files have changed in this diff Show More