@dynamic-labs/starknet 0.18.25 → 0.18.26

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 CHANGED
@@ -1,4 +1,11 @@
1
1
 
2
+ ### [0.18.26](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.25...v0.18.26) (2023-10-14)
3
+
4
+ ### Bug Fixes
5
+
6
+ * ArgentX' support for in-browser wallet
7
+
8
+
2
9
  ### [0.18.25](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.24...v0.18.25) (2023-10-12)
3
10
 
4
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/starknet",
3
- "version": "0.18.25",
3
+ "version": "0.18.26",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -30,9 +30,9 @@
30
30
  "get-starknet-core": "^3.2.0",
31
31
  "text-encoding": "0.7.0",
32
32
  "@dynamic-labs/sdk-api": "0.0.270",
33
- "@dynamic-labs/utils": "0.18.25",
34
- "@dynamic-labs/wallet-book": "0.18.25",
35
- "@dynamic-labs/wallet-connector-core": "0.18.25"
33
+ "@dynamic-labs/utils": "0.18.26",
34
+ "@dynamic-labs/wallet-book": "0.18.26",
35
+ "@dynamic-labs/wallet-connector-core": "0.18.26"
36
36
  },
37
37
  "peerDependencies": {}
38
38
  }
@@ -36,7 +36,7 @@ class StarknetWalletConnector extends walletConnectorCore.WalletConnectorBase {
36
36
  getNetwork() {
37
37
  var _a;
38
38
  return _tslib.__awaiter(this, void 0, void 0, function* () {
39
- const wallet = yield this.getWallet();
39
+ const wallet = this.getWallet();
40
40
  if (!wallet) {
41
41
  return Promise.resolve(undefined);
42
42
  }
@@ -48,7 +48,7 @@ class StarknetWalletConnector extends walletConnectorCore.WalletConnectorBase {
48
48
  }
49
49
  connect() {
50
50
  return _tslib.__awaiter(this, void 0, void 0, function* () {
51
- const wallet = yield this.getWallet();
51
+ const wallet = this.getWallet();
52
52
  try {
53
53
  if (wallet && !wallet.isConnected) {
54
54
  yield wallet.enable({ starknetVersion: STARKNET_VERSION });
@@ -61,7 +61,7 @@ class StarknetWalletConnector extends walletConnectorCore.WalletConnectorBase {
61
61
  }
62
62
  fetchPublicAddress() {
63
63
  return _tslib.__awaiter(this, void 0, void 0, function* () {
64
- const wallet = yield this.getWallet();
64
+ const wallet = this.getWallet();
65
65
  /**
66
66
  * Fetches public address. Uses `isPreauthorized` as a temporary solution to ensure
67
67
  * the wallets store's data is read. Without it, an empty string may be returned due
@@ -74,19 +74,10 @@ class StarknetWalletConnector extends walletConnectorCore.WalletConnectorBase {
74
74
  }
75
75
  getSigner() {
76
76
  return _tslib.__awaiter(this, void 0, void 0, function* () {
77
- const wallet = yield this.getWallet();
77
+ const wallet = this.getWallet();
78
78
  return wallet === null || wallet === void 0 ? void 0 : wallet.account;
79
79
  });
80
80
  }
81
- getWallet() {
82
- return _tslib.__awaiter(this, void 0, void 0, function* () {
83
- if (!this.wallet) {
84
- const providers = yield getStarknetCore.getStarknet().getAvailableWallets();
85
- this.wallet = providers.find((provider) => provider.name === this.name);
86
- }
87
- return this.wallet;
88
- });
89
- }
90
81
  getWeb3Provider() {
91
82
  return _tslib.__awaiter(this, void 0, void 0, function* () {
92
83
  const wallet = yield this.getWallet();
@@ -95,7 +86,7 @@ class StarknetWalletConnector extends walletConnectorCore.WalletConnectorBase {
95
86
  }
96
87
  signMessage(messageToSign) {
97
88
  return _tslib.__awaiter(this, void 0, void 0, function* () {
98
- const wallet = yield this.getWallet();
89
+ const wallet = this.getWallet();
99
90
  const walletAddress = yield this.fetchPublicAddress();
100
91
  if (!walletAddress || !wallet) {
101
92
  walletConnectorCore.logger.error('Could not fetch wallet address for signing message');
@@ -133,23 +124,25 @@ class StarknetWalletConnector extends walletConnectorCore.WalletConnectorBase {
133
124
  getStarknetCore.getStarknet().disconnect({ clearLastWallet: true });
134
125
  });
135
126
  }
136
- getStarknetWindowObject() {
137
- const starknetWindowInstance = window[`starknet_${this.windowKey}`] || window['starknet'];
138
- if ((starknetWindowInstance === null || starknetWindowInstance === void 0 ? void 0 : starknetWindowInstance.name) === this.name) {
127
+ getWallet() {
128
+ let starknetWindowInstance = window[`starknet_${this.windowKey}`];
129
+ if (starknetWindowInstance !== undefined) {
139
130
  return starknetWindowInstance;
140
131
  }
141
132
  else {
142
- return undefined;
133
+ starknetWindowInstance = window['starknet'];
134
+ if ((starknetWindowInstance === null || starknetWindowInstance === void 0 ? void 0 : starknetWindowInstance.name) === this.name) {
135
+ return starknetWindowInstance;
136
+ }
143
137
  }
138
+ return undefined;
144
139
  }
145
140
  isInstalledOnBrowser() {
146
- var _a;
147
- const starknetWindowInstance = (_a = window[`starknet_${this.windowKey}`]) !== null && _a !== void 0 ? _a : window['starknet'];
148
- return (starknetWindowInstance === null || starknetWindowInstance === void 0 ? void 0 : starknetWindowInstance.name) === this.name;
141
+ return this.getWallet() !== undefined;
149
142
  }
150
143
  getConnectedAccounts() {
151
144
  return _tslib.__awaiter(this, void 0, void 0, function* () {
152
- const wallet = yield this.getWallet();
145
+ const wallet = this.getWallet();
153
146
  if (!wallet) {
154
147
  return [];
155
148
  }
@@ -161,7 +154,7 @@ class StarknetWalletConnector extends walletConnectorCore.WalletConnectorBase {
161
154
  });
162
155
  }
163
156
  setupEventListeners(listeners) {
164
- const wallet = this.getStarknetWindowObject();
157
+ const wallet = this.getWallet();
165
158
  if (!wallet) {
166
159
  return walletConnectorCore.logger.error('Wallet has not been found');
167
160
  }
@@ -186,7 +179,7 @@ class StarknetWalletConnector extends walletConnectorCore.WalletConnectorBase {
186
179
  yield ((_c = listeners.onDisconnect) === null || _c === void 0 ? void 0 : _c.call(listeners));
187
180
  return;
188
181
  }
189
- const chainId = this.mapChainUrlToChainId(network.toString());
182
+ const chainId = this.mapNetworkNameToChainId(network.toString());
190
183
  if (chainId) {
191
184
  yield ((_d = listeners.onChainChange) === null || _d === void 0 ? void 0 : _d.call(listeners, chainId));
192
185
  }
@@ -196,7 +189,7 @@ class StarknetWalletConnector extends walletConnectorCore.WalletConnectorBase {
196
189
  }
197
190
  teardownEventListeners() {
198
191
  return _tslib.__awaiter(this, void 0, void 0, function* () {
199
- const wallet = yield this.getWallet();
192
+ const wallet = this.getWallet();
200
193
  if (this.handleAccountChange) {
201
194
  wallet === null || wallet === void 0 ? void 0 : wallet.off(ACCOUNT_CHANGED_EVENT_LISTENER, this.handleAccountChange);
202
195
  this.handleAccountChange = undefined;
@@ -207,14 +200,19 @@ class StarknetWalletConnector extends walletConnectorCore.WalletConnectorBase {
207
200
  }
208
201
  });
209
202
  }
210
- mapChainUrlToChainId(baseUrl) {
211
- if (baseUrl.includes('mainnet')) {
203
+ mapNetworkNameToChainId(networkName) {
204
+ if (networkName === starknet.constants.NetworkName.SN_MAIN ||
205
+ networkName.includes('mainnet')) {
212
206
  return starknet.constants.StarknetChainId.SN_MAIN;
213
207
  }
214
- else if (baseUrl.includes('goerli')) {
208
+ else if (networkName === starknet.constants.NetworkName.SN_GOERLI ||
209
+ networkName.includes('goerli')) {
215
210
  return starknet.constants.StarknetChainId.SN_GOERLI;
216
211
  }
217
- return undefined;
212
+ else {
213
+ walletConnectorCore.logger.error('Unknown networkName', networkName);
214
+ return undefined;
215
+ }
218
216
  }
219
217
  }
220
218
 
@@ -32,17 +32,16 @@ declare abstract class StarknetWalletConnector extends WalletConnectorBase {
32
32
  connect(): Promise<void>;
33
33
  fetchPublicAddress(): Promise<string | undefined>;
34
34
  getSigner(): Promise<AccountInterface | undefined>;
35
- getWallet(): Promise<StarknetWindowObject | undefined>;
36
35
  getWeb3Provider(): Promise<ProviderInterface | undefined>;
37
36
  signMessage(messageToSign: string): Promise<string | undefined>;
38
37
  getBalance(): Promise<string | undefined>;
39
38
  endSession(): Promise<void>;
40
- getStarknetWindowObject(): StarknetWindowObject | undefined;
39
+ getWallet(): StarknetWindowObject | undefined;
41
40
  isInstalledOnBrowser(): boolean;
42
41
  getConnectedAccounts(): Promise<string[]>;
43
42
  setupEventListeners(listeners: WalletEventListeners): void;
44
43
  teardownEventListeners(): Promise<void>;
45
- mapChainUrlToChainId(baseUrl: string): constants.StarknetChainId | undefined;
44
+ mapNetworkNameToChainId(networkName: string): constants.StarknetChainId | undefined;
46
45
  }
47
46
  export type StarknetWalletConnectorType = StarknetWalletConnector;
48
47
  export default StarknetWalletConnector;
@@ -34,7 +34,7 @@ class StarknetWalletConnector extends WalletConnectorBase {
34
34
  getNetwork() {
35
35
  var _a;
36
36
  return __awaiter(this, void 0, void 0, function* () {
37
- const wallet = yield this.getWallet();
37
+ const wallet = this.getWallet();
38
38
  if (!wallet) {
39
39
  return Promise.resolve(undefined);
40
40
  }
@@ -46,7 +46,7 @@ class StarknetWalletConnector extends WalletConnectorBase {
46
46
  }
47
47
  connect() {
48
48
  return __awaiter(this, void 0, void 0, function* () {
49
- const wallet = yield this.getWallet();
49
+ const wallet = this.getWallet();
50
50
  try {
51
51
  if (wallet && !wallet.isConnected) {
52
52
  yield wallet.enable({ starknetVersion: STARKNET_VERSION });
@@ -59,7 +59,7 @@ class StarknetWalletConnector extends WalletConnectorBase {
59
59
  }
60
60
  fetchPublicAddress() {
61
61
  return __awaiter(this, void 0, void 0, function* () {
62
- const wallet = yield this.getWallet();
62
+ const wallet = this.getWallet();
63
63
  /**
64
64
  * Fetches public address. Uses `isPreauthorized` as a temporary solution to ensure
65
65
  * the wallets store's data is read. Without it, an empty string may be returned due
@@ -72,19 +72,10 @@ class StarknetWalletConnector extends WalletConnectorBase {
72
72
  }
73
73
  getSigner() {
74
74
  return __awaiter(this, void 0, void 0, function* () {
75
- const wallet = yield this.getWallet();
75
+ const wallet = this.getWallet();
76
76
  return wallet === null || wallet === void 0 ? void 0 : wallet.account;
77
77
  });
78
78
  }
79
- getWallet() {
80
- return __awaiter(this, void 0, void 0, function* () {
81
- if (!this.wallet) {
82
- const providers = yield getStarknet().getAvailableWallets();
83
- this.wallet = providers.find((provider) => provider.name === this.name);
84
- }
85
- return this.wallet;
86
- });
87
- }
88
79
  getWeb3Provider() {
89
80
  return __awaiter(this, void 0, void 0, function* () {
90
81
  const wallet = yield this.getWallet();
@@ -93,7 +84,7 @@ class StarknetWalletConnector extends WalletConnectorBase {
93
84
  }
94
85
  signMessage(messageToSign) {
95
86
  return __awaiter(this, void 0, void 0, function* () {
96
- const wallet = yield this.getWallet();
87
+ const wallet = this.getWallet();
97
88
  const walletAddress = yield this.fetchPublicAddress();
98
89
  if (!walletAddress || !wallet) {
99
90
  logger.error('Could not fetch wallet address for signing message');
@@ -131,23 +122,25 @@ class StarknetWalletConnector extends WalletConnectorBase {
131
122
  getStarknet().disconnect({ clearLastWallet: true });
132
123
  });
133
124
  }
134
- getStarknetWindowObject() {
135
- const starknetWindowInstance = window[`starknet_${this.windowKey}`] || window['starknet'];
136
- if ((starknetWindowInstance === null || starknetWindowInstance === void 0 ? void 0 : starknetWindowInstance.name) === this.name) {
125
+ getWallet() {
126
+ let starknetWindowInstance = window[`starknet_${this.windowKey}`];
127
+ if (starknetWindowInstance !== undefined) {
137
128
  return starknetWindowInstance;
138
129
  }
139
130
  else {
140
- return undefined;
131
+ starknetWindowInstance = window['starknet'];
132
+ if ((starknetWindowInstance === null || starknetWindowInstance === void 0 ? void 0 : starknetWindowInstance.name) === this.name) {
133
+ return starknetWindowInstance;
134
+ }
141
135
  }
136
+ return undefined;
142
137
  }
143
138
  isInstalledOnBrowser() {
144
- var _a;
145
- const starknetWindowInstance = (_a = window[`starknet_${this.windowKey}`]) !== null && _a !== void 0 ? _a : window['starknet'];
146
- return (starknetWindowInstance === null || starknetWindowInstance === void 0 ? void 0 : starknetWindowInstance.name) === this.name;
139
+ return this.getWallet() !== undefined;
147
140
  }
148
141
  getConnectedAccounts() {
149
142
  return __awaiter(this, void 0, void 0, function* () {
150
- const wallet = yield this.getWallet();
143
+ const wallet = this.getWallet();
151
144
  if (!wallet) {
152
145
  return [];
153
146
  }
@@ -159,7 +152,7 @@ class StarknetWalletConnector extends WalletConnectorBase {
159
152
  });
160
153
  }
161
154
  setupEventListeners(listeners) {
162
- const wallet = this.getStarknetWindowObject();
155
+ const wallet = this.getWallet();
163
156
  if (!wallet) {
164
157
  return logger.error('Wallet has not been found');
165
158
  }
@@ -184,7 +177,7 @@ class StarknetWalletConnector extends WalletConnectorBase {
184
177
  yield ((_c = listeners.onDisconnect) === null || _c === void 0 ? void 0 : _c.call(listeners));
185
178
  return;
186
179
  }
187
- const chainId = this.mapChainUrlToChainId(network.toString());
180
+ const chainId = this.mapNetworkNameToChainId(network.toString());
188
181
  if (chainId) {
189
182
  yield ((_d = listeners.onChainChange) === null || _d === void 0 ? void 0 : _d.call(listeners, chainId));
190
183
  }
@@ -194,7 +187,7 @@ class StarknetWalletConnector extends WalletConnectorBase {
194
187
  }
195
188
  teardownEventListeners() {
196
189
  return __awaiter(this, void 0, void 0, function* () {
197
- const wallet = yield this.getWallet();
190
+ const wallet = this.getWallet();
198
191
  if (this.handleAccountChange) {
199
192
  wallet === null || wallet === void 0 ? void 0 : wallet.off(ACCOUNT_CHANGED_EVENT_LISTENER, this.handleAccountChange);
200
193
  this.handleAccountChange = undefined;
@@ -205,14 +198,19 @@ class StarknetWalletConnector extends WalletConnectorBase {
205
198
  }
206
199
  });
207
200
  }
208
- mapChainUrlToChainId(baseUrl) {
209
- if (baseUrl.includes('mainnet')) {
201
+ mapNetworkNameToChainId(networkName) {
202
+ if (networkName === constants.NetworkName.SN_MAIN ||
203
+ networkName.includes('mainnet')) {
210
204
  return constants.StarknetChainId.SN_MAIN;
211
205
  }
212
- else if (baseUrl.includes('goerli')) {
206
+ else if (networkName === constants.NetworkName.SN_GOERLI ||
207
+ networkName.includes('goerli')) {
213
208
  return constants.StarknetChainId.SN_GOERLI;
214
209
  }
215
- return undefined;
210
+ else {
211
+ logger.error('Unknown networkName', networkName);
212
+ return undefined;
213
+ }
216
214
  }
217
215
  }
218
216