@dynamic-labs/starknet 4.0.0-alpha.26 → 4.0.0-alpha.28

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.
Files changed (68) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/package.cjs +1 -1
  3. package/package.js +1 -1
  4. package/package.json +13 -10
  5. package/src/StarknetWalletConnector.cjs +233 -0
  6. package/src/StarknetWalletConnector.d.ts +58 -0
  7. package/src/StarknetWalletConnector.js +229 -0
  8. package/src/getAvailableWallets.cjs +27 -0
  9. package/src/getAvailableWallets.d.ts +8 -0
  10. package/src/getAvailableWallets.js +21 -0
  11. package/src/index.cjs +12 -13
  12. package/src/index.d.ts +16 -7
  13. package/src/index.js +11 -13
  14. package/src/types.d.ts +26 -11
  15. package/src/utils/convertors.cjs +1 -1
  16. package/src/utils/convertors.d.ts +1 -1
  17. package/src/utils/convertors.js +1 -1
  18. package/src/utils/starknetSnap.d.ts +2 -2
  19. package/src/wallet/StarknetWallet.cjs +0 -3
  20. package/src/wallet/StarknetWallet.d.ts +4 -4
  21. package/src/wallet/StarknetWallet.js +0 -3
  22. package/src/wallets/argent/argentMobile/argentMobile.cjs +73 -0
  23. package/src/wallets/argent/argentMobile/argentMobile.d.ts +16 -0
  24. package/src/wallets/argent/argentMobile/argentMobile.js +69 -0
  25. package/src/wallets/argent/base.cjs +50 -0
  26. package/src/wallets/argent/base.d.ts +5 -0
  27. package/src/wallets/argent/base.js +46 -0
  28. package/src/wallets/argent/injected/argentx.cjs +33 -0
  29. package/src/wallets/argent/injected/argentx.d.ts +8 -0
  30. package/src/wallets/argent/injected/argentx.js +29 -0
  31. package/src/wallets/argent/webwallet/webwallet.cjs +37 -0
  32. package/src/wallets/argent/webwallet/webwallet.d.ts +10 -0
  33. package/src/wallets/argent/webwallet/webwallet.js +33 -0
  34. package/src/wallets/injected/fetchStarknetInjectedWalletConnectors.cjs +34 -0
  35. package/src/wallets/injected/fetchStarknetInjectedWalletConnectors.d.ts +5 -0
  36. package/src/wallets/injected/fetchStarknetInjectedWalletConnectors.js +30 -0
  37. package/src/wallets/injected/injected.cjs +138 -0
  38. package/src/wallets/injected/injected.d.ts +9 -0
  39. package/src/wallets/injected/injected.js +134 -0
  40. package/src/wallets/{metamask.d.ts → injected/metamask.d.ts} +2 -4
  41. package/src/starknetWalletConnector.cjs +0 -320
  42. package/src/starknetWalletConnector.d.ts +0 -128
  43. package/src/starknetWalletConnector.js +0 -314
  44. package/src/utils/starknetSnap.cjs +0 -92
  45. package/src/utils/starknetSnap.js +0 -88
  46. package/src/wallets/argentx.cjs +0 -24
  47. package/src/wallets/argentx.d.ts +0 -8
  48. package/src/wallets/argentx.js +0 -20
  49. package/src/wallets/argentxBase.cjs +0 -50
  50. package/src/wallets/argentxBase.d.ts +0 -16
  51. package/src/wallets/argentxBase.js +0 -48
  52. package/src/wallets/argentxMobile.cjs +0 -100
  53. package/src/wallets/argentxMobile.d.ts +0 -13
  54. package/src/wallets/argentxMobile.js +0 -96
  55. package/src/wallets/argentxWeb.cjs +0 -57
  56. package/src/wallets/argentxWeb.d.ts +0 -8
  57. package/src/wallets/argentxWeb.js +0 -53
  58. package/src/wallets/bitget.cjs +0 -22
  59. package/src/wallets/bitget.d.ts +0 -7
  60. package/src/wallets/bitget.js +0 -18
  61. package/src/wallets/braavos.cjs +0 -37
  62. package/src/wallets/braavos.d.ts +0 -8
  63. package/src/wallets/braavos.js +0 -33
  64. package/src/wallets/metamask.cjs +0 -121
  65. package/src/wallets/metamask.js +0 -117
  66. package/src/wallets/okx.cjs +0 -15
  67. package/src/wallets/okx.d.ts +0 -6
  68. package/src/wallets/okx.js +0 -11
@@ -1,117 +0,0 @@
1
- 'use client'
2
- import { __awaiter } from '../../_virtual/_tslib.js';
3
- import { Eip6963ProviderSingleton } from '@dynamic-labs/utils';
4
- import { Logger, LogLevel } from '@dynamic-labs/logger';
5
- import StarknetWalletConnector from '../starknetWalletConnector.js';
6
- import { createMetaMaskProviderWrapper } from '../utils/starknetSnap.js';
7
-
8
- const logger = new Logger('MetaMask Starknet Snap', LogLevel.INFO);
9
- class MetaMask extends StarknetWalletConnector {
10
- constructor(opts) {
11
- super('MetaMask Starknet', 'metamask_snap', opts);
12
- this.overrideKey = 'metamaskstarknet';
13
- const { providers } = Eip6963ProviderSingleton.get();
14
- const metamaskProvider = providers.find((p) => ['io.metamask', 'io.metamask.flask'].includes(p.info.rdns));
15
- if (metamaskProvider) {
16
- this.provider = metamaskProvider.provider;
17
- }
18
- if (!window.starknet_metamask_snap && metamaskProvider) {
19
- window.starknet_metamask_snap = createMetaMaskProviderWrapper(metamaskProvider.provider);
20
- }
21
- }
22
- getNetwork() {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- if (!this.provider) {
25
- logger.error('[getNetwork] - No provider found, returning undefined');
26
- return undefined;
27
- }
28
- try {
29
- logger.info('[getNetwork] - trying to fetch network using provider');
30
- // we are using this method to get the network so that we always "see" the absolute
31
- // active network in the companion site. when using the snap wrapper to get the network,
32
- // we don't "see" the actual active network in the companion site – instead we see the
33
- // network that was active at the time of the snap initialization
34
- const result = yield this.provider.request({
35
- method: 'wallet_invokeSnap',
36
- params: {
37
- request: {
38
- method: 'starkNet_getCurrentNetwork',
39
- params: {},
40
- },
41
- snapId: 'npm:@consensys/starknet-snap',
42
- },
43
- });
44
- if (!('chainId' in result) || typeof result.chainId !== 'string') {
45
- logger.error(`[getNetwork] - result.chainId should be a string, but got: ${
46
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
- result.chainId}`);
48
- return undefined;
49
- }
50
- if (result.chainId !== this.currentChainId) {
51
- const resultChainName = this.mapChainIdToNetworkName(result.chainId);
52
- const currentChainName = this.currentChainId
53
- ? this.mapChainIdToNetworkName(this.currentChainId)
54
- : undefined;
55
- logger.info(`[getNetwork] - emitting chainChange event. got chainId: ${result.chainId} (${resultChainName}). current chainId: ${this.currentChainId} (${currentChainName})`);
56
- this.emit('chainChange', { chain: result.chainId });
57
- }
58
- this.currentChainId = result.chainId;
59
- return this.currentChainId;
60
- }
61
- catch (e) {
62
- logger.error('[getNetwork] - network fetch request failed, returning undefined', e);
63
- return undefined;
64
- }
65
- });
66
- }
67
- setupEventListeners() {
68
- if (this.intervalId) {
69
- return;
70
- }
71
- this.intervalId = setInterval(() => {
72
- this.getNetwork().then((chainId) => {
73
- if (!chainId) {
74
- return;
75
- }
76
- const resultChainName = this.mapChainIdToNetworkName(chainId);
77
- const currentChainName = this.currentChainId
78
- ? this.mapChainIdToNetworkName(this.currentChainId)
79
- : undefined;
80
- logger.info(`[setupEventListeners] - got network: ${chainId} (${resultChainName}). current network: ${this.currentChainId} (${currentChainName})`);
81
- if (chainId !== this.currentChainId) {
82
- logger.info(`[setupEventListeners] - emitting chainChange event: ${chainId}`);
83
- this.emit('chainChange', { chain: chainId });
84
- this.currentChainId = chainId;
85
- }
86
- });
87
- }, 5000);
88
- }
89
- teardownEventListeners() {
90
- return __awaiter(this, void 0, void 0, function* () {
91
- clearInterval(this.intervalId);
92
- this.intervalId = undefined;
93
- });
94
- }
95
- endSession() {
96
- return __awaiter(this, void 0, void 0, function* () {
97
- this.teardownEventListeners();
98
- });
99
- }
100
- getConnectedAccounts() {
101
- return __awaiter(this, void 0, void 0, function* () {
102
- const wallet = this.getWallet();
103
- if (!wallet) {
104
- return [];
105
- }
106
- const isProviderConnected = this.isProviderConnected();
107
- const isPreauthorized = yield wallet.isPreauthorized();
108
- const shouldReconnect = !isProviderConnected && isPreauthorized;
109
- if (shouldReconnect) {
110
- yield this.connect();
111
- }
112
- return wallet.selectedAddress ? [wallet.selectedAddress] : [];
113
- });
114
- }
115
- }
116
-
117
- export { MetaMask };
@@ -1,15 +0,0 @@
1
- 'use client'
2
- 'use strict';
3
-
4
- Object.defineProperty(exports, '__esModule', { value: true });
5
-
6
- var starknetWalletConnector = require('../starknetWalletConnector.cjs');
7
-
8
- class Okx extends starknetWalletConnector["default"] {
9
- constructor(opts) {
10
- super('OKX Starknet', 'okxwallet', opts);
11
- this.overrideKey = 'okxstarknet';
12
- }
13
- }
14
-
15
- exports.Okx = Okx;
@@ -1,6 +0,0 @@
1
- import type { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
2
- import StarknetProvider from '../starknetWalletConnector';
3
- export declare class Okx extends StarknetProvider implements WalletConnectorBase {
4
- overrideKey: string;
5
- constructor(opts: any);
6
- }
@@ -1,11 +0,0 @@
1
- 'use client'
2
- import StarknetWalletConnector from '../starknetWalletConnector.js';
3
-
4
- class Okx extends StarknetWalletConnector {
5
- constructor(opts) {
6
- super('OKX Starknet', 'okxwallet', opts);
7
- this.overrideKey = 'okxstarknet';
8
- }
9
- }
10
-
11
- export { Okx };