signify-ts 0.2.0 → 0.3.0-dev.e31e78d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -34
- package/dist/exports.d.ts +40 -40
- package/dist/exports.js +40 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.js +3 -8
- package/dist/keri/app/aiding.d.ts +54 -18
- package/{src/keri/app/aiding.ts → dist/keri/app/aiding.js} +130 -236
- package/dist/keri/app/clienting.d.ts +59 -22
- package/{src/keri/app/clienting.ts → dist/keri/app/clienting.js} +146 -235
- package/dist/keri/app/contacting.d.ts +30 -23
- package/{src/keri/app/contacting.ts → dist/keri/app/contacting.js} +26 -63
- package/dist/keri/app/controller.d.ts +49 -6
- package/{src/keri/app/controller.ts → dist/keri/app/controller.js} +80 -186
- package/dist/keri/app/coring.d.ts +134 -25
- package/{src/keri/app/coring.ts → dist/keri/app/coring.js} +83 -56
- package/dist/keri/app/credentialing.d.ts +191 -67
- package/dist/keri/app/credentialing.js +540 -0
- package/dist/keri/app/delegating.d.ts +18 -0
- package/dist/keri/app/delegating.js +24 -0
- package/dist/keri/app/escrowing.d.ts +5 -3
- package/{src/keri/app/escrowing.ts → dist/keri/app/escrowing.js} +3 -9
- package/dist/keri/app/exchanging.d.ts +243 -11
- package/dist/keri/app/exchanging.js +242 -0
- package/dist/keri/app/grouping.d.ts +11 -9
- package/{src/keri/app/grouping.ts → dist/keri/app/grouping.js} +10 -29
- package/dist/keri/app/habery.d.ts +2 -2
- package/dist/keri/app/habery.js +117 -0
- package/dist/keri/app/notifying.d.ts +2 -2
- package/{src/keri/app/notifying.ts → dist/keri/app/notifying.js} +7 -17
- package/dist/keri/core/authing.d.ts +2 -2
- package/{src/keri/core/authing.ts → dist/keri/core/authing.js} +26 -42
- package/dist/keri/core/base64.d.ts +2 -0
- package/dist/keri/core/base64.js +16 -0
- package/dist/keri/core/bexter.d.ts +1 -1
- package/{src/keri/core/bexter.ts → dist/keri/core/bexter.js} +18 -32
- package/dist/keri/core/cigar.d.ts +2 -2
- package/dist/keri/core/cigar.js +13 -0
- package/dist/keri/core/cipher.d.ts +1 -1
- package/{src/keri/core/cipher.ts → dist/keri/core/cipher.js} +10 -19
- package/dist/keri/core/core.d.ts +117 -9
- package/dist/keri/core/core.js +385 -0
- package/dist/keri/core/counter.d.ts +2 -2
- package/dist/keri/core/counter.js +221 -0
- package/dist/keri/core/decrypter.d.ts +4 -4
- package/{src/keri/core/decrypter.ts → dist/keri/core/decrypter.js} +23 -40
- package/dist/keri/core/diger.d.ts +3 -3
- package/{src/keri/core/diger.ts → dist/keri/core/diger.js} +18 -33
- package/dist/keri/core/encrypter.d.ts +2 -2
- package/{src/keri/core/encrypter.ts → dist/keri/core/encrypter.js} +18 -38
- package/dist/keri/core/eventing.d.ts +6 -6
- package/dist/keri/core/eventing.js +383 -0
- package/dist/keri/core/httping.d.ts +11 -4
- package/{src/keri/core/httping.ts → dist/keri/core/httping.js} +36 -101
- package/dist/keri/core/indexer.d.ts +1 -1
- package/dist/keri/core/indexer.js +407 -0
- package/dist/keri/core/keeping.d.ts +113 -46
- package/dist/keri/core/keeping.js +347 -0
- package/{src/keri/core/kering.ts → dist/keri/core/kering.js} +1 -3
- package/dist/keri/core/keyState.d.ts +98 -0
- package/dist/keri/core/manager.d.ts +147 -12
- package/dist/keri/core/manager.js +880 -0
- package/dist/keri/core/matter.d.ts +1 -1
- package/dist/keri/core/matter.js +460 -0
- package/dist/keri/core/number.d.ts +2 -2
- package/{src/keri/core/number.ts → dist/keri/core/number.js} +26 -32
- package/dist/keri/core/pather.d.ts +2 -2
- package/{src/keri/core/pather.ts → dist/keri/core/pather.js} +12 -27
- package/dist/keri/core/prefixer.d.ts +10 -10
- package/dist/keri/core/prefixer.js +182 -0
- package/dist/keri/core/saider.d.ts +2 -12
- package/dist/keri/core/saider.js +107 -0
- package/dist/keri/core/salter.d.ts +44 -9
- package/dist/keri/core/salter.js +110 -0
- package/dist/keri/core/seqner.d.ts +1 -1
- package/{src/keri/core/seqner.ts → dist/keri/core/seqner.js} +20 -21
- package/dist/keri/core/serder.d.ts +25 -12
- package/dist/keri/core/serder.js +133 -0
- package/dist/keri/core/siger.d.ts +2 -2
- package/{src/keri/core/siger.ts → dist/keri/core/siger.js} +4 -14
- package/dist/keri/core/signer.d.ts +4 -4
- package/dist/keri/core/signer.js +84 -0
- package/{src/keri/core/tholder.ts → dist/keri/core/tholder.js} +69 -94
- package/dist/keri/core/utils.d.ts +1 -1
- package/{src/keri/core/utils.ts → dist/keri/core/utils.js} +30 -60
- package/dist/keri/core/vdring.d.ts +2 -2
- package/dist/keri/core/vdring.js +61 -0
- package/dist/keri/core/verfer.d.ts +2 -6
- package/dist/keri/core/verfer.js +37 -0
- package/dist/keri/end/ending.d.ts +10 -8
- package/dist/keri/end/ending.js +136 -0
- package/{src/ready.ts → dist/ready.js} +1 -2
- package/dist/types/keria-api-schema.d.ts +1158 -0
- package/dist/types/keria-api-schema.js +34 -0
- package/package.json +53 -52
- package/dist/math.d.ts +0 -1
- package/dist/signify-ts.cjs +0 -7835
- package/dist/signify-ts.cjs.development.js +0 -9501
- package/dist/signify-ts.cjs.development.js.map +0 -1
- package/dist/signify-ts.cjs.map +0 -7
- package/dist/signify-ts.cjs.production.min.js +0 -2
- package/dist/signify-ts.cjs.production.min.js.map +0 -1
- package/dist/signify-ts.esm.js +0 -9345
- package/dist/signify-ts.esm.js.map +0 -1
- package/dist/signify-ts.mjs +0 -7811
- package/dist/signify-ts.mjs.map +0 -7
- package/src/buffer-polyfill.ts +0 -5
- package/src/exports.ts +0 -44
- package/src/index.ts +0 -4
- package/src/keri/app/credentialing.ts +0 -820
- package/src/keri/app/exchanging.ts +0 -220
- package/src/keri/app/habery.ts +0 -185
- package/src/keri/core/cigar.ts +0 -18
- package/src/keri/core/core.ts +0 -326
- package/src/keri/core/counter.ts +0 -273
- package/src/keri/core/eventing.ts +0 -581
- package/src/keri/core/indexer.ts +0 -509
- package/src/keri/core/keeping.ts +0 -684
- package/src/keri/core/manager.ts +0 -1183
- package/src/keri/core/matter.ts +0 -521
- package/src/keri/core/prefixer.ts +0 -233
- package/src/keri/core/saider.ts +0 -186
- package/src/keri/core/salter.ts +0 -120
- package/src/keri/core/serder.ts +0 -163
- package/src/keri/core/signer.ts +0 -133
- package/src/keri/core/vdring.ts +0 -94
- package/src/keri/core/verfer.ts +0 -47
- package/src/keri/end/ending.ts +0 -170
- package/src/math.ts +0 -3
- /package/dist/{buffer-polyfill.d.ts → keri/core/keyState.js} +0 -0
|
@@ -0,0 +1,880 @@
|
|
|
1
|
+
import { Encrypter } from "./encrypter.js";
|
|
2
|
+
import { Decrypter } from "./decrypter.js";
|
|
3
|
+
import { Salter, Tier } from "./salter.js";
|
|
4
|
+
import { Signer } from "./signer.js";
|
|
5
|
+
import { Verfer } from "./verfer.js";
|
|
6
|
+
import { MtrDex } from "./matter.js";
|
|
7
|
+
import { Diger } from "./diger.js";
|
|
8
|
+
import { b } from "./core.js";
|
|
9
|
+
/**
|
|
10
|
+
* Kinds of key pair generation algorithms.
|
|
11
|
+
* Salty is deterministic based on a salt and stem.
|
|
12
|
+
* Randy is random.
|
|
13
|
+
* Group is a multi-signature group algorithm indicating keys are retrieved from a group member which will be either Salty or Randy.
|
|
14
|
+
* Extern is an external key pair algorithm indicating keys are provided by an external source such as an HSM.
|
|
15
|
+
*/
|
|
16
|
+
export var Algos;
|
|
17
|
+
(function (Algos) {
|
|
18
|
+
Algos["randy"] = "randy";
|
|
19
|
+
Algos["salty"] = "salty";
|
|
20
|
+
Algos["group"] = "group";
|
|
21
|
+
Algos["extern"] = "extern";
|
|
22
|
+
})(Algos || (Algos = {}));
|
|
23
|
+
/**
|
|
24
|
+
* Lot (set) of public keys as an ordered list with indexes and the time created.
|
|
25
|
+
* Indexes refer to the index of the ordered sequence of keys in an establishment event (inception or rotation).
|
|
26
|
+
* Assumes the same length for each set of keys across all PubLot instances used for a given identifier.
|
|
27
|
+
*/
|
|
28
|
+
class PubLot {
|
|
29
|
+
constructor() {
|
|
30
|
+
/**
|
|
31
|
+
* List of fully qualified, Base64 encoded public keys. Defaults to empty.
|
|
32
|
+
*/
|
|
33
|
+
this.pubs = new Array();
|
|
34
|
+
/**
|
|
35
|
+
* Rotation index; index of rotation (est event) that uses this public key set.
|
|
36
|
+
* The index of the key set for an inception event is 0.
|
|
37
|
+
*/
|
|
38
|
+
this.ridx = 0;
|
|
39
|
+
/**
|
|
40
|
+
* Key index; index of the starting key in the key set for this lot in sequence
|
|
41
|
+
* with reference to all public keys for the identifier.
|
|
42
|
+
* For example, if each set (PubLot.pubs) has 3 keys then ridx 2 has kidx of 2*3 = 6.
|
|
43
|
+
* Defaults to 0.
|
|
44
|
+
*/
|
|
45
|
+
this.kidx = 0;
|
|
46
|
+
/**
|
|
47
|
+
* Datetime of when key set created formatted as an ISO 8601 compliant string.
|
|
48
|
+
*/
|
|
49
|
+
this.dt = '';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Prefix's public key situation (set of public keys).
|
|
54
|
+
*/
|
|
55
|
+
class PreSit {
|
|
56
|
+
constructor() {
|
|
57
|
+
/**
|
|
58
|
+
* Previous publot; previous public key set.
|
|
59
|
+
*/
|
|
60
|
+
this.old = new PubLot();
|
|
61
|
+
/**
|
|
62
|
+
* New, current publot; current public key set.
|
|
63
|
+
*/
|
|
64
|
+
this.new = new PubLot();
|
|
65
|
+
/**
|
|
66
|
+
* Next public publot
|
|
67
|
+
*/
|
|
68
|
+
this.nxt = new PubLot();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Identifier prefix parameters for creating new key pairs.
|
|
73
|
+
*/
|
|
74
|
+
class PrePrm {
|
|
75
|
+
constructor() {
|
|
76
|
+
/**
|
|
77
|
+
* Prefix index for this keypair sequence.
|
|
78
|
+
*/
|
|
79
|
+
this.pidx = 0;
|
|
80
|
+
/**
|
|
81
|
+
* Key generation algorithm type.
|
|
82
|
+
* Defaults to Salty.
|
|
83
|
+
* Salty default uses indices and salt to create new key pairs.
|
|
84
|
+
*/
|
|
85
|
+
this.algo = Algos.salty;
|
|
86
|
+
/**
|
|
87
|
+
* Used for salty algo. Defaults to empty. Unused for randy algo.
|
|
88
|
+
*/
|
|
89
|
+
this.salt = '';
|
|
90
|
+
/**
|
|
91
|
+
* Default unique path prefix used by the salty algo during key generation.
|
|
92
|
+
*/
|
|
93
|
+
this.stem = '';
|
|
94
|
+
/**
|
|
95
|
+
* Security tier for stretch index; used by the salty algo.
|
|
96
|
+
*/
|
|
97
|
+
this.tier = '';
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* An identifier prefix's public key set (list) at a given rotation index ridx.
|
|
102
|
+
*/
|
|
103
|
+
class PubSet {
|
|
104
|
+
constructor() {
|
|
105
|
+
/**
|
|
106
|
+
* List of fully qualified, Base64 encoded public keys.
|
|
107
|
+
*/
|
|
108
|
+
this.pubs = new Array();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Describes a path to a specific derived keypair for a given identifier
|
|
113
|
+
*/
|
|
114
|
+
class PubPath {
|
|
115
|
+
constructor() {
|
|
116
|
+
/**
|
|
117
|
+
* The path to a specific keypair. To generate a keypair you combine the path with the salt and tier.
|
|
118
|
+
*/
|
|
119
|
+
this.path = '';
|
|
120
|
+
/**
|
|
121
|
+
* Derivation code indicating the kind of cryptographic keypair to generate. Defaults to Ed25519.
|
|
122
|
+
*/
|
|
123
|
+
this.code = '';
|
|
124
|
+
/**
|
|
125
|
+
* Security tier to use to generate a keypair. Defaults to high.
|
|
126
|
+
*/
|
|
127
|
+
this.tier = Tier.high;
|
|
128
|
+
/**
|
|
129
|
+
* Flag to control whether to generate a low security, temporary key. Used for speed for unit tests. Do NOT use for production identifiers.
|
|
130
|
+
*/
|
|
131
|
+
this.temp = false;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
class Keys {
|
|
135
|
+
constructor(signers, paths) {
|
|
136
|
+
this._signers = signers;
|
|
137
|
+
if (paths != undefined) {
|
|
138
|
+
if (signers.length != paths.length) {
|
|
139
|
+
throw new Error('If paths are provided, they must be the same length as signers');
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
this._paths = paths;
|
|
143
|
+
}
|
|
144
|
+
get paths() {
|
|
145
|
+
return this._paths;
|
|
146
|
+
}
|
|
147
|
+
get signers() {
|
|
148
|
+
return this._signers;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
export class RandyCreator {
|
|
152
|
+
create(codes = undefined, count = 1, code = MtrDex.Ed25519_Seed, transferable = true) {
|
|
153
|
+
const signers = new Array();
|
|
154
|
+
if (codes == undefined) {
|
|
155
|
+
codes = new Array(count).fill(code);
|
|
156
|
+
}
|
|
157
|
+
codes.forEach(function (code) {
|
|
158
|
+
signers.push(new Signer({ code: code, transferable: transferable }));
|
|
159
|
+
});
|
|
160
|
+
return new Keys(signers);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Unused for random key generation.
|
|
164
|
+
*/
|
|
165
|
+
get salt() {
|
|
166
|
+
return '';
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Unused for random key generation.
|
|
170
|
+
*/
|
|
171
|
+
get stem() {
|
|
172
|
+
return '';
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Unused for random key generation.
|
|
176
|
+
*/
|
|
177
|
+
get tier() {
|
|
178
|
+
return '';
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Deterministically creates a key pair based on combining a salt with a path stretch algorithm.
|
|
183
|
+
* The salt is randomized if not provided.
|
|
184
|
+
*/
|
|
185
|
+
export class SaltyCreator {
|
|
186
|
+
constructor(salt = undefined, tier = undefined, stem = undefined) {
|
|
187
|
+
this.salter = new Salter({ qb64: salt, tier: tier });
|
|
188
|
+
this._stem = stem == undefined ? '' : stem;
|
|
189
|
+
}
|
|
190
|
+
get salt() {
|
|
191
|
+
return this.salter.qb64;
|
|
192
|
+
}
|
|
193
|
+
get stem() {
|
|
194
|
+
return this._stem;
|
|
195
|
+
}
|
|
196
|
+
get tier() {
|
|
197
|
+
return this.salter.tier;
|
|
198
|
+
}
|
|
199
|
+
create(codes = undefined, count = 1, code = MtrDex.Ed25519_Seed, transferable = true, pidx = 0, ridx = 0, kidx = 0, temp = false) {
|
|
200
|
+
const signers = new Array();
|
|
201
|
+
const paths = new Array();
|
|
202
|
+
if (codes == undefined) {
|
|
203
|
+
codes = new Array(count).fill(code);
|
|
204
|
+
}
|
|
205
|
+
codes.forEach((code, idx) => {
|
|
206
|
+
// Previous definition of path
|
|
207
|
+
// let path = this.stem + pidx.toString(16) + ridx.toString(16) + (kidx+idx).toString(16)
|
|
208
|
+
const path = this.stem == ''
|
|
209
|
+
? pidx.toString(16)
|
|
210
|
+
: this.stem + ridx.toString(16) + (kidx + idx).toString(16);
|
|
211
|
+
signers.push(this.salter.signer(code, transferable, path, this.tier, temp));
|
|
212
|
+
paths.push(path);
|
|
213
|
+
});
|
|
214
|
+
return new Keys(signers, paths);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
export class Creatory {
|
|
218
|
+
constructor(algo = Algos.salty) {
|
|
219
|
+
switch (algo) {
|
|
220
|
+
case Algos.randy:
|
|
221
|
+
this._make = this._makeRandy;
|
|
222
|
+
break;
|
|
223
|
+
case Algos.salty:
|
|
224
|
+
this._make = this._makeSalty;
|
|
225
|
+
break;
|
|
226
|
+
default:
|
|
227
|
+
throw new Error(`unsupported algo=${algo}`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
make(...args) {
|
|
231
|
+
return this._make(...args);
|
|
232
|
+
}
|
|
233
|
+
_makeRandy() {
|
|
234
|
+
return new RandyCreator();
|
|
235
|
+
}
|
|
236
|
+
_makeSalty(...args) {
|
|
237
|
+
return new SaltyCreator(...args);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
export function openManager(passcode, salt) {
|
|
241
|
+
if (passcode.length < 21) {
|
|
242
|
+
throw new Error('Bran (passcode seed material) too short.');
|
|
243
|
+
}
|
|
244
|
+
const bran = MtrDex.Salt_128 + 'A' + passcode.substring(0, 21); // qb64 salt for seed
|
|
245
|
+
const signer = new Salter({ qb64: bran }).signer(MtrDex.Ed25519_Seed, false);
|
|
246
|
+
const seed = signer.qb64;
|
|
247
|
+
const aeid = signer.verfer.qb64; // lest it remove encryption
|
|
248
|
+
let algo;
|
|
249
|
+
const salter = salt != undefined ? new Salter({ qb64: salt }) : undefined;
|
|
250
|
+
if (salt != undefined) {
|
|
251
|
+
algo = Algos.salty;
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
algo = Algos.randy;
|
|
255
|
+
}
|
|
256
|
+
return new Manager({ seed: seed, aeid: aeid, algo: algo, salter: salter });
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Manages key pair creation, retrieval, and message signing.
|
|
260
|
+
*/
|
|
261
|
+
export class Manager {
|
|
262
|
+
constructor(args) {
|
|
263
|
+
let { ks, seed, aeid, pidx, algo, salter, tier } = args;
|
|
264
|
+
this._ks = ks == undefined ? new Keeper() : ks;
|
|
265
|
+
this._seed = seed;
|
|
266
|
+
this._encrypter = undefined;
|
|
267
|
+
this._decrypter = undefined;
|
|
268
|
+
aeid = aeid == undefined ? undefined : aeid;
|
|
269
|
+
pidx = pidx == undefined ? 0 : pidx;
|
|
270
|
+
algo = algo == undefined ? Algos.salty : algo;
|
|
271
|
+
const salt = salter === null || salter === void 0 ? void 0 : salter.qb64;
|
|
272
|
+
tier = tier == undefined ? Tier.low : tier;
|
|
273
|
+
if (this.pidx == undefined) {
|
|
274
|
+
this.pidx = pidx;
|
|
275
|
+
}
|
|
276
|
+
if (this.algo == undefined) {
|
|
277
|
+
this.algo = algo;
|
|
278
|
+
}
|
|
279
|
+
if (this.salt == undefined) {
|
|
280
|
+
this.salt = salt;
|
|
281
|
+
}
|
|
282
|
+
if (this.tier == undefined) {
|
|
283
|
+
this.tier = tier;
|
|
284
|
+
}
|
|
285
|
+
if (this.aeid == undefined) {
|
|
286
|
+
this.updateAeid(aeid, this._seed);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
get ks() {
|
|
290
|
+
return this._ks;
|
|
291
|
+
}
|
|
292
|
+
get encrypter() {
|
|
293
|
+
return this._encrypter;
|
|
294
|
+
}
|
|
295
|
+
get decrypter() {
|
|
296
|
+
return this._decrypter;
|
|
297
|
+
}
|
|
298
|
+
get seed() {
|
|
299
|
+
return this._seed;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* qb64 auth encrypt id prefix
|
|
303
|
+
*/
|
|
304
|
+
get aeid() {
|
|
305
|
+
return this.ks.getGbls('aeid');
|
|
306
|
+
}
|
|
307
|
+
get pidx() {
|
|
308
|
+
const pidx = this.ks.getGbls('pidx');
|
|
309
|
+
if (pidx != undefined) {
|
|
310
|
+
return parseInt(pidx, 16);
|
|
311
|
+
}
|
|
312
|
+
return undefined;
|
|
313
|
+
}
|
|
314
|
+
set pidx(pidx) {
|
|
315
|
+
this.ks.pinGbls('pidx', pidx.toString(16));
|
|
316
|
+
}
|
|
317
|
+
get salt() {
|
|
318
|
+
if (this._decrypter == undefined) {
|
|
319
|
+
return this._salt;
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
const salt = this.ks.getGbls('salt');
|
|
323
|
+
return this._decrypter.decrypt(b(salt)).qb64;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
set salt(salt) {
|
|
327
|
+
if (this._encrypter == undefined) {
|
|
328
|
+
this._salt = salt;
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
salt = this._encrypter.encrypt(b(salt)).qb64;
|
|
332
|
+
this.ks.pinGbls('salt', salt);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
get tier() {
|
|
336
|
+
return this.ks.getGbls('tier');
|
|
337
|
+
}
|
|
338
|
+
set tier(tier) {
|
|
339
|
+
this.ks.pinGbls('tier', tier);
|
|
340
|
+
}
|
|
341
|
+
get algo() {
|
|
342
|
+
const a = this.ks.getGbls('algo');
|
|
343
|
+
const ta = a;
|
|
344
|
+
return Algos[ta];
|
|
345
|
+
}
|
|
346
|
+
set algo(algo) {
|
|
347
|
+
this.ks.pinGbls('algo', algo);
|
|
348
|
+
}
|
|
349
|
+
updateAeid(aeid, seed) {
|
|
350
|
+
var _a;
|
|
351
|
+
if (this.aeid != undefined) {
|
|
352
|
+
const seed = b(this._seed);
|
|
353
|
+
if (this._seed == undefined || !((_a = this._encrypter) === null || _a === void 0 ? void 0 : _a.verifySeed(seed))) {
|
|
354
|
+
throw new Error(`Last seed missing or provided last seed "
|
|
355
|
+
"not associated with last aeid=${this.aeid}.`);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
if (aeid != '' && aeid != undefined) {
|
|
359
|
+
if (aeid != this.aeid) {
|
|
360
|
+
this._encrypter = new Encrypter({}, b(aeid));
|
|
361
|
+
if (seed == undefined || !this._encrypter.verifySeed(b(seed))) {
|
|
362
|
+
throw new Error(`Seed missing or provided seed not associated"
|
|
363
|
+
" with provided aeid=${aeid}.`);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
else if (this.algo == Algos.randy) {
|
|
368
|
+
// Unlike KERIpy, we don't support unencrypted secrets
|
|
369
|
+
throw new Error('Invalid Manager configuration, encryption must be used with Randy key creation.');
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
this._encrypter = undefined;
|
|
373
|
+
}
|
|
374
|
+
const salt = this.salt;
|
|
375
|
+
if (salt != undefined) {
|
|
376
|
+
this.salt = salt;
|
|
377
|
+
}
|
|
378
|
+
if (this._decrypter != undefined) {
|
|
379
|
+
for (const [keys, data] of this.ks.prmsElements()) {
|
|
380
|
+
if (data.salt != undefined) {
|
|
381
|
+
const salter = this._decrypter.decrypt(b(data.salt));
|
|
382
|
+
data.salt =
|
|
383
|
+
this._encrypter == undefined
|
|
384
|
+
? salter.qb64
|
|
385
|
+
: this._encrypter.encrypt(null, salter);
|
|
386
|
+
this.ks.pinPrms(keys, data);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
for (const [pubKey, signer] of this.ks.prisElements(this._decrypter)) {
|
|
390
|
+
this.ks.pinPris(pubKey, signer, this._encrypter);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
this.ks.pinGbls('aeid', aeid); // set aeid in db
|
|
394
|
+
this._seed = seed; // set .seed in memory
|
|
395
|
+
// update .decrypter
|
|
396
|
+
this._decrypter =
|
|
397
|
+
seed != undefined ? new Decrypter({}, b(seed)) : undefined;
|
|
398
|
+
}
|
|
399
|
+
incept(args) {
|
|
400
|
+
let { icodes = undefined, icount = 1, icode = MtrDex.Ed25519_Seed, ncodes = undefined, ncount = 1, ncode = MtrDex.Ed25519_Seed, dcode = MtrDex.Blake3_256, algo = undefined, salt = undefined, stem = undefined, tier = undefined, rooted = true, transferable = true, temp = false, } = args;
|
|
401
|
+
if (rooted && algo == undefined) {
|
|
402
|
+
algo = this.algo;
|
|
403
|
+
}
|
|
404
|
+
if (rooted && salt == undefined) {
|
|
405
|
+
salt = this.salt;
|
|
406
|
+
}
|
|
407
|
+
if (rooted && tier == undefined) {
|
|
408
|
+
tier = this.tier;
|
|
409
|
+
}
|
|
410
|
+
const pidx = this.pidx;
|
|
411
|
+
const ridx = 0;
|
|
412
|
+
const kidx = 0;
|
|
413
|
+
const creator = new Creatory(algo).make(salt, tier, stem);
|
|
414
|
+
if (icodes == undefined) {
|
|
415
|
+
if (icount < 0) {
|
|
416
|
+
throw new Error(`Invalid icount=${icount} must be >= 0.`);
|
|
417
|
+
}
|
|
418
|
+
icodes = new Array(icount).fill(icode);
|
|
419
|
+
}
|
|
420
|
+
const ikeys = creator.create(icodes, 0, MtrDex.Ed25519_Seed, transferable, pidx, ridx, kidx, temp);
|
|
421
|
+
const verfers = Array.from(ikeys.signers, (signer) => signer.verfer);
|
|
422
|
+
if (ncodes == undefined) {
|
|
423
|
+
if (ncount < 0) {
|
|
424
|
+
throw new Error(`Invalid ncount=${ncount} must be >= 0.`);
|
|
425
|
+
}
|
|
426
|
+
ncodes = new Array(ncount).fill(ncode);
|
|
427
|
+
}
|
|
428
|
+
const nkeys = creator.create(ncodes, 0, MtrDex.Ed25519_Seed, transferable, pidx, ridx + 1, kidx + icodes.length, temp);
|
|
429
|
+
const digers = Array.from(nkeys.signers, (signer) => new Diger({ code: dcode }, signer.verfer.qb64b));
|
|
430
|
+
const pp = new PrePrm();
|
|
431
|
+
pp.pidx = pidx;
|
|
432
|
+
pp.algo = algo;
|
|
433
|
+
pp.salt =
|
|
434
|
+
creator.salt.length == 0 || this.encrypter == undefined
|
|
435
|
+
? ''
|
|
436
|
+
: this.encrypter.encrypt(b(creator.salt)).qb64;
|
|
437
|
+
pp.stem = creator.stem;
|
|
438
|
+
pp.tier = creator.tier;
|
|
439
|
+
const dt = new Date().toString();
|
|
440
|
+
const nw = new PubLot();
|
|
441
|
+
nw.pubs = Array.from(verfers, (verfer) => verfer.qb64);
|
|
442
|
+
nw.ridx = ridx;
|
|
443
|
+
nw.kidx = kidx;
|
|
444
|
+
nw.dt = dt;
|
|
445
|
+
const nt = new PubLot();
|
|
446
|
+
nt.pubs = Array.from(nkeys.signers, (signer) => signer.verfer.qb64);
|
|
447
|
+
nt.ridx = ridx + 1;
|
|
448
|
+
nt.kidx = kidx + icodes.length;
|
|
449
|
+
nt.dt = dt;
|
|
450
|
+
const ps = new PreSit();
|
|
451
|
+
ps.new = nw;
|
|
452
|
+
ps.nxt = nt;
|
|
453
|
+
const pre = verfers[0].qb64;
|
|
454
|
+
if (!this.ks.putPres(pre, verfers[0].qb64b)) {
|
|
455
|
+
throw new Error(`Already incepted pre=${pre}.`);
|
|
456
|
+
}
|
|
457
|
+
if (!this.ks.putPrms(pre, pp)) {
|
|
458
|
+
throw new Error(`Already incepted prm for pre=${pre}.`);
|
|
459
|
+
}
|
|
460
|
+
this.pidx = pidx + 1;
|
|
461
|
+
if (!this.ks.putSits(pre, ps)) {
|
|
462
|
+
throw new Error(`Already incepted sit for pre=${pre}.`);
|
|
463
|
+
}
|
|
464
|
+
if (this.encrypter != undefined) {
|
|
465
|
+
// Only store encrypted keys if we have an encrypter, otherwise regenerate
|
|
466
|
+
ikeys.signers.forEach((signer) => {
|
|
467
|
+
this.ks.putPris(signer.verfer.qb64, signer, this.encrypter);
|
|
468
|
+
});
|
|
469
|
+
nkeys.signers.forEach((signer) => {
|
|
470
|
+
this.ks.putPris(signer.verfer.qb64, signer, this.encrypter);
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
else if (this._encrypter == undefined &&
|
|
474
|
+
ikeys.paths != undefined &&
|
|
475
|
+
nkeys.paths != undefined) {
|
|
476
|
+
ikeys.paths.forEach((path, idx) => {
|
|
477
|
+
const signer = ikeys.signers[idx];
|
|
478
|
+
const ppt = new PubPath();
|
|
479
|
+
ppt.path = path;
|
|
480
|
+
ppt.code = icodes[idx];
|
|
481
|
+
ppt.tier = pp.tier;
|
|
482
|
+
ppt.temp = temp;
|
|
483
|
+
this.ks.putPths(signer.verfer.qb64, ppt);
|
|
484
|
+
});
|
|
485
|
+
nkeys.paths.forEach((path, idx) => {
|
|
486
|
+
const signer = nkeys.signers[idx];
|
|
487
|
+
const ppt = new PubPath();
|
|
488
|
+
ppt.path = path;
|
|
489
|
+
ppt.code = ncodes[idx];
|
|
490
|
+
ppt.tier = pp.tier;
|
|
491
|
+
ppt.temp = temp;
|
|
492
|
+
this.ks.putPths(signer.verfer.qb64, ppt);
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
else {
|
|
496
|
+
throw new Error('invalid configuration, randy keys without encryption');
|
|
497
|
+
}
|
|
498
|
+
const pubSet = new PubSet();
|
|
499
|
+
pubSet.pubs = ps.new.pubs;
|
|
500
|
+
this.ks.putPubs(riKey(pre, ridx), pubSet);
|
|
501
|
+
const nxtPubSet = new PubSet();
|
|
502
|
+
nxtPubSet.pubs = ps.nxt.pubs;
|
|
503
|
+
this.ks.putPubs(riKey(pre, ridx + 1), nxtPubSet);
|
|
504
|
+
return [verfers, digers];
|
|
505
|
+
}
|
|
506
|
+
move(old, gnu) {
|
|
507
|
+
if (old == gnu) {
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
if (this.ks.getPres(old) == undefined) {
|
|
511
|
+
throw new Error(`Nonexistent old pre=${old}, nothing to assign.`);
|
|
512
|
+
}
|
|
513
|
+
if (this.ks.getPres(gnu) != undefined) {
|
|
514
|
+
throw new Error(`Preexistent new pre=${gnu} may not clobber.`);
|
|
515
|
+
}
|
|
516
|
+
const oldprm = this.ks.getPrms(old);
|
|
517
|
+
if (oldprm == undefined) {
|
|
518
|
+
throw new Error(`Nonexistent old prm for pre=${old}, nothing to move.`);
|
|
519
|
+
}
|
|
520
|
+
if (this.ks.getPrms(gnu) != undefined) {
|
|
521
|
+
throw new Error(`Preexistent new prm for pre=${gnu} may not clobber.`);
|
|
522
|
+
}
|
|
523
|
+
const oldsit = this.ks.getSits(old);
|
|
524
|
+
if (oldsit == undefined) {
|
|
525
|
+
throw new Error(`Nonexistent old sit for pre=${old}, nothing to move.`);
|
|
526
|
+
}
|
|
527
|
+
if (this.ks.getSits(gnu) != undefined) {
|
|
528
|
+
throw new Error(`Preexistent new sit for pre=${gnu} may not clobber.`);
|
|
529
|
+
}
|
|
530
|
+
if (!this.ks.putPrms(gnu, oldprm)) {
|
|
531
|
+
throw new Error(`Failed moving prm from old pre=${old} to new pre=${gnu}.`);
|
|
532
|
+
}
|
|
533
|
+
else {
|
|
534
|
+
this.ks.remPrms(old);
|
|
535
|
+
}
|
|
536
|
+
if (!this.ks.putSits(gnu, oldsit)) {
|
|
537
|
+
throw new Error(`Failed moving sit from old pre=${old} to new pre=${gnu}.`);
|
|
538
|
+
}
|
|
539
|
+
else {
|
|
540
|
+
this.ks.remSits(old);
|
|
541
|
+
}
|
|
542
|
+
let i = 0;
|
|
543
|
+
while (true) {
|
|
544
|
+
const pl = this.ks.getPubs(riKey(old, i));
|
|
545
|
+
if (pl == undefined) {
|
|
546
|
+
break;
|
|
547
|
+
}
|
|
548
|
+
if (!this.ks.putPubs(riKey(gnu, i), pl)) {
|
|
549
|
+
throw new Error(`Failed moving pubs at pre=${old} ri=${i} to new pre=${gnu}`);
|
|
550
|
+
}
|
|
551
|
+
i = i + 1;
|
|
552
|
+
}
|
|
553
|
+
if (!this.ks.pinPres(old, b(gnu))) {
|
|
554
|
+
throw new Error(`Failed assiging new pre=${gnu} to old pre=${old}.`);
|
|
555
|
+
}
|
|
556
|
+
if (!this.ks.putPres(gnu, b(gnu))) {
|
|
557
|
+
throw new Error(`Failed assiging new pre=${gnu}.`);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
rotate(args) {
|
|
561
|
+
let { pre, ncodes = undefined, ncount = 1, ncode = MtrDex.Ed25519_Seed, dcode = MtrDex.Blake3_256, transferable = true, temp = false, erase = true, } = args;
|
|
562
|
+
const pp = this.ks.getPrms(pre);
|
|
563
|
+
if (pp == undefined) {
|
|
564
|
+
throw new Error(`Attempt to rotate nonexistent pre=${pre}.`);
|
|
565
|
+
}
|
|
566
|
+
const ps = this.ks.getSits(pre);
|
|
567
|
+
if (ps == undefined) {
|
|
568
|
+
throw new Error(`Attempt to rotate nonexistent pre=${pre}.`);
|
|
569
|
+
}
|
|
570
|
+
if (ps.nxt.pubs == undefined || ps.nxt.pubs.length == 0) {
|
|
571
|
+
throw new Error(`Attempt to rotate nontransferable pre=${pre}.`);
|
|
572
|
+
}
|
|
573
|
+
const old = ps.old;
|
|
574
|
+
ps.old = ps.new;
|
|
575
|
+
ps.new = ps.nxt;
|
|
576
|
+
if (this.aeid != undefined && this.decrypter == undefined) {
|
|
577
|
+
throw new Error('Unauthorized decryption attempt. Aeid but no decrypter.');
|
|
578
|
+
}
|
|
579
|
+
const verfers = new Array();
|
|
580
|
+
ps.new.pubs.forEach((pub) => {
|
|
581
|
+
if (this.decrypter != undefined) {
|
|
582
|
+
const signer = this.ks.getPris(pub, this.decrypter);
|
|
583
|
+
if (signer == undefined) {
|
|
584
|
+
throw new Error(`Missing prikey in db for pubkey=${pub}`);
|
|
585
|
+
}
|
|
586
|
+
verfers.push(signer.verfer);
|
|
587
|
+
}
|
|
588
|
+
else {
|
|
589
|
+
// Should we regenerate from salt here since this.decryptor is undefined
|
|
590
|
+
verfers.push(new Verfer({ qb64: pub }));
|
|
591
|
+
}
|
|
592
|
+
});
|
|
593
|
+
let salt = pp.salt;
|
|
594
|
+
if (salt != undefined && salt != '') {
|
|
595
|
+
// If you provded a Salt for an AID but don't have encryption, pitch a fit
|
|
596
|
+
if (this.decrypter == undefined) {
|
|
597
|
+
throw new Error('Invalid configuration: AID salt with no encryption');
|
|
598
|
+
}
|
|
599
|
+
salt = this.decrypter.decrypt(b(salt)).qb64;
|
|
600
|
+
}
|
|
601
|
+
else {
|
|
602
|
+
salt = this.salt;
|
|
603
|
+
}
|
|
604
|
+
const creator = new Creatory(pp.algo).make(salt, pp.tier, pp.stem);
|
|
605
|
+
if (ncodes == undefined) {
|
|
606
|
+
if (ncount < 0) {
|
|
607
|
+
throw new Error(`Invalid count=${ncount} must be >= 0`);
|
|
608
|
+
}
|
|
609
|
+
ncodes = new Array(ncount).fill(ncode);
|
|
610
|
+
}
|
|
611
|
+
const pidx = pp.pidx;
|
|
612
|
+
const ridx = ps.new.ridx + 1;
|
|
613
|
+
const kidx = ps.nxt.kidx + ps.new.pubs.length;
|
|
614
|
+
const keys = creator.create(ncodes, 0, '', transferable, pidx, ridx, kidx, temp);
|
|
615
|
+
const digers = Array.from(keys.signers, (signer) => new Diger({ code: dcode }, signer.verfer.qb64b));
|
|
616
|
+
const dt = new Date().toString();
|
|
617
|
+
ps.nxt = new PubLot();
|
|
618
|
+
ps.nxt.pubs = Array.from(keys.signers, (signer) => signer.verfer.qb64);
|
|
619
|
+
ps.nxt.ridx = ridx;
|
|
620
|
+
ps.nxt.kidx = kidx;
|
|
621
|
+
ps.nxt.dt = dt;
|
|
622
|
+
if (!this.ks.pinSits(pre, ps)) {
|
|
623
|
+
throw new Error(`Problem updating pubsit db for pre=${pre}.`);
|
|
624
|
+
}
|
|
625
|
+
if (this.encrypter != undefined) {
|
|
626
|
+
// Only store encrypted keys if we have an encrypter, otherwise regenerate
|
|
627
|
+
keys.signers.forEach((signer) => {
|
|
628
|
+
this.ks.putPris(signer.verfer.qb64, signer, this.encrypter);
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
else if (this._encrypter == undefined && keys.paths != undefined) {
|
|
632
|
+
keys.paths.forEach((path, idx) => {
|
|
633
|
+
const signer = keys.signers[idx];
|
|
634
|
+
const ppt = new PubPath();
|
|
635
|
+
ppt.path = path;
|
|
636
|
+
ppt.tier = pp.tier;
|
|
637
|
+
ppt.temp = temp;
|
|
638
|
+
this.ks.putPths(signer.verfer.qb64, ppt);
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
else {
|
|
642
|
+
throw new Error('invalid configuration, randy keys without encryption');
|
|
643
|
+
}
|
|
644
|
+
const newPs = new PubSet();
|
|
645
|
+
newPs.pubs = ps.nxt.pubs;
|
|
646
|
+
this.ks.putPubs(riKey(pre, ps.nxt.ridx), newPs);
|
|
647
|
+
if (erase) {
|
|
648
|
+
old.pubs.forEach((pub) => {
|
|
649
|
+
this.ks.remPris(pub);
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
return [verfers, digers];
|
|
653
|
+
}
|
|
654
|
+
sign(args) {
|
|
655
|
+
const { ser, pubs = undefined, verfers = undefined, indexed = true, indices = undefined, ondices = undefined, } = args;
|
|
656
|
+
const signers = new Array();
|
|
657
|
+
if (pubs == undefined && verfers == undefined) {
|
|
658
|
+
throw new Error('pubs or verfers required');
|
|
659
|
+
}
|
|
660
|
+
if (pubs != undefined) {
|
|
661
|
+
if (this.aeid != undefined && this.decrypter == undefined) {
|
|
662
|
+
throw new Error('Unauthorized decryption attempt. Aeid but no decrypter.');
|
|
663
|
+
}
|
|
664
|
+
pubs.forEach((pub) => {
|
|
665
|
+
//If no decrypter then get SaltyState and regenerate prikey
|
|
666
|
+
if (this.decrypter != undefined) {
|
|
667
|
+
const signer = this.ks.getPris(pub, this.decrypter);
|
|
668
|
+
if (signer == undefined) {
|
|
669
|
+
throw new Error(`Missing prikey in db for pubkey=${pub}`);
|
|
670
|
+
}
|
|
671
|
+
signers.push(signer);
|
|
672
|
+
}
|
|
673
|
+
else {
|
|
674
|
+
const verfer = new Verfer({ qb64: pub });
|
|
675
|
+
const ppt = this.ks.getPths(pub);
|
|
676
|
+
if (ppt == undefined) {
|
|
677
|
+
throw new Error(`Missing prikey in db for pubkey=${pub}`);
|
|
678
|
+
}
|
|
679
|
+
const salter = new Salter({ qb64: this.salt });
|
|
680
|
+
signers.push(salter.signer(ppt.code, verfer.transferable, ppt.path, ppt.tier, ppt.temp));
|
|
681
|
+
}
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
else {
|
|
685
|
+
verfers.forEach((verfer) => {
|
|
686
|
+
if (this.decrypter != undefined) {
|
|
687
|
+
const signer = this.ks.getPris(verfer.qb64, this.decrypter);
|
|
688
|
+
if (signer == undefined) {
|
|
689
|
+
throw new Error(`Missing prikey in db for pubkey=${verfer.qb64}`);
|
|
690
|
+
}
|
|
691
|
+
signers.push(signer);
|
|
692
|
+
}
|
|
693
|
+
else {
|
|
694
|
+
const ppt = this.ks.getPths(verfer.qb64);
|
|
695
|
+
if (ppt == undefined) {
|
|
696
|
+
throw new Error(`Missing prikey in db for pubkey=${verfer.qb64}`);
|
|
697
|
+
}
|
|
698
|
+
const salter = new Salter({ qb64: this.salt });
|
|
699
|
+
signers.push(salter.signer(ppt.code, verfer.transferable, ppt.path, ppt.tier, ppt.temp));
|
|
700
|
+
}
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
if (indices != undefined && indices.length != signers.length) {
|
|
704
|
+
throw new Error(`Mismatch indices length=${indices.length} and resultant signers length=${signers.length}`);
|
|
705
|
+
}
|
|
706
|
+
if (ondices != undefined && ondices.length != signers.length) {
|
|
707
|
+
throw new Error(`Mismatch ondices length=${ondices.length} and resultant signers length=${signers.length}`);
|
|
708
|
+
}
|
|
709
|
+
if (indexed) {
|
|
710
|
+
const sigers = new Array();
|
|
711
|
+
signers.forEach((signer, idx) => {
|
|
712
|
+
let i;
|
|
713
|
+
if (indices != undefined) {
|
|
714
|
+
i = indices[idx];
|
|
715
|
+
if (i < 0) {
|
|
716
|
+
throw new Error(`Invalid signing index = ${i}, not whole number.`);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
else {
|
|
720
|
+
i = idx;
|
|
721
|
+
}
|
|
722
|
+
let o;
|
|
723
|
+
if (ondices != undefined) {
|
|
724
|
+
o = ondices[idx];
|
|
725
|
+
if (o <= 0) {
|
|
726
|
+
throw new Error(`Invalid other signing index = {o}, not None or not whole number.`);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
else {
|
|
730
|
+
o = i;
|
|
731
|
+
}
|
|
732
|
+
const only = o == undefined;
|
|
733
|
+
sigers.push(signer.sign(ser, i, only, o));
|
|
734
|
+
});
|
|
735
|
+
return sigers;
|
|
736
|
+
}
|
|
737
|
+
else {
|
|
738
|
+
const cigars = new Array();
|
|
739
|
+
signers.forEach((signer) => {
|
|
740
|
+
cigars.push(signer.sign(ser));
|
|
741
|
+
});
|
|
742
|
+
return cigars;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
export function riKey(pre, ridx) {
|
|
747
|
+
return pre + '.' + ridx.toString(16).padStart(32, '0');
|
|
748
|
+
}
|
|
749
|
+
/**
|
|
750
|
+
* Keeper sets up named sub databases for key pair storage (KS).
|
|
751
|
+
* Methods provide key pair creation, storage, and data signing.
|
|
752
|
+
* In-memory test implementation of Keeper key store
|
|
753
|
+
*/
|
|
754
|
+
class Keeper {
|
|
755
|
+
constructor() {
|
|
756
|
+
this._gbls = new Map();
|
|
757
|
+
this._pris = new Map();
|
|
758
|
+
this._pths = new Map();
|
|
759
|
+
this._pres = new Map();
|
|
760
|
+
this._prms = new Map();
|
|
761
|
+
this._sits = new Map();
|
|
762
|
+
this._pubs = new Map();
|
|
763
|
+
}
|
|
764
|
+
getGbls(key) {
|
|
765
|
+
return this._gbls.get(key);
|
|
766
|
+
}
|
|
767
|
+
pinGbls(key, val) {
|
|
768
|
+
this._gbls.set(key, val);
|
|
769
|
+
}
|
|
770
|
+
prmsElements() {
|
|
771
|
+
const out = new Array();
|
|
772
|
+
this._prms.forEach((value, key) => {
|
|
773
|
+
out.push([key, value]);
|
|
774
|
+
});
|
|
775
|
+
return out;
|
|
776
|
+
}
|
|
777
|
+
getPrms(keys) {
|
|
778
|
+
return this._prms.get(keys);
|
|
779
|
+
}
|
|
780
|
+
pinPrms(keys, data) {
|
|
781
|
+
this._prms.set(keys, data);
|
|
782
|
+
}
|
|
783
|
+
putPrms(keys, data) {
|
|
784
|
+
if (this._prms.has(keys)) {
|
|
785
|
+
return false;
|
|
786
|
+
}
|
|
787
|
+
this._prms.set(keys, data);
|
|
788
|
+
return true;
|
|
789
|
+
}
|
|
790
|
+
remPrms(keys) {
|
|
791
|
+
return this._prms.delete(keys);
|
|
792
|
+
}
|
|
793
|
+
prisElements(decrypter) {
|
|
794
|
+
const out = new Array();
|
|
795
|
+
this._pris.forEach(function (val, pubKey) {
|
|
796
|
+
const verfer = new Verfer({ qb64: pubKey });
|
|
797
|
+
const signer = decrypter.decrypt(val, null, verfer.transferable);
|
|
798
|
+
out.push([pubKey, signer]);
|
|
799
|
+
});
|
|
800
|
+
return out;
|
|
801
|
+
}
|
|
802
|
+
pinPris(pubKey, signer, encrypter) {
|
|
803
|
+
const cipher = encrypter.encrypt(null, signer);
|
|
804
|
+
this._pris.set(pubKey, cipher.qb64b);
|
|
805
|
+
}
|
|
806
|
+
putPris(pubKey, signer, encrypter) {
|
|
807
|
+
if (this._pris.has(pubKey)) {
|
|
808
|
+
return false;
|
|
809
|
+
}
|
|
810
|
+
const cipher = encrypter.encrypt(null, signer);
|
|
811
|
+
this._pris.set(pubKey, cipher.qb64b);
|
|
812
|
+
return true;
|
|
813
|
+
}
|
|
814
|
+
getPris(pubKey, decrypter) {
|
|
815
|
+
const val = this._pris.get(pubKey);
|
|
816
|
+
if (val == undefined) {
|
|
817
|
+
return undefined;
|
|
818
|
+
}
|
|
819
|
+
const verfer = new Verfer({ qb64: pubKey });
|
|
820
|
+
return decrypter.decrypt(val, null, verfer.transferable);
|
|
821
|
+
}
|
|
822
|
+
pinPths(pubKey, val) {
|
|
823
|
+
this._pths.set(pubKey, val);
|
|
824
|
+
return true;
|
|
825
|
+
}
|
|
826
|
+
putPths(pubKey, val) {
|
|
827
|
+
if (this._pths.has(pubKey)) {
|
|
828
|
+
return false;
|
|
829
|
+
}
|
|
830
|
+
this._pths.set(pubKey, val);
|
|
831
|
+
return true;
|
|
832
|
+
}
|
|
833
|
+
getPths(pubKey) {
|
|
834
|
+
return this._pths.get(pubKey);
|
|
835
|
+
}
|
|
836
|
+
remPris(pubKey) {
|
|
837
|
+
this._pris.delete(pubKey);
|
|
838
|
+
}
|
|
839
|
+
getPres(pre) {
|
|
840
|
+
return this._pres.get(pre);
|
|
841
|
+
}
|
|
842
|
+
pinPres(pre, val) {
|
|
843
|
+
this._pres.set(pre, val);
|
|
844
|
+
return true;
|
|
845
|
+
}
|
|
846
|
+
putPres(pre, val) {
|
|
847
|
+
if (this._pres.has(pre)) {
|
|
848
|
+
return false;
|
|
849
|
+
}
|
|
850
|
+
this._pres.set(pre, val);
|
|
851
|
+
return true;
|
|
852
|
+
}
|
|
853
|
+
getSits(keys) {
|
|
854
|
+
return this._sits.get(keys);
|
|
855
|
+
}
|
|
856
|
+
putSits(pre, val) {
|
|
857
|
+
if (this._sits.has(pre)) {
|
|
858
|
+
return false;
|
|
859
|
+
}
|
|
860
|
+
this._sits.set(pre, val);
|
|
861
|
+
return true;
|
|
862
|
+
}
|
|
863
|
+
pinSits(pre, val) {
|
|
864
|
+
this._sits.set(pre, val);
|
|
865
|
+
return true;
|
|
866
|
+
}
|
|
867
|
+
remSits(keys) {
|
|
868
|
+
return this._sits.delete(keys);
|
|
869
|
+
}
|
|
870
|
+
getPubs(keys) {
|
|
871
|
+
return this._pubs.get(keys);
|
|
872
|
+
}
|
|
873
|
+
putPubs(keys, data) {
|
|
874
|
+
if (this._pubs.has(keys)) {
|
|
875
|
+
return false;
|
|
876
|
+
}
|
|
877
|
+
this._pubs.set(keys, data);
|
|
878
|
+
return true;
|
|
879
|
+
}
|
|
880
|
+
}
|