rise-wallet 0.1.4-beta.1 → 0.2.28
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 +64 -34
- package/dist/cli/Dialog.d.ts +34 -0
- package/dist/cli/Dialog.js +60 -0
- package/dist/cli/Dialog.js.map +1 -0
- package/dist/cli/Messenger.d.ts +7 -0
- package/dist/cli/Messenger.js +123 -0
- package/dist/cli/Messenger.js.map +1 -0
- package/dist/cli/bin/commands-D7N5ucUu.js +50 -0
- package/dist/cli/bin/index.js +9 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +3 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/internal/http.d.ts +6 -0
- package/dist/cli/internal/http.js +17 -0
- package/dist/cli/internal/http.js.map +1 -0
- package/dist/cli/tsdown.config.d.ts +2 -0
- package/dist/cli/tsdown.config.js +28 -0
- package/dist/cli/tsdown.config.js.map +1 -0
- package/dist/core/Chains.d.ts +210 -0
- package/dist/core/Chains.js +20 -0
- package/dist/core/Chains.js.map +1 -0
- package/dist/core/Dialog.d.ts +307 -0
- package/dist/core/Dialog.js +809 -0
- package/dist/core/Dialog.js.map +1 -0
- package/dist/core/Messenger.d.ts +164 -0
- package/dist/core/Messenger.js +207 -0
- package/dist/core/Messenger.js.map +1 -0
- package/dist/core/Mode.d.ts +4 -0
- package/dist/core/Mode.js +5 -0
- package/dist/core/Mode.js.map +1 -0
- package/dist/core/Porto.d.ts +1608 -0
- package/dist/core/Porto.js +105 -0
- package/dist/core/Porto.js.map +1 -0
- package/dist/core/RpcSchema.d.ts +81 -0
- package/dist/core/RpcSchema.js +2 -0
- package/dist/core/RpcSchema.js.map +1 -0
- package/dist/core/Storage.d.ts +14 -0
- package/dist/core/Storage.js +109 -0
- package/dist/core/Storage.js.map +1 -0
- package/dist/core/Transport.d.ts +22 -0
- package/dist/core/Transport.js +37 -0
- package/dist/core/Transport.js.map +1 -0
- package/dist/core/internal/_generated/chains.d.ts +1 -0
- package/dist/core/internal/_generated/chains.js +3 -0
- package/dist/core/internal/_generated/chains.js.map +1 -0
- package/dist/core/internal/_generated/contracts/IthacaAccount.d.ts +1120 -0
- package/dist/core/internal/_generated/contracts/IthacaAccount.js +1453 -0
- package/dist/core/internal/_generated/contracts/IthacaAccount.js.map +1 -0
- package/dist/core/internal/call.d.ts +163 -0
- package/dist/core/internal/call.js +115 -0
- package/dist/core/internal/call.js.map +1 -0
- package/dist/core/internal/erc8010.d.ts +17 -0
- package/dist/core/internal/erc8010.js +29 -0
- package/dist/core/internal/erc8010.js.map +1 -0
- package/dist/core/internal/intersectionObserver.d.ts +1 -0
- package/dist/core/internal/intersectionObserver.js +5 -0
- package/dist/core/internal/intersectionObserver.js.map +1 -0
- package/dist/core/internal/logger.d.ts +21 -0
- package/dist/core/internal/logger.js +24 -0
- package/dist/core/internal/logger.js.map +1 -0
- package/dist/core/internal/mode.d.ts +344 -0
- package/dist/core/internal/mode.js +110 -0
- package/dist/core/internal/mode.js.map +1 -0
- package/dist/core/internal/modes/dialog.d.ts +799 -0
- package/dist/core/internal/modes/dialog.js +760 -0
- package/dist/core/internal/modes/dialog.js.map +1 -0
- package/dist/core/internal/modes/reactNative.d.ts +1401 -0
- package/dist/core/internal/modes/reactNative.js +19 -0
- package/dist/core/internal/modes/reactNative.js.map +1 -0
- package/dist/core/internal/modes/relay.d.ts +684 -0
- package/dist/core/internal/modes/relay.js +708 -0
- package/dist/core/internal/modes/relay.js.map +1 -0
- package/dist/core/internal/permissions.d.ts +59 -0
- package/dist/core/internal/permissions.js +30 -0
- package/dist/core/internal/permissions.js.map +1 -0
- package/dist/core/internal/permissionsRequest.d.ts +71 -0
- package/dist/core/internal/permissionsRequest.js +58 -0
- package/dist/core/internal/permissionsRequest.js.map +1 -0
- package/dist/core/internal/porto.d.ts +13 -0
- package/dist/core/internal/porto.js +2 -0
- package/dist/core/internal/porto.js.map +1 -0
- package/dist/core/internal/promise.d.ts +8 -0
- package/dist/core/internal/promise.js +11 -0
- package/dist/core/internal/promise.js.map +1 -0
- package/dist/core/internal/provider.d.ts +29 -0
- package/dist/core/internal/provider.js +941 -0
- package/dist/core/internal/provider.js.map +1 -0
- package/dist/core/internal/relay/rpcSchema.d.ts +75 -0
- package/dist/core/internal/relay/rpcSchema.js +7 -0
- package/dist/core/internal/relay/rpcSchema.js.map +1 -0
- package/dist/core/internal/relay/schema/capabilities.d.ts +164 -0
- package/dist/core/internal/relay/schema/capabilities.js +112 -0
- package/dist/core/internal/relay/schema/capabilities.js.map +1 -0
- package/dist/core/internal/relay/schema/intent.d.ts +167 -0
- package/dist/core/internal/relay/schema/intent.js +170 -0
- package/dist/core/internal/relay/schema/intent.js.map +1 -0
- package/dist/core/internal/relay/schema/key.d.ts +43 -0
- package/dist/core/internal/relay/schema/key.js +30 -0
- package/dist/core/internal/relay/schema/key.js.map +1 -0
- package/dist/core/internal/relay/schema/permission.d.ts +39 -0
- package/dist/core/internal/relay/schema/permission.js +29 -0
- package/dist/core/internal/relay/schema/permission.js.map +1 -0
- package/dist/core/internal/relay/schema/preCall.d.ts +62 -0
- package/dist/core/internal/relay/schema/preCall.js +36 -0
- package/dist/core/internal/relay/schema/preCall.js.map +1 -0
- package/dist/core/internal/relay/schema/quotes.d.ts +369 -0
- package/dist/core/internal/relay/schema/quotes.js +89 -0
- package/dist/core/internal/relay/schema/quotes.js.map +1 -0
- package/dist/core/internal/relay/schema/rpc.d.ts +1528 -0
- package/dist/core/internal/relay/schema/rpc.js +638 -0
- package/dist/core/internal/relay/schema/rpc.js.map +1 -0
- package/dist/core/internal/relay/schema/token.d.ts +13 -0
- package/dist/core/internal/relay/schema/token.js +13 -0
- package/dist/core/internal/relay/schema/token.js.map +1 -0
- package/dist/core/internal/requiredFunds.d.ts +18 -0
- package/dist/core/internal/requiredFunds.js +25 -0
- package/dist/core/internal/requiredFunds.js.map +1 -0
- package/dist/core/internal/schema/capabilities.d.ts +313 -0
- package/dist/core/internal/schema/capabilities.js +133 -0
- package/dist/core/internal/schema/capabilities.js.map +1 -0
- package/dist/core/internal/schema/key.d.ts +164 -0
- package/dist/core/internal/schema/key.js +75 -0
- package/dist/core/internal/schema/key.js.map +1 -0
- package/dist/core/internal/schema/permissions.d.ts +102 -0
- package/dist/core/internal/schema/permissions.js +28 -0
- package/dist/core/internal/schema/permissions.js.map +1 -0
- package/dist/core/internal/schema/request.d.ts +937 -0
- package/dist/core/internal/schema/request.js +57 -0
- package/dist/core/internal/schema/request.js.map +1 -0
- package/dist/core/internal/schema/rpc.d.ts +3314 -0
- package/dist/core/internal/schema/rpc.js +599 -0
- package/dist/core/internal/schema/rpc.js.map +1 -0
- package/dist/core/internal/schema/token.d.ts +1 -0
- package/dist/core/internal/schema/token.js +2 -0
- package/dist/core/internal/schema/token.js.map +1 -0
- package/dist/core/internal/schema/utils.d.ts +18 -0
- package/dist/core/internal/schema/utils.js +213 -0
- package/dist/core/internal/schema/utils.js.map +1 -0
- package/dist/core/internal/siwe.d.ts +32 -0
- package/dist/core/internal/siwe.js +92 -0
- package/dist/core/internal/siwe.js.map +1 -0
- package/dist/core/internal/store.d.ts +2 -0
- package/dist/core/internal/store.js +9 -0
- package/dist/core/internal/store.js.map +1 -0
- package/dist/core/internal/tokens.d.ts +57 -0
- package/dist/core/internal/tokens.js +69 -0
- package/dist/core/internal/tokens.js.map +1 -0
- package/dist/core/internal/types.d.ts +298 -0
- package/dist/core/internal/types.js +2 -0
- package/dist/core/internal/types.js.map +1 -0
- package/dist/core/internal/urlString.d.ts +1 -0
- package/dist/core/internal/urlString.js +8 -0
- package/dist/core/internal/urlString.js.map +1 -0
- package/dist/core/internal/userAgent.d.ts +10 -0
- package/dist/core/internal/userAgent.js +19 -0
- package/dist/core/internal/userAgent.js.map +1 -0
- package/dist/core/internal/utils.d.ts +24 -0
- package/dist/core/internal/utils.js +62 -0
- package/dist/core/internal/utils.js.map +1 -0
- package/dist/core/react-native/Porto.d.ts +1480 -0
- package/dist/core/react-native/Porto.js +17 -0
- package/dist/core/react-native/Porto.js.map +1 -0
- package/dist/core/react-native/configure.d.ts +9 -0
- package/dist/core/react-native/configure.js +24 -0
- package/dist/core/react-native/configure.js.map +1 -0
- package/dist/core/react-native/environment.d.ts +26 -0
- package/dist/core/react-native/environment.js +13 -0
- package/dist/core/react-native/environment.js.map +1 -0
- package/dist/core/react-native/index.d.ts +4 -0
- package/dist/core/react-native/index.js +5 -0
- package/dist/core/react-native/index.js.map +1 -0
- package/dist/core/react-native/utils.d.ts +1 -0
- package/dist/core/react-native/utils.js +12 -0
- package/dist/core/react-native/utils.js.map +1 -0
- package/dist/index.d.ts +16 -2
- package/dist/index.js +15 -2
- package/dist/index.js.map +1 -0
- package/dist/internal/index.d.ts +3 -0
- package/dist/internal/index.js +4 -0
- package/dist/internal/index.js.map +1 -0
- package/dist/react-native/crypto.d.ts +1 -0
- package/dist/react-native/crypto.js +12 -0
- package/dist/react-native/crypto.js.map +1 -0
- package/dist/react-native/index.d.ts +7 -0
- package/dist/react-native/index.js +12 -0
- package/dist/react-native/index.js.map +1 -0
- package/dist/react-native/register.d.ts +2 -0
- package/dist/react-native/register.js +15 -0
- package/dist/react-native/register.js.map +1 -0
- package/dist/register/index.d.ts +14 -0
- package/dist/register/index.js +2 -0
- package/dist/register/index.js.map +1 -0
- package/dist/remote/Actions.d.ts +33 -0
- package/dist/remote/Actions.js +76 -0
- package/dist/remote/Actions.js.map +1 -0
- package/dist/remote/Events.d.ts +46 -0
- package/dist/remote/Events.js +132 -0
- package/dist/remote/Events.js.map +1 -0
- package/dist/remote/Hooks.d.ts +3800 -0
- package/dist/remote/Hooks.js +106 -0
- package/dist/remote/Hooks.js.map +1 -0
- package/dist/remote/Porto.d.ts +857 -0
- package/dist/remote/Porto.js +66 -0
- package/dist/remote/Porto.js.map +1 -0
- package/dist/remote/index.d.ts +4 -0
- package/dist/remote/index.js +5 -0
- package/dist/remote/index.js.map +1 -0
- package/dist/remote/internal/methodPolicies.d.ts +96 -0
- package/dist/remote/internal/methodPolicies.js +102 -0
- package/dist/remote/internal/methodPolicies.js.map +1 -0
- package/dist/server/Route.d.ts +87 -0
- package/dist/server/Route.js +189 -0
- package/dist/server/Route.js.map +1 -0
- package/dist/server/Router.d.ts +23 -0
- package/dist/server/Router.js +29 -0
- package/dist/server/Router.js.map +1 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +3 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/internal/merchantSchema.d.ts +64 -0
- package/dist/server/internal/merchantSchema.js +7 -0
- package/dist/server/internal/merchantSchema.js.map +1 -0
- package/dist/server/internal/requestListener.d.ts +123 -0
- package/dist/server/internal/requestListener.js +172 -0
- package/dist/server/internal/requestListener.js.map +1 -0
- package/dist/theme/Theme.d.ts +121 -0
- package/dist/theme/Theme.js +18 -0
- package/dist/theme/Theme.js.map +1 -0
- package/dist/theme/index.d.ts +2 -0
- package/dist/theme/index.js +2 -0
- package/dist/theme/index.js.map +1 -0
- package/dist/trusted-hosts.d.ts +1 -0
- package/dist/trusted-hosts.js +41 -0
- package/dist/trusted-hosts.js.map +1 -0
- package/dist/viem/Account.d.ts +110 -0
- package/dist/viem/Account.js +132 -0
- package/dist/viem/Account.js.map +1 -0
- package/dist/viem/AccountActions.d.ts +10 -0
- package/dist/viem/AccountActions.js +14 -0
- package/dist/viem/AccountActions.js.map +1 -0
- package/dist/viem/CapabilitiesSchema.d.ts +14 -0
- package/dist/viem/CapabilitiesSchema.js +2 -0
- package/dist/viem/CapabilitiesSchema.js.map +1 -0
- package/dist/viem/ContractActions.d.ts +208 -0
- package/dist/viem/ContractActions.js +350 -0
- package/dist/viem/ContractActions.js.map +1 -0
- package/dist/viem/Key.d.ts +1155 -0
- package/dist/viem/Key.js +924 -0
- package/dist/viem/Key.js.map +1 -0
- package/dist/viem/RelayActions.d.ts +435 -0
- package/dist/viem/RelayActions.js +385 -0
- package/dist/viem/RelayActions.js.map +1 -0
- package/dist/viem/RelayClient.d.ts +26 -0
- package/dist/viem/RelayClient.js +44 -0
- package/dist/viem/RelayClient.js.map +1 -0
- package/dist/viem/RpcSchema.d.ts +22 -0
- package/dist/viem/RpcSchema.js +2 -0
- package/dist/viem/RpcSchema.js.map +1 -0
- package/dist/viem/WalletActions.d.ts +86 -0
- package/dist/viem/WalletActions.js +220 -0
- package/dist/viem/WalletActions.js.map +1 -0
- package/dist/viem/WalletClient.d.ts +20 -0
- package/dist/viem/WalletClient.js +23 -0
- package/dist/viem/WalletClient.js.map +1 -0
- package/dist/viem/index.d.ts +13 -0
- package/dist/viem/index.js +12 -0
- package/dist/viem/index.js.map +1 -0
- package/dist/viem/internal/relayActions.d.ts +364 -0
- package/dist/viem/internal/relayActions.js +783 -0
- package/dist/viem/internal/relayActions.js.map +1 -0
- package/dist/viem/internal/utils.d.ts +15 -0
- package/dist/viem/internal/utils.js +2 -0
- package/dist/viem/internal/utils.js.map +1 -0
- package/dist/wagmi/Actions.d.ts +1 -0
- package/dist/wagmi/Actions.js +2 -0
- package/dist/wagmi/Actions.js.map +1 -0
- package/dist/wagmi/Connector.d.ts +26 -0
- package/dist/wagmi/Connector.js +238 -0
- package/dist/wagmi/Connector.js.map +1 -0
- package/dist/wagmi/Hooks.d.ts +1 -0
- package/dist/wagmi/Hooks.js +2 -0
- package/dist/wagmi/Hooks.js.map +1 -0
- package/dist/wagmi/Query.d.ts +1 -0
- package/dist/wagmi/Query.js +2 -0
- package/dist/wagmi/Query.js.map +1 -0
- package/dist/wagmi/index.d.ts +4 -0
- package/dist/wagmi/index.js +5 -0
- package/dist/wagmi/index.js.map +1 -0
- package/dist/wagmi/internal/core.d.ts +83 -0
- package/dist/wagmi/internal/core.js +229 -0
- package/dist/wagmi/internal/core.js.map +1 -0
- package/dist/wagmi/internal/query.d.ts +32 -0
- package/dist/wagmi/internal/query.js +23 -0
- package/dist/wagmi/internal/query.js.map +1 -0
- package/dist/wagmi/internal/react.d.ts +90 -0
- package/dist/wagmi/internal/react.js +256 -0
- package/dist/wagmi/internal/react.js.map +1 -0
- package/dist/wagmi/internal/types.d.ts +10 -0
- package/dist/wagmi/internal/types.js +2 -0
- package/dist/wagmi/internal/types.js.map +1 -0
- package/dist/wagmi/internal/utils.d.ts +1 -0
- package/dist/wagmi/internal/utils.js +18 -0
- package/dist/wagmi/internal/utils.js.map +1 -0
- package/package.json +286 -34
- package/src/cli/Dialog.ts +75 -0
- package/src/cli/Messenger.ts +148 -0
- package/src/cli/bin/index.ts +37 -0
- package/src/cli/bin/tsconfig.json +8 -0
- package/src/cli/index.ts +2 -0
- package/src/cli/internal/commands.ts +212 -0
- package/src/cli/internal/context.ts +56 -0
- package/src/cli/internal/http.ts +28 -0
- package/src/cli/internal/utils.ts +28 -0
- package/src/cli/tsdown.config.ts +37 -0
- package/src/core/Chains.ts +25 -0
- package/src/core/Dialog.ts +1059 -0
- package/src/core/Messenger.ts +394 -0
- package/src/core/Mode.ts +4 -0
- package/src/core/Porto.ts +287 -0
- package/src/core/RpcSchema.ts +124 -0
- package/src/core/Storage.ts +122 -0
- package/src/core/Transport.ts +45 -0
- package/src/core/internal/_generated/chains.ts +2 -0
- package/src/core/internal/_generated/contracts/EIP7702Proxy.ts +25 -0
- package/src/core/internal/_generated/contracts/Escrow.ts +330 -0
- package/src/core/internal/_generated/contracts/ExperimentERC20.ts +569 -0
- package/src/core/internal/_generated/contracts/ExperimentERC721.ts +588 -0
- package/src/core/internal/_generated/contracts/GuardedExecutor.ts +623 -0
- package/src/core/internal/_generated/contracts/ICallChecker.ts +34 -0
- package/src/core/internal/_generated/contracts/ICommon.ts +4 -0
- package/src/core/internal/_generated/contracts/IEscrow.ts +114 -0
- package/src/core/internal/_generated/contracts/IFunder.ts +80 -0
- package/src/core/internal/_generated/contracts/IFunderV4.ts +45 -0
- package/src/core/internal/_generated/contracts/IIthacaAccount.ts +107 -0
- package/src/core/internal/_generated/contracts/IOAppCore.ts +142 -0
- package/src/core/internal/_generated/contracts/IOAppMsgInspector.ts +45 -0
- package/src/core/internal/_generated/contracts/IOAppReceiver.ts +161 -0
- package/src/core/internal/_generated/contracts/IOrchestrator.ts +95 -0
- package/src/core/internal/_generated/contracts/ISettler.ts +52 -0
- package/src/core/internal/_generated/contracts/ISigner.ts +34 -0
- package/src/core/internal/_generated/contracts/IthacaAccount.ts +1454 -0
- package/src/core/internal/_generated/contracts/IthacaAccountNew.ts +1454 -0
- package/src/core/internal/_generated/contracts/IthacaAccountOld.ts +1454 -0
- package/src/core/internal/_generated/contracts/LayerZeroSettler.ts +811 -0
- package/src/core/internal/_generated/contracts/LibNonce.ts +15 -0
- package/src/core/internal/_generated/contracts/LibTStack.ts +4 -0
- package/src/core/internal/_generated/contracts/MultiSigSigner.ts +203 -0
- package/src/core/internal/_generated/contracts/OApp.ts +412 -0
- package/src/core/internal/_generated/contracts/OAppCore.ts +229 -0
- package/src/core/internal/_generated/contracts/OAppReceiver.ts +396 -0
- package/src/core/internal/_generated/contracts/OAppSender.ts +245 -0
- package/src/core/internal/_generated/contracts/Orchestrator.ts +390 -0
- package/src/core/internal/_generated/contracts/SimpleFunder.ts +534 -0
- package/src/core/internal/_generated/contracts/SimpleSettler.ts +360 -0
- package/src/core/internal/_generated/contracts/Simulator.ts +170 -0
- package/src/core/internal/_generated/contracts/TokenTransferLib.ts +4 -0
- package/src/core/internal/_snapshots/provider.browser.test.ts.snap +119 -0
- package/src/core/internal/_snapshots/provider.test.ts.snap +1103 -0
- package/src/core/internal/call.test.ts +116 -0
- package/src/core/internal/call.ts +245 -0
- package/src/core/internal/erc8010.test.ts +74 -0
- package/src/core/internal/erc8010.ts +44 -0
- package/src/core/internal/intersectionObserver.ts +5 -0
- package/src/core/internal/logger.ts +42 -0
- package/src/core/internal/mode.ts +498 -0
- package/src/core/internal/modes/dialog.ts +1051 -0
- package/src/core/internal/modes/reactNative.ts +29 -0
- package/src/core/internal/modes/relay.ts +893 -0
- package/src/core/internal/permissions.ts +43 -0
- package/src/core/internal/permissionsRequest.ts +88 -0
- package/src/core/internal/porto.ts +16 -0
- package/src/core/internal/promise.ts +19 -0
- package/src/core/internal/provider.browser.test.ts +311 -0
- package/src/core/internal/provider.test.ts +3552 -0
- package/src/core/internal/provider.ts +1277 -0
- package/src/core/internal/relay/rpcSchema.ts +101 -0
- package/src/core/internal/relay/schema/capabilities.test.ts +663 -0
- package/src/core/internal/relay/schema/capabilities.ts +156 -0
- package/src/core/internal/relay/schema/intent.test.ts +433 -0
- package/src/core/internal/relay/schema/intent.ts +174 -0
- package/src/core/internal/relay/schema/key.test.ts +424 -0
- package/src/core/internal/relay/schema/key.ts +34 -0
- package/src/core/internal/relay/schema/permission.test.ts +499 -0
- package/src/core/internal/relay/schema/permission.ts +34 -0
- package/src/core/internal/relay/schema/preCall.ts +39 -0
- package/src/core/internal/relay/schema/quotes.test.ts +901 -0
- package/src/core/internal/relay/schema/quotes.ts +98 -0
- package/src/core/internal/relay/schema/rpc.ts +822 -0
- package/src/core/internal/relay/schema/token.ts +16 -0
- package/src/core/internal/requiredFunds.test.ts +141 -0
- package/src/core/internal/requiredFunds.ts +45 -0
- package/src/core/internal/schema/capabilities.test.ts +1334 -0
- package/src/core/internal/schema/capabilities.ts +162 -0
- package/src/core/internal/schema/key.test.ts +570 -0
- package/src/core/internal/schema/key.ts +98 -0
- package/src/core/internal/schema/permissions.test.ts +948 -0
- package/src/core/internal/schema/permissions.ts +31 -0
- package/src/core/internal/schema/request.bench.ts +35 -0
- package/src/core/internal/schema/request.ts +90 -0
- package/src/core/internal/schema/rpc.ts +821 -0
- package/src/core/internal/schema/token.ts +1 -0
- package/src/core/internal/schema/utils.test.ts +572 -0
- package/src/core/internal/schema/utils.ts +236 -0
- package/src/core/internal/siwe.test.ts +473 -0
- package/src/core/internal/siwe.ts +144 -0
- package/src/core/internal/store.ts +9 -0
- package/src/core/internal/tokens.test.ts +317 -0
- package/src/core/internal/tokens.ts +125 -0
- package/src/core/internal/types.ts +448 -0
- package/src/core/internal/urlString.ts +5 -0
- package/src/core/internal/userAgent.ts +35 -0
- package/src/core/internal/utils.test.ts +35 -0
- package/src/core/internal/utils.ts +67 -0
- package/src/core/react-native/Porto.ts +22 -0
- package/src/core/react-native/configure.ts +31 -0
- package/src/core/react-native/environment.ts +43 -0
- package/src/core/react-native/index.ts +4 -0
- package/src/core/react-native/utils.ts +18 -0
- package/src/index.ts +17 -0
- package/src/internal/index.ts +3 -0
- package/src/react-native/crypto.ts +19 -0
- package/src/react-native/index.ts +15 -0
- package/src/react-native/register.ts +24 -0
- package/src/register/index.ts +17 -0
- package/src/remote/Actions.ts +115 -0
- package/src/remote/Events.ts +193 -0
- package/src/remote/Hooks.ts +194 -0
- package/src/remote/Porto.ts +144 -0
- package/src/remote/index.ts +4 -0
- package/src/remote/internal/methodPolicies.ts +124 -0
- package/src/server/Route.test.ts +347 -0
- package/src/server/Route.ts +259 -0
- package/src/server/Router.test.ts +32 -0
- package/src/server/Router.ts +59 -0
- package/src/server/index.ts +2 -0
- package/src/server/internal/merchantSchema.ts +11 -0
- package/src/server/internal/requestListener.ts +284 -0
- package/src/theme/Theme.ts +163 -0
- package/src/theme/index.ts +2 -0
- package/src/trusted-hosts.ts +40 -0
- package/src/tsconfig.build.tsbuildinfo +1 -0
- package/src/tsconfig.json +15 -0
- package/src/viem/Account.test.ts +270 -0
- package/src/viem/Account.ts +278 -0
- package/src/viem/AccountActions.test.ts +3 -0
- package/src/viem/AccountActions.ts +30 -0
- package/src/viem/CapabilitiesSchema.ts +18 -0
- package/src/viem/ContractActions.test.ts +980 -0
- package/src/viem/ContractActions.ts +624 -0
- package/src/viem/Key.test.ts +1420 -0
- package/src/viem/Key.ts +1318 -0
- package/src/viem/RelayActions.test.ts +1730 -0
- package/src/viem/RelayActions.ts +1082 -0
- package/src/viem/RelayClient.test.ts +127 -0
- package/src/viem/RelayClient.ts +87 -0
- package/src/viem/RpcSchema.ts +27 -0
- package/src/viem/WalletActions.test.ts +646 -0
- package/src/viem/WalletActions.ts +476 -0
- package/src/viem/WalletClient.test.ts +36 -0
- package/src/viem/WalletClient.ts +74 -0
- package/src/viem/index.ts +13 -0
- package/src/viem/internal/relayActions.test.ts +1296 -0
- package/src/viem/internal/relayActions.ts +1222 -0
- package/src/viem/internal/utils.ts +27 -0
- package/src/wagmi/Actions.ts +13 -0
- package/src/wagmi/Connector.ts +304 -0
- package/src/wagmi/Hooks.ts +14 -0
- package/src/wagmi/Query.ts +5 -0
- package/src/wagmi/index.ts +4 -0
- package/src/wagmi/internal/core.test.ts +12 -0
- package/src/wagmi/internal/core.ts +468 -0
- package/src/wagmi/internal/query.ts +52 -0
- package/src/wagmi/internal/react.test.ts +12 -0
- package/src/wagmi/internal/react.ts +705 -0
- package/src/wagmi/internal/types.ts +21 -0
- package/src/wagmi/internal/utils.ts +25 -0
- package/dist/chain.cjs +0 -17
- package/dist/chain.d.cts +0 -41
- package/dist/chain.d.ts +0 -41
- package/dist/chain.js +0 -13
- package/dist/config.cjs +0 -19
- package/dist/config.d.cts +0 -3
- package/dist/config.d.ts +0 -3
- package/dist/config.js +0 -16
- package/dist/index.cjs +0 -18
- package/dist/index.d.cts +0 -2
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function isReactNative() {
|
|
2
|
+
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative')
|
|
3
|
+
return true
|
|
4
|
+
|
|
5
|
+
if (
|
|
6
|
+
typeof window !== 'undefined' &&
|
|
7
|
+
Object.hasOwn(window, 'ReactNativeWebView')
|
|
8
|
+
)
|
|
9
|
+
return true
|
|
10
|
+
|
|
11
|
+
if (
|
|
12
|
+
typeof globalThis !== 'undefined' &&
|
|
13
|
+
Object.hasOwn(globalThis, 'HermesEngine')
|
|
14
|
+
)
|
|
15
|
+
return true
|
|
16
|
+
|
|
17
|
+
return false
|
|
18
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * as Chains from './core/Chains.js'
|
|
2
|
+
export * as Dialog from './core/Dialog.js'
|
|
3
|
+
export {
|
|
4
|
+
/** @internal @deprecated export required for inference. */
|
|
5
|
+
from,
|
|
6
|
+
/** @internal @deprecated export required for inference. */
|
|
7
|
+
type Provider,
|
|
8
|
+
} from './core/internal/provider.js'
|
|
9
|
+
export * as Messenger from './core/Messenger.js'
|
|
10
|
+
export * as Mode from './core/Mode.js'
|
|
11
|
+
export * as Porto from './core/Porto.js'
|
|
12
|
+
export * as RpcSchema from './core/RpcSchema.js'
|
|
13
|
+
export * as Storage from './core/Storage.js'
|
|
14
|
+
export * as Transport from './core/Transport.js'
|
|
15
|
+
export * as Account from './viem/Account.js'
|
|
16
|
+
export * as Key from './viem/Key.js'
|
|
17
|
+
export * as RelayActions from './viem/RelayActions.js'
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as ExpoCrypto from 'expo-crypto'
|
|
2
|
+
import { Platform } from 'react-native'
|
|
3
|
+
|
|
4
|
+
if (Platform.OS !== 'web')
|
|
5
|
+
Object.defineProperty(globalThis, 'crypto', {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
value: {
|
|
8
|
+
digest: (algorithm, message) => ExpoCrypto.digest(algorithm, message),
|
|
9
|
+
getRandomValues: (array) => ExpoCrypto.getRandomValues(array),
|
|
10
|
+
randomUUID: () => ExpoCrypto.randomUUID(),
|
|
11
|
+
} satisfies {
|
|
12
|
+
digest: (
|
|
13
|
+
algorithm: ExpoCrypto.CryptoDigestAlgorithm,
|
|
14
|
+
message: BufferSource,
|
|
15
|
+
) => Promise<ArrayBuffer>
|
|
16
|
+
randomUUID: () => string
|
|
17
|
+
getRandomValues: (array: Uint8Array) => Uint8Array
|
|
18
|
+
},
|
|
19
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isEnvironmentConfigured,
|
|
3
|
+
isReactNative,
|
|
4
|
+
} from '../core/react-native/index.js'
|
|
5
|
+
import { configure } from './register.js'
|
|
6
|
+
|
|
7
|
+
if (isReactNative() && !isEnvironmentConfigured()) configure()
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* React Native entrypoint
|
|
11
|
+
* @see https://reactnative.dev/docs/platform-specific-code#native-specific-extensions-ie-sharing-code-with-nodejs-and-web
|
|
12
|
+
**/
|
|
13
|
+
export * as Mode from '../core/Mode.js'
|
|
14
|
+
export * from '../core/react-native/index.js'
|
|
15
|
+
export * as Porto from '../core/react-native/Porto.js'
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import './crypto.js'
|
|
2
|
+
import {
|
|
3
|
+
isEnvironmentConfigured,
|
|
4
|
+
isReactNative,
|
|
5
|
+
} from '../core/react-native/index.js'
|
|
6
|
+
|
|
7
|
+
export const configure = () =>
|
|
8
|
+
void import('../core/react-native/configure.js')
|
|
9
|
+
.then(({ configureReactNativeEnvironment }) =>
|
|
10
|
+
configureReactNativeEnvironment(),
|
|
11
|
+
)
|
|
12
|
+
.catch((error) => {
|
|
13
|
+
console.error(
|
|
14
|
+
[
|
|
15
|
+
'[porto:react-native] React Native environment not configured',
|
|
16
|
+
'You need to import the configuration entrypoint at the top of your app',
|
|
17
|
+
"import 'porto/react-native/configure'",
|
|
18
|
+
'then import `Porto` and the rest',
|
|
19
|
+
].join('\n'),
|
|
20
|
+
error,
|
|
21
|
+
)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
if (isReactNative() && !isEnvironmentConfigured()) configure()
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ValueOf } from 'viem'
|
|
2
|
+
import type * as Rpc from '../core/internal/schema/rpc.js'
|
|
3
|
+
|
|
4
|
+
declare module 'viem' {
|
|
5
|
+
interface Register {
|
|
6
|
+
// biome-ignore lint/suspicious/noTsIgnore: _
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
CapabilitiesSchema: {
|
|
9
|
+
getCapabilities: {
|
|
10
|
+
ReturnType: ValueOf<Rpc.wallet_getCapabilities.Response_encoded>
|
|
11
|
+
}
|
|
12
|
+
sendCalls: {
|
|
13
|
+
Request: Rpc.wallet_sendCalls.Capabilities_encoded
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import * as Provider from 'ox/Provider'
|
|
2
|
+
import * as RpcResponse from 'ox/RpcResponse'
|
|
3
|
+
|
|
4
|
+
import type * as Porto from '../core/Porto.js'
|
|
5
|
+
import type * as Remote from './Porto.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Action to reject an RPC request.
|
|
9
|
+
*
|
|
10
|
+
* @param porto - Porto instance.
|
|
11
|
+
* @param request - Request to reject.
|
|
12
|
+
* @param error - Error to reject with.
|
|
13
|
+
*/
|
|
14
|
+
export async function reject(
|
|
15
|
+
porto: Pick<Remote.Porto<any>, 'messenger'>,
|
|
16
|
+
request: Porto.QueuedRequest['request'],
|
|
17
|
+
error?: Provider.ProviderRpcError | RpcResponse.BaseError | undefined,
|
|
18
|
+
) {
|
|
19
|
+
const error_ = error ?? new Provider.UserRejectedRequestError()
|
|
20
|
+
const { messenger } = porto
|
|
21
|
+
messenger.send(
|
|
22
|
+
'rpc-response',
|
|
23
|
+
Object.assign(
|
|
24
|
+
RpcResponse.from({
|
|
25
|
+
error: {
|
|
26
|
+
code: error_.code,
|
|
27
|
+
message: error_.message,
|
|
28
|
+
},
|
|
29
|
+
id: request.id,
|
|
30
|
+
jsonrpc: '2.0',
|
|
31
|
+
}),
|
|
32
|
+
{
|
|
33
|
+
_request: request,
|
|
34
|
+
},
|
|
35
|
+
),
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Action to reject all RPC requests.
|
|
41
|
+
*
|
|
42
|
+
* @param porto - Porto instance.
|
|
43
|
+
* @param error - Error to reject with.
|
|
44
|
+
*/
|
|
45
|
+
export async function rejectAll(
|
|
46
|
+
porto: Pick<Remote.Porto<any>, 'messenger' | '_internal'>,
|
|
47
|
+
error?: Provider.ProviderRpcError | RpcResponse.BaseError | undefined,
|
|
48
|
+
) {
|
|
49
|
+
const { _internal } = porto
|
|
50
|
+
const requests = _internal.remoteStore.getState().requests
|
|
51
|
+
for (const request of requests) await reject(porto, request.request, error)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Action to respond to an RPC request.
|
|
56
|
+
*
|
|
57
|
+
* @param porto - Porto instance.
|
|
58
|
+
* @param request - Request to respond to.
|
|
59
|
+
*/
|
|
60
|
+
export async function respond<result>(
|
|
61
|
+
porto: Pick<Remote.Porto<any>, 'messenger' | 'provider'>,
|
|
62
|
+
request: Porto.QueuedRequest['request'],
|
|
63
|
+
options?: {
|
|
64
|
+
error?: RpcResponse.ErrorObject | undefined
|
|
65
|
+
onError?: (error: RpcResponse.BaseError) =>
|
|
66
|
+
| undefined
|
|
67
|
+
| {
|
|
68
|
+
cancelResponse: boolean
|
|
69
|
+
}
|
|
70
|
+
result?: result | undefined
|
|
71
|
+
selector?: (result: result) => unknown
|
|
72
|
+
},
|
|
73
|
+
) {
|
|
74
|
+
const { messenger, provider } = porto
|
|
75
|
+
const { error, selector } = options ?? {}
|
|
76
|
+
const shared = {
|
|
77
|
+
id: request.id,
|
|
78
|
+
jsonrpc: '2.0',
|
|
79
|
+
} as const
|
|
80
|
+
|
|
81
|
+
if (error) {
|
|
82
|
+
messenger.send(
|
|
83
|
+
'rpc-response',
|
|
84
|
+
Object.assign(RpcResponse.from({ ...shared, error, status: 'error' }), {
|
|
85
|
+
_request: request,
|
|
86
|
+
}),
|
|
87
|
+
)
|
|
88
|
+
return
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
let result = options?.result ?? (await provider.request(request))
|
|
93
|
+
if (selector) result = selector(result as never)
|
|
94
|
+
messenger.send(
|
|
95
|
+
'rpc-response',
|
|
96
|
+
Object.assign(RpcResponse.from({ ...shared, result }), {
|
|
97
|
+
_request: request,
|
|
98
|
+
}),
|
|
99
|
+
)
|
|
100
|
+
return result
|
|
101
|
+
} catch (e) {
|
|
102
|
+
const error = e as RpcResponse.BaseError
|
|
103
|
+
if (options?.onError?.(error)?.cancelResponse === true)
|
|
104
|
+
// If the onError callback sets cancelResponse to true,
|
|
105
|
+
// we do not send a response.
|
|
106
|
+
return
|
|
107
|
+
messenger.send(
|
|
108
|
+
'rpc-response',
|
|
109
|
+
Object.assign(RpcResponse.from({ ...shared, error, status: 'error' }), {
|
|
110
|
+
_request: request,
|
|
111
|
+
}),
|
|
112
|
+
)
|
|
113
|
+
throw error
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import type * as Address from 'ox/Address'
|
|
2
|
+
import type * as Hex from 'ox/Hex'
|
|
3
|
+
import * as Provider from 'ox/Provider'
|
|
4
|
+
import * as z from 'zod/mini'
|
|
5
|
+
import * as Rpc from '../core/internal/schema/rpc.js'
|
|
6
|
+
import type { Payload } from '../core/Messenger.js'
|
|
7
|
+
import * as Actions from './Actions.js'
|
|
8
|
+
import type * as Remote from './Porto.js'
|
|
9
|
+
|
|
10
|
+
const trustedOrigins = ['id.porto.sh', 'localhost:5174', 'localhost:5173']
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Event listener which is triggered when a request is ready
|
|
14
|
+
* to be handled by the dialog.
|
|
15
|
+
*
|
|
16
|
+
* @param porto - Porto instance.
|
|
17
|
+
* @param cb - Callback function.
|
|
18
|
+
* @returns Unsubscribe function.
|
|
19
|
+
*/
|
|
20
|
+
export function onDialogRequest(
|
|
21
|
+
porto: Pick<
|
|
22
|
+
Remote.Porto<any>,
|
|
23
|
+
'_internal' | 'methodPolicies' | 'messenger' | 'provider'
|
|
24
|
+
>,
|
|
25
|
+
cb: (payload: onDialogRequest.Payload) => void,
|
|
26
|
+
) {
|
|
27
|
+
return onRequests(porto, (requests, event) => {
|
|
28
|
+
let account: onDialogRequest.Payload['account']
|
|
29
|
+
let request_dialog: onDialogRequest.Payload['request'] | undefined
|
|
30
|
+
let requireConnection: boolean | undefined
|
|
31
|
+
|
|
32
|
+
// Process the pending requests, as well as finding the first request
|
|
33
|
+
// that requires the dialog.
|
|
34
|
+
for (const r of requests) {
|
|
35
|
+
const { request } = r ?? {}
|
|
36
|
+
|
|
37
|
+
// If this request doesn't have a JSON-RPC request, skip it.
|
|
38
|
+
if (!request) continue
|
|
39
|
+
|
|
40
|
+
// If this request is a wallet_connect request, we need to make sure
|
|
41
|
+
// the provided chain ids are supported by the dialog.
|
|
42
|
+
if (request.method === 'wallet_connect') {
|
|
43
|
+
const params = z.decode(
|
|
44
|
+
Rpc.wallet_connect.Parameters,
|
|
45
|
+
request.params?.[0] as never,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
// Extract chainIds that the app has requested.
|
|
49
|
+
const chainIds_app = params?.chainIds
|
|
50
|
+
if (chainIds_app?.[0]) {
|
|
51
|
+
const chainIds = porto._internal.store.getState().chainIds
|
|
52
|
+
|
|
53
|
+
// Find the first app chain that is supported by the dialog.
|
|
54
|
+
const chainId = chainIds_app.find((chainId) =>
|
|
55
|
+
chainIds.includes(chainId),
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
// If the requested chain is not supported, respond with an error.
|
|
59
|
+
if (!chainId) {
|
|
60
|
+
Actions.respond(porto, request, {
|
|
61
|
+
error: new Provider.UnsupportedChainIdError(),
|
|
62
|
+
}).catch(() => {})
|
|
63
|
+
continue
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Update the dialog chainIds so that the app chain is the "active" chain.
|
|
67
|
+
porto._internal.store.setState((x) => ({
|
|
68
|
+
...x,
|
|
69
|
+
chainIds: [chainId, ...x.chainIds.filter((x) => x !== chainId)],
|
|
70
|
+
}))
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Extract the method policy for this request. Method policies are
|
|
75
|
+
// used to determine if the request should be headless (bypassed), or
|
|
76
|
+
// if it is supported by the dialog.
|
|
77
|
+
const policy = porto.methodPolicies?.find(
|
|
78
|
+
(policy) => policy.method === request.method,
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
const shouldBypass = (() => {
|
|
82
|
+
if (!request) return false
|
|
83
|
+
|
|
84
|
+
const rule = policy?.modes?.headless
|
|
85
|
+
if (rule) {
|
|
86
|
+
if (
|
|
87
|
+
typeof rule === 'object' &&
|
|
88
|
+
rule.sameOrigin &&
|
|
89
|
+
event.origin !== window.location.origin
|
|
90
|
+
)
|
|
91
|
+
return false
|
|
92
|
+
return true
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return false
|
|
96
|
+
})()
|
|
97
|
+
if (shouldBypass) {
|
|
98
|
+
Actions.respond(porto, request).catch(() => {})
|
|
99
|
+
continue
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const rule = policy?.modes?.dialog
|
|
103
|
+
const shouldDialog = (() => {
|
|
104
|
+
if (!rule) return true
|
|
105
|
+
if (
|
|
106
|
+
typeof rule === 'object' &&
|
|
107
|
+
rule.sameOrigin &&
|
|
108
|
+
event.origin !== window.location.origin
|
|
109
|
+
)
|
|
110
|
+
return trustedOrigins.some((origin) => event.origin.endsWith(origin))
|
|
111
|
+
return rule
|
|
112
|
+
})()
|
|
113
|
+
if (!shouldDialog) {
|
|
114
|
+
Actions.respond(porto, request, {
|
|
115
|
+
error: new Provider.UnsupportedMethodError(),
|
|
116
|
+
}).catch(() => {})
|
|
117
|
+
continue
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// If this requests requires a specific account, set it.
|
|
121
|
+
account ??= r.account
|
|
122
|
+
// If this request requires an account connection, set it.
|
|
123
|
+
requireConnection ??= policy?.requireConnection ?? true
|
|
124
|
+
// At this point, we know that this request should be handled by the dialog.
|
|
125
|
+
request_dialog ??= request
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
cb({
|
|
129
|
+
account: requireConnection ? account : undefined,
|
|
130
|
+
origin: event.origin,
|
|
131
|
+
request: request_dialog ?? null,
|
|
132
|
+
})
|
|
133
|
+
})
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export declare namespace onDialogRequest {
|
|
137
|
+
type Payload = {
|
|
138
|
+
account?:
|
|
139
|
+
| {
|
|
140
|
+
address: Address.Address
|
|
141
|
+
key?:
|
|
142
|
+
| {
|
|
143
|
+
credentialId?: string | undefined
|
|
144
|
+
publicKey: Hex.Hex
|
|
145
|
+
}
|
|
146
|
+
| undefined
|
|
147
|
+
}
|
|
148
|
+
| undefined
|
|
149
|
+
request: Remote.RemoteState['requests'][number]['request'] | null
|
|
150
|
+
origin: string
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Event listener which is triggered when the remote context receives
|
|
156
|
+
* an initialization message from the parent context.
|
|
157
|
+
*
|
|
158
|
+
* @param porto - Porto instance.
|
|
159
|
+
* @param cb - Callback function.
|
|
160
|
+
* @returns Unsubscribe function.
|
|
161
|
+
*/
|
|
162
|
+
export function onInitialized(
|
|
163
|
+
porto: Pick<Remote.Porto<any>, 'messenger'>,
|
|
164
|
+
cb: (
|
|
165
|
+
payload: Extract<Payload<'__internal'>, { type: 'init' }>,
|
|
166
|
+
event: MessageEvent,
|
|
167
|
+
) => void,
|
|
168
|
+
) {
|
|
169
|
+
const { messenger } = porto
|
|
170
|
+
return messenger.on('__internal', (payload, event) => {
|
|
171
|
+
if (payload.type === 'init') cb(payload, event)
|
|
172
|
+
})
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Event listener which is triggered when the remote context receives
|
|
177
|
+
* an RPC request from the parent context.
|
|
178
|
+
*
|
|
179
|
+
* @param porto - Porto instance.
|
|
180
|
+
* @param cb - Callback function.
|
|
181
|
+
* @returns Unsubscribe function.
|
|
182
|
+
*/
|
|
183
|
+
export function onRequests(
|
|
184
|
+
porto: Pick<Remote.Porto<any>, '_internal' | 'messenger'>,
|
|
185
|
+
cb: (payload: Remote.RemoteState['requests'], event: MessageEvent) => void,
|
|
186
|
+
) {
|
|
187
|
+
const { messenger, _internal } = porto
|
|
188
|
+
return messenger.on('rpc-requests', (payload, event) => {
|
|
189
|
+
const requests = payload as Remote.RemoteState['requests']
|
|
190
|
+
_internal.remoteStore.setState({ requests })
|
|
191
|
+
cb(requests, event)
|
|
192
|
+
})
|
|
193
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { Address } from 'ox'
|
|
2
|
+
import { useMemo } from 'react'
|
|
3
|
+
import { useStore } from 'zustand'
|
|
4
|
+
import { useShallow } from 'zustand/shallow'
|
|
5
|
+
|
|
6
|
+
import type * as Chains from '../core/Chains.js'
|
|
7
|
+
import type * as Porto from '../core/Porto.js'
|
|
8
|
+
import * as RelayClient from '../viem/RelayClient.js'
|
|
9
|
+
import * as WalletClient from '../viem/WalletClient.js'
|
|
10
|
+
import type * as Remote from './Porto.js'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Hook to access and subscribe to the current account.
|
|
14
|
+
* If an `address` is provided, it will return the account if exists.
|
|
15
|
+
*
|
|
16
|
+
* @param porto - Porto instance.
|
|
17
|
+
* @param parameters - Parameters.
|
|
18
|
+
* @returns Account.
|
|
19
|
+
*/
|
|
20
|
+
export function useAccount<
|
|
21
|
+
chains extends readonly [Chains.Chain, ...Chains.Chain[]],
|
|
22
|
+
>(
|
|
23
|
+
porto: Pick<Remote.Porto<chains>, '_internal'>,
|
|
24
|
+
parameters: useAccount.Parameters = {},
|
|
25
|
+
) {
|
|
26
|
+
const { address } = parameters
|
|
27
|
+
return usePortoStore(porto, (x) => {
|
|
28
|
+
if (!address) return x.accounts[0]
|
|
29
|
+
return x.accounts.find((x) => Address.isEqual(x.address, address))
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export namespace useAccount {
|
|
34
|
+
export type Parameters = {
|
|
35
|
+
address?: Address.Address | undefined
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Hook to access and subscribe to the current accounts.
|
|
41
|
+
*
|
|
42
|
+
* @param porto - Porto instance.
|
|
43
|
+
* @returns Accounts.
|
|
44
|
+
*/
|
|
45
|
+
export function useAccounts<
|
|
46
|
+
chains extends readonly [Chains.Chain, ...Chains.Chain[]],
|
|
47
|
+
>(porto: Pick<Remote.Porto<chains>, '_internal'>) {
|
|
48
|
+
return usePortoStore(porto, (x) => x.accounts)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Hook to access and subscribe to the current chain.
|
|
53
|
+
* If a `chainId` is provided, it will return the chain if supported.
|
|
54
|
+
*
|
|
55
|
+
* @param porto - Porto instance.
|
|
56
|
+
* @param parameters - Parameters.
|
|
57
|
+
* @returns Chain.
|
|
58
|
+
*/
|
|
59
|
+
export function useChain<
|
|
60
|
+
chains extends readonly [Chains.Chain, ...Chains.Chain[]],
|
|
61
|
+
>(
|
|
62
|
+
porto: Pick<Remote.Porto<chains>, '_internal'>,
|
|
63
|
+
parameters: useChain.Parameters = {},
|
|
64
|
+
) {
|
|
65
|
+
return usePortoStore(porto, (state) => {
|
|
66
|
+
const chainId = parameters.chainId ?? state.chainIds[0]
|
|
67
|
+
return porto._internal.config.chains.find((x) => x.id === chainId) as
|
|
68
|
+
| chains[number]
|
|
69
|
+
| undefined
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export namespace useChain {
|
|
74
|
+
export type Parameters = {
|
|
75
|
+
chainId?: number | undefined
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Hook to access and subscribe to the store of the Porto instance.
|
|
81
|
+
*
|
|
82
|
+
* @param porto - Porto instance.
|
|
83
|
+
* @param selector - Selector function.
|
|
84
|
+
* @returns Store state.
|
|
85
|
+
*/
|
|
86
|
+
export function usePortoStore<
|
|
87
|
+
slice = Porto.State,
|
|
88
|
+
chains extends readonly [Chains.Chain, ...Chains.Chain[]] = readonly [
|
|
89
|
+
Chains.Chain,
|
|
90
|
+
...Chains.Chain[],
|
|
91
|
+
],
|
|
92
|
+
>(
|
|
93
|
+
porto: Pick<Remote.Porto<chains>, '_internal'>,
|
|
94
|
+
selector: Parameters<
|
|
95
|
+
typeof useStore<typeof porto._internal.store, slice>
|
|
96
|
+
>[1] = (state) => state as slice,
|
|
97
|
+
) {
|
|
98
|
+
const { store } = porto._internal
|
|
99
|
+
return useStore(store, useShallow(selector))
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Hook to access and subscribe to the remote store of the Porto instance.
|
|
104
|
+
*
|
|
105
|
+
* @param porto - Porto instance.
|
|
106
|
+
* @param selector - Selector function.
|
|
107
|
+
* @returns Remote store state.
|
|
108
|
+
*/
|
|
109
|
+
export function useRemoteStore<
|
|
110
|
+
slice = Remote.State,
|
|
111
|
+
chains extends readonly [Chains.Chain, ...Chains.Chain[]] = readonly [
|
|
112
|
+
Chains.Chain,
|
|
113
|
+
...Chains.Chain[],
|
|
114
|
+
],
|
|
115
|
+
>(
|
|
116
|
+
porto: Pick<Remote.Porto<chains>, '_internal'>,
|
|
117
|
+
selector: Parameters<
|
|
118
|
+
typeof useStore<typeof porto._internal.remoteStore, slice>
|
|
119
|
+
>[1] = (state) => state as slice,
|
|
120
|
+
) {
|
|
121
|
+
const { remoteStore } = porto._internal
|
|
122
|
+
return useStore(remoteStore, useShallow(selector))
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Hook to access and subscribe to current pending requests.
|
|
127
|
+
*
|
|
128
|
+
* @param porto - Porto instance.
|
|
129
|
+
* @returns Requests.
|
|
130
|
+
*/
|
|
131
|
+
export function useRequests<
|
|
132
|
+
chains extends readonly [Chains.Chain, ...Chains.Chain[]],
|
|
133
|
+
>(porto: Pick<Remote.Porto<chains>, '_internal'>) {
|
|
134
|
+
return useRemoteStore(porto, (state) =>
|
|
135
|
+
state.requests.filter((x) => x.status === 'pending').map((x) => x.request),
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Hook to access and subscribe to the next pending request.
|
|
141
|
+
*
|
|
142
|
+
* @param porto - Porto instance.
|
|
143
|
+
* @returns Request.
|
|
144
|
+
*/
|
|
145
|
+
export function useRequest<
|
|
146
|
+
chains extends readonly [Chains.Chain, ...Chains.Chain[]],
|
|
147
|
+
>(porto: Pick<Remote.Porto<chains>, '_internal'>) {
|
|
148
|
+
return useRemoteStore(
|
|
149
|
+
porto,
|
|
150
|
+
(state) =>
|
|
151
|
+
state.requests.find((request) => request.status === 'pending')?.request,
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Hook to access and subscribe to the Relay Client of the Porto instance.
|
|
157
|
+
*
|
|
158
|
+
* @param porto - Porto instance.
|
|
159
|
+
* @returns Relay Client.
|
|
160
|
+
*/
|
|
161
|
+
export function useRelayClient<
|
|
162
|
+
chains extends readonly [Chains.Chain, ...Chains.Chain[]],
|
|
163
|
+
>(
|
|
164
|
+
porto: Pick<Remote.Porto<chains>, '_internal'>,
|
|
165
|
+
parameters: useRelayClient.Parameters = {},
|
|
166
|
+
) {
|
|
167
|
+
const defaultChainId = useChain(porto)?.id
|
|
168
|
+
const chainId = parameters.chainId ?? defaultChainId
|
|
169
|
+
return RelayClient.fromPorto(porto, { chainId })
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export namespace useRelayClient {
|
|
173
|
+
export type Parameters = {
|
|
174
|
+
chainId?: number | undefined
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Hook to access and subscribe to the wallet client of the Porto instance.
|
|
180
|
+
*
|
|
181
|
+
* @param porto - Porto instance.
|
|
182
|
+
* @returns Wallet Client.
|
|
183
|
+
*/
|
|
184
|
+
export function useWalletClient<
|
|
185
|
+
chains extends readonly [Chains.Chain, ...Chains.Chain[]],
|
|
186
|
+
>(porto: Pick<Remote.Porto<chains>, '_internal' | 'provider'>) {
|
|
187
|
+
return useMemo(() => WalletClient.fromPorto(porto), [porto])
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export namespace useWalletClient {
|
|
191
|
+
export type Parameters = {
|
|
192
|
+
chainId?: number | undefined
|
|
193
|
+
}
|
|
194
|
+
}
|