diff --git a/js/package.json b/js/package.json index a1315ced..6ec9e039 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "@confio/ics23", - "version": "0.6.0", + "version": "0.6.3", "description": "Merkle proof verification library - implements Cosmos ICS23 Spec", "main": "build/index.js", "types": "build/index.d.ts", diff --git a/js/src/index.ts b/js/src/index.ts index e21738ba..515de8ec 100644 --- a/js/src/index.ts +++ b/js/src/index.ts @@ -3,6 +3,8 @@ export { verifyMembership, verifyNonMembership } from "./ics23"; export { calculateExistenceRoot, CommitmentRoot, + iavlSpec, + tendermintSpec, verifyExistence, verifyNonExistence } from "./proofs"; diff --git a/js/src/proofs.spec.ts b/js/src/proofs.spec.ts index d41b5e7b..23f3da5d 100644 --- a/js/src/proofs.spec.ts +++ b/js/src/proofs.spec.ts @@ -1,7 +1,7 @@ import { ics23 } from "./generated/codecimpl"; import { fromHex, toAscii } from "./helpers"; -import { calculateExistenceRoot, ensureSpec, IavlSpec } from "./proofs"; +import { calculateExistenceRoot, ensureSpec, iavlSpec } from "./proofs"; describe("calculateExistenceRoot", () => { it("must have at least one step", () => { @@ -63,7 +63,7 @@ describe("calculateExistenceRoot", () => { }); describe("ensureSpec", () => { - const validLeaf = IavlSpec.leafSpec; + const validLeaf = iavlSpec.leafSpec; const invalidLeaf = { prefix: Uint8Array.from([0]), hash: ics23.HashOp.SHA512, @@ -87,8 +87,8 @@ describe("ensureSpec", () => { }; const depthLimitedSpec = { - leafSpec: IavlSpec.leafSpec, - innerSpec: IavlSpec.innerSpec, + leafSpec: iavlSpec.leafSpec, + innerSpec: iavlSpec.innerSpec, minDepth: 2, maxDepth: 4 }; @@ -98,7 +98,7 @@ describe("ensureSpec", () => { key: toAscii("foo"), value: toAscii("bar") }; - expect(() => ensureSpec(proof, IavlSpec)).toThrow(); + expect(() => ensureSpec(proof, iavlSpec)).toThrow(); }); it("accepts one valid leaf", () => { @@ -108,7 +108,7 @@ describe("ensureSpec", () => { leaf: validLeaf }; // fail if this throws (invalid spec) - ensureSpec(proof, IavlSpec); + ensureSpec(proof, iavlSpec); }); it("rejects invalid leaf", () => { @@ -117,7 +117,7 @@ describe("ensureSpec", () => { value: toAscii("bar"), leaf: invalidLeaf }; - expect(() => ensureSpec(proof, IavlSpec)).toThrow(); + expect(() => ensureSpec(proof, iavlSpec)).toThrow(); }); it("rejects inner without leaf", () => { @@ -126,7 +126,7 @@ describe("ensureSpec", () => { value: toAscii("bar"), path: [validInner] }; - expect(() => ensureSpec(proof, IavlSpec)).toThrow(); + expect(() => ensureSpec(proof, iavlSpec)).toThrow(); }); it("accepts leaf with one inner", () => { @@ -137,7 +137,7 @@ describe("ensureSpec", () => { path: [validInner] }; // fail if this throws (invalid spec) - ensureSpec(proof, IavlSpec); + ensureSpec(proof, iavlSpec); }); it("rejects with invalid inner (prefix)", () => { @@ -147,7 +147,7 @@ describe("ensureSpec", () => { leaf: validLeaf, path: [invalidInner, validInner] }; - expect(() => ensureSpec(proof, IavlSpec)).toThrow(); + expect(() => ensureSpec(proof, iavlSpec)).toThrow(); }); it("rejects with invalid inner (hash)", () => { @@ -157,7 +157,7 @@ describe("ensureSpec", () => { leaf: validLeaf, path: [validInner, invalidInnerHash] }; - expect(() => ensureSpec(proof, IavlSpec)).toThrow(); + expect(() => ensureSpec(proof, iavlSpec)).toThrow(); }); it("accepts depth limited with proper number of nodes", () => { diff --git a/js/src/proofs.ts b/js/src/proofs.ts index e137ac4f..d5664091 100644 --- a/js/src/proofs.ts +++ b/js/src/proofs.ts @@ -8,7 +8,7 @@ import { ensureLeaf } from "./specs"; -export const IavlSpec: ics23.IProofSpec = { +export const iavlSpec: ics23.IProofSpec = { leafSpec: { prefix: Uint8Array.from([0]), hash: ics23.HashOp.SHA256, @@ -25,7 +25,7 @@ export const IavlSpec: ics23.IProofSpec = { } }; -export const TendermintSpec: ics23.IProofSpec = { +export const tendermintSpec: ics23.IProofSpec = { leafSpec: { prefix: Uint8Array.from([0]), hash: ics23.HashOp.SHA256, diff --git a/js/src/testvectors.spec.ts b/js/src/testvectors.spec.ts index c4e3240b..b585c49a 100644 --- a/js/src/testvectors.spec.ts +++ b/js/src/testvectors.spec.ts @@ -9,7 +9,7 @@ import { verifyMembership, verifyNonMembership } from "./ics23"; -import { IavlSpec, TendermintSpec } from "./proofs"; +import { iavlSpec, tendermintSpec } from "./proofs"; describe("calculateExistenceRoot", () => { interface RefData { @@ -61,58 +61,58 @@ describe("calculateExistenceRoot", () => { } it("should parse iavl left", () => { - validateTestVector("../testdata/iavl/exist_left.json", IavlSpec); + validateTestVector("../testdata/iavl/exist_left.json", iavlSpec); }); it("should parse iavl right", () => { - validateTestVector("../testdata/iavl/exist_right.json", IavlSpec); + validateTestVector("../testdata/iavl/exist_right.json", iavlSpec); }); it("should parse iavl middle", () => { - validateTestVector("../testdata/iavl/exist_middle.json", IavlSpec); + validateTestVector("../testdata/iavl/exist_middle.json", iavlSpec); }); it("should parse iavl left - nonexist", () => { - validateTestVector("../testdata/iavl/nonexist_left.json", IavlSpec); + validateTestVector("../testdata/iavl/nonexist_left.json", iavlSpec); }); it("should parse iavl right - nonexist", () => { - validateTestVector("../testdata/iavl/nonexist_right.json", IavlSpec); + validateTestVector("../testdata/iavl/nonexist_right.json", iavlSpec); }); it("should parse iavl middle - nonexist", () => { - validateTestVector("../testdata/iavl/nonexist_middle.json", IavlSpec); + validateTestVector("../testdata/iavl/nonexist_middle.json", iavlSpec); }); it("should parse tendermint left", () => { validateTestVector( "../testdata/tendermint/exist_left.json", - TendermintSpec + tendermintSpec ); }); it("should parse tendermint right", () => { validateTestVector( "../testdata/tendermint/exist_right.json", - TendermintSpec + tendermintSpec ); }); it("should parse tendermint middle", () => { validateTestVector( "../testdata/tendermint/exist_middle.json", - TendermintSpec + tendermintSpec ); }); it("should parse tendermint left - nonexist", () => { validateTestVector( "../testdata/tendermint/nonexist_left.json", - TendermintSpec + tendermintSpec ); }); it("should parse tendermint right - nonexist", () => { validateTestVector( "../testdata/tendermint/nonexist_right.json", - TendermintSpec + tendermintSpec ); }); it("should parse tendermint middle - nonexist", () => { validateTestVector( "../testdata/tendermint/nonexist_middle.json", - TendermintSpec + tendermintSpec ); }); @@ -172,7 +172,7 @@ describe("calculateExistenceRoot", () => { "../testdata/iavl/nonexist_right.json", "../testdata/iavl/nonexist_middle.json" ]); - validateBatch(proof, IavlSpec, data[0]); + validateBatch(proof, iavlSpec, data[0]); }); it("should validate iavl batch nonexist", () => { @@ -184,7 +184,7 @@ describe("calculateExistenceRoot", () => { "../testdata/iavl/nonexist_right.json", "../testdata/iavl/nonexist_middle.json" ]); - validateBatch(proof, IavlSpec, data[5]); + validateBatch(proof, iavlSpec, data[5]); }); it("should validate compressed iavl batch exist", () => { @@ -205,7 +205,7 @@ describe("calculateExistenceRoot", () => { expect(origBin).toEqual(origBin2); expect(origBin).not.toEqual(smallBin); - validateBatch(small, IavlSpec, data[0]); + validateBatch(small, iavlSpec, data[0]); }); it("should validate compressed iavl batch nonexist", () => { @@ -226,7 +226,7 @@ describe("calculateExistenceRoot", () => { expect(origBin).toEqual(origBin2); expect(origBin).not.toEqual(smallBin); - validateBatch(small, IavlSpec, data[5]); + validateBatch(small, iavlSpec, data[5]); }); it("should validate tendermint batch exist", () => { @@ -238,7 +238,7 @@ describe("calculateExistenceRoot", () => { "../testdata/tendermint/nonexist_right.json", "../testdata/tendermint/nonexist_middle.json" ]); - validateBatch(proof, TendermintSpec, data[2]); + validateBatch(proof, tendermintSpec, data[2]); }); it("should validate tendermint batch nonexist", () => { @@ -250,6 +250,6 @@ describe("calculateExistenceRoot", () => { "../testdata/tendermint/nonexist_right.json", "../testdata/tendermint/nonexist_middle.json" ]); - validateBatch(proof, TendermintSpec, data[3]); + validateBatch(proof, tendermintSpec, data[3]); }); });