@subwallet/extension-base 1.3.22-0 → 1.3.23-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 +75 -2
- package/background/KoniTypes.js +2 -0
- package/cjs/background/KoniTypes.js +2 -0
- package/cjs/constants/environment.js +4 -2
- package/cjs/constants/signing.js +6 -2
- package/cjs/core/logic-validation/recipientAddress.js +9 -1
- package/cjs/core/logic-validation/transfer.js +35 -29
- package/cjs/core/types.js +1 -0
- package/cjs/core/utils.js +12 -1
- package/cjs/defaults.js +1 -1
- package/cjs/koni/api/dotsama/crowdloan.js +1 -1
- package/cjs/koni/api/nft/index.js +9 -16
- package/cjs/koni/api/staking/index.js +3 -4
- package/cjs/koni/background/handlers/Extension.js +234 -96
- package/cjs/koni/background/handlers/State.js +15 -0
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/cardano/consts.js +11 -0
- package/cjs/services/balance-service/helpers/subscribe/cardano/index.js +63 -0
- package/cjs/services/balance-service/helpers/subscribe/cardano/types.js +1 -0
- package/cjs/services/balance-service/helpers/subscribe/cardano/utils.js +74 -0
- package/cjs/services/balance-service/helpers/subscribe/index.js +21 -7
- package/cjs/services/balance-service/helpers/subscribe/ton/utils.js +2 -2
- package/cjs/services/balance-service/index.js +4 -2
- package/cjs/services/balance-service/transfer/cardano-transfer.js +122 -0
- package/cjs/services/balance-service/transfer/token.js +4 -4
- package/cjs/services/chain-service/handler/CardanoApi.js +176 -0
- package/cjs/services/chain-service/handler/CardanoChainHandler.js +83 -0
- package/cjs/services/chain-service/handler/TonApi.js +2 -5
- package/cjs/services/chain-service/index.js +29 -7
- package/cjs/services/chain-service/utils/index.js +40 -11
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost-manta.js +1 -1
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +1 -1
- package/cjs/services/earning-service/service.js +6 -12
- package/cjs/services/fee-service/service.js +19 -8
- package/cjs/services/history-service/index.js +4 -6
- package/cjs/services/inapp-notification-service/index.js +12 -4
- package/cjs/services/keyring-service/context/account-context.js +17 -2
- package/cjs/services/keyring-service/context/handlers/Derive.js +10 -7
- package/cjs/services/keyring-service/context/handlers/Migration.js +268 -0
- package/cjs/services/keyring-service/context/handlers/Mnemonic.js +2 -2
- package/cjs/services/keyring-service/context/handlers/Secret.js +1 -1
- package/cjs/services/keyring-service/utils.js +18 -0
- package/cjs/services/request-service/handler/CardanoRequestHandler.js +172 -0
- package/cjs/services/request-service/handler/EvmRequestHandler.js +1 -1
- package/cjs/services/request-service/index.js +20 -2
- package/cjs/services/setting-service/constants.js +10 -1
- package/cjs/services/storage-service/DatabaseService.js +3 -0
- package/cjs/services/storage-service/db-stores/InappNotification.js +6 -0
- package/cjs/services/swap-service/handler/asset-hub/handler.js +0 -59
- package/cjs/services/swap-service/handler/chainflip-handler.js +33 -281
- package/cjs/services/swap-service/handler/hydradx-handler.js +23 -190
- package/cjs/services/swap-service/handler/simpleswap-handler.js +1 -222
- package/cjs/services/swap-service/handler/uniswap-handler.js +331 -0
- package/cjs/services/swap-service/index.js +31 -22
- package/cjs/services/swap-service/utils.js +21 -38
- package/cjs/services/transaction-service/helpers/index.js +6 -1
- package/cjs/services/transaction-service/index.js +278 -21
- package/cjs/services/transaction-service/utils.js +5 -1
- package/cjs/types/account/info/keyring.js +12 -1
- package/cjs/types/fee/cardano.js +1 -0
- package/cjs/types/swap/index.js +7 -2
- package/cjs/utils/account/analyze.js +2 -1
- package/cjs/utils/account/common.js +29 -20
- package/cjs/utils/account/derive/info/solo.js +9 -4
- package/cjs/utils/account/derive/validate.js +36 -2
- package/cjs/utils/account/transform.js +38 -13
- package/cjs/utils/fee/transfer.js +40 -7
- package/cjs/utils/index.js +2 -2
- package/cjs/utils/staticData/index.js +7 -2
- package/constants/environment.d.ts +1 -0
- package/constants/environment.js +2 -1
- package/constants/signing.js +6 -2
- package/core/logic-validation/recipientAddress.js +11 -3
- package/core/logic-validation/transfer.js +9 -3
- package/core/substrate/xcm-parser.d.ts +1 -1
- package/core/types.d.ts +1 -0
- package/core/types.js +1 -0
- package/core/utils.d.ts +1 -0
- package/core/utils.js +13 -3
- package/defaults.d.ts +1 -1
- package/defaults.js +1 -1
- package/koni/api/dotsama/crowdloan.js +3 -3
- package/koni/api/nft/index.js +10 -16
- package/koni/api/nft/story_odyssey_nft/index.d.ts +1 -1
- package/koni/api/staking/index.js +4 -5
- package/koni/background/handlers/Extension.d.ts +9 -0
- package/koni/background/handlers/Extension.js +144 -8
- package/koni/background/handlers/State.d.ts +5 -1
- package/koni/background/handlers/State.js +16 -1
- package/package.json +71 -9
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/cardano/consts.d.ts +1 -0
- package/services/balance-service/helpers/subscribe/cardano/consts.js +4 -0
- package/services/balance-service/helpers/subscribe/cardano/index.d.ts +2 -0
- package/services/balance-service/helpers/subscribe/cardano/index.js +57 -0
- package/services/balance-service/helpers/subscribe/cardano/types.d.ts +34 -0
- package/services/balance-service/helpers/subscribe/cardano/types.js +1 -0
- package/services/balance-service/helpers/subscribe/cardano/utils.d.ts +15 -0
- package/services/balance-service/helpers/subscribe/cardano/utils.js +62 -0
- package/services/balance-service/helpers/subscribe/index.d.ts +2 -2
- package/services/balance-service/helpers/subscribe/index.js +23 -9
- package/services/balance-service/helpers/subscribe/ton/utils.d.ts +1 -1
- package/services/balance-service/helpers/subscribe/ton/utils.js +1 -1
- package/services/balance-service/index.js +4 -2
- package/services/balance-service/transfer/cardano-transfer.d.ts +24 -0
- package/services/balance-service/transfer/cardano-transfer.js +114 -0
- package/services/balance-service/transfer/token.d.ts +1 -1
- package/services/balance-service/transfer/token.js +2 -2
- package/services/chain-service/handler/CardanoApi.d.ts +38 -0
- package/services/chain-service/handler/CardanoApi.js +167 -0
- package/services/chain-service/handler/CardanoChainHandler.d.ts +17 -0
- package/services/chain-service/handler/CardanoChainHandler.js +75 -0
- package/services/chain-service/handler/TonApi.js +3 -6
- package/services/chain-service/handler/types.d.ts +1 -0
- package/services/chain-service/index.d.ts +3 -1
- package/services/chain-service/index.js +29 -7
- package/services/chain-service/types.d.ts +9 -1
- package/services/chain-service/utils/index.d.ts +4 -0
- package/services/chain-service/utils/index.js +32 -11
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/handlers/liquid-staking/bifrost-manta.js +1 -1
- package/services/earning-service/handlers/liquid-staking/bifrost.js +1 -1
- package/services/earning-service/service.js +8 -14
- package/services/fee-service/service.js +19 -8
- package/services/history-service/index.js +6 -8
- package/services/inapp-notification-service/index.d.ts +3 -4
- package/services/inapp-notification-service/index.js +14 -6
- package/services/keyring-service/context/account-context.d.ts +6 -2
- package/services/keyring-service/context/account-context.js +17 -2
- package/services/keyring-service/context/handlers/Derive.d.ts +1 -1
- package/services/keyring-service/context/handlers/Derive.js +10 -8
- package/services/keyring-service/context/handlers/Migration.d.ts +17 -0
- package/services/keyring-service/context/handlers/Migration.js +258 -0
- package/services/keyring-service/context/handlers/Mnemonic.js +2 -2
- package/services/keyring-service/context/handlers/Secret.js +2 -2
- package/services/keyring-service/utils.d.ts +2 -0
- package/services/keyring-service/utils.js +11 -0
- package/services/request-service/handler/CardanoRequestHandler.d.ts +16 -0
- package/services/request-service/handler/CardanoRequestHandler.js +163 -0
- package/services/request-service/handler/EvmRequestHandler.js +1 -1
- package/services/request-service/index.d.ts +6 -3
- package/services/request-service/index.js +19 -5
- package/services/setting-service/constants.d.ts +3 -0
- package/services/setting-service/constants.js +6 -0
- package/services/storage-service/DatabaseService.d.ts +1 -0
- package/services/storage-service/DatabaseService.js +3 -0
- package/services/storage-service/db-stores/InappNotification.d.ts +1 -0
- package/services/storage-service/db-stores/InappNotification.js +6 -0
- package/services/swap-service/handler/asset-hub/handler.d.ts +1 -4
- package/services/swap-service/handler/asset-hub/handler.js +2 -61
- package/services/swap-service/handler/base-handler.d.ts +1 -4
- package/services/swap-service/handler/chainflip-handler.d.ts +2 -9
- package/services/swap-service/handler/chainflip-handler.js +31 -280
- package/services/swap-service/handler/hydradx-handler.d.ts +1 -6
- package/services/swap-service/handler/hydradx-handler.js +13 -180
- package/services/swap-service/handler/simpleswap-handler.d.ts +1 -4
- package/services/swap-service/handler/simpleswap-handler.js +5 -226
- package/services/swap-service/handler/uniswap-handler.d.ts +41 -0
- package/services/swap-service/handler/uniswap-handler.js +323 -0
- package/services/swap-service/index.js +30 -22
- package/services/swap-service/utils.d.ts +1 -5
- package/services/swap-service/utils.js +7 -21
- package/services/transaction-service/helpers/index.d.ts +2 -0
- package/services/transaction-service/helpers/index.js +4 -0
- package/services/transaction-service/index.d.ts +8 -2
- package/services/transaction-service/index.js +263 -10
- package/services/transaction-service/types.d.ts +7 -0
- package/services/transaction-service/utils.js +7 -2
- package/types/account/info/keyring.d.ts +4 -1
- package/types/account/info/keyring.js +9 -0
- package/types/account/info/proxy.d.ts +2 -0
- package/types/balance/index.d.ts +4 -1
- package/types/fee/base.d.ts +1 -1
- package/types/fee/cardano.d.ts +18 -0
- package/types/fee/cardano.js +1 -0
- package/types/fee/subscription.d.ts +4 -3
- package/types/swap/index.d.ts +11 -3
- package/types/swap/index.js +7 -2
- package/utils/account/analyze.js +2 -1
- package/utils/account/common.d.ts +11 -6
- package/utils/account/common.js +28 -19
- package/utils/account/derive/info/solo.js +10 -5
- package/utils/account/derive/validate.d.ts +1 -0
- package/utils/account/derive/validate.js +34 -1
- package/utils/account/transform.d.ts +2 -1
- package/utils/account/transform.js +37 -13
- package/utils/fee/transfer.d.ts +2 -1
- package/utils/fee/transfer.js +44 -11
- package/utils/index.js +4 -4
- package/utils/staticData/index.d.ts +4 -1
- package/utils/staticData/index.js +5 -1
- package/utils/staticData/oldChainPrefix.json +1 -0
|
@@ -40,6 +40,7 @@ class TransactionService {
|
|
|
40
40
|
aliveProcessMap = new Map();
|
|
41
41
|
transactionSubject = new _rxjs.BehaviorSubject({});
|
|
42
42
|
aliveProcessSubject = new _rxjs.BehaviorSubject(this.aliveProcessMap);
|
|
43
|
+
cacheProcessInfo = {};
|
|
43
44
|
get transactions() {
|
|
44
45
|
return this.transactionSubject.getValue();
|
|
45
46
|
}
|
|
@@ -110,9 +111,13 @@ class TransactionService {
|
|
|
110
111
|
const substrateApi = this.state.chainService.getSubstrateApi(chainInfo.slug);
|
|
111
112
|
const evmApi = this.state.chainService.getEvmApi(chainInfo.slug);
|
|
112
113
|
const tonApi = this.state.chainService.getTonApi(chainInfo.slug);
|
|
113
|
-
const
|
|
114
|
+
const cardanoApi = this.state.chainService.getCardanoApi(chainInfo.slug);
|
|
115
|
+
// todo: should split into isEvmTx && isNoEvmApi. Because other chains type also has no Evm Api. Same to all blockchain.
|
|
116
|
+
// todo: refactor check evmTransaction.
|
|
117
|
+
const isNoEvmApi = transaction && !(0, _helpers.isSubstrateTransaction)(transaction) && !(0, _helpers.isTonTransaction)(transaction) && !(0, _helpers.isCardanoTransaction)(transaction) && !evmApi;
|
|
114
118
|
const isNoTonApi = transaction && (0, _helpers.isTonTransaction)(transaction) && !tonApi;
|
|
115
|
-
|
|
119
|
+
const isNoCardanoApi = transaction && (0, _helpers.isCardanoTransaction)(transaction) && !cardanoApi;
|
|
120
|
+
if (isNoEvmApi || isNoTonApi || isNoCardanoApi) {
|
|
116
121
|
validationResponse.errors.push(new _TransactionError.TransactionError(_types.BasicTxErrorType.CHAIN_DISCONNECTED, undefined));
|
|
117
122
|
}
|
|
118
123
|
|
|
@@ -176,6 +181,10 @@ class TransactionService {
|
|
|
176
181
|
}
|
|
177
182
|
};
|
|
178
183
|
}
|
|
184
|
+
getCacheInfo(processId, step) {
|
|
185
|
+
var _this$cacheProcessInf;
|
|
186
|
+
return ((_this$cacheProcessInf = this.cacheProcessInfo[processId]) === null || _this$cacheProcessInf === void 0 ? void 0 : _this$cacheProcessInf[step]) || '';
|
|
187
|
+
}
|
|
179
188
|
updateAliveProcess() {
|
|
180
189
|
this.aliveProcessSubject.next(this.aliveProcessMap);
|
|
181
190
|
}
|
|
@@ -270,9 +279,61 @@ class TransactionService {
|
|
|
270
279
|
'eventsHandler' in validatedTransaction && delete validatedTransaction.eventsHandler;
|
|
271
280
|
return validatedTransaction;
|
|
272
281
|
}
|
|
282
|
+
async handlePermitTransaction(transaction) {
|
|
283
|
+
var _transaction$step;
|
|
284
|
+
const transactionId = (0, _helpers.getTransactionId)(transaction.chainType, transaction.chain, true);
|
|
285
|
+
const validatedTransaction = {
|
|
286
|
+
...transaction,
|
|
287
|
+
id: transactionId,
|
|
288
|
+
extrinsicHash: '',
|
|
289
|
+
status: undefined,
|
|
290
|
+
errors: transaction.errors || [],
|
|
291
|
+
warnings: transaction.warnings || [],
|
|
292
|
+
processId: (_transaction$step = transaction.step) === null || _transaction$step === void 0 ? void 0 : _transaction$step.processId
|
|
293
|
+
};
|
|
294
|
+
const txInput = {
|
|
295
|
+
...transaction,
|
|
296
|
+
isInternal: true,
|
|
297
|
+
status: _KoniTypes.ExtrinsicStatus.QUEUED,
|
|
298
|
+
id: transactionId,
|
|
299
|
+
extrinsicHash: transactionId,
|
|
300
|
+
createdAt: new Date().getTime(),
|
|
301
|
+
updatedAt: new Date().getTime()
|
|
302
|
+
};
|
|
303
|
+
const _data = transaction.data;
|
|
304
|
+
const emitter = this.sendPermitTransaction(txInput);
|
|
305
|
+
await new Promise((resolve, reject) => {
|
|
306
|
+
emitter.on('success', data => {
|
|
307
|
+
validatedTransaction.id = data.id;
|
|
308
|
+
validatedTransaction.extrinsicHash = data.extrinsicHash;
|
|
309
|
+
this.cacheProcessInfo[_data.processId] = {
|
|
310
|
+
[_data.step]: data.extrinsicHash
|
|
311
|
+
};
|
|
312
|
+
resolve();
|
|
313
|
+
});
|
|
314
|
+
emitter.on('error', data => {
|
|
315
|
+
if (data.errors.length > 0) {
|
|
316
|
+
validatedTransaction.errors.push(...data.errors);
|
|
317
|
+
resolve();
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
emitter.on('timeout', data => {
|
|
321
|
+
if (transaction.errorOnTimeOut && data.errors.length > 0) {
|
|
322
|
+
validatedTransaction.errors.push(...data.errors);
|
|
323
|
+
resolve();
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
// @ts-ignore
|
|
329
|
+
'transaction' in validatedTransaction && delete validatedTransaction.transaction;
|
|
330
|
+
'additionalValidator' in validatedTransaction && delete validatedTransaction.additionalValidator;
|
|
331
|
+
'eventsHandler' in validatedTransaction && delete validatedTransaction.eventsHandler;
|
|
332
|
+
return validatedTransaction;
|
|
333
|
+
}
|
|
273
334
|
async sendTransaction(transaction) {
|
|
274
335
|
// Send Transaction
|
|
275
|
-
const emitter = await (transaction.chainType === 'substrate' ? this.signAndSendSubstrateTransaction(transaction) : transaction.chainType === 'evm' ? this.signAndSendEvmTransaction(transaction) : this.signAndSendTonTransaction(transaction));
|
|
336
|
+
const emitter = await (transaction.chainType === 'substrate' ? this.signAndSendSubstrateTransaction(transaction) : transaction.chainType === 'evm' ? this.signAndSendEvmTransaction(transaction) : transaction.chainType === 'cardano' ? this.signAndSendCardanoTransaction(transaction) : this.signAndSendTonTransaction(transaction));
|
|
276
337
|
const {
|
|
277
338
|
eventsHandler,
|
|
278
339
|
step
|
|
@@ -322,7 +383,12 @@ class TransactionService {
|
|
|
322
383
|
}
|
|
323
384
|
return false;
|
|
324
385
|
});
|
|
325
|
-
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Now simple check, first step have step id = 1.
|
|
389
|
+
* Improve to fetch the process from db
|
|
390
|
+
* */
|
|
391
|
+
if (rejectError && step.stepId === 1) {
|
|
326
392
|
this.deleteProcess(step);
|
|
327
393
|
} else {
|
|
328
394
|
this.updateProcessStepStatus(step, {
|
|
@@ -348,6 +414,71 @@ class TransactionService {
|
|
|
348
414
|
eventsHandler === null || eventsHandler === void 0 ? void 0 : eventsHandler(emitter);
|
|
349
415
|
return emitter;
|
|
350
416
|
}
|
|
417
|
+
sendPermitTransaction(transaction) {
|
|
418
|
+
// Send Transaction
|
|
419
|
+
const emitter = this.signAndSendEvmPermitTransaction(transaction);
|
|
420
|
+
const {
|
|
421
|
+
eventsHandler,
|
|
422
|
+
step
|
|
423
|
+
} = transaction;
|
|
424
|
+
emitter.on('send', data => {
|
|
425
|
+
if (step) {
|
|
426
|
+
this.updateProcessStepStatus(step, {
|
|
427
|
+
transactionId: transaction.id,
|
|
428
|
+
status: _types.StepStatus.SUBMITTING,
|
|
429
|
+
chain: transaction.chain
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
emitter.on('extrinsicHash', data => {
|
|
434
|
+
if (step) {
|
|
435
|
+
this.updateProcessStepStatus(step, {
|
|
436
|
+
extrinsicHash: data.extrinsicHash,
|
|
437
|
+
status: _types.StepStatus.PROCESSING
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
emitter.on('success', data => {
|
|
442
|
+
if (step) {
|
|
443
|
+
this.updateProcessStepStatus(step, {
|
|
444
|
+
status: _types.StepStatus.COMPLETE
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
emitter.on('error', data => {
|
|
449
|
+
// this.handlePostProcessing(data.id); // might enable this later
|
|
450
|
+
this.onFailed({
|
|
451
|
+
...data,
|
|
452
|
+
errors: [...data.errors, new _TransactionError.TransactionError(_types.BasicTxErrorType.INTERNAL_ERROR)]
|
|
453
|
+
});
|
|
454
|
+
if (step) {
|
|
455
|
+
const rejectError = data.errors.find(error => {
|
|
456
|
+
// TODO: REFACTOR ERROR CODE
|
|
457
|
+
if ([_types.BasicTxErrorType.UNABLE_TO_SIGN, _types.BasicTxErrorType.USER_REJECT_REQUEST].includes(error.errorType)) {
|
|
458
|
+
return true;
|
|
459
|
+
}
|
|
460
|
+
return false;
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Now simple check, first step have step id = 1.
|
|
465
|
+
* Improve to fetch the process from db
|
|
466
|
+
* */
|
|
467
|
+
if (rejectError && step.stepId === 1) {
|
|
468
|
+
this.deleteProcess(step);
|
|
469
|
+
} else {
|
|
470
|
+
this.updateProcessStepStatus(step, {
|
|
471
|
+
status: _types.StepStatus.FAILED
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
// Todo: handle any event with transaction.eventsHandler
|
|
478
|
+
|
|
479
|
+
eventsHandler === null || eventsHandler === void 0 ? void 0 : eventsHandler(emitter);
|
|
480
|
+
return emitter;
|
|
481
|
+
}
|
|
351
482
|
removeTransaction(id) {
|
|
352
483
|
if (this.transactions[id]) {
|
|
353
484
|
delete this.transactions[id];
|
|
@@ -371,7 +502,7 @@ class TransactionService {
|
|
|
371
502
|
return (0, _utils3.getExplorerLink)(chainInfo, transaction.extrinsicHash, 'tx');
|
|
372
503
|
}
|
|
373
504
|
transactionToHistories(id, startBlock, nonce, eventLogs) {
|
|
374
|
-
var _transaction$
|
|
505
|
+
var _transaction$step2;
|
|
375
506
|
const transaction = this.getTransaction(id);
|
|
376
507
|
const extrinsicType = transaction.extrinsicType;
|
|
377
508
|
const chainInfo = this.state.chainService.getChainInfoByKey(transaction.chain);
|
|
@@ -396,7 +527,7 @@ class TransactionService {
|
|
|
396
527
|
// Will be added in next step
|
|
397
528
|
nonce: nonce !== null && nonce !== void 0 ? nonce : 0,
|
|
398
529
|
startBlock: startBlock || 0,
|
|
399
|
-
processId: (_transaction$
|
|
530
|
+
processId: (_transaction$step2 = transaction.step) === null || _transaction$step2 === void 0 ? void 0 : _transaction$step2.processId
|
|
400
531
|
};
|
|
401
532
|
const nativeAsset = (0, _utils2._getChainNativeTokenBasicInfo)(chainInfo);
|
|
402
533
|
const baseNativeAmount = {
|
|
@@ -1172,7 +1303,64 @@ class TransactionService {
|
|
|
1172
1303
|
}
|
|
1173
1304
|
return emitter;
|
|
1174
1305
|
}
|
|
1175
|
-
|
|
1306
|
+
signAndSendEvmPermitTransaction(_ref10) {
|
|
1307
|
+
let {
|
|
1308
|
+
address,
|
|
1309
|
+
id,
|
|
1310
|
+
isPassConfirmation,
|
|
1311
|
+
step,
|
|
1312
|
+
transaction,
|
|
1313
|
+
url
|
|
1314
|
+
} = _ref10;
|
|
1315
|
+
// Allow sign transaction
|
|
1316
|
+
const canSign = true;
|
|
1317
|
+
const emitter = new _eventemitter.default();
|
|
1318
|
+
const eventData = {
|
|
1319
|
+
id,
|
|
1320
|
+
errors: [],
|
|
1321
|
+
warnings: [],
|
|
1322
|
+
extrinsicHash: id,
|
|
1323
|
+
processId: step === null || step === void 0 ? void 0 : step.processId
|
|
1324
|
+
};
|
|
1325
|
+
const evmSignaturePayload = {
|
|
1326
|
+
id: id,
|
|
1327
|
+
type: 'eth_signTypedData_v4',
|
|
1328
|
+
payload: transaction,
|
|
1329
|
+
address: address,
|
|
1330
|
+
hashPayload: '',
|
|
1331
|
+
canSign: canSign,
|
|
1332
|
+
processId: step === null || step === void 0 ? void 0 : step.processId
|
|
1333
|
+
};
|
|
1334
|
+
this.state.requestService.addConfirmation(id, url || _constants2.EXTENSION_REQUEST_URL, 'evmSignatureRequest', evmSignaturePayload, {
|
|
1335
|
+
isPassConfirmation
|
|
1336
|
+
}).then(_ref11 => {
|
|
1337
|
+
let {
|
|
1338
|
+
isApproved,
|
|
1339
|
+
payload: signature
|
|
1340
|
+
} = _ref11;
|
|
1341
|
+
if (isApproved) {
|
|
1342
|
+
// Emit signed event
|
|
1343
|
+
emitter.emit('signed', eventData);
|
|
1344
|
+
emitter.emit('send', eventData); // This event is needed after sending transaction with queue
|
|
1345
|
+
|
|
1346
|
+
if (!signature) {
|
|
1347
|
+
throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.UNAUTHORIZED, (0, _i18next.t)('Failed to sign'));
|
|
1348
|
+
}
|
|
1349
|
+
eventData.extrinsicHash = signature;
|
|
1350
|
+
emitter.emit('extrinsicHash', eventData);
|
|
1351
|
+
emitter.emit('success', eventData);
|
|
1352
|
+
} else {
|
|
1353
|
+
eventData.errors.push(new _TransactionError.TransactionError(_types.BasicTxErrorType.USER_REJECT_REQUEST));
|
|
1354
|
+
emitter.emit('error', eventData);
|
|
1355
|
+
}
|
|
1356
|
+
}).catch(e => {
|
|
1357
|
+
this.removeTransaction(id);
|
|
1358
|
+
eventData.errors.push(new _TransactionError.TransactionError(_types.BasicTxErrorType.UNABLE_TO_SIGN, (0, _i18next.t)(e.message)));
|
|
1359
|
+
emitter.emit('error', eventData);
|
|
1360
|
+
});
|
|
1361
|
+
return emitter;
|
|
1362
|
+
}
|
|
1363
|
+
signAndSendSubstrateTransaction(_ref12) {
|
|
1176
1364
|
var _this$state$chainServ;
|
|
1177
1365
|
let {
|
|
1178
1366
|
address,
|
|
@@ -1184,7 +1372,7 @@ class TransactionService {
|
|
|
1184
1372
|
step,
|
|
1185
1373
|
transaction,
|
|
1186
1374
|
url
|
|
1187
|
-
} =
|
|
1375
|
+
} = _ref12;
|
|
1188
1376
|
const tip = (feeCustom === null || feeCustom === void 0 ? void 0 : feeCustom.tip) || '0';
|
|
1189
1377
|
const feeAssetId = nonNativeTokenPayFeeSlug ? (_this$state$chainServ = this.state.chainService.getAssetBySlug(nonNativeTokenPayFeeSlug).metadata) === null || _this$state$chainServ === void 0 ? void 0 : _this$state$chainServ.multilocation : undefined;
|
|
1190
1378
|
const emitter = new _eventemitter.default();
|
|
@@ -1255,20 +1443,20 @@ class TransactionService {
|
|
|
1255
1443
|
eventData.extrinsicHash = txState.txHash.toHex();
|
|
1256
1444
|
eventData.eventLogs = txState.events;
|
|
1257
1445
|
// TODO: push block hash and block number into eventData
|
|
1258
|
-
txState.events.filter(
|
|
1446
|
+
txState.events.filter(_ref13 => {
|
|
1259
1447
|
let {
|
|
1260
1448
|
event: {
|
|
1261
1449
|
section
|
|
1262
1450
|
}
|
|
1263
|
-
} =
|
|
1451
|
+
} = _ref13;
|
|
1264
1452
|
return section === 'system';
|
|
1265
|
-
}).forEach(
|
|
1453
|
+
}).forEach(_ref14 => {
|
|
1266
1454
|
let {
|
|
1267
1455
|
event: {
|
|
1268
1456
|
data: [error],
|
|
1269
1457
|
method
|
|
1270
1458
|
}
|
|
1271
|
-
} =
|
|
1459
|
+
} = _ref14;
|
|
1272
1460
|
if (method === 'ExtrinsicFailed') {
|
|
1273
1461
|
eventData.errors.push(new _TransactionError.TransactionError(_types.BasicTxErrorType.SEND_TRANSACTION_FAILED, error.toString()));
|
|
1274
1462
|
emitter.emit('error', eventData);
|
|
@@ -1288,7 +1476,7 @@ class TransactionService {
|
|
|
1288
1476
|
});
|
|
1289
1477
|
return emitter;
|
|
1290
1478
|
}
|
|
1291
|
-
signAndSendTonTransaction(
|
|
1479
|
+
signAndSendTonTransaction(_ref15) {
|
|
1292
1480
|
let {
|
|
1293
1481
|
address,
|
|
1294
1482
|
chain,
|
|
@@ -1297,7 +1485,7 @@ class TransactionService {
|
|
|
1297
1485
|
step,
|
|
1298
1486
|
transaction,
|
|
1299
1487
|
url
|
|
1300
|
-
} =
|
|
1488
|
+
} = _ref15;
|
|
1301
1489
|
const walletContract = _uiKeyring.default.getPair(address).ton.currentContract;
|
|
1302
1490
|
const emitter = new _eventemitter.default();
|
|
1303
1491
|
const eventData = {
|
|
@@ -1314,11 +1502,11 @@ class TransactionService {
|
|
|
1314
1502
|
...payload,
|
|
1315
1503
|
messagePayload: (0, _utils.cellToBase64Str)(message),
|
|
1316
1504
|
messages: []
|
|
1317
|
-
}, {}).then(
|
|
1505
|
+
}, {}).then(_ref16 => {
|
|
1318
1506
|
let {
|
|
1319
1507
|
isApproved,
|
|
1320
1508
|
payload
|
|
1321
|
-
} =
|
|
1509
|
+
} = _ref16;
|
|
1322
1510
|
if (!isApproved) {
|
|
1323
1511
|
this.removeTransaction(id);
|
|
1324
1512
|
eventData.errors.push(new _TransactionError.TransactionError(_types.BasicTxErrorType.USER_REJECT_REQUEST));
|
|
@@ -1336,7 +1524,7 @@ class TransactionService {
|
|
|
1336
1524
|
});
|
|
1337
1525
|
});
|
|
1338
1526
|
};
|
|
1339
|
-
const tonTransactionConfig = transaction;
|
|
1527
|
+
const tonTransactionConfig = transaction; // todo: is this same as payload?
|
|
1340
1528
|
const seqno = tonTransactionConfig.seqno;
|
|
1341
1529
|
const messages = tonTransactionConfig.messages;
|
|
1342
1530
|
const transferObjectPromise = (0, _utils.getTransferCellPromise)(walletContract, signer, payload, seqno, messages);
|
|
@@ -1353,8 +1541,8 @@ class TransactionService {
|
|
|
1353
1541
|
if (!externalMsgHash) {
|
|
1354
1542
|
return;
|
|
1355
1543
|
}
|
|
1356
|
-
tonApi.getStatusByExtMsgHash(externalMsgHash, extrinsicType).then(
|
|
1357
|
-
let [status, hex] =
|
|
1544
|
+
tonApi.getStatusByExtMsgHash(externalMsgHash, extrinsicType).then(_ref17 => {
|
|
1545
|
+
let [status, hex] = _ref17;
|
|
1358
1546
|
if (status && hex) {
|
|
1359
1547
|
eventData.extrinsicHash = hex;
|
|
1360
1548
|
emitter.emit('extrinsicHash', eventData);
|
|
@@ -1383,6 +1571,75 @@ class TransactionService {
|
|
|
1383
1571
|
});
|
|
1384
1572
|
return emitter;
|
|
1385
1573
|
}
|
|
1574
|
+
signAndSendCardanoTransaction(_ref18) {
|
|
1575
|
+
let {
|
|
1576
|
+
chain,
|
|
1577
|
+
id,
|
|
1578
|
+
transaction,
|
|
1579
|
+
url
|
|
1580
|
+
} = _ref18;
|
|
1581
|
+
const emitter = new _eventemitter.default();
|
|
1582
|
+
const eventData = {
|
|
1583
|
+
id,
|
|
1584
|
+
errors: [],
|
|
1585
|
+
warnings: [],
|
|
1586
|
+
extrinsicHash: id
|
|
1587
|
+
};
|
|
1588
|
+
const transactionConfig = transaction;
|
|
1589
|
+
const cardanoApi = this.state.chainService.getCardanoApi(chain);
|
|
1590
|
+
this.state.requestService.addConfirmationCardano(id, url || _constants2.EXTENSION_REQUEST_URL, 'cardanoSendTransactionRequest', transactionConfig, {}).then(_ref19 => {
|
|
1591
|
+
let {
|
|
1592
|
+
isApproved,
|
|
1593
|
+
payload
|
|
1594
|
+
} = _ref19;
|
|
1595
|
+
if (!isApproved) {
|
|
1596
|
+
this.removeTransaction(id);
|
|
1597
|
+
eventData.errors.push(new _TransactionError.TransactionError(_types.BasicTxErrorType.USER_REJECT_REQUEST));
|
|
1598
|
+
emitter.emit('error', eventData);
|
|
1599
|
+
} else {
|
|
1600
|
+
if (!payload) {
|
|
1601
|
+
throw new Error('Failed to sign');
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1604
|
+
// Emit signed event
|
|
1605
|
+
emitter.emit('signed', eventData);
|
|
1606
|
+
|
|
1607
|
+
// Send transaction
|
|
1608
|
+
this.handleTransactionTimeout(emitter, eventData);
|
|
1609
|
+
emitter.emit('send', eventData);
|
|
1610
|
+
|
|
1611
|
+
// send qua api
|
|
1612
|
+
cardanoApi.sendCardanoTxReturnHash(payload).then(txHash => {
|
|
1613
|
+
if (!txHash) {
|
|
1614
|
+
eventData.errors.push(new _TransactionError.TransactionError(_types.BasicTxErrorType.SEND_TRANSACTION_FAILED));
|
|
1615
|
+
emitter.emit('error', eventData);
|
|
1616
|
+
}
|
|
1617
|
+
eventData.extrinsicHash = txHash;
|
|
1618
|
+
emitter.emit('extrinsicHash', eventData);
|
|
1619
|
+
|
|
1620
|
+
// todo: wait transaction by fetch txHash by API
|
|
1621
|
+
cardanoApi.getStatusByTxHash(txHash, transactionConfig.cardanoTtlOffset).then(status => {
|
|
1622
|
+
if (!status) {
|
|
1623
|
+
eventData.errors.push(new _TransactionError.TransactionError(_types.BasicTxErrorType.SEND_TRANSACTION_FAILED));
|
|
1624
|
+
emitter.emit('error', eventData);
|
|
1625
|
+
}
|
|
1626
|
+
emitter.emit('success', eventData);
|
|
1627
|
+
}).catch(e => {
|
|
1628
|
+
eventData.errors.push(new _TransactionError.TransactionError(_types.BasicTxErrorType.SEND_TRANSACTION_FAILED, e.message));
|
|
1629
|
+
emitter.emit('error', eventData);
|
|
1630
|
+
});
|
|
1631
|
+
}).catch(e => {
|
|
1632
|
+
eventData.errors.push(new _TransactionError.TransactionError(_types.BasicTxErrorType.SEND_TRANSACTION_FAILED, e.message));
|
|
1633
|
+
emitter.emit('error', eventData);
|
|
1634
|
+
});
|
|
1635
|
+
}
|
|
1636
|
+
}).catch(e => {
|
|
1637
|
+
this.removeTransaction(id);
|
|
1638
|
+
eventData.errors.push(new _TransactionError.TransactionError(_types.BasicTxErrorType.UNABLE_TO_SIGN, (0, _i18next.t)(e.message)));
|
|
1639
|
+
emitter.emit('error', eventData);
|
|
1640
|
+
});
|
|
1641
|
+
return emitter;
|
|
1642
|
+
}
|
|
1386
1643
|
handleTransactionTimeout(emitter, eventData) {
|
|
1387
1644
|
const timeout = setTimeout(() => {
|
|
1388
1645
|
const transaction = this.getTransaction(eventData.id);
|
|
@@ -1525,9 +1782,9 @@ class TransactionService {
|
|
|
1525
1782
|
}
|
|
1526
1783
|
}
|
|
1527
1784
|
async createProcessNotification(transactionId) {
|
|
1528
|
-
var _transaction$
|
|
1785
|
+
var _transaction$step3;
|
|
1529
1786
|
const transaction = this.getTransaction(transactionId);
|
|
1530
|
-
if (transaction && (_transaction$
|
|
1787
|
+
if (transaction && (_transaction$step3 = transaction.step) !== null && _transaction$step3 !== void 0 && _transaction$step3.processId) {
|
|
1531
1788
|
const process = this.aliveProcessMap.get(transaction.step.processId);
|
|
1532
1789
|
if (process) {
|
|
1533
1790
|
await this.state.inappNotificationService.createProcessNotification(process);
|
|
@@ -9,6 +9,7 @@ exports.getSimpleSwapExplorerLink = getSimpleSwapExplorerLink;
|
|
|
9
9
|
exports.parseTransactionData = parseTransactionData;
|
|
10
10
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
11
11
|
var _utils2 = require("@subwallet/extension-base/services/swap-service/utils");
|
|
12
|
+
var _util = require("@polkadot/util");
|
|
12
13
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
13
14
|
// SPDX-License-Identifier: Apache-2.0
|
|
14
15
|
|
|
@@ -55,6 +56,9 @@ function getBlockExplorerTxRoute(chainInfo) {
|
|
|
55
56
|
if ((0, _utils._isPureEvmChain)(chainInfo)) {
|
|
56
57
|
return 'tx';
|
|
57
58
|
}
|
|
59
|
+
if ((0, _utils._isPureCardanoChain)(chainInfo)) {
|
|
60
|
+
return 'transaction';
|
|
61
|
+
}
|
|
58
62
|
if (['aventus', 'deeper_network'].includes(chainInfo.slug)) {
|
|
59
63
|
return 'transaction';
|
|
60
64
|
}
|
|
@@ -69,7 +73,7 @@ function getExplorerLink(chainInfo, value, type) {
|
|
|
69
73
|
const route = getBlockExplorerAccountRoute(explorerLink);
|
|
70
74
|
return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}${route}/${value}`;
|
|
71
75
|
}
|
|
72
|
-
if (explorerLink &&
|
|
76
|
+
if (explorerLink && (0, _util.isHex)((0, _util.hexAddPrefix)(value))) {
|
|
73
77
|
if (chainInfo.slug === 'bittensor') {
|
|
74
78
|
return undefined;
|
|
75
79
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.AccountSignMode = exports.AccountChainType = exports.AccountActions = void 0;
|
|
6
|
+
exports.SUPPORTED_ACCOUNT_CHAIN_TYPES = exports.AccountSignMode = exports.AccountChainType = exports.AccountActions = exports.ACCOUNT_CHAIN_TYPE_ORDINAL_MAP = void 0;
|
|
7
7
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
8
8
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
9
|
/**
|
|
@@ -67,7 +67,18 @@ exports.AccountChainType = AccountChainType;
|
|
|
67
67
|
AccountChainType["ETHEREUM"] = "ethereum";
|
|
68
68
|
AccountChainType["BITCOIN"] = "bitcoin";
|
|
69
69
|
AccountChainType["TON"] = "ton";
|
|
70
|
+
AccountChainType["CARDANO"] = "cardano";
|
|
70
71
|
})(AccountChainType || (exports.AccountChainType = AccountChainType = {}));
|
|
72
|
+
const ACCOUNT_CHAIN_TYPE_ORDINAL_MAP = {
|
|
73
|
+
[AccountChainType.SUBSTRATE]: 1,
|
|
74
|
+
[AccountChainType.ETHEREUM]: 2,
|
|
75
|
+
[AccountChainType.TON]: 3,
|
|
76
|
+
[AccountChainType.CARDANO]: 4,
|
|
77
|
+
[AccountChainType.BITCOIN]: 5
|
|
78
|
+
};
|
|
79
|
+
exports.ACCOUNT_CHAIN_TYPE_ORDINAL_MAP = ACCOUNT_CHAIN_TYPE_ORDINAL_MAP;
|
|
80
|
+
const SUPPORTED_ACCOUNT_CHAIN_TYPES = ['substrate', 'ethereum', 'ton', 'cardano'];
|
|
81
|
+
exports.SUPPORTED_ACCOUNT_CHAIN_TYPES = SUPPORTED_ACCOUNT_CHAIN_TYPES;
|
|
71
82
|
let AccountActions;
|
|
72
83
|
/**
|
|
73
84
|
* Represents the actions associated with an account.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/cjs/types/swap/index.js
CHANGED
|
@@ -27,6 +27,7 @@ let SwapStepType;
|
|
|
27
27
|
exports.SwapStepType = SwapStepType;
|
|
28
28
|
(function (SwapStepType) {
|
|
29
29
|
SwapStepType["SWAP"] = "SWAP";
|
|
30
|
+
SwapStepType["PERMIT"] = "PERMIT";
|
|
30
31
|
})(SwapStepType || (exports.SwapStepType = SwapStepType = {}));
|
|
31
32
|
let SwapProviderId;
|
|
32
33
|
exports.SwapProviderId = SwapProviderId;
|
|
@@ -40,10 +41,14 @@ exports.SwapProviderId = SwapProviderId;
|
|
|
40
41
|
SwapProviderId["ROCOCO_ASSET_HUB"] = "ROCOCO_ASSET_HUB";
|
|
41
42
|
SwapProviderId["WESTEND_ASSET_HUB"] = "WESTEND_ASSET_HUB";
|
|
42
43
|
SwapProviderId["SIMPLE_SWAP"] = "SIMPLE_SWAP";
|
|
44
|
+
SwapProviderId["UNISWAP"] = "UNISWAP";
|
|
43
45
|
})(SwapProviderId || (exports.SwapProviderId = SwapProviderId = {}));
|
|
44
|
-
const _SUPPORTED_SWAP_PROVIDERS = [SwapProviderId.CHAIN_FLIP_TESTNET, SwapProviderId.CHAIN_FLIP_MAINNET, SwapProviderId.HYDRADX_MAINNET,
|
|
46
|
+
const _SUPPORTED_SWAP_PROVIDERS = [SwapProviderId.CHAIN_FLIP_TESTNET, SwapProviderId.CHAIN_FLIP_MAINNET, SwapProviderId.HYDRADX_MAINNET,
|
|
47
|
+
// SwapProviderId.HYDRADX_TESTNET,
|
|
48
|
+
SwapProviderId.POLKADOT_ASSET_HUB, SwapProviderId.KUSAMA_ASSET_HUB,
|
|
49
|
+
// SwapProviderId.ROCOCO_ASSET_HUB,
|
|
45
50
|
// SwapProviderId.WESTEND_ASSET_HUB,
|
|
46
|
-
SwapProviderId.SIMPLE_SWAP];
|
|
51
|
+
SwapProviderId.SIMPLE_SWAP, SwapProviderId.UNISWAP];
|
|
47
52
|
exports._SUPPORTED_SWAP_PROVIDERS = _SUPPORTED_SWAP_PROVIDERS;
|
|
48
53
|
// process handling
|
|
49
54
|
let SwapFeeType;
|
|
@@ -21,7 +21,8 @@ const isStrValidWithAddress = (str, account, chainInfo) => {
|
|
|
21
21
|
} else if (account.address.toLowerCase().includes(str) || reformated.toLowerCase().includes(str)) {
|
|
22
22
|
return 'valid';
|
|
23
23
|
}
|
|
24
|
-
} else if (account.chainType === _types.AccountChainType.TON) {
|
|
24
|
+
} else if (account.chainType === _types.AccountChainType.TON || account.chainType === _types.AccountChainType.CARDANO) {
|
|
25
|
+
// todo: recheck for Cardano
|
|
25
26
|
const isTestnet = chainInfo.isTestnet;
|
|
26
27
|
const reformated = (0, _common.reformatAddress)(account.address, isTestnet ? 0 : 1);
|
|
27
28
|
if (account.address.toLowerCase() === str || reformated.toLowerCase() === str) {
|
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports._reformatAddressWithChain = void 0;
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
6
|
+
exports.getAccountChainTypeForAddress = exports._reformatAddressWithChain = void 0;
|
|
7
|
+
exports.getAddressesByChainType = getAddressesByChainType;
|
|
8
|
+
exports.getAddressesByChainTypeMap = getAddressesByChainTypeMap;
|
|
9
9
|
exports.isAccountAll = isAccountAll;
|
|
10
10
|
exports.modifyAccountName = void 0;
|
|
11
11
|
exports.quickFormatAddressToCompare = quickFormatAddressToCompare;
|
|
12
12
|
exports.reformatAddress = reformatAddress;
|
|
13
|
+
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
13
14
|
var _constants = require("@subwallet/extension-base/constants");
|
|
14
15
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
15
16
|
var _types = require("@subwallet/extension-base/types");
|
|
@@ -50,10 +51,11 @@ function reformatAddress(address) {
|
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
const _reformatAddressWithChain = (address, chainInfo) => {
|
|
54
|
+
// todo: check for cardano
|
|
53
55
|
const chainType = (0, _utils._chainInfoToChainType)(chainInfo);
|
|
54
56
|
if (chainType === _types.AccountChainType.SUBSTRATE) {
|
|
55
57
|
return reformatAddress(address, (0, _utils._getChainSubstrateAddressPrefix)(chainInfo));
|
|
56
|
-
} else if (chainType === _types.AccountChainType.TON) {
|
|
58
|
+
} else if (chainType === _types.AccountChainType.TON || chainType === _types.AccountChainType.CARDANO) {
|
|
57
59
|
const isTestnet = chainInfo.isTestnet;
|
|
58
60
|
return reformatAddress(address, isTestnet ? 0 : 1);
|
|
59
61
|
} else {
|
|
@@ -63,31 +65,38 @@ const _reformatAddressWithChain = (address, chainInfo) => {
|
|
|
63
65
|
exports._reformatAddressWithChain = _reformatAddressWithChain;
|
|
64
66
|
const getAccountChainTypeForAddress = address => {
|
|
65
67
|
const type = (0, _keyring.getKeypairTypeByAddress)(address);
|
|
66
|
-
return (0, _utils2.
|
|
68
|
+
return (0, _utils2.getAccountChainTypeFromKeypairType)(type);
|
|
67
69
|
};
|
|
68
70
|
exports.getAccountChainTypeForAddress = getAccountChainTypeForAddress;
|
|
69
|
-
function
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
function getAddressesByChainType(addresses, chainTypes) {
|
|
72
|
+
const addressByChainTypeMap = getAddressesByChainTypeMap(addresses);
|
|
73
|
+
return chainTypes.map(chainType => {
|
|
74
|
+
return addressByChainTypeMap[chainType];
|
|
75
|
+
}).flat(); // todo: recheck
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function getAddressesByChainTypeMap(addresses) {
|
|
79
|
+
const addressByChainType = {
|
|
80
|
+
substrate: [],
|
|
81
|
+
evm: [],
|
|
82
|
+
bitcoin: [],
|
|
83
|
+
ton: [],
|
|
84
|
+
cardano: []
|
|
85
|
+
};
|
|
74
86
|
addresses.forEach(address => {
|
|
75
87
|
if ((0, _utilCrypto.isEthereumAddress)(address)) {
|
|
76
|
-
evm.push(address);
|
|
88
|
+
addressByChainType.evm.push(address);
|
|
77
89
|
} else if ((0, _keyring.isTonAddress)(address)) {
|
|
78
|
-
ton.push(address);
|
|
90
|
+
addressByChainType.ton.push(address);
|
|
79
91
|
} else if ((0, _keyring.isBitcoinAddress)(address)) {
|
|
80
|
-
bitcoin.push(address);
|
|
92
|
+
addressByChainType.bitcoin.push(address);
|
|
93
|
+
} else if ((0, _keyring.isCardanoAddress)(address)) {
|
|
94
|
+
addressByChainType.cardano.push(address);
|
|
81
95
|
} else {
|
|
82
|
-
substrate.push(address);
|
|
96
|
+
addressByChainType.substrate.push(address);
|
|
83
97
|
}
|
|
84
98
|
});
|
|
85
|
-
return
|
|
86
|
-
bitcoin,
|
|
87
|
-
evm,
|
|
88
|
-
substrate,
|
|
89
|
-
ton
|
|
90
|
-
};
|
|
99
|
+
return addressByChainType;
|
|
91
100
|
}
|
|
92
101
|
function quickFormatAddressToCompare(address) {
|
|
93
102
|
if (!(0, _keyring.isAddress)(address)) {
|
|
@@ -24,12 +24,16 @@ const parseUnifiedSuriToDerivationPath = (suri, type) => {
|
|
|
24
24
|
return `m/44'/60'/0'/0/${first}/${secondIndex}`;
|
|
25
25
|
} else if (type === 'ton') {
|
|
26
26
|
return `m/44'/607'/${first}'/${secondIndex}'`;
|
|
27
|
+
} else if (type === 'cardano') {
|
|
28
|
+
return `m/1852'/1815'/${first}'/${secondIndex}'`;
|
|
27
29
|
}
|
|
28
30
|
} else {
|
|
29
31
|
if (type === 'ethereum') {
|
|
30
32
|
return `m/44'/60'/0'/0/${first}`;
|
|
31
33
|
} else if (type === 'ton') {
|
|
32
34
|
return `m/44'/607'/${first}'`;
|
|
35
|
+
} else if (type === 'cardano') {
|
|
36
|
+
return `m/1852'/1815'/${first}'`;
|
|
33
37
|
}
|
|
34
38
|
}
|
|
35
39
|
if (_types.SubstrateKeypairTypes.includes(type)) {
|
|
@@ -48,7 +52,7 @@ const getSoloDerivationInfo = function (type) {
|
|
|
48
52
|
} = metadata;
|
|
49
53
|
if (suri) {
|
|
50
54
|
if (derivePath) {
|
|
51
|
-
const validateTypeFunc = type === 'ethereum' ? _validate.validateEvmDerivationPath : type === 'ton' ? _validate.validateTonDerivationPath : () => undefined;
|
|
55
|
+
const validateTypeFunc = type === 'ethereum' ? _validate.validateEvmDerivationPath : type === 'ton' ? _validate.validateTonDerivationPath : type === 'cardano' ? _validate.validateCardanoDerivationPath : () => undefined;
|
|
52
56
|
const validateTypeRs = validateTypeFunc(derivePath);
|
|
53
57
|
if (validateTypeRs) {
|
|
54
58
|
return {
|
|
@@ -105,7 +109,7 @@ const getSoloDerivationInfo = function (type) {
|
|
|
105
109
|
}
|
|
106
110
|
} else {
|
|
107
111
|
if (derivePath) {
|
|
108
|
-
const validateTypeFunc = type === 'ethereum' ? _validate.validateEvmDerivationPath : type === 'ton' ? _validate.validateTonDerivationPath : () => undefined;
|
|
112
|
+
const validateTypeFunc = type === 'ethereum' ? _validate.validateEvmDerivationPath : type === 'ton' ? _validate.validateTonDerivationPath : type === 'cardano' ? _validate.validateCardanoDerivationPath : () => undefined;
|
|
109
113
|
const validateTypeRs = validateTypeFunc(derivePath);
|
|
110
114
|
if (validateTypeRs) {
|
|
111
115
|
return {
|
|
@@ -224,6 +228,7 @@ const derivePair = (parentPair, name, suri, derivationPath) => {
|
|
|
224
228
|
}
|
|
225
229
|
const isEvm = _types.EthereumKeypairTypes.includes(parentPair.type);
|
|
226
230
|
const isTon = parentPair.type === 'ton';
|
|
231
|
+
const isCardano = parentPair.type === 'cardano';
|
|
227
232
|
const meta = {
|
|
228
233
|
name,
|
|
229
234
|
parentAddress: parentPair.address,
|
|
@@ -234,8 +239,8 @@ const derivePair = (parentPair, name, suri, derivationPath) => {
|
|
|
234
239
|
if (isTon && (_parentPair$ton = parentPair.ton) !== null && _parentPair$ton !== void 0 && _parentPair$ton.contractVersion) {
|
|
235
240
|
meta.tonContractVersion = parentPair.ton.contractVersion;
|
|
236
241
|
}
|
|
237
|
-
if (derivationPath && (isEvm || isTon)) {
|
|
238
|
-
return isEvm ? parentPair.evm.deriveCustom(derivationPath, meta) : parentPair.ton.deriveCustom(derivationPath, meta);
|
|
242
|
+
if (derivationPath && (isEvm || isTon || isCardano)) {
|
|
243
|
+
return isEvm ? parentPair.evm.deriveCustom(derivationPath, meta) : isTon ? parentPair.ton.deriveCustom(derivationPath, meta) : parentPair.cardano.deriveCustom(derivationPath, meta);
|
|
239
244
|
} else {
|
|
240
245
|
return parentPair.substrate.derive(suri, meta);
|
|
241
246
|
}
|