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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var mobileWalletAdapterProtocol = require('@solana-mobile/mobile-wallet-adapter-protocol');
5
+ var mobileWalletAdapterProtocolWeb3js = require('@solana-mobile/mobile-wallet-adapter-protocol-web3js');
6
6
  var walletAdapterBase = require('@solana/wallet-adapter-base');
7
7
  var web3_js = require('@solana/web3.js');
8
8
 
@@ -40,15 +40,6 @@ function getIsSupported() {
40
40
 
41
41
  const SolanaMobileWalletAdapterWalletName = 'Default wallet app';
42
42
  const SIGNATURE_LENGTH_IN_BYTES = 64;
43
- function getBase64StringFromByteArray(byteArray) {
44
- return window.btoa(String.fromCharCode.call(null, ...byteArray));
45
- }
46
- function getByteArrayFromBase64String(base64EncodedByteArray) {
47
- return new Uint8Array(window
48
- .atob(base64EncodedByteArray)
49
- .split('')
50
- .map((c) => c.charCodeAt(0)));
51
- }
52
43
  class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalletAdapter {
53
44
  constructor(config) {
54
45
  super();
@@ -72,7 +63,7 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
72
63
  }
73
64
  get publicKey() {
74
65
  if (this._publicKey == null && this._authorizationResult != null) {
75
- this._publicKey = new web3_js.PublicKey(this._authorizationResult.publicKey);
66
+ this._publicKey = new web3_js.PublicKey(this._authorizationResult.pub_key);
76
67
  }
77
68
  return this._publicKey ? this._publicKey : null;
78
69
  }
@@ -107,8 +98,8 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
107
98
  return;
108
99
  }
109
100
  try {
110
- yield this.withWallet((mobileWallet) => __awaiter(this, void 0, void 0, function* () {
111
- const { auth_token, pub_key: base58PublicKey, wallet_uri_base, } = yield mobileWallet('authorize', { identity: this._appIdentity });
101
+ yield this.transact((walletAPI) => __awaiter(this, void 0, void 0, function* () {
102
+ const { auth_token, pub_key: base58PublicKey, wallet_uri_base, } = yield walletAPI({ method: 'authorize', identity: this._appIdentity });
112
103
  try {
113
104
  this._publicKey = new web3_js.PublicKey(base58PublicKey);
114
105
  }
@@ -116,9 +107,9 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
116
107
  throw new walletAdapterBase.WalletPublicKeyError((e instanceof Error && (e === null || e === void 0 ? void 0 : e.message)) || 'Unknown error', e);
117
108
  }
118
109
  this.handleAuthorizationResult({
119
- authToken: auth_token,
120
- publicKey: base58PublicKey,
121
- walletUriBase: wallet_uri_base,
110
+ auth_token,
111
+ pub_key: base58PublicKey,
112
+ wallet_uri_base: wallet_uri_base,
122
113
  }); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
123
114
  this.emit('connect',
124
115
  // Having just set an `authorizationResult`, `this.publicKey` is definitely non-null
@@ -140,14 +131,15 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
140
131
  yield this._authorizationResultCache.set(authorizationResult);
141
132
  });
142
133
  }
143
- performReauthorization(mobileWallet, currentAuthorizationResult) {
134
+ performReauthorization(walletAPI, currentAuthorizationResult) {
144
135
  return __awaiter(this, void 0, void 0, function* () {
145
136
  try {
146
- const { auth_token } = yield mobileWallet('reauthorize', {
147
- auth_token: currentAuthorizationResult.authToken,
137
+ const { auth_token } = yield walletAPI({
138
+ method: 'reauthorize',
139
+ auth_token: currentAuthorizationResult.auth_token,
148
140
  });
149
- if (currentAuthorizationResult.authToken !== auth_token) {
150
- this.handleAuthorizationResult(Object.assign(Object.assign({}, currentAuthorizationResult), { authToken: auth_token })); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
141
+ if (currentAuthorizationResult.auth_token !== auth_token) {
142
+ this.handleAuthorizationResult(Object.assign(Object.assign({}, currentAuthorizationResult), { auth_token })); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
151
143
  }
152
144
  return auth_token;
153
145
  }
@@ -165,12 +157,12 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
165
157
  this.emit('disconnect');
166
158
  });
167
159
  }
168
- withWallet(callback) {
160
+ transact(callback) {
169
161
  var _a;
170
162
  return __awaiter(this, void 0, void 0, function* () {
171
- const walletUriBase = (_a = this._authorizationResult) === null || _a === void 0 ? void 0 : _a.walletUriBase;
163
+ const walletUriBase = (_a = this._authorizationResult) === null || _a === void 0 ? void 0 : _a.wallet_uri_base;
172
164
  const config = walletUriBase ? { baseUri: walletUriBase } : undefined;
173
- return yield mobileWalletAdapterProtocol.withLocalWallet(callback, config);
165
+ return yield mobileWalletAdapterProtocolWeb3js.transact(callback, config);
174
166
  });
175
167
  }
176
168
  assertIsAuthorized() {
@@ -184,17 +176,14 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
184
176
  try {
185
177
  const authorizationResult = this.assertIsAuthorized();
186
178
  try {
187
- const serializedTransactions = transactions.map((transaction) => transaction.serialize({
188
- requireAllSignatures: false,
189
- verifySignatures: false,
190
- }));
191
- const payloads = serializedTransactions.map((serializedTransaction) => serializedTransaction.toString('base64'));
192
- return yield this.withWallet((mobileWallet) => __awaiter(this, void 0, void 0, function* () {
193
- const freshAuthToken = yield this.performReauthorization(mobileWallet, authorizationResult);
194
- const { signed_payloads: base64EncodedCompiledTransactions } = yield mobileWallet('sign_transaction', { auth_token: freshAuthToken, payloads });
195
- const compiledTransactions = base64EncodedCompiledTransactions.map(getByteArrayFromBase64String);
196
- const transactions = compiledTransactions.map(web3_js.Transaction.from);
197
- return transactions;
179
+ return yield this.transact((walletAPI) => __awaiter(this, void 0, void 0, function* () {
180
+ const freshAuthToken = yield this.performReauthorization(walletAPI, authorizationResult);
181
+ const signedTransactions = yield walletAPI({
182
+ method: 'sign_transaction',
183
+ auth_token: freshAuthToken,
184
+ transactions,
185
+ });
186
+ return signedTransactions;
198
187
  }));
199
188
  }
200
189
  catch (error) {
@@ -212,34 +201,14 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
212
201
  try {
213
202
  const authorizationResult = this.assertIsAuthorized();
214
203
  try {
215
- if (transaction.feePayer == null) {
216
- transaction.feePayer = this.publicKey || undefined;
217
- }
218
- if (transaction.recentBlockhash == null) {
219
- const { blockhash } = yield connection.getRecentBlockhash(connection.commitment);
220
- transaction.recentBlockhash = blockhash;
221
- }
222
- const serializedTransaction = transaction.serialize({
223
- requireAllSignatures: false,
224
- verifySignatures: false,
225
- });
226
- const payloads = [serializedTransaction.toString('base64')];
227
- return yield this.withWallet((mobileWallet) => __awaiter(this, void 0, void 0, function* () {
228
- const freshAuthToken = yield this.performReauthorization(mobileWallet, authorizationResult);
229
- let targetCommitment;
230
- switch (connection.commitment) {
231
- case 'confirmed':
232
- case 'finalized':
233
- case 'processed':
234
- targetCommitment = connection.commitment;
235
- break;
236
- default:
237
- targetCommitment = 'finalized';
238
- }
239
- const { signatures } = yield mobileWallet('sign_and_send_transaction', {
204
+ return yield this.transact((walletAPI) => __awaiter(this, void 0, void 0, function* () {
205
+ const freshAuthToken = yield this.performReauthorization(walletAPI, authorizationResult);
206
+ const signatures = yield walletAPI({
207
+ method: 'sign_and_send_transaction',
240
208
  auth_token: freshAuthToken,
241
- commitment: targetCommitment,
242
- payloads,
209
+ fee_payer: this.publicKey || undefined,
210
+ connection,
211
+ transactions: [transaction],
243
212
  });
244
213
  return signatures[0];
245
214
  }));
@@ -271,13 +240,13 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
271
240
  try {
272
241
  const authorizationResult = this.assertIsAuthorized();
273
242
  try {
274
- return yield this.withWallet((mobileWallet) => __awaiter(this, void 0, void 0, function* () {
275
- const freshAuthToken = yield this.performReauthorization(mobileWallet, authorizationResult);
276
- const { signed_payloads: [base64EncodedSignedMessage], } = yield mobileWallet('sign_message', {
243
+ return yield this.transact((walletAPI) => __awaiter(this, void 0, void 0, function* () {
244
+ const freshAuthToken = yield this.performReauthorization(walletAPI, authorizationResult);
245
+ const [signedMessage] = yield walletAPI({
246
+ method: 'sign_message',
277
247
  auth_token: freshAuthToken,
278
- payloads: [getBase64StringFromByteArray(message)],
248
+ byteArrays: [message],
279
249
  });
280
- const signedMessage = getByteArrayFromBase64String(base64EncodedSignedMessage);
281
250
  const signature = signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES);
282
251
  return signature;
283
252
  }));
package/lib/cjs/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var mobileWalletAdapterProtocol = require('@solana-mobile/mobile-wallet-adapter-protocol');
5
+ var mobileWalletAdapterProtocolWeb3js = require('@solana-mobile/mobile-wallet-adapter-protocol-web3js');
6
6
  var walletAdapterBase = require('@solana/wallet-adapter-base');
7
7
  var web3_js = require('@solana/web3.js');
8
8
 
@@ -40,15 +40,6 @@ function getIsSupported() {
40
40
 
41
41
  const SolanaMobileWalletAdapterWalletName = 'Default wallet app';
42
42
  const SIGNATURE_LENGTH_IN_BYTES = 64;
43
- function getBase64StringFromByteArray(byteArray) {
44
- return window.btoa(String.fromCharCode.call(null, ...byteArray));
45
- }
46
- function getByteArrayFromBase64String(base64EncodedByteArray) {
47
- return new Uint8Array(window
48
- .atob(base64EncodedByteArray)
49
- .split('')
50
- .map((c) => c.charCodeAt(0)));
51
- }
52
43
  class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalletAdapter {
53
44
  constructor(config) {
54
45
  super();
@@ -72,7 +63,7 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
72
63
  }
73
64
  get publicKey() {
74
65
  if (this._publicKey == null && this._authorizationResult != null) {
75
- this._publicKey = new web3_js.PublicKey(this._authorizationResult.publicKey);
66
+ this._publicKey = new web3_js.PublicKey(this._authorizationResult.pub_key);
76
67
  }
77
68
  return this._publicKey ? this._publicKey : null;
78
69
  }
@@ -107,8 +98,8 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
107
98
  return;
108
99
  }
109
100
  try {
110
- yield this.withWallet((mobileWallet) => __awaiter(this, void 0, void 0, function* () {
111
- const { auth_token, pub_key: base58PublicKey, wallet_uri_base, } = yield mobileWallet('authorize', { identity: this._appIdentity });
101
+ yield this.transact((walletAPI) => __awaiter(this, void 0, void 0, function* () {
102
+ const { auth_token, pub_key: base58PublicKey, wallet_uri_base, } = yield walletAPI({ method: 'authorize', identity: this._appIdentity });
112
103
  try {
113
104
  this._publicKey = new web3_js.PublicKey(base58PublicKey);
114
105
  }
@@ -116,9 +107,9 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
116
107
  throw new walletAdapterBase.WalletPublicKeyError((e instanceof Error && (e === null || e === void 0 ? void 0 : e.message)) || 'Unknown error', e);
117
108
  }
118
109
  this.handleAuthorizationResult({
119
- authToken: auth_token,
120
- publicKey: base58PublicKey,
121
- walletUriBase: wallet_uri_base,
110
+ auth_token,
111
+ pub_key: base58PublicKey,
112
+ wallet_uri_base: wallet_uri_base,
122
113
  }); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
123
114
  this.emit('connect',
124
115
  // Having just set an `authorizationResult`, `this.publicKey` is definitely non-null
@@ -140,14 +131,15 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
140
131
  yield this._authorizationResultCache.set(authorizationResult);
141
132
  });
142
133
  }
143
- performReauthorization(mobileWallet, currentAuthorizationResult) {
134
+ performReauthorization(walletAPI, currentAuthorizationResult) {
144
135
  return __awaiter(this, void 0, void 0, function* () {
145
136
  try {
146
- const { auth_token } = yield mobileWallet('reauthorize', {
147
- auth_token: currentAuthorizationResult.authToken,
137
+ const { auth_token } = yield walletAPI({
138
+ method: 'reauthorize',
139
+ auth_token: currentAuthorizationResult.auth_token,
148
140
  });
149
- if (currentAuthorizationResult.authToken !== auth_token) {
150
- this.handleAuthorizationResult(Object.assign(Object.assign({}, currentAuthorizationResult), { authToken: auth_token })); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
141
+ if (currentAuthorizationResult.auth_token !== auth_token) {
142
+ this.handleAuthorizationResult(Object.assign(Object.assign({}, currentAuthorizationResult), { auth_token })); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
151
143
  }
152
144
  return auth_token;
153
145
  }
@@ -165,12 +157,12 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
165
157
  this.emit('disconnect');
166
158
  });
167
159
  }
168
- withWallet(callback) {
160
+ transact(callback) {
169
161
  var _a;
170
162
  return __awaiter(this, void 0, void 0, function* () {
171
- const walletUriBase = (_a = this._authorizationResult) === null || _a === void 0 ? void 0 : _a.walletUriBase;
163
+ const walletUriBase = (_a = this._authorizationResult) === null || _a === void 0 ? void 0 : _a.wallet_uri_base;
172
164
  const config = walletUriBase ? { baseUri: walletUriBase } : undefined;
173
- return yield mobileWalletAdapterProtocol.withLocalWallet(callback, config);
165
+ return yield mobileWalletAdapterProtocolWeb3js.transact(callback, config);
174
166
  });
175
167
  }
176
168
  assertIsAuthorized() {
@@ -184,17 +176,14 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
184
176
  try {
185
177
  const authorizationResult = this.assertIsAuthorized();
186
178
  try {
187
- const serializedTransactions = transactions.map((transaction) => transaction.serialize({
188
- requireAllSignatures: false,
189
- verifySignatures: false,
190
- }));
191
- const payloads = serializedTransactions.map((serializedTransaction) => serializedTransaction.toString('base64'));
192
- return yield this.withWallet((mobileWallet) => __awaiter(this, void 0, void 0, function* () {
193
- const freshAuthToken = yield this.performReauthorization(mobileWallet, authorizationResult);
194
- const { signed_payloads: base64EncodedCompiledTransactions } = yield mobileWallet('sign_transaction', { auth_token: freshAuthToken, payloads });
195
- const compiledTransactions = base64EncodedCompiledTransactions.map(getByteArrayFromBase64String);
196
- const transactions = compiledTransactions.map(web3_js.Transaction.from);
197
- return transactions;
179
+ return yield this.transact((walletAPI) => __awaiter(this, void 0, void 0, function* () {
180
+ const freshAuthToken = yield this.performReauthorization(walletAPI, authorizationResult);
181
+ const signedTransactions = yield walletAPI({
182
+ method: 'sign_transaction',
183
+ auth_token: freshAuthToken,
184
+ transactions,
185
+ });
186
+ return signedTransactions;
198
187
  }));
199
188
  }
200
189
  catch (error) {
@@ -212,34 +201,14 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
212
201
  try {
213
202
  const authorizationResult = this.assertIsAuthorized();
214
203
  try {
215
- if (transaction.feePayer == null) {
216
- transaction.feePayer = this.publicKey || undefined;
217
- }
218
- if (transaction.recentBlockhash == null) {
219
- const { blockhash } = yield connection.getRecentBlockhash(connection.commitment);
220
- transaction.recentBlockhash = blockhash;
221
- }
222
- const serializedTransaction = transaction.serialize({
223
- requireAllSignatures: false,
224
- verifySignatures: false,
225
- });
226
- const payloads = [serializedTransaction.toString('base64')];
227
- return yield this.withWallet((mobileWallet) => __awaiter(this, void 0, void 0, function* () {
228
- const freshAuthToken = yield this.performReauthorization(mobileWallet, authorizationResult);
229
- let targetCommitment;
230
- switch (connection.commitment) {
231
- case 'confirmed':
232
- case 'finalized':
233
- case 'processed':
234
- targetCommitment = connection.commitment;
235
- break;
236
- default:
237
- targetCommitment = 'finalized';
238
- }
239
- const { signatures } = yield mobileWallet('sign_and_send_transaction', {
204
+ return yield this.transact((walletAPI) => __awaiter(this, void 0, void 0, function* () {
205
+ const freshAuthToken = yield this.performReauthorization(walletAPI, authorizationResult);
206
+ const signatures = yield walletAPI({
207
+ method: 'sign_and_send_transaction',
240
208
  auth_token: freshAuthToken,
241
- commitment: targetCommitment,
242
- payloads,
209
+ fee_payer: this.publicKey || undefined,
210
+ connection,
211
+ transactions: [transaction],
243
212
  });
244
213
  return signatures[0];
245
214
  }));
@@ -271,13 +240,13 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
271
240
  try {
272
241
  const authorizationResult = this.assertIsAuthorized();
273
242
  try {
274
- return yield this.withWallet((mobileWallet) => __awaiter(this, void 0, void 0, function* () {
275
- const freshAuthToken = yield this.performReauthorization(mobileWallet, authorizationResult);
276
- const { signed_payloads: [base64EncodedSignedMessage], } = yield mobileWallet('sign_message', {
243
+ return yield this.transact((walletAPI) => __awaiter(this, void 0, void 0, function* () {
244
+ const freshAuthToken = yield this.performReauthorization(walletAPI, authorizationResult);
245
+ const [signedMessage] = yield walletAPI({
246
+ method: 'sign_message',
277
247
  auth_token: freshAuthToken,
278
- payloads: [getBase64StringFromByteArray(message)],
248
+ byteArrays: [message],
279
249
  });
280
- const signedMessage = getByteArrayFromBase64String(base64EncodedSignedMessage);
281
250
  const signature = signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES);
282
251
  return signature;
283
252
  }));
@@ -2,11 +2,11 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var mobileWalletAdapterProtocol = require('@solana-mobile/mobile-wallet-adapter-protocol');
5
+ var mobileWalletAdapterProtocolWeb3js = require('@solana-mobile/mobile-wallet-adapter-protocol-web3js');
6
6
  var walletAdapterBase = require('@solana/wallet-adapter-base');
7
7
  var web3_js = require('@solana/web3.js');
8
8
  var reactNative = require('react-native');
9
- var AsyncStorage = require('@react-native-community/async-storage');
9
+ var AsyncStorage = require('@react-native-async-storage/async-storage');
10
10
 
11
11
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
12
12
 
@@ -43,15 +43,6 @@ function getIsSupported() {
43
43
 
44
44
  const SolanaMobileWalletAdapterWalletName = 'Default wallet app';
45
45
  const SIGNATURE_LENGTH_IN_BYTES = 64;
46
- function getBase64StringFromByteArray(byteArray) {
47
- return window.btoa(String.fromCharCode.call(null, ...byteArray));
48
- }
49
- function getByteArrayFromBase64String(base64EncodedByteArray) {
50
- return new Uint8Array(window
51
- .atob(base64EncodedByteArray)
52
- .split('')
53
- .map((c) => c.charCodeAt(0)));
54
- }
55
46
  class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalletAdapter {
56
47
  constructor(config) {
57
48
  super();
@@ -75,7 +66,7 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
75
66
  }
76
67
  get publicKey() {
77
68
  if (this._publicKey == null && this._authorizationResult != null) {
78
- this._publicKey = new web3_js.PublicKey(this._authorizationResult.publicKey);
69
+ this._publicKey = new web3_js.PublicKey(this._authorizationResult.pub_key);
79
70
  }
80
71
  return this._publicKey ? this._publicKey : null;
81
72
  }
@@ -110,8 +101,8 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
110
101
  return;
111
102
  }
112
103
  try {
113
- yield this.withWallet((mobileWallet) => __awaiter(this, void 0, void 0, function* () {
114
- const { auth_token, pub_key: base58PublicKey, wallet_uri_base, } = yield mobileWallet('authorize', { identity: this._appIdentity });
104
+ yield this.transact((walletAPI) => __awaiter(this, void 0, void 0, function* () {
105
+ const { auth_token, pub_key: base58PublicKey, wallet_uri_base, } = yield walletAPI({ method: 'authorize', identity: this._appIdentity });
115
106
  try {
116
107
  this._publicKey = new web3_js.PublicKey(base58PublicKey);
117
108
  }
@@ -119,9 +110,9 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
119
110
  throw new walletAdapterBase.WalletPublicKeyError((e instanceof Error && (e === null || e === void 0 ? void 0 : e.message)) || 'Unknown error', e);
120
111
  }
121
112
  this.handleAuthorizationResult({
122
- authToken: auth_token,
123
- publicKey: base58PublicKey,
124
- walletUriBase: wallet_uri_base,
113
+ auth_token,
114
+ pub_key: base58PublicKey,
115
+ wallet_uri_base: wallet_uri_base,
125
116
  }); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
126
117
  this.emit('connect',
127
118
  // Having just set an `authorizationResult`, `this.publicKey` is definitely non-null
@@ -143,14 +134,15 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
143
134
  yield this._authorizationResultCache.set(authorizationResult);
144
135
  });
145
136
  }
146
- performReauthorization(mobileWallet, currentAuthorizationResult) {
137
+ performReauthorization(walletAPI, currentAuthorizationResult) {
147
138
  return __awaiter(this, void 0, void 0, function* () {
148
139
  try {
149
- const { auth_token } = yield mobileWallet('reauthorize', {
150
- auth_token: currentAuthorizationResult.authToken,
140
+ const { auth_token } = yield walletAPI({
141
+ method: 'reauthorize',
142
+ auth_token: currentAuthorizationResult.auth_token,
151
143
  });
152
- if (currentAuthorizationResult.authToken !== auth_token) {
153
- this.handleAuthorizationResult(Object.assign(Object.assign({}, currentAuthorizationResult), { authToken: auth_token })); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
144
+ if (currentAuthorizationResult.auth_token !== auth_token) {
145
+ this.handleAuthorizationResult(Object.assign(Object.assign({}, currentAuthorizationResult), { auth_token })); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
154
146
  }
155
147
  return auth_token;
156
148
  }
@@ -168,12 +160,12 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
168
160
  this.emit('disconnect');
169
161
  });
170
162
  }
171
- withWallet(callback) {
163
+ transact(callback) {
172
164
  var _a;
173
165
  return __awaiter(this, void 0, void 0, function* () {
174
- const walletUriBase = (_a = this._authorizationResult) === null || _a === void 0 ? void 0 : _a.walletUriBase;
166
+ const walletUriBase = (_a = this._authorizationResult) === null || _a === void 0 ? void 0 : _a.wallet_uri_base;
175
167
  const config = walletUriBase ? { baseUri: walletUriBase } : undefined;
176
- return yield mobileWalletAdapterProtocol.withLocalWallet(callback, config);
168
+ return yield mobileWalletAdapterProtocolWeb3js.transact(callback, config);
177
169
  });
178
170
  }
179
171
  assertIsAuthorized() {
@@ -187,17 +179,14 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
187
179
  try {
188
180
  const authorizationResult = this.assertIsAuthorized();
189
181
  try {
190
- const serializedTransactions = transactions.map((transaction) => transaction.serialize({
191
- requireAllSignatures: false,
192
- verifySignatures: false,
193
- }));
194
- const payloads = serializedTransactions.map((serializedTransaction) => serializedTransaction.toString('base64'));
195
- return yield this.withWallet((mobileWallet) => __awaiter(this, void 0, void 0, function* () {
196
- const freshAuthToken = yield this.performReauthorization(mobileWallet, authorizationResult);
197
- const { signed_payloads: base64EncodedCompiledTransactions } = yield mobileWallet('sign_transaction', { auth_token: freshAuthToken, payloads });
198
- const compiledTransactions = base64EncodedCompiledTransactions.map(getByteArrayFromBase64String);
199
- const transactions = compiledTransactions.map(web3_js.Transaction.from);
200
- return transactions;
182
+ return yield this.transact((walletAPI) => __awaiter(this, void 0, void 0, function* () {
183
+ const freshAuthToken = yield this.performReauthorization(walletAPI, authorizationResult);
184
+ const signedTransactions = yield walletAPI({
185
+ method: 'sign_transaction',
186
+ auth_token: freshAuthToken,
187
+ transactions,
188
+ });
189
+ return signedTransactions;
201
190
  }));
202
191
  }
203
192
  catch (error) {
@@ -215,34 +204,14 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
215
204
  try {
216
205
  const authorizationResult = this.assertIsAuthorized();
217
206
  try {
218
- if (transaction.feePayer == null) {
219
- transaction.feePayer = this.publicKey || undefined;
220
- }
221
- if (transaction.recentBlockhash == null) {
222
- const { blockhash } = yield connection.getRecentBlockhash(connection.commitment);
223
- transaction.recentBlockhash = blockhash;
224
- }
225
- const serializedTransaction = transaction.serialize({
226
- requireAllSignatures: false,
227
- verifySignatures: false,
228
- });
229
- const payloads = [serializedTransaction.toString('base64')];
230
- return yield this.withWallet((mobileWallet) => __awaiter(this, void 0, void 0, function* () {
231
- const freshAuthToken = yield this.performReauthorization(mobileWallet, authorizationResult);
232
- let targetCommitment;
233
- switch (connection.commitment) {
234
- case 'confirmed':
235
- case 'finalized':
236
- case 'processed':
237
- targetCommitment = connection.commitment;
238
- break;
239
- default:
240
- targetCommitment = 'finalized';
241
- }
242
- const { signatures } = yield mobileWallet('sign_and_send_transaction', {
207
+ return yield this.transact((walletAPI) => __awaiter(this, void 0, void 0, function* () {
208
+ const freshAuthToken = yield this.performReauthorization(walletAPI, authorizationResult);
209
+ const signatures = yield walletAPI({
210
+ method: 'sign_and_send_transaction',
243
211
  auth_token: freshAuthToken,
244
- commitment: targetCommitment,
245
- payloads,
212
+ fee_payer: this.publicKey || undefined,
213
+ connection,
214
+ transactions: [transaction],
246
215
  });
247
216
  return signatures[0];
248
217
  }));
@@ -274,13 +243,13 @@ class SolanaMobileWalletAdapter extends walletAdapterBase.BaseMessageSignerWalle
274
243
  try {
275
244
  const authorizationResult = this.assertIsAuthorized();
276
245
  try {
277
- return yield this.withWallet((mobileWallet) => __awaiter(this, void 0, void 0, function* () {
278
- const freshAuthToken = yield this.performReauthorization(mobileWallet, authorizationResult);
279
- const { signed_payloads: [base64EncodedSignedMessage], } = yield mobileWallet('sign_message', {
246
+ return yield this.transact((walletAPI) => __awaiter(this, void 0, void 0, function* () {
247
+ const freshAuthToken = yield this.performReauthorization(walletAPI, authorizationResult);
248
+ const [signedMessage] = yield walletAPI({
249
+ method: 'sign_message',
280
250
  auth_token: freshAuthToken,
281
- payloads: [getBase64StringFromByteArray(message)],
251
+ byteArrays: [message],
282
252
  });
283
- const signedMessage = getByteArrayFromBase64String(base64EncodedSignedMessage);
284
253
  const signature = signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES);
285
254
  return signature;
286
255
  }));
@@ -1,6 +1,6 @@
1
- import { withLocalWallet } from '@solana-mobile/mobile-wallet-adapter-protocol';
1
+ import { transact } from '@solana-mobile/mobile-wallet-adapter-protocol-web3js';
2
2
  import { BaseMessageSignerWalletAdapter, WalletReadyState, WalletNotReadyError, WalletPublicKeyError, WalletConnectionError, WalletDisconnectedError, WalletNotConnectedError, WalletSignTransactionError, WalletSendTransactionError, WalletSignMessageError } from '@solana/wallet-adapter-base';
3
- import { PublicKey, Transaction } from '@solana/web3.js';
3
+ import { PublicKey } from '@solana/web3.js';
4
4
 
5
5
  /******************************************************************************
6
6
  Copyright (c) Microsoft Corporation.
@@ -36,15 +36,6 @@ function getIsSupported() {
36
36
 
37
37
  const SolanaMobileWalletAdapterWalletName = 'Default wallet app';
38
38
  const SIGNATURE_LENGTH_IN_BYTES = 64;
39
- function getBase64StringFromByteArray(byteArray) {
40
- return window.btoa(String.fromCharCode.call(null, ...byteArray));
41
- }
42
- function getByteArrayFromBase64String(base64EncodedByteArray) {
43
- return new Uint8Array(window
44
- .atob(base64EncodedByteArray)
45
- .split('')
46
- .map((c) => c.charCodeAt(0)));
47
- }
48
39
  class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
49
40
  constructor(config) {
50
41
  super();
@@ -68,7 +59,7 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
68
59
  }
69
60
  get publicKey() {
70
61
  if (this._publicKey == null && this._authorizationResult != null) {
71
- this._publicKey = new PublicKey(this._authorizationResult.publicKey);
62
+ this._publicKey = new PublicKey(this._authorizationResult.pub_key);
72
63
  }
73
64
  return this._publicKey ? this._publicKey : null;
74
65
  }
@@ -103,8 +94,8 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
103
94
  return;
104
95
  }
105
96
  try {
106
- yield this.withWallet((mobileWallet) => __awaiter(this, void 0, void 0, function* () {
107
- const { auth_token, pub_key: base58PublicKey, wallet_uri_base, } = yield mobileWallet('authorize', { identity: this._appIdentity });
97
+ yield this.transact((walletAPI) => __awaiter(this, void 0, void 0, function* () {
98
+ const { auth_token, pub_key: base58PublicKey, wallet_uri_base, } = yield walletAPI({ method: 'authorize', identity: this._appIdentity });
108
99
  try {
109
100
  this._publicKey = new PublicKey(base58PublicKey);
110
101
  }
@@ -112,9 +103,9 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
112
103
  throw new WalletPublicKeyError((e instanceof Error && (e === null || e === void 0 ? void 0 : e.message)) || 'Unknown error', e);
113
104
  }
114
105
  this.handleAuthorizationResult({
115
- authToken: auth_token,
116
- publicKey: base58PublicKey,
117
- walletUriBase: wallet_uri_base,
106
+ auth_token,
107
+ pub_key: base58PublicKey,
108
+ wallet_uri_base: wallet_uri_base,
118
109
  }); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
119
110
  this.emit('connect',
120
111
  // Having just set an `authorizationResult`, `this.publicKey` is definitely non-null
@@ -136,14 +127,15 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
136
127
  yield this._authorizationResultCache.set(authorizationResult);
137
128
  });
138
129
  }
139
- performReauthorization(mobileWallet, currentAuthorizationResult) {
130
+ performReauthorization(walletAPI, currentAuthorizationResult) {
140
131
  return __awaiter(this, void 0, void 0, function* () {
141
132
  try {
142
- const { auth_token } = yield mobileWallet('reauthorize', {
143
- auth_token: currentAuthorizationResult.authToken,
133
+ const { auth_token } = yield walletAPI({
134
+ method: 'reauthorize',
135
+ auth_token: currentAuthorizationResult.auth_token,
144
136
  });
145
- if (currentAuthorizationResult.authToken !== auth_token) {
146
- this.handleAuthorizationResult(Object.assign(Object.assign({}, currentAuthorizationResult), { authToken: auth_token })); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
137
+ if (currentAuthorizationResult.auth_token !== auth_token) {
138
+ this.handleAuthorizationResult(Object.assign(Object.assign({}, currentAuthorizationResult), { auth_token })); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
147
139
  }
148
140
  return auth_token;
149
141
  }
@@ -161,12 +153,12 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
161
153
  this.emit('disconnect');
162
154
  });
163
155
  }
164
- withWallet(callback) {
156
+ transact(callback) {
165
157
  var _a;
166
158
  return __awaiter(this, void 0, void 0, function* () {
167
- const walletUriBase = (_a = this._authorizationResult) === null || _a === void 0 ? void 0 : _a.walletUriBase;
159
+ const walletUriBase = (_a = this._authorizationResult) === null || _a === void 0 ? void 0 : _a.wallet_uri_base;
168
160
  const config = walletUriBase ? { baseUri: walletUriBase } : undefined;
169
- return yield withLocalWallet(callback, config);
161
+ return yield transact(callback, config);
170
162
  });
171
163
  }
172
164
  assertIsAuthorized() {
@@ -180,17 +172,14 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
180
172
  try {
181
173
  const authorizationResult = this.assertIsAuthorized();
182
174
  try {
183
- const serializedTransactions = transactions.map((transaction) => transaction.serialize({
184
- requireAllSignatures: false,
185
- verifySignatures: false,
186
- }));
187
- const payloads = serializedTransactions.map((serializedTransaction) => serializedTransaction.toString('base64'));
188
- return yield this.withWallet((mobileWallet) => __awaiter(this, void 0, void 0, function* () {
189
- const freshAuthToken = yield this.performReauthorization(mobileWallet, authorizationResult);
190
- const { signed_payloads: base64EncodedCompiledTransactions } = yield mobileWallet('sign_transaction', { auth_token: freshAuthToken, payloads });
191
- const compiledTransactions = base64EncodedCompiledTransactions.map(getByteArrayFromBase64String);
192
- const transactions = compiledTransactions.map(Transaction.from);
193
- return transactions;
175
+ return yield this.transact((walletAPI) => __awaiter(this, void 0, void 0, function* () {
176
+ const freshAuthToken = yield this.performReauthorization(walletAPI, authorizationResult);
177
+ const signedTransactions = yield walletAPI({
178
+ method: 'sign_transaction',
179
+ auth_token: freshAuthToken,
180
+ transactions,
181
+ });
182
+ return signedTransactions;
194
183
  }));
195
184
  }
196
185
  catch (error) {
@@ -208,34 +197,14 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
208
197
  try {
209
198
  const authorizationResult = this.assertIsAuthorized();
210
199
  try {
211
- if (transaction.feePayer == null) {
212
- transaction.feePayer = this.publicKey || undefined;
213
- }
214
- if (transaction.recentBlockhash == null) {
215
- const { blockhash } = yield connection.getRecentBlockhash(connection.commitment);
216
- transaction.recentBlockhash = blockhash;
217
- }
218
- const serializedTransaction = transaction.serialize({
219
- requireAllSignatures: false,
220
- verifySignatures: false,
221
- });
222
- const payloads = [serializedTransaction.toString('base64')];
223
- return yield this.withWallet((mobileWallet) => __awaiter(this, void 0, void 0, function* () {
224
- const freshAuthToken = yield this.performReauthorization(mobileWallet, authorizationResult);
225
- let targetCommitment;
226
- switch (connection.commitment) {
227
- case 'confirmed':
228
- case 'finalized':
229
- case 'processed':
230
- targetCommitment = connection.commitment;
231
- break;
232
- default:
233
- targetCommitment = 'finalized';
234
- }
235
- const { signatures } = yield mobileWallet('sign_and_send_transaction', {
200
+ return yield this.transact((walletAPI) => __awaiter(this, void 0, void 0, function* () {
201
+ const freshAuthToken = yield this.performReauthorization(walletAPI, authorizationResult);
202
+ const signatures = yield walletAPI({
203
+ method: 'sign_and_send_transaction',
236
204
  auth_token: freshAuthToken,
237
- commitment: targetCommitment,
238
- payloads,
205
+ fee_payer: this.publicKey || undefined,
206
+ connection,
207
+ transactions: [transaction],
239
208
  });
240
209
  return signatures[0];
241
210
  }));
@@ -267,13 +236,13 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
267
236
  try {
268
237
  const authorizationResult = this.assertIsAuthorized();
269
238
  try {
270
- return yield this.withWallet((mobileWallet) => __awaiter(this, void 0, void 0, function* () {
271
- const freshAuthToken = yield this.performReauthorization(mobileWallet, authorizationResult);
272
- const { signed_payloads: [base64EncodedSignedMessage], } = yield mobileWallet('sign_message', {
239
+ return yield this.transact((walletAPI) => __awaiter(this, void 0, void 0, function* () {
240
+ const freshAuthToken = yield this.performReauthorization(walletAPI, authorizationResult);
241
+ const [signedMessage] = yield walletAPI({
242
+ method: 'sign_message',
273
243
  auth_token: freshAuthToken,
274
- payloads: [getBase64StringFromByteArray(message)],
244
+ byteArrays: [message],
275
245
  });
276
- const signedMessage = getByteArrayFromBase64String(base64EncodedSignedMessage);
277
246
  const signature = signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES);
278
247
  return signature;
279
248
  }));
package/lib/esm/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { withLocalWallet } from '@solana-mobile/mobile-wallet-adapter-protocol';
1
+ import { transact } from '@solana-mobile/mobile-wallet-adapter-protocol-web3js';
2
2
  import { BaseMessageSignerWalletAdapter, WalletReadyState, WalletNotReadyError, WalletPublicKeyError, WalletConnectionError, WalletDisconnectedError, WalletNotConnectedError, WalletSignTransactionError, WalletSendTransactionError, WalletSignMessageError } from '@solana/wallet-adapter-base';
3
- import { PublicKey, Transaction } from '@solana/web3.js';
3
+ import { PublicKey } from '@solana/web3.js';
4
4
 
5
5
  /******************************************************************************
6
6
  Copyright (c) Microsoft Corporation.
@@ -36,15 +36,6 @@ function getIsSupported() {
36
36
 
37
37
  const SolanaMobileWalletAdapterWalletName = 'Default wallet app';
38
38
  const SIGNATURE_LENGTH_IN_BYTES = 64;
39
- function getBase64StringFromByteArray(byteArray) {
40
- return window.btoa(String.fromCharCode.call(null, ...byteArray));
41
- }
42
- function getByteArrayFromBase64String(base64EncodedByteArray) {
43
- return new Uint8Array(window
44
- .atob(base64EncodedByteArray)
45
- .split('')
46
- .map((c) => c.charCodeAt(0)));
47
- }
48
39
  class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
49
40
  constructor(config) {
50
41
  super();
@@ -68,7 +59,7 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
68
59
  }
69
60
  get publicKey() {
70
61
  if (this._publicKey == null && this._authorizationResult != null) {
71
- this._publicKey = new PublicKey(this._authorizationResult.publicKey);
62
+ this._publicKey = new PublicKey(this._authorizationResult.pub_key);
72
63
  }
73
64
  return this._publicKey ? this._publicKey : null;
74
65
  }
@@ -103,8 +94,8 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
103
94
  return;
104
95
  }
105
96
  try {
106
- yield this.withWallet((mobileWallet) => __awaiter(this, void 0, void 0, function* () {
107
- const { auth_token, pub_key: base58PublicKey, wallet_uri_base, } = yield mobileWallet('authorize', { identity: this._appIdentity });
97
+ yield this.transact((walletAPI) => __awaiter(this, void 0, void 0, function* () {
98
+ const { auth_token, pub_key: base58PublicKey, wallet_uri_base, } = yield walletAPI({ method: 'authorize', identity: this._appIdentity });
108
99
  try {
109
100
  this._publicKey = new PublicKey(base58PublicKey);
110
101
  }
@@ -112,9 +103,9 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
112
103
  throw new WalletPublicKeyError((e instanceof Error && (e === null || e === void 0 ? void 0 : e.message)) || 'Unknown error', e);
113
104
  }
114
105
  this.handleAuthorizationResult({
115
- authToken: auth_token,
116
- publicKey: base58PublicKey,
117
- walletUriBase: wallet_uri_base,
106
+ auth_token,
107
+ pub_key: base58PublicKey,
108
+ wallet_uri_base: wallet_uri_base,
118
109
  }); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
119
110
  this.emit('connect',
120
111
  // Having just set an `authorizationResult`, `this.publicKey` is definitely non-null
@@ -136,14 +127,15 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
136
127
  yield this._authorizationResultCache.set(authorizationResult);
137
128
  });
138
129
  }
139
- performReauthorization(mobileWallet, currentAuthorizationResult) {
130
+ performReauthorization(walletAPI, currentAuthorizationResult) {
140
131
  return __awaiter(this, void 0, void 0, function* () {
141
132
  try {
142
- const { auth_token } = yield mobileWallet('reauthorize', {
143
- auth_token: currentAuthorizationResult.authToken,
133
+ const { auth_token } = yield walletAPI({
134
+ method: 'reauthorize',
135
+ auth_token: currentAuthorizationResult.auth_token,
144
136
  });
145
- if (currentAuthorizationResult.authToken !== auth_token) {
146
- this.handleAuthorizationResult(Object.assign(Object.assign({}, currentAuthorizationResult), { authToken: auth_token })); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
137
+ if (currentAuthorizationResult.auth_token !== auth_token) {
138
+ this.handleAuthorizationResult(Object.assign(Object.assign({}, currentAuthorizationResult), { auth_token })); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
147
139
  }
148
140
  return auth_token;
149
141
  }
@@ -161,12 +153,12 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
161
153
  this.emit('disconnect');
162
154
  });
163
155
  }
164
- withWallet(callback) {
156
+ transact(callback) {
165
157
  var _a;
166
158
  return __awaiter(this, void 0, void 0, function* () {
167
- const walletUriBase = (_a = this._authorizationResult) === null || _a === void 0 ? void 0 : _a.walletUriBase;
159
+ const walletUriBase = (_a = this._authorizationResult) === null || _a === void 0 ? void 0 : _a.wallet_uri_base;
168
160
  const config = walletUriBase ? { baseUri: walletUriBase } : undefined;
169
- return yield withLocalWallet(callback, config);
161
+ return yield transact(callback, config);
170
162
  });
171
163
  }
172
164
  assertIsAuthorized() {
@@ -180,17 +172,14 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
180
172
  try {
181
173
  const authorizationResult = this.assertIsAuthorized();
182
174
  try {
183
- const serializedTransactions = transactions.map((transaction) => transaction.serialize({
184
- requireAllSignatures: false,
185
- verifySignatures: false,
186
- }));
187
- const payloads = serializedTransactions.map((serializedTransaction) => serializedTransaction.toString('base64'));
188
- return yield this.withWallet((mobileWallet) => __awaiter(this, void 0, void 0, function* () {
189
- const freshAuthToken = yield this.performReauthorization(mobileWallet, authorizationResult);
190
- const { signed_payloads: base64EncodedCompiledTransactions } = yield mobileWallet('sign_transaction', { auth_token: freshAuthToken, payloads });
191
- const compiledTransactions = base64EncodedCompiledTransactions.map(getByteArrayFromBase64String);
192
- const transactions = compiledTransactions.map(Transaction.from);
193
- return transactions;
175
+ return yield this.transact((walletAPI) => __awaiter(this, void 0, void 0, function* () {
176
+ const freshAuthToken = yield this.performReauthorization(walletAPI, authorizationResult);
177
+ const signedTransactions = yield walletAPI({
178
+ method: 'sign_transaction',
179
+ auth_token: freshAuthToken,
180
+ transactions,
181
+ });
182
+ return signedTransactions;
194
183
  }));
195
184
  }
196
185
  catch (error) {
@@ -208,34 +197,14 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
208
197
  try {
209
198
  const authorizationResult = this.assertIsAuthorized();
210
199
  try {
211
- if (transaction.feePayer == null) {
212
- transaction.feePayer = this.publicKey || undefined;
213
- }
214
- if (transaction.recentBlockhash == null) {
215
- const { blockhash } = yield connection.getRecentBlockhash(connection.commitment);
216
- transaction.recentBlockhash = blockhash;
217
- }
218
- const serializedTransaction = transaction.serialize({
219
- requireAllSignatures: false,
220
- verifySignatures: false,
221
- });
222
- const payloads = [serializedTransaction.toString('base64')];
223
- return yield this.withWallet((mobileWallet) => __awaiter(this, void 0, void 0, function* () {
224
- const freshAuthToken = yield this.performReauthorization(mobileWallet, authorizationResult);
225
- let targetCommitment;
226
- switch (connection.commitment) {
227
- case 'confirmed':
228
- case 'finalized':
229
- case 'processed':
230
- targetCommitment = connection.commitment;
231
- break;
232
- default:
233
- targetCommitment = 'finalized';
234
- }
235
- const { signatures } = yield mobileWallet('sign_and_send_transaction', {
200
+ return yield this.transact((walletAPI) => __awaiter(this, void 0, void 0, function* () {
201
+ const freshAuthToken = yield this.performReauthorization(walletAPI, authorizationResult);
202
+ const signatures = yield walletAPI({
203
+ method: 'sign_and_send_transaction',
236
204
  auth_token: freshAuthToken,
237
- commitment: targetCommitment,
238
- payloads,
205
+ fee_payer: this.publicKey || undefined,
206
+ connection,
207
+ transactions: [transaction],
239
208
  });
240
209
  return signatures[0];
241
210
  }));
@@ -267,13 +236,13 @@ class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
267
236
  try {
268
237
  const authorizationResult = this.assertIsAuthorized();
269
238
  try {
270
- return yield this.withWallet((mobileWallet) => __awaiter(this, void 0, void 0, function* () {
271
- const freshAuthToken = yield this.performReauthorization(mobileWallet, authorizationResult);
272
- const { signed_payloads: [base64EncodedSignedMessage], } = yield mobileWallet('sign_message', {
239
+ return yield this.transact((walletAPI) => __awaiter(this, void 0, void 0, function* () {
240
+ const freshAuthToken = yield this.performReauthorization(walletAPI, authorizationResult);
241
+ const [signedMessage] = yield walletAPI({
242
+ method: 'sign_message',
273
243
  auth_token: freshAuthToken,
274
- payloads: [getBase64StringFromByteArray(message)],
244
+ byteArrays: [message],
275
245
  });
276
- const signedMessage = getByteArrayFromBase64String(base64EncodedSignedMessage);
277
246
  const signature = signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES);
278
247
  return signature;
279
248
  }));
@@ -29,7 +29,7 @@ declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
29
29
  private handleAuthorizationResult;
30
30
  private performReauthorization;
31
31
  disconnect(): Promise<void>;
32
- private withWallet;
32
+ private transact;
33
33
  private assertIsAuthorized;
34
34
  private performSignTransactions;
35
35
  sendTransaction(transaction: Transaction, connection: Connection, _options?: SendOptions): Promise<TransactionSignature>;
@@ -29,7 +29,7 @@ declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
29
29
  private handleAuthorizationResult;
30
30
  private performReauthorization;
31
31
  disconnect(): Promise<void>;
32
- private withWallet;
32
+ private transact;
33
33
  private assertIsAuthorized;
34
34
  private performSignTransactions;
35
35
  sendTransaction(transaction: Transaction, connection: Connection, _options?: SendOptions): Promise<TransactionSignature>;
@@ -29,7 +29,7 @@ declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
29
29
  private handleAuthorizationResult;
30
30
  private performReauthorization;
31
31
  disconnect(): Promise<void>;
32
- private withWallet;
32
+ private transact;
33
33
  private assertIsAuthorized;
34
34
  private performSignTransactions;
35
35
  sendTransaction(transaction: Transaction, connection: Connection, _options?: SendOptions): Promise<TransactionSignature>;
@@ -29,7 +29,7 @@ declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
29
29
  private handleAuthorizationResult;
30
30
  private performReauthorization;
31
31
  disconnect(): Promise<void>;
32
- private withWallet;
32
+ private transact;
33
33
  private assertIsAuthorized;
34
34
  private performSignTransactions;
35
35
  sendTransaction(transaction: Transaction, connection: Connection, _options?: SendOptions): Promise<TransactionSignature>;
@@ -29,7 +29,7 @@ declare class SolanaMobileWalletAdapter extends BaseMessageSignerWalletAdapter {
29
29
  private handleAuthorizationResult;
30
30
  private performReauthorization;
31
31
  disconnect(): Promise<void>;
32
- private withWallet;
32
+ private transact;
33
33
  private assertIsAuthorized;
34
34
  private performSignTransactions;
35
35
  sendTransaction(transaction: Transaction, connection: Connection, _options?: SendOptions): Promise<TransactionSignature>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@solana-mobile/wallet-adapter-mobile",
3
3
  "description": "An adapter for mobile wallet apps that conform to the Solana Mobile Wallet Adapter protocol",
4
- "version": "0.0.1-alpha.1",
4
+ "version": "0.0.1-alpha.4",
5
5
  "author": "Steven Luscher <steven.luscher@solanamobile.com>",
6
6
  "repository": "https://github.com/solana-mobile/mobile-wallet-adapter",
7
7
  "license": "Apache-2.0",
@@ -40,8 +40,8 @@
40
40
  "@solana/web3.js": "^1.36.0"
41
41
  },
42
42
  "dependencies": {
43
- "@react-native-community/async-storage": "^1.12.1",
44
- "@solana-mobile/mobile-wallet-adapter-protocol": "^0.0.1-alpha.1",
43
+ "@react-native-async-storage/async-storage": "^1.17.7",
44
+ "@solana-mobile/mobile-wallet-adapter-protocol-web3js": "^0.0.1-alpha.4",
45
45
  "@solana/wallet-adapter-base": "^0.9.8",
46
46
  "@solana/web3.js": "^1.20.0"
47
47
  },
@@ -49,5 +49,5 @@
49
49
  "agadoo": "^2.0.0",
50
50
  "shx": "^0.3.4"
51
51
  },
52
- "gitHead": "56c859fc81d1dc009d9b49d93af440a5a3e600a9"
52
+ "gitHead": "d8a5244c5535b02f3dcf8144554a474ddac43f32"
53
53
  }