@estoc/didcomm 0.4.1-estoc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts ADDED
@@ -0,0 +1,950 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Allow fine configuration of packing process.
6
+ */
7
+ type PackEncryptedOptions = {
8
+ /**
9
+ * If `true` and message is authenticated than information about sender will be protected from mediators, but
10
+ * additional re-encryption will be required. For anonymous messages this property will be ignored.
11
+ * Default false.
12
+ */
13
+ protect_sender?: boolean,
14
+
15
+ /**
16
+ * Whether the encrypted messages need to be wrapped into `Forward` messages to be sent to Mediators
17
+ * as defined by the `Forward` protocol.
18
+ * Default true.
19
+ */
20
+ forward?: boolean,
21
+
22
+ /**
23
+ * if forward is enabled these optional headers can be passed to the wrapping `Forward` messages.
24
+ * If forward is disabled this property will be ignored.
25
+ */
26
+ forward_headers?: Array<[string, string]>,
27
+
28
+ /**
29
+ * Identifier (DID URL) of messaging service (https://identity.foundation/didcomm-messaging/spec/#did-document-service-endpoint).
30
+ * If DID contains multiple messaging services it allows specify what service to use.
31
+ * If not present first service will be used.
32
+ */
33
+ messaging_service?: string,
34
+
35
+ /**
36
+ * Algorithm used for authenticated encryption.
37
+ * Default "A256cbcHs512Ecdh1puA256kw"
38
+ */
39
+ enc_alg_auth?: "A256cbcHs512Ecdh1puA256kw",
40
+
41
+ /**
42
+ * Algorithm used for anonymous encryption.
43
+ * Default "Xc20pEcdhEsA256kw"
44
+ */
45
+ enc_alg_anon?: "A256cbcHs512EcdhEsA256kw" | "Xc20pEcdhEsA256kw" | "A256gcmEcdhEsA256kw",
46
+ }
47
+
48
+
49
+
50
+ /**
51
+ * Allows fine customization of unpacking process
52
+ */
53
+ type UnpackOptions = {
54
+ /**
55
+ * Whether the plaintext must be decryptable by all keys resolved by the secrets resolver.
56
+ * False by default.
57
+ */
58
+ expect_decrypt_by_all_keys?: boolean,
59
+
60
+ /**
61
+ * If `true` and the packed message is a `Forward`
62
+ * wrapping a plaintext packed for the given recipient, then both Forward and packed plaintext are unpacked automatically,
63
+ * and the unpacked plaintext will be returned instead of unpacked Forward.
64
+ * False by default.
65
+ */
66
+ unwrap_re_wrapping_forward?: boolean,
67
+
68
+ /**
69
+ * Whether the `from_prior` header must be verified during unpack.
70
+ * If `false`, the raw `from_prior` JWT stays in the returned message for separate verification:
71
+ * its issuer DID is not resolved, and `from_prior` and `from_prior_issuer_kid` in metadata stay unset.
72
+ * True by default.
73
+ */
74
+ verify_from_prior?: boolean,
75
+ }
76
+
77
+
78
+
79
+ /**
80
+ * Additional metadata about this `encrypt` method execution like used keys identifiers,
81
+ * used messaging service.
82
+ */
83
+ type PackEncryptedMetadata = {
84
+ /**
85
+ * Information about messaging service used for message preparation.
86
+ * Practically `service_endpoint` field can be used to transport the message.
87
+ */
88
+ messaging_service?: MessagingServiceMetadata,
89
+
90
+ /**
91
+ * Identifier (DID URL) of sender key used for message encryption.
92
+ */
93
+ from_kid?: string,
94
+
95
+ /**
96
+ * Identifier (DID URL) of sender key used for message sign.
97
+ */
98
+ sign_by_kid?: string,
99
+
100
+ /**
101
+ * Identifiers (DID URLs) of recipient keys used for message encryption.
102
+ */
103
+ to_kids: Array<string>,
104
+ }
105
+
106
+
107
+
108
+ /**
109
+ * Additional metadata about this `pack` method execution like used key identifiers.
110
+ */
111
+ type PackSignedMetadata = {
112
+ /**
113
+ * Identifier (DID URL) of sign key.
114
+ */
115
+ sign_by_kid: String,
116
+ }
117
+
118
+
119
+
120
+ /**
121
+ * Additional metadata about this `unpack` method execution like trust predicates
122
+ * and used keys identifiers.
123
+ */
124
+ type UnpackMetadata = {
125
+ /**
126
+ * Whether the plaintext has been encrypted.
127
+ */
128
+ encrypted: boolean,
129
+
130
+ /**
131
+ * Whether the plaintext has been authenticated.
132
+ */
133
+ authenticated: boolean,
134
+
135
+ /**
136
+ * Whether the plaintext has been signed.
137
+ */
138
+ non_repudiation: boolean,
139
+
140
+ /**
141
+ * Whether the sender ID was hidden or protected.
142
+ */
143
+ anonymous_sender: boolean,
144
+
145
+ /**
146
+ * Whether the plaintext was re-wrapped in a forward message by a mediator.
147
+ */
148
+ re_wrapped_in_forward: boolean,
149
+
150
+ /**
151
+ * Key ID of the sender used for authentication encryption
152
+ * if the plaintext has been authenticated and encrypted.
153
+ */
154
+ encrypted_from_kid?: string,
155
+
156
+ /**
157
+ * Target key IDS for encryption if the plaintext has been encrypted.
158
+ */
159
+ encrypted_to_kids?: Array<string>,
160
+
161
+ /**
162
+ * Key ID used for signature if the plaintext has been signed.
163
+ */
164
+ sign_from: string,
165
+
166
+ /**
167
+ * Key ID used for from_prior header signature if from_prior header is present
168
+ */
169
+ from_prior_issuer_kid?: string,
170
+
171
+ /**
172
+ * Algorithm used for authenticated encryption.
173
+ * Default "A256cbcHs512Ecdh1puA256kw"
174
+ */
175
+ enc_alg_auth?: "A256cbcHs512Ecdh1puA256kw",
176
+
177
+ /**
178
+ * Algorithm used for anonymous encryption.
179
+ * Default "Xc20pEcdhEsA256kw"
180
+ */
181
+ enc_alg_anon?: "A256cbcHs512EcdhEsA256kw" | "Xc20pEcdhEsA256kw" | "A256gcmEcdhEsA256kw",
182
+
183
+ /**
184
+ * Algorithm used for message signing.
185
+ */
186
+ sign_alg?: "EdDSA" | "ES256" | "ES256K",
187
+
188
+ /**
189
+ * If the plaintext has been signed, the JWS is returned for non-repudiation purposes.
190
+ */
191
+ signed_message?: string,
192
+
193
+ /**
194
+ * If plaintext contains from_prior header, its unpacked value is returned
195
+ */
196
+ from_prior?: IFromPrior,
197
+ }
198
+
199
+
200
+
201
+ /**
202
+ * Information about messaging service used for message preparation.
203
+ * Practically `service_endpoint` field can be used to transport the message.
204
+ */
205
+ type MessagingServiceMetadata = {
206
+ /**
207
+ * Identifier (DID URL) of used messaging service.
208
+ */
209
+ id: string,
210
+
211
+ /**
212
+ * Service endpoint of used messaging service.
213
+ */
214
+ service_endpoint: string,
215
+ }
216
+
217
+
218
+
219
+ /**
220
+ * Interface for secrets resolver.
221
+ * Resolves secrets such as private keys to be used for signing and encryption.
222
+ */
223
+ interface SecretsResolver {
224
+ /**
225
+ * Finds secret (usually private key) identified by the given key ID.
226
+ *
227
+ * @param `secret_id` the ID (in form of DID URL) identifying a secret
228
+ *
229
+ * @returns A secret (usually private key) or None of there is no secret for the given ID
230
+ *
231
+ * @throws DIDCommIoError - IO error in resolving process
232
+ * @throws DIDCommInvalidState - Code error or unexpected state was detected
233
+ *
234
+ * ```
235
+ * let e = Error("Unble perform io operation");
236
+ * e.name = "DIDCommIoError"
237
+ * throw e
238
+ * ```
239
+ */
240
+ get_secret(secret_id: string): Promise<Secret | null>;
241
+
242
+ /**
243
+ * Find all secrets that have one of the given IDs.
244
+ * Return secrets only for key IDs for which a secret is present.
245
+ *
246
+ * @param `secret_ids` the IDs find secrets for
247
+ *
248
+ * @returns possible empty list of all secrets that have one of the given IDs.
249
+ *
250
+ * @throws DIDCommIoError - IO error in resolving process
251
+ * @throws DIDCommInvalidState - Code error or unexpected state was detected
252
+ *
253
+ * Note to throw compatible error use code like this
254
+ *
255
+ * ```
256
+ * let e = Error("Unble perform io operation");
257
+ * e.name = "DIDCommIoError"
258
+ * throw e
259
+ * ```
260
+ */
261
+ find_secrets(secret_ids: Array<string>): Promise<Array<string>>;
262
+ }
263
+
264
+
265
+
266
+ /**
267
+ * Must have the same semantics as type ('type' field) of the corresponding method in DID Doc containing a public key.
268
+ */
269
+ type SecretType =
270
+ "JsonWebKey2020" | "X25519KeyAgreementKey2019"
271
+ | "Ed25519VerificationKey2018" | "EcdsaSecp256k1VerificationKey2019" | string
272
+
273
+
274
+
275
+ /**
276
+ * Properties for DIDCommMessagingService
277
+ * (https://identity.foundation/didcomm-messaging/spec/#did-document-service-endpoint).
278
+ */
279
+ type DIDCommMessagingService = {
280
+ uri: string,
281
+ accept?: Array<string>,
282
+ routing_keys: Array<string>,
283
+ }
284
+
285
+
286
+
287
+ /**
288
+ * Represents DID Doc resolver (https://www.w3.org/TR/did-core/#did-resolution).
289
+ */
290
+ interface DIDResolver {
291
+ /**
292
+ * Resolves a DID document by the given DID.
293
+ *
294
+ * @param `did` a DID to be resolved.
295
+ *
296
+ * @returns An instance of resolved DID DOC or null if DID is not found.
297
+ *
298
+ * @throws DIDCommMalformed - Resolved DID Doc looks malformed
299
+ * @throws DIDCommIoError - IO error in resolving process
300
+ * @throws DIDCommInvalidState - Code error or unexpected state was detected
301
+ *
302
+ * Note to throw compatible error use code like this
303
+ *
304
+ * ```
305
+ * let e = Error("Unble perform io operation");
306
+ * e.name = "DIDCommIoError"
307
+ * throw e
308
+ * ```
309
+ */
310
+ resolve(did: string): Promise<DIDDoc | null>;
311
+ }
312
+
313
+
314
+
315
+ /**
316
+ * Represents DID Document (https://www.w3.org/TR/did-core/)
317
+ */
318
+ type DIDDoc = {
319
+ /**
320
+ * DID for the given DID Doc
321
+ */
322
+ id: string,
323
+
324
+ /**
325
+ * DID URLs of verification methods used for key agreement.
326
+ * See https://www.w3.org/TR/did-core/#verification-methods.
327
+ */
328
+ keyAgreement: Array<string>,
329
+
330
+ /**
331
+ * Returns DID URLs of verification methods used for authentication.
332
+ * See https://www.w3.org/TR/did-core/#authentication
333
+ */
334
+ authentication: Array<string>,
335
+
336
+ /**
337
+ * All local verification methods including embedded to
338
+ * key agreement and authentication sections.
339
+ * See https://www.w3.org/TR/did-core/#verification-methods.
340
+ */
341
+ verificationMethod: Array<VerificationMethod>,
342
+
343
+ /**
344
+ * All services (https://www.w3.org/TR/did-core/#services)
345
+ */
346
+ service: Array<Service>,
347
+ }
348
+
349
+
350
+
351
+ /**
352
+ * Represents additional service properties defined for specific Service type.
353
+ */
354
+ type ServiceKind = DIDCommMessagingService | any
355
+
356
+
357
+
358
+ /**
359
+ * Represents secret.
360
+ */
361
+ type Secret = {
362
+ /**
363
+ * A key ID identifying a secret (private key).
364
+ */
365
+ id: string,
366
+
367
+ /**
368
+ * Must have the same semantics as type ('type' field) of the corresponding method in DID Doc containing a public key.
369
+ */
370
+ type: SecretType,
371
+
372
+ /**
373
+ * Possible value of the secret (private key)
374
+ */
375
+ privateKeyJwk?: any,
376
+ privateKeyMultibase?: string,
377
+ privateKeyBase58?: string,
378
+ }
379
+
380
+
381
+
382
+ /**
383
+ * Represents service record in DID Document (https://www.w3.org/TR/did-core/#services).
384
+ */
385
+ type Service = {
386
+ id: string,
387
+ type: string,
388
+ serviceEndpoint: ServiceKind,
389
+ }
390
+
391
+
392
+
393
+ /**
394
+ * Represents verification method record in DID Document
395
+ * (https://www.w3.org/TR/did-core/#verification-methods).
396
+ */
397
+ type VerificationMethod = {
398
+ id: string,
399
+ type: VerificationMethodType,
400
+ controller: string,
401
+ publicKeyJwk?: any,
402
+ publicKeyMultibase?: string,
403
+ publicKeyBase58?: string,
404
+ }
405
+
406
+
407
+
408
+ export namespace FromPrior {
409
+ /**
410
+ * Unpacks a plaintext value from a signed `from_prior` JWT.
411
+ * https://identity.foundation/didcomm-messaging/spec/#did-rotation
412
+ *
413
+ * @param from_prior_jwt signed `from_prior` JWT
414
+ * @param did_resolver instance of `DIDResolver` to resolve DIDs
415
+ *
416
+ * @returns promise resolving to a tuple of the plaintext `from_prior` value and the identifier
417
+ * of the issuer key used to sign `from_prior`
418
+ *
419
+ * @throws DIDCommMalformed Signed `from_prior` JWT is malformed.
420
+ * @throws DIDCommDIDNotResolved Issuer DID not found.
421
+ * @throws DIDCommDIDUrlNotFound Issuer authentication verification method is not found.
422
+ * @throws DIDCommUnsupported Used crypto or method is unsupported.
423
+ */
424
+ function unpack(
425
+ from_prior: string,
426
+ did_resolver: DIDResolver,
427
+ ): Promise<[FromPrior, string]>;
428
+ }
429
+
430
+
431
+
432
+ export namespace Message {
433
+ /**
434
+ * Resolves recipient DID DOC Service and Builds Forward envelops if needed.
435
+ *
436
+ * Wraps the given packed DIDComm message in Forward messages for every routing key.
437
+ *
438
+ * @param msg the message to be wrapped in Forward messages
439
+ * @param headers optional headers for Forward message
440
+ * @param to recipient's DID (DID URL)
441
+ * @param routing_keys list of routing keys
442
+ * @param enc_alg_anon The encryption algorithm to be used for anonymous encryption (anon_crypt)
443
+ * @param did_resolver instance of `DIDResolver` to resolve DIDs.
444
+ *
445
+ * @returns a top-level packed Forward message as JSON string
446
+ *
447
+ * @throws DIDCommDIDNotResolved
448
+ * @throws DIDCommDIDUrlNotFound
449
+ * @throws DIDCommIoError
450
+ * @throws DIDCommInvalidState
451
+ * @throws DIDCommIllegalArgument
452
+ */
453
+ function wrap_in_forward(
454
+ msg: string,
455
+ headers: Record<string, string>,
456
+ to: string,
457
+ routing_keys: Array<string>,
458
+ enc_alg_anon: string,
459
+ did_resolver: DIDResolver,
460
+ ): Promise<string>;
461
+ }
462
+
463
+
464
+
465
+ export namespace Message {
466
+ /**
467
+ * Unpacks the packed message by doing decryption and verifying the signatures.
468
+ * This method supports all DID Comm message types (encrypted, signed, plaintext).
469
+ *
470
+ * If unpack options expect a particular property (for example that a message is encrypted)
471
+ * and the packed message doesn't meet the criteria (it's not encrypted), then a MessageUntrusted
472
+ * error will be returned.
473
+ *
474
+ * @param `packed_msg` the message as JSON string to be unpacked
475
+ * @param `did_resolver` instance of `DIDResolver` to resolve DIDs
476
+ * @param `secrets_resolver` instance of SecretsResolver` to resolve sender DID keys secrets
477
+ * @param `options` allow fine configuration of unpacking process and imposing additional restrictions
478
+ * to message to be trusted.
479
+ *
480
+ * @returns Tuple `[message, metadata]`.
481
+ * - `message` plain message instance
482
+ * - `metadata` additional metadata about this `unpack` execution like used keys identifiers,
483
+ * trust context, algorithms and etc.
484
+ *
485
+ * @throws DIDCommDIDNotResolved
486
+ * @throws DIDCommDIDUrlNotFound
487
+ * @throws DIDCommMalformed
488
+ * @throws DIDCommIoError
489
+ * @throws DIDCommInvalidState
490
+ * @throws DIDCommNoCompatibleCrypto
491
+ * @throws DIDCommUnsupported
492
+ * @throws DIDCommIllegalArgument
493
+ */
494
+ function unpack(
495
+ msg: string,
496
+ did_resolver: DIDResolver,
497
+ secrets_resolver: SecretsResolver,
498
+ options: UnpackOptions,
499
+ ): Promise<[Message, UnpackMetadata]>;
500
+ }
501
+
502
+
503
+
504
+ interface FromPrior {
505
+ /**
506
+ * @returns FromPrior representation as plain object
507
+ */
508
+ as_value(): IFromPrior;
509
+ }
510
+
511
+
512
+
513
+ interface FromPrior {
514
+ /**
515
+ * Packs a plaintext `from_prior` value into a signed JWT.
516
+ * https://identity.foundation/didcomm-messaging/spec/#did-rotation
517
+ *
518
+ * @param issuer_kid (optional) identifier of the issuer key being used to sign `from_prior` JWT value
519
+ * @param did_resolver instance of `DIDResolver` to resolve DIDs
520
+ * @param secrets_resolver instance of `SecretsResolver` to resolve issuer DID keys secrets
521
+ *
522
+ * @returns promise resolving to a tuple of the signed `from_prior` JWT and the identifier of the issuer key
523
+ * actually used to sign `from_prior`
524
+ *
525
+ * @throws DIDCommMalformed `from_prior` plaintext value has invalid format.
526
+ * @throws DIDCommIllegalArgument `issuer_kid` is invalid or does not consist with `from_prior` plaintext value.
527
+ * @throws DIDCommDIDNotResolved Issuer DID not found.
528
+ * @throws DIDCommDIDUrlNotFound Issuer authentication verification method is not found.
529
+ * @throws DIDCommSecretNotFound Issuer secret is not found.
530
+ * @throws DIDCommUnsupported Used crypto or method is unsupported.
531
+ * @throws DIDCommInvalidState Indicates a library error.
532
+ */
533
+ pack(
534
+ issuer_kid: string | null,
535
+ did_resolver: DIDResolver,
536
+ secrets_resolver: SecretsResolver,
537
+ ): Promise<[string, string]>;
538
+ }
539
+
540
+
541
+
542
+ interface Message {
543
+ /**
544
+ * @returns message representation as plain object
545
+ */
546
+ as_value(): IMessage;
547
+ }
548
+
549
+
550
+
551
+ interface Message {
552
+ /**
553
+ * Produces `DIDComm Encrypted Message`
554
+ * https://identity.foundation/didcomm-messaging/spec/#didcomm-encrypted-message.
555
+ *
556
+ * A DIDComm encrypted message is an encrypted JWM (JSON Web Messages) and
557
+ * hides its content from all but authorized recipients, discloses (optionally) and proves
558
+ * the sender to exactly and only those recipients, and provides integrity guarantees.
559
+ * It is important in privacy-preserving routing. It is what normally moves over network
560
+ * transports in DIDComm applications, and is the safest format for storing DIDComm data at rest.
561
+ *
562
+ * Encryption is done as following:
563
+ * - Encryption is done via the keys from the `keyAgreement` verification relationship in the DID Doc
564
+ * - if `to` is a DID, then multiplex encryption is done for all keys from the
565
+ * receiver's `keyAgreement` verification relationship
566
+ * which are compatible the sender's key.
567
+ * - if `to` is a key ID, then encryption is done for the receiver's `keyAgreement`
568
+ * verification method identified by the given key ID.
569
+ * - if `from` is a DID, then sender `keyAgreement` will be negotiated based on recipient preference and
570
+ * sender-recipient crypto compatibility.
571
+ * - if `from` is a key ID, then the sender's `keyAgreement` verification method
572
+ * identified by the given key ID is used.
573
+ * - if `from` is None, then anonymous encryption is done and there will be no sender authentication property.
574
+ *
575
+ * It's possible to add non-repudiation by providing `sign_by` parameter.
576
+ *
577
+ * @param `to` recipient DID or key ID the sender uses encryption.
578
+ * @param `from` a sender DID or key ID. If set message will be repudiable authenticated or anonymous otherwise.
579
+ * Must match `from` header in Plaintext if the header is set.
580
+ * @param `sign_by` if `Some` message will be additionally signed to provide additional non-repudiable authentication
581
+ * by provided DID/Key. Signed messages are only necessary when the origin of plaintext must be provable
582
+ * to third parties, or when the sender can’t be proven to the recipient by authenticated encryption because
583
+ * the recipient is not known in advance (e.g., in a broadcast scenario).
584
+ * Adding a signature when one is not needed can degrade rather than enhance security because
585
+ * it relinquishes the sender’s ability to speak off the record.
586
+ * @param `did_resolver` instance of `DIDResolver` to resolve DIDs.
587
+ * @param `secrets_resolver` instance of SecretsResolver` to resolve sender DID keys secrets.
588
+ * @param `options` allow fine configuration of packing process.
589
+ *
590
+ * @returns Tuple `[encrypted_message, metadata]`.
591
+ * - `encrypted_message` A DIDComm encrypted message as a JSON string.
592
+ * - `metadata` additional metadata about this `pack` execution like used keys identifiers,
593
+ * used messaging service.
594
+ *
595
+ * @throws DIDCommDIDNotResolved
596
+ * @throws DIDCommDIDUrlNotFound
597
+ * @throws DIDCommMalformed
598
+ * @throws DIDCommIoError
599
+ * @throws DIDCommInvalidState
600
+ * @throws DIDCommNoCompatibleCrypto
601
+ * @throws DIDCommUnsupported
602
+ * @throws DIDCommIllegalArgument
603
+ */
604
+ pack_encrypted(
605
+ to: string,
606
+ from: string | null,
607
+ sign_by: string | null,
608
+ did_resolver: DIDResolver,
609
+ secrets_resolver: SecretsResolver,
610
+ options: PackEncryptedOptions,
611
+ ): Promise<[string, PackEncryptedMetadata]>;
612
+ }
613
+
614
+
615
+
616
+ interface Message {
617
+ /**
618
+ * Produces `DIDComm Plaintext Messages`
619
+ * https://identity.foundation/didcomm-messaging/spec/#didcomm-plaintext-messages.
620
+ *
621
+ * A DIDComm message in its plaintext form, not packaged into any protective envelope,
622
+ * is known as a DIDComm plaintext message. Plaintext messages lack confidentiality and integrity
623
+ * guarantees, and are repudiable. They are therefore not normally transported across security boundaries.
624
+ * However, this may be a helpful format to inspect in debuggers, since it exposes underlying semantics,
625
+ * and it is the format used in this spec to give examples of headers and other internals.
626
+ * Depending on ambient security, plaintext may or may not be an appropriate format for DIDComm data at rest.
627
+ *
628
+ * @param `did_resolver` instance of `DIDResolver` to resolve DIDs.
629
+ *
630
+ * @returns a DIDComm plaintext message s JSON string
631
+ *
632
+ * @throws DIDCommDIDNotResolved
633
+ * @throws DIDCommDIDUrlNotFound
634
+ * @throws DIDCommIoError
635
+ * @throws DIDCommInvalidState
636
+ * @throws DIDCommIllegalArgument
637
+ */
638
+ pack_plaintext(did_resolver: DIDResolver): Promise<string>;
639
+ }
640
+
641
+
642
+
643
+ interface Message {
644
+ /**
645
+ * Tries to parse the Message to a Forward message
646
+ *
647
+ * @returns a parsed message or null
648
+ */
649
+ try_parse_forward(): ParsedForward;
650
+ }
651
+
652
+
653
+
654
+ interface Message {
655
+ /**
656
+ * Produces `DIDComm Signed Message`
657
+ * https://identity.foundation/didcomm-messaging/spec/#didcomm-signed-message.
658
+ *
659
+ * Signed messages are not necessary to provide message integrity (tamper evidence),
660
+ * or to prove the sender to the recipient. Both of these guarantees automatically occur
661
+ * with the authenticated encryption in DIDComm encrypted messages. Signed messages are only
662
+ * necessary when the origin of plaintext must be provable to third parties,
663
+ * or when the sender can’t be proven to the recipient by authenticated encryption because
664
+ * the recipient is not known in advance (e.g., in a broadcast scenario).
665
+ * We therefore expect signed messages to be used in a few cases, but not as a matter of course.
666
+ *
667
+ * @param `sign_by` a DID or key ID the sender uses for signing
668
+ * @param `did_resolver` instance of `DIDResolver` to resolve DIDs.
669
+ * @param `secrets_resolver` instance of SecretsResolver` to resolve sender DID keys secrets
670
+ *
671
+ * @returns Tuple (signed_message, metadata)
672
+ * - `signed_message` a DIDComm signed message as JSON string
673
+ * - `metadata` additional metadata about this `encrypt` execution like used keys identifiers and algorithms.
674
+ *
675
+ * @throws DIDCommDIDNotResolved
676
+ * @throws DIDCommDIDUrlNotFound
677
+ * @throws DIDCommMalformed
678
+ * @throws DIDCommIoError
679
+ * @throws DIDCommInvalidState
680
+ * @throws DIDCommNoCompatibleCrypto
681
+ * @throws DIDCommUnsupported
682
+ * @throws DIDCommIllegalArgument
683
+ */
684
+ pack_signed(
685
+ sign_by: string,
686
+ did_resolver: DIDResolver,
687
+ secrets_resolver: SecretsResolver,
688
+ ): Promise<[string, PackSignedMetadata]>;
689
+ }
690
+
691
+
692
+
693
+ interface ParsedForward {
694
+ as_value(): IParsedForward;
695
+ }
696
+
697
+
698
+
699
+ type Attachment = {
700
+ /**
701
+ * A JSON object that gives access to the actual content of the attachment.
702
+ * Can be based on base64, json or external links.
703
+ */
704
+ data: AttachmentData,
705
+
706
+ /**
707
+ * Identifies attached content within the scope of a given message.
708
+ * Recommended on appended attachment descriptors. Possible but generally unused
709
+ * on embedded attachment descriptors. Never required if no references to the attachment
710
+ * exist; if omitted, then there is no way to refer to the attachment later in the thread,
711
+ * in error messages, and so forth. Because id is used to compose URIs, it is recommended
712
+ * that this name be brief and avoid spaces and other characters that require URI escaping.
713
+ */
714
+ id?: string,
715
+
716
+ /**
717
+ * A human-readable description of the content.
718
+ */
719
+ description?: string,
720
+
721
+ /**
722
+ * A hint about the name that might be used if this attachment is persisted as a file.
723
+ * It is not required, and need not be unique. If this field is present and mime-type is not,
724
+ * the extension on the filename may be used to infer a MIME type.
725
+ */
726
+ filename?: string,
727
+
728
+ /**
729
+ * Describes the MIME type of the attached content.
730
+ */
731
+ media_type?: string,
732
+
733
+ /**
734
+ * Describes the format of the attachment if the mime_type is not sufficient.
735
+ */
736
+ format?: string,
737
+
738
+ /**
739
+ * A hint about when the content in this attachment was last modified
740
+ * in UTC Epoch Seconds (seconds since 1970-01-01T00:00:00Z UTC).
741
+ */
742
+ lastmod_time?: number,
743
+
744
+ /**
745
+ * Mostly relevant when content is included by reference instead of by value.
746
+ * Lets the receiver guess how expensive it will be, in time, bandwidth, and storage,
747
+ * to fully fetch the attachment.
748
+ */
749
+ byte_count?: number,
750
+ }
751
+
752
+
753
+
754
+ type AttachmentData = Base64AttachmentData | JsonAttachmentData | LinksAttachmentData
755
+
756
+
757
+
758
+ type Base64AttachmentData = {
759
+ /**
760
+ * Base64-encoded data, when representing arbitrary content inline.
761
+ */
762
+ base64: string,
763
+
764
+ /**
765
+ * A JSON Web Signature over the content of the attachment.
766
+ */
767
+ jws?: string,
768
+ }
769
+
770
+
771
+
772
+ type IFromPrior = {
773
+ /**
774
+ * new DID after rotation
775
+ */
776
+ iss: string,
777
+
778
+ /**
779
+ * prior DID
780
+ */
781
+ sub: string,
782
+
783
+ /**
784
+ * Datetime of the DID rotation
785
+ */
786
+ iat?: number,
787
+ }
788
+
789
+
790
+
791
+ type IMessage = {
792
+ /**
793
+ * Message id. Must be unique to the sender.
794
+ */
795
+ id: string,
796
+
797
+ /**
798
+ * Must be "application/didcomm-plain+json"
799
+ */
800
+ typ: string,
801
+
802
+ /**
803
+ * Message type attribute value MUST be a valid Message Type URI,
804
+ * that when resolved gives human readable information about the message.
805
+ * The attribute’s value also informs the content of the message,
806
+ * or example the presence of other attributes and how they should be processed.
807
+ */
808
+ type: string,
809
+
810
+ /**
811
+ * Message body.
812
+ */
813
+ body: any,
814
+
815
+ /**
816
+ * Sender identifier. The from attribute MUST be a string that is a valid DID
817
+ * or DID URL (without the fragment component) which identifies the sender of the message.
818
+ */
819
+ from?: string,
820
+
821
+ /**
822
+ * Identifier(s) for recipients. MUST be an array of strings where each element
823
+ * is a valid DID or DID URL (without the fragment component) that identifies a member
824
+ * of the message’s intended audience.
825
+ */
826
+ to?: Array<string>,
827
+
828
+ /**
829
+ * Uniquely identifies the thread that the message belongs to.
830
+ * If not included the id property of the message MUST be treated as the value of the `thid`.
831
+ */
832
+ thid?: string,
833
+
834
+ /**
835
+ * If the message is a child of a thread the `pthid`
836
+ * will uniquely identify which thread is the parent.
837
+ */
838
+ pthid?: string,
839
+
840
+ /**
841
+ * Custom message headers.
842
+ */
843
+ [extra_header: string]: any
844
+
845
+ /**
846
+ * The attribute is used for the sender
847
+ * to express when they created the message, expressed in
848
+ * UTC Epoch Seconds (seconds since 1970-01-01T00:00:00Z UTC).
849
+ * This attribute is informative to the recipient, and may be relied on by protocols.
850
+ */
851
+ created_time?: number,
852
+
853
+ /**
854
+ * The expires_time attribute is used for the sender to express when they consider
855
+ * the message to be expired, expressed in UTC Epoch Seconds (seconds since 1970-01-01T00:00:00Z UTC).
856
+ * This attribute signals when the message is considered no longer valid by the sender.
857
+ * When omitted, the message is considered to have no expiration by the sender.
858
+ */
859
+ expires_time?: number,
860
+
861
+ /**
862
+ * from_prior is a compactly serialized signed JWT containing FromPrior value
863
+ */
864
+ from_prior?: string,
865
+
866
+ /**
867
+ * Message attachments
868
+ */
869
+ attachments?: Array<Attachment>,
870
+ };
871
+
872
+
873
+
874
+ type IParsedForward = {
875
+ msg: Message,
876
+ next: string,
877
+ forwarded_msg: any
878
+ }
879
+
880
+
881
+
882
+ type JsonAttachmentData = {
883
+ /**
884
+ * Directly embedded JSON data.
885
+ */
886
+ json: any,
887
+
888
+ /**
889
+ * A JSON Web Signature over the content of the attachment.
890
+ */
891
+ jws?: string,
892
+ }
893
+
894
+
895
+
896
+ type LinksAttachmentData = {
897
+ /**
898
+ * A list of one or more locations at which the content may be fetched.
899
+ */
900
+ links: Array<string>,
901
+
902
+ /**
903
+ * The hash of the content encoded in multi-hash format. Used as an integrity check for the attachment.
904
+ */
905
+ hash: string,
906
+
907
+ /**
908
+ * A JSON Web Signature over the content of the attachment.
909
+ */
910
+ jws?: string,
911
+ }
912
+
913
+
914
+
915
+ type VerificationMethodType = "JsonWebKey2020" | "X25519KeyAgreementKey2019"
916
+ | "Ed25519VerificationKey2018" | "EcdsaSecp256k1VerificationKey2019" | string
917
+
918
+
919
+
920
+ /**
921
+ * Allows building of `from_prior` message header according
922
+ * to DIDComm DID Rotation procedure
923
+ * https://identity.foundation/didcomm-messaging/spec/#did-rotation.
924
+ */
925
+ export class FromPrior {
926
+ free(): void;
927
+ [Symbol.dispose](): void;
928
+ /**
929
+ * Instantiates FromPrior from plain object
930
+ */
931
+ constructor(value: IFromPrior);
932
+ }
933
+
934
+ /**
935
+ * Wrapper for plain message. Provides helpers for message building and packing/unpacking.
936
+ */
937
+ export class Message {
938
+ free(): void;
939
+ [Symbol.dispose](): void;
940
+ /**
941
+ * Instantiates message from plain object
942
+ */
943
+ constructor(value: IMessage);
944
+ }
945
+
946
+ export class ParsedForward {
947
+ private constructor();
948
+ free(): void;
949
+ [Symbol.dispose](): void;
950
+ }