@interop/did-method-peer 0.0.0-stage → 0.1.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.
@@ -0,0 +1,647 @@
1
+ /**
2
+ * `DidPeerDriver`: the `@interop/did-io` method driver for did:peer numalgo 4.
3
+ * Generates DIDs from key pairs, a seed or a caller-supplied input document,
4
+ * resolves long forms offline and short forms through the configured
5
+ * `LongFormStore`, dereferences verification method and service nodes by DID
6
+ * URL, and performs reference resolution so the documents it returns carry
7
+ * absolute DID URLs like did:key and did:web documents do.
8
+ */
9
+ import { decodeSecretKeySeed } from '@interop/bnid';
10
+ import { contextsBySuite, deepClone, findVerificationMethod } from '@interop/did-io';
11
+ import { VerificationMethodError } from '@interop/data-integrity-core';
12
+ import { X25519KeyAgreementKey2020 } from '@interop/x25519-key-agreement-key';
13
+ import { DEFAULT_PURPOSES, DID_CONTEXT_URL, DID_PEER_PREFIX } from './constants.js';
14
+ import { addThirdPartyMethod, addVerificationMethod, validateInputDocument } from './inputDocument.js';
15
+ import { encodeLongForm, isLongForm, isShortForm, longToShort, resolutionError, resolveLongForm, resolveShortForm } from './numalgo4.js';
16
+ import { METHOD_PROPERTIES, RESOURCE_PROPERTIES, findResource, isPlainObject } from './resources.js';
17
+ const ED25519_MULTIKEY_HEADER = 'z6Mk';
18
+ const X25519_MULTIKEY_HEADER = 'z6LS';
19
+ const X25519_TYPES = new Set([
20
+ 'X25519KeyAgreementKey2019',
21
+ 'X25519KeyAgreementKey2020'
22
+ ]);
23
+ function isLiveEntry(entry) {
24
+ return isPlainObject(entry) && 'keyPair' in entry;
25
+ }
26
+ function isThirdPartyEntry(entry) {
27
+ return isPlainObject(entry) && 'method' in entry && 'purposes' in entry;
28
+ }
29
+ /**
30
+ * Rewrites a contextualized document's relative ids and relationship
31
+ * references to absolute DID URLs against `did` (DID Core's relative DID URL
32
+ * rule). Touches the `id` of object entries in `verificationMethod`, the five
33
+ * relationships and `service`, and string entries in the five relationships.
34
+ * Already-absolute values are left alone. Mutates in place; callers pass the
35
+ * fresh copy the codec returned.
36
+ */
37
+ function resolveReferences({ didDocument, did }) {
38
+ const doc = didDocument;
39
+ const absolute = (value) => typeof value === 'string' && value.startsWith('#')
40
+ ? `${did}${value}`
41
+ : value;
42
+ for (const property of RESOURCE_PROPERTIES) {
43
+ const entries = doc[property];
44
+ if (!Array.isArray(entries)) {
45
+ continue;
46
+ }
47
+ for (let index = 0; index < entries.length; index++) {
48
+ const entry = entries[index];
49
+ if (isPlainObject(entry)) {
50
+ entry.id = absolute(entry.id);
51
+ }
52
+ else if (property !== 'verificationMethod' && property !== 'service') {
53
+ entries[index] = absolute(entry);
54
+ }
55
+ }
56
+ }
57
+ return didDocument;
58
+ }
59
+ /**
60
+ * Decodes a secret key seed: a bnid multibase/multihash string (`z1A...`) or
61
+ * a `Uint8Array` of exactly 32 bytes.
62
+ */
63
+ function decodeSeed(seed) {
64
+ if (typeof seed === 'string') {
65
+ if (!seed.startsWith('z1A')) {
66
+ throw new TypeError('"seed" parameter must be a multibase/multihash encoded string, or a ' +
67
+ 'Uint8Array.');
68
+ }
69
+ return decodeSecretKeySeed({ secretKeySeed: seed });
70
+ }
71
+ if (!(seed instanceof Uint8Array) || seed.length !== 32) {
72
+ throw new TypeError('"seed" must be a Uint8Array of exactly 32 bytes.');
73
+ }
74
+ return new Uint8Array(seed);
75
+ }
76
+ export class DidPeerDriver {
77
+ method;
78
+ longFormStore;
79
+ rememberOnResolve;
80
+ _allowedKeyTypes;
81
+ /**
82
+ * @param options {object}
83
+ * @param [options.longFormStore] {LongFormStore} - Where long forms are
84
+ * remembered so short forms resolve. A `Map` works for in-memory use.
85
+ * Without one, every short form is `notFound`.
86
+ * @param [options.rememberOnResolve=true] {boolean} - Whether a successful
87
+ * long form `get()` writes the store. `generate()` always writes.
88
+ */
89
+ constructor({ longFormStore, rememberOnResolve = true } = {}) {
90
+ this.method = 'peer';
91
+ this.longFormStore = longFormStore;
92
+ this.rememberOnResolve = rememberOnResolve;
93
+ this._allowedKeyTypes = new Map();
94
+ }
95
+ /**
96
+ * Registers a key suite for generation and key rebuilding.
97
+ *
98
+ * Preferred form: pass a `keyPairClass` exposing static `multibaseHeader`,
99
+ * `from` and (optionally) `generate`. Lower-level form: pass
100
+ * `multibaseMultikeyHeader` plus a `fromMultibase` deserializer; suites
101
+ * registered this way cannot `generate()`.
102
+ *
103
+ * @param options {object}
104
+ * @param [options.keyPairClass] {KeyPairClass}
105
+ * @param [options.multibaseMultikeyHeader] {string}
106
+ * @param [options.fromMultibase] {FromMultibase}
107
+ * @param [options.enableEncryptionKeyDerivation=false] {boolean} - When
108
+ * `true`, generating with this (Ed25519) suite also derives an X25519
109
+ * `keyAgreement` key from the verification key. Off by default, since
110
+ * reusing one key for signing and key agreement is a posture choice.
111
+ */
112
+ use({ keyPairClass, multibaseMultikeyHeader, fromMultibase, enableEncryptionKeyDerivation = false } = {}) {
113
+ if (keyPairClass) {
114
+ const header = keyPairClass.multibaseHeader;
115
+ if (!(header && typeof header === 'string')) {
116
+ throw new TypeError('"keyPairClass.multibaseHeader" must be a string.');
117
+ }
118
+ if (typeof keyPairClass.from !== 'function') {
119
+ throw new TypeError('"keyPairClass.from" must be a function.');
120
+ }
121
+ this._allowedKeyTypes.set(header, {
122
+ fromMultibase: keyPairClass.from.bind(keyPairClass),
123
+ generate: typeof keyPairClass.generate === 'function'
124
+ ? keyPairClass.generate.bind(keyPairClass)
125
+ : undefined,
126
+ enableEncryptionKeyDerivation
127
+ });
128
+ return;
129
+ }
130
+ if (!multibaseMultikeyHeader ||
131
+ typeof multibaseMultikeyHeader !== 'string') {
132
+ throw new TypeError('"multibaseMultikeyHeader" must be a string.');
133
+ }
134
+ if (typeof fromMultibase !== 'function') {
135
+ throw new TypeError('"fromMultibase" must be a function.');
136
+ }
137
+ this._allowedKeyTypes.set(multibaseMultikeyHeader, {
138
+ fromMultibase,
139
+ enableEncryptionKeyDerivation
140
+ });
141
+ }
142
+ /**
143
+ * Generates a did:peer numalgo 4 DID. Three mutually exclusive entry paths:
144
+ *
145
+ * 1. `inputDocument`: validated, encoded and resolved as given. `keyPairs`
146
+ * (keyed by bare fragment) binds live pairs to the document's methods;
147
+ * a fragment with no method, or a public key that differs, is a
148
+ * `TypeError`.
149
+ * 2. `seed`: one key pair is derived with the selected or sole registered
150
+ * suite, then as path 3.
151
+ * 3. Explicit or random key pairs: `verificationKeyPair` (or a fresh random
152
+ * pair) gets the four default purposes; `keyAgreementKeyPair` gets
153
+ * `keyAgreement`, or an X25519 key is derived when the suite was
154
+ * registered with `enableEncryptionKeyDerivation`; `verificationMethods`
155
+ * entries (`{ keyPair, fragment?, purposes? }`, `{ method, purposes }`
156
+ * for a third-party method with explicit purposes, or a bare third-party
157
+ * reference / method object with the default four) are added in order;
158
+ * `service` is copied.
159
+ *
160
+ * Every path binds the live pairs (`controller` and `id` set to the long
161
+ * form), writes the long form store when one is configured, and returns the
162
+ * did-io generation result. `didDocument.id` is the long form.
163
+ *
164
+ * @param [options] {GenerateOptions}
165
+ *
166
+ * @returns {Promise<DidGenerationResult>}
167
+ */
168
+ async generate(options = {}) {
169
+ return this._generate(options, { remember: true });
170
+ }
171
+ async _generate({ inputDocument, keyPairs, seed, keyType, verificationKeyPair, keyAgreementKeyPair, verificationMethods, service }, { remember }) {
172
+ if (keyPairs && !inputDocument) {
173
+ throw new TypeError('"keyPairs" requires an "inputDocument".');
174
+ }
175
+ if (inputDocument &&
176
+ (seed !== undefined ||
177
+ keyType !== undefined ||
178
+ verificationKeyPair ||
179
+ keyAgreementKeyPair ||
180
+ verificationMethods ||
181
+ service)) {
182
+ throw new TypeError('"inputDocument" cannot be combined with "seed", "keyType", ' +
183
+ '"verificationKeyPair", "keyAgreementKeyPair", ' +
184
+ '"verificationMethods" or "service".');
185
+ }
186
+ if (seed !== undefined && verificationKeyPair) {
187
+ throw new TypeError('"seed" and "verificationKeyPair" are two sources for one key; pass one.');
188
+ }
189
+ if (keyType !== undefined && verificationKeyPair) {
190
+ throw new TypeError('"keyType" has no effect with an explicit "verificationKeyPair".');
191
+ }
192
+ // Live pairs to bind after the long form is known, by bare fragment.
193
+ const livePairs = new Map();
194
+ let document;
195
+ if (inputDocument) {
196
+ document = inputDocument;
197
+ validateInputDocument({ inputDocument: document });
198
+ for (const [fragment, pair] of keyPairs ?? []) {
199
+ await this._assertPairMatchesMethod({
200
+ inputDocument: document,
201
+ fragment,
202
+ pair
203
+ });
204
+ livePairs.set(fragment, pair);
205
+ }
206
+ }
207
+ else {
208
+ document = { '@context': [DID_CONTEXT_URL] };
209
+ let verificationPair;
210
+ if (seed !== undefined) {
211
+ verificationPair = await this._generateKeyPair({ seed, keyType });
212
+ }
213
+ else if (verificationKeyPair) {
214
+ verificationPair = await this._toKeyPair(verificationKeyPair);
215
+ }
216
+ else if (!verificationMethods && !keyAgreementKeyPair) {
217
+ verificationPair = await this._generateKeyPair({ keyType });
218
+ }
219
+ if (verificationPair) {
220
+ const { fragment } = await addVerificationMethod({
221
+ inputDocument: document,
222
+ keyPair: verificationPair,
223
+ purposes: DEFAULT_PURPOSES
224
+ });
225
+ livePairs.set(fragment, verificationPair);
226
+ }
227
+ let agreementPair;
228
+ if (keyAgreementKeyPair) {
229
+ agreementPair = await this._toKeyPair(keyAgreementKeyPair);
230
+ }
231
+ else if (verificationPair) {
232
+ agreementPair = this._deriveKeyAgreementKey(verificationPair);
233
+ }
234
+ if (agreementPair) {
235
+ const { fragment } = await addVerificationMethod({
236
+ inputDocument: document,
237
+ keyPair: agreementPair,
238
+ purposes: ['keyAgreement']
239
+ });
240
+ livePairs.set(fragment, agreementPair);
241
+ }
242
+ for (const entry of verificationMethods ?? []) {
243
+ if (isLiveEntry(entry)) {
244
+ const pair = await this._toKeyPair(entry.keyPair);
245
+ const { fragment } = await addVerificationMethod({
246
+ inputDocument: document,
247
+ keyPair: pair,
248
+ fragment: entry.fragment,
249
+ purposes: entry.purposes ?? DEFAULT_PURPOSES
250
+ });
251
+ livePairs.set(fragment, pair);
252
+ }
253
+ else if (isThirdPartyEntry(entry)) {
254
+ addThirdPartyMethod({
255
+ inputDocument: document,
256
+ entry: entry.method,
257
+ purposes: entry.purposes
258
+ });
259
+ }
260
+ else {
261
+ addThirdPartyMethod({
262
+ inputDocument: document,
263
+ entry,
264
+ purposes: DEFAULT_PURPOSES
265
+ });
266
+ }
267
+ }
268
+ if (service) {
269
+ document.service = deepClone(service);
270
+ }
271
+ validateInputDocument({ inputDocument: document });
272
+ }
273
+ const longForm = encodeLongForm({ inputDocument: document });
274
+ const shortForm = longToShort({ did: longForm });
275
+ const didDocument = resolveReferences({
276
+ didDocument: resolveLongForm({ did: longForm }),
277
+ did: longForm
278
+ });
279
+ const boundPairs = new Map();
280
+ for (const [fragment, pair] of livePairs) {
281
+ pair.controller = longForm;
282
+ pair.id = `${longForm}#${fragment}`;
283
+ boundPairs.set(pair.id, pair);
284
+ }
285
+ if (remember && this.longFormStore) {
286
+ try {
287
+ await this.longFormStore.set(shortForm, longForm);
288
+ }
289
+ catch (cause) {
290
+ throw new Error(`Failed to write the long form store for "${shortForm}".`, { cause });
291
+ }
292
+ }
293
+ const methodFor = ({ purpose }) => {
294
+ const { id } = this.publicMethodFor({ didDocument, purpose });
295
+ const pair = id === undefined ? undefined : boundPairs.get(id);
296
+ if (!pair) {
297
+ throw new Error(`No key pair available for verification method "${id}" (purpose "${purpose}").`);
298
+ }
299
+ return pair;
300
+ };
301
+ return { didDocument, keyPairs: boundPairs, methodFor };
302
+ }
303
+ /**
304
+ * Generates a did:peer DID from existing key pairs (live instances or plain
305
+ * public key descriptions, rebuilt through the registered suites). With only
306
+ * `keyAgreementKeyPair`, no signing key is generated.
307
+ *
308
+ * @param options {object}
309
+ * @param [options.verificationKeyPair] {AbstractKeyPair | IKeyPair}
310
+ * @param [options.keyAgreementKeyPair] {AbstractKeyPair | IKeyPair}
311
+ *
312
+ * @returns {Promise<DidGenerationResult>}
313
+ */
314
+ async fromKeyPair({ verificationKeyPair, keyAgreementKeyPair } = {}) {
315
+ if (!(verificationKeyPair || keyAgreementKeyPair)) {
316
+ throw new TypeError('"verificationKeyPair" or "keyAgreementKeyPair" must be provided.');
317
+ }
318
+ return this.generate({ verificationKeyPair, keyAgreementKeyPair });
319
+ }
320
+ /**
321
+ * Converts a public key description to a did:peer DID document. An X25519
322
+ * description becomes the `keyAgreement` key, anything else the
323
+ * verification key. Unlike `generate()`, no `keyPairs` map is returned and
324
+ * the long form store is not written.
325
+ *
326
+ * @param options {object}
327
+ * @param options.publicKeyDescription {AbstractKeyPair | IKeyPair | IPublicKey}
328
+ *
329
+ * @returns {Promise<{didDocument: IDIDDocument}>}
330
+ */
331
+ async publicKeyToDidDoc({ publicKeyDescription } = {}) {
332
+ if (!publicKeyDescription) {
333
+ throw new TypeError('"publicKeyDescription" is required.');
334
+ }
335
+ const keyPair = await this._toKeyPair(publicKeyDescription);
336
+ const isKeyAgreement = X25519_TYPES.has(keyPair.type ?? '') ||
337
+ keyPair.publicKeyMultibase?.startsWith(X25519_MULTIKEY_HEADER) === true;
338
+ const { didDocument } = await this._generate(isKeyAgreement
339
+ ? { keyAgreementKeyPair: keyPair }
340
+ : { verificationKeyPair: keyPair }, { remember: false });
341
+ return { didDocument };
342
+ }
343
+ /**
344
+ * Resolves a did:peer numalgo 4 DID or DID URL. A long form resolves
345
+ * offline; a short form resolves through the long form store. A `#fragment`
346
+ * returns the verification method or service node with that id, cloned,
347
+ * with an `@context`. A `?query` or `/path` is stripped and the authority
348
+ * resolved.
349
+ *
350
+ * @param options {object}
351
+ * @param [options.did] {string}
352
+ * @param [options.url] {string} - Alias for `did`.
353
+ *
354
+ * @throws {DIDResolutionError} `methodNotSupported` for a non-did:peer DID
355
+ * or another numalgo; `invalidDid` for a malformed or tampered DID;
356
+ * `invalidDidUrl` for more than one `#`; `notFound` for a short form whose
357
+ * long form has not been seen; `internalError` for a store failure.
358
+ * @throws {VerificationMethodError} `notFound` for an unknown fragment.
359
+ *
360
+ * @returns {Promise<IDIDDocument | IPublicKey>}
361
+ */
362
+ async get({ did, url } = {}) {
363
+ did = did ?? url;
364
+ if (typeof did !== 'string' || did.length === 0) {
365
+ throw new TypeError('A string "did" or "url" parameter is required.');
366
+ }
367
+ if (did.indexOf('#') !== did.lastIndexOf('#')) {
368
+ throw resolutionError({
369
+ code: 'invalidDidUrl',
370
+ message: `DID URL "${did}" has more than one "#".`
371
+ });
372
+ }
373
+ const hashIndex = did.indexOf('#');
374
+ const beforeHash = hashIndex === -1 ? did : did.slice(0, hashIndex);
375
+ const fragment = hashIndex === -1 ? '' : did.slice(hashIndex + 1);
376
+ const authority = beforeHash.split(/[?/]/)[0] ?? '';
377
+ if (!authority.startsWith(DID_PEER_PREFIX)) {
378
+ throw resolutionError({
379
+ code: 'methodNotSupported',
380
+ message: `DID method not supported: "${authority}".`
381
+ });
382
+ }
383
+ const numalgo = authority.charAt(DID_PEER_PREFIX.length);
384
+ if (!/^[0-9]$/.test(numalgo)) {
385
+ throw resolutionError({
386
+ code: 'invalidDid',
387
+ message: `Malformed did:peer DID (no numalgo digit): "${authority}".`
388
+ });
389
+ }
390
+ if (numalgo !== '4') {
391
+ throw resolutionError({
392
+ code: 'methodNotSupported',
393
+ message: `did:peer numalgo ${numalgo} is not supported; only numalgo 4 is.`
394
+ });
395
+ }
396
+ let didDocument;
397
+ if (isLongForm(authority)) {
398
+ didDocument = resolveLongForm({ did: authority });
399
+ if (this.longFormStore && this.rememberOnResolve) {
400
+ try {
401
+ await this.longFormStore.set(longToShort({ did: authority }), authority);
402
+ }
403
+ catch (cause) {
404
+ throw resolutionError({
405
+ code: 'internalError',
406
+ message: `Failed to write the long form store for "${authority}".`,
407
+ cause
408
+ });
409
+ }
410
+ }
411
+ }
412
+ else if (isShortForm(authority)) {
413
+ didDocument = await this._resolveShortForm(authority);
414
+ }
415
+ else {
416
+ throw resolutionError({
417
+ code: 'invalidDid',
418
+ message: `Malformed did:peer numalgo 4 DID: "${authority}".`
419
+ });
420
+ }
421
+ resolveReferences({ didDocument, did: authority });
422
+ if (!fragment) {
423
+ return didDocument;
424
+ }
425
+ const id = `${authority}#${fragment}`;
426
+ // The legacy `publicKey` array is not searched.
427
+ const node = findResource({
428
+ document: didDocument,
429
+ id
430
+ });
431
+ if (!node) {
432
+ throw new VerificationMethodError(`DID document entity with id "${id}" not found.`, { code: 'notFound', verificationMethod: id });
433
+ }
434
+ const context = (typeof node.type === 'string'
435
+ ? contextsBySuite.get(node.type)
436
+ : undefined) ?? deepClone(didDocument['@context']);
437
+ const result = deepClone(node);
438
+ result.id = id;
439
+ return (context === undefined ? result : { '@context': context, ...result });
440
+ }
441
+ /**
442
+ * Returns the public verification method for a purpose from a DID document
443
+ * returned by this driver (whose references are absolute), without
444
+ * `@context`.
445
+ *
446
+ * @param options {object}
447
+ * @param options.didDocument {IDIDDocument}
448
+ * @param options.purpose {string}
449
+ *
450
+ * @returns {IPublicKey}
451
+ */
452
+ publicMethodFor({ didDocument, purpose } = {}) {
453
+ if (!didDocument) {
454
+ throw new TypeError('The "didDocument" parameter is required.');
455
+ }
456
+ if (!purpose) {
457
+ throw new TypeError('The "purpose" parameter is required.');
458
+ }
459
+ const method = findVerificationMethod({ doc: didDocument, purpose });
460
+ if (!method) {
461
+ throw new Error(`No verification method found for purpose "${purpose}"`);
462
+ }
463
+ return method;
464
+ }
465
+ /**
466
+ * Resolves a short form through the long form store: a missing store or a
467
+ * value that is not a non-empty string is `notFound`; a store that throws,
468
+ * or returns a string that is not a long form, is `internalError`; a stored
469
+ * long form whose own short form differs from the requested one is
470
+ * `invalidDid`. Does not write.
471
+ */
472
+ async _resolveShortForm(shortForm) {
473
+ const notFound = () => {
474
+ throw resolutionError({
475
+ code: 'notFound',
476
+ message: `Long form for "${shortForm}" has not been seen; a short form resolves only after its long form.`
477
+ });
478
+ };
479
+ if (!this.longFormStore) {
480
+ return notFound();
481
+ }
482
+ let stored;
483
+ try {
484
+ stored = await this.longFormStore.get(shortForm);
485
+ }
486
+ catch (cause) {
487
+ throw resolutionError({
488
+ code: 'internalError',
489
+ message: `Long form store lookup failed for "${shortForm}".`,
490
+ cause
491
+ });
492
+ }
493
+ if (typeof stored !== 'string' || stored.length === 0) {
494
+ return notFound();
495
+ }
496
+ if (!isLongForm(stored)) {
497
+ throw resolutionError({
498
+ code: 'internalError',
499
+ message: `Long form store returned a value for "${shortForm}" that is not a did:peer numalgo 4 long form.`
500
+ });
501
+ }
502
+ if (longToShort({ did: stored }) !== shortForm) {
503
+ throw resolutionError({
504
+ code: 'invalidDid',
505
+ message: `Stored long form for "${shortForm}" belongs to a different DID.`
506
+ });
507
+ }
508
+ return resolveShortForm({ longFormDid: stored });
509
+ }
510
+ /**
511
+ * Checks that a live pair's public key equals the input document's method
512
+ * `#${fragment}` before the pair is bound to it. A method carrying
513
+ * `publicKeyMultibase` is compared directly. Any other serialization (a 2018
514
+ * suite's `publicKeyBase58`, a JSON Web Key's `publicKeyJwk`) is rebuilt
515
+ * through the pair's own registered suite and compared by fingerprint, so
516
+ * the suite decides which serializations it can read.
517
+ */
518
+ async _assertPairMatchesMethod({ inputDocument, fragment, pair }) {
519
+ const id = `#${fragment}`;
520
+ const method = findResource({
521
+ document: inputDocument,
522
+ id,
523
+ properties: METHOD_PROPERTIES
524
+ });
525
+ if (!method) {
526
+ throw new TypeError(`"keyPairs" names fragment "${fragment}" but the input document has no method with id "${id}".`);
527
+ }
528
+ const mismatch = (cause) => new TypeError(`"keyPairs" pair for fragment "${fragment}" does not match the public key of method "${id}".`, { cause });
529
+ const pairMultibase = this._publicKeyMultibaseOf(pair);
530
+ if (typeof method.publicKeyMultibase === 'string') {
531
+ if (method.publicKeyMultibase !== pairMultibase) {
532
+ throw mismatch();
533
+ }
534
+ return;
535
+ }
536
+ const registered = this._allowedKeyTypes.get(pairMultibase.slice(0, 4));
537
+ if (!registered) {
538
+ throw new Error(`Cannot compare method "${id}" with the pair for fragment "${fragment}": no key suite is registered for header "${pairMultibase.slice(0, 4)}".`);
539
+ }
540
+ let rebuilt;
541
+ try {
542
+ rebuilt = await registered.fromMultibase(method);
543
+ }
544
+ catch (cause) {
545
+ throw mismatch(cause);
546
+ }
547
+ if (this._publicKeyMultibaseOf(rebuilt) !== pairMultibase) {
548
+ throw mismatch();
549
+ }
550
+ }
551
+ /**
552
+ * Returns a live pair's public key as a multibase Multikey string: its
553
+ * `publicKeyMultibase`, or its `fingerprint()` for a suite that serializes
554
+ * the public key another way.
555
+ */
556
+ _publicKeyMultibaseOf(pair) {
557
+ const live = pair;
558
+ if (typeof live.publicKeyMultibase === 'string') {
559
+ return live.publicKeyMultibase;
560
+ }
561
+ if (typeof pair.fingerprint === 'function') {
562
+ return pair.fingerprint();
563
+ }
564
+ throw new TypeError('A "keyPairs" pair must expose "publicKeyMultibase" or "fingerprint()".');
565
+ }
566
+ /**
567
+ * Derives an X25519 key agreement pair from a live Ed25519 pair when its
568
+ * suite was registered with `enableEncryptionKeyDerivation`; otherwise
569
+ * returns `undefined`.
570
+ */
571
+ _deriveKeyAgreementKey(verificationPair) {
572
+ const live = verificationPair;
573
+ const publicKeyMultibase = live.publicKeyMultibase;
574
+ if (!publicKeyMultibase?.startsWith(ED25519_MULTIKEY_HEADER)) {
575
+ return undefined;
576
+ }
577
+ const registered = this._allowedKeyTypes.get(publicKeyMultibase.slice(0, 4));
578
+ if (!registered?.enableEncryptionKeyDerivation) {
579
+ return undefined;
580
+ }
581
+ return X25519KeyAgreementKey2020.fromEd25519({
582
+ controller: live.controller,
583
+ publicKeyMultibase,
584
+ privateKeyMultibase: live.privateKeyMultibase
585
+ });
586
+ }
587
+ /**
588
+ * Generates a key pair from the selected or sole registered suite.
589
+ */
590
+ async _generateKeyPair({ seed, keyType } = {}) {
591
+ let header;
592
+ if (keyType) {
593
+ header = typeof keyType === 'string' ? keyType : keyType.multibaseHeader;
594
+ }
595
+ else if (this._allowedKeyTypes.size === 1) {
596
+ ;
597
+ [header] = this._allowedKeyTypes.keys();
598
+ }
599
+ else if (this._allowedKeyTypes.size === 0) {
600
+ throw new Error('No key suite registered; call "use({keyPairClass})" or pass a ' +
601
+ '"verificationKeyPair".');
602
+ }
603
+ else {
604
+ throw new Error('Multiple key suites registered; specify which via "keyType" or pass ' +
605
+ 'a "verificationKeyPair".');
606
+ }
607
+ const registered = this._allowedKeyTypes.get(header);
608
+ if (!registered?.generate) {
609
+ throw new Error(`Registered suite "${header}" cannot generate keys; register it via ` +
610
+ '"use({keyPairClass})".');
611
+ }
612
+ const seedBytes = seed === undefined ? undefined : decodeSeed(seed);
613
+ return registered.generate({ seed: seedBytes });
614
+ }
615
+ /**
616
+ * Returns a live key pair for a live instance or a plain public key
617
+ * description (rebuilt through the registered suite for its header).
618
+ */
619
+ async _toKeyPair(description) {
620
+ const candidate = description;
621
+ if (typeof candidate?.export === 'function') {
622
+ return description;
623
+ }
624
+ const publicKeyMultibase = candidate?.publicKeyMultibase;
625
+ if (typeof publicKeyMultibase !== 'string' || !publicKeyMultibase) {
626
+ throw new TypeError('"publicKeyMultibase" is required to rebuild a key pair.');
627
+ }
628
+ const header = publicKeyMultibase.slice(0, 4);
629
+ const registered = this._allowedKeyTypes.get(header);
630
+ if (!registered) {
631
+ throw new Error(`Unsupported multibase header "${header}". Register the suite via ` +
632
+ '"use()".');
633
+ }
634
+ return registered.fromMultibase({ publicKeyMultibase });
635
+ }
636
+ }
637
+ /**
638
+ * Factory matching the `.driver()` API of the other did-io drivers.
639
+ *
640
+ * @param [options] {DidPeerDriverOptions}
641
+ *
642
+ * @returns {DidPeerDriver}
643
+ */
644
+ export function driver(options = {}) {
645
+ return new DidPeerDriver(options);
646
+ }
647
+ //# sourceMappingURL=DidPeerDriver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DidPeerDriver.js","sourceRoot":"","sources":["../src/DidPeerDriver.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AACnD,OAAO,EACL,eAAe,EACf,SAAS,EACT,sBAAsB,EACv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