diff --git a/js/package.json b/js/package.json index 138564456..ff1a1eaae 100644 --- a/js/package.json +++ b/js/package.json @@ -34,7 +34,7 @@ "@types/jasmine": "^3.5.0", "jasmine": "^3.5.0", "jasmine-console-reporter": "^3.1.0", - "prettier": "^1.17.0", + "prettier": "^2.5.1", "shx": "^0.3.4", "source-map-support": "^0.5.16", "tslint": "^5.8.0", diff --git a/js/src/compress.ts b/js/src/compress.ts index cc411f8f6..6e8919686 100644 --- a/js/src/compress.ts +++ b/js/src/compress.ts @@ -34,8 +34,8 @@ function compress_batch(proof: ics23.IBatchProof): ics23.ICompressedBatchProof { nonexist: { key: non.key, left: compress_exist(non.left, lookup, registry), - right: compress_exist(non.right, lookup, registry) - } + right: compress_exist(non.right, lookup, registry), + }, }; centries.push(centry); } else { @@ -45,7 +45,7 @@ function compress_batch(proof: ics23.IBatchProof): ics23.ICompressedBatchProof { return { entries: centries, - lookupInners: lookup + lookupInners: lookup, }; } @@ -58,7 +58,7 @@ function compress_exist( return undefined; } - const path = exist.path!.map(inner => { + const path = exist.path!.map((inner) => { const sig = ics23.InnerOp.encode(inner).finish(); let idx = registry.get(sig); if (idx === undefined) { @@ -73,7 +73,7 @@ function compress_exist( key: exist.key, value: exist.value, leaf: exist.leaf, - path + path, }; } @@ -81,7 +81,7 @@ function decompress_batch( proof: ics23.ICompressedBatchProof ): ics23.IBatchProof { const lookup = proof.lookupInners!; - const entries = proof.entries!.map(comp => { + const entries = proof.entries!.map((comp) => { if (!!comp.exist) { return { exist: decompress_exist(comp.exist, lookup) }; } else if (!!comp.nonexist) { @@ -90,15 +90,15 @@ function decompress_batch( nonexist: { key: non.key, left: decompress_exist(non.left, lookup), - right: decompress_exist(non.right, lookup) - } + right: decompress_exist(non.right, lookup), + }, }; } else { throw new Error("Unexpected batch entry during compress"); } }); return { - entries + entries, }; } @@ -110,6 +110,6 @@ function decompress_exist( return undefined; } const { key, value, leaf, path } = exist; - const newPath = (path || []).map(idx => lookup[idx]); + const newPath = (path || []).map((idx) => lookup[idx]); return { key, value, leaf, path: newPath }; } diff --git a/js/src/generated/codecimpl.d.ts b/js/src/generated/codecimpl.d.ts index c05e5a128..b49b82ff9 100644 --- a/js/src/generated/codecimpl.d.ts +++ b/js/src/generated/codecimpl.d.ts @@ -9,7 +9,7 @@ export namespace ics23 { KECCAK = 3, RIPEMD160 = 4, BITCOIN = 5, - SHA512_256 = 6 + SHA512_256 = 6, } /** @@ -27,7 +27,7 @@ export namespace ics23 { FIXED64_BIG = 5, FIXED64_LITTLE = 6, REQUIRE_32_BYTES = 7, - REQUIRE_64_BYTES = 8 + REQUIRE_64_BYTES = 8, } /** Properties of an ExistenceProof. */ diff --git a/js/src/ics23.ts b/js/src/ics23.ts index cf659ca63..302e4100d 100644 --- a/js/src/ics23.ts +++ b/js/src/ics23.ts @@ -116,7 +116,7 @@ function getExistForKey( if (match(proof.exist)) { return proof.exist!; } else if (!!proof.batch) { - return proof.batch.entries!.map(x => x.exist || null).find(match); + return proof.batch.entries!.map((x) => x.exist || null).find(match); } return undefined; } @@ -135,7 +135,7 @@ function getNonExistForKey( if (match(proof.nonexist)) { return proof.nonexist!; } else if (!!proof.batch) { - return proof.batch.entries!.map(x => x.nonexist || null).find(match); + return proof.batch.entries!.map((x) => x.nonexist || null).find(match); } return undefined; } diff --git a/js/src/index.ts b/js/src/index.ts index 515de8ec8..a05eae487 100644 --- a/js/src/index.ts +++ b/js/src/index.ts @@ -6,5 +6,5 @@ export { iavlSpec, tendermintSpec, verifyExistence, - verifyNonExistence + verifyNonExistence, } from "./proofs"; diff --git a/js/src/ops.spec.ts b/js/src/ops.spec.ts index d99b715ae..520cf47e7 100644 --- a/js/src/ops.spec.ts +++ b/js/src/ops.spec.ts @@ -84,7 +84,7 @@ describe("applyLeaf", () => { it("hashes with length prefix", () => { const op: ics23.ILeafOp = { hash: ics23.HashOp.SHA256, - length: ics23.LengthOp.VAR_PROTO + length: ics23.LengthOp.VAR_PROTO, }; // echo -n food | xxd -ps const key = toAscii("food"); // 04666f6f64 @@ -99,7 +99,7 @@ describe("applyLeaf", () => { it("hashes with length prefix (fixed 32-bit little-endian encoding)", () => { const op: ics23.ILeafOp = { hash: ics23.HashOp.SHA256, - length: ics23.LengthOp.FIXED32_LITTLE + length: ics23.LengthOp.FIXED32_LITTLE, }; // echo -n food | xxd -ps const key = toAscii("food"); // 04000000666f6f64 @@ -115,7 +115,7 @@ describe("applyLeaf", () => { const op: ics23.ILeafOp = { hash: ics23.HashOp.SHA256, length: ics23.LengthOp.VAR_PROTO, - prehashValue: ics23.HashOp.SHA256 + prehashValue: ics23.HashOp.SHA256, }; const key = toAscii("food"); // 04666f6f64 // echo -n yet another long string | sha256sum @@ -129,7 +129,7 @@ describe("applyLeaf", () => { it("requires key", () => { const op: ics23.ILeafOp = { - hash: ics23.HashOp.SHA256 + hash: ics23.HashOp.SHA256, }; const key = toAscii("food"); const value = toAscii(""); @@ -138,7 +138,7 @@ describe("applyLeaf", () => { it("requires value", () => { const op: ics23.ILeafOp = { - hash: ics23.HashOp.SHA256 + hash: ics23.HashOp.SHA256, }; const key = toAscii(""); const value = toAscii("time"); @@ -151,7 +151,7 @@ describe("applyInner", () => { const op: ics23.IInnerOp = { hash: ics23.HashOp.SHA256, prefix: fromHex("0123456789"), - suffix: fromHex("deadbeef") + suffix: fromHex("deadbeef"), }; const child = fromHex("00cafe00"); // echo -n 012345678900cafe00deadbeef | xxd -r -p | sha256sum @@ -165,7 +165,7 @@ describe("applyInner", () => { const op: ics23.IInnerOp = { hash: ics23.HashOp.SHA256, prefix: fromHex("0123456789"), - suffix: fromHex("deadbeef") + suffix: fromHex("deadbeef"), }; expect(() => applyInner(op, fromHex(""))).toThrow(); }); @@ -173,7 +173,7 @@ describe("applyInner", () => { it("hash child with only prefix", () => { const op: ics23.IInnerOp = { hash: ics23.HashOp.SHA256, - prefix: fromHex("00204080a0c0e0") + prefix: fromHex("00204080a0c0e0"), }; const child = fromHex("ffccbb997755331100"); // echo -n 00204080a0c0e0ffccbb997755331100 | xxd -r -p | sha256sum @@ -186,7 +186,7 @@ describe("applyInner", () => { it("hash child with only suffix", () => { const op: ics23.IInnerOp = { hash: ics23.HashOp.SHA256, - suffix: toAscii(" just kidding!") + suffix: toAscii(" just kidding!"), }; const child = toAscii("this is a sha256 hash, really...."); // echo -n 'this is a sha256 hash, really.... just kidding!' | sha256sum diff --git a/js/src/ops.ts b/js/src/ops.ts index 5d744cf81..b3003a76e 100644 --- a/js/src/ops.ts +++ b/js/src/ops.ts @@ -31,7 +31,7 @@ export function applyLeaf( const data = new Uint8Array([ ...ensureBytes(leaf.prefix), ...pkey, - ...pvalue + ...pvalue, ]); return doHash(ensureHash(leaf.hash), data); } @@ -46,7 +46,7 @@ export function applyInner( const preimage = new Uint8Array([ ...ensureBytes(inner.prefix), ...child, - ...ensureBytes(inner.suffix) + ...ensureBytes(inner.suffix), ]); return doHash(ensureHash(inner.hash), preimage); } diff --git a/js/src/proofs.spec.ts b/js/src/proofs.spec.ts index c31d7a9e9..d8c822b2e 100644 --- a/js/src/proofs.spec.ts +++ b/js/src/proofs.spec.ts @@ -7,7 +7,7 @@ describe("calculateExistenceRoot", () => { it("must have at least one step", () => { const proof: ics23.IExistenceProof = { key: toAscii("foo"), - value: toAscii("bar") + value: toAscii("bar"), }; expect(() => calculateExistenceRoot(proof)).toThrow(); }); @@ -17,8 +17,8 @@ describe("calculateExistenceRoot", () => { value: toAscii("some longer text"), leaf: { hash: ics23.HashOp.SHA256, - length: ics23.LengthOp.VAR_PROTO - } + length: ics23.LengthOp.VAR_PROTO, + }, }; const expected = fromHex( "b68f5d298e915ae1753dd333da1f9cf605411a5f2e12516be6758f365e6db265" @@ -32,9 +32,9 @@ describe("calculateExistenceRoot", () => { path: [ { hash: ics23.HashOp.SHA256, - prefix: fromHex("deadbeef00cafe00") - } - ] + prefix: fromHex("deadbeef00cafe00"), + }, + ], }; expect(() => calculateExistenceRoot(proof)).toThrow(); }); @@ -44,16 +44,16 @@ describe("calculateExistenceRoot", () => { value: toAscii("some longer text"), leaf: { hash: ics23.HashOp.SHA256, - length: ics23.LengthOp.VAR_PROTO + length: ics23.LengthOp.VAR_PROTO, }, // output: b68f5d298e915ae1753dd333da1f9cf605411a5f2e12516be6758f365e6db265 path: [ { hash: ics23.HashOp.SHA256, - prefix: fromHex("deadbeef00cafe00") - } + prefix: fromHex("deadbeef00cafe00"), + }, // echo -n deadbeef00cafe00b68f5d298e915ae1753dd333da1f9cf605411a5f2e12516be6758f365e6db265 | xxd -r -p | sha256sum - ] + ], }; const expected = fromHex( "836ea236a6902a665c2a004c920364f24cad52ded20b1e4f22c3179bfe25b2a9" @@ -69,34 +69,34 @@ describe("ensureSpec", () => { hash: ics23.HashOp.SHA512, prehashValue: ics23.HashOp.NO_HASH, prehashKey: ics23.HashOp.NO_HASH, - length: ics23.LengthOp.VAR_PROTO + length: ics23.LengthOp.VAR_PROTO, }; const validInner = { hash: ics23.HashOp.SHA256, - prefix: fromHex("deadbeef00cafe00") + prefix: fromHex("deadbeef00cafe00"), // suffix: Uint8Array.from([]), }; const invalidInner = { hash: ics23.HashOp.SHA256, - prefix: fromHex("aa") + prefix: fromHex("aa"), }; const invalidInnerHash = { hash: ics23.HashOp.SHA512, - prefix: fromHex("deadbeef00cafe00") + prefix: fromHex("deadbeef00cafe00"), }; const depthLimitedSpec = { leafSpec: iavlSpec.leafSpec, innerSpec: iavlSpec.innerSpec, minDepth: 2, - maxDepth: 4 + maxDepth: 4, }; it("rejects empty proof", () => { const proof: ics23.IExistenceProof = { key: toAscii("foo"), - value: toAscii("bar") + value: toAscii("bar"), }; expect(() => ensureSpec(proof, iavlSpec)).toThrow(); }); @@ -105,7 +105,7 @@ describe("ensureSpec", () => { const proof: ics23.IExistenceProof = { key: toAscii("foo"), value: toAscii("bar"), - leaf: validLeaf + leaf: validLeaf, }; // fail if this throws (invalid spec) ensureSpec(proof, iavlSpec); @@ -115,7 +115,7 @@ describe("ensureSpec", () => { const proof: ics23.IExistenceProof = { key: toAscii("foo"), value: toAscii("bar"), - leaf: invalidLeaf + leaf: invalidLeaf, }; expect(() => ensureSpec(proof, iavlSpec)).toThrow(); }); @@ -124,7 +124,7 @@ describe("ensureSpec", () => { const proof: ics23.IExistenceProof = { key: toAscii("foo"), value: toAscii("bar"), - path: [validInner] + path: [validInner], }; expect(() => ensureSpec(proof, iavlSpec)).toThrow(); }); @@ -134,7 +134,7 @@ describe("ensureSpec", () => { key: toAscii("foo"), value: toAscii("bar"), leaf: validLeaf, - path: [validInner] + path: [validInner], }; // fail if this throws (invalid spec) ensureSpec(proof, iavlSpec); @@ -145,7 +145,7 @@ describe("ensureSpec", () => { key: toAscii("foo"), value: toAscii("bar"), leaf: validLeaf, - path: [invalidInner, validInner] + path: [invalidInner, validInner], }; expect(() => ensureSpec(proof, iavlSpec)).toThrow(); }); @@ -155,7 +155,7 @@ describe("ensureSpec", () => { key: toAscii("foo"), value: toAscii("bar"), leaf: validLeaf, - path: [validInner, invalidInnerHash] + path: [validInner, invalidInnerHash], }; expect(() => ensureSpec(proof, iavlSpec)).toThrow(); }); @@ -165,7 +165,7 @@ describe("ensureSpec", () => { key: toAscii("foo"), value: toAscii("bar"), leaf: validLeaf, - path: [validInner, validInner, validInner] + path: [validInner, validInner, validInner], }; // fail if this throws (invalid spec) ensureSpec(proof, depthLimitedSpec); @@ -176,7 +176,7 @@ describe("ensureSpec", () => { key: toAscii("foo"), value: toAscii("bar"), leaf: validLeaf, - path: [validInner] + path: [validInner], }; expect(() => ensureSpec(proof, depthLimitedSpec)).toThrow(); }); @@ -186,7 +186,7 @@ describe("ensureSpec", () => { key: toAscii("foo"), value: toAscii("bar"), leaf: validLeaf, - path: [validInner, validInner, validInner, validInner, validInner] + path: [validInner, validInner, validInner, validInner, validInner], }; expect(() => ensureSpec(proof, depthLimitedSpec)).toThrow(); }); diff --git a/js/src/proofs.ts b/js/src/proofs.ts index d56640910..17ada7590 100644 --- a/js/src/proofs.ts +++ b/js/src/proofs.ts @@ -5,7 +5,7 @@ import { ensureBytesBefore, ensureBytesEqual, ensureInner, - ensureLeaf + ensureLeaf, } from "./specs"; export const iavlSpec: ics23.IProofSpec = { @@ -14,15 +14,15 @@ export const iavlSpec: ics23.IProofSpec = { hash: ics23.HashOp.SHA256, prehashValue: ics23.HashOp.SHA256, prehashKey: ics23.HashOp.NO_HASH, - length: ics23.LengthOp.VAR_PROTO + length: ics23.LengthOp.VAR_PROTO, }, innerSpec: { childOrder: [0, 1], minPrefixLength: 4, maxPrefixLength: 12, childSize: 33, - hash: ics23.HashOp.SHA256 - } + hash: ics23.HashOp.SHA256, + }, }; export const tendermintSpec: ics23.IProofSpec = { @@ -31,15 +31,15 @@ export const tendermintSpec: ics23.IProofSpec = { hash: ics23.HashOp.SHA256, prehashValue: ics23.HashOp.SHA256, prehashKey: ics23.HashOp.NO_HASH, - length: ics23.LengthOp.VAR_PROTO + length: ics23.LengthOp.VAR_PROTO, }, innerSpec: { childOrder: [0, 1], minPrefixLength: 1, maxPrefixLength: 1, childSize: 32, - hash: ics23.HashOp.SHA256 - } + hash: ics23.HashOp.SHA256, + }, }; export type CommitmentRoot = Uint8Array; @@ -281,5 +281,5 @@ function getPosition(order: ReadonlyArray, branch: number): number { if (branch < 0 || branch >= order.length) { throw new Error(`Invalid branch: ${branch}`); } - return order.findIndex(val => val === branch); + return order.findIndex((val) => val === branch); } diff --git a/js/src/testvectors.spec.ts b/js/src/testvectors.spec.ts index db3642602..1ac2e807e 100644 --- a/js/src/testvectors.spec.ts +++ b/js/src/testvectors.spec.ts @@ -6,7 +6,7 @@ import { batchVerifyMembership, batchVerifyNonMembership, verifyMembership, - verifyNonMembership + verifyNonMembership, } from "./ics23"; import { iavlSpec, tendermintSpec } from "./proofs"; import { fromHex } from "./testhelpers.spec"; @@ -35,7 +35,7 @@ describe("calculateExistenceRoot", () => { const data = { root: fromHex(root), key: fromHex(key), - value: value ? fromHex(value) : undefined + value: value ? fromHex(value) : undefined, }; return { proof: commit, data }; @@ -49,7 +49,7 @@ describe("calculateExistenceRoot", () => { function validateTestVector(filepath: string, spec: ics23.IProofSpec): void { const { proof, - data: { root, key, value } + data: { root, key, value }, } = loadFile(filepath); if (value) { const valid = verifyMembership(proof, spec, root, key, value); @@ -132,13 +132,13 @@ describe("calculateExistenceRoot", () => { const commit: ics23.ICommitmentProof = { batch: { // tslint:disable-next-line:readonly-array - entries: entries as ics23.IBatchEntry[] - } + entries: entries as ics23.IBatchEntry[], + }, }; return { proof: commit, - data: refs + data: refs, }; } @@ -170,7 +170,7 @@ describe("calculateExistenceRoot", () => { "../testdata/iavl/exist_middle.json", "../testdata/iavl/nonexist_left.json", "../testdata/iavl/nonexist_right.json", - "../testdata/iavl/nonexist_middle.json" + "../testdata/iavl/nonexist_middle.json", ]); validateBatch(proof, iavlSpec, data[0]); }); @@ -182,7 +182,7 @@ describe("calculateExistenceRoot", () => { "../testdata/iavl/exist_middle.json", "../testdata/iavl/nonexist_left.json", "../testdata/iavl/nonexist_right.json", - "../testdata/iavl/nonexist_middle.json" + "../testdata/iavl/nonexist_middle.json", ]); validateBatch(proof, iavlSpec, data[5]); }); @@ -194,7 +194,7 @@ describe("calculateExistenceRoot", () => { "../testdata/iavl/exist_middle.json", "../testdata/iavl/nonexist_left.json", "../testdata/iavl/nonexist_right.json", - "../testdata/iavl/nonexist_middle.json" + "../testdata/iavl/nonexist_middle.json", ]); const small = compress(proof); @@ -215,7 +215,7 @@ describe("calculateExistenceRoot", () => { "../testdata/iavl/exist_middle.json", "../testdata/iavl/nonexist_left.json", "../testdata/iavl/nonexist_right.json", - "../testdata/iavl/nonexist_middle.json" + "../testdata/iavl/nonexist_middle.json", ]); const small = compress(proof); @@ -236,7 +236,7 @@ describe("calculateExistenceRoot", () => { "../testdata/tendermint/exist_middle.json", "../testdata/tendermint/nonexist_left.json", "../testdata/tendermint/nonexist_right.json", - "../testdata/tendermint/nonexist_middle.json" + "../testdata/tendermint/nonexist_middle.json", ]); validateBatch(proof, tendermintSpec, data[2]); }); @@ -248,7 +248,7 @@ describe("calculateExistenceRoot", () => { "../testdata/tendermint/exist_middle.json", "../testdata/tendermint/nonexist_left.json", "../testdata/tendermint/nonexist_right.json", - "../testdata/tendermint/nonexist_middle.json" + "../testdata/tendermint/nonexist_middle.json", ]); validateBatch(proof, tendermintSpec, data[3]); }); diff --git a/js/yarn.lock b/js/yarn.lock index f6e8bc684..c78e3b4f0 100644 --- a/js/yarn.lock +++ b/js/yarn.lock @@ -385,10 +385,10 @@ perfy@^1.1.5: resolved "https://registry.yarnpkg.com/perfy/-/perfy-1.1.5.tgz#0d629f870a34a3eb1866d3db485d2b3faef29e4b" integrity sha512-/ieVBpMaPTJf83YTUl2TImsSwMEJ23qGP2w27pE6aX+NrB/ZRGqOnQZpl7J719yFwd+ebDiHguPNFeMSamyK7w== -prettier@^1.17.0: - version "1.19.1" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb" - integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew== +prettier@^2.5.1: + version "2.5.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.5.1.tgz#fff75fa9d519c54cf0fce328c1017d94546bc56a" + integrity sha512-vBZcPRUR5MZJwoyi3ZoyQlc1rXeEck8KgeC9AwwOn+exuxLxq5toTRDTSaVrXHxelDMHy9zlicw8u66yxoSUFg== protobufjs@^6.8.8: version "6.8.9"