@hai.ai/jacs 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +336 -52
- package/client.d.ts +96 -0
- package/client.js +560 -0
- package/express.d.ts +69 -0
- package/express.js +130 -0
- package/express.js.map +1 -0
- package/index.d.ts +117 -96
- package/index.js +19 -17
- package/jacs.darwin-arm64.node +0 -0
- package/jacs.darwin-x64.node +0 -0
- package/jacs.linux-arm-gnueabihf.node +0 -0
- package/jacs.linux-arm-musleabihf.node +0 -0
- package/jacs.linux-arm64-gnu.node +0 -0
- package/jacs.linux-x64-gnu.node +0 -0
- package/jacs.linux-x64-musl.node +0 -0
- package/koa.d.ts +59 -0
- package/koa.js +124 -0
- package/koa.js.map +1 -0
- package/langchain.d.ts +97 -0
- package/langchain.js +439 -0
- package/langchain.js.map +1 -0
- package/mcp.d.ts +75 -42
- package/mcp.js +449 -422
- package/mcp.js.map +1 -1
- package/package.json +91 -7
- package/scripts/install-cli.js +125 -0
- package/simple.d.ts +92 -430
- package/simple.js +507 -524
- package/src/a2a.js +2 -2
- package/testing.d.ts +39 -0
- package/testing.js +49 -0
- package/vercel-ai.d.ts +54 -0
- package/vercel-ai.js +162 -0
- package/vercel-ai.js.map +1 -0
- package/mcp.ts +0 -521
package/express.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* JACS Express Middleware
|
|
4
|
+
*
|
|
5
|
+
* Factory-based middleware for Express v4/v5 that verifies incoming
|
|
6
|
+
* JACS-signed request bodies and optionally auto-signs JSON responses.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import express from 'express';
|
|
11
|
+
* import { JacsClient } from './client';
|
|
12
|
+
* import { jacsMiddleware } from './express';
|
|
13
|
+
*
|
|
14
|
+
* const client = await JacsClient.quickstart();
|
|
15
|
+
* const app = express();
|
|
16
|
+
* app.use(express.text({ type: 'application/json' }));
|
|
17
|
+
* app.use(jacsMiddleware({ client, verify: true }));
|
|
18
|
+
*
|
|
19
|
+
* app.post('/api/data', (req, res) => {
|
|
20
|
+
* console.log(req.jacsPayload); // verified payload
|
|
21
|
+
* res.json({ status: 'ok' });
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.jacsMiddleware = jacsMiddleware;
|
|
27
|
+
// =============================================================================
|
|
28
|
+
// Internal helpers
|
|
29
|
+
// =============================================================================
|
|
30
|
+
/** Methods that carry a request body. */
|
|
31
|
+
const BODY_METHODS = new Set(['POST', 'PUT', 'PATCH']);
|
|
32
|
+
async function resolveClient(options) {
|
|
33
|
+
if (options.client) {
|
|
34
|
+
return options.client;
|
|
35
|
+
}
|
|
36
|
+
// Lazy-import to avoid hard dependency on client.ts at module level
|
|
37
|
+
const { JacsClient: ClientCtor } = await import('./client.js');
|
|
38
|
+
if (options.configPath) {
|
|
39
|
+
const client = new ClientCtor();
|
|
40
|
+
await client.load(options.configPath);
|
|
41
|
+
return client;
|
|
42
|
+
}
|
|
43
|
+
return ClientCtor.quickstart();
|
|
44
|
+
}
|
|
45
|
+
// =============================================================================
|
|
46
|
+
// Middleware factory
|
|
47
|
+
// =============================================================================
|
|
48
|
+
/**
|
|
49
|
+
* Create JACS Express middleware.
|
|
50
|
+
*
|
|
51
|
+
* The returned middleware attaches `req.jacsClient` on every request.
|
|
52
|
+
* When `verify` is true (default), POST/PUT/PATCH bodies are verified as
|
|
53
|
+
* JACS-signed documents and the extracted payload is set on `req.jacsPayload`.
|
|
54
|
+
* When `sign` is true, `res.json()` is intercepted to auto-sign the response.
|
|
55
|
+
*/
|
|
56
|
+
function jacsMiddleware(options = {}) {
|
|
57
|
+
const shouldVerify = options.verify !== false;
|
|
58
|
+
const shouldSign = options.sign === true;
|
|
59
|
+
const isOptional = options.optional === true;
|
|
60
|
+
// Client is resolved once (lazy, on first request) then cached.
|
|
61
|
+
let clientPromise = null;
|
|
62
|
+
function getClient() {
|
|
63
|
+
if (!clientPromise) {
|
|
64
|
+
clientPromise = resolveClient(options);
|
|
65
|
+
}
|
|
66
|
+
return clientPromise;
|
|
67
|
+
}
|
|
68
|
+
// Pre-resolve immediately if a client is already provided (avoids first-request latency).
|
|
69
|
+
if (options.client) {
|
|
70
|
+
clientPromise = Promise.resolve(options.client);
|
|
71
|
+
}
|
|
72
|
+
return async function jacsExpressMiddleware(req, res, next) {
|
|
73
|
+
let client;
|
|
74
|
+
try {
|
|
75
|
+
client = await getClient();
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
res.status(500).json({ error: 'JACS initialization failed' });
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
// Always expose the client on the request for manual use in route handlers.
|
|
82
|
+
req.jacsClient = client;
|
|
83
|
+
// ----- Verify incoming body -----
|
|
84
|
+
if (shouldVerify && BODY_METHODS.has(req.method)) {
|
|
85
|
+
const rawBody = typeof req.body === 'string' ? req.body : null;
|
|
86
|
+
if (rawBody) {
|
|
87
|
+
try {
|
|
88
|
+
const result = await client.verify(rawBody);
|
|
89
|
+
if (result.valid) {
|
|
90
|
+
req.jacsPayload = result.data;
|
|
91
|
+
}
|
|
92
|
+
else if (!isOptional) {
|
|
93
|
+
res.status(401).json({ error: 'JACS verification failed', details: result.errors });
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
// When optional and invalid, just continue without jacsPayload.
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
if (!isOptional) {
|
|
100
|
+
res.status(401).json({ error: 'JACS verification failed', details: [String(err)] });
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else if (!isOptional && req.body !== undefined) {
|
|
106
|
+
// Body exists but is not a string — cannot verify.
|
|
107
|
+
// Only reject if body is present; missing body on POST may be handled by route.
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// ----- Auto-sign responses -----
|
|
111
|
+
if (shouldSign) {
|
|
112
|
+
const originalJson = res.json.bind(res);
|
|
113
|
+
res.json = function jacsSignedJson(body) {
|
|
114
|
+
// Fire-and-forget async signing, then send via original json.
|
|
115
|
+
client
|
|
116
|
+
.signMessage(body)
|
|
117
|
+
.then((signed) => {
|
|
118
|
+
originalJson(signed.raw);
|
|
119
|
+
})
|
|
120
|
+
.catch(() => {
|
|
121
|
+
// Signing failed — send unsigned to avoid hanging response.
|
|
122
|
+
originalJson(body);
|
|
123
|
+
});
|
|
124
|
+
return res;
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
next();
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=express.js.map
|
package/express.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express.js","sourceRoot":"","sources":["express.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;AAyFH,wCAmFC;AAvHD,gFAAgF;AAChF,mBAAmB;AACnB,gFAAgF;AAEhF,yCAAyC;AACzC,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;AAEvD,KAAK,UAAU,aAAa,CAAC,OAA8B;IACzD,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACnB,OAAO,OAAO,CAAC,MAAM,CAAC;IACxB,CAAC;IAED,oEAAoE;IACpE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC;IAE/D,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,MAAM,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;QAChC,MAAM,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACtC,OAAO,MAAM,CAAC;IAChB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AAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBAC3B,CAAC,CAAC;qBACD,KAAK,CAAC,GAAG,EAAE;oBACV,4DAA4D;oBAC5D,YAAY,CAAC,IAAI,CAAC,CAAC;gBACrB,CAAC,CAAC,CAAC;gBACL,OAAO,GAAG,CAAC;YACb,CAAC,CAAC;QACJ,CAAC;QAED,IAAI,EAAE,CAAC;IACT,CAAC,CAAC;AACJ,CAAC"}
|
package/index.d.ts
CHANGED
|
@@ -3,12 +3,14 @@
|
|
|
3
3
|
|
|
4
4
|
/* auto-generated by NAPI-RS */
|
|
5
5
|
|
|
6
|
-
/** Hash a string using SHA-256. */
|
|
6
|
+
/** Hash a string using SHA-256. Sync-only (pure CPU, fast). */
|
|
7
7
|
export declare function hashString(data: string): string
|
|
8
|
-
/** Create a JACS configuration object. */
|
|
8
|
+
/** Create a JACS configuration object. Sync-only (minimal CPU). */
|
|
9
9
|
export declare function createConfig(jacsUseSecurity?: string | undefined | null, jacsDataDirectory?: string | undefined | null, jacsKeyDirectory?: string | undefined | null, jacsAgentPrivateKeyFilename?: string | undefined | null, jacsAgentPublicKeyFilename?: string | undefined | null, jacsAgentKeyAlgorithm?: string | undefined | null, jacsPrivateKeyPassword?: string | undefined | null, jacsAgentIdAndVersion?: string | undefined | null, jacsDefaultStorage?: string | undefined | null): string
|
|
10
|
-
/** Create a JACS agent programmatically (
|
|
11
|
-
export declare function
|
|
10
|
+
/** Create a JACS agent programmatically (sync, blocks event loop). */
|
|
11
|
+
export declare function createAgentSync(name: string, password: string, algorithm?: string | undefined | null, dataDirectory?: string | undefined | null, keyDirectory?: string | undefined | null, configPath?: string | undefined | null, agentType?: string | undefined | null, description?: string | undefined | null, domain?: string | undefined | null, defaultStorage?: string | undefined | null): string
|
|
12
|
+
/** Create a JACS agent programmatically (async, returns Promise). */
|
|
13
|
+
export declare function createAgent(name: string, password: string, algorithm?: string | undefined | null, dataDirectory?: string | undefined | null, keyDirectory?: string | undefined | null, configPath?: string | undefined | null, agentType?: string | undefined | null, description?: string | undefined | null, domain?: string | undefined | null, defaultStorage?: string | undefined | null): Promise<string>
|
|
12
14
|
/** Add an agent to the local trust store. */
|
|
13
15
|
export declare function trustAgent(agentJson: string): string
|
|
14
16
|
/** List all trusted agent IDs. */
|
|
@@ -19,28 +21,31 @@ export declare function untrustAgent(agentId: string): void
|
|
|
19
21
|
export declare function isTrusted(agentId: string): boolean
|
|
20
22
|
/** Get a trusted agent's JSON document. */
|
|
21
23
|
export declare function getTrustedAgent(agentId: string): string
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export declare function audit(configPath?: string | undefined | null, recentN?: number | undefined | null): string
|
|
24
|
+
/** Run a security audit (sync, blocks event loop). */
|
|
25
|
+
export declare function auditSync(configPath?: string | undefined | null, recentN?: number | undefined | null): string
|
|
26
|
+
/** Run a security audit (async, returns Promise). */
|
|
27
|
+
export declare function audit(configPath?: string | undefined | null, recentN?: number | undefined | null): Promise<string>
|
|
27
28
|
/** @deprecated Use `new JacsAgent()` and `agent.load()` instead. */
|
|
28
|
-
export declare function
|
|
29
|
+
export declare function legacyLoad(configPath: string): string
|
|
29
30
|
/** @deprecated Use `new JacsAgent()` and instance methods instead. */
|
|
30
|
-
export declare function
|
|
31
|
+
export declare function legacySignAgent(agentString: string, publicKey: Buffer, publicKeyEncType: string): string
|
|
31
32
|
/** @deprecated Use `new JacsAgent()` and instance methods instead. */
|
|
32
|
-
export declare function
|
|
33
|
+
export declare function legacyVerifyString(data: string, signatureBase64: string, publicKey: Buffer, publicKeyEncType: string): boolean
|
|
33
34
|
/** @deprecated Use `new JacsAgent()` and instance methods instead. */
|
|
34
|
-
export declare function
|
|
35
|
+
export declare function legacySignString(data: string): string
|
|
35
36
|
/** @deprecated Use `new JacsAgent()` and instance methods instead. */
|
|
36
|
-
export declare function
|
|
37
|
+
export declare function legacyVerifyAgent(agentfile?: string | undefined | null): boolean
|
|
37
38
|
/** @deprecated Use `new JacsAgent()` and instance methods instead. */
|
|
38
|
-
export declare function
|
|
39
|
-
/** Result of verify_document_standalone. Exposed to JS as { valid, signerId }. */
|
|
39
|
+
export declare function legacyUpdateAgent(newAgentString: string): string
|
|
40
|
+
/** Result of verify_document_standalone. Exposed to JS as { valid, signerId, timestamp, agentVersion }. */
|
|
40
41
|
export interface VerifyStandaloneResult {
|
|
41
42
|
valid: boolean
|
|
42
43
|
/** Signer agent ID; exposed to JS as signerId (camelCase). */
|
|
43
44
|
signerId: string
|
|
45
|
+
/** Signing timestamp from jacsSignature.date. */
|
|
46
|
+
timestamp: string
|
|
47
|
+
/** Signer agent version from jacsSignature.agentVersion. */
|
|
48
|
+
agentVersion: string
|
|
44
49
|
}
|
|
45
50
|
/**
|
|
46
51
|
* Verify a signed JACS document without loading an agent.
|
|
@@ -48,31 +53,26 @@ export interface VerifyStandaloneResult {
|
|
|
48
53
|
*/
|
|
49
54
|
export declare function verifyDocumentStandalone(signedDocument: string, keyResolution?: string | undefined | null, dataDirectory?: string | undefined | null, keyDirectory?: string | undefined | null): VerifyStandaloneResult
|
|
50
55
|
/** @deprecated Use `new JacsAgent()` and instance methods instead. */
|
|
51
|
-
export declare function
|
|
56
|
+
export declare function legacyVerifyDocument(documentString: string): boolean
|
|
52
57
|
/** @deprecated Use `new JacsAgent()` and instance methods instead. */
|
|
53
|
-
export declare function
|
|
58
|
+
export declare function legacyUpdateDocument(documentKey: string, newDocumentString: string, attachments?: Array<string> | undefined | null, embed?: boolean | undefined | null): string
|
|
54
59
|
/** @deprecated Use `new JacsAgent()` and instance methods instead. */
|
|
55
|
-
export declare function
|
|
60
|
+
export declare function legacyVerifySignature(documentString: string, signatureField?: string | undefined | null): boolean
|
|
56
61
|
/** @deprecated Use `new JacsAgent()` and instance methods instead. */
|
|
57
|
-
export declare function
|
|
62
|
+
export declare function legacyCreateAgreement(documentString: string, agentids: Array<string>, question?: string | undefined | null, context?: string | undefined | null, agreementFieldname?: string | undefined | null): string
|
|
58
63
|
/** @deprecated Use `new JacsAgent()` and instance methods instead. */
|
|
59
|
-
export declare function
|
|
64
|
+
export declare function legacySignAgreement(documentString: string, agreementFieldname?: string | undefined | null): string
|
|
60
65
|
/** @deprecated Use `new JacsAgent()` and instance methods instead. */
|
|
61
|
-
export declare function
|
|
66
|
+
export declare function legacyCreateDocument(documentString: string, customSchema?: string | undefined | null, outputfilename?: string | undefined | null, noSave?: boolean | undefined | null, attachments?: string | undefined | null, embed?: boolean | undefined | null): string
|
|
62
67
|
/** @deprecated Use `new JacsAgent()` and instance methods instead. */
|
|
63
|
-
export declare function
|
|
68
|
+
export declare function legacyCheckAgreement(documentString: string, agreementFieldname?: string | undefined | null): string
|
|
64
69
|
/** @deprecated Use `new JacsAgent()` and instance methods instead. */
|
|
65
|
-
export declare function
|
|
70
|
+
export declare function legacySignRequest(params: any): string
|
|
66
71
|
/** @deprecated Use `new JacsAgent()` and instance methods instead. */
|
|
67
|
-
export declare function
|
|
72
|
+
export declare function legacyVerifyResponse(documentString: string): object
|
|
68
73
|
/** @deprecated Use `new JacsAgent()` and instance methods instead. */
|
|
69
|
-
export declare function
|
|
70
|
-
/**
|
|
71
|
-
* Information about a public key fetched from HAI key service.
|
|
72
|
-
*
|
|
73
|
-
* This struct contains the public key data and metadata returned by
|
|
74
|
-
* the HAI key distribution service.
|
|
75
|
-
*/
|
|
74
|
+
export declare function legacyVerifyResponseWithAgentId(documentString: string): object
|
|
75
|
+
/** Information about a public key fetched from HAI key service. */
|
|
76
76
|
export interface RemotePublicKeyInfo {
|
|
77
77
|
/** The raw public key bytes (DER encoded). */
|
|
78
78
|
publicKey: Buffer
|
|
@@ -85,44 +85,9 @@ export interface RemotePublicKeyInfo {
|
|
|
85
85
|
/** The version of the key. */
|
|
86
86
|
version: string
|
|
87
87
|
}
|
|
88
|
-
/**
|
|
89
|
-
* Fetch a public key from HAI's key distribution service.
|
|
90
|
-
*
|
|
91
|
-
* This function retrieves the public key for a specific agent and version
|
|
92
|
-
* from the HAI key distribution service. It is used to obtain trusted public
|
|
93
|
-
* keys for verifying agent signatures without requiring local key storage.
|
|
94
|
-
*
|
|
95
|
-
* # Arguments
|
|
96
|
-
*
|
|
97
|
-
* * `agent_id` - The unique identifier of the agent whose key to fetch.
|
|
98
|
-
* * `version` - The version of the agent's key to fetch. Use "latest" for
|
|
99
|
-
* the most recent version. If not provided, defaults to "latest".
|
|
100
|
-
*
|
|
101
|
-
* # Returns
|
|
102
|
-
*
|
|
103
|
-
* Returns a `RemotePublicKeyInfo` object containing the public key, algorithm, and hash.
|
|
104
|
-
*
|
|
105
|
-
* # Environment Variables
|
|
106
|
-
*
|
|
107
|
-
* * `HAI_KEYS_BASE_URL` - Base URL for the key service. Defaults to `https://keys.hai.ai`.
|
|
108
|
-
*
|
|
109
|
-
* # Example
|
|
110
|
-
*
|
|
111
|
-
* ```javascript
|
|
112
|
-
* const { fetchRemoteKey } = require('@hai.ai/jacs');
|
|
113
|
-
*
|
|
114
|
-
* const keyInfo = fetchRemoteKey('550e8400-e29b-41d4-a716-446655440000', 'latest');
|
|
115
|
-
* console.log('Algorithm:', keyInfo.algorithm);
|
|
116
|
-
* console.log('Hash:', keyInfo.publicKeyHash);
|
|
117
|
-
* ```
|
|
118
|
-
*/
|
|
88
|
+
/** Fetch a public key from HAI's key distribution service. */
|
|
119
89
|
export declare function fetchRemoteKey(agentId: string, version?: string | undefined | null): RemotePublicKeyInfo
|
|
120
|
-
/**
|
|
121
|
-
* Build a verification URL for a signed JACS document.
|
|
122
|
-
*
|
|
123
|
-
* Encodes `document` as URL-safe base64 (no padding) and returns a full URL
|
|
124
|
-
* like `https://hai.ai/jacs/verify?s=...`. Throws if the URL would exceed 2048 chars.
|
|
125
|
-
*/
|
|
90
|
+
/** Build a verification URL for a signed JACS document. */
|
|
126
91
|
export declare function generateVerifyLink(document: string, baseUrl: string): string
|
|
127
92
|
/**
|
|
128
93
|
* JacsAgent is a handle to a JACS agent instance.
|
|
@@ -135,44 +100,100 @@ export declare class JacsAgent {
|
|
|
135
100
|
* Call `load()` to initialize it with a configuration.
|
|
136
101
|
*/
|
|
137
102
|
constructor()
|
|
103
|
+
/** Load an agent from a configuration file (sync, blocks event loop). */
|
|
104
|
+
loadSync(configPath: string): string
|
|
105
|
+
/** Create an ephemeral in-memory agent (sync, blocks event loop). */
|
|
106
|
+
ephemeralSync(algorithm?: string | undefined | null): string
|
|
107
|
+
/** Sign an external agent's document (sync, blocks event loop). */
|
|
108
|
+
signAgentSync(agentString: string, publicKey: Buffer, publicKeyEncType: string): string
|
|
109
|
+
/** Verify a signature on arbitrary string data (sync, blocks event loop). */
|
|
110
|
+
verifyStringSync(data: string, signatureBase64: string, publicKey: Buffer, publicKeyEncType: string): boolean
|
|
111
|
+
/** Sign arbitrary string data (sync, blocks event loop). */
|
|
112
|
+
signStringSync(data: string): string
|
|
113
|
+
/** Verify this agent's signature and hash (sync, blocks event loop). */
|
|
114
|
+
verifyAgentSync(agentfile?: string | undefined | null): boolean
|
|
115
|
+
/** Update the agent document (sync, blocks event loop). */
|
|
116
|
+
updateAgentSync(newAgentString: string): string
|
|
117
|
+
/** Verify a document's signature and hash (sync, blocks event loop). */
|
|
118
|
+
verifyDocumentSync(documentString: string): boolean
|
|
119
|
+
/** Update an existing document (sync, blocks event loop). */
|
|
120
|
+
updateDocumentSync(documentKey: string, newDocumentString: string, attachments?: Array<string> | undefined | null, embed?: boolean | undefined | null): string
|
|
121
|
+
/** Verify a document's signature with optional custom field (sync, blocks event loop). */
|
|
122
|
+
verifySignatureSync(documentString: string, signatureField?: string | undefined | null): boolean
|
|
123
|
+
/** Create an agreement on a document (sync, blocks event loop). */
|
|
124
|
+
createAgreementSync(documentString: string, agentids: Array<string>, question?: string | undefined | null, context?: string | undefined | null, agreementFieldname?: string | undefined | null): string
|
|
125
|
+
/** Create an agreement with extended options (sync, blocks event loop). */
|
|
126
|
+
createAgreementWithOptionsSync(documentString: string, agentids: Array<string>, question?: string | undefined | null, context?: string | undefined | null, agreementFieldname?: string | undefined | null, timeout?: string | undefined | null, quorum?: number | undefined | null, requiredAlgorithms?: Array<string> | undefined | null, minimumStrength?: string | undefined | null): string
|
|
127
|
+
/** Sign an agreement on a document (sync, blocks event loop). */
|
|
128
|
+
signAgreementSync(documentString: string, agreementFieldname?: string | undefined | null): string
|
|
129
|
+
/** Create a new JACS document (sync, blocks event loop). */
|
|
130
|
+
createDocumentSync(documentString: string, customSchema?: string | undefined | null, outputfilename?: string | undefined | null, noSave?: boolean | undefined | null, attachments?: string | undefined | null, embed?: boolean | undefined | null): string
|
|
131
|
+
/** Check an agreement on a document (sync, blocks event loop). */
|
|
132
|
+
checkAgreementSync(documentString: string, agreementFieldname?: string | undefined | null): string
|
|
133
|
+
/** Get setup instructions (sync, blocks event loop). */
|
|
134
|
+
getSetupInstructionsSync(domain: string, ttl?: number | undefined | null): string
|
|
135
|
+
/** Register with HAI.ai (sync, blocks event loop). */
|
|
136
|
+
registerWithHaiSync(apiKey?: string | undefined | null, haiUrl?: string | undefined | null, preview?: boolean | undefined | null): string
|
|
137
|
+
/**
|
|
138
|
+
* Returns diagnostic information as a JSON string.
|
|
139
|
+
* Lightweight — no async variant needed.
|
|
140
|
+
*/
|
|
141
|
+
diagnostics(): string
|
|
142
|
+
/** Verify a document by ID (sync, blocks event loop). */
|
|
143
|
+
verifyDocumentByIdSync(documentId: string): boolean
|
|
144
|
+
/** Re-encrypt the agent's private key (sync, blocks event loop). */
|
|
145
|
+
reencryptKeySync(oldPassword: string, newPassword: string): void
|
|
146
|
+
/**
|
|
147
|
+
* Sign a request payload (wraps in a JACS document).
|
|
148
|
+
* Sync-only: uses V8 thread-local JsObject.
|
|
149
|
+
*/
|
|
150
|
+
signRequest(params: any): string
|
|
151
|
+
/**
|
|
152
|
+
* Verify a response payload.
|
|
153
|
+
* Sync-only: returns V8 thread-local JsObject.
|
|
154
|
+
*/
|
|
155
|
+
verifyResponse(documentString: string): object
|
|
156
|
+
/**
|
|
157
|
+
* Verify a response payload and return the agent ID.
|
|
158
|
+
* Sync-only: returns V8 thread-local JsObject.
|
|
159
|
+
*/
|
|
160
|
+
verifyResponseWithAgentId(documentString: string): object
|
|
138
161
|
/** Load an agent from a configuration file. */
|
|
139
|
-
load(configPath: string): string
|
|
140
|
-
/**
|
|
141
|
-
|
|
162
|
+
load(configPath: string): Promise<string>
|
|
163
|
+
/** Create an ephemeral in-memory agent. */
|
|
164
|
+
ephemeral(algorithm?: string | undefined | null): Promise<string>
|
|
165
|
+
/** Sign an external agent's document. */
|
|
166
|
+
signAgent(agentString: string, publicKey: Buffer, publicKeyEncType: string): Promise<string>
|
|
142
167
|
/** Verify a signature on arbitrary string data. */
|
|
143
|
-
verifyString(data: string, signatureBase64: string, publicKey: Buffer, publicKeyEncType: string): boolean
|
|
168
|
+
verifyString(data: string, signatureBase64: string, publicKey: Buffer, publicKeyEncType: string): Promise<boolean>
|
|
144
169
|
/** Sign arbitrary string data with this agent's private key. */
|
|
145
|
-
signString(data: string): string
|
|
170
|
+
signString(data: string): Promise<string>
|
|
146
171
|
/** Verify this agent's signature and hash. */
|
|
147
|
-
verifyAgent(agentfile?: string | undefined | null): boolean
|
|
172
|
+
verifyAgent(agentfile?: string | undefined | null): Promise<boolean>
|
|
148
173
|
/** Update the agent document with new data. */
|
|
149
|
-
updateAgent(newAgentString: string): string
|
|
174
|
+
updateAgent(newAgentString: string): Promise<string>
|
|
150
175
|
/** Verify a document's signature and hash. */
|
|
151
|
-
verifyDocument(documentString: string): boolean
|
|
176
|
+
verifyDocument(documentString: string): Promise<boolean>
|
|
152
177
|
/** Update an existing document. */
|
|
153
|
-
updateDocument(documentKey: string, newDocumentString: string, attachments?: Array<string> | undefined | null, embed?: boolean | undefined | null): string
|
|
178
|
+
updateDocument(documentKey: string, newDocumentString: string, attachments?: Array<string> | undefined | null, embed?: boolean | undefined | null): Promise<string>
|
|
154
179
|
/** Verify a document's signature with an optional custom signature field. */
|
|
155
|
-
verifySignature(documentString: string, signatureField?: string | undefined | null): boolean
|
|
180
|
+
verifySignature(documentString: string, signatureField?: string | undefined | null): Promise<boolean>
|
|
156
181
|
/** Create an agreement on a document. */
|
|
157
|
-
createAgreement(documentString: string, agentids: Array<string>, question?: string | undefined | null, context?: string | undefined | null, agreementFieldname?: string | undefined | null): string
|
|
182
|
+
createAgreement(documentString: string, agentids: Array<string>, question?: string | undefined | null, context?: string | undefined | null, agreementFieldname?: string | undefined | null): Promise<string>
|
|
183
|
+
/** Create an agreement with extended options. */
|
|
184
|
+
createAgreementWithOptions(documentString: string, agentids: Array<string>, question?: string | undefined | null, context?: string | undefined | null, agreementFieldname?: string | undefined | null, timeout?: string | undefined | null, quorum?: number | undefined | null, requiredAlgorithms?: Array<string> | undefined | null, minimumStrength?: string | undefined | null): Promise<string>
|
|
158
185
|
/** Sign an agreement on a document. */
|
|
159
|
-
signAgreement(documentString: string, agreementFieldname?: string | undefined | null): string
|
|
186
|
+
signAgreement(documentString: string, agreementFieldname?: string | undefined | null): Promise<string>
|
|
160
187
|
/** Create a new JACS document. */
|
|
161
|
-
createDocument(documentString: string, customSchema?: string | undefined | null, outputfilename?: string | undefined | null, noSave?: boolean | undefined | null, attachments?: string | undefined | null, embed?: boolean | undefined | null): string
|
|
188
|
+
createDocument(documentString: string, customSchema?: string | undefined | null, outputfilename?: string | undefined | null, noSave?: boolean | undefined | null, attachments?: string | undefined | null, embed?: boolean | undefined | null): Promise<string>
|
|
162
189
|
/** Check an agreement on a document. */
|
|
163
|
-
checkAgreement(documentString: string, agreementFieldname?: string | undefined | null): string
|
|
164
|
-
/**
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
verifyDocumentById(documentId: string): boolean
|
|
190
|
+
checkAgreement(documentString: string, agreementFieldname?: string | undefined | null): Promise<string>
|
|
191
|
+
/** Get setup instructions for DNS records, DNSSEC, and HAI registration. */
|
|
192
|
+
getSetupInstructions(domain: string, ttl?: number | undefined | null): Promise<string>
|
|
193
|
+
/** Register this agent with HAI.ai. */
|
|
194
|
+
registerWithHai(apiKey?: string | undefined | null, haiUrl?: string | undefined | null, preview?: boolean | undefined | null): Promise<string>
|
|
195
|
+
/** Verify a document looked up by ID from storage. */
|
|
196
|
+
verifyDocumentById(documentId: string): Promise<boolean>
|
|
170
197
|
/** Re-encrypt the agent's private key with a new password. */
|
|
171
|
-
reencryptKey(oldPassword: string, newPassword: string): void
|
|
172
|
-
/** Sign a request payload (wraps in a JACS document). */
|
|
173
|
-
signRequest(params: any): string
|
|
174
|
-
/** Verify a response payload. */
|
|
175
|
-
verifyResponse(documentString: string): object
|
|
176
|
-
/** Verify a response payload and return the agent ID. */
|
|
177
|
-
verifyResponseWithAgentId(documentString: string): object
|
|
198
|
+
reencryptKey(oldPassword: string, newPassword: string): Promise<void>
|
|
178
199
|
}
|
package/index.js
CHANGED
|
@@ -310,34 +310,36 @@ if (!nativeBinding) {
|
|
|
310
310
|
throw new Error(`Failed to load native binding`)
|
|
311
311
|
}
|
|
312
312
|
|
|
313
|
-
const { JacsAgent, hashString, createConfig, createAgent, trustAgent, listTrustedAgents, untrustAgent, isTrusted, getTrustedAgent, audit,
|
|
313
|
+
const { JacsAgent, hashString, createConfig, createAgentSync, createAgent, trustAgent, listTrustedAgents, untrustAgent, isTrusted, getTrustedAgent, auditSync, audit, legacyLoad, legacySignAgent, legacyVerifyString, legacySignString, legacyVerifyAgent, legacyUpdateAgent, verifyDocumentStandalone, legacyVerifyDocument, legacyUpdateDocument, legacyVerifySignature, legacyCreateAgreement, legacySignAgreement, legacyCreateDocument, legacyCheckAgreement, legacySignRequest, legacyVerifyResponse, legacyVerifyResponseWithAgentId, fetchRemoteKey, generateVerifyLink } = nativeBinding
|
|
314
314
|
|
|
315
315
|
module.exports.JacsAgent = JacsAgent
|
|
316
316
|
module.exports.hashString = hashString
|
|
317
317
|
module.exports.createConfig = createConfig
|
|
318
|
+
module.exports.createAgentSync = createAgentSync
|
|
318
319
|
module.exports.createAgent = createAgent
|
|
319
320
|
module.exports.trustAgent = trustAgent
|
|
320
321
|
module.exports.listTrustedAgents = listTrustedAgents
|
|
321
322
|
module.exports.untrustAgent = untrustAgent
|
|
322
323
|
module.exports.isTrusted = isTrusted
|
|
323
324
|
module.exports.getTrustedAgent = getTrustedAgent
|
|
325
|
+
module.exports.auditSync = auditSync
|
|
324
326
|
module.exports.audit = audit
|
|
325
|
-
module.exports.
|
|
326
|
-
module.exports.
|
|
327
|
-
module.exports.
|
|
328
|
-
module.exports.
|
|
329
|
-
module.exports.
|
|
330
|
-
module.exports.
|
|
327
|
+
module.exports.legacyLoad = legacyLoad
|
|
328
|
+
module.exports.legacySignAgent = legacySignAgent
|
|
329
|
+
module.exports.legacyVerifyString = legacyVerifyString
|
|
330
|
+
module.exports.legacySignString = legacySignString
|
|
331
|
+
module.exports.legacyVerifyAgent = legacyVerifyAgent
|
|
332
|
+
module.exports.legacyUpdateAgent = legacyUpdateAgent
|
|
331
333
|
module.exports.verifyDocumentStandalone = verifyDocumentStandalone
|
|
332
|
-
module.exports.
|
|
333
|
-
module.exports.
|
|
334
|
-
module.exports.
|
|
335
|
-
module.exports.
|
|
336
|
-
module.exports.
|
|
337
|
-
module.exports.
|
|
338
|
-
module.exports.
|
|
339
|
-
module.exports.
|
|
340
|
-
module.exports.
|
|
341
|
-
module.exports.
|
|
334
|
+
module.exports.legacyVerifyDocument = legacyVerifyDocument
|
|
335
|
+
module.exports.legacyUpdateDocument = legacyUpdateDocument
|
|
336
|
+
module.exports.legacyVerifySignature = legacyVerifySignature
|
|
337
|
+
module.exports.legacyCreateAgreement = legacyCreateAgreement
|
|
338
|
+
module.exports.legacySignAgreement = legacySignAgreement
|
|
339
|
+
module.exports.legacyCreateDocument = legacyCreateDocument
|
|
340
|
+
module.exports.legacyCheckAgreement = legacyCheckAgreement
|
|
341
|
+
module.exports.legacySignRequest = legacySignRequest
|
|
342
|
+
module.exports.legacyVerifyResponse = legacyVerifyResponse
|
|
343
|
+
module.exports.legacyVerifyResponseWithAgentId = legacyVerifyResponseWithAgentId
|
|
342
344
|
module.exports.fetchRemoteKey = fetchRemoteKey
|
|
343
345
|
module.exports.generateVerifyLink = generateVerifyLink
|
package/jacs.darwin-arm64.node
CHANGED
|
Binary file
|
package/jacs.darwin-x64.node
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/jacs.linux-x64-gnu.node
CHANGED
|
Binary file
|
package/jacs.linux-x64-musl.node
CHANGED
|
Binary file
|
package/koa.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JACS Koa Middleware
|
|
3
|
+
*
|
|
4
|
+
* Factory-based middleware for Koa that verifies incoming JACS-signed
|
|
5
|
+
* request bodies and optionally auto-signs JSON responses.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import Koa from 'koa';
|
|
10
|
+
* import bodyParser from 'koa-bodyparser';
|
|
11
|
+
* import { JacsClient } from './client';
|
|
12
|
+
* import { jacsKoaMiddleware } from './koa';
|
|
13
|
+
*
|
|
14
|
+
* const client = await JacsClient.quickstart();
|
|
15
|
+
* const app = new Koa();
|
|
16
|
+
* app.use(bodyParser({ enableTypes: ['text'] }));
|
|
17
|
+
* app.use(jacsKoaMiddleware({ client, verify: true }));
|
|
18
|
+
*
|
|
19
|
+
* app.use(async (ctx) => {
|
|
20
|
+
* console.log(ctx.state.jacsPayload); // verified payload
|
|
21
|
+
* ctx.body = { status: 'ok' };
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
import type { JacsClient } from './client.js';
|
|
26
|
+
export interface JacsKoaMiddlewareOptions {
|
|
27
|
+
/** Pre-initialized JacsClient instance (preferred). */
|
|
28
|
+
client?: JacsClient;
|
|
29
|
+
/** Path to jacs config file. Used only if `client` is not provided. */
|
|
30
|
+
configPath?: string;
|
|
31
|
+
/** Auto-sign JSON response bodies after next(). Default: false (opt-in). */
|
|
32
|
+
sign?: boolean;
|
|
33
|
+
/** Verify incoming POST/PUT/PATCH bodies as JACS documents. Default: true. */
|
|
34
|
+
verify?: boolean;
|
|
35
|
+
/** Allow unsigned/invalid requests to pass through instead of returning 401. Default: false. */
|
|
36
|
+
optional?: boolean;
|
|
37
|
+
}
|
|
38
|
+
interface KoaContext {
|
|
39
|
+
request: {
|
|
40
|
+
method: string;
|
|
41
|
+
body?: any;
|
|
42
|
+
};
|
|
43
|
+
state: Record<string, any>;
|
|
44
|
+
body: any;
|
|
45
|
+
status: number;
|
|
46
|
+
method: string;
|
|
47
|
+
type: string;
|
|
48
|
+
[key: string]: any;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Create JACS Koa middleware.
|
|
52
|
+
*
|
|
53
|
+
* Attaches `ctx.state.jacsClient` on every request.
|
|
54
|
+
* When `verify` is true (default), POST/PUT/PATCH bodies are verified and
|
|
55
|
+
* extracted payload is set on `ctx.state.jacsPayload`.
|
|
56
|
+
* When `sign` is true, `ctx.body` is auto-signed after downstream middleware runs.
|
|
57
|
+
*/
|
|
58
|
+
export declare function jacsKoaMiddleware(options?: JacsKoaMiddlewareOptions): (ctx: KoaContext, next: () => Promise<void>) => Promise<void>;
|
|
59
|
+
export {};
|