@solana-mobile/mobile-wallet-adapter-protocol 2.2.5 → 2.2.6
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/android/build.gradle +3 -3
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +2 -1
- package/android/gradle.properties +1 -1
- package/android/gradlew +173 -110
- package/android/gradlew.bat +22 -18
- package/lib/cjs/index.browser.js +451 -480
- package/lib/cjs/index.js +451 -480
- package/lib/cjs/index.native.js +66 -86
- package/lib/esm/index.browser.js +451 -479
- package/lib/esm/index.js +451 -479
- package/lib/types/index.browser.d.ts +9 -2
- package/lib/types/index.d.ts +9 -2
- package/lib/types/index.native.d.ts +9 -2
- package/package.json +74 -75
package/lib/cjs/index.native.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var reactNative = require('react-native');
|
|
6
4
|
var jsBase64 = require('js-base64');
|
|
7
5
|
var walletStandardUtil = require('@solana/wallet-standard-util');
|
|
@@ -18,8 +16,12 @@ const SolanaMobileWalletAdapterErrorCode = {
|
|
|
18
16
|
ERROR_WALLET_NOT_FOUND: 'ERROR_WALLET_NOT_FOUND',
|
|
19
17
|
ERROR_INVALID_PROTOCOL_VERSION: 'ERROR_INVALID_PROTOCOL_VERSION',
|
|
20
18
|
ERROR_BROWSER_NOT_SUPPORTED: 'ERROR_BROWSER_NOT_SUPPORTED',
|
|
19
|
+
ERROR_LOOPBACK_ACCESS_BLOCKED: 'ERROR_LOOPBACK_ACCESS_BLOCKED',
|
|
20
|
+
ERROR_ASSOCIATION_CANCELLED: 'ERROR_ASSOCIATION_CANCELLED',
|
|
21
21
|
};
|
|
22
22
|
class SolanaMobileWalletAdapterError extends Error {
|
|
23
|
+
data;
|
|
24
|
+
code;
|
|
23
25
|
constructor(...args) {
|
|
24
26
|
const [code, message, data] = args;
|
|
25
27
|
super(message);
|
|
@@ -39,6 +41,9 @@ const SolanaMobileWalletAdapterProtocolErrorCode = {
|
|
|
39
41
|
ERROR_ATTEST_ORIGIN_ANDROID: -100,
|
|
40
42
|
};
|
|
41
43
|
class SolanaMobileWalletAdapterProtocolError extends Error {
|
|
44
|
+
data;
|
|
45
|
+
code;
|
|
46
|
+
jsonRpcMessageId;
|
|
42
47
|
constructor(...args) {
|
|
43
48
|
const [jsonRpcMessageId, code, message, data] = args;
|
|
44
49
|
super(message);
|
|
@@ -49,31 +54,6 @@ class SolanaMobileWalletAdapterProtocolError extends Error {
|
|
|
49
54
|
}
|
|
50
55
|
}
|
|
51
56
|
|
|
52
|
-
/******************************************************************************
|
|
53
|
-
Copyright (c) Microsoft Corporation.
|
|
54
|
-
|
|
55
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
56
|
-
purpose with or without fee is hereby granted.
|
|
57
|
-
|
|
58
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
59
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
60
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
61
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
62
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
63
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
64
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
65
|
-
***************************************************************************** */
|
|
66
|
-
|
|
67
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
68
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
69
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
70
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
71
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
72
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
73
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
57
|
var NativeSolanaMobileWalletAdapter = reactNative.TurboModuleRegistry.getEnforcing('SolanaMobileWalletAdapter');
|
|
78
58
|
|
|
79
59
|
function createSIWSMessage(payload) {
|
|
@@ -116,16 +96,14 @@ function createMobileWalletProxy(protocolVersion, protocolRequestHandler) {
|
|
|
116
96
|
return null;
|
|
117
97
|
}
|
|
118
98
|
if (target[p] == null) {
|
|
119
|
-
target[p] = function (inputParams) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return handleMobileWalletResponse(p, result, protocolVersion);
|
|
128
|
-
});
|
|
99
|
+
target[p] = async function (inputParams) {
|
|
100
|
+
const { method, params } = handleMobileWalletRequest(p, inputParams, protocolVersion);
|
|
101
|
+
const result = await protocolRequestHandler(method, params);
|
|
102
|
+
// if the request tried to sign in but the wallet did not return a sign in result, fallback on message signing
|
|
103
|
+
if (method === 'authorize' && params.sign_in_payload && !result.sign_in_result) {
|
|
104
|
+
result['sign_in_result'] = await signInFallback(params.sign_in_payload, result, protocolRequestHandler);
|
|
105
|
+
}
|
|
106
|
+
return handleMobileWalletResponse(p, result, protocolVersion);
|
|
129
107
|
};
|
|
130
108
|
}
|
|
131
109
|
return target[p];
|
|
@@ -229,48 +207,52 @@ function handleMobileWalletResponse(method, response, protocolVersion) {
|
|
|
229
207
|
if (capabilities.supports_clone_authorization === true) {
|
|
230
208
|
features.push(SolanaCloneAuthorization);
|
|
231
209
|
}
|
|
232
|
-
return
|
|
210
|
+
return {
|
|
211
|
+
...capabilities,
|
|
212
|
+
features: features,
|
|
213
|
+
};
|
|
233
214
|
}
|
|
234
215
|
case 'v1': {
|
|
235
|
-
return
|
|
216
|
+
return {
|
|
217
|
+
...capabilities,
|
|
218
|
+
supports_sign_and_send_transactions: true,
|
|
219
|
+
supports_clone_authorization: capabilities.features.includes(SolanaCloneAuthorization)
|
|
220
|
+
};
|
|
236
221
|
}
|
|
237
222
|
}
|
|
238
223
|
}
|
|
239
224
|
}
|
|
240
225
|
return response;
|
|
241
226
|
}
|
|
242
|
-
function signInFallback(signInPayload, authorizationResult, protocolRequestHandler) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
addresses: [address],
|
|
250
|
-
payloads: [siwsMessage]
|
|
251
|
-
});
|
|
252
|
-
const signedPayload = jsBase64.toUint8Array(signMessageResult.signed_payloads[0]);
|
|
253
|
-
const signedMessage = jsBase64.fromUint8Array(signedPayload.slice(0, signedPayload.length - 64));
|
|
254
|
-
const signature = jsBase64.fromUint8Array(signedPayload.slice(signedPayload.length - 64));
|
|
255
|
-
const signInResult = {
|
|
256
|
-
address: address,
|
|
257
|
-
// Workaround: some wallets have been observed to only reply with the message signature.
|
|
258
|
-
// This is non-compliant with the spec, but in the interest of maximizing compatibility,
|
|
259
|
-
// detect this case and reuse the original message.
|
|
260
|
-
signed_message: signedMessage.length == 0 ? siwsMessage : signedMessage,
|
|
261
|
-
signature
|
|
262
|
-
};
|
|
263
|
-
return signInResult;
|
|
227
|
+
async function signInFallback(signInPayload, authorizationResult, protocolRequestHandler) {
|
|
228
|
+
const domain = signInPayload.domain ?? window.location.host;
|
|
229
|
+
const address = authorizationResult.accounts[0].address;
|
|
230
|
+
const siwsMessage = createSIWSMessageBase64Url({ ...signInPayload, domain, address: base64ToBase58(address) });
|
|
231
|
+
const signMessageResult = await protocolRequestHandler('sign_messages', {
|
|
232
|
+
addresses: [address],
|
|
233
|
+
payloads: [siwsMessage]
|
|
264
234
|
});
|
|
235
|
+
const signedPayload = jsBase64.toUint8Array(signMessageResult.signed_payloads[0]);
|
|
236
|
+
const signedMessage = jsBase64.fromUint8Array(signedPayload.slice(0, signedPayload.length - 64));
|
|
237
|
+
const signature = jsBase64.fromUint8Array(signedPayload.slice(signedPayload.length - 64));
|
|
238
|
+
const signInResult = {
|
|
239
|
+
address: address,
|
|
240
|
+
// Workaround: some wallets have been observed to only reply with the message signature.
|
|
241
|
+
// This is non-compliant with the spec, but in the interest of maximizing compatibility,
|
|
242
|
+
// detect this case and reuse the original message.
|
|
243
|
+
signed_message: signedMessage.length == 0 ? siwsMessage : signedMessage,
|
|
244
|
+
signature
|
|
245
|
+
};
|
|
246
|
+
return signInResult;
|
|
265
247
|
}
|
|
266
248
|
|
|
267
249
|
reactNative.AppRegistry.registerHeadlessTask('SolanaMobileWalletAdapterSessionBackgroundTask', () => {
|
|
268
|
-
return () =>
|
|
250
|
+
return async () => {
|
|
269
251
|
// This is a no-op task that is used to keep the app alive while the session is active.
|
|
270
252
|
// The actual session management is handled in the native module.
|
|
271
253
|
// This is necessary for the React Native Android implementation to work correctly.
|
|
272
254
|
// The task is started before startActivityResult and stopped when the activity result callback is triggered
|
|
273
|
-
}
|
|
255
|
+
};
|
|
274
256
|
});
|
|
275
257
|
const LINKING_ERROR = `The package 'solana-mobile-wallet-adapter-protocol' doesn't seem to be linked. Make sure: \n\n` +
|
|
276
258
|
'- You rebuilt the app after installing the package\n' +
|
|
@@ -311,31 +293,29 @@ function handleError(e) {
|
|
|
311
293
|
}
|
|
312
294
|
throw e;
|
|
313
295
|
}
|
|
314
|
-
function transact(callback, config) {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
return SolanaMobileWalletAdapter.invoke(method, params);
|
|
323
|
-
}
|
|
324
|
-
catch (e) {
|
|
325
|
-
return handleError(e);
|
|
326
|
-
}
|
|
327
|
-
}));
|
|
328
|
-
return yield callback(wallet);
|
|
329
|
-
}
|
|
330
|
-
catch (e) {
|
|
331
|
-
return handleError(e);
|
|
332
|
-
}
|
|
333
|
-
finally {
|
|
334
|
-
if (didSuccessfullyConnect) {
|
|
335
|
-
yield SolanaMobileWalletAdapter.endSession();
|
|
296
|
+
async function transact(callback, config) {
|
|
297
|
+
let didSuccessfullyConnect = false;
|
|
298
|
+
try {
|
|
299
|
+
const sessionProperties = await SolanaMobileWalletAdapter.startSession(config);
|
|
300
|
+
didSuccessfullyConnect = true;
|
|
301
|
+
const wallet = createMobileWalletProxy(sessionProperties.protocol_version, async (method, params) => {
|
|
302
|
+
try {
|
|
303
|
+
return SolanaMobileWalletAdapter.invoke(method, params);
|
|
336
304
|
}
|
|
305
|
+
catch (e) {
|
|
306
|
+
return handleError(e);
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
return await callback(wallet);
|
|
310
|
+
}
|
|
311
|
+
catch (e) {
|
|
312
|
+
return handleError(e);
|
|
313
|
+
}
|
|
314
|
+
finally {
|
|
315
|
+
if (didSuccessfullyConnect) {
|
|
316
|
+
await SolanaMobileWalletAdapter.endSession();
|
|
337
317
|
}
|
|
338
|
-
}
|
|
318
|
+
}
|
|
339
319
|
}
|
|
340
320
|
|
|
341
321
|
exports.SolanaCloneAuthorization = SolanaCloneAuthorization;
|