Skip to content

Commit f173e62

Browse files
authored
Merge pull request #34 from confio/export-specs-in-js
Export specs in js
2 parents 65ad804 + 3cb1bc2 commit f173e62

File tree

5 files changed

+35
-33
lines changed

5 files changed

+35
-33
lines changed

js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@confio/ics23",
3-
"version": "0.6.0",
3+
"version": "0.6.3",
44
"description": "Merkle proof verification library - implements Cosmos ICS23 Spec",
55
"main": "build/index.js",
66
"types": "build/index.d.ts",

js/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ export { verifyMembership, verifyNonMembership } from "./ics23";
33
export {
44
calculateExistenceRoot,
55
CommitmentRoot,
6+
iavlSpec,
7+
tendermintSpec,
68
verifyExistence,
79
verifyNonExistence
810
} from "./proofs";

js/src/proofs.spec.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ics23 } from "./generated/codecimpl";
22

33
import { fromHex, toAscii } from "./helpers";
4-
import { calculateExistenceRoot, ensureSpec, IavlSpec } from "./proofs";
4+
import { calculateExistenceRoot, ensureSpec, iavlSpec } from "./proofs";
55

66
describe("calculateExistenceRoot", () => {
77
it("must have at least one step", () => {
@@ -63,7 +63,7 @@ describe("calculateExistenceRoot", () => {
6363
});
6464

6565
describe("ensureSpec", () => {
66-
const validLeaf = IavlSpec.leafSpec;
66+
const validLeaf = iavlSpec.leafSpec;
6767
const invalidLeaf = {
6868
prefix: Uint8Array.from([0]),
6969
hash: ics23.HashOp.SHA512,
@@ -87,8 +87,8 @@ describe("ensureSpec", () => {
8787
};
8888

8989
const depthLimitedSpec = {
90-
leafSpec: IavlSpec.leafSpec,
91-
innerSpec: IavlSpec.innerSpec,
90+
leafSpec: iavlSpec.leafSpec,
91+
innerSpec: iavlSpec.innerSpec,
9292
minDepth: 2,
9393
maxDepth: 4
9494
};
@@ -98,7 +98,7 @@ describe("ensureSpec", () => {
9898
key: toAscii("foo"),
9999
value: toAscii("bar")
100100
};
101-
expect(() => ensureSpec(proof, IavlSpec)).toThrow();
101+
expect(() => ensureSpec(proof, iavlSpec)).toThrow();
102102
});
103103

104104
it("accepts one valid leaf", () => {
@@ -108,7 +108,7 @@ describe("ensureSpec", () => {
108108
leaf: validLeaf
109109
};
110110
// fail if this throws (invalid spec)
111-
ensureSpec(proof, IavlSpec);
111+
ensureSpec(proof, iavlSpec);
112112
});
113113

114114
it("rejects invalid leaf", () => {
@@ -117,7 +117,7 @@ describe("ensureSpec", () => {
117117
value: toAscii("bar"),
118118
leaf: invalidLeaf
119119
};
120-
expect(() => ensureSpec(proof, IavlSpec)).toThrow();
120+
expect(() => ensureSpec(proof, iavlSpec)).toThrow();
121121
});
122122

123123
it("rejects inner without leaf", () => {
@@ -126,7 +126,7 @@ describe("ensureSpec", () => {
126126
value: toAscii("bar"),
127127
path: [validInner]
128128
};
129-
expect(() => ensureSpec(proof, IavlSpec)).toThrow();
129+
expect(() => ensureSpec(proof, iavlSpec)).toThrow();
130130
});
131131

132132
it("accepts leaf with one inner", () => {
@@ -137,7 +137,7 @@ describe("ensureSpec", () => {
137137
path: [validInner]
138138
};
139139
// fail if this throws (invalid spec)
140-
ensureSpec(proof, IavlSpec);
140+
ensureSpec(proof, iavlSpec);
141141
});
142142

143143
it("rejects with invalid inner (prefix)", () => {
@@ -147,7 +147,7 @@ describe("ensureSpec", () => {
147147
leaf: validLeaf,
148148
path: [invalidInner, validInner]
149149
};
150-
expect(() => ensureSpec(proof, IavlSpec)).toThrow();
150+
expect(() => ensureSpec(proof, iavlSpec)).toThrow();
151151
});
152152

153153
it("rejects with invalid inner (hash)", () => {
@@ -157,7 +157,7 @@ describe("ensureSpec", () => {
157157
leaf: validLeaf,
158158
path: [validInner, invalidInnerHash]
159159
};
160-
expect(() => ensureSpec(proof, IavlSpec)).toThrow();
160+
expect(() => ensureSpec(proof, iavlSpec)).toThrow();
161161
});
162162

163163
it("accepts depth limited with proper number of nodes", () => {

js/src/proofs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
ensureLeaf
99
} from "./specs";
1010

11-
export const IavlSpec: ics23.IProofSpec = {
11+
export const iavlSpec: ics23.IProofSpec = {
1212
leafSpec: {
1313
prefix: Uint8Array.from([0]),
1414
hash: ics23.HashOp.SHA256,
@@ -25,7 +25,7 @@ export const IavlSpec: ics23.IProofSpec = {
2525
}
2626
};
2727

28-
export const TendermintSpec: ics23.IProofSpec = {
28+
export const tendermintSpec: ics23.IProofSpec = {
2929
leafSpec: {
3030
prefix: Uint8Array.from([0]),
3131
hash: ics23.HashOp.SHA256,

js/src/testvectors.spec.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
verifyMembership,
1010
verifyNonMembership
1111
} from "./ics23";
12-
import { IavlSpec, TendermintSpec } from "./proofs";
12+
import { iavlSpec, tendermintSpec } from "./proofs";
1313

1414
describe("calculateExistenceRoot", () => {
1515
interface RefData {
@@ -61,58 +61,58 @@ describe("calculateExistenceRoot", () => {
6161
}
6262

6363
it("should parse iavl left", () => {
64-
validateTestVector("../testdata/iavl/exist_left.json", IavlSpec);
64+
validateTestVector("../testdata/iavl/exist_left.json", iavlSpec);
6565
});
6666
it("should parse iavl right", () => {
67-
validateTestVector("../testdata/iavl/exist_right.json", IavlSpec);
67+
validateTestVector("../testdata/iavl/exist_right.json", iavlSpec);
6868
});
6969
it("should parse iavl middle", () => {
70-
validateTestVector("../testdata/iavl/exist_middle.json", IavlSpec);
70+
validateTestVector("../testdata/iavl/exist_middle.json", iavlSpec);
7171
});
7272
it("should parse iavl left - nonexist", () => {
73-
validateTestVector("../testdata/iavl/nonexist_left.json", IavlSpec);
73+
validateTestVector("../testdata/iavl/nonexist_left.json", iavlSpec);
7474
});
7575
it("should parse iavl right - nonexist", () => {
76-
validateTestVector("../testdata/iavl/nonexist_right.json", IavlSpec);
76+
validateTestVector("../testdata/iavl/nonexist_right.json", iavlSpec);
7777
});
7878
it("should parse iavl middle - nonexist", () => {
79-
validateTestVector("../testdata/iavl/nonexist_middle.json", IavlSpec);
79+
validateTestVector("../testdata/iavl/nonexist_middle.json", iavlSpec);
8080
});
8181

8282
it("should parse tendermint left", () => {
8383
validateTestVector(
8484
"../testdata/tendermint/exist_left.json",
85-
TendermintSpec
85+
tendermintSpec
8686
);
8787
});
8888
it("should parse tendermint right", () => {
8989
validateTestVector(
9090
"../testdata/tendermint/exist_right.json",
91-
TendermintSpec
91+
tendermintSpec
9292
);
9393
});
9494
it("should parse tendermint middle", () => {
9595
validateTestVector(
9696
"../testdata/tendermint/exist_middle.json",
97-
TendermintSpec
97+
tendermintSpec
9898
);
9999
});
100100
it("should parse tendermint left - nonexist", () => {
101101
validateTestVector(
102102
"../testdata/tendermint/nonexist_left.json",
103-
TendermintSpec
103+
tendermintSpec
104104
);
105105
});
106106
it("should parse tendermint right - nonexist", () => {
107107
validateTestVector(
108108
"../testdata/tendermint/nonexist_right.json",
109-
TendermintSpec
109+
tendermintSpec
110110
);
111111
});
112112
it("should parse tendermint middle - nonexist", () => {
113113
validateTestVector(
114114
"../testdata/tendermint/nonexist_middle.json",
115-
TendermintSpec
115+
tendermintSpec
116116
);
117117
});
118118

@@ -172,7 +172,7 @@ describe("calculateExistenceRoot", () => {
172172
"../testdata/iavl/nonexist_right.json",
173173
"../testdata/iavl/nonexist_middle.json"
174174
]);
175-
validateBatch(proof, IavlSpec, data[0]);
175+
validateBatch(proof, iavlSpec, data[0]);
176176
});
177177

178178
it("should validate iavl batch nonexist", () => {
@@ -184,7 +184,7 @@ describe("calculateExistenceRoot", () => {
184184
"../testdata/iavl/nonexist_right.json",
185185
"../testdata/iavl/nonexist_middle.json"
186186
]);
187-
validateBatch(proof, IavlSpec, data[5]);
187+
validateBatch(proof, iavlSpec, data[5]);
188188
});
189189

190190
it("should validate compressed iavl batch exist", () => {
@@ -205,7 +205,7 @@ describe("calculateExistenceRoot", () => {
205205
expect(origBin).toEqual(origBin2);
206206
expect(origBin).not.toEqual(smallBin);
207207

208-
validateBatch(small, IavlSpec, data[0]);
208+
validateBatch(small, iavlSpec, data[0]);
209209
});
210210

211211
it("should validate compressed iavl batch nonexist", () => {
@@ -226,7 +226,7 @@ describe("calculateExistenceRoot", () => {
226226
expect(origBin).toEqual(origBin2);
227227
expect(origBin).not.toEqual(smallBin);
228228

229-
validateBatch(small, IavlSpec, data[5]);
229+
validateBatch(small, iavlSpec, data[5]);
230230
});
231231

232232
it("should validate tendermint batch exist", () => {
@@ -238,7 +238,7 @@ describe("calculateExistenceRoot", () => {
238238
"../testdata/tendermint/nonexist_right.json",
239239
"../testdata/tendermint/nonexist_middle.json"
240240
]);
241-
validateBatch(proof, TendermintSpec, data[2]);
241+
validateBatch(proof, tendermintSpec, data[2]);
242242
});
243243

244244
it("should validate tendermint batch nonexist", () => {
@@ -250,6 +250,6 @@ describe("calculateExistenceRoot", () => {
250250
"../testdata/tendermint/nonexist_right.json",
251251
"../testdata/tendermint/nonexist_middle.json"
252252
]);
253-
validateBatch(proof, TendermintSpec, data[3]);
253+
validateBatch(proof, tendermintSpec, data[3]);
254254
});
255255
});

0 commit comments

Comments
 (0)