bsv-mcp 0.0.17 → 0.0.18
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/index.ts +1 -1
- package/package.json +1 -1
- package/tools/wallet/schemas.ts +5 -13
- package/tools/wallet/tools.ts +13 -15
package/index.ts
CHANGED
package/package.json
CHANGED
package/tools/wallet/schemas.ts
CHANGED
|
@@ -74,21 +74,13 @@ export const walletDecryptArgsSchema = z.object({
|
|
|
74
74
|
|
|
75
75
|
// Combined wallet encryption/decryption args
|
|
76
76
|
export const walletEncryptionArgsSchema = z.object({
|
|
77
|
-
mode: z.enum(["encrypt", "decrypt"]).describe("Operation mode: 'encrypt' to encrypt
|
|
77
|
+
mode: z.enum(["encrypt", "decrypt"]).describe("Operation mode: 'encrypt' to encrypt plaintext or 'decrypt' to decrypt data"),
|
|
78
78
|
data: z.union([
|
|
79
|
-
z.string().describe("Text data
|
|
80
|
-
z.array(z.number()).describe("Binary data
|
|
81
|
-
]).describe("Data to process:
|
|
79
|
+
z.string().describe("Text data to encrypt or decrypt"),
|
|
80
|
+
z.array(z.number()).describe("Binary data to encrypt or decrypt")
|
|
81
|
+
]).describe("Data to process: text/data for encryption or decryption"),
|
|
82
82
|
encoding: z.enum(["utf8", "hex", "base64"]).optional().default("utf8").describe("Encoding of text data (default: utf8)"),
|
|
83
|
-
|
|
84
|
-
keyID: z.string().describe("Key identifier - use 'default' or 'primary' for the default wallet key"),
|
|
85
|
-
privilegedReason: z.string().optional().describe("Required reason for privileged operations"),
|
|
86
|
-
counterparty: z
|
|
87
|
-
.union([z.string(), z.literal("self"), z.literal("anyone")])
|
|
88
|
-
.optional()
|
|
89
|
-
.describe("Recipient of encryption. Use 'self' for personal encryption, or provide a specific key for a recipient"),
|
|
90
|
-
privileged: z.boolean().optional().describe("Indicates if operation requires elevated privileges"),
|
|
91
|
-
}).describe("Combined schema for encryption and decryption operations. Use 'mode' to specify the operation type, with required parameters data, protocolID, and keyID.");
|
|
83
|
+
}).describe("Schema for encryption and decryption operations");
|
|
92
84
|
|
|
93
85
|
// Create HMAC arguments
|
|
94
86
|
export const createHmacArgsSchema = z.object({
|
package/tools/wallet/tools.ts
CHANGED
|
@@ -39,7 +39,7 @@ import type { createOrdinalsArgsSchema } from "./createOrdinals";
|
|
|
39
39
|
import { registerGetAddressTool } from "./getAddress";
|
|
40
40
|
import { registerPurchaseListingTool } from "./purchaseListing";
|
|
41
41
|
import { registerSendToAddressTool } from "./sendToAddress";
|
|
42
|
-
import { Utils } from "@bsv/sdk";
|
|
42
|
+
import { Utils, type WalletProtocol } from "@bsv/sdk";
|
|
43
43
|
|
|
44
44
|
// Define mapping from tool names to argument schemas
|
|
45
45
|
type ToolArgSchemas = {
|
|
@@ -177,24 +177,18 @@ export function registerWalletTools(
|
|
|
177
177
|
"Combined tool for encrypting and decrypting data using the wallet's cryptographic keys.\n\n" +
|
|
178
178
|
"PARAMETERS:\n" +
|
|
179
179
|
"- mode: (required) Either \"encrypt\" to encrypt plaintext or \"decrypt\" to decrypt ciphertext\n" +
|
|
180
|
-
"- data: (required) Text string or array of numbers to process
|
|
181
|
-
"- encoding: (optional) For text input, the encoding format (utf8, hex, base64) - default is utf8\n" +
|
|
182
|
-
"- protocolID: (required) Protocol identifier - common values are 'aes' for symmetric encryption or 'ecies' for asymmetric encryption\n" +
|
|
183
|
-
"- keyID: (required) Key identifier - use 'default' or 'primary' for the default wallet key\n\n" +
|
|
180
|
+
"- data: (required) Text string or array of numbers to process\n" +
|
|
181
|
+
"- encoding: (optional) For text input, the encoding format (utf8, hex, base64) - default is utf8\n\n" +
|
|
184
182
|
"EXAMPLES:\n" +
|
|
185
183
|
"1. Encrypt text data:\n" +
|
|
186
184
|
" {\n" +
|
|
187
185
|
" \"mode\": \"encrypt\",\n" +
|
|
188
|
-
" \"data\": \"Hello World\"
|
|
189
|
-
" \"protocolID\": [1, \"aes\"],\n" +
|
|
190
|
-
" \"keyID\": \"default\"\n" +
|
|
186
|
+
" \"data\": \"Hello World\"\n" +
|
|
191
187
|
" }\n\n" +
|
|
192
188
|
"2. Decrypt previously encrypted data:\n" +
|
|
193
189
|
" {\n" +
|
|
194
190
|
" \"mode\": \"decrypt\",\n" +
|
|
195
|
-
" \"data\": [encrypted bytes from previous response]
|
|
196
|
-
" \"protocolID\": [1, \"aes\"],\n" +
|
|
197
|
-
" \"keyID\": \"default\"\n" +
|
|
191
|
+
" \"data\": [encrypted bytes from previous response]\n" +
|
|
198
192
|
" }",
|
|
199
193
|
{ args: walletEncryptionArgsSchema },
|
|
200
194
|
async (
|
|
@@ -202,7 +196,11 @@ export function registerWalletTools(
|
|
|
202
196
|
extra: RequestHandlerExtra,
|
|
203
197
|
) => {
|
|
204
198
|
try {
|
|
205
|
-
const { mode, data,
|
|
199
|
+
const { mode, data, encoding } = args;
|
|
200
|
+
|
|
201
|
+
// Set default values for required parameters
|
|
202
|
+
const protocolID: WalletProtocol = [1, "aes256"];
|
|
203
|
+
const keyID = "default";
|
|
206
204
|
|
|
207
205
|
// Convert string data to binary if needed
|
|
208
206
|
let binaryData: number[];
|
|
@@ -214,7 +212,7 @@ export function registerWalletTools(
|
|
|
214
212
|
binaryData = toArray(data, encoding || "utf8");
|
|
215
213
|
}
|
|
216
214
|
|
|
217
|
-
let result: { ciphertext?: number[]; plaintext?: number[] } = {};
|
|
215
|
+
let result: { ciphertext?: number[]; plaintext?: number[] | string } = {};
|
|
218
216
|
if (mode === "encrypt") {
|
|
219
217
|
result = await wallet.encrypt({
|
|
220
218
|
plaintext: binaryData,
|
|
@@ -229,10 +227,10 @@ export function registerWalletTools(
|
|
|
229
227
|
});
|
|
230
228
|
|
|
231
229
|
// For decryption, convert plaintext back to string if it's likely UTF-8 text
|
|
232
|
-
if (result.plaintext) {
|
|
230
|
+
if (result.plaintext as number[]) {
|
|
233
231
|
try {
|
|
234
232
|
const { toUTF8 } = Utils;
|
|
235
|
-
const textResult = toUTF8(result.plaintext);
|
|
233
|
+
const textResult = toUTF8(result.plaintext as number[]);
|
|
236
234
|
// If conversion succeeds and seems like valid text, return as string
|
|
237
235
|
if (textResult && textResult.length > 0) {
|
|
238
236
|
return {
|