@dynamic-labs/starknet 4.0.0-alpha.9 → 4.0.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/CHANGELOG.md +483 -1
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +14 -12
- package/src/StarknetWalletConnector.cjs +232 -0
- package/src/StarknetWalletConnector.d.ts +58 -0
- package/src/StarknetWalletConnector.js +228 -0
- package/src/index.cjs +14 -12
- package/src/index.d.ts +16 -7
- package/src/index.js +12 -12
- package/src/types.d.ts +26 -11
- package/src/utils/convertors.cjs +1 -1
- package/src/utils/convertors.d.ts +1 -1
- package/src/utils/convertors.js +1 -1
- package/src/wallet/StarknetWallet.cjs +24 -3
- package/src/wallet/StarknetWallet.d.ts +14 -4
- package/src/wallet/StarknetWallet.js +24 -3
- package/src/wallets/argent/argentMobile/argentMobile.cjs +70 -0
- package/src/wallets/argent/argentMobile/argentMobile.d.ts +16 -0
- package/src/wallets/argent/argentMobile/argentMobile.js +66 -0
- package/src/wallets/argent/base.cjs +50 -0
- package/src/wallets/argent/base.d.ts +5 -0
- package/src/wallets/argent/base.js +46 -0
- package/src/wallets/argent/injected/argentx.cjs +33 -0
- package/src/wallets/argent/injected/argentx.d.ts +8 -0
- package/src/wallets/argent/injected/argentx.js +29 -0
- package/src/wallets/argent/webwallet/webwallet.cjs +37 -0
- package/src/wallets/argent/webwallet/webwallet.d.ts +10 -0
- package/src/wallets/argent/webwallet/webwallet.js +33 -0
- package/src/wallets/injected/braavos.cjs +31 -0
- package/src/wallets/injected/braavos.d.ts +13 -0
- package/src/wallets/injected/braavos.js +27 -0
- package/src/wallets/injected/fetchStarknetInjectedWalletConnectors.cjs +35 -0
- package/src/wallets/injected/fetchStarknetInjectedWalletConnectors.d.ts +5 -0
- package/src/wallets/injected/fetchStarknetInjectedWalletConnectors.js +31 -0
- package/src/wallets/injected/injected.cjs +141 -0
- package/src/wallets/injected/injected.d.ts +10 -0
- package/src/wallets/injected/injected.js +137 -0
- package/src/wallets/{metamask.cjs → injected/metamask.cjs} +19 -29
- package/src/wallets/{metamask.d.ts → injected/metamask.d.ts} +2 -4
- package/src/wallets/{metamask.js → injected/metamask.js} +15 -29
- package/src/starknetWalletConnector.cjs +0 -320
- package/src/starknetWalletConnector.d.ts +0 -127
- package/src/starknetWalletConnector.js +0 -314
- package/src/utils/starknetSnap.cjs +0 -92
- package/src/utils/starknetSnap.d.ts +0 -8
- package/src/utils/starknetSnap.js +0 -88
- package/src/wallets/argentx.cjs +0 -24
- package/src/wallets/argentx.d.ts +0 -8
- package/src/wallets/argentx.js +0 -20
- package/src/wallets/argentxBase.cjs +0 -50
- package/src/wallets/argentxBase.d.ts +0 -16
- package/src/wallets/argentxBase.js +0 -48
- package/src/wallets/argentxMobile.cjs +0 -100
- package/src/wallets/argentxMobile.d.ts +0 -13
- package/src/wallets/argentxMobile.js +0 -96
- package/src/wallets/argentxWeb.cjs +0 -57
- package/src/wallets/argentxWeb.d.ts +0 -8
- package/src/wallets/argentxWeb.js +0 -53
- package/src/wallets/bitget.cjs +0 -22
- package/src/wallets/bitget.d.ts +0 -7
- package/src/wallets/bitget.js +0 -18
- package/src/wallets/braavos.cjs +0 -37
- package/src/wallets/braavos.d.ts +0 -8
- package/src/wallets/braavos.js +0 -33
- package/src/wallets/okx.cjs +0 -15
- package/src/wallets/okx.d.ts +0 -6
- package/src/wallets/okx.js +0 -11
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
-
|
|
6
|
-
var _tslib = require('../_virtual/_tslib.cjs');
|
|
7
|
-
var getStarknetCore = require('get-starknet-core');
|
|
8
|
-
var starknet = require('starknet');
|
|
9
|
-
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
10
|
-
var utils = require('@dynamic-labs/utils');
|
|
11
|
-
var constants = require('./constants.cjs');
|
|
12
|
-
var ethereumContractAbi = require('./ethereumContractAbi.cjs');
|
|
13
|
-
var convertors = require('./utils/convertors.cjs');
|
|
14
|
-
var StarknetWallet = require('./wallet/StarknetWallet.cjs');
|
|
15
|
-
|
|
16
|
-
const ACCOUNT_CHANGED_EVENT_LISTENER = 'accountsChanged';
|
|
17
|
-
const NETWORK_CHANGED_EVENT_LISTENER = 'networkChanged';
|
|
18
|
-
class StarknetWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
19
|
-
constructor(name, windowKey, opts) {
|
|
20
|
-
var _a;
|
|
21
|
-
super(opts);
|
|
22
|
-
this.STARKNET_VERSION = 'v5';
|
|
23
|
-
this.ChainWallet = StarknetWallet.StarknetWallet;
|
|
24
|
-
this.connectedChain = 'STARK';
|
|
25
|
-
this.supportedChains = ['STARK'];
|
|
26
|
-
this.switchNetworkOnlyFromWallet = true;
|
|
27
|
-
// required for metamask snap integration as MM snaps don't have event listeners
|
|
28
|
-
this.canSetEventListeners = true;
|
|
29
|
-
this.name = name;
|
|
30
|
-
this.windowKey = windowKey;
|
|
31
|
-
this.starknetNetworks = opts.starknetNetworks;
|
|
32
|
-
this.chainRpcProviders = opts.chainRpcProviders;
|
|
33
|
-
(_a = this.chainRpcProviders) === null || _a === void 0 ? void 0 : _a.registerStarknetProviders();
|
|
34
|
-
}
|
|
35
|
-
get walletBookWallet() {
|
|
36
|
-
return this.walletBook.wallets[this.key];
|
|
37
|
-
}
|
|
38
|
-
// abstracting this method to a function due to some wallets (bitget)
|
|
39
|
-
// having non-standard use of the isConnected flag. This allows for us to use other flags to determine connectivity
|
|
40
|
-
isProviderConnected() {
|
|
41
|
-
var _a;
|
|
42
|
-
const wallet = this.getWallet();
|
|
43
|
-
return (_a = wallet === null || wallet === void 0 ? void 0 : wallet.isConnected) !== null && _a !== void 0 ? _a : false;
|
|
44
|
-
}
|
|
45
|
-
getPublicClient() {
|
|
46
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
var _a;
|
|
48
|
-
if (this.starknetNetworks === undefined ||
|
|
49
|
-
this.starknetNetworks.length === 0)
|
|
50
|
-
return;
|
|
51
|
-
const configurations = {
|
|
52
|
-
cosmos: [],
|
|
53
|
-
evm: undefined,
|
|
54
|
-
solana: undefined,
|
|
55
|
-
starknet: this.starknetNetworks,
|
|
56
|
-
};
|
|
57
|
-
const chainId = yield this.getNetwork();
|
|
58
|
-
const starknetRpcProvider = (_a = this.chainRpcProviders) === null || _a === void 0 ? void 0 : _a.getStarknetRpcProviderByChainId(configurations, chainId);
|
|
59
|
-
return starknetRpcProvider === null || starknetRpcProvider === void 0 ? void 0 : starknetRpcProvider.provider;
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* returns starknet wallet network id
|
|
64
|
-
*/
|
|
65
|
-
getNetwork() {
|
|
66
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
var _a;
|
|
68
|
-
const wallet = this.getWallet();
|
|
69
|
-
if (!wallet) {
|
|
70
|
-
return Promise.resolve(undefined);
|
|
71
|
-
}
|
|
72
|
-
if (!this.isProviderConnected()) {
|
|
73
|
-
yield wallet.enable({ starknetVersion: this.STARKNET_VERSION });
|
|
74
|
-
}
|
|
75
|
-
return Promise.resolve((_a = wallet.provider) === null || _a === void 0 ? void 0 : _a.getChainId());
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
connect() {
|
|
79
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
80
|
-
const wallet = this.getWallet();
|
|
81
|
-
try {
|
|
82
|
-
if (wallet && !this.isProviderConnected()) {
|
|
83
|
-
yield wallet.enable({ starknetVersion: this.STARKNET_VERSION });
|
|
84
|
-
localStorage.setItem('dynamic_should_have_wallet', 'true');
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
catch (err) {
|
|
88
|
-
walletConnectorCore.logger.error(err);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
getAddress() {
|
|
93
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
const wallet = this.getWallet();
|
|
95
|
-
if (!this.isInstalledOnBrowser() &&
|
|
96
|
-
utils.isMobile() &&
|
|
97
|
-
this.walletBookWallet.mobile &&
|
|
98
|
-
this.walletBookWallet.mobile.inAppBrowser &&
|
|
99
|
-
this.mobileExperience === 'in-app-browser') {
|
|
100
|
-
const inAppBrowserCompiledTemplate = utils.template(this.walletBookWallet.mobile.inAppBrowser);
|
|
101
|
-
const deepLink = inAppBrowserCompiledTemplate({
|
|
102
|
-
encodedDappURI: encodeURIComponent(window.location.toString()),
|
|
103
|
-
});
|
|
104
|
-
window.location.assign(deepLink);
|
|
105
|
-
}
|
|
106
|
-
if (wallet && !this.isProviderConnected()) {
|
|
107
|
-
yield (wallet === null || wallet === void 0 ? void 0 : wallet.isPreauthorized());
|
|
108
|
-
yield this.connect();
|
|
109
|
-
}
|
|
110
|
-
return Promise.resolve(wallet === null || wallet === void 0 ? void 0 : wallet.selectedAddress);
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
getWalletAccount() {
|
|
114
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
115
|
-
const wallet = this.getWallet();
|
|
116
|
-
return wallet === null || wallet === void 0 ? void 0 : wallet.account;
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
getProvider() {
|
|
120
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
121
|
-
const wallet = yield this.getWallet();
|
|
122
|
-
return wallet === null || wallet === void 0 ? void 0 : wallet.provider;
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
signMessage(messageToSign) {
|
|
126
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
127
|
-
// FetchPublicAddress also handles the connection to the wallet this is why we call it before getWallet.
|
|
128
|
-
const walletAddress = yield this.getAddress();
|
|
129
|
-
const wallet = this.getWallet();
|
|
130
|
-
if (!walletAddress || !wallet) {
|
|
131
|
-
walletConnectorCore.logger.error('Could not fetch wallet address for signing message');
|
|
132
|
-
return undefined;
|
|
133
|
-
}
|
|
134
|
-
const encodedMessage = convertors.formatTypedDataMessage(messageToSign, (yield wallet.provider.getChainId()));
|
|
135
|
-
const signature = yield wallet.account.signMessage(encodedMessage);
|
|
136
|
-
return signature === null || signature === void 0 ? void 0 : signature.join(',');
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
getBalance(address) {
|
|
140
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
141
|
-
const provider = yield this.getProvider();
|
|
142
|
-
if (!provider) {
|
|
143
|
-
walletConnectorCore.logger.error('Could not find provider for getting balance');
|
|
144
|
-
return undefined;
|
|
145
|
-
}
|
|
146
|
-
const contract = new starknet.Contract(ethereumContractAbi, constants.ETH_STARKNET_ADDRESS, provider);
|
|
147
|
-
try {
|
|
148
|
-
const { balance } = yield contract.balanceOf(address);
|
|
149
|
-
/**
|
|
150
|
-
* Dividing by 1e18 as the returned balance is a Gwei number.
|
|
151
|
-
* Read more here: https://www.investopedia.com/terms/g/gwei-ethereum.asp#toc-what-is-gwei
|
|
152
|
-
*/
|
|
153
|
-
return (Number(starknet.cairo.uint256(balance.low).low) / 1e18).toFixed(6);
|
|
154
|
-
}
|
|
155
|
-
catch (error) {
|
|
156
|
-
walletConnectorCore.logger.error(error);
|
|
157
|
-
throw new utils.DynamicError('Something went wrong');
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
endSession() {
|
|
162
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
163
|
-
localStorage.removeItem('dynamic_should_have_wallet');
|
|
164
|
-
getStarknetCore.getStarknet().disconnect({ clearLastWallet: true });
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
getWallet() {
|
|
168
|
-
let starknetWindowInstance = window[`starknet_${this.windowKey}`];
|
|
169
|
-
if (starknetWindowInstance !== undefined) {
|
|
170
|
-
return starknetWindowInstance;
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
starknetWindowInstance = window['starknet'];
|
|
174
|
-
if ((starknetWindowInstance === null || starknetWindowInstance === void 0 ? void 0 : starknetWindowInstance.name) === this.name) {
|
|
175
|
-
return starknetWindowInstance;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return undefined;
|
|
179
|
-
}
|
|
180
|
-
isInstalledOnBrowser() {
|
|
181
|
-
return this.getWallet() !== undefined;
|
|
182
|
-
}
|
|
183
|
-
getConnectedAccounts() {
|
|
184
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
185
|
-
const wallet = this.getWallet();
|
|
186
|
-
if (!wallet) {
|
|
187
|
-
return [];
|
|
188
|
-
}
|
|
189
|
-
try {
|
|
190
|
-
yield this.reconnectIfNeeded(wallet);
|
|
191
|
-
}
|
|
192
|
-
catch (e) {
|
|
193
|
-
return [];
|
|
194
|
-
}
|
|
195
|
-
const getSelectedAddress = () => wallet.selectedAddress
|
|
196
|
-
? Promise.resolve([wallet.selectedAddress])
|
|
197
|
-
: Promise.reject();
|
|
198
|
-
return utils.retryableFn(getSelectedAddress, {
|
|
199
|
-
fallbackValue: [],
|
|
200
|
-
retryIntervalMs: 100,
|
|
201
|
-
retryStrategy: 'timeout-and-rejection',
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
reconnectIfNeeded(wallet) {
|
|
206
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
207
|
-
const needsReconnection = !this.isProviderConnected() && (yield wallet.isPreauthorized());
|
|
208
|
-
if (needsReconnection) {
|
|
209
|
-
/**
|
|
210
|
-
* this is a hack for braavos
|
|
211
|
-
* it is needed because the wallet doesn't return any addresses or connected state
|
|
212
|
-
* without a reconnection, and when the wallet is locked, the connect call never resolves
|
|
213
|
-
*/
|
|
214
|
-
if (localStorage.getItem('dynamic_should_have_wallet') === 'true') {
|
|
215
|
-
try {
|
|
216
|
-
yield utils.retryableFn(this.connect.bind(this), {
|
|
217
|
-
maxRetries: 0,
|
|
218
|
-
retryStrategy: 'timeout-only',
|
|
219
|
-
timeoutMs: 1000,
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
catch (_a) {
|
|
223
|
-
localStorage.removeItem('dynamic_should_have_wallet');
|
|
224
|
-
throw new Error('Could not reconnect');
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
228
|
-
yield this.connect();
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
setupEventListeners() {
|
|
234
|
-
if (!this.canSetEventListeners)
|
|
235
|
-
return;
|
|
236
|
-
const wallet = this.getWallet();
|
|
237
|
-
if (!wallet) {
|
|
238
|
-
return walletConnectorCore.logger.error('Wallet has not been found');
|
|
239
|
-
}
|
|
240
|
-
this.handleAccountChange = (address) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
241
|
-
if (!address) {
|
|
242
|
-
this.emit('disconnect');
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
if (address.toString()) {
|
|
246
|
-
this.emit('accountChange', { accounts: [address.toString()] });
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
this.handleNetworkChange = (network) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
250
|
-
if (!network) {
|
|
251
|
-
this.emit('disconnect');
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
const chain = this.mapNetworkNameToChainId(network.toString());
|
|
255
|
-
if (chain) {
|
|
256
|
-
this.emit('chainChange', { chain });
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
wallet === null || wallet === void 0 ? void 0 : wallet.on(ACCOUNT_CHANGED_EVENT_LISTENER, this.handleAccountChange);
|
|
260
|
-
wallet === null || wallet === void 0 ? void 0 : wallet.on(NETWORK_CHANGED_EVENT_LISTENER, this.handleNetworkChange);
|
|
261
|
-
}
|
|
262
|
-
teardownEventListeners() {
|
|
263
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
264
|
-
if (!this.canSetEventListeners)
|
|
265
|
-
return;
|
|
266
|
-
const wallet = this.getWallet();
|
|
267
|
-
if (this.handleAccountChange) {
|
|
268
|
-
wallet === null || wallet === void 0 ? void 0 : wallet.off(ACCOUNT_CHANGED_EVENT_LISTENER, this.handleAccountChange);
|
|
269
|
-
this.handleAccountChange = undefined;
|
|
270
|
-
}
|
|
271
|
-
if (this.handleNetworkChange) {
|
|
272
|
-
wallet === null || wallet === void 0 ? void 0 : wallet.off(NETWORK_CHANGED_EVENT_LISTENER, this.handleNetworkChange);
|
|
273
|
-
this.handleNetworkChange = undefined;
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
mapNetworkNameToChainId(networkNameOrChainId) {
|
|
278
|
-
if (networkNameOrChainId === starknet.constants.NetworkName.SN_MAIN ||
|
|
279
|
-
networkNameOrChainId.includes('mainnet') ||
|
|
280
|
-
networkNameOrChainId === starknet.constants.StarknetChainId.SN_MAIN) {
|
|
281
|
-
return starknet.constants.StarknetChainId.SN_MAIN;
|
|
282
|
-
}
|
|
283
|
-
else if (networkNameOrChainId === starknet.constants.NetworkName.SN_GOERLI ||
|
|
284
|
-
networkNameOrChainId.includes('goerli') ||
|
|
285
|
-
networkNameOrChainId === starknet.constants.StarknetChainId.SN_GOERLI) {
|
|
286
|
-
return starknet.constants.StarknetChainId.SN_GOERLI;
|
|
287
|
-
}
|
|
288
|
-
else if (networkNameOrChainId === starknet.constants.NetworkName.SN_SEPOLIA ||
|
|
289
|
-
networkNameOrChainId.includes('sepolia') ||
|
|
290
|
-
networkNameOrChainId === starknet.constants.StarknetChainId.SN_SEPOLIA) {
|
|
291
|
-
return starknet.constants.StarknetChainId.SN_SEPOLIA;
|
|
292
|
-
}
|
|
293
|
-
else {
|
|
294
|
-
walletConnectorCore.logger.error('Unknown networkName', networkNameOrChainId);
|
|
295
|
-
return undefined;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
mapChainIdToNetworkName(chainIdOrNetworkName) {
|
|
299
|
-
if (chainIdOrNetworkName === starknet.constants.StarknetChainId.SN_MAIN ||
|
|
300
|
-
chainIdOrNetworkName === starknet.constants.NetworkName.SN_MAIN) {
|
|
301
|
-
return starknet.constants.NetworkName.SN_MAIN;
|
|
302
|
-
}
|
|
303
|
-
else if (chainIdOrNetworkName === starknet.constants.StarknetChainId.SN_GOERLI ||
|
|
304
|
-
chainIdOrNetworkName === starknet.constants.NetworkName.SN_GOERLI) {
|
|
305
|
-
return starknet.constants.NetworkName.SN_GOERLI;
|
|
306
|
-
}
|
|
307
|
-
else if (chainIdOrNetworkName === starknet.constants.StarknetChainId.SN_SEPOLIA ||
|
|
308
|
-
chainIdOrNetworkName === starknet.constants.NetworkName.SN_SEPOLIA) {
|
|
309
|
-
return starknet.constants.NetworkName.SN_SEPOLIA;
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
walletConnectorCore.logger.error('Unknown chainId', chainIdOrNetworkName);
|
|
313
|
-
return undefined;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
exports.ACCOUNT_CHANGED_EVENT_LISTENER = ACCOUNT_CHANGED_EVENT_LISTENER;
|
|
319
|
-
exports.NETWORK_CHANGED_EVENT_LISTENER = NETWORK_CHANGED_EVENT_LISTENER;
|
|
320
|
-
exports["default"] = StarknetWalletConnector;
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { StarknetWindowObject } from 'get-starknet-core';
|
|
2
|
-
import { ProviderInterface, constants, AccountInterface, RpcProvider } from 'starknet';
|
|
3
|
-
import { Chain, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
-
import { NetworkConfiguration } from '@dynamic-labs/sdk-api-core';
|
|
5
|
-
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
6
|
-
import { IChainRpcProviders } from '@dynamic-labs/starknet-core';
|
|
7
|
-
import { StarknetWalletKey } from './types';
|
|
8
|
-
import { StarknetWallet } from './wallet';
|
|
9
|
-
type AccountChangeEventHandler = (address: {
|
|
10
|
-
toString(): string;
|
|
11
|
-
}) => Promise<void>;
|
|
12
|
-
type NetworkChangeEventHandler = (network: {
|
|
13
|
-
toString(): string;
|
|
14
|
-
}) => Promise<void>;
|
|
15
|
-
export declare const ACCOUNT_CHANGED_EVENT_LISTENER = "accountsChanged";
|
|
16
|
-
export declare const NETWORK_CHANGED_EVENT_LISTENER = "networkChanged";
|
|
17
|
-
declare abstract class StarknetWalletConnector extends WalletConnectorBase<typeof StarknetWallet> {
|
|
18
|
-
STARKNET_VERSION: 'v5' | 'v4';
|
|
19
|
-
name: string;
|
|
20
|
-
windowKey: StarknetWalletKey;
|
|
21
|
-
ChainWallet: typeof StarknetWallet;
|
|
22
|
-
connectedChain: Chain;
|
|
23
|
-
supportedChains: Chain[];
|
|
24
|
-
handleAccountChange: AccountChangeEventHandler | undefined;
|
|
25
|
-
handleNetworkChange: NetworkChangeEventHandler | undefined;
|
|
26
|
-
switchNetworkOnlyFromWallet: boolean;
|
|
27
|
-
starknetNetworks: NetworkConfiguration[];
|
|
28
|
-
canSetEventListeners: boolean;
|
|
29
|
-
constructor(name: string, windowKey: StarknetWalletKey, opts: {
|
|
30
|
-
chainRpcProviders: IChainRpcProviders;
|
|
31
|
-
starknetNetworks: NetworkConfiguration[];
|
|
32
|
-
walletBook: WalletBookSchema;
|
|
33
|
-
});
|
|
34
|
-
get walletBookWallet(): {
|
|
35
|
-
name: string;
|
|
36
|
-
brand?: {
|
|
37
|
-
alt?: string | undefined;
|
|
38
|
-
primaryColor?: string | undefined;
|
|
39
|
-
spriteId?: string | undefined;
|
|
40
|
-
} | undefined;
|
|
41
|
-
chainGroup?: string | undefined;
|
|
42
|
-
chains?: string[] | undefined;
|
|
43
|
-
desktop?: {
|
|
44
|
-
chromeId?: string | undefined;
|
|
45
|
-
edgeId?: string | undefined;
|
|
46
|
-
firefoxId?: string | undefined;
|
|
47
|
-
native?: string | undefined;
|
|
48
|
-
operaId?: string | undefined;
|
|
49
|
-
safariId?: string | undefined;
|
|
50
|
-
universal?: string | undefined;
|
|
51
|
-
} | undefined;
|
|
52
|
-
eip6963Config?: {
|
|
53
|
-
rdns: string;
|
|
54
|
-
} | undefined;
|
|
55
|
-
filterFromWalletConnect?: boolean | undefined;
|
|
56
|
-
group?: string | undefined;
|
|
57
|
-
hardwareWallets?: string[] | undefined;
|
|
58
|
-
injectedConfig?: {
|
|
59
|
-
chain: string;
|
|
60
|
-
extensionLocators: {
|
|
61
|
-
value: boolean;
|
|
62
|
-
flag: string;
|
|
63
|
-
}[];
|
|
64
|
-
providerInterface?: string | undefined;
|
|
65
|
-
walletStandard?: {
|
|
66
|
-
features: string[];
|
|
67
|
-
name: string;
|
|
68
|
-
providerId?: string | undefined;
|
|
69
|
-
} | undefined;
|
|
70
|
-
walletStandardLocators?: {
|
|
71
|
-
name: string;
|
|
72
|
-
locator: string;
|
|
73
|
-
}[] | undefined;
|
|
74
|
-
windowLocations?: string[] | undefined;
|
|
75
|
-
}[] | undefined;
|
|
76
|
-
mobile?: {
|
|
77
|
-
android?: string | null | undefined;
|
|
78
|
-
androidId?: string | undefined;
|
|
79
|
-
inAppBrowser?: string | null | undefined;
|
|
80
|
-
ios?: string | null | undefined;
|
|
81
|
-
iosId?: string | undefined;
|
|
82
|
-
native?: string | undefined;
|
|
83
|
-
universal?: string | undefined;
|
|
84
|
-
} | undefined;
|
|
85
|
-
mobileExperience?: "in-app-browser" | "redirect" | undefined;
|
|
86
|
-
shortName?: string | undefined;
|
|
87
|
-
showOnlyIfInstalled?: boolean | undefined;
|
|
88
|
-
switchNetworkOnlyFromWallet?: boolean | undefined;
|
|
89
|
-
walletConnect?: {
|
|
90
|
-
sdks?: string[] | undefined;
|
|
91
|
-
} | undefined;
|
|
92
|
-
walletGroup?: string | undefined;
|
|
93
|
-
walletLimitations?: {
|
|
94
|
-
browserExtension?: {
|
|
95
|
-
unsupportedEvents?: string[] | undefined;
|
|
96
|
-
unsupportedMethods?: string[] | undefined;
|
|
97
|
-
} | undefined;
|
|
98
|
-
mobile?: {
|
|
99
|
-
unsupportedEvents?: string[] | undefined;
|
|
100
|
-
unsupportedMethods?: string[] | undefined;
|
|
101
|
-
} | undefined;
|
|
102
|
-
} | undefined;
|
|
103
|
-
};
|
|
104
|
-
isProviderConnected(): boolean;
|
|
105
|
-
getPublicClient(): Promise<RpcProvider | undefined>;
|
|
106
|
-
/**
|
|
107
|
-
* returns starknet wallet network id
|
|
108
|
-
*/
|
|
109
|
-
getNetwork(): Promise<any>;
|
|
110
|
-
connect(): Promise<void>;
|
|
111
|
-
getAddress(): Promise<string | undefined>;
|
|
112
|
-
getWalletAccount(): Promise<AccountInterface | undefined>;
|
|
113
|
-
getProvider(): Promise<ProviderInterface | undefined>;
|
|
114
|
-
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
115
|
-
getBalance(address: string): Promise<string | undefined>;
|
|
116
|
-
endSession(): Promise<void>;
|
|
117
|
-
getWallet(): StarknetWindowObject | undefined;
|
|
118
|
-
isInstalledOnBrowser(): boolean;
|
|
119
|
-
getConnectedAccounts(): Promise<string[]>;
|
|
120
|
-
reconnectIfNeeded(wallet: StarknetWindowObject): Promise<Promise<Promise<void>>>;
|
|
121
|
-
setupEventListeners(): void;
|
|
122
|
-
teardownEventListeners(): Promise<void>;
|
|
123
|
-
mapNetworkNameToChainId(networkNameOrChainId: string): constants.StarknetChainId | undefined;
|
|
124
|
-
mapChainIdToNetworkName(chainIdOrNetworkName: string): constants.NetworkName | undefined;
|
|
125
|
-
}
|
|
126
|
-
export type StarknetWalletConnectorType = StarknetWalletConnector;
|
|
127
|
-
export default StarknetWalletConnector;
|