@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Dynamic Labs, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
/******************************************************************************
|
|
7
|
+
Copyright (c) Microsoft Corporation.
|
|
8
|
+
|
|
9
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
10
|
+
purpose with or without fee is hereby granted.
|
|
11
|
+
|
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
13
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
14
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
15
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
16
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
17
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
18
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
19
|
+
***************************************************************************** */
|
|
20
|
+
|
|
21
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
32
|
+
var e = new Error(message);
|
|
33
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.__awaiter = __awaiter;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
/******************************************************************************
|
|
3
|
+
Copyright (c) Microsoft Corporation.
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
9
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
10
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
11
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
12
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
+
***************************************************************************** */
|
|
16
|
+
|
|
17
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
28
|
+
var e = new Error(message);
|
|
29
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { __awaiter };
|
package/package.cjs
ADDED
package/package.js
ADDED
package/package.json
CHANGED
|
@@ -1 +1,32 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"name": "@dynamic-labs/aleo",
|
|
3
|
+
"version": "4.67.0",
|
|
4
|
+
"description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
|
|
5
|
+
"author": "Dynamic Labs, Inc.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "./src/index.cjs",
|
|
8
|
+
"module": "./src/index.js",
|
|
9
|
+
"types": "./src/index.d.ts",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./src/index.d.ts",
|
|
14
|
+
"import": "./src/index.js",
|
|
15
|
+
"require": "./src/index.cjs"
|
|
16
|
+
},
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://www.dynamic.xyz/",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@dynamic-labs/assert-package-version": "4.67.0",
|
|
22
|
+
"@provablehq/aleo-wallet-adaptor-core": "0.3.0-alpha.3",
|
|
23
|
+
"@provablehq/aleo-wallet-adaptor-shield": "0.3.0-alpha.3",
|
|
24
|
+
"@provablehq/aleo-wallet-standard": "0.3.0-alpha.3",
|
|
25
|
+
"@provablehq/aleo-types": "0.3.0-alpha.3",
|
|
26
|
+
"@dynamic-labs/types": "4.67.0",
|
|
27
|
+
"@dynamic-labs/utils": "4.67.0",
|
|
28
|
+
"@dynamic-labs/wallet-book": "4.67.0",
|
|
29
|
+
"@dynamic-labs/wallet-connector-core": "4.67.0"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {}
|
|
32
|
+
}
|
|
@@ -0,0 +1,322 @@
|
|
|
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 aleoWalletAdaptorShield = require('@provablehq/aleo-wallet-adaptor-shield');
|
|
9
|
+
var aleoTypes = require('@provablehq/aleo-types');
|
|
10
|
+
var utils = require('@dynamic-labs/utils');
|
|
11
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
12
|
+
var AleoWalletConnector = require('../AleoWalletConnector/AleoWalletConnector.cjs');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Registry mapping wallet overrideKeys to their adapter constructors.
|
|
16
|
+
*
|
|
17
|
+
* Keys must match the wallet book entry key (i.e. the overrideKey).
|
|
18
|
+
* Add new adapter-based wallets here or via registerAdapter() at runtime.
|
|
19
|
+
*/
|
|
20
|
+
const adapterRegistry = {
|
|
21
|
+
shield: aleoWalletAdaptorShield.ShieldWalletAdapter,
|
|
22
|
+
};
|
|
23
|
+
const AleoNetworkToIdMap = {
|
|
24
|
+
[aleoTypes.Network.MAINNET]: 0,
|
|
25
|
+
[aleoTypes.Network.TESTNET]: 1,
|
|
26
|
+
};
|
|
27
|
+
const getNetworkByChainId = (chainId) => {
|
|
28
|
+
const entry = Object.entries(AleoNetworkToIdMap).find(([, id]) => id === chainId);
|
|
29
|
+
return entry === null || entry === void 0 ? void 0 : entry[0];
|
|
30
|
+
};
|
|
31
|
+
const WALLET_NOT_CONNECTED = 'Wallet not connected';
|
|
32
|
+
const MICROCREDITS_PER_CREDIT = 1000000;
|
|
33
|
+
const fetchPublicBalance = (address, network) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
const networkSegment = network === aleoTypes.Network.TESTNET ? 'testnet' : 'mainnet';
|
|
35
|
+
const url = `https://api.explorer.provable.com/v1/${networkSegment}/program/credits.aleo/mapping/account/${address}`;
|
|
36
|
+
const response = yield fetch(url);
|
|
37
|
+
if (!response.ok)
|
|
38
|
+
return BigInt(0);
|
|
39
|
+
const text = yield response.text();
|
|
40
|
+
if (!text || text === 'null')
|
|
41
|
+
return BigInt(0);
|
|
42
|
+
const cleaned = text.replace(/u64\.private|u64|[_"]/g, '').trim();
|
|
43
|
+
const value = BigInt(cleaned);
|
|
44
|
+
return value > BigInt(0) ? value : BigInt(0);
|
|
45
|
+
});
|
|
46
|
+
const extractRecordMicrocredits = (record) => {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
if (!record || typeof record !== 'object')
|
|
49
|
+
return BigInt(0);
|
|
50
|
+
const r = record;
|
|
51
|
+
const plaintext = (_a = r.plaintext) !== null && _a !== void 0 ? _a : r.data;
|
|
52
|
+
if (!plaintext || typeof plaintext !== 'object')
|
|
53
|
+
return BigInt(0);
|
|
54
|
+
const pt = plaintext;
|
|
55
|
+
const microcredits = (_b = pt.microcredits) !== null && _b !== void 0 ? _b : pt.microcredits_;
|
|
56
|
+
if (typeof microcredits !== 'string')
|
|
57
|
+
return BigInt(0);
|
|
58
|
+
const value = BigInt(microcredits.replace(/u64\.private|u64|_/g, '').trim());
|
|
59
|
+
return value > BigInt(0) ? value : BigInt(0);
|
|
60
|
+
};
|
|
61
|
+
const fetchPrivateBalance = (adapter) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
+
const records = yield adapter.requestRecords('credits.aleo', true);
|
|
63
|
+
if (!Array.isArray(records))
|
|
64
|
+
return BigInt(0);
|
|
65
|
+
return records.reduce((total, record) => total + extractRecordMicrocredits(record), BigInt(0));
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* Connector for Aleo wallets that use a direct adapter interface rather than
|
|
69
|
+
* the @provablehq/aleo-wallet-standard StandardWallet feature-map API.
|
|
70
|
+
*
|
|
71
|
+
* Extends AleoWalletConnector so it inherits chain/network wiring and falls
|
|
72
|
+
* back to StandardWallet detection when no adapter is registered.
|
|
73
|
+
*
|
|
74
|
+
* To add a new adapter-based wallet, register its constructor:
|
|
75
|
+
* ```typescript
|
|
76
|
+
* AleoWalletAdapterConnector.registerAdapter('leowallet', LeoWalletAdapter);
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
class AleoWalletAdapterConnector extends AleoWalletConnector.AleoWalletConnector {
|
|
80
|
+
/**
|
|
81
|
+
* Register an adapter constructor for a given wallet key.
|
|
82
|
+
* This is the primary extension point for non-standard wallets.
|
|
83
|
+
*/
|
|
84
|
+
static registerAdapter(key, AdapterCtor) {
|
|
85
|
+
adapterRegistry[key] = AdapterCtor;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Instantiate the adapter for this connector's overrideKey.
|
|
89
|
+
* Returns undefined when no constructor is registered (falls back to StandardWallet).
|
|
90
|
+
*/
|
|
91
|
+
createAdapter() {
|
|
92
|
+
const AdapterCtor = adapterRegistry[this.overrideKey];
|
|
93
|
+
return AdapterCtor ? new AdapterCtor() : undefined;
|
|
94
|
+
}
|
|
95
|
+
isInstalledOnBrowser() {
|
|
96
|
+
if (!this.adapter) {
|
|
97
|
+
this.adapter = this.createAdapter();
|
|
98
|
+
}
|
|
99
|
+
if (this.adapter) {
|
|
100
|
+
return this.adapter.readyState === aleoWalletStandard.WalletReadyState.INSTALLED;
|
|
101
|
+
}
|
|
102
|
+
// No adapter registered — fall back to StandardWallet window detection
|
|
103
|
+
return super.isInstalledOnBrowser();
|
|
104
|
+
}
|
|
105
|
+
supportsNetworkSwitching() {
|
|
106
|
+
return this.aleoNetworks.length > 1;
|
|
107
|
+
}
|
|
108
|
+
switchNetwork(_a) {
|
|
109
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ networkChainId, }) {
|
|
110
|
+
if (!this.adapter) {
|
|
111
|
+
this.adapter = this.createAdapter();
|
|
112
|
+
}
|
|
113
|
+
if (networkChainId === undefined || networkChainId === null)
|
|
114
|
+
return;
|
|
115
|
+
const chainIdNum = Number(networkChainId);
|
|
116
|
+
const isValidNetwork = this.aleoNetworks.some((network) => Number(network.chainId) === chainIdNum);
|
|
117
|
+
if (!isValidNetwork) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const network = getNetworkByChainId(chainIdNum);
|
|
121
|
+
if (network && this.adapter) {
|
|
122
|
+
yield this.adapter.switchNetwork(network);
|
|
123
|
+
this.emit('chainChange', { chain: String(chainIdNum) });
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
getNetwork() {
|
|
128
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
var _a;
|
|
130
|
+
if (!((_a = this.adapter) === null || _a === void 0 ? void 0 : _a.network)) {
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
const id = AleoNetworkToIdMap[this.adapter.network];
|
|
134
|
+
return id !== undefined ? String(id) : undefined;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
connect() {
|
|
138
|
+
const _super = Object.create(null, {
|
|
139
|
+
connect: { get: () => super.connect }
|
|
140
|
+
});
|
|
141
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
142
|
+
var _a, _b, _c;
|
|
143
|
+
if (!this.adapter) {
|
|
144
|
+
this.adapter = this.createAdapter();
|
|
145
|
+
}
|
|
146
|
+
if (!this.adapter) {
|
|
147
|
+
// No adapter registered — fall back to StandardWallet connect
|
|
148
|
+
return _super.connect.call(this);
|
|
149
|
+
}
|
|
150
|
+
if (this.adapter.connected) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
yield this.adapter.connect(((_a = this.adapter) === null || _a === void 0 ? void 0 : _a.network) ||
|
|
155
|
+
getNetworkByChainId(Number((_c = (_b = this.aleoNetworks[0]) === null || _b === void 0 ? void 0 : _b.chainId) !== null && _c !== void 0 ? _c : -1)) ||
|
|
156
|
+
aleoTypes.Network.MAINNET, aleoWalletStandard.WalletDecryptPermission.UponRequest);
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
throw new utils.DynamicError(`Failed to connect to ${this.name}: ${error}`);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
getAddress() {
|
|
164
|
+
const _super = Object.create(null, {
|
|
165
|
+
getAddress: { get: () => super.getAddress }
|
|
166
|
+
});
|
|
167
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
var _a, _b, _c, _d;
|
|
169
|
+
if (!this.adapter) {
|
|
170
|
+
return _super.getAddress.call(this);
|
|
171
|
+
}
|
|
172
|
+
const { account } = this.adapter;
|
|
173
|
+
if (account === null || account === void 0 ? void 0 : account.address) {
|
|
174
|
+
return account.address;
|
|
175
|
+
}
|
|
176
|
+
const result = yield this.adapter.connect(((_a = this.adapter) === null || _a === void 0 ? void 0 : _a.network) ||
|
|
177
|
+
getNetworkByChainId(Number((_c = (_b = this.aleoNetworks[0]) === null || _b === void 0 ? void 0 : _b.chainId) !== null && _c !== void 0 ? _c : -1)) ||
|
|
178
|
+
aleoTypes.Network.MAINNET, aleoWalletStandard.WalletDecryptPermission.UponRequest);
|
|
179
|
+
return (_d = result === null || result === void 0 ? void 0 : result.address) !== null && _d !== void 0 ? _d : '';
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
getConnectedAccounts() {
|
|
183
|
+
const _super = Object.create(null, {
|
|
184
|
+
getConnectedAccounts: { get: () => super.getConnectedAccounts }
|
|
185
|
+
});
|
|
186
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
187
|
+
if (!this.adapter) {
|
|
188
|
+
return _super.getConnectedAccounts.call(this);
|
|
189
|
+
}
|
|
190
|
+
const { account } = this.adapter;
|
|
191
|
+
return (account === null || account === void 0 ? void 0 : account.address) ? [account.address] : [];
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
signMessage(messageToSign) {
|
|
195
|
+
const _super = Object.create(null, {
|
|
196
|
+
signMessage: { get: () => super.signMessage }
|
|
197
|
+
});
|
|
198
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
199
|
+
if (!this.adapter) {
|
|
200
|
+
return _super.signMessage.call(this, messageToSign);
|
|
201
|
+
}
|
|
202
|
+
if (!this.adapter.connected) {
|
|
203
|
+
throw new utils.DynamicError(WALLET_NOT_CONNECTED);
|
|
204
|
+
}
|
|
205
|
+
try {
|
|
206
|
+
const messageBytes = new TextEncoder().encode(messageToSign);
|
|
207
|
+
const signatureBytes = yield this.adapter.signMessage(messageBytes);
|
|
208
|
+
return Array.from(signatureBytes, (b) => b.toString(16).padStart(2, '0')).join('');
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
walletConnectorCore.logger.error(`[${this.name}] Sign message failed:`, error);
|
|
212
|
+
throw new utils.DynamicError(`Failed to sign message: ${error}`);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
getBalance(address) {
|
|
217
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
218
|
+
var _a, _b;
|
|
219
|
+
if (!this.adapter) {
|
|
220
|
+
return '0';
|
|
221
|
+
}
|
|
222
|
+
if (!this.adapter.connected) {
|
|
223
|
+
yield this.connect();
|
|
224
|
+
}
|
|
225
|
+
const resolvedAddress = address !== null && address !== void 0 ? address : (_a = this.adapter.account) === null || _a === void 0 ? void 0 : _a.address;
|
|
226
|
+
if (!resolvedAddress) {
|
|
227
|
+
return '0';
|
|
228
|
+
}
|
|
229
|
+
const network = (_b = this.adapter.network) !== null && _b !== void 0 ? _b : aleoTypes.Network.MAINNET;
|
|
230
|
+
let totalMicrocredits = BigInt(0);
|
|
231
|
+
try {
|
|
232
|
+
totalMicrocredits += yield fetchPublicBalance(resolvedAddress, network);
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
walletConnectorCore.logger.debug(`[${this.name}] Failed to fetch public balance:`, error);
|
|
236
|
+
}
|
|
237
|
+
try {
|
|
238
|
+
totalMicrocredits += yield fetchPrivateBalance(this.adapter);
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
walletConnectorCore.logger.debug(`[${this.name}] Failed to fetch private records:`, error);
|
|
242
|
+
}
|
|
243
|
+
return (Number(totalMicrocredits) / MICROCREDITS_PER_CREDIT).toFixed(6);
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
requestTransaction(transaction) {
|
|
247
|
+
const _super = Object.create(null, {
|
|
248
|
+
requestTransaction: { get: () => super.requestTransaction }
|
|
249
|
+
});
|
|
250
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
251
|
+
if (!this.adapter) {
|
|
252
|
+
return _super.requestTransaction.call(this, transaction);
|
|
253
|
+
}
|
|
254
|
+
if (!this.adapter.connected) {
|
|
255
|
+
throw new utils.DynamicError(WALLET_NOT_CONNECTED);
|
|
256
|
+
}
|
|
257
|
+
const [transition] = transaction.transitions;
|
|
258
|
+
if (!transition) {
|
|
259
|
+
throw new utils.DynamicError('Transaction must have at least one transition');
|
|
260
|
+
}
|
|
261
|
+
const options = {
|
|
262
|
+
fee: transaction.fee,
|
|
263
|
+
function: transition.functionName,
|
|
264
|
+
inputs: transition.inputs,
|
|
265
|
+
privateFee: transaction.feePrivate,
|
|
266
|
+
program: transition.program,
|
|
267
|
+
};
|
|
268
|
+
const { transactionId } = yield this.adapter.executeTransaction(options);
|
|
269
|
+
return transactionId;
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
decrypt(ciphertext, options) {
|
|
273
|
+
const _super = Object.create(null, {
|
|
274
|
+
decrypt: { get: () => super.decrypt }
|
|
275
|
+
});
|
|
276
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
277
|
+
if (!this.adapter) {
|
|
278
|
+
return _super.decrypt.call(this, ciphertext, options);
|
|
279
|
+
}
|
|
280
|
+
if (!this.adapter.connected) {
|
|
281
|
+
throw new utils.DynamicError(WALLET_NOT_CONNECTED);
|
|
282
|
+
}
|
|
283
|
+
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);
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
requestRecords(program, options) {
|
|
287
|
+
const _super = Object.create(null, {
|
|
288
|
+
requestRecords: { get: () => super.requestRecords }
|
|
289
|
+
});
|
|
290
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
291
|
+
var _a;
|
|
292
|
+
if (!this.adapter) {
|
|
293
|
+
return _super.requestRecords.call(this, program, options);
|
|
294
|
+
}
|
|
295
|
+
if (!this.adapter.connected) {
|
|
296
|
+
throw new utils.DynamicError(WALLET_NOT_CONNECTED);
|
|
297
|
+
}
|
|
298
|
+
return this.adapter.requestRecords(program, (_a = options === null || options === void 0 ? void 0 : options.plaintext) !== null && _a !== void 0 ? _a : false);
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
endSession() {
|
|
302
|
+
const _super = Object.create(null, {
|
|
303
|
+
endSession: { get: () => super.endSession }
|
|
304
|
+
});
|
|
305
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
306
|
+
if (!this.adapter) {
|
|
307
|
+
return _super.endSession.call(this);
|
|
308
|
+
}
|
|
309
|
+
if (this.adapter.connected) {
|
|
310
|
+
try {
|
|
311
|
+
yield this.adapter.disconnect();
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
314
|
+
walletConnectorCore.logger.debug(`[${this.name}] Error during disconnect:`, error);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
this.adapter = undefined;
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
exports.AleoWalletAdapterConnector = AleoWalletAdapterConnector;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type BaseAleoWalletAdapter } from '@provablehq/aleo-wallet-adaptor-core';
|
|
2
|
+
import { AleoWalletConnector, AleoWalletConnectorOpts } from '../AleoWalletConnector';
|
|
3
|
+
import type { AleoTransaction } from '../../types';
|
|
4
|
+
/**
|
|
5
|
+
* Factory function that creates a BaseAleoWalletAdapter instance for a given wallet key.
|
|
6
|
+
*/
|
|
7
|
+
export type AleoAdapterFactory = () => BaseAleoWalletAdapter;
|
|
8
|
+
/**
|
|
9
|
+
* Constructor type for Aleo wallet adapters (class reference, no instantiation).
|
|
10
|
+
*/
|
|
11
|
+
export type AleoAdapterConstructor = new () => BaseAleoWalletAdapter;
|
|
12
|
+
export type AleoWalletAdapterConnectorOpts = AleoWalletConnectorOpts;
|
|
13
|
+
/**
|
|
14
|
+
* Connector for Aleo wallets that use a direct adapter interface rather than
|
|
15
|
+
* the @provablehq/aleo-wallet-standard StandardWallet feature-map API.
|
|
16
|
+
*
|
|
17
|
+
* Extends AleoWalletConnector so it inherits chain/network wiring and falls
|
|
18
|
+
* back to StandardWallet detection when no adapter is registered.
|
|
19
|
+
*
|
|
20
|
+
* To add a new adapter-based wallet, register its constructor:
|
|
21
|
+
* ```typescript
|
|
22
|
+
* AleoWalletAdapterConnector.registerAdapter('leowallet', LeoWalletAdapter);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare abstract class AleoWalletAdapterConnector extends AleoWalletConnector {
|
|
26
|
+
protected adapter: BaseAleoWalletAdapter | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Register an adapter constructor for a given wallet key.
|
|
29
|
+
* This is the primary extension point for non-standard wallets.
|
|
30
|
+
*/
|
|
31
|
+
static registerAdapter(key: string, AdapterCtor: AleoAdapterConstructor): void;
|
|
32
|
+
/**
|
|
33
|
+
* Instantiate the adapter for this connector's overrideKey.
|
|
34
|
+
* Returns undefined when no constructor is registered (falls back to StandardWallet).
|
|
35
|
+
*/
|
|
36
|
+
protected createAdapter(): BaseAleoWalletAdapter | undefined;
|
|
37
|
+
isInstalledOnBrowser(): boolean;
|
|
38
|
+
supportsNetworkSwitching(): boolean;
|
|
39
|
+
switchNetwork({ networkChainId, }: {
|
|
40
|
+
networkChainId: number | string | undefined;
|
|
41
|
+
}): Promise<void>;
|
|
42
|
+
getNetwork(): Promise<string | undefined>;
|
|
43
|
+
connect(): Promise<void>;
|
|
44
|
+
getAddress(): Promise<string | undefined>;
|
|
45
|
+
getConnectedAccounts(): Promise<string[]>;
|
|
46
|
+
signMessage(messageToSign: string): Promise<string>;
|
|
47
|
+
getBalance(address?: string): Promise<string>;
|
|
48
|
+
requestTransaction(transaction: AleoTransaction): Promise<string>;
|
|
49
|
+
decrypt(ciphertext: string, options?: {
|
|
50
|
+
tpk?: string;
|
|
51
|
+
programId?: string;
|
|
52
|
+
functionName?: string;
|
|
53
|
+
index?: number;
|
|
54
|
+
}): Promise<string>;
|
|
55
|
+
requestRecords(program: string, options?: {
|
|
56
|
+
plaintext?: boolean;
|
|
57
|
+
}): Promise<unknown[]>;
|
|
58
|
+
endSession(): Promise<void>;
|
|
59
|
+
}
|