signify-ts 0.1.1 → 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 +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 +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 -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 +7835 -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 +7811 -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 +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 +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/counter.ts
CHANGED
|
@@ -1,97 +1,151 @@
|
|
|
1
|
-
import {Codex, Sizage} from
|
|
2
|
-
import {b, b64ToInt, d, intToB64} from
|
|
1
|
+
import { Codex, Sizage } from './matter';
|
|
2
|
+
import { b, b64ToInt, d, intToB64 } from './core';
|
|
3
3
|
|
|
4
4
|
export interface CounterArgs {
|
|
5
|
-
code?: string
|
|
6
|
-
count?: number
|
|
7
|
-
countB64?: string
|
|
8
|
-
qb64b?: Uint8Array
|
|
9
|
-
qb64?: string
|
|
10
|
-
qb2?: Uint8Array
|
|
11
|
-
strip?: boolean
|
|
5
|
+
code?: string;
|
|
6
|
+
count?: number;
|
|
7
|
+
countB64?: string;
|
|
8
|
+
qb64b?: Uint8Array;
|
|
9
|
+
qb64?: string;
|
|
10
|
+
qb2?: Uint8Array;
|
|
11
|
+
strip?: boolean;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export class CounterCodex extends Codex {
|
|
15
|
-
public ControllerIdxSigs: string = '-A'
|
|
16
|
-
public WitnessIdxSigs: string = '-B'
|
|
17
|
-
public NonTransReceiptCouples: string = '-C'
|
|
18
|
-
public TransReceiptQuadruples: string = '-D'
|
|
19
|
-
public FirstSeenReplayCouples: string = '-E'
|
|
20
|
-
public TransIdxSigGroups: string = '-F'
|
|
21
|
-
public SealSourceCouples: string = '-G'
|
|
22
|
-
public TransLastIdxSigGroups: string = '-H'
|
|
23
|
-
public SealSourceTriples: string = '-I'
|
|
24
|
-
public SadPathSig: string = '-J'
|
|
25
|
-
public SadPathSigGroup: string = '-K'
|
|
26
|
-
public PathedMaterialQuadlets: string = '-L'
|
|
27
|
-
public AttachedMaterialQuadlets: string = '-V'
|
|
28
|
-
public BigAttachedMaterialQuadlets: string = '-0V'
|
|
29
|
-
public KERIProtocolStack: string = '--AAA'
|
|
15
|
+
public ControllerIdxSigs: string = '-A'; // Qualified Base64 Indexed Signature.
|
|
16
|
+
public WitnessIdxSigs: string = '-B'; // Qualified Base64 Indexed Signature.
|
|
17
|
+
public NonTransReceiptCouples: string = '-C'; // Composed Base64 Couple, pre+cig.
|
|
18
|
+
public TransReceiptQuadruples: string = '-D'; // Composed Base64 Quadruple, pre+snu+dig+sig.
|
|
19
|
+
public FirstSeenReplayCouples: string = '-E'; // Composed Base64 Couple, fnu+dts.
|
|
20
|
+
public TransIdxSigGroups: string = '-F'; // Composed Base64 Group, pre+snu+dig+ControllerIdxSigs group.
|
|
21
|
+
public SealSourceCouples: string = '-G'; // Composed Base64 couple, snu+dig of given delegators or issuers event
|
|
22
|
+
public TransLastIdxSigGroups: string = '-H'; // Composed Base64 Group, pre+ControllerIdxSigs group.
|
|
23
|
+
public SealSourceTriples: string = '-I'; // Composed Base64 triple, pre+snu+dig of anchoring source event
|
|
24
|
+
public SadPathSig: string = '-J'; // Composed Base64 Group path+TransIdxSigGroup of SAID of content
|
|
25
|
+
public SadPathSigGroup: string = '-K'; // Composed Base64 Group, root(path)+SaidPathCouples
|
|
26
|
+
public PathedMaterialQuadlets: string = '-L'; // Composed Grouped Pathed Material Quadlet (4 char each)
|
|
27
|
+
public AttachedMaterialQuadlets: string = '-V'; // Composed Grouped Attached Material Quadlet (4 char each)
|
|
28
|
+
public BigAttachedMaterialQuadlets: string = '-0V'; // Composed Grouped Attached Material Quadlet (4 char each)
|
|
29
|
+
public KERIProtocolStack: string = '--AAA'; // KERI ACDC Protocol Stack CESR Version
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
export const CtrDex = new CounterCodex()
|
|
32
|
+
export const CtrDex = new CounterCodex();
|
|
33
33
|
|
|
34
34
|
export class Counter {
|
|
35
|
-
static Sizes = new Map(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
['-
|
|
57
|
-
['-
|
|
58
|
-
['-
|
|
59
|
-
|
|
60
|
-
|
|
35
|
+
static Sizes = new Map(
|
|
36
|
+
Object.entries({
|
|
37
|
+
'-A': new Sizage(2, 2, 4, 0),
|
|
38
|
+
'-B': new Sizage(2, 2, 4, 0),
|
|
39
|
+
'-C': new Sizage(2, 2, 4, 0),
|
|
40
|
+
'-D': new Sizage(2, 2, 4, 0),
|
|
41
|
+
'-E': new Sizage(2, 2, 4, 0),
|
|
42
|
+
'-F': new Sizage(2, 2, 4, 0),
|
|
43
|
+
'-G': new Sizage(2, 2, 4, 0),
|
|
44
|
+
'-H': new Sizage(2, 2, 4, 0),
|
|
45
|
+
'-I': new Sizage(2, 2, 4, 0),
|
|
46
|
+
'-J': new Sizage(2, 2, 4, 0),
|
|
47
|
+
'-K': new Sizage(2, 2, 4, 0),
|
|
48
|
+
'-L': new Sizage(2, 2, 4, 0),
|
|
49
|
+
'-V': new Sizage(2, 2, 4, 0),
|
|
50
|
+
'-0V': new Sizage(3, 5, 8, 0),
|
|
51
|
+
'--AAA': new Sizage(5, 3, 8, 0),
|
|
52
|
+
})
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
static Hards = new Map<string, number>([
|
|
56
|
+
['-A', 2],
|
|
57
|
+
['-B', 2],
|
|
58
|
+
['-C', 2],
|
|
59
|
+
['-D', 2],
|
|
60
|
+
['-E', 2],
|
|
61
|
+
['-F', 2],
|
|
62
|
+
['-G', 2],
|
|
63
|
+
['-H', 2],
|
|
64
|
+
['-I', 2],
|
|
65
|
+
['-J', 2],
|
|
66
|
+
['-K', 2],
|
|
67
|
+
['-L', 2],
|
|
68
|
+
['-M', 2],
|
|
69
|
+
['-N', 2],
|
|
70
|
+
['-O', 2],
|
|
71
|
+
['-P', 2],
|
|
72
|
+
['-Q', 2],
|
|
73
|
+
['-R', 2],
|
|
74
|
+
['-S', 2],
|
|
75
|
+
['-T', 2],
|
|
76
|
+
['-U', 2],
|
|
77
|
+
['-V', 2],
|
|
78
|
+
['-W', 2],
|
|
79
|
+
['-X', 2],
|
|
80
|
+
['-Y', 2],
|
|
81
|
+
['-Z', 2],
|
|
82
|
+
['-a', 2],
|
|
83
|
+
['-b', 2],
|
|
84
|
+
['-c', 2],
|
|
85
|
+
['-d', 2],
|
|
86
|
+
['-e', 2],
|
|
87
|
+
['-f', 2],
|
|
88
|
+
['-g', 2],
|
|
89
|
+
['-h', 2],
|
|
90
|
+
['-i', 2],
|
|
91
|
+
['-j', 2],
|
|
92
|
+
['-k', 2],
|
|
93
|
+
['-l', 2],
|
|
94
|
+
['-m', 2],
|
|
95
|
+
['-n', 2],
|
|
96
|
+
['-o', 2],
|
|
97
|
+
['-p', 2],
|
|
98
|
+
['-q', 2],
|
|
99
|
+
['-r', 2],
|
|
100
|
+
['-s', 2],
|
|
101
|
+
['-t', 2],
|
|
102
|
+
['-u', 2],
|
|
103
|
+
['-v', 2],
|
|
104
|
+
['-w', 2],
|
|
105
|
+
['-x', 2],
|
|
106
|
+
['-y', 2],
|
|
107
|
+
['-z', 2],
|
|
108
|
+
['-0', 3],
|
|
109
|
+
['--', 5],
|
|
110
|
+
]);
|
|
111
|
+
|
|
112
|
+
private _code: string = '';
|
|
61
113
|
private _count: number = -1;
|
|
62
114
|
|
|
63
|
-
constructor({code, count, countB64, qb64b, qb64, qb2}: CounterArgs) {
|
|
115
|
+
constructor({ code, count, countB64, qb64b, qb64, qb2 }: CounterArgs) {
|
|
64
116
|
if (code != undefined) {
|
|
65
117
|
if (!Counter.Sizes.has(code)) {
|
|
66
|
-
throw new Error(`"Unsupported code=${code}.`)
|
|
118
|
+
throw new Error(`"Unsupported code=${code}.`);
|
|
67
119
|
}
|
|
68
120
|
|
|
69
|
-
|
|
70
|
-
|
|
121
|
+
const sizage = Counter.Sizes.get(code)!;
|
|
122
|
+
const cs = sizage.hs + sizage.ss;
|
|
71
123
|
if (sizage.fs != cs || cs % 4 != 0) {
|
|
72
|
-
throw new Error(
|
|
124
|
+
throw new Error(
|
|
125
|
+
`Whole code size not full size or not multiple of 4. cs=${cs} fs=${sizage.fs}.`
|
|
126
|
+
);
|
|
73
127
|
}
|
|
74
128
|
|
|
75
129
|
if (count == undefined) {
|
|
76
|
-
count = countB64 == undefined ? 1 : b64ToInt(countB64)
|
|
130
|
+
count = countB64 == undefined ? 1 : b64ToInt(countB64);
|
|
77
131
|
}
|
|
78
132
|
|
|
79
|
-
if (count < 0 || count >
|
|
80
|
-
throw new Error(`Invalid count=${count} for code=${code}.`)
|
|
133
|
+
if (count < 0 || count > 64 ** sizage.ss - 1) {
|
|
134
|
+
throw new Error(`Invalid count=${count} for code=${code}.`);
|
|
81
135
|
}
|
|
82
136
|
|
|
83
|
-
this._code = code
|
|
84
|
-
this._count = count
|
|
85
|
-
|
|
137
|
+
this._code = code;
|
|
138
|
+
this._count = count;
|
|
86
139
|
} else if (qb64b != undefined) {
|
|
87
|
-
|
|
88
|
-
this._exfil(qb64)
|
|
140
|
+
const qb64 = d(qb64b);
|
|
141
|
+
this._exfil(qb64);
|
|
89
142
|
} else if (qb64 != undefined) {
|
|
90
|
-
this._exfil(qb64)
|
|
143
|
+
this._exfil(qb64);
|
|
91
144
|
} else if (qb2 != undefined) {
|
|
92
|
-
|
|
93
145
|
} else {
|
|
94
|
-
throw new Error(
|
|
146
|
+
throw new Error(
|
|
147
|
+
`Improper initialization need either (code and count) or qb64b or qb64 or qb2.`
|
|
148
|
+
);
|
|
95
149
|
}
|
|
96
150
|
}
|
|
97
151
|
|
|
@@ -108,100 +162,112 @@ export class Counter {
|
|
|
108
162
|
}
|
|
109
163
|
|
|
110
164
|
get qb64b() {
|
|
111
|
-
return b(this.qb64)
|
|
165
|
+
return b(this.qb64);
|
|
112
166
|
}
|
|
113
167
|
|
|
114
168
|
countToB64(l?: number): string {
|
|
115
169
|
if (l == undefined) {
|
|
116
|
-
|
|
117
|
-
l = sizage.ss
|
|
170
|
+
const sizage = Counter.Sizes.get(this.code)!;
|
|
171
|
+
l = sizage.ss;
|
|
118
172
|
}
|
|
119
|
-
return intToB64(this.count, l)
|
|
173
|
+
return intToB64(this.count, l);
|
|
120
174
|
}
|
|
121
175
|
|
|
122
|
-
static semVerToB64(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
176
|
+
static semVerToB64(
|
|
177
|
+
version: string = '',
|
|
178
|
+
major: number = 0,
|
|
179
|
+
minor: number = 0,
|
|
180
|
+
patch: number = 0
|
|
181
|
+
): string {
|
|
182
|
+
let parts = [major, minor, patch];
|
|
183
|
+
if (version != '') {
|
|
184
|
+
const ssplits = version.split('.');
|
|
185
|
+
const splits = ssplits.map((x) => {
|
|
186
|
+
if (x == '') return 0;
|
|
187
|
+
return parseInt(x);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
const off = splits.length;
|
|
191
|
+
const x = 3 - off;
|
|
133
192
|
for (let i = 0; i < x; i++) {
|
|
134
|
-
splits.push(parts[i + off])
|
|
193
|
+
splits.push(parts[i + off]);
|
|
135
194
|
}
|
|
136
|
-
parts = splits
|
|
195
|
+
parts = splits;
|
|
137
196
|
}
|
|
138
197
|
|
|
139
198
|
parts.forEach((p) => {
|
|
140
|
-
if(p < 0 || p > 63) {
|
|
141
|
-
throw new Error(
|
|
199
|
+
if (p < 0 || p > 63) {
|
|
200
|
+
throw new Error(
|
|
201
|
+
`Out of bounds semantic version. Part=${p} is < 0 or > 63.`
|
|
202
|
+
);
|
|
142
203
|
}
|
|
143
|
-
})
|
|
204
|
+
});
|
|
144
205
|
|
|
145
|
-
return parts
|
|
146
|
-
|
|
147
|
-
|
|
206
|
+
return parts
|
|
207
|
+
.map((p) => {
|
|
208
|
+
return intToB64(p, 1);
|
|
209
|
+
})
|
|
210
|
+
.join('');
|
|
148
211
|
}
|
|
149
212
|
|
|
150
213
|
private _infil(): string {
|
|
151
|
-
|
|
152
|
-
|
|
214
|
+
const code = this.code;
|
|
215
|
+
const count = this.count;
|
|
153
216
|
|
|
154
|
-
|
|
155
|
-
|
|
217
|
+
const sizage = Counter.Sizes.get(code)!;
|
|
218
|
+
const cs = sizage.hs + sizage.ss;
|
|
156
219
|
if (sizage.fs != cs || cs % 4 != 0) {
|
|
157
|
-
throw new Error(
|
|
220
|
+
throw new Error(
|
|
221
|
+
`Whole code size not full size or not multiple of 4. cs=${cs} fs=${sizage.fs}.`
|
|
222
|
+
);
|
|
158
223
|
}
|
|
159
224
|
|
|
160
|
-
if (count < 0 || count >
|
|
161
|
-
throw new Error(`Invalid count=${count} for code=${code}.`)
|
|
225
|
+
if (count < 0 || count > 64 ** sizage.ss - 1) {
|
|
226
|
+
throw new Error(`Invalid count=${count} for code=${code}.`);
|
|
162
227
|
}
|
|
163
228
|
|
|
164
|
-
|
|
229
|
+
const both = `${code}${intToB64(count, sizage.ss)}`;
|
|
165
230
|
|
|
166
231
|
if (both.length % 4) {
|
|
167
|
-
throw new Error(
|
|
232
|
+
throw new Error(
|
|
233
|
+
`Invalid size = ${both.length} of ${both} not a multiple of 4.`
|
|
234
|
+
);
|
|
168
235
|
}
|
|
169
236
|
|
|
170
|
-
return both
|
|
237
|
+
return both;
|
|
171
238
|
}
|
|
172
239
|
|
|
173
240
|
private _exfil(qb64: string) {
|
|
174
241
|
if (qb64.length == 0) {
|
|
175
|
-
throw new Error(
|
|
242
|
+
throw new Error('Empty Material');
|
|
176
243
|
}
|
|
177
244
|
|
|
178
|
-
|
|
245
|
+
const first = qb64.slice(0, 2);
|
|
179
246
|
if (!Counter.Hards.has(first)) {
|
|
180
|
-
throw new Error(`Unexpected code ${first}`)
|
|
247
|
+
throw new Error(`Unexpected code ${first}`);
|
|
181
248
|
}
|
|
182
249
|
|
|
183
|
-
|
|
250
|
+
const hs = Counter.Hards.get(first)!;
|
|
184
251
|
if (qb64.length < hs) {
|
|
185
|
-
throw new Error(`Need ${hs - qb64.length} more characters.`)
|
|
252
|
+
throw new Error(`Need ${hs - qb64.length} more characters.`);
|
|
186
253
|
}
|
|
187
254
|
|
|
188
|
-
|
|
255
|
+
const hard = qb64.slice(0, hs);
|
|
189
256
|
if (!Counter.Sizes.has(hard)) {
|
|
190
|
-
throw new Error(`Unsupported code ${hard}`)
|
|
257
|
+
throw new Error(`Unsupported code ${hard}`);
|
|
191
258
|
}
|
|
192
259
|
|
|
193
|
-
|
|
194
|
-
|
|
260
|
+
const sizage = Counter.Sizes.get(hard)!;
|
|
261
|
+
const cs = sizage!.hs + sizage!.ss;
|
|
195
262
|
|
|
196
263
|
if (qb64.length < cs) {
|
|
197
|
-
throw new Error(`Need ${cs - qb64.length} more chars.`)
|
|
264
|
+
throw new Error(`Need ${cs - qb64.length} more chars.`);
|
|
198
265
|
}
|
|
199
266
|
|
|
200
|
-
|
|
201
|
-
|
|
267
|
+
const scount = qb64.slice(sizage.hs, sizage.hs + sizage.ss);
|
|
268
|
+
const count = b64ToInt(scount);
|
|
202
269
|
|
|
203
|
-
this._code = hard
|
|
204
|
-
this._count = count
|
|
270
|
+
this._code = hard;
|
|
271
|
+
this._count = count;
|
|
205
272
|
}
|
|
206
|
-
|
|
207
|
-
}
|
|
273
|
+
}
|
|
@@ -1,66 +1,80 @@
|
|
|
1
|
-
import libsodium from
|
|
2
|
-
|
|
3
|
-
import {Matter, MatterArgs, MtrDex} from './matter';
|
|
4
|
-
import {Signer} from "./signer";
|
|
5
|
-
import {Cipher} from "./cipher";
|
|
6
|
-
import {EmptyMaterialError} from "./kering";
|
|
7
|
-
import {Salter} from "./salter";
|
|
1
|
+
import libsodium from 'libsodium-wrappers-sumo';
|
|
8
2
|
|
|
3
|
+
import { Matter, MatterArgs, MtrDex } from './matter';
|
|
4
|
+
import { Signer } from './signer';
|
|
5
|
+
import { Cipher } from './cipher';
|
|
6
|
+
import { EmptyMaterialError } from './kering';
|
|
7
|
+
import { Salter } from './salter';
|
|
9
8
|
|
|
10
9
|
export class Decrypter extends Matter {
|
|
11
10
|
private readonly _decrypt: any;
|
|
12
|
-
constructor(
|
|
11
|
+
constructor(
|
|
12
|
+
{ raw, code = MtrDex.X25519_Private, qb64, qb64b, qb2 }: MatterArgs,
|
|
13
|
+
seed: Uint8Array | undefined = undefined
|
|
14
|
+
) {
|
|
13
15
|
try {
|
|
14
|
-
super({raw, code, qb64, qb64b, qb2})
|
|
15
|
-
} catch(e) {
|
|
16
|
-
if(e instanceof EmptyMaterialError) {
|
|
16
|
+
super({ raw, code, qb64, qb64b, qb2 });
|
|
17
|
+
} catch (e) {
|
|
18
|
+
if (e instanceof EmptyMaterialError) {
|
|
17
19
|
if (seed != undefined) {
|
|
18
|
-
|
|
20
|
+
const signer = new Signer({ qb64b: seed });
|
|
19
21
|
if (signer.code != MtrDex.Ed25519_Seed) {
|
|
20
|
-
throw new Error(
|
|
22
|
+
throw new Error(
|
|
23
|
+
`Unsupported signing seed derivation code ${signer.code}`
|
|
24
|
+
);
|
|
21
25
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
const sigkey = new Uint8Array(
|
|
27
|
+
signer.raw.length + signer.verfer.raw.length
|
|
28
|
+
);
|
|
29
|
+
sigkey.set(signer.raw);
|
|
30
|
+
sigkey.set(signer.verfer.raw, signer.raw.length);
|
|
31
|
+
raw =
|
|
32
|
+
libsodium.crypto_sign_ed25519_sk_to_curve25519(sigkey);
|
|
33
|
+
super({ raw, code, qb64, qb64b, qb2 });
|
|
34
|
+
} else {
|
|
35
|
+
throw e;
|
|
30
36
|
}
|
|
31
37
|
} else {
|
|
32
|
-
throw e
|
|
38
|
+
throw e;
|
|
33
39
|
}
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
if (this.code == MtrDex.X25519_Private) {
|
|
37
|
-
this._decrypt = this._x25519
|
|
43
|
+
this._decrypt = this._x25519;
|
|
38
44
|
} else {
|
|
39
|
-
throw new Error(`Unsupported decrypter code = ${this.code}.`)
|
|
45
|
+
throw new Error(`Unsupported decrypter code = ${this.code}.`);
|
|
40
46
|
}
|
|
41
47
|
}
|
|
42
48
|
|
|
43
|
-
decrypt(
|
|
49
|
+
decrypt(
|
|
50
|
+
ser: Uint8Array | null = null,
|
|
51
|
+
cipher: Cipher | null = null,
|
|
52
|
+
transferable: boolean = false
|
|
53
|
+
) {
|
|
44
54
|
if (ser == null && cipher == null) {
|
|
45
|
-
throw new EmptyMaterialError(
|
|
55
|
+
throw new EmptyMaterialError('Neither ser or cipher were provided');
|
|
46
56
|
}
|
|
47
57
|
|
|
48
58
|
if (ser != null) {
|
|
49
|
-
cipher = new Cipher({qb64b: ser})
|
|
59
|
+
cipher = new Cipher({ qb64b: ser });
|
|
50
60
|
}
|
|
51
61
|
|
|
52
|
-
return this._decrypt(cipher, this.raw, transferable)
|
|
62
|
+
return this._decrypt(cipher, this.raw, transferable);
|
|
53
63
|
}
|
|
54
64
|
|
|
55
65
|
_x25519(cipher: Cipher, prikey: Uint8Array, transferable: boolean = false) {
|
|
56
|
-
|
|
57
|
-
|
|
66
|
+
const pubkey = libsodium.crypto_scalarmult_base(prikey);
|
|
67
|
+
const plain = libsodium.crypto_box_seal_open(
|
|
68
|
+
cipher.raw,
|
|
69
|
+
pubkey,
|
|
70
|
+
prikey
|
|
71
|
+
);
|
|
58
72
|
if (cipher.code == MtrDex.X25519_Cipher_Salt) {
|
|
59
|
-
return new Salter({qb64b: plain})
|
|
73
|
+
return new Salter({ qb64b: plain });
|
|
60
74
|
} else if (cipher.code == MtrDex.X25519_Cipher_Seed) {
|
|
61
|
-
return new Signer({qb64b: plain, transferable: transferable})
|
|
75
|
+
return new Signer({ qb64b: plain, transferable: transferable });
|
|
62
76
|
} else {
|
|
63
|
-
throw new Error(`Unsupported cipher text code == ${cipher.code}`)
|
|
77
|
+
throw new Error(`Unsupported cipher text code == ${cipher.code}`);
|
|
64
78
|
}
|
|
65
79
|
}
|
|
66
|
-
}
|
|
80
|
+
}
|
package/src/keri/core/diger.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { blake3 } from '@noble/hashes/blake3';
|
|
2
2
|
|
|
3
|
-
import {Matter, MatterArgs, MtrDex} from './matter';
|
|
3
|
+
import { Matter, MatterArgs, MtrDex } from './matter';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @description : Diger is subset of Matter and is used to verify the digest of serialization
|
|
@@ -10,21 +10,25 @@ import {Matter, MatterArgs, MtrDex} from './matter';
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
export class Diger extends Matter {
|
|
13
|
-
private readonly _verify: any
|
|
13
|
+
private readonly _verify: any;
|
|
14
14
|
|
|
15
15
|
// This constructor will assign digest verification function to ._verify
|
|
16
|
-
constructor(
|
|
16
|
+
constructor(
|
|
17
|
+
{ raw, code = MtrDex.Blake3_256, qb64, qb64b, qb2 }: MatterArgs,
|
|
18
|
+
ser: Uint8Array | null = null
|
|
19
|
+
) {
|
|
17
20
|
try {
|
|
18
|
-
super({raw, code, qb64, qb64b, qb2});
|
|
21
|
+
super({ raw, code, qb64, qb64b, qb2 });
|
|
19
22
|
} catch (error) {
|
|
20
23
|
if (ser == null) {
|
|
21
24
|
throw error;
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
if (code === MtrDex.Blake3_256) {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
const dig = Buffer.from(
|
|
29
|
+
blake3.create({ dkLen: 32 }).update(ser).digest()
|
|
30
|
+
);
|
|
31
|
+
super({ raw: dig, code: code });
|
|
28
32
|
} else {
|
|
29
33
|
throw new Error(`Unsupported code = ${code} for digester.`);
|
|
30
34
|
}
|
|
@@ -37,7 +41,6 @@ export class Diger extends Matter {
|
|
|
37
41
|
}
|
|
38
42
|
}
|
|
39
43
|
|
|
40
|
-
|
|
41
44
|
/**
|
|
42
45
|
*
|
|
43
46
|
* @param {Uint8Array} ser serialization bytes
|
|
@@ -49,34 +52,32 @@ export class Diger extends Matter {
|
|
|
49
52
|
return this._verify(ser, this.raw);
|
|
50
53
|
}
|
|
51
54
|
|
|
52
|
-
compare(ser: Uint8Array, dig: any = null, diger: Diger | null = null
|
|
55
|
+
compare(ser: Uint8Array, dig: any = null, diger: Diger | null = null) {
|
|
53
56
|
if (dig != null) {
|
|
54
57
|
if (dig.toString() == this.qb64) {
|
|
55
|
-
return true
|
|
58
|
+
return true;
|
|
56
59
|
}
|
|
57
60
|
|
|
58
|
-
diger = new Diger({qb64b: dig})
|
|
61
|
+
diger = new Diger({ qb64b: dig });
|
|
59
62
|
} else if (diger != null) {
|
|
60
63
|
if (diger.qb64b == this.qb64b) {
|
|
61
64
|
return true;
|
|
62
65
|
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
else {
|
|
66
|
-
throw new Error("Both dig and diger may not be None.")
|
|
66
|
+
} else {
|
|
67
|
+
throw new Error('Both dig and diger may not be None.');
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
if (diger.code == this.code) {
|
|
70
|
-
return false
|
|
71
|
+
return false;
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
return diger.verify(ser) && this.verify(ser)
|
|
74
|
+
return diger.verify(ser) && this.verify(ser);
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
|
|
77
77
|
blake3_256(ser: Uint8Array, dig: any) {
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
const digest = Buffer.from(
|
|
79
|
+
blake3.create({ dkLen: 32 }).update(ser).digest()
|
|
80
|
+
);
|
|
81
|
+
return digest.toString() === dig.toString();
|
|
81
82
|
}
|
|
82
83
|
}
|