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.
- package/README.md +104 -34
- package/dist/exports.d.ts +40 -40
- package/dist/exports.js +40 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.js +3 -8
- package/dist/keri/app/aiding.d.ts +54 -18
- package/{src/keri/app/aiding.ts → dist/keri/app/aiding.js} +130 -236
- package/dist/keri/app/clienting.d.ts +59 -22
- package/{src/keri/app/clienting.ts → dist/keri/app/clienting.js} +146 -235
- package/dist/keri/app/contacting.d.ts +30 -23
- package/{src/keri/app/contacting.ts → dist/keri/app/contacting.js} +26 -63
- package/dist/keri/app/controller.d.ts +49 -6
- package/{src/keri/app/controller.ts → dist/keri/app/controller.js} +80 -186
- package/dist/keri/app/coring.d.ts +134 -25
- package/{src/keri/app/coring.ts → dist/keri/app/coring.js} +83 -56
- package/dist/keri/app/credentialing.d.ts +187 -69
- package/dist/keri/app/credentialing.js +540 -0
- package/dist/keri/app/delegating.d.ts +18 -0
- package/dist/keri/app/delegating.js +24 -0
- package/dist/keri/app/escrowing.d.ts +5 -3
- package/{src/keri/app/escrowing.ts → dist/keri/app/escrowing.js} +3 -9
- package/dist/keri/app/exchanging.d.ts +243 -11
- package/dist/keri/app/exchanging.js +242 -0
- package/dist/keri/app/grouping.d.ts +11 -9
- package/{src/keri/app/grouping.ts → dist/keri/app/grouping.js} +10 -29
- package/dist/keri/app/habery.d.ts +2 -2
- package/dist/keri/app/habery.js +117 -0
- package/dist/keri/app/notifying.d.ts +2 -2
- package/{src/keri/app/notifying.ts → dist/keri/app/notifying.js} +7 -17
- package/dist/keri/core/authing.d.ts +2 -2
- package/{src/keri/core/authing.ts → dist/keri/core/authing.js} +26 -42
- package/dist/keri/core/base64.d.ts +2 -0
- package/dist/keri/core/base64.js +16 -0
- package/dist/keri/core/bexter.d.ts +1 -1
- package/{src/keri/core/bexter.ts → dist/keri/core/bexter.js} +18 -32
- package/dist/keri/core/cigar.d.ts +2 -2
- package/dist/keri/core/cigar.js +13 -0
- package/dist/keri/core/cipher.d.ts +1 -1
- package/{src/keri/core/cipher.ts → dist/keri/core/cipher.js} +10 -19
- package/dist/keri/core/core.d.ts +117 -9
- package/dist/keri/core/core.js +385 -0
- package/dist/keri/core/counter.d.ts +2 -2
- package/dist/keri/core/counter.js +221 -0
- package/dist/keri/core/decrypter.d.ts +4 -4
- package/{src/keri/core/decrypter.ts → dist/keri/core/decrypter.js} +23 -40
- package/dist/keri/core/diger.d.ts +3 -3
- package/{src/keri/core/diger.ts → dist/keri/core/diger.js} +18 -33
- package/dist/keri/core/encrypter.d.ts +2 -2
- package/{src/keri/core/encrypter.ts → dist/keri/core/encrypter.js} +18 -38
- package/dist/keri/core/eventing.d.ts +6 -6
- package/dist/keri/core/eventing.js +383 -0
- package/dist/keri/core/httping.d.ts +11 -4
- package/{src/keri/core/httping.ts → dist/keri/core/httping.js} +36 -101
- package/dist/keri/core/indexer.d.ts +1 -1
- package/dist/keri/core/indexer.js +407 -0
- package/dist/keri/core/keeping.d.ts +113 -46
- package/dist/keri/core/keeping.js +347 -0
- package/{src/keri/core/kering.ts → dist/keri/core/kering.js} +1 -3
- package/dist/keri/core/keyState.d.ts +98 -0
- package/dist/keri/core/manager.d.ts +147 -12
- package/dist/keri/core/manager.js +880 -0
- package/dist/keri/core/matter.d.ts +1 -1
- package/dist/keri/core/matter.js +460 -0
- package/dist/keri/core/number.d.ts +2 -2
- package/{src/keri/core/number.ts → dist/keri/core/number.js} +26 -32
- package/dist/keri/core/pather.d.ts +2 -2
- package/{src/keri/core/pather.ts → dist/keri/core/pather.js} +12 -27
- package/dist/keri/core/prefixer.d.ts +10 -10
- package/dist/keri/core/prefixer.js +182 -0
- package/dist/keri/core/saider.d.ts +2 -12
- package/dist/keri/core/saider.js +107 -0
- package/dist/keri/core/salter.d.ts +44 -9
- package/dist/keri/core/salter.js +110 -0
- package/dist/keri/core/seqner.d.ts +1 -1
- package/{src/keri/core/seqner.ts → dist/keri/core/seqner.js} +20 -21
- package/dist/keri/core/serder.d.ts +25 -12
- package/dist/keri/core/serder.js +133 -0
- package/dist/keri/core/siger.d.ts +2 -2
- package/{src/keri/core/siger.ts → dist/keri/core/siger.js} +4 -14
- package/dist/keri/core/signer.d.ts +4 -4
- package/dist/keri/core/signer.js +84 -0
- package/{src/keri/core/tholder.ts → dist/keri/core/tholder.js} +69 -94
- package/dist/keri/core/utils.d.ts +1 -1
- package/{src/keri/core/utils.ts → dist/keri/core/utils.js} +30 -60
- package/dist/keri/core/vdring.d.ts +2 -2
- package/dist/keri/core/vdring.js +61 -0
- package/dist/keri/core/verfer.d.ts +2 -6
- package/dist/keri/core/verfer.js +37 -0
- package/dist/keri/end/ending.d.ts +10 -8
- package/dist/keri/end/ending.js +136 -0
- package/{src/ready.ts → dist/ready.js} +1 -2
- package/dist/types/keria-api-schema.d.ts +1158 -0
- package/dist/types/keria-api-schema.js +34 -0
- package/package.json +53 -52
- package/dist/math.d.ts +0 -1
- package/dist/signify-ts.cjs +0 -7842
- package/dist/signify-ts.cjs.development.js +0 -9501
- package/dist/signify-ts.cjs.development.js.map +0 -1
- package/dist/signify-ts.cjs.map +0 -7
- package/dist/signify-ts.cjs.production.min.js +0 -2
- package/dist/signify-ts.cjs.production.min.js.map +0 -1
- package/dist/signify-ts.esm.js +0 -9345
- package/dist/signify-ts.esm.js.map +0 -1
- package/dist/signify-ts.mjs +0 -7818
- package/dist/signify-ts.mjs.map +0 -7
- package/src/buffer-polyfill.ts +0 -5
- package/src/exports.ts +0 -44
- package/src/index.ts +0 -4
- package/src/keri/app/credentialing.ts +0 -841
- package/src/keri/app/exchanging.ts +0 -220
- package/src/keri/app/habery.ts +0 -185
- package/src/keri/core/cigar.ts +0 -18
- package/src/keri/core/core.ts +0 -326
- package/src/keri/core/counter.ts +0 -273
- package/src/keri/core/eventing.ts +0 -581
- package/src/keri/core/indexer.ts +0 -509
- package/src/keri/core/keeping.ts +0 -684
- package/src/keri/core/manager.ts +0 -1183
- package/src/keri/core/matter.ts +0 -521
- package/src/keri/core/prefixer.ts +0 -233
- package/src/keri/core/saider.ts +0 -186
- package/src/keri/core/salter.ts +0 -120
- package/src/keri/core/serder.ts +0 -163
- package/src/keri/core/signer.ts +0 -133
- package/src/keri/core/vdring.ts +0 -94
- package/src/keri/core/verfer.ts +0 -47
- package/src/keri/end/ending.ts +0 -170
- package/src/math.ts +0 -3
- /package/dist/{buffer-polyfill.d.ts → keri/core/keyState.js} +0 -0
package/src/keri/core/indexer.ts
DELETED
|
@@ -1,509 +0,0 @@
|
|
|
1
|
-
import { EmptyMaterialError } from './kering';
|
|
2
|
-
import { b, b64ToInt, d, intToB64, readInt } from './core';
|
|
3
|
-
import Base64 from 'urlsafe-base64';
|
|
4
|
-
import { Buffer } from 'buffer';
|
|
5
|
-
|
|
6
|
-
export class IndexerCodex {
|
|
7
|
-
Ed25519_Sig: string = 'A'; // Ed25519 sig appears same in both lists if any.
|
|
8
|
-
Ed25519_Crt_Sig: string = 'B'; // Ed25519 sig appears in current list only.
|
|
9
|
-
ECDSA_256k1_Sig: string = 'C'; // ECDSA secp256k1 sig appears same in both lists if any.
|
|
10
|
-
ECDSA_256k1_Crt_Sig: string = 'D'; // ECDSA secp256k1 sig appears in current list.
|
|
11
|
-
ECDSA_256r1_Sig: string = 'E'; // ECDSA secp256r1 sig appears same in both lists if any.
|
|
12
|
-
ECDSA_256r1_Crt_Sig: string = 'F'; // ECDSA secp256r1 sig appears in current list.
|
|
13
|
-
Ed448_Sig: string = '0A'; // Ed448 signature appears in both lists.
|
|
14
|
-
Ed448_Crt_Sig: string = '0B'; // Ed448 signature appears in current list only.
|
|
15
|
-
Ed25519_Big_Sig: string = '2A'; // Ed25519 sig appears in both lists.
|
|
16
|
-
Ed25519_Big_Crt_Sig: string = '2B'; // Ed25519 sig appears in current list only.
|
|
17
|
-
ECDSA_256k1_Big_Sig: string = '2C'; // ECDSA secp256k1 sig appears in both lists.
|
|
18
|
-
ECDSA_256k1_Big_Crt_Sig: string = '2D'; // ECDSA secp256k1 sig appears in current list only.
|
|
19
|
-
ECDSA_256r1_Big_Sig: string = '2E'; // ECDSA secp256r1 sig appears in both lists.
|
|
20
|
-
ECDSA_256r1_Big_Crt_Sig: string = '2F'; // ECDSA secp256r1 sig appears in current list only.
|
|
21
|
-
Ed448_Big_Sig: string = '3A'; // Ed448 signature appears in both lists.
|
|
22
|
-
Ed448_Big_Crt_Sig: string = '3B'; // Ed448 signature appears in current list only.
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const IdrDex = new IndexerCodex();
|
|
26
|
-
|
|
27
|
-
export class IndexedSigCodex {
|
|
28
|
-
Ed25519_Sig: string = 'A'; // Ed25519 sig appears same in both lists if any.
|
|
29
|
-
Ed25519_Crt_Sig: string = 'B'; // Ed25519 sig appears in current list only.
|
|
30
|
-
ECDSA_256k1_Sig: string = 'C'; // ECDSA secp256k1 sig appears same in both lists if any.
|
|
31
|
-
ECDSA_256k1_Crt_Sig: string = 'D'; // ECDSA secp256k1 sig appears in current list.
|
|
32
|
-
ECDSA_256r1_Sig: string = 'E'; // ECDSA secp256r1 sig appears same in both lists if any.
|
|
33
|
-
ECDSA_256r1_Crt_Sig: string = 'F'; // ECDSA secp256r1 sig appears in current list.
|
|
34
|
-
Ed448_Sig: string = '0A'; // Ed448 signature appears in both lists.
|
|
35
|
-
Ed448_Crt_Sig: string = '0B'; // Ed448 signature appears in current list only.
|
|
36
|
-
Ed25519_Big_Sig: string = '2A'; // Ed25519 sig appears in both lists.
|
|
37
|
-
Ed25519_Big_Crt_Sig: string = '2B'; // Ed25519 sig appears in current list only.
|
|
38
|
-
ECDSA_256k1_Big_Sig: string = '2C'; // ECDSA secp256k1 sig appears in both lists.
|
|
39
|
-
ECDSA_256k1_Big_Crt_Sig: string = '2D'; // ECDSA secp256k1 sig appears in current list only.
|
|
40
|
-
ECDSA_256r1_Big_Sig: string = '2E'; // ECDSA secp256r1 sig appears in both lists.
|
|
41
|
-
ECDSA_256r1_Big_Crt_Sig: string = '2F'; // ECDSA secp256r1 sig appears in current list only.
|
|
42
|
-
Ed448_Big_Sig: string = '3A'; // Ed448 signature appears in both lists.
|
|
43
|
-
Ed448_Big_Crt_Sig: string = '3B'; // Ed448 signature appears in current list only.
|
|
44
|
-
|
|
45
|
-
has(prop: string): boolean {
|
|
46
|
-
const m = new Map(
|
|
47
|
-
Array.from(Object.entries(this), (v) => [v[1], v[0]])
|
|
48
|
-
);
|
|
49
|
-
return m.has(prop);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export const IdxSigDex = new IndexedSigCodex();
|
|
54
|
-
|
|
55
|
-
export class IndexedCurrentSigCodex {
|
|
56
|
-
Ed25519_Crt_Sig: string = 'B'; // Ed25519 sig appears in current list only.
|
|
57
|
-
ECDSA_256k1_Crt_Sig: string = 'D'; // ECDSA secp256k1 sig appears in current list only.
|
|
58
|
-
ECDSA_256r1_Crt_Sig: string = 'F'; // ECDSA secp256r1 sig appears in current list.
|
|
59
|
-
Ed448_Crt_Sig: string = '0B'; // Ed448 signature appears in current list only.
|
|
60
|
-
Ed25519_Big_Crt_Sig: string = '2B'; // Ed25519 sig appears in current list only.
|
|
61
|
-
ECDSA_256k1_Big_Crt_Sig: string = '2D'; // ECDSA secp256k1 sig appears in current list only.
|
|
62
|
-
ECDSA_256r1_Big_Crt_Sig: string = '2F'; // ECDSA secp256r1 sig appears in current list only.
|
|
63
|
-
Ed448_Big_Crt_Sig: string = '3B'; // Ed448 signature appears in current list only.
|
|
64
|
-
|
|
65
|
-
has(prop: string): boolean {
|
|
66
|
-
const m = new Map(
|
|
67
|
-
Array.from(Object.entries(this), (v) => [v[1], v[0]])
|
|
68
|
-
);
|
|
69
|
-
return m.has(prop);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export const IdxCrtSigDex = new IndexedCurrentSigCodex();
|
|
74
|
-
|
|
75
|
-
export class IndexedBothSigCodex {
|
|
76
|
-
Ed25519_Sig: string = 'A'; // Ed25519 sig appears same in both lists if any.
|
|
77
|
-
ECDSA_256k1_Sig: string = 'C'; // ECDSA secp256k1 sig appears same in both lists if any.
|
|
78
|
-
Ed448_Sig: string = '0A'; // Ed448 signature appears in both lists.
|
|
79
|
-
Ed25519_Big_Sig: string = '2A'; // Ed25519 sig appears in both listsy.
|
|
80
|
-
ECDSA_256k1_Big_Sig: string = '2C'; // ECDSA secp256k1 sig appears in both lists.
|
|
81
|
-
Ed448_Big_Sig: string = '3A'; // Ed448 signature appears in both lists.
|
|
82
|
-
|
|
83
|
-
has(prop: string): boolean {
|
|
84
|
-
const m = new Map(
|
|
85
|
-
Array.from(Object.entries(this), (v) => [v[1], v[0]])
|
|
86
|
-
);
|
|
87
|
-
return m.has(prop);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export const IdxBthSigDex = new IndexedBothSigCodex();
|
|
92
|
-
|
|
93
|
-
export class Xizage {
|
|
94
|
-
public hs: number;
|
|
95
|
-
public ss: number;
|
|
96
|
-
public os: number;
|
|
97
|
-
public fs?: number;
|
|
98
|
-
public ls: number;
|
|
99
|
-
|
|
100
|
-
constructor(hs: number, ss: number, os: number, fs?: number, ls?: number) {
|
|
101
|
-
this.hs = hs;
|
|
102
|
-
this.ss = ss;
|
|
103
|
-
this.os = os;
|
|
104
|
-
this.fs = fs;
|
|
105
|
-
this.ls = ls!;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export interface IndexerArgs {
|
|
110
|
-
raw?: Uint8Array | undefined;
|
|
111
|
-
code?: string | undefined;
|
|
112
|
-
index?: number;
|
|
113
|
-
ondex?: number;
|
|
114
|
-
qb64b?: Uint8Array | undefined;
|
|
115
|
-
qb64?: string | undefined;
|
|
116
|
-
qb2?: Uint8Array | undefined;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export class Indexer {
|
|
120
|
-
public Codex = IdrDex;
|
|
121
|
-
|
|
122
|
-
static Hards = new Map<string, number>([
|
|
123
|
-
['A', 1],
|
|
124
|
-
['B', 1],
|
|
125
|
-
['C', 1],
|
|
126
|
-
['D', 1],
|
|
127
|
-
['E', 1],
|
|
128
|
-
['F', 1],
|
|
129
|
-
['G', 1],
|
|
130
|
-
['H', 1],
|
|
131
|
-
['I', 1],
|
|
132
|
-
['J', 1],
|
|
133
|
-
['K', 1],
|
|
134
|
-
['L', 1],
|
|
135
|
-
['M', 1],
|
|
136
|
-
['N', 1],
|
|
137
|
-
['O', 1],
|
|
138
|
-
['P', 1],
|
|
139
|
-
['Q', 1],
|
|
140
|
-
['R', 1],
|
|
141
|
-
['S', 1],
|
|
142
|
-
['T', 1],
|
|
143
|
-
['U', 1],
|
|
144
|
-
['V', 1],
|
|
145
|
-
['W', 1],
|
|
146
|
-
['X', 1],
|
|
147
|
-
['Y', 1],
|
|
148
|
-
['Z', 1],
|
|
149
|
-
['a', 1],
|
|
150
|
-
['b', 1],
|
|
151
|
-
['c', 1],
|
|
152
|
-
['d', 1],
|
|
153
|
-
['e', 1],
|
|
154
|
-
['f', 1],
|
|
155
|
-
['g', 1],
|
|
156
|
-
['h', 1],
|
|
157
|
-
['i', 1],
|
|
158
|
-
['j', 1],
|
|
159
|
-
['k', 1],
|
|
160
|
-
['l', 1],
|
|
161
|
-
['m', 1],
|
|
162
|
-
['n', 1],
|
|
163
|
-
['o', 1],
|
|
164
|
-
['p', 1],
|
|
165
|
-
['q', 1],
|
|
166
|
-
['r', 1],
|
|
167
|
-
['s', 1],
|
|
168
|
-
['t', 1],
|
|
169
|
-
['u', 1],
|
|
170
|
-
['v', 1],
|
|
171
|
-
['w', 1],
|
|
172
|
-
['x', 1],
|
|
173
|
-
['y', 1],
|
|
174
|
-
['z', 1],
|
|
175
|
-
['0', 2],
|
|
176
|
-
['1', 2],
|
|
177
|
-
['2', 2],
|
|
178
|
-
['3', 2],
|
|
179
|
-
['4', 2],
|
|
180
|
-
]);
|
|
181
|
-
|
|
182
|
-
static Sizes = new Map(
|
|
183
|
-
Object.entries({
|
|
184
|
-
A: new Xizage(1, 1, 0, 88, 0),
|
|
185
|
-
B: new Xizage(1, 1, 0, 88, 0),
|
|
186
|
-
C: new Xizage(1, 1, 0, 88, 0),
|
|
187
|
-
D: new Xizage(1, 1, 0, 88, 0),
|
|
188
|
-
E: new Xizage(1, 1, 0, 88, 0),
|
|
189
|
-
F: new Xizage(1, 1, 0, 88, 0),
|
|
190
|
-
'0A': new Xizage(2, 2, 1, 156, 0),
|
|
191
|
-
'0B': new Xizage(2, 2, 1, 156, 0),
|
|
192
|
-
|
|
193
|
-
'2A': new Xizage(2, 4, 2, 92, 0),
|
|
194
|
-
'2B': new Xizage(2, 4, 2, 92, 0),
|
|
195
|
-
'2C': new Xizage(2, 4, 2, 92, 0),
|
|
196
|
-
'2D': new Xizage(2, 4, 2, 92, 0),
|
|
197
|
-
'2E': new Xizage(2, 4, 2, 92, 0),
|
|
198
|
-
'2F': new Xizage(2, 4, 2, 92, 0),
|
|
199
|
-
|
|
200
|
-
'3A': new Xizage(2, 6, 3, 160, 0),
|
|
201
|
-
'3B': new Xizage(2, 6, 3, 160, 0),
|
|
202
|
-
|
|
203
|
-
'0z': new Xizage(2, 2, 0, undefined, 0),
|
|
204
|
-
'1z': new Xizage(2, 2, 1, 76, 1),
|
|
205
|
-
'4z': new Xizage(2, 6, 3, 80, 1),
|
|
206
|
-
})
|
|
207
|
-
);
|
|
208
|
-
|
|
209
|
-
private _code: string = '';
|
|
210
|
-
private _index: number = -1;
|
|
211
|
-
private _ondex: number | undefined;
|
|
212
|
-
private _raw: Uint8Array = new Uint8Array(0);
|
|
213
|
-
|
|
214
|
-
constructor({
|
|
215
|
-
raw = undefined,
|
|
216
|
-
code = IdrDex.Ed25519_Sig,
|
|
217
|
-
index = 0,
|
|
218
|
-
ondex = undefined,
|
|
219
|
-
qb64b = undefined,
|
|
220
|
-
qb64 = undefined,
|
|
221
|
-
qb2 = undefined,
|
|
222
|
-
}: IndexerArgs) {
|
|
223
|
-
if (raw != undefined) {
|
|
224
|
-
if (code == undefined) {
|
|
225
|
-
throw new EmptyMaterialError(
|
|
226
|
-
`Improper initialization need either (raw and code) or qb64b or qb64 or qb2.`
|
|
227
|
-
);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
if (!Indexer.Sizes.has(code)) {
|
|
231
|
-
throw new Error(`Unsupported code=${code}.`);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
const xizage = Indexer.Sizes.get(code)!;
|
|
235
|
-
const os = xizage.os;
|
|
236
|
-
const fs = xizage.fs;
|
|
237
|
-
const cs = xizage.hs + xizage.ss;
|
|
238
|
-
const ms = xizage.ss - xizage.os;
|
|
239
|
-
|
|
240
|
-
if (!Number.isInteger(index) || index < 0 || index > 64 ** ms - 1) {
|
|
241
|
-
throw new Error(`Invalid index=${index} for code=${code}.`);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
if (
|
|
245
|
-
ondex != undefined &&
|
|
246
|
-
xizage.os != 0 &&
|
|
247
|
-
!(ondex >= 0 && ondex <= 64 ** os - 1)
|
|
248
|
-
) {
|
|
249
|
-
throw new Error(`Invalid ondex=${ondex} for code=${code}.`);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (IdxCrtSigDex.has(code) && ondex != undefined) {
|
|
253
|
-
throw new Error(`Non None ondex=${ondex} for code=${code}.`);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
if (IdxBthSigDex.has(code)) {
|
|
257
|
-
if (ondex == undefined) {
|
|
258
|
-
ondex = index;
|
|
259
|
-
} else {
|
|
260
|
-
if (ondex != index && os == 0) {
|
|
261
|
-
throw new Error(
|
|
262
|
-
`Non matching ondex=${ondex} and index=${index} for code=${code}.`
|
|
263
|
-
);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
if (fs == undefined) {
|
|
269
|
-
throw new Error('variable length unsupported');
|
|
270
|
-
}
|
|
271
|
-
// TODO: Don't support this code
|
|
272
|
-
// if not fs: # compute fs from index
|
|
273
|
-
// if cs % 4:
|
|
274
|
-
// raise InvalidCodeSizeError(f"Whole code size not multiple of 4 for "
|
|
275
|
-
// f"variable length material. cs={cs}.")
|
|
276
|
-
// if os != 0:
|
|
277
|
-
// raise InvalidCodeSizeError(f"Non-zero other index size for "
|
|
278
|
-
// f"variable length material. os={os}.")
|
|
279
|
-
// fs = (index * 4) + cs
|
|
280
|
-
const rawsize = Math.floor(((fs - cs) * 3) / 4);
|
|
281
|
-
raw = raw.slice(0, rawsize);
|
|
282
|
-
|
|
283
|
-
if (raw.length != rawsize) {
|
|
284
|
-
throw new Error(
|
|
285
|
-
`Not enougth raw bytes for code=${code} and index=${index} ,expected ${rawsize} got ${raw.length}.`
|
|
286
|
-
);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
this._code = code;
|
|
290
|
-
this._index = index;
|
|
291
|
-
this._ondex = ondex;
|
|
292
|
-
this._raw = raw;
|
|
293
|
-
} else if (qb64b != undefined) {
|
|
294
|
-
const qb64 = d(qb64b);
|
|
295
|
-
this._exfil(qb64);
|
|
296
|
-
} else if (qb64 != undefined) {
|
|
297
|
-
this._exfil(qb64);
|
|
298
|
-
} else if (qb2 != undefined) {
|
|
299
|
-
this._bexfil(qb2);
|
|
300
|
-
} else {
|
|
301
|
-
throw new EmptyMaterialError(
|
|
302
|
-
`Improper initialization need either (raw and code and index) or qb64b or qb64 or qb2.`
|
|
303
|
-
);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
private _bexfil(qb2: Uint8Array) {
|
|
308
|
-
throw new Error(`qb2 not yet supported: ${qb2}`);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
public static _rawSize(code: string) {
|
|
312
|
-
const xizage = Indexer.Sizes.get(code)!;
|
|
313
|
-
return Math.floor(xizage.fs! - ((xizage.hs + xizage.ss) * 3) / 4);
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
get code(): string {
|
|
317
|
-
return this._code;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
get raw(): Uint8Array {
|
|
321
|
-
return this._raw;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
get index(): number {
|
|
325
|
-
return this._index;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
get ondex(): number | undefined {
|
|
329
|
-
return this._ondex;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
get qb64(): string {
|
|
333
|
-
return this._infil();
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
get qb64b() {
|
|
337
|
-
return b(this.qb64);
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
private _infil(): string {
|
|
341
|
-
const code = this.code;
|
|
342
|
-
const index = this.index;
|
|
343
|
-
const ondex = this.ondex;
|
|
344
|
-
const raw = this.raw;
|
|
345
|
-
|
|
346
|
-
const ps = (3 - (raw.length % 3)) % 3;
|
|
347
|
-
const xizage = Indexer.Sizes.get(code)!;
|
|
348
|
-
const cs = xizage.hs + xizage.ss;
|
|
349
|
-
const ms = xizage.ss - xizage.os;
|
|
350
|
-
|
|
351
|
-
// TODO: don't support this code
|
|
352
|
-
// if not fs: # compute fs from index
|
|
353
|
-
// if cs % 4:
|
|
354
|
-
// raise InvalidCodeSizeError(f"Whole code size not multiple of 4 for "
|
|
355
|
-
// f"variable length material. cs={cs}.")
|
|
356
|
-
// if os != 0:
|
|
357
|
-
// raise InvalidCodeSizeError(f"Non-zero other index size for "
|
|
358
|
-
// f"variable length material. os={os}.")
|
|
359
|
-
// fs = (index * 4) + cs
|
|
360
|
-
|
|
361
|
-
if (index < 0 || index > 64 ** ms - 1) {
|
|
362
|
-
throw new Error(`Invalid index=${index} for code=${code}.`);
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
if (
|
|
366
|
-
ondex != undefined &&
|
|
367
|
-
xizage.os != 0 &&
|
|
368
|
-
!(ondex >= 0 && ondex <= 64 ** xizage.os - 1)
|
|
369
|
-
) {
|
|
370
|
-
throw new Error(
|
|
371
|
-
`Invalid ondex=${ondex} for os=${xizage.os} and code=${code}.`
|
|
372
|
-
);
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
const both = `${code}${intToB64(index, ms)}${intToB64(
|
|
376
|
-
ondex == undefined ? 0 : ondex,
|
|
377
|
-
xizage.os
|
|
378
|
-
)}`;
|
|
379
|
-
|
|
380
|
-
if (both.length != cs) {
|
|
381
|
-
throw new Error(
|
|
382
|
-
`Mismatch code size = ${cs} with table = ${both.length}.`
|
|
383
|
-
);
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
if (cs % 4 != ps - xizage.ls) {
|
|
387
|
-
throw new Error(
|
|
388
|
-
`Invalid code=${both} for converted raw pad size=${ps}.`
|
|
389
|
-
);
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
const bytes = new Uint8Array(ps + raw.length);
|
|
393
|
-
for (let i = 0; i < ps; i++) {
|
|
394
|
-
bytes[i] = 0;
|
|
395
|
-
}
|
|
396
|
-
for (let i = 0; i < raw.length; i++) {
|
|
397
|
-
const odx = i + ps;
|
|
398
|
-
bytes[odx] = raw[i];
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
const full =
|
|
402
|
-
both + Base64.encode(Buffer.from(bytes)).slice(ps - xizage.ls);
|
|
403
|
-
if (full.length != xizage.fs) {
|
|
404
|
-
throw new Error(`Invalid code=${both} for raw size=${raw.length}.`);
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
return full;
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
_exfil(qb64: string) {
|
|
411
|
-
if (qb64.length == 0) {
|
|
412
|
-
throw new Error('Empty Material');
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
const first = qb64[0];
|
|
416
|
-
if (!Array.from(Indexer.Hards.keys()).includes(first)) {
|
|
417
|
-
throw new Error(`Unexpected code ${first}`);
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
const hs = Indexer.Hards.get(first)!;
|
|
421
|
-
if (qb64.length < hs) {
|
|
422
|
-
throw new Error(`Need ${hs - qb64.length} more characters.`);
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
const hard = qb64.slice(0, hs);
|
|
426
|
-
if (!Array.from(Indexer.Sizes.keys()).includes(hard)) {
|
|
427
|
-
throw new Error(`Unsupported code ${hard}`);
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
const xizage = Indexer.Sizes.get(hard)!;
|
|
431
|
-
const cs = xizage.hs + xizage.ss; // both hard + soft code size
|
|
432
|
-
const ms = xizage.ss - xizage.os;
|
|
433
|
-
|
|
434
|
-
if (qb64.length < cs) {
|
|
435
|
-
throw new Error(`Need ${cs - qb64.length} more characters.`);
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
const sindex = qb64.slice(hs, hs + ms);
|
|
439
|
-
const index = b64ToInt(sindex);
|
|
440
|
-
|
|
441
|
-
const sondex = qb64.slice(hs + ms, hs + ms + xizage.os);
|
|
442
|
-
let ondex;
|
|
443
|
-
if (IdxCrtSigDex.has(hard)) {
|
|
444
|
-
ondex = xizage.os != 0 ? b64ToInt(sondex) : undefined;
|
|
445
|
-
if (ondex != 0 && ondex != undefined) {
|
|
446
|
-
throw new Error(`Invalid ondex=${ondex} for code=${hard}.`);
|
|
447
|
-
} else {
|
|
448
|
-
ondex = undefined;
|
|
449
|
-
}
|
|
450
|
-
} else {
|
|
451
|
-
ondex = xizage.os != 0 ? b64ToInt(sondex) : index;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
if (xizage.fs == undefined) {
|
|
455
|
-
throw new Error('variable length not supported');
|
|
456
|
-
}
|
|
457
|
-
// TODO: support variable length
|
|
458
|
-
// if not fs: # compute fs from index which means variable length
|
|
459
|
-
// if cs % 4:
|
|
460
|
-
// raise ValidationError(f"Whole code size not multiple of 4 for "
|
|
461
|
-
// f"variable length material. cs={cs}.")
|
|
462
|
-
// if os != 0:
|
|
463
|
-
// raise ValidationError(f"Non-zero other index size for "
|
|
464
|
-
// f"variable length material. os={os}.")
|
|
465
|
-
// fs = (index * 4) + cs
|
|
466
|
-
|
|
467
|
-
if (qb64.length < xizage.fs) {
|
|
468
|
-
throw new Error(`Need ${xizage.fs - qb64.length} more chars.`);
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
qb64 = qb64.slice(0, xizage.fs);
|
|
472
|
-
const ps = cs % 4;
|
|
473
|
-
const pbs = 2 * ps != 0 ? ps : xizage.ls;
|
|
474
|
-
let raw;
|
|
475
|
-
if (ps != 0) {
|
|
476
|
-
const base = new Array(ps + 1).join('A') + qb64.slice(cs);
|
|
477
|
-
const paw = Base64.decode(base); // decode base to leave prepadded raw
|
|
478
|
-
const pi = readInt(paw.slice(0, ps)); // prepad as int
|
|
479
|
-
if (pi & (2 ** pbs - 1)) {
|
|
480
|
-
// masked pad bits non-zero
|
|
481
|
-
throw new Error(
|
|
482
|
-
`Non zeroed prepad bits = {pi & (2 ** pbs - 1 ):<06b} in {qb64b[cs:cs+1]}.`
|
|
483
|
-
);
|
|
484
|
-
}
|
|
485
|
-
raw = paw.slice(ps); // strip off ps prepad paw bytes
|
|
486
|
-
} else {
|
|
487
|
-
const base = qb64.slice(cs);
|
|
488
|
-
const paw = Base64.decode(base);
|
|
489
|
-
const li = readInt(paw.slice(0, xizage!.ls));
|
|
490
|
-
if (li != 0) {
|
|
491
|
-
if (li == 1) {
|
|
492
|
-
throw new Error(`Non zeroed lead byte = 0x{li:02x}.`);
|
|
493
|
-
} else {
|
|
494
|
-
throw new Error(`Non zeroed lead bytes = 0x{li:04x}`);
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
raw = paw.slice(xizage!.ls);
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
if (raw.length != Math.floor(((qb64.length - cs) * 3) / 4)) {
|
|
501
|
-
throw new Error(`Improperly qualified material = ${qb64}`);
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
this._code = hard;
|
|
505
|
-
this._index = index;
|
|
506
|
-
this._ondex = ondex;
|
|
507
|
-
this._raw = new Uint8Array(raw); // must be bytes for crpto opts and immutable not bytearray
|
|
508
|
-
}
|
|
509
|
-
}
|