@provablehq/veil-aleo-react-hooks 0.4.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 +21 -0
- package/README.md +106 -0
- package/dist/index.d.ts +117 -0
- package/dist/index.js +119 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Provable Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# @provablehq/veil-aleo-react-hooks
|
|
2
|
+
|
|
3
|
+
React bindings for the Veil Aleo SDK.
|
|
4
|
+
|
|
5
|
+
Provides a `VeilProvider` context provider and a `useVeilWallet` hook that wrap
|
|
6
|
+
the Provable/Aleo wallet adapters (Shield, Leo, Puzzle, Fox). Reach for it when
|
|
7
|
+
building a React app that connects a wallet and needs viem-shaped clients: the
|
|
8
|
+
hook hands back a `publicClient` for chain reads and, once a wallet connects, a
|
|
9
|
+
`walletClient` for transactions — no manual adapter bridging. `react` (>=18) is
|
|
10
|
+
a peer dependency.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
pnpm add @provablehq/veil-aleo-react-hooks @provablehq/veil-core react
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`react` is a peer dependency — the caller supplies it.
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
Wrap the app in `VeilProvider`, then call `useVeilWallet` in any component below
|
|
23
|
+
it. The provider configures all known Aleo wallets; the hook derives its network
|
|
24
|
+
from the provider unless the caller overrides it.
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
import { VeilProvider, useVeilWallet } from '@provablehq/veil-aleo-react-hooks'
|
|
28
|
+
|
|
29
|
+
function Root() {
|
|
30
|
+
return (
|
|
31
|
+
<VeilProvider network="mainnet">
|
|
32
|
+
<Wallet />
|
|
33
|
+
</VeilProvider>
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function Wallet() {
|
|
38
|
+
const {
|
|
39
|
+
publicClient, // read-only client, always available
|
|
40
|
+
walletClient, // write client, defined once connected
|
|
41
|
+
address, // connected address, or null
|
|
42
|
+
connected,
|
|
43
|
+
connecting,
|
|
44
|
+
connect, // connect(walletName?) selects + connects in one step
|
|
45
|
+
disconnect,
|
|
46
|
+
wallets, // available wallets with install status
|
|
47
|
+
selectWallet, // select a wallet by name before connecting
|
|
48
|
+
} = useVeilWallet()
|
|
49
|
+
|
|
50
|
+
if (!connected) {
|
|
51
|
+
return (
|
|
52
|
+
<button disabled={connecting} onClick={() => connect('Shield Wallet')}>
|
|
53
|
+
{connecting ? 'Connecting…' : 'Connect'}
|
|
54
|
+
</button>
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function send() {
|
|
59
|
+
// walletClient is defined here because `connected` is true.
|
|
60
|
+
const txId = await walletClient!.writeContract({
|
|
61
|
+
program: 'credits.aleo',
|
|
62
|
+
function: 'transfer_public',
|
|
63
|
+
inputs: ['aleo1...', '100u64'],
|
|
64
|
+
})
|
|
65
|
+
console.log(txId)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<div>
|
|
70
|
+
<span>{address}</span>
|
|
71
|
+
<button onClick={send}>Send</button>
|
|
72
|
+
<button onClick={disconnect}>Disconnect</button>
|
|
73
|
+
</div>
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Chain reads run without a connected wallet:
|
|
79
|
+
|
|
80
|
+
```tsx
|
|
81
|
+
const { publicClient } = useVeilWallet()
|
|
82
|
+
const balance = await publicClient.getBalance({ address: 'aleo1...' })
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Configuration
|
|
86
|
+
|
|
87
|
+
`VeilProvider` (`VeilProviderProps`) accepts:
|
|
88
|
+
|
|
89
|
+
- `network` — `'mainnet'` or `'testnet'`. Defaults to `'mainnet'`.
|
|
90
|
+
- `autoConnect` — reconnect to the previously used wallet. Defaults to `true`.
|
|
91
|
+
- `decryptPermission` — decrypt permission level. Defaults to `UponRequest`.
|
|
92
|
+
- `programs` — program ids to register with the wallet for decrypt permissions.
|
|
93
|
+
- `wallets` — override the default wallet list (Shield, Leo, Puzzle, Fox).
|
|
94
|
+
- `recordAccess` — connect-time record/field grant for privacy-preserving wallets.
|
|
95
|
+
- `readAddress` — set `false` to transact without the dApp learning the address.
|
|
96
|
+
Defaults to `true`.
|
|
97
|
+
- `algorithmsAllowed` — allowlist authorizing `derived` transaction inputs (e.g.
|
|
98
|
+
blinding algorithms).
|
|
99
|
+
|
|
100
|
+
`useVeilWallet` (`UseVeilWalletConfig`) accepts:
|
|
101
|
+
|
|
102
|
+
- `rpcUrl` — RPC endpoint. Defaults to the Provable mainnet API.
|
|
103
|
+
- `network` — transport network. Defaults to the provider's network.
|
|
104
|
+
|
|
105
|
+
The hook re-exports `PublicClient`, `WalletClient`, `AleoWalletAdapter`, and
|
|
106
|
+
`AnyWalletAdapter` so the caller can type consumers without extra imports.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode, ComponentProps } from 'react';
|
|
3
|
+
import { AleoWalletProvider, useWallet } from '@provablehq/aleo-wallet-adaptor-react';
|
|
4
|
+
import { WalletDecryptPermission } from '@provablehq/aleo-wallet-standard';
|
|
5
|
+
import { RecordAccessGrant, AlgorithmGrant, PublicClient, WalletClient } from '@provablehq/veil-core';
|
|
6
|
+
export { PublicClient, WalletClient } from '@provablehq/veil-core';
|
|
7
|
+
export { AleoWalletAdapter, AnyWalletAdapter } from '@provablehq/veil-aleo-wallet-adapter';
|
|
8
|
+
|
|
9
|
+
interface VeilProviderProps {
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
/** Network to connect to. Defaults to 'mainnet'. */
|
|
12
|
+
network?: 'mainnet' | 'testnet';
|
|
13
|
+
/** Auto-connect to previously used wallet. Defaults to true. */
|
|
14
|
+
autoConnect?: boolean;
|
|
15
|
+
/** Decrypt permission level. Defaults to UponRequest. */
|
|
16
|
+
decryptPermission?: WalletDecryptPermission;
|
|
17
|
+
/** Programs to register with the wallet for decrypt permissions. */
|
|
18
|
+
programs?: string[];
|
|
19
|
+
/** Override the default wallet list. If omitted, all known wallets are included. */
|
|
20
|
+
wallets?: ComponentProps<typeof AleoWalletProvider>['wallets'];
|
|
21
|
+
/** Connect-time record/field access grant for privacy-preserving wallets. */
|
|
22
|
+
recordAccess?: RecordAccessGrant;
|
|
23
|
+
/** If false, transact without the dapp ever learning the address. Defaults to true. */
|
|
24
|
+
readAddress?: boolean;
|
|
25
|
+
/** Allowlist authorizing `derived` transaction inputs (e.g. blinding algorithms). */
|
|
26
|
+
algorithmsAllowed?: AlgorithmGrant[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Batteries-included provider for veil + Aleo wallets.
|
|
30
|
+
*
|
|
31
|
+
* Wraps the app with wallet connection support. All known Aleo wallets
|
|
32
|
+
* (Shield, Leo, Puzzle, Fox) are auto-configured.
|
|
33
|
+
*
|
|
34
|
+
* ```tsx
|
|
35
|
+
* import { VeilProvider } from '@provablehq/veil-aleo-react-hooks'
|
|
36
|
+
*
|
|
37
|
+
* <VeilProvider network="mainnet">
|
|
38
|
+
* <App />
|
|
39
|
+
* </VeilProvider>
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
declare function VeilProvider({ children, network, autoConnect, decryptPermission, programs, wallets: walletsOverride, recordAccess, readAddress, algorithmsAllowed, }: VeilProviderProps): react_jsx_runtime.JSX.Element;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Options for {@link useVeilWallet}.
|
|
46
|
+
*
|
|
47
|
+
* @property rpcUrl Node endpoint both clients read through (and the wallet
|
|
48
|
+
* client falls back to). Defaults to the Provable API,
|
|
49
|
+
* `https://api.provable.com/v2`.
|
|
50
|
+
* @property network Network for the HTTP transport. Defaults to the connected
|
|
51
|
+
* wallet's network, or `'mainnet'` before a wallet connects. Set it to pin
|
|
52
|
+
* the transport to one network regardless of the wallet.
|
|
53
|
+
*/
|
|
54
|
+
interface UseVeilWalletConfig {
|
|
55
|
+
rpcUrl?: string;
|
|
56
|
+
network?: 'mainnet' | 'testnet';
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Clients, connection state, and connection controls from {@link useVeilWallet}.
|
|
60
|
+
*
|
|
61
|
+
* @property publicClient Read-only client for chain queries. Usable with or
|
|
62
|
+
* without a connected wallet.
|
|
63
|
+
* @property walletClient Write client that signs and submits through the
|
|
64
|
+
* connected wallet. `undefined` until a wallet connects — gate writes on it.
|
|
65
|
+
* @property address The connected account's address, or `null` when disconnected.
|
|
66
|
+
* @property connected True once a wallet session is established and
|
|
67
|
+
* `walletClient` is available.
|
|
68
|
+
* @property connecting True while a connect is in flight — use it to disable
|
|
69
|
+
* the connect button.
|
|
70
|
+
* @property connect Opens the wallet's approval flow on its current network.
|
|
71
|
+
* Pass a wallet name to select and connect in one step; otherwise the wallet
|
|
72
|
+
* chosen via `selectWallet` is connected.
|
|
73
|
+
* @property disconnect Ends the wallet session; `walletClient` becomes
|
|
74
|
+
* `undefined` and `address` becomes `null`.
|
|
75
|
+
* @property wallets Detected wallets with their install status, for building a
|
|
76
|
+
* wallet picker.
|
|
77
|
+
* @property selectWallet Chooses which wallet a later `connect()` opens, by name.
|
|
78
|
+
*/
|
|
79
|
+
interface UseVeilWalletReturn {
|
|
80
|
+
publicClient: PublicClient;
|
|
81
|
+
walletClient: WalletClient | undefined;
|
|
82
|
+
address: string | null;
|
|
83
|
+
connected: boolean;
|
|
84
|
+
connecting: boolean;
|
|
85
|
+
connect: (walletName?: string) => Promise<void>;
|
|
86
|
+
disconnect: () => Promise<void>;
|
|
87
|
+
wallets: ReturnType<typeof useWallet>['wallets'];
|
|
88
|
+
selectWallet: (name: string) => void;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* All-in-one hook for veil + Aleo wallet interaction.
|
|
92
|
+
*
|
|
93
|
+
* Returns a publicClient (always available) and a walletClient
|
|
94
|
+
* (available after wallet connection). No manual adapter bridging needed.
|
|
95
|
+
*
|
|
96
|
+
* ```tsx
|
|
97
|
+
* import { useVeilWallet } from '@provablehq/veil-aleo-react-hooks'
|
|
98
|
+
*
|
|
99
|
+
* function App() {
|
|
100
|
+
* const { publicClient, walletClient, address, connect } = useVeilWallet()
|
|
101
|
+
*
|
|
102
|
+
* // Read — always works
|
|
103
|
+
* const balance = await publicClient.getBalance({ address: 'aleo1...' })
|
|
104
|
+
*
|
|
105
|
+
* // Write — after connect
|
|
106
|
+
* const txId = await walletClient.writeContract({
|
|
107
|
+
* program: 'my_program.aleo',
|
|
108
|
+
* function: 'transfer',
|
|
109
|
+
* inputs: ['aleo1...', '100u64'],
|
|
110
|
+
* fee: 500_000n,
|
|
111
|
+
* })
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
declare function useVeilWallet(config?: UseVeilWalletConfig): UseVeilWalletReturn;
|
|
116
|
+
|
|
117
|
+
export { type UseVeilWalletConfig, type UseVeilWalletReturn, VeilProvider, type VeilProviderProps, useVeilWallet };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// src/provider.tsx
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { AleoWalletProvider } from "@provablehq/aleo-wallet-adaptor-react";
|
|
4
|
+
import { ShieldWalletAdapter } from "@provablehq/aleo-wallet-adaptor-shield";
|
|
5
|
+
import { LeoWalletAdapter } from "@provablehq/aleo-wallet-adaptor-leo";
|
|
6
|
+
import { PuzzleWalletAdapter } from "@provablehq/aleo-wallet-adaptor-puzzle";
|
|
7
|
+
import { FoxWalletAdapter } from "@provablehq/aleo-wallet-adaptor-fox";
|
|
8
|
+
import { Network } from "@provablehq/aleo-types";
|
|
9
|
+
import { WalletDecryptPermission } from "@provablehq/aleo-wallet-standard";
|
|
10
|
+
import { jsx } from "react/jsx-runtime";
|
|
11
|
+
var networkMap = {
|
|
12
|
+
mainnet: Network.MAINNET,
|
|
13
|
+
testnet: Network.TESTNET
|
|
14
|
+
};
|
|
15
|
+
function VeilProvider({
|
|
16
|
+
children,
|
|
17
|
+
network = "mainnet",
|
|
18
|
+
autoConnect = true,
|
|
19
|
+
decryptPermission = WalletDecryptPermission.UponRequest,
|
|
20
|
+
programs,
|
|
21
|
+
wallets: walletsOverride,
|
|
22
|
+
recordAccess,
|
|
23
|
+
readAddress,
|
|
24
|
+
algorithmsAllowed
|
|
25
|
+
}) {
|
|
26
|
+
const wallets = useMemo(
|
|
27
|
+
() => walletsOverride ?? [
|
|
28
|
+
new ShieldWalletAdapter(),
|
|
29
|
+
new LeoWalletAdapter(),
|
|
30
|
+
new PuzzleWalletAdapter(),
|
|
31
|
+
new FoxWalletAdapter()
|
|
32
|
+
],
|
|
33
|
+
[walletsOverride]
|
|
34
|
+
);
|
|
35
|
+
return /* @__PURE__ */ jsx(
|
|
36
|
+
AleoWalletProvider,
|
|
37
|
+
{
|
|
38
|
+
wallets,
|
|
39
|
+
network: networkMap[network],
|
|
40
|
+
autoConnect,
|
|
41
|
+
decryptPermission,
|
|
42
|
+
programs,
|
|
43
|
+
recordAccess,
|
|
44
|
+
readAddress,
|
|
45
|
+
algorithmsAllowed,
|
|
46
|
+
children
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/useVeilWallet.ts
|
|
52
|
+
import { useMemo as useMemo2 } from "react";
|
|
53
|
+
import { useWallet } from "@provablehq/aleo-wallet-adaptor-react";
|
|
54
|
+
import {
|
|
55
|
+
createPublicClient,
|
|
56
|
+
createWalletClient,
|
|
57
|
+
http,
|
|
58
|
+
fallback
|
|
59
|
+
} from "@provablehq/veil-core";
|
|
60
|
+
import { fromWalletAdapter } from "@provablehq/veil-aleo-wallet-adapter";
|
|
61
|
+
var DEFAULT_API_URL = "https://api.provable.com/v2";
|
|
62
|
+
function useVeilWallet(config) {
|
|
63
|
+
const { rpcUrl = DEFAULT_API_URL } = config ?? {};
|
|
64
|
+
const wallet = useWallet();
|
|
65
|
+
const network = config?.network ?? (wallet.network === "testnet" ? "testnet" : "mainnet");
|
|
66
|
+
const publicClient = useMemo2(
|
|
67
|
+
() => createPublicClient({ transport: http(rpcUrl, { network }) }),
|
|
68
|
+
[rpcUrl, network]
|
|
69
|
+
);
|
|
70
|
+
const walletClient = useMemo2(() => {
|
|
71
|
+
if (!wallet.connected || !wallet.address || !wallet.network) return void 0;
|
|
72
|
+
const walletNetwork = wallet.network === "testnet" ? "testnet" : "mainnet";
|
|
73
|
+
const adapter = {
|
|
74
|
+
account: { address: wallet.address },
|
|
75
|
+
connected: wallet.connected,
|
|
76
|
+
network: walletNetwork,
|
|
77
|
+
signMessage: (message) => wallet.signMessage(message).then((r) => r ?? new Uint8Array()),
|
|
78
|
+
executeTransaction: (options) => wallet.executeTransaction(options).then((r) => r ?? { transactionId: "" }),
|
|
79
|
+
executeDeployment: (deployment) => wallet.executeDeployment(deployment),
|
|
80
|
+
transactionStatus: (txId) => wallet.transactionStatus(txId),
|
|
81
|
+
decrypt: (cipherText) => wallet.decrypt(cipherText),
|
|
82
|
+
requestRecords: (program, includePlaintext) => wallet.requestRecords(program, includePlaintext),
|
|
83
|
+
transitionViewKeys: (txId) => wallet.transitionViewKeys(txId),
|
|
84
|
+
switchNetwork: async (network2) => {
|
|
85
|
+
await wallet.switchNetwork(network2);
|
|
86
|
+
},
|
|
87
|
+
requestTransactionHistory: (program) => wallet.requestTransactionHistory(program),
|
|
88
|
+
algorithmsSupported: () => wallet.algorithmsSupported()
|
|
89
|
+
};
|
|
90
|
+
const { account, transport: walletTransport } = fromWalletAdapter(adapter);
|
|
91
|
+
return createWalletClient({
|
|
92
|
+
account,
|
|
93
|
+
transport: fallback([walletTransport, http(rpcUrl, { network })])
|
|
94
|
+
});
|
|
95
|
+
}, [wallet.connected, wallet.address, wallet.network, rpcUrl, network]);
|
|
96
|
+
const connect = async (walletName) => {
|
|
97
|
+
if (walletName) {
|
|
98
|
+
wallet.selectWallet(walletName);
|
|
99
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
100
|
+
}
|
|
101
|
+
await wallet.connect(wallet.network);
|
|
102
|
+
};
|
|
103
|
+
return {
|
|
104
|
+
publicClient,
|
|
105
|
+
walletClient,
|
|
106
|
+
address: wallet.address,
|
|
107
|
+
connected: wallet.connected,
|
|
108
|
+
connecting: wallet.connecting,
|
|
109
|
+
connect,
|
|
110
|
+
disconnect: () => wallet.disconnect(),
|
|
111
|
+
wallets: wallet.wallets,
|
|
112
|
+
selectWallet: wallet.selectWallet
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
export {
|
|
116
|
+
VeilProvider,
|
|
117
|
+
useVeilWallet
|
|
118
|
+
};
|
|
119
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/provider.tsx","../src/useVeilWallet.ts"],"sourcesContent":["import { useMemo, type ComponentProps, type ReactNode } from 'react'\nimport { AleoWalletProvider } from '@provablehq/aleo-wallet-adaptor-react'\nimport { ShieldWalletAdapter } from '@provablehq/aleo-wallet-adaptor-shield'\nimport { LeoWalletAdapter } from '@provablehq/aleo-wallet-adaptor-leo'\nimport { PuzzleWalletAdapter } from '@provablehq/aleo-wallet-adaptor-puzzle'\nimport { FoxWalletAdapter } from '@provablehq/aleo-wallet-adaptor-fox'\nimport { Network } from '@provablehq/aleo-types'\nimport { WalletDecryptPermission } from '@provablehq/aleo-wallet-standard'\nimport type { RecordAccessGrant, AlgorithmGrant } from '@provablehq/veil-core'\n\nexport interface VeilProviderProps {\n children: ReactNode\n /** Network to connect to. Defaults to 'mainnet'. */\n network?: 'mainnet' | 'testnet'\n /** Auto-connect to previously used wallet. Defaults to true. */\n autoConnect?: boolean\n /** Decrypt permission level. Defaults to UponRequest. */\n decryptPermission?: WalletDecryptPermission\n /** Programs to register with the wallet for decrypt permissions. */\n programs?: string[]\n /** Override the default wallet list. If omitted, all known wallets are included. */\n wallets?: ComponentProps<typeof AleoWalletProvider>['wallets']\n /** Connect-time record/field access grant for privacy-preserving wallets. */\n recordAccess?: RecordAccessGrant\n /** If false, transact without the dapp ever learning the address. Defaults to true. */\n readAddress?: boolean\n /** Allowlist authorizing `derived` transaction inputs (e.g. blinding algorithms). */\n algorithmsAllowed?: AlgorithmGrant[]\n}\n\nconst networkMap = {\n mainnet: Network.MAINNET,\n testnet: Network.TESTNET,\n} as const\n\n/**\n * Batteries-included provider for veil + Aleo wallets.\n *\n * Wraps the app with wallet connection support. All known Aleo wallets\n * (Shield, Leo, Puzzle, Fox) are auto-configured.\n *\n * ```tsx\n * import { VeilProvider } from '@provablehq/veil-aleo-react-hooks'\n *\n * <VeilProvider network=\"mainnet\">\n * <App />\n * </VeilProvider>\n * ```\n */\nexport function VeilProvider({\n children,\n network = 'mainnet',\n autoConnect = true,\n decryptPermission = WalletDecryptPermission.UponRequest,\n programs,\n wallets: walletsOverride,\n recordAccess,\n readAddress,\n algorithmsAllowed,\n}: VeilProviderProps) {\n const wallets = useMemo(\n () =>\n walletsOverride ?? [\n new ShieldWalletAdapter(),\n new LeoWalletAdapter(),\n new PuzzleWalletAdapter(),\n new FoxWalletAdapter(),\n ],\n [walletsOverride],\n )\n\n return (\n <AleoWalletProvider\n wallets={wallets}\n network={networkMap[network]}\n autoConnect={autoConnect}\n decryptPermission={decryptPermission}\n programs={programs}\n recordAccess={recordAccess}\n readAddress={readAddress}\n algorithmsAllowed={algorithmsAllowed}\n >\n {children}\n </AleoWalletProvider>\n )\n}\n","import { useMemo } from 'react'\nimport { useWallet } from '@provablehq/aleo-wallet-adaptor-react'\nimport {\n createPublicClient,\n createWalletClient,\n http,\n fallback,\n type Network,\n type PublicClient,\n type TxHistoryResult,\n type WalletClient,\n} from '@provablehq/veil-core'\nimport { fromWalletAdapter, type AleoWalletAdapter } from '@provablehq/veil-aleo-wallet-adapter'\n\nconst DEFAULT_API_URL = 'https://api.provable.com/v2'\n\n/**\n * Options for {@link useVeilWallet}.\n *\n * @property rpcUrl Node endpoint both clients read through (and the wallet\n * client falls back to). Defaults to the Provable API,\n * `https://api.provable.com/v2`.\n * @property network Network for the HTTP transport. Defaults to the connected\n * wallet's network, or `'mainnet'` before a wallet connects. Set it to pin\n * the transport to one network regardless of the wallet.\n */\nexport interface UseVeilWalletConfig {\n rpcUrl?: string\n network?: 'mainnet' | 'testnet'\n}\n\n/**\n * Clients, connection state, and connection controls from {@link useVeilWallet}.\n *\n * @property publicClient Read-only client for chain queries. Usable with or\n * without a connected wallet.\n * @property walletClient Write client that signs and submits through the\n * connected wallet. `undefined` until a wallet connects — gate writes on it.\n * @property address The connected account's address, or `null` when disconnected.\n * @property connected True once a wallet session is established and\n * `walletClient` is available.\n * @property connecting True while a connect is in flight — use it to disable\n * the connect button.\n * @property connect Opens the wallet's approval flow on its current network.\n * Pass a wallet name to select and connect in one step; otherwise the wallet\n * chosen via `selectWallet` is connected.\n * @property disconnect Ends the wallet session; `walletClient` becomes\n * `undefined` and `address` becomes `null`.\n * @property wallets Detected wallets with their install status, for building a\n * wallet picker.\n * @property selectWallet Chooses which wallet a later `connect()` opens, by name.\n */\nexport interface UseVeilWalletReturn {\n publicClient: PublicClient\n walletClient: WalletClient | undefined\n address: string | null\n connected: boolean\n connecting: boolean\n connect: (walletName?: string) => Promise<void>\n disconnect: () => Promise<void>\n wallets: ReturnType<typeof useWallet>['wallets']\n selectWallet: (name: string) => void\n}\n\n/**\n * All-in-one hook for veil + Aleo wallet interaction.\n *\n * Returns a publicClient (always available) and a walletClient\n * (available after wallet connection). No manual adapter bridging needed.\n *\n * ```tsx\n * import { useVeilWallet } from '@provablehq/veil-aleo-react-hooks'\n *\n * function App() {\n * const { publicClient, walletClient, address, connect } = useVeilWallet()\n *\n * // Read — always works\n * const balance = await publicClient.getBalance({ address: 'aleo1...' })\n *\n * // Write — after connect\n * const txId = await walletClient.writeContract({\n * program: 'my_program.aleo',\n * function: 'transfer',\n * inputs: ['aleo1...', '100u64'],\n * fee: 500_000n,\n * })\n * }\n * ```\n */\nexport function useVeilWallet(config?: UseVeilWalletConfig): UseVeilWalletReturn {\n const { rpcUrl = DEFAULT_API_URL } = config ?? {}\n\n const wallet = useWallet()\n\n // Derive network from the wallet provider context, with config override\n const network = config?.network ?? (wallet.network === 'testnet' ? 'testnet' : 'mainnet')\n\n const publicClient = useMemo(\n () => createPublicClient({ transport: http(rpcUrl, { network }) }),\n [rpcUrl, network],\n )\n\n const walletClient = useMemo(() => {\n if (!wallet.connected || !wallet.address || !wallet.network) return undefined\n\n const walletNetwork: Network = wallet.network === 'testnet' ? 'testnet' : 'mainnet'\n\n const adapter: AleoWalletAdapter = {\n account: { address: wallet.address },\n connected: wallet.connected,\n network: walletNetwork,\n signMessage: (message: Uint8Array) =>\n wallet.signMessage(message).then((r) => r ?? new Uint8Array()),\n executeTransaction: (options) =>\n wallet.executeTransaction(options).then((r) => r ?? { transactionId: '' }),\n executeDeployment: (deployment) => wallet.executeDeployment(deployment),\n transactionStatus: (txId) => wallet.transactionStatus(txId),\n decrypt: (cipherText) => wallet.decrypt(cipherText),\n requestRecords: (program, includePlaintext) =>\n wallet.requestRecords(program, includePlaintext),\n transitionViewKeys: (txId) => wallet.transitionViewKeys(txId),\n switchNetwork: async (network) => {\n await wallet.switchNetwork(network as any)\n },\n requestTransactionHistory: (program) =>\n wallet.requestTransactionHistory(program) as Promise<TxHistoryResult>,\n algorithmsSupported: () => wallet.algorithmsSupported(),\n }\n\n const { account, transport: walletTransport } = fromWalletAdapter(adapter)\n\n return createWalletClient({\n account,\n transport: fallback([walletTransport, http(rpcUrl, { network })]),\n })\n }, [wallet.connected, wallet.address, wallet.network, rpcUrl, network])\n\n const connect = async (walletName?: string) => {\n if (walletName) {\n wallet.selectWallet(walletName as Parameters<typeof wallet.selectWallet>[0])\n // Allow React to process the selection before connecting\n await new Promise((r) => setTimeout(r, 0))\n }\n await wallet.connect(wallet.network!)\n }\n\n return {\n publicClient,\n walletClient,\n address: wallet.address,\n connected: wallet.connected,\n connecting: wallet.connecting,\n connect,\n disconnect: () => wallet.disconnect(),\n wallets: wallet.wallets,\n selectWallet: wallet.selectWallet as unknown as (name: string) => void,\n }\n}\n"],"mappings":";AAAA,SAAS,eAAoD;AAC7D,SAAS,0BAA0B;AACnC,SAAS,2BAA2B;AACpC,SAAS,wBAAwB;AACjC,SAAS,2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G,CAAC,CAAC;AAAA,IAC3C;AACA,UAAM,OAAO,QAAQ,OAAO,OAAQ;AAAA,EACtC;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,SAAS,OAAO;AAAA,IAChB,WAAW,OAAO;AAAA,IAClB,YAAY,OAAO;AAAA,IACnB;AAAA,IACA,YAAY,MAAM,OAAO,WAAW;AAAA,IACpC,SAAS,OAAO;AAAA,IAChB,cAAc,OAAO;AAAA,EACvB;AACF;","names":["useMemo","network"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@provablehq/veil-aleo-react-hooks",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "React hooks and providers for the building web apps.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/ProvableHQ/veil.git",
|
|
9
|
+
"directory": "packages/react"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/ProvableHQ/veil#readme",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"main": "dist/index.js",
|
|
14
|
+
"types": "dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"sideEffects": false,
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=18"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"react": ">=18"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@provablehq/aleo-wallet-adaptor-react": "1.0.0",
|
|
36
|
+
"@provablehq/aleo-wallet-adaptor-shield": "1.0.0",
|
|
37
|
+
"@provablehq/aleo-wallet-adaptor-leo": "1.0.0",
|
|
38
|
+
"@provablehq/aleo-wallet-adaptor-puzzle": "1.0.0",
|
|
39
|
+
"@provablehq/aleo-wallet-adaptor-fox": "1.0.0",
|
|
40
|
+
"@provablehq/aleo-types": "1.0.0",
|
|
41
|
+
"@provablehq/aleo-wallet-standard": "1.0.0",
|
|
42
|
+
"@provablehq/veil-core": "0.4.0",
|
|
43
|
+
"@provablehq/veil-aleo-wallet-adapter": "0.4.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/react": "^19.0.0",
|
|
47
|
+
"typescript": "^5.7.0"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsup",
|
|
51
|
+
"typecheck": "tsc --noEmit"
|
|
52
|
+
}
|
|
53
|
+
}
|