@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/LICENSE +674 -0
- package/README.md +31 -0
- package/dist/index.d.mts +109 -0
- package/dist/index.d.ts +109 -0
- package/dist/index.js +323 -0
- package/dist/index.mjs +314 -0
- package/package.json +45 -0
- package/src/FoxWalletAdapter.ts +398 -0
- package/src/index.ts +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# @provablehq/aleo-wallet-adaptor-fox
|
|
2
|
+
|
|
3
|
+
Adapter that exposes the Fox wallet through the Aleo wallet adaptor interfaces.
|
|
4
|
+
|
|
5
|
+
## When to use it
|
|
6
|
+
|
|
7
|
+
- Provide Fox wallet connectivity in React (or headless) projects built on the adaptor core.
|
|
8
|
+
- Offer Fox as an option in the modal UI alongside other supported wallets.
|
|
9
|
+
- Prototype Fox-specific flows while keeping the rest of the integration unchanged.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm add @provablehq/aleo-wallet-adaptor-fox
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { FoxWalletAdapter } from '@provablehq/aleo-wallet-adaptor-fox';
|
|
21
|
+
|
|
22
|
+
const wallets = [new FoxWalletAdapter()];
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Related packages
|
|
26
|
+
|
|
27
|
+
- `@provablehq/aleo-wallet-adaptor-core` – shared adapter base.
|
|
28
|
+
- `@provablehq/aleo-wallet-adaptor-react` – React provider that consumes this adapter.
|
|
29
|
+
- `@provablehq/aleo-wallet-adaptor-react-ui` – wallet picker UI that automatically lists Fox when available.
|
|
30
|
+
|
|
31
|
+
Live demo: https://aleo-dev-toolkit-react-app.vercel.app/
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Network, Account, TransactionOptions, TransactionStatusResponse } from '@provablehq/aleo-types';
|
|
2
|
+
import { WalletName, WalletDecryptPermission, WalletReadyState, AleoDeployment } from '@provablehq/aleo-wallet-standard';
|
|
3
|
+
import { BaseAleoWalletAdapter } from '@provablehq/aleo-wallet-adaptor-core';
|
|
4
|
+
import { LeoWallet, LeoWalletAdapterConfig } from '@provablehq/aleo-wallet-adaptor-leo';
|
|
5
|
+
|
|
6
|
+
interface FoxWindow extends Window {
|
|
7
|
+
foxwallet?: {
|
|
8
|
+
aleo?: LeoWallet;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Fox wallet adapter
|
|
13
|
+
*/
|
|
14
|
+
declare class FoxWalletAdapter extends BaseAleoWalletAdapter {
|
|
15
|
+
/**
|
|
16
|
+
* The wallet name
|
|
17
|
+
*/
|
|
18
|
+
readonly name: WalletName<"Fox Wallet">;
|
|
19
|
+
/**
|
|
20
|
+
* The wallet URL
|
|
21
|
+
*/
|
|
22
|
+
url: string;
|
|
23
|
+
/**
|
|
24
|
+
* The wallet icon (base64-encoded SVG)
|
|
25
|
+
*/
|
|
26
|
+
readonly icon = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iOTAwIiBoZWlnaHQ9IjkwMCIgdmlld0JveD0iMCAwIDkwMCA5MDAiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSI5MDAiIGhlaWdodD0iOTAwIiByeD0iNDUwIiBmaWxsPSJibGFjayIvPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTU3Ny4yNDkgMjE1Ljk3NUM1MzkuOTU2IDE5Ni4yMzIgNTExLjY0NiAxNjEuNTQ5IDUwMC40NjggMTE5Ljg2OEM0OTcuMDIxIDEzMi42MTMg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
|
|
35
|
+
/**
|
|
36
|
+
* The wallet's decrypt permission
|
|
37
|
+
*/
|
|
38
|
+
decryptPermission: WalletDecryptPermission;
|
|
39
|
+
/**
|
|
40
|
+
* Public key
|
|
41
|
+
*/
|
|
42
|
+
private _publicKey;
|
|
43
|
+
_readyState: WalletReadyState;
|
|
44
|
+
/**
|
|
45
|
+
* Fox wallet instance
|
|
46
|
+
*/
|
|
47
|
+
private _foxWallet;
|
|
48
|
+
/**
|
|
49
|
+
* Create a new Fox wallet adapter
|
|
50
|
+
* @param config Adapter configuration
|
|
51
|
+
*/
|
|
52
|
+
constructor(config?: LeoWalletAdapterConfig);
|
|
53
|
+
/**
|
|
54
|
+
* Check if Fox wallet is available
|
|
55
|
+
*/
|
|
56
|
+
private _checkAvailability;
|
|
57
|
+
/**
|
|
58
|
+
* Connect to Fox wallet
|
|
59
|
+
* @returns The connected account
|
|
60
|
+
*/
|
|
61
|
+
connect(network: Network, decryptPermission: WalletDecryptPermission, programs?: string[]): Promise<Account>;
|
|
62
|
+
/**
|
|
63
|
+
* Disconnect from Fox wallet
|
|
64
|
+
*/
|
|
65
|
+
disconnect(): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Sign a transaction with Fox wallet
|
|
68
|
+
* @param options Transaction options
|
|
69
|
+
* @returns The signed transaction
|
|
70
|
+
*/
|
|
71
|
+
signMessage(message: Uint8Array): Promise<Uint8Array>;
|
|
72
|
+
decrypt(cipherText: string, tpk?: string, programId?: string, functionName?: string, index?: number): Promise<string>;
|
|
73
|
+
/**
|
|
74
|
+
* Execute a transaction with Fox wallet
|
|
75
|
+
* @param options Transaction options
|
|
76
|
+
* @returns The executed temporary transaction ID
|
|
77
|
+
*/
|
|
78
|
+
executeTransaction(options: TransactionOptions): Promise<{
|
|
79
|
+
transactionId: string;
|
|
80
|
+
}>;
|
|
81
|
+
/**
|
|
82
|
+
* Get transaction status
|
|
83
|
+
* @param transactionId The transaction ID
|
|
84
|
+
* @returns The transaction status
|
|
85
|
+
*/
|
|
86
|
+
transactionStatus(transactionId: string): Promise<TransactionStatusResponse>;
|
|
87
|
+
/**
|
|
88
|
+
* Request records from Fox wallet
|
|
89
|
+
* @param program The program to request records from
|
|
90
|
+
* @param includePlaintext Whether to include plaintext on each record
|
|
91
|
+
* @returns The records
|
|
92
|
+
*/
|
|
93
|
+
requestRecords(program: string, includePlaintext: boolean): Promise<unknown[]>;
|
|
94
|
+
/**
|
|
95
|
+
* Switch the network
|
|
96
|
+
* @param network The network to switch to
|
|
97
|
+
*/
|
|
98
|
+
switchNetwork(_network: Network): Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* Execute a deployment
|
|
101
|
+
* @param deployment The deployment to execute
|
|
102
|
+
* @returns The executed transaction ID
|
|
103
|
+
*/
|
|
104
|
+
executeDeployment(deployment: AleoDeployment): Promise<{
|
|
105
|
+
transactionId: string;
|
|
106
|
+
}>;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { FoxWalletAdapter, type FoxWindow };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Network, Account, TransactionOptions, TransactionStatusResponse } from '@provablehq/aleo-types';
|
|
2
|
+
import { WalletName, WalletDecryptPermission, WalletReadyState, AleoDeployment } from '@provablehq/aleo-wallet-standard';
|
|
3
|
+
import { BaseAleoWalletAdapter } from '@provablehq/aleo-wallet-adaptor-core';
|
|
4
|
+
import { LeoWallet, LeoWalletAdapterConfig } from '@provablehq/aleo-wallet-adaptor-leo';
|
|
5
|
+
|
|
6
|
+
interface FoxWindow extends Window {
|
|
7
|
+
foxwallet?: {
|
|
8
|
+
aleo?: LeoWallet;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Fox wallet adapter
|
|
13
|
+
*/
|
|
14
|
+
declare class FoxWalletAdapter extends BaseAleoWalletAdapter {
|
|
15
|
+
/**
|
|
16
|
+
* The wallet name
|
|
17
|
+
*/
|
|
18
|
+
readonly name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jA2OCA3NDguNzQ0IDIwOS42MzkgNDYxLjM2MiAzOTYuODM5IDQxNi4yMzRMMzk2LjczNSA0MTUuNzExQzQ0Ni42NjkgMzk5LjUxOSA0NzAuMDY5IDM2Ny4wMzEgNDc0LjE0MyAzMjQuODI3QzQwMi4wNjMgMzgzLjIyMyAyODguMTk2IDMxMC44MjkgMzExLjgwNSAyMjAuMTU0QzQxLjI0MjUgMzUzLjM0NiAxNDEuNzM3IDc4NS40MTEgNDQ4LjQ0NSA3ODAuMDgzQzU4Mi4wNTUgNzgwLjA4MyA2OTUuMDg1IDY5MS43MDYgNzMyLjE3IDU3MC4yMTRDNzc2LjQ2MyA0MjguNTYxIDcwNC44IDI3Ny42MDkgNTc3LjI0OSAyMTUuOTc1WiIgZmlsbD0iIzEyRkU3NCIvPgo8L3N2Zz4K";
|
|
27
|
+
/**
|
|
28
|
+
* The window object
|
|
29
|
+
*/
|
|
30
|
+
private _window;
|
|
31
|
+
/**
|
|
32
|
+
* Current network
|
|
33
|
+
*/
|
|
34
|
+
network: Network;
|
|
35
|
+
/**
|
|
36
|
+
* The wallet's decrypt permission
|
|
37
|
+
*/
|
|
38
|
+
decryptPermission: WalletDecryptPermission;
|
|
39
|
+
/**
|
|
40
|
+
* Public key
|
|
41
|
+
*/
|
|
42
|
+
private _publicKey;
|
|
43
|
+
_readyState: WalletReadyState;
|
|
44
|
+
/**
|
|
45
|
+
* Fox wallet instance
|
|
46
|
+
*/
|
|
47
|
+
private _foxWallet;
|
|
48
|
+
/**
|
|
49
|
+
* Create a new Fox wallet adapter
|
|
50
|
+
* @param config Adapter configuration
|
|
51
|
+
*/
|
|
52
|
+
constructor(config?: LeoWalletAdapterConfig);
|
|
53
|
+
/**
|
|
54
|
+
* Check if Fox wallet is available
|
|
55
|
+
*/
|
|
56
|
+
private _checkAvailability;
|
|
57
|
+
/**
|
|
58
|
+
* Connect to Fox wallet
|
|
59
|
+
* @returns The connected account
|
|
60
|
+
*/
|
|
61
|
+
connect(network: Network, decryptPermission: WalletDecryptPermission, programs?: string[]): Promise<Account>;
|
|
62
|
+
/**
|
|
63
|
+
* Disconnect from Fox wallet
|
|
64
|
+
*/
|
|
65
|
+
disconnect(): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Sign a transaction with Fox wallet
|
|
68
|
+
* @param options Transaction options
|
|
69
|
+
* @returns The signed transaction
|
|
70
|
+
*/
|
|
71
|
+
signMessage(message: Uint8Array): Promise<Uint8Array>;
|
|
72
|
+
decrypt(cipherText: string, tpk?: string, programId?: string, functionName?: string, index?: number): Promise<string>;
|
|
73
|
+
/**
|
|
74
|
+
* Execute a transaction with Fox wallet
|
|
75
|
+
* @param options Transaction options
|
|
76
|
+
* @returns The executed temporary transaction ID
|
|
77
|
+
*/
|
|
78
|
+
executeTransaction(options: TransactionOptions): Promise<{
|
|
79
|
+
transactionId: string;
|
|
80
|
+
}>;
|
|
81
|
+
/**
|
|
82
|
+
* Get transaction status
|
|
83
|
+
* @param transactionId The transaction ID
|
|
84
|
+
* @returns The transaction status
|
|
85
|
+
*/
|
|
86
|
+
transactionStatus(transactionId: string): Promise<TransactionStatusResponse>;
|
|
87
|
+
/**
|
|
88
|
+
* Request records from Fox wallet
|
|
89
|
+
* @param program The program to request records from
|
|
90
|
+
* @param includePlaintext Whether to include plaintext on each record
|
|
91
|
+
* @returns The records
|
|
92
|
+
*/
|
|
93
|
+
requestRecords(program: string, includePlaintext: boolean): Promise<unknown[]>;
|
|
94
|
+
/**
|
|
95
|
+
* Switch the network
|
|
96
|
+
* @param network The network to switch to
|
|
97
|
+
*/
|
|
98
|
+
switchNetwork(_network: Network): Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* Execute a deployment
|
|
101
|
+
* @param deployment The deployment to execute
|
|
102
|
+
* @returns The executed transaction ID
|
|
103
|
+
*/
|
|
104
|
+
executeDeployment(deployment: AleoDeployment): Promise<{
|
|
105
|
+
transactionId: string;
|
|
106
|
+
}>;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { FoxWalletAdapter, type FoxWindow };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
FoxWalletAdapter: () => FoxWalletAdapter
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(src_exports);
|
|
26
|
+
|
|
27
|
+
// src/FoxWalletAdapter.ts
|
|
28
|
+
var import_aleo_types = require("@provablehq/aleo-types");
|
|
29
|
+
var import_aleo_wallet_standard = require("@provablehq/aleo-wallet-standard");
|
|
30
|
+
var import_aleo_wallet_adaptor_core = require("@provablehq/aleo-wallet-adaptor-core");
|
|
31
|
+
var import_aleo_wallet_adaptor_leo = require("@provablehq/aleo-wallet-adaptor-leo");
|
|
32
|
+
var FoxWalletAdapter = class extends import_aleo_wallet_adaptor_core.BaseAleoWalletAdapter {
|
|
33
|
+
/**
|
|
34
|
+
* Create a new Fox wallet adapter
|
|
35
|
+
* @param config Adapter configuration
|
|
36
|
+
*/
|
|
37
|
+
constructor(config) {
|
|
38
|
+
super();
|
|
39
|
+
/**
|
|
40
|
+
* The wallet name
|
|
41
|
+
*/
|
|
42
|
+
this.name = "Fox Wallet";
|
|
43
|
+
/**
|
|
44
|
+
* The wallet URL
|
|
45
|
+
*/
|
|
46
|
+
this.url = "https://foxwallet.com/download";
|
|
47
|
+
/**
|
|
48
|
+
* The wallet icon (base64-encoded SVG)
|
|
49
|
+
*/
|
|
50
|
+
this.icon = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iOTAwIiBoZWlnaHQ9IjkwMCIgdmlld0JveD0iMCAwIDkwMCA5MDAiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSI5MDAiIGhlaWdodD0iOTAwIiByeD0iNDUwIiBmaWxsPSJibGFjayIvPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTU3Ny4yNDkgMjE1Ljk3NUM1MzkuOTU2IDE5Ni4yMzIgNTExLjY0NiAxNjEuNTQ5IDUwMC40NjggMTE5Ljg2OEM0OTcuMDIxIDEzMi42MTMgNDk1LjI0NSAxNDUuOTg0IDQ5NS4yNDUgMTU5Ljc3NEM0OTUuMjQ1IDE3MC41MzMgNDk2LjM5NCAxODAuOTggNDk4LjQ4MyAxOTEuMTEzQzQ5OC40ODMgMTkxLjExMyA0OTguNDgzIDE5MS4xMTMgNDk4LjQ4MyAxOTEuMjE3QzQ5OC40ODMgMTkxLjMyMiA0OTguNTg4IDE5MS41MzEgNDk4LjU4OCAxOTEuNjM1QzUwMS40MDggMjA1LjIxNiA1MDYuMDA1IDIxOC4wNjUgNTEyLjE2OCAyMjkuOTc0QzQ5OS4wMDYgMjIwLjI1OCA0ODcuMzA2IDIwOC42NjMgNDc3LjQ4NiAxOTUuNjA1QzQ2NC4zMjMgMjk3LjY2NyA1MDEuNDA4IDQwMy45MDcgNTY5LjIwNiA0NzMuODk4QzY1Ny42ODcgNTc2LjkgNTc2LjEgNzUxLjY2OSA0MzguMjA3IDc0Ny4wNzNDMjQzLjA2OCA3NDguNzQ0IDIwOS42MzkgNDYxLjM2MiAzOTYuODM5IDQxNi4yMzRMMzk2LjczNSA0MTUuNzExQzQ0Ni42NjkgMzk5LjUxOSA0NzAuMDY5IDM2Ny4wMzEgNDc0LjE0MyAzMjQuODI3QzQwMi4wNjMgMzgzLjIyMyAyODguMTk2IDMxMC44MjkgMzExLjgwNSAyMjAuMTU0QzQxLjI0MjUgMzUzLjM0NiAxNDEuNzM3IDc4NS40MTEgNDQ4LjQ0NSA3ODAuMDgzQzU4Mi4wNTUgNzgwLjA4MyA2OTUuMDg1IDY5MS43MDYgNzMyLjE3IDU3MC4yMTRDNzc2LjQ2MyA0MjguNTYxIDcwNC44IDI3Ny42MDkgNTc3LjI0OSAyMTUuOTc1WiIgZmlsbD0iIzEyRkU3NCIvPgo8L3N2Zz4K";
|
|
51
|
+
/**
|
|
52
|
+
* Current network
|
|
53
|
+
*/
|
|
54
|
+
this.network = import_aleo_types.Network.MAINNET;
|
|
55
|
+
/**
|
|
56
|
+
* The wallet's decrypt permission
|
|
57
|
+
*/
|
|
58
|
+
this.decryptPermission = import_aleo_wallet_standard.WalletDecryptPermission.NoDecrypt;
|
|
59
|
+
/**
|
|
60
|
+
* Public key
|
|
61
|
+
*/
|
|
62
|
+
this._publicKey = "";
|
|
63
|
+
this._readyState = typeof window === "undefined" || typeof document === "undefined" ? import_aleo_wallet_standard.WalletReadyState.UNSUPPORTED : import_aleo_wallet_standard.WalletReadyState.NOT_DETECTED;
|
|
64
|
+
console.debug("FoxWalletAdapter constructor", config);
|
|
65
|
+
this.network = import_aleo_types.Network.MAINNET;
|
|
66
|
+
this._checkAvailability();
|
|
67
|
+
this._foxWallet = this._window?.foxwallet?.aleo;
|
|
68
|
+
if (config?.isMobile) {
|
|
69
|
+
this.url = `https://app.leo.app/browser?url=${config.mobileWebviewUrl}`;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Check if Fox wallet is available
|
|
74
|
+
*/
|
|
75
|
+
_checkAvailability() {
|
|
76
|
+
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
77
|
+
this.readyState = import_aleo_wallet_standard.WalletReadyState.UNSUPPORTED;
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
this._window = window;
|
|
81
|
+
if (this._window.foxwallet?.aleo) {
|
|
82
|
+
this.readyState = import_aleo_wallet_standard.WalletReadyState.INSTALLED;
|
|
83
|
+
} else {
|
|
84
|
+
const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
|
|
85
|
+
if (isMobile) {
|
|
86
|
+
this.readyState = import_aleo_wallet_standard.WalletReadyState.LOADABLE;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Connect to Fox wallet
|
|
92
|
+
* @returns The connected account
|
|
93
|
+
*/
|
|
94
|
+
async connect(network, decryptPermission, programs) {
|
|
95
|
+
try {
|
|
96
|
+
if (this.readyState !== import_aleo_wallet_standard.WalletReadyState.INSTALLED) {
|
|
97
|
+
throw new import_aleo_wallet_adaptor_core.WalletConnectionError("Fox Wallet is not available");
|
|
98
|
+
}
|
|
99
|
+
if (network !== import_aleo_types.Network.MAINNET) {
|
|
100
|
+
throw new import_aleo_wallet_adaptor_core.WalletConnectionError("Fox Wallet only support mainnet");
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
await this._foxWallet?.connect(decryptPermission, import_aleo_wallet_adaptor_leo.LEO_NETWORK_MAP[network], programs);
|
|
104
|
+
this.network = network;
|
|
105
|
+
} catch (error) {
|
|
106
|
+
if (error instanceof Object && "name" in error && (error.name === "InvalidParamsAleoWalletError" || error.name !== "NotGrantedAleoWalletError")) {
|
|
107
|
+
throw new import_aleo_wallet_adaptor_core.WalletConnectionError(
|
|
108
|
+
"Connection failed: Likely due to a difference in configured network and the selected wallet network. Configured network: " + network
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
throw new import_aleo_wallet_adaptor_core.WalletConnectionError(
|
|
112
|
+
error instanceof Error ? error.message : "Connection failed"
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
this._publicKey = this._foxWallet?.publicKey || "";
|
|
116
|
+
if (!this._publicKey) {
|
|
117
|
+
throw new import_aleo_wallet_adaptor_core.WalletConnectionError("No address returned from wallet");
|
|
118
|
+
}
|
|
119
|
+
const account = {
|
|
120
|
+
address: this._publicKey
|
|
121
|
+
};
|
|
122
|
+
this.account = account;
|
|
123
|
+
this.decryptPermission = decryptPermission;
|
|
124
|
+
this.emit("connect", account);
|
|
125
|
+
return account;
|
|
126
|
+
} catch (err) {
|
|
127
|
+
this.emit("error", err instanceof Error ? err : new Error(String(err)));
|
|
128
|
+
throw new import_aleo_wallet_adaptor_core.WalletConnectionError(err instanceof Error ? err.message : "Connection failed");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Disconnect from Fox wallet
|
|
133
|
+
*/
|
|
134
|
+
async disconnect() {
|
|
135
|
+
try {
|
|
136
|
+
await this._foxWallet?.disconnect();
|
|
137
|
+
this._publicKey = "";
|
|
138
|
+
this.account = void 0;
|
|
139
|
+
this.emit("disconnect");
|
|
140
|
+
} catch (err) {
|
|
141
|
+
this.emit("error", err instanceof Error ? err : new Error(String(err)));
|
|
142
|
+
throw new import_aleo_wallet_adaptor_core.WalletDisconnectionError(
|
|
143
|
+
err instanceof Error ? err.message : "Disconnection failed"
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Sign a transaction with Fox wallet
|
|
149
|
+
* @param options Transaction options
|
|
150
|
+
* @returns The signed transaction
|
|
151
|
+
*/
|
|
152
|
+
async signMessage(message) {
|
|
153
|
+
if (!this._publicKey || !this.account) {
|
|
154
|
+
throw new import_aleo_wallet_adaptor_core.WalletNotConnectedError();
|
|
155
|
+
}
|
|
156
|
+
try {
|
|
157
|
+
const signature = await this._foxWallet?.signMessage(message);
|
|
158
|
+
if (!signature) {
|
|
159
|
+
throw new import_aleo_wallet_adaptor_core.WalletSignMessageError("Failed to sign message");
|
|
160
|
+
}
|
|
161
|
+
return signature.signature;
|
|
162
|
+
} catch (error) {
|
|
163
|
+
throw new import_aleo_wallet_adaptor_core.WalletSignMessageError(
|
|
164
|
+
error instanceof Error ? error.message : "Failed to sign message"
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
async decrypt(cipherText, tpk, programId, functionName, index) {
|
|
169
|
+
if (!this._foxWallet || !this._publicKey) {
|
|
170
|
+
throw new import_aleo_wallet_adaptor_core.WalletNotConnectedError();
|
|
171
|
+
}
|
|
172
|
+
switch (this.decryptPermission) {
|
|
173
|
+
case import_aleo_wallet_standard.WalletDecryptPermission.NoDecrypt:
|
|
174
|
+
throw new import_aleo_wallet_adaptor_core.WalletDecryptionNotAllowedError();
|
|
175
|
+
case import_aleo_wallet_standard.WalletDecryptPermission.UponRequest:
|
|
176
|
+
case import_aleo_wallet_standard.WalletDecryptPermission.AutoDecrypt:
|
|
177
|
+
case import_aleo_wallet_standard.WalletDecryptPermission.OnChainHistory: {
|
|
178
|
+
try {
|
|
179
|
+
const result = await this._foxWallet.decrypt(
|
|
180
|
+
cipherText,
|
|
181
|
+
tpk,
|
|
182
|
+
programId,
|
|
183
|
+
functionName,
|
|
184
|
+
index
|
|
185
|
+
);
|
|
186
|
+
return result.text;
|
|
187
|
+
} catch (error) {
|
|
188
|
+
throw new import_aleo_wallet_adaptor_core.WalletDecryptionError(
|
|
189
|
+
error instanceof Error ? error.message : "Failed to decrypt"
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
default:
|
|
194
|
+
throw new import_aleo_wallet_adaptor_core.WalletDecryptionError();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Execute a transaction with Fox wallet
|
|
199
|
+
* @param options Transaction options
|
|
200
|
+
* @returns The executed temporary transaction ID
|
|
201
|
+
*/
|
|
202
|
+
async executeTransaction(options) {
|
|
203
|
+
if (!this._publicKey || !this.account) {
|
|
204
|
+
throw new import_aleo_wallet_adaptor_core.WalletNotConnectedError();
|
|
205
|
+
}
|
|
206
|
+
try {
|
|
207
|
+
const requestData = {
|
|
208
|
+
address: this._publicKey,
|
|
209
|
+
chainId: import_aleo_wallet_adaptor_leo.LEO_NETWORK_MAP[this.network],
|
|
210
|
+
fee: options.fee ? options.fee : 1e-3,
|
|
211
|
+
feePrivate: options.privateFee ?? false,
|
|
212
|
+
transitions: [
|
|
213
|
+
{
|
|
214
|
+
program: options.program,
|
|
215
|
+
functionName: options.function,
|
|
216
|
+
inputs: options.inputs
|
|
217
|
+
}
|
|
218
|
+
]
|
|
219
|
+
};
|
|
220
|
+
const result = await this._foxWallet?.requestTransaction(requestData);
|
|
221
|
+
if (!result?.transactionId) {
|
|
222
|
+
throw new import_aleo_wallet_adaptor_core.WalletTransactionError("Could not create transaction");
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
transactionId: result.transactionId
|
|
226
|
+
};
|
|
227
|
+
} catch (error) {
|
|
228
|
+
console.error("Fox Wallet executeTransaction error", error);
|
|
229
|
+
if (error instanceof import_aleo_wallet_adaptor_core.WalletError) {
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
232
|
+
throw new import_aleo_wallet_adaptor_core.WalletTransactionError(
|
|
233
|
+
error instanceof Error ? error.message : "Failed to execute transaction"
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Get transaction status
|
|
239
|
+
* @param transactionId The transaction ID
|
|
240
|
+
* @returns The transaction status
|
|
241
|
+
*/
|
|
242
|
+
async transactionStatus(transactionId) {
|
|
243
|
+
if (!this._publicKey || !this.account) {
|
|
244
|
+
throw new import_aleo_wallet_adaptor_core.WalletNotConnectedError();
|
|
245
|
+
}
|
|
246
|
+
try {
|
|
247
|
+
const result = await this._foxWallet?.transactionStatus(transactionId);
|
|
248
|
+
if (!result?.status) {
|
|
249
|
+
throw new import_aleo_wallet_adaptor_core.WalletTransactionError("Could not get transaction status");
|
|
250
|
+
}
|
|
251
|
+
return {
|
|
252
|
+
status: result.status
|
|
253
|
+
};
|
|
254
|
+
} catch (error) {
|
|
255
|
+
throw new import_aleo_wallet_adaptor_core.WalletTransactionError(
|
|
256
|
+
error instanceof Error ? error.message : "Failed to get transaction status"
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Request records from Fox wallet
|
|
262
|
+
* @param program The program to request records from
|
|
263
|
+
* @param includePlaintext Whether to include plaintext on each record
|
|
264
|
+
* @returns The records
|
|
265
|
+
*/
|
|
266
|
+
async requestRecords(program, includePlaintext) {
|
|
267
|
+
if (!this._publicKey || !this.account) {
|
|
268
|
+
throw new import_aleo_wallet_adaptor_core.WalletNotConnectedError();
|
|
269
|
+
}
|
|
270
|
+
try {
|
|
271
|
+
const result = includePlaintext ? await this._foxWallet?.requestRecordPlaintexts(program) : await this._foxWallet?.requestRecords(program);
|
|
272
|
+
return result?.records || [];
|
|
273
|
+
} catch (error) {
|
|
274
|
+
throw new import_aleo_wallet_adaptor_core.WalletError(error instanceof Error ? error.message : "Failed to request records");
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Switch the network
|
|
279
|
+
* @param network The network to switch to
|
|
280
|
+
*/
|
|
281
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
282
|
+
async switchNetwork(_network) {
|
|
283
|
+
console.error("Fox Wallet does not support switching networks");
|
|
284
|
+
throw new import_aleo_wallet_adaptor_core.MethodNotImplementedError("switchNetwork");
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Execute a deployment
|
|
288
|
+
* @param deployment The deployment to execute
|
|
289
|
+
* @returns The executed transaction ID
|
|
290
|
+
*/
|
|
291
|
+
async executeDeployment(deployment) {
|
|
292
|
+
try {
|
|
293
|
+
if (!this._foxWallet || !this._publicKey)
|
|
294
|
+
throw new import_aleo_wallet_adaptor_core.WalletNotConnectedError();
|
|
295
|
+
try {
|
|
296
|
+
const result = await this._foxWallet?.requestDeploy({
|
|
297
|
+
address: this._publicKey,
|
|
298
|
+
chainId: import_aleo_wallet_adaptor_leo.LEO_NETWORK_MAP[this.network],
|
|
299
|
+
program: deployment.program,
|
|
300
|
+
fee: deployment.fee,
|
|
301
|
+
feePrivate: deployment.feePrivate
|
|
302
|
+
});
|
|
303
|
+
if (!result?.transactionId) {
|
|
304
|
+
throw new import_aleo_wallet_adaptor_core.WalletTransactionError("Could not create deployment");
|
|
305
|
+
}
|
|
306
|
+
return {
|
|
307
|
+
transactionId: result.transactionId
|
|
308
|
+
};
|
|
309
|
+
} catch (error) {
|
|
310
|
+
throw new import_aleo_wallet_adaptor_core.WalletTransactionError(
|
|
311
|
+
error instanceof Error ? error.message : "Failed to execute deployment"
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
} catch (error) {
|
|
315
|
+
this.emit("error", error instanceof Error ? error : new Error(String(error)));
|
|
316
|
+
throw error;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
321
|
+
0 && (module.exports = {
|
|
322
|
+
FoxWalletAdapter
|
|
323
|
+
});
|