@solana-mobile/mobile-wallet-adapter-protocol 2.2.5 → 2.2.7
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/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 +844 -1020
- package/lib/cjs/index.browser.js.map +1 -0
- package/lib/cjs/index.js +844 -1020
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/index.native.js +241 -312
- package/lib/cjs/index.native.js.map +1 -0
- package/lib/cjs/package.json +1 -3
- package/lib/esm/index.browser.js +842 -1016
- package/lib/esm/index.browser.js.map +1 -0
- package/lib/esm/index.js +842 -1016
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/package.json +1 -3
- package/lib/types/index.d.ts +174 -176
- package/lib/types/index.d.ts.map +1 -1
- package/package.json +75 -75
- package/lib/types/index.browser.d.ts +0 -263
- package/lib/types/index.browser.d.ts.map +0 -1
- package/lib/types/index.native.d.ts +0 -263
- package/lib/types/index.native.d.ts.map +0 -1
package/lib/cjs/index.native.js
CHANGED
|
@@ -1,343 +1,270 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var walletStandardUtil = require('@solana/wallet-standard-util');
|
|
8
|
-
var codecsStrings = require('@solana/codecs-strings');
|
|
9
|
-
|
|
10
|
-
// 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 js_base64 = require("js-base64");
|
|
4
|
+
let _solana_wallet_standard_util = require("@solana/wallet-standard-util");
|
|
5
|
+
let _solana_codecs_strings = require("@solana/codecs-strings");
|
|
6
|
+
//#region src/errors.ts
|
|
11
7
|
const SolanaMobileWalletAdapterErrorCode = {
|
|
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
|
-
constructor(...args) {
|
|
24
|
-
const [code, message, data] = args;
|
|
25
|
-
super(message);
|
|
26
|
-
this.code = code;
|
|
27
|
-
this.data = data;
|
|
28
|
-
this.name = 'SolanaMobileWalletAdapterError';
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
// Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
|
|
32
31
|
const SolanaMobileWalletAdapterProtocolErrorCode = {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
ERROR_ATTEST_ORIGIN_ANDROID: -100,
|
|
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
|
|
40
38
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
var NativeSolanaMobileWalletAdapter = reactNative.TurboModuleRegistry.getEnforcing('SolanaMobileWalletAdapter');
|
|
78
|
-
|
|
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
|
+
}
|
|
51
|
+
};
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/codegenSpec/NativeSolanaMobileWalletAdapter.ts
|
|
54
|
+
var NativeSolanaMobileWalletAdapter_default = react_native.TurboModuleRegistry.getEnforcing("SolanaMobileWalletAdapter");
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/createSIWSMessage.ts
|
|
79
57
|
function createSIWSMessage(payload) {
|
|
80
|
-
|
|
58
|
+
return (0, _solana_wallet_standard_util.createSignInMessageText)(payload);
|
|
81
59
|
}
|
|
82
60
|
function createSIWSMessageBase64Url(payload) {
|
|
83
|
-
|
|
84
|
-
.replace(/\+/g, '-')
|
|
85
|
-
.replace(/\//g, '_')
|
|
86
|
-
.replace(/=+$/, ''); // convert to base64url encoding;
|
|
61
|
+
return (0, js_base64.encode)(createSIWSMessage(payload)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
87
62
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const SolanaSignTransactions =
|
|
91
|
-
const SolanaCloneAuthorization =
|
|
92
|
-
const SolanaSignInWithSolana =
|
|
93
|
-
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/types.ts
|
|
65
|
+
const SolanaSignTransactions = "solana:signTransactions";
|
|
66
|
+
const SolanaCloneAuthorization = "solana:cloneAuthorization";
|
|
67
|
+
const SolanaSignInWithSolana = "solana:signInWithSolana";
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/base58Utils.ts
|
|
94
70
|
function fromUint8Array(byteArray) {
|
|
95
|
-
|
|
71
|
+
return (0, _solana_codecs_strings.getBase58Decoder)().decode(byteArray);
|
|
96
72
|
}
|
|
97
73
|
function base64ToBase58(base64EncodedString) {
|
|
98
|
-
|
|
74
|
+
return fromUint8Array((0, js_base64.toUint8Array)(base64EncodedString));
|
|
99
75
|
}
|
|
100
|
-
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/createMobileWalletProxy.ts
|
|
101
78
|
/**
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
+
*/
|
|
108
85
|
function createMobileWalletProxy(protocolVersion, protocolRequestHandler) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return handleMobileWalletResponse(p, result, protocolVersion);
|
|
128
|
-
});
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
return target[p];
|
|
132
|
-
},
|
|
133
|
-
defineProperty() {
|
|
134
|
-
return false;
|
|
135
|
-
},
|
|
136
|
-
deleteProperty() {
|
|
137
|
-
return false;
|
|
138
|
-
},
|
|
139
|
-
});
|
|
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
|
+
});
|
|
140
104
|
}
|
|
141
105
|
/**
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
+
*/
|
|
150
114
|
function handleMobileWalletRequest(methodName, methodParams, protocolVersion) {
|
|
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
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
method = 'authorize';
|
|
205
|
-
break;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
break;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
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
|
+
let { chain } = params;
|
|
120
|
+
if (protocolVersion === "legacy") {
|
|
121
|
+
switch (chain) {
|
|
122
|
+
case "solana:testnet":
|
|
123
|
+
chain = "testnet";
|
|
124
|
+
break;
|
|
125
|
+
case "solana:devnet":
|
|
126
|
+
chain = "devnet";
|
|
127
|
+
break;
|
|
128
|
+
case "solana:mainnet":
|
|
129
|
+
chain = "mainnet-beta";
|
|
130
|
+
break;
|
|
131
|
+
default: chain = params.cluster;
|
|
132
|
+
}
|
|
133
|
+
params.cluster = chain;
|
|
134
|
+
} else {
|
|
135
|
+
switch (chain) {
|
|
136
|
+
case "testnet":
|
|
137
|
+
case "devnet":
|
|
138
|
+
chain = `solana:${chain}`;
|
|
139
|
+
break;
|
|
140
|
+
case "mainnet-beta":
|
|
141
|
+
chain = "solana:mainnet";
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
params.chain = chain;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
case "reauthorize": {
|
|
148
|
+
const { auth_token, identity } = params;
|
|
149
|
+
if (auth_token) switch (protocolVersion) {
|
|
150
|
+
case "legacy":
|
|
151
|
+
method = "reauthorize";
|
|
152
|
+
params = {
|
|
153
|
+
auth_token,
|
|
154
|
+
identity
|
|
155
|
+
};
|
|
156
|
+
break;
|
|
157
|
+
default:
|
|
158
|
+
method = "authorize";
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
method,
|
|
166
|
+
params
|
|
167
|
+
};
|
|
213
168
|
}
|
|
214
169
|
/**
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
170
|
+
* Handles all {@link MobileWallet} API responses and modifies the response for backwards compatibility, if needed
|
|
171
|
+
*
|
|
172
|
+
* @param method the {@link MobileWallet} method that was called
|
|
173
|
+
* @param response the original response that was returned by the method call
|
|
174
|
+
* @param protocolVersion the protocol version in use for this session/request
|
|
175
|
+
* @returns the possibly modified response
|
|
176
|
+
*/
|
|
222
177
|
function handleMobileWalletResponse(method, response, protocolVersion) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
178
|
+
switch (method) {
|
|
179
|
+
case "getCapabilities": {
|
|
180
|
+
const capabilities = response;
|
|
181
|
+
switch (protocolVersion) {
|
|
182
|
+
case "legacy": {
|
|
183
|
+
const features = [SolanaSignTransactions];
|
|
184
|
+
if (capabilities.supports_clone_authorization === true) features.push(SolanaCloneAuthorization);
|
|
185
|
+
return {
|
|
186
|
+
...capabilities,
|
|
187
|
+
features
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
case "v1": return {
|
|
191
|
+
...capabilities,
|
|
192
|
+
supports_sign_and_send_transactions: true,
|
|
193
|
+
supports_clone_authorization: capabilities.features.includes(SolanaCloneAuthorization)
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return response;
|
|
241
199
|
}
|
|
242
|
-
function signInFallback(signInPayload, authorizationResult, protocolRequestHandler) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
signature
|
|
262
|
-
};
|
|
263
|
-
return signInResult;
|
|
264
|
-
});
|
|
200
|
+
async function signInFallback(signInPayload, authorizationResult, protocolRequestHandler) {
|
|
201
|
+
const domain = signInPayload.domain ?? window.location.host;
|
|
202
|
+
const address = authorizationResult.accounts[0].address;
|
|
203
|
+
const siwsMessage = createSIWSMessageBase64Url({
|
|
204
|
+
...signInPayload,
|
|
205
|
+
domain,
|
|
206
|
+
address: base64ToBase58(address)
|
|
207
|
+
});
|
|
208
|
+
const signedPayload = (0, js_base64.toUint8Array)((await protocolRequestHandler("sign_messages", {
|
|
209
|
+
addresses: [address],
|
|
210
|
+
payloads: [siwsMessage]
|
|
211
|
+
})).signed_payloads[0]);
|
|
212
|
+
const signedMessage = (0, js_base64.fromUint8Array)(signedPayload.slice(0, signedPayload.length - 64));
|
|
213
|
+
const signature = (0, js_base64.fromUint8Array)(signedPayload.slice(signedPayload.length - 64));
|
|
214
|
+
return {
|
|
215
|
+
address,
|
|
216
|
+
signed_message: signedMessage.length == 0 ? siwsMessage : signedMessage,
|
|
217
|
+
signature
|
|
218
|
+
};
|
|
265
219
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
// The actual session management is handled in the native module.
|
|
271
|
-
// This is necessary for the React Native Android implementation to work correctly.
|
|
272
|
-
// The task is started before startActivityResult and stopped when the activity result callback is triggered
|
|
273
|
-
});
|
|
220
|
+
//#endregion
|
|
221
|
+
//#region src/__forks__/react-native/transact.ts
|
|
222
|
+
react_native.AppRegistry.registerHeadlessTask("SolanaMobileWalletAdapterSessionBackgroundTask", () => {
|
|
223
|
+
return async () => {};
|
|
274
224
|
});
|
|
275
|
-
const LINKING_ERROR =
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
' - You have added `@solana-mobile/mobile-wallet-adapter-protocol` to the `nohoist` section of your package.json\n' +
|
|
280
|
-
'- You are not using Expo managed workflow\n';
|
|
281
|
-
const SolanaMobileWalletAdapter = reactNative.Platform.OS === 'android' && NativeSolanaMobileWalletAdapter
|
|
282
|
-
? NativeSolanaMobileWalletAdapter
|
|
283
|
-
: new Proxy({}, {
|
|
284
|
-
get() {
|
|
285
|
-
throw new Error(reactNative.Platform.OS !== 'android'
|
|
286
|
-
? 'The package `solana-mobile-wallet-adapter-protocol` is only compatible with React Native Android'
|
|
287
|
-
: LINKING_ERROR);
|
|
288
|
-
},
|
|
289
|
-
});
|
|
225
|
+
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";
|
|
226
|
+
const SolanaMobileWalletAdapter = react_native.Platform.OS === "android" && NativeSolanaMobileWalletAdapter_default ? NativeSolanaMobileWalletAdapter_default : new Proxy({}, { get() {
|
|
227
|
+
throw new Error(react_native.Platform.OS !== "android" ? "The package `solana-mobile-wallet-adapter-protocol` is only compatible with React Native Android" : LINKING_ERROR);
|
|
228
|
+
} });
|
|
290
229
|
function getErrorMessage(e) {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
return e.message;
|
|
296
|
-
}
|
|
230
|
+
switch (e.code) {
|
|
231
|
+
case "ERROR_WALLET_NOT_FOUND": return "Found no installed wallet that supports the mobile wallet protocol.";
|
|
232
|
+
default: return e.message;
|
|
233
|
+
}
|
|
297
234
|
}
|
|
298
235
|
function handleError(e) {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
}
|
|
312
|
-
throw e;
|
|
236
|
+
if (e instanceof Error) {
|
|
237
|
+
const reactNativeError = e;
|
|
238
|
+
switch (reactNativeError.code) {
|
|
239
|
+
case void 0: throw e;
|
|
240
|
+
case "JSON_RPC_ERROR": {
|
|
241
|
+
const details = reactNativeError.userInfo;
|
|
242
|
+
throw new SolanaMobileWalletAdapterProtocolError(0, details.jsonRpcErrorCode, e.message);
|
|
243
|
+
}
|
|
244
|
+
default: throw new SolanaMobileWalletAdapterError(reactNativeError.code, getErrorMessage(reactNativeError), reactNativeError.userInfo);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
throw e;
|
|
313
248
|
}
|
|
314
|
-
function transact(callback, config) {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
return handleError(e);
|
|
332
|
-
}
|
|
333
|
-
finally {
|
|
334
|
-
if (didSuccessfullyConnect) {
|
|
335
|
-
yield SolanaMobileWalletAdapter.endSession();
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
});
|
|
249
|
+
async function transact(callback, config) {
|
|
250
|
+
let didSuccessfullyConnect = false;
|
|
251
|
+
try {
|
|
252
|
+
const sessionProperties = await SolanaMobileWalletAdapter.startSession(config);
|
|
253
|
+
didSuccessfullyConnect = true;
|
|
254
|
+
return await callback(createMobileWalletProxy(sessionProperties.protocol_version, async (method, params) => {
|
|
255
|
+
try {
|
|
256
|
+
return SolanaMobileWalletAdapter.invoke(method, params);
|
|
257
|
+
} catch (e) {
|
|
258
|
+
return handleError(e);
|
|
259
|
+
}
|
|
260
|
+
}));
|
|
261
|
+
} catch (e) {
|
|
262
|
+
return handleError(e);
|
|
263
|
+
} finally {
|
|
264
|
+
if (didSuccessfullyConnect) await SolanaMobileWalletAdapter.endSession();
|
|
265
|
+
}
|
|
339
266
|
}
|
|
340
|
-
|
|
267
|
+
//#endregion
|
|
341
268
|
exports.SolanaCloneAuthorization = SolanaCloneAuthorization;
|
|
342
269
|
exports.SolanaMobileWalletAdapterError = SolanaMobileWalletAdapterError;
|
|
343
270
|
exports.SolanaMobileWalletAdapterErrorCode = SolanaMobileWalletAdapterErrorCode;
|
|
@@ -346,3 +273,5 @@ exports.SolanaMobileWalletAdapterProtocolErrorCode = SolanaMobileWalletAdapterPr
|
|
|
346
273
|
exports.SolanaSignInWithSolana = SolanaSignInWithSolana;
|
|
347
274
|
exports.SolanaSignTransactions = SolanaSignTransactions;
|
|
348
275
|
exports.transact = transact;
|
|
276
|
+
|
|
277
|
+
//# sourceMappingURL=index.native.js.map
|