@wagmi/connectors 3.1.1-cjs → 4.0.0-alpha.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.
- package/dist/esm/coinbaseWallet.js +141 -0
- package/dist/esm/coinbaseWallet.js.map +1 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/index.test-d.js +4 -0
- package/dist/esm/index.test-d.js.map +1 -0
- package/dist/esm/injected.js +372 -0
- package/dist/esm/injected.js.map +1 -0
- package/dist/esm/ledger.js +162 -0
- package/dist/esm/ledger.js.map +1 -0
- package/dist/esm/safe.js +88 -0
- package/dist/esm/safe.js.map +1 -0
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -0
- package/dist/esm/version.js +2 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/esm/walletConnect.js +280 -0
- package/dist/esm/walletConnect.js.map +1 -0
- package/dist/types/coinbaseWallet.d.ts +21 -0
- package/dist/types/coinbaseWallet.d.ts.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.test-d.d.ts +2 -0
- package/dist/types/index.test-d.d.ts.map +1 -0
- package/dist/types/injected.d.ts +382 -0
- package/dist/types/injected.d.ts.map +1 -0
- package/dist/types/ledger.d.ts +18 -0
- package/dist/types/ledger.d.ts.map +1 -0
- package/dist/types/safe.d.ts +18 -0
- package/dist/types/safe.d.ts.map +1 -0
- package/dist/types/version.d.ts +2 -0
- package/dist/types/version.d.ts.map +1 -0
- package/dist/types/walletConnect.d.ts +63 -0
- package/dist/types/walletConnect.d.ts.map +1 -0
- package/package.json +44 -82
- package/src/coinbaseWallet.ts +207 -0
- package/src/index.ts +17 -0
- package/src/injected.ts +535 -0
- package/src/ledger.ts +210 -0
- package/src/safe.ts +114 -0
- package/src/version.ts +1 -0
- package/src/walletConnect.ts +394 -0
- package/README.md +0 -46
- package/coinbaseWallet/package.json +0 -4
- package/dist/base-70e3a8a9.d.ts +0 -142
- package/dist/chunk-2UFLHRLT.js +0 -391
- package/dist/chunk-OQILYQDO.js +0 -15
- package/dist/chunk-UGBGYVBH.js +0 -22
- package/dist/chunk-W65LBPLT.js +0 -58
- package/dist/coinbaseWallet.d.ts +0 -62
- package/dist/coinbaseWallet.js +0 -216
- package/dist/index.d.ts +0 -20
- package/dist/index.js +0 -16
- package/dist/injected.d.ts +0 -64
- package/dist/injected.js +0 -9
- package/dist/ledger.d.ts +0 -69
- package/dist/ledger.js +0 -261
- package/dist/metaMask.d.ts +0 -33
- package/dist/metaMask.js +0 -144
- package/dist/mock/index.d.ts +0 -80
- package/dist/mock/index.js +0 -200
- package/dist/safe.d.ts +0 -53
- package/dist/safe.js +0 -129
- package/dist/walletConnect.d.ts +0 -109
- package/dist/walletConnect.js +0 -325
- package/dist/walletConnectLegacy.d.ts +0 -38
- package/dist/walletConnectLegacy.js +0 -179
- package/injected/package.json +0 -4
- package/ledger/package.json +0 -4
- package/metaMask/package.json +0 -4
- package/mock/package.json +0 -4
- package/safe/package.json +0 -4
- package/walletConnect/package.json +0 -4
- package/walletConnectLegacy/package.json +0 -4
package/dist/metaMask.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
-
|
|
3
|
-
var _chunk2UFLHRLTjs = require('./chunk-2UFLHRLT.js');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var _chunkUGBGYVBHjs = require('./chunk-UGBGYVBH.js');
|
|
7
|
-
require('./chunk-OQILYQDO.js');
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var _chunkW65LBPLTjs = require('./chunk-W65LBPLT.js');
|
|
13
|
-
|
|
14
|
-
// src/metaMask.ts
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
var _viem = require('viem');
|
|
20
|
-
var _UNSTABLE_shimOnConnectSelectAccount;
|
|
21
|
-
var MetaMaskConnector = class extends _chunk2UFLHRLTjs.InjectedConnector {
|
|
22
|
-
constructor({
|
|
23
|
-
chains,
|
|
24
|
-
options: options_
|
|
25
|
-
} = {}) {
|
|
26
|
-
const options = {
|
|
27
|
-
name: "MetaMask",
|
|
28
|
-
shimDisconnect: true,
|
|
29
|
-
getProvider() {
|
|
30
|
-
function getReady(ethereum2) {
|
|
31
|
-
const isMetaMask = !!_optionalChain([ethereum2, 'optionalAccess', _ => _.isMetaMask]);
|
|
32
|
-
if (!isMetaMask)
|
|
33
|
-
return;
|
|
34
|
-
if (ethereum2.isBraveWallet && !ethereum2._events && !ethereum2._state)
|
|
35
|
-
return;
|
|
36
|
-
if (ethereum2.isApexWallet)
|
|
37
|
-
return;
|
|
38
|
-
if (ethereum2.isAvalanche)
|
|
39
|
-
return;
|
|
40
|
-
if (ethereum2.isBitKeep)
|
|
41
|
-
return;
|
|
42
|
-
if (ethereum2.isBlockWallet)
|
|
43
|
-
return;
|
|
44
|
-
if (ethereum2.isCoin98)
|
|
45
|
-
return;
|
|
46
|
-
if (ethereum2.isFordefi)
|
|
47
|
-
return;
|
|
48
|
-
if (ethereum2.isMathWallet)
|
|
49
|
-
return;
|
|
50
|
-
if (ethereum2.isOkxWallet || ethereum2.isOKExWallet)
|
|
51
|
-
return;
|
|
52
|
-
if (ethereum2.isOneInchIOSWallet || ethereum2.isOneInchAndroidWallet)
|
|
53
|
-
return;
|
|
54
|
-
if (ethereum2.isOpera)
|
|
55
|
-
return;
|
|
56
|
-
if (ethereum2.isPortal)
|
|
57
|
-
return;
|
|
58
|
-
if (ethereum2.isRabby)
|
|
59
|
-
return;
|
|
60
|
-
if (ethereum2.isDefiant)
|
|
61
|
-
return;
|
|
62
|
-
if (ethereum2.isTokenPocket)
|
|
63
|
-
return;
|
|
64
|
-
if (ethereum2.isTokenary)
|
|
65
|
-
return;
|
|
66
|
-
if (ethereum2.isZeal)
|
|
67
|
-
return;
|
|
68
|
-
if (ethereum2.isZerion)
|
|
69
|
-
return;
|
|
70
|
-
return ethereum2;
|
|
71
|
-
}
|
|
72
|
-
if (typeof window === "undefined")
|
|
73
|
-
return;
|
|
74
|
-
const ethereum = window.ethereum;
|
|
75
|
-
if (_optionalChain([ethereum, 'optionalAccess', _2 => _2.providers]))
|
|
76
|
-
return ethereum.providers.find(getReady);
|
|
77
|
-
return getReady(ethereum);
|
|
78
|
-
},
|
|
79
|
-
...options_
|
|
80
|
-
};
|
|
81
|
-
super({ chains, options });
|
|
82
|
-
this.id = "metaMask";
|
|
83
|
-
this.shimDisconnectKey = `${this.id}.shimDisconnect`;
|
|
84
|
-
_chunkW65LBPLTjs.__privateAdd.call(void 0, this, _UNSTABLE_shimOnConnectSelectAccount, void 0);
|
|
85
|
-
_chunkW65LBPLTjs.__privateSet.call(void 0, this, _UNSTABLE_shimOnConnectSelectAccount, options.UNSTABLE_shimOnConnectSelectAccount);
|
|
86
|
-
}
|
|
87
|
-
async connect({ chainId } = {}) {
|
|
88
|
-
try {
|
|
89
|
-
const provider = await this.getProvider();
|
|
90
|
-
if (!provider)
|
|
91
|
-
throw new (0, _chunkUGBGYVBHjs.ConnectorNotFoundError)();
|
|
92
|
-
if (provider.on) {
|
|
93
|
-
provider.on("accountsChanged", this.onAccountsChanged);
|
|
94
|
-
provider.on("chainChanged", this.onChainChanged);
|
|
95
|
-
provider.on("disconnect", this.onDisconnect);
|
|
96
|
-
}
|
|
97
|
-
this.emit("message", { type: "connecting" });
|
|
98
|
-
let account = null;
|
|
99
|
-
if (_chunkW65LBPLTjs.__privateGet.call(void 0, this, _UNSTABLE_shimOnConnectSelectAccount) && _optionalChain([this, 'access', _3 => _3.options, 'optionalAccess', _4 => _4.shimDisconnect]) && !_optionalChain([this, 'access', _5 => _5.storage, 'optionalAccess', _6 => _6.getItem, 'call', _7 => _7(this.shimDisconnectKey)])) {
|
|
100
|
-
account = await this.getAccount().catch(() => null);
|
|
101
|
-
const isConnected = !!account;
|
|
102
|
-
if (isConnected)
|
|
103
|
-
try {
|
|
104
|
-
await provider.request({
|
|
105
|
-
method: "wallet_requestPermissions",
|
|
106
|
-
params: [{ eth_accounts: {} }]
|
|
107
|
-
});
|
|
108
|
-
account = await this.getAccount();
|
|
109
|
-
} catch (error) {
|
|
110
|
-
if (this.isUserRejectedRequestError(error))
|
|
111
|
-
throw new (0, _viem.UserRejectedRequestError)(error);
|
|
112
|
-
if (error.code === new (0, _viem.ResourceUnavailableRpcError)(error).code)
|
|
113
|
-
throw error;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
if (!account) {
|
|
117
|
-
const accounts = await provider.request({
|
|
118
|
-
method: "eth_requestAccounts"
|
|
119
|
-
});
|
|
120
|
-
account = _viem.getAddress.call(void 0, accounts[0]);
|
|
121
|
-
}
|
|
122
|
-
let id = await this.getChainId();
|
|
123
|
-
let unsupported = this.isChainUnsupported(id);
|
|
124
|
-
if (chainId && id !== chainId) {
|
|
125
|
-
const chain = await this.switchChain(chainId);
|
|
126
|
-
id = chain.id;
|
|
127
|
-
unsupported = this.isChainUnsupported(id);
|
|
128
|
-
}
|
|
129
|
-
if (_optionalChain([this, 'access', _8 => _8.options, 'optionalAccess', _9 => _9.shimDisconnect]))
|
|
130
|
-
_optionalChain([this, 'access', _10 => _10.storage, 'optionalAccess', _11 => _11.setItem, 'call', _12 => _12(this.shimDisconnectKey, true)]);
|
|
131
|
-
return { account, chain: { id, unsupported }, provider };
|
|
132
|
-
} catch (error) {
|
|
133
|
-
if (this.isUserRejectedRequestError(error))
|
|
134
|
-
throw new (0, _viem.UserRejectedRequestError)(error);
|
|
135
|
-
if (error.code === -32002)
|
|
136
|
-
throw new (0, _viem.ResourceUnavailableRpcError)(error);
|
|
137
|
-
throw error;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
_UNSTABLE_shimOnConnectSelectAccount = new WeakMap();
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
exports.MetaMaskConnector = MetaMaskConnector;
|
package/dist/mock/index.d.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { Chain } from 'viem/chains';
|
|
2
|
-
import { c as WalletClient, C as Connector, a as ConnectorData } from '../base-70e3a8a9.js';
|
|
3
|
-
import EventEmitter from 'eventemitter3';
|
|
4
|
-
import 'viem';
|
|
5
|
-
|
|
6
|
-
type MockProviderOptions = {
|
|
7
|
-
chainId: number;
|
|
8
|
-
flags?: {
|
|
9
|
-
isAuthorized?: boolean;
|
|
10
|
-
failConnect?: boolean;
|
|
11
|
-
failSwitchChain?: boolean;
|
|
12
|
-
noSwitchChain?: boolean;
|
|
13
|
-
};
|
|
14
|
-
walletClient: WalletClient;
|
|
15
|
-
};
|
|
16
|
-
type Events = {
|
|
17
|
-
accountsChanged(accounts: string[]): void;
|
|
18
|
-
chainChanged(chainId: number | string): void;
|
|
19
|
-
disconnect(): void;
|
|
20
|
-
};
|
|
21
|
-
type Event = keyof Events;
|
|
22
|
-
declare class MockProvider {
|
|
23
|
-
#private;
|
|
24
|
-
events: EventEmitter<Events, any>;
|
|
25
|
-
chainId: number;
|
|
26
|
-
constructor(options: MockProviderOptions);
|
|
27
|
-
enable(): Promise<`0x${string}`[]>;
|
|
28
|
-
disconnect(): Promise<void>;
|
|
29
|
-
getAccounts(): Promise<`0x${string}`[]>;
|
|
30
|
-
getWalletClient(): WalletClient;
|
|
31
|
-
switchChain(chainId: number): Promise<void>;
|
|
32
|
-
switchWalletClient(walletClient: WalletClient): Promise<void>;
|
|
33
|
-
watchAsset(_asset: {
|
|
34
|
-
address: string;
|
|
35
|
-
decimals?: number;
|
|
36
|
-
image?: string;
|
|
37
|
-
symbol: string;
|
|
38
|
-
}): Promise<boolean>;
|
|
39
|
-
request({ method, params }: any): Promise<unknown>;
|
|
40
|
-
on(event: Event, listener: (...args: any[]) => void): this;
|
|
41
|
-
removeListener(event: Event, listener: (...args: any[]) => void): this;
|
|
42
|
-
toJSON(): string;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
type MockConnectorOptions = Omit<MockProviderOptions, 'chainId'> & {
|
|
46
|
-
chainId?: number;
|
|
47
|
-
};
|
|
48
|
-
declare class MockConnector extends Connector<MockProvider, MockConnectorOptions> {
|
|
49
|
-
#private;
|
|
50
|
-
readonly id = "mock";
|
|
51
|
-
readonly name = "Mock";
|
|
52
|
-
readonly ready = true;
|
|
53
|
-
constructor({ chains, options, }: {
|
|
54
|
-
chains?: Chain[];
|
|
55
|
-
options: MockConnectorOptions;
|
|
56
|
-
});
|
|
57
|
-
connect({ chainId }?: {
|
|
58
|
-
chainId?: number;
|
|
59
|
-
}): Promise<Required<ConnectorData>>;
|
|
60
|
-
disconnect(): Promise<void>;
|
|
61
|
-
getAccount(): Promise<`0x${string}`>;
|
|
62
|
-
getChainId(): Promise<number>;
|
|
63
|
-
getProvider({ chainId }?: {
|
|
64
|
-
chainId?: number;
|
|
65
|
-
}): Promise<MockProvider>;
|
|
66
|
-
getWalletClient(): Promise<WalletClient>;
|
|
67
|
-
isAuthorized(): Promise<boolean>;
|
|
68
|
-
watchAsset(asset: {
|
|
69
|
-
address: string;
|
|
70
|
-
decimals?: number;
|
|
71
|
-
image?: string;
|
|
72
|
-
symbol: string;
|
|
73
|
-
}): Promise<boolean>;
|
|
74
|
-
protected onAccountsChanged: (accounts: string[]) => void;
|
|
75
|
-
protected onChainChanged: (chainId: number | string) => void;
|
|
76
|
-
protected onDisconnect: () => void;
|
|
77
|
-
toJSON(): string;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export { MockConnector, MockProvider, MockProviderOptions };
|
package/dist/mock/index.js
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
-
|
|
3
|
-
var _chunkOQILYQDOjs = require('../chunk-OQILYQDO.js');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var _chunkW65LBPLTjs = require('../chunk-W65LBPLT.js');
|
|
11
|
-
|
|
12
|
-
// src/mock/connector.ts
|
|
13
|
-
var _viem = require('viem');
|
|
14
|
-
|
|
15
|
-
// src/mock/provider.ts
|
|
16
|
-
var _eventemitter3 = require('eventemitter3'); var _eventemitter32 = _interopRequireDefault(_eventemitter3);
|
|
17
|
-
|
|
18
|
-
var _options, _walletClient;
|
|
19
|
-
var MockProvider = class {
|
|
20
|
-
constructor(options) {
|
|
21
|
-
this.events = new (0, _eventemitter32.default)();
|
|
22
|
-
_chunkW65LBPLTjs.__privateAdd.call(void 0, this, _options, void 0);
|
|
23
|
-
_chunkW65LBPLTjs.__privateAdd.call(void 0, this, _walletClient, void 0);
|
|
24
|
-
this.chainId = options.chainId;
|
|
25
|
-
_chunkW65LBPLTjs.__privateSet.call(void 0, this, _options, options);
|
|
26
|
-
}
|
|
27
|
-
async enable() {
|
|
28
|
-
if (_optionalChain([_chunkW65LBPLTjs.__privateGet.call(void 0, this, _options), 'access', _ => _.flags, 'optionalAccess', _2 => _2.failConnect]))
|
|
29
|
-
throw new (0, _viem.UserRejectedRequestError)(new Error("Failed to connect."));
|
|
30
|
-
if (!_chunkW65LBPLTjs.__privateGet.call(void 0, this, _walletClient))
|
|
31
|
-
_chunkW65LBPLTjs.__privateSet.call(void 0, this, _walletClient, _chunkW65LBPLTjs.__privateGet.call(void 0, this, _options).walletClient);
|
|
32
|
-
const address = _chunkW65LBPLTjs.__privateGet.call(void 0, this, _walletClient).account.address;
|
|
33
|
-
this.events.emit("accountsChanged", [address]);
|
|
34
|
-
return [address];
|
|
35
|
-
}
|
|
36
|
-
async disconnect() {
|
|
37
|
-
this.events.emit("disconnect");
|
|
38
|
-
_chunkW65LBPLTjs.__privateSet.call(void 0, this, _walletClient, void 0);
|
|
39
|
-
}
|
|
40
|
-
async getAccounts() {
|
|
41
|
-
const address = _optionalChain([_chunkW65LBPLTjs.__privateGet.call(void 0, this, _walletClient), 'optionalAccess', _3 => _3.account, 'access', _4 => _4.address]);
|
|
42
|
-
if (!address)
|
|
43
|
-
return [];
|
|
44
|
-
return [_viem.getAddress.call(void 0, address)];
|
|
45
|
-
}
|
|
46
|
-
getWalletClient() {
|
|
47
|
-
const walletClient = _chunkW65LBPLTjs.__privateGet.call(void 0, this, _walletClient);
|
|
48
|
-
if (!walletClient)
|
|
49
|
-
throw new Error("walletClient not found");
|
|
50
|
-
return walletClient;
|
|
51
|
-
}
|
|
52
|
-
async switchChain(chainId) {
|
|
53
|
-
if (_optionalChain([_chunkW65LBPLTjs.__privateGet.call(void 0, this, _options), 'access', _5 => _5.flags, 'optionalAccess', _6 => _6.failSwitchChain]))
|
|
54
|
-
throw new (0, _viem.UserRejectedRequestError)(new Error("Failed to switch chain."));
|
|
55
|
-
_chunkW65LBPLTjs.__privateGet.call(void 0, this, _options).chainId = chainId;
|
|
56
|
-
this.chainId = chainId;
|
|
57
|
-
this.events.emit("chainChanged", chainId);
|
|
58
|
-
}
|
|
59
|
-
async switchWalletClient(walletClient) {
|
|
60
|
-
const address = walletClient.account.address;
|
|
61
|
-
_chunkW65LBPLTjs.__privateSet.call(void 0, this, _walletClient, walletClient);
|
|
62
|
-
this.events.emit("accountsChanged", [address]);
|
|
63
|
-
}
|
|
64
|
-
async watchAsset(_asset) {
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
|
-
async request({ method, params }) {
|
|
68
|
-
return _optionalChain([_chunkW65LBPLTjs.__privateGet.call(void 0, this, _walletClient), 'optionalAccess', _7 => _7.transport, 'access', _8 => _8.request, 'call', _9 => _9({ method, params })]);
|
|
69
|
-
}
|
|
70
|
-
on(event, listener) {
|
|
71
|
-
this.events.on(event, listener);
|
|
72
|
-
return this;
|
|
73
|
-
}
|
|
74
|
-
removeListener(event, listener) {
|
|
75
|
-
this.events.removeListener(event, listener);
|
|
76
|
-
return this;
|
|
77
|
-
}
|
|
78
|
-
toJSON() {
|
|
79
|
-
return "<MockProvider>";
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
_options = new WeakMap();
|
|
83
|
-
_walletClient = new WeakMap();
|
|
84
|
-
|
|
85
|
-
// src/mock/connector.ts
|
|
86
|
-
var _provider, _switchChain, switchChain_fn;
|
|
87
|
-
var MockConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
88
|
-
constructor({
|
|
89
|
-
chains,
|
|
90
|
-
options
|
|
91
|
-
}) {
|
|
92
|
-
super({
|
|
93
|
-
chains,
|
|
94
|
-
options: {
|
|
95
|
-
...options,
|
|
96
|
-
chainId: _nullishCoalesce(options.chainId, () => ( _optionalChain([chains, 'optionalAccess', _10 => _10[0], 'optionalAccess', _11 => _11.id])))
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
_chunkW65LBPLTjs.__privateAdd.call(void 0, this, _switchChain);
|
|
100
|
-
this.id = "mock";
|
|
101
|
-
this.name = "Mock";
|
|
102
|
-
this.ready = true;
|
|
103
|
-
_chunkW65LBPLTjs.__privateAdd.call(void 0, this, _provider, void 0);
|
|
104
|
-
this.onAccountsChanged = (accounts) => {
|
|
105
|
-
if (accounts.length === 0)
|
|
106
|
-
this.emit("disconnect");
|
|
107
|
-
else
|
|
108
|
-
this.emit("change", { account: _viem.getAddress.call(void 0, accounts[0]) });
|
|
109
|
-
};
|
|
110
|
-
this.onChainChanged = (chainId) => {
|
|
111
|
-
const id = _chunkOQILYQDOjs.normalizeChainId.call(void 0, chainId);
|
|
112
|
-
const unsupported = this.isChainUnsupported(id);
|
|
113
|
-
this.emit("change", { chain: { id, unsupported } });
|
|
114
|
-
};
|
|
115
|
-
this.onDisconnect = () => {
|
|
116
|
-
this.emit("disconnect");
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
async connect({ chainId } = {}) {
|
|
120
|
-
const provider = await this.getProvider({ chainId });
|
|
121
|
-
provider.on("accountsChanged", this.onAccountsChanged);
|
|
122
|
-
provider.on("chainChanged", this.onChainChanged);
|
|
123
|
-
provider.on("disconnect", this.onDisconnect);
|
|
124
|
-
this.emit("message", { type: "connecting" });
|
|
125
|
-
const accounts = await provider.enable();
|
|
126
|
-
const account = _viem.getAddress.call(void 0, accounts[0]);
|
|
127
|
-
const id = _chunkOQILYQDOjs.normalizeChainId.call(void 0, provider.chainId);
|
|
128
|
-
const unsupported = this.isChainUnsupported(id);
|
|
129
|
-
const data = { account, chain: { id, unsupported }, provider };
|
|
130
|
-
if (!_optionalChain([this, 'access', _12 => _12.options, 'access', _13 => _13.flags, 'optionalAccess', _14 => _14.noSwitchChain]))
|
|
131
|
-
this.switchChain = _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _switchChain, switchChain_fn);
|
|
132
|
-
return new Promise(
|
|
133
|
-
(res) => setTimeout(() => res(data), 100)
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
async disconnect() {
|
|
137
|
-
const provider = await this.getProvider();
|
|
138
|
-
await provider.disconnect();
|
|
139
|
-
provider.removeListener("accountsChanged", this.onAccountsChanged);
|
|
140
|
-
provider.removeListener("chainChanged", this.onChainChanged);
|
|
141
|
-
provider.removeListener("disconnect", this.onDisconnect);
|
|
142
|
-
}
|
|
143
|
-
async getAccount() {
|
|
144
|
-
const provider = await this.getProvider();
|
|
145
|
-
const accounts = await provider.getAccounts();
|
|
146
|
-
const account = accounts[0];
|
|
147
|
-
if (!account)
|
|
148
|
-
throw new Error("Failed to get account");
|
|
149
|
-
return _viem.getAddress.call(void 0, account);
|
|
150
|
-
}
|
|
151
|
-
async getChainId() {
|
|
152
|
-
const provider = await this.getProvider();
|
|
153
|
-
return _chunkOQILYQDOjs.normalizeChainId.call(void 0, provider.chainId);
|
|
154
|
-
}
|
|
155
|
-
async getProvider({ chainId } = {}) {
|
|
156
|
-
if (!_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider) || chainId)
|
|
157
|
-
_chunkW65LBPLTjs.__privateSet.call(void 0, this, _provider, new MockProvider({
|
|
158
|
-
...this.options,
|
|
159
|
-
chainId: _nullishCoalesce(_nullishCoalesce(chainId, () => ( this.options.chainId)), () => ( this.chains[0].id))
|
|
160
|
-
}));
|
|
161
|
-
return _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider);
|
|
162
|
-
}
|
|
163
|
-
async getWalletClient() {
|
|
164
|
-
const provider = await this.getProvider();
|
|
165
|
-
return provider.getWalletClient();
|
|
166
|
-
}
|
|
167
|
-
async isAuthorized() {
|
|
168
|
-
try {
|
|
169
|
-
const provider = await this.getProvider();
|
|
170
|
-
const account = await provider.getAccounts();
|
|
171
|
-
return _nullishCoalesce(_optionalChain([this, 'access', _15 => _15.options, 'access', _16 => _16.flags, 'optionalAccess', _17 => _17.isAuthorized]), () => ( !!account));
|
|
172
|
-
} catch (e) {
|
|
173
|
-
return false;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
async watchAsset(asset) {
|
|
177
|
-
const provider = await this.getProvider();
|
|
178
|
-
return provider.watchAsset(asset);
|
|
179
|
-
}
|
|
180
|
-
toJSON() {
|
|
181
|
-
return "<MockConnector>";
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
_provider = new WeakMap();
|
|
185
|
-
_switchChain = new WeakSet();
|
|
186
|
-
switchChain_fn = async function(chainId) {
|
|
187
|
-
const provider = await this.getProvider();
|
|
188
|
-
await provider.switchChain(chainId);
|
|
189
|
-
return _nullishCoalesce(this.chains.find((x) => x.id === chainId), () => ( {
|
|
190
|
-
id: chainId,
|
|
191
|
-
name: `Chain ${chainId}`,
|
|
192
|
-
network: `${chainId}`,
|
|
193
|
-
nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
|
|
194
|
-
rpcUrls: { default: { http: [""] }, public: { http: [""] } }
|
|
195
|
-
}));
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
exports.MockConnector = MockConnector; exports.MockProvider = MockProvider;
|
package/dist/safe.d.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { SafeAppProvider } from '@safe-global/safe-apps-provider';
|
|
2
|
-
import { Opts } from '@safe-global/safe-apps-sdk';
|
|
3
|
-
import { Chain } from 'viem/chains';
|
|
4
|
-
import { C as Connector, c as WalletClient } from './base-70e3a8a9.js';
|
|
5
|
-
import 'eventemitter3';
|
|
6
|
-
import 'viem';
|
|
7
|
-
|
|
8
|
-
type SafeConnectorProvider = SafeAppProvider;
|
|
9
|
-
type SafeConnectorOptions = Opts & {
|
|
10
|
-
/**
|
|
11
|
-
* Connector automatically connects when used as Safe App.
|
|
12
|
-
*
|
|
13
|
-
* This flag simulates the disconnect behavior by keeping track of connection status in storage
|
|
14
|
-
* and only autoconnecting when previously connected by user action (e.g. explicitly choosing to connect).
|
|
15
|
-
*
|
|
16
|
-
* @default false
|
|
17
|
-
*/
|
|
18
|
-
shimDisconnect?: boolean;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Connector for [Safe Wallet](https://safe.global)
|
|
22
|
-
*/
|
|
23
|
-
declare class SafeConnector extends Connector<SafeConnectorProvider, SafeConnectorOptions> {
|
|
24
|
-
#private;
|
|
25
|
-
readonly id = "safe";
|
|
26
|
-
readonly name = "Safe";
|
|
27
|
-
ready: boolean;
|
|
28
|
-
protected shimDisconnectKey: string;
|
|
29
|
-
constructor({ chains, options: options_, }: {
|
|
30
|
-
chains?: Chain[];
|
|
31
|
-
options?: SafeConnectorOptions;
|
|
32
|
-
});
|
|
33
|
-
connect(): Promise<{
|
|
34
|
-
account: `0x${string}`;
|
|
35
|
-
chain: {
|
|
36
|
-
id: number;
|
|
37
|
-
unsupported: boolean;
|
|
38
|
-
};
|
|
39
|
-
}>;
|
|
40
|
-
disconnect(): Promise<void>;
|
|
41
|
-
getAccount(): Promise<`0x${string}`>;
|
|
42
|
-
getChainId(): Promise<number>;
|
|
43
|
-
getProvider(): Promise<SafeAppProvider>;
|
|
44
|
-
getWalletClient({ chainId, }?: {
|
|
45
|
-
chainId?: number;
|
|
46
|
-
}): Promise<WalletClient>;
|
|
47
|
-
isAuthorized(): Promise<boolean>;
|
|
48
|
-
protected onAccountsChanged(_accounts: string[]): void;
|
|
49
|
-
protected onChainChanged(_chainId: string | number): void;
|
|
50
|
-
protected onDisconnect(): void;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export { SafeConnector, SafeConnectorOptions, SafeConnectorProvider };
|
package/dist/safe.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
-
|
|
3
|
-
var _chunkUGBGYVBHjs = require('./chunk-UGBGYVBH.js');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var _chunkOQILYQDOjs = require('./chunk-OQILYQDO.js');
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var _chunkW65LBPLTjs = require('./chunk-W65LBPLT.js');
|
|
13
|
-
|
|
14
|
-
// src/safe.ts
|
|
15
|
-
var _safeappsprovider = require('@safe-global/safe-apps-provider');
|
|
16
|
-
var _safeappssdk = require('@safe-global/safe-apps-sdk'); var _safeappssdk2 = _interopRequireDefault(_safeappssdk);
|
|
17
|
-
var _viem = require('viem');
|
|
18
|
-
var _provider, _sdk;
|
|
19
|
-
var SafeConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
20
|
-
constructor({
|
|
21
|
-
chains,
|
|
22
|
-
options: options_
|
|
23
|
-
}) {
|
|
24
|
-
const options = {
|
|
25
|
-
shimDisconnect: false,
|
|
26
|
-
...options_
|
|
27
|
-
};
|
|
28
|
-
super({ chains, options });
|
|
29
|
-
this.id = "safe";
|
|
30
|
-
this.name = "Safe";
|
|
31
|
-
this.ready = !(typeof window === "undefined") && _optionalChain([window, 'optionalAccess', _ => _.parent]) !== window;
|
|
32
|
-
_chunkW65LBPLTjs.__privateAdd.call(void 0, this, _provider, void 0);
|
|
33
|
-
_chunkW65LBPLTjs.__privateAdd.call(void 0, this, _sdk, void 0);
|
|
34
|
-
this.shimDisconnectKey = `${this.id}.shimDisconnect`;
|
|
35
|
-
let SDK = _safeappssdk2.default;
|
|
36
|
-
if (typeof _safeappssdk2.default !== "function" && typeof _safeappssdk2.default.default === "function")
|
|
37
|
-
SDK = _safeappssdk2.default.default;
|
|
38
|
-
_chunkW65LBPLTjs.__privateSet.call(void 0, this, _sdk, new SDK(options));
|
|
39
|
-
}
|
|
40
|
-
async connect() {
|
|
41
|
-
const provider = await this.getProvider();
|
|
42
|
-
if (!provider)
|
|
43
|
-
throw new (0, _chunkUGBGYVBHjs.ConnectorNotFoundError)();
|
|
44
|
-
if (provider.on) {
|
|
45
|
-
provider.on("accountsChanged", this.onAccountsChanged);
|
|
46
|
-
provider.on("chainChanged", this.onChainChanged);
|
|
47
|
-
provider.on("disconnect", this.onDisconnect);
|
|
48
|
-
}
|
|
49
|
-
this.emit("message", { type: "connecting" });
|
|
50
|
-
const account = await this.getAccount();
|
|
51
|
-
const id = await this.getChainId();
|
|
52
|
-
if (this.options.shimDisconnect)
|
|
53
|
-
_optionalChain([this, 'access', _2 => _2.storage, 'optionalAccess', _3 => _3.setItem, 'call', _4 => _4(this.shimDisconnectKey, true)]);
|
|
54
|
-
return {
|
|
55
|
-
account,
|
|
56
|
-
chain: { id, unsupported: this.isChainUnsupported(id) }
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
async disconnect() {
|
|
60
|
-
const provider = await this.getProvider();
|
|
61
|
-
if (!_optionalChain([provider, 'optionalAccess', _5 => _5.removeListener]))
|
|
62
|
-
return;
|
|
63
|
-
provider.removeListener("accountsChanged", this.onAccountsChanged);
|
|
64
|
-
provider.removeListener("chainChanged", this.onChainChanged);
|
|
65
|
-
provider.removeListener("disconnect", this.onDisconnect);
|
|
66
|
-
if (this.options.shimDisconnect)
|
|
67
|
-
_optionalChain([this, 'access', _6 => _6.storage, 'optionalAccess', _7 => _7.removeItem, 'call', _8 => _8(this.shimDisconnectKey)]);
|
|
68
|
-
}
|
|
69
|
-
async getAccount() {
|
|
70
|
-
const provider = await this.getProvider();
|
|
71
|
-
if (!provider)
|
|
72
|
-
throw new (0, _chunkUGBGYVBHjs.ConnectorNotFoundError)();
|
|
73
|
-
const accounts = await provider.request({
|
|
74
|
-
method: "eth_accounts"
|
|
75
|
-
});
|
|
76
|
-
return _viem.getAddress.call(void 0, accounts[0]);
|
|
77
|
-
}
|
|
78
|
-
async getChainId() {
|
|
79
|
-
const provider = await this.getProvider();
|
|
80
|
-
if (!provider)
|
|
81
|
-
throw new (0, _chunkUGBGYVBHjs.ConnectorNotFoundError)();
|
|
82
|
-
return _chunkOQILYQDOjs.normalizeChainId.call(void 0, provider.chainId);
|
|
83
|
-
}
|
|
84
|
-
async getProvider() {
|
|
85
|
-
if (!_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider)) {
|
|
86
|
-
const safe = await _chunkW65LBPLTjs.__privateGet.call(void 0, this, _sdk).safe.getInfo();
|
|
87
|
-
if (!safe)
|
|
88
|
-
throw new Error("Could not load Safe information");
|
|
89
|
-
_chunkW65LBPLTjs.__privateSet.call(void 0, this, _provider, new (0, _safeappsprovider.SafeAppProvider)(safe, _chunkW65LBPLTjs.__privateGet.call(void 0, this, _sdk)));
|
|
90
|
-
}
|
|
91
|
-
return _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider);
|
|
92
|
-
}
|
|
93
|
-
async getWalletClient({
|
|
94
|
-
chainId
|
|
95
|
-
} = {}) {
|
|
96
|
-
const provider = await this.getProvider();
|
|
97
|
-
const account = await this.getAccount();
|
|
98
|
-
const chain = this.chains.find((x) => x.id === chainId);
|
|
99
|
-
if (!provider)
|
|
100
|
-
throw new Error("provider is required.");
|
|
101
|
-
return _viem.createWalletClient.call(void 0, {
|
|
102
|
-
account,
|
|
103
|
-
chain,
|
|
104
|
-
transport: _viem.custom.call(void 0, provider)
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
async isAuthorized() {
|
|
108
|
-
try {
|
|
109
|
-
if (this.options.shimDisconnect && !_optionalChain([this, 'access', _9 => _9.storage, 'optionalAccess', _10 => _10.getItem, 'call', _11 => _11(this.shimDisconnectKey)]))
|
|
110
|
-
return false;
|
|
111
|
-
const account = await this.getAccount();
|
|
112
|
-
return !!account;
|
|
113
|
-
} catch (e) {
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
onAccountsChanged(_accounts) {
|
|
118
|
-
}
|
|
119
|
-
onChainChanged(_chainId) {
|
|
120
|
-
}
|
|
121
|
-
onDisconnect() {
|
|
122
|
-
this.emit("disconnect");
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
_provider = new WeakMap();
|
|
126
|
-
_sdk = new WeakMap();
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
exports.SafeConnector = SafeConnector;
|