openclaw-messagebox-plugin 0.1.3 → 0.1.5
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 +44 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +85 -14
- package/dist/index.js.map +1 -1
- package/dist/src/client.d.ts +11 -4
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/client.js +94 -13
- package/dist/src/client.js.map +1 -1
- package/dist/src/core/config.d.ts +12 -0
- package/dist/src/core/config.d.ts.map +1 -0
- package/dist/src/core/config.js +14 -0
- package/dist/src/core/config.js.map +1 -0
- package/dist/src/core/index.d.ts +26 -0
- package/dist/src/core/index.d.ts.map +1 -0
- package/dist/src/core/index.js +27 -0
- package/dist/src/core/index.js.map +1 -0
- package/dist/src/core/payment.d.ts +17 -0
- package/dist/src/core/payment.d.ts.map +1 -0
- package/dist/src/core/payment.js +95 -0
- package/dist/src/core/payment.js.map +1 -0
- package/dist/src/core/types.d.ts +95 -0
- package/dist/src/core/types.d.ts.map +1 -0
- package/dist/src/core/types.js +5 -0
- package/dist/src/core/types.js.map +1 -0
- package/dist/src/core/verify.d.ts +29 -0
- package/dist/src/core/verify.d.ts.map +1 -0
- package/dist/src/core/verify.js +105 -0
- package/dist/src/core/verify.js.map +1 -0
- package/dist/src/core/wallet.d.ts +100 -0
- package/dist/src/core/wallet.d.ts.map +1 -0
- package/dist/src/core/wallet.js +225 -0
- package/dist/src/core/wallet.js.map +1 -0
- package/index.ts +95 -14
- package/openclaw.plugin.json +3 -2
- package/package.json +7 -6
- package/src/client.ts +106 -14
- package/src/core/config.d.ts +12 -0
- package/src/core/config.ts +21 -0
- package/src/core/index.ts +42 -0
- package/src/core/payment.d.ts +17 -0
- package/src/core/payment.ts +111 -0
- package/src/core/types.d.ts +95 -0
- package/src/core/types.ts +102 -0
- package/src/core/verify.d.ts +29 -0
- package/src/core/verify.ts +119 -0
- package/src/core/wallet.d.ts +100 -0
- package/src/core/wallet.ts +289 -0
package/README.md
CHANGED
|
@@ -8,12 +8,51 @@ A programmatic OpenClaw plugin that enables secure, P2P encrypted messaging and
|
|
|
8
8
|
- **Real-time Hooks**: Real-time agent wake-ups via WebSockets.
|
|
9
9
|
- **Direct P2P Payments**: Integrated PeerPay support for machine-to-machine commerce.
|
|
10
10
|
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Configuration
|
|
14
|
+
|
|
15
|
+
You can configure the plugin in your `openclaw.json` file. The plugin supports both a flat structure and a nested `config` object under its ID.
|
|
16
|
+
|
|
17
|
+
### Example Configuration
|
|
18
|
+
```json
|
|
19
|
+
{
|
|
20
|
+
"plugins": {
|
|
21
|
+
"entries": {
|
|
22
|
+
"openclaw-messagebox-plugin": {
|
|
23
|
+
"enabled": true,
|
|
24
|
+
"host": "https://msg.bsv.direct",
|
|
25
|
+
"chaintracksUrl": "https://chaintracks-us-1.bsvb.tech",
|
|
26
|
+
"arcUrl": "https://arc.gorillapool.io",
|
|
27
|
+
"walletDir": "~/.openclaw/bsv-wallet"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Options
|
|
35
|
+
|
|
36
|
+
| Option | Default | Description |
|
|
37
|
+
| :--- | :--- | :--- |
|
|
38
|
+
| `host` | `https://msg.bsv.direct` | The MessageBox server host URL. |
|
|
39
|
+
| `chaintracksUrl`| `https://chaintracks-us-1.bsvb.tech` | Custom server for SPV block header verification. |
|
|
40
|
+
| `arcUrl` | `https://arc.gorillapool.io` | Custom ARC/Arcade server for transaction broadcasting. |
|
|
41
|
+
| `walletDir` | `~/.openclaw/bsv-wallet` | Directory where `wallet-identity.json` is stored. |
|
|
42
|
+
| `dbPath` | (auto-generated) | Path to the local SQLite database for message history. |
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
11
46
|
## AI Tool: `messagebox`
|
|
12
|
-
Agents can use the `messagebox` tool to:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
47
|
+
Agents can use the `messagebox` tool to perform the following actions:
|
|
48
|
+
|
|
49
|
+
| Action | Description |
|
|
50
|
+
| :--- | :--- |
|
|
51
|
+
| `send` | Deliver an encrypted message to another agent's identity key. |
|
|
52
|
+
| `inbox` | Retrieve and decrypt incoming messages from your mailbox. |
|
|
53
|
+
| `acknowledge` | Mark messages as processed to remove them from the server. |
|
|
54
|
+
| `pay` | Send a direct peer-to-peer BSV payment via messaging. |
|
|
55
|
+
| `status` | Show connection status, host, and your identity key. |
|
|
17
56
|
|
|
18
57
|
## Architecture
|
|
19
58
|
Built with the **OpenClaw Plugin SDK**, this extension uses:
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAOA;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,GAAG,EAAE,GAAG,QAyJxC"}
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,43 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import os from "node:os";
|
|
3
|
+
import { MessageBoxManager } from "./src/client.js";
|
|
4
|
+
import { MessageStore } from "./src/store.js";
|
|
5
|
+
import { BSVAgentWallet } from "./src/core/wallet.js";
|
|
3
6
|
/**
|
|
4
7
|
* OpenClaw MessageBox Plugin
|
|
5
8
|
* Enables secure P2P encrypted messaging and payments.
|
|
6
9
|
*/
|
|
7
10
|
export default function register(api) {
|
|
8
|
-
// Capture configuration from the gateway (handle
|
|
9
|
-
const
|
|
11
|
+
// Capture configuration from the gateway (handle multiple IDs and flat/nested structures)
|
|
12
|
+
const entries = api.getConfig?.()?.plugins?.entries || {};
|
|
13
|
+
const entry = entries['openclaw-messagebox']
|
|
14
|
+
|| entries['openclaw-messagebox-plugin']
|
|
15
|
+
|| entries['bsv-messagebox']
|
|
16
|
+
|| {};
|
|
10
17
|
const pluginConfig = { ...entry, ...(entry.config || {}), ...(api.config || {}) };
|
|
11
18
|
const host = pluginConfig.host || 'https://msg.bsv.direct';
|
|
12
19
|
const network = pluginConfig.network || 'mainnet';
|
|
13
20
|
const chaintracksUrl = pluginConfig.chaintracksUrl || 'https://chaintracks-us-1.bsvb.tech';
|
|
14
|
-
const arcUrl = pluginConfig.arcUrl || '';
|
|
21
|
+
const arcUrl = pluginConfig.arcUrl || (network === 'testnet' ? 'https://testnet.arc.gorillapool.io' : 'https://arc.gorillapool.io');
|
|
15
22
|
const walletDir = pluginConfig.walletDir || path.join(os.homedir(), '.openclaw', 'bsv-wallet');
|
|
16
|
-
|
|
23
|
+
const dbPath = pluginConfig.dbPath || path.join(os.homedir(), '.openclaw', 'openclaw-messagebox', 'messages.sqlite');
|
|
24
|
+
let manager = null;
|
|
25
|
+
let store = null;
|
|
26
|
+
let wallet = null;
|
|
27
|
+
api.logger.info(`[messagebox] Initializing MessageBox Plugin (network: ${network}, host: ${host})`);
|
|
28
|
+
async function ensureInitialized() {
|
|
29
|
+
if (manager)
|
|
30
|
+
return manager;
|
|
31
|
+
// Initialize shared wallet
|
|
32
|
+
wallet = await BSVAgentWallet.load({
|
|
33
|
+
network: network,
|
|
34
|
+
storageDir: walletDir
|
|
35
|
+
});
|
|
36
|
+
store = new MessageStore(dbPath);
|
|
37
|
+
await store.init();
|
|
38
|
+
manager = new MessageBoxManager({ host, walletDir, dbPath }, store, wallet);
|
|
39
|
+
return manager;
|
|
40
|
+
}
|
|
17
41
|
// Register the messagebox tool
|
|
18
42
|
api.registerTool({
|
|
19
43
|
name: "messagebox",
|
|
@@ -34,6 +58,11 @@ export default function register(api) {
|
|
|
34
58
|
type: "string",
|
|
35
59
|
description: "Message content (will be encrypted client-side)"
|
|
36
60
|
},
|
|
61
|
+
box: {
|
|
62
|
+
type: "string",
|
|
63
|
+
default: "default",
|
|
64
|
+
description: "Target mailbox/folder"
|
|
65
|
+
},
|
|
37
66
|
sats: {
|
|
38
67
|
type: "number",
|
|
39
68
|
description: "Amount in satoshis for direct P2P payment"
|
|
@@ -48,13 +77,41 @@ export default function register(api) {
|
|
|
48
77
|
},
|
|
49
78
|
async execute(_id, params) {
|
|
50
79
|
try {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
80
|
+
const m = await ensureInitialized();
|
|
81
|
+
switch (params.action) {
|
|
82
|
+
case "send":
|
|
83
|
+
if (!params.recipientKey || !params.body)
|
|
84
|
+
throw new Error("recipientKey and body required");
|
|
85
|
+
const msgId = await m.send(params.recipientKey, params.body, params.box);
|
|
86
|
+
return { content: [{ type: "text", text: `✅ Message sent successfully. ID: ${msgId}` }] };
|
|
87
|
+
case "inbox":
|
|
88
|
+
await m.poll(params.box);
|
|
89
|
+
const messages = await store.getInbox();
|
|
90
|
+
if (messages.length === 0)
|
|
91
|
+
return { content: [{ type: "text", text: "Your inbox is empty." }] };
|
|
92
|
+
const list = messages.map(msg => `[${new Date(msg.ts).toLocaleString()}] FROM: ${msg.senderKey.slice(0, 12)}... - "${msg.body}"`).join('\n');
|
|
93
|
+
return { content: [{ type: "text", text: `📬 Inbox (Last ${messages.length} messages):\n\n${list}` }] };
|
|
94
|
+
case "acknowledge":
|
|
95
|
+
if (!params.messageIds || params.messageIds.length === 0)
|
|
96
|
+
throw new Error("messageIds array required");
|
|
97
|
+
await m.acknowledge(params.messageIds);
|
|
98
|
+
return { content: [{ type: "text", text: `✅ Acknowledged ${params.messageIds.length} messages.` }] };
|
|
99
|
+
case "status":
|
|
100
|
+
return { content: [{ type: "text", text: `MessageBox Status:\nHost: ${host}\nIdentity: ${m.getIdentityKey()}\nDatabase: ${dbPath}` }] };
|
|
101
|
+
case "pay":
|
|
102
|
+
if (!params.recipientKey || !params.sats)
|
|
103
|
+
throw new Error("recipientKey and sats required");
|
|
104
|
+
const payResult = await wallet.createPayment({
|
|
105
|
+
to: params.recipientKey,
|
|
106
|
+
satoshis: params.sats,
|
|
107
|
+
description: "P2P Payment via MessageBox"
|
|
108
|
+
});
|
|
109
|
+
// Send the BEEF payment as a message to the recipient's payment_inbox
|
|
110
|
+
const pmsgId = await m.send(params.recipientKey, JSON.stringify(payResult), 'payment_inbox');
|
|
111
|
+
return { content: [{ type: "text", text: `✅ P2P Payment sent! Amount: ${params.sats} sats. Notification ID: ${pmsgId}` }] };
|
|
112
|
+
default:
|
|
113
|
+
throw new Error(`Unknown action: ${params.action}`);
|
|
114
|
+
}
|
|
58
115
|
}
|
|
59
116
|
catch (error) {
|
|
60
117
|
return {
|
|
@@ -70,11 +127,25 @@ export default function register(api) {
|
|
|
70
127
|
api.registerService({
|
|
71
128
|
id: "messagebox-listener",
|
|
72
129
|
start: async () => {
|
|
73
|
-
|
|
74
|
-
|
|
130
|
+
try {
|
|
131
|
+
const m = await ensureInitialized();
|
|
132
|
+
api.logger.info("[messagebox] Starting WebSocket listener...");
|
|
133
|
+
await m.listen((msg) => {
|
|
134
|
+
api.logger.info(`[messagebox] ⚡ New message from ${msg.senderKey.slice(0, 12)}...`);
|
|
135
|
+
// Wake the agent to handle the incoming private message
|
|
136
|
+
const wakeText = `⚡ New private message received!\n\nFrom: ${msg.senderKey}\nMessage: ${msg.body}\n\nYou can reply using messagebox({ action: "send", recipientKey: "${msg.senderKey}", body: "..." })`;
|
|
137
|
+
api.wakeAgent?.({
|
|
138
|
+
prompt: wakeText,
|
|
139
|
+
sessionKey: `hook:messagebox:${msg.id}`
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
api.logger.error(`[messagebox] WebSocket listener failed: ${err.message}`);
|
|
145
|
+
}
|
|
75
146
|
},
|
|
76
147
|
stop: async () => {
|
|
77
|
-
api.logger.info("[messagebox] Stopping
|
|
148
|
+
api.logger.info("[messagebox] Stopping WebSocket listener...");
|
|
78
149
|
}
|
|
79
150
|
});
|
|
80
151
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,GAAQ;IACvC,0FAA0F;IAC1F,MAAM,OAAO,GAAG,GAAG,CAAC,SAAS,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,IAAI,EAAE,CAAC;IAC1D,MAAM,KAAK,GAAG,OAAO,CAAC,qBAAqB,CAAC;WACvC,OAAO,CAAC,4BAA4B,CAAC;WACrC,OAAO,CAAC,gBAAgB,CAAC;WACzB,EAAE,CAAC;IAER,MAAM,YAAY,GAAG,EAAE,GAAG,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE,CAAC;IAClF,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,IAAI,wBAAwB,CAAC;IAC3D,MAAM,OAAO,GAAG,YAAY,CAAC,OAAO,IAAI,SAAS,CAAC;IAClD,MAAM,cAAc,GAAG,YAAY,CAAC,cAAc,IAAI,oCAAoC,CAAC;IAC3F,MAAM,MAAM,GAAG,YAAY,CA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C,CAAC;gBAE/D,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE;oBACrB,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,mCAAmC,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;oBAEpF,wDAAwD;oBACxD,MAAM,QAAQ,GAAG,4CAA4C,GAAG,CAAC,SAAS,cAAc,GAAG,CAAC,IAAI,uEAAuE,GAAG,CAAC,SAAS,mBAAmB,CAAC;oBAExM,GAAG,CAAC,SAAS,EAAE,CAAC;wBACd,MAAM,EAAE,QAAQ;wBAChB,UAAU,EAAE,mBAAmB,GAAG,CAAC,EAAE,EAAE;qBACxC,CAAC,CAAC;gBACL,CAAC,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,GAAQ,EAAE,CAAC;gBAClB,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,2CAA2C,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;YAC7E,CAAC;QACH,CAAC;QACD,IAAI,EAAE,KAAK,IAAI,EAAE;YACf,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAC;QACjE,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/dist/src/client.d.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { MessageBoxConfig, MessageRecord } from './types.js';
|
|
2
|
+
import { MessageStore } from './store.js';
|
|
3
|
+
import { BSVAgentWallet } from './core/wallet.js';
|
|
2
4
|
export declare class MessageBoxManager {
|
|
3
5
|
private client;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
private privKey;
|
|
7
|
+
private store;
|
|
8
|
+
private wallet;
|
|
9
|
+
constructor(config: MessageBoxConfig, store: MessageStore, wallet: BSVAgentWallet);
|
|
10
|
+
send(recipientKey: string, body: string, box?: string): Promise<string>;
|
|
11
|
+
poll(box?: string): Promise<MessageRecord[]>;
|
|
12
|
+
acknowledge(messageIds: string[]): Promise<void>;
|
|
13
|
+
listen(onMessage: (msg: MessageRecord) => void): Promise<void>;
|
|
14
|
+
getIdentityKey(): string;
|
|
8
15
|
}
|
|
9
16
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/src/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG1C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,OAAO,CAAa;IAC5B,OAAO,CAAC,KAAK,CAAe;IAC5B,OAAO,CAAC,MAAM,CAAiB;gBAEnB,MAAM,EAAE,gBAAgB,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,cAAc;IAoB3E,IAAI,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,GAAE,MAAkB,GAAG,OAAO,CAAC,MAAM,CAAC;IAuBlF,IAAI,CAAC,GAAG,GAAE,MAAkB,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IA4BvD,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE;IAMhC,MAAM,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,aAAa,KAAK,IAAI;IAwBpD,cAAc,IAAI,MAAM;CAGzB"}
|
package/dist/src/client.js
CHANGED
|
@@ -1,21 +1,102 @@
|
|
|
1
|
+
import { MessageBoxClient } from '@bsv/message-box-client';
|
|
2
|
+
import { PrivateKey } from '@bsv/sdk';
|
|
3
|
+
import * as fs from 'node:fs';
|
|
4
|
+
import * as path from 'node:path';
|
|
1
5
|
export class MessageBoxManager {
|
|
2
6
|
client;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
7
|
+
privKey;
|
|
8
|
+
store;
|
|
9
|
+
wallet;
|
|
10
|
+
constructor(config, store, wallet) {
|
|
11
|
+
const identityPath = path.join(config.walletDir, 'wallet-identity.json');
|
|
12
|
+
if (!fs.existsSync(identityPath)) {
|
|
13
|
+
throw new Error(`Identity file not found at ${identityPath}. Please onboard your agent first.`);
|
|
14
|
+
}
|
|
15
|
+
const identity = JSON.parse(fs.readFileSync(identityPath, 'utf-8'));
|
|
16
|
+
this.privKey = PrivateKey.fromHex(identity.rootKeyHex);
|
|
17
|
+
this.store = store;
|
|
18
|
+
this.wallet = wallet;
|
|
19
|
+
// Initialize the MessageBoxClient with correct SDK-style wallet interface
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
this.client = new MessageBoxClient({
|
|
22
|
+
host: config.host,
|
|
23
|
+
walletClient: this.wallet._setup.wallet,
|
|
24
|
+
networkPreset: config.walletDir.includes('testnet') ? 'testnet' : 'mainnet'
|
|
25
|
+
});
|
|
6
26
|
}
|
|
7
|
-
async send(
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
|
|
27
|
+
async send(recipientKey, body, box = 'default') {
|
|
28
|
+
// sendMessage handles BRC-2 encryption internally using the walletClient
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
const response = await this.client.sendMessage({
|
|
31
|
+
recipient: recipientKey,
|
|
32
|
+
messageBox: box,
|
|
33
|
+
body: body
|
|
34
|
+
});
|
|
35
|
+
// Save to local store
|
|
36
|
+
await this.store.saveMessage({
|
|
37
|
+
id: response.messageId,
|
|
38
|
+
senderKey: this.privKey.toPublicKey().toString(),
|
|
39
|
+
recipientKey,
|
|
40
|
+
body, // store decrypted locally
|
|
41
|
+
box,
|
|
42
|
+
ts: Date.now(),
|
|
43
|
+
acknowledged: false
|
|
44
|
+
});
|
|
45
|
+
return response.messageId;
|
|
11
46
|
}
|
|
12
|
-
async poll(
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
|
|
47
|
+
async poll(box = 'default') {
|
|
48
|
+
// listMessages handles BRC-2 decryption internally using the walletClient
|
|
49
|
+
// @ts-ignore
|
|
50
|
+
const messages = await this.client.listMessages({ messageBox: box });
|
|
51
|
+
const records = [];
|
|
52
|
+
for (const msg of messages) {
|
|
53
|
+
const record = {
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
id: msg.id || msg.messageId,
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
senderKey: msg.sender || msg.senderKey,
|
|
58
|
+
recipientKey: this.privKey.toPublicKey().toString(),
|
|
59
|
+
body: typeof msg.body === 'string' ? msg.body : JSON.stringify(msg.body),
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
box: msg.box || box,
|
|
62
|
+
// @ts-ignore
|
|
63
|
+
ts: msg.timestamp || Date.now(),
|
|
64
|
+
acknowledged: false
|
|
65
|
+
};
|
|
66
|
+
await this.store.saveMessage(record);
|
|
67
|
+
records.push(record);
|
|
68
|
+
}
|
|
69
|
+
return records;
|
|
16
70
|
}
|
|
17
|
-
async acknowledge(
|
|
18
|
-
//
|
|
71
|
+
async acknowledge(messageIds) {
|
|
72
|
+
// @ts-ignore
|
|
73
|
+
await this.client.acknowledgeMessage({ messageIds });
|
|
74
|
+
await this.store.markAcknowledged(messageIds);
|
|
75
|
+
}
|
|
76
|
+
async listen(onMessage) {
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
return this.client.listenForLiveMessages({
|
|
79
|
+
messageBox: 'default',
|
|
80
|
+
onMessage: async (msg) => {
|
|
81
|
+
const record = {
|
|
82
|
+
// @ts-ignore
|
|
83
|
+
id: msg.id || msg.messageId,
|
|
84
|
+
// @ts-ignore
|
|
85
|
+
senderKey: msg.sender || msg.senderKey,
|
|
86
|
+
recipientKey: this.privKey.toPublicKey().toString(),
|
|
87
|
+
body: typeof msg.body === 'string' ? msg.body : JSON.stringify(msg.body),
|
|
88
|
+
// @ts-ignore
|
|
89
|
+
box: msg.box || 'default',
|
|
90
|
+
ts: Date.now(),
|
|
91
|
+
acknowledged: false
|
|
92
|
+
};
|
|
93
|
+
await this.store.saveMessage(record);
|
|
94
|
+
onMessage(record);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
getIdentityKey() {
|
|
99
|
+
return this.privKey.toPublicKey().toString();
|
|
19
100
|
}
|
|
20
101
|
}
|
|
21
102
|
//# sourceMappingURL=client.js.map
|
package/dist/src/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAGtC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC,MAAM,OAAO,iBAAiB;IACpB,MAAM,CAAmB;IACzB,OAAO,CAAa;IACpB,KAAK,CAAe;IACpB,MAAM,CAAiB;IAE/B,YAAY,MAAwB,EAAE,KAAmB,EAAE,MAAsB;QAC/E,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,sBAAsB,CAAC,CAAC;QACzE,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,8BAA8B,YAAY,oCAAoC,CAAC,CAAC;QAClG,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC,CAAC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AAE,GAAQ,EAAE,EAAE;gBAC5B,MAAM,MAAM,GAAkB;oBAC5B,aAAa;oBACb,EAAE,EAAE,GAAG,CAAC,EAAE,IAAK,GAAW,CAAC,SAAS;oBACpC,aAAa;oBACb,SAAS,EAAE,GAAG,CAAC,MAAM,IAAK,GAAW,CAAC,SAAS;oBAC/C,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE;oBACnD,IAAI,EAAE,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC;oBACxE,aAAa;oBACb,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,SAAS;oBACzB,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE;oBACd,YAAY,EAAE,KAAK;iBACpB,CAAC;gBAEF,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;gBACrC,SAAS,CAAC,MAAM,CAAC,CAAC;YACpB,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE,CAAC;IAC/C,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @a2a-bsv/core — Configuration defaults and helpers.
|
|
3
|
+
*/
|
|
4
|
+
import type { WalletConfig } from './types.js';
|
|
5
|
+
/** Map our 'mainnet'/'testnet' to the wallet-toolbox's 'main'/'test' chain type. */
|
|
6
|
+
export type Chain = 'main' | 'test';
|
|
7
|
+
export declare function toChain(network: WalletConfig['network']): Chain;
|
|
8
|
+
/** Default TAAL API keys from the wallet-toolbox examples. */
|
|
9
|
+
export declare const DEFAULT_TAAL_API_KEYS: Record<Chain, string>;
|
|
10
|
+
/** Default SQLite database name. */
|
|
11
|
+
export declare const DEFAULT_DB_NAME = "a2a_agent_wallet";
|
|
12
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/core/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,oFAAoF;AACpF,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;AAEpC,wBAAgB,OAAO,CAAC,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,GAAG,KAAK,CAE/D;AAED,8DAA8D;AAC9D,eAAO,MAAM,qBAAqB,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAGvD,CAAC;AAEF,oCAAoC;AACpC,eAAO,MAAM,eAAe,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @a2a-bsv/core — Configuration defaults and helpers.
|
|
3
|
+
*/
|
|
4
|
+
export function toChain(network) {
|
|
5
|
+
return network === 'mainnet' ? 'main' : 'test';
|
|
6
|
+
}
|
|
7
|
+
/** Default TAAL API keys from the wallet-toolbox examples. */
|
|
8
|
+
export const DEFAULT_TAAL_API_KEYS = {
|
|
9
|
+
main: 'mainnet_9596de07e92300c6287e4393594ae39c',
|
|
10
|
+
test: 'testnet_0e6cf72133b43ea2d7861da2a38684e3',
|
|
11
|
+
};
|
|
12
|
+
/** Default SQLite database name. */
|
|
13
|
+
export const DEFAULT_DB_NAME = 'a2a_agent_wallet';
|
|
14
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/core/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,MAAM,UAAU,OAAO,CAAC,OAAgC;IACtD,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;AACjD,CAAC;AAED,8DAA8D;AAC9D,MAAM,CAAC,MAAM,qBAAqB,GAA0B;IAC1D,IAAI,EAAE,0CAA0C;IAChD,IAAI,EAAE,0CAA0C;CACjD,CAAC;AAEF,oCAAoC;AACpC,MAAM,CAAC,MAAM,eAAe,GAAG,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @a2a-bsv/core — Agent-to-agent BSV payment library.
|
|
3
|
+
*
|
|
4
|
+
* Wraps @bsv/sdk and @bsv/wallet-toolbox to provide a clean, minimal API
|
|
5
|
+
* for AI agents to pay each other using BSV blockchain transactions.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { BSVAgentWallet } from '@a2a-bsv/core';
|
|
10
|
+
*
|
|
11
|
+
* const wallet = await BSVAgentWallet.load({
|
|
12
|
+
* network: 'testnet',
|
|
13
|
+
* storageDir: './my-agent-wallet',
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* const identityKey = await wallet.getIdentityKey();
|
|
17
|
+
* console.log('My identity:', identityKey);
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export { BSVAgentWallet } from './wallet.js';
|
|
21
|
+
export type { WalletConfig, WalletIdentity, PaymentParams, PaymentResult, VerifyParams, VerifyResult, AcceptParams, AcceptResult, } from './types.js';
|
|
22
|
+
export { toChain, DEFAULT_TAAL_API_KEYS, DEFAULT_DB_NAME } from './config.js';
|
|
23
|
+
export type { Chain } from './config.js';
|
|
24
|
+
export { buildPayment } from './payment.js';
|
|
25
|
+
export { verifyPayment, acceptPayment } from './verify.js';
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7C,YAAY,EACV,YAAY,EACZ,cAAc,EACd,aAAa,EACb,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,GACb,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9E,YAAY,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @a2a-bsv/core — Agent-to-agent BSV payment library.
|
|
3
|
+
*
|
|
4
|
+
* Wraps @bsv/sdk and @bsv/wallet-toolbox to provide a clean, minimal API
|
|
5
|
+
* for AI agents to pay each other using BSV blockchain transactions.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { BSVAgentWallet } from '@a2a-bsv/core';
|
|
10
|
+
*
|
|
11
|
+
* const wallet = await BSVAgentWallet.load({
|
|
12
|
+
* network: 'testnet',
|
|
13
|
+
* storageDir: './my-agent-wallet',
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* const identityKey = await wallet.getIdentityKey();
|
|
17
|
+
* console.log('My identity:', identityKey);
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
// Main wallet class
|
|
21
|
+
export { BSVAgentWallet } from './wallet.js';
|
|
22
|
+
// Config helpers (for advanced use)
|
|
23
|
+
export { toChain, DEFAULT_TAAL_API_KEYS, DEFAULT_DB_NAME } from './config.js';
|
|
24
|
+
// Lower-level helpers (for advanced use)
|
|
25
|
+
export { buildPayment } from './payment.js';
|
|
26
|
+
export { verifyPayment, acceptPayment } from './verify.js';
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,oBAAoB;AACpB,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAc7C,oCAAoC;AACpC,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG9E,yCAAyC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @a2a-bsv/core — Payment construction helpers.
|
|
3
|
+
*
|
|
4
|
+
* Uses BRC-29 key derivation so the recipient can internalize the payment
|
|
5
|
+
* without ever reusing an address.
|
|
6
|
+
*/
|
|
7
|
+
import type { SetupWallet } from '@bsv/wallet-toolbox';
|
|
8
|
+
import type { PaymentParams, PaymentResult } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Build a BRC-29 payment transaction using the wallet's createAction API.
|
|
11
|
+
*
|
|
12
|
+
* The transaction is created with `acceptDelayedBroadcast: false` — the sender
|
|
13
|
+
* broadcasts immediately. The resulting Atomic BEEF and derivation metadata are
|
|
14
|
+
* returned so the recipient can verify and internalize the payment on their side.
|
|
15
|
+
*/
|
|
16
|
+
export declare function buildPayment(setup: SetupWallet, params: PaymentParams): Promise<PaymentResult>;
|
|
17
|
+
//# sourceMappingURL=payment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment.d.ts","sourceRoot":"","sources":["../../../src/core/payment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG/D;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,KAAK,EAAE,WAAW,EAClB,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,aAAa,CAAC,CA8ExB"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @a2a-bsv/core — Payment construction helpers.
|
|
3
|
+
*
|
|
4
|
+
* Uses BRC-29 key derivation so the recipient can internalize the payment
|
|
5
|
+
* without ever reusing an address.
|
|
6
|
+
*/
|
|
7
|
+
import { Beef, Utils } from '@bsv/sdk';
|
|
8
|
+
import { randomBytesBase64, ScriptTemplateBRC29 } from '@bsv/wallet-toolbox';
|
|
9
|
+
/**
|
|
10
|
+
* Build a BRC-29 payment transaction using the wallet's createAction API.
|
|
11
|
+
*
|
|
12
|
+
* The transaction is created with `acceptDelayedBroadcast: false` — the sender
|
|
13
|
+
* broadcasts immediately. The resulting Atomic BEEF and derivation metadata are
|
|
14
|
+
* returned so the recipient can verify and internalize the payment on their side.
|
|
15
|
+
*/
|
|
16
|
+
export async function buildPayment(setup, params) {
|
|
17
|
+
const { to, satoshis, description } = params;
|
|
18
|
+
const desc = normalizeDescription(description ?? 'agent payment');
|
|
19
|
+
// Generate unique BRC-29 derivation prefixes and suffixes
|
|
20
|
+
const derivationPrefix = randomBytesBase64(8);
|
|
21
|
+
const derivationSuffix = randomBytesBase64(8);
|
|
22
|
+
// Build BRC-29 locking script
|
|
23
|
+
const keyDeriver = setup.keyDeriver;
|
|
24
|
+
const t = new ScriptTemplateBRC29({
|
|
25
|
+
derivationPrefix,
|
|
26
|
+
derivationSuffix,
|
|
27
|
+
keyDeriver,
|
|
28
|
+
});
|
|
29
|
+
// Determine the recipient identity key.
|
|
30
|
+
// If `to` is a compressed public key hex (66 chars, starts with 02/03), use directly.
|
|
31
|
+
// Otherwise treat as an address — for BRC-29 we need a public key.
|
|
32
|
+
let recipientPubKey;
|
|
33
|
+
if (/^0[23][0-9a-fA-F]{64}$/.test(to)) {
|
|
34
|
+
recipientPubKey = to;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
// If it's an address, we can't do BRC-29 (needs pubkey). Throw a clear error.
|
|
38
|
+
throw new Error('PaymentParams.to must be a compressed public key (hex) for BRC-29 payments. ' +
|
|
39
|
+
'Raw BSV addresses are not supported — the recipient must share their identity key.');
|
|
40
|
+
}
|
|
41
|
+
const lockingScript = t.lock(setup.rootKey.toString(), recipientPubKey);
|
|
42
|
+
const label = 'a2a-payment';
|
|
43
|
+
const car = await setup.wallet.createAction({
|
|
44
|
+
outputs: [
|
|
45
|
+
{
|
|
46
|
+
lockingScript: lockingScript.toHex(),
|
|
47
|
+
satoshis,
|
|
48
|
+
outputDescription: desc,
|
|
49
|
+
tags: ['relinquish'],
|
|
50
|
+
customInstructions: JSON.stringify({
|
|
51
|
+
derivationPrefix,
|
|
52
|
+
derivationSuffix,
|
|
53
|
+
type: 'BRC29',
|
|
54
|
+
}),
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
options: {
|
|
58
|
+
randomizeOutputs: false,
|
|
59
|
+
acceptDelayedBroadcast: false,
|
|
60
|
+
},
|
|
61
|
+
labels: [label],
|
|
62
|
+
description: desc,
|
|
63
|
+
});
|
|
64
|
+
// Extract the txid from the createAction result.
|
|
65
|
+
// The tx field is a number[] (AtomicBEEF binary). Parse it to get txid.
|
|
66
|
+
if (!car.tx) {
|
|
67
|
+
throw new Error('createAction did not return a transaction. Check wallet funding.');
|
|
68
|
+
}
|
|
69
|
+
const beef = Beef.fromBinary(car.tx);
|
|
70
|
+
// The last transaction in the beef is our new tx
|
|
71
|
+
const lastTx = beef.txs[beef.txs.length - 1];
|
|
72
|
+
const txid = lastTx.txid;
|
|
73
|
+
// Encode the atomic BEEF as base64
|
|
74
|
+
const atomicBinary = beef.toBinaryAtomic(txid);
|
|
75
|
+
const beefBase64 = Utils.toBase64(atomicBinary);
|
|
76
|
+
return {
|
|
77
|
+
beef: beefBase64,
|
|
78
|
+
txid,
|
|
79
|
+
satoshis,
|
|
80
|
+
derivationPrefix,
|
|
81
|
+
derivationSuffix,
|
|
82
|
+
senderIdentityKey: setup.identityKey,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Ensure description meets BRC-100's 5-50 character requirement.
|
|
87
|
+
*/
|
|
88
|
+
function normalizeDescription(desc) {
|
|
89
|
+
if (desc.length < 5)
|
|
90
|
+
return desc.padEnd(5, ' ');
|
|
91
|
+
if (desc.length > 50)
|
|
92
|
+
return desc.slice(0, 50);
|
|
93
|
+
return desc;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=payment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment.js","sourceRoot":"","sources":["../../../src/core/payment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAK7E;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,KAAkB,EAClB,MAAqB;IAErB,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;IAC7C,MAAM,IAAI,GAAG,oBAAoB,CAAC,WAAW,IAAI,eAAe,CAAC,CAAC;IAElE,0DAA0D;IAC1D,MAAM,gBAAgB,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAC9C,MAAM,gBAAgB,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAE9C,8BAA8B;IAC9B,MAAM,UAAU,GAAG,KAAK,CAAC,UAA8B,CAAC;IACxD,MAAM,CAAC,GAAG,IAAI,mBAAmB,CAAC;QAChC,gBAAgB;QAChB,gBAAgB;QAChB,UAAU;KACX,CAAC,CAAC;IAEH,wCAAwC;IACxC,sFAAsF;IACtF,mEA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