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

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