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