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/manager.ts
CHANGED
|
@@ -1,65 +1,67 @@
|
|
|
1
|
-
import {Encrypter} from
|
|
2
|
-
import {Decrypter} from
|
|
3
|
-
import {Salter, Tier} from
|
|
4
|
-
import {Signer} from
|
|
5
|
-
import {Verfer} from
|
|
6
|
-
import {MtrDex} from
|
|
7
|
-
import {Diger} from
|
|
8
|
-
import {Cigar} from
|
|
9
|
-
import {Siger} from
|
|
10
|
-
import {b} from
|
|
11
|
-
|
|
1
|
+
import { Encrypter } from './encrypter';
|
|
2
|
+
import { Decrypter } from './decrypter';
|
|
3
|
+
import { Salter, Tier } from './salter';
|
|
4
|
+
import { Signer } from './signer';
|
|
5
|
+
import { Verfer } from './verfer';
|
|
6
|
+
import { MtrDex } from './matter';
|
|
7
|
+
import { Diger } from './diger';
|
|
8
|
+
import { Cigar } from './cigar';
|
|
9
|
+
import { Siger } from './siger';
|
|
10
|
+
import { b } from './core';
|
|
12
11
|
|
|
13
12
|
export enum Algos {
|
|
14
|
-
randy =
|
|
15
|
-
salty =
|
|
13
|
+
randy = 'randy',
|
|
14
|
+
salty = 'salty',
|
|
15
|
+
group = 'group',
|
|
16
|
+
extern = 'extern',
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
class PubLot {
|
|
19
|
-
public pubs: Array<string> = new Array<string>()
|
|
20
|
-
public ridx: number = 0
|
|
21
|
-
public kidx: number = 0
|
|
22
|
-
public dt:string =
|
|
20
|
+
public pubs: Array<string> = new Array<string>(); // list qb64 public keys.
|
|
21
|
+
public ridx: number = 0; // index of rotation (est event) that uses public key set
|
|
22
|
+
public kidx: number = 0; // index of key in sequence of public keys
|
|
23
|
+
public dt: string = ''; // datetime ISO8601 when key set created
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
class PreSit {
|
|
26
|
-
public old: PubLot = new PubLot()
|
|
27
|
-
public new: PubLot = new PubLot()
|
|
28
|
-
public nxt: PubLot = new PubLot()
|
|
27
|
+
public old: PubLot = new PubLot(); //previous publot
|
|
28
|
+
public new: PubLot = new PubLot(); //newly current publot
|
|
29
|
+
public nxt: PubLot = new PubLot(); //next public publot
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
class PrePrm {
|
|
32
|
-
public pidx: number = 0
|
|
33
|
-
public algo: Algos = Algos.salty
|
|
34
|
-
public salt: string = ''
|
|
35
|
-
public stem: string = ''
|
|
36
|
-
public tier: string = ''
|
|
37
|
-
|
|
33
|
+
public pidx: number = 0; // prefix index for this keypair sequence
|
|
34
|
+
public algo: Algos = Algos.salty; // salty default uses indices and salt to create new key pairs
|
|
35
|
+
public salt: string = ''; // empty salt used for salty algo.
|
|
36
|
+
public stem: string = ''; // default unique path stem for salty algo
|
|
37
|
+
public tier: string = ''; // security tier for stretch index salty algo
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
class PubSet {
|
|
41
|
-
pubs: Array<string> = new Array<string>() // list qb64 public keys.
|
|
41
|
+
pubs: Array<string> = new Array<string>(); // list qb64 public keys.
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
class PubPath {
|
|
45
|
-
path: string =
|
|
46
|
-
code: string =
|
|
47
|
-
tier: string = Tier.high
|
|
48
|
-
temp: boolean = false
|
|
45
|
+
path: string = '';
|
|
46
|
+
code: string = '';
|
|
47
|
+
tier: string = Tier.high;
|
|
48
|
+
temp: boolean = false;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
class Keys {
|
|
52
|
-
private readonly _signers: Array<Signer
|
|
53
|
-
private readonly _paths?: Array<string
|
|
52
|
+
private readonly _signers: Array<Signer>;
|
|
53
|
+
private readonly _paths?: Array<string>;
|
|
54
54
|
|
|
55
55
|
constructor(signers: Array<Signer>, paths?: Array<string>) {
|
|
56
|
-
this._signers = signers
|
|
56
|
+
this._signers = signers;
|
|
57
57
|
if (paths != undefined) {
|
|
58
58
|
if (signers.length != paths.length) {
|
|
59
|
-
throw new Error(
|
|
59
|
+
throw new Error(
|
|
60
|
+
'If paths are provided, they must be the same length as signers'
|
|
61
|
+
);
|
|
60
62
|
}
|
|
61
63
|
}
|
|
62
|
-
this._paths = paths
|
|
64
|
+
this._paths = paths;
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
get paths(): Array<string> | undefined {
|
|
@@ -72,52 +74,65 @@ class Keys {
|
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
export interface Creator {
|
|
75
|
-
create(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
create(
|
|
78
|
+
codes: Array<string> | undefined,
|
|
79
|
+
count: number,
|
|
80
|
+
code: string,
|
|
81
|
+
transferable: boolean,
|
|
82
|
+
pidx: number,
|
|
83
|
+
ridx: number,
|
|
84
|
+
kidx: number,
|
|
85
|
+
temp: boolean
|
|
86
|
+
): Keys;
|
|
87
|
+
salt: string;
|
|
88
|
+
stem: string;
|
|
89
|
+
tier: Tier;
|
|
80
90
|
}
|
|
81
91
|
|
|
82
92
|
export class RandyCreator implements Creator {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
93
|
+
create(
|
|
94
|
+
codes: Array<string> | undefined = undefined,
|
|
95
|
+
count: number = 1,
|
|
96
|
+
code: string = MtrDex.Ed25519_Seed,
|
|
97
|
+
transferable: boolean = true
|
|
98
|
+
): Keys {
|
|
99
|
+
const signers = new Array<Signer>();
|
|
87
100
|
if (codes == undefined) {
|
|
88
|
-
codes = new Array(count).fill(code)
|
|
101
|
+
codes = new Array(count).fill(code);
|
|
89
102
|
}
|
|
90
103
|
|
|
91
|
-
codes.forEach(function(code) {
|
|
92
|
-
signers.push(
|
|
93
|
-
|
|
104
|
+
codes.forEach(function (code) {
|
|
105
|
+
signers.push(
|
|
106
|
+
new Signer({ code: code, transferable: transferable })
|
|
107
|
+
);
|
|
108
|
+
});
|
|
94
109
|
|
|
95
|
-
return new Keys(signers)
|
|
110
|
+
return new Keys(signers);
|
|
96
111
|
}
|
|
97
112
|
|
|
98
113
|
get salt(): string {
|
|
99
|
-
return
|
|
114
|
+
return '';
|
|
100
115
|
}
|
|
101
116
|
|
|
102
117
|
get stem(): string {
|
|
103
|
-
return
|
|
118
|
+
return '';
|
|
104
119
|
}
|
|
105
120
|
|
|
106
121
|
get tier(): Tier {
|
|
107
|
-
return
|
|
122
|
+
return '' as Tier;
|
|
108
123
|
}
|
|
109
124
|
}
|
|
110
125
|
|
|
111
126
|
export class SaltyCreator implements Creator {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
this.
|
|
120
|
-
|
|
127
|
+
public salter: Salter;
|
|
128
|
+
private readonly _stem: string;
|
|
129
|
+
constructor(
|
|
130
|
+
salt: string | undefined = undefined,
|
|
131
|
+
tier: Tier | undefined = undefined,
|
|
132
|
+
stem: string | undefined = undefined
|
|
133
|
+
) {
|
|
134
|
+
this.salter = new Salter({ qb64: salt, tier: tier });
|
|
135
|
+
this._stem = stem == undefined ? '' : stem;
|
|
121
136
|
}
|
|
122
137
|
|
|
123
138
|
get salt(): string {
|
|
@@ -132,721 +147,870 @@ export class SaltyCreator implements Creator {
|
|
|
132
147
|
return this.salter.tier!;
|
|
133
148
|
}
|
|
134
149
|
|
|
135
|
-
create(
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
150
|
+
create(
|
|
151
|
+
codes: Array<string> | undefined = undefined,
|
|
152
|
+
count: number = 1,
|
|
153
|
+
code: string = MtrDex.Ed25519_Seed,
|
|
154
|
+
transferable: boolean = true,
|
|
155
|
+
pidx: number = 0,
|
|
156
|
+
ridx: number = 0,
|
|
157
|
+
kidx: number = 0,
|
|
158
|
+
temp: boolean = false
|
|
159
|
+
): Keys {
|
|
160
|
+
const signers = new Array<Signer>();
|
|
161
|
+
const paths = new Array<string>();
|
|
141
162
|
|
|
142
163
|
if (codes == undefined) {
|
|
143
|
-
codes = new Array<string>(count).fill(code)
|
|
164
|
+
codes = new Array<string>(count).fill(code);
|
|
144
165
|
}
|
|
145
166
|
|
|
146
167
|
codes.forEach((code, idx) => {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
168
|
+
// Previuos definition of path
|
|
169
|
+
// let path = this.stem + pidx.toString(16) + ridx.toString(16) + (kidx+idx).toString(16)
|
|
170
|
+
const path =
|
|
171
|
+
this.stem == ''
|
|
172
|
+
? pidx.toString(16)
|
|
173
|
+
: this.stem + ridx.toString(16) + (kidx + idx).toString(16);
|
|
174
|
+
|
|
175
|
+
signers.push(
|
|
176
|
+
this.salter.signer(code, transferable, path, this.tier, temp)
|
|
177
|
+
);
|
|
178
|
+
paths.push(path);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
return new Keys(signers, paths);
|
|
153
182
|
}
|
|
154
183
|
}
|
|
155
184
|
|
|
156
185
|
export class Creatory {
|
|
157
|
-
private readonly _make: any
|
|
186
|
+
private readonly _make: any;
|
|
158
187
|
constructor(algo: Algos = Algos.salty) {
|
|
159
|
-
switch(algo) {
|
|
188
|
+
switch (algo) {
|
|
160
189
|
case Algos.randy:
|
|
161
|
-
this._make = this._makeRandy
|
|
190
|
+
this._make = this._makeRandy;
|
|
162
191
|
break;
|
|
163
192
|
case Algos.salty:
|
|
164
|
-
this._make = this._makeSalty
|
|
193
|
+
this._make = this._makeSalty;
|
|
165
194
|
break;
|
|
166
195
|
default:
|
|
167
|
-
throw new Error(`unsupported algo=${algo}`)
|
|
196
|
+
throw new Error(`unsupported algo=${algo}`);
|
|
168
197
|
}
|
|
169
198
|
}
|
|
170
199
|
|
|
171
200
|
make(...args: any[]): Creator {
|
|
172
|
-
return this._make(...args)
|
|
201
|
+
return this._make(...args);
|
|
173
202
|
}
|
|
174
203
|
|
|
175
204
|
_makeRandy(): Creator {
|
|
176
|
-
return new RandyCreator()
|
|
205
|
+
return new RandyCreator();
|
|
177
206
|
}
|
|
178
207
|
|
|
179
208
|
_makeSalty(...args: any[]): Creator {
|
|
180
|
-
return new SaltyCreator(...args)
|
|
209
|
+
return new SaltyCreator(...args);
|
|
181
210
|
}
|
|
182
211
|
}
|
|
183
212
|
|
|
184
213
|
export function openManager(passcode: string, salt?: string) {
|
|
185
214
|
if (passcode.length < 21) {
|
|
186
|
-
throw new Error(
|
|
215
|
+
throw new Error('Bran (passcode seed material) too short.');
|
|
187
216
|
}
|
|
188
217
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
218
|
+
const bran = MtrDex.Salt_128 + 'A' + passcode.substring(0, 21); // qb64 salt for seed
|
|
219
|
+
const signer = new Salter({ qb64: bran }).signer(
|
|
220
|
+
MtrDex.Ed25519_Seed,
|
|
221
|
+
false
|
|
222
|
+
);
|
|
223
|
+
const seed = signer.qb64;
|
|
224
|
+
const aeid = signer.verfer.qb64; // lest it remove encryption
|
|
193
225
|
|
|
194
226
|
let algo;
|
|
195
227
|
|
|
228
|
+
const salter = salt != undefined ? new Salter({ qb64: salt }) : undefined;
|
|
196
229
|
if (salt != undefined) {
|
|
197
|
-
algo = Algos.salty
|
|
198
|
-
salt = new Salter({qb64: salt}).qb64
|
|
230
|
+
algo = Algos.salty;
|
|
199
231
|
} else {
|
|
200
|
-
algo = Algos.randy
|
|
232
|
+
algo = Algos.randy;
|
|
201
233
|
}
|
|
202
234
|
|
|
203
|
-
return new Manager({seed: seed, aeid: aeid, algo: algo,
|
|
235
|
+
return new Manager({ seed: seed, aeid: aeid, algo: algo, salter: salter });
|
|
204
236
|
}
|
|
205
237
|
|
|
206
238
|
export interface ManagerArgs {
|
|
207
|
-
ks?: KeyStore | undefined
|
|
208
|
-
seed?: string | undefined
|
|
209
|
-
aeid?: string | undefined
|
|
210
|
-
pidx?: number | undefined
|
|
211
|
-
algo?: Algos | undefined
|
|
212
|
-
|
|
213
|
-
tier?: string | undefined
|
|
239
|
+
ks?: KeyStore | undefined;
|
|
240
|
+
seed?: string | undefined;
|
|
241
|
+
aeid?: string | undefined;
|
|
242
|
+
pidx?: number | undefined;
|
|
243
|
+
algo?: Algos | undefined;
|
|
244
|
+
salter?: Salter | undefined;
|
|
245
|
+
tier?: string | undefined;
|
|
214
246
|
}
|
|
215
247
|
|
|
216
|
-
export interface
|
|
217
|
-
icodes?: any | undefined
|
|
218
|
-
icount?: number
|
|
219
|
-
icode?: string
|
|
220
|
-
ncodes?: any | undefined
|
|
221
|
-
ncount?: number
|
|
222
|
-
ncode?: string
|
|
223
|
-
dcode?: string
|
|
224
|
-
algo?: Algos | undefined
|
|
225
|
-
salt?: string | undefined
|
|
226
|
-
stem?: string | undefined
|
|
227
|
-
tier?: string | undefined
|
|
228
|
-
rooted?: boolean
|
|
229
|
-
transferable?: boolean
|
|
230
|
-
temp?: boolean
|
|
248
|
+
export interface ManagerInceptArgs {
|
|
249
|
+
icodes?: any | undefined;
|
|
250
|
+
icount?: number;
|
|
251
|
+
icode?: string;
|
|
252
|
+
ncodes?: any | undefined;
|
|
253
|
+
ncount?: number;
|
|
254
|
+
ncode?: string;
|
|
255
|
+
dcode?: string;
|
|
256
|
+
algo?: Algos | undefined;
|
|
257
|
+
salt?: string | undefined;
|
|
258
|
+
stem?: string | undefined;
|
|
259
|
+
tier?: string | undefined;
|
|
260
|
+
rooted?: boolean;
|
|
261
|
+
transferable?: boolean;
|
|
262
|
+
temp?: boolean;
|
|
231
263
|
}
|
|
232
264
|
|
|
233
265
|
interface RotateArgs {
|
|
234
|
-
pre: string
|
|
235
|
-
ncodes?: any | undefined
|
|
236
|
-
ncount?: number
|
|
237
|
-
ncode?: string
|
|
238
|
-
dcode?: string
|
|
239
|
-
transferable?: boolean
|
|
240
|
-
temp?: boolean
|
|
241
|
-
erase?: boolean
|
|
266
|
+
pre: string;
|
|
267
|
+
ncodes?: any | undefined;
|
|
268
|
+
ncount?: number;
|
|
269
|
+
ncode?: string;
|
|
270
|
+
dcode?: string;
|
|
271
|
+
transferable?: boolean;
|
|
272
|
+
temp?: boolean;
|
|
273
|
+
erase?: boolean;
|
|
242
274
|
}
|
|
243
275
|
|
|
244
276
|
interface SignArgs {
|
|
245
|
-
ser: Uint8Array
|
|
246
|
-
pubs?: Array<string> | undefined
|
|
247
|
-
verfers?: Array<Verfer> | undefined
|
|
248
|
-
indexed?: boolean
|
|
249
|
-
indices?: Array<number> | undefined
|
|
250
|
-
ondices?: Array<number> | undefined
|
|
277
|
+
ser: Uint8Array;
|
|
278
|
+
pubs?: Array<string> | undefined;
|
|
279
|
+
verfers?: Array<Verfer> | undefined;
|
|
280
|
+
indexed?: boolean;
|
|
281
|
+
indices?: Array<number> | undefined;
|
|
282
|
+
ondices?: Array<number> | undefined;
|
|
251
283
|
}
|
|
252
284
|
|
|
253
285
|
export class Manager {
|
|
254
|
-
private _seed?: string
|
|
255
|
-
private _salt?: string
|
|
256
|
-
private _encrypter: Encrypter | undefined
|
|
257
|
-
private _decrypter: Decrypter | undefined
|
|
258
|
-
private readonly _ks: KeyStore
|
|
286
|
+
private _seed?: string;
|
|
287
|
+
private _salt?: string;
|
|
288
|
+
private _encrypter: Encrypter | undefined;
|
|
289
|
+
private _decrypter: Decrypter | undefined;
|
|
290
|
+
private readonly _ks: KeyStore;
|
|
259
291
|
|
|
260
|
-
constructor({ks, seed, aeid, pidx, algo,
|
|
292
|
+
constructor({ ks, seed, aeid, pidx, algo, salter, tier }: ManagerArgs) {
|
|
293
|
+
this._ks = ks == undefined ? new Keeper() : ks;
|
|
294
|
+
this._seed = seed;
|
|
295
|
+
this._encrypter = undefined;
|
|
296
|
+
this._decrypter = undefined;
|
|
261
297
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
this._decrypter = undefined
|
|
298
|
+
aeid = aeid == undefined ? undefined : aeid;
|
|
299
|
+
pidx = pidx == undefined ? 0 : pidx;
|
|
300
|
+
algo = algo == undefined ? Algos.salty : algo;
|
|
266
301
|
|
|
267
|
-
|
|
268
|
-
pidx = pidx == undefined ? 0 : pidx
|
|
269
|
-
algo = algo == undefined ? Algos.salty : algo
|
|
302
|
+
const salt = salter?.qb64;
|
|
270
303
|
|
|
271
|
-
|
|
272
|
-
salt = new Salter({}).qb64
|
|
273
|
-
} else {
|
|
274
|
-
if (new Salter({qb64: salt}).qb64 != salt) {
|
|
275
|
-
throw new Error(`Invalid qb64 for salt=${salt}.`)
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
tier = tier == undefined ? Tier.low : tier
|
|
304
|
+
tier = tier == undefined ? Tier.low : tier;
|
|
280
305
|
|
|
281
306
|
if (this.pidx == undefined) {
|
|
282
|
-
this.pidx = pidx
|
|
307
|
+
this.pidx = pidx;
|
|
283
308
|
}
|
|
284
309
|
|
|
285
310
|
if (this.algo == undefined) {
|
|
286
|
-
this.algo = algo
|
|
311
|
+
this.algo = algo;
|
|
287
312
|
}
|
|
288
313
|
|
|
289
314
|
if (this.salt == undefined) {
|
|
290
|
-
this.salt = salt
|
|
315
|
+
this.salt = salt;
|
|
291
316
|
}
|
|
292
317
|
|
|
293
318
|
if (this.tier == undefined) {
|
|
294
|
-
this.tier = tier
|
|
319
|
+
this.tier = tier;
|
|
295
320
|
}
|
|
296
321
|
|
|
297
322
|
if (this.aeid == undefined) {
|
|
298
|
-
this.updateAeid(aeid, this._seed)
|
|
323
|
+
this.updateAeid(aeid, this._seed);
|
|
299
324
|
}
|
|
300
325
|
}
|
|
301
326
|
|
|
302
327
|
get ks(): KeyStore {
|
|
303
|
-
return this._ks
|
|
328
|
+
return this._ks;
|
|
304
329
|
}
|
|
305
330
|
|
|
306
331
|
get encrypter(): Encrypter | undefined {
|
|
307
|
-
return this._encrypter
|
|
332
|
+
return this._encrypter;
|
|
308
333
|
}
|
|
309
334
|
|
|
310
335
|
get decrypter(): Decrypter | undefined {
|
|
311
|
-
return this._decrypter
|
|
336
|
+
return this._decrypter;
|
|
312
337
|
}
|
|
313
338
|
|
|
314
339
|
get seed(): string | undefined {
|
|
315
|
-
return this._seed
|
|
340
|
+
return this._seed;
|
|
316
341
|
}
|
|
317
342
|
|
|
318
343
|
get aeid(): string | undefined {
|
|
319
|
-
return this.ks.getGbls('aeid')
|
|
344
|
+
return this.ks.getGbls('aeid');
|
|
320
345
|
}
|
|
321
346
|
|
|
322
347
|
get pidx(): number | undefined {
|
|
323
|
-
|
|
348
|
+
const pidx = this.ks.getGbls('pidx');
|
|
324
349
|
if (pidx != undefined) {
|
|
325
|
-
return parseInt(pidx, 16)
|
|
350
|
+
return parseInt(pidx, 16);
|
|
326
351
|
}
|
|
327
|
-
return undefined
|
|
352
|
+
return undefined;
|
|
328
353
|
}
|
|
329
354
|
|
|
330
355
|
set pidx(pidx: number | undefined) {
|
|
331
|
-
this.ks.pinGbls('pidx', pidx!.toString(16))
|
|
356
|
+
this.ks.pinGbls('pidx', pidx!.toString(16));
|
|
332
357
|
}
|
|
333
358
|
|
|
334
|
-
get salt(): string
|
|
359
|
+
get salt(): string | undefined {
|
|
335
360
|
if (this._decrypter == undefined) {
|
|
336
|
-
return this._salt
|
|
361
|
+
return this._salt;
|
|
337
362
|
} else {
|
|
338
|
-
|
|
339
|
-
return this._decrypter.decrypt(b(salt)).qb64
|
|
363
|
+
const salt = this.ks.getGbls('salt');
|
|
364
|
+
return this._decrypter.decrypt(b(salt)).qb64;
|
|
340
365
|
}
|
|
341
366
|
}
|
|
342
367
|
|
|
343
368
|
set salt(salt: string | undefined) {
|
|
344
|
-
if(this._encrypter == undefined) {
|
|
345
|
-
this._salt = salt
|
|
369
|
+
if (this._encrypter == undefined) {
|
|
370
|
+
this._salt = salt;
|
|
346
371
|
} else {
|
|
347
|
-
salt = this._encrypter.encrypt(b(salt)).qb64
|
|
348
|
-
this.ks.pinGbls('salt', salt!)
|
|
372
|
+
salt = this._encrypter.encrypt(b(salt)).qb64;
|
|
373
|
+
this.ks.pinGbls('salt', salt!);
|
|
349
374
|
}
|
|
350
375
|
}
|
|
351
376
|
|
|
352
377
|
get tier(): string | undefined {
|
|
353
|
-
return this.ks.getGbls('tier')
|
|
378
|
+
return this.ks.getGbls('tier');
|
|
354
379
|
}
|
|
355
380
|
|
|
356
381
|
set tier(tier: string | undefined) {
|
|
357
|
-
this.ks.pinGbls('tier', tier!)
|
|
382
|
+
this.ks.pinGbls('tier', tier!);
|
|
358
383
|
}
|
|
359
384
|
|
|
360
385
|
get algo(): Algos | undefined {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
return Algos[ta]
|
|
386
|
+
const a = this.ks.getGbls('algo');
|
|
387
|
+
const ta = a as keyof typeof Algos;
|
|
388
|
+
return Algos[ta];
|
|
364
389
|
}
|
|
365
390
|
|
|
366
391
|
set algo(algo: Algos | undefined) {
|
|
367
|
-
this.ks.pinGbls('algo', algo! as string)
|
|
392
|
+
this.ks.pinGbls('algo', algo! as string);
|
|
368
393
|
}
|
|
369
394
|
|
|
370
395
|
private updateAeid(aeid: string | undefined, seed?: string) {
|
|
371
396
|
if (this.aeid != undefined) {
|
|
372
|
-
|
|
397
|
+
const seed = b(this._seed);
|
|
373
398
|
if (this._seed == undefined || !this._encrypter?.verifySeed(seed)) {
|
|
374
399
|
throw new Error(`Last seed missing or provided last seed "
|
|
375
|
-
"not associated with last aeid=${this.aeid}.`)
|
|
400
|
+
"not associated with last aeid=${this.aeid}.`);
|
|
376
401
|
}
|
|
377
402
|
}
|
|
378
403
|
|
|
379
|
-
if (aeid !=
|
|
404
|
+
if (aeid != '' && aeid != undefined) {
|
|
380
405
|
if (aeid != this.aeid) {
|
|
381
|
-
this._encrypter = new Encrypter({}, b(aeid))
|
|
406
|
+
this._encrypter = new Encrypter({}, b(aeid));
|
|
382
407
|
if (seed == undefined || !this._encrypter.verifySeed(b(seed))) {
|
|
383
408
|
throw new Error(`Seed missing or provided seed not associated"
|
|
384
|
-
" with provided aeid=${aeid}.`)
|
|
409
|
+
" with provided aeid=${aeid}.`);
|
|
385
410
|
}
|
|
386
411
|
}
|
|
387
412
|
} else if (this.algo == Algos.randy) {
|
|
388
413
|
// Unlike KERIpy, we don't support unencrypted secrets
|
|
389
|
-
throw new Error(
|
|
414
|
+
throw new Error(
|
|
415
|
+
'Invalid Manager configuration, encryption must be used with Randy key creation.'
|
|
416
|
+
);
|
|
390
417
|
} else {
|
|
391
|
-
this._encrypter = undefined
|
|
418
|
+
this._encrypter = undefined;
|
|
392
419
|
}
|
|
393
420
|
|
|
394
|
-
|
|
395
|
-
if(salt != undefined) {
|
|
396
|
-
this.salt = salt
|
|
421
|
+
const salt = this.salt;
|
|
422
|
+
if (salt != undefined) {
|
|
423
|
+
this.salt = salt;
|
|
397
424
|
}
|
|
398
425
|
|
|
399
426
|
if (this._decrypter != undefined) {
|
|
400
427
|
for (const [keys, data] of this.ks.prmsElements()) {
|
|
401
428
|
if (data.salt != undefined) {
|
|
402
|
-
|
|
403
|
-
data.salt =
|
|
404
|
-
|
|
429
|
+
const salter = this._decrypter.decrypt(b(data.salt));
|
|
430
|
+
data.salt =
|
|
431
|
+
this._encrypter == undefined
|
|
432
|
+
? salter.qb64
|
|
433
|
+
: this._encrypter.encrypt(null, salter);
|
|
434
|
+
this.ks.pinPrms(keys, data);
|
|
405
435
|
}
|
|
406
436
|
}
|
|
407
437
|
|
|
408
|
-
for (const [pubKey, signer] of this.ks.prisElements(
|
|
409
|
-
this.
|
|
438
|
+
for (const [pubKey, signer] of this.ks.prisElements(
|
|
439
|
+
this._decrypter
|
|
440
|
+
)) {
|
|
441
|
+
this.ks.pinPris(pubKey, signer, this._encrypter!);
|
|
410
442
|
}
|
|
411
|
-
|
|
412
443
|
}
|
|
413
444
|
|
|
414
|
-
this.ks.pinGbls(
|
|
415
|
-
this._seed = seed
|
|
445
|
+
this.ks.pinGbls('aeid', aeid!); // set aeid in db
|
|
446
|
+
this._seed = seed; // set .seed in memory
|
|
416
447
|
|
|
417
448
|
// update .decrypter
|
|
418
|
-
this._decrypter =
|
|
449
|
+
this._decrypter =
|
|
450
|
+
seed != undefined ? new Decrypter({}, b(seed)) : undefined;
|
|
419
451
|
}
|
|
420
452
|
|
|
421
|
-
incept({
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
453
|
+
incept({
|
|
454
|
+
icodes = undefined,
|
|
455
|
+
icount = 1,
|
|
456
|
+
icode = MtrDex.Ed25519_Seed,
|
|
457
|
+
ncodes = undefined,
|
|
458
|
+
ncount = 1,
|
|
459
|
+
ncode = MtrDex.Ed25519_Seed,
|
|
460
|
+
dcode = MtrDex.Blake3_256,
|
|
461
|
+
algo = undefined,
|
|
462
|
+
salt = undefined,
|
|
463
|
+
stem = undefined,
|
|
464
|
+
tier = undefined,
|
|
465
|
+
rooted = true,
|
|
466
|
+
transferable = true,
|
|
467
|
+
temp = false,
|
|
468
|
+
}: ManagerInceptArgs): [Array<Verfer>, Array<Diger>] {
|
|
426
469
|
if (rooted && algo == undefined) {
|
|
427
|
-
algo = this.algo
|
|
470
|
+
algo = this.algo;
|
|
428
471
|
}
|
|
429
472
|
if (rooted && salt == undefined) {
|
|
430
|
-
salt = this.salt
|
|
473
|
+
salt = this.salt;
|
|
431
474
|
}
|
|
432
475
|
if (rooted && tier == undefined) {
|
|
433
|
-
tier = this.tier
|
|
476
|
+
tier = this.tier;
|
|
434
477
|
}
|
|
435
478
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
479
|
+
const pidx = this.pidx!;
|
|
480
|
+
const ridx = 0;
|
|
481
|
+
const kidx = 0;
|
|
439
482
|
|
|
440
|
-
|
|
483
|
+
const creator = new Creatory(algo).make(salt, tier, stem);
|
|
441
484
|
|
|
442
485
|
if (icodes == undefined) {
|
|
443
486
|
if (icount < 0) {
|
|
444
|
-
throw new Error(`Invalid icount=${icount} must be >= 0.`)
|
|
487
|
+
throw new Error(`Invalid icount=${icount} must be >= 0.`);
|
|
445
488
|
}
|
|
446
489
|
|
|
447
|
-
icodes = new Array<string>(icount).fill(icode)
|
|
490
|
+
icodes = new Array<string>(icount).fill(icode);
|
|
448
491
|
}
|
|
449
492
|
|
|
450
|
-
|
|
451
|
-
|
|
493
|
+
const ikeys = creator.create(
|
|
494
|
+
icodes,
|
|
495
|
+
0,
|
|
496
|
+
MtrDex.Ed25519_Seed,
|
|
497
|
+
transferable,
|
|
498
|
+
pidx,
|
|
499
|
+
ridx,
|
|
500
|
+
kidx,
|
|
501
|
+
temp
|
|
502
|
+
);
|
|
503
|
+
const verfers = Array.from(
|
|
504
|
+
ikeys.signers,
|
|
505
|
+
(signer: Signer) => signer.verfer
|
|
506
|
+
);
|
|
452
507
|
|
|
453
508
|
if (ncodes == undefined) {
|
|
454
509
|
if (ncount < 0) {
|
|
455
|
-
throw new Error(`Invalid ncount=${ncount} must be >= 0.`)
|
|
510
|
+
throw new Error(`Invalid ncount=${ncount} must be >= 0.`);
|
|
456
511
|
}
|
|
457
512
|
|
|
458
|
-
ncodes = new Array<string>(ncount).fill(ncode)
|
|
513
|
+
ncodes = new Array<string>(ncount).fill(ncode);
|
|
459
514
|
}
|
|
460
515
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
516
|
+
const nkeys = creator.create(
|
|
517
|
+
ncodes,
|
|
518
|
+
0,
|
|
519
|
+
MtrDex.Ed25519_Seed,
|
|
520
|
+
transferable,
|
|
521
|
+
pidx,
|
|
522
|
+
ridx + 1,
|
|
523
|
+
kidx + icodes.length,
|
|
524
|
+
temp
|
|
525
|
+
);
|
|
526
|
+
|
|
527
|
+
const digers = Array.from(
|
|
528
|
+
nkeys.signers,
|
|
529
|
+
(signer: Signer) => new Diger({ code: dcode }, signer.verfer.qb64b)
|
|
530
|
+
);
|
|
531
|
+
|
|
532
|
+
const pp = new PrePrm();
|
|
533
|
+
pp.pidx = pidx!;
|
|
534
|
+
pp.algo = algo!;
|
|
535
|
+
pp.salt =
|
|
536
|
+
creator.salt.length == 0 || this.encrypter == undefined
|
|
537
|
+
? ''
|
|
538
|
+
: this.encrypter.encrypt(b(creator.salt)).qb64;
|
|
539
|
+
pp.stem = creator.stem;
|
|
540
|
+
pp.tier = creator.tier;
|
|
541
|
+
|
|
542
|
+
const dt = new Date().toString();
|
|
543
|
+
const nw = new PubLot();
|
|
544
|
+
nw.pubs = Array.from(verfers, (verfer: Verfer) => verfer.qb64);
|
|
545
|
+
nw.ridx = ridx;
|
|
546
|
+
nw.kidx = kidx;
|
|
547
|
+
nw.dt = dt;
|
|
548
|
+
|
|
549
|
+
const nt = new PubLot();
|
|
550
|
+
nt.pubs = Array.from(
|
|
551
|
+
nkeys.signers,
|
|
552
|
+
(signer: Signer) => signer.verfer.qb64
|
|
553
|
+
);
|
|
554
|
+
nt.ridx = ridx + 1;
|
|
555
|
+
nt.kidx = kidx + icodes.length;
|
|
556
|
+
nt.dt = dt;
|
|
557
|
+
|
|
558
|
+
const ps = new PreSit();
|
|
559
|
+
ps.new = nw;
|
|
560
|
+
ps.nxt = nt;
|
|
561
|
+
|
|
562
|
+
const pre = verfers[0].qb64;
|
|
491
563
|
if (!this.ks.putPres(pre, verfers[0].qb64b)) {
|
|
492
|
-
throw new Error(`Already incepted pre=${pre}.`)
|
|
564
|
+
throw new Error(`Already incepted pre=${pre}.`);
|
|
493
565
|
}
|
|
494
566
|
|
|
495
567
|
if (!this.ks.putPrms(pre, pp)) {
|
|
496
|
-
throw new Error(`Already incepted prm for pre=${pre}.`)
|
|
568
|
+
throw new Error(`Already incepted prm for pre=${pre}.`);
|
|
497
569
|
}
|
|
498
570
|
|
|
499
|
-
this.pidx = pidx! + 1
|
|
571
|
+
this.pidx = pidx! + 1;
|
|
500
572
|
|
|
501
573
|
if (!this.ks.putSits(pre, ps)) {
|
|
502
|
-
throw new Error(`Already incepted sit for pre=${pre}.`)
|
|
574
|
+
throw new Error(`Already incepted sit for pre=${pre}.`);
|
|
503
575
|
}
|
|
504
576
|
|
|
505
|
-
if (this.encrypter != undefined) {
|
|
577
|
+
if (this.encrypter != undefined) {
|
|
578
|
+
// Only store encrypted keys if we have an encrypter, otherwise regenerate
|
|
506
579
|
ikeys.signers.forEach((signer: Signer) => {
|
|
507
|
-
this.ks.putPris(signer.verfer.qb64, signer, this.encrypter!)
|
|
508
|
-
})
|
|
580
|
+
this.ks.putPris(signer.verfer.qb64, signer, this.encrypter!);
|
|
581
|
+
});
|
|
509
582
|
|
|
510
583
|
nkeys.signers.forEach((signer: Signer) => {
|
|
511
|
-
this.ks.putPris(signer.verfer.qb64, signer, this.encrypter!)
|
|
512
|
-
})
|
|
513
|
-
} else if (
|
|
584
|
+
this.ks.putPris(signer.verfer.qb64, signer, this.encrypter!);
|
|
585
|
+
});
|
|
586
|
+
} else if (
|
|
587
|
+
this._encrypter == undefined &&
|
|
588
|
+
ikeys.paths != undefined &&
|
|
589
|
+
nkeys.paths != undefined
|
|
590
|
+
) {
|
|
514
591
|
ikeys.paths.forEach((path: string, idx: number) => {
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
ppt.path = path
|
|
518
|
-
ppt.code = icodes[idx]
|
|
519
|
-
ppt.tier = pp.tier
|
|
520
|
-
ppt.temp = temp
|
|
521
|
-
this.ks.putPths(signer.verfer.qb64, ppt)
|
|
522
|
-
})
|
|
592
|
+
const signer = ikeys.signers[idx];
|
|
593
|
+
const ppt = new PubPath();
|
|
594
|
+
ppt.path = path;
|
|
595
|
+
ppt.code = icodes[idx];
|
|
596
|
+
ppt.tier = pp.tier;
|
|
597
|
+
ppt.temp = temp;
|
|
598
|
+
this.ks.putPths(signer.verfer.qb64, ppt);
|
|
599
|
+
});
|
|
523
600
|
nkeys.paths.forEach((path: string, idx: number) => {
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
ppt.path = path
|
|
527
|
-
ppt.code = ncodes[idx]
|
|
528
|
-
ppt.tier = pp.tier
|
|
529
|
-
ppt.temp = temp
|
|
530
|
-
this.ks.putPths(signer.verfer.qb64, ppt)
|
|
531
|
-
})
|
|
601
|
+
const signer = nkeys.signers[idx];
|
|
602
|
+
const ppt = new PubPath();
|
|
603
|
+
ppt.path = path;
|
|
604
|
+
ppt.code = ncodes[idx];
|
|
605
|
+
ppt.tier = pp.tier;
|
|
606
|
+
ppt.temp = temp;
|
|
607
|
+
this.ks.putPths(signer.verfer.qb64, ppt);
|
|
608
|
+
});
|
|
532
609
|
} else {
|
|
533
|
-
throw new Error(
|
|
610
|
+
throw new Error(
|
|
611
|
+
'invalid configuration, randy keys without encryption'
|
|
612
|
+
);
|
|
534
613
|
}
|
|
535
614
|
|
|
536
|
-
|
|
537
|
-
pubSet.pubs = ps.new.pubs
|
|
538
|
-
this.ks.putPubs(riKey(pre, ridx), pubSet)
|
|
615
|
+
const pubSet = new PubSet();
|
|
616
|
+
pubSet.pubs = ps.new.pubs;
|
|
617
|
+
this.ks.putPubs(riKey(pre, ridx), pubSet);
|
|
539
618
|
|
|
540
|
-
|
|
541
|
-
nxtPubSet.pubs = ps.nxt.pubs
|
|
542
|
-
this.ks.putPubs(riKey(pre, ridx+1), nxtPubSet)
|
|
619
|
+
const nxtPubSet = new PubSet();
|
|
620
|
+
nxtPubSet.pubs = ps.nxt.pubs;
|
|
621
|
+
this.ks.putPubs(riKey(pre, ridx + 1), nxtPubSet);
|
|
543
622
|
|
|
544
|
-
return [verfers, digers]
|
|
623
|
+
return [verfers, digers];
|
|
545
624
|
}
|
|
546
625
|
|
|
547
626
|
move(old: string, gnu: string) {
|
|
548
627
|
if (old == gnu) {
|
|
549
|
-
return
|
|
628
|
+
return;
|
|
550
629
|
}
|
|
551
630
|
|
|
552
631
|
if (this.ks.getPres(old) == undefined) {
|
|
553
|
-
throw new Error(`Nonexistent old pre=${old}, nothing to assign.`)
|
|
632
|
+
throw new Error(`Nonexistent old pre=${old}, nothing to assign.`);
|
|
554
633
|
}
|
|
555
634
|
|
|
556
635
|
if (this.ks.getPres(gnu) != undefined) {
|
|
557
|
-
throw new Error(`Preexistent new pre=${gnu} may not clobber.`)
|
|
636
|
+
throw new Error(`Preexistent new pre=${gnu} may not clobber.`);
|
|
558
637
|
}
|
|
559
638
|
|
|
560
|
-
|
|
639
|
+
const oldprm = this.ks.getPrms(old);
|
|
561
640
|
if (oldprm == undefined) {
|
|
562
|
-
throw new Error(
|
|
641
|
+
throw new Error(
|
|
642
|
+
`Nonexistent old prm for pre=${old}, nothing to move.`
|
|
643
|
+
);
|
|
563
644
|
}
|
|
564
645
|
|
|
565
646
|
if (this.ks.getPrms(gnu) != undefined) {
|
|
566
|
-
throw new Error(
|
|
647
|
+
throw new Error(
|
|
648
|
+
`Preexistent new prm for pre=${gnu} may not clobber.`
|
|
649
|
+
);
|
|
567
650
|
}
|
|
568
651
|
|
|
569
|
-
|
|
652
|
+
const oldsit = this.ks.getSits(old);
|
|
570
653
|
if (oldsit == undefined) {
|
|
571
|
-
throw new Error(
|
|
654
|
+
throw new Error(
|
|
655
|
+
`Nonexistent old sit for pre=${old}, nothing to move.`
|
|
656
|
+
);
|
|
572
657
|
}
|
|
573
658
|
|
|
574
659
|
if (this.ks.getSits(gnu) != undefined) {
|
|
575
|
-
throw new Error(
|
|
660
|
+
throw new Error(
|
|
661
|
+
`Preexistent new sit for pre=${gnu} may not clobber.`
|
|
662
|
+
);
|
|
576
663
|
}
|
|
577
664
|
|
|
578
665
|
if (!this.ks.putPrms(gnu, oldprm)) {
|
|
579
|
-
throw new Error(
|
|
666
|
+
throw new Error(
|
|
667
|
+
`Failed moving prm from old pre=${old} to new pre=${gnu}.`
|
|
668
|
+
);
|
|
580
669
|
} else {
|
|
581
|
-
this.ks.remPrms(old)
|
|
670
|
+
this.ks.remPrms(old);
|
|
582
671
|
}
|
|
583
672
|
|
|
584
673
|
if (!this.ks.putSits(gnu, oldsit)) {
|
|
585
|
-
throw new Error(
|
|
674
|
+
throw new Error(
|
|
675
|
+
`Failed moving sit from old pre=${old} to new pre=${gnu}.`
|
|
676
|
+
);
|
|
586
677
|
} else {
|
|
587
|
-
this.ks.remSits(old)
|
|
678
|
+
this.ks.remSits(old);
|
|
588
679
|
}
|
|
589
680
|
|
|
590
|
-
let i = 0
|
|
681
|
+
let i = 0;
|
|
591
682
|
while (true) {
|
|
592
|
-
|
|
683
|
+
const pl = this.ks.getPubs(riKey(old, i));
|
|
593
684
|
if (pl == undefined) {
|
|
594
|
-
break
|
|
685
|
+
break;
|
|
595
686
|
}
|
|
596
687
|
|
|
597
688
|
if (!this.ks.putPubs(riKey(gnu, i), pl)) {
|
|
598
|
-
throw new Error(
|
|
689
|
+
throw new Error(
|
|
690
|
+
`Failed moving pubs at pre=${old} ri=${i} to new pre=${gnu}`
|
|
691
|
+
);
|
|
599
692
|
}
|
|
600
|
-
i = i + 1
|
|
693
|
+
i = i + 1;
|
|
601
694
|
}
|
|
602
695
|
|
|
603
696
|
if (!this.ks.pinPres(old, b(gnu))) {
|
|
604
|
-
throw new Error(
|
|
697
|
+
throw new Error(
|
|
698
|
+
`Failed assiging new pre=${gnu} to old pre=${old}.`
|
|
699
|
+
);
|
|
605
700
|
}
|
|
606
701
|
|
|
607
702
|
if (!this.ks.putPres(gnu, b(gnu))) {
|
|
608
|
-
throw new Error(`Failed assiging new pre=${gnu}.`)
|
|
703
|
+
throw new Error(`Failed assiging new pre=${gnu}.`);
|
|
609
704
|
}
|
|
610
705
|
}
|
|
611
706
|
|
|
612
|
-
rotate({
|
|
613
|
-
|
|
614
|
-
|
|
707
|
+
rotate({
|
|
708
|
+
pre,
|
|
709
|
+
ncodes = undefined,
|
|
710
|
+
ncount = 1,
|
|
711
|
+
ncode = MtrDex.Ed25519_Seed,
|
|
712
|
+
dcode = MtrDex.Blake3_256,
|
|
713
|
+
transferable = true,
|
|
714
|
+
temp = false,
|
|
715
|
+
erase = true,
|
|
716
|
+
}: RotateArgs): [Array<Verfer>, Array<Diger>] {
|
|
717
|
+
const pp = this.ks.getPrms(pre);
|
|
615
718
|
if (pp == undefined) {
|
|
616
|
-
throw new Error(`Attempt to rotate nonexistent pre=${pre}.`)
|
|
719
|
+
throw new Error(`Attempt to rotate nonexistent pre=${pre}.`);
|
|
617
720
|
}
|
|
618
721
|
|
|
619
|
-
|
|
722
|
+
const ps = this.ks.getSits(pre);
|
|
620
723
|
if (ps == undefined) {
|
|
621
|
-
throw new Error(`Attempt to rotate nonexistent pre=${pre}.`)
|
|
724
|
+
throw new Error(`Attempt to rotate nonexistent pre=${pre}.`);
|
|
622
725
|
}
|
|
623
726
|
|
|
624
727
|
if (ps.nxt.pubs == undefined || ps.nxt.pubs.length == 0) {
|
|
625
|
-
throw new Error(`Attempt to rotate nontransferable pre=${pre}.`)
|
|
728
|
+
throw new Error(`Attempt to rotate nontransferable pre=${pre}.`);
|
|
626
729
|
}
|
|
627
730
|
|
|
628
|
-
|
|
629
|
-
ps.old = ps.new
|
|
630
|
-
ps.new = ps.nxt
|
|
731
|
+
const old = ps.old;
|
|
732
|
+
ps.old = ps.new;
|
|
733
|
+
ps.new = ps.nxt;
|
|
631
734
|
|
|
632
735
|
if (this.aeid != undefined && this.decrypter == undefined) {
|
|
633
|
-
throw new Error(
|
|
736
|
+
throw new Error(
|
|
737
|
+
'Unauthorized decryption attempt. Aeid but no decrypter.'
|
|
738
|
+
);
|
|
634
739
|
}
|
|
635
740
|
|
|
636
|
-
|
|
741
|
+
const verfers = new Array<Verfer>();
|
|
637
742
|
ps.new.pubs.forEach((pub) => {
|
|
638
743
|
if (this.decrypter != undefined) {
|
|
639
|
-
|
|
744
|
+
const signer = this.ks.getPris(pub, this.decrypter);
|
|
640
745
|
if (signer == undefined) {
|
|
641
|
-
throw new Error(`Missing prikey in db for pubkey=${pub}`)
|
|
746
|
+
throw new Error(`Missing prikey in db for pubkey=${pub}`);
|
|
642
747
|
}
|
|
643
|
-
verfers.push(signer.verfer)
|
|
748
|
+
verfers.push(signer.verfer);
|
|
644
749
|
} else {
|
|
645
750
|
// Should we regenerate from salt here since this.decryptor is undefined
|
|
646
|
-
verfers.push(new Verfer({qb64: pub}))
|
|
751
|
+
verfers.push(new Verfer({ qb64: pub }));
|
|
647
752
|
}
|
|
753
|
+
});
|
|
648
754
|
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
if (salt != undefined && salt != "") { // If you provded a Salt for an AID but don't have encryption, pitch a fit
|
|
755
|
+
let salt = pp.salt;
|
|
756
|
+
if (salt != undefined && salt != '') {
|
|
757
|
+
// If you provded a Salt for an AID but don't have encryption, pitch a fit
|
|
653
758
|
if (this.decrypter == undefined) {
|
|
654
|
-
throw new Error(
|
|
759
|
+
throw new Error(
|
|
760
|
+
'Invalid configuration: AID salt with no encryption'
|
|
761
|
+
);
|
|
655
762
|
}
|
|
656
|
-
salt = this.decrypter.decrypt(b(salt)).qb64
|
|
763
|
+
salt = this.decrypter.decrypt(b(salt)).qb64;
|
|
657
764
|
} else {
|
|
658
|
-
salt = this.salt
|
|
765
|
+
salt = this.salt!;
|
|
659
766
|
}
|
|
660
767
|
|
|
661
|
-
|
|
768
|
+
const creator = new Creatory(pp.algo).make(salt, pp.tier, pp.stem);
|
|
662
769
|
|
|
663
770
|
if (ncodes == undefined) {
|
|
664
771
|
if (ncount < 0) {
|
|
665
|
-
throw new Error(`Invalid count=${ncount} must be >= 0`)
|
|
772
|
+
throw new Error(`Invalid count=${ncount} must be >= 0`);
|
|
666
773
|
}
|
|
667
|
-
ncodes = new Array<string>(ncount).fill(ncode)
|
|
774
|
+
ncodes = new Array<string>(ncount).fill(ncode);
|
|
668
775
|
}
|
|
669
776
|
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
777
|
+
const pidx = pp.pidx;
|
|
778
|
+
const ridx = ps.new.ridx + 1;
|
|
779
|
+
const kidx = ps.nxt.kidx + ps.new.pubs.length;
|
|
780
|
+
|
|
781
|
+
const keys = creator.create(
|
|
782
|
+
ncodes,
|
|
783
|
+
0,
|
|
784
|
+
'',
|
|
785
|
+
transferable,
|
|
786
|
+
pidx,
|
|
787
|
+
ridx,
|
|
788
|
+
kidx,
|
|
789
|
+
temp
|
|
790
|
+
);
|
|
791
|
+
const digers = Array.from(
|
|
792
|
+
keys.signers,
|
|
793
|
+
(signer: Signer) => new Diger({ code: dcode }, signer.verfer.qb64b)
|
|
794
|
+
);
|
|
795
|
+
|
|
796
|
+
const dt = new Date().toString();
|
|
797
|
+
ps.nxt = new PubLot();
|
|
798
|
+
ps.nxt.pubs = Array.from(
|
|
799
|
+
keys.signers,
|
|
800
|
+
(signer: Signer) => signer.verfer.qb64
|
|
801
|
+
);
|
|
802
|
+
ps.nxt.ridx = ridx;
|
|
803
|
+
ps.nxt.kidx = kidx;
|
|
804
|
+
ps.nxt.dt = dt;
|
|
683
805
|
|
|
684
806
|
if (!this.ks.pinSits(pre, ps)) {
|
|
685
|
-
throw new Error(`Problem updating pubsit db for pre=${pre}.`)
|
|
807
|
+
throw new Error(`Problem updating pubsit db for pre=${pre}.`);
|
|
686
808
|
}
|
|
687
809
|
|
|
688
|
-
if (this.encrypter != undefined) {
|
|
810
|
+
if (this.encrypter != undefined) {
|
|
811
|
+
// Only store encrypted keys if we have an encrypter, otherwise regenerate
|
|
689
812
|
keys.signers.forEach((signer: Signer) => {
|
|
690
|
-
this.ks.putPris(signer.verfer.qb64, signer, this.encrypter!)
|
|
691
|
-
})
|
|
813
|
+
this.ks.putPris(signer.verfer.qb64, signer, this.encrypter!);
|
|
814
|
+
});
|
|
692
815
|
} else if (this._encrypter == undefined && keys.paths != undefined) {
|
|
693
816
|
keys.paths.forEach((path: string, idx: number) => {
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
ppt.path = path
|
|
697
|
-
ppt.tier = pp!.tier
|
|
698
|
-
ppt.temp = temp
|
|
699
|
-
this.ks.putPths(signer.verfer.qb64, ppt)
|
|
700
|
-
})
|
|
817
|
+
const signer = keys.signers[idx];
|
|
818
|
+
const ppt = new PubPath();
|
|
819
|
+
ppt.path = path;
|
|
820
|
+
ppt.tier = pp!.tier;
|
|
821
|
+
ppt.temp = temp;
|
|
822
|
+
this.ks.putPths(signer.verfer.qb64, ppt);
|
|
823
|
+
});
|
|
701
824
|
} else {
|
|
702
|
-
throw new Error(
|
|
825
|
+
throw new Error(
|
|
826
|
+
'invalid configuration, randy keys without encryption'
|
|
827
|
+
);
|
|
703
828
|
}
|
|
704
829
|
|
|
705
|
-
|
|
706
|
-
newPs.pubs = ps.nxt.pubs
|
|
707
|
-
this.ks.putPubs(riKey(pre, ps.nxt.ridx), newPs)
|
|
830
|
+
const newPs = new PubSet();
|
|
831
|
+
newPs.pubs = ps.nxt.pubs;
|
|
832
|
+
this.ks.putPubs(riKey(pre, ps.nxt.ridx), newPs);
|
|
708
833
|
|
|
709
834
|
if (erase) {
|
|
710
835
|
old.pubs.forEach((pub) => {
|
|
711
|
-
this.ks.remPris(pub)
|
|
712
|
-
})
|
|
836
|
+
this.ks.remPris(pub);
|
|
837
|
+
});
|
|
713
838
|
}
|
|
714
839
|
|
|
715
|
-
return [verfers, digers]
|
|
840
|
+
return [verfers, digers];
|
|
716
841
|
}
|
|
717
842
|
|
|
718
|
-
sign({
|
|
719
|
-
|
|
843
|
+
sign({
|
|
844
|
+
ser,
|
|
845
|
+
pubs = undefined,
|
|
846
|
+
verfers = undefined,
|
|
847
|
+
indexed = true,
|
|
848
|
+
indices = undefined,
|
|
849
|
+
ondices = undefined,
|
|
850
|
+
}: SignArgs) {
|
|
851
|
+
const signers = new Array<Signer>();
|
|
720
852
|
|
|
721
853
|
if (pubs == undefined && verfers == undefined) {
|
|
722
|
-
throw new Error(
|
|
854
|
+
throw new Error('pubs or verfers required');
|
|
723
855
|
}
|
|
724
856
|
|
|
725
857
|
if (pubs != undefined) {
|
|
726
858
|
if (this.aeid != undefined && this.decrypter == undefined) {
|
|
727
|
-
throw new Error(
|
|
859
|
+
throw new Error(
|
|
860
|
+
'Unauthorized decryption attempt. Aeid but no decrypter.'
|
|
861
|
+
);
|
|
728
862
|
}
|
|
729
863
|
|
|
730
864
|
pubs.forEach((pub) => {
|
|
731
865
|
//If no decrypter then get SaltyState and regenerate prikey
|
|
732
866
|
if (this.decrypter != undefined) {
|
|
733
|
-
|
|
867
|
+
const signer = this.ks.getPris(pub, this.decrypter);
|
|
734
868
|
if (signer == undefined) {
|
|
735
|
-
throw new Error(
|
|
869
|
+
throw new Error(
|
|
870
|
+
`Missing prikey in db for pubkey=${pub}`
|
|
871
|
+
);
|
|
736
872
|
}
|
|
737
|
-
signers.push(signer)
|
|
873
|
+
signers.push(signer);
|
|
738
874
|
} else {
|
|
739
|
-
|
|
740
|
-
|
|
875
|
+
const verfer = new Verfer({ qb64: pub });
|
|
876
|
+
const ppt = this.ks.getPths(pub);
|
|
741
877
|
if (ppt == undefined) {
|
|
742
|
-
throw new Error(
|
|
878
|
+
throw new Error(
|
|
879
|
+
`Missing prikey in db for pubkey=${pub}`
|
|
880
|
+
);
|
|
743
881
|
}
|
|
744
|
-
|
|
745
|
-
signers.push(
|
|
882
|
+
const salter = new Salter({ qb64: this.salt });
|
|
883
|
+
signers.push(
|
|
884
|
+
salter.signer(
|
|
885
|
+
ppt.code,
|
|
886
|
+
verfer.transferable,
|
|
887
|
+
ppt.path,
|
|
888
|
+
ppt.tier as Tier,
|
|
889
|
+
ppt.temp
|
|
890
|
+
)
|
|
891
|
+
);
|
|
746
892
|
}
|
|
747
|
-
})
|
|
893
|
+
});
|
|
748
894
|
} else {
|
|
749
895
|
verfers!.forEach((verfer: Verfer) => {
|
|
750
896
|
if (this.decrypter != undefined) {
|
|
751
|
-
|
|
897
|
+
const signer = this.ks.getPris(verfer.qb64, this.decrypter);
|
|
752
898
|
if (signer == undefined) {
|
|
753
|
-
throw new Error(
|
|
899
|
+
throw new Error(
|
|
900
|
+
`Missing prikey in db for pubkey=${verfer.qb64}`
|
|
901
|
+
);
|
|
754
902
|
}
|
|
755
|
-
signers.push(signer)
|
|
903
|
+
signers.push(signer);
|
|
756
904
|
} else {
|
|
757
|
-
|
|
905
|
+
const ppt = this.ks.getPths(verfer.qb64);
|
|
758
906
|
if (ppt == undefined) {
|
|
759
|
-
throw new Error(
|
|
907
|
+
throw new Error(
|
|
908
|
+
`Missing prikey in db for pubkey=${verfer.qb64}`
|
|
909
|
+
);
|
|
760
910
|
}
|
|
761
|
-
|
|
762
|
-
signers.push(
|
|
911
|
+
const salter = new Salter({ qb64: this.salt });
|
|
912
|
+
signers.push(
|
|
913
|
+
salter.signer(
|
|
914
|
+
ppt.code,
|
|
915
|
+
verfer.transferable,
|
|
916
|
+
ppt.path,
|
|
917
|
+
ppt.tier as Tier,
|
|
918
|
+
ppt.temp
|
|
919
|
+
)
|
|
920
|
+
);
|
|
763
921
|
}
|
|
764
|
-
})
|
|
922
|
+
});
|
|
765
923
|
}
|
|
766
924
|
|
|
767
925
|
if (indices != undefined && indices.length != signers.length) {
|
|
768
|
-
throw new Error(
|
|
926
|
+
throw new Error(
|
|
927
|
+
`Mismatch indices length=${indices.length} and resultant signers length=${signers.length}`
|
|
928
|
+
);
|
|
769
929
|
}
|
|
770
930
|
|
|
771
931
|
if (ondices != undefined && ondices.length != signers.length) {
|
|
772
|
-
throw new Error(
|
|
932
|
+
throw new Error(
|
|
933
|
+
`Mismatch ondices length=${ondices.length} and resultant signers length=${signers.length}`
|
|
934
|
+
);
|
|
773
935
|
}
|
|
774
936
|
|
|
775
937
|
if (indexed) {
|
|
776
|
-
|
|
938
|
+
const sigers = new Array<Siger>();
|
|
777
939
|
signers.forEach((signer, idx) => {
|
|
778
|
-
let i
|
|
940
|
+
let i;
|
|
779
941
|
if (indices != undefined) {
|
|
780
|
-
i = indices[idx]
|
|
942
|
+
i = indices[idx];
|
|
781
943
|
if (i < 0) {
|
|
782
|
-
throw new Error(
|
|
944
|
+
throw new Error(
|
|
945
|
+
`Invalid signing index = ${i}, not whole number.`
|
|
946
|
+
);
|
|
783
947
|
}
|
|
784
948
|
} else {
|
|
785
|
-
i = idx
|
|
949
|
+
i = idx;
|
|
786
950
|
}
|
|
787
951
|
|
|
788
|
-
let o
|
|
952
|
+
let o;
|
|
789
953
|
if (ondices != undefined) {
|
|
790
|
-
o = ondices[idx]
|
|
954
|
+
o = ondices[idx];
|
|
791
955
|
if (o <= 0) {
|
|
792
|
-
throw new Error(
|
|
956
|
+
throw new Error(
|
|
957
|
+
`Invalid other signing index = {o}, not None or not whole number.`
|
|
958
|
+
);
|
|
793
959
|
}
|
|
794
960
|
} else {
|
|
795
|
-
o = i
|
|
961
|
+
o = i;
|
|
796
962
|
}
|
|
797
963
|
|
|
798
|
-
|
|
799
|
-
sigers.push(signer.sign(ser, i, only, o) as Siger)
|
|
800
|
-
})
|
|
801
|
-
return sigers
|
|
964
|
+
const only = o == undefined;
|
|
965
|
+
sigers.push(signer.sign(ser, i, only, o) as Siger);
|
|
966
|
+
});
|
|
967
|
+
return sigers;
|
|
802
968
|
} else {
|
|
803
|
-
|
|
969
|
+
const cigars = new Array<Cigar>();
|
|
804
970
|
signers.forEach((signer: Signer) => {
|
|
805
|
-
cigars.push(signer.sign(ser) as Cigar)
|
|
806
|
-
})
|
|
971
|
+
cigars.push(signer.sign(ser) as Cigar);
|
|
972
|
+
});
|
|
807
973
|
|
|
808
|
-
return cigars
|
|
974
|
+
return cigars;
|
|
809
975
|
}
|
|
810
976
|
}
|
|
811
977
|
}
|
|
812
978
|
|
|
813
979
|
export function riKey(pre: string, ridx: number) {
|
|
814
|
-
return pre +
|
|
815
|
-
|
|
980
|
+
return pre + '.' + ridx.toString(16).padStart(32, '0');
|
|
816
981
|
}
|
|
817
982
|
|
|
818
|
-
|
|
819
983
|
export interface KeyStore {
|
|
820
|
-
getGbls(key: string): string | undefined
|
|
821
|
-
pinGbls(key: string, val: string): void
|
|
822
|
-
|
|
823
|
-
prmsElements(): Array<[string, PrePrm]
|
|
824
|
-
getPrms(keys: string)
|
|
825
|
-
pinPrms(keys: string, data: PrePrm): void
|
|
826
|
-
putPrms(keys: string, data: PrePrm): boolean
|
|
827
|
-
remPrms(keys: string): boolean
|
|
828
|
-
|
|
829
|
-
prisElements(decrypter: Decrypter): Array<[string, Signer]
|
|
830
|
-
getPris(keys: string, decrypter: Decrypter): Signer | undefined
|
|
831
|
-
pinPris(keys: string, data: Signer, encrypter: Encrypter): void
|
|
832
|
-
putPris(pubKey: string, signer: Signer, encrypter: Encrypter): boolean
|
|
833
|
-
remPris(pubKey: string): void
|
|
834
|
-
|
|
835
|
-
getPths(pubKey: string): PubPath | undefined
|
|
836
|
-
putPths(pubKey: string, val: PubPath): boolean
|
|
837
|
-
pinPths(pubKey: string, val: PubPath): boolean
|
|
838
|
-
|
|
839
|
-
getPres(pre: string): Uint8Array | undefined
|
|
840
|
-
putPres(pre: string, val: Uint8Array): boolean
|
|
841
|
-
pinPres(pre: string, val: Uint8Array): boolean
|
|
842
|
-
|
|
843
|
-
getSits(keys: string)
|
|
844
|
-
putSits(pre: string, val: PreSit): boolean
|
|
845
|
-
pinSits(pre: string, val: PreSit): boolean
|
|
846
|
-
remSits(keys: string): boolean
|
|
847
|
-
|
|
848
|
-
getPubs(keys: string): PubSet | undefined
|
|
849
|
-
putPubs(keys: string, data: PubSet): boolean
|
|
984
|
+
getGbls(key: string): string | undefined;
|
|
985
|
+
pinGbls(key: string, val: string): void;
|
|
986
|
+
|
|
987
|
+
prmsElements(): Array<[string, PrePrm]>;
|
|
988
|
+
getPrms(keys: string): PrePrm | undefined;
|
|
989
|
+
pinPrms(keys: string, data: PrePrm): void;
|
|
990
|
+
putPrms(keys: string, data: PrePrm): boolean;
|
|
991
|
+
remPrms(keys: string): boolean;
|
|
992
|
+
|
|
993
|
+
prisElements(decrypter: Decrypter): Array<[string, Signer]>;
|
|
994
|
+
getPris(keys: string, decrypter: Decrypter): Signer | undefined;
|
|
995
|
+
pinPris(keys: string, data: Signer, encrypter: Encrypter): void;
|
|
996
|
+
putPris(pubKey: string, signer: Signer, encrypter: Encrypter): boolean;
|
|
997
|
+
remPris(pubKey: string): void;
|
|
998
|
+
|
|
999
|
+
getPths(pubKey: string): PubPath | undefined;
|
|
1000
|
+
putPths(pubKey: string, val: PubPath): boolean;
|
|
1001
|
+
pinPths(pubKey: string, val: PubPath): boolean;
|
|
1002
|
+
|
|
1003
|
+
getPres(pre: string): Uint8Array | undefined;
|
|
1004
|
+
putPres(pre: string, val: Uint8Array): boolean;
|
|
1005
|
+
pinPres(pre: string, val: Uint8Array): boolean;
|
|
1006
|
+
|
|
1007
|
+
getSits(keys: string): PreSit | undefined;
|
|
1008
|
+
putSits(pre: string, val: PreSit): boolean;
|
|
1009
|
+
pinSits(pre: string, val: PreSit): boolean;
|
|
1010
|
+
remSits(keys: string): boolean;
|
|
1011
|
+
|
|
1012
|
+
getPubs(keys: string): PubSet | undefined;
|
|
1013
|
+
putPubs(keys: string, data: PubSet): boolean;
|
|
850
1014
|
}
|
|
851
1015
|
|
|
852
1016
|
/*
|
|
@@ -854,169 +1018,166 @@ export interface KeyStore {
|
|
|
854
1018
|
*/
|
|
855
1019
|
|
|
856
1020
|
class Keeper implements KeyStore {
|
|
857
|
-
private readonly _gbls: Map<string, string
|
|
858
|
-
private readonly _pris: Map<string, Uint8Array
|
|
859
|
-
private readonly _pths: Map<string, PubPath
|
|
860
|
-
private readonly _pres: Map<string, Uint8Array
|
|
861
|
-
private readonly _prms: Map<string, PrePrm
|
|
862
|
-
private readonly _sits: Map<string, PreSit
|
|
863
|
-
private readonly _pubs: Map<string, PubSet
|
|
1021
|
+
private readonly _gbls: Map<string, string>;
|
|
1022
|
+
private readonly _pris: Map<string, Uint8Array>;
|
|
1023
|
+
private readonly _pths: Map<string, PubPath>;
|
|
1024
|
+
private readonly _pres: Map<string, Uint8Array>;
|
|
1025
|
+
private readonly _prms: Map<string, PrePrm>;
|
|
1026
|
+
private readonly _sits: Map<string, PreSit>;
|
|
1027
|
+
private readonly _pubs: Map<string, PubSet>;
|
|
864
1028
|
|
|
865
1029
|
constructor() {
|
|
866
|
-
this._gbls = new Map<string, string>()
|
|
867
|
-
this._pris = new Map<string, Uint8Array>()
|
|
868
|
-
this._pths = new Map<string, PubPath>()
|
|
869
|
-
this._pres = new Map<string, Uint8Array>()
|
|
870
|
-
this._prms = new Map<string, PrePrm>()
|
|
871
|
-
this._sits = new Map<string, PreSit>()
|
|
872
|
-
this._pubs = new Map<string, PubSet>()
|
|
873
|
-
|
|
1030
|
+
this._gbls = new Map<string, string>();
|
|
1031
|
+
this._pris = new Map<string, Uint8Array>();
|
|
1032
|
+
this._pths = new Map<string, PubPath>();
|
|
1033
|
+
this._pres = new Map<string, Uint8Array>();
|
|
1034
|
+
this._prms = new Map<string, PrePrm>();
|
|
1035
|
+
this._sits = new Map<string, PreSit>();
|
|
1036
|
+
this._pubs = new Map<string, PubSet>();
|
|
874
1037
|
}
|
|
875
1038
|
|
|
876
1039
|
getGbls(key: string): string | undefined {
|
|
877
|
-
return this._gbls.get(key)
|
|
1040
|
+
return this._gbls.get(key);
|
|
878
1041
|
}
|
|
879
1042
|
|
|
880
1043
|
pinGbls(key: string, val: string): void {
|
|
881
|
-
this._gbls.set(key, val)
|
|
1044
|
+
this._gbls.set(key, val);
|
|
882
1045
|
}
|
|
883
1046
|
|
|
884
1047
|
prmsElements(): Array<[string, PrePrm]> {
|
|
885
|
-
|
|
1048
|
+
const out = new Array<[string, PrePrm]>();
|
|
886
1049
|
this._prms.forEach((value, key) => {
|
|
887
|
-
out.push([key, value])
|
|
888
|
-
})
|
|
1050
|
+
out.push([key, value]);
|
|
1051
|
+
});
|
|
889
1052
|
|
|
890
|
-
return out
|
|
1053
|
+
return out;
|
|
891
1054
|
}
|
|
892
1055
|
|
|
893
1056
|
getPrms(keys: string): PrePrm | undefined {
|
|
894
|
-
return this._prms.get(keys)
|
|
1057
|
+
return this._prms.get(keys);
|
|
895
1058
|
}
|
|
896
1059
|
|
|
897
1060
|
pinPrms(keys: string, data: PrePrm): void {
|
|
898
|
-
this._prms.set(keys, data)
|
|
1061
|
+
this._prms.set(keys, data);
|
|
899
1062
|
}
|
|
900
1063
|
|
|
901
1064
|
putPrms(keys: string, data: PrePrm): boolean {
|
|
902
1065
|
if (this._prms.has(keys)) {
|
|
903
|
-
return false
|
|
1066
|
+
return false;
|
|
904
1067
|
}
|
|
905
|
-
this._prms.set(keys, data)
|
|
906
|
-
return true
|
|
1068
|
+
this._prms.set(keys, data);
|
|
1069
|
+
return true;
|
|
907
1070
|
}
|
|
908
1071
|
|
|
909
1072
|
remPrms(keys: string): boolean {
|
|
910
|
-
return this._prms.delete(keys)
|
|
1073
|
+
return this._prms.delete(keys);
|
|
911
1074
|
}
|
|
912
1075
|
|
|
913
1076
|
prisElements(decrypter: Decrypter): Array<[string, Signer]> {
|
|
914
|
-
|
|
1077
|
+
const out = new Array<[string, Signer]>();
|
|
915
1078
|
this._pris.forEach(function (val, pubKey) {
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
out.push([pubKey, signer])
|
|
919
|
-
})
|
|
920
|
-
return out
|
|
1079
|
+
const verfer = new Verfer({ qb64: pubKey });
|
|
1080
|
+
const signer = decrypter.decrypt(val, null, verfer.transferable);
|
|
1081
|
+
out.push([pubKey, signer]);
|
|
1082
|
+
});
|
|
1083
|
+
return out;
|
|
921
1084
|
}
|
|
922
1085
|
|
|
923
1086
|
pinPris(pubKey: string, signer: Signer, encrypter: Encrypter): void {
|
|
924
|
-
|
|
925
|
-
this._pris.set(pubKey, cipher.qb64b)
|
|
1087
|
+
const cipher = encrypter.encrypt(null, signer);
|
|
1088
|
+
this._pris.set(pubKey, cipher.qb64b);
|
|
926
1089
|
}
|
|
927
1090
|
|
|
928
1091
|
putPris(pubKey: string, signer: Signer, encrypter: Encrypter): boolean {
|
|
929
1092
|
if (this._pris.has(pubKey)) {
|
|
930
|
-
return false
|
|
1093
|
+
return false;
|
|
931
1094
|
}
|
|
932
|
-
|
|
933
|
-
this._pris.set(pubKey, cipher.qb64b)
|
|
934
|
-
return true
|
|
1095
|
+
const cipher = encrypter.encrypt(null, signer);
|
|
1096
|
+
this._pris.set(pubKey, cipher.qb64b);
|
|
1097
|
+
return true;
|
|
935
1098
|
}
|
|
936
1099
|
|
|
937
1100
|
getPris(pubKey: string, decrypter: Decrypter): Signer | undefined {
|
|
938
|
-
|
|
1101
|
+
const val = this._pris.get(pubKey);
|
|
939
1102
|
if (val == undefined) {
|
|
940
|
-
return undefined
|
|
1103
|
+
return undefined;
|
|
941
1104
|
}
|
|
942
|
-
|
|
1105
|
+
const verfer = new Verfer({ qb64: pubKey });
|
|
943
1106
|
|
|
944
|
-
|
|
945
|
-
return decrypter.decrypt(val, null, verfer.transferable)
|
|
1107
|
+
return decrypter.decrypt(val, null, verfer.transferable);
|
|
946
1108
|
}
|
|
947
1109
|
|
|
948
1110
|
pinPths(pubKey: string, val: PubPath): boolean {
|
|
949
|
-
this._pths.set(pubKey, val)
|
|
950
|
-
return true
|
|
1111
|
+
this._pths.set(pubKey, val);
|
|
1112
|
+
return true;
|
|
951
1113
|
}
|
|
952
1114
|
|
|
953
1115
|
putPths(pubKey: string, val: PubPath): boolean {
|
|
954
1116
|
if (this._pths.has(pubKey)) {
|
|
955
|
-
return false
|
|
1117
|
+
return false;
|
|
956
1118
|
}
|
|
957
1119
|
|
|
958
|
-
this._pths.set(pubKey, val)
|
|
959
|
-
return true
|
|
960
|
-
|
|
1120
|
+
this._pths.set(pubKey, val);
|
|
1121
|
+
return true;
|
|
961
1122
|
}
|
|
962
1123
|
|
|
963
1124
|
getPths(pubKey: string): PubPath | undefined {
|
|
964
|
-
return this._pths.get(pubKey)
|
|
1125
|
+
return this._pths.get(pubKey);
|
|
965
1126
|
}
|
|
966
1127
|
|
|
967
1128
|
remPris(pubKey: string): void {
|
|
968
|
-
this._pris.delete(pubKey)
|
|
1129
|
+
this._pris.delete(pubKey);
|
|
969
1130
|
}
|
|
970
1131
|
|
|
971
1132
|
getPres(pre: string): Uint8Array | undefined {
|
|
972
|
-
return this._pres.get(pre)
|
|
1133
|
+
return this._pres.get(pre);
|
|
973
1134
|
}
|
|
974
1135
|
|
|
975
1136
|
pinPres(pre: string, val: Uint8Array): boolean {
|
|
976
|
-
this._pres.set(pre, val)
|
|
977
|
-
return true
|
|
1137
|
+
this._pres.set(pre, val);
|
|
1138
|
+
return true;
|
|
978
1139
|
}
|
|
979
1140
|
|
|
980
1141
|
putPres(pre: string, val: Uint8Array): boolean {
|
|
981
1142
|
if (this._pres.has(pre)) {
|
|
982
|
-
return false
|
|
1143
|
+
return false;
|
|
983
1144
|
}
|
|
984
1145
|
|
|
985
|
-
this._pres.set(pre, val)
|
|
986
|
-
return true
|
|
1146
|
+
this._pres.set(pre, val);
|
|
1147
|
+
return true;
|
|
987
1148
|
}
|
|
988
1149
|
|
|
989
1150
|
getSits(keys: string): PreSit | undefined {
|
|
990
|
-
return this._sits.get(keys)
|
|
1151
|
+
return this._sits.get(keys);
|
|
991
1152
|
}
|
|
992
1153
|
|
|
993
1154
|
putSits(pre: string, val: PreSit): boolean {
|
|
994
1155
|
if (this._sits.has(pre)) {
|
|
995
|
-
return false
|
|
1156
|
+
return false;
|
|
996
1157
|
}
|
|
997
1158
|
|
|
998
|
-
this._sits.set(pre, val)
|
|
999
|
-
return true
|
|
1159
|
+
this._sits.set(pre, val);
|
|
1160
|
+
return true;
|
|
1000
1161
|
}
|
|
1001
1162
|
|
|
1002
1163
|
pinSits(pre: string, val: PreSit): boolean {
|
|
1003
|
-
this._sits.set(pre, val)
|
|
1004
|
-
return true
|
|
1164
|
+
this._sits.set(pre, val);
|
|
1165
|
+
return true;
|
|
1005
1166
|
}
|
|
1006
1167
|
|
|
1007
1168
|
remSits(keys: string): boolean {
|
|
1008
|
-
return this._sits.delete(keys)
|
|
1169
|
+
return this._sits.delete(keys);
|
|
1009
1170
|
}
|
|
1010
1171
|
|
|
1011
1172
|
getPubs(keys: string): PubSet | undefined {
|
|
1012
|
-
return this._pubs.get(keys)
|
|
1173
|
+
return this._pubs.get(keys);
|
|
1013
1174
|
}
|
|
1014
1175
|
|
|
1015
1176
|
putPubs(keys: string, data: PubSet): boolean {
|
|
1016
1177
|
if (this._pubs.has(keys)) {
|
|
1017
|
-
return false
|
|
1178
|
+
return false;
|
|
1018
1179
|
}
|
|
1019
|
-
this._pubs.set(keys, data)
|
|
1020
|
-
return true
|
|
1180
|
+
this._pubs.set(keys, data);
|
|
1181
|
+
return true;
|
|
1021
1182
|
}
|
|
1022
|
-
}
|
|
1183
|
+
}
|