@solana-mobile/wallet-adapter-mobile 0.9.2 → 0.9.4

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.
@@ -2,9 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var mobileWalletAdapterProtocolWeb3js = require('@solana-mobile/mobile-wallet-adapter-protocol-web3js');
6
5
  var walletAdapterBase = require('@solana/wallet-adapter-base');
7
6
  var web3_js = require('@solana/web3.js');
7
+ var mobileWalletAdapterProtocolWeb3js = require('@solana-mobile/mobile-wallet-adapter-protocol-web3js');
8
8
 
9
9
  /*! *****************************************************************************
10
10
  Copyright (c) Microsoft Corporation.
@@ -31,13 +31,6 @@ function __awaiter(thisArg, _arguments, P, generator) {
31
31
  });
32
32
  }
33
33
 
34
- function toUint8Array(base64EncodedByteArray) {
35
- return new Uint8Array(window
36
- .atob(base64EncodedByteArray)
37
- .split('')
38
- .map((c) => c.charCodeAt(0)));
39
- }
40
-
41
34
  function getIsSupported() {
42
35
  return (typeof window !== 'undefined' &&
43
36
  window.isSecureContext &&
@@ -45,6 +38,13 @@ function getIsSupported() {
45
38
  /android/i.test(navigator.userAgent));
46
39
  }
47
40
 
41
+ function toUint8Array(base64EncodedByteArray) {
42
+ return new Uint8Array(window
43
+ .atob(base64EncodedByteArray)
44
+ .split('')
45
+ .map((c) => c.charCodeAt(0)));
46
+ }
47
+
48
48
  const SolanaMobileWalletAdapterWalletName = 'Default wallet app';
49
49
  const SIGNATURE_LENGTH_IN_BYTES = 64;
50
50
  function getPublicKeyFromAddress(address) {
@@ -72,7 +72,7 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
72
72
  // Having a prior authorization result is, right now, the best
73
73
  // indication that a mobile wallet is installed. There is no API
74
74
  // we can use to test for whether the association URI is supported.
75
- this.emit('readyStateChange', (this._readyState = walletAdapterBase.WalletReadyState.Installed));
75
+ this.declareWalletAsInstalled();
76
76
  }
77
77
  });
78
78
  }
@@ -97,6 +97,11 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
97
97
  get readyState() {
98
98
  return this._readyState;
99
99
  }
100
+ declareWalletAsInstalled() {
101
+ if (this._readyState !== walletAdapterBase.WalletReadyState.Installed) {
102
+ this.emit('readyStateChange', (this._readyState = walletAdapterBase.WalletReadyState.Installed));
103
+ }
104
+ }
100
105
  runWithGuard(callback) {
101
106
  return __awaiter(this, void 0, void 0, function* () {
102
107
  try {
@@ -108,34 +113,59 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
108
113
  }
109
114
  });
110
115
  }
111
- connect() {
116
+ autoConnect_DO_NOT_USE_OR_YOU_WILL_BE_FIRED() {
112
117
  return __awaiter(this, void 0, void 0, function* () {
118
+ if (this.connecting || this.connected) {
119
+ return;
120
+ }
113
121
  return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
114
122
  if (this._readyState !== walletAdapterBase.WalletReadyState.Installed && this._readyState !== walletAdapterBase.WalletReadyState.Loadable) {
115
123
  throw new walletAdapterBase.WalletNotReadyError();
116
124
  }
117
125
  this._connecting = true;
118
- const cachedAuthorizationResult = yield this._authorizationResultCache.get();
119
- if (cachedAuthorizationResult) {
120
- this._authorizationResult = cachedAuthorizationResult;
121
- this._connecting = false;
122
- if (this._readyState !== walletAdapterBase.WalletReadyState.Installed) {
123
- this.emit('readyStateChange', (this._readyState = walletAdapterBase.WalletReadyState.Installed));
126
+ try {
127
+ const cachedAuthorizationResult = yield this._authorizationResultCache.get();
128
+ if (cachedAuthorizationResult) {
129
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
130
+ this.handleAuthorizationResult(cachedAuthorizationResult);
124
131
  }
125
- this._selectedAddress = yield this._addressSelector.select(cachedAuthorizationResult.accounts.map(({ address }) => address));
126
- this.emit('connect',
127
- // Having just set `this._selectedAddress`, `this.publicKey` is definitely non-null
128
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
129
- this.publicKey);
130
- return;
131
132
  }
133
+ catch (e) {
134
+ throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
135
+ }
136
+ finally {
137
+ this._connecting = false;
138
+ }
139
+ }));
140
+ });
141
+ }
142
+ connect() {
143
+ return __awaiter(this, void 0, void 0, function* () {
144
+ if (this.connecting || this.connected) {
145
+ return;
146
+ }
147
+ return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
148
+ if (this._readyState !== walletAdapterBase.WalletReadyState.Installed && this._readyState !== walletAdapterBase.WalletReadyState.Loadable) {
149
+ throw new walletAdapterBase.WalletNotReadyError();
150
+ }
151
+ this._connecting = true;
132
152
  try {
153
+ const cachedAuthorizationResult = yield this._authorizationResultCache.get();
154
+ if (cachedAuthorizationResult) {
155
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
156
+ this.handleAuthorizationResult(cachedAuthorizationResult);
157
+ return;
158
+ }
133
159
  yield this.transact((wallet) => __awaiter(this, void 0, void 0, function* () {
134
160
  const authorizationResult = yield wallet.authorize({
135
161
  cluster: this._cluster,
136
162
  identity: this._appIdentity,
137
163
  });
138
- this.handleAuthorizationResult(authorizationResult); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
164
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
165
+ Promise.all([
166
+ this._authorizationResultCache.set(authorizationResult),
167
+ this.handleAuthorizationResult(authorizationResult),
168
+ ]);
139
169
  }));
140
170
  }
141
171
  catch (e) {
@@ -158,6 +188,7 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
158
188
  // Case 3: The new list of addresses isn't exactly the same as the old list, in the same order.
159
189
  this._authorizationResult.accounts.some((account, ii) => account.address !== authorizationResult.accounts[ii].address);
160
190
  this._authorizationResult = authorizationResult;
191
+ this.declareWalletAsInstalled();
161
192
  if (didPublicKeysChange) {
162
193
  const nextSelectedAddress = yield this._addressSelector.select(authorizationResult.accounts.map(({ address }) => address));
163
194
  if (nextSelectedAddress !== this._selectedAddress) {
@@ -169,7 +200,6 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
169
200
  this.publicKey);
170
201
  }
171
202
  }
172
- yield this._authorizationResultCache.set(authorizationResult);
173
203
  });
174
204
  }
175
205
  performReauthorization(wallet, authToken) {
@@ -178,7 +208,11 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
178
208
  const authorizationResult = yield wallet.reauthorize({
179
209
  auth_token: authToken,
180
210
  });
181
- this.handleAuthorizationResult(authorizationResult); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
211
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
212
+ Promise.all([
213
+ this._authorizationResultCache.set(authorizationResult),
214
+ this.handleAuthorizationResult(authorizationResult),
215
+ ]);
182
216
  }
183
217
  catch (e) {
184
218
  this.disconnect();
package/lib/cjs/index.js CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var mobileWalletAdapterProtocolWeb3js = require('@solana-mobile/mobile-wallet-adapter-protocol-web3js');
6
5
  var walletAdapterBase = require('@solana/wallet-adapter-base');
7
6
  var web3_js = require('@solana/web3.js');
7
+ var mobileWalletAdapterProtocolWeb3js = require('@solana-mobile/mobile-wallet-adapter-protocol-web3js');
8
8
 
9
9
  /*! *****************************************************************************
10
10
  Copyright (c) Microsoft Corporation.
@@ -31,13 +31,6 @@ function __awaiter(thisArg, _arguments, P, generator) {
31
31
  });
32
32
  }
33
33
 
34
- function toUint8Array(base64EncodedByteArray) {
35
- return new Uint8Array(window
36
- .atob(base64EncodedByteArray)
37
- .split('')
38
- .map((c) => c.charCodeAt(0)));
39
- }
40
-
41
34
  function getIsSupported() {
42
35
  return (typeof window !== 'undefined' &&
43
36
  window.isSecureContext &&
@@ -45,6 +38,13 @@ function getIsSupported() {
45
38
  /android/i.test(navigator.userAgent));
46
39
  }
47
40
 
41
+ function toUint8Array(base64EncodedByteArray) {
42
+ return new Uint8Array(window
43
+ .atob(base64EncodedByteArray)
44
+ .split('')
45
+ .map((c) => c.charCodeAt(0)));
46
+ }
47
+
48
48
  const SolanaMobileWalletAdapterWalletName = 'Default wallet app';
49
49
  const SIGNATURE_LENGTH_IN_BYTES = 64;
50
50
  function getPublicKeyFromAddress(address) {
@@ -72,7 +72,7 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
72
72
  // Having a prior authorization result is, right now, the best
73
73
  // indication that a mobile wallet is installed. There is no API
74
74
  // we can use to test for whether the association URI is supported.
75
- this.emit('readyStateChange', (this._readyState = walletAdapterBase.WalletReadyState.Installed));
75
+ this.declareWalletAsInstalled();
76
76
  }
77
77
  });
78
78
  }
@@ -97,6 +97,11 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
97
97
  get readyState() {
98
98
  return this._readyState;
99
99
  }
100
+ declareWalletAsInstalled() {
101
+ if (this._readyState !== walletAdapterBase.WalletReadyState.Installed) {
102
+ this.emit('readyStateChange', (this._readyState = walletAdapterBase.WalletReadyState.Installed));
103
+ }
104
+ }
100
105
  runWithGuard(callback) {
101
106
  return __awaiter(this, void 0, void 0, function* () {
102
107
  try {
@@ -108,34 +113,59 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
108
113
  }
109
114
  });
110
115
  }
111
- connect() {
116
+ autoConnect_DO_NOT_USE_OR_YOU_WILL_BE_FIRED() {
112
117
  return __awaiter(this, void 0, void 0, function* () {
118
+ if (this.connecting || this.connected) {
119
+ return;
120
+ }
113
121
  return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
114
122
  if (this._readyState !== walletAdapterBase.WalletReadyState.Installed && this._readyState !== walletAdapterBase.WalletReadyState.Loadable) {
115
123
  throw new walletAdapterBase.WalletNotReadyError();
116
124
  }
117
125
  this._connecting = true;
118
- const cachedAuthorizationResult = yield this._authorizationResultCache.get();
119
- if (cachedAuthorizationResult) {
120
- this._authorizationResult = cachedAuthorizationResult;
121
- this._connecting = false;
122
- if (this._readyState !== walletAdapterBase.WalletReadyState.Installed) {
123
- this.emit('readyStateChange', (this._readyState = walletAdapterBase.WalletReadyState.Installed));
126
+ try {
127
+ const cachedAuthorizationResult = yield this._authorizationResultCache.get();
128
+ if (cachedAuthorizationResult) {
129
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
130
+ this.handleAuthorizationResult(cachedAuthorizationResult);
124
131
  }
125
- this._selectedAddress = yield this._addressSelector.select(cachedAuthorizationResult.accounts.map(({ address }) => address));
126
- this.emit('connect',
127
- // Having just set `this._selectedAddress`, `this.publicKey` is definitely non-null
128
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
129
- this.publicKey);
130
- return;
131
132
  }
133
+ catch (e) {
134
+ throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
135
+ }
136
+ finally {
137
+ this._connecting = false;
138
+ }
139
+ }));
140
+ });
141
+ }
142
+ connect() {
143
+ return __awaiter(this, void 0, void 0, function* () {
144
+ if (this.connecting || this.connected) {
145
+ return;
146
+ }
147
+ return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
148
+ if (this._readyState !== walletAdapterBase.WalletReadyState.Installed && this._readyState !== walletAdapterBase.WalletReadyState.Loadable) {
149
+ throw new walletAdapterBase.WalletNotReadyError();
150
+ }
151
+ this._connecting = true;
132
152
  try {
153
+ const cachedAuthorizationResult = yield this._authorizationResultCache.get();
154
+ if (cachedAuthorizationResult) {
155
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
156
+ this.handleAuthorizationResult(cachedAuthorizationResult);
157
+ return;
158
+ }
133
159
  yield this.transact((wallet) => __awaiter(this, void 0, void 0, function* () {
134
160
  const authorizationResult = yield wallet.authorize({
135
161
  cluster: this._cluster,
136
162
  identity: this._appIdentity,
137
163
  });
138
- this.handleAuthorizationResult(authorizationResult); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
164
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
165
+ Promise.all([
166
+ this._authorizationResultCache.set(authorizationResult),
167
+ this.handleAuthorizationResult(authorizationResult),
168
+ ]);
139
169
  }));
140
170
  }
141
171
  catch (e) {
@@ -158,6 +188,7 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
158
188
  // Case 3: The new list of addresses isn't exactly the same as the old list, in the same order.
159
189
  this._authorizationResult.accounts.some((account, ii) => account.address !== authorizationResult.accounts[ii].address);
160
190
  this._authorizationResult = authorizationResult;
191
+ this.declareWalletAsInstalled();
161
192
  if (didPublicKeysChange) {
162
193
  const nextSelectedAddress = yield this._addressSelector.select(authorizationResult.accounts.map(({ address }) => address));
163
194
  if (nextSelectedAddress !== this._selectedAddress) {
@@ -169,7 +200,6 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
169
200
  this.publicKey);
170
201
  }
171
202
  }
172
- yield this._authorizationResultCache.set(authorizationResult);
173
203
  });
174
204
  }
175
205
  performReauthorization(wallet, authToken) {
@@ -178,7 +208,11 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
178
208
  const authorizationResult = yield wallet.reauthorize({
179
209
  auth_token: authToken,
180
210
  });
181
- this.handleAuthorizationResult(authorizationResult); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
211
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
212
+ Promise.all([
213
+ this._authorizationResultCache.set(authorizationResult),
214
+ this.handleAuthorizationResult(authorizationResult),
215
+ ]);
182
216
  }
183
217
  catch (e) {
184
218
  this.disconnect();
@@ -2,11 +2,11 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var mobileWalletAdapterProtocolWeb3js = require('@solana-mobile/mobile-wallet-adapter-protocol-web3js');
6
5
  var walletAdapterBase = require('@solana/wallet-adapter-base');
7
6
  var web3_js = require('@solana/web3.js');
8
- var jsBase64 = require('js-base64');
7
+ var mobileWalletAdapterProtocolWeb3js = require('@solana-mobile/mobile-wallet-adapter-protocol-web3js');
9
8
  var reactNative = require('react-native');
9
+ var jsBase64 = require('js-base64');
10
10
  var AsyncStorage = require('@react-native-async-storage/async-storage');
11
11
 
12
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -69,7 +69,7 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
69
69
  // Having a prior authorization result is, right now, the best
70
70
  // indication that a mobile wallet is installed. There is no API
71
71
  // we can use to test for whether the association URI is supported.
72
- this.emit('readyStateChange', (this._readyState = walletAdapterBase.WalletReadyState.Installed));
72
+ this.declareWalletAsInstalled();
73
73
  }
74
74
  });
75
75
  }
@@ -94,6 +94,11 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
94
94
  get readyState() {
95
95
  return this._readyState;
96
96
  }
97
+ declareWalletAsInstalled() {
98
+ if (this._readyState !== walletAdapterBase.WalletReadyState.Installed) {
99
+ this.emit('readyStateChange', (this._readyState = walletAdapterBase.WalletReadyState.Installed));
100
+ }
101
+ }
97
102
  runWithGuard(callback) {
98
103
  return __awaiter(this, void 0, void 0, function* () {
99
104
  try {
@@ -105,34 +110,59 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
105
110
  }
106
111
  });
107
112
  }
108
- connect() {
113
+ autoConnect_DO_NOT_USE_OR_YOU_WILL_BE_FIRED() {
109
114
  return __awaiter(this, void 0, void 0, function* () {
115
+ if (this.connecting || this.connected) {
116
+ return;
117
+ }
110
118
  return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
111
119
  if (this._readyState !== walletAdapterBase.WalletReadyState.Installed && this._readyState !== walletAdapterBase.WalletReadyState.Loadable) {
112
120
  throw new walletAdapterBase.WalletNotReadyError();
113
121
  }
114
122
  this._connecting = true;
115
- const cachedAuthorizationResult = yield this._authorizationResultCache.get();
116
- if (cachedAuthorizationResult) {
117
- this._authorizationResult = cachedAuthorizationResult;
118
- this._connecting = false;
119
- if (this._readyState !== walletAdapterBase.WalletReadyState.Installed) {
120
- this.emit('readyStateChange', (this._readyState = walletAdapterBase.WalletReadyState.Installed));
123
+ try {
124
+ const cachedAuthorizationResult = yield this._authorizationResultCache.get();
125
+ if (cachedAuthorizationResult) {
126
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
127
+ this.handleAuthorizationResult(cachedAuthorizationResult);
121
128
  }
122
- this._selectedAddress = yield this._addressSelector.select(cachedAuthorizationResult.accounts.map(({ address }) => address));
123
- this.emit('connect',
124
- // Having just set `this._selectedAddress`, `this.publicKey` is definitely non-null
125
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
126
- this.publicKey);
127
- return;
128
129
  }
130
+ catch (e) {
131
+ throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
132
+ }
133
+ finally {
134
+ this._connecting = false;
135
+ }
136
+ }));
137
+ });
138
+ }
139
+ connect() {
140
+ return __awaiter(this, void 0, void 0, function* () {
141
+ if (this.connecting || this.connected) {
142
+ return;
143
+ }
144
+ return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
145
+ if (this._readyState !== walletAdapterBase.WalletReadyState.Installed && this._readyState !== walletAdapterBase.WalletReadyState.Loadable) {
146
+ throw new walletAdapterBase.WalletNotReadyError();
147
+ }
148
+ this._connecting = true;
129
149
  try {
150
+ const cachedAuthorizationResult = yield this._authorizationResultCache.get();
151
+ if (cachedAuthorizationResult) {
152
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
153
+ this.handleAuthorizationResult(cachedAuthorizationResult);
154
+ return;
155
+ }
130
156
  yield this.transact((wallet) => __awaiter(this, void 0, void 0, function* () {
131
157
  const authorizationResult = yield wallet.authorize({
132
158
  cluster: this._cluster,
133
159
  identity: this._appIdentity,
134
160
  });
135
- this.handleAuthorizationResult(authorizationResult); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
161
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
162
+ Promise.all([
163
+ this._authorizationResultCache.set(authorizationResult),
164
+ this.handleAuthorizationResult(authorizationResult),
165
+ ]);
136
166
  }));
137
167
  }
138
168
  catch (e) {
@@ -155,6 +185,7 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
155
185
  // Case 3: The new list of addresses isn't exactly the same as the old list, in the same order.
156
186
  this._authorizationResult.accounts.some((account, ii) => account.address !== authorizationResult.accounts[ii].address);
157
187
  this._authorizationResult = authorizationResult;
188
+ this.declareWalletAsInstalled();
158
189
  if (didPublicKeysChange) {
159
190
  const nextSelectedAddress = yield this._addressSelector.select(authorizationResult.accounts.map(({ address }) => address));
160
191
  if (nextSelectedAddress !== this._selectedAddress) {
@@ -166,7 +197,6 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
166
197
  this.publicKey);
167
198
  }
168
199
  }
169
- yield this._authorizationResultCache.set(authorizationResult);
170
200
  });
171
201
  }
172
202
  performReauthorization(wallet, authToken) {
@@ -175,7 +205,11 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
175
205
  const authorizationResult = yield wallet.reauthorize({
176
206
  auth_token: authToken,
177
207
  });
178
- this.handleAuthorizationResult(authorizationResult); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
208
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
209
+ Promise.all([
210
+ this._authorizationResultCache.set(authorizationResult),
211
+ this.handleAuthorizationResult(authorizationResult),
212
+ ]);
179
213
  }
180
214
  catch (e) {
181
215
  this.disconnect();
@@ -1,6 +1,6 @@
1
- import { transact } from '@solana-mobile/mobile-wallet-adapter-protocol-web3js';
2
1
  import { BaseMessageSignerWalletAdapter, WalletReadyState, WalletPublicKeyError, WalletNotReadyError, WalletConnectionError, WalletDisconnectedError, WalletNotConnectedError, WalletSignTransactionError, WalletSendTransactionError, WalletSignMessageError } from '@solana/wallet-adapter-base';
3
2
  import { PublicKey } from '@solana/web3.js';
3
+ import { transact } from '@solana-mobile/mobile-wallet-adapter-protocol-web3js';
4
4
 
5
5
  /*! *****************************************************************************
6
6
  Copyright (c) Microsoft Corporation.
@@ -27,13 +27,6 @@ function __awaiter(thisArg, _arguments, P, generator) {
27
27
  });
28
28
  }
29
29
 
30
- function toUint8Array(base64EncodedByteArray) {
31
- return new Uint8Array(window
32
- .atob(base64EncodedByteArray)
33
- .split('')
34
- .map((c) => c.charCodeAt(0)));
35
- }
36
-
37
30
  function getIsSupported() {
38
31
  return (typeof window !== 'undefined' &&
39
32
  window.isSecureContext &&
@@ -41,6 +34,13 @@ function getIsSupported() {
41
34
  /android/i.test(navigator.userAgent));
42
35
  }
43
36
 
37
+ function toUint8Array(base64EncodedByteArray) {
38
+ return new Uint8Array(window
39
+ .atob(base64EncodedByteArray)
40
+ .split('')
41
+ .map((c) => c.charCodeAt(0)));
42
+ }
43
+
44
44
  const SolanaMobileWalletAdapterWalletName = 'Default wallet app';
45
45
  const SIGNATURE_LENGTH_IN_BYTES = 64;
46
46
  function getPublicKeyFromAddress(address) {
@@ -68,7 +68,7 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
68
68
  // Having a prior authorization result is, right now, the best
69
69
  // indication that a mobile wallet is installed. There is no API
70
70
  // we can use to test for whether the association URI is supported.
71
- this.emit('readyStateChange', (this._readyState = WalletReadyState.Installed));
71
+ this.declareWalletAsInstalled();
72
72
  }
73
73
  });
74
74
  }
@@ -93,6 +93,11 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
93
93
  get readyState() {
94
94
  return this._readyState;
95
95
  }
96
+ declareWalletAsInstalled() {
97
+ if (this._readyState !== WalletReadyState.Installed) {
98
+ this.emit('readyStateChange', (this._readyState = WalletReadyState.Installed));
99
+ }
100
+ }
96
101
  runWithGuard(callback) {
97
102
  return __awaiter(this, void 0, void 0, function* () {
98
103
  try {
@@ -104,34 +109,59 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
104
109
  }
105
110
  });
106
111
  }
107
- connect() {
112
+ autoConnect_DO_NOT_USE_OR_YOU_WILL_BE_FIRED() {
108
113
  return __awaiter(this, void 0, void 0, function* () {
114
+ if (this.connecting || this.connected) {
115
+ return;
116
+ }
109
117
  return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
110
118
  if (this._readyState !== WalletReadyState.Installed && this._readyState !== WalletReadyState.Loadable) {
111
119
  throw new WalletNotReadyError();
112
120
  }
113
121
  this._connecting = true;
114
- const cachedAuthorizationResult = yield this._authorizationResultCache.get();
115
- if (cachedAuthorizationResult) {
116
- this._authorizationResult = cachedAuthorizationResult;
117
- this._connecting = false;
118
- if (this._readyState !== WalletReadyState.Installed) {
119
- this.emit('readyStateChange', (this._readyState = WalletReadyState.Installed));
122
+ try {
123
+ const cachedAuthorizationResult = yield this._authorizationResultCache.get();
124
+ if (cachedAuthorizationResult) {
125
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
126
+ this.handleAuthorizationResult(cachedAuthorizationResult);
120
127
  }
121
- this._selectedAddress = yield this._addressSelector.select(cachedAuthorizationResult.accounts.map(({ address }) => address));
122
- this.emit('connect',
123
- // Having just set `this._selectedAddress`, `this.publicKey` is definitely non-null
124
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
125
- this.publicKey);
126
- return;
127
128
  }
129
+ catch (e) {
130
+ throw new WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
131
+ }
132
+ finally {
133
+ this._connecting = false;
134
+ }
135
+ }));
136
+ });
137
+ }
138
+ connect() {
139
+ return __awaiter(this, void 0, void 0, function* () {
140
+ if (this.connecting || this.connected) {
141
+ return;
142
+ }
143
+ return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
144
+ if (this._readyState !== WalletReadyState.Installed && this._readyState !== WalletReadyState.Loadable) {
145
+ throw new WalletNotReadyError();
146
+ }
147
+ this._connecting = true;
128
148
  try {
149
+ const cachedAuthorizationResult = yield this._authorizationResultCache.get();
150
+ if (cachedAuthorizationResult) {
151
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
152
+ this.handleAuthorizationResult(cachedAuthorizationResult);
153
+ return;
154
+ }
129
155
  yield this.transact((wallet) => __awaiter(this, void 0, void 0, function* () {
130
156
  const authorizationResult = yield wallet.authorize({
131
157
  cluster: this._cluster,
132
158
  identity: this._appIdentity,
133
159
  });
134
- this.handleAuthorizationResult(authorizationResult); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
160
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
161
+ Promise.all([
162
+ this._authorizationResultCache.set(authorizationResult),
163
+ this.handleAuthorizationResult(authorizationResult),
164
+ ]);
135
165
  }));
136
166
  }
137
167
  catch (e) {
@@ -154,6 +184,7 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
154
184
  // Case 3: The new list of addresses isn't exactly the same as the old list, in the same order.
155
185
  this._authorizationResult.accounts.some((account, ii) => account.address !== authorizationResult.accounts[ii].address);
156
186
  this._authorizationResult = authorizationResult;
187
+ this.declareWalletAsInstalled();
157
188
  if (didPublicKeysChange) {
158
189
  const nextSelectedAddress = yield this._addressSelector.select(authorizationResult.accounts.map(({ address }) => address));
159
190
  if (nextSelectedAddress !== this._selectedAddress) {
@@ -165,7 +196,6 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
165
196
  this.publicKey);
166
197
  }
167
198
  }
168
- yield this._authorizationResultCache.set(authorizationResult);
169
199
  });
170
200
  }
171
201
  performReauthorization(wallet, authToken) {
@@ -174,7 +204,11 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
174
204
  const authorizationResult = yield wallet.reauthorize({
175
205
  auth_token: authToken,
176
206
  });
177
- this.handleAuthorizationResult(authorizationResult); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
207
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
208
+ Promise.all([
209
+ this._authorizationResultCache.set(authorizationResult),
210
+ this.handleAuthorizationResult(authorizationResult),
211
+ ]);
178
212
  }
179
213
  catch (e) {
180
214
  this.disconnect();
package/lib/esm/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { transact } from '@solana-mobile/mobile-wallet-adapter-protocol-web3js';
2
1
  import { BaseMessageSignerWalletAdapter, WalletReadyState, WalletPublicKeyError, WalletNotReadyError, WalletConnectionError, WalletDisconnectedError, WalletNotConnectedError, WalletSignTransactionError, WalletSendTransactionError, WalletSignMessageError } from '@solana/wallet-adapter-base';
3
2
  import { PublicKey } from '@solana/web3.js';
3
+ import { transact } from '@solana-mobile/mobile-wallet-adapter-protocol-web3js';
4
4
 
5
5
  /*! *****************************************************************************
6
6
  Copyright (c) Microsoft Corporation.
@@ -27,13 +27,6 @@ function __awaiter(thisArg, _arguments, P, generator) {
27
27
  });
28
28
  }
29
29
 
30
- function toUint8Array(base64EncodedByteArray) {
31
- return new Uint8Array(window
32
- .atob(base64EncodedByteArray)
33
- .split('')
34
- .map((c) => c.charCodeAt(0)));
35
- }
36
-
37
30
  function getIsSupported() {
38
31
  return (typeof window !== 'undefined' &&
39
32
  window.isSecureContext &&
@@ -41,6 +34,13 @@ function getIsSupported() {
41
34
  /android/i.test(navigator.userAgent));
42
35
  }
43
36
 
37
+ function toUint8Array(base64EncodedByteArray) {
38
+ return new Uint8Array(window
39
+ .atob(base64EncodedByteArray)
40
+ .split('')
41
+ .map((c) => c.charCodeAt(0)));
42
+ }
43
+
44
44
  const SolanaMobileWalletAdapterWalletName = 'Default wallet app';
45
45
  const SIGNATURE_LENGTH_IN_BYTES = 64;
46
46
  function getPublicKeyFromAddress(address) {
@@ -68,7 +68,7 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
68
68
  // Having a prior authorization result is, right now, the best
69
69
  // indication that a mobile wallet is installed. There is no API
70
70
  // we can use to test for whether the association URI is supported.
71
- this.emit('readyStateChange', (this._readyState = WalletReadyState.Installed));
71
+ this.declareWalletAsInstalled();
72
72
  }
73
73
  });
74
74
  }
@@ -93,6 +93,11 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
93
93
  get readyState() {
94
94
  return this._readyState;
95
95
  }
96
+ declareWalletAsInstalled() {
97
+ if (this._readyState !== WalletReadyState.Installed) {
98
+ this.emit('readyStateChange', (this._readyState = WalletReadyState.Installed));
99
+ }
100
+ }
96
101
  runWithGuard(callback) {
97
102
  return __awaiter(this, void 0, void 0, function* () {
98
103
  try {
@@ -104,34 +109,59 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
104
109
  }
105
110
  });
106
111
  }
107
- connect() {
112
+ autoConnect_DO_NOT_USE_OR_YOU_WILL_BE_FIRED() {
108
113
  return __awaiter(this, void 0, void 0, function* () {
114
+ if (this.connecting || this.connected) {
115
+ return;
116
+ }
109
117
  return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
110
118
  if (this._readyState !== WalletReadyState.Installed && this._readyState !== WalletReadyState.Loadable) {
111
119
  throw new WalletNotReadyError();
112
120
  }
113
121
  this._connecting = true;
114
- const cachedAuthorizationResult = yield this._authorizationResultCache.get();
115
- if (cachedAuthorizationResult) {
116
- this._authorizationResult = cachedAuthorizationResult;
117
- this._connecting = false;
118
- if (this._readyState !== WalletReadyState.Installed) {
119
- this.emit('readyStateChange', (this._readyState = WalletReadyState.Installed));
122
+ try {
123
+ const cachedAuthorizationResult = yield this._authorizationResultCache.get();
124
+ if (cachedAuthorizationResult) {
125
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
126
+ this.handleAuthorizationResult(cachedAuthorizationResult);
120
127
  }
121
- this._selectedAddress = yield this._addressSelector.select(cachedAuthorizationResult.accounts.map(({ address }) => address));
122
- this.emit('connect',
123
- // Having just set `this._selectedAddress`, `this.publicKey` is definitely non-null
124
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
125
- this.publicKey);
126
- return;
127
128
  }
129
+ catch (e) {
130
+ throw new WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
131
+ }
132
+ finally {
133
+ this._connecting = false;
134
+ }
135
+ }));
136
+ });
137
+ }
138
+ connect() {
139
+ return __awaiter(this, void 0, void 0, function* () {
140
+ if (this.connecting || this.connected) {
141
+ return;
142
+ }
143
+ return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
144
+ if (this._readyState !== WalletReadyState.Installed && this._readyState !== WalletReadyState.Loadable) {
145
+ throw new WalletNotReadyError();
146
+ }
147
+ this._connecting = true;
128
148
  try {
149
+ const cachedAuthorizationResult = yield this._authorizationResultCache.get();
150
+ if (cachedAuthorizationResult) {
151
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
152
+ this.handleAuthorizationResult(cachedAuthorizationResult);
153
+ return;
154
+ }
129
155
  yield this.transact((wallet) => __awaiter(this, void 0, void 0, function* () {
130
156
  const authorizationResult = yield wallet.authorize({
131
157
  cluster: this._cluster,
132
158
  identity: this._appIdentity,
133
159
  });
134
- this.handleAuthorizationResult(authorizationResult); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
160
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
161
+ Promise.all([
162
+ this._authorizationResultCache.set(authorizationResult),
163
+ this.handleAuthorizationResult(authorizationResult),
164
+ ]);
135
165
  }));
136
166
  }
137
167
  catch (e) {
@@ -154,6 +184,7 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
154
184
  // Case 3: The new list of addresses isn't exactly the same as the old list, in the same order.
155
185
  this._authorizationResult.accounts.some((account, ii) => account.address !== authorizationResult.accounts[ii].address);
156
186
  this._authorizationResult = authorizationResult;
187
+ this.declareWalletAsInstalled();
157
188
  if (didPublicKeysChange) {
158
189
  const nextSelectedAddress = yield this._addressSelector.select(authorizationResult.accounts.map(({ address }) => address));
159
190
  if (nextSelectedAddress !== this._selectedAddress) {
@@ -165,7 +196,6 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
165
196
  this.publicKey);
166
197
  }
167
198
  }
168
- yield this._authorizationResultCache.set(authorizationResult);
169
199
  });
170
200
  }
171
201
  performReauthorization(wallet, authToken) {
@@ -174,7 +204,11 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
174
204
  const authorizationResult = yield wallet.reauthorize({
175
205
  auth_token: authToken,
176
206
  });
177
- this.handleAuthorizationResult(authorizationResult); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
207
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
208
+ Promise.all([
209
+ this._authorizationResultCache.set(authorizationResult),
210
+ this.handleAuthorizationResult(authorizationResult),
211
+ ]);
178
212
  }
179
213
  catch (e) {
180
214
  this.disconnect();
@@ -35,7 +35,9 @@ declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
35
35
  get connected(): boolean;
36
36
  get connecting(): boolean;
37
37
  get readyState(): WalletReadyState;
38
+ private declareWalletAsInstalled;
38
39
  private runWithGuard;
40
+ autoConnect_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(): Promise<void>;
39
41
  connect(): Promise<void>;
40
42
  private handleAuthorizationResult;
41
43
  private performReauthorization;
@@ -1 +1 @@
1
- {"version":3,"file":"index.browser.d.mts","sourceRoot":"","sources":["../../src/index.ts","../../src/base64Utils.ts","../../src/getIsSupported.ts","../../src/adapter.ts","../../src/createDefaultAddressSelector.ts","../../src/createDefaultAuthorizationResultCache.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.browser.d.mts","sourceRoot":"","sources":["../../src/index.ts","../../src/getIsSupported.ts","../../src/base64Utils.ts","../../src/adapter.ts","../../src/createDefaultAddressSelector.ts","../../src/createDefaultAuthorizationResultCache.ts"],"names":[],"mappings":""}
@@ -35,7 +35,9 @@ declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
35
35
  get connected(): boolean;
36
36
  get connecting(): boolean;
37
37
  get readyState(): WalletReadyState;
38
+ private declareWalletAsInstalled;
38
39
  private runWithGuard;
40
+ autoConnect_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(): Promise<void>;
39
41
  connect(): Promise<void>;
40
42
  private handleAuthorizationResult;
41
43
  private performReauthorization;
@@ -1 +1 @@
1
- {"version":3,"file":"index.browser.d.ts","sourceRoot":"","sources":["../../src/index.ts","../../src/base64Utils.ts","../../src/getIsSupported.ts","../../src/adapter.ts","../../src/createDefaultAddressSelector.ts","../../src/createDefaultAuthorizationResultCache.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.browser.d.ts","sourceRoot":"","sources":["../../src/index.ts","../../src/getIsSupported.ts","../../src/base64Utils.ts","../../src/adapter.ts","../../src/createDefaultAddressSelector.ts","../../src/createDefaultAuthorizationResultCache.ts"],"names":[],"mappings":""}
@@ -35,7 +35,9 @@ declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
35
35
  get connected(): boolean;
36
36
  get connecting(): boolean;
37
37
  get readyState(): WalletReadyState;
38
+ private declareWalletAsInstalled;
38
39
  private runWithGuard;
40
+ autoConnect_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(): Promise<void>;
39
41
  connect(): Promise<void>;
40
42
  private handleAuthorizationResult;
41
43
  private performReauthorization;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/index.ts","../../src/base64Utils.ts","../../src/getIsSupported.ts","../../src/adapter.ts","../../src/createDefaultAddressSelector.ts","../../src/createDefaultAuthorizationResultCache.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/index.ts","../../src/getIsSupported.ts","../../src/base64Utils.ts","../../src/adapter.ts","../../src/createDefaultAddressSelector.ts","../../src/createDefaultAuthorizationResultCache.ts"],"names":[],"mappings":""}
@@ -35,7 +35,9 @@ declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
35
35
  get connected(): boolean;
36
36
  get connecting(): boolean;
37
37
  get readyState(): WalletReadyState;
38
+ private declareWalletAsInstalled;
38
39
  private runWithGuard;
40
+ autoConnect_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(): Promise<void>;
39
41
  connect(): Promise<void>;
40
42
  private handleAuthorizationResult;
41
43
  private performReauthorization;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts","../../src/base64Utils.ts","../../src/getIsSupported.ts","../../src/adapter.ts","../../src/createDefaultAddressSelector.ts","../../src/createDefaultAuthorizationResultCache.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts","../../src/getIsSupported.ts","../../src/base64Utils.ts","../../src/adapter.ts","../../src/createDefaultAddressSelector.ts","../../src/createDefaultAuthorizationResultCache.ts"],"names":[],"mappings":""}
@@ -35,7 +35,9 @@ declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
35
35
  get connected(): boolean;
36
36
  get connecting(): boolean;
37
37
  get readyState(): WalletReadyState;
38
+ private declareWalletAsInstalled;
38
39
  private runWithGuard;
40
+ autoConnect_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(): Promise<void>;
39
41
  connect(): Promise<void>;
40
42
  private handleAuthorizationResult;
41
43
  private performReauthorization;
@@ -1 +1 @@
1
- {"version":3,"file":"index.native.d.ts","sourceRoot":"","sources":["../../src/index.ts","../../src/base64Utils.ts","../../src/getIsSupported.ts","../../src/adapter.ts","../../src/createDefaultAddressSelector.ts","../../src/createDefaultAuthorizationResultCache.ts","../../src/__forks__/react-native/createDefaultAuthorizationResultCache.ts","../../src/__forks__/react-native/getIsSupported.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.native.d.ts","sourceRoot":"","sources":["../../src/index.ts","../../src/getIsSupported.ts","../../src/base64Utils.ts","../../src/adapter.ts","../../src/createDefaultAddressSelector.ts","../../src/createDefaultAuthorizationResultCache.ts","../../src/__forks__/react-native/createDefaultAuthorizationResultCache.ts","../../src/__forks__/react-native/getIsSupported.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@solana-mobile/wallet-adapter-mobile",
3
3
  "description": "An adapter for mobile wallet apps that conform to the Solana Mobile Wallet Adapter protocol",
4
- "version": "0.9.2",
4
+ "version": "0.9.4",
5
5
  "author": "Steven Luscher <steven.luscher@solanamobile.com>",
6
6
  "repository": "https://github.com/solana-mobile/mobile-wallet-adapter",
7
7
  "license": "Apache-2.0",
@@ -19,7 +19,7 @@
19
19
  "./package.json": "./package.json",
20
20
  ".": {
21
21
  "import": "./lib/esm/index.mjs",
22
- "require": "./lib/esm/index.cjs"
22
+ "require": "./lib/cjs/index.js"
23
23
  }
24
24
  },
25
25
  "files": [
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "@react-native-async-storage/async-storage": "^1.17.7",
44
- "@solana-mobile/mobile-wallet-adapter-protocol-web3js": "^0.9.2",
44
+ "@solana-mobile/mobile-wallet-adapter-protocol-web3js": "^0.9.4",
45
45
  "@solana/wallet-adapter-base": "^0.9.17",
46
46
  "js-base64": "^3.7.2"
47
47
  },
@@ -51,5 +51,5 @@
51
51
  "cross-env": "^7.0.3",
52
52
  "shx": "^0.3.4"
53
53
  },
54
- "gitHead": "2d6baf8692d29f164cec7f772f7a9779fe5f0220"
54
+ "gitHead": "83d9987d68083fe62de95a094bea10faa1bce5ea"
55
55
  }