@subwallet/extension-base 0.4.5-0 → 0.4.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,7 +1,9 @@
1
1
  import { AuthUrls, Resolver } from '@subwallet/extension-base/background/handlers/State';
2
- import { AccountJson, AuthorizeRequest, RequestAccountList, RequestAccountSubscribe, RequestAuthorizeReject, RequestAuthorizeSubscribe, RequestAuthorizeTab, RequestCurrentAccountAddress, ResponseAuthorizeList, ResponseJsonGetAccountInfo, SeedLengths } from '@subwallet/extension-base/background/types';
2
+ import { AccountAuthType, AccountJson, AuthorizeRequest, RequestAccountList, RequestAccountSubscribe, RequestAuthorizeReject, RequestAuthorizeSubscribe, RequestAuthorizeTab, RequestCurrentAccountAddress, ResponseAuthorizeList, ResponseJsonGetAccountInfo, SeedLengths } from '@subwallet/extension-base/background/types';
3
3
  import { InjectedAccount, MetadataDefBase } from '@subwallet/extension-inject/types';
4
4
  import Web3 from 'web3';
5
+ import { RequestArguments, TransactionConfig } from 'web3-core';
6
+ import { JsonRpcPayload, JsonRpcResponse } from 'web3-core-helpers';
5
7
  import { ApiPromise } from '@polkadot/api';
6
8
  import { SubmittableExtrinsicFunction } from '@polkadot/api/promise/types';
7
9
  import { KeyringPair$Json } from '@polkadot/keyring/types';
@@ -30,6 +32,7 @@ export interface AuthRequestV2 extends Resolver<ResultResolver> {
30
32
  idStr: string;
31
33
  request: RequestAuthorizeTab;
32
34
  url: string;
35
+ accountAuthType: AccountAuthType;
33
36
  }
34
37
  export interface RequestAuthorizeApproveV2 {
35
38
  id: string;
@@ -244,6 +247,7 @@ export interface NetworkJson {
244
247
  dependencies?: string[];
245
248
  getStakingOnChain?: boolean;
246
249
  apiStatus?: NETWORK_STATUS;
250
+ requestId?: string;
247
251
  }
248
252
  export interface DonateInfo {
249
253
  key: string;
@@ -295,6 +299,7 @@ export declare type TokenInfo = {
295
299
  export interface AccountsWithCurrentAddress {
296
300
  accounts: AccountJson[];
297
301
  currentAddress?: string;
302
+ currentGenesisHash?: string | null;
298
303
  isShowBalance?: boolean;
299
304
  allAccountLogo?: string;
300
305
  }
@@ -303,6 +308,7 @@ export interface OptionInputAddress {
303
308
  }
304
309
  export interface CurrentAccountInfo {
305
310
  address: string;
311
+ currentGenesisHash: string | null;
306
312
  }
307
313
  export interface RequestSettingsType {
308
314
  isShowBalance: boolean;
@@ -641,6 +647,90 @@ export interface CrossChainRelation {
641
647
  type: ChainRelationType;
642
648
  relationMap: Record<string, ChainRelationInfo>;
643
649
  }
650
+ export declare type RequestEvmEvents = null;
651
+ export declare type EvmEventType = 'connect' | 'disconnect' | 'accountsChanged' | 'chainChanged' | 'message' | 'data' | 'reconnect' | 'error';
652
+ export declare type EvmAccountsChangedPayload = string[];
653
+ export declare type EvmChainChangedPayload = string;
654
+ export declare type EvmConnectPayload = {
655
+ chainId: EvmChainChangedPayload;
656
+ };
657
+ export declare type EvmDisconnectPayload = unknown;
658
+ export interface EvmEvent {
659
+ type: EvmEventType;
660
+ payload: EvmAccountsChangedPayload | EvmChainChangedPayload | EvmConnectPayload | EvmDisconnectPayload;
661
+ }
662
+ export interface EvmAppState {
663
+ networkKey?: string;
664
+ chainId?: string;
665
+ isConnected?: boolean;
666
+ web3?: Web3;
667
+ listenEvents?: string[];
668
+ }
669
+ export declare type RequestEvmProviderSend = JsonRpcPayload;
670
+ export interface ResponseEvmProviderSend {
671
+ error: (Error | null);
672
+ result?: JsonRpcResponse;
673
+ }
674
+ export interface EvmProviderRpcErrorInterface extends Error {
675
+ message: string;
676
+ code: number;
677
+ data?: unknown;
678
+ }
679
+ export declare type EvmRpcErrorHelperMap = Record<'USER_REJECTED_REQUEST' | 'UNAUTHORIZED' | 'UNSUPPORTED_METHOD' | 'DISCONNECTED' | 'CHAIN_DISCONNECTED' | 'INVALID_PARAMS' | 'INTERNAL_ERROR', [number, string]>;
680
+ export interface EvmSendTransactionParams {
681
+ from: string;
682
+ to?: string;
683
+ value?: string | number;
684
+ gasLimit?: string | number;
685
+ maxPriorityFeePerGas?: string | number;
686
+ maxFeePerGas?: string | number;
687
+ gasPrice?: string | number;
688
+ data?: string;
689
+ }
690
+ export interface SwitchNetworkRequest {
691
+ networkKey: string;
692
+ address?: string;
693
+ }
694
+ export interface EvmSignatureRequest {
695
+ address: string;
696
+ type: string;
697
+ payload: unknown;
698
+ }
699
+ export interface ConfirmationsQueueItemOptions {
700
+ requiredPassword?: boolean;
701
+ address?: string;
702
+ networkKey?: string;
703
+ }
704
+ export interface ConfirmationsQueueItem<T> extends ConfirmationsQueueItemOptions {
705
+ id: string;
706
+ url: string;
707
+ payload: T;
708
+ payloadJson: string;
709
+ }
710
+ export interface ConfirmationResult<T> {
711
+ id: string;
712
+ isApproved: boolean;
713
+ url?: string;
714
+ payload?: T;
715
+ password?: string;
716
+ }
717
+ export interface EvmSendTransactionRequest extends TransactionConfig {
718
+ estimateGas: string;
719
+ }
720
+ export interface ConfirmationDefinitions {
721
+ addNetworkRequest: [ConfirmationsQueueItem<NetworkJson>, ConfirmationResult<NetworkJson>];
722
+ switchNetworkRequest: [ConfirmationsQueueItem<SwitchNetworkRequest>, ConfirmationResult<boolean>];
723
+ evmSignatureRequest: [ConfirmationsQueueItem<EvmSignatureRequest>, ConfirmationResult<string>];
724
+ evmSendTransactionRequest: [ConfirmationsQueueItem<EvmSendTransactionRequest>, ConfirmationResult<boolean>];
725
+ }
726
+ export declare type ConfirmationType = keyof ConfirmationDefinitions;
727
+ export declare type ConfirmationsQueue = {
728
+ [ConfirmationType in keyof ConfirmationDefinitions]: Record<string, ConfirmationDefinitions[ConfirmationType][0]>;
729
+ };
730
+ export declare type RequestConfirmationsSubscribe = null;
731
+ export declare type RequestConfirmationComplete = {
732
+ [ConfirmationType in keyof ConfirmationDefinitions]?: ConfirmationDefinitions[ConfirmationType][1];
733
+ };
644
734
  export interface KoniRequestSignatures {
645
735
  'pri(networkMap.recoverDotSama)': [string, boolean];
646
736
  'pri(substrateNft.submitTransaction)': [SubstrateNftSubmitTransaction, NftTransactionResponse, NftTransactionResponse];
@@ -707,10 +797,10 @@ export interface KoniRequestSignatures {
707
797
  'pri(accounts.saveRecent)': [RequestSaveRecentAccount, SingleAddress];
708
798
  'pri(accounts.triggerSubscription)': [null, boolean];
709
799
  'pri(currentAccount.saveAddress)': [RequestCurrentAccountAddress, boolean, CurrentAccountInfo];
710
- 'pri(currentAccount.changeBalancesVisibility)': [null, boolean, ResponseSettingsType];
711
- 'pri(currentAccount.subscribeSettings)': [null, ResponseSettingsType, ResponseSettingsType];
712
- 'pri(currentAccount.saveAccountAllLogo)': [string, boolean, ResponseSettingsType];
713
- 'pri(currentAccount.saveTheme)': [ThemeTypes, boolean, ResponseSettingsType];
800
+ 'pri(settings.changeBalancesVisibility)': [null, boolean, ResponseSettingsType];
801
+ 'pri(settings.subscribe)': [null, ResponseSettingsType, ResponseSettingsType];
802
+ 'pri(settings.saveAccountAllLogo)': [string, boolean, ResponseSettingsType];
803
+ 'pri(settings.saveTheme)': [ThemeTypes, boolean, ResponseSettingsType];
714
804
  'pri(chainRegistry.getSubscription)': [null, Record<string, ChainRegistry>, Record<string, ChainRegistry>];
715
805
  'pri(transaction.history.getSubscription)': [null, Record<string, TransactionHistoryItemType[]>, Record<string, TransactionHistoryItemType[]>];
716
806
  'pri(transaction.history.add)': [RequestTransactionHistoryAdd, boolean, TransactionHistoryItemType[]];
@@ -719,8 +809,13 @@ export interface KoniRequestSignatures {
719
809
  'pri(transfer.getExistentialDeposit)': [RequestTransferExistentialDeposit, string];
720
810
  'pri(subscription.cancel)': [string, boolean];
721
811
  'pri(freeBalance.subscribe)': [RequestFreeBalance, string, string];
812
+ 'pri(confirmations.subscribe)': [RequestConfirmationsSubscribe, ConfirmationsQueue, ConfirmationsQueue];
813
+ 'pri(confirmations.complete)': [RequestConfirmationComplete, boolean];
722
814
  'pub(utils.getRandom)': [RandomTestRequest, number];
723
815
  'pub(accounts.listV2)': [RequestAccountList, InjectedAccount[]];
724
816
  'pub(accounts.subscribeV2)': [RequestAccountSubscribe, boolean, InjectedAccount[]];
817
+ 'evm(events.subscribe)': [RequestEvmEvents, boolean, EvmEvent];
818
+ 'evm(request)': [RequestArguments, unknown];
819
+ 'evm(provider.send)': [RequestEvmProviderSend, string | number, ResponseEvmProviderSend];
725
820
  }
726
821
  export {};
@@ -1,7 +1,7 @@
1
1
  /// <reference types="chrome" />
2
2
  import type { MetadataDef, ProviderMeta } from '@subwallet/extension-inject/types';
3
3
  import type { JsonRpcResponse, ProviderInterface, ProviderInterfaceCallback } from '@polkadot/rpc-provider/types';
4
- import type { AccountJson, AuthorizeRequest, MetadataRequest, RequestAuthorizeTab, RequestRpcSend, RequestRpcSubscribe, RequestRpcUnsubscribe, RequestSign, ResponseRpcListProviders, ResponseSigning, SigningRequest } from '../types';
4
+ import type { AccountAuthType, AccountJson, AuthorizeRequest, MetadataRequest, RequestAuthorizeTab, RequestRpcSend, RequestRpcSubscribe, RequestRpcUnsubscribe, RequestSign, ResponseRpcListProviders, ResponseSigning, SigningRequest } from '../types';
5
5
  import { BehaviorSubject } from 'rxjs';
6
6
  export interface Resolver<T> {
7
7
  reject: (error: Error) => void;
@@ -20,6 +20,7 @@ export interface AuthUrlInfo {
20
20
  isAllowed: boolean;
21
21
  origin: string;
22
22
  url: string;
23
+ accountAuthType?: AccountAuthType;
23
24
  isAllowedMap: Record<string, boolean>;
24
25
  }
25
26
  interface MetaRequest extends Resolver<boolean> {
@@ -56,6 +57,7 @@ export default class State {
56
57
  get allMetaRequests(): MetadataRequest[];
57
58
  get allSignRequests(): SigningRequest[];
58
59
  get authUrls(): AuthUrls;
60
+ protected getPopup(): number[];
59
61
  protected popupClose(): void;
60
62
  protected popupOpen(): void;
61
63
  private authComplete;
@@ -12,8 +12,6 @@ const NOTIFICATION_URL = chrome.extension.getURL('notification.html');
12
12
  const POPUP_WINDOW_OPTS = {
13
13
  focused: true,
14
14
  height: 621,
15
- left: 150,
16
- top: 150,
17
15
  type: 'popup',
18
16
  url: NOTIFICATION_URL,
19
17
  width: 460
@@ -157,6 +155,10 @@ export default class State {
157
155
  return this.#authUrls;
158
156
  }
159
157
 
158
+ getPopup() {
159
+ return this.#windows;
160
+ }
161
+
160
162
  popupClose() {
161
163
  this.#windows.forEach(id => withErrorLog(() => chrome.windows.remove(id)));
162
164
  this.#windows = [];
@@ -38,9 +38,6 @@ export interface AccountsWithCurrentAddress {
38
38
  accounts: AccountJson[];
39
39
  currentAddress?: string;
40
40
  }
41
- export interface CurrentAccountInfo {
42
- address: string;
43
- }
44
41
  export declare type AccountWithChildren = AccountJson & {
45
42
  children?: AccountWithChildren[];
46
43
  };
@@ -138,8 +135,12 @@ export interface TransportRequestMessage<TMessageType extends MessageTypes> {
138
135
  origin: 'page' | 'extension' | string;
139
136
  request: RequestTypes[TMessageType];
140
137
  }
138
+ export declare type AccountAuthType = 'substrate' | 'evm' | 'both';
141
139
  export interface RequestAuthorizeTab {
142
140
  origin: string;
141
+ accountAuthType?: AccountAuthType;
142
+ allowedAccounts?: string[];
143
+ reConfirm?: boolean;
143
144
  }
144
145
  export interface RequestAuthorizeApprove {
145
146
  id: string;
@@ -226,8 +227,11 @@ export interface RequestAccountBatchExport {
226
227
  }
227
228
  export interface RequestAccountList {
228
229
  anyType?: boolean;
230
+ accountAuthType?: AccountAuthType;
231
+ }
232
+ export interface RequestAccountSubscribe {
233
+ accountAuthType?: AccountAuthType;
229
234
  }
230
- export declare type RequestAccountSubscribe = null;
231
235
  export interface RequestRpcSend {
232
236
  method: string;
233
237
  params: unknown[];
@@ -29,8 +29,6 @@ const NOTIFICATION_URL = chrome.extension.getURL('notification.html');
29
29
  const POPUP_WINDOW_OPTS = {
30
30
  focused: true,
31
31
  height: 621,
32
- left: 150,
33
- top: 150,
34
32
  type: 'popup',
35
33
  url: NOTIFICATION_URL,
36
34
  width: 460
@@ -192,6 +190,10 @@ class State {
192
190
  return this.#authUrls;
193
191
  }
194
192
 
193
+ getPopup() {
194
+ return this.#windows;
195
+ }
196
+
195
197
  popupClose() {
196
198
  this.#windows.forEach(id => (0, _helpers.withErrorLog)(() => chrome.windows.remove(id)));
197
199
  this.#windows = [];
@@ -11,6 +11,6 @@ const packageInfo = {
11
11
  name: '@subwallet/extension-base',
12
12
  path: typeof __dirname === 'string' ? __dirname : 'auto',
13
13
  type: 'cjs',
14
- version: '0.4.5-0'
14
+ version: '0.4.6-0'
15
15
  };
16
16
  exports.packageInfo = packageInfo;
@@ -16,12 +16,15 @@ class Accounts {
16
16
 
17
17
  get(anyType) {
18
18
  return sendRequest('pub(accounts.listV2)', {
19
- anyType
19
+ anyType,
20
+ accountAuthType: 'substrate'
20
21
  });
21
22
  }
22
23
 
23
24
  subscribe(cb) {
24
- sendRequest('pub(accounts.subscribeV2)', null, cb).catch(error => console.error(error));
25
+ sendRequest('pub(accounts.subscribeV2)', {
26
+ accountAuthType: 'substrate'
27
+ }, cb).catch(error => console.error(error));
25
28
  return () => {// FIXME we need the ability to unsubscribe
26
29
  };
27
30
  }
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "./cjs/detectPackage.js"
18
18
  ],
19
19
  "type": "module",
20
- "version": "0.4.5-0",
20
+ "version": "0.4.6-0",
21
21
  "main": "./cjs/index.js",
22
22
  "module": "./index.js",
23
23
  "types": "./index.d.ts",
@@ -199,12 +199,14 @@
199
199
  "@polkadot/ui-settings": "^0.89.1",
200
200
  "@polkadot/util": "^8.3.1",
201
201
  "@polkadot/util-crypto": "^8.3.1",
202
- "@subwallet/extension-chains": "^0.4.5-0",
203
- "@subwallet/extension-dapp": "^0.4.5-0",
204
- "@subwallet/extension-inject": "^0.4.5-0",
202
+ "@subwallet/extension-chains": "^0.4.6-0",
203
+ "@subwallet/extension-dapp": "^0.4.6-0",
204
+ "@subwallet/extension-inject": "^0.4.6-0",
205
205
  "ethereumjs-tx": "^2.1.2",
206
206
  "eventemitter3": "^4.0.7",
207
207
  "rxjs": "^7.5.1",
208
- "web3": "^1.7.1"
208
+ "web3": "^1.7.3",
209
+ "web3-core": "^1.7.3",
210
+ "web3-core-helpers": "^1.7.3"
209
211
  }
210
212
  }
package/packageInfo.js CHANGED
@@ -5,5 +5,5 @@ export const packageInfo = {
5
5
  name: '@subwallet/extension-base',
6
6
  path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
7
7
  type: 'esm',
8
- version: '0.4.5-0'
8
+ version: '0.4.6-0'
9
9
  };
package/page/Accounts.js CHANGED
@@ -9,12 +9,15 @@ export default class Accounts {
9
9
 
10
10
  get(anyType) {
11
11
  return sendRequest('pub(accounts.listV2)', {
12
- anyType
12
+ anyType,
13
+ accountAuthType: 'substrate'
13
14
  });
14
15
  }
15
16
 
16
17
  subscribe(cb) {
17
- sendRequest('pub(accounts.subscribeV2)', null, cb).catch(error => console.error(error));
18
+ sendRequest('pub(accounts.subscribeV2)', {
19
+ accountAuthType: 'substrate'
20
+ }, cb).catch(error => console.error(error));
18
21
  return () => {// FIXME we need the ability to unsubscribe
19
22
  };
20
23
  }