@kya-os/mcp-i-core 1.1.0 → 1.1.1-canary.0
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/dist/__tests__/utils/mock-providers.d.ts +102 -0
- package/dist/__tests__/utils/mock-providers.d.ts.map +1 -0
- package/dist/__tests__/utils/mock-providers.js +270 -0
- package/dist/__tests__/utils/mock-providers.js.map +1 -0
- package/dist/cache/tool-protection-cache.d.ts +73 -0
- package/dist/cache/tool-protection-cache.d.ts.map +1 -0
- package/dist/cache/tool-protection-cache.js +83 -0
- package/dist/cache/tool-protection-cache.js.map +1 -0
- package/dist/compliance/index.d.ts +8 -0
- package/dist/compliance/index.d.ts.map +1 -0
- package/dist/compliance/index.js +24 -0
- package/dist/compliance/index.js.map +1 -0
- package/dist/compliance/schema-registry.d.ts +50 -0
- package/dist/compliance/schema-registry.d.ts.map +1 -0
- package/dist/compliance/schema-registry.js +438 -0
- package/dist/compliance/schema-registry.js.map +1 -0
- package/dist/compliance/schema-verifier-v2.d.ts +110 -0
- package/dist/compliance/schema-verifier-v2.d.ts.map +1 -0
- package/dist/compliance/schema-verifier-v2.js +510 -0
- package/dist/compliance/schema-verifier-v2.js.map +1 -0
- package/dist/compliance/schema-verifier.d.ts +110 -0
- package/dist/compliance/schema-verifier.d.ts.map +1 -0
- package/dist/compliance/schema-verifier.js +518 -0
- package/dist/compliance/schema-verifier.js.map +1 -0
- package/dist/delegation/bitstring.d.ts +139 -0
- package/dist/delegation/bitstring.d.ts.map +1 -0
- package/dist/delegation/bitstring.js +213 -0
- package/dist/delegation/bitstring.js.map +1 -0
- package/dist/delegation/cascading-revocation.d.ts +162 -0
- package/dist/delegation/cascading-revocation.d.ts.map +1 -0
- package/dist/delegation/cascading-revocation.js +263 -0
- package/dist/delegation/cascading-revocation.js.map +1 -0
- package/dist/delegation/delegation-graph.d.ts +178 -0
- package/dist/delegation/delegation-graph.d.ts.map +1 -0
- package/dist/delegation/delegation-graph.js +209 -0
- package/dist/delegation/delegation-graph.js.map +1 -0
- package/dist/delegation/index.d.ts +14 -0
- package/dist/delegation/index.d.ts.map +1 -0
- package/dist/delegation/index.js +30 -0
- package/dist/delegation/index.js.map +1 -0
- package/dist/delegation/statuslist-manager.d.ts +148 -0
- package/dist/delegation/statuslist-manager.d.ts.map +1 -0
- package/dist/delegation/statuslist-manager.js +221 -0
- package/dist/delegation/statuslist-manager.js.map +1 -0
- package/dist/delegation/storage/index.d.ts +9 -0
- package/dist/delegation/storage/index.d.ts.map +1 -0
- package/dist/delegation/storage/index.js +25 -0
- package/dist/delegation/storage/index.js.map +1 -0
- package/dist/delegation/storage/memory-graph-storage.d.ts +70 -0
- package/dist/delegation/storage/memory-graph-storage.d.ts.map +1 -0
- package/dist/delegation/storage/memory-graph-storage.js +149 -0
- package/dist/delegation/storage/memory-graph-storage.js.map +1 -0
- package/dist/delegation/storage/memory-statuslist-storage.d.ts +49 -0
- package/dist/delegation/storage/memory-statuslist-storage.d.ts.map +1 -0
- package/dist/delegation/storage/memory-statuslist-storage.js +67 -0
- package/dist/delegation/storage/memory-statuslist-storage.js.map +1 -0
- package/dist/delegation/utils.d.ts +19 -0
- package/dist/delegation/utils.d.ts.map +1 -0
- package/dist/delegation/utils.js +48 -0
- package/dist/delegation/utils.js.map +1 -0
- package/dist/delegation/vc-issuer.d.ts +135 -0
- package/dist/delegation/vc-issuer.d.ts.map +1 -0
- package/dist/delegation/vc-issuer.js +140 -0
- package/dist/delegation/vc-issuer.js.map +1 -0
- package/dist/delegation/vc-verifier.d.ts +213 -0
- package/dist/delegation/vc-verifier.d.ts.map +1 -0
- package/dist/delegation/vc-verifier.js +354 -0
- package/dist/delegation/vc-verifier.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +64 -1
- package/dist/index.js.map +1 -1
- package/dist/providers/base.d.ts +1 -1
- package/dist/providers/base.d.ts.map +1 -1
- package/dist/providers/memory.js +2 -2
- package/dist/providers/memory.js.map +1 -1
- package/dist/runtime/base.d.ts +12 -0
- package/dist/runtime/base.d.ts.map +1 -1
- package/dist/runtime/base.js +96 -2
- package/dist/runtime/base.js.map +1 -1
- package/dist/services/tool-protection.service.d.ts +55 -0
- package/dist/services/tool-protection.service.d.ts.map +1 -0
- package/dist/services/tool-protection.service.js +158 -0
- package/dist/services/tool-protection.service.js.map +1 -0
- package/dist/types/tool-protection.d.ts +103 -0
- package/dist/types/tool-protection.d.ts.map +1 -0
- package/dist/types/tool-protection.js +41 -0
- package/dist/types/tool-protection.js.map +1 -0
- package/dist/utils/cors.d.ts +44 -0
- package/dist/utils/cors.d.ts.map +1 -0
- package/dist/utils/cors.js +71 -0
- package/dist/utils/cors.js.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +21 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +9 -6
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* StatusList2021 Manager
|
|
4
|
+
*
|
|
5
|
+
* Manages StatusList2021 credentials for efficient delegation revocation.
|
|
6
|
+
* Follows the Python POC design from Delegation-Revocation.md.
|
|
7
|
+
*
|
|
8
|
+
* SOLID Principles:
|
|
9
|
+
* - Single Responsibility: Manages status list allocation and updates
|
|
10
|
+
* - Open/Closed: Extensible via storage provider interface
|
|
11
|
+
* - Liskov Substitution: Any storage provider can be used
|
|
12
|
+
* - Interface Segregation: Minimal storage interface
|
|
13
|
+
* - Dependency Inversion: Depends on abstractions (storage, signing)
|
|
14
|
+
*
|
|
15
|
+
* Related Spec: W3C StatusList2021
|
|
16
|
+
* Python Reference: Delegation-Revocation.md
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.StatusList2021Manager = void 0;
|
|
20
|
+
exports.createStatusListManager = createStatusListManager;
|
|
21
|
+
const bitstring_1 = require("./bitstring");
|
|
22
|
+
const utils_1 = require("./utils");
|
|
23
|
+
/**
|
|
24
|
+
* StatusList2021 Manager
|
|
25
|
+
*
|
|
26
|
+
* Manages status lists for efficient delegation revocation.
|
|
27
|
+
* Per Delegation-Revocation.md:
|
|
28
|
+
* - StatusList2021 for efficient revocation distribution
|
|
29
|
+
* - Compressed bitstrings for scalability
|
|
30
|
+
* - Separate lists for revocation vs suspension
|
|
31
|
+
*/
|
|
32
|
+
class StatusList2021Manager {
|
|
33
|
+
storage;
|
|
34
|
+
identity;
|
|
35
|
+
signingFunction;
|
|
36
|
+
compressor;
|
|
37
|
+
decompressor;
|
|
38
|
+
statusListBaseUrl;
|
|
39
|
+
defaultListSize;
|
|
40
|
+
constructor(storage, identity, signingFunction, compressor, decompressor, options) {
|
|
41
|
+
this.storage = storage;
|
|
42
|
+
this.identity = identity;
|
|
43
|
+
this.signingFunction = signingFunction;
|
|
44
|
+
this.compressor = compressor;
|
|
45
|
+
this.decompressor = decompressor;
|
|
46
|
+
this.statusListBaseUrl = options?.statusListBaseUrl || 'https://status.example.com';
|
|
47
|
+
this.defaultListSize = options?.defaultListSize || 131072; // 128K entries (16KB compressed)
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Allocate a status entry for a new delegation credential
|
|
51
|
+
*
|
|
52
|
+
* Per Delegation-Revocation.md: Each delegation gets a unique status list entry.
|
|
53
|
+
*
|
|
54
|
+
* @param purpose - "revocation" or "suspension"
|
|
55
|
+
* @returns CredentialStatus entry for the delegation VC
|
|
56
|
+
*/
|
|
57
|
+
async allocateStatusEntry(purpose) {
|
|
58
|
+
// Determine which status list to use
|
|
59
|
+
const statusListId = `${this.statusListBaseUrl}/${purpose}/v1`;
|
|
60
|
+
// Allocate index in the status list (thread-safe)
|
|
61
|
+
const index = await this.storage.allocateIndex(statusListId);
|
|
62
|
+
// Ensure the status list exists
|
|
63
|
+
await this.ensureStatusListExists(statusListId, purpose);
|
|
64
|
+
// Create the credential status entry
|
|
65
|
+
const credentialStatus = {
|
|
66
|
+
id: `${statusListId}#${index}`,
|
|
67
|
+
type: 'StatusList2021Entry',
|
|
68
|
+
statusPurpose: purpose,
|
|
69
|
+
statusListIndex: index.toString(),
|
|
70
|
+
statusListCredential: statusListId,
|
|
71
|
+
};
|
|
72
|
+
return credentialStatus;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Revoke or suspend a delegation by updating its status
|
|
76
|
+
*
|
|
77
|
+
* @param credentialStatus - The credential status entry from the VC
|
|
78
|
+
* @param revoked - true to revoke/suspend, false to restore
|
|
79
|
+
*/
|
|
80
|
+
async updateStatus(credentialStatus, revoked) {
|
|
81
|
+
const { statusListCredential, statusListIndex } = credentialStatus;
|
|
82
|
+
// Get the current status list
|
|
83
|
+
const statusList = await this.storage.getStatusList(statusListCredential);
|
|
84
|
+
if (!statusList) {
|
|
85
|
+
throw new Error(`Status list not found: ${statusListCredential}`);
|
|
86
|
+
}
|
|
87
|
+
// Decode the bitstring
|
|
88
|
+
const manager = await bitstring_1.BitstringManager.decode(statusList.credentialSubject.encodedList, this.compressor, this.decompressor);
|
|
89
|
+
// Update the bit
|
|
90
|
+
const index = parseInt(statusListIndex, 10);
|
|
91
|
+
manager.setBit(index, revoked);
|
|
92
|
+
// Re-encode
|
|
93
|
+
const encodedList = await manager.encode();
|
|
94
|
+
// Update the credential
|
|
95
|
+
const updatedCredential = {
|
|
96
|
+
...statusList,
|
|
97
|
+
credentialSubject: {
|
|
98
|
+
...statusList.credentialSubject,
|
|
99
|
+
encodedList,
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
// Re-sign the credential (proof changes when content changes)
|
|
103
|
+
const unsignedCredential = { ...updatedCredential };
|
|
104
|
+
delete unsignedCredential.proof;
|
|
105
|
+
const canonicalVC = (0, utils_1.canonicalizeJSON)(unsignedCredential);
|
|
106
|
+
const proof = await this.signingFunction(canonicalVC, this.identity.getDid(), this.identity.getKeyId());
|
|
107
|
+
const signedCredential = {
|
|
108
|
+
...updatedCredential,
|
|
109
|
+
proof,
|
|
110
|
+
};
|
|
111
|
+
// Save the updated status list
|
|
112
|
+
await this.storage.setStatusList(statusListCredential, signedCredential);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Check if a credential is revoked
|
|
116
|
+
*
|
|
117
|
+
* @param credentialStatus - The credential status entry
|
|
118
|
+
* @returns true if revoked/suspended, false otherwise
|
|
119
|
+
*/
|
|
120
|
+
async checkStatus(credentialStatus) {
|
|
121
|
+
const { statusListCredential, statusListIndex } = credentialStatus;
|
|
122
|
+
// Get the status list
|
|
123
|
+
const statusList = await this.storage.getStatusList(statusListCredential);
|
|
124
|
+
if (!statusList) {
|
|
125
|
+
// Status list doesn't exist = not revoked
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
// Decode and check the bit
|
|
129
|
+
const manager = await bitstring_1.BitstringManager.decode(statusList.credentialSubject.encodedList, this.compressor, this.decompressor);
|
|
130
|
+
const index = parseInt(statusListIndex, 10);
|
|
131
|
+
return manager.getBit(index);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Get all revoked indices in a status list
|
|
135
|
+
*
|
|
136
|
+
* Useful for debugging or auditing.
|
|
137
|
+
*
|
|
138
|
+
* @param statusListId - The status list URL
|
|
139
|
+
* @returns Array of revoked indices
|
|
140
|
+
*/
|
|
141
|
+
async getRevokedIndices(statusListId) {
|
|
142
|
+
const statusList = await this.storage.getStatusList(statusListId);
|
|
143
|
+
if (!statusList) {
|
|
144
|
+
return [];
|
|
145
|
+
}
|
|
146
|
+
const manager = await bitstring_1.BitstringManager.decode(statusList.credentialSubject.encodedList, this.compressor, this.decompressor);
|
|
147
|
+
return manager.getSetBits();
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Ensure a status list exists, creating it if needed
|
|
151
|
+
*
|
|
152
|
+
* @param statusListId - The status list URL
|
|
153
|
+
* @param purpose - "revocation" or "suspension"
|
|
154
|
+
*/
|
|
155
|
+
async ensureStatusListExists(statusListId, purpose) {
|
|
156
|
+
// Check if it already exists
|
|
157
|
+
const existing = await this.storage.getStatusList(statusListId);
|
|
158
|
+
if (existing) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
// Create a new status list
|
|
162
|
+
const manager = new bitstring_1.BitstringManager(this.defaultListSize, this.compressor, this.decompressor);
|
|
163
|
+
const encodedList = await manager.encode();
|
|
164
|
+
// Create the unsigned credential
|
|
165
|
+
const unsignedCredential = {
|
|
166
|
+
'@context': [
|
|
167
|
+
'https://www.w3.org/2018/credentials/v1',
|
|
168
|
+
'https://w3id.org/vc/status-list/2021/v1',
|
|
169
|
+
],
|
|
170
|
+
id: statusListId,
|
|
171
|
+
type: ['VerifiableCredential', 'StatusList2021Credential'],
|
|
172
|
+
issuer: this.identity.getDid(),
|
|
173
|
+
issuanceDate: new Date().toISOString(),
|
|
174
|
+
credentialSubject: {
|
|
175
|
+
id: `${statusListId}#list`,
|
|
176
|
+
type: 'StatusList2021',
|
|
177
|
+
statusPurpose: purpose,
|
|
178
|
+
encodedList,
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
// Sign it
|
|
182
|
+
const canonicalVC = (0, utils_1.canonicalizeJSON)(unsignedCredential);
|
|
183
|
+
const proof = await this.signingFunction(canonicalVC, this.identity.getDid(), this.identity.getKeyId());
|
|
184
|
+
const signedCredential = {
|
|
185
|
+
...unsignedCredential,
|
|
186
|
+
proof,
|
|
187
|
+
};
|
|
188
|
+
// Store it
|
|
189
|
+
await this.storage.setStatusList(statusListId, signedCredential);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Get the status list base URL
|
|
193
|
+
*/
|
|
194
|
+
getStatusListBaseUrl() {
|
|
195
|
+
return this.statusListBaseUrl;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Get the default list size
|
|
199
|
+
*/
|
|
200
|
+
getDefaultListSize() {
|
|
201
|
+
return this.defaultListSize;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
exports.StatusList2021Manager = StatusList2021Manager;
|
|
205
|
+
/**
|
|
206
|
+
* Create a StatusList2021 manager
|
|
207
|
+
*
|
|
208
|
+
* Convenience factory function.
|
|
209
|
+
*
|
|
210
|
+
* @param storage - Storage provider
|
|
211
|
+
* @param identity - Identity provider
|
|
212
|
+
* @param signingFunction - VC signing function
|
|
213
|
+
* @param compressor - Compression function
|
|
214
|
+
* @param decompressor - Decompression function
|
|
215
|
+
* @param options - Manager options
|
|
216
|
+
* @returns StatusList2021Manager instance
|
|
217
|
+
*/
|
|
218
|
+
function createStatusListManager(storage, identity, signingFunction, compressor, decompressor, options) {
|
|
219
|
+
return new StatusList2021Manager(storage, identity, signingFunction, compressor, decompressor, options);
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=statuslist-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"statuslist-manager.js","sourceRoot":"","sources":["../../src/delegation/statuslist-manager.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AA8TH,0DAmBC;AA3UD,2CAA2F;AAE3F,mCAA2C;AAkD3C;;;;;;;;GAQG;AACH,MAAa,qBAAqB;IAKtB;IACA;IACA;IACA;IACA;IARF,iBAAiB,CAAS;IAC1B,eAAe,CAAS;IAEhC,YACU,OAAkC,EAClC,QAAoC,EACpC,eAAkC,EAClC,UAA+B,EAC/B,YAAmC,EAC3C,OAKC;QAVO,YAAO,GAAP,OAAO,CAA2B;QAClC,aAAQ,GAAR,QAAQ,CAA4B;QACpC,oBAAe,GAAf,eAAe,CAAmB;QAClC,eAAU,GAAV,UAAU,CAAqB;QAC/B,iBAAY,GAAZ,YAAY,CAAuB;QAQ3C,IAAI,CAAC,iBAAiB,GAAG,OAAO,EAAE,iBAAiB,IAAI,4BAA4B,CAAC;QACpF,IAAI,CAAC,eAAe,GAAG,OAAO,EAAE,eAAe,IAAI,MAAM,CAAC,CAAC,iCAAiC;IAC9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AI,IAAI,EAAE,CAAC,WAAW,EAAE;YACtC,iBAAiB,EAAE;gBACjB,EAAE,EAAE,GAAG,YAAY,OAAO;gBAC1B,IAAI,EAAE,gBAAyB;gBAC/B,aAAa,EAAE,OAAO;gBACtB,WAAW;aACZ;SACF,CAAC;QAEF,UAAU;QACV,MAAM,WAAW,GAAG,IAAA,wBAAgB,EAAC,kBAAkB,CAAC,CAAC;QACzD,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,eAAe,CACtC,WAAW,EACX,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,EACtB,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CACzB,CAAC;QAEF,MAAM,gBAAgB,GAA6B;YACjD,GAAG,kBAAkB;YACrB,KAAK;SACN,CAAC;QAEF,WAAW;QACX,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC;IACnE,CAAC;IAED;;OAEG;IACH,oBAAoB;QAClB,OAAO,IAAI,CAAC,iBAAiB,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,kBAAkB;QAChB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;CACF;AA5OD,sDA4OC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,uBAAuB,CACrC,OAAkC,EAClC,QAAoC,EACpC,eAAkC,EAClC,UAA+B,EAC/B,YAAmC,EACnC,OAGC;IAED,OAAO,IAAI,qBAAqB,CAC9B,OAAO,EACP,QAAQ,EACR,eAAe,EACf,UAAU,EACV,YAAY,EACZ,OAAO,CACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage Implementations
|
|
3
|
+
*
|
|
4
|
+
* Example storage providers for testing and development.
|
|
5
|
+
* Production implementations would use persistent storage (KV, DB, etc.)
|
|
6
|
+
*/
|
|
7
|
+
export * from './memory-statuslist-storage';
|
|
8
|
+
export * from './memory-graph-storage';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/delegation/storage/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Storage Implementations
|
|
4
|
+
*
|
|
5
|
+
* Example storage providers for testing and development.
|
|
6
|
+
* Production implementations would use persistent storage (KV, DB, etc.)
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
__exportStar(require("./memory-statuslist-storage"), exports);
|
|
24
|
+
__exportStar(require("./memory-graph-storage"), exports);
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/delegation/storage/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,8DAA4C;AAC5C,yDAAuC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-Memory Delegation Graph Storage Provider
|
|
3
|
+
*
|
|
4
|
+
* Memory-based implementation for testing and development.
|
|
5
|
+
* NOT suitable for production (no persistence).
|
|
6
|
+
*
|
|
7
|
+
* SOLID: Implements DelegationGraphStorageProvider interface
|
|
8
|
+
*/
|
|
9
|
+
import type { DelegationGraphStorageProvider, DelegationNode } from '../delegation-graph';
|
|
10
|
+
/**
|
|
11
|
+
* Memory-based Delegation Graph storage
|
|
12
|
+
*
|
|
13
|
+
* Stores delegation nodes in memory with efficient graph queries.
|
|
14
|
+
* Useful for:
|
|
15
|
+
* - Unit tests
|
|
16
|
+
* - Integration tests
|
|
17
|
+
* - Development/debugging
|
|
18
|
+
* - Examples
|
|
19
|
+
*/
|
|
20
|
+
export declare class MemoryDelegationGraphStorage implements DelegationGraphStorageProvider {
|
|
21
|
+
private nodes;
|
|
22
|
+
/**
|
|
23
|
+
* Get a delegation node by ID
|
|
24
|
+
*/
|
|
25
|
+
getNode(delegationId: string): Promise<DelegationNode | null>;
|
|
26
|
+
/**
|
|
27
|
+
* Save a delegation node
|
|
28
|
+
*/
|
|
29
|
+
setNode(node: DelegationNode): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Get all children of a delegation
|
|
32
|
+
*/
|
|
33
|
+
getChildren(delegationId: string): Promise<DelegationNode[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Get the full chain from root to this delegation
|
|
36
|
+
*/
|
|
37
|
+
getChain(delegationId: string): Promise<DelegationNode[]>;
|
|
38
|
+
/**
|
|
39
|
+
* Get all descendants (children, grandchildren, etc.)
|
|
40
|
+
*
|
|
41
|
+
* Uses BFS for efficiency.
|
|
42
|
+
*/
|
|
43
|
+
getDescendants(delegationId: string): Promise<DelegationNode[]>;
|
|
44
|
+
/**
|
|
45
|
+
* Delete a node
|
|
46
|
+
*/
|
|
47
|
+
deleteNode(delegationId: string): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Clear all data (for testing)
|
|
50
|
+
*/
|
|
51
|
+
clear(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Get all node IDs (for testing)
|
|
54
|
+
*/
|
|
55
|
+
getAllNodeIds(): string[];
|
|
56
|
+
/**
|
|
57
|
+
* Get graph statistics (for testing/debugging)
|
|
58
|
+
*/
|
|
59
|
+
getStats(): {
|
|
60
|
+
totalNodes: number;
|
|
61
|
+
rootNodes: number;
|
|
62
|
+
leafNodes: number;
|
|
63
|
+
maxDepth: number;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Synchronous chain retrieval (for stats)
|
|
67
|
+
*/
|
|
68
|
+
private getChainSync;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=memory-graph-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-graph-storage.d.ts","sourceRoot":"","sources":["../../../src/delegation/storage/memory-graph-storage.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,8BAA8B,EAC9B,cAAc,EACf,MAAM,qBAAqB,CAAC;AAE7B;;;;;;;;;GASG;AACH,qBAAa,4BACX,YAAW,8BAA8B;IAEzC,OAAO,CAAC,KAAK,CAAqC;IAElD;;OAEG;IACG,OAAO,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAInE;;OAEG;IACG,OAAO,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlD;;OAEG;IACG,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IASlE;;OAEG;IACG,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAgB/D;;;;OAIG;IACG,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IA+BrE;;OAEG;IACG,UAAU,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrD;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,aAAa,IAAI,MAAM,EAAE;IAIzB;;OAEG;IACH,QAAQ,IAAI;QACV,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;KAClB;IAqBD;;OAEG;IACH,OAAO,CAAC,YAAY;CAcrB"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* In-Memory Delegation Graph Storage Provider
|
|
4
|
+
*
|
|
5
|
+
* Memory-based implementation for testing and development.
|
|
6
|
+
* NOT suitable for production (no persistence).
|
|
7
|
+
*
|
|
8
|
+
* SOLID: Implements DelegationGraphStorageProvider interface
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.MemoryDelegationGraphStorage = void 0;
|
|
12
|
+
/**
|
|
13
|
+
* Memory-based Delegation Graph storage
|
|
14
|
+
*
|
|
15
|
+
* Stores delegation nodes in memory with efficient graph queries.
|
|
16
|
+
* Useful for:
|
|
17
|
+
* - Unit tests
|
|
18
|
+
* - Integration tests
|
|
19
|
+
* - Development/debugging
|
|
20
|
+
* - Examples
|
|
21
|
+
*/
|
|
22
|
+
class MemoryDelegationGraphStorage {
|
|
23
|
+
nodes = new Map();
|
|
24
|
+
/**
|
|
25
|
+
* Get a delegation node by ID
|
|
26
|
+
*/
|
|
27
|
+
async getNode(delegationId) {
|
|
28
|
+
return this.nodes.get(delegationId) || null;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Save a delegation node
|
|
32
|
+
*/
|
|
33
|
+
async setNode(node) {
|
|
34
|
+
this.nodes.set(node.id, node);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get all children of a delegation
|
|
38
|
+
*/
|
|
39
|
+
async getChildren(delegationId) {
|
|
40
|
+
const parent = this.nodes.get(delegationId);
|
|
41
|
+
if (!parent)
|
|
42
|
+
return [];
|
|
43
|
+
return parent.children
|
|
44
|
+
.map((childId) => this.nodes.get(childId))
|
|
45
|
+
.filter((node) => node !== undefined);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get the full chain from root to this delegation
|
|
49
|
+
*/
|
|
50
|
+
async getChain(delegationId) {
|
|
51
|
+
const chain = [];
|
|
52
|
+
let currentId = delegationId;
|
|
53
|
+
// Walk up the tree to root
|
|
54
|
+
while (currentId) {
|
|
55
|
+
const node = this.nodes.get(currentId);
|
|
56
|
+
if (!node)
|
|
57
|
+
break;
|
|
58
|
+
chain.unshift(node); // Add to front (root first)
|
|
59
|
+
currentId = node.parentId;
|
|
60
|
+
}
|
|
61
|
+
return chain;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get all descendants (children, grandchildren, etc.)
|
|
65
|
+
*
|
|
66
|
+
* Uses BFS for efficiency.
|
|
67
|
+
*/
|
|
68
|
+
async getDescendants(delegationId) {
|
|
69
|
+
const descendants = [];
|
|
70
|
+
const queue = [delegationId];
|
|
71
|
+
const visited = new Set();
|
|
72
|
+
while (queue.length > 0) {
|
|
73
|
+
const currentId = queue.shift();
|
|
74
|
+
// Skip if already visited (prevent infinite loops)
|
|
75
|
+
if (visited.has(currentId))
|
|
76
|
+
continue;
|
|
77
|
+
visited.add(currentId);
|
|
78
|
+
const node = this.nodes.get(currentId);
|
|
79
|
+
if (!node)
|
|
80
|
+
continue;
|
|
81
|
+
// Add children to queue
|
|
82
|
+
for (const childId of node.children) {
|
|
83
|
+
if (!visited.has(childId)) {
|
|
84
|
+
queue.push(childId);
|
|
85
|
+
const childNode = this.nodes.get(childId);
|
|
86
|
+
if (childNode) {
|
|
87
|
+
descendants.push(childNode);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return descendants;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Delete a node
|
|
96
|
+
*/
|
|
97
|
+
async deleteNode(delegationId) {
|
|
98
|
+
this.nodes.delete(delegationId);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Clear all data (for testing)
|
|
102
|
+
*/
|
|
103
|
+
clear() {
|
|
104
|
+
this.nodes.clear();
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get all node IDs (for testing)
|
|
108
|
+
*/
|
|
109
|
+
getAllNodeIds() {
|
|
110
|
+
return Array.from(this.nodes.keys());
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Get graph statistics (for testing/debugging)
|
|
114
|
+
*/
|
|
115
|
+
getStats() {
|
|
116
|
+
const nodes = Array.from(this.nodes.values());
|
|
117
|
+
const rootNodes = nodes.filter((n) => n.parentId === null).length;
|
|
118
|
+
const leafNodes = nodes.filter((n) => n.children.length === 0).length;
|
|
119
|
+
// Calculate max depth
|
|
120
|
+
let maxDepth = 0;
|
|
121
|
+
for (const node of nodes) {
|
|
122
|
+
const chain = this.getChainSync(node.id);
|
|
123
|
+
maxDepth = Math.max(maxDepth, chain.length - 1);
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
totalNodes: nodes.length,
|
|
127
|
+
rootNodes,
|
|
128
|
+
leafNodes,
|
|
129
|
+
maxDepth,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Synchronous chain retrieval (for stats)
|
|
134
|
+
*/
|
|
135
|
+
getChainSync(delegationId) {
|
|
136
|
+
const chain = [];
|
|
137
|
+
let currentId = delegationId;
|
|
138
|
+
while (currentId) {
|
|
139
|
+
const node = this.nodes.get(currentId);
|
|
140
|
+
if (!node)
|
|
141
|
+
break;
|
|
142
|
+
chain.unshift(node);
|
|
143
|
+
currentId = node.parentId;
|
|
144
|
+
}
|
|
145
|
+
return chain;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.MemoryDelegationGraphStorage = MemoryDelegationGraphStorage;
|
|
149
|
+
//# sourceMappingURL=memory-graph-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-graph-storage.js","sourceRoot":"","sources":["../../../src/delegation/storage/memory-graph-storage.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAOH;;;;;;;;;GASG;AACH,MAAa,4BAA4B;IAG/B,KAAK,GAAG,IAAI,GAAG,EAA0B,CAAC;IAElD;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,YAAoB;QAChC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,IAAI,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,IAAoB;QAChC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW,CAAC,YAAoB;QACpC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAC5C,IAAI,CAAC,MAAM;YAAE,OAAO,EAAE,CAAC;QAEvB,OAAO,MAAM,CAAC,QAAQ;aACnB,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;aACzC,MAAM,CAAC,CAAC,IAAI,EAA0B,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;IAClE,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ,CAAC,YAAoB;QACjC,MAAM,KAAK,GAAqB,EAAE,CAAC;QACnC,IAAI,SAAS,GAAkB,YAAY,CAAC;QAE5C,2BAA2B;QAC3B,OAAO,SAAS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AkB,YAAY,CAAC;QAE5C,OAAO,SAAS,EAAE,CAAC;YACjB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YACvC,IAAI,CAAC,IAAI;gBAAE,MAAM;YAEjB,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACpB,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC5B,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAzJD,oEAyJC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-Memory StatusList Storage Provider
|
|
3
|
+
*
|
|
4
|
+
* Memory-based implementation for testing and development.
|
|
5
|
+
* NOT suitable for production (no persistence).
|
|
6
|
+
*
|
|
7
|
+
* SOLID: Implements StatusListStorageProvider interface
|
|
8
|
+
*/
|
|
9
|
+
import type { StatusList2021Credential } from '@kya-os/contracts';
|
|
10
|
+
import type { StatusListStorageProvider } from '../statuslist-manager';
|
|
11
|
+
/**
|
|
12
|
+
* Memory-based StatusList storage
|
|
13
|
+
*
|
|
14
|
+
* Stores status lists in memory. Thread-safe index allocation.
|
|
15
|
+
* Useful for:
|
|
16
|
+
* - Unit tests
|
|
17
|
+
* - Integration tests
|
|
18
|
+
* - Development/debugging
|
|
19
|
+
* - Examples
|
|
20
|
+
*/
|
|
21
|
+
export declare class MemoryStatusListStorage implements StatusListStorageProvider {
|
|
22
|
+
private statusLists;
|
|
23
|
+
private indexCounters;
|
|
24
|
+
/**
|
|
25
|
+
* Get a status list credential by ID
|
|
26
|
+
*/
|
|
27
|
+
getStatusList(statusListId: string): Promise<StatusList2021Credential | null>;
|
|
28
|
+
/**
|
|
29
|
+
* Save a status list credential
|
|
30
|
+
*/
|
|
31
|
+
setStatusList(statusListId: string, credential: StatusList2021Credential): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Allocate a new index (thread-safe)
|
|
34
|
+
*/
|
|
35
|
+
allocateIndex(statusListId: string): Promise<number>;
|
|
36
|
+
/**
|
|
37
|
+
* Get current index count (for testing)
|
|
38
|
+
*/
|
|
39
|
+
getIndexCount(statusListId: string): number;
|
|
40
|
+
/**
|
|
41
|
+
* Clear all data (for testing)
|
|
42
|
+
*/
|
|
43
|
+
clear(): void;
|
|
44
|
+
/**
|
|
45
|
+
* Get all status list IDs (for testing)
|
|
46
|
+
*/
|
|
47
|
+
getAllStatusListIds(): string[];
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=memory-statuslist-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-statuslist-storage.d.ts","sourceRoot":"","sources":["../../../src/delegation/storage/memory-statuslist-storage.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAEvE;;;;;;;;;GASG;AACH,qBAAa,uBAAwB,YAAW,yBAAyB;IACvE,OAAO,CAAC,WAAW,CAA+C;IAClE,OAAO,CAAC,aAAa,CAA6B;IAElD;;OAEG;IACG,aAAa,CACjB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,wBAAwB,GAAG,IAAI,CAAC;IAI3C;;OAEG;IACG,aAAa,CACjB,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,wBAAwB,GACnC,OAAO,CAAC,IAAI,CAAC;IAIhB;;OAEG;IACG,aAAa,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAO1D;;OAEG;IACH,aAAa,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;IAI3C;;OAEG;IACH,KAAK,IAAI,IAAI;IAKb;;OAEG;IACH,mBAAmB,IAAI,MAAM,EAAE;CAGhC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* In-Memory StatusList Storage Provider
|
|
4
|
+
*
|
|
5
|
+
* Memory-based implementation for testing and development.
|
|
6
|
+
* NOT suitable for production (no persistence).
|
|
7
|
+
*
|
|
8
|
+
* SOLID: Implements StatusListStorageProvider interface
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.MemoryStatusListStorage = void 0;
|
|
12
|
+
/**
|
|
13
|
+
* Memory-based StatusList storage
|
|
14
|
+
*
|
|
15
|
+
* Stores status lists in memory. Thread-safe index allocation.
|
|
16
|
+
* Useful for:
|
|
17
|
+
* - Unit tests
|
|
18
|
+
* - Integration tests
|
|
19
|
+
* - Development/debugging
|
|
20
|
+
* - Examples
|
|
21
|
+
*/
|
|
22
|
+
class MemoryStatusListStorage {
|
|
23
|
+
statusLists = new Map();
|
|
24
|
+
indexCounters = new Map();
|
|
25
|
+
/**
|
|
26
|
+
* Get a status list credential by ID
|
|
27
|
+
*/
|
|
28
|
+
async getStatusList(statusListId) {
|
|
29
|
+
return this.statusLists.get(statusListId) || null;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Save a status list credential
|
|
33
|
+
*/
|
|
34
|
+
async setStatusList(statusListId, credential) {
|
|
35
|
+
this.statusLists.set(statusListId, credential);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Allocate a new index (thread-safe)
|
|
39
|
+
*/
|
|
40
|
+
async allocateIndex(statusListId) {
|
|
41
|
+
const current = this.indexCounters.get(statusListId) || 0;
|
|
42
|
+
const allocated = current;
|
|
43
|
+
this.indexCounters.set(statusListId, current + 1);
|
|
44
|
+
return allocated;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get current index count (for testing)
|
|
48
|
+
*/
|
|
49
|
+
getIndexCount(statusListId) {
|
|
50
|
+
return this.indexCounters.get(statusListId) || 0;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Clear all data (for testing)
|
|
54
|
+
*/
|
|
55
|
+
clear() {
|
|
56
|
+
this.statusLists.clear();
|
|
57
|
+
this.indexCounters.clear();
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get all status list IDs (for testing)
|
|
61
|
+
*/
|
|
62
|
+
getAllStatusListIds() {
|
|
63
|
+
return Array.from(this.statusLists.keys());
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.MemoryStatusListStorage = MemoryStatusListStorage;
|
|
67
|
+
//# sourceMappingURL=memory-statuslist-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-statuslist-storage.js","sourceRoot":"","sources":["../../../src/delegation/storage/memory-statuslist-storage.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAKH;;;;;;;;;GASG;AACH,MAAa,uBAAuB;IAC1B,WAAW,GAAG,IAAI,GAAG,EAAoC,CAAC;IAC1D,aAAa,GAAG,IAAI,GAAG,EAAkB,CAAC;IAElD;;OAEG;IACH,KAAK,CAAC,aAAa,CACjB,YAAoB;QAEpB,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,IAAI,CAAC;IACpD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,aAAa,CACjB,YAAoB,EACpB,UAAoC;QAEpC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;IACjD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,aAAa,CAAC,YAAoB;QACtC,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QAC1D,MAAM,SAAS,GAAG,OAAO,CAAC;QAC1B,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,GAAG,CAAC,CAAC,CAAC;QAClD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,aAAa,CAAC,YAAoB;QAChC,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IACnD,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,mBAAmB;QACjB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7C,CAAC;CACF;AAtDD,0DAsDC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Delegation Utilities
|
|
3
|
+
*
|
|
4
|
+
* Shared utility functions for delegation credential operations.
|
|
5
|
+
* Following DRY (Don't Repeat Yourself) principle.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* JSON canonicalization (RFC 8785)
|
|
9
|
+
*
|
|
10
|
+
* Creates a deterministic representation of JSON for signing.
|
|
11
|
+
* Per W3C VC spec, canonicalization ensures identical VCs produce identical signatures.
|
|
12
|
+
*
|
|
13
|
+
* DRY: Single implementation shared across vc-issuer and statuslist-manager.
|
|
14
|
+
*
|
|
15
|
+
* @param obj - The object to canonicalize
|
|
16
|
+
* @returns Canonical JSON string
|
|
17
|
+
*/
|
|
18
|
+
export declare function canonicalizeJSON(obj: any): string;
|
|
19
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/delegation/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAuBjD"}
|