hbsig 0.0.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.
Files changed (44) hide show
  1. package/cjs/bin_to_str.js +44 -0
  2. package/cjs/collect-body-keys.js +470 -0
  3. package/cjs/encode-array-item.js +110 -0
  4. package/cjs/encode-utils.js +236 -0
  5. package/cjs/encode.js +1318 -0
  6. package/cjs/erl_json.js +317 -0
  7. package/cjs/erl_str.js +1037 -0
  8. package/cjs/flat.js +222 -0
  9. package/cjs/http-message-signatures/httpbis.js +489 -0
  10. package/cjs/http-message-signatures/index.js +25 -0
  11. package/cjs/http-message-signatures/structured-header.js +129 -0
  12. package/cjs/httpsig.js +716 -0
  13. package/cjs/httpsig2.js +1160 -0
  14. package/cjs/id.js +470 -0
  15. package/cjs/index.js +63 -0
  16. package/cjs/send.js +194 -0
  17. package/cjs/signer-utils.js +617 -0
  18. package/cjs/signer.js +606 -0
  19. package/cjs/structured.js +296 -0
  20. package/cjs/test.js +27 -0
  21. package/cjs/utils.js +42 -0
  22. package/esm/bin_to_str.js +46 -0
  23. package/esm/collect-body-keys.js +436 -0
  24. package/esm/encode-array-item.js +112 -0
  25. package/esm/encode-utils.js +185 -0
  26. package/esm/encode.js +1219 -0
  27. package/esm/erl_json.js +289 -0
  28. package/esm/erl_str.js +1139 -0
  29. package/esm/flat.js +196 -0
  30. package/esm/http-message-signatures/httpbis.js +438 -0
  31. package/esm/http-message-signatures/index.js +4 -0
  32. package/esm/http-message-signatures/structured-header.js +105 -0
  33. package/esm/httpsig.js +658 -0
  34. package/esm/httpsig2.js +1097 -0
  35. package/esm/id.js +459 -0
  36. package/esm/index.js +4 -0
  37. package/esm/package.json +3 -0
  38. package/esm/send.js +124 -0
  39. package/esm/signer-utils.js +494 -0
  40. package/esm/signer.js +452 -0
  41. package/esm/structured.js +269 -0
  42. package/esm/test.js +6 -0
  43. package/esm/utils.js +28 -0
  44. package/package.json +28 -0
@@ -0,0 +1,105 @@
1
+ import {
2
+ isInnerList,
3
+ parseDictionary,
4
+ parseItem,
5
+ parseList,
6
+ serializeDictionary,
7
+ serializeInnerList,
8
+ serializeItem,
9
+ serializeList,
10
+ } from "structured-headers"
11
+
12
+ export class Dictionary {
13
+ constructor(input) {
14
+ this.raw = input
15
+ this.parsed = parseDictionary(input)
16
+ }
17
+
18
+ toString() {
19
+ return this.serialize()
20
+ }
21
+
22
+ serialize() {
23
+ return serializeDictionary(this.parsed)
24
+ }
25
+
26
+ has(key) {
27
+ return this.parsed.has(key)
28
+ }
29
+
30
+ get(key) {
31
+ const value = this.parsed.get(key)
32
+ if (!value) {
33
+ return value
34
+ }
35
+ if (isInnerList(value)) {
36
+ return serializeInnerList(value)
37
+ }
38
+ return serializeItem(value)
39
+ }
40
+ }
41
+
42
+ export class List {
43
+ constructor(input) {
44
+ this.raw = input
45
+ this.parsed = parseList(input)
46
+ }
47
+
48
+ toString() {
49
+ return this.serialize()
50
+ }
51
+
52
+ serialize() {
53
+ return serializeList(this.parsed)
54
+ }
55
+ }
56
+
57
+ export class Item {
58
+ constructor(input) {
59
+ this.raw = input
60
+ this.parsed = parseItem(input)
61
+ }
62
+
63
+ toString() {
64
+ return this.serialize()
65
+ }
66
+
67
+ serialize() {
68
+ return serializeItem(this.parsed)
69
+ }
70
+ }
71
+
72
+ export function parseHeader(header) {
73
+ const classes = [List, Dictionary, Item]
74
+ for (let i = 0; i < classes.length; i++) {
75
+ try {
76
+ return new classes[i](header)
77
+ } catch (e) {
78
+ // noop
79
+ }
80
+ }
81
+ throw new Error("Unable to parse header as structured field")
82
+ }
83
+
84
+ /**
85
+ * This allows consumers of the library to supply field specifications that aren't
86
+ * strictly "structured fields". Really a string must start with a `"` but that won't
87
+ * tend to happen in our configs.
88
+ *
89
+ * @param {string} input
90
+ * @returns {string}
91
+ */
92
+ export function quoteString(input) {
93
+ // if it's not quoted, attempt to quote
94
+ if (!input.startsWith('"')) {
95
+ // try to split the structured field
96
+ const [name, ...rest] = input.split(";")
97
+ // no params, just quote the whole thing
98
+ if (!rest.length) {
99
+ return `"${name}"`
100
+ }
101
+ // quote the first part and put the rest back as it was
102
+ return `"${name}";${rest.join(";")}`
103
+ }
104
+ return input
105
+ }