@zcloak/ai-agent 1.0.0 → 1.0.3
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 +3 -3
- package/dist/bind.d.ts +1 -1
- package/dist/bind.js +3 -6
- package/dist/bind.js.map +1 -1
- package/dist/cli.js +8 -11
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.js +10 -11
- package/dist/config.js.map +1 -1
- package/dist/crypto.js +34 -47
- package/dist/crypto.js.map +1 -1
- package/dist/daemon.js +29 -41
- package/dist/daemon.js.map +1 -1
- package/dist/delete.d.ts +1 -1
- package/dist/delete.js +11 -17
- package/dist/delete.js.map +1 -1
- package/dist/doc.d.ts +1 -1
- package/dist/doc.js +18 -24
- package/dist/doc.js.map +1 -1
- package/dist/error.js +10 -23
- package/dist/error.js.map +1 -1
- package/dist/feed.d.ts +1 -1
- package/dist/feed.js +3 -6
- package/dist/feed.js.map +1 -1
- package/dist/identity.js +16 -24
- package/dist/identity.js.map +1 -1
- package/dist/identity_cmd.d.ts +9 -3
- package/dist/identity_cmd.js +44 -29
- package/dist/identity_cmd.js.map +1 -1
- package/dist/idl.d.ts +7 -0
- package/dist/idl.js +41 -20
- package/dist/idl.js.map +1 -1
- package/dist/key-store.js +6 -43
- package/dist/key-store.js.map +1 -1
- package/dist/pow.d.ts +1 -1
- package/dist/pow.js +3 -9
- package/dist/pow.js.map +1 -1
- package/dist/register.d.ts +1 -1
- package/dist/register.js +5 -8
- package/dist/register.js.map +1 -1
- package/dist/rpc.js +4 -10
- package/dist/rpc.js.map +1 -1
- package/dist/serve.d.ts +1 -1
- package/dist/serve.js +27 -31
- package/dist/serve.js.map +1 -1
- package/dist/session.d.ts +6 -4
- package/dist/session.js +27 -30
- package/dist/session.js.map +1 -1
- package/dist/sign.d.ts +1 -1
- package/dist/sign.js +17 -23
- package/dist/sign.js.map +1 -1
- package/dist/types/common.js +1 -2
- package/dist/types/common.js.map +1 -1
- package/dist/types/config.d.ts +2 -0
- package/dist/types/config.js +1 -2
- package/dist/types/config.js.map +1 -1
- package/dist/types/registry.d.ts +2 -2
- package/dist/types/registry.js +2 -3
- package/dist/types/registry.js.map +1 -1
- package/dist/types/sign-event.d.ts +47 -1
- package/dist/types/sign-event.js +2 -3
- package/dist/types/sign-event.js.map +1 -1
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +37 -57
- package/dist/utils.js.map +1 -1
- package/dist/verify.d.ts +1 -1
- package/dist/verify.js +17 -23
- package/dist/verify.js.map +1 -1
- package/dist/vetkey.d.ts +5 -1
- package/dist/vetkey.js +306 -70
- package/dist/vetkey.js.map +1 -1
- package/package.json +2 -3
package/dist/verify.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
2
|
/**
|
|
4
3
|
* zCloak.ai Verification Tool
|
|
5
4
|
*
|
|
@@ -15,14 +14,9 @@
|
|
|
15
14
|
*
|
|
16
15
|
* All commands support --identity=<pem_path> to specify identity file.
|
|
17
16
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
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 utils_1 = require("./utils");
|
|
17
|
+
import fs from 'fs';
|
|
18
|
+
import path from 'path';
|
|
19
|
+
import { hashFile, verifyManifestEntries, formatSignEvent, formatSignEvents, } from './utils.js';
|
|
26
20
|
// ========== Help Information ==========
|
|
27
21
|
function showHelp() {
|
|
28
22
|
console.log('zCloak.ai Verification Tool');
|
|
@@ -86,7 +80,7 @@ async function cmdVerifyMessage(session, content) {
|
|
|
86
80
|
}
|
|
87
81
|
const actor = await session.getAnonymousSignActor();
|
|
88
82
|
const events = await actor.verify_message(content);
|
|
89
|
-
console.log(
|
|
83
|
+
console.log(formatSignEvents(events));
|
|
90
84
|
await resolveSigners(session, events);
|
|
91
85
|
}
|
|
92
86
|
/** Verify single file signature */
|
|
@@ -95,19 +89,19 @@ async function cmdVerifyFile(session, filePath) {
|
|
|
95
89
|
console.error('Error: file path is required');
|
|
96
90
|
process.exit(1);
|
|
97
91
|
}
|
|
98
|
-
if (!
|
|
92
|
+
if (!fs.existsSync(filePath)) {
|
|
99
93
|
console.error(`Error: file does not exist: ${filePath}`);
|
|
100
94
|
process.exit(1);
|
|
101
95
|
}
|
|
102
96
|
// Compute file hash
|
|
103
|
-
const fileHash =
|
|
104
|
-
console.log(`File: ${
|
|
97
|
+
const fileHash = hashFile(filePath);
|
|
98
|
+
console.log(`File: ${path.basename(filePath)}`);
|
|
105
99
|
console.log(`SHA256: ${fileHash}`);
|
|
106
100
|
console.log('');
|
|
107
101
|
// On-chain verification
|
|
108
102
|
const actor = await session.getAnonymousSignActor();
|
|
109
103
|
const events = await actor.verify_file_hash(fileHash);
|
|
110
|
-
console.log(
|
|
104
|
+
console.log(formatSignEvents(events));
|
|
111
105
|
await resolveSigners(session, events);
|
|
112
106
|
}
|
|
113
107
|
/** Verify folder signature (MANIFEST.sha256) */
|
|
@@ -116,19 +110,19 @@ async function cmdVerifyFolder(session, folderPath) {
|
|
|
116
110
|
console.error('Error: folder path is required');
|
|
117
111
|
process.exit(1);
|
|
118
112
|
}
|
|
119
|
-
if (!
|
|
113
|
+
if (!fs.existsSync(folderPath) || !fs.statSync(folderPath).isDirectory()) {
|
|
120
114
|
console.error(`Error: directory does not exist: ${folderPath}`);
|
|
121
115
|
process.exit(1);
|
|
122
116
|
}
|
|
123
|
-
const manifestPath =
|
|
124
|
-
if (!
|
|
117
|
+
const manifestPath = path.join(folderPath, 'MANIFEST.sha256');
|
|
118
|
+
if (!fs.existsSync(manifestPath)) {
|
|
125
119
|
console.error(`Error: MANIFEST.sha256 not found: ${manifestPath}`);
|
|
126
120
|
process.exit(1);
|
|
127
121
|
}
|
|
128
122
|
// Step 1: Local file integrity verification using shared MANIFEST parser
|
|
129
123
|
console.log('=== Step 1: Local File Integrity Verification ===');
|
|
130
|
-
const manifestContent =
|
|
131
|
-
const results =
|
|
124
|
+
const manifestContent = fs.readFileSync(manifestPath, 'utf-8');
|
|
125
|
+
const results = verifyManifestEntries(manifestContent, folderPath);
|
|
132
126
|
let allPassed = true;
|
|
133
127
|
for (const r of results) {
|
|
134
128
|
if (r.passed) {
|
|
@@ -147,11 +141,11 @@ async function cmdVerifyFolder(session, folderPath) {
|
|
|
147
141
|
console.log('\nLocal verification passed!');
|
|
148
142
|
// Step 2: Compute MANIFEST hash and verify on-chain
|
|
149
143
|
console.log('\n=== Step 2: On-chain Signature Verification ===');
|
|
150
|
-
const manifestHash =
|
|
144
|
+
const manifestHash = hashFile(manifestPath);
|
|
151
145
|
console.log(`MANIFEST SHA256: ${manifestHash}`);
|
|
152
146
|
const actor = await session.getAnonymousSignActor();
|
|
153
147
|
const events = await actor.verify_file_hash(manifestHash);
|
|
154
|
-
console.log(
|
|
148
|
+
console.log(formatSignEvents(events));
|
|
155
149
|
await resolveSigners(session, events);
|
|
156
150
|
}
|
|
157
151
|
/** Query Kind 1 identity profile */
|
|
@@ -164,7 +158,7 @@ async function cmdVerifyProfile(session, principal) {
|
|
|
164
158
|
const result = await actor.get_kind1_event_by_principal(principal);
|
|
165
159
|
// opt SignEvent → formatted output
|
|
166
160
|
if (result && result.length > 0) {
|
|
167
|
-
console.log(`(opt ${
|
|
161
|
+
console.log(`(opt ${formatSignEvent(result[0])})`);
|
|
168
162
|
}
|
|
169
163
|
else {
|
|
170
164
|
console.log('(null)');
|
|
@@ -175,7 +169,7 @@ async function cmdVerifyProfile(session, principal) {
|
|
|
175
169
|
* Entry point when invoked via cli.ts.
|
|
176
170
|
* Receives a Session instance with pre-parsed arguments.
|
|
177
171
|
*/
|
|
178
|
-
async function run(session) {
|
|
172
|
+
export async function run(session) {
|
|
179
173
|
const command = session.args._args[0];
|
|
180
174
|
try {
|
|
181
175
|
switch (command) {
|
package/dist/verify.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify.js","sourceRoot":"","sources":["../src/verify.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"verify.js","sourceRoot":"","sources":["../src/verify.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EACL,QAAQ,EACR,qBAAqB,EACrB,eAAe,EACf,gBAAgB,GACjB,MAAM,YAAY,CAAC;AAIpB,yCAAyC;AACzC,SAAS,QAAQ;IACf,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;IAC3C,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACtB,OAAO,CAAC,GAAG,CAAC,oEAAoE,CAAC,CAAC;IAClF,OAAO,CAAC,GAAG,CAAC,0EAA0E,CAAC,CAAC;IACxF,OAAO,CAAC,GAAG,CAAC,uFAAuF,CAAC,CAAC;IACrG,OAAO,CAAC,GAAG,CAAC,2EAA2E,CAAC,CAAC;IACzF,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACzB,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;IAClD,OAAO,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAC;IACpD,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;AACvD,CAAC;AAED;;;GAGG;AACH,KAAK,UAAU,cAAc,CAAC,OAAgB,EAAE,MAAmB;IACjE,MAAM,WAAW,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAE5C,4BAA4B;IAC5B,MAAM,KAAK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,CAAC;gBACD,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/vetkey.d.ts
CHANGED
|
@@ -13,10 +13,14 @@
|
|
|
13
13
|
* serve Start daemon (UDS or stdio mode)
|
|
14
14
|
* stop Stop a running daemon
|
|
15
15
|
* status Query daemon status
|
|
16
|
+
* grant Grant Kind5 decryption access to another user
|
|
17
|
+
* revoke Revoke an access grant
|
|
18
|
+
* grants-out List grants issued by the caller (as grantor)
|
|
19
|
+
* grants-in List grants received by the caller (as grantee)
|
|
16
20
|
*
|
|
17
21
|
* Usage: zcloak-ai vetkey <sub-command> [options]
|
|
18
22
|
*/
|
|
19
|
-
import type { Session } from './session';
|
|
23
|
+
import type { Session } from './session.js';
|
|
20
24
|
/**
|
|
21
25
|
* Run the vetkey sub-command.
|
|
22
26
|
* Follows the same pattern as other CLI modules (sign.ts, verify.ts, etc.).
|
package/dist/vetkey.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* VetKey CLI Module — VetKey IBE encryption/decryption and daemon management
|
|
4
3
|
*
|
|
@@ -14,52 +13,22 @@
|
|
|
14
13
|
* serve Start daemon (UDS or stdio mode)
|
|
15
14
|
* stop Stop a running daemon
|
|
16
15
|
* status Query daemon status
|
|
16
|
+
* grant Grant Kind5 decryption access to another user
|
|
17
|
+
* revoke Revoke an access grant
|
|
18
|
+
* grants-out List grants issued by the caller (as grantor)
|
|
19
|
+
* grants-in List grants received by the caller (as grantee)
|
|
17
20
|
*
|
|
18
21
|
* Usage: zcloak-ai vetkey <sub-command> [options]
|
|
19
22
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
o[k2] = m[k];
|
|
30
|
-
}));
|
|
31
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
32
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
33
|
-
}) : function(o, v) {
|
|
34
|
-
o["default"] = v;
|
|
35
|
-
});
|
|
36
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
37
|
-
var ownKeys = function(o) {
|
|
38
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
39
|
-
var ar = [];
|
|
40
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
41
|
-
return ar;
|
|
42
|
-
};
|
|
43
|
-
return ownKeys(o);
|
|
44
|
-
};
|
|
45
|
-
return function (mod) {
|
|
46
|
-
if (mod && mod.__esModule) return mod;
|
|
47
|
-
var result = {};
|
|
48
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
49
|
-
__setModuleDefault(result, mod);
|
|
50
|
-
return result;
|
|
51
|
-
};
|
|
52
|
-
})();
|
|
53
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
-
exports.run = run;
|
|
55
|
-
const fs_1 = require("fs");
|
|
56
|
-
const net_1 = require("net");
|
|
57
|
-
const readline_1 = require("readline");
|
|
58
|
-
const cryptoOps = __importStar(require("./crypto"));
|
|
59
|
-
const key_store_1 = require("./key-store");
|
|
60
|
-
const serve_1 = require("./serve");
|
|
61
|
-
const daemon_1 = require("./daemon");
|
|
62
|
-
const error_1 = require("./error");
|
|
23
|
+
import { readFileSync, writeFileSync } from 'fs';
|
|
24
|
+
import { createConnection } from 'net';
|
|
25
|
+
import { createInterface } from 'readline';
|
|
26
|
+
import { Principal } from '@dfinity/principal';
|
|
27
|
+
import * as cryptoOps from './crypto.js';
|
|
28
|
+
import { KeyStore } from './key-store.js';
|
|
29
|
+
import { runDaemonUds, runDaemonStdio } from './serve.js';
|
|
30
|
+
import { findRunningDaemon } from './daemon.js';
|
|
31
|
+
import { canisterCallError } from './error.js';
|
|
63
32
|
// ============================================================================
|
|
64
33
|
// Module Entry Point
|
|
65
34
|
// ============================================================================
|
|
@@ -69,7 +38,7 @@ const error_1 = require("./error");
|
|
|
69
38
|
*
|
|
70
39
|
* @param session - CLI session with parsed args and canister access
|
|
71
40
|
*/
|
|
72
|
-
async function run(session) {
|
|
41
|
+
export async function run(session) {
|
|
73
42
|
const command = session.args._args[0];
|
|
74
43
|
switch (command) {
|
|
75
44
|
case 'encrypt-sign':
|
|
@@ -93,6 +62,18 @@ async function run(session) {
|
|
|
93
62
|
case 'status':
|
|
94
63
|
await cmdStatus(session);
|
|
95
64
|
break;
|
|
65
|
+
case 'grant':
|
|
66
|
+
await cmdGrant(session);
|
|
67
|
+
break;
|
|
68
|
+
case 'revoke':
|
|
69
|
+
await cmdRevoke(session);
|
|
70
|
+
break;
|
|
71
|
+
case 'grants-out':
|
|
72
|
+
await cmdGrantsOut(session);
|
|
73
|
+
break;
|
|
74
|
+
case 'grants-in':
|
|
75
|
+
await cmdGrantsIn(session);
|
|
76
|
+
break;
|
|
96
77
|
default:
|
|
97
78
|
showHelp();
|
|
98
79
|
process.exit(command ? 1 : 0);
|
|
@@ -114,17 +95,27 @@ function showHelp() {
|
|
|
114
95
|
console.log(' stop Stop a running daemon');
|
|
115
96
|
console.log(' status Query daemon status');
|
|
116
97
|
console.log('');
|
|
98
|
+
console.log('Kind5 Access Control:');
|
|
99
|
+
console.log(' grant Grant decryption access to another user');
|
|
100
|
+
console.log(' revoke Revoke an access grant');
|
|
101
|
+
console.log(' grants-out List grants you issued (as grantor)');
|
|
102
|
+
console.log(' grants-in List grants you received (as grantee)');
|
|
103
|
+
console.log('');
|
|
117
104
|
console.log('Options:');
|
|
118
|
-
console.log(' --text=<content>
|
|
119
|
-
console.log(' --file=<path>
|
|
120
|
-
console.log(' --event-id=<id>
|
|
121
|
-
console.log(' --output=<path>
|
|
122
|
-
console.log(' --key-name=<name>
|
|
123
|
-
console.log(' --stdio
|
|
124
|
-
console.log(' --public-key=<hex>
|
|
125
|
-
console.log(' --ibe-identity=<id>
|
|
126
|
-
console.log(' --tags=<json>
|
|
127
|
-
console.log(' --json
|
|
105
|
+
console.log(' --text=<content> Plaintext to encrypt');
|
|
106
|
+
console.log(' --file=<path> File to encrypt');
|
|
107
|
+
console.log(' --event-id=<id> Event ID for decryption');
|
|
108
|
+
console.log(' --output=<path> Output file path');
|
|
109
|
+
console.log(' --key-name=<name> Daemon key name (default: "default")');
|
|
110
|
+
console.log(' --stdio Use stdin/stdout mode for daemon');
|
|
111
|
+
console.log(' --public-key=<hex> IBE public key for offline encryption');
|
|
112
|
+
console.log(' --ibe-identity=<id> IBE identity for offline encryption');
|
|
113
|
+
console.log(' --tags=<json> Tags as JSON array');
|
|
114
|
+
console.log(' --json Output in JSON format');
|
|
115
|
+
console.log(' --grantee=<principal> Grantee principal (for grant)');
|
|
116
|
+
console.log(' --event-ids=<id1,id2> Event IDs to authorize (for grant, empty=all)');
|
|
117
|
+
console.log(' --duration=<dur> Grant duration: 30d, 1y, permanent (for grant)');
|
|
118
|
+
console.log(' --grant-id=<id> Grant ID (for revoke)');
|
|
128
119
|
}
|
|
129
120
|
// ============================================================================
|
|
130
121
|
// Command Implementations
|
|
@@ -165,7 +156,7 @@ async function cmdEncryptSign(session) {
|
|
|
165
156
|
dpkBytes = new Uint8Array(result);
|
|
166
157
|
}
|
|
167
158
|
catch (e) {
|
|
168
|
-
throw
|
|
159
|
+
throw canisterCallError(`get_ibe_public_key failed: ${e instanceof Error ? e.message : String(e)}`, e);
|
|
169
160
|
}
|
|
170
161
|
// Step 2: Generate IBE identity
|
|
171
162
|
const ibeIdentity = cryptoOps.makeIbeIdentity(principal, plaintext);
|
|
@@ -183,7 +174,7 @@ async function cmdEncryptSign(session) {
|
|
|
183
174
|
});
|
|
184
175
|
}
|
|
185
176
|
catch (e) {
|
|
186
|
-
throw
|
|
177
|
+
throw canisterCallError(`sign Kind5PrivatePost failed: ${e instanceof Error ? e.message : String(e)}`, e);
|
|
187
178
|
}
|
|
188
179
|
// Step 5: Output
|
|
189
180
|
if (jsonOutput) {
|
|
@@ -225,7 +216,7 @@ async function cmdDecrypt(session) {
|
|
|
225
216
|
dpkBytes = new Uint8Array(result);
|
|
226
217
|
}
|
|
227
218
|
catch (e) {
|
|
228
|
-
throw
|
|
219
|
+
throw canisterCallError(`get_ibe_public_key failed: ${e instanceof Error ? e.message : String(e)}`, e);
|
|
229
220
|
}
|
|
230
221
|
// Request decryption package from canister
|
|
231
222
|
let pkg;
|
|
@@ -238,13 +229,13 @@ async function cmdDecrypt(session) {
|
|
|
238
229
|
};
|
|
239
230
|
}
|
|
240
231
|
catch (e) {
|
|
241
|
-
throw
|
|
232
|
+
throw canisterCallError(`get_kind5_decryption_key failed: ${e instanceof Error ? e.message : String(e)}`, e);
|
|
242
233
|
}
|
|
243
234
|
// Full decrypt
|
|
244
235
|
const plaintext = cryptoOps.ibeDecrypt(pkg.encrypted_key, dpkBytes, pkg.ibe_identity, pkg.ciphertext, transportSecret);
|
|
245
236
|
// Output
|
|
246
237
|
if (output) {
|
|
247
|
-
|
|
238
|
+
writeFileSync(output, plaintext);
|
|
248
239
|
if (jsonOutput) {
|
|
249
240
|
console.log(JSON.stringify({
|
|
250
241
|
event_id: eventId,
|
|
@@ -302,7 +293,7 @@ async function cmdEncryptOnly(session) {
|
|
|
302
293
|
dpkBytes = new Uint8Array(result);
|
|
303
294
|
}
|
|
304
295
|
catch (e) {
|
|
305
|
-
throw
|
|
296
|
+
throw canisterCallError(`get_ibe_public_key failed: ${e instanceof Error ? e.message : String(e)}`, e);
|
|
306
297
|
}
|
|
307
298
|
}
|
|
308
299
|
const ibeIdentity = ibeIdentityOverride ?? cryptoOps.makeIbeIdentity(principalText, plaintext);
|
|
@@ -336,7 +327,7 @@ async function cmdGetPubkey(session) {
|
|
|
336
327
|
dpkBytes = new Uint8Array(result);
|
|
337
328
|
}
|
|
338
329
|
catch (e) {
|
|
339
|
-
throw
|
|
330
|
+
throw canisterCallError(`get_ibe_public_key failed: ${e instanceof Error ? e.message : String(e)}`, e);
|
|
340
331
|
}
|
|
341
332
|
if (jsonOutput) {
|
|
342
333
|
console.log(JSON.stringify({
|
|
@@ -372,13 +363,13 @@ async function cmdServe(session) {
|
|
|
372
363
|
}
|
|
373
364
|
// Derive AES-256 key from VetKey via the sign actor
|
|
374
365
|
console.error(`Deriving AES-256 key from VetKey (derivation_id: ${derivationId})...`);
|
|
375
|
-
const keyStore = await
|
|
366
|
+
const keyStore = await KeyStore.deriveFromActor(actor, derivationId);
|
|
376
367
|
console.error("Key derived successfully. Starting JSON-RPC daemon...");
|
|
377
368
|
if (stdio) {
|
|
378
|
-
await
|
|
369
|
+
await runDaemonStdio(keyStore, principal, derivationId);
|
|
379
370
|
}
|
|
380
371
|
else {
|
|
381
|
-
await
|
|
372
|
+
await runDaemonUds(keyStore, principal, derivationId);
|
|
382
373
|
}
|
|
383
374
|
}
|
|
384
375
|
/**
|
|
@@ -390,7 +381,7 @@ async function cmdStop(session) {
|
|
|
390
381
|
const jsonOutput = !!args['json'];
|
|
391
382
|
const principal = session.getPrincipal();
|
|
392
383
|
const derivationId = `${principal}:${keyName}`;
|
|
393
|
-
const sockPath =
|
|
384
|
+
const sockPath = findRunningDaemon(derivationId);
|
|
394
385
|
// Connect to socket and send shutdown
|
|
395
386
|
const response = await sendRpcToSocket(sockPath, {
|
|
396
387
|
id: 1,
|
|
@@ -412,7 +403,7 @@ async function cmdStatus(session) {
|
|
|
412
403
|
const jsonOutput = !!args['json'];
|
|
413
404
|
const principal = session.getPrincipal();
|
|
414
405
|
const derivationId = `${principal}:${keyName}`;
|
|
415
|
-
const sockPath =
|
|
406
|
+
const sockPath = findRunningDaemon(derivationId);
|
|
416
407
|
// Connect to socket and send status
|
|
417
408
|
const response = await sendRpcToSocket(sockPath, {
|
|
418
409
|
id: 1,
|
|
@@ -452,7 +443,7 @@ function readInput(text, file) {
|
|
|
452
443
|
if (text)
|
|
453
444
|
return new TextEncoder().encode(text);
|
|
454
445
|
if (file)
|
|
455
|
-
return
|
|
446
|
+
return readFileSync(file);
|
|
456
447
|
throw new Error("Either --text or --file must be provided");
|
|
457
448
|
}
|
|
458
449
|
/**
|
|
@@ -461,12 +452,12 @@ function readInput(text, file) {
|
|
|
461
452
|
*/
|
|
462
453
|
function sendRpcToSocket(socketPath, request) {
|
|
463
454
|
return new Promise((resolve, reject) => {
|
|
464
|
-
const conn =
|
|
455
|
+
const conn = createConnection(socketPath);
|
|
465
456
|
let responded = false;
|
|
466
457
|
conn.on("connect", () => {
|
|
467
458
|
conn.write(JSON.stringify(request) + "\n");
|
|
468
459
|
});
|
|
469
|
-
const rl =
|
|
460
|
+
const rl = createInterface({ input: conn });
|
|
470
461
|
rl.on("line", (line) => {
|
|
471
462
|
if (!responded) {
|
|
472
463
|
responded = true;
|
|
@@ -504,4 +495,249 @@ function sendRpcToSocket(socketPath, request) {
|
|
|
504
495
|
}, 10000);
|
|
505
496
|
});
|
|
506
497
|
}
|
|
498
|
+
/**
|
|
499
|
+
* Parse a human-readable duration string into nanoseconds.
|
|
500
|
+
*
|
|
501
|
+
* Supported formats:
|
|
502
|
+
* - "permanent" or "perm" → undefined (no expiration)
|
|
503
|
+
* - "<number>d" → days
|
|
504
|
+
* - "<number>h" → hours
|
|
505
|
+
* - "<number>y" → years (365 days)
|
|
506
|
+
* - "<number>m" → months (30 days)
|
|
507
|
+
* - plain number → treated as seconds
|
|
508
|
+
*
|
|
509
|
+
* @returns bigint nanoseconds, or undefined for permanent
|
|
510
|
+
*/
|
|
511
|
+
function parseDuration(input) {
|
|
512
|
+
const s = input.trim().toLowerCase();
|
|
513
|
+
if (s === 'permanent' || s === 'perm')
|
|
514
|
+
return undefined;
|
|
515
|
+
const NS_PER_SEC = 1000000000n;
|
|
516
|
+
const match = s.match(/^(\d+)\s*([dhmy]?)$/);
|
|
517
|
+
if (!match)
|
|
518
|
+
throw new Error(`Invalid duration format: "${input}". Use e.g. 30d, 24h, 1y, permanent`);
|
|
519
|
+
const num = BigInt(match[1]);
|
|
520
|
+
const unit = match[2] || 's';
|
|
521
|
+
switch (unit) {
|
|
522
|
+
case 'h': return num * 3600n * NS_PER_SEC;
|
|
523
|
+
case 'd': return num * 86400n * NS_PER_SEC;
|
|
524
|
+
case 'm': return num * 30n * 86400n * NS_PER_SEC;
|
|
525
|
+
case 'y': return num * 365n * 86400n * NS_PER_SEC;
|
|
526
|
+
case 's': return num * NS_PER_SEC;
|
|
527
|
+
default: throw new Error(`Unknown duration unit: ${unit}`);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Format a nanosecond timestamp to a human-readable date string.
|
|
532
|
+
* Returns "permanent" for u64::MAX.
|
|
533
|
+
*/
|
|
534
|
+
function formatNsTimestamp(ns) {
|
|
535
|
+
// u64::MAX = 18446744073709551615
|
|
536
|
+
if (ns >= 18446744073709551615n)
|
|
537
|
+
return 'permanent';
|
|
538
|
+
const ms = Number(ns / 1000000n);
|
|
539
|
+
return new Date(ms).toISOString();
|
|
540
|
+
}
|
|
541
|
+
// ============================================================================
|
|
542
|
+
// Kind5 Access Control Commands
|
|
543
|
+
// ============================================================================
|
|
544
|
+
/**
|
|
545
|
+
* grant: Authorize another user to decrypt your Kind5 encrypted posts.
|
|
546
|
+
*
|
|
547
|
+
* Options:
|
|
548
|
+
* --grantee=<principal> (required) Recipient's principal ID
|
|
549
|
+
* --event-ids=<id1,id2> (optional) Specific event IDs to authorize; empty = all Kind5 posts
|
|
550
|
+
* --duration=<dur> (optional) Duration: 30d, 1y, permanent (default: permanent)
|
|
551
|
+
* --json Output in JSON format
|
|
552
|
+
*/
|
|
553
|
+
async function cmdGrant(session) {
|
|
554
|
+
const args = session.args;
|
|
555
|
+
const granteePrincipal = args['grantee'];
|
|
556
|
+
const eventIdsStr = args['event-ids'];
|
|
557
|
+
const durationStr = args['duration'];
|
|
558
|
+
const jsonOutput = !!args['json'];
|
|
559
|
+
if (!granteePrincipal) {
|
|
560
|
+
throw new Error('--grantee=<principal> is required');
|
|
561
|
+
}
|
|
562
|
+
// Validate grantee is a valid principal
|
|
563
|
+
let grantee;
|
|
564
|
+
try {
|
|
565
|
+
grantee = Principal.fromText(granteePrincipal);
|
|
566
|
+
}
|
|
567
|
+
catch {
|
|
568
|
+
throw new Error(`Invalid grantee principal: "${granteePrincipal}"`);
|
|
569
|
+
}
|
|
570
|
+
// Parse event IDs (comma-separated, empty list = all Kind5 posts)
|
|
571
|
+
const eventIds = eventIdsStr
|
|
572
|
+
? eventIdsStr.split(',').map(id => id.trim()).filter(Boolean)
|
|
573
|
+
: [];
|
|
574
|
+
// Parse duration (default: permanent)
|
|
575
|
+
const durationNs = durationStr ? parseDuration(durationStr) : undefined;
|
|
576
|
+
// Candid opt: [bigint] when present, [] when None (permanent)
|
|
577
|
+
const durationOpt = durationNs !== undefined ? [durationNs] : [];
|
|
578
|
+
const actor = await session.getSignActor();
|
|
579
|
+
let result;
|
|
580
|
+
try {
|
|
581
|
+
result = await actor.grant_kind5_access({
|
|
582
|
+
grantee,
|
|
583
|
+
event_ids: eventIds,
|
|
584
|
+
duration_ns: durationOpt,
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
catch (e) {
|
|
588
|
+
throw canisterCallError(`grant_kind5_access failed: ${e instanceof Error ? e.message : String(e)}`, e);
|
|
589
|
+
}
|
|
590
|
+
if ('Err' in result) {
|
|
591
|
+
throw new Error(`Grant failed: ${result.Err}`);
|
|
592
|
+
}
|
|
593
|
+
const grantId = result.Ok;
|
|
594
|
+
if (jsonOutput) {
|
|
595
|
+
console.log(JSON.stringify({
|
|
596
|
+
grant_id: grantId.toString(),
|
|
597
|
+
grantee: granteePrincipal,
|
|
598
|
+
event_ids: eventIds,
|
|
599
|
+
scope: eventIds.length === 0 ? 'all_kind5_posts' : 'specific_events',
|
|
600
|
+
duration: durationStr || 'permanent',
|
|
601
|
+
}));
|
|
602
|
+
}
|
|
603
|
+
else {
|
|
604
|
+
console.log('Kind5 access granted successfully!');
|
|
605
|
+
console.log(` Grant ID: ${grantId}`);
|
|
606
|
+
console.log(` Grantee: ${granteePrincipal}`);
|
|
607
|
+
console.log(` Scope: ${eventIds.length === 0 ? 'All Kind5 posts' : `${eventIds.length} specific event(s)`}`);
|
|
608
|
+
console.log(` Duration: ${durationStr || 'permanent'}`);
|
|
609
|
+
if (eventIds.length > 0) {
|
|
610
|
+
console.log(` Event IDs: ${eventIds.join(', ')}`);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* revoke: Revoke an access grant by grant ID.
|
|
616
|
+
*
|
|
617
|
+
* Options:
|
|
618
|
+
* --grant-id=<id> (required) The grant ID to revoke
|
|
619
|
+
* --json Output in JSON format
|
|
620
|
+
*/
|
|
621
|
+
async function cmdRevoke(session) {
|
|
622
|
+
const args = session.args;
|
|
623
|
+
const grantIdStr = args['grant-id'];
|
|
624
|
+
const jsonOutput = !!args['json'];
|
|
625
|
+
if (!grantIdStr) {
|
|
626
|
+
throw new Error('--grant-id=<id> is required');
|
|
627
|
+
}
|
|
628
|
+
let grantId;
|
|
629
|
+
try {
|
|
630
|
+
grantId = BigInt(grantIdStr);
|
|
631
|
+
}
|
|
632
|
+
catch {
|
|
633
|
+
throw new Error(`Invalid grant ID: "${grantIdStr}" (must be a number)`);
|
|
634
|
+
}
|
|
635
|
+
const actor = await session.getSignActor();
|
|
636
|
+
let result;
|
|
637
|
+
try {
|
|
638
|
+
result = await actor.revoke_kind5_access(grantId);
|
|
639
|
+
}
|
|
640
|
+
catch (e) {
|
|
641
|
+
throw canisterCallError(`revoke_kind5_access failed: ${e instanceof Error ? e.message : String(e)}`, e);
|
|
642
|
+
}
|
|
643
|
+
if ('Err' in result) {
|
|
644
|
+
throw new Error(`Revoke failed: ${result.Err}`);
|
|
645
|
+
}
|
|
646
|
+
if (jsonOutput) {
|
|
647
|
+
console.log(JSON.stringify({ grant_id: grantIdStr, revoked: true }));
|
|
648
|
+
}
|
|
649
|
+
else {
|
|
650
|
+
console.log(`Grant ${grantIdStr} revoked successfully.`);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* grants-out: List all active grants issued by the caller (as grantor).
|
|
655
|
+
*/
|
|
656
|
+
async function cmdGrantsOut(session) {
|
|
657
|
+
const jsonOutput = !!session.args['json'];
|
|
658
|
+
const actor = await session.getSignActor();
|
|
659
|
+
let grants;
|
|
660
|
+
try {
|
|
661
|
+
grants = await actor.get_kind5_grants_by_grantor();
|
|
662
|
+
}
|
|
663
|
+
catch (e) {
|
|
664
|
+
throw canisterCallError(`get_kind5_grants_by_grantor failed: ${e instanceof Error ? e.message : String(e)}`, e);
|
|
665
|
+
}
|
|
666
|
+
if (jsonOutput) {
|
|
667
|
+
console.log(JSON.stringify(formatGrantsForJson(grants)));
|
|
668
|
+
}
|
|
669
|
+
else {
|
|
670
|
+
printGrants(grants, 'issued');
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* grants-in: List all active grants received by the caller (as grantee).
|
|
675
|
+
*/
|
|
676
|
+
async function cmdGrantsIn(session) {
|
|
677
|
+
const jsonOutput = !!session.args['json'];
|
|
678
|
+
const actor = await session.getSignActor();
|
|
679
|
+
let grants;
|
|
680
|
+
try {
|
|
681
|
+
grants = await actor.get_kind5_grants_by_grantee();
|
|
682
|
+
}
|
|
683
|
+
catch (e) {
|
|
684
|
+
throw canisterCallError(`get_kind5_grants_by_grantee failed: ${e instanceof Error ? e.message : String(e)}`, e);
|
|
685
|
+
}
|
|
686
|
+
if (jsonOutput) {
|
|
687
|
+
console.log(JSON.stringify(formatGrantsForJson(grants)));
|
|
688
|
+
}
|
|
689
|
+
else {
|
|
690
|
+
printGrants(grants, 'received');
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Format grant records for JSON output.
|
|
695
|
+
* Converts bigint fields to strings for JSON serialization.
|
|
696
|
+
*/
|
|
697
|
+
function formatGrantsForJson(grants) {
|
|
698
|
+
return grants.map(g => ({
|
|
699
|
+
grant_id: g.grant_id.toString(),
|
|
700
|
+
grantor: g.grantor.toText(),
|
|
701
|
+
grantee: g.grantee.toText(),
|
|
702
|
+
event_ids: g.event_ids,
|
|
703
|
+
scope: g.event_ids.length === 0 ? 'all_kind5_posts' : 'specific_events',
|
|
704
|
+
created_at: g.created_at.toString(),
|
|
705
|
+
expires_at: g.expires_at.toString(),
|
|
706
|
+
expires_at_human: formatNsTimestamp(g.expires_at),
|
|
707
|
+
status: 'Active' in g.status ? 'Active' : 'Revoked',
|
|
708
|
+
}));
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* Print grant records in human-readable table format.
|
|
712
|
+
* @param grants - Array of AccessGrant records from canister
|
|
713
|
+
* @param direction - "issued" (grants-out) or "received" (grants-in)
|
|
714
|
+
*/
|
|
715
|
+
function printGrants(grants, direction) {
|
|
716
|
+
if (grants.length === 0) {
|
|
717
|
+
console.log(`No Kind5 access grants ${direction}.`);
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
console.log(`Kind5 access grants ${direction} (${grants.length} total):`);
|
|
721
|
+
console.log('');
|
|
722
|
+
for (const g of grants) {
|
|
723
|
+
const scope = g.event_ids.length === 0
|
|
724
|
+
? 'All Kind5 posts'
|
|
725
|
+
: `${g.event_ids.length} event(s)`;
|
|
726
|
+
const peer = direction === 'issued'
|
|
727
|
+
? `Grantee: ${g.grantee.toText()}`
|
|
728
|
+
: `Grantor: ${g.grantor.toText()}`;
|
|
729
|
+
console.log(` [Grant #${g.grant_id}]`);
|
|
730
|
+
console.log(` ${peer}`);
|
|
731
|
+
console.log(` Scope: ${scope}`);
|
|
732
|
+
console.log(` Expires: ${formatNsTimestamp(g.expires_at)}`);
|
|
733
|
+
console.log(` Created: ${formatNsTimestamp(g.created_at)}`);
|
|
734
|
+
if (g.event_ids.length > 0 && g.event_ids.length <= 5) {
|
|
735
|
+
console.log(` Event IDs: ${g.event_ids.join(', ')}`);
|
|
736
|
+
}
|
|
737
|
+
else if (g.event_ids.length > 5) {
|
|
738
|
+
console.log(` Event IDs: ${g.event_ids.slice(0, 5).join(', ')} ... (+${g.event_ids.length - 5} more)`);
|
|
739
|
+
}
|
|
740
|
+
console.log('');
|
|
741
|
+
}
|
|
742
|
+
}
|
|
507
743
|
//# sourceMappingURL=vetkey.js.map
|