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