@dynamic-labs/multi-wallet 0.16.0 → 0.16.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.
- package/CHANGELOG.md +7 -0
- package/package.json +6 -4
- package/src/wallets/clients/walletConnect/walletConnect.d.ts +1 -1
- package/src/wallets/cosmos/keplrWalletConnect.cjs.js +1 -1
- package/src/wallets/cosmos/keplrWalletConnect.d.ts +1 -1
- package/src/wallets/cosmos/keplrWalletConnect.es.js +1 -1
- package/src/wallets/cosmos/utils/indexDB.cjs.js +97 -0
- package/src/wallets/cosmos/utils/indexDB.d.ts +18 -0
- package/src/wallets/cosmos/utils/indexDB.es.js +93 -0
- package/src/wallets/cosmos/wcClient.cjs.js +333 -0
- package/src/wallets/cosmos/wcClient.d.ts +104 -0
- package/src/wallets/cosmos/wcClient.es.js +325 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
|
|
2
|
+
### [0.16.1](https://github.com/dynamic-labs/DynamicAuth/compare/v0.16.0...v0.16.1) (2023-04-15)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* stream polyfill error that impacted some setups ([#1876](https://github.com/dynamic-labs/DynamicAuth/issues/1876)) ([7e4ef90](https://github.com/dynamic-labs/DynamicAuth/commit/7e4ef90f372f61f8961f8e6a5dd2a22f06e3d8ba))
|
|
8
|
+
|
|
2
9
|
## [0.16.0](https://github.com/dynamic-labs/DynamicAuth/compare/v0.15.0...v0.16.0) (2023-04-14)
|
|
3
10
|
It is has been a bit over a month since our last stable launch, and here comes V0.16.0!
|
|
4
11
|
We have some cool features for you and one breaking change that you should be aware of (We try our best to minimize these, but we gotta keep on cleaning legacy stuff).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/multi-wallet",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/dynamic-labs/DynamicAuth.git",
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"buffer": "^6.0.3",
|
|
11
|
+
"deepmerge": "^4.3.1",
|
|
11
12
|
"@dynamic-labs/sdk-api": "0.0.174",
|
|
12
13
|
"@dynamic-labs/wallet-book": "^0.0.11",
|
|
13
14
|
"starknet": "^3.19.0",
|
|
@@ -16,6 +17,7 @@
|
|
|
16
17
|
"@solana/web3.js": "^1.70.1",
|
|
17
18
|
"@coinbase/wallet-sdk": "^3.6.4",
|
|
18
19
|
"@walletconnect/client": "^1.8.0",
|
|
20
|
+
"@walletconnect/utils": "^1.8.0",
|
|
19
21
|
"@blocto/sdk": "^0.3.3",
|
|
20
22
|
"fortmatic": "^2.4.0",
|
|
21
23
|
"@onflow/fcl": "^1.3.2",
|
|
@@ -24,10 +26,10 @@
|
|
|
24
26
|
"@walletconnect/universal-provider": "^2.4.2",
|
|
25
27
|
"tslib": "^2.4.1",
|
|
26
28
|
"magic-sdk": "^16.0.1",
|
|
27
|
-
"@keplr-wallet/
|
|
29
|
+
"@keplr-wallet/provider": "0.11.56",
|
|
28
30
|
"@keplr-wallet/types": "^0.11.51",
|
|
29
|
-
"@dynamic-labs/logger": "0.16.
|
|
30
|
-
"@dynamic-labs/wallet-connector-core": "0.16.
|
|
31
|
+
"@dynamic-labs/logger": "0.16.1",
|
|
32
|
+
"@dynamic-labs/wallet-connector-core": "0.16.1"
|
|
31
33
|
},
|
|
32
34
|
"devDependencies": {
|
|
33
35
|
"@walletconnect/types": "^2.2.1"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Client from '@walletconnect/client';
|
|
2
|
-
import { KeplrWalletConnectV1 } from '@keplr-wallet/wc-client';
|
|
3
2
|
import { FetchPublicAddressOpts, PayloadParams, WalletEventListeners } from '@dynamic-labs/wallet-connector-core';
|
|
4
3
|
import { WalletSchema } from '@dynamic-labs/wallet-book';
|
|
4
|
+
import { KeplrWalletConnectV1 } from '../../cosmos/wcClient';
|
|
5
5
|
export declare const initClient: (name: string, settings?: any) => Client;
|
|
6
6
|
/**
|
|
7
7
|
* Attach event handlers to WalletConnect events.
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var tslib = require('tslib');
|
|
4
|
-
var wcClient = require('@keplr-wallet/wc-client');
|
|
5
4
|
var walletBook = require('@dynamic-labs/wallet-book');
|
|
6
5
|
var walletConnect = require('../clients/walletConnect/walletConnect.cjs.js');
|
|
7
6
|
var isMobile = require('../../utils/isMobile.cjs.js');
|
|
8
7
|
var logger = require('../../utils/logger.cjs.js');
|
|
9
8
|
var normalizeWalletName = require('../../utils/normalizeWalletName/normalizeWalletName.cjs.js');
|
|
9
|
+
var wcClient = require('./wcClient.cjs.js');
|
|
10
10
|
|
|
11
11
|
const DYNAMIC_KEPLR_NETWORK_ID = 'dynamic_keplr_wc_network_id';
|
|
12
12
|
class KeplrWalletConnect {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { KeplrWalletConnectV1 } from '@keplr-wallet/wc-client';
|
|
2
1
|
import Client from '@walletconnect/client';
|
|
3
2
|
import { OfflineAminoSigner } from '@keplr-wallet/types';
|
|
4
3
|
import { Chain, FetchPublicAddressOpts, WalletConnector, WalletEventListeners } from '@dynamic-labs/wallet-connector-core';
|
|
5
4
|
import { EvmNetwork } from '../ethereum/evm-network';
|
|
6
5
|
import { SwitchNetworkOps } from '../ethereum/ethProvider';
|
|
6
|
+
import { KeplrWalletConnectV1 } from './wcClient';
|
|
7
7
|
declare class KeplrWalletConnect implements WalletConnector {
|
|
8
8
|
constructor({ evmNetworks }: {
|
|
9
9
|
evmNetworks: EvmNetwork[];
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { __awaiter } from 'tslib';
|
|
2
|
-
import { KeplrWalletConnectV1 } from '@keplr-wallet/wc-client';
|
|
3
2
|
import { getWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
4
3
|
import { initClient, fetchWalletConnectCosmosPublicAddress, killWalletConnectSession, getDeepLink, setupWalletConnectEventListeners, teardownWalletConnectEventListeners } from '../clients/walletConnect/walletConnect.es.js';
|
|
5
4
|
import { isMobile, isIOS } from '../../utils/isMobile.es.js';
|
|
6
5
|
import { logger } from '../../utils/logger.es.js';
|
|
7
6
|
import { normalizeWalletName } from '../../utils/normalizeWalletName/normalizeWalletName.es.js';
|
|
7
|
+
import { KeplrWalletConnectV1 } from './wcClient.es.js';
|
|
8
8
|
|
|
9
9
|
const DYNAMIC_KEPLR_NETWORK_ID = 'dynamic_keplr_wc_network_id';
|
|
10
10
|
class KeplrWalletConnect {
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var tslib = require('tslib');
|
|
6
|
+
|
|
7
|
+
/* eslint-disable */
|
|
8
|
+
class IndexedDBKVStore {
|
|
9
|
+
constructor(_prefix) {
|
|
10
|
+
this._prefix = _prefix;
|
|
11
|
+
}
|
|
12
|
+
get(key) {
|
|
13
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
const tx = (yield this.getDB()).transaction([this.prefix()], 'readonly');
|
|
15
|
+
const store = tx.objectStore(this.prefix());
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
const request = store.get(key);
|
|
18
|
+
request.onerror = (event) => {
|
|
19
|
+
event.stopPropagation();
|
|
20
|
+
reject(event.target);
|
|
21
|
+
};
|
|
22
|
+
request.onsuccess = () => {
|
|
23
|
+
if (!request.result) {
|
|
24
|
+
resolve(undefined);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
resolve(request.result.data);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
set(key, data) {
|
|
34
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
if (data === null) {
|
|
36
|
+
const tx = (yield this.getDB()).transaction([this.prefix()], 'readwrite');
|
|
37
|
+
const store = tx.objectStore(this.prefix());
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
const request = store.delete(key);
|
|
40
|
+
request.onerror = (event) => {
|
|
41
|
+
event.stopPropagation();
|
|
42
|
+
reject(event.target);
|
|
43
|
+
};
|
|
44
|
+
request.onsuccess = () => {
|
|
45
|
+
resolve();
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
const tx = (yield this.getDB()).transaction([this.prefix()], 'readwrite');
|
|
51
|
+
const store = tx.objectStore(this.prefix());
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
const request = store.put({
|
|
54
|
+
key,
|
|
55
|
+
data,
|
|
56
|
+
});
|
|
57
|
+
request.onerror = (event) => {
|
|
58
|
+
event.stopPropagation();
|
|
59
|
+
reject(event.target);
|
|
60
|
+
};
|
|
61
|
+
request.onsuccess = () => {
|
|
62
|
+
resolve();
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
prefix() {
|
|
69
|
+
return this._prefix;
|
|
70
|
+
}
|
|
71
|
+
getDB() {
|
|
72
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
if (this.cachedDB) {
|
|
74
|
+
return this.cachedDB;
|
|
75
|
+
}
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
const request = window.indexedDB.open(this.prefix());
|
|
78
|
+
request.onerror = (event) => {
|
|
79
|
+
event.stopPropagation();
|
|
80
|
+
reject(event.target);
|
|
81
|
+
};
|
|
82
|
+
request.onupgradeneeded = (event) => {
|
|
83
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
84
|
+
// @ts-ignore
|
|
85
|
+
const db = event.target.result;
|
|
86
|
+
db.createObjectStore(this.prefix(), { keyPath: 'key' });
|
|
87
|
+
};
|
|
88
|
+
request.onsuccess = () => {
|
|
89
|
+
this.cachedDB = request.result;
|
|
90
|
+
resolve(request.result);
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
exports.IndexedDBKVStore = IndexedDBKVStore;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copied from https://github.com/chainapsis/keplr-wallet/blob/master/packages/common/src/kv-store/indexed-db.ts
|
|
3
|
+
* because of the dependency issue on cipher-base that required a stream polyfill.
|
|
4
|
+
*/
|
|
5
|
+
export interface KVStore {
|
|
6
|
+
get<T = unknown>(key: string): Promise<T | undefined>;
|
|
7
|
+
prefix(): string;
|
|
8
|
+
set<T = unknown>(key: string, data: T | null): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export declare class IndexedDBKVStore implements KVStore {
|
|
11
|
+
protected readonly _prefix: string;
|
|
12
|
+
protected cachedDB?: IDBDatabase;
|
|
13
|
+
constructor(_prefix: string);
|
|
14
|
+
get<T = unknown>(key: string): Promise<T | undefined>;
|
|
15
|
+
set<T = unknown>(key: string, data: T | null): Promise<void>;
|
|
16
|
+
prefix(): string;
|
|
17
|
+
protected getDB(): Promise<IDBDatabase>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { __awaiter } from 'tslib';
|
|
2
|
+
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
class IndexedDBKVStore {
|
|
5
|
+
constructor(_prefix) {
|
|
6
|
+
this._prefix = _prefix;
|
|
7
|
+
}
|
|
8
|
+
get(key) {
|
|
9
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
10
|
+
const tx = (yield this.getDB()).transaction([this.prefix()], 'readonly');
|
|
11
|
+
const store = tx.objectStore(this.prefix());
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const request = store.get(key);
|
|
14
|
+
request.onerror = (event) => {
|
|
15
|
+
event.stopPropagation();
|
|
16
|
+
reject(event.target);
|
|
17
|
+
};
|
|
18
|
+
request.onsuccess = () => {
|
|
19
|
+
if (!request.result) {
|
|
20
|
+
resolve(undefined);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
resolve(request.result.data);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
set(key, data) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
if (data === null) {
|
|
32
|
+
const tx = (yield this.getDB()).transaction([this.prefix()], 'readwrite');
|
|
33
|
+
const store = tx.objectStore(this.prefix());
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
const request = store.delete(key);
|
|
36
|
+
request.onerror = (event) => {
|
|
37
|
+
event.stopPropagation();
|
|
38
|
+
reject(event.target);
|
|
39
|
+
};
|
|
40
|
+
request.onsuccess = () => {
|
|
41
|
+
resolve();
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
const tx = (yield this.getDB()).transaction([this.prefix()], 'readwrite');
|
|
47
|
+
const store = tx.objectStore(this.prefix());
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
const request = store.put({
|
|
50
|
+
key,
|
|
51
|
+
data,
|
|
52
|
+
});
|
|
53
|
+
request.onerror = (event) => {
|
|
54
|
+
event.stopPropagation();
|
|
55
|
+
reject(event.target);
|
|
56
|
+
};
|
|
57
|
+
request.onsuccess = () => {
|
|
58
|
+
resolve();
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
prefix() {
|
|
65
|
+
return this._prefix;
|
|
66
|
+
}
|
|
67
|
+
getDB() {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
if (this.cachedDB) {
|
|
70
|
+
return this.cachedDB;
|
|
71
|
+
}
|
|
72
|
+
return new Promise((resolve, reject) => {
|
|
73
|
+
const request = window.indexedDB.open(this.prefix());
|
|
74
|
+
request.onerror = (event) => {
|
|
75
|
+
event.stopPropagation();
|
|
76
|
+
reject(event.target);
|
|
77
|
+
};
|
|
78
|
+
request.onupgradeneeded = (event) => {
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
const db = event.target.result;
|
|
82
|
+
db.createObjectStore(this.prefix(), { keyPath: 'key' });
|
|
83
|
+
};
|
|
84
|
+
request.onsuccess = () => {
|
|
85
|
+
this.cachedDB = request.result;
|
|
86
|
+
resolve(request.result);
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { IndexedDBKVStore };
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var tslib = require('tslib');
|
|
6
|
+
var buffer = require('buffer');
|
|
7
|
+
var provider = require('@keplr-wallet/provider');
|
|
8
|
+
var utils = require('@walletconnect/utils');
|
|
9
|
+
var deepmerge = require('deepmerge');
|
|
10
|
+
var indexDB = require('./utils/indexDB.cjs.js');
|
|
11
|
+
|
|
12
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
|
+
|
|
14
|
+
var deepmerge__default = /*#__PURE__*/_interopDefaultLegacy(deepmerge);
|
|
15
|
+
|
|
16
|
+
/* eslint-disable */
|
|
17
|
+
// VersionFormatRegExp checks if a chainID is in the format required for parsing versions
|
|
18
|
+
// The chainID should be in the form: `{identifier}-{version}`
|
|
19
|
+
const ChainVersionFormatRegExp = /(.+)-([\d]+)/;
|
|
20
|
+
function parseChainId(chainId) {
|
|
21
|
+
const split = chainId.split(ChainVersionFormatRegExp).filter(Boolean);
|
|
22
|
+
if (split.length !== 2) {
|
|
23
|
+
return {
|
|
24
|
+
identifier: chainId,
|
|
25
|
+
version: 0,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
return { identifier: split[0], version: parseInt(split[1]) };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
class KeplrWalletConnectV1 {
|
|
33
|
+
constructor(connector, options = {}) {
|
|
34
|
+
this.connector = connector;
|
|
35
|
+
this.options = options;
|
|
36
|
+
this.version = '0.9.0';
|
|
37
|
+
this.mode = 'walletconnect';
|
|
38
|
+
this.defaultOptions = {};
|
|
39
|
+
this.onCallReqeust = (error, payload) => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
if (error) {
|
|
41
|
+
console.log(error);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (!payload) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (payload.method === 'keplr_keystore_may_changed_event_wallet_connect_v1') {
|
|
48
|
+
const param = payload.params[0];
|
|
49
|
+
if (!param) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const lastSeenKeys = yield this.getAllLastSeenKey();
|
|
53
|
+
if (!lastSeenKeys) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const mayChangedKeyMap = {};
|
|
57
|
+
for (const mayChangedKey of param.keys) {
|
|
58
|
+
mayChangedKeyMap[mayChangedKey.chainIdentifier] = {
|
|
59
|
+
address: mayChangedKey.address,
|
|
60
|
+
algo: param.algo,
|
|
61
|
+
bech32Address: mayChangedKey.bech32Address,
|
|
62
|
+
isKeystone: param.isKeystone,
|
|
63
|
+
isNanoLedger: param.isNanoLedger,
|
|
64
|
+
name: param.name,
|
|
65
|
+
pubKey: mayChangedKey.pubKey,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
let hasChanged = false;
|
|
69
|
+
for (const chainId of Object.keys(lastSeenKeys)) {
|
|
70
|
+
const savedKey = lastSeenKeys[chainId];
|
|
71
|
+
if (savedKey) {
|
|
72
|
+
const { identifier } = parseChainId(chainId);
|
|
73
|
+
const mayChangedKey = mayChangedKeyMap[identifier];
|
|
74
|
+
if (mayChangedKey) {
|
|
75
|
+
if (mayChangedKey.algo !== savedKey.algo ||
|
|
76
|
+
mayChangedKey.name !== savedKey.name ||
|
|
77
|
+
mayChangedKey.isKeystone !== savedKey.isKeystone ||
|
|
78
|
+
mayChangedKey.isNanoLedger !== savedKey.isNanoLedger ||
|
|
79
|
+
mayChangedKey.address !== savedKey.address ||
|
|
80
|
+
mayChangedKey.bech32Address !== savedKey.bech32Address ||
|
|
81
|
+
mayChangedKey.pubKey !== savedKey.pubKey) {
|
|
82
|
+
hasChanged = true;
|
|
83
|
+
lastSeenKeys[chainId] = mayChangedKey;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (hasChanged) {
|
|
89
|
+
yield this.saveAllLastSeenKey(lastSeenKeys);
|
|
90
|
+
window.dispatchEvent(new Event('keplr_keystorechange'));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
if (!options.kvStore) {
|
|
95
|
+
options.kvStore = new indexDB.IndexedDBKVStore('keplr_wallet_connect');
|
|
96
|
+
}
|
|
97
|
+
connector.on('disconnect', () => {
|
|
98
|
+
this.clearSaved();
|
|
99
|
+
});
|
|
100
|
+
connector.on('call_request', this.onCallReqeust);
|
|
101
|
+
}
|
|
102
|
+
clearSaved() {
|
|
103
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
const kvStore = this.options.kvStore;
|
|
105
|
+
yield Promise.all([
|
|
106
|
+
kvStore.set(this.getKeyHasEnabled(), null),
|
|
107
|
+
kvStore.set(this.getKeyLastSeenKey(), null),
|
|
108
|
+
]);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
sendCustomRequest(request, options) {
|
|
112
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
if (this.options.onBeforeSendRequest) {
|
|
114
|
+
yield this.options.onBeforeSendRequest(request, options);
|
|
115
|
+
}
|
|
116
|
+
const res = yield this.connector.sendCustomRequest(request, options);
|
|
117
|
+
if (this.options.onAfterSendRequest) {
|
|
118
|
+
yield this.options.onAfterSendRequest(res, request, options);
|
|
119
|
+
}
|
|
120
|
+
return res;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
enable(chainIds) {
|
|
124
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
if (typeof chainIds === 'string') {
|
|
126
|
+
chainIds = [chainIds];
|
|
127
|
+
}
|
|
128
|
+
const hasEnabledChainIds = yield this.getHasEnabledChainIds();
|
|
129
|
+
let allEnabled = true;
|
|
130
|
+
for (const chainId of chainIds) {
|
|
131
|
+
if (hasEnabledChainIds.indexOf(chainId) < 0) {
|
|
132
|
+
allEnabled = false;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (allEnabled) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
yield this.sendCustomRequest({
|
|
140
|
+
id: utils.payloadId(),
|
|
141
|
+
jsonrpc: '2.0',
|
|
142
|
+
method: 'keplr_enable_wallet_connect_v1',
|
|
143
|
+
params: chainIds,
|
|
144
|
+
});
|
|
145
|
+
yield this.saveHasEnabledChainIds(chainIds);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
getKeyHasEnabled() {
|
|
149
|
+
return `${this.connector.session.handshakeTopic}-enabled`;
|
|
150
|
+
}
|
|
151
|
+
getHasEnabledChainIds() {
|
|
152
|
+
var _a;
|
|
153
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
154
|
+
return ((_a = (yield this.options.kvStore.get(this.getKeyHasEnabled()))) !== null && _a !== void 0 ? _a : []);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
saveHasEnabledChainIds(chainIds) {
|
|
158
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
159
|
+
const hasEnabledChainIds = yield this.getHasEnabledChainIds();
|
|
160
|
+
for (const chainId of chainIds) {
|
|
161
|
+
if (hasEnabledChainIds.indexOf(chainId) < 0) {
|
|
162
|
+
hasEnabledChainIds.push(chainId);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
yield this.options.kvStore.set(this.getKeyHasEnabled(), hasEnabledChainIds);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
enigmaDecrypt(_chainId, _ciphertext, _nonce) {
|
|
169
|
+
throw new Error('Not yet implemented');
|
|
170
|
+
}
|
|
171
|
+
enigmaEncrypt(_chainId, _contractCodeHash,
|
|
172
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
173
|
+
_msg) {
|
|
174
|
+
throw new Error('Not yet implemented');
|
|
175
|
+
}
|
|
176
|
+
experimentalSuggestChain(_chainInfo) {
|
|
177
|
+
throw new Error('Not yet implemented');
|
|
178
|
+
}
|
|
179
|
+
getEnigmaPubKey(_chainId) {
|
|
180
|
+
throw new Error('Not yet implemented');
|
|
181
|
+
}
|
|
182
|
+
getEnigmaTxEncryptionKey(_chainId, _nonce) {
|
|
183
|
+
throw new Error('Not yet implemented');
|
|
184
|
+
}
|
|
185
|
+
getEnigmaUtils(_chainId) {
|
|
186
|
+
throw new Error('Not yet implemented');
|
|
187
|
+
}
|
|
188
|
+
getKey(chainId) {
|
|
189
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
190
|
+
const lastSeenKey = yield this.getLastSeenKey(chainId);
|
|
191
|
+
if (lastSeenKey) {
|
|
192
|
+
return {
|
|
193
|
+
address: buffer.Buffer.from(lastSeenKey.address, 'hex'),
|
|
194
|
+
algo: lastSeenKey.algo,
|
|
195
|
+
bech32Address: lastSeenKey.bech32Address,
|
|
196
|
+
isKeystone: lastSeenKey.isKeystone,
|
|
197
|
+
isNanoLedger: lastSeenKey.isNanoLedger,
|
|
198
|
+
name: lastSeenKey.name,
|
|
199
|
+
pubKey: buffer.Buffer.from(lastSeenKey.pubKey, 'hex'),
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
const response = (yield this.sendCustomRequest({
|
|
203
|
+
id: utils.payloadId(),
|
|
204
|
+
jsonrpc: '2.0',
|
|
205
|
+
method: 'keplr_get_key_wallet_connect_v1',
|
|
206
|
+
params: [chainId],
|
|
207
|
+
}))[0];
|
|
208
|
+
yield this.saveLastSeenKey(chainId, response);
|
|
209
|
+
return {
|
|
210
|
+
address: buffer.Buffer.from(response.address, 'hex'),
|
|
211
|
+
algo: response.algo,
|
|
212
|
+
bech32Address: response.bech32Address,
|
|
213
|
+
isKeystone: response.isKeystone,
|
|
214
|
+
isNanoLedger: response.isNanoLedger,
|
|
215
|
+
name: response.name,
|
|
216
|
+
pubKey: buffer.Buffer.from(response.pubKey, 'hex'),
|
|
217
|
+
};
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
getKeyLastSeenKey() {
|
|
221
|
+
return `${this.connector.session.handshakeTopic}-key`;
|
|
222
|
+
}
|
|
223
|
+
getLastSeenKey(chainId) {
|
|
224
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
225
|
+
const saved = yield this.getAllLastSeenKey();
|
|
226
|
+
if (!saved) {
|
|
227
|
+
return undefined;
|
|
228
|
+
}
|
|
229
|
+
return saved[chainId];
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
getAllLastSeenKey() {
|
|
233
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
234
|
+
return yield this.options.kvStore.get(this.getKeyLastSeenKey());
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
saveAllLastSeenKey(data) {
|
|
238
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
239
|
+
yield this.options.kvStore.set(this.getKeyLastSeenKey(), data);
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
saveLastSeenKey(chainId, response) {
|
|
243
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
244
|
+
let saved = yield this.getAllLastSeenKey();
|
|
245
|
+
if (!saved) {
|
|
246
|
+
saved = {};
|
|
247
|
+
}
|
|
248
|
+
saved[chainId] = response;
|
|
249
|
+
yield this.saveAllLastSeenKey(saved);
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
signArbitrary(_chainId, _signer, _data) {
|
|
253
|
+
throw new Error('Not yet implemented');
|
|
254
|
+
}
|
|
255
|
+
verifyArbitrary(_chainId, _signer, _data, _signature) {
|
|
256
|
+
throw new Error('Not yet implemented');
|
|
257
|
+
}
|
|
258
|
+
signEthereum(_chainId, _signer, _data, _mode) {
|
|
259
|
+
throw new Error('Not yet implemented');
|
|
260
|
+
}
|
|
261
|
+
signICNSAdr36(_chainId, _contractAddress, _owner, _username, _addressChainIds) {
|
|
262
|
+
throw new Error('Not yet implemented');
|
|
263
|
+
}
|
|
264
|
+
getOfflineSigner(chainId) {
|
|
265
|
+
return new provider.CosmJSOfflineSigner(chainId, this);
|
|
266
|
+
}
|
|
267
|
+
getOfflineSignerAuto(chainId) {
|
|
268
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
269
|
+
const key = yield this.getKey(chainId);
|
|
270
|
+
if (key.isNanoLedger) {
|
|
271
|
+
return new provider.CosmJSOfflineSignerOnlyAmino(chainId, this);
|
|
272
|
+
}
|
|
273
|
+
return new provider.CosmJSOfflineSigner(chainId, this);
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
getOfflineSignerOnlyAmino(chainId) {
|
|
277
|
+
return new provider.CosmJSOfflineSignerOnlyAmino(chainId, this);
|
|
278
|
+
}
|
|
279
|
+
getSecret20ViewingKey(_chainId, _contractAddress) {
|
|
280
|
+
throw new Error('Not yet implemented');
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* In the extension environment, this API let the extension to send the tx on behalf of the client.
|
|
284
|
+
* But, in the wallet connect environment, in order to send the tx on behalf of the client, wallet should receive the tx data from remote.
|
|
285
|
+
* However, this approach is not efficient and hard to ensure the stability and `KeplrWalletConnect` should have the informations of rpc and rest endpoints.
|
|
286
|
+
* So, rather than implementing this, just fallback to the client sided implementation or throw error of the client sided implementation is not delivered to the `options`.
|
|
287
|
+
* @param chainId
|
|
288
|
+
* @param stdTx
|
|
289
|
+
* @param mode
|
|
290
|
+
*/
|
|
291
|
+
sendTx(chainId, tx, mode) {
|
|
292
|
+
if (this.options.sendTx) {
|
|
293
|
+
return this.options.sendTx(chainId, tx, mode);
|
|
294
|
+
}
|
|
295
|
+
throw new Error('send tx is not delivered by options');
|
|
296
|
+
}
|
|
297
|
+
signAmino(chainId, signer, signDoc, signOptions = {}) {
|
|
298
|
+
var _a;
|
|
299
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
300
|
+
return (yield this.sendCustomRequest({
|
|
301
|
+
id: utils.payloadId(),
|
|
302
|
+
jsonrpc: '2.0',
|
|
303
|
+
method: 'keplr_sign_amino_wallet_connect_v1',
|
|
304
|
+
params: [
|
|
305
|
+
chainId,
|
|
306
|
+
signer,
|
|
307
|
+
signDoc,
|
|
308
|
+
deepmerge__default["default"]((_a = this.defaultOptions.sign) !== null && _a !== void 0 ? _a : {}, signOptions),
|
|
309
|
+
],
|
|
310
|
+
}))[0];
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
signDirect(_chainId, _signer, _signDoc, _signOptions = {}) {
|
|
314
|
+
throw new Error('Not yet implemented');
|
|
315
|
+
}
|
|
316
|
+
suggestToken(_chainId, _contractAddress, _viewingKey) {
|
|
317
|
+
throw new Error('Not yet implemented');
|
|
318
|
+
}
|
|
319
|
+
experimentalSignEIP712CosmosTx_v0(_chainId, _signer, _eip712, _signDoc, _signOptions = {}) {
|
|
320
|
+
throw new Error('Not yet implemented');
|
|
321
|
+
}
|
|
322
|
+
getChainInfosWithoutEndpoints() {
|
|
323
|
+
throw new Error('Not yet implemented');
|
|
324
|
+
}
|
|
325
|
+
disable(_chainIds) {
|
|
326
|
+
throw new Error('Not yet implemented');
|
|
327
|
+
}
|
|
328
|
+
changeKeyRingName(_opts) {
|
|
329
|
+
throw new Error('Not yet implemented');
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
exports.KeplrWalletConnectV1 = KeplrWalletConnectV1;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { ChainInfo, EthSignType, Keplr, KeplrIntereactionOptions, KeplrMode, KeplrSignOptions, Key, DirectSignResponse, OfflineDirectSigner, AminoSignResponse, BroadcastMode, OfflineAminoSigner, StdSignature, StdSignDoc, ICNSAdr36Signatures, ChainInfoWithoutEndpoints, SecretUtils } from '@keplr-wallet/types';
|
|
2
|
+
import { KVStore } from './utils/indexDB';
|
|
3
|
+
export type KeplrGetKeyWalletCoonectV1Response = {
|
|
4
|
+
address: string;
|
|
5
|
+
algo: string;
|
|
6
|
+
bech32Address: string;
|
|
7
|
+
isKeystone: boolean;
|
|
8
|
+
isNanoLedger: boolean;
|
|
9
|
+
name: string;
|
|
10
|
+
pubKey: string;
|
|
11
|
+
};
|
|
12
|
+
export type KeplrKeystoreMayChangedEventParam = {
|
|
13
|
+
algo: string;
|
|
14
|
+
isKeystone: boolean;
|
|
15
|
+
isNanoLedger: boolean;
|
|
16
|
+
keys: {
|
|
17
|
+
address: string;
|
|
18
|
+
bech32Address: string;
|
|
19
|
+
chainIdentifier: string;
|
|
20
|
+
pubKey: string;
|
|
21
|
+
}[];
|
|
22
|
+
name: string;
|
|
23
|
+
};
|
|
24
|
+
export declare class KeplrWalletConnectV1 implements Keplr {
|
|
25
|
+
readonly connector: any;
|
|
26
|
+
readonly options: {
|
|
27
|
+
kvStore?: KVStore;
|
|
28
|
+
onAfterSendRequest?: (response: any, request: Partial<any>, options?: any) => Promise<void> | void;
|
|
29
|
+
onBeforeSendRequest?: (request: Partial<any>, options?: any) => Promise<void> | void;
|
|
30
|
+
sendTx?: Keplr['sendTx'];
|
|
31
|
+
};
|
|
32
|
+
constructor(connector: any, options?: {
|
|
33
|
+
kvStore?: KVStore;
|
|
34
|
+
onAfterSendRequest?: (response: any, request: Partial<any>, options?: any) => Promise<void> | void;
|
|
35
|
+
onBeforeSendRequest?: (request: Partial<any>, options?: any) => Promise<void> | void;
|
|
36
|
+
sendTx?: Keplr['sendTx'];
|
|
37
|
+
});
|
|
38
|
+
readonly version: string;
|
|
39
|
+
readonly mode: KeplrMode;
|
|
40
|
+
defaultOptions: KeplrIntereactionOptions;
|
|
41
|
+
protected readonly onCallReqeust: (error: Error | null, payload: any | null) => Promise<void>;
|
|
42
|
+
protected clearSaved(): Promise<void>;
|
|
43
|
+
protected sendCustomRequest(request: Partial<any>, options?: any): Promise<any>;
|
|
44
|
+
enable(chainIds: string | string[]): Promise<void>;
|
|
45
|
+
protected getKeyHasEnabled(): string;
|
|
46
|
+
protected getHasEnabledChainIds(): Promise<string[]>;
|
|
47
|
+
protected saveHasEnabledChainIds(chainIds: string[]): Promise<void>;
|
|
48
|
+
enigmaDecrypt(_chainId: string, _ciphertext: Uint8Array, _nonce: Uint8Array): Promise<Uint8Array>;
|
|
49
|
+
enigmaEncrypt(_chainId: string, _contractCodeHash: string, _msg: object): Promise<Uint8Array>;
|
|
50
|
+
experimentalSuggestChain(_chainInfo: ChainInfo): Promise<void>;
|
|
51
|
+
getEnigmaPubKey(_chainId: string): Promise<Uint8Array>;
|
|
52
|
+
getEnigmaTxEncryptionKey(_chainId: string, _nonce: Uint8Array): Promise<Uint8Array>;
|
|
53
|
+
getEnigmaUtils(_chainId: string): SecretUtils;
|
|
54
|
+
getKey(chainId: string): Promise<Key>;
|
|
55
|
+
protected getKeyLastSeenKey(): string;
|
|
56
|
+
protected getLastSeenKey(chainId: string): Promise<KeplrGetKeyWalletCoonectV1Response | undefined>;
|
|
57
|
+
protected getAllLastSeenKey(): Promise<{
|
|
58
|
+
[chainId: string]: KeplrGetKeyWalletCoonectV1Response | undefined;
|
|
59
|
+
} | undefined>;
|
|
60
|
+
protected saveAllLastSeenKey(data: {
|
|
61
|
+
[chainId: string]: KeplrGetKeyWalletCoonectV1Response | undefined;
|
|
62
|
+
}): Promise<void>;
|
|
63
|
+
protected saveLastSeenKey(chainId: string, response: KeplrGetKeyWalletCoonectV1Response): Promise<void>;
|
|
64
|
+
signArbitrary(_chainId: string, _signer: string, _data: string | Uint8Array): Promise<StdSignature>;
|
|
65
|
+
verifyArbitrary(_chainId: string, _signer: string, _data: string | Uint8Array, _signature: StdSignature): Promise<boolean>;
|
|
66
|
+
signEthereum(_chainId: string, _signer: string, _data: string | Uint8Array, _mode: EthSignType): Promise<Uint8Array>;
|
|
67
|
+
signICNSAdr36(_chainId: string, _contractAddress: string, _owner: string, _username: string, _addressChainIds: string[]): Promise<ICNSAdr36Signatures>;
|
|
68
|
+
getOfflineSigner(chainId: string): OfflineAminoSigner & OfflineDirectSigner;
|
|
69
|
+
getOfflineSignerAuto(chainId: string): Promise<OfflineAminoSigner | OfflineDirectSigner>;
|
|
70
|
+
getOfflineSignerOnlyAmino(chainId: string): OfflineAminoSigner;
|
|
71
|
+
getSecret20ViewingKey(_chainId: string, _contractAddress: string): Promise<string>;
|
|
72
|
+
/**
|
|
73
|
+
* In the extension environment, this API let the extension to send the tx on behalf of the client.
|
|
74
|
+
* But, in the wallet connect environment, in order to send the tx on behalf of the client, wallet should receive the tx data from remote.
|
|
75
|
+
* However, this approach is not efficient and hard to ensure the stability and `KeplrWalletConnect` should have the informations of rpc and rest endpoints.
|
|
76
|
+
* So, rather than implementing this, just fallback to the client sided implementation or throw error of the client sided implementation is not delivered to the `options`.
|
|
77
|
+
* @param chainId
|
|
78
|
+
* @param stdTx
|
|
79
|
+
* @param mode
|
|
80
|
+
*/
|
|
81
|
+
sendTx(chainId: string, tx: Uint8Array, mode: BroadcastMode): Promise<Uint8Array>;
|
|
82
|
+
signAmino(chainId: string, signer: string, signDoc: StdSignDoc, signOptions?: KeplrSignOptions): Promise<AminoSignResponse>;
|
|
83
|
+
signDirect(_chainId: string, _signer: string, _signDoc: {
|
|
84
|
+
accountNumber?: any | null;
|
|
85
|
+
authInfoBytes?: Uint8Array | null;
|
|
86
|
+
bodyBytes?: Uint8Array | null;
|
|
87
|
+
chainId?: string | null;
|
|
88
|
+
}, _signOptions?: KeplrSignOptions): Promise<DirectSignResponse>;
|
|
89
|
+
suggestToken(_chainId: string, _contractAddress: string, _viewingKey?: string): Promise<void>;
|
|
90
|
+
experimentalSignEIP712CosmosTx_v0(_chainId: string, _signer: string, _eip712: {
|
|
91
|
+
domain: Record<string, any>;
|
|
92
|
+
primaryType: string;
|
|
93
|
+
types: Record<string, {
|
|
94
|
+
name: string;
|
|
95
|
+
type: string;
|
|
96
|
+
}[] | undefined>;
|
|
97
|
+
}, _signDoc: StdSignDoc, _signOptions?: KeplrSignOptions): Promise<AminoSignResponse>;
|
|
98
|
+
getChainInfosWithoutEndpoints(): Promise<ChainInfoWithoutEndpoints[]>;
|
|
99
|
+
disable(_chainIds?: string | string[]): Promise<void>;
|
|
100
|
+
changeKeyRingName(_opts: {
|
|
101
|
+
defaultName: string;
|
|
102
|
+
editable?: boolean | undefined;
|
|
103
|
+
}): Promise<string>;
|
|
104
|
+
}
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import { __awaiter } from 'tslib';
|
|
2
|
+
import { Buffer } from 'buffer';
|
|
3
|
+
import { CosmJSOfflineSigner, CosmJSOfflineSignerOnlyAmino } from '@keplr-wallet/provider';
|
|
4
|
+
import { payloadId } from '@walletconnect/utils';
|
|
5
|
+
import deepmerge from 'deepmerge';
|
|
6
|
+
import { IndexedDBKVStore } from './utils/indexDB.es.js';
|
|
7
|
+
|
|
8
|
+
/* eslint-disable */
|
|
9
|
+
// VersionFormatRegExp checks if a chainID is in the format required for parsing versions
|
|
10
|
+
// The chainID should be in the form: `{identifier}-{version}`
|
|
11
|
+
const ChainVersionFormatRegExp = /(.+)-([\d]+)/;
|
|
12
|
+
function parseChainId(chainId) {
|
|
13
|
+
const split = chainId.split(ChainVersionFormatRegExp).filter(Boolean);
|
|
14
|
+
if (split.length !== 2) {
|
|
15
|
+
return {
|
|
16
|
+
identifier: chainId,
|
|
17
|
+
version: 0,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
return { identifier: split[0], version: parseInt(split[1]) };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
class KeplrWalletConnectV1 {
|
|
25
|
+
constructor(connector, options = {}) {
|
|
26
|
+
this.connector = connector;
|
|
27
|
+
this.options = options;
|
|
28
|
+
this.version = '0.9.0';
|
|
29
|
+
this.mode = 'walletconnect';
|
|
30
|
+
this.defaultOptions = {};
|
|
31
|
+
this.onCallReqeust = (error, payload) => __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
if (error) {
|
|
33
|
+
console.log(error);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (!payload) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (payload.method === 'keplr_keystore_may_changed_event_wallet_connect_v1') {
|
|
40
|
+
const param = payload.params[0];
|
|
41
|
+
if (!param) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const lastSeenKeys = yield this.getAllLastSeenKey();
|
|
45
|
+
if (!lastSeenKeys) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const mayChangedKeyMap = {};
|
|
49
|
+
for (const mayChangedKey of param.keys) {
|
|
50
|
+
mayChangedKeyMap[mayChangedKey.chainIdentifier] = {
|
|
51
|
+
address: mayChangedKey.address,
|
|
52
|
+
algo: param.algo,
|
|
53
|
+
bech32Address: mayChangedKey.bech32Address,
|
|
54
|
+
isKeystone: param.isKeystone,
|
|
55
|
+
isNanoLedger: param.isNanoLedger,
|
|
56
|
+
name: param.name,
|
|
57
|
+
pubKey: mayChangedKey.pubKey,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
let hasChanged = false;
|
|
61
|
+
for (const chainId of Object.keys(lastSeenKeys)) {
|
|
62
|
+
const savedKey = lastSeenKeys[chainId];
|
|
63
|
+
if (savedKey) {
|
|
64
|
+
const { identifier } = parseChainId(chainId);
|
|
65
|
+
const mayChangedKey = mayChangedKeyMap[identifier];
|
|
66
|
+
if (mayChangedKey) {
|
|
67
|
+
if (mayChangedKey.algo !== savedKey.algo ||
|
|
68
|
+
mayChangedKey.name !== savedKey.name ||
|
|
69
|
+
mayChangedKey.isKeystone !== savedKey.isKeystone ||
|
|
70
|
+
mayChangedKey.isNanoLedger !== savedKey.isNanoLedger ||
|
|
71
|
+
mayChangedKey.address !== savedKey.address ||
|
|
72
|
+
mayChangedKey.bech32Address !== savedKey.bech32Address ||
|
|
73
|
+
mayChangedKey.pubKey !== savedKey.pubKey) {
|
|
74
|
+
hasChanged = true;
|
|
75
|
+
lastSeenKeys[chainId] = mayChangedKey;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (hasChanged) {
|
|
81
|
+
yield this.saveAllLastSeenKey(lastSeenKeys);
|
|
82
|
+
window.dispatchEvent(new Event('keplr_keystorechange'));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
if (!options.kvStore) {
|
|
87
|
+
options.kvStore = new IndexedDBKVStore('keplr_wallet_connect');
|
|
88
|
+
}
|
|
89
|
+
connector.on('disconnect', () => {
|
|
90
|
+
this.clearSaved();
|
|
91
|
+
});
|
|
92
|
+
connector.on('call_request', this.onCallReqeust);
|
|
93
|
+
}
|
|
94
|
+
clearSaved() {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
const kvStore = this.options.kvStore;
|
|
97
|
+
yield Promise.all([
|
|
98
|
+
kvStore.set(this.getKeyHasEnabled(), null),
|
|
99
|
+
kvStore.set(this.getKeyLastSeenKey(), null),
|
|
100
|
+
]);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
sendCustomRequest(request, options) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
if (this.options.onBeforeSendRequest) {
|
|
106
|
+
yield this.options.onBeforeSendRequest(request, options);
|
|
107
|
+
}
|
|
108
|
+
const res = yield this.connector.sendCustomRequest(request, options);
|
|
109
|
+
if (this.options.onAfterSendRequest) {
|
|
110
|
+
yield this.options.onAfterSendRequest(res, request, options);
|
|
111
|
+
}
|
|
112
|
+
return res;
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
enable(chainIds) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
if (typeof chainIds === 'string') {
|
|
118
|
+
chainIds = [chainIds];
|
|
119
|
+
}
|
|
120
|
+
const hasEnabledChainIds = yield this.getHasEnabledChainIds();
|
|
121
|
+
let allEnabled = true;
|
|
122
|
+
for (const chainId of chainIds) {
|
|
123
|
+
if (hasEnabledChainIds.indexOf(chainId) < 0) {
|
|
124
|
+
allEnabled = false;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (allEnabled) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
yield this.sendCustomRequest({
|
|
132
|
+
id: payloadId(),
|
|
133
|
+
jsonrpc: '2.0',
|
|
134
|
+
method: 'keplr_enable_wallet_connect_v1',
|
|
135
|
+
params: chainIds,
|
|
136
|
+
});
|
|
137
|
+
yield this.saveHasEnabledChainIds(chainIds);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
getKeyHasEnabled() {
|
|
141
|
+
return `${this.connector.session.handshakeTopic}-enabled`;
|
|
142
|
+
}
|
|
143
|
+
getHasEnabledChainIds() {
|
|
144
|
+
var _a;
|
|
145
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
return ((_a = (yield this.options.kvStore.get(this.getKeyHasEnabled()))) !== null && _a !== void 0 ? _a : []);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
saveHasEnabledChainIds(chainIds) {
|
|
150
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
151
|
+
const hasEnabledChainIds = yield this.getHasEnabledChainIds();
|
|
152
|
+
for (const chainId of chainIds) {
|
|
153
|
+
if (hasEnabledChainIds.indexOf(chainId) < 0) {
|
|
154
|
+
hasEnabledChainIds.push(chainId);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
yield this.options.kvStore.set(this.getKeyHasEnabled(), hasEnabledChainIds);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
enigmaDecrypt(_chainId, _ciphertext, _nonce) {
|
|
161
|
+
throw new Error('Not yet implemented');
|
|
162
|
+
}
|
|
163
|
+
enigmaEncrypt(_chainId, _contractCodeHash,
|
|
164
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
165
|
+
_msg) {
|
|
166
|
+
throw new Error('Not yet implemented');
|
|
167
|
+
}
|
|
168
|
+
experimentalSuggestChain(_chainInfo) {
|
|
169
|
+
throw new Error('Not yet implemented');
|
|
170
|
+
}
|
|
171
|
+
getEnigmaPubKey(_chainId) {
|
|
172
|
+
throw new Error('Not yet implemented');
|
|
173
|
+
}
|
|
174
|
+
getEnigmaTxEncryptionKey(_chainId, _nonce) {
|
|
175
|
+
throw new Error('Not yet implemented');
|
|
176
|
+
}
|
|
177
|
+
getEnigmaUtils(_chainId) {
|
|
178
|
+
throw new Error('Not yet implemented');
|
|
179
|
+
}
|
|
180
|
+
getKey(chainId) {
|
|
181
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
182
|
+
const lastSeenKey = yield this.getLastSeenKey(chainId);
|
|
183
|
+
if (lastSeenKey) {
|
|
184
|
+
return {
|
|
185
|
+
address: Buffer.from(lastSeenKey.address, 'hex'),
|
|
186
|
+
algo: lastSeenKey.algo,
|
|
187
|
+
bech32Address: lastSeenKey.bech32Address,
|
|
188
|
+
isKeystone: lastSeenKey.isKeystone,
|
|
189
|
+
isNanoLedger: lastSeenKey.isNanoLedger,
|
|
190
|
+
name: lastSeenKey.name,
|
|
191
|
+
pubKey: Buffer.from(lastSeenKey.pubKey, 'hex'),
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
const response = (yield this.sendCustomRequest({
|
|
195
|
+
id: payloadId(),
|
|
196
|
+
jsonrpc: '2.0',
|
|
197
|
+
method: 'keplr_get_key_wallet_connect_v1',
|
|
198
|
+
params: [chainId],
|
|
199
|
+
}))[0];
|
|
200
|
+
yield this.saveLastSeenKey(chainId, response);
|
|
201
|
+
return {
|
|
202
|
+
address: Buffer.from(response.address, 'hex'),
|
|
203
|
+
algo: response.algo,
|
|
204
|
+
bech32Address: response.bech32Address,
|
|
205
|
+
isKeystone: response.isKeystone,
|
|
206
|
+
isNanoLedger: response.isNanoLedger,
|
|
207
|
+
name: response.name,
|
|
208
|
+
pubKey: Buffer.from(response.pubKey, 'hex'),
|
|
209
|
+
};
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
getKeyLastSeenKey() {
|
|
213
|
+
return `${this.connector.session.handshakeTopic}-key`;
|
|
214
|
+
}
|
|
215
|
+
getLastSeenKey(chainId) {
|
|
216
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
217
|
+
const saved = yield this.getAllLastSeenKey();
|
|
218
|
+
if (!saved) {
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
return saved[chainId];
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
getAllLastSeenKey() {
|
|
225
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
226
|
+
return yield this.options.kvStore.get(this.getKeyLastSeenKey());
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
saveAllLastSeenKey(data) {
|
|
230
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
231
|
+
yield this.options.kvStore.set(this.getKeyLastSeenKey(), data);
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
saveLastSeenKey(chainId, response) {
|
|
235
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
236
|
+
let saved = yield this.getAllLastSeenKey();
|
|
237
|
+
if (!saved) {
|
|
238
|
+
saved = {};
|
|
239
|
+
}
|
|
240
|
+
saved[chainId] = response;
|
|
241
|
+
yield this.saveAllLastSeenKey(saved);
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
signArbitrary(_chainId, _signer, _data) {
|
|
245
|
+
throw new Error('Not yet implemented');
|
|
246
|
+
}
|
|
247
|
+
verifyArbitrary(_chainId, _signer, _data, _signature) {
|
|
248
|
+
throw new Error('Not yet implemented');
|
|
249
|
+
}
|
|
250
|
+
signEthereum(_chainId, _signer, _data, _mode) {
|
|
251
|
+
throw new Error('Not yet implemented');
|
|
252
|
+
}
|
|
253
|
+
signICNSAdr36(_chainId, _contractAddress, _owner, _username, _addressChainIds) {
|
|
254
|
+
throw new Error('Not yet implemented');
|
|
255
|
+
}
|
|
256
|
+
getOfflineSigner(chainId) {
|
|
257
|
+
return new CosmJSOfflineSigner(chainId, this);
|
|
258
|
+
}
|
|
259
|
+
getOfflineSignerAuto(chainId) {
|
|
260
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
261
|
+
const key = yield this.getKey(chainId);
|
|
262
|
+
if (key.isNanoLedger) {
|
|
263
|
+
return new CosmJSOfflineSignerOnlyAmino(chainId, this);
|
|
264
|
+
}
|
|
265
|
+
return new CosmJSOfflineSigner(chainId, this);
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
getOfflineSignerOnlyAmino(chainId) {
|
|
269
|
+
return new CosmJSOfflineSignerOnlyAmino(chainId, this);
|
|
270
|
+
}
|
|
271
|
+
getSecret20ViewingKey(_chainId, _contractAddress) {
|
|
272
|
+
throw new Error('Not yet implemented');
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* In the extension environment, this API let the extension to send the tx on behalf of the client.
|
|
276
|
+
* But, in the wallet connect environment, in order to send the tx on behalf of the client, wallet should receive the tx data from remote.
|
|
277
|
+
* However, this approach is not efficient and hard to ensure the stability and `KeplrWalletConnect` should have the informations of rpc and rest endpoints.
|
|
278
|
+
* So, rather than implementing this, just fallback to the client sided implementation or throw error of the client sided implementation is not delivered to the `options`.
|
|
279
|
+
* @param chainId
|
|
280
|
+
* @param stdTx
|
|
281
|
+
* @param mode
|
|
282
|
+
*/
|
|
283
|
+
sendTx(chainId, tx, mode) {
|
|
284
|
+
if (this.options.sendTx) {
|
|
285
|
+
return this.options.sendTx(chainId, tx, mode);
|
|
286
|
+
}
|
|
287
|
+
throw new Error('send tx is not delivered by options');
|
|
288
|
+
}
|
|
289
|
+
signAmino(chainId, signer, signDoc, signOptions = {}) {
|
|
290
|
+
var _a;
|
|
291
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
292
|
+
return (yield this.sendCustomRequest({
|
|
293
|
+
id: payloadId(),
|
|
294
|
+
jsonrpc: '2.0',
|
|
295
|
+
method: 'keplr_sign_amino_wallet_connect_v1',
|
|
296
|
+
params: [
|
|
297
|
+
chainId,
|
|
298
|
+
signer,
|
|
299
|
+
signDoc,
|
|
300
|
+
deepmerge((_a = this.defaultOptions.sign) !== null && _a !== void 0 ? _a : {}, signOptions),
|
|
301
|
+
],
|
|
302
|
+
}))[0];
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
signDirect(_chainId, _signer, _signDoc, _signOptions = {}) {
|
|
306
|
+
throw new Error('Not yet implemented');
|
|
307
|
+
}
|
|
308
|
+
suggestToken(_chainId, _contractAddress, _viewingKey) {
|
|
309
|
+
throw new Error('Not yet implemented');
|
|
310
|
+
}
|
|
311
|
+
experimentalSignEIP712CosmosTx_v0(_chainId, _signer, _eip712, _signDoc, _signOptions = {}) {
|
|
312
|
+
throw new Error('Not yet implemented');
|
|
313
|
+
}
|
|
314
|
+
getChainInfosWithoutEndpoints() {
|
|
315
|
+
throw new Error('Not yet implemented');
|
|
316
|
+
}
|
|
317
|
+
disable(_chainIds) {
|
|
318
|
+
throw new Error('Not yet implemented');
|
|
319
|
+
}
|
|
320
|
+
changeKeyRingName(_opts) {
|
|
321
|
+
throw new Error('Not yet implemented');
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export { KeplrWalletConnectV1 };
|