Compare commits
No commits in common. "v0.1.0-develop.50" and "v0.1.0-develop.49" have entirely different histories.
v0.1.0-dev
...
v0.1.0-dev
|
@ -1,10 +1,3 @@
|
|||
# [0.1.0-develop.50](https://git.lumeweb.com/LumeWeb/libs5/compare/v0.1.0-develop.49...v0.1.0-develop.50) (2023-09-07)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add CID.fromHash ([4a157d9](https://git.lumeweb.com/LumeWeb/libs5/commit/4a157d9ecaa74eb9ff17d33398aa06ecf2b07607))
|
||||
|
||||
# [0.1.0-develop.49](https://git.lumeweb.com/LumeWeb/libs5/compare/v0.1.0-develop.48...v0.1.0-develop.49) (2023-09-07)
|
||||
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "@lumeweb/libs5",
|
||||
"version": "0.1.0-develop.50",
|
||||
"version": "0.1.0-develop.49",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@lumeweb/libs5",
|
||||
"version": "0.1.0-develop.50",
|
||||
"version": "0.1.0-develop.49",
|
||||
"dependencies": {
|
||||
"@noble/curves": "^1.1.0",
|
||||
"@noble/hashes": "^1.3.1",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@lumeweb/libs5",
|
||||
"version": "0.1.0-develop.50",
|
||||
"version": "0.1.0-develop.49",
|
||||
"type": "module",
|
||||
"main": "lib/index.js",
|
||||
"repository": {
|
||||
|
|
17
src/cid.ts
17
src/cid.ts
|
@ -3,7 +3,6 @@ import { Multihash } from "#multihash.js";
|
|||
import { CID_TYPES, REGISTRY_TYPES } from "#constants.js";
|
||||
import { decodeEndian, encodeEndian } from "#util.js";
|
||||
import { concatBytes, equalBytes } from "@noble/curves/abstract/utils";
|
||||
import { hexToBytes } from "@noble/hashes/utils";
|
||||
|
||||
export default class CID extends Multibase {
|
||||
type: number;
|
||||
|
@ -26,22 +25,6 @@ export default class CID extends Multibase {
|
|||
return CID._init(bytes);
|
||||
}
|
||||
|
||||
static fromHash(
|
||||
bytes: string | Uint8Array,
|
||||
size: number,
|
||||
type = CID_TYPES.RAW,
|
||||
): CID {
|
||||
if (typeof bytes === "string") {
|
||||
bytes = hexToBytes(bytes);
|
||||
}
|
||||
|
||||
if (!Object.values(CID_TYPES).includes(type)) {
|
||||
throw new Error(`invalid cid type ${type}`);
|
||||
}
|
||||
|
||||
return new CID(type, new Multihash(bytes), size);
|
||||
}
|
||||
|
||||
private static _init(bytes: Uint8Array): CID {
|
||||
const type = bytes[0];
|
||||
if (type === CID_TYPES.BRIDGE) {
|
||||
|
|
Loading…
Reference in New Issue