@solana-mobile/mobile-wallet-adapter-protocol 2.2.6 → 2.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -6
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +1 -1
- package/android/gradlew +1 -1
- package/lib/cjs/index.browser.js +827 -966
- package/lib/cjs/index.browser.js.map +1 -0
- package/lib/cjs/index.js +827 -966
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/index.native.js +245 -293
- package/lib/cjs/index.native.js.map +1 -0
- package/lib/cjs/package.json +1 -3
- package/lib/esm/index.browser.js +826 -964
- package/lib/esm/index.browser.js.map +1 -0
- package/lib/esm/index.js +826 -964
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/package.json +1 -3
- package/lib/types/index.d.ts +172 -181
- package/lib/types/index.d.ts.map +1 -1
- package/package.json +7 -6
- package/src/codegenSpec/NativeSolanaMobileWalletAdapter.ts +2 -0
- package/lib/types/index.browser.d.ts +0 -270
- package/lib/types/index.browser.d.ts.map +0 -1
- package/lib/types/index.native.d.ts +0 -270
- package/lib/types/index.native.d.ts.map +0 -1
package/lib/cjs/index.native.js
CHANGED
|
@@ -1,323 +1,273 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let react_native = require("react-native");
|
|
3
|
+
let _solana_codecs_strings = require("@solana/codecs-strings");
|
|
4
|
+
let js_base64 = require("js-base64");
|
|
5
|
+
let _solana_wallet_standard_util = require("@solana/wallet-standard-util");
|
|
6
|
+
//#region src/errors.ts
|
|
9
7
|
const SolanaMobileWalletAdapterErrorCode = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
8
|
+
ERROR_ASSOCIATION_PORT_OUT_OF_RANGE: "ERROR_ASSOCIATION_PORT_OUT_OF_RANGE",
|
|
9
|
+
ERROR_REFLECTOR_ID_OUT_OF_RANGE: "ERROR_REFLECTOR_ID_OUT_OF_RANGE",
|
|
10
|
+
ERROR_FORBIDDEN_WALLET_BASE_URL: "ERROR_FORBIDDEN_WALLET_BASE_URL",
|
|
11
|
+
ERROR_SECURE_CONTEXT_REQUIRED: "ERROR_SECURE_CONTEXT_REQUIRED",
|
|
12
|
+
ERROR_SESSION_CLOSED: "ERROR_SESSION_CLOSED",
|
|
13
|
+
ERROR_SESSION_TIMEOUT: "ERROR_SESSION_TIMEOUT",
|
|
14
|
+
ERROR_WALLET_NOT_FOUND: "ERROR_WALLET_NOT_FOUND",
|
|
15
|
+
ERROR_INVALID_PROTOCOL_VERSION: "ERROR_INVALID_PROTOCOL_VERSION",
|
|
16
|
+
ERROR_BROWSER_NOT_SUPPORTED: "ERROR_BROWSER_NOT_SUPPORTED",
|
|
17
|
+
ERROR_LOOPBACK_ACCESS_BLOCKED: "ERROR_LOOPBACK_ACCESS_BLOCKED",
|
|
18
|
+
ERROR_ASSOCIATION_CANCELLED: "ERROR_ASSOCIATION_CANCELLED"
|
|
19
|
+
};
|
|
20
|
+
var SolanaMobileWalletAdapterError = class extends Error {
|
|
21
|
+
data;
|
|
22
|
+
code;
|
|
23
|
+
constructor(...args) {
|
|
24
|
+
const [code, message, data] = args;
|
|
25
|
+
super(message);
|
|
26
|
+
this.code = code;
|
|
27
|
+
this.data = data;
|
|
28
|
+
this.name = "SolanaMobileWalletAdapterError";
|
|
29
|
+
}
|
|
21
30
|
};
|
|
22
|
-
class SolanaMobileWalletAdapterError extends Error {
|
|
23
|
-
data;
|
|
24
|
-
code;
|
|
25
|
-
constructor(...args) {
|
|
26
|
-
const [code, message, data] = args;
|
|
27
|
-
super(message);
|
|
28
|
-
this.code = code;
|
|
29
|
-
this.data = data;
|
|
30
|
-
this.name = 'SolanaMobileWalletAdapterError';
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
// Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
|
|
34
31
|
const SolanaMobileWalletAdapterProtocolErrorCode = {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
32
|
+
ERROR_AUTHORIZATION_FAILED: -1,
|
|
33
|
+
ERROR_INVALID_PAYLOADS: -2,
|
|
34
|
+
ERROR_NOT_SIGNED: -3,
|
|
35
|
+
ERROR_NOT_SUBMITTED: -4,
|
|
36
|
+
ERROR_TOO_MANY_PAYLOADS: -5,
|
|
37
|
+
ERROR_ATTEST_ORIGIN_ANDROID: -100
|
|
38
|
+
};
|
|
39
|
+
var SolanaMobileWalletAdapterProtocolError = class extends Error {
|
|
40
|
+
data;
|
|
41
|
+
code;
|
|
42
|
+
jsonRpcMessageId;
|
|
43
|
+
constructor(...args) {
|
|
44
|
+
const [jsonRpcMessageId, code, message, data] = args;
|
|
45
|
+
super(message);
|
|
46
|
+
this.code = code;
|
|
47
|
+
this.data = data;
|
|
48
|
+
this.jsonRpcMessageId = jsonRpcMessageId;
|
|
49
|
+
this.name = "SolanaMobileWalletAdapterProtocolError";
|
|
50
|
+
}
|
|
42
51
|
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
this.code = code;
|
|
51
|
-
this.data = data;
|
|
52
|
-
this.jsonRpcMessageId = jsonRpcMessageId;
|
|
53
|
-
this.name = 'SolanaMobileWalletAdapterProtocolError';
|
|
54
|
-
}
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/codegenSpec/NativeSolanaMobileWalletAdapter.ts
|
|
54
|
+
var NativeSolanaMobileWalletAdapter_default = react_native.TurboModuleRegistry.getEnforcing("SolanaMobileWalletAdapter");
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/base58Utils.ts
|
|
57
|
+
function fromUint8Array(byteArray) {
|
|
58
|
+
return (0, _solana_codecs_strings.getBase58Decoder)().decode(byteArray);
|
|
55
59
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
function base64ToBase58(base64EncodedString) {
|
|
61
|
+
return fromUint8Array((0, js_base64.toUint8Array)(base64EncodedString));
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/createSIWSMessage.ts
|
|
59
65
|
function createSIWSMessage(payload) {
|
|
60
|
-
|
|
66
|
+
return (0, _solana_wallet_standard_util.createSignInMessageText)(payload);
|
|
61
67
|
}
|
|
62
68
|
function createSIWSMessageBase64Url(payload) {
|
|
63
|
-
|
|
64
|
-
.replace(/\+/g, '-')
|
|
65
|
-
.replace(/\//g, '_')
|
|
66
|
-
.replace(/=+$/, ''); // convert to base64url encoding;
|
|
69
|
+
return (0, js_base64.encode)(createSIWSMessage(payload)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
67
70
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const SolanaSignTransactions =
|
|
71
|
-
const SolanaCloneAuthorization =
|
|
72
|
-
const SolanaSignInWithSolana =
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return codecsStrings.getBase58Decoder().decode(byteArray);
|
|
76
|
-
}
|
|
77
|
-
function base64ToBase58(base64EncodedString) {
|
|
78
|
-
return fromUint8Array(jsBase64.toUint8Array(base64EncodedString));
|
|
79
|
-
}
|
|
80
|
-
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/types.ts
|
|
73
|
+
const SolanaSignTransactions = "solana:signTransactions";
|
|
74
|
+
const SolanaCloneAuthorization = "solana:cloneAuthorization";
|
|
75
|
+
const SolanaSignInWithSolana = "solana:signInWithSolana";
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/createMobileWalletProxy.ts
|
|
81
78
|
/**
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
79
|
+
* Creates a {@link MobileWallet} proxy that handles backwards compatibility and API to RPC conversion.
|
|
80
|
+
*
|
|
81
|
+
* @param protocolVersion the protocol version in use for this session/request
|
|
82
|
+
* @param protocolRequestHandler callback function that handles sending the RPC request to the wallet endpoint.
|
|
83
|
+
* @returns a {@link MobileWallet} proxy
|
|
84
|
+
*/
|
|
88
85
|
function createMobileWalletProxy(protocolVersion, protocolRequestHandler) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
return target[p];
|
|
110
|
-
},
|
|
111
|
-
defineProperty() {
|
|
112
|
-
return false;
|
|
113
|
-
},
|
|
114
|
-
deleteProperty() {
|
|
115
|
-
return false;
|
|
116
|
-
},
|
|
117
|
-
});
|
|
86
|
+
return new Proxy({}, {
|
|
87
|
+
get(target, p) {
|
|
88
|
+
if (p === "then") return null;
|
|
89
|
+
if (target[p] == null) target[p] = async function(inputParams) {
|
|
90
|
+
const { method, params } = handleMobileWalletRequest(p, inputParams, protocolVersion);
|
|
91
|
+
const result = await protocolRequestHandler(method, params);
|
|
92
|
+
if (method === "authorize" && params.sign_in_payload && !result.sign_in_result) result.sign_in_result = await signInFallback(params.sign_in_payload, result, protocolRequestHandler);
|
|
93
|
+
return handleMobileWalletResponse(p, result, protocolVersion);
|
|
94
|
+
};
|
|
95
|
+
return target[p];
|
|
96
|
+
},
|
|
97
|
+
defineProperty() {
|
|
98
|
+
return false;
|
|
99
|
+
},
|
|
100
|
+
deleteProperty() {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
118
104
|
}
|
|
119
105
|
/**
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
106
|
+
* Handles all {@link MobileWallet} API requests and determines the correct MWA RPC method and params to call.
|
|
107
|
+
* This handles backwards compatibility, based on the provided @protocolVersion.
|
|
108
|
+
*
|
|
109
|
+
* @param methodName the name of {@link MobileWallet} method that was called
|
|
110
|
+
* @param methodParams the parameters that were passed to the method
|
|
111
|
+
* @param protocolVersion the protocol version in use for this session/request
|
|
112
|
+
* @returns the RPC request method and params that should be sent to the wallet endpoint
|
|
113
|
+
*/
|
|
128
114
|
function handleMobileWalletRequest(methodName, methodParams, protocolVersion) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
break;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return { method, params };
|
|
115
|
+
let params = methodParams;
|
|
116
|
+
let method = methodName.toString().replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`).toLowerCase();
|
|
117
|
+
switch (methodName) {
|
|
118
|
+
case "authorize": {
|
|
119
|
+
const authorizeParams = params;
|
|
120
|
+
let { chain } = authorizeParams;
|
|
121
|
+
if (protocolVersion === "legacy") {
|
|
122
|
+
switch (chain) {
|
|
123
|
+
case "solana:testnet":
|
|
124
|
+
chain = "testnet";
|
|
125
|
+
break;
|
|
126
|
+
case "solana:devnet":
|
|
127
|
+
chain = "devnet";
|
|
128
|
+
break;
|
|
129
|
+
case "solana:mainnet":
|
|
130
|
+
chain = "mainnet-beta";
|
|
131
|
+
break;
|
|
132
|
+
default: chain = authorizeParams.cluster;
|
|
133
|
+
}
|
|
134
|
+
authorizeParams.cluster = chain;
|
|
135
|
+
params = authorizeParams;
|
|
136
|
+
} else {
|
|
137
|
+
switch (chain) {
|
|
138
|
+
case "testnet":
|
|
139
|
+
case "devnet":
|
|
140
|
+
chain = `solana:${chain}`;
|
|
141
|
+
break;
|
|
142
|
+
case "mainnet-beta":
|
|
143
|
+
chain = "solana:mainnet";
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
authorizeParams.chain = chain;
|
|
147
|
+
params = authorizeParams;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
case "reauthorize": {
|
|
151
|
+
const { auth_token, identity } = params;
|
|
152
|
+
if (auth_token) switch (protocolVersion) {
|
|
153
|
+
case "legacy":
|
|
154
|
+
method = "reauthorize";
|
|
155
|
+
params = {
|
|
156
|
+
auth_token,
|
|
157
|
+
identity
|
|
158
|
+
};
|
|
159
|
+
break;
|
|
160
|
+
default:
|
|
161
|
+
method = "authorize";
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
method,
|
|
169
|
+
params
|
|
170
|
+
};
|
|
191
171
|
}
|
|
192
172
|
/**
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
173
|
+
* Handles all {@link MobileWallet} API responses and modifies the response for backwards compatibility, if needed
|
|
174
|
+
*
|
|
175
|
+
* @param method the {@link MobileWallet} method that was called
|
|
176
|
+
* @param response the original response that was returned by the method call
|
|
177
|
+
* @param protocolVersion the protocol version in use for this session/request
|
|
178
|
+
* @returns the possibly modified response
|
|
179
|
+
*/
|
|
200
180
|
function handleMobileWalletResponse(method, response, protocolVersion) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
return response;
|
|
181
|
+
switch (method) {
|
|
182
|
+
case "getCapabilities": {
|
|
183
|
+
const capabilities = response;
|
|
184
|
+
switch (protocolVersion) {
|
|
185
|
+
case "legacy": {
|
|
186
|
+
const features = [SolanaSignTransactions];
|
|
187
|
+
if (capabilities.supports_clone_authorization === true) features.push(SolanaCloneAuthorization);
|
|
188
|
+
return {
|
|
189
|
+
...capabilities,
|
|
190
|
+
features
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
case "v1": return {
|
|
194
|
+
...capabilities,
|
|
195
|
+
supports_sign_and_send_transactions: true,
|
|
196
|
+
supports_clone_authorization: capabilities.features.includes(SolanaCloneAuthorization)
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return response;
|
|
226
202
|
}
|
|
227
203
|
async function signInFallback(signInPayload, authorizationResult, protocolRequestHandler) {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
return signInResult;
|
|
204
|
+
const domain = signInPayload.domain ?? window.location.host;
|
|
205
|
+
const address = authorizationResult.accounts[0].address;
|
|
206
|
+
const siwsMessage = createSIWSMessageBase64Url({
|
|
207
|
+
...signInPayload,
|
|
208
|
+
domain,
|
|
209
|
+
address: base64ToBase58(address)
|
|
210
|
+
});
|
|
211
|
+
const signedPayload = (0, js_base64.toUint8Array)((await protocolRequestHandler("sign_messages", {
|
|
212
|
+
addresses: [address],
|
|
213
|
+
payloads: [siwsMessage]
|
|
214
|
+
})).signed_payloads[0]);
|
|
215
|
+
const signedMessage = (0, js_base64.fromUint8Array)(signedPayload.slice(0, signedPayload.length - 64));
|
|
216
|
+
const signature = (0, js_base64.fromUint8Array)(signedPayload.slice(signedPayload.length - 64));
|
|
217
|
+
return {
|
|
218
|
+
address,
|
|
219
|
+
signed_message: signedMessage.length == 0 ? siwsMessage : signedMessage,
|
|
220
|
+
signature
|
|
221
|
+
};
|
|
247
222
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
// The actual session management is handled in the native module.
|
|
253
|
-
// This is necessary for the React Native Android implementation to work correctly.
|
|
254
|
-
// The task is started before startActivityResult and stopped when the activity result callback is triggered
|
|
255
|
-
};
|
|
223
|
+
//#endregion
|
|
224
|
+
//#region src/__forks__/react-native/transact.ts
|
|
225
|
+
react_native.AppRegistry.registerHeadlessTask("SolanaMobileWalletAdapterSessionBackgroundTask", () => {
|
|
226
|
+
return async () => {};
|
|
256
227
|
});
|
|
257
|
-
const LINKING_ERROR =
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
' - You have added `@solana-mobile/mobile-wallet-adapter-protocol` to the `nohoist` section of your package.json\n' +
|
|
262
|
-
'- You are not using Expo managed workflow\n';
|
|
263
|
-
const SolanaMobileWalletAdapter = reactNative.Platform.OS === 'android' && NativeSolanaMobileWalletAdapter
|
|
264
|
-
? NativeSolanaMobileWalletAdapter
|
|
265
|
-
: new Proxy({}, {
|
|
266
|
-
get() {
|
|
267
|
-
throw new Error(reactNative.Platform.OS !== 'android'
|
|
268
|
-
? 'The package `solana-mobile-wallet-adapter-protocol` is only compatible with React Native Android'
|
|
269
|
-
: LINKING_ERROR);
|
|
270
|
-
},
|
|
271
|
-
});
|
|
228
|
+
const LINKING_ERROR = "The package 'solana-mobile-wallet-adapter-protocol' doesn't seem to be linked. Make sure: \n\n- You rebuilt the app after installing the package\n- If you are using Lerna workspaces\n - You have added `@solana-mobile/mobile-wallet-adapter-protocol` as an explicit dependency, and\n - You have added `@solana-mobile/mobile-wallet-adapter-protocol` to the `nohoist` section of your package.json\n- You are not using Expo managed workflow\n";
|
|
229
|
+
const SolanaMobileWalletAdapter = react_native.Platform.OS === "android" && NativeSolanaMobileWalletAdapter_default ? NativeSolanaMobileWalletAdapter_default : new Proxy({}, { get() {
|
|
230
|
+
throw new Error(react_native.Platform.OS !== "android" ? "The package `solana-mobile-wallet-adapter-protocol` is only compatible with React Native Android" : LINKING_ERROR);
|
|
231
|
+
} });
|
|
272
232
|
function getErrorMessage(e) {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
return e.message;
|
|
278
|
-
}
|
|
233
|
+
switch (e.code) {
|
|
234
|
+
case "ERROR_WALLET_NOT_FOUND": return "Found no installed wallet that supports the mobile wallet protocol.";
|
|
235
|
+
default: return e.message;
|
|
236
|
+
}
|
|
279
237
|
}
|
|
280
238
|
function handleError(e) {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
294
|
-
throw e;
|
|
239
|
+
if (e instanceof Error) {
|
|
240
|
+
const reactNativeError = e;
|
|
241
|
+
switch (reactNativeError.code) {
|
|
242
|
+
case void 0: throw e;
|
|
243
|
+
case "JSON_RPC_ERROR": {
|
|
244
|
+
const details = reactNativeError.userInfo;
|
|
245
|
+
throw new SolanaMobileWalletAdapterProtocolError(0, details.jsonRpcErrorCode, e.message);
|
|
246
|
+
}
|
|
247
|
+
default: throw new SolanaMobileWalletAdapterError(reactNativeError.code, getErrorMessage(reactNativeError), reactNativeError.userInfo);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
throw e;
|
|
295
251
|
}
|
|
296
252
|
async function transact(callback, config) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
}
|
|
314
|
-
finally {
|
|
315
|
-
if (didSuccessfullyConnect) {
|
|
316
|
-
await SolanaMobileWalletAdapter.endSession();
|
|
317
|
-
}
|
|
318
|
-
}
|
|
253
|
+
let didSuccessfullyConnect = false;
|
|
254
|
+
try {
|
|
255
|
+
const sessionProperties = await SolanaMobileWalletAdapter.startSession(config);
|
|
256
|
+
didSuccessfullyConnect = true;
|
|
257
|
+
return await callback(createMobileWalletProxy(sessionProperties.protocol_version, async (method, params) => {
|
|
258
|
+
try {
|
|
259
|
+
return SolanaMobileWalletAdapter.invoke(method, params);
|
|
260
|
+
} catch (e) {
|
|
261
|
+
return handleError(e);
|
|
262
|
+
}
|
|
263
|
+
}));
|
|
264
|
+
} catch (e) {
|
|
265
|
+
return handleError(e);
|
|
266
|
+
} finally {
|
|
267
|
+
if (didSuccessfullyConnect) await SolanaMobileWalletAdapter.endSession();
|
|
268
|
+
}
|
|
319
269
|
}
|
|
320
|
-
|
|
270
|
+
//#endregion
|
|
321
271
|
exports.SolanaCloneAuthorization = SolanaCloneAuthorization;
|
|
322
272
|
exports.SolanaMobileWalletAdapterError = SolanaMobileWalletAdapterError;
|
|
323
273
|
exports.SolanaMobileWalletAdapterErrorCode = SolanaMobileWalletAdapterErrorCode;
|
|
@@ -326,3 +276,5 @@ exports.SolanaMobileWalletAdapterProtocolErrorCode = SolanaMobileWalletAdapterPr
|
|
|
326
276
|
exports.SolanaSignInWithSolana = SolanaSignInWithSolana;
|
|
327
277
|
exports.SolanaSignTransactions = SolanaSignTransactions;
|
|
328
278
|
exports.transact = transact;
|
|
279
|
+
|
|
280
|
+
//# sourceMappingURL=index.native.js.map
|