@subwallet/extension-base 0.5.3-1 → 0.5.6-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.
@@ -1,13 +1,15 @@
1
1
  import { AuthUrls, Resolver } from '@subwallet/extension-base/background/handlers/State';
2
- import { AccountAuthType, AccountJson, AuthorizeRequest, RequestAccountList, RequestAccountSubscribe, RequestAuthorizeCancel, RequestAuthorizeReject, RequestAuthorizeSubscribe, RequestAuthorizeTab, RequestCurrentAccountAddress, ResponseAuthorizeList, ResponseJsonGetAccountInfo, SeedLengths } from '@subwallet/extension-base/background/types';
2
+ import { AccountAuthType, AccountJson, AuthorizeRequest, RequestAccountList, RequestAccountSubscribe, RequestAuthorizeCancel, RequestAuthorizeReject, RequestAuthorizeSubscribe, RequestAuthorizeTab, RequestCurrentAccountAddress, RequestParseTransactionSubstrate, RequestQRIsLocked, RequestQrSignSubstrate, ResponseAuthorizeList, ResponseJsonGetAccountInfo, ResponseParseTransactionSubstrate, ResponseQRIsLocked, ResponseQrSignSubstrate, SeedLengths } from '@subwallet/extension-base/background/types';
3
+ import { ExternalState, LedgerState, QrState } from '@subwallet/extension-base/signers/types';
3
4
  import { InjectedAccount, MetadataDefBase } from '@subwallet/extension-inject/types';
4
5
  import Web3 from 'web3';
5
6
  import { RequestArguments, TransactionConfig } from 'web3-core';
6
7
  import { JsonRpcPayload, JsonRpcResponse } from 'web3-core-helpers';
7
8
  import { ApiPromise } from '@polkadot/api';
8
9
  import { SubmittableExtrinsicFunction } from '@polkadot/api/promise/types';
9
- import { KeyringPair$Json } from '@polkadot/keyring/types';
10
+ import { KeyringPair$Json, KeyringPair$Meta } from '@polkadot/keyring/types';
10
11
  import { Registry } from '@polkadot/types/types';
12
+ import { SignerResult } from '@polkadot/types/types/extrinsic';
11
13
  import { SingleAddress } from '@polkadot/ui-keyring/observable/types';
12
14
  import { KeyringOptions } from '@polkadot/ui-keyring/options/types';
13
15
  import { KeyringPairs$Json } from '@polkadot/ui-keyring/types';
@@ -315,11 +317,12 @@ export declare type TokenInfo = {
315
317
  symbol: string;
316
318
  symbolAlt?: string;
317
319
  erc20Address?: string;
318
- assetIndex?: number;
320
+ assetIndex?: number | string;
319
321
  decimals: number;
320
322
  name: string;
321
323
  coinGeckoKey?: string;
322
324
  specialOption?: object;
325
+ assetId?: string;
323
326
  };
324
327
  export interface AccountsWithCurrentAddress {
325
328
  accounts: AccountJson[];
@@ -453,8 +456,20 @@ export interface RequestCrossChainTransfer extends RequestCheckCrossChainTransfe
453
456
  }
454
457
  export interface ResponseCheckCrossChainTransfer {
455
458
  errors?: Array<TransferError>;
456
- estimateFee?: string;
457
- feeSymbol?: string;
459
+ feeString?: string;
460
+ estimatedFee: string;
461
+ feeSymbol: string;
462
+ }
463
+ export declare type RequestTransferExternal = RequestCheckTransfer;
464
+ export declare type RequestCrossChainTransferExternal = RequestCheckCrossChainTransfer;
465
+ export interface RequestRejectExternalRequest {
466
+ id: string;
467
+ message?: string;
468
+ throwError?: boolean;
469
+ }
470
+ export interface RequestResolveExternalRequest {
471
+ id: string;
472
+ data: SignerResult;
458
473
  }
459
474
  export interface ResponsePrivateKeyValidateV2 {
460
475
  addressMap: Record<KeypairType, string>;
@@ -505,16 +520,36 @@ export declare enum TransferErrorCode {
505
520
  NOT_ENOUGH_VALUE = "notEnoughValue",
506
521
  INVALID_VALUE = "invalidValue",
507
522
  INVALID_TOKEN = "invalidToken",
523
+ INVALID_PARAM = "invalidParam",
508
524
  KEYRING_ERROR = "keyringError",
509
525
  TRANSFER_ERROR = "transferError",
510
526
  TIMEOUT = "timeout",
511
527
  UNSUPPORTED = "unsupported"
512
528
  }
529
+ export declare enum BasicTxErrorCode {
530
+ INVALID_FROM_ADDRESS = "invalidFromAccount",
531
+ INVALID_TO_ADDRESS = "invalidToAccount",
532
+ NOT_ENOUGH_VALUE = "notEnoughValue",
533
+ INVALID_VALUE = "invalidValue",
534
+ INVALID_TOKEN = "invalidToken",
535
+ INVALID_PARAM = "invalidParam",
536
+ KEYRING_ERROR = "keyringError",
537
+ TRANSFER_ERROR = "transferError",
538
+ STAKING_ERROR = "stakingError",
539
+ UN_STAKING_ERROR = "unStakingError",
540
+ WITHDRAW_STAKING_ERROR = "withdrawStakingError",
541
+ TIMEOUT = "timeout",
542
+ UNSUPPORTED = "unsupported"
543
+ }
513
544
  export declare type TransferError = {
514
545
  code: TransferErrorCode;
515
546
  data?: object;
516
547
  message: string;
517
548
  };
549
+ export interface BaseTxError {
550
+ code: BasicTxErrorCode;
551
+ message: string;
552
+ }
518
553
  export interface ResponseCheckTransfer {
519
554
  errors?: Array<TransferError>;
520
555
  fromAccountFree: string;
@@ -524,12 +559,13 @@ export interface ResponseCheckTransfer {
524
559
  }
525
560
  export declare enum TransferStep {
526
561
  READY = "ready",
562
+ SIGNING = "signing",
527
563
  START = "start",
528
564
  PROCESSING = "processing",
529
565
  SUCCESS = "success",
530
566
  ERROR = "error"
531
567
  }
532
- declare type TxResultType = {
568
+ export declare type TxResultType = {
533
569
  change: string;
534
570
  changeSymbol?: string;
535
571
  fee?: string;
@@ -544,6 +580,16 @@ export interface ResponseTransfer {
544
580
  txResult?: TxResultType;
545
581
  isFinalized?: boolean;
546
582
  }
583
+ export interface ResponseTransferExternal extends ResponseTransfer {
584
+ externalState?: ExternalState;
585
+ }
586
+ export interface ResponseTransferQr extends ResponseTransferExternal {
587
+ qrState?: QrState;
588
+ isBusy?: boolean;
589
+ }
590
+ export interface ResponseTransferLedger extends ResponseTransferExternal {
591
+ ledgerState?: LedgerState;
592
+ }
547
593
  export interface EvmNftTransactionRequest {
548
594
  networkKey: string;
549
595
  senderAddress: string;
@@ -562,14 +608,6 @@ export interface EvmNftSubmitTransaction {
562
608
  networkKey: string;
563
609
  rawTransaction: Record<string, any>;
564
610
  }
565
- export interface NftTransactionResponse {
566
- passwordError?: string | null;
567
- callHash?: string;
568
- status?: boolean;
569
- transactionHash?: string;
570
- txError?: boolean;
571
- isSendingSelf: boolean;
572
- }
573
611
  export interface ValidateNetworkResponse {
574
612
  success: boolean;
575
613
  key: string;
@@ -672,12 +710,60 @@ export interface SubstrateNftSubmitTransaction {
672
710
  export declare type ChainRelationType = 'p' | 'r';
673
711
  export interface ChainRelationInfo {
674
712
  type: ChainRelationType;
713
+ isEthereum: boolean;
675
714
  supportedToken: string[];
676
715
  }
677
716
  export interface CrossChainRelation {
678
717
  type: ChainRelationType;
718
+ isEthereum: boolean;
679
719
  relationMap: Record<string, ChainRelationInfo>;
680
720
  }
721
+ export interface RequestAccountMeta {
722
+ address: string | Uint8Array;
723
+ }
724
+ export interface ResponseAccountMeta {
725
+ meta: KeyringPair$Meta;
726
+ }
727
+ export declare type ResponseRejectExternalRequest = void;
728
+ export declare type ResponseResolveExternalRequest = void;
729
+ export declare enum ExternalRequestPromiseStatus {
730
+ PENDING = 0,
731
+ REJECTED = 1,
732
+ FAILED = 2,
733
+ COMPLETED = 3
734
+ }
735
+ export interface ExternalRequestPromise {
736
+ resolve?: (result: SignerResult | PromiseLike<SignerResult>) => void;
737
+ reject?: (error?: Error) => void;
738
+ status: ExternalRequestPromiseStatus;
739
+ message?: string;
740
+ createdAt: number;
741
+ }
742
+ export interface RequestAccountCreateExternalV2 {
743
+ address: string;
744
+ genesisHash?: string | null;
745
+ name: string;
746
+ isEthereum: boolean;
747
+ isAllowed: boolean;
748
+ }
749
+ export interface RequestAccountCreateHardwareV2 {
750
+ accountIndex: number;
751
+ address: string;
752
+ addressOffset: number;
753
+ genesisHash: string;
754
+ hardwareType: string;
755
+ name: string;
756
+ isAllowed?: boolean;
757
+ }
758
+ export declare enum AccountExternalErrorCode {
759
+ INVALID_ADDRESS = "invalidToAccount",
760
+ KEYRING_ERROR = "keyringError",
761
+ UNKNOWN_ERROR = "unknownError"
762
+ }
763
+ export interface AccountExternalError {
764
+ code: AccountExternalErrorCode;
765
+ message: string;
766
+ }
681
767
  export declare type RequestEvmEvents = null;
682
768
  export declare type EvmEventType = 'connect' | 'disconnect' | 'accountsChanged' | 'chainChanged' | 'message' | 'data' | 'reconnect' | 'error';
683
769
  export declare type EvmAccountsChangedPayload = string[];
@@ -702,11 +788,13 @@ export interface ResponseEvmProviderSend {
702
788
  error: (Error | null);
703
789
  result?: JsonRpcResponse;
704
790
  }
705
- export interface EvmProviderRpcErrorInterface extends Error {
706
- message: string;
707
- code: number;
791
+ export interface SubWalletProviderErrorInterface extends Error {
792
+ code?: number;
708
793
  data?: unknown;
709
794
  }
795
+ export interface EvmProviderRpcErrorInterface extends SubWalletProviderErrorInterface {
796
+ code: number;
797
+ }
710
798
  export declare type EvmRpcErrorHelperMap = Record<'USER_REJECTED_REQUEST' | 'UNAUTHORIZED' | 'UNSUPPORTED_METHOD' | 'DISCONNECTED' | 'CHAIN_DISCONNECTED' | 'INVALID_PARAMS' | 'INTERNAL_ERROR', [number, string]>;
711
799
  export interface EvmSendTransactionParams {
712
800
  from: string;
@@ -745,15 +833,51 @@ export interface ConfirmationResult<T> {
745
833
  payload?: T;
746
834
  password?: string;
747
835
  }
836
+ export interface ConfirmationResultQr<T> extends ConfirmationResult<T> {
837
+ signature: `0x${string}`;
838
+ }
748
839
  export interface EvmSendTransactionRequest extends TransactionConfig {
749
840
  estimateGas: string;
750
841
  }
842
+ export interface EvmRequestQr {
843
+ qrPayload: string;
844
+ canSign: boolean;
845
+ }
846
+ export interface EvmSendTransactionRequestQr extends TransactionConfig, EvmRequestQr {
847
+ estimateGas: string;
848
+ }
849
+ export interface EvmSignatureRequestQr extends EvmSignatureRequest, EvmRequestQr {
850
+ }
751
851
  export interface ConfirmationDefinitions {
752
852
  addNetworkRequest: [ConfirmationsQueueItem<NetworkJson>, ConfirmationResult<NetworkJson>];
753
853
  addTokenRequest: [ConfirmationsQueueItem<CustomEvmToken>, ConfirmationResult<boolean>];
754
854
  switchNetworkRequest: [ConfirmationsQueueItem<SwitchNetworkRequest>, ConfirmationResult<boolean>];
755
855
  evmSignatureRequest: [ConfirmationsQueueItem<EvmSignatureRequest>, ConfirmationResult<string>];
856
+ evmSignatureRequestQr: [ConfirmationsQueueItem<EvmSignatureRequestQr>, ConfirmationResultQr<string>];
756
857
  evmSendTransactionRequest: [ConfirmationsQueueItem<EvmSendTransactionRequest>, ConfirmationResult<boolean>];
858
+ evmSendTransactionRequestQr: [ConfirmationsQueueItem<EvmSendTransactionRequestQr>, ConfirmationResultQr<boolean>];
859
+ }
860
+ export interface RequestParseTransactionEVM {
861
+ data: string;
862
+ }
863
+ export interface ResponseParseTransactionEVM {
864
+ data: ParseEVMTransactionData | string;
865
+ input: string;
866
+ nonce: number;
867
+ to: string;
868
+ gas: number;
869
+ gasPrice: number;
870
+ value: number;
871
+ }
872
+ export interface RequestQrSignEVM {
873
+ address: string;
874
+ message: string;
875
+ type: 'message' | 'transaction';
876
+ chainId?: number;
877
+ password: string;
878
+ }
879
+ export interface ResponseQrSignEVM {
880
+ signature: string;
757
881
  }
758
882
  export declare type ConfirmationType = keyof ConfirmationDefinitions;
759
883
  export declare type ConfirmationsQueue = {
@@ -812,6 +936,9 @@ export interface BasicTxResponse {
812
936
  transactionHash?: string;
813
937
  txError?: boolean;
814
938
  }
939
+ export interface NftTransactionResponse extends BasicTxResponse {
940
+ isSendingSelf: boolean;
941
+ }
815
942
  export interface BondingOptionParams {
816
943
  networkKey: string;
817
944
  address: string;
@@ -860,6 +987,51 @@ export interface StakeClaimRewardParams {
860
987
  validatorAddress?: string;
861
988
  password?: string;
862
989
  }
990
+ export interface ResponseNftTransferExternal extends NftTransactionResponse {
991
+ externalState?: ExternalState;
992
+ }
993
+ export interface ResponseNftTransferQr extends ResponseNftTransferExternal {
994
+ qrState?: QrState;
995
+ isBusy?: boolean;
996
+ }
997
+ export interface ResponseNftTransferLedger extends ResponseNftTransferExternal {
998
+ ledgerState?: LedgerState;
999
+ }
1000
+ export declare type RequestNftTransferExternalSubstrate = Omit<SubstrateNftSubmitTransaction, 'password'>;
1001
+ export declare type RequestNftTransferExternalEVM = Omit<EvmNftSubmitTransaction, 'password'>;
1002
+ export declare type RequestStakeExternal = Omit<BondingSubmitParams, 'password'>;
1003
+ export interface ResponseStakeExternal extends BasicTxResponse {
1004
+ externalState?: ExternalState;
1005
+ }
1006
+ export interface ResponseStakeQr extends ResponseStakeExternal {
1007
+ qrState?: QrState;
1008
+ isBusy?: boolean;
1009
+ }
1010
+ export interface ResponseStakeLedger extends ResponseStakeExternal {
1011
+ ledgerState?: LedgerState;
1012
+ }
1013
+ export declare type RequestUnStakeExternal = Omit<UnbondingSubmitParams, 'password'>;
1014
+ export interface ResponseUnStakeExternal extends BasicTxResponse {
1015
+ externalState?: ExternalState;
1016
+ }
1017
+ export interface ResponseUnStakeQr extends ResponseUnStakeExternal {
1018
+ qrState?: QrState;
1019
+ isBusy?: boolean;
1020
+ }
1021
+ export interface ResponseUnStakeLedger extends ResponseUnStakeExternal {
1022
+ ledgerState?: LedgerState;
1023
+ }
1024
+ export declare type RequestWithdrawStakeExternal = Omit<StakeWithdrawalParams, 'password'>;
1025
+ export interface ResponseWithdrawStakeExternal extends BasicTxResponse {
1026
+ externalState?: ExternalState;
1027
+ }
1028
+ export interface ResponseWithdrawStakeQr extends ResponseWithdrawStakeExternal {
1029
+ qrState?: QrState;
1030
+ isBusy?: boolean;
1031
+ }
1032
+ export interface ResponseWithdrawStakeLedger extends ResponseWithdrawStakeExternal {
1033
+ ledgerState?: LedgerState;
1034
+ }
863
1035
  export interface StakeDelegationRequest {
864
1036
  address: string;
865
1037
  networkKey: string;
@@ -889,6 +1061,13 @@ export interface RequestParseEVMTransactionInput {
889
1061
  export interface ResponseParseEVMTransactionInput {
890
1062
  result: ParseEVMTransactionData | string;
891
1063
  }
1064
+ export interface LedgerNetwork {
1065
+ genesisHash: string;
1066
+ displayName: string;
1067
+ network: string;
1068
+ icon: 'substrate' | 'ethereum';
1069
+ isDevMode: boolean;
1070
+ }
892
1071
  export interface KoniRequestSignatures {
893
1072
  'pri(staking.delegationInfo)': [StakeDelegationRequest, DelegationItem[]];
894
1073
  'pri(staking.submitClaimReward)': [StakeClaimRewardParams, BasicTxResponse, BasicTxResponse];
@@ -957,6 +1136,8 @@ export interface KoniRequestSignatures {
957
1136
  'pri(seed.validateV2)': [RequestSeedValidateV2, ResponseSeedValidateV2];
958
1137
  'pri(privateKey.validateV2)': [RequestSeedValidateV2, ResponsePrivateKeyValidateV2];
959
1138
  'pri(accounts.create.suriV2)': [RequestAccountCreateSuriV2, ResponseAccountCreateSuriV2];
1139
+ 'pri(accounts.create.externalV2)': [RequestAccountCreateExternalV2, AccountExternalError[]];
1140
+ 'pri(accounts.create.hardwareV2)': [RequestAccountCreateHardwareV2, boolean];
960
1141
  'pri(accounts.checkTransfer)': [RequestCheckTransfer, ResponseCheckTransfer];
961
1142
  'pri(accounts.checkCrossChainTransfer)': [RequestCheckCrossChainTransfer, ResponseCheckCrossChainTransfer];
962
1143
  'pri(accounts.transfer)': [RequestTransfer, Array<TransferError>, ResponseTransfer];
@@ -969,6 +1150,7 @@ export interface KoniRequestSignatures {
969
1150
  'pri(accounts.subscribeAccountsInputAddress)': [RequestAccountSubscribe, string, OptionInputAddress];
970
1151
  'pri(accounts.saveRecent)': [RequestSaveRecentAccount, SingleAddress];
971
1152
  'pri(accounts.triggerSubscription)': [null, boolean];
1153
+ 'pri(accounts.get.meta)': [RequestAccountMeta, ResponseAccountMeta];
972
1154
  'pri(currentAccount.saveAddress)': [RequestCurrentAccountAddress, boolean, CurrentAccountInfo];
973
1155
  'pri(settings.changeBalancesVisibility)': [null, boolean, ResponseSettingsType];
974
1156
  'pri(settings.subscribe)': [null, ResponseSettingsType, ResponseSettingsType];
@@ -987,13 +1169,32 @@ export interface KoniRequestSignatures {
987
1169
  'pub(utils.getRandom)': [RandomTestRequest, number];
988
1170
  'pub(accounts.listV2)': [RequestAccountList, InjectedAccount[]];
989
1171
  'pub(accounts.subscribeV2)': [RequestAccountSubscribe, boolean, InjectedAccount[]];
1172
+ 'pri(qr.transaction.parse.substrate)': [RequestParseTransactionSubstrate, ResponseParseTransactionSubstrate];
1173
+ 'pri(qr.transaction.parse.evm)': [RequestParseTransactionEVM, ResponseParseTransactionEVM];
1174
+ 'pri(qr.isLocked)': [RequestQRIsLocked, ResponseQRIsLocked];
1175
+ 'pri(qr.sign.substrate)': [RequestQrSignSubstrate, ResponseQrSignSubstrate];
1176
+ 'pri(qr.sign.evm)': [RequestQrSignEVM, ResponseQrSignEVM];
1177
+ 'pri(account.external.reject)': [RequestRejectExternalRequest, ResponseRejectExternalRequest];
1178
+ 'pri(account.external.resolve)': [RequestResolveExternalRequest, ResponseResolveExternalRequest];
990
1179
  'evm(events.subscribe)': [RequestEvmEvents, boolean, EvmEvent];
991
1180
  'evm(request)': [RequestArguments, unknown];
992
1181
  'evm(provider.send)': [RequestEvmProviderSend, string | number, ResponseEvmProviderSend];
993
1182
  'pri(evm.transaction.parse.input)': [RequestParseEVMTransactionInput, ResponseParseEVMTransactionInput];
1183
+ 'pri(accounts.transfer.qr.create)': [RequestTransferExternal, Array<TransferError>, ResponseTransferQr];
1184
+ 'pri(accounts.cross.transfer.qr.create)': [RequestCrossChainTransferExternal, Array<TransferError>, ResponseTransferQr];
1185
+ 'pri(nft.transfer.qr.create.substrate)': [RequestNftTransferExternalSubstrate, Array<BaseTxError>, ResponseNftTransferQr];
1186
+ 'pri(nft.transfer.qr.create.evm)': [RequestNftTransferExternalEVM, Array<BaseTxError>, ResponseNftTransferQr];
1187
+ 'pri(stake.qr.create)': [RequestStakeExternal, Array<BaseTxError>, ResponseStakeQr];
1188
+ 'pri(unStake.qr.create)': [RequestUnStakeExternal, Array<BaseTxError>, ResponseUnStakeQr];
1189
+ 'pri(withdrawStake.qr.create)': [RequestWithdrawStakeExternal, Array<BaseTxError>, ResponseWithdrawStakeQr];
1190
+ 'pri(accounts.transfer.ledger.create)': [RequestTransferExternal, Array<TransferError>, ResponseTransferLedger];
1191
+ 'pri(accounts.cross.transfer.ledger.create)': [RequestCrossChainTransferExternal, Array<TransferError>, ResponseTransferLedger];
1192
+ 'pri(nft.transfer.ledger.create.substrate)': [RequestNftTransferExternalSubstrate, Array<BaseTxError>, ResponseNftTransferQr];
1193
+ 'pri(stake.ledger.create)': [RequestStakeExternal, Array<BaseTxError>, ResponseStakeLedger];
1194
+ 'pri(unStake.ledger.create)': [RequestUnStakeExternal, Array<BaseTxError>, ResponseUnStakeLedger];
1195
+ 'pri(withdrawStake.ledger.create)': [RequestWithdrawStakeExternal, Array<BaseTxError>, ResponseWithdrawStakeLedger];
994
1196
  'pri(authorize.subscribe)': [null, AuthUrls, AuthUrls];
995
1197
  }
996
1198
  export interface ApplicationMetadataType {
997
1199
  version: string;
998
1200
  }
999
- export {};
@@ -64,18 +64,55 @@ export let TransferErrorCode;
64
64
  TransferErrorCode["NOT_ENOUGH_VALUE"] = "notEnoughValue";
65
65
  TransferErrorCode["INVALID_VALUE"] = "invalidValue";
66
66
  TransferErrorCode["INVALID_TOKEN"] = "invalidToken";
67
+ TransferErrorCode["INVALID_PARAM"] = "invalidParam";
67
68
  TransferErrorCode["KEYRING_ERROR"] = "keyringError";
68
69
  TransferErrorCode["TRANSFER_ERROR"] = "transferError";
69
70
  TransferErrorCode["TIMEOUT"] = "timeout";
70
71
  TransferErrorCode["UNSUPPORTED"] = "unsupported";
71
72
  })(TransferErrorCode || (TransferErrorCode = {}));
72
73
 
74
+ export let BasicTxErrorCode;
75
+
76
+ (function (BasicTxErrorCode) {
77
+ BasicTxErrorCode["INVALID_FROM_ADDRESS"] = "invalidFromAccount";
78
+ BasicTxErrorCode["INVALID_TO_ADDRESS"] = "invalidToAccount";
79
+ BasicTxErrorCode["NOT_ENOUGH_VALUE"] = "notEnoughValue";
80
+ BasicTxErrorCode["INVALID_VALUE"] = "invalidValue";
81
+ BasicTxErrorCode["INVALID_TOKEN"] = "invalidToken";
82
+ BasicTxErrorCode["INVALID_PARAM"] = "invalidParam";
83
+ BasicTxErrorCode["KEYRING_ERROR"] = "keyringError";
84
+ BasicTxErrorCode["TRANSFER_ERROR"] = "transferError";
85
+ BasicTxErrorCode["STAKING_ERROR"] = "stakingError";
86
+ BasicTxErrorCode["UN_STAKING_ERROR"] = "unStakingError";
87
+ BasicTxErrorCode["WITHDRAW_STAKING_ERROR"] = "withdrawStakingError";
88
+ BasicTxErrorCode["TIMEOUT"] = "timeout";
89
+ BasicTxErrorCode["UNSUPPORTED"] = "unsupported";
90
+ })(BasicTxErrorCode || (BasicTxErrorCode = {}));
91
+
73
92
  export let TransferStep;
74
93
 
75
94
  (function (TransferStep) {
76
95
  TransferStep["READY"] = "ready";
96
+ TransferStep["SIGNING"] = "signing";
77
97
  TransferStep["START"] = "start";
78
98
  TransferStep["PROCESSING"] = "processing";
79
99
  TransferStep["SUCCESS"] = "success";
80
100
  TransferStep["ERROR"] = "error";
81
- })(TransferStep || (TransferStep = {}));
101
+ })(TransferStep || (TransferStep = {}));
102
+
103
+ export let ExternalRequestPromiseStatus;
104
+
105
+ (function (ExternalRequestPromiseStatus) {
106
+ ExternalRequestPromiseStatus[ExternalRequestPromiseStatus["PENDING"] = 0] = "PENDING";
107
+ ExternalRequestPromiseStatus[ExternalRequestPromiseStatus["REJECTED"] = 1] = "REJECTED";
108
+ ExternalRequestPromiseStatus[ExternalRequestPromiseStatus["FAILED"] = 2] = "FAILED";
109
+ ExternalRequestPromiseStatus[ExternalRequestPromiseStatus["COMPLETED"] = 3] = "COMPLETED";
110
+ })(ExternalRequestPromiseStatus || (ExternalRequestPromiseStatus = {}));
111
+
112
+ export let AccountExternalErrorCode;
113
+
114
+ (function (AccountExternalErrorCode) {
115
+ AccountExternalErrorCode["INVALID_ADDRESS"] = "invalidToAccount";
116
+ AccountExternalErrorCode["KEYRING_ERROR"] = "keyringError";
117
+ AccountExternalErrorCode["UNKNOWN_ERROR"] = "unknownError";
118
+ })(AccountExternalErrorCode || (AccountExternalErrorCode = {}));
@@ -39,6 +39,8 @@ export default class Extension {
39
39
  private signingApproveSignature;
40
40
  private signingCancel;
41
41
  private signingIsLocked;
42
+ private qrIsLocked;
43
+ private qrSignSubstrate;
42
44
  private signingSubscribe;
43
45
  private windowOpen;
44
46
  private derive;
@@ -4,7 +4,7 @@ import { ALLOWED_PATH, PASSWORD_EXPIRY_MS } from '@subwallet/extension-base/defa
4
4
  import { TypeRegistry } from '@polkadot/types';
5
5
  import keyring from '@polkadot/ui-keyring';
6
6
  import { accounts as accountsObservable } from '@polkadot/ui-keyring/observable/accounts';
7
- import { assert, isHex } from '@polkadot/util';
7
+ import { assert, isHex, u8aToHex } from '@polkadot/util';
8
8
  import { keyExtractSuri, mnemonicGenerate, mnemonicValidate } from '@polkadot/util-crypto';
9
9
  import { withErrorLog } from "./helpers.js";
10
10
  import { createSubscription, unsubscribe } from "./subscriptions.js";
@@ -475,6 +475,53 @@ export default class Extension {
475
475
  isLocked: pair.isLocked,
476
476
  remainingTime
477
477
  };
478
+ }
479
+
480
+ qrIsLocked({
481
+ address
482
+ }) {
483
+ const pair = keyring.getPair(address);
484
+ assert(pair, 'Unable to find pair');
485
+ const remainingTime = this.refreshAccountPasswordCache(pair);
486
+ return {
487
+ isLocked: pair.isLocked,
488
+ remainingTime
489
+ };
490
+ }
491
+
492
+ qrSignSubstrate({
493
+ address,
494
+ message,
495
+ password,
496
+ savePass
497
+ }) {
498
+ const pair = keyring.getPair(address);
499
+ assert(pair, 'Unable to find pair');
500
+
501
+ if (pair.isLocked && !password) {
502
+ throw new Error('Password needed to unlock the account');
503
+ }
504
+
505
+ if (pair.isLocked) {
506
+ try {
507
+ pair.decodePkcs8(password);
508
+ } catch (e) {
509
+ throw new Error('invalid password');
510
+ }
511
+ }
512
+
513
+ const signed = u8aToHex(pair.sign(message));
514
+ const _address = pair.address;
515
+
516
+ if (savePass) {
517
+ this.#cachedUnlocks[_address] = Date.now() + PASSWORD_EXPIRY_MS;
518
+ } else {
519
+ pair.lock();
520
+ }
521
+
522
+ return {
523
+ signature: signed
524
+ };
478
525
  } // FIXME This looks very much like what we have in authorization
479
526
 
480
527
 
@@ -662,6 +709,12 @@ export default class Extension {
662
709
  case 'pri(signing.isLocked)':
663
710
  return this.signingIsLocked(request);
664
711
 
712
+ case 'pri(qr.isLocked)':
713
+ return this.qrIsLocked(request);
714
+
715
+ case 'pri(qr.sign.substrate)':
716
+ return this.qrSignSubstrate(request);
717
+
665
718
  case 'pri(signing.requests)':
666
719
  return this.signingSubscribe(id, port);
667
720
 
@@ -5,7 +5,7 @@ import type { SignerPayloadJSON, SignerPayloadRaw } from '@polkadot/types/types'
5
5
  import type { KeyringPairs$Json } from '@polkadot/ui-keyring/types';
6
6
  import type { HexString } from '@polkadot/util/types';
7
7
  import type { KeypairType } from '@polkadot/util-crypto/types';
8
- import { CurrentNetworkInfo, KoniRequestSignatures } from '@subwallet/extension-base/background/KoniTypes';
8
+ import { CurrentNetworkInfo, KoniRequestSignatures, NetworkJson } from '@subwallet/extension-base/background/KoniTypes';
9
9
  import { TypeRegistry } from '@polkadot/types';
10
10
  import { ALLOWED_PATH } from '../defaults';
11
11
  import { AuthUrls } from './handlers/State';
@@ -25,6 +25,7 @@ export declare type SeedLengths = 12 | 24;
25
25
  export interface AccountJson extends KeyringPair$Meta {
26
26
  address: string;
27
27
  genesisHash?: string | null;
28
+ originGenesisHash?: string | null;
28
29
  isExternal?: boolean;
29
30
  isHardware?: boolean;
30
31
  isHidden?: boolean;
@@ -38,13 +39,20 @@ export interface AccountsWithCurrentAddress {
38
39
  accounts: AccountJson[];
39
40
  currentAddress?: string;
40
41
  }
42
+ export interface CurrentAccountInfo {
43
+ address: string;
44
+ }
41
45
  export declare type AccountWithChildren = AccountJson & {
42
46
  children?: AccountWithChildren[];
43
47
  };
48
+ export interface FindAccountFunction {
49
+ (networkMap: Record<string, NetworkJson>, address: string, genesisHash?: string): AccountJson | undefined;
50
+ }
44
51
  export declare type AccountsContext = {
45
52
  accounts: AccountJson[];
46
53
  hierarchy: AccountWithChildren[];
47
54
  master?: AccountJson;
55
+ getAccountByAddress: FindAccountFunction;
48
56
  };
49
57
  export declare type CurrentAccContext = {
50
58
  currentAccount: AccountJson | null;
@@ -276,18 +284,36 @@ export interface RequestSeedValidate {
276
284
  suri: string;
277
285
  type?: KeypairType;
278
286
  }
287
+ export interface RequestParseTransactionSubstrate {
288
+ genesisHash: string;
289
+ rawPayload: string;
290
+ specVersion: number;
291
+ }
292
+ export interface RequestQRIsLocked {
293
+ address: string;
294
+ }
295
+ export interface RequestQrSignSubstrate {
296
+ address: string;
297
+ message: string;
298
+ savePass: boolean;
299
+ password?: string;
300
+ }
279
301
  export declare type ResponseTypes = {
280
302
  [MessageType in keyof RequestSignatures]: RequestSignatures[MessageType][1];
281
303
  };
282
304
  export declare type ResponseType<TMessageType extends keyof RequestSignatures> = RequestSignatures[TMessageType][1];
283
305
  interface TransportResponseMessageSub<TMessageType extends MessageTypesWithSubscriptions> {
284
306
  error?: string;
307
+ errorCode?: number;
308
+ errorData?: unknown;
285
309
  id: string;
286
310
  response?: ResponseTypes[TMessageType];
287
311
  subscription?: SubscriptionMessageTypes[TMessageType];
288
312
  }
289
313
  interface TransportResponseMessageNoSub<TMessageType extends MessageTypesWithNoSubscriptions> {
290
314
  error?: string;
315
+ errorCode?: number;
316
+ errorData?: unknown;
291
317
  id: string;
292
318
  response?: ResponseTypes[TMessageType];
293
319
  }
@@ -349,4 +375,30 @@ export interface ResponseJsonGetAccountInfo {
349
375
  export interface ResponseAuthorizeList {
350
376
  list: AuthUrls;
351
377
  }
378
+ export interface FormattedMethod {
379
+ args?: ArgInfo[];
380
+ method: string;
381
+ }
382
+ export interface ArgInfo {
383
+ argName: string;
384
+ argValue: string | string[];
385
+ }
386
+ export interface EraInfo {
387
+ period: number;
388
+ phase: number;
389
+ }
390
+ export interface ResponseParseTransactionSubstrate {
391
+ era: EraInfo | string;
392
+ nonce: number;
393
+ method: string;
394
+ tip: number;
395
+ specVersion: number;
396
+ }
397
+ export interface ResponseQRIsLocked {
398
+ isLocked: boolean;
399
+ remainingTime: number;
400
+ }
401
+ export interface ResponseQrSignSubstrate {
402
+ signature: string;
403
+ }
352
404
  export {};