openclaw-storage-plugin 0.1.3 → 0.1.4
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 +38 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -13
- package/dist/index.js.map +1 -1
- package/dist/src/client.d.ts +8 -0
- package/dist/src/client.d.ts.map +1 -0
- package/dist/src/client.js +45 -0
- package/dist/src/client.js.map +1 -0
- 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/dist/src/types.d.ts +11 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/index.ts +36 -13
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/src/client.ts +56 -0
- 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/src/types.ts +11 -0
package/README.md
CHANGED
|
@@ -7,10 +7,45 @@ A programmatic OpenClaw plugin that enables hash-based permanent storage for AI
|
|
|
7
7
|
- **Efficiency**: Agents share large files via hashes instead of large message bodies.
|
|
8
8
|
- **Shared Identity**: Uses the same BSV wallet as your other OpenClaw plugins.
|
|
9
9
|
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Configuration
|
|
13
|
+
|
|
14
|
+
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.
|
|
15
|
+
|
|
16
|
+
### Example Configuration
|
|
17
|
+
```json
|
|
18
|
+
{
|
|
19
|
+
"plugins": {
|
|
20
|
+
"entries": {
|
|
21
|
+
"openclaw-storage-plugin": {
|
|
22
|
+
"enabled": true,
|
|
23
|
+
"storageHost": "https://storage.bsv.direct",
|
|
24
|
+
"walletDir": "~/.openclaw/bsv-wallet"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Options
|
|
32
|
+
|
|
33
|
+
| Option | Default | Description |
|
|
34
|
+
| :--- | :--- | :--- |
|
|
35
|
+
| `storageHost` | `https://storage.bsv.direct` | Preferred UHRP storage host URL. |
|
|
36
|
+
| `walletDir` | `~/.openclaw/bsv-wallet` | Directory where `wallet-identity.json` is stored. |
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
10
40
|
## AI Tool: `storage`
|
|
11
|
-
Agents can use the `storage` tool to:
|
|
12
|
-
|
|
13
|
-
|
|
41
|
+
Agents can use the `storage` tool to perform the following actions:
|
|
42
|
+
|
|
43
|
+
| Action | Description |
|
|
44
|
+
| :--- | :--- |
|
|
45
|
+
| `upload` | Save local content to a UHRP storage host and get its hash. |
|
|
46
|
+
| `download` | Retrieve and verify content using a SHA256 hash. |
|
|
47
|
+
| `list` | See all files uploaded or cached by this agent. |
|
|
48
|
+
| `status` | Check storage host connection and protocol status. |
|
|
14
49
|
|
|
15
50
|
## Architecture
|
|
16
51
|
Built with the **OpenClaw Plugin SDK**, this extension interfaces with UHRP storage servers to provide agents with a decentralized "hard drive."
|
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":"AAIA;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,GAAG,EAAE,GAAG,QA8ExC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import os from "node:os";
|
|
3
|
+
import { StorageManager } from "./src/client.js";
|
|
3
4
|
/**
|
|
4
5
|
* OpenClaw Storage Plugin
|
|
5
6
|
* Enables UHRP hash-based storage for agent data.
|
|
@@ -8,17 +9,22 @@ export default function register(api) {
|
|
|
8
9
|
const entries = api.getConfig?.()?.plugins?.entries || {};
|
|
9
10
|
const entry = entries['openclaw-storage']
|
|
10
11
|
|| entries['openclaw-storage-plugin']
|
|
11
|
-
|| entries['bsv-storage']
|
|
12
12
|
|| {};
|
|
13
13
|
const pluginConfig = { ...entry, ...(entry.config || {}), ...(api.config || {}) };
|
|
14
14
|
const storageHost = pluginConfig.storageHost || 'https://storage.bsv.direct';
|
|
15
|
-
const network = pluginConfig.network || 'mainnet';
|
|
16
15
|
const walletDir = pluginConfig.walletDir || path.join(os.homedir(), '.openclaw', 'bsv-wallet');
|
|
17
|
-
|
|
16
|
+
let manager = null;
|
|
17
|
+
api.logger.info(`[storage] Initializing Storage Plugin (host: ${storageHost})`);
|
|
18
|
+
function ensureInitialized() {
|
|
19
|
+
if (manager)
|
|
20
|
+
return manager;
|
|
21
|
+
manager = new StorageManager({ storageHost, walletDir });
|
|
22
|
+
return manager;
|
|
23
|
+
}
|
|
18
24
|
// Register the storage tool
|
|
19
25
|
api.registerTool({
|
|
20
26
|
name: "storage",
|
|
21
|
-
description: "Hash-based permanent storage for large assets",
|
|
27
|
+
description: "Hash-based permanent storage for large assets via UHRP",
|
|
22
28
|
parameters: {
|
|
23
29
|
type: "object",
|
|
24
30
|
properties: {
|
|
@@ -29,24 +35,37 @@ export default function register(api) {
|
|
|
29
35
|
},
|
|
30
36
|
data: {
|
|
31
37
|
type: "string",
|
|
32
|
-
description: "Content to upload"
|
|
38
|
+
description: "Content to upload (UTF-8 string)"
|
|
33
39
|
},
|
|
34
40
|
hash: {
|
|
35
41
|
type: "string",
|
|
36
|
-
description: "UHRP hash to download"
|
|
42
|
+
description: "SHA256 UHRP hash to download"
|
|
37
43
|
}
|
|
38
44
|
},
|
|
39
45
|
required: ["action"]
|
|
40
46
|
},
|
|
41
47
|
async execute(_id, params) {
|
|
42
48
|
try {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
const m = ensureInitialized();
|
|
50
|
+
switch (params.action) {
|
|
51
|
+
case "upload":
|
|
52
|
+
if (!params.data)
|
|
53
|
+
throw new Error("data is required for upload");
|
|
54
|
+
const hash = await m.upload(params.data);
|
|
55
|
+
return { content: [{ type: "text", text: `✅ Uploaded successfully!\nUHRP Hash: ${hash}\nURL: ${storageHost}/cdn/${hash}` }] };
|
|
56
|
+
case "download":
|
|
57
|
+
if (!params.hash)
|
|
58
|
+
throw new Error("hash is required for download");
|
|
59
|
+
const buffer = await m.download(params.hash);
|
|
60
|
+
const content = buffer.toString('utf-8');
|
|
61
|
+
return { content: [{ type: "text", text: `📥 Downloaded Content (Verified):\n\n${content}` }] };
|
|
62
|
+
case "status":
|
|
63
|
+
return { content: [{ type: "text", text: `Storage Status:\nHost: ${storageHost}\nMode: UHRP Content-Addressable` }] };
|
|
64
|
+
case "list":
|
|
65
|
+
return { content: [{ type: "text", text: "Local file index integration pending logic development." }] };
|
|
66
|
+
default:
|
|
67
|
+
throw new Error(`Unknown action: ${params.action}`);
|
|
68
|
+
}
|
|
50
69
|
}
|
|
51
70
|
catch (error) {
|
|
52
71
|
return {
|
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;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,GAAQ;IACvC,MAAM,OAAO,GAAG,GAAG,CAAC,SAAS,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,IAAI,EAAE,CAAC;IAC1D,MAAM,KAAK,GAAG,OAAO,CAAC,kBAAkB,CAAC;WACpC,OAAO,CAAC,yBAAyB,CAAC;WAClC,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,WAAW,GAAG,YAAY,CAAC,WAAW,IAAI,4BAA4B,CAAC;IAC7E,MAAM,SAAS,GAAG,YAAY,CAAC,SAAS,IAAI,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC;IAE/F,IAAI,OAAO,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U,WAAW,QAAQ,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC;oBAEhI,KAAK,UAAU;wBACb,IAAI,CAAC,MAAM,CAAC,IAAI;4BAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;wBACnE,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;wBAC7C,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;wBACzC,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,wCAAwC,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC;oBAElG,KAAK,QAAQ;wBACX,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,0BAA0B,WAAW,kCAAkC,EAAE,CAAC,EAAE,CAAC;oBAExH,KAAK,MAAM;wBACT,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,yDAAyD,EAAE,CAAC,EAAE,CAAC;oBAE1G;wBACE,MAAM,IAAI,KAAK,CAAC,mBAAmB,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;gBACxD,CAAC;YACH,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,OAAO;oBACL,OAAO,EAAE,CAAC;4BACR,IAAI,EAAE,MAAM;4BACZ,IAAI,EAAE,UAAU,KAAK,CAAC,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE;yBACjD,CAAC;iBACH,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { StorageConfig } from './types.js';
|
|
2
|
+
export declare class StorageManager {
|
|
3
|
+
private config;
|
|
4
|
+
constructor(config: StorageConfig);
|
|
5
|
+
upload(data: Buffer | string): Promise<string>;
|
|
6
|
+
download(hash: string): Promise<Buffer>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAc,MAAM,YAAY,CAAC;AAEvD,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAgB;gBAElB,MAAM,EAAE,aAAa;IAI3B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA2B9C,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAkB9C"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Utils, Hash } from '@bsv/sdk';
|
|
2
|
+
export class StorageManager {
|
|
3
|
+
config;
|
|
4
|
+
constructor(config) {
|
|
5
|
+
this.config = config;
|
|
6
|
+
}
|
|
7
|
+
async upload(data) {
|
|
8
|
+
const buffer = typeof data === 'string' ? Buffer.from(data) : data;
|
|
9
|
+
const hash = Utils.toHex(Hash.sha256(buffer));
|
|
10
|
+
const host = this.config.storageHost.replace(/\/$/, '');
|
|
11
|
+
// 1. Check if it already exists
|
|
12
|
+
const headResp = await fetch(`${host}/cdn/${hash}`, { method: 'HEAD' });
|
|
13
|
+
if (headResp.ok)
|
|
14
|
+
return hash;
|
|
15
|
+
// 2. Upload
|
|
16
|
+
const uploadResp = await fetch(`${host}/upload`, {
|
|
17
|
+
method: 'POST',
|
|
18
|
+
headers: {
|
|
19
|
+
'Content-Type': 'application/octet-stream',
|
|
20
|
+
'X-UHRP-Hash': hash
|
|
21
|
+
},
|
|
22
|
+
body: buffer
|
|
23
|
+
});
|
|
24
|
+
if (!uploadResp.ok) {
|
|
25
|
+
const err = await uploadResp.text();
|
|
26
|
+
throw new Error(`Upload failed: ${uploadResp.status} ${err}`);
|
|
27
|
+
}
|
|
28
|
+
return hash;
|
|
29
|
+
}
|
|
30
|
+
async download(hash) {
|
|
31
|
+
const host = this.config.storageHost.replace(/\/$/, '');
|
|
32
|
+
const resp = await fetch(`${host}/cdn/${hash}`);
|
|
33
|
+
if (!resp.ok) {
|
|
34
|
+
throw new Error(`Download failed: ${resp.status}`);
|
|
35
|
+
}
|
|
36
|
+
const buffer = Buffer.from(await resp.arrayBuffer());
|
|
37
|
+
// Integrity verification
|
|
38
|
+
const downloadedHash = Utils.toHex(Hash.sha256(buffer));
|
|
39
|
+
if (downloadedHash !== hash) {
|
|
40
|
+
throw new Error(`Integrity check failed: Expected ${hash}, got ${downloadedHash}`);
|
|
41
|
+
}
|
|
42
|
+
return buffer;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAGvC,MAAM,OAAO,cAAc;IACjB,MAAM,CAAgB;IAE9B,YAAY,MAAqB;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,IAAqB;QAChC,MAAM,MAAM,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACnE,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;QAC9C,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAExD,gCAAgC;QAChC,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,QAA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cAAc,EAAE,CAAC,CAAC;QACrF,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,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;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allet configuration for creating or loading an agent wallet. */
|
|
5
|
+
export interface WalletConfig {
|
|
6
|
+
/** BSV network to use. */
|
|
7
|
+
network: 'mainnet' | 'testnet';
|
|
8
|
+
/** Directory path for SQLite wallet persistence. */
|
|
9
|
+
storageDir: string;
|
|
10
|
+
/** Optional: pre-existing root private key hex. If omitted on create(), a new one is generated. */
|
|
11
|
+
rootKeyHex?: string;
|
|
12
|
+
/** Optional TAAL API key for ARC broadcasting. Falls back to public default. */
|
|
13
|
+
taalApiKey?: string;
|
|
14
|
+
/** Optional fee model in sat/KB. Falls back to BSV_FEE_MODEL env var or default 100 sat/KB. */
|
|
15
|
+
feeModel?: number;
|
|
16
|
+
}
|
|
17
|
+
/** Parameters for building a payment transaction. */
|
|
18
|
+
export interface PaymentParams {
|
|
19
|
+
/** Recipient's compressed public key (hex) or BSV address. */
|
|
20
|
+
to: string;
|
|
21
|
+
/** Amount to pay in satoshis. */
|
|
22
|
+
satoshis: number;
|
|
23
|
+
/** Human-readable description (5-50 chars per BRC-100). */
|
|
24
|
+
description?: string;
|
|
25
|
+
/** Optional metadata embedded as OP_RETURN (future use). */
|
|
26
|
+
metadata?: {
|
|
27
|
+
taskId?: string;
|
|
28
|
+
protocol?: string;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** Result from building a payment. */
|
|
32
|
+
export interface PaymentResult {
|
|
33
|
+
/** Base64-encoded Atomic BEEF transaction data. */
|
|
34
|
+
beef: string;
|
|
35
|
+
/** Transaction ID (hex). */
|
|
36
|
+
txid: string;
|
|
37
|
+
/** Amount paid in satoshis. */
|
|
38
|
+
satoshis: number;
|
|
39
|
+
/** BRC-29 derivation prefix (base64). Needed by recipient to internalize. */
|
|
40
|
+
derivationPrefix: string;
|
|
41
|
+
/** BRC-29 derivation suffix (base64). Needed by recipient to internalize. */
|
|
42
|
+
derivationSuffix: string;
|
|
43
|
+
/** Sender's identity key (compressed hex). Needed by recipient to internalize. */
|
|
44
|
+
senderIdentityKey: string;
|
|
45
|
+
}
|
|
46
|
+
/** Parameters for verifying an incoming payment. */
|
|
47
|
+
export interface VerifyParams {
|
|
48
|
+
/** Base64-encoded Atomic BEEF data. */
|
|
49
|
+
beef: string;
|
|
50
|
+
/** Expected payment amount in satoshis. */
|
|
51
|
+
expectedAmount?: number;
|
|
52
|
+
/** Expected sender identity key (optional). */
|
|
53
|
+
expectedSender?: string;
|
|
54
|
+
}
|
|
55
|
+
/** Result from verifying a payment. */
|
|
56
|
+
export interface VerifyResult {
|
|
57
|
+
/** Whether the payment passes all checks. */
|
|
58
|
+
valid: boolean;
|
|
59
|
+
/** Transaction ID (hex). */
|
|
60
|
+
txid: string;
|
|
61
|
+
/** Number of outputs found in the transaction. */
|
|
62
|
+
outputCount: number;
|
|
63
|
+
/** Errors encountered during verification. */
|
|
64
|
+
errors: string[];
|
|
65
|
+
}
|
|
66
|
+
/** Parameters for accepting (internalizing) a verified payment. */
|
|
67
|
+
export interface AcceptParams {
|
|
68
|
+
/** Base64-encoded Atomic BEEF data. */
|
|
69
|
+
beef: string;
|
|
70
|
+
/** The output index to internalize (default: 0). */
|
|
71
|
+
vout?: number;
|
|
72
|
+
/** BRC-29 derivation prefix from the PaymentResult. */
|
|
73
|
+
derivationPrefix: string;
|
|
74
|
+
/** BRC-29 derivation suffix from the PaymentResult. */
|
|
75
|
+
derivationSuffix: string;
|
|
76
|
+
/** Sender's identity key from the PaymentResult. */
|
|
77
|
+
senderIdentityKey: string;
|
|
78
|
+
/** Human-readable description for wallet records (5-50 chars). */
|
|
79
|
+
description?: string;
|
|
80
|
+
}
|
|
81
|
+
/** Result from accepting a payment. */
|
|
82
|
+
export interface AcceptResult {
|
|
83
|
+
/** Whether the payment was accepted. */
|
|
84
|
+
accepted: boolean;
|
|
85
|
+
}
|
|
86
|
+
/** Serializable wallet identity info, persisted alongside the SQLite database. */
|
|
87
|
+
export interface WalletIdentity {
|
|
88
|
+
/** The root private key (hex). Guard this carefully. */
|
|
89
|
+
rootKeyHex: string;
|
|
90
|
+
/** The wallet's public identity key (compressed hex). */
|
|
91
|
+
identityKey: string;
|
|
92
|
+
/** Network this wallet targets. */
|
|
93
|
+
network: 'mainnet' | 'testnet';
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,oEAAoE;AACpE,MAAM,WAAW,YAAY;IAC3B,0BAA0B;IAC1B,OAAO,EAAE,SAAS,GAAG,SAAS,CAAC;IAC/B,oDAAoD;IACpD,UAAU,EAAE,MAAM,CAAC;IACnB,mGAAmG;IACnG,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gFAAgF;IAChF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,+FAA+F;IAC/F,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,qDAAqD;AACrD,MAAM,WAAW,aAAa;IAC5B,8DAA8D;IAC9D,EAAE,EAAE,MAAM,CAAC;IACX,iCAAiC;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,2DAA2D;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,QAAQ,CAAC,EAAE;QACT,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED,sCAAsC;AACtC,MAAM,WAAW,aAAa;IAC5B,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,6EAA6E;IAC7E,gBAAgB,EAAE,MAAM,CAAC;IACzB,6EAA6E;IAC7E,gBAAgB,EAAE,MAAM,CAAC;IACzB,kFAAkF;IAClF,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,oDAAoD;AACpD,MAAM,WAAW,YAAY;IAC3B,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,2CAA2C;IAC3C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,+CAA+C;IAC/C,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,uCAAuC;AACvC,MAAM,WAAW,YAAY;IAC3B,6CAA6C;IAC7C,KAAK,EAAE,OAAO,CAAC;IACf,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,kDAAkD;IAClD,WAAW,EAAE,MAAM,CAAC;IACpB,8CAA8C;IAC9C,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,mEAAmE;AACnE,MAAM,WAAW,YAAY;IAC3B,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uDAAuD;IACvD,gBAAgB,EAAE,MAAM,CAAC;IACzB,uDAAuD;IACvD,gBAAgB,EAAE,MAAM,CAAC;IACzB,oDAAoD;IACpD,iBAAiB,EAAE,MAAM,CAAC;IAC1B,kEAAkE;IAClE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,uCAAuC;AACvC,MAAM,WAAW,YAAY;IAC3B,wCAAwC;IACxC,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,kFAAkF;AAClF,MAAM,WAAW,cAAc;IAC7B,wDAAwD;IACxD,UAAU,EAAE,MAAM,CAAC;IACnB,yDAAyD;IACzD,WAAW,EAAE,MAAM,CAAC;IACpB,mCAAmC;IACnC,OAAO,EAAE,SAAS,GAAG,SAAS,CAAC;CAChC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @a2a-bsv/core — Payment verification and acceptance helpers.
|
|
3
|
+
*
|
|
4
|
+
* Verification: parse the Atomic BEEF, validate structure.
|
|
5
|
+
* Acceptance: internalize the payment into the recipient wallet via BRC-29
|
|
6
|
+
* wallet payment protocol.
|
|
7
|
+
*/
|
|
8
|
+
import type { SetupWallet } from '@bsv/wallet-toolbox';
|
|
9
|
+
import type { VerifyParams, VerifyResult, AcceptParams, AcceptResult } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Verify an incoming Atomic BEEF payment.
|
|
12
|
+
*
|
|
13
|
+
* This performs structural validation:
|
|
14
|
+
* - Decodes the base64 BEEF
|
|
15
|
+
* - Checks the BEEF is parseable
|
|
16
|
+
* - Checks there is at least one transaction
|
|
17
|
+
* - Runs SPV verification via tx.verify()
|
|
18
|
+
* - Optionally checks the sender identity key
|
|
19
|
+
*/
|
|
20
|
+
export declare function verifyPayment(params: VerifyParams): Promise<VerifyResult>;
|
|
21
|
+
/**
|
|
22
|
+
* Accept (internalize) a verified BRC-29 payment into the recipient's wallet.
|
|
23
|
+
*
|
|
24
|
+
* This calls wallet.internalizeAction with the 'wallet payment' protocol,
|
|
25
|
+
* providing the BRC-29 derivation info so the wallet can derive the correct
|
|
26
|
+
* key and claim the output.
|
|
27
|
+
*/
|
|
28
|
+
export declare function acceptPayment(setup: SetupWallet, params: AcceptParams): Promise<AcceptResult>;
|
|
29
|
+
//# sourceMappingURL=verify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../src/core/verify.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAGzF;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAkD/E;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,KAAK,EAAE,WAAW,EAClB,MAAM,EAAE,YAAY,GACnB,OAAO,CAAC,YAAY,CAAC,CA2BvB"}
|