@subwallet/extension-base 1.3.31-1 → 1.3.33-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/background/KoniTypes.d.ts +94 -3
- package/background/KoniTypes.js +14 -0
- package/background/errors/CardanoProviderError.d.ts +6 -0
- package/background/errors/CardanoProviderError.js +61 -0
- package/background/types.d.ts +2 -2
- package/cjs/background/KoniTypes.js +16 -1
- package/cjs/background/errors/CardanoProviderError.js +67 -0
- package/cjs/constants/environment.js +4 -2
- package/cjs/constants/index.js +4 -1
- package/cjs/core/logic-validation/request.js +50 -3
- package/cjs/koni/api/contract-handler/evm/web3.js +21 -0
- package/cjs/koni/api/staking/bonding/utils.js +24 -3
- package/cjs/koni/background/handlers/Extension.js +141 -107
- package/cjs/koni/background/handlers/State.js +232 -6
- package/cjs/koni/background/handlers/Tabs.js +277 -55
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/cardano/cips/cip30.js +63 -0
- package/cjs/page/cardano/cips/index.js +20 -0
- package/cjs/page/cardano/index.js +41 -0
- package/cjs/page/{SubWalleEvmProvider.js → evm/index.js} +2 -2
- package/cjs/page/index.js +9 -4
- package/cjs/services/balance-service/transfer/xcm/acrossBridge/index.js +6 -2
- package/cjs/services/balance-service/transfer/xcm/index.js +2 -0
- package/cjs/services/chain-service/handler/CardanoApi.js +33 -0
- package/cjs/services/chain-service/index.js +31 -0
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +3 -3
- package/cjs/services/earning-service/handlers/native-staking/dtao.js +2 -2
- package/cjs/services/earning-service/handlers/native-staking/mythos.js +42 -8
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +1 -1
- package/cjs/services/earning-service/handlers/native-staking/tao.js +13 -13
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +1 -1
- package/cjs/services/migration-service/scripts/MigrateAuthUrls.js +1 -1
- package/cjs/services/price-service/coingecko.js +22 -3
- package/cjs/services/price-service/index.js +75 -2
- package/cjs/services/request-service/constants.js +3 -1
- package/cjs/services/request-service/handler/AuthRequestHandler.js +38 -5
- package/cjs/services/request-service/handler/CardanoRequestHandler.js +45 -3
- package/cjs/services/request-service/helper/index.js +419 -1
- package/cjs/services/swap-service/handler/asset-hub/handler.js +1 -1
- package/cjs/services/swap-service/handler/base-handler.js +81 -21
- package/cjs/services/swap-service/handler/hydradx-handler.js +1 -1
- package/cjs/services/swap-service/handler/uniswap-handler.js +274 -45
- package/cjs/services/swap-service/index.js +33 -11
- package/cjs/services/swap-service/utils.js +15 -2
- package/cjs/utils/auth.js +2 -1
- package/cjs/utils/cardano.js +20 -0
- package/cjs/utils/index.js +16 -4
- package/cjs/utils/price.js +28 -0
- package/constants/environment.d.ts +1 -0
- package/constants/environment.js +2 -1
- package/constants/index.d.ts +1 -0
- package/constants/index.js +1 -0
- package/core/logic-validation/request.d.ts +6 -2
- package/core/logic-validation/request.js +51 -5
- package/koni/api/contract-handler/evm/web3.d.ts +2 -0
- package/koni/api/contract-handler/evm/web3.js +19 -0
- package/koni/api/staking/bonding/utils.d.ts +2 -1
- package/koni/api/staking/bonding/utils.js +23 -3
- package/koni/background/handlers/Extension.d.ts +2 -0
- package/koni/background/handlers/Extension.js +32 -2
- package/koni/background/handlers/State.d.ts +6 -1
- package/koni/background/handlers/State.js +228 -6
- package/koni/background/handlers/Tabs.d.ts +11 -1
- package/koni/background/handlers/Tabs.js +242 -19
- package/package.json +67 -42
- package/packageInfo.js +1 -1
- package/page/cardano/cips/cip30.d.ts +22 -0
- package/page/cardano/cips/cip30.js +55 -0
- package/page/cardano/cips/index.d.ts +3 -0
- package/page/cardano/cips/index.js +7 -0
- package/page/cardano/index.d.ts +13 -0
- package/page/cardano/index.js +34 -0
- package/page/{SubWalleEvmProvider.d.ts → evm/index.d.ts} +3 -2
- package/page/{SubWalleEvmProvider.js → evm/index.js} +1 -1
- package/page/index.d.ts +3 -2
- package/page/index.js +6 -2
- package/page/{Accounts.d.ts → substrate/Accounts.d.ts} +1 -1
- package/page/{Metadata.d.ts → substrate/Metadata.d.ts} +1 -1
- package/page/{PostMessageProvider.d.ts → substrate/PostMessageProvider.d.ts} +1 -1
- package/page/{Signer.d.ts → substrate/Signer.d.ts} +1 -1
- package/page/{Injected.d.ts → substrate/index.d.ts} +1 -1
- package/services/balance-service/helpers/subscribe/cardano/types.d.ts +14 -0
- package/services/balance-service/transfer/xcm/acrossBridge/index.d.ts +4 -0
- package/services/balance-service/transfer/xcm/acrossBridge/index.js +4 -1
- package/services/balance-service/transfer/xcm/index.js +2 -0
- package/services/chain-service/handler/CardanoApi.d.ts +3 -1
- package/services/chain-service/handler/CardanoApi.js +33 -0
- package/services/chain-service/index.d.ts +5 -1
- package/services/chain-service/index.js +32 -1
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +3 -3
- package/services/earning-service/handlers/native-staking/dtao.js +2 -2
- package/services/earning-service/handlers/native-staking/mythos.js +42 -8
- package/services/earning-service/handlers/native-staking/relay-chain.js +1 -1
- package/services/earning-service/handlers/native-staking/tao.js +14 -14
- package/services/earning-service/handlers/nomination-pool/index.js +1 -1
- package/services/migration-service/scripts/MigrateAuthUrls.js +1 -1
- package/services/price-service/coingecko.d.ts +2 -1
- package/services/price-service/coingecko.js +19 -1
- package/services/price-service/index.d.ts +11 -1
- package/services/price-service/index.js +78 -5
- package/services/request-service/constants.js +3 -1
- package/services/request-service/handler/AuthRequestHandler.js +40 -7
- package/services/request-service/handler/CardanoRequestHandler.d.ts +2 -0
- package/services/request-service/handler/CardanoRequestHandler.js +45 -3
- package/services/request-service/helper/index.d.ts +54 -0
- package/services/request-service/helper/index.js +406 -1
- package/services/request-service/types.d.ts +3 -1
- package/services/swap-service/handler/asset-hub/handler.js +1 -1
- package/services/swap-service/handler/base-handler.d.ts +3 -1
- package/services/swap-service/handler/base-handler.js +82 -22
- package/services/swap-service/handler/hydradx-handler.js +1 -1
- package/services/swap-service/handler/uniswap-handler.d.ts +5 -0
- package/services/swap-service/handler/uniswap-handler.js +275 -46
- package/services/swap-service/index.js +34 -12
- package/services/swap-service/utils.d.ts +3 -2
- package/services/swap-service/utils.js +13 -1
- package/types/swap/index.d.ts +1 -0
- package/types/transaction/process.d.ts +2 -0
- package/utils/auth.js +3 -2
- package/utils/cardano.d.ts +2 -0
- package/utils/cardano.js +12 -0
- package/utils/index.d.ts +2 -1
- package/utils/index.js +2 -1
- package/utils/price.d.ts +3 -0
- package/utils/price.js +20 -0
- package/cjs/utils/canDerive.js +0 -12
- package/utils/canDerive.d.ts +0 -2
- package/utils/canDerive.js +0 -6
- /package/cjs/page/{Accounts.js → substrate/Accounts.js} +0 -0
- /package/cjs/page/{Metadata.js → substrate/Metadata.js} +0 -0
- /package/cjs/page/{PostMessageProvider.js → substrate/PostMessageProvider.js} +0 -0
- /package/cjs/page/{Signer.js → substrate/Signer.js} +0 -0
- /package/cjs/page/{Injected.js → substrate/index.js} +0 -0
- /package/page/{Accounts.js → substrate/Accounts.js} +0 -0
- /package/page/{Metadata.js → substrate/Metadata.js} +0 -0
- /package/page/{PostMessageProvider.js → substrate/PostMessageProvider.js} +0 -0
- /package/page/{Signer.js → substrate/Signer.js} +0 -0
- /package/page/{Injected.js → substrate/index.js} +0 -0
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { isProductionMode } from '@subwallet/extension-base/constants';
|
|
5
5
|
import { staticData, StaticKey } from '@subwallet/extension-base/utils/staticData';
|
|
6
|
+
import { subwalletApiSdk } from '@subwallet/subwallet-api-sdk';
|
|
6
7
|
import { isArray } from '@polkadot/util';
|
|
7
8
|
const DEFAULT_CURRENCY = 'USD';
|
|
8
9
|
const DERIVATIVE_TOKEN_SLUG_LIST = ['susds', 'savings-dai'];
|
|
@@ -101,11 +102,13 @@ export const getPriceMap = async (priceIds, currency = 'USD') => {
|
|
|
101
102
|
const currencyData = staticData[StaticKey.CURRENCY_SYMBOL][currency || DEFAULT_CURRENCY];
|
|
102
103
|
const priceMap = {};
|
|
103
104
|
const price24hMap = {};
|
|
105
|
+
const lastUpdatedMap = {};
|
|
104
106
|
responseDataPrice.forEach(val => {
|
|
105
107
|
const currentPrice = val.current_price || 0;
|
|
106
108
|
const price24h = currentPrice - (val.price_change_24h || 0);
|
|
107
109
|
priceMap[val.id] = currentPrice;
|
|
108
110
|
price24hMap[val.id] = price24h;
|
|
111
|
+
lastUpdatedMap[val.id] = new Date(val.last_updated || val.last_updated_at || Date.now());
|
|
109
112
|
});
|
|
110
113
|
const derivativeTokenSlugs = await fetchDerivativeTokenSlugs();
|
|
111
114
|
|
|
@@ -123,9 +126,24 @@ export const getPriceMap = async (priceIds, currency = 'USD') => {
|
|
|
123
126
|
currency,
|
|
124
127
|
currencyData,
|
|
125
128
|
priceMap,
|
|
126
|
-
price24hMap
|
|
129
|
+
price24hMap,
|
|
130
|
+
lastUpdatedMap
|
|
127
131
|
};
|
|
128
132
|
} catch (e) {
|
|
129
133
|
return {};
|
|
130
134
|
}
|
|
135
|
+
};
|
|
136
|
+
export const getHistoryPrice = async (priceId, type) => {
|
|
137
|
+
try {
|
|
138
|
+
var _subwalletApiSdk$pric;
|
|
139
|
+
const response = await ((_subwalletApiSdk$pric = subwalletApiSdk.priceHistoryApi) === null || _subwalletApiSdk$pric === void 0 ? void 0 : _subwalletApiSdk$pric.getPriceHistory(priceId, type));
|
|
140
|
+
if (response) {
|
|
141
|
+
return response;
|
|
142
|
+
}
|
|
143
|
+
} catch (e) {
|
|
144
|
+
console.error('Error fetching price history:', e);
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
history: []
|
|
148
|
+
};
|
|
131
149
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CurrencyType, PriceJson } from '@subwallet/extension-base/background/KoniTypes';
|
|
1
|
+
import { CurrencyType, CurrentTokenPrice, HistoryTokenPriceJSON, PriceChartTimeframe, PriceJson } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
2
|
import { CronServiceInterface, PersistDataServiceInterface, ServiceStatus, StoppableServiceInterface } from '@subwallet/extension-base/services/base/types';
|
|
3
3
|
import { ChainService } from '@subwallet/extension-base/services/chain-service';
|
|
4
4
|
import { EventService } from '@subwallet/extension-base/services/event-service';
|
|
@@ -12,6 +12,7 @@ export declare class PriceService implements StoppableServiceInterface, PersistD
|
|
|
12
12
|
private priceSubject;
|
|
13
13
|
private rawPriceSubject;
|
|
14
14
|
private rawExchangeRateMap;
|
|
15
|
+
private historyTokenPriceSubject;
|
|
15
16
|
private refreshTimeout;
|
|
16
17
|
private priceIds;
|
|
17
18
|
private readonly currency;
|
|
@@ -28,6 +29,15 @@ export declare class PriceService implements StoppableServiceInterface, PersistD
|
|
|
28
29
|
getPriceIds(): Set<string>;
|
|
29
30
|
setPriceCurrency(newCurrencyCode: CurrencyType): Promise<boolean>;
|
|
30
31
|
refreshPriceData(priceIds?: Set<string>): void;
|
|
32
|
+
getHistoryTokenPriceData(priceId: string, timeframe: PriceChartTimeframe): Promise<HistoryTokenPriceJSON>;
|
|
33
|
+
subscribeCurrentTokenPrice(priceId: string, callback: (price: CurrentTokenPrice) => void): {
|
|
34
|
+
unsubscribe: () => void;
|
|
35
|
+
currentPrice: {
|
|
36
|
+
value: number;
|
|
37
|
+
value24h: number;
|
|
38
|
+
time: number;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
31
41
|
init(): Promise<void>;
|
|
32
42
|
loadData(): Promise<void>;
|
|
33
43
|
persistData(): Promise<void>;
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
|
|
4
4
|
import { CRON_REFRESH_PRICE_INTERVAL, CURRENCY } from '@subwallet/extension-base/constants';
|
|
5
5
|
import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
|
|
6
|
-
import { getExchangeRateMap, getPriceMap } from '@subwallet/extension-base/services/price-service/coingecko';
|
|
6
|
+
import { getExchangeRateMap, getHistoryPrice, getPriceMap } from '@subwallet/extension-base/services/price-service/coingecko';
|
|
7
7
|
import { SWStorage } from '@subwallet/extension-base/storage';
|
|
8
8
|
import { CurrentCurrencyStore } from '@subwallet/extension-base/stores';
|
|
9
|
-
import { wait } from '@subwallet/extension-base/utils';
|
|
9
|
+
import { getTokenPriceHistoryId, TIME_INTERVAL, wait } from '@subwallet/extension-base/utils';
|
|
10
10
|
import { createPromiseHandler } from '@subwallet/extension-base/utils/promise';
|
|
11
11
|
import { staticData, StaticKey } from '@subwallet/extension-base/utils/staticData';
|
|
12
|
-
import { BehaviorSubject, combineLatest } from 'rxjs';
|
|
12
|
+
import { BehaviorSubject, combineLatest, distinctUntilChanged, map } from 'rxjs';
|
|
13
13
|
const DEFAULT_CURRENCY = 'USD';
|
|
14
14
|
const DEFAULT_PRICE_SUBJECT = {
|
|
15
15
|
currency: DEFAULT_CURRENCY,
|
|
@@ -21,7 +21,8 @@ const DEFAULT_PRICE_SUBJECT = {
|
|
|
21
21
|
},
|
|
22
22
|
priceMap: {},
|
|
23
23
|
price24hMap: {},
|
|
24
|
-
exchangeRateMap: {}
|
|
24
|
+
exchangeRateMap: {},
|
|
25
|
+
lastUpdatedMap: {}
|
|
25
26
|
};
|
|
26
27
|
const checkFetchSuccess = (obj1, obj2) => {
|
|
27
28
|
return Object.keys(obj1).length > 0 && Object.keys(obj2).length > 0;
|
|
@@ -35,6 +36,7 @@ export class PriceService {
|
|
|
35
36
|
});
|
|
36
37
|
this.rawPriceSubject = new BehaviorSubject({});
|
|
37
38
|
this.rawExchangeRateMap = new BehaviorSubject({});
|
|
39
|
+
this.historyTokenPriceSubject = new BehaviorSubject({});
|
|
38
40
|
this.status = ServiceStatus.NOT_INITIALIZED;
|
|
39
41
|
this.dbService = dbService;
|
|
40
42
|
this.eventService = eventService;
|
|
@@ -92,6 +94,7 @@ export class PriceService {
|
|
|
92
94
|
}
|
|
93
95
|
async calculatePriceMap(currency) {
|
|
94
96
|
let {
|
|
97
|
+
lastUpdatedMap,
|
|
95
98
|
price24hMap,
|
|
96
99
|
priceMap
|
|
97
100
|
} = this.rawPriceSubject.value;
|
|
@@ -122,7 +125,10 @@ export class PriceService {
|
|
|
122
125
|
},
|
|
123
126
|
currency: currencyKey,
|
|
124
127
|
exchangeRateMap: exchangeRateData,
|
|
125
|
-
currencyData: staticData[StaticKey.CURRENCY_SYMBOL][currencyKey || DEFAULT_CURRENCY]
|
|
128
|
+
currencyData: staticData[StaticKey.CURRENCY_SYMBOL][currencyKey || DEFAULT_CURRENCY],
|
|
129
|
+
lastUpdatedMap: {
|
|
130
|
+
...lastUpdatedMap
|
|
131
|
+
}
|
|
126
132
|
};
|
|
127
133
|
if (currencyKey === DEFAULT_CURRENCY) {
|
|
128
134
|
return finalPriceMap;
|
|
@@ -164,6 +170,73 @@ export class PriceService {
|
|
|
164
170
|
});
|
|
165
171
|
this.refreshTimeout = setTimeout(this.refreshPriceData.bind(this), CRON_REFRESH_PRICE_INTERVAL);
|
|
166
172
|
}
|
|
173
|
+
async getHistoryTokenPriceData(priceId, timeframe) {
|
|
174
|
+
var _this$rawExchangeRate;
|
|
175
|
+
const id = getTokenPriceHistoryId(priceId, timeframe);
|
|
176
|
+
const currentData = this.historyTokenPriceSubject.value[id];
|
|
177
|
+
const now = Date.now();
|
|
178
|
+
const timeInterval = TIME_INTERVAL[timeframe];
|
|
179
|
+
let history = currentData ? structuredClone(currentData) : undefined;
|
|
180
|
+
const needsRefresh = !history || history.length === 0 || now - history[history.length - 1].time > timeInterval;
|
|
181
|
+
if (needsRefresh) {
|
|
182
|
+
const {
|
|
183
|
+
history: newHistory
|
|
184
|
+
} = await getHistoryPrice(priceId, timeframe);
|
|
185
|
+
if (newHistory.length > 0) {
|
|
186
|
+
history = newHistory;
|
|
187
|
+
|
|
188
|
+
// Update internal cache
|
|
189
|
+
this.historyTokenPriceSubject.next({
|
|
190
|
+
...this.historyTokenPriceSubject.value,
|
|
191
|
+
[id]: structuredClone(history)
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (!history) {
|
|
196
|
+
return {
|
|
197
|
+
history: []
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Resolve current currency
|
|
202
|
+
const {
|
|
203
|
+
promise,
|
|
204
|
+
resolve
|
|
205
|
+
} = createPromiseHandler();
|
|
206
|
+
this.getCurrentCurrency(resolve);
|
|
207
|
+
const currencyKey = await promise;
|
|
208
|
+
const exchangeRate = (_this$rawExchangeRate = this.rawExchangeRateMap.value[currencyKey || DEFAULT_CURRENCY]) === null || _this$rawExchangeRate === void 0 ? void 0 : _this$rawExchangeRate.exchange;
|
|
209
|
+
|
|
210
|
+
// Convert value if needed
|
|
211
|
+
if (exchangeRate && currencyKey !== DEFAULT_CURRENCY) {
|
|
212
|
+
history = history.map(point => ({
|
|
213
|
+
...point,
|
|
214
|
+
value: point.value * exchangeRate
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
history
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
subscribeCurrentTokenPrice(priceId, callback) {
|
|
222
|
+
const priceData = this.priceSubject.value;
|
|
223
|
+
const currentPrice = {
|
|
224
|
+
value: priceData.priceMap[priceId],
|
|
225
|
+
value24h: priceData.price24hMap[priceId],
|
|
226
|
+
time: priceData.lastUpdatedMap[priceId].getTime()
|
|
227
|
+
};
|
|
228
|
+
const unsubscribe = this.priceSubject.pipe(map(valueSubject => ({
|
|
229
|
+
value: valueSubject.priceMap[priceId],
|
|
230
|
+
value24h: valueSubject.price24hMap[priceId],
|
|
231
|
+
time: valueSubject.lastUpdatedMap[priceId].getTime()
|
|
232
|
+
})), distinctUntilChanged()).subscribe(callback);
|
|
233
|
+
return {
|
|
234
|
+
unsubscribe: () => {
|
|
235
|
+
unsubscribe.unsubscribe();
|
|
236
|
+
},
|
|
237
|
+
currentPrice
|
|
238
|
+
};
|
|
239
|
+
}
|
|
167
240
|
async init() {
|
|
168
241
|
this.status = ServiceStatus.INITIALIZING;
|
|
169
242
|
// Fetch data from storage
|
|
@@ -5,7 +5,9 @@ export const EXTENSION_REQUEST_URL = 'extension';
|
|
|
5
5
|
export const PREDEFINED_CHAIN_DAPP_CHAIN_MAP = {
|
|
6
6
|
'portal.astar.network': ['astar', 'astarEvm'],
|
|
7
7
|
'apps.moonbeam.network': ['moonbeam', 'moonriver'],
|
|
8
|
-
'app.stellaswap.com': ['moonbeam']
|
|
8
|
+
'app.stellaswap.com': ['moonbeam'],
|
|
9
|
+
'testnet-preprod.minswap.org': ['cardano_preproduction'],
|
|
10
|
+
'localhost:7777': ['cardano_preproduction']
|
|
9
11
|
};
|
|
10
12
|
export const WEB_APP_URL = [
|
|
11
13
|
/// Web app
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { ALL_ACCOUNT_AUTH_TYPES } from '@subwallet/extension-base/constants';
|
|
5
|
-
import { _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
5
|
+
import { _isChainCardanoCompatible, _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
6
6
|
import { DAPP_CONNECT_BOTH_TYPE_ACCOUNT_URL, PREDEFINED_CHAIN_DAPP_CHAIN_MAP, WEB_APP_URL } from '@subwallet/extension-base/services/request-service/constants';
|
|
7
7
|
import AuthorizeStore from '@subwallet/extension-base/stores/Authorize';
|
|
8
8
|
import { createPromiseHandler, getDomainFromUrl, stripUrl } from '@subwallet/extension-base/utils';
|
|
9
9
|
import { getId } from '@subwallet/extension-base/utils/getId';
|
|
10
|
-
import { isSubstrateAddress, isTonAddress } from '@subwallet/keyring';
|
|
10
|
+
import { isCardanoAddress, isSubstrateAddress, isTonAddress } from '@subwallet/keyring';
|
|
11
11
|
import { BehaviorSubject } from 'rxjs';
|
|
12
12
|
import { isEthereumAddress } from '@polkadot/util-crypto';
|
|
13
13
|
const AUTH_URLS_KEY = 'authUrls';
|
|
@@ -37,6 +37,13 @@ export default class AuthRequestHandler {
|
|
|
37
37
|
value.accountAuthTypes = ['evm', 'substrate'];
|
|
38
38
|
needUpdateAuthList = true;
|
|
39
39
|
}
|
|
40
|
+
const existKeyEvmNetworkConnect = value.currentEvmNetworkKey;
|
|
41
|
+
if (existKeyEvmNetworkConnect) {
|
|
42
|
+
value.currentNetworkMap = {
|
|
43
|
+
evm: existKeyEvmNetworkConnect
|
|
44
|
+
};
|
|
45
|
+
needUpdateAuthList = true;
|
|
46
|
+
}
|
|
40
47
|
acc[key] = {
|
|
41
48
|
...value
|
|
42
49
|
};
|
|
@@ -145,6 +152,18 @@ export default class AuthRequestHandler {
|
|
|
145
152
|
}
|
|
146
153
|
}
|
|
147
154
|
}
|
|
155
|
+
if (options.accessType === 'cardano') {
|
|
156
|
+
const cardanoChains = Object.values(chainInfoMaps).filter(_isChainCardanoCompatible);
|
|
157
|
+
chainInfo = (defaultChain ? chainInfoMaps[defaultChain] : chainInfoMaps.cardano) || cardanoChains[0]; // auto active cardano mainnet chain, because dont support switch network yet
|
|
158
|
+
|
|
159
|
+
if (options.autoActive) {
|
|
160
|
+
var _chainInfo3;
|
|
161
|
+
if (!needEnableChains.includes((_chainInfo3 = chainInfo) === null || _chainInfo3 === void 0 ? void 0 : _chainInfo3.slug)) {
|
|
162
|
+
var _chainInfo4;
|
|
163
|
+
needEnableChains.push((_chainInfo4 = chainInfo) === null || _chainInfo4 === void 0 ? void 0 : _chainInfo4.slug);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
148
167
|
needEnableChains = needEnableChains.filter(slug => {
|
|
149
168
|
var _chainStateMap$slug;
|
|
150
169
|
return !((_chainStateMap$slug = chainStateMap[slug]) !== null && _chainStateMap$slug !== void 0 && _chainStateMap$slug.active);
|
|
@@ -193,20 +212,31 @@ export default class AuthRequestHandler {
|
|
|
193
212
|
if (isTonAddress(a) && !accountAuthTypes.includes('ton')) {
|
|
194
213
|
return true;
|
|
195
214
|
}
|
|
215
|
+
if (isCardanoAddress(a) && !accountAuthTypes.includes('cardano')) {
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
196
218
|
return false;
|
|
197
219
|
});
|
|
198
220
|
backupAllowed.forEach(acc => {
|
|
199
221
|
isAllowedMap[acc] = true;
|
|
200
222
|
});
|
|
201
223
|
}
|
|
202
|
-
|
|
224
|
+
const defaultNetworkMap = {};
|
|
203
225
|
if (accountAuthTypes.includes('evm')) {
|
|
204
226
|
const chainInfo = this.getDAppChainInfo({
|
|
205
227
|
accessType: 'evm',
|
|
206
228
|
autoActive: true,
|
|
207
229
|
url
|
|
208
230
|
});
|
|
209
|
-
|
|
231
|
+
defaultNetworkMap.evm = chainInfo === null || chainInfo === void 0 ? void 0 : chainInfo.slug;
|
|
232
|
+
}
|
|
233
|
+
if (accountAuthTypes.includes('cardano')) {
|
|
234
|
+
const chainInfo = this.getDAppChainInfo({
|
|
235
|
+
accessType: 'cardano',
|
|
236
|
+
autoActive: true,
|
|
237
|
+
url
|
|
238
|
+
});
|
|
239
|
+
defaultNetworkMap.cardano = chainInfo === null || chainInfo === void 0 ? void 0 : chainInfo.slug;
|
|
210
240
|
}
|
|
211
241
|
this.getAuthorize(value => {
|
|
212
242
|
let authorizeList = {};
|
|
@@ -230,7 +260,7 @@ export default class AuthRequestHandler {
|
|
|
230
260
|
origin,
|
|
231
261
|
url,
|
|
232
262
|
accountAuthTypes: [...new Set([...accountAuthTypes, ...((existed === null || existed === void 0 ? void 0 : existed.accountAuthTypes) || [])])],
|
|
233
|
-
|
|
263
|
+
currentNetworkMap: existed ? existed.currentNetworkMap : defaultNetworkMap
|
|
234
264
|
};
|
|
235
265
|
this.setAuthorize(authorizeList, () => {
|
|
236
266
|
cb();
|
|
@@ -328,12 +358,14 @@ export default class AuthRequestHandler {
|
|
|
328
358
|
list.push(...allowedListByRequestType.filter(a => isSubstrateAddress(a)));
|
|
329
359
|
} else if (accountAuthType === 'ton') {
|
|
330
360
|
list.push(...allowedListByRequestType.filter(a => isTonAddress(a)));
|
|
361
|
+
} else if (accountAuthType === 'cardano') {
|
|
362
|
+
list.push(...allowedListByRequestType.filter(a => isCardanoAddress(a)));
|
|
331
363
|
}
|
|
332
364
|
return list;
|
|
333
365
|
}, []);
|
|
334
366
|
if (!confirmAnotherType && !request.reConfirm && allowedListByRequestType.length !== 0) {
|
|
335
367
|
// Prevent appear confirmation popup
|
|
336
|
-
return
|
|
368
|
+
return true;
|
|
337
369
|
}
|
|
338
370
|
} else {
|
|
339
371
|
// Auto auth for web app
|
|
@@ -349,7 +381,8 @@ export default class AuthRequestHandler {
|
|
|
349
381
|
isAllowedMap,
|
|
350
382
|
origin,
|
|
351
383
|
url,
|
|
352
|
-
accountAuthTypes: ALL_ACCOUNT_AUTH_TYPES
|
|
384
|
+
accountAuthTypes: ALL_ACCOUNT_AUTH_TYPES,
|
|
385
|
+
currentNetworkMap: {}
|
|
353
386
|
};
|
|
354
387
|
this.setAuthorize(authList);
|
|
355
388
|
return true;
|
|
@@ -11,6 +11,8 @@ export default class CardanoRequestHandler {
|
|
|
11
11
|
addConfirmationCardano<CT extends ConfirmationTypeCardano>(id: string, url: string, type: CT, payload: ConfirmationDefinitionsCardano[CT][0]['payload'], options?: ConfirmationsQueueItemOptions, validator?: (input: ConfirmationDefinitionsCardano[CT][1]) => Error | undefined): Promise<ConfirmationDefinitionsCardano[CT][1]>;
|
|
12
12
|
completeConfirmationCardano(request: RequestConfirmationCompleteCardano): Promise<boolean>;
|
|
13
13
|
private decorateResult;
|
|
14
|
+
private signMessage;
|
|
14
15
|
private signTransactionCardano;
|
|
16
|
+
private signDappTransactionCardano;
|
|
15
17
|
resetWallet(): void;
|
|
16
18
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import { FixedTransaction, TransactionWitnessSet, Vkeywitnesses } from '@emurgo/cardano-serialization-lib-nodejs';
|
|
4
5
|
import { isInternalRequest } from '@subwallet/extension-base/utils/request';
|
|
5
6
|
import { keyring } from '@subwallet/ui-keyring';
|
|
6
7
|
import { t } from 'i18next';
|
|
@@ -12,7 +13,8 @@ export default class CardanoRequestHandler {
|
|
|
12
13
|
confirmationsQueueSubjectCardano = new BehaviorSubject({
|
|
13
14
|
cardanoSignatureRequest: {},
|
|
14
15
|
cardanoSendTransactionRequest: {},
|
|
15
|
-
cardanoWatchTransactionRequest: {}
|
|
16
|
+
cardanoWatchTransactionRequest: {},
|
|
17
|
+
cardanoSignTransactionRequest: {}
|
|
16
18
|
});
|
|
17
19
|
confirmationsPromiseMap = {};
|
|
18
20
|
constructor(requestService) {
|
|
@@ -114,9 +116,11 @@ export default class CardanoRequestHandler {
|
|
|
114
116
|
async decorateResult(t, request, result) {
|
|
115
117
|
if (result.payload === '') {
|
|
116
118
|
if (t === 'cardanoSignatureRequest') {
|
|
117
|
-
|
|
119
|
+
result.payload = this.signMessage(request);
|
|
118
120
|
} else if (t === 'cardanoSendTransactionRequest') {
|
|
119
121
|
result.payload = this.signTransactionCardano(request);
|
|
122
|
+
} else if (t === 'cardanoSignTransactionRequest') {
|
|
123
|
+
result.payload = this.signDappTransactionCardano(request);
|
|
120
124
|
}
|
|
121
125
|
if (t === 'cardanoSignatureRequest' || t === 'cardanoSendTransactionRequest') {
|
|
122
126
|
const isAlwaysRequired = await this.#requestService.settingService.isAlwaysRequired;
|
|
@@ -126,6 +130,17 @@ export default class CardanoRequestHandler {
|
|
|
126
130
|
}
|
|
127
131
|
}
|
|
128
132
|
}
|
|
133
|
+
signMessage(confirmation) {
|
|
134
|
+
const {
|
|
135
|
+
address,
|
|
136
|
+
payload
|
|
137
|
+
} = confirmation.payload;
|
|
138
|
+
const pair = keyring.getPair(address);
|
|
139
|
+
if (pair.isLocked) {
|
|
140
|
+
keyring.unlockPair(pair.address);
|
|
141
|
+
}
|
|
142
|
+
return pair.cardano.signMessage(payload, true);
|
|
143
|
+
}
|
|
129
144
|
signTransactionCardano(confirmation) {
|
|
130
145
|
// alibaba
|
|
131
146
|
const transaction = confirmation.payload;
|
|
@@ -137,7 +152,34 @@ export default class CardanoRequestHandler {
|
|
|
137
152
|
if (pair.isLocked) {
|
|
138
153
|
keyring.unlockPair(pair.address);
|
|
139
154
|
}
|
|
140
|
-
return pair.cardano.
|
|
155
|
+
return pair.cardano.signTransaction(cardanoPayload);
|
|
156
|
+
}
|
|
157
|
+
signDappTransactionCardano(confirmation) {
|
|
158
|
+
var _FixedTransaction$fro;
|
|
159
|
+
// alibaba
|
|
160
|
+
const transaction = confirmation.payload;
|
|
161
|
+
const {
|
|
162
|
+
addressRequireKeyTypes,
|
|
163
|
+
cardanoPayload,
|
|
164
|
+
from
|
|
165
|
+
} = transaction;
|
|
166
|
+
const vkeyWitnessesFinal = Vkeywitnesses.new();
|
|
167
|
+
const txWitnessSet = (_FixedTransaction$fro = FixedTransaction.from_hex(cardanoPayload).witness_set()) !== null && _FixedTransaction$fro !== void 0 ? _FixedTransaction$fro : TransactionWitnessSet.new();
|
|
168
|
+
const pair = keyring.getPair(from);
|
|
169
|
+
if (pair.isLocked) {
|
|
170
|
+
keyring.unlockPair(pair.address);
|
|
171
|
+
}
|
|
172
|
+
const keyTypes = [...new Set(addressRequireKeyTypes)];
|
|
173
|
+
const vKeyWitnessesHex = pair.cardano.signTransaction(cardanoPayload, {
|
|
174
|
+
needVkeywitness: true,
|
|
175
|
+
keyTypes
|
|
176
|
+
});
|
|
177
|
+
const vKeyWitnesses = Vkeywitnesses.from_hex(vKeyWitnessesHex);
|
|
178
|
+
for (let i = 0; i < vKeyWitnesses.len(); i++) {
|
|
179
|
+
vkeyWitnessesFinal.add(vKeyWitnesses.get(i));
|
|
180
|
+
}
|
|
181
|
+
txWitnessSet.set_vkeys(vkeyWitnessesFinal);
|
|
182
|
+
return txWitnessSet.to_hex();
|
|
141
183
|
}
|
|
142
184
|
resetWallet() {
|
|
143
185
|
const confirmations = this.confirmationsQueueSubjectCardano.getValue();
|
|
@@ -1,2 +1,56 @@
|
|
|
1
|
+
import * as CardanoWasm from '@emurgo/cardano-serialization-lib-nodejs';
|
|
2
|
+
import { CardanoBalanceItem, CardanoUtxosItem } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/cardano/types';
|
|
1
3
|
import { MetadataStore } from '@subwallet/extension-base/stores';
|
|
2
4
|
export declare const extractMetadata: (store: MetadataStore) => void;
|
|
5
|
+
export declare const convertAssetToValue: (amount: CardanoBalanceItem[]) => CardanoWasm.Value;
|
|
6
|
+
export declare const convertValueToAsset: (value: CardanoWasm.Value) => CardanoBalanceItem[];
|
|
7
|
+
export declare const convertUtxoRawToUtxo: (utxos: CardanoUtxosItem[]) => CardanoWasm.TransactionUnspentOutput[];
|
|
8
|
+
export declare function getBalanceAddressMap(outputs: CardanoWasm.TransactionOutputs): Record<string, CardanoWasm.Value>;
|
|
9
|
+
/**
|
|
10
|
+
* Extracts all required key hashes from a list of certificates.
|
|
11
|
+
* Handles different certificate kinds: stake deregistration, delegation,
|
|
12
|
+
* pool registration, pool retirement, and MIR (move instantaneous rewards).
|
|
13
|
+
*
|
|
14
|
+
* Only processes key hash credentials (ignores script credentials).
|
|
15
|
+
*
|
|
16
|
+
* @param {Certificates} certificates - List of certificate objects from a transaction body.
|
|
17
|
+
* @returns {string[]} - An array of required key hashes in hex format.
|
|
18
|
+
*/
|
|
19
|
+
export declare function extractKeyHashFromCertificate(certificates?: CardanoWasm.Certificates): string[];
|
|
20
|
+
/**
|
|
21
|
+
* Extracts required key hashes from withdrawal entries.
|
|
22
|
+
* It processes only credentials of kind 0 (key hash based).
|
|
23
|
+
*
|
|
24
|
+
* @param {Withdrawals} withdrawals - The withdrawal map from a transaction body.
|
|
25
|
+
* @returns {string[]} - An array of required key hashes in hex format.
|
|
26
|
+
*/
|
|
27
|
+
export declare function extractKeyHashesFromWithdrawals(withdrawals?: CardanoWasm.Withdrawals): string[];
|
|
28
|
+
/**
|
|
29
|
+
* Recursively extract all Ed25519 key hashes from a NativeScripts collection.
|
|
30
|
+
* Only processes `ScriptPubkey` entries (kind = 0), and traverses through nested scripts.
|
|
31
|
+
*
|
|
32
|
+
* @param {NativeScripts} scripts - A collection of native scripts.
|
|
33
|
+
* @returns {string[]} - An array of key hashes (hex-encoded) from all script_pubkey entries.
|
|
34
|
+
*/
|
|
35
|
+
export declare function extractKeyHashesFromScripts(scripts?: CardanoWasm.NativeScripts): string[];
|
|
36
|
+
/**
|
|
37
|
+
* Extract required key hashes from the RequiredSigners field in the transaction body.
|
|
38
|
+
* Each entry is an Ed25519 key hash that must sign the transaction.
|
|
39
|
+
*
|
|
40
|
+
* @param {Ed25519KeyHashes} requiredSigners - A list of required signer key hashes.
|
|
41
|
+
* @returns {string[]} - Array of hex-encoded Ed25519 key hashes.
|
|
42
|
+
*/
|
|
43
|
+
export declare function extractKeyHashesFromRequiredSigners(requiredSigners?: CardanoWasm.Ed25519KeyHashes): string[];
|
|
44
|
+
/**
|
|
45
|
+
* Extract required key hashes from collateral inputs in a linear and readable flow.
|
|
46
|
+
*
|
|
47
|
+
* This function resolves UTXOs of each collateral input,
|
|
48
|
+
* attempts to extract the payment key hash from various supported address types,
|
|
49
|
+
* and returns an array of required signer key hashes in hex format.
|
|
50
|
+
*
|
|
51
|
+
* @param {TransactionInputs} collaterals - Collateral inputs used for script validation
|
|
52
|
+
* @param getSpecificUtxo
|
|
53
|
+
* @returns {Promise<string[]>} - Hex-encoded key hashes required to sign the transaction
|
|
54
|
+
*/
|
|
55
|
+
export declare function extractKeyHashesFromCollaterals(collaterals?: CardanoWasm.TransactionInputs, getSpecificUtxo?: (txHash: string, txId: number) => Promise<CardanoUtxosItem | undefined>): Promise<string[]>;
|
|
56
|
+
export declare function hasSufficientCardanoValue(valueA: CardanoWasm.Value, valueB: CardanoWasm.Value): boolean;
|