@bcts/envelope 1.0.0-alpha.7 → 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 +9 -9
- 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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bcts/envelope",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Gordian Envelope for TypeScript",
|
|
6
6
|
"license": "BSD-2-Clause-Patent",
|
|
@@ -59,8 +59,8 @@
|
|
|
59
59
|
"node": ">=18.0.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@bcts/eslint": "
|
|
63
|
-
"@bcts/tsconfig": "
|
|
62
|
+
"@bcts/eslint": "^0.1.0",
|
|
63
|
+
"@bcts/tsconfig": "^0.1.0",
|
|
64
64
|
"@eslint/js": "^9.39.1",
|
|
65
65
|
"@types/node": "^24.10.1",
|
|
66
66
|
"@types/pako": "^2.0.3",
|
|
@@ -73,12 +73,12 @@
|
|
|
73
73
|
"vitest": "^3.2.4"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@bcts/components": "
|
|
77
|
-
"@bcts/crypto": "
|
|
78
|
-
"@bcts/dcbor": "
|
|
79
|
-
"@bcts/known-values": "
|
|
80
|
-
"@bcts/rand": "
|
|
81
|
-
"@bcts/uniform-resources": "
|
|
76
|
+
"@bcts/components": "^1.0.0-alpha.9",
|
|
77
|
+
"@bcts/crypto": "^1.0.0-alpha.9",
|
|
78
|
+
"@bcts/dcbor": "^1.0.0-alpha.9",
|
|
79
|
+
"@bcts/known-values": "^1.0.0-alpha.9",
|
|
80
|
+
"@bcts/rand": "^1.0.0-alpha.9",
|
|
81
|
+
"@bcts/uniform-resources": "^1.0.0-alpha.9",
|
|
82
82
|
"pako": "^2.1.0"
|
|
83
83
|
}
|
|
84
84
|
}
|
package/src/base/assertions.ts
CHANGED
|
@@ -11,157 +11,6 @@ import { EnvelopeError } from "./error";
|
|
|
11
11
|
/// These methods extend the Envelope class to provide a rich API for
|
|
12
12
|
/// working with assertions, matching the Rust bc-envelope implementation.
|
|
13
13
|
|
|
14
|
-
declare module "./envelope" {
|
|
15
|
-
interface Envelope {
|
|
16
|
-
/// Returns a new envelope with multiple assertion envelopes added.
|
|
17
|
-
///
|
|
18
|
-
/// This is a convenience method for adding multiple assertions at once.
|
|
19
|
-
/// Each assertion in the array must be a valid assertion envelope or an
|
|
20
|
-
/// obscured variant of one.
|
|
21
|
-
///
|
|
22
|
-
/// @param assertions - An array of valid assertion envelopes to add
|
|
23
|
-
/// @returns A new envelope with all the assertions added
|
|
24
|
-
/// @throws {EnvelopeError} If any of the provided envelopes are not valid
|
|
25
|
-
/// assertion envelopes
|
|
26
|
-
addAssertionEnvelopes(assertions: Envelope[]): Envelope;
|
|
27
|
-
|
|
28
|
-
/// Adds an optional assertion envelope to this envelope.
|
|
29
|
-
///
|
|
30
|
-
/// If the optional assertion is present, adds it to the envelope.
|
|
31
|
-
/// Otherwise, returns the envelope unchanged. This method is particularly
|
|
32
|
-
/// useful when working with functions that may or may not return an
|
|
33
|
-
/// assertion.
|
|
34
|
-
///
|
|
35
|
-
/// The method also ensures that duplicate assertions (with the same digest)
|
|
36
|
-
/// are not added, making it idempotent.
|
|
37
|
-
///
|
|
38
|
-
/// @param assertion - An optional assertion envelope to add
|
|
39
|
-
/// @returns A new envelope with the assertion added if provided, or the
|
|
40
|
-
/// original envelope if no assertion was provided or it was a duplicate
|
|
41
|
-
/// @throws {EnvelopeError} If the provided envelope is not a valid assertion
|
|
42
|
-
/// envelope or an obscured variant
|
|
43
|
-
addOptionalAssertionEnvelope(assertion: Envelope | undefined): Envelope;
|
|
44
|
-
|
|
45
|
-
/// Adds an assertion with the given predicate and optional object.
|
|
46
|
-
///
|
|
47
|
-
/// This method is useful when you have a predicate but may or may not have
|
|
48
|
-
/// an object value to associate with it. If the object is present, an
|
|
49
|
-
/// assertion is created and added to the envelope. Otherwise, the
|
|
50
|
-
/// envelope is returned unchanged.
|
|
51
|
-
///
|
|
52
|
-
/// @param predicate - The predicate for the assertion
|
|
53
|
-
/// @param object - An optional object value for the assertion
|
|
54
|
-
/// @returns A new envelope with the assertion added if the object was
|
|
55
|
-
/// provided, or the original envelope if no object was provided
|
|
56
|
-
addOptionalAssertion(
|
|
57
|
-
predicate: EnvelopeEncodableValue,
|
|
58
|
-
object: EnvelopeEncodableValue | undefined,
|
|
59
|
-
): Envelope;
|
|
60
|
-
|
|
61
|
-
/// Adds an assertion with the given predicate and string value, but only if
|
|
62
|
-
/// the string is non-empty.
|
|
63
|
-
///
|
|
64
|
-
/// This is a convenience method that only adds an assertion if the string
|
|
65
|
-
/// value is non-empty. It's particularly useful when working with user
|
|
66
|
-
/// input or optional text fields that should only be included if they
|
|
67
|
-
/// contain actual content.
|
|
68
|
-
///
|
|
69
|
-
/// @param predicate - The predicate for the assertion
|
|
70
|
-
/// @param str - The string value for the assertion
|
|
71
|
-
/// @returns A new envelope with the assertion added if the string is
|
|
72
|
-
/// non-empty, or the original envelope if the string is empty
|
|
73
|
-
addNonemptyStringAssertion(predicate: EnvelopeEncodableValue, str: string): Envelope;
|
|
74
|
-
|
|
75
|
-
/// Returns a new envelope with the given array of assertions added.
|
|
76
|
-
///
|
|
77
|
-
/// Similar to `addAssertionEnvelopes` but doesn't throw errors. This is
|
|
78
|
-
/// useful when you're certain all envelopes in the array are valid
|
|
79
|
-
/// assertion envelopes and don't need to handle errors.
|
|
80
|
-
///
|
|
81
|
-
/// @param envelopes - An array of assertion envelopes to add
|
|
82
|
-
/// @returns A new envelope with all the valid assertions added
|
|
83
|
-
addAssertions(envelopes: Envelope[]): Envelope;
|
|
84
|
-
|
|
85
|
-
/// Adds an assertion only if the provided condition is true.
|
|
86
|
-
///
|
|
87
|
-
/// This method allows for conditional inclusion of assertions based on a
|
|
88
|
-
/// boolean condition. It's a convenient way to add assertions only in
|
|
89
|
-
/// certain circumstances without requiring separate conditional logic.
|
|
90
|
-
///
|
|
91
|
-
/// @param condition - Boolean that determines whether to add the assertion
|
|
92
|
-
/// @param predicate - The predicate for the assertion
|
|
93
|
-
/// @param object - The object value for the assertion
|
|
94
|
-
/// @returns A new envelope with the assertion added if the condition is
|
|
95
|
-
/// true, or the original envelope if the condition is false
|
|
96
|
-
addAssertionIf(
|
|
97
|
-
condition: boolean,
|
|
98
|
-
predicate: EnvelopeEncodableValue,
|
|
99
|
-
object: EnvelopeEncodableValue,
|
|
100
|
-
): Envelope;
|
|
101
|
-
|
|
102
|
-
/// Adds an assertion envelope only if the provided condition is true.
|
|
103
|
-
///
|
|
104
|
-
/// Similar to `addAssertionIf` but works with pre-constructed assertion
|
|
105
|
-
/// envelopes. This is useful when you have already created an assertion
|
|
106
|
-
/// envelope separately and want to conditionally add it.
|
|
107
|
-
///
|
|
108
|
-
/// @param condition - Boolean that determines whether to add the assertion
|
|
109
|
-
/// envelope
|
|
110
|
-
/// @param assertionEnvelope - The assertion envelope to add
|
|
111
|
-
/// @returns A new envelope with the assertion added if the condition is
|
|
112
|
-
/// true, or the original envelope if the condition is false
|
|
113
|
-
/// @throws {EnvelopeError} If the provided envelope is not a valid assertion
|
|
114
|
-
/// envelope or an obscured variant and the condition is true
|
|
115
|
-
addAssertionEnvelopeIf(condition: boolean, assertionEnvelope: Envelope): Envelope;
|
|
116
|
-
|
|
117
|
-
/// Returns a new envelope with the given assertion removed.
|
|
118
|
-
///
|
|
119
|
-
/// Finds and removes an assertion matching the target assertion's digest.
|
|
120
|
-
/// If the assertion doesn't exist, returns the same envelope unchanged.
|
|
121
|
-
/// If removing the assertion would leave the envelope with no assertions,
|
|
122
|
-
/// returns just the subject as a new envelope.
|
|
123
|
-
///
|
|
124
|
-
/// @param target - The assertion envelope to remove
|
|
125
|
-
/// @returns A new envelope with the specified assertion removed if found,
|
|
126
|
-
/// or the original envelope if not found
|
|
127
|
-
removeAssertion(target: Envelope): Envelope;
|
|
128
|
-
|
|
129
|
-
/// Returns a new envelope with the given assertion replaced by a new one.
|
|
130
|
-
///
|
|
131
|
-
/// This method removes the specified assertion and adds a new one in its
|
|
132
|
-
/// place. If the targeted assertion does not exist, returns the same
|
|
133
|
-
/// envelope with the new assertion added.
|
|
134
|
-
///
|
|
135
|
-
/// @param assertion - The assertion envelope to replace
|
|
136
|
-
/// @param newAssertion - The new assertion envelope to add
|
|
137
|
-
/// @returns A new envelope with the assertion replaced if found, or the
|
|
138
|
-
/// original envelope with the new assertion added if not found
|
|
139
|
-
/// @throws {EnvelopeError} If the new assertion is not a valid assertion
|
|
140
|
-
/// envelope or an obscured variant
|
|
141
|
-
replaceAssertion(assertion: Envelope, newAssertion: Envelope): Envelope;
|
|
142
|
-
|
|
143
|
-
/// Returns a new envelope with its subject replaced by the provided one.
|
|
144
|
-
///
|
|
145
|
-
/// This method preserves all assertions from the original envelope but
|
|
146
|
-
/// applies them to a new subject. It effectively creates a new envelope
|
|
147
|
-
/// with the provided subject and copies over all assertions from the
|
|
148
|
-
/// current envelope.
|
|
149
|
-
///
|
|
150
|
-
/// @param subject - The new subject for the envelope
|
|
151
|
-
/// @returns A new envelope with the new subject and all assertions from the
|
|
152
|
-
/// original envelope
|
|
153
|
-
replaceSubject(subject: Envelope): Envelope;
|
|
154
|
-
|
|
155
|
-
/// Returns the assertions of this envelope.
|
|
156
|
-
///
|
|
157
|
-
/// For a node envelope, returns the array of assertion envelopes.
|
|
158
|
-
/// For all other envelope types, returns an empty array.
|
|
159
|
-
///
|
|
160
|
-
/// @returns An array of assertion envelopes
|
|
161
|
-
assertions(): Envelope[];
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
14
|
/// Implementation of addAssertionEnvelopes
|
|
166
15
|
Envelope.prototype.addAssertionEnvelopes = function (
|
|
167
16
|
this: Envelope,
|
package/src/base/elide.ts
CHANGED
|
@@ -33,142 +33,6 @@ export function elideAction(): ObscureAction {
|
|
|
33
33
|
return { type: "elide" };
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
/// Support for eliding elements from envelopes.
|
|
37
|
-
declare module "./envelope" {
|
|
38
|
-
interface Envelope {
|
|
39
|
-
/// Returns the elided variant of this envelope.
|
|
40
|
-
///
|
|
41
|
-
/// Elision replaces an envelope with just its digest, hiding its content
|
|
42
|
-
/// while maintaining the integrity of the envelope's digest tree.
|
|
43
|
-
///
|
|
44
|
-
/// @returns The elided envelope
|
|
45
|
-
elide(): Envelope;
|
|
46
|
-
|
|
47
|
-
/// Returns a version of this envelope with elements in the target set
|
|
48
|
-
/// obscured using the specified action.
|
|
49
|
-
///
|
|
50
|
-
/// @param target - The set of digests that identify elements to be obscured
|
|
51
|
-
/// @param action - The action to perform on the targeted elements
|
|
52
|
-
/// @returns The modified envelope
|
|
53
|
-
elideRemovingSetWithAction(target: Set<Digest>, action: ObscureAction): Envelope;
|
|
54
|
-
|
|
55
|
-
/// Returns a version of this envelope with elements in the target set
|
|
56
|
-
/// elided.
|
|
57
|
-
///
|
|
58
|
-
/// @param target - The set of digests that identify elements to be elided
|
|
59
|
-
/// @returns The modified envelope
|
|
60
|
-
elideRemovingSet(target: Set<Digest>): Envelope;
|
|
61
|
-
|
|
62
|
-
/// Returns a version of this envelope with elements in the target array
|
|
63
|
-
/// obscured using the specified action.
|
|
64
|
-
///
|
|
65
|
-
/// @param target - An array of DigestProviders
|
|
66
|
-
/// @param action - The action to perform
|
|
67
|
-
/// @returns The modified envelope
|
|
68
|
-
elideRemovingArrayWithAction(target: DigestProvider[], action: ObscureAction): Envelope;
|
|
69
|
-
|
|
70
|
-
/// Returns a version of this envelope with elements in the target array
|
|
71
|
-
/// elided.
|
|
72
|
-
///
|
|
73
|
-
/// @param target - An array of DigestProviders
|
|
74
|
-
/// @returns The modified envelope
|
|
75
|
-
elideRemovingArray(target: DigestProvider[]): Envelope;
|
|
76
|
-
|
|
77
|
-
/// Returns a version of this envelope with the target element obscured.
|
|
78
|
-
///
|
|
79
|
-
/// @param target - A DigestProvider
|
|
80
|
-
/// @param action - The action to perform
|
|
81
|
-
/// @returns The modified envelope
|
|
82
|
-
elideRemovingTargetWithAction(target: DigestProvider, action: ObscureAction): Envelope;
|
|
83
|
-
|
|
84
|
-
/// Returns a version of this envelope with the target element elided.
|
|
85
|
-
///
|
|
86
|
-
/// @param target - A DigestProvider
|
|
87
|
-
/// @returns The modified envelope
|
|
88
|
-
elideRemovingTarget(target: DigestProvider): Envelope;
|
|
89
|
-
|
|
90
|
-
/// Returns a version of this envelope with only elements in the target set
|
|
91
|
-
/// revealed, and all other elements obscured.
|
|
92
|
-
///
|
|
93
|
-
/// @param target - The set of digests that identify elements to be revealed
|
|
94
|
-
/// @param action - The action to perform on other elements
|
|
95
|
-
/// @returns The modified envelope
|
|
96
|
-
elideRevealingSetWithAction(target: Set<Digest>, action: ObscureAction): Envelope;
|
|
97
|
-
|
|
98
|
-
/// Returns a version of this envelope with only elements in the target set
|
|
99
|
-
/// revealed.
|
|
100
|
-
///
|
|
101
|
-
/// @param target - The set of digests that identify elements to be revealed
|
|
102
|
-
/// @returns The modified envelope
|
|
103
|
-
elideRevealingSet(target: Set<Digest>): Envelope;
|
|
104
|
-
|
|
105
|
-
/// Returns a version of this envelope with elements not in the target array
|
|
106
|
-
/// obscured.
|
|
107
|
-
///
|
|
108
|
-
/// @param target - An array of DigestProviders
|
|
109
|
-
/// @param action - The action to perform
|
|
110
|
-
/// @returns The modified envelope
|
|
111
|
-
elideRevealingArrayWithAction(target: DigestProvider[], action: ObscureAction): Envelope;
|
|
112
|
-
|
|
113
|
-
/// Returns a version of this envelope with elements not in the target array
|
|
114
|
-
/// elided.
|
|
115
|
-
///
|
|
116
|
-
/// @param target - An array of DigestProviders
|
|
117
|
-
/// @returns The modified envelope
|
|
118
|
-
elideRevealingArray(target: DigestProvider[]): Envelope;
|
|
119
|
-
|
|
120
|
-
/// Returns a version of this envelope with all elements except the target
|
|
121
|
-
/// element obscured.
|
|
122
|
-
///
|
|
123
|
-
/// @param target - A DigestProvider
|
|
124
|
-
/// @param action - The action to perform
|
|
125
|
-
/// @returns The modified envelope
|
|
126
|
-
elideRevealingTargetWithAction(target: DigestProvider, action: ObscureAction): Envelope;
|
|
127
|
-
|
|
128
|
-
/// Returns a version of this envelope with all elements except the target
|
|
129
|
-
/// element elided.
|
|
130
|
-
///
|
|
131
|
-
/// @param target - A DigestProvider
|
|
132
|
-
/// @returns The modified envelope
|
|
133
|
-
elideRevealingTarget(target: DigestProvider): Envelope;
|
|
134
|
-
|
|
135
|
-
/// Returns the unelided variant of this envelope by revealing the original
|
|
136
|
-
/// content.
|
|
137
|
-
///
|
|
138
|
-
/// @param envelope - The original unelided envelope
|
|
139
|
-
/// @returns The revealed envelope
|
|
140
|
-
/// @throws {EnvelopeError} If digests don't match
|
|
141
|
-
unelide(envelope: Envelope): Envelope;
|
|
142
|
-
|
|
143
|
-
/// Returns the set of digests of nodes matching the specified criteria.
|
|
144
|
-
///
|
|
145
|
-
/// @param targetDigests - Optional set of digests to filter by
|
|
146
|
-
/// @param obscureTypes - Array of ObscureType values to match against
|
|
147
|
-
/// @returns A Set of matching digests
|
|
148
|
-
nodesMatching(targetDigests: Set<Digest> | undefined, obscureTypes: ObscureType[]): Set<Digest>;
|
|
149
|
-
|
|
150
|
-
/// Returns a new envelope with elided nodes restored from the provided set.
|
|
151
|
-
///
|
|
152
|
-
/// @param envelopes - An array of envelopes that may match elided nodes
|
|
153
|
-
/// @returns The envelope with restored nodes
|
|
154
|
-
walkUnelide(envelopes: Envelope[]): Envelope;
|
|
155
|
-
|
|
156
|
-
/// Returns a new envelope with nodes matching target digests replaced.
|
|
157
|
-
///
|
|
158
|
-
/// @param target - Set of digests identifying nodes to replace
|
|
159
|
-
/// @param replacement - The envelope to use for replacement
|
|
160
|
-
/// @returns The modified envelope
|
|
161
|
-
/// @throws {EnvelopeError} If replacement is invalid
|
|
162
|
-
walkReplace(target: Set<Digest>, replacement: Envelope): Envelope;
|
|
163
|
-
|
|
164
|
-
/// Checks if two envelopes are identical (same structure and content).
|
|
165
|
-
///
|
|
166
|
-
/// @param other - The other envelope to compare with
|
|
167
|
-
/// @returns `true` if identical
|
|
168
|
-
isIdenticalTo(other: Envelope): boolean;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
36
|
/// Implementation of elide()
|
|
173
37
|
Envelope.prototype.elide = function (this: Envelope): Envelope {
|
|
174
38
|
const c = this.case();
|
|
@@ -117,49 +117,6 @@ export function extractNull(envelope: Envelope): null {
|
|
|
117
117
|
throw EnvelopeError.cbor("envelope does not contain null");
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
/// Extension methods for Envelope to support CBOR decoding.
|
|
121
|
-
///
|
|
122
|
-
/// These methods are added to the Envelope class prototype to match
|
|
123
|
-
/// the Rust API.
|
|
124
|
-
declare module "./envelope" {
|
|
125
|
-
interface Envelope {
|
|
126
|
-
/// Attempts to extract the leaf CBOR value from this envelope.
|
|
127
|
-
///
|
|
128
|
-
/// @returns The CBOR value contained in the leaf
|
|
129
|
-
/// @throws {EnvelopeError} If the envelope is not a leaf
|
|
130
|
-
tryLeaf(): Cbor;
|
|
131
|
-
|
|
132
|
-
/// Converts this envelope to a string.
|
|
133
|
-
///
|
|
134
|
-
/// @returns The string value
|
|
135
|
-
/// @throws {EnvelopeError} If the envelope cannot be converted
|
|
136
|
-
extractString(): string;
|
|
137
|
-
|
|
138
|
-
/// Converts this envelope to a number.
|
|
139
|
-
///
|
|
140
|
-
/// @returns The number value
|
|
141
|
-
/// @throws {EnvelopeError} If the envelope cannot be converted
|
|
142
|
-
extractNumber(): number;
|
|
143
|
-
|
|
144
|
-
/// Converts this envelope to a boolean.
|
|
145
|
-
///
|
|
146
|
-
/// @returns The boolean value
|
|
147
|
-
/// @throws {EnvelopeError} If the envelope cannot be converted
|
|
148
|
-
extractBoolean(): boolean;
|
|
149
|
-
|
|
150
|
-
/// Converts this envelope to a byte array.
|
|
151
|
-
///
|
|
152
|
-
/// @returns The byte array value
|
|
153
|
-
/// @throws {EnvelopeError} If the envelope cannot be converted
|
|
154
|
-
extractBytes(): Uint8Array;
|
|
155
|
-
|
|
156
|
-
/// Extracts null from this envelope.
|
|
157
|
-
///
|
|
158
|
-
/// @throws {EnvelopeError} If the envelope does not contain null
|
|
159
|
-
extractNull(): null;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
120
|
/// Static methods for creating envelopes from CBOR data.
|
|
164
121
|
///
|
|
165
122
|
/// These are convenience methods that mirror the Rust implementation.
|
package/src/base/envelope.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Assertion } from "./assertion";
|
|
|
3
3
|
import { EnvelopeError } from "./error";
|
|
4
4
|
import type { EnvelopeEncodableValue } from "./envelope-encodable";
|
|
5
5
|
import { KnownValue } from "@bcts/known-values";
|
|
6
|
-
import type { Cbor } from "@bcts/dcbor";
|
|
6
|
+
import type { Cbor, CborMap } from "@bcts/dcbor";
|
|
7
7
|
import {
|
|
8
8
|
cbor,
|
|
9
9
|
cborData,
|
|
@@ -18,6 +18,20 @@ import {
|
|
|
18
18
|
} from "@bcts/dcbor";
|
|
19
19
|
import { ENVELOPE, LEAF, ENCRYPTED, COMPRESSED } from "@bcts/components";
|
|
20
20
|
|
|
21
|
+
// Type imports for extension method declarations
|
|
22
|
+
// These are imported as types only to avoid circular dependencies at runtime
|
|
23
|
+
import type { ObscureAction, ObscureType } from "./elide";
|
|
24
|
+
import type { Visitor } from "./walk";
|
|
25
|
+
import type {
|
|
26
|
+
SymmetricKey,
|
|
27
|
+
SealedMessage,
|
|
28
|
+
PublicKeyBase,
|
|
29
|
+
PrivateKeyBase,
|
|
30
|
+
Signer,
|
|
31
|
+
Verifier,
|
|
32
|
+
SignatureMetadata,
|
|
33
|
+
} from "../extension";
|
|
34
|
+
|
|
21
35
|
/// Import tag values from the tags registry
|
|
22
36
|
/// These match the Rust reference implementation in bc-tags-rust
|
|
23
37
|
const TAG_ENVELOPE = ENVELOPE.value;
|
|
@@ -787,4 +801,188 @@ export class Envelope implements DigestProvider {
|
|
|
787
801
|
///
|
|
788
802
|
/// @returns A diagnostic string
|
|
789
803
|
declare diagnostic: () => string;
|
|
804
|
+
|
|
805
|
+
//
|
|
806
|
+
// Extension methods (implemented via prototype extension in extension modules)
|
|
807
|
+
// These declarations ensure TypeScript recognizes the methods when consuming the package
|
|
808
|
+
//
|
|
809
|
+
|
|
810
|
+
// From assertions.ts
|
|
811
|
+
declare addAssertionEnvelopes: (assertions: Envelope[]) => Envelope;
|
|
812
|
+
declare addOptionalAssertionEnvelope: (assertion: Envelope | undefined) => Envelope;
|
|
813
|
+
declare addOptionalAssertion: (
|
|
814
|
+
predicate: EnvelopeEncodableValue,
|
|
815
|
+
object: EnvelopeEncodableValue | undefined,
|
|
816
|
+
) => Envelope;
|
|
817
|
+
declare addNonemptyStringAssertion: (predicate: EnvelopeEncodableValue, str: string) => Envelope;
|
|
818
|
+
declare addAssertions: (envelopes: Envelope[]) => Envelope;
|
|
819
|
+
declare addAssertionIf: (
|
|
820
|
+
condition: boolean,
|
|
821
|
+
predicate: EnvelopeEncodableValue,
|
|
822
|
+
object: EnvelopeEncodableValue,
|
|
823
|
+
) => Envelope;
|
|
824
|
+
declare addAssertionEnvelopeIf: (condition: boolean, assertionEnvelope: Envelope) => Envelope;
|
|
825
|
+
declare removeAssertion: (target: Envelope) => Envelope;
|
|
826
|
+
declare replaceAssertion: (assertion: Envelope, newAssertion: Envelope) => Envelope;
|
|
827
|
+
declare replaceSubject: (subject: Envelope) => Envelope;
|
|
828
|
+
|
|
829
|
+
// From elide.ts
|
|
830
|
+
declare elide: () => Envelope;
|
|
831
|
+
declare elideRemovingSetWithAction: (target: Set<Digest>, action: ObscureAction) => Envelope;
|
|
832
|
+
declare elideRemovingSet: (target: Set<Digest>) => Envelope;
|
|
833
|
+
declare elideRemovingArrayWithAction: (
|
|
834
|
+
target: DigestProvider[],
|
|
835
|
+
action: ObscureAction,
|
|
836
|
+
) => Envelope;
|
|
837
|
+
declare elideRemovingArray: (target: DigestProvider[]) => Envelope;
|
|
838
|
+
declare elideRemovingTargetWithAction: (
|
|
839
|
+
target: DigestProvider,
|
|
840
|
+
action: ObscureAction,
|
|
841
|
+
) => Envelope;
|
|
842
|
+
declare elideRemovingTarget: (target: DigestProvider) => Envelope;
|
|
843
|
+
declare elideRevealingSetWithAction: (target: Set<Digest>, action: ObscureAction) => Envelope;
|
|
844
|
+
declare elideRevealingSet: (target: Set<Digest>) => Envelope;
|
|
845
|
+
declare elideRevealingArrayWithAction: (
|
|
846
|
+
target: DigestProvider[],
|
|
847
|
+
action: ObscureAction,
|
|
848
|
+
) => Envelope;
|
|
849
|
+
declare elideRevealingArray: (target: DigestProvider[]) => Envelope;
|
|
850
|
+
declare elideRevealingTargetWithAction: (
|
|
851
|
+
target: DigestProvider,
|
|
852
|
+
action: ObscureAction,
|
|
853
|
+
) => Envelope;
|
|
854
|
+
declare elideRevealingTarget: (target: DigestProvider) => Envelope;
|
|
855
|
+
declare unelide: (envelope: Envelope) => Envelope;
|
|
856
|
+
declare nodesMatching: (
|
|
857
|
+
targetDigests: Set<Digest> | undefined,
|
|
858
|
+
obscureTypes: ObscureType[],
|
|
859
|
+
) => Set<Digest>;
|
|
860
|
+
declare walkUnelide: (envelopes: Envelope[]) => Envelope;
|
|
861
|
+
declare walkReplace: (target: Set<Digest>, replacement: Envelope) => Envelope;
|
|
862
|
+
declare isIdenticalTo: (other: Envelope) => boolean;
|
|
863
|
+
|
|
864
|
+
// From leaf.ts
|
|
865
|
+
declare tryLeaf: () => Cbor;
|
|
866
|
+
declare extractString: () => string;
|
|
867
|
+
declare extractNumber: () => number;
|
|
868
|
+
declare extractBoolean: () => boolean;
|
|
869
|
+
declare extractBytes: () => Uint8Array;
|
|
870
|
+
declare extractNull: () => null;
|
|
871
|
+
|
|
872
|
+
// From queries.ts
|
|
873
|
+
declare isFalse: () => boolean;
|
|
874
|
+
declare isTrue: () => boolean;
|
|
875
|
+
declare isBool: () => boolean;
|
|
876
|
+
declare isNumber: () => boolean;
|
|
877
|
+
declare isSubjectNumber: () => boolean;
|
|
878
|
+
declare isNaN: () => boolean;
|
|
879
|
+
declare isSubjectNaN: () => boolean;
|
|
880
|
+
declare isNull: () => boolean;
|
|
881
|
+
declare tryByteString: () => Uint8Array;
|
|
882
|
+
declare asByteString: () => Uint8Array | undefined;
|
|
883
|
+
declare asArray: () => readonly Cbor[] | undefined;
|
|
884
|
+
declare asMap: () => CborMap | undefined;
|
|
885
|
+
declare asText: () => string | undefined;
|
|
886
|
+
declare asLeaf: () => Cbor | undefined;
|
|
887
|
+
declare hasAssertions: () => boolean;
|
|
888
|
+
declare asAssertion: () => Envelope | undefined;
|
|
889
|
+
declare tryAssertion: () => Envelope;
|
|
890
|
+
declare asPredicate: () => Envelope | undefined;
|
|
891
|
+
declare tryPredicate: () => Envelope;
|
|
892
|
+
declare asObject: () => Envelope | undefined;
|
|
893
|
+
declare tryObject: () => Envelope;
|
|
894
|
+
declare isAssertion: () => boolean;
|
|
895
|
+
declare isElided: () => boolean;
|
|
896
|
+
declare isLeaf: () => boolean;
|
|
897
|
+
declare isNode: () => boolean;
|
|
898
|
+
declare isWrapped: () => boolean;
|
|
899
|
+
declare isInternal: () => boolean;
|
|
900
|
+
declare isObscured: () => boolean;
|
|
901
|
+
declare assertions: () => Envelope[];
|
|
902
|
+
declare assertionsWithPredicate: (predicate: EnvelopeEncodableValue) => Envelope[];
|
|
903
|
+
declare assertionWithPredicate: (predicate: EnvelopeEncodableValue) => Envelope;
|
|
904
|
+
declare optionalAssertionWithPredicate: (
|
|
905
|
+
predicate: EnvelopeEncodableValue,
|
|
906
|
+
) => Envelope | undefined;
|
|
907
|
+
declare objectForPredicate: (predicate: EnvelopeEncodableValue) => Envelope;
|
|
908
|
+
declare optionalObjectForPredicate: (predicate: EnvelopeEncodableValue) => Envelope | undefined;
|
|
909
|
+
declare objectsForPredicate: (predicate: EnvelopeEncodableValue) => Envelope[];
|
|
910
|
+
declare elementsCount: () => number;
|
|
911
|
+
|
|
912
|
+
// From walk.ts
|
|
913
|
+
declare walk: <State>(hideNodes: boolean, state: State, visit: Visitor<State>) => void;
|
|
914
|
+
|
|
915
|
+
// From wrap.ts
|
|
916
|
+
declare wrap: () => Envelope;
|
|
917
|
+
declare tryUnwrap: () => Envelope;
|
|
918
|
+
declare unwrap: () => Envelope;
|
|
919
|
+
|
|
920
|
+
// From attachment.ts
|
|
921
|
+
declare addAttachment: (
|
|
922
|
+
payload: EnvelopeEncodableValue,
|
|
923
|
+
vendor: string,
|
|
924
|
+
conformsTo?: string,
|
|
925
|
+
) => Envelope;
|
|
926
|
+
declare attachmentPayload: () => Envelope;
|
|
927
|
+
declare attachmentVendor: () => string;
|
|
928
|
+
declare attachmentConformsTo: () => string | undefined;
|
|
929
|
+
declare attachments: () => Envelope[];
|
|
930
|
+
declare attachmentsWithVendorAndConformsTo: (vendor?: string, conformsTo?: string) => Envelope[];
|
|
931
|
+
|
|
932
|
+
// From compress.ts
|
|
933
|
+
declare compress: () => Envelope;
|
|
934
|
+
declare decompress: () => Envelope;
|
|
935
|
+
declare compressSubject: () => Envelope;
|
|
936
|
+
declare decompressSubject: () => Envelope;
|
|
937
|
+
declare isCompressed: () => boolean;
|
|
938
|
+
|
|
939
|
+
// From encrypt.ts
|
|
940
|
+
declare encryptSubject: (key: SymmetricKey) => Envelope;
|
|
941
|
+
declare decryptSubject: (key: SymmetricKey) => Envelope;
|
|
942
|
+
declare encrypt: (key: SymmetricKey) => Envelope;
|
|
943
|
+
declare decrypt: (key: SymmetricKey) => Envelope;
|
|
944
|
+
declare isEncrypted: () => boolean;
|
|
945
|
+
|
|
946
|
+
// From proof.ts
|
|
947
|
+
declare proofContainsSet: (target: Set<Digest>) => Envelope | undefined;
|
|
948
|
+
declare proofContainsTarget: (target: Envelope) => Envelope | undefined;
|
|
949
|
+
declare confirmContainsSet: (target: Set<Digest>, proof: Envelope) => boolean;
|
|
950
|
+
declare confirmContainsTarget: (target: Envelope, proof: Envelope) => boolean;
|
|
951
|
+
|
|
952
|
+
// From recipient.ts
|
|
953
|
+
declare encryptSubjectToRecipient: (recipientPublicKey: PublicKeyBase) => Envelope;
|
|
954
|
+
declare encryptSubjectToRecipients: (recipients: PublicKeyBase[]) => Envelope;
|
|
955
|
+
declare addRecipient: (recipientPublicKey: PublicKeyBase, contentKey: SymmetricKey) => Envelope;
|
|
956
|
+
declare decryptSubjectToRecipient: (recipientPrivateKey: PrivateKeyBase) => Envelope;
|
|
957
|
+
declare decryptToRecipient: (recipientPrivateKey: PrivateKeyBase) => Envelope;
|
|
958
|
+
declare encryptToRecipients: (recipients: PublicKeyBase[]) => Envelope;
|
|
959
|
+
declare recipients: () => SealedMessage[];
|
|
960
|
+
|
|
961
|
+
// From salt.ts
|
|
962
|
+
declare addSalt: () => Envelope;
|
|
963
|
+
declare addSaltWithLength: (count: number) => Envelope;
|
|
964
|
+
declare addSaltBytes: (saltBytes: Uint8Array) => Envelope;
|
|
965
|
+
declare addSaltInRange: (min: number, max: number) => Envelope;
|
|
966
|
+
|
|
967
|
+
// From signature.ts
|
|
968
|
+
declare addSignature: (signer: Signer) => Envelope;
|
|
969
|
+
declare addSignatureWithMetadata: (signer: Signer, metadata?: SignatureMetadata) => Envelope;
|
|
970
|
+
declare addSignatures: (signers: Signer[]) => Envelope;
|
|
971
|
+
declare hasSignatureFrom: (verifier: Verifier) => boolean;
|
|
972
|
+
declare verifySignatureFrom: (verifier: Verifier) => Envelope;
|
|
973
|
+
declare signatures: () => Envelope[];
|
|
974
|
+
|
|
975
|
+
// From types.ts
|
|
976
|
+
declare addType: (object: EnvelopeEncodableValue) => Envelope;
|
|
977
|
+
declare types: () => Envelope[];
|
|
978
|
+
declare getType: () => Envelope;
|
|
979
|
+
declare hasType: (t: EnvelopeEncodableValue) => boolean;
|
|
980
|
+
declare checkType: (t: EnvelopeEncodableValue) => void;
|
|
981
|
+
|
|
982
|
+
// Static methods from extensions
|
|
983
|
+
declare static newAttachment: (
|
|
984
|
+
payload: EnvelopeEncodableValue,
|
|
985
|
+
vendor: string,
|
|
986
|
+
conformsTo?: string,
|
|
987
|
+
) => Envelope;
|
|
790
988
|
}
|