signify-ts 0.2.1 → 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 +187 -69
  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 -7842
  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 -7818
  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 -841
  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
@@ -1,326 +0,0 @@
1
- export enum Serials {
2
- JSON = 'JSON',
3
- }
4
-
5
- export enum Ident {
6
- KERI = 'KERI',
7
- ACDC = 'ACDC',
8
- }
9
-
10
- export class Version {
11
- public major: number;
12
- public minor: number;
13
-
14
- constructor(major: number = 1, minor: number = 0) {
15
- this.major = major;
16
- this.minor = minor;
17
- }
18
- }
19
-
20
- export const Versionage = new Version();
21
-
22
- export const Ilks = {
23
- icp: 'icp',
24
- rot: 'rot',
25
- ixn: 'ixn',
26
- dip: 'dip',
27
- drt: 'drt',
28
- rct: 'rct',
29
- vrc: 'vrc',
30
- rpy: 'rpy',
31
- exn: 'exn',
32
- vcp: 'vcp',
33
- iss: 'iss',
34
- rev: 'rev',
35
- };
36
-
37
- export const IcpLabels = [
38
- 'v',
39
- 'i',
40
- 's',
41
- 't',
42
- 'kt',
43
- 'k',
44
- 'n',
45
- 'bt',
46
- 'b',
47
- 'c',
48
- 'a',
49
- ];
50
-
51
- export const DipLabels = [
52
- 'v',
53
- 'i',
54
- 's',
55
- 't',
56
- 'kt',
57
- 'k',
58
- 'n',
59
- 'bt',
60
- 'b',
61
- 'c',
62
- 'a',
63
- 'di',
64
- ];
65
-
66
- export const RotLabels = [
67
- 'v',
68
- 'i',
69
- 's',
70
- 't',
71
- 'p',
72
- 'kt',
73
- 'k',
74
- 'n',
75
- 'bt',
76
- 'br',
77
- 'ba',
78
- 'a',
79
- ];
80
- export const DrtLabels = [
81
- 'v',
82
- 'i',
83
- 's',
84
- 't',
85
- 'p',
86
- 'kt',
87
- 'k',
88
- 'n',
89
- 'bt',
90
- 'br',
91
- 'ba',
92
- 'a',
93
- ];
94
- export const IxnLabels = ['v', 'i', 's', 't', 'p', 'a'];
95
-
96
- export const KsnLabels = [
97
- 'v',
98
- 'i',
99
- 's',
100
- 't',
101
- 'p',
102
- 'd',
103
- 'f',
104
- 'dt',
105
- 'et',
106
- 'kt',
107
- 'k',
108
- 'n',
109
- 'bt',
110
- 'b',
111
- 'c',
112
- 'ee',
113
- 'di',
114
- 'r',
115
- ];
116
-
117
- export const RpyLabels = ['v', 't', 'd', 'dt', 'r', 'a'];
118
-
119
- const encoder = new TextEncoder();
120
- const decoder = new TextDecoder();
121
-
122
- export const VERFULLSIZE = 17;
123
- export const MINSNIFFSIZE = 12 + VERFULLSIZE;
124
- export const MINSIGSIZE = 4;
125
-
126
- // const version_pattern = 'KERI(?P<major>[0-9a-f])(?P<minor>[0-9a-f])
127
- // (?P<kind>[A-Z]{4})(?P<size>[0-9a-f]{6})'
128
- // const version_pattern1 = `KERI\(\?P<major>\[0\-9a\-f\]\)\(\?P<minor>\[0\-9a\-f\]\)\
129
- // (\?P<kind>\[A\-Z\]\{4\}\)\(\?P<size>\[0\-9a\-f\]\{6\}\)_`
130
-
131
- export const VEREX = '(KERI|ACDC)([0-9a-f])([0-9a-f])([A-Z]{4})([0-9a-f]{6})_';
132
-
133
- export interface Dict<TValue> {
134
- [id: string]: TValue;
135
- }
136
-
137
- // Regex pattern matching
138
-
139
- /**
140
- * @description This function is use to deversify the version
141
- * Here we will use regex to to validate and extract serialization kind,size and version
142
- * @param {string} versionString version string
143
- * @return {Object} contaning prototol (KERI or ACDC), kind of serialization like cbor,json,mgpk
144
- * version = version of object ,size = raw size integer
145
- */
146
- export function deversify(
147
- versionString: string
148
- ): [Ident, Serials, Version, string] {
149
- let kind;
150
- let size;
151
- let proto;
152
- const version = Versionage;
153
-
154
- // we need to identify how to match the buffers pattern ,like we do regex matching for strings
155
- const re = new RegExp(VEREX);
156
-
157
- const match = re.exec(versionString);
158
-
159
- if (match) {
160
- [proto, version.major, version.minor, kind, size] = [
161
- match[1],
162
- +match[2],
163
- +match[3],
164
- match[4],
165
- match[5],
166
- ];
167
- if (!Object.values(Serials).includes(kind as Serials)) {
168
- throw new Error(`Invalid serialization kind = ${kind}`);
169
- }
170
- if (!Object.values(Ident).includes(proto as Ident)) {
171
- throw new Error(`Invalid serialization kind = ${kind}`);
172
- }
173
-
174
- const ta = kind as keyof typeof Serials;
175
- kind = Serials[ta];
176
- const pa = proto as keyof typeof Ident;
177
- proto = Ident[pa];
178
-
179
- return [proto, kind, version, size];
180
- }
181
- throw new Error(`Invalid version string = ${versionString}`);
182
- }
183
-
184
- export function versify(
185
- ident: Ident = Ident.KERI,
186
- version?: Version,
187
- kind: Serials = Serials.JSON,
188
- size: number = 0
189
- ) {
190
- version = version == undefined ? Versionage : version;
191
-
192
- return `${ident}${version.major.toString(
193
- 16
194
- )}${version.minor.toString()}${kind}${size.toString(16).padStart(6, '0')}_`;
195
- }
196
-
197
- export const B64ChrByIdx = new Map<number, string>([
198
- [0, 'A'],
199
- [1, 'B'],
200
- [2, 'C'],
201
- [3, 'D'],
202
- [4, 'E'],
203
- [5, 'F'],
204
- [6, 'G'],
205
- [7, 'H'],
206
- [8, 'I'],
207
- [9, 'J'],
208
- [10, 'K'],
209
- [11, 'L'],
210
- [12, 'M'],
211
- [13, 'N'],
212
- [14, 'O'],
213
- [15, 'P'],
214
- [16, 'Q'],
215
- [17, 'R'],
216
- [18, 'S'],
217
- [19, 'T'],
218
- [20, 'U'],
219
- [21, 'V'],
220
- [22, 'W'],
221
- [23, 'X'],
222
- [24, 'Y'],
223
- [25, 'Z'],
224
- [26, 'a'],
225
- [27, 'b'],
226
- [28, 'c'],
227
- [29, 'd'],
228
- [30, 'e'],
229
- [31, 'f'],
230
- [32, 'g'],
231
- [33, 'h'],
232
- [34, 'i'],
233
- [35, 'j'],
234
- [36, 'k'],
235
- [37, 'l'],
236
- [38, 'm'],
237
- [39, 'n'],
238
- [40, 'o'],
239
- [41, 'p'],
240
- [42, 'q'],
241
- [43, 'r'],
242
- [44, 's'],
243
- [45, 't'],
244
- [46, 'u'],
245
- [47, 'v'],
246
- [48, 'w'],
247
- [49, 'x'],
248
- [50, 'y'],
249
- [51, 'z'],
250
- [52, '0'],
251
- [53, '1'],
252
- [54, '2'],
253
- [55, '3'],
254
- [56, '4'],
255
- [57, '5'],
256
- [58, '6'],
257
- [59, '7'],
258
- [60, '8'],
259
- [61, '9'],
260
- [62, '-'],
261
- [63, '_'],
262
- ]);
263
-
264
- export const B64IdxByChr = new Map<string, number>(
265
- Array.from(B64ChrByIdx, (entry) => [entry[1], entry[0]])
266
- );
267
-
268
- export function intToB64(i: number, l = 1): string {
269
- let out = '';
270
- while (l != 0) {
271
- out = B64ChrByIdx.get(i % 64) + out;
272
- i = Math.floor(i / 64);
273
- if (i == 0) {
274
- break;
275
- }
276
- }
277
-
278
- const x = l - out.length;
279
- for (let i = 0; i < x; i++) {
280
- out = 'A' + out;
281
- }
282
-
283
- return out;
284
- }
285
-
286
- export function intToB64b(n: number, l: number = 1): Uint8Array {
287
- const s = intToB64(n, l);
288
- return b(s);
289
- }
290
-
291
- export function b64ToInt(s: string): number {
292
- if (s.length == 0) {
293
- throw new Error('Empty string, conversion undefined.');
294
- }
295
-
296
- let i = 0;
297
- const rev = s.split('').reverse();
298
- rev.forEach((c: string, e: number) => {
299
- i |= B64IdxByChr.get(c)! << (e * 6);
300
- });
301
-
302
- return i;
303
- }
304
-
305
- export function b(s?: string): Uint8Array {
306
- return encoder.encode(s);
307
- }
308
-
309
- export function d(u?: Uint8Array): string {
310
- return decoder.decode(u);
311
- }
312
-
313
- export function concat(one: Uint8Array, two: Uint8Array): Uint8Array {
314
- const out = new Uint8Array(one.length + two.length);
315
- out.set(one);
316
- out.set(two, one.length);
317
- return out;
318
- }
319
-
320
- export function readInt(array: Uint8Array) {
321
- let value = 0;
322
- for (let i = 0; i < array.length; i++) {
323
- value = value * 256 + array[i];
324
- }
325
- return value;
326
- }
@@ -1,273 +0,0 @@
1
- import { Codex, Sizage } from './matter';
2
- import { b, b64ToInt, d, intToB64 } from './core';
3
-
4
- export interface CounterArgs {
5
- code?: string;
6
- count?: number;
7
- countB64?: string;
8
- qb64b?: Uint8Array;
9
- qb64?: string;
10
- qb2?: Uint8Array;
11
- strip?: boolean;
12
- }
13
-
14
- export class CounterCodex extends Codex {
15
- public ControllerIdxSigs: string = '-A'; // Qualified Base64 Indexed Signature.
16
- public WitnessIdxSigs: string = '-B'; // Qualified Base64 Indexed Signature.
17
- public NonTransReceiptCouples: string = '-C'; // Composed Base64 Couple, pre+cig.
18
- public TransReceiptQuadruples: string = '-D'; // Composed Base64 Quadruple, pre+snu+dig+sig.
19
- public FirstSeenReplayCouples: string = '-E'; // Composed Base64 Couple, fnu+dts.
20
- public TransIdxSigGroups: string = '-F'; // Composed Base64 Group, pre+snu+dig+ControllerIdxSigs group.
21
- public SealSourceCouples: string = '-G'; // Composed Base64 couple, snu+dig of given delegators or issuers event
22
- public TransLastIdxSigGroups: string = '-H'; // Composed Base64 Group, pre+ControllerIdxSigs group.
23
- public SealSourceTriples: string = '-I'; // Composed Base64 triple, pre+snu+dig of anchoring source event
24
- public SadPathSig: string = '-J'; // Composed Base64 Group path+TransIdxSigGroup of SAID of content
25
- public SadPathSigGroup: string = '-K'; // Composed Base64 Group, root(path)+SaidPathCouples
26
- public PathedMaterialQuadlets: string = '-L'; // Composed Grouped Pathed Material Quadlet (4 char each)
27
- public AttachedMaterialQuadlets: string = '-V'; // Composed Grouped Attached Material Quadlet (4 char each)
28
- public BigAttachedMaterialQuadlets: string = '-0V'; // Composed Grouped Attached Material Quadlet (4 char each)
29
- public KERIProtocolStack: string = '--AAA'; // KERI ACDC Protocol Stack CESR Version
30
- }
31
-
32
- export const CtrDex = new CounterCodex();
33
-
34
- export class Counter {
35
- static Sizes = new Map(
36
- Object.entries({
37
- '-A': new Sizage(2, 2, 4, 0),
38
- '-B': new Sizage(2, 2, 4, 0),
39
- '-C': new Sizage(2, 2, 4, 0),
40
- '-D': new Sizage(2, 2, 4, 0),
41
- '-E': new Sizage(2, 2, 4, 0),
42
- '-F': new Sizage(2, 2, 4, 0),
43
- '-G': new Sizage(2, 2, 4, 0),
44
- '-H': new Sizage(2, 2, 4, 0),
45
- '-I': new Sizage(2, 2, 4, 0),
46
- '-J': new Sizage(2, 2, 4, 0),
47
- '-K': new Sizage(2, 2, 4, 0),
48
- '-L': new Sizage(2, 2, 4, 0),
49
- '-V': new Sizage(2, 2, 4, 0),
50
- '-0V': new Sizage(3, 5, 8, 0),
51
- '--AAA': new Sizage(5, 3, 8, 0),
52
- })
53
- );
54
-
55
- static Hards = new Map<string, number>([
56
- ['-A', 2],
57
- ['-B', 2],
58
- ['-C', 2],
59
- ['-D', 2],
60
- ['-E', 2],
61
- ['-F', 2],
62
- ['-G', 2],
63
- ['-H', 2],
64
- ['-I', 2],
65
- ['-J', 2],
66
- ['-K', 2],
67
- ['-L', 2],
68
- ['-M', 2],
69
- ['-N', 2],
70
- ['-O', 2],
71
- ['-P', 2],
72
- ['-Q', 2],
73
- ['-R', 2],
74
- ['-S', 2],
75
- ['-T', 2],
76
- ['-U', 2],
77
- ['-V', 2],
78
- ['-W', 2],
79
- ['-X', 2],
80
- ['-Y', 2],
81
- ['-Z', 2],
82
- ['-a', 2],
83
- ['-b', 2],
84
- ['-c', 2],
85
- ['-d', 2],
86
- ['-e', 2],
87
- ['-f', 2],
88
- ['-g', 2],
89
- ['-h', 2],
90
- ['-i', 2],
91
- ['-j', 2],
92
- ['-k', 2],
93
- ['-l', 2],
94
- ['-m', 2],
95
- ['-n', 2],
96
- ['-o', 2],
97
- ['-p', 2],
98
- ['-q', 2],
99
- ['-r', 2],
100
- ['-s', 2],
101
- ['-t', 2],
102
- ['-u', 2],
103
- ['-v', 2],
104
- ['-w', 2],
105
- ['-x', 2],
106
- ['-y', 2],
107
- ['-z', 2],
108
- ['-0', 3],
109
- ['--', 5],
110
- ]);
111
-
112
- private _code: string = '';
113
- private _count: number = -1;
114
-
115
- constructor({ code, count, countB64, qb64b, qb64, qb2 }: CounterArgs) {
116
- if (code != undefined) {
117
- if (!Counter.Sizes.has(code)) {
118
- throw new Error(`"Unsupported code=${code}.`);
119
- }
120
-
121
- const sizage = Counter.Sizes.get(code)!;
122
- const cs = sizage.hs + sizage.ss;
123
- if (sizage.fs != cs || cs % 4 != 0) {
124
- throw new Error(
125
- `Whole code size not full size or not multiple of 4. cs=${cs} fs=${sizage.fs}.`
126
- );
127
- }
128
-
129
- if (count == undefined) {
130
- count = countB64 == undefined ? 1 : b64ToInt(countB64);
131
- }
132
-
133
- if (count < 0 || count > 64 ** sizage.ss - 1) {
134
- throw new Error(`Invalid count=${count} for code=${code}.`);
135
- }
136
-
137
- this._code = code;
138
- this._count = count;
139
- } else if (qb64b != undefined) {
140
- const qb64 = d(qb64b);
141
- this._exfil(qb64);
142
- } else if (qb64 != undefined) {
143
- this._exfil(qb64);
144
- } else if (qb2 != undefined) {
145
- } else {
146
- throw new Error(
147
- `Improper initialization need either (code and count) or qb64b or qb64 or qb2.`
148
- );
149
- }
150
- }
151
-
152
- get code(): string {
153
- return this._code;
154
- }
155
-
156
- get count() {
157
- return this._count;
158
- }
159
-
160
- get qb64() {
161
- return this._infil();
162
- }
163
-
164
- get qb64b() {
165
- return b(this.qb64);
166
- }
167
-
168
- countToB64(l?: number): string {
169
- if (l == undefined) {
170
- const sizage = Counter.Sizes.get(this.code)!;
171
- l = sizage.ss;
172
- }
173
- return intToB64(this.count, l);
174
- }
175
-
176
- static semVerToB64(
177
- version: string = '',
178
- major: number = 0,
179
- minor: number = 0,
180
- patch: number = 0
181
- ): string {
182
- let parts = [major, minor, patch];
183
- if (version != '') {
184
- const ssplits = version.split('.');
185
- const splits = ssplits.map((x) => {
186
- if (x == '') return 0;
187
- return parseInt(x);
188
- });
189
-
190
- const off = splits.length;
191
- const x = 3 - off;
192
- for (let i = 0; i < x; i++) {
193
- splits.push(parts[i + off]);
194
- }
195
- parts = splits;
196
- }
197
-
198
- parts.forEach((p) => {
199
- if (p < 0 || p > 63) {
200
- throw new Error(
201
- `Out of bounds semantic version. Part=${p} is < 0 or > 63.`
202
- );
203
- }
204
- });
205
-
206
- return parts
207
- .map((p) => {
208
- return intToB64(p, 1);
209
- })
210
- .join('');
211
- }
212
-
213
- private _infil(): string {
214
- const code = this.code;
215
- const count = this.count;
216
-
217
- const sizage = Counter.Sizes.get(code)!;
218
- const cs = sizage.hs + sizage.ss;
219
- if (sizage.fs != cs || cs % 4 != 0) {
220
- throw new Error(
221
- `Whole code size not full size or not multiple of 4. cs=${cs} fs=${sizage.fs}.`
222
- );
223
- }
224
-
225
- if (count < 0 || count > 64 ** sizage.ss - 1) {
226
- throw new Error(`Invalid count=${count} for code=${code}.`);
227
- }
228
-
229
- const both = `${code}${intToB64(count, sizage.ss)}`;
230
-
231
- if (both.length % 4) {
232
- throw new Error(
233
- `Invalid size = ${both.length} of ${both} not a multiple of 4.`
234
- );
235
- }
236
-
237
- return both;
238
- }
239
-
240
- private _exfil(qb64: string) {
241
- if (qb64.length == 0) {
242
- throw new Error('Empty Material');
243
- }
244
-
245
- const first = qb64.slice(0, 2);
246
- if (!Counter.Hards.has(first)) {
247
- throw new Error(`Unexpected code ${first}`);
248
- }
249
-
250
- const hs = Counter.Hards.get(first)!;
251
- if (qb64.length < hs) {
252
- throw new Error(`Need ${hs - qb64.length} more characters.`);
253
- }
254
-
255
- const hard = qb64.slice(0, hs);
256
- if (!Counter.Sizes.has(hard)) {
257
- throw new Error(`Unsupported code ${hard}`);
258
- }
259
-
260
- const sizage = Counter.Sizes.get(hard)!;
261
- const cs = sizage!.hs + sizage!.ss;
262
-
263
- if (qb64.length < cs) {
264
- throw new Error(`Need ${cs - qb64.length} more chars.`);
265
- }
266
-
267
- const scount = qb64.slice(sizage.hs, sizage.hs + sizage.ss);
268
- const count = b64ToInt(scount);
269
-
270
- this._code = hard;
271
- this._count = count;
272
- }
273
- }