@sphereon/ssi-sdk-ext.mnemonic-seed-manager 0.28.1-feature.oyd.cmsm.improv.20 → 0.28.1-next.53
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/dist/index.cjs +746 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{types/IMnemonicSeedManager.d.ts → index.d.cts} +73 -14
- package/dist/index.d.ts +169 -9
- package/dist/index.js +716 -37
- package/dist/index.js.map +1 -1
- package/package.json +27 -12
- package/src/entities/MnemonicEntity.ts +10 -15
- package/src/index.ts +1 -0
- package/dist/agent/MnemonicSeedManager.d.ts +0 -26
- package/dist/agent/MnemonicSeedManager.d.ts.map +0 -1
- package/dist/agent/MnemonicSeedManager.js +0 -209
- package/dist/agent/MnemonicSeedManager.js.map +0 -1
- package/dist/entities/MnemonicEntity.d.ts +0 -9
- package/dist/entities/MnemonicEntity.d.ts.map +0 -1
- package/dist/entities/MnemonicEntity.js +0 -50
- package/dist/entities/MnemonicEntity.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/migrations/generic/1-CreateMnemonics.d.ts +0 -7
- package/dist/migrations/generic/1-CreateMnemonics.d.ts.map +0 -1
- package/dist/migrations/generic/1-CreateMnemonics.js +0 -72
- package/dist/migrations/generic/1-CreateMnemonics.js.map +0 -1
- package/dist/migrations/generic/index.d.ts +0 -10
- package/dist/migrations/generic/index.d.ts.map +0 -1
- package/dist/migrations/generic/index.js +0 -13
- package/dist/migrations/generic/index.js.map +0 -1
- package/dist/migrations/index.d.ts +0 -2
- package/dist/migrations/index.d.ts.map +0 -1
- package/dist/migrations/index.js +0 -6
- package/dist/migrations/index.js.map +0 -1
- package/dist/migrations/internal-migrations-ormconfig.d.ts +0 -7
- package/dist/migrations/internal-migrations-ormconfig.d.ts.map +0 -1
- package/dist/migrations/internal-migrations-ormconfig.js +0 -29
- package/dist/migrations/internal-migrations-ormconfig.js.map +0 -1
- package/dist/migrations/postgres/1659566636105-CreateMnemonics.d.ts +0 -7
- package/dist/migrations/postgres/1659566636105-CreateMnemonics.d.ts.map +0 -1
- package/dist/migrations/postgres/1659566636105-CreateMnemonics.js +0 -29
- package/dist/migrations/postgres/1659566636105-CreateMnemonics.js.map +0 -1
- package/dist/migrations/sqlite/1659566622817-CreateMnemonics.d.ts +0 -7
- package/dist/migrations/sqlite/1659566622817-CreateMnemonics.d.ts.map +0 -1
- package/dist/migrations/sqlite/1659566622817-CreateMnemonics.js +0 -29
- package/dist/migrations/sqlite/1659566622817-CreateMnemonics.js.map +0 -1
- package/dist/types/IMnemonicSeedManager.d.ts.map +0 -1
- package/dist/types/IMnemonicSeedManager.js +0 -3
- package/dist/types/IMnemonicSeedManager.js.map +0 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,746 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
10
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
11
|
+
};
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
30
|
+
mod
|
|
31
|
+
));
|
|
32
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
|
+
|
|
34
|
+
// plugin.schema.json
|
|
35
|
+
var require_plugin_schema = __commonJS({
|
|
36
|
+
"plugin.schema.json"(exports, module2) {
|
|
37
|
+
module2.exports = {
|
|
38
|
+
IMnemonicSeedManager: {
|
|
39
|
+
components: {
|
|
40
|
+
schemas: {
|
|
41
|
+
IMnemonicInfoStoreArgs: {
|
|
42
|
+
type: "object",
|
|
43
|
+
properties: {
|
|
44
|
+
id: {
|
|
45
|
+
type: "string"
|
|
46
|
+
},
|
|
47
|
+
hash: {
|
|
48
|
+
type: "string"
|
|
49
|
+
},
|
|
50
|
+
mnemonic: {
|
|
51
|
+
type: "array",
|
|
52
|
+
items: {
|
|
53
|
+
type: "string"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
masterKey: {
|
|
57
|
+
type: "string"
|
|
58
|
+
},
|
|
59
|
+
chainCode: {
|
|
60
|
+
type: "string"
|
|
61
|
+
},
|
|
62
|
+
kms: {
|
|
63
|
+
type: "string"
|
|
64
|
+
},
|
|
65
|
+
path: {
|
|
66
|
+
type: "string"
|
|
67
|
+
},
|
|
68
|
+
withZeroBytes: {
|
|
69
|
+
type: "boolean"
|
|
70
|
+
},
|
|
71
|
+
type: {
|
|
72
|
+
type: "string",
|
|
73
|
+
enum: [
|
|
74
|
+
"Ed25519",
|
|
75
|
+
"Secp256k1"
|
|
76
|
+
]
|
|
77
|
+
},
|
|
78
|
+
persist: {
|
|
79
|
+
type: "boolean"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
DeleteResult: {
|
|
84
|
+
type: "object",
|
|
85
|
+
properties: {
|
|
86
|
+
raw: {},
|
|
87
|
+
affected: {
|
|
88
|
+
type: [
|
|
89
|
+
"number",
|
|
90
|
+
"null"
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
required: [
|
|
95
|
+
"raw"
|
|
96
|
+
]
|
|
97
|
+
},
|
|
98
|
+
ManagedKeyInfo: {
|
|
99
|
+
type: "object",
|
|
100
|
+
properties: {
|
|
101
|
+
kid: {
|
|
102
|
+
type: "string",
|
|
103
|
+
description: "Key ID"
|
|
104
|
+
},
|
|
105
|
+
kms: {
|
|
106
|
+
type: "string",
|
|
107
|
+
description: "Key Management System"
|
|
108
|
+
},
|
|
109
|
+
type: {
|
|
110
|
+
$ref: "#/components/schemas/TKeyType",
|
|
111
|
+
description: "Key type"
|
|
112
|
+
},
|
|
113
|
+
publicKeyHex: {
|
|
114
|
+
type: "string",
|
|
115
|
+
description: "Public key"
|
|
116
|
+
},
|
|
117
|
+
meta: {
|
|
118
|
+
anyOf: [
|
|
119
|
+
{
|
|
120
|
+
$ref: "#/components/schemas/KeyMetadata"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
type: "null"
|
|
124
|
+
}
|
|
125
|
+
],
|
|
126
|
+
description: "Optional. Key metadata. This should be used to determine which algorithms are supported."
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
required: [
|
|
130
|
+
"kid",
|
|
131
|
+
"kms",
|
|
132
|
+
"type",
|
|
133
|
+
"publicKeyHex"
|
|
134
|
+
],
|
|
135
|
+
description: "Represents information about a managed key. Private or secret key material is NOT present."
|
|
136
|
+
},
|
|
137
|
+
TKeyType: {
|
|
138
|
+
type: "string",
|
|
139
|
+
enum: [
|
|
140
|
+
"Ed25519",
|
|
141
|
+
"Secp256k1",
|
|
142
|
+
"Secp256r1",
|
|
143
|
+
"X25519",
|
|
144
|
+
"Bls12381G1",
|
|
145
|
+
"Bls12381G2",
|
|
146
|
+
"RSA"
|
|
147
|
+
],
|
|
148
|
+
description: "Cryptographic key type."
|
|
149
|
+
},
|
|
150
|
+
KeyMetadata: {
|
|
151
|
+
type: "object",
|
|
152
|
+
properties: {
|
|
153
|
+
algorithms: {
|
|
154
|
+
type: "array",
|
|
155
|
+
items: {
|
|
156
|
+
type: "string"
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
description: "This encapsulates data about a key.\n\nImplementations of {@link @veramo/key-manager#AbstractKeyManagementSystem | AbstractKeyManagementSystem } should populate this object, for each key, with the algorithms that can be performed using it.\n\nThis can also be used to add various tags to the keys under management."
|
|
161
|
+
},
|
|
162
|
+
IMnemonicInfoKeyResult: {
|
|
163
|
+
type: "object",
|
|
164
|
+
properties: {
|
|
165
|
+
masterKey: {
|
|
166
|
+
type: "string"
|
|
167
|
+
},
|
|
168
|
+
chainCode: {
|
|
169
|
+
type: "string"
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
IMnemonicGeneratorArgs: {
|
|
174
|
+
type: "object",
|
|
175
|
+
properties: {
|
|
176
|
+
bits: {
|
|
177
|
+
type: "number",
|
|
178
|
+
enum: [
|
|
179
|
+
128,
|
|
180
|
+
160,
|
|
181
|
+
192,
|
|
182
|
+
224,
|
|
183
|
+
256
|
|
184
|
+
]
|
|
185
|
+
},
|
|
186
|
+
id: {
|
|
187
|
+
type: "string"
|
|
188
|
+
},
|
|
189
|
+
persist: {
|
|
190
|
+
type: "boolean"
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
required: [
|
|
194
|
+
"bits"
|
|
195
|
+
]
|
|
196
|
+
},
|
|
197
|
+
IMnemonicInfoResult: {
|
|
198
|
+
type: "object",
|
|
199
|
+
properties: {
|
|
200
|
+
id: {
|
|
201
|
+
type: "string"
|
|
202
|
+
},
|
|
203
|
+
hash: {
|
|
204
|
+
type: "string"
|
|
205
|
+
},
|
|
206
|
+
mnemonic: {
|
|
207
|
+
type: "array",
|
|
208
|
+
items: {
|
|
209
|
+
type: "string"
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
masterKey: {
|
|
213
|
+
type: "string"
|
|
214
|
+
},
|
|
215
|
+
chainCode: {
|
|
216
|
+
type: "string"
|
|
217
|
+
},
|
|
218
|
+
kms: {
|
|
219
|
+
type: "string"
|
|
220
|
+
},
|
|
221
|
+
path: {
|
|
222
|
+
type: "string"
|
|
223
|
+
},
|
|
224
|
+
withZeroBytes: {
|
|
225
|
+
type: "boolean"
|
|
226
|
+
},
|
|
227
|
+
type: {
|
|
228
|
+
type: "string",
|
|
229
|
+
enum: [
|
|
230
|
+
"Ed25519",
|
|
231
|
+
"Secp256k1"
|
|
232
|
+
]
|
|
233
|
+
},
|
|
234
|
+
persist: {
|
|
235
|
+
type: "boolean"
|
|
236
|
+
},
|
|
237
|
+
succeeded: {
|
|
238
|
+
type: "boolean"
|
|
239
|
+
},
|
|
240
|
+
seed: {
|
|
241
|
+
type: "string"
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
ISeedGeneratorArgs: {
|
|
246
|
+
type: "object",
|
|
247
|
+
properties: {
|
|
248
|
+
mnemonic: {
|
|
249
|
+
type: "array",
|
|
250
|
+
items: {
|
|
251
|
+
type: "string"
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
required: [
|
|
256
|
+
"mnemonic"
|
|
257
|
+
]
|
|
258
|
+
},
|
|
259
|
+
IMnemonicVerificationArgs: {
|
|
260
|
+
type: "object",
|
|
261
|
+
properties: {
|
|
262
|
+
id: {
|
|
263
|
+
type: "string"
|
|
264
|
+
},
|
|
265
|
+
hash: {
|
|
266
|
+
type: "string"
|
|
267
|
+
},
|
|
268
|
+
wordList: {
|
|
269
|
+
type: "array",
|
|
270
|
+
items: {
|
|
271
|
+
type: "string"
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
required: [
|
|
276
|
+
"wordList"
|
|
277
|
+
]
|
|
278
|
+
},
|
|
279
|
+
IPartialMnemonicVerificationArgs: {
|
|
280
|
+
type: "object",
|
|
281
|
+
properties: {
|
|
282
|
+
id: {
|
|
283
|
+
type: "string"
|
|
284
|
+
},
|
|
285
|
+
hash: {
|
|
286
|
+
type: "string"
|
|
287
|
+
},
|
|
288
|
+
indexedWordList: {
|
|
289
|
+
type: "array",
|
|
290
|
+
items: {
|
|
291
|
+
type: "array",
|
|
292
|
+
minItems: 2,
|
|
293
|
+
items: [
|
|
294
|
+
{
|
|
295
|
+
type: "number"
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
type: "string"
|
|
299
|
+
}
|
|
300
|
+
],
|
|
301
|
+
maxItems: 2
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
required: [
|
|
306
|
+
"indexedWordList"
|
|
307
|
+
]
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
methods: {
|
|
311
|
+
deleteMnemonicInfo: {
|
|
312
|
+
description: "",
|
|
313
|
+
arguments: {
|
|
314
|
+
$ref: "#/components/schemas/IMnemonicInfoStoreArgs"
|
|
315
|
+
},
|
|
316
|
+
returnType: {
|
|
317
|
+
$ref: "#/components/schemas/DeleteResult"
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
generateKeysFromMnemonic: {
|
|
321
|
+
description: "",
|
|
322
|
+
arguments: {
|
|
323
|
+
$ref: "#/components/schemas/IMnemonicInfoStoreArgs"
|
|
324
|
+
},
|
|
325
|
+
returnType: {
|
|
326
|
+
$ref: "#/components/schemas/ManagedKeyInfo"
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
generateMasterKey: {
|
|
330
|
+
description: "",
|
|
331
|
+
arguments: {
|
|
332
|
+
$ref: "#/components/schemas/IMnemonicInfoStoreArgs"
|
|
333
|
+
},
|
|
334
|
+
returnType: {
|
|
335
|
+
$ref: "#/components/schemas/IMnemonicInfoKeyResult"
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
generateMnemonic: {
|
|
339
|
+
description: "",
|
|
340
|
+
arguments: {
|
|
341
|
+
$ref: "#/components/schemas/IMnemonicGeneratorArgs"
|
|
342
|
+
},
|
|
343
|
+
returnType: {
|
|
344
|
+
$ref: "#/components/schemas/IMnemonicInfoResult"
|
|
345
|
+
}
|
|
346
|
+
},
|
|
347
|
+
generateSeed: {
|
|
348
|
+
description: "",
|
|
349
|
+
arguments: {
|
|
350
|
+
$ref: "#/components/schemas/ISeedGeneratorArgs"
|
|
351
|
+
},
|
|
352
|
+
returnType: {
|
|
353
|
+
$ref: "#/components/schemas/IMnemonicInfoResult"
|
|
354
|
+
}
|
|
355
|
+
},
|
|
356
|
+
getMnemonicInfo: {
|
|
357
|
+
description: "",
|
|
358
|
+
arguments: {
|
|
359
|
+
$ref: "#/components/schemas/IMnemonicInfoStoreArgs"
|
|
360
|
+
},
|
|
361
|
+
returnType: {
|
|
362
|
+
$ref: "#/components/schemas/IMnemonicInfoResult"
|
|
363
|
+
}
|
|
364
|
+
},
|
|
365
|
+
saveMnemonicInfo: {
|
|
366
|
+
description: "",
|
|
367
|
+
arguments: {
|
|
368
|
+
$ref: "#/components/schemas/IMnemonicInfoStoreArgs"
|
|
369
|
+
},
|
|
370
|
+
returnType: {
|
|
371
|
+
$ref: "#/components/schemas/IMnemonicInfoResult"
|
|
372
|
+
}
|
|
373
|
+
},
|
|
374
|
+
verifyMnemonic: {
|
|
375
|
+
description: "",
|
|
376
|
+
arguments: {
|
|
377
|
+
$ref: "#/components/schemas/IMnemonicVerificationArgs"
|
|
378
|
+
},
|
|
379
|
+
returnType: {
|
|
380
|
+
$ref: "#/components/schemas/IMnemonicInfoResult"
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
verifyPartialMnemonic: {
|
|
384
|
+
description: "",
|
|
385
|
+
arguments: {
|
|
386
|
+
$ref: "#/components/schemas/IPartialMnemonicVerificationArgs"
|
|
387
|
+
},
|
|
388
|
+
returnType: {
|
|
389
|
+
$ref: "#/components/schemas/IMnemonicInfoResult"
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
// src/index.ts
|
|
400
|
+
var index_exports = {};
|
|
401
|
+
__export(index_exports, {
|
|
402
|
+
MnemonicSeedManager: () => MnemonicSeedManager,
|
|
403
|
+
MnemonicSeedManagerEntities: () => MnemonicSeedManagerEntities,
|
|
404
|
+
MnemonicSeedManagerMigrations: () => MnemonicSeedManagerMigrations,
|
|
405
|
+
schema: () => schema
|
|
406
|
+
});
|
|
407
|
+
module.exports = __toCommonJS(index_exports);
|
|
408
|
+
var import_reflect_metadata = require("reflect-metadata");
|
|
409
|
+
|
|
410
|
+
// src/entities/MnemonicEntity.ts
|
|
411
|
+
var import_typeorm = require("typeorm");
|
|
412
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
413
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
414
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
415
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
416
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
417
|
+
}
|
|
418
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
419
|
+
function _ts_metadata(k, v) {
|
|
420
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
421
|
+
}
|
|
422
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
423
|
+
var MnemonicEntity = class extends import_typeorm.BaseEntity {
|
|
424
|
+
static {
|
|
425
|
+
__name(this, "MnemonicEntity");
|
|
426
|
+
}
|
|
427
|
+
id;
|
|
428
|
+
hash;
|
|
429
|
+
mnemonic;
|
|
430
|
+
masterKey;
|
|
431
|
+
chainCode;
|
|
432
|
+
};
|
|
433
|
+
_ts_decorate([
|
|
434
|
+
(0, import_typeorm.PrimaryColumn)({
|
|
435
|
+
name: "id",
|
|
436
|
+
type: "varchar"
|
|
437
|
+
}),
|
|
438
|
+
_ts_metadata("design:type", String)
|
|
439
|
+
], MnemonicEntity.prototype, "id", void 0);
|
|
440
|
+
_ts_decorate([
|
|
441
|
+
(0, import_typeorm.Column)({
|
|
442
|
+
name: "hash",
|
|
443
|
+
unique: true,
|
|
444
|
+
type: "varchar"
|
|
445
|
+
}),
|
|
446
|
+
_ts_metadata("design:type", String)
|
|
447
|
+
], MnemonicEntity.prototype, "hash", void 0);
|
|
448
|
+
_ts_decorate([
|
|
449
|
+
(0, import_typeorm.Column)({
|
|
450
|
+
name: "mnemonic",
|
|
451
|
+
unique: true,
|
|
452
|
+
type: "varchar"
|
|
453
|
+
}),
|
|
454
|
+
_ts_metadata("design:type", String)
|
|
455
|
+
], MnemonicEntity.prototype, "mnemonic", void 0);
|
|
456
|
+
_ts_decorate([
|
|
457
|
+
(0, import_typeorm.Column)({
|
|
458
|
+
name: "master_key",
|
|
459
|
+
default: null,
|
|
460
|
+
type: "varchar"
|
|
461
|
+
}),
|
|
462
|
+
_ts_metadata("design:type", String)
|
|
463
|
+
], MnemonicEntity.prototype, "masterKey", void 0);
|
|
464
|
+
_ts_decorate([
|
|
465
|
+
(0, import_typeorm.Column)({
|
|
466
|
+
name: "chain_code",
|
|
467
|
+
default: null,
|
|
468
|
+
type: "varchar"
|
|
469
|
+
}),
|
|
470
|
+
_ts_metadata("design:type", String)
|
|
471
|
+
], MnemonicEntity.prototype, "chainCode", void 0);
|
|
472
|
+
MnemonicEntity = _ts_decorate([
|
|
473
|
+
(0, import_typeorm.Entity)("Mnemonic")
|
|
474
|
+
], MnemonicEntity);
|
|
475
|
+
|
|
476
|
+
// src/agent/MnemonicSeedManager.ts
|
|
477
|
+
var import_utils = require("@noble/hashes/utils");
|
|
478
|
+
var import_ssi_sdk_ext = require("@sphereon/ssi-sdk-ext.key-utils");
|
|
479
|
+
var import_ed25519_hd_key = require("ed25519-hd-key");
|
|
480
|
+
var bip39 = __toESM(require("bip39"), 1);
|
|
481
|
+
var MnemonicSeedManager = class {
|
|
482
|
+
static {
|
|
483
|
+
__name(this, "MnemonicSeedManager");
|
|
484
|
+
}
|
|
485
|
+
dbConnection;
|
|
486
|
+
secretBox;
|
|
487
|
+
schema;
|
|
488
|
+
methods;
|
|
489
|
+
constructor(dbConnection, secretBox) {
|
|
490
|
+
this.dbConnection = dbConnection;
|
|
491
|
+
this.secretBox = secretBox;
|
|
492
|
+
this.schema = schema.IMnemonicInfoGenerator;
|
|
493
|
+
this.methods = {
|
|
494
|
+
generateMnemonic: this.generateMnemonic.bind(this),
|
|
495
|
+
generateSeed: this.generateSeed.bind(this),
|
|
496
|
+
verifyMnemonic: this.verifyMnemonic.bind(this),
|
|
497
|
+
verifyPartialMnemonic: this.verifyPartialMnemonic.bind(this),
|
|
498
|
+
saveMnemonicInfo: this.saveMnemonicInfo.bind(this),
|
|
499
|
+
getMnemonicInfo: this.getMnemonicInfo.bind(this),
|
|
500
|
+
deleteMnemonicInfo: this.deleteMnemonicInfo.bind(this),
|
|
501
|
+
generateMasterKey: this.generateMasterKey.bind(this),
|
|
502
|
+
generateKeysFromMnemonic: this.generateKeysFromMnemonic.bind(this)
|
|
503
|
+
};
|
|
504
|
+
if (!secretBox) {
|
|
505
|
+
console.warn("Please provide SecretBox to the KeyStore");
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
async generateMnemonic(args) {
|
|
509
|
+
const mnemonic = bip39.generateMnemonic(args.bits);
|
|
510
|
+
if (args.persist) {
|
|
511
|
+
return await this.saveMnemonicInfo({
|
|
512
|
+
id: args.id,
|
|
513
|
+
mnemonic: mnemonic.split(" ")
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
return {
|
|
517
|
+
mnemonic: mnemonic.split(" ")
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
async verifyMnemonic(args) {
|
|
521
|
+
const mnemonicInfo = await this.getMnemonicInfo({
|
|
522
|
+
id: args.id,
|
|
523
|
+
hash: args.hash
|
|
524
|
+
});
|
|
525
|
+
if (mnemonicInfo?.mnemonic) {
|
|
526
|
+
return {
|
|
527
|
+
succeeded: mnemonicInfo.mnemonic.join(" ") === args.wordList?.join(" ")
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
throw new Error("Mnemonic not found");
|
|
531
|
+
}
|
|
532
|
+
async verifyPartialMnemonic(args) {
|
|
533
|
+
const mnemonicInfo = await this.getMnemonicInfo({
|
|
534
|
+
id: args.id,
|
|
535
|
+
hash: args.hash
|
|
536
|
+
});
|
|
537
|
+
if (mnemonicInfo?.mnemonic) {
|
|
538
|
+
return {
|
|
539
|
+
succeeded: args.indexedWordList.every((indexedWord) => mnemonicInfo.mnemonic?.indexOf(indexedWord[1]) === indexedWord[0])
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
throw new Error("Mnemonic not found");
|
|
543
|
+
}
|
|
544
|
+
async generateSeed(args) {
|
|
545
|
+
return Promise.resolve({
|
|
546
|
+
seed: (await bip39.mnemonicToSeed(args.mnemonic.join(" "))).toString("hex")
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
async saveMnemonicInfo(args) {
|
|
550
|
+
if (args.mnemonic && this.secretBox) {
|
|
551
|
+
const mnemonic = args.mnemonic.join(" ");
|
|
552
|
+
const hash = (0, import_utils.bytesToHex)((0, import_ssi_sdk_ext.shaHasher)(mnemonic, "sha256"));
|
|
553
|
+
const mnemonicInfo = new MnemonicEntity();
|
|
554
|
+
mnemonicInfo.id = args.id ? args.id : hash;
|
|
555
|
+
mnemonicInfo.hash = hash;
|
|
556
|
+
mnemonicInfo.mnemonic = await this.secretBox.encrypt(mnemonic);
|
|
557
|
+
const result = await (await this.dbConnection).getRepository(MnemonicEntity).save(mnemonicInfo);
|
|
558
|
+
return Promise.resolve({
|
|
559
|
+
id: result.id,
|
|
560
|
+
hash: result.hash,
|
|
561
|
+
mnemonic: args.mnemonic
|
|
562
|
+
});
|
|
563
|
+
} else {
|
|
564
|
+
throw new Error("Mnemonic needs to be provided.");
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
async getMnemonicInfo(args) {
|
|
568
|
+
const mnemonicInfo = await (await this.dbConnection).getRepository(MnemonicEntity).createQueryBuilder().where("id = :id", {
|
|
569
|
+
id: args.id
|
|
570
|
+
}).orWhere("hash = :hash", {
|
|
571
|
+
hash: args.hash
|
|
572
|
+
}).getOne();
|
|
573
|
+
if (mnemonicInfo?.mnemonic) {
|
|
574
|
+
const mnemonicStr = await this.secretBox?.decrypt(mnemonicInfo.mnemonic);
|
|
575
|
+
return {
|
|
576
|
+
id: mnemonicInfo.id,
|
|
577
|
+
hash: mnemonicInfo.hash,
|
|
578
|
+
mnemonic: mnemonicStr?.split(" ")
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
return {};
|
|
582
|
+
}
|
|
583
|
+
async deleteMnemonicInfo(args) {
|
|
584
|
+
return (await this.dbConnection).createQueryBuilder().delete().from(MnemonicEntity).where("id = :id", {
|
|
585
|
+
id: args.id
|
|
586
|
+
}).orWhere("hash = :hash", {
|
|
587
|
+
hash: args.hash
|
|
588
|
+
}).execute();
|
|
589
|
+
}
|
|
590
|
+
async saveMasterKey(args) {
|
|
591
|
+
if (args.masterKey) {
|
|
592
|
+
return (await this.dbConnection).createQueryBuilder().update(MnemonicEntity).set({
|
|
593
|
+
masterKey: args.masterKey
|
|
594
|
+
}).where("id = :id", {
|
|
595
|
+
id: args.id
|
|
596
|
+
}).orWhere("hash = :hash", {
|
|
597
|
+
hash: args.hash
|
|
598
|
+
}).execute();
|
|
599
|
+
}
|
|
600
|
+
throw new Error("Master Key needs to be provided.");
|
|
601
|
+
}
|
|
602
|
+
async generateMasterKey(args) {
|
|
603
|
+
const mnemonic = (await this.getMnemonicInfo({
|
|
604
|
+
id: args.id,
|
|
605
|
+
hash: args.hash
|
|
606
|
+
})).mnemonic;
|
|
607
|
+
if (mnemonic) {
|
|
608
|
+
const mnemonicInfo = await this.generateSeed({
|
|
609
|
+
mnemonic
|
|
610
|
+
});
|
|
611
|
+
if (mnemonicInfo.seed) {
|
|
612
|
+
if (args.type === "Ed25519") {
|
|
613
|
+
const { key, chainCode } = (0, import_ed25519_hd_key.getMasterKeyFromSeed)(mnemonicInfo.seed);
|
|
614
|
+
await this.saveMasterKey({
|
|
615
|
+
masterKey: key.toString("hex"),
|
|
616
|
+
chainCode: chainCode.toString("hex")
|
|
617
|
+
});
|
|
618
|
+
return {
|
|
619
|
+
masterKey: key.toString("hex"),
|
|
620
|
+
chainCode: chainCode.toString("hex")
|
|
621
|
+
};
|
|
622
|
+
} else {
|
|
623
|
+
throw new Error("Secp256k1 keys are not supported yet");
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
throw new Error("Mnemonic not found");
|
|
628
|
+
}
|
|
629
|
+
async generateKeysFromMnemonic(args, context) {
|
|
630
|
+
const mnemonic = (await this.getMnemonicInfo({
|
|
631
|
+
id: args.id,
|
|
632
|
+
hash: args.hash
|
|
633
|
+
})).mnemonic;
|
|
634
|
+
if (mnemonic && context) {
|
|
635
|
+
if (args.path && args.kms) {
|
|
636
|
+
const seed = (await this.generateSeed({
|
|
637
|
+
mnemonic
|
|
638
|
+
})).seed;
|
|
639
|
+
const { key, chainCode } = (0, import_ed25519_hd_key.derivePath)(args.path, seed);
|
|
640
|
+
const extPrivateKey = Buffer.concat([
|
|
641
|
+
key,
|
|
642
|
+
chainCode
|
|
643
|
+
]);
|
|
644
|
+
const publicKey = (0, import_ed25519_hd_key.getPublicKey)(key, args.withZeroBytes);
|
|
645
|
+
return await context.agent.keyManagerImport({
|
|
646
|
+
privateKeyHex: extPrivateKey.toString("hex"),
|
|
647
|
+
publicKeyHex: publicKey.toString("hex"),
|
|
648
|
+
type: "Ed25519",
|
|
649
|
+
kms: args.kms
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
throw new Error("Please provide kms and derivation path");
|
|
653
|
+
}
|
|
654
|
+
throw new Error("Master Key not found");
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
|
|
658
|
+
// src/migrations/generic/1-CreateMnemonics.ts
|
|
659
|
+
var import_debug = __toESM(require("debug"), 1);
|
|
660
|
+
|
|
661
|
+
// src/migrations/postgres/1659566636105-CreateMnemonics.ts
|
|
662
|
+
var CreateMnemonics1659566636105 = class {
|
|
663
|
+
static {
|
|
664
|
+
__name(this, "CreateMnemonics1659566636105");
|
|
665
|
+
}
|
|
666
|
+
name = "CreateMnemonics1659566636105";
|
|
667
|
+
async up(queryRunner) {
|
|
668
|
+
await queryRunner.query(`CREATE TABLE "Mnemonic" ("id" character varying NOT NULL, "hash" character varying NOT NULL, "mnemonic" character varying NOT NULL, "master_key" character varying, "chain_code" character varying, CONSTRAINT "UQ_hash" UNIQUE ("hash"), CONSTRAINT "UQ_mnemonic" UNIQUE ("mnemonic"), CONSTRAINT "PK_mnemonic_id" PRIMARY KEY ("id"))`);
|
|
669
|
+
}
|
|
670
|
+
async down(queryRunner) {
|
|
671
|
+
await queryRunner.query(`DROP TABLE "Mnemonic"`);
|
|
672
|
+
}
|
|
673
|
+
};
|
|
674
|
+
|
|
675
|
+
// src/migrations/sqlite/1659566622817-CreateMnemonics.ts
|
|
676
|
+
var CreateMnemonics1659566622817 = class {
|
|
677
|
+
static {
|
|
678
|
+
__name(this, "CreateMnemonics1659566622817");
|
|
679
|
+
}
|
|
680
|
+
name = "CreateMnemonics1659566622817";
|
|
681
|
+
async up(queryRunner) {
|
|
682
|
+
await queryRunner.query(`CREATE TABLE "Mnemonic" ("id" varchar PRIMARY KEY NOT NULL, "hash" varchar NOT NULL, "mnemonic" varchar NOT NULL, "master_key" varchar, "chain_code" varchar, CONSTRAINT "UQ_hash" UNIQUE ("hash"), CONSTRAINT "UQ_mnemonic" UNIQUE ("mnemonic"))`);
|
|
683
|
+
}
|
|
684
|
+
async down(queryRunner) {
|
|
685
|
+
await queryRunner.query(`DROP TABLE "Mnemonic"`);
|
|
686
|
+
}
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
// src/migrations/generic/1-CreateMnemonics.ts
|
|
690
|
+
var debug = (0, import_debug.default)("sphereon:ssi-sdk:migrations");
|
|
691
|
+
var CreateMnemonics1659567079429 = class {
|
|
692
|
+
static {
|
|
693
|
+
__name(this, "CreateMnemonics1659567079429");
|
|
694
|
+
}
|
|
695
|
+
name = "CreateMnemonics1659567079429";
|
|
696
|
+
async up(queryRunner) {
|
|
697
|
+
debug("migration: creating mnemonic tables");
|
|
698
|
+
const dbType = queryRunner.connection.driver.options.type;
|
|
699
|
+
if (dbType === "postgres") {
|
|
700
|
+
debug("using postgres migration file");
|
|
701
|
+
const mig = new CreateMnemonics1659566636105();
|
|
702
|
+
const up = await mig.up(queryRunner);
|
|
703
|
+
debug("Migration statements executed");
|
|
704
|
+
return up;
|
|
705
|
+
} else if (dbType === "sqlite" || "react-native") {
|
|
706
|
+
debug("using sqlite/react-native migration file");
|
|
707
|
+
const mig = new CreateMnemonics1659566622817();
|
|
708
|
+
const up = await mig.up(queryRunner);
|
|
709
|
+
debug("Migration statements executed");
|
|
710
|
+
return up;
|
|
711
|
+
} else {
|
|
712
|
+
return Promise.reject("Migrations are currently only supported for sqlite, react-native and postgres. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now");
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
async down(queryRunner) {
|
|
716
|
+
debug("reverting mnemonic tables");
|
|
717
|
+
const dbType = queryRunner.connection.driver.options.type;
|
|
718
|
+
if (dbType === "postgres") {
|
|
719
|
+
debug("using postgres migration file");
|
|
720
|
+
const mig = new CreateMnemonics1659566636105();
|
|
721
|
+
const down = await mig.down(queryRunner);
|
|
722
|
+
debug("Migration statements executed");
|
|
723
|
+
return down;
|
|
724
|
+
} else if (dbType === "sqlite" || "react-native") {
|
|
725
|
+
debug("using sqlite/react-native migration file");
|
|
726
|
+
const mig = new CreateMnemonics1659566622817();
|
|
727
|
+
const down = await mig.down(queryRunner);
|
|
728
|
+
debug("Migration statements executed");
|
|
729
|
+
return down;
|
|
730
|
+
} else {
|
|
731
|
+
return Promise.reject("Migrations are currently only supported for sqlite, react-native and postgres. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now");
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
};
|
|
735
|
+
|
|
736
|
+
// src/migrations/generic/index.ts
|
|
737
|
+
var MnemonicSeedManagerMigrations = [
|
|
738
|
+
CreateMnemonics1659567079429
|
|
739
|
+
];
|
|
740
|
+
|
|
741
|
+
// src/index.ts
|
|
742
|
+
var schema = require_plugin_schema();
|
|
743
|
+
var MnemonicSeedManagerEntities = [
|
|
744
|
+
MnemonicEntity
|
|
745
|
+
];
|
|
746
|
+
//# sourceMappingURL=index.cjs.map
|