@ensdomains/content-hash
Advanced tools
Comparing version 3.0.0-beta.4 to 3.0.0-beta.5
@@ -10,5 +10,7 @@ "use strict"; | ||
const digest_1 = require("multiformats/hashes/digest"); | ||
const stripHexPrefix = (value) => value.startsWith("0x") ? value.slice(2) : value; | ||
const hexStringToBytes = (hex) => { | ||
const value = stripHexPrefix(hex); | ||
let value = hex; | ||
if (value.startsWith("0x")) { | ||
value = value.slice(2); | ||
} | ||
if (value.length % 2 !== 0) { | ||
@@ -61,9 +63,8 @@ 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); | ||
@@ -70,0 +71,0 @@ } |
@@ -7,3 +7,2 @@ 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; | ||
/** | ||
@@ -15,3 +14,6 @@ * Convert a hexadecimal string to Bytes, the string can start with or without '0x' | ||
export const hexStringToBytes = (hex) => { | ||
const value = stripHexPrefix(hex); | ||
let value = hex; | ||
if (value.startsWith("0x")) { | ||
value = value.slice(2); | ||
} | ||
if (value.length % 2 !== 0) { | ||
@@ -80,10 +82,9 @@ 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); | ||
@@ -90,0 +91,0 @@ } |
{ | ||
"name": "@ensdomains/content-hash", | ||
"version": "3.0.0-beta.4", | ||
"version": "3.0.0-beta.5", | ||
"description": "A simple tool to encode/decode content hash for EIP 1577 compliant ENS Resolvers (fork of pldespaigne/content-hash)", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -13,5 +13,2 @@ import { base32 } from "multiformats/bases/base32"; | ||
const stripHexPrefix = (value: string): string => | ||
value.startsWith("0x") ? value.slice(2) : value; | ||
/** | ||
@@ -23,3 +20,6 @@ * Convert a hexadecimal string to Bytes, the string can start with or without '0x' | ||
export const hexStringToBytes = (hex: string): Bytes => { | ||
const value = stripHexPrefix(hex); | ||
let value: string = hex; | ||
if (value.startsWith("0x")) { | ||
value = value.slice(2); | ||
} | ||
@@ -95,9 +95,8 @@ 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); | ||
@@ -104,0 +103,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
917
54786