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
@@ -103,7 +103,7 @@ export declare class Matter {
103
103
  get size(): number;
104
104
  get raw(): Uint8Array;
105
105
  get qb64(): string;
106
- get qb64b(): Uint8Array;
106
+ get qb64b(): Uint8Array<ArrayBufferLike>;
107
107
  get transferable(): boolean;
108
108
  get digestive(): boolean;
109
109
  static _rawSize(code: string): number;
@@ -0,0 +1,460 @@
1
+ import { EmptyMaterialError } from "./kering.js";
2
+ import { intToB64, readInt } from "./core.js";
3
+ import { b, d } from "./core.js";
4
+ import { decodeBase64Url, encodeBase64Url } from "./base64.js";
5
+ export class Codex {
6
+ has(prop) {
7
+ const m = new Map(Array.from(Object.entries(this), (v) => [v[1], v[0]]));
8
+ return m.has(prop);
9
+ }
10
+ }
11
+ export class MatterCodex extends Codex {
12
+ constructor() {
13
+ super(...arguments);
14
+ this.Ed25519_Seed = 'A'; // Ed25519 256 bit random seed for private key
15
+ this.Ed25519N = 'B'; // Ed25519 verification key non-transferable, basic derivation.
16
+ this.X25519 = 'C'; // X25519 public encryption key, converted from Ed25519 or Ed25519N.
17
+ this.Ed25519 = 'D'; // Ed25519 verification key basic derivation
18
+ this.Blake3_256 = 'E'; // Blake3 256 bit digest self-addressing derivation.
19
+ this.SHA3_256 = 'H'; // SHA3 256 bit digest self-addressing derivation.
20
+ this.SHA2_256 = 'I'; // SHA2 256 bit digest self-addressing derivation.
21
+ this.ECDSA_256k1_Seed = 'J'; // ECDSA secp256k1 256 bit random Seed for private key
22
+ this.X25519_Private = 'O'; // X25519 private decryption key converted from Ed25519
23
+ this.X25519_Cipher_Seed = 'P'; // X25519 124 char b64 Cipher of 44 char qb64 Seed
24
+ this.ECDSA_256r1_Seed = 'Q'; // ECDSA secp256r1 256 bit random Seed for private key
25
+ this.Salt_128 = '0A'; // 128 bit random salt or 128 bit number (see Huge)
26
+ this.Ed25519_Sig = '0B'; // Ed25519 signature.
27
+ this.ECDSA_256k1_Sig = '0C'; // ECDSA secp256k1 signature.
28
+ this.ECDSA_256r1_Sig = '0I'; // ECDSA secp256r1 signature.
29
+ this.StrB64_L0 = '4A'; // String Base64 Only Lead Size 0
30
+ this.StrB64_L1 = '5A'; // String Base64 Only Lead Size 1
31
+ this.StrB64_L2 = '6A'; // String Base64 Only Lead Size 2
32
+ this.ECDSA_256k1N = '1AAA'; // ECDSA secp256k1 verification key non-transferable, basic derivation.
33
+ this.ECDSA_256k1 = '1AAB'; // ECDSA public verification or encryption key, basic derivation
34
+ this.X25519_Cipher_Salt = '1AAH'; // X25519 100 char b64 Cipher of 24 char qb64 Salt
35
+ this.ECDSA_256r1N = '1AAI'; // ECDSA secp256r1 verification key non-transferable, basic derivation.
36
+ this.ECDSA_256r1 = '1AAJ'; // ECDSA secp256r1 verification or encryption key, basic derivation
37
+ this.StrB64_Big_L0 = '7AAA'; // String Base64 Only Big Lead Size 0
38
+ this.StrB64_Big_L1 = '8AAA'; // String Base64 Only Big Lead Size 1
39
+ this.StrB64_Big_L2 = '9AAA'; // String Base64 Only Big Lead Size 2
40
+ }
41
+ }
42
+ export const MtrDex = new MatterCodex();
43
+ export class NonTransCodex extends Codex {
44
+ constructor() {
45
+ super(...arguments);
46
+ this.Ed25519N = 'B'; // Ed25519 verification key non-transferable, basic derivation.
47
+ this.ECDSA_256k1N = '1AAA'; // ECDSA secp256k1 verification key non-transferable, basic derivation.
48
+ this.Ed448N = '1AAC'; // Ed448 non-transferable prefix public signing verification key. Basic derivation.
49
+ this.ECDSA_256r1N = '1AAI'; // ECDSA secp256r1 verification key non-transferable, basic derivation.
50
+ }
51
+ }
52
+ export const NonTransDex = new NonTransCodex();
53
+ export class DigiCodex extends Codex {
54
+ constructor() {
55
+ super(...arguments);
56
+ this.Blake3_256 = 'E'; // Blake3 256 bit digest self-addressing derivation.
57
+ this.Blake2b_256 = 'F'; // Blake2b 256 bit digest self-addressing derivation.
58
+ this.Blake2s_256 = 'G'; // Blake2s 256 bit digest self-addressing derivation.
59
+ this.SHA3_256 = 'H'; // SHA3 256 bit digest self-addressing derivation.
60
+ this.SHA2_256 = 'I'; // SHA2 256 bit digest self-addressing derivation.
61
+ this.Blake3_512 = '0D'; // Blake3 512 bit digest self-addressing derivation.
62
+ this.Blake2b_512 = '0E'; // Blake2b 512 bit digest self-addressing derivation.
63
+ this.SHA3_512 = '0F'; // SHA3 512 bit digest self-addressing derivation.
64
+ this.SHA2_512 = '0G'; // SHA2 512 bit digest self-addressing derivation.
65
+ }
66
+ }
67
+ export const DigiDex = new DigiCodex();
68
+ export class NumCodex extends Codex {
69
+ constructor() {
70
+ super(...arguments);
71
+ this.Short = 'M'; // Short 2 byte b2 number
72
+ this.Long = '0H'; // Long 4 byte b2 number
73
+ this.Big = 'N'; // Big 8 byte b2 number
74
+ this.Huge = '0A'; // Huge 16 byte b2 number (same as Salt_128)
75
+ }
76
+ }
77
+ export const NumDex = new NumCodex();
78
+ export class BexCodex extends Codex {
79
+ constructor() {
80
+ super(...arguments);
81
+ this.StrB64_L0 = '4A'; // String Base64 Only Leader Size 0
82
+ this.StrB64_L1 = '5A'; // String Base64 Only Leader Size 1
83
+ this.StrB64_L2 = '6A'; // String Base64 Only Leader Size 2
84
+ this.StrB64_Big_L0 = '7AAA'; // String Base64 Only Big Leader Size 0
85
+ this.StrB64_Big_L1 = '8AAA'; // String Base64 Only Big Leader Size 1
86
+ this.StrB64_Big_L2 = '9AAA'; // String Base64 Only Big Leader Size 2
87
+ }
88
+ }
89
+ export const BexDex = new BexCodex();
90
+ class SmallVarRawSizeCodex extends Codex {
91
+ constructor() {
92
+ super(...arguments);
93
+ this.Lead0 = '4'; // First Selector Character for all ls == 0 codes
94
+ this.Lead1 = '5'; // First Selector Character for all ls == 1 codes
95
+ this.Lead2 = '6'; // First Selector Character for all ls == 2 codes
96
+ }
97
+ }
98
+ export const SmallVrzDex = new SmallVarRawSizeCodex();
99
+ class LargeVarRawSizeCodex extends Codex {
100
+ constructor() {
101
+ super(...arguments);
102
+ this.Lead0_Big = '7'; // First Selector Character for all ls == 0 codes
103
+ this.Lead1_Big = '8'; // First Selector Character for all ls == 1 codes
104
+ this.Lead2_Big = '9'; // First Selector Character for all ls == 2 codes
105
+ }
106
+ }
107
+ export const LargeVrzDex = new LargeVarRawSizeCodex();
108
+ export class Sizage {
109
+ constructor(hs, ss, fs, ls) {
110
+ this.hs = hs;
111
+ this.ss = ss;
112
+ this.fs = fs;
113
+ this.ls = ls;
114
+ }
115
+ }
116
+ export class Matter {
117
+ constructor({ raw, code = MtrDex.Ed25519N, qb64b, qb64, qb2, rize, }) {
118
+ this._code = '';
119
+ this._size = -1;
120
+ this._raw = new Uint8Array(0);
121
+ let size = -1;
122
+ if (raw != undefined) {
123
+ if (code.length == 0) {
124
+ throw new Error('Improper initialization need either (raw and code) or qb64b or qb64 or qb2.');
125
+ }
126
+ if (SmallVrzDex.has(code[0]) || LargeVrzDex.has(code[0])) {
127
+ if (rize !== undefined) {
128
+ if (rize < 0)
129
+ throw new Error(`missing var raw size for code=${code}`);
130
+ }
131
+ else {
132
+ rize = raw.length;
133
+ }
134
+ const ls = (3 - (rize % 3)) % 3; // calc actual lead (pad) size
135
+ size = Math.floor((rize + ls) / 3); // calculate value of size in triplets
136
+ if (SmallVrzDex.has(code[0])) {
137
+ if (size <= 64 ** 2 - 1) {
138
+ const hs = 2;
139
+ const s = Object.values(SmallVrzDex)[ls];
140
+ code = `${s}${code.substring(1, hs)}`;
141
+ }
142
+ else if (size <= 64 ** 4 - 1) {
143
+ const hs = 4;
144
+ const s = Object.values(LargeVrzDex)[ls];
145
+ code = `${s}${'AAAA'.substring(0, hs - 2)}${code[1]}`;
146
+ }
147
+ else {
148
+ throw new Error(`Unsupported raw size for code=${code}`);
149
+ }
150
+ }
151
+ else {
152
+ if (size <= 64 ** 4 - 1) {
153
+ const hs = 4;
154
+ const s = Object.values(LargeVrzDex)[ls];
155
+ code = `${s}${code.substring(1, hs)}`;
156
+ }
157
+ else {
158
+ throw new Error(`Unsupported raw size for code=${code}`);
159
+ }
160
+ }
161
+ }
162
+ else {
163
+ const sizage = Matter.Sizes.get(code);
164
+ if (sizage.fs == -1) {
165
+ // invalid
166
+ throw new Error(`Unsupported variable size code=${code}`);
167
+ }
168
+ rize = Matter._rawSize(code);
169
+ }
170
+ raw = raw.slice(0, rize); // copy only exact size from raw stream
171
+ if (raw.length != rize) {
172
+ // forbids shorter
173
+ throw new Error(`Not enougth raw bytes for code=${code} expected ${rize} got ${raw.length}.`);
174
+ }
175
+ this._code = code; // hard value part of code
176
+ this._size = size; // soft value part of code in int
177
+ this._raw = raw; // crypto ops require bytes not bytearray
178
+ }
179
+ else if (qb64 !== undefined) {
180
+ this._exfil(qb64);
181
+ }
182
+ else if (qb64b !== undefined) {
183
+ const qb64 = d(qb64b);
184
+ this._exfil(qb64);
185
+ }
186
+ else if (qb2 !== undefined) {
187
+ this._bexfil(qb2);
188
+ }
189
+ else {
190
+ throw new EmptyMaterialError('EmptyMaterialError');
191
+ }
192
+ }
193
+ get code() {
194
+ return this._code;
195
+ }
196
+ get size() {
197
+ return this._size;
198
+ }
199
+ get raw() {
200
+ return this._raw;
201
+ }
202
+ get qb64() {
203
+ return this._infil();
204
+ }
205
+ get qb64b() {
206
+ return b(this.qb64);
207
+ }
208
+ get transferable() {
209
+ return !NonTransDex.has(this.code);
210
+ }
211
+ get digestive() {
212
+ return DigiDex.has(this.code);
213
+ }
214
+ static _rawSize(code) {
215
+ const sizage = this.Sizes.get(code); // get sizes
216
+ const cs = sizage.hs + sizage.ss; // both hard + soft code size
217
+ if (sizage.fs === -1) {
218
+ throw Error(`Non-fixed raw size code ${code}.`);
219
+ }
220
+ return Math.floor(((sizage.fs - cs) * 3) / 4) - sizage.ls;
221
+ }
222
+ static _leadSize(code) {
223
+ const sizage = this.Sizes.get(code);
224
+ return sizage.ls;
225
+ }
226
+ get both() {
227
+ const sizage = Matter.Sizes.get(this.code);
228
+ return `${this.code}${intToB64(this.size, sizage.ss)}`;
229
+ }
230
+ _infil() {
231
+ const code = this.code;
232
+ const size = this.size;
233
+ const raw = this.raw;
234
+ const ps = (3 - (raw.length % 3)) % 3; // pad size chars or lead size bytes
235
+ const sizage = Matter.Sizes.get(code);
236
+ if (sizage.fs === undefined) {
237
+ // Variable size code, NOT SUPPORTED
238
+ const cs = sizage.hs + sizage.ss;
239
+ if (cs % 4) {
240
+ throw new Error(`Whole code size not multiple of 4 for variable length material. cs=${cs}`);
241
+ }
242
+ if (size < 0 || size > 64 ** sizage.ss - 1) {
243
+ throw new Error(`Invalid size=${size} for code=${code}.`);
244
+ }
245
+ const both = `${code}${intToB64(size, sizage.ss)}`;
246
+ if (both.length % 4 !== ps - sizage.ls) {
247
+ throw new Error(`Invalid code=${both} for converted raw pad size=${ps}.`);
248
+ }
249
+ const bytes = new Uint8Array(sizage.ls + raw.length);
250
+ for (let i = 0; i < sizage.ls; i++) {
251
+ bytes[i] = 0;
252
+ }
253
+ for (let i = 0; i < raw.length; i++) {
254
+ const odx = i + ps;
255
+ bytes[odx] = raw[i];
256
+ }
257
+ return both + encodeBase64Url(bytes);
258
+ }
259
+ else {
260
+ const both = code;
261
+ const cs = both.length;
262
+ if (cs % 4 != ps - sizage.ls) {
263
+ // adjusted pad given lead bytes
264
+ throw new Error(`Invalid code=${both} for converted raw pad size=${ps}, ${raw.length}.`);
265
+ }
266
+ // prepad, convert, and replace upfront
267
+ // when fixed and ls != 0 then cs % 4 is zero and ps==ls
268
+ // otherwise fixed and ls == 0 then cs % 4 == ps
269
+ const bytes = new Uint8Array(ps + raw.length);
270
+ for (let i = 0; i < ps; i++) {
271
+ bytes[i] = 0;
272
+ }
273
+ for (let i = 0; i < raw.length; i++) {
274
+ const odx = i + ps;
275
+ bytes[odx] = raw[i];
276
+ }
277
+ return both + encodeBase64Url(bytes).slice(cs % 4);
278
+ }
279
+ }
280
+ _exfil(qb64) {
281
+ if (qb64.length == 0) {
282
+ throw new Error('Empty Material');
283
+ }
284
+ const first = qb64[0];
285
+ if (!Array.from(Matter.Hards.keys()).includes(first)) {
286
+ throw new Error(`Unexpected code ${first}`);
287
+ }
288
+ const hs = Matter.Hards.get(first);
289
+ if (qb64.length < hs) {
290
+ throw new Error(`Shortage Error`);
291
+ }
292
+ const hard = qb64.slice(0, hs);
293
+ if (!Array.from(Matter.Sizes.keys()).includes(hard)) {
294
+ throw new Error(`Unsupported code ${hard}`);
295
+ }
296
+ const sizage = Matter.Sizes.get(hard);
297
+ const cs = sizage.hs + sizage.ss;
298
+ let size = -1;
299
+ if (sizage.fs == -1) {
300
+ // Variable size code, Not supported
301
+ throw new Error('Variable size codes not supported yet');
302
+ }
303
+ else {
304
+ size = sizage.fs;
305
+ }
306
+ if (qb64.length < sizage.fs) {
307
+ throw new Error(`Need ${sizage.fs - qb64.length} more chars.`);
308
+ }
309
+ qb64 = qb64.slice(0, sizage.fs);
310
+ const ps = cs % 4;
311
+ const pbs = 2 * (ps == 0 ? sizage.ls : ps);
312
+ let raw;
313
+ if (ps != 0) {
314
+ const base = new Array(ps + 1).join('A') + qb64.slice(cs);
315
+ const paw = Uint8Array.from(decodeBase64Url(base)); // decode base to leave prepadded raw
316
+ const pi = readInt(paw.subarray(0, ps)); // prepad as int
317
+ if (pi & (2 ** pbs - 1)) {
318
+ // masked pad bits non-zero
319
+ throw new Error(`Non zeroed prepad bits = {pi & (2 ** pbs - 1 ):<06b} in {qb64b[cs:cs+1]}.`);
320
+ }
321
+ raw = paw.subarray(ps); // strip off ps prepad paw bytes
322
+ }
323
+ else {
324
+ const base = qb64.slice(cs);
325
+ const paw = Uint8Array.from(decodeBase64Url(base));
326
+ const li = readInt(paw.subarray(0, sizage.ls));
327
+ if (li != 0) {
328
+ if (li == 1) {
329
+ throw new Error(`Non zeroed lead byte = 0x{li:02x}.`);
330
+ }
331
+ else {
332
+ throw new Error(`Non zeroed lead bytes = 0x{li:04x}`);
333
+ }
334
+ }
335
+ raw = paw.subarray(sizage.ls);
336
+ }
337
+ this._code = hard; // hard only
338
+ this._size = size;
339
+ this._raw = Uint8Array.from(raw); // ensure bytes so immutable and for crypto ops
340
+ }
341
+ _bexfil(qb2) {
342
+ throw new Error(`qb2 not yet supported: ${qb2}`);
343
+ }
344
+ }
345
+ Matter.Sizes = new Map(Object.entries({
346
+ A: new Sizage(1, 0, 44, 0),
347
+ B: new Sizage(1, 0, 44, 0),
348
+ C: new Sizage(1, 0, 44, 0),
349
+ D: new Sizage(1, 0, 44, 0),
350
+ E: new Sizage(1, 0, 44, 0),
351
+ F: new Sizage(1, 0, 44, 0),
352
+ G: new Sizage(1, 0, 44, 0),
353
+ H: new Sizage(1, 0, 44, 0),
354
+ I: new Sizage(1, 0, 44, 0),
355
+ J: new Sizage(1, 0, 44, 0),
356
+ K: new Sizage(1, 0, 76, 0),
357
+ L: new Sizage(1, 0, 76, 0),
358
+ M: new Sizage(1, 0, 4, 0),
359
+ N: new Sizage(1, 0, 12, 0),
360
+ O: new Sizage(1, 0, 44, 0),
361
+ P: new Sizage(1, 0, 124, 0),
362
+ Q: new Sizage(1, 0, 44, 0),
363
+ '0A': new Sizage(2, 0, 24, 0),
364
+ '0B': new Sizage(2, 0, 88, 0),
365
+ '0C': new Sizage(2, 0, 88, 0),
366
+ '0D': new Sizage(2, 0, 88, 0),
367
+ '0E': new Sizage(2, 0, 88, 0),
368
+ '0F': new Sizage(2, 0, 88, 0),
369
+ '0G': new Sizage(2, 0, 88, 0),
370
+ '0H': new Sizage(2, 0, 8, 0),
371
+ '0I': new Sizage(2, 0, 88, 0),
372
+ '1AAA': new Sizage(4, 0, 48, 0),
373
+ '1AAB': new Sizage(4, 0, 48, 0),
374
+ '1AAC': new Sizage(4, 0, 80, 0),
375
+ '1AAD': new Sizage(4, 0, 80, 0),
376
+ '1AAE': new Sizage(4, 0, 56, 0),
377
+ '1AAF': new Sizage(4, 0, 8, 0),
378
+ '1AAG': new Sizage(4, 0, 36, 0),
379
+ '1AAH': new Sizage(4, 0, 100, 0),
380
+ '1AAI': new Sizage(4, 0, 48, 0),
381
+ '1AAJ': new Sizage(4, 0, 48, 0),
382
+ '2AAA': new Sizage(4, 0, 8, 1),
383
+ '3AAA': new Sizage(4, 0, 8, 2),
384
+ '4A': new Sizage(2, 2, undefined, 0),
385
+ '5A': new Sizage(2, 2, undefined, 1),
386
+ '6A': new Sizage(2, 2, undefined, 2),
387
+ '7AAA': new Sizage(4, 4, undefined, 0),
388
+ '8AAA': new Sizage(4, 4, undefined, 1),
389
+ '9AAA': new Sizage(4, 4, undefined, 2),
390
+ '4B': new Sizage(2, 2, undefined, 0),
391
+ '5B': new Sizage(2, 2, undefined, 1),
392
+ '6B': new Sizage(2, 2, undefined, 2),
393
+ '7AAB': new Sizage(4, 4, undefined, 0),
394
+ '8AAB': new Sizage(4, 4, undefined, 1),
395
+ '9AAB': new Sizage(4, 4, undefined, 2),
396
+ }));
397
+ Matter.Hards = new Map([
398
+ ['A', 1],
399
+ ['B', 1],
400
+ ['C', 1],
401
+ ['D', 1],
402
+ ['E', 1],
403
+ ['F', 1],
404
+ ['G', 1],
405
+ ['H', 1],
406
+ ['I', 1],
407
+ ['J', 1],
408
+ ['K', 1],
409
+ ['L', 1],
410
+ ['M', 1],
411
+ ['N', 1],
412
+ ['O', 1],
413
+ ['P', 1],
414
+ ['Q', 1],
415
+ ['R', 1],
416
+ ['S', 1],
417
+ ['T', 1],
418
+ ['U', 1],
419
+ ['V', 1],
420
+ ['W', 1],
421
+ ['X', 1],
422
+ ['Y', 1],
423
+ ['Z', 1],
424
+ ['a', 1],
425
+ ['b', 1],
426
+ ['c', 1],
427
+ ['d', 1],
428
+ ['e', 1],
429
+ ['f', 1],
430
+ ['g', 1],
431
+ ['h', 1],
432
+ ['i', 1],
433
+ ['j', 1],
434
+ ['k', 1],
435
+ ['l', 1],
436
+ ['m', 1],
437
+ ['n', 1],
438
+ ['o', 1],
439
+ ['p', 1],
440
+ ['q', 1],
441
+ ['r', 1],
442
+ ['s', 1],
443
+ ['t', 1],
444
+ ['u', 1],
445
+ ['v', 1],
446
+ ['w', 1],
447
+ ['x', 1],
448
+ ['y', 1],
449
+ ['z', 1],
450
+ ['0', 2],
451
+ ['1', 4],
452
+ ['2', 4],
453
+ ['3', 4],
454
+ ['4', 2],
455
+ ['5', 2],
456
+ ['6', 2],
457
+ ['7', 4],
458
+ ['8', 4],
459
+ ['9', 4],
460
+ ]);
@@ -1,6 +1,6 @@
1
- import { Matter, MatterArgs } from './matter';
1
+ import { Matter, MatterArgs } from './matter.ts';
2
2
  export declare class CesrNumber extends Matter {
3
- constructor({ raw, code, qb64b, qb64, qb2 }: MatterArgs, num?: number | string, numh?: string);
3
+ constructor({ raw, code, qb64b, qb64, qb2 }: MatterArgs, num?: number | string);
4
4
  get num(): number;
5
5
  get numh(): string;
6
6
  get positive(): boolean;
@@ -1,66 +1,60 @@
1
- import { Matter, MatterArgs, NumDex } from './matter';
2
- import { bytesToInt, intToBytes } from './utils';
3
-
1
+ import { Matter, NumDex } from "./matter.js";
2
+ import { bytesToInt, intToBytes } from "./utils.js";
4
3
  export class CesrNumber extends Matter {
5
- constructor(
6
- { raw, code, qb64b, qb64, qb2 }: MatterArgs,
7
- num?: number | string,
8
- numh?: string
9
- ) {
4
+ constructor({ raw, code, qb64b, qb64, qb2 }, num) {
10
5
  let _num;
11
- if (
12
- raw == undefined &&
6
+ if (raw == undefined &&
13
7
  qb64 == undefined &&
14
8
  qb64b == undefined &&
15
- qb2 == undefined
16
- ) {
17
- if (typeof num == 'number') {
9
+ qb2 == undefined) {
10
+ if (typeof num === 'number') {
18
11
  _num = num;
19
- } else if (numh != undefined) {
20
- _num = parseInt(numh, 16);
21
- } else {
12
+ }
13
+ else if (typeof num === 'string') {
14
+ _num = parseInt(num, 16);
15
+ if (Number.isNaN(_num)) {
16
+ throw new Error(`Invalid hex string for num: ${num}`);
17
+ }
18
+ }
19
+ else {
22
20
  _num = 0;
23
21
  }
24
22
  }
25
-
26
23
  if (_num == undefined) {
27
24
  throw new Error('Invalid whole number');
28
25
  }
29
-
30
26
  if (_num <= 256 ** 2 - 1) {
31
27
  // make short version of code
32
28
  code = NumDex.Short;
33
- } else if (_num <= 256 ** 4 - 1) {
29
+ }
30
+ else if (_num <= 256 ** 4 - 1) {
34
31
  // make long version of code
35
32
  code = code = NumDex.Long;
36
- } else if (_num <= 256 ** 8 - 1) {
33
+ }
34
+ else if (_num <= 256 ** 8 - 1) {
37
35
  // make big version of code
38
36
  code = code = NumDex.Big;
39
- } else if (_num <= 256 ** 16 - 1) {
37
+ }
38
+ else if (_num <= 256 ** 16 - 1) {
40
39
  // make huge version of code
41
40
  code = code = NumDex.Huge;
42
- } else {
43
- throw new Error('Invalid num = {num}, too large to encode.');
44
41
  }
45
-
42
+ else {
43
+ throw new Error(`Invalid num = ${num}, too large to encode.`);
44
+ }
46
45
  raw = intToBytes(_num, Matter._rawSize(code));
47
-
48
46
  super({ raw, code, qb64b, qb64, qb2 });
49
-
50
47
  if (!NumDex.has(this.code)) {
51
48
  throw new Error('Invalid code ' + code + ' for Number');
52
49
  }
53
50
  }
54
-
55
- get num(): number {
51
+ get num() {
56
52
  return bytesToInt(this.raw);
57
53
  }
58
-
59
- get numh(): string {
54
+ get numh() {
60
55
  return this.num.toString(16);
61
56
  }
62
-
63
- get positive(): boolean {
57
+ get positive() {
64
58
  return this.num > 0;
65
59
  }
66
60
  }
@@ -1,5 +1,5 @@
1
- import { Bexter } from './bexter';
2
- import { MatterArgs } from './matter';
1
+ import { Bexter } from './bexter.ts';
2
+ import { MatterArgs } from './matter.ts';
3
3
  export declare class Pather extends Bexter {
4
4
  constructor({ raw, code, qb64b, qb64, qb2 }: MatterArgs, bext?: string, path?: string[]);
5
5
  get path(): string[];
@@ -1,7 +1,6 @@
1
- import { Bexter, Reb64 } from './bexter';
2
- import { MatterArgs, MtrDex } from './matter';
3
- import { EmptyMaterialError } from './kering';
4
-
1
+ import { Bexter, Reb64 } from "./bexter.js";
2
+ import { MtrDex } from "./matter.js";
3
+ import { EmptyMaterialError } from "./kering.js";
5
4
  /*
6
5
  Pather is a subclass of Bexter that provides SAD Path language specific functionality
7
6
  for variable length strings that only contain Base64 URL safe characters. Pather allows
@@ -33,64 +32,50 @@ import { EmptyMaterialError } from './kering';
33
32
  qb64 = '4AAC-A-1-B-3'
34
33
 
35
34
  */
36
-
37
35
  export class Pather extends Bexter {
38
- constructor(
39
- { raw, code = MtrDex.StrB64_L0, qb64b, qb64, qb2 }: MatterArgs,
40
- bext?: string,
41
- path?: string[]
42
- ) {
43
- if (
44
- raw === undefined &&
36
+ constructor({ raw, code = MtrDex.StrB64_L0, qb64b, qb64, qb2 }, bext, path) {
37
+ if (raw === undefined &&
45
38
  bext === undefined &&
46
39
  qb64b === undefined &&
47
40
  qb64 === undefined &&
48
- qb2 === undefined
49
- ) {
41
+ qb2 === undefined) {
50
42
  if (path === undefined)
51
43
  throw new EmptyMaterialError('Missing bext string.');
52
-
53
44
  bext = Pather._bextify(path);
54
45
  }
55
-
56
46
  super({ raw, code, qb64b, qb64, qb2 }, bext);
57
47
  }
58
-
59
48
  // TODO: implement SAD access methods like resolve, root, strip, startswith and tail
60
-
61
- get path(): string[] {
49
+ get path() {
62
50
  if (!this.bext.startsWith('-')) {
63
51
  throw new Error('invalid SAD ptr');
64
52
  }
65
-
66
53
  let path = this.bext;
67
54
  while (path.charAt(0) === '-') {
68
55
  path = path.substring(1);
69
56
  }
70
-
71
57
  const apath = path.split('-');
72
58
  if (apath[0] !== '') {
73
59
  return apath;
74
- } else {
60
+ }
61
+ else {
75
62
  return [];
76
63
  }
77
64
  }
78
-
79
- static _bextify(path: any[]): string {
65
+ static _bextify(path) {
80
66
  const vath = [];
81
67
  for (const p of path) {
82
68
  let sp = '';
83
69
  if (typeof p === 'number') {
84
70
  sp = p.toString();
85
- } else {
71
+ }
72
+ else {
86
73
  sp = p;
87
74
  }
88
-
89
75
  const match = Reb64.exec(sp);
90
76
  if (!match) {
91
77
  throw new Error(`"Non Base64 path component = ${p}.`);
92
78
  }
93
-
94
79
  vath.push(sp);
95
80
  }
96
81
  return '-' + vath.join('-');