@provablehq/aleo-wallet-adaptor-fox 0.1.1-alpha.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/dist/index.mjs ADDED
@@ -0,0 +1,314 @@
1
+ // src/FoxWalletAdapter.ts
2
+ import {
3
+ Network
4
+ } from "@provablehq/aleo-types";
5
+ import {
6
+ WalletDecryptPermission,
7
+ WalletReadyState
8
+ } from "@provablehq/aleo-wallet-standard";
9
+ import {
10
+ BaseAleoWalletAdapter,
11
+ MethodNotImplementedError,
12
+ WalletConnectionError,
13
+ WalletDecryptionError,
14
+ WalletDecryptionNotAllowedError,
15
+ WalletDisconnectionError,
16
+ WalletError,
17
+ WalletNotConnectedError,
18
+ WalletSignMessageError,
19
+ WalletTransactionError
20
+ } from "@provablehq/aleo-wallet-adaptor-core";
21
+ import {
22
+ LEO_NETWORK_MAP
23
+ } from "@provablehq/aleo-wallet-adaptor-leo";
24
+ var FoxWalletAdapter = class extends BaseAleoWalletAdapter {
25
+ /**
26
+ * Create a new Fox wallet adapter
27
+ * @param config Adapter configuration
28
+ */
29
+ constructor(config) {
30
+ super();
31
+ /**
32
+ * The wallet name
33
+ */
34
+ this.name = "Fox Wallet";
35
+ /**
36
+ * The wallet URL
37
+ */
38
+ this.url = "https://foxwallet.com/download";
39
+ /**
40
+ * The wallet icon (base64-encoded SVG)
41
+ */
42
+ this.icon = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iOTAwIiBoZWlnaHQ9IjkwMCIgdmlld0JveD0iMCAwIDkwMCA5MDAiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSI5MDAiIGhlaWdodD0iOTAwIiByeD0iNDUwIiBmaWxsPSJibGFjayIvPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTU3Ny4yND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network
45
+ */
46
+ this.network = Network.MAINNET;
47
+ /**
48
+ * The wallet's decrypt permission
49
+ */
50
+ this.decryptPermission = WalletDecryptPermission.NoDecrypt;
51
+ /**
52
+ * Public key
53
+ */
54
+ this._publicKey = "";
55
+ this._readyState = typeof window === "undefined" || typeof document === "undefined" ? WalletReadyState.UNSUPPORTED : WalletReadyState.NOT_DETECTED;
56
+ console.debug("FoxWalletAdapter constructor", config);
57
+ this.network = Network.MAINNET;
58
+ this._checkAvailability();
59
+ this._foxWallet = this._window?.foxwallet?.aleo;
60
+ if (config?.isMobile) {
61
+ this.url = `https://app.leo.app/browser?url=${config.mobileWebviewUrl}`;
62
+ }
63
+ }
64
+ /**
65
+ * Check if Fox wallet is available
66
+ */
67
+ _checkAvailability() {
68
+ if (typeof window === "undefined" || typeof document === "undefined") {
69
+ this.readyState = WalletReadyState.UNSUPPORTED;
70
+ return;
71
+ }
72
+ this._window = window;
73
+ if (this._window.foxwallet?.aleo) {
74
+ this.readyState = WalletReadyState.INSTALLED;
75
+ } else {
76
+ const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
77
+ if (isMobile) {
78
+ this.readyState = WalletReadyState.LOADABLE;
79
+ }
80
+ }
81
+ }
82
+ /**
83
+ * Connect to Fox wallet
84
+ * @returns The connected account
85
+ */
86
+ async connect(network, decryptPermission, programs) {
87
+ try {
88
+ if (this.readyState !== WalletReadyState.INSTALLED) {
89
+ throw new WalletConnectionError("Fox Wallet is not available");
90
+ }
91
+ if (network !== Network.MAINNET) {
92
+ throw new WalletConnectionError("Fox Wallet only support mainnet");
93
+ }
94
+ try {
95
+ await this._foxWallet?.connect(decryptPermission, LEO_NETWORK_MAP[network], programs);
96
+ this.network = network;
97
+ } catch (error) {
98
+ if (error instanceof Object && "name" in error && (error.name === "InvalidParamsAleoWalletError" || error.name !== "NotGrantedAleoWalletError")) {
99
+ throw new WalletConnectionError(
100
+ "Connection failed: Likely due to a difference in configured network and the selected wallet network. Configured network: " + network
101
+ );
102
+ }
103
+ throw new WalletConnectionError(
104
+ error instanceof Error ? error.message : "Connection failed"
105
+ );
106
+ }
107
+ this._publicKey = this._foxWallet?.publicKey || "";
108
+ if (!this._publicKey) {
109
+ throw new WalletConnectionError("No address returned from wallet");
110
+ }
111
+ const account = {
112
+ address: this._publicKey
113
+ };
114
+ this.account = account;
115
+ this.decryptPermission = decryptPermission;
116
+ this.emit("connect", account);
117
+ return account;
118
+ } catch (err) {
119
+ this.emit("error", err instanceof Error ? err : new Error(String(err)));
120
+ throw new WalletConnectionError(err instanceof Error ? err.message : "Connection failed");
121
+ }
122
+ }
123
+ /**
124
+ * Disconnect from Fox wallet
125
+ */
126
+ async disconnect() {
127
+ try {
128
+ await this._foxWallet?.disconnect();
129
+ this._publicKey = "";
130
+ this.account = void 0;
131
+ this.emit("disconnect");
132
+ } catch (err) {
133
+ this.emit("error", err instanceof Error ? err : new Error(String(err)));
134
+ throw new WalletDisconnectionError(
135
+ err instanceof Error ? err.message : "Disconnection failed"
136
+ );
137
+ }
138
+ }
139
+ /**
140
+ * Sign a transaction with Fox wallet
141
+ * @param options Transaction options
142
+ * @returns The signed transaction
143
+ */
144
+ async signMessage(message) {
145
+ if (!this._publicKey || !this.account) {
146
+ throw new WalletNotConnectedError();
147
+ }
148
+ try {
149
+ const signature = await this._foxWallet?.signMessage(message);
150
+ if (!signature) {
151
+ throw new WalletSignMessageError("Failed to sign message");
152
+ }
153
+ return signature.signature;
154
+ } catch (error) {
155
+ throw new WalletSignMessageError(
156
+ error instanceof Error ? error.message : "Failed to sign message"
157
+ );
158
+ }
159
+ }
160
+ async decrypt(cipherText, tpk, programId, functionName, index) {
161
+ if (!this._foxWallet || !this._publicKey) {
162
+ throw new WalletNotConnectedError();
163
+ }
164
+ switch (this.decryptPermission) {
165
+ case WalletDecryptPermission.NoDecrypt:
166
+ throw new WalletDecryptionNotAllowedError();
167
+ case WalletDecryptPermission.UponRequest:
168
+ case WalletDecryptPermission.AutoDecrypt:
169
+ case WalletDecryptPermission.OnChainHistory: {
170
+ try {
171
+ const result = await this._foxWallet.decrypt(
172
+ cipherText,
173
+ tpk,
174
+ programId,
175
+ functionName,
176
+ index
177
+ );
178
+ return result.text;
179
+ } catch (error) {
180
+ throw new WalletDecryptionError(
181
+ error instanceof Error ? error.message : "Failed to decrypt"
182
+ );
183
+ }
184
+ }
185
+ default:
186
+ throw new WalletDecryptionError();
187
+ }
188
+ }
189
+ /**
190
+ * Execute a transaction with Fox wallet
191
+ * @param options Transaction options
192
+ * @returns The executed temporary transaction ID
193
+ */
194
+ async executeTransaction(options) {
195
+ if (!this._publicKey || !this.account) {
196
+ throw new WalletNotConnectedError();
197
+ }
198
+ try {
199
+ const requestData = {
200
+ address: this._publicKey,
201
+ chainId: LEO_NETWORK_MAP[this.network],
202
+ fee: options.fee ? options.fee : 1e-3,
203
+ feePrivate: options.privateFee ?? false,
204
+ transitions: [
205
+ {
206
+ program: options.program,
207
+ functionName: options.function,
208
+ inputs: options.inputs
209
+ }
210
+ ]
211
+ };
212
+ const result = await this._foxWallet?.requestTransaction(requestData);
213
+ if (!result?.transactionId) {
214
+ throw new WalletTransactionError("Could not create transaction");
215
+ }
216
+ return {
217
+ transactionId: result.transactionId
218
+ };
219
+ } catch (error) {
220
+ console.error("Fox Wallet executeTransaction error", error);
221
+ if (error instanceof WalletError) {
222
+ throw error;
223
+ }
224
+ throw new WalletTransactionError(
225
+ error instanceof Error ? error.message : "Failed to execute transaction"
226
+ );
227
+ }
228
+ }
229
+ /**
230
+ * Get transaction status
231
+ * @param transactionId The transaction ID
232
+ * @returns The transaction status
233
+ */
234
+ async transactionStatus(transactionId) {
235
+ if (!this._publicKey || !this.account) {
236
+ throw new WalletNotConnectedError();
237
+ }
238
+ try {
239
+ const result = await this._foxWallet?.transactionStatus(transactionId);
240
+ if (!result?.status) {
241
+ throw new WalletTransactionError("Could not get transaction status");
242
+ }
243
+ return {
244
+ status: result.status
245
+ };
246
+ } catch (error) {
247
+ throw new WalletTransactionError(
248
+ error instanceof Error ? error.message : "Failed to get transaction status"
249
+ );
250
+ }
251
+ }
252
+ /**
253
+ * Request records from Fox wallet
254
+ * @param program The program to request records from
255
+ * @param includePlaintext Whether to include plaintext on each record
256
+ * @returns The records
257
+ */
258
+ async requestRecords(program, includePlaintext) {
259
+ if (!this._publicKey || !this.account) {
260
+ throw new WalletNotConnectedError();
261
+ }
262
+ try {
263
+ const result = includePlaintext ? await this._foxWallet?.requestRecordPlaintexts(program) : await this._foxWallet?.requestRecords(program);
264
+ return result?.records || [];
265
+ } catch (error) {
266
+ throw new WalletError(error instanceof Error ? error.message : "Failed to request records");
267
+ }
268
+ }
269
+ /**
270
+ * Switch the network
271
+ * @param network The network to switch to
272
+ */
273
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
274
+ async switchNetwork(_network) {
275
+ console.error("Fox Wallet does not support switching networks");
276
+ throw new MethodNotImplementedError("switchNetwork");
277
+ }
278
+ /**
279
+ * Execute a deployment
280
+ * @param deployment The deployment to execute
281
+ * @returns The executed transaction ID
282
+ */
283
+ async executeDeployment(deployment) {
284
+ try {
285
+ if (!this._foxWallet || !this._publicKey)
286
+ throw new WalletNotConnectedError();
287
+ try {
288
+ const result = await this._foxWallet?.requestDeploy({
289
+ address: this._publicKey,
290
+ chainId: LEO_NETWORK_MAP[this.network],
291
+ program: deployment.program,
292
+ fee: deployment.fee,
293
+ feePrivate: deployment.feePrivate
294
+ });
295
+ if (!result?.transactionId) {
296
+ throw new WalletTransactionError("Could not create deployment");
297
+ }
298
+ return {
299
+ transactionId: result.transactionId
300
+ };
301
+ } catch (error) {
302
+ throw new WalletTransactionError(
303
+ error instanceof Error ? error.message : "Failed to execute deployment"
304
+ );
305
+ }
306
+ } catch (error) {
307
+ this.emit("error", error instanceof Error ? error : new Error(String(error)));
308
+ throw error;
309
+ }
310
+ }
311
+ };
312
+ export {
313
+ FoxWalletAdapter
314
+ };
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@provablehq/aleo-wallet-adaptor-fox",
3
+ "version": "0.1.1-alpha.0",
4
+ "description": "Fox wallet adapter for Aleo",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "license": "GPL-3.0-or-later",
9
+ "files": [
10
+ "dist",
11
+ "src"
12
+ ],
13
+ "dependencies": {
14
+ "@provablehq/aleo-types": "0.1.1-alpha.0",
15
+ "@provablehq/aleo-wallet-adaptor-core": "0.1.1-alpha.0",
16
+ "@provablehq/aleo-wallet-adaptor-leo": "0.1.1-alpha.0",
17
+ "@provablehq/aleo-wallet-standard": "0.1.1-alpha.0"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/ProvableHQ/aleo-dev-toolkit.git",
22
+ "directory": "packages/aleo-wallet-adaptor/wallets/fox"
23
+ },
24
+ "homepage": "https://provable.com/",
25
+ "keywords": [
26
+ "aleo",
27
+ "wallet",
28
+ "adapter",
29
+ "fox"
30
+ ],
31
+ "author": "Provable Labs",
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "devDependencies": {
36
+ "rimraf": "^5.0.5",
37
+ "tsup": "^7.0.0",
38
+ "typescript": "^5.0.0"
39
+ },
40
+ "scripts": {
41
+ "build": "tsup",
42
+ "clean": "rimraf dist",
43
+ "dev": "tsup --watch"
44
+ }
45
+ }