colonies-ts 0.1.0 → 0.1.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.
- package/README.md +20 -1
- package/dist/index.d.mts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ColonyOS TypeScript/Javascript Client Library
|
|
2
2
|
|
|
3
3
|
[](https://github.com/colonyos/colonies-ts/actions/workflows/node.yml)
|
|
4
4
|
[](https://codecov.io/gh/colonyos/colonies-ts)
|
|
@@ -285,6 +285,7 @@ new ColoniesClient({
|
|
|
285
285
|
| `submitWorkflowSpec(spec)` | Submit a workflow (DAG) |
|
|
286
286
|
| `getProcessGraph(graphId)` | Get workflow details |
|
|
287
287
|
| `getProcessGraphs(colonyName, count, state?)` | List workflows |
|
|
288
|
+
| `getProcessesForWorkflow(graphId, colonyName, count?)` | Get processes for a workflow |
|
|
288
289
|
| `removeProcessGraph(graphId)` | Remove a workflow |
|
|
289
290
|
| `removeAllProcessGraphs(colonyName, state?)` | Remove all workflows |
|
|
290
291
|
|
|
@@ -312,6 +313,7 @@ new ColoniesClient({
|
|
|
312
313
|
| `removeBlueprint(colonyName, name)` | Remove a blueprint |
|
|
313
314
|
| `updateBlueprintStatus(colonyName, name, status)` | Update blueprint status |
|
|
314
315
|
| `reconcileBlueprint(colonyName, name, force?)` | Trigger reconciliation |
|
|
316
|
+
| `getBlueprintHistory(blueprintId, limit?)` | Get blueprint change history |
|
|
315
317
|
|
|
316
318
|
#### Crons & Generators
|
|
317
319
|
|
|
@@ -321,10 +323,27 @@ new ColoniesClient({
|
|
|
321
323
|
| `getCron(cronId)` | Get a cron job |
|
|
322
324
|
| `addCron(cronSpec)` | Add a cron job |
|
|
323
325
|
| `removeCron(cronId)` | Remove a cron job |
|
|
326
|
+
| `runCron(cronId)` | Run a cron job immediately |
|
|
324
327
|
| `getGenerators(colonyName)` | List generators |
|
|
325
328
|
| `getGenerator(generatorId)` | Get a generator |
|
|
326
329
|
| `addGenerator(generatorSpec)` | Add a generator |
|
|
327
330
|
|
|
331
|
+
#### Files
|
|
332
|
+
|
|
333
|
+
| Method | Description |
|
|
334
|
+
|--------|-------------|
|
|
335
|
+
| `getFileLabels(colonyName, name?, exact?)` | List file labels |
|
|
336
|
+
| `getFiles(colonyName, label)` | Get files for a label |
|
|
337
|
+
| `getFile(colonyName, options)` | Get a specific file by ID or name+label |
|
|
338
|
+
|
|
339
|
+
#### Users
|
|
340
|
+
|
|
341
|
+
| Method | Description |
|
|
342
|
+
|--------|-------------|
|
|
343
|
+
| `getUsers(colonyName)` | List users in a colony |
|
|
344
|
+
| `addUser(user)` | Add a user |
|
|
345
|
+
| `removeUser(colonyName, name)` | Remove a user |
|
|
346
|
+
|
|
328
347
|
### ProcessState
|
|
329
348
|
|
|
330
349
|
```typescript
|
package/dist/index.d.mts
CHANGED
|
@@ -130,6 +130,7 @@ declare class ColoniesClient {
|
|
|
130
130
|
getProcessGraph(processGraphId: string): Promise<any>;
|
|
131
131
|
getProcessGraphs(colonyName: string, count: number, state?: ProcessState): Promise<any>;
|
|
132
132
|
removeProcessGraph(processGraphId: string): Promise<any>;
|
|
133
|
+
getProcessesForWorkflow(processGraphId: string, colonyName: string, count?: number): Promise<any>;
|
|
133
134
|
removeAllProcessGraphs(colonyName: string, state?: ProcessState): Promise<any>;
|
|
134
135
|
addLog(processId: string, message: string, executorPrvKey: string): Promise<any>;
|
|
135
136
|
getLogs(colonyName: string, processId: string, executorName: string, count?: number, since?: number): Promise<any>;
|
|
@@ -138,6 +139,7 @@ declare class ColoniesClient {
|
|
|
138
139
|
getCron(cronId: string): Promise<any>;
|
|
139
140
|
addCron(cronSpec: any): Promise<any>;
|
|
140
141
|
removeCron(cronId: string): Promise<any>;
|
|
142
|
+
runCron(cronId: string): Promise<any>;
|
|
141
143
|
getGenerators(colonyName: string, count?: number): Promise<any>;
|
|
142
144
|
getGenerator(generatorId: string): Promise<any>;
|
|
143
145
|
addGenerator(generatorSpec: any): Promise<any>;
|
|
@@ -152,6 +154,13 @@ declare class ColoniesClient {
|
|
|
152
154
|
removeUser(colonyName: string, name: string): Promise<any>;
|
|
153
155
|
getFileLabels(colonyName: string, name?: string, exact?: boolean): Promise<any>;
|
|
154
156
|
getFiles(colonyName: string, label: string): Promise<any>;
|
|
157
|
+
getFile(colonyName: string, options: {
|
|
158
|
+
fileId: string;
|
|
159
|
+
} | {
|
|
160
|
+
name: string;
|
|
161
|
+
label: string;
|
|
162
|
+
latest?: boolean;
|
|
163
|
+
}): Promise<any>;
|
|
155
164
|
addAttribute(attribute: {
|
|
156
165
|
targetid: string;
|
|
157
166
|
targetcolonyname: string;
|
|
@@ -256,6 +265,12 @@ declare class ColoniesClient {
|
|
|
256
265
|
* @param force - Force reconciliation even if no changes detected
|
|
257
266
|
*/
|
|
258
267
|
reconcileBlueprint(colonyName: string, name: string, force?: boolean): Promise<any>;
|
|
268
|
+
/**
|
|
269
|
+
* Get the history of changes for a specific blueprint
|
|
270
|
+
* @param blueprintId - ID of the blueprint
|
|
271
|
+
* @param limit - Optional limit on number of history entries to retrieve
|
|
272
|
+
*/
|
|
273
|
+
getBlueprintHistory(blueprintId: string, limit?: number): Promise<any>;
|
|
259
274
|
/**
|
|
260
275
|
* Subscribe to process state changes using WebSocket
|
|
261
276
|
* Use this to wait for a process to be assigned (RUNNING state) before subscribing to channels
|
package/dist/index.d.ts
CHANGED
|
@@ -130,6 +130,7 @@ declare class ColoniesClient {
|
|
|
130
130
|
getProcessGraph(processGraphId: string): Promise<any>;
|
|
131
131
|
getProcessGraphs(colonyName: string, count: number, state?: ProcessState): Promise<any>;
|
|
132
132
|
removeProcessGraph(processGraphId: string): Promise<any>;
|
|
133
|
+
getProcessesForWorkflow(processGraphId: string, colonyName: string, count?: number): Promise<any>;
|
|
133
134
|
removeAllProcessGraphs(colonyName: string, state?: ProcessState): Promise<any>;
|
|
134
135
|
addLog(processId: string, message: string, executorPrvKey: string): Promise<any>;
|
|
135
136
|
getLogs(colonyName: string, processId: string, executorName: string, count?: number, since?: number): Promise<any>;
|
|
@@ -138,6 +139,7 @@ declare class ColoniesClient {
|
|
|
138
139
|
getCron(cronId: string): Promise<any>;
|
|
139
140
|
addCron(cronSpec: any): Promise<any>;
|
|
140
141
|
removeCron(cronId: string): Promise<any>;
|
|
142
|
+
runCron(cronId: string): Promise<any>;
|
|
141
143
|
getGenerators(colonyName: string, count?: number): Promise<any>;
|
|
142
144
|
getGenerator(generatorId: string): Promise<any>;
|
|
143
145
|
addGenerator(generatorSpec: any): Promise<any>;
|
|
@@ -152,6 +154,13 @@ declare class ColoniesClient {
|
|
|
152
154
|
removeUser(colonyName: string, name: string): Promise<any>;
|
|
153
155
|
getFileLabels(colonyName: string, name?: string, exact?: boolean): Promise<any>;
|
|
154
156
|
getFiles(colonyName: string, label: string): Promise<any>;
|
|
157
|
+
getFile(colonyName: string, options: {
|
|
158
|
+
fileId: string;
|
|
159
|
+
} | {
|
|
160
|
+
name: string;
|
|
161
|
+
label: string;
|
|
162
|
+
latest?: boolean;
|
|
163
|
+
}): Promise<any>;
|
|
155
164
|
addAttribute(attribute: {
|
|
156
165
|
targetid: string;
|
|
157
166
|
targetcolonyname: string;
|
|
@@ -256,6 +265,12 @@ declare class ColoniesClient {
|
|
|
256
265
|
* @param force - Force reconciliation even if no changes detected
|
|
257
266
|
*/
|
|
258
267
|
reconcileBlueprint(colonyName: string, name: string, force?: boolean): Promise<any>;
|
|
268
|
+
/**
|
|
269
|
+
* Get the history of changes for a specific blueprint
|
|
270
|
+
* @param blueprintId - ID of the blueprint
|
|
271
|
+
* @param limit - Optional limit on number of history entries to retrieve
|
|
272
|
+
*/
|
|
273
|
+
getBlueprintHistory(blueprintId: string, limit?: number): Promise<any>;
|
|
259
274
|
/**
|
|
260
275
|
* Subscribe to process state changes using WebSocket
|
|
261
276
|
* Use this to wait for a process to be assigned (RUNNING state) before subscribing to channels
|
package/dist/index.js
CHANGED
|
@@ -474,6 +474,16 @@ var ColoniesClient = class {
|
|
|
474
474
|
};
|
|
475
475
|
return this.sendRPC(this.createRPCMsg(msg));
|
|
476
476
|
}
|
|
477
|
+
async getProcessesForWorkflow(processGraphId, colonyName, count = 100) {
|
|
478
|
+
const msg = {
|
|
479
|
+
msgtype: "getprocessesmsg",
|
|
480
|
+
processgraphid: processGraphId,
|
|
481
|
+
colonyname: colonyName,
|
|
482
|
+
count,
|
|
483
|
+
state: -1
|
|
484
|
+
};
|
|
485
|
+
return this.sendRPC(this.createRPCMsg(msg));
|
|
486
|
+
}
|
|
477
487
|
async removeAllProcessGraphs(colonyName, state) {
|
|
478
488
|
const msg = {
|
|
479
489
|
msgtype: "removeallprocessgraphsmsg",
|
|
@@ -551,6 +561,13 @@ var ColoniesClient = class {
|
|
|
551
561
|
};
|
|
552
562
|
return this.sendRPC(this.createRPCMsg(msg));
|
|
553
563
|
}
|
|
564
|
+
async runCron(cronId) {
|
|
565
|
+
const msg = {
|
|
566
|
+
msgtype: "runcronmsg",
|
|
567
|
+
cronid: cronId
|
|
568
|
+
};
|
|
569
|
+
return this.sendRPC(this.createRPCMsg(msg));
|
|
570
|
+
}
|
|
554
571
|
// ==================== Generator Methods ====================
|
|
555
572
|
async getGenerators(colonyName, count = 100) {
|
|
556
573
|
const msg = {
|
|
@@ -615,6 +632,22 @@ var ColoniesClient = class {
|
|
|
615
632
|
};
|
|
616
633
|
return this.sendRPC(this.createRPCMsg(msg));
|
|
617
634
|
}
|
|
635
|
+
async getFile(colonyName, options) {
|
|
636
|
+
const msg = {
|
|
637
|
+
msgtype: "getfilemsg",
|
|
638
|
+
colonyname: colonyName
|
|
639
|
+
};
|
|
640
|
+
if ("fileId" in options) {
|
|
641
|
+
msg.fileid = options.fileId;
|
|
642
|
+
} else {
|
|
643
|
+
msg.name = options.name;
|
|
644
|
+
msg.label = options.label;
|
|
645
|
+
if (options.latest !== void 0) {
|
|
646
|
+
msg.latest = options.latest;
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
return this.sendRPC(this.createRPCMsg(msg));
|
|
650
|
+
}
|
|
618
651
|
// ==================== Attribute Methods ====================
|
|
619
652
|
async addAttribute(attribute) {
|
|
620
653
|
const msg = {
|
|
@@ -910,6 +943,21 @@ var ColoniesClient = class {
|
|
|
910
943
|
};
|
|
911
944
|
return this.sendRPC(this.createRPCMsg(msg));
|
|
912
945
|
}
|
|
946
|
+
/**
|
|
947
|
+
* Get the history of changes for a specific blueprint
|
|
948
|
+
* @param blueprintId - ID of the blueprint
|
|
949
|
+
* @param limit - Optional limit on number of history entries to retrieve
|
|
950
|
+
*/
|
|
951
|
+
async getBlueprintHistory(blueprintId, limit) {
|
|
952
|
+
const msg = {
|
|
953
|
+
msgtype: "getblueprinthistorymsg",
|
|
954
|
+
blueprintid: blueprintId
|
|
955
|
+
};
|
|
956
|
+
if (limit !== void 0) {
|
|
957
|
+
msg.limit = limit;
|
|
958
|
+
}
|
|
959
|
+
return this.sendRPC(this.createRPCMsg(msg));
|
|
960
|
+
}
|
|
913
961
|
/**
|
|
914
962
|
* Subscribe to process state changes using WebSocket
|
|
915
963
|
* Use this to wait for a process to be assigned (RUNNING state) before subscribing to channels
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/crypto.ts","../src/client.ts"],"sourcesContent":["export { Crypto, generatePrivateKey, deriveId, sign } from './crypto';\nexport { ColoniesClient, ProcessState } from './client';\nexport type { ColoniesClientConfig, FunctionSpec, RPCMessage } from './client';\n","/**\n * ColonyOS Crypto implementation\n * Ported from pycolonies/crypto.py\n * Based on eth-utils and eth-keys (MIT-licensed)\n */\n\nimport { sha3_256 } from '@noble/hashes/sha3';\nimport { sha256 } from '@noble/hashes/sha256';\nimport { hmac } from '@noble/hashes/hmac';\nimport { bytesToHex, hexToBytes, randomBytes } from '@noble/hashes/utils';\n\n// ============== secp256k1 Curve Parameters ==============\n\nconst A = 0n;\nconst N = 115792089237316195423570985008687907852837564279074904382605163141518161494337n;\nconst Gx = 55066263022277343669578718895168534326250603453777594175500187360389116729240n;\nconst Gy = 32670510020758816978083085130507043184471273380659243275938904335757337482424n;\nconst G: [bigint, bigint] = [Gx, Gy];\nconst P = 2n ** 256n - 2n ** 32n - 977n;\n\ntype Point = [bigint, bigint];\ntype JacobianPoint = [bigint, bigint, bigint];\n\n// ============== Utility Functions ==============\n\nfunction pad32(value: Uint8Array): Uint8Array {\n if (value.length >= 32) return value.slice(0, 32);\n const padded = new Uint8Array(32);\n padded.set(value, 32 - value.length);\n return padded;\n}\n\nfunction intToBigEndian(value: bigint): Uint8Array {\n if (value === 0n) return new Uint8Array([0]);\n const hex = value.toString(16);\n const paddedHex = hex.length % 2 ? '0' + hex : hex;\n return hexToBytes(paddedHex);\n}\n\nfunction bigEndianToInt(value: Uint8Array): bigint {\n if (value.length === 0) return 0n;\n return BigInt('0x' + bytesToHex(value));\n}\n\n// ============== Elliptic Curve Math ==============\n\nfunction inv(a: bigint, n: bigint): bigint {\n if (a === 0n) return 0n;\n let lm = 1n, hm = 0n;\n let low = ((a % n) + n) % n, high = n;\n while (low > 1n) {\n const r = high / low;\n const nm = hm - lm * r;\n const newVal = high - low * r;\n hm = lm;\n high = low;\n lm = nm;\n low = newVal;\n }\n return ((lm % n) + n) % n;\n}\n\nfunction toJacobian(p: Point): JacobianPoint {\n return [p[0], p[1], 1n];\n}\n\nfunction fromJacobian(p: JacobianPoint): Point {\n const z = inv(p[2], P);\n const z2 = (z * z) % P;\n const z3 = (z2 * z) % P;\n return [((p[0] * z2) % P + P) % P, ((p[1] * z3) % P + P) % P];\n}\n\nfunction jacobianDouble(p: JacobianPoint): JacobianPoint {\n if (p[1] === 0n) return [0n, 0n, 0n];\n const ysq = (p[1] ** 2n) % P;\n const S = (4n * p[0] * ysq) % P;\n const M = (3n * p[0] ** 2n + A * p[2] ** 4n) % P;\n const nx = ((M ** 2n - 2n * S) % P + P) % P;\n const ny = ((M * (S - nx) - 8n * ysq ** 2n) % P + P) % P;\n const nz = (2n * p[1] * p[2]) % P;\n return [nx, ny, nz];\n}\n\nfunction jacobianAdd(p: JacobianPoint, q: JacobianPoint): JacobianPoint {\n if (p[1] === 0n) return q;\n if (q[1] === 0n) return p;\n\n const U1 = (p[0] * q[2] ** 2n) % P;\n const U2 = (q[0] * p[2] ** 2n) % P;\n const S1 = (p[1] * q[2] ** 3n) % P;\n const S2 = (q[1] * p[2] ** 3n) % P;\n\n if (U1 === U2) {\n if (S1 !== S2) return [0n, 0n, 1n];\n return jacobianDouble(p);\n }\n\n const H = ((U2 - U1) % P + P) % P;\n const R = ((S2 - S1) % P + P) % P;\n const H2 = (H * H) % P;\n const H3 = (H * H2) % P;\n const U1H2 = (U1 * H2) % P;\n const nx = ((R ** 2n - H3 - 2n * U1H2) % P + P) % P;\n const ny = ((R * (U1H2 - nx) - S1 * H3) % P + P) % P;\n const nz = (H * p[2] * q[2]) % P;\n\n return [nx, ny, nz];\n}\n\nfunction jacobianMultiply(a: JacobianPoint, n: bigint): JacobianPoint {\n if (a[1] === 0n || n === 0n) return [0n, 0n, 1n];\n if (n === 1n) return a;\n if (n < 0n || n >= N) return jacobianMultiply(a, ((n % N) + N) % N);\n if (n % 2n === 0n) {\n return jacobianDouble(jacobianMultiply(a, n / 2n));\n } else {\n return jacobianAdd(jacobianDouble(jacobianMultiply(a, n / 2n)), a);\n }\n}\n\nfunction fastMultiply(a: Point, n: bigint): Point {\n return fromJacobian(jacobianMultiply(toJacobian(a), n));\n}\n\nfunction encodeRawPublicKey(rawPublicKey: Point): Uint8Array {\n const left = pad32(intToBigEndian(rawPublicKey[0]));\n const right = pad32(intToBigEndian(rawPublicKey[1]));\n const result = new Uint8Array(64);\n result.set(left, 0);\n result.set(right, 32);\n return result;\n}\n\nfunction privateKeyToPublicKey(privateKeyBytes: Uint8Array): Uint8Array {\n const privateKeyAsNum = bigEndianToInt(privateKeyBytes);\n if (privateKeyAsNum >= N) {\n throw new Error('Invalid private key');\n }\n const rawPublicKey = fastMultiply(G, privateKeyAsNum);\n return encodeRawPublicKey(rawPublicKey);\n}\n\n// ============== ECDSA Signing ==============\n\nfunction deterministicGenerateK(msgHash: Uint8Array, privateKeyBytes: Uint8Array): bigint {\n const v0 = new Uint8Array(32).fill(0x01);\n const k0 = new Uint8Array(32).fill(0x00);\n\n // k1 = HMAC(k0, v0 || 0x00 || priv || hash)\n const data1 = new Uint8Array(v0.length + 1 + privateKeyBytes.length + msgHash.length);\n data1.set(v0, 0);\n data1[v0.length] = 0x00;\n data1.set(privateKeyBytes, v0.length + 1);\n data1.set(msgHash, v0.length + 1 + privateKeyBytes.length);\n const k1 = hmac(sha256, k0, data1);\n\n // v1 = HMAC(k1, v0)\n const v1 = hmac(sha256, k1, v0);\n\n // k2 = HMAC(k1, v1 || 0x01 || priv || hash)\n const data2 = new Uint8Array(v1.length + 1 + privateKeyBytes.length + msgHash.length);\n data2.set(v1, 0);\n data2[v1.length] = 0x01;\n data2.set(privateKeyBytes, v1.length + 1);\n data2.set(msgHash, v1.length + 1 + privateKeyBytes.length);\n const k2 = hmac(sha256, k1, data2);\n\n // v2 = HMAC(k2, v1)\n const v2 = hmac(sha256, k2, v1);\n\n // kb = HMAC(k2, v2)\n const kb = hmac(sha256, k2, v2);\n return bigEndianToInt(kb);\n}\n\nfunction ecdsaRawSign(msgHash: Uint8Array, privateKeyBytes: Uint8Array): [number, bigint, bigint] {\n const z = bigEndianToInt(msgHash);\n const k = deterministicGenerateK(msgHash, privateKeyBytes);\n\n const [r, y] = fastMultiply(G, k);\n const privKeyNum = bigEndianToInt(privateKeyBytes);\n const sRaw = (inv(k, N) * (z + r * privKeyNum)) % N;\n\n const v = 27 + Number((y % 2n) ^ (sRaw * 2n < N ? 0n : 1n));\n const s = sRaw * 2n < N ? sRaw : N - sRaw;\n\n return [v - 27, r, s];\n}\n\n// ============== Exported Functions ==============\n\n/**\n * Generate a new random private key\n * @returns Hex-encoded private key (64 characters)\n */\nexport function generatePrivateKey(): string {\n const randomData = randomBytes(32);\n const hash = sha3_256(randomData);\n return bytesToHex(hash);\n}\n\n/**\n * Derive the public ID from a private key\n * Uses SHA3-256 hash of \"04\" + hex(publicKey)\n * @param privateKey - Hex-encoded private key\n * @returns Hex-encoded ID (64 characters)\n */\nexport function deriveId(privateKey: string): string {\n const privateKeyBytes = hexToBytes(privateKey);\n const publicKey = privateKeyToPublicKey(privateKeyBytes);\n const publicKeyHex = '04' + bytesToHex(publicKey);\n\n // Hash the string representation, not the bytes\n const encoder = new TextEncoder();\n const hash = sha3_256(encoder.encode(publicKeyHex));\n\n return bytesToHex(hash);\n}\n\n/**\n * Sign a message with a private key\n * @param message - Message to sign\n * @param privateKey - Hex-encoded private key\n * @returns Hex-encoded signature (130 characters: r + s + v)\n */\nexport function sign(message: string, privateKey: string): string {\n const privateKeyBytes = hexToBytes(privateKey);\n\n // Hash message with SHA3-256\n const encoder = new TextEncoder();\n const msgHash = sha3_256(encoder.encode(message));\n\n const [v, r, s] = ecdsaRawSign(msgHash, privateKeyBytes);\n\n // Format: r (32 bytes) + s (32 bytes) + v (1 byte)\n const vBytes = new Uint8Array([v]);\n const rBytes = pad32(intToBigEndian(r));\n const sBytes = pad32(intToBigEndian(s));\n\n const signature = new Uint8Array(65);\n signature.set(rBytes, 0);\n signature.set(sBytes, 32);\n signature.set(vBytes, 64);\n\n return bytesToHex(signature);\n}\n\n/**\n * Crypto utility class for convenience\n */\nexport class Crypto {\n generatePrivateKey(): string {\n return generatePrivateKey();\n }\n\n id(privateKey: string): string {\n return deriveId(privateKey);\n }\n\n sign(message: string, privateKey: string): string {\n return sign(message, privateKey);\n }\n}\n\n// Export internal functions for testing\nexport const _internal = {\n jacobianAdd,\n jacobianDouble,\n fastMultiply,\n pad32,\n intToBigEndian,\n bigEndianToInt,\n};\n","/**\n * ColonyOS Client\n * Ported from colonyspace/aila/src/lib/api/colony.ts\n */\n\nimport { Crypto } from './crypto';\n\n// Helper function to decode base64 payload with proper UTF-8 handling\nfunction decodeBase64Utf8(base64: string): string {\n const binaryStr = atob(base64);\n const bytes = new Uint8Array(binaryStr.length);\n for (let i = 0; i < binaryStr.length; i++) {\n bytes[i] = binaryStr.charCodeAt(i);\n }\n return new TextDecoder('utf-8').decode(bytes);\n}\n\n// Helper function to encode string to base64 with proper UTF-8 handling\nfunction encodeBase64Utf8(str: string): string {\n const utf8Bytes = new TextEncoder().encode(str);\n const binaryStr = String.fromCharCode(...utf8Bytes);\n return btoa(binaryStr);\n}\n\nexport interface ColoniesClientConfig {\n host: string;\n port: number;\n tls?: boolean;\n}\n\nexport interface RPCMessage {\n payloadtype: string;\n payload: string;\n signature: string;\n}\n\nexport interface FunctionSpec {\n nodename?: string;\n funcname: string;\n args?: any[];\n kwargs?: Record<string, any>;\n priority?: number;\n maxwaittime?: number;\n maxexectime?: number;\n maxretries?: number;\n conditions?: {\n colonyname?: string;\n executornames?: string[];\n executortype?: string;\n dependencies?: string[];\n nodes?: number;\n cpu?: string;\n processes?: number;\n processespernode?: number;\n mem?: string;\n storage?: string;\n gpu?: { name?: string; mem?: string; count?: number; nodecount?: number };\n walltime?: number;\n };\n label?: string;\n fs?: any;\n env?: Record<string, string>;\n channels?: string[];\n}\n\nexport enum ProcessState {\n WAITING = 0,\n RUNNING = 1,\n SUCCESS = 2,\n FAILED = 3,\n}\n\nexport class ColoniesClient {\n private host: string;\n private port: number;\n private tls: boolean;\n private crypto: Crypto;\n private privateKey: string | null = null;\n\n constructor(config: ColoniesClientConfig) {\n this.host = config.host;\n this.port = config.port;\n this.tls = config.tls ?? false;\n this.crypto = new Crypto();\n }\n\n setPrivateKey(privateKey: string): void {\n this.privateKey = privateKey;\n }\n\n private getBaseUrl(): string {\n const protocol = this.tls ? 'https' : 'http';\n return `${protocol}://${this.host}:${this.port}/api`;\n }\n\n private createRPCMsg(msg: any): RPCMessage {\n if (!this.privateKey) {\n throw new Error('Private key not set. Call setPrivateKey() first.');\n }\n\n const payload = encodeBase64Utf8(JSON.stringify(msg));\n const signature = this.crypto.sign(payload, this.privateKey);\n\n return {\n payloadtype: msg.msgtype,\n payload,\n signature,\n };\n }\n\n private async sendRPC(rpcMessage: RPCMessage): Promise<any> {\n const url = this.getBaseUrl();\n\n const response = await fetch(url, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(rpcMessage),\n });\n\n if (!response.ok) {\n const errorText = await response.text();\n let errorObj;\n try {\n errorObj = JSON.parse(errorText);\n } catch {\n throw new Error(`Request failed with status ${response.status}: ${response.statusText}`);\n }\n\n if (errorObj.payload) {\n try {\n const decodedPayload = decodeBase64Utf8(errorObj.payload);\n const decodedError = JSON.parse(decodedPayload);\n throw new Error(decodedError.message || JSON.stringify(decodedError));\n } catch (e) {\n if (e instanceof Error && e.message !== 'Request failed') {\n throw e;\n }\n }\n }\n throw new Error(JSON.stringify(errorObj));\n }\n\n const responseText = await response.text();\n if (!responseText || responseText.trim() === '') {\n throw new Error('Server returned empty response');\n }\n\n const rpcReplyMsg = JSON.parse(responseText);\n const msg = JSON.parse(decodeBase64Utf8(rpcReplyMsg.payload));\n\n if (rpcReplyMsg.error === true) {\n const errorMessage = typeof msg === 'object' && msg.message ? msg.message : JSON.stringify(msg);\n throw new Error(errorMessage);\n }\n\n return msg;\n }\n\n // ==================== Colony Methods ====================\n\n async getColonies(): Promise<any> {\n const msg = { msgtype: 'getcoloniesmsg' };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getStatistics(): Promise<any> {\n const msg = { msgtype: 'getstatisticsmsg' };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Add a new colony (requires server private key)\n * @param colony - Colony object with colonyid and name\n */\n async addColony(colony: { colonyid: string; name: string }): Promise<any> {\n const msg = {\n msgtype: 'addcolonymsg',\n colony,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Remove a colony (requires server private key)\n * @param colonyName - Name of the colony to remove\n */\n async removeColony(colonyName: string): Promise<any> {\n const msg = {\n msgtype: 'removecolonymsg',\n colonyname: colonyName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Executor Methods ====================\n\n async getExecutors(colonyName: string): Promise<any> {\n const msg = {\n msgtype: 'getexecutorsmsg',\n colonyname: colonyName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getExecutor(colonyName: string, executorName: string): Promise<any> {\n const msg = {\n msgtype: 'getexecutormsg',\n colonyname: colonyName,\n executorname: executorName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async addExecutor(executor: {\n executorid: string;\n executortype: string;\n executorname: string;\n colonyname: string;\n }): Promise<any> {\n const msg = {\n msgtype: 'addexecutormsg',\n executor,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async approveExecutor(colonyName: string, executorName: string): Promise<any> {\n const msg = {\n msgtype: 'approveexecutormsg',\n colonyname: colonyName,\n executorname: executorName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async removeExecutor(colonyName: string, executorName: string): Promise<any> {\n const msg = {\n msgtype: 'removeexecutormsg',\n colonyname: colonyName,\n executorname: executorName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Process Methods ====================\n\n async submitFunctionSpec(spec: FunctionSpec): Promise<any> {\n const msg = {\n msgtype: 'submitfuncspecmsg',\n spec,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getProcess(processId: string): Promise<any> {\n const msg = {\n msgtype: 'getprocessmsg',\n processid: processId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getProcesses(colonyName: string, count: number, state: ProcessState): Promise<any> {\n const msg = {\n msgtype: 'getprocessesmsg',\n colonyname: colonyName,\n count,\n state,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async removeProcess(processId: string): Promise<any> {\n const msg = {\n msgtype: 'removeprocessmsg',\n processid: processId,\n all: false,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async removeAllProcesses(colonyName: string, state: number = -1): Promise<any> {\n const msg = {\n msgtype: 'removeallprocessesmsg',\n colonyname: colonyName,\n state,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async assign(colonyName: string, timeout: number, executorPrvKey: string): Promise<any> {\n // Temporarily set the executor private key for this operation\n const originalKey = this.privateKey;\n this.setPrivateKey(executorPrvKey);\n\n try {\n const msg = {\n msgtype: 'assignprocessmsg',\n colonyname: colonyName,\n timeout,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n } finally {\n if (originalKey) {\n this.setPrivateKey(originalKey);\n }\n }\n }\n\n async closeProcess(processId: string, output: string[]): Promise<any> {\n const msg = {\n msgtype: 'closesuccessfulmsg',\n processid: processId,\n out: output,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async failProcess(processId: string, errors: string[]): Promise<any> {\n const msg = {\n msgtype: 'closefailedmsg',\n processid: processId,\n errors,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Workflow Methods ====================\n\n async submitWorkflowSpec(workflowSpec: {\n colonyname: string;\n functionspecs: FunctionSpec[];\n }): Promise<any> {\n const msg = {\n msgtype: 'submitworkflowspecmsg',\n spec: workflowSpec,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getProcessGraph(processGraphId: string): Promise<any> {\n const msg = {\n msgtype: 'getprocessgraphmsg',\n processgraphid: processGraphId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getProcessGraphs(colonyName: string, count: number, state?: ProcessState): Promise<any> {\n const msg: any = {\n msgtype: 'getprocessgraphsmsg',\n colonyname: colonyName,\n count,\n };\n if (state !== undefined) {\n msg.state = state;\n }\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async removeProcessGraph(processGraphId: string): Promise<any> {\n const msg = {\n msgtype: 'removeprocessgraphmsg',\n processgraphid: processGraphId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async removeAllProcessGraphs(colonyName: string, state?: ProcessState): Promise<any> {\n const msg: any = {\n msgtype: 'removeallprocessgraphsmsg',\n colonyname: colonyName,\n };\n if (state !== undefined) {\n msg.state = state;\n }\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Log Methods ====================\n\n async addLog(processId: string, message: string, executorPrvKey: string): Promise<any> {\n const originalKey = this.privateKey;\n this.setPrivateKey(executorPrvKey);\n\n try {\n const msg = {\n msgtype: 'addlogmsg',\n processid: processId,\n message,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n } finally {\n if (originalKey) {\n this.setPrivateKey(originalKey);\n }\n }\n }\n\n async getLogs(colonyName: string, processId: string, executorName: string, count: number = 100, since: number = 0): Promise<any> {\n const msg = {\n msgtype: 'getlogsmsg',\n colonyname: colonyName,\n processid: processId,\n executorname: executorName,\n count,\n since,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Function Methods ====================\n\n async getFunctions(executorName: string, colonyName: string): Promise<any> {\n const msg = {\n msgtype: 'getfunctionsmsg',\n executorname: executorName,\n colonyname: colonyName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Cron Methods ====================\n\n async getCrons(colonyName: string, count: number = 100): Promise<any> {\n const msg = {\n msgtype: 'getcronsmsg',\n colonyname: colonyName,\n count,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getCron(cronId: string): Promise<any> {\n const msg = {\n msgtype: 'getcronmsg',\n cronid: cronId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async addCron(cronSpec: any): Promise<any> {\n const msg = {\n msgtype: 'addcronmsg',\n cron: cronSpec,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async removeCron(cronId: string): Promise<any> {\n const msg = {\n msgtype: 'removecronmsg',\n cronid: cronId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Generator Methods ====================\n\n async getGenerators(colonyName: string, count: number = 100): Promise<any> {\n const msg = {\n msgtype: 'getgeneratorsmsg',\n colonyname: colonyName,\n count,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getGenerator(generatorId: string): Promise<any> {\n const msg = {\n msgtype: 'getgeneratormsg',\n generatorid: generatorId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async addGenerator(generatorSpec: any): Promise<any> {\n const msg = {\n msgtype: 'addgeneratormsg',\n generator: generatorSpec,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== User Methods ====================\n\n async getUsers(colonyName: string): Promise<any> {\n const msg = {\n msgtype: 'getusersmsg',\n colonyname: colonyName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async addUser(user: {\n colonyname: string;\n userid: string;\n name: string;\n email: string;\n phone: string;\n }): Promise<any> {\n const msg = {\n msgtype: 'addusermsg',\n user,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async removeUser(colonyName: string, name: string): Promise<any> {\n const msg = {\n msgtype: 'removeusermsg',\n colonyname: colonyName,\n name,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== File Methods ====================\n\n async getFileLabels(colonyName: string, name: string = '', exact: boolean = false): Promise<any> {\n const msg = {\n msgtype: 'getfilelabelsmsg',\n colonyname: colonyName,\n name,\n exact,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getFiles(colonyName: string, label: string): Promise<any> {\n const msg = {\n msgtype: 'getfilesmsg',\n colonyname: colonyName,\n label,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Attribute Methods ====================\n\n async addAttribute(attribute: {\n targetid: string;\n targetcolonyname: string;\n targetprocessgraphid: string;\n attributetype: number;\n key: string;\n value: string;\n }): Promise<any> {\n const msg = {\n msgtype: 'addattributemsg',\n attribute,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getAttribute(attributeId: string): Promise<any> {\n const msg = {\n msgtype: 'getattributemsg',\n attributeid: attributeId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Channel Methods ====================\n\n /**\n * Append a message to a process channel\n * @param processId - ID of the process\n * @param channelName - Name of the channel\n * @param sequence - Client-assigned sequence number\n * @param inReplyTo - Sequence number this message is replying to (0 if not a reply)\n * @param payload - Message content (string or Uint8Array)\n */\n async channelAppend(\n processId: string,\n channelName: string,\n sequence: number,\n inReplyTo: number,\n payload: string | Uint8Array\n ): Promise<any> {\n let payloadBytes: number[];\n if (typeof payload === 'string') {\n const encoder = new TextEncoder();\n payloadBytes = Array.from(encoder.encode(payload));\n } else {\n payloadBytes = Array.from(payload);\n }\n\n const msg = {\n msgtype: 'channelappendmsg',\n processid: processId,\n name: channelName,\n sequence: sequence,\n inreplyto: inReplyTo,\n payload: payloadBytes,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Read messages from a process channel\n * @param processId - ID of the process\n * @param channelName - Name of the channel\n * @param afterSeq - Read messages after this sequence number (use 0 for all)\n * @param limit - Maximum number of messages to return (0 for no limit)\n */\n async channelRead(\n processId: string,\n channelName: string,\n afterSeq: number,\n limit: number\n ): Promise<any[]> {\n const msg = {\n msgtype: 'channelreadmsg',\n processid: processId,\n name: channelName,\n afterseq: afterSeq,\n limit: limit,\n };\n\n const response = await this.sendRPC(this.createRPCMsg(msg));\n\n // Response is an array of channel entries, decode payload bytes if needed\n if (Array.isArray(response)) {\n return response.map((entry) => ({\n ...entry,\n payload:\n typeof entry.payload === 'string'\n ? (() => {\n try {\n const binaryStr = atob(entry.payload);\n const bytes = new Uint8Array(binaryStr.length);\n for (let i = 0; i < binaryStr.length; i++) {\n bytes[i] = binaryStr.charCodeAt(i);\n }\n return new TextDecoder('utf-8').decode(bytes);\n } catch {\n return entry.payload;\n }\n })()\n : Array.isArray(entry.payload)\n ? new TextDecoder('utf-8').decode(new Uint8Array(entry.payload))\n : entry.payload,\n }));\n }\n\n return response || [];\n }\n\n /**\n * Subscribe to a channel using WebSocket for real-time updates\n * @param processId - ID of the process\n * @param channelName - Name of the channel\n * @param afterSeq - Start reading after this sequence number\n * @param timeout - Timeout in seconds for the subscription\n * @param onMessage - Callback for new messages\n * @param onError - Callback for errors\n * @param onClose - Callback when connection closes\n * @returns WebSocket instance for cleanup\n */\n subscribeChannel(\n processId: string,\n channelName: string,\n afterSeq: number,\n timeout: number,\n onMessage: (entries: any[]) => void,\n onError: (error: Error) => void,\n onClose: () => void\n ): WebSocket {\n if (!this.privateKey) {\n throw new Error('Private key not set. Call setPrivateKey() first.');\n }\n\n const wsProtocol = this.tls ? 'wss' : 'ws';\n const wsUrl = `${wsProtocol}://${this.host}:${this.port}/pubsub`;\n\n const ws = new WebSocket(wsUrl);\n\n ws.onopen = () => {\n const msg = {\n msgtype: 'subscribechannelmsg',\n processid: processId,\n name: channelName,\n afterseq: afterSeq,\n timeout: timeout,\n };\n\n const rpcMsg = this.createRPCMsg(msg);\n ws.send(JSON.stringify(rpcMsg));\n };\n\n ws.onmessage = (event) => {\n try {\n const rpcReply = JSON.parse(event.data as string);\n\n if (rpcReply.error) {\n const errorPayload = JSON.parse(decodeBase64Utf8(rpcReply.payload));\n onError(new Error(errorPayload.message || 'WebSocket error'));\n return;\n }\n\n const data = JSON.parse(decodeBase64Utf8(rpcReply.payload));\n\n if (Array.isArray(data)) {\n const entries = data.map((entry) => ({\n ...entry,\n payload:\n typeof entry.payload === 'string'\n ? (() => {\n try {\n const binaryStr = atob(entry.payload);\n const bytes = new Uint8Array(binaryStr.length);\n for (let i = 0; i < binaryStr.length; i++) {\n bytes[i] = binaryStr.charCodeAt(i);\n }\n return new TextDecoder('utf-8').decode(bytes);\n } catch {\n return entry.payload;\n }\n })()\n : Array.isArray(entry.payload)\n ? new TextDecoder('utf-8').decode(new Uint8Array(entry.payload))\n : entry.payload,\n }));\n\n const errorEntry = entries.find((e) => e.error);\n if (errorEntry) {\n onError(new Error(errorEntry.error));\n return;\n }\n\n onMessage(entries);\n }\n } catch (err) {\n onError(err instanceof Error ? err : new Error(String(err)));\n }\n };\n\n ws.onerror = () => {\n onError(new Error('WebSocket connection error'));\n };\n\n ws.onclose = () => {\n onClose();\n };\n\n return ws;\n }\n\n // ==================== Blueprint Definition Methods ====================\n\n /**\n * Add a blueprint definition\n * @param definition - Blueprint definition object\n */\n async addBlueprintDefinition(definition: any): Promise<any> {\n const msg = {\n msgtype: 'addblueprintdefinitionmsg',\n blueprintdefinition: definition,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Get a blueprint definition by name\n * @param colonyName - Name of the colony\n * @param name - Name of the blueprint definition\n */\n async getBlueprintDefinition(colonyName: string, name: string): Promise<any> {\n const msg = {\n msgtype: 'getblueprintdefinitionmsg',\n colonyname: colonyName,\n name,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Get all blueprint definitions in a colony\n * @param colonyName - Name of the colony\n */\n async getBlueprintDefinitions(colonyName: string): Promise<any[]> {\n const msg = {\n msgtype: 'getblueprintdefinitionsmsg',\n colonyname: colonyName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Remove a blueprint definition\n * @param colonyName - Name of the colony (namespace)\n * @param name - Name of the blueprint definition to remove\n */\n async removeBlueprintDefinition(colonyName: string, name: string): Promise<void> {\n const msg = {\n msgtype: 'removeblueprintdefinitionmsg',\n namespace: colonyName,\n name,\n };\n await this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Blueprint Methods ====================\n\n /**\n * Add a blueprint instance\n * @param blueprint - Blueprint object\n */\n async addBlueprint(blueprint: any): Promise<any> {\n const msg = {\n msgtype: 'addblueprintmsg',\n blueprint,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Get a blueprint by name\n * @param colonyName - Name of the colony (namespace)\n * @param name - Name of the blueprint\n */\n async getBlueprint(colonyName: string, name: string): Promise<any> {\n const msg = {\n msgtype: 'getblueprintmsg',\n namespace: colonyName,\n name,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Get blueprints in a colony, optionally filtered by kind and location\n * @param colonyName - Name of the colony (namespace)\n * @param kind - Optional kind filter\n * @param location - Optional location filter\n */\n async getBlueprints(colonyName: string, kind?: string, location?: string): Promise<any[]> {\n const msg: any = {\n msgtype: 'getblueprintsmsg',\n namespace: colonyName,\n };\n if (kind) msg.kind = kind;\n if (location) msg.locationname = location;\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Update an existing blueprint\n * @param blueprint - Updated blueprint object\n * @param forceGeneration - Force generation bump even if spec unchanged\n */\n async updateBlueprint(blueprint: any, forceGeneration: boolean = false): Promise<any> {\n const msg = {\n msgtype: 'updateblueprintmsg',\n blueprint,\n forcegeneration: forceGeneration,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Remove a blueprint\n * @param colonyName - Name of the colony (namespace)\n * @param name - Name of the blueprint to remove\n */\n async removeBlueprint(colonyName: string, name: string): Promise<void> {\n const msg = {\n msgtype: 'removeblueprintmsg',\n namespace: colonyName,\n name,\n };\n await this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Update blueprint status (current state)\n * @param colonyName - Name of the colony\n * @param name - Name of the blueprint\n * @param status - Status object representing current state\n */\n async updateBlueprintStatus(colonyName: string, name: string, status: any): Promise<void> {\n const msg = {\n msgtype: 'updateblueprintstatusmsg',\n colonyname: colonyName,\n blueprintname: name,\n status,\n };\n await this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Trigger reconciliation for a blueprint\n * @param colonyName - Name of the colony (namespace)\n * @param name - Name of the blueprint\n * @param force - Force reconciliation even if no changes detected\n */\n async reconcileBlueprint(colonyName: string, name: string, force: boolean = false): Promise<any> {\n const msg = {\n msgtype: 'reconcileblueprintmsg',\n namespace: colonyName,\n name,\n force,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Subscribe to process state changes using WebSocket\n * Use this to wait for a process to be assigned (RUNNING state) before subscribing to channels\n * @param colonyName - Name of the colony\n * @param processId - ID of the process to watch\n * @param state - Target state to wait for (0=WAITING, 1=RUNNING, 2=SUCCESS, 3=FAILED)\n * @param timeout - Timeout in seconds for the subscription\n * @param onProcess - Callback when process reaches the target state\n * @param onError - Callback for errors\n * @param onClose - Callback when connection closes\n * @returns WebSocket instance for cleanup\n */\n subscribeProcess(\n colonyName: string,\n processId: string,\n state: number,\n timeout: number,\n onProcess: (process: any) => void,\n onError: (error: Error) => void,\n onClose: () => void\n ): WebSocket {\n if (!this.privateKey) {\n throw new Error('Private key not set. Call setPrivateKey() first.');\n }\n\n const wsProtocol = this.tls ? 'wss' : 'ws';\n const wsUrl = `${wsProtocol}://${this.host}:${this.port}/pubsub`;\n\n const ws = new WebSocket(wsUrl);\n\n ws.onopen = () => {\n const msg = {\n msgtype: 'subscribeprocessmsg',\n colonyname: colonyName,\n processid: processId,\n executortype: '',\n state: state,\n timeout: timeout,\n };\n\n const rpcMsg = this.createRPCMsg(msg);\n ws.send(JSON.stringify(rpcMsg));\n };\n\n ws.onmessage = (event) => {\n try {\n const rpcReply = JSON.parse(event.data as string);\n\n if (rpcReply.error) {\n const errorPayload = JSON.parse(decodeBase64Utf8(rpcReply.payload));\n onError(new Error(errorPayload.message || 'WebSocket error'));\n return;\n }\n\n const process = JSON.parse(decodeBase64Utf8(rpcReply.payload));\n onProcess(process);\n } catch (err) {\n onError(err instanceof Error ? err : new Error(String(err)));\n }\n };\n\n ws.onerror = () => {\n onError(new Error('WebSocket connection error'));\n };\n\n ws.onclose = () => {\n onClose();\n };\n\n return ws;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMA,kBAAyB;AACzB,oBAAuB;AACvB,kBAAqB;AACrB,mBAAoD;AAIpD,IAAM,IAAI;AACV,IAAM,IA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G,UAAU,MAAM;AACjB,cAAQ;AAAA,IACV;AAEA,WAAO;AAAA,EACT;AACF;","names":["ProcessState"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/crypto.ts","../src/client.ts"],"sourcesContent":["export { Crypto, generatePrivateKey, deriveId, sign } from './crypto';\nexport { ColoniesClient, ProcessState } from './client';\nexport type { ColoniesClientConfig, FunctionSpec, RPCMessage } from './client';\n","/**\n * ColonyOS Crypto implementation\n * Ported from pycolonies/crypto.py\n * Based on eth-utils and eth-keys (MIT-licensed)\n */\n\nimport { sha3_256 } from '@noble/hashes/sha3';\nimport { sha256 } from '@noble/hashes/sha256';\nimport { hmac } from '@noble/hashes/hmac';\nimport { bytesToHex, hexToBytes, randomBytes } from '@noble/hashes/utils';\n\n// ============== secp256k1 Curve Parameters ==============\n\nconst A = 0n;\nconst N = 115792089237316195423570985008687907852837564279074904382605163141518161494337n;\nconst Gx = 55066263022277343669578718895168534326250603453777594175500187360389116729240n;\nconst Gy = 32670510020758816978083085130507043184471273380659243275938904335757337482424n;\nconst G: [bigint, bigint] = [Gx, Gy];\nconst P = 2n ** 256n - 2n ** 32n - 977n;\n\ntype Point = [bigint, bigint];\ntype JacobianPoint = [bigint, bigint, bigint];\n\n// ============== Utility Functions ==============\n\nfunction pad32(value: Uint8Array): Uint8Array {\n if (value.length >= 32) return value.slice(0, 32);\n const padded = new Uint8Array(32);\n padded.set(value, 32 - value.length);\n return padded;\n}\n\nfunction intToBigEndian(value: bigint): Uint8Array {\n if (value === 0n) return new Uint8Array([0]);\n const hex = value.toString(16);\n const paddedHex = hex.length % 2 ? '0' + hex : hex;\n return hexToBytes(paddedHex);\n}\n\nfunction bigEndianToInt(value: Uint8Array): bigint {\n if (value.length === 0) return 0n;\n return BigInt('0x' + bytesToHex(value));\n}\n\n// ============== Elliptic Curve Math ==============\n\nfunction inv(a: bigint, n: bigint): bigint {\n if (a === 0n) return 0n;\n let lm = 1n, hm = 0n;\n let low = ((a % n) + n) % n, high = n;\n while (low > 1n) {\n const r = high / low;\n const nm = hm - lm * r;\n const newVal = high - low * r;\n hm = lm;\n high = low;\n lm = nm;\n low = newVal;\n }\n return ((lm % n) + n) % n;\n}\n\nfunction toJacobian(p: Point): JacobianPoint {\n return [p[0], p[1], 1n];\n}\n\nfunction fromJacobian(p: JacobianPoint): Point {\n const z = inv(p[2], P);\n const z2 = (z * z) % P;\n const z3 = (z2 * z) % P;\n return [((p[0] * z2) % P + P) % P, ((p[1] * z3) % P + P) % P];\n}\n\nfunction jacobianDouble(p: JacobianPoint): JacobianPoint {\n if (p[1] === 0n) return [0n, 0n, 0n];\n const ysq = (p[1] ** 2n) % P;\n const S = (4n * p[0] * ysq) % P;\n const M = (3n * p[0] ** 2n + A * p[2] ** 4n) % P;\n const nx = ((M ** 2n - 2n * S) % P + P) % P;\n const ny = ((M * (S - nx) - 8n * ysq ** 2n) % P + P) % P;\n const nz = (2n * p[1] * p[2]) % P;\n return [nx, ny, nz];\n}\n\nfunction jacobianAdd(p: JacobianPoint, q: JacobianPoint): JacobianPoint {\n if (p[1] === 0n) return q;\n if (q[1] === 0n) return p;\n\n const U1 = (p[0] * q[2] ** 2n) % P;\n const U2 = (q[0] * p[2] ** 2n) % P;\n const S1 = (p[1] * q[2] ** 3n) % P;\n const S2 = (q[1] * p[2] ** 3n) % P;\n\n if (U1 === U2) {\n if (S1 !== S2) return [0n, 0n, 1n];\n return jacobianDouble(p);\n }\n\n const H = ((U2 - U1) % P + P) % P;\n const R = ((S2 - S1) % P + P) % P;\n const H2 = (H * H) % P;\n const H3 = (H * H2) % P;\n const U1H2 = (U1 * H2) % P;\n const nx = ((R ** 2n - H3 - 2n * U1H2) % P + P) % P;\n const ny = ((R * (U1H2 - nx) - S1 * H3) % P + P) % P;\n const nz = (H * p[2] * q[2]) % P;\n\n return [nx, ny, nz];\n}\n\nfunction jacobianMultiply(a: JacobianPoint, n: bigint): JacobianPoint {\n if (a[1] === 0n || n === 0n) return [0n, 0n, 1n];\n if (n === 1n) return a;\n if (n < 0n || n >= N) return jacobianMultiply(a, ((n % N) + N) % N);\n if (n % 2n === 0n) {\n return jacobianDouble(jacobianMultiply(a, n / 2n));\n } else {\n return jacobianAdd(jacobianDouble(jacobianMultiply(a, n / 2n)), a);\n }\n}\n\nfunction fastMultiply(a: Point, n: bigint): Point {\n return fromJacobian(jacobianMultiply(toJacobian(a), n));\n}\n\nfunction encodeRawPublicKey(rawPublicKey: Point): Uint8Array {\n const left = pad32(intToBigEndian(rawPublicKey[0]));\n const right = pad32(intToBigEndian(rawPublicKey[1]));\n const result = new Uint8Array(64);\n result.set(left, 0);\n result.set(right, 32);\n return result;\n}\n\nfunction privateKeyToPublicKey(privateKeyBytes: Uint8Array): Uint8Array {\n const privateKeyAsNum = bigEndianToInt(privateKeyBytes);\n if (privateKeyAsNum >= N) {\n throw new Error('Invalid private key');\n }\n const rawPublicKey = fastMultiply(G, privateKeyAsNum);\n return encodeRawPublicKey(rawPublicKey);\n}\n\n// ============== ECDSA Signing ==============\n\nfunction deterministicGenerateK(msgHash: Uint8Array, privateKeyBytes: Uint8Array): bigint {\n const v0 = new Uint8Array(32).fill(0x01);\n const k0 = new Uint8Array(32).fill(0x00);\n\n // k1 = HMAC(k0, v0 || 0x00 || priv || hash)\n const data1 = new Uint8Array(v0.length + 1 + privateKeyBytes.length + msgHash.length);\n data1.set(v0, 0);\n data1[v0.length] = 0x00;\n data1.set(privateKeyBytes, v0.length + 1);\n data1.set(msgHash, v0.length + 1 + privateKeyBytes.length);\n const k1 = hmac(sha256, k0, data1);\n\n // v1 = HMAC(k1, v0)\n const v1 = hmac(sha256, k1, v0);\n\n // k2 = HMAC(k1, v1 || 0x01 || priv || hash)\n const data2 = new Uint8Array(v1.length + 1 + privateKeyBytes.length + msgHash.length);\n data2.set(v1, 0);\n data2[v1.length] = 0x01;\n data2.set(privateKeyBytes, v1.length + 1);\n data2.set(msgHash, v1.length + 1 + privateKeyBytes.length);\n const k2 = hmac(sha256, k1, data2);\n\n // v2 = HMAC(k2, v1)\n const v2 = hmac(sha256, k2, v1);\n\n // kb = HMAC(k2, v2)\n const kb = hmac(sha256, k2, v2);\n return bigEndianToInt(kb);\n}\n\nfunction ecdsaRawSign(msgHash: Uint8Array, privateKeyBytes: Uint8Array): [number, bigint, bigint] {\n const z = bigEndianToInt(msgHash);\n const k = deterministicGenerateK(msgHash, privateKeyBytes);\n\n const [r, y] = fastMultiply(G, k);\n const privKeyNum = bigEndianToInt(privateKeyBytes);\n const sRaw = (inv(k, N) * (z + r * privKeyNum)) % N;\n\n const v = 27 + Number((y % 2n) ^ (sRaw * 2n < N ? 0n : 1n));\n const s = sRaw * 2n < N ? sRaw : N - sRaw;\n\n return [v - 27, r, s];\n}\n\n// ============== Exported Functions ==============\n\n/**\n * Generate a new random private key\n * @returns Hex-encoded private key (64 characters)\n */\nexport function generatePrivateKey(): string {\n const randomData = randomBytes(32);\n const hash = sha3_256(randomData);\n return bytesToHex(hash);\n}\n\n/**\n * Derive the public ID from a private key\n * Uses SHA3-256 hash of \"04\" + hex(publicKey)\n * @param privateKey - Hex-encoded private key\n * @returns Hex-encoded ID (64 characters)\n */\nexport function deriveId(privateKey: string): string {\n const privateKeyBytes = hexToBytes(privateKey);\n const publicKey = privateKeyToPublicKey(privateKeyBytes);\n const publicKeyHex = '04' + bytesToHex(publicKey);\n\n // Hash the string representation, not the bytes\n const encoder = new TextEncoder();\n const hash = sha3_256(encoder.encode(publicKeyHex));\n\n return bytesToHex(hash);\n}\n\n/**\n * Sign a message with a private key\n * @param message - Message to sign\n * @param privateKey - Hex-encoded private key\n * @returns Hex-encoded signature (130 characters: r + s + v)\n */\nexport function sign(message: string, privateKey: string): string {\n const privateKeyBytes = hexToBytes(privateKey);\n\n // Hash message with SHA3-256\n const encoder = new TextEncoder();\n const msgHash = sha3_256(encoder.encode(message));\n\n const [v, r, s] = ecdsaRawSign(msgHash, privateKeyBytes);\n\n // Format: r (32 bytes) + s (32 bytes) + v (1 byte)\n const vBytes = new Uint8Array([v]);\n const rBytes = pad32(intToBigEndian(r));\n const sBytes = pad32(intToBigEndian(s));\n\n const signature = new Uint8Array(65);\n signature.set(rBytes, 0);\n signature.set(sBytes, 32);\n signature.set(vBytes, 64);\n\n return bytesToHex(signature);\n}\n\n/**\n * Crypto utility class for convenience\n */\nexport class Crypto {\n generatePrivateKey(): string {\n return generatePrivateKey();\n }\n\n id(privateKey: string): string {\n return deriveId(privateKey);\n }\n\n sign(message: string, privateKey: string): string {\n return sign(message, privateKey);\n }\n}\n\n// Export internal functions for testing\nexport const _internal = {\n jacobianAdd,\n jacobianDouble,\n fastMultiply,\n pad32,\n intToBigEndian,\n bigEndianToInt,\n};\n","/**\n * ColonyOS Client\n * Ported from colonyspace/aila/src/lib/api/colony.ts\n */\n\nimport { Crypto } from './crypto';\n\n// Helper function to decode base64 payload with proper UTF-8 handling\nfunction decodeBase64Utf8(base64: string): string {\n const binaryStr = atob(base64);\n const bytes = new Uint8Array(binaryStr.length);\n for (let i = 0; i < binaryStr.length; i++) {\n bytes[i] = binaryStr.charCodeAt(i);\n }\n return new TextDecoder('utf-8').decode(bytes);\n}\n\n// Helper function to encode string to base64 with proper UTF-8 handling\nfunction encodeBase64Utf8(str: string): string {\n const utf8Bytes = new TextEncoder().encode(str);\n const binaryStr = String.fromCharCode(...utf8Bytes);\n return btoa(binaryStr);\n}\n\nexport interface ColoniesClientConfig {\n host: string;\n port: number;\n tls?: boolean;\n}\n\nexport interface RPCMessage {\n payloadtype: string;\n payload: string;\n signature: string;\n}\n\nexport interface FunctionSpec {\n nodename?: string;\n funcname: string;\n args?: any[];\n kwargs?: Record<string, any>;\n priority?: number;\n maxwaittime?: number;\n maxexectime?: number;\n maxretries?: number;\n conditions?: {\n colonyname?: string;\n executornames?: string[];\n executortype?: string;\n dependencies?: string[];\n nodes?: number;\n cpu?: string;\n processes?: number;\n processespernode?: number;\n mem?: string;\n storage?: string;\n gpu?: { name?: string; mem?: string; count?: number; nodecount?: number };\n walltime?: number;\n };\n label?: string;\n fs?: any;\n env?: Record<string, string>;\n channels?: string[];\n}\n\nexport enum ProcessState {\n WAITING = 0,\n RUNNING = 1,\n SUCCESS = 2,\n FAILED = 3,\n}\n\nexport class ColoniesClient {\n private host: string;\n private port: number;\n private tls: boolean;\n private crypto: Crypto;\n private privateKey: string | null = null;\n\n constructor(config: ColoniesClientConfig) {\n this.host = config.host;\n this.port = config.port;\n this.tls = config.tls ?? false;\n this.crypto = new Crypto();\n }\n\n setPrivateKey(privateKey: string): void {\n this.privateKey = privateKey;\n }\n\n private getBaseUrl(): string {\n const protocol = this.tls ? 'https' : 'http';\n return `${protocol}://${this.host}:${this.port}/api`;\n }\n\n private createRPCMsg(msg: any): RPCMessage {\n if (!this.privateKey) {\n throw new Error('Private key not set. Call setPrivateKey() first.');\n }\n\n const payload = encodeBase64Utf8(JSON.stringify(msg));\n const signature = this.crypto.sign(payload, this.privateKey);\n\n return {\n payloadtype: msg.msgtype,\n payload,\n signature,\n };\n }\n\n private async sendRPC(rpcMessage: RPCMessage): Promise<any> {\n const url = this.getBaseUrl();\n\n const response = await fetch(url, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(rpcMessage),\n });\n\n if (!response.ok) {\n const errorText = await response.text();\n let errorObj;\n try {\n errorObj = JSON.parse(errorText);\n } catch {\n throw new Error(`Request failed with status ${response.status}: ${response.statusText}`);\n }\n\n if (errorObj.payload) {\n try {\n const decodedPayload = decodeBase64Utf8(errorObj.payload);\n const decodedError = JSON.parse(decodedPayload);\n throw new Error(decodedError.message || JSON.stringify(decodedError));\n } catch (e) {\n if (e instanceof Error && e.message !== 'Request failed') {\n throw e;\n }\n }\n }\n throw new Error(JSON.stringify(errorObj));\n }\n\n const responseText = await response.text();\n if (!responseText || responseText.trim() === '') {\n throw new Error('Server returned empty response');\n }\n\n const rpcReplyMsg = JSON.parse(responseText);\n const msg = JSON.parse(decodeBase64Utf8(rpcReplyMsg.payload));\n\n if (rpcReplyMsg.error === true) {\n const errorMessage = typeof msg === 'object' && msg.message ? msg.message : JSON.stringify(msg);\n throw new Error(errorMessage);\n }\n\n return msg;\n }\n\n // ==================== Colony Methods ====================\n\n async getColonies(): Promise<any> {\n const msg = { msgtype: 'getcoloniesmsg' };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getStatistics(): Promise<any> {\n const msg = { msgtype: 'getstatisticsmsg' };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Add a new colony (requires server private key)\n * @param colony - Colony object with colonyid and name\n */\n async addColony(colony: { colonyid: string; name: string }): Promise<any> {\n const msg = {\n msgtype: 'addcolonymsg',\n colony,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Remove a colony (requires server private key)\n * @param colonyName - Name of the colony to remove\n */\n async removeColony(colonyName: string): Promise<any> {\n const msg = {\n msgtype: 'removecolonymsg',\n colonyname: colonyName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Executor Methods ====================\n\n async getExecutors(colonyName: string): Promise<any> {\n const msg = {\n msgtype: 'getexecutorsmsg',\n colonyname: colonyName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getExecutor(colonyName: string, executorName: string): Promise<any> {\n const msg = {\n msgtype: 'getexecutormsg',\n colonyname: colonyName,\n executorname: executorName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async addExecutor(executor: {\n executorid: string;\n executortype: string;\n executorname: string;\n colonyname: string;\n }): Promise<any> {\n const msg = {\n msgtype: 'addexecutormsg',\n executor,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async approveExecutor(colonyName: string, executorName: string): Promise<any> {\n const msg = {\n msgtype: 'approveexecutormsg',\n colonyname: colonyName,\n executorname: executorName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async removeExecutor(colonyName: string, executorName: string): Promise<any> {\n const msg = {\n msgtype: 'removeexecutormsg',\n colonyname: colonyName,\n executorname: executorName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Process Methods ====================\n\n async submitFunctionSpec(spec: FunctionSpec): Promise<any> {\n const msg = {\n msgtype: 'submitfuncspecmsg',\n spec,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getProcess(processId: string): Promise<any> {\n const msg = {\n msgtype: 'getprocessmsg',\n processid: processId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getProcesses(colonyName: string, count: number, state: ProcessState): Promise<any> {\n const msg = {\n msgtype: 'getprocessesmsg',\n colonyname: colonyName,\n count,\n state,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async removeProcess(processId: string): Promise<any> {\n const msg = {\n msgtype: 'removeprocessmsg',\n processid: processId,\n all: false,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async removeAllProcesses(colonyName: string, state: number = -1): Promise<any> {\n const msg = {\n msgtype: 'removeallprocessesmsg',\n colonyname: colonyName,\n state,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async assign(colonyName: string, timeout: number, executorPrvKey: string): Promise<any> {\n // Temporarily set the executor private key for this operation\n const originalKey = this.privateKey;\n this.setPrivateKey(executorPrvKey);\n\n try {\n const msg = {\n msgtype: 'assignprocessmsg',\n colonyname: colonyName,\n timeout,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n } finally {\n if (originalKey) {\n this.setPrivateKey(originalKey);\n }\n }\n }\n\n async closeProcess(processId: string, output: string[]): Promise<any> {\n const msg = {\n msgtype: 'closesuccessfulmsg',\n processid: processId,\n out: output,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async failProcess(processId: string, errors: string[]): Promise<any> {\n const msg = {\n msgtype: 'closefailedmsg',\n processid: processId,\n errors,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Workflow Methods ====================\n\n async submitWorkflowSpec(workflowSpec: {\n colonyname: string;\n functionspecs: FunctionSpec[];\n }): Promise<any> {\n const msg = {\n msgtype: 'submitworkflowspecmsg',\n spec: workflowSpec,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getProcessGraph(processGraphId: string): Promise<any> {\n const msg = {\n msgtype: 'getprocessgraphmsg',\n processgraphid: processGraphId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getProcessGraphs(colonyName: string, count: number, state?: ProcessState): Promise<any> {\n const msg: any = {\n msgtype: 'getprocessgraphsmsg',\n colonyname: colonyName,\n count,\n };\n if (state !== undefined) {\n msg.state = state;\n }\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async removeProcessGraph(processGraphId: string): Promise<any> {\n const msg = {\n msgtype: 'removeprocessgraphmsg',\n processgraphid: processGraphId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getProcessesForWorkflow(processGraphId: string, colonyName: string, count: number = 100): Promise<any> {\n const msg = {\n msgtype: 'getprocessesmsg',\n processgraphid: processGraphId,\n colonyname: colonyName,\n count,\n state: -1,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async removeAllProcessGraphs(colonyName: string, state?: ProcessState): Promise<any> {\n const msg: any = {\n msgtype: 'removeallprocessgraphsmsg',\n colonyname: colonyName,\n };\n if (state !== undefined) {\n msg.state = state;\n }\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Log Methods ====================\n\n async addLog(processId: string, message: string, executorPrvKey: string): Promise<any> {\n const originalKey = this.privateKey;\n this.setPrivateKey(executorPrvKey);\n\n try {\n const msg = {\n msgtype: 'addlogmsg',\n processid: processId,\n message,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n } finally {\n if (originalKey) {\n this.setPrivateKey(originalKey);\n }\n }\n }\n\n async getLogs(colonyName: string, processId: string, executorName: string, count: number = 100, since: number = 0): Promise<any> {\n const msg = {\n msgtype: 'getlogsmsg',\n colonyname: colonyName,\n processid: processId,\n executorname: executorName,\n count,\n since,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Function Methods ====================\n\n async getFunctions(executorName: string, colonyName: string): Promise<any> {\n const msg = {\n msgtype: 'getfunctionsmsg',\n executorname: executorName,\n colonyname: colonyName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Cron Methods ====================\n\n async getCrons(colonyName: string, count: number = 100): Promise<any> {\n const msg = {\n msgtype: 'getcronsmsg',\n colonyname: colonyName,\n count,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getCron(cronId: string): Promise<any> {\n const msg = {\n msgtype: 'getcronmsg',\n cronid: cronId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async addCron(cronSpec: any): Promise<any> {\n const msg = {\n msgtype: 'addcronmsg',\n cron: cronSpec,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async removeCron(cronId: string): Promise<any> {\n const msg = {\n msgtype: 'removecronmsg',\n cronid: cronId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async runCron(cronId: string): Promise<any> {\n const msg = {\n msgtype: 'runcronmsg',\n cronid: cronId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Generator Methods ====================\n\n async getGenerators(colonyName: string, count: number = 100): Promise<any> {\n const msg = {\n msgtype: 'getgeneratorsmsg',\n colonyname: colonyName,\n count,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getGenerator(generatorId: string): Promise<any> {\n const msg = {\n msgtype: 'getgeneratormsg',\n generatorid: generatorId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async addGenerator(generatorSpec: any): Promise<any> {\n const msg = {\n msgtype: 'addgeneratormsg',\n generator: generatorSpec,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== User Methods ====================\n\n async getUsers(colonyName: string): Promise<any> {\n const msg = {\n msgtype: 'getusersmsg',\n colonyname: colonyName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async addUser(user: {\n colonyname: string;\n userid: string;\n name: string;\n email: string;\n phone: string;\n }): Promise<any> {\n const msg = {\n msgtype: 'addusermsg',\n user,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async removeUser(colonyName: string, name: string): Promise<any> {\n const msg = {\n msgtype: 'removeusermsg',\n colonyname: colonyName,\n name,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== File Methods ====================\n\n async getFileLabels(colonyName: string, name: string = '', exact: boolean = false): Promise<any> {\n const msg = {\n msgtype: 'getfilelabelsmsg',\n colonyname: colonyName,\n name,\n exact,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getFiles(colonyName: string, label: string): Promise<any> {\n const msg = {\n msgtype: 'getfilesmsg',\n colonyname: colonyName,\n label,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getFile(\n colonyName: string,\n options: { fileId: string } | { name: string; label: string; latest?: boolean }\n ): Promise<any> {\n const msg: any = {\n msgtype: 'getfilemsg',\n colonyname: colonyName,\n };\n\n if ('fileId' in options) {\n msg.fileid = options.fileId;\n } else {\n msg.name = options.name;\n msg.label = options.label;\n if (options.latest !== undefined) {\n msg.latest = options.latest;\n }\n }\n\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Attribute Methods ====================\n\n async addAttribute(attribute: {\n targetid: string;\n targetcolonyname: string;\n targetprocessgraphid: string;\n attributetype: number;\n key: string;\n value: string;\n }): Promise<any> {\n const msg = {\n msgtype: 'addattributemsg',\n attribute,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getAttribute(attributeId: string): Promise<any> {\n const msg = {\n msgtype: 'getattributemsg',\n attributeid: attributeId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Channel Methods ====================\n\n /**\n * Append a message to a process channel\n * @param processId - ID of the process\n * @param channelName - Name of the channel\n * @param sequence - Client-assigned sequence number\n * @param inReplyTo - Sequence number this message is replying to (0 if not a reply)\n * @param payload - Message content (string or Uint8Array)\n */\n async channelAppend(\n processId: string,\n channelName: string,\n sequence: number,\n inReplyTo: number,\n payload: string | Uint8Array\n ): Promise<any> {\n let payloadBytes: number[];\n if (typeof payload === 'string') {\n const encoder = new TextEncoder();\n payloadBytes = Array.from(encoder.encode(payload));\n } else {\n payloadBytes = Array.from(payload);\n }\n\n const msg = {\n msgtype: 'channelappendmsg',\n processid: processId,\n name: channelName,\n sequence: sequence,\n inreplyto: inReplyTo,\n payload: payloadBytes,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Read messages from a process channel\n * @param processId - ID of the process\n * @param channelName - Name of the channel\n * @param afterSeq - Read messages after this sequence number (use 0 for all)\n * @param limit - Maximum number of messages to return (0 for no limit)\n */\n async channelRead(\n processId: string,\n channelName: string,\n afterSeq: number,\n limit: number\n ): Promise<any[]> {\n const msg = {\n msgtype: 'channelreadmsg',\n processid: processId,\n name: channelName,\n afterseq: afterSeq,\n limit: limit,\n };\n\n const response = await this.sendRPC(this.createRPCMsg(msg));\n\n // Response is an array of channel entries, decode payload bytes if needed\n if (Array.isArray(response)) {\n return response.map((entry) => ({\n ...entry,\n payload:\n typeof entry.payload === 'string'\n ? (() => {\n try {\n const binaryStr = atob(entry.payload);\n const bytes = new Uint8Array(binaryStr.length);\n for (let i = 0; i < binaryStr.length; i++) {\n bytes[i] = binaryStr.charCodeAt(i);\n }\n return new TextDecoder('utf-8').decode(bytes);\n } catch {\n return entry.payload;\n }\n })()\n : Array.isArray(entry.payload)\n ? new TextDecoder('utf-8').decode(new Uint8Array(entry.payload))\n : entry.payload,\n }));\n }\n\n return response || [];\n }\n\n /**\n * Subscribe to a channel using WebSocket for real-time updates\n * @param processId - ID of the process\n * @param channelName - Name of the channel\n * @param afterSeq - Start reading after this sequence number\n * @param timeout - Timeout in seconds for the subscription\n * @param onMessage - Callback for new messages\n * @param onError - Callback for errors\n * @param onClose - Callback when connection closes\n * @returns WebSocket instance for cleanup\n */\n subscribeChannel(\n processId: string,\n channelName: string,\n afterSeq: number,\n timeout: number,\n onMessage: (entries: any[]) => void,\n onError: (error: Error) => void,\n onClose: () => void\n ): WebSocket {\n if (!this.privateKey) {\n throw new Error('Private key not set. Call setPrivateKey() first.');\n }\n\n const wsProtocol = this.tls ? 'wss' : 'ws';\n const wsUrl = `${wsProtocol}://${this.host}:${this.port}/pubsub`;\n\n const ws = new WebSocket(wsUrl);\n\n ws.onopen = () => {\n const msg = {\n msgtype: 'subscribechannelmsg',\n processid: processId,\n name: channelName,\n afterseq: afterSeq,\n timeout: timeout,\n };\n\n const rpcMsg = this.createRPCMsg(msg);\n ws.send(JSON.stringify(rpcMsg));\n };\n\n ws.onmessage = (event) => {\n try {\n const rpcReply = JSON.parse(event.data as string);\n\n if (rpcReply.error) {\n const errorPayload = JSON.parse(decodeBase64Utf8(rpcReply.payload));\n onError(new Error(errorPayload.message || 'WebSocket error'));\n return;\n }\n\n const data = JSON.parse(decodeBase64Utf8(rpcReply.payload));\n\n if (Array.isArray(data)) {\n const entries = data.map((entry) => ({\n ...entry,\n payload:\n typeof entry.payload === 'string'\n ? (() => {\n try {\n const binaryStr = atob(entry.payload);\n const bytes = new Uint8Array(binaryStr.length);\n for (let i = 0; i < binaryStr.length; i++) {\n bytes[i] = binaryStr.charCodeAt(i);\n }\n return new TextDecoder('utf-8').decode(bytes);\n } catch {\n return entry.payload;\n }\n })()\n : Array.isArray(entry.payload)\n ? new TextDecoder('utf-8').decode(new Uint8Array(entry.payload))\n : entry.payload,\n }));\n\n const errorEntry = entries.find((e) => e.error);\n if (errorEntry) {\n onError(new Error(errorEntry.error));\n return;\n }\n\n onMessage(entries);\n }\n } catch (err) {\n onError(err instanceof Error ? err : new Error(String(err)));\n }\n };\n\n ws.onerror = () => {\n onError(new Error('WebSocket connection error'));\n };\n\n ws.onclose = () => {\n onClose();\n };\n\n return ws;\n }\n\n // ==================== Blueprint Definition Methods ====================\n\n /**\n * Add a blueprint definition\n * @param definition - Blueprint definition object\n */\n async addBlueprintDefinition(definition: any): Promise<any> {\n const msg = {\n msgtype: 'addblueprintdefinitionmsg',\n blueprintdefinition: definition,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Get a blueprint definition by name\n * @param colonyName - Name of the colony\n * @param name - Name of the blueprint definition\n */\n async getBlueprintDefinition(colonyName: string, name: string): Promise<any> {\n const msg = {\n msgtype: 'getblueprintdefinitionmsg',\n colonyname: colonyName,\n name,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Get all blueprint definitions in a colony\n * @param colonyName - Name of the colony\n */\n async getBlueprintDefinitions(colonyName: string): Promise<any[]> {\n const msg = {\n msgtype: 'getblueprintdefinitionsmsg',\n colonyname: colonyName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Remove a blueprint definition\n * @param colonyName - Name of the colony (namespace)\n * @param name - Name of the blueprint definition to remove\n */\n async removeBlueprintDefinition(colonyName: string, name: string): Promise<void> {\n const msg = {\n msgtype: 'removeblueprintdefinitionmsg',\n namespace: colonyName,\n name,\n };\n await this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Blueprint Methods ====================\n\n /**\n * Add a blueprint instance\n * @param blueprint - Blueprint object\n */\n async addBlueprint(blueprint: any): Promise<any> {\n const msg = {\n msgtype: 'addblueprintmsg',\n blueprint,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Get a blueprint by name\n * @param colonyName - Name of the colony (namespace)\n * @param name - Name of the blueprint\n */\n async getBlueprint(colonyName: string, name: string): Promise<any> {\n const msg = {\n msgtype: 'getblueprintmsg',\n namespace: colonyName,\n name,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Get blueprints in a colony, optionally filtered by kind and location\n * @param colonyName - Name of the colony (namespace)\n * @param kind - Optional kind filter\n * @param location - Optional location filter\n */\n async getBlueprints(colonyName: string, kind?: string, location?: string): Promise<any[]> {\n const msg: any = {\n msgtype: 'getblueprintsmsg',\n namespace: colonyName,\n };\n if (kind) msg.kind = kind;\n if (location) msg.locationname = location;\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Update an existing blueprint\n * @param blueprint - Updated blueprint object\n * @param forceGeneration - Force generation bump even if spec unchanged\n */\n async updateBlueprint(blueprint: any, forceGeneration: boolean = false): Promise<any> {\n const msg = {\n msgtype: 'updateblueprintmsg',\n blueprint,\n forcegeneration: forceGeneration,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Remove a blueprint\n * @param colonyName - Name of the colony (namespace)\n * @param name - Name of the blueprint to remove\n */\n async removeBlueprint(colonyName: string, name: string): Promise<void> {\n const msg = {\n msgtype: 'removeblueprintmsg',\n namespace: colonyName,\n name,\n };\n await this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Update blueprint status (current state)\n * @param colonyName - Name of the colony\n * @param name - Name of the blueprint\n * @param status - Status object representing current state\n */\n async updateBlueprintStatus(colonyName: string, name: string, status: any): Promise<void> {\n const msg = {\n msgtype: 'updateblueprintstatusmsg',\n colonyname: colonyName,\n blueprintname: name,\n status,\n };\n await this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Trigger reconciliation for a blueprint\n * @param colonyName - Name of the colony (namespace)\n * @param name - Name of the blueprint\n * @param force - Force reconciliation even if no changes detected\n */\n async reconcileBlueprint(colonyName: string, name: string, force: boolean = false): Promise<any> {\n const msg = {\n msgtype: 'reconcileblueprintmsg',\n namespace: colonyName,\n name,\n force,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Get the history of changes for a specific blueprint\n * @param blueprintId - ID of the blueprint\n * @param limit - Optional limit on number of history entries to retrieve\n */\n async getBlueprintHistory(blueprintId: string, limit?: number): Promise<any> {\n const msg: any = {\n msgtype: 'getblueprinthistorymsg',\n blueprintid: blueprintId,\n };\n if (limit !== undefined) {\n msg.limit = limit;\n }\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Subscribe to process state changes using WebSocket\n * Use this to wait for a process to be assigned (RUNNING state) before subscribing to channels\n * @param colonyName - Name of the colony\n * @param processId - ID of the process to watch\n * @param state - Target state to wait for (0=WAITING, 1=RUNNING, 2=SUCCESS, 3=FAILED)\n * @param timeout - Timeout in seconds for the subscription\n * @param onProcess - Callback when process reaches the target state\n * @param onError - Callback for errors\n * @param onClose - Callback when connection closes\n * @returns WebSocket instance for cleanup\n */\n subscribeProcess(\n colonyName: string,\n processId: string,\n state: number,\n timeout: number,\n onProcess: (process: any) => void,\n onError: (error: Error) => void,\n onClose: () => void\n ): WebSocket {\n if (!this.privateKey) {\n throw new Error('Private key not set. Call setPrivateKey() first.');\n }\n\n const wsProtocol = this.tls ? 'wss' : 'ws';\n const wsUrl = `${wsProtocol}://${this.host}:${this.port}/pubsub`;\n\n const ws = new WebSocket(wsUrl);\n\n ws.onopen = () => {\n const msg = {\n msgtype: 'subscribeprocessmsg',\n colonyname: colonyName,\n processid: processId,\n executortype: '',\n state: state,\n timeout: timeout,\n };\n\n const rpcMsg = this.createRPCMsg(msg);\n ws.send(JSON.stringify(rpcMsg));\n };\n\n ws.onmessage = (event) => {\n try {\n const rpcReply = JSON.parse(event.data as string);\n\n if (rpcReply.error) {\n const errorPayload = JSON.parse(decodeBase64Utf8(rpcReply.payload));\n onError(new Error(errorPayload.message || 'WebSocket error'));\n return;\n }\n\n const process = JSON.parse(decodeBase64Utf8(rpcReply.payload));\n onProcess(process);\n } catch (err) {\n onError(err instanceof Error ? err : new Error(String(err)));\n }\n };\n\n ws.onerror = () => {\n onError(new Error('WebSocket connection error'));\n };\n\n ws.onclose = () => {\n onClose();\n };\n\n return ws;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMA,kBAAyB;AACzB,oBAAuB;AACvB,kBAAqB;AACrB,mBAAoD;AAIpD,IAAM,IAAI;AACV,IAAM,IAAI;AACV,IAAM,KAAK;AACX,IAA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X,QAAI,CAAC,KAAK,YAAY;AACpB,YAAM,IAAI,MAAM,kDAAkD;AAAA,IACpE;AAEA,UAAM,aAAa,KAAK,MAAM,QAAQ;AACtC,UAAM,QAAQ,GAAG,UAAU,MAAM,KAAK,IAAI,IAAI,KAAK,IAAI;AAEvD,UAAM,KAAK,IAAI,UAAU,KAAK;AAE9B,OAAG,SAAS,MAAM;AAChB,YAAM,MAAM;AAAA,QACV,SAAS;AAAA,QACT,YAAY;AAAA,QACZ,WAAW;AAAA,QACX,cAAc;AAAA,QACd;AAAA,QACA;AAAA,MACF;AAEA,YAAM,SAAS,KAAK,aAAa,GAAG;AACpC,SAAG,KAAK,KAAK,UAAU,MAAM,CAAC;AAAA,IAChC;AAEA,OAAG,YAAY,CAAC,UAAU;AACxB,UAAI;AACF,cAAM,WAAW,KAAK,MAAM,MAAM,IAAc;AAEhD,YAAI,SAAS,OAAO;AAClB,gBAAM,eAAe,KAAK,MAAM,iBAAiB,SAAS,OAAO,CAAC;AAClE,kBAAQ,IAAI,MAAM,aAAa,WAAW,iBAAiB,CAAC;AAC5D;AAAA,QACF;AAEA,cAAM,UAAU,KAAK,MAAM,iBAAiB,SAAS,OAAO,CAAC;AAC7D,kBAAU,OAAO;AAAA,MACnB,SAAS,KAAK;AACZ,gBAAQ,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC,CAAC;AAAA,MAC7D;AAAA,IACF;AAEA,OAAG,UAAU,MAAM;AACjB,cAAQ,IAAI,MAAM,4BAA4B,CAAC;AAAA,IACjD;AAEA,OAAG,UAAU,MAAM;AACjB,cAAQ;AAAA,IACV;AAEA,WAAO;AAAA,EACT;AACF;","names":["ProcessState"]}
|
package/dist/index.mjs
CHANGED
|
@@ -443,6 +443,16 @@ var ColoniesClient = class {
|
|
|
443
443
|
};
|
|
444
444
|
return this.sendRPC(this.createRPCMsg(msg));
|
|
445
445
|
}
|
|
446
|
+
async getProcessesForWorkflow(processGraphId, colonyName, count = 100) {
|
|
447
|
+
const msg = {
|
|
448
|
+
msgtype: "getprocessesmsg",
|
|
449
|
+
processgraphid: processGraphId,
|
|
450
|
+
colonyname: colonyName,
|
|
451
|
+
count,
|
|
452
|
+
state: -1
|
|
453
|
+
};
|
|
454
|
+
return this.sendRPC(this.createRPCMsg(msg));
|
|
455
|
+
}
|
|
446
456
|
async removeAllProcessGraphs(colonyName, state) {
|
|
447
457
|
const msg = {
|
|
448
458
|
msgtype: "removeallprocessgraphsmsg",
|
|
@@ -520,6 +530,13 @@ var ColoniesClient = class {
|
|
|
520
530
|
};
|
|
521
531
|
return this.sendRPC(this.createRPCMsg(msg));
|
|
522
532
|
}
|
|
533
|
+
async runCron(cronId) {
|
|
534
|
+
const msg = {
|
|
535
|
+
msgtype: "runcronmsg",
|
|
536
|
+
cronid: cronId
|
|
537
|
+
};
|
|
538
|
+
return this.sendRPC(this.createRPCMsg(msg));
|
|
539
|
+
}
|
|
523
540
|
// ==================== Generator Methods ====================
|
|
524
541
|
async getGenerators(colonyName, count = 100) {
|
|
525
542
|
const msg = {
|
|
@@ -584,6 +601,22 @@ var ColoniesClient = class {
|
|
|
584
601
|
};
|
|
585
602
|
return this.sendRPC(this.createRPCMsg(msg));
|
|
586
603
|
}
|
|
604
|
+
async getFile(colonyName, options) {
|
|
605
|
+
const msg = {
|
|
606
|
+
msgtype: "getfilemsg",
|
|
607
|
+
colonyname: colonyName
|
|
608
|
+
};
|
|
609
|
+
if ("fileId" in options) {
|
|
610
|
+
msg.fileid = options.fileId;
|
|
611
|
+
} else {
|
|
612
|
+
msg.name = options.name;
|
|
613
|
+
msg.label = options.label;
|
|
614
|
+
if (options.latest !== void 0) {
|
|
615
|
+
msg.latest = options.latest;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
return this.sendRPC(this.createRPCMsg(msg));
|
|
619
|
+
}
|
|
587
620
|
// ==================== Attribute Methods ====================
|
|
588
621
|
async addAttribute(attribute) {
|
|
589
622
|
const msg = {
|
|
@@ -879,6 +912,21 @@ var ColoniesClient = class {
|
|
|
879
912
|
};
|
|
880
913
|
return this.sendRPC(this.createRPCMsg(msg));
|
|
881
914
|
}
|
|
915
|
+
/**
|
|
916
|
+
* Get the history of changes for a specific blueprint
|
|
917
|
+
* @param blueprintId - ID of the blueprint
|
|
918
|
+
* @param limit - Optional limit on number of history entries to retrieve
|
|
919
|
+
*/
|
|
920
|
+
async getBlueprintHistory(blueprintId, limit) {
|
|
921
|
+
const msg = {
|
|
922
|
+
msgtype: "getblueprinthistorymsg",
|
|
923
|
+
blueprintid: blueprintId
|
|
924
|
+
};
|
|
925
|
+
if (limit !== void 0) {
|
|
926
|
+
msg.limit = limit;
|
|
927
|
+
}
|
|
928
|
+
return this.sendRPC(this.createRPCMsg(msg));
|
|
929
|
+
}
|
|
882
930
|
/**
|
|
883
931
|
* Subscribe to process state changes using WebSocket
|
|
884
932
|
* Use this to wait for a process to be assigned (RUNNING state) before subscribing to channels
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/crypto.ts","../src/client.ts"],"sourcesContent":["/**\n * ColonyOS Crypto implementation\n * Ported from pycolonies/crypto.py\n * Based on eth-utils and eth-keys (MIT-licensed)\n */\n\nimport { sha3_256 } from '@noble/hashes/sha3';\nimport { sha256 } from '@noble/hashes/sha256';\nimport { hmac } from '@noble/hashes/hmac';\nimport { bytesToHex, hexToBytes, randomBytes } from '@noble/hashes/utils';\n\n// ============== secp256k1 Curve Parameters ==============\n\nconst A = 0n;\nconst N = 115792089237316195423570985008687907852837564279074904382605163141518161494337n;\nconst Gx = 55066263022277343669578718895168534326250603453777594175500187360389116729240n;\nconst Gy = 32670510020758816978083085130507043184471273380659243275938904335757337482424n;\nconst G: [bigint, bigint] = [Gx, Gy];\nconst P = 2n ** 256n - 2n ** 32n - 977n;\n\ntype Point = [bigint, bigint];\ntype JacobianPoint = [bigint, bigint, bigint];\n\n// ============== Utility Functions ==============\n\nfunction pad32(value: Uint8Array): Uint8Array {\n if (value.length >= 32) return value.slice(0, 32);\n const padded = new Uint8Array(32);\n padded.set(value, 32 - value.length);\n return padded;\n}\n\nfunction intToBigEndian(value: bigint): Uint8Array {\n if (value === 0n) return new Uint8Array([0]);\n const hex = value.toString(16);\n const paddedHex = hex.length % 2 ? '0' + hex : hex;\n return hexToBytes(paddedHex);\n}\n\nfunction bigEndianToInt(value: Uint8Array): bigint {\n if (value.length === 0) return 0n;\n return BigInt('0x' + bytesToHex(value));\n}\n\n// ============== Elliptic Curve Math ==============\n\nfunction inv(a: bigint, n: bigint): bigint {\n if (a === 0n) return 0n;\n let lm = 1n, hm = 0n;\n let low = ((a % n) + n) % n, high = n;\n while (low > 1n) {\n const r = high / low;\n const nm = hm - lm * r;\n const newVal = high - low * r;\n hm = lm;\n high = low;\n lm = nm;\n low = newVal;\n }\n return ((lm % n) + n) % n;\n}\n\nfunction toJacobian(p: Point): JacobianPoint {\n return [p[0], p[1], 1n];\n}\n\nfunction fromJacobian(p: JacobianPoint): Point {\n const z = inv(p[2], P);\n const z2 = (z * z) % P;\n const z3 = (z2 * z) % P;\n return [((p[0] * z2) % P + P) % P, ((p[1] * z3) % P + P) % P];\n}\n\nfunction jacobianDouble(p: JacobianPoint): JacobianPoint {\n if (p[1] === 0n) return [0n, 0n, 0n];\n const ysq = (p[1] ** 2n) % P;\n const S = (4n * p[0] * ysq) % P;\n const M = (3n * p[0] ** 2n + A * p[2] ** 4n) % P;\n const nx = ((M ** 2n - 2n * S) % P + P) % P;\n const ny = ((M * (S - nx) - 8n * ysq ** 2n) % P + P) % P;\n const nz = (2n * p[1] * p[2]) % P;\n return [nx, ny, nz];\n}\n\nfunction jacobianAdd(p: JacobianPoint, q: JacobianPoint): JacobianPoint {\n if (p[1] === 0n) return q;\n if (q[1] === 0n) return p;\n\n const U1 = (p[0] * q[2] ** 2n) % P;\n const U2 = (q[0] * p[2] ** 2n) % P;\n const S1 = (p[1] * q[2] ** 3n) % P;\n const S2 = (q[1] * p[2] ** 3n) % P;\n\n if (U1 === U2) {\n if (S1 !== S2) return [0n, 0n, 1n];\n return jacobianDouble(p);\n }\n\n const H = ((U2 - U1) % P + P) % P;\n const R = ((S2 - S1) % P + P) % P;\n const H2 = (H * H) % P;\n const H3 = (H * H2) % P;\n const U1H2 = (U1 * H2) % P;\n const nx = ((R ** 2n - H3 - 2n * U1H2) % P + P) % P;\n const ny = ((R * (U1H2 - nx) - S1 * H3) % P + P) % P;\n const nz = (H * p[2] * q[2]) % P;\n\n return [nx, ny, nz];\n}\n\nfunction jacobianMultiply(a: JacobianPoint, n: bigint): JacobianPoint {\n if (a[1] === 0n || n === 0n) return [0n, 0n, 1n];\n if (n === 1n) return a;\n if (n < 0n || n >= N) return jacobianMultiply(a, ((n % N) + N) % N);\n if (n % 2n === 0n) {\n return jacobianDouble(jacobianMultiply(a, n / 2n));\n } else {\n return jacobianAdd(jacobianDouble(jacobianMultiply(a, n / 2n)), a);\n }\n}\n\nfunction fastMultiply(a: Point, n: bigint): Point {\n return fromJacobian(jacobianMultiply(toJacobian(a), n));\n}\n\nfunction encodeRawPublicKey(rawPublicKey: Point): Uint8Array {\n const left = pad32(intToBigEndian(rawPublicKey[0]));\n const right = pad32(intToBigEndian(rawPublicKey[1]));\n const result = new Uint8Array(64);\n result.set(left, 0);\n result.set(right, 32);\n return result;\n}\n\nfunction privateKeyToPublicKey(privateKeyBytes: Uint8Array): Uint8Array {\n const privateKeyAsNum = bigEndianToInt(privateKeyBytes);\n if (privateKeyAsNum >= N) {\n throw new Error('Invalid private key');\n }\n const rawPublicKey = fastMultiply(G, privateKeyAsNum);\n return encodeRawPublicKey(rawPublicKey);\n}\n\n// ============== ECDSA Signing ==============\n\nfunction deterministicGenerateK(msgHash: Uint8Array, privateKeyBytes: Uint8Array): bigint {\n const v0 = new Uint8Array(32).fill(0x01);\n const k0 = new Uint8Array(32).fill(0x00);\n\n // k1 = HMAC(k0, v0 || 0x00 || priv || hash)\n const data1 = new Uint8Array(v0.length + 1 + privateKeyBytes.length + msgHash.length);\n data1.set(v0, 0);\n data1[v0.length] = 0x00;\n data1.set(privateKeyBytes, v0.length + 1);\n data1.set(msgHash, v0.length + 1 + privateKeyBytes.length);\n const k1 = hmac(sha256, k0, data1);\n\n // v1 = HMAC(k1, v0)\n const v1 = hmac(sha256, k1, v0);\n\n // k2 = HMAC(k1, v1 || 0x01 || priv || hash)\n const data2 = new Uint8Array(v1.length + 1 + privateKeyBytes.length + msgHash.length);\n data2.set(v1, 0);\n data2[v1.length] = 0x01;\n data2.set(privateKeyBytes, v1.length + 1);\n data2.set(msgHash, v1.length + 1 + privateKeyBytes.length);\n const k2 = hmac(sha256, k1, data2);\n\n // v2 = HMAC(k2, v1)\n const v2 = hmac(sha256, k2, v1);\n\n // kb = HMAC(k2, v2)\n const kb = hmac(sha256, k2, v2);\n return bigEndianToInt(kb);\n}\n\nfunction ecdsaRawSign(msgHash: Uint8Array, privateKeyBytes: Uint8Array): [number, bigint, bigint] {\n const z = bigEndianToInt(msgHash);\n const k = deterministicGenerateK(msgHash, privateKeyBytes);\n\n const [r, y] = fastMultiply(G, k);\n const privKeyNum = bigEndianToInt(privateKeyBytes);\n const sRaw = (inv(k, N) * (z + r * privKeyNum)) % N;\n\n const v = 27 + Number((y % 2n) ^ (sRaw * 2n < N ? 0n : 1n));\n const s = sRaw * 2n < N ? sRaw : N - sRaw;\n\n return [v - 27, r, s];\n}\n\n// ============== Exported Functions ==============\n\n/**\n * Generate a new random private key\n * @returns Hex-encoded private key (64 characters)\n */\nexport function generatePrivateKey(): string {\n const randomData = randomBytes(32);\n const hash = sha3_256(randomData);\n return bytesToHex(hash);\n}\n\n/**\n * Derive the public ID from a private key\n * Uses SHA3-256 hash of \"04\" + hex(publicKey)\n * @param privateKey - Hex-encoded private key\n * @returns Hex-encoded ID (64 characters)\n */\nexport function deriveId(privateKey: string): string {\n const privateKeyBytes = hexToBytes(privateKey);\n const publicKey = privateKeyToPublicKey(privateKeyBytes);\n const publicKeyHex = '04' + bytesToHex(publicKey);\n\n // Hash the string representation, not the bytes\n const encoder = new TextEncoder();\n const hash = sha3_256(encoder.encode(publicKeyHex));\n\n return bytesToHex(hash);\n}\n\n/**\n * Sign a message with a private key\n * @param message - Message to sign\n * @param privateKey - Hex-encoded private key\n * @returns Hex-encoded signature (130 characters: r + s + v)\n */\nexport function sign(message: string, privateKey: string): string {\n const privateKeyBytes = hexToBytes(privateKey);\n\n // Hash message with SHA3-256\n const encoder = new TextEncoder();\n const msgHash = sha3_256(encoder.encode(message));\n\n const [v, r, s] = ecdsaRawSign(msgHash, privateKeyBytes);\n\n // Format: r (32 bytes) + s (32 bytes) + v (1 byte)\n const vBytes = new Uint8Array([v]);\n const rBytes = pad32(intToBigEndian(r));\n const sBytes = pad32(intToBigEndian(s));\n\n const signature = new Uint8Array(65);\n signature.set(rBytes, 0);\n signature.set(sBytes, 32);\n signature.set(vBytes, 64);\n\n return bytesToHex(signature);\n}\n\n/**\n * Crypto utility class for convenience\n */\nexport class Crypto {\n generatePrivateKey(): string {\n return generatePrivateKey();\n }\n\n id(privateKey: string): string {\n return deriveId(privateKey);\n }\n\n sign(message: string, privateKey: string): string {\n return sign(message, privateKey);\n }\n}\n\n// Export internal functions for testing\nexport const _internal = {\n jacobianAdd,\n jacobianDouble,\n fastMultiply,\n pad32,\n intToBigEndian,\n bigEndianToInt,\n};\n","/**\n * ColonyOS Client\n * Ported from colonyspace/aila/src/lib/api/colony.ts\n */\n\nimport { Crypto } from './crypto';\n\n// Helper function to decode base64 payload with proper UTF-8 handling\nfunction decodeBase64Utf8(base64: string): string {\n const binaryStr = atob(base64);\n const bytes = new Uint8Array(binaryStr.length);\n for (let i = 0; i < binaryStr.length; i++) {\n bytes[i] = binaryStr.charCodeAt(i);\n }\n return new TextDecoder('utf-8').decode(bytes);\n}\n\n// Helper function to encode string to base64 with proper UTF-8 handling\nfunction encodeBase64Utf8(str: string): string {\n const utf8Bytes = new TextEncoder().encode(str);\n const binaryStr = String.fromCharCode(...utf8Bytes);\n return btoa(binaryStr);\n}\n\nexport interface ColoniesClientConfig {\n host: string;\n port: number;\n tls?: boolean;\n}\n\nexport interface RPCMessage {\n payloadtype: string;\n payload: string;\n signature: string;\n}\n\nexport interface FunctionSpec {\n nodename?: string;\n funcname: string;\n args?: any[];\n kwargs?: Record<string, any>;\n priority?: number;\n maxwaittime?: number;\n maxexectime?: number;\n maxretries?: number;\n conditions?: {\n colonyname?: string;\n executornames?: string[];\n executortype?: string;\n dependencies?: string[];\n nodes?: number;\n cpu?: string;\n processes?: number;\n processespernode?: number;\n mem?: string;\n storage?: string;\n gpu?: { name?: string; mem?: string; count?: number; nodecount?: number };\n walltime?: number;\n };\n label?: string;\n fs?: any;\n env?: Record<string, string>;\n channels?: string[];\n}\n\nexport enum ProcessState {\n WAITING = 0,\n RUNNING = 1,\n SUCCESS = 2,\n FAILED = 3,\n}\n\nexport class ColoniesClient {\n private host: string;\n private port: number;\n private tls: boolean;\n private crypto: Crypto;\n private privateKey: string | null = null;\n\n constructor(config: ColoniesClientConfig) {\n this.host = config.host;\n this.port = config.port;\n this.tls = config.tls ?? false;\n this.crypto = new Crypto();\n }\n\n setPrivateKey(privateKey: string): void {\n this.privateKey = privateKey;\n }\n\n private getBaseUrl(): string {\n const protocol = this.tls ? 'https' : 'http';\n return `${protocol}://${this.host}:${this.port}/api`;\n }\n\n private createRPCMsg(msg: any): RPCMessage {\n if (!this.privateKey) {\n throw new Error('Private key not set. Call setPrivateKey() first.');\n }\n\n const payload = encodeBase64Utf8(JSON.stringify(msg));\n const signature = this.crypto.sign(payload, this.privateKey);\n\n return {\n payloadtype: msg.msgtype,\n payload,\n signature,\n };\n }\n\n private async sendRPC(rpcMessage: RPCMessage): Promise<any> {\n const url = this.getBaseUrl();\n\n const response = await fetch(url, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(rpcMessage),\n });\n\n if (!response.ok) {\n const errorText = await response.text();\n let errorObj;\n try {\n errorObj = JSON.parse(errorText);\n } catch {\n throw new Error(`Request failed with status ${response.status}: ${response.statusText}`);\n }\n\n if (errorObj.payload) {\n try {\n const decodedPayload = decodeBase64Utf8(errorObj.payload);\n const decodedError = JSON.parse(decodedPayload);\n throw new Error(decodedError.message || JSON.stringify(decodedError));\n } catch (e) {\n if (e instanceof Error && e.message !== 'Request failed') {\n throw e;\n }\n }\n }\n throw new Error(JSON.stringify(errorObj));\n }\n\n const responseText = await response.text();\n if (!responseText || responseText.trim() === '') {\n throw new Error('Server returned empty response');\n }\n\n const rpcReplyMsg = JSON.parse(responseText);\n const msg = JSON.parse(decodeBase64Utf8(rpcReplyMsg.payload));\n\n if (rpcReplyMsg.error === true) {\n const errorMessage = typeof msg === 'object' && msg.message ? msg.message : JSON.stringify(msg);\n throw new Error(errorMessage);\n }\n\n return msg;\n }\n\n // ==================== Colony Methods ====================\n\n async getColonies(): Promise<any> {\n const msg = { msgtype: 'getcoloniesmsg' };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getStatistics(): Promise<any> {\n const msg = { msgtype: 'getstatisticsmsg' };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Add a new colony (requires server private key)\n * @param colony - Colony object with colonyid and name\n */\n async addColony(colony: { colonyid: string; name: string }): Promise<any> {\n const msg = {\n msgtype: 'addcolonymsg',\n colony,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Remove a colony (requires server private key)\n * @param colonyName - Name of the colony to remove\n */\n async removeColony(colonyName: string): Promise<any> {\n const msg = {\n msgtype: 'removecolonymsg',\n colonyname: colonyName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Executor Methods ====================\n\n async getExecutors(colonyName: string): Promise<any> {\n const msg = {\n msgtype: 'getexecutorsmsg',\n colonyname: colonyName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getExecutor(colonyName: string, executorName: string): Promise<any> {\n const msg = {\n msgtype: 'getexecutormsg',\n colonyname: colonyName,\n executorname: executorName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async addExecutor(executor: {\n executorid: string;\n executortype: string;\n executorname: string;\n colonyname: string;\n }): Promise<any> {\n const msg = {\n msgtype: 'addexecutormsg',\n executor,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async approveExecutor(colonyName: string, executorName: string): Promise<any> {\n const msg = {\n msgtype: 'approveexecutormsg',\n colonyname: colonyName,\n executorname: executorName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async removeExecutor(colonyName: string, executorName: string): Promise<any> {\n const msg = {\n msgtype: 'removeexecutormsg',\n colonyname: colonyName,\n executorname: executorName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Process Methods ====================\n\n async submitFunctionSpec(spec: FunctionSpec): Promise<any> {\n const msg = {\n msgtype: 'submitfuncspecmsg',\n spec,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getProcess(processId: string): Promise<any> {\n const msg = {\n msgtype: 'getprocessmsg',\n processid: processId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getProcesses(colonyName: string, count: number, state: ProcessState): Promise<any> {\n const msg = {\n msgtype: 'getprocessesmsg',\n colonyname: colonyName,\n count,\n state,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async removeProcess(processId: string): Promise<any> {\n const msg = {\n msgtype: 'removeprocessmsg',\n processid: processId,\n all: false,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async removeAllProcesses(colonyName: string, state: number = -1): Promise<any> {\n const msg = {\n msgtype: 'removeallprocessesmsg',\n colonyname: colonyName,\n state,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async assign(colonyName: string, timeout: number, executorPrvKey: string): Promise<any> {\n // Temporarily set the executor private key for this operation\n const originalKey = this.privateKey;\n this.setPrivateKey(executorPrvKey);\n\n try {\n const msg = {\n msgtype: 'assignprocessmsg',\n colonyname: colonyName,\n timeout,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n } finally {\n if (originalKey) {\n this.setPrivateKey(originalKey);\n }\n }\n }\n\n async closeProcess(processId: string, output: string[]): Promise<any> {\n const msg = {\n msgtype: 'closesuccessfulmsg',\n processid: processId,\n out: output,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async failProcess(processId: string, errors: string[]): Promise<any> {\n const msg = {\n msgtype: 'closefailedmsg',\n processid: processId,\n errors,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Workflow Methods ====================\n\n async submitWorkflowSpec(workflowSpec: {\n colonyname: string;\n functionspecs: FunctionSpec[];\n }): Promise<any> {\n const msg = {\n msgtype: 'submitworkflowspecmsg',\n spec: workflowSpec,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getProcessGraph(processGraphId: string): Promise<any> {\n const msg = {\n msgtype: 'getprocessgraphmsg',\n processgraphid: processGraphId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getProcessGraphs(colonyName: string, count: number, state?: ProcessState): Promise<any> {\n const msg: any = {\n msgtype: 'getprocessgraphsmsg',\n colonyname: colonyName,\n count,\n };\n if (state !== undefined) {\n msg.state = state;\n }\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async removeProcessGraph(processGraphId: string): Promise<any> {\n const msg = {\n msgtype: 'removeprocessgraphmsg',\n processgraphid: processGraphId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async removeAllProcessGraphs(colonyName: string, state?: ProcessState): Promise<any> {\n const msg: any = {\n msgtype: 'removeallprocessgraphsmsg',\n colonyname: colonyName,\n };\n if (state !== undefined) {\n msg.state = state;\n }\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Log Methods ====================\n\n async addLog(processId: string, message: string, executorPrvKey: string): Promise<any> {\n const originalKey = this.privateKey;\n this.setPrivateKey(executorPrvKey);\n\n try {\n const msg = {\n msgtype: 'addlogmsg',\n processid: processId,\n message,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n } finally {\n if (originalKey) {\n this.setPrivateKey(originalKey);\n }\n }\n }\n\n async getLogs(colonyName: string, processId: string, executorName: string, count: number = 100, since: number = 0): Promise<any> {\n const msg = {\n msgtype: 'getlogsmsg',\n colonyname: colonyName,\n processid: processId,\n executorname: executorName,\n count,\n since,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Function Methods ====================\n\n async getFunctions(executorName: string, colonyName: string): Promise<any> {\n const msg = {\n msgtype: 'getfunctionsmsg',\n executorname: executorName,\n colonyname: colonyName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Cron Methods ====================\n\n async getCrons(colonyName: string, count: number = 100): Promise<any> {\n const msg = {\n msgtype: 'getcronsmsg',\n colonyname: colonyName,\n count,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getCron(cronId: string): Promise<any> {\n const msg = {\n msgtype: 'getcronmsg',\n cronid: cronId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async addCron(cronSpec: any): Promise<any> {\n const msg = {\n msgtype: 'addcronmsg',\n cron: cronSpec,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async removeCron(cronId: string): Promise<any> {\n const msg = {\n msgtype: 'removecronmsg',\n cronid: cronId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Generator Methods ====================\n\n async getGenerators(colonyName: string, count: number = 100): Promise<any> {\n const msg = {\n msgtype: 'getgeneratorsmsg',\n colonyname: colonyName,\n count,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getGenerator(generatorId: string): Promise<any> {\n const msg = {\n msgtype: 'getgeneratormsg',\n generatorid: generatorId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async addGenerator(generatorSpec: any): Promise<any> {\n const msg = {\n msgtype: 'addgeneratormsg',\n generator: generatorSpec,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== User Methods ====================\n\n async getUsers(colonyName: string): Promise<any> {\n const msg = {\n msgtype: 'getusersmsg',\n colonyname: colonyName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async addUser(user: {\n colonyname: string;\n userid: string;\n name: string;\n email: string;\n phone: string;\n }): Promise<any> {\n const msg = {\n msgtype: 'addusermsg',\n user,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async removeUser(colonyName: string, name: string): Promise<any> {\n const msg = {\n msgtype: 'removeusermsg',\n colonyname: colonyName,\n name,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== File Methods ====================\n\n async getFileLabels(colonyName: string, name: string = '', exact: boolean = false): Promise<any> {\n const msg = {\n msgtype: 'getfilelabelsmsg',\n colonyname: colonyName,\n name,\n exact,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getFiles(colonyName: string, label: string): Promise<any> {\n const msg = {\n msgtype: 'getfilesmsg',\n colonyname: colonyName,\n label,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Attribute Methods ====================\n\n async addAttribute(attribute: {\n targetid: string;\n targetcolonyname: string;\n targetprocessgraphid: string;\n attributetype: number;\n key: string;\n value: string;\n }): Promise<any> {\n const msg = {\n msgtype: 'addattributemsg',\n attribute,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getAttribute(attributeId: string): Promise<any> {\n const msg = {\n msgtype: 'getattributemsg',\n attributeid: attributeId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Channel Methods ====================\n\n /**\n * Append a message to a process channel\n * @param processId - ID of the process\n * @param channelName - Name of the channel\n * @param sequence - Client-assigned sequence number\n * @param inReplyTo - Sequence number this message is replying to (0 if not a reply)\n * @param payload - Message content (string or Uint8Array)\n */\n async channelAppend(\n processId: string,\n channelName: string,\n sequence: number,\n inReplyTo: number,\n payload: string | Uint8Array\n ): Promise<any> {\n let payloadBytes: number[];\n if (typeof payload === 'string') {\n const encoder = new TextEncoder();\n payloadBytes = Array.from(encoder.encode(payload));\n } else {\n payloadBytes = Array.from(payload);\n }\n\n const msg = {\n msgtype: 'channelappendmsg',\n processid: processId,\n name: channelName,\n sequence: sequence,\n inreplyto: inReplyTo,\n payload: payloadBytes,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Read messages from a process channel\n * @param processId - ID of the process\n * @param channelName - Name of the channel\n * @param afterSeq - Read messages after this sequence number (use 0 for all)\n * @param limit - Maximum number of messages to return (0 for no limit)\n */\n async channelRead(\n processId: string,\n channelName: string,\n afterSeq: number,\n limit: number\n ): Promise<any[]> {\n const msg = {\n msgtype: 'channelreadmsg',\n processid: processId,\n name: channelName,\n afterseq: afterSeq,\n limit: limit,\n };\n\n const response = await this.sendRPC(this.createRPCMsg(msg));\n\n // Response is an array of channel entries, decode payload bytes if needed\n if (Array.isArray(response)) {\n return response.map((entry) => ({\n ...entry,\n payload:\n typeof entry.payload === 'string'\n ? (() => {\n try {\n const binaryStr = atob(entry.payload);\n const bytes = new Uint8Array(binaryStr.length);\n for (let i = 0; i < binaryStr.length; i++) {\n bytes[i] = binaryStr.charCodeAt(i);\n }\n return new TextDecoder('utf-8').decode(bytes);\n } catch {\n return entry.payload;\n }\n })()\n : Array.isArray(entry.payload)\n ? new TextDecoder('utf-8').decode(new Uint8Array(entry.payload))\n : entry.payload,\n }));\n }\n\n return response || [];\n }\n\n /**\n * Subscribe to a channel using WebSocket for real-time updates\n * @param processId - ID of the process\n * @param channelName - Name of the channel\n * @param afterSeq - Start reading after this sequence number\n * @param timeout - Timeout in seconds for the subscription\n * @param onMessage - Callback for new messages\n * @param onError - Callback for errors\n * @param onClose - Callback when connection closes\n * @returns WebSocket instance for cleanup\n */\n subscribeChannel(\n processId: string,\n channelName: string,\n afterSeq: number,\n timeout: number,\n onMessage: (entries: any[]) => void,\n onError: (error: Error) => void,\n onClose: () => void\n ): WebSocket {\n if (!this.privateKey) {\n throw new Error('Private key not set. Call setPrivateKey() first.');\n }\n\n const wsProtocol = this.tls ? 'wss' : 'ws';\n const wsUrl = `${wsProtocol}://${this.host}:${this.port}/pubsub`;\n\n const ws = new WebSocket(wsUrl);\n\n ws.onopen = () => {\n const msg = {\n msgtype: 'subscribechannelmsg',\n processid: processId,\n name: channelName,\n afterseq: afterSeq,\n timeout: timeout,\n };\n\n const rpcMsg = this.createRPCMsg(msg);\n ws.send(JSON.stringify(rpcMsg));\n };\n\n ws.onmessage = (event) => {\n try {\n const rpcReply = JSON.parse(event.data as string);\n\n if (rpcReply.error) {\n const errorPayload = JSON.parse(decodeBase64Utf8(rpcReply.payload));\n onError(new Error(errorPayload.message || 'WebSocket error'));\n return;\n }\n\n const data = JSON.parse(decodeBase64Utf8(rpcReply.payload));\n\n if (Array.isArray(data)) {\n const entries = data.map((entry) => ({\n ...entry,\n payload:\n typeof entry.payload === 'string'\n ? (() => {\n try {\n const binaryStr = atob(entry.payload);\n const bytes = new Uint8Array(binaryStr.length);\n for (let i = 0; i < binaryStr.length; i++) {\n bytes[i] = binaryStr.charCodeAt(i);\n }\n return new TextDecoder('utf-8').decode(bytes);\n } catch {\n return entry.payload;\n }\n })()\n : Array.isArray(entry.payload)\n ? new TextDecoder('utf-8').decode(new Uint8Array(entry.payload))\n : entry.payload,\n }));\n\n const errorEntry = entries.find((e) => e.error);\n if (errorEntry) {\n onError(new Error(errorEntry.error));\n return;\n }\n\n onMessage(entries);\n }\n } catch (err) {\n onError(err instanceof Error ? err : new Error(String(err)));\n }\n };\n\n ws.onerror = () => {\n onError(new Error('WebSocket connection error'));\n };\n\n ws.onclose = () => {\n onClose();\n };\n\n return ws;\n }\n\n // ==================== Blueprint Definition Methods ====================\n\n /**\n * Add a blueprint definition\n * @param definition - Blueprint definition object\n */\n async addBlueprintDefinition(definition: any): Promise<any> {\n const msg = {\n msgtype: 'addblueprintdefinitionmsg',\n blueprintdefinition: definition,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Get a blueprint definition by name\n * @param colonyName - Name of the colony\n * @param name - Name of the blueprint definition\n */\n async getBlueprintDefinition(colonyName: string, name: string): Promise<any> {\n const msg = {\n msgtype: 'getblueprintdefinitionmsg',\n colonyname: colonyName,\n name,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Get all blueprint definitions in a colony\n * @param colonyName - Name of the colony\n */\n async getBlueprintDefinitions(colonyName: string): Promise<any[]> {\n const msg = {\n msgtype: 'getblueprintdefinitionsmsg',\n colonyname: colonyName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Remove a blueprint definition\n * @param colonyName - Name of the colony (namespace)\n * @param name - Name of the blueprint definition to remove\n */\n async removeBlueprintDefinition(colonyName: string, name: string): Promise<void> {\n const msg = {\n msgtype: 'removeblueprintdefinitionmsg',\n namespace: colonyName,\n name,\n };\n await this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Blueprint Methods ====================\n\n /**\n * Add a blueprint instance\n * @param blueprint - Blueprint object\n */\n async addBlueprint(blueprint: any): Promise<any> {\n const msg = {\n msgtype: 'addblueprintmsg',\n blueprint,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Get a blueprint by name\n * @param colonyName - Name of the colony (namespace)\n * @param name - Name of the blueprint\n */\n async getBlueprint(colonyName: string, name: string): Promise<any> {\n const msg = {\n msgtype: 'getblueprintmsg',\n namespace: colonyName,\n name,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Get blueprints in a colony, optionally filtered by kind and location\n * @param colonyName - Name of the colony (namespace)\n * @param kind - Optional kind filter\n * @param location - Optional location filter\n */\n async getBlueprints(colonyName: string, kind?: string, location?: string): Promise<any[]> {\n const msg: any = {\n msgtype: 'getblueprintsmsg',\n namespace: colonyName,\n };\n if (kind) msg.kind = kind;\n if (location) msg.locationname = location;\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Update an existing blueprint\n * @param blueprint - Updated blueprint object\n * @param forceGeneration - Force generation bump even if spec unchanged\n */\n async updateBlueprint(blueprint: any, forceGeneration: boolean = false): Promise<any> {\n const msg = {\n msgtype: 'updateblueprintmsg',\n blueprint,\n forcegeneration: forceGeneration,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Remove a blueprint\n * @param colonyName - Name of the colony (namespace)\n * @param name - Name of the blueprint to remove\n */\n async removeBlueprint(colonyName: string, name: string): Promise<void> {\n const msg = {\n msgtype: 'removeblueprintmsg',\n namespace: colonyName,\n name,\n };\n await this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Update blueprint status (current state)\n * @param colonyName - Name of the colony\n * @param name - Name of the blueprint\n * @param status - Status object representing current state\n */\n async updateBlueprintStatus(colonyName: string, name: string, status: any): Promise<void> {\n const msg = {\n msgtype: 'updateblueprintstatusmsg',\n colonyname: colonyName,\n blueprintname: name,\n status,\n };\n await this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Trigger reconciliation for a blueprint\n * @param colonyName - Name of the colony (namespace)\n * @param name - Name of the blueprint\n * @param force - Force reconciliation even if no changes detected\n */\n async reconcileBlueprint(colonyName: string, name: string, force: boolean = false): Promise<any> {\n const msg = {\n msgtype: 'reconcileblueprintmsg',\n namespace: colonyName,\n name,\n force,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Subscribe to process state changes using WebSocket\n * Use this to wait for a process to be assigned (RUNNING state) before subscribing to channels\n * @param colonyName - Name of the colony\n * @param processId - ID of the process to watch\n * @param state - Target state to wait for (0=WAITING, 1=RUNNING, 2=SUCCESS, 3=FAILED)\n * @param timeout - Timeout in seconds for the subscription\n * @param onProcess - Callback when process reaches the target state\n * @param onError - Callback for errors\n * @param onClose - Callback when connection closes\n * @returns WebSocket instance for cleanup\n */\n subscribeProcess(\n colonyName: string,\n processId: string,\n state: number,\n timeout: number,\n onProcess: (process: any) => void,\n onError: (error: Error) => void,\n onClose: () => void\n ): WebSocket {\n if (!this.privateKey) {\n throw new Error('Private key not set. Call setPrivateKey() first.');\n }\n\n const wsProtocol = this.tls ? 'wss' : 'ws';\n const wsUrl = `${wsProtocol}://${this.host}:${this.port}/pubsub`;\n\n const ws = new WebSocket(wsUrl);\n\n ws.onopen = () => {\n const msg = {\n msgtype: 'subscribeprocessmsg',\n colonyname: colonyName,\n processid: processId,\n executortype: '',\n state: state,\n timeout: timeout,\n };\n\n const rpcMsg = this.createRPCMsg(msg);\n ws.send(JSON.stringify(rpcMsg));\n };\n\n ws.onmessage = (event) => {\n try {\n const rpcReply = JSON.parse(event.data as string);\n\n if (rpcReply.error) {\n const errorPayload = JSON.parse(decodeBase64Utf8(rpcReply.payload));\n onError(new Error(errorPayload.message || 'WebSocket error'));\n return;\n }\n\n const process = JSON.parse(decodeBase64Utf8(rpcReply.payload));\n onProcess(process);\n } catch (err) {\n onError(err instanceof Error ? err : new Error(String(err)));\n }\n };\n\n ws.onerror = () => {\n onError(new Error('WebSocket connection error'));\n };\n\n ws.onclose = () => {\n onClose();\n };\n\n return ws;\n }\n}\n"],"mappings":";AAMA,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,SAAS,YAAY;AACrB,SAAS,YAAY,YAAY,mBAAmB;AAIpD,IAAM,IAAI;AACV,IAAM,IAAI;AACV,IAAM,KAAK;AACX,IAAM,KAAK;AACX,IAAM,IAAsB,CAAC,IAAI,EAAE;AACnC,IAAM,IAAI,MAAM,OAAO,MAAM,MAAM;AAOnC,SAAS,MAAM,OAA+B;AAC5C,MAAI,MAAM,UAAU,GAAI,QAAO,MAAM,MAAM,GAAG,EAAE;AAChD,QAAM,SAAS,IAAI,WAAW,EAAE;AAChC,SAAO,IAAI,OAAO,KAAK,MAAM,MAAM;AACnC,SAAO;AACT;AAEA,SAAS,eAAe,OAA2B;AACjD,MAAI,UAAU,GAAI,QAAO,IAAI,WAAW,CAAC,CAAC,CAAC;AAC3C,QAAM,MAAM,MAAM,SAAS,EAAE;AAC7B,QAAM,YA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AI,UAAU,KAAK;AAE9B,OAAG,SAAS,MAAM;AAChB,YAAM,MAAM;AAAA,QACV,SAAS;AAAA,QACT,YAAY;AAAA,QACZ,WAAW;AAAA,QACX,cAAc;AAAA,QACd;AAAA,QACA;AAAA,MACF;AAEA,YAAM,SAAS,KAAK,aAAa,GAAG;AACpC,SAAG,KAAK,KAAK,UAAU,MAAM,CAAC;AAAA,IAChC;AAEA,OAAG,YAAY,CAAC,UAAU;AACxB,UAAI;AACF,cAAM,WAAW,KAAK,MAAM,MAAM,IAAc;AAEhD,YAAI,SAAS,OAAO;AAClB,gBAAM,eAAe,KAAK,MAAM,iBAAiB,SAAS,OAAO,CAAC;AAClE,kBAAQ,IAAI,MAAM,aAAa,WAAW,iBAAiB,CAAC;AAC5D;AAAA,QACF;AAEA,cAAM,UAAU,KAAK,MAAM,iBAAiB,SAAS,OAAO,CAAC;AAC7D,kBAAU,OAAO;AAAA,MACnB,SAAS,KAAK;AACZ,gBAAQ,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC,CAAC;AAAA,MAC7D;AAAA,IACF;AAEA,OAAG,UAAU,MAAM;AACjB,cAAQ,IAAI,MAAM,4BAA4B,CAAC;AAAA,IACjD;AAEA,OAAG,UAAU,MAAM;AACjB,cAAQ;AAAA,IACV;AAEA,WAAO;AAAA,EACT;AACF;","names":["ProcessState"]}
|
|
1
|
+
{"version":3,"sources":["../src/crypto.ts","../src/client.ts"],"sourcesContent":["/**\n * ColonyOS Crypto implementation\n * Ported from pycolonies/crypto.py\n * Based on eth-utils and eth-keys (MIT-licensed)\n */\n\nimport { sha3_256 } from '@noble/hashes/sha3';\nimport { sha256 } from '@noble/hashes/sha256';\nimport { hmac } from '@noble/hashes/hmac';\nimport { bytesToHex, hexToBytes, randomBytes } from '@noble/hashes/utils';\n\n// ============== secp256k1 Curve Parameters ==============\n\nconst A = 0n;\nconst N = 115792089237316195423570985008687907852837564279074904382605163141518161494337n;\nconst Gx = 55066263022277343669578718895168534326250603453777594175500187360389116729240n;\nconst Gy = 32670510020758816978083085130507043184471273380659243275938904335757337482424n;\nconst G: [bigint, bigint] = [Gx, Gy];\nconst P = 2n ** 256n - 2n ** 32n - 977n;\n\ntype Point = [bigint, bigint];\ntype JacobianPoint = [bigint, bigint, bigint];\n\n// ============== Utility Functions ==============\n\nfunction pad32(value: Uint8Array): Uint8Array {\n if (value.length >= 32) return value.slice(0, 32);\n const padded = new Uint8Array(32);\n padded.set(value, 32 - value.length);\n return padded;\n}\n\nfunction intToBigEndian(value: bigint): Uint8Array {\n if (value === 0n) return new Uint8Array([0]);\n const hex = value.toString(16);\n const paddedHex = hex.length % 2 ? '0' + hex : hex;\n return hexToBytes(paddedHex);\n}\n\nfunction bigEndianToInt(value: Uint8Array): bigint {\n if (value.length === 0) return 0n;\n return BigInt('0x' + bytesToHex(value));\n}\n\n// ============== Elliptic Curve Math ==============\n\nfunction inv(a: bigint, n: bigint): bigint {\n if (a === 0n) return 0n;\n let lm = 1n, hm = 0n;\n let low = ((a % n) + n) % n, high = n;\n while (low > 1n) {\n const r = high / low;\n const nm = hm - lm * r;\n const newVal = high - low * r;\n hm = lm;\n high = low;\n lm = nm;\n low = newVal;\n }\n return ((lm % n) + n) % n;\n}\n\nfunction toJacobian(p: Point): JacobianPoint {\n return [p[0], p[1], 1n];\n}\n\nfunction fromJacobian(p: JacobianPoint): Point {\n const z = inv(p[2], P);\n const z2 = (z * z) % P;\n const z3 = (z2 * z) % P;\n return [((p[0] * z2) % P + P) % P, ((p[1] * z3) % P + P) % P];\n}\n\nfunction jacobianDouble(p: JacobianPoint): JacobianPoint {\n if (p[1] === 0n) return [0n, 0n, 0n];\n const ysq = (p[1] ** 2n) % P;\n const S = (4n * p[0] * ysq) % P;\n const M = (3n * p[0] ** 2n + A * p[2] ** 4n) % P;\n const nx = ((M ** 2n - 2n * S) % P + P) % P;\n const ny = ((M * (S - nx) - 8n * ysq ** 2n) % P + P) % P;\n const nz = (2n * p[1] * p[2]) % P;\n return [nx, ny, nz];\n}\n\nfunction jacobianAdd(p: JacobianPoint, q: JacobianPoint): JacobianPoint {\n if (p[1] === 0n) return q;\n if (q[1] === 0n) return p;\n\n const U1 = (p[0] * q[2] ** 2n) % P;\n const U2 = (q[0] * p[2] ** 2n) % P;\n const S1 = (p[1] * q[2] ** 3n) % P;\n const S2 = (q[1] * p[2] ** 3n) % P;\n\n if (U1 === U2) {\n if (S1 !== S2) return [0n, 0n, 1n];\n return jacobianDouble(p);\n }\n\n const H = ((U2 - U1) % P + P) % P;\n const R = ((S2 - S1) % P + P) % P;\n const H2 = (H * H) % P;\n const H3 = (H * H2) % P;\n const U1H2 = (U1 * H2) % P;\n const nx = ((R ** 2n - H3 - 2n * U1H2) % P + P) % P;\n const ny = ((R * (U1H2 - nx) - S1 * H3) % P + P) % P;\n const nz = (H * p[2] * q[2]) % P;\n\n return [nx, ny, nz];\n}\n\nfunction jacobianMultiply(a: JacobianPoint, n: bigint): JacobianPoint {\n if (a[1] === 0n || n === 0n) return [0n, 0n, 1n];\n if (n === 1n) return a;\n if (n < 0n || n >= N) return jacobianMultiply(a, ((n % N) + N) % N);\n if (n % 2n === 0n) {\n return jacobianDouble(jacobianMultiply(a, n / 2n));\n } else {\n return jacobianAdd(jacobianDouble(jacobianMultiply(a, n / 2n)), a);\n }\n}\n\nfunction fastMultiply(a: Point, n: bigint): Point {\n return fromJacobian(jacobianMultiply(toJacobian(a), n));\n}\n\nfunction encodeRawPublicKey(rawPublicKey: Point): Uint8Array {\n const left = pad32(intToBigEndian(rawPublicKey[0]));\n const right = pad32(intToBigEndian(rawPublicKey[1]));\n const result = new Uint8Array(64);\n result.set(left, 0);\n result.set(right, 32);\n return result;\n}\n\nfunction privateKeyToPublicKey(privateKeyBytes: Uint8Array): Uint8Array {\n const privateKeyAsNum = bigEndianToInt(privateKeyBytes);\n if (privateKeyAsNum >= N) {\n throw new Error('Invalid private key');\n }\n const rawPublicKey = fastMultiply(G, privateKeyAsNum);\n return encodeRawPublicKey(rawPublicKey);\n}\n\n// ============== ECDSA Signing ==============\n\nfunction deterministicGenerateK(msgHash: Uint8Array, privateKeyBytes: Uint8Array): bigint {\n const v0 = new Uint8Array(32).fill(0x01);\n const k0 = new Uint8Array(32).fill(0x00);\n\n // k1 = HMAC(k0, v0 || 0x00 || priv || hash)\n const data1 = new Uint8Array(v0.length + 1 + privateKeyBytes.length + msgHash.length);\n data1.set(v0, 0);\n data1[v0.length] = 0x00;\n data1.set(privateKeyBytes, v0.length + 1);\n data1.set(msgHash, v0.length + 1 + privateKeyBytes.length);\n const k1 = hmac(sha256, k0, data1);\n\n // v1 = HMAC(k1, v0)\n const v1 = hmac(sha256, k1, v0);\n\n // k2 = HMAC(k1, v1 || 0x01 || priv || hash)\n const data2 = new Uint8Array(v1.length + 1 + privateKeyBytes.length + msgHash.length);\n data2.set(v1, 0);\n data2[v1.length] = 0x01;\n data2.set(privateKeyBytes, v1.length + 1);\n data2.set(msgHash, v1.length + 1 + privateKeyBytes.length);\n const k2 = hmac(sha256, k1, data2);\n\n // v2 = HMAC(k2, v1)\n const v2 = hmac(sha256, k2, v1);\n\n // kb = HMAC(k2, v2)\n const kb = hmac(sha256, k2, v2);\n return bigEndianToInt(kb);\n}\n\nfunction ecdsaRawSign(msgHash: Uint8Array, privateKeyBytes: Uint8Array): [number, bigint, bigint] {\n const z = bigEndianToInt(msgHash);\n const k = deterministicGenerateK(msgHash, privateKeyBytes);\n\n const [r, y] = fastMultiply(G, k);\n const privKeyNum = bigEndianToInt(privateKeyBytes);\n const sRaw = (inv(k, N) * (z + r * privKeyNum)) % N;\n\n const v = 27 + Number((y % 2n) ^ (sRaw * 2n < N ? 0n : 1n));\n const s = sRaw * 2n < N ? sRaw : N - sRaw;\n\n return [v - 27, r, s];\n}\n\n// ============== Exported Functions ==============\n\n/**\n * Generate a new random private key\n * @returns Hex-encoded private key (64 characters)\n */\nexport function generatePrivateKey(): string {\n const randomData = randomBytes(32);\n const hash = sha3_256(randomData);\n return bytesToHex(hash);\n}\n\n/**\n * Derive the public ID from a private key\n * Uses SHA3-256 hash of \"04\" + hex(publicKey)\n * @param privateKey - Hex-encoded private key\n * @returns Hex-encoded ID (64 characters)\n */\nexport function deriveId(privateKey: string): string {\n const privateKeyBytes = hexToBytes(privateKey);\n const publicKey = privateKeyToPublicKey(privateKeyBytes);\n const publicKeyHex = '04' + bytesToHex(publicKey);\n\n // Hash the string representation, not the bytes\n const encoder = new TextEncoder();\n const hash = sha3_256(encoder.encode(publicKeyHex));\n\n return bytesToHex(hash);\n}\n\n/**\n * Sign a message with a private key\n * @param message - Message to sign\n * @param privateKey - Hex-encoded private key\n * @returns Hex-encoded signature (130 characters: r + s + v)\n */\nexport function sign(message: string, privateKey: string): string {\n const privateKeyBytes = hexToBytes(privateKey);\n\n // Hash message with SHA3-256\n const encoder = new TextEncoder();\n const msgHash = sha3_256(encoder.encode(message));\n\n const [v, r, s] = ecdsaRawSign(msgHash, privateKeyBytes);\n\n // Format: r (32 bytes) + s (32 bytes) + v (1 byte)\n const vBytes = new Uint8Array([v]);\n const rBytes = pad32(intToBigEndian(r));\n const sBytes = pad32(intToBigEndian(s));\n\n const signature = new Uint8Array(65);\n signature.set(rBytes, 0);\n signature.set(sBytes, 32);\n signature.set(vBytes, 64);\n\n return bytesToHex(signature);\n}\n\n/**\n * Crypto utility class for convenience\n */\nexport class Crypto {\n generatePrivateKey(): string {\n return generatePrivateKey();\n }\n\n id(privateKey: string): string {\n return deriveId(privateKey);\n }\n\n sign(message: string, privateKey: string): string {\n return sign(message, privateKey);\n }\n}\n\n// Export internal functions for testing\nexport const _internal = {\n jacobianAdd,\n jacobianDouble,\n fastMultiply,\n pad32,\n intToBigEndian,\n bigEndianToInt,\n};\n","/**\n * ColonyOS Client\n * Ported from colonyspace/aila/src/lib/api/colony.ts\n */\n\nimport { Crypto } from './crypto';\n\n// Helper function to decode base64 payload with proper UTF-8 handling\nfunction decodeBase64Utf8(base64: string): string {\n const binaryStr = atob(base64);\n const bytes = new Uint8Array(binaryStr.length);\n for (let i = 0; i < binaryStr.length; i++) {\n bytes[i] = binaryStr.charCodeAt(i);\n }\n return new TextDecoder('utf-8').decode(bytes);\n}\n\n// Helper function to encode string to base64 with proper UTF-8 handling\nfunction encodeBase64Utf8(str: string): string {\n const utf8Bytes = new TextEncoder().encode(str);\n const binaryStr = String.fromCharCode(...utf8Bytes);\n return btoa(binaryStr);\n}\n\nexport interface ColoniesClientConfig {\n host: string;\n port: number;\n tls?: boolean;\n}\n\nexport interface RPCMessage {\n payloadtype: string;\n payload: string;\n signature: string;\n}\n\nexport interface FunctionSpec {\n nodename?: string;\n funcname: string;\n args?: any[];\n kwargs?: Record<string, any>;\n priority?: number;\n maxwaittime?: number;\n maxexectime?: number;\n maxretries?: number;\n conditions?: {\n colonyname?: string;\n executornames?: string[];\n executortype?: string;\n dependencies?: string[];\n nodes?: number;\n cpu?: string;\n processes?: number;\n processespernode?: number;\n mem?: string;\n storage?: string;\n gpu?: { name?: string; mem?: string; count?: number; nodecount?: number };\n walltime?: number;\n };\n label?: string;\n fs?: any;\n env?: Record<string, string>;\n channels?: string[];\n}\n\nexport enum ProcessState {\n WAITING = 0,\n RUNNING = 1,\n SUCCESS = 2,\n FAILED = 3,\n}\n\nexport class ColoniesClient {\n private host: string;\n private port: number;\n private tls: boolean;\n private crypto: Crypto;\n private privateKey: string | null = null;\n\n constructor(config: ColoniesClientConfig) {\n this.host = config.host;\n this.port = config.port;\n this.tls = config.tls ?? false;\n this.crypto = new Crypto();\n }\n\n setPrivateKey(privateKey: string): void {\n this.privateKey = privateKey;\n }\n\n private getBaseUrl(): string {\n const protocol = this.tls ? 'https' : 'http';\n return `${protocol}://${this.host}:${this.port}/api`;\n }\n\n private createRPCMsg(msg: any): RPCMessage {\n if (!this.privateKey) {\n throw new Error('Private key not set. Call setPrivateKey() first.');\n }\n\n const payload = encodeBase64Utf8(JSON.stringify(msg));\n const signature = this.crypto.sign(payload, this.privateKey);\n\n return {\n payloadtype: msg.msgtype,\n payload,\n signature,\n };\n }\n\n private async sendRPC(rpcMessage: RPCMessage): Promise<any> {\n const url = this.getBaseUrl();\n\n const response = await fetch(url, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(rpcMessage),\n });\n\n if (!response.ok) {\n const errorText = await response.text();\n let errorObj;\n try {\n errorObj = JSON.parse(errorText);\n } catch {\n throw new Error(`Request failed with status ${response.status}: ${response.statusText}`);\n }\n\n if (errorObj.payload) {\n try {\n const decodedPayload = decodeBase64Utf8(errorObj.payload);\n const decodedError = JSON.parse(decodedPayload);\n throw new Error(decodedError.message || JSON.stringify(decodedError));\n } catch (e) {\n if (e instanceof Error && e.message !== 'Request failed') {\n throw e;\n }\n }\n }\n throw new Error(JSON.stringify(errorObj));\n }\n\n const responseText = await response.text();\n if (!responseText || responseText.trim() === '') {\n throw new Error('Server returned empty response');\n }\n\n const rpcReplyMsg = JSON.parse(responseText);\n const msg = JSON.parse(decodeBase64Utf8(rpcReplyMsg.payload));\n\n if (rpcReplyMsg.error === true) {\n const errorMessage = typeof msg === 'object' && msg.message ? msg.message : JSON.stringify(msg);\n throw new Error(errorMessage);\n }\n\n return msg;\n }\n\n // ==================== Colony Methods ====================\n\n async getColonies(): Promise<any> {\n const msg = { msgtype: 'getcoloniesmsg' };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getStatistics(): Promise<any> {\n const msg = { msgtype: 'getstatisticsmsg' };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Add a new colony (requires server private key)\n * @param colony - Colony object with colonyid and name\n */\n async addColony(colony: { colonyid: string; name: string }): Promise<any> {\n const msg = {\n msgtype: 'addcolonymsg',\n colony,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Remove a colony (requires server private key)\n * @param colonyName - Name of the colony to remove\n */\n async removeColony(colonyName: string): Promise<any> {\n const msg = {\n msgtype: 'removecolonymsg',\n colonyname: colonyName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Executor Methods ====================\n\n async getExecutors(colonyName: string): Promise<any> {\n const msg = {\n msgtype: 'getexecutorsmsg',\n colonyname: colonyName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getExecutor(colonyName: string, executorName: string): Promise<any> {\n const msg = {\n msgtype: 'getexecutormsg',\n colonyname: colonyName,\n executorname: executorName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async addExecutor(executor: {\n executorid: string;\n executortype: string;\n executorname: string;\n colonyname: string;\n }): Promise<any> {\n const msg = {\n msgtype: 'addexecutormsg',\n executor,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async approveExecutor(colonyName: string, executorName: string): Promise<any> {\n const msg = {\n msgtype: 'approveexecutormsg',\n colonyname: colonyName,\n executorname: executorName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async removeExecutor(colonyName: string, executorName: string): Promise<any> {\n const msg = {\n msgtype: 'removeexecutormsg',\n colonyname: colonyName,\n executorname: executorName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Process Methods ====================\n\n async submitFunctionSpec(spec: FunctionSpec): Promise<any> {\n const msg = {\n msgtype: 'submitfuncspecmsg',\n spec,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getProcess(processId: string): Promise<any> {\n const msg = {\n msgtype: 'getprocessmsg',\n processid: processId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getProcesses(colonyName: string, count: number, state: ProcessState): Promise<any> {\n const msg = {\n msgtype: 'getprocessesmsg',\n colonyname: colonyName,\n count,\n state,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async removeProcess(processId: string): Promise<any> {\n const msg = {\n msgtype: 'removeprocessmsg',\n processid: processId,\n all: false,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async removeAllProcesses(colonyName: string, state: number = -1): Promise<any> {\n const msg = {\n msgtype: 'removeallprocessesmsg',\n colonyname: colonyName,\n state,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async assign(colonyName: string, timeout: number, executorPrvKey: string): Promise<any> {\n // Temporarily set the executor private key for this operation\n const originalKey = this.privateKey;\n this.setPrivateKey(executorPrvKey);\n\n try {\n const msg = {\n msgtype: 'assignprocessmsg',\n colonyname: colonyName,\n timeout,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n } finally {\n if (originalKey) {\n this.setPrivateKey(originalKey);\n }\n }\n }\n\n async closeProcess(processId: string, output: string[]): Promise<any> {\n const msg = {\n msgtype: 'closesuccessfulmsg',\n processid: processId,\n out: output,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async failProcess(processId: string, errors: string[]): Promise<any> {\n const msg = {\n msgtype: 'closefailedmsg',\n processid: processId,\n errors,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Workflow Methods ====================\n\n async submitWorkflowSpec(workflowSpec: {\n colonyname: string;\n functionspecs: FunctionSpec[];\n }): Promise<any> {\n const msg = {\n msgtype: 'submitworkflowspecmsg',\n spec: workflowSpec,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getProcessGraph(processGraphId: string): Promise<any> {\n const msg = {\n msgtype: 'getprocessgraphmsg',\n processgraphid: processGraphId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getProcessGraphs(colonyName: string, count: number, state?: ProcessState): Promise<any> {\n const msg: any = {\n msgtype: 'getprocessgraphsmsg',\n colonyname: colonyName,\n count,\n };\n if (state !== undefined) {\n msg.state = state;\n }\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async removeProcessGraph(processGraphId: string): Promise<any> {\n const msg = {\n msgtype: 'removeprocessgraphmsg',\n processgraphid: processGraphId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getProcessesForWorkflow(processGraphId: string, colonyName: string, count: number = 100): Promise<any> {\n const msg = {\n msgtype: 'getprocessesmsg',\n processgraphid: processGraphId,\n colonyname: colonyName,\n count,\n state: -1,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async removeAllProcessGraphs(colonyName: string, state?: ProcessState): Promise<any> {\n const msg: any = {\n msgtype: 'removeallprocessgraphsmsg',\n colonyname: colonyName,\n };\n if (state !== undefined) {\n msg.state = state;\n }\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Log Methods ====================\n\n async addLog(processId: string, message: string, executorPrvKey: string): Promise<any> {\n const originalKey = this.privateKey;\n this.setPrivateKey(executorPrvKey);\n\n try {\n const msg = {\n msgtype: 'addlogmsg',\n processid: processId,\n message,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n } finally {\n if (originalKey) {\n this.setPrivateKey(originalKey);\n }\n }\n }\n\n async getLogs(colonyName: string, processId: string, executorName: string, count: number = 100, since: number = 0): Promise<any> {\n const msg = {\n msgtype: 'getlogsmsg',\n colonyname: colonyName,\n processid: processId,\n executorname: executorName,\n count,\n since,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Function Methods ====================\n\n async getFunctions(executorName: string, colonyName: string): Promise<any> {\n const msg = {\n msgtype: 'getfunctionsmsg',\n executorname: executorName,\n colonyname: colonyName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Cron Methods ====================\n\n async getCrons(colonyName: string, count: number = 100): Promise<any> {\n const msg = {\n msgtype: 'getcronsmsg',\n colonyname: colonyName,\n count,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getCron(cronId: string): Promise<any> {\n const msg = {\n msgtype: 'getcronmsg',\n cronid: cronId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async addCron(cronSpec: any): Promise<any> {\n const msg = {\n msgtype: 'addcronmsg',\n cron: cronSpec,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async removeCron(cronId: string): Promise<any> {\n const msg = {\n msgtype: 'removecronmsg',\n cronid: cronId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async runCron(cronId: string): Promise<any> {\n const msg = {\n msgtype: 'runcronmsg',\n cronid: cronId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Generator Methods ====================\n\n async getGenerators(colonyName: string, count: number = 100): Promise<any> {\n const msg = {\n msgtype: 'getgeneratorsmsg',\n colonyname: colonyName,\n count,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getGenerator(generatorId: string): Promise<any> {\n const msg = {\n msgtype: 'getgeneratormsg',\n generatorid: generatorId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async addGenerator(generatorSpec: any): Promise<any> {\n const msg = {\n msgtype: 'addgeneratormsg',\n generator: generatorSpec,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== User Methods ====================\n\n async getUsers(colonyName: string): Promise<any> {\n const msg = {\n msgtype: 'getusersmsg',\n colonyname: colonyName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async addUser(user: {\n colonyname: string;\n userid: string;\n name: string;\n email: string;\n phone: string;\n }): Promise<any> {\n const msg = {\n msgtype: 'addusermsg',\n user,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async removeUser(colonyName: string, name: string): Promise<any> {\n const msg = {\n msgtype: 'removeusermsg',\n colonyname: colonyName,\n name,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== File Methods ====================\n\n async getFileLabels(colonyName: string, name: string = '', exact: boolean = false): Promise<any> {\n const msg = {\n msgtype: 'getfilelabelsmsg',\n colonyname: colonyName,\n name,\n exact,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getFiles(colonyName: string, label: string): Promise<any> {\n const msg = {\n msgtype: 'getfilesmsg',\n colonyname: colonyName,\n label,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getFile(\n colonyName: string,\n options: { fileId: string } | { name: string; label: string; latest?: boolean }\n ): Promise<any> {\n const msg: any = {\n msgtype: 'getfilemsg',\n colonyname: colonyName,\n };\n\n if ('fileId' in options) {\n msg.fileid = options.fileId;\n } else {\n msg.name = options.name;\n msg.label = options.label;\n if (options.latest !== undefined) {\n msg.latest = options.latest;\n }\n }\n\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Attribute Methods ====================\n\n async addAttribute(attribute: {\n targetid: string;\n targetcolonyname: string;\n targetprocessgraphid: string;\n attributetype: number;\n key: string;\n value: string;\n }): Promise<any> {\n const msg = {\n msgtype: 'addattributemsg',\n attribute,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n async getAttribute(attributeId: string): Promise<any> {\n const msg = {\n msgtype: 'getattributemsg',\n attributeid: attributeId,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Channel Methods ====================\n\n /**\n * Append a message to a process channel\n * @param processId - ID of the process\n * @param channelName - Name of the channel\n * @param sequence - Client-assigned sequence number\n * @param inReplyTo - Sequence number this message is replying to (0 if not a reply)\n * @param payload - Message content (string or Uint8Array)\n */\n async channelAppend(\n processId: string,\n channelName: string,\n sequence: number,\n inReplyTo: number,\n payload: string | Uint8Array\n ): Promise<any> {\n let payloadBytes: number[];\n if (typeof payload === 'string') {\n const encoder = new TextEncoder();\n payloadBytes = Array.from(encoder.encode(payload));\n } else {\n payloadBytes = Array.from(payload);\n }\n\n const msg = {\n msgtype: 'channelappendmsg',\n processid: processId,\n name: channelName,\n sequence: sequence,\n inreplyto: inReplyTo,\n payload: payloadBytes,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Read messages from a process channel\n * @param processId - ID of the process\n * @param channelName - Name of the channel\n * @param afterSeq - Read messages after this sequence number (use 0 for all)\n * @param limit - Maximum number of messages to return (0 for no limit)\n */\n async channelRead(\n processId: string,\n channelName: string,\n afterSeq: number,\n limit: number\n ): Promise<any[]> {\n const msg = {\n msgtype: 'channelreadmsg',\n processid: processId,\n name: channelName,\n afterseq: afterSeq,\n limit: limit,\n };\n\n const response = await this.sendRPC(this.createRPCMsg(msg));\n\n // Response is an array of channel entries, decode payload bytes if needed\n if (Array.isArray(response)) {\n return response.map((entry) => ({\n ...entry,\n payload:\n typeof entry.payload === 'string'\n ? (() => {\n try {\n const binaryStr = atob(entry.payload);\n const bytes = new Uint8Array(binaryStr.length);\n for (let i = 0; i < binaryStr.length; i++) {\n bytes[i] = binaryStr.charCodeAt(i);\n }\n return new TextDecoder('utf-8').decode(bytes);\n } catch {\n return entry.payload;\n }\n })()\n : Array.isArray(entry.payload)\n ? new TextDecoder('utf-8').decode(new Uint8Array(entry.payload))\n : entry.payload,\n }));\n }\n\n return response || [];\n }\n\n /**\n * Subscribe to a channel using WebSocket for real-time updates\n * @param processId - ID of the process\n * @param channelName - Name of the channel\n * @param afterSeq - Start reading after this sequence number\n * @param timeout - Timeout in seconds for the subscription\n * @param onMessage - Callback for new messages\n * @param onError - Callback for errors\n * @param onClose - Callback when connection closes\n * @returns WebSocket instance for cleanup\n */\n subscribeChannel(\n processId: string,\n channelName: string,\n afterSeq: number,\n timeout: number,\n onMessage: (entries: any[]) => void,\n onError: (error: Error) => void,\n onClose: () => void\n ): WebSocket {\n if (!this.privateKey) {\n throw new Error('Private key not set. Call setPrivateKey() first.');\n }\n\n const wsProtocol = this.tls ? 'wss' : 'ws';\n const wsUrl = `${wsProtocol}://${this.host}:${this.port}/pubsub`;\n\n const ws = new WebSocket(wsUrl);\n\n ws.onopen = () => {\n const msg = {\n msgtype: 'subscribechannelmsg',\n processid: processId,\n name: channelName,\n afterseq: afterSeq,\n timeout: timeout,\n };\n\n const rpcMsg = this.createRPCMsg(msg);\n ws.send(JSON.stringify(rpcMsg));\n };\n\n ws.onmessage = (event) => {\n try {\n const rpcReply = JSON.parse(event.data as string);\n\n if (rpcReply.error) {\n const errorPayload = JSON.parse(decodeBase64Utf8(rpcReply.payload));\n onError(new Error(errorPayload.message || 'WebSocket error'));\n return;\n }\n\n const data = JSON.parse(decodeBase64Utf8(rpcReply.payload));\n\n if (Array.isArray(data)) {\n const entries = data.map((entry) => ({\n ...entry,\n payload:\n typeof entry.payload === 'string'\n ? (() => {\n try {\n const binaryStr = atob(entry.payload);\n const bytes = new Uint8Array(binaryStr.length);\n for (let i = 0; i < binaryStr.length; i++) {\n bytes[i] = binaryStr.charCodeAt(i);\n }\n return new TextDecoder('utf-8').decode(bytes);\n } catch {\n return entry.payload;\n }\n })()\n : Array.isArray(entry.payload)\n ? new TextDecoder('utf-8').decode(new Uint8Array(entry.payload))\n : entry.payload,\n }));\n\n const errorEntry = entries.find((e) => e.error);\n if (errorEntry) {\n onError(new Error(errorEntry.error));\n return;\n }\n\n onMessage(entries);\n }\n } catch (err) {\n onError(err instanceof Error ? err : new Error(String(err)));\n }\n };\n\n ws.onerror = () => {\n onError(new Error('WebSocket connection error'));\n };\n\n ws.onclose = () => {\n onClose();\n };\n\n return ws;\n }\n\n // ==================== Blueprint Definition Methods ====================\n\n /**\n * Add a blueprint definition\n * @param definition - Blueprint definition object\n */\n async addBlueprintDefinition(definition: any): Promise<any> {\n const msg = {\n msgtype: 'addblueprintdefinitionmsg',\n blueprintdefinition: definition,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Get a blueprint definition by name\n * @param colonyName - Name of the colony\n * @param name - Name of the blueprint definition\n */\n async getBlueprintDefinition(colonyName: string, name: string): Promise<any> {\n const msg = {\n msgtype: 'getblueprintdefinitionmsg',\n colonyname: colonyName,\n name,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Get all blueprint definitions in a colony\n * @param colonyName - Name of the colony\n */\n async getBlueprintDefinitions(colonyName: string): Promise<any[]> {\n const msg = {\n msgtype: 'getblueprintdefinitionsmsg',\n colonyname: colonyName,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Remove a blueprint definition\n * @param colonyName - Name of the colony (namespace)\n * @param name - Name of the blueprint definition to remove\n */\n async removeBlueprintDefinition(colonyName: string, name: string): Promise<void> {\n const msg = {\n msgtype: 'removeblueprintdefinitionmsg',\n namespace: colonyName,\n name,\n };\n await this.sendRPC(this.createRPCMsg(msg));\n }\n\n // ==================== Blueprint Methods ====================\n\n /**\n * Add a blueprint instance\n * @param blueprint - Blueprint object\n */\n async addBlueprint(blueprint: any): Promise<any> {\n const msg = {\n msgtype: 'addblueprintmsg',\n blueprint,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Get a blueprint by name\n * @param colonyName - Name of the colony (namespace)\n * @param name - Name of the blueprint\n */\n async getBlueprint(colonyName: string, name: string): Promise<any> {\n const msg = {\n msgtype: 'getblueprintmsg',\n namespace: colonyName,\n name,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Get blueprints in a colony, optionally filtered by kind and location\n * @param colonyName - Name of the colony (namespace)\n * @param kind - Optional kind filter\n * @param location - Optional location filter\n */\n async getBlueprints(colonyName: string, kind?: string, location?: string): Promise<any[]> {\n const msg: any = {\n msgtype: 'getblueprintsmsg',\n namespace: colonyName,\n };\n if (kind) msg.kind = kind;\n if (location) msg.locationname = location;\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Update an existing blueprint\n * @param blueprint - Updated blueprint object\n * @param forceGeneration - Force generation bump even if spec unchanged\n */\n async updateBlueprint(blueprint: any, forceGeneration: boolean = false): Promise<any> {\n const msg = {\n msgtype: 'updateblueprintmsg',\n blueprint,\n forcegeneration: forceGeneration,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Remove a blueprint\n * @param colonyName - Name of the colony (namespace)\n * @param name - Name of the blueprint to remove\n */\n async removeBlueprint(colonyName: string, name: string): Promise<void> {\n const msg = {\n msgtype: 'removeblueprintmsg',\n namespace: colonyName,\n name,\n };\n await this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Update blueprint status (current state)\n * @param colonyName - Name of the colony\n * @param name - Name of the blueprint\n * @param status - Status object representing current state\n */\n async updateBlueprintStatus(colonyName: string, name: string, status: any): Promise<void> {\n const msg = {\n msgtype: 'updateblueprintstatusmsg',\n colonyname: colonyName,\n blueprintname: name,\n status,\n };\n await this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Trigger reconciliation for a blueprint\n * @param colonyName - Name of the colony (namespace)\n * @param name - Name of the blueprint\n * @param force - Force reconciliation even if no changes detected\n */\n async reconcileBlueprint(colonyName: string, name: string, force: boolean = false): Promise<any> {\n const msg = {\n msgtype: 'reconcileblueprintmsg',\n namespace: colonyName,\n name,\n force,\n };\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Get the history of changes for a specific blueprint\n * @param blueprintId - ID of the blueprint\n * @param limit - Optional limit on number of history entries to retrieve\n */\n async getBlueprintHistory(blueprintId: string, limit?: number): Promise<any> {\n const msg: any = {\n msgtype: 'getblueprinthistorymsg',\n blueprintid: blueprintId,\n };\n if (limit !== undefined) {\n msg.limit = limit;\n }\n return this.sendRPC(this.createRPCMsg(msg));\n }\n\n /**\n * Subscribe to process state changes using WebSocket\n * Use this to wait for a process to be assigned (RUNNING state) before subscribing to channels\n * @param colonyName - Name of the colony\n * @param processId - ID of the process to watch\n * @param state - Target state to wait for (0=WAITING, 1=RUNNING, 2=SUCCESS, 3=FAILED)\n * @param timeout - Timeout in seconds for the subscription\n * @param onProcess - Callback when process reaches the target state\n * @param onError - Callback for errors\n * @param onClose - Callback when connection closes\n * @returns WebSocket instance for cleanup\n */\n subscribeProcess(\n colonyName: string,\n processId: string,\n state: number,\n timeout: number,\n onProcess: (process: any) => void,\n onError: (error: Error) => void,\n onClose: () => void\n ): WebSocket {\n if (!this.privateKey) {\n throw new Error('Private key not set. Call setPrivateKey() first.');\n }\n\n const wsProtocol = this.tls ? 'wss' : 'ws';\n const wsUrl = `${wsProtocol}://${this.host}:${this.port}/pubsub`;\n\n const ws = new WebSocket(wsUrl);\n\n ws.onopen = () => {\n const msg = {\n msgtype: 'subscribeprocessmsg',\n colonyname: colonyName,\n processid: processId,\n executortype: '',\n state: state,\n timeout: timeout,\n };\n\n const rpcMsg = this.createRPCMsg(msg);\n ws.send(JSON.stringify(rpcMsg));\n };\n\n ws.onmessage = (event) => {\n try {\n const rpcReply = JSON.parse(event.data as string);\n\n if (rpcReply.error) {\n const errorPayload = JSON.parse(decodeBase64Utf8(rpcReply.payload));\n onError(new Error(errorPayload.message || 'WebSocket error'));\n return;\n }\n\n const process = JSON.parse(decodeBase64Utf8(rpcReply.payload));\n onProcess(process);\n } catch (err) {\n onError(err instanceof Error ? err : new Error(String(err)));\n }\n };\n\n ws.onerror = () => {\n onError(new Error('WebSocket connection error'));\n };\n\n ws.onclose = () => {\n onClose();\n };\n\n return ws;\n }\n}\n"],"mappings":";AAMA,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,SAAS,YAAY;AACrB,SAAS,YAAY,YAAY,mBAAmB;AAIpD,IAAM,IAAI;AACV,IAAM,IAAI;AACV,IAAM,KAAK;AACX,IAAM,KAAK;AACX,IAAM,IAAsB,CAAC,IAAI,EAAE;AACnC,IAAM,IAAI,MAAM,OAAO,MAAM,MAAM;AAOnC,SAAS,MAAM,OAA+B;AAC5C,MAAI,MAAM,UAAU,GAAI,QAAO,MAAM,MAAM,GAAG,EAAE;AAChD,QAAM,SAAS,IAAI,WAAW,EAAE;AAChC,SAAO,IAAI,OAAO,KAAK,MAAM,MAAM;AACnC,SAAO;AACT;AAEA,SAAS,eAAe,OAA2B;AACjD,MAAI,UAAU,GAAI,QAAO,IAAI,WAAW,CAAC,CAAC,CAAC;AAC3C,QAAM,MAAM,MAAM,SAAS,EAAE;AAC7B,QAAM,YAAY,IAAI,SAAS,IAAI,MAAM,MAAM;AAC/C,SAAO,WAAW,SAAS;AAC7B;AAEA,SAAS,eAAe,OAA2B;AACjD,MAAI,MAAM,WAAW,EAAG,QAAO;AAC/B,SAAO,OAAO,OAAO,WAAW,KAAK,CAAC;AACxC;AAIA,SAAS,IAAI,GAAW,GAAmB;AACzC,MAAI,MAAM,GAAI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