Socket
Book a DemoSign in
Socket

@aztec/blob-lib

Package Overview
Dependencies
Maintainers
6
Versions
812
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aztec/blob-lib - npm Package Compare versions

Comparing version
0.0.1-commit.934299a21
to
0.0.1-commit.936cb2cae
+1
-1
dest/blob.d.ts

@@ -37,3 +37,3 @@ import { FIELDS_PER_BLOB } from '@aztec/constants';

*
* @throws If data does not match the expected length (BYTES_PER_BLOB).
* @throws If data does not match the expected length (getBytesPerBlob()).
*/

@@ -40,0 +40,0 @@ static fromBlobBuffer(data: Uint8Array): Promise<Blob>;

@@ -6,3 +6,3 @@ import { FIELDS_PER_BLOB } from '@aztec/constants';

import { computeBlobCommitment, computeChallengeZ, computeEthVersionedBlobHash } from './hash.js';
import { BYTES_PER_BLOB, BYTES_PER_COMMITMENT, getKzg } from './kzg_context.js';
import { getBytesPerBlob, getBytesPerCommitment, getKzg } from './kzg_context.js';
export { FIELDS_PER_BLOB };

@@ -25,7 +25,7 @@ /**

this.commitment = commitment;
if (data.length !== BYTES_PER_BLOB) {
throw new Error(`Blob data must be ${BYTES_PER_BLOB} bytes. Got ${data.length}.`);
if (data.length !== getBytesPerBlob()) {
throw new Error(`Blob data must be ${getBytesPerBlob()} bytes. Got ${data.length}.`);
}
if (commitment.length !== BYTES_PER_COMMITMENT) {
throw new Error(`Blob commitment must be ${BYTES_PER_COMMITMENT} bytes. Got ${commitment.length}.`);
if (commitment.length !== getBytesPerCommitment()) {
throw new Error(`Blob commitment must be ${getBytesPerCommitment()} bytes. Got ${commitment.length}.`);
}

@@ -38,3 +38,3 @@ }

*
* @throws If data does not match the expected length (BYTES_PER_BLOB).
* @throws If data does not match the expected length (getBytesPerBlob()).
*/ static async fromBlobBuffer(data) {

@@ -57,3 +57,3 @@ const commitment = await computeBlobCommitment(data);

serializeToBuffer(fields)
], BYTES_PER_BLOB);
], getBytesPerBlob());
const commitment = await computeBlobCommitment(data);

@@ -60,0 +60,0 @@ return new Blob(data, commitment);

import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
import { sha256, sha256ToField } from '@aztec/foundation/crypto/sha256';
import { Fr } from '@aztec/foundation/curves/bn254';
import { BYTES_PER_BLOB, BYTES_PER_COMMITMENT, getKzg } from './kzg_context.js';
import { getBytesPerBlob, getBytesPerCommitment, getKzg } from './kzg_context.js';
import { SpongeBlob } from './sponge_blob.js';

@@ -39,4 +39,4 @@ const VERSIONED_HASH_VERSION_KZG = 0x01;

export async function computeBlobCommitment(data) {
if (data.length !== BYTES_PER_BLOB) {
throw new Error(`Expected ${BYTES_PER_BLOB} bytes per blob. Got ${data.length}.`);
if (data.length !== getBytesPerBlob()) {
throw new Error(`Expected ${getBytesPerBlob()} bytes per blob. Got ${data.length}.`);
}

@@ -59,8 +59,8 @@ return Buffer.from(await getKzg().asyncBlobToKzgCommitment(data));

*/ export function commitmentToFields(commitment) {
if (commitment.length !== BYTES_PER_COMMITMENT) {
throw new Error(`Expected ${BYTES_PER_COMMITMENT} bytes for blob commitment. Got ${commitment.length}.`);
if (commitment.length !== getBytesPerCommitment()) {
throw new Error(`Expected ${getBytesPerCommitment()} bytes for blob commitment. Got ${commitment.length}.`);
}
return [
new Fr(commitment.subarray(0, 31)),
new Fr(commitment.subarray(31, BYTES_PER_COMMITMENT))
new Fr(commitment.subarray(31, getBytesPerCommitment()))
];

@@ -67,0 +67,0 @@ }

@@ -1,3 +0,5 @@

import { DasContextJs } from '@crate-crypto/node-eth-kzg';
export * from '@crate-crypto/node-eth-kzg';
import type { DasContextJs } from '@crate-crypto/node-eth-kzg';
export type { DasContextJs } from '@crate-crypto/node-eth-kzg';
export declare function getBytesPerBlob(): number;
export declare function getBytesPerCommitment(): number;
/**

@@ -8,2 +10,2 @@ * Returns the lazily-initialized KZG context.

export declare function getKzg(): DasContextJs;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoia3pnX2NvbnRleHQuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9remdfY29udGV4dC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsWUFBWSxFQUFFLE1BQU0sNEJBQTRCLENBQUM7QUFFMUQsY0FBYyw0QkFBNEIsQ0FBQztBQUkzQzs7O0dBR0c7QUFDSCx3QkFBZ0IsTUFBTSxJQUFJLFlBQVksQ0FLckMifQ==
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoia3pnX2NvbnRleHQuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9remdfY29udGV4dC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw0QkFBNEIsQ0FBQztBQU0vRCxZQUFZLEVBQUUsWUFBWSxFQUFFLE1BQU0sNEJBQTRCLENBQUM7QUFlL0Qsd0JBQWdCLGVBQWUsSUFBSSxNQUFNLENBRXhDO0FBRUQsd0JBQWdCLHFCQUFxQixJQUFJLE1BQU0sQ0FFOUM7QUFJRDs7O0dBR0c7QUFDSCx3QkFBZ0IsTUFBTSxJQUFJLFlBQVksQ0FLckMifQ==

@@ -1,1 +0,1 @@

{"version":3,"file":"kzg_context.d.ts","sourceRoot":"","sources":["../src/kzg_context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,cAAc,4BAA4B,CAAC;AAI3C;;;GAGG;AACH,wBAAgB,MAAM,IAAI,YAAY,CAKrC"}
{"version":3,"file":"kzg_context.d.ts","sourceRoot":"","sources":["../src/kzg_context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAM/D,YAAY,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAe/D,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED,wBAAgB,qBAAqB,IAAI,MAAM,CAE9C;AAID;;;GAGG;AACH,wBAAgB,MAAM,IAAI,YAAY,CAKrC"}

@@ -1,3 +0,18 @@

import { DasContextJs } from '@crate-crypto/node-eth-kzg';
export * from '@crate-crypto/node-eth-kzg';
import { createRequire } from 'module';
let nativeModule;
/** Lazily loads the @crate-crypto/node-eth-kzg native module. */ function loadNativeModule() {
if (!nativeModule) {
const require = createRequire(import.meta.url);
nativeModule = require('@crate-crypto/node-eth-kzg');
}
return nativeModule;
}
// Ethereum blob constants, loaded lazily from the native module.
// Values: BYTES_PER_BLOB=131072, BYTES_PER_COMMITMENT=48
export function getBytesPerBlob() {
return loadNativeModule().BYTES_PER_BLOB;
}
export function getBytesPerCommitment() {
return loadNativeModule().BYTES_PER_COMMITMENT;
}
let kzgInstance;

@@ -9,3 +24,3 @@ /**

if (!kzgInstance) {
kzgInstance = DasContextJs.create({
kzgInstance = loadNativeModule().DasContextJs.create({
usePrecomp: true

@@ -12,0 +27,0 @@ });

{
"name": "@aztec/blob-lib",
"version": "0.0.1-commit.934299a21",
"version": "0.0.1-commit.936cb2cae",
"type": "module",

@@ -30,4 +30,4 @@ "exports": {

"dependencies": {
"@aztec/constants": "0.0.1-commit.934299a21",
"@aztec/foundation": "0.0.1-commit.934299a21",
"@aztec/constants": "0.0.1-commit.936cb2cae",
"@aztec/foundation": "0.0.1-commit.936cb2cae",
"@crate-crypto/node-eth-kzg": "^0.10.0",

@@ -34,0 +34,0 @@ "tslib": "^2.4.0"

@@ -8,3 +8,3 @@ import { FIELDS_PER_BLOB } from '@aztec/constants';

import type { BlobJson } from './interface.js';
import { BYTES_PER_BLOB, BYTES_PER_COMMITMENT, getKzg } from './kzg_context.js';
import { getBytesPerBlob, getBytesPerCommitment, getKzg } from './kzg_context.js';

@@ -31,7 +31,7 @@ export { FIELDS_PER_BLOB };

) {
if (data.length !== BYTES_PER_BLOB) {
throw new Error(`Blob data must be ${BYTES_PER_BLOB} bytes. Got ${data.length}.`);
if (data.length !== getBytesPerBlob()) {
throw new Error(`Blob data must be ${getBytesPerBlob()} bytes. Got ${data.length}.`);
}
if (commitment.length !== BYTES_PER_COMMITMENT) {
throw new Error(`Blob commitment must be ${BYTES_PER_COMMITMENT} bytes. Got ${commitment.length}.`);
if (commitment.length !== getBytesPerCommitment()) {
throw new Error(`Blob commitment must be ${getBytesPerCommitment()} bytes. Got ${commitment.length}.`);
}

@@ -45,3 +45,3 @@ }

*
* @throws If data does not match the expected length (BYTES_PER_BLOB).
* @throws If data does not match the expected length (getBytesPerBlob()).
*/

@@ -66,3 +66,3 @@ static async fromBlobBuffer(data: Uint8Array): Promise<Blob> {

const data = Buffer.concat([serializeToBuffer(fields)], BYTES_PER_BLOB);
const data = Buffer.concat([serializeToBuffer(fields)], getBytesPerBlob());
const commitment = await computeBlobCommitment(data);

@@ -69,0 +69,0 @@ return new Blob(data, commitment);

@@ -6,3 +6,3 @@ import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';

import { BYTES_PER_BLOB, BYTES_PER_COMMITMENT, getKzg } from './kzg_context.js';
import { getBytesPerBlob, getBytesPerCommitment, getKzg } from './kzg_context.js';
import { SpongeBlob } from './sponge_blob.js';

@@ -49,4 +49,4 @@

export async function computeBlobCommitment(data: Uint8Array): Promise<Buffer> {
if (data.length !== BYTES_PER_BLOB) {
throw new Error(`Expected ${BYTES_PER_BLOB} bytes per blob. Got ${data.length}.`);
if (data.length !== getBytesPerBlob()) {
throw new Error(`Expected ${getBytesPerBlob()} bytes per blob. Got ${data.length}.`);
}

@@ -72,7 +72,7 @@

export function commitmentToFields(commitment: Buffer): [Fr, Fr] {
if (commitment.length !== BYTES_PER_COMMITMENT) {
throw new Error(`Expected ${BYTES_PER_COMMITMENT} bytes for blob commitment. Got ${commitment.length}.`);
if (commitment.length !== getBytesPerCommitment()) {
throw new Error(`Expected ${getBytesPerCommitment()} bytes for blob commitment. Got ${commitment.length}.`);
}
return [new Fr(commitment.subarray(0, 31)), new Fr(commitment.subarray(31, BYTES_PER_COMMITMENT))];
return [new Fr(commitment.subarray(0, 31)), new Fr(commitment.subarray(31, getBytesPerCommitment()))];
}

@@ -79,0 +79,0 @@

@@ -1,5 +0,30 @@

import { DasContextJs } from '@crate-crypto/node-eth-kzg';
import type { DasContextJs } from '@crate-crypto/node-eth-kzg';
import { createRequire } from 'module';
export * from '@crate-crypto/node-eth-kzg';
// Re-export the type only. The native module is loaded lazily to avoid
// creating a napi-rs CustomGC handle at import time, which keeps the
// Node.js event loop alive and can deadlock process.exit().
export type { DasContextJs } from '@crate-crypto/node-eth-kzg';
let nativeModule: typeof import('@crate-crypto/node-eth-kzg') | undefined;
/** Lazily loads the @crate-crypto/node-eth-kzg native module. */
function loadNativeModule(): typeof import('@crate-crypto/node-eth-kzg') {
if (!nativeModule) {
const require = createRequire(import.meta.url);
nativeModule = require('@crate-crypto/node-eth-kzg') as typeof import('@crate-crypto/node-eth-kzg');
}
return nativeModule!;
}
// Ethereum blob constants, loaded lazily from the native module.
// Values: BYTES_PER_BLOB=131072, BYTES_PER_COMMITMENT=48
export function getBytesPerBlob(): number {
return loadNativeModule().BYTES_PER_BLOB;
}
export function getBytesPerCommitment(): number {
return loadNativeModule().BYTES_PER_COMMITMENT;
}
let kzgInstance: DasContextJs | undefined;

@@ -13,5 +38,5 @@

if (!kzgInstance) {
kzgInstance = DasContextJs.create({ usePrecomp: true });
kzgInstance = loadNativeModule().DasContextJs.create({ usePrecomp: true });
}
return kzgInstance;
}