@aibtc/mcp-server 1.0.0
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 +340 -0
- package/dist/api.d.ts +9 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +79 -0
- package/dist/api.js.map +1 -0
- package/dist/config/contracts.d.ts +169 -0
- package/dist/config/contracts.d.ts.map +1 -0
- package/dist/config/contracts.js +250 -0
- package/dist/config/contracts.js.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +3 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/networks.d.ts +11 -0
- package/dist/config/networks.d.ts.map +1 -0
- package/dist/config/networks.js +21 -0
- package/dist/config/networks.js.map +1 -0
- package/dist/endpoints/index.d.ts +2 -0
- package/dist/endpoints/index.d.ts.map +1 -0
- package/dist/endpoints/index.js +2 -0
- package/dist/endpoints/index.js.map +1 -0
- package/dist/endpoints/registry.d.ts +38 -0
- package/dist/endpoints/registry.d.ts.map +1 -0
- package/dist/endpoints/registry.js +935 -0
- package/dist/endpoints/registry.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +79 -0
- package/dist/index.js.map +1 -0
- package/dist/services/bitflow.service.d.ts +159 -0
- package/dist/services/bitflow.service.d.ts.map +1 -0
- package/dist/services/bitflow.service.js +325 -0
- package/dist/services/bitflow.service.js.map +1 -0
- package/dist/services/bns.service.d.ts +87 -0
- package/dist/services/bns.service.d.ts.map +1 -0
- package/dist/services/bns.service.js +312 -0
- package/dist/services/bns.service.js.map +1 -0
- package/dist/services/defi.service.d.ts +146 -0
- package/dist/services/defi.service.d.ts.map +1 -0
- package/dist/services/defi.service.js +461 -0
- package/dist/services/defi.service.js.map +1 -0
- package/dist/services/hiro-api.d.ts +438 -0
- package/dist/services/hiro-api.d.ts.map +1 -0
- package/dist/services/hiro-api.js +376 -0
- package/dist/services/hiro-api.js.map +1 -0
- package/dist/services/nft.service.d.ts +70 -0
- package/dist/services/nft.service.d.ts.map +1 -0
- package/dist/services/nft.service.js +148 -0
- package/dist/services/nft.service.js.map +1 -0
- package/dist/services/sbtc.service.d.ts +44 -0
- package/dist/services/sbtc.service.d.ts.map +1 -0
- package/dist/services/sbtc.service.js +100 -0
- package/dist/services/sbtc.service.js.map +1 -0
- package/dist/services/scaffold.service.d.ts +41 -0
- package/dist/services/scaffold.service.d.ts.map +1 -0
- package/dist/services/scaffold.service.js +1055 -0
- package/dist/services/scaffold.service.js.map +1 -0
- package/dist/services/stacking.service.d.ts +58 -0
- package/dist/services/stacking.service.d.ts.map +1 -0
- package/dist/services/stacking.service.js +153 -0
- package/dist/services/stacking.service.js.map +1 -0
- package/dist/services/tokens.service.d.ts +62 -0
- package/dist/services/tokens.service.d.ts.map +1 -0
- package/dist/services/tokens.service.js +119 -0
- package/dist/services/tokens.service.js.map +1 -0
- package/dist/services/wallet-manager.d.ts +107 -0
- package/dist/services/wallet-manager.d.ts.map +1 -0
- package/dist/services/wallet-manager.js +389 -0
- package/dist/services/wallet-manager.js.map +1 -0
- package/dist/services/x402.service.d.ts +26 -0
- package/dist/services/x402.service.d.ts.map +1 -0
- package/dist/services/x402.service.js +125 -0
- package/dist/services/x402.service.js.map +1 -0
- package/dist/tools/bitflow.tools.d.ts +3 -0
- package/dist/tools/bitflow.tools.d.ts.map +1 -0
- package/dist/tools/bitflow.tools.js +501 -0
- package/dist/tools/bitflow.tools.js.map +1 -0
- package/dist/tools/bns.tools.d.ts +3 -0
- package/dist/tools/bns.tools.d.ts.map +1 -0
- package/dist/tools/bns.tools.js +164 -0
- package/dist/tools/bns.tools.js.map +1 -0
- package/dist/tools/contract.tools.d.ts +3 -0
- package/dist/tools/contract.tools.d.ts.map +1 -0
- package/dist/tools/contract.tools.js +126 -0
- package/dist/tools/contract.tools.js.map +1 -0
- package/dist/tools/defi.tools.d.ts +3 -0
- package/dist/tools/defi.tools.d.ts.map +1 -0
- package/dist/tools/defi.tools.js +425 -0
- package/dist/tools/defi.tools.js.map +1 -0
- package/dist/tools/endpoint.tools.d.ts +3 -0
- package/dist/tools/endpoint.tools.d.ts.map +1 -0
- package/dist/tools/endpoint.tools.js +157 -0
- package/dist/tools/endpoint.tools.js.map +1 -0
- package/dist/tools/index.d.ts +6 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +52 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/nft.tools.d.ts +3 -0
- package/dist/tools/nft.tools.d.ts.map +1 -0
- package/dist/tools/nft.tools.js +154 -0
- package/dist/tools/nft.tools.js.map +1 -0
- package/dist/tools/openrouter.tools.d.ts +3 -0
- package/dist/tools/openrouter.tools.d.ts.map +1 -0
- package/dist/tools/openrouter.tools.js +664 -0
- package/dist/tools/openrouter.tools.js.map +1 -0
- package/dist/tools/query.tools.d.ts +3 -0
- package/dist/tools/query.tools.d.ts.map +1 -0
- package/dist/tools/query.tools.js +209 -0
- package/dist/tools/query.tools.js.map +1 -0
- package/dist/tools/sbtc.tools.d.ts +3 -0
- package/dist/tools/sbtc.tools.d.ts.map +1 -0
- package/dist/tools/sbtc.tools.js +103 -0
- package/dist/tools/sbtc.tools.js.map +1 -0
- package/dist/tools/scaffold.tools.d.ts +3 -0
- package/dist/tools/scaffold.tools.d.ts.map +1 -0
- package/dist/tools/scaffold.tools.js +216 -0
- package/dist/tools/scaffold.tools.js.map +1 -0
- package/dist/tools/stacking.tools.d.ts +3 -0
- package/dist/tools/stacking.tools.d.ts.map +1 -0
- package/dist/tools/stacking.tools.js +112 -0
- package/dist/tools/stacking.tools.js.map +1 -0
- package/dist/tools/tokens.tools.d.ts +3 -0
- package/dist/tools/tokens.tools.d.ts.map +1 -0
- package/dist/tools/tokens.tools.js +154 -0
- package/dist/tools/tokens.tools.js.map +1 -0
- package/dist/tools/transfer.tools.d.ts +3 -0
- package/dist/tools/transfer.tools.d.ts.map +1 -0
- package/dist/tools/transfer.tools.js +62 -0
- package/dist/tools/transfer.tools.js.map +1 -0
- package/dist/tools/wallet-management.tools.d.ts +6 -0
- package/dist/tools/wallet-management.tools.d.ts.map +1 -0
- package/dist/tools/wallet-management.tools.js +390 -0
- package/dist/tools/wallet-management.tools.js.map +1 -0
- package/dist/tools/wallet.tools.d.ts +3 -0
- package/dist/tools/wallet.tools.d.ts.map +1 -0
- package/dist/tools/wallet.tools.js +105 -0
- package/dist/tools/wallet.tools.js.map +1 -0
- package/dist/transactions/builder.d.ts +56 -0
- package/dist/transactions/builder.d.ts.map +1 -0
- package/dist/transactions/builder.js +134 -0
- package/dist/transactions/builder.js.map +1 -0
- package/dist/transactions/clarity-values.d.ts +67 -0
- package/dist/transactions/clarity-values.d.ts.map +1 -0
- package/dist/transactions/clarity-values.js +169 -0
- package/dist/transactions/clarity-values.js.map +1 -0
- package/dist/transactions/post-conditions.d.ts +27 -0
- package/dist/transactions/post-conditions.d.ts.map +1 -0
- package/dist/transactions/post-conditions.js +101 -0
- package/dist/transactions/post-conditions.js.map +1 -0
- package/dist/utils/encryption.d.ts +33 -0
- package/dist/utils/encryption.d.ts.map +1 -0
- package/dist/utils/encryption.js +110 -0
- package/dist/utils/encryption.js.map +1 -0
- package/dist/utils/errors.d.ts +84 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +132 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/formatting.d.ts +51 -0
- package/dist/utils/formatting.d.ts.map +1 -0
- package/dist/utils/formatting.js +114 -0
- package/dist/utils/formatting.js.map +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +6 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/storage.d.ts +90 -0
- package/dist/utils/storage.d.ts.map +1 -0
- package/dist/utils/storage.js +196 -0
- package/dist/utils/storage.js.map +1 -0
- package/dist/utils/validation.d.ts +67 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +74 -0
- package/dist/utils/validation.js.map +1 -0
- package/dist/wallet.d.ts +86 -0
- package/dist/wallet.d.ts.map +1 -0
- package/dist/wallet.js +279 -0
- package/dist/wallet.js.map +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import crypto from "crypto";
|
|
2
|
+
// Scrypt parameters - memory-hard to resist GPU/ASIC attacks
|
|
3
|
+
const SCRYPT_PARAMS = {
|
|
4
|
+
N: 16384, // 2^14 - CPU/memory cost
|
|
5
|
+
r: 8, // Block size
|
|
6
|
+
p: 1, // Parallelization
|
|
7
|
+
keyLen: 32, // 256 bits for AES-256
|
|
8
|
+
};
|
|
9
|
+
const CURRENT_VERSION = 1;
|
|
10
|
+
/**
|
|
11
|
+
* Derive encryption key from password using Scrypt
|
|
12
|
+
*/
|
|
13
|
+
function deriveKey(password, salt) {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
crypto.scrypt(password, salt, SCRYPT_PARAMS.keyLen, {
|
|
16
|
+
N: SCRYPT_PARAMS.N,
|
|
17
|
+
r: SCRYPT_PARAMS.r,
|
|
18
|
+
p: SCRYPT_PARAMS.p,
|
|
19
|
+
}, (err, derivedKey) => {
|
|
20
|
+
if (err) {
|
|
21
|
+
reject(err);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
resolve(derivedKey);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Encrypt plaintext with password using AES-256-GCM
|
|
31
|
+
*/
|
|
32
|
+
export async function encrypt(plaintext, password) {
|
|
33
|
+
// Generate random salt and IV
|
|
34
|
+
const salt = crypto.randomBytes(32);
|
|
35
|
+
const iv = crypto.randomBytes(12); // GCM recommended IV size
|
|
36
|
+
// Derive key from password
|
|
37
|
+
const key = await deriveKey(password, salt);
|
|
38
|
+
// Encrypt with AES-256-GCM
|
|
39
|
+
const cipher = crypto.createCipheriv("aes-256-gcm", key, iv);
|
|
40
|
+
const encrypted = Buffer.concat([
|
|
41
|
+
cipher.update(plaintext, "utf8"),
|
|
42
|
+
cipher.final(),
|
|
43
|
+
]);
|
|
44
|
+
const authTag = cipher.getAuthTag();
|
|
45
|
+
return {
|
|
46
|
+
ciphertext: encrypted.toString("base64"),
|
|
47
|
+
iv: iv.toString("base64"),
|
|
48
|
+
authTag: authTag.toString("base64"),
|
|
49
|
+
salt: salt.toString("base64"),
|
|
50
|
+
scryptParams: SCRYPT_PARAMS,
|
|
51
|
+
version: CURRENT_VERSION,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Decrypt ciphertext with password using AES-256-GCM
|
|
56
|
+
*/
|
|
57
|
+
export async function decrypt(encrypted, password) {
|
|
58
|
+
// Decode from base64
|
|
59
|
+
const ciphertext = Buffer.from(encrypted.ciphertext, "base64");
|
|
60
|
+
const iv = Buffer.from(encrypted.iv, "base64");
|
|
61
|
+
const authTag = Buffer.from(encrypted.authTag, "base64");
|
|
62
|
+
const salt = Buffer.from(encrypted.salt, "base64");
|
|
63
|
+
// Derive key using stored parameters
|
|
64
|
+
const key = await deriveKeyWithParams(password, salt, encrypted.scryptParams);
|
|
65
|
+
// Decrypt with AES-256-GCM
|
|
66
|
+
const decipher = crypto.createDecipheriv("aes-256-gcm", key, iv);
|
|
67
|
+
decipher.setAuthTag(authTag);
|
|
68
|
+
try {
|
|
69
|
+
const decrypted = Buffer.concat([
|
|
70
|
+
decipher.update(ciphertext),
|
|
71
|
+
decipher.final(),
|
|
72
|
+
]);
|
|
73
|
+
return decrypted.toString("utf8");
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
throw new Error("Decryption failed - invalid password or corrupted data");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Derive key with custom scrypt parameters (for stored data)
|
|
81
|
+
*/
|
|
82
|
+
function deriveKeyWithParams(password, salt, params) {
|
|
83
|
+
return new Promise((resolve, reject) => {
|
|
84
|
+
crypto.scrypt(password, salt, params.keyLen, {
|
|
85
|
+
N: params.N,
|
|
86
|
+
r: params.r,
|
|
87
|
+
p: params.p,
|
|
88
|
+
}, (err, derivedKey) => {
|
|
89
|
+
if (err) {
|
|
90
|
+
reject(err);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
resolve(derivedKey);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Generate cryptographically secure random bytes
|
|
100
|
+
*/
|
|
101
|
+
export function randomBytes(length) {
|
|
102
|
+
return crypto.randomBytes(length);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Generate a random UUID for wallet IDs
|
|
106
|
+
*/
|
|
107
|
+
export function generateWalletId() {
|
|
108
|
+
return crypto.randomUUID();
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=encryption.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption.js","sourceRoot":"","sources":["../../src/utils/encryption.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAmB5B,6DAA6D;AAC7D,MAAM,aAAa,GAAG;IACpB,CAAC,EAAE,KAAK,EAAE,yBAAyB;IACnC,CAAC,EAAE,CAAC,EAAE,aAAa;IACnB,CAAC,EAAE,CAAC,EAAE,kBAAkB;IACxB,MAAM,EAAE,EAAE,EAAE,uBAAuB;CACpC,CAAC;AAEF,MAAM,eAAe,GAAG,CAAC,CAAC;AAE1B;;GAEG;AACH,SAAS,SAAS,CAAC,QAAgB,EAAE,IAAY;IAC/C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,CAAC,MAAM,CACX,QAAQ,EACR,IAAI,EACJ,aAAa,CAAC,MAAM,EACpB;YACE,CAAC,EAAE,aAAa,CAAC,CAAC;YAClB,CAAC,EA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M,CACX,QAAQ,EACR,IAAI,EACJ,MAAM,CAAC,MAAM,EACb;YACE,CAAC,EAAE,MAAM,CAAC,CAAC;YACX,CAAC,EAAE,MAAM,CAAC,CAAC;YACX,CAAC,EAAE,MAAM,CAAC,CAAC;SACZ,EACD,CAAC,GAAG,EAAE,UAAU,EAAE,EAAE;YAClB,IAAI,GAAG,EAAE,CAAC;gBACR,MAAM,CAAC,GAAG,CAAC,CAAC;YACd,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,UAAU,CAAC,CAAC;YACtB,CAAC;QACH,CAAC,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,MAAc;IACxC,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;AACpC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,MAAM,CAAC,UAAU,EAAE,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for aibtc-mcp-server
|
|
3
|
+
*/
|
|
4
|
+
export declare class AibtcError extends Error {
|
|
5
|
+
readonly code: string;
|
|
6
|
+
readonly details?: unknown | undefined;
|
|
7
|
+
constructor(message: string, code: string, details?: unknown | undefined);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Error for invalid configuration
|
|
11
|
+
*/
|
|
12
|
+
export declare class ConfigError extends AibtcError {
|
|
13
|
+
constructor(message: string, details?: unknown);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Error for transaction failures
|
|
17
|
+
*/
|
|
18
|
+
export declare class TransactionError extends AibtcError {
|
|
19
|
+
readonly txid?: string | undefined;
|
|
20
|
+
constructor(message: string, txid?: string | undefined, details?: unknown);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Error for API failures
|
|
24
|
+
*/
|
|
25
|
+
export declare class ApiError extends AibtcError {
|
|
26
|
+
readonly statusCode?: number | undefined;
|
|
27
|
+
constructor(message: string, statusCode?: number | undefined, details?: unknown);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Error for contract call failures
|
|
31
|
+
*/
|
|
32
|
+
export declare class ContractError extends AibtcError {
|
|
33
|
+
readonly contractId?: string | undefined;
|
|
34
|
+
constructor(message: string, contractId?: string | undefined, details?: unknown);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Base error for wallet operations
|
|
38
|
+
*/
|
|
39
|
+
export declare class WalletError extends AibtcError {
|
|
40
|
+
constructor(message: string, details?: unknown);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Error when wallet is locked and operation requires unlocked wallet
|
|
44
|
+
*/
|
|
45
|
+
export declare class WalletLockedError extends WalletError {
|
|
46
|
+
constructor();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Error when wallet is not found
|
|
50
|
+
*/
|
|
51
|
+
export declare class WalletNotFoundError extends WalletError {
|
|
52
|
+
constructor(walletId: string);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Error for invalid password
|
|
56
|
+
*/
|
|
57
|
+
export declare class InvalidPasswordError extends WalletError {
|
|
58
|
+
constructor();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Error for invalid mnemonic
|
|
62
|
+
*/
|
|
63
|
+
export declare class InvalidMnemonicError extends WalletError {
|
|
64
|
+
constructor();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Format error for tool response
|
|
68
|
+
*/
|
|
69
|
+
export declare function formatError(error: unknown): {
|
|
70
|
+
message: string;
|
|
71
|
+
code?: string;
|
|
72
|
+
details?: unknown;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Create error response for MCP tools
|
|
76
|
+
*/
|
|
77
|
+
export declare function createErrorResponse(error: unknown): {
|
|
78
|
+
content: Array<{
|
|
79
|
+
type: "text";
|
|
80
|
+
text: string;
|
|
81
|
+
}>;
|
|
82
|
+
isError: true;
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAK;aAGjB,IAAI,EAAE,MAAM;aACZ,OAAO,CAAC,EAAE,OAAO;gBAFjC,OAAO,EAAE,MAAM,EACC,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,OAAO,YAAA;CAKpC;AAED;;GAEG;AACH,qBAAa,WAAY,SAAQ,UAAU;gBAC7B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;CAI/C;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,UAAU;aACD,IAAI,CAAC,EAAE,MAAM;gBAA9C,OAAO,EAAE,MAAM,EAAkB,IAAI,CAAC,EAAE,MAAM,YAAA,EAAE,OAAO,CAAC,EAAE,OAAO;CAI9E;AAED;;GAEG;AACH,qBAAa,QAAS,SAAQ,UAAU;aAGpB,UAAU,CAAC,EAAE,MAAM;gBADnC,OAAO,EAAE,MAAM,EACC,UAAU,CAAC,EAAE,MAAM,YAAA,EACnC,OAAO,CAAC,EAAE,OAAO;CAKpB;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,UAAU;aAGzB,UAAU,CAAC,EAAE,MAAM;gBADnC,OAAO,EAAE,MAAM,EACC,UAAU,CAAC,EAAE,MAAM,YAAA,EACnC,OAAO,CAAC,EAAE,OAAO;CAKpB;AAED;;GAEG;AACH,qBAAa,WAAY,SAAQ,UAAU;gBAC7B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;CAI/C;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,WAAW;;CAKjD;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,WAAW;gBACtC,QAAQ,EAAE,MAAM;CAI7B;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,WAAW;;CAKpD;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,WAAW;;CAKpD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CAcjG;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG;IACnD,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,OAAO,EAAE,IAAI,CAAC;CACf,CAWA"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for aibtc-mcp-server
|
|
3
|
+
*/
|
|
4
|
+
export class AibtcError extends Error {
|
|
5
|
+
code;
|
|
6
|
+
details;
|
|
7
|
+
constructor(message, code, details) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.details = details;
|
|
11
|
+
this.name = "AibtcError";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Error for invalid configuration
|
|
16
|
+
*/
|
|
17
|
+
export class ConfigError extends AibtcError {
|
|
18
|
+
constructor(message, details) {
|
|
19
|
+
super(message, "CONFIG_ERROR", details);
|
|
20
|
+
this.name = "ConfigError";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Error for transaction failures
|
|
25
|
+
*/
|
|
26
|
+
export class TransactionError extends AibtcError {
|
|
27
|
+
txid;
|
|
28
|
+
constructor(message, txid, details) {
|
|
29
|
+
super(message, "TRANSACTION_ERROR", details);
|
|
30
|
+
this.txid = txid;
|
|
31
|
+
this.name = "TransactionError";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Error for API failures
|
|
36
|
+
*/
|
|
37
|
+
export class ApiError extends AibtcError {
|
|
38
|
+
statusCode;
|
|
39
|
+
constructor(message, statusCode, details) {
|
|
40
|
+
super(message, "API_ERROR", details);
|
|
41
|
+
this.statusCode = statusCode;
|
|
42
|
+
this.name = "ApiError";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Error for contract call failures
|
|
47
|
+
*/
|
|
48
|
+
export class ContractError extends AibtcError {
|
|
49
|
+
contractId;
|
|
50
|
+
constructor(message, contractId, details) {
|
|
51
|
+
super(message, "CONTRACT_ERROR", details);
|
|
52
|
+
this.contractId = contractId;
|
|
53
|
+
this.name = "ContractError";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Base error for wallet operations
|
|
58
|
+
*/
|
|
59
|
+
export class WalletError extends AibtcError {
|
|
60
|
+
constructor(message, details) {
|
|
61
|
+
super(message, "WALLET_ERROR", details);
|
|
62
|
+
this.name = "WalletError";
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Error when wallet is locked and operation requires unlocked wallet
|
|
67
|
+
*/
|
|
68
|
+
export class WalletLockedError extends WalletError {
|
|
69
|
+
constructor() {
|
|
70
|
+
super("Wallet is locked. Use wallet_unlock to unlock it.");
|
|
71
|
+
this.name = "WalletLockedError";
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Error when wallet is not found
|
|
76
|
+
*/
|
|
77
|
+
export class WalletNotFoundError extends WalletError {
|
|
78
|
+
constructor(walletId) {
|
|
79
|
+
super(`Wallet not found: ${walletId}`);
|
|
80
|
+
this.name = "WalletNotFoundError";
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Error for invalid password
|
|
85
|
+
*/
|
|
86
|
+
export class InvalidPasswordError extends WalletError {
|
|
87
|
+
constructor() {
|
|
88
|
+
super("Invalid password");
|
|
89
|
+
this.name = "InvalidPasswordError";
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Error for invalid mnemonic
|
|
94
|
+
*/
|
|
95
|
+
export class InvalidMnemonicError extends WalletError {
|
|
96
|
+
constructor() {
|
|
97
|
+
super("Invalid mnemonic phrase");
|
|
98
|
+
this.name = "InvalidMnemonicError";
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Format error for tool response
|
|
103
|
+
*/
|
|
104
|
+
export function formatError(error) {
|
|
105
|
+
if (error instanceof AibtcError) {
|
|
106
|
+
return {
|
|
107
|
+
message: error.message,
|
|
108
|
+
code: error.code,
|
|
109
|
+
details: error.details,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
if (error instanceof Error) {
|
|
113
|
+
return { message: error.message };
|
|
114
|
+
}
|
|
115
|
+
return { message: "Unknown error occurred" };
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Create error response for MCP tools
|
|
119
|
+
*/
|
|
120
|
+
export function createErrorResponse(error) {
|
|
121
|
+
const formatted = formatError(error);
|
|
122
|
+
return {
|
|
123
|
+
content: [
|
|
124
|
+
{
|
|
125
|
+
type: "text",
|
|
126
|
+
text: `Error: ${formatted.message}${formatted.code ? ` (${formatted.code})` : ""}`,
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
isError: true,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IAGjB;IACA;IAHlB,YACE,OAAe,EACC,IAAY,EACZ,OAAiB;QAEjC,KAAK,CAAC,OAAO,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IACrC,OAAO;QACL,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,UAAU,SAAS,CAAC,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;aACnF;SACF;QACD,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format STX amount from micro-STX to STX
|
|
3
|
+
*/
|
|
4
|
+
export declare function formatStx(microStx: string | bigint): string;
|
|
5
|
+
/**
|
|
6
|
+
* Format sBTC amount from sats to BTC
|
|
7
|
+
*/
|
|
8
|
+
export declare function formatSbtc(sats: string | bigint): string;
|
|
9
|
+
/**
|
|
10
|
+
* Format token amount with decimals
|
|
11
|
+
*/
|
|
12
|
+
export declare function formatTokenAmount(amount: string | bigint, decimals: number, symbol?: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Parse STX amount string to micro-STX
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseStxAmount(amount: string): bigint;
|
|
17
|
+
/**
|
|
18
|
+
* Format address for display (truncated)
|
|
19
|
+
*/
|
|
20
|
+
export declare function formatAddress(address: string, chars?: number): string;
|
|
21
|
+
/**
|
|
22
|
+
* Format transaction ID for display
|
|
23
|
+
*/
|
|
24
|
+
export declare function formatTxId(txid: string, chars?: number): string;
|
|
25
|
+
/**
|
|
26
|
+
* Format date from timestamp
|
|
27
|
+
*/
|
|
28
|
+
export declare function formatDate(timestamp: number): string;
|
|
29
|
+
/**
|
|
30
|
+
* Format block height
|
|
31
|
+
*/
|
|
32
|
+
export declare function formatBlockHeight(height: number): string;
|
|
33
|
+
/**
|
|
34
|
+
* Create JSON response for MCP tools
|
|
35
|
+
*/
|
|
36
|
+
export declare function createJsonResponse(data: unknown): {
|
|
37
|
+
content: Array<{
|
|
38
|
+
type: "text";
|
|
39
|
+
text: string;
|
|
40
|
+
}>;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Create success response for MCP tools
|
|
44
|
+
*/
|
|
45
|
+
export declare function createSuccessResponse(message: string, data?: unknown): {
|
|
46
|
+
content: Array<{
|
|
47
|
+
type: "text";
|
|
48
|
+
text: string;
|
|
49
|
+
}>;
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=formatting.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatting.d.ts","sourceRoot":"","sources":["../../src/utils/formatting.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAW3D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAWxD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,MAAM,GACd,MAAM,CAeR;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAWrD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,GAAE,MAAU,GAAG,MAAM,CAKxE;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,GAAE,MAAU,GAAG,MAAM,CAElE;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAExD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,OAAO,GAAG;IACjD,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChD,CASA;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,OAAO,GACb;IACD,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChD,CAaA"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format STX amount from micro-STX to STX
|
|
3
|
+
*/
|
|
4
|
+
export function formatStx(microStx) {
|
|
5
|
+
const value = BigInt(microStx);
|
|
6
|
+
const stx = value / BigInt(1_000_000);
|
|
7
|
+
const remainder = value % BigInt(1_000_000);
|
|
8
|
+
if (remainder === BigInt(0)) {
|
|
9
|
+
return `${stx} STX`;
|
|
10
|
+
}
|
|
11
|
+
const decimal = remainder.toString().padStart(6, "0").replace(/0+$/, "");
|
|
12
|
+
return `${stx}.${decimal} STX`;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Format sBTC amount from sats to BTC
|
|
16
|
+
*/
|
|
17
|
+
export function formatSbtc(sats) {
|
|
18
|
+
const value = BigInt(sats);
|
|
19
|
+
const btc = value / BigInt(100_000_000);
|
|
20
|
+
const remainder = value % BigInt(100_000_000);
|
|
21
|
+
if (remainder === BigInt(0)) {
|
|
22
|
+
return `${btc} sBTC`;
|
|
23
|
+
}
|
|
24
|
+
const decimal = remainder.toString().padStart(8, "0").replace(/0+$/, "");
|
|
25
|
+
return `${btc}.${decimal} sBTC`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Format token amount with decimals
|
|
29
|
+
*/
|
|
30
|
+
export function formatTokenAmount(amount, decimals, symbol) {
|
|
31
|
+
const value = BigInt(amount);
|
|
32
|
+
const divisor = BigInt(10 ** decimals);
|
|
33
|
+
const whole = value / divisor;
|
|
34
|
+
const remainder = value % divisor;
|
|
35
|
+
let result;
|
|
36
|
+
if (remainder === BigInt(0)) {
|
|
37
|
+
result = whole.toString();
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
const decimal = remainder.toString().padStart(decimals, "0").replace(/0+$/, "");
|
|
41
|
+
result = `${whole}.${decimal}`;
|
|
42
|
+
}
|
|
43
|
+
return symbol ? `${result} ${symbol}` : result;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Parse STX amount string to micro-STX
|
|
47
|
+
*/
|
|
48
|
+
export function parseStxAmount(amount) {
|
|
49
|
+
// Remove STX suffix if present
|
|
50
|
+
const cleaned = amount.replace(/\s*STX$/i, "").trim();
|
|
51
|
+
if (cleaned.includes(".")) {
|
|
52
|
+
const [whole, decimal] = cleaned.split(".");
|
|
53
|
+
const paddedDecimal = (decimal || "").padEnd(6, "0").slice(0, 6);
|
|
54
|
+
return BigInt(whole || "0") * BigInt(1_000_000) + BigInt(paddedDecimal);
|
|
55
|
+
}
|
|
56
|
+
return BigInt(cleaned) * BigInt(1_000_000);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Format address for display (truncated)
|
|
60
|
+
*/
|
|
61
|
+
export function formatAddress(address, chars = 8) {
|
|
62
|
+
if (address.length <= chars * 2 + 3) {
|
|
63
|
+
return address;
|
|
64
|
+
}
|
|
65
|
+
return `${address.slice(0, chars)}...${address.slice(-chars)}`;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Format transaction ID for display
|
|
69
|
+
*/
|
|
70
|
+
export function formatTxId(txid, chars = 8) {
|
|
71
|
+
return formatAddress(txid, chars);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Format date from timestamp
|
|
75
|
+
*/
|
|
76
|
+
export function formatDate(timestamp) {
|
|
77
|
+
return new Date(timestamp * 1000).toISOString();
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Format block height
|
|
81
|
+
*/
|
|
82
|
+
export function formatBlockHeight(height) {
|
|
83
|
+
return height.toLocaleString();
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Create JSON response for MCP tools
|
|
87
|
+
*/
|
|
88
|
+
export function createJsonResponse(data) {
|
|
89
|
+
return {
|
|
90
|
+
content: [
|
|
91
|
+
{
|
|
92
|
+
type: "text",
|
|
93
|
+
text: JSON.stringify(data, null, 2),
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Create success response for MCP tools
|
|
100
|
+
*/
|
|
101
|
+
export function createSuccessResponse(message, data) {
|
|
102
|
+
const response = data
|
|
103
|
+
? { success: true, message, ...data }
|
|
104
|
+
: { success: true, message };
|
|
105
|
+
return {
|
|
106
|
+
content: [
|
|
107
|
+
{
|
|
108
|
+
type: "text",
|
|
109
|
+
text: JSON.stringify(response, null, 2),
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=formatting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatting.js","sourceRoot":"","sources":["../../src/utils/formatting.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,QAAyB;IACjD,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC/B,MAAM,GAAG,GAAG,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;IACtC,MAAM,SAAS,GAAG,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;IAE5C,IAAI,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5B,OAAO,GAAG,GAAG,MAAM,CAAC;IACtB,CAAC;IAED,MAAM,OAAO,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC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AAE,KAAK,CAAC,CAAC;AACpC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,SAAiB;IAC1C,OAAO,IAAI,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;AAClD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAc;IAC9C,OAAO,MAAM,CAAC,cAAc,EAAE,CAAC;AACjC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAa;IAG9C,OAAO;QACL,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;aACpC;SACF;KACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACnC,OAAe,EACf,IAAc;IAId,MAAM,QAAQ,GAAG,IAAI;QACnB,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE;QACrC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IAE/B,OAAO;QACL,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;aACxC;SACF;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { EncryptedData } from "./encryption.js";
|
|
2
|
+
import type { Network } from "../config/networks.js";
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* Wallet metadata (stored in index, no sensitive data)
|
|
6
|
+
*/
|
|
7
|
+
export interface WalletMetadata {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
address: string;
|
|
11
|
+
network: Network;
|
|
12
|
+
createdAt: string;
|
|
13
|
+
lastUsed?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Wallet index file structure
|
|
17
|
+
*/
|
|
18
|
+
export interface WalletIndex {
|
|
19
|
+
version: number;
|
|
20
|
+
wallets: WalletMetadata[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* App configuration
|
|
24
|
+
*/
|
|
25
|
+
export interface AppConfig {
|
|
26
|
+
version: number;
|
|
27
|
+
activeWalletId: string | null;
|
|
28
|
+
autoLockTimeout: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Keystore file structure (contains encrypted mnemonic)
|
|
32
|
+
*/
|
|
33
|
+
export interface KeystoreFile {
|
|
34
|
+
version: number;
|
|
35
|
+
encrypted: EncryptedData;
|
|
36
|
+
addressIndex: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get storage directory path
|
|
40
|
+
*/
|
|
41
|
+
export declare function getStorageDir(): string;
|
|
42
|
+
/**
|
|
43
|
+
* Check if storage directory exists
|
|
44
|
+
*/
|
|
45
|
+
export declare function storageExists(): Promise<boolean>;
|
|
46
|
+
/**
|
|
47
|
+
* Initialize storage directory structure
|
|
48
|
+
*/
|
|
49
|
+
export declare function initializeStorage(): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Read wallet index
|
|
52
|
+
*/
|
|
53
|
+
export declare function readWalletIndex(): Promise<WalletIndex>;
|
|
54
|
+
/**
|
|
55
|
+
* Write wallet index (atomic write with temp file)
|
|
56
|
+
*/
|
|
57
|
+
export declare function writeWalletIndex(index: WalletIndex): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Read app config
|
|
60
|
+
*/
|
|
61
|
+
export declare function readAppConfig(): Promise<AppConfig>;
|
|
62
|
+
/**
|
|
63
|
+
* Write app config (atomic write)
|
|
64
|
+
*/
|
|
65
|
+
export declare function writeAppConfig(config: AppConfig): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Read keystore for a wallet
|
|
68
|
+
*/
|
|
69
|
+
export declare function readKeystore(walletId: string): Promise<KeystoreFile>;
|
|
70
|
+
/**
|
|
71
|
+
* Write keystore for a wallet (creates directory if needed)
|
|
72
|
+
*/
|
|
73
|
+
export declare function writeKeystore(walletId: string, keystore: KeystoreFile): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Delete a wallet directory and its contents
|
|
76
|
+
*/
|
|
77
|
+
export declare function deleteWalletStorage(walletId: string): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Update wallet metadata in index
|
|
80
|
+
*/
|
|
81
|
+
export declare function updateWalletMetadata(walletId: string, updates: Partial<WalletMetadata>): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Add wallet to index
|
|
84
|
+
*/
|
|
85
|
+
export declare function addWalletToIndex(wallet: WalletMetadata): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Remove wallet from index
|
|
88
|
+
*/
|
|
89
|
+
export declare function removeWalletFromIndex(walletId: string): Promise<void>;
|
|
90
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/utils/storage.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,E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