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