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