@kya-os/checkpoint-express 1.1.0 → 1.1.2
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/CHANGELOG.md +62 -0
- package/dist/index.js +22 -1797
- package/dist/index.mjs +15 -1790
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import nodeCrypto from 'crypto';
|
|
2
|
-
import {
|
|
2
|
+
import { verifyRequest, renderDecisionAsResponse } from '@kya-os/checkpoint-wasm-runtime/orchestrator';
|
|
3
|
+
import { makeSystemClock, makePolicyEvaluator, makeReputationOracle, makeStatusListCache, makeDidResolver } from '@kya-os/checkpoint-wasm-runtime/adapters';
|
|
3
4
|
import { shouldEnforce, acceptsHtml, encodeVerdictCookie, classifyResponseShape, BLOCKED_PATH, VERDICT_COOKIE_NAME } from '@kya-os/checkpoint-shared';
|
|
4
5
|
export { DEFAULT_POLICY, ENFORCEMENT_ACTIONS, createEvaluationContext, evaluatePolicy } from '@kya-os/checkpoint-shared';
|
|
5
6
|
|
|
@@ -653,18 +654,18 @@ function createAutoPipelineProxy(_redis, namespace = "root") {
|
|
|
653
654
|
}
|
|
654
655
|
});
|
|
655
656
|
}
|
|
656
|
-
var
|
|
657
|
+
var __defProp2, __export2, error_exports, UpstashError, UrlError, UpstashJSONParseError, MAX_BUFFER_SIZE, HttpClient, defaultSerializer, Command, ExecCommand, FIELD_TYPES, SearchIndex, HRandFieldCommand, AppendCommand, BitCountCommand, BitFieldCommand, BitOpCommand, BitPosCommand, ClientSetInfoCommand, CopyCommand, DBSizeCommand, DecrCommand, DecrByCommand, DelCommand, EchoCommand, EvalROCommand, EvalCommand, EvalshaROCommand, EvalshaCommand, ExistsCommand, ExpireCommand, ExpireAtCommand, FCallCommand, FCallRoCommand, FlushAllCommand, FlushDBCommand, FunctionDeleteCommand, FunctionFlushCommand, FunctionListCommand, FunctionLoadCommand, FunctionStatsCommand, GeoAddCommand, GeoDistCommand, GeoHashCommand, GeoPosCommand, GeoSearchCommand, GeoSearchStoreCommand, GetCommand, GetBitCommand, GetDelCommand, GetExCommand, GetRangeCommand, GetSetCommand, HDelCommand, HExistsCommand, HExpireCommand, HExpireAtCommand, HExpireTimeCommand, HPersistCommand, HPExpireCommand, HPExpireAtCommand, HPExpireTimeCommand, HPTtlCommand, HGetCommand, HGetAllCommand, HMGetCommand, HGetDelCommand, HGetExCommand, HIncrByCommand, HIncrByFloatCommand, HKeysCommand, HLenCommand, HMSetCommand, HScanCommand, HSetCommand, HSetExCommand, HSetNXCommand, HStrLenCommand, HTtlCommand, HValsCommand, IncrCommand, IncrByCommand, IncrByFloatCommand, JsonArrAppendCommand, JsonArrIndexCommand, JsonArrInsertCommand, JsonArrLenCommand, JsonArrPopCommand, JsonArrTrimCommand, JsonClearCommand, JsonDelCommand, JsonForgetCommand, JsonGetCommand, JsonMergeCommand, JsonMGetCommand, JsonMSetCommand, JsonNumIncrByCommand, JsonNumMultByCommand, JsonObjKeysCommand, JsonObjLenCommand, JsonRespCommand, JsonSetCommand, JsonStrAppendCommand, JsonStrLenCommand, JsonToggleCommand, JsonTypeCommand, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, LMoveCommand, LmPopCommand, LPopCommand, LPosCommand, LPushCommand, LPushXCommand, LRangeCommand, LRemCommand, LSetCommand, LTrimCommand, MGetCommand, MSetCommand, MSetNXCommand, PersistCommand, PExpireCommand, PExpireAtCommand, PfAddCommand, PfCountCommand, PfMergeCommand, PingCommand, PSetEXCommand, PTtlCommand, PublishCommand, RandomKeyCommand, RenameCommand, RenameNXCommand, RPopCommand, RPushCommand, RPushXCommand, SAddCommand, ScanCommand, SCardCommand, ScriptExistsCommand, ScriptFlushCommand, ScriptLoadCommand, SDiffCommand, SDiffStoreCommand, SetCommand, SetBitCommand, SetExCommand, SetNxCommand, SetRangeCommand, SInterCommand, SInterCardCommand, SInterStoreCommand, SIsMemberCommand, SMembersCommand, SMIsMemberCommand, SMoveCommand, SPopCommand, SRandMemberCommand, SRemCommand, SScanCommand, StrLenCommand, SUnionCommand, SUnionStoreCommand, TimeCommand, TouchCommand, TtlCommand, TypeCommand, UnlinkCommand, XAckCommand, XAckDelCommand, XAddCommand, XAutoClaim, XClaimCommand, XDelCommand, XDelExCommand, XGroupCommand, XInfoCommand, XLenCommand, XPendingCommand, XRangeCommand, UNBALANCED_XREAD_ERR, XReadCommand, UNBALANCED_XREADGROUP_ERR, XReadGroupCommand, XRevRangeCommand, XTrimCommand, ZAddCommand, ZCardCommand, ZCountCommand, ZIncrByCommand, ZInterStoreCommand, ZLexCountCommand, ZPopMaxCommand, ZPopMinCommand, ZRangeCommand, ZRankCommand, ZRemCommand, ZRemRangeByLexCommand, ZRemRangeByRankCommand, ZRemRangeByScoreCommand, ZRevRankCommand, ZScanCommand, ZScoreCommand, ZUnionCommand, ZUnionStoreCommand, ZDiffStoreCommand, ZMScoreCommand, Pipeline, EXCLUDE_COMMANDS, AutoPipelineExecutor, PSubscribeCommand, Subscriber, SubscribeCommand, parseWithTryCatch, Script, ScriptRO, Redis, VERSION;
|
|
657
658
|
var init_chunk_IH7W44G6 = __esm({
|
|
658
659
|
"../../node_modules/.pnpm/@upstash+redis@1.37.0/node_modules/@upstash/redis/chunk-IH7W44G6.mjs"() {
|
|
659
660
|
init_crypto_node();
|
|
660
661
|
init_crypto_node();
|
|
661
|
-
|
|
662
|
-
|
|
662
|
+
__defProp2 = Object.defineProperty;
|
|
663
|
+
__export2 = (target, all) => {
|
|
663
664
|
for (var name in all)
|
|
664
|
-
|
|
665
|
+
__defProp2(target, name, { get: all[name], enumerable: true });
|
|
665
666
|
};
|
|
666
667
|
error_exports = {};
|
|
667
|
-
|
|
668
|
+
__export2(error_exports, {
|
|
668
669
|
UpstashError: () => UpstashError,
|
|
669
670
|
UpstashJSONParseError: () => UpstashJSONParseError,
|
|
670
671
|
UrlError: () => UrlError
|
|
@@ -4921,10 +4922,10 @@ var init_nodejs = __esm({
|
|
|
4921
4922
|
_noTokenize;
|
|
4922
4923
|
_noStem;
|
|
4923
4924
|
_from;
|
|
4924
|
-
constructor(noTokenize = { noTokenize: false }, noStem = { noStem: false },
|
|
4925
|
+
constructor(noTokenize = { noTokenize: false }, noStem = { noStem: false }, from = { from: null }) {
|
|
4925
4926
|
this._noTokenize = noTokenize;
|
|
4926
4927
|
this._noStem = noStem;
|
|
4927
|
-
this._from =
|
|
4928
|
+
this._from = from;
|
|
4928
4929
|
}
|
|
4929
4930
|
noTokenize() {
|
|
4930
4931
|
return new _TextFieldBuilder({ noTokenize: true }, this._noStem, this._from);
|
|
@@ -4947,9 +4948,9 @@ var init_nodejs = __esm({
|
|
|
4947
4948
|
NumericFieldBuilder = class _NumericFieldBuilder {
|
|
4948
4949
|
type;
|
|
4949
4950
|
_from;
|
|
4950
|
-
constructor(type,
|
|
4951
|
+
constructor(type, from = { from: null }) {
|
|
4951
4952
|
this.type = type;
|
|
4952
|
-
this._from =
|
|
4953
|
+
this._from = from;
|
|
4953
4954
|
}
|
|
4954
4955
|
from(field) {
|
|
4955
4956
|
return new _NumericFieldBuilder(this.type, { from: field });
|
|
@@ -4968,9 +4969,9 @@ var init_nodejs = __esm({
|
|
|
4968
4969
|
BoolFieldBuilder = class _BoolFieldBuilder {
|
|
4969
4970
|
_fast;
|
|
4970
4971
|
_from;
|
|
4971
|
-
constructor(fast = { fast: false },
|
|
4972
|
+
constructor(fast = { fast: false }, from = { from: null }) {
|
|
4972
4973
|
this._fast = fast;
|
|
4973
|
-
this._from =
|
|
4974
|
+
this._from = from;
|
|
4974
4975
|
}
|
|
4975
4976
|
fast() {
|
|
4976
4977
|
return new _BoolFieldBuilder({ fast: true }, this._from);
|
|
@@ -5006,9 +5007,9 @@ var init_nodejs = __esm({
|
|
|
5006
5007
|
DateFieldBuilder = class _DateFieldBuilder {
|
|
5007
5008
|
_fast;
|
|
5008
5009
|
_from;
|
|
5009
|
-
constructor(fast = { fast: false },
|
|
5010
|
+
constructor(fast = { fast: false }, from = { from: null }) {
|
|
5010
5011
|
this._fast = fast;
|
|
5011
|
-
this._from =
|
|
5012
|
+
this._from = from;
|
|
5012
5013
|
}
|
|
5013
5014
|
fast() {
|
|
5014
5015
|
return new _DateFieldBuilder({ fast: true }, this._from);
|
|
@@ -5191,1782 +5192,6 @@ var init_nodejs = __esm({
|
|
|
5191
5192
|
};
|
|
5192
5193
|
}
|
|
5193
5194
|
});
|
|
5194
|
-
|
|
5195
|
-
// ../checkpoint-wasm-runtime/dist/orchestrator.mjs
|
|
5196
|
-
var __defProp2 = Object.defineProperty;
|
|
5197
|
-
var __export2 = (target, all) => {
|
|
5198
|
-
for (var name in all)
|
|
5199
|
-
__defProp2(target, name, { get: all[name], enumerable: true });
|
|
5200
|
-
};
|
|
5201
|
-
var kya_os_engine_exports = {};
|
|
5202
|
-
__export2(kya_os_engine_exports, {
|
|
5203
|
-
default: () => kya_os_engine_default,
|
|
5204
|
-
initSync: () => initSync,
|
|
5205
|
-
verify: () => verify
|
|
5206
|
-
});
|
|
5207
|
-
function getUint8ArrayMemory0() {
|
|
5208
|
-
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
5209
|
-
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
5210
|
-
}
|
|
5211
|
-
return cachedUint8ArrayMemory0;
|
|
5212
|
-
}
|
|
5213
|
-
function decodeText(ptr, len) {
|
|
5214
|
-
numBytesDecoded += len;
|
|
5215
|
-
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
5216
|
-
cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
|
|
5217
|
-
cachedTextDecoder.decode();
|
|
5218
|
-
numBytesDecoded = len;
|
|
5219
|
-
}
|
|
5220
|
-
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
5221
|
-
}
|
|
5222
|
-
function getStringFromWasm0(ptr, len) {
|
|
5223
|
-
ptr = ptr >>> 0;
|
|
5224
|
-
return decodeText(ptr, len);
|
|
5225
|
-
}
|
|
5226
|
-
function addHeapObject(obj) {
|
|
5227
|
-
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
5228
|
-
const idx = heap_next;
|
|
5229
|
-
heap_next = heap[idx];
|
|
5230
|
-
heap[idx] = obj;
|
|
5231
|
-
return idx;
|
|
5232
|
-
}
|
|
5233
|
-
function getObject(idx) {
|
|
5234
|
-
return heap[idx];
|
|
5235
|
-
}
|
|
5236
|
-
function passStringToWasm0(arg, malloc, realloc) {
|
|
5237
|
-
if (realloc === void 0) {
|
|
5238
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
5239
|
-
const ptr2 = malloc(buf.length, 1) >>> 0;
|
|
5240
|
-
getUint8ArrayMemory0().subarray(ptr2, ptr2 + buf.length).set(buf);
|
|
5241
|
-
WASM_VECTOR_LEN = buf.length;
|
|
5242
|
-
return ptr2;
|
|
5243
|
-
}
|
|
5244
|
-
let len = arg.length;
|
|
5245
|
-
let ptr = malloc(len, 1) >>> 0;
|
|
5246
|
-
const mem = getUint8ArrayMemory0();
|
|
5247
|
-
let offset = 0;
|
|
5248
|
-
for (; offset < len; offset++) {
|
|
5249
|
-
const code = arg.charCodeAt(offset);
|
|
5250
|
-
if (code > 127) break;
|
|
5251
|
-
mem[ptr + offset] = code;
|
|
5252
|
-
}
|
|
5253
|
-
if (offset !== len) {
|
|
5254
|
-
if (offset !== 0) {
|
|
5255
|
-
arg = arg.slice(offset);
|
|
5256
|
-
}
|
|
5257
|
-
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
5258
|
-
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
5259
|
-
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
5260
|
-
offset += ret.written;
|
|
5261
|
-
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
5262
|
-
}
|
|
5263
|
-
WASM_VECTOR_LEN = offset;
|
|
5264
|
-
return ptr;
|
|
5265
|
-
}
|
|
5266
|
-
function getDataViewMemory0() {
|
|
5267
|
-
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || cachedDataViewMemory0.buffer.detached === void 0 && cachedDataViewMemory0.buffer !== wasm.memory.buffer) {
|
|
5268
|
-
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
5269
|
-
}
|
|
5270
|
-
return cachedDataViewMemory0;
|
|
5271
|
-
}
|
|
5272
|
-
function isLikeNone(x) {
|
|
5273
|
-
return x === void 0 || x === null;
|
|
5274
|
-
}
|
|
5275
|
-
function debugString(val) {
|
|
5276
|
-
const type = typeof val;
|
|
5277
|
-
if (type == "number" || type == "boolean" || val == null) {
|
|
5278
|
-
return `${val}`;
|
|
5279
|
-
}
|
|
5280
|
-
if (type == "string") {
|
|
5281
|
-
return `"${val}"`;
|
|
5282
|
-
}
|
|
5283
|
-
if (type == "symbol") {
|
|
5284
|
-
const description = val.description;
|
|
5285
|
-
if (description == null) {
|
|
5286
|
-
return "Symbol";
|
|
5287
|
-
} else {
|
|
5288
|
-
return `Symbol(${description})`;
|
|
5289
|
-
}
|
|
5290
|
-
}
|
|
5291
|
-
if (type == "function") {
|
|
5292
|
-
const name = val.name;
|
|
5293
|
-
if (typeof name == "string" && name.length > 0) {
|
|
5294
|
-
return `Function(${name})`;
|
|
5295
|
-
} else {
|
|
5296
|
-
return "Function";
|
|
5297
|
-
}
|
|
5298
|
-
}
|
|
5299
|
-
if (Array.isArray(val)) {
|
|
5300
|
-
const length = val.length;
|
|
5301
|
-
let debug = "[";
|
|
5302
|
-
if (length > 0) {
|
|
5303
|
-
debug += debugString(val[0]);
|
|
5304
|
-
}
|
|
5305
|
-
for (let i = 1; i < length; i++) {
|
|
5306
|
-
debug += ", " + debugString(val[i]);
|
|
5307
|
-
}
|
|
5308
|
-
debug += "]";
|
|
5309
|
-
return debug;
|
|
5310
|
-
}
|
|
5311
|
-
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
5312
|
-
let className;
|
|
5313
|
-
if (builtInMatches && builtInMatches.length > 1) {
|
|
5314
|
-
className = builtInMatches[1];
|
|
5315
|
-
} else {
|
|
5316
|
-
return toString.call(val);
|
|
5317
|
-
}
|
|
5318
|
-
if (className == "Object") {
|
|
5319
|
-
try {
|
|
5320
|
-
return "Object(" + JSON.stringify(val) + ")";
|
|
5321
|
-
} catch (_) {
|
|
5322
|
-
return "Object";
|
|
5323
|
-
}
|
|
5324
|
-
}
|
|
5325
|
-
if (val instanceof Error) {
|
|
5326
|
-
return `${val.name}: ${val.message}
|
|
5327
|
-
${val.stack}`;
|
|
5328
|
-
}
|
|
5329
|
-
return className;
|
|
5330
|
-
}
|
|
5331
|
-
function handleError(f, args) {
|
|
5332
|
-
try {
|
|
5333
|
-
return f.apply(this, args);
|
|
5334
|
-
} catch (e) {
|
|
5335
|
-
wasm.__wbindgen_export3(addHeapObject(e));
|
|
5336
|
-
}
|
|
5337
|
-
}
|
|
5338
|
-
function getArrayU8FromWasm0(ptr, len) {
|
|
5339
|
-
ptr = ptr >>> 0;
|
|
5340
|
-
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
5341
|
-
}
|
|
5342
|
-
function dropObject(idx) {
|
|
5343
|
-
if (idx < 132) return;
|
|
5344
|
-
heap[idx] = heap_next;
|
|
5345
|
-
heap_next = idx;
|
|
5346
|
-
}
|
|
5347
|
-
function takeObject(idx) {
|
|
5348
|
-
const ret = getObject(idx);
|
|
5349
|
-
dropObject(idx);
|
|
5350
|
-
return ret;
|
|
5351
|
-
}
|
|
5352
|
-
function verify(input_js, ctx_js) {
|
|
5353
|
-
try {
|
|
5354
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
5355
|
-
wasm.verify(retptr, addHeapObject(input_js), addHeapObject(ctx_js));
|
|
5356
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
5357
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
5358
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
5359
|
-
if (r2) {
|
|
5360
|
-
throw takeObject(r1);
|
|
5361
|
-
}
|
|
5362
|
-
return takeObject(r0);
|
|
5363
|
-
} finally {
|
|
5364
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
5365
|
-
}
|
|
5366
|
-
}
|
|
5367
|
-
function __wbg_get_imports() {
|
|
5368
|
-
const imports = {};
|
|
5369
|
-
imports.wbg = {};
|
|
5370
|
-
imports.wbg.__wbg_Error_e83987f665cf5504 = function(arg0, arg1) {
|
|
5371
|
-
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
5372
|
-
return addHeapObject(ret);
|
|
5373
|
-
};
|
|
5374
|
-
imports.wbg.__wbg_Number_bb48ca12f395cd08 = function(arg0) {
|
|
5375
|
-
const ret = Number(getObject(arg0));
|
|
5376
|
-
return ret;
|
|
5377
|
-
};
|
|
5378
|
-
imports.wbg.__wbg_String_8f0eb39a4a4c2f66 = function(arg0, arg1) {
|
|
5379
|
-
const ret = String(getObject(arg1));
|
|
5380
|
-
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
5381
|
-
const len1 = WASM_VECTOR_LEN;
|
|
5382
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
5383
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
5384
|
-
};
|
|
5385
|
-
imports.wbg.__wbg___wbindgen_bigint_get_as_i64_f3ebc5a755000afd = function(arg0, arg1) {
|
|
5386
|
-
const v = getObject(arg1);
|
|
5387
|
-
const ret = typeof v === "bigint" ? v : void 0;
|
|
5388
|
-
getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
|
|
5389
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
5390
|
-
};
|
|
5391
|
-
imports.wbg.__wbg___wbindgen_boolean_get_6d5a1ee65bab5f68 = function(arg0) {
|
|
5392
|
-
const v = getObject(arg0);
|
|
5393
|
-
const ret = typeof v === "boolean" ? v : void 0;
|
|
5394
|
-
return isLikeNone(ret) ? 16777215 : ret ? 1 : 0;
|
|
5395
|
-
};
|
|
5396
|
-
imports.wbg.__wbg___wbindgen_debug_string_df47ffb5e35e6763 = function(arg0, arg1) {
|
|
5397
|
-
const ret = debugString(getObject(arg1));
|
|
5398
|
-
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
5399
|
-
const len1 = WASM_VECTOR_LEN;
|
|
5400
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
5401
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
5402
|
-
};
|
|
5403
|
-
imports.wbg.__wbg___wbindgen_in_bb933bd9e1b3bc0f = function(arg0, arg1) {
|
|
5404
|
-
const ret = getObject(arg0) in getObject(arg1);
|
|
5405
|
-
return ret;
|
|
5406
|
-
};
|
|
5407
|
-
imports.wbg.__wbg___wbindgen_is_bigint_cb320707dcd35f0b = function(arg0) {
|
|
5408
|
-
const ret = typeof getObject(arg0) === "bigint";
|
|
5409
|
-
return ret;
|
|
5410
|
-
};
|
|
5411
|
-
imports.wbg.__wbg___wbindgen_is_function_ee8a6c5833c90377 = function(arg0) {
|
|
5412
|
-
const ret = typeof getObject(arg0) === "function";
|
|
5413
|
-
return ret;
|
|
5414
|
-
};
|
|
5415
|
-
imports.wbg.__wbg___wbindgen_is_object_c818261d21f283a4 = function(arg0) {
|
|
5416
|
-
const val = getObject(arg0);
|
|
5417
|
-
const ret = typeof val === "object" && val !== null;
|
|
5418
|
-
return ret;
|
|
5419
|
-
};
|
|
5420
|
-
imports.wbg.__wbg___wbindgen_is_string_fbb76cb2940daafd = function(arg0) {
|
|
5421
|
-
const ret = typeof getObject(arg0) === "string";
|
|
5422
|
-
return ret;
|
|
5423
|
-
};
|
|
5424
|
-
imports.wbg.__wbg___wbindgen_is_undefined_2d472862bd29a478 = function(arg0) {
|
|
5425
|
-
const ret = getObject(arg0) === void 0;
|
|
5426
|
-
return ret;
|
|
5427
|
-
};
|
|
5428
|
-
imports.wbg.__wbg___wbindgen_jsval_eq_6b13ab83478b1c50 = function(arg0, arg1) {
|
|
5429
|
-
const ret = getObject(arg0) === getObject(arg1);
|
|
5430
|
-
return ret;
|
|
5431
|
-
};
|
|
5432
|
-
imports.wbg.__wbg___wbindgen_jsval_loose_eq_b664b38a2f582147 = function(arg0, arg1) {
|
|
5433
|
-
const ret = getObject(arg0) == getObject(arg1);
|
|
5434
|
-
return ret;
|
|
5435
|
-
};
|
|
5436
|
-
imports.wbg.__wbg___wbindgen_number_get_a20bf9b85341449d = function(arg0, arg1) {
|
|
5437
|
-
const obj = getObject(arg1);
|
|
5438
|
-
const ret = typeof obj === "number" ? obj : void 0;
|
|
5439
|
-
getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
|
|
5440
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
5441
|
-
};
|
|
5442
|
-
imports.wbg.__wbg___wbindgen_string_get_e4f06c90489ad01b = function(arg0, arg1) {
|
|
5443
|
-
const obj = getObject(arg1);
|
|
5444
|
-
const ret = typeof obj === "string" ? obj : void 0;
|
|
5445
|
-
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
5446
|
-
var len1 = WASM_VECTOR_LEN;
|
|
5447
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
5448
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
5449
|
-
};
|
|
5450
|
-
imports.wbg.__wbg___wbindgen_throw_b855445ff6a94295 = function(arg0, arg1) {
|
|
5451
|
-
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
5452
|
-
};
|
|
5453
|
-
imports.wbg.__wbg_call_e762c39fa8ea36bf = function() {
|
|
5454
|
-
return handleError(function(arg0, arg1) {
|
|
5455
|
-
const ret = getObject(arg0).call(getObject(arg1));
|
|
5456
|
-
return addHeapObject(ret);
|
|
5457
|
-
}, arguments);
|
|
5458
|
-
};
|
|
5459
|
-
imports.wbg.__wbg_done_2042aa2670fb1db1 = function(arg0) {
|
|
5460
|
-
const ret = getObject(arg0).done;
|
|
5461
|
-
return ret;
|
|
5462
|
-
};
|
|
5463
|
-
imports.wbg.__wbg_entries_e171b586f8f6bdbf = function(arg0) {
|
|
5464
|
-
const ret = Object.entries(getObject(arg0));
|
|
5465
|
-
return addHeapObject(ret);
|
|
5466
|
-
};
|
|
5467
|
-
imports.wbg.__wbg_get_7bed016f185add81 = function(arg0, arg1) {
|
|
5468
|
-
const ret = getObject(arg0)[arg1 >>> 0];
|
|
5469
|
-
return addHeapObject(ret);
|
|
5470
|
-
};
|
|
5471
|
-
imports.wbg.__wbg_get_efcb449f58ec27c2 = function() {
|
|
5472
|
-
return handleError(function(arg0, arg1) {
|
|
5473
|
-
const ret = Reflect.get(getObject(arg0), getObject(arg1));
|
|
5474
|
-
return addHeapObject(ret);
|
|
5475
|
-
}, arguments);
|
|
5476
|
-
};
|
|
5477
|
-
imports.wbg.__wbg_get_with_ref_key_1dc361bd10053bfe = function(arg0, arg1) {
|
|
5478
|
-
const ret = getObject(arg0)[getObject(arg1)];
|
|
5479
|
-
return addHeapObject(ret);
|
|
5480
|
-
};
|
|
5481
|
-
imports.wbg.__wbg_instanceof_ArrayBuffer_70beb1189ca63b38 = function(arg0) {
|
|
5482
|
-
let result;
|
|
5483
|
-
try {
|
|
5484
|
-
result = getObject(arg0) instanceof ArrayBuffer;
|
|
5485
|
-
} catch (_) {
|
|
5486
|
-
result = false;
|
|
5487
|
-
}
|
|
5488
|
-
const ret = result;
|
|
5489
|
-
return ret;
|
|
5490
|
-
};
|
|
5491
|
-
imports.wbg.__wbg_instanceof_Map_8579b5e2ab5437c7 = function(arg0) {
|
|
5492
|
-
let result;
|
|
5493
|
-
try {
|
|
5494
|
-
result = getObject(arg0) instanceof Map;
|
|
5495
|
-
} catch (_) {
|
|
5496
|
-
result = false;
|
|
5497
|
-
}
|
|
5498
|
-
const ret = result;
|
|
5499
|
-
return ret;
|
|
5500
|
-
};
|
|
5501
|
-
imports.wbg.__wbg_instanceof_Uint8Array_20c8e73002f7af98 = function(arg0) {
|
|
5502
|
-
let result;
|
|
5503
|
-
try {
|
|
5504
|
-
result = getObject(arg0) instanceof Uint8Array;
|
|
5505
|
-
} catch (_) {
|
|
5506
|
-
result = false;
|
|
5507
|
-
}
|
|
5508
|
-
const ret = result;
|
|
5509
|
-
return ret;
|
|
5510
|
-
};
|
|
5511
|
-
imports.wbg.__wbg_isArray_96e0af9891d0945d = function(arg0) {
|
|
5512
|
-
const ret = Array.isArray(getObject(arg0));
|
|
5513
|
-
return ret;
|
|
5514
|
-
};
|
|
5515
|
-
imports.wbg.__wbg_isSafeInteger_d216eda7911dde36 = function(arg0) {
|
|
5516
|
-
const ret = Number.isSafeInteger(getObject(arg0));
|
|
5517
|
-
return ret;
|
|
5518
|
-
};
|
|
5519
|
-
imports.wbg.__wbg_iterator_e5822695327a3c39 = function() {
|
|
5520
|
-
const ret = Symbol.iterator;
|
|
5521
|
-
return addHeapObject(ret);
|
|
5522
|
-
};
|
|
5523
|
-
imports.wbg.__wbg_length_69bca3cb64fc8748 = function(arg0) {
|
|
5524
|
-
const ret = getObject(arg0).length;
|
|
5525
|
-
return ret;
|
|
5526
|
-
};
|
|
5527
|
-
imports.wbg.__wbg_length_cdd215e10d9dd507 = function(arg0) {
|
|
5528
|
-
const ret = getObject(arg0).length;
|
|
5529
|
-
return ret;
|
|
5530
|
-
};
|
|
5531
|
-
imports.wbg.__wbg_new_1acc0b6eea89d040 = function() {
|
|
5532
|
-
const ret = new Object();
|
|
5533
|
-
return addHeapObject(ret);
|
|
5534
|
-
};
|
|
5535
|
-
imports.wbg.__wbg_new_5a79be3ab53b8aa5 = function(arg0) {
|
|
5536
|
-
const ret = new Uint8Array(getObject(arg0));
|
|
5537
|
-
return addHeapObject(ret);
|
|
5538
|
-
};
|
|
5539
|
-
imports.wbg.__wbg_new_68651c719dcda04e = function() {
|
|
5540
|
-
const ret = /* @__PURE__ */ new Map();
|
|
5541
|
-
return addHeapObject(ret);
|
|
5542
|
-
};
|
|
5543
|
-
imports.wbg.__wbg_new_e17d9f43105b08be = function() {
|
|
5544
|
-
const ret = new Array();
|
|
5545
|
-
return addHeapObject(ret);
|
|
5546
|
-
};
|
|
5547
|
-
imports.wbg.__wbg_next_020810e0ae8ebcb0 = function() {
|
|
5548
|
-
return handleError(function(arg0) {
|
|
5549
|
-
const ret = getObject(arg0).next();
|
|
5550
|
-
return addHeapObject(ret);
|
|
5551
|
-
}, arguments);
|
|
5552
|
-
};
|
|
5553
|
-
imports.wbg.__wbg_next_2c826fe5dfec6b6a = function(arg0) {
|
|
5554
|
-
const ret = getObject(arg0).next;
|
|
5555
|
-
return addHeapObject(ret);
|
|
5556
|
-
};
|
|
5557
|
-
imports.wbg.__wbg_prototypesetcall_2a6620b6922694b2 = function(arg0, arg1, arg2) {
|
|
5558
|
-
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
|
|
5559
|
-
};
|
|
5560
|
-
imports.wbg.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
|
|
5561
|
-
getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
|
|
5562
|
-
};
|
|
5563
|
-
imports.wbg.__wbg_set_907fb406c34a251d = function(arg0, arg1, arg2) {
|
|
5564
|
-
const ret = getObject(arg0).set(getObject(arg1), getObject(arg2));
|
|
5565
|
-
return addHeapObject(ret);
|
|
5566
|
-
};
|
|
5567
|
-
imports.wbg.__wbg_set_c213c871859d6500 = function(arg0, arg1, arg2) {
|
|
5568
|
-
getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
|
|
5569
|
-
};
|
|
5570
|
-
imports.wbg.__wbg_value_692627309814bb8c = function(arg0) {
|
|
5571
|
-
const ret = getObject(arg0).value;
|
|
5572
|
-
return addHeapObject(ret);
|
|
5573
|
-
};
|
|
5574
|
-
imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
|
|
5575
|
-
const ret = getStringFromWasm0(arg0, arg1);
|
|
5576
|
-
return addHeapObject(ret);
|
|
5577
|
-
};
|
|
5578
|
-
imports.wbg.__wbindgen_cast_4625c577ab2ec9ee = function(arg0) {
|
|
5579
|
-
const ret = BigInt.asUintN(64, arg0);
|
|
5580
|
-
return addHeapObject(ret);
|
|
5581
|
-
};
|
|
5582
|
-
imports.wbg.__wbindgen_cast_9ae0607507abb057 = function(arg0) {
|
|
5583
|
-
const ret = arg0;
|
|
5584
|
-
return addHeapObject(ret);
|
|
5585
|
-
};
|
|
5586
|
-
imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
|
|
5587
|
-
const ret = arg0;
|
|
5588
|
-
return addHeapObject(ret);
|
|
5589
|
-
};
|
|
5590
|
-
imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
|
|
5591
|
-
const ret = getObject(arg0);
|
|
5592
|
-
return addHeapObject(ret);
|
|
5593
|
-
};
|
|
5594
|
-
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
|
|
5595
|
-
takeObject(arg0);
|
|
5596
|
-
};
|
|
5597
|
-
return imports;
|
|
5598
|
-
}
|
|
5599
|
-
function __wbg_finalize_init(instance, module) {
|
|
5600
|
-
wasm = instance.exports;
|
|
5601
|
-
cachedDataViewMemory0 = null;
|
|
5602
|
-
cachedUint8ArrayMemory0 = null;
|
|
5603
|
-
return wasm;
|
|
5604
|
-
}
|
|
5605
|
-
function initSync(module) {
|
|
5606
|
-
if (wasm !== void 0) return wasm;
|
|
5607
|
-
if (typeof module !== "undefined") {
|
|
5608
|
-
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
5609
|
-
({ module } = module);
|
|
5610
|
-
} else {
|
|
5611
|
-
console.warn("using deprecated parameters for `initSync()`; pass a single object instead");
|
|
5612
|
-
}
|
|
5613
|
-
}
|
|
5614
|
-
const imports = __wbg_get_imports();
|
|
5615
|
-
if (!(module instanceof WebAssembly.Module)) {
|
|
5616
|
-
module = new WebAssembly.Module(module);
|
|
5617
|
-
}
|
|
5618
|
-
const instance = new WebAssembly.Instance(module, imports);
|
|
5619
|
-
return __wbg_finalize_init(instance);
|
|
5620
|
-
}
|
|
5621
|
-
var wasm;
|
|
5622
|
-
var cachedUint8ArrayMemory0;
|
|
5623
|
-
var cachedTextDecoder;
|
|
5624
|
-
var MAX_SAFARI_DECODE_BYTES;
|
|
5625
|
-
var numBytesDecoded;
|
|
5626
|
-
var heap;
|
|
5627
|
-
var heap_next;
|
|
5628
|
-
var WASM_VECTOR_LEN;
|
|
5629
|
-
var cachedTextEncoder;
|
|
5630
|
-
var cachedDataViewMemory0;
|
|
5631
|
-
var kya_os_engine_default;
|
|
5632
|
-
var BLOCKED_HOSTNAMES = /* @__PURE__ */ new Set(["localhost", "metadata", "metadata.google.internal"]);
|
|
5633
|
-
var UnsafeOutboundUrl = class extends Error {
|
|
5634
|
-
kind = "UnsafeOutboundUrl";
|
|
5635
|
-
};
|
|
5636
|
-
function assertSafeHttpsUrl(rawUrl, label = "outbound URL") {
|
|
5637
|
-
let parsed;
|
|
5638
|
-
try {
|
|
5639
|
-
parsed = new URL(rawUrl);
|
|
5640
|
-
} catch {
|
|
5641
|
-
throw new UnsafeOutboundUrl(`${label} must be a valid URL: ${rawUrl}`);
|
|
5642
|
-
}
|
|
5643
|
-
if (parsed.protocol !== "https:") {
|
|
5644
|
-
throw new UnsafeOutboundUrl(`${label} must use https: ${rawUrl}`);
|
|
5645
|
-
}
|
|
5646
|
-
if (parsed.username || parsed.password) {
|
|
5647
|
-
throw new UnsafeOutboundUrl(`${label} must not contain credentials: ${rawUrl}`);
|
|
5648
|
-
}
|
|
5649
|
-
const hostname = normalizeHostname(parsed.hostname);
|
|
5650
|
-
if (!hostname || isBlockedHostname(hostname)) {
|
|
5651
|
-
throw new UnsafeOutboundUrl(`${label} targets a local or private host: ${rawUrl}`);
|
|
5652
|
-
}
|
|
5653
|
-
return rawUrl;
|
|
5654
|
-
}
|
|
5655
|
-
function normalizeHostname(hostname) {
|
|
5656
|
-
let normalized = hostname.trim().toLowerCase();
|
|
5657
|
-
if (normalized.startsWith("[") && normalized.endsWith("]")) {
|
|
5658
|
-
normalized = normalized.slice(1, -1);
|
|
5659
|
-
}
|
|
5660
|
-
while (normalized.endsWith(".")) {
|
|
5661
|
-
normalized = normalized.slice(0, -1);
|
|
5662
|
-
}
|
|
5663
|
-
return normalized;
|
|
5664
|
-
}
|
|
5665
|
-
function isBlockedHostname(hostname) {
|
|
5666
|
-
if (BLOCKED_HOSTNAMES.has(hostname) || hostname.endsWith(".localhost")) {
|
|
5667
|
-
return true;
|
|
5668
|
-
}
|
|
5669
|
-
const ipv4 = parseIpv4(hostname);
|
|
5670
|
-
if (ipv4) {
|
|
5671
|
-
return isBlockedIpv4(ipv4);
|
|
5672
|
-
}
|
|
5673
|
-
return isBlockedIpv6(hostname);
|
|
5674
|
-
}
|
|
5675
|
-
function parseIpv4(hostname) {
|
|
5676
|
-
const parts = hostname.split(".");
|
|
5677
|
-
if (parts.length !== 4) return null;
|
|
5678
|
-
const octets = parts.map((part) => {
|
|
5679
|
-
if (!/^\d{1,3}$/.test(part)) return Number.NaN;
|
|
5680
|
-
const value = Number(part);
|
|
5681
|
-
return value >= 0 && value <= 255 ? value : Number.NaN;
|
|
5682
|
-
});
|
|
5683
|
-
if (octets.some(Number.isNaN)) return null;
|
|
5684
|
-
return octets;
|
|
5685
|
-
}
|
|
5686
|
-
function isBlockedIpv4([a, b]) {
|
|
5687
|
-
return a === 0 || a === 10 || a === 127 || a === 100 && b >= 64 && b <= 127 || a === 169 && b === 254 || a === 172 && b >= 16 && b <= 31 || a === 192 && b === 168 || a === 198 && (b === 18 || b === 19) || a >= 224;
|
|
5688
|
-
}
|
|
5689
|
-
function isBlockedIpv6(hostname) {
|
|
5690
|
-
if (!hostname.includes(":")) return false;
|
|
5691
|
-
const ipv4Mapped = hostname.match(/(?:^|:)ffff:(\d{1,3}(?:\.\d{1,3}){3})$/);
|
|
5692
|
-
if (ipv4Mapped) {
|
|
5693
|
-
const ipv4 = parseIpv4(ipv4Mapped[1]);
|
|
5694
|
-
return ipv4 ? isBlockedIpv4(ipv4) : true;
|
|
5695
|
-
}
|
|
5696
|
-
if (hostname === "::" || hostname === "::1" || hostname === "0:0:0:0:0:0:0:1") {
|
|
5697
|
-
return true;
|
|
5698
|
-
}
|
|
5699
|
-
const firstSegment = Number.parseInt(hostname.split(":")[0] || "0", 16);
|
|
5700
|
-
if (Number.isNaN(firstSegment)) return true;
|
|
5701
|
-
return (firstSegment & 65024) === 64512 || // unique local fc00::/7
|
|
5702
|
-
(firstSegment & 65472) === 65152 || // link-local fe80::/10
|
|
5703
|
-
(firstSegment & 65280) === 65280;
|
|
5704
|
-
}
|
|
5705
|
-
function engineVerify(input, ctx) {
|
|
5706
|
-
const result = (void 0)(input, ctx);
|
|
5707
|
-
return result;
|
|
5708
|
-
}
|
|
5709
|
-
function base64UrlDecode(input) {
|
|
5710
|
-
const padded = input.replace(/-/g, "+").replace(/_/g, "/");
|
|
5711
|
-
const padding = padded.length % 4 === 0 ? "" : "=".repeat(4 - padded.length % 4);
|
|
5712
|
-
return new Uint8Array(Buffer.from(padded + padding, "base64"));
|
|
5713
|
-
}
|
|
5714
|
-
function buildAgentRequest(req, opts = {}) {
|
|
5715
|
-
const mcpI = tryBuildMcpIFromBody(req);
|
|
5716
|
-
if (mcpI) {
|
|
5717
|
-
return { protocol: "McpI", request: mcpI };
|
|
5718
|
-
}
|
|
5719
|
-
if (opts.legacyEnvelopeFallback) {
|
|
5720
|
-
const legacyMcpI = tryBuildMcpIFromLegacyHeader(req);
|
|
5721
|
-
if (legacyMcpI) {
|
|
5722
|
-
return { protocol: "McpI", request: legacyMcpI };
|
|
5723
|
-
}
|
|
5724
|
-
}
|
|
5725
|
-
if (getHeader(req, "signature-input")) {
|
|
5726
|
-
return { protocol: "HttpSigned", request: buildHttpSigned(req) };
|
|
5727
|
-
}
|
|
5728
|
-
return { protocol: "PlainHttp", request: buildPlainHttp(req) };
|
|
5729
|
-
}
|
|
5730
|
-
function hasMalformedJwsBody(req) {
|
|
5731
|
-
const parsed = parseBodyAsObject(req.body);
|
|
5732
|
-
if (!parsed || typeof parsed !== "object") return false;
|
|
5733
|
-
const meta = parsed._meta;
|
|
5734
|
-
if (!meta || typeof meta !== "object") return false;
|
|
5735
|
-
const proof = meta.proof;
|
|
5736
|
-
if (!proof || typeof proof !== "object") return false;
|
|
5737
|
-
const jws = proof.jws;
|
|
5738
|
-
if (typeof jws !== "string" || jws.length === 0) return false;
|
|
5739
|
-
const raw = Array.from(Buffer.from(jws, "utf8"));
|
|
5740
|
-
return parseJwsPayloadStruct(raw) === null;
|
|
5741
|
-
}
|
|
5742
|
-
function extractIssuer(request) {
|
|
5743
|
-
if (request.protocol === "McpI") return request.request.payload.iss || null;
|
|
5744
|
-
return null;
|
|
5745
|
-
}
|
|
5746
|
-
function extractAgentDid(request) {
|
|
5747
|
-
if (request.protocol === "McpI") return request.request.payload.sub || null;
|
|
5748
|
-
return null;
|
|
5749
|
-
}
|
|
5750
|
-
function extractCredentialStatusUrl(request) {
|
|
5751
|
-
if (request.protocol !== "McpI") return null;
|
|
5752
|
-
const raw = decodeJwsPayloadJson(request.request.raw);
|
|
5753
|
-
if (!raw) return null;
|
|
5754
|
-
const vc = raw.vc;
|
|
5755
|
-
if (!vc || typeof vc !== "object") return null;
|
|
5756
|
-
const credentialStatus = vc.credentialStatus;
|
|
5757
|
-
if (!credentialStatus || typeof credentialStatus !== "object") return null;
|
|
5758
|
-
const id = credentialStatus.id;
|
|
5759
|
-
return typeof id === "string" ? id : null;
|
|
5760
|
-
}
|
|
5761
|
-
function tryBuildMcpIFromBody(req) {
|
|
5762
|
-
const parsed = parseBodyAsObject(req.body);
|
|
5763
|
-
if (!parsed) return null;
|
|
5764
|
-
const meta = parsed._meta;
|
|
5765
|
-
if (!meta || typeof meta !== "object") return null;
|
|
5766
|
-
const proof = meta.proof;
|
|
5767
|
-
if (!proof || typeof proof !== "object") return null;
|
|
5768
|
-
const jws = proof.jws;
|
|
5769
|
-
if (typeof jws !== "string" || jws.length === 0) return null;
|
|
5770
|
-
const raw = Array.from(Buffer.from(jws, "utf8"));
|
|
5771
|
-
const payload = parseJwsPayloadStruct(raw);
|
|
5772
|
-
if (!payload) return null;
|
|
5773
|
-
return { raw, payload };
|
|
5774
|
-
}
|
|
5775
|
-
function parseBodyAsObject(body) {
|
|
5776
|
-
if (!body) return null;
|
|
5777
|
-
if (Buffer.isBuffer(body)) {
|
|
5778
|
-
try {
|
|
5779
|
-
return JSON.parse(body.toString("utf8"));
|
|
5780
|
-
} catch {
|
|
5781
|
-
return null;
|
|
5782
|
-
}
|
|
5783
|
-
}
|
|
5784
|
-
if (typeof body === "string") {
|
|
5785
|
-
try {
|
|
5786
|
-
return JSON.parse(body);
|
|
5787
|
-
} catch {
|
|
5788
|
-
return null;
|
|
5789
|
-
}
|
|
5790
|
-
}
|
|
5791
|
-
if (typeof body === "object") return body;
|
|
5792
|
-
return null;
|
|
5793
|
-
}
|
|
5794
|
-
function tryBuildMcpIFromLegacyHeader(req) {
|
|
5795
|
-
const header = getHeader(req, "kya-delegation");
|
|
5796
|
-
if (!header) return null;
|
|
5797
|
-
let parsed;
|
|
5798
|
-
try {
|
|
5799
|
-
parsed = JSON.parse(header);
|
|
5800
|
-
} catch {
|
|
5801
|
-
return null;
|
|
5802
|
-
}
|
|
5803
|
-
if (!parsed || typeof parsed !== "object") return null;
|
|
5804
|
-
const obj = parsed;
|
|
5805
|
-
const protectedSeg = obj.protected;
|
|
5806
|
-
const payloadSeg = obj.payload;
|
|
5807
|
-
const signatureSeg = obj.signature;
|
|
5808
|
-
if (typeof protectedSeg !== "string" || typeof payloadSeg !== "string" || typeof signatureSeg !== "string") {
|
|
5809
|
-
return null;
|
|
5810
|
-
}
|
|
5811
|
-
const compact = `${protectedSeg}.${payloadSeg}.${signatureSeg}`;
|
|
5812
|
-
const raw = Array.from(Buffer.from(compact, "utf8"));
|
|
5813
|
-
const payload = parseJwsPayloadStruct(raw);
|
|
5814
|
-
if (!payload) return null;
|
|
5815
|
-
return { raw, payload };
|
|
5816
|
-
}
|
|
5817
|
-
function parseJwsPayloadStruct(rawBytes) {
|
|
5818
|
-
const json = decodeJwsPayloadJson(rawBytes);
|
|
5819
|
-
if (!json || typeof json !== "object") return null;
|
|
5820
|
-
return projectMcpIPayload(json);
|
|
5821
|
-
}
|
|
5822
|
-
function decodeJwsPayloadJson(rawBytes) {
|
|
5823
|
-
const text = Buffer.from(rawBytes).toString("utf8");
|
|
5824
|
-
const segments = text.split(".");
|
|
5825
|
-
if (segments.length !== 3) return null;
|
|
5826
|
-
let decoded;
|
|
5827
|
-
try {
|
|
5828
|
-
decoded = base64UrlDecode(segments[1]);
|
|
5829
|
-
} catch {
|
|
5830
|
-
return null;
|
|
5831
|
-
}
|
|
5832
|
-
try {
|
|
5833
|
-
return JSON.parse(Buffer.from(decoded).toString("utf8"));
|
|
5834
|
-
} catch {
|
|
5835
|
-
return null;
|
|
5836
|
-
}
|
|
5837
|
-
}
|
|
5838
|
-
function projectMcpIPayload(raw) {
|
|
5839
|
-
const aud = raw.aud;
|
|
5840
|
-
const iss = raw.iss;
|
|
5841
|
-
const sub = raw.sub;
|
|
5842
|
-
const nonce = raw.nonce;
|
|
5843
|
-
const sessionId = raw.sessionId;
|
|
5844
|
-
const ts = raw.ts;
|
|
5845
|
-
const requestHash = raw.requestHash;
|
|
5846
|
-
const responseHash = raw.responseHash;
|
|
5847
|
-
if (typeof aud !== "string" || typeof iss !== "string" || typeof sub !== "string" || typeof nonce !== "string" || typeof sessionId !== "string" || typeof ts !== "number" || typeof requestHash !== "string" || typeof responseHash !== "string") {
|
|
5848
|
-
return null;
|
|
5849
|
-
}
|
|
5850
|
-
return { aud, iss, sub, nonce, sessionId, ts, requestHash, responseHash };
|
|
5851
|
-
}
|
|
5852
|
-
function buildHttpSigned(req) {
|
|
5853
|
-
return {
|
|
5854
|
-
raw: bodyAsBytes(req.body),
|
|
5855
|
-
method: req.method,
|
|
5856
|
-
path: req.url,
|
|
5857
|
-
headers: flattenHeaders(req.headers)
|
|
5858
|
-
};
|
|
5859
|
-
}
|
|
5860
|
-
function buildPlainHttp(req) {
|
|
5861
|
-
return {
|
|
5862
|
-
raw: bodyAsBytes(req.body),
|
|
5863
|
-
method: req.method,
|
|
5864
|
-
path: req.url,
|
|
5865
|
-
headers: flattenHeaders(req.headers),
|
|
5866
|
-
userAgent: getHeader(req, "user-agent") ?? null,
|
|
5867
|
-
remoteIp: req.remoteAddress ?? null
|
|
5868
|
-
};
|
|
5869
|
-
}
|
|
5870
|
-
function getHeader(req, name) {
|
|
5871
|
-
const lowered = name.toLowerCase();
|
|
5872
|
-
for (const [key, value] of Object.entries(req.headers)) {
|
|
5873
|
-
if (key.toLowerCase() !== lowered) continue;
|
|
5874
|
-
if (Array.isArray(value)) return value[0] ?? null;
|
|
5875
|
-
if (typeof value === "string") return value;
|
|
5876
|
-
}
|
|
5877
|
-
return null;
|
|
5878
|
-
}
|
|
5879
|
-
function flattenHeaders(headers) {
|
|
5880
|
-
const out = [];
|
|
5881
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
5882
|
-
if (value === void 0) continue;
|
|
5883
|
-
if (Array.isArray(value)) {
|
|
5884
|
-
for (const v of value) out.push([key, v]);
|
|
5885
|
-
} else {
|
|
5886
|
-
out.push([key, value]);
|
|
5887
|
-
}
|
|
5888
|
-
}
|
|
5889
|
-
return out;
|
|
5890
|
-
}
|
|
5891
|
-
function bodyAsBytes(body) {
|
|
5892
|
-
if (!body) return [];
|
|
5893
|
-
if (Buffer.isBuffer(body)) return Array.from(body);
|
|
5894
|
-
if (typeof body === "string") return Array.from(Buffer.from(body, "utf8"));
|
|
5895
|
-
if (typeof body === "object") return Array.from(Buffer.from(JSON.stringify(body), "utf8"));
|
|
5896
|
-
return [];
|
|
5897
|
-
}
|
|
5898
|
-
var DEFAULT_REPUTATION_BASELINE = 1;
|
|
5899
|
-
async function verifyRequest(req, opts) {
|
|
5900
|
-
return verifyRequest_internal(req, opts);
|
|
5901
|
-
}
|
|
5902
|
-
async function verifyRequest_internal(req, opts) {
|
|
5903
|
-
if (hasMalformedJwsBody(req)) {
|
|
5904
|
-
return blockWithParseError("malformed JWS body", opts.enforcementMode);
|
|
5905
|
-
}
|
|
5906
|
-
const agentRequest = buildAgentRequest(req, {
|
|
5907
|
-
legacyEnvelopeFallback: opts.legacyEnvelopeFallback
|
|
5908
|
-
});
|
|
5909
|
-
const issuer = extractIssuer(agentRequest);
|
|
5910
|
-
const agentDid = extractAgentDid(agentRequest);
|
|
5911
|
-
const credentialStatusUrl = extractCredentialStatusUrl(agentRequest);
|
|
5912
|
-
const baseline = opts.reputationBaseline ?? DEFAULT_REPUTATION_BASELINE;
|
|
5913
|
-
const [didResult, statusResult, repResult] = await Promise.allSettled([
|
|
5914
|
-
issuer ? opts.didResolver.resolve(issuer) : Promise.resolve(null),
|
|
5915
|
-
credentialStatusUrl ? fetchCredentialStatus(credentialStatusUrl, opts.statusListCache) : Promise.resolve(null),
|
|
5916
|
-
agentDid ? opts.reputationOracle.score(agentDid) : Promise.resolve(baseline)
|
|
5917
|
-
]);
|
|
5918
|
-
if (didResult.status === "rejected") {
|
|
5919
|
-
if (isDidResolverError(didResult.reason)) {
|
|
5920
|
-
return blockWithParseError(
|
|
5921
|
-
didResult.reason instanceof Error ? didResult.reason.message : String(didResult.reason),
|
|
5922
|
-
opts.enforcementMode
|
|
5923
|
-
);
|
|
5924
|
-
}
|
|
5925
|
-
throw didResult.reason;
|
|
5926
|
-
}
|
|
5927
|
-
if (statusResult.status === "rejected") {
|
|
5928
|
-
if (statusResult.reason instanceof UnsafeOutboundUrl) {
|
|
5929
|
-
return blockWithParseError(statusResult.reason.message, opts.enforcementMode);
|
|
5930
|
-
}
|
|
5931
|
-
throw statusResult.reason;
|
|
5932
|
-
}
|
|
5933
|
-
if (repResult.status === "rejected") {
|
|
5934
|
-
throw repResult.reason;
|
|
5935
|
-
}
|
|
5936
|
-
const didDoc = didResult.value;
|
|
5937
|
-
const revokedIndices = statusResult.value;
|
|
5938
|
-
const repScore = repResult.value;
|
|
5939
|
-
const tenantDecision = await opts.policyEvaluator.evaluate({
|
|
5940
|
-
tenantHost: opts.tenantHost,
|
|
5941
|
-
reputation: repScore
|
|
5942
|
-
});
|
|
5943
|
-
const ctx = {
|
|
5944
|
-
didDocs: didDoc && issuer ? { [issuer]: didDoc } : {},
|
|
5945
|
-
revoked: revokedIndices !== null && credentialStatusUrl ? { [credentialStatusUrl]: revokedIndices } : {},
|
|
5946
|
-
reputation: agentDid ? { [agentDid]: repScore } : {},
|
|
5947
|
-
tenantDecision,
|
|
5948
|
-
nowUnix: opts.clock.nowUnix(),
|
|
5949
|
-
enforcementMode: opts.enforcementMode
|
|
5950
|
-
};
|
|
5951
|
-
return engineVerify(agentRequest, ctx);
|
|
5952
|
-
}
|
|
5953
|
-
async function fetchCredentialStatus(credentialStatusUrl, statusListCache) {
|
|
5954
|
-
assertSafeHttpsUrl(credentialStatusUrl, "credential status URL");
|
|
5955
|
-
return statusListCache.fetch(credentialStatusUrl);
|
|
5956
|
-
}
|
|
5957
|
-
function isDidResolverError(err) {
|
|
5958
|
-
if (!(err instanceof Error)) return false;
|
|
5959
|
-
const kind = err.kind;
|
|
5960
|
-
return kind === "DidNotFound" || kind === "DidResolverTimeout" || kind === "DidResolverError" || kind === "MalformedDid" || kind === "UnsupportedKeyType" || kind === "UnsupportedDidMethod";
|
|
5961
|
-
}
|
|
5962
|
-
function blockWithParseError(detail, enforcementMode) {
|
|
5963
|
-
return {
|
|
5964
|
-
decision: {
|
|
5965
|
-
kind: "Block",
|
|
5966
|
-
reason: {
|
|
5967
|
-
kind: "ParseError",
|
|
5968
|
-
detail
|
|
5969
|
-
}
|
|
5970
|
-
},
|
|
5971
|
-
enforcementMode,
|
|
5972
|
-
engineInfo: {
|
|
5973
|
-
name: "checkpoint-engine-wasm",
|
|
5974
|
-
version: "0.0.0-host-synth",
|
|
5975
|
-
rulesetHash: "sha256:host-synthesized",
|
|
5976
|
-
rulesetVersion: "0.0.0-host-synth",
|
|
5977
|
-
extras: { synthesized: true }
|
|
5978
|
-
}
|
|
5979
|
-
};
|
|
5980
|
-
}
|
|
5981
|
-
function renderDecisionAsResponse(result) {
|
|
5982
|
-
const baseHeaders = buildBaseHeaders(result);
|
|
5983
|
-
if (result.enforcementMode === "observe") {
|
|
5984
|
-
return {
|
|
5985
|
-
status: null,
|
|
5986
|
-
headers: {
|
|
5987
|
-
...baseHeaders,
|
|
5988
|
-
"X-Checkpoint-Mode": "observe",
|
|
5989
|
-
"X-Checkpoint-Would-Have-Been": result.decision.kind,
|
|
5990
|
-
...wouldHaveBeenReasonHeader(result)
|
|
5991
|
-
}
|
|
5992
|
-
};
|
|
5993
|
-
}
|
|
5994
|
-
switch (result.decision.kind) {
|
|
5995
|
-
case "Permit":
|
|
5996
|
-
return {
|
|
5997
|
-
status: null,
|
|
5998
|
-
headers: { ...baseHeaders, "X-Checkpoint-Decision": "permit" }
|
|
5999
|
-
};
|
|
6000
|
-
case "Block": {
|
|
6001
|
-
const reason = result.decision.reason;
|
|
6002
|
-
return {
|
|
6003
|
-
status: httpStatusForBlockReason(reason),
|
|
6004
|
-
headers: {
|
|
6005
|
-
...baseHeaders,
|
|
6006
|
-
...blockHeaders(reason),
|
|
6007
|
-
"X-Checkpoint-Decision": "block",
|
|
6008
|
-
"X-Checkpoint-Reason": reason.kind
|
|
6009
|
-
},
|
|
6010
|
-
body: blockResponseBody(reason)
|
|
6011
|
-
};
|
|
6012
|
-
}
|
|
6013
|
-
case "Challenge": {
|
|
6014
|
-
const params = result.decision.params;
|
|
6015
|
-
return {
|
|
6016
|
-
status: 401,
|
|
6017
|
-
headers: {
|
|
6018
|
-
...baseHeaders,
|
|
6019
|
-
"X-Checkpoint-Decision": "challenge",
|
|
6020
|
-
"X-Checkpoint-Challenge": params.nonce
|
|
6021
|
-
},
|
|
6022
|
-
body: {
|
|
6023
|
-
challenge: params
|
|
6024
|
-
}
|
|
6025
|
-
};
|
|
6026
|
-
}
|
|
6027
|
-
case "Redirect": {
|
|
6028
|
-
const target = result.decision.target;
|
|
6029
|
-
return {
|
|
6030
|
-
status: 302,
|
|
6031
|
-
headers: {
|
|
6032
|
-
...baseHeaders,
|
|
6033
|
-
"X-Checkpoint-Decision": "redirect",
|
|
6034
|
-
Location: target.url,
|
|
6035
|
-
"X-Checkpoint-Redirect-Reason": target.reason
|
|
6036
|
-
}
|
|
6037
|
-
};
|
|
6038
|
-
}
|
|
6039
|
-
case "Instruct": {
|
|
6040
|
-
const payload = result.decision.payload;
|
|
6041
|
-
return {
|
|
6042
|
-
status: 422,
|
|
6043
|
-
headers: {
|
|
6044
|
-
...baseHeaders,
|
|
6045
|
-
"X-Checkpoint-Decision": "instruct",
|
|
6046
|
-
"Content-Type": "application/problem+json"
|
|
6047
|
-
},
|
|
6048
|
-
body: {
|
|
6049
|
-
type: payload.problem,
|
|
6050
|
-
title: payload.title,
|
|
6051
|
-
suggestedActions: payload.suggestedActions
|
|
6052
|
-
}
|
|
6053
|
-
};
|
|
6054
|
-
}
|
|
6055
|
-
}
|
|
6056
|
-
}
|
|
6057
|
-
function buildBaseHeaders(result) {
|
|
6058
|
-
const headers = {
|
|
6059
|
-
"X-Checkpoint-Engine": result.engineInfo.name,
|
|
6060
|
-
"X-Checkpoint-Engine-Version": result.engineInfo.version
|
|
6061
|
-
};
|
|
6062
|
-
if (result.engineInfo.rulesetHash) {
|
|
6063
|
-
headers["X-Checkpoint-Ruleset-Hash"] = result.engineInfo.rulesetHash;
|
|
6064
|
-
}
|
|
6065
|
-
return headers;
|
|
6066
|
-
}
|
|
6067
|
-
function httpStatusForBlockReason(reason) {
|
|
6068
|
-
switch (reason.kind) {
|
|
6069
|
-
case "Unauthenticated":
|
|
6070
|
-
case "Expired":
|
|
6071
|
-
return 401;
|
|
6072
|
-
case "ParseError":
|
|
6073
|
-
return 400;
|
|
6074
|
-
case "InvalidSignature":
|
|
6075
|
-
case "Revoked":
|
|
6076
|
-
case "OutOfScope":
|
|
6077
|
-
case "LowReputation":
|
|
6078
|
-
case "PolicyDenied":
|
|
6079
|
-
return 403;
|
|
6080
|
-
}
|
|
6081
|
-
}
|
|
6082
|
-
function blockHeaders(reason) {
|
|
6083
|
-
if (reason.kind === "Unauthenticated") {
|
|
6084
|
-
return { "WWW-Authenticate": 'KyaProof realm="checkpoint"' };
|
|
6085
|
-
}
|
|
6086
|
-
return {};
|
|
6087
|
-
}
|
|
6088
|
-
function blockResponseBody(reason) {
|
|
6089
|
-
switch (reason.kind) {
|
|
6090
|
-
case "Revoked":
|
|
6091
|
-
case "InvalidSignature":
|
|
6092
|
-
case "Unauthenticated":
|
|
6093
|
-
case "Expired":
|
|
6094
|
-
return { error: humanError(reason.kind), reason: reason.kind };
|
|
6095
|
-
case "OutOfScope":
|
|
6096
|
-
return {
|
|
6097
|
-
error: "requested scope is not granted",
|
|
6098
|
-
reason: "OutOfScope",
|
|
6099
|
-
requested: reason.requested,
|
|
6100
|
-
granted: reason.granted
|
|
6101
|
-
};
|
|
6102
|
-
case "LowReputation":
|
|
6103
|
-
return {
|
|
6104
|
-
error: "agent reputation below tenant threshold",
|
|
6105
|
-
reason: "LowReputation",
|
|
6106
|
-
score: reason.score,
|
|
6107
|
-
threshold: reason.threshold
|
|
6108
|
-
};
|
|
6109
|
-
case "PolicyDenied":
|
|
6110
|
-
return {
|
|
6111
|
-
error: "tenant policy denied the request",
|
|
6112
|
-
reason: "PolicyDenied",
|
|
6113
|
-
detail: reason.detail
|
|
6114
|
-
};
|
|
6115
|
-
case "ParseError":
|
|
6116
|
-
return {
|
|
6117
|
-
error: "request envelope could not be parsed",
|
|
6118
|
-
reason: "ParseError",
|
|
6119
|
-
detail: reason.detail
|
|
6120
|
-
};
|
|
6121
|
-
}
|
|
6122
|
-
}
|
|
6123
|
-
function humanError(kind) {
|
|
6124
|
-
switch (kind) {
|
|
6125
|
-
case "Revoked":
|
|
6126
|
-
return "credential has been revoked";
|
|
6127
|
-
case "InvalidSignature":
|
|
6128
|
-
return "request signature failed verification";
|
|
6129
|
-
case "Unauthenticated":
|
|
6130
|
-
return "authentication required";
|
|
6131
|
-
case "Expired":
|
|
6132
|
-
return "credential is expired";
|
|
6133
|
-
}
|
|
6134
|
-
}
|
|
6135
|
-
function wouldHaveBeenReasonHeader(result) {
|
|
6136
|
-
if (result.decision.kind === "Block") {
|
|
6137
|
-
return { "X-Checkpoint-Would-Have-Been-Reason": result.decision.reason.kind };
|
|
6138
|
-
}
|
|
6139
|
-
return {};
|
|
6140
|
-
}
|
|
6141
|
-
function coerce(o) {
|
|
6142
|
-
if (o instanceof Uint8Array && o.constructor.name === "Uint8Array") {
|
|
6143
|
-
return o;
|
|
6144
|
-
}
|
|
6145
|
-
if (o instanceof ArrayBuffer) {
|
|
6146
|
-
return new Uint8Array(o);
|
|
6147
|
-
}
|
|
6148
|
-
if (ArrayBuffer.isView(o)) {
|
|
6149
|
-
return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
|
|
6150
|
-
}
|
|
6151
|
-
throw new Error("Unknown type, must be binary type");
|
|
6152
|
-
}
|
|
6153
|
-
|
|
6154
|
-
// ../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/vendor/base-x.js
|
|
6155
|
-
function base(ALPHABET, name) {
|
|
6156
|
-
if (ALPHABET.length >= 255) {
|
|
6157
|
-
throw new TypeError("Alphabet too long");
|
|
6158
|
-
}
|
|
6159
|
-
var BASE_MAP = new Uint8Array(256);
|
|
6160
|
-
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
6161
|
-
BASE_MAP[j] = 255;
|
|
6162
|
-
}
|
|
6163
|
-
for (var i = 0; i < ALPHABET.length; i++) {
|
|
6164
|
-
var x = ALPHABET.charAt(i);
|
|
6165
|
-
var xc = x.charCodeAt(0);
|
|
6166
|
-
if (BASE_MAP[xc] !== 255) {
|
|
6167
|
-
throw new TypeError(x + " is ambiguous");
|
|
6168
|
-
}
|
|
6169
|
-
BASE_MAP[xc] = i;
|
|
6170
|
-
}
|
|
6171
|
-
var BASE = ALPHABET.length;
|
|
6172
|
-
var LEADER = ALPHABET.charAt(0);
|
|
6173
|
-
var FACTOR = Math.log(BASE) / Math.log(256);
|
|
6174
|
-
var iFACTOR = Math.log(256) / Math.log(BASE);
|
|
6175
|
-
function encode(source) {
|
|
6176
|
-
if (source instanceof Uint8Array)
|
|
6177
|
-
;
|
|
6178
|
-
else if (ArrayBuffer.isView(source)) {
|
|
6179
|
-
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
6180
|
-
} else if (Array.isArray(source)) {
|
|
6181
|
-
source = Uint8Array.from(source);
|
|
6182
|
-
}
|
|
6183
|
-
if (!(source instanceof Uint8Array)) {
|
|
6184
|
-
throw new TypeError("Expected Uint8Array");
|
|
6185
|
-
}
|
|
6186
|
-
if (source.length === 0) {
|
|
6187
|
-
return "";
|
|
6188
|
-
}
|
|
6189
|
-
var zeroes = 0;
|
|
6190
|
-
var length = 0;
|
|
6191
|
-
var pbegin = 0;
|
|
6192
|
-
var pend = source.length;
|
|
6193
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
6194
|
-
pbegin++;
|
|
6195
|
-
zeroes++;
|
|
6196
|
-
}
|
|
6197
|
-
var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
|
|
6198
|
-
var b58 = new Uint8Array(size);
|
|
6199
|
-
while (pbegin !== pend) {
|
|
6200
|
-
var carry = source[pbegin];
|
|
6201
|
-
var i2 = 0;
|
|
6202
|
-
for (var it1 = size - 1; (carry !== 0 || i2 < length) && it1 !== -1; it1--, i2++) {
|
|
6203
|
-
carry += 256 * b58[it1] >>> 0;
|
|
6204
|
-
b58[it1] = carry % BASE >>> 0;
|
|
6205
|
-
carry = carry / BASE >>> 0;
|
|
6206
|
-
}
|
|
6207
|
-
if (carry !== 0) {
|
|
6208
|
-
throw new Error("Non-zero carry");
|
|
6209
|
-
}
|
|
6210
|
-
length = i2;
|
|
6211
|
-
pbegin++;
|
|
6212
|
-
}
|
|
6213
|
-
var it2 = size - length;
|
|
6214
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
6215
|
-
it2++;
|
|
6216
|
-
}
|
|
6217
|
-
var str = LEADER.repeat(zeroes);
|
|
6218
|
-
for (; it2 < size; ++it2) {
|
|
6219
|
-
str += ALPHABET.charAt(b58[it2]);
|
|
6220
|
-
}
|
|
6221
|
-
return str;
|
|
6222
|
-
}
|
|
6223
|
-
function decodeUnsafe(source) {
|
|
6224
|
-
if (typeof source !== "string") {
|
|
6225
|
-
throw new TypeError("Expected String");
|
|
6226
|
-
}
|
|
6227
|
-
if (source.length === 0) {
|
|
6228
|
-
return new Uint8Array();
|
|
6229
|
-
}
|
|
6230
|
-
var psz = 0;
|
|
6231
|
-
if (source[psz] === " ") {
|
|
6232
|
-
return;
|
|
6233
|
-
}
|
|
6234
|
-
var zeroes = 0;
|
|
6235
|
-
var length = 0;
|
|
6236
|
-
while (source[psz] === LEADER) {
|
|
6237
|
-
zeroes++;
|
|
6238
|
-
psz++;
|
|
6239
|
-
}
|
|
6240
|
-
var size = (source.length - psz) * FACTOR + 1 >>> 0;
|
|
6241
|
-
var b256 = new Uint8Array(size);
|
|
6242
|
-
while (source[psz]) {
|
|
6243
|
-
var carry = BASE_MAP[source.charCodeAt(psz)];
|
|
6244
|
-
if (carry === 255) {
|
|
6245
|
-
return;
|
|
6246
|
-
}
|
|
6247
|
-
var i2 = 0;
|
|
6248
|
-
for (var it3 = size - 1; (carry !== 0 || i2 < length) && it3 !== -1; it3--, i2++) {
|
|
6249
|
-
carry += BASE * b256[it3] >>> 0;
|
|
6250
|
-
b256[it3] = carry % 256 >>> 0;
|
|
6251
|
-
carry = carry / 256 >>> 0;
|
|
6252
|
-
}
|
|
6253
|
-
if (carry !== 0) {
|
|
6254
|
-
throw new Error("Non-zero carry");
|
|
6255
|
-
}
|
|
6256
|
-
length = i2;
|
|
6257
|
-
psz++;
|
|
6258
|
-
}
|
|
6259
|
-
if (source[psz] === " ") {
|
|
6260
|
-
return;
|
|
6261
|
-
}
|
|
6262
|
-
var it4 = size - length;
|
|
6263
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
6264
|
-
it4++;
|
|
6265
|
-
}
|
|
6266
|
-
var vch = new Uint8Array(zeroes + (size - it4));
|
|
6267
|
-
var j2 = zeroes;
|
|
6268
|
-
while (it4 !== size) {
|
|
6269
|
-
vch[j2++] = b256[it4++];
|
|
6270
|
-
}
|
|
6271
|
-
return vch;
|
|
6272
|
-
}
|
|
6273
|
-
function decode2(string) {
|
|
6274
|
-
var buffer = decodeUnsafe(string);
|
|
6275
|
-
if (buffer) {
|
|
6276
|
-
return buffer;
|
|
6277
|
-
}
|
|
6278
|
-
throw new Error(`Non-${name} character`);
|
|
6279
|
-
}
|
|
6280
|
-
return {
|
|
6281
|
-
encode,
|
|
6282
|
-
decodeUnsafe,
|
|
6283
|
-
decode: decode2
|
|
6284
|
-
};
|
|
6285
|
-
}
|
|
6286
|
-
var src = base;
|
|
6287
|
-
var _brrp__multiformats_scope_baseX = src;
|
|
6288
|
-
var base_x_default = _brrp__multiformats_scope_baseX;
|
|
6289
|
-
|
|
6290
|
-
// ../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/bases/base.js
|
|
6291
|
-
var Encoder = class {
|
|
6292
|
-
name;
|
|
6293
|
-
prefix;
|
|
6294
|
-
baseEncode;
|
|
6295
|
-
constructor(name, prefix, baseEncode) {
|
|
6296
|
-
this.name = name;
|
|
6297
|
-
this.prefix = prefix;
|
|
6298
|
-
this.baseEncode = baseEncode;
|
|
6299
|
-
}
|
|
6300
|
-
encode(bytes) {
|
|
6301
|
-
if (bytes instanceof Uint8Array) {
|
|
6302
|
-
return `${this.prefix}${this.baseEncode(bytes)}`;
|
|
6303
|
-
} else {
|
|
6304
|
-
throw Error("Unknown type, must be binary type");
|
|
6305
|
-
}
|
|
6306
|
-
}
|
|
6307
|
-
};
|
|
6308
|
-
var Decoder = class {
|
|
6309
|
-
name;
|
|
6310
|
-
prefix;
|
|
6311
|
-
baseDecode;
|
|
6312
|
-
prefixCodePoint;
|
|
6313
|
-
constructor(name, prefix, baseDecode) {
|
|
6314
|
-
this.name = name;
|
|
6315
|
-
this.prefix = prefix;
|
|
6316
|
-
const prefixCodePoint = prefix.codePointAt(0);
|
|
6317
|
-
if (prefixCodePoint === void 0) {
|
|
6318
|
-
throw new Error("Invalid prefix character");
|
|
6319
|
-
}
|
|
6320
|
-
this.prefixCodePoint = prefixCodePoint;
|
|
6321
|
-
this.baseDecode = baseDecode;
|
|
6322
|
-
}
|
|
6323
|
-
decode(text) {
|
|
6324
|
-
if (typeof text === "string") {
|
|
6325
|
-
if (text.codePointAt(0) !== this.prefixCodePoint) {
|
|
6326
|
-
throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
|
|
6327
|
-
}
|
|
6328
|
-
return this.baseDecode(text.slice(this.prefix.length));
|
|
6329
|
-
} else {
|
|
6330
|
-
throw Error("Can only multibase decode strings");
|
|
6331
|
-
}
|
|
6332
|
-
}
|
|
6333
|
-
or(decoder) {
|
|
6334
|
-
return or(this, decoder);
|
|
6335
|
-
}
|
|
6336
|
-
};
|
|
6337
|
-
var ComposedDecoder = class {
|
|
6338
|
-
decoders;
|
|
6339
|
-
constructor(decoders) {
|
|
6340
|
-
this.decoders = decoders;
|
|
6341
|
-
}
|
|
6342
|
-
or(decoder) {
|
|
6343
|
-
return or(this, decoder);
|
|
6344
|
-
}
|
|
6345
|
-
decode(input) {
|
|
6346
|
-
const prefix = input[0];
|
|
6347
|
-
const decoder = this.decoders[prefix];
|
|
6348
|
-
if (decoder != null) {
|
|
6349
|
-
return decoder.decode(input);
|
|
6350
|
-
} else {
|
|
6351
|
-
throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
|
|
6352
|
-
}
|
|
6353
|
-
}
|
|
6354
|
-
};
|
|
6355
|
-
function or(left, right) {
|
|
6356
|
-
return new ComposedDecoder({
|
|
6357
|
-
...left.decoders ?? { [left.prefix]: left },
|
|
6358
|
-
...right.decoders ?? { [right.prefix]: right }
|
|
6359
|
-
});
|
|
6360
|
-
}
|
|
6361
|
-
var Codec = class {
|
|
6362
|
-
name;
|
|
6363
|
-
prefix;
|
|
6364
|
-
baseEncode;
|
|
6365
|
-
baseDecode;
|
|
6366
|
-
encoder;
|
|
6367
|
-
decoder;
|
|
6368
|
-
constructor(name, prefix, baseEncode, baseDecode) {
|
|
6369
|
-
this.name = name;
|
|
6370
|
-
this.prefix = prefix;
|
|
6371
|
-
this.baseEncode = baseEncode;
|
|
6372
|
-
this.baseDecode = baseDecode;
|
|
6373
|
-
this.encoder = new Encoder(name, prefix, baseEncode);
|
|
6374
|
-
this.decoder = new Decoder(name, prefix, baseDecode);
|
|
6375
|
-
}
|
|
6376
|
-
encode(input) {
|
|
6377
|
-
return this.encoder.encode(input);
|
|
6378
|
-
}
|
|
6379
|
-
decode(input) {
|
|
6380
|
-
return this.decoder.decode(input);
|
|
6381
|
-
}
|
|
6382
|
-
};
|
|
6383
|
-
function from({ name, prefix, encode, decode: decode2 }) {
|
|
6384
|
-
return new Codec(name, prefix, encode, decode2);
|
|
6385
|
-
}
|
|
6386
|
-
function baseX({ name, prefix, alphabet }) {
|
|
6387
|
-
const { encode, decode: decode2 } = base_x_default(alphabet, name);
|
|
6388
|
-
return from({
|
|
6389
|
-
prefix,
|
|
6390
|
-
name,
|
|
6391
|
-
encode,
|
|
6392
|
-
decode: (text) => coerce(decode2(text))
|
|
6393
|
-
});
|
|
6394
|
-
}
|
|
6395
|
-
|
|
6396
|
-
// ../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/bases/base58.js
|
|
6397
|
-
var base58btc = baseX({
|
|
6398
|
-
name: "base58btc",
|
|
6399
|
-
prefix: "z",
|
|
6400
|
-
alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
|
6401
|
-
});
|
|
6402
|
-
baseX({
|
|
6403
|
-
name: "base58flickr",
|
|
6404
|
-
prefix: "Z",
|
|
6405
|
-
alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
|
|
6406
|
-
});
|
|
6407
|
-
var BLOCKED_HOSTNAMES2 = /* @__PURE__ */ new Set(["localhost", "metadata", "metadata.google.internal"]);
|
|
6408
|
-
var UnsafeOutboundUrl2 = class extends Error {
|
|
6409
|
-
kind = "UnsafeOutboundUrl";
|
|
6410
|
-
};
|
|
6411
|
-
function assertSafeHttpsUrl2(rawUrl, label = "outbound URL") {
|
|
6412
|
-
let parsed;
|
|
6413
|
-
try {
|
|
6414
|
-
parsed = new URL(rawUrl);
|
|
6415
|
-
} catch {
|
|
6416
|
-
throw new UnsafeOutboundUrl2(`${label} must be a valid URL: ${rawUrl}`);
|
|
6417
|
-
}
|
|
6418
|
-
if (parsed.protocol !== "https:") {
|
|
6419
|
-
throw new UnsafeOutboundUrl2(`${label} must use https: ${rawUrl}`);
|
|
6420
|
-
}
|
|
6421
|
-
if (parsed.username || parsed.password) {
|
|
6422
|
-
throw new UnsafeOutboundUrl2(`${label} must not contain credentials: ${rawUrl}`);
|
|
6423
|
-
}
|
|
6424
|
-
const hostname = normalizeHostname2(parsed.hostname);
|
|
6425
|
-
if (!hostname || isBlockedHostname2(hostname)) {
|
|
6426
|
-
throw new UnsafeOutboundUrl2(`${label} targets a local or private host: ${rawUrl}`);
|
|
6427
|
-
}
|
|
6428
|
-
return rawUrl;
|
|
6429
|
-
}
|
|
6430
|
-
function normalizeHostname2(hostname) {
|
|
6431
|
-
let normalized = hostname.trim().toLowerCase();
|
|
6432
|
-
if (normalized.startsWith("[") && normalized.endsWith("]")) {
|
|
6433
|
-
normalized = normalized.slice(1, -1);
|
|
6434
|
-
}
|
|
6435
|
-
while (normalized.endsWith(".")) {
|
|
6436
|
-
normalized = normalized.slice(0, -1);
|
|
6437
|
-
}
|
|
6438
|
-
return normalized;
|
|
6439
|
-
}
|
|
6440
|
-
function isBlockedHostname2(hostname) {
|
|
6441
|
-
if (BLOCKED_HOSTNAMES2.has(hostname) || hostname.endsWith(".localhost")) {
|
|
6442
|
-
return true;
|
|
6443
|
-
}
|
|
6444
|
-
const ipv4 = parseIpv42(hostname);
|
|
6445
|
-
if (ipv4) {
|
|
6446
|
-
return isBlockedIpv42(ipv4);
|
|
6447
|
-
}
|
|
6448
|
-
return isBlockedIpv62(hostname);
|
|
6449
|
-
}
|
|
6450
|
-
function parseIpv42(hostname) {
|
|
6451
|
-
const parts = hostname.split(".");
|
|
6452
|
-
if (parts.length !== 4) return null;
|
|
6453
|
-
const octets = parts.map((part) => {
|
|
6454
|
-
if (!/^\d{1,3}$/.test(part)) return Number.NaN;
|
|
6455
|
-
const value = Number(part);
|
|
6456
|
-
return value >= 0 && value <= 255 ? value : Number.NaN;
|
|
6457
|
-
});
|
|
6458
|
-
if (octets.some(Number.isNaN)) return null;
|
|
6459
|
-
return octets;
|
|
6460
|
-
}
|
|
6461
|
-
function isBlockedIpv42([a, b]) {
|
|
6462
|
-
return a === 0 || a === 10 || a === 127 || a === 100 && b >= 64 && b <= 127 || a === 169 && b === 254 || a === 172 && b >= 16 && b <= 31 || a === 192 && b === 168 || a === 198 && (b === 18 || b === 19) || a >= 224;
|
|
6463
|
-
}
|
|
6464
|
-
function isBlockedIpv62(hostname) {
|
|
6465
|
-
if (!hostname.includes(":")) return false;
|
|
6466
|
-
const ipv4Mapped = hostname.match(/(?:^|:)ffff:(\d{1,3}(?:\.\d{1,3}){3})$/);
|
|
6467
|
-
if (ipv4Mapped) {
|
|
6468
|
-
const ipv4 = parseIpv42(ipv4Mapped[1]);
|
|
6469
|
-
return ipv4 ? isBlockedIpv42(ipv4) : true;
|
|
6470
|
-
}
|
|
6471
|
-
if (hostname === "::" || hostname === "::1" || hostname === "0:0:0:0:0:0:0:1") {
|
|
6472
|
-
return true;
|
|
6473
|
-
}
|
|
6474
|
-
const firstSegment = Number.parseInt(hostname.split(":")[0] || "0", 16);
|
|
6475
|
-
if (Number.isNaN(firstSegment)) return true;
|
|
6476
|
-
return (firstSegment & 65024) === 64512 || // unique local fc00::/7
|
|
6477
|
-
(firstSegment & 65472) === 65152 || // link-local fe80::/10
|
|
6478
|
-
(firstSegment & 65280) === 65280;
|
|
6479
|
-
}
|
|
6480
|
-
function base64UrlDecode2(input) {
|
|
6481
|
-
const padded = input.replace(/-/g, "+").replace(/_/g, "/");
|
|
6482
|
-
const padding = padded.length % 4 === 0 ? "" : "=".repeat(4 - padded.length % 4);
|
|
6483
|
-
return new Uint8Array(Buffer.from(padded + padding, "base64"));
|
|
6484
|
-
}
|
|
6485
|
-
var ED25519_PUBLIC_KEY_LENGTH = 32;
|
|
6486
|
-
var MalformedDid = class extends Error {
|
|
6487
|
-
kind = "MalformedDid";
|
|
6488
|
-
};
|
|
6489
|
-
var UnsupportedKeyType = class extends Error {
|
|
6490
|
-
kind = "UnsupportedKeyType";
|
|
6491
|
-
};
|
|
6492
|
-
var DidNotFound = class extends Error {
|
|
6493
|
-
kind = "DidNotFound";
|
|
6494
|
-
};
|
|
6495
|
-
var DidResolverTimeout = class extends Error {
|
|
6496
|
-
kind = "DidResolverTimeout";
|
|
6497
|
-
};
|
|
6498
|
-
var DidResolverError = class extends Error {
|
|
6499
|
-
kind = "DidResolverError";
|
|
6500
|
-
};
|
|
6501
|
-
var UnsupportedDidMethod = class extends Error {
|
|
6502
|
-
kind = "UnsupportedDidMethod";
|
|
6503
|
-
};
|
|
6504
|
-
var ED25519_MULTICODEC_PREFIX = [237, 1];
|
|
6505
|
-
var DEFAULT_FETCH_TIMEOUT_MS = 3e3;
|
|
6506
|
-
var DEFAULT_TTL_MS = 5 * 6e4;
|
|
6507
|
-
function makeDidResolver(opts = {}) {
|
|
6508
|
-
const timeoutMs = opts.fetchTimeoutMs ?? DEFAULT_FETCH_TIMEOUT_MS;
|
|
6509
|
-
const ttlMs = opts.ttlMs ?? DEFAULT_TTL_MS;
|
|
6510
|
-
const fetchImpl = opts.fetch ?? fetch;
|
|
6511
|
-
const cache = opts.cache ?? /* @__PURE__ */ new Map();
|
|
6512
|
-
const now = opts.now ?? (() => Date.now());
|
|
6513
|
-
return {
|
|
6514
|
-
async resolve(did) {
|
|
6515
|
-
const cached = cache.get(did);
|
|
6516
|
-
if (cached && now() - cached.fetchedAt < ttlMs) {
|
|
6517
|
-
return cached.value;
|
|
6518
|
-
}
|
|
6519
|
-
if (did.startsWith("did:key:")) {
|
|
6520
|
-
const doc = decodeDidKey(did);
|
|
6521
|
-
cache.set(did, { value: doc, fetchedAt: now() });
|
|
6522
|
-
return doc;
|
|
6523
|
-
}
|
|
6524
|
-
if (did.startsWith("did:web:")) {
|
|
6525
|
-
const doc = await resolveDidWeb(did, fetchImpl, timeoutMs);
|
|
6526
|
-
cache.set(did, { value: doc, fetchedAt: now() });
|
|
6527
|
-
return doc;
|
|
6528
|
-
}
|
|
6529
|
-
throw new UnsupportedDidMethod(`Phase 1 supports did:key and did:web only; got: ${did}`);
|
|
6530
|
-
}
|
|
6531
|
-
};
|
|
6532
|
-
}
|
|
6533
|
-
function decodeDidKey(did) {
|
|
6534
|
-
if (!did.startsWith("did:key:")) {
|
|
6535
|
-
throw new MalformedDid(`expected did:key prefix, got: ${did}`);
|
|
6536
|
-
}
|
|
6537
|
-
const multibaseValue = did.slice("did:key:".length);
|
|
6538
|
-
if (!multibaseValue.startsWith("z")) {
|
|
6539
|
-
throw new MalformedDid(
|
|
6540
|
-
`did:key expects base58btc (multibase 'z' prefix); got: ${multibaseValue[0] ?? "<empty>"}`
|
|
6541
|
-
);
|
|
6542
|
-
}
|
|
6543
|
-
let decoded;
|
|
6544
|
-
try {
|
|
6545
|
-
decoded = base58btc.decode(multibaseValue);
|
|
6546
|
-
} catch (cause) {
|
|
6547
|
-
throw new MalformedDid(`did:key multibase decode failed: ${String(cause)}`);
|
|
6548
|
-
}
|
|
6549
|
-
if (decoded.length < 2 || decoded[0] !== ED25519_MULTICODEC_PREFIX[0] || decoded[1] !== ED25519_MULTICODEC_PREFIX[1]) {
|
|
6550
|
-
const prefixHex = decoded.length >= 2 ? `0x${decoded[0].toString(16).padStart(2, "0")}${decoded[1].toString(16).padStart(2, "0")}` : "<too short>";
|
|
6551
|
-
throw new UnsupportedKeyType(
|
|
6552
|
-
`did:key expects Ed25519 multicodec 0xed01; got ${prefixHex} (only Ed25519 supported in Phase 1)`
|
|
6553
|
-
);
|
|
6554
|
-
}
|
|
6555
|
-
const publicKey = decoded.slice(2);
|
|
6556
|
-
if (publicKey.length !== 32) {
|
|
6557
|
-
throw new MalformedDid(`did:key Ed25519 public key must be 32 bytes; got ${publicKey.length}`);
|
|
6558
|
-
}
|
|
6559
|
-
const vm = {
|
|
6560
|
-
id: `${did}#${multibaseValue}`,
|
|
6561
|
-
// multibase as fragment — mcp-i-core PR #16
|
|
6562
|
-
keyType: "Ed25519",
|
|
6563
|
-
publicKeyBytes: Array.from(publicKey)
|
|
6564
|
-
};
|
|
6565
|
-
return {
|
|
6566
|
-
id: did,
|
|
6567
|
-
verificationMethods: [vm]
|
|
6568
|
-
};
|
|
6569
|
-
}
|
|
6570
|
-
async function resolveDidWeb(did, fetchImpl, timeoutMs) {
|
|
6571
|
-
const transformedUrl = didWebToUrl(did);
|
|
6572
|
-
let url;
|
|
6573
|
-
try {
|
|
6574
|
-
url = assertSafeHttpsUrl2(transformedUrl, "did:web resolution URL");
|
|
6575
|
-
} catch (cause) {
|
|
6576
|
-
if (cause instanceof UnsafeOutboundUrl2) {
|
|
6577
|
-
throw new DidResolverError(cause.message);
|
|
6578
|
-
}
|
|
6579
|
-
throw cause;
|
|
6580
|
-
}
|
|
6581
|
-
const controller = new AbortController();
|
|
6582
|
-
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
6583
|
-
let response;
|
|
6584
|
-
try {
|
|
6585
|
-
response = await fetchImpl(url, { signal: controller.signal });
|
|
6586
|
-
} catch (cause) {
|
|
6587
|
-
if (cause instanceof Error && cause.name === "AbortError") {
|
|
6588
|
-
throw new DidResolverTimeout(`did:web fetch timed out after ${timeoutMs}ms: ${url}`);
|
|
6589
|
-
}
|
|
6590
|
-
throw new DidResolverError(`did:web fetch failed: ${url}: ${String(cause)}`);
|
|
6591
|
-
} finally {
|
|
6592
|
-
clearTimeout(timer);
|
|
6593
|
-
}
|
|
6594
|
-
if (response.status === 404) {
|
|
6595
|
-
throw new DidNotFound(`no DID document at ${url}`);
|
|
6596
|
-
}
|
|
6597
|
-
if (!response.ok) {
|
|
6598
|
-
throw new DidResolverError(`did:web HTTP ${response.status} at ${url}`);
|
|
6599
|
-
}
|
|
6600
|
-
let raw;
|
|
6601
|
-
try {
|
|
6602
|
-
raw = await response.json();
|
|
6603
|
-
} catch (cause) {
|
|
6604
|
-
throw new DidResolverError(`did:web response not valid JSON at ${url}: ${String(cause)}`);
|
|
6605
|
-
}
|
|
6606
|
-
return mapW3CDocToEngineShape(raw, did);
|
|
6607
|
-
}
|
|
6608
|
-
function didWebToUrl(did) {
|
|
6609
|
-
const path = did.slice("did:web:".length);
|
|
6610
|
-
if (!path) {
|
|
6611
|
-
throw new MalformedDid(`did:web with empty path: ${did}`);
|
|
6612
|
-
}
|
|
6613
|
-
const parts = path.split(":").map((segment) => {
|
|
6614
|
-
try {
|
|
6615
|
-
return decodeURIComponent(segment);
|
|
6616
|
-
} catch {
|
|
6617
|
-
throw new MalformedDid(`did:web segment contains invalid percent-encoding: ${segment}`);
|
|
6618
|
-
}
|
|
6619
|
-
});
|
|
6620
|
-
if (parts.length === 1) {
|
|
6621
|
-
return `https://${parts[0]}/.well-known/did.json`;
|
|
6622
|
-
}
|
|
6623
|
-
return `https://${parts[0]}/${parts.slice(1).join("/")}/did.json`;
|
|
6624
|
-
}
|
|
6625
|
-
function mapW3CDocToEngineShape(raw, requestedDid) {
|
|
6626
|
-
if (raw === null || typeof raw !== "object") {
|
|
6627
|
-
throw new DidResolverError(`did:web response must be a JSON object`);
|
|
6628
|
-
}
|
|
6629
|
-
const doc = raw;
|
|
6630
|
-
const id = typeof doc.id === "string" ? doc.id : requestedDid;
|
|
6631
|
-
const w3cMethods = Array.isArray(doc.verificationMethod) ? doc.verificationMethod : [];
|
|
6632
|
-
const verificationMethods = [];
|
|
6633
|
-
for (const entry of w3cMethods) {
|
|
6634
|
-
if (entry === null || typeof entry !== "object") continue;
|
|
6635
|
-
const vm = entry;
|
|
6636
|
-
if (!isEd25519Type(vm.type)) continue;
|
|
6637
|
-
const vmId = typeof vm.id === "string" ? vm.id : void 0;
|
|
6638
|
-
if (!vmId) continue;
|
|
6639
|
-
const pubKey = extractEd25519PublicKey(vm);
|
|
6640
|
-
if (!pubKey) continue;
|
|
6641
|
-
verificationMethods.push({
|
|
6642
|
-
id: vmId,
|
|
6643
|
-
keyType: "Ed25519",
|
|
6644
|
-
publicKeyBytes: Array.from(pubKey)
|
|
6645
|
-
});
|
|
6646
|
-
}
|
|
6647
|
-
return { id, verificationMethods };
|
|
6648
|
-
}
|
|
6649
|
-
function isEd25519Type(type) {
|
|
6650
|
-
return type === "Ed25519VerificationKey2020" || type === "Ed25519VerificationKey2018";
|
|
6651
|
-
}
|
|
6652
|
-
function extractEd25519PublicKey(vm) {
|
|
6653
|
-
if (typeof vm.publicKeyMultibase === "string") {
|
|
6654
|
-
const mb = vm.publicKeyMultibase;
|
|
6655
|
-
if (!mb.startsWith("z")) return null;
|
|
6656
|
-
try {
|
|
6657
|
-
const decoded = base58btc.decode(mb);
|
|
6658
|
-
if (decoded.length === 34 && decoded[0] === ED25519_MULTICODEC_PREFIX[0] && decoded[1] === ED25519_MULTICODEC_PREFIX[1]) {
|
|
6659
|
-
return decoded.slice(2);
|
|
6660
|
-
}
|
|
6661
|
-
if (decoded.length === 32) return decoded;
|
|
6662
|
-
} catch {
|
|
6663
|
-
return null;
|
|
6664
|
-
}
|
|
6665
|
-
return null;
|
|
6666
|
-
}
|
|
6667
|
-
if (vm.publicKeyJwk && typeof vm.publicKeyJwk === "object") {
|
|
6668
|
-
const jwk = vm.publicKeyJwk;
|
|
6669
|
-
if (jwk.kty !== "OKP" || jwk.crv !== "Ed25519") return null;
|
|
6670
|
-
if (typeof jwk.x !== "string") return null;
|
|
6671
|
-
let decoded;
|
|
6672
|
-
try {
|
|
6673
|
-
decoded = base64UrlDecode2(jwk.x);
|
|
6674
|
-
} catch {
|
|
6675
|
-
return null;
|
|
6676
|
-
}
|
|
6677
|
-
if (decoded.length !== ED25519_PUBLIC_KEY_LENGTH) {
|
|
6678
|
-
return null;
|
|
6679
|
-
}
|
|
6680
|
-
return decoded;
|
|
6681
|
-
}
|
|
6682
|
-
return null;
|
|
6683
|
-
}
|
|
6684
|
-
var StatusListUnavailable = class extends Error {
|
|
6685
|
-
kind = "StatusListUnavailable";
|
|
6686
|
-
};
|
|
6687
|
-
var MalformedStatusList = class extends Error {
|
|
6688
|
-
kind = "MalformedStatusList";
|
|
6689
|
-
};
|
|
6690
|
-
var StatusListTimeout = class extends Error {
|
|
6691
|
-
kind = "StatusListTimeout";
|
|
6692
|
-
};
|
|
6693
|
-
var DEFAULT_FETCH_TIMEOUT_MS2 = 3e3;
|
|
6694
|
-
var DEFAULT_TTL_MS2 = 3e4;
|
|
6695
|
-
function makeStatusListCache(opts = {}) {
|
|
6696
|
-
const timeoutMs = opts.fetchTimeoutMs ?? DEFAULT_FETCH_TIMEOUT_MS2;
|
|
6697
|
-
const ttlMs = opts.ttlMs ?? DEFAULT_TTL_MS2;
|
|
6698
|
-
const fetchImpl = opts.fetch ?? fetch;
|
|
6699
|
-
const cache = opts.cache ?? /* @__PURE__ */ new Map();
|
|
6700
|
-
const now = opts.now ?? (() => Date.now());
|
|
6701
|
-
return {
|
|
6702
|
-
async fetch(url) {
|
|
6703
|
-
const cached = cache.get(url);
|
|
6704
|
-
if (cached && now() - cached.fetchedAt < ttlMs) {
|
|
6705
|
-
return cached.indices;
|
|
6706
|
-
}
|
|
6707
|
-
const indices = await fetchAndDecode(url, fetchImpl, timeoutMs);
|
|
6708
|
-
cache.set(url, { indices, fetchedAt: now() });
|
|
6709
|
-
return indices;
|
|
6710
|
-
}
|
|
6711
|
-
};
|
|
6712
|
-
}
|
|
6713
|
-
async function fetchAndDecode(url, fetchImpl, timeoutMs) {
|
|
6714
|
-
let safeUrl;
|
|
6715
|
-
try {
|
|
6716
|
-
safeUrl = assertSafeHttpsUrl2(url, "status list URL");
|
|
6717
|
-
} catch (cause) {
|
|
6718
|
-
if (cause instanceof UnsafeOutboundUrl2) {
|
|
6719
|
-
throw new StatusListUnavailable(cause.message);
|
|
6720
|
-
}
|
|
6721
|
-
throw cause;
|
|
6722
|
-
}
|
|
6723
|
-
const controller = new AbortController();
|
|
6724
|
-
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
6725
|
-
let response;
|
|
6726
|
-
try {
|
|
6727
|
-
response = await fetchImpl(safeUrl, { signal: controller.signal });
|
|
6728
|
-
} catch (cause) {
|
|
6729
|
-
if (cause instanceof Error && cause.name === "AbortError") {
|
|
6730
|
-
throw new StatusListTimeout(`status list fetch timed out after ${timeoutMs}ms: ${url}`);
|
|
6731
|
-
}
|
|
6732
|
-
throw new StatusListUnavailable(`status list fetch failed: ${url}: ${String(cause)}`);
|
|
6733
|
-
} finally {
|
|
6734
|
-
clearTimeout(timer);
|
|
6735
|
-
}
|
|
6736
|
-
if (!response.ok) {
|
|
6737
|
-
throw new StatusListUnavailable(`status list HTTP ${response.status} at ${url}`);
|
|
6738
|
-
}
|
|
6739
|
-
let vc;
|
|
6740
|
-
try {
|
|
6741
|
-
vc = await response.json();
|
|
6742
|
-
} catch (cause) {
|
|
6743
|
-
throw new MalformedStatusList(
|
|
6744
|
-
`status list response not valid JSON at ${url}: ${String(cause)}`
|
|
6745
|
-
);
|
|
6746
|
-
}
|
|
6747
|
-
const encoded = extractEncodedList(vc);
|
|
6748
|
-
return enumerateRevokedIndices(encoded);
|
|
6749
|
-
}
|
|
6750
|
-
function extractEncodedList(vc) {
|
|
6751
|
-
if (vc === null || typeof vc !== "object") {
|
|
6752
|
-
throw new MalformedStatusList("status list VC must be a JSON object");
|
|
6753
|
-
}
|
|
6754
|
-
const obj = vc;
|
|
6755
|
-
const subject = obj.credentialSubject;
|
|
6756
|
-
if (subject === null || typeof subject !== "object") {
|
|
6757
|
-
throw new MalformedStatusList("status list VC missing credentialSubject");
|
|
6758
|
-
}
|
|
6759
|
-
const encoded = subject.encodedList;
|
|
6760
|
-
if (typeof encoded !== "string") {
|
|
6761
|
-
throw new MalformedStatusList("status list VC missing credentialSubject.encodedList string");
|
|
6762
|
-
}
|
|
6763
|
-
return encoded;
|
|
6764
|
-
}
|
|
6765
|
-
function enumerateRevokedIndices(encodedList) {
|
|
6766
|
-
let bytes;
|
|
6767
|
-
try {
|
|
6768
|
-
const compressed = base64UrlDecode2(encodedList);
|
|
6769
|
-
bytes = new Uint8Array(gunzipSync(compressed));
|
|
6770
|
-
} catch (cause) {
|
|
6771
|
-
throw new MalformedStatusList(`status list bitstring decode failed: ${String(cause)}`);
|
|
6772
|
-
}
|
|
6773
|
-
const indices = [];
|
|
6774
|
-
for (let byteIndex = 0; byteIndex < bytes.length; byteIndex += 1) {
|
|
6775
|
-
const byte = bytes[byteIndex];
|
|
6776
|
-
if (byte === 0) continue;
|
|
6777
|
-
for (let bit = 0; bit < 8; bit += 1) {
|
|
6778
|
-
const mask = 1 << 7 - bit;
|
|
6779
|
-
if ((byte & mask) !== 0) {
|
|
6780
|
-
indices.push(byteIndex * 8 + bit);
|
|
6781
|
-
}
|
|
6782
|
-
}
|
|
6783
|
-
}
|
|
6784
|
-
return indices;
|
|
6785
|
-
}
|
|
6786
|
-
var DEFAULT_FETCH_TIMEOUT_MS3 = 1500;
|
|
6787
|
-
var DEFAULT_TTL_MS3 = 1e4;
|
|
6788
|
-
var DEFAULT_BASELINE = 1;
|
|
6789
|
-
function makeReputationOracle(opts = {}) {
|
|
6790
|
-
const argusUrl = opts.argusUrl;
|
|
6791
|
-
const timeoutMs = opts.fetchTimeoutMs ?? DEFAULT_FETCH_TIMEOUT_MS3;
|
|
6792
|
-
const ttlMs = opts.ttlMs ?? DEFAULT_TTL_MS3;
|
|
6793
|
-
const fetchImpl = opts.fetch ?? fetch;
|
|
6794
|
-
const baseline = opts.baselineWhenUnreachable ?? DEFAULT_BASELINE;
|
|
6795
|
-
const cache = opts.cache ?? /* @__PURE__ */ new Map();
|
|
6796
|
-
const now = opts.now ?? (() => Date.now());
|
|
6797
|
-
const log = opts.logger ?? (() => {
|
|
6798
|
-
});
|
|
6799
|
-
return {
|
|
6800
|
-
async score(agentDid) {
|
|
6801
|
-
const cached = cache.get(agentDid);
|
|
6802
|
-
if (cached && now() - cached.fetchedAt < ttlMs) {
|
|
6803
|
-
return cached.value;
|
|
6804
|
-
}
|
|
6805
|
-
if (!argusUrl) {
|
|
6806
|
-
return baseline;
|
|
6807
|
-
}
|
|
6808
|
-
const value = await fetchAndValidate(argusUrl, agentDid, fetchImpl, timeoutMs, baseline, log);
|
|
6809
|
-
cache.set(agentDid, { value, fetchedAt: now() });
|
|
6810
|
-
return value;
|
|
6811
|
-
}
|
|
6812
|
-
};
|
|
6813
|
-
}
|
|
6814
|
-
async function fetchAndValidate(argusUrl, agentDid, fetchImpl, timeoutMs, baseline, log) {
|
|
6815
|
-
const url = `${argusUrl.replace(/\/$/, "")}/v1/reputation?agent=${encodeURIComponent(agentDid)}`;
|
|
6816
|
-
const controller = new AbortController();
|
|
6817
|
-
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
6818
|
-
let response;
|
|
6819
|
-
try {
|
|
6820
|
-
response = await fetchImpl(url, { signal: controller.signal });
|
|
6821
|
-
} catch (cause) {
|
|
6822
|
-
if (cause instanceof Error && cause.name === "AbortError") {
|
|
6823
|
-
log(
|
|
6824
|
-
`[reputation-oracle] Argus timed out after ${timeoutMs}ms (${agentDid}); using baseline ${baseline}`
|
|
6825
|
-
);
|
|
6826
|
-
} else {
|
|
6827
|
-
log(
|
|
6828
|
-
`[reputation-oracle] Argus fetch failed (${agentDid}): ${String(cause)}; using baseline ${baseline}`
|
|
6829
|
-
);
|
|
6830
|
-
}
|
|
6831
|
-
return baseline;
|
|
6832
|
-
} finally {
|
|
6833
|
-
clearTimeout(timer);
|
|
6834
|
-
}
|
|
6835
|
-
if (!response.ok) {
|
|
6836
|
-
log(
|
|
6837
|
-
`[reputation-oracle] Argus HTTP ${response.status} (${agentDid}); using baseline ${baseline}`
|
|
6838
|
-
);
|
|
6839
|
-
return baseline;
|
|
6840
|
-
}
|
|
6841
|
-
let body;
|
|
6842
|
-
try {
|
|
6843
|
-
body = await response.json();
|
|
6844
|
-
} catch (cause) {
|
|
6845
|
-
log(
|
|
6846
|
-
`[reputation-oracle] Argus response not JSON (${agentDid}): ${String(cause)}; using baseline ${baseline}`
|
|
6847
|
-
);
|
|
6848
|
-
return baseline;
|
|
6849
|
-
}
|
|
6850
|
-
if (body === null || typeof body !== "object") {
|
|
6851
|
-
log(
|
|
6852
|
-
`[reputation-oracle] Argus response not an object (${agentDid}); using baseline ${baseline}`
|
|
6853
|
-
);
|
|
6854
|
-
return baseline;
|
|
6855
|
-
}
|
|
6856
|
-
const score = body.score;
|
|
6857
|
-
if (typeof score !== "number" || !Number.isFinite(score)) {
|
|
6858
|
-
log(
|
|
6859
|
-
`[reputation-oracle] Argus score not a finite number (${agentDid}): ${String(score)}; using baseline ${baseline}`
|
|
6860
|
-
);
|
|
6861
|
-
return baseline;
|
|
6862
|
-
}
|
|
6863
|
-
if (score < 0 || score > 1) {
|
|
6864
|
-
log(
|
|
6865
|
-
`[reputation-oracle] Argus score out of range (${agentDid}): ${score}; using baseline ${baseline}`
|
|
6866
|
-
);
|
|
6867
|
-
return baseline;
|
|
6868
|
-
}
|
|
6869
|
-
return score;
|
|
6870
|
-
}
|
|
6871
|
-
var DEFAULT_FETCH_TIMEOUT_MS4 = 2e3;
|
|
6872
|
-
var DEFAULT_TTL_MS4 = 6e4;
|
|
6873
|
-
var PERMIT_BY_DEFAULT_POLICY = { reputationThreshold: 0 };
|
|
6874
|
-
function makePolicyEvaluator(opts = {}) {
|
|
6875
|
-
const dashboardUrl = opts.dashboardUrl;
|
|
6876
|
-
const timeoutMs = opts.fetchTimeoutMs ?? DEFAULT_FETCH_TIMEOUT_MS4;
|
|
6877
|
-
const ttlMs = opts.ttlMs ?? DEFAULT_TTL_MS4;
|
|
6878
|
-
const fetchImpl = opts.fetch ?? fetch;
|
|
6879
|
-
const fallbackPolicy = opts.defaultPolicy ?? PERMIT_BY_DEFAULT_POLICY;
|
|
6880
|
-
const cache = opts.cache ?? /* @__PURE__ */ new Map();
|
|
6881
|
-
const now = opts.now ?? (() => Date.now());
|
|
6882
|
-
const log = opts.logger ?? (() => {
|
|
6883
|
-
});
|
|
6884
|
-
return {
|
|
6885
|
-
async evaluate(input) {
|
|
6886
|
-
const policy = await getOrFetchPolicy(
|
|
6887
|
-
input.tenantHost,
|
|
6888
|
-
dashboardUrl,
|
|
6889
|
-
fetchImpl,
|
|
6890
|
-
timeoutMs,
|
|
6891
|
-
fallbackPolicy,
|
|
6892
|
-
cache,
|
|
6893
|
-
ttlMs,
|
|
6894
|
-
now,
|
|
6895
|
-
log
|
|
6896
|
-
);
|
|
6897
|
-
return computeDecision(policy, input);
|
|
6898
|
-
}
|
|
6899
|
-
};
|
|
6900
|
-
}
|
|
6901
|
-
function computeDecision(policy, input) {
|
|
6902
|
-
if (input.reputation < policy.reputationThreshold) {
|
|
6903
|
-
return {
|
|
6904
|
-
kind: "Block",
|
|
6905
|
-
reason: {
|
|
6906
|
-
kind: "LowReputation",
|
|
6907
|
-
score: input.reputation,
|
|
6908
|
-
threshold: policy.reputationThreshold
|
|
6909
|
-
}
|
|
6910
|
-
};
|
|
6911
|
-
}
|
|
6912
|
-
return { kind: "Permit" };
|
|
6913
|
-
}
|
|
6914
|
-
async function getOrFetchPolicy(tenantHost, dashboardUrl, fetchImpl, timeoutMs, fallbackPolicy, cache, ttlMs, now, log) {
|
|
6915
|
-
const cached = cache.get(tenantHost);
|
|
6916
|
-
if (cached && now() - cached.fetchedAt < ttlMs) {
|
|
6917
|
-
return cached.policy;
|
|
6918
|
-
}
|
|
6919
|
-
const cacheFallback = () => {
|
|
6920
|
-
cache.set(tenantHost, { policy: fallbackPolicy, fetchedAt: now() });
|
|
6921
|
-
return fallbackPolicy;
|
|
6922
|
-
};
|
|
6923
|
-
if (!dashboardUrl) {
|
|
6924
|
-
return cacheFallback();
|
|
6925
|
-
}
|
|
6926
|
-
const url = `${dashboardUrl.replace(/\/$/, "")}/api/policy?tenant=${encodeURIComponent(tenantHost)}`;
|
|
6927
|
-
const controller = new AbortController();
|
|
6928
|
-
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
6929
|
-
let response;
|
|
6930
|
-
try {
|
|
6931
|
-
response = await fetchImpl(url, { signal: controller.signal });
|
|
6932
|
-
} catch (cause) {
|
|
6933
|
-
log(`[policy-evaluator] fetch failed (${tenantHost}): ${String(cause)}; using fallback`);
|
|
6934
|
-
return cacheFallback();
|
|
6935
|
-
} finally {
|
|
6936
|
-
clearTimeout(timer);
|
|
6937
|
-
}
|
|
6938
|
-
if (!response.ok) {
|
|
6939
|
-
log(`[policy-evaluator] dashboard HTTP ${response.status} (${tenantHost}); using fallback`);
|
|
6940
|
-
return cacheFallback();
|
|
6941
|
-
}
|
|
6942
|
-
let body;
|
|
6943
|
-
try {
|
|
6944
|
-
body = await response.json();
|
|
6945
|
-
} catch (cause) {
|
|
6946
|
-
log(
|
|
6947
|
-
`[policy-evaluator] dashboard response not JSON (${tenantHost}): ${String(cause)}; using fallback`
|
|
6948
|
-
);
|
|
6949
|
-
return cacheFallback();
|
|
6950
|
-
}
|
|
6951
|
-
const parsed = parseTenantPolicy(body);
|
|
6952
|
-
if (!parsed) {
|
|
6953
|
-
log(`[policy-evaluator] dashboard response malformed (${tenantHost}); using fallback`);
|
|
6954
|
-
return cacheFallback();
|
|
6955
|
-
}
|
|
6956
|
-
cache.set(tenantHost, { policy: parsed, fetchedAt: now() });
|
|
6957
|
-
return parsed;
|
|
6958
|
-
}
|
|
6959
|
-
function parseTenantPolicy(raw) {
|
|
6960
|
-
if (raw === null || typeof raw !== "object") return null;
|
|
6961
|
-
const threshold = raw.reputationThreshold;
|
|
6962
|
-
if (typeof threshold !== "number" || !Number.isFinite(threshold) || threshold < 0 || threshold > 1) {
|
|
6963
|
-
return null;
|
|
6964
|
-
}
|
|
6965
|
-
return { reputationThreshold: threshold };
|
|
6966
|
-
}
|
|
6967
|
-
function makeSystemClock() {
|
|
6968
|
-
return { nowUnix: () => Math.floor(Date.now() / 1e3) };
|
|
6969
|
-
}
|
|
6970
5195
|
function adaptToExpressResponse(rendered, req, res, next) {
|
|
6971
5196
|
const clientAcceptsHtml = acceptsHtml(req.headers);
|
|
6972
5197
|
const verdictCookie = encodeVerdictCookie(rendered);
|