@opendatalabs/vana-sdk 0.1.0-alpha.d6bebb0 → 0.1.0-alpha.e2e45dd
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 +43 -32
- package/dist/browser-cRpdLQ3-.d.ts +237 -0
- package/dist/browser.d.ts +1 -0
- package/dist/browser.js +294 -0
- package/dist/browser.js.map +1 -0
- package/dist/chains.browser.cjs +2 -2
- package/dist/chains.browser.cjs.map +1 -1
- package/dist/chains.browser.js +2 -2
- package/dist/chains.browser.js.map +1 -1
- package/dist/chains.cjs +2 -2
- package/dist/chains.cjs.map +1 -1
- package/dist/chains.js +2 -2
- package/dist/chains.js.map +1 -1
- package/dist/chains.node.cjs +2 -2
- package/dist/chains.node.cjs.map +1 -1
- package/dist/chains.node.js +2 -2
- package/dist/chains.node.js.map +1 -1
- package/dist/index.browser.d.ts +8717 -5109
- package/dist/index.browser.js +17345 -12939
- package/dist/index.browser.js.map +1 -1
- package/dist/index.node.cjs +17440 -12982
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.d.cts +8721 -5109
- package/dist/index.node.d.ts +8721 -5109
- package/dist/index.node.js +17392 -12936
- package/dist/index.node.js.map +1 -1
- package/dist/node-CkdgwBiv.d.cts +237 -0
- package/dist/node-CkdgwBiv.d.ts +237 -0
- package/dist/node.cjs +350 -0
- package/dist/node.cjs.map +1 -0
- package/dist/node.d.cts +1 -0
- package/dist/node.d.ts +1 -0
- package/dist/node.js +313 -0
- package/dist/node.js.map +1 -0
- package/dist/platform.browser.d.ts +3 -202
- package/dist/platform.browser.js +48 -1
- package/dist/platform.browser.js.map +1 -1
- package/dist/platform.cjs +76 -1
- package/dist/platform.cjs.map +1 -1
- package/dist/platform.d.cts +2 -1
- package/dist/platform.d.ts +2 -1
- package/dist/platform.js +76 -1
- package/dist/platform.js.map +1 -1
- package/dist/platform.node.cjs +76 -1
- package/dist/platform.node.cjs.map +1 -1
- package/dist/platform.node.d.cts +4 -202
- package/dist/platform.node.d.ts +4 -202
- package/dist/platform.node.js +76 -1
- package/dist/platform.node.js.map +1 -1
- package/package.json +2 -2
package/dist/node.js
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
// src/platform/node.ts
|
|
2
|
+
import { randomBytes } from "crypto";
|
|
3
|
+
import * as openpgp from "openpgp";
|
|
4
|
+
|
|
5
|
+
// src/platform/shared/crypto-utils.ts
|
|
6
|
+
function processWalletPublicKey(publicKey) {
|
|
7
|
+
const publicKeyHex = publicKey.startsWith("0x") ? publicKey.slice(2) : publicKey;
|
|
8
|
+
const publicKeyBytes = Buffer.from(publicKeyHex, "hex");
|
|
9
|
+
return publicKeyBytes.length === 64 ? Buffer.concat([Buffer.from([4]), publicKeyBytes]) : publicKeyBytes;
|
|
10
|
+
}
|
|
11
|
+
function processWalletPrivateKey(privateKey) {
|
|
12
|
+
const privateKeyHex = privateKey.startsWith("0x") ? privateKey.slice(2) : privateKey;
|
|
13
|
+
return Buffer.from(privateKeyHex, "hex");
|
|
14
|
+
}
|
|
15
|
+
function parseEncryptedDataBuffer(encryptedBuffer) {
|
|
16
|
+
return {
|
|
17
|
+
iv: encryptedBuffer.slice(0, 16),
|
|
18
|
+
ephemPublicKey: encryptedBuffer.slice(16, 81),
|
|
19
|
+
// 65 bytes for uncompressed public key
|
|
20
|
+
ciphertext: encryptedBuffer.slice(81, -32),
|
|
21
|
+
mac: encryptedBuffer.slice(-32)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// src/platform/shared/pgp-utils.ts
|
|
26
|
+
var STANDARD_PGP_CONFIG = {
|
|
27
|
+
preferredCompressionAlgorithm: 2,
|
|
28
|
+
// zlib (openpgp.enums.compression.zlib)
|
|
29
|
+
preferredSymmetricAlgorithm: 7
|
|
30
|
+
// aes256 (openpgp.enums.symmetric.aes256)
|
|
31
|
+
};
|
|
32
|
+
function processPGPKeyOptions(options) {
|
|
33
|
+
return {
|
|
34
|
+
name: options?.name || "Vana User",
|
|
35
|
+
email: options?.email || "user@vana.org",
|
|
36
|
+
passphrase: options?.passphrase
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function getPGPKeyGenParams(options) {
|
|
40
|
+
const { name, email, passphrase } = processPGPKeyOptions(options);
|
|
41
|
+
return {
|
|
42
|
+
type: "rsa",
|
|
43
|
+
rsaBits: 2048,
|
|
44
|
+
userIDs: [{ name, email }],
|
|
45
|
+
passphrase,
|
|
46
|
+
config: STANDARD_PGP_CONFIG
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/platform/shared/error-utils.ts
|
|
51
|
+
function wrapCryptoError(operation, error) {
|
|
52
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
53
|
+
return new Error(`${operation} failed: ${message}`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/platform/shared/stream-utils.ts
|
|
57
|
+
async function streamToUint8Array(stream) {
|
|
58
|
+
const reader = stream.getReader();
|
|
59
|
+
const chunks = [];
|
|
60
|
+
try {
|
|
61
|
+
while (true) {
|
|
62
|
+
const { done, value } = await reader.read();
|
|
63
|
+
if (done) break;
|
|
64
|
+
chunks.push(value);
|
|
65
|
+
}
|
|
66
|
+
} finally {
|
|
67
|
+
reader.releaseLock();
|
|
68
|
+
}
|
|
69
|
+
const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
|
|
70
|
+
const result = new Uint8Array(totalLength);
|
|
71
|
+
let offset = 0;
|
|
72
|
+
for (const chunk of chunks) {
|
|
73
|
+
result.set(chunk, offset);
|
|
74
|
+
offset += chunk.length;
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// src/platform/node.ts
|
|
80
|
+
var eccrypto = null;
|
|
81
|
+
async function getEccrypto() {
|
|
82
|
+
if (!eccrypto) {
|
|
83
|
+
try {
|
|
84
|
+
const eccryptoLib = await import("eccrypto");
|
|
85
|
+
eccrypto = {
|
|
86
|
+
encrypt: eccryptoLib.encrypt,
|
|
87
|
+
decrypt: eccryptoLib.decrypt,
|
|
88
|
+
getPublicCompressed: eccryptoLib.getPublicCompressed
|
|
89
|
+
};
|
|
90
|
+
} catch (error) {
|
|
91
|
+
throw new Error(`Failed to load eccrypto library: ${error}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return eccrypto;
|
|
95
|
+
}
|
|
96
|
+
var NodeCryptoAdapter = class {
|
|
97
|
+
async encryptWithPublicKey(data, publicKeyHex) {
|
|
98
|
+
try {
|
|
99
|
+
const eccryptoLib = await getEccrypto();
|
|
100
|
+
const publicKey = Buffer.from(publicKeyHex, "hex");
|
|
101
|
+
const message = Buffer.from(data, "utf8");
|
|
102
|
+
const encrypted = await eccryptoLib.encrypt(publicKey, message);
|
|
103
|
+
const result = Buffer.concat([
|
|
104
|
+
encrypted.iv,
|
|
105
|
+
encrypted.ephemPublicKey,
|
|
106
|
+
encrypted.ciphertext,
|
|
107
|
+
encrypted.mac
|
|
108
|
+
]);
|
|
109
|
+
return result.toString("hex");
|
|
110
|
+
} catch (error) {
|
|
111
|
+
throw new Error(`Encryption failed: ${error}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async decryptWithPrivateKey(encryptedData, privateKeyHex) {
|
|
115
|
+
try {
|
|
116
|
+
const eccryptoLib = await getEccrypto();
|
|
117
|
+
const privateKeyBuffer = processWalletPrivateKey(privateKeyHex);
|
|
118
|
+
const encryptedBuffer = Buffer.from(encryptedData, "hex");
|
|
119
|
+
const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
|
|
120
|
+
const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
|
|
121
|
+
const decrypted = await eccryptoLib.decrypt(
|
|
122
|
+
privateKeyBuffer,
|
|
123
|
+
encryptedObj
|
|
124
|
+
);
|
|
125
|
+
return decrypted.toString("utf8");
|
|
126
|
+
} catch (error) {
|
|
127
|
+
throw new Error(`Decryption failed: ${error}`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
async generateKeyPair() {
|
|
131
|
+
try {
|
|
132
|
+
const eccryptoLib = await getEccrypto();
|
|
133
|
+
const privateKey = randomBytes(32);
|
|
134
|
+
const publicKey = eccryptoLib.getPublicCompressed(privateKey);
|
|
135
|
+
return {
|
|
136
|
+
privateKey: privateKey.toString("hex"),
|
|
137
|
+
publicKey: publicKey.toString("hex")
|
|
138
|
+
};
|
|
139
|
+
} catch (error) {
|
|
140
|
+
throw wrapCryptoError("key generation", error);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async encryptWithWalletPublicKey(data, publicKey) {
|
|
144
|
+
try {
|
|
145
|
+
const eccryptoLib = await getEccrypto();
|
|
146
|
+
const uncompressedKey = processWalletPublicKey(publicKey);
|
|
147
|
+
const encrypted = await eccryptoLib.encrypt(
|
|
148
|
+
uncompressedKey,
|
|
149
|
+
Buffer.from(data)
|
|
150
|
+
);
|
|
151
|
+
const result = Buffer.concat([
|
|
152
|
+
encrypted.iv,
|
|
153
|
+
encrypted.ephemPublicKey,
|
|
154
|
+
encrypted.ciphertext,
|
|
155
|
+
encrypted.mac
|
|
156
|
+
]);
|
|
157
|
+
return result.toString("hex");
|
|
158
|
+
} catch (error) {
|
|
159
|
+
throw wrapCryptoError("encrypt with wallet public key", error);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
async decryptWithWalletPrivateKey(encryptedData, privateKey) {
|
|
163
|
+
try {
|
|
164
|
+
const eccryptoLib = await getEccrypto();
|
|
165
|
+
const privateKeyBuffer = processWalletPrivateKey(privateKey);
|
|
166
|
+
const encryptedBuffer = Buffer.from(encryptedData, "hex");
|
|
167
|
+
const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
|
|
168
|
+
const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
|
|
169
|
+
const decryptedBuffer = await eccryptoLib.decrypt(
|
|
170
|
+
privateKeyBuffer,
|
|
171
|
+
encryptedObj
|
|
172
|
+
);
|
|
173
|
+
return decryptedBuffer.toString("utf8");
|
|
174
|
+
} catch (error) {
|
|
175
|
+
throw wrapCryptoError("decrypt with wallet private key", error);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
async encryptWithPassword(data, password) {
|
|
179
|
+
try {
|
|
180
|
+
const message = await openpgp.createMessage({
|
|
181
|
+
binary: data
|
|
182
|
+
});
|
|
183
|
+
const encrypted = await openpgp.encrypt({
|
|
184
|
+
message,
|
|
185
|
+
passwords: [password],
|
|
186
|
+
format: "binary"
|
|
187
|
+
});
|
|
188
|
+
if (encrypted instanceof Uint8Array) {
|
|
189
|
+
return encrypted;
|
|
190
|
+
}
|
|
191
|
+
if (encrypted && typeof encrypted === "object" && "getReader" in encrypted) {
|
|
192
|
+
return await streamToUint8Array(
|
|
193
|
+
encrypted
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
throw new Error("Unexpected encrypted data format");
|
|
197
|
+
} catch (error) {
|
|
198
|
+
throw wrapCryptoError("encrypt with password", error);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
async decryptWithPassword(encryptedData, password) {
|
|
202
|
+
try {
|
|
203
|
+
const message = await openpgp.readMessage({
|
|
204
|
+
binaryMessage: encryptedData
|
|
205
|
+
});
|
|
206
|
+
const { data: decrypted } = await openpgp.decrypt({
|
|
207
|
+
message,
|
|
208
|
+
passwords: [password],
|
|
209
|
+
format: "binary"
|
|
210
|
+
});
|
|
211
|
+
return new Uint8Array(decrypted);
|
|
212
|
+
} catch (error) {
|
|
213
|
+
throw wrapCryptoError("decrypt with password", error);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
var NodePGPAdapter = class {
|
|
218
|
+
async encrypt(data, publicKeyArmored) {
|
|
219
|
+
try {
|
|
220
|
+
const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
|
|
221
|
+
const encrypted = await openpgp.encrypt({
|
|
222
|
+
message: await openpgp.createMessage({ text: data }),
|
|
223
|
+
encryptionKeys: publicKey,
|
|
224
|
+
config: {
|
|
225
|
+
preferredCompressionAlgorithm: openpgp.enums.compression.zlib
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
return encrypted;
|
|
229
|
+
} catch (error) {
|
|
230
|
+
throw wrapCryptoError("PGP encryption", error);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
async decrypt(encryptedData, privateKeyArmored) {
|
|
234
|
+
try {
|
|
235
|
+
const privateKey = await openpgp.readPrivateKey({
|
|
236
|
+
armoredKey: privateKeyArmored
|
|
237
|
+
});
|
|
238
|
+
const message = await openpgp.readMessage({
|
|
239
|
+
armoredMessage: encryptedData
|
|
240
|
+
});
|
|
241
|
+
const { data: decrypted } = await openpgp.decrypt({
|
|
242
|
+
message,
|
|
243
|
+
decryptionKeys: privateKey
|
|
244
|
+
});
|
|
245
|
+
return decrypted;
|
|
246
|
+
} catch (error) {
|
|
247
|
+
throw wrapCryptoError("PGP decryption", error);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
async generateKeyPair(options) {
|
|
251
|
+
try {
|
|
252
|
+
const keyGenParams = getPGPKeyGenParams(options);
|
|
253
|
+
const { privateKey, publicKey } = await openpgp.generateKey(keyGenParams);
|
|
254
|
+
return { publicKey, privateKey };
|
|
255
|
+
} catch (error) {
|
|
256
|
+
throw wrapCryptoError("PGP key generation", error);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
var NodeHttpAdapter = class {
|
|
261
|
+
async fetch(url, options) {
|
|
262
|
+
if (typeof globalThis.fetch !== "undefined") {
|
|
263
|
+
return globalThis.fetch(url, options);
|
|
264
|
+
}
|
|
265
|
+
throw new Error("No fetch implementation available in Node.js environment");
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
var NodeCacheAdapter = class {
|
|
269
|
+
cache = /* @__PURE__ */ new Map();
|
|
270
|
+
defaultTtl = 2 * 60 * 60 * 1e3;
|
|
271
|
+
// 2 hours in milliseconds
|
|
272
|
+
get(key) {
|
|
273
|
+
const entry = this.cache.get(key);
|
|
274
|
+
if (!entry) {
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
if (Date.now() > entry.expires) {
|
|
278
|
+
this.cache.delete(key);
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
return entry.value;
|
|
282
|
+
}
|
|
283
|
+
set(key, value) {
|
|
284
|
+
this.cache.set(key, {
|
|
285
|
+
value,
|
|
286
|
+
expires: Date.now() + this.defaultTtl
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
delete(key) {
|
|
290
|
+
this.cache.delete(key);
|
|
291
|
+
}
|
|
292
|
+
clear() {
|
|
293
|
+
this.cache.clear();
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
var NodePlatformAdapter = class {
|
|
297
|
+
crypto;
|
|
298
|
+
pgp;
|
|
299
|
+
http;
|
|
300
|
+
cache;
|
|
301
|
+
platform = "node";
|
|
302
|
+
constructor() {
|
|
303
|
+
this.crypto = new NodeCryptoAdapter();
|
|
304
|
+
this.pgp = new NodePGPAdapter();
|
|
305
|
+
this.http = new NodeHttpAdapter();
|
|
306
|
+
this.cache = new NodeCacheAdapter();
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
var nodePlatformAdapter = new NodePlatformAdapter();
|
|
310
|
+
export {
|
|
311
|
+
NodePlatformAdapter
|
|
312
|
+
};
|
|
313
|
+
//# sourceMappingURL=node.js.map
|
package/dist/node.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/platform/node.ts","../src/platform/shared/crypto-utils.ts","../src/platform/shared/pgp-utils.ts","../src/platform/shared/error-utils.ts","../src/platform/shared/stream-utils.ts"],"sourcesContent":["/**\n * Node.js implementation of the Vana Platform Adapter\n *\n * This implementation uses Node.js-specific libraries and configurations\n * to provide crypto, PGP, and HTTP functionality.\n */\n\nimport { randomBytes } from \"crypto\";\nimport * as openpgp from \"openpgp\";\nimport {\n VanaPlatformAdapter,\n VanaCryptoAdapter,\n VanaPGPAdapter,\n VanaHttpAdapter,\n VanaCacheAdapter,\n} from \"./interface\";\nimport {\n processWalletPublicKey,\n processWalletPrivateKey,\n parseEncryptedDataBuffer,\n} from \"./shared/crypto-utils\";\nimport { getPGPKeyGenParams } from \"./shared/pgp-utils\";\nimport { wrapCryptoError } from \"./shared/error-utils\";\nimport { streamToUint8Array } from \"./shared/stream-utils\";\n\n// Eccrypto type definitions removed - using dynamic imports instead\n\n// Dynamically import eccrypto for Node.js\nlet eccrypto: {\n encrypt: (\n publicKey: Buffer,\n message: Buffer,\n ) => Promise<{\n iv: Buffer;\n ephemPublicKey: Buffer;\n ciphertext: Buffer;\n mac: Buffer;\n }>;\n decrypt: (\n privateKey: Buffer,\n encrypted: {\n iv: Buffer;\n ephemPublicKey: Buffer;\n ciphertext: Buffer;\n mac: Buffer;\n },\n ) => Promise<Buffer>;\n getPublicCompressed: (privateKey: Buffer) => Buffer;\n} | null = null;\n\n// Lazy load eccrypto\n/**\n * Lazy loads the eccrypto library for Node.js crypto operations\n *\n * @returns Promise resolving to the eccrypto library instance\n */\nasync function getEccrypto() {\n if (!eccrypto) {\n try {\n // Import the eccrypto library for Node.js\n const eccryptoLib = await import(\"eccrypto\");\n\n eccrypto = {\n encrypt: eccryptoLib.encrypt,\n decrypt: eccryptoLib.decrypt,\n getPublicCompressed: eccryptoLib.getPublicCompressed,\n };\n } catch (error) {\n throw new Error(`Failed to load eccrypto library: ${error}`);\n }\n }\n return eccrypto;\n}\n\n/**\n * Node.js implementation of crypto operations using secp256k1\n */\nclass NodeCryptoAdapter implements VanaCryptoAdapter {\n async encryptWithPublicKey(\n data: string,\n publicKeyHex: string,\n ): Promise<string> {\n try {\n const eccryptoLib = await getEccrypto();\n const publicKey = Buffer.from(publicKeyHex, \"hex\");\n const message = Buffer.from(data, \"utf8\");\n\n const encrypted = await eccryptoLib.encrypt(publicKey, message);\n\n // Concatenate all components and return as hex string for API consistency\n const result = Buffer.concat([\n encrypted.iv,\n encrypted.ephemPublicKey,\n encrypted.ciphertext,\n encrypted.mac,\n ]);\n\n return result.toString(\"hex\");\n } catch (error) {\n throw new Error(`Encryption failed: ${error}`);\n }\n }\n\n async decryptWithPrivateKey(\n encryptedData: string,\n privateKeyHex: string,\n ): Promise<string> {\n try {\n const eccryptoLib = await getEccrypto();\n\n // Use shared utilities to process keys and parse data\n const privateKeyBuffer = processWalletPrivateKey(privateKeyHex);\n const encryptedBuffer = Buffer.from(encryptedData, \"hex\");\n const { iv, ephemPublicKey, ciphertext, mac } =\n parseEncryptedDataBuffer(encryptedBuffer);\n\n // Reconstruct the encrypted data structure for eccrypto\n const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };\n\n const decrypted = await eccryptoLib.decrypt(\n privateKeyBuffer,\n encryptedObj,\n );\n return decrypted.toString(\"utf8\");\n } catch (error) {\n throw new Error(`Decryption failed: ${error}`);\n }\n }\n\n async generateKeyPair(): Promise<{ publicKey: string; privateKey: string }> {\n try {\n const eccryptoLib = await getEccrypto();\n const privateKey = randomBytes(32);\n const publicKey = eccryptoLib.getPublicCompressed(privateKey);\n\n return {\n privateKey: privateKey.toString(\"hex\"),\n publicKey: publicKey.toString(\"hex\"),\n };\n } catch (error) {\n throw wrapCryptoError(\"key generation\", error);\n }\n }\n\n async encryptWithWalletPublicKey(\n data: string,\n publicKey: string,\n ): Promise<string> {\n try {\n const eccryptoLib = await getEccrypto();\n\n // Use shared utility to process public key\n const uncompressedKey = processWalletPublicKey(publicKey);\n\n const encrypted = await eccryptoLib.encrypt(\n uncompressedKey,\n Buffer.from(data),\n );\n\n // Concatenate all components and return as hex (same format as browser)\n const result = Buffer.concat([\n encrypted.iv,\n encrypted.ephemPublicKey,\n encrypted.ciphertext,\n encrypted.mac,\n ]);\n\n return result.toString(\"hex\");\n } catch (error) {\n throw wrapCryptoError(\"encrypt with wallet public key\", error);\n }\n }\n\n async decryptWithWalletPrivateKey(\n encryptedData: string,\n privateKey: string,\n ): Promise<string> {\n try {\n const eccryptoLib = await getEccrypto();\n\n // Use shared utilities to process keys and parse data\n const privateKeyBuffer = processWalletPrivateKey(privateKey);\n const encryptedBuffer = Buffer.from(encryptedData, \"hex\");\n const { iv, ephemPublicKey, ciphertext, mac } =\n parseEncryptedDataBuffer(encryptedBuffer);\n\n // Reconstruct the encrypted data structure for eccrypto\n const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };\n\n // Decrypt using ECDH\n const decryptedBuffer = await eccryptoLib.decrypt(\n privateKeyBuffer,\n encryptedObj,\n );\n\n return decryptedBuffer.toString(\"utf8\");\n } catch (error) {\n throw wrapCryptoError(\"decrypt with wallet private key\", error);\n }\n }\n\n async encryptWithPassword(\n data: Uint8Array,\n password: string,\n ): Promise<Uint8Array> {\n try {\n const message = await openpgp.createMessage({\n binary: data,\n });\n\n // Use password-based encryption with wallet signature as password\n // Note: For deterministic encryption, we would need to control the salt\n // This implementation is secure but not deterministic due to OpenPGP's design\n const encrypted = await openpgp.encrypt({\n message,\n passwords: [password],\n format: \"binary\",\n });\n\n // In Node.js, the encrypted result is already a Uint8Array\n if (encrypted instanceof Uint8Array) {\n return encrypted;\n }\n\n // If it's a stream (should not happen with format: \"binary\"), read it\n if (\n encrypted &&\n typeof encrypted === \"object\" &&\n \"getReader\" in encrypted\n ) {\n return await streamToUint8Array(\n encrypted as ReadableStream<Uint8Array>,\n );\n }\n\n throw new Error(\"Unexpected encrypted data format\");\n } catch (error) {\n throw wrapCryptoError(\"encrypt with password\", error);\n }\n }\n\n async decryptWithPassword(\n encryptedData: Uint8Array,\n password: string,\n ): Promise<Uint8Array> {\n try {\n const message = await openpgp.readMessage({\n binaryMessage: encryptedData,\n });\n\n // Use password-based decryption with wallet signature as password\n const { data: decrypted } = await openpgp.decrypt({\n message,\n passwords: [password],\n format: \"binary\",\n });\n\n // Convert decrypted data back to Uint8Array\n return new Uint8Array(decrypted as ArrayBuffer);\n } catch (error) {\n throw wrapCryptoError(\"decrypt with password\", error);\n }\n }\n}\n\n/**\n * Node.js implementation of PGP operations using openpgp with Node-specific configuration\n */\nclass NodePGPAdapter implements VanaPGPAdapter {\n async encrypt(data: string, publicKeyArmored: string): Promise<string> {\n try {\n const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });\n\n const encrypted = await openpgp.encrypt({\n message: await openpgp.createMessage({ text: data }),\n encryptionKeys: publicKey,\n config: {\n preferredCompressionAlgorithm: openpgp.enums.compression.zlib,\n },\n });\n\n return encrypted as string;\n } catch (error) {\n throw wrapCryptoError(\"PGP encryption\", error);\n }\n }\n\n async decrypt(\n encryptedData: string,\n privateKeyArmored: string,\n ): Promise<string> {\n try {\n const privateKey = await openpgp.readPrivateKey({\n armoredKey: privateKeyArmored,\n });\n const message = await openpgp.readMessage({\n armoredMessage: encryptedData,\n });\n\n const { data: decrypted } = await openpgp.decrypt({\n message,\n decryptionKeys: privateKey,\n });\n\n return decrypted as string;\n } catch (error) {\n throw wrapCryptoError(\"PGP decryption\", error);\n }\n }\n\n async generateKeyPair(options?: {\n name?: string;\n email?: string;\n passphrase?: string;\n }): Promise<{ publicKey: string; privateKey: string }> {\n try {\n // Use shared utility to get standardized parameters\n const keyGenParams = getPGPKeyGenParams(options);\n\n const { privateKey, publicKey } = await openpgp.generateKey(keyGenParams);\n\n return { publicKey, privateKey };\n } catch (error) {\n throw wrapCryptoError(\"PGP key generation\", error);\n }\n }\n}\n\n/**\n * Node.js implementation of HTTP operations using node-fetch or native fetch\n */\nclass NodeHttpAdapter implements VanaHttpAdapter {\n async fetch(url: string, options?: RequestInit): Promise<Response> {\n if (typeof globalThis.fetch !== \"undefined\") {\n return globalThis.fetch(url, options);\n }\n\n throw new Error(\"No fetch implementation available in Node.js environment\");\n }\n}\n\n/**\n * Node.js implementation of cache operations using in-memory Map with TTL\n */\nclass NodeCacheAdapter implements VanaCacheAdapter {\n private cache = new Map<string, { value: string; expires: number }>();\n private readonly defaultTtl = 2 * 60 * 60 * 1000; // 2 hours in milliseconds\n\n get(key: string): string | null {\n const entry = this.cache.get(key);\n if (!entry) {\n return null;\n }\n\n // Check if expired\n if (Date.now() > entry.expires) {\n this.cache.delete(key);\n return null;\n }\n\n return entry.value;\n }\n\n set(key: string, value: string): void {\n this.cache.set(key, {\n value,\n expires: Date.now() + this.defaultTtl,\n });\n }\n\n delete(key: string): void {\n this.cache.delete(key);\n }\n\n clear(): void {\n this.cache.clear();\n }\n}\n\n/**\n * Complete Node.js platform adapter implementation\n */\nexport class NodePlatformAdapter implements VanaPlatformAdapter {\n crypto: VanaCryptoAdapter;\n pgp: VanaPGPAdapter;\n http: VanaHttpAdapter;\n cache: VanaCacheAdapter;\n platform: \"node\" = \"node\" as const;\n\n constructor() {\n this.crypto = new NodeCryptoAdapter();\n this.pgp = new NodePGPAdapter();\n this.http = new NodeHttpAdapter();\n this.cache = new NodeCacheAdapter();\n }\n}\n\n/**\n * Default instance export for backwards compatibility\n */\nexport const nodePlatformAdapter: VanaPlatformAdapter =\n new NodePlatformAdapter();\n","/**\n * Shared crypto utilities for platform adapters\n *\n * IMPORTANT: This module contains NO IMPORTS to avoid affecting bundle loading.\n * All functions are pure utilities that can be safely shared across platforms.\n */\n\n/**\n * Process wallet public key for encryption operations\n * Removes 0x prefix and ensures uncompressed format (65 bytes with 0x04 prefix)\n *\n * @param publicKey The public key (with or without 0x prefix)\n * @returns Buffer containing uncompressed public key\n */\nexport function processWalletPublicKey(publicKey: string): Buffer {\n const publicKeyHex = publicKey.startsWith(\"0x\")\n ? publicKey.slice(2)\n : publicKey;\n const publicKeyBytes = Buffer.from(publicKeyHex, \"hex\");\n\n // Ensure public key is in uncompressed format (65 bytes with 0x04 prefix)\n // If it's 64 bytes, add the 0x04 prefix; if already 65 bytes, use as-is\n return publicKeyBytes.length === 64\n ? Buffer.concat([Buffer.from([4]), publicKeyBytes])\n : publicKeyBytes;\n}\n\n/**\n * Process wallet private key for decryption operations\n * Removes 0x prefix and converts to Buffer\n *\n * @param privateKey The private key (with or without 0x prefix)\n * @returns Buffer containing private key\n */\nexport function processWalletPrivateKey(privateKey: string): Buffer {\n const privateKeyHex = privateKey.startsWith(\"0x\")\n ? privateKey.slice(2)\n : privateKey;\n return Buffer.from(privateKeyHex, \"hex\");\n}\n\n/**\n * Parse encrypted data buffer into components\n * Extracts IV, ephemeral public key, ciphertext, and MAC from a concatenated buffer\n *\n * @param encryptedBuffer The buffer containing encrypted data\n * @returns Object with parsed components\n */\nexport function parseEncryptedDataBuffer(encryptedBuffer: Buffer) {\n return {\n iv: encryptedBuffer.slice(0, 16),\n ephemPublicKey: encryptedBuffer.slice(16, 81), // 65 bytes for uncompressed public key\n ciphertext: encryptedBuffer.slice(81, -32),\n mac: encryptedBuffer.slice(-32),\n };\n}\n\n/**\n * Convert hex string to Uint8Array\n *\n * @param hex The hex string to convert\n * @returns Uint8Array representation\n */\nexport function hexToUint8Array(hex: string): Uint8Array {\n const result = new Uint8Array(hex.length / 2);\n for (let i = 0; i < hex.length; i += 2) {\n result[i / 2] = parseInt(hex.substr(i, 2), 16);\n }\n return result;\n}\n\n/**\n * Convert Uint8Array to hex string\n *\n * @param array The Uint8Array to convert\n * @returns Hex string representation\n */\nexport function uint8ArrayToHex(array: Uint8Array): string {\n return Array.from(array, (byte) => byte.toString(16).padStart(2, \"0\")).join(\n \"\",\n );\n}\n\n/**\n * Cross-platform base64 encoding\n * Works in both Node.js and browser environments\n *\n * @param str The string to encode\n * @returns Base64 encoded string\n */\nexport function toBase64(str: string): string {\n if (typeof Buffer !== \"undefined\") {\n // Node.js environment\n return Buffer.from(str, \"utf8\").toString(\"base64\");\n } else if (typeof btoa !== \"undefined\") {\n // Browser environment\n return btoa(str);\n } else {\n // Fallback manual implementation\n const chars =\n \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n let result = \"\";\n let i = 0;\n while (i < str.length) {\n const a = str.charCodeAt(i++);\n const b = i < str.length ? str.charCodeAt(i++) : 0;\n const c = i < str.length ? str.charCodeAt(i++) : 0;\n\n const bitmap = (a << 16) | (b << 8) | c;\n\n result += chars.charAt((bitmap >> 18) & 63);\n result += chars.charAt((bitmap >> 12) & 63);\n result += i - 2 < str.length ? chars.charAt((bitmap >> 6) & 63) : \"=\";\n result += i - 1 < str.length ? chars.charAt(bitmap & 63) : \"=\";\n }\n return result;\n }\n}\n\n/**\n * Cross-platform base64 decoding\n * Works in both Node.js and browser environments\n *\n * @param str The base64 string to decode\n * @returns Decoded string\n */\nexport function fromBase64(str: string): string {\n if (typeof Buffer !== \"undefined\") {\n // Node.js environment\n return Buffer.from(str, \"base64\").toString(\"utf8\");\n } else if (typeof atob !== \"undefined\") {\n // Browser environment\n return atob(str);\n } else {\n // Fallback manual implementation\n const chars =\n \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n let result = \"\";\n let i = 0;\n\n // Remove any characters not in the base64 character set\n str = str.replace(/[^A-Za-z0-9+/]/g, \"\");\n\n while (i < str.length) {\n const encoded1 = chars.indexOf(str.charAt(i++));\n const encoded2 = chars.indexOf(str.charAt(i++));\n const encoded3 = chars.indexOf(str.charAt(i++));\n const encoded4 = chars.indexOf(str.charAt(i++));\n\n const bitmap =\n (encoded1 << 18) | (encoded2 << 12) | (encoded3 << 6) | encoded4;\n\n result += String.fromCharCode((bitmap >> 16) & 255);\n if (encoded3 !== 64) result += String.fromCharCode((bitmap >> 8) & 255);\n if (encoded4 !== 64) result += String.fromCharCode(bitmap & 255);\n }\n return result;\n }\n}\n","/**\n * Shared PGP utilities for platform adapters\n *\n * IMPORTANT: This module contains NO IMPORTS to avoid affecting bundle loading.\n * All functions are pure utilities that can be safely shared across platforms.\n */\n\n/**\n * Standard OpenPGP configuration for consistent behavior across platforms\n * Uses enum values instead of importing openpgp to avoid loading issues\n */\nexport const STANDARD_PGP_CONFIG = {\n preferredCompressionAlgorithm: 2, // zlib (openpgp.enums.compression.zlib)\n preferredSymmetricAlgorithm: 7, // aes256 (openpgp.enums.symmetric.aes256)\n} as const;\n\n/**\n * Process PGP key generation options with sensible defaults\n *\n * @param options - Optional key generation parameters\n * @param options.name - The name for the PGP key (defaults to \"Vana User\")\n * @param options.email - The email for the PGP key (defaults to \"user@vana.org\")\n * @param options.passphrase - Optional passphrase to protect the private key\n * @returns Processed options with defaults applied\n */\nexport function processPGPKeyOptions(options?: {\n name?: string;\n email?: string;\n passphrase?: string;\n}) {\n return {\n name: options?.name || \"Vana User\",\n email: options?.email || \"user@vana.org\",\n passphrase: options?.passphrase,\n };\n}\n\n/**\n * Get standard PGP key generation parameters\n * Combines default values with standard configuration\n *\n * @param options - Optional key generation parameters\n * @param options.name - The name for the PGP key (defaults to \"Vana User\")\n * @param options.email - The email for the PGP key (defaults to \"user@vana.org\")\n * @param options.passphrase - Optional passphrase to protect the private key\n * @returns Complete key generation parameters object\n */\nexport function getPGPKeyGenParams(options?: {\n name?: string;\n email?: string;\n passphrase?: string;\n}) {\n const { name, email, passphrase } = processPGPKeyOptions(options);\n\n return {\n type: \"rsa\" as const,\n rsaBits: 2048,\n userIDs: [{ name, email }],\n passphrase,\n config: STANDARD_PGP_CONFIG,\n };\n}\n","/**\n * Shared error utilities for platform adapters\n *\n * IMPORTANT: This module contains NO IMPORTS to avoid affecting bundle loading.\n * All functions are pure utilities that can be safely shared across platforms.\n */\n\n/**\n * Wrap platform-specific errors with consistent messaging\n * Provides consistent error formatting across all crypto operations\n *\n * @param operation The operation that failed (e.g., \"encryption\", \"decryption\")\n * @param error The original error that occurred\n * @returns Wrapped error with consistent format\n */\nexport function wrapCryptoError(operation: string, error: unknown): Error {\n const message = error instanceof Error ? error.message : \"Unknown error\";\n return new Error(`${operation} failed: ${message}`);\n}\n\n/**\n * Validate encrypted data structure has required fields\n * Ensures encrypted data objects contain the expected properties\n *\n * @param data The data structure to validate\n * @throws Error if data structure is invalid\n */\nexport function validateEncryptedDataStructure(data: unknown): void {\n if (!data || typeof data !== \"object\") {\n throw new Error(\"Invalid encrypted data format\");\n }\n\n const obj = data as Record<string, unknown>;\n if (!obj.encrypted || !obj.iv || !obj.ephemeralPublicKey) {\n throw new Error(\"Invalid encrypted data format\");\n }\n}\n","/**\n * Shared stream utilities for platform adapters\n *\n * IMPORTANT: This module contains NO IMPORTS to avoid affecting bundle loading.\n * All functions are pure utilities that can be safely shared across platforms.\n */\n\n/**\n * Convert ReadableStream to Uint8Array\n * Used primarily in Node.js environment where OpenPGP may return streams\n *\n * @param stream The ReadableStream to convert\n * @returns Promise resolving to Uint8Array containing all stream data\n */\nexport async function streamToUint8Array(\n stream: ReadableStream<Uint8Array>,\n): Promise<Uint8Array> {\n const reader = stream.getReader();\n const chunks: Uint8Array[] = [];\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n chunks.push(value);\n }\n } finally {\n reader.releaseLock();\n }\n\n // Concatenate all chunks\n const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);\n const result = new Uint8Array(totalLength);\n let offset = 0;\n for (const chunk of chunks) {\n result.set(chunk, offset);\n offset += chunk.length;\n }\n\n return result;\n}\n"],"mappings":";AAOA,SAAS,mBAAmB;AAC5B,YAAY,aAAa;;;ACMlB,SAAS,uBAAuB,WAA2B;AAChE,QAAM,eAAe,UAAU,WAAW,IAAI,IAC1C,UAAU,MAAM,CAAC,IACjB;AACJ,QAAM,iBAAiB,OAAO,KAAK,cAAc,KAAK;AAItD,SAAO,eAAe,WAAW,KAC7B,OAAO,OAAO,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,IAChD;AACN;AASO,SAAS,wBAAwB,YAA4B;AAClE,QAAM,gBAAgB,WAAW,WAAW,IAAI,IAC5C,WAAW,MAAM,CAAC,IAClB;AACJ,SAAO,OAAO,KAAK,eAAe,KAAK;AACzC;AASO,SAAS,yBAAyB,iBAAyB;AAChE,SAAO;AAAA,IAC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;AAAA,EAEA,IAAI,KAAa,OAAqB;AACpC,SAAK,MAAM,IAAI,KAAK;AAAA,MAClB;AAAA,MACA,SAAS,KAAK,IAAI,IAAI,KAAK;AAAA,IAC7B,CAAC;AAAA,EACH;AAAA,EAEA,OAAO,KAAmB;AACxB,SAAK,MAAM,OAAO,GAAG;AAAA,EACvB;AAAA,EAEA,QAAc;AACZ,SAAK,MAAM,MAAM;AAAA,EACnB;AACF;AAKO,IAAM,sBAAN,MAAyD;AAAA,EAC9D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAmB;AAAA,EAEnB,cAAc;AACZ,SAAK,SAAS,IAAI,kBAAkB;AACpC,SAAK,MAAM,IAAI,eAAe;AAC9B,SAAK,OAAO,IAAI,gBAAgB;AAChC,SAAK,QAAQ,IAAI,iBAAiB;AAAA,EACpC;AACF;AAKO,IAAM,sBACX,IAAI,oBAAoB;","names":[]}
|
|
@@ -1,204 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* This interface abstracts all environment-specific dependencies to ensure
|
|
5
|
-
* the SDK works seamlessly across Node.js and browser/SSR environments.
|
|
6
|
-
*
|
|
7
|
-
* **Implementation Context:**
|
|
8
|
-
* - Node.js: Uses native crypto modules and full OpenPGP support
|
|
9
|
-
* - Browser: Uses Web Crypto API and browser-compatible libraries
|
|
10
|
-
* - SSR: Automatically selects appropriate implementation based on runtime
|
|
11
|
-
*
|
|
12
|
-
* **Usage Notes:**
|
|
13
|
-
* Platform adapters are automatically selected by the SDK. Direct usage is only
|
|
14
|
-
* needed for custom implementations or testing.
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* Platform type identifier
|
|
18
|
-
*/
|
|
19
|
-
type PlatformType = "node" | "browser";
|
|
20
|
-
/**
|
|
21
|
-
* Encryption operations that require different implementations per platform
|
|
22
|
-
*/
|
|
23
|
-
interface VanaCryptoAdapter {
|
|
24
|
-
/**
|
|
25
|
-
* Encrypt data with a public key using asymmetric cryptography
|
|
26
|
-
*
|
|
27
|
-
* **Usage Context:**
|
|
28
|
-
* - Used internally for file encryption before storage
|
|
29
|
-
* - Public key format: Armored PGP public key string
|
|
30
|
-
* - Returns base64-encoded encrypted data
|
|
31
|
-
*
|
|
32
|
-
* @param data The data to encrypt
|
|
33
|
-
* @param publicKey The public key for encryption
|
|
34
|
-
* @returns Promise resolving to encrypted data
|
|
35
|
-
*/
|
|
36
|
-
encryptWithPublicKey(data: string, publicKey: string): Promise<string>;
|
|
37
|
-
/**
|
|
38
|
-
* Decrypt data with a private key using asymmetric cryptography
|
|
39
|
-
*
|
|
40
|
-
* @param encryptedData The encrypted data
|
|
41
|
-
* @param privateKey The private key for decryption
|
|
42
|
-
* @returns Promise resolving to decrypted data
|
|
43
|
-
*/
|
|
44
|
-
decryptWithPrivateKey(encryptedData: string, privateKey: string): Promise<string>;
|
|
45
|
-
/**
|
|
46
|
-
* Generate a new key pair for asymmetric cryptography
|
|
47
|
-
*
|
|
48
|
-
* @returns Promise resolving to public and private key pair
|
|
49
|
-
*/
|
|
50
|
-
generateKeyPair(): Promise<{
|
|
51
|
-
publicKey: string;
|
|
52
|
-
privateKey: string;
|
|
53
|
-
}>;
|
|
54
|
-
/**
|
|
55
|
-
* Encrypt data with a wallet's public key using ECDH cryptography
|
|
56
|
-
* Uses platform-appropriate ECDH implementation (eccrypto vs eccrypto-js)
|
|
57
|
-
*
|
|
58
|
-
* **Usage Context:**
|
|
59
|
-
* - Used for sharing encryption keys with permission recipients
|
|
60
|
-
* - Public key format: Compressed or uncompressed secp256k1 hex string
|
|
61
|
-
* - Compatible with Ethereum wallet public keys
|
|
62
|
-
*
|
|
63
|
-
* @param data The data to encrypt (string)
|
|
64
|
-
* @param publicKey The wallet's public key (secp256k1)
|
|
65
|
-
* @returns Promise resolving to encrypted data as hex string
|
|
66
|
-
*/
|
|
67
|
-
encryptWithWalletPublicKey(data: string, publicKey: string): Promise<string>;
|
|
68
|
-
/**
|
|
69
|
-
* Decrypt data with a wallet's private key using ECDH cryptography
|
|
70
|
-
* Uses platform-appropriate ECDH implementation (eccrypto vs eccrypto-js)
|
|
71
|
-
*
|
|
72
|
-
* @param encryptedData The encrypted data as hex string
|
|
73
|
-
* @param privateKey The wallet's private key (secp256k1)
|
|
74
|
-
* @returns Promise resolving to decrypted data as string
|
|
75
|
-
*/
|
|
76
|
-
decryptWithWalletPrivateKey(encryptedData: string, privateKey: string): Promise<string>;
|
|
77
|
-
/**
|
|
78
|
-
* Encrypt data with a password using PGP password-based encryption
|
|
79
|
-
* Uses platform-appropriate OpenPGP implementation with consistent format
|
|
80
|
-
*
|
|
81
|
-
* @param data The data to encrypt as Uint8Array
|
|
82
|
-
* @param password The password for encryption (typically wallet signature)
|
|
83
|
-
* @returns Promise resolving to encrypted data as Uint8Array
|
|
84
|
-
*/
|
|
85
|
-
encryptWithPassword(data: Uint8Array, password: string): Promise<Uint8Array>;
|
|
86
|
-
/**
|
|
87
|
-
* Decrypt data with a password using PGP password-based decryption
|
|
88
|
-
* Uses platform-appropriate OpenPGP implementation with consistent format
|
|
89
|
-
*
|
|
90
|
-
* @param encryptedData The encrypted data as Uint8Array
|
|
91
|
-
* @param password The password for decryption (typically wallet signature)
|
|
92
|
-
* @returns Promise resolving to decrypted data as Uint8Array
|
|
93
|
-
*/
|
|
94
|
-
decryptWithPassword(encryptedData: Uint8Array, password: string): Promise<Uint8Array>;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* PGP operations that require different configurations per platform
|
|
98
|
-
*/
|
|
99
|
-
interface VanaPGPAdapter {
|
|
100
|
-
/**
|
|
101
|
-
* Encrypt data using PGP with proper platform configuration
|
|
102
|
-
*
|
|
103
|
-
* @param data The data to encrypt
|
|
104
|
-
* @param publicKey The PGP public key
|
|
105
|
-
* @returns Promise resolving to encrypted data
|
|
106
|
-
*/
|
|
107
|
-
encrypt(data: string, publicKey: string): Promise<string>;
|
|
108
|
-
/**
|
|
109
|
-
* Decrypt data using PGP with proper platform configuration
|
|
110
|
-
*
|
|
111
|
-
* @param encryptedData The encrypted data
|
|
112
|
-
* @param privateKey The PGP private key
|
|
113
|
-
* @returns Promise resolving to decrypted data
|
|
114
|
-
*/
|
|
115
|
-
decrypt(encryptedData: string, privateKey: string): Promise<string>;
|
|
116
|
-
/**
|
|
117
|
-
* Generate a new PGP key pair with platform-appropriate configuration
|
|
118
|
-
*
|
|
119
|
-
* @param options - Key generation options
|
|
120
|
-
* @param options.name - The name for the PGP key
|
|
121
|
-
* @param options.email - The email for the PGP key
|
|
122
|
-
* @param options.passphrase - Optional passphrase to protect the private key
|
|
123
|
-
* @returns Promise resolving to public and private key pair
|
|
124
|
-
*/
|
|
125
|
-
generateKeyPair(options?: {
|
|
126
|
-
name?: string;
|
|
127
|
-
email?: string;
|
|
128
|
-
passphrase?: string;
|
|
129
|
-
}): Promise<{
|
|
130
|
-
publicKey: string;
|
|
131
|
-
privateKey: string;
|
|
132
|
-
}>;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* HTTP operations that need consistent API across platforms
|
|
136
|
-
*/
|
|
137
|
-
interface VanaHttpAdapter {
|
|
138
|
-
/**
|
|
139
|
-
* Perform HTTP request with platform-appropriate fetch implementation
|
|
140
|
-
*
|
|
141
|
-
* @param url The URL to request
|
|
142
|
-
* @param options Request options
|
|
143
|
-
* @returns Promise resolving to response
|
|
144
|
-
*/
|
|
145
|
-
fetch(url: string, options?: RequestInit): Promise<Response>;
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Main platform adapter interface that combines all platform-specific functionality
|
|
149
|
-
*
|
|
150
|
-
* **Implementation Guidelines:**
|
|
151
|
-
* 1. All methods must maintain consistent behavior across platforms
|
|
152
|
-
* 2. Error types and messages should be unified
|
|
153
|
-
* 3. Data formats (encoding, serialization) must be identical
|
|
154
|
-
* 4. Performance characteristics can vary but API must be consistent
|
|
155
|
-
*
|
|
156
|
-
* **Custom Implementation Example:**
|
|
157
|
-
* ```typescript
|
|
158
|
-
* class CustomPlatformAdapter implements VanaPlatformAdapter {
|
|
159
|
-
* crypto = new CustomCryptoAdapter();
|
|
160
|
-
* pgp = new CustomPGPAdapter();
|
|
161
|
-
* http = new CustomHttpAdapter();
|
|
162
|
-
* platform = 'browser' as const;
|
|
163
|
-
* }
|
|
164
|
-
* ```
|
|
165
|
-
*/
|
|
166
|
-
interface VanaPlatformAdapter {
|
|
167
|
-
/**
|
|
168
|
-
* Crypto operations adapter
|
|
169
|
-
*/
|
|
170
|
-
crypto: VanaCryptoAdapter;
|
|
171
|
-
/**
|
|
172
|
-
* PGP operations adapter
|
|
173
|
-
*/
|
|
174
|
-
pgp: VanaPGPAdapter;
|
|
175
|
-
/**
|
|
176
|
-
* HTTP operations adapter
|
|
177
|
-
*/
|
|
178
|
-
http: VanaHttpAdapter;
|
|
179
|
-
/**
|
|
180
|
-
* Platform identifier for debugging/telemetry
|
|
181
|
-
*/
|
|
182
|
-
readonly platform: PlatformType;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Browser implementation of the Vana Platform Adapter
|
|
187
|
-
*
|
|
188
|
-
* This implementation uses browser-compatible libraries and configurations
|
|
189
|
-
* to provide crypto, PGP, and HTTP functionality without Node.js dependencies.
|
|
190
|
-
*/
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Complete browser platform adapter implementation
|
|
194
|
-
*/
|
|
195
|
-
declare class BrowserPlatformAdapter implements VanaPlatformAdapter {
|
|
196
|
-
crypto: VanaCryptoAdapter;
|
|
197
|
-
pgp: VanaPGPAdapter;
|
|
198
|
-
http: VanaHttpAdapter;
|
|
199
|
-
platform: "browser";
|
|
200
|
-
constructor();
|
|
201
|
-
}
|
|
1
|
+
import { V as VanaPlatformAdapter, P as PlatformType } from './browser-cRpdLQ3-.js';
|
|
2
|
+
export { B as BrowserPlatformAdapter } from './browser-cRpdLQ3-.js';
|
|
202
3
|
|
|
203
4
|
/**
|
|
204
5
|
* Browser-only exports for platform adapters
|
|
@@ -256,4 +57,4 @@ declare function getPlatformCapabilities(): {
|
|
|
256
57
|
streams: boolean;
|
|
257
58
|
};
|
|
258
59
|
|
|
259
|
-
export {
|
|
60
|
+
export { VanaPlatformAdapter, createBrowserPlatformAdapter, createPlatformAdapterSafe, detectPlatform, getPlatformCapabilities, isPlatformSupported };
|
package/dist/platform.browser.js
CHANGED
|
@@ -75,7 +75,7 @@ var init_error_utils = __esm({
|
|
|
75
75
|
|
|
76
76
|
// src/platform/browser.ts
|
|
77
77
|
import * as openpgp from "openpgp";
|
|
78
|
-
var BrowserCryptoAdapter, BrowserPGPAdapter, BrowserHttpAdapter, BrowserPlatformAdapter, browserPlatformAdapter;
|
|
78
|
+
var BrowserCryptoAdapter, BrowserPGPAdapter, BrowserHttpAdapter, BrowserCacheAdapter, BrowserPlatformAdapter, browserPlatformAdapter;
|
|
79
79
|
var init_browser = __esm({
|
|
80
80
|
"src/platform/browser.ts"() {
|
|
81
81
|
"use strict";
|
|
@@ -254,15 +254,62 @@ var init_browser = __esm({
|
|
|
254
254
|
return fetch(url, options);
|
|
255
255
|
}
|
|
256
256
|
};
|
|
257
|
+
BrowserCacheAdapter = class {
|
|
258
|
+
constructor() {
|
|
259
|
+
__publicField(this, "prefix", "vana_cache_");
|
|
260
|
+
}
|
|
261
|
+
get(key) {
|
|
262
|
+
try {
|
|
263
|
+
if (typeof sessionStorage === "undefined") {
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
return sessionStorage.getItem(this.prefix + key);
|
|
267
|
+
} catch {
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
set(key, value) {
|
|
272
|
+
try {
|
|
273
|
+
if (typeof sessionStorage !== "undefined") {
|
|
274
|
+
sessionStorage.setItem(this.prefix + key, value);
|
|
275
|
+
}
|
|
276
|
+
} catch {
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
delete(key) {
|
|
280
|
+
try {
|
|
281
|
+
if (typeof sessionStorage !== "undefined") {
|
|
282
|
+
sessionStorage.removeItem(this.prefix + key);
|
|
283
|
+
}
|
|
284
|
+
} catch {
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
clear() {
|
|
288
|
+
try {
|
|
289
|
+
if (typeof sessionStorage === "undefined") {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
const keys = Object.keys(sessionStorage);
|
|
293
|
+
for (const key of keys) {
|
|
294
|
+
if (key.startsWith(this.prefix)) {
|
|
295
|
+
sessionStorage.removeItem(key);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
} catch {
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
};
|
|
257
302
|
BrowserPlatformAdapter = class {
|
|
258
303
|
constructor() {
|
|
259
304
|
__publicField(this, "crypto");
|
|
260
305
|
__publicField(this, "pgp");
|
|
261
306
|
__publicField(this, "http");
|
|
307
|
+
__publicField(this, "cache");
|
|
262
308
|
__publicField(this, "platform", "browser");
|
|
263
309
|
this.crypto = new BrowserCryptoAdapter();
|
|
264
310
|
this.pgp = new BrowserPGPAdapter();
|
|
265
311
|
this.http = new BrowserHttpAdapter();
|
|
312
|
+
this.cache = new BrowserCacheAdapter();
|
|
266
313
|
}
|
|
267
314
|
};
|
|
268
315
|
browserPlatformAdapter = new BrowserPlatformAdapter();
|