Skip to content

Commit

Permalink
Merge pull request cosmos#70 from confio/prettier2
Browse files Browse the repository at this point in the history
Update prettier to 2.5.1 and format code
  • Loading branch information
ethanfrey authored Jan 31, 2022
2 parents a48c323 + 1f2d37c commit 02465ea
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 76 deletions.
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 10 additions & 10 deletions js/src/compress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -45,7 +45,7 @@ function compress_batch(proof: ics23.IBatchProof): ics23.ICompressedBatchProof {

return {
entries: centries,
lookupInners: lookup
lookupInners: lookup,
};
}

Expand All @@ -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) {
Expand All @@ -73,15 +73,15 @@ function compress_exist(
key: exist.key,
value: exist.value,
leaf: exist.leaf,
path
path,
};
}

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) {
Expand All @@ -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,
};
}

Expand All @@ -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 };
}
4 changes: 2 additions & 2 deletions js/src/generated/codecimpl.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export namespace ics23 {
KECCAK = 3,
RIPEMD160 = 4,
BITCOIN = 5,
SHA512_256 = 6
SHA512_256 = 6,
}

/**
Expand All @@ -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. */
Expand Down
4 changes: 2 additions & 2 deletions js/src/ics23.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export {
iavlSpec,
tendermintSpec,
verifyExistence,
verifyNonExistence
verifyNonExistence,
} from "./proofs";
18 changes: 9 additions & 9 deletions js/src/ops.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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("");
Expand All @@ -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");
Expand All @@ -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
Expand All @@ -165,15 +165,15 @@ describe("applyInner", () => {
const op: ics23.IInnerOp = {
hash: ics23.HashOp.SHA256,
prefix: fromHex("0123456789"),
suffix: fromHex("deadbeef")
suffix: fromHex("deadbeef"),
};
expect(() => applyInner(op, fromHex(""))).toThrow();
});

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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions js/src/ops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function applyLeaf(
const data = new Uint8Array([
...ensureBytes(leaf.prefix),
...pkey,
...pvalue
...pvalue,
]);
return doHash(ensureHash(leaf.hash), data);
}
Expand All @@ -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);
}
Expand Down
Loading

0 comments on commit 02465ea

Please sign in to comment.