Skip to content

Commit

Permalink
Make packages JSR ready
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarhussain committed Feb 27, 2025
1 parent 089daed commit 6a4f500
Show file tree
Hide file tree
Showing 257 changed files with 928 additions and 827 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ node_modules
!.yarn/versions

# Deno
deno.lock
deno.lock
# Dnt generate npm package
packages/*/npm/
15 changes: 14 additions & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
{
"nodeModulesDir": "auto"
"nodeModulesDir": "auto",
"workspace": [
"./packages/as-sha256",
"./packages/persistent-merkle-tree",
"./packages/persistent-ts",
"./packages/simpleserialize.com",
"./packages/ssz"
],
"tasks": {
"test": "deno task --filter ssz test:unit"
},
"imports": {
"@deno/dnt": "jsr:@deno/dnt@^0.41.3"
}
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"scripts": {
"clean": "lerna run clean",
"generate": "lerna run generate",
"build": "yarn clean && lerna run build",
"lint": "lerna run lint",
"check-types": "lerna run check-types",
"test:browsers": "lerna run test:browsers",
Expand Down
10 changes: 10 additions & 0 deletions packages/as-sha256/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {build, emptyDir} from "@deno/dnt";
import packageJSON from "./package.json" with {type: "json"};
import {getBuildOptions} from "../../scripts/build_npm.ts";

await emptyDir("./npm");

await build({
...getBuildOptions(packageJSON),
entryPoints: ["./src/index.ts"],
});
6 changes: 2 additions & 4 deletions packages/as-sha256/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
"url": "git+https://github.com/chainsafe/ssz.git"
},
"type": "module",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"main": "src/index.ts",
"files": [
"lib",
"build"
],
"scripts": {
Expand All @@ -32,7 +30,7 @@
"asbuild:simd": "yarn asbuild:simd:untouched && yarn asbuild:simd:optimized",
"build:lib": "tsc -p tsconfig.build.json",
"build:web": "webpack --mode production --entry ./index.js --output ./dist/as-sha256.min.js",
"build": "yarn asbuild && yarn asbuild:simd && yarn generate && yarn build:lib",
"build": "yarn asbuild && yarn asbuild:simd && yarn generate",
"test:unit": "vitest run --dir test/unit/",
"test:browsers": "vitest run --config ./vitest.browser.config.ts --dir test/unit",
"benchmark": "node -r ts-node/register ./node_modules/.bin/benchmark 'test/perf/*.test.ts'",
Expand Down
10 changes: 5 additions & 5 deletions packages/as-sha256/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {allocUnsafe} from "./alloc.js";
import {newInstance, WasmContext} from "./wasm.js";
import type {HashObject} from "./hashObject.js";
import {byteArrayIntoHashObject, byteArrayToHashObject, hashObjectToByteArray} from "./hashObject.js";
import SHA256 from "./sha256.js";
import {allocUnsafe} from "./alloc.ts";
import {newInstance, WasmContext} from "./wasm.ts";
import type {HashObject} from "./hashObject.ts";
import {byteArrayIntoHashObject, byteArrayToHashObject, hashObjectToByteArray} from "./hashObject.ts";
import SHA256 from "./sha256.ts";
export {HashObject, byteArrayToHashObject, hashObjectToByteArray, byteArrayIntoHashObject, SHA256};

let ctx: WasmContext;
Expand Down
2 changes: 1 addition & 1 deletion packages/as-sha256/src/sha256.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {newInstance, WasmContext} from "./wasm.js";
import {newInstance, WasmContext} from "./wasm.ts";

/**
* Class based SHA256
Expand Down
4 changes: 2 additions & 2 deletions packages/as-sha256/src/wasm.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {wasmCode} from "./wasmCode.js";
import {wasmSimdCode} from "./wasmSimdCode.js";
import {wasmCode} from "./wasmCode.ts";
import {wasmSimdCode} from "./wasmSimdCode.ts";

export interface WasmContext {
readonly HAS_SIMD: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/as-sha256/test/unit/getSimdTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import {describe, beforeAll, expect, it} from "vitest";
import crypto from "crypto";
import {byteArrayToHashObject, hashObjectToByteArray} from "../../src/hashObject.js";
import {byteArrayToHashObject, hashObjectToByteArray} from "../../src/hashObject.ts";

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function getSimdTests(sha256: any, useSimd: boolean): void {
Expand Down
2 changes: 1 addition & 1 deletion packages/as-sha256/test/unit/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
digest64,
digest64HashObjects,
hashObjectToByteArray,
} from "../../src/index.js";
} from "../../src/index.ts";

describe("hashObjectToByteArray and byteArrayToHashObject", function () {
const tcs = [
Expand Down
4 changes: 2 additions & 2 deletions packages/as-sha256/test/unit/noSimd.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as sha256 from "../../src/index.js";
import {getSimdTests} from "./getSimdTests.js";
import * as sha256 from "../../src/index.ts";
import {getSimdTests} from "./getSimdTests.ts";

const useSimd = false;
getSimdTests(sha256, useSimd);
4 changes: 2 additions & 2 deletions packages/as-sha256/test/unit/simd.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as sha256 from "../../src/index.js";
import {getSimdTests} from "./getSimdTests.js";
import * as sha256 from "../../src/index.ts";
import {getSimdTests} from "./getSimdTests.ts";

const useSimd = true;
getSimdTests(sha256, useSimd);
27 changes: 27 additions & 0 deletions packages/persistent-merkle-tree/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {build, emptyDir} from "@deno/dnt";
import packageJSON from "./package.json" with {type: "json"};
import {getBuildOptions} from "../../scripts/build_npm.ts";

await emptyDir("./npm");

await build({
...getBuildOptions(packageJSON),
entryPoints: [
{
name: ".",
path: "src/index.ts"
},
{
name: "./hasher/hashtree",
path: "./src/hasher/hashtree.ts"
},
{
name: "./hasher/noble",
path: "./src/hasher/noble.ts"
},
{
name: "./hasher/as-sha256",
path: "./src/hasher/as-sha256.ts"
}
],
});
30 changes: 4 additions & 26 deletions packages/persistent-merkle-tree/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,17 @@
"description": "Merkle tree implemented as a persistent datastructure",
"type": "module",
"exports": {
".": {
"import": "./lib/index.js",
"types": "./lib/index.d.ts"
},
"./hasher/hashtree": {
"import": "./lib/hasher/hashtree.js",
"types": "./lib/hasher/hashtree.d.ts"
},
"./hasher/noble": {
"import": "./lib/hasher/noble.js",
"types": "./lib/hasher/noble.d.ts"
},
"./hasher/as-sha256": {
"import": "./lib/hasher/as-sha256.js",
"types": "./lib/hasher/as-sha256.d.ts"
}
},
"typesVersions": {
"*": {
"*": [
"*",
"lib/*",
"lib/*/index"
]
}
".": "./src/index.ts",
"./hasher/hashtree": "./src/hasher/hashtree.ts",
"./hasher/noble": "./src/hasher/noble.ts",
"./hasher/as-sha256": "./src/hasher/as-sha256.ts"
},
"files": [
"lib"
],
"scripts": {
"check-types": "tsc --noEmit",
"clean": "rm -rf lib",
"build": "tsc -p tsconfig.build.json",
"lint": "eslint --color --ext .ts src/",
"lint:fix": "yarn run lint --fix",
"benchmark:files": "node --max-old-space-size=4096 --expose-gc --loader ts-node/esm ../../node_modules/.bin/benchmark",
Expand Down
2 changes: 1 addition & 1 deletion packages/persistent-merkle-tree/src/hashComputation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {Node} from "./node.js";
import type {Node} from "./node.ts";

/**
* HashComputation to be later used to compute hash of nodes from bottom up.
Expand Down
8 changes: 4 additions & 4 deletions packages/persistent-merkle-tree/src/hasher/as-sha256.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import {
batchHash4HashObjectInputs,
hashInto,
} from "@chainsafe/as-sha256";
import type {Hasher} from "./types.js";
import {Node} from "../node.js";
import type {HashComputationLevel} from "../hashComputation.js";
import {BLOCK_SIZE, doDigestNLevel, doMerkleizeBlockArray, doMerkleizeBlocksBytes} from "./util.js";
import type {Hasher} from "./types.ts";
import {Node} from "../node.ts";
import type {HashComputationLevel} from "../hashComputation.ts";
import {BLOCK_SIZE, doDigestNLevel, doMerkleizeBlockArray, doMerkleizeBlocksBytes} from "./util.ts";

/**
* hashInto() function of as-sha256 loop through every 256 bytes
Expand Down
8 changes: 4 additions & 4 deletions packages/persistent-merkle-tree/src/hasher/hashtree.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {hashInto} from "@chainsafe/hashtree";
import {Hasher, HashObject} from "./types.js";
import {Node} from "../node.js";
import type {HashComputationLevel} from "../hashComputation.js";
import {Hasher, HashObject} from "./types.ts";
import {Node} from "../node.ts";
import type {HashComputationLevel} from "../hashComputation.ts";
import {byteArrayIntoHashObject} from "@chainsafe/as-sha256";
import {doDigestNLevel, doMerkleizeBlockArray, doMerkleizeBlocksBytes} from "./util.js";
import {doDigestNLevel, doMerkleizeBlockArray, doMerkleizeBlocksBytes} from "./util.ts";

/**
* Best SIMD implementation is in 512 bits = 64 bytes
Expand Down
10 changes: 5 additions & 5 deletions packages/persistent-merkle-tree/src/hasher/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Hasher} from "./types.js";
import {hasher as nobleHasher} from "./noble.js";
import type {HashComputationLevel} from "../hashComputation.js";
import {Hasher} from "./types.ts";
import {hasher as nobleHasher} from "./noble.ts";
import type {HashComputationLevel} from "../hashComputation.ts";

export * from "./types.js";
export * from "./util.js";
export * from "./types.ts";
export * from "./util.ts";

/**
* Hasher used across the SSZ codebase, by default, this does not support batch hash.
Expand Down
4 changes: 2 additions & 2 deletions packages/persistent-merkle-tree/src/hasher/noble.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {sha256} from "@noble/hashes/sha256";
import {digest64HashObjects, byteArrayIntoHashObject} from "@chainsafe/as-sha256";
import type {Hasher} from "./types.js";
import type {Hasher} from "./types.ts";
import {
BLOCK_SIZE,
doDigestNLevel,
doMerkleizeBlockArray,
doMerkleizeBlocksBytes,
hashObjectToUint8Array,
} from "./util.js";
} from "./util.ts";

const digest64 = (a: Uint8Array, b: Uint8Array): Uint8Array => sha256.create().update(a).update(b).digest();
const hashInto = (input: Uint8Array, output: Uint8Array): void => {
Expand Down
2 changes: 1 addition & 1 deletion packages/persistent-merkle-tree/src/hasher/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {HashObject} from "@chainsafe/as-sha256";
import type {HashComputationLevel} from "../hashComputation.js";
import type {HashComputationLevel} from "../hashComputation.ts";

export type {HashObject};

Expand Down
2 changes: 1 addition & 1 deletion packages/persistent-merkle-tree/src/hasher/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {byteArrayToHashObject, HashObject, hashObjectToByteArray} from "@chainsafe/as-sha256";
import {zeroHash} from "../zeroHash.js";
import {zeroHash} from "../zeroHash.ts";

export function hashObjectToUint8Array(obj: HashObject): Uint8Array {
const byteArr = new Uint8Array(32);
Expand Down
22 changes: 11 additions & 11 deletions packages/persistent-merkle-tree/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export * from "./gindex.js";
export * from "./hasher/index.js";
export * from "./node.js";
export * from "./hashComputation.js";
export * from "./packedNode.js";
export * from "./proof/index.js";
export * from "./subtree.js";
export * from "./tree.js";
export * from "./zeroNode.js";
export * from "./zeroHash.js";
export * from "./snapshot.js";
export * from "./gindex.ts";
export * from "./hasher/index.ts";
export * from "./node.ts";
export * from "./hashComputation.ts";
export * from "./packedNode.ts";
export * from "./proof/index.ts";
export * from "./subtree.ts";
export * from "./tree.ts";
export * from "./zeroNode.ts";
export * from "./zeroHash.ts";
export * from "./snapshot.ts";
2 changes: 1 addition & 1 deletion packages/persistent-merkle-tree/src/node.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {HashObject} from "@chainsafe/as-sha256";
import {hashObjectToUint8Array, hasher, uint8ArrayToHashObject} from "./hasher/index.js";
import {hashObjectToUint8Array, hasher, uint8ArrayToHashObject} from "./hasher/index.ts";

const TWO_POWER_32 = 2 ** 32;

Expand Down
4 changes: 2 additions & 2 deletions packages/persistent-merkle-tree/src/packedNode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {subtreeFillToContents} from "./subtree.js";
import {Node, LeafNode, getNodeH, setNodeH} from "./node.js";
import {subtreeFillToContents} from "./subtree.ts";
import {Node, LeafNode, getNodeH, setNodeH} from "./node.ts";

const NUMBER_2_POW_32 = 2 ** 32;

Expand Down
6 changes: 3 additions & 3 deletions packages/persistent-merkle-tree/src/proof/compactMulti.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {convertGindexToBitstring, Gindex, GindexBitstring} from "../gindex.js";
import {BranchNode, LeafNode, Node} from "../node.js";
import {computeProofBitstrings} from "./util.js";
import {convertGindexToBitstring, Gindex, GindexBitstring} from "../gindex.ts";
import {BranchNode, LeafNode, Node} from "../node.ts";
import {computeProofBitstrings} from "./util.ts";

export function computeDescriptor(indices: Gindex[]): Uint8Array {
// include all helper indices
Expand Down
14 changes: 7 additions & 7 deletions packages/persistent-merkle-tree/src/proof/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {Gindex} from "../gindex.js";
import {Node} from "../node.js";
import {createMultiProof, createNodeFromMultiProof} from "./multi.js";
import {createNodeFromCompactMultiProof, createCompactMultiProof} from "./compactMulti.js";
import {createNodeFromSingleProof, createSingleProof} from "./single.js";
import {Gindex} from "../gindex.ts";
import {Node} from "../node.ts";
import {createMultiProof, createNodeFromMultiProof} from "./multi.ts";
import {createNodeFromCompactMultiProof, createCompactMultiProof} from "./compactMulti.ts";
import {createNodeFromSingleProof, createSingleProof} from "./single.ts";
import {
computeTreeOffsetProofSerializedLength,
createNodeFromTreeOffsetProof,
createTreeOffsetProof,
deserializeTreeOffsetProof,
serializeTreeOffsetProof,
} from "./treeOffset.js";
} from "./treeOffset.ts";

export {computeDescriptor, descriptorToBitlist} from "./compactMulti.js";
export {computeDescriptor, descriptorToBitlist} from "./compactMulti.ts";

export enum ProofType {
single = "single",
Expand Down
8 changes: 4 additions & 4 deletions packages/persistent-merkle-tree/src/proof/multi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Gindex} from "../gindex.js";
import {BranchNode, LeafNode, Node} from "../node.js";
import {Tree} from "../tree.js";
import {computeMultiProofBitstrings, SortOrder} from "./util.js";
import {Gindex} from "../gindex.ts";
import {BranchNode, LeafNode, Node} from "../node.ts";
import {Tree} from "../tree.ts";
import {computeMultiProofBitstrings, SortOrder} from "./util.ts";

/**
* Create an multiproof
Expand Down
4 changes: 2 additions & 2 deletions packages/persistent-merkle-tree/src/proof/single.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {BranchNode, LeafNode, Node} from "../node.js";
import {Gindex, gindexIterator} from "../gindex.js";
import {BranchNode, LeafNode, Node} from "../node.ts";
import {Gindex, gindexIterator} from "../gindex.ts";

export const ERR_INVALID_NAV = "Invalid tree navigation";

Expand Down
6 changes: 3 additions & 3 deletions packages/persistent-merkle-tree/src/proof/treeOffset.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Gindex, GindexBitstring} from "../gindex.js";
import {BranchNode, LeafNode, Node} from "../node.js";
import {computeMultiProofBitstrings} from "./util.js";
import {Gindex, GindexBitstring} from "../gindex.ts";
import {BranchNode, LeafNode, Node} from "../node.ts";
import {computeMultiProofBitstrings} from "./util.ts";

/**
* Compute offsets and leaves of a tree-offset proof
Expand Down
2 changes: 1 addition & 1 deletion packages/persistent-merkle-tree/src/proof/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Gindex, GindexBitstring, gindexParent, gindexSibling} from "../gindex.js";
import {Gindex, GindexBitstring, gindexParent, gindexSibling} from "../gindex.ts";

// Not currently in use, but simpler implementation useful for testing
/**
Expand Down
Loading

0 comments on commit 6a4f500

Please sign in to comment.