@awebai/claude-channel 0.1.3 → 0.2.1

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.
@@ -1,161 +0,0 @@
1
- import * as ed from "@noble/ed25519";
2
- import { sha512 } from "@noble/hashes/sha2.js";
3
- import { extractPublicKey } from "./did.js";
4
- // @noble/ed25519 v2 requires setting the hash function
5
- ed.etc.sha512Sync = (...m) => sha512(ed.etc.concatBytes(...m));
6
- /**
7
- * Build the canonical JSON payload for message signing.
8
- * Fields are sorted lexicographically, no whitespace, minimal escaping.
9
- * Optional fields (from_stable_id, message_id, to_stable_id) are omitted when empty.
10
- */
11
- export function canonicalJSON(env) {
12
- const fields = [
13
- ["body", env.body],
14
- ["from", env.from],
15
- ["from_did", env.from_did],
16
- ["subject", env.subject],
17
- ["timestamp", env.timestamp],
18
- ["to", env.to],
19
- ["to_did", env.to_did],
20
- ["type", env.type],
21
- ];
22
- if (env.from_stable_id)
23
- fields.push(["from_stable_id", env.from_stable_id]);
24
- if (env.message_id)
25
- fields.push(["message_id", env.message_id]);
26
- if (env.to_stable_id)
27
- fields.push(["to_stable_id", env.to_stable_id]);
28
- fields.sort((a, b) => (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0));
29
- let result = "{";
30
- for (let i = 0; i < fields.length; i++) {
31
- if (i > 0)
32
- result += ",";
33
- result += '"' + fields[i][0] + '":"' + escapeJSON(fields[i][1]) + '"';
34
- }
35
- result += "}";
36
- return result;
37
- }
38
- /** JSON-escape a string value, matching Go's writeEscapedString exactly. */
39
- function escapeJSON(s) {
40
- let result = "";
41
- for (const ch of s) {
42
- const code = ch.codePointAt(0);
43
- switch (ch) {
44
- case '"':
45
- result += '\\"';
46
- break;
47
- case "\\":
48
- result += "\\\\";
49
- break;
50
- case "\n":
51
- result += "\\n";
52
- break;
53
- case "\r":
54
- result += "\\r";
55
- break;
56
- case "\t":
57
- result += "\\t";
58
- break;
59
- case "\b":
60
- result += "\\b";
61
- break;
62
- case "\f":
63
- result += "\\f";
64
- break;
65
- default:
66
- if (code < 0x20) {
67
- result += "\\u" + code.toString(16).padStart(4, "0");
68
- }
69
- else {
70
- result += ch;
71
- }
72
- }
73
- }
74
- return result;
75
- }
76
- function b64Encode(bytes) {
77
- // Build binary string without spread to avoid stack overflow on large inputs
78
- let bin = "";
79
- for (let i = 0; i < bytes.length; i++)
80
- bin += String.fromCharCode(bytes[i]);
81
- // Base64 RFC 4648 no padding (RawStdEncoding)
82
- return btoa(bin).replace(/=+$/, "");
83
- }
84
- function b64Decode(s) {
85
- const bin = atob(s);
86
- const bytes = new Uint8Array(bin.length);
87
- for (let i = 0; i < bin.length; i++)
88
- bytes[i] = bin.charCodeAt(i);
89
- return bytes;
90
- }
91
- /** Sign a message envelope. Returns base64 signature (no padding). */
92
- export async function signMessage(seed, env) {
93
- const payload = canonicalJSON(env);
94
- const sig = ed.sign(new TextEncoder().encode(payload), seed);
95
- return b64Encode(sig);
96
- }
97
- /**
98
- * Verify a message envelope signature.
99
- * Returns 'unverified' if DID or signature is missing.
100
- * Returns 'failed' if signature doesn't verify.
101
- * Returns 'verified' if valid.
102
- */
103
- export async function verifyMessage(env) {
104
- if (!env.from_did || !env.signature) {
105
- return "unverified";
106
- }
107
- if (env.signing_key_id && env.signing_key_id !== env.from_did) {
108
- return "failed";
109
- }
110
- if (!env.from_did.startsWith("did:key:z")) {
111
- return "unverified";
112
- }
113
- let publicKey;
114
- try {
115
- publicKey = extractPublicKey(env.from_did);
116
- }
117
- catch {
118
- return "failed";
119
- }
120
- let sigBytes;
121
- try {
122
- sigBytes = b64Decode(env.signature);
123
- }
124
- catch {
125
- return "failed";
126
- }
127
- const payload = canonicalJSON(env);
128
- const valid = ed.verify(sigBytes, new TextEncoder().encode(payload), publicKey);
129
- return valid ? "verified" : "failed";
130
- }
131
- /**
132
- * Verify a signature against a pre-computed canonical payload string.
133
- * Use when the server returns signed_payload alongside the message.
134
- */
135
- export async function verifySignedPayload(signedPayload, signatureB64, fromDID, signingKeyID) {
136
- if (!fromDID || !signatureB64 || !signedPayload) {
137
- return "unverified";
138
- }
139
- if (signingKeyID && signingKeyID !== fromDID) {
140
- return "failed";
141
- }
142
- if (!fromDID.startsWith("did:key:z")) {
143
- return "unverified";
144
- }
145
- let publicKey;
146
- try {
147
- publicKey = extractPublicKey(fromDID);
148
- }
149
- catch {
150
- return "failed";
151
- }
152
- let sigBytes;
153
- try {
154
- sigBytes = b64Decode(signatureB64);
155
- }
156
- catch {
157
- return "failed";
158
- }
159
- const valid = ed.verify(sigBytes, new TextEncoder().encode(signedPayload), publicKey);
160
- return valid ? "verified" : "failed";
161
- }
package/dist/index.d.ts DELETED
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env node
2
- import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3
- import { APIClient } from "./api/client.js";
4
- import { type AgentEvent } from "./api/events.js";
5
- import { PinStore } from "./identity/pinstore.js";
6
- export declare function dispatchEvent(mcp: Server, client: APIClient, pinStore: PinStore, selfAlias: string, dispatched: Set<string>, event: AgentEvent): Promise<void>;
7
- export declare function isDirectExecution(moduleURL: string): boolean;