@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
@@ -0,0 +1,34 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var injected = require('./injected.cjs');
7
+
8
+ const filteredStarknetWalletKeysOverrides = [
9
+ // TODO(starknet-v6): Remove once these wallets support v6
10
+ 'okxstarknet',
11
+ 'bitgetstarknet',
12
+ ];
13
+ const fetchStarknetInjectedWalletConnectors = ({ walletBook, }) => {
14
+ var _a;
15
+ return Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {})
16
+ .filter(([key, wallet]) => {
17
+ var _a;
18
+ return ((_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => config.chain === 'starknet')) &&
19
+ !filteredStarknetWalletKeysOverrides.includes(key);
20
+ })
21
+ .map(([key, wallet]) => {
22
+ var _a, _b, _c;
23
+ const name = wallet.shortName || wallet.name;
24
+ const walletConnectorFallback = Boolean(wallet.walletConnect);
25
+ const id = (_c = (_b = (_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a[0].windowLocations) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : key;
26
+ return class extends injected.Injected {
27
+ constructor(props) {
28
+ super(name, id, Object.assign({ name, overrideKey: key, walletBookWallet: wallet, walletConnectorFallback }, props));
29
+ }
30
+ };
31
+ });
32
+ };
33
+
34
+ exports.fetchStarknetInjectedWalletConnectors = fetchStarknetInjectedWalletConnectors;
@@ -0,0 +1,5 @@
1
+ import { WalletConnectorConstructor } from '@dynamic-labs/wallet-connector-core';
2
+ import { WalletBookSchema } from '@dynamic-labs/wallet-book';
3
+ export declare const fetchStarknetInjectedWalletConnectors: ({ walletBook, }: {
4
+ walletBook: WalletBookSchema;
5
+ }) => WalletConnectorConstructor[];
@@ -0,0 +1,30 @@
1
+ 'use client'
2
+ import { Injected } from './injected.js';
3
+
4
+ const filteredStarknetWalletKeysOverrides = [
5
+ // TODO(starknet-v6): Remove once these wallets support v6
6
+ 'okxstarknet',
7
+ 'bitgetstarknet',
8
+ ];
9
+ const fetchStarknetInjectedWalletConnectors = ({ walletBook, }) => {
10
+ var _a;
11
+ return Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {})
12
+ .filter(([key, wallet]) => {
13
+ var _a;
14
+ return ((_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => config.chain === 'starknet')) &&
15
+ !filteredStarknetWalletKeysOverrides.includes(key);
16
+ })
17
+ .map(([key, wallet]) => {
18
+ var _a, _b, _c;
19
+ const name = wallet.shortName || wallet.name;
20
+ const walletConnectorFallback = Boolean(wallet.walletConnect);
21
+ const id = (_c = (_b = (_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a[0].windowLocations) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : key;
22
+ return class extends Injected {
23
+ constructor(props) {
24
+ super(name, id, Object.assign({ name, overrideKey: key, walletBookWallet: wallet, walletConnectorFallback }, props));
25
+ }
26
+ };
27
+ });
28
+ };
29
+
30
+ export { fetchStarknetInjectedWalletConnectors };
@@ -0,0 +1,138 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../../_virtual/_tslib.cjs');
7
+ var typesJs = require('@starknet-io/types-js');
8
+ var utils = require('@dynamic-labs/utils');
9
+ var StarknetWalletConnector = require('../../StarknetWalletConnector.cjs');
10
+ var getAvailableWallets = require('../../getAvailableWallets.cjs');
11
+
12
+ class Injected extends StarknetWalletConnector.StarknetWalletConnector {
13
+ prompt(options) {
14
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
15
+ const wallet = this.getWindowWallet();
16
+ if (!wallet) {
17
+ throw new utils.DynamicError('No wallet available to send RPC requests to');
18
+ }
19
+ this.logger.debug('[prompt] Sending wallet_requestAccounts with silent_mode:', options.silently);
20
+ const accounts = yield wallet.request({
21
+ params: {
22
+ silent_mode: options.silently,
23
+ },
24
+ type: 'wallet_requestAccounts',
25
+ });
26
+ this.logger.debug('[prompt] Received from wallet_requestAccounts:', accounts);
27
+ if (accounts.length === 0) {
28
+ return {
29
+ data: {
30
+ account: undefined,
31
+ chainId: undefined,
32
+ },
33
+ wallet,
34
+ };
35
+ }
36
+ const [account] = accounts;
37
+ this.logger.debug('[prompt] Sending wallet_requestChaindId');
38
+ const chainId = yield wallet.request({
39
+ type: 'wallet_requestChainId',
40
+ });
41
+ this.logger.debug('[prompt] Received from wallet_requestChainId:', chainId);
42
+ return {
43
+ data: {
44
+ account,
45
+ chainId: BigInt(chainId),
46
+ },
47
+ wallet,
48
+ };
49
+ });
50
+ }
51
+ getAddress() {
52
+ const _super = Object.create(null, {
53
+ getAddress: { get: () => super.getAddress }
54
+ });
55
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
56
+ var _a;
57
+ if (this.isInstalledOnBrowser()) {
58
+ return _super.getAddress.call(this);
59
+ }
60
+ const inAppBrowserBase = (_a = this.walletBookWallet.mobile) === null || _a === void 0 ? void 0 : _a.inAppBrowser;
61
+ if (!inAppBrowserBase || !utils.isMobile()) {
62
+ return undefined;
63
+ }
64
+ const inAppBrowserTemplate = utils.template(inAppBrowserBase);
65
+ const deepLink = inAppBrowserTemplate({
66
+ encodedDappURI: window.location.toString().replace(/http(s)?:\/\//, ''),
67
+ });
68
+ window.location.href = deepLink;
69
+ return undefined;
70
+ });
71
+ }
72
+ getConnectedAccounts() {
73
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
74
+ var _a;
75
+ if ((_a = this.walletData) === null || _a === void 0 ? void 0 : _a.account) {
76
+ this.logger.debug('[getConnectedAccounts] Found existing account:', this.walletData.account);
77
+ return [this.walletData.account];
78
+ }
79
+ const wallet = this.getWindowWallet();
80
+ if (!wallet) {
81
+ return [];
82
+ }
83
+ const silently = yield this.shouldPromptSilently(wallet);
84
+ let data;
85
+ this.logger.debug('[getConnectedAccounts] No existing account, attempting to connect with silent mode:', silently);
86
+ try {
87
+ ({ data } = yield this.prompt({
88
+ silently,
89
+ }));
90
+ }
91
+ catch (error) {
92
+ this.logger.debug(`[getConnectedAccounts] Silent connect errored out: ${error}`);
93
+ return [];
94
+ }
95
+ this.logger.debug(`[getConnectedAccounts] Connect returned account: ${data === null || data === void 0 ? void 0 : data.account}`);
96
+ if (!(data === null || data === void 0 ? void 0 : data.account)) {
97
+ return [];
98
+ }
99
+ this.walletData = data;
100
+ this.wallet = wallet;
101
+ this.setupEventListeners();
102
+ return [data.account];
103
+ });
104
+ }
105
+ shouldPromptSilently(wallet) {
106
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
107
+ /**
108
+ * In general, getConnectedAccounts should send a "silent" request to the wallet, meaning
109
+ * no popup will be displayed to the user. However, in the case that the user comes back
110
+ * to the dapp with a locked wallet, we do want to trigger a popup for the user to unlock
111
+ * their wallet, but only if their wallet has still granted permission to the dapp to access
112
+ * its data. That's what the following `wallet_getPermissions` RPC request does.
113
+ */
114
+ let silently = true;
115
+ try {
116
+ const permissions = yield wallet.request({
117
+ type: 'wallet_getPermissions',
118
+ });
119
+ if (permissions.includes(typesJs.WALLET_API.Permission.ACCOUNTS)) {
120
+ this.logger.debug('[getConnectedAccounts] Received `accounts` permission from wallet_getPermissions');
121
+ silently = false;
122
+ }
123
+ }
124
+ catch (error) {
125
+ this.logger.debug('[getConnectedAccounts] `wallet_getPermissions` threw error:', error);
126
+ }
127
+ return silently;
128
+ });
129
+ }
130
+ getWindowWallet() {
131
+ this.logger.debug('[getWindowWallet] Looking for wallet from get-starknet-core:', this.id);
132
+ const wallet = getAvailableWallets.availableWallets.find((wallet) => wallet.id === this.id);
133
+ this.logger.debug('[getWindowWallet] Lookup result:', wallet);
134
+ return wallet;
135
+ }
136
+ }
137
+
138
+ exports.Injected = Injected;
@@ -0,0 +1,9 @@
1
+ import { StarknetWalletConnector } from '../../StarknetWalletConnector';
2
+ import { PromptOptions, PromptResult } from '../../types';
3
+ export declare class Injected extends StarknetWalletConnector {
4
+ prompt(options: PromptOptions): Promise<PromptResult>;
5
+ getAddress(): Promise<string | undefined>;
6
+ getConnectedAccounts(): Promise<string[]>;
7
+ private shouldPromptSilently;
8
+ private getWindowWallet;
9
+ }
@@ -0,0 +1,134 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../../_virtual/_tslib.js';
3
+ import { WALLET_API } from '@starknet-io/types-js';
4
+ import { DynamicError, isMobile, template } from '@dynamic-labs/utils';
5
+ import { StarknetWalletConnector } from '../../StarknetWalletConnector.js';
6
+ import { availableWallets } from '../../getAvailableWallets.js';
7
+
8
+ class Injected extends StarknetWalletConnector {
9
+ prompt(options) {
10
+ return __awaiter(this, void 0, void 0, function* () {
11
+ const wallet = this.getWindowWallet();
12
+ if (!wallet) {
13
+ throw new DynamicError('No wallet available to send RPC requests to');
14
+ }
15
+ this.logger.debug('[prompt] Sending wallet_requestAccounts with silent_mode:', options.silently);
16
+ const accounts = yield wallet.request({
17
+ params: {
18
+ silent_mode: options.silently,
19
+ },
20
+ type: 'wallet_requestAccounts',
21
+ });
22
+ this.logger.debug('[prompt] Received from wallet_requestAccounts:', accounts);
23
+ if (accounts.length === 0) {
24
+ return {
25
+ data: {
26
+ account: undefined,
27
+ chainId: undefined,
28
+ },
29
+ wallet,
30
+ };
31
+ }
32
+ const [account] = accounts;
33
+ this.logger.debug('[prompt] Sending wallet_requestChaindId');
34
+ const chainId = yield wallet.request({
35
+ type: 'wallet_requestChainId',
36
+ });
37
+ this.logger.debug('[prompt] Received from wallet_requestChainId:', chainId);
38
+ return {
39
+ data: {
40
+ account,
41
+ chainId: BigInt(chainId),
42
+ },
43
+ wallet,
44
+ };
45
+ });
46
+ }
47
+ getAddress() {
48
+ const _super = Object.create(null, {
49
+ getAddress: { get: () => super.getAddress }
50
+ });
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ var _a;
53
+ if (this.isInstalledOnBrowser()) {
54
+ return _super.getAddress.call(this);
55
+ }
56
+ const inAppBrowserBase = (_a = this.walletBookWallet.mobile) === null || _a === void 0 ? void 0 : _a.inAppBrowser;
57
+ if (!inAppBrowserBase || !isMobile()) {
58
+ return undefined;
59
+ }
60
+ const inAppBrowserTemplate = template(inAppBrowserBase);
61
+ const deepLink = inAppBrowserTemplate({
62
+ encodedDappURI: window.location.toString().replace(/http(s)?:\/\//, ''),
63
+ });
64
+ window.location.href = deepLink;
65
+ return undefined;
66
+ });
67
+ }
68
+ getConnectedAccounts() {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ var _a;
71
+ if ((_a = this.walletData) === null || _a === void 0 ? void 0 : _a.account) {
72
+ this.logger.debug('[getConnectedAccounts] Found existing account:', this.walletData.account);
73
+ return [this.walletData.account];
74
+ }
75
+ const wallet = this.getWindowWallet();
76
+ if (!wallet) {
77
+ return [];
78
+ }
79
+ const silently = yield this.shouldPromptSilently(wallet);
80
+ let data;
81
+ this.logger.debug('[getConnectedAccounts] No existing account, attempting to connect with silent mode:', silently);
82
+ try {
83
+ ({ data } = yield this.prompt({
84
+ silently,
85
+ }));
86
+ }
87
+ catch (error) {
88
+ this.logger.debug(`[getConnectedAccounts] Silent connect errored out: ${error}`);
89
+ return [];
90
+ }
91
+ this.logger.debug(`[getConnectedAccounts] Connect returned account: ${data === null || data === void 0 ? void 0 : data.account}`);
92
+ if (!(data === null || data === void 0 ? void 0 : data.account)) {
93
+ return [];
94
+ }
95
+ this.walletData = data;
96
+ this.wallet = wallet;
97
+ this.setupEventListeners();
98
+ return [data.account];
99
+ });
100
+ }
101
+ shouldPromptSilently(wallet) {
102
+ return __awaiter(this, void 0, void 0, function* () {
103
+ /**
104
+ * In general, getConnectedAccounts should send a "silent" request to the wallet, meaning
105
+ * no popup will be displayed to the user. However, in the case that the user comes back
106
+ * to the dapp with a locked wallet, we do want to trigger a popup for the user to unlock
107
+ * their wallet, but only if their wallet has still granted permission to the dapp to access
108
+ * its data. That's what the following `wallet_getPermissions` RPC request does.
109
+ */
110
+ let silently = true;
111
+ try {
112
+ const permissions = yield wallet.request({
113
+ type: 'wallet_getPermissions',
114
+ });
115
+ if (permissions.includes(WALLET_API.Permission.ACCOUNTS)) {
116
+ this.logger.debug('[getConnectedAccounts] Received `accounts` permission from wallet_getPermissions');
117
+ silently = false;
118
+ }
119
+ }
120
+ catch (error) {
121
+ this.logger.debug('[getConnectedAccounts] `wallet_getPermissions` threw error:', error);
122
+ }
123
+ return silently;
124
+ });
125
+ }
126
+ getWindowWallet() {
127
+ this.logger.debug('[getWindowWallet] Looking for wallet from get-starknet-core:', this.id);
128
+ const wallet = availableWallets.find((wallet) => wallet.id === this.id);
129
+ this.logger.debug('[getWindowWallet] Lookup result:', wallet);
130
+ return wallet;
131
+ }
132
+ }
133
+
134
+ export { Injected };
@@ -1,6 +1,5 @@
1
- import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
2
- import StarknetProvider from '../starknetWalletConnector';
3
- export declare class MetaMask extends StarknetProvider implements WalletConnectorBase {
1
+ import { Injected } from './injected';
2
+ export declare class MetaMask extends Injected {
4
3
  overrideKey: string;
5
4
  private currentChainId;
6
5
  private intervalId;
@@ -10,5 +9,4 @@ export declare class MetaMask extends StarknetProvider implements WalletConnecto
10
9
  setupEventListeners(): void;
11
10
  teardownEventListeners(): Promise<void>;
12
11
  endSession(): Promise<void>;
13
- getConnectedAccounts(): Promise<string[]>;
14
12
  }