@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
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import * as CardanoWasm from '@emurgo/cardano-serialization-lib-nodejs';
|
|
4
5
|
import { _AssetType } from '@subwallet/chain-list/types';
|
|
6
|
+
import { CardanoProviderError } from '@subwallet/extension-base/background/errors/CardanoProviderError';
|
|
5
7
|
import { EvmProviderError } from '@subwallet/extension-base/background/errors/EvmProviderError';
|
|
6
8
|
import { withErrorLog } from '@subwallet/extension-base/background/handlers/helpers';
|
|
7
9
|
import { createSubscription, unsubscribe } from '@subwallet/extension-base/background/handlers/subscriptions';
|
|
8
|
-
import { EvmProviderErrorType } from '@subwallet/extension-base/background/KoniTypes';
|
|
10
|
+
import { CardanoProviderErrorType, EvmProviderErrorType } from '@subwallet/extension-base/background/KoniTypes';
|
|
9
11
|
import RequestBytesSign from '@subwallet/extension-base/background/RequestBytesSign';
|
|
10
12
|
import RequestExtrinsicSign from '@subwallet/extension-base/background/RequestExtrinsicSign';
|
|
11
|
-
import { ALL_ACCOUNT_KEY, CRON_GET_API_MAP_STATUS, PERMISSIONS_TO_REVOKE } from '@subwallet/extension-base/constants';
|
|
13
|
+
import { ALL_ACCOUNT_KEY, CRON_GET_API_MAP_STATUS, MAX_COLLATERAL_AMOUNT, PERMISSIONS_TO_REVOKE } from '@subwallet/extension-base/constants';
|
|
12
14
|
import { generateValidationProcess, validationAuthMiddleware } from '@subwallet/extension-base/core/logic-validation';
|
|
13
15
|
import { PHISHING_PAGE_REDIRECT } from '@subwallet/extension-base/defaults';
|
|
14
16
|
import { _CHAIN_VALIDATION_ERROR } from '@subwallet/extension-base/services/chain-service/handler/types';
|
|
15
17
|
import { _generateCustomProviderKey } from '@subwallet/extension-base/services/chain-service/utils';
|
|
18
|
+
import { hasSufficientCardanoValue } from '@subwallet/extension-base/services/request-service/helper';
|
|
16
19
|
import { DEFAULT_CHAIN_PATROL_ENABLE } from '@subwallet/extension-base/services/setting-service/constants';
|
|
17
|
-
import {
|
|
18
|
-
import { EthereumKeypairTypes, SubstrateKeypairTypes, TonKeypairTypes } from '@subwallet/keyring/types';
|
|
20
|
+
import { convertCardanoAddressToHex, getEVMChainInfo, reformatAddress, stripUrl } from '@subwallet/extension-base/utils';
|
|
21
|
+
import { CardanoKeypairTypes, EthereumKeypairTypes, SubstrateKeypairTypes, TonKeypairTypes } from '@subwallet/keyring/types';
|
|
22
|
+
import { keyring } from '@subwallet/ui-keyring';
|
|
19
23
|
import Web3 from 'web3';
|
|
20
24
|
import { checkIfDenied } from '@polkadot/phishing';
|
|
21
25
|
import { isArray, isNumber } from '@polkadot/util';
|
|
@@ -32,7 +36,8 @@ function transformAccountsV2(accounts, anyType = false, authInfo, accountAuthTyp
|
|
|
32
36
|
const validTypes = {
|
|
33
37
|
evm: EthereumKeypairTypes,
|
|
34
38
|
substrate: SubstrateKeypairTypes,
|
|
35
|
-
ton: TonKeypairTypes
|
|
39
|
+
ton: TonKeypairTypes,
|
|
40
|
+
cardano: CardanoKeypairTypes
|
|
36
41
|
};
|
|
37
42
|
return accountAuthTypes.some(authType => {
|
|
38
43
|
var _validTypes$authType;
|
|
@@ -48,9 +53,7 @@ function transformAccountsV2(accounts, anyType = false, authInfo, accountAuthTyp
|
|
|
48
53
|
isHidden
|
|
49
54
|
}
|
|
50
55
|
}
|
|
51
|
-
}) => !isHidden).filter(({
|
|
52
|
-
type
|
|
53
|
-
}) => anyType ? true : canDerive(type)).filter(authTypeFilter).filter(({
|
|
56
|
+
}) => !isHidden).filter(authTypeFilter).filter(({
|
|
54
57
|
json: {
|
|
55
58
|
address
|
|
56
59
|
}
|
|
@@ -116,6 +119,7 @@ export default class KoniTabs {
|
|
|
116
119
|
const payloadValidate = {
|
|
117
120
|
address,
|
|
118
121
|
networkKey: '',
|
|
122
|
+
type: 'substrate',
|
|
119
123
|
errors: [],
|
|
120
124
|
payloadAfterValidated: request
|
|
121
125
|
};
|
|
@@ -132,6 +136,7 @@ export default class KoniTabs {
|
|
|
132
136
|
const address = request.address;
|
|
133
137
|
const payloadValidate = {
|
|
134
138
|
address,
|
|
139
|
+
type: 'substrate',
|
|
135
140
|
networkKey: '',
|
|
136
141
|
errors: [],
|
|
137
142
|
payloadAfterValidated: request
|
|
@@ -262,6 +267,12 @@ export default class KoniTabs {
|
|
|
262
267
|
if (authInfo.accountAuthTypes.includes('evm')) {
|
|
263
268
|
accountAuthTypes.push('evm');
|
|
264
269
|
}
|
|
270
|
+
if (authInfo.accountAuthTypes.includes('ton')) {
|
|
271
|
+
accountAuthTypes.push('ton');
|
|
272
|
+
}
|
|
273
|
+
if (authInfo.accountAuthTypes.includes('cardano')) {
|
|
274
|
+
accountAuthTypes.push('cardano');
|
|
275
|
+
}
|
|
265
276
|
}
|
|
266
277
|
return transformAccountsV2(this.#koniState.keyringService.context.pairs, anyType, authInfo, accountAuthTypes);
|
|
267
278
|
}
|
|
@@ -314,25 +325,32 @@ export default class KoniTabs {
|
|
|
314
325
|
return true;
|
|
315
326
|
}
|
|
316
327
|
authorizeV2(url, request) {
|
|
317
|
-
var _request$accountAuthT, _request$accountAuthT2;
|
|
328
|
+
var _request$accountAuthT, _request$accountAuthT2, _request$accountAuthT3, _request$accountAuthT4;
|
|
318
329
|
const isConnectOnlyEvmAccountType = ((_request$accountAuthT = request.accountAuthTypes) === null || _request$accountAuthT === void 0 ? void 0 : _request$accountAuthT.length) === 1 && ((_request$accountAuthT2 = request.accountAuthTypes) === null || _request$accountAuthT2 === void 0 ? void 0 : _request$accountAuthT2.includes('evm'));
|
|
330
|
+
const isConnectOnlyCardanoAccountType = ((_request$accountAuthT3 = request.accountAuthTypes) === null || _request$accountAuthT3 === void 0 ? void 0 : _request$accountAuthT3.length) === 1 && ((_request$accountAuthT4 = request.accountAuthTypes) === null || _request$accountAuthT4 === void 0 ? void 0 : _request$accountAuthT4.includes('cardano'));
|
|
319
331
|
if (isConnectOnlyEvmAccountType) {
|
|
320
332
|
return new Promise((resolve, reject) => {
|
|
321
333
|
this.#koniState.authorizeUrlV2(url, request).then(resolve).catch(e => {
|
|
322
334
|
reject(new EvmProviderError(EvmProviderErrorType.USER_REJECTED_REQUEST));
|
|
323
335
|
});
|
|
324
336
|
});
|
|
337
|
+
} else if (isConnectOnlyCardanoAccountType) {
|
|
338
|
+
return new Promise((resolve, reject) => {
|
|
339
|
+
this.#koniState.authorizeUrlV2(url, request).then(resolve).catch(e => {
|
|
340
|
+
reject(new CardanoProviderError(CardanoProviderErrorType.REFUSED_REQUEST));
|
|
341
|
+
});
|
|
342
|
+
});
|
|
325
343
|
} else {
|
|
326
344
|
return this.#koniState.authorizeUrlV2(url, request);
|
|
327
345
|
}
|
|
328
346
|
}
|
|
329
347
|
|
|
330
348
|
// TODO: Update logic
|
|
331
|
-
async
|
|
349
|
+
async getCurrentAccount(url, authType) {
|
|
332
350
|
return await new Promise(resolve => {
|
|
333
351
|
this.getAuthInfo(url).then(authInfo => {
|
|
334
352
|
const allAccounts = this.#koniState.keyringService.context.pairs;
|
|
335
|
-
const accountList = transformAccountsV2(allAccounts, false, authInfo, [
|
|
353
|
+
const accountList = transformAccountsV2(allAccounts, false, authInfo, [authType]).map(a => a.address);
|
|
336
354
|
let accounts = [];
|
|
337
355
|
const proxyId = this.#koniState.keyringService.context.currentAccount.proxyId;
|
|
338
356
|
if (proxyId === ALL_ACCOUNT_KEY || !proxyId) {
|
|
@@ -360,8 +378,8 @@ export default class KoniTabs {
|
|
|
360
378
|
let autoActiveChain = false;
|
|
361
379
|
if (url) {
|
|
362
380
|
const authInfo = await this.getAuthInfo(url);
|
|
363
|
-
if (authInfo !== null && authInfo !== void 0 && authInfo.
|
|
364
|
-
currentChain = authInfo === null || authInfo === void 0 ? void 0 : authInfo.
|
|
381
|
+
if (authInfo !== null && authInfo !== void 0 && authInfo.currentNetworkMap.evm) {
|
|
382
|
+
currentChain = authInfo === null || authInfo === void 0 ? void 0 : authInfo.currentNetworkMap.evm;
|
|
365
383
|
}
|
|
366
384
|
if (authInfo !== null && authInfo !== void 0 && authInfo.isAllowed) {
|
|
367
385
|
autoActiveChain = true;
|
|
@@ -413,7 +431,7 @@ export default class KoniTabs {
|
|
|
413
431
|
}
|
|
414
432
|
}
|
|
415
433
|
async getEvmPermission(url, id) {
|
|
416
|
-
const accounts = await this.
|
|
434
|
+
const accounts = await this.getCurrentAccount(url, 'evm');
|
|
417
435
|
return [{
|
|
418
436
|
id: id,
|
|
419
437
|
invoker: url,
|
|
@@ -726,9 +744,9 @@ export default class KoniTabs {
|
|
|
726
744
|
};
|
|
727
745
|
|
|
728
746
|
// Detect accounts changed
|
|
729
|
-
let currentAccountList = await this.
|
|
747
|
+
let currentAccountList = await this.getCurrentAccount(url, 'evm');
|
|
730
748
|
const onCurrentAccountChanged = async () => {
|
|
731
|
-
const newAccountList = await this.
|
|
749
|
+
const newAccountList = await this.getCurrentAccount(url, 'evm');
|
|
732
750
|
|
|
733
751
|
// Compare to void looping reload
|
|
734
752
|
if (JSON.stringify(currentAccountList) !== JSON.stringify(newAccountList)) {
|
|
@@ -755,7 +773,7 @@ export default class KoniTabs {
|
|
|
755
773
|
}
|
|
756
774
|
|
|
757
775
|
// Detect account
|
|
758
|
-
const newAccountList = await this.
|
|
776
|
+
const newAccountList = await this.getCurrentAccount(url, 'evm');
|
|
759
777
|
|
|
760
778
|
// Compare to void looping reload
|
|
761
779
|
if (JSON.stringify(currentAccountList) !== JSON.stringify(newAccountList)) {
|
|
@@ -884,7 +902,7 @@ export default class KoniTabs {
|
|
|
884
902
|
});
|
|
885
903
|
}
|
|
886
904
|
async canUseAccount(address, url) {
|
|
887
|
-
const allowedAccounts = await this.
|
|
905
|
+
const allowedAccounts = await this.getCurrentAccount(url, 'evm');
|
|
888
906
|
return !!allowedAccounts.find(acc => acc.toLowerCase() === address.toLowerCase());
|
|
889
907
|
}
|
|
890
908
|
async evmSign(id, url, {
|
|
@@ -921,7 +939,7 @@ export default class KoniTabs {
|
|
|
921
939
|
case 'net_version':
|
|
922
940
|
return parseInt(await this.getEvmCurrentChainId(url), 16);
|
|
923
941
|
case 'eth_accounts':
|
|
924
|
-
return await this.
|
|
942
|
+
return await this.getCurrentAccount(url, 'evm');
|
|
925
943
|
case 'eth_sendTransaction':
|
|
926
944
|
return await this.evmSendTransaction(id, url, request);
|
|
927
945
|
case 'eth_sign':
|
|
@@ -1042,6 +1060,191 @@ export default class KoniTabs {
|
|
|
1042
1060
|
});
|
|
1043
1061
|
return await this.#koniState.addTokenConfirm(id, url, tokenInfo);
|
|
1044
1062
|
}
|
|
1063
|
+
|
|
1064
|
+
// Cardano
|
|
1065
|
+
|
|
1066
|
+
async getCurrentInformationCardanoDapp(url) {
|
|
1067
|
+
const authInfo = await this.getAuthInfo(url);
|
|
1068
|
+
if (!authInfo || !authInfo.isAllowedMap || !authInfo.isAllowed) {
|
|
1069
|
+
throw new CardanoProviderError(CardanoProviderErrorType.REFUSED_REQUEST, 'You need to connect to the wallet first');
|
|
1070
|
+
}
|
|
1071
|
+
const cardanoAddress = authInfo.currentAccount;
|
|
1072
|
+
if (!cardanoAddress || !authInfo.isAllowedMap[cardanoAddress]) {
|
|
1073
|
+
throw new CardanoProviderError(CardanoProviderErrorType.ACCOUNT_CHANGED, 'No Cardano address found');
|
|
1074
|
+
}
|
|
1075
|
+
const keypair = keyring.getPair(cardanoAddress);
|
|
1076
|
+
if (!keypair) {
|
|
1077
|
+
throw new CardanoProviderError(CardanoProviderErrorType.ACCOUNT_CHANGED, 'No Cardano address found');
|
|
1078
|
+
}
|
|
1079
|
+
const network = authInfo === null || authInfo === void 0 ? void 0 : authInfo.currentNetworkMap.cardano;
|
|
1080
|
+
if (!network) {
|
|
1081
|
+
throw new CardanoProviderError(CardanoProviderErrorType.INTERNAL_ERROR, 'No network key found');
|
|
1082
|
+
}
|
|
1083
|
+
return {
|
|
1084
|
+
address: cardanoAddress,
|
|
1085
|
+
network
|
|
1086
|
+
};
|
|
1087
|
+
}
|
|
1088
|
+
async cardanoGetAccountList(id, url) {
|
|
1089
|
+
const authList = await this.#koniState.getAuthList();
|
|
1090
|
+
const urlStripped = stripUrl(url);
|
|
1091
|
+
const authInfo = authList[urlStripped];
|
|
1092
|
+
if (!authInfo || !authInfo.isAllowedMap) {
|
|
1093
|
+
throw new CardanoProviderError(CardanoProviderErrorType.REFUSED_REQUEST, 'You need to connect to the wallet first');
|
|
1094
|
+
}
|
|
1095
|
+
const accountList = await this.getCurrentAccount(url, 'cardano');
|
|
1096
|
+
const currentCardanoAccount = authInfo.currentAccount;
|
|
1097
|
+
if (currentCardanoAccount !== accountList[0]) {
|
|
1098
|
+
authList[urlStripped].currentAccount = accountList[0];
|
|
1099
|
+
this.#koniState.setAuthorize(authList);
|
|
1100
|
+
}
|
|
1101
|
+
return accountList.map(address => {
|
|
1102
|
+
const isTestnet = (authInfo === null || authInfo === void 0 ? void 0 : authInfo.currentNetworkMap.cardano) !== 'cardano_preproduction';
|
|
1103
|
+
const addressChainFormat = reformatAddress(address, +isTestnet);
|
|
1104
|
+
return convertCardanoAddressToHex(addressChainFormat);
|
|
1105
|
+
});
|
|
1106
|
+
}
|
|
1107
|
+
async cardanoGetAccountBalance(id, url) {
|
|
1108
|
+
const {
|
|
1109
|
+
address
|
|
1110
|
+
} = await this.getCurrentInformationCardanoDapp(url);
|
|
1111
|
+
const balanceValue = await this.#koniState.cardanoGetBalance(id, url, address);
|
|
1112
|
+
return balanceValue.to_hex();
|
|
1113
|
+
}
|
|
1114
|
+
async cardanoGetChangeAddress(id, url) {
|
|
1115
|
+
const authList = await this.#koniState.getAuthList();
|
|
1116
|
+
const urlStripped = stripUrl(url);
|
|
1117
|
+
const authInfo = authList[urlStripped];
|
|
1118
|
+
if (!authInfo || !authInfo.isAllowedMap) {
|
|
1119
|
+
throw new CardanoProviderError(CardanoProviderErrorType.REFUSED_REQUEST, 'You need to connect to the wallet first');
|
|
1120
|
+
}
|
|
1121
|
+
const accountList = await this.getCurrentAccount(url, 'cardano');
|
|
1122
|
+
const currentCardanoAccount = authInfo.currentAccount;
|
|
1123
|
+
if (currentCardanoAccount !== accountList[0]) {
|
|
1124
|
+
authList[urlStripped].currentAccount = accountList[0];
|
|
1125
|
+
this.#koniState.setAuthorize(authList);
|
|
1126
|
+
}
|
|
1127
|
+
const {
|
|
1128
|
+
address,
|
|
1129
|
+
network
|
|
1130
|
+
} = await this.getCurrentInformationCardanoDapp(url);
|
|
1131
|
+
const isTestnet = network !== 'cardano_preproduction';
|
|
1132
|
+
const addressChainFormat = reformatAddress(address, +isTestnet);
|
|
1133
|
+
return convertCardanoAddressToHex(addressChainFormat);
|
|
1134
|
+
}
|
|
1135
|
+
async cardanoGetCurrentNetworkId(id, url) {
|
|
1136
|
+
let currentChain;
|
|
1137
|
+
let autoActiveChain = false;
|
|
1138
|
+
if (url) {
|
|
1139
|
+
const authInfo = await this.getAuthInfo(url);
|
|
1140
|
+
if (authInfo !== null && authInfo !== void 0 && authInfo.currentNetworkMap.cardano) {
|
|
1141
|
+
currentChain = authInfo.currentNetworkMap.cardano;
|
|
1142
|
+
}
|
|
1143
|
+
if (authInfo !== null && authInfo !== void 0 && authInfo.isAllowed) {
|
|
1144
|
+
autoActiveChain = true;
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
const currentNetwork = this.#koniState.requestService.getDAppChainInfo({
|
|
1148
|
+
autoActive: autoActiveChain,
|
|
1149
|
+
accessType: 'cardano',
|
|
1150
|
+
defaultChain: currentChain,
|
|
1151
|
+
url
|
|
1152
|
+
});
|
|
1153
|
+
if (!(currentNetwork !== null && currentNetwork !== void 0 && currentNetwork.cardanoInfo)) {
|
|
1154
|
+
throw new CardanoProviderError(CardanoProviderErrorType.INTERNAL_ERROR, 'Can\'t get current network');
|
|
1155
|
+
}
|
|
1156
|
+
return +!(currentNetwork !== null && currentNetwork !== void 0 && currentNetwork.isTestnet);
|
|
1157
|
+
}
|
|
1158
|
+
async cardanoGetUtxo(id, url, params) {
|
|
1159
|
+
const {
|
|
1160
|
+
address,
|
|
1161
|
+
network
|
|
1162
|
+
} = await this.getCurrentInformationCardanoDapp(url);
|
|
1163
|
+
const utxos = await this.#koniState.chainService.getUtxosByAddress(address, network, params === null || params === void 0 ? void 0 : params.paginate);
|
|
1164
|
+
if (!(params !== null && params !== void 0 && params.amount)) {
|
|
1165
|
+
return utxos.map(utxo => utxo.to_hex());
|
|
1166
|
+
}
|
|
1167
|
+
let expectedValue = CardanoWasm.Value.zero();
|
|
1168
|
+
try {
|
|
1169
|
+
expectedValue = CardanoWasm.Value.from_hex(params === null || params === void 0 ? void 0 : params.amount);
|
|
1170
|
+
} catch (e) {
|
|
1171
|
+
throw new CardanoProviderError(CardanoProviderErrorType.INVALID_REQUEST, 'Amount is invalid');
|
|
1172
|
+
}
|
|
1173
|
+
let currentTotalUtxoValue = CardanoWasm.Value.zero();
|
|
1174
|
+
const utxosFiltered = [];
|
|
1175
|
+
for (const utxo of utxos) {
|
|
1176
|
+
currentTotalUtxoValue = currentTotalUtxoValue.checked_add(utxo.output().amount());
|
|
1177
|
+
utxosFiltered.push(utxo);
|
|
1178
|
+
if (hasSufficientCardanoValue(currentTotalUtxoValue, expectedValue)) {
|
|
1179
|
+
return utxosFiltered.map(utxo => utxo.to_hex());
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
return null;
|
|
1183
|
+
}
|
|
1184
|
+
async cardanoGetCollateral(id, url, params) {
|
|
1185
|
+
const {
|
|
1186
|
+
address,
|
|
1187
|
+
network
|
|
1188
|
+
} = await this.getCurrentInformationCardanoDapp(url);
|
|
1189
|
+
const utxos = await this.#koniState.chainService.getUtxosByAddress(address, network);
|
|
1190
|
+
let expectedValue = CardanoWasm.Value.zero();
|
|
1191
|
+
try {
|
|
1192
|
+
if (params !== null && params !== void 0 && params.amount) {
|
|
1193
|
+
expectedValue = CardanoWasm.Value.from_hex(params === null || params === void 0 ? void 0 : params.amount);
|
|
1194
|
+
} else {
|
|
1195
|
+
expectedValue = CardanoWasm.Value.new(CardanoWasm.BigNum.from_str(MAX_COLLATERAL_AMOUNT));
|
|
1196
|
+
}
|
|
1197
|
+
} catch (e) {
|
|
1198
|
+
throw new CardanoProviderError(CardanoProviderErrorType.INVALID_REQUEST, 'Amount is invalid');
|
|
1199
|
+
}
|
|
1200
|
+
if (expectedValue.multiasset() || expectedValue.coin().compare(CardanoWasm.BigNum.from_str(MAX_COLLATERAL_AMOUNT)) > 0) {
|
|
1201
|
+
throw new CardanoProviderError(CardanoProviderErrorType.INVALID_REQUEST, 'Amount is invalid');
|
|
1202
|
+
}
|
|
1203
|
+
let currentTotalUtxoValue = CardanoWasm.Value.zero();
|
|
1204
|
+
const utxosFinal = [];
|
|
1205
|
+
for (const utxo of utxos) {
|
|
1206
|
+
const amount = utxo.output().amount();
|
|
1207
|
+
if (amount.multiasset()) {
|
|
1208
|
+
continue;
|
|
1209
|
+
}
|
|
1210
|
+
currentTotalUtxoValue = currentTotalUtxoValue.checked_add(amount);
|
|
1211
|
+
utxosFinal.push(utxo);
|
|
1212
|
+
if (hasSufficientCardanoValue(currentTotalUtxoValue, expectedValue)) {
|
|
1213
|
+
break;
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
return utxosFinal.length ? utxosFinal.map(utxo => utxo.to_hex()) : null;
|
|
1217
|
+
}
|
|
1218
|
+
async cardanoSignData(id, url, params) {
|
|
1219
|
+
const {
|
|
1220
|
+
address
|
|
1221
|
+
} = await this.getCurrentInformationCardanoDapp(url);
|
|
1222
|
+
const signResult = await this.#koniState.cardanoSignData(id, url, params, address);
|
|
1223
|
+
if (signResult) {
|
|
1224
|
+
return signResult;
|
|
1225
|
+
} else {
|
|
1226
|
+
throw new CardanoProviderError(CardanoProviderErrorType.INTERNAL_ERROR, 'Failed to sign data');
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
async cardanoSignTransaction(id, url, params) {
|
|
1230
|
+
const {
|
|
1231
|
+
address
|
|
1232
|
+
} = await this.getCurrentInformationCardanoDapp(url);
|
|
1233
|
+
const signResult = await this.#koniState.cardanoSignTx(id, url, params, address);
|
|
1234
|
+
if (signResult) {
|
|
1235
|
+
return signResult;
|
|
1236
|
+
} else {
|
|
1237
|
+
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, 'Failed to sign message');
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
async cardanoSubmitTransaction(id, url, params) {
|
|
1241
|
+
const txHash = await this.#koniState.cardanoSubmitTx(id, url, params);
|
|
1242
|
+
if (txHash) {
|
|
1243
|
+
return txHash;
|
|
1244
|
+
} else {
|
|
1245
|
+
throw new CardanoProviderError(CardanoProviderErrorType.INTERNAL_ERROR, 'Failed to submit transaction');
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1045
1248
|
async handle(id, type, request, url, port) {
|
|
1046
1249
|
if (type === 'pub(phishing.redirectIfDenied)') {
|
|
1047
1250
|
return this.redirectIfPhishing(url);
|
|
@@ -1101,6 +1304,26 @@ export default class KoniTabs {
|
|
|
1101
1304
|
return await this.handleEvmRequest(id, url, request);
|
|
1102
1305
|
case 'evm(provider.send)':
|
|
1103
1306
|
return await this.handleEvmSend(id, url, port, request);
|
|
1307
|
+
|
|
1308
|
+
// Cardano
|
|
1309
|
+
case 'cardano(account.get.address)':
|
|
1310
|
+
return await this.cardanoGetAccountList(id, url);
|
|
1311
|
+
case 'cardano(account.get.balance)':
|
|
1312
|
+
return await this.cardanoGetAccountBalance(id, url);
|
|
1313
|
+
case 'cardano(account.get.change.address)':
|
|
1314
|
+
return await this.cardanoGetChangeAddress(id, url);
|
|
1315
|
+
case 'cardano(account.get.collateral)':
|
|
1316
|
+
return await this.cardanoGetCollateral(id, url, request);
|
|
1317
|
+
case 'cardano(account.get.utxos)':
|
|
1318
|
+
return await this.cardanoGetUtxo(id, url, request);
|
|
1319
|
+
case 'cardano(network.get.current)':
|
|
1320
|
+
return await this.cardanoGetCurrentNetworkId(id, url);
|
|
1321
|
+
case 'cardano(data.sign)':
|
|
1322
|
+
return await this.cardanoSignData(id, url, request);
|
|
1323
|
+
case 'cardano(transaction.sign)':
|
|
1324
|
+
return await this.cardanoSignTransaction(id, url, request);
|
|
1325
|
+
case 'cardano(transaction.submit)':
|
|
1326
|
+
return await this.cardanoSubmitTransaction(id, url, request);
|
|
1104
1327
|
default:
|
|
1105
1328
|
throw new Error(`Unable to handle message of type ${type}`);
|
|
1106
1329
|
}
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.3.
|
|
20
|
+
"version": "1.3.33-0",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -34,6 +34,11 @@
|
|
|
34
34
|
"require": "./cjs/background/errors/BalanceError.js",
|
|
35
35
|
"default": "./background/errors/BalanceError.js"
|
|
36
36
|
},
|
|
37
|
+
"./background/errors/CardanoProviderError": {
|
|
38
|
+
"types": "./background/errors/CardanoProviderError.d.ts",
|
|
39
|
+
"require": "./cjs/background/errors/CardanoProviderError.js",
|
|
40
|
+
"default": "./background/errors/CardanoProviderError.js"
|
|
41
|
+
},
|
|
37
42
|
"./background/errors/EvmProviderError": {
|
|
38
43
|
"types": "./background/errors/EvmProviderError.d.ts",
|
|
39
44
|
"require": "./cjs/background/errors/EvmProviderError.js",
|
|
@@ -594,35 +599,50 @@
|
|
|
594
599
|
"require": "./cjs/page/index.js",
|
|
595
600
|
"default": "./page/index.js"
|
|
596
601
|
},
|
|
597
|
-
"./page/
|
|
598
|
-
"types": "./page/
|
|
599
|
-
"require": "./cjs/page/
|
|
600
|
-
"default": "./page/
|
|
601
|
-
},
|
|
602
|
-
"./page/
|
|
603
|
-
"types": "./page/
|
|
604
|
-
"require": "./cjs/page/
|
|
605
|
-
"default": "./page/
|
|
606
|
-
},
|
|
607
|
-
"./page/
|
|
608
|
-
"types": "./page/
|
|
609
|
-
"require": "./cjs/page/
|
|
610
|
-
"default": "./page/
|
|
611
|
-
},
|
|
612
|
-
"./page/
|
|
613
|
-
"types": "./page/
|
|
614
|
-
"require": "./cjs/page/
|
|
615
|
-
"default": "./page/
|
|
616
|
-
},
|
|
617
|
-
"./page/
|
|
618
|
-
"types": "./page/
|
|
619
|
-
"require": "./cjs/page/
|
|
620
|
-
"default": "./page/
|
|
621
|
-
},
|
|
622
|
-
"./page/
|
|
623
|
-
"types": "./page/
|
|
624
|
-
"require": "./cjs/page/
|
|
625
|
-
"default": "./page/
|
|
602
|
+
"./page/cardano": {
|
|
603
|
+
"types": "./page/cardano/index.d.ts",
|
|
604
|
+
"require": "./cjs/page/cardano/index.js",
|
|
605
|
+
"default": "./page/cardano/index.js"
|
|
606
|
+
},
|
|
607
|
+
"./page/cardano/cips": {
|
|
608
|
+
"types": "./page/cardano/cips/index.d.ts",
|
|
609
|
+
"require": "./cjs/page/cardano/cips/index.js",
|
|
610
|
+
"default": "./page/cardano/cips/index.js"
|
|
611
|
+
},
|
|
612
|
+
"./page/cardano/cips/cip30": {
|
|
613
|
+
"types": "./page/cardano/cips/cip30.d.ts",
|
|
614
|
+
"require": "./cjs/page/cardano/cips/cip30.js",
|
|
615
|
+
"default": "./page/cardano/cips/cip30.js"
|
|
616
|
+
},
|
|
617
|
+
"./page/evm": {
|
|
618
|
+
"types": "./page/evm/index.d.ts",
|
|
619
|
+
"require": "./cjs/page/evm/index.js",
|
|
620
|
+
"default": "./page/evm/index.js"
|
|
621
|
+
},
|
|
622
|
+
"./page/substrate": {
|
|
623
|
+
"types": "./page/substrate/index.d.ts",
|
|
624
|
+
"require": "./cjs/page/substrate/index.js",
|
|
625
|
+
"default": "./page/substrate/index.js"
|
|
626
|
+
},
|
|
627
|
+
"./page/substrate/Accounts": {
|
|
628
|
+
"types": "./page/substrate/Accounts.d.ts",
|
|
629
|
+
"require": "./cjs/page/substrate/Accounts.js",
|
|
630
|
+
"default": "./page/substrate/Accounts.js"
|
|
631
|
+
},
|
|
632
|
+
"./page/substrate/Metadata": {
|
|
633
|
+
"types": "./page/substrate/Metadata.d.ts",
|
|
634
|
+
"require": "./cjs/page/substrate/Metadata.js",
|
|
635
|
+
"default": "./page/substrate/Metadata.js"
|
|
636
|
+
},
|
|
637
|
+
"./page/substrate/PostMessageProvider": {
|
|
638
|
+
"types": "./page/substrate/PostMessageProvider.d.ts",
|
|
639
|
+
"require": "./cjs/page/substrate/PostMessageProvider.js",
|
|
640
|
+
"default": "./page/substrate/PostMessageProvider.js"
|
|
641
|
+
},
|
|
642
|
+
"./page/substrate/Signer": {
|
|
643
|
+
"types": "./page/substrate/Signer.d.ts",
|
|
644
|
+
"require": "./cjs/page/substrate/Signer.js",
|
|
645
|
+
"default": "./page/substrate/Signer.js"
|
|
626
646
|
},
|
|
627
647
|
"./page/types": {
|
|
628
648
|
"types": "./page/types.d.ts",
|
|
@@ -2481,10 +2501,10 @@
|
|
|
2481
2501
|
"require": "./cjs/utils/auth.js",
|
|
2482
2502
|
"default": "./utils/auth.js"
|
|
2483
2503
|
},
|
|
2484
|
-
"./utils/
|
|
2485
|
-
"types": "./utils/
|
|
2486
|
-
"require": "./cjs/utils/
|
|
2487
|
-
"default": "./utils/
|
|
2504
|
+
"./utils/cardano": {
|
|
2505
|
+
"types": "./utils/cardano.d.ts",
|
|
2506
|
+
"require": "./cjs/utils/cardano.js",
|
|
2507
|
+
"default": "./utils/cardano.js"
|
|
2488
2508
|
},
|
|
2489
2509
|
"./utils/environment": {
|
|
2490
2510
|
"types": "./utils/environment.d.ts",
|
|
@@ -2596,6 +2616,11 @@
|
|
|
2596
2616
|
"require": "./cjs/utils/object.js",
|
|
2597
2617
|
"default": "./utils/object.js"
|
|
2598
2618
|
},
|
|
2619
|
+
"./utils/price": {
|
|
2620
|
+
"types": "./utils/price.d.ts",
|
|
2621
|
+
"require": "./cjs/utils/price.js",
|
|
2622
|
+
"default": "./utils/price.js"
|
|
2623
|
+
},
|
|
2599
2624
|
"./utils/promise": {
|
|
2600
2625
|
"types": "./utils/promise.d.ts",
|
|
2601
2626
|
"require": "./cjs/utils/promise.js",
|
|
@@ -2679,14 +2704,14 @@
|
|
|
2679
2704
|
"@reduxjs/toolkit": "^1.9.1",
|
|
2680
2705
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
2681
2706
|
"@substrate/connect": "^0.8.9",
|
|
2682
|
-
"@subwallet/chain-list": "0.2.
|
|
2683
|
-
"@subwallet/extension-base": "^1.3.
|
|
2684
|
-
"@subwallet/extension-chains": "^1.3.
|
|
2685
|
-
"@subwallet/extension-dapp": "^1.3.
|
|
2686
|
-
"@subwallet/extension-inject": "^1.3.
|
|
2687
|
-
"@subwallet/keyring": "^0.1.
|
|
2688
|
-
"@subwallet/subwallet-api-sdk": "^1.3.
|
|
2689
|
-
"@subwallet/ui-keyring": "^0.1.
|
|
2707
|
+
"@subwallet/chain-list": "0.2.104",
|
|
2708
|
+
"@subwallet/extension-base": "^1.3.33-0",
|
|
2709
|
+
"@subwallet/extension-chains": "^1.3.33-0",
|
|
2710
|
+
"@subwallet/extension-dapp": "^1.3.33-0",
|
|
2711
|
+
"@subwallet/extension-inject": "^1.3.33-0",
|
|
2712
|
+
"@subwallet/keyring": "^0.1.11",
|
|
2713
|
+
"@subwallet/subwallet-api-sdk": "^1.3.33-0",
|
|
2714
|
+
"@subwallet/ui-keyring": "^0.1.11",
|
|
2690
2715
|
"@ton/core": "^0.56.3",
|
|
2691
2716
|
"@ton/crypto": "^3.2.0",
|
|
2692
2717
|
"@ton/ton": "^15.0.0",
|
package/packageInfo.js
CHANGED
|
@@ -7,5 +7,5 @@ export const packageInfo = {
|
|
|
7
7
|
name: '@subwallet/extension-base',
|
|
8
8
|
path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
|
|
9
9
|
type: 'esm',
|
|
10
|
-
version: '1.3.
|
|
10
|
+
version: '1.3.33-0'
|
|
11
11
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CardanoPaginate, Cbor } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
|
+
import { SendRequest } from '@subwallet/extension-base/page/types';
|
|
3
|
+
export declare class CIP30Api {
|
|
4
|
+
private sendMessage;
|
|
5
|
+
constructor(sendMessage: SendRequest);
|
|
6
|
+
getExtension(): {
|
|
7
|
+
cip: number;
|
|
8
|
+
}[];
|
|
9
|
+
getNetworkId(): Promise<number>;
|
|
10
|
+
getCollateral(payload: {
|
|
11
|
+
amount: Cbor;
|
|
12
|
+
}): Promise<string[] | null>;
|
|
13
|
+
getUtxos(amount?: Cbor, paginate?: CardanoPaginate): Promise<string[] | null>;
|
|
14
|
+
getUsedAddresses(): Promise<string[]>;
|
|
15
|
+
getChangeAddress(): Promise<string>;
|
|
16
|
+
getUnusedAddresses(): Promise<string[]>;
|
|
17
|
+
getRewardAddresses(): Promise<string[]>;
|
|
18
|
+
signTx(tx: Cbor, partialSign?: boolean): Promise<string>;
|
|
19
|
+
signData(address: string, payload: string): Promise<import("@subwallet/extension-base/background/KoniTypes").ResponseCardanoSignData>;
|
|
20
|
+
submitTx(tx: Cbor): Promise<string>;
|
|
21
|
+
getBalance(): Promise<string>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export class CIP30Api {
|
|
5
|
+
constructor(sendMessage) {
|
|
6
|
+
this.sendMessage = sendMessage;
|
|
7
|
+
}
|
|
8
|
+
getExtension() {
|
|
9
|
+
return [{
|
|
10
|
+
cip: 30
|
|
11
|
+
}];
|
|
12
|
+
}
|
|
13
|
+
async getNetworkId() {
|
|
14
|
+
return await this.sendMessage('cardano(network.get.current)');
|
|
15
|
+
}
|
|
16
|
+
async getCollateral(payload) {
|
|
17
|
+
return await this.sendMessage('cardano(account.get.collateral)', payload);
|
|
18
|
+
}
|
|
19
|
+
async getUtxos(amount, paginate) {
|
|
20
|
+
return await this.sendMessage('cardano(account.get.utxos)', {
|
|
21
|
+
amount,
|
|
22
|
+
paginate
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async getUsedAddresses() {
|
|
26
|
+
return await this.sendMessage('cardano(account.get.address)');
|
|
27
|
+
}
|
|
28
|
+
async getChangeAddress() {
|
|
29
|
+
return await this.sendMessage('cardano(account.get.change.address)');
|
|
30
|
+
}
|
|
31
|
+
async getUnusedAddresses() {
|
|
32
|
+
return new Promise(resolve => resolve([]));
|
|
33
|
+
}
|
|
34
|
+
async getRewardAddresses() {
|
|
35
|
+
return new Promise(resolve => resolve([]));
|
|
36
|
+
}
|
|
37
|
+
async signTx(tx, partialSign = false) {
|
|
38
|
+
return await this.sendMessage('cardano(transaction.sign)', {
|
|
39
|
+
tx,
|
|
40
|
+
partialSign
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
async signData(address, payload) {
|
|
44
|
+
return await this.sendMessage('cardano(data.sign)', {
|
|
45
|
+
address,
|
|
46
|
+
payload
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
async submitTx(tx) {
|
|
50
|
+
return await this.sendMessage('cardano(transaction.submit)', tx);
|
|
51
|
+
}
|
|
52
|
+
async getBalance() {
|
|
53
|
+
return await this.sendMessage('cardano(account.get.balance)');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CardanoExtensionCIP, CardanoProvider } from '@subwallet/extension-inject/types';
|
|
2
|
+
import { CIP30Api } from '@subwallet/extension-base/page/cardano/cips';
|
|
3
|
+
import { SendRequest } from '@subwallet/extension-base/page/types';
|
|
4
|
+
export default class SubWalletCardanoProvider implements CardanoProvider {
|
|
5
|
+
readonly apiVersion: string;
|
|
6
|
+
readonly icon: string;
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly supportedExtensions: CardanoExtensionCIP[];
|
|
9
|
+
protected sendMessage: SendRequest;
|
|
10
|
+
constructor(sendMessage: SendRequest);
|
|
11
|
+
enable(): Promise<Readonly<CIP30Api>>;
|
|
12
|
+
isEnable(): Promise<boolean>;
|
|
13
|
+
}
|