@ensdomains/content-hash
Advanced tools
Comparing version 3.0.0-beta.3 to 3.0.0-beta.4
@@ -1,7 +0,1 @@ | ||
{ | ||
"type": "commonjs", | ||
"dependencies": { | ||
"@multiformats/sha3": "^2.0.17", | ||
"multiformats": "^12.0.1" | ||
} | ||
} | ||
{"type":"commonjs"} |
@@ -10,7 +10,5 @@ "use strict"; | ||
const digest_1 = require("multiformats/hashes/digest"); | ||
const stripHexPrefix = (value) => value.startsWith("0x") ? value.slice(2) : value; | ||
const hexStringToBytes = (hex) => { | ||
let value = hex; | ||
if (value.startsWith("0x")) { | ||
value = value.slice(2); | ||
} | ||
const value = stripHexPrefix(hex); | ||
if (value.length % 2 !== 0) { | ||
@@ -63,8 +61,9 @@ throw new Error("Invalid hex string"); | ||
ipns: (value) => { | ||
const value_ = stripHexPrefix(value); | ||
let cid; | ||
try { | ||
cid = cid_1.CID.parse(value, value.startsWith("k") ? base36_1.base36 : undefined); | ||
cid = cid_1.CID.parse(value_, value_.startsWith("k") ? base36_1.base36 : undefined); | ||
} | ||
catch (e) { | ||
const bytes = base58_1.base58btc.decode(`z${value}`); | ||
const bytes = base58_1.base58btc.decode(`z${value_}`); | ||
cid = new cid_1.CID(0, 0x72, (0, digest_1.create)(0x00, bytes.slice(2)), bytes); | ||
@@ -71,0 +70,0 @@ } |
@@ -1,4 +0,1 @@ | ||
{ | ||
"type": "module", | ||
"sideEffects": false | ||
} | ||
{"type":"module","sideEffects":false} |
@@ -7,2 +7,3 @@ import { base32 } from "multiformats/bases/base32"; | ||
import { create as createDigest, decode as multihashDecode, } from "multiformats/hashes/digest"; | ||
const stripHexPrefix = (value) => value.startsWith("0x") ? value.slice(2) : value; | ||
/** | ||
@@ -14,6 +15,3 @@ * Convert a hexadecimal string to Bytes, the string can start with or without '0x' | ||
export const hexStringToBytes = (hex) => { | ||
let value = hex; | ||
if (value.startsWith("0x")) { | ||
value = value.slice(2); | ||
} | ||
const value = stripHexPrefix(hex); | ||
if (value.length % 2 !== 0) { | ||
@@ -82,9 +80,10 @@ throw new Error("Invalid hex string"); | ||
ipns: (value) => { | ||
const value_ = stripHexPrefix(value); | ||
let cid; | ||
try { | ||
cid = CID.parse(value, value.startsWith("k") ? base36 : undefined); | ||
cid = CID.parse(value_, value_.startsWith("k") ? base36 : undefined); | ||
} | ||
catch (e) { | ||
// legacy v0 decode | ||
const bytes = base58btc.decode(`z${value}`); | ||
const bytes = base58btc.decode(`z${value_}`); | ||
cid = new CID(0, 0x72, createDigest(0x00, bytes.slice(2)), bytes); | ||
@@ -91,0 +90,0 @@ } |
{ | ||
"name": "@ensdomains/content-hash", | ||
"version": "3.0.0-beta.3", | ||
"version": "3.0.0-beta.4", | ||
"description": "A simple tool to encode/decode content hash for EIP 1577 compliant ENS Resolvers (fork of pldespaigne/content-hash)", | ||
@@ -48,5 +48,2 @@ "type": "module", | ||
"devDependencies": { | ||
"@types/fs-extra": "^11.0.1", | ||
"fs-extra": "^11.1.1", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^5.1.6", | ||
@@ -57,10 +54,9 @@ "vitest": "^0.33.0" | ||
"test": "vitest", | ||
"tsn": "ts-node-esm --project tsconfig.node.json", | ||
"clean": "rm -rf ./dist", | ||
"build:pkgjson": "pnpm run tsn ./scripts/generatePackageJson.ts", | ||
"build:cjs": "tsc --project tsconfig.build.json --module commonjs --outDir ./dist/cjs --removeComments --verbatimModuleSyntax false", | ||
"build:esm": "tsc --project tsconfig.build.json --module es2022 --outDir ./dist/esm", | ||
"build:cjs": "tsc --project tsconfig.build.json --module commonjs --outDir ./dist/cjs --removeComments --verbatimModuleSyntax false && echo > ./dist/cjs/package.json '{\"type\":\"commonjs\"}'", | ||
"build:esm": "tsc --project tsconfig.build.json --module es2022 --outDir ./dist/esm && echo > ./dist/esm/package.json '{\"type\":\"module\",\"sideEffects\":false}'", | ||
"build:types": "tsc --project tsconfig.build.json --module esnext --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap", | ||
"build": "pnpm run clean && pnpm run build:cjs && pnpm run build:esm && pnpm run build:types && pnpm run build:pkgjson" | ||
"build": "pnpm run clean && pnpm run build:cjs && pnpm run build:esm && pnpm run build:types", | ||
"prepublish": "pnpm run build" | ||
} | ||
} |
@@ -13,2 +13,5 @@ import { base32 } from "multiformats/bases/base32"; | ||
const stripHexPrefix = (value: string): string => | ||
value.startsWith("0x") ? value.slice(2) : value; | ||
/** | ||
@@ -20,6 +23,3 @@ * Convert a hexadecimal string to Bytes, the string can start with or without '0x' | ||
export const hexStringToBytes = (hex: string): Bytes => { | ||
let value: string = hex; | ||
if (value.startsWith("0x")) { | ||
value = value.slice(2); | ||
} | ||
const value = stripHexPrefix(hex); | ||
@@ -95,8 +95,9 @@ if (value.length % 2 !== 0) { | ||
ipns: (value: string): Bytes => { | ||
const value_ = stripHexPrefix(value); | ||
let cid: CID; | ||
try { | ||
cid = CID.parse(value, value.startsWith("k") ? base36 : undefined); | ||
cid = CID.parse(value_, value_.startsWith("k") ? base36 : undefined); | ||
} catch (e) { | ||
// legacy v0 decode | ||
const bytes = base58btc.decode(`z${value}`); | ||
const bytes = base58btc.decode(`z${value_}`); | ||
cid = new CID(0, 0x72, createDigest(0x00, bytes.slice(2)), bytes); | ||
@@ -103,0 +104,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
55244
2
915