@solana-mobile/wallet-adapter-mobile 2.0.1 → 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.
@@ -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,7 +1,7 @@
1
1
  {
2
2
  "name": "@solana-mobile/wallet-adapter-mobile",
3
3
  "description": "An adapter for mobile wallet apps that conform to the Solana Mobile Wallet Adapter protocol",
4
- "version": "2.0.1",
4
+ "version": "2.0.2",
5
5
  "author": "Steven Luscher <steven.luscher@solanamobile.com>",
6
6
  "repository": "https://github.com/solana-mobile/mobile-wallet-adapter",
7
7
  "license": "Apache-2.0",
@@ -40,11 +40,14 @@
40
40
  "@solana/web3.js": "^1.58.0"
41
41
  },
42
42
  "dependencies": {
43
- "@react-native-async-storage/async-storage": "^1.17.7",
44
43
  "@solana-mobile/mobile-wallet-adapter-protocol-web3js": "^2.0.1",
45
- "@solana/wallet-adapter-base": "^0.9.17",
44
+ "@solana/wallet-adapter-base": "^0.9.23",
45
+ "@solana/wallet-standard-features": "^1.1.0",
46
46
  "js-base64": "^3.7.2"
47
47
  },
48
+ "optionalDependencies": {
49
+ "@react-native-async-storage/async-storage": "^1.17.7"
50
+ },
48
51
  "devDependencies": {
49
52
  "@solana/web3.js": "^1.58.0",
50
53
  "agadoo": "^2.0.0",