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

verkle-cryptography-wasm

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

verkle-cryptography-wasm - npm Package Compare versions

Comparing version 0.4.6 to 0.4.7

7

dist/cjs/index.d.ts

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

import { type ProverInput as ProverInputBase, type VerifierInput as VerifierInputBase } from './verkleFFIBindings/index.js';
export declare const loadVerkleCrypto: () => Promise<{

@@ -9,7 +10,9 @@ getTreeKey: (address: Uint8Array, treeIndex: Uint8Array, subIndex: number) => Uint8Array;

serializeCommitment: (commitment: Uint8Array) => Uint8Array;
createProof: (input: Uint8Array) => Uint8Array;
verifyProof: (proofInput: Uint8Array) => boolean;
createProof: (proverInputs: ProverInput[]) => Uint8Array;
verifyProof: (proof: Uint8Array, verifierInputs: VerifierInput[]) => boolean;
}>;
export type ProverInput = ProverInputBase;
export type VerifierInput = VerifierInputBase;
export type Scalar = Uint8Array;
export type Commitment = Uint8Array;
//# sourceMappingURL=index.d.ts.map

@@ -42,7 +42,7 @@ "use strict";

};
createProof = function createProof(input) {
return verkleFFI.createProof(input);
createProof = function createProof(proverInputs) {
return (0, _index.createProof)(verkleFFI, proverInputs);
};
verifyProof = function verifyProof(proofInput) {
return verkleFFI.verifyProof(proofInput);
verifyProof = function verifyProof(proof, verifierInputs) {
return (0, _index.verifyProof)(verkleFFI, proof, verifierInputs);
};

@@ -49,0 +49,0 @@ return _context.abrupt("return", {

import { initVerkleWasm, zeroCommitment, verifyExecutionWitnessPreState } from '../wasm/rust_verkle_wasm.js';
import { getTreeKey, getTreeKeyHash, updateCommitment, createProof, verifyProof } from './verkleFFI.js';
export { initVerkleWasm, getTreeKey, getTreeKeyHash, updateCommitment, zeroCommitment, verifyExecutionWitnessPreState, createProof, verifyProof };
import { getTreeKey, getTreeKeyHash, updateCommitment, createProof, verifyProof, type ProverInput, type VerifierInput } from './verkleFFI.js';
export { initVerkleWasm, getTreeKey, getTreeKeyHash, updateCommitment, zeroCommitment, verifyExecutionWitnessPreState, createProof, verifyProof, type ProverInput, type VerifierInput, };
//# sourceMappingURL=index.d.ts.map

@@ -5,4 +5,16 @@ import { Context as VerkleFFI } from '../wasm/rust_verkle_wasm.js';

export declare function updateCommitment(verkleFFI: VerkleFFI, commitment: Uint8Array, commitmentIndex: number, oldScalarValue: Uint8Array, newScalarValue: Uint8Array): Uint8Array;
export declare function createProof(verkleFFI: VerkleFFI, bytes: Uint8Array): Uint8Array;
export declare function verifyProof(verkleFFI: VerkleFFI, proof: Uint8Array): boolean;
export declare function createProof(verkleFFI: VerkleFFI, proverInputs: ProverInput[]): Uint8Array;
export declare function verifyProof(verkleFFI: VerkleFFI, proof: Uint8Array, verifierInputs: VerifierInput[]): boolean;
export interface ProverInput {
serializedCommitment: Uint8Array;
vector: Uint8Array[];
indices: number[];
}
export interface VerifierInput {
serializedCommitment: Uint8Array;
indexValuePairs: Array<{
index: number;
value: Uint8Array;
}>;
}
//# sourceMappingURL=verkleFFI.d.ts.map

@@ -11,2 +11,9 @@ "use strict";

exports.verifyProof = verifyProof;
var _util = require("@ethereumjs/util");
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
// This is equal to 2n + 256n * 64n.

@@ -97,7 +104,32 @@ //

}
function createProof(verkleFFI, bytes) {
return verkleFFI.createProof(bytes);
function createProof(verkleFFI, proverInputs) {
var serializedProofInputs = serializedProverInputs(proverInputs);
return verkleFFI.createProof(serializedProofInputs);
}
function verifyProof(verkleFFI, proof) {
return verkleFFI.verifyProof(proof);
function verifyProof(verkleFFI, proof, verifierInputs) {
var serializedVerifierInput = serializeVerifierInputs(proof, verifierInputs);
return verkleFFI.verifyProof(serializedVerifierInput);
}
function serializedProverInputs(proofInputs) {
var serializedProverInputs = proofInputs.flatMap(function (_ref) {
var serializedCommitment = _ref.serializedCommitment,
vector = _ref.vector,
indices = _ref.indices;
return indices.flatMap(function (index) {
return [serializedCommitment].concat(_toConsumableArray(vector), [new Uint8Array([index]), vector[index]]);
});
});
return _util.concatBytes.apply(void 0, _toConsumableArray(serializedProverInputs));
}
function serializeVerifierInputs(proof, verifierInputs) {
var serializedVerifierInputs = [proof].concat(_toConsumableArray(verifierInputs.flatMap(function (_ref2) {
var serializedCommitment = _ref2.serializedCommitment,
indexValuePairs = _ref2.indexValuePairs;
return indexValuePairs.flatMap(function (_ref3) {
var index = _ref3.index,
value = _ref3.value;
return [serializedCommitment, new Uint8Array([index]), value];
});
})));
return _util.concatBytes.apply(void 0, _toConsumableArray(serializedVerifierInputs));
}

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

import { type ProverInput as ProverInputBase, type VerifierInput as VerifierInputBase } from './verkleFFIBindings/index.js';
export declare const loadVerkleCrypto: () => Promise<{

@@ -9,7 +10,9 @@ getTreeKey: (address: Uint8Array, treeIndex: Uint8Array, subIndex: number) => Uint8Array;

serializeCommitment: (commitment: Uint8Array) => Uint8Array;
createProof: (input: Uint8Array) => Uint8Array;
verifyProof: (proofInput: Uint8Array) => boolean;
createProof: (proverInputs: ProverInput[]) => Uint8Array;
verifyProof: (proof: Uint8Array, verifierInputs: VerifierInput[]) => boolean;
}>;
export type ProverInput = ProverInputBase;
export type VerifierInput = VerifierInputBase;
export type Scalar = Uint8Array;
export type Commitment = Uint8Array;
//# sourceMappingURL=index.d.ts.map

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

import { initVerkleWasm, getTreeKey as getTreeKeyBase, getTreeKeyHash as getTreeKeyHashBase, updateCommitment as updateCommitmentBase, zeroCommitment as zeroCommitmentBase, verifyExecutionWitnessPreState as verifyExecutionWitnessPreStateBase, } from './verkleFFIBindings/index.js';
import { initVerkleWasm, getTreeKey as getTreeKeyBase, getTreeKeyHash as getTreeKeyHashBase, updateCommitment as updateCommitmentBase, zeroCommitment as zeroCommitmentBase, verifyExecutionWitnessPreState as verifyExecutionWitnessPreStateBase, createProof as createProofBase, verifyProof as verifyProofBase, } from './verkleFFIBindings/index.js';
import { Context as VerkleFFI } from './wasm/rust_verkle_wasm.js';

@@ -13,4 +13,4 @@ export const loadVerkleCrypto = async () => {

const serializeCommitment = (commitment) => verkleFFI.serializeCommitment(commitment);
const createProof = (input) => verkleFFI.createProof(input);
const verifyProof = (proofInput) => verkleFFI.verifyProof(proofInput);
const createProof = (proverInputs) => createProofBase(verkleFFI, proverInputs);
const verifyProof = (proof, verifierInputs) => verifyProofBase(verkleFFI, proof, verifierInputs);
return {

@@ -25,5 +25,5 @@ getTreeKey,

createProof,
verifyProof
verifyProof,
};
};
//# sourceMappingURL=index.js.map
import { initVerkleWasm, zeroCommitment, verifyExecutionWitnessPreState } from '../wasm/rust_verkle_wasm.js';
import { getTreeKey, getTreeKeyHash, updateCommitment, createProof, verifyProof } from './verkleFFI.js';
export { initVerkleWasm, getTreeKey, getTreeKeyHash, updateCommitment, zeroCommitment, verifyExecutionWitnessPreState, createProof, verifyProof };
import { getTreeKey, getTreeKeyHash, updateCommitment, createProof, verifyProof, type ProverInput, type VerifierInput } from './verkleFFI.js';
export { initVerkleWasm, getTreeKey, getTreeKeyHash, updateCommitment, zeroCommitment, verifyExecutionWitnessPreState, createProof, verifyProof, type ProverInput, type VerifierInput, };
//# sourceMappingURL=index.d.ts.map

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

import { initVerkleWasm, zeroCommitment, verifyExecutionWitnessPreState } from '../wasm/rust_verkle_wasm.js';
import { getTreeKey, getTreeKeyHash, updateCommitment, createProof, verifyProof } from './verkleFFI.js';
export { initVerkleWasm, getTreeKey, getTreeKeyHash, updateCommitment, zeroCommitment, verifyExecutionWitnessPreState, createProof, verifyProof };
import { initVerkleWasm, zeroCommitment, verifyExecutionWitnessPreState, } from '../wasm/rust_verkle_wasm.js';
import { getTreeKey, getTreeKeyHash, updateCommitment, createProof, verifyProof, } from './verkleFFI.js';
export { initVerkleWasm, getTreeKey, getTreeKeyHash, updateCommitment, zeroCommitment, verifyExecutionWitnessPreState, createProof, verifyProof, };
//# sourceMappingURL=index.js.map

@@ -5,4 +5,16 @@ import { Context as VerkleFFI } from '../wasm/rust_verkle_wasm.js';

export declare function updateCommitment(verkleFFI: VerkleFFI, commitment: Uint8Array, commitmentIndex: number, oldScalarValue: Uint8Array, newScalarValue: Uint8Array): Uint8Array;
export declare function createProof(verkleFFI: VerkleFFI, bytes: Uint8Array): Uint8Array;
export declare function verifyProof(verkleFFI: VerkleFFI, proof: Uint8Array): boolean;
export declare function createProof(verkleFFI: VerkleFFI, proverInputs: ProverInput[]): Uint8Array;
export declare function verifyProof(verkleFFI: VerkleFFI, proof: Uint8Array, verifierInputs: VerifierInput[]): boolean;
export interface ProverInput {
serializedCommitment: Uint8Array;
vector: Uint8Array[];
indices: number[];
}
export interface VerifierInput {
serializedCommitment: Uint8Array;
indexValuePairs: Array<{
index: number;
value: Uint8Array;
}>;
}
//# sourceMappingURL=verkleFFI.d.ts.map

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

import { concatBytes } from '@ethereumjs/util';
// This is equal to 2n + 256n * 64n.

@@ -86,8 +87,30 @@ //

}
export function createProof(verkleFFI, bytes) {
return verkleFFI.createProof(bytes);
export function createProof(verkleFFI, proverInputs) {
const serializedProofInputs = serializedProverInputs(proverInputs);
return verkleFFI.createProof(serializedProofInputs);
}
export function verifyProof(verkleFFI, proof) {
return verkleFFI.verifyProof(proof);
export function verifyProof(verkleFFI, proof, verifierInputs) {
const serializedVerifierInput = serializeVerifierInputs(proof, verifierInputs);
return verkleFFI.verifyProof(serializedVerifierInput);
}
function serializedProverInputs(proofInputs) {
const serializedProverInputs = proofInputs.flatMap(({ serializedCommitment, vector, indices }) => indices.flatMap((index) => [
serializedCommitment,
...vector,
new Uint8Array([index]),
vector[index],
]));
return concatBytes(...serializedProverInputs);
}
function serializeVerifierInputs(proof, verifierInputs) {
const serializedVerifierInputs = [
proof,
...verifierInputs.flatMap(({ serializedCommitment, indexValuePairs }) => indexValuePairs.flatMap(({ index, value }) => [
serializedCommitment,
new Uint8Array([index]),
value,
])),
];
return concatBytes(...serializedVerifierInputs);
}
//# sourceMappingURL=verkleFFI.js.map
{
"name": "verkle-cryptography-wasm",
"version": "0.4.6",
"version": "0.4.7",
"description": "Verkle Trie Crytography WASM/TypeScript Bindings",

@@ -54,3 +54,3 @@ "keywords": [

"@typescript-eslint/parser": "^6.7.3",
"@vitest/browser": "^1.4.0",
"@vitest/browser": "^2.0.5",
"babel-plugin-transform-import-meta": "^2.2.1",

@@ -68,3 +68,3 @@ "eslint": "^8.50.0",

"vite-plugin-wasm": "^3.3.0",
"vitest": "^1.2.2"
"vitest": "^2.0.5"
},

@@ -78,2 +78,2 @@ "engines": {

}
}
}

@@ -10,2 +10,4 @@ import {

verifyProof as verifyProofBase,
type ProverInput as ProverInputBase,
type VerifierInput as VerifierInputBase,
} from './verkleFFIBindings/index.js'

@@ -33,4 +35,6 @@ import { Context as VerkleFFI } from './wasm/rust_verkle_wasm.js'

const verifyExecutionWitnessPreState = (prestateRoot: string, execution_witness_json: string): boolean =>
verifyExecutionWitnessPreStateBase(prestateRoot, execution_witness_json)
const verifyExecutionWitnessPreState = (
prestateRoot: string,
execution_witness_json: string,
): boolean => verifyExecutionWitnessPreStateBase(prestateRoot, execution_witness_json)

@@ -41,4 +45,5 @@ const zeroCommitment = zeroCommitmentBase()

const serializeCommitment = (commitment: Uint8Array) => verkleFFI.serializeCommitment(commitment)
const createProof = (input: Uint8Array) => verkleFFI.createProof(input)
const verifyProof = (proofInput: Uint8Array) => verkleFFI.verifyProof(proofInput)
const createProof = (proverInputs: ProverInput[]) => createProofBase(verkleFFI, proverInputs)
const verifyProof = (proof: Uint8Array, verifierInputs: VerifierInput[]) =>
verifyProofBase(verkleFFI, proof, verifierInputs)
return {

@@ -53,6 +58,12 @@ getTreeKey,

createProof,
verifyProof
verifyProof,
}
}
// Input used to create proofs over vectors
export type ProverInput = ProverInputBase
// Input needed to verify proofs over vectors
// alongside the proof.
export type VerifierInput = VerifierInputBase
// This is a 32 byte serialized field element

@@ -63,2 +74,2 @@ export type Scalar = Uint8Array

// It is 64 bytes because the point is serialized in uncompressed format.
export type Commitment = Uint8Array
export type Commitment = Uint8Array
import { bytesToHex, randomBytes } from '@ethereumjs/util'
import { beforeAll, describe, expect, test, assert } from 'vitest'
import { VerkleCrypto, loadVerkleCrypto } from '../index.js'
import { ProverInput, VerifierInput, loadVerkleCrypto } from '../index.js'
import { verifyExecutionWitnessPreState, Context as VerkleFFI } from '../wasm/rust_verkle_wasm.js'
import kaustinenBlock72 from './data/kaustinen6Block72.json'

@@ -11,3 +12,3 @@ import kaustinenBlock73 from './data/kaustinen6Block73.json'

let ffi: VerkleFFI
let verkleCrypto: VerkleCrypto
let verkleCrypto: Awaited<ReturnType<typeof loadVerkleCrypto>>
beforeAll(async () => {

@@ -142,2 +143,95 @@ verkleCrypto = await loadVerkleCrypto()

test('createVerifyProof', () => {
// Preparation stage
//
// First we will emulate having a node with children.
//
// In verkle, the maximum number of children an internal node can have is 256.
const NUMBER_OF_CHILDREN = 256
// Populate the vector with 256 values.
const children = []
for (let i = 0; i < NUMBER_OF_CHILDREN; i++) {
children.push(createScalarFromIndex(i))
}
// Commit to that vector/children
const commitment = ffi.commitToScalars(children)
// Serialize the commitment
//
// This is the format that they should arrive in, over the wire
const serializedCommitment = ffi.serializeCommitment(commitment)
// Create proof
//
const proofInputs: ProverInput[] = [
{ serializedCommitment: serializedCommitment, vector: children, indices: [1, 2] },
]
const proof = verkleCrypto.createProof(proofInputs)
// Verify proof
//
const verifierInputs: VerifierInput[] = [
{
serializedCommitment: serializedCommitment,
indexValuePairs: [
{ index: 1, value: children[1] },
{ index: 2, value: children[2] },
],
},
]
const valid = verkleCrypto.verifyProof(proof, verifierInputs)
expect(valid).toBe(true)
})
test('createVerifyProofMultipleCommitments', () => {
const NUMBER_OF_CHILDREN = 256
// Create two sets of vectors
const children1 = Array.from({ length: NUMBER_OF_CHILDREN }, (_, i) => createScalarFromIndex(i))
const children2 = Array.from({ length: NUMBER_OF_CHILDREN }, (_, i) =>
createScalarFromIndex(i + NUMBER_OF_CHILDREN),
)
// Create commitments for both sets
const commitment1 = ffi.commitToScalars(children1)
const commitment2 = ffi.commitToScalars(children2)
// Serialize the commitments
const serializedCommitment1 = verkleCrypto.serializeCommitment(commitment1)
const serializedCommitment2 = verkleCrypto.serializeCommitment(commitment2)
// Create proof
const proofInputs: ProverInput[] = [
{ serializedCommitment: serializedCommitment1, vector: children1, indices: [1, 2] },
{ serializedCommitment: serializedCommitment2, vector: children2, indices: [3, 4] },
]
const proof = verkleCrypto.createProof(proofInputs)
// Verify proof
const verifierInputs: VerifierInput[] = [
{
serializedCommitment: serializedCommitment1,
indexValuePairs: [
{ index: 1, value: children1[1] },
{ index: 2, value: children1[2] },
],
},
{
serializedCommitment: serializedCommitment2,
indexValuePairs: [
{ index: 3, value: children2[3] },
{ index: 4, value: children2[4] },
],
},
]
const valid = verkleCrypto.verifyProof(proof, verifierInputs)
expect(valid).toBe(true)
})
test('serializeCommitment', () => {

@@ -234,1 +328,9 @@ // Create a commitment that we can hash

})
function createScalarFromIndex(index: number): Uint8Array {
const BYTES_PER_SCALAR = 32
const scalar = new Uint8Array(BYTES_PER_SCALAR)
scalar[0] = index // Set first byte to index (little-endian)
return scalar
}

@@ -1,4 +0,16 @@

import { initVerkleWasm, zeroCommitment, verifyExecutionWitnessPreState } from '../wasm/rust_verkle_wasm.js'
import {
initVerkleWasm,
zeroCommitment,
verifyExecutionWitnessPreState,
} from '../wasm/rust_verkle_wasm.js'
import { getTreeKey, getTreeKeyHash, updateCommitment, createProof, verifyProof } from './verkleFFI.js'
import {
getTreeKey,
getTreeKeyHash,
updateCommitment,
createProof,
verifyProof,
type ProverInput,
type VerifierInput,
} from './verkleFFI.js'

@@ -13,3 +25,5 @@ export {

createProof,
verifyProof
verifyProof,
type ProverInput,
type VerifierInput,
}

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

import { concatBytes } from '@ethereumjs/util'
import { Context as VerkleFFI } from '../wasm/rust_verkle_wasm.js'

@@ -117,8 +119,63 @@

export function createProof(verkleFFI: VerkleFFI, bytes: Uint8Array): Uint8Array {
return verkleFFI.createProof(bytes)
export function createProof(verkleFFI: VerkleFFI, proverInputs: ProverInput[]): Uint8Array {
const serializedProofInputs = serializedProverInputs(proverInputs)
return verkleFFI.createProof(serializedProofInputs)
}
export function verifyProof(verkleFFI: VerkleFFI, proof: Uint8Array): boolean {
return verkleFFI.verifyProof(proof)
}
export function verifyProof(
verkleFFI: VerkleFFI,
proof: Uint8Array,
verifierInputs: VerifierInput[],
): boolean {
const serializedVerifierInput = serializeVerifierInputs(proof, verifierInputs)
return verkleFFI.verifyProof(serializedVerifierInput)
}
export interface ProverInput {
// Commitment to the vector we want to create a proof for
serializedCommitment: Uint8Array
// The vector that we want to make proofs over
vector: Uint8Array[]
// The indices that we want to prove exist in the vector
indices: number[]
}
function serializedProverInputs(proofInputs: ProverInput[]): Uint8Array {
const serializedProverInputs = proofInputs.flatMap(({ serializedCommitment, vector, indices }) =>
indices.flatMap((index) => [
serializedCommitment,
...vector,
new Uint8Array([index]),
vector[index],
]),
)
return concatBytes(...serializedProverInputs)
}
export interface VerifierInput {
// A commitment to the vector that we want to verify
// proofs over.
serializedCommitment: Uint8Array
// A tuple of index and values that we want to verify about the
// committed vector.
//
// ie (index_i, value_i) will verify that the value of the committed
// vector at index `index_i` was `value_i`
indexValuePairs: Array<{ index: number; value: Uint8Array }>
}
function serializeVerifierInputs(proof: Uint8Array, verifierInputs: VerifierInput[]): Uint8Array {
const serializedVerifierInputs = [
proof,
...verifierInputs.flatMap(({ serializedCommitment, indexValuePairs }) =>
indexValuePairs.flatMap(({ index, value }) => [
serializedCommitment,
new Uint8Array([index]),
value,
]),
),
]
return concatBytes(...serializedVerifierInputs)
}

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 too big to display

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 too big to display

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