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