@dynamic-labs/aleo 0.0.0 → 4.67.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.
Files changed (31) hide show
  1. package/CHANGELOG.md +6993 -0
  2. package/LICENSE +21 -0
  3. package/_virtual/_tslib.cjs +36 -0
  4. package/_virtual/_tslib.js +32 -0
  5. package/package.cjs +8 -0
  6. package/package.js +4 -0
  7. package/package.json +32 -1
  8. package/src/connectors/AleoWalletAdapterConnector/AleoWalletAdapterConnector.cjs +322 -0
  9. package/src/connectors/AleoWalletAdapterConnector/AleoWalletAdapterConnector.d.ts +59 -0
  10. package/src/connectors/AleoWalletAdapterConnector/AleoWalletAdapterConnector.js +318 -0
  11. package/src/connectors/AleoWalletAdapterConnector/index.d.ts +2 -0
  12. package/src/connectors/AleoWalletConnector/AleoWalletConnector.cjs +219 -0
  13. package/src/connectors/AleoWalletConnector/AleoWalletConnector.d.ts +111 -0
  14. package/src/connectors/AleoWalletConnector/AleoWalletConnector.js +215 -0
  15. package/src/connectors/AleoWalletConnector/index.d.ts +2 -0
  16. package/src/index.cjs +39 -0
  17. package/src/index.d.ts +14 -0
  18. package/src/index.js +16 -0
  19. package/src/types.d.ts +42 -0
  20. package/src/utils/fetchAleoWalletAdapterConnectors/fetchAleoWalletAdapterConnectors.cjs +71 -0
  21. package/src/utils/fetchAleoWalletAdapterConnectors/fetchAleoWalletAdapterConnectors.d.ts +25 -0
  22. package/src/utils/fetchAleoWalletAdapterConnectors/fetchAleoWalletAdapterConnectors.js +66 -0
  23. package/src/utils/fetchAleoWalletAdapterConnectors/index.d.ts +1 -0
  24. package/src/wallet/AleoWallet/AleoWallet.cjs +105 -0
  25. package/src/wallet/AleoWallet/AleoWallet.d.ts +57 -0
  26. package/src/wallet/AleoWallet/AleoWallet.js +101 -0
  27. package/src/wallet/AleoWallet/index.d.ts +1 -0
  28. package/src/wallet/isAleoWallet/index.d.ts +1 -0
  29. package/src/wallet/isAleoWallet/isAleoWallet.cjs +8 -0
  30. package/src/wallet/isAleoWallet/isAleoWallet.d.ts +3 -0
  31. package/src/wallet/isAleoWallet/isAleoWallet.js +4 -0
@@ -0,0 +1,318 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../../_virtual/_tslib.js';
3
+ import { WalletReadyState, WalletDecryptPermission } from '@provablehq/aleo-wallet-standard';
4
+ import { ShieldWalletAdapter } from '@provablehq/aleo-wallet-adaptor-shield';
5
+ import { Network } from '@provablehq/aleo-types';
6
+ import { DynamicError } from '@dynamic-labs/utils';
7
+ import { logger } from '@dynamic-labs/wallet-connector-core';
8
+ import { AleoWalletConnector } from '../AleoWalletConnector/AleoWalletConnector.js';
9
+
10
+ /**
11
+ * Registry mapping wallet overrideKeys to their adapter constructors.
12
+ *
13
+ * Keys must match the wallet book entry key (i.e. the overrideKey).
14
+ * Add new adapter-based wallets here or via registerAdapter() at runtime.
15
+ */
16
+ const adapterRegistry = {
17
+ shield: ShieldWalletAdapter,
18
+ };
19
+ const AleoNetworkToIdMap = {
20
+ [Network.MAINNET]: 0,
21
+ [Network.TESTNET]: 1,
22
+ };
23
+ const getNetworkByChainId = (chainId) => {
24
+ const entry = Object.entries(AleoNetworkToIdMap).find(([, id]) => id === chainId);
25
+ return entry === null || entry === void 0 ? void 0 : entry[0];
26
+ };
27
+ const WALLET_NOT_CONNECTED = 'Wallet not connected';
28
+ const MICROCREDITS_PER_CREDIT = 1000000;
29
+ const fetchPublicBalance = (address, network) => __awaiter(void 0, void 0, void 0, function* () {
30
+ const networkSegment = network === Network.TESTNET ? 'testnet' : 'mainnet';
31
+ const url = `https://api.explorer.provable.com/v1/${networkSegment}/program/credits.aleo/mapping/account/${address}`;
32
+ const response = yield fetch(url);
33
+ if (!response.ok)
34
+ return BigInt(0);
35
+ const text = yield response.text();
36
+ if (!text || text === 'null')
37
+ return BigInt(0);
38
+ const cleaned = text.replace(/u64\.private|u64|[_"]/g, '').trim();
39
+ const value = BigInt(cleaned);
40
+ return value > BigInt(0) ? value : BigInt(0);
41
+ });
42
+ const extractRecordMicrocredits = (record) => {
43
+ var _a, _b;
44
+ if (!record || typeof record !== 'object')
45
+ return BigInt(0);
46
+ const r = record;
47
+ const plaintext = (_a = r.plaintext) !== null && _a !== void 0 ? _a : r.data;
48
+ if (!plaintext || typeof plaintext !== 'object')
49
+ return BigInt(0);
50
+ const pt = plaintext;
51
+ const microcredits = (_b = pt.microcredits) !== null && _b !== void 0 ? _b : pt.microcredits_;
52
+ if (typeof microcredits !== 'string')
53
+ return BigInt(0);
54
+ const value = BigInt(microcredits.replace(/u64\.private|u64|_/g, '').trim());
55
+ return value > BigInt(0) ? value : BigInt(0);
56
+ };
57
+ const fetchPrivateBalance = (adapter) => __awaiter(void 0, void 0, void 0, function* () {
58
+ const records = yield adapter.requestRecords('credits.aleo', true);
59
+ if (!Array.isArray(records))
60
+ return BigInt(0);
61
+ return records.reduce((total, record) => total + extractRecordMicrocredits(record), BigInt(0));
62
+ });
63
+ /**
64
+ * Connector for Aleo wallets that use a direct adapter interface rather than
65
+ * the @provablehq/aleo-wallet-standard StandardWallet feature-map API.
66
+ *
67
+ * Extends AleoWalletConnector so it inherits chain/network wiring and falls
68
+ * back to StandardWallet detection when no adapter is registered.
69
+ *
70
+ * To add a new adapter-based wallet, register its constructor:
71
+ * ```typescript
72
+ * AleoWalletAdapterConnector.registerAdapter('leowallet', LeoWalletAdapter);
73
+ * ```
74
+ */
75
+ class AleoWalletAdapterConnector extends AleoWalletConnector {
76
+ /**
77
+ * Register an adapter constructor for a given wallet key.
78
+ * This is the primary extension point for non-standard wallets.
79
+ */
80
+ static registerAdapter(key, AdapterCtor) {
81
+ adapterRegistry[key] = AdapterCtor;
82
+ }
83
+ /**
84
+ * Instantiate the adapter for this connector's overrideKey.
85
+ * Returns undefined when no constructor is registered (falls back to StandardWallet).
86
+ */
87
+ createAdapter() {
88
+ const AdapterCtor = adapterRegistry[this.overrideKey];
89
+ return AdapterCtor ? new AdapterCtor() : undefined;
90
+ }
91
+ isInstalledOnBrowser() {
92
+ if (!this.adapter) {
93
+ this.adapter = this.createAdapter();
94
+ }
95
+ if (this.adapter) {
96
+ return this.adapter.readyState === WalletReadyState.INSTALLED;
97
+ }
98
+ // No adapter registered — fall back to StandardWallet window detection
99
+ return super.isInstalledOnBrowser();
100
+ }
101
+ supportsNetworkSwitching() {
102
+ return this.aleoNetworks.length > 1;
103
+ }
104
+ switchNetwork(_a) {
105
+ return __awaiter(this, arguments, void 0, function* ({ networkChainId, }) {
106
+ if (!this.adapter) {
107
+ this.adapter = this.createAdapter();
108
+ }
109
+ if (networkChainId === undefined || networkChainId === null)
110
+ return;
111
+ const chainIdNum = Number(networkChainId);
112
+ const isValidNetwork = this.aleoNetworks.some((network) => Number(network.chainId) === chainIdNum);
113
+ if (!isValidNetwork) {
114
+ return;
115
+ }
116
+ const network = getNetworkByChainId(chainIdNum);
117
+ if (network && this.adapter) {
118
+ yield this.adapter.switchNetwork(network);
119
+ this.emit('chainChange', { chain: String(chainIdNum) });
120
+ }
121
+ });
122
+ }
123
+ getNetwork() {
124
+ return __awaiter(this, void 0, void 0, function* () {
125
+ var _a;
126
+ if (!((_a = this.adapter) === null || _a === void 0 ? void 0 : _a.network)) {
127
+ return undefined;
128
+ }
129
+ const id = AleoNetworkToIdMap[this.adapter.network];
130
+ return id !== undefined ? String(id) : undefined;
131
+ });
132
+ }
133
+ connect() {
134
+ const _super = Object.create(null, {
135
+ connect: { get: () => super.connect }
136
+ });
137
+ return __awaiter(this, void 0, void 0, function* () {
138
+ var _a, _b, _c;
139
+ if (!this.adapter) {
140
+ this.adapter = this.createAdapter();
141
+ }
142
+ if (!this.adapter) {
143
+ // No adapter registered — fall back to StandardWallet connect
144
+ return _super.connect.call(this);
145
+ }
146
+ if (this.adapter.connected) {
147
+ return;
148
+ }
149
+ try {
150
+ yield this.adapter.connect(((_a = this.adapter) === null || _a === void 0 ? void 0 : _a.network) ||
151
+ getNetworkByChainId(Number((_c = (_b = this.aleoNetworks[0]) === null || _b === void 0 ? void 0 : _b.chainId) !== null && _c !== void 0 ? _c : -1)) ||
152
+ Network.MAINNET, WalletDecryptPermission.UponRequest);
153
+ }
154
+ catch (error) {
155
+ throw new DynamicError(`Failed to connect to ${this.name}: ${error}`);
156
+ }
157
+ });
158
+ }
159
+ getAddress() {
160
+ const _super = Object.create(null, {
161
+ getAddress: { get: () => super.getAddress }
162
+ });
163
+ return __awaiter(this, void 0, void 0, function* () {
164
+ var _a, _b, _c, _d;
165
+ if (!this.adapter) {
166
+ return _super.getAddress.call(this);
167
+ }
168
+ const { account } = this.adapter;
169
+ if (account === null || account === void 0 ? void 0 : account.address) {
170
+ return account.address;
171
+ }
172
+ const result = yield this.adapter.connect(((_a = this.adapter) === null || _a === void 0 ? void 0 : _a.network) ||
173
+ getNetworkByChainId(Number((_c = (_b = this.aleoNetworks[0]) === null || _b === void 0 ? void 0 : _b.chainId) !== null && _c !== void 0 ? _c : -1)) ||
174
+ Network.MAINNET, WalletDecryptPermission.UponRequest);
175
+ return (_d = result === null || result === void 0 ? void 0 : result.address) !== null && _d !== void 0 ? _d : '';
176
+ });
177
+ }
178
+ getConnectedAccounts() {
179
+ const _super = Object.create(null, {
180
+ getConnectedAccounts: { get: () => super.getConnectedAccounts }
181
+ });
182
+ return __awaiter(this, void 0, void 0, function* () {
183
+ if (!this.adapter) {
184
+ return _super.getConnectedAccounts.call(this);
185
+ }
186
+ const { account } = this.adapter;
187
+ return (account === null || account === void 0 ? void 0 : account.address) ? [account.address] : [];
188
+ });
189
+ }
190
+ signMessage(messageToSign) {
191
+ const _super = Object.create(null, {
192
+ signMessage: { get: () => super.signMessage }
193
+ });
194
+ return __awaiter(this, void 0, void 0, function* () {
195
+ if (!this.adapter) {
196
+ return _super.signMessage.call(this, messageToSign);
197
+ }
198
+ if (!this.adapter.connected) {
199
+ throw new DynamicError(WALLET_NOT_CONNECTED);
200
+ }
201
+ try {
202
+ const messageBytes = new TextEncoder().encode(messageToSign);
203
+ const signatureBytes = yield this.adapter.signMessage(messageBytes);
204
+ return Array.from(signatureBytes, (b) => b.toString(16).padStart(2, '0')).join('');
205
+ }
206
+ catch (error) {
207
+ logger.error(`[${this.name}] Sign message failed:`, error);
208
+ throw new DynamicError(`Failed to sign message: ${error}`);
209
+ }
210
+ });
211
+ }
212
+ getBalance(address) {
213
+ return __awaiter(this, void 0, void 0, function* () {
214
+ var _a, _b;
215
+ if (!this.adapter) {
216
+ return '0';
217
+ }
218
+ if (!this.adapter.connected) {
219
+ yield this.connect();
220
+ }
221
+ const resolvedAddress = address !== null && address !== void 0 ? address : (_a = this.adapter.account) === null || _a === void 0 ? void 0 : _a.address;
222
+ if (!resolvedAddress) {
223
+ return '0';
224
+ }
225
+ const network = (_b = this.adapter.network) !== null && _b !== void 0 ? _b : Network.MAINNET;
226
+ let totalMicrocredits = BigInt(0);
227
+ try {
228
+ totalMicrocredits += yield fetchPublicBalance(resolvedAddress, network);
229
+ }
230
+ catch (error) {
231
+ logger.debug(`[${this.name}] Failed to fetch public balance:`, error);
232
+ }
233
+ try {
234
+ totalMicrocredits += yield fetchPrivateBalance(this.adapter);
235
+ }
236
+ catch (error) {
237
+ logger.debug(`[${this.name}] Failed to fetch private records:`, error);
238
+ }
239
+ return (Number(totalMicrocredits) / MICROCREDITS_PER_CREDIT).toFixed(6);
240
+ });
241
+ }
242
+ requestTransaction(transaction) {
243
+ const _super = Object.create(null, {
244
+ requestTransaction: { get: () => super.requestTransaction }
245
+ });
246
+ return __awaiter(this, void 0, void 0, function* () {
247
+ if (!this.adapter) {
248
+ return _super.requestTransaction.call(this, transaction);
249
+ }
250
+ if (!this.adapter.connected) {
251
+ throw new DynamicError(WALLET_NOT_CONNECTED);
252
+ }
253
+ const [transition] = transaction.transitions;
254
+ if (!transition) {
255
+ throw new DynamicError('Transaction must have at least one transition');
256
+ }
257
+ const options = {
258
+ fee: transaction.fee,
259
+ function: transition.functionName,
260
+ inputs: transition.inputs,
261
+ privateFee: transaction.feePrivate,
262
+ program: transition.program,
263
+ };
264
+ const { transactionId } = yield this.adapter.executeTransaction(options);
265
+ return transactionId;
266
+ });
267
+ }
268
+ decrypt(ciphertext, options) {
269
+ const _super = Object.create(null, {
270
+ decrypt: { get: () => super.decrypt }
271
+ });
272
+ return __awaiter(this, void 0, void 0, function* () {
273
+ if (!this.adapter) {
274
+ return _super.decrypt.call(this, ciphertext, options);
275
+ }
276
+ if (!this.adapter.connected) {
277
+ throw new DynamicError(WALLET_NOT_CONNECTED);
278
+ }
279
+ return this.adapter.decrypt(ciphertext, options === null || options === void 0 ? void 0 : options.tpk, options === null || options === void 0 ? void 0 : options.programId, options === null || options === void 0 ? void 0 : options.functionName, options === null || options === void 0 ? void 0 : options.index);
280
+ });
281
+ }
282
+ requestRecords(program, options) {
283
+ const _super = Object.create(null, {
284
+ requestRecords: { get: () => super.requestRecords }
285
+ });
286
+ return __awaiter(this, void 0, void 0, function* () {
287
+ var _a;
288
+ if (!this.adapter) {
289
+ return _super.requestRecords.call(this, program, options);
290
+ }
291
+ if (!this.adapter.connected) {
292
+ throw new DynamicError(WALLET_NOT_CONNECTED);
293
+ }
294
+ return this.adapter.requestRecords(program, (_a = options === null || options === void 0 ? void 0 : options.plaintext) !== null && _a !== void 0 ? _a : false);
295
+ });
296
+ }
297
+ endSession() {
298
+ const _super = Object.create(null, {
299
+ endSession: { get: () => super.endSession }
300
+ });
301
+ return __awaiter(this, void 0, void 0, function* () {
302
+ if (!this.adapter) {
303
+ return _super.endSession.call(this);
304
+ }
305
+ if (this.adapter.connected) {
306
+ try {
307
+ yield this.adapter.disconnect();
308
+ }
309
+ catch (error) {
310
+ logger.debug(`[${this.name}] Error during disconnect:`, error);
311
+ }
312
+ }
313
+ this.adapter = undefined;
314
+ });
315
+ }
316
+ }
317
+
318
+ export { AleoWalletAdapterConnector };
@@ -0,0 +1,2 @@
1
+ export { AleoWalletAdapterConnector } from './AleoWalletAdapterConnector';
2
+ export type { AleoWalletAdapterConnectorOpts, AleoAdapterFactory, AleoAdapterConstructor, } from './AleoWalletAdapterConnector';
@@ -0,0 +1,219 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../../_virtual/_tslib.cjs');
7
+ var aleoWalletStandard = require('@provablehq/aleo-wallet-standard');
8
+ var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
9
+ var utils = require('@dynamic-labs/utils');
10
+ var AleoWallet = require('../../wallet/AleoWallet/AleoWallet.cjs');
11
+
12
+ const WALLET_NOT_CONNECTED = 'Wallet not connected';
13
+ const NetworkIdToAleoChain = {
14
+ 0: aleoWalletStandard.ALEO_CHAINS.MAINNET,
15
+ 1: aleoWalletStandard.ALEO_CHAINS.TESTNET,
16
+ };
17
+ const isTypedStandardWallet = (value) => typeof value === 'object' &&
18
+ value !== null &&
19
+ 'features' in value &&
20
+ typeof value.features === 'object';
21
+ class AleoWalletConnector extends walletConnectorCore.WalletConnectorBase {
22
+ constructor(opts) {
23
+ var _a;
24
+ super(opts);
25
+ this.ChainWallet = AleoWallet.AleoWallet;
26
+ this.name = 'Aleo Wallet';
27
+ this.overrideKey = 'aleowallet';
28
+ this.connectedChain = 'ALEO';
29
+ this.supportedChains = ['ALEO'];
30
+ this.switchNetworkOnlyFromWallet = true;
31
+ this.aleoNetworks = opts.aleoNetworks;
32
+ this.overrideKey = (_a = opts.overrideKey) !== null && _a !== void 0 ? _a : 'aleowallet';
33
+ this.windowKey = opts.windowKey;
34
+ }
35
+ /**
36
+ * Retrieves the StandardWallet instance from the window object.
37
+ * Caches the result after first successful lookup.
38
+ */
39
+ getStandardWallet() {
40
+ if (this.standardWallet) {
41
+ return this.standardWallet;
42
+ }
43
+ if (typeof window === 'undefined') {
44
+ return undefined;
45
+ }
46
+ const wallet = window[this.windowKey];
47
+ if (isTypedStandardWallet(wallet)) {
48
+ this.standardWallet = wallet;
49
+ }
50
+ return this.standardWallet;
51
+ }
52
+ isInstalledOnBrowser() {
53
+ if (this.isInstalledCache !== undefined) {
54
+ return this.isInstalledCache;
55
+ }
56
+ this.isInstalledCache = Boolean(this.getStandardWallet());
57
+ return this.isInstalledCache;
58
+ }
59
+ connect() {
60
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
61
+ var _a, _b;
62
+ const wallet = this.getStandardWallet();
63
+ if (!wallet) {
64
+ throw new utils.DynamicError(`${this.name} is not installed`);
65
+ }
66
+ const connectFeature = wallet.features[aleoWalletStandard.WalletFeatureName.CONNECT];
67
+ if (!(connectFeature === null || connectFeature === void 0 ? void 0 : connectFeature.available)) {
68
+ throw new utils.DynamicError(`${this.name} does not support connect`);
69
+ }
70
+ const networkId = (_a = this.aleoNetworks[0]) === null || _a === void 0 ? void 0 : _a.networkId;
71
+ const chain = (_b = NetworkIdToAleoChain[String(networkId)]) !== null && _b !== void 0 ? _b : aleoWalletStandard.ALEO_CHAINS.MAINNET;
72
+ try {
73
+ yield connectFeature.connect(aleoWalletStandard.WalletDecryptPermission.UponRequest, chain);
74
+ }
75
+ catch (error) {
76
+ throw new utils.DynamicError(`Failed to connect to ${this.name}: ${error}`);
77
+ }
78
+ const accountsFeature = wallet.features[aleoWalletStandard.WalletFeatureName.ACCOUNTS];
79
+ if (accountsFeature === null || accountsFeature === void 0 ? void 0 : accountsFeature.available) {
80
+ const accounts = yield accountsFeature.getAccounts();
81
+ [this.publicKey] = accounts;
82
+ }
83
+ });
84
+ }
85
+ getAddress() {
86
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
87
+ if (this.publicKey) {
88
+ return this.publicKey;
89
+ }
90
+ const wallet = this.getStandardWallet();
91
+ if (!wallet) {
92
+ return undefined;
93
+ }
94
+ const accountsFeature = wallet.features[aleoWalletStandard.WalletFeatureName.ACCOUNTS];
95
+ if (!(accountsFeature === null || accountsFeature === void 0 ? void 0 : accountsFeature.available)) {
96
+ return undefined;
97
+ }
98
+ const accounts = yield accountsFeature.getAccounts();
99
+ [this.publicKey] = accounts;
100
+ return this.publicKey;
101
+ });
102
+ }
103
+ getConnectedAccounts() {
104
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
105
+ const wallet = this.getStandardWallet();
106
+ if (!wallet) {
107
+ return [];
108
+ }
109
+ const accountsFeature = wallet.features[aleoWalletStandard.WalletFeatureName.ACCOUNTS];
110
+ if (!(accountsFeature === null || accountsFeature === void 0 ? void 0 : accountsFeature.available)) {
111
+ return [];
112
+ }
113
+ return accountsFeature.getAccounts();
114
+ });
115
+ }
116
+ getNetwork() {
117
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
118
+ var _a;
119
+ const wallet = this.getStandardWallet();
120
+ if (!wallet) {
121
+ return aleoWalletStandard.ALEO_CHAINS.MAINNET;
122
+ }
123
+ const chainFeature = wallet.features[aleoWalletStandard.WalletFeatureName.CHAINS];
124
+ if (!(chainFeature === null || chainFeature === void 0 ? void 0 : chainFeature.available)) {
125
+ return aleoWalletStandard.ALEO_CHAINS.MAINNET;
126
+ }
127
+ try {
128
+ const chains = yield chainFeature.getChains();
129
+ return (_a = chains[0]) !== null && _a !== void 0 ? _a : aleoWalletStandard.ALEO_CHAINS.MAINNET;
130
+ }
131
+ catch (_b) {
132
+ return aleoWalletStandard.ALEO_CHAINS.MAINNET;
133
+ }
134
+ });
135
+ }
136
+ signMessage(messageToSign) {
137
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
138
+ const wallet = this.getStandardWallet();
139
+ if (!wallet) {
140
+ throw new utils.DynamicError(WALLET_NOT_CONNECTED);
141
+ }
142
+ const signFeature = wallet.features[aleoWalletStandard.WalletFeatureName.SIGN];
143
+ if (!(signFeature === null || signFeature === void 0 ? void 0 : signFeature.available)) {
144
+ throw new utils.DynamicError(`${this.name} does not support message signing`);
145
+ }
146
+ try {
147
+ return yield signFeature.signMessage(messageToSign);
148
+ }
149
+ catch (error) {
150
+ walletConnectorCore.logger.error(`[${this.name}] Sign message failed:`, error);
151
+ throw new utils.DynamicError(`Failed to sign message: ${error}`);
152
+ }
153
+ });
154
+ }
155
+ requestTransaction(transaction) {
156
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
157
+ const wallet = this.getStandardWallet();
158
+ if (!wallet) {
159
+ throw new utils.DynamicError(WALLET_NOT_CONNECTED);
160
+ }
161
+ const executeFeature = wallet.features[aleoWalletStandard.WalletFeatureName.EXECUTE];
162
+ if (!(executeFeature === null || executeFeature === void 0 ? void 0 : executeFeature.available)) {
163
+ throw new utils.DynamicError(`${this.name} does not support transaction execution`);
164
+ }
165
+ return executeFeature.requestTransaction(transaction);
166
+ });
167
+ }
168
+ decrypt(ciphertext, options) {
169
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
170
+ const wallet = this.getStandardWallet();
171
+ if (!wallet) {
172
+ throw new utils.DynamicError(WALLET_NOT_CONNECTED);
173
+ }
174
+ const decryptFeature = wallet.features[aleoWalletStandard.WalletFeatureName.DECRYPT];
175
+ if (!(decryptFeature === null || decryptFeature === void 0 ? void 0 : decryptFeature.available)) {
176
+ throw new utils.DynamicError(`${this.name} does not support decryption`);
177
+ }
178
+ return decryptFeature.decrypt(ciphertext, options);
179
+ });
180
+ }
181
+ requestRecords(program, options) {
182
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
183
+ const wallet = this.getStandardWallet();
184
+ if (!wallet) {
185
+ throw new utils.DynamicError(WALLET_NOT_CONNECTED);
186
+ }
187
+ const recordsFeature = wallet.features[aleoWalletStandard.WalletFeatureName.REQUEST_RECORDS];
188
+ if (!(recordsFeature === null || recordsFeature === void 0 ? void 0 : recordsFeature.available)) {
189
+ throw new utils.DynamicError(`${this.name} does not support record requests`);
190
+ }
191
+ return recordsFeature.requestRecords(program, options);
192
+ });
193
+ }
194
+ getEnabledNetworks() {
195
+ return this.aleoNetworks;
196
+ }
197
+ endSession() {
198
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
199
+ const wallet = this.getStandardWallet();
200
+ if (!wallet) {
201
+ return;
202
+ }
203
+ const connectFeature = wallet.features[aleoWalletStandard.WalletFeatureName.CONNECT];
204
+ if (connectFeature === null || connectFeature === void 0 ? void 0 : connectFeature.available) {
205
+ try {
206
+ yield connectFeature.disconnect();
207
+ }
208
+ catch (error) {
209
+ walletConnectorCore.logger.debug(`[${this.name}] Error during disconnect:`, error);
210
+ }
211
+ }
212
+ this.publicKey = undefined;
213
+ this.standardWallet = undefined;
214
+ this.isInstalledCache = undefined;
215
+ });
216
+ }
217
+ }
218
+
219
+ exports.AleoWalletConnector = AleoWalletConnector;
@@ -0,0 +1,111 @@
1
+ import { WalletFeatureName, WalletDecryptPermission, type AleoChain, type StandardWallet } from '@provablehq/aleo-wallet-standard';
2
+ import { Chain, WalletConnectorBase, WalletMetadata } from '@dynamic-labs/wallet-connector-core';
3
+ import type { WalletBookSchema } from '@dynamic-labs/wallet-book';
4
+ import type { GenericNetwork } from '@dynamic-labs/types';
5
+ import { AleoWallet } from '../../wallet/AleoWallet';
6
+ import type { AleoTransaction } from '../../types';
7
+ /**
8
+ * Feature-specific types for type-safe access to StandardWallet features
9
+ */
10
+ type ConnectFeatureDetails = {
11
+ available: boolean;
12
+ connect(decryptPermission: WalletDecryptPermission, network: AleoChain, programs?: string[]): Promise<void>;
13
+ disconnect(): Promise<void>;
14
+ };
15
+ type AccountsFeatureDetails = {
16
+ available: boolean;
17
+ getAccounts(): Promise<string[]>;
18
+ };
19
+ type SignFeatureDetails = {
20
+ available: boolean;
21
+ signMessage(message: string): Promise<string>;
22
+ };
23
+ type ExecuteFeatureDetails = {
24
+ available: boolean;
25
+ requestTransaction(transaction: AleoTransaction): Promise<string>;
26
+ };
27
+ type ChainFeatureDetails = {
28
+ available: boolean;
29
+ getChains(): Promise<AleoChain[]>;
30
+ };
31
+ type SwitchNetworkFeatureDetails = {
32
+ available: boolean;
33
+ switchNetwork(network: AleoChain): Promise<void>;
34
+ };
35
+ type DecryptFeatureDetails = {
36
+ available: boolean;
37
+ decrypt(ciphertext: string, options?: {
38
+ tpk?: string;
39
+ programId?: string;
40
+ functionName?: string;
41
+ index?: number;
42
+ }): Promise<string>;
43
+ };
44
+ type RequestRecordsFeatureDetails = {
45
+ available: boolean;
46
+ requestRecords(program: string, options?: {
47
+ plaintext?: boolean;
48
+ }): Promise<unknown[]>;
49
+ };
50
+ type TypedStandardWallet = Omit<StandardWallet, 'features'> & {
51
+ features: {
52
+ [WalletFeatureName.CONNECT]?: ConnectFeatureDetails;
53
+ [WalletFeatureName.ACCOUNTS]?: AccountsFeatureDetails;
54
+ [WalletFeatureName.SIGN]?: SignFeatureDetails;
55
+ [WalletFeatureName.EXECUTE]?: ExecuteFeatureDetails;
56
+ [WalletFeatureName.CHAINS]?: ChainFeatureDetails;
57
+ [WalletFeatureName.SWITCH_NETWORK]?: SwitchNetworkFeatureDetails;
58
+ [WalletFeatureName.DECRYPT]?: DecryptFeatureDetails;
59
+ [WalletFeatureName.REQUEST_RECORDS]?: RequestRecordsFeatureDetails;
60
+ };
61
+ };
62
+ export type AleoWalletConnectorOpts = {
63
+ walletBook: WalletBookSchema;
64
+ aleoNetworks: GenericNetwork[];
65
+ metadata?: WalletMetadata;
66
+ overrideKey?: string;
67
+ walletData?: WalletBookSchema['wallets'][string];
68
+ /**
69
+ * The key on window where the wallet injects itself (e.g. 'shield')
70
+ * Comes from the wallet book injectedConfig.walletStandard.providerId
71
+ */
72
+ windowKey: string;
73
+ };
74
+ export declare abstract class AleoWalletConnector extends WalletConnectorBase<typeof AleoWallet> {
75
+ ChainWallet: typeof AleoWallet;
76
+ name: string;
77
+ overrideKey: string;
78
+ connectedChain: Chain;
79
+ supportedChains: Chain[];
80
+ switchNetworkOnlyFromWallet: boolean;
81
+ protected aleoNetworks: GenericNetwork[];
82
+ protected windowKey: string;
83
+ private standardWallet;
84
+ private publicKey;
85
+ private isInstalledCache;
86
+ constructor(opts: AleoWalletConnectorOpts);
87
+ /**
88
+ * Retrieves the StandardWallet instance from the window object.
89
+ * Caches the result after first successful lookup.
90
+ */
91
+ getStandardWallet(): TypedStandardWallet | undefined;
92
+ isInstalledOnBrowser(): boolean;
93
+ connect(): Promise<void>;
94
+ getAddress(): Promise<string | undefined>;
95
+ getConnectedAccounts(): Promise<string[]>;
96
+ getNetwork(): Promise<string | undefined>;
97
+ signMessage(messageToSign: string): Promise<string>;
98
+ requestTransaction(transaction: AleoTransaction): Promise<string>;
99
+ decrypt(ciphertext: string, options?: {
100
+ tpk?: string;
101
+ programId?: string;
102
+ functionName?: string;
103
+ index?: number;
104
+ }): Promise<string>;
105
+ requestRecords(program: string, options?: {
106
+ plaintext?: boolean;
107
+ }): Promise<unknown[]>;
108
+ getEnabledNetworks(): GenericNetwork[];
109
+ endSession(): Promise<void>;
110
+ }
111
+ export {};