@freedomofpress/cometbft 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/commit.d.ts +7 -0
  2. package/dist/commit.js +175 -0
  3. package/dist/commit.js.map +1 -0
  4. package/dist/encoding.d.ts +4 -0
  5. package/dist/encoding.js +31 -0
  6. package/dist/encoding.js.map +1 -0
  7. package/dist/lightclient.d.ts +17 -0
  8. package/dist/lightclient.js +275 -0
  9. package/dist/lightclient.js.map +1 -0
  10. package/dist/proto/cometbft/crypto/v1/keys.d.ts +28 -0
  11. package/dist/proto/cometbft/crypto/v1/keys.js +110 -0
  12. package/dist/proto/cometbft/crypto/v1/keys.js.map +1 -0
  13. package/dist/proto/cometbft/crypto/v1/proof.d.ts +60 -0
  14. package/dist/proto/cometbft/crypto/v1/proof.js +416 -0
  15. package/dist/proto/cometbft/crypto/v1/proof.js.map +1 -0
  16. package/dist/proto/cometbft/types/v1/canonical.d.ts +85 -0
  17. package/dist/proto/cometbft/types/v1/canonical.js +586 -0
  18. package/dist/proto/cometbft/types/v1/canonical.js.map +1 -0
  19. package/dist/proto/cometbft/types/v1/types.d.ts +206 -0
  20. package/dist/proto/cometbft/types/v1/types.js +1794 -0
  21. package/dist/proto/cometbft/types/v1/types.js.map +1 -0
  22. package/dist/proto/cometbft/types/v1/validator.d.ts +64 -0
  23. package/dist/proto/cometbft/types/v1/validator.js +382 -0
  24. package/dist/proto/cometbft/types/v1/validator.js.map +1 -0
  25. package/dist/proto/cometbft/version/v1/types.d.ts +41 -0
  26. package/dist/proto/cometbft/version/v1/types.js +154 -0
  27. package/dist/proto/cometbft/version/v1/types.js.map +1 -0
  28. package/dist/proto/gogoproto/gogo.d.ts +1 -0
  29. package/dist/proto/gogoproto/gogo.js +8 -0
  30. package/dist/proto/gogoproto/gogo.js.map +1 -0
  31. package/dist/proto/google/protobuf/descriptor.d.ts +1228 -0
  32. package/dist/proto/google/protobuf/descriptor.js +5056 -0
  33. package/dist/proto/google/protobuf/descriptor.js.map +1 -0
  34. package/dist/proto/google/protobuf/timestamp.d.ts +128 -0
  35. package/dist/proto/google/protobuf/timestamp.js +83 -0
  36. package/dist/proto/google/protobuf/timestamp.js.map +1 -0
  37. package/dist/tests/commit.test.d.ts +1 -0
  38. package/dist/tests/commit.test.js +219 -0
  39. package/dist/tests/commit.test.js.map +1 -0
  40. package/dist/tests/encoding.test.d.ts +1 -0
  41. package/dist/tests/encoding.test.js +31 -0
  42. package/dist/tests/encoding.test.js.map +1 -0
  43. package/dist/tests/fixtures/commit-12.json +64 -0
  44. package/dist/tests/fixtures/validators-12.json +41 -0
  45. package/dist/tests/fixtures/webcat.json +71 -0
  46. package/dist/tests/lightclient.test.d.ts +1 -0
  47. package/dist/tests/lightclient.test.js +234 -0
  48. package/dist/tests/lightclient.test.js.map +1 -0
  49. package/dist/tests/validators.test.d.ts +1 -0
  50. package/dist/tests/validators.test.js +184 -0
  51. package/dist/tests/validators.test.js.map +1 -0
  52. package/dist/tests/webcat.test.d.ts +1 -0
  53. package/dist/tests/webcat.test.js +52 -0
  54. package/dist/tests/webcat.test.js.map +1 -0
  55. package/dist/types.d.ts +62 -0
  56. package/dist/types.js +2 -0
  57. package/dist/types.js.map +1 -0
  58. package/dist/validators.d.ts +6 -0
  59. package/dist/validators.js +55 -0
  60. package/dist/validators.js.map +1 -0
  61. package/package.json +5 -5
  62. package/src/lightclient.ts +176 -0
  63. package/src/tests/lightclient.test.ts +20 -5
  64. package/src/tests/webcat.test.ts +17 -47
@@ -0,0 +1,85 @@
1
+ import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
2
+ import { Timestamp } from "../../../google/protobuf/timestamp";
3
+ import { SignedMsgType } from "./types";
4
+ export declare const protobufPackage = "cometbft.types.v1";
5
+ /**
6
+ * CanonicalBlockID is a canonical representation of a BlockID, which gets
7
+ * serialized and signed.
8
+ */
9
+ export interface CanonicalBlockID {
10
+ hash: Uint8Array;
11
+ partSetHeader?: CanonicalPartSetHeader | undefined;
12
+ }
13
+ /**
14
+ * CanonicalPartSetHeader is a canonical representation of a PartSetHeader,
15
+ * which gets serialized and signed.
16
+ */
17
+ export interface CanonicalPartSetHeader {
18
+ total: number;
19
+ hash: Uint8Array;
20
+ }
21
+ /**
22
+ * CanonicalProposal is a canonical representation of a Proposal, which gets
23
+ * serialized and signed.
24
+ */
25
+ export interface CanonicalProposal {
26
+ /** type alias for byte */
27
+ type: SignedMsgType;
28
+ /** canonicalization requires fixed size encoding here */
29
+ height: bigint;
30
+ /** canonicalization requires fixed size encoding here */
31
+ round: bigint;
32
+ polRound: bigint;
33
+ blockId?: CanonicalBlockID | undefined;
34
+ timestamp?: Timestamp | undefined;
35
+ chainId: string;
36
+ }
37
+ /**
38
+ * CanonicalVote is a canonical representation of a Vote, which gets
39
+ * serialized and signed.
40
+ */
41
+ export interface CanonicalVote {
42
+ /** type alias for byte */
43
+ type: SignedMsgType;
44
+ /** canonicalization requires fixed size encoding here */
45
+ height: bigint;
46
+ /** canonicalization requires fixed size encoding here */
47
+ round: bigint;
48
+ blockId?: CanonicalBlockID | undefined;
49
+ timestamp?: Timestamp | undefined;
50
+ chainId: string;
51
+ }
52
+ /**
53
+ * CanonicalVoteExtension provides us a way to serialize a vote extension from
54
+ * a particular validator such that we can sign over those serialized bytes.
55
+ */
56
+ export interface CanonicalVoteExtension {
57
+ extension: Uint8Array;
58
+ height: bigint;
59
+ round: bigint;
60
+ chainId: string;
61
+ }
62
+ export declare const CanonicalBlockID: MessageFns<CanonicalBlockID>;
63
+ export declare const CanonicalPartSetHeader: MessageFns<CanonicalPartSetHeader>;
64
+ export declare const CanonicalProposal: MessageFns<CanonicalProposal>;
65
+ export declare const CanonicalVote: MessageFns<CanonicalVote>;
66
+ export declare const CanonicalVoteExtension: MessageFns<CanonicalVoteExtension>;
67
+ type Builtin = Date | Function | Uint8Array | string | number | boolean | bigint | undefined;
68
+ export type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
69
+ [K in keyof T]?: DeepPartial<T[K]>;
70
+ } : Partial<T>;
71
+ type KeysOfUnion<T> = T extends T ? keyof T : never;
72
+ export type Exact<P, I extends P> = P extends Builtin ? P : P & {
73
+ [K in keyof P]: Exact<P[K], I[K]>;
74
+ } & {
75
+ [K in Exclude<keyof I, KeysOfUnion<P>>]: never;
76
+ };
77
+ export interface MessageFns<T> {
78
+ encode(message: T, writer?: BinaryWriter): BinaryWriter;
79
+ decode(input: BinaryReader | Uint8Array, length?: number): T;
80
+ fromJSON(object: any): T;
81
+ toJSON(message: T): unknown;
82
+ create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
83
+ fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
84
+ }
85
+ export {};
@@ -0,0 +1,586 @@
1
+ // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
2
+ // versions:
3
+ // protoc-gen-ts_proto v2.6.1
4
+ // protoc unknown
5
+ // source: cometbft/types/v1/canonical.proto
6
+ /* eslint-disable */
7
+ import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
8
+ import { Timestamp } from "../../../google/protobuf/timestamp";
9
+ import { signedMsgTypeFromJSON, signedMsgTypeToJSON } from "./types";
10
+ export const protobufPackage = "cometbft.types.v1";
11
+ function createBaseCanonicalBlockID() {
12
+ return { hash: new Uint8Array(0), partSetHeader: undefined };
13
+ }
14
+ export const CanonicalBlockID = {
15
+ encode(message, writer = new BinaryWriter()) {
16
+ if (message.hash.length !== 0) {
17
+ writer.uint32(10).bytes(message.hash);
18
+ }
19
+ if (message.partSetHeader !== undefined) {
20
+ CanonicalPartSetHeader.encode(message.partSetHeader, writer.uint32(18).fork()).join();
21
+ }
22
+ return writer;
23
+ },
24
+ decode(input, length) {
25
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
26
+ let end = length === undefined ? reader.len : reader.pos + length;
27
+ const message = createBaseCanonicalBlockID();
28
+ while (reader.pos < end) {
29
+ const tag = reader.uint32();
30
+ switch (tag >>> 3) {
31
+ case 1: {
32
+ if (tag !== 10) {
33
+ break;
34
+ }
35
+ message.hash = reader.bytes();
36
+ continue;
37
+ }
38
+ case 2: {
39
+ if (tag !== 18) {
40
+ break;
41
+ }
42
+ message.partSetHeader = CanonicalPartSetHeader.decode(reader, reader.uint32());
43
+ continue;
44
+ }
45
+ }
46
+ if ((tag & 7) === 4 || tag === 0) {
47
+ break;
48
+ }
49
+ reader.skip(tag & 7);
50
+ }
51
+ return message;
52
+ },
53
+ fromJSON(object) {
54
+ return {
55
+ hash: isSet(object.hash) ? bytesFromBase64(object.hash) : new Uint8Array(0),
56
+ partSetHeader: isSet(object.partSetHeader) ? CanonicalPartSetHeader.fromJSON(object.partSetHeader) : undefined,
57
+ };
58
+ },
59
+ toJSON(message) {
60
+ const obj = {};
61
+ if (message.hash.length !== 0) {
62
+ obj.hash = base64FromBytes(message.hash);
63
+ }
64
+ if (message.partSetHeader !== undefined) {
65
+ obj.partSetHeader = CanonicalPartSetHeader.toJSON(message.partSetHeader);
66
+ }
67
+ return obj;
68
+ },
69
+ create(base) {
70
+ return CanonicalBlockID.fromPartial(base ?? {});
71
+ },
72
+ fromPartial(object) {
73
+ const message = createBaseCanonicalBlockID();
74
+ message.hash = object.hash ?? new Uint8Array(0);
75
+ message.partSetHeader = (object.partSetHeader !== undefined && object.partSetHeader !== null)
76
+ ? CanonicalPartSetHeader.fromPartial(object.partSetHeader)
77
+ : undefined;
78
+ return message;
79
+ },
80
+ };
81
+ function createBaseCanonicalPartSetHeader() {
82
+ return { total: 0, hash: new Uint8Array(0) };
83
+ }
84
+ export const CanonicalPartSetHeader = {
85
+ encode(message, writer = new BinaryWriter()) {
86
+ if (message.total !== 0) {
87
+ writer.uint32(8).uint32(message.total);
88
+ }
89
+ if (message.hash.length !== 0) {
90
+ writer.uint32(18).bytes(message.hash);
91
+ }
92
+ return writer;
93
+ },
94
+ decode(input, length) {
95
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
96
+ let end = length === undefined ? reader.len : reader.pos + length;
97
+ const message = createBaseCanonicalPartSetHeader();
98
+ while (reader.pos < end) {
99
+ const tag = reader.uint32();
100
+ switch (tag >>> 3) {
101
+ case 1: {
102
+ if (tag !== 8) {
103
+ break;
104
+ }
105
+ message.total = reader.uint32();
106
+ continue;
107
+ }
108
+ case 2: {
109
+ if (tag !== 18) {
110
+ break;
111
+ }
112
+ message.hash = reader.bytes();
113
+ continue;
114
+ }
115
+ }
116
+ if ((tag & 7) === 4 || tag === 0) {
117
+ break;
118
+ }
119
+ reader.skip(tag & 7);
120
+ }
121
+ return message;
122
+ },
123
+ fromJSON(object) {
124
+ return {
125
+ total: isSet(object.total) ? globalThis.Number(object.total) : 0,
126
+ hash: isSet(object.hash) ? bytesFromBase64(object.hash) : new Uint8Array(0),
127
+ };
128
+ },
129
+ toJSON(message) {
130
+ const obj = {};
131
+ if (message.total !== 0) {
132
+ obj.total = Math.round(message.total);
133
+ }
134
+ if (message.hash.length !== 0) {
135
+ obj.hash = base64FromBytes(message.hash);
136
+ }
137
+ return obj;
138
+ },
139
+ create(base) {
140
+ return CanonicalPartSetHeader.fromPartial(base ?? {});
141
+ },
142
+ fromPartial(object) {
143
+ const message = createBaseCanonicalPartSetHeader();
144
+ message.total = object.total ?? 0;
145
+ message.hash = object.hash ?? new Uint8Array(0);
146
+ return message;
147
+ },
148
+ };
149
+ function createBaseCanonicalProposal() {
150
+ return { type: 0, height: 0n, round: 0n, polRound: 0n, blockId: undefined, timestamp: undefined, chainId: "" };
151
+ }
152
+ export const CanonicalProposal = {
153
+ encode(message, writer = new BinaryWriter()) {
154
+ if (message.type !== 0) {
155
+ writer.uint32(8).int32(message.type);
156
+ }
157
+ if (message.height !== 0n) {
158
+ if (BigInt.asIntN(64, message.height) !== message.height) {
159
+ throw new globalThis.Error("value provided for field message.height of type sfixed64 too large");
160
+ }
161
+ writer.uint32(17).sfixed64(message.height);
162
+ }
163
+ if (message.round !== 0n) {
164
+ if (BigInt.asIntN(64, message.round) !== message.round) {
165
+ throw new globalThis.Error("value provided for field message.round of type sfixed64 too large");
166
+ }
167
+ writer.uint32(25).sfixed64(message.round);
168
+ }
169
+ if (message.polRound !== 0n) {
170
+ if (BigInt.asIntN(64, message.polRound) !== message.polRound) {
171
+ throw new globalThis.Error("value provided for field message.polRound of type int64 too large");
172
+ }
173
+ writer.uint32(32).int64(message.polRound);
174
+ }
175
+ if (message.blockId !== undefined) {
176
+ CanonicalBlockID.encode(message.blockId, writer.uint32(42).fork()).join();
177
+ }
178
+ if (message.timestamp !== undefined) {
179
+ Timestamp.encode(message.timestamp, writer.uint32(50).fork()).join();
180
+ }
181
+ if (message.chainId !== "") {
182
+ writer.uint32(58).string(message.chainId);
183
+ }
184
+ return writer;
185
+ },
186
+ decode(input, length) {
187
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
188
+ let end = length === undefined ? reader.len : reader.pos + length;
189
+ const message = createBaseCanonicalProposal();
190
+ while (reader.pos < end) {
191
+ const tag = reader.uint32();
192
+ switch (tag >>> 3) {
193
+ case 1: {
194
+ if (tag !== 8) {
195
+ break;
196
+ }
197
+ message.type = reader.int32();
198
+ continue;
199
+ }
200
+ case 2: {
201
+ if (tag !== 17) {
202
+ break;
203
+ }
204
+ message.height = reader.sfixed64();
205
+ continue;
206
+ }
207
+ case 3: {
208
+ if (tag !== 25) {
209
+ break;
210
+ }
211
+ message.round = reader.sfixed64();
212
+ continue;
213
+ }
214
+ case 4: {
215
+ if (tag !== 32) {
216
+ break;
217
+ }
218
+ message.polRound = reader.int64();
219
+ continue;
220
+ }
221
+ case 5: {
222
+ if (tag !== 42) {
223
+ break;
224
+ }
225
+ message.blockId = CanonicalBlockID.decode(reader, reader.uint32());
226
+ continue;
227
+ }
228
+ case 6: {
229
+ if (tag !== 50) {
230
+ break;
231
+ }
232
+ message.timestamp = Timestamp.decode(reader, reader.uint32());
233
+ continue;
234
+ }
235
+ case 7: {
236
+ if (tag !== 58) {
237
+ break;
238
+ }
239
+ message.chainId = reader.string();
240
+ continue;
241
+ }
242
+ }
243
+ if ((tag & 7) === 4 || tag === 0) {
244
+ break;
245
+ }
246
+ reader.skip(tag & 7);
247
+ }
248
+ return message;
249
+ },
250
+ fromJSON(object) {
251
+ return {
252
+ type: isSet(object.type) ? signedMsgTypeFromJSON(object.type) : 0,
253
+ height: isSet(object.height) ? BigInt(object.height) : 0n,
254
+ round: isSet(object.round) ? BigInt(object.round) : 0n,
255
+ polRound: isSet(object.polRound) ? BigInt(object.polRound) : 0n,
256
+ blockId: isSet(object.blockId) ? CanonicalBlockID.fromJSON(object.blockId) : undefined,
257
+ timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined,
258
+ chainId: isSet(object.chainId) ? globalThis.String(object.chainId) : "",
259
+ };
260
+ },
261
+ toJSON(message) {
262
+ const obj = {};
263
+ if (message.type !== 0) {
264
+ obj.type = signedMsgTypeToJSON(message.type);
265
+ }
266
+ if (message.height !== 0n) {
267
+ obj.height = message.height.toString();
268
+ }
269
+ if (message.round !== 0n) {
270
+ obj.round = message.round.toString();
271
+ }
272
+ if (message.polRound !== 0n) {
273
+ obj.polRound = message.polRound.toString();
274
+ }
275
+ if (message.blockId !== undefined) {
276
+ obj.blockId = CanonicalBlockID.toJSON(message.blockId);
277
+ }
278
+ if (message.timestamp !== undefined) {
279
+ obj.timestamp = fromTimestamp(message.timestamp).toISOString();
280
+ }
281
+ if (message.chainId !== "") {
282
+ obj.chainId = message.chainId;
283
+ }
284
+ return obj;
285
+ },
286
+ create(base) {
287
+ return CanonicalProposal.fromPartial(base ?? {});
288
+ },
289
+ fromPartial(object) {
290
+ const message = createBaseCanonicalProposal();
291
+ message.type = object.type ?? 0;
292
+ message.height = object.height ?? 0n;
293
+ message.round = object.round ?? 0n;
294
+ message.polRound = object.polRound ?? 0n;
295
+ message.blockId = (object.blockId !== undefined && object.blockId !== null)
296
+ ? CanonicalBlockID.fromPartial(object.blockId)
297
+ : undefined;
298
+ message.timestamp = (object.timestamp !== undefined && object.timestamp !== null)
299
+ ? Timestamp.fromPartial(object.timestamp)
300
+ : undefined;
301
+ message.chainId = object.chainId ?? "";
302
+ return message;
303
+ },
304
+ };
305
+ function createBaseCanonicalVote() {
306
+ return { type: 0, height: 0n, round: 0n, blockId: undefined, timestamp: undefined, chainId: "" };
307
+ }
308
+ export const CanonicalVote = {
309
+ encode(message, writer = new BinaryWriter()) {
310
+ if (message.type !== 0) {
311
+ writer.uint32(8).int32(message.type);
312
+ }
313
+ if (message.height !== 0n) {
314
+ if (BigInt.asIntN(64, message.height) !== message.height) {
315
+ throw new globalThis.Error("value provided for field message.height of type sfixed64 too large");
316
+ }
317
+ writer.uint32(17).sfixed64(message.height);
318
+ }
319
+ if (message.round !== 0n) {
320
+ if (BigInt.asIntN(64, message.round) !== message.round) {
321
+ throw new globalThis.Error("value provided for field message.round of type sfixed64 too large");
322
+ }
323
+ writer.uint32(25).sfixed64(message.round);
324
+ }
325
+ if (message.blockId !== undefined) {
326
+ CanonicalBlockID.encode(message.blockId, writer.uint32(34).fork()).join();
327
+ }
328
+ if (message.timestamp !== undefined) {
329
+ Timestamp.encode(message.timestamp, writer.uint32(42).fork()).join();
330
+ }
331
+ if (message.chainId !== "") {
332
+ writer.uint32(50).string(message.chainId);
333
+ }
334
+ return writer;
335
+ },
336
+ decode(input, length) {
337
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
338
+ let end = length === undefined ? reader.len : reader.pos + length;
339
+ const message = createBaseCanonicalVote();
340
+ while (reader.pos < end) {
341
+ const tag = reader.uint32();
342
+ switch (tag >>> 3) {
343
+ case 1: {
344
+ if (tag !== 8) {
345
+ break;
346
+ }
347
+ message.type = reader.int32();
348
+ continue;
349
+ }
350
+ case 2: {
351
+ if (tag !== 17) {
352
+ break;
353
+ }
354
+ message.height = reader.sfixed64();
355
+ continue;
356
+ }
357
+ case 3: {
358
+ if (tag !== 25) {
359
+ break;
360
+ }
361
+ message.round = reader.sfixed64();
362
+ continue;
363
+ }
364
+ case 4: {
365
+ if (tag !== 34) {
366
+ break;
367
+ }
368
+ message.blockId = CanonicalBlockID.decode(reader, reader.uint32());
369
+ continue;
370
+ }
371
+ case 5: {
372
+ if (tag !== 42) {
373
+ break;
374
+ }
375
+ message.timestamp = Timestamp.decode(reader, reader.uint32());
376
+ continue;
377
+ }
378
+ case 6: {
379
+ if (tag !== 50) {
380
+ break;
381
+ }
382
+ message.chainId = reader.string();
383
+ continue;
384
+ }
385
+ }
386
+ if ((tag & 7) === 4 || tag === 0) {
387
+ break;
388
+ }
389
+ reader.skip(tag & 7);
390
+ }
391
+ return message;
392
+ },
393
+ fromJSON(object) {
394
+ return {
395
+ type: isSet(object.type) ? signedMsgTypeFromJSON(object.type) : 0,
396
+ height: isSet(object.height) ? BigInt(object.height) : 0n,
397
+ round: isSet(object.round) ? BigInt(object.round) : 0n,
398
+ blockId: isSet(object.blockId) ? CanonicalBlockID.fromJSON(object.blockId) : undefined,
399
+ timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined,
400
+ chainId: isSet(object.chainId) ? globalThis.String(object.chainId) : "",
401
+ };
402
+ },
403
+ toJSON(message) {
404
+ const obj = {};
405
+ if (message.type !== 0) {
406
+ obj.type = signedMsgTypeToJSON(message.type);
407
+ }
408
+ if (message.height !== 0n) {
409
+ obj.height = message.height.toString();
410
+ }
411
+ if (message.round !== 0n) {
412
+ obj.round = message.round.toString();
413
+ }
414
+ if (message.blockId !== undefined) {
415
+ obj.blockId = CanonicalBlockID.toJSON(message.blockId);
416
+ }
417
+ if (message.timestamp !== undefined) {
418
+ obj.timestamp = fromTimestamp(message.timestamp).toISOString();
419
+ }
420
+ if (message.chainId !== "") {
421
+ obj.chainId = message.chainId;
422
+ }
423
+ return obj;
424
+ },
425
+ create(base) {
426
+ return CanonicalVote.fromPartial(base ?? {});
427
+ },
428
+ fromPartial(object) {
429
+ const message = createBaseCanonicalVote();
430
+ message.type = object.type ?? 0;
431
+ message.height = object.height ?? 0n;
432
+ message.round = object.round ?? 0n;
433
+ message.blockId = (object.blockId !== undefined && object.blockId !== null)
434
+ ? CanonicalBlockID.fromPartial(object.blockId)
435
+ : undefined;
436
+ message.timestamp = (object.timestamp !== undefined && object.timestamp !== null)
437
+ ? Timestamp.fromPartial(object.timestamp)
438
+ : undefined;
439
+ message.chainId = object.chainId ?? "";
440
+ return message;
441
+ },
442
+ };
443
+ function createBaseCanonicalVoteExtension() {
444
+ return { extension: new Uint8Array(0), height: 0n, round: 0n, chainId: "" };
445
+ }
446
+ export const CanonicalVoteExtension = {
447
+ encode(message, writer = new BinaryWriter()) {
448
+ if (message.extension.length !== 0) {
449
+ writer.uint32(10).bytes(message.extension);
450
+ }
451
+ if (message.height !== 0n) {
452
+ if (BigInt.asIntN(64, message.height) !== message.height) {
453
+ throw new globalThis.Error("value provided for field message.height of type sfixed64 too large");
454
+ }
455
+ writer.uint32(17).sfixed64(message.height);
456
+ }
457
+ if (message.round !== 0n) {
458
+ if (BigInt.asIntN(64, message.round) !== message.round) {
459
+ throw new globalThis.Error("value provided for field message.round of type sfixed64 too large");
460
+ }
461
+ writer.uint32(25).sfixed64(message.round);
462
+ }
463
+ if (message.chainId !== "") {
464
+ writer.uint32(34).string(message.chainId);
465
+ }
466
+ return writer;
467
+ },
468
+ decode(input, length) {
469
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
470
+ let end = length === undefined ? reader.len : reader.pos + length;
471
+ const message = createBaseCanonicalVoteExtension();
472
+ while (reader.pos < end) {
473
+ const tag = reader.uint32();
474
+ switch (tag >>> 3) {
475
+ case 1: {
476
+ if (tag !== 10) {
477
+ break;
478
+ }
479
+ message.extension = reader.bytes();
480
+ continue;
481
+ }
482
+ case 2: {
483
+ if (tag !== 17) {
484
+ break;
485
+ }
486
+ message.height = reader.sfixed64();
487
+ continue;
488
+ }
489
+ case 3: {
490
+ if (tag !== 25) {
491
+ break;
492
+ }
493
+ message.round = reader.sfixed64();
494
+ continue;
495
+ }
496
+ case 4: {
497
+ if (tag !== 34) {
498
+ break;
499
+ }
500
+ message.chainId = reader.string();
501
+ continue;
502
+ }
503
+ }
504
+ if ((tag & 7) === 4 || tag === 0) {
505
+ break;
506
+ }
507
+ reader.skip(tag & 7);
508
+ }
509
+ return message;
510
+ },
511
+ fromJSON(object) {
512
+ return {
513
+ extension: isSet(object.extension) ? bytesFromBase64(object.extension) : new Uint8Array(0),
514
+ height: isSet(object.height) ? BigInt(object.height) : 0n,
515
+ round: isSet(object.round) ? BigInt(object.round) : 0n,
516
+ chainId: isSet(object.chainId) ? globalThis.String(object.chainId) : "",
517
+ };
518
+ },
519
+ toJSON(message) {
520
+ const obj = {};
521
+ if (message.extension.length !== 0) {
522
+ obj.extension = base64FromBytes(message.extension);
523
+ }
524
+ if (message.height !== 0n) {
525
+ obj.height = message.height.toString();
526
+ }
527
+ if (message.round !== 0n) {
528
+ obj.round = message.round.toString();
529
+ }
530
+ if (message.chainId !== "") {
531
+ obj.chainId = message.chainId;
532
+ }
533
+ return obj;
534
+ },
535
+ create(base) {
536
+ return CanonicalVoteExtension.fromPartial(base ?? {});
537
+ },
538
+ fromPartial(object) {
539
+ const message = createBaseCanonicalVoteExtension();
540
+ message.extension = object.extension ?? new Uint8Array(0);
541
+ message.height = object.height ?? 0n;
542
+ message.round = object.round ?? 0n;
543
+ message.chainId = object.chainId ?? "";
544
+ return message;
545
+ },
546
+ };
547
+ function bytesFromBase64(b64) {
548
+ const bin = globalThis.atob(b64);
549
+ const arr = new Uint8Array(bin.length);
550
+ for (let i = 0; i < bin.length; ++i) {
551
+ arr[i] = bin.charCodeAt(i);
552
+ }
553
+ return arr;
554
+ }
555
+ function base64FromBytes(arr) {
556
+ const bin = [];
557
+ arr.forEach((byte) => {
558
+ bin.push(globalThis.String.fromCharCode(byte));
559
+ });
560
+ return globalThis.btoa(bin.join(""));
561
+ }
562
+ function toTimestamp(date) {
563
+ const seconds = BigInt(Math.trunc(date.getTime() / 1_000));
564
+ const nanos = (date.getTime() % 1_000) * 1_000_000;
565
+ return { seconds, nanos };
566
+ }
567
+ function fromTimestamp(t) {
568
+ let millis = (globalThis.Number(t.seconds.toString()) || 0) * 1_000;
569
+ millis += (t.nanos || 0) / 1_000_000;
570
+ return new globalThis.Date(millis);
571
+ }
572
+ function fromJsonTimestamp(o) {
573
+ if (o instanceof globalThis.Date) {
574
+ return toTimestamp(o);
575
+ }
576
+ else if (typeof o === "string") {
577
+ return toTimestamp(new globalThis.Date(o));
578
+ }
579
+ else {
580
+ return Timestamp.fromJSON(o);
581
+ }
582
+ }
583
+ function isSet(value) {
584
+ return value !== null && value !== undefined;
585
+ }
586
+ //# sourceMappingURL=canonical.js.map