@forge-connect/react 1.0.1 → 1.0.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/dist/index.cjs +63 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +107 -60
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/provider.tsx
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/provider.tsx
|
|
2
2
|
var _react = require('react');
|
|
3
3
|
|
|
4
4
|
// src/context.ts
|
|
@@ -1233,7 +1233,7 @@ async function startAuthentication(options) {
|
|
|
1233
1233
|
}
|
|
1234
1234
|
|
|
1235
1235
|
// src/runtime-imports.ts
|
|
1236
|
-
var importSolanaWeb3 = () =>
|
|
1236
|
+
var importSolanaWeb3 = () => Promise.resolve().then(() => _interopRequireWildcard(require("@solana/web3.js")));
|
|
1237
1237
|
|
|
1238
1238
|
// src/components/tabs/wallet-connect.tsx
|
|
1239
1239
|
|
|
@@ -2144,19 +2144,33 @@ function useWallets() {
|
|
|
2144
2144
|
[api, getAccessToken, fetchWallets]
|
|
2145
2145
|
);
|
|
2146
2146
|
const linkWallet = _react.useCallback.call(void 0,
|
|
2147
|
-
async (walletAddress, signMessage, chain = "solana") => {
|
|
2147
|
+
async (walletAddress, signMessage, chain = "solana", signTransaction) => {
|
|
2148
2148
|
const token = getAccessToken();
|
|
2149
2149
|
if (!token) throw new Error("Please sign in to continue.");
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2150
|
+
if (signMessage) {
|
|
2151
|
+
const { challengeId, message: challengeMessage } = await api.walletChallenge(walletAddress, chain);
|
|
2152
|
+
const encoded = new TextEncoder().encode(challengeMessage);
|
|
2153
|
+
const signatureBytes = await signMessage(encoded);
|
|
2154
|
+
const signature = chain === "solana" ? uint8ArrayToBase58(signatureBytes) : Array.from(signatureBytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
2155
|
+
await api.linkAuthMethod(token, {
|
|
2156
|
+
provider: `${chain}_wallet`,
|
|
2157
|
+
challengeId,
|
|
2158
|
+
signature,
|
|
2159
|
+
walletAddress
|
|
2160
|
+
});
|
|
2161
|
+
} else {
|
|
2162
|
+
if (!signTransaction) {
|
|
2163
|
+
throw new Error("Wallet does not support message signing or transaction signing.");
|
|
2164
|
+
}
|
|
2165
|
+
const { challengeId, transaction: txBase64 } = await api.walletChallengeTx(walletAddress, chain);
|
|
2166
|
+
const signedTxBase64 = await signTransaction(txBase64);
|
|
2167
|
+
await api.linkAuthMethod(token, {
|
|
2168
|
+
provider: `${chain}_wallet_tx`,
|
|
2169
|
+
challengeId,
|
|
2170
|
+
signedTransaction: signedTxBase64,
|
|
2171
|
+
walletAddress
|
|
2172
|
+
});
|
|
2173
|
+
}
|
|
2160
2174
|
await fetchWallets();
|
|
2161
2175
|
},
|
|
2162
2176
|
[api, getAccessToken, fetchWallets]
|
|
@@ -3548,10 +3562,23 @@ function WalletLinkStep({ onBack, onSuccess, onFatalError }) {
|
|
|
3548
3562
|
const [loading, setLoading] = _react.useState.call(void 0, false);
|
|
3549
3563
|
const [error, setError] = _react.useState.call(void 0, "");
|
|
3550
3564
|
const [showOther, setShowOther] = _react.useState.call(void 0, false);
|
|
3565
|
+
const [coldWallet, setColdWallet] = _react.useState.call(void 0, false);
|
|
3551
3566
|
const mobile = _react.useMemo.call(void 0, () => isMobile(), []);
|
|
3552
3567
|
const walletConfig = config.walletConfig;
|
|
3553
3568
|
const preferred = _nullishCoalesce(_optionalChain([walletConfig, 'optionalAccess', _111 => _111.preferredWallets]), () => ( []));
|
|
3554
3569
|
const onlyPreferred = _nullishCoalesce(_optionalChain([walletConfig, 'optionalAccess', _112 => _112.onlyPreferred]), () => ( false));
|
|
3570
|
+
const coldWalletRef = _react.useRef.call(void 0, coldWallet);
|
|
3571
|
+
coldWalletRef.current = coldWallet;
|
|
3572
|
+
const buildSignTxFnForAdapter = _react.useCallback.call(void 0, (adapter) => {
|
|
3573
|
+
if (!adapter.signTransaction) return void 0;
|
|
3574
|
+
return async (txBase64) => {
|
|
3575
|
+
const { Transaction } = await importSolanaWeb3();
|
|
3576
|
+
const bytes = Uint8Array.from(atob(txBase64), (c) => c.charCodeAt(0));
|
|
3577
|
+
const tx = Transaction.from(bytes);
|
|
3578
|
+
const signedTx = await adapter.signTransaction(tx);
|
|
3579
|
+
return btoa(String.fromCharCode(...new Uint8Array(signedTx.serialize())));
|
|
3580
|
+
};
|
|
3581
|
+
}, []);
|
|
3555
3582
|
const handleConnect = async (w) => {
|
|
3556
3583
|
if (w.readyState !== "Installed") {
|
|
3557
3584
|
if (mobile) {
|
|
@@ -3571,9 +3598,14 @@ function WalletLinkStep({ onBack, onSuccess, onFatalError }) {
|
|
|
3571
3598
|
if (!w.adapter.connected) await w.adapter.connect();
|
|
3572
3599
|
const pk = w.adapter.publicKey;
|
|
3573
3600
|
if (!pk) throw new Error("Wallet did not provide a public key.");
|
|
3601
|
+
const useCold = coldWalletRef.current;
|
|
3574
3602
|
const adapterSignMessage = w.adapter.signMessage ? (msg) => w.adapter.signMessage(msg) : void 0;
|
|
3575
|
-
|
|
3576
|
-
|
|
3603
|
+
await linkWallet(
|
|
3604
|
+
pk.toBase58(),
|
|
3605
|
+
useCold ? void 0 : adapterSignMessage,
|
|
3606
|
+
"solana",
|
|
3607
|
+
useCold ? buildSignTxFnForAdapter(w.adapter) : void 0
|
|
3608
|
+
);
|
|
3577
3609
|
onSuccess();
|
|
3578
3610
|
} catch (err) {
|
|
3579
3611
|
onFatalError(err instanceof Error ? err.message : "Could not link this wallet. Please try again.");
|
|
@@ -3630,7 +3662,7 @@ function WalletLinkStep({ onBack, onSuccess, onFatalError }) {
|
|
|
3630
3662
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "fc-tab", children: [
|
|
3631
3663
|
loading ? /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { style: { textAlign: "center", padding: "24px 0" }, children: [
|
|
3632
3664
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "fc-tab-title", children: "Connecting..." }),
|
|
3633
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "fc-text", children: "Approve the connection, then sign the verification request in your wallet" }),
|
|
3665
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "fc-text", children: coldWallet ? "Confirm the transaction on your device" : "Approve the connection, then sign the verification request in your wallet" }),
|
|
3634
3666
|
error && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
3635
3667
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "fc-error", children: error }),
|
|
3636
3668
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
@@ -3688,6 +3720,21 @@ function WalletLinkStep({ onBack, onSuccess, onFatalError }) {
|
|
|
3688
3720
|
] }, w.adapter.name))
|
|
3689
3721
|
] }),
|
|
3690
3722
|
preferredWallets.length === 0 && otherWallets.length === 0 && mobileExtraWallets.length === 0 && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "fc-text", children: "No wallet found. Please install a Solana wallet (like Phantom) to continue." }),
|
|
3723
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "label", { className: "fc-cold-wallet-toggle", children: [
|
|
3724
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
3725
|
+
"input",
|
|
3726
|
+
{
|
|
3727
|
+
type: "checkbox",
|
|
3728
|
+
checked: coldWallet,
|
|
3729
|
+
onChange: (e) => setColdWallet(e.target.checked)
|
|
3730
|
+
}
|
|
3731
|
+
),
|
|
3732
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "fc-toggle-track" }),
|
|
3733
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: "fc-cold-wallet-label", children: [
|
|
3734
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: "Hardware wallet" }),
|
|
3735
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: "Ledger, Trezor, Keystone..." })
|
|
3736
|
+
] })
|
|
3737
|
+
] }),
|
|
3691
3738
|
error && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "fc-error", children: error })
|
|
3692
3739
|
] }),
|
|
3693
3740
|
!loading && onBack && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "fc-switch", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "button", { type: "button", className: "fc-link", onClick: onBack, children: "Back" }) })
|