@solana-mobile/wallet-standard-mobile 0.5.1 → 0.5.2
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 +38 -33
- package/lib/cjs/index.browser.js.map +1 -1
- package/lib/cjs/index.js +38 -33
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/index.native.js +31 -26
- package/lib/cjs/index.native.js.map +1 -1
- package/lib/esm/index.browser.js +37 -32
- package/lib/esm/index.browser.js.map +1 -1
- package/lib/esm/index.js +37 -32
- package/lib/esm/index.js.map +1 -1
- package/lib/types/index.d.ts.map +1 -1
- package/package.json +2 -2
package/lib/cjs/index.browser.js
CHANGED
|
@@ -22,14 +22,22 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
}) : target, mod));
|
|
23
23
|
//#endregion
|
|
24
24
|
let _solana_wallet_standard_features = require("@solana/wallet-standard-features");
|
|
25
|
-
let qrcode = require("qrcode");
|
|
26
|
-
qrcode = __toESM(qrcode);
|
|
27
25
|
let _solana_mobile_mobile_wallet_adapter_protocol = require("@solana-mobile/mobile-wallet-adapter-protocol");
|
|
28
26
|
let _wallet_standard_features = require("@wallet-standard/features");
|
|
29
27
|
let bs58 = require("bs58");
|
|
30
28
|
bs58 = __toESM(bs58);
|
|
29
|
+
let qrcode = require("qrcode");
|
|
30
|
+
qrcode = __toESM(qrcode);
|
|
31
31
|
let _wallet_standard_wallet = require("@wallet-standard/wallet");
|
|
32
32
|
let _solana_wallet_standard_chains = require("@solana/wallet-standard-chains");
|
|
33
|
+
//#region src/base64Utils.ts
|
|
34
|
+
function fromUint8Array(byteArray) {
|
|
35
|
+
return window.btoa(String.fromCharCode.call(null, ...byteArray));
|
|
36
|
+
}
|
|
37
|
+
function toUint8Array(base64EncodedByteArray) {
|
|
38
|
+
return new Uint8Array(window.atob(base64EncodedByteArray).split("").map((c) => c.charCodeAt(0)));
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
33
41
|
//#region src/embedded-modal/loadingSpinner.ts
|
|
34
42
|
const modalHtml$1 = `
|
|
35
43
|
<div class="mobile-wallet-adapter-embedded-loading-indicator" role="dialog" aria-modal="true" aria-labelledby="modal-title">
|
|
@@ -612,17 +620,6 @@ const css$4 = `
|
|
|
612
620
|
}
|
|
613
621
|
`;
|
|
614
622
|
//#endregion
|
|
615
|
-
//#region src/icon.ts
|
|
616
|
-
const icon = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik03IDIuNUgxN0MxNy44Mjg0IDIuNSAxOC41IDMuMTcxNTcgMTguNSA0VjIwQzE4LjUgMjAuODI4NCAxNy44Mjg0IDIxLjUgMTcgMjEuNUg3QzYuMTcxNTcgMjEuNSA1LjUgMjAuODI4NCA1LjUgMjBWNEM1LjUgMy4xNzE1NyA2LjE3MTU3IDIuNSA3IDIuNVpNMyA0QzMgMS43OTA4NiA0Ljc5MDg2IDAgNyAwSDE3QzE5LjIwOTEgMCAyMSAxLjc5MDg2IDIxIDRWMjBDMjEgMjIuMjA5MSAxOS4yMDkxIDI0IDE3IDI0SDdDNC43OTA4NiAyNCAzIDIyLjIwOTEgMyAyMFY0Wk0xMSA0LjYxNTM4QzEwLjQ0NzcgNC42MTUzOCAxMCA1LjA2MzEgMTAgNS42MTUzOFY2LjM4NDYyQzEwIDYuOTM2OSAxMC40NDc3IDcuMzg0NjIgMTEgNy4zODQ2MkgxM0MxMy41NTIzIDcuMzg0NjIgMTQgNi45MzY5IDE0IDYuMzg0NjJWNS42MTUzOEMxNCA1LjA2MzEgMTMuNTUyMyA0LjYxNTM4IDEzIDQuNjE1MzhIMTFaIiBmaWxsPSIjRENCOEZGIi8+Cjwvc3ZnPgo=";
|
|
617
|
-
//#endregion
|
|
618
|
-
//#region src/base64Utils.ts
|
|
619
|
-
function fromUint8Array(byteArray) {
|
|
620
|
-
return window.btoa(String.fromCharCode.call(null, ...byteArray));
|
|
621
|
-
}
|
|
622
|
-
function toUint8Array(base64EncodedByteArray) {
|
|
623
|
-
return new Uint8Array(window.atob(base64EncodedByteArray).split("").map((c) => c.charCodeAt(0)));
|
|
624
|
-
}
|
|
625
|
-
//#endregion
|
|
626
623
|
//#region src/embedded-modal/localConnectionModal.ts
|
|
627
624
|
var LocalConnectionModal = class extends EmbeddedModal {
|
|
628
625
|
contentStyles = css$3;
|
|
@@ -874,7 +871,7 @@ var LoopbackPermissionModal = class extends EmbeddedModal {
|
|
|
874
871
|
launchButton?.removeEventListener("click", listener);
|
|
875
872
|
try {
|
|
876
873
|
await fetch("http://localhost");
|
|
877
|
-
} catch
|
|
874
|
+
} catch {}
|
|
878
875
|
this.close();
|
|
879
876
|
};
|
|
880
877
|
launchButton?.addEventListener("click", listener);
|
|
@@ -978,7 +975,7 @@ function getIsPwaLaunchedAsApp() {
|
|
|
978
975
|
async function checkLocalNetworkAccessPermission() {
|
|
979
976
|
if (typeof navigator !== "undefined" && isSolanaMobileWebShell(navigator.userAgent)) return;
|
|
980
977
|
try {
|
|
981
|
-
|
|
978
|
+
const lnaPermission = await navigator.permissions.query({ name: "loopback-network" });
|
|
982
979
|
if (lnaPermission.state === "granted") return;
|
|
983
980
|
else if (lnaPermission.state === "denied") {
|
|
984
981
|
const modal = new LoopbackPermissionBlockedModal();
|
|
@@ -1019,6 +1016,9 @@ async function checkLocalNetworkAccessPermission() {
|
|
|
1019
1016
|
}
|
|
1020
1017
|
}
|
|
1021
1018
|
//#endregion
|
|
1019
|
+
//#region src/icon.ts
|
|
1020
|
+
const icon = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik03IDIuNUgxN0MxNy44Mjg0IDIuNSAxOC41IDMuMTcxNTcgMTguNSA0VjIwQzE4LjUgMjAuODI4NCAxNy44Mjg0IDIxLjUgMTcgMjEuNUg3QzYuMTcxNTcgMjEuNSA1LjUgMjAuODI4NCA1LjUgMjBWNEM1LjUgMy4xNzE1NyA2LjE3MTU3IDIuNSA3IDIuNVpNMyA0QzMgMS43OTA4NiA0Ljc5MDg2IDAgNyAwSDE3QzE5LjIwOTEgMCAyMSAxLjc5MDg2IDIxIDRWMjBDMjEgMjIuMjA5MSAxOS4yMDkxIDI0IDE3IDI0SDdDNC43OTA4NiAyNCAzIDIyLjIwOTEgMyAyMFY0Wk0xMSA0LjYxNTM4QzEwLjQ0NzcgNC42MTUzOCAxMCA1LjA2MzEgMTAgNS42MTUzOFY2LjM4NDYyQzEwIDYuOTM2OSAxMC40NDc3IDcuMzg0NjIgMTEgNy4zODQ2MkgxM0MxMy41NTIzIDcuMzg0NjIgMTQgNi45MzY5IDE0IDYuMzg0NjJWNS42MTUzOEMxNCA1LjA2MzEgMTMuNTUyMyA0LjYxNTM4IDEzIDQuNjE1MzhIMTFaIiBmaWxsPSIjRENCOEZGIi8+Cjwvc3ZnPgo=";
|
|
1021
|
+
//#endregion
|
|
1022
1022
|
//#region src/wallet.ts
|
|
1023
1023
|
const SolanaMobileWalletAdapterWalletName = "Mobile Wallet Adapter";
|
|
1024
1024
|
const SolanaMobileWalletAdapterRemoteWalletName = "Remote Mobile Wallet Adapter";
|
|
@@ -1030,6 +1030,9 @@ const DEFAULT_FEATURES = [
|
|
|
1030
1030
|
_solana_wallet_standard_features.SolanaSignIn
|
|
1031
1031
|
];
|
|
1032
1032
|
const WALLET_ASSOCIATION_TIMEOUT = 3e4;
|
|
1033
|
+
function getErrorMessage(error) {
|
|
1034
|
+
return error instanceof Error ? error.message : "Unknown error";
|
|
1035
|
+
}
|
|
1033
1036
|
var LocalSolanaMobileWalletAdapterWallet = class {
|
|
1034
1037
|
#listeners = {};
|
|
1035
1038
|
#version = "1.0.0";
|
|
@@ -1146,7 +1149,7 @@ var LocalSolanaMobileWalletAdapterWallet = class {
|
|
|
1146
1149
|
} else return { accounts: this.accounts };
|
|
1147
1150
|
} else await this.#performAuthorization();
|
|
1148
1151
|
} catch (e) {
|
|
1149
|
-
throw new Error(e
|
|
1152
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
1150
1153
|
} finally {
|
|
1151
1154
|
this.#connecting = false;
|
|
1152
1155
|
}
|
|
@@ -1181,7 +1184,7 @@ var LocalSolanaMobileWalletAdapterWallet = class {
|
|
|
1181
1184
|
return authorization;
|
|
1182
1185
|
});
|
|
1183
1186
|
} catch (e) {
|
|
1184
|
-
throw new Error(e
|
|
1187
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
1185
1188
|
}
|
|
1186
1189
|
};
|
|
1187
1190
|
#handleAuthorizationResult = async (authorization) => {
|
|
@@ -1224,7 +1227,7 @@ var LocalSolanaMobileWalletAdapterWallet = class {
|
|
|
1224
1227
|
Promise.all([this.#authorizationCache.set(authorization), this.#handleAuthorizationResult(authorization)]);
|
|
1225
1228
|
} catch (e) {
|
|
1226
1229
|
this.#disconnect();
|
|
1227
|
-
throw new Error(e
|
|
1230
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
1228
1231
|
}
|
|
1229
1232
|
};
|
|
1230
1233
|
#disconnect = async () => {
|
|
@@ -1240,10 +1243,12 @@ var LocalSolanaMobileWalletAdapterWallet = class {
|
|
|
1240
1243
|
const currentConnectionGeneration = this.#connectionGeneration;
|
|
1241
1244
|
const loadingSpinner = new EmbeddedLoadingSpinner();
|
|
1242
1245
|
try {
|
|
1246
|
+
let associating = true;
|
|
1243
1247
|
let timeout = void 0;
|
|
1244
1248
|
const result = await Promise.race([checkLocalNetworkAccessPermission().then(async () => {
|
|
1245
1249
|
loadingSpinner.init();
|
|
1246
1250
|
const { wallet, close } = await (0, _solana_mobile_mobile_wallet_adapter_protocol.startScenario)(config);
|
|
1251
|
+
associating = false;
|
|
1247
1252
|
loadingSpinner.addEventListener("close", (event) => {
|
|
1248
1253
|
if (event) close();
|
|
1249
1254
|
});
|
|
@@ -1254,7 +1259,7 @@ var LocalSolanaMobileWalletAdapterWallet = class {
|
|
|
1254
1259
|
return result;
|
|
1255
1260
|
}), new Promise((_, reject) => {
|
|
1256
1261
|
timeout = setTimeout(() => {
|
|
1257
|
-
reject(new _solana_mobile_mobile_wallet_adapter_protocol.SolanaMobileWalletAdapterError(_solana_mobile_mobile_wallet_adapter_protocol.SolanaMobileWalletAdapterErrorCode.ERROR_ASSOCIATION_CANCELLED, "Wallet connection timed out", { event: void 0 }));
|
|
1262
|
+
if (associating) reject(new _solana_mobile_mobile_wallet_adapter_protocol.SolanaMobileWalletAdapterError(_solana_mobile_mobile_wallet_adapter_protocol.SolanaMobileWalletAdapterErrorCode.ERROR_ASSOCIATION_CANCELLED, "Wallet connection timed out", { event: void 0 }));
|
|
1258
1263
|
}, WALLET_ASSOCIATION_TIMEOUT);
|
|
1259
1264
|
})]);
|
|
1260
1265
|
clearTimeout(timeout);
|
|
@@ -1297,14 +1302,14 @@ var LocalSolanaMobileWalletAdapterWallet = class {
|
|
|
1297
1302
|
return (await wallet.signTransactions({ payloads: base64Transactions })).signed_payloads.map(toUint8Array);
|
|
1298
1303
|
});
|
|
1299
1304
|
} catch (e) {
|
|
1300
|
-
throw new Error(e
|
|
1305
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
1301
1306
|
}
|
|
1302
1307
|
};
|
|
1303
1308
|
#performSignAndSendTransaction = async (transaction, options) => {
|
|
1304
1309
|
const { authToken, chain } = this.#assertIsAuthorized();
|
|
1305
1310
|
try {
|
|
1306
1311
|
return await this.#transact(async (wallet) => {
|
|
1307
|
-
const [capabilities
|
|
1312
|
+
const [capabilities] = await Promise.all([wallet.getCapabilities(), this.#performReauthorization(wallet, authToken, chain)]);
|
|
1308
1313
|
if (capabilities.supports_sign_and_send_transactions) {
|
|
1309
1314
|
const base64Transaction = fromUint8Array(transaction);
|
|
1310
1315
|
return (await wallet.signAndSendTransactions({
|
|
@@ -1314,7 +1319,7 @@ var LocalSolanaMobileWalletAdapterWallet = class {
|
|
|
1314
1319
|
} else throw new Error("connected wallet does not support signAndSendTransaction");
|
|
1315
1320
|
});
|
|
1316
1321
|
} catch (e) {
|
|
1317
|
-
throw new Error(e
|
|
1322
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
1318
1323
|
}
|
|
1319
1324
|
};
|
|
1320
1325
|
#signAndSendTransaction = async (...inputs) => {
|
|
@@ -1348,7 +1353,7 @@ var LocalSolanaMobileWalletAdapterWallet = class {
|
|
|
1348
1353
|
});
|
|
1349
1354
|
});
|
|
1350
1355
|
} catch (e) {
|
|
1351
|
-
throw new Error(e
|
|
1356
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
1352
1357
|
}
|
|
1353
1358
|
};
|
|
1354
1359
|
#signIn = async (...inputs) => {
|
|
@@ -1378,7 +1383,7 @@ var LocalSolanaMobileWalletAdapterWallet = class {
|
|
|
1378
1383
|
signature: toUint8Array(authorizationResult.sign_in_result.signature)
|
|
1379
1384
|
};
|
|
1380
1385
|
} catch (e) {
|
|
1381
|
-
throw new Error(e
|
|
1386
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
1382
1387
|
} finally {
|
|
1383
1388
|
this.#connecting = false;
|
|
1384
1389
|
}
|
|
@@ -1491,13 +1496,13 @@ var RemoteSolanaMobileWalletAdapterWallet = class {
|
|
|
1491
1496
|
#off(event, listener) {
|
|
1492
1497
|
this.#listeners[event] = this.#listeners[event]?.filter((existingListener) => listener !== existingListener);
|
|
1493
1498
|
}
|
|
1494
|
-
#connect = async (
|
|
1499
|
+
#connect = async (_input = {}) => {
|
|
1495
1500
|
if (this.#connecting || this.connected) return { accounts: this.accounts };
|
|
1496
1501
|
this.#connecting = true;
|
|
1497
1502
|
try {
|
|
1498
1503
|
await this.#performAuthorization();
|
|
1499
1504
|
} catch (e) {
|
|
1500
|
-
throw new Error(e
|
|
1505
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
1501
1506
|
} finally {
|
|
1502
1507
|
this.#connecting = false;
|
|
1503
1508
|
}
|
|
@@ -1533,7 +1538,7 @@ var RemoteSolanaMobileWalletAdapterWallet = class {
|
|
|
1533
1538
|
return authorizationResult;
|
|
1534
1539
|
});
|
|
1535
1540
|
} catch (e) {
|
|
1536
|
-
throw new Error(e
|
|
1541
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
1537
1542
|
}
|
|
1538
1543
|
};
|
|
1539
1544
|
#handleAuthorizationResult = async (authorization) => {
|
|
@@ -1576,7 +1581,7 @@ var RemoteSolanaMobileWalletAdapterWallet = class {
|
|
|
1576
1581
|
Promise.all([this.#authorizationCache.set(authorization), this.#handleAuthorizationResult(authorization)]);
|
|
1577
1582
|
} catch (e) {
|
|
1578
1583
|
this.#disconnect();
|
|
1579
|
-
throw new Error(e
|
|
1584
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
1580
1585
|
}
|
|
1581
1586
|
};
|
|
1582
1587
|
#disconnect = async () => {
|
|
@@ -1647,14 +1652,14 @@ var RemoteSolanaMobileWalletAdapterWallet = class {
|
|
|
1647
1652
|
return (await wallet.signTransactions({ payloads: transactions.map(fromUint8Array) })).signed_payloads.map(toUint8Array);
|
|
1648
1653
|
});
|
|
1649
1654
|
} catch (e) {
|
|
1650
|
-
throw new Error(e
|
|
1655
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
1651
1656
|
}
|
|
1652
1657
|
};
|
|
1653
1658
|
#performSignAndSendTransaction = async (transaction, options) => {
|
|
1654
1659
|
const { authToken, chain } = this.#assertIsAuthorized();
|
|
1655
1660
|
try {
|
|
1656
1661
|
return await this.#transact(async (wallet) => {
|
|
1657
|
-
const [capabilities
|
|
1662
|
+
const [capabilities] = await Promise.all([wallet.getCapabilities(), this.#performReauthorization(wallet, authToken, chain)]);
|
|
1658
1663
|
if (capabilities.supports_sign_and_send_transactions) return (await wallet.signAndSendTransactions({
|
|
1659
1664
|
...options,
|
|
1660
1665
|
payloads: [fromUint8Array(transaction)]
|
|
@@ -1662,7 +1667,7 @@ var RemoteSolanaMobileWalletAdapterWallet = class {
|
|
|
1662
1667
|
else throw new Error("connected wallet does not support signAndSendTransaction");
|
|
1663
1668
|
});
|
|
1664
1669
|
} catch (e) {
|
|
1665
|
-
throw new Error(e
|
|
1670
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
1666
1671
|
}
|
|
1667
1672
|
};
|
|
1668
1673
|
#signAndSendTransaction = async (...inputs) => {
|
|
@@ -1696,7 +1701,7 @@ var RemoteSolanaMobileWalletAdapterWallet = class {
|
|
|
1696
1701
|
});
|
|
1697
1702
|
});
|
|
1698
1703
|
} catch (e) {
|
|
1699
|
-
throw new Error(e
|
|
1704
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
1700
1705
|
}
|
|
1701
1706
|
};
|
|
1702
1707
|
#signIn = async (...inputs) => {
|
|
@@ -1726,7 +1731,7 @@ var RemoteSolanaMobileWalletAdapterWallet = class {
|
|
|
1726
1731
|
signature: toUint8Array(authorizationResult.sign_in_result.signature)
|
|
1727
1732
|
};
|
|
1728
1733
|
} catch (e) {
|
|
1729
|
-
throw new Error(e
|
|
1734
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
1730
1735
|
} finally {
|
|
1731
1736
|
this.#connecting = false;
|
|
1732
1737
|
}
|