mcard-js 2.1.49 → 2.1.51

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 (109) hide show
  1. package/dist/CardCollection-EMSBVZP3.js +10 -0
  2. package/dist/CardCollection-KQWR4PCV.js +10 -0
  3. package/dist/CardCollection-ORGE2XBG.js +10 -0
  4. package/dist/EngineRegistry-ABZXHZWO.js +17 -0
  5. package/dist/EngineRegistry-EIOT4MUZ.js +17 -0
  6. package/dist/EngineRegistry-IQ6EVO72.js +17 -0
  7. package/dist/EngineRegistry-PHRFXEOE.js +17 -0
  8. package/dist/IndexedDBEngine-EWA3SLAO.js +12 -0
  9. package/dist/IndexedDBEngine-FXAD42F3.js +12 -0
  10. package/dist/IndexedDBEngine-RD4447IS.js +12 -0
  11. package/dist/LLMRuntime-ARUWOX52.js +17 -0
  12. package/dist/LLMRuntime-C3XCO7WF.js +17 -0
  13. package/dist/LLMRuntime-CQ7X43QR.js +17 -0
  14. package/dist/LLMRuntime-PD45COKE.js +17 -0
  15. package/dist/LLMRuntime-QOUMLT33.js +17 -0
  16. package/dist/LLMRuntime-SZNLTHD7.js +17 -0
  17. package/dist/LLMRuntime-TVJGK2BG.js +17 -0
  18. package/dist/LambdaRuntime-25GMEJCU.js +19 -0
  19. package/dist/LambdaRuntime-7KQUMHPI.js +19 -0
  20. package/dist/LambdaRuntime-DRT7ODPC.js +19 -0
  21. package/dist/LambdaRuntime-HSREEYQG.js +19 -0
  22. package/dist/LambdaRuntime-IH7NVG6Z.js +19 -0
  23. package/dist/LambdaRuntime-MPG27FM2.js +19 -0
  24. package/dist/LambdaRuntime-ODSWIMNM.js +19 -0
  25. package/dist/LambdaRuntime-PHGRZYAW.js +19 -0
  26. package/dist/LambdaRuntime-QOEYR37L.js +19 -0
  27. package/dist/LambdaRuntime-RT33TFN2.js +19 -0
  28. package/dist/LambdaRuntime-W6TQBP5O.js +19 -0
  29. package/dist/Loader-35WSUC53.js +14 -0
  30. package/dist/Loader-STS3G4OQ.js +16 -0
  31. package/dist/Loader-W22AEM6F.js +12 -0
  32. package/dist/Loader-YBPWP43S.js +12 -0
  33. package/dist/Loader-ZYSS7B4D.js +12 -0
  34. package/dist/NetworkRuntime-KR2QITXV.js +987 -0
  35. package/dist/NetworkRuntime-S6V2CMZV.js +1575 -0
  36. package/dist/OllamaProvider-2ANW6EB2.js +9 -0
  37. package/dist/OllamaProvider-5QFJKYAC.js +9 -0
  38. package/dist/OllamaProvider-6QXJGR7V.js +9 -0
  39. package/dist/OllamaProvider-ABEEFX7M.js +9 -0
  40. package/dist/OllamaProvider-Z2CGY5LY.js +9 -0
  41. package/dist/VCard-225X42W7.js +25 -0
  42. package/dist/chunk-2APJYBH4.js +368 -0
  43. package/dist/chunk-4DFTWDRB.js +497 -0
  44. package/dist/chunk-4PBRTFSY.js +112 -0
  45. package/dist/chunk-4T3H25AP.js +299 -0
  46. package/dist/chunk-5DFXPIRL.js +42 -0
  47. package/dist/chunk-5HRZV4R3.js +217 -0
  48. package/dist/chunk-6ZRJXVJ3.js +529 -0
  49. package/dist/chunk-7N7JYGN2.js +364 -0
  50. package/dist/chunk-7QTJUGYQ.js +74 -0
  51. package/dist/chunk-7TXIPJI2.js +2360 -0
  52. package/dist/chunk-BFJUD527.js +2369 -0
  53. package/dist/chunk-CHXIVTQV.js +364 -0
  54. package/dist/chunk-DM2ABCA4.js +497 -0
  55. package/dist/chunk-DTPHGTBQ.js +275 -0
  56. package/dist/chunk-EDAJ5FO6.js +405 -0
  57. package/dist/chunk-ETJWXHKZ.js +246 -0
  58. package/dist/chunk-FLYGNPUC.js +2369 -0
  59. package/dist/chunk-FSDRDWOP.js +34 -0
  60. package/dist/chunk-GIKMCG4D.js +497 -0
  61. package/dist/chunk-IJKS3LGK.js +428 -0
  62. package/dist/chunk-JUQ2VQZA.js +428 -0
  63. package/dist/chunk-JVW4J7BY.js +2369 -0
  64. package/dist/chunk-JWTRVEC3.js +2369 -0
  65. package/dist/chunk-KJM4C65U.js +299 -0
  66. package/dist/chunk-KMC566CN.js +591 -0
  67. package/dist/chunk-KMNP6DBL.js +455 -0
  68. package/dist/chunk-LVU7O5IY.js +597 -0
  69. package/dist/chunk-M4C6RWLA.js +373 -0
  70. package/dist/chunk-NAAAKSEO.js +541 -0
  71. package/dist/chunk-NKIXLPHL.js +373 -0
  72. package/dist/chunk-NOEDMK7I.js +428 -0
  73. package/dist/chunk-NOPYSBOQ.js +2360 -0
  74. package/dist/chunk-P4G42QCY.js +2369 -0
  75. package/dist/chunk-PKLONZCF.js +253 -0
  76. package/dist/chunk-PNGECWPN.js +597 -0
  77. package/dist/chunk-PYP6T64W.js +217 -0
  78. package/dist/chunk-QFT3COE2.js +217 -0
  79. package/dist/chunk-QFZFXMNX.js +275 -0
  80. package/dist/chunk-QZGRQRJP.js +2369 -0
  81. package/dist/chunk-R3XRBAM7.js +253 -0
  82. package/dist/chunk-RYP66UMH.js +74 -0
  83. package/dist/chunk-RZIZYRLF.js +112 -0
  84. package/dist/chunk-T43V44RS.js +2369 -0
  85. package/dist/chunk-UCNVX5BZ.js +74 -0
  86. package/dist/chunk-UDF7HS4V.js +368 -0
  87. package/dist/chunk-VJPXJVEH.js +299 -0
  88. package/dist/chunk-VW3KBDK5.js +74 -0
  89. package/dist/chunk-X72XIYSN.js +364 -0
  90. package/dist/chunk-XETU7TV4.js +112 -0
  91. package/dist/chunk-Y4BT6LHA.js +368 -0
  92. package/dist/chunk-YQGB6BIA.js +2369 -0
  93. package/dist/chunk-ZEQPO3XV.js +217 -0
  94. package/dist/chunk-ZKRKWXEQ.js +2369 -0
  95. package/dist/chunk-ZMK2HTZ5.js +275 -0
  96. package/dist/constants-CLB7B6MN.js +101 -0
  97. package/dist/constants-O343SMHL.js +103 -0
  98. package/dist/constants-YPGDEX5X.js +103 -0
  99. package/dist/index.browser.cjs +11 -5
  100. package/dist/index.browser.js +12 -12
  101. package/dist/index.cjs +2358 -1896
  102. package/dist/index.d.cts +934 -776
  103. package/dist/index.d.ts +934 -776
  104. package/dist/index.js +1353 -1271
  105. package/dist/storage/SqliteNodeEngine.cjs +12 -6
  106. package/dist/storage/SqliteNodeEngine.js +4 -4
  107. package/dist/storage/SqliteWasmEngine.cjs +11 -5
  108. package/dist/storage/SqliteWasmEngine.js +4 -4
  109. package/package.json +5 -3
@@ -0,0 +1,529 @@
1
+ import {
2
+ ContentTypeInterpreter,
3
+ MCard,
4
+ createVCardDOTSMetadata
5
+ } from "./chunk-GGQCF7ZK.js";
6
+ import {
7
+ GTime,
8
+ HashValidator
9
+ } from "./chunk-ASW6AOA7.js";
10
+
11
+ // src/model/VCard.ts
12
+ import { parse } from "yaml";
13
+ var CapabilityScope = /* @__PURE__ */ ((CapabilityScope2) => {
14
+ CapabilityScope2["READ"] = "read";
15
+ CapabilityScope2["WRITE"] = "write";
16
+ CapabilityScope2["EXECUTE"] = "execute";
17
+ CapabilityScope2["ADMIN"] = "admin";
18
+ CapabilityScope2["DELEGATE"] = "delegate";
19
+ return CapabilityScope2;
20
+ })(CapabilityScope || {});
21
+ var GatekeeperDirection = /* @__PURE__ */ ((GatekeeperDirection2) => {
22
+ GatekeeperDirection2["INGRESS"] = "ingress";
23
+ GatekeeperDirection2["EGRESS"] = "egress";
24
+ return GatekeeperDirection2;
25
+ })(GatekeeperDirection || {});
26
+ function isVCard(card) {
27
+ try {
28
+ const content = asVCardView(parseVCardContent(card));
29
+ if (content.vcard) return true;
30
+ return content.type === "VCard" || Boolean(content.subjectDid && content.capabilities);
31
+ } catch {
32
+ return false;
33
+ }
34
+ }
35
+ function getPCardRefs(vcard) {
36
+ const content = asVCardView(parseVCardContent(vcard));
37
+ const data = asVCardView(content.vcard || content);
38
+ const verificationRefs = data.verification?.pcard_refs || [];
39
+ const hashes = [];
40
+ for (const r of verificationRefs) {
41
+ if (typeof r === "string") hashes.push(r);
42
+ else if (r.hash) hashes.push(r.hash);
43
+ }
44
+ return hashes;
45
+ }
46
+ function getSubjectDid(vcard) {
47
+ const content = asVCardView(parseVCardContent(vcard));
48
+ const data = asVCardView(content.vcard || content);
49
+ return data.identity?.subject_did || data.subjectDid;
50
+ }
51
+ function parseVCardContent(card) {
52
+ try {
53
+ const text = card.getContentAsText();
54
+ try {
55
+ return JSON.parse(text);
56
+ } catch {
57
+ return parse(text);
58
+ }
59
+ } catch {
60
+ return {};
61
+ }
62
+ }
63
+ function asVCardView(value) {
64
+ return value;
65
+ }
66
+ var VCard = class _VCard extends MCard {
67
+ // Mutable Runtime State (initialized via _initializeMutableState)
68
+ _subjectDid;
69
+ _controllerPubkeys;
70
+ _capabilities;
71
+ _externalRefs;
72
+ _exportManifest;
73
+ _gatekeeperLog;
74
+ _pcardRefsHashes;
75
+ _managedEventTypes;
76
+ _wrappedPcardHash;
77
+ constructor(content, hash, g_time, contentType, hashFunction, initialData) {
78
+ super(content, hash, g_time, contentType, hashFunction);
79
+ this._gatekeeperLog = [];
80
+ this._exportManifest = [];
81
+ this._initializeMutableState(initialData);
82
+ }
83
+ _initializeMutableState(data) {
84
+ const v = asVCardView(data.vcard || data);
85
+ this._subjectDid = v.identity?.subject_did || v.subjectDid || "";
86
+ this._controllerPubkeys = v.identity?.controller_pubkeys || v.controllerPubkeys || [];
87
+ const rawCaps = v.gatekeeper?.capabilities || v.capabilities || [];
88
+ this._capabilities = rawCaps.map((c) => {
89
+ const capabilityId = c.id || c.capabilityId;
90
+ const actorDid = c.actor || c.actorDid;
91
+ const resourcePattern = c.resourcePattern || c.resource_pattern;
92
+ const expiry = c.expiresAt || c.expires_at;
93
+ if (!capabilityId || !actorDid || !c.scope || !resourcePattern) {
94
+ return null;
95
+ }
96
+ return {
97
+ capabilityId,
98
+ actorDid,
99
+ scope: c.scope,
100
+ resourcePattern,
101
+ expiresAt: expiry ? new Date(expiry) : void 0,
102
+ transferable: c.transferable || false,
103
+ constraints: c.constraints
104
+ };
105
+ }).filter((c) => c !== null);
106
+ const rawRefs = v.externalRefs || v.external_refs || [];
107
+ this._externalRefs = rawRefs.map((r) => {
108
+ const uri = r.uri;
109
+ const contentHash = r.contentHash || r.content_hash;
110
+ const status = r.status;
111
+ if (!uri || !contentHash || !status) {
112
+ return null;
113
+ }
114
+ return {
115
+ uri,
116
+ contentHash,
117
+ status,
118
+ qosMetrics: r.qos || r.qosMetrics
119
+ };
120
+ }).filter((r) => r !== null);
121
+ const rawPCardRefs = v.verification?.pcard_refs || [];
122
+ this._pcardRefsHashes = rawPCardRefs.map((r) => typeof r === "string" ? r : r.hash).filter((hash) => typeof hash === "string");
123
+ this._managedEventTypes = v.managed_event_types || [];
124
+ this._wrappedPcardHash = v.wrapped_pcard_hash;
125
+ }
126
+ /**
127
+ * Create a new VCard from parameters.
128
+ * Follows strict UPTV structure { vcard: { ... } }.
129
+ */
130
+ static async createVCard(subjectDid, controllerPubkeys, capabilities = [], externalRefs = [], managedEventTypes = [], wrappedPcardHash, hashAlgorithm = "sha256", extraFields = {}) {
131
+ const structure = {
132
+ vcard: {
133
+ type: "authentication-authorization",
134
+ identity: {
135
+ subject_did: subjectDid,
136
+ controller_pubkeys: controllerPubkeys
137
+ },
138
+ gatekeeper: {
139
+ capabilities: capabilities.map((c) => ({
140
+ id: c.capabilityId,
141
+ actor: c.actorDid,
142
+ scope: c.scope,
143
+ resource_pattern: c.resourcePattern,
144
+ expires_at: c.expiresAt?.toISOString(),
145
+ transferable: c.transferable,
146
+ constraints: c.constraints
147
+ }))
148
+ },
149
+ verification: {
150
+ pcard_refs: []
151
+ // Populated if provided in a separate arg or we filter externalRefs?
152
+ // For now, we assume externalRefs are generic.
153
+ // To strictly follow PCard Logic, we could expose pcardRefs arg, but keeping signature for now.
154
+ },
155
+ external_refs: externalRefs.map((r) => ({
156
+ uri: r.uri,
157
+ content_hash: r.contentHash,
158
+ status: r.status,
159
+ qos: r.qosMetrics
160
+ })),
161
+ managed_event_types: managedEventTypes,
162
+ wrapped_pcard_hash: wrappedPcardHash,
163
+ ...extraFields
164
+ }
165
+ };
166
+ const contentString = JSON.stringify(structure, null, 2);
167
+ const bytes = new TextEncoder().encode(contentString);
168
+ const hash = await HashValidator.computeHash(bytes, hashAlgorithm);
169
+ const g_time = GTime.stampNow(hashAlgorithm);
170
+ const contentType = ContentTypeInterpreter.detect(bytes);
171
+ return new _VCard(bytes, hash, g_time, contentType, hashAlgorithm, structure);
172
+ }
173
+ /**
174
+ * Create a VCard wrapper from an existing MCard.
175
+ */
176
+ static async fromMCard(card) {
177
+ const content = parseVCardContent(card);
178
+ return new _VCard(
179
+ card.content,
180
+ card.hash,
181
+ card.g_time,
182
+ card.contentType,
183
+ card.hashFunction,
184
+ content
185
+ );
186
+ }
187
+ getDOTSMetadata() {
188
+ return createVCardDOTSMetadata();
189
+ }
190
+ // =========================================================================
191
+ // Accessors
192
+ // =========================================================================
193
+ get subjectDid() {
194
+ return this._subjectDid;
195
+ }
196
+ get controllerPubkeys() {
197
+ return this._controllerPubkeys;
198
+ }
199
+ get capabilities() {
200
+ return this._capabilities;
201
+ }
202
+ get externalRefs() {
203
+ return this._externalRefs;
204
+ }
205
+ // =========================================================================
206
+ // Runtime Mutability (Gatekeeper Logic)
207
+ // =========================================================================
208
+ addCapability(capability) {
209
+ this._capabilities.push(capability);
210
+ }
211
+ getValidCapabilities() {
212
+ const now = /* @__PURE__ */ new Date();
213
+ return this._capabilities.filter(
214
+ (c) => c.expiresAt === void 0 || new Date(c.expiresAt) > now
215
+ );
216
+ }
217
+ hasCapability(scope, resourceHash) {
218
+ for (const cap of this.getValidCapabilities()) {
219
+ if (cap.scope === scope) {
220
+ const regex = new RegExp(cap.resourcePattern);
221
+ if (regex.test(resourceHash)) return true;
222
+ }
223
+ }
224
+ return false;
225
+ }
226
+ addPCardReference(pcardHash) {
227
+ if (!this._pcardRefsHashes.includes(pcardHash)) {
228
+ this._pcardRefsHashes.push(pcardHash);
229
+ }
230
+ this.addExternalRef({
231
+ uri: `pcard://${pcardHash}`,
232
+ contentHash: pcardHash,
233
+ status: "verified"
234
+ });
235
+ }
236
+ getPCardReferences() {
237
+ const set = new Set(this._pcardRefsHashes);
238
+ this._externalRefs.forEach((r) => {
239
+ if (r.uri.startsWith("pcard://")) set.add(r.contentHash);
240
+ });
241
+ return Array.from(set);
242
+ }
243
+ addExternalRef(ref) {
244
+ this._externalRefs.push(ref);
245
+ }
246
+ getExternalRefsByStatus(status) {
247
+ return this._externalRefs.filter((r) => r.status === status);
248
+ }
249
+ verifyExternalRef(uri, newHash) {
250
+ for (const ref of this._externalRefs) {
251
+ if (ref.uri === uri) {
252
+ if (ref.contentHash === newHash) {
253
+ ref.status = "verified";
254
+ ref.lastVerified = /* @__PURE__ */ new Date();
255
+ return true;
256
+ } else {
257
+ ref.status = "stale";
258
+ return false;
259
+ }
260
+ }
261
+ }
262
+ return false;
263
+ }
264
+ authorizeIngress(sourceDid, contentHash, capabilityId) {
265
+ let authorized = false;
266
+ let usedCapability;
267
+ for (const cap of this.getValidCapabilities()) {
268
+ if (cap.actorDid === sourceDid && (cap.scope === "write" /* WRITE */ || cap.scope === "admin" /* ADMIN */)) {
269
+ if (capabilityId === void 0 || cap.capabilityId === capabilityId) {
270
+ authorized = true;
271
+ usedCapability = cap.capabilityId;
272
+ break;
273
+ }
274
+ }
275
+ }
276
+ const event = {
277
+ direction: "ingress" /* INGRESS */,
278
+ timestamp: /* @__PURE__ */ new Date(),
279
+ sourceDid,
280
+ contentHash,
281
+ authorized,
282
+ capabilityUsed: usedCapability
283
+ };
284
+ this._gatekeeperLog.push(event);
285
+ return authorized;
286
+ }
287
+ getManagedEventTypes() {
288
+ return this._managedEventTypes || [];
289
+ }
290
+ getWrappedPcardHash() {
291
+ return this._wrappedPcardHash;
292
+ }
293
+ registerForEgress(contentHash) {
294
+ if (!this._exportManifest.includes(contentHash)) {
295
+ this._exportManifest.push(contentHash);
296
+ return true;
297
+ }
298
+ return false;
299
+ }
300
+ authorizeEgress(destinationDid, contentHash, capabilityId) {
301
+ if (!this._exportManifest.includes(contentHash)) {
302
+ this._logEgress(destinationDid, contentHash, false, void 0);
303
+ return false;
304
+ }
305
+ let authorized = false;
306
+ let usedCapability;
307
+ for (const cap of this.getValidCapabilities()) {
308
+ if (cap.scope === "read" /* READ */ || cap.scope === "admin" /* ADMIN */) {
309
+ const regex = new RegExp(cap.resourcePattern);
310
+ if (regex.test(contentHash)) {
311
+ if (capabilityId === void 0 || cap.capabilityId === capabilityId) {
312
+ authorized = true;
313
+ usedCapability = cap.capabilityId;
314
+ break;
315
+ }
316
+ }
317
+ }
318
+ }
319
+ this._logEgress(destinationDid, contentHash, authorized, usedCapability);
320
+ return authorized;
321
+ }
322
+ _logEgress(dst, hash, auth, cap) {
323
+ const event = {
324
+ direction: "egress" /* EGRESS */,
325
+ timestamp: /* @__PURE__ */ new Date(),
326
+ destinationDid: dst,
327
+ contentHash: hash,
328
+ authorized: auth,
329
+ capabilityUsed: cap
330
+ };
331
+ this._gatekeeperLog.push(event);
332
+ }
333
+ getGatekeeperLog(direction) {
334
+ if (direction === void 0) return this._gatekeeperLog;
335
+ return this._gatekeeperLog.filter((e) => e.direction === direction);
336
+ }
337
+ logGatekeeperEvent(event) {
338
+ this._gatekeeperLog.push(event);
339
+ }
340
+ getExportManifest() {
341
+ return [...this._exportManifest];
342
+ }
343
+ // =========================================================================
344
+ // EOS Compliance
345
+ // =========================================================================
346
+ simulateMode() {
347
+ return new VCardSimulation(this);
348
+ }
349
+ // =========================================================================
350
+ // Petri Net Token Semantics
351
+ // =========================================================================
352
+ /**
353
+ * Get the handle where this VCard token currently resides
354
+ *
355
+ * In Petri Net terms, this is the "Place" where the token is located.
356
+ *
357
+ * @returns Handle string if available in content, or hash-based handle
358
+ */
359
+ getTokenHandle() {
360
+ const content = asVCardView(parseVCardContent(this));
361
+ const v = asVCardView(content.vcard || content);
362
+ return v.handle || v.token_handle || `vcard://${this.hash.substring(0, 16)}`;
363
+ }
364
+ /**
365
+ * Check if this VCard is a VerificationVCard (result of PCard execution)
366
+ *
367
+ * VerificationVCards are produced by PCard transitions and contain
368
+ * execution results with provenance chain.
369
+ *
370
+ * @returns True if this is a verification token
371
+ */
372
+ isVerificationVCard() {
373
+ const content = asVCardView(parseVCardContent(this));
374
+ const v = asVCardView(content.vcard || content);
375
+ return v.type === "verification" || v.type === "verification-result" || Boolean(v.verification?.execution_result);
376
+ }
377
+ /**
378
+ * Get the previous hash in the provenance chain
379
+ *
380
+ * In Petri Net terms, this links to the input VCard that was "consumed"
381
+ * when the transition fired to produce this VCard.
382
+ *
383
+ * @returns Previous VCard hash if this is part of a verification cascade
384
+ */
385
+ getPreviousHash() {
386
+ const content = asVCardView(parseVCardContent(this));
387
+ const v = asVCardView(content.vcard || content);
388
+ return v.previous_hash || v.previousHash || v.verification?.previous_hash;
389
+ }
390
+ /**
391
+ * Get the PCard hash that produced this VCard (if verification)
392
+ *
393
+ * This links the output token to the transition that created it.
394
+ *
395
+ * @returns PCard hash that produced this VCard
396
+ */
397
+ getSourcePCardHash() {
398
+ const content = asVCardView(parseVCardContent(this));
399
+ const v = asVCardView(content.vcard || content);
400
+ return v.source_pcard || v.verification?.pcard_hash || v.produced_by;
401
+ }
402
+ /**
403
+ * Create a VerificationVCard from PCard execution result
404
+ *
405
+ * This is the factory method for producing output tokens in the Petri Net.
406
+ *
407
+ * @param pcard - The PCard (Transition) that executed
408
+ * @param result - Execution result
409
+ * @param previousVCard - Input VCard (pre-condition) if any
410
+ * @param success - Whether execution succeeded
411
+ * @returns New VerificationVCard
412
+ */
413
+ static async createVerificationVCard(pcard, result, previousVCard, success = true, hashAlgorithm = "sha256", executionTelemetry) {
414
+ const handle = typeof pcard.getBalancedHandle === "function" ? pcard.getBalancedHandle() : `hash/${pcard.hash.substring(0, 16)}/balanced`;
415
+ const verificationData = {
416
+ pcard_hash: pcard.hash,
417
+ execution_result: result,
418
+ success,
419
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
420
+ previous_hash: previousVCard?.hash
421
+ };
422
+ if (executionTelemetry) {
423
+ verificationData.execution_telemetry = executionTelemetry;
424
+ }
425
+ const structure = {
426
+ vcard: {
427
+ type: "verification",
428
+ handle,
429
+ identity: {
430
+ subject_did: "did:ptr:system",
431
+ controller_pubkeys: []
432
+ },
433
+ verification: verificationData,
434
+ gatekeeper: {
435
+ capabilities: []
436
+ },
437
+ external_refs: []
438
+ }
439
+ };
440
+ const contentString = JSON.stringify(structure, null, 2);
441
+ const bytes = new TextEncoder().encode(contentString);
442
+ const hash = await HashValidator.computeHash(bytes, hashAlgorithm);
443
+ const g_time = GTime.stampNow(hashAlgorithm);
444
+ const contentType = ContentTypeInterpreter.detect(bytes);
445
+ return new _VCard(bytes, hash, g_time, contentType, hashAlgorithm, structure);
446
+ }
447
+ /**
448
+ * Check if this VCard enables a specific PCard to fire
449
+ *
450
+ * @param requiredHandle - The handle where a precondition VCard must exist
451
+ * @returns True if this VCard satisfies that precondition
452
+ */
453
+ enablesTransition(requiredHandle) {
454
+ const myHandle = this.getTokenHandle();
455
+ return myHandle === requiredHandle;
456
+ }
457
+ // =========================================================================
458
+ // VCard Sandwich methods have been extracted to VCardSandwich.ts
459
+ // =========================================================================
460
+ };
461
+ var VCardSimulation = class {
462
+ vcard;
463
+ log;
464
+ constructor(vcard) {
465
+ this.vcard = vcard;
466
+ this.log = [];
467
+ }
468
+ logEffect(effectType, details) {
469
+ this.log.push({
470
+ timestamp: /* @__PURE__ */ new Date(),
471
+ effectType,
472
+ details,
473
+ simulated: true
474
+ });
475
+ }
476
+ getSimulationLog() {
477
+ return this.log;
478
+ }
479
+ };
480
+ var VCardPre = class extends VCard {
481
+ fireHook(eventType, mcard) {
482
+ if (this.getManagedEventTypes().includes(eventType)) {
483
+ this.logGatekeeperEvent({
484
+ direction: "ingress" /* INGRESS */,
485
+ timestamp: /* @__PURE__ */ new Date(),
486
+ sourceDid: void 0,
487
+ destinationDid: this.subjectDid || "unknown",
488
+ contentHash: mcard.hash,
489
+ authorized: true,
490
+ capabilityUsed: "VCardPre_Hook"
491
+ });
492
+ }
493
+ }
494
+ };
495
+ var VCardPost = class extends VCard {
496
+ dispatchEvents(logDb) {
497
+ const dispatchedCards = [];
498
+ for (const eventType of this.getManagedEventTypes()) {
499
+ const payload = JSON.stringify({ type: eventType, dispatched_by: this.hash });
500
+ const encoder = new TextEncoder();
501
+ if (logDb && typeof logDb.add === "function") {
502
+ logDb.add({ type: eventType, payload, dispatchedBy: this.hash });
503
+ }
504
+ dispatchedCards.push(new MCard(encoder.encode(payload), "temp-hash-" + Date.now(), "temp-time", "application/json", "sha256"));
505
+ this.logGatekeeperEvent({
506
+ direction: "egress" /* EGRESS */,
507
+ timestamp: /* @__PURE__ */ new Date(),
508
+ sourceDid: this.subjectDid || "unknown",
509
+ destinationDid: void 0,
510
+ contentHash: "temp-hash-" + Date.now(),
511
+ authorized: true,
512
+ capabilityUsed: "VCardPost_Dispatch"
513
+ });
514
+ }
515
+ return dispatchedCards;
516
+ }
517
+ };
518
+
519
+ export {
520
+ CapabilityScope,
521
+ GatekeeperDirection,
522
+ isVCard,
523
+ getPCardRefs,
524
+ getSubjectDid,
525
+ VCard,
526
+ VCardSimulation,
527
+ VCardPre,
528
+ VCardPost
529
+ };