@dynamic-labs/starknet 4.0.0-alpha.4 → 4.0.0-alpha.40

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