@subwallet/extension-base 0.6.7-1wr → 0.6.7-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/background/KoniTypes.d.ts +64 -53
- package/background/KoniTypes.js +13 -23
- package/background/RequestBytesSign.js +1 -2
- package/background/RequestExtrinsicSign.js +1 -2
- package/background/handlers/Extension.js +28 -122
- package/background/handlers/State.js +28 -71
- package/background/handlers/Tabs.js +9 -45
- package/background/handlers/helpers.js +1 -1
- package/background/handlers/index.js +4 -2
- package/background/handlers/subscriptions.js +5 -2
- package/bundle.js +1 -0
- package/cjs/background/KoniTypes.js +15 -24
- package/cjs/background/RequestBytesSign.js +1 -6
- package/cjs/background/RequestExtrinsicSign.js +1 -4
- package/cjs/background/handlers/Extension.js +27 -174
- package/cjs/background/handlers/State.js +28 -82
- package/cjs/background/handlers/Tabs.js +9 -60
- package/cjs/background/handlers/helpers.js +1 -2
- package/cjs/background/handlers/index.js +4 -10
- package/cjs/background/handlers/subscriptions.js +5 -4
- package/cjs/bundle.js +0 -1
- package/cjs/defaults.js +2 -3
- package/cjs/detectOther.js +0 -4
- package/cjs/detectPackage.js +2 -4
- package/cjs/errors/SubWalletProviderError.js +1 -3
- package/cjs/index.js +0 -2
- package/cjs/packageInfo.js +3 -1
- package/cjs/page/Accounts.js +3 -6
- package/cjs/page/Injected.js +1 -8
- package/cjs/page/Metadata.js +1 -5
- package/cjs/page/PostMessageProvider.js +22 -38
- package/cjs/page/Signer.js +11 -11
- package/cjs/page/index.js +6 -13
- package/cjs/signers/substrates/LedgerSigner.js +1 -7
- package/cjs/signers/substrates/QrSigner.js +1 -10
- package/cjs/signers/web3/QrSigner.js +1 -12
- package/cjs/stores/Accounts.js +1 -8
- package/cjs/stores/Base.js +1 -15
- package/cjs/stores/Metadata.js +1 -6
- package/cjs/stores/index.js +0 -3
- package/cjs/utils/canDerive.js +1 -1
- package/cjs/utils/getId.js +1 -3
- package/cjs/utils/index.js +0 -1
- package/defaults.d.ts +1 -2
- package/defaults.js +2 -2
- package/detectOther.js +1 -0
- package/detectPackage.js +2 -0
- package/errors/SubWalletProviderError.js +1 -1
- package/index.js +2 -0
- package/package.json +5 -5
- package/packageInfo.js +3 -1
- package/page/Accounts.js +3 -4
- package/page/Injected.js +1 -1
- package/page/Metadata.js +1 -3
- package/page/PostMessageProvider.js +22 -33
- package/page/Signer.js +11 -9
- package/page/index.js +8 -6
- package/signers/substrates/LedgerSigner.js +1 -3
- package/signers/substrates/QrSigner.js +1 -5
- package/signers/web3/QrSigner.js +1 -5
- package/stores/Accounts.js +1 -3
- package/stores/Base.js +1 -13
- package/stores/Metadata.js +1 -1
- package/stores/index.js +1 -0
- package/utils/canDerive.js +1 -0
- package/utils/getId.js +1 -0
- package/utils/index.js +1 -0
package/page/index.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
// Copyright 2019-2022 @polkadot/extension authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { SubWalletProviderError } from '@subwallet/extension-base/errors/SubWalletProviderError';
|
|
4
5
|
import { MESSAGE_ORIGIN_PAGE } from "../defaults.js";
|
|
5
6
|
import { getId } from "../utils/getId.js";
|
|
6
|
-
import Injected from "./Injected.js";
|
|
7
|
+
import Injected from "./Injected.js";
|
|
8
|
+
// when sending a message from the injector to the extension, we
|
|
7
9
|
// - create an event - this we send to the loader
|
|
8
10
|
// - the loader takes this event and uses port.postMessage to background
|
|
9
11
|
// - on response, the loader creates a reponse event
|
|
10
12
|
// - this injector, listens on the events, maps it to the original
|
|
11
13
|
// - resolves/rejects the promise with the result (or sub data)
|
|
12
14
|
|
|
13
|
-
const handlers = {};
|
|
15
|
+
const handlers = {};
|
|
16
|
+
|
|
17
|
+
// a generic message sender that creates an event, returning a promise that will
|
|
14
18
|
// resolve once the event is resolved (by the response listener just below this)
|
|
15
19
|
|
|
16
20
|
export function sendMessage(message, request, subscriber) {
|
|
@@ -29,8 +33,9 @@ export function sendMessage(message, request, subscriber) {
|
|
|
29
33
|
};
|
|
30
34
|
window.postMessage(transportRequestMessage, '*');
|
|
31
35
|
});
|
|
32
|
-
}
|
|
36
|
+
}
|
|
33
37
|
|
|
38
|
+
// the enable function, called by the dapp to allow access
|
|
34
39
|
export async function enable(origin) {
|
|
35
40
|
await sendMessage('pub(authorize.tabV2)', {
|
|
36
41
|
origin
|
|
@@ -39,16 +44,13 @@ export async function enable(origin) {
|
|
|
39
44
|
}
|
|
40
45
|
export function handleResponse(data) {
|
|
41
46
|
const handler = handlers[data.id];
|
|
42
|
-
|
|
43
47
|
if (!handler) {
|
|
44
48
|
console.error(`Unknown response: ${JSON.stringify(data)}`);
|
|
45
49
|
return;
|
|
46
50
|
}
|
|
47
|
-
|
|
48
51
|
if (!handler.subscriber) {
|
|
49
52
|
delete handlers[data.id];
|
|
50
53
|
}
|
|
51
|
-
|
|
52
54
|
if (data.subscription) {
|
|
53
55
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
54
56
|
handler.subscriber(data.subscription);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { ExternalRequestPromiseStatus } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
5
|
import { u8aToHex } from '@polkadot/util';
|
|
5
6
|
export default class LedgerSigner {
|
|
@@ -7,14 +8,12 @@ export default class LedgerSigner {
|
|
|
7
8
|
#callback;
|
|
8
9
|
#setState;
|
|
9
10
|
#id;
|
|
10
|
-
|
|
11
11
|
constructor(registry, callback, id, setState) {
|
|
12
12
|
this.#registry = registry;
|
|
13
13
|
this.#callback = callback;
|
|
14
14
|
this.#id = id;
|
|
15
15
|
this.#setState = setState;
|
|
16
16
|
}
|
|
17
|
-
|
|
18
17
|
async signPayload(payload) {
|
|
19
18
|
return new Promise((resolve, reject) => {
|
|
20
19
|
const raw = this.#registry.createType('ExtrinsicPayload', payload, {
|
|
@@ -35,5 +34,4 @@ export default class LedgerSigner {
|
|
|
35
34
|
});
|
|
36
35
|
});
|
|
37
36
|
}
|
|
38
|
-
|
|
39
37
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/react-signer authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { ExternalRequestPromiseStatus } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
5
|
import { u8aToHex } from '@polkadot/util';
|
|
5
6
|
import { blake2AsU8a } from '@polkadot/util-crypto';
|
|
@@ -9,7 +10,6 @@ export default class QrSigner {
|
|
|
9
10
|
#registry;
|
|
10
11
|
#resolver;
|
|
11
12
|
#setState;
|
|
12
|
-
|
|
13
13
|
constructor({
|
|
14
14
|
callback,
|
|
15
15
|
id,
|
|
@@ -23,7 +23,6 @@ export default class QrSigner {
|
|
|
23
23
|
this.#resolver = resolver;
|
|
24
24
|
this.#setState = setState;
|
|
25
25
|
}
|
|
26
|
-
|
|
27
26
|
async signPayload(payload) {
|
|
28
27
|
return new Promise((resolve, reject) => {
|
|
29
28
|
// limit size of the transaction
|
|
@@ -32,12 +31,10 @@ export default class QrSigner {
|
|
|
32
31
|
version: payload.version
|
|
33
32
|
});
|
|
34
33
|
const qrPayload = isQrHashed ? blake2AsU8a(wrapper.toU8a(true)) : wrapper.toU8a();
|
|
35
|
-
|
|
36
34
|
const resolver = result => {
|
|
37
35
|
this.#resolver();
|
|
38
36
|
resolve(result);
|
|
39
37
|
};
|
|
40
|
-
|
|
41
38
|
this.#setState({
|
|
42
39
|
reject: reject,
|
|
43
40
|
resolve: resolver,
|
|
@@ -55,5 +52,4 @@ export default class QrSigner {
|
|
|
55
52
|
});
|
|
56
53
|
});
|
|
57
54
|
}
|
|
58
|
-
|
|
59
55
|
}
|
package/signers/web3/QrSigner.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { ExternalRequestPromiseStatus } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
5
|
import RLP from 'rlp';
|
|
5
6
|
import { u8aToHex } from '@polkadot/util';
|
|
@@ -8,7 +9,6 @@ export default class QrSigner {
|
|
|
8
9
|
#id;
|
|
9
10
|
#resolver;
|
|
10
11
|
#setState;
|
|
11
|
-
|
|
12
12
|
constructor({
|
|
13
13
|
callback,
|
|
14
14
|
id,
|
|
@@ -20,17 +20,14 @@ export default class QrSigner {
|
|
|
20
20
|
this.#resolver = resolver;
|
|
21
21
|
this.#setState = setState;
|
|
22
22
|
}
|
|
23
|
-
|
|
24
23
|
async signTransaction(tx) {
|
|
25
24
|
return new Promise((resolve, reject) => {
|
|
26
25
|
const data = [tx.nonce, tx.gasPrice, tx.gasLimit, tx.to, tx.value, tx.data, tx.chainId, new Uint8Array([0x00]), new Uint8Array([0x00])];
|
|
27
26
|
const qrPayload = RLP.encode(data);
|
|
28
|
-
|
|
29
27
|
const resolver = result => {
|
|
30
28
|
this.#resolver();
|
|
31
29
|
resolve(result);
|
|
32
30
|
};
|
|
33
|
-
|
|
34
31
|
this.#setState({
|
|
35
32
|
reject: reject,
|
|
36
33
|
resolve: resolver,
|
|
@@ -48,5 +45,4 @@ export default class QrSigner {
|
|
|
48
45
|
});
|
|
49
46
|
});
|
|
50
47
|
}
|
|
51
|
-
|
|
52
48
|
}
|
package/stores/Accounts.js
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
// Copyright 2019-2022 @polkadot/extension-base authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { EXTENSION_PREFIX } from "../defaults.js";
|
|
4
5
|
import BaseStore from "./Base.js";
|
|
5
6
|
export default class AccountsStore extends BaseStore {
|
|
6
7
|
constructor() {
|
|
7
8
|
super(EXTENSION_PREFIX ? `${EXTENSION_PREFIX}accounts` : null);
|
|
8
9
|
}
|
|
9
|
-
|
|
10
10
|
set(key, value, update) {
|
|
11
11
|
// shortcut, don't save testing accounts in extension storage
|
|
12
12
|
if (key.startsWith('account:') && value.meta && value.meta.isTesting) {
|
|
13
13
|
update && update();
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
16
|
super.set(key, value, update);
|
|
18
17
|
}
|
|
19
|
-
|
|
20
18
|
}
|
package/stores/Base.js
CHANGED
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
// Copyright 2019-2022 @polkadot/extension-base authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
const lastError = type => {
|
|
4
5
|
const error = chrome.runtime.lastError;
|
|
5
|
-
|
|
6
6
|
if (error) {
|
|
7
7
|
console.error(`BaseStore.${type}:: runtime.lastError:`, error);
|
|
8
8
|
}
|
|
9
9
|
};
|
|
10
|
-
|
|
11
10
|
export default class BaseStore {
|
|
12
11
|
#prefix;
|
|
13
|
-
|
|
14
12
|
constructor(prefix) {
|
|
15
13
|
this.#prefix = prefix ? `${prefix}:` : '';
|
|
16
14
|
}
|
|
17
|
-
|
|
18
15
|
getPrefix() {
|
|
19
16
|
return this.#prefix;
|
|
20
17
|
}
|
|
21
|
-
|
|
22
18
|
all(update) {
|
|
23
19
|
this.allMap(map => {
|
|
24
20
|
Object.entries(map).forEach(([key, value]) => {
|
|
@@ -26,25 +22,20 @@ export default class BaseStore {
|
|
|
26
22
|
});
|
|
27
23
|
});
|
|
28
24
|
}
|
|
29
|
-
|
|
30
25
|
allMap(update) {
|
|
31
26
|
chrome.storage.local.get(null, result => {
|
|
32
27
|
lastError('all');
|
|
33
28
|
const entries = Object.entries(result);
|
|
34
29
|
const map = {};
|
|
35
|
-
|
|
36
30
|
for (let i = 0; i < entries.length; i++) {
|
|
37
31
|
const [key, value] = entries[i];
|
|
38
|
-
|
|
39
32
|
if (key.startsWith(this.#prefix)) {
|
|
40
33
|
map[key.replace(this.#prefix, '')] = value;
|
|
41
34
|
}
|
|
42
35
|
}
|
|
43
|
-
|
|
44
36
|
update(map);
|
|
45
37
|
});
|
|
46
38
|
}
|
|
47
|
-
|
|
48
39
|
get(_key, update) {
|
|
49
40
|
const key = `${this.#prefix}${_key}`;
|
|
50
41
|
chrome.storage.local.get([key], result => {
|
|
@@ -52,7 +43,6 @@ export default class BaseStore {
|
|
|
52
43
|
update(result[key]);
|
|
53
44
|
});
|
|
54
45
|
}
|
|
55
|
-
|
|
56
46
|
remove(_key, update) {
|
|
57
47
|
const key = `${this.#prefix}${_key}`;
|
|
58
48
|
chrome.storage.local.remove(key, () => {
|
|
@@ -60,7 +50,6 @@ export default class BaseStore {
|
|
|
60
50
|
update && update();
|
|
61
51
|
});
|
|
62
52
|
}
|
|
63
|
-
|
|
64
53
|
set(_key, value, update) {
|
|
65
54
|
const key = `${this.#prefix}${_key}`;
|
|
66
55
|
chrome.storage.local.set({
|
|
@@ -70,5 +59,4 @@ export default class BaseStore {
|
|
|
70
59
|
update && update();
|
|
71
60
|
});
|
|
72
61
|
}
|
|
73
|
-
|
|
74
62
|
}
|
package/stores/Metadata.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Copyright 2019-2022 @polkadot/extension-base authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { EXTENSION_PREFIX } from "../defaults.js";
|
|
4
5
|
import BaseStore from "./Base.js";
|
|
5
6
|
export default class MetadataStore extends BaseStore {
|
|
6
7
|
constructor() {
|
|
7
8
|
super(`${EXTENSION_PREFIX}metadata`);
|
|
8
9
|
}
|
|
9
|
-
|
|
10
10
|
}
|
package/stores/index.js
CHANGED
package/utils/canDerive.js
CHANGED
package/utils/getId.js
CHANGED
package/utils/index.js
CHANGED