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/matter.ts
CHANGED
|
@@ -1,138 +1,339 @@
|
|
|
1
|
-
import {EmptyMaterialError} from
|
|
1
|
+
import { EmptyMaterialError } from './kering';
|
|
2
2
|
|
|
3
|
-
import {intToB64, readInt} from './core';
|
|
4
|
-
import Base64 from
|
|
5
|
-
import {b, d} from
|
|
3
|
+
import { intToB64, readInt } from './core';
|
|
4
|
+
import Base64 from 'urlsafe-base64';
|
|
5
|
+
import { b, d } from './core';
|
|
6
6
|
import { Buffer } from 'buffer';
|
|
7
7
|
|
|
8
8
|
export class Codex {
|
|
9
9
|
has(prop: string): boolean {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const m = new Map(
|
|
11
|
+
Array.from(Object.entries(this), (v) => [v[1], v[0]])
|
|
12
|
+
);
|
|
13
|
+
return m.has(prop);
|
|
12
14
|
}
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
export class MatterCodex extends Codex {
|
|
16
|
-
Ed25519_Seed:
|
|
17
|
-
Ed25519N:
|
|
18
|
-
X25519:
|
|
19
|
-
Ed25519:
|
|
20
|
-
Blake3_256:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
|
26
44
|
}
|
|
27
45
|
|
|
28
|
-
export const MtrDex = new MatterCodex()
|
|
29
|
-
|
|
46
|
+
export const MtrDex = new MatterCodex();
|
|
30
47
|
|
|
31
48
|
export class NonTransCodex extends Codex {
|
|
32
|
-
Ed25519N: string = 'B'
|
|
33
|
-
ECDSA_256k1N: string = '1AAA'
|
|
34
|
-
Ed448N: string = '1AAC'
|
|
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.
|
|
35
53
|
}
|
|
36
54
|
|
|
37
|
-
export const NonTransDex = new NonTransCodex()
|
|
38
|
-
|
|
55
|
+
export const NonTransDex = new NonTransCodex();
|
|
39
56
|
|
|
40
57
|
export class DigiCodex extends Codex {
|
|
41
|
-
Blake3_256: string = 'E'
|
|
42
|
-
Blake2b_256: string = 'F'
|
|
43
|
-
Blake2s_256: string = 'G'
|
|
44
|
-
SHA3_256: string = 'H'
|
|
45
|
-
SHA2_256: string = 'I'
|
|
46
|
-
Blake3_512: string = '0D'
|
|
47
|
-
Blake2b_512: string = '0E'
|
|
48
|
-
SHA3_512: string = '0F'
|
|
49
|
-
SHA2_512: string = '0G'
|
|
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)
|
|
50
76
|
}
|
|
51
77
|
|
|
52
|
-
export const
|
|
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();
|
|
53
106
|
|
|
54
107
|
export class Sizage {
|
|
55
108
|
public hs: number;
|
|
56
109
|
public ss: number;
|
|
57
|
-
public ls
|
|
58
|
-
public fs
|
|
110
|
+
public ls?: number;
|
|
111
|
+
public fs?: number;
|
|
59
112
|
|
|
60
|
-
constructor(hs: number, ss: number, fs
|
|
113
|
+
constructor(hs: number, ss: number, fs?: number, ls?: number) {
|
|
61
114
|
this.hs = hs;
|
|
62
115
|
this.ss = ss;
|
|
63
116
|
this.fs = fs;
|
|
64
|
-
this.ls = ls
|
|
117
|
+
this.ls = ls!;
|
|
65
118
|
}
|
|
66
119
|
}
|
|
67
120
|
|
|
68
121
|
export interface MatterArgs {
|
|
69
|
-
raw?: Uint8Array | undefined
|
|
70
|
-
code?: string
|
|
71
|
-
qb64b?: Uint8Array | undefined
|
|
72
|
-
qb64?: string
|
|
73
|
-
qb2?: Uint8Array | undefined
|
|
122
|
+
raw?: Uint8Array | undefined;
|
|
123
|
+
code?: string;
|
|
124
|
+
qb64b?: Uint8Array | undefined;
|
|
125
|
+
qb64?: string;
|
|
126
|
+
qb2?: Uint8Array | undefined;
|
|
127
|
+
rize?: number;
|
|
74
128
|
}
|
|
75
129
|
|
|
76
130
|
export class Matter {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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 = '';
|
|
100
252
|
private _size: number = -1;
|
|
101
253
|
private _raw: Uint8Array = new Uint8Array(0);
|
|
102
254
|
|
|
103
|
-
constructor({
|
|
104
|
-
|
|
105
|
-
|
|
255
|
+
constructor({
|
|
256
|
+
raw,
|
|
257
|
+
code = MtrDex.Ed25519N,
|
|
258
|
+
qb64b,
|
|
259
|
+
qb64,
|
|
260
|
+
qb2,
|
|
261
|
+
rize,
|
|
262
|
+
}: MatterArgs) {
|
|
263
|
+
let size = -1;
|
|
106
264
|
if (raw != undefined) {
|
|
107
265
|
if (code.length == 0) {
|
|
108
|
-
throw new Error(
|
|
266
|
+
throw new Error(
|
|
267
|
+
'Improper initialization need either (raw and code) or qb64b or qb64 or qb2.'
|
|
268
|
+
);
|
|
109
269
|
}
|
|
110
270
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
+
}
|
|
116
280
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
+
}
|
|
122
314
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
+
}
|
|
126
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
|
|
127
328
|
} else if (qb64 !== undefined) {
|
|
128
|
-
this._exfil(qb64)
|
|
329
|
+
this._exfil(qb64);
|
|
129
330
|
} else if (qb64b !== undefined) {
|
|
130
|
-
|
|
131
|
-
this._exfil(qb64)
|
|
331
|
+
const qb64 = d(qb64b);
|
|
332
|
+
this._exfil(qb64);
|
|
132
333
|
} else if (qb2 !== undefined) {
|
|
133
|
-
this._bexfil(qb2)
|
|
334
|
+
this._bexfil(qb2);
|
|
134
335
|
} else {
|
|
135
|
-
throw new EmptyMaterialError(
|
|
336
|
+
throw new EmptyMaterialError('EmptyMaterialError');
|
|
136
337
|
}
|
|
137
338
|
}
|
|
138
339
|
|
|
@@ -145,7 +346,7 @@ export class Matter {
|
|
|
145
346
|
}
|
|
146
347
|
|
|
147
348
|
get raw(): Uint8Array {
|
|
148
|
-
return this._raw
|
|
349
|
+
return this._raw;
|
|
149
350
|
}
|
|
150
351
|
|
|
151
352
|
get qb64() {
|
|
@@ -153,135 +354,168 @@ export class Matter {
|
|
|
153
354
|
}
|
|
154
355
|
|
|
155
356
|
get qb64b() {
|
|
156
|
-
return b(this.qb64)
|
|
357
|
+
return b(this.qb64);
|
|
157
358
|
}
|
|
158
359
|
|
|
159
360
|
get transferable(): boolean {
|
|
160
|
-
return !NonTransDex.has(this.code)
|
|
361
|
+
return !NonTransDex.has(this.code);
|
|
161
362
|
}
|
|
162
363
|
|
|
163
364
|
get digestive(): boolean {
|
|
164
|
-
return DigiDex.has(this.code)
|
|
365
|
+
return DigiDex.has(this.code);
|
|
165
366
|
}
|
|
166
367
|
|
|
167
368
|
static _rawSize(code: string) {
|
|
168
|
-
|
|
169
|
-
|
|
369
|
+
const sizage = this.Sizes.get(code); // get sizes
|
|
370
|
+
const cs = sizage!.hs + sizage!.ss; // both hard + soft code size
|
|
170
371
|
if (sizage!.fs === -1) {
|
|
171
|
-
throw Error(`Non-fixed raw size code ${code}.`)
|
|
372
|
+
throw Error(`Non-fixed raw size code ${code}.`);
|
|
172
373
|
}
|
|
173
374
|
|
|
174
|
-
return
|
|
175
|
-
|
|
375
|
+
return Math.floor(((sizage!.fs! - cs) * 3) / 4) - sizage!.ls!;
|
|
176
376
|
}
|
|
177
377
|
|
|
178
378
|
static _leadSize(code: string) {
|
|
179
|
-
|
|
180
|
-
return sizage!.ls
|
|
379
|
+
const sizage = this.Sizes.get(code);
|
|
380
|
+
return sizage!.ls;
|
|
181
381
|
}
|
|
182
382
|
|
|
183
383
|
get both() {
|
|
184
|
-
|
|
185
|
-
return `${this.code}${intToB64(this.size, sizage!.
|
|
384
|
+
const sizage = Matter.Sizes.get(this.code);
|
|
385
|
+
return `${this.code}${intToB64(this.size, sizage!.ss)}`;
|
|
186
386
|
}
|
|
187
387
|
|
|
188
|
-
|
|
189
388
|
private _infil() {
|
|
190
|
-
|
|
191
|
-
|
|
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
|
+
}
|
|
192
407
|
|
|
193
|
-
|
|
194
|
-
|
|
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
|
+
}
|
|
195
423
|
|
|
196
|
-
|
|
197
|
-
throw new Error("Variable sized codes not supported... yet");
|
|
424
|
+
return both + Base64.encode(Buffer.from(bytes));
|
|
198
425
|
} else {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
if (
|
|
202
|
-
|
|
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
|
+
);
|
|
203
433
|
}
|
|
204
434
|
// prepad, convert, and replace upfront
|
|
205
435
|
// when fixed and ls != 0 then cs % 4 is zero and ps==ls
|
|
206
436
|
// otherwise fixed and ls == 0 then cs % 4 == ps
|
|
207
|
-
|
|
437
|
+
const bytes = new Uint8Array(ps + raw.length);
|
|
208
438
|
for (let i = 0; i < ps; i++) {
|
|
209
439
|
bytes[i] = 0;
|
|
210
440
|
}
|
|
211
441
|
for (let i = 0; i < raw.length; i++) {
|
|
212
|
-
|
|
442
|
+
const odx = i + ps;
|
|
213
443
|
bytes[odx] = raw[i];
|
|
214
444
|
}
|
|
215
445
|
|
|
216
|
-
return both + Base64.encode(Buffer.from(bytes)).slice(cs % 4)
|
|
446
|
+
return both + Base64.encode(Buffer.from(bytes)).slice(cs % 4);
|
|
217
447
|
}
|
|
218
448
|
}
|
|
219
449
|
|
|
220
450
|
private _exfil(qb64: string) {
|
|
221
451
|
if (qb64.length == 0) {
|
|
222
|
-
throw new Error(
|
|
452
|
+
throw new Error('Empty Material');
|
|
223
453
|
}
|
|
224
454
|
|
|
225
|
-
|
|
455
|
+
const first = qb64[0];
|
|
226
456
|
if (!Array.from(Matter.Hards.keys()).includes(first)) {
|
|
227
|
-
throw new Error(`Unexpected code ${first}`)
|
|
457
|
+
throw new Error(`Unexpected code ${first}`);
|
|
228
458
|
}
|
|
229
459
|
|
|
230
|
-
|
|
460
|
+
const hs = Matter.Hards.get(first);
|
|
231
461
|
if (qb64.length < hs!) {
|
|
232
|
-
throw new Error(`Shortage Error`)
|
|
462
|
+
throw new Error(`Shortage Error`);
|
|
233
463
|
}
|
|
234
464
|
|
|
235
|
-
|
|
465
|
+
const hard = qb64.slice(0, hs);
|
|
236
466
|
if (!Array.from(Matter.Sizes.keys()).includes(hard)) {
|
|
237
|
-
throw new Error(`Unsupported code ${hard}`)
|
|
467
|
+
throw new Error(`Unsupported code ${hard}`);
|
|
238
468
|
}
|
|
239
469
|
|
|
240
|
-
|
|
241
|
-
|
|
470
|
+
const sizage = Matter.Sizes.get(hard);
|
|
471
|
+
const cs = sizage!.hs + sizage!.ss;
|
|
242
472
|
let size = -1;
|
|
243
|
-
if (sizage!.fs == -1) {
|
|
244
|
-
|
|
473
|
+
if (sizage!.fs == -1) {
|
|
474
|
+
// Variable size code, Not supported
|
|
475
|
+
throw new Error('Variable size codes not supported yet');
|
|
245
476
|
} else {
|
|
246
|
-
size = sizage!.fs
|
|
477
|
+
size = sizage!.fs!;
|
|
247
478
|
}
|
|
248
479
|
|
|
249
|
-
if (qb64.length < sizage!.fs) {
|
|
250
|
-
throw new Error(`Need ${sizage!.fs - qb64.length} more chars.`)
|
|
480
|
+
if (qb64.length < sizage!.fs!) {
|
|
481
|
+
throw new Error(`Need ${sizage!.fs! - qb64.length} more chars.`);
|
|
251
482
|
}
|
|
252
483
|
|
|
253
|
-
qb64 = qb64.slice(0, sizage!.fs)
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
let raw
|
|
484
|
+
qb64 = qb64.slice(0, sizage!.fs);
|
|
485
|
+
const ps = cs % 4;
|
|
486
|
+
const pbs = 2 * (ps == 0 ? sizage!.ls! : ps);
|
|
487
|
+
let raw;
|
|
257
488
|
if (ps != 0) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
if (pi & (2 ** pbs - 1)) {
|
|
262
|
-
|
|
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
|
+
);
|
|
263
497
|
}
|
|
264
|
-
raw = paw.subarray(ps)
|
|
498
|
+
raw = paw.subarray(ps); // strip off ps prepad paw bytes
|
|
265
499
|
} else {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
500
|
+
const base = qb64.slice(cs);
|
|
501
|
+
const paw = Base64.decode(base);
|
|
502
|
+
const li = readInt(paw.subarray(0, sizage!.ls));
|
|
269
503
|
if (li != 0) {
|
|
270
504
|
if (li == 1) {
|
|
271
|
-
throw new Error(`Non zeroed lead byte = 0x{li:02x}.`)
|
|
505
|
+
throw new Error(`Non zeroed lead byte = 0x{li:02x}.`);
|
|
272
506
|
} else {
|
|
273
|
-
throw new Error(`Non zeroed lead bytes = 0x{li:04x}`)
|
|
507
|
+
throw new Error(`Non zeroed lead bytes = 0x{li:04x}`);
|
|
274
508
|
}
|
|
275
509
|
}
|
|
276
|
-
raw = paw.subarray(sizage!.ls)
|
|
510
|
+
raw = paw.subarray(sizage!.ls);
|
|
277
511
|
}
|
|
278
512
|
|
|
279
|
-
this._code = hard
|
|
280
|
-
this._size = size
|
|
281
|
-
this._raw = Uint8Array.from(raw)
|
|
513
|
+
this._code = hard; // hard only
|
|
514
|
+
this._size = size;
|
|
515
|
+
this._raw = Uint8Array.from(raw); // ensure bytes so immutable and for crypto ops
|
|
282
516
|
}
|
|
283
517
|
|
|
284
518
|
private _bexfil(qb2: Uint8Array) {
|
|
285
|
-
throw new Error(`qb2 not yet supported: ${qb2}`)
|
|
519
|
+
throw new Error(`qb2 not yet supported: ${qb2}`);
|
|
286
520
|
}
|
|
287
521
|
}
|