hbsig 0.2.8 → 0.3.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.
- package/cjs/commit.js +263 -43
- package/cjs/encode-utils.js +10 -4
- package/cjs/encode.js +66 -19
- package/cjs/erl_json.js +12 -3
- package/cjs/erl_str.js +5 -0
- package/cjs/flat.js +70 -13
- package/cjs/httpsig.js +159 -173
- package/cjs/parser.js +30 -6
- package/cjs/send.js +11 -7
- package/cjs/signer-utils.js +14 -12
- package/cjs/signer.js +140 -281
- package/cjs/structured.js +140 -146
- package/cjs/test.js +0 -15
- package/esm/commit.js +174 -19
- package/esm/encode-utils.js +10 -4
- package/esm/encode.js +52 -15
- package/esm/erl_json.js +4 -1
- package/esm/erl_str.js +5 -0
- package/esm/flat.js +61 -7
- package/esm/httpsig.js +118 -113
- package/esm/parser.js +26 -8
- package/esm/send.js +8 -3
- package/esm/signer-utils.js +5 -1
- package/esm/signer.js +66 -174
- package/esm/structured.js +97 -98
- package/esm/test.js +2 -6
- package/package.json +2 -2
package/cjs/parser.js
CHANGED
|
@@ -39,7 +39,7 @@ function decodeSigInput(signatureInput) {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
// Extract from signature name to the next signature (if any) or end
|
|
42
|
-
var nextSigMatch = signatureInput.substring(startIndex + signatureName.length).match(/,\s*[a-zA-Z0-
|
|
42
|
+
var nextSigMatch = signatureInput.substring(startIndex + signatureName.length).match(/,\s*[a-zA-Z0-9_-]+=/);
|
|
43
43
|
var endIndex = nextSigMatch ? startIndex + signatureName.length + nextSigMatch.index : signatureInput.length;
|
|
44
44
|
inputToDecode = signatureInput.substring(startIndex, endIndex).trim();
|
|
45
45
|
}
|
|
@@ -48,7 +48,7 @@ function decodeSigInput(signatureInput) {
|
|
|
48
48
|
var signatures = {};
|
|
49
49
|
|
|
50
50
|
// Split by signature entries (handle multiple signatures)
|
|
51
|
-
var entries = inputToDecode.split(/,(?=\s*[a-zA-Z0-
|
|
51
|
+
var entries = inputToDecode.split(/,(?=\s*[a-zA-Z0-9_-]+=)/);
|
|
52
52
|
var _iterator = _createForOfIteratorHelper(entries),
|
|
53
53
|
_step;
|
|
54
54
|
try {
|
|
@@ -57,7 +57,7 @@ function decodeSigInput(signatureInput) {
|
|
|
57
57
|
var trimmedEntry = entry.trim();
|
|
58
58
|
|
|
59
59
|
// Match signature-name=(components);params format
|
|
60
|
-
var match = trimmedEntry.match(/^([a-zA-Z0-
|
|
60
|
+
var match = trimmedEntry.match(/^([a-zA-Z0-9_-]+)=\(([^)]*)\)(.*)$/);
|
|
61
61
|
if (!match) {
|
|
62
62
|
continue;
|
|
63
63
|
}
|
|
@@ -146,7 +146,6 @@ function extractSignatureName(headers) {
|
|
|
146
146
|
* @returns {Buffer|null} Public key buffer or null
|
|
147
147
|
*/
|
|
148
148
|
function extractPubKey(headers, signatureName) {
|
|
149
|
-
var _Object$values$;
|
|
150
149
|
var signatureInput = headers["signature-input"] || headers["Signature-Input"];
|
|
151
150
|
if (!signatureInput) return null;
|
|
152
151
|
|
|
@@ -155,10 +154,35 @@ function extractPubKey(headers, signatureName) {
|
|
|
155
154
|
if (!decoded) return null;
|
|
156
155
|
|
|
157
156
|
// If we decoded a specific signature, use its keyid
|
|
158
|
-
|
|
157
|
+
// When no specific signatureName, prefer RSA signature over HMAC
|
|
158
|
+
// (HMAC keyid is "constant:ao" which is not a real public key)
|
|
159
|
+
var keyid = null;
|
|
160
|
+
if (signatureName && decoded.params) {
|
|
161
|
+
keyid = decoded.params.keyid;
|
|
162
|
+
} else {
|
|
163
|
+
var _rsaEntry$params, _entries$;
|
|
164
|
+
var entries = Object.values(decoded);
|
|
165
|
+
var rsaEntry = entries.find(function (e) {
|
|
166
|
+
var _e$params;
|
|
167
|
+
return (_e$params = e.params) === null || _e$params === void 0 || (_e$params = _e$params.alg) === null || _e$params === void 0 ? void 0 : _e$params.startsWith("rsa-");
|
|
168
|
+
});
|
|
169
|
+
keyid = (rsaEntry === null || rsaEntry === void 0 || (_rsaEntry$params = rsaEntry.params) === null || _rsaEntry$params === void 0 ? void 0 : _rsaEntry$params.keyid) || ((_entries$ = entries[0]) === null || _entries$ === void 0 || (_entries$ = _entries$.params) === null || _entries$ === void 0 ? void 0 : _entries$.keyid);
|
|
170
|
+
}
|
|
159
171
|
if (!keyid) return null;
|
|
160
172
|
try {
|
|
161
|
-
|
|
173
|
+
// Strip scheme prefix if present (e.g., "publickey:base64data" -> "base64data")
|
|
174
|
+
var keyidToDecode = keyid;
|
|
175
|
+
if (keyid.includes(":")) {
|
|
176
|
+
var colonIndex = keyid.indexOf(":");
|
|
177
|
+
keyidToDecode = keyid.substring(colonIndex + 1);
|
|
178
|
+
}
|
|
179
|
+
// Handle both base64url and standard base64 encoding
|
|
180
|
+
// Standard base64 uses +/ while base64url uses -_
|
|
181
|
+
if (keyidToDecode.includes("+") || keyidToDecode.includes("/")) {
|
|
182
|
+
// Standard base64 - convert to buffer directly
|
|
183
|
+
return Buffer.from(keyidToDecode, "base64");
|
|
184
|
+
}
|
|
185
|
+
return _base64url["default"].toBuffer(keyidToDecode);
|
|
162
186
|
} catch (error) {
|
|
163
187
|
return null;
|
|
164
188
|
}
|
package/cjs/send.js
CHANGED
|
@@ -78,8 +78,7 @@ function _send() {
|
|
|
78
78
|
_args3 = arguments,
|
|
79
79
|
_t,
|
|
80
80
|
_t2,
|
|
81
|
-
_t3
|
|
82
|
-
_t4;
|
|
81
|
+
_t3;
|
|
83
82
|
return _regenerator().w(function (_context3) {
|
|
84
83
|
while (1) switch (_context3.n) {
|
|
85
84
|
case 0:
|
|
@@ -105,9 +104,8 @@ function _send() {
|
|
|
105
104
|
_context3.n = 2;
|
|
106
105
|
return response.text();
|
|
107
106
|
case 2:
|
|
108
|
-
_t3 = _context3.v;
|
|
109
|
-
|
|
110
|
-
throw new _t(_t4);
|
|
107
|
+
_t3 = _t2.concat.call(_t2, _context3.v);
|
|
108
|
+
throw new _t(_t3);
|
|
111
109
|
case 3:
|
|
112
110
|
_context3.n = 4;
|
|
113
111
|
return (0, _sendUtils.result)(response);
|
|
@@ -123,7 +121,9 @@ var httpSigName = exports.httpSigName = function httpSigName(address) {
|
|
|
123
121
|
var hexString = _toConsumableArray(decoded.subarray(1, 9)).map(function (_byte) {
|
|
124
122
|
return _byte.toString(16).padStart(2, "0");
|
|
125
123
|
}).join("");
|
|
126
|
-
|
|
124
|
+
// Use 'comm-' prefix to match HyperBEAM's siginfo_to_commitments pattern
|
|
125
|
+
// (it strips <<"comm-", Rest/binary>> before parsing structured fields)
|
|
126
|
+
return "comm-".concat(hexString);
|
|
127
127
|
};
|
|
128
128
|
var toView = function toView(value) {
|
|
129
129
|
if (ArrayBuffer.isView(value)) {
|
|
@@ -147,10 +147,14 @@ var toHttpSigner = exports.toHttpSigner = function toHttpSigner(signer) {
|
|
|
147
147
|
_injected$alg = injected.alg,
|
|
148
148
|
alg = _injected$alg === void 0 ? "rsa-pss-sha512" : _injected$alg;
|
|
149
149
|
var publicKeyBuffer = toView(publicKey);
|
|
150
|
+
// Use standard base64 encoding for keyid to be compatible with HyperBEAM's
|
|
151
|
+
// base64:decode in dev_codec_httpsig_keyid:apply_scheme
|
|
152
|
+
// Include "publickey:" prefix so HyperBEAM knows the key scheme
|
|
153
|
+
var keyidBase64 = "publickey:".concat(publicKeyBuffer.toString("base64"));
|
|
150
154
|
var signingParameters = createSigningParameters({
|
|
151
155
|
params: params,
|
|
152
156
|
paramValues: {
|
|
153
|
-
keyid:
|
|
157
|
+
keyid: keyidBase64,
|
|
154
158
|
alg: alg
|
|
155
159
|
}
|
|
156
160
|
});
|
package/cjs/signer-utils.js
CHANGED
|
@@ -308,8 +308,7 @@ function _send() {
|
|
|
308
308
|
_t6,
|
|
309
309
|
_t7,
|
|
310
310
|
_t8,
|
|
311
|
-
_t9
|
|
312
|
-
_t0;
|
|
311
|
+
_t9;
|
|
313
312
|
return _regenerator().w(function (_context7) {
|
|
314
313
|
while (1) switch (_context7.n) {
|
|
315
314
|
case 0:
|
|
@@ -335,20 +334,19 @@ function _send() {
|
|
|
335
334
|
_context7.n = 2;
|
|
336
335
|
return response.text();
|
|
337
336
|
case 2:
|
|
338
|
-
_t6 = _context7.v;
|
|
339
|
-
|
|
340
|
-
throw new _t4(_t7);
|
|
337
|
+
_t6 = _t5.concat.call(_t5, _context7.v);
|
|
338
|
+
throw new _t4(_t6);
|
|
341
339
|
case 3:
|
|
342
|
-
|
|
340
|
+
_t7 = response.headers;
|
|
343
341
|
_context7.n = 4;
|
|
344
342
|
return response.text();
|
|
345
343
|
case 4:
|
|
346
|
-
|
|
347
|
-
|
|
344
|
+
_t8 = _context7.v;
|
|
345
|
+
_t9 = response.status;
|
|
348
346
|
return _context7.a(2, {
|
|
349
|
-
headers:
|
|
350
|
-
body:
|
|
351
|
-
status:
|
|
347
|
+
headers: _t7,
|
|
348
|
+
body: _t8,
|
|
349
|
+
status: _t9
|
|
352
350
|
});
|
|
353
351
|
}
|
|
354
352
|
}, _callee7);
|
|
@@ -394,10 +392,14 @@ var toHttpSigner = exports.toHttpSigner = function toHttpSigner(signer) {
|
|
|
394
392
|
_injected$alg = injected.alg,
|
|
395
393
|
alg = _injected$alg === void 0 ? "rsa-pss-sha512" : _injected$alg;
|
|
396
394
|
var publicKeyBuffer = toView(publicKey);
|
|
395
|
+
// Use standard base64 encoding for keyid to be compatible with HyperBEAM's
|
|
396
|
+
// base64:decode in dev_codec_httpsig_keyid:apply_scheme
|
|
397
|
+
// Include "publickey:" prefix so HyperBEAM knows the key scheme
|
|
398
|
+
var keyidBase64 = "publickey:".concat(publicKeyBuffer.toString("base64"));
|
|
397
399
|
var signingParameters = createSigningParameters({
|
|
398
400
|
params: params,
|
|
399
401
|
paramValues: {
|
|
400
|
-
keyid:
|
|
402
|
+
keyid: keyidBase64,
|
|
401
403
|
alg: alg
|
|
402
404
|
}
|
|
403
405
|
});
|