@subwallet/extension-base 0.7.1 → 0.7.2-1

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.
@@ -2,12 +2,16 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  export let ApiInitStatus;
5
+
6
+ /// Request Auth
5
7
  (function (ApiInitStatus) {
6
8
  ApiInitStatus[ApiInitStatus["SUCCESS"] = 0] = "SUCCESS";
7
9
  ApiInitStatus[ApiInitStatus["ALREADY_EXIST"] = 1] = "ALREADY_EXIST";
8
10
  ApiInitStatus[ApiInitStatus["NOT_SUPPORT"] = 2] = "NOT_SUPPORT";
9
11
  ApiInitStatus[ApiInitStatus["NOT_EXIST"] = 3] = "NOT_EXIST";
10
12
  })(ApiInitStatus || (ApiInitStatus = {}));
13
+ /// Staking subscribe
14
+
11
15
  export let StakingType;
12
16
  (function (StakingType) {
13
17
  StakingType["NOMINATED"] = "nominated";
@@ -37,6 +41,27 @@ export let ContractType;
37
41
  ContractType["wasm"] = "wasm";
38
42
  ContractType["evm"] = "evm";
39
43
  })(ContractType || (ContractType = {}));
44
+ // External account
45
+
46
+ export let AccountExternalErrorCode;
47
+ (function (AccountExternalErrorCode) {
48
+ AccountExternalErrorCode["INVALID_ADDRESS"] = "invalidToAccount";
49
+ AccountExternalErrorCode["KEYRING_ERROR"] = "keyringError";
50
+ AccountExternalErrorCode["UNKNOWN_ERROR"] = "unknownError";
51
+ })(AccountExternalErrorCode || (AccountExternalErrorCode = {}));
52
+ /// Sign External Request
53
+
54
+ // Status
55
+
56
+ export let ExternalRequestPromiseStatus;
57
+
58
+ // Structure
59
+ (function (ExternalRequestPromiseStatus) {
60
+ ExternalRequestPromiseStatus[ExternalRequestPromiseStatus["PENDING"] = 0] = "PENDING";
61
+ ExternalRequestPromiseStatus[ExternalRequestPromiseStatus["REJECTED"] = 1] = "REJECTED";
62
+ ExternalRequestPromiseStatus[ExternalRequestPromiseStatus["FAILED"] = 2] = "FAILED";
63
+ ExternalRequestPromiseStatus[ExternalRequestPromiseStatus["COMPLETED"] = 3] = "COMPLETED";
64
+ })(ExternalRequestPromiseStatus || (ExternalRequestPromiseStatus = {}));
40
65
  export let NETWORK_ERROR;
41
66
  (function (NETWORK_ERROR) {
42
67
  NETWORK_ERROR["INVALID_INFO_TYPE"] = "invalidInfoType";
@@ -57,32 +82,25 @@ export let NETWORK_STATUS;
57
82
  })(NETWORK_STATUS || (NETWORK_STATUS = {}));
58
83
  export let TransferErrorCode;
59
84
  (function (TransferErrorCode) {
60
- TransferErrorCode["INVALID_FROM_ADDRESS"] = "invalidFromAccount";
61
- TransferErrorCode["INVALID_TO_ADDRESS"] = "invalidToAccount";
62
85
  TransferErrorCode["NOT_ENOUGH_VALUE"] = "notEnoughValue";
63
86
  TransferErrorCode["INVALID_VALUE"] = "invalidValue";
64
87
  TransferErrorCode["INVALID_TOKEN"] = "invalidToken";
65
- TransferErrorCode["INVALID_PARAM"] = "invalidParam";
66
- TransferErrorCode["KEYRING_ERROR"] = "keyringError";
67
88
  TransferErrorCode["TRANSFER_ERROR"] = "transferError";
68
- TransferErrorCode["TIMEOUT"] = "timeout";
69
89
  TransferErrorCode["UNSUPPORTED"] = "unsupported";
70
90
  })(TransferErrorCode || (TransferErrorCode = {}));
71
91
  export let BasicTxErrorCode;
72
92
  (function (BasicTxErrorCode) {
73
- BasicTxErrorCode["INVALID_FROM_ADDRESS"] = "invalidFromAccount";
74
- BasicTxErrorCode["INVALID_TO_ADDRESS"] = "invalidToAccount";
75
- BasicTxErrorCode["NOT_ENOUGH_VALUE"] = "notEnoughValue";
76
- BasicTxErrorCode["INVALID_VALUE"] = "invalidValue";
77
- BasicTxErrorCode["INVALID_TOKEN"] = "invalidToken";
78
93
  BasicTxErrorCode["INVALID_PARAM"] = "invalidParam";
79
94
  BasicTxErrorCode["KEYRING_ERROR"] = "keyringError";
80
- BasicTxErrorCode["TRANSFER_ERROR"] = "transferError";
81
95
  BasicTxErrorCode["STAKING_ERROR"] = "stakingError";
82
96
  BasicTxErrorCode["UN_STAKING_ERROR"] = "unStakingError";
83
97
  BasicTxErrorCode["WITHDRAW_STAKING_ERROR"] = "withdrawStakingError";
98
+ BasicTxErrorCode["CLAIM_REWARD_ERROR"] = "claimRewardError";
99
+ BasicTxErrorCode["CREATE_COMPOUND_ERROR"] = "createCompoundError";
100
+ BasicTxErrorCode["CANCEL_COMPOUND_ERROR"] = "cancelCompoundError";
84
101
  BasicTxErrorCode["TIMEOUT"] = "timeout";
85
- BasicTxErrorCode["UNSUPPORTED"] = "unsupported";
102
+ BasicTxErrorCode["BALANCE_TO_LOW"] = "balanceTooLow1";
103
+ BasicTxErrorCode["UNKNOWN_ERROR"] = "unknownError";
86
104
  })(BasicTxErrorCode || (BasicTxErrorCode = {}));
87
105
  export let TransferStep;
88
106
  (function (TransferStep) {
@@ -99,21 +117,4 @@ export let CustomTokenType;
99
117
  CustomTokenType["erc721"] = "erc721";
100
118
  CustomTokenType["psp22"] = "psp22";
101
119
  CustomTokenType["psp34"] = "psp34";
102
- })(CustomTokenType || (CustomTokenType = {}));
103
- export let ExternalRequestPromiseStatus;
104
- (function (ExternalRequestPromiseStatus) {
105
- ExternalRequestPromiseStatus[ExternalRequestPromiseStatus["PENDING"] = 0] = "PENDING";
106
- ExternalRequestPromiseStatus[ExternalRequestPromiseStatus["REJECTED"] = 1] = "REJECTED";
107
- ExternalRequestPromiseStatus[ExternalRequestPromiseStatus["FAILED"] = 2] = "FAILED";
108
- ExternalRequestPromiseStatus[ExternalRequestPromiseStatus["COMPLETED"] = 3] = "COMPLETED";
109
- })(ExternalRequestPromiseStatus || (ExternalRequestPromiseStatus = {}));
110
- export let AccountExternalErrorCode;
111
- (function (AccountExternalErrorCode) {
112
- AccountExternalErrorCode["INVALID_ADDRESS"] = "invalidToAccount";
113
- AccountExternalErrorCode["KEYRING_ERROR"] = "keyringError";
114
- AccountExternalErrorCode["UNKNOWN_ERROR"] = "unknownError";
115
- })(AccountExternalErrorCode || (AccountExternalErrorCode = {}));
116
- export let BasicTxError;
117
- (function (BasicTxError) {
118
- BasicTxError["BalanceTooLow"] = "BalanceTooLow";
119
- })(BasicTxError || (BasicTxError = {}));
120
+ })(CustomTokenType || (CustomTokenType = {}));
@@ -1,13 +1,16 @@
1
1
  /// <reference types="chrome" />
2
+ import type { KeyringPair } from '@polkadot/keyring/types';
2
3
  import type { KeypairType } from '@polkadot/util-crypto/types';
3
4
  import type { MessageTypes, RequestTypes, ResponseType } from '../types';
4
5
  import State from './State';
6
+ declare type CachedUnlocks = Record<string, number>;
5
7
  export declare const SEED_DEFAULT_LENGTH = 12;
6
8
  export declare const SEED_LENGTHS: number[];
7
9
  export declare const ETH_DERIVE_DEFAULT = "/m/44'/60'/0'/0/0";
8
10
  export declare function getSuri(seed: string, type?: KeypairType): string;
9
11
  export default class Extension {
10
12
  #private;
13
+ protected readonly cachedUnlocks: CachedUnlocks;
11
14
  constructor(state: State);
12
15
  private accountsCreateExternal;
13
16
  private accountsCreateHardware;
@@ -16,7 +19,7 @@ export default class Extension {
16
19
  private accountsEdit;
17
20
  private accountsExport;
18
21
  private accountsForget;
19
- private refreshAccountPasswordCache;
22
+ protected refreshAccountPasswordCache(pair: KeyringPair): number;
20
23
  private accountsShow;
21
24
  private accountsTie;
22
25
  private accountsValidate;
@@ -39,8 +42,6 @@ export default class Extension {
39
42
  private signingApproveSignature;
40
43
  private signingCancel;
41
44
  private signingIsLocked;
42
- private qrIsLocked;
43
- private qrSignSubstrate;
44
45
  private signingSubscribe;
45
46
  private windowOpen;
46
47
  private derive;
@@ -49,3 +50,4 @@ export default class Extension {
49
50
  private toggleAuthorization;
50
51
  handle<TMessageType extends MessageTypes>(id: string, type: TMessageType, request: RequestTypes[TMessageType], port: chrome.runtime.Port): Promise<ResponseType<TMessageType>>;
51
52
  }
53
+ export {};
@@ -5,7 +5,7 @@ import { ALLOWED_PATH, PASSWORD_EXPIRY_MS } from '@subwallet/extension-base/defa
5
5
  import { TypeRegistry } from '@polkadot/types';
6
6
  import keyring from '@polkadot/ui-keyring';
7
7
  import { accounts as accountsObservable } from '@polkadot/ui-keyring/observable/accounts';
8
- import { assert, isHex, u8aToHex } from '@polkadot/util';
8
+ import { assert, isHex } from '@polkadot/util';
9
9
  import { keyExtractSuri, mnemonicGenerate, mnemonicValidate } from '@polkadot/util-crypto';
10
10
  import { withErrorLog } from "./helpers.js";
11
11
  import { createSubscription, unsubscribe } from "./subscriptions.js";
@@ -35,10 +35,9 @@ function isJsonPayload(value) {
35
35
  return value.genesisHash !== undefined;
36
36
  }
37
37
  export default class Extension {
38
- #cachedUnlocks;
39
38
  #state;
40
39
  constructor(state) {
41
- this.#cachedUnlocks = {};
40
+ this.cachedUnlocks = {};
42
41
  this.#state = state;
43
42
  }
44
43
  accountsCreateExternal({
@@ -136,10 +135,10 @@ export default class Extension {
136
135
  const {
137
136
  address
138
137
  } = pair;
139
- const savedExpiry = this.#cachedUnlocks[address] || 0;
138
+ const savedExpiry = this.cachedUnlocks[address] || 0;
140
139
  const remainingTime = savedExpiry - Date.now();
141
140
  if (remainingTime < 0) {
142
- this.#cachedUnlocks[address] = 0;
141
+ this.cachedUnlocks[address] = 0;
143
142
  pair.lock();
144
143
  return 0;
145
144
  }
@@ -387,7 +386,7 @@ export default class Extension {
387
386
  }
388
387
  const result = request.sign(registry, pair);
389
388
  if (savePass) {
390
- this.#cachedUnlocks[address] = Date.now() + PASSWORD_EXPIRY_MS;
389
+ this.cachedUnlocks[address] = Date.now() + PASSWORD_EXPIRY_MS;
391
390
  } else {
392
391
  pair.lock();
393
392
  }
@@ -437,46 +436,6 @@ export default class Extension {
437
436
  remainingTime
438
437
  };
439
438
  }
440
- qrIsLocked({
441
- address
442
- }) {
443
- const pair = keyring.getPair(address);
444
- assert(pair, 'Unable to find pair');
445
- const remainingTime = this.refreshAccountPasswordCache(pair);
446
- return {
447
- isLocked: pair.isLocked,
448
- remainingTime
449
- };
450
- }
451
- qrSignSubstrate({
452
- address,
453
- message,
454
- password,
455
- savePass
456
- }) {
457
- const pair = keyring.getPair(address);
458
- assert(pair, 'Unable to find pair');
459
- if (pair.isLocked && !password) {
460
- throw new Error('Password needed to unlock the account');
461
- }
462
- if (pair.isLocked) {
463
- try {
464
- pair.decodePkcs8(password);
465
- } catch (e) {
466
- throw new Error('invalid password');
467
- }
468
- }
469
- const signed = u8aToHex(pair.sign(message));
470
- const _address = pair.address;
471
- if (savePass) {
472
- this.#cachedUnlocks[_address] = Date.now() + PASSWORD_EXPIRY_MS;
473
- } else {
474
- pair.lock();
475
- }
476
- return {
477
- signature: signed
478
- };
479
- }
480
439
 
481
440
  // FIXME This looks very much like what we have in authorization
482
441
  signingSubscribe(id, port) {
@@ -620,10 +579,6 @@ export default class Extension {
620
579
  return this.signingCancel(request);
621
580
  case 'pri(signing.isLocked)':
622
581
  return this.signingIsLocked(request);
623
- case 'pri(qr.isLocked)':
624
- return this.qrIsLocked(request);
625
- case 'pri(qr.sign.substrate)':
626
- return this.qrSignSubstrate(request);
627
582
  case 'pri(signing.requests)':
628
583
  return this.signingSubscribe(id, port);
629
584
  case 'pri(window.open)':
@@ -34,6 +34,7 @@ export interface AccountJson extends KeyringPair$Meta {
34
34
  suri?: string;
35
35
  type?: KeypairType;
36
36
  whenCreated?: number;
37
+ isReadOnly?: boolean;
37
38
  }
38
39
  export interface AccountsWithCurrentAddress {
39
40
  accounts: AccountJson[];
@@ -52,7 +53,6 @@ export declare type AccountsContext = {
52
53
  accounts: AccountJson[];
53
54
  hierarchy: AccountWithChildren[];
54
55
  master?: AccountJson;
55
- getAccountByAddress: FindAccountFunction;
56
56
  };
57
57
  export declare type CurrentAccContext = {
58
58
  currentAccount: AccountJson | null;
@@ -284,20 +284,6 @@ export interface RequestSeedValidate {
284
284
  suri: string;
285
285
  type?: KeypairType;
286
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
- }
301
287
  export declare type ResponseTypes = {
302
288
  [MessageType in keyof RequestSignatures]: RequestSignatures[MessageType][1];
303
289
  };
@@ -375,30 +361,4 @@ export interface ResponseJsonGetAccountInfo {
375
361
  export interface ResponseAuthorizeList {
376
362
  list: AuthUrls;
377
363
  }
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
- }
404
364
  export {};
@@ -3,10 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.TransferStep = exports.TransferErrorCode = exports.StakingType = exports.RMRK_VER = exports.NETWORK_STATUS = exports.NETWORK_ERROR = exports.ExternalRequestPromiseStatus = exports.CustomTokenType = exports.CrowdloanParaState = exports.ContractType = exports.BasicTxErrorCode = exports.BasicTxError = exports.ApiInitStatus = exports.AccountExternalErrorCode = exports.APIItemState = void 0;
6
+ exports.TransferStep = exports.TransferErrorCode = exports.StakingType = exports.RMRK_VER = exports.NETWORK_STATUS = exports.NETWORK_ERROR = exports.ExternalRequestPromiseStatus = exports.CustomTokenType = exports.CrowdloanParaState = exports.ContractType = exports.BasicTxErrorCode = exports.ApiInitStatus = exports.AccountExternalErrorCode = exports.APIItemState = void 0;
7
7
  // Copyright 2019-2022 @polkadot/extension-koni authors & contributors
8
8
  // SPDX-License-Identifier: Apache-2.0
9
- let ApiInitStatus;
9
+ let ApiInitStatus; /// Request Auth
10
10
  exports.ApiInitStatus = ApiInitStatus;
11
11
  (function (ApiInitStatus) {
12
12
  ApiInitStatus[ApiInitStatus["SUCCESS"] = 0] = "SUCCESS";
@@ -14,6 +14,7 @@ exports.ApiInitStatus = ApiInitStatus;
14
14
  ApiInitStatus[ApiInitStatus["NOT_SUPPORT"] = 2] = "NOT_SUPPORT";
15
15
  ApiInitStatus[ApiInitStatus["NOT_EXIST"] = 3] = "NOT_EXIST";
16
16
  })(ApiInitStatus || (exports.ApiInitStatus = ApiInitStatus = {}));
17
+ /// Staking subscribe
17
18
  let StakingType;
18
19
  exports.StakingType = StakingType;
19
20
  (function (StakingType) {
@@ -48,6 +49,24 @@ exports.ContractType = ContractType;
48
49
  ContractType["wasm"] = "wasm";
49
50
  ContractType["evm"] = "evm";
50
51
  })(ContractType || (exports.ContractType = ContractType = {}));
52
+ // External account
53
+ let AccountExternalErrorCode;
54
+ exports.AccountExternalErrorCode = AccountExternalErrorCode;
55
+ (function (AccountExternalErrorCode) {
56
+ AccountExternalErrorCode["INVALID_ADDRESS"] = "invalidToAccount";
57
+ AccountExternalErrorCode["KEYRING_ERROR"] = "keyringError";
58
+ AccountExternalErrorCode["UNKNOWN_ERROR"] = "unknownError";
59
+ })(AccountExternalErrorCode || (exports.AccountExternalErrorCode = AccountExternalErrorCode = {}));
60
+ /// Sign External Request
61
+ // Status
62
+ let ExternalRequestPromiseStatus; // Structure
63
+ exports.ExternalRequestPromiseStatus = ExternalRequestPromiseStatus;
64
+ (function (ExternalRequestPromiseStatus) {
65
+ ExternalRequestPromiseStatus[ExternalRequestPromiseStatus["PENDING"] = 0] = "PENDING";
66
+ ExternalRequestPromiseStatus[ExternalRequestPromiseStatus["REJECTED"] = 1] = "REJECTED";
67
+ ExternalRequestPromiseStatus[ExternalRequestPromiseStatus["FAILED"] = 2] = "FAILED";
68
+ ExternalRequestPromiseStatus[ExternalRequestPromiseStatus["COMPLETED"] = 3] = "COMPLETED";
69
+ })(ExternalRequestPromiseStatus || (exports.ExternalRequestPromiseStatus = ExternalRequestPromiseStatus = {}));
51
70
  let NETWORK_ERROR;
52
71
  exports.NETWORK_ERROR = NETWORK_ERROR;
53
72
  (function (NETWORK_ERROR) {
@@ -71,33 +90,26 @@ exports.NETWORK_STATUS = NETWORK_STATUS;
71
90
  let TransferErrorCode;
72
91
  exports.TransferErrorCode = TransferErrorCode;
73
92
  (function (TransferErrorCode) {
74
- TransferErrorCode["INVALID_FROM_ADDRESS"] = "invalidFromAccount";
75
- TransferErrorCode["INVALID_TO_ADDRESS"] = "invalidToAccount";
76
93
  TransferErrorCode["NOT_ENOUGH_VALUE"] = "notEnoughValue";
77
94
  TransferErrorCode["INVALID_VALUE"] = "invalidValue";
78
95
  TransferErrorCode["INVALID_TOKEN"] = "invalidToken";
79
- TransferErrorCode["INVALID_PARAM"] = "invalidParam";
80
- TransferErrorCode["KEYRING_ERROR"] = "keyringError";
81
96
  TransferErrorCode["TRANSFER_ERROR"] = "transferError";
82
- TransferErrorCode["TIMEOUT"] = "timeout";
83
97
  TransferErrorCode["UNSUPPORTED"] = "unsupported";
84
98
  })(TransferErrorCode || (exports.TransferErrorCode = TransferErrorCode = {}));
85
99
  let BasicTxErrorCode;
86
100
  exports.BasicTxErrorCode = BasicTxErrorCode;
87
101
  (function (BasicTxErrorCode) {
88
- BasicTxErrorCode["INVALID_FROM_ADDRESS"] = "invalidFromAccount";
89
- BasicTxErrorCode["INVALID_TO_ADDRESS"] = "invalidToAccount";
90
- BasicTxErrorCode["NOT_ENOUGH_VALUE"] = "notEnoughValue";
91
- BasicTxErrorCode["INVALID_VALUE"] = "invalidValue";
92
- BasicTxErrorCode["INVALID_TOKEN"] = "invalidToken";
93
102
  BasicTxErrorCode["INVALID_PARAM"] = "invalidParam";
94
103
  BasicTxErrorCode["KEYRING_ERROR"] = "keyringError";
95
- BasicTxErrorCode["TRANSFER_ERROR"] = "transferError";
96
104
  BasicTxErrorCode["STAKING_ERROR"] = "stakingError";
97
105
  BasicTxErrorCode["UN_STAKING_ERROR"] = "unStakingError";
98
106
  BasicTxErrorCode["WITHDRAW_STAKING_ERROR"] = "withdrawStakingError";
107
+ BasicTxErrorCode["CLAIM_REWARD_ERROR"] = "claimRewardError";
108
+ BasicTxErrorCode["CREATE_COMPOUND_ERROR"] = "createCompoundError";
109
+ BasicTxErrorCode["CANCEL_COMPOUND_ERROR"] = "cancelCompoundError";
99
110
  BasicTxErrorCode["TIMEOUT"] = "timeout";
100
- BasicTxErrorCode["UNSUPPORTED"] = "unsupported";
111
+ BasicTxErrorCode["BALANCE_TO_LOW"] = "balanceTooLow1";
112
+ BasicTxErrorCode["UNKNOWN_ERROR"] = "unknownError";
101
113
  })(BasicTxErrorCode || (exports.BasicTxErrorCode = BasicTxErrorCode = {}));
102
114
  let TransferStep;
103
115
  exports.TransferStep = TransferStep;
@@ -116,24 +128,4 @@ exports.CustomTokenType = CustomTokenType;
116
128
  CustomTokenType["erc721"] = "erc721";
117
129
  CustomTokenType["psp22"] = "psp22";
118
130
  CustomTokenType["psp34"] = "psp34";
119
- })(CustomTokenType || (exports.CustomTokenType = CustomTokenType = {}));
120
- let ExternalRequestPromiseStatus;
121
- exports.ExternalRequestPromiseStatus = ExternalRequestPromiseStatus;
122
- (function (ExternalRequestPromiseStatus) {
123
- ExternalRequestPromiseStatus[ExternalRequestPromiseStatus["PENDING"] = 0] = "PENDING";
124
- ExternalRequestPromiseStatus[ExternalRequestPromiseStatus["REJECTED"] = 1] = "REJECTED";
125
- ExternalRequestPromiseStatus[ExternalRequestPromiseStatus["FAILED"] = 2] = "FAILED";
126
- ExternalRequestPromiseStatus[ExternalRequestPromiseStatus["COMPLETED"] = 3] = "COMPLETED";
127
- })(ExternalRequestPromiseStatus || (exports.ExternalRequestPromiseStatus = ExternalRequestPromiseStatus = {}));
128
- let AccountExternalErrorCode;
129
- exports.AccountExternalErrorCode = AccountExternalErrorCode;
130
- (function (AccountExternalErrorCode) {
131
- AccountExternalErrorCode["INVALID_ADDRESS"] = "invalidToAccount";
132
- AccountExternalErrorCode["KEYRING_ERROR"] = "keyringError";
133
- AccountExternalErrorCode["UNKNOWN_ERROR"] = "unknownError";
134
- })(AccountExternalErrorCode || (exports.AccountExternalErrorCode = AccountExternalErrorCode = {}));
135
- let BasicTxError;
136
- exports.BasicTxError = BasicTxError;
137
- (function (BasicTxError) {
138
- BasicTxError["BalanceTooLow"] = "BalanceTooLow";
139
- })(BasicTxError || (exports.BasicTxError = BasicTxError = {}));
131
+ })(CustomTokenType || (exports.CustomTokenType = CustomTokenType = {}));
@@ -49,10 +49,9 @@ function isJsonPayload(value) {
49
49
  return value.genesisHash !== undefined;
50
50
  }
51
51
  class Extension {
52
- #cachedUnlocks;
53
52
  #state;
54
53
  constructor(state) {
55
- this.#cachedUnlocks = {};
54
+ this.cachedUnlocks = {};
56
55
  this.#state = state;
57
56
  }
58
57
  accountsCreateExternal(_ref2) {
@@ -157,10 +156,10 @@ class Extension {
157
156
  const {
158
157
  address
159
158
  } = pair;
160
- const savedExpiry = this.#cachedUnlocks[address] || 0;
159
+ const savedExpiry = this.cachedUnlocks[address] || 0;
161
160
  const remainingTime = savedExpiry - Date.now();
162
161
  if (remainingTime < 0) {
163
- this.#cachedUnlocks[address] = 0;
162
+ this.cachedUnlocks[address] = 0;
164
163
  pair.lock();
165
164
  return 0;
166
165
  }
@@ -420,7 +419,7 @@ class Extension {
420
419
  }
421
420
  const result = request.sign(registry, pair);
422
421
  if (savePass) {
423
- this.#cachedUnlocks[address] = Date.now() + _defaults.PASSWORD_EXPIRY_MS;
422
+ this.cachedUnlocks[address] = Date.now() + _defaults.PASSWORD_EXPIRY_MS;
424
423
  } else {
425
424
  pair.lock();
426
425
  }
@@ -473,48 +472,6 @@ class Extension {
473
472
  remainingTime
474
473
  };
475
474
  }
476
- qrIsLocked(_ref24) {
477
- let {
478
- address
479
- } = _ref24;
480
- const pair = _uiKeyring.default.getPair(address);
481
- (0, _util.assert)(pair, 'Unable to find pair');
482
- const remainingTime = this.refreshAccountPasswordCache(pair);
483
- return {
484
- isLocked: pair.isLocked,
485
- remainingTime
486
- };
487
- }
488
- qrSignSubstrate(_ref25) {
489
- let {
490
- address,
491
- message,
492
- password,
493
- savePass
494
- } = _ref25;
495
- const pair = _uiKeyring.default.getPair(address);
496
- (0, _util.assert)(pair, 'Unable to find pair');
497
- if (pair.isLocked && !password) {
498
- throw new Error('Password needed to unlock the account');
499
- }
500
- if (pair.isLocked) {
501
- try {
502
- pair.decodePkcs8(password);
503
- } catch (e) {
504
- throw new Error('invalid password');
505
- }
506
- }
507
- const signed = (0, _util.u8aToHex)(pair.sign(message));
508
- const _address = pair.address;
509
- if (savePass) {
510
- this.#cachedUnlocks[_address] = Date.now() + _defaults.PASSWORD_EXPIRY_MS;
511
- } else {
512
- pair.lock();
513
- }
514
- return {
515
- signature: signed
516
- };
517
- }
518
475
 
519
476
  // FIXME This looks very much like what we have in authorization
520
477
  signingSubscribe(id, port) {
@@ -550,19 +507,19 @@ class Extension {
550
507
  throw new Error(`"${suri}" is not a valid derivation path`);
551
508
  }
552
509
  }
553
- derivationValidate(_ref26) {
510
+ derivationValidate(_ref24) {
554
511
  let {
555
512
  parentAddress,
556
513
  parentPassword,
557
514
  suri
558
- } = _ref26;
515
+ } = _ref24;
559
516
  const childPair = this.derive(parentAddress, suri, parentPassword, {});
560
517
  return {
561
518
  address: childPair.address,
562
519
  suri
563
520
  };
564
521
  }
565
- derivationCreate(_ref27) {
522
+ derivationCreate(_ref25) {
566
523
  let {
567
524
  genesisHash,
568
525
  name,
@@ -570,7 +527,7 @@ class Extension {
570
527
  parentPassword,
571
528
  password,
572
529
  suri
573
- } = _ref27;
530
+ } = _ref25;
574
531
  const childPair = this.derive(parentAddress, suri, parentPassword, {
575
532
  genesisHash,
576
533
  name,
@@ -660,10 +617,6 @@ class Extension {
660
617
  return this.signingCancel(request);
661
618
  case 'pri(signing.isLocked)':
662
619
  return this.signingIsLocked(request);
663
- case 'pri(qr.isLocked)':
664
- return this.qrIsLocked(request);
665
- case 'pri(qr.sign.substrate)':
666
- return this.qrSignSubstrate(request);
667
620
  case 'pri(signing.requests)':
668
621
  return this.signingSubscribe(id, port);
669
622
  case 'pri(window.open)':
@@ -13,6 +13,6 @@ const packageInfo = {
13
13
  name: '@subwallet/extension-base',
14
14
  path: typeof __dirname === 'string' ? __dirname : 'auto',
15
15
  type: 'cjs',
16
- version: '0.7.1'
16
+ version: '0.7.2-1'
17
17
  };
18
18
  exports.packageInfo = packageInfo;
@@ -21,6 +21,7 @@ let sendRequest;
21
21
  */
22
22
  class PostMessageProvider {
23
23
  #eventemitter;
24
+ isClonable = true;
24
25
 
25
26
  // Whether or not the actual extension background provider is connected
26
27
  #isConnected = false;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ // Copyright 2017-2022 @polkadot/react-signer authors & contributors
8
+ // SPDX-License-Identifier: Apache-2.0
9
+
10
+ let id = 1;
11
+ class KeyringSigner {
12
+ #pair;
13
+ #registry;
14
+ constructor(_ref) {
15
+ let {
16
+ keyPair,
17
+ registry
18
+ } = _ref;
19
+ this.#pair = keyPair;
20
+ this.#registry = registry;
21
+ }
22
+ async signPayload(payload) {
23
+ return new Promise(resolve => {
24
+ const wrapper = this.#registry.createType('ExtrinsicPayload', payload, {
25
+ version: payload.version
26
+ });
27
+ const signature = wrapper.sign(this.#pair).signature;
28
+ resolve({
29
+ id: id++,
30
+ signature: signature
31
+ });
32
+ });
33
+ }
34
+ }
35
+ exports.default = KeyringSigner;
@@ -1 +1,15 @@
1
- "use strict";
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SignerType = void 0;
7
+ // Copyright 2019-2022 @polkadot/extension-koni authors & contributors
8
+ // SPDX-License-Identifier: Apache-2.0
9
+ let SignerType;
10
+ exports.SignerType = SignerType;
11
+ (function (SignerType) {
12
+ SignerType["PASSWORD"] = "PASSWORD";
13
+ SignerType["QR"] = "QR";
14
+ SignerType["LEDGER"] = "LEDGER";
15
+ })(SignerType || (exports.SignerType = SignerType = {}));
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "./cjs/detectPackage.js"
18
18
  ],
19
19
  "type": "module",
20
- "version": "0.7.1",
20
+ "version": "0.7.2-1",
21
21
  "main": "./cjs/index.js",
22
22
  "module": "./index.js",
23
23
  "types": "./index.d.ts",
@@ -150,6 +150,11 @@
150
150
  "require": "./cjs/page/types.js",
151
151
  "default": "./page/types.js"
152
152
  },
153
+ "./signers/substrates/KeyringSigner": {
154
+ "types": "./signers/substrates/KeyringSigner.d.ts",
155
+ "require": "./cjs/signers/substrates/KeyringSigner.js",
156
+ "default": "./signers/substrates/KeyringSigner.js"
157
+ },
153
158
  "./signers/substrates/LedgerSigner": {
154
159
  "types": "./signers/substrates/LedgerSigner.d.ts",
155
160
  "require": "./cjs/signers/substrates/LedgerSigner.js",
@@ -224,9 +229,9 @@
224
229
  "@polkadot/ui-settings": "^2.9.10",
225
230
  "@polkadot/util": "^10.1.9",
226
231
  "@polkadot/util-crypto": "^10.1.9",
227
- "@subwallet/extension-chains": "^0.7.1",
228
- "@subwallet/extension-dapp": "^0.7.1",
229
- "@subwallet/extension-inject": "^0.7.1",
232
+ "@subwallet/extension-chains": "^0.7.2-1",
233
+ "@subwallet/extension-dapp": "^0.7.2-1",
234
+ "@subwallet/extension-inject": "^0.7.2-1",
230
235
  "ethereumjs-tx": "^2.1.2",
231
236
  "eventemitter3": "^4.0.7",
232
237
  "rlp": "^3.0.0",
package/packageInfo.js CHANGED
@@ -7,5 +7,5 @@ export const packageInfo = {
7
7
  name: '@subwallet/extension-base',
8
8
  path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
9
9
  type: 'esm',
10
- version: '0.7.1'
10
+ version: '0.7.2-1'
11
11
  };
@@ -14,6 +14,7 @@ interface SubscriptionHandler {
14
14
  */
15
15
  export default class PostMessageProvider implements InjectedProvider {
16
16
  #private;
17
+ isClonable: boolean;
17
18
  /**
18
19
  * @param {function} sendRequest The function to be called to send requests to the node
19
20
  * @param {function} subscriptionNotificationHandler Channel for receiving subscription messages
@@ -14,6 +14,7 @@ let sendRequest;
14
14
  */
15
15
  export default class PostMessageProvider {
16
16
  #eventemitter;
17
+ isClonable = true;
17
18
 
18
19
  // Whether or not the actual extension background provider is connected
19
20
  #isConnected = false;