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,236 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.analyzeArray = analyzeArray;
7
+ exports.encodePrimitiveContent = encodePrimitiveContent;
8
+ exports.formatFloat = formatFloat;
9
+ exports.getAoType = getAoType;
10
+ exports.getValueByPath = getValueByPath;
11
+ exports.hasNewline = hasNewline;
12
+ exports.hasNonAscii = hasNonAscii;
13
+ exports.isBytes = isBytes;
14
+ exports.isEmpty = isEmpty;
15
+ exports.isPojo = isPojo;
16
+ exports.sha256 = sha256;
17
+ exports.sortTypeAnnotations = sortTypeAnnotations;
18
+ exports.toBuffer = toBuffer;
19
+ var _fastSha = require("fast-sha256");
20
+ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
21
+ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
22
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
23
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
24
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
25
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
26
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
27
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
28
+ function isBytes(value) {
29
+ return value instanceof ArrayBuffer || ArrayBuffer.isView(value) || Buffer.isBuffer(value) || value && _typeof(value) === "object" && value.type === "Buffer" && Array.isArray(value.data);
30
+ }
31
+ function isPojo(value) {
32
+ return !isBytes(value) && !Array.isArray(value) && !(value instanceof Blob) && _typeof(value) === "object" && value !== null;
33
+ }
34
+ function hasNewline(_x) {
35
+ return _hasNewline.apply(this, arguments);
36
+ }
37
+ function _hasNewline() {
38
+ _hasNewline = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(value) {
39
+ return _regenerator().w(function (_context) {
40
+ while (1) switch (_context.n) {
41
+ case 0:
42
+ if (!(typeof value === "string")) {
43
+ _context.n = 1;
44
+ break;
45
+ }
46
+ return _context.a(2, value.includes("\n"));
47
+ case 1:
48
+ if (!(value instanceof Blob)) {
49
+ _context.n = 3;
50
+ break;
51
+ }
52
+ _context.n = 2;
53
+ return value.text();
54
+ case 2:
55
+ value = _context.v;
56
+ return _context.a(2, value.includes("\n"));
57
+ case 3:
58
+ if (!isBytes(value)) {
59
+ _context.n = 4;
60
+ break;
61
+ }
62
+ return _context.a(2, Buffer.from(value).includes("\n"));
63
+ case 4:
64
+ return _context.a(2, false);
65
+ }
66
+ }, _callee);
67
+ }));
68
+ return _hasNewline.apply(this, arguments);
69
+ }
70
+ function sha256(_x2) {
71
+ return _sha.apply(this, arguments);
72
+ }
73
+ function _sha() {
74
+ _sha = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(data) {
75
+ var uint8Array, hashResult;
76
+ return _regenerator().w(function (_context2) {
77
+ while (1) switch (_context2.n) {
78
+ case 0:
79
+ if (!(data instanceof ArrayBuffer)) {
80
+ _context2.n = 1;
81
+ break;
82
+ }
83
+ uint8Array = new Uint8Array(data);
84
+ _context2.n = 4;
85
+ break;
86
+ case 1:
87
+ if (!(data instanceof Uint8Array)) {
88
+ _context2.n = 2;
89
+ break;
90
+ }
91
+ uint8Array = data;
92
+ _context2.n = 4;
93
+ break;
94
+ case 2:
95
+ if (!ArrayBuffer.isView(data)) {
96
+ _context2.n = 3;
97
+ break;
98
+ }
99
+ uint8Array = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
100
+ _context2.n = 4;
101
+ break;
102
+ case 3:
103
+ throw new Error("sha256 expects ArrayBuffer or ArrayBufferView");
104
+ case 4:
105
+ hashResult = (0, _fastSha.hash)(uint8Array);
106
+ return _context2.a(2, hashResult.buffer.slice(hashResult.byteOffset, hashResult.byteOffset + hashResult.byteLength));
107
+ }
108
+ }, _callee2);
109
+ }));
110
+ return _sha.apply(this, arguments);
111
+ }
112
+ function formatFloat(num) {
113
+ var exp = num.toExponential(20);
114
+ exp = exp.replace(/e\+(\d)$/, "e+0$1");
115
+ exp = exp.replace(/e-(\d)$/, "e-0$1");
116
+ return exp;
117
+ }
118
+ function hasNonAscii(str) {
119
+ return /[^\x00-\x7F]/.test(str);
120
+ }
121
+ function toBuffer(value) {
122
+ if (Buffer.isBuffer(value)) {
123
+ return value;
124
+ } else if (value && _typeof(value) === "object" && value.type === "Buffer" && Array.isArray(value.data)) {
125
+ return Buffer.from(value.data);
126
+ } else if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) {
127
+ return Buffer.from(value);
128
+ } else {
129
+ return Buffer.from(value);
130
+ }
131
+ }
132
+
133
+ // Navigate through a path to get a value from nested object/array
134
+ function getValueByPath(obj, path) {
135
+ var pathParts = path.split("/");
136
+ var value = obj;
137
+ var _iterator = _createForOfIteratorHelper(pathParts),
138
+ _step;
139
+ try {
140
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
141
+ var part = _step.value;
142
+ if (/^\d+$/.test(part)) {
143
+ value = value[parseInt(part) - 1];
144
+ } else {
145
+ value = value[part];
146
+ }
147
+ }
148
+ } catch (err) {
149
+ _iterator.e(err);
150
+ } finally {
151
+ _iterator.f();
152
+ }
153
+ return value;
154
+ }
155
+
156
+ // Get the ao-type for a value
157
+ function getAoType(value) {
158
+ if (typeof value === "boolean" || value === null || value === undefined || _typeof(value) === "symbol") {
159
+ return "atom";
160
+ } else if (typeof value === "number") {
161
+ return Number.isInteger(value) ? "integer" : "float";
162
+ } else if (typeof value === "string" && value.length === 0) {
163
+ return "empty-binary";
164
+ } else if (isBytes(value) && (value.length === 0 || value.byteLength === 0)) {
165
+ return "empty-binary";
166
+ } else if (Array.isArray(value) && value.length === 0) {
167
+ return "empty-list";
168
+ } else if (Array.isArray(value)) {
169
+ return "list";
170
+ } else if (isPojo(value) && Object.keys(value).length === 0) {
171
+ return "empty-message";
172
+ }
173
+ return null;
174
+ }
175
+
176
+ // Check if a value is empty
177
+ function isEmpty(value) {
178
+ return Array.isArray(value) && value.length === 0 || isPojo(value) && Object.keys(value).length === 0 || isBytes(value) && (value.length === 0 || value.byteLength === 0) || typeof value === "string" && value.length === 0;
179
+ }
180
+
181
+ // Convert primitive values to their encoded string representation
182
+ function encodePrimitiveContent(value) {
183
+ if (typeof value === "string") {
184
+ return value;
185
+ } else if (typeof value === "boolean") {
186
+ return "\"".concat(value, "\"");
187
+ } else if (typeof value === "number") {
188
+ return String(value);
189
+ } else if (value === null) {
190
+ return '"null"';
191
+ } else if (value === undefined) {
192
+ return '"undefined"';
193
+ } else if (_typeof(value) === "symbol") {
194
+ return "\"".concat(value.description || "Symbol.for()", "\"");
195
+ }
196
+ return value;
197
+ }
198
+
199
+ // Sort type annotations by their numeric prefix
200
+ function sortTypeAnnotations(types) {
201
+ return types.sort(function (a, b) {
202
+ var aNum = parseInt(a.split("=")[0]);
203
+ var bNum = parseInt(b.split("=")[0]);
204
+ return aNum - bNum;
205
+ });
206
+ }
207
+
208
+ // Analyze array contents
209
+ function analyzeArray(array) {
210
+ return {
211
+ hasObjects: array.some(function (item) {
212
+ return isPojo(item);
213
+ }),
214
+ hasArrays: array.some(function (item) {
215
+ return Array.isArray(item);
216
+ }),
217
+ hasEmptyStrings: array.some(function (item) {
218
+ return typeof item === "string" && item === "";
219
+ }),
220
+ hasEmptyObjects: array.some(function (item) {
221
+ return isPojo(item) && Object.keys(item).length === 0;
222
+ }),
223
+ hasOnlyEmptyElements: array.length > 0 && array.every(function (item) {
224
+ return Array.isArray(item) && item.length === 0 || isPojo(item) && Object.keys(item).length === 0 || typeof item === "string" && item === "";
225
+ }),
226
+ hasOnlyNonEmptyObjects: array.length > 0 && array.every(function (item) {
227
+ return isPojo(item) && Object.keys(item).length > 0;
228
+ }),
229
+ hasObjectsWithOnlyEmptyValues: array.some(function (item) {
230
+ if (!isPojo(item) || Object.keys(item).length === 0) return false;
231
+ return Object.values(item).every(function (v) {
232
+ return isEmpty(v);
233
+ });
234
+ })
235
+ };
236
+ }