@bcts/envelope 1.0.0-alpha.8 → 1.0.0-alpha.9
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.map +1 -1
- package/dist/index.d.cts +353 -549
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +353 -549
- package/dist/index.d.mts.map +1 -1
- package/dist/index.iife.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
- package/src/base/assertions.ts +0 -151
- package/src/base/elide.ts +0 -136
- package/src/base/envelope-decodable.ts +0 -43
- package/src/base/envelope.ts +199 -1
- package/src/base/leaf.ts +1 -80
- package/src/base/queries.ts +0 -130
- package/src/base/walk.ts +0 -26
- package/src/base/wrap.ts +0 -46
- package/src/extension/attachment.ts +0 -89
- package/src/extension/compress.ts +0 -117
- package/src/extension/encrypt.ts +0 -82
- package/src/extension/proof.ts +0 -49
- package/src/extension/recipient.ts +0 -117
- package/src/extension/salt.ts +0 -109
- package/src/extension/signature.ts +0 -65
- package/src/extension/types.ts +0 -130
|
@@ -286,123 +286,6 @@ export class SealedMessage {
|
|
|
286
286
|
}
|
|
287
287
|
}
|
|
288
288
|
|
|
289
|
-
declare module "../base/envelope" {
|
|
290
|
-
interface Envelope {
|
|
291
|
-
/// Encrypts the envelope's subject to a single recipient.
|
|
292
|
-
///
|
|
293
|
-
/// Generates a random content key, encrypts the subject with it,
|
|
294
|
-
/// and adds a sealed message containing the content key encrypted
|
|
295
|
-
/// to the recipient's public key.
|
|
296
|
-
///
|
|
297
|
-
/// @param recipientPublicKey - The recipient's public key
|
|
298
|
-
/// @returns A new envelope with encrypted subject and recipient assertion
|
|
299
|
-
///
|
|
300
|
-
/// @example
|
|
301
|
-
/// ```typescript
|
|
302
|
-
/// const bob = PrivateKeyBase.generate();
|
|
303
|
-
/// const encrypted = envelope.encryptSubjectToRecipient(bob.publicKeys());
|
|
304
|
-
/// ```
|
|
305
|
-
encryptSubjectToRecipient(recipientPublicKey: PublicKeyBase): Envelope;
|
|
306
|
-
|
|
307
|
-
/// Encrypts the envelope's subject to multiple recipients.
|
|
308
|
-
///
|
|
309
|
-
/// Each recipient gets their own sealed message containing the same
|
|
310
|
-
/// content key encrypted to their public key. Recipients must try
|
|
311
|
-
/// each sealed message until one decrypts successfully.
|
|
312
|
-
///
|
|
313
|
-
/// @param recipients - Array of recipient public keys
|
|
314
|
-
/// @returns A new envelope with encrypted subject and multiple recipient assertions
|
|
315
|
-
///
|
|
316
|
-
/// @example
|
|
317
|
-
/// ```typescript
|
|
318
|
-
/// const encrypted = envelope.encryptSubjectToRecipients([
|
|
319
|
-
/// alice.publicKeys(),
|
|
320
|
-
/// bob.publicKeys(),
|
|
321
|
-
/// charlie.publicKeys()
|
|
322
|
-
/// ]);
|
|
323
|
-
/// ```
|
|
324
|
-
encryptSubjectToRecipients(recipients: PublicKeyBase[]): Envelope;
|
|
325
|
-
|
|
326
|
-
/// Adds a recipient to an already encrypted envelope.
|
|
327
|
-
///
|
|
328
|
-
/// The envelope must already be encrypted with a content key.
|
|
329
|
-
/// This method adds another recipient who can decrypt using the
|
|
330
|
-
/// same content key.
|
|
331
|
-
///
|
|
332
|
-
/// @param recipientPublicKey - The new recipient's public key
|
|
333
|
-
/// @param contentKey - The symmetric key used to encrypt the subject
|
|
334
|
-
/// @returns A new envelope with an additional recipient assertion
|
|
335
|
-
///
|
|
336
|
-
/// @example
|
|
337
|
-
/// ```typescript
|
|
338
|
-
/// const dave = PrivateKeyBase.generate();
|
|
339
|
-
/// const withDave = encrypted.addRecipient(dave.publicKeys(), contentKey);
|
|
340
|
-
/// ```
|
|
341
|
-
addRecipient(recipientPublicKey: PublicKeyBase, contentKey: SymmetricKey): Envelope;
|
|
342
|
-
|
|
343
|
-
/// Decrypts an envelope's subject using a recipient's private key.
|
|
344
|
-
///
|
|
345
|
-
/// Tries each `hasRecipient` assertion until one unseals successfully,
|
|
346
|
-
/// then uses the recovered content key to decrypt the subject.
|
|
347
|
-
///
|
|
348
|
-
/// @param recipientPrivateKey - The recipient's private key
|
|
349
|
-
/// @returns A new envelope with decrypted subject
|
|
350
|
-
/// @throws {EnvelopeError} If not a valid recipient or subject not encrypted
|
|
351
|
-
///
|
|
352
|
-
/// @example
|
|
353
|
-
/// ```typescript
|
|
354
|
-
/// const decrypted = encrypted.decryptSubjectToRecipient(bob);
|
|
355
|
-
/// ```
|
|
356
|
-
decryptSubjectToRecipient(recipientPrivateKey: PrivateKeyBase): Envelope;
|
|
357
|
-
|
|
358
|
-
/// Convenience method to decrypt and unwrap an envelope.
|
|
359
|
-
///
|
|
360
|
-
/// Useful when the entire envelope was wrapped and encrypted.
|
|
361
|
-
/// Decrypts the subject and then unwraps it.
|
|
362
|
-
///
|
|
363
|
-
/// @param recipientPrivateKey - The recipient's private key
|
|
364
|
-
/// @returns The original decrypted and unwrapped envelope
|
|
365
|
-
/// @throws {EnvelopeError} If not a valid recipient, subject not encrypted, or cannot unwrap
|
|
366
|
-
///
|
|
367
|
-
/// @example
|
|
368
|
-
/// ```typescript
|
|
369
|
-
/// const original = wrappedEncrypted.decryptToRecipient(alice);
|
|
370
|
-
/// ```
|
|
371
|
-
decryptToRecipient(recipientPrivateKey: PrivateKeyBase): Envelope;
|
|
372
|
-
|
|
373
|
-
/// Convenience method to encrypt an entire envelope to recipients.
|
|
374
|
-
///
|
|
375
|
-
/// Wraps the envelope first, then encrypts it to the recipients.
|
|
376
|
-
/// This encrypts both the subject and all assertions.
|
|
377
|
-
///
|
|
378
|
-
/// @param recipients - Array of recipient public keys
|
|
379
|
-
/// @returns A new encrypted envelope
|
|
380
|
-
///
|
|
381
|
-
/// @example
|
|
382
|
-
/// ```typescript
|
|
383
|
-
/// const encrypted = envelope.encryptToRecipients([
|
|
384
|
-
/// alice.publicKeys(),
|
|
385
|
-
/// bob.publicKeys()
|
|
386
|
-
/// ]);
|
|
387
|
-
/// ```
|
|
388
|
-
encryptToRecipients(recipients: PublicKeyBase[]): Envelope;
|
|
389
|
-
|
|
390
|
-
/// Returns all sealed messages (recipient assertions) in the envelope.
|
|
391
|
-
///
|
|
392
|
-
/// Each sealed message represents one recipient who can decrypt
|
|
393
|
-
/// the envelope's subject.
|
|
394
|
-
///
|
|
395
|
-
/// @returns Array of sealed messages
|
|
396
|
-
///
|
|
397
|
-
/// @example
|
|
398
|
-
/// ```typescript
|
|
399
|
-
/// const recipients = envelope.recipients();
|
|
400
|
-
/// console.log(`Envelope has ${recipients.length} recipients`);
|
|
401
|
-
/// ```
|
|
402
|
-
recipients(): SealedMessage[];
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
|
|
406
289
|
/// Implementation of encryptSubjectToRecipient()
|
|
407
290
|
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
408
291
|
if (Envelope?.prototype) {
|
package/src/extension/salt.ts
CHANGED
|
@@ -60,115 +60,6 @@ function calculateProportionalSaltSize(envelopeSize: number, rng?: RandomNumberG
|
|
|
60
60
|
return rngNextInClosedRangeI32(actualRng, minSize, maxSize);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
declare module "../base/envelope" {
|
|
64
|
-
interface Envelope {
|
|
65
|
-
/// Adds a proportionally-sized salt assertion to decorrelate the envelope.
|
|
66
|
-
///
|
|
67
|
-
/// This method adds random salt bytes as an assertion to the envelope. The
|
|
68
|
-
/// size of the salt is proportional to the size of the envelope being
|
|
69
|
-
/// salted:
|
|
70
|
-
/// - For small envelopes: 8-16 bytes
|
|
71
|
-
/// - For larger envelopes: 5-25% of the envelope's size
|
|
72
|
-
///
|
|
73
|
-
/// Salt is added as an assertion with the predicate 'salt' and an object
|
|
74
|
-
/// containing random bytes. This changes the digest of the envelope while
|
|
75
|
-
/// preserving its semantic content, making it impossible to correlate with
|
|
76
|
-
/// other envelopes containing the same information.
|
|
77
|
-
///
|
|
78
|
-
/// @returns A new envelope with the salt assertion added
|
|
79
|
-
///
|
|
80
|
-
/// @example
|
|
81
|
-
/// ```typescript
|
|
82
|
-
/// // Create an envelope with personally identifiable information
|
|
83
|
-
/// const alice = Envelope.new("Alice")
|
|
84
|
-
/// .addAssertion("email", "alice@example.com")
|
|
85
|
-
/// .addAssertion("ssn", "123-45-6789");
|
|
86
|
-
///
|
|
87
|
-
/// // Create a second envelope with the same information
|
|
88
|
-
/// const alice2 = Envelope.new("Alice")
|
|
89
|
-
/// .addAssertion("email", "alice@example.com")
|
|
90
|
-
/// .addAssertion("ssn", "123-45-6789");
|
|
91
|
-
///
|
|
92
|
-
/// // The envelopes have the same digest
|
|
93
|
-
/// console.log(alice.digest().equals(alice2.digest())); // true
|
|
94
|
-
///
|
|
95
|
-
/// // Add salt to both envelopes
|
|
96
|
-
/// const aliceSalted = alice.addSalt();
|
|
97
|
-
/// const alice2Salted = alice2.addSalt();
|
|
98
|
-
///
|
|
99
|
-
/// // Now the envelopes have different digests, preventing correlation
|
|
100
|
-
/// console.log(aliceSalted.digest().equals(alice2Salted.digest())); // false
|
|
101
|
-
/// ```
|
|
102
|
-
addSalt(): Envelope;
|
|
103
|
-
|
|
104
|
-
/// Adds salt of a specific byte length to the envelope.
|
|
105
|
-
///
|
|
106
|
-
/// This method adds salt of a specified number of bytes to decorrelate the
|
|
107
|
-
/// envelope. It requires that the byte count be at least 8 bytes (64 bits)
|
|
108
|
-
/// to ensure sufficient entropy for effective decorrelation.
|
|
109
|
-
///
|
|
110
|
-
/// @param count - The exact number of salt bytes to add
|
|
111
|
-
/// @returns A new envelope with salt added
|
|
112
|
-
/// @throws {EnvelopeError} If the byte count is less than 8
|
|
113
|
-
///
|
|
114
|
-
/// @example
|
|
115
|
-
/// ```typescript
|
|
116
|
-
/// const envelope = Envelope.new("Hello");
|
|
117
|
-
///
|
|
118
|
-
/// // Add exactly 16 bytes of salt
|
|
119
|
-
/// const salted = envelope.addSaltWithLength(16);
|
|
120
|
-
///
|
|
121
|
-
/// // Trying to add less than 8 bytes will throw an error
|
|
122
|
-
/// try {
|
|
123
|
-
/// envelope.addSaltWithLength(7);
|
|
124
|
-
/// } catch (e) {
|
|
125
|
-
/// console.log("Error: salt must be at least 8 bytes");
|
|
126
|
-
/// }
|
|
127
|
-
/// ```
|
|
128
|
-
addSaltWithLength(count: number): Envelope;
|
|
129
|
-
|
|
130
|
-
/// Adds the given salt bytes as an assertion to the envelope.
|
|
131
|
-
///
|
|
132
|
-
/// This method attaches specific salt bytes as an assertion to the
|
|
133
|
-
/// envelope, using 'salt' as the predicate. This is useful when you need
|
|
134
|
-
/// to control the specific salt content being added.
|
|
135
|
-
///
|
|
136
|
-
/// @param saltBytes - A Uint8Array containing salt bytes
|
|
137
|
-
/// @returns A new envelope with the salt assertion added
|
|
138
|
-
///
|
|
139
|
-
/// @example
|
|
140
|
-
/// ```typescript
|
|
141
|
-
/// // Create salt with specific bytes
|
|
142
|
-
/// const salt = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
|
|
143
|
-
///
|
|
144
|
-
/// // Add this specific salt to an envelope
|
|
145
|
-
/// const envelope = Envelope.new("Hello");
|
|
146
|
-
/// const salted = envelope.addSaltBytes(salt);
|
|
147
|
-
/// ```
|
|
148
|
-
addSaltBytes(saltBytes: Uint8Array): Envelope;
|
|
149
|
-
|
|
150
|
-
/// Adds salt with a byte length randomly chosen from the given range.
|
|
151
|
-
///
|
|
152
|
-
/// This method adds salt with a length randomly selected from the specified
|
|
153
|
-
/// range to decorrelate the envelope. This provides additional
|
|
154
|
-
/// decorrelation by varying the size of the salt itself.
|
|
155
|
-
///
|
|
156
|
-
/// @param min - Minimum number of salt bytes (must be at least 8)
|
|
157
|
-
/// @param max - Maximum number of salt bytes
|
|
158
|
-
/// @returns A new envelope with salt added
|
|
159
|
-
/// @throws {EnvelopeError} If min is less than 8 or max is less than min
|
|
160
|
-
///
|
|
161
|
-
/// @example
|
|
162
|
-
/// ```typescript
|
|
163
|
-
/// const envelope = Envelope.new("Hello");
|
|
164
|
-
///
|
|
165
|
-
/// // Add salt with a length randomly chosen between 16 and 32 bytes
|
|
166
|
-
/// const salted = envelope.addSaltInRange(16, 32);
|
|
167
|
-
/// ```
|
|
168
|
-
addSaltInRange(min: number, max: number): Envelope;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
63
|
/// Implementation of addSalt()
|
|
173
64
|
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
174
65
|
if (Envelope?.prototype) {
|
|
@@ -247,71 +247,6 @@ export class SignatureMetadata {
|
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
-
/**
|
|
251
|
-
* Support for signing envelopes and verifying signatures.
|
|
252
|
-
*/
|
|
253
|
-
declare module "../base/envelope" {
|
|
254
|
-
interface Envelope {
|
|
255
|
-
/**
|
|
256
|
-
* Creates a signature for the envelope's subject and returns a new
|
|
257
|
-
* envelope with a 'signed': Signature assertion.
|
|
258
|
-
*
|
|
259
|
-
* @param signer - The signing key
|
|
260
|
-
* @returns The signed envelope
|
|
261
|
-
*
|
|
262
|
-
* @example
|
|
263
|
-
* ```typescript
|
|
264
|
-
* const privateKey = SigningPrivateKey.generate();
|
|
265
|
-
* const envelope = Envelope.new("Hello, world!");
|
|
266
|
-
* const signed = envelope.addSignature(privateKey);
|
|
267
|
-
* ```
|
|
268
|
-
*/
|
|
269
|
-
addSignature(signer: Signer): Envelope;
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* Creates a signature for the envelope's subject with optional metadata.
|
|
273
|
-
*
|
|
274
|
-
* @param signer - The signing key
|
|
275
|
-
* @param metadata - Optional metadata to attach to the signature
|
|
276
|
-
* @returns The signed envelope
|
|
277
|
-
*/
|
|
278
|
-
addSignatureWithMetadata(signer: Signer, metadata?: SignatureMetadata): Envelope;
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Creates multiple signatures for the envelope's subject.
|
|
282
|
-
*
|
|
283
|
-
* @param signers - Array of signing keys
|
|
284
|
-
* @returns The envelope with multiple signatures
|
|
285
|
-
*/
|
|
286
|
-
addSignatures(signers: Signer[]): Envelope;
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* Returns whether this envelope has a valid signature from the given verifier.
|
|
290
|
-
*
|
|
291
|
-
* @param verifier - The public key to verify against
|
|
292
|
-
* @returns True if a valid signature from this verifier exists
|
|
293
|
-
*/
|
|
294
|
-
hasSignatureFrom(verifier: Verifier): boolean;
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Verifies that this envelope has a valid signature from the given verifier
|
|
298
|
-
* and returns the envelope.
|
|
299
|
-
*
|
|
300
|
-
* @param verifier - The public key to verify against
|
|
301
|
-
* @returns The verified envelope
|
|
302
|
-
* @throws {EnvelopeError} If no valid signature is found
|
|
303
|
-
*/
|
|
304
|
-
verifySignatureFrom(verifier: Verifier): Envelope;
|
|
305
|
-
|
|
306
|
-
/**
|
|
307
|
-
* Returns all signature assertions in this envelope.
|
|
308
|
-
*
|
|
309
|
-
* @returns Array of signature envelopes
|
|
310
|
-
*/
|
|
311
|
-
signatures(): Envelope[];
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
250
|
// Implementation
|
|
316
251
|
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
317
252
|
if (Envelope?.prototype) {
|
package/src/extension/types.ts
CHANGED
|
@@ -53,136 +53,6 @@ import { EnvelopeError } from "../base/error";
|
|
|
53
53
|
/// The standard predicate for type assertions
|
|
54
54
|
export const IS_A = "isA";
|
|
55
55
|
|
|
56
|
-
declare module "../base/envelope" {
|
|
57
|
-
interface Envelope {
|
|
58
|
-
/// Adds a type assertion to the envelope using the `'isA'` predicate.
|
|
59
|
-
///
|
|
60
|
-
/// This method provides a convenient way to declare the type of an envelope
|
|
61
|
-
/// using the standard `'isA'` predicate. The type can be any value that can
|
|
62
|
-
/// be converted to an envelope, typically a string.
|
|
63
|
-
///
|
|
64
|
-
/// @param object - The type to assign to this envelope
|
|
65
|
-
/// @returns A new envelope with the type assertion added
|
|
66
|
-
///
|
|
67
|
-
/// @example
|
|
68
|
-
/// ```typescript
|
|
69
|
-
/// // Create a document and declare its type
|
|
70
|
-
/// const document = Envelope.new("Important Content").addType("Document");
|
|
71
|
-
///
|
|
72
|
-
/// // Verify the type was added
|
|
73
|
-
/// assert(document.hasType("Document"));
|
|
74
|
-
/// ```
|
|
75
|
-
addType(object: EnvelopeEncodableValue): Envelope;
|
|
76
|
-
|
|
77
|
-
/// Returns all type objects from the envelope's `'isA'` assertions.
|
|
78
|
-
///
|
|
79
|
-
/// This method retrieves all objects of assertions that use the `'isA'`
|
|
80
|
-
/// predicate. Each returned envelope represents a type that has been
|
|
81
|
-
/// assigned to this envelope.
|
|
82
|
-
///
|
|
83
|
-
/// @returns An array of envelopes, each representing a type assigned to
|
|
84
|
-
/// this envelope
|
|
85
|
-
///
|
|
86
|
-
/// @example
|
|
87
|
-
/// ```typescript
|
|
88
|
-
/// // Create an envelope with multiple types
|
|
89
|
-
/// const multiTyped = Envelope.new("Versatile Entity")
|
|
90
|
-
/// .addType("Person")
|
|
91
|
-
/// .addType("Employee")
|
|
92
|
-
/// .addType("Manager");
|
|
93
|
-
///
|
|
94
|
-
/// // Get all the type objects
|
|
95
|
-
/// const types = multiTyped.types();
|
|
96
|
-
///
|
|
97
|
-
/// // There should be 3 types
|
|
98
|
-
/// console.log(types.length); // 3
|
|
99
|
-
/// ```
|
|
100
|
-
types(): Envelope[];
|
|
101
|
-
|
|
102
|
-
/// Gets a single type object from the envelope's `'isA'` assertions.
|
|
103
|
-
///
|
|
104
|
-
/// This method is useful when an envelope is expected to have exactly one
|
|
105
|
-
/// type. It throws an error if the envelope has zero or multiple types.
|
|
106
|
-
///
|
|
107
|
-
/// @returns The single type object if exactly one exists
|
|
108
|
-
/// @throws {EnvelopeError} If multiple types exist or no types exist
|
|
109
|
-
///
|
|
110
|
-
/// @example
|
|
111
|
-
/// ```typescript
|
|
112
|
-
/// // Create an envelope with a single type
|
|
113
|
-
/// const person = Envelope.new("Alice").addType("Person");
|
|
114
|
-
///
|
|
115
|
-
/// // Get the type
|
|
116
|
-
/// const typeObj = person.getType();
|
|
117
|
-
/// const typeString = typeObj.extractString();
|
|
118
|
-
/// console.log(typeString); // "Person"
|
|
119
|
-
/// ```
|
|
120
|
-
getType(): Envelope;
|
|
121
|
-
|
|
122
|
-
/// Checks if the envelope has a specific type, using an envelope as the
|
|
123
|
-
/// type identifier.
|
|
124
|
-
///
|
|
125
|
-
/// This method compares the digest of each type object with the digest of
|
|
126
|
-
/// the provided value to determine if the envelope has the specified type.
|
|
127
|
-
///
|
|
128
|
-
/// @param t - The type to check for, which will be converted to an envelope
|
|
129
|
-
/// @returns `true` if the envelope has the specified type, `false`
|
|
130
|
-
/// otherwise
|
|
131
|
-
///
|
|
132
|
-
/// @example
|
|
133
|
-
/// ```typescript
|
|
134
|
-
/// // Create a typed envelope
|
|
135
|
-
/// const document = Envelope.new("Contract")
|
|
136
|
-
/// .addType("LegalDocument")
|
|
137
|
-
/// .addAssertion("status", "Draft");
|
|
138
|
-
///
|
|
139
|
-
/// // Check for various types
|
|
140
|
-
/// console.log(document.hasType("LegalDocument")); // true
|
|
141
|
-
/// console.log(document.hasType("Spreadsheet")); // false
|
|
142
|
-
/// ```
|
|
143
|
-
hasType(t: EnvelopeEncodableValue): boolean;
|
|
144
|
-
|
|
145
|
-
/// Verifies that the envelope has a specific type.
|
|
146
|
-
///
|
|
147
|
-
/// This method is similar to `hasType` but throws an error instead of
|
|
148
|
-
/// returning false, making it suitable for use in validation chains.
|
|
149
|
-
///
|
|
150
|
-
/// @param t - The type to check for, which will be converted to an envelope
|
|
151
|
-
/// @throws {EnvelopeError} If the envelope does not have the specified type
|
|
152
|
-
///
|
|
153
|
-
/// @example
|
|
154
|
-
/// ```typescript
|
|
155
|
-
/// // Function that processes a person
|
|
156
|
-
/// function processPerson(envelope: Envelope): string {
|
|
157
|
-
/// // Verify this is a person
|
|
158
|
-
/// envelope.checkType("Person");
|
|
159
|
-
///
|
|
160
|
-
/// // Extract the name
|
|
161
|
-
/// const name = envelope.subject().extractString();
|
|
162
|
-
/// return name;
|
|
163
|
-
/// }
|
|
164
|
-
///
|
|
165
|
-
/// // Create a person envelope
|
|
166
|
-
/// const person = Envelope.new("Alice").addType("Person");
|
|
167
|
-
///
|
|
168
|
-
/// // Process the person
|
|
169
|
-
/// const result = processPerson(person);
|
|
170
|
-
/// console.log(result); // "Alice"
|
|
171
|
-
///
|
|
172
|
-
/// // Create a non-person envelope
|
|
173
|
-
/// const document = Envelope.new("Contract").addType("Document");
|
|
174
|
-
///
|
|
175
|
-
/// // Processing will throw an error
|
|
176
|
-
/// try {
|
|
177
|
-
/// processPerson(document);
|
|
178
|
-
/// } catch (e) {
|
|
179
|
-
/// console.log("Not a person!");
|
|
180
|
-
/// }
|
|
181
|
-
/// ```
|
|
182
|
-
checkType(t: EnvelopeEncodableValue): void;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
56
|
/// Implementation of addType()
|
|
187
57
|
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
188
58
|
if (Envelope?.prototype) {
|