@subwallet/extension-base 0.5.3-1 → 0.5.4-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,18 @@ 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
+ }
461
+ export declare type RequestTransferExternal = RequestCheckTransfer;
462
+ export declare type RequestCrossChainTransferExternal = RequestCheckCrossChainTransfer;
463
+ export interface RequestRejectExternalRequest {
464
+ id: string;
465
+ message?: string;
466
+ throwError?: boolean;
467
+ }
468
+ export interface RequestResolveExternalRequest {
469
+ id: string;
470
+ data: SignerResult;
458
471
  }
459
472
  export interface ResponsePrivateKeyValidateV2 {
460
473
  addressMap: Record<KeypairType, string>;
@@ -505,16 +518,36 @@ export declare enum TransferErrorCode {
505
518
  NOT_ENOUGH_VALUE = "notEnoughValue",
506
519
  INVALID_VALUE = "invalidValue",
507
520
  INVALID_TOKEN = "invalidToken",
521
+ INVALID_PARAM = "invalidParam",
508
522
  KEYRING_ERROR = "keyringError",
509
523
  TRANSFER_ERROR = "transferError",
510
524
  TIMEOUT = "timeout",
511
525
  UNSUPPORTED = "unsupported"
512
526
  }
527
+ export declare enum BasicTxErrorCode {
528
+ INVALID_FROM_ADDRESS = "invalidFromAccount",
529
+ INVALID_TO_ADDRESS = "invalidToAccount",
530
+ NOT_ENOUGH_VALUE = "notEnoughValue",
531
+ INVALID_VALUE = "invalidValue",
532
+ INVALID_TOKEN = "invalidToken",
533
+ INVALID_PARAM = "invalidParam",
534
+ KEYRING_ERROR = "keyringError",
535
+ TRANSFER_ERROR = "transferError",
536
+ STAKING_ERROR = "stakingError",
537
+ UN_STAKING_ERROR = "unStakingError",
538
+ WITHDRAW_STAKING_ERROR = "withdrawStakingError",
539
+ TIMEOUT = "timeout",
540
+ UNSUPPORTED = "unsupported"
541
+ }
513
542
  export declare type TransferError = {
514
543
  code: TransferErrorCode;
515
544
  data?: object;
516
545
  message: string;
517
546
  };
547
+ export interface BaseTxError {
548
+ code: BasicTxErrorCode;
549
+ message: string;
550
+ }
518
551
  export interface ResponseCheckTransfer {
519
552
  errors?: Array<TransferError>;
520
553
  fromAccountFree: string;
@@ -524,12 +557,13 @@ export interface ResponseCheckTransfer {
524
557
  }
525
558
  export declare enum TransferStep {
526
559
  READY = "ready",
560
+ SIGNING = "signing",
527
561
  START = "start",
528
562
  PROCESSING = "processing",
529
563
  SUCCESS = "success",
530
564
  ERROR = "error"
531
565
  }
532
- declare type TxResultType = {
566
+ export declare type TxResultType = {
533
567
  change: string;
534
568
  changeSymbol?: string;
535
569
  fee?: string;
@@ -544,6 +578,16 @@ export interface ResponseTransfer {
544
578
  txResult?: TxResultType;
545
579
  isFinalized?: boolean;
546
580
  }
581
+ export interface ResponseTransferExternal extends ResponseTransfer {
582
+ externalState?: ExternalState;
583
+ }
584
+ export interface ResponseTransferQr extends ResponseTransferExternal {
585
+ qrState?: QrState;
586
+ isBusy?: boolean;
587
+ }
588
+ export interface ResponseTransferLedger extends ResponseTransferExternal {
589
+ ledgerState?: LedgerState;
590
+ }
547
591
  export interface EvmNftTransactionRequest {
548
592
  networkKey: string;
549
593
  senderAddress: string;
@@ -562,14 +606,6 @@ export interface EvmNftSubmitTransaction {
562
606
  networkKey: string;
563
607
  rawTransaction: Record<string, any>;
564
608
  }
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
609
  export interface ValidateNetworkResponse {
574
610
  success: boolean;
575
611
  key: string;
@@ -672,12 +708,60 @@ export interface SubstrateNftSubmitTransaction {
672
708
  export declare type ChainRelationType = 'p' | 'r';
673
709
  export interface ChainRelationInfo {
674
710
  type: ChainRelationType;
711
+ isEthereum: boolean;
675
712
  supportedToken: string[];
676
713
  }
677
714
  export interface CrossChainRelation {
678
715
  type: ChainRelationType;
716
+ isEthereum: boolean;
679
717
  relationMap: Record<string, ChainRelationInfo>;
680
718
  }
719
+ export interface RequestAccountMeta {
720
+ address: string | Uint8Array;
721
+ }
722
+ export interface ResponseAccountMeta {
723
+ meta: KeyringPair$Meta;
724
+ }
725
+ export declare type ResponseRejectExternalRequest = void;
726
+ export declare type ResponseResolveExternalRequest = void;
727
+ export declare enum ExternalRequestPromiseStatus {
728
+ PENDING = 0,
729
+ REJECTED = 1,
730
+ FAILED = 2,
731
+ COMPLETED = 3
732
+ }
733
+ export interface ExternalRequestPromise {
734
+ resolve?: (result: SignerResult | PromiseLike<SignerResult>) => void;
735
+ reject?: (error?: Error) => void;
736
+ status: ExternalRequestPromiseStatus;
737
+ message?: string;
738
+ createdAt: number;
739
+ }
740
+ export interface RequestAccountCreateExternalV2 {
741
+ address: string;
742
+ genesisHash?: string | null;
743
+ name: string;
744
+ isEthereum: boolean;
745
+ isAllowed: boolean;
746
+ }
747
+ export interface RequestAccountCreateHardwareV2 {
748
+ accountIndex: number;
749
+ address: string;
750
+ addressOffset: number;
751
+ genesisHash: string;
752
+ hardwareType: string;
753
+ name: string;
754
+ isAllowed?: boolean;
755
+ }
756
+ export declare enum AccountExternalErrorCode {
757
+ INVALID_ADDRESS = "invalidToAccount",
758
+ KEYRING_ERROR = "keyringError",
759
+ UNKNOWN_ERROR = "unknownError"
760
+ }
761
+ export interface AccountExternalError {
762
+ code: AccountExternalErrorCode;
763
+ message: string;
764
+ }
681
765
  export declare type RequestEvmEvents = null;
682
766
  export declare type EvmEventType = 'connect' | 'disconnect' | 'accountsChanged' | 'chainChanged' | 'message' | 'data' | 'reconnect' | 'error';
683
767
  export declare type EvmAccountsChangedPayload = string[];
@@ -702,11 +786,13 @@ export interface ResponseEvmProviderSend {
702
786
  error: (Error | null);
703
787
  result?: JsonRpcResponse;
704
788
  }
705
- export interface EvmProviderRpcErrorInterface extends Error {
706
- message: string;
707
- code: number;
789
+ export interface SubWalletProviderErrorInterface extends Error {
790
+ code?: number;
708
791
  data?: unknown;
709
792
  }
793
+ export interface EvmProviderRpcErrorInterface extends SubWalletProviderErrorInterface {
794
+ code: number;
795
+ }
710
796
  export declare type EvmRpcErrorHelperMap = Record<'USER_REJECTED_REQUEST' | 'UNAUTHORIZED' | 'UNSUPPORTED_METHOD' | 'DISCONNECTED' | 'CHAIN_DISCONNECTED' | 'INVALID_PARAMS' | 'INTERNAL_ERROR', [number, string]>;
711
797
  export interface EvmSendTransactionParams {
712
798
  from: string;
@@ -745,15 +831,51 @@ export interface ConfirmationResult<T> {
745
831
  payload?: T;
746
832
  password?: string;
747
833
  }
834
+ export interface ConfirmationResultQr<T> extends ConfirmationResult<T> {
835
+ signature: `0x${string}`;
836
+ }
748
837
  export interface EvmSendTransactionRequest extends TransactionConfig {
749
838
  estimateGas: string;
750
839
  }
840
+ export interface EvmRequestQr {
841
+ qrPayload: string;
842
+ canSign: boolean;
843
+ }
844
+ export interface EvmSendTransactionRequestQr extends TransactionConfig, EvmRequestQr {
845
+ estimateGas: string;
846
+ }
847
+ export interface EvmSignatureRequestQr extends EvmSignatureRequest, EvmRequestQr {
848
+ }
751
849
  export interface ConfirmationDefinitions {
752
850
  addNetworkRequest: [ConfirmationsQueueItem<NetworkJson>, ConfirmationResult<NetworkJson>];
753
851
  addTokenRequest: [ConfirmationsQueueItem<CustomEvmToken>, ConfirmationResult<boolean>];
754
852
  switchNetworkRequest: [ConfirmationsQueueItem<SwitchNetworkRequest>, ConfirmationResult<boolean>];
755
853
  evmSignatureRequest: [ConfirmationsQueueItem<EvmSignatureRequest>, ConfirmationResult<string>];
854
+ evmSignatureRequestQr: [ConfirmationsQueueItem<EvmSignatureRequestQr>, ConfirmationResultQr<string>];
756
855
  evmSendTransactionRequest: [ConfirmationsQueueItem<EvmSendTransactionRequest>, ConfirmationResult<boolean>];
856
+ evmSendTransactionRequestQr: [ConfirmationsQueueItem<EvmSendTransactionRequestQr>, ConfirmationResultQr<boolean>];
857
+ }
858
+ export interface RequestParseTransactionEVM {
859
+ data: string;
860
+ }
861
+ export interface ResponseParseTransactionEVM {
862
+ data: ParseEVMTransactionData | string;
863
+ input: string;
864
+ nonce: number;
865
+ to: string;
866
+ gas: number;
867
+ gasPrice: number;
868
+ value: number;
869
+ }
870
+ export interface RequestQrSignEVM {
871
+ address: string;
872
+ message: string;
873
+ type: 'message' | 'transaction';
874
+ chainId?: number;
875
+ password: string;
876
+ }
877
+ export interface ResponseQrSignEVM {
878
+ signature: string;
757
879
  }
758
880
  export declare type ConfirmationType = keyof ConfirmationDefinitions;
759
881
  export declare type ConfirmationsQueue = {
@@ -812,6 +934,9 @@ export interface BasicTxResponse {
812
934
  transactionHash?: string;
813
935
  txError?: boolean;
814
936
  }
937
+ export interface NftTransactionResponse extends BasicTxResponse {
938
+ isSendingSelf: boolean;
939
+ }
815
940
  export interface BondingOptionParams {
816
941
  networkKey: string;
817
942
  address: string;
@@ -860,6 +985,51 @@ export interface StakeClaimRewardParams {
860
985
  validatorAddress?: string;
861
986
  password?: string;
862
987
  }
988
+ export interface ResponseNftTransferExternal extends NftTransactionResponse {
989
+ externalState?: ExternalState;
990
+ }
991
+ export interface ResponseNftTransferQr extends ResponseNftTransferExternal {
992
+ qrState?: QrState;
993
+ isBusy?: boolean;
994
+ }
995
+ export interface ResponseNftTransferLedger extends ResponseNftTransferExternal {
996
+ ledgerState?: LedgerState;
997
+ }
998
+ export declare type RequestNftTransferExternalSubstrate = Omit<SubstrateNftSubmitTransaction, 'password'>;
999
+ export declare type RequestNftTransferExternalEVM = Omit<EvmNftSubmitTransaction, 'password'>;
1000
+ export declare type RequestStakeExternal = Omit<BondingSubmitParams, 'password'>;
1001
+ export interface ResponseStakeExternal extends BasicTxResponse {
1002
+ externalState?: ExternalState;
1003
+ }
1004
+ export interface ResponseStakeQr extends ResponseStakeExternal {
1005
+ qrState?: QrState;
1006
+ isBusy?: boolean;
1007
+ }
1008
+ export interface ResponseStakeLedger extends ResponseStakeExternal {
1009
+ ledgerState?: LedgerState;
1010
+ }
1011
+ export declare type RequestUnStakeExternal = Omit<UnbondingSubmitParams, 'password'>;
1012
+ export interface ResponseUnStakeExternal extends BasicTxResponse {
1013
+ externalState?: ExternalState;
1014
+ }
1015
+ export interface ResponseUnStakeQr extends ResponseUnStakeExternal {
1016
+ qrState?: QrState;
1017
+ isBusy?: boolean;
1018
+ }
1019
+ export interface ResponseUnStakeLedger extends ResponseUnStakeExternal {
1020
+ ledgerState?: LedgerState;
1021
+ }
1022
+ export declare type RequestWithdrawStakeExternal = Omit<StakeWithdrawalParams, 'password'>;
1023
+ export interface ResponseWithdrawStakeExternal extends BasicTxResponse {
1024
+ externalState?: ExternalState;
1025
+ }
1026
+ export interface ResponseWithdrawStakeQr extends ResponseWithdrawStakeExternal {
1027
+ qrState?: QrState;
1028
+ isBusy?: boolean;
1029
+ }
1030
+ export interface ResponseWithdrawStakeLedger extends ResponseWithdrawStakeExternal {
1031
+ ledgerState?: LedgerState;
1032
+ }
863
1033
  export interface StakeDelegationRequest {
864
1034
  address: string;
865
1035
  networkKey: string;
@@ -889,6 +1059,13 @@ export interface RequestParseEVMTransactionInput {
889
1059
  export interface ResponseParseEVMTransactionInput {
890
1060
  result: ParseEVMTransactionData | string;
891
1061
  }
1062
+ export interface LedgerNetwork {
1063
+ genesisHash: string;
1064
+ displayName: string;
1065
+ network: string;
1066
+ icon: 'substrate' | 'ethereum';
1067
+ isDevMode: boolean;
1068
+ }
892
1069
  export interface KoniRequestSignatures {
893
1070
  'pri(staking.delegationInfo)': [StakeDelegationRequest, DelegationItem[]];
894
1071
  'pri(staking.submitClaimReward)': [StakeClaimRewardParams, BasicTxResponse, BasicTxResponse];
@@ -957,6 +1134,8 @@ export interface KoniRequestSignatures {
957
1134
  'pri(seed.validateV2)': [RequestSeedValidateV2, ResponseSeedValidateV2];
958
1135
  'pri(privateKey.validateV2)': [RequestSeedValidateV2, ResponsePrivateKeyValidateV2];
959
1136
  'pri(accounts.create.suriV2)': [RequestAccountCreateSuriV2, ResponseAccountCreateSuriV2];
1137
+ 'pri(accounts.create.externalV2)': [RequestAccountCreateExternalV2, AccountExternalError[]];
1138
+ 'pri(accounts.create.hardwareV2)': [RequestAccountCreateHardwareV2, boolean];
960
1139
  'pri(accounts.checkTransfer)': [RequestCheckTransfer, ResponseCheckTransfer];
961
1140
  'pri(accounts.checkCrossChainTransfer)': [RequestCheckCrossChainTransfer, ResponseCheckCrossChainTransfer];
962
1141
  'pri(accounts.transfer)': [RequestTransfer, Array<TransferError>, ResponseTransfer];
@@ -969,6 +1148,7 @@ export interface KoniRequestSignatures {
969
1148
  'pri(accounts.subscribeAccountsInputAddress)': [RequestAccountSubscribe, string, OptionInputAddress];
970
1149
  'pri(accounts.saveRecent)': [RequestSaveRecentAccount, SingleAddress];
971
1150
  'pri(accounts.triggerSubscription)': [null, boolean];
1151
+ 'pri(accounts.get.meta)': [RequestAccountMeta, ResponseAccountMeta];
972
1152
  'pri(currentAccount.saveAddress)': [RequestCurrentAccountAddress, boolean, CurrentAccountInfo];
973
1153
  'pri(settings.changeBalancesVisibility)': [null, boolean, ResponseSettingsType];
974
1154
  'pri(settings.subscribe)': [null, ResponseSettingsType, ResponseSettingsType];
@@ -987,13 +1167,32 @@ export interface KoniRequestSignatures {
987
1167
  'pub(utils.getRandom)': [RandomTestRequest, number];
988
1168
  'pub(accounts.listV2)': [RequestAccountList, InjectedAccount[]];
989
1169
  'pub(accounts.subscribeV2)': [RequestAccountSubscribe, boolean, InjectedAccount[]];
1170
+ 'pri(qr.transaction.parse.substrate)': [RequestParseTransactionSubstrate, ResponseParseTransactionSubstrate];
1171
+ 'pri(qr.transaction.parse.evm)': [RequestParseTransactionEVM, ResponseParseTransactionEVM];
1172
+ 'pri(qr.isLocked)': [RequestQRIsLocked, ResponseQRIsLocked];
1173
+ 'pri(qr.sign.substrate)': [RequestQrSignSubstrate, ResponseQrSignSubstrate];
1174
+ 'pri(qr.sign.evm)': [RequestQrSignEVM, ResponseQrSignEVM];
1175
+ 'pri(account.external.reject)': [RequestRejectExternalRequest, ResponseRejectExternalRequest];
1176
+ 'pri(account.external.resolve)': [RequestResolveExternalRequest, ResponseResolveExternalRequest];
990
1177
  'evm(events.subscribe)': [RequestEvmEvents, boolean, EvmEvent];
991
1178
  'evm(request)': [RequestArguments, unknown];
992
1179
  'evm(provider.send)': [RequestEvmProviderSend, string | number, ResponseEvmProviderSend];
993
1180
  'pri(evm.transaction.parse.input)': [RequestParseEVMTransactionInput, ResponseParseEVMTransactionInput];
1181
+ 'pri(accounts.transfer.qr.create)': [RequestTransferExternal, Array<TransferError>, ResponseTransferQr];
1182
+ 'pri(accounts.cross.transfer.qr.create)': [RequestCrossChainTransferExternal, Array<TransferError>, ResponseTransferQr];
1183
+ 'pri(nft.transfer.qr.create.substrate)': [RequestNftTransferExternalSubstrate, Array<BaseTxError>, ResponseNftTransferQr];
1184
+ 'pri(nft.transfer.qr.create.evm)': [RequestNftTransferExternalEVM, Array<BaseTxError>, ResponseNftTransferQr];
1185
+ 'pri(stake.qr.create)': [RequestStakeExternal, Array<BaseTxError>, ResponseStakeQr];
1186
+ 'pri(unStake.qr.create)': [RequestUnStakeExternal, Array<BaseTxError>, ResponseUnStakeQr];
1187
+ 'pri(withdrawStake.qr.create)': [RequestWithdrawStakeExternal, Array<BaseTxError>, ResponseWithdrawStakeQr];
1188
+ 'pri(accounts.transfer.ledger.create)': [RequestTransferExternal, Array<TransferError>, ResponseTransferLedger];
1189
+ 'pri(accounts.cross.transfer.ledger.create)': [RequestCrossChainTransferExternal, Array<TransferError>, ResponseTransferLedger];
1190
+ 'pri(nft.transfer.ledger.create.substrate)': [RequestNftTransferExternalSubstrate, Array<BaseTxError>, ResponseNftTransferQr];
1191
+ 'pri(stake.ledger.create)': [RequestStakeExternal, Array<BaseTxError>, ResponseStakeLedger];
1192
+ 'pri(unStake.ledger.create)': [RequestUnStakeExternal, Array<BaseTxError>, ResponseUnStakeLedger];
1193
+ 'pri(withdrawStake.ledger.create)': [RequestWithdrawStakeExternal, Array<BaseTxError>, ResponseWithdrawStakeLedger];
994
1194
  'pri(authorize.subscribe)': [null, AuthUrls, AuthUrls];
995
1195
  }
996
1196
  export interface ApplicationMetadataType {
997
1197
  version: string;
998
1198
  }
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 {};