@opendatalabs/vana-sdk 0.1.0-alpha.82bbb39 → 0.1.0-alpha.899ca9d
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 +42 -0
- package/dist/browser-DY8XDblx.d.ts +241 -0
- package/dist/browser.d.ts +1 -0
- package/dist/browser.js +309 -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 +1756 -1479
- package/dist/index.browser.js +37686 -35103
- package/dist/index.browser.js.map +1 -1
- package/dist/index.node.cjs +38174 -35582
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.d.cts +1790 -1486
- package/dist/index.node.d.ts +1790 -1486
- package/dist/index.node.js +38402 -35813
- package/dist/index.node.js.map +1 -1
- package/dist/node-D9-F9uEP.d.cts +238 -0
- package/dist/node-D9-F9uEP.d.ts +238 -0
- package/dist/node.cjs +348 -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 +311 -0
- package/dist/node.js.map +1 -0
- package/dist/platform.browser.d.ts +3 -236
- package/dist/platform.browser.js +31 -8
- package/dist/platform.browser.js.map +1 -1
- package/dist/platform.cjs +72 -62
- 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 +72 -62
- package/dist/platform.js.map +1 -1
- package/dist/platform.node.cjs +72 -62
- package/dist/platform.node.cjs.map +1 -1
- package/dist/platform.node.d.cts +7 -236
- package/dist/platform.node.d.ts +7 -236
- package/dist/platform.node.js +72 -62
- package/dist/platform.node.js.map +1 -1
- package/package.json +17 -12
package/dist/platform.node.d.ts
CHANGED
|
@@ -1,225 +1,15 @@
|
|
|
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
|
-
* Simple cache operations that work across platforms
|
|
149
|
-
*/
|
|
150
|
-
interface VanaCacheAdapter {
|
|
151
|
-
/**
|
|
152
|
-
* Get a value from the cache
|
|
153
|
-
*
|
|
154
|
-
* @param key The cache key
|
|
155
|
-
* @returns The cached value or null if not found/expired
|
|
156
|
-
*/
|
|
157
|
-
get(key: string): string | null;
|
|
158
|
-
/**
|
|
159
|
-
* Set a value in the cache
|
|
160
|
-
*
|
|
161
|
-
* @param key The cache key
|
|
162
|
-
* @param value The value to cache
|
|
163
|
-
*/
|
|
164
|
-
set(key: string, value: string): void;
|
|
165
|
-
/**
|
|
166
|
-
* Delete a value from the cache
|
|
167
|
-
*
|
|
168
|
-
* @param key The cache key
|
|
169
|
-
*/
|
|
170
|
-
delete(key: string): void;
|
|
171
|
-
/**
|
|
172
|
-
* Clear all values from the cache
|
|
173
|
-
*/
|
|
174
|
-
clear(): void;
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Main platform adapter interface that combines all platform-specific functionality
|
|
178
|
-
*
|
|
179
|
-
* **Implementation Guidelines:**
|
|
180
|
-
* 1. All methods must maintain consistent behavior across platforms
|
|
181
|
-
* 2. Error types and messages should be unified
|
|
182
|
-
* 3. Data formats (encoding, serialization) must be identical
|
|
183
|
-
* 4. Performance characteristics can vary but API must be consistent
|
|
184
|
-
*
|
|
185
|
-
* **Custom Implementation Example:**
|
|
186
|
-
* ```typescript
|
|
187
|
-
* class CustomPlatformAdapter implements VanaPlatformAdapter {
|
|
188
|
-
* crypto = new CustomCryptoAdapter();
|
|
189
|
-
* pgp = new CustomPGPAdapter();
|
|
190
|
-
* http = new CustomHttpAdapter();
|
|
191
|
-
* platform = 'browser' as const;
|
|
192
|
-
* }
|
|
193
|
-
* ```
|
|
194
|
-
*/
|
|
195
|
-
interface VanaPlatformAdapter {
|
|
196
|
-
/**
|
|
197
|
-
* Crypto operations adapter
|
|
198
|
-
*/
|
|
199
|
-
crypto: VanaCryptoAdapter;
|
|
200
|
-
/**
|
|
201
|
-
* PGP operations adapter
|
|
202
|
-
*/
|
|
203
|
-
pgp: VanaPGPAdapter;
|
|
204
|
-
/**
|
|
205
|
-
* HTTP operations adapter
|
|
206
|
-
*/
|
|
207
|
-
http: VanaHttpAdapter;
|
|
208
|
-
/**
|
|
209
|
-
* Cache operations adapter
|
|
210
|
-
*/
|
|
211
|
-
cache: VanaCacheAdapter;
|
|
212
|
-
/**
|
|
213
|
-
* Platform identifier for debugging/telemetry
|
|
214
|
-
*/
|
|
215
|
-
readonly platform: PlatformType;
|
|
216
|
-
}
|
|
1
|
+
import { V as VanaPlatformAdapter, a as VanaCryptoAdapter, b as VanaPGPAdapter, c as VanaHttpAdapter, d as VanaCacheAdapter, P as PlatformType } from './node-D9-F9uEP.js';
|
|
2
|
+
export { N as NodePlatformAdapter } from './node-D9-F9uEP.js';
|
|
217
3
|
|
|
218
4
|
/**
|
|
219
5
|
* Browser implementation of the Vana Platform Adapter
|
|
220
6
|
*
|
|
221
7
|
* This implementation uses browser-compatible libraries and configurations
|
|
222
8
|
* to provide crypto, PGP, and HTTP functionality without Node.js dependencies.
|
|
9
|
+
*
|
|
10
|
+
* WARNING: Dependencies that access globals during init
|
|
11
|
+
* MUST be dynamically imported to support Turbopack.
|
|
12
|
+
* See: https://github.com/vercel/next.js/issues/82632
|
|
223
13
|
*/
|
|
224
14
|
|
|
225
15
|
/**
|
|
@@ -234,25 +24,6 @@ declare class BrowserPlatformAdapter implements VanaPlatformAdapter {
|
|
|
234
24
|
constructor();
|
|
235
25
|
}
|
|
236
26
|
|
|
237
|
-
/**
|
|
238
|
-
* Node.js implementation of the Vana Platform Adapter
|
|
239
|
-
*
|
|
240
|
-
* This implementation uses Node.js-specific libraries and configurations
|
|
241
|
-
* to provide crypto, PGP, and HTTP functionality.
|
|
242
|
-
*/
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Complete Node.js platform adapter implementation
|
|
246
|
-
*/
|
|
247
|
-
declare class NodePlatformAdapter implements VanaPlatformAdapter {
|
|
248
|
-
crypto: VanaCryptoAdapter;
|
|
249
|
-
pgp: VanaPGPAdapter;
|
|
250
|
-
http: VanaHttpAdapter;
|
|
251
|
-
cache: VanaCacheAdapter;
|
|
252
|
-
platform: "node";
|
|
253
|
-
constructor();
|
|
254
|
-
}
|
|
255
|
-
|
|
256
27
|
/**
|
|
257
28
|
* Platform detection and adapter utilities
|
|
258
29
|
*
|
|
@@ -331,4 +102,4 @@ declare function createBrowserPlatformAdapter(): VanaPlatformAdapter;
|
|
|
331
102
|
*/
|
|
332
103
|
declare function createPlatformAdapterSafe(): Promise<VanaPlatformAdapter>;
|
|
333
104
|
|
|
334
|
-
export { BrowserPlatformAdapter,
|
|
105
|
+
export { BrowserPlatformAdapter, VanaPlatformAdapter, createBrowserPlatformAdapter, createNodePlatformAdapter, createPlatformAdapter, createPlatformAdapterFor, createPlatformAdapterSafe, detectPlatform, getPlatformCapabilities, isPlatformSupported };
|
package/dist/platform.node.js
CHANGED
|
@@ -75,26 +75,46 @@ var init_error_utils = __esm({
|
|
|
75
75
|
}
|
|
76
76
|
});
|
|
77
77
|
|
|
78
|
+
// src/utils/lazy-import.ts
|
|
79
|
+
function lazyImport(importFn) {
|
|
80
|
+
let cached = null;
|
|
81
|
+
return () => {
|
|
82
|
+
if (!cached) {
|
|
83
|
+
cached = importFn().catch((err) => {
|
|
84
|
+
cached = null;
|
|
85
|
+
throw new Error("Failed to load module", { cause: err });
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return cached;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
var init_lazy_import = __esm({
|
|
92
|
+
"src/utils/lazy-import.ts"() {
|
|
93
|
+
"use strict";
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
78
97
|
// src/platform/browser.ts
|
|
79
98
|
var browser_exports = {};
|
|
80
99
|
__export(browser_exports, {
|
|
81
100
|
BrowserPlatformAdapter: () => BrowserPlatformAdapter,
|
|
82
101
|
browserPlatformAdapter: () => browserPlatformAdapter
|
|
83
102
|
});
|
|
84
|
-
|
|
85
|
-
var BrowserCryptoAdapter, BrowserPGPAdapter, BrowserHttpAdapter, BrowserCacheAdapter, BrowserPlatformAdapter, browserPlatformAdapter;
|
|
103
|
+
var getOpenPGP, BrowserCryptoAdapter, BrowserPGPAdapter, BrowserHttpAdapter, BrowserCacheAdapter, BrowserPlatformAdapter, browserPlatformAdapter;
|
|
86
104
|
var init_browser = __esm({
|
|
87
105
|
"src/platform/browser.ts"() {
|
|
88
106
|
"use strict";
|
|
89
107
|
init_crypto_utils();
|
|
90
108
|
init_pgp_utils();
|
|
91
109
|
init_error_utils();
|
|
110
|
+
init_lazy_import();
|
|
111
|
+
getOpenPGP = lazyImport(() => import("openpgp"));
|
|
92
112
|
BrowserCryptoAdapter = class {
|
|
93
113
|
async encryptWithPublicKey(data, publicKeyHex) {
|
|
94
114
|
try {
|
|
95
|
-
const
|
|
115
|
+
const eccrypto = await import("eccrypto-js");
|
|
96
116
|
const publicKeyBuffer = Buffer.from(publicKeyHex, "hex");
|
|
97
|
-
const encrypted = await
|
|
117
|
+
const encrypted = await eccrypto.encrypt(
|
|
98
118
|
publicKeyBuffer,
|
|
99
119
|
Buffer.from(data, "utf8")
|
|
100
120
|
);
|
|
@@ -111,12 +131,12 @@ var init_browser = __esm({
|
|
|
111
131
|
}
|
|
112
132
|
async decryptWithPrivateKey(encryptedData, privateKeyHex) {
|
|
113
133
|
try {
|
|
114
|
-
const
|
|
134
|
+
const eccrypto = await import("eccrypto-js");
|
|
115
135
|
const privateKeyBuffer = processWalletPrivateKey(privateKeyHex);
|
|
116
136
|
const encryptedBuffer = Buffer.from(encryptedData, "hex");
|
|
117
137
|
const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
|
|
118
138
|
const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
|
|
119
|
-
const decryptedBuffer = await
|
|
139
|
+
const decryptedBuffer = await eccrypto.decrypt(
|
|
120
140
|
privateKeyBuffer,
|
|
121
141
|
encryptedObj
|
|
122
142
|
);
|
|
@@ -127,11 +147,11 @@ var init_browser = __esm({
|
|
|
127
147
|
}
|
|
128
148
|
async generateKeyPair() {
|
|
129
149
|
try {
|
|
130
|
-
const
|
|
150
|
+
const eccrypto = await import("eccrypto-js");
|
|
131
151
|
const privateKeyBytes = new Uint8Array(32);
|
|
132
152
|
crypto.getRandomValues(privateKeyBytes);
|
|
133
153
|
const privateKey = Buffer.from(privateKeyBytes);
|
|
134
|
-
const publicKey =
|
|
154
|
+
const publicKey = eccrypto.getPublicCompressed(privateKey);
|
|
135
155
|
return {
|
|
136
156
|
privateKey: privateKey.toString("hex"),
|
|
137
157
|
publicKey: publicKey.toString("hex")
|
|
@@ -142,9 +162,9 @@ var init_browser = __esm({
|
|
|
142
162
|
}
|
|
143
163
|
async encryptWithWalletPublicKey(data, publicKey) {
|
|
144
164
|
try {
|
|
145
|
-
const
|
|
165
|
+
const eccrypto = await import("eccrypto-js");
|
|
146
166
|
const uncompressedKey = processWalletPublicKey(publicKey);
|
|
147
|
-
const encryptedBuffer = await
|
|
167
|
+
const encryptedBuffer = await eccrypto.encrypt(
|
|
148
168
|
uncompressedKey,
|
|
149
169
|
Buffer.from(data)
|
|
150
170
|
);
|
|
@@ -161,12 +181,12 @@ var init_browser = __esm({
|
|
|
161
181
|
}
|
|
162
182
|
async decryptWithWalletPrivateKey(encryptedData, privateKey) {
|
|
163
183
|
try {
|
|
164
|
-
const
|
|
184
|
+
const eccrypto = await import("eccrypto-js");
|
|
165
185
|
const privateKeyBuffer = processWalletPrivateKey(privateKey);
|
|
166
186
|
const encryptedBuffer = Buffer.from(encryptedData, "hex");
|
|
167
187
|
const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
|
|
168
188
|
const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
|
|
169
|
-
const decryptedBuffer = await
|
|
189
|
+
const decryptedBuffer = await eccrypto.decrypt(
|
|
170
190
|
privateKeyBuffer,
|
|
171
191
|
encryptedObj
|
|
172
192
|
);
|
|
@@ -177,11 +197,11 @@ var init_browser = __esm({
|
|
|
177
197
|
}
|
|
178
198
|
async encryptWithPassword(data, password) {
|
|
179
199
|
try {
|
|
180
|
-
const
|
|
181
|
-
const message = await
|
|
200
|
+
const openpgp = await getOpenPGP();
|
|
201
|
+
const message = await openpgp.createMessage({
|
|
182
202
|
binary: data
|
|
183
203
|
});
|
|
184
|
-
const encrypted = await
|
|
204
|
+
const encrypted = await openpgp.encrypt({
|
|
185
205
|
message,
|
|
186
206
|
passwords: [password],
|
|
187
207
|
format: "binary"
|
|
@@ -195,11 +215,11 @@ var init_browser = __esm({
|
|
|
195
215
|
}
|
|
196
216
|
async decryptWithPassword(encryptedData, password) {
|
|
197
217
|
try {
|
|
198
|
-
const
|
|
199
|
-
const message = await
|
|
218
|
+
const openpgp = await getOpenPGP();
|
|
219
|
+
const message = await openpgp.readMessage({
|
|
200
220
|
binaryMessage: encryptedData
|
|
201
221
|
});
|
|
202
|
-
const { data: decrypted } = await
|
|
222
|
+
const { data: decrypted } = await openpgp.decrypt({
|
|
203
223
|
message,
|
|
204
224
|
passwords: [password],
|
|
205
225
|
format: "binary"
|
|
@@ -213,6 +233,7 @@ var init_browser = __esm({
|
|
|
213
233
|
BrowserPGPAdapter = class {
|
|
214
234
|
async encrypt(data, publicKeyArmored) {
|
|
215
235
|
try {
|
|
236
|
+
const openpgp = await getOpenPGP();
|
|
216
237
|
const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
|
|
217
238
|
const encrypted = await openpgp.encrypt({
|
|
218
239
|
message: await openpgp.createMessage({ text: data }),
|
|
@@ -228,6 +249,7 @@ var init_browser = __esm({
|
|
|
228
249
|
}
|
|
229
250
|
async decrypt(encryptedData, privateKeyArmored) {
|
|
230
251
|
try {
|
|
252
|
+
const openpgp = await getOpenPGP();
|
|
231
253
|
const privateKey = await openpgp.readPrivateKey({
|
|
232
254
|
armoredKey: privateKeyArmored
|
|
233
255
|
});
|
|
@@ -245,6 +267,7 @@ var init_browser = __esm({
|
|
|
245
267
|
}
|
|
246
268
|
async generateKeyPair(options) {
|
|
247
269
|
try {
|
|
270
|
+
const openpgp = await getOpenPGP();
|
|
248
271
|
const keyGenParams = getPGPKeyGenParams(options);
|
|
249
272
|
const { privateKey, publicKey } = await openpgp.generateKey(keyGenParams);
|
|
250
273
|
return { publicKey, privateKey };
|
|
@@ -328,8 +351,6 @@ init_browser();
|
|
|
328
351
|
init_crypto_utils();
|
|
329
352
|
init_pgp_utils();
|
|
330
353
|
init_error_utils();
|
|
331
|
-
import { randomBytes } from "crypto";
|
|
332
|
-
import * as openpgp2 from "openpgp";
|
|
333
354
|
|
|
334
355
|
// src/platform/shared/stream-utils.ts
|
|
335
356
|
async function streamToUint8Array(stream) {
|
|
@@ -355,29 +376,16 @@ async function streamToUint8Array(stream) {
|
|
|
355
376
|
}
|
|
356
377
|
|
|
357
378
|
// src/platform/node.ts
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
try {
|
|
362
|
-
const eccryptoLib = await import("eccrypto");
|
|
363
|
-
eccrypto = {
|
|
364
|
-
encrypt: eccryptoLib.encrypt,
|
|
365
|
-
decrypt: eccryptoLib.decrypt,
|
|
366
|
-
getPublicCompressed: eccryptoLib.getPublicCompressed
|
|
367
|
-
};
|
|
368
|
-
} catch (error) {
|
|
369
|
-
throw new Error(`Failed to load eccrypto library: ${error}`);
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
return eccrypto;
|
|
373
|
-
}
|
|
379
|
+
init_lazy_import();
|
|
380
|
+
var getOpenPGP2 = lazyImport(() => import("openpgp"));
|
|
381
|
+
var getEccrypto = lazyImport(() => import("eccrypto"));
|
|
374
382
|
var NodeCryptoAdapter = class {
|
|
375
383
|
async encryptWithPublicKey(data, publicKeyHex) {
|
|
376
384
|
try {
|
|
377
|
-
const
|
|
385
|
+
const eccrypto = await getEccrypto();
|
|
378
386
|
const publicKey = Buffer.from(publicKeyHex, "hex");
|
|
379
387
|
const message = Buffer.from(data, "utf8");
|
|
380
|
-
const encrypted = await
|
|
388
|
+
const encrypted = await eccrypto.encrypt(publicKey, message);
|
|
381
389
|
const result = Buffer.concat([
|
|
382
390
|
encrypted.iv,
|
|
383
391
|
encrypted.ephemPublicKey,
|
|
@@ -391,15 +399,12 @@ var NodeCryptoAdapter = class {
|
|
|
391
399
|
}
|
|
392
400
|
async decryptWithPrivateKey(encryptedData, privateKeyHex) {
|
|
393
401
|
try {
|
|
394
|
-
const
|
|
402
|
+
const eccrypto = await getEccrypto();
|
|
395
403
|
const privateKeyBuffer = processWalletPrivateKey(privateKeyHex);
|
|
396
404
|
const encryptedBuffer = Buffer.from(encryptedData, "hex");
|
|
397
405
|
const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
|
|
398
406
|
const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
|
|
399
|
-
const decrypted = await
|
|
400
|
-
privateKeyBuffer,
|
|
401
|
-
encryptedObj
|
|
402
|
-
);
|
|
407
|
+
const decrypted = await eccrypto.decrypt(privateKeyBuffer, encryptedObj);
|
|
403
408
|
return decrypted.toString("utf8");
|
|
404
409
|
} catch (error) {
|
|
405
410
|
throw new Error(`Decryption failed: ${error}`);
|
|
@@ -407,9 +412,9 @@ var NodeCryptoAdapter = class {
|
|
|
407
412
|
}
|
|
408
413
|
async generateKeyPair() {
|
|
409
414
|
try {
|
|
410
|
-
const
|
|
411
|
-
const privateKey =
|
|
412
|
-
const publicKey =
|
|
415
|
+
const eccrypto = await getEccrypto();
|
|
416
|
+
const privateKey = eccrypto.generatePrivate();
|
|
417
|
+
const publicKey = eccrypto.getPublicCompressed(privateKey);
|
|
413
418
|
return {
|
|
414
419
|
privateKey: privateKey.toString("hex"),
|
|
415
420
|
publicKey: publicKey.toString("hex")
|
|
@@ -420,9 +425,9 @@ var NodeCryptoAdapter = class {
|
|
|
420
425
|
}
|
|
421
426
|
async encryptWithWalletPublicKey(data, publicKey) {
|
|
422
427
|
try {
|
|
423
|
-
const
|
|
428
|
+
const eccrypto = await getEccrypto();
|
|
424
429
|
const uncompressedKey = processWalletPublicKey(publicKey);
|
|
425
|
-
const encrypted = await
|
|
430
|
+
const encrypted = await eccrypto.encrypt(
|
|
426
431
|
uncompressedKey,
|
|
427
432
|
Buffer.from(data)
|
|
428
433
|
);
|
|
@@ -439,12 +444,12 @@ var NodeCryptoAdapter = class {
|
|
|
439
444
|
}
|
|
440
445
|
async decryptWithWalletPrivateKey(encryptedData, privateKey) {
|
|
441
446
|
try {
|
|
442
|
-
const
|
|
447
|
+
const eccrypto = await getEccrypto();
|
|
443
448
|
const privateKeyBuffer = processWalletPrivateKey(privateKey);
|
|
444
449
|
const encryptedBuffer = Buffer.from(encryptedData, "hex");
|
|
445
450
|
const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
|
|
446
451
|
const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
|
|
447
|
-
const decryptedBuffer = await
|
|
452
|
+
const decryptedBuffer = await eccrypto.decrypt(
|
|
448
453
|
privateKeyBuffer,
|
|
449
454
|
encryptedObj
|
|
450
455
|
);
|
|
@@ -455,10 +460,11 @@ var NodeCryptoAdapter = class {
|
|
|
455
460
|
}
|
|
456
461
|
async encryptWithPassword(data, password) {
|
|
457
462
|
try {
|
|
458
|
-
const
|
|
463
|
+
const openpgp = await getOpenPGP2();
|
|
464
|
+
const message = await openpgp.createMessage({
|
|
459
465
|
binary: data
|
|
460
466
|
});
|
|
461
|
-
const encrypted = await
|
|
467
|
+
const encrypted = await openpgp.encrypt({
|
|
462
468
|
message,
|
|
463
469
|
passwords: [password],
|
|
464
470
|
format: "binary"
|
|
@@ -478,10 +484,11 @@ var NodeCryptoAdapter = class {
|
|
|
478
484
|
}
|
|
479
485
|
async decryptWithPassword(encryptedData, password) {
|
|
480
486
|
try {
|
|
481
|
-
const
|
|
487
|
+
const openpgp = await getOpenPGP2();
|
|
488
|
+
const message = await openpgp.readMessage({
|
|
482
489
|
binaryMessage: encryptedData
|
|
483
490
|
});
|
|
484
|
-
const { data: decrypted } = await
|
|
491
|
+
const { data: decrypted } = await openpgp.decrypt({
|
|
485
492
|
message,
|
|
486
493
|
passwords: [password],
|
|
487
494
|
format: "binary"
|
|
@@ -495,12 +502,13 @@ var NodeCryptoAdapter = class {
|
|
|
495
502
|
var NodePGPAdapter = class {
|
|
496
503
|
async encrypt(data, publicKeyArmored) {
|
|
497
504
|
try {
|
|
498
|
-
const
|
|
499
|
-
const
|
|
500
|
-
|
|
505
|
+
const openpgp = await getOpenPGP2();
|
|
506
|
+
const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
|
|
507
|
+
const encrypted = await openpgp.encrypt({
|
|
508
|
+
message: await openpgp.createMessage({ text: data }),
|
|
501
509
|
encryptionKeys: publicKey,
|
|
502
510
|
config: {
|
|
503
|
-
preferredCompressionAlgorithm:
|
|
511
|
+
preferredCompressionAlgorithm: openpgp.enums.compression.zlib
|
|
504
512
|
}
|
|
505
513
|
});
|
|
506
514
|
return encrypted;
|
|
@@ -510,13 +518,14 @@ var NodePGPAdapter = class {
|
|
|
510
518
|
}
|
|
511
519
|
async decrypt(encryptedData, privateKeyArmored) {
|
|
512
520
|
try {
|
|
513
|
-
const
|
|
521
|
+
const openpgp = await getOpenPGP2();
|
|
522
|
+
const privateKey = await openpgp.readPrivateKey({
|
|
514
523
|
armoredKey: privateKeyArmored
|
|
515
524
|
});
|
|
516
|
-
const message = await
|
|
525
|
+
const message = await openpgp.readMessage({
|
|
517
526
|
armoredMessage: encryptedData
|
|
518
527
|
});
|
|
519
|
-
const { data: decrypted } = await
|
|
528
|
+
const { data: decrypted } = await openpgp.decrypt({
|
|
520
529
|
message,
|
|
521
530
|
decryptionKeys: privateKey
|
|
522
531
|
});
|
|
@@ -527,8 +536,9 @@ var NodePGPAdapter = class {
|
|
|
527
536
|
}
|
|
528
537
|
async generateKeyPair(options) {
|
|
529
538
|
try {
|
|
539
|
+
const openpgp = await getOpenPGP2();
|
|
530
540
|
const keyGenParams = getPGPKeyGenParams(options);
|
|
531
|
-
const { privateKey, publicKey } = await
|
|
541
|
+
const { privateKey, publicKey } = await openpgp.generateKey(keyGenParams);
|
|
532
542
|
return { publicKey, privateKey };
|
|
533
543
|
} catch (error) {
|
|
534
544
|
throw wrapCryptoError("PGP key generation", error);
|