@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
package/dist/feed.js ADDED
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * zCloak.ai Event/Post Fetching Tool
5
+ *
6
+ * Provides global counter query and event fetching by counter range.
7
+ * Uses @dfinity JS SDK to interact directly with ICP canister, no dfx required.
8
+ *
9
+ * Usage:
10
+ * zcloak-ai feed counter Get current global counter value
11
+ * zcloak-ai feed fetch <from> <to> Fetch events by counter range
12
+ *
13
+ * All commands support --identity=<pem_path> to specify identity file.
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.run = run;
17
+ const utils_1 = require("./utils");
18
+ // ========== Help Information ==========
19
+ function showHelp() {
20
+ console.log('zCloak.ai Event/Post Fetching Tool');
21
+ console.log('');
22
+ console.log('Usage:');
23
+ console.log(' zcloak-ai feed counter Get current global counter value');
24
+ console.log(' zcloak-ai feed fetch <from> <to> Fetch events by counter range');
25
+ console.log('');
26
+ console.log('');
27
+ console.log('Examples:');
28
+ console.log(' zcloak-ai feed counter');
29
+ console.log(' zcloak-ai feed fetch 11 16');
30
+ }
31
+ // ========== Command Implementations ==========
32
+ /** Get current global counter value */
33
+ async function cmdCounter(session) {
34
+ const actor = await session.getAnonymousSignActor();
35
+ const counter = await actor.get_counter();
36
+ console.log(`(${counter} : nat32)`);
37
+ }
38
+ /** Fetch events by counter range */
39
+ async function cmdFetch(session, from, to) {
40
+ if (!from || !to) {
41
+ console.error('Error: from and to parameters are required');
42
+ console.error('Usage: zcloak-ai feed fetch <from> <to>');
43
+ process.exit(1);
44
+ }
45
+ const fromNum = parseInt(from, 10);
46
+ const toNum = parseInt(to, 10);
47
+ if (isNaN(fromNum) || isNaN(toNum)) {
48
+ console.error('Error: from and to must be numbers');
49
+ process.exit(1);
50
+ }
51
+ const actor = await session.getAnonymousSignActor();
52
+ const events = await actor.fetch_events_by_counter(fromNum, toNum);
53
+ console.log((0, utils_1.formatSignEvents)(events));
54
+ }
55
+ // ========== Exported run() — called by cli.ts ==========
56
+ /**
57
+ * Entry point when invoked via cli.ts.
58
+ * Receives a Session instance with pre-parsed arguments.
59
+ */
60
+ async function run(session) {
61
+ const command = session.args._args[0];
62
+ try {
63
+ switch (command) {
64
+ case 'counter':
65
+ await cmdCounter(session);
66
+ break;
67
+ case 'fetch':
68
+ await cmdFetch(session, session.args._args[1], session.args._args[2]);
69
+ break;
70
+ default:
71
+ showHelp();
72
+ if (command) {
73
+ console.error(`\nUnknown command: ${command}`);
74
+ }
75
+ process.exit(1);
76
+ }
77
+ }
78
+ catch (err) {
79
+ console.error(`Operation failed: ${err instanceof Error ? err.message : String(err)}`);
80
+ process.exit(1);
81
+ }
82
+ }
83
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;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,qBAAqB,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACvF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * zCloak.ai Identity Management Module
3
+ *
4
+ * Loads ECDSA secp256k1 identity from dfx-compatible PEM files for signing operations.
5
+ * Replaces the original `dfx identity get-principal` and similar commands.
6
+ *
7
+ * dfx generates EC PRIVATE KEY (SEC1/PKCS#1 format, OID 1.3.132.0.10 secp256k1),
8
+ * which is handled by Secp256k1KeyIdentity from @dfinity/identity-secp256k1.
9
+ *
10
+ * PEM file location priority:
11
+ * 1. --identity=<path> command line argument
12
+ * 2. ZCLOAK_IDENTITY environment variable
13
+ * 3. ~/.config/dfx/identity/default/identity.pem (dfx default location)
14
+ */
15
+ import { Secp256k1KeyIdentity } from '@dfinity/identity-secp256k1';
16
+ /**
17
+ * dfx default identity PEM file path
18
+ * Unified for macOS and Linux: ~/.config/dfx/identity/default/identity.pem
19
+ */
20
+ export declare const DEFAULT_PEM_PATH: string;
21
+ /**
22
+ * Get PEM file path.
23
+ * Searches by priority: --identity argument > environment variable > dfx default location.
24
+ *
25
+ * When called with an explicit argv array, uses that instead of process.argv.
26
+ * This enables deterministic, testable behavior without global state dependency.
27
+ *
28
+ * @param argv - Optional explicit argument array (defaults to process.argv)
29
+ * @returns Absolute path to PEM file
30
+ * @throws {Error} If no PEM file can be found or the specified path does not exist
31
+ */
32
+ export declare function getPemPath(argv?: string[]): string;
33
+ /**
34
+ * Load an ECDSA secp256k1 identity directly from a given PEM file path.
35
+ *
36
+ * Does NOT read the PEM path from argv/environment variables. It is intended
37
+ * for cases where the caller already knows the exact path (e.g. after generating
38
+ * a new key file, or when Session has already resolved the path).
39
+ *
40
+ * Uses Secp256k1KeyIdentity.fromPem() which handles the dfx PEM format:
41
+ * -----BEGIN EC PRIVATE KEY----- (SEC1 / RFC 5915 format)
42
+ * <base64 encoded DER data>
43
+ * -----END EC PRIVATE KEY-----
44
+ *
45
+ * @param pemPath - Absolute path to the PEM file
46
+ * @returns Secp256k1KeyIdentity
47
+ * @throws {Error} If the PEM file cannot be read or parsed
48
+ */
49
+ export declare function loadIdentityFromPath(pemPath: string): Secp256k1KeyIdentity;
50
+ //# sourceMappingURL=identity.d.ts.map
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ /**
3
+ * zCloak.ai Identity Management Module
4
+ *
5
+ * Loads ECDSA secp256k1 identity from dfx-compatible PEM files for signing operations.
6
+ * Replaces the original `dfx identity get-principal` and similar commands.
7
+ *
8
+ * dfx generates EC PRIVATE KEY (SEC1/PKCS#1 format, OID 1.3.132.0.10 secp256k1),
9
+ * which is handled by Secp256k1KeyIdentity from @dfinity/identity-secp256k1.
10
+ *
11
+ * PEM file location priority:
12
+ * 1. --identity=<path> command line argument
13
+ * 2. ZCLOAK_IDENTITY environment variable
14
+ * 3. ~/.config/dfx/identity/default/identity.pem (dfx default location)
15
+ */
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.DEFAULT_PEM_PATH = void 0;
21
+ exports.getPemPath = getPemPath;
22
+ exports.loadIdentityFromPath = loadIdentityFromPath;
23
+ const fs_1 = __importDefault(require("fs"));
24
+ const path_1 = __importDefault(require("path"));
25
+ const os_1 = __importDefault(require("os"));
26
+ const identity_secp256k1_1 = require("@dfinity/identity-secp256k1");
27
+ // ========== PEM File Lookup ==========
28
+ /**
29
+ * dfx default identity PEM file path
30
+ * Unified for macOS and Linux: ~/.config/dfx/identity/default/identity.pem
31
+ */
32
+ exports.DEFAULT_PEM_PATH = path_1.default.join(os_1.default.homedir(), '.config', 'dfx', 'identity', 'default', 'identity.pem');
33
+ /**
34
+ * Get PEM file path.
35
+ * Searches by priority: --identity argument > environment variable > dfx default location.
36
+ *
37
+ * When called with an explicit argv array, uses that instead of process.argv.
38
+ * This enables deterministic, testable behavior without global state dependency.
39
+ *
40
+ * @param argv - Optional explicit argument array (defaults to process.argv)
41
+ * @returns Absolute path to PEM file
42
+ * @throws {Error} If no PEM file can be found or the specified path does not exist
43
+ */
44
+ function getPemPath(argv) {
45
+ const effectiveArgv = argv ?? process.argv;
46
+ // 1. Get from --identity=<path> argument
47
+ const identityArg = effectiveArgv.find(a => a.startsWith('--identity='));
48
+ if (identityArg) {
49
+ const p = identityArg.split('=').slice(1).join('='); // Support paths containing =
50
+ const resolved = path_1.default.resolve(p);
51
+ if (!fs_1.default.existsSync(resolved)) {
52
+ throw new Error(`Specified PEM file does not exist: ${resolved}`);
53
+ }
54
+ return resolved;
55
+ }
56
+ // 2. Get from environment variable
57
+ if (process.env.ZCLOAK_IDENTITY) {
58
+ const resolved = path_1.default.resolve(process.env.ZCLOAK_IDENTITY);
59
+ if (!fs_1.default.existsSync(resolved)) {
60
+ throw new Error(`PEM file specified by ZCLOAK_IDENTITY does not exist: ${resolved}`);
61
+ }
62
+ return resolved;
63
+ }
64
+ // 3. Use dfx default location
65
+ if (fs_1.default.existsSync(exports.DEFAULT_PEM_PATH)) {
66
+ return exports.DEFAULT_PEM_PATH;
67
+ }
68
+ throw new Error('Identity PEM file not found. Provide one via:\n' +
69
+ ' 1. --identity=<pem_file_path>\n' +
70
+ ' 2. Set environment variable ZCLOAK_IDENTITY=<pem_file_path>\n' +
71
+ ` 3. Ensure dfx default identity exists: ${exports.DEFAULT_PEM_PATH}`);
72
+ }
73
+ // ========== Identity Management ==========
74
+ /**
75
+ * Load an ECDSA secp256k1 identity directly from a given PEM file path.
76
+ *
77
+ * Does NOT read the PEM path from argv/environment variables. It is intended
78
+ * for cases where the caller already knows the exact path (e.g. after generating
79
+ * a new key file, or when Session has already resolved the path).
80
+ *
81
+ * Uses Secp256k1KeyIdentity.fromPem() which handles the dfx PEM format:
82
+ * -----BEGIN EC PRIVATE KEY----- (SEC1 / RFC 5915 format)
83
+ * <base64 encoded DER data>
84
+ * -----END EC PRIVATE KEY-----
85
+ *
86
+ * @param pemPath - Absolute path to the PEM file
87
+ * @returns Secp256k1KeyIdentity
88
+ * @throws {Error} If the PEM file cannot be read or parsed
89
+ */
90
+ function loadIdentityFromPath(pemPath) {
91
+ const pemContent = fs_1.default.readFileSync(pemPath, 'utf-8');
92
+ try {
93
+ return identity_secp256k1_1.Secp256k1KeyIdentity.fromPem(pemContent);
94
+ }
95
+ catch (err) {
96
+ throw new Error(`Failed to load ECDSA secp256k1 identity from ${pemPath}: ${err.message}`);
97
+ }
98
+ }
99
+ //# sourceMappingURL=identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity.js","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;;;;AA8BH,gCAkCC;AAoBD,oDASC;AA3FD,4CAAoB;AACpB,gDAAwB;AACxB,4CAAoB;AACpB,oEAAmE;AAGnE,wCAAwC;AAExC;;;GAGG;AACU,QAAA,gBAAgB,GAAW,cAAI,CAAC,IAAI,CAC/C,YAAE,CAAC,OAAO,EAAE,EACZ,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,cAAc,CACxD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,SAAgB,UAAU,CAAC,IAAe;IACxC,MAAM,aAAa,GAAG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAE3C,yCAAyC;IACzC,MAAM,WAAW,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC;IACzE,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,G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,GAAa,CAAC,OAAO,EAAE,CACrF,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * zCloak.ai Identity Key Management Script
4
+ *
5
+ * Generates and inspects ECDSA secp256k1 identity PEM files without requiring dfx.
6
+ * Uses Node.js built-in crypto module to produce the same SEC1 PEM format that dfx generates.
7
+ *
8
+ * Usage:
9
+ * zcloak-ai identity generate [--output=<path>] [--force]
10
+ * Generate a new secp256k1 private key PEM file.
11
+ * Default output: ~/.config/dfx/identity/default/identity.pem
12
+ * Use --force to overwrite an existing file.
13
+ *
14
+ * zcloak-ai identity show
15
+ * Print the PEM path and principal ID of the current identity.
16
+ */
17
+ import { Session } from './session';
18
+ /**
19
+ * Entry point when invoked via cli.ts.
20
+ * Receives a Session instance with pre-parsed arguments.
21
+ */
22
+ export declare function run(session: Session): void;
23
+ //# sourceMappingURL=identity_cmd.d.ts.map
@@ -0,0 +1,136 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * zCloak.ai Identity Key Management Script
5
+ *
6
+ * Generates and inspects ECDSA secp256k1 identity PEM files without requiring dfx.
7
+ * Uses Node.js built-in crypto module to produce the same SEC1 PEM format that dfx generates.
8
+ *
9
+ * Usage:
10
+ * zcloak-ai identity generate [--output=<path>] [--force]
11
+ * Generate a new secp256k1 private key PEM file.
12
+ * Default output: ~/.config/dfx/identity/default/identity.pem
13
+ * Use --force to overwrite an existing file.
14
+ *
15
+ * zcloak-ai identity show
16
+ * Print the PEM path and principal ID of the current identity.
17
+ */
18
+ var __importDefault = (this && this.__importDefault) || function (mod) {
19
+ return (mod && mod.__esModule) ? mod : { "default": mod };
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.run = run;
23
+ const fs_1 = __importDefault(require("fs"));
24
+ const path_1 = __importDefault(require("path"));
25
+ const crypto_1 = require("crypto");
26
+ const identity_1 = require("./identity");
27
+ // ========== Help ==========
28
+ function showHelp() {
29
+ console.log('zCloak.ai Identity Key Management');
30
+ console.log('');
31
+ console.log('Usage:');
32
+ console.log(' zcloak-ai identity generate [--output=<path>] [--force]');
33
+ console.log(' Generate a new ECDSA secp256k1 PEM key file (no dfx required)');
34
+ console.log(' Default path: ~/.config/dfx/identity/default/identity.pem');
35
+ console.log('');
36
+ console.log(' zcloak-ai identity show');
37
+ console.log(' Print PEM file path and principal ID of the current identity');
38
+ console.log('');
39
+ console.log('Options:');
40
+ console.log(' --output=<path> Custom output path for the generated PEM file');
41
+ console.log(' --force Overwrite existing PEM file without error');
42
+ console.log(' --identity=<path> Use a specific identity PEM (for "show" command)');
43
+ console.log('');
44
+ console.log('Examples:');
45
+ console.log(' zcloak-ai identity generate');
46
+ console.log(' zcloak-ai identity generate --output=./my-agent.pem');
47
+ console.log(' zcloak-ai identity generate --force');
48
+ console.log(' zcloak-ai identity show');
49
+ console.log(' zcloak-ai identity show --identity=./my-agent.pem');
50
+ }
51
+ // ========== Commands ==========
52
+ /**
53
+ * Generate a new ECDSA secp256k1 PEM file.
54
+ *
55
+ * Node.js `generateKeyPairSync('ec', { namedCurve: 'secp256k1' })` produces an EC key
56
+ * with OID 1.3.132.0.10 (secp256k1). Exporting with `{ type: 'sec1', format: 'pem' }`
57
+ * yields the RFC 5915 SEC1 format:
58
+ *
59
+ * -----BEGIN EC PRIVATE KEY-----
60
+ * <base64 DER: SEQUENCE { version INTEGER(1), privateKey OCTET STRING(32), [OID], [pubkey] }>
61
+ * -----END EC PRIVATE KEY-----
62
+ *
63
+ * This is byte-for-byte identical to what `dfx identity new` generates and is directly
64
+ * loadable by Secp256k1KeyIdentity.fromPem().
65
+ */
66
+ function cmdGenerate(args) {
67
+ // Determine output path: --output flag or dfx default
68
+ const outputRaw = args['output'];
69
+ const outputPath = typeof outputRaw === 'string'
70
+ ? path_1.default.resolve(outputRaw)
71
+ : identity_1.DEFAULT_PEM_PATH;
72
+ // Safety check: refuse to overwrite without --force
73
+ if (fs_1.default.existsSync(outputPath) && !args['force']) {
74
+ console.error(`Error: PEM file already exists: ${outputPath}`);
75
+ console.error('Use --force to overwrite.');
76
+ process.exit(1);
77
+ }
78
+ // Ensure parent directory exists
79
+ const dir = path_1.default.dirname(outputPath);
80
+ if (!fs_1.default.existsSync(dir)) {
81
+ fs_1.default.mkdirSync(dir, { recursive: true });
82
+ }
83
+ // Generate EC key pair and export as SEC1 PEM (same format as dfx)
84
+ const { privateKey } = (0, crypto_1.generateKeyPairSync)('ec', { namedCurve: 'secp256k1' });
85
+ const pem = privateKey.export({ type: 'sec1', format: 'pem' });
86
+ // Write with owner-only permissions (0600), matching how dfx stores identity files
87
+ fs_1.default.writeFileSync(outputPath, pem, { mode: 0o600 });
88
+ console.log(`Identity PEM generated: ${outputPath}`);
89
+ // Derive and display the Principal from the newly written file so the user
90
+ // can verify immediately. We use loadIdentityFromPath() to bypass the global
91
+ // argv / cache lookup — no process.argv mutation needed.
92
+ const identity = (0, identity_1.loadIdentityFromPath)(outputPath);
93
+ console.log(`Principal ID: ${identity.getPrincipal().toText()}`);
94
+ }
95
+ /**
96
+ * Print the PEM path and principal ID of the current identity.
97
+ * Uses session to resolve PEM path and principal from the argv-based context.
98
+ */
99
+ function cmdShow(session) {
100
+ const pemPath = session.getPemPath();
101
+ const principal = session.getPrincipal();
102
+ console.log(`PEM file: ${pemPath}`);
103
+ console.log(`Principal ID: ${principal}`);
104
+ }
105
+ // ========== Exported run() — called by cli.ts ==========
106
+ /**
107
+ * Entry point when invoked via cli.ts.
108
+ * Receives a Session instance with pre-parsed arguments.
109
+ */
110
+ function run(session) {
111
+ const args = session.args;
112
+ const cmd = args._args[0];
113
+ if (!cmd || cmd === '--help' || cmd === '-h') {
114
+ showHelp();
115
+ process.exit(0);
116
+ }
117
+ try {
118
+ switch (cmd) {
119
+ case 'generate':
120
+ cmdGenerate(args);
121
+ break;
122
+ case 'show':
123
+ cmdShow(session);
124
+ break;
125
+ default:
126
+ console.error(`Unknown command: ${cmd}`);
127
+ console.error('Run "zcloak-ai identity" for help.');
128
+ process.exit(1);
129
+ }
130
+ }
131
+ catch (err) {
132
+ console.error(`Operation failed: ${err instanceof Error ? err.message : String(err)}`);
133
+ process.exit(1);
134
+ }
135
+ }
136
+ //# sourceMappingURL=identity_cmd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity_cmd.js","sourceRoot":"","sources":["../src/identity_cmd.ts"],"names":[],"mappings":";;AACA;;;;;;;;;;;;;;GAcG;;;;;AAwGH,kBA0BC;AAhID,4CAAoB;AACpB,gDAAwB;AACxB,mCAA6C;AAC7C,yCAAoE;AAIpE,6BAA6B;AAE7B,SAAS,QAAQ;IACf,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;IACjD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACtB,OAAO,CAAC,GAAG,CAAC,2DAA2D,CAAC,CAAC;IACzE,OAAO,CAAC,GAAG,CAAC,qEAAqE,CAAC,CAAC;IACnF,OAAO,CAAC,GAAG,CAAC,iEAAiE,CAAC,CAAC;IAC/E,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;IACzC,OAAO,CAAC,GAAG,CAAC,oEAAoE,CAAC,CAAC;IAClF,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACxB,OAAO,CAAC,GAAG,CAAC,oEAAoE,CAAC,CAAC;IAClF,OAAO,CAAC,GAAG,CAAC,gEAAgE,CAAC,CAAC;IAC9E,OAAO,CAAC,GAAG,CAAC,uEAAuE,CAAC,CAAC;IACrF,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACzB,OAAO,CAAC,GAAG,CAA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CAAC,OAAO,CAAC,CAAC;gBACjB,MAAM;YACR;gBACE,OAAO,CAAC,KAAK,CAAC,oBAAoB,GAAG,EAAE,CAAC,CAAC;gBACzC,OAAO,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC;gBACpD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,qBAAqB,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACvF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
package/dist/idl.d.ts ADDED
@@ -0,0 +1,99 @@
1
+ /**
2
+ * zCloak.ai Candid IDL Definitions — Single Source of Truth
3
+ *
4
+ * Contains complete interface definitions for the signatures canister and registry canister.
5
+ * TypeScript type interfaces in types/sign-event.ts and types/registry.ts are
6
+ * AUTO-GENERATED from these IDL definitions via `npm run generate-types`.
7
+ *
8
+ * When the canister API changes:
9
+ * 1. Update the IDL definitions in this file
10
+ * 2. Run `npm run generate-types` to regenerate TS types
11
+ * 3. Run `npm run build` to verify compilation
12
+ *
13
+ * Architecture:
14
+ * - buildSignTypes() / buildRegistryTypes() — named IDL type constructors (used by codegen)
15
+ * - buildSignService() / buildRegistryService() — service constructors (used by codegen for shared instances)
16
+ * - signIdlFactory / registryIdlFactory — IDL.InterfaceFactory (used by @dfinity/agent Actor)
17
+ *
18
+ * The canister's actual Candid .did schema is the upstream source; this file is derived from
19
+ * skill.md documentation and verified against actual canister responses.
20
+ */
21
+ import { IDL } from '@dfinity/candid';
22
+ /**
23
+ * Build named IDL types for the signatures canister.
24
+ * Exported so that the codegen script can discover type names and their structures.
25
+ *
26
+ * @param I - The IDL module (passed through to allow use in both factory and codegen contexts)
27
+ */
28
+ export declare function buildSignTypes(I: typeof IDL): {
29
+ SignEvent: IDL.RecordClass;
30
+ SignParm: IDL.VariantClass;
31
+ DecryptionPackage: IDL.RecordClass;
32
+ };
33
+ /**
34
+ * Build the signatures canister service, reusing pre-built named types.
35
+ * Exported for codegen to share type instances with the name registry.
36
+ *
37
+ * @param I - The IDL module
38
+ * @param types - Named types from buildSignTypes() (same instances used in the registry)
39
+ */
40
+ export declare function buildSignService(I: typeof IDL, types: ReturnType<typeof buildSignTypes>): IDL.ServiceClass<string, {
41
+ agent_sign: IDL.FuncClass<[IDL.VariantClass, IDL.TextClass], [IDL.VariantClass]>;
42
+ sign: IDL.FuncClass<[IDL.VariantClass], [IDL.RecordClass]>;
43
+ mcp_sign: IDL.FuncClass<[IDL.PrincipalClass, IDL.VariantClass], [IDL.RecordClass]>;
44
+ get_ibe_public_key: IDL.FuncClass<[], [IDL.VecClass<number | bigint>]>;
45
+ get_kind5_decryption_key: IDL.FuncClass<[IDL.TextClass, IDL.VecClass<number | bigint>], [IDL.RecordClass]>;
46
+ derive_vetkey: IDL.FuncClass<[IDL.TextClass, IDL.VecClass<number | bigint>], [IDL.VecClass<number | bigint>]>;
47
+ get_counter: IDL.FuncClass<[], [IDL.FixedNatClass]>;
48
+ fetch_events_by_counter: IDL.FuncClass<[IDL.FixedNatClass, IDL.FixedNatClass], [IDL.VecClass<Record<string, any>>]>;
49
+ get_all_sign_events: IDL.FuncClass<[], [IDL.VecClass<Record<string, any>>]>;
50
+ fetch_user_sign: IDL.FuncClass<[IDL.PrincipalClass, IDL.FixedNatClass, IDL.FixedNatClass], [IDL.FixedNatClass, IDL.VecClass<Record<string, any>>]>;
51
+ get_user_latest_sign_event_id: IDL.FuncClass<[IDL.PrincipalClass], [IDL.TextClass]>;
52
+ verify_message: IDL.FuncClass<[IDL.TextClass], [IDL.VecClass<Record<string, any>>]>;
53
+ verify_msg_hash: IDL.FuncClass<[IDL.TextClass], [IDL.VecClass<Record<string, any>>]>;
54
+ verify_file_hash: IDL.FuncClass<[IDL.TextClass], [IDL.VecClass<Record<string, any>>]>;
55
+ get_sign_event_by_id: IDL.FuncClass<[IDL.TextClass], [IDL.OptClass<Record<string, any>>]>;
56
+ get_kind1_event_by_principal: IDL.FuncClass<[IDL.TextClass], [IDL.OptClass<Record<string, any>>]>;
57
+ greet: IDL.FuncClass<[IDL.TextClass], [IDL.TextClass]>;
58
+ }>;
59
+ /**
60
+ * Signatures canister IDL factory (standard @dfinity/agent interface)
61
+ * Canister ID: zpbbm-piaaa-aaaaj-a3dsq-cai
62
+ */
63
+ export declare const signIdlFactory: IDL.InterfaceFactory;
64
+ /**
65
+ * Build named IDL types for the registry canister.
66
+ * Exported so that the codegen script can discover type names and their structures.
67
+ *
68
+ * @param I - The IDL module
69
+ */
70
+ export declare function buildRegistryTypes(I: typeof IDL): {
71
+ Position: IDL.RecordClass;
72
+ AiProfile: IDL.RecordClass;
73
+ UserProfile: IDL.RecordClass;
74
+ RegisterResult: IDL.RecordClass;
75
+ TwoFARecord: IDL.RecordClass;
76
+ };
77
+ /**
78
+ * Build the registry canister service, reusing pre-built named types.
79
+ * Exported for codegen to share type instances with the name registry.
80
+ *
81
+ * @param I - The IDL module
82
+ * @param types - Named types from buildRegistryTypes() (same instances used in the registry)
83
+ */
84
+ export declare function buildRegistryService(I: typeof IDL, types: ReturnType<typeof buildRegistryTypes>): IDL.ServiceClass<string, {
85
+ get_username_by_principal: IDL.FuncClass<[IDL.TextClass], [IDL.OptClass<string>]>;
86
+ get_user_principal: IDL.FuncClass<[IDL.TextClass], [IDL.OptClass<import("@dfinity/principal").Principal>]>;
87
+ user_profile_get: IDL.FuncClass<[IDL.TextClass], [IDL.OptClass<Record<string, any>>]>;
88
+ user_profile_get_by_principal: IDL.FuncClass<[IDL.TextClass], [IDL.OptClass<Record<string, any>>]>;
89
+ register_agent: IDL.FuncClass<[IDL.TextClass], [IDL.VariantClass]>;
90
+ agent_prepare_bond: IDL.FuncClass<[IDL.TextClass], [IDL.VariantClass]>;
91
+ prepare_2fa_info: IDL.FuncClass<[IDL.TextClass], [IDL.VariantClass]>;
92
+ query_2fa_result_by_challenge: IDL.FuncClass<[IDL.TextClass], [IDL.OptClass<Record<string, any>>]>;
93
+ }>;
94
+ /**
95
+ * Registry canister IDL factory (standard @dfinity/agent interface)
96
+ * Canister ID: 3spie-caaaa-aaaam-ae3sa-cai
97
+ */
98
+ export declare const registryIdlFactory: IDL.InterfaceFactory;
99
+ //# sourceMappingURL=idl.d.ts.map