@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.
- package/CHANGELOG.md +6993 -0
- package/LICENSE +21 -0
- package/_virtual/_tslib.cjs +36 -0
- package/_virtual/_tslib.js +32 -0
- package/package.cjs +8 -0
- package/package.js +4 -0
- package/package.json +32 -1
- package/src/connectors/AleoWalletAdapterConnector/AleoWalletAdapterConnector.cjs +322 -0
- package/src/connectors/AleoWalletAdapterConnector/AleoWalletAdapterConnector.d.ts +59 -0
- package/src/connectors/AleoWalletAdapterConnector/AleoWalletAdapterConnector.js +318 -0
- package/src/connectors/AleoWalletAdapterConnector/index.d.ts +2 -0
- package/src/connectors/AleoWalletConnector/AleoWalletConnector.cjs +219 -0
- package/src/connectors/AleoWalletConnector/AleoWalletConnector.d.ts +111 -0
- package/src/connectors/AleoWalletConnector/AleoWalletConnector.js +215 -0
- package/src/connectors/AleoWalletConnector/index.d.ts +2 -0
- package/src/index.cjs +39 -0
- package/src/index.d.ts +14 -0
- package/src/index.js +16 -0
- package/src/types.d.ts +42 -0
- package/src/utils/fetchAleoWalletAdapterConnectors/fetchAleoWalletAdapterConnectors.cjs +71 -0
- package/src/utils/fetchAleoWalletAdapterConnectors/fetchAleoWalletAdapterConnectors.d.ts +25 -0
- package/src/utils/fetchAleoWalletAdapterConnectors/fetchAleoWalletAdapterConnectors.js +66 -0
- package/src/utils/fetchAleoWalletAdapterConnectors/index.d.ts +1 -0
- package/src/wallet/AleoWallet/AleoWallet.cjs +105 -0
- package/src/wallet/AleoWallet/AleoWallet.d.ts +57 -0
- package/src/wallet/AleoWallet/AleoWallet.js +101 -0
- package/src/wallet/AleoWallet/index.d.ts +1 -0
- package/src/wallet/isAleoWallet/index.d.ts +1 -0
- package/src/wallet/isAleoWallet/isAleoWallet.cjs +8 -0
- package/src/wallet/isAleoWallet/isAleoWallet.d.ts +3 -0
- package/src/wallet/isAleoWallet/isAleoWallet.js +4 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
+
import { ALEO_CHAINS, WalletFeatureName, WalletDecryptPermission } from '@provablehq/aleo-wallet-standard';
|
|
4
|
+
import { WalletConnectorBase, logger } from '@dynamic-labs/wallet-connector-core';
|
|
5
|
+
import { DynamicError } from '@dynamic-labs/utils';
|
|
6
|
+
import { AleoWallet } from '../../wallet/AleoWallet/AleoWallet.js';
|
|
7
|
+
|
|
8
|
+
const WALLET_NOT_CONNECTED = 'Wallet not connected';
|
|
9
|
+
const NetworkIdToAleoChain = {
|
|
10
|
+
0: ALEO_CHAINS.MAINNET,
|
|
11
|
+
1: ALEO_CHAINS.TESTNET,
|
|
12
|
+
};
|
|
13
|
+
const isTypedStandardWallet = (value) => typeof value === 'object' &&
|
|
14
|
+
value !== null &&
|
|
15
|
+
'features' in value &&
|
|
16
|
+
typeof value.features === 'object';
|
|
17
|
+
class AleoWalletConnector extends WalletConnectorBase {
|
|
18
|
+
constructor(opts) {
|
|
19
|
+
var _a;
|
|
20
|
+
super(opts);
|
|
21
|
+
this.ChainWallet = AleoWallet;
|
|
22
|
+
this.name = 'Aleo Wallet';
|
|
23
|
+
this.overrideKey = 'aleowallet';
|
|
24
|
+
this.connectedChain = 'ALEO';
|
|
25
|
+
this.supportedChains = ['ALEO'];
|
|
26
|
+
this.switchNetworkOnlyFromWallet = true;
|
|
27
|
+
this.aleoNetworks = opts.aleoNetworks;
|
|
28
|
+
this.overrideKey = (_a = opts.overrideKey) !== null && _a !== void 0 ? _a : 'aleowallet';
|
|
29
|
+
this.windowKey = opts.windowKey;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Retrieves the StandardWallet instance from the window object.
|
|
33
|
+
* Caches the result after first successful lookup.
|
|
34
|
+
*/
|
|
35
|
+
getStandardWallet() {
|
|
36
|
+
if (this.standardWallet) {
|
|
37
|
+
return this.standardWallet;
|
|
38
|
+
}
|
|
39
|
+
if (typeof window === 'undefined') {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
const wallet = window[this.windowKey];
|
|
43
|
+
if (isTypedStandardWallet(wallet)) {
|
|
44
|
+
this.standardWallet = wallet;
|
|
45
|
+
}
|
|
46
|
+
return this.standardWallet;
|
|
47
|
+
}
|
|
48
|
+
isInstalledOnBrowser() {
|
|
49
|
+
if (this.isInstalledCache !== undefined) {
|
|
50
|
+
return this.isInstalledCache;
|
|
51
|
+
}
|
|
52
|
+
this.isInstalledCache = Boolean(this.getStandardWallet());
|
|
53
|
+
return this.isInstalledCache;
|
|
54
|
+
}
|
|
55
|
+
connect() {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
var _a, _b;
|
|
58
|
+
const wallet = this.getStandardWallet();
|
|
59
|
+
if (!wallet) {
|
|
60
|
+
throw new DynamicError(`${this.name} is not installed`);
|
|
61
|
+
}
|
|
62
|
+
const connectFeature = wallet.features[WalletFeatureName.CONNECT];
|
|
63
|
+
if (!(connectFeature === null || connectFeature === void 0 ? void 0 : connectFeature.available)) {
|
|
64
|
+
throw new DynamicError(`${this.name} does not support connect`);
|
|
65
|
+
}
|
|
66
|
+
const networkId = (_a = this.aleoNetworks[0]) === null || _a === void 0 ? void 0 : _a.networkId;
|
|
67
|
+
const chain = (_b = NetworkIdToAleoChain[String(networkId)]) !== null && _b !== void 0 ? _b : ALEO_CHAINS.MAINNET;
|
|
68
|
+
try {
|
|
69
|
+
yield connectFeature.connect(WalletDecryptPermission.UponRequest, chain);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
throw new DynamicError(`Failed to connect to ${this.name}: ${error}`);
|
|
73
|
+
}
|
|
74
|
+
const accountsFeature = wallet.features[WalletFeatureName.ACCOUNTS];
|
|
75
|
+
if (accountsFeature === null || accountsFeature === void 0 ? void 0 : accountsFeature.available) {
|
|
76
|
+
const accounts = yield accountsFeature.getAccounts();
|
|
77
|
+
[this.publicKey] = accounts;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
getAddress() {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
if (this.publicKey) {
|
|
84
|
+
return this.publicKey;
|
|
85
|
+
}
|
|
86
|
+
const wallet = this.getStandardWallet();
|
|
87
|
+
if (!wallet) {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
const accountsFeature = wallet.features[WalletFeatureName.ACCOUNTS];
|
|
91
|
+
if (!(accountsFeature === null || accountsFeature === void 0 ? void 0 : accountsFeature.available)) {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
const accounts = yield accountsFeature.getAccounts();
|
|
95
|
+
[this.publicKey] = accounts;
|
|
96
|
+
return this.publicKey;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
getConnectedAccounts() {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
const wallet = this.getStandardWallet();
|
|
102
|
+
if (!wallet) {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
const accountsFeature = wallet.features[WalletFeatureName.ACCOUNTS];
|
|
106
|
+
if (!(accountsFeature === null || accountsFeature === void 0 ? void 0 : accountsFeature.available)) {
|
|
107
|
+
return [];
|
|
108
|
+
}
|
|
109
|
+
return accountsFeature.getAccounts();
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
getNetwork() {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
var _a;
|
|
115
|
+
const wallet = this.getStandardWallet();
|
|
116
|
+
if (!wallet) {
|
|
117
|
+
return ALEO_CHAINS.MAINNET;
|
|
118
|
+
}
|
|
119
|
+
const chainFeature = wallet.features[WalletFeatureName.CHAINS];
|
|
120
|
+
if (!(chainFeature === null || chainFeature === void 0 ? void 0 : chainFeature.available)) {
|
|
121
|
+
return ALEO_CHAINS.MAINNET;
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
const chains = yield chainFeature.getChains();
|
|
125
|
+
return (_a = chains[0]) !== null && _a !== void 0 ? _a : ALEO_CHAINS.MAINNET;
|
|
126
|
+
}
|
|
127
|
+
catch (_b) {
|
|
128
|
+
return ALEO_CHAINS.MAINNET;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
signMessage(messageToSign) {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
const wallet = this.getStandardWallet();
|
|
135
|
+
if (!wallet) {
|
|
136
|
+
throw new DynamicError(WALLET_NOT_CONNECTED);
|
|
137
|
+
}
|
|
138
|
+
const signFeature = wallet.features[WalletFeatureName.SIGN];
|
|
139
|
+
if (!(signFeature === null || signFeature === void 0 ? void 0 : signFeature.available)) {
|
|
140
|
+
throw new DynamicError(`${this.name} does not support message signing`);
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
return yield signFeature.signMessage(messageToSign);
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
logger.error(`[${this.name}] Sign message failed:`, error);
|
|
147
|
+
throw new DynamicError(`Failed to sign message: ${error}`);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
requestTransaction(transaction) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
const wallet = this.getStandardWallet();
|
|
154
|
+
if (!wallet) {
|
|
155
|
+
throw new DynamicError(WALLET_NOT_CONNECTED);
|
|
156
|
+
}
|
|
157
|
+
const executeFeature = wallet.features[WalletFeatureName.EXECUTE];
|
|
158
|
+
if (!(executeFeature === null || executeFeature === void 0 ? void 0 : executeFeature.available)) {
|
|
159
|
+
throw new DynamicError(`${this.name} does not support transaction execution`);
|
|
160
|
+
}
|
|
161
|
+
return executeFeature.requestTransaction(transaction);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
decrypt(ciphertext, options) {
|
|
165
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
166
|
+
const wallet = this.getStandardWallet();
|
|
167
|
+
if (!wallet) {
|
|
168
|
+
throw new DynamicError(WALLET_NOT_CONNECTED);
|
|
169
|
+
}
|
|
170
|
+
const decryptFeature = wallet.features[WalletFeatureName.DECRYPT];
|
|
171
|
+
if (!(decryptFeature === null || decryptFeature === void 0 ? void 0 : decryptFeature.available)) {
|
|
172
|
+
throw new DynamicError(`${this.name} does not support decryption`);
|
|
173
|
+
}
|
|
174
|
+
return decryptFeature.decrypt(ciphertext, options);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
requestRecords(program, options) {
|
|
178
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
179
|
+
const wallet = this.getStandardWallet();
|
|
180
|
+
if (!wallet) {
|
|
181
|
+
throw new DynamicError(WALLET_NOT_CONNECTED);
|
|
182
|
+
}
|
|
183
|
+
const recordsFeature = wallet.features[WalletFeatureName.REQUEST_RECORDS];
|
|
184
|
+
if (!(recordsFeature === null || recordsFeature === void 0 ? void 0 : recordsFeature.available)) {
|
|
185
|
+
throw new DynamicError(`${this.name} does not support record requests`);
|
|
186
|
+
}
|
|
187
|
+
return recordsFeature.requestRecords(program, options);
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
getEnabledNetworks() {
|
|
191
|
+
return this.aleoNetworks;
|
|
192
|
+
}
|
|
193
|
+
endSession() {
|
|
194
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
195
|
+
const wallet = this.getStandardWallet();
|
|
196
|
+
if (!wallet) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const connectFeature = wallet.features[WalletFeatureName.CONNECT];
|
|
200
|
+
if (connectFeature === null || connectFeature === void 0 ? void 0 : connectFeature.available) {
|
|
201
|
+
try {
|
|
202
|
+
yield connectFeature.disconnect();
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
logger.debug(`[${this.name}] Error during disconnect:`, error);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
this.publicKey = undefined;
|
|
209
|
+
this.standardWallet = undefined;
|
|
210
|
+
this.isInstalledCache = undefined;
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export { AleoWalletConnector };
|
package/src/index.cjs
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var assertPackageVersion = require('@dynamic-labs/assert-package-version');
|
|
7
|
+
var _package = require('../package.cjs');
|
|
8
|
+
var fetchAleoWalletAdapterConnectors = require('./utils/fetchAleoWalletAdapterConnectors/fetchAleoWalletAdapterConnectors.cjs');
|
|
9
|
+
var AleoWalletConnector = require('./connectors/AleoWalletConnector/AleoWalletConnector.cjs');
|
|
10
|
+
var AleoWalletAdapterConnector = require('./connectors/AleoWalletAdapterConnector/AleoWalletAdapterConnector.cjs');
|
|
11
|
+
var isAleoWallet = require('./wallet/isAleoWallet/isAleoWallet.cjs');
|
|
12
|
+
var aleoWalletStandard = require('@provablehq/aleo-wallet-standard');
|
|
13
|
+
|
|
14
|
+
assertPackageVersion.assertPackageVersion('@dynamic-labs/aleo', _package.version);
|
|
15
|
+
const AleoWalletConnectors = (props) => [
|
|
16
|
+
// ...fetchAleoWalletConnectors(props),
|
|
17
|
+
...fetchAleoWalletAdapterConnectors.fetchAleoWalletAdapterConnectors(props),
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
exports.AleoWalletConnector = AleoWalletConnector.AleoWalletConnector;
|
|
21
|
+
exports.AleoWalletAdapterConnector = AleoWalletAdapterConnector.AleoWalletAdapterConnector;
|
|
22
|
+
exports.isAleoWallet = isAleoWallet.isAleoWallet;
|
|
23
|
+
Object.defineProperty(exports, 'ALEO_CHAINS', {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () { return aleoWalletStandard.ALEO_CHAINS; }
|
|
26
|
+
});
|
|
27
|
+
Object.defineProperty(exports, 'WalletDecryptPermission', {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () { return aleoWalletStandard.WalletDecryptPermission; }
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, 'WalletFeatureName', {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () { return aleoWalletStandard.WalletFeatureName; }
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(exports, 'WalletReadyState', {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
get: function () { return aleoWalletStandard.WalletReadyState; }
|
|
38
|
+
});
|
|
39
|
+
exports.AleoWalletConnectors = AleoWalletConnectors;
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { GenericNetwork } from '@dynamic-labs/types';
|
|
2
|
+
import type { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
3
|
+
export { AleoWalletConnector } from './connectors/AleoWalletConnector';
|
|
4
|
+
export type { AleoWalletConnectorOpts } from './connectors/AleoWalletConnector';
|
|
5
|
+
export { AleoWalletAdapterConnector } from './connectors/AleoWalletAdapterConnector';
|
|
6
|
+
export type { AleoWalletAdapterConnectorOpts, AleoAdapterFactory, AleoAdapterConstructor, } from './connectors/AleoWalletAdapterConnector';
|
|
7
|
+
export { isAleoWallet } from './wallet/isAleoWallet';
|
|
8
|
+
export type { AleoTransaction, AleoTransition } from './types';
|
|
9
|
+
export { ALEO_CHAINS, WalletDecryptPermission, WalletFeatureName, WalletReadyState, } from './types';
|
|
10
|
+
export type { AleoChain, StandardWallet } from './types';
|
|
11
|
+
export declare const AleoWalletConnectors: (props: {
|
|
12
|
+
walletBook: WalletBookSchema;
|
|
13
|
+
aleoNetworks: GenericNetwork[];
|
|
14
|
+
}) => import("dist/packages/wallet-connector-core/src").WalletConnectorConstructor[];
|
package/src/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { assertPackageVersion } from '@dynamic-labs/assert-package-version';
|
|
3
|
+
import { version } from '../package.js';
|
|
4
|
+
import { fetchAleoWalletAdapterConnectors } from './utils/fetchAleoWalletAdapterConnectors/fetchAleoWalletAdapterConnectors.js';
|
|
5
|
+
export { AleoWalletConnector } from './connectors/AleoWalletConnector/AleoWalletConnector.js';
|
|
6
|
+
export { AleoWalletAdapterConnector } from './connectors/AleoWalletAdapterConnector/AleoWalletAdapterConnector.js';
|
|
7
|
+
export { isAleoWallet } from './wallet/isAleoWallet/isAleoWallet.js';
|
|
8
|
+
export { ALEO_CHAINS, WalletDecryptPermission, WalletFeatureName, WalletReadyState } from '@provablehq/aleo-wallet-standard';
|
|
9
|
+
|
|
10
|
+
assertPackageVersion('@dynamic-labs/aleo', version);
|
|
11
|
+
const AleoWalletConnectors = (props) => [
|
|
12
|
+
// ...fetchAleoWalletConnectors(props),
|
|
13
|
+
...fetchAleoWalletAdapterConnectors(props),
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
export { AleoWalletConnectors };
|
package/src/types.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AleoChain, WalletDecryptPermission, WalletReadyState } from '@provablehq/aleo-wallet-standard';
|
|
2
|
+
export { WalletFeatureName, WalletDecryptPermission, WalletReadyState, ALEO_CHAINS, } from '@provablehq/aleo-wallet-standard';
|
|
3
|
+
export type { AleoChain, StandardWallet, WalletFeatures, WalletAdapter, WalletAdapterProps, WalletEvents, } from '@provablehq/aleo-wallet-standard';
|
|
4
|
+
export type AleoTransition = {
|
|
5
|
+
program: string;
|
|
6
|
+
functionName: string;
|
|
7
|
+
inputs: unknown[];
|
|
8
|
+
};
|
|
9
|
+
export type AleoTransaction = {
|
|
10
|
+
address: string;
|
|
11
|
+
chainId: string;
|
|
12
|
+
transitions: AleoTransition[];
|
|
13
|
+
fee: number;
|
|
14
|
+
feePrivate: boolean;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Minimal interface for non-standard Aleo wallet adapters.
|
|
18
|
+
*
|
|
19
|
+
* Wallets that don't implement the @provablehq/aleo-wallet-standard
|
|
20
|
+
* StandardWallet interface (e.g. Leo, Puzzle, Fox via @demox-labs adapters)
|
|
21
|
+
* can be wrapped by implementing this interface.
|
|
22
|
+
*/
|
|
23
|
+
export type IAleoAdapter = {
|
|
24
|
+
publicKey: string | null | undefined;
|
|
25
|
+
connected: boolean;
|
|
26
|
+
readyState: WalletReadyState | string;
|
|
27
|
+
connect(decryptPermission?: WalletDecryptPermission, network?: AleoChain, programs?: string[]): Promise<{
|
|
28
|
+
address: string;
|
|
29
|
+
}>;
|
|
30
|
+
disconnect(): Promise<void>;
|
|
31
|
+
signMessage(message: string): Promise<string>;
|
|
32
|
+
requestTransaction(transaction: AleoTransaction): Promise<string>;
|
|
33
|
+
decrypt?(ciphertext: string, options?: {
|
|
34
|
+
tpk?: string;
|
|
35
|
+
programId?: string;
|
|
36
|
+
functionName?: string;
|
|
37
|
+
index?: number;
|
|
38
|
+
}): Promise<string>;
|
|
39
|
+
requestRecords?(program: string, options?: {
|
|
40
|
+
plaintext?: boolean;
|
|
41
|
+
}): Promise<unknown[]>;
|
|
42
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var walletBook = require('@dynamic-labs/wallet-book');
|
|
7
|
+
var AleoWalletAdapterConnector = require('../../connectors/AleoWalletAdapterConnector/AleoWalletAdapterConnector.cjs');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Checks whether a wallet book entry targets the non-standard Aleo adapter path.
|
|
11
|
+
*
|
|
12
|
+
* A wallet qualifies if it has an injectedConfig for the 'aleo' chain with the
|
|
13
|
+
* 'aleo-wallet-adapter:' feature flag (distinct from 'aleo-wallet-standard:').
|
|
14
|
+
*/
|
|
15
|
+
const isValidAleoWalletAdapterWallet = (wallet) => {
|
|
16
|
+
var _a;
|
|
17
|
+
return Boolean((_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
return config.chain === 'aleo' &&
|
|
20
|
+
Array.isArray((_a = config.walletStandard) === null || _a === void 0 ? void 0 : _a.features) &&
|
|
21
|
+
config.walletStandard.features.includes('aleo-wallet-adapter:') &&
|
|
22
|
+
((_b = config.walletStandard) === null || _b === void 0 ? void 0 : _b.providerId);
|
|
23
|
+
}));
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Builds a connector constructor for every non-standard Aleo wallet found in
|
|
27
|
+
* the wallet book (those using 'aleo-wallet-adapter:' rather than the
|
|
28
|
+
* StandardWallet feature map).
|
|
29
|
+
*
|
|
30
|
+
* Each constructor is an anonymous AleoWalletAdapterConnector subclass.
|
|
31
|
+
* Connect those wallets by registering their adapter constructors:
|
|
32
|
+
* ```typescript
|
|
33
|
+
* AleoWalletAdapterConnector.registerAdapter('leowallet', LeoWalletAdapter);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
const fetchAleoWalletAdapterConnectors = ({ walletBook: walletBook$1, aleoNetworks, }) => {
|
|
37
|
+
var _a;
|
|
38
|
+
return Object.entries((_a = walletBook$1 === null || walletBook$1 === void 0 ? void 0 : walletBook$1.wallets) !== null && _a !== void 0 ? _a : {})
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
40
|
+
.filter(([_, wallet]) => isValidAleoWalletAdapterWallet(wallet))
|
|
41
|
+
.map(([key, wallet]) => {
|
|
42
|
+
var _a, _b, _c, _d, _e, _f;
|
|
43
|
+
const name = (_b = (_a = wallet.shortName) !== null && _a !== void 0 ? _a : wallet.name) !== null && _b !== void 0 ? _b : key;
|
|
44
|
+
const windowKey = (_f = (_e = (_d = (_c = wallet.injectedConfig) === null || _c === void 0 ? void 0 : _c.find((c) => c.chain === 'aleo')) === null || _d === void 0 ? void 0 : _d.walletStandard) === null || _e === void 0 ? void 0 : _e.providerId) !== null && _f !== void 0 ? _f : key;
|
|
45
|
+
return class extends AleoWalletAdapterConnector.AleoWalletAdapterConnector {
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
|
+
constructor(props) {
|
|
48
|
+
var _a;
|
|
49
|
+
super(Object.assign(Object.assign({}, props), { aleoNetworks, metadata: {
|
|
50
|
+
brandColor: undefined,
|
|
51
|
+
deepLinks: undefined,
|
|
52
|
+
downloadLinks: undefined,
|
|
53
|
+
groupKey: undefined,
|
|
54
|
+
icon: ((_a = wallet === null || wallet === void 0 ? void 0 : wallet.brand) === null || _a === void 0 ? void 0 : _a.spriteId)
|
|
55
|
+
? walletBook.renderTemplate('iconicUrl', wallet.brand.spriteId)
|
|
56
|
+
: '',
|
|
57
|
+
id: key,
|
|
58
|
+
name,
|
|
59
|
+
rdns: undefined,
|
|
60
|
+
supportedHardwareWallets: undefined,
|
|
61
|
+
walletLimitations: undefined,
|
|
62
|
+
}, overrideKey: key, walletData: wallet, windowKey }));
|
|
63
|
+
this.name = name;
|
|
64
|
+
this.overrideKey = key;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
exports.fetchAleoWalletAdapterConnectors = fetchAleoWalletAdapterConnectors;
|
|
71
|
+
exports.isValidAleoWalletAdapterWallet = isValidAleoWalletAdapterWallet;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
2
|
+
import { WalletConnectorConstructor } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
import type { GenericNetwork } from '@dynamic-labs/types';
|
|
4
|
+
/**
|
|
5
|
+
* Checks whether a wallet book entry targets the non-standard Aleo adapter path.
|
|
6
|
+
*
|
|
7
|
+
* A wallet qualifies if it has an injectedConfig for the 'aleo' chain with the
|
|
8
|
+
* 'aleo-wallet-adapter:' feature flag (distinct from 'aleo-wallet-standard:').
|
|
9
|
+
*/
|
|
10
|
+
export declare const isValidAleoWalletAdapterWallet: (wallet: WalletBookSchema['wallets'][string]) => boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Builds a connector constructor for every non-standard Aleo wallet found in
|
|
13
|
+
* the wallet book (those using 'aleo-wallet-adapter:' rather than the
|
|
14
|
+
* StandardWallet feature map).
|
|
15
|
+
*
|
|
16
|
+
* Each constructor is an anonymous AleoWalletAdapterConnector subclass.
|
|
17
|
+
* Connect those wallets by registering their adapter constructors:
|
|
18
|
+
* ```typescript
|
|
19
|
+
* AleoWalletAdapterConnector.registerAdapter('leowallet', LeoWalletAdapter);
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare const fetchAleoWalletAdapterConnectors: ({ walletBook, aleoNetworks, }: {
|
|
23
|
+
walletBook: WalletBookSchema;
|
|
24
|
+
aleoNetworks: GenericNetwork[];
|
|
25
|
+
}) => WalletConnectorConstructor[];
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { renderTemplate } from '@dynamic-labs/wallet-book';
|
|
3
|
+
import { AleoWalletAdapterConnector } from '../../connectors/AleoWalletAdapterConnector/AleoWalletAdapterConnector.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Checks whether a wallet book entry targets the non-standard Aleo adapter path.
|
|
7
|
+
*
|
|
8
|
+
* A wallet qualifies if it has an injectedConfig for the 'aleo' chain with the
|
|
9
|
+
* 'aleo-wallet-adapter:' feature flag (distinct from 'aleo-wallet-standard:').
|
|
10
|
+
*/
|
|
11
|
+
const isValidAleoWalletAdapterWallet = (wallet) => {
|
|
12
|
+
var _a;
|
|
13
|
+
return Boolean((_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => {
|
|
14
|
+
var _a, _b;
|
|
15
|
+
return config.chain === 'aleo' &&
|
|
16
|
+
Array.isArray((_a = config.walletStandard) === null || _a === void 0 ? void 0 : _a.features) &&
|
|
17
|
+
config.walletStandard.features.includes('aleo-wallet-adapter:') &&
|
|
18
|
+
((_b = config.walletStandard) === null || _b === void 0 ? void 0 : _b.providerId);
|
|
19
|
+
}));
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Builds a connector constructor for every non-standard Aleo wallet found in
|
|
23
|
+
* the wallet book (those using 'aleo-wallet-adapter:' rather than the
|
|
24
|
+
* StandardWallet feature map).
|
|
25
|
+
*
|
|
26
|
+
* Each constructor is an anonymous AleoWalletAdapterConnector subclass.
|
|
27
|
+
* Connect those wallets by registering their adapter constructors:
|
|
28
|
+
* ```typescript
|
|
29
|
+
* AleoWalletAdapterConnector.registerAdapter('leowallet', LeoWalletAdapter);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
const fetchAleoWalletAdapterConnectors = ({ walletBook, aleoNetworks, }) => {
|
|
33
|
+
var _a;
|
|
34
|
+
return Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {})
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
36
|
+
.filter(([_, wallet]) => isValidAleoWalletAdapterWallet(wallet))
|
|
37
|
+
.map(([key, wallet]) => {
|
|
38
|
+
var _a, _b, _c, _d, _e, _f;
|
|
39
|
+
const name = (_b = (_a = wallet.shortName) !== null && _a !== void 0 ? _a : wallet.name) !== null && _b !== void 0 ? _b : key;
|
|
40
|
+
const windowKey = (_f = (_e = (_d = (_c = wallet.injectedConfig) === null || _c === void 0 ? void 0 : _c.find((c) => c.chain === 'aleo')) === null || _d === void 0 ? void 0 : _d.walletStandard) === null || _e === void 0 ? void 0 : _e.providerId) !== null && _f !== void 0 ? _f : key;
|
|
41
|
+
return class extends AleoWalletAdapterConnector {
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
+
constructor(props) {
|
|
44
|
+
var _a;
|
|
45
|
+
super(Object.assign(Object.assign({}, props), { aleoNetworks, metadata: {
|
|
46
|
+
brandColor: undefined,
|
|
47
|
+
deepLinks: undefined,
|
|
48
|
+
downloadLinks: undefined,
|
|
49
|
+
groupKey: undefined,
|
|
50
|
+
icon: ((_a = wallet === null || wallet === void 0 ? void 0 : wallet.brand) === null || _a === void 0 ? void 0 : _a.spriteId)
|
|
51
|
+
? renderTemplate('iconicUrl', wallet.brand.spriteId)
|
|
52
|
+
: '',
|
|
53
|
+
id: key,
|
|
54
|
+
name,
|
|
55
|
+
rdns: undefined,
|
|
56
|
+
supportedHardwareWallets: undefined,
|
|
57
|
+
walletLimitations: undefined,
|
|
58
|
+
}, overrideKey: key, walletData: wallet, windowKey }));
|
|
59
|
+
this.name = name;
|
|
60
|
+
this.overrideKey = key;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export { fetchAleoWalletAdapterConnectors, isValidAleoWalletAdapterWallet };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { fetchAleoWalletAdapterConnectors, isValidAleoWalletAdapterWallet, } from './fetchAleoWalletAdapterConnectors';
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
|
+
var utils = require('@dynamic-labs/utils');
|
|
8
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
9
|
+
|
|
10
|
+
class AleoWallet extends walletConnectorCore.Wallet {
|
|
11
|
+
sendBalance(_a) {
|
|
12
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ amount, toAddress, token, }) {
|
|
13
|
+
var _b, _c, _d;
|
|
14
|
+
const chainId = (_b = (yield this._connector.getNetwork())) !== null && _b !== void 0 ? _b : '0';
|
|
15
|
+
const decimals = (_c = token === null || token === void 0 ? void 0 : token.decimals) !== null && _c !== void 0 ? _c : 6;
|
|
16
|
+
const microcredits = BigInt(Math.round(parseFloat(amount) * Math.pow(10, decimals)));
|
|
17
|
+
const program = (_d = token === null || token === void 0 ? void 0 : token.address) !== null && _d !== void 0 ? _d : 'credits.aleo';
|
|
18
|
+
const transaction = {
|
|
19
|
+
address: this.address,
|
|
20
|
+
chainId,
|
|
21
|
+
fee: 50000,
|
|
22
|
+
feePrivate: false,
|
|
23
|
+
transitions: [
|
|
24
|
+
{
|
|
25
|
+
functionName: 'transfer_public',
|
|
26
|
+
inputs: [toAddress, `${microcredits}u64`],
|
|
27
|
+
program,
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
};
|
|
31
|
+
return this._connector.requestTransaction(transaction);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
getBalance() {
|
|
35
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
var _a;
|
|
37
|
+
return (_a = (yield this._connector.getBalance(this.address))) !== null && _a !== void 0 ? _a : '0';
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Returns the Aleo public key for this wallet.
|
|
42
|
+
* In Aleo, the public key and address are the same value.
|
|
43
|
+
*/
|
|
44
|
+
getPublicKey() {
|
|
45
|
+
return this.address;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Returns the current network this wallet is connected to (e.g. 'aleo:mainnet').
|
|
49
|
+
*/
|
|
50
|
+
getNetworkInfo() {
|
|
51
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
return this._connector.getNetwork();
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Signs a message with the Aleo wallet.
|
|
57
|
+
* Accepts both plain strings and Uint8Array (decoded to UTF-8).
|
|
58
|
+
*/
|
|
59
|
+
signMessage(message) {
|
|
60
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
const messageString = typeof message === 'string' ? message : new TextDecoder().decode(message);
|
|
62
|
+
const signature = yield this._connector.signMessage(messageString);
|
|
63
|
+
if (!signature) {
|
|
64
|
+
throw new utils.DynamicError('Failed to sign message');
|
|
65
|
+
}
|
|
66
|
+
return signature;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Executes a program transition on the Aleo network.
|
|
71
|
+
* Returns the transaction ID on success.
|
|
72
|
+
*
|
|
73
|
+
* @param transaction - The transaction to execute
|
|
74
|
+
*/
|
|
75
|
+
requestTransaction(transaction) {
|
|
76
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
return this._connector.requestTransaction(transaction);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Decrypts an Aleo ciphertext using the wallet's view key.
|
|
82
|
+
* Useful for reading private record data.
|
|
83
|
+
*
|
|
84
|
+
* @param ciphertext - The ciphertext string to decrypt
|
|
85
|
+
* @param options - Optional parameters (tpk, programId, functionName, index)
|
|
86
|
+
*/
|
|
87
|
+
decrypt(ciphertext, options) {
|
|
88
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
return this._connector.decrypt(ciphertext, options);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Requests the records owned by this wallet for a given Aleo program.
|
|
94
|
+
*
|
|
95
|
+
* @param program - The program ID to fetch records for (e.g. 'credits.aleo')
|
|
96
|
+
* @param options - Optional: { plaintext: true } to return decrypted record data
|
|
97
|
+
*/
|
|
98
|
+
requestRecords(program, options) {
|
|
99
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
return this._connector.requestRecords(program, options);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
exports.AleoWallet = AleoWallet;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Wallet } from '@dynamic-labs/wallet-connector-core';
|
|
2
|
+
import type { AleoWalletConnector } from '../../connectors/AleoWalletConnector';
|
|
3
|
+
import type { AleoTransaction } from '../../types';
|
|
4
|
+
export declare class AleoWallet extends Wallet<AleoWalletConnector> {
|
|
5
|
+
sendBalance({ amount, toAddress, token, }: {
|
|
6
|
+
amount: string;
|
|
7
|
+
toAddress: string;
|
|
8
|
+
token?: {
|
|
9
|
+
address: string;
|
|
10
|
+
decimals?: number;
|
|
11
|
+
};
|
|
12
|
+
}): Promise<string | undefined>;
|
|
13
|
+
getBalance(): Promise<string>;
|
|
14
|
+
/**
|
|
15
|
+
* Returns the Aleo public key for this wallet.
|
|
16
|
+
* In Aleo, the public key and address are the same value.
|
|
17
|
+
*/
|
|
18
|
+
getPublicKey(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Returns the current network this wallet is connected to (e.g. 'aleo:mainnet').
|
|
21
|
+
*/
|
|
22
|
+
getNetworkInfo(): Promise<string | undefined>;
|
|
23
|
+
/**
|
|
24
|
+
* Signs a message with the Aleo wallet.
|
|
25
|
+
* Accepts both plain strings and Uint8Array (decoded to UTF-8).
|
|
26
|
+
*/
|
|
27
|
+
signMessage(message: string | Uint8Array): Promise<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Executes a program transition on the Aleo network.
|
|
30
|
+
* Returns the transaction ID on success.
|
|
31
|
+
*
|
|
32
|
+
* @param transaction - The transaction to execute
|
|
33
|
+
*/
|
|
34
|
+
requestTransaction(transaction: AleoTransaction): Promise<string>;
|
|
35
|
+
/**
|
|
36
|
+
* Decrypts an Aleo ciphertext using the wallet's view key.
|
|
37
|
+
* Useful for reading private record data.
|
|
38
|
+
*
|
|
39
|
+
* @param ciphertext - The ciphertext string to decrypt
|
|
40
|
+
* @param options - Optional parameters (tpk, programId, functionName, index)
|
|
41
|
+
*/
|
|
42
|
+
decrypt(ciphertext: string, options?: {
|
|
43
|
+
tpk?: string;
|
|
44
|
+
programId?: string;
|
|
45
|
+
functionName?: string;
|
|
46
|
+
index?: number;
|
|
47
|
+
}): Promise<string>;
|
|
48
|
+
/**
|
|
49
|
+
* Requests the records owned by this wallet for a given Aleo program.
|
|
50
|
+
*
|
|
51
|
+
* @param program - The program ID to fetch records for (e.g. 'credits.aleo')
|
|
52
|
+
* @param options - Optional: { plaintext: true } to return decrypted record data
|
|
53
|
+
*/
|
|
54
|
+
requestRecords(program: string, options?: {
|
|
55
|
+
plaintext?: boolean;
|
|
56
|
+
}): Promise<unknown[]>;
|
|
57
|
+
}
|