@solana-mobile/wallet-adapter-mobile 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,106 +1,119 @@
1
- # `@solana-mobile/wallet-adapter-mobile`
2
-
3
- This is a plugin for use with [`@solana/wallet-adapter`](https://github.com/solana-labs/wallet-adapter). It enables apps to use a native wallet app on a mobile device to sign messages and transactions, and to send transactions if the wallet offers support for sending transactions.
4
-
5
- ## Usage
6
-
7
- Users of these libraries do not need to take any extra steps:
8
-
9
- * `@solana/wallet-adapter-react@">=0.15.21"`
10
-
11
- Those libraries automatically bundle the Mobile Wallet Adapter plugin, and enable it when running in a compatible mobile environment.
12
-
13
- ## Advanced usage
14
-
15
- Developers might wish to customize the behavior of this plugin for their app. Specifying the app's name and icon, deciding which address to select in the event the wallet authorizes the app to use more than one, specifying which network cluster to communicate with, and more are made possible by creating an instance of the mobile wallet adapter like this.
16
-
17
- ```typescript
18
- new SolanaMobileWalletAdapter({
19
- addressSelector: createDefaultAddressSelector(),
20
- appIdentity: {
21
- name: 'My app',
22
- uri: 'https://myapp.io',
23
- icon: 'relative/path/to/icon.png',
24
- },
25
- authorizationResultCache: createDefaultAuthorizationResultCache(),
26
- cluster: WalletAdapterNetwork.Devnet,
27
- onWalletNotFound: createDefaultWalletNotFoundHandler(),
28
- });
29
- ```
30
-
31
- Developers who use `@solana/wallet-adapter-react@">=0.15.21"` can supply this custom instance to `WalletProvider` which will use it to override the default one.
32
-
33
- ```typescript
34
- const wallets = useMemo(
35
- () => [
36
- new SolanaMobileWalletAdapter({
37
- addressSelector: createDefaultAddressSelector(),
38
- appIdentity: {
39
- name: 'My app',
40
- uri: 'https://myapp.io',
41
- icon: 'relative/path/to/icon.png',
42
- },
43
- authorizationResultCache: createDefaultAuthorizationResultCache(),
44
- cluster: WalletAdapterNetwork.Devnet,
45
- onWalletNotFound: createDefaultWalletNotFoundHandler(),
46
- }),
47
- ],
48
- [],
49
- );
50
-
51
- return (
52
- <ConnectionProvider endpoint={clusterApiUrl(WalletAdapterNetwork.Devnet)}>
53
- <WalletProvider wallets={wallets}>
54
- <MyApp />
55
- </WalletProvider>
56
- </ConnectionProvider>
57
- )
58
- ```
59
-
60
- For more information about how to use wallet adapter plugins, visit https://github.com/solana-labs/wallet-adapter
61
-
62
- ## Configuration
63
-
64
- ### App identity
65
-
66
- The `AppIdentity` config identifies your app to a native mobile wallet. When someone connects to a wallet for the first time, the wallet may present this information in the on-screen prompt where the ask if the visitor would like to authorize your app for use with their account.
67
-
68
- - `name` &ndash; The plain-language name of your application.
69
- - `uri` &ndash; The uri of your application. This uri may be required to participate in [dApp identity verification](https://github.com/solana-mobile/mobile-wallet-adapter/blob/main/spec/spec.md#dapp-identity-verification) as part of the mobile wallet adapter protocol specification.
70
- - `icon` &ndash; An icon file path, relative to the `uri`.
71
-
72
- ### Address selector
73
-
74
- The Mobile Wallet Adapter specification allows a wallet to authorize a dApp to use one or more addresses. dApps must supply code to select a single address for use in the adapter. That code must conform to the `AddressSelector` interface.
75
-
76
- ```typescript
77
- export interface AddressSelector {
78
- select(addresses: Base64EncodedAddress[]): Promise<Base64EncodedAddress>;
79
- }
80
- ```
81
-
82
- Alternatively, you can use the included `createDefaultAddressSelector()` method to create a selector that always chooses the first address in the list.
83
-
84
- ### Authorization result cache
85
-
86
- The first time that someone authorizes a native wallet app for use with your application, you should cache that authorization for future use. You can supply your own implementation that conforms to the `AuthorizationResultCache` interface.
87
-
88
- ```typescript
89
- export interface AuthorizationResultCache {
90
- clear(): Promise<void>;
91
- get(): Promise<AuthorizationResult | undefined>;
92
- set(authorizationResult: AuthorizationResult): Promise<void>;
93
- }
94
- ```
95
-
96
- Alternatively, you can use the included `createDefaultAuthorizationResultCache()` method to create a cache that reads and writes the adapter's last-obtained `AuthorizationResult` to your browser's local storage, if available.
97
-
98
- ### Cluster
99
-
100
- Each authorization a dApp makes with a wallet is tied to a particular Solana cluster. If a dApp wants to change the cluster on which to transact, it must seek an authorization for that cluster.
101
-
102
- ### Wallet-not-found handler
103
-
104
- When you call `connect()` but no wallet responds within a reasonable amount of time, it is presumed that no compatible wallet is installed. You must supply an `onWalletNotFound` function to handle this case.
105
-
106
- Alternatively, you can use the included `createDefaultWalletNotFoundHandler()` method to create a function that opens the Solana Mobile ecosystem wallets webpage.
1
+ # `@solana-mobile/wallet-adapter-mobile`
2
+
3
+ This is a plugin for use with [`@solana/wallet-adapter`](https://github.com/solana-labs/wallet-adapter). It enables apps to use a native wallet app on a mobile device to sign messages and transactions, and to send transactions if the wallet offers support for sending transactions.
4
+
5
+ ## Usage
6
+
7
+ Users of these libraries do not need to take any extra steps:
8
+
9
+ * `@solana/wallet-adapter-react@">=0.15.21"`
10
+
11
+ Those libraries automatically bundle the Mobile Wallet Adapter plugin, and enable it when running in a compatible mobile environment.
12
+
13
+ ## Advanced usage
14
+
15
+ Developers might wish to customize the behavior of this plugin for their app. Specifying the app's name and icon, deciding which address to select in the event the wallet authorizes the app to use more than one, specifying which network cluster to communicate with, and more are made possible by creating an instance of the mobile wallet adapter like this.
16
+
17
+ ```typescript
18
+ new SolanaMobileWalletAdapter({
19
+ addressSelector: createDefaultAddressSelector(),
20
+ appIdentity: {
21
+ name: 'My app',
22
+ uri: 'https://myapp.io',
23
+ icon: 'relative/path/to/icon.png',
24
+ },
25
+ authorizationResultCache: createDefaultAuthorizationResultCache(),
26
+ cluster: WalletAdapterNetwork.Devnet,
27
+ onWalletNotFound: createDefaultWalletNotFoundHandler(),
28
+ });
29
+ ```
30
+
31
+ Developers who use `@solana/wallet-adapter-react@">=0.15.21"` can supply this custom instance to `WalletProvider` which will use it to override the default one.
32
+
33
+ ```typescript
34
+ const wallets = useMemo(
35
+ () => [
36
+ new SolanaMobileWalletAdapter({
37
+ addressSelector: createDefaultAddressSelector(),
38
+ appIdentity: {
39
+ name: 'My app',
40
+ uri: 'https://myapp.io',
41
+ icon: 'relative/path/to/icon.png',
42
+ },
43
+ authorizationResultCache: createDefaultAuthorizationResultCache(),
44
+ cluster: WalletAdapterNetwork.Devnet,
45
+ onWalletNotFound: createDefaultWalletNotFoundHandler(),
46
+ }),
47
+ ],
48
+ [],
49
+ );
50
+
51
+ return (
52
+ <ConnectionProvider endpoint={clusterApiUrl(WalletAdapterNetwork.Devnet)}>
53
+ <WalletProvider wallets={wallets}>
54
+ <MyApp />
55
+ </WalletProvider>
56
+ </ConnectionProvider>
57
+ )
58
+ ```
59
+
60
+ For more information about how to use wallet adapter plugins, visit https://github.com/solana-labs/wallet-adapter
61
+
62
+ ## Configuration
63
+
64
+ ### App identity
65
+
66
+ The `AppIdentity` config identifies your app to a native mobile wallet. When someone connects to a wallet for the first time, the wallet may present this information in the on-screen prompt where the ask if the visitor would like to authorize your app for use with their account.
67
+
68
+ - `name` &ndash; The plain-language name of your application.
69
+ - `uri` &ndash; The uri of your application. This uri may be required to participate in [dApp identity verification](https://github.com/solana-mobile/mobile-wallet-adapter/blob/main/spec/spec.md#dapp-identity-verification) as part of the mobile wallet adapter protocol specification.
70
+ - `icon` &ndash; An icon file path, relative to the `uri`.
71
+
72
+ ### Address selector
73
+
74
+ The Mobile Wallet Adapter specification allows a wallet to authorize a dApp to use one or more addresses. dApps must supply code to select a single address for use in the adapter. That code must conform to the `AddressSelector` interface.
75
+
76
+ ```typescript
77
+ export interface AddressSelector {
78
+ select(addresses: Base64EncodedAddress[]): Promise<Base64EncodedAddress>;
79
+ }
80
+ ```
81
+
82
+ Alternatively, you can use the included `createDefaultAddressSelector()` method to create a selector that always chooses the first address in the list.
83
+
84
+ ### Authorization result cache
85
+
86
+ The first time that someone authorizes a native wallet app for use with your application, you should cache that authorization for future use. You can supply your own implementation that conforms to the `AuthorizationResultCache` interface.
87
+
88
+ ```typescript
89
+ export interface AuthorizationResultCache {
90
+ clear(): Promise<void>;
91
+ get(): Promise<AuthorizationResult | undefined>;
92
+ set(authorizationResult: AuthorizationResult): Promise<void>;
93
+ }
94
+ ```
95
+
96
+ Alternatively, you can use the included `createDefaultAuthorizationResultCache()` method to create a cache that reads and writes the adapter's last-obtained `AuthorizationResult` to your browser's local storage, if available.
97
+
98
+ ### Cluster
99
+
100
+ Each authorization a dApp makes with a wallet is tied to a particular Solana cluster. If a dApp wants to change the cluster on which to transact, it must seek an authorization for that cluster.
101
+
102
+ ### Wallet-not-found handler
103
+
104
+ When you call `connect()` but no wallet responds within a reasonable amount of time, it is presumed that no compatible wallet is installed. You must supply an `onWalletNotFound` function to handle this case.
105
+
106
+ Alternatively, you can use the included `createDefaultWalletNotFoundHandler()` method to create a function that opens the Solana Mobile ecosystem wallets webpage.
107
+
108
+ ## Android Chrome Browser Issues
109
+ Chrome on Android has a policy of blocking all navigation that does not come from explicit user gestures (click, tap, swipe, keypress). As a result, MWA Intent navigation to a wallet app will be blocked if it does not come from a user gesture.
110
+
111
+ You will see an error like:
112
+
113
+ ```
114
+ Navigation is blocked: solana-wallet:/v1/associate...
115
+ ```
116
+
117
+ There isn't a way around this on the Android Chrome Browser, but you can write a mobile app if you need this behavior.
118
+
119
+
@@ -54,8 +54,9 @@ function getPublicKeyFromAddress(address) {
54
54
  function isVersionedTransaction(transaction) {
55
55
  return 'version' in transaction;
56
56
  }
57
- class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalletAdapter {
57
+ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseSignInMessageSignerWalletAdapter {
58
58
  constructor(config) {
59
+ var _a;
59
60
  super();
60
61
  this.supportedTransactionVersions = new Set(
61
62
  // FIXME(#244): We can't actually know what versions are supported until we know which wallet we're talking to.
@@ -74,7 +75,7 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
74
75
  this._authorizationResultCache = config.authorizationResultCache;
75
76
  this._addressSelector = config.addressSelector;
76
77
  this._appIdentity = config.appIdentity;
77
- this._cluster = config.cluster;
78
+ this._chain = (_a = config.chain) !== null && _a !== void 0 ? _a : config.cluster;
78
79
  this._onWalletNotFound = config.onWalletNotFound;
79
80
  if (this._readyState !== walletAdapterBase.WalletReadyState.Unsupported) {
80
81
  this._authorizationResultCache.get().then((authorizationResult) => {
@@ -166,23 +167,7 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
166
167
  }
167
168
  this._connecting = true;
168
169
  try {
169
- const cachedAuthorizationResult = yield this._authorizationResultCache.get();
170
- if (cachedAuthorizationResult) {
171
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
172
- this.handleAuthorizationResult(cachedAuthorizationResult);
173
- return;
174
- }
175
- yield this.transact((wallet) => __awaiter(this, void 0, void 0, function* () {
176
- const authorizationResult = yield wallet.authorize({
177
- cluster: this._cluster,
178
- identity: this._appIdentity,
179
- });
180
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
181
- Promise.all([
182
- this._authorizationResultCache.set(authorizationResult),
183
- this.handleAuthorizationResult(authorizationResult),
184
- ]);
185
- }));
170
+ yield this.performAuthorization();
186
171
  }
187
172
  catch (e) {
188
173
  throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
@@ -193,6 +178,34 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
193
178
  }));
194
179
  });
195
180
  }
181
+ performAuthorization(signInPayload) {
182
+ return __awaiter(this, void 0, void 0, function* () {
183
+ try {
184
+ const cachedAuthorizationResult = yield this._authorizationResultCache.get();
185
+ if (cachedAuthorizationResult) {
186
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
187
+ this.handleAuthorizationResult(cachedAuthorizationResult);
188
+ return cachedAuthorizationResult;
189
+ }
190
+ return yield this.transact((wallet) => __awaiter(this, void 0, void 0, function* () {
191
+ const authorizationResult = yield wallet.authorize({
192
+ chain: this._chain,
193
+ identity: this._appIdentity,
194
+ sign_in_payload: signInPayload,
195
+ });
196
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
197
+ Promise.all([
198
+ this._authorizationResultCache.set(authorizationResult),
199
+ this.handleAuthorizationResult(authorizationResult),
200
+ ]);
201
+ return authorizationResult;
202
+ }));
203
+ }
204
+ catch (e) {
205
+ throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
206
+ }
207
+ });
208
+ }
196
209
  handleAuthorizationResult(authorizationResult) {
197
210
  var _a;
198
211
  return __awaiter(this, void 0, void 0, function* () {
@@ -221,7 +234,7 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
221
234
  performReauthorization(wallet, authToken) {
222
235
  return __awaiter(this, void 0, void 0, function* () {
223
236
  try {
224
- const authorizationResult = yield wallet.reauthorize({
237
+ const authorizationResult = yield wallet.authorize({
225
238
  auth_token: authToken,
226
239
  identity: this._appIdentity,
227
240
  });
@@ -420,6 +433,38 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
420
433
  }));
421
434
  });
422
435
  }
436
+ signIn(input) {
437
+ return __awaiter(this, void 0, void 0, function* () {
438
+ return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
439
+ var _a, _b;
440
+ if (this._readyState !== walletAdapterBase.WalletReadyState.Installed && this._readyState !== walletAdapterBase.WalletReadyState.Loadable) {
441
+ throw new walletAdapterBase.WalletNotReadyError();
442
+ }
443
+ this._connecting = true;
444
+ try {
445
+ const authorizationResult = yield this.performAuthorization(Object.assign(Object.assign({}, input), { domain: (_a = input === null || input === void 0 ? void 0 : input.domain) !== null && _a !== void 0 ? _a : window.location.host }));
446
+ if (!authorizationResult.sign_in_result) {
447
+ throw new Error("Sign in failed, no sign in result returned by wallet");
448
+ }
449
+ const signedInAddress = authorizationResult.sign_in_result.address;
450
+ const signedInAccount = Object.assign(Object.assign({}, (_b = authorizationResult.accounts.find(acc => acc.address == signedInAddress)) !== null && _b !== void 0 ? _b : {
451
+ address: signedInAddress
452
+ }), { publicKey: toUint8Array(signedInAddress) });
453
+ return {
454
+ account: signedInAccount,
455
+ signedMessage: toUint8Array(authorizationResult.sign_in_result.signed_message),
456
+ signature: toUint8Array(authorizationResult.sign_in_result.signature)
457
+ };
458
+ }
459
+ catch (e) {
460
+ throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
461
+ }
462
+ finally {
463
+ this._connecting = false;
464
+ }
465
+ }));
466
+ });
467
+ }
423
468
  }
424
469
 
425
470
  function createDefaultAddressSelector() {
package/lib/cjs/index.js CHANGED
@@ -54,8 +54,9 @@ function getPublicKeyFromAddress(address) {
54
54
  function isVersionedTransaction(transaction) {
55
55
  return 'version' in transaction;
56
56
  }
57
- class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalletAdapter {
57
+ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseSignInMessageSignerWalletAdapter {
58
58
  constructor(config) {
59
+ var _a;
59
60
  super();
60
61
  this.supportedTransactionVersions = new Set(
61
62
  // FIXME(#244): We can't actually know what versions are supported until we know which wallet we're talking to.
@@ -74,7 +75,7 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
74
75
  this._authorizationResultCache = config.authorizationResultCache;
75
76
  this._addressSelector = config.addressSelector;
76
77
  this._appIdentity = config.appIdentity;
77
- this._cluster = config.cluster;
78
+ this._chain = (_a = config.chain) !== null && _a !== void 0 ? _a : config.cluster;
78
79
  this._onWalletNotFound = config.onWalletNotFound;
79
80
  if (this._readyState !== walletAdapterBase.WalletReadyState.Unsupported) {
80
81
  this._authorizationResultCache.get().then((authorizationResult) => {
@@ -166,23 +167,7 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
166
167
  }
167
168
  this._connecting = true;
168
169
  try {
169
- const cachedAuthorizationResult = yield this._authorizationResultCache.get();
170
- if (cachedAuthorizationResult) {
171
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
172
- this.handleAuthorizationResult(cachedAuthorizationResult);
173
- return;
174
- }
175
- yield this.transact((wallet) => __awaiter(this, void 0, void 0, function* () {
176
- const authorizationResult = yield wallet.authorize({
177
- cluster: this._cluster,
178
- identity: this._appIdentity,
179
- });
180
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
181
- Promise.all([
182
- this._authorizationResultCache.set(authorizationResult),
183
- this.handleAuthorizationResult(authorizationResult),
184
- ]);
185
- }));
170
+ yield this.performAuthorization();
186
171
  }
187
172
  catch (e) {
188
173
  throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
@@ -193,6 +178,34 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
193
178
  }));
194
179
  });
195
180
  }
181
+ performAuthorization(signInPayload) {
182
+ return __awaiter(this, void 0, void 0, function* () {
183
+ try {
184
+ const cachedAuthorizationResult = yield this._authorizationResultCache.get();
185
+ if (cachedAuthorizationResult) {
186
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
187
+ this.handleAuthorizationResult(cachedAuthorizationResult);
188
+ return cachedAuthorizationResult;
189
+ }
190
+ return yield this.transact((wallet) => __awaiter(this, void 0, void 0, function* () {
191
+ const authorizationResult = yield wallet.authorize({
192
+ chain: this._chain,
193
+ identity: this._appIdentity,
194
+ sign_in_payload: signInPayload,
195
+ });
196
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
197
+ Promise.all([
198
+ this._authorizationResultCache.set(authorizationResult),
199
+ this.handleAuthorizationResult(authorizationResult),
200
+ ]);
201
+ return authorizationResult;
202
+ }));
203
+ }
204
+ catch (e) {
205
+ throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
206
+ }
207
+ });
208
+ }
196
209
  handleAuthorizationResult(authorizationResult) {
197
210
  var _a;
198
211
  return __awaiter(this, void 0, void 0, function* () {
@@ -221,7 +234,7 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
221
234
  performReauthorization(wallet, authToken) {
222
235
  return __awaiter(this, void 0, void 0, function* () {
223
236
  try {
224
- const authorizationResult = yield wallet.reauthorize({
237
+ const authorizationResult = yield wallet.authorize({
225
238
  auth_token: authToken,
226
239
  identity: this._appIdentity,
227
240
  });
@@ -420,6 +433,38 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
420
433
  }));
421
434
  });
422
435
  }
436
+ signIn(input) {
437
+ return __awaiter(this, void 0, void 0, function* () {
438
+ return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
439
+ var _a, _b;
440
+ if (this._readyState !== walletAdapterBase.WalletReadyState.Installed && this._readyState !== walletAdapterBase.WalletReadyState.Loadable) {
441
+ throw new walletAdapterBase.WalletNotReadyError();
442
+ }
443
+ this._connecting = true;
444
+ try {
445
+ const authorizationResult = yield this.performAuthorization(Object.assign(Object.assign({}, input), { domain: (_a = input === null || input === void 0 ? void 0 : input.domain) !== null && _a !== void 0 ? _a : window.location.host }));
446
+ if (!authorizationResult.sign_in_result) {
447
+ throw new Error("Sign in failed, no sign in result returned by wallet");
448
+ }
449
+ const signedInAddress = authorizationResult.sign_in_result.address;
450
+ const signedInAccount = Object.assign(Object.assign({}, (_b = authorizationResult.accounts.find(acc => acc.address == signedInAddress)) !== null && _b !== void 0 ? _b : {
451
+ address: signedInAddress
452
+ }), { publicKey: toUint8Array(signedInAddress) });
453
+ return {
454
+ account: signedInAccount,
455
+ signedMessage: toUint8Array(authorizationResult.sign_in_result.signed_message),
456
+ signature: toUint8Array(authorizationResult.sign_in_result.signature)
457
+ };
458
+ }
459
+ catch (e) {
460
+ throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
461
+ }
462
+ finally {
463
+ this._connecting = false;
464
+ }
465
+ }));
466
+ });
467
+ }
423
468
  }
424
469
 
425
470
  function createDefaultAddressSelector() {
@@ -51,8 +51,9 @@ function getPublicKeyFromAddress(address) {
51
51
  function isVersionedTransaction(transaction) {
52
52
  return 'version' in transaction;
53
53
  }
54
- class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalletAdapter {
54
+ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseSignInMessageSignerWalletAdapter {
55
55
  constructor(config) {
56
+ var _a;
56
57
  super();
57
58
  this.supportedTransactionVersions = new Set(
58
59
  // FIXME(#244): We can't actually know what versions are supported until we know which wallet we're talking to.
@@ -71,7 +72,7 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
71
72
  this._authorizationResultCache = config.authorizationResultCache;
72
73
  this._addressSelector = config.addressSelector;
73
74
  this._appIdentity = config.appIdentity;
74
- this._cluster = config.cluster;
75
+ this._chain = (_a = config.chain) !== null && _a !== void 0 ? _a : config.cluster;
75
76
  this._onWalletNotFound = config.onWalletNotFound;
76
77
  if (this._readyState !== walletAdapterBase.WalletReadyState.Unsupported) {
77
78
  this._authorizationResultCache.get().then((authorizationResult) => {
@@ -163,23 +164,7 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
163
164
  }
164
165
  this._connecting = true;
165
166
  try {
166
- const cachedAuthorizationResult = yield this._authorizationResultCache.get();
167
- if (cachedAuthorizationResult) {
168
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
169
- this.handleAuthorizationResult(cachedAuthorizationResult);
170
- return;
171
- }
172
- yield this.transact((wallet) => __awaiter(this, void 0, void 0, function* () {
173
- const authorizationResult = yield wallet.authorize({
174
- cluster: this._cluster,
175
- identity: this._appIdentity,
176
- });
177
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
178
- Promise.all([
179
- this._authorizationResultCache.set(authorizationResult),
180
- this.handleAuthorizationResult(authorizationResult),
181
- ]);
182
- }));
167
+ yield this.performAuthorization();
183
168
  }
184
169
  catch (e) {
185
170
  throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
@@ -190,6 +175,34 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
190
175
  }));
191
176
  });
192
177
  }
178
+ performAuthorization(signInPayload) {
179
+ return __awaiter(this, void 0, void 0, function* () {
180
+ try {
181
+ const cachedAuthorizationResult = yield this._authorizationResultCache.get();
182
+ if (cachedAuthorizationResult) {
183
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
184
+ this.handleAuthorizationResult(cachedAuthorizationResult);
185
+ return cachedAuthorizationResult;
186
+ }
187
+ return yield this.transact((wallet) => __awaiter(this, void 0, void 0, function* () {
188
+ const authorizationResult = yield wallet.authorize({
189
+ chain: this._chain,
190
+ identity: this._appIdentity,
191
+ sign_in_payload: signInPayload,
192
+ });
193
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
194
+ Promise.all([
195
+ this._authorizationResultCache.set(authorizationResult),
196
+ this.handleAuthorizationResult(authorizationResult),
197
+ ]);
198
+ return authorizationResult;
199
+ }));
200
+ }
201
+ catch (e) {
202
+ throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
203
+ }
204
+ });
205
+ }
193
206
  handleAuthorizationResult(authorizationResult) {
194
207
  var _a;
195
208
  return __awaiter(this, void 0, void 0, function* () {
@@ -218,7 +231,7 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
218
231
  performReauthorization(wallet, authToken) {
219
232
  return __awaiter(this, void 0, void 0, function* () {
220
233
  try {
221
- const authorizationResult = yield wallet.reauthorize({
234
+ const authorizationResult = yield wallet.authorize({
222
235
  auth_token: authToken,
223
236
  identity: this._appIdentity,
224
237
  });
@@ -417,6 +430,38 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
417
430
  }));
418
431
  });
419
432
  }
433
+ signIn(input) {
434
+ return __awaiter(this, void 0, void 0, function* () {
435
+ return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
436
+ var _a, _b;
437
+ if (this._readyState !== walletAdapterBase.WalletReadyState.Installed && this._readyState !== walletAdapterBase.WalletReadyState.Loadable) {
438
+ throw new walletAdapterBase.WalletNotReadyError();
439
+ }
440
+ this._connecting = true;
441
+ try {
442
+ const authorizationResult = yield this.performAuthorization(Object.assign(Object.assign({}, input), { domain: (_a = input === null || input === void 0 ? void 0 : input.domain) !== null && _a !== void 0 ? _a : window.location.host }));
443
+ if (!authorizationResult.sign_in_result) {
444
+ throw new Error("Sign in failed, no sign in result returned by wallet");
445
+ }
446
+ const signedInAddress = authorizationResult.sign_in_result.address;
447
+ const signedInAccount = Object.assign(Object.assign({}, (_b = authorizationResult.accounts.find(acc => acc.address == signedInAddress)) !== null && _b !== void 0 ? _b : {
448
+ address: signedInAddress
449
+ }), { publicKey: jsBase64.toUint8Array(signedInAddress) });
450
+ return {
451
+ account: signedInAccount,
452
+ signedMessage: jsBase64.toUint8Array(authorizationResult.sign_in_result.signed_message),
453
+ signature: jsBase64.toUint8Array(authorizationResult.sign_in_result.signature)
454
+ };
455
+ }
456
+ catch (e) {
457
+ throw new walletAdapterBase.WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
458
+ }
459
+ finally {
460
+ this._connecting = false;
461
+ }
462
+ }));
463
+ });
464
+ }
420
465
  }
421
466
 
422
467
  function createDefaultAddressSelector() {
@@ -1,4 +1,4 @@
1
- import { BaseMessageSignerWalletAdapter, WalletReadyState, WalletPublicKeyError, WalletNotReadyError, WalletConnectionError, WalletDisconnectedError, WalletNotConnectedError, WalletSignTransactionError, WalletSendTransactionError, WalletSignMessageError } from '@solana/wallet-adapter-base';
1
+ import { BaseSignInMessageSignerWalletAdapter, WalletReadyState, WalletPublicKeyError, WalletNotReadyError, WalletConnectionError, WalletDisconnectedError, WalletNotConnectedError, WalletSignTransactionError, WalletSendTransactionError, WalletSignMessageError } from '@solana/wallet-adapter-base';
2
2
  import { PublicKey } from '@solana/web3.js';
3
3
  import { transact } from '@solana-mobile/mobile-wallet-adapter-protocol-web3js';
4
4
 
@@ -50,8 +50,9 @@ function getPublicKeyFromAddress(address) {
50
50
  function isVersionedTransaction(transaction) {
51
51
  return 'version' in transaction;
52
52
  }
53
- class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
53
+ class SolanaMobileWalletAdapter extends BaseSignInMessageSignerWalletAdapter {
54
54
  constructor(config) {
55
+ var _a;
55
56
  super();
56
57
  this.supportedTransactionVersions = new Set(
57
58
  // FIXME(#244): We can't actually know what versions are supported until we know which wallet we're talking to.
@@ -70,7 +71,7 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
70
71
  this._authorizationResultCache = config.authorizationResultCache;
71
72
  this._addressSelector = config.addressSelector;
72
73
  this._appIdentity = config.appIdentity;
73
- this._cluster = config.cluster;
74
+ this._chain = (_a = config.chain) !== null && _a !== void 0 ? _a : config.cluster;
74
75
  this._onWalletNotFound = config.onWalletNotFound;
75
76
  if (this._readyState !== WalletReadyState.Unsupported) {
76
77
  this._authorizationResultCache.get().then((authorizationResult) => {
@@ -162,23 +163,7 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
162
163
  }
163
164
  this._connecting = true;
164
165
  try {
165
- const cachedAuthorizationResult = yield this._authorizationResultCache.get();
166
- if (cachedAuthorizationResult) {
167
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
168
- this.handleAuthorizationResult(cachedAuthorizationResult);
169
- return;
170
- }
171
- yield this.transact((wallet) => __awaiter(this, void 0, void 0, function* () {
172
- const authorizationResult = yield wallet.authorize({
173
- cluster: this._cluster,
174
- identity: this._appIdentity,
175
- });
176
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
177
- Promise.all([
178
- this._authorizationResultCache.set(authorizationResult),
179
- this.handleAuthorizationResult(authorizationResult),
180
- ]);
181
- }));
166
+ yield this.performAuthorization();
182
167
  }
183
168
  catch (e) {
184
169
  throw new WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
@@ -189,6 +174,34 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
189
174
  }));
190
175
  });
191
176
  }
177
+ performAuthorization(signInPayload) {
178
+ return __awaiter(this, void 0, void 0, function* () {
179
+ try {
180
+ const cachedAuthorizationResult = yield this._authorizationResultCache.get();
181
+ if (cachedAuthorizationResult) {
182
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
183
+ this.handleAuthorizationResult(cachedAuthorizationResult);
184
+ return cachedAuthorizationResult;
185
+ }
186
+ return yield this.transact((wallet) => __awaiter(this, void 0, void 0, function* () {
187
+ const authorizationResult = yield wallet.authorize({
188
+ chain: this._chain,
189
+ identity: this._appIdentity,
190
+ sign_in_payload: signInPayload,
191
+ });
192
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
193
+ Promise.all([
194
+ this._authorizationResultCache.set(authorizationResult),
195
+ this.handleAuthorizationResult(authorizationResult),
196
+ ]);
197
+ return authorizationResult;
198
+ }));
199
+ }
200
+ catch (e) {
201
+ throw new WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
202
+ }
203
+ });
204
+ }
192
205
  handleAuthorizationResult(authorizationResult) {
193
206
  var _a;
194
207
  return __awaiter(this, void 0, void 0, function* () {
@@ -217,7 +230,7 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
217
230
  performReauthorization(wallet, authToken) {
218
231
  return __awaiter(this, void 0, void 0, function* () {
219
232
  try {
220
- const authorizationResult = yield wallet.reauthorize({
233
+ const authorizationResult = yield wallet.authorize({
221
234
  auth_token: authToken,
222
235
  identity: this._appIdentity,
223
236
  });
@@ -416,6 +429,38 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
416
429
  }));
417
430
  });
418
431
  }
432
+ signIn(input) {
433
+ return __awaiter(this, void 0, void 0, function* () {
434
+ return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
435
+ var _a, _b;
436
+ if (this._readyState !== WalletReadyState.Installed && this._readyState !== WalletReadyState.Loadable) {
437
+ throw new WalletNotReadyError();
438
+ }
439
+ this._connecting = true;
440
+ try {
441
+ const authorizationResult = yield this.performAuthorization(Object.assign(Object.assign({}, input), { domain: (_a = input === null || input === void 0 ? void 0 : input.domain) !== null && _a !== void 0 ? _a : window.location.host }));
442
+ if (!authorizationResult.sign_in_result) {
443
+ throw new Error("Sign in failed, no sign in result returned by wallet");
444
+ }
445
+ const signedInAddress = authorizationResult.sign_in_result.address;
446
+ const signedInAccount = Object.assign(Object.assign({}, (_b = authorizationResult.accounts.find(acc => acc.address == signedInAddress)) !== null && _b !== void 0 ? _b : {
447
+ address: signedInAddress
448
+ }), { publicKey: toUint8Array(signedInAddress) });
449
+ return {
450
+ account: signedInAccount,
451
+ signedMessage: toUint8Array(authorizationResult.sign_in_result.signed_message),
452
+ signature: toUint8Array(authorizationResult.sign_in_result.signature)
453
+ };
454
+ }
455
+ catch (e) {
456
+ throw new WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
457
+ }
458
+ finally {
459
+ this._connecting = false;
460
+ }
461
+ }));
462
+ });
463
+ }
419
464
  }
420
465
 
421
466
  function createDefaultAddressSelector() {
package/lib/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { BaseMessageSignerWalletAdapter, WalletReadyState, WalletPublicKeyError, WalletNotReadyError, WalletConnectionError, WalletDisconnectedError, WalletNotConnectedError, WalletSignTransactionError, WalletSendTransactionError, WalletSignMessageError } from '@solana/wallet-adapter-base';
1
+ import { BaseSignInMessageSignerWalletAdapter, WalletReadyState, WalletPublicKeyError, WalletNotReadyError, WalletConnectionError, WalletDisconnectedError, WalletNotConnectedError, WalletSignTransactionError, WalletSendTransactionError, WalletSignMessageError } from '@solana/wallet-adapter-base';
2
2
  import { PublicKey } from '@solana/web3.js';
3
3
  import { transact } from '@solana-mobile/mobile-wallet-adapter-protocol-web3js';
4
4
 
@@ -50,8 +50,9 @@ function getPublicKeyFromAddress(address) {
50
50
  function isVersionedTransaction(transaction) {
51
51
  return 'version' in transaction;
52
52
  }
53
- class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
53
+ class SolanaMobileWalletAdapter extends BaseSignInMessageSignerWalletAdapter {
54
54
  constructor(config) {
55
+ var _a;
55
56
  super();
56
57
  this.supportedTransactionVersions = new Set(
57
58
  // FIXME(#244): We can't actually know what versions are supported until we know which wallet we're talking to.
@@ -70,7 +71,7 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
70
71
  this._authorizationResultCache = config.authorizationResultCache;
71
72
  this._addressSelector = config.addressSelector;
72
73
  this._appIdentity = config.appIdentity;
73
- this._cluster = config.cluster;
74
+ this._chain = (_a = config.chain) !== null && _a !== void 0 ? _a : config.cluster;
74
75
  this._onWalletNotFound = config.onWalletNotFound;
75
76
  if (this._readyState !== WalletReadyState.Unsupported) {
76
77
  this._authorizationResultCache.get().then((authorizationResult) => {
@@ -162,23 +163,7 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
162
163
  }
163
164
  this._connecting = true;
164
165
  try {
165
- const cachedAuthorizationResult = yield this._authorizationResultCache.get();
166
- if (cachedAuthorizationResult) {
167
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
168
- this.handleAuthorizationResult(cachedAuthorizationResult);
169
- return;
170
- }
171
- yield this.transact((wallet) => __awaiter(this, void 0, void 0, function* () {
172
- const authorizationResult = yield wallet.authorize({
173
- cluster: this._cluster,
174
- identity: this._appIdentity,
175
- });
176
- // TODO: Evaluate whether there's any threat to not `awaiting` this expression
177
- Promise.all([
178
- this._authorizationResultCache.set(authorizationResult),
179
- this.handleAuthorizationResult(authorizationResult),
180
- ]);
181
- }));
166
+ yield this.performAuthorization();
182
167
  }
183
168
  catch (e) {
184
169
  throw new WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
@@ -189,6 +174,34 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
189
174
  }));
190
175
  });
191
176
  }
177
+ performAuthorization(signInPayload) {
178
+ return __awaiter(this, void 0, void 0, function* () {
179
+ try {
180
+ const cachedAuthorizationResult = yield this._authorizationResultCache.get();
181
+ if (cachedAuthorizationResult) {
182
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
183
+ this.handleAuthorizationResult(cachedAuthorizationResult);
184
+ return cachedAuthorizationResult;
185
+ }
186
+ return yield this.transact((wallet) => __awaiter(this, void 0, void 0, function* () {
187
+ const authorizationResult = yield wallet.authorize({
188
+ chain: this._chain,
189
+ identity: this._appIdentity,
190
+ sign_in_payload: signInPayload,
191
+ });
192
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
193
+ Promise.all([
194
+ this._authorizationResultCache.set(authorizationResult),
195
+ this.handleAuthorizationResult(authorizationResult),
196
+ ]);
197
+ return authorizationResult;
198
+ }));
199
+ }
200
+ catch (e) {
201
+ throw new WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
202
+ }
203
+ });
204
+ }
192
205
  handleAuthorizationResult(authorizationResult) {
193
206
  var _a;
194
207
  return __awaiter(this, void 0, void 0, function* () {
@@ -217,7 +230,7 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
217
230
  performReauthorization(wallet, authToken) {
218
231
  return __awaiter(this, void 0, void 0, function* () {
219
232
  try {
220
- const authorizationResult = yield wallet.reauthorize({
233
+ const authorizationResult = yield wallet.authorize({
221
234
  auth_token: authToken,
222
235
  identity: this._appIdentity,
223
236
  });
@@ -416,6 +429,38 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
416
429
  }));
417
430
  });
418
431
  }
432
+ signIn(input) {
433
+ return __awaiter(this, void 0, void 0, function* () {
434
+ return yield this.runWithGuard(() => __awaiter(this, void 0, void 0, function* () {
435
+ var _a, _b;
436
+ if (this._readyState !== WalletReadyState.Installed && this._readyState !== WalletReadyState.Loadable) {
437
+ throw new WalletNotReadyError();
438
+ }
439
+ this._connecting = true;
440
+ try {
441
+ const authorizationResult = yield this.performAuthorization(Object.assign(Object.assign({}, input), { domain: (_a = input === null || input === void 0 ? void 0 : input.domain) !== null && _a !== void 0 ? _a : window.location.host }));
442
+ if (!authorizationResult.sign_in_result) {
443
+ throw new Error("Sign in failed, no sign in result returned by wallet");
444
+ }
445
+ const signedInAddress = authorizationResult.sign_in_result.address;
446
+ const signedInAccount = Object.assign(Object.assign({}, (_b = authorizationResult.accounts.find(acc => acc.address == signedInAddress)) !== null && _b !== void 0 ? _b : {
447
+ address: signedInAddress
448
+ }), { publicKey: toUint8Array(signedInAddress) });
449
+ return {
450
+ account: signedInAccount,
451
+ signedMessage: toUint8Array(authorizationResult.sign_in_result.signed_message),
452
+ signature: toUint8Array(authorizationResult.sign_in_result.signature)
453
+ };
454
+ }
455
+ catch (e) {
456
+ throw new WalletConnectionError((e instanceof Error && e.message) || 'Unknown error', e);
457
+ }
458
+ finally {
459
+ this._connecting = false;
460
+ }
461
+ }));
462
+ });
463
+ }
419
464
  }
420
465
 
421
466
  function createDefaultAddressSelector() {
@@ -1,7 +1,8 @@
1
- import { BaseMessageSignerWalletAdapter, WalletName, WalletReadyState } from "@solana/wallet-adapter-base";
1
+ import { BaseSignInMessageSignerWalletAdapter, WalletName, WalletReadyState } from "@solana/wallet-adapter-base";
2
2
  import { Connection, PublicKey, SendOptions, TransactionSignature, TransactionVersion, VersionedTransaction } from "@solana/web3.js";
3
3
  import { Transaction as LegacyTransaction } from "@solana/web3.js";
4
- import { AppIdentity, AuthorizationResult, Base64EncodedAddress, Cluster } from "@solana-mobile/mobile-wallet-adapter-protocol";
4
+ import { AppIdentity, AuthorizationResult, Base64EncodedAddress, Chain, Cluster, SignInPayload } from "@solana-mobile/mobile-wallet-adapter-protocol";
5
+ import { SolanaSignInInput, SolanaSignInOutput } from "@solana/wallet-standard-features";
5
6
  interface AuthorizationResultCache {
6
7
  clear(): Promise<void>;
7
8
  get(): Promise<AuthorizationResult | undefined>;
@@ -11,7 +12,7 @@ interface AddressSelector {
11
12
  select(addresses: Base64EncodedAddress[]): Promise<Base64EncodedAddress>;
12
13
  }
13
14
  declare const SolanaMobileWalletAdapterWalletName: WalletName<string>;
14
- declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
15
+ declare class SolanaMobileWalletAdapter extends BaseSignInMessageSignerWalletAdapter {
15
16
  readonly supportedTransactionVersions: Set<TransactionVersion>;
16
17
  name: WalletName<string>;
17
18
  url: string;
@@ -27,11 +28,14 @@ declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
27
28
  * 'generation' don't continue to do work and throw exceptions.
28
29
  */
29
30
  private _connectionGeneration;
30
- private _cluster;
31
+ private _chain;
31
32
  private _onWalletNotFound;
32
33
  private _publicKey;
33
34
  private _readyState;
34
35
  private _selectedAddress;
36
+ /**
37
+ * @deprecated @param cluster config paramter is deprecated, use @param chain instead
38
+ */
35
39
  constructor(config: {
36
40
  addressSelector: AddressSelector;
37
41
  appIdentity: AppIdentity;
@@ -39,6 +43,13 @@ declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
39
43
  cluster: Cluster;
40
44
  onWalletNotFound: (mobileWalletAdapter: SolanaMobileWalletAdapter) => Promise<void>;
41
45
  });
46
+ constructor(config: {
47
+ addressSelector: AddressSelector;
48
+ appIdentity: AppIdentity;
49
+ authorizationResultCache: AuthorizationResultCache;
50
+ chain: Chain;
51
+ onWalletNotFound: (mobileWalletAdapter: SolanaMobileWalletAdapter) => Promise<void>;
52
+ });
42
53
  get publicKey(): PublicKey | null;
43
54
  get connected(): boolean;
44
55
  get connecting(): boolean;
@@ -49,6 +60,7 @@ declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
49
60
  autoConnect_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(): Promise<void>;
50
61
  autoConnect(): Promise<void>;
51
62
  connect(): Promise<void>;
63
+ performAuthorization(signInPayload?: SignInPayload): Promise<AuthorizationResult>;
52
64
  private handleAuthorizationResult;
53
65
  private performReauthorization;
54
66
  disconnect(): Promise<void>;
@@ -59,6 +71,7 @@ declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
59
71
  signTransaction<T extends LegacyTransaction | VersionedTransaction>(transaction: T): Promise<T>;
60
72
  signAllTransactions<T extends LegacyTransaction | VersionedTransaction>(transactions: T[]): Promise<T[]>;
61
73
  signMessage(message: Uint8Array): Promise<Uint8Array>;
74
+ signIn(input?: SolanaSignInInput): Promise<SolanaSignInOutput>;
62
75
  }
63
76
  declare function createDefaultAddressSelector(): AddressSelector;
64
77
  declare function createDefaultAuthorizationResultCache(): AuthorizationResultCache;
@@ -1,7 +1,8 @@
1
- import { BaseMessageSignerWalletAdapter, WalletName, WalletReadyState } from "@solana/wallet-adapter-base";
1
+ import { BaseSignInMessageSignerWalletAdapter, WalletName, WalletReadyState } from "@solana/wallet-adapter-base";
2
2
  import { Connection, PublicKey, SendOptions, TransactionSignature, TransactionVersion, VersionedTransaction } from "@solana/web3.js";
3
3
  import { Transaction as LegacyTransaction } from "@solana/web3.js";
4
- import { AppIdentity, AuthorizationResult, Base64EncodedAddress, Cluster } from "@solana-mobile/mobile-wallet-adapter-protocol";
4
+ import { AppIdentity, AuthorizationResult, Base64EncodedAddress, Chain, Cluster, SignInPayload } from "@solana-mobile/mobile-wallet-adapter-protocol";
5
+ import { SolanaSignInInput, SolanaSignInOutput } from "@solana/wallet-standard-features";
5
6
  interface AuthorizationResultCache {
6
7
  clear(): Promise<void>;
7
8
  get(): Promise<AuthorizationResult | undefined>;
@@ -11,7 +12,7 @@ interface AddressSelector {
11
12
  select(addresses: Base64EncodedAddress[]): Promise<Base64EncodedAddress>;
12
13
  }
13
14
  declare const SolanaMobileWalletAdapterWalletName: WalletName<string>;
14
- declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
15
+ declare class SolanaMobileWalletAdapter extends BaseSignInMessageSignerWalletAdapter {
15
16
  readonly supportedTransactionVersions: Set<TransactionVersion>;
16
17
  name: WalletName<string>;
17
18
  url: string;
@@ -27,11 +28,14 @@ declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
27
28
  * 'generation' don't continue to do work and throw exceptions.
28
29
  */
29
30
  private _connectionGeneration;
30
- private _cluster;
31
+ private _chain;
31
32
  private _onWalletNotFound;
32
33
  private _publicKey;
33
34
  private _readyState;
34
35
  private _selectedAddress;
36
+ /**
37
+ * @deprecated @param cluster config paramter is deprecated, use @param chain instead
38
+ */
35
39
  constructor(config: {
36
40
  addressSelector: AddressSelector;
37
41
  appIdentity: AppIdentity;
@@ -39,6 +43,13 @@ declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
39
43
  cluster: Cluster;
40
44
  onWalletNotFound: (mobileWalletAdapter: SolanaMobileWalletAdapter) => Promise<void>;
41
45
  });
46
+ constructor(config: {
47
+ addressSelector: AddressSelector;
48
+ appIdentity: AppIdentity;
49
+ authorizationResultCache: AuthorizationResultCache;
50
+ chain: Chain;
51
+ onWalletNotFound: (mobileWalletAdapter: SolanaMobileWalletAdapter) => Promise<void>;
52
+ });
42
53
  get publicKey(): PublicKey | null;
43
54
  get connected(): boolean;
44
55
  get connecting(): boolean;
@@ -49,6 +60,7 @@ declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
49
60
  autoConnect_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(): Promise<void>;
50
61
  autoConnect(): Promise<void>;
51
62
  connect(): Promise<void>;
63
+ performAuthorization(signInPayload?: SignInPayload): Promise<AuthorizationResult>;
52
64
  private handleAuthorizationResult;
53
65
  private performReauthorization;
54
66
  disconnect(): Promise<void>;
@@ -59,6 +71,7 @@ declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
59
71
  signTransaction<T extends LegacyTransaction | VersionedTransaction>(transaction: T): Promise<T>;
60
72
  signAllTransactions<T extends LegacyTransaction | VersionedTransaction>(transactions: T[]): Promise<T[]>;
61
73
  signMessage(message: Uint8Array): Promise<Uint8Array>;
74
+ signIn(input?: SolanaSignInInput): Promise<SolanaSignInOutput>;
62
75
  }
63
76
  declare function createDefaultAddressSelector(): AddressSelector;
64
77
  declare function createDefaultAuthorizationResultCache(): AuthorizationResultCache;
@@ -1,7 +1,8 @@
1
- import { BaseMessageSignerWalletAdapter, WalletName, WalletReadyState } from "@solana/wallet-adapter-base";
1
+ import { BaseSignInMessageSignerWalletAdapter, WalletName, WalletReadyState } from "@solana/wallet-adapter-base";
2
2
  import { Connection, PublicKey, SendOptions, TransactionSignature, TransactionVersion, VersionedTransaction } from "@solana/web3.js";
3
3
  import { Transaction as LegacyTransaction } from "@solana/web3.js";
4
- import { AppIdentity, AuthorizationResult, Base64EncodedAddress, Cluster } from "@solana-mobile/mobile-wallet-adapter-protocol";
4
+ import { AppIdentity, AuthorizationResult, Base64EncodedAddress, Chain, Cluster, SignInPayload } from "@solana-mobile/mobile-wallet-adapter-protocol";
5
+ import { SolanaSignInInput, SolanaSignInOutput } from "@solana/wallet-standard-features";
5
6
  interface AuthorizationResultCache {
6
7
  clear(): Promise<void>;
7
8
  get(): Promise<AuthorizationResult | undefined>;
@@ -11,7 +12,7 @@ interface AddressSelector {
11
12
  select(addresses: Base64EncodedAddress[]): Promise<Base64EncodedAddress>;
12
13
  }
13
14
  declare const SolanaMobileWalletAdapterWalletName: WalletName<string>;
14
- declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
15
+ declare class SolanaMobileWalletAdapter extends BaseSignInMessageSignerWalletAdapter {
15
16
  readonly supportedTransactionVersions: Set<TransactionVersion>;
16
17
  name: WalletName<string>;
17
18
  url: string;
@@ -27,11 +28,14 @@ declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
27
28
  * 'generation' don't continue to do work and throw exceptions.
28
29
  */
29
30
  private _connectionGeneration;
30
- private _cluster;
31
+ private _chain;
31
32
  private _onWalletNotFound;
32
33
  private _publicKey;
33
34
  private _readyState;
34
35
  private _selectedAddress;
36
+ /**
37
+ * @deprecated @param cluster config paramter is deprecated, use @param chain instead
38
+ */
35
39
  constructor(config: {
36
40
  addressSelector: AddressSelector;
37
41
  appIdentity: AppIdentity;
@@ -39,6 +43,13 @@ declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
39
43
  cluster: Cluster;
40
44
  onWalletNotFound: (mobileWalletAdapter: SolanaMobileWalletAdapter) => Promise<void>;
41
45
  });
46
+ constructor(config: {
47
+ addressSelector: AddressSelector;
48
+ appIdentity: AppIdentity;
49
+ authorizationResultCache: AuthorizationResultCache;
50
+ chain: Chain;
51
+ onWalletNotFound: (mobileWalletAdapter: SolanaMobileWalletAdapter) => Promise<void>;
52
+ });
42
53
  get publicKey(): PublicKey | null;
43
54
  get connected(): boolean;
44
55
  get connecting(): boolean;
@@ -49,6 +60,7 @@ declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
49
60
  autoConnect_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(): Promise<void>;
50
61
  autoConnect(): Promise<void>;
51
62
  connect(): Promise<void>;
63
+ performAuthorization(signInPayload?: SignInPayload): Promise<AuthorizationResult>;
52
64
  private handleAuthorizationResult;
53
65
  private performReauthorization;
54
66
  disconnect(): Promise<void>;
@@ -59,6 +71,7 @@ declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
59
71
  signTransaction<T extends LegacyTransaction | VersionedTransaction>(transaction: T): Promise<T>;
60
72
  signAllTransactions<T extends LegacyTransaction | VersionedTransaction>(transactions: T[]): Promise<T[]>;
61
73
  signMessage(message: Uint8Array): Promise<Uint8Array>;
74
+ signIn(input?: SolanaSignInInput): Promise<SolanaSignInOutput>;
62
75
  }
63
76
  declare function createDefaultAddressSelector(): AddressSelector;
64
77
  declare function createDefaultAuthorizationResultCache(): AuthorizationResultCache;
package/package.json CHANGED
@@ -1,55 +1,57 @@
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": "2.0.0",
5
- "author": "Steven Luscher <steven.luscher@solanamobile.com>",
6
- "repository": "https://github.com/solana-mobile/mobile-wallet-adapter",
7
- "license": "Apache-2.0",
8
- "type": "module",
9
- "sideEffects": false,
10
- "main": "lib/cjs/index.js",
11
- "module": "lib/esm/index.js",
12
- "react-native": "lib/cjs/index.native.js",
13
- "types": "lib/types/index.d.ts",
14
- "browser": {
15
- "./lib/cjs/index.js": "./lib/cjs/index.browser.js",
16
- "./lib/esm/index.js": "./lib/esm/index.browser.js"
17
- },
18
- "exports": {
19
- "./package.json": "./package.json",
20
- ".": {
21
- "import": "./lib/esm/index.js",
22
- "require": "./lib/cjs/index.js"
23
- }
24
- },
25
- "files": [
26
- "lib",
27
- "LICENSE"
28
- ],
29
- "publishConfig": {
30
- "access": "public"
31
- },
32
- "scripts": {
33
- "clean": "shx rm -rf lib/*",
34
- "build": "yarn clean && rollup --config ../../rollup.config.ts --configPlugin rollup-plugin-ts",
35
- "build:watch": "yarn clean && rollup --config ../../rollup.config.ts --configPlugin rollup-plugin-ts --watch",
36
- "postbuild": "cross-env echo {\\\"type\\\":\\\"commonjs\\\"} | npx json > lib/cjs/package.json && echo {\\\"type\\\":\\\"module\\\"} | npx json > lib/esm/package.json",
37
- "prepublishOnly": "agadoo"
38
- },
39
- "peerDependencies": {
40
- "@solana/web3.js": "^1.58.0"
41
- },
42
- "dependencies": {
43
- "@react-native-async-storage/async-storage": "^1.17.7",
44
- "@solana-mobile/mobile-wallet-adapter-protocol-web3js": "^2.0.0",
45
- "@solana/wallet-adapter-base": "^0.9.17",
46
- "js-base64": "^3.7.2"
47
- },
48
- "devDependencies": {
49
- "@solana/web3.js": "^1.58.0",
50
- "agadoo": "^2.0.0",
51
- "cross-env": "^7.0.3",
52
- "shx": "^0.3.4"
53
- },
54
- "gitHead": "4118590f5f66fcbc9d04f839abb150f31f1d2ae5"
55
- }
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": "2.0.2",
5
+ "author": "Steven Luscher <steven.luscher@solanamobile.com>",
6
+ "repository": "https://github.com/solana-mobile/mobile-wallet-adapter",
7
+ "license": "Apache-2.0",
8
+ "type": "module",
9
+ "sideEffects": false,
10
+ "main": "lib/cjs/index.js",
11
+ "module": "lib/esm/index.js",
12
+ "react-native": "lib/cjs/index.native.js",
13
+ "types": "lib/types/index.d.ts",
14
+ "browser": {
15
+ "./lib/cjs/index.js": "./lib/cjs/index.browser.js",
16
+ "./lib/esm/index.js": "./lib/esm/index.browser.js"
17
+ },
18
+ "exports": {
19
+ "./package.json": "./package.json",
20
+ ".": {
21
+ "import": "./lib/esm/index.js",
22
+ "require": "./lib/cjs/index.js"
23
+ }
24
+ },
25
+ "files": [
26
+ "lib",
27
+ "LICENSE"
28
+ ],
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "scripts": {
33
+ "clean": "shx rm -rf lib/*",
34
+ "build": "yarn clean && rollup --config ../../rollup.config.ts --configPlugin rollup-plugin-ts",
35
+ "build:watch": "yarn clean && rollup --config ../../rollup.config.ts --configPlugin rollup-plugin-ts --watch",
36
+ "postbuild": "cross-env echo {\\\"type\\\":\\\"commonjs\\\"} | npx json > lib/cjs/package.json && echo {\\\"type\\\":\\\"module\\\"} | npx json > lib/esm/package.json",
37
+ "prepublishOnly": "agadoo"
38
+ },
39
+ "peerDependencies": {
40
+ "@solana/web3.js": "^1.58.0"
41
+ },
42
+ "dependencies": {
43
+ "@solana-mobile/mobile-wallet-adapter-protocol-web3js": "^2.0.1",
44
+ "@solana/wallet-adapter-base": "^0.9.23",
45
+ "@solana/wallet-standard-features": "^1.1.0",
46
+ "js-base64": "^3.7.2"
47
+ },
48
+ "optionalDependencies": {
49
+ "@react-native-async-storage/async-storage": "^1.17.7"
50
+ },
51
+ "devDependencies": {
52
+ "@solana/web3.js": "^1.58.0",
53
+ "agadoo": "^2.0.0",
54
+ "cross-env": "^7.0.3",
55
+ "shx": "^0.3.4"
56
+ }
57
+ }