@dynamic-labs/aleo 4.79.2 → 4.81.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/CHANGELOG.md +25 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +10 -6
- package/src/connectors/DynamicWaasAleoConnector/DynamicWaasAleoConnector.cjs +798 -0
- package/src/connectors/DynamicWaasAleoConnector/DynamicWaasAleoConnector.d.ts +409 -0
- package/src/connectors/DynamicWaasAleoConnector/DynamicWaasAleoConnector.js +794 -0
- package/src/connectors/DynamicWaasAleoConnector/index.cjs +13 -0
- package/src/connectors/DynamicWaasAleoConnector/index.d.ts +3 -0
- package/src/connectors/DynamicWaasAleoConnector/index.js +9 -0
- package/src/connectors/WaasAleoWalletConnector/WaasAleoWalletConnector.cjs +216 -0
- package/src/connectors/WaasAleoWalletConnector/WaasAleoWalletConnector.d.ts +116 -0
- package/src/connectors/WaasAleoWalletConnector/WaasAleoWalletConnector.js +211 -0
- package/src/connectors/WaasAleoWalletConnector/index.d.ts +1 -0
- package/src/index.cjs +15 -0
- package/src/index.d.ts +5 -0
- package/src/index.js +7 -0
- package/src/utils/AleoUiTransaction/AleoUiTransaction.cjs +354 -0
- package/src/utils/AleoUiTransaction/AleoUiTransaction.d.ts +130 -0
- package/src/utils/AleoUiTransaction/AleoUiTransaction.js +350 -0
- package/src/utils/AleoUiTransaction/index.d.ts +2 -0
- package/src/utils/aleoSendableTokens/aleoSendableTokens.cjs +185 -0
- package/src/utils/aleoSendableTokens/aleoSendableTokens.d.ts +78 -0
- package/src/utils/aleoSendableTokens/aleoSendableTokens.js +175 -0
- package/src/utils/aleoSendableTokens/index.d.ts +2 -0
- package/src/utils/aleoShieldableTokens/aleoShieldableTokens.cjs +119 -0
- package/src/utils/aleoShieldableTokens/aleoShieldableTokens.d.ts +45 -0
- package/src/utils/aleoShieldableTokens/aleoShieldableTokens.js +114 -0
- package/src/utils/aleoShieldableTokens/index.d.ts +2 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var DynamicWaasAleoConnector = require('./DynamicWaasAleoConnector.cjs');
|
|
7
|
+
|
|
8
|
+
const DynamicWaasAleoConnectors = () => [
|
|
9
|
+
DynamicWaasAleoConnector.DynamicWaasAleoConnector,
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
exports.DynamicWaasAleoConnector = DynamicWaasAleoConnector.DynamicWaasAleoConnector;
|
|
13
|
+
exports.DynamicWaasAleoConnectors = DynamicWaasAleoConnectors;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { DynamicWaasAleoConnector } from './DynamicWaasAleoConnector.js';
|
|
3
|
+
export { DynamicWaasAleoConnector } from './DynamicWaasAleoConnector.js';
|
|
4
|
+
|
|
5
|
+
const DynamicWaasAleoConnectors = () => [
|
|
6
|
+
DynamicWaasAleoConnector,
|
|
7
|
+
];
|
|
8
|
+
|
|
9
|
+
export { DynamicWaasAleoConnectors };
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
|
+
var aleoTypes = require('@provablehq/aleo-types');
|
|
8
|
+
var logger = require('@dynamic-labs/logger');
|
|
9
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
10
|
+
var AleoWallet = require('../../wallet/AleoWallet/AleoWallet.cjs');
|
|
11
|
+
var fetchPublicBalance = require('../../utils/fetchPublicBalance/fetchPublicBalance.cjs');
|
|
12
|
+
var getNetworkByChainId = require('../../utils/getNetworkByChainId/getNetworkByChainId.cjs');
|
|
13
|
+
|
|
14
|
+
const MICROCREDITS_PER_CREDIT = 1000000;
|
|
15
|
+
/**
|
|
16
|
+
* localStorage key for the user-selected Aleo chainId. Mirrors the pattern
|
|
17
|
+
* used by `DYNAMIC_SVM_NETWORK_ID_LS_KEY` in `@dynamic-labs/solana-core` and
|
|
18
|
+
* the equivalent EVM key — gives WaaS Aleo wallets the same persisted-network
|
|
19
|
+
* UX as the other chains.
|
|
20
|
+
*/
|
|
21
|
+
const DYNAMIC_ALEO_NETWORK_ID_LS_KEY = 'dynamic_aleo_network_id';
|
|
22
|
+
/**
|
|
23
|
+
* Abstract WaaS-side base connector for Aleo.
|
|
24
|
+
* Does NOT depend on the @provablehq/aleo-wallet-standard StandardWallet
|
|
25
|
+
* (that's only relevant for injected browser wallets like Leo/Puzzle/Fox).
|
|
26
|
+
* The concrete Dynamic WaaS connector extends this via `withDynamicWaas`.
|
|
27
|
+
*/
|
|
28
|
+
class WaasAleoWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
29
|
+
constructor(name, opts) {
|
|
30
|
+
var _a;
|
|
31
|
+
super({
|
|
32
|
+
metadata: opts.metadata,
|
|
33
|
+
walletBook: opts.walletBook,
|
|
34
|
+
});
|
|
35
|
+
this.ChainWallet = AleoWallet.AleoWallet;
|
|
36
|
+
this.name = 'Waas Aleo Wallet';
|
|
37
|
+
this.connectedChain = 'ALEO';
|
|
38
|
+
this.supportedChains = ['ALEO'];
|
|
39
|
+
this.name = name;
|
|
40
|
+
this.logger = new logger.Logger(this.name);
|
|
41
|
+
this.aleoNetworks = (_a = opts.aleoNetworks) !== null && _a !== void 0 ? _a : [];
|
|
42
|
+
this.overrideKey = this.key;
|
|
43
|
+
}
|
|
44
|
+
// ---------------------------------------------------------------------------
|
|
45
|
+
// Network selection (mirrors EVM/Solana Turnkey patterns)
|
|
46
|
+
//
|
|
47
|
+
// localStorage value (set via switchNetwork) → getSelectedNetwork
|
|
48
|
+
// ↓ if absent
|
|
49
|
+
// default fallback (testnet-prefer for sandbox)
|
|
50
|
+
//
|
|
51
|
+
// Persisting in localStorage keeps the widget's network across reloads and
|
|
52
|
+
// keeps parity with how EVM/SVM Turnkey connectors track selectedNetwork.
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
/**
|
|
55
|
+
* Reads the user's selected network chainId from localStorage. Returns ''
|
|
56
|
+
* if nothing is stored (matches Solana Turnkey's pattern). Callers should
|
|
57
|
+
* fall back to a default when this is empty.
|
|
58
|
+
*/
|
|
59
|
+
getNetworkId() {
|
|
60
|
+
var _a;
|
|
61
|
+
if (typeof globalThis === 'undefined' || !globalThis.localStorage) {
|
|
62
|
+
return '';
|
|
63
|
+
}
|
|
64
|
+
return ((_a = globalThis.localStorage.getItem(DYNAMIC_ALEO_NETWORK_ID_LS_KEY)) !== null && _a !== void 0 ? _a : '');
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Writes the selected network chainId to localStorage. Pass `null` to
|
|
68
|
+
* clear (e.g. on logout). Same shape as EVM/Solana Turnkey.
|
|
69
|
+
*/
|
|
70
|
+
setNetworkId(networkId) {
|
|
71
|
+
if (typeof globalThis === 'undefined' || !globalThis.localStorage) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (networkId === null || networkId === '') {
|
|
75
|
+
globalThis.localStorage.removeItem(DYNAMIC_ALEO_NETWORK_ID_LS_KEY);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
globalThis.localStorage.setItem(DYNAMIC_ALEO_NETWORK_ID_LS_KEY, networkId);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Returns the currently-selected network entry from `aleoNetworks`.
|
|
83
|
+
*
|
|
84
|
+
* Resolution order:
|
|
85
|
+
* 1. localStorage value (set by `setNetworkId` / `switchNetwork`)
|
|
86
|
+
* 2. First entry in `aleoNetworks` — this is the env's default ordering
|
|
87
|
+
* (matches how `TurnkeyEVMWalletConnector.getLastUsedChainId` falls
|
|
88
|
+
* back to `evmNetworks[0].chainId`). Crucially, if we returned a
|
|
89
|
+
* different network than the env's default, the widget's network-
|
|
90
|
+
* mismatch detector would flag the wallet as being on the wrong
|
|
91
|
+
* chain and replace the chain pill with a "Switch Network" button.
|
|
92
|
+
*
|
|
93
|
+
* Returns undefined only if no networks are configured at all.
|
|
94
|
+
*
|
|
95
|
+
* Note: when an env enables both mainnet + testnet (e.g. some sandbox
|
|
96
|
+
* configs), the user can call `switchNetwork({ networkChainId: 1 })` to
|
|
97
|
+
* land on testnet; the choice is persisted in localStorage and survives
|
|
98
|
+
* reloads.
|
|
99
|
+
*/
|
|
100
|
+
getSelectedNetwork() {
|
|
101
|
+
if (this.aleoNetworks.length === 0)
|
|
102
|
+
return undefined;
|
|
103
|
+
const stored = this.getNetworkId();
|
|
104
|
+
if (stored) {
|
|
105
|
+
const match = this.aleoNetworks.find((n) => String(n.chainId) === stored);
|
|
106
|
+
if (match)
|
|
107
|
+
return match;
|
|
108
|
+
}
|
|
109
|
+
return this.aleoNetworks[0];
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Resolves the current Aleo `Network` enum (used internally by
|
|
113
|
+
* `fetchPublicBalance`). Falls back to TESTNET if nothing's configured.
|
|
114
|
+
* Protected so WaaS subclasses can reuse the same selected-network for
|
|
115
|
+
* widget flows (e.g. AleoUiTransaction.getBalance).
|
|
116
|
+
*/
|
|
117
|
+
resolveNetwork() {
|
|
118
|
+
var _a, _b;
|
|
119
|
+
const entry = this.getSelectedNetwork();
|
|
120
|
+
const chainId = typeof (entry === null || entry === void 0 ? void 0 : entry.chainId) === 'number'
|
|
121
|
+
? entry.chainId
|
|
122
|
+
: Number((_a = entry === null || entry === void 0 ? void 0 : entry.chainId) !== null && _a !== void 0 ? _a : NaN);
|
|
123
|
+
return ((_b = (Number.isFinite(chainId) ? getNetworkByChainId.getNetworkByChainId(chainId) : undefined)) !== null && _b !== void 0 ? _b : aleoTypes.Network.TESTNET);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Returns the active network's chainId as a STRING.
|
|
127
|
+
*
|
|
128
|
+
* dynamic-auth's `useWalletConnectorNetwork` hook explicitly treats Aleo
|
|
129
|
+
* (alongside STARK and STELLAR) as a string-chainId chain — see the
|
|
130
|
+
* `useChainAsString` switch. Returning a number causes downstream
|
|
131
|
+
* comparisons and the chainChange event handler to mis-parse, leaving the
|
|
132
|
+
* widget in a perpetual loading-skeleton state.
|
|
133
|
+
*
|
|
134
|
+
* Returning `'0'` or `'1'` matches the format consumers expect, while
|
|
135
|
+
* `resolveNetworkIdForRequest` happily coerces `'1'` back to `1` for the
|
|
136
|
+
* balance API call.
|
|
137
|
+
*/
|
|
138
|
+
getNetwork() {
|
|
139
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
140
|
+
const entry = this.getSelectedNetwork();
|
|
141
|
+
if ((entry === null || entry === void 0 ? void 0 : entry.chainId) === undefined || (entry === null || entry === void 0 ? void 0 : entry.chainId) === null) {
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
return String(entry.chainId);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Indicates this connector supports user-driven network switching, so the
|
|
149
|
+
* widget UI exposes the chain-switcher dropdown for Aleo wallets.
|
|
150
|
+
*/
|
|
151
|
+
supportsNetworkSwitching() {
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Returns the env-configured Aleo networks. The widget's NetworkPicker
|
|
156
|
+
* uses this to render the chain-switcher dropdown and to decide whether
|
|
157
|
+
* the wallet's current network is "supported". Without overriding this,
|
|
158
|
+
* the base class returns `[]` and the widget renders a red "Switch Network"
|
|
159
|
+
* button (because no network in the empty list matches `getNetwork()`'s
|
|
160
|
+
* value).
|
|
161
|
+
*
|
|
162
|
+
* Mirrors `AleoWalletConnector.getEnabledNetworks()` from the external-
|
|
163
|
+
* wallet path.
|
|
164
|
+
*/
|
|
165
|
+
getEnabledNetworks() {
|
|
166
|
+
return this.aleoNetworks;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Switches the active Aleo network. Persists the selection in localStorage
|
|
170
|
+
* and emits `chainChange` so the widget / DApp can react. Mirrors the
|
|
171
|
+
* EVM/SVM Turnkey switchNetwork flow.
|
|
172
|
+
*/
|
|
173
|
+
switchNetwork(_a) {
|
|
174
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ networkChainId, }) {
|
|
175
|
+
if (networkChainId === undefined ||
|
|
176
|
+
networkChainId === null ||
|
|
177
|
+
networkChainId === '') {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
const chainIdString = String(networkChainId);
|
|
181
|
+
// Validate the chainId is one we actually have configured before persisting.
|
|
182
|
+
const target = this.aleoNetworks.find((n) => String(n.chainId) === chainIdString);
|
|
183
|
+
if (!target) {
|
|
184
|
+
this.logger.warn(`[switchNetwork] chainId ${chainIdString} not in configured aleoNetworks`);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
this.setNetworkId(chainIdString);
|
|
188
|
+
this.emit('chainChange', { chain: chainIdString });
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Returns the wallet's public credits balance as a human-readable credits
|
|
193
|
+
* string (e.g. "0.5" = 0.5 credits = 500,000 microcredits).
|
|
194
|
+
* Matches the format used by AleoWalletAdapterConnector.getBalance so the
|
|
195
|
+
* widget UI renders WaaS Aleo wallets identically to external Aleo wallets.
|
|
196
|
+
*/
|
|
197
|
+
getBalance(address) {
|
|
198
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
199
|
+
const targetAddress = address !== null && address !== void 0 ? address : (yield this.getAddress());
|
|
200
|
+
if (!targetAddress) {
|
|
201
|
+
return undefined;
|
|
202
|
+
}
|
|
203
|
+
try {
|
|
204
|
+
const microcredits = yield fetchPublicBalance.fetchPublicBalance(targetAddress, this.resolveNetwork());
|
|
205
|
+
return (Number(microcredits) / MICROCREDITS_PER_CREDIT).toFixed(6);
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
this.logger.debug('Failed to fetch Aleo public balance', error);
|
|
209
|
+
return undefined;
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
exports.DYNAMIC_ALEO_NETWORK_ID_LS_KEY = DYNAMIC_ALEO_NETWORK_ID_LS_KEY;
|
|
216
|
+
exports.WaasAleoWalletConnector = WaasAleoWalletConnector;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Network } from '@provablehq/aleo-types';
|
|
2
|
+
import { Logger } from '@dynamic-labs/logger';
|
|
3
|
+
import type { GenericNetwork } from '@dynamic-labs/types';
|
|
4
|
+
import { type Chain, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
5
|
+
import { AleoWallet } from '../../wallet/AleoWallet';
|
|
6
|
+
/**
|
|
7
|
+
* localStorage key for the user-selected Aleo chainId. Mirrors the pattern
|
|
8
|
+
* used by `DYNAMIC_SVM_NETWORK_ID_LS_KEY` in `@dynamic-labs/solana-core` and
|
|
9
|
+
* the equivalent EVM key — gives WaaS Aleo wallets the same persisted-network
|
|
10
|
+
* UX as the other chains.
|
|
11
|
+
*/
|
|
12
|
+
export declare const DYNAMIC_ALEO_NETWORK_ID_LS_KEY = "dynamic_aleo_network_id";
|
|
13
|
+
export type WaasAleoWalletConnectorProps = {
|
|
14
|
+
metadata?: unknown;
|
|
15
|
+
aleoNetworks?: GenericNetwork[];
|
|
16
|
+
walletBook: unknown;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Abstract WaaS-side base connector for Aleo.
|
|
20
|
+
* Does NOT depend on the @provablehq/aleo-wallet-standard StandardWallet
|
|
21
|
+
* (that's only relevant for injected browser wallets like Leo/Puzzle/Fox).
|
|
22
|
+
* The concrete Dynamic WaaS connector extends this via `withDynamicWaas`.
|
|
23
|
+
*/
|
|
24
|
+
export declare abstract class WaasAleoWalletConnector extends WalletConnectorBase<typeof AleoWallet> {
|
|
25
|
+
ChainWallet: typeof AleoWallet;
|
|
26
|
+
name: string;
|
|
27
|
+
connectedChain: Chain;
|
|
28
|
+
readonly supportedChains: Chain[];
|
|
29
|
+
protected aleoNetworks: GenericNetwork[];
|
|
30
|
+
logger: Logger;
|
|
31
|
+
constructor(name: string, opts: WaasAleoWalletConnectorProps);
|
|
32
|
+
/**
|
|
33
|
+
* Reads the user's selected network chainId from localStorage. Returns ''
|
|
34
|
+
* if nothing is stored (matches Solana Turnkey's pattern). Callers should
|
|
35
|
+
* fall back to a default when this is empty.
|
|
36
|
+
*/
|
|
37
|
+
getNetworkId(): string;
|
|
38
|
+
/**
|
|
39
|
+
* Writes the selected network chainId to localStorage. Pass `null` to
|
|
40
|
+
* clear (e.g. on logout). Same shape as EVM/Solana Turnkey.
|
|
41
|
+
*/
|
|
42
|
+
setNetworkId(networkId: string | null): void;
|
|
43
|
+
/**
|
|
44
|
+
* Returns the currently-selected network entry from `aleoNetworks`.
|
|
45
|
+
*
|
|
46
|
+
* Resolution order:
|
|
47
|
+
* 1. localStorage value (set by `setNetworkId` / `switchNetwork`)
|
|
48
|
+
* 2. First entry in `aleoNetworks` — this is the env's default ordering
|
|
49
|
+
* (matches how `TurnkeyEVMWalletConnector.getLastUsedChainId` falls
|
|
50
|
+
* back to `evmNetworks[0].chainId`). Crucially, if we returned a
|
|
51
|
+
* different network than the env's default, the widget's network-
|
|
52
|
+
* mismatch detector would flag the wallet as being on the wrong
|
|
53
|
+
* chain and replace the chain pill with a "Switch Network" button.
|
|
54
|
+
*
|
|
55
|
+
* Returns undefined only if no networks are configured at all.
|
|
56
|
+
*
|
|
57
|
+
* Note: when an env enables both mainnet + testnet (e.g. some sandbox
|
|
58
|
+
* configs), the user can call `switchNetwork({ networkChainId: 1 })` to
|
|
59
|
+
* land on testnet; the choice is persisted in localStorage and survives
|
|
60
|
+
* reloads.
|
|
61
|
+
*/
|
|
62
|
+
getSelectedNetwork(): GenericNetwork | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* Resolves the current Aleo `Network` enum (used internally by
|
|
65
|
+
* `fetchPublicBalance`). Falls back to TESTNET if nothing's configured.
|
|
66
|
+
* Protected so WaaS subclasses can reuse the same selected-network for
|
|
67
|
+
* widget flows (e.g. AleoUiTransaction.getBalance).
|
|
68
|
+
*/
|
|
69
|
+
protected resolveNetwork(): Network;
|
|
70
|
+
/**
|
|
71
|
+
* Returns the active network's chainId as a STRING.
|
|
72
|
+
*
|
|
73
|
+
* dynamic-auth's `useWalletConnectorNetwork` hook explicitly treats Aleo
|
|
74
|
+
* (alongside STARK and STELLAR) as a string-chainId chain — see the
|
|
75
|
+
* `useChainAsString` switch. Returning a number causes downstream
|
|
76
|
+
* comparisons and the chainChange event handler to mis-parse, leaving the
|
|
77
|
+
* widget in a perpetual loading-skeleton state.
|
|
78
|
+
*
|
|
79
|
+
* Returning `'0'` or `'1'` matches the format consumers expect, while
|
|
80
|
+
* `resolveNetworkIdForRequest` happily coerces `'1'` back to `1` for the
|
|
81
|
+
* balance API call.
|
|
82
|
+
*/
|
|
83
|
+
getNetwork(): Promise<string | undefined>;
|
|
84
|
+
/**
|
|
85
|
+
* Indicates this connector supports user-driven network switching, so the
|
|
86
|
+
* widget UI exposes the chain-switcher dropdown for Aleo wallets.
|
|
87
|
+
*/
|
|
88
|
+
supportsNetworkSwitching(): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Returns the env-configured Aleo networks. The widget's NetworkPicker
|
|
91
|
+
* uses this to render the chain-switcher dropdown and to decide whether
|
|
92
|
+
* the wallet's current network is "supported". Without overriding this,
|
|
93
|
+
* the base class returns `[]` and the widget renders a red "Switch Network"
|
|
94
|
+
* button (because no network in the empty list matches `getNetwork()`'s
|
|
95
|
+
* value).
|
|
96
|
+
*
|
|
97
|
+
* Mirrors `AleoWalletConnector.getEnabledNetworks()` from the external-
|
|
98
|
+
* wallet path.
|
|
99
|
+
*/
|
|
100
|
+
getEnabledNetworks(): GenericNetwork[];
|
|
101
|
+
/**
|
|
102
|
+
* Switches the active Aleo network. Persists the selection in localStorage
|
|
103
|
+
* and emits `chainChange` so the widget / DApp can react. Mirrors the
|
|
104
|
+
* EVM/SVM Turnkey switchNetwork flow.
|
|
105
|
+
*/
|
|
106
|
+
switchNetwork({ networkChainId, }: {
|
|
107
|
+
networkChainId: number | string | undefined;
|
|
108
|
+
}): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Returns the wallet's public credits balance as a human-readable credits
|
|
111
|
+
* string (e.g. "0.5" = 0.5 credits = 500,000 microcredits).
|
|
112
|
+
* Matches the format used by AleoWalletAdapterConnector.getBalance so the
|
|
113
|
+
* widget UI renders WaaS Aleo wallets identically to external Aleo wallets.
|
|
114
|
+
*/
|
|
115
|
+
getBalance(address?: string): Promise<string | undefined>;
|
|
116
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
+
import { Network } from '@provablehq/aleo-types';
|
|
4
|
+
import { Logger } from '@dynamic-labs/logger';
|
|
5
|
+
import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
6
|
+
import { AleoWallet } from '../../wallet/AleoWallet/AleoWallet.js';
|
|
7
|
+
import { fetchPublicBalance } from '../../utils/fetchPublicBalance/fetchPublicBalance.js';
|
|
8
|
+
import { getNetworkByChainId } from '../../utils/getNetworkByChainId/getNetworkByChainId.js';
|
|
9
|
+
|
|
10
|
+
const MICROCREDITS_PER_CREDIT = 1000000;
|
|
11
|
+
/**
|
|
12
|
+
* localStorage key for the user-selected Aleo chainId. Mirrors the pattern
|
|
13
|
+
* used by `DYNAMIC_SVM_NETWORK_ID_LS_KEY` in `@dynamic-labs/solana-core` and
|
|
14
|
+
* the equivalent EVM key — gives WaaS Aleo wallets the same persisted-network
|
|
15
|
+
* UX as the other chains.
|
|
16
|
+
*/
|
|
17
|
+
const DYNAMIC_ALEO_NETWORK_ID_LS_KEY = 'dynamic_aleo_network_id';
|
|
18
|
+
/**
|
|
19
|
+
* Abstract WaaS-side base connector for Aleo.
|
|
20
|
+
* Does NOT depend on the @provablehq/aleo-wallet-standard StandardWallet
|
|
21
|
+
* (that's only relevant for injected browser wallets like Leo/Puzzle/Fox).
|
|
22
|
+
* The concrete Dynamic WaaS connector extends this via `withDynamicWaas`.
|
|
23
|
+
*/
|
|
24
|
+
class WaasAleoWalletConnector extends WalletConnectorBase {
|
|
25
|
+
constructor(name, opts) {
|
|
26
|
+
var _a;
|
|
27
|
+
super({
|
|
28
|
+
metadata: opts.metadata,
|
|
29
|
+
walletBook: opts.walletBook,
|
|
30
|
+
});
|
|
31
|
+
this.ChainWallet = AleoWallet;
|
|
32
|
+
this.name = 'Waas Aleo Wallet';
|
|
33
|
+
this.connectedChain = 'ALEO';
|
|
34
|
+
this.supportedChains = ['ALEO'];
|
|
35
|
+
this.name = name;
|
|
36
|
+
this.logger = new Logger(this.name);
|
|
37
|
+
this.aleoNetworks = (_a = opts.aleoNetworks) !== null && _a !== void 0 ? _a : [];
|
|
38
|
+
this.overrideKey = this.key;
|
|
39
|
+
}
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
// Network selection (mirrors EVM/Solana Turnkey patterns)
|
|
42
|
+
//
|
|
43
|
+
// localStorage value (set via switchNetwork) → getSelectedNetwork
|
|
44
|
+
// ↓ if absent
|
|
45
|
+
// default fallback (testnet-prefer for sandbox)
|
|
46
|
+
//
|
|
47
|
+
// Persisting in localStorage keeps the widget's network across reloads and
|
|
48
|
+
// keeps parity with how EVM/SVM Turnkey connectors track selectedNetwork.
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
/**
|
|
51
|
+
* Reads the user's selected network chainId from localStorage. Returns ''
|
|
52
|
+
* if nothing is stored (matches Solana Turnkey's pattern). Callers should
|
|
53
|
+
* fall back to a default when this is empty.
|
|
54
|
+
*/
|
|
55
|
+
getNetworkId() {
|
|
56
|
+
var _a;
|
|
57
|
+
if (typeof globalThis === 'undefined' || !globalThis.localStorage) {
|
|
58
|
+
return '';
|
|
59
|
+
}
|
|
60
|
+
return ((_a = globalThis.localStorage.getItem(DYNAMIC_ALEO_NETWORK_ID_LS_KEY)) !== null && _a !== void 0 ? _a : '');
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Writes the selected network chainId to localStorage. Pass `null` to
|
|
64
|
+
* clear (e.g. on logout). Same shape as EVM/Solana Turnkey.
|
|
65
|
+
*/
|
|
66
|
+
setNetworkId(networkId) {
|
|
67
|
+
if (typeof globalThis === 'undefined' || !globalThis.localStorage) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (networkId === null || networkId === '') {
|
|
71
|
+
globalThis.localStorage.removeItem(DYNAMIC_ALEO_NETWORK_ID_LS_KEY);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
globalThis.localStorage.setItem(DYNAMIC_ALEO_NETWORK_ID_LS_KEY, networkId);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Returns the currently-selected network entry from `aleoNetworks`.
|
|
79
|
+
*
|
|
80
|
+
* Resolution order:
|
|
81
|
+
* 1. localStorage value (set by `setNetworkId` / `switchNetwork`)
|
|
82
|
+
* 2. First entry in `aleoNetworks` — this is the env's default ordering
|
|
83
|
+
* (matches how `TurnkeyEVMWalletConnector.getLastUsedChainId` falls
|
|
84
|
+
* back to `evmNetworks[0].chainId`). Crucially, if we returned a
|
|
85
|
+
* different network than the env's default, the widget's network-
|
|
86
|
+
* mismatch detector would flag the wallet as being on the wrong
|
|
87
|
+
* chain and replace the chain pill with a "Switch Network" button.
|
|
88
|
+
*
|
|
89
|
+
* Returns undefined only if no networks are configured at all.
|
|
90
|
+
*
|
|
91
|
+
* Note: when an env enables both mainnet + testnet (e.g. some sandbox
|
|
92
|
+
* configs), the user can call `switchNetwork({ networkChainId: 1 })` to
|
|
93
|
+
* land on testnet; the choice is persisted in localStorage and survives
|
|
94
|
+
* reloads.
|
|
95
|
+
*/
|
|
96
|
+
getSelectedNetwork() {
|
|
97
|
+
if (this.aleoNetworks.length === 0)
|
|
98
|
+
return undefined;
|
|
99
|
+
const stored = this.getNetworkId();
|
|
100
|
+
if (stored) {
|
|
101
|
+
const match = this.aleoNetworks.find((n) => String(n.chainId) === stored);
|
|
102
|
+
if (match)
|
|
103
|
+
return match;
|
|
104
|
+
}
|
|
105
|
+
return this.aleoNetworks[0];
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Resolves the current Aleo `Network` enum (used internally by
|
|
109
|
+
* `fetchPublicBalance`). Falls back to TESTNET if nothing's configured.
|
|
110
|
+
* Protected so WaaS subclasses can reuse the same selected-network for
|
|
111
|
+
* widget flows (e.g. AleoUiTransaction.getBalance).
|
|
112
|
+
*/
|
|
113
|
+
resolveNetwork() {
|
|
114
|
+
var _a, _b;
|
|
115
|
+
const entry = this.getSelectedNetwork();
|
|
116
|
+
const chainId = typeof (entry === null || entry === void 0 ? void 0 : entry.chainId) === 'number'
|
|
117
|
+
? entry.chainId
|
|
118
|
+
: Number((_a = entry === null || entry === void 0 ? void 0 : entry.chainId) !== null && _a !== void 0 ? _a : NaN);
|
|
119
|
+
return ((_b = (Number.isFinite(chainId) ? getNetworkByChainId(chainId) : undefined)) !== null && _b !== void 0 ? _b : Network.TESTNET);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Returns the active network's chainId as a STRING.
|
|
123
|
+
*
|
|
124
|
+
* dynamic-auth's `useWalletConnectorNetwork` hook explicitly treats Aleo
|
|
125
|
+
* (alongside STARK and STELLAR) as a string-chainId chain — see the
|
|
126
|
+
* `useChainAsString` switch. Returning a number causes downstream
|
|
127
|
+
* comparisons and the chainChange event handler to mis-parse, leaving the
|
|
128
|
+
* widget in a perpetual loading-skeleton state.
|
|
129
|
+
*
|
|
130
|
+
* Returning `'0'` or `'1'` matches the format consumers expect, while
|
|
131
|
+
* `resolveNetworkIdForRequest` happily coerces `'1'` back to `1` for the
|
|
132
|
+
* balance API call.
|
|
133
|
+
*/
|
|
134
|
+
getNetwork() {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
const entry = this.getSelectedNetwork();
|
|
137
|
+
if ((entry === null || entry === void 0 ? void 0 : entry.chainId) === undefined || (entry === null || entry === void 0 ? void 0 : entry.chainId) === null) {
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
return String(entry.chainId);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Indicates this connector supports user-driven network switching, so the
|
|
145
|
+
* widget UI exposes the chain-switcher dropdown for Aleo wallets.
|
|
146
|
+
*/
|
|
147
|
+
supportsNetworkSwitching() {
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Returns the env-configured Aleo networks. The widget's NetworkPicker
|
|
152
|
+
* uses this to render the chain-switcher dropdown and to decide whether
|
|
153
|
+
* the wallet's current network is "supported". Without overriding this,
|
|
154
|
+
* the base class returns `[]` and the widget renders a red "Switch Network"
|
|
155
|
+
* button (because no network in the empty list matches `getNetwork()`'s
|
|
156
|
+
* value).
|
|
157
|
+
*
|
|
158
|
+
* Mirrors `AleoWalletConnector.getEnabledNetworks()` from the external-
|
|
159
|
+
* wallet path.
|
|
160
|
+
*/
|
|
161
|
+
getEnabledNetworks() {
|
|
162
|
+
return this.aleoNetworks;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Switches the active Aleo network. Persists the selection in localStorage
|
|
166
|
+
* and emits `chainChange` so the widget / DApp can react. Mirrors the
|
|
167
|
+
* EVM/SVM Turnkey switchNetwork flow.
|
|
168
|
+
*/
|
|
169
|
+
switchNetwork(_a) {
|
|
170
|
+
return __awaiter(this, arguments, void 0, function* ({ networkChainId, }) {
|
|
171
|
+
if (networkChainId === undefined ||
|
|
172
|
+
networkChainId === null ||
|
|
173
|
+
networkChainId === '') {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const chainIdString = String(networkChainId);
|
|
177
|
+
// Validate the chainId is one we actually have configured before persisting.
|
|
178
|
+
const target = this.aleoNetworks.find((n) => String(n.chainId) === chainIdString);
|
|
179
|
+
if (!target) {
|
|
180
|
+
this.logger.warn(`[switchNetwork] chainId ${chainIdString} not in configured aleoNetworks`);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
this.setNetworkId(chainIdString);
|
|
184
|
+
this.emit('chainChange', { chain: chainIdString });
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Returns the wallet's public credits balance as a human-readable credits
|
|
189
|
+
* string (e.g. "0.5" = 0.5 credits = 500,000 microcredits).
|
|
190
|
+
* Matches the format used by AleoWalletAdapterConnector.getBalance so the
|
|
191
|
+
* widget UI renders WaaS Aleo wallets identically to external Aleo wallets.
|
|
192
|
+
*/
|
|
193
|
+
getBalance(address) {
|
|
194
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
195
|
+
const targetAddress = address !== null && address !== void 0 ? address : (yield this.getAddress());
|
|
196
|
+
if (!targetAddress) {
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
199
|
+
try {
|
|
200
|
+
const microcredits = yield fetchPublicBalance(targetAddress, this.resolveNetwork());
|
|
201
|
+
return (Number(microcredits) / MICROCREDITS_PER_CREDIT).toFixed(6);
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
this.logger.debug('Failed to fetch Aleo public balance', error);
|
|
205
|
+
return undefined;
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export { DYNAMIC_ALEO_NETWORK_ID_LS_KEY, WaasAleoWalletConnector };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './WaasAleoWalletConnector';
|
package/src/index.cjs
CHANGED
|
@@ -6,20 +6,29 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
6
6
|
var assertPackageVersion = require('@dynamic-labs/assert-package-version');
|
|
7
7
|
var _package = require('../package.cjs');
|
|
8
8
|
var fetchAleoWalletAdapterConnectors = require('./utils/fetchAleoWalletAdapterConnectors/fetchAleoWalletAdapterConnectors.cjs');
|
|
9
|
+
var index = require('./connectors/DynamicWaasAleoConnector/index.cjs');
|
|
9
10
|
var AleoWalletConnector = require('./connectors/AleoWalletConnector/AleoWalletConnector.cjs');
|
|
10
11
|
var AleoWalletAdapterConnector = require('./connectors/AleoWalletAdapterConnector/AleoWalletAdapterConnector.cjs');
|
|
12
|
+
var WaasAleoWalletConnector = require('./connectors/WaasAleoWalletConnector/WaasAleoWalletConnector.cjs');
|
|
11
13
|
var isAleoWallet = require('./wallet/isAleoWallet/isAleoWallet.cjs');
|
|
14
|
+
var AleoUiTransaction = require('./utils/AleoUiTransaction/AleoUiTransaction.cjs');
|
|
12
15
|
var aleoWalletStandard = require('@provablehq/aleo-wallet-standard');
|
|
16
|
+
var aleoSendableTokens = require('./utils/aleoSendableTokens/aleoSendableTokens.cjs');
|
|
17
|
+
var DynamicWaasAleoConnector = require('./connectors/DynamicWaasAleoConnector/DynamicWaasAleoConnector.cjs');
|
|
13
18
|
|
|
14
19
|
assertPackageVersion.assertPackageVersion('@dynamic-labs/aleo', _package.version);
|
|
15
20
|
const AleoWalletConnectors = (props) => [
|
|
16
21
|
// ...fetchAleoWalletConnectors(props),
|
|
17
22
|
...fetchAleoWalletAdapterConnectors.fetchAleoWalletAdapterConnectors(props),
|
|
23
|
+
...index.DynamicWaasAleoConnectors(),
|
|
18
24
|
];
|
|
19
25
|
|
|
26
|
+
exports.DynamicWaasAleoConnectors = index.DynamicWaasAleoConnectors;
|
|
20
27
|
exports.AleoWalletConnector = AleoWalletConnector.AleoWalletConnector;
|
|
21
28
|
exports.AleoWalletAdapterConnector = AleoWalletAdapterConnector.AleoWalletAdapterConnector;
|
|
29
|
+
exports.WaasAleoWalletConnector = WaasAleoWalletConnector.WaasAleoWalletConnector;
|
|
22
30
|
exports.isAleoWallet = isAleoWallet.isAleoWallet;
|
|
31
|
+
exports.AleoUiTransaction = AleoUiTransaction.AleoUiTransaction;
|
|
23
32
|
Object.defineProperty(exports, 'ALEO_CHAINS', {
|
|
24
33
|
enumerable: true,
|
|
25
34
|
get: function () { return aleoWalletStandard.ALEO_CHAINS; }
|
|
@@ -36,4 +45,10 @@ Object.defineProperty(exports, 'WalletReadyState', {
|
|
|
36
45
|
enumerable: true,
|
|
37
46
|
get: function () { return aleoWalletStandard.WalletReadyState; }
|
|
38
47
|
});
|
|
48
|
+
exports.ALEO_CREDITS_PROGRAM = aleoSendableTokens.ALEO_CREDITS_PROGRAM;
|
|
49
|
+
exports.ALEO_TOKEN_REGISTRY_PROGRAM = aleoSendableTokens.ALEO_TOKEN_REGISTRY_PROGRAM;
|
|
50
|
+
exports.extractRecordAtomicAmount = aleoSendableTokens.extractRecordAtomicAmount;
|
|
51
|
+
exports.getAleoSendableTokensForNetwork = aleoSendableTokens.getAleoSendableTokensForNetwork;
|
|
52
|
+
exports.recordMatchesSendableToken = aleoSendableTokens.recordMatchesSendableToken;
|
|
53
|
+
exports.DynamicWaasAleoConnector = DynamicWaasAleoConnector.DynamicWaasAleoConnector;
|
|
39
54
|
exports.AleoWalletConnectors = AleoWalletConnectors;
|
package/src/index.d.ts
CHANGED
|
@@ -4,10 +4,15 @@ export { AleoWalletConnector } from './connectors/AleoWalletConnector';
|
|
|
4
4
|
export type { AleoWalletConnectorOpts } from './connectors/AleoWalletConnector';
|
|
5
5
|
export { AleoWalletAdapterConnector } from './connectors/AleoWalletAdapterConnector';
|
|
6
6
|
export type { AleoWalletAdapterConnectorOpts, AleoAdapterFactory, AleoAdapterConstructor, } from './connectors/AleoWalletAdapterConnector';
|
|
7
|
+
export { DynamicWaasAleoConnector, DynamicWaasAleoConnectors, } from './connectors/DynamicWaasAleoConnector';
|
|
8
|
+
export { WaasAleoWalletConnector } from './connectors/WaasAleoWalletConnector';
|
|
7
9
|
export { isAleoWallet } from './wallet/isAleoWallet';
|
|
10
|
+
export { AleoUiTransaction } from './utils/AleoUiTransaction';
|
|
8
11
|
export type { AleoTransaction, AleoTransition } from './types';
|
|
9
12
|
export { ALEO_CHAINS, WalletDecryptPermission, WalletFeatureName, WalletReadyState, } from './types';
|
|
10
13
|
export type { AleoChain, StandardWallet } from './types';
|
|
14
|
+
export { ALEO_CREDITS_PROGRAM, ALEO_TOKEN_REGISTRY_PROGRAM, extractRecordAtomicAmount, getAleoSendableTokensForNetwork, recordMatchesSendableToken, } from './utils/aleoSendableTokens/aleoSendableTokens';
|
|
15
|
+
export type { AleoOwnedRecord, AleoProgramKind, AleoSendableToken, } from './utils/aleoSendableTokens/aleoSendableTokens';
|
|
11
16
|
export declare const AleoWalletConnectors: (props: {
|
|
12
17
|
walletBook: WalletBookSchema;
|
|
13
18
|
aleoNetworks: GenericNetwork[];
|
package/src/index.js
CHANGED
|
@@ -2,15 +2,22 @@
|
|
|
2
2
|
import { assertPackageVersion } from '@dynamic-labs/assert-package-version';
|
|
3
3
|
import { version } from '../package.js';
|
|
4
4
|
import { fetchAleoWalletAdapterConnectors } from './utils/fetchAleoWalletAdapterConnectors/fetchAleoWalletAdapterConnectors.js';
|
|
5
|
+
import { DynamicWaasAleoConnectors } from './connectors/DynamicWaasAleoConnector/index.js';
|
|
6
|
+
export { DynamicWaasAleoConnectors } from './connectors/DynamicWaasAleoConnector/index.js';
|
|
5
7
|
export { AleoWalletConnector } from './connectors/AleoWalletConnector/AleoWalletConnector.js';
|
|
6
8
|
export { AleoWalletAdapterConnector } from './connectors/AleoWalletAdapterConnector/AleoWalletAdapterConnector.js';
|
|
9
|
+
export { WaasAleoWalletConnector } from './connectors/WaasAleoWalletConnector/WaasAleoWalletConnector.js';
|
|
7
10
|
export { isAleoWallet } from './wallet/isAleoWallet/isAleoWallet.js';
|
|
11
|
+
export { AleoUiTransaction } from './utils/AleoUiTransaction/AleoUiTransaction.js';
|
|
8
12
|
export { ALEO_CHAINS, WalletDecryptPermission, WalletFeatureName, WalletReadyState } from '@provablehq/aleo-wallet-standard';
|
|
13
|
+
export { ALEO_CREDITS_PROGRAM, ALEO_TOKEN_REGISTRY_PROGRAM, extractRecordAtomicAmount, getAleoSendableTokensForNetwork, recordMatchesSendableToken } from './utils/aleoSendableTokens/aleoSendableTokens.js';
|
|
14
|
+
export { DynamicWaasAleoConnector } from './connectors/DynamicWaasAleoConnector/DynamicWaasAleoConnector.js';
|
|
9
15
|
|
|
10
16
|
assertPackageVersion('@dynamic-labs/aleo', version);
|
|
11
17
|
const AleoWalletConnectors = (props) => [
|
|
12
18
|
// ...fetchAleoWalletConnectors(props),
|
|
13
19
|
...fetchAleoWalletAdapterConnectors(props),
|
|
20
|
+
...DynamicWaasAleoConnectors(),
|
|
14
21
|
];
|
|
15
22
|
|
|
16
23
|
export { AleoWalletConnectors };
|