@zcloak/ai-agent 1.0.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.
Files changed (80) hide show
  1. package/README.md +5 -0
  2. package/dist/bind.d.ts +22 -0
  3. package/dist/bind.js +145 -0
  4. package/dist/bind.js.map +1 -0
  5. package/dist/cli.d.ts +31 -0
  6. package/dist/cli.js +126 -0
  7. package/dist/cli.js.map +1 -0
  8. package/dist/config.d.ts +14 -0
  9. package/dist/config.js +34 -0
  10. package/dist/config.js.map +1 -0
  11. package/dist/crypto.d.ts +113 -0
  12. package/dist/crypto.js +252 -0
  13. package/dist/crypto.js.map +1 -0
  14. package/dist/daemon.d.ts +94 -0
  15. package/dist/daemon.js +271 -0
  16. package/dist/daemon.js.map +1 -0
  17. package/dist/delete.d.ts +22 -0
  18. package/dist/delete.js +231 -0
  19. package/dist/delete.js.map +1 -0
  20. package/dist/doc.d.ts +23 -0
  21. package/dist/doc.js +180 -0
  22. package/dist/doc.js.map +1 -0
  23. package/dist/error.d.ts +45 -0
  24. package/dist/error.js +79 -0
  25. package/dist/error.js.map +1 -0
  26. package/dist/feed.d.ts +20 -0
  27. package/dist/feed.js +83 -0
  28. package/dist/feed.js.map +1 -0
  29. package/dist/identity.d.ts +50 -0
  30. package/dist/identity.js +99 -0
  31. package/dist/identity.js.map +1 -0
  32. package/dist/identity_cmd.d.ts +23 -0
  33. package/dist/identity_cmd.js +136 -0
  34. package/dist/identity_cmd.js.map +1 -0
  35. package/dist/idl.d.ts +99 -0
  36. package/dist/idl.js +213 -0
  37. package/dist/idl.js.map +1 -0
  38. package/dist/key-store.d.ts +88 -0
  39. package/dist/key-store.js +171 -0
  40. package/dist/key-store.js.map +1 -0
  41. package/dist/pow.d.ts +24 -0
  42. package/dist/pow.js +86 -0
  43. package/dist/pow.js.map +1 -0
  44. package/dist/register.d.ts +24 -0
  45. package/dist/register.js +191 -0
  46. package/dist/register.js.map +1 -0
  47. package/dist/rpc.d.ts +107 -0
  48. package/dist/rpc.js +60 -0
  49. package/dist/rpc.js.map +1 -0
  50. package/dist/serve.d.ts +55 -0
  51. package/dist/serve.js +455 -0
  52. package/dist/serve.js.map +1 -0
  53. package/dist/session.d.ts +104 -0
  54. package/dist/session.js +189 -0
  55. package/dist/session.js.map +1 -0
  56. package/dist/sign.d.ts +33 -0
  57. package/dist/sign.js +355 -0
  58. package/dist/sign.js.map +1 -0
  59. package/dist/types/common.d.ts +63 -0
  60. package/dist/types/common.js +8 -0
  61. package/dist/types/common.js.map +1 -0
  62. package/dist/types/config.d.ts +28 -0
  63. package/dist/types/config.js +8 -0
  64. package/dist/types/config.js.map +1 -0
  65. package/dist/types/registry.d.ts +72 -0
  66. package/dist/types/registry.js +13 -0
  67. package/dist/types/registry.js.map +1 -0
  68. package/dist/types/sign-event.d.ts +134 -0
  69. package/dist/types/sign-event.js +13 -0
  70. package/dist/types/sign-event.js.map +1 -0
  71. package/dist/utils.d.ts +113 -0
  72. package/dist/utils.js +382 -0
  73. package/dist/utils.js.map +1 -0
  74. package/dist/verify.d.ts +23 -0
  75. package/dist/verify.js +207 -0
  76. package/dist/verify.js.map +1 -0
  77. package/dist/vetkey.d.ts +27 -0
  78. package/dist/vetkey.js +507 -0
  79. package/dist/vetkey.js.map +1 -0
  80. package/package.json +55 -0
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /**
3
+ * Common utility type definitions
4
+ *
5
+ * Contains public types for command line arguments, PoW results, MANIFEST, etc.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/types/common.ts"],"names":[],"mappings":";AAAA;;;;GAIG"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Configuration type definitions
3
+ *
4
+ * Defines interfaces for canister IDs and application config.
5
+ */
6
+ /** Canister ID pair */
7
+ export interface CanisterIds {
8
+ /** Registry canister ID */
9
+ registry: string;
10
+ /** Signatures canister ID */
11
+ signatures: string;
12
+ }
13
+ /** Full application configuration */
14
+ export interface AppConfig {
15
+ /** Canister IDs */
16
+ canisterIds: CanisterIds;
17
+ /** PoW required leading zeros count */
18
+ pow_zeros: number;
19
+ /** Agent binding page URL */
20
+ bind_url: string;
21
+ /** Agent profile page URL prefix */
22
+ profile_url: string;
23
+ /** 2FA verification page URL */
24
+ twofa_url: string;
25
+ /** Event view page URL prefix (appended with event ID to form the full URL) */
26
+ event_url: string;
27
+ }
28
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /**
3
+ * Configuration type definitions
4
+ *
5
+ * Defines interfaces for canister IDs and application config.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":";AAAA;;;;GAIG"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * AUTO-GENERATED from idl.ts — DO NOT EDIT MANUALLY
3
+ *
4
+ * Run `npm run generate-types` to regenerate this file.
5
+ * Source: registryIdlFactory in src/idl.ts
6
+ * Generated: 2026-03-04T08:49:52.875Z
7
+ *
8
+ * These types are derived from the Candid IDL definitions and correspond to
9
+ * the canister's runtime interface. Edit idl.ts to change type definitions.
10
+ */
11
+ import type { Principal } from '@dfinity/principal';
12
+ import type { ActorMethod } from '@dfinity/agent';
13
+ import type { CandidOpt } from './sign-event';
14
+ /** Position record — position information in the registry canister */
15
+ export interface Position {
16
+ is_human: boolean;
17
+ connection_list: Principal[];
18
+ }
19
+ /** AI profile record */
20
+ export interface AiProfile {
21
+ position: CandidOpt<Position>;
22
+ }
23
+ /** User profile record */
24
+ export interface UserProfile {
25
+ username: string;
26
+ passkey_name: string[];
27
+ ai_profile: CandidOpt<AiProfile>;
28
+ principal_id: CandidOpt<string>;
29
+ }
30
+ /** Registration success result */
31
+ export interface RegisterResult {
32
+ username: string;
33
+ }
34
+ /** 2FA verification record — tracks a pending or completed 2FA request */
35
+ export interface TwoFARecord {
36
+ request_timestamp: bigint;
37
+ content: string;
38
+ confirm_timestamp: CandidOpt<bigint>;
39
+ confirm_owner: CandidOpt<string>;
40
+ caller: string;
41
+ owner_list: string[];
42
+ }
43
+ /** Return type for canister method */
44
+ export type AgentPrepareBondResult = {
45
+ Ok: string;
46
+ } | {
47
+ Err: string;
48
+ };
49
+ /** Return type for canister method */
50
+ export type Prepare2faInfoResult = {
51
+ Ok: string;
52
+ } | {
53
+ Err: string;
54
+ };
55
+ /** Return type for canister method */
56
+ export type RegisterAgentResult = {
57
+ Ok: RegisterResult;
58
+ } | {
59
+ Err: string;
60
+ };
61
+ /** Registry canister service interface */
62
+ export interface RegistryService {
63
+ agent_prepare_bond: ActorMethod<[string], AgentPrepareBondResult>;
64
+ get_user_principal: ActorMethod<[string], CandidOpt<Principal>>;
65
+ get_username_by_principal: ActorMethod<[string], CandidOpt<string>>;
66
+ prepare_2fa_info: ActorMethod<[string], Prepare2faInfoResult>;
67
+ query_2fa_result_by_challenge: ActorMethod<[string], CandidOpt<TwoFARecord>>;
68
+ register_agent: ActorMethod<[string], RegisterAgentResult>;
69
+ user_profile_get: ActorMethod<[string], CandidOpt<UserProfile>>;
70
+ user_profile_get_by_principal: ActorMethod<[string], CandidOpt<UserProfile>>;
71
+ }
72
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ /**
3
+ * AUTO-GENERATED from idl.ts — DO NOT EDIT MANUALLY
4
+ *
5
+ * Run `npm run generate-types` to regenerate this file.
6
+ * Source: registryIdlFactory in src/idl.ts
7
+ * Generated: 2026-03-04T08:49:52.875Z
8
+ *
9
+ * These types are derived from the Candid IDL definitions and correspond to
10
+ * the canister's runtime interface. Edit idl.ts to change type definitions.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/types/registry.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG"}
@@ -0,0 +1,134 @@
1
+ /**
2
+ * AUTO-GENERATED from idl.ts — DO NOT EDIT MANUALLY
3
+ *
4
+ * Run `npm run generate-types` to regenerate this file.
5
+ * Source: signIdlFactory in src/idl.ts
6
+ * Generated: 2026-03-04T08:49:52.875Z
7
+ *
8
+ * These types are derived from the Candid IDL definitions and correspond to
9
+ * the canister's runtime interface. Edit idl.ts to change type definitions.
10
+ */
11
+ import type { Principal } from '@dfinity/principal';
12
+ import type { ActorMethod } from '@dfinity/agent';
13
+ /** Candid opt type representation: [] means null, [T] means has value */
14
+ export type CandidOpt<T> = [] | [T];
15
+ /** SignEvent — sign event record returned by canister */
16
+ export interface SignEvent {
17
+ id: string;
18
+ content: CandidOpt<string>;
19
+ counter: CandidOpt<number>;
20
+ ai_id: string;
21
+ kind: number;
22
+ content_hash: string;
23
+ tags: CandidOpt<string[][]>;
24
+ created_at: bigint;
25
+ }
26
+ /** SignParm variant — signing parameter types (one-of union) */
27
+ export type SignParm = {
28
+ Kind13PrivateContract: {
29
+ content: string;
30
+ tags: CandidOpt<string[][]>;
31
+ };
32
+ } | {
33
+ Kind12PublicContract: {
34
+ content: string;
35
+ tags: CandidOpt<string[][]>;
36
+ };
37
+ } | {
38
+ Kind10JobRequest: {
39
+ content: string;
40
+ tags: CandidOpt<string[][]>;
41
+ };
42
+ } | {
43
+ Kind1IdentityProfile: {
44
+ content: string;
45
+ };
46
+ } | {
47
+ Kind5PrivatePost: {
48
+ ibe_identity: string;
49
+ encrypted_content: number[];
50
+ tags: CandidOpt<string[][]>;
51
+ };
52
+ } | {
53
+ Kind8MediaAsset: {
54
+ content: string;
55
+ tags: CandidOpt<string[][]>;
56
+ };
57
+ } | {
58
+ Kind6Interaction: {
59
+ content: string;
60
+ tags: CandidOpt<string[][]>;
61
+ };
62
+ } | {
63
+ Kind9ServiceListing: {
64
+ content: string;
65
+ tags: CandidOpt<string[][]>;
66
+ };
67
+ } | {
68
+ Kind4PublicPost: {
69
+ content: string;
70
+ tags: CandidOpt<string[][]>;
71
+ };
72
+ } | {
73
+ Kind7ContactList: {
74
+ tags: CandidOpt<string[][]>;
75
+ };
76
+ } | {
77
+ Kind3SimpleAgreement: {
78
+ content: string;
79
+ tags: CandidOpt<string[][]>;
80
+ };
81
+ } | {
82
+ Kind15GeneralAttestation: {
83
+ content: string;
84
+ tags: CandidOpt<string[][]>;
85
+ };
86
+ } | {
87
+ Kind2IdentityVerification: {
88
+ content: string;
89
+ tags: CandidOpt<string[][]>;
90
+ };
91
+ } | {
92
+ Kind14Review: {
93
+ content: string;
94
+ tags: CandidOpt<string[][]>;
95
+ };
96
+ } | {
97
+ Kind11DocumentSignature: {
98
+ content: string;
99
+ tags: CandidOpt<string[][]>;
100
+ };
101
+ };
102
+ /** Return type for canister method */
103
+ export type AgentSignResult = {
104
+ Ok: SignEvent;
105
+ } | {
106
+ Err: string;
107
+ };
108
+ /** Backward-compatible alias for agent_sign return type */
109
+ export type SignResult = AgentSignResult;
110
+ /** Signatures canister service interface — all callable canister methods */
111
+ export interface SignService {
112
+ agent_sign: ActorMethod<[SignParm, string], AgentSignResult>;
113
+ derive_vetkey: ActorMethod<[string, number[]], number[]>;
114
+ fetch_events_by_counter: ActorMethod<[number, number], SignEvent[]>;
115
+ fetch_user_sign: ActorMethod<[Principal, number, number], [number, SignEvent[]]>;
116
+ get_all_sign_events: ActorMethod<[], SignEvent[]>;
117
+ get_counter: ActorMethod<[], number>;
118
+ get_ibe_public_key: ActorMethod<[], number[]>;
119
+ get_kind1_event_by_principal: ActorMethod<[string], CandidOpt<SignEvent>>;
120
+ get_kind5_decryption_key: ActorMethod<[string, number[]], {
121
+ encrypted_key: number[];
122
+ ciphertext: number[];
123
+ ibe_identity: string;
124
+ }>;
125
+ get_sign_event_by_id: ActorMethod<[string], CandidOpt<SignEvent>>;
126
+ get_user_latest_sign_event_id: ActorMethod<[Principal], string>;
127
+ greet: ActorMethod<[string], string>;
128
+ mcp_sign: ActorMethod<[Principal, SignParm], SignEvent>;
129
+ sign: ActorMethod<[SignParm], SignEvent>;
130
+ verify_file_hash: ActorMethod<[string], SignEvent[]>;
131
+ verify_message: ActorMethod<[string], SignEvent[]>;
132
+ verify_msg_hash: ActorMethod<[string], SignEvent[]>;
133
+ }
134
+ //# sourceMappingURL=sign-event.d.ts.map
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ /**
3
+ * AUTO-GENERATED from idl.ts — DO NOT EDIT MANUALLY
4
+ *
5
+ * Run `npm run generate-types` to regenerate this file.
6
+ * Source: signIdlFactory in src/idl.ts
7
+ * Generated: 2026-03-04T08:49:52.875Z
8
+ *
9
+ * These types are derived from the Candid IDL definitions and correspond to
10
+ * the canister's runtime interface. Edit idl.ts to change type definitions.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ //# sourceMappingURL=sign-event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sign-event.js","sourceRoot":"","sources":["../../src/types/sign-event.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG"}
@@ -0,0 +1,113 @@
1
+ /**
2
+ * zCloak.ai Common Utilities
3
+ *
4
+ * Provides PoW computation, file hashing, argument parsing, formatted output, and more.
5
+ * All other scripts depend on this module.
6
+ */
7
+ import type { ParsedArgs, PowResult, ManifestOptions, ManifestResult, ManifestEntry, ManifestVerifyResult } from './types/common';
8
+ import type { SignEvent, SignResult } from './types/sign-event';
9
+ export declare function computePow(base: string, zeros?: number): PowResult;
10
+ /**
11
+ * Parse command line arguments into a structured object.
12
+ * Supports both --key=value and --flag formats.
13
+ * Positional arguments (not starting with --) are placed in _args array in order.
14
+ *
15
+ * When called with an explicit argv array, uses that instead of process.argv.
16
+ * The first two elements (node path and script path) are always skipped,
17
+ * matching the process.argv convention.
18
+ *
19
+ * @param argv - Optional explicit argument array (defaults to process.argv)
20
+ */
21
+ export declare function parseArgs(argv?: string[]): ParsedArgs;
22
+ /**
23
+ * Parse --tags argument into a tag array
24
+ * Format: "t:crypto,sub:web3,m:alice_id"
25
+ */
26
+ export declare function parseTags(tagsStr: string | boolean | string[] | undefined): string[][];
27
+ /**
28
+ * Compute SHA256 hash of a file (pure Node.js implementation, no shell dependency)
29
+ * @param filePath - File path
30
+ * @returns 64-character hex hash value
31
+ * @throws {Error} If the file cannot be read
32
+ */
33
+ export declare function hashFile(filePath: string): string;
34
+ /**
35
+ * Get file size (bytes)
36
+ * @throws {Error} If the file cannot be stat'd
37
+ */
38
+ export declare function getFileSize(filePath: string): number;
39
+ /**
40
+ * Return MIME type based on file path
41
+ */
42
+ export declare function getMimeType(filePath: string): string;
43
+ /**
44
+ * Recursively list all files in a directory (excluding MANIFEST.sha256, .git, node_modules)
45
+ * @param dir - Directory path
46
+ * @param prefix - Path prefix (for recursion)
47
+ * @returns Sorted list of relative paths
48
+ */
49
+ export declare function listFiles(dir: string, prefix?: string): string[];
50
+ /**
51
+ * Generate MANIFEST.sha256 file (with metadata header)
52
+ * Format compatible with GNU sha256sum, metadata represented as # comment lines
53
+ *
54
+ * This version uses pure Node.js implementation, no shell command dependency.
55
+ * The author field is obtained via identity.ts; left empty if identity cannot be loaded.
56
+ */
57
+ export declare function generateManifest(folderPath: string, options?: ManifestOptions): ManifestResult;
58
+ /**
59
+ * Parse MANIFEST.sha256 file content into structured entries.
60
+ *
61
+ * Skips comment lines (starting with #) and empty lines.
62
+ * Each valid line must match: <64-hex-hash> <whitespace> <path>
63
+ * Non-empty non-comment lines that don't match this format cause an error
64
+ * (strict mode — prevents silently ignoring corrupted MANIFEST content).
65
+ *
66
+ * @param manifestContent - Full text content of the MANIFEST.sha256 file
67
+ * @returns Array of parsed ManifestEntry objects
68
+ * @throws {Error} If a non-empty non-comment line has invalid format
69
+ */
70
+ export declare function parseManifestEntries(manifestContent: string): ManifestEntry[];
71
+ /**
72
+ * Verify file integrity against MANIFEST entries.
73
+ *
74
+ * Parses the MANIFEST content, then checks each listed file:
75
+ * - If the file does not exist → { passed: false, reason: 'not_found' }
76
+ * - If the file hash doesn't match → { passed: false, reason: 'hash_mismatch' }
77
+ * - If the hash matches → { passed: true }
78
+ *
79
+ * Returns structured results; the caller decides how to format output.
80
+ *
81
+ * @param manifestContent - MANIFEST.sha256 file content
82
+ * @param basePath - Absolute path of the folder containing the files
83
+ * @returns Array of verification results, one per file entry
84
+ * @throws {Error} If the MANIFEST format is invalid
85
+ */
86
+ export declare function verifyManifestEntries(manifestContent: string, basePath: string): ManifestVerifyResult[];
87
+ /**
88
+ * Format a SignEvent object into readable text
89
+ * Candid opt types are represented as [] | [value] in JS
90
+ */
91
+ export declare function formatSignEvent(event: SignEvent): string;
92
+ /**
93
+ * Format a SignEvent array
94
+ */
95
+ export declare function formatSignEvents(events: SignEvent[]): string;
96
+ /**
97
+ * Build a full event view URL from an event ID.
98
+ * Uses the configured event_url prefix from config.
99
+ * @param eventId - The unique event ID (sha256 hash)
100
+ * @returns Full URL to view the event on the website
101
+ */
102
+ export declare function buildEventUrl(eventId: string): string;
103
+ /**
104
+ * Format agent_sign return value (Ok/Err variant).
105
+ * On success, appends a "View:" line with the event URL so the agent
106
+ * can present a clickable link to the user.
107
+ */
108
+ export declare function formatSignResult(result: SignResult): string;
109
+ /**
110
+ * Format opt text type
111
+ */
112
+ export declare function formatOptText(optText: [] | [string]): string;
113
+ //# sourceMappingURL=utils.d.ts.map