@solana-mobile/wallet-adapter-mobile 0.0.1-alpha.0 → 0.0.1-alpha.1

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.
@@ -6,7 +6,7 @@ var mobileWalletAdapterProtocol = require('@solana-mobile/mobile-wallet-adapter-
6
6
  var walletAdapterBase = require('@solana/wallet-adapter-base');
7
7
  var web3_js = require('@solana/web3.js');
8
8
 
9
- /*! *****************************************************************************
9
+ /******************************************************************************
10
10
  Copyright (c) Microsoft Corporation.
11
11
 
12
12
  Permission to use, copy, modify, and/or distribute this software for any
@@ -31,13 +31,21 @@ function __awaiter(thisArg, _arguments, P, generator) {
31
31
  });
32
32
  }
33
33
 
34
+ function getIsSupported() {
35
+ return (typeof window !== 'undefined' &&
36
+ window.isSecureContext &&
37
+ typeof document !== 'undefined' &&
38
+ /android/i.test(navigator.userAgent));
39
+ }
40
+
34
41
  const SolanaMobileWalletAdapterWalletName = 'Default wallet app';
35
42
  const SIGNATURE_LENGTH_IN_BYTES = 64;
36
43
  function getBase64StringFromByteArray(byteArray) {
37
- return btoa(String.fromCharCode.call(null, ...byteArray));
44
+ return window.btoa(String.fromCharCode.call(null, ...byteArray));
38
45
  }
39
46
  function getByteArrayFromBase64String(base64EncodedByteArray) {
40
- return new Uint8Array(atob(base64EncodedByteArray)
47
+ return new Uint8Array(window
48
+ .atob(base64EncodedByteArray)
41
49
  .split('')
42
50
  .map((c) => c.charCodeAt(0)));
43
51
  }
@@ -48,12 +56,7 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
48
56
  this.url = 'https://solanamobile.com';
49
57
  this.icon = 'data:image/svg+xml;base64,PHN2ZyBmaWxsPSJub25lIiBoZWlnaHQ9IjI4IiB3aWR0aD0iMjgiIHZpZXdCb3g9Ii0zIDAgMjggMjgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGcgZmlsbD0iI0RDQjhGRiI+PHBhdGggZD0iTTE3LjQgMTcuNEgxNXYyLjRoMi40di0yLjRabTEuMi05LjZoLTIuNHYyLjRoMi40VjcuOFoiLz48cGF0aCBkPSJNMjEuNiAzVjBoLTIuNHYzaC0zLjZWMGgtMi40djNoLTIuNHY2LjZINC41YTIuMSAyLjEgMCAxIDEgMC00LjJoMi43VjNINC41QTQuNSA0LjUgMCAwIDAgMCA3LjVWMjRoMjEuNnYtNi42aC0yLjR2NC4ySDIuNFYxMS41Yy41LjMgMS4yLjQgMS44LjVoNy41QTYuNiA2LjYgMCAwIDAgMjQgOVYzaC0yLjRabTAgNS43YTQuMiA0LjIgMCAxIDEtOC40IDBWNS40aDguNHYzLjNaIi8+PC9nPjwvc3ZnPg==';
50
58
  this._connecting = false;
51
- this._readyState = typeof window === 'undefined' ||
52
- typeof document === 'undefined' ||
53
- !/android/i.test(navigator.userAgent) ||
54
- !window.isSecureContext
55
- ? walletAdapterBase.WalletReadyState.Unsupported
56
- : walletAdapterBase.WalletReadyState.Loadable;
59
+ this._readyState = getIsSupported() ? walletAdapterBase.WalletReadyState.Loadable : walletAdapterBase.WalletReadyState.Unsupported;
57
60
  this._authorizationResultCache = config.authorizationResultCache;
58
61
  this._appIdentity = config.appIdentity;
59
62
  if (this._readyState !== walletAdapterBase.WalletReadyState.Unsupported) {
package/lib/cjs/index.js CHANGED
@@ -6,7 +6,7 @@ var mobileWalletAdapterProtocol = require('@solana-mobile/mobile-wallet-adapter-
6
6
  var walletAdapterBase = require('@solana/wallet-adapter-base');
7
7
  var web3_js = require('@solana/web3.js');
8
8
 
9
- /*! *****************************************************************************
9
+ /******************************************************************************
10
10
  Copyright (c) Microsoft Corporation.
11
11
 
12
12
  Permission to use, copy, modify, and/or distribute this software for any
@@ -31,13 +31,21 @@ function __awaiter(thisArg, _arguments, P, generator) {
31
31
  });
32
32
  }
33
33
 
34
+ function getIsSupported() {
35
+ return (typeof window !== 'undefined' &&
36
+ window.isSecureContext &&
37
+ typeof document !== 'undefined' &&
38
+ /android/i.test(navigator.userAgent));
39
+ }
40
+
34
41
  const SolanaMobileWalletAdapterWalletName = 'Default wallet app';
35
42
  const SIGNATURE_LENGTH_IN_BYTES = 64;
36
43
  function getBase64StringFromByteArray(byteArray) {
37
- return btoa(String.fromCharCode.call(null, ...byteArray));
44
+ return window.btoa(String.fromCharCode.call(null, ...byteArray));
38
45
  }
39
46
  function getByteArrayFromBase64String(base64EncodedByteArray) {
40
- return new Uint8Array(atob(base64EncodedByteArray)
47
+ return new Uint8Array(window
48
+ .atob(base64EncodedByteArray)
41
49
  .split('')
42
50
  .map((c) => c.charCodeAt(0)));
43
51
  }
@@ -48,12 +56,7 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
48
56
  this.url = 'https://solanamobile.com';
49
57
  this.icon = 'data:image/svg+xml;base64,PHN2ZyBmaWxsPSJub25lIiBoZWlnaHQ9IjI4IiB3aWR0aD0iMjgiIHZpZXdCb3g9Ii0zIDAgMjggMjgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGcgZmlsbD0iI0RDQjhGRiI+PHBhdGggZD0iTTE3LjQgMTcuNEgxNXYyLjRoMi40di0yLjRabTEuMi05LjZoLTIuNHYyLjRoMi40VjcuOFoiLz48cGF0aCBkPSJNMjEuNiAzVjBoLTIuNHYzaC0zLjZWMGgtMi40djNoLTIuNHY2LjZINC41YTIuMSAyLjEgMCAxIDEgMC00LjJoMi43VjNINC41QTQuNSA0LjUgMCAwIDAgMCA3LjVWMjRoMjEuNnYtNi42aC0yLjR2NC4ySDIuNFYxMS41Yy41LjMgMS4yLjQgMS44LjVoNy41QTYuNiA2LjYgMCAwIDAgMjQgOVYzaC0yLjRabTAgNS43YTQuMiA0LjIgMCAxIDEtOC40IDBWNS40aDguNHYzLjNaIi8+PC9nPjwvc3ZnPg==';
50
58
  this._connecting = false;
51
- this._readyState = typeof window === 'undefined' ||
52
- typeof document === 'undefined' ||
53
- !/android/i.test(navigator.userAgent) ||
54
- !window.isSecureContext
55
- ? walletAdapterBase.WalletReadyState.Unsupported
56
- : walletAdapterBase.WalletReadyState.Loadable;
59
+ this._readyState = getIsSupported() ? walletAdapterBase.WalletReadyState.Loadable : walletAdapterBase.WalletReadyState.Unsupported;
57
60
  this._authorizationResultCache = config.authorizationResultCache;
58
61
  this._appIdentity = config.appIdentity;
59
62
  if (this._readyState !== walletAdapterBase.WalletReadyState.Unsupported) {
@@ -0,0 +1,335 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var mobileWalletAdapterProtocol = require('@solana-mobile/mobile-wallet-adapter-protocol');
6
+ var walletAdapterBase = require('@solana/wallet-adapter-base');
7
+ var web3_js = require('@solana/web3.js');
8
+ var reactNative = require('react-native');
9
+ var AsyncStorage = require('@react-native-community/async-storage');
10
+
11
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
12
+
13
+ var AsyncStorage__default = /*#__PURE__*/_interopDefaultLegacy(AsyncStorage);
14
+
15
+ /******************************************************************************
16
+ Copyright (c) Microsoft Corporation.
17
+
18
+ Permission to use, copy, modify, and/or distribute this software for any
19
+ purpose with or without fee is hereby granted.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
22
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
23
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
24
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
25
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
26
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
27
+ PERFORMANCE OF THIS SOFTWARE.
28
+ ***************************************************************************** */
29
+
30
+ function __awaiter(thisArg, _arguments, P, generator) {
31
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
32
+ return new (P || (P = Promise))(function (resolve, reject) {
33
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
34
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
35
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
36
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
37
+ });
38
+ }
39
+
40
+ function getIsSupported() {
41
+ return reactNative.Platform.OS === 'android';
42
+ }
43
+
44
+ const SolanaMobileWalletAdapterWalletName = 'Default wallet app';
45
+ const SIGNATURE_LENGTH_IN_BYTES = 64;
46
+ function getBase64StringFromByteArray(byteArray) {
47
+ return window.btoa(String.fromCharCode.call(null, ...byteArray));
48
+ }
49
+ function getByteArrayFromBase64String(base64EncodedByteArray) {
50
+ return new Uint8Array(window
51
+ .atob(base64EncodedByteArray)
52
+ .split('')
53
+ .map((c) => c.charCodeAt(0)));
54
+ }
55
+ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalletAdapter {
56
+ constructor(config) {
57
+ super();
58
+ this.name = SolanaMobileWalletAdapterWalletName;
59
+ this.url = 'https://solanamobile.com';
60
+ this.icon = 'data:image/svg+xml;base64,PHN2ZyBmaWxsPSJub25lIiBoZWlnaHQ9IjI4IiB3aWR0aD0iMjgiIHZpZXdCb3g9Ii0zIDAgMjggMjgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGcgZmlsbD0iI0RDQjhGRiI+PHBhdGggZD0iTTE3LjQgMTcuNEgxNXYyLjRoMi40di0yLjRabTEuMi05LjZoLTIuNHYyLjRoMi40VjcuOFoiLz48cGF0aCBkPSJNMjEuNiAzVjBoLTIuNHYzaC0zLjZWMGgtMi40djNoLTIuNHY2LjZINC41YTIuMSAyLjEgMCAxIDEgMC00LjJoMi43VjNINC41QTQuNSA0LjUgMCAwIDAgMCA3LjVWMjRoMjEuNnYtNi42aC0yLjR2NC4ySDIuNFYxMS41Yy41LjMgMS4yLjQgMS44LjVoNy41QTYuNiA2LjYgMCAwIDAgMjQgOVYzaC0yLjRabTAgNS43YTQuMiA0LjIgMCAxIDEtOC40IDBWNS40aDguNHYzLjNaIi8+PC9nPjwvc3ZnPg==';
61
+ this._connecting = false;
62
+ this._readyState = getIsSupported() ? walletAdapterBase.WalletReadyState.Loadable : walletAdapterBase.WalletReadyState.Unsupported;
63
+ this._authorizationResultCache = config.authorizationResultCache;
64
+ this._appIdentity = config.appIdentity;
65
+ if (this._readyState !== walletAdapterBase.WalletReadyState.Unsupported) {
66
+ this._authorizationResultCache.get().then((authorizationResult) => {
67
+ if (authorizationResult) {
68
+ // Having a prior authorization result is, right now, the best
69
+ // indication that a mobile wallet is installed. There is no API
70
+ // we can use to test for whether the association URI is supported.
71
+ this.emit('readyStateChange', (this._readyState = walletAdapterBase.WalletReadyState.Installed));
72
+ }
73
+ });
74
+ }
75
+ }
76
+ get publicKey() {
77
+ if (this._publicKey == null && this._authorizationResult != null) {
78
+ this._publicKey = new web3_js.PublicKey(this._authorizationResult.publicKey);
79
+ }
80
+ return this._publicKey ? this._publicKey : null;
81
+ }
82
+ get connected() {
83
+ return !!this._authorizationResult;
84
+ }
85
+ get connecting() {
86
+ return this._connecting;
87
+ }
88
+ get readyState() {
89
+ return this._readyState;
90
+ }
91
+ connect() {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ if (this._readyState !== walletAdapterBase.WalletReadyState.Installed && this._readyState !== walletAdapterBase.WalletReadyState.Loadable) {
94
+ const err = new walletAdapterBase.WalletNotReadyError();
95
+ this.emit('error', err);
96
+ throw err;
97
+ }
98
+ this._connecting = true;
99
+ const cachedAuthorizationResult = yield this._authorizationResultCache.get();
100
+ if (cachedAuthorizationResult) {
101
+ this._authorizationResult = cachedAuthorizationResult;
102
+ this._connecting = false;
103
+ if (this._readyState !== walletAdapterBase.WalletReadyState.Installed) {
104
+ this.emit('readyStateChange', (this._readyState = walletAdapterBase.WalletReadyState.Installed));
105
+ }
106
+ this.emit('connect',
107
+ // Having just set an `authorizationResult`, `this.publicKey` is definitely non-null
108
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
109
+ this.publicKey);
110
+ return;
111
+ }
112
+ try {
113
+ yield this.withWallet((mobileWallet) => __awaiter(this, void 0, void 0, function* () {
114
+ const { auth_token, pub_key: base58PublicKey, wallet_uri_base, } = yield mobileWallet('authorize', { identity: this._appIdentity });
115
+ try {
116
+ this._publicKey = new web3_js.PublicKey(base58PublicKey);
117
+ }
118
+ catch (e) {
119
+ throw new walletAdapterBase.WalletPublicKeyError((e instanceof Error && (e === null || e === void 0 ? void 0 : e.message)) || 'Unknown error', e);
120
+ }
121
+ this.handleAuthorizationResult({
122
+ authToken: auth_token,
123
+ publicKey: base58PublicKey,
124
+ walletUriBase: wallet_uri_base,
125
+ }); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
126
+ this.emit('connect',
127
+ // Having just set an `authorizationResult`, `this.publicKey` is definitely non-null
128
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
129
+ this.publicKey);
130
+ }));
131
+ }
132
+ catch (e) {
133
+ throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
134
+ }
135
+ finally {
136
+ this._connecting = false;
137
+ }
138
+ });
139
+ }
140
+ handleAuthorizationResult(authorizationResult) {
141
+ return __awaiter(this, void 0, void 0, function* () {
142
+ this._authorizationResult = authorizationResult;
143
+ yield this._authorizationResultCache.set(authorizationResult);
144
+ });
145
+ }
146
+ performReauthorization(mobileWallet, currentAuthorizationResult) {
147
+ return __awaiter(this, void 0, void 0, function* () {
148
+ try {
149
+ const { auth_token } = yield mobileWallet('reauthorize', {
150
+ auth_token: currentAuthorizationResult.authToken,
151
+ });
152
+ if (currentAuthorizationResult.authToken !== auth_token) {
153
+ this.handleAuthorizationResult(Object.assign(Object.assign({}, currentAuthorizationResult), { authToken: auth_token })); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
154
+ }
155
+ return auth_token;
156
+ }
157
+ catch (e) {
158
+ this.disconnect();
159
+ throw new walletAdapterBase.WalletDisconnectedError((e instanceof Error && (e === null || e === void 0 ? void 0 : e.message)) || 'Unknown error', e);
160
+ }
161
+ });
162
+ }
163
+ disconnect() {
164
+ return __awaiter(this, void 0, void 0, function* () {
165
+ this._authorizationResultCache.clear(); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
166
+ delete this._authorizationResult;
167
+ delete this._publicKey;
168
+ this.emit('disconnect');
169
+ });
170
+ }
171
+ withWallet(callback) {
172
+ var _a;
173
+ return __awaiter(this, void 0, void 0, function* () {
174
+ const walletUriBase = (_a = this._authorizationResult) === null || _a === void 0 ? void 0 : _a.walletUriBase;
175
+ const config = walletUriBase ? { baseUri: walletUriBase } : undefined;
176
+ return yield mobileWalletAdapterProtocol.withLocalWallet(callback, config);
177
+ });
178
+ }
179
+ assertIsAuthorized() {
180
+ const authorizationResult = this._authorizationResult;
181
+ if (!authorizationResult)
182
+ throw new walletAdapterBase.WalletNotConnectedError();
183
+ return authorizationResult;
184
+ }
185
+ performSignTransactions(transactions) {
186
+ return __awaiter(this, void 0, void 0, function* () {
187
+ try {
188
+ const authorizationResult = this.assertIsAuthorized();
189
+ try {
190
+ const serializedTransactions = transactions.map((transaction) => transaction.serialize({
191
+ requireAllSignatures: false,
192
+ verifySignatures: false,
193
+ }));
194
+ const payloads = serializedTransactions.map((serializedTransaction) => serializedTransaction.toString('base64'));
195
+ return yield this.withWallet((mobileWallet) => __awaiter(this, void 0, void 0, function* () {
196
+ const freshAuthToken = yield this.performReauthorization(mobileWallet, authorizationResult);
197
+ const { signed_payloads: base64EncodedCompiledTransactions } = yield mobileWallet('sign_transaction', { auth_token: freshAuthToken, payloads });
198
+ const compiledTransactions = base64EncodedCompiledTransactions.map(getByteArrayFromBase64String);
199
+ const transactions = compiledTransactions.map(web3_js.Transaction.from);
200
+ return transactions;
201
+ }));
202
+ }
203
+ catch (error) {
204
+ throw new walletAdapterBase.WalletSignTransactionError(error === null || error === void 0 ? void 0 : error.message, error);
205
+ }
206
+ }
207
+ catch (error) {
208
+ this.emit('error', error);
209
+ throw error;
210
+ }
211
+ });
212
+ }
213
+ sendTransaction(transaction, connection, _options) {
214
+ return __awaiter(this, void 0, void 0, function* () {
215
+ try {
216
+ const authorizationResult = this.assertIsAuthorized();
217
+ try {
218
+ if (transaction.feePayer == null) {
219
+ transaction.feePayer = this.publicKey || undefined;
220
+ }
221
+ if (transaction.recentBlockhash == null) {
222
+ const { blockhash } = yield connection.getRecentBlockhash(connection.commitment);
223
+ transaction.recentBlockhash = blockhash;
224
+ }
225
+ const serializedTransaction = transaction.serialize({
226
+ requireAllSignatures: false,
227
+ verifySignatures: false,
228
+ });
229
+ const payloads = [serializedTransaction.toString('base64')];
230
+ return yield this.withWallet((mobileWallet) => __awaiter(this, void 0, void 0, function* () {
231
+ const freshAuthToken = yield this.performReauthorization(mobileWallet, authorizationResult);
232
+ let targetCommitment;
233
+ switch (connection.commitment) {
234
+ case 'confirmed':
235
+ case 'finalized':
236
+ case 'processed':
237
+ targetCommitment = connection.commitment;
238
+ break;
239
+ default:
240
+ targetCommitment = 'finalized';
241
+ }
242
+ const { signatures } = yield mobileWallet('sign_and_send_transaction', {
243
+ auth_token: freshAuthToken,
244
+ commitment: targetCommitment,
245
+ payloads,
246
+ });
247
+ return signatures[0];
248
+ }));
249
+ }
250
+ catch (error) {
251
+ throw new walletAdapterBase.WalletSendTransactionError(error === null || error === void 0 ? void 0 : error.message, error);
252
+ }
253
+ }
254
+ catch (error) {
255
+ this.emit('error', error);
256
+ throw error;
257
+ }
258
+ });
259
+ }
260
+ signTransaction(transaction) {
261
+ return __awaiter(this, void 0, void 0, function* () {
262
+ const [signedTransaction] = yield this.performSignTransactions([transaction]);
263
+ return signedTransaction;
264
+ });
265
+ }
266
+ signAllTransactions(transactions) {
267
+ return __awaiter(this, void 0, void 0, function* () {
268
+ const signedTransactions = yield this.performSignTransactions(transactions);
269
+ return signedTransactions;
270
+ });
271
+ }
272
+ signMessage(message) {
273
+ return __awaiter(this, void 0, void 0, function* () {
274
+ try {
275
+ const authorizationResult = this.assertIsAuthorized();
276
+ try {
277
+ return yield this.withWallet((mobileWallet) => __awaiter(this, void 0, void 0, function* () {
278
+ const freshAuthToken = yield this.performReauthorization(mobileWallet, authorizationResult);
279
+ const { signed_payloads: [base64EncodedSignedMessage], } = yield mobileWallet('sign_message', {
280
+ auth_token: freshAuthToken,
281
+ payloads: [getBase64StringFromByteArray(message)],
282
+ });
283
+ const signedMessage = getByteArrayFromBase64String(base64EncodedSignedMessage);
284
+ const signature = signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES);
285
+ return signature;
286
+ }));
287
+ }
288
+ catch (error) {
289
+ throw new walletAdapterBase.WalletSignMessageError(error === null || error === void 0 ? void 0 : error.message, error);
290
+ }
291
+ }
292
+ catch (error) {
293
+ this.emit('error', error);
294
+ throw error;
295
+ }
296
+ });
297
+ }
298
+ }
299
+
300
+ const CACHE_KEY = 'SolanaMobileWalletAdapterDefaultAuthorizationCache';
301
+ function createDefaultAuthorizationResultCache() {
302
+ return {
303
+ clear() {
304
+ return __awaiter(this, void 0, void 0, function* () {
305
+ try {
306
+ yield AsyncStorage__default["default"].removeItem(CACHE_KEY);
307
+ // eslint-disable-next-line no-empty
308
+ }
309
+ catch (_a) { }
310
+ });
311
+ },
312
+ get() {
313
+ return __awaiter(this, void 0, void 0, function* () {
314
+ try {
315
+ return (JSON.parse((yield AsyncStorage__default["default"].getItem(CACHE_KEY))) || undefined);
316
+ // eslint-disable-next-line no-empty
317
+ }
318
+ catch (_a) { }
319
+ });
320
+ },
321
+ set(authorizationResult) {
322
+ return __awaiter(this, void 0, void 0, function* () {
323
+ try {
324
+ yield AsyncStorage__default["default"].setItem(CACHE_KEY, JSON.stringify(authorizationResult));
325
+ // eslint-disable-next-line no-empty
326
+ }
327
+ catch (_a) { }
328
+ });
329
+ },
330
+ };
331
+ }
332
+
333
+ exports.SolanaMobileWalletAdapter = SolanaMobileWalletAdapter;
334
+ exports.SolanaMobileWalletAdapterWalletName = SolanaMobileWalletAdapterWalletName;
335
+ exports.createDefaultAuthorizationResultCache = createDefaultAuthorizationResultCache;
@@ -2,7 +2,7 @@ import { withLocalWallet } from '@solana-mobile/mobile-wallet-adapter-protocol';
2
2
  import { BaseMessageSignerWalletAdapter, WalletReadyState, WalletNotReadyError, WalletPublicKeyError, WalletConnectionError, WalletDisconnectedError, WalletNotConnectedError, WalletSignTransactionError, WalletSendTransactionError, WalletSignMessageError } from '@solana/wallet-adapter-base';
3
3
  import { PublicKey, Transaction } from '@solana/web3.js';
4
4
 
5
- /*! *****************************************************************************
5
+ /******************************************************************************
6
6
  Copyright (c) Microsoft Corporation.
7
7
 
8
8
  Permission to use, copy, modify, and/or distribute this software for any
@@ -27,13 +27,21 @@ function __awaiter(thisArg, _arguments, P, generator) {
27
27
  });
28
28
  }
29
29
 
30
+ function getIsSupported() {
31
+ return (typeof window !== 'undefined' &&
32
+ window.isSecureContext &&
33
+ typeof document !== 'undefined' &&
34
+ /android/i.test(navigator.userAgent));
35
+ }
36
+
30
37
  const SolanaMobileWalletAdapterWalletName = 'Default wallet app';
31
38
  const SIGNATURE_LENGTH_IN_BYTES = 64;
32
39
  function getBase64StringFromByteArray(byteArray) {
33
- return btoa(String.fromCharCode.call(null, ...byteArray));
40
+ return window.btoa(String.fromCharCode.call(null, ...byteArray));
34
41
  }
35
42
  function getByteArrayFromBase64String(base64EncodedByteArray) {
36
- return new Uint8Array(atob(base64EncodedByteArray)
43
+ return new Uint8Array(window
44
+ .atob(base64EncodedByteArray)
37
45
  .split('')
38
46
  .map((c) => c.charCodeAt(0)));
39
47
  }
@@ -44,12 +52,7 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
44
52
  this.url = 'https://solanamobile.com';
45
53
  this.icon = 'data:image/svg+xml;base64,PHN2ZyBmaWxsPSJub25lIiBoZWlnaHQ9IjI4IiB3aWR0aD0iMjgiIHZpZXdCb3g9Ii0zIDAgMjggMjgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGcgZmlsbD0iI0RDQjhGRiI+PHBhdGggZD0iTTE3LjQgMTcuNEgxNXYyLjRoMi40di0yLjRabTEuMi05LjZoLTIuNHYyLjRoMi40VjcuOFoiLz48cGF0aCBkPSJNMjEuNiAzVjBoLTIuNHYzaC0zLjZWMGgtMi40djNoLTIuNHY2LjZINC41YTIuMSAyLjEgMCAxIDEgMC00LjJoMi43VjNINC41QTQuNSA0LjUgMCAwIDAgMCA3LjVWMjRoMjEuNnYtNi42aC0yLjR2NC4ySDIuNFYxMS41Yy41LjMgMS4yLjQgMS44LjVoNy41QTYuNiA2LjYgMCAwIDAgMjQgOVYzaC0yLjRabTAgNS43YTQuMiA0LjIgMCAxIDEtOC40IDBWNS40aDguNHYzLjNaIi8+PC9nPjwvc3ZnPg==';
46
54
  this._connecting = false;
47
- this._readyState = typeof window === 'undefined' ||
48
- typeof document === 'undefined' ||
49
- !/android/i.test(navigator.userAgent) ||
50
- !window.isSecureContext
51
- ? WalletReadyState.Unsupported
52
- : WalletReadyState.Loadable;
55
+ this._readyState = getIsSupported() ? WalletReadyState.Loadable : WalletReadyState.Unsupported;
53
56
  this._authorizationResultCache = config.authorizationResultCache;
54
57
  this._appIdentity = config.appIdentity;
55
58
  if (this._readyState !== WalletReadyState.Unsupported) {
package/lib/esm/index.mjs CHANGED
@@ -2,7 +2,7 @@ import { withLocalWallet } from '@solana-mobile/mobile-wallet-adapter-protocol';
2
2
  import { BaseMessageSignerWalletAdapter, WalletReadyState, WalletNotReadyError, WalletPublicKeyError, WalletConnectionError, WalletDisconnectedError, WalletNotConnectedError, WalletSignTransactionError, WalletSendTransactionError, WalletSignMessageError } from '@solana/wallet-adapter-base';
3
3
  import { PublicKey, Transaction } from '@solana/web3.js';
4
4
 
5
- /*! *****************************************************************************
5
+ /******************************************************************************
6
6
  Copyright (c) Microsoft Corporation.
7
7
 
8
8
  Permission to use, copy, modify, and/or distribute this software for any
@@ -27,13 +27,21 @@ function __awaiter(thisArg, _arguments, P, generator) {
27
27
  });
28
28
  }
29
29
 
30
+ function getIsSupported() {
31
+ return (typeof window !== 'undefined' &&
32
+ window.isSecureContext &&
33
+ typeof document !== 'undefined' &&
34
+ /android/i.test(navigator.userAgent));
35
+ }
36
+
30
37
  const SolanaMobileWalletAdapterWalletName = 'Default wallet app';
31
38
  const SIGNATURE_LENGTH_IN_BYTES = 64;
32
39
  function getBase64StringFromByteArray(byteArray) {
33
- return btoa(String.fromCharCode.call(null, ...byteArray));
40
+ return window.btoa(String.fromCharCode.call(null, ...byteArray));
34
41
  }
35
42
  function getByteArrayFromBase64String(base64EncodedByteArray) {
36
- return new Uint8Array(atob(base64EncodedByteArray)
43
+ return new Uint8Array(window
44
+ .atob(base64EncodedByteArray)
37
45
  .split('')
38
46
  .map((c) => c.charCodeAt(0)));
39
47
  }
@@ -44,12 +52,7 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
44
52
  this.url = 'https://solanamobile.com';
45
53
  this.icon = 'data:image/svg+xml;base64,PHN2ZyBmaWxsPSJub25lIiBoZWlnaHQ9IjI4IiB3aWR0aD0iMjgiIHZpZXdCb3g9Ii0zIDAgMjggMjgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGcgZmlsbD0iI0RDQjhGRiI+PHBhdGggZD0iTTE3LjQgMTcuNEgxNXYyLjRoMi40di0yLjRabTEuMi05LjZoLTIuNHYyLjRoMi40VjcuOFoiLz48cGF0aCBkPSJNMjEuNiAzVjBoLTIuNHYzaC0zLjZWMGgtMi40djNoLTIuNHY2LjZINC41YTIuMSAyLjEgMCAxIDEgMC00LjJoMi43VjNINC41QTQuNSA0LjUgMCAwIDAgMCA3LjVWMjRoMjEuNnYtNi42aC0yLjR2NC4ySDIuNFYxMS41Yy41LjMgMS4yLjQgMS44LjVoNy41QTYuNiA2LjYgMCAwIDAgMjQgOVYzaC0yLjRabTAgNS43YTQuMiA0LjIgMCAxIDEtOC40IDBWNS40aDguNHYzLjNaIi8+PC9nPjwvc3ZnPg==';
46
54
  this._connecting = false;
47
- this._readyState = typeof window === 'undefined' ||
48
- typeof document === 'undefined' ||
49
- !/android/i.test(navigator.userAgent) ||
50
- !window.isSecureContext
51
- ? WalletReadyState.Unsupported
52
- : WalletReadyState.Loadable;
55
+ this._readyState = getIsSupported() ? WalletReadyState.Loadable : WalletReadyState.Unsupported;
53
56
  this._authorizationResultCache = config.authorizationResultCache;
54
57
  this._appIdentity = config.appIdentity;
55
58
  if (this._readyState !== WalletReadyState.Unsupported) {
@@ -6,9 +6,9 @@ interface AuthorizationResultCache {
6
6
  get(): Promise<AuthorizationResult | undefined>;
7
7
  set(authorizationResult: AuthorizationResult): Promise<void>;
8
8
  }
9
- declare const SolanaMobileWalletAdapterWalletName: WalletName;
9
+ declare const SolanaMobileWalletAdapterWalletName: WalletName<string>;
10
10
  declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
11
- name: WalletName;
11
+ name: WalletName<string>;
12
12
  url: string;
13
13
  icon: string;
14
14
  private _appIdentity;
@@ -1 +1 @@
1
- {"version":3,"file":"index.browser.d.mts","sourceRoot":"","sources":["../../src/index.ts","../../src/adapter.ts","../../src/createDefaultAuthorizationResultCache.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.browser.d.mts","sourceRoot":"","sources":["../../src/index.ts","../../src/getIsSupported.ts","../../src/adapter.ts","../../src/createDefaultAuthorizationResultCache.ts"],"names":[],"mappings":""}
@@ -6,9 +6,9 @@ interface AuthorizationResultCache {
6
6
  get(): Promise<AuthorizationResult | undefined>;
7
7
  set(authorizationResult: AuthorizationResult): Promise<void>;
8
8
  }
9
- declare const SolanaMobileWalletAdapterWalletName: WalletName;
9
+ declare const SolanaMobileWalletAdapterWalletName: WalletName<string>;
10
10
  declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
11
- name: WalletName;
11
+ name: WalletName<string>;
12
12
  url: string;
13
13
  icon: string;
14
14
  private _appIdentity;
@@ -1 +1 @@
1
- {"version":3,"file":"index.browser.d.ts","sourceRoot":"","sources":["../../src/index.ts","../../src/adapter.ts","../../src/createDefaultAuthorizationResultCache.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.browser.d.ts","sourceRoot":"","sources":["../../src/index.ts","../../src/getIsSupported.ts","../../src/adapter.ts","../../src/createDefaultAuthorizationResultCache.ts"],"names":[],"mappings":""}
@@ -6,9 +6,9 @@ interface AuthorizationResultCache {
6
6
  get(): Promise<AuthorizationResult | undefined>;
7
7
  set(authorizationResult: AuthorizationResult): Promise<void>;
8
8
  }
9
- declare const SolanaMobileWalletAdapterWalletName: WalletName;
9
+ declare const SolanaMobileWalletAdapterWalletName: WalletName<string>;
10
10
  declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
11
- name: WalletName;
11
+ name: WalletName<string>;
12
12
  url: string;
13
13
  icon: string;
14
14
  private _appIdentity;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/index.ts","../../src/adapter.ts","../../src/createDefaultAuthorizationResultCache.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/index.ts","../../src/getIsSupported.ts","../../src/adapter.ts","../../src/createDefaultAuthorizationResultCache.ts"],"names":[],"mappings":""}
@@ -6,9 +6,9 @@ interface AuthorizationResultCache {
6
6
  get(): Promise<AuthorizationResult | undefined>;
7
7
  set(authorizationResult: AuthorizationResult): Promise<void>;
8
8
  }
9
- declare const SolanaMobileWalletAdapterWalletName: WalletName;
9
+ declare const SolanaMobileWalletAdapterWalletName: WalletName<string>;
10
10
  declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
11
- name: WalletName;
11
+ name: WalletName<string>;
12
12
  url: string;
13
13
  icon: string;
14
14
  private _appIdentity;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts","../../src/adapter.ts","../../src/createDefaultAuthorizationResultCache.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts","../../src/getIsSupported.ts","../../src/adapter.ts","../../src/createDefaultAuthorizationResultCache.ts"],"names":[],"mappings":""}
@@ -0,0 +1,42 @@
1
+ import { AppIdentity, AuthorizationResult } from "@solana-mobile/mobile-wallet-adapter-protocol";
2
+ import { BaseMessageSignerWalletAdapter, WalletName, WalletReadyState } from "@solana/wallet-adapter-base";
3
+ import { Connection, PublicKey, SendOptions, Transaction, TransactionSignature } from "@solana/web3.js";
4
+ interface AuthorizationResultCache {
5
+ clear(): Promise<void>;
6
+ get(): Promise<AuthorizationResult | undefined>;
7
+ set(authorizationResult: AuthorizationResult): Promise<void>;
8
+ }
9
+ declare const SolanaMobileWalletAdapterWalletName: WalletName<string>;
10
+ declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
11
+ name: WalletName<string>;
12
+ url: string;
13
+ icon: string;
14
+ private _appIdentity;
15
+ private _authorizationResult;
16
+ private _authorizationResultCache;
17
+ private _connecting;
18
+ private _publicKey;
19
+ private _readyState;
20
+ constructor(config: {
21
+ appIdentity: AppIdentity;
22
+ authorizationResultCache: AuthorizationResultCache;
23
+ });
24
+ get publicKey(): PublicKey | null;
25
+ get connected(): boolean;
26
+ get connecting(): boolean;
27
+ get readyState(): WalletReadyState;
28
+ connect(): Promise<void>;
29
+ private handleAuthorizationResult;
30
+ private performReauthorization;
31
+ disconnect(): Promise<void>;
32
+ private withWallet;
33
+ private assertIsAuthorized;
34
+ private performSignTransactions;
35
+ sendTransaction(transaction: Transaction, connection: Connection, _options?: SendOptions): Promise<TransactionSignature>;
36
+ signTransaction(transaction: Transaction): Promise<Transaction>;
37
+ signAllTransactions(transactions: Transaction[]): Promise<Transaction[]>;
38
+ signMessage(message: Uint8Array): Promise<Uint8Array>;
39
+ }
40
+ declare function createDefaultAuthorizationResultCache(): AuthorizationResultCache;
41
+ export { AuthorizationResultCache, SolanaMobileWalletAdapterWalletName, SolanaMobileWalletAdapter, createDefaultAuthorizationResultCache };
42
+ //# sourceMappingURL=index.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.native.d.ts","sourceRoot":"","sources":["../../src/index.ts","../../src/getIsSupported.ts","../../src/adapter.ts","../../src/createDefaultAuthorizationResultCache.ts","../../src/__forks__/react-native/createDefaultAuthorizationResultCache.ts","../../src/__forks__/react-native/getIsSupported.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,22 +1,26 @@
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.0.1-alpha.0",
4
+ "version": "0.0.1-alpha.1",
5
5
  "author": "Steven Luscher <steven.luscher@solanamobile.com>",
6
- "repository": "https://github.com/solana-mobile/wallet-adapter-mobile",
6
+ "repository": "https://github.com/solana-mobile/mobile-wallet-adapter",
7
7
  "license": "Apache-2.0",
8
8
  "type": "module",
9
9
  "sideEffects": false,
10
10
  "main": "lib/cjs/index.js",
11
11
  "module": "lib/esm/index.mjs",
12
+ "react-native": "lib/cjs/index.native.js",
12
13
  "types": "lib/types/index.d.ts",
13
14
  "browser": {
14
15
  "./lib/cjs/index.js": "./lib/cjs/index.browser.js",
15
16
  "./lib/esm/index.mjs": "./lib/esm/index.browser.mjs"
16
17
  },
17
18
  "exports": {
18
- "import": "./lib/esm/index.mjs",
19
- "require": "./lib/cjs/index.js"
19
+ "./package.json": "./package.json",
20
+ ".": {
21
+ "import": "./lib/esm/index.mjs",
22
+ "require": "./lib/esm/index.cjs"
23
+ }
20
24
  },
21
25
  "files": [
22
26
  "lib",
@@ -36,11 +40,14 @@
36
40
  "@solana/web3.js": "^1.36.0"
37
41
  },
38
42
  "dependencies": {
39
- "@solana-mobile/mobile-wallet-adapter-protocol": "^0.0.1-alpha.0",
40
- "@solana/wallet-adapter-base": "^0.9.0",
43
+ "@react-native-community/async-storage": "^1.12.1",
44
+ "@solana-mobile/mobile-wallet-adapter-protocol": "^0.0.1-alpha.1",
45
+ "@solana/wallet-adapter-base": "^0.9.8",
41
46
  "@solana/web3.js": "^1.20.0"
42
47
  },
43
48
  "devDependencies": {
44
- "agadoo": "^2.0.0"
45
- }
49
+ "agadoo": "^2.0.0",
50
+ "shx": "^0.3.4"
51
+ },
52
+ "gitHead": "56c859fc81d1dc009d9b49d93af440a5a3e600a9"
46
53
  }