@ensdomains/content-hash
Advanced tools
Comparing version 3.0.0 to 3.1.0-rc.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.concatUint8Arrays = exports.cidV0ToV1Base32 = exports.cidForWeb = void 0; | ||
const base32_1 = require("multiformats/bases/base32"); | ||
const base36_1 = require("multiformats/bases/base36"); | ||
const cid_1 = require("multiformats/cid"); | ||
const cid_js_1 = require("./utils/cid.js"); | ||
const coders_js_1 = require("./utils/coders.js"); | ||
const dnsLabelMaxLength = 63; | ||
const cidForWeb = (ipfsHash) => { | ||
let cid = cid_1.CID.parse(ipfsHash); | ||
let cid = cid_js_1.CID.parse(ipfsHash); | ||
if (cid.version === 0) { | ||
cid = cid.toV1(); | ||
} | ||
const dnsLabel = cid.toString(base32_1.base32); | ||
const dnsLabel = cid.toString(coders_js_1.base32); | ||
if (dnsLabel.length > dnsLabelMaxLength) { | ||
const b36 = cid.toString(base36_1.base36); | ||
const b36 = cid.toString(coders_js_1.base36); | ||
if (b36.length <= dnsLabelMaxLength) { | ||
@@ -25,7 +24,7 @@ return b36; | ||
const cidV0ToV1Base32 = (ipfsHash) => { | ||
let cid = cid_1.CID.parse(ipfsHash); | ||
let cid = cid_js_1.CID.parse(ipfsHash); | ||
if (cid.version === 0) { | ||
cid = cid.toV1(); | ||
} | ||
return cid.toString(base32_1.base32); | ||
return cid.toString(coders_js_1.base32); | ||
}; | ||
@@ -32,0 +31,0 @@ exports.cidV0ToV1Base32 = cidV0ToV1Base32; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getCodec = exports.encode = exports.decode = exports.cidV0ToV1Base32 = exports.cidForWeb = void 0; | ||
const multiformats_1 = require("multiformats"); | ||
const helpers_js_1 = require("./helpers.js"); | ||
const map_js_1 = require("./map.js"); | ||
const profiles_js_1 = require("./profiles.js"); | ||
const varint_js_1 = require("./utils/varint.js"); | ||
var helpers_js_2 = require("./helpers.js"); | ||
@@ -13,3 +13,3 @@ Object.defineProperty(exports, "cidForWeb", { enumerable: true, get: function () { return helpers_js_2.cidForWeb; } }); | ||
const bytes = (0, profiles_js_1.hexStringToBytes)(contentHash); | ||
const [code, offset] = multiformats_1.varint.decode(bytes); | ||
const [code, offset] = (0, varint_js_1.decodeVarint)(bytes); | ||
const value = bytes.slice(offset); | ||
@@ -29,3 +29,3 @@ const name = map_js_1.codeToName[code]; | ||
const code = map_js_1.nameToCode[name]; | ||
const codeBytes = multiformats_1.varint.encodeTo(code, new Uint8Array(multiformats_1.varint.encodingLength(code))); | ||
const codeBytes = (0, varint_js_1.encodeVarint)(code, new Uint8Array((0, varint_js_1.varintEncodingLength)(code))); | ||
return (0, profiles_js_1.bytesToHexString)((0, helpers_js_1.concatUint8Arrays)(codeBytes, bytes)); | ||
@@ -36,3 +36,3 @@ }; | ||
const bytes = (0, profiles_js_1.hexStringToBytes)(contentHash); | ||
const [code] = multiformats_1.varint.decode(bytes); | ||
const [code] = (0, varint_js_1.decodeVarint)(bytes); | ||
return map_js_1.codeToName[code]; | ||
@@ -39,0 +39,0 @@ }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.profiles = exports.bytesToHexString = exports.hexStringToBytes = void 0; | ||
const base32_1 = require("multiformats/bases/base32"); | ||
const base36_1 = require("multiformats/bases/base36"); | ||
const base58_1 = require("multiformats/bases/base58"); | ||
const base64_1 = require("multiformats/bases/base64"); | ||
const cid_1 = require("multiformats/cid"); | ||
const digest_1 = require("multiformats/hashes/digest"); | ||
const coders_1 = require("@ensdomains/address-encoder/coders"); | ||
const cid_js_1 = require("./utils/cid.js"); | ||
const coders_js_1 = require("./utils/coders.js"); | ||
const digest_js_1 = require("./utils/digest.js"); | ||
const hexStringToBytes = (hex) => { | ||
@@ -37,3 +35,3 @@ let value = hex; | ||
if (multihash.size < 38) { | ||
const mh = (0, digest_1.decode)(multihash.bytes); | ||
const mh = (0, digest_js_1.decodeDigest)(multihash.bytes); | ||
if (mh.code === 0x0 && mh.size < 36) { | ||
@@ -49,3 +47,3 @@ return false; | ||
}; | ||
const base64Decode = (value) => base64_1.base64url.decode(`u${value}`); | ||
const base64Decode = (value) => (0, coders_1.decodeArAddress)(value); | ||
const encodes = { | ||
@@ -57,7 +55,7 @@ skynet: (value) => { | ||
const bytes = (0, exports.hexStringToBytes)(value); | ||
const multihash = (0, digest_1.create)(0x1b, bytes); | ||
return cid_1.CID.create(1, 0xfa, multihash).bytes; | ||
const multihash = (0, digest_js_1.createDigest)(0x1b, bytes); | ||
return cid_js_1.CID.create(1, 0xfa, multihash).bytes; | ||
}, | ||
ipfs: (value) => { | ||
return cid_1.CID.parse(value).toV1().bytes; | ||
return cid_js_1.CID.parse(value).toV1().bytes; | ||
}, | ||
@@ -67,7 +65,7 @@ ipns: (value) => { | ||
try { | ||
cid = cid_1.CID.parse(value, value.startsWith("k") ? base36_1.base36 : undefined); | ||
cid = cid_js_1.CID.parse(value, value.startsWith("k") ? coders_js_1.base36 : undefined); | ||
} | ||
catch (e) { | ||
const bytes = base58_1.base58btc.decode(`z${value}`); | ||
cid = new cid_1.CID(0, 0x72, (0, digest_1.create)(0x00, bytes.slice(2)), bytes); | ||
const bytes = coders_js_1.base58btc.decode(`z${value}`); | ||
cid = new cid_js_1.CID(0, 0x72, (0, digest_js_1.createDigest)(0x00, bytes.slice(2)), bytes); | ||
} | ||
@@ -77,3 +75,3 @@ if (!isCryptographicIPNS(cid)) { | ||
} | ||
return cid_1.CID.create(1, 0x72, cid.multihash).bytes; | ||
return cid_js_1.CID.create(1, 0x72, cid.multihash).bytes; | ||
}, | ||
@@ -90,16 +88,16 @@ utf8: (value) => { | ||
hexMultiHash: (value) => { | ||
const cid = cid_1.CID.decode(value); | ||
return (0, exports.bytesToHexString)((0, digest_1.decode)(cid.multihash.bytes).digest); | ||
const cid = cid_js_1.CID.decode(value); | ||
return (0, exports.bytesToHexString)((0, digest_js_1.decodeDigest)(cid.multihash.bytes).digest); | ||
}, | ||
ipfs: (value) => { | ||
const cid = cid_1.CID.decode(value).toV1(); | ||
return cid.toString(cid.code === 0x72 ? base36_1.base36 : base32_1.base32); | ||
const cid = cid_js_1.CID.decode(value).toV1(); | ||
return cid.toString(cid.code === 0x72 ? coders_js_1.base36 : coders_js_1.base32); | ||
}, | ||
ipns: (value) => { | ||
const cid = cid_1.CID.decode(value).toV1(); | ||
const cid = cid_js_1.CID.decode(value).toV1(); | ||
if (!isCryptographicIPNS(cid)) { | ||
console.warn("[ensdomains/content-hash] use of non-cryptographic identifiers in ipns-ns is deprecated and will be removed, migrate to ED25519 libp2p-key"); | ||
return String.fromCodePoint(...cid_1.CID.decode(value).multihash.digest); | ||
return String.fromCodePoint(...cid_js_1.CID.decode(value).multihash.digest); | ||
} | ||
return cid.toString(base36_1.base36); | ||
return cid.toString(coders_js_1.base36); | ||
}, | ||
@@ -111,3 +109,3 @@ utf8: (value) => { | ||
base64: (value) => { | ||
return base64_1.base64url.encode(value).substring(1); | ||
return (0, coders_1.encodeArAddress)(value); | ||
}, | ||
@@ -114,0 +112,0 @@ }; |
@@ -1,4 +0,3 @@ | ||
import { base32 } from "multiformats/bases/base32"; | ||
import { base36 } from "multiformats/bases/base36"; | ||
import { CID } from "multiformats/cid"; | ||
import { CID } from "./utils/cid.js"; | ||
import { base32, base36 } from "./utils/coders.js"; | ||
// Label's max length in DNS (https://tools.ietf.org/html/rfc1034#page-7) | ||
@@ -5,0 +4,0 @@ const dnsLabelMaxLength = 63; |
@@ -1,5 +0,5 @@ | ||
import { varint } from "multiformats"; | ||
import { concatUint8Arrays } from "./helpers.js"; | ||
import { codeToName, nameToCode } from "./map.js"; | ||
import { bytesToHexString, hexStringToBytes, profiles, } from "./profiles.js"; | ||
import { decodeVarint, encodeVarint, varintEncodingLength, } from "./utils/varint.js"; | ||
export {} from "./map.js"; | ||
@@ -14,3 +14,3 @@ export { cidForWeb, cidV0ToV1Base32 } from "./helpers.js"; | ||
const bytes = hexStringToBytes(contentHash); | ||
const [code, offset] = varint.decode(bytes); | ||
const [code, offset] = decodeVarint(bytes); | ||
const value = bytes.slice(offset); | ||
@@ -34,3 +34,3 @@ const name = codeToName[code]; | ||
const code = nameToCode[name]; | ||
const codeBytes = varint.encodeTo(code, new Uint8Array(varint.encodingLength(code))); | ||
const codeBytes = encodeVarint(code, new Uint8Array(varintEncodingLength(code))); | ||
return bytesToHexString(concatUint8Arrays(codeBytes, bytes)); | ||
@@ -45,5 +45,5 @@ }; | ||
const bytes = hexStringToBytes(contentHash); | ||
const [code] = varint.decode(bytes); | ||
const [code] = decodeVarint(bytes); | ||
return codeToName[code]; | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,7 +0,5 @@ | ||
import { base32 } from "multiformats/bases/base32"; | ||
import { base36 } from "multiformats/bases/base36"; | ||
import { base58btc } from "multiformats/bases/base58"; | ||
import { base64url } from "multiformats/bases/base64"; | ||
import { CID } from "multiformats/cid"; | ||
import { create as createDigest, decode as multihashDecode, } from "multiformats/hashes/digest"; | ||
import { decodeArAddress, encodeArAddress, } from "@ensdomains/address-encoder/coders"; | ||
import { CID } from "./utils/cid.js"; | ||
import { base32, base36, base58btc } from "./utils/coders.js"; | ||
import { createDigest, decodeDigest } from "./utils/digest.js"; | ||
/** | ||
@@ -45,3 +43,3 @@ * Convert a hexadecimal string to Bytes, the string can start with or without '0x' | ||
if (multihash.size < 38) { | ||
const mh = multihashDecode(multihash.bytes); | ||
const mh = decodeDigest(multihash.bytes); | ||
// ED25519 pubkeys are inlined using identity hash function | ||
@@ -62,3 +60,3 @@ // and we should not see anything shorter than that | ||
}; | ||
const base64Decode = (value) => base64url.decode(`u${value}`); | ||
const base64Decode = (value) => decodeArAddress(value); | ||
/** | ||
@@ -114,3 +112,3 @@ * list of known encoding, | ||
const cid = CID.decode(value); | ||
return bytesToHexString(multihashDecode(cid.multihash.bytes).digest); | ||
return bytesToHexString(decodeDigest(cid.multihash.bytes).digest); | ||
}, | ||
@@ -137,3 +135,3 @@ ipfs: (value) => { | ||
base64: (value) => { | ||
return base64url.encode(value).substring(1); | ||
return encodeArAddress(value); | ||
}, | ||
@@ -140,0 +138,0 @@ }; |
{ | ||
"name": "@ensdomains/content-hash", | ||
"version": "3.0.0", | ||
"version": "3.1.0-rc.0", | ||
"description": "A simple tool to encode/decode content hash for EIP 1577 compliant ENS Resolvers (fork of pldespaigne/content-hash)", | ||
@@ -44,4 +44,5 @@ "type": "module", | ||
"dependencies": { | ||
"@multiformats/sha3": "^2.0.17", | ||
"multiformats": "^12.0.1" | ||
"@ensdomains/address-encoder": "1.0.0-rc.2", | ||
"@noble/curves": "^1.2.0", | ||
"@scure/base": "^1.1.3" | ||
}, | ||
@@ -48,0 +49,0 @@ "devDependencies": { |
@@ -1,4 +0,3 @@ | ||
import { base32 } from "multiformats/bases/base32"; | ||
import { base36 } from "multiformats/bases/base36"; | ||
import { CID } from "multiformats/cid"; | ||
import { CID } from "./utils/cid.js"; | ||
import { base32, base36 } from "./utils/coders.js"; | ||
@@ -5,0 +4,0 @@ // Label's max length in DNS (https://tools.ietf.org/html/rfc1034#page-7) |
@@ -1,2 +0,1 @@ | ||
import { varint } from "multiformats"; | ||
import { concatUint8Arrays } from "./helpers.js"; | ||
@@ -10,2 +9,7 @@ import { codeToName, nameToCode, type Codec, type CodecId } from "./map.js"; | ||
} from "./profiles.js"; | ||
import { | ||
decodeVarint, | ||
encodeVarint, | ||
varintEncodingLength, | ||
} from "./utils/varint.js"; | ||
@@ -23,3 +27,3 @@ export { type Codec, type CodecId } from "./map.js"; | ||
const bytes = hexStringToBytes(contentHash); | ||
const [code, offset] = varint.decode(bytes); | ||
const [code, offset] = decodeVarint(bytes); | ||
const value = bytes.slice(offset); | ||
@@ -42,5 +46,5 @@ const name = codeToName[code as CodecId]; | ||
const code = nameToCode[name] as number; | ||
const codeBytes = varint.encodeTo( | ||
const codeBytes = encodeVarint( | ||
code, | ||
new Uint8Array(varint.encodingLength(code)) | ||
new Uint8Array(varintEncodingLength(code)) | ||
); | ||
@@ -57,4 +61,4 @@ return bytesToHexString(concatUint8Arrays(codeBytes, bytes)); | ||
const bytes = hexStringToBytes(contentHash); | ||
const [code] = varint.decode(bytes); | ||
const [code] = decodeVarint(bytes); | ||
return codeToName[code as CodecId]; | ||
}; |
@@ -1,10 +0,8 @@ | ||
import { base32 } from "multiformats/bases/base32"; | ||
import { base36 } from "multiformats/bases/base36"; | ||
import { base58btc } from "multiformats/bases/base58"; | ||
import { base64url } from "multiformats/bases/base64"; | ||
import { CID } from "multiformats/cid"; | ||
import { | ||
create as createDigest, | ||
decode as multihashDecode, | ||
} from "multiformats/hashes/digest"; | ||
decodeArAddress, | ||
encodeArAddress, | ||
} from "@ensdomains/address-encoder/coders"; | ||
import { CID } from "./utils/cid.js"; | ||
import { base32, base36, base58btc } from "./utils/coders.js"; | ||
import { createDigest, decodeDigest } from "./utils/digest.js"; | ||
@@ -57,3 +55,3 @@ type Bytes = Uint8Array; | ||
if (multihash.size < 38) { | ||
const mh = multihashDecode(multihash.bytes); | ||
const mh = decodeDigest(multihash.bytes); | ||
// ED25519 pubkeys are inlined using identity hash function | ||
@@ -74,3 +72,3 @@ // and we should not see anything shorter than that | ||
const base64Decode = (value: string): Bytes => base64url.decode(`u${value}`); | ||
const base64Decode = (value: string): Bytes => decodeArAddress(value); | ||
@@ -129,3 +127,3 @@ /** | ||
const cid = CID.decode(value); | ||
return bytesToHexString(multihashDecode(cid.multihash.bytes).digest); | ||
return bytesToHexString(decodeDigest(cid.multihash.bytes).digest); | ||
}, | ||
@@ -154,3 +152,3 @@ ipfs: (value: Bytes): string => { | ||
base64: (value: Bytes): string => { | ||
return base64url.encode(value).substring(1); | ||
return encodeArAddress(value); | ||
}, | ||
@@ -157,0 +155,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
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
172527
82
3152
3
2
1
+ Added@noble/curves@^1.2.0
+ Added@scure/base@^1.1.3
+ Added@ensdomains/address-encoder@1.0.0-rc.2(transitive)
+ Added@noble/curves@1.8.1(transitive)
+ Added@noble/hashes@1.7.1(transitive)
+ Added@scure/base@1.2.4(transitive)
+ Addedbech32@2.0.0(transitive)
- Removed@multiformats/sha3@^2.0.17
- Removedmultiformats@^12.0.1
- Removed@multiformats/sha3@2.0.17(transitive)
- Removedjs-sha3@0.8.0(transitive)
- Removedmultiformats@12.1.39.9.0(transitive)