@fluent.xyz/connect 0.3.1 → 0.3.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.d.ts +107 -2
- package/dist/index.js +257 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as viem from 'viem';
|
|
2
2
|
import { Chain, PublicClient, Transport, Address, createPublicClient, Hex, Abi, Hash, SignableMessage, TypedData, TypedDataDefinition, WalletClient } from 'viem';
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import { ReactNode, AnchorHTMLAttributes, SVGProps } from 'react';
|
|
4
|
+
import { ReactNode, RefObject, AnchorHTMLAttributes, SVGProps } from 'react';
|
|
5
5
|
import * as _privy_io_react_auth from '@privy-io/react-auth';
|
|
6
6
|
import { CallType } from '@zerodev/permissions/policies';
|
|
7
7
|
export { CallType, ParamCondition } from '@zerodev/permissions/policies';
|
|
@@ -1747,6 +1747,8 @@ type FluentWidgetRenderContext = {
|
|
|
1747
1747
|
* smart-contract wallets sign in; a not-yet-deployed smart account cannot (no ERC-6492).
|
|
1748
1748
|
*/
|
|
1749
1749
|
getAuthToken: () => Promise<string>;
|
|
1750
|
+
/** The resolved auth mode: `"hosted"` unless the config says `"direct"`. */
|
|
1751
|
+
authMode: FluentWidgetAuthMode;
|
|
1750
1752
|
};
|
|
1751
1753
|
type FluentWidgetConnectButtonRenderContext = {
|
|
1752
1754
|
connected: boolean;
|
|
@@ -1840,6 +1842,109 @@ declare class FluentAuthError extends Error {
|
|
|
1840
1842
|
constructor(code: FluentAuthErrorCode, message: string, status?: number | undefined);
|
|
1841
1843
|
}
|
|
1842
1844
|
|
|
1845
|
+
/** One JSON-RPC request as the embedded page sends it: method plus positional params. */
|
|
1846
|
+
type FluentIframeRpcRequest = {
|
|
1847
|
+
method: string;
|
|
1848
|
+
params?: unknown[];
|
|
1849
|
+
};
|
|
1850
|
+
/**
|
|
1851
|
+
* The widget surface answering an embedded page's wallet calls needs. Every field is
|
|
1852
|
+
* injected so the handler is pure: it never reads the DOM or React state on its own.
|
|
1853
|
+
*/
|
|
1854
|
+
type FluentIframeRpcExecutor = {
|
|
1855
|
+
authMode: FluentWidgetAuthMode;
|
|
1856
|
+
/** Read at call time: the account changes while the bridge lives. */
|
|
1857
|
+
account: () => FluentWidgetAccount;
|
|
1858
|
+
chainId: number;
|
|
1859
|
+
sign: FluentSignApi;
|
|
1860
|
+
sendCalls: (calls: FluentEncodedBatchCall[]) => Promise<FluentExecuteResult>;
|
|
1861
|
+
/** Read-only chain access for the methods the wallet does not answer itself. */
|
|
1862
|
+
rpc: (method: string, params?: unknown[]) => Promise<unknown>;
|
|
1863
|
+
};
|
|
1864
|
+
type FluentIframeRpcHandler = (request: FluentIframeRpcRequest) => Promise<unknown>;
|
|
1865
|
+
/**
|
|
1866
|
+
* An error the embedded page understands: EIP-1193 provider codes (4001 user rejected,
|
|
1867
|
+
* 4100 unauthorized, 4200 unsupported method) and EIP-1474 JSON-RPC codes (-32602
|
|
1868
|
+
* invalid params, -32603 internal error).
|
|
1869
|
+
*/
|
|
1870
|
+
declare class FluentIframeRpcError extends Error {
|
|
1871
|
+
readonly code: number;
|
|
1872
|
+
constructor(code: number, message: string);
|
|
1873
|
+
}
|
|
1874
|
+
declare function createFluentIframeRpcHandler(executor: FluentIframeRpcExecutor): FluentIframeRpcHandler;
|
|
1875
|
+
/** The part of a `message` event the bridge reads; named so tests can build one without a DOM. */
|
|
1876
|
+
type FluentIframeMessageEvent = {
|
|
1877
|
+
origin: string;
|
|
1878
|
+
source: unknown;
|
|
1879
|
+
data: unknown;
|
|
1880
|
+
};
|
|
1881
|
+
type MessageListener = (event: FluentIframeMessageEvent) => void;
|
|
1882
|
+
/** Where the bridge listens for the iframe's messages; `window` outside tests. */
|
|
1883
|
+
type FluentIframeListenTarget = {
|
|
1884
|
+
addEventListener: (type: "message", listener: MessageListener) => void;
|
|
1885
|
+
removeEventListener: (type: "message", listener: MessageListener) => void;
|
|
1886
|
+
};
|
|
1887
|
+
/**
|
|
1888
|
+
* The iframe element, reduced to the window the bridge replies to. Read on every
|
|
1889
|
+
* message, so an element swapped in later is picked up without rebuilding the bridge.
|
|
1890
|
+
*/
|
|
1891
|
+
type FluentIframeElement = {
|
|
1892
|
+
contentWindow: {
|
|
1893
|
+
postMessage: (message: unknown, targetOrigin: string) => void;
|
|
1894
|
+
} | null;
|
|
1895
|
+
};
|
|
1896
|
+
type FluentIframeBridgeOptions = {
|
|
1897
|
+
/**
|
|
1898
|
+
* The exact origin the marketplace is served from. Messages from any other origin are
|
|
1899
|
+
* dropped without a reply: `@ledgerhq/iframe-provider` posts with `targetOrigin "*"`
|
|
1900
|
+
* and checks nothing itself, so this is the only origin check in the exchange.
|
|
1901
|
+
*/
|
|
1902
|
+
allowedOrigin: string;
|
|
1903
|
+
executor: FluentIframeRpcExecutor;
|
|
1904
|
+
listenOn?: FluentIframeListenTarget;
|
|
1905
|
+
};
|
|
1906
|
+
type FluentIframeBridge = {
|
|
1907
|
+
/** Tell the iframe who is signed in now: `[]` on sign-out. */
|
|
1908
|
+
notifyAccountsChanged: (accounts: readonly Address[]) => void;
|
|
1909
|
+
notifyChainChanged: (chainId: number) => void;
|
|
1910
|
+
/**
|
|
1911
|
+
* Stop listening and stop notifying. A request accepted before this is still answered,
|
|
1912
|
+
* so a review confirmed after the host unmounts does not leave the iframe waiting.
|
|
1913
|
+
*/
|
|
1914
|
+
dispose: () => void;
|
|
1915
|
+
};
|
|
1916
|
+
/**
|
|
1917
|
+
* Answers an embedded page's EIP-1193 calls with the widget, over the JSON-RPC 2.0
|
|
1918
|
+
* `postMessage` protocol `@ledgerhq/iframe-provider` speaks, which marketplace
|
|
1919
|
+
* white-label frontends embed: a request is `{jsonrpc, id, method, params}` posted to `window.parent`, the reply
|
|
1920
|
+
* carries the same `id` with `result` or `error`, and events are `{jsonrpc, method, params}`
|
|
1921
|
+
* without an `id`.
|
|
1922
|
+
*/
|
|
1923
|
+
declare function createFluentIframeBridge(iframe: FluentIframeElement, options: FluentIframeBridgeOptions): FluentIframeBridge;
|
|
1924
|
+
|
|
1925
|
+
/**
|
|
1926
|
+
* The user dismissed a review (transaction or signature) instead of confirming it.
|
|
1927
|
+
* A class, not a message, so callers that translate errors for another party — the
|
|
1928
|
+
* iframe bridge maps it to EIP-1193 `4001` — can recognise it without parsing prose.
|
|
1929
|
+
*/
|
|
1930
|
+
declare class FluentReviewRejectedError extends Error {
|
|
1931
|
+
readonly review: "transaction" | "signature";
|
|
1932
|
+
constructor(review: "transaction" | "signature");
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1935
|
+
type UseFluentIframeBridgeOptions = {
|
|
1936
|
+
/** The exact origin the embedded page is served from; see `createFluentIframeBridge`. */
|
|
1937
|
+
allowedOrigin: string;
|
|
1938
|
+
};
|
|
1939
|
+
/**
|
|
1940
|
+
* Lets a page embedded in `iframeRef` use the account signed in here, over the
|
|
1941
|
+
* JSON-RPC `postMessage` protocol `@ledgerhq/iframe-provider` speaks. The bridge lives
|
|
1942
|
+
* while the component is mounted; the bridge states the chain and account before its
|
|
1943
|
+
* first reply, and sign-in and sign-out reach the iframe as `accountsChanged`. Direct mode only: in hosted mode
|
|
1944
|
+
* the signing and sending calls reject the way `signMessage` does.
|
|
1945
|
+
*/
|
|
1946
|
+
declare function useFluentIframeBridge(iframeRef: RefObject<FluentIframeElement | null>, { allowedOrigin }: UseFluentIframeBridgeOptions): void;
|
|
1947
|
+
|
|
1843
1948
|
type FluentWidgetConnectButtonProps = {
|
|
1844
1949
|
connected: boolean;
|
|
1845
1950
|
/** Preparing the account after sign-in — disables the button and shows a spinner. */
|
|
@@ -2129,4 +2234,4 @@ type AccountAvatarProps = {
|
|
|
2129
2234
|
*/
|
|
2130
2235
|
declare function AccountAvatar({ userLogoUrl, defaultLogoUrl, className }: AccountAvatarProps): React.JSX.Element;
|
|
2131
2236
|
|
|
2132
|
-
export { AccountAvatar, type AccountAvatarProps, type AppDefinition, type BridgeAddresses, Button, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, FLUENT_CONNECT_DEFAULT_ASSETS, FLUENT_GAS_PAYMENT_DEFAULT_ETH_RATES, FLUENT_USER_TOKEN_LIMIT, FLUENT_WIDGET_SESSION_STORAGE_KEY, FLUENT_WIDGET_USER_TOKENS_STORAGE_KEY, FLUENT_ZERODEV_ERC20_PAYMASTER_QUERY, FLUENT_ZERODEV_PAYMASTER_DEMO_RECIPIENT, type FluentAccountCapabilities, FluentAccountDrawer, type FluentAccountType, FluentAuthError, type FluentAuthErrorCode, type FluentBatchApi, type FluentBatchCallInput, type FluentBatchConfirmationMode, type FluentBatchOperation, type FluentBatchOperationExecuteOptions, type FluentBatchOperationExecutor, type FluentBatchOperationInput, type FluentBatchOperationReview, type FluentCallPermission, type FluentChainDefinition, type FluentClient, type FluentClientConfig, type FluentEncodedBatchCall, type FluentExecuteResult, type FluentExternalWalletState, type FluentFamilies, type FluentFamiliesClient, type FluentFamiliesClientConfig, type FluentFamily, type FluentFamilyTier, type FluentFamilyType, type FluentGasPayment, type FluentGasPaymentEthRates, type FluentGasPaymentSelection, type FluentGasPaymentValueTier, type FluentGasTokenSymbol, type FluentPermissionApi, type FluentPermissionArgConstraint, type FluentPermissionArgs, type FluentPermissionBatchPolicy, type FluentPermissionBatchPolicyInput, type FluentPermissionCallInput, type FluentPermissionCallPolicy, type FluentPermissionClient, type FluentPermissionClientConfig, type FluentPermissionGrant, type FluentPermissionGrantRequest, type FluentPermissionPolicy, type FluentPermissionPolicyBuilders, type FluentPermissionPreview, type FluentPermissionSession, type FluentPermissionSessionExecutor, type FluentPermissionSessionInput, type FluentPermissionStatus, FluentPortalContainerProvider, type FluentSession, type FluentSignApi, type FluentSignatureReview, type FluentSpendPeriod, type FluentSpendPermission, type FluentSponsorshipReason, type FluentTokenBalance, type FluentTokenDefinition, type FluentTypedDataRequest, type FluentUserTokenAddResult, FluentWidget, type FluentWidgetAccount, type FluentWidgetAuthMode, type FluentWidgetConfig, FluentWidgetConnectButton, type FluentWidgetConnectButtonProps, type FluentWidgetConnectButtonRenderContext, type FluentWidgetExecutionStatus, type FluentWidgetGasPayment, type FluentWidgetNetwork, FluentWidgetNetworkProvider, type FluentWidgetProps, type FluentWidgetRenderContext, type FluentWidgetSession, type FluentWidgetStatus, type FluentZeroDevErc20PaymasterToken, type FluentZeroDevErc20PaymasterTokenInfo, type FluentZeroDevKernel, type FluentZeroDevPaymasterDemoResult, type FluentZeroDevPaymasterKernel, type FluentZeroDevPermissionCall, type FluentZeroDevPermissionSession, type FluentZeroDevSignerMode, Icon, type IconName, type L1ChainDefinition, Label, type ResolvedFluentWidgetConfig, Separator, Switch, type UserTokenStore, WIDGET_STYLE_SCOPE, WalletMenuActionCard, type ZerodevIntegration, buttonVariants, clearPrivyRecentLoginMethod, createFluentBatchOp, createFluentClient, createFluentFamiliesClient, createFluentPermissionApi, createFluentPermissionClient, createFluentPermissionPolicyBuilders, createFluentPermissionSession, createFluentSponsorshipRpcUrl, createFluentUserTokenStore, createFluentZeroDevErc20Paymaster, createFluentZeroDevErc20PaymasterApprovalCall, createFluentZeroDevErc20PaymasterClient, createFluentZeroDevErc20PaymasterRpcUrl, createFluentZeroDevPermissionSession, createFluentZeroDevRpcUrl, createFluentZeroDevSponsoredPaymaster, findFluentSymbolCollisions, fluent, apps as fluentApps, fluentBridgeAbi, fluent$1 as fluentChain, fluentChains, fluentDefinitionToViemChain, integrations as fluentIntegrations, l1Chains as fluentL1Chains, fluentMainnet, fluentMainnetTokenDefaults, fluentTestnet, fluentTestnetTokenDefaults, fluentTokenIdentity, fluentZeroDevChainIds, getApp, getContractAddressFromChain, getFluentChain, getFluentChainByChainId, getFluentChainForNetwork, getFluentDefaultWidgetDisplayTokens, getFluentDefaultWidgetGasTokens, getFluentExplorerBaseUrl, getFluentGasPaymentEthValue, getFluentGasPaymentTokens, getFluentGasPaymentValueTier, getFluentGasTokenAddress, getFluentTokenDefaults, getFluentTokenDefaultsForNetwork, getFluentZeroDevErc20PaymasterTokens, getL1Chain, getL1ForFluentChain, getZeroDevRpcUrl, getZerodevIntegration, isFaucetNetwork, isFluentDefaultToken, isFluentNativeToken, isFluentZeroDevChain, l1DefinitionToViemChain, mergeFluentDisplayTokens, normalizeFluentWidgetNetwork, readFluentTokenBalances, readFluentTokenMetadata, registryVersion, resolveBridgeAddresses, resolveFluentWidgetNetworkFromEnv, resolveFluentZeroDevErc20PaymasterToken, resolveL1Definition, selectFluentGasPaymentToken, sendFluentZeroDevErc20PaymasterDemo, sortFluentGasTokens, useFluentUserTokens, useFluentWidget, useFluentWidgetNetwork, useFluentZeroDevAccount, useWidget, withFluentSignaturePrompt };
|
|
2237
|
+
export { AccountAvatar, type AccountAvatarProps, type AppDefinition, type BridgeAddresses, Button, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, FLUENT_CONNECT_DEFAULT_ASSETS, FLUENT_GAS_PAYMENT_DEFAULT_ETH_RATES, FLUENT_USER_TOKEN_LIMIT, FLUENT_WIDGET_SESSION_STORAGE_KEY, FLUENT_WIDGET_USER_TOKENS_STORAGE_KEY, FLUENT_ZERODEV_ERC20_PAYMASTER_QUERY, FLUENT_ZERODEV_PAYMASTER_DEMO_RECIPIENT, type FluentAccountCapabilities, FluentAccountDrawer, type FluentAccountType, FluentAuthError, type FluentAuthErrorCode, type FluentBatchApi, type FluentBatchCallInput, type FluentBatchConfirmationMode, type FluentBatchOperation, type FluentBatchOperationExecuteOptions, type FluentBatchOperationExecutor, type FluentBatchOperationInput, type FluentBatchOperationReview, type FluentCallPermission, type FluentChainDefinition, type FluentClient, type FluentClientConfig, type FluentEncodedBatchCall, type FluentExecuteResult, type FluentExternalWalletState, type FluentFamilies, type FluentFamiliesClient, type FluentFamiliesClientConfig, type FluentFamily, type FluentFamilyTier, type FluentFamilyType, type FluentGasPayment, type FluentGasPaymentEthRates, type FluentGasPaymentSelection, type FluentGasPaymentValueTier, type FluentGasTokenSymbol, type FluentIframeBridge, type FluentIframeBridgeOptions, type FluentIframeElement, FluentIframeRpcError, type FluentIframeRpcExecutor, type FluentIframeRpcHandler, type FluentIframeRpcRequest, type FluentPermissionApi, type FluentPermissionArgConstraint, type FluentPermissionArgs, type FluentPermissionBatchPolicy, type FluentPermissionBatchPolicyInput, type FluentPermissionCallInput, type FluentPermissionCallPolicy, type FluentPermissionClient, type FluentPermissionClientConfig, type FluentPermissionGrant, type FluentPermissionGrantRequest, type FluentPermissionPolicy, type FluentPermissionPolicyBuilders, type FluentPermissionPreview, type FluentPermissionSession, type FluentPermissionSessionExecutor, type FluentPermissionSessionInput, type FluentPermissionStatus, FluentPortalContainerProvider, FluentReviewRejectedError, type FluentSession, type FluentSignApi, type FluentSignatureReview, type FluentSpendPeriod, type FluentSpendPermission, type FluentSponsorshipReason, type FluentTokenBalance, type FluentTokenDefinition, type FluentTypedDataRequest, type FluentUserTokenAddResult, FluentWidget, type FluentWidgetAccount, type FluentWidgetAuthMode, type FluentWidgetConfig, FluentWidgetConnectButton, type FluentWidgetConnectButtonProps, type FluentWidgetConnectButtonRenderContext, type FluentWidgetExecutionStatus, type FluentWidgetGasPayment, type FluentWidgetNetwork, FluentWidgetNetworkProvider, type FluentWidgetProps, type FluentWidgetRenderContext, type FluentWidgetSession, type FluentWidgetStatus, type FluentZeroDevErc20PaymasterToken, type FluentZeroDevErc20PaymasterTokenInfo, type FluentZeroDevKernel, type FluentZeroDevPaymasterDemoResult, type FluentZeroDevPaymasterKernel, type FluentZeroDevPermissionCall, type FluentZeroDevPermissionSession, type FluentZeroDevSignerMode, Icon, type IconName, type L1ChainDefinition, Label, type ResolvedFluentWidgetConfig, Separator, Switch, type UseFluentIframeBridgeOptions, type UserTokenStore, WIDGET_STYLE_SCOPE, WalletMenuActionCard, type ZerodevIntegration, buttonVariants, clearPrivyRecentLoginMethod, createFluentBatchOp, createFluentClient, createFluentFamiliesClient, createFluentIframeBridge, createFluentIframeRpcHandler, createFluentPermissionApi, createFluentPermissionClient, createFluentPermissionPolicyBuilders, createFluentPermissionSession, createFluentSponsorshipRpcUrl, createFluentUserTokenStore, createFluentZeroDevErc20Paymaster, createFluentZeroDevErc20PaymasterApprovalCall, createFluentZeroDevErc20PaymasterClient, createFluentZeroDevErc20PaymasterRpcUrl, createFluentZeroDevPermissionSession, createFluentZeroDevRpcUrl, createFluentZeroDevSponsoredPaymaster, findFluentSymbolCollisions, fluent, apps as fluentApps, fluentBridgeAbi, fluent$1 as fluentChain, fluentChains, fluentDefinitionToViemChain, integrations as fluentIntegrations, l1Chains as fluentL1Chains, fluentMainnet, fluentMainnetTokenDefaults, fluentTestnet, fluentTestnetTokenDefaults, fluentTokenIdentity, fluentZeroDevChainIds, getApp, getContractAddressFromChain, getFluentChain, getFluentChainByChainId, getFluentChainForNetwork, getFluentDefaultWidgetDisplayTokens, getFluentDefaultWidgetGasTokens, getFluentExplorerBaseUrl, getFluentGasPaymentEthValue, getFluentGasPaymentTokens, getFluentGasPaymentValueTier, getFluentGasTokenAddress, getFluentTokenDefaults, getFluentTokenDefaultsForNetwork, getFluentZeroDevErc20PaymasterTokens, getL1Chain, getL1ForFluentChain, getZeroDevRpcUrl, getZerodevIntegration, isFaucetNetwork, isFluentDefaultToken, isFluentNativeToken, isFluentZeroDevChain, l1DefinitionToViemChain, mergeFluentDisplayTokens, normalizeFluentWidgetNetwork, readFluentTokenBalances, readFluentTokenMetadata, registryVersion, resolveBridgeAddresses, resolveFluentWidgetNetworkFromEnv, resolveFluentZeroDevErc20PaymasterToken, resolveL1Definition, selectFluentGasPaymentToken, sendFluentZeroDevErc20PaymasterDemo, sortFluentGasTokens, useFluentIframeBridge, useFluentUserTokens, useFluentWidget, useFluentWidgetNetwork, useFluentZeroDevAccount, useWidget, withFluentSignaturePrompt };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { toEventSelector, parseAbiItem, defineChain, http, createPublicClient, formatUnits, isAddress, getAddress, encodeFunctionData, parseUnits, zeroAddress, numberToHex, BaseError, HttpRequestError, fallback,
|
|
1
|
+
import { toEventSelector, parseAbiItem, defineChain, http, createPublicClient, formatUnits, isAddress, getAddress, encodeFunctionData, parseUnits, zeroAddress, numberToHex, hexToBigInt, isHex, toHex, BaseError, HttpRequestError, fallback, stringToHex, bytesToHex } from 'viem';
|
|
2
2
|
import * as React2 from 'react';
|
|
3
3
|
import { createContext, forwardRef, useContext, useMemo, useState, useCallback, useLayoutEffect, useRef, useEffect } from 'react';
|
|
4
4
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
@@ -7479,8 +7479,257 @@ function toUnixSeconds(value) {
|
|
|
7479
7479
|
return value > 1e12 ? Math.floor(value / 1e3) : Math.floor(value);
|
|
7480
7480
|
}
|
|
7481
7481
|
|
|
7482
|
+
// src/widget/reviewRejected.ts
|
|
7483
|
+
var FluentReviewRejectedError = class extends Error {
|
|
7484
|
+
constructor(review) {
|
|
7485
|
+
super(`User rejected Fluent ${review} review`);
|
|
7486
|
+
this.review = review;
|
|
7487
|
+
this.name = "FluentReviewRejectedError";
|
|
7488
|
+
}
|
|
7489
|
+
review;
|
|
7490
|
+
};
|
|
7491
|
+
|
|
7492
|
+
// src/widget/iframeBridge.ts
|
|
7493
|
+
var READ_ONLY_METHODS = /* @__PURE__ */ new Set([
|
|
7494
|
+
"eth_blockNumber",
|
|
7495
|
+
"eth_call",
|
|
7496
|
+
"eth_estimateGas",
|
|
7497
|
+
"eth_feeHistory",
|
|
7498
|
+
"eth_gasPrice",
|
|
7499
|
+
"eth_getBalance",
|
|
7500
|
+
"eth_getBlockByHash",
|
|
7501
|
+
"eth_getBlockByNumber",
|
|
7502
|
+
"eth_getCode",
|
|
7503
|
+
"eth_getLogs",
|
|
7504
|
+
"eth_getStorageAt",
|
|
7505
|
+
"eth_getTransactionByHash",
|
|
7506
|
+
"eth_getTransactionCount",
|
|
7507
|
+
"eth_getTransactionReceipt",
|
|
7508
|
+
"eth_maxPriorityFeePerGas",
|
|
7509
|
+
"net_version"
|
|
7510
|
+
]);
|
|
7511
|
+
var FluentIframeRpcError = class extends Error {
|
|
7512
|
+
constructor(code, message) {
|
|
7513
|
+
super(message);
|
|
7514
|
+
this.code = code;
|
|
7515
|
+
this.name = "FluentIframeRpcError";
|
|
7516
|
+
}
|
|
7517
|
+
code;
|
|
7518
|
+
};
|
|
7519
|
+
function createFluentIframeRpcHandler(executor) {
|
|
7520
|
+
const invalid = (method, what) => new FluentIframeRpcError(-32602, `${method}: expected ${what}`);
|
|
7521
|
+
const assertOwnAddress = (candidate, method) => {
|
|
7522
|
+
const address = executor.account().address;
|
|
7523
|
+
if (!address) {
|
|
7524
|
+
throw new FluentIframeRpcError(4100, `${method}: no account is signed in`);
|
|
7525
|
+
}
|
|
7526
|
+
if (typeof candidate !== "string" || !isAddress(candidate)) {
|
|
7527
|
+
throw invalid(method, "an address");
|
|
7528
|
+
}
|
|
7529
|
+
if (candidate.toLowerCase() !== address.toLowerCase()) {
|
|
7530
|
+
throw new FluentIframeRpcError(4100, `${method}: ${candidate} is not the signed-in account`);
|
|
7531
|
+
}
|
|
7532
|
+
};
|
|
7533
|
+
const assertDirectMode = () => {
|
|
7534
|
+
if (executor.authMode === "hosted") {
|
|
7535
|
+
throw new FluentAuthError(
|
|
7536
|
+
"hosted_not_supported",
|
|
7537
|
+
'The iframe bridge needs authMode: "direct" \u2014 there is no hosted signer to ask.'
|
|
7538
|
+
);
|
|
7539
|
+
}
|
|
7540
|
+
};
|
|
7541
|
+
const parseTypedData = (payload, method) => {
|
|
7542
|
+
const value = typeof payload === "string" ? safeJsonParse(payload) : payload;
|
|
7543
|
+
if (!value || typeof value !== "object") {
|
|
7544
|
+
throw invalid(method, "EIP-712 typed data");
|
|
7545
|
+
}
|
|
7546
|
+
return value;
|
|
7547
|
+
};
|
|
7548
|
+
const parseHex = (value, method, what) => {
|
|
7549
|
+
if (value === void 0 || value === null) return void 0;
|
|
7550
|
+
if (typeof value !== "string" || !isHex(value)) throw invalid(method, `${what} as hex`);
|
|
7551
|
+
return value;
|
|
7552
|
+
};
|
|
7553
|
+
return async (request) => {
|
|
7554
|
+
const { method } = request;
|
|
7555
|
+
const params = request.params ?? [];
|
|
7556
|
+
if (!Array.isArray(params)) throw invalid(method, "positional params");
|
|
7557
|
+
switch (method) {
|
|
7558
|
+
// `enable` is what `@ledgerhq/iframe-provider`'s own `enable()` sends.
|
|
7559
|
+
case "enable":
|
|
7560
|
+
case "eth_accounts":
|
|
7561
|
+
case "eth_requestAccounts": {
|
|
7562
|
+
const address = executor.account().address;
|
|
7563
|
+
return address ? [address] : [];
|
|
7564
|
+
}
|
|
7565
|
+
case "eth_chainId":
|
|
7566
|
+
return toHex(executor.chainId);
|
|
7567
|
+
case "eth_signTypedData_v4":
|
|
7568
|
+
case "eth_signTypedData_v3": {
|
|
7569
|
+
assertDirectMode();
|
|
7570
|
+
assertOwnAddress(params[0], method);
|
|
7571
|
+
return executor.sign.signTypedData(parseTypedData(params[1], method));
|
|
7572
|
+
}
|
|
7573
|
+
case "eth_signTypedData": {
|
|
7574
|
+
assertDirectMode();
|
|
7575
|
+
const [first, second] = params;
|
|
7576
|
+
const addressFirst = typeof first === "string" && isAddress(first);
|
|
7577
|
+
assertOwnAddress(addressFirst ? first : second, method);
|
|
7578
|
+
return executor.sign.signTypedData(parseTypedData(addressFirst ? second : first, method));
|
|
7579
|
+
}
|
|
7580
|
+
case "personal_sign": {
|
|
7581
|
+
assertDirectMode();
|
|
7582
|
+
assertOwnAddress(params[1], method);
|
|
7583
|
+
const message = params[0];
|
|
7584
|
+
if (typeof message !== "string") throw invalid(method, "a message");
|
|
7585
|
+
return executor.sign.signMessage({ message: isHex(message) ? { raw: message } : message });
|
|
7586
|
+
}
|
|
7587
|
+
case "eth_sendTransaction": {
|
|
7588
|
+
assertDirectMode();
|
|
7589
|
+
const tx = params[0];
|
|
7590
|
+
if (!tx || typeof tx !== "object") throw invalid(method, "a transaction object");
|
|
7591
|
+
const { from, to, data, value } = tx;
|
|
7592
|
+
assertOwnAddress(from, method);
|
|
7593
|
+
if (typeof to !== "string" || !isAddress(to)) throw invalid(method, "a recipient");
|
|
7594
|
+
const valueHex = parseHex(value, method, "value");
|
|
7595
|
+
const result = await executor.sendCalls([
|
|
7596
|
+
{
|
|
7597
|
+
to,
|
|
7598
|
+
data: parseHex(data, method, "data") ?? "0x",
|
|
7599
|
+
value: valueHex === void 0 ? 0n : hexToBigInt(valueHex)
|
|
7600
|
+
}
|
|
7601
|
+
]);
|
|
7602
|
+
return result.hash;
|
|
7603
|
+
}
|
|
7604
|
+
default:
|
|
7605
|
+
if (READ_ONLY_METHODS.has(method)) {
|
|
7606
|
+
return executor.rpc(method, request.params);
|
|
7607
|
+
}
|
|
7608
|
+
throw new FluentIframeRpcError(4200, `Unsupported method: ${method}`);
|
|
7609
|
+
}
|
|
7610
|
+
};
|
|
7611
|
+
}
|
|
7612
|
+
function safeJsonParse(text) {
|
|
7613
|
+
try {
|
|
7614
|
+
return JSON.parse(text);
|
|
7615
|
+
} catch {
|
|
7616
|
+
return void 0;
|
|
7617
|
+
}
|
|
7618
|
+
}
|
|
7619
|
+
function isJsonRpcRequest(data) {
|
|
7620
|
+
if (!data || typeof data !== "object") return false;
|
|
7621
|
+
const { jsonrpc, method } = data;
|
|
7622
|
+
return jsonrpc === "2.0" && typeof method === "string";
|
|
7623
|
+
}
|
|
7624
|
+
function createFluentIframeBridge(iframe, options) {
|
|
7625
|
+
const { executor } = options;
|
|
7626
|
+
const allowedOrigin = exactOrigin(options.allowedOrigin);
|
|
7627
|
+
const listenOn = options.listenOn ?? globalThis.window;
|
|
7628
|
+
const handle = createFluentIframeRpcHandler(executor);
|
|
7629
|
+
let disposed = false;
|
|
7630
|
+
let announced = false;
|
|
7631
|
+
const post = (message) => {
|
|
7632
|
+
iframe.contentWindow?.postMessage(message, allowedOrigin);
|
|
7633
|
+
};
|
|
7634
|
+
const notify = (message) => {
|
|
7635
|
+
if (disposed) return;
|
|
7636
|
+
post(message);
|
|
7637
|
+
};
|
|
7638
|
+
const listener = (event) => {
|
|
7639
|
+
if (event.origin !== allowedOrigin) return;
|
|
7640
|
+
if (!iframe.contentWindow || event.source !== iframe.contentWindow) return;
|
|
7641
|
+
if (!isJsonRpcRequest(event.data)) return;
|
|
7642
|
+
const { id, method, params } = event.data;
|
|
7643
|
+
if (id === void 0 || id === null) return;
|
|
7644
|
+
if (!announced) {
|
|
7645
|
+
announced = true;
|
|
7646
|
+
post({ jsonrpc: "2.0", method: "chainChanged", params: [toHex(executor.chainId)] });
|
|
7647
|
+
const address = executor.account().address;
|
|
7648
|
+
post({ jsonrpc: "2.0", method: "accountsChanged", params: [address ? [address] : []] });
|
|
7649
|
+
}
|
|
7650
|
+
void handle({ method, params }).then(
|
|
7651
|
+
(result) => post({ jsonrpc: "2.0", id, result }),
|
|
7652
|
+
(error) => post({ jsonrpc: "2.0", id, error: toRpcError(error) })
|
|
7653
|
+
);
|
|
7654
|
+
};
|
|
7655
|
+
listenOn.addEventListener("message", listener);
|
|
7656
|
+
return {
|
|
7657
|
+
notifyAccountsChanged: (accounts) => notify({ jsonrpc: "2.0", method: "accountsChanged", params: [accounts] }),
|
|
7658
|
+
notifyChainChanged: (chainId) => notify({ jsonrpc: "2.0", method: "chainChanged", params: [toHex(chainId)] }),
|
|
7659
|
+
dispose: () => {
|
|
7660
|
+
disposed = true;
|
|
7661
|
+
listenOn.removeEventListener("message", listener);
|
|
7662
|
+
}
|
|
7663
|
+
};
|
|
7664
|
+
}
|
|
7665
|
+
function toRpcError(error) {
|
|
7666
|
+
if (error instanceof FluentIframeRpcError) return { code: error.code, message: error.message };
|
|
7667
|
+
if (error instanceof FluentReviewRejectedError) return { code: 4001, message: error.message };
|
|
7668
|
+
if (error instanceof FluentAuthError) {
|
|
7669
|
+
const code = error.code === "hosted_not_supported" ? 4200 : -32603;
|
|
7670
|
+
return { code, message: `${error.code}: ${error.message}` };
|
|
7671
|
+
}
|
|
7672
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
7673
|
+
return { code: -32603, message };
|
|
7674
|
+
}
|
|
7675
|
+
function exactOrigin(candidate) {
|
|
7676
|
+
let origin;
|
|
7677
|
+
try {
|
|
7678
|
+
const url = new URL(candidate);
|
|
7679
|
+
if (url.protocol === "http:" || url.protocol === "https:") origin = url.origin;
|
|
7680
|
+
} catch {
|
|
7681
|
+
origin = void 0;
|
|
7682
|
+
}
|
|
7683
|
+
if (!origin || origin === "null") {
|
|
7684
|
+
throw new Error(`allowedOrigin must be an origin such as https://market.example, got "${candidate}"`);
|
|
7685
|
+
}
|
|
7686
|
+
return origin;
|
|
7687
|
+
}
|
|
7688
|
+
function useFluentIframeBridge(iframeRef, { allowedOrigin }) {
|
|
7689
|
+
const { widget, authMode } = useFluentWidget();
|
|
7690
|
+
const { chain } = useFluentWidgetNetwork();
|
|
7691
|
+
const widgetRef = useRef(widget);
|
|
7692
|
+
widgetRef.current = widget;
|
|
7693
|
+
const rpc = useMemo(
|
|
7694
|
+
() => createPublicClient({ chain, transport: createFluentRpcTransport(chain) }),
|
|
7695
|
+
[chain]
|
|
7696
|
+
);
|
|
7697
|
+
const bridgeRef = useRef(null);
|
|
7698
|
+
useEffect(() => {
|
|
7699
|
+
const iframe = {
|
|
7700
|
+
get contentWindow() {
|
|
7701
|
+
return iframeRef.current?.contentWindow ?? null;
|
|
7702
|
+
}
|
|
7703
|
+
};
|
|
7704
|
+
const bridge = createFluentIframeBridge(iframe, {
|
|
7705
|
+
allowedOrigin,
|
|
7706
|
+
executor: {
|
|
7707
|
+
authMode,
|
|
7708
|
+
account: () => widgetRef.current.account,
|
|
7709
|
+
chainId: chain.id,
|
|
7710
|
+
sign: {
|
|
7711
|
+
signMessage: (params) => widgetRef.current.signMessage(params),
|
|
7712
|
+
signTypedData: (typedData) => widgetRef.current.signTypedData(typedData)
|
|
7713
|
+
},
|
|
7714
|
+
sendCalls: (calls) => widgetRef.current.createBatchOp({ calls }).execute(),
|
|
7715
|
+
rpc: (method, params) => rpc.request({ method, params })
|
|
7716
|
+
}
|
|
7717
|
+
});
|
|
7718
|
+
bridge.notifyChainChanged(chain.id);
|
|
7719
|
+
bridgeRef.current = bridge;
|
|
7720
|
+
return () => {
|
|
7721
|
+
bridge.dispose();
|
|
7722
|
+
bridgeRef.current = null;
|
|
7723
|
+
};
|
|
7724
|
+
}, [iframeRef, allowedOrigin, authMode, chain.id, rpc]);
|
|
7725
|
+
const address = widget.account.address;
|
|
7726
|
+
useEffect(() => {
|
|
7727
|
+
bridgeRef.current?.notifyAccountsChanged(address ? [address] : []);
|
|
7728
|
+
}, [address]);
|
|
7729
|
+
}
|
|
7730
|
+
|
|
7482
7731
|
// package.json
|
|
7483
|
-
var version = "0.3.
|
|
7732
|
+
var version = "0.3.2";
|
|
7484
7733
|
|
|
7485
7734
|
// src/core/analytics.ts
|
|
7486
7735
|
var INSTANCE_NAME = "fluent";
|
|
@@ -9891,7 +10140,7 @@ function useReviewPrompt(options) {
|
|
|
9891
10140
|
setReview(null);
|
|
9892
10141
|
}, []);
|
|
9893
10142
|
const reject = useCallback(() => {
|
|
9894
|
-
resolution.current?.reject(new
|
|
10143
|
+
resolution.current?.reject(new FluentReviewRejectedError(label));
|
|
9895
10144
|
resolution.current = null;
|
|
9896
10145
|
setReview(null);
|
|
9897
10146
|
}, []);
|
|
@@ -11340,7 +11589,8 @@ function FluentWidgetContent({
|
|
|
11340
11589
|
status,
|
|
11341
11590
|
connecting,
|
|
11342
11591
|
refreshBalances,
|
|
11343
|
-
getAuthToken
|
|
11592
|
+
getAuthToken,
|
|
11593
|
+
authMode: resolvedConfig.authMode
|
|
11344
11594
|
}),
|
|
11345
11595
|
[
|
|
11346
11596
|
session,
|
|
@@ -11354,7 +11604,8 @@ function FluentWidgetContent({
|
|
|
11354
11604
|
status,
|
|
11355
11605
|
connecting,
|
|
11356
11606
|
refreshBalances,
|
|
11357
|
-
getAuthToken
|
|
11607
|
+
getAuthToken,
|
|
11608
|
+
resolvedConfig.authMode
|
|
11358
11609
|
]
|
|
11359
11610
|
);
|
|
11360
11611
|
const accountAvatarUrl = resolvedConfig.avatar.forceDefault ? void 0 : getHighResTwitterAvatar(user?.twitter?.profilePictureUrl);
|
|
@@ -11659,6 +11910,6 @@ function FluentWidget(props) {
|
|
|
11659
11910
|
) });
|
|
11660
11911
|
}
|
|
11661
11912
|
|
|
11662
|
-
export { AccountAvatar, Button, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, FLUENT_CONNECT_DEFAULT_ASSETS, FLUENT_GAS_PAYMENT_DEFAULT_ETH_RATES, FLUENT_USER_TOKEN_LIMIT, FLUENT_WIDGET_SESSION_STORAGE_KEY, FLUENT_WIDGET_USER_TOKENS_STORAGE_KEY, FLUENT_ZERODEV_ERC20_PAYMASTER_QUERY, FLUENT_ZERODEV_PAYMASTER_DEMO_RECIPIENT, FluentAccountDrawer, FluentAuthError, FluentPortalContainerProvider, FluentWidget, FluentWidgetConnectButton, FluentWidgetNetworkProvider, Icon, Label, Separator, Switch, WIDGET_STYLE_SCOPE, WalletMenuActionCard, buttonVariants, clearPrivyRecentLoginMethod, createFluentBatchOp, createFluentClient, createFluentFamiliesClient, createFluentPermissionApi, createFluentPermissionClient, createFluentPermissionPolicyBuilders, createFluentPermissionSession, createFluentSponsorshipRpcUrl, createFluentUserTokenStore, createFluentZeroDevErc20Paymaster, createFluentZeroDevErc20PaymasterApprovalCall, createFluentZeroDevErc20PaymasterClient, createFluentZeroDevErc20PaymasterRpcUrl, createFluentZeroDevPermissionSession, createFluentZeroDevRpcUrl, createFluentZeroDevSponsoredPaymaster, findFluentSymbolCollisions, fluent2 as fluent, apps as fluentApps, fluentBridgeAbi, fluent as fluentChain, fluentChains, fluentDefinitionToViemChain, integrations as fluentIntegrations, l1Chains as fluentL1Chains, fluentMainnet, fluentMainnetTokenDefaults, fluentTestnet, fluentTestnetTokenDefaults, fluentTokenIdentity, fluentZeroDevChainIds, getApp, getContractAddressFromChain, getFluentChain, getFluentChainByChainId, getFluentChainForNetwork, getFluentDefaultWidgetDisplayTokens, getFluentDefaultWidgetGasTokens, getFluentExplorerBaseUrl, getFluentGasPaymentEthValue, getFluentGasPaymentTokens, getFluentGasPaymentValueTier, getFluentGasTokenAddress, getFluentTokenDefaults, getFluentTokenDefaultsForNetwork, getFluentZeroDevErc20PaymasterTokens, getL1Chain, getL1ForFluentChain, getZeroDevRpcUrl, getZerodevIntegration, isFaucetNetwork, isFluentDefaultToken, isFluentNativeToken, isFluentZeroDevChain, l1DefinitionToViemChain, mergeFluentDisplayTokens, normalizeFluentWidgetNetwork, readFluentTokenBalances, readFluentTokenMetadata, registryVersion, resolveBridgeAddresses, resolveFluentWidgetNetworkFromEnv, resolveFluentZeroDevErc20PaymasterToken, resolveL1Definition, selectFluentGasPaymentToken, sendFluentZeroDevErc20PaymasterDemo, sortFluentGasTokens, useFluentUserTokens, useFluentWidget, useFluentWidgetNetwork, useFluentZeroDevAccount, useWidget, withFluentSignaturePrompt };
|
|
11913
|
+
export { AccountAvatar, Button, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, FLUENT_CONNECT_DEFAULT_ASSETS, FLUENT_GAS_PAYMENT_DEFAULT_ETH_RATES, FLUENT_USER_TOKEN_LIMIT, FLUENT_WIDGET_SESSION_STORAGE_KEY, FLUENT_WIDGET_USER_TOKENS_STORAGE_KEY, FLUENT_ZERODEV_ERC20_PAYMASTER_QUERY, FLUENT_ZERODEV_PAYMASTER_DEMO_RECIPIENT, FluentAccountDrawer, FluentAuthError, FluentIframeRpcError, FluentPortalContainerProvider, FluentReviewRejectedError, FluentWidget, FluentWidgetConnectButton, FluentWidgetNetworkProvider, Icon, Label, Separator, Switch, WIDGET_STYLE_SCOPE, WalletMenuActionCard, buttonVariants, clearPrivyRecentLoginMethod, createFluentBatchOp, createFluentClient, createFluentFamiliesClient, createFluentIframeBridge, createFluentIframeRpcHandler, createFluentPermissionApi, createFluentPermissionClient, createFluentPermissionPolicyBuilders, createFluentPermissionSession, createFluentSponsorshipRpcUrl, createFluentUserTokenStore, createFluentZeroDevErc20Paymaster, createFluentZeroDevErc20PaymasterApprovalCall, createFluentZeroDevErc20PaymasterClient, createFluentZeroDevErc20PaymasterRpcUrl, createFluentZeroDevPermissionSession, createFluentZeroDevRpcUrl, createFluentZeroDevSponsoredPaymaster, findFluentSymbolCollisions, fluent2 as fluent, apps as fluentApps, fluentBridgeAbi, fluent as fluentChain, fluentChains, fluentDefinitionToViemChain, integrations as fluentIntegrations, l1Chains as fluentL1Chains, fluentMainnet, fluentMainnetTokenDefaults, fluentTestnet, fluentTestnetTokenDefaults, fluentTokenIdentity, fluentZeroDevChainIds, getApp, getContractAddressFromChain, getFluentChain, getFluentChainByChainId, getFluentChainForNetwork, getFluentDefaultWidgetDisplayTokens, getFluentDefaultWidgetGasTokens, getFluentExplorerBaseUrl, getFluentGasPaymentEthValue, getFluentGasPaymentTokens, getFluentGasPaymentValueTier, getFluentGasTokenAddress, getFluentTokenDefaults, getFluentTokenDefaultsForNetwork, getFluentZeroDevErc20PaymasterTokens, getL1Chain, getL1ForFluentChain, getZeroDevRpcUrl, getZerodevIntegration, isFaucetNetwork, isFluentDefaultToken, isFluentNativeToken, isFluentZeroDevChain, l1DefinitionToViemChain, mergeFluentDisplayTokens, normalizeFluentWidgetNetwork, readFluentTokenBalances, readFluentTokenMetadata, registryVersion, resolveBridgeAddresses, resolveFluentWidgetNetworkFromEnv, resolveFluentZeroDevErc20PaymasterToken, resolveL1Definition, selectFluentGasPaymentToken, sendFluentZeroDevErc20PaymasterDemo, sortFluentGasTokens, useFluentIframeBridge, useFluentUserTokens, useFluentWidget, useFluentWidgetNetwork, useFluentZeroDevAccount, useWidget, withFluentSignaturePrompt };
|
|
11663
11914
|
//# sourceMappingURL=index.js.map
|
|
11664
11915
|
//# sourceMappingURL=index.js.map
|