@kya-os/mcp-i 0.1.0-alpha.2.3 → 0.1.0-alpha.2.5
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/README.md +192 -216
- package/dist/auto.d.ts +0 -12
- package/dist/auto.js +3 -14
- package/dist/crypto.d.ts +10 -26
- package/dist/crypto.js +117 -37
- package/dist/dev-helper.d.ts +3 -0
- package/dist/dev-helper.js +46 -0
- package/dist/encrypted-storage.d.ts +11 -0
- package/dist/encrypted-storage.js +73 -0
- package/dist/index.d.ts +29 -106
- package/dist/index.js +225 -392
- package/dist/logger.d.ts +32 -0
- package/dist/logger.js +66 -0
- package/dist/registry/index.d.ts +0 -31
- package/dist/registry/index.js +2 -42
- package/dist/registry/knowthat.d.ts +3 -18
- package/dist/registry/knowthat.js +10 -35
- package/dist/rotation.d.ts +35 -0
- package/dist/rotation.js +102 -0
- package/dist/storage.d.ts +41 -0
- package/dist/storage.js +163 -0
- package/dist/transport.d.ts +35 -0
- package/dist/transport.js +189 -0
- package/dist/types.d.ts +72 -99
- package/dist/types.js +0 -4
- package/package.json +16 -6
- package/dist/__tests__/challenge-response.test.d.ts +0 -5
- package/dist/__tests__/challenge-response.test.d.ts.map +0 -1
- package/dist/__tests__/challenge-response.test.js +0 -218
- package/dist/__tests__/challenge-response.test.js.map +0 -1
- package/dist/__tests__/crypto.test.d.ts +0 -5
- package/dist/__tests__/crypto.test.d.ts.map +0 -1
- package/dist/__tests__/crypto.test.js +0 -153
- package/dist/__tests__/crypto.test.js.map +0 -1
- package/dist/auto.d.ts.map +0 -1
- package/dist/auto.js.map +0 -1
- package/dist/crypto.d.ts.map +0 -1
- package/dist/crypto.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/registry/cursor.d.ts +0 -25
- package/dist/registry/cursor.d.ts.map +0 -1
- package/dist/registry/cursor.js +0 -108
- package/dist/registry/cursor.js.map +0 -1
- package/dist/registry/glama.d.ts +0 -25
- package/dist/registry/glama.d.ts.map +0 -1
- package/dist/registry/glama.js +0 -111
- package/dist/registry/glama.js.map +0 -1
- package/dist/registry/index.d.ts.map +0 -1
- package/dist/registry/index.js.map +0 -1
- package/dist/registry/knowthat.d.ts.map +0 -1
- package/dist/registry/knowthat.js.map +0 -1
- package/dist/registry/smithery.d.ts +0 -29
- package/dist/registry/smithery.d.ts.map +0 -1
- package/dist/registry/smithery.js +0 -119
- package/dist/registry/smithery.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
|
2
|
+
export interface Logger {
|
|
3
|
+
debug(message: string, ...args: any[]): void;
|
|
4
|
+
info(message: string, ...args: any[]): void;
|
|
5
|
+
warn(message: string, ...args: any[]): void;
|
|
6
|
+
error(message: string, ...args: any[]): void;
|
|
7
|
+
}
|
|
8
|
+
export declare class SilentLogger implements Logger {
|
|
9
|
+
debug(): void;
|
|
10
|
+
info(): void;
|
|
11
|
+
warn(): void;
|
|
12
|
+
error(): void;
|
|
13
|
+
}
|
|
14
|
+
export declare class ConsoleLogger implements Logger {
|
|
15
|
+
private prefix;
|
|
16
|
+
private level;
|
|
17
|
+
constructor(prefix?: string, level?: LogLevel);
|
|
18
|
+
private shouldLog;
|
|
19
|
+
debug(message: string, ...args: any[]): void;
|
|
20
|
+
info(message: string, ...args: any[]): void;
|
|
21
|
+
warn(message: string, ...args: any[]): void;
|
|
22
|
+
error(message: string, ...args: any[]): void;
|
|
23
|
+
}
|
|
24
|
+
export declare class LoggerFactory {
|
|
25
|
+
private static instance;
|
|
26
|
+
static setLogger(logger: Logger): void;
|
|
27
|
+
static getLogger(): Logger;
|
|
28
|
+
static createConsoleLogger(level?: LogLevel): Logger;
|
|
29
|
+
static createSilentLogger(): Logger;
|
|
30
|
+
static reset(): void;
|
|
31
|
+
}
|
|
32
|
+
export declare function getLogger(): Logger;
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LoggerFactory = exports.ConsoleLogger = exports.SilentLogger = void 0;
|
|
4
|
+
exports.getLogger = getLogger;
|
|
5
|
+
class SilentLogger {
|
|
6
|
+
debug() { }
|
|
7
|
+
info() { }
|
|
8
|
+
warn() { }
|
|
9
|
+
error() { }
|
|
10
|
+
}
|
|
11
|
+
exports.SilentLogger = SilentLogger;
|
|
12
|
+
class ConsoleLogger {
|
|
13
|
+
constructor(prefix = '[MCP-I]', level = 'info') {
|
|
14
|
+
this.prefix = prefix;
|
|
15
|
+
this.level = level;
|
|
16
|
+
}
|
|
17
|
+
shouldLog(level) {
|
|
18
|
+
const levels = ['debug', 'info', 'warn', 'error', 'silent'];
|
|
19
|
+
const currentIndex = levels.indexOf(this.level);
|
|
20
|
+
const messageIndex = levels.indexOf(level);
|
|
21
|
+
return messageIndex >= currentIndex;
|
|
22
|
+
}
|
|
23
|
+
debug(message, ...args) {
|
|
24
|
+
if (this.shouldLog('debug')) {
|
|
25
|
+
console.log('[DEBUG]', message, ...args);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
info(message, ...args) {
|
|
29
|
+
if (this.shouldLog('info')) {
|
|
30
|
+
console.log('[INFO]', message, ...args);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
warn(message, ...args) {
|
|
34
|
+
if (this.shouldLog('warn')) {
|
|
35
|
+
console.warn('[WARN]', message, ...args);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
error(message, ...args) {
|
|
39
|
+
if (this.shouldLog('error')) {
|
|
40
|
+
console.error('[ERROR]', message, ...args);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.ConsoleLogger = ConsoleLogger;
|
|
45
|
+
class LoggerFactory {
|
|
46
|
+
static setLogger(logger) {
|
|
47
|
+
LoggerFactory.instance = logger;
|
|
48
|
+
}
|
|
49
|
+
static getLogger() {
|
|
50
|
+
return LoggerFactory.instance;
|
|
51
|
+
}
|
|
52
|
+
static createConsoleLogger(level) {
|
|
53
|
+
return new ConsoleLogger('[MCP-I]', level);
|
|
54
|
+
}
|
|
55
|
+
static createSilentLogger() {
|
|
56
|
+
return new SilentLogger();
|
|
57
|
+
}
|
|
58
|
+
static reset() {
|
|
59
|
+
LoggerFactory.instance = new SilentLogger();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.LoggerFactory = LoggerFactory;
|
|
63
|
+
LoggerFactory.instance = new SilentLogger();
|
|
64
|
+
function getLogger() {
|
|
65
|
+
return LoggerFactory.getLogger();
|
|
66
|
+
}
|
package/dist/registry/index.d.ts
CHANGED
|
@@ -1,43 +1,12 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Registry management for MCP-I identity
|
|
3
|
-
*
|
|
4
|
-
* Currently supports KnowThat.ai as the primary registry.
|
|
5
|
-
* Additional registries will be added as directories adopt MCP-I.
|
|
6
|
-
*/
|
|
7
1
|
import { RegistryAdapter, RegistryName, RegistryTier } from "../types";
|
|
8
|
-
/**
|
|
9
|
-
* Registry tier definitions
|
|
10
|
-
*
|
|
11
|
-
* As more directories adopt MCP-I, they will be added to appropriate tiers.
|
|
12
|
-
* Directory maintainers can contact us to discuss integration.
|
|
13
|
-
*/
|
|
14
2
|
export declare const REGISTRY_TIERS: Record<RegistryTier, RegistryName[]>;
|
|
15
|
-
/**
|
|
16
|
-
* Registry factory
|
|
17
|
-
*
|
|
18
|
-
* Manages registry adapters dynamically. New registries can be added
|
|
19
|
-
* without modifying core code.
|
|
20
|
-
*/
|
|
21
3
|
export declare class RegistryFactory {
|
|
22
4
|
private static adapters;
|
|
23
|
-
/**
|
|
24
|
-
* Get a registry adapter by name
|
|
25
|
-
*/
|
|
26
5
|
static getAdapter(name: RegistryName): RegistryAdapter | null;
|
|
27
|
-
/**
|
|
28
|
-
* Get all adapters for a tier
|
|
29
|
-
*/
|
|
30
6
|
static getAdaptersByTier(tier: RegistryTier): RegistryAdapter[];
|
|
31
|
-
/**
|
|
32
|
-
* Register a custom adapter
|
|
33
|
-
*/
|
|
34
7
|
static registerAdapter(name: string, factory: () => RegistryAdapter): void;
|
|
35
8
|
}
|
|
36
|
-
/**
|
|
37
|
-
* Resolve registries from options
|
|
38
|
-
*/
|
|
39
9
|
export declare function resolveRegistries(registries?: RegistryName[] | RegistryTier | {
|
|
40
10
|
include?: RegistryName[] | RegistryTier;
|
|
41
11
|
exclude?: RegistryName[];
|
|
42
12
|
}): RegistryName[];
|
|
43
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/registry/index.js
CHANGED
|
@@ -1,52 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Registry management for MCP-I identity
|
|
4
|
-
*
|
|
5
|
-
* Currently supports KnowThat.ai as the primary registry.
|
|
6
|
-
* Additional registries will be added as directories adopt MCP-I.
|
|
7
|
-
*/
|
|
8
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
3
|
exports.RegistryFactory = exports.REGISTRY_TIERS = void 0;
|
|
10
4
|
exports.resolveRegistries = resolveRegistries;
|
|
11
5
|
const knowthat_1 = require("./knowthat");
|
|
12
|
-
/**
|
|
13
|
-
* Registry tier definitions
|
|
14
|
-
*
|
|
15
|
-
* As more directories adopt MCP-I, they will be added to appropriate tiers.
|
|
16
|
-
* Directory maintainers can contact us to discuss integration.
|
|
17
|
-
*/
|
|
18
6
|
exports.REGISTRY_TIERS = {
|
|
19
|
-
verified: ["knowthat"],
|
|
20
|
-
experimental: [], // Future: Directories in beta/testing phase
|
|
21
|
-
enterprise: [], // Future: Enterprise-specific registries
|
|
22
|
-
all: ["knowthat"], // Currently same as verified
|
|
7
|
+
verified: ["knowthat"],
|
|
23
8
|
};
|
|
24
|
-
/**
|
|
25
|
-
* Registry factory
|
|
26
|
-
*
|
|
27
|
-
* Manages registry adapters dynamically. New registries can be added
|
|
28
|
-
* without modifying core code.
|
|
29
|
-
*/
|
|
30
9
|
class RegistryFactory {
|
|
31
|
-
/**
|
|
32
|
-
* Get a registry adapter by name
|
|
33
|
-
*/
|
|
34
10
|
static getAdapter(name) {
|
|
35
11
|
const factory = this.adapters.get(name);
|
|
36
12
|
return factory ? factory() : null;
|
|
37
13
|
}
|
|
38
|
-
/**
|
|
39
|
-
* Get all adapters for a tier
|
|
40
|
-
*/
|
|
41
14
|
static getAdaptersByTier(tier) {
|
|
42
15
|
const registries = exports.REGISTRY_TIERS[tier] || [];
|
|
43
16
|
return registries
|
|
44
17
|
.map((name) => this.getAdapter(name))
|
|
45
18
|
.filter((adapter) => adapter !== null);
|
|
46
19
|
}
|
|
47
|
-
/**
|
|
48
|
-
* Register a custom adapter
|
|
49
|
-
*/
|
|
50
20
|
static registerAdapter(name, factory) {
|
|
51
21
|
this.adapters.set(name, factory);
|
|
52
22
|
}
|
|
@@ -54,25 +24,18 @@ class RegistryFactory {
|
|
|
54
24
|
exports.RegistryFactory = RegistryFactory;
|
|
55
25
|
RegistryFactory.adapters = new Map([
|
|
56
26
|
["knowthat", () => new knowthat_1.KnowThatRegistry()],
|
|
57
|
-
|
|
27
|
+
["knowthat.ai", () => new knowthat_1.KnowThatRegistry()],
|
|
58
28
|
]);
|
|
59
|
-
/**
|
|
60
|
-
* Resolve registries from options
|
|
61
|
-
*/
|
|
62
29
|
function resolveRegistries(registries) {
|
|
63
|
-
// Default to 'verified' tier
|
|
64
30
|
if (!registries) {
|
|
65
31
|
return exports.REGISTRY_TIERS.verified;
|
|
66
32
|
}
|
|
67
|
-
// Array of specific registries
|
|
68
33
|
if (Array.isArray(registries)) {
|
|
69
34
|
return registries;
|
|
70
35
|
}
|
|
71
|
-
// Tier name
|
|
72
36
|
if (typeof registries === "string") {
|
|
73
37
|
return exports.REGISTRY_TIERS[registries] || [];
|
|
74
38
|
}
|
|
75
|
-
// Config object with include/exclude
|
|
76
39
|
const config = registries;
|
|
77
40
|
let included = [];
|
|
78
41
|
if (config.include) {
|
|
@@ -84,13 +47,10 @@ function resolveRegistries(registries) {
|
|
|
84
47
|
}
|
|
85
48
|
}
|
|
86
49
|
else {
|
|
87
|
-
// Default to 'verified' if no include specified
|
|
88
50
|
included = exports.REGISTRY_TIERS.verified;
|
|
89
51
|
}
|
|
90
|
-
// Apply exclusions
|
|
91
52
|
if (config.exclude && config.exclude.length > 0) {
|
|
92
53
|
return included.filter((name) => !config.exclude.includes(name));
|
|
93
54
|
}
|
|
94
55
|
return included;
|
|
95
56
|
}
|
|
96
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,28 +1,13 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* KnowThat.ai Registry Adapter
|
|
3
|
-
* Primary registry that can host DIDs
|
|
4
|
-
*/
|
|
5
1
|
import { RegistryAdapter, RegistryPublishData, RegistryPublishResult, RegistryStatus } from '../types';
|
|
2
|
+
import { Transport } from '../transport';
|
|
6
3
|
export declare class KnowThatRegistry implements RegistryAdapter {
|
|
7
4
|
name: string;
|
|
8
5
|
type: 'primary' | 'secondary';
|
|
9
6
|
private endpoint;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* Primary registration - creates DID and hosts DID document
|
|
13
|
-
*/
|
|
7
|
+
private transport;
|
|
8
|
+
constructor(endpoint?: string, transport?: Transport);
|
|
14
9
|
publish(data: RegistryPublishData): Promise<RegistryPublishResult>;
|
|
15
|
-
/**
|
|
16
|
-
* Verify agent exists and is valid
|
|
17
|
-
*/
|
|
18
10
|
verify(did: string): Promise<boolean>;
|
|
19
|
-
/**
|
|
20
|
-
* Get agent status in KnowThat registry
|
|
21
|
-
*/
|
|
22
11
|
getStatus(did: string): Promise<RegistryStatus>;
|
|
23
|
-
/**
|
|
24
|
-
* Extract agent slug from DID
|
|
25
|
-
*/
|
|
26
12
|
private extractAgentSlug;
|
|
27
13
|
}
|
|
28
|
-
//# sourceMappingURL=knowthat.d.ts.map
|
|
@@ -1,27 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* KnowThat.ai Registry Adapter
|
|
4
|
-
* Primary registry that can host DIDs
|
|
5
|
-
*/
|
|
6
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
-
};
|
|
9
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
3
|
exports.KnowThatRegistry = void 0;
|
|
11
|
-
const
|
|
4
|
+
const transport_1 = require("../transport");
|
|
12
5
|
class KnowThatRegistry {
|
|
13
|
-
constructor(endpoint = 'https://knowthat.ai') {
|
|
6
|
+
constructor(endpoint = 'https://knowthat.ai', transport) {
|
|
14
7
|
this.name = 'knowthat';
|
|
15
8
|
this.type = 'primary';
|
|
16
9
|
this.endpoint = endpoint;
|
|
10
|
+
this.transport = transport || transport_1.TransportFactory.create();
|
|
17
11
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Primary registration - creates DID and hosts DID document
|
|
20
|
-
*/
|
|
21
12
|
async publish(data) {
|
|
22
13
|
try {
|
|
23
|
-
|
|
24
|
-
const response = await axios_1.default.post(`${this.endpoint}/api/agents/auto-register`, {
|
|
14
|
+
const response = await this.transport.post(`${this.endpoint}/api/agents/auto-register`, {
|
|
25
15
|
metadata: {
|
|
26
16
|
name: data.name,
|
|
27
17
|
description: data.description,
|
|
@@ -33,7 +23,6 @@ class KnowThatRegistry {
|
|
|
33
23
|
language: 'typescript',
|
|
34
24
|
platform: 'node'
|
|
35
25
|
},
|
|
36
|
-
// If we already have a public key, send it
|
|
37
26
|
publicKey: data.publicKey || undefined
|
|
38
27
|
}, {
|
|
39
28
|
timeout: 30000,
|
|
@@ -49,7 +38,7 @@ class KnowThatRegistry {
|
|
|
49
38
|
};
|
|
50
39
|
}
|
|
51
40
|
catch (error) {
|
|
52
|
-
if (error.
|
|
41
|
+
if (error.message?.includes('Rate limit exceeded')) {
|
|
53
42
|
return {
|
|
54
43
|
success: false,
|
|
55
44
|
error: 'Rate limit exceeded. Please try again later.'
|
|
@@ -57,37 +46,29 @@ class KnowThatRegistry {
|
|
|
57
46
|
}
|
|
58
47
|
return {
|
|
59
48
|
success: false,
|
|
60
|
-
error: error.
|
|
49
|
+
error: error.message || 'Failed to register with KnowThat.ai'
|
|
61
50
|
};
|
|
62
51
|
}
|
|
63
52
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Verify agent exists and is valid
|
|
66
|
-
*/
|
|
67
53
|
async verify(did) {
|
|
68
54
|
try {
|
|
69
55
|
const agentSlug = this.extractAgentSlug(did);
|
|
70
|
-
const response = await
|
|
56
|
+
const response = await this.transport.get(`${this.endpoint}/api/agents/${agentSlug}/verify`, { timeout: 5000 });
|
|
71
57
|
return response.data.valid === true;
|
|
72
58
|
}
|
|
73
59
|
catch {
|
|
74
60
|
return false;
|
|
75
61
|
}
|
|
76
62
|
}
|
|
77
|
-
/**
|
|
78
|
-
* Get agent status in KnowThat registry
|
|
79
|
-
*/
|
|
80
63
|
async getStatus(did) {
|
|
81
64
|
try {
|
|
82
65
|
const agentSlug = this.extractAgentSlug(did);
|
|
83
|
-
const response = await
|
|
66
|
+
const response = await this.transport.get(`${this.endpoint}/api/agents/${agentSlug}/status`, { timeout: 5000 });
|
|
84
67
|
return {
|
|
85
68
|
name: this.name,
|
|
86
69
|
status: response.data.verified ? 'active' : 'pending',
|
|
87
70
|
registeredAt: response.data.registeredAt,
|
|
88
|
-
|
|
89
|
-
type: 'primary',
|
|
90
|
-
registryAgentId: response.data.agentId
|
|
71
|
+
type: 'primary'
|
|
91
72
|
};
|
|
92
73
|
}
|
|
93
74
|
catch (error) {
|
|
@@ -95,19 +76,13 @@ class KnowThatRegistry {
|
|
|
95
76
|
name: this.name,
|
|
96
77
|
status: 'failed',
|
|
97
78
|
type: 'primary',
|
|
98
|
-
error: 'Failed to get status'
|
|
99
|
-
lastSyncAt: new Date().toISOString()
|
|
79
|
+
error: 'Failed to get status'
|
|
100
80
|
};
|
|
101
81
|
}
|
|
102
82
|
}
|
|
103
|
-
/**
|
|
104
|
-
* Extract agent slug from DID
|
|
105
|
-
*/
|
|
106
83
|
extractAgentSlug(did) {
|
|
107
|
-
// did:web:knowthat.ai:agents:my-agent -> my-agent
|
|
108
84
|
const parts = did.split(':');
|
|
109
85
|
return parts[parts.length - 1];
|
|
110
86
|
}
|
|
111
87
|
}
|
|
112
88
|
exports.KnowThatRegistry = KnowThatRegistry;
|
|
113
|
-
//# sourceMappingURL=knowthat.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { PersistedIdentity } from './types';
|
|
2
|
+
import { Transport } from './transport';
|
|
3
|
+
export interface KeyRotationPolicy {
|
|
4
|
+
maxAge?: number;
|
|
5
|
+
maxSignatures?: number;
|
|
6
|
+
algorithm?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface KeyRotationResult {
|
|
9
|
+
success: boolean;
|
|
10
|
+
newKeyId?: string;
|
|
11
|
+
oldKeyId?: string;
|
|
12
|
+
gracePeriodEnd?: Date;
|
|
13
|
+
error?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface KeyHealth {
|
|
16
|
+
age: number;
|
|
17
|
+
signatureCount: number;
|
|
18
|
+
shouldRotate: boolean;
|
|
19
|
+
lastRotated?: Date;
|
|
20
|
+
}
|
|
21
|
+
export declare class KeyRotationManager {
|
|
22
|
+
private identity;
|
|
23
|
+
private transport;
|
|
24
|
+
private policy;
|
|
25
|
+
private signatureCount;
|
|
26
|
+
private keyCreatedAt;
|
|
27
|
+
private lastRotatedAt?;
|
|
28
|
+
constructor(identity: PersistedIdentity, transport: Transport, policy?: KeyRotationPolicy);
|
|
29
|
+
checkKeyHealth(): KeyHealth;
|
|
30
|
+
incrementSignatureCount(): void;
|
|
31
|
+
rotateKeys(reason?: string): Promise<KeyRotationResult>;
|
|
32
|
+
setupAutoRotation(callback?: (result: KeyRotationResult) => void): NodeJS.Timer;
|
|
33
|
+
private getRegistryUrl;
|
|
34
|
+
private extractAgentId;
|
|
35
|
+
}
|
package/dist/rotation.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KeyRotationManager = void 0;
|
|
4
|
+
const crypto_1 = require("./crypto");
|
|
5
|
+
class KeyRotationManager {
|
|
6
|
+
constructor(identity, transport, policy = {}) {
|
|
7
|
+
this.identity = identity;
|
|
8
|
+
this.transport = transport;
|
|
9
|
+
this.policy = policy;
|
|
10
|
+
this.signatureCount = 0;
|
|
11
|
+
this.keyCreatedAt = new Date(identity.registeredAt);
|
|
12
|
+
}
|
|
13
|
+
checkKeyHealth() {
|
|
14
|
+
const now = new Date();
|
|
15
|
+
const age = now.getTime() - this.keyCreatedAt.getTime();
|
|
16
|
+
const maxAge = this.policy.maxAge || 90 * 24 * 60 * 60 * 1000;
|
|
17
|
+
const maxSignatures = this.policy.maxSignatures || 1000000;
|
|
18
|
+
const shouldRotate = age > maxAge || this.signatureCount > maxSignatures;
|
|
19
|
+
return {
|
|
20
|
+
age,
|
|
21
|
+
signatureCount: this.signatureCount,
|
|
22
|
+
shouldRotate,
|
|
23
|
+
lastRotated: this.lastRotatedAt
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
incrementSignatureCount() {
|
|
27
|
+
this.signatureCount++;
|
|
28
|
+
}
|
|
29
|
+
async rotateKeys(reason = 'scheduled') {
|
|
30
|
+
try {
|
|
31
|
+
const newKeyPair = await (0, crypto_1.generateKeyPair)();
|
|
32
|
+
const timestamp = Date.now();
|
|
33
|
+
const message = `rotate-keys:${this.identity.did}:${timestamp}:${reason}`;
|
|
34
|
+
const signature = await (0, crypto_1.sign)(message, this.identity.privateKey);
|
|
35
|
+
const rotationRequest = {
|
|
36
|
+
newPublicKey: {
|
|
37
|
+
type: 'Ed25519VerificationKey2020',
|
|
38
|
+
publicKeyBase64: newKeyPair.publicKey
|
|
39
|
+
},
|
|
40
|
+
rotationReason: reason,
|
|
41
|
+
signedStatement: signature,
|
|
42
|
+
timestamp
|
|
43
|
+
};
|
|
44
|
+
const registryUrl = this.getRegistryUrl();
|
|
45
|
+
const agentId = this.extractAgentId();
|
|
46
|
+
const response = await this.transport.post(`${registryUrl}/api/agents/${agentId}/rotate-key`, rotationRequest, {
|
|
47
|
+
headers: {
|
|
48
|
+
'Authorization': `DID-Auth ${signature}`,
|
|
49
|
+
'Content-Type': 'application/json'
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
if (response.data.success) {
|
|
53
|
+
this.identity.publicKey = newKeyPair.publicKey;
|
|
54
|
+
this.identity.privateKey = newKeyPair.privateKey;
|
|
55
|
+
this.lastRotatedAt = new Date();
|
|
56
|
+
this.keyCreatedAt = new Date();
|
|
57
|
+
this.signatureCount = 0;
|
|
58
|
+
return {
|
|
59
|
+
success: true,
|
|
60
|
+
newKeyId: response.data.newKeyId,
|
|
61
|
+
oldKeyId: response.data.oldKeyId,
|
|
62
|
+
gracePeriodEnd: new Date(response.data.gracePeriodEnd)
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
return {
|
|
67
|
+
success: false,
|
|
68
|
+
error: response.data.error || 'Key rotation failed'
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
return {
|
|
74
|
+
success: false,
|
|
75
|
+
error: error.message || 'Key rotation error'
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
setupAutoRotation(callback) {
|
|
80
|
+
const checkInterval = 24 * 60 * 60 * 1000;
|
|
81
|
+
return setInterval(async () => {
|
|
82
|
+
const health = this.checkKeyHealth();
|
|
83
|
+
if (health.shouldRotate) {
|
|
84
|
+
const result = await this.rotateKeys('auto-rotation');
|
|
85
|
+
if (callback) {
|
|
86
|
+
callback(result);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}, checkInterval);
|
|
90
|
+
}
|
|
91
|
+
getRegistryUrl() {
|
|
92
|
+
return 'https://knowthat.ai';
|
|
93
|
+
}
|
|
94
|
+
extractAgentId() {
|
|
95
|
+
if (this.identity.agentId) {
|
|
96
|
+
return this.identity.agentId;
|
|
97
|
+
}
|
|
98
|
+
const parts = this.identity.did.split(':');
|
|
99
|
+
return parts[parts.length - 1];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.KeyRotationManager = KeyRotationManager;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { PersistedIdentity } from './types';
|
|
2
|
+
export interface StorageProvider {
|
|
3
|
+
load(): Promise<PersistedIdentity | null>;
|
|
4
|
+
save(identity: PersistedIdentity): Promise<void>;
|
|
5
|
+
exists(): Promise<boolean>;
|
|
6
|
+
}
|
|
7
|
+
export declare class FileStorage implements StorageProvider {
|
|
8
|
+
private filePath;
|
|
9
|
+
constructor(customPath?: string);
|
|
10
|
+
load(): Promise<PersistedIdentity | null>;
|
|
11
|
+
save(identity: PersistedIdentity): Promise<void>;
|
|
12
|
+
exists(): Promise<boolean>;
|
|
13
|
+
}
|
|
14
|
+
export declare class MemoryStorage implements StorageProvider {
|
|
15
|
+
private static instances;
|
|
16
|
+
private key;
|
|
17
|
+
constructor(key?: string);
|
|
18
|
+
load(): Promise<PersistedIdentity | null>;
|
|
19
|
+
save(identity: PersistedIdentity): Promise<void>;
|
|
20
|
+
exists(): Promise<boolean>;
|
|
21
|
+
static clear(): void;
|
|
22
|
+
}
|
|
23
|
+
export declare class EnvironmentStorage {
|
|
24
|
+
static load(): PersistedIdentity | null;
|
|
25
|
+
}
|
|
26
|
+
export declare class CombinedStorage implements StorageProvider {
|
|
27
|
+
private providers;
|
|
28
|
+
private primaryProvider;
|
|
29
|
+
constructor(providers: StorageProvider[]);
|
|
30
|
+
load(): Promise<PersistedIdentity | null>;
|
|
31
|
+
save(identity: PersistedIdentity): Promise<void>;
|
|
32
|
+
exists(): Promise<boolean>;
|
|
33
|
+
}
|
|
34
|
+
export declare class StorageFactory {
|
|
35
|
+
static create(options?: {
|
|
36
|
+
storage?: 'file' | 'memory' | 'auto';
|
|
37
|
+
customPath?: string;
|
|
38
|
+
memoryKey?: string;
|
|
39
|
+
encryptionPassword?: string;
|
|
40
|
+
}): StorageProvider;
|
|
41
|
+
}
|