@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/esm/index.browser.js
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { SolanaSignAndSendTransaction, SolanaSignIn, SolanaSignMessage, SolanaSignTransaction } from "@solana/wallet-standard-features";
|
|
2
|
-
import QRCode from "qrcode";
|
|
3
2
|
import { SolanaMobileWalletAdapterError, SolanaMobileWalletAdapterErrorCode, startRemoteScenario, startScenario } from "@solana-mobile/mobile-wallet-adapter-protocol";
|
|
4
3
|
import { StandardConnect, StandardDisconnect, StandardEvents } from "@wallet-standard/features";
|
|
5
4
|
import base58 from "bs58";
|
|
5
|
+
import QRCode from "qrcode";
|
|
6
6
|
import { registerWallet } from "@wallet-standard/wallet";
|
|
7
7
|
import { SOLANA_MAINNET_CHAIN } from "@solana/wallet-standard-chains";
|
|
8
|
+
//#region src/base64Utils.ts
|
|
9
|
+
function fromUint8Array(byteArray) {
|
|
10
|
+
return window.btoa(String.fromCharCode.call(null, ...byteArray));
|
|
11
|
+
}
|
|
12
|
+
function toUint8Array(base64EncodedByteArray) {
|
|
13
|
+
return new Uint8Array(window.atob(base64EncodedByteArray).split("").map((c) => c.charCodeAt(0)));
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
8
16
|
//#region src/embedded-modal/loadingSpinner.ts
|
|
9
17
|
const modalHtml$1 = `
|
|
10
18
|
<div class="mobile-wallet-adapter-embedded-loading-indicator" role="dialog" aria-modal="true" aria-labelledby="modal-title">
|
|
@@ -587,17 +595,6 @@ const css$4 = `
|
|
|
587
595
|
}
|
|
588
596
|
`;
|
|
589
597
|
//#endregion
|
|
590
|
-
//#region src/icon.ts
|
|
591
|
-
const icon = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik03IDIuNUgxN0MxNy44Mjg0IDIuNSAxOC41IDMuMTcxNTcgMTguNSA0VjIwQzE4LjUgMjAuODI4NCAxNy44Mjg0IDIxLjUgMTcgMjEuNUg3QzYuMTcxNTcgMjEuNSA1LjUgMjAuODI4NCA1LjUgMjBWNEM1LjUgMy4xNzE1NyA2LjE3MTU3IDIuNSA3IDIuNVpNMyA0QzMgMS43OTA4NiA0Ljc5MDg2IDAgNyAwSDE3QzE5LjIwOTEgMCAyMSAxLjc5MDg2IDIxIDRWMjBDMjEgMjIuMjA5MSAxOS4yMDkxIDI0IDE3IDI0SDdDNC43OTA4NiAyNCAzIDIyLjIwOTEgMyAyMFY0Wk0xMSA0LjYxNTM4QzEwLjQ0NzcgNC42MTUzOCAxMCA1LjA2MzEgMTAgNS42MTUzOFY2LjM4NDYyQzEwIDYuOTM2OSAxMC40NDc3IDcuMzg0NjIgMTEgNy4zODQ2MkgxM0MxMy41NTIzIDcuMzg0NjIgMTQgNi45MzY5IDE0IDYuMzg0NjJWNS42MTUzOEMxNCA1LjA2MzEgMTMuNTUyMyA0LjYxNTM4IDEzIDQuNjE1MzhIMTFaIiBmaWxsPSIjRENCOEZGIi8+Cjwvc3ZnPgo=";
|
|
592
|
-
//#endregion
|
|
593
|
-
//#region src/base64Utils.ts
|
|
594
|
-
function fromUint8Array(byteArray) {
|
|
595
|
-
return window.btoa(String.fromCharCode.call(null, ...byteArray));
|
|
596
|
-
}
|
|
597
|
-
function toUint8Array(base64EncodedByteArray) {
|
|
598
|
-
return new Uint8Array(window.atob(base64EncodedByteArray).split("").map((c) => c.charCodeAt(0)));
|
|
599
|
-
}
|
|
600
|
-
//#endregion
|
|
601
598
|
//#region src/embedded-modal/localConnectionModal.ts
|
|
602
599
|
var LocalConnectionModal = class extends EmbeddedModal {
|
|
603
600
|
contentStyles = css$3;
|
|
@@ -849,7 +846,7 @@ var LoopbackPermissionModal = class extends EmbeddedModal {
|
|
|
849
846
|
launchButton?.removeEventListener("click", listener);
|
|
850
847
|
try {
|
|
851
848
|
await fetch("http://localhost");
|
|
852
|
-
} catch
|
|
849
|
+
} catch {}
|
|
853
850
|
this.close();
|
|
854
851
|
};
|
|
855
852
|
launchButton?.addEventListener("click", listener);
|
|
@@ -953,7 +950,7 @@ function getIsPwaLaunchedAsApp() {
|
|
|
953
950
|
async function checkLocalNetworkAccessPermission() {
|
|
954
951
|
if (typeof navigator !== "undefined" && isSolanaMobileWebShell(navigator.userAgent)) return;
|
|
955
952
|
try {
|
|
956
|
-
|
|
953
|
+
const lnaPermission = await navigator.permissions.query({ name: "loopback-network" });
|
|
957
954
|
if (lnaPermission.state === "granted") return;
|
|
958
955
|
else if (lnaPermission.state === "denied") {
|
|
959
956
|
const modal = new LoopbackPermissionBlockedModal();
|
|
@@ -994,6 +991,9 @@ async function checkLocalNetworkAccessPermission() {
|
|
|
994
991
|
}
|
|
995
992
|
}
|
|
996
993
|
//#endregion
|
|
994
|
+
//#region src/icon.ts
|
|
995
|
+
const icon = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik03IDIuNUgxN0MxNy44Mjg0IDIuNSAxOC41IDMuMTcxNTcgMTguNSA0VjIwQzE4LjUgMjAuODI4NCAxNy44Mjg0IDIxLjUgMTcgMjEuNUg3QzYuMTcxNTcgMjEuNSA1LjUgMjAuODI4NCA1LjUgMjBWNEM1LjUgMy4xNzE1NyA2LjE3MTU3IDIuNSA3IDIuNVpNMyA0QzMgMS43OTA4NiA0Ljc5MDg2IDAgNyAwSDE3QzE5LjIwOTEgMCAyMSAxLjc5MDg2IDIxIDRWMjBDMjEgMjIuMjA5MSAxOS4yMDkxIDI0IDE3IDI0SDdDNC43OTA4NiAyNCAzIDIyLjIwOTEgMyAyMFY0Wk0xMSA0LjYxNTM4QzEwLjQ0NzcgNC42MTUzOCAxMCA1LjA2MzEgMTAgNS42MTUzOFY2LjM4NDYyQzEwIDYuOTM2OSAxMC40NDc3IDcuMzg0NjIgMTEgNy4zODQ2MkgxM0MxMy41NTIzIDcuMzg0NjIgMTQgNi45MzY5IDE0IDYuMzg0NjJWNS42MTUzOEMxNCA1LjA2MzEgMTMuNTUyMyA0LjYxNTM4IDEzIDQuNjE1MzhIMTFaIiBmaWxsPSIjRENCOEZGIi8+Cjwvc3ZnPgo=";
|
|
996
|
+
//#endregion
|
|
997
997
|
//#region src/wallet.ts
|
|
998
998
|
const SolanaMobileWalletAdapterWalletName = "Mobile Wallet Adapter";
|
|
999
999
|
const SolanaMobileWalletAdapterRemoteWalletName = "Remote Mobile Wallet Adapter";
|
|
@@ -1005,6 +1005,9 @@ const DEFAULT_FEATURES = [
|
|
|
1005
1005
|
SolanaSignIn
|
|
1006
1006
|
];
|
|
1007
1007
|
const WALLET_ASSOCIATION_TIMEOUT = 3e4;
|
|
1008
|
+
function getErrorMessage(error) {
|
|
1009
|
+
return error instanceof Error ? error.message : "Unknown error";
|
|
1010
|
+
}
|
|
1008
1011
|
var LocalSolanaMobileWalletAdapterWallet = class {
|
|
1009
1012
|
#listeners = {};
|
|
1010
1013
|
#version = "1.0.0";
|
|
@@ -1121,7 +1124,7 @@ var LocalSolanaMobileWalletAdapterWallet = class {
|
|
|
1121
1124
|
} else return { accounts: this.accounts };
|
|
1122
1125
|
} else await this.#performAuthorization();
|
|
1123
1126
|
} catch (e) {
|
|
1124
|
-
throw new Error(e
|
|
1127
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
1125
1128
|
} finally {
|
|
1126
1129
|
this.#connecting = false;
|
|
1127
1130
|
}
|
|
@@ -1156,7 +1159,7 @@ var LocalSolanaMobileWalletAdapterWallet = class {
|
|
|
1156
1159
|
return authorization;
|
|
1157
1160
|
});
|
|
1158
1161
|
} catch (e) {
|
|
1159
|
-
throw new Error(e
|
|
1162
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
1160
1163
|
}
|
|
1161
1164
|
};
|
|
1162
1165
|
#handleAuthorizationResult = async (authorization) => {
|
|
@@ -1199,7 +1202,7 @@ var LocalSolanaMobileWalletAdapterWallet = class {
|
|
|
1199
1202
|
Promise.all([this.#authorizationCache.set(authorization), this.#handleAuthorizationResult(authorization)]);
|
|
1200
1203
|
} catch (e) {
|
|
1201
1204
|
this.#disconnect();
|
|
1202
|
-
throw new Error(e
|
|
1205
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
1203
1206
|
}
|
|
1204
1207
|
};
|
|
1205
1208
|
#disconnect = async () => {
|
|
@@ -1215,10 +1218,12 @@ var LocalSolanaMobileWalletAdapterWallet = class {
|
|
|
1215
1218
|
const currentConnectionGeneration = this.#connectionGeneration;
|
|
1216
1219
|
const loadingSpinner = new EmbeddedLoadingSpinner();
|
|
1217
1220
|
try {
|
|
1221
|
+
let associating = true;
|
|
1218
1222
|
let timeout = void 0;
|
|
1219
1223
|
const result = await Promise.race([checkLocalNetworkAccessPermission().then(async () => {
|
|
1220
1224
|
loadingSpinner.init();
|
|
1221
1225
|
const { wallet, close } = await startScenario(config);
|
|
1226
|
+
associating = false;
|
|
1222
1227
|
loadingSpinner.addEventListener("close", (event) => {
|
|
1223
1228
|
if (event) close();
|
|
1224
1229
|
});
|
|
@@ -1229,7 +1234,7 @@ var LocalSolanaMobileWalletAdapterWallet = class {
|
|
|
1229
1234
|
return result;
|
|
1230
1235
|
}), new Promise((_, reject) => {
|
|
1231
1236
|
timeout = setTimeout(() => {
|
|
1232
|
-
reject(new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_ASSOCIATION_CANCELLED, "Wallet connection timed out", { event: void 0 }));
|
|
1237
|
+
if (associating) reject(new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_ASSOCIATION_CANCELLED, "Wallet connection timed out", { event: void 0 }));
|
|
1233
1238
|
}, WALLET_ASSOCIATION_TIMEOUT);
|
|
1234
1239
|
})]);
|
|
1235
1240
|
clearTimeout(timeout);
|
|
@@ -1272,14 +1277,14 @@ var LocalSolanaMobileWalletAdapterWallet = class {
|
|
|
1272
1277
|
return (await wallet.signTransactions({ payloads: base64Transactions })).signed_payloads.map(toUint8Array);
|
|
1273
1278
|
});
|
|
1274
1279
|
} catch (e) {
|
|
1275
|
-
throw new Error(e
|
|
1280
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
1276
1281
|
}
|
|
1277
1282
|
};
|
|
1278
1283
|
#performSignAndSendTransaction = async (transaction, options) => {
|
|
1279
1284
|
const { authToken, chain } = this.#assertIsAuthorized();
|
|
1280
1285
|
try {
|
|
1281
1286
|
return await this.#transact(async (wallet) => {
|
|
1282
|
-
const [capabilities
|
|
1287
|
+
const [capabilities] = await Promise.all([wallet.getCapabilities(), this.#performReauthorization(wallet, authToken, chain)]);
|
|
1283
1288
|
if (capabilities.supports_sign_and_send_transactions) {
|
|
1284
1289
|
const base64Transaction = fromUint8Array(transaction);
|
|
1285
1290
|
return (await wallet.signAndSendTransactions({
|
|
@@ -1289,7 +1294,7 @@ var LocalSolanaMobileWalletAdapterWallet = class {
|
|
|
1289
1294
|
} else throw new Error("connected wallet does not support signAndSendTransaction");
|
|
1290
1295
|
});
|
|
1291
1296
|
} catch (e) {
|
|
1292
|
-
throw new Error(e
|
|
1297
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
1293
1298
|
}
|
|
1294
1299
|
};
|
|
1295
1300
|
#signAndSendTransaction = async (...inputs) => {
|
|
@@ -1323,7 +1328,7 @@ var LocalSolanaMobileWalletAdapterWallet = class {
|
|
|
1323
1328
|
});
|
|
1324
1329
|
});
|
|
1325
1330
|
} catch (e) {
|
|
1326
|
-
throw new Error(e
|
|
1331
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
1327
1332
|
}
|
|
1328
1333
|
};
|
|
1329
1334
|
#signIn = async (...inputs) => {
|
|
@@ -1353,7 +1358,7 @@ var LocalSolanaMobileWalletAdapterWallet = class {
|
|
|
1353
1358
|
signature: toUint8Array(authorizationResult.sign_in_result.signature)
|
|
1354
1359
|
};
|
|
1355
1360
|
} catch (e) {
|
|
1356
|
-
throw new Error(e
|
|
1361
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
1357
1362
|
} finally {
|
|
1358
1363
|
this.#connecting = false;
|
|
1359
1364
|
}
|
|
@@ -1466,13 +1471,13 @@ var RemoteSolanaMobileWalletAdapterWallet = class {
|
|
|
1466
1471
|
#off(event, listener) {
|
|
1467
1472
|
this.#listeners[event] = this.#listeners[event]?.filter((existingListener) => listener !== existingListener);
|
|
1468
1473
|
}
|
|
1469
|
-
#connect = async (
|
|
1474
|
+
#connect = async (_input = {}) => {
|
|
1470
1475
|
if (this.#connecting || this.connected) return { accounts: this.accounts };
|
|
1471
1476
|
this.#connecting = true;
|
|
1472
1477
|
try {
|
|
1473
1478
|
await this.#performAuthorization();
|
|
1474
1479
|
} catch (e) {
|
|
1475
|
-
throw new Error(e
|
|
1480
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
1476
1481
|
} finally {
|
|
1477
1482
|
this.#connecting = false;
|
|
1478
1483
|
}
|
|
@@ -1508,7 +1513,7 @@ var RemoteSolanaMobileWalletAdapterWallet = class {
|
|
|
1508
1513
|
return authorizationResult;
|
|
1509
1514
|
});
|
|
1510
1515
|
} catch (e) {
|
|
1511
|
-
throw new Error(e
|
|
1516
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
1512
1517
|
}
|
|
1513
1518
|
};
|
|
1514
1519
|
#handleAuthorizationResult = async (authorization) => {
|
|
@@ -1551,7 +1556,7 @@ var RemoteSolanaMobileWalletAdapterWallet = class {
|
|
|
1551
1556
|
Promise.all([this.#authorizationCache.set(authorization), this.#handleAuthorizationResult(authorization)]);
|
|
1552
1557
|
} catch (e) {
|
|
1553
1558
|
this.#disconnect();
|
|
1554
|
-
throw new Error(e
|
|
1559
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
1555
1560
|
}
|
|
1556
1561
|
};
|
|
1557
1562
|
#disconnect = async () => {
|
|
@@ -1622,14 +1627,14 @@ var RemoteSolanaMobileWalletAdapterWallet = class {
|
|
|
1622
1627
|
return (await wallet.signTransactions({ payloads: transactions.map(fromUint8Array) })).signed_payloads.map(toUint8Array);
|
|
1623
1628
|
});
|
|
1624
1629
|
} catch (e) {
|
|
1625
|
-
throw new Error(e
|
|
1630
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
1626
1631
|
}
|
|
1627
1632
|
};
|
|
1628
1633
|
#performSignAndSendTransaction = async (transaction, options) => {
|
|
1629
1634
|
const { authToken, chain } = this.#assertIsAuthorized();
|
|
1630
1635
|
try {
|
|
1631
1636
|
return await this.#transact(async (wallet) => {
|
|
1632
|
-
const [capabilities
|
|
1637
|
+
const [capabilities] = await Promise.all([wallet.getCapabilities(), this.#performReauthorization(wallet, authToken, chain)]);
|
|
1633
1638
|
if (capabilities.supports_sign_and_send_transactions) return (await wallet.signAndSendTransactions({
|
|
1634
1639
|
...options,
|
|
1635
1640
|
payloads: [fromUint8Array(transaction)]
|
|
@@ -1637,7 +1642,7 @@ var RemoteSolanaMobileWalletAdapterWallet = class {
|
|
|
1637
1642
|
else throw new Error("connected wallet does not support signAndSendTransaction");
|
|
1638
1643
|
});
|
|
1639
1644
|
} catch (e) {
|
|
1640
|
-
throw new Error(e
|
|
1645
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
1641
1646
|
}
|
|
1642
1647
|
};
|
|
1643
1648
|
#signAndSendTransaction = async (...inputs) => {
|
|
@@ -1671,7 +1676,7 @@ var RemoteSolanaMobileWalletAdapterWallet = class {
|
|
|
1671
1676
|
});
|
|
1672
1677
|
});
|
|
1673
1678
|
} catch (e) {
|
|
1674
|
-
throw new Error(e
|
|
1679
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
1675
1680
|
}
|
|
1676
1681
|
};
|
|
1677
1682
|
#signIn = async (...inputs) => {
|
|
@@ -1701,7 +1706,7 @@ var RemoteSolanaMobileWalletAdapterWallet = class {
|
|
|
1701
1706
|
signature: toUint8Array(authorizationResult.sign_in_result.signature)
|
|
1702
1707
|
};
|
|
1703
1708
|
} catch (e) {
|
|
1704
|
-
throw new Error(e
|
|
1709
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
1705
1710
|
} finally {
|
|
1706
1711
|
this.#connecting = false;
|
|
1707
1712
|
}
|