@irvinebroque/http-rfc-utils 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.
Files changed (147) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +222 -0
  3. package/dist/auth.d.ts +139 -0
  4. package/dist/auth.d.ts.map +1 -0
  5. package/dist/auth.js +991 -0
  6. package/dist/auth.js.map +1 -0
  7. package/dist/cache-status.d.ts +15 -0
  8. package/dist/cache-status.d.ts.map +1 -0
  9. package/dist/cache-status.js +152 -0
  10. package/dist/cache-status.js.map +1 -0
  11. package/dist/cache.d.ts +94 -0
  12. package/dist/cache.d.ts.map +1 -0
  13. package/dist/cache.js +244 -0
  14. package/dist/cache.js.map +1 -0
  15. package/dist/client-hints.d.ts +23 -0
  16. package/dist/client-hints.d.ts.map +1 -0
  17. package/dist/client-hints.js +81 -0
  18. package/dist/client-hints.js.map +1 -0
  19. package/dist/conditional.d.ts +97 -0
  20. package/dist/conditional.d.ts.map +1 -0
  21. package/dist/conditional.js +300 -0
  22. package/dist/conditional.js.map +1 -0
  23. package/dist/content-disposition.d.ts +23 -0
  24. package/dist/content-disposition.d.ts.map +1 -0
  25. package/dist/content-disposition.js +122 -0
  26. package/dist/content-disposition.js.map +1 -0
  27. package/dist/cookie.d.ts +43 -0
  28. package/dist/cookie.d.ts.map +1 -0
  29. package/dist/cookie.js +472 -0
  30. package/dist/cookie.js.map +1 -0
  31. package/dist/cors.d.ts +53 -0
  32. package/dist/cors.d.ts.map +1 -0
  33. package/dist/cors.js +170 -0
  34. package/dist/cors.js.map +1 -0
  35. package/dist/datetime.d.ts +53 -0
  36. package/dist/datetime.d.ts.map +1 -0
  37. package/dist/datetime.js +205 -0
  38. package/dist/datetime.js.map +1 -0
  39. package/dist/digest.d.ts +220 -0
  40. package/dist/digest.d.ts.map +1 -0
  41. package/dist/digest.js +355 -0
  42. package/dist/digest.js.map +1 -0
  43. package/dist/encoding.d.ts +14 -0
  44. package/dist/encoding.d.ts.map +1 -0
  45. package/dist/encoding.js +86 -0
  46. package/dist/encoding.js.map +1 -0
  47. package/dist/etag.d.ts +55 -0
  48. package/dist/etag.d.ts.map +1 -0
  49. package/dist/etag.js +182 -0
  50. package/dist/etag.js.map +1 -0
  51. package/dist/ext-value.d.ts +40 -0
  52. package/dist/ext-value.d.ts.map +1 -0
  53. package/dist/ext-value.js +119 -0
  54. package/dist/ext-value.js.map +1 -0
  55. package/dist/forwarded.d.ts +14 -0
  56. package/dist/forwarded.d.ts.map +1 -0
  57. package/dist/forwarded.js +93 -0
  58. package/dist/forwarded.js.map +1 -0
  59. package/dist/header-utils.d.ts +71 -0
  60. package/dist/header-utils.d.ts.map +1 -0
  61. package/dist/header-utils.js +143 -0
  62. package/dist/header-utils.js.map +1 -0
  63. package/dist/headers.d.ts +71 -0
  64. package/dist/headers.d.ts.map +1 -0
  65. package/dist/headers.js +134 -0
  66. package/dist/headers.js.map +1 -0
  67. package/dist/hsts.d.ts +15 -0
  68. package/dist/hsts.d.ts.map +1 -0
  69. package/dist/hsts.js +106 -0
  70. package/dist/hsts.js.map +1 -0
  71. package/dist/http-signatures.d.ts +202 -0
  72. package/dist/http-signatures.d.ts.map +1 -0
  73. package/dist/http-signatures.js +720 -0
  74. package/dist/http-signatures.js.map +1 -0
  75. package/dist/index.d.ts +41 -0
  76. package/dist/index.d.ts.map +1 -0
  77. package/dist/index.js +125 -0
  78. package/dist/index.js.map +1 -0
  79. package/dist/json-pointer.d.ts +97 -0
  80. package/dist/json-pointer.d.ts.map +1 -0
  81. package/dist/json-pointer.js +278 -0
  82. package/dist/json-pointer.js.map +1 -0
  83. package/dist/jsonpath.d.ts +98 -0
  84. package/dist/jsonpath.d.ts.map +1 -0
  85. package/dist/jsonpath.js +1470 -0
  86. package/dist/jsonpath.js.map +1 -0
  87. package/dist/language.d.ts +14 -0
  88. package/dist/language.d.ts.map +1 -0
  89. package/dist/language.js +95 -0
  90. package/dist/language.js.map +1 -0
  91. package/dist/link.d.ts +102 -0
  92. package/dist/link.d.ts.map +1 -0
  93. package/dist/link.js +437 -0
  94. package/dist/link.js.map +1 -0
  95. package/dist/linkset.d.ts +111 -0
  96. package/dist/linkset.d.ts.map +1 -0
  97. package/dist/linkset.js +501 -0
  98. package/dist/linkset.js.map +1 -0
  99. package/dist/negotiate.d.ts +71 -0
  100. package/dist/negotiate.d.ts.map +1 -0
  101. package/dist/negotiate.js +357 -0
  102. package/dist/negotiate.js.map +1 -0
  103. package/dist/pagination.d.ts +80 -0
  104. package/dist/pagination.d.ts.map +1 -0
  105. package/dist/pagination.js +188 -0
  106. package/dist/pagination.js.map +1 -0
  107. package/dist/prefer.d.ts +18 -0
  108. package/dist/prefer.d.ts.map +1 -0
  109. package/dist/prefer.js +93 -0
  110. package/dist/prefer.js.map +1 -0
  111. package/dist/problem.d.ts +54 -0
  112. package/dist/problem.d.ts.map +1 -0
  113. package/dist/problem.js +104 -0
  114. package/dist/problem.js.map +1 -0
  115. package/dist/proxy-status.d.ts +28 -0
  116. package/dist/proxy-status.d.ts.map +1 -0
  117. package/dist/proxy-status.js +220 -0
  118. package/dist/proxy-status.js.map +1 -0
  119. package/dist/range.d.ts +28 -0
  120. package/dist/range.d.ts.map +1 -0
  121. package/dist/range.js +243 -0
  122. package/dist/range.js.map +1 -0
  123. package/dist/response.d.ts +101 -0
  124. package/dist/response.d.ts.map +1 -0
  125. package/dist/response.js +200 -0
  126. package/dist/response.js.map +1 -0
  127. package/dist/sorting.d.ts +66 -0
  128. package/dist/sorting.d.ts.map +1 -0
  129. package/dist/sorting.js +168 -0
  130. package/dist/sorting.js.map +1 -0
  131. package/dist/structured-fields.d.ts +30 -0
  132. package/dist/structured-fields.d.ts.map +1 -0
  133. package/dist/structured-fields.js +468 -0
  134. package/dist/structured-fields.js.map +1 -0
  135. package/dist/types.d.ts +772 -0
  136. package/dist/types.d.ts.map +1 -0
  137. package/dist/types.js +8 -0
  138. package/dist/types.js.map +1 -0
  139. package/dist/uri-template.d.ts +48 -0
  140. package/dist/uri-template.d.ts.map +1 -0
  141. package/dist/uri-template.js +483 -0
  142. package/dist/uri-template.js.map +1 -0
  143. package/dist/uri.d.ts +80 -0
  144. package/dist/uri.d.ts.map +1 -0
  145. package/dist/uri.js +423 -0
  146. package/dist/uri.js.map +1 -0
  147. package/package.json +66 -0
@@ -0,0 +1,202 @@
1
+ /**
2
+ * HTTP Message Signatures per RFC 9421.
3
+ * RFC 9421 §2-3.
4
+ * @see https://www.rfc-editor.org/rfc/rfc9421.html
5
+ *
6
+ * This module provides primitives for creating signature bases and parsing/formatting
7
+ * Signature-Input and Signature fields. Actual cryptographic signing/verification
8
+ * is out of scope - this provides the HTTP-layer primitives.
9
+ */
10
+ import type { SignatureComponent, SignatureParams, SignatureInput, Signature, SignatureMessageContext, SignatureBaseResult, DerivedComponentName } from './types.js';
11
+ /**
12
+ * Derived component names per RFC 9421 §2.2.
13
+ * These are special component identifiers that start with '@'.
14
+ */
15
+ export declare const DERIVED_COMPONENTS: readonly DerivedComponentName[];
16
+ /**
17
+ * Check if a component name is a derived component.
18
+ * RFC 9421 §2.2.
19
+ */
20
+ export declare function isDerivedComponent(name: string): name is DerivedComponentName;
21
+ /**
22
+ * Parse a Signature-Input field value.
23
+ * RFC 9421 §4.1.
24
+ *
25
+ * The Signature-Input field is a Dictionary Structured Field containing the
26
+ * metadata for one or more message signatures.
27
+ *
28
+ * @param value - The Signature-Input header field value
29
+ * @returns Array of parsed SignatureInput objects, or null if parsing fails
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * const inputs = parseSignatureInput(
34
+ * 'sig1=("@method" "@authority" "content-type");created=1618884473;keyid="test-key"'
35
+ * );
36
+ * // Returns: [{ label: 'sig1', components: [...], params: { created: 1618884473, keyid: 'test-key' } }]
37
+ * ```
38
+ */
39
+ export declare function parseSignatureInput(value: string): SignatureInput[] | null;
40
+ /**
41
+ * Format SignatureInput objects to a Signature-Input field value.
42
+ * RFC 9421 §4.1.
43
+ *
44
+ * @param inputs - Array of SignatureInput objects to format
45
+ * @returns The formatted Signature-Input header field value
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * const value = formatSignatureInput([{
50
+ * label: 'sig1',
51
+ * components: [{ name: '@method' }, { name: 'content-type' }],
52
+ * params: { created: 1618884473, keyid: 'test-key' }
53
+ * }]);
54
+ * // Returns: 'sig1=("@method" "content-type");created=1618884473;keyid="test-key"'
55
+ * ```
56
+ */
57
+ export declare function formatSignatureInput(inputs: SignatureInput[]): string;
58
+ /**
59
+ * Parse a Signature field value.
60
+ * RFC 9421 §4.2.
61
+ *
62
+ * The Signature field is a Dictionary Structured Field containing signature
63
+ * values as byte sequences.
64
+ *
65
+ * @param value - The Signature header field value
66
+ * @returns Array of parsed Signature objects, or null if parsing fails
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * const sigs = parseSignature('sig1=:YmFzZTY0ZW5jb2RlZHNpZw==:');
71
+ * // Returns: [{ label: 'sig1', value: Uint8Array([...]) }]
72
+ * ```
73
+ */
74
+ export declare function parseSignature(value: string): Signature[] | null;
75
+ /**
76
+ * Format Signature objects to a Signature field value.
77
+ * RFC 9421 §4.2.
78
+ *
79
+ * @param signatures - Array of Signature objects to format
80
+ * @returns The formatted Signature header field value
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * const value = formatSignature([{
85
+ * label: 'sig1',
86
+ * value: new Uint8Array([98, 97, 115, 101, 54, 52])
87
+ * }]);
88
+ * // Returns: 'sig1=:YmFzZTY0:' (base64 encoded)
89
+ * ```
90
+ */
91
+ export declare function formatSignature(signatures: Signature[]): string;
92
+ /**
93
+ * Parse a component identifier string.
94
+ * RFC 9421 §2.
95
+ *
96
+ * Component identifiers are strings that identify HTTP message components
97
+ * to be included in the signature base.
98
+ *
99
+ * @param value - The component identifier string (e.g., '"content-type"' or '"cache-control";sf')
100
+ * @returns Parsed SignatureComponent, or null if parsing fails
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * const component = parseComponentIdentifier('"content-type"');
105
+ * // Returns: { name: 'content-type' }
106
+ *
107
+ * const componentWithParams = parseComponentIdentifier('"example-dict";key="member"');
108
+ * // Returns: { name: 'example-dict', params: { key: 'member' } }
109
+ * ```
110
+ */
111
+ export declare function parseComponentIdentifier(value: string): SignatureComponent | null;
112
+ /**
113
+ * Format a component identifier to string.
114
+ * RFC 9421 §2.
115
+ *
116
+ * @param component - The SignatureComponent to format
117
+ * @returns The formatted component identifier string
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * formatComponentIdentifier({ name: 'content-type' });
122
+ * // Returns: '"content-type"'
123
+ *
124
+ * formatComponentIdentifier({ name: 'example-dict', params: { key: 'member' } });
125
+ * // Returns: '"example-dict";key="member"'
126
+ * ```
127
+ */
128
+ export declare function formatComponentIdentifier(component: SignatureComponent): string;
129
+ /**
130
+ * Canonicalize field values per RFC 9421 §2.1.
131
+ *
132
+ * Multiple field values are combined with ", " (comma + space).
133
+ * Leading/trailing whitespace is trimmed from each value.
134
+ * Obsolete line folding is replaced with a single space.
135
+ *
136
+ * @param values - Array of field values
137
+ * @returns The canonicalized field value
138
+ *
139
+ * @example
140
+ * ```ts
141
+ * canonicalizeFieldValue([' value1 ', ' value2 ']);
142
+ * // Returns: 'value1, value2'
143
+ * ```
144
+ */
145
+ export declare function canonicalizeFieldValue(values: string[]): string;
146
+ /**
147
+ * Binary-wrap field values per RFC 9421 §2.1.4.
148
+ *
149
+ * Each field value is base64-encoded individually, and the results are
150
+ * combined with ", " (comma + space) and then re-encoded as a byte sequence.
151
+ *
152
+ * @param values - Array of field values
153
+ * @returns The binary-wrapped field value as a byte sequence
154
+ *
155
+ * @example
156
+ * ```ts
157
+ * binaryWrapFieldValues(['value1', 'value2']);
158
+ * // Returns base64 of each value concatenated
159
+ * ```
160
+ */
161
+ export declare function binaryWrapFieldValues(values: string[]): Uint8Array;
162
+ /**
163
+ * Derive a component value from a message context.
164
+ * RFC 9421 §2.
165
+ *
166
+ * @param message - The message context
167
+ * @param component - The component to derive
168
+ * @returns The derived value, or null if the component cannot be derived
169
+ */
170
+ export declare function deriveComponentValue(message: SignatureMessageContext, component: SignatureComponent): string | null;
171
+ /**
172
+ * Create the signature base string.
173
+ * RFC 9421 §2.5.
174
+ *
175
+ * The signature base is the string that will be signed. It contains one line
176
+ * per covered component, plus the signature parameters line at the end.
177
+ *
178
+ * @param message - The message context
179
+ * @param components - The components to include in the signature
180
+ * @param params - The signature parameters
181
+ * @returns The signature base and formatted signature-params, or null if creation fails
182
+ *
183
+ * @example
184
+ * ```ts
185
+ * const result = createSignatureBase(
186
+ * {
187
+ * method: 'POST',
188
+ * authority: 'example.com',
189
+ * headers: new Map([['content-type', ['application/json']]])
190
+ * },
191
+ * [{ name: '@method' }, { name: '@authority' }, { name: 'content-type' }],
192
+ * { created: 1618884473, keyid: 'test-key' }
193
+ * );
194
+ * // Returns:
195
+ * // {
196
+ * // base: '"@method": POST\n"@authority": example.com\n"content-type": application/json\n"@signature-params": ("@method" "@authority" "content-type");created=1618884473;keyid="test-key"',
197
+ * // signatureParams: '("@method" "@authority" "content-type");created=1618884473;keyid="test-key"'
198
+ * // }
199
+ * ```
200
+ */
201
+ export declare function createSignatureBase(message: SignatureMessageContext, components: SignatureComponent[], params?: SignatureParams): SignatureBaseResult | null;
202
+ //# sourceMappingURL=http-signatures.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-signatures.d.ts","sourceRoot":"","sources":["../src/http-signatures.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EACR,kBAAkB,EAElB,eAAe,EACf,cAAc,EACd,SAAS,EACT,uBAAuB,EACvB,mBAAmB,EACnB,oBAAoB,EAIvB,MAAM,YAAY,CAAC;AAEpB;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,SAAS,oBAAoB,EAUpD,CAAC;AAEX;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,oBAAoB,CAE7E;AAED;;;;;;;;;;;;;;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