Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@web3-storage/car-block-validator

Package Overview
Dependencies
Maintainers
7
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@web3-storage/car-block-validator - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

14

cjs/src/index.js

@@ -33,3 +33,3 @@ 'use strict';

]));
async function validateBlock(block) {
function validateBlock(block) {
const hasher = hashMap.get(block.cid.multihash.code);

@@ -39,6 +39,12 @@ if (!hasher) {

}
const bytesHash = await hasher.digest(block.bytes);
if (!uint8arrays.equals(bytesHash.digest, block.cid.multihash.digest)) {
throw new Error('CID hash does not match bytes');
const result = hasher.digest(block.bytes);
const compareDigests = h => {
if (!uint8arrays.equals(h.digest, block.cid.multihash.digest)) {
throw new Error('CID hash does not match bytes');
}
};
if (result instanceof Promise) {
return result.then(compareDigests);
}
compareDigests(result);
}

@@ -45,0 +51,0 @@

@@ -45,3 +45,3 @@ import {

]));
export async function validateBlock(block) {
export function validateBlock(block) {
const hasher = hashMap.get(block.cid.multihash.code);

@@ -51,6 +51,12 @@ if (!hasher) {

}
const bytesHash = await hasher.digest(block.bytes);
if (!equals(bytesHash.digest, block.cid.multihash.digest)) {
throw new Error('CID hash does not match bytes');
const result = hasher.digest(block.bytes);
const compareDigests = h => {
if (!equals(h.digest, block.cid.multihash.digest)) {
throw new Error('CID hash does not match bytes');
}
};
if (result instanceof Promise) {
return result.then(compareDigests);
}
compareDigests(result);
}
{
"name": "@web3-storage/car-block-validator",
"version": "1.0.1",
"version": "1.1.0",
"description": "Validate car block bytes",

@@ -5,0 +5,0 @@ "main": "./cjs/src/index.js",

@@ -26,2 +26,3 @@ import { sha256, sha512 } from 'multiformats/hashes/sha2'

/** @type {Map<number, import('multiformats/hashes/interface').MultihashHasher>} */
export const hashMap = new Map(

@@ -39,3 +40,3 @@ [

*/
export async function validateBlock (block) {
export function validateBlock (block) {
const hasher = hashMap.get(block.cid.multihash.code)

@@ -46,7 +47,16 @@ if (!hasher) {

const bytesHash = await hasher.digest(block.bytes)
const result = hasher.digest(block.bytes)
if (!equals(bytesHash.digest, block.cid.multihash.digest)) {
throw new Error('CID hash does not match bytes')
/** @param {import('multiformats/hashes/interface').MultihashDigest} h */
const compareDigests = h => {
if (!equals(h.digest, block.cid.multihash.digest)) {
throw new Error('CID hash does not match bytes')
}
}
if (result instanceof Promise) {
return result.then(compareDigests)
}
compareDigests(result)
}

@@ -40,5 +40,5 @@ import test from 'ava'

for await (const block of reader) {
t.throwsAsync(() => validateBlock(block))
t.throwsAsync(async () => validateBlock(block))
}
})
}

@@ -5,3 +5,3 @@ /**

*/
export function validateBlock(block: Block): Promise<void>;
export function validateBlock(block: Block): Promise<void> | undefined;
/**

@@ -12,3 +12,4 @@ * @typedef {object} Block

*/
export const hashMap: Map<any, any>;
/** @type {Map<number, import('multiformats/hashes/interface').MultihashHasher>} */
export const hashMap: Map<number, import('multiformats/hashes/interface').MultihashHasher>;
export type Block = {

@@ -15,0 +16,0 @@ cid: import('multiformats/cid').CID;

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc