@subwallet/extension-base 1.3.42-0 → 1.3.44-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 +35 -23
- package/background/errors/BitcoinProviderError.d.ts +1 -1
- package/background/errors/BitcoinProviderError.js +2 -2
- package/background/types.d.ts +1 -1
- package/cjs/background/errors/BitcoinProviderError.js +2 -2
- package/cjs/core/logic-validation/recipientAddress.js +8 -2
- package/cjs/core/logic-validation/request.js +316 -3
- package/cjs/koni/background/handlers/Extension.js +418 -90
- package/cjs/koni/background/handlers/State.js +198 -6
- package/cjs/koni/background/handlers/Tabs.js +119 -6
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/bitcoin/index.js +67 -0
- package/cjs/page/index.js +5 -0
- package/cjs/services/buy-service/index.js +17 -2
- package/cjs/services/earning-service/handlers/native-staking/para-chain.js +27 -5
- package/cjs/services/request-service/handler/AuthRequestHandler.js +18 -0
- package/cjs/services/request-service/handler/BitcoinRequestHandler.js +48 -61
- package/cjs/services/request-service/index.js +2 -2
- package/cjs/services/transaction-service/index.js +71 -2
- package/cjs/utils/auth.js +2 -1
- package/core/logic-validation/recipientAddress.js +8 -2
- package/core/logic-validation/request.d.ts +6 -2
- package/core/logic-validation/request.js +309 -3
- package/koni/background/handlers/Extension.d.ts +3 -0
- package/koni/background/handlers/Extension.js +330 -6
- package/koni/background/handlers/State.d.ts +4 -1
- package/koni/background/handlers/State.js +189 -4
- package/koni/background/handlers/Tabs.d.ts +7 -2
- package/koni/background/handlers/Tabs.js +119 -9
- package/package.json +11 -6
- package/packageInfo.js +1 -1
- package/page/bitcoin/index.d.ts +17 -0
- package/page/bitcoin/index.js +60 -0
- package/page/index.d.ts +2 -1
- package/page/index.js +4 -0
- package/services/balance-service/transfer/cardano-transfer.d.ts +2 -0
- package/services/buy-service/index.js +17 -2
- package/services/earning-service/handlers/native-staking/para-chain.js +27 -5
- package/services/request-service/handler/AuthRequestHandler.js +19 -1
- package/services/request-service/handler/BitcoinRequestHandler.d.ts +3 -4
- package/services/request-service/handler/BitcoinRequestHandler.js +48 -61
- package/services/request-service/index.d.ts +1 -2
- package/services/request-service/index.js +2 -2
- package/services/transaction-service/index.d.ts +1 -0
- package/services/transaction-service/index.js +71 -2
- package/services/transaction-service/types.d.ts +1 -0
- package/types/balance/transfer.d.ts +4 -2
- package/types/buy.d.ts +1 -1
- package/utils/auth.js +3 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="chrome" />
|
|
2
|
-
import { RequestAddPspToken } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
|
+
import { BitcoinRequestGetAddressesResult, RequestAddPspToken } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
3
|
import { MessageTypes, RequestTypes, ResponseTypes } from '@subwallet/extension-base/background/types';
|
|
4
4
|
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
|
|
5
5
|
import { AuthUrlInfo, AuthUrls } from '@subwallet/extension-base/services/request-service/types';
|
|
@@ -42,7 +42,6 @@ export default class KoniTabs {
|
|
|
42
42
|
private checkAndHandleProviderStatus;
|
|
43
43
|
private getEvmProvider;
|
|
44
44
|
private performWeb3Method;
|
|
45
|
-
canUseAccount(address: string, url: string): Promise<boolean>;
|
|
46
45
|
private evmSign;
|
|
47
46
|
evmSendTransaction(id: string, url: string, { params }: RequestArguments): Promise<string>;
|
|
48
47
|
private handleEvmRequest;
|
|
@@ -60,5 +59,11 @@ export default class KoniTabs {
|
|
|
60
59
|
private cardanoSignData;
|
|
61
60
|
private cardanoSignTransaction;
|
|
62
61
|
private cardanoSubmitTransaction;
|
|
62
|
+
isBitcoinPublicRequest(type: string, request: RequestArguments): boolean;
|
|
63
|
+
bitcoinGetAddresses(url: string): Promise<BitcoinRequestGetAddressesResult>;
|
|
64
|
+
private bitcoinSign;
|
|
65
|
+
private bitcoinSignPspt;
|
|
66
|
+
private bitcoinSendTransfer;
|
|
67
|
+
private handleBitcoinRequest;
|
|
63
68
|
handle<TMessageType extends MessageTypes>(id: string, type: TMessageType, request: RequestTypes[TMessageType], url: string, port: chrome.runtime.Port): Promise<ResponseTypes[keyof ResponseTypes]>;
|
|
64
69
|
}
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
import * as CardanoWasm from '@emurgo/cardano-serialization-lib-nodejs';
|
|
5
5
|
import { _AssetType } from '@subwallet/chain-list/types';
|
|
6
|
+
import { BitcoinProviderError } from '@subwallet/extension-base/background/errors/BitcoinProviderError';
|
|
6
7
|
import { CardanoProviderError } from '@subwallet/extension-base/background/errors/CardanoProviderError';
|
|
7
8
|
import { EvmProviderError } from '@subwallet/extension-base/background/errors/EvmProviderError';
|
|
8
9
|
import { withErrorLog } from '@subwallet/extension-base/background/handlers/helpers';
|
|
9
10
|
import { createSubscription, unsubscribe } from '@subwallet/extension-base/background/handlers/subscriptions';
|
|
10
|
-
import { CardanoProviderErrorType, EvmProviderErrorType } from '@subwallet/extension-base/background/KoniTypes';
|
|
11
|
+
import { BitcoinProviderErrorType, CardanoProviderErrorType, EvmProviderErrorType } from '@subwallet/extension-base/background/KoniTypes';
|
|
11
12
|
import RequestBytesSign from '@subwallet/extension-base/background/RequestBytesSign';
|
|
12
13
|
import RequestExtrinsicSign from '@subwallet/extension-base/background/RequestExtrinsicSign';
|
|
13
14
|
import { ALL_ACCOUNT_KEY, CRON_GET_API_MAP_STATUS, MAX_COLLATERAL_AMOUNT, PERMISSIONS_TO_REVOKE } from '@subwallet/extension-base/constants';
|
|
@@ -18,11 +19,12 @@ import { _generateCustomProviderKey } from '@subwallet/extension-base/services/c
|
|
|
18
19
|
import { hasSufficientCardanoValue } from '@subwallet/extension-base/services/request-service/helper';
|
|
19
20
|
import { DEFAULT_CHAIN_PATROL_ENABLE } from '@subwallet/extension-base/services/setting-service/constants';
|
|
20
21
|
import { convertCardanoAddressToHex, getEVMChainInfo, reformatAddress, stripUrl } from '@subwallet/extension-base/utils';
|
|
21
|
-
import { CardanoKeypairTypes, EthereumKeypairTypes, SubstrateKeypairTypes, TonKeypairTypes } from '@subwallet/keyring/types';
|
|
22
|
+
import { BitcoinKeypairTypes, CardanoKeypairTypes, EthereumKeypairTypes, SubstrateKeypairTypes, TonKeypairTypes } from '@subwallet/keyring/types';
|
|
23
|
+
import { getBitcoinAddressInfo } from '@subwallet/keyring/utils';
|
|
22
24
|
import { keyring } from '@subwallet/ui-keyring';
|
|
23
25
|
import Web3 from 'web3';
|
|
24
26
|
import { checkIfDenied } from '@polkadot/phishing';
|
|
25
|
-
import { isArray, isNumber } from '@polkadot/util';
|
|
27
|
+
import { hexStripPrefix, isArray, isNumber, u8aToHex } from '@polkadot/util';
|
|
26
28
|
import { isEthereumAddress } from '@polkadot/util-crypto';
|
|
27
29
|
function transformAccountsV2(accounts, anyType = false, authInfo, accountAuthTypes) {
|
|
28
30
|
const accountSelected = authInfo ? authInfo.isAllowed ? Object.keys(authInfo.isAllowedMap).filter(address => authInfo.isAllowedMap[address]) : [] : [];
|
|
@@ -38,7 +40,8 @@ function transformAccountsV2(accounts, anyType = false, authInfo, accountAuthTyp
|
|
|
38
40
|
evm: EthereumKeypairTypes,
|
|
39
41
|
substrate: SubstrateKeypairTypes,
|
|
40
42
|
ton: TonKeypairTypes,
|
|
41
|
-
cardano: CardanoKeypairTypes
|
|
43
|
+
cardano: CardanoKeypairTypes,
|
|
44
|
+
bitcoin: BitcoinKeypairTypes
|
|
42
45
|
};
|
|
43
46
|
const isValidTypes = accountAuthTypes.some(authType => {
|
|
44
47
|
var _validTypes$authType;
|
|
@@ -911,10 +914,6 @@ export default class KoniTabs {
|
|
|
911
914
|
});
|
|
912
915
|
});
|
|
913
916
|
}
|
|
914
|
-
async canUseAccount(address, url) {
|
|
915
|
-
const allowedAccounts = await this.getCurrentAccount(url, 'evm');
|
|
916
|
-
return !!allowedAccounts.find(acc => acc.toLowerCase() === address.toLowerCase());
|
|
917
|
-
}
|
|
918
917
|
async evmSign(id, url, {
|
|
919
918
|
method,
|
|
920
919
|
params
|
|
@@ -1276,6 +1275,113 @@ export default class KoniTabs {
|
|
|
1276
1275
|
throw new CardanoProviderError(CardanoProviderErrorType.INTERNAL_ERROR, 'Failed to submit transaction');
|
|
1277
1276
|
}
|
|
1278
1277
|
}
|
|
1278
|
+
|
|
1279
|
+
/// Bitcoin
|
|
1280
|
+
|
|
1281
|
+
isBitcoinPublicRequest(type, request) {
|
|
1282
|
+
return type === 'bitcoin(request)' && ['getAddresses'].includes(request === null || request === void 0 ? void 0 : request.method);
|
|
1283
|
+
}
|
|
1284
|
+
async bitcoinGetAddresses(url) {
|
|
1285
|
+
try {
|
|
1286
|
+
const isCompleted = await this.#koniState.authorizeUrlV2(url, {
|
|
1287
|
+
origin: url,
|
|
1288
|
+
accountAuthTypes: ['bitcoin']
|
|
1289
|
+
});
|
|
1290
|
+
const result = [];
|
|
1291
|
+
if (!isCompleted) {
|
|
1292
|
+
return result;
|
|
1293
|
+
}
|
|
1294
|
+
const authInfo = await this.getAuthInfo(url);
|
|
1295
|
+
if (!authInfo || !authInfo.isAllowedMap || !authInfo.isAllowed) {
|
|
1296
|
+
return result;
|
|
1297
|
+
}
|
|
1298
|
+
const addressesAllowed = await this.getCurrentAccount(url, 'bitcoin');
|
|
1299
|
+
const addressResults = [];
|
|
1300
|
+
addressesAllowed.forEach(address => {
|
|
1301
|
+
const pair = keyring.getPair(address);
|
|
1302
|
+
if (pair.meta.noPublicKey) {
|
|
1303
|
+
return;
|
|
1304
|
+
}
|
|
1305
|
+
const addressInfo = getBitcoinAddressInfo(address);
|
|
1306
|
+
const item = {
|
|
1307
|
+
address,
|
|
1308
|
+
type: addressInfo.type,
|
|
1309
|
+
isTestnet: addressInfo.network === 'testnet'
|
|
1310
|
+
};
|
|
1311
|
+
item.derivationPath = pair.meta.derivationPath;
|
|
1312
|
+
item.publicKey = hexStripPrefix(u8aToHex(pair.publicKey));
|
|
1313
|
+
if (pair.publicKey.length !== 32) {
|
|
1314
|
+
item.tweakedPublicKey = hexStripPrefix(u8aToHex(pair.publicKey.slice(1, 33)));
|
|
1315
|
+
}
|
|
1316
|
+
addressResults.push(item);
|
|
1317
|
+
});
|
|
1318
|
+
return addressResults;
|
|
1319
|
+
} catch (e) {
|
|
1320
|
+
throw new BitcoinProviderError(BitcoinProviderErrorType.USER_REJECTED_REQUEST);
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
async bitcoinSign(id, url, {
|
|
1324
|
+
method,
|
|
1325
|
+
params
|
|
1326
|
+
}) {
|
|
1327
|
+
const signResult = await this.#koniState.bitcoinSign(id, url, method, params);
|
|
1328
|
+
if (signResult) {
|
|
1329
|
+
return signResult;
|
|
1330
|
+
} else {
|
|
1331
|
+
throw new BitcoinProviderError(BitcoinProviderErrorType.INVALID_PARAMS, 'Failed to sign message');
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
async bitcoinSignPspt(id, url, {
|
|
1335
|
+
method,
|
|
1336
|
+
params
|
|
1337
|
+
}) {
|
|
1338
|
+
const psbtParams = params;
|
|
1339
|
+
const signResult = await this.#koniState.bitcoinSignPspt(id, url, psbtParams);
|
|
1340
|
+
if (signResult) {
|
|
1341
|
+
return signResult;
|
|
1342
|
+
} else {
|
|
1343
|
+
throw new BitcoinProviderError(BitcoinProviderErrorType.INVALID_PARAMS, 'Failed to sign message');
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
async bitcoinSendTransfer(id, url, {
|
|
1347
|
+
params
|
|
1348
|
+
}) {
|
|
1349
|
+
const transactionParams = params;
|
|
1350
|
+
const transactionHash = await this.#koniState.bitcoinSendTransaction(id, url, transactionParams);
|
|
1351
|
+
if (!transactionHash) {
|
|
1352
|
+
throw new BitcoinProviderError(BitcoinProviderErrorType.USER_REJECTED_REQUEST);
|
|
1353
|
+
}
|
|
1354
|
+
return {
|
|
1355
|
+
txid: transactionHash
|
|
1356
|
+
};
|
|
1357
|
+
}
|
|
1358
|
+
async handleBitcoinRequest(id, url, request, port) {
|
|
1359
|
+
const {
|
|
1360
|
+
method
|
|
1361
|
+
} = request;
|
|
1362
|
+
try {
|
|
1363
|
+
switch (method) {
|
|
1364
|
+
case 'getAddresses':
|
|
1365
|
+
return await this.bitcoinGetAddresses(url);
|
|
1366
|
+
case 'signMessage':
|
|
1367
|
+
return await this.bitcoinSign(id, url, request);
|
|
1368
|
+
case 'signPsbt':
|
|
1369
|
+
return await this.bitcoinSignPspt(id, url, request);
|
|
1370
|
+
case 'sendTransfer':
|
|
1371
|
+
return await this.bitcoinSendTransfer(id, url, request);
|
|
1372
|
+
default:
|
|
1373
|
+
throw new Error(`Method ${method} is not supported by SubWalletBitcoin provider`);
|
|
1374
|
+
}
|
|
1375
|
+
} catch (e) {
|
|
1376
|
+
// @ts-ignore
|
|
1377
|
+
if (e.code) {
|
|
1378
|
+
throw e;
|
|
1379
|
+
} else {
|
|
1380
|
+
console.error(e);
|
|
1381
|
+
throw new BitcoinProviderError(BitcoinProviderErrorType.INTERNAL_ERROR, e === null || e === void 0 ? void 0 : e.toString());
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1279
1385
|
async handle(id, type, request, url, port) {
|
|
1280
1386
|
if (type === 'pub(phishing.redirectIfDenied)') {
|
|
1281
1387
|
return this.redirectIfPhishing(url);
|
|
@@ -1286,7 +1392,7 @@ export default class KoniTabs {
|
|
|
1286
1392
|
|
|
1287
1393
|
// Wait for account ready and chain ready
|
|
1288
1394
|
await Promise.all([this.#koniState.eventService.waitAccountReady, this.#koniState.eventService.waitChainReady]);
|
|
1289
|
-
if (!['pub(authorize.tabV2)', 'pub(accounts.subscribeV2)'].includes(type) && !this.isEvmPublicRequest(type, request)) {
|
|
1395
|
+
if (!['pub(authorize.tabV2)', 'pub(accounts.subscribeV2)'].includes(type) && !this.isEvmPublicRequest(type, request) && !this.isBitcoinPublicRequest(type, request)) {
|
|
1290
1396
|
await this.#koniState.ensureUrlAuthorizedV2(url).catch(e => {
|
|
1291
1397
|
if (type.startsWith('evm')) {
|
|
1292
1398
|
throw new EvmProviderError(EvmProviderErrorType.INTERNAL_ERROR, e.message);
|
|
@@ -1357,6 +1463,10 @@ export default class KoniTabs {
|
|
|
1357
1463
|
return await this.cardanoSignTransaction(id, url, request);
|
|
1358
1464
|
case 'cardano(transaction.submit)':
|
|
1359
1465
|
return await this.cardanoSubmitTransaction(id, url, request);
|
|
1466
|
+
|
|
1467
|
+
// Bitcoin
|
|
1468
|
+
case 'bitcoin(request)':
|
|
1469
|
+
return await this.handleBitcoinRequest(id, url, request, port);
|
|
1360
1470
|
default:
|
|
1361
1471
|
throw new Error(`Unable to handle message of type ${type}`);
|
|
1362
1472
|
}
|
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.44-0",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -609,6 +609,11 @@
|
|
|
609
609
|
"require": "./cjs/page/index.js",
|
|
610
610
|
"default": "./page/index.js"
|
|
611
611
|
},
|
|
612
|
+
"./page/bitcoin": {
|
|
613
|
+
"types": "./page/bitcoin/index.d.ts",
|
|
614
|
+
"require": "./cjs/page/bitcoin/index.js",
|
|
615
|
+
"default": "./page/bitcoin/index.js"
|
|
616
|
+
},
|
|
612
617
|
"./page/cardano": {
|
|
613
618
|
"types": "./page/cardano/index.d.ts",
|
|
614
619
|
"require": "./cjs/page/cardano/index.js",
|
|
@@ -2850,12 +2855,12 @@
|
|
|
2850
2855
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
2851
2856
|
"@substrate/connect": "^0.8.9",
|
|
2852
2857
|
"@subwallet/chain-list": "0.2.107",
|
|
2853
|
-
"@subwallet/extension-base": "^1.3.
|
|
2854
|
-
"@subwallet/extension-chains": "^1.3.
|
|
2855
|
-
"@subwallet/extension-dapp": "^1.3.
|
|
2856
|
-
"@subwallet/extension-inject": "^1.3.
|
|
2858
|
+
"@subwallet/extension-base": "^1.3.44-0",
|
|
2859
|
+
"@subwallet/extension-chains": "^1.3.44-0",
|
|
2860
|
+
"@subwallet/extension-dapp": "^1.3.44-0",
|
|
2861
|
+
"@subwallet/extension-inject": "^1.3.44-0",
|
|
2857
2862
|
"@subwallet/keyring": "^0.1.12",
|
|
2858
|
-
"@subwallet/subwallet-api-sdk": "^1.3.
|
|
2863
|
+
"@subwallet/subwallet-api-sdk": "^1.3.44-0",
|
|
2859
2864
|
"@subwallet/ui-keyring": "^0.1.12",
|
|
2860
2865
|
"@ton/core": "^0.56.3",
|
|
2861
2866
|
"@ton/crypto": "^3.2.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.44-0'
|
|
11
11
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SendRequest } from '@subwallet/extension-base/page/types';
|
|
2
|
+
import { BitcoinProvider } from '@subwallet/extension-inject/types';
|
|
3
|
+
export default class SubWalletBitcoinProvider {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly version: string;
|
|
6
|
+
protected sendMessage: SendRequest;
|
|
7
|
+
private isSubWallet;
|
|
8
|
+
constructor(sendMessage: SendRequest);
|
|
9
|
+
private requestAccounts;
|
|
10
|
+
private getAccounts;
|
|
11
|
+
private signMessage;
|
|
12
|
+
private signPsbt;
|
|
13
|
+
private sendTransfer;
|
|
14
|
+
private request;
|
|
15
|
+
private getProductInfo;
|
|
16
|
+
get apis(): BitcoinProvider;
|
|
17
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
const WALLET_NAME = 'SubWallet';
|
|
5
|
+
const WALLET_VERSION = process.env.PKG_VERSION;
|
|
6
|
+
export default class SubWalletBitcoinProvider {
|
|
7
|
+
name = WALLET_NAME;
|
|
8
|
+
version = WALLET_VERSION;
|
|
9
|
+
isSubWallet = true;
|
|
10
|
+
constructor(sendMessage) {
|
|
11
|
+
this.sendMessage = sendMessage;
|
|
12
|
+
}
|
|
13
|
+
async requestAccounts() {
|
|
14
|
+
return await this.request('getAccounts');
|
|
15
|
+
}
|
|
16
|
+
async getAccounts() {
|
|
17
|
+
return await this.request('getAccounts');
|
|
18
|
+
}
|
|
19
|
+
async signMessage(params) {
|
|
20
|
+
return await this.request('signMessage', params);
|
|
21
|
+
}
|
|
22
|
+
async signPsbt(params) {
|
|
23
|
+
return await this.request('signPsbt', params);
|
|
24
|
+
}
|
|
25
|
+
async sendTransfer(params) {
|
|
26
|
+
return await this.request('sendTransfer', params);
|
|
27
|
+
}
|
|
28
|
+
request(method, params) {
|
|
29
|
+
// Implement this method
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
32
|
+
this.sendMessage('bitcoin(request)', {
|
|
33
|
+
method,
|
|
34
|
+
params
|
|
35
|
+
}).then(result => {
|
|
36
|
+
resolve(result);
|
|
37
|
+
}).catch(e => {
|
|
38
|
+
reject(e);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
getProductInfo() {
|
|
43
|
+
return {
|
|
44
|
+
name: this.name,
|
|
45
|
+
version: this.version
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
get apis() {
|
|
49
|
+
return {
|
|
50
|
+
isSubWallet: this.isSubWallet,
|
|
51
|
+
request: (method, params) => this.request(method, params),
|
|
52
|
+
getAccounts: () => this.getAccounts(),
|
|
53
|
+
signMessage: params => this.signMessage(params),
|
|
54
|
+
signPsbt: params => this.signPsbt(params),
|
|
55
|
+
sendTransfer: params => this.sendTransfer(params),
|
|
56
|
+
requestAccounts: () => this.requestAccounts(),
|
|
57
|
+
getProductInfo: () => this.getProductInfo()
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
package/page/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MessageTypes, MessageTypesWithNoSubscriptions, MessageTypesWithNullRequest, MessageTypesWithSubscriptions, RequestTypes, ResponseTypes, SubscriptionMessageTypes, TransportResponseMessage } from '../background/types';
|
|
2
2
|
import Injected from '@subwallet/extension-base/page/substrate';
|
|
3
|
-
import { AuthRequestOption, CardanoProvider, EvmProvider } from '@subwallet/extension-inject/types';
|
|
3
|
+
import { AuthRequestOption, BitcoinProvider, CardanoProvider, EvmProvider } from '@subwallet/extension-inject/types';
|
|
4
4
|
export interface Handler {
|
|
5
5
|
resolve: (data?: any) => void;
|
|
6
6
|
reject: (error: Error) => void;
|
|
@@ -16,3 +16,4 @@ export declare function handleResponse<TMessageType extends MessageTypes>(data:
|
|
|
16
16
|
}): void;
|
|
17
17
|
export declare function initEvmProvider(version: string): EvmProvider;
|
|
18
18
|
export declare function initCardanoProvider(): CardanoProvider;
|
|
19
|
+
export declare function initBitcoinProvider(): BitcoinProvider;
|
package/page/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { ProviderError } from '@subwallet/extension-base/background/errors/ProviderError';
|
|
5
5
|
import { ProviderErrorType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
|
+
import SubWalletBitcoinProvider from '@subwallet/extension-base/page/bitcoin';
|
|
6
7
|
import SubWalletCardanoProvider from '@subwallet/extension-base/page/cardano';
|
|
7
8
|
import SubWalletEvmProvider from '@subwallet/extension-base/page/evm';
|
|
8
9
|
import Injected from '@subwallet/extension-base/page/substrate';
|
|
@@ -72,4 +73,7 @@ export function initEvmProvider(version) {
|
|
|
72
73
|
}
|
|
73
74
|
export function initCardanoProvider() {
|
|
74
75
|
return new SubWalletCardanoProvider(sendMessage);
|
|
76
|
+
}
|
|
77
|
+
export function initBitcoinProvider() {
|
|
78
|
+
return new SubWalletBitcoinProvider(sendMessage).apis;
|
|
75
79
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { _ChainAsset } from '@subwallet/chain-list/types';
|
|
2
|
+
import { ErrorValidation } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
3
|
import { _CardanoApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
3
4
|
export interface CardanoTransactionConfigProps {
|
|
4
5
|
tokenInfo: _ChainAsset;
|
|
@@ -20,5 +21,6 @@ export interface CardanoTransactionConfig {
|
|
|
20
21
|
cardanoTtlOffset: number;
|
|
21
22
|
estimateCardanoFee: string;
|
|
22
23
|
cardanoPayload: string;
|
|
24
|
+
errors?: ErrorValidation[];
|
|
23
25
|
}
|
|
24
26
|
export declare function createCardanoTransaction(params: CardanoTransactionConfigProps): Promise<[CardanoTransactionConfig | null, string]>;
|
|
@@ -6,7 +6,18 @@ import { fetchStaticData } from '@subwallet/extension-base/utils/fetchStaticData
|
|
|
6
6
|
import { BehaviorSubject } from 'rxjs';
|
|
7
7
|
import { DEFAULT_SERVICE_INFO } from "./constants/index.js";
|
|
8
8
|
const convertSupportType = support => {
|
|
9
|
-
|
|
9
|
+
switch (support) {
|
|
10
|
+
case 'ETHEREUM':
|
|
11
|
+
return AccountChainType.ETHEREUM;
|
|
12
|
+
case 'SUBSTRATE':
|
|
13
|
+
return AccountChainType.SUBSTRATE;
|
|
14
|
+
case 'CARDANO':
|
|
15
|
+
return AccountChainType.CARDANO;
|
|
16
|
+
case 'TON':
|
|
17
|
+
return AccountChainType.TON;
|
|
18
|
+
default:
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
10
21
|
};
|
|
11
22
|
export default class BuyService {
|
|
12
23
|
#state;
|
|
@@ -29,11 +40,15 @@ export default class BuyService {
|
|
|
29
40
|
const data = await fetchStaticData('buy-token-configs');
|
|
30
41
|
const result = {};
|
|
31
42
|
for (const datum of data) {
|
|
43
|
+
const support = convertSupportType(datum.support);
|
|
44
|
+
if (!support) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
32
47
|
const temp = {
|
|
33
48
|
serviceInfo: {
|
|
34
49
|
...DEFAULT_SERVICE_INFO
|
|
35
50
|
},
|
|
36
|
-
support
|
|
51
|
+
support,
|
|
37
52
|
services: [],
|
|
38
53
|
slug: datum.slug,
|
|
39
54
|
symbol: datum.symbol,
|
|
@@ -426,6 +426,10 @@ export default class ParaNativeStakingPoolHandler extends BaseParaNativeStakingP
|
|
|
426
426
|
const apiPromise = await this.substrateApi.isReady;
|
|
427
427
|
const binaryAmount = new BN(amount);
|
|
428
428
|
const selectedCollatorInfo = selectedValidators[0];
|
|
429
|
+
const {
|
|
430
|
+
address: selectedCollatorAddress,
|
|
431
|
+
nominatorCount: selectedCollatorNominatorCount
|
|
432
|
+
} = selectedCollatorInfo;
|
|
429
433
|
|
|
430
434
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
431
435
|
const compoundResult = async extrinsic => {
|
|
@@ -440,8 +444,17 @@ export default class ParaNativeStakingPoolHandler extends BaseParaNativeStakingP
|
|
|
440
444
|
}];
|
|
441
445
|
};
|
|
442
446
|
if (!positionInfo) {
|
|
443
|
-
|
|
444
|
-
|
|
447
|
+
var _apiPromise$api;
|
|
448
|
+
const isTxSupportedDelegate = !!((_apiPromise$api = apiPromise.api) !== null && _apiPromise$api !== void 0 && _apiPromise$api.tx.parachainStaking.delegate);
|
|
449
|
+
if (isTxSupportedDelegate) {
|
|
450
|
+
const extrinsic = apiPromise.api.tx.parachainStaking.delegate(selectedCollatorAddress, binaryAmount, new BN(selectedCollatorNominatorCount), 0);
|
|
451
|
+
return compoundResult(extrinsic);
|
|
452
|
+
} else {
|
|
453
|
+
var _apiPromise$api$query, _apiPromise$api$query2;
|
|
454
|
+
const autoCompoundingDelegation = await ((_apiPromise$api$query = apiPromise.api.query) === null || _apiPromise$api$query === void 0 ? void 0 : (_apiPromise$api$query2 = _apiPromise$api$query.parachainStaking) === null || _apiPromise$api$query2 === void 0 ? void 0 : _apiPromise$api$query2.autoCompoundingDelegations(selectedCollatorAddress));
|
|
455
|
+
const extrinsic = apiPromise.api.tx.parachainStaking.delegateWithAutoCompound(selectedCollatorAddress, binaryAmount, 100, new BN(selectedCollatorNominatorCount), new BN(autoCompoundingDelegation.length), 0);
|
|
456
|
+
return compoundResult(extrinsic);
|
|
457
|
+
}
|
|
445
458
|
}
|
|
446
459
|
const {
|
|
447
460
|
bondedValidators,
|
|
@@ -449,10 +462,19 @@ export default class ParaNativeStakingPoolHandler extends BaseParaNativeStakingP
|
|
|
449
462
|
} = getBondedValidators(positionInfo.nominations);
|
|
450
463
|
const parsedSelectedCollatorAddress = reformatAddress(selectedCollatorInfo.address, 0);
|
|
451
464
|
if (!bondedValidators.includes(parsedSelectedCollatorAddress)) {
|
|
452
|
-
|
|
453
|
-
|
|
465
|
+
var _apiPromise$api2;
|
|
466
|
+
const isTxSupportedDelegate = !!((_apiPromise$api2 = apiPromise.api) !== null && _apiPromise$api2 !== void 0 && _apiPromise$api2.tx.parachainStaking.delegate);
|
|
467
|
+
if (isTxSupportedDelegate) {
|
|
468
|
+
const extrinsic = apiPromise.api.tx.parachainStaking.delegate(selectedCollatorAddress, binaryAmount, new BN(selectedCollatorNominatorCount), nominationCount);
|
|
469
|
+
return compoundResult(extrinsic);
|
|
470
|
+
} else {
|
|
471
|
+
var _apiPromise$api$query3, _apiPromise$api$query4;
|
|
472
|
+
const autoCompoundingDelegation = await ((_apiPromise$api$query3 = apiPromise.api.query) === null || _apiPromise$api$query3 === void 0 ? void 0 : (_apiPromise$api$query4 = _apiPromise$api$query3.parachainStaking) === null || _apiPromise$api$query4 === void 0 ? void 0 : _apiPromise$api$query4.autoCompoundingDelegations(selectedCollatorAddress));
|
|
473
|
+
const extrinsic = apiPromise.api.tx.parachainStaking.delegateWithAutoCompound(selectedCollatorAddress, binaryAmount, 100, new BN(selectedCollatorNominatorCount), new BN(autoCompoundingDelegation.length), nominationCount);
|
|
474
|
+
return compoundResult(extrinsic);
|
|
475
|
+
}
|
|
454
476
|
} else {
|
|
455
|
-
const extrinsic = apiPromise.api.tx.parachainStaking.delegatorBondMore(
|
|
477
|
+
const extrinsic = apiPromise.api.tx.parachainStaking.delegatorBondMore(selectedCollatorAddress, binaryAmount);
|
|
456
478
|
return compoundResult(extrinsic);
|
|
457
479
|
}
|
|
458
480
|
}
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { ALL_ACCOUNT_AUTH_TYPES } from '@subwallet/extension-base/constants';
|
|
5
|
-
import { _isChainCardanoCompatible, _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
5
|
+
import { _isChainBitcoinCompatible, _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
10
|
import { isCardanoAddress, isSubstrateAddress, isTonAddress } from '@subwallet/keyring';
|
|
11
|
+
import { isBitcoinAddress } from '@subwallet/keyring/utils/address/validate';
|
|
11
12
|
import { BehaviorSubject } from 'rxjs';
|
|
12
13
|
import { isEthereumAddress } from '@polkadot/util-crypto';
|
|
13
14
|
const AUTH_URLS_KEY = 'authUrls';
|
|
@@ -166,6 +167,18 @@ export default class AuthRequestHandler {
|
|
|
166
167
|
}
|
|
167
168
|
}
|
|
168
169
|
}
|
|
170
|
+
if (options.accessType === 'bitcoin') {
|
|
171
|
+
const bitcoinChains = Object.values(chainInfoMaps).filter(_isChainBitcoinCompatible);
|
|
172
|
+
chainInfo = (defaultChain ? chainInfoMaps[defaultChain] : chainInfoMaps.bitcoin) || bitcoinChains[0]; // auto active cardano mainnet chain, because dont support switch network yet
|
|
173
|
+
|
|
174
|
+
if (options.autoActive) {
|
|
175
|
+
var _chainInfo5;
|
|
176
|
+
if (!needEnableChains.includes((_chainInfo5 = chainInfo) === null || _chainInfo5 === void 0 ? void 0 : _chainInfo5.slug)) {
|
|
177
|
+
var _chainInfo6;
|
|
178
|
+
needEnableChains.push((_chainInfo6 = chainInfo) === null || _chainInfo6 === void 0 ? void 0 : _chainInfo6.slug);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
169
182
|
needEnableChains = needEnableChains.filter(slug => {
|
|
170
183
|
var _chainStateMap$slug;
|
|
171
184
|
return !((_chainStateMap$slug = chainStateMap[slug]) !== null && _chainStateMap$slug !== void 0 && _chainStateMap$slug.active);
|
|
@@ -217,6 +230,9 @@ export default class AuthRequestHandler {
|
|
|
217
230
|
if (isCardanoAddress(a) && !accountAuthTypes.includes('cardano')) {
|
|
218
231
|
return true;
|
|
219
232
|
}
|
|
233
|
+
if (isBitcoinAddress(a) && !accountAuthTypes.includes('bitcoin')) {
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
220
236
|
return false;
|
|
221
237
|
});
|
|
222
238
|
backupAllowed.forEach(acc => {
|
|
@@ -365,6 +381,8 @@ export default class AuthRequestHandler {
|
|
|
365
381
|
list.push(...allowedListByRequestType.filter(a => isTonAddress(a)));
|
|
366
382
|
} else if (accountAuthType === 'cardano') {
|
|
367
383
|
list.push(...allowedListByRequestType.filter(a => isCardanoAddress(a)));
|
|
384
|
+
} else if (accountAuthType === 'bitcoin') {
|
|
385
|
+
list.push(...allowedListByRequestType.filter(a => isBitcoinAddress(a)));
|
|
368
386
|
}
|
|
369
387
|
return list;
|
|
370
388
|
}, []);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { ConfirmationDefinitionsBitcoin, ConfirmationsQueueBitcoin, ConfirmationsQueueItemOptions, ConfirmationTypeBitcoin, RequestConfirmationCompleteBitcoin
|
|
1
|
+
import { BitcoinSignMessageResult, ConfirmationDefinitionsBitcoin, ConfirmationsQueueBitcoin, ConfirmationsQueueItemOptions, ConfirmationTypeBitcoin, RequestConfirmationCompleteBitcoin } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
2
|
import { ChainService } from '@subwallet/extension-base/services/chain-service';
|
|
3
|
-
import FeeService from '@subwallet/extension-base/services/fee-service/service';
|
|
4
3
|
import RequestService from '@subwallet/extension-base/services/request-service';
|
|
5
4
|
import TransactionService from '@subwallet/extension-base/services/transaction-service';
|
|
6
5
|
import { BehaviorSubject } from 'rxjs';
|
|
@@ -8,12 +7,12 @@ export default class BitcoinRequestHandler {
|
|
|
8
7
|
#private;
|
|
9
8
|
private readonly confirmationsQueueSubjectBitcoin;
|
|
10
9
|
private readonly confirmationsPromiseMap;
|
|
11
|
-
constructor(requestService: RequestService, chainService: ChainService,
|
|
10
|
+
constructor(requestService: RequestService, chainService: ChainService, transactionService: TransactionService);
|
|
12
11
|
get numBitcoinRequests(): number;
|
|
13
12
|
getConfirmationsQueueSubjectBitcoin(): BehaviorSubject<ConfirmationsQueueBitcoin>;
|
|
14
13
|
addConfirmationBitcoin<CT extends ConfirmationTypeBitcoin>(id: string, url: string, type: CT, payload: ConfirmationDefinitionsBitcoin[CT][0]['payload'], options?: ConfirmationsQueueItemOptions, validator?: (input: ConfirmationDefinitionsBitcoin[CT][1]) => Error | undefined): Promise<ConfirmationDefinitionsBitcoin[CT][1]>;
|
|
15
14
|
updateConfirmationBitcoin<CT extends ConfirmationTypeBitcoin>(id: string, type: CT, payload: ConfirmationDefinitionsBitcoin[CT][0]['payload'], options?: ConfirmationsQueueItemOptions, validator?: (input: ConfirmationDefinitionsBitcoin[CT][1]) => Error | undefined): void;
|
|
16
|
-
signMessageBitcoin(confirmation: ConfirmationDefinitionsBitcoin['bitcoinSignatureRequest'][0]):
|
|
15
|
+
signMessageBitcoin(confirmation: ConfirmationDefinitionsBitcoin['bitcoinSignatureRequest'][0]): BitcoinSignMessageResult;
|
|
17
16
|
private signTransactionBitcoin;
|
|
18
17
|
private signTransactionBitcoinWithPayload;
|
|
19
18
|
private signPsbt;
|