signify-ts 0.2.0 → 0.3.0-dev.e31e78d

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 (129) hide show
  1. package/README.md +104 -34
  2. package/dist/exports.d.ts +40 -40
  3. package/dist/exports.js +40 -0
  4. package/dist/index.d.ts +2 -3
  5. package/dist/index.js +3 -8
  6. package/dist/keri/app/aiding.d.ts +54 -18
  7. package/{src/keri/app/aiding.ts → dist/keri/app/aiding.js} +130 -236
  8. package/dist/keri/app/clienting.d.ts +59 -22
  9. package/{src/keri/app/clienting.ts → dist/keri/app/clienting.js} +146 -235
  10. package/dist/keri/app/contacting.d.ts +30 -23
  11. package/{src/keri/app/contacting.ts → dist/keri/app/contacting.js} +26 -63
  12. package/dist/keri/app/controller.d.ts +49 -6
  13. package/{src/keri/app/controller.ts → dist/keri/app/controller.js} +80 -186
  14. package/dist/keri/app/coring.d.ts +134 -25
  15. package/{src/keri/app/coring.ts → dist/keri/app/coring.js} +83 -56
  16. package/dist/keri/app/credentialing.d.ts +191 -67
  17. package/dist/keri/app/credentialing.js +540 -0
  18. package/dist/keri/app/delegating.d.ts +18 -0
  19. package/dist/keri/app/delegating.js +24 -0
  20. package/dist/keri/app/escrowing.d.ts +5 -3
  21. package/{src/keri/app/escrowing.ts → dist/keri/app/escrowing.js} +3 -9
  22. package/dist/keri/app/exchanging.d.ts +243 -11
  23. package/dist/keri/app/exchanging.js +242 -0
  24. package/dist/keri/app/grouping.d.ts +11 -9
  25. package/{src/keri/app/grouping.ts → dist/keri/app/grouping.js} +10 -29
  26. package/dist/keri/app/habery.d.ts +2 -2
  27. package/dist/keri/app/habery.js +117 -0
  28. package/dist/keri/app/notifying.d.ts +2 -2
  29. package/{src/keri/app/notifying.ts → dist/keri/app/notifying.js} +7 -17
  30. package/dist/keri/core/authing.d.ts +2 -2
  31. package/{src/keri/core/authing.ts → dist/keri/core/authing.js} +26 -42
  32. package/dist/keri/core/base64.d.ts +2 -0
  33. package/dist/keri/core/base64.js +16 -0
  34. package/dist/keri/core/bexter.d.ts +1 -1
  35. package/{src/keri/core/bexter.ts → dist/keri/core/bexter.js} +18 -32
  36. package/dist/keri/core/cigar.d.ts +2 -2
  37. package/dist/keri/core/cigar.js +13 -0
  38. package/dist/keri/core/cipher.d.ts +1 -1
  39. package/{src/keri/core/cipher.ts → dist/keri/core/cipher.js} +10 -19
  40. package/dist/keri/core/core.d.ts +117 -9
  41. package/dist/keri/core/core.js +385 -0
  42. package/dist/keri/core/counter.d.ts +2 -2
  43. package/dist/keri/core/counter.js +221 -0
  44. package/dist/keri/core/decrypter.d.ts +4 -4
  45. package/{src/keri/core/decrypter.ts → dist/keri/core/decrypter.js} +23 -40
  46. package/dist/keri/core/diger.d.ts +3 -3
  47. package/{src/keri/core/diger.ts → dist/keri/core/diger.js} +18 -33
  48. package/dist/keri/core/encrypter.d.ts +2 -2
  49. package/{src/keri/core/encrypter.ts → dist/keri/core/encrypter.js} +18 -38
  50. package/dist/keri/core/eventing.d.ts +6 -6
  51. package/dist/keri/core/eventing.js +383 -0
  52. package/dist/keri/core/httping.d.ts +11 -4
  53. package/{src/keri/core/httping.ts → dist/keri/core/httping.js} +36 -101
  54. package/dist/keri/core/indexer.d.ts +1 -1
  55. package/dist/keri/core/indexer.js +407 -0
  56. package/dist/keri/core/keeping.d.ts +113 -46
  57. package/dist/keri/core/keeping.js +347 -0
  58. package/{src/keri/core/kering.ts → dist/keri/core/kering.js} +1 -3
  59. package/dist/keri/core/keyState.d.ts +98 -0
  60. package/dist/keri/core/manager.d.ts +147 -12
  61. package/dist/keri/core/manager.js +880 -0
  62. package/dist/keri/core/matter.d.ts +1 -1
  63. package/dist/keri/core/matter.js +460 -0
  64. package/dist/keri/core/number.d.ts +2 -2
  65. package/{src/keri/core/number.ts → dist/keri/core/number.js} +26 -32
  66. package/dist/keri/core/pather.d.ts +2 -2
  67. package/{src/keri/core/pather.ts → dist/keri/core/pather.js} +12 -27
  68. package/dist/keri/core/prefixer.d.ts +10 -10
  69. package/dist/keri/core/prefixer.js +182 -0
  70. package/dist/keri/core/saider.d.ts +2 -12
  71. package/dist/keri/core/saider.js +107 -0
  72. package/dist/keri/core/salter.d.ts +44 -9
  73. package/dist/keri/core/salter.js +110 -0
  74. package/dist/keri/core/seqner.d.ts +1 -1
  75. package/{src/keri/core/seqner.ts → dist/keri/core/seqner.js} +20 -21
  76. package/dist/keri/core/serder.d.ts +25 -12
  77. package/dist/keri/core/serder.js +133 -0
  78. package/dist/keri/core/siger.d.ts +2 -2
  79. package/{src/keri/core/siger.ts → dist/keri/core/siger.js} +4 -14
  80. package/dist/keri/core/signer.d.ts +4 -4
  81. package/dist/keri/core/signer.js +84 -0
  82. package/{src/keri/core/tholder.ts → dist/keri/core/tholder.js} +69 -94
  83. package/dist/keri/core/utils.d.ts +1 -1
  84. package/{src/keri/core/utils.ts → dist/keri/core/utils.js} +30 -60
  85. package/dist/keri/core/vdring.d.ts +2 -2
  86. package/dist/keri/core/vdring.js +61 -0
  87. package/dist/keri/core/verfer.d.ts +2 -6
  88. package/dist/keri/core/verfer.js +37 -0
  89. package/dist/keri/end/ending.d.ts +10 -8
  90. package/dist/keri/end/ending.js +136 -0
  91. package/{src/ready.ts → dist/ready.js} +1 -2
  92. package/dist/types/keria-api-schema.d.ts +1158 -0
  93. package/dist/types/keria-api-schema.js +34 -0
  94. package/package.json +53 -52
  95. package/dist/math.d.ts +0 -1
  96. package/dist/signify-ts.cjs +0 -7835
  97. package/dist/signify-ts.cjs.development.js +0 -9501
  98. package/dist/signify-ts.cjs.development.js.map +0 -1
  99. package/dist/signify-ts.cjs.map +0 -7
  100. package/dist/signify-ts.cjs.production.min.js +0 -2
  101. package/dist/signify-ts.cjs.production.min.js.map +0 -1
  102. package/dist/signify-ts.esm.js +0 -9345
  103. package/dist/signify-ts.esm.js.map +0 -1
  104. package/dist/signify-ts.mjs +0 -7811
  105. package/dist/signify-ts.mjs.map +0 -7
  106. package/src/buffer-polyfill.ts +0 -5
  107. package/src/exports.ts +0 -44
  108. package/src/index.ts +0 -4
  109. package/src/keri/app/credentialing.ts +0 -820
  110. package/src/keri/app/exchanging.ts +0 -220
  111. package/src/keri/app/habery.ts +0 -185
  112. package/src/keri/core/cigar.ts +0 -18
  113. package/src/keri/core/core.ts +0 -326
  114. package/src/keri/core/counter.ts +0 -273
  115. package/src/keri/core/eventing.ts +0 -581
  116. package/src/keri/core/indexer.ts +0 -509
  117. package/src/keri/core/keeping.ts +0 -684
  118. package/src/keri/core/manager.ts +0 -1183
  119. package/src/keri/core/matter.ts +0 -521
  120. package/src/keri/core/prefixer.ts +0 -233
  121. package/src/keri/core/saider.ts +0 -186
  122. package/src/keri/core/salter.ts +0 -120
  123. package/src/keri/core/serder.ts +0 -163
  124. package/src/keri/core/signer.ts +0 -133
  125. package/src/keri/core/vdring.ts +0 -94
  126. package/src/keri/core/verfer.ts +0 -47
  127. package/src/keri/end/ending.ts +0 -170
  128. package/src/math.ts +0 -3
  129. /package/dist/{buffer-polyfill.d.ts → keri/core/keyState.js} +0 -0
@@ -0,0 +1,407 @@
1
+ import { EmptyMaterialError } from "./kering.js";
2
+ import { b, b64ToInt, d, intToB64, readInt } from "./core.js";
3
+ import { decodeBase64Url, encodeBase64Url } from "./base64.js";
4
+ export class IndexerCodex {
5
+ constructor() {
6
+ this.Ed25519_Sig = 'A'; // Ed25519 sig appears same in both lists if any.
7
+ this.Ed25519_Crt_Sig = 'B'; // Ed25519 sig appears in current list only.
8
+ this.ECDSA_256k1_Sig = 'C'; // ECDSA secp256k1 sig appears same in both lists if any.
9
+ this.ECDSA_256k1_Crt_Sig = 'D'; // ECDSA secp256k1 sig appears in current list.
10
+ this.ECDSA_256r1_Sig = 'E'; // ECDSA secp256r1 sig appears same in both lists if any.
11
+ this.ECDSA_256r1_Crt_Sig = 'F'; // ECDSA secp256r1 sig appears in current list.
12
+ this.Ed448_Sig = '0A'; // Ed448 signature appears in both lists.
13
+ this.Ed448_Crt_Sig = '0B'; // Ed448 signature appears in current list only.
14
+ this.Ed25519_Big_Sig = '2A'; // Ed25519 sig appears in both lists.
15
+ this.Ed25519_Big_Crt_Sig = '2B'; // Ed25519 sig appears in current list only.
16
+ this.ECDSA_256k1_Big_Sig = '2C'; // ECDSA secp256k1 sig appears in both lists.
17
+ this.ECDSA_256k1_Big_Crt_Sig = '2D'; // ECDSA secp256k1 sig appears in current list only.
18
+ this.ECDSA_256r1_Big_Sig = '2E'; // ECDSA secp256r1 sig appears in both lists.
19
+ this.ECDSA_256r1_Big_Crt_Sig = '2F'; // ECDSA secp256r1 sig appears in current list only.
20
+ this.Ed448_Big_Sig = '3A'; // Ed448 signature appears in both lists.
21
+ this.Ed448_Big_Crt_Sig = '3B'; // Ed448 signature appears in current list only.
22
+ }
23
+ }
24
+ export const IdrDex = new IndexerCodex();
25
+ export class IndexedSigCodex {
26
+ constructor() {
27
+ this.Ed25519_Sig = 'A'; // Ed25519 sig appears same in both lists if any.
28
+ this.Ed25519_Crt_Sig = 'B'; // Ed25519 sig appears in current list only.
29
+ this.ECDSA_256k1_Sig = 'C'; // ECDSA secp256k1 sig appears same in both lists if any.
30
+ this.ECDSA_256k1_Crt_Sig = 'D'; // ECDSA secp256k1 sig appears in current list.
31
+ this.ECDSA_256r1_Sig = 'E'; // ECDSA secp256r1 sig appears same in both lists if any.
32
+ this.ECDSA_256r1_Crt_Sig = 'F'; // ECDSA secp256r1 sig appears in current list.
33
+ this.Ed448_Sig = '0A'; // Ed448 signature appears in both lists.
34
+ this.Ed448_Crt_Sig = '0B'; // Ed448 signature appears in current list only.
35
+ this.Ed25519_Big_Sig = '2A'; // Ed25519 sig appears in both lists.
36
+ this.Ed25519_Big_Crt_Sig = '2B'; // Ed25519 sig appears in current list only.
37
+ this.ECDSA_256k1_Big_Sig = '2C'; // ECDSA secp256k1 sig appears in both lists.
38
+ this.ECDSA_256k1_Big_Crt_Sig = '2D'; // ECDSA secp256k1 sig appears in current list only.
39
+ this.ECDSA_256r1_Big_Sig = '2E'; // ECDSA secp256r1 sig appears in both lists.
40
+ this.ECDSA_256r1_Big_Crt_Sig = '2F'; // ECDSA secp256r1 sig appears in current list only.
41
+ this.Ed448_Big_Sig = '3A'; // Ed448 signature appears in both lists.
42
+ this.Ed448_Big_Crt_Sig = '3B'; // Ed448 signature appears in current list only.
43
+ }
44
+ has(prop) {
45
+ const m = new Map(Array.from(Object.entries(this), (v) => [v[1], v[0]]));
46
+ return m.has(prop);
47
+ }
48
+ }
49
+ export const IdxSigDex = new IndexedSigCodex();
50
+ export class IndexedCurrentSigCodex {
51
+ constructor() {
52
+ this.Ed25519_Crt_Sig = 'B'; // Ed25519 sig appears in current list only.
53
+ this.ECDSA_256k1_Crt_Sig = 'D'; // ECDSA secp256k1 sig appears in current list only.
54
+ this.ECDSA_256r1_Crt_Sig = 'F'; // ECDSA secp256r1 sig appears in current list.
55
+ this.Ed448_Crt_Sig = '0B'; // Ed448 signature appears in current list only.
56
+ this.Ed25519_Big_Crt_Sig = '2B'; // Ed25519 sig appears in current list only.
57
+ this.ECDSA_256k1_Big_Crt_Sig = '2D'; // ECDSA secp256k1 sig appears in current list only.
58
+ this.ECDSA_256r1_Big_Crt_Sig = '2F'; // ECDSA secp256r1 sig appears in current list only.
59
+ this.Ed448_Big_Crt_Sig = '3B'; // Ed448 signature appears in current list only.
60
+ }
61
+ has(prop) {
62
+ const m = new Map(Array.from(Object.entries(this), (v) => [v[1], v[0]]));
63
+ return m.has(prop);
64
+ }
65
+ }
66
+ export const IdxCrtSigDex = new IndexedCurrentSigCodex();
67
+ export class IndexedBothSigCodex {
68
+ constructor() {
69
+ this.Ed25519_Sig = 'A'; // Ed25519 sig appears same in both lists if any.
70
+ this.ECDSA_256k1_Sig = 'C'; // ECDSA secp256k1 sig appears same in both lists if any.
71
+ this.Ed448_Sig = '0A'; // Ed448 signature appears in both lists.
72
+ this.Ed25519_Big_Sig = '2A'; // Ed25519 sig appears in both listsy.
73
+ this.ECDSA_256k1_Big_Sig = '2C'; // ECDSA secp256k1 sig appears in both lists.
74
+ this.Ed448_Big_Sig = '3A'; // Ed448 signature appears in both lists.
75
+ }
76
+ has(prop) {
77
+ const m = new Map(Array.from(Object.entries(this), (v) => [v[1], v[0]]));
78
+ return m.has(prop);
79
+ }
80
+ }
81
+ export const IdxBthSigDex = new IndexedBothSigCodex();
82
+ export class Xizage {
83
+ constructor(hs, ss, os, fs, ls) {
84
+ this.hs = hs;
85
+ this.ss = ss;
86
+ this.os = os;
87
+ this.fs = fs;
88
+ this.ls = ls;
89
+ }
90
+ }
91
+ export class Indexer {
92
+ constructor({ raw = undefined, code = IdrDex.Ed25519_Sig, index = 0, ondex = undefined, qb64b = undefined, qb64 = undefined, qb2 = undefined, }) {
93
+ this.Codex = IdrDex;
94
+ this._code = '';
95
+ this._index = -1;
96
+ this._raw = new Uint8Array(0);
97
+ if (raw != undefined) {
98
+ if (code == undefined) {
99
+ throw new EmptyMaterialError(`Improper initialization need either (raw and code) or qb64b or qb64 or qb2.`);
100
+ }
101
+ if (!Indexer.Sizes.has(code)) {
102
+ throw new Error(`Unsupported code=${code}.`);
103
+ }
104
+ const xizage = Indexer.Sizes.get(code);
105
+ const os = xizage.os;
106
+ const fs = xizage.fs;
107
+ const cs = xizage.hs + xizage.ss;
108
+ const ms = xizage.ss - xizage.os;
109
+ if (!Number.isInteger(index) || index < 0 || index > 64 ** ms - 1) {
110
+ throw new Error(`Invalid index=${index} for code=${code}.`);
111
+ }
112
+ if (ondex != undefined &&
113
+ xizage.os != 0 &&
114
+ !(ondex >= 0 && ondex <= 64 ** os - 1)) {
115
+ throw new Error(`Invalid ondex=${ondex} for code=${code}.`);
116
+ }
117
+ if (IdxCrtSigDex.has(code) && ondex != undefined) {
118
+ throw new Error(`Non None ondex=${ondex} for code=${code}.`);
119
+ }
120
+ if (IdxBthSigDex.has(code)) {
121
+ if (ondex == undefined) {
122
+ ondex = index;
123
+ }
124
+ else {
125
+ if (ondex != index && os == 0) {
126
+ throw new Error(`Non matching ondex=${ondex} and index=${index} for code=${code}.`);
127
+ }
128
+ }
129
+ }
130
+ if (fs == undefined) {
131
+ throw new Error('variable length unsupported');
132
+ }
133
+ // TODO: Don't support this code
134
+ // if not fs: # compute fs from index
135
+ // if cs % 4:
136
+ // raise InvalidCodeSizeError(f"Whole code size not multiple of 4 for "
137
+ // f"variable length material. cs={cs}.")
138
+ // if os != 0:
139
+ // raise InvalidCodeSizeError(f"Non-zero other index size for "
140
+ // f"variable length material. os={os}.")
141
+ // fs = (index * 4) + cs
142
+ const rawsize = Math.floor(((fs - cs) * 3) / 4);
143
+ raw = raw.slice(0, rawsize);
144
+ if (raw.length != rawsize) {
145
+ throw new Error(`Not enougth raw bytes for code=${code} and index=${index} ,expected ${rawsize} got ${raw.length}.`);
146
+ }
147
+ this._code = code;
148
+ this._index = index;
149
+ this._ondex = ondex;
150
+ this._raw = raw;
151
+ }
152
+ else if (qb64b != undefined) {
153
+ const qb64 = d(qb64b);
154
+ this._exfil(qb64);
155
+ }
156
+ else if (qb64 != undefined) {
157
+ this._exfil(qb64);
158
+ }
159
+ else if (qb2 != undefined) {
160
+ this._bexfil(qb2);
161
+ }
162
+ else {
163
+ throw new EmptyMaterialError(`Improper initialization need either (raw and code and index) or qb64b or qb64 or qb2.`);
164
+ }
165
+ }
166
+ _bexfil(qb2) {
167
+ throw new Error(`qb2 not yet supported: ${qb2}`);
168
+ }
169
+ static _rawSize(code) {
170
+ const xizage = Indexer.Sizes.get(code);
171
+ return Math.floor(xizage.fs - ((xizage.hs + xizage.ss) * 3) / 4);
172
+ }
173
+ get code() {
174
+ return this._code;
175
+ }
176
+ get raw() {
177
+ return this._raw;
178
+ }
179
+ get index() {
180
+ return this._index;
181
+ }
182
+ get ondex() {
183
+ return this._ondex;
184
+ }
185
+ get qb64() {
186
+ return this._infil();
187
+ }
188
+ get qb64b() {
189
+ return b(this.qb64);
190
+ }
191
+ _infil() {
192
+ const code = this.code;
193
+ const index = this.index;
194
+ const ondex = this.ondex;
195
+ const raw = this.raw;
196
+ const ps = (3 - (raw.length % 3)) % 3;
197
+ const xizage = Indexer.Sizes.get(code);
198
+ const cs = xizage.hs + xizage.ss;
199
+ const ms = xizage.ss - xizage.os;
200
+ // TODO: don't support this code
201
+ // if not fs: # compute fs from index
202
+ // if cs % 4:
203
+ // raise InvalidCodeSizeError(f"Whole code size not multiple of 4 for "
204
+ // f"variable length material. cs={cs}.")
205
+ // if os != 0:
206
+ // raise InvalidCodeSizeError(f"Non-zero other index size for "
207
+ // f"variable length material. os={os}.")
208
+ // fs = (index * 4) + cs
209
+ if (index < 0 || index > 64 ** ms - 1) {
210
+ throw new Error(`Invalid index=${index} for code=${code}.`);
211
+ }
212
+ if (ondex != undefined &&
213
+ xizage.os != 0 &&
214
+ !(ondex >= 0 && ondex <= 64 ** xizage.os - 1)) {
215
+ throw new Error(`Invalid ondex=${ondex} for os=${xizage.os} and code=${code}.`);
216
+ }
217
+ const both = `${code}${intToB64(index, ms)}${intToB64(ondex == undefined ? 0 : ondex, xizage.os)}`;
218
+ if (both.length != cs) {
219
+ throw new Error(`Mismatch code size = ${cs} with table = ${both.length}.`);
220
+ }
221
+ if (cs % 4 != ps - xizage.ls) {
222
+ throw new Error(`Invalid code=${both} for converted raw pad size=${ps}.`);
223
+ }
224
+ const bytes = new Uint8Array(ps + raw.length);
225
+ for (let i = 0; i < ps; i++) {
226
+ bytes[i] = 0;
227
+ }
228
+ for (let i = 0; i < raw.length; i++) {
229
+ const odx = i + ps;
230
+ bytes[odx] = raw[i];
231
+ }
232
+ const full = both + encodeBase64Url(bytes).slice(ps - xizage.ls);
233
+ if (full.length != xizage.fs) {
234
+ throw new Error(`Invalid code=${both} for raw size=${raw.length}.`);
235
+ }
236
+ return full;
237
+ }
238
+ _exfil(qb64) {
239
+ if (qb64.length == 0) {
240
+ throw new Error('Empty Material');
241
+ }
242
+ const first = qb64[0];
243
+ if (!Array.from(Indexer.Hards.keys()).includes(first)) {
244
+ throw new Error(`Unexpected code ${first}`);
245
+ }
246
+ const hs = Indexer.Hards.get(first);
247
+ if (qb64.length < hs) {
248
+ throw new Error(`Need ${hs - qb64.length} more characters.`);
249
+ }
250
+ const hard = qb64.slice(0, hs);
251
+ if (!Array.from(Indexer.Sizes.keys()).includes(hard)) {
252
+ throw new Error(`Unsupported code ${hard}`);
253
+ }
254
+ const xizage = Indexer.Sizes.get(hard);
255
+ const cs = xizage.hs + xizage.ss; // both hard + soft code size
256
+ const ms = xizage.ss - xizage.os;
257
+ if (qb64.length < cs) {
258
+ throw new Error(`Need ${cs - qb64.length} more characters.`);
259
+ }
260
+ const sindex = qb64.slice(hs, hs + ms);
261
+ const index = b64ToInt(sindex);
262
+ const sondex = qb64.slice(hs + ms, hs + ms + xizage.os);
263
+ let ondex;
264
+ if (IdxCrtSigDex.has(hard)) {
265
+ ondex = xizage.os != 0 ? b64ToInt(sondex) : undefined;
266
+ if (ondex != 0 && ondex != undefined) {
267
+ throw new Error(`Invalid ondex=${ondex} for code=${hard}.`);
268
+ }
269
+ else {
270
+ ondex = undefined;
271
+ }
272
+ }
273
+ else {
274
+ ondex = xizage.os != 0 ? b64ToInt(sondex) : index;
275
+ }
276
+ if (xizage.fs == undefined) {
277
+ throw new Error('variable length not supported');
278
+ }
279
+ // TODO: support variable length
280
+ // if not fs: # compute fs from index which means variable length
281
+ // if cs % 4:
282
+ // raise ValidationError(f"Whole code size not multiple of 4 for "
283
+ // f"variable length material. cs={cs}.")
284
+ // if os != 0:
285
+ // raise ValidationError(f"Non-zero other index size for "
286
+ // f"variable length material. os={os}.")
287
+ // fs = (index * 4) + cs
288
+ if (qb64.length < xizage.fs) {
289
+ throw new Error(`Need ${xizage.fs - qb64.length} more chars.`);
290
+ }
291
+ qb64 = qb64.slice(0, xizage.fs);
292
+ const ps = cs % 4;
293
+ const pbs = 2 * ps != 0 ? ps : xizage.ls;
294
+ let raw;
295
+ if (ps != 0) {
296
+ const base = new Array(ps + 1).join('A') + qb64.slice(cs);
297
+ const paw = decodeBase64Url(base); // decode base to leave prepadded raw
298
+ const pi = readInt(paw.slice(0, ps)); // prepad as int
299
+ if (pi & (2 ** pbs - 1)) {
300
+ // masked pad bits non-zero
301
+ throw new Error(`Non zeroed prepad bits = {pi & (2 ** pbs - 1 ):<06b} in {qb64b[cs:cs+1]}.`);
302
+ }
303
+ raw = paw.slice(ps); // strip off ps prepad paw bytes
304
+ }
305
+ else {
306
+ const base = qb64.slice(cs);
307
+ const paw = decodeBase64Url(base);
308
+ const li = readInt(paw.slice(0, xizage.ls));
309
+ if (li != 0) {
310
+ if (li == 1) {
311
+ throw new Error(`Non zeroed lead byte = 0x{li:02x}.`);
312
+ }
313
+ else {
314
+ throw new Error(`Non zeroed lead bytes = 0x{li:04x}`);
315
+ }
316
+ }
317
+ raw = paw.slice(xizage.ls);
318
+ }
319
+ if (raw.length != Math.floor(((qb64.length - cs) * 3) / 4)) {
320
+ throw new Error(`Improperly qualified material = ${qb64}`);
321
+ }
322
+ this._code = hard;
323
+ this._index = index;
324
+ this._ondex = ondex;
325
+ this._raw = new Uint8Array(raw); // must be bytes for crpto opts and immutable not bytearray
326
+ }
327
+ }
328
+ Indexer.Hards = new Map([
329
+ ['A', 1],
330
+ ['B', 1],
331
+ ['C', 1],
332
+ ['D', 1],
333
+ ['E', 1],
334
+ ['F', 1],
335
+ ['G', 1],
336
+ ['H', 1],
337
+ ['I', 1],
338
+ ['J', 1],
339
+ ['K', 1],
340
+ ['L', 1],
341
+ ['M', 1],
342
+ ['N', 1],
343
+ ['O', 1],
344
+ ['P', 1],
345
+ ['Q', 1],
346
+ ['R', 1],
347
+ ['S', 1],
348
+ ['T', 1],
349
+ ['U', 1],
350
+ ['V', 1],
351
+ ['W', 1],
352
+ ['X', 1],
353
+ ['Y', 1],
354
+ ['Z', 1],
355
+ ['a', 1],
356
+ ['b', 1],
357
+ ['c', 1],
358
+ ['d', 1],
359
+ ['e', 1],
360
+ ['f', 1],
361
+ ['g', 1],
362
+ ['h', 1],
363
+ ['i', 1],
364
+ ['j', 1],
365
+ ['k', 1],
366
+ ['l', 1],
367
+ ['m', 1],
368
+ ['n', 1],
369
+ ['o', 1],
370
+ ['p', 1],
371
+ ['q', 1],
372
+ ['r', 1],
373
+ ['s', 1],
374
+ ['t', 1],
375
+ ['u', 1],
376
+ ['v', 1],
377
+ ['w', 1],
378
+ ['x', 1],
379
+ ['y', 1],
380
+ ['z', 1],
381
+ ['0', 2],
382
+ ['1', 2],
383
+ ['2', 2],
384
+ ['3', 2],
385
+ ['4', 2],
386
+ ]);
387
+ Indexer.Sizes = new Map(Object.entries({
388
+ A: new Xizage(1, 1, 0, 88, 0),
389
+ B: new Xizage(1, 1, 0, 88, 0),
390
+ C: new Xizage(1, 1, 0, 88, 0),
391
+ D: new Xizage(1, 1, 0, 88, 0),
392
+ E: new Xizage(1, 1, 0, 88, 0),
393
+ F: new Xizage(1, 1, 0, 88, 0),
394
+ '0A': new Xizage(2, 2, 1, 156, 0),
395
+ '0B': new Xizage(2, 2, 1, 156, 0),
396
+ '2A': new Xizage(2, 4, 2, 92, 0),
397
+ '2B': new Xizage(2, 4, 2, 92, 0),
398
+ '2C': new Xizage(2, 4, 2, 92, 0),
399
+ '2D': new Xizage(2, 4, 2, 92, 0),
400
+ '2E': new Xizage(2, 4, 2, 92, 0),
401
+ '2F': new Xizage(2, 4, 2, 92, 0),
402
+ '3A': new Xizage(2, 6, 3, 160, 0),
403
+ '3B': new Xizage(2, 6, 3, 160, 0),
404
+ '0z': new Xizage(2, 2, 0, undefined, 0),
405
+ '1z': new Xizage(2, 2, 1, 76, 1),
406
+ '4z': new Xizage(2, 6, 3, 80, 1),
407
+ }));
@@ -1,24 +1,82 @@
1
- import { Salter } from './salter';
2
- import { Algos } from './manager';
3
- import { Tier } from './salter';
4
- import { Signer } from './signer';
5
- import { Siger } from './siger';
6
- import { Cigar } from './cigar';
7
- export {};
1
+ import { Salter } from './salter.ts';
2
+ import { Algos } from './manager.ts';
3
+ import { Tier } from './salter.ts';
4
+ import { Signer } from './signer.ts';
5
+ import { HabState, KeyState } from './keyState.ts';
8
6
  /** External module definition */
7
+ export interface ExternalModuleType {
8
+ new (pidx: number, args: IdentifierManagerParams): IdentifierManager;
9
+ }
9
10
  export interface ExternalModule {
10
11
  type: string;
11
12
  name: string;
12
- module: any;
13
+ module: ExternalModuleType;
14
+ }
15
+ export type IdentifierManagerResult = [string[], string[]];
16
+ export type SignResult = string[];
17
+ export interface IdentifierManagerParams {
18
+ [key: string]: unknown;
19
+ }
20
+ export interface SaltyManagerParams extends IdentifierManagerParams {
21
+ pidx: number;
22
+ kidx: number;
23
+ tier: Tier;
24
+ transferable: boolean;
25
+ stem: string | undefined;
26
+ icodes: string[] | undefined;
27
+ ncodes: string[] | undefined;
28
+ dcode: string | undefined;
29
+ sxlt: string | undefined;
30
+ }
31
+ export interface RandyManagerParams extends IdentifierManagerParams {
32
+ nxts?: string[];
33
+ prxs?: string[];
34
+ transferable: boolean;
13
35
  }
14
- export declare class KeyManager {
15
- private salter?;
16
- private modules?;
36
+ export interface GroupManagerParams extends IdentifierManagerParams {
37
+ mhab: HabState;
38
+ }
39
+ /**
40
+ * Interface for KERI identifier (prefix) creation, rotation, and signing.
41
+ * @param T Type of the key keeper
42
+ */
43
+ export interface IdentifierManager<T extends IdentifierManagerParams = IdentifierManagerParams> {
44
+ algo: Algos;
45
+ signers: Signer[];
46
+ params(): T;
47
+ incept(transferable: boolean): Promise<IdentifierManagerResult>;
48
+ rotate(ncodes: string[], transferable: boolean, states?: KeyState[], rstates?: KeyState[]): Promise<IdentifierManagerResult>;
49
+ sign(ser: Uint8Array, indexed?: boolean, indices?: number[], ondices?: number[]): Promise<SignResult>;
50
+ }
51
+ /**
52
+ * Creates IdentifierManager instances based on the algorithm and key indexes.
53
+ */
54
+ export declare class IdentifierManagerFactory {
55
+ private salter;
56
+ private modules;
57
+ /**
58
+ * Creates a factory for generating IdentifierManagers. Requires a salt to be specified.
59
+ * Allows external key management modules to be configured.
60
+ * @param salter
61
+ * @param externalModules
62
+ */
17
63
  constructor(salter: Salter, externalModules?: ExternalModule[]);
18
- new(algo: Algos, pidx: number, kargs: any): any;
19
- get(aid: any): any;
64
+ /**
65
+ *
66
+ * @param algo
67
+ * @param pidx
68
+ * @param kargs
69
+ */
70
+ new(algo: Algos, pidx: number, kargs: any): IdentifierManager<IdentifierManagerParams> | GroupIdentifierManager;
71
+ /**
72
+ * Generates an algorithm-specific IdentifierManager instance with correct keys based on
73
+ * the indexes provided by the HabState.
74
+ * @param aid HabState with the algorithm and key indexes
75
+ * @returns IdentifierManager instance
76
+ */
77
+ get(aid: HabState): IdentifierManager;
20
78
  }
21
- export declare class SaltyKeeper {
79
+ export declare class SaltyIdentifierManager implements IdentifierManager {
22
80
  private aeid;
23
81
  private encrypter;
24
82
  private decrypter;
@@ -40,23 +98,13 @@ export declare class SaltyKeeper {
40
98
  private creator;
41
99
  algo: Algos;
42
100
  signers: Signer[];
43
- constructor(salter: Salter, pidx: number, kidx?: number, tier?: Tier, transferable?: boolean, stem?: undefined, code?: string, count?: number, icodes?: string[] | undefined, ncode?: string, ncount?: number, ncodes?: string[] | undefined, dcode?: string, bran?: string | undefined, sxlt?: undefined);
44
- params(): {
45
- sxlt: string | undefined;
46
- pidx: number;
47
- kidx: number;
48
- stem: string | undefined;
49
- tier: Tier;
50
- icodes: string[] | undefined;
51
- ncodes: string[] | undefined;
52
- dcode: string | undefined;
53
- transferable: boolean;
54
- };
55
- incept(transferable: boolean): string[][];
56
- rotate(ncodes: string[], transferable: boolean, ..._: any[]): string[][];
57
- sign(ser: Uint8Array, indexed?: boolean, indices?: number[] | undefined, ondices?: number[] | undefined): string[];
101
+ constructor(salter: Salter, pidx: number, kidx?: number, tier?: Tier, transferable?: boolean, stem?: string | undefined, code?: string, count?: number, icodes?: string[] | undefined, ncode?: string, ncount?: number, ncodes?: string[] | undefined, dcode?: string, bran?: string | undefined, sxlt?: string | undefined);
102
+ params(): SaltyManagerParams;
103
+ incept(transferable: boolean): Promise<IdentifierManagerResult>;
104
+ rotate(ncodes: string[], transferable: boolean): Promise<[string[], string[]]>;
105
+ sign(ser: Uint8Array, indexed?: boolean, indices?: number[] | undefined, ondices?: number[] | undefined): Promise<SignResult>;
58
106
  }
59
- export declare class RandyKeeper {
107
+ export declare class RandyIdentifierManager implements IdentifierManager {
60
108
  private salter;
61
109
  private code;
62
110
  private count;
@@ -75,29 +123,48 @@ export declare class RandyKeeper {
75
123
  algo: Algos;
76
124
  signers: Signer[];
77
125
  constructor(salter: Salter, code: string | undefined, count: number | undefined, icodes: string[] | undefined, transferable: boolean | undefined, ncode: string | undefined, ncount: number | undefined, ncodes: string[], dcode?: string, prxs?: string[] | undefined, nxts?: string[] | undefined);
78
- params(): {
79
- nxts: string[] | undefined;
80
- prxs: string[] | undefined;
81
- transferable: boolean;
82
- };
83
- incept(transferable: boolean): string[][];
84
- rotate(ncodes: string[], transferable: boolean, ..._: any[]): any[][];
85
- sign(ser: Uint8Array, indexed?: boolean, indices?: number[] | undefined, ondices?: number[] | undefined): any[];
126
+ params(): RandyManagerParams;
127
+ incept(transferable: boolean): Promise<IdentifierManagerResult>;
128
+ rotate(ncodes: string[], transferable: boolean): Promise<IdentifierManagerResult>;
129
+ sign(ser: Uint8Array, indexed?: boolean, indices?: number[] | undefined, ondices?: number[] | undefined): Promise<SignResult>;
86
130
  }
87
- export declare class GroupKeeper {
131
+ export declare class GroupIdentifierManager implements IdentifierManager {
88
132
  private manager;
89
133
  private mhab;
90
134
  private gkeys;
91
135
  private gdigs;
92
136
  algo: Algos;
93
137
  signers: Signer[];
94
- constructor(manager: KeyManager, mhab?: undefined, states?: any[] | undefined, rstates?: any[] | undefined, keys?: any[] | undefined, ndigs?: any[] | undefined);
95
- incept(..._: any): (string[] | undefined)[];
96
- rotate(_ncodes: string[], _transferable: boolean, states: any[], rstates: any[], ..._: any): string[][];
97
- sign(ser: Uint8Array, indexed?: boolean, _indices?: number[] | undefined, _ondices?: number[] | undefined): Promise<Siger[] | Cigar[]>;
138
+ constructor(manager: IdentifierManagerFactory, mhab: HabState, states?: KeyState[] | undefined, rstates?: KeyState[] | undefined, keys?: string[], ndigs?: string[]);
139
+ incept(): Promise<IdentifierManagerResult>;
140
+ /**
141
+ * Performs a multisig rotation
142
+ * @param _ncodes
143
+ * @param _transferable
144
+ * @param states
145
+ * @param rstates key state records for the prior establishment event indicating next key digests.
146
+ * You should pass in the current key
147
+ */
148
+ rotate(_ncodes: string[], _transferable: boolean, states: KeyState[], rstates: KeyState[]): Promise<IdentifierManagerResult>;
149
+ sign(ser: Uint8Array, indexed?: boolean): Promise<SignResult>;
98
150
  params(): {
99
- mhab: any;
100
- keys: string[] | undefined;
101
- ndigs: string[] | undefined;
151
+ mhab: {
152
+ name: string;
153
+ prefix: string;
154
+ icp_dt: string;
155
+ state: import("../../types/keria-api-schema.ts").components["schemas"]["KeyStateRecord"];
156
+ transferable: boolean;
157
+ windexes: string[];
158
+ } & ({
159
+ salty: import("../../types/keria-api-schema.ts").components["schemas"]["SaltyState"];
160
+ } | {
161
+ randy: import("../../types/keria-api-schema.ts").components["schemas"]["RandyKeyState"];
162
+ } | {
163
+ group: import("../../types/keria-api-schema.ts").components["schemas"]["GroupKeyState"];
164
+ } | {
165
+ extern: import("../../types/keria-api-schema.ts").components["schemas"]["ExternState"];
166
+ });
167
+ keys: string[];
168
+ ndigs: string[];
102
169
  };
103
170
  }