@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
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var CardanoWasm = _interopRequireWildcard(require("@emurgo/cardano-serialization-lib-nodejs"));
|
|
9
|
+
var _BitcoinProviderError = require("@subwallet/extension-base/background/errors/BitcoinProviderError");
|
|
9
10
|
var _CardanoProviderError = require("@subwallet/extension-base/background/errors/CardanoProviderError");
|
|
10
11
|
var _EvmProviderError = require("@subwallet/extension-base/background/errors/EvmProviderError");
|
|
11
12
|
var _helpers = require("@subwallet/extension-base/background/handlers/helpers");
|
|
@@ -49,6 +50,8 @@ var _cardano = require("@subwallet/extension-base/utils/cardano");
|
|
|
49
50
|
var _promise = require("@subwallet/extension-base/utils/promise");
|
|
50
51
|
var _subwalletApiSdk = _interopRequireDefault(require("@subwallet/subwallet-api-sdk"));
|
|
51
52
|
var _uiKeyring = require("@subwallet/ui-keyring");
|
|
53
|
+
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
54
|
+
var bitcoin = _interopRequireWildcard(require("bitcoinjs-lib"));
|
|
52
55
|
var _bn = _interopRequireDefault(require("bn.js"));
|
|
53
56
|
var _i18next = require("i18next");
|
|
54
57
|
var _rxjs = require("rxjs");
|
|
@@ -113,7 +116,7 @@ class KoniState {
|
|
|
113
116
|
this.chainService = new _chainService.ChainService(this.dbService, this.eventService);
|
|
114
117
|
this.subscanService = _subscanService.SubscanService.getInstance();
|
|
115
118
|
this.settingService = new _SettingService.default();
|
|
116
|
-
this.requestService = new _requestService.default(this.chainService, this.settingService, this.keyringService, this.
|
|
119
|
+
this.requestService = new _requestService.default(this.chainService, this.settingService, this.keyringService, this.transactionService);
|
|
117
120
|
this.priceService = new _priceService.PriceService(this.dbService, this.eventService, this.chainService);
|
|
118
121
|
this.balanceService = new _balanceService.BalanceService(this);
|
|
119
122
|
this.historyService = new _historyService.HistoryService(this.dbService, this.chainService, this.eventService, this.keyringService, this.subscanService);
|
|
@@ -1043,6 +1046,8 @@ class KoniState {
|
|
|
1043
1046
|
});
|
|
1044
1047
|
});
|
|
1045
1048
|
}
|
|
1049
|
+
|
|
1050
|
+
// Cardano
|
|
1046
1051
|
async cardanoGetBalance(id, url, address) {
|
|
1047
1052
|
const authInfoMap = await this.getAuthList();
|
|
1048
1053
|
const authInfo = authInfoMap[(0, _utils3.stripUrl)(url)];
|
|
@@ -1265,6 +1270,193 @@ class KoniState {
|
|
|
1265
1270
|
const cardanoApi = this.chainService.getCardanoApi(networkKey);
|
|
1266
1271
|
return await cardanoApi.sendCardanoTxReturnHash(txHex);
|
|
1267
1272
|
}
|
|
1273
|
+
|
|
1274
|
+
// Bitcoin
|
|
1275
|
+
async bitcoinSign(id, url, method, params) {
|
|
1276
|
+
const {
|
|
1277
|
+
address,
|
|
1278
|
+
message
|
|
1279
|
+
} = params;
|
|
1280
|
+
const payloadValidation = {
|
|
1281
|
+
address,
|
|
1282
|
+
type: 'bitcoin',
|
|
1283
|
+
payloadAfterValidated: message,
|
|
1284
|
+
errors: [],
|
|
1285
|
+
networkKey: ''
|
|
1286
|
+
};
|
|
1287
|
+
const validationSteps = [_logicValidation.validationAuthMiddleware, _logicValidation.validationBitcoinSignMessageMiddleware];
|
|
1288
|
+
const result = await (0, _logicValidation.generateValidationProcess)(this, url, payloadValidation, validationSteps);
|
|
1289
|
+
const errorsFormated = (0, _logicValidation.convertErrorFormat)(result.errors);
|
|
1290
|
+
const payloadAfterValidated = {
|
|
1291
|
+
...result.payloadAfterValidated,
|
|
1292
|
+
errors: errorsFormated,
|
|
1293
|
+
id
|
|
1294
|
+
};
|
|
1295
|
+
return this.requestService.addConfirmationBitcoin(id, url, 'bitcoinSignatureRequest', payloadAfterValidated, {}).then(_ref9 => {
|
|
1296
|
+
let {
|
|
1297
|
+
isApproved,
|
|
1298
|
+
payload
|
|
1299
|
+
} = _ref9;
|
|
1300
|
+
if (isApproved) {
|
|
1301
|
+
if (payload) {
|
|
1302
|
+
return payload;
|
|
1303
|
+
} else {
|
|
1304
|
+
throw new _BitcoinProviderError.BitcoinProviderError(_KoniTypes.BitcoinProviderErrorType.INVALID_PARAMS, (0, _i18next.t)('Not found signature'));
|
|
1305
|
+
}
|
|
1306
|
+
} else {
|
|
1307
|
+
throw new _BitcoinProviderError.BitcoinProviderError(_KoniTypes.BitcoinProviderErrorType.USER_REJECTED_REQUEST);
|
|
1308
|
+
}
|
|
1309
|
+
});
|
|
1310
|
+
}
|
|
1311
|
+
async bitcoinSignPspt(id, url, params) {
|
|
1312
|
+
const {
|
|
1313
|
+
address,
|
|
1314
|
+
network,
|
|
1315
|
+
psbt
|
|
1316
|
+
} = params;
|
|
1317
|
+
const payloadValidation = {
|
|
1318
|
+
address,
|
|
1319
|
+
type: 'bitcoin',
|
|
1320
|
+
payloadAfterValidated: params,
|
|
1321
|
+
errors: [],
|
|
1322
|
+
networkKey: network === 'mainnet' ? 'bitcoin' : 'bitcoinTestnet'
|
|
1323
|
+
};
|
|
1324
|
+
const validationSteps = [_logicValidation.validationAuthMiddleware, _logicValidation.validationBitcoinConnectMiddleware, _logicValidation.validationBitcoinSignPsbtMiddleware];
|
|
1325
|
+
const result = await (0, _logicValidation.generateValidationProcess)(this, url, payloadValidation, validationSteps);
|
|
1326
|
+
const errorsFormated = (0, _logicValidation.convertErrorFormat)(result.errors);
|
|
1327
|
+
const payloadAfterValidated = {
|
|
1328
|
+
...result.payloadAfterValidated,
|
|
1329
|
+
errors: errorsFormated
|
|
1330
|
+
};
|
|
1331
|
+
const network_ = network === 'mainnet' ? bitcoin.networks.bitcoin : bitcoin.networks.testnet;
|
|
1332
|
+
const psbtGenerate = bitcoin.Psbt.fromHex(psbt, {
|
|
1333
|
+
network: network_
|
|
1334
|
+
});
|
|
1335
|
+
const isExistedInput = (inputs, address) => inputs.findIndex(_ref10 => {
|
|
1336
|
+
let {
|
|
1337
|
+
address: address_
|
|
1338
|
+
} = _ref10;
|
|
1339
|
+
return (0, _utils3.isSameAddress)(address, address_ || '');
|
|
1340
|
+
});
|
|
1341
|
+
let to = '';
|
|
1342
|
+
const tokenInfo = this.getNativeTokenInfo(result.networkKey);
|
|
1343
|
+
let value = new _bignumber.default(0);
|
|
1344
|
+
const totalBalance = await this.balanceService.getTotalBalance(address, result.networkKey, tokenInfo.slug);
|
|
1345
|
+
let inputAmount = new _bignumber.default(0);
|
|
1346
|
+
const psbtInputData = psbtGenerate.data.inputs.reduce((inputs, _ref11, inputIndex) => {
|
|
1347
|
+
let {
|
|
1348
|
+
nonWitnessUtxo,
|
|
1349
|
+
witnessUtxo
|
|
1350
|
+
} = _ref11;
|
|
1351
|
+
let inputData = null;
|
|
1352
|
+
if (witnessUtxo) {
|
|
1353
|
+
inputData = {
|
|
1354
|
+
address: bitcoin.address.fromOutputScript(witnessUtxo === null || witnessUtxo === void 0 ? void 0 : witnessUtxo.script, network_),
|
|
1355
|
+
amount: witnessUtxo.value.toString()
|
|
1356
|
+
};
|
|
1357
|
+
} else if (nonWitnessUtxo) {
|
|
1358
|
+
const txin = psbtGenerate.txInputs[inputIndex];
|
|
1359
|
+
const txout = bitcoin.Transaction.fromBuffer(nonWitnessUtxo).outs[txin.index];
|
|
1360
|
+
inputData = {
|
|
1361
|
+
address: bitcoin.address.fromOutputScript(txout.script, network_),
|
|
1362
|
+
amount: txout.value.toString()
|
|
1363
|
+
};
|
|
1364
|
+
}
|
|
1365
|
+
if (inputData) {
|
|
1366
|
+
inputs.push(inputData);
|
|
1367
|
+
if ((0, _utils3.isSameAddress)(address, inputData.address || '')) {
|
|
1368
|
+
inputAmount = inputAmount.plus(new _bignumber.default(inputData.amount || '0'));
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
return inputs;
|
|
1372
|
+
}, []);
|
|
1373
|
+
if (new _bignumber.default(totalBalance.value).lt(inputAmount)) {
|
|
1374
|
+
payloadAfterValidated.errors = [{
|
|
1375
|
+
message: (0, _i18next.t)('Insufficient balance'),
|
|
1376
|
+
name: (0, _i18next.t)('Unable to sign transaction')
|
|
1377
|
+
}];
|
|
1378
|
+
}
|
|
1379
|
+
const psbtOutputData = psbtGenerate.txOutputs.map(output => {
|
|
1380
|
+
let address = '';
|
|
1381
|
+
try {
|
|
1382
|
+
address = output.address || bitcoin.address.fromOutputScript(output.script, network_);
|
|
1383
|
+
} catch (e) {
|
|
1384
|
+
if (output.script.includes(bitcoin.opcodes.OP_RETURN)) {
|
|
1385
|
+
address = 'OP_RETURN';
|
|
1386
|
+
} else {
|
|
1387
|
+
address = 'Unknown';
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
if (isExistedInput(psbtInputData, address) === -1) {
|
|
1391
|
+
to = address;
|
|
1392
|
+
value = value.plus(new _bignumber.default(output.value));
|
|
1393
|
+
}
|
|
1394
|
+
return {
|
|
1395
|
+
address,
|
|
1396
|
+
amount: output.value.toString()
|
|
1397
|
+
};
|
|
1398
|
+
});
|
|
1399
|
+
payloadAfterValidated.payload = {
|
|
1400
|
+
...payloadAfterValidated.payload,
|
|
1401
|
+
psbt,
|
|
1402
|
+
tokenSlug: tokenInfo.slug,
|
|
1403
|
+
value: value.toString(),
|
|
1404
|
+
to,
|
|
1405
|
+
txInput: psbtInputData,
|
|
1406
|
+
txOutput: psbtOutputData
|
|
1407
|
+
};
|
|
1408
|
+
return this.requestService.addConfirmationBitcoin(id, url, 'bitcoinSignPsbtRequest', payloadAfterValidated, {}).then(_ref12 => {
|
|
1409
|
+
let {
|
|
1410
|
+
isApproved,
|
|
1411
|
+
payload
|
|
1412
|
+
} = _ref12;
|
|
1413
|
+
if (isApproved) {
|
|
1414
|
+
if (payload) {
|
|
1415
|
+
return payload;
|
|
1416
|
+
} else {
|
|
1417
|
+
throw new _BitcoinProviderError.BitcoinProviderError(_KoniTypes.BitcoinProviderErrorType.INVALID_PARAMS, (0, _i18next.t)('Not found signature'));
|
|
1418
|
+
}
|
|
1419
|
+
} else {
|
|
1420
|
+
throw new _BitcoinProviderError.BitcoinProviderError(_KoniTypes.BitcoinProviderErrorType.USER_REJECTED_REQUEST);
|
|
1421
|
+
}
|
|
1422
|
+
});
|
|
1423
|
+
}
|
|
1424
|
+
async bitcoinSendTransaction(id, url, transactionParams) {
|
|
1425
|
+
const payloadValidation = {
|
|
1426
|
+
address: transactionParams.account,
|
|
1427
|
+
type: 'bitcoin',
|
|
1428
|
+
payloadAfterValidated: transactionParams,
|
|
1429
|
+
errors: [],
|
|
1430
|
+
networkKey: transactionParams.network === 'mainnet' ? 'bitcoin' : 'bitcoinTestnet'
|
|
1431
|
+
};
|
|
1432
|
+
const validationSteps = [_logicValidation.validationAuthMiddleware, _logicValidation.validationBitcoinConnectMiddleware, _logicValidation.validationBitcoinSendTransactionMiddleware];
|
|
1433
|
+
const result = await (0, _logicValidation.generateValidationProcess)(this, url, payloadValidation, validationSteps);
|
|
1434
|
+
const errorsFormated = (0, _logicValidation.convertErrorFormat)(result.errors);
|
|
1435
|
+
const requestPayload = {
|
|
1436
|
+
...result.payloadAfterValidated,
|
|
1437
|
+
hashPayload: JSON.stringify(result.payloadAfterValidated),
|
|
1438
|
+
from: transactionParams.account,
|
|
1439
|
+
id,
|
|
1440
|
+
errors: errorsFormated
|
|
1441
|
+
};
|
|
1442
|
+
|
|
1443
|
+
// Custom handle this instead of general handler transaction
|
|
1444
|
+
return this.requestService.addConfirmationBitcoin(id, url, 'bitcoinSendTransactionRequestAfterConfirmation', requestPayload, {}).then(_ref13 => {
|
|
1445
|
+
let {
|
|
1446
|
+
isApproved,
|
|
1447
|
+
payload
|
|
1448
|
+
} = _ref13;
|
|
1449
|
+
if (isApproved) {
|
|
1450
|
+
if (payload) {
|
|
1451
|
+
return payload;
|
|
1452
|
+
} else {
|
|
1453
|
+
throw new _BitcoinProviderError.BitcoinProviderError(_KoniTypes.BitcoinProviderErrorType.INVALID_PARAMS, (0, _i18next.t)('Not found signature'));
|
|
1454
|
+
}
|
|
1455
|
+
} else {
|
|
1456
|
+
throw new _BitcoinProviderError.BitcoinProviderError(_KoniTypes.BitcoinProviderErrorType.USER_REJECTED_REQUEST);
|
|
1457
|
+
}
|
|
1458
|
+
});
|
|
1459
|
+
}
|
|
1268
1460
|
getConfirmationsQueueSubject() {
|
|
1269
1461
|
return this.requestService.confirmationsQueueSubject;
|
|
1270
1462
|
}
|
|
@@ -1359,11 +1551,11 @@ class KoniState {
|
|
|
1359
1551
|
const subscription = this.keyringService.context.observable.currentAccount.subscribe(handleRemind);
|
|
1360
1552
|
}
|
|
1361
1553
|
}
|
|
1362
|
-
async setStorageFromWS(
|
|
1554
|
+
async setStorageFromWS(_ref14) {
|
|
1363
1555
|
let {
|
|
1364
1556
|
key,
|
|
1365
1557
|
value
|
|
1366
|
-
} =
|
|
1558
|
+
} = _ref14;
|
|
1367
1559
|
try {
|
|
1368
1560
|
const jsonData = JSON.stringify(value);
|
|
1369
1561
|
await _storage.SWStorage.instance.setItem(key, jsonData);
|
|
@@ -1505,9 +1697,9 @@ class KoniState {
|
|
|
1505
1697
|
this.eventService.emit('general.start', true);
|
|
1506
1698
|
|
|
1507
1699
|
// Complete starting
|
|
1508
|
-
starting.resolve();
|
|
1509
1700
|
this.waitStarting = null;
|
|
1510
1701
|
this.generalStatus = _types.ServiceStatus.STARTED;
|
|
1702
|
+
starting.resolve();
|
|
1511
1703
|
}
|
|
1512
1704
|
async _startFull() {
|
|
1513
1705
|
// Continue wait existed starting process
|
|
@@ -1821,12 +2013,12 @@ class KoniState {
|
|
|
1821
2013
|
|
|
1822
2014
|
/* Metadata */
|
|
1823
2015
|
|
|
1824
|
-
getCrowdloanContributions(
|
|
2016
|
+
getCrowdloanContributions(_ref15) {
|
|
1825
2017
|
let {
|
|
1826
2018
|
address,
|
|
1827
2019
|
page,
|
|
1828
2020
|
relayChain
|
|
1829
|
-
} =
|
|
2021
|
+
} = _ref15;
|
|
1830
2022
|
return this.subscanService.getCrowdloanContributions(relayChain, address, page);
|
|
1831
2023
|
}
|
|
1832
2024
|
}
|
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = exports.chainPatrolCheckUrl = void 0;
|
|
8
8
|
var CardanoWasm = _interopRequireWildcard(require("@emurgo/cardano-serialization-lib-nodejs"));
|
|
9
9
|
var _types = require("@subwallet/chain-list/types");
|
|
10
|
+
var _BitcoinProviderError = require("@subwallet/extension-base/background/errors/BitcoinProviderError");
|
|
10
11
|
var _CardanoProviderError = require("@subwallet/extension-base/background/errors/CardanoProviderError");
|
|
11
12
|
var _EvmProviderError = require("@subwallet/extension-base/background/errors/EvmProviderError");
|
|
12
13
|
var _helpers = require("@subwallet/extension-base/background/handlers/helpers");
|
|
@@ -23,6 +24,7 @@ var _helper = require("@subwallet/extension-base/services/request-service/helper
|
|
|
23
24
|
var _constants2 = require("@subwallet/extension-base/services/setting-service/constants");
|
|
24
25
|
var _utils2 = require("@subwallet/extension-base/utils");
|
|
25
26
|
var _types3 = require("@subwallet/keyring/types");
|
|
27
|
+
var _utils3 = require("@subwallet/keyring/utils");
|
|
26
28
|
var _uiKeyring = require("@subwallet/ui-keyring");
|
|
27
29
|
var _web = _interopRequireDefault(require("web3"));
|
|
28
30
|
var _phishing = require("@polkadot/phishing");
|
|
@@ -51,7 +53,8 @@ function transformAccountsV2(accounts) {
|
|
|
51
53
|
evm: _types3.EthereumKeypairTypes,
|
|
52
54
|
substrate: _types3.SubstrateKeypairTypes,
|
|
53
55
|
ton: _types3.TonKeypairTypes,
|
|
54
|
-
cardano: _types3.CardanoKeypairTypes
|
|
56
|
+
cardano: _types3.CardanoKeypairTypes,
|
|
57
|
+
bitcoin: _types3.BitcoinKeypairTypes
|
|
55
58
|
};
|
|
56
59
|
const isValidTypes = accountAuthTypes.some(authType => {
|
|
57
60
|
var _validTypes$authType;
|
|
@@ -952,10 +955,6 @@ class KoniTabs {
|
|
|
952
955
|
});
|
|
953
956
|
});
|
|
954
957
|
}
|
|
955
|
-
async canUseAccount(address, url) {
|
|
956
|
-
const allowedAccounts = await this.getCurrentAccount(url, 'evm');
|
|
957
|
-
return !!allowedAccounts.find(acc => acc.toLowerCase() === address.toLowerCase());
|
|
958
|
-
}
|
|
959
958
|
async evmSign(id, url, _ref19) {
|
|
960
959
|
let {
|
|
961
960
|
method,
|
|
@@ -1320,6 +1319,116 @@ class KoniTabs {
|
|
|
1320
1319
|
throw new _CardanoProviderError.CardanoProviderError(_KoniTypes.CardanoProviderErrorType.INTERNAL_ERROR, 'Failed to submit transaction');
|
|
1321
1320
|
}
|
|
1322
1321
|
}
|
|
1322
|
+
|
|
1323
|
+
/// Bitcoin
|
|
1324
|
+
|
|
1325
|
+
isBitcoinPublicRequest(type, request) {
|
|
1326
|
+
return type === 'bitcoin(request)' && ['getAddresses'].includes(request === null || request === void 0 ? void 0 : request.method);
|
|
1327
|
+
}
|
|
1328
|
+
async bitcoinGetAddresses(url) {
|
|
1329
|
+
try {
|
|
1330
|
+
const isCompleted = await this.#koniState.authorizeUrlV2(url, {
|
|
1331
|
+
origin: url,
|
|
1332
|
+
accountAuthTypes: ['bitcoin']
|
|
1333
|
+
});
|
|
1334
|
+
const result = [];
|
|
1335
|
+
if (!isCompleted) {
|
|
1336
|
+
return result;
|
|
1337
|
+
}
|
|
1338
|
+
const authInfo = await this.getAuthInfo(url);
|
|
1339
|
+
if (!authInfo || !authInfo.isAllowedMap || !authInfo.isAllowed) {
|
|
1340
|
+
return result;
|
|
1341
|
+
}
|
|
1342
|
+
const addressesAllowed = await this.getCurrentAccount(url, 'bitcoin');
|
|
1343
|
+
const addressResults = [];
|
|
1344
|
+
addressesAllowed.forEach(address => {
|
|
1345
|
+
const pair = _uiKeyring.keyring.getPair(address);
|
|
1346
|
+
if (pair.meta.noPublicKey) {
|
|
1347
|
+
return;
|
|
1348
|
+
}
|
|
1349
|
+
const addressInfo = (0, _utils3.getBitcoinAddressInfo)(address);
|
|
1350
|
+
const item = {
|
|
1351
|
+
address,
|
|
1352
|
+
type: addressInfo.type,
|
|
1353
|
+
isTestnet: addressInfo.network === 'testnet'
|
|
1354
|
+
};
|
|
1355
|
+
item.derivationPath = pair.meta.derivationPath;
|
|
1356
|
+
item.publicKey = (0, _util.hexStripPrefix)((0, _util.u8aToHex)(pair.publicKey));
|
|
1357
|
+
if (pair.publicKey.length !== 32) {
|
|
1358
|
+
item.tweakedPublicKey = (0, _util.hexStripPrefix)((0, _util.u8aToHex)(pair.publicKey.slice(1, 33)));
|
|
1359
|
+
}
|
|
1360
|
+
addressResults.push(item);
|
|
1361
|
+
});
|
|
1362
|
+
return addressResults;
|
|
1363
|
+
} catch (e) {
|
|
1364
|
+
throw new _BitcoinProviderError.BitcoinProviderError(_KoniTypes.BitcoinProviderErrorType.USER_REJECTED_REQUEST);
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
async bitcoinSign(id, url, _ref22) {
|
|
1368
|
+
let {
|
|
1369
|
+
method,
|
|
1370
|
+
params
|
|
1371
|
+
} = _ref22;
|
|
1372
|
+
const signResult = await this.#koniState.bitcoinSign(id, url, method, params);
|
|
1373
|
+
if (signResult) {
|
|
1374
|
+
return signResult;
|
|
1375
|
+
} else {
|
|
1376
|
+
throw new _BitcoinProviderError.BitcoinProviderError(_KoniTypes.BitcoinProviderErrorType.INVALID_PARAMS, 'Failed to sign message');
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
async bitcoinSignPspt(id, url, _ref23) {
|
|
1380
|
+
let {
|
|
1381
|
+
method,
|
|
1382
|
+
params
|
|
1383
|
+
} = _ref23;
|
|
1384
|
+
const psbtParams = params;
|
|
1385
|
+
const signResult = await this.#koniState.bitcoinSignPspt(id, url, psbtParams);
|
|
1386
|
+
if (signResult) {
|
|
1387
|
+
return signResult;
|
|
1388
|
+
} else {
|
|
1389
|
+
throw new _BitcoinProviderError.BitcoinProviderError(_KoniTypes.BitcoinProviderErrorType.INVALID_PARAMS, 'Failed to sign message');
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
async bitcoinSendTransfer(id, url, _ref24) {
|
|
1393
|
+
let {
|
|
1394
|
+
params
|
|
1395
|
+
} = _ref24;
|
|
1396
|
+
const transactionParams = params;
|
|
1397
|
+
const transactionHash = await this.#koniState.bitcoinSendTransaction(id, url, transactionParams);
|
|
1398
|
+
if (!transactionHash) {
|
|
1399
|
+
throw new _BitcoinProviderError.BitcoinProviderError(_KoniTypes.BitcoinProviderErrorType.USER_REJECTED_REQUEST);
|
|
1400
|
+
}
|
|
1401
|
+
return {
|
|
1402
|
+
txid: transactionHash
|
|
1403
|
+
};
|
|
1404
|
+
}
|
|
1405
|
+
async handleBitcoinRequest(id, url, request, port) {
|
|
1406
|
+
const {
|
|
1407
|
+
method
|
|
1408
|
+
} = request;
|
|
1409
|
+
try {
|
|
1410
|
+
switch (method) {
|
|
1411
|
+
case 'getAddresses':
|
|
1412
|
+
return await this.bitcoinGetAddresses(url);
|
|
1413
|
+
case 'signMessage':
|
|
1414
|
+
return await this.bitcoinSign(id, url, request);
|
|
1415
|
+
case 'signPsbt':
|
|
1416
|
+
return await this.bitcoinSignPspt(id, url, request);
|
|
1417
|
+
case 'sendTransfer':
|
|
1418
|
+
return await this.bitcoinSendTransfer(id, url, request);
|
|
1419
|
+
default:
|
|
1420
|
+
throw new Error(`Method ${method} is not supported by SubWalletBitcoin provider`);
|
|
1421
|
+
}
|
|
1422
|
+
} catch (e) {
|
|
1423
|
+
// @ts-ignore
|
|
1424
|
+
if (e.code) {
|
|
1425
|
+
throw e;
|
|
1426
|
+
} else {
|
|
1427
|
+
console.error(e);
|
|
1428
|
+
throw new _BitcoinProviderError.BitcoinProviderError(_KoniTypes.BitcoinProviderErrorType.INTERNAL_ERROR, e === null || e === void 0 ? void 0 : e.toString());
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1323
1432
|
async handle(id, type, request, url, port) {
|
|
1324
1433
|
if (type === 'pub(phishing.redirectIfDenied)') {
|
|
1325
1434
|
return this.redirectIfPhishing(url);
|
|
@@ -1330,7 +1439,7 @@ class KoniTabs {
|
|
|
1330
1439
|
|
|
1331
1440
|
// Wait for account ready and chain ready
|
|
1332
1441
|
await Promise.all([this.#koniState.eventService.waitAccountReady, this.#koniState.eventService.waitChainReady]);
|
|
1333
|
-
if (!['pub(authorize.tabV2)', 'pub(accounts.subscribeV2)'].includes(type) && !this.isEvmPublicRequest(type, request)) {
|
|
1442
|
+
if (!['pub(authorize.tabV2)', 'pub(accounts.subscribeV2)'].includes(type) && !this.isEvmPublicRequest(type, request) && !this.isBitcoinPublicRequest(type, request)) {
|
|
1334
1443
|
await this.#koniState.ensureUrlAuthorizedV2(url).catch(e => {
|
|
1335
1444
|
if (type.startsWith('evm')) {
|
|
1336
1445
|
throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INTERNAL_ERROR, e.message);
|
|
@@ -1401,6 +1510,10 @@ class KoniTabs {
|
|
|
1401
1510
|
return await this.cardanoSignTransaction(id, url, request);
|
|
1402
1511
|
case 'cardano(transaction.submit)':
|
|
1403
1512
|
return await this.cardanoSubmitTransaction(id, url, request);
|
|
1513
|
+
|
|
1514
|
+
// Bitcoin
|
|
1515
|
+
case 'bitcoin(request)':
|
|
1516
|
+
return await this.handleBitcoinRequest(id, url, request, port);
|
|
1404
1517
|
default:
|
|
1405
1518
|
throw new Error(`Unable to handle message of type ${type}`);
|
|
1406
1519
|
}
|
package/cjs/packageInfo.js
CHANGED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
// Copyright 2019-2022 @subwallet/extension authors & contributors
|
|
8
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
|
|
10
|
+
const WALLET_NAME = 'SubWallet';
|
|
11
|
+
const WALLET_VERSION = process.env.PKG_VERSION;
|
|
12
|
+
class SubWalletBitcoinProvider {
|
|
13
|
+
name = WALLET_NAME;
|
|
14
|
+
version = WALLET_VERSION;
|
|
15
|
+
isSubWallet = true;
|
|
16
|
+
constructor(sendMessage) {
|
|
17
|
+
this.sendMessage = sendMessage;
|
|
18
|
+
}
|
|
19
|
+
async requestAccounts() {
|
|
20
|
+
return await this.request('getAccounts');
|
|
21
|
+
}
|
|
22
|
+
async getAccounts() {
|
|
23
|
+
return await this.request('getAccounts');
|
|
24
|
+
}
|
|
25
|
+
async signMessage(params) {
|
|
26
|
+
return await this.request('signMessage', params);
|
|
27
|
+
}
|
|
28
|
+
async signPsbt(params) {
|
|
29
|
+
return await this.request('signPsbt', params);
|
|
30
|
+
}
|
|
31
|
+
async sendTransfer(params) {
|
|
32
|
+
return await this.request('sendTransfer', params);
|
|
33
|
+
}
|
|
34
|
+
request(method, params) {
|
|
35
|
+
// Implement this method
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
38
|
+
this.sendMessage('bitcoin(request)', {
|
|
39
|
+
method,
|
|
40
|
+
params
|
|
41
|
+
}).then(result => {
|
|
42
|
+
resolve(result);
|
|
43
|
+
}).catch(e => {
|
|
44
|
+
reject(e);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
getProductInfo() {
|
|
49
|
+
return {
|
|
50
|
+
name: this.name,
|
|
51
|
+
version: this.version
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
get apis() {
|
|
55
|
+
return {
|
|
56
|
+
isSubWallet: this.isSubWallet,
|
|
57
|
+
request: (method, params) => this.request(method, params),
|
|
58
|
+
getAccounts: () => this.getAccounts(),
|
|
59
|
+
signMessage: params => this.signMessage(params),
|
|
60
|
+
signPsbt: params => this.signPsbt(params),
|
|
61
|
+
sendTransfer: params => this.sendTransfer(params),
|
|
62
|
+
requestAccounts: () => this.requestAccounts(),
|
|
63
|
+
getProductInfo: () => this.getProductInfo()
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.default = SubWalletBitcoinProvider;
|
package/cjs/page/index.js
CHANGED
|
@@ -6,11 +6,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.enable = enable;
|
|
8
8
|
exports.handleResponse = handleResponse;
|
|
9
|
+
exports.initBitcoinProvider = initBitcoinProvider;
|
|
9
10
|
exports.initCardanoProvider = initCardanoProvider;
|
|
10
11
|
exports.initEvmProvider = initEvmProvider;
|
|
11
12
|
exports.sendMessage = sendMessage;
|
|
12
13
|
var _ProviderError = require("@subwallet/extension-base/background/errors/ProviderError");
|
|
13
14
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
15
|
+
var _bitcoin = _interopRequireDefault(require("@subwallet/extension-base/page/bitcoin"));
|
|
14
16
|
var _cardano = _interopRequireDefault(require("@subwallet/extension-base/page/cardano"));
|
|
15
17
|
var _evm = _interopRequireDefault(require("@subwallet/extension-base/page/evm"));
|
|
16
18
|
var _substrate = _interopRequireDefault(require("@subwallet/extension-base/page/substrate"));
|
|
@@ -76,4 +78,7 @@ function initEvmProvider(version) {
|
|
|
76
78
|
}
|
|
77
79
|
function initCardanoProvider() {
|
|
78
80
|
return new _cardano.default(sendMessage);
|
|
81
|
+
}
|
|
82
|
+
function initBitcoinProvider() {
|
|
83
|
+
return new _bitcoin.default(sendMessage).apis;
|
|
79
84
|
}
|
|
@@ -12,7 +12,18 @@ var _constants = require("./constants");
|
|
|
12
12
|
// SPDX-License-Identifier: Apache-2.0
|
|
13
13
|
|
|
14
14
|
const convertSupportType = support => {
|
|
15
|
-
|
|
15
|
+
switch (support) {
|
|
16
|
+
case 'ETHEREUM':
|
|
17
|
+
return _types.AccountChainType.ETHEREUM;
|
|
18
|
+
case 'SUBSTRATE':
|
|
19
|
+
return _types.AccountChainType.SUBSTRATE;
|
|
20
|
+
case 'CARDANO':
|
|
21
|
+
return _types.AccountChainType.CARDANO;
|
|
22
|
+
case 'TON':
|
|
23
|
+
return _types.AccountChainType.TON;
|
|
24
|
+
default:
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
16
27
|
};
|
|
17
28
|
class BuyService {
|
|
18
29
|
#state;
|
|
@@ -35,11 +46,15 @@ class BuyService {
|
|
|
35
46
|
const data = await (0, _fetchStaticData.fetchStaticData)('buy-token-configs');
|
|
36
47
|
const result = {};
|
|
37
48
|
for (const datum of data) {
|
|
49
|
+
const support = convertSupportType(datum.support);
|
|
50
|
+
if (!support) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
38
53
|
const temp = {
|
|
39
54
|
serviceInfo: {
|
|
40
55
|
..._constants.DEFAULT_SERVICE_INFO
|
|
41
56
|
},
|
|
42
|
-
support
|
|
57
|
+
support,
|
|
43
58
|
services: [],
|
|
44
59
|
slug: datum.slug,
|
|
45
60
|
symbol: datum.symbol,
|
|
@@ -433,6 +433,10 @@ class ParaNativeStakingPoolHandler extends _basePara.default {
|
|
|
433
433
|
const apiPromise = await this.substrateApi.isReady;
|
|
434
434
|
const binaryAmount = new _util.BN(amount);
|
|
435
435
|
const selectedCollatorInfo = selectedValidators[0];
|
|
436
|
+
const {
|
|
437
|
+
address: selectedCollatorAddress,
|
|
438
|
+
nominatorCount: selectedCollatorNominatorCount
|
|
439
|
+
} = selectedCollatorInfo;
|
|
436
440
|
|
|
437
441
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
438
442
|
const compoundResult = async extrinsic => {
|
|
@@ -447,8 +451,17 @@ class ParaNativeStakingPoolHandler extends _basePara.default {
|
|
|
447
451
|
}];
|
|
448
452
|
};
|
|
449
453
|
if (!positionInfo) {
|
|
450
|
-
|
|
451
|
-
|
|
454
|
+
var _apiPromise$api;
|
|
455
|
+
const isTxSupportedDelegate = !!((_apiPromise$api = apiPromise.api) !== null && _apiPromise$api !== void 0 && _apiPromise$api.tx.parachainStaking.delegate);
|
|
456
|
+
if (isTxSupportedDelegate) {
|
|
457
|
+
const extrinsic = apiPromise.api.tx.parachainStaking.delegate(selectedCollatorAddress, binaryAmount, new _util.BN(selectedCollatorNominatorCount), 0);
|
|
458
|
+
return compoundResult(extrinsic);
|
|
459
|
+
} else {
|
|
460
|
+
var _apiPromise$api$query, _apiPromise$api$query2;
|
|
461
|
+
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));
|
|
462
|
+
const extrinsic = apiPromise.api.tx.parachainStaking.delegateWithAutoCompound(selectedCollatorAddress, binaryAmount, 100, new _util.BN(selectedCollatorNominatorCount), new _util.BN(autoCompoundingDelegation.length), 0);
|
|
463
|
+
return compoundResult(extrinsic);
|
|
464
|
+
}
|
|
452
465
|
}
|
|
453
466
|
const {
|
|
454
467
|
bondedValidators,
|
|
@@ -456,10 +469,19 @@ class ParaNativeStakingPoolHandler extends _basePara.default {
|
|
|
456
469
|
} = (0, _utils.getBondedValidators)(positionInfo.nominations);
|
|
457
470
|
const parsedSelectedCollatorAddress = (0, _utils3.reformatAddress)(selectedCollatorInfo.address, 0);
|
|
458
471
|
if (!bondedValidators.includes(parsedSelectedCollatorAddress)) {
|
|
459
|
-
|
|
460
|
-
|
|
472
|
+
var _apiPromise$api2;
|
|
473
|
+
const isTxSupportedDelegate = !!((_apiPromise$api2 = apiPromise.api) !== null && _apiPromise$api2 !== void 0 && _apiPromise$api2.tx.parachainStaking.delegate);
|
|
474
|
+
if (isTxSupportedDelegate) {
|
|
475
|
+
const extrinsic = apiPromise.api.tx.parachainStaking.delegate(selectedCollatorAddress, binaryAmount, new _util.BN(selectedCollatorNominatorCount), nominationCount);
|
|
476
|
+
return compoundResult(extrinsic);
|
|
477
|
+
} else {
|
|
478
|
+
var _apiPromise$api$query3, _apiPromise$api$query4;
|
|
479
|
+
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));
|
|
480
|
+
const extrinsic = apiPromise.api.tx.parachainStaking.delegateWithAutoCompound(selectedCollatorAddress, binaryAmount, 100, new _util.BN(selectedCollatorNominatorCount), new _util.BN(autoCompoundingDelegation.length), nominationCount);
|
|
481
|
+
return compoundResult(extrinsic);
|
|
482
|
+
}
|
|
461
483
|
} else {
|
|
462
|
-
const extrinsic = apiPromise.api.tx.parachainStaking.delegatorBondMore(
|
|
484
|
+
const extrinsic = apiPromise.api.tx.parachainStaking.delegatorBondMore(selectedCollatorAddress, binaryAmount);
|
|
463
485
|
return compoundResult(extrinsic);
|
|
464
486
|
}
|
|
465
487
|
}
|
|
@@ -12,6 +12,7 @@ var _Authorize = _interopRequireDefault(require("@subwallet/extension-base/store
|
|
|
12
12
|
var _utils2 = require("@subwallet/extension-base/utils");
|
|
13
13
|
var _getId = require("@subwallet/extension-base/utils/getId");
|
|
14
14
|
var _keyring = require("@subwallet/keyring");
|
|
15
|
+
var _validate = require("@subwallet/keyring/utils/address/validate");
|
|
15
16
|
var _rxjs = require("rxjs");
|
|
16
17
|
var _utilCrypto = require("@polkadot/util-crypto");
|
|
17
18
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
@@ -179,6 +180,18 @@ class AuthRequestHandler {
|
|
|
179
180
|
}
|
|
180
181
|
}
|
|
181
182
|
}
|
|
183
|
+
if (options.accessType === 'bitcoin') {
|
|
184
|
+
const bitcoinChains = Object.values(chainInfoMaps).filter(_utils._isChainBitcoinCompatible);
|
|
185
|
+
chainInfo = (defaultChain ? chainInfoMaps[defaultChain] : chainInfoMaps.bitcoin) || bitcoinChains[0]; // auto active cardano mainnet chain, because dont support switch network yet
|
|
186
|
+
|
|
187
|
+
if (options.autoActive) {
|
|
188
|
+
var _chainInfo5;
|
|
189
|
+
if (!needEnableChains.includes((_chainInfo5 = chainInfo) === null || _chainInfo5 === void 0 ? void 0 : _chainInfo5.slug)) {
|
|
190
|
+
var _chainInfo6;
|
|
191
|
+
needEnableChains.push((_chainInfo6 = chainInfo) === null || _chainInfo6 === void 0 ? void 0 : _chainInfo6.slug);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
182
195
|
needEnableChains = needEnableChains.filter(slug => {
|
|
183
196
|
var _chainStateMap$slug;
|
|
184
197
|
return !((_chainStateMap$slug = chainStateMap[slug]) !== null && _chainStateMap$slug !== void 0 && _chainStateMap$slug.active);
|
|
@@ -230,6 +243,9 @@ class AuthRequestHandler {
|
|
|
230
243
|
if ((0, _keyring.isCardanoAddress)(a) && !accountAuthTypes.includes('cardano')) {
|
|
231
244
|
return true;
|
|
232
245
|
}
|
|
246
|
+
if ((0, _validate.isBitcoinAddress)(a) && !accountAuthTypes.includes('bitcoin')) {
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
233
249
|
return false;
|
|
234
250
|
});
|
|
235
251
|
backupAllowed.forEach(acc => {
|
|
@@ -384,6 +400,8 @@ class AuthRequestHandler {
|
|
|
384
400
|
list.push(...allowedListByRequestType.filter(a => (0, _keyring.isTonAddress)(a)));
|
|
385
401
|
} else if (accountAuthType === 'cardano') {
|
|
386
402
|
list.push(...allowedListByRequestType.filter(a => (0, _keyring.isCardanoAddress)(a)));
|
|
403
|
+
} else if (accountAuthType === 'bitcoin') {
|
|
404
|
+
list.push(...allowedListByRequestType.filter(a => (0, _validate.isBitcoinAddress)(a)));
|
|
387
405
|
}
|
|
388
406
|
return list;
|
|
389
407
|
}, []);
|