@kingdomchain/wallet-client 0.1.0

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.
package/dist/index.js ADDED
@@ -0,0 +1,1723 @@
1
+ import { toHex, fromHex } from '@cosmjs/encoding';
2
+ import { sha256 } from '@noble/hashes/sha256';
3
+ import * as ed from '@noble/ed25519';
4
+ import { Registry } from '@cosmjs/proto-signing';
5
+ import { defaultRegistryTypes, SigningStargateClient } from '@cosmjs/stargate';
6
+ import { BinaryWriter, BinaryReader } from '@bufbuild/protobuf/wire';
7
+
8
+ // src/attestation.ts
9
+ var ATTESTATION_TYPE_CITIZENSHIP_APPLICATION = "citizenship_application";
10
+ var ATTESTATION_TYPE_RECOVERY = "recovery";
11
+ function hashField(value) {
12
+ return sha256(new TextEncoder().encode(value));
13
+ }
14
+ function formatUint64(value, fieldName) {
15
+ if (value < 0n) {
16
+ throw new Error(`${fieldName} must be non-negative, got ${value}`);
17
+ }
18
+ if (value > 0xffffffffffffffffn) {
19
+ throw new Error(`${fieldName} exceeds uint64 max, got ${value}`);
20
+ }
21
+ return value.toString(10);
22
+ }
23
+ function unixSeconds(date) {
24
+ return Math.trunc(date.getTime() / 1e3);
25
+ }
26
+ function combineHashes(hashes) {
27
+ const totalLen = hashes.reduce((acc, h) => acc + h.length, 0);
28
+ const preimage = new Uint8Array(totalLen);
29
+ let offset = 0;
30
+ for (const h of hashes) {
31
+ preimage.set(h, offset);
32
+ offset += h.length;
33
+ }
34
+ return toHex(sha256(preimage));
35
+ }
36
+ function attestationSignPayload(input) {
37
+ const hashes = [
38
+ hashField(input.attestationType),
39
+ hashField(input.chainId),
40
+ hashField(input.intendedWallet),
41
+ hashField(input.caseId),
42
+ hashField(input.policyVersion),
43
+ hashField(input.nonce),
44
+ hashField(input.uniquenessReference),
45
+ hashField(String(unixSeconds(input.issuedAt))),
46
+ hashField(String(unixSeconds(input.expiresAt))),
47
+ hashField(input.providerId),
48
+ hashField(formatUint64(input.providerKeyVersion, "providerKeyVersion"))
49
+ ];
50
+ if (input.attestationType === ATTESTATION_TYPE_RECOVERY) {
51
+ hashes.push(
52
+ hashField(formatUint64(input.citizenId ?? 0n, "citizenId")),
53
+ hashField(input.oldWallet ?? ""),
54
+ hashField(input.newWallet ?? "")
55
+ );
56
+ }
57
+ return combineHashes(hashes);
58
+ }
59
+ async function signAttestationPayload(privateKeySeed, payload) {
60
+ if (privateKeySeed.length !== 32) {
61
+ throw new Error("invalid ed25519 seed size");
62
+ }
63
+ const sig = await ed.signAsync(new TextEncoder().encode(payload), privateKeySeed);
64
+ return toHex(sig);
65
+ }
66
+ async function publicKeyFromPrivateSeed(privateKeySeed) {
67
+ if (privateKeySeed.length !== 32) {
68
+ throw new Error("invalid ed25519 seed size");
69
+ }
70
+ const pub = await ed.getPublicKeyAsync(privateKeySeed);
71
+ return toHex(pub);
72
+ }
73
+ function providerSeedFromHex(hex) {
74
+ const seed = fromHex(hex);
75
+ if (seed.length !== 32) {
76
+ throw new Error("provider seed hex must decode to 32 bytes");
77
+ }
78
+ return new Uint8Array(seed);
79
+ }
80
+ function createBaseTimestamp() {
81
+ return { seconds: 0n, nanos: 0 };
82
+ }
83
+ var Timestamp = {
84
+ encode(message, writer = new BinaryWriter()) {
85
+ if (message.seconds !== 0n) {
86
+ if (BigInt.asIntN(64, message.seconds) !== message.seconds) {
87
+ throw new globalThis.Error("value provided for field message.seconds of type int64 too large");
88
+ }
89
+ writer.uint32(8).int64(message.seconds);
90
+ }
91
+ if (message.nanos !== 0) {
92
+ writer.uint32(16).int32(message.nanos);
93
+ }
94
+ return writer;
95
+ },
96
+ decode(input, length) {
97
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
98
+ const end = length === void 0 ? reader.len : reader.pos + length;
99
+ const message = createBaseTimestamp();
100
+ while (reader.pos < end) {
101
+ const tag = reader.uint32();
102
+ switch (tag >>> 3) {
103
+ case 1: {
104
+ if (tag !== 8) {
105
+ break;
106
+ }
107
+ message.seconds = reader.int64();
108
+ continue;
109
+ }
110
+ case 2: {
111
+ if (tag !== 16) {
112
+ break;
113
+ }
114
+ message.nanos = reader.int32();
115
+ continue;
116
+ }
117
+ }
118
+ if ((tag & 7) === 4 || tag === 0) {
119
+ break;
120
+ }
121
+ reader.skip(tag & 7);
122
+ }
123
+ return message;
124
+ },
125
+ create(base) {
126
+ return Timestamp.fromPartial(base ?? {});
127
+ },
128
+ fromPartial(object) {
129
+ const message = createBaseTimestamp();
130
+ message.seconds = object.seconds !== void 0 && object.seconds !== null ? BigInt(object.seconds) : 0n;
131
+ message.nanos = object.nanos ?? 0;
132
+ return message;
133
+ }
134
+ };
135
+
136
+ // src/generated/isatheword/kingdomchain/citizen/v1/tx.ts
137
+ function createBaseMsgIssueKCP() {
138
+ return { authority: "", application_id: "", wallet_address: "", uniqueness_commitment: "", decision_id: "" };
139
+ }
140
+ var MsgIssueKCP = {
141
+ encode(message, writer = new BinaryWriter()) {
142
+ if (message.authority !== "") {
143
+ writer.uint32(10).string(message.authority);
144
+ }
145
+ if (message.application_id !== "") {
146
+ writer.uint32(18).string(message.application_id);
147
+ }
148
+ if (message.wallet_address !== "") {
149
+ writer.uint32(26).string(message.wallet_address);
150
+ }
151
+ if (message.uniqueness_commitment !== "") {
152
+ writer.uint32(34).string(message.uniqueness_commitment);
153
+ }
154
+ if (message.decision_id !== "") {
155
+ writer.uint32(42).string(message.decision_id);
156
+ }
157
+ return writer;
158
+ },
159
+ decode(input, length) {
160
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
161
+ const end = length === void 0 ? reader.len : reader.pos + length;
162
+ const message = createBaseMsgIssueKCP();
163
+ while (reader.pos < end) {
164
+ const tag = reader.uint32();
165
+ switch (tag >>> 3) {
166
+ case 1: {
167
+ if (tag !== 10) {
168
+ break;
169
+ }
170
+ message.authority = reader.string();
171
+ continue;
172
+ }
173
+ case 2: {
174
+ if (tag !== 18) {
175
+ break;
176
+ }
177
+ message.application_id = reader.string();
178
+ continue;
179
+ }
180
+ case 3: {
181
+ if (tag !== 26) {
182
+ break;
183
+ }
184
+ message.wallet_address = reader.string();
185
+ continue;
186
+ }
187
+ case 4: {
188
+ if (tag !== 34) {
189
+ break;
190
+ }
191
+ message.uniqueness_commitment = reader.string();
192
+ continue;
193
+ }
194
+ case 5: {
195
+ if (tag !== 42) {
196
+ break;
197
+ }
198
+ message.decision_id = reader.string();
199
+ continue;
200
+ }
201
+ }
202
+ if ((tag & 7) === 4 || tag === 0) {
203
+ break;
204
+ }
205
+ reader.skip(tag & 7);
206
+ }
207
+ return message;
208
+ },
209
+ create(base) {
210
+ return MsgIssueKCP.fromPartial(base ?? {});
211
+ },
212
+ fromPartial(object) {
213
+ const message = createBaseMsgIssueKCP();
214
+ message.authority = object.authority ?? "";
215
+ message.application_id = object.application_id ?? "";
216
+ message.wallet_address = object.wallet_address ?? "";
217
+ message.uniqueness_commitment = object.uniqueness_commitment ?? "";
218
+ message.decision_id = object.decision_id ?? "";
219
+ return message;
220
+ }
221
+ };
222
+ function createBaseMsgSuspendKCP() {
223
+ return { authority: "", citizen_id: 0n, reason_code: "", expires_at: void 0 };
224
+ }
225
+ var MsgSuspendKCP = {
226
+ encode(message, writer = new BinaryWriter()) {
227
+ if (message.authority !== "") {
228
+ writer.uint32(10).string(message.authority);
229
+ }
230
+ if (message.citizen_id !== 0n) {
231
+ if (BigInt.asUintN(64, message.citizen_id) !== message.citizen_id) {
232
+ throw new globalThis.Error("value provided for field message.citizen_id of type uint64 too large");
233
+ }
234
+ writer.uint32(16).uint64(message.citizen_id);
235
+ }
236
+ if (message.reason_code !== "") {
237
+ writer.uint32(26).string(message.reason_code);
238
+ }
239
+ if (message.expires_at !== void 0) {
240
+ Timestamp.encode(toTimestamp(message.expires_at), writer.uint32(34).fork()).join();
241
+ }
242
+ return writer;
243
+ },
244
+ decode(input, length) {
245
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
246
+ const end = length === void 0 ? reader.len : reader.pos + length;
247
+ const message = createBaseMsgSuspendKCP();
248
+ while (reader.pos < end) {
249
+ const tag = reader.uint32();
250
+ switch (tag >>> 3) {
251
+ case 1: {
252
+ if (tag !== 10) {
253
+ break;
254
+ }
255
+ message.authority = reader.string();
256
+ continue;
257
+ }
258
+ case 2: {
259
+ if (tag !== 16) {
260
+ break;
261
+ }
262
+ message.citizen_id = reader.uint64();
263
+ continue;
264
+ }
265
+ case 3: {
266
+ if (tag !== 26) {
267
+ break;
268
+ }
269
+ message.reason_code = reader.string();
270
+ continue;
271
+ }
272
+ case 4: {
273
+ if (tag !== 34) {
274
+ break;
275
+ }
276
+ message.expires_at = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
277
+ continue;
278
+ }
279
+ }
280
+ if ((tag & 7) === 4 || tag === 0) {
281
+ break;
282
+ }
283
+ reader.skip(tag & 7);
284
+ }
285
+ return message;
286
+ },
287
+ create(base) {
288
+ return MsgSuspendKCP.fromPartial(base ?? {});
289
+ },
290
+ fromPartial(object) {
291
+ const message = createBaseMsgSuspendKCP();
292
+ message.authority = object.authority ?? "";
293
+ message.citizen_id = object.citizen_id !== void 0 && object.citizen_id !== null ? BigInt(object.citizen_id) : 0n;
294
+ message.reason_code = object.reason_code ?? "";
295
+ message.expires_at = object.expires_at ?? void 0;
296
+ return message;
297
+ }
298
+ };
299
+ function createBaseMsgReactivateKCP() {
300
+ return { authority: "", citizen_id: 0n };
301
+ }
302
+ var MsgReactivateKCP = {
303
+ encode(message, writer = new BinaryWriter()) {
304
+ if (message.authority !== "") {
305
+ writer.uint32(10).string(message.authority);
306
+ }
307
+ if (message.citizen_id !== 0n) {
308
+ if (BigInt.asUintN(64, message.citizen_id) !== message.citizen_id) {
309
+ throw new globalThis.Error("value provided for field message.citizen_id of type uint64 too large");
310
+ }
311
+ writer.uint32(16).uint64(message.citizen_id);
312
+ }
313
+ return writer;
314
+ },
315
+ decode(input, length) {
316
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
317
+ const end = length === void 0 ? reader.len : reader.pos + length;
318
+ const message = createBaseMsgReactivateKCP();
319
+ while (reader.pos < end) {
320
+ const tag = reader.uint32();
321
+ switch (tag >>> 3) {
322
+ case 1: {
323
+ if (tag !== 10) {
324
+ break;
325
+ }
326
+ message.authority = reader.string();
327
+ continue;
328
+ }
329
+ case 2: {
330
+ if (tag !== 16) {
331
+ break;
332
+ }
333
+ message.citizen_id = reader.uint64();
334
+ continue;
335
+ }
336
+ }
337
+ if ((tag & 7) === 4 || tag === 0) {
338
+ break;
339
+ }
340
+ reader.skip(tag & 7);
341
+ }
342
+ return message;
343
+ },
344
+ create(base) {
345
+ return MsgReactivateKCP.fromPartial(base ?? {});
346
+ },
347
+ fromPartial(object) {
348
+ const message = createBaseMsgReactivateKCP();
349
+ message.authority = object.authority ?? "";
350
+ message.citizen_id = object.citizen_id !== void 0 && object.citizen_id !== null ? BigInt(object.citizen_id) : 0n;
351
+ return message;
352
+ }
353
+ };
354
+ function createBaseMsgRevokeKCP() {
355
+ return { authority: "", citizen_id: 0n, reason_code: "", evidence_ref: "" };
356
+ }
357
+ var MsgRevokeKCP = {
358
+ encode(message, writer = new BinaryWriter()) {
359
+ if (message.authority !== "") {
360
+ writer.uint32(10).string(message.authority);
361
+ }
362
+ if (message.citizen_id !== 0n) {
363
+ if (BigInt.asUintN(64, message.citizen_id) !== message.citizen_id) {
364
+ throw new globalThis.Error("value provided for field message.citizen_id of type uint64 too large");
365
+ }
366
+ writer.uint32(16).uint64(message.citizen_id);
367
+ }
368
+ if (message.reason_code !== "") {
369
+ writer.uint32(26).string(message.reason_code);
370
+ }
371
+ if (message.evidence_ref !== "") {
372
+ writer.uint32(34).string(message.evidence_ref);
373
+ }
374
+ return writer;
375
+ },
376
+ decode(input, length) {
377
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
378
+ const end = length === void 0 ? reader.len : reader.pos + length;
379
+ const message = createBaseMsgRevokeKCP();
380
+ while (reader.pos < end) {
381
+ const tag = reader.uint32();
382
+ switch (tag >>> 3) {
383
+ case 1: {
384
+ if (tag !== 10) {
385
+ break;
386
+ }
387
+ message.authority = reader.string();
388
+ continue;
389
+ }
390
+ case 2: {
391
+ if (tag !== 16) {
392
+ break;
393
+ }
394
+ message.citizen_id = reader.uint64();
395
+ continue;
396
+ }
397
+ case 3: {
398
+ if (tag !== 26) {
399
+ break;
400
+ }
401
+ message.reason_code = reader.string();
402
+ continue;
403
+ }
404
+ case 4: {
405
+ if (tag !== 34) {
406
+ break;
407
+ }
408
+ message.evidence_ref = reader.string();
409
+ continue;
410
+ }
411
+ }
412
+ if ((tag & 7) === 4 || tag === 0) {
413
+ break;
414
+ }
415
+ reader.skip(tag & 7);
416
+ }
417
+ return message;
418
+ },
419
+ create(base) {
420
+ return MsgRevokeKCP.fromPartial(base ?? {});
421
+ },
422
+ fromPartial(object) {
423
+ const message = createBaseMsgRevokeKCP();
424
+ message.authority = object.authority ?? "";
425
+ message.citizen_id = object.citizen_id !== void 0 && object.citizen_id !== null ? BigInt(object.citizen_id) : 0n;
426
+ message.reason_code = object.reason_code ?? "";
427
+ message.evidence_ref = object.evidence_ref ?? "";
428
+ return message;
429
+ }
430
+ };
431
+ function createBaseMsgInitiateRecovery() {
432
+ return { authority: "", citizen_id: 0n, new_wallet: "", recovery_case_id: "", cooling_off_ends_at: void 0 };
433
+ }
434
+ var MsgInitiateRecovery = {
435
+ encode(message, writer = new BinaryWriter()) {
436
+ if (message.authority !== "") {
437
+ writer.uint32(10).string(message.authority);
438
+ }
439
+ if (message.citizen_id !== 0n) {
440
+ if (BigInt.asUintN(64, message.citizen_id) !== message.citizen_id) {
441
+ throw new globalThis.Error("value provided for field message.citizen_id of type uint64 too large");
442
+ }
443
+ writer.uint32(16).uint64(message.citizen_id);
444
+ }
445
+ if (message.new_wallet !== "") {
446
+ writer.uint32(26).string(message.new_wallet);
447
+ }
448
+ if (message.recovery_case_id !== "") {
449
+ writer.uint32(34).string(message.recovery_case_id);
450
+ }
451
+ if (message.cooling_off_ends_at !== void 0) {
452
+ Timestamp.encode(toTimestamp(message.cooling_off_ends_at), writer.uint32(42).fork()).join();
453
+ }
454
+ return writer;
455
+ },
456
+ decode(input, length) {
457
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
458
+ const end = length === void 0 ? reader.len : reader.pos + length;
459
+ const message = createBaseMsgInitiateRecovery();
460
+ while (reader.pos < end) {
461
+ const tag = reader.uint32();
462
+ switch (tag >>> 3) {
463
+ case 1: {
464
+ if (tag !== 10) {
465
+ break;
466
+ }
467
+ message.authority = reader.string();
468
+ continue;
469
+ }
470
+ case 2: {
471
+ if (tag !== 16) {
472
+ break;
473
+ }
474
+ message.citizen_id = reader.uint64();
475
+ continue;
476
+ }
477
+ case 3: {
478
+ if (tag !== 26) {
479
+ break;
480
+ }
481
+ message.new_wallet = reader.string();
482
+ continue;
483
+ }
484
+ case 4: {
485
+ if (tag !== 34) {
486
+ break;
487
+ }
488
+ message.recovery_case_id = reader.string();
489
+ continue;
490
+ }
491
+ case 5: {
492
+ if (tag !== 42) {
493
+ break;
494
+ }
495
+ message.cooling_off_ends_at = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
496
+ continue;
497
+ }
498
+ }
499
+ if ((tag & 7) === 4 || tag === 0) {
500
+ break;
501
+ }
502
+ reader.skip(tag & 7);
503
+ }
504
+ return message;
505
+ },
506
+ create(base) {
507
+ return MsgInitiateRecovery.fromPartial(base ?? {});
508
+ },
509
+ fromPartial(object) {
510
+ const message = createBaseMsgInitiateRecovery();
511
+ message.authority = object.authority ?? "";
512
+ message.citizen_id = object.citizen_id !== void 0 && object.citizen_id !== null ? BigInt(object.citizen_id) : 0n;
513
+ message.new_wallet = object.new_wallet ?? "";
514
+ message.recovery_case_id = object.recovery_case_id ?? "";
515
+ message.cooling_off_ends_at = object.cooling_off_ends_at ?? void 0;
516
+ return message;
517
+ }
518
+ };
519
+ function createBaseMsgApproveRecovery() {
520
+ return { authority: "", recovery_case_id: "" };
521
+ }
522
+ var MsgApproveRecovery = {
523
+ encode(message, writer = new BinaryWriter()) {
524
+ if (message.authority !== "") {
525
+ writer.uint32(10).string(message.authority);
526
+ }
527
+ if (message.recovery_case_id !== "") {
528
+ writer.uint32(18).string(message.recovery_case_id);
529
+ }
530
+ return writer;
531
+ },
532
+ decode(input, length) {
533
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
534
+ const end = length === void 0 ? reader.len : reader.pos + length;
535
+ const message = createBaseMsgApproveRecovery();
536
+ while (reader.pos < end) {
537
+ const tag = reader.uint32();
538
+ switch (tag >>> 3) {
539
+ case 1: {
540
+ if (tag !== 10) {
541
+ break;
542
+ }
543
+ message.authority = reader.string();
544
+ continue;
545
+ }
546
+ case 2: {
547
+ if (tag !== 18) {
548
+ break;
549
+ }
550
+ message.recovery_case_id = reader.string();
551
+ continue;
552
+ }
553
+ }
554
+ if ((tag & 7) === 4 || tag === 0) {
555
+ break;
556
+ }
557
+ reader.skip(tag & 7);
558
+ }
559
+ return message;
560
+ },
561
+ create(base) {
562
+ return MsgApproveRecovery.fromPartial(base ?? {});
563
+ },
564
+ fromPartial(object) {
565
+ const message = createBaseMsgApproveRecovery();
566
+ message.authority = object.authority ?? "";
567
+ message.recovery_case_id = object.recovery_case_id ?? "";
568
+ return message;
569
+ }
570
+ };
571
+ function createBaseMsgFinalizeRecovery() {
572
+ return { authority: "", recovery_case_id: "", decision_id: "" };
573
+ }
574
+ var MsgFinalizeRecovery = {
575
+ encode(message, writer = new BinaryWriter()) {
576
+ if (message.authority !== "") {
577
+ writer.uint32(10).string(message.authority);
578
+ }
579
+ if (message.recovery_case_id !== "") {
580
+ writer.uint32(18).string(message.recovery_case_id);
581
+ }
582
+ if (message.decision_id !== "") {
583
+ writer.uint32(26).string(message.decision_id);
584
+ }
585
+ return writer;
586
+ },
587
+ decode(input, length) {
588
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
589
+ const end = length === void 0 ? reader.len : reader.pos + length;
590
+ const message = createBaseMsgFinalizeRecovery();
591
+ while (reader.pos < end) {
592
+ const tag = reader.uint32();
593
+ switch (tag >>> 3) {
594
+ case 1: {
595
+ if (tag !== 10) {
596
+ break;
597
+ }
598
+ message.authority = reader.string();
599
+ continue;
600
+ }
601
+ case 2: {
602
+ if (tag !== 18) {
603
+ break;
604
+ }
605
+ message.recovery_case_id = reader.string();
606
+ continue;
607
+ }
608
+ case 3: {
609
+ if (tag !== 26) {
610
+ break;
611
+ }
612
+ message.decision_id = reader.string();
613
+ continue;
614
+ }
615
+ }
616
+ if ((tag & 7) === 4 || tag === 0) {
617
+ break;
618
+ }
619
+ reader.skip(tag & 7);
620
+ }
621
+ return message;
622
+ },
623
+ create(base) {
624
+ return MsgFinalizeRecovery.fromPartial(base ?? {});
625
+ },
626
+ fromPartial(object) {
627
+ const message = createBaseMsgFinalizeRecovery();
628
+ message.authority = object.authority ?? "";
629
+ message.recovery_case_id = object.recovery_case_id ?? "";
630
+ message.decision_id = object.decision_id ?? "";
631
+ return message;
632
+ }
633
+ };
634
+ function createBaseMsgCancelRecovery() {
635
+ return { authority: "", recovery_case_id: "", reason_code: "" };
636
+ }
637
+ var MsgCancelRecovery = {
638
+ encode(message, writer = new BinaryWriter()) {
639
+ if (message.authority !== "") {
640
+ writer.uint32(10).string(message.authority);
641
+ }
642
+ if (message.recovery_case_id !== "") {
643
+ writer.uint32(18).string(message.recovery_case_id);
644
+ }
645
+ if (message.reason_code !== "") {
646
+ writer.uint32(26).string(message.reason_code);
647
+ }
648
+ return writer;
649
+ },
650
+ decode(input, length) {
651
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
652
+ const end = length === void 0 ? reader.len : reader.pos + length;
653
+ const message = createBaseMsgCancelRecovery();
654
+ while (reader.pos < end) {
655
+ const tag = reader.uint32();
656
+ switch (tag >>> 3) {
657
+ case 1: {
658
+ if (tag !== 10) {
659
+ break;
660
+ }
661
+ message.authority = reader.string();
662
+ continue;
663
+ }
664
+ case 2: {
665
+ if (tag !== 18) {
666
+ break;
667
+ }
668
+ message.recovery_case_id = reader.string();
669
+ continue;
670
+ }
671
+ case 3: {
672
+ if (tag !== 26) {
673
+ break;
674
+ }
675
+ message.reason_code = reader.string();
676
+ continue;
677
+ }
678
+ }
679
+ if ((tag & 7) === 4 || tag === 0) {
680
+ break;
681
+ }
682
+ reader.skip(tag & 7);
683
+ }
684
+ return message;
685
+ },
686
+ create(base) {
687
+ return MsgCancelRecovery.fromPartial(base ?? {});
688
+ },
689
+ fromPartial(object) {
690
+ const message = createBaseMsgCancelRecovery();
691
+ message.authority = object.authority ?? "";
692
+ message.recovery_case_id = object.recovery_case_id ?? "";
693
+ message.reason_code = object.reason_code ?? "";
694
+ return message;
695
+ }
696
+ };
697
+ function toTimestamp(date) {
698
+ const seconds = BigInt(Math.trunc(date.getTime() / 1e3));
699
+ const nanos = date.getTime() % 1e3 * 1e6;
700
+ return { seconds, nanos };
701
+ }
702
+ function fromTimestamp(t) {
703
+ let millis = (globalThis.Number(t.seconds.toString()) || 0) * 1e3;
704
+ millis += (t.nanos || 0) / 1e6;
705
+ return new globalThis.Date(millis);
706
+ }
707
+ function createBaseMsgRegisterProvider() {
708
+ return {
709
+ authority: "",
710
+ provider_id: "",
711
+ public_key: "",
712
+ key_version: 0n,
713
+ supported_assurance_levels: [],
714
+ supported_jurisdictions: [],
715
+ active_from: void 0,
716
+ active_until: void 0
717
+ };
718
+ }
719
+ var MsgRegisterProvider = {
720
+ encode(message, writer = new BinaryWriter()) {
721
+ if (message.authority !== "") {
722
+ writer.uint32(10).string(message.authority);
723
+ }
724
+ if (message.provider_id !== "") {
725
+ writer.uint32(18).string(message.provider_id);
726
+ }
727
+ if (message.public_key !== "") {
728
+ writer.uint32(26).string(message.public_key);
729
+ }
730
+ if (message.key_version !== 0n) {
731
+ if (BigInt.asUintN(64, message.key_version) !== message.key_version) {
732
+ throw new globalThis.Error("value provided for field message.key_version of type uint64 too large");
733
+ }
734
+ writer.uint32(32).uint64(message.key_version);
735
+ }
736
+ for (const v of message.supported_assurance_levels) {
737
+ writer.uint32(42).string(v);
738
+ }
739
+ for (const v of message.supported_jurisdictions) {
740
+ writer.uint32(50).string(v);
741
+ }
742
+ if (message.active_from !== void 0) {
743
+ Timestamp.encode(toTimestamp2(message.active_from), writer.uint32(58).fork()).join();
744
+ }
745
+ if (message.active_until !== void 0) {
746
+ Timestamp.encode(toTimestamp2(message.active_until), writer.uint32(66).fork()).join();
747
+ }
748
+ return writer;
749
+ },
750
+ decode(input, length) {
751
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
752
+ const end = length === void 0 ? reader.len : reader.pos + length;
753
+ const message = createBaseMsgRegisterProvider();
754
+ while (reader.pos < end) {
755
+ const tag = reader.uint32();
756
+ switch (tag >>> 3) {
757
+ case 1: {
758
+ if (tag !== 10) {
759
+ break;
760
+ }
761
+ message.authority = reader.string();
762
+ continue;
763
+ }
764
+ case 2: {
765
+ if (tag !== 18) {
766
+ break;
767
+ }
768
+ message.provider_id = reader.string();
769
+ continue;
770
+ }
771
+ case 3: {
772
+ if (tag !== 26) {
773
+ break;
774
+ }
775
+ message.public_key = reader.string();
776
+ continue;
777
+ }
778
+ case 4: {
779
+ if (tag !== 32) {
780
+ break;
781
+ }
782
+ message.key_version = reader.uint64();
783
+ continue;
784
+ }
785
+ case 5: {
786
+ if (tag !== 42) {
787
+ break;
788
+ }
789
+ message.supported_assurance_levels.push(reader.string());
790
+ continue;
791
+ }
792
+ case 6: {
793
+ if (tag !== 50) {
794
+ break;
795
+ }
796
+ message.supported_jurisdictions.push(reader.string());
797
+ continue;
798
+ }
799
+ case 7: {
800
+ if (tag !== 58) {
801
+ break;
802
+ }
803
+ message.active_from = fromTimestamp2(Timestamp.decode(reader, reader.uint32()));
804
+ continue;
805
+ }
806
+ case 8: {
807
+ if (tag !== 66) {
808
+ break;
809
+ }
810
+ message.active_until = fromTimestamp2(Timestamp.decode(reader, reader.uint32()));
811
+ continue;
812
+ }
813
+ }
814
+ if ((tag & 7) === 4 || tag === 0) {
815
+ break;
816
+ }
817
+ reader.skip(tag & 7);
818
+ }
819
+ return message;
820
+ },
821
+ create(base) {
822
+ return MsgRegisterProvider.fromPartial(base ?? {});
823
+ },
824
+ fromPartial(object) {
825
+ const message = createBaseMsgRegisterProvider();
826
+ message.authority = object.authority ?? "";
827
+ message.provider_id = object.provider_id ?? "";
828
+ message.public_key = object.public_key ?? "";
829
+ message.key_version = object.key_version !== void 0 && object.key_version !== null ? BigInt(object.key_version) : 0n;
830
+ message.supported_assurance_levels = object.supported_assurance_levels?.map((e) => e) || [];
831
+ message.supported_jurisdictions = object.supported_jurisdictions?.map((e) => e) || [];
832
+ message.active_from = object.active_from ?? void 0;
833
+ message.active_until = object.active_until ?? void 0;
834
+ return message;
835
+ }
836
+ };
837
+ function createBaseMsgSuspendProvider() {
838
+ return { authority: "", provider_id: "", reason_code: "" };
839
+ }
840
+ var MsgSuspendProvider = {
841
+ encode(message, writer = new BinaryWriter()) {
842
+ if (message.authority !== "") {
843
+ writer.uint32(10).string(message.authority);
844
+ }
845
+ if (message.provider_id !== "") {
846
+ writer.uint32(18).string(message.provider_id);
847
+ }
848
+ if (message.reason_code !== "") {
849
+ writer.uint32(26).string(message.reason_code);
850
+ }
851
+ return writer;
852
+ },
853
+ decode(input, length) {
854
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
855
+ const end = length === void 0 ? reader.len : reader.pos + length;
856
+ const message = createBaseMsgSuspendProvider();
857
+ while (reader.pos < end) {
858
+ const tag = reader.uint32();
859
+ switch (tag >>> 3) {
860
+ case 1: {
861
+ if (tag !== 10) {
862
+ break;
863
+ }
864
+ message.authority = reader.string();
865
+ continue;
866
+ }
867
+ case 2: {
868
+ if (tag !== 18) {
869
+ break;
870
+ }
871
+ message.provider_id = reader.string();
872
+ continue;
873
+ }
874
+ case 3: {
875
+ if (tag !== 26) {
876
+ break;
877
+ }
878
+ message.reason_code = reader.string();
879
+ continue;
880
+ }
881
+ }
882
+ if ((tag & 7) === 4 || tag === 0) {
883
+ break;
884
+ }
885
+ reader.skip(tag & 7);
886
+ }
887
+ return message;
888
+ },
889
+ create(base) {
890
+ return MsgSuspendProvider.fromPartial(base ?? {});
891
+ },
892
+ fromPartial(object) {
893
+ const message = createBaseMsgSuspendProvider();
894
+ message.authority = object.authority ?? "";
895
+ message.provider_id = object.provider_id ?? "";
896
+ message.reason_code = object.reason_code ?? "";
897
+ return message;
898
+ }
899
+ };
900
+ function createBaseMsgSubmitApplication() {
901
+ return {
902
+ applicant_wallet: "",
903
+ application_id: "",
904
+ provider_id: "",
905
+ provider_key_version: 0n,
906
+ chain_id: "",
907
+ case_id: "",
908
+ policy_version: "",
909
+ nonce: "",
910
+ uniqueness_reference: "",
911
+ issued_at: void 0,
912
+ expires_at: void 0,
913
+ signature: ""
914
+ };
915
+ }
916
+ var MsgSubmitApplication = {
917
+ encode(message, writer = new BinaryWriter()) {
918
+ if (message.applicant_wallet !== "") {
919
+ writer.uint32(10).string(message.applicant_wallet);
920
+ }
921
+ if (message.application_id !== "") {
922
+ writer.uint32(18).string(message.application_id);
923
+ }
924
+ if (message.provider_id !== "") {
925
+ writer.uint32(26).string(message.provider_id);
926
+ }
927
+ if (message.provider_key_version !== 0n) {
928
+ if (BigInt.asUintN(64, message.provider_key_version) !== message.provider_key_version) {
929
+ throw new globalThis.Error("value provided for field message.provider_key_version of type uint64 too large");
930
+ }
931
+ writer.uint32(32).uint64(message.provider_key_version);
932
+ }
933
+ if (message.chain_id !== "") {
934
+ writer.uint32(42).string(message.chain_id);
935
+ }
936
+ if (message.case_id !== "") {
937
+ writer.uint32(50).string(message.case_id);
938
+ }
939
+ if (message.policy_version !== "") {
940
+ writer.uint32(58).string(message.policy_version);
941
+ }
942
+ if (message.nonce !== "") {
943
+ writer.uint32(66).string(message.nonce);
944
+ }
945
+ if (message.uniqueness_reference !== "") {
946
+ writer.uint32(74).string(message.uniqueness_reference);
947
+ }
948
+ if (message.issued_at !== void 0) {
949
+ Timestamp.encode(toTimestamp2(message.issued_at), writer.uint32(82).fork()).join();
950
+ }
951
+ if (message.expires_at !== void 0) {
952
+ Timestamp.encode(toTimestamp2(message.expires_at), writer.uint32(90).fork()).join();
953
+ }
954
+ if (message.signature !== "") {
955
+ writer.uint32(98).string(message.signature);
956
+ }
957
+ return writer;
958
+ },
959
+ decode(input, length) {
960
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
961
+ const end = length === void 0 ? reader.len : reader.pos + length;
962
+ const message = createBaseMsgSubmitApplication();
963
+ while (reader.pos < end) {
964
+ const tag = reader.uint32();
965
+ switch (tag >>> 3) {
966
+ case 1: {
967
+ if (tag !== 10) {
968
+ break;
969
+ }
970
+ message.applicant_wallet = reader.string();
971
+ continue;
972
+ }
973
+ case 2: {
974
+ if (tag !== 18) {
975
+ break;
976
+ }
977
+ message.application_id = reader.string();
978
+ continue;
979
+ }
980
+ case 3: {
981
+ if (tag !== 26) {
982
+ break;
983
+ }
984
+ message.provider_id = reader.string();
985
+ continue;
986
+ }
987
+ case 4: {
988
+ if (tag !== 32) {
989
+ break;
990
+ }
991
+ message.provider_key_version = reader.uint64();
992
+ continue;
993
+ }
994
+ case 5: {
995
+ if (tag !== 42) {
996
+ break;
997
+ }
998
+ message.chain_id = reader.string();
999
+ continue;
1000
+ }
1001
+ case 6: {
1002
+ if (tag !== 50) {
1003
+ break;
1004
+ }
1005
+ message.case_id = reader.string();
1006
+ continue;
1007
+ }
1008
+ case 7: {
1009
+ if (tag !== 58) {
1010
+ break;
1011
+ }
1012
+ message.policy_version = reader.string();
1013
+ continue;
1014
+ }
1015
+ case 8: {
1016
+ if (tag !== 66) {
1017
+ break;
1018
+ }
1019
+ message.nonce = reader.string();
1020
+ continue;
1021
+ }
1022
+ case 9: {
1023
+ if (tag !== 74) {
1024
+ break;
1025
+ }
1026
+ message.uniqueness_reference = reader.string();
1027
+ continue;
1028
+ }
1029
+ case 10: {
1030
+ if (tag !== 82) {
1031
+ break;
1032
+ }
1033
+ message.issued_at = fromTimestamp2(Timestamp.decode(reader, reader.uint32()));
1034
+ continue;
1035
+ }
1036
+ case 11: {
1037
+ if (tag !== 90) {
1038
+ break;
1039
+ }
1040
+ message.expires_at = fromTimestamp2(Timestamp.decode(reader, reader.uint32()));
1041
+ continue;
1042
+ }
1043
+ case 12: {
1044
+ if (tag !== 98) {
1045
+ break;
1046
+ }
1047
+ message.signature = reader.string();
1048
+ continue;
1049
+ }
1050
+ }
1051
+ if ((tag & 7) === 4 || tag === 0) {
1052
+ break;
1053
+ }
1054
+ reader.skip(tag & 7);
1055
+ }
1056
+ return message;
1057
+ },
1058
+ create(base) {
1059
+ return MsgSubmitApplication.fromPartial(base ?? {});
1060
+ },
1061
+ fromPartial(object) {
1062
+ const message = createBaseMsgSubmitApplication();
1063
+ message.applicant_wallet = object.applicant_wallet ?? "";
1064
+ message.application_id = object.application_id ?? "";
1065
+ message.provider_id = object.provider_id ?? "";
1066
+ message.provider_key_version = object.provider_key_version !== void 0 && object.provider_key_version !== null ? BigInt(object.provider_key_version) : 0n;
1067
+ message.chain_id = object.chain_id ?? "";
1068
+ message.case_id = object.case_id ?? "";
1069
+ message.policy_version = object.policy_version ?? "";
1070
+ message.nonce = object.nonce ?? "";
1071
+ message.uniqueness_reference = object.uniqueness_reference ?? "";
1072
+ message.issued_at = object.issued_at ?? void 0;
1073
+ message.expires_at = object.expires_at ?? void 0;
1074
+ message.signature = object.signature ?? "";
1075
+ return message;
1076
+ }
1077
+ };
1078
+ function createBaseMsgSubmitRecoveryAttestation() {
1079
+ return {
1080
+ applicant_wallet: "",
1081
+ recovery_case_id: "",
1082
+ provider_id: "",
1083
+ provider_key_version: 0n,
1084
+ chain_id: "",
1085
+ case_id: "",
1086
+ policy_version: "",
1087
+ nonce: "",
1088
+ uniqueness_reference: "",
1089
+ citizen_id: 0n,
1090
+ old_wallet: "",
1091
+ new_wallet: "",
1092
+ issued_at: void 0,
1093
+ expires_at: void 0,
1094
+ signature: ""
1095
+ };
1096
+ }
1097
+ var MsgSubmitRecoveryAttestation = {
1098
+ encode(message, writer = new BinaryWriter()) {
1099
+ if (message.applicant_wallet !== "") {
1100
+ writer.uint32(10).string(message.applicant_wallet);
1101
+ }
1102
+ if (message.recovery_case_id !== "") {
1103
+ writer.uint32(18).string(message.recovery_case_id);
1104
+ }
1105
+ if (message.provider_id !== "") {
1106
+ writer.uint32(26).string(message.provider_id);
1107
+ }
1108
+ if (message.provider_key_version !== 0n) {
1109
+ if (BigInt.asUintN(64, message.provider_key_version) !== message.provider_key_version) {
1110
+ throw new globalThis.Error("value provided for field message.provider_key_version of type uint64 too large");
1111
+ }
1112
+ writer.uint32(32).uint64(message.provider_key_version);
1113
+ }
1114
+ if (message.chain_id !== "") {
1115
+ writer.uint32(42).string(message.chain_id);
1116
+ }
1117
+ if (message.case_id !== "") {
1118
+ writer.uint32(50).string(message.case_id);
1119
+ }
1120
+ if (message.policy_version !== "") {
1121
+ writer.uint32(58).string(message.policy_version);
1122
+ }
1123
+ if (message.nonce !== "") {
1124
+ writer.uint32(66).string(message.nonce);
1125
+ }
1126
+ if (message.uniqueness_reference !== "") {
1127
+ writer.uint32(74).string(message.uniqueness_reference);
1128
+ }
1129
+ if (message.citizen_id !== 0n) {
1130
+ if (BigInt.asUintN(64, message.citizen_id) !== message.citizen_id) {
1131
+ throw new globalThis.Error("value provided for field message.citizen_id of type uint64 too large");
1132
+ }
1133
+ writer.uint32(80).uint64(message.citizen_id);
1134
+ }
1135
+ if (message.old_wallet !== "") {
1136
+ writer.uint32(90).string(message.old_wallet);
1137
+ }
1138
+ if (message.new_wallet !== "") {
1139
+ writer.uint32(98).string(message.new_wallet);
1140
+ }
1141
+ if (message.issued_at !== void 0) {
1142
+ Timestamp.encode(toTimestamp2(message.issued_at), writer.uint32(106).fork()).join();
1143
+ }
1144
+ if (message.expires_at !== void 0) {
1145
+ Timestamp.encode(toTimestamp2(message.expires_at), writer.uint32(114).fork()).join();
1146
+ }
1147
+ if (message.signature !== "") {
1148
+ writer.uint32(122).string(message.signature);
1149
+ }
1150
+ return writer;
1151
+ },
1152
+ decode(input, length) {
1153
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
1154
+ const end = length === void 0 ? reader.len : reader.pos + length;
1155
+ const message = createBaseMsgSubmitRecoveryAttestation();
1156
+ while (reader.pos < end) {
1157
+ const tag = reader.uint32();
1158
+ switch (tag >>> 3) {
1159
+ case 1: {
1160
+ if (tag !== 10) {
1161
+ break;
1162
+ }
1163
+ message.applicant_wallet = reader.string();
1164
+ continue;
1165
+ }
1166
+ case 2: {
1167
+ if (tag !== 18) {
1168
+ break;
1169
+ }
1170
+ message.recovery_case_id = reader.string();
1171
+ continue;
1172
+ }
1173
+ case 3: {
1174
+ if (tag !== 26) {
1175
+ break;
1176
+ }
1177
+ message.provider_id = reader.string();
1178
+ continue;
1179
+ }
1180
+ case 4: {
1181
+ if (tag !== 32) {
1182
+ break;
1183
+ }
1184
+ message.provider_key_version = reader.uint64();
1185
+ continue;
1186
+ }
1187
+ case 5: {
1188
+ if (tag !== 42) {
1189
+ break;
1190
+ }
1191
+ message.chain_id = reader.string();
1192
+ continue;
1193
+ }
1194
+ case 6: {
1195
+ if (tag !== 50) {
1196
+ break;
1197
+ }
1198
+ message.case_id = reader.string();
1199
+ continue;
1200
+ }
1201
+ case 7: {
1202
+ if (tag !== 58) {
1203
+ break;
1204
+ }
1205
+ message.policy_version = reader.string();
1206
+ continue;
1207
+ }
1208
+ case 8: {
1209
+ if (tag !== 66) {
1210
+ break;
1211
+ }
1212
+ message.nonce = reader.string();
1213
+ continue;
1214
+ }
1215
+ case 9: {
1216
+ if (tag !== 74) {
1217
+ break;
1218
+ }
1219
+ message.uniqueness_reference = reader.string();
1220
+ continue;
1221
+ }
1222
+ case 10: {
1223
+ if (tag !== 80) {
1224
+ break;
1225
+ }
1226
+ message.citizen_id = reader.uint64();
1227
+ continue;
1228
+ }
1229
+ case 11: {
1230
+ if (tag !== 90) {
1231
+ break;
1232
+ }
1233
+ message.old_wallet = reader.string();
1234
+ continue;
1235
+ }
1236
+ case 12: {
1237
+ if (tag !== 98) {
1238
+ break;
1239
+ }
1240
+ message.new_wallet = reader.string();
1241
+ continue;
1242
+ }
1243
+ case 13: {
1244
+ if (tag !== 106) {
1245
+ break;
1246
+ }
1247
+ message.issued_at = fromTimestamp2(Timestamp.decode(reader, reader.uint32()));
1248
+ continue;
1249
+ }
1250
+ case 14: {
1251
+ if (tag !== 114) {
1252
+ break;
1253
+ }
1254
+ message.expires_at = fromTimestamp2(Timestamp.decode(reader, reader.uint32()));
1255
+ continue;
1256
+ }
1257
+ case 15: {
1258
+ if (tag !== 122) {
1259
+ break;
1260
+ }
1261
+ message.signature = reader.string();
1262
+ continue;
1263
+ }
1264
+ }
1265
+ if ((tag & 7) === 4 || tag === 0) {
1266
+ break;
1267
+ }
1268
+ reader.skip(tag & 7);
1269
+ }
1270
+ return message;
1271
+ },
1272
+ create(base) {
1273
+ return MsgSubmitRecoveryAttestation.fromPartial(base ?? {});
1274
+ },
1275
+ fromPartial(object) {
1276
+ const message = createBaseMsgSubmitRecoveryAttestation();
1277
+ message.applicant_wallet = object.applicant_wallet ?? "";
1278
+ message.recovery_case_id = object.recovery_case_id ?? "";
1279
+ message.provider_id = object.provider_id ?? "";
1280
+ message.provider_key_version = object.provider_key_version !== void 0 && object.provider_key_version !== null ? BigInt(object.provider_key_version) : 0n;
1281
+ message.chain_id = object.chain_id ?? "";
1282
+ message.case_id = object.case_id ?? "";
1283
+ message.policy_version = object.policy_version ?? "";
1284
+ message.nonce = object.nonce ?? "";
1285
+ message.uniqueness_reference = object.uniqueness_reference ?? "";
1286
+ message.citizen_id = object.citizen_id !== void 0 && object.citizen_id !== null ? BigInt(object.citizen_id) : 0n;
1287
+ message.old_wallet = object.old_wallet ?? "";
1288
+ message.new_wallet = object.new_wallet ?? "";
1289
+ message.issued_at = object.issued_at ?? void 0;
1290
+ message.expires_at = object.expires_at ?? void 0;
1291
+ message.signature = object.signature ?? "";
1292
+ return message;
1293
+ }
1294
+ };
1295
+ function createBaseMsgDecideApplication() {
1296
+ return { authority: "", application_id: "", approved: false, reason_code: "" };
1297
+ }
1298
+ var MsgDecideApplication = {
1299
+ encode(message, writer = new BinaryWriter()) {
1300
+ if (message.authority !== "") {
1301
+ writer.uint32(10).string(message.authority);
1302
+ }
1303
+ if (message.application_id !== "") {
1304
+ writer.uint32(18).string(message.application_id);
1305
+ }
1306
+ if (message.approved !== false) {
1307
+ writer.uint32(24).bool(message.approved);
1308
+ }
1309
+ if (message.reason_code !== "") {
1310
+ writer.uint32(34).string(message.reason_code);
1311
+ }
1312
+ return writer;
1313
+ },
1314
+ decode(input, length) {
1315
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
1316
+ const end = length === void 0 ? reader.len : reader.pos + length;
1317
+ const message = createBaseMsgDecideApplication();
1318
+ while (reader.pos < end) {
1319
+ const tag = reader.uint32();
1320
+ switch (tag >>> 3) {
1321
+ case 1: {
1322
+ if (tag !== 10) {
1323
+ break;
1324
+ }
1325
+ message.authority = reader.string();
1326
+ continue;
1327
+ }
1328
+ case 2: {
1329
+ if (tag !== 18) {
1330
+ break;
1331
+ }
1332
+ message.application_id = reader.string();
1333
+ continue;
1334
+ }
1335
+ case 3: {
1336
+ if (tag !== 24) {
1337
+ break;
1338
+ }
1339
+ message.approved = reader.bool();
1340
+ continue;
1341
+ }
1342
+ case 4: {
1343
+ if (tag !== 34) {
1344
+ break;
1345
+ }
1346
+ message.reason_code = reader.string();
1347
+ continue;
1348
+ }
1349
+ }
1350
+ if ((tag & 7) === 4 || tag === 0) {
1351
+ break;
1352
+ }
1353
+ reader.skip(tag & 7);
1354
+ }
1355
+ return message;
1356
+ },
1357
+ create(base) {
1358
+ return MsgDecideApplication.fromPartial(base ?? {});
1359
+ },
1360
+ fromPartial(object) {
1361
+ const message = createBaseMsgDecideApplication();
1362
+ message.authority = object.authority ?? "";
1363
+ message.application_id = object.application_id ?? "";
1364
+ message.approved = object.approved ?? false;
1365
+ message.reason_code = object.reason_code ?? "";
1366
+ return message;
1367
+ }
1368
+ };
1369
+ function createBaseMsgDecideRecoveryAttestation() {
1370
+ return { authority: "", recovery_case_id: "", approved: false, reason_code: "" };
1371
+ }
1372
+ var MsgDecideRecoveryAttestation = {
1373
+ encode(message, writer = new BinaryWriter()) {
1374
+ if (message.authority !== "") {
1375
+ writer.uint32(10).string(message.authority);
1376
+ }
1377
+ if (message.recovery_case_id !== "") {
1378
+ writer.uint32(18).string(message.recovery_case_id);
1379
+ }
1380
+ if (message.approved !== false) {
1381
+ writer.uint32(24).bool(message.approved);
1382
+ }
1383
+ if (message.reason_code !== "") {
1384
+ writer.uint32(34).string(message.reason_code);
1385
+ }
1386
+ return writer;
1387
+ },
1388
+ decode(input, length) {
1389
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
1390
+ const end = length === void 0 ? reader.len : reader.pos + length;
1391
+ const message = createBaseMsgDecideRecoveryAttestation();
1392
+ while (reader.pos < end) {
1393
+ const tag = reader.uint32();
1394
+ switch (tag >>> 3) {
1395
+ case 1: {
1396
+ if (tag !== 10) {
1397
+ break;
1398
+ }
1399
+ message.authority = reader.string();
1400
+ continue;
1401
+ }
1402
+ case 2: {
1403
+ if (tag !== 18) {
1404
+ break;
1405
+ }
1406
+ message.recovery_case_id = reader.string();
1407
+ continue;
1408
+ }
1409
+ case 3: {
1410
+ if (tag !== 24) {
1411
+ break;
1412
+ }
1413
+ message.approved = reader.bool();
1414
+ continue;
1415
+ }
1416
+ case 4: {
1417
+ if (tag !== 34) {
1418
+ break;
1419
+ }
1420
+ message.reason_code = reader.string();
1421
+ continue;
1422
+ }
1423
+ }
1424
+ if ((tag & 7) === 4 || tag === 0) {
1425
+ break;
1426
+ }
1427
+ reader.skip(tag & 7);
1428
+ }
1429
+ return message;
1430
+ },
1431
+ create(base) {
1432
+ return MsgDecideRecoveryAttestation.fromPartial(base ?? {});
1433
+ },
1434
+ fromPartial(object) {
1435
+ const message = createBaseMsgDecideRecoveryAttestation();
1436
+ message.authority = object.authority ?? "";
1437
+ message.recovery_case_id = object.recovery_case_id ?? "";
1438
+ message.approved = object.approved ?? false;
1439
+ message.reason_code = object.reason_code ?? "";
1440
+ return message;
1441
+ }
1442
+ };
1443
+ function toTimestamp2(date) {
1444
+ const seconds = BigInt(Math.trunc(date.getTime() / 1e3));
1445
+ const nanos = date.getTime() % 1e3 * 1e6;
1446
+ return { seconds, nanos };
1447
+ }
1448
+ function fromTimestamp2(t) {
1449
+ let millis = (globalThis.Number(t.seconds.toString()) || 0) * 1e3;
1450
+ millis += (t.nanos || 0) / 1e6;
1451
+ return new globalThis.Date(millis);
1452
+ }
1453
+ var ApplicationStatus = /* @__PURE__ */ ((ApplicationStatus2) => {
1454
+ ApplicationStatus2[ApplicationStatus2["APPLICATION_STATUS_UNSPECIFIED"] = 0] = "APPLICATION_STATUS_UNSPECIFIED";
1455
+ ApplicationStatus2[ApplicationStatus2["APPLICATION_STATUS_SUBMITTED"] = 1] = "APPLICATION_STATUS_SUBMITTED";
1456
+ ApplicationStatus2[ApplicationStatus2["APPLICATION_STATUS_PENDING_REVIEW"] = 2] = "APPLICATION_STATUS_PENDING_REVIEW";
1457
+ ApplicationStatus2[ApplicationStatus2["APPLICATION_STATUS_APPROVED"] = 3] = "APPLICATION_STATUS_APPROVED";
1458
+ ApplicationStatus2[ApplicationStatus2["APPLICATION_STATUS_REJECTED"] = 4] = "APPLICATION_STATUS_REJECTED";
1459
+ ApplicationStatus2[ApplicationStatus2["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
1460
+ return ApplicationStatus2;
1461
+ })(ApplicationStatus || {});
1462
+ var RecoveryAttestationStatus = /* @__PURE__ */ ((RecoveryAttestationStatus2) => {
1463
+ RecoveryAttestationStatus2[RecoveryAttestationStatus2["RECOVERY_ATTESTATION_STATUS_UNSPECIFIED"] = 0] = "RECOVERY_ATTESTATION_STATUS_UNSPECIFIED";
1464
+ RecoveryAttestationStatus2[RecoveryAttestationStatus2["RECOVERY_ATTESTATION_STATUS_SUBMITTED"] = 1] = "RECOVERY_ATTESTATION_STATUS_SUBMITTED";
1465
+ RecoveryAttestationStatus2[RecoveryAttestationStatus2["RECOVERY_ATTESTATION_STATUS_PENDING_REVIEW"] = 2] = "RECOVERY_ATTESTATION_STATUS_PENDING_REVIEW";
1466
+ RecoveryAttestationStatus2[RecoveryAttestationStatus2["RECOVERY_ATTESTATION_STATUS_APPROVED"] = 3] = "RECOVERY_ATTESTATION_STATUS_APPROVED";
1467
+ RecoveryAttestationStatus2[RecoveryAttestationStatus2["RECOVERY_ATTESTATION_STATUS_REJECTED"] = 4] = "RECOVERY_ATTESTATION_STATUS_REJECTED";
1468
+ RecoveryAttestationStatus2[RecoveryAttestationStatus2["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
1469
+ return RecoveryAttestationStatus2;
1470
+ })(RecoveryAttestationStatus || {});
1471
+
1472
+ // src/registry.ts
1473
+ function wrapMsgFns(msgFns) {
1474
+ return {
1475
+ encode: (message) => msgFns.encode(message),
1476
+ decode: (input) => msgFns.decode(input),
1477
+ fromPartial: (object) => msgFns.fromPartial(object)
1478
+ };
1479
+ }
1480
+ var COMPLIANCE_MSG_TYPES = [
1481
+ ["/isatheword.kingdomchain.compliance.v1.MsgRegisterProvider", wrapMsgFns(MsgRegisterProvider)],
1482
+ ["/isatheword.kingdomchain.compliance.v1.MsgSuspendProvider", wrapMsgFns(MsgSuspendProvider)],
1483
+ ["/isatheword.kingdomchain.compliance.v1.MsgSubmitApplication", wrapMsgFns(MsgSubmitApplication)],
1484
+ ["/isatheword.kingdomchain.compliance.v1.MsgSubmitRecoveryAttestation", wrapMsgFns(MsgSubmitRecoveryAttestation)],
1485
+ ["/isatheword.kingdomchain.compliance.v1.MsgDecideApplication", wrapMsgFns(MsgDecideApplication)],
1486
+ ["/isatheword.kingdomchain.compliance.v1.MsgDecideRecoveryAttestation", wrapMsgFns(MsgDecideRecoveryAttestation)]
1487
+ ];
1488
+ var CITIZEN_MSG_TYPES = [
1489
+ ["/isatheword.kingdomchain.citizen.v1.MsgIssueKCP", wrapMsgFns(MsgIssueKCP)],
1490
+ ["/isatheword.kingdomchain.citizen.v1.MsgSuspendKCP", wrapMsgFns(MsgSuspendKCP)],
1491
+ ["/isatheword.kingdomchain.citizen.v1.MsgReactivateKCP", wrapMsgFns(MsgReactivateKCP)],
1492
+ ["/isatheword.kingdomchain.citizen.v1.MsgRevokeKCP", wrapMsgFns(MsgRevokeKCP)],
1493
+ ["/isatheword.kingdomchain.citizen.v1.MsgInitiateRecovery", wrapMsgFns(MsgInitiateRecovery)],
1494
+ ["/isatheword.kingdomchain.citizen.v1.MsgApproveRecovery", wrapMsgFns(MsgApproveRecovery)],
1495
+ ["/isatheword.kingdomchain.citizen.v1.MsgFinalizeRecovery", wrapMsgFns(MsgFinalizeRecovery)],
1496
+ ["/isatheword.kingdomchain.citizen.v1.MsgCancelRecovery", wrapMsgFns(MsgCancelRecovery)]
1497
+ ];
1498
+ function createKingdomChainRegistry() {
1499
+ return new Registry([...defaultRegistryTypes, ...COMPLIANCE_MSG_TYPES, ...CITIZEN_MSG_TYPES]);
1500
+ }
1501
+
1502
+ // src/chainConstants.ts
1503
+ var UKDR_MINIMAL_DENOM = "ukdr";
1504
+ var UKDR_DISPLAY_DENOM = "KDR";
1505
+ var UKDR_DECIMALS = 6;
1506
+ var BECH32_PREFIX = "king";
1507
+ var CHAIN_COIN_TYPE = 118;
1508
+ var DEFAULT_CHAIN_ID = "kingdomchain-e2e";
1509
+ var DEFAULT_RPC_URL = "http://127.0.0.1:26657";
1510
+ var DEFAULT_REST_URL = "http://127.0.0.1:1317";
1511
+
1512
+ // src/browserSigner.ts
1513
+ var WalletNotInstalledError = class extends Error {
1514
+ constructor(walletName) {
1515
+ super(`${walletName} extension is not installed. Install it and refresh the page.`);
1516
+ this.walletName = walletName;
1517
+ this.name = "WalletNotInstalledError";
1518
+ }
1519
+ walletName;
1520
+ };
1521
+ var WalletConnectionError = class extends Error {
1522
+ constructor(walletName, step, cause) {
1523
+ const stepLabel = step === "suggestChain" ? "chain suggestion" : step === "enable" ? "connection request" : "offline signer retrieval";
1524
+ super(`${walletName} failed during ${stepLabel}.`, { cause });
1525
+ this.walletName = walletName;
1526
+ this.step = step;
1527
+ this.name = "WalletConnectionError";
1528
+ }
1529
+ walletName;
1530
+ step;
1531
+ };
1532
+ var WalletConnectionRejectedError = class extends WalletConnectionError {
1533
+ constructor(walletName, step, cause) {
1534
+ super(walletName, step, cause);
1535
+ this.name = "WalletConnectionRejectedError";
1536
+ }
1537
+ };
1538
+ var WalletAccountError = class extends Error {
1539
+ constructor(walletName) {
1540
+ super(`${walletName} returned no usable accounts. Reconnect the wallet and try again.`);
1541
+ this.walletName = walletName;
1542
+ this.name = "WalletAccountError";
1543
+ }
1544
+ walletName;
1545
+ };
1546
+ var InvalidChainConfigError = class extends Error {
1547
+ constructor(message) {
1548
+ super(message);
1549
+ this.name = "InvalidChainConfigError";
1550
+ }
1551
+ };
1552
+ var RpcConnectionError = class extends Error {
1553
+ constructor(rpcUrl, cause) {
1554
+ super(`Failed to connect to RPC endpoint ${rpcUrl}. Is the node running and reachable?`, { cause });
1555
+ this.rpcUrl = rpcUrl;
1556
+ this.name = "RpcConnectionError";
1557
+ }
1558
+ rpcUrl;
1559
+ };
1560
+ var UKDR_CURRENCY = {
1561
+ coinDenom: UKDR_DISPLAY_DENOM,
1562
+ coinMinimalDenom: UKDR_MINIMAL_DENOM,
1563
+ coinDecimals: UKDR_DECIMALS
1564
+ };
1565
+ var UKDR_FEE_CURRENCY = {
1566
+ ...UKDR_CURRENCY,
1567
+ gasPriceStep: { low: 0, average: 0, high: 0.025 }
1568
+ };
1569
+ function isWalletApiPresent(api) {
1570
+ if (api == null || typeof api !== "object") {
1571
+ return false;
1572
+ }
1573
+ const candidate = api;
1574
+ return typeof candidate.experimentalSuggestChain === "function" && typeof candidate.enable === "function" && typeof candidate.getOfflineSigner === "function";
1575
+ }
1576
+ function validateChainConfig(chainId, rpcUrl, restUrl) {
1577
+ if (!chainId.trim()) {
1578
+ throw new InvalidChainConfigError("chainId is required");
1579
+ }
1580
+ if (!rpcUrl.trim()) {
1581
+ throw new InvalidChainConfigError("rpcUrl is required");
1582
+ }
1583
+ if (!restUrl.trim()) {
1584
+ throw new InvalidChainConfigError("restUrl is required");
1585
+ }
1586
+ }
1587
+ function isKeplrAvailable() {
1588
+ return typeof window !== "undefined" && isWalletApiPresent(window.keplr);
1589
+ }
1590
+ function isLeapAvailable() {
1591
+ return typeof window !== "undefined" && isWalletApiPresent(window.leap);
1592
+ }
1593
+ function buildKingdomChainInfo(chainId, rpcUrl, restUrl, chainName = "Kingdom Chain") {
1594
+ validateChainConfig(chainId, rpcUrl, restUrl);
1595
+ const accPub = `${BECH32_PREFIX}pub`;
1596
+ const valAddr = `${BECH32_PREFIX}valoper`;
1597
+ const valPub = `${BECH32_PREFIX}valoperpub`;
1598
+ const consAddr = `${BECH32_PREFIX}valcons`;
1599
+ const consPub = `${BECH32_PREFIX}valconspub`;
1600
+ return {
1601
+ chainId,
1602
+ chainName,
1603
+ rpc: rpcUrl,
1604
+ rest: restUrl,
1605
+ bip44: { coinType: CHAIN_COIN_TYPE },
1606
+ bech32Config: {
1607
+ bech32PrefixAccAddr: BECH32_PREFIX,
1608
+ bech32PrefixAccPub: accPub,
1609
+ bech32PrefixValAddr: valAddr,
1610
+ bech32PrefixValPub: valPub,
1611
+ bech32PrefixConsAddr: consAddr,
1612
+ bech32PrefixConsPub: consPub
1613
+ },
1614
+ currencies: [UKDR_CURRENCY],
1615
+ feeCurrencies: [UKDR_FEE_CURRENCY],
1616
+ stakeCurrency: UKDR_CURRENCY
1617
+ };
1618
+ }
1619
+ async function assertSignerHasAccount(signer, walletName) {
1620
+ let accounts;
1621
+ try {
1622
+ accounts = await signer.getAccounts();
1623
+ } catch (err) {
1624
+ throw new WalletConnectionError(walletName, "getOfflineSigner", err);
1625
+ }
1626
+ if (accounts.length === 0 || !accounts[0]?.address?.trim()) {
1627
+ throw new WalletAccountError(walletName);
1628
+ }
1629
+ }
1630
+ async function suggestAndConnect(walletApi, chainInfo, walletName = "Wallet") {
1631
+ try {
1632
+ await walletApi.experimentalSuggestChain(chainInfo);
1633
+ } catch (err) {
1634
+ throw new WalletConnectionRejectedError(walletName, "suggestChain", err);
1635
+ }
1636
+ try {
1637
+ await walletApi.enable(chainInfo.chainId);
1638
+ } catch (err) {
1639
+ throw new WalletConnectionRejectedError(walletName, "enable", err);
1640
+ }
1641
+ let signer;
1642
+ try {
1643
+ signer = walletApi.getOfflineSigner(chainInfo.chainId);
1644
+ } catch (err) {
1645
+ throw new WalletConnectionError(walletName, "getOfflineSigner", err);
1646
+ }
1647
+ await assertSignerHasAccount(signer, walletName);
1648
+ return signer;
1649
+ }
1650
+ function resolveWalletApi(getter, walletName) {
1651
+ if (!isWalletApiPresent(getter())) {
1652
+ throw new WalletNotInstalledError(walletName);
1653
+ }
1654
+ const api = getter();
1655
+ if (!isWalletApiPresent(api)) {
1656
+ throw new WalletNotInstalledError(walletName);
1657
+ }
1658
+ return api;
1659
+ }
1660
+ async function connectKeplr(chainInfo) {
1661
+ const api = resolveWalletApi(() => window.keplr, "Keplr");
1662
+ return suggestAndConnect(api, chainInfo, "Keplr");
1663
+ }
1664
+ async function connectLeap(chainInfo) {
1665
+ const api = resolveWalletApi(() => window.leap, "Leap");
1666
+ return suggestAndConnect(api, chainInfo, "Leap");
1667
+ }
1668
+ async function createBrowserSigningClient(rpcUrl, signer) {
1669
+ if (!rpcUrl.trim()) {
1670
+ throw new InvalidChainConfigError("rpcUrl is required");
1671
+ }
1672
+ try {
1673
+ return await SigningStargateClient.connectWithSigner(rpcUrl, signer, {
1674
+ registry: createKingdomChainRegistry()
1675
+ });
1676
+ } catch (err) {
1677
+ throw new RpcConnectionError(rpcUrl, err);
1678
+ }
1679
+ }
1680
+
1681
+ // src/submitApplication.ts
1682
+ function buildSubmitApplicationMsg(applicantWallet, applicationId, attestationInput, signature) {
1683
+ return {
1684
+ typeUrl: "/isatheword.kingdomchain.compliance.v1.MsgSubmitApplication",
1685
+ value: MsgSubmitApplication.fromPartial({
1686
+ applicant_wallet: applicantWallet,
1687
+ application_id: applicationId,
1688
+ provider_id: attestationInput.providerId,
1689
+ provider_key_version: attestationInput.providerKeyVersion,
1690
+ chain_id: attestationInput.chainId,
1691
+ case_id: attestationInput.caseId,
1692
+ policy_version: attestationInput.policyVersion,
1693
+ nonce: attestationInput.nonce,
1694
+ uniqueness_reference: attestationInput.uniquenessReference,
1695
+ issued_at: attestationInput.issuedAt,
1696
+ expires_at: attestationInput.expiresAt,
1697
+ signature
1698
+ })
1699
+ };
1700
+ }
1701
+ async function signCitizenshipAttestation(params) {
1702
+ const input = {
1703
+ attestationType: ATTESTATION_TYPE_CITIZENSHIP_APPLICATION,
1704
+ chainId: params.chainId,
1705
+ intendedWallet: params.applicantWallet,
1706
+ caseId: params.applicationId,
1707
+ policyVersion: params.policyVersion,
1708
+ nonce: params.nonce,
1709
+ uniquenessReference: params.uniquenessReference,
1710
+ issuedAt: params.issuedAt,
1711
+ expiresAt: params.expiresAt,
1712
+ providerId: params.providerId,
1713
+ providerKeyVersion: params.providerKeyVersion ?? 1n
1714
+ };
1715
+ const payload = attestationSignPayload(input);
1716
+ const providerSeed = providerSeedFromHex(params.providerSeedHex);
1717
+ const signature = await signAttestationPayload(providerSeed, payload);
1718
+ return { signature, input };
1719
+ }
1720
+
1721
+ export { ATTESTATION_TYPE_CITIZENSHIP_APPLICATION, ATTESTATION_TYPE_RECOVERY, ApplicationStatus, BECH32_PREFIX, CHAIN_COIN_TYPE, DEFAULT_CHAIN_ID, DEFAULT_REST_URL, DEFAULT_RPC_URL, InvalidChainConfigError, MsgSubmitApplication, MsgSubmitRecoveryAttestation, RecoveryAttestationStatus, RpcConnectionError, UKDR_DECIMALS, UKDR_DISPLAY_DENOM, UKDR_MINIMAL_DENOM, WalletAccountError, WalletConnectionError, WalletConnectionRejectedError, WalletNotInstalledError, attestationSignPayload, buildKingdomChainInfo, buildSubmitApplicationMsg, connectKeplr, connectLeap, createBrowserSigningClient, createKingdomChainRegistry, isKeplrAvailable, isLeapAvailable, providerSeedFromHex, publicKeyFromPrivateSeed, signAttestationPayload, signCitizenshipAttestation, suggestAndConnect, validateChainConfig };
1722
+ //# sourceMappingURL=index.js.map
1723
+ //# sourceMappingURL=index.js.map