rise-wallet 0.1.4-beta.2 → 0.2.29-beta.1
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 +56 -34
- package/dist/cli/Dialog.d.ts +35 -0
- package/dist/cli/Dialog.d.ts.map +1 -0
- package/dist/cli/Dialog.js +60 -0
- package/dist/cli/Dialog.js.map +1 -0
- package/dist/cli/Messenger.d.ts +8 -0
- package/dist/cli/Messenger.d.ts.map +1 -0
- package/dist/cli/Messenger.js +123 -0
- package/dist/cli/Messenger.js.map +1 -0
- package/dist/cli/bin/commands-BWkYsY2L.js +50 -0
- package/dist/cli/bin/index.js +9 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +3 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/internal/commands.d.ts +13 -0
- package/dist/cli/internal/commands.d.ts.map +1 -0
- package/dist/cli/internal/commands.js +180 -0
- package/dist/cli/internal/commands.js.map +1 -0
- package/dist/cli/internal/context.d.ts +521 -0
- package/dist/cli/internal/context.d.ts.map +1 -0
- package/dist/cli/internal/context.js +38 -0
- package/dist/cli/internal/context.js.map +1 -0
- package/dist/cli/internal/http.d.ts +7 -0
- package/dist/cli/internal/http.d.ts.map +1 -0
- package/dist/cli/internal/http.js +17 -0
- package/dist/cli/internal/http.js.map +1 -0
- package/dist/cli/internal/utils.d.ts +7 -0
- package/dist/cli/internal/utils.d.ts.map +1 -0
- package/dist/cli/internal/utils.js +24 -0
- package/dist/cli/internal/utils.js.map +1 -0
- package/dist/core/Chains.d.ts +211 -0
- package/dist/core/Chains.d.ts.map +1 -0
- package/dist/core/Chains.js +20 -0
- package/dist/core/Chains.js.map +1 -0
- package/dist/core/Dialog.d.ts +308 -0
- package/dist/core/Dialog.d.ts.map +1 -0
- package/dist/core/Dialog.js +809 -0
- package/dist/core/Dialog.js.map +1 -0
- package/dist/core/Messenger.d.ts +165 -0
- package/dist/core/Messenger.d.ts.map +1 -0
- package/dist/core/Messenger.js +207 -0
- package/dist/core/Messenger.js.map +1 -0
- package/dist/core/Mode.d.ts +5 -0
- package/dist/core/Mode.d.ts.map +1 -0
- package/dist/core/Mode.js +5 -0
- package/dist/core/Mode.js.map +1 -0
- package/dist/core/Porto.d.ts +1609 -0
- package/dist/core/Porto.d.ts.map +1 -0
- package/dist/core/Porto.js +105 -0
- package/dist/core/Porto.js.map +1 -0
- package/dist/core/RpcSchema.d.ts +82 -0
- package/dist/core/RpcSchema.d.ts.map +1 -0
- package/dist/core/RpcSchema.js +2 -0
- package/dist/core/RpcSchema.js.map +1 -0
- package/dist/core/Storage.d.ts +15 -0
- package/dist/core/Storage.d.ts.map +1 -0
- package/dist/core/Storage.js +109 -0
- package/dist/core/Storage.js.map +1 -0
- package/dist/core/Transport.d.ts +23 -0
- package/dist/core/Transport.d.ts.map +1 -0
- package/dist/core/Transport.js +37 -0
- package/dist/core/Transport.js.map +1 -0
- package/dist/core/internal/_generated/chains.d.ts +2 -0
- package/dist/core/internal/_generated/chains.d.ts.map +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/EIP7702Proxy.d.ts +18 -0
- package/dist/core/internal/_generated/contracts/EIP7702Proxy.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/EIP7702Proxy.js +24 -0
- package/dist/core/internal/_generated/contracts/EIP7702Proxy.js.map +1 -0
- package/dist/core/internal/_generated/contracts/Escrow.d.ts +256 -0
- package/dist/core/internal/_generated/contracts/Escrow.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/Escrow.js +329 -0
- package/dist/core/internal/_generated/contracts/Escrow.js.map +1 -0
- package/dist/core/internal/_generated/contracts/ExperimentERC20.d.ts +440 -0
- package/dist/core/internal/_generated/contracts/ExperimentERC20.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/ExperimentERC20.js +568 -0
- package/dist/core/internal/_generated/contracts/ExperimentERC20.js.map +1 -0
- package/dist/core/internal/_generated/contracts/ExperimentERC721.d.ts +456 -0
- package/dist/core/internal/_generated/contracts/ExperimentERC721.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/ExperimentERC721.js +587 -0
- package/dist/core/internal/_generated/contracts/ExperimentERC721.js.map +1 -0
- package/dist/core/internal/_generated/contracts/GuardedExecutor.d.ts +482 -0
- package/dist/core/internal/_generated/contracts/GuardedExecutor.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/GuardedExecutor.js +622 -0
- package/dist/core/internal/_generated/contracts/GuardedExecutor.js.map +1 -0
- package/dist/core/internal/_generated/contracts/ICallChecker.d.ts +25 -0
- package/dist/core/internal/_generated/contracts/ICallChecker.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/ICallChecker.js +33 -0
- package/dist/core/internal/_generated/contracts/ICallChecker.js.map +1 -0
- package/dist/core/internal/_generated/contracts/ICommon.d.ts +3 -0
- package/dist/core/internal/_generated/contracts/ICommon.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/ICommon.js +3 -0
- package/dist/core/internal/_generated/contracts/ICommon.js.map +1 -0
- package/dist/core/internal/_generated/contracts/IEscrow.d.ts +88 -0
- package/dist/core/internal/_generated/contracts/IEscrow.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/IEscrow.js +113 -0
- package/dist/core/internal/_generated/contracts/IEscrow.js.map +1 -0
- package/dist/core/internal/_generated/contracts/IFunder.d.ts +61 -0
- package/dist/core/internal/_generated/contracts/IFunder.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/IFunder.js +79 -0
- package/dist/core/internal/_generated/contracts/IFunder.js.map +1 -0
- package/dist/core/internal/_generated/contracts/IFunderV4.d.ts +34 -0
- package/dist/core/internal/_generated/contracts/IFunderV4.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/IFunderV4.js +44 -0
- package/dist/core/internal/_generated/contracts/IFunderV4.js.map +1 -0
- package/dist/core/internal/_generated/contracts/IIthacaAccount.d.ts +81 -0
- package/dist/core/internal/_generated/contracts/IIthacaAccount.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/IIthacaAccount.js +106 -0
- package/dist/core/internal/_generated/contracts/IIthacaAccount.js.map +1 -0
- package/dist/core/internal/_generated/contracts/IOAppCore.d.ts +108 -0
- package/dist/core/internal/_generated/contracts/IOAppCore.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/IOAppCore.js +141 -0
- package/dist/core/internal/_generated/contracts/IOAppCore.js.map +1 -0
- package/dist/core/internal/_generated/contracts/IOAppMsgInspector.d.ts +33 -0
- package/dist/core/internal/_generated/contracts/IOAppMsgInspector.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/IOAppMsgInspector.js +44 -0
- package/dist/core/internal/_generated/contracts/IOAppMsgInspector.js.map +1 -0
- package/dist/core/internal/_generated/contracts/IOAppReceiver.d.ts +122 -0
- package/dist/core/internal/_generated/contracts/IOAppReceiver.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/IOAppReceiver.js +160 -0
- package/dist/core/internal/_generated/contracts/IOAppReceiver.js.map +1 -0
- package/dist/core/internal/_generated/contracts/IOrchestrator.d.ts +71 -0
- package/dist/core/internal/_generated/contracts/IOrchestrator.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/IOrchestrator.js +94 -0
- package/dist/core/internal/_generated/contracts/IOrchestrator.js.map +1 -0
- package/dist/core/internal/_generated/contracts/ISettler.d.ts +39 -0
- package/dist/core/internal/_generated/contracts/ISettler.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/ISettler.js +51 -0
- package/dist/core/internal/_generated/contracts/ISettler.js.map +1 -0
- package/dist/core/internal/_generated/contracts/ISigner.d.ts +25 -0
- package/dist/core/internal/_generated/contracts/ISigner.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/ISigner.js +33 -0
- package/dist/core/internal/_generated/contracts/ISigner.js.map +1 -0
- package/dist/core/internal/_generated/contracts/IthacaAccount.d.ts +1121 -0
- package/dist/core/internal/_generated/contracts/IthacaAccount.d.ts.map +1 -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/_generated/contracts/IthacaAccountNew.d.ts +1121 -0
- package/dist/core/internal/_generated/contracts/IthacaAccountNew.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/IthacaAccountNew.js +1453 -0
- package/dist/core/internal/_generated/contracts/IthacaAccountNew.js.map +1 -0
- package/dist/core/internal/_generated/contracts/IthacaAccountOld.d.ts +1121 -0
- package/dist/core/internal/_generated/contracts/IthacaAccountOld.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/IthacaAccountOld.js +1453 -0
- package/dist/core/internal/_generated/contracts/IthacaAccountOld.js.map +1 -0
- package/dist/core/internal/_generated/contracts/LayerZeroSettler.d.ts +621 -0
- package/dist/core/internal/_generated/contracts/LayerZeroSettler.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/LayerZeroSettler.js +810 -0
- package/dist/core/internal/_generated/contracts/LayerZeroSettler.js.map +1 -0
- package/dist/core/internal/_generated/contracts/LibNonce.d.ts +11 -0
- package/dist/core/internal/_generated/contracts/LibNonce.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/LibNonce.js +14 -0
- package/dist/core/internal/_generated/contracts/LibNonce.js.map +1 -0
- package/dist/core/internal/_generated/contracts/LibTStack.d.ts +3 -0
- package/dist/core/internal/_generated/contracts/LibTStack.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/LibTStack.js +3 -0
- package/dist/core/internal/_generated/contracts/LibTStack.js.map +1 -0
- package/dist/core/internal/_generated/contracts/MultiSigSigner.d.ts +157 -0
- package/dist/core/internal/_generated/contracts/MultiSigSigner.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/MultiSigSigner.js +202 -0
- package/dist/core/internal/_generated/contracts/MultiSigSigner.js.map +1 -0
- package/dist/core/internal/_generated/contracts/OApp.d.ts +314 -0
- package/dist/core/internal/_generated/contracts/OApp.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/OApp.js +411 -0
- package/dist/core/internal/_generated/contracts/OApp.js.map +1 -0
- package/dist/core/internal/_generated/contracts/OAppCore.d.ts +175 -0
- package/dist/core/internal/_generated/contracts/OAppCore.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/OAppCore.js +228 -0
- package/dist/core/internal/_generated/contracts/OAppCore.js.map +1 -0
- package/dist/core/internal/_generated/contracts/OAppReceiver.d.ts +302 -0
- package/dist/core/internal/_generated/contracts/OAppReceiver.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/OAppReceiver.js +395 -0
- package/dist/core/internal/_generated/contracts/OAppReceiver.js.map +1 -0
- package/dist/core/internal/_generated/contracts/OAppSender.d.ts +187 -0
- package/dist/core/internal/_generated/contracts/OAppSender.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/OAppSender.js +244 -0
- package/dist/core/internal/_generated/contracts/OAppSender.js.map +1 -0
- package/dist/core/internal/_generated/contracts/Orchestrator.d.ts +302 -0
- package/dist/core/internal/_generated/contracts/Orchestrator.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/Orchestrator.js +389 -0
- package/dist/core/internal/_generated/contracts/Orchestrator.js.map +1 -0
- package/dist/core/internal/_generated/contracts/SimpleFunder.d.ts +413 -0
- package/dist/core/internal/_generated/contracts/SimpleFunder.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/SimpleFunder.js +533 -0
- package/dist/core/internal/_generated/contracts/SimpleFunder.js.map +1 -0
- package/dist/core/internal/_generated/contracts/SimpleSettler.d.ts +280 -0
- package/dist/core/internal/_generated/contracts/SimpleSettler.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/SimpleSettler.js +359 -0
- package/dist/core/internal/_generated/contracts/SimpleSettler.js.map +1 -0
- package/dist/core/internal/_generated/contracts/Simulator.d.ts +131 -0
- package/dist/core/internal/_generated/contracts/Simulator.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/Simulator.js +169 -0
- package/dist/core/internal/_generated/contracts/Simulator.js.map +1 -0
- package/dist/core/internal/_generated/contracts/TokenTransferLib.d.ts +3 -0
- package/dist/core/internal/_generated/contracts/TokenTransferLib.d.ts.map +1 -0
- package/dist/core/internal/_generated/contracts/TokenTransferLib.js +3 -0
- package/dist/core/internal/_generated/contracts/TokenTransferLib.js.map +1 -0
- package/dist/core/internal/call.d.ts +164 -0
- package/dist/core/internal/call.d.ts.map +1 -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 +18 -0
- package/dist/core/internal/erc8010.d.ts.map +1 -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 +2 -0
- package/dist/core/internal/intersectionObserver.d.ts.map +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 +22 -0
- package/dist/core/internal/logger.d.ts.map +1 -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 +345 -0
- package/dist/core/internal/mode.d.ts.map +1 -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 +800 -0
- package/dist/core/internal/modes/dialog.d.ts.map +1 -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 +1402 -0
- package/dist/core/internal/modes/reactNative.d.ts.map +1 -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 +685 -0
- package/dist/core/internal/modes/relay.d.ts.map +1 -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 +60 -0
- package/dist/core/internal/permissions.d.ts.map +1 -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 +72 -0
- package/dist/core/internal/permissionsRequest.d.ts.map +1 -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 +14 -0
- package/dist/core/internal/porto.d.ts.map +1 -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 +9 -0
- package/dist/core/internal/promise.d.ts.map +1 -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 +30 -0
- package/dist/core/internal/provider.d.ts.map +1 -0
- package/dist/core/internal/provider.js +944 -0
- package/dist/core/internal/provider.js.map +1 -0
- package/dist/core/internal/relay/rpcSchema.d.ts +76 -0
- package/dist/core/internal/relay/rpcSchema.d.ts.map +1 -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 +165 -0
- package/dist/core/internal/relay/schema/capabilities.d.ts.map +1 -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 +168 -0
- package/dist/core/internal/relay/schema/intent.d.ts.map +1 -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 +44 -0
- package/dist/core/internal/relay/schema/key.d.ts.map +1 -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 +40 -0
- package/dist/core/internal/relay/schema/permission.d.ts.map +1 -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 +63 -0
- package/dist/core/internal/relay/schema/preCall.d.ts.map +1 -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 +370 -0
- package/dist/core/internal/relay/schema/quotes.d.ts.map +1 -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 +1529 -0
- package/dist/core/internal/relay/schema/rpc.d.ts.map +1 -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 +14 -0
- package/dist/core/internal/relay/schema/token.d.ts.map +1 -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 +19 -0
- package/dist/core/internal/requiredFunds.d.ts.map +1 -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 +314 -0
- package/dist/core/internal/schema/capabilities.d.ts.map +1 -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 +165 -0
- package/dist/core/internal/schema/key.d.ts.map +1 -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 +103 -0
- package/dist/core/internal/schema/permissions.d.ts.map +1 -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 +938 -0
- package/dist/core/internal/schema/request.d.ts.map +1 -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 +3315 -0
- package/dist/core/internal/schema/rpc.d.ts.map +1 -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 +2 -0
- package/dist/core/internal/schema/token.d.ts.map +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 +19 -0
- package/dist/core/internal/schema/utils.d.ts.map +1 -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 +33 -0
- package/dist/core/internal/siwe.d.ts.map +1 -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 +3 -0
- package/dist/core/internal/store.d.ts.map +1 -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 +58 -0
- package/dist/core/internal/tokens.d.ts.map +1 -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 +299 -0
- package/dist/core/internal/types.d.ts.map +1 -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 +2 -0
- package/dist/core/internal/urlString.d.ts.map +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 +11 -0
- package/dist/core/internal/userAgent.d.ts.map +1 -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 +25 -0
- package/dist/core/internal/utils.d.ts.map +1 -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 +1481 -0
- package/dist/core/react-native/Porto.d.ts.map +1 -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 +10 -0
- package/dist/core/react-native/configure.d.ts.map +1 -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 +27 -0
- package/dist/core/react-native/environment.d.ts.map +1 -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 +5 -0
- package/dist/core/react-native/index.d.ts.map +1 -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 +2 -0
- package/dist/core/react-native/utils.d.ts.map +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 +17 -2
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -2
- package/dist/index.js.map +1 -0
- package/dist/index.native.d.ts +8 -0
- package/dist/index.native.d.ts.map +1 -0
- package/dist/index.native.js +12 -0
- package/dist/index.native.js.map +1 -0
- package/dist/internal/index.d.ts +4 -0
- package/dist/internal/index.d.ts.map +1 -0
- package/dist/internal/index.js +4 -0
- package/dist/internal/index.js.map +1 -0
- package/dist/react-native/crypto.d.ts +2 -0
- package/dist/react-native/crypto.d.ts.map +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 +8 -0
- package/dist/react-native/index.d.ts.map +1 -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 +3 -0
- package/dist/react-native/register.d.ts.map +1 -0
- package/dist/react-native/register.js +15 -0
- package/dist/react-native/register.js.map +1 -0
- package/dist/register/index.d.ts +15 -0
- package/dist/register/index.d.ts.map +1 -0
- package/dist/register/index.js +2 -0
- package/dist/register/index.js.map +1 -0
- package/dist/remote/Actions.d.ts +34 -0
- package/dist/remote/Actions.d.ts.map +1 -0
- package/dist/remote/Actions.js +76 -0
- package/dist/remote/Actions.js.map +1 -0
- package/dist/remote/Events.d.ts +47 -0
- package/dist/remote/Events.d.ts.map +1 -0
- package/dist/remote/Events.js +132 -0
- package/dist/remote/Events.js.map +1 -0
- package/dist/remote/Hooks.d.ts +3801 -0
- package/dist/remote/Hooks.d.ts.map +1 -0
- package/dist/remote/Hooks.js +106 -0
- package/dist/remote/Hooks.js.map +1 -0
- package/dist/remote/Porto.d.ts +858 -0
- package/dist/remote/Porto.d.ts.map +1 -0
- package/dist/remote/Porto.js +66 -0
- package/dist/remote/Porto.js.map +1 -0
- package/dist/remote/index.d.ts +5 -0
- package/dist/remote/index.d.ts.map +1 -0
- package/dist/remote/index.js +5 -0
- package/dist/remote/index.js.map +1 -0
- package/dist/remote/internal/methodPolicies.d.ts +97 -0
- package/dist/remote/internal/methodPolicies.d.ts.map +1 -0
- package/dist/remote/internal/methodPolicies.js +102 -0
- package/dist/remote/internal/methodPolicies.js.map +1 -0
- package/dist/server/Route.d.ts +88 -0
- package/dist/server/Route.d.ts.map +1 -0
- package/dist/server/Route.js +189 -0
- package/dist/server/Route.js.map +1 -0
- package/dist/server/Router.d.ts +24 -0
- package/dist/server/Router.d.ts.map +1 -0
- package/dist/server/Router.js +29 -0
- package/dist/server/Router.js.map +1 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +3 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/internal/merchantSchema.d.ts +65 -0
- package/dist/server/internal/merchantSchema.d.ts.map +1 -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 +124 -0
- package/dist/server/internal/requestListener.d.ts.map +1 -0
- package/dist/server/internal/requestListener.js +172 -0
- package/dist/server/internal/requestListener.js.map +1 -0
- package/dist/theme/Theme.d.ts +122 -0
- package/dist/theme/Theme.d.ts.map +1 -0
- package/dist/theme/Theme.js +18 -0
- package/dist/theme/Theme.js.map +1 -0
- package/dist/theme/index.d.ts +3 -0
- package/dist/theme/index.d.ts.map +1 -0
- package/dist/theme/index.js +2 -0
- package/dist/theme/index.js.map +1 -0
- package/dist/trusted-hosts.d.ts +2 -0
- package/dist/trusted-hosts.d.ts.map +1 -0
- package/dist/trusted-hosts.js +44 -0
- package/dist/trusted-hosts.js.map +1 -0
- package/dist/tsconfig.tmp.tsbuildinfo +1 -0
- package/dist/viem/Account.d.ts +111 -0
- package/dist/viem/Account.d.ts.map +1 -0
- package/dist/viem/Account.js +132 -0
- package/dist/viem/Account.js.map +1 -0
- package/dist/viem/AccountActions.d.ts +11 -0
- package/dist/viem/AccountActions.d.ts.map +1 -0
- package/dist/viem/AccountActions.js +14 -0
- package/dist/viem/AccountActions.js.map +1 -0
- package/dist/viem/CapabilitiesSchema.d.ts +15 -0
- package/dist/viem/CapabilitiesSchema.d.ts.map +1 -0
- package/dist/viem/CapabilitiesSchema.js +2 -0
- package/dist/viem/CapabilitiesSchema.js.map +1 -0
- package/dist/viem/ContractActions.d.ts +209 -0
- package/dist/viem/ContractActions.d.ts.map +1 -0
- package/dist/viem/ContractActions.js +350 -0
- package/dist/viem/ContractActions.js.map +1 -0
- package/dist/viem/Key.d.ts +1156 -0
- package/dist/viem/Key.d.ts.map +1 -0
- package/dist/viem/Key.js +924 -0
- package/dist/viem/Key.js.map +1 -0
- package/dist/viem/RelayActions.d.ts +436 -0
- package/dist/viem/RelayActions.d.ts.map +1 -0
- package/dist/viem/RelayActions.js +385 -0
- package/dist/viem/RelayActions.js.map +1 -0
- package/dist/viem/RelayClient.d.ts +27 -0
- package/dist/viem/RelayClient.d.ts.map +1 -0
- package/dist/viem/RelayClient.js +44 -0
- package/dist/viem/RelayClient.js.map +1 -0
- package/dist/viem/RpcSchema.d.ts +23 -0
- package/dist/viem/RpcSchema.d.ts.map +1 -0
- package/dist/viem/RpcSchema.js +2 -0
- package/dist/viem/RpcSchema.js.map +1 -0
- package/dist/viem/WalletActions.d.ts +87 -0
- package/dist/viem/WalletActions.d.ts.map +1 -0
- package/dist/viem/WalletActions.js +220 -0
- package/dist/viem/WalletActions.js.map +1 -0
- package/dist/viem/WalletClient.d.ts +21 -0
- package/dist/viem/WalletClient.d.ts.map +1 -0
- package/dist/viem/WalletClient.js +23 -0
- package/dist/viem/WalletClient.js.map +1 -0
- package/dist/viem/index.d.ts +14 -0
- package/dist/viem/index.d.ts.map +1 -0
- package/dist/viem/index.js +12 -0
- package/dist/viem/index.js.map +1 -0
- package/dist/viem/internal/relayActions.d.ts +365 -0
- package/dist/viem/internal/relayActions.d.ts.map +1 -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 +16 -0
- package/dist/viem/internal/utils.d.ts.map +1 -0
- package/dist/viem/internal/utils.js +2 -0
- package/dist/viem/internal/utils.js.map +1 -0
- package/dist/wagmi/Actions.d.ts +2 -0
- package/dist/wagmi/Actions.d.ts.map +1 -0
- package/dist/wagmi/Actions.js +2 -0
- package/dist/wagmi/Actions.js.map +1 -0
- package/dist/wagmi/Connector.d.ts +28 -0
- package/dist/wagmi/Connector.d.ts.map +1 -0
- package/dist/wagmi/Connector.js +238 -0
- package/dist/wagmi/Connector.js.map +1 -0
- package/dist/wagmi/Hooks.d.ts +2 -0
- package/dist/wagmi/Hooks.d.ts.map +1 -0
- package/dist/wagmi/Hooks.js +2 -0
- package/dist/wagmi/Hooks.js.map +1 -0
- package/dist/wagmi/Hooks.native.d.ts +3 -0
- package/dist/wagmi/Hooks.native.d.ts.map +1 -0
- package/dist/wagmi/Hooks.native.js +3 -0
- package/dist/wagmi/Hooks.native.js.map +1 -0
- package/dist/wagmi/Query.d.ts +2 -0
- package/dist/wagmi/Query.d.ts.map +1 -0
- package/dist/wagmi/Query.js +2 -0
- package/dist/wagmi/Query.js.map +1 -0
- package/dist/wagmi/index.d.ts +5 -0
- package/dist/wagmi/index.d.ts.map +1 -0
- package/dist/wagmi/index.js +5 -0
- package/dist/wagmi/index.js.map +1 -0
- package/dist/wagmi/index.native.d.ts +6 -0
- package/dist/wagmi/index.native.d.ts.map +1 -0
- package/dist/wagmi/index.native.js +6 -0
- package/dist/wagmi/index.native.js.map +1 -0
- package/dist/wagmi/internal/core.d.ts +84 -0
- package/dist/wagmi/internal/core.d.ts.map +1 -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 +33 -0
- package/dist/wagmi/internal/query.d.ts.map +1 -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 +91 -0
- package/dist/wagmi/internal/react.d.ts.map +1 -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 +11 -0
- package/dist/wagmi/internal/types.d.ts.map +1 -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 +2 -0
- package/dist/wagmi/internal/utils.d.ts.map +1 -0
- package/dist/wagmi/internal/utils.js +18 -0
- package/dist/wagmi/internal/utils.js.map +1 -0
- package/package.json +287 -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 +216 -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 +4 -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 +1278 -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.native.ts +15 -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 +43 -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 +306 -0
- package/src/wagmi/Hooks.native.ts +16 -0
- package/src/wagmi/Hooks.ts +14 -0
- package/src/wagmi/Query.ts +5 -0
- package/src/wagmi/index.native.ts +6 -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
package/src/viem/Key.ts
ADDED
|
@@ -0,0 +1,1318 @@
|
|
|
1
|
+
import * as AbiFunction from 'ox/AbiFunction'
|
|
2
|
+
import * as AbiParameters from 'ox/AbiParameters'
|
|
3
|
+
import * as Address from 'ox/Address'
|
|
4
|
+
import * as Bytes from 'ox/Bytes'
|
|
5
|
+
import * as Hash from 'ox/Hash'
|
|
6
|
+
import * as Hex from 'ox/Hex'
|
|
7
|
+
import * as Json from 'ox/Json'
|
|
8
|
+
import * as P256 from 'ox/P256'
|
|
9
|
+
import * as PublicKey from 'ox/PublicKey'
|
|
10
|
+
import * as Secp256k1 from 'ox/Secp256k1'
|
|
11
|
+
import * as Signature from 'ox/Signature'
|
|
12
|
+
import * as TypedData from 'ox/TypedData'
|
|
13
|
+
import * as Value from 'ox/Value'
|
|
14
|
+
import * as WebAuthnP256 from 'ox/WebAuthnP256'
|
|
15
|
+
import * as WebCryptoP256 from 'ox/WebCryptoP256'
|
|
16
|
+
import { zeroAddress } from 'viem'
|
|
17
|
+
import * as Call from '../core/internal/call.js'
|
|
18
|
+
import type * as RelayKey_schema from '../core/internal/relay/schema/key.js'
|
|
19
|
+
import type * as RelayPermission_schema from '../core/internal/relay/schema/permission.js'
|
|
20
|
+
import type * as Key_schema from '../core/internal/schema/key.js'
|
|
21
|
+
import type * as Tokens from '../core/internal/tokens.js'
|
|
22
|
+
import type {
|
|
23
|
+
Compute,
|
|
24
|
+
ExactPartial,
|
|
25
|
+
Mutable,
|
|
26
|
+
OneOf,
|
|
27
|
+
PartialBy,
|
|
28
|
+
RequiredBy,
|
|
29
|
+
UnionOmit,
|
|
30
|
+
UnionRequiredBy,
|
|
31
|
+
} from '../core/internal/types.js'
|
|
32
|
+
import type * as Storage from '../core/Storage.js'
|
|
33
|
+
|
|
34
|
+
type PrivateKeyFn = () => Hex.Hex
|
|
35
|
+
|
|
36
|
+
export type BaseKey<
|
|
37
|
+
type extends string = string,
|
|
38
|
+
privateKey = unknown,
|
|
39
|
+
> = Compute<
|
|
40
|
+
Key_schema.WithPermissions & {
|
|
41
|
+
/** Whether the key will need its digest (SHA256) prehashed when signing. */
|
|
42
|
+
prehash?: boolean | undefined
|
|
43
|
+
/** Private key. */
|
|
44
|
+
privateKey?: privateKey | undefined
|
|
45
|
+
/** Key type. */
|
|
46
|
+
type: type
|
|
47
|
+
}
|
|
48
|
+
>
|
|
49
|
+
|
|
50
|
+
export type Key = OneOf<
|
|
51
|
+
AddressKey | P256Key | Secp256k1Key | WebCryptoKey | WebAuthnKey
|
|
52
|
+
>
|
|
53
|
+
export type AddressKey = BaseKey<'address'>
|
|
54
|
+
export type P256Key = BaseKey<'p256', PrivateKeyFn>
|
|
55
|
+
export type Secp256k1Key = BaseKey<'secp256k1', PrivateKeyFn>
|
|
56
|
+
export type WebCryptoKey = BaseKey<'p256', CryptoKey>
|
|
57
|
+
export type WebAuthnKey = BaseKey<
|
|
58
|
+
'webauthn-p256',
|
|
59
|
+
OneOf<
|
|
60
|
+
| {
|
|
61
|
+
credential: Pick<WebAuthnP256.P256Credential, 'id' | 'publicKey'>
|
|
62
|
+
rpId: string | undefined
|
|
63
|
+
}
|
|
64
|
+
| {
|
|
65
|
+
privateKey: PrivateKeyFn
|
|
66
|
+
}
|
|
67
|
+
>
|
|
68
|
+
>
|
|
69
|
+
|
|
70
|
+
export type Permissions = Key_schema.Permissions
|
|
71
|
+
|
|
72
|
+
/** RPC (relay-compatible) format of a key. */
|
|
73
|
+
export type Relay = RelayKey_schema.WithPermissions
|
|
74
|
+
|
|
75
|
+
/** Serialized (contract-compatible) format of a key. */
|
|
76
|
+
export type Serialized = {
|
|
77
|
+
expiry: number
|
|
78
|
+
isSuperAdmin: boolean
|
|
79
|
+
keyType: number
|
|
80
|
+
publicKey: Hex.Hex
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export type SpendPermissions = Key_schema.SpendPermissions
|
|
84
|
+
export type SpendPermission = SpendPermissions[number]
|
|
85
|
+
|
|
86
|
+
/** Relay key type to key type mapping. */
|
|
87
|
+
export const fromRelayKeyType = {
|
|
88
|
+
p256: 'p256',
|
|
89
|
+
secp256k1: 'secp256k1',
|
|
90
|
+
webauthnp256: 'webauthn-p256',
|
|
91
|
+
} as const
|
|
92
|
+
|
|
93
|
+
/** Relay key role to key role mapping. */
|
|
94
|
+
export const fromRelayKeyRole = {
|
|
95
|
+
admin: 'admin',
|
|
96
|
+
normal: 'session',
|
|
97
|
+
} as const
|
|
98
|
+
|
|
99
|
+
/** Serialized (contract-compatible) key type to key type mapping. */
|
|
100
|
+
export const fromSerializedKeyType = {
|
|
101
|
+
0: 'p256',
|
|
102
|
+
1: 'webauthn-p256',
|
|
103
|
+
2: 'secp256k1',
|
|
104
|
+
} as const
|
|
105
|
+
|
|
106
|
+
/** Serialized (contract-compatible) spend period to period mapping. */
|
|
107
|
+
export const fromSerializedSpendPeriod = {
|
|
108
|
+
0: 'minute',
|
|
109
|
+
1: 'hour',
|
|
110
|
+
2: 'day',
|
|
111
|
+
3: 'week',
|
|
112
|
+
4: 'month',
|
|
113
|
+
5: 'year',
|
|
114
|
+
} as const
|
|
115
|
+
|
|
116
|
+
/** Key type to Relay key type mapping. */
|
|
117
|
+
export const toRelayKeyType = {
|
|
118
|
+
address: 'secp256k1',
|
|
119
|
+
p256: 'p256',
|
|
120
|
+
secp256k1: 'secp256k1',
|
|
121
|
+
'webauthn-p256': 'webauthnp256',
|
|
122
|
+
} as const
|
|
123
|
+
|
|
124
|
+
/** Key role to Relay key role mapping. */
|
|
125
|
+
export const toRelayKeyRole = {
|
|
126
|
+
admin: 'admin',
|
|
127
|
+
session: 'normal',
|
|
128
|
+
} as const
|
|
129
|
+
|
|
130
|
+
/** Key type to serialized (contract-compatible) key type mapping. */
|
|
131
|
+
export const toSerializedKeyType = {
|
|
132
|
+
address: 2,
|
|
133
|
+
p256: 0,
|
|
134
|
+
secp256k1: 2,
|
|
135
|
+
'webauthn-p256': 1,
|
|
136
|
+
} as const
|
|
137
|
+
|
|
138
|
+
/** Period to serialized (contract-compatible) spend period mapping. */
|
|
139
|
+
export const toSerializedSpendPeriod = {
|
|
140
|
+
day: 2,
|
|
141
|
+
hour: 1,
|
|
142
|
+
minute: 0,
|
|
143
|
+
month: 4,
|
|
144
|
+
week: 3,
|
|
145
|
+
year: 5,
|
|
146
|
+
} as const
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Creates a random P256 key.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* import * as Key from './key.js'
|
|
154
|
+
*
|
|
155
|
+
* // Admin Key
|
|
156
|
+
* const key = Key.createP256()
|
|
157
|
+
*
|
|
158
|
+
* // Session Key
|
|
159
|
+
* const key = Key.createP256({
|
|
160
|
+
* expiry: 1714857600,
|
|
161
|
+
* role: 'session',
|
|
162
|
+
* })
|
|
163
|
+
* ```
|
|
164
|
+
*
|
|
165
|
+
* @param parameters - Key parameters.
|
|
166
|
+
* @returns P256 key.
|
|
167
|
+
*/
|
|
168
|
+
export function createP256(parameters: createP256.Parameters = {}) {
|
|
169
|
+
const privateKey = P256.randomPrivateKey()
|
|
170
|
+
return fromP256({
|
|
171
|
+
...parameters,
|
|
172
|
+
privateKey,
|
|
173
|
+
})
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export declare namespace createP256 {
|
|
177
|
+
type Parameters = Pick<
|
|
178
|
+
fromP256.Parameters,
|
|
179
|
+
'expiry' | 'feeToken' | 'permissions' | 'role'
|
|
180
|
+
>
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Creates a random Secp256k1 key.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```ts
|
|
188
|
+
* import * as Key from './key.js'
|
|
189
|
+
*
|
|
190
|
+
* // Admin Key
|
|
191
|
+
* const key = Key.createSecp256k1()
|
|
192
|
+
*
|
|
193
|
+
* // Session Key
|
|
194
|
+
* const key = Key.createSecp256k1({
|
|
195
|
+
* expiry: 1714857600,
|
|
196
|
+
* role: 'session',
|
|
197
|
+
* })
|
|
198
|
+
* ```
|
|
199
|
+
*
|
|
200
|
+
* @param parameters - Key parameters.
|
|
201
|
+
* @returns Secp256k1 key.
|
|
202
|
+
*/
|
|
203
|
+
export function createSecp256k1(parameters: createSecp256k1.Parameters = {}) {
|
|
204
|
+
const privateKey = Secp256k1.randomPrivateKey()
|
|
205
|
+
return fromSecp256k1({
|
|
206
|
+
...parameters,
|
|
207
|
+
privateKey,
|
|
208
|
+
})
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export declare namespace createSecp256k1 {
|
|
212
|
+
type Parameters = Pick<
|
|
213
|
+
fromSecp256k1.Parameters,
|
|
214
|
+
'expiry' | 'feeToken' | 'permissions' | 'role'
|
|
215
|
+
>
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Creates a WebAuthnP256 key.
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```ts
|
|
223
|
+
* import { Bytes } from 'ox'
|
|
224
|
+
* import * as Key from './key.js'
|
|
225
|
+
*
|
|
226
|
+
* // Admin Key
|
|
227
|
+
* const key = Key.createWebAuthnP256({
|
|
228
|
+
* label: 'My Key',
|
|
229
|
+
* userId: Bytes.from('0x0000000000000000000000000000000000000000'),
|
|
230
|
+
* })
|
|
231
|
+
*
|
|
232
|
+
* // Session Key
|
|
233
|
+
* const key = Key.createWebAuthnP256({
|
|
234
|
+
* expiry: 1714857600,
|
|
235
|
+
* label: 'My Key',
|
|
236
|
+
* role: 'session',
|
|
237
|
+
* userId: Bytes.from('0x0000000000000000000000000000000000000000'),
|
|
238
|
+
* })
|
|
239
|
+
* ```
|
|
240
|
+
*
|
|
241
|
+
* @param parameters - Key parameters.
|
|
242
|
+
* @returns WebAuthnP256 key.
|
|
243
|
+
*/
|
|
244
|
+
export async function createWebAuthnP256(
|
|
245
|
+
parameters: createWebAuthnP256.Parameters,
|
|
246
|
+
) {
|
|
247
|
+
const { createFn, label, rpId, userId } = parameters
|
|
248
|
+
|
|
249
|
+
const credential = await WebAuthnP256.createCredential({
|
|
250
|
+
authenticatorSelection: {
|
|
251
|
+
requireResidentKey: true,
|
|
252
|
+
residentKey: 'required',
|
|
253
|
+
userVerification: 'required',
|
|
254
|
+
},
|
|
255
|
+
createFn,
|
|
256
|
+
extensions: {
|
|
257
|
+
credProps: true,
|
|
258
|
+
},
|
|
259
|
+
rp: rpId
|
|
260
|
+
? {
|
|
261
|
+
id: rpId,
|
|
262
|
+
name: rpId,
|
|
263
|
+
}
|
|
264
|
+
: undefined,
|
|
265
|
+
user: {
|
|
266
|
+
displayName: label,
|
|
267
|
+
id: new Uint8Array(userId ?? Bytes.fromString(label)),
|
|
268
|
+
name: label,
|
|
269
|
+
},
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
return fromWebAuthnP256({
|
|
273
|
+
...parameters,
|
|
274
|
+
credential: {
|
|
275
|
+
id: credential.id,
|
|
276
|
+
publicKey: credential.publicKey,
|
|
277
|
+
},
|
|
278
|
+
id: userId
|
|
279
|
+
? Bytes.toHex(userId)
|
|
280
|
+
: PublicKey.toHex(credential.publicKey, {
|
|
281
|
+
includePrefix: false,
|
|
282
|
+
}),
|
|
283
|
+
})
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export declare namespace createWebAuthnP256 {
|
|
287
|
+
type Parameters = Pick<
|
|
288
|
+
fromWebAuthnP256.Parameters,
|
|
289
|
+
'expiry' | 'feeToken' | 'permissions' | 'role'
|
|
290
|
+
> & {
|
|
291
|
+
/**
|
|
292
|
+
* Credential creation function. Useful for environments that do not support
|
|
293
|
+
* the WebAuthn API natively (i.e. React Native or testing environments).
|
|
294
|
+
*
|
|
295
|
+
* @default window.navigator.credentials.create
|
|
296
|
+
*/
|
|
297
|
+
createFn?: WebAuthnP256.createCredential.Options['createFn'] | undefined
|
|
298
|
+
/** Label. */
|
|
299
|
+
label: string
|
|
300
|
+
/** Relying Party ID. */
|
|
301
|
+
rpId?: string | undefined
|
|
302
|
+
/** User ID. */
|
|
303
|
+
userId?: Bytes.Bytes | undefined
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Creates a random WebAuthn-wrapped P256 key.
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* ```ts
|
|
312
|
+
* import * as Key from './key.js'
|
|
313
|
+
*
|
|
314
|
+
* // Admin Key
|
|
315
|
+
* const key = Key.createHeadlessWebAuthnP256()
|
|
316
|
+
*
|
|
317
|
+
* // Session Key
|
|
318
|
+
* const key = Key.createHeadlessWebAuthnP256({
|
|
319
|
+
* expiry: 1714857600,
|
|
320
|
+
* role: 'session',
|
|
321
|
+
* })
|
|
322
|
+
* ```
|
|
323
|
+
*
|
|
324
|
+
* @param parameters - Key parameters.
|
|
325
|
+
* @returns P256 key.
|
|
326
|
+
*/
|
|
327
|
+
export function createHeadlessWebAuthnP256(
|
|
328
|
+
parameters: createHeadlessWebAuthnP256.Parameters = {},
|
|
329
|
+
) {
|
|
330
|
+
const privateKey = P256.randomPrivateKey()
|
|
331
|
+
return fromHeadlessWebAuthnP256({
|
|
332
|
+
...parameters,
|
|
333
|
+
privateKey,
|
|
334
|
+
})
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export declare namespace createHeadlessWebAuthnP256 {
|
|
338
|
+
type Parameters = Pick<
|
|
339
|
+
fromHeadlessWebAuthnP256.Parameters,
|
|
340
|
+
'expiry' | 'feeToken' | 'permissions' | 'role'
|
|
341
|
+
>
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Creates a random WebCryptoP256 key.
|
|
346
|
+
*
|
|
347
|
+
* @example
|
|
348
|
+
* ```ts
|
|
349
|
+
* import * as Key from './key.js'
|
|
350
|
+
*
|
|
351
|
+
* // Admin Key
|
|
352
|
+
* const key = Key.createWebCryptoP256()
|
|
353
|
+
*
|
|
354
|
+
* // Session Key
|
|
355
|
+
* const key = Key.createWebCryptoP256({
|
|
356
|
+
* expiry: 1714857600,
|
|
357
|
+
* role: 'session',
|
|
358
|
+
* })
|
|
359
|
+
* ```
|
|
360
|
+
*
|
|
361
|
+
* @param parameters - Key parameters.
|
|
362
|
+
* @returns WebCryptoP256 key.
|
|
363
|
+
*/
|
|
364
|
+
export async function createWebCryptoP256(
|
|
365
|
+
parameters: createWebCryptoP256.Parameters = {},
|
|
366
|
+
) {
|
|
367
|
+
const keyPair = await WebCryptoP256.createKeyPair()
|
|
368
|
+
return fromWebCryptoP256({
|
|
369
|
+
...parameters,
|
|
370
|
+
keyPair,
|
|
371
|
+
})
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export declare namespace createWebCryptoP256 {
|
|
375
|
+
type Parameters = Pick<
|
|
376
|
+
fromWebCryptoP256.Parameters,
|
|
377
|
+
'expiry' | 'feeToken' | 'permissions' | 'role'
|
|
378
|
+
>
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Deserializes a key from its serialized format.
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
385
|
+
* ```ts
|
|
386
|
+
* import * as Key from './key.js'
|
|
387
|
+
*
|
|
388
|
+
* const key = Key.deserialize({
|
|
389
|
+
* expiry: 0,
|
|
390
|
+
* isSuperAdmin: false,
|
|
391
|
+
* keyType: 0,
|
|
392
|
+
* publicKey: '0x04ec0effa5f2f378cbf7fd2fa7ca1e8dc51cf777c129fa1c00a0e9a9205f2e511ff3f20b34a4e0b50587d055c0e0fad33d32cf1147d3bb2538fbab0d15d8e65008',
|
|
393
|
+
* })
|
|
394
|
+
* ```
|
|
395
|
+
*
|
|
396
|
+
* @param serialized - Serialized key.
|
|
397
|
+
* @returns Key.
|
|
398
|
+
*/
|
|
399
|
+
export function deserialize(
|
|
400
|
+
serialized: Serialized,
|
|
401
|
+
options: deserialize.Options = {},
|
|
402
|
+
): Key {
|
|
403
|
+
const { chainId } = options
|
|
404
|
+
const publicKey = serialized.publicKey
|
|
405
|
+
const type = (fromSerializedKeyType as any)[serialized.keyType]
|
|
406
|
+
return from({
|
|
407
|
+
chainId,
|
|
408
|
+
expiry: serialized.expiry,
|
|
409
|
+
publicKey,
|
|
410
|
+
role: serialized.isSuperAdmin ? 'admin' : 'session',
|
|
411
|
+
type,
|
|
412
|
+
})
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
export declare namespace deserialize {
|
|
416
|
+
type Options = {
|
|
417
|
+
chainId?: number | undefined
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Instantiates a key from its parameters.
|
|
423
|
+
*
|
|
424
|
+
* @example
|
|
425
|
+
* ```ts
|
|
426
|
+
* import { P256 } from 'ox'
|
|
427
|
+
* import * as Key from './key.js'
|
|
428
|
+
*
|
|
429
|
+
* const privateKey = P256.randomPrivateKey()
|
|
430
|
+
* const publicKey = P256.getPublicKey({ privateKey })
|
|
431
|
+
*
|
|
432
|
+
* const key = Key.from({
|
|
433
|
+
* expiry: 0,
|
|
434
|
+
* publicKey,
|
|
435
|
+
* async sign({ payload }) {
|
|
436
|
+
* return P256.sign({ payload, privateKey })
|
|
437
|
+
* },
|
|
438
|
+
* type: 'p256',
|
|
439
|
+
* })
|
|
440
|
+
* ```
|
|
441
|
+
*
|
|
442
|
+
* @param key - Key.
|
|
443
|
+
* @returns Key.
|
|
444
|
+
*/
|
|
445
|
+
export function from<type extends Key['type']>(
|
|
446
|
+
key: from.Value<type>,
|
|
447
|
+
options: from.Options = {},
|
|
448
|
+
): Extract<Key, { type: type }> {
|
|
449
|
+
const { chainId = key.chainId } = options
|
|
450
|
+
const { expiry = 0, id, prehash = false, role = 'admin', type } = key
|
|
451
|
+
|
|
452
|
+
const publicKey = (() => {
|
|
453
|
+
const publicKey = key.publicKey
|
|
454
|
+
if (publicKey === '0x') return publicKey
|
|
455
|
+
if (type === 'secp256k1' || type === 'address') {
|
|
456
|
+
const isAddress =
|
|
457
|
+
Hex.size(publicKey) === 20 ||
|
|
458
|
+
Hex.toBigInt(Hex.slice(publicKey, 0, 12)) === 0n
|
|
459
|
+
const address = isAddress
|
|
460
|
+
? Hex.slice(publicKey, -20)
|
|
461
|
+
: Address.fromPublicKey(PublicKey.fromHex(publicKey))
|
|
462
|
+
return address
|
|
463
|
+
}
|
|
464
|
+
return publicKey
|
|
465
|
+
})()
|
|
466
|
+
|
|
467
|
+
return {
|
|
468
|
+
...key,
|
|
469
|
+
chainId,
|
|
470
|
+
expiry,
|
|
471
|
+
hash: hash({
|
|
472
|
+
publicKey,
|
|
473
|
+
type,
|
|
474
|
+
}),
|
|
475
|
+
id: (id ?? publicKey).toLowerCase() as Hex.Hex,
|
|
476
|
+
prehash,
|
|
477
|
+
publicKey: publicKey.toLowerCase() as Hex.Hex,
|
|
478
|
+
role,
|
|
479
|
+
type,
|
|
480
|
+
} satisfies BaseKey<string> as never
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
export declare namespace from {
|
|
484
|
+
type Value<type extends Key['type'] = Key['type']> = OneOf<
|
|
485
|
+
UnionRequiredBy<ExactPartial<UnionOmit<Key, 'hash'>>, 'publicKey'> & {
|
|
486
|
+
type: type | Key['type']
|
|
487
|
+
}
|
|
488
|
+
>
|
|
489
|
+
|
|
490
|
+
type Options = {
|
|
491
|
+
chainId?: number | undefined
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Instantiates a P256 key from its parameters.
|
|
497
|
+
*
|
|
498
|
+
* @example
|
|
499
|
+
* ```ts
|
|
500
|
+
* import { P256 } from 'ox'
|
|
501
|
+
* import * as Key from './key.js'
|
|
502
|
+
*
|
|
503
|
+
* // Admin Key
|
|
504
|
+
* const key = Key.fromP256({
|
|
505
|
+
* privateKey: P256.randomPrivateKey(),
|
|
506
|
+
* })
|
|
507
|
+
*
|
|
508
|
+
* // Session Key
|
|
509
|
+
* const key = Key.fromP256({
|
|
510
|
+
* expiry: 1714857600,
|
|
511
|
+
* privateKey: P256.randomPrivateKey(),
|
|
512
|
+
* role: 'session',
|
|
513
|
+
* })
|
|
514
|
+
* ```
|
|
515
|
+
*
|
|
516
|
+
* @param parameters - Key parameters.
|
|
517
|
+
* @returns P256 key.
|
|
518
|
+
*/
|
|
519
|
+
export function fromP256(parameters: fromP256.Parameters) {
|
|
520
|
+
const { chainId, expiry, feeToken, permissions, privateKey, role } =
|
|
521
|
+
parameters
|
|
522
|
+
const publicKey = PublicKey.toHex(P256.getPublicKey({ privateKey }), {
|
|
523
|
+
includePrefix: false,
|
|
524
|
+
})
|
|
525
|
+
return from({
|
|
526
|
+
chainId,
|
|
527
|
+
expiry,
|
|
528
|
+
feeToken,
|
|
529
|
+
permissions,
|
|
530
|
+
privateKey() {
|
|
531
|
+
return privateKey
|
|
532
|
+
},
|
|
533
|
+
publicKey,
|
|
534
|
+
role,
|
|
535
|
+
type: 'p256',
|
|
536
|
+
})
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
export declare namespace fromP256 {
|
|
540
|
+
type Parameters = Pick<
|
|
541
|
+
from.Value,
|
|
542
|
+
'chainId' | 'expiry' | 'feeToken' | 'permissions' | 'role'
|
|
543
|
+
> & {
|
|
544
|
+
/** P256 private key. */
|
|
545
|
+
privateKey: Hex.Hex
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Converts a Relay-formatted key to a key.
|
|
551
|
+
*
|
|
552
|
+
* @example
|
|
553
|
+
* TODO
|
|
554
|
+
*
|
|
555
|
+
* @param relayKey - Relay key.
|
|
556
|
+
* @returns Key.
|
|
557
|
+
*/
|
|
558
|
+
export function fromRelay(relayKey: Relay, options: { chainId: number }): Key {
|
|
559
|
+
const { chainId } = options
|
|
560
|
+
const { publicKey } = relayKey
|
|
561
|
+
|
|
562
|
+
const isAddress =
|
|
563
|
+
Hex.size(publicKey) === 20 ||
|
|
564
|
+
Hex.toBigInt(Hex.slice(publicKey, 0, 12)) === 0n
|
|
565
|
+
|
|
566
|
+
const permissions: {
|
|
567
|
+
calls?: Mutable<Key_schema.CallPermissions> | undefined
|
|
568
|
+
spend?: Mutable<Key_schema.SpendPermissions> | undefined
|
|
569
|
+
} = {}
|
|
570
|
+
|
|
571
|
+
for (const permission of relayKey.permissions) {
|
|
572
|
+
if (permission.type === 'call') {
|
|
573
|
+
permissions.calls ??= []
|
|
574
|
+
permissions.calls.push({
|
|
575
|
+
signature: permission.selector,
|
|
576
|
+
to: permission.to === Call.anyTarget ? undefined : permission.to,
|
|
577
|
+
})
|
|
578
|
+
}
|
|
579
|
+
if (permission.type === 'spend') {
|
|
580
|
+
permissions.spend ??= []
|
|
581
|
+
permissions.spend.push({
|
|
582
|
+
limit: permission.limit,
|
|
583
|
+
period: permission.period,
|
|
584
|
+
token: permission.token as Address.Address,
|
|
585
|
+
})
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
return from({
|
|
590
|
+
chainId,
|
|
591
|
+
expiry: relayKey.expiry,
|
|
592
|
+
permissions: permissions as Permissions,
|
|
593
|
+
publicKey: relayKey.publicKey,
|
|
594
|
+
role: fromRelayKeyRole[relayKey.role],
|
|
595
|
+
type: isAddress ? 'address' : fromRelayKeyType[relayKey.type],
|
|
596
|
+
})
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Instantiates a Secp256k1 key from its parameters.
|
|
601
|
+
*
|
|
602
|
+
* @example
|
|
603
|
+
* ```ts
|
|
604
|
+
* import { Secp256k1 } from 'ox'
|
|
605
|
+
* import * as Key from './key.js'
|
|
606
|
+
*
|
|
607
|
+
* // Admin Key
|
|
608
|
+
* const key = Key.fromSecp256k1({
|
|
609
|
+
* privateKey: Secp256k1.randomPrivateKey(),
|
|
610
|
+
* })
|
|
611
|
+
*
|
|
612
|
+
* // Session Key
|
|
613
|
+
* const key = Key.fromSecp256k1({
|
|
614
|
+
* expiry: 1714857600,
|
|
615
|
+
* privateKey: Secp256k1.randomPrivateKey(),
|
|
616
|
+
* role: 'session',
|
|
617
|
+
* })
|
|
618
|
+
* ```
|
|
619
|
+
*
|
|
620
|
+
* @param parameters - Key parameters.
|
|
621
|
+
* @returns Secp256k1 key.
|
|
622
|
+
*/
|
|
623
|
+
export function fromSecp256k1(parameters: fromSecp256k1.Parameters) {
|
|
624
|
+
const { privateKey, role } = parameters
|
|
625
|
+
const publicKey = (() => {
|
|
626
|
+
if (parameters.publicKey) return parameters.publicKey
|
|
627
|
+
if (privateKey)
|
|
628
|
+
return Address.fromPublicKey(Secp256k1.getPublicKey({ privateKey }))
|
|
629
|
+
return parameters.address.toLowerCase() as Hex.Hex
|
|
630
|
+
})()
|
|
631
|
+
return from({
|
|
632
|
+
expiry: parameters.expiry ?? 0,
|
|
633
|
+
feeToken: parameters.feeToken,
|
|
634
|
+
permissions: parameters.permissions,
|
|
635
|
+
privateKey: privateKey ? () => privateKey : undefined,
|
|
636
|
+
publicKey,
|
|
637
|
+
role,
|
|
638
|
+
type: 'secp256k1',
|
|
639
|
+
} as Secp256k1Key)
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
export declare namespace fromSecp256k1 {
|
|
643
|
+
type Parameters = Pick<
|
|
644
|
+
from.Value,
|
|
645
|
+
'expiry' | 'feeToken' | 'permissions' | 'role'
|
|
646
|
+
> &
|
|
647
|
+
OneOf<
|
|
648
|
+
| {
|
|
649
|
+
/** Ethereum address. */
|
|
650
|
+
address: Address.Address
|
|
651
|
+
}
|
|
652
|
+
| {
|
|
653
|
+
/** Secp256k1 public key. */
|
|
654
|
+
publicKey: Hex.Hex
|
|
655
|
+
}
|
|
656
|
+
| {
|
|
657
|
+
/** Secp256k1 private key. */
|
|
658
|
+
privateKey: Hex.Hex
|
|
659
|
+
}
|
|
660
|
+
>
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* Instantiates a WebAuthnP256 key from its parameters.
|
|
665
|
+
*
|
|
666
|
+
* @example
|
|
667
|
+
* ```ts
|
|
668
|
+
* import { WebAuthnP256 } from 'ox'
|
|
669
|
+
* import * as Key from './key.js'
|
|
670
|
+
*
|
|
671
|
+
* const credential = await WebAuthnP256.createCredential({ name: 'My Key' })
|
|
672
|
+
*
|
|
673
|
+
* // Admin Key
|
|
674
|
+
* const key = Key.fromWebAuthnP256({
|
|
675
|
+
* credential,
|
|
676
|
+
* })
|
|
677
|
+
*
|
|
678
|
+
* // Session Key
|
|
679
|
+
* const key = Key.fromWebAuthnP256({
|
|
680
|
+
* expiry: 1714857600,
|
|
681
|
+
* credential,
|
|
682
|
+
* role: 'session',
|
|
683
|
+
* })
|
|
684
|
+
* ```
|
|
685
|
+
*
|
|
686
|
+
* @param parameters - Key parameters.
|
|
687
|
+
* @returns WebAuthnP256 key.
|
|
688
|
+
*/
|
|
689
|
+
export function fromWebAuthnP256(parameters: fromWebAuthnP256.Parameters) {
|
|
690
|
+
const { credential, id, rpId } = parameters
|
|
691
|
+
const publicKey = PublicKey.toHex(credential.publicKey, {
|
|
692
|
+
includePrefix: false,
|
|
693
|
+
})
|
|
694
|
+
return from({
|
|
695
|
+
chainId: parameters.chainId,
|
|
696
|
+
expiry: parameters.expiry ?? 0,
|
|
697
|
+
feeToken: parameters.feeToken,
|
|
698
|
+
id,
|
|
699
|
+
permissions: parameters.permissions,
|
|
700
|
+
privateKey: {
|
|
701
|
+
credential,
|
|
702
|
+
rpId,
|
|
703
|
+
},
|
|
704
|
+
publicKey,
|
|
705
|
+
role: parameters.role,
|
|
706
|
+
type: 'webauthn-p256',
|
|
707
|
+
})
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
export declare namespace fromWebAuthnP256 {
|
|
711
|
+
type Parameters = Pick<
|
|
712
|
+
from.Value,
|
|
713
|
+
'chainId' | 'expiry' | 'feeToken' | 'id' | 'permissions' | 'role'
|
|
714
|
+
> & {
|
|
715
|
+
/** WebAuthnP256 Credential. */
|
|
716
|
+
credential: Pick<WebAuthnP256.P256Credential, 'id' | 'publicKey'>
|
|
717
|
+
/** Relying Party ID. */
|
|
718
|
+
rpId?: string | undefined
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* Instantiates a WebAuthn-wrapped P256 key from its parameters.
|
|
724
|
+
*
|
|
725
|
+
* @example
|
|
726
|
+
* ```ts
|
|
727
|
+
* import { P256 } from 'ox'
|
|
728
|
+
* import * as Key from './key.js'
|
|
729
|
+
*
|
|
730
|
+
* const privateKey = P256.randomPrivateKey()
|
|
731
|
+
*
|
|
732
|
+
* // Admin Key
|
|
733
|
+
* const key = Key.fromHeadlessWebAuthnP256({
|
|
734
|
+
* privateKey,
|
|
735
|
+
* })
|
|
736
|
+
*
|
|
737
|
+
* // Session Key
|
|
738
|
+
* const key = Key.fromHeadlessWebAuthnP256({
|
|
739
|
+
* expiry: 1714857600,
|
|
740
|
+
* privateKey,
|
|
741
|
+
* role: 'session',
|
|
742
|
+
* })
|
|
743
|
+
* ```
|
|
744
|
+
*
|
|
745
|
+
* @param parameters - Key parameters.
|
|
746
|
+
* @returns WebAuthn-wrapped P256 key.
|
|
747
|
+
*/
|
|
748
|
+
export function fromHeadlessWebAuthnP256(
|
|
749
|
+
parameters: fromHeadlessWebAuthnP256.Parameters,
|
|
750
|
+
) {
|
|
751
|
+
const { privateKey } = parameters
|
|
752
|
+
const publicKey = PublicKey.toHex(P256.getPublicKey({ privateKey }), {
|
|
753
|
+
includePrefix: false,
|
|
754
|
+
})
|
|
755
|
+
return from({
|
|
756
|
+
chainId: parameters.chainId,
|
|
757
|
+
expiry: parameters.expiry ?? 0,
|
|
758
|
+
feeToken: parameters.feeToken,
|
|
759
|
+
permissions: parameters.permissions,
|
|
760
|
+
privateKey: {
|
|
761
|
+
privateKey() {
|
|
762
|
+
return privateKey
|
|
763
|
+
},
|
|
764
|
+
},
|
|
765
|
+
publicKey,
|
|
766
|
+
role: parameters.role,
|
|
767
|
+
type: 'webauthn-p256',
|
|
768
|
+
})
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
export declare namespace fromHeadlessWebAuthnP256 {
|
|
772
|
+
type Parameters = Pick<
|
|
773
|
+
from.Value,
|
|
774
|
+
'chainId' | 'expiry' | 'feeToken' | 'permissions' | 'role'
|
|
775
|
+
> & {
|
|
776
|
+
/** P256 private key. */
|
|
777
|
+
privateKey: Hex.Hex
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* Instantiates a WebCryptoP256 key from its parameters.
|
|
783
|
+
*
|
|
784
|
+
* @example
|
|
785
|
+
* ```ts
|
|
786
|
+
* import { WebCryptoP256 } from 'ox'
|
|
787
|
+
* import * as Key from './key.js'
|
|
788
|
+
*
|
|
789
|
+
* const keyPair = await WebCryptoP256.createKeyPair()
|
|
790
|
+
*
|
|
791
|
+
* // Admin Key
|
|
792
|
+
* const key = Key.fromWebCryptoP256({
|
|
793
|
+
* keyPair,
|
|
794
|
+
* })
|
|
795
|
+
*
|
|
796
|
+
* // Session Key
|
|
797
|
+
* const key = Key.fromWebCryptoP256({
|
|
798
|
+
* expiry: 1714857600,
|
|
799
|
+
* keyPair,
|
|
800
|
+
* role: 'session',
|
|
801
|
+
* })
|
|
802
|
+
* ```
|
|
803
|
+
*
|
|
804
|
+
* @param parameters - Key parameters.
|
|
805
|
+
* @returns WebCryptoP256 key.
|
|
806
|
+
*/
|
|
807
|
+
export function fromWebCryptoP256(parameters: fromWebCryptoP256.Parameters) {
|
|
808
|
+
const { chainId, expiry, feeToken, keyPair, permissions, role } = parameters
|
|
809
|
+
const { privateKey } = keyPair
|
|
810
|
+
const publicKey = PublicKey.toHex(keyPair.publicKey, {
|
|
811
|
+
includePrefix: false,
|
|
812
|
+
})
|
|
813
|
+
return from({
|
|
814
|
+
chainId,
|
|
815
|
+
expiry,
|
|
816
|
+
feeToken,
|
|
817
|
+
permissions,
|
|
818
|
+
prehash: true,
|
|
819
|
+
privateKey,
|
|
820
|
+
publicKey,
|
|
821
|
+
role,
|
|
822
|
+
type: 'p256',
|
|
823
|
+
})
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
export declare namespace fromWebCryptoP256 {
|
|
827
|
+
type Parameters = Pick<
|
|
828
|
+
from.Value,
|
|
829
|
+
'chainId' | 'expiry' | 'feeToken' | 'permissions' | 'role'
|
|
830
|
+
> & {
|
|
831
|
+
/** P256 private key. */
|
|
832
|
+
keyPair: Awaited<ReturnType<typeof WebCryptoP256.createKeyPair>>
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
/**
|
|
837
|
+
* Hashes a key.
|
|
838
|
+
*
|
|
839
|
+
* @example
|
|
840
|
+
* ```ts
|
|
841
|
+
* import * as Key from './key.js'
|
|
842
|
+
*
|
|
843
|
+
* const key = Key.createP256()
|
|
844
|
+
*
|
|
845
|
+
* const hash = Key.hash(key)
|
|
846
|
+
* ```
|
|
847
|
+
*
|
|
848
|
+
* @param key - Key.
|
|
849
|
+
* @returns Hashed key.
|
|
850
|
+
*/
|
|
851
|
+
export function hash(key: Pick<Key, 'publicKey' | 'type'>): Hex.Hex {
|
|
852
|
+
const { type } = key
|
|
853
|
+
const publicKey = serializePublicKey(key.publicKey)
|
|
854
|
+
return Hash.keccak256(
|
|
855
|
+
AbiParameters.encode(
|
|
856
|
+
[{ type: 'uint8' }, { type: 'bytes32' }],
|
|
857
|
+
[toSerializedKeyType[type], Hash.keccak256(publicKey)],
|
|
858
|
+
),
|
|
859
|
+
)
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
/**
|
|
863
|
+
* Serializes a public key.
|
|
864
|
+
*
|
|
865
|
+
* @param publicKey - Public key.
|
|
866
|
+
* @returns Serialized public key.
|
|
867
|
+
*/
|
|
868
|
+
export function serializePublicKey(publicKey: Hex.Hex): Hex.Hex {
|
|
869
|
+
return Hex.size(publicKey) < 32 ? Hex.padLeft(publicKey, 32) : publicKey
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* Serializes a key to a contract-compatible format.
|
|
874
|
+
*
|
|
875
|
+
* @example
|
|
876
|
+
* ```ts
|
|
877
|
+
* import * as Key from './key.js'
|
|
878
|
+
*
|
|
879
|
+
* const key = Key.createP256()
|
|
880
|
+
*
|
|
881
|
+
* const serialized = Key.serialize(key)
|
|
882
|
+
* ```
|
|
883
|
+
*
|
|
884
|
+
* @param key - Key.
|
|
885
|
+
* @returns Serialized key.
|
|
886
|
+
*/
|
|
887
|
+
export function serialize(key: Key): Serialized {
|
|
888
|
+
const { expiry = 0, publicKey, role, type } = key
|
|
889
|
+
return {
|
|
890
|
+
expiry,
|
|
891
|
+
isSuperAdmin: role === 'admin',
|
|
892
|
+
keyType: toSerializedKeyType[type],
|
|
893
|
+
publicKey: serializePublicKey(publicKey),
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
export async function sign(key: Key, parameters: sign.Parameters) {
|
|
898
|
+
const { address, storage, webAuthn, wrap = true } = parameters
|
|
899
|
+
const { privateKey, publicKey, type: keyType } = key
|
|
900
|
+
|
|
901
|
+
if (!privateKey)
|
|
902
|
+
throw new Error(
|
|
903
|
+
'Key does not have a private key to sign with.\n\nKey:\n' +
|
|
904
|
+
Json.stringify(key, null, 2),
|
|
905
|
+
)
|
|
906
|
+
|
|
907
|
+
const payload = (() => {
|
|
908
|
+
if (!address) return parameters.payload
|
|
909
|
+
return TypedData.getSignPayload({
|
|
910
|
+
domain: { verifyingContract: address },
|
|
911
|
+
message: {
|
|
912
|
+
digest: parameters.payload,
|
|
913
|
+
},
|
|
914
|
+
primaryType: 'ERC1271Sign',
|
|
915
|
+
types: {
|
|
916
|
+
ERC1271Sign: [{ name: 'digest', type: 'bytes32' }],
|
|
917
|
+
},
|
|
918
|
+
})
|
|
919
|
+
})()
|
|
920
|
+
|
|
921
|
+
const [signature, prehash] = await (async () => {
|
|
922
|
+
if (keyType === 'p256') {
|
|
923
|
+
const { privateKey } = key
|
|
924
|
+
if (typeof privateKey === 'function')
|
|
925
|
+
return [
|
|
926
|
+
Signature.toHex(P256.sign({ payload, privateKey: privateKey() })),
|
|
927
|
+
false,
|
|
928
|
+
]
|
|
929
|
+
if (privateKey instanceof CryptoKey) {
|
|
930
|
+
const signature = Signature.toHex(
|
|
931
|
+
await WebCryptoP256.sign({ payload, privateKey }),
|
|
932
|
+
)
|
|
933
|
+
return [signature, true]
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
if (keyType === 'secp256k1') {
|
|
937
|
+
return [
|
|
938
|
+
Signature.toHex(Secp256k1.sign({ payload, privateKey: privateKey() })),
|
|
939
|
+
false,
|
|
940
|
+
]
|
|
941
|
+
}
|
|
942
|
+
if (keyType === 'webauthn-p256') {
|
|
943
|
+
if (privateKey.privateKey) {
|
|
944
|
+
const { payload: wrapped, metadata } = WebAuthnP256.getSignPayload({
|
|
945
|
+
challenge: payload,
|
|
946
|
+
origin: 'https://ithaca.xyz',
|
|
947
|
+
rpId: 'ithaca.xyz',
|
|
948
|
+
})
|
|
949
|
+
const { r, s } = P256.sign({
|
|
950
|
+
hash: true,
|
|
951
|
+
payload: wrapped,
|
|
952
|
+
privateKey: privateKey.privateKey(),
|
|
953
|
+
})
|
|
954
|
+
const signature = serializeWebAuthnSignature({
|
|
955
|
+
metadata,
|
|
956
|
+
signature: { r, s },
|
|
957
|
+
})
|
|
958
|
+
return [signature, false]
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
const { credential, rpId } = privateKey
|
|
962
|
+
|
|
963
|
+
const cacheKey = `porto.webauthnVerified.${key.hash}`
|
|
964
|
+
const now = Date.now()
|
|
965
|
+
const verificationTimeout = 10 * 60 * 1_000 // 10 minutes in milliseconds
|
|
966
|
+
|
|
967
|
+
let requireVerification = true
|
|
968
|
+
if (storage) {
|
|
969
|
+
const lastVerified = await storage.getItem<number>(cacheKey)
|
|
970
|
+
requireVerification =
|
|
971
|
+
!lastVerified || now - lastVerified > verificationTimeout
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
const {
|
|
975
|
+
signature: { r, s },
|
|
976
|
+
raw,
|
|
977
|
+
metadata,
|
|
978
|
+
} = await WebAuthnP256.sign({
|
|
979
|
+
challenge: payload,
|
|
980
|
+
credentialId: credential.id,
|
|
981
|
+
getFn: webAuthn?.getFn,
|
|
982
|
+
rpId,
|
|
983
|
+
userVerification: requireVerification ? 'required' : 'preferred',
|
|
984
|
+
})
|
|
985
|
+
|
|
986
|
+
const response = raw.response as AuthenticatorAssertionResponse
|
|
987
|
+
if (!response?.userHandle)
|
|
988
|
+
throw new Error('No user handle in response', {
|
|
989
|
+
cause: { response },
|
|
990
|
+
})
|
|
991
|
+
const id = Bytes.toHex(new Uint8Array(response.userHandle!))
|
|
992
|
+
if (key.id && Address.validate(key.id) && !Address.isEqual(key.id, id))
|
|
993
|
+
throw new Error(
|
|
994
|
+
`supplied webauthn key "${key.id}" does not match signature webauthn key "${id}"`,
|
|
995
|
+
{ cause: { id, key } },
|
|
996
|
+
)
|
|
997
|
+
|
|
998
|
+
if (requireVerification && storage) await storage.setItem(cacheKey, now)
|
|
999
|
+
|
|
1000
|
+
const signature = serializeWebAuthnSignature({
|
|
1001
|
+
metadata,
|
|
1002
|
+
signature: { r, s },
|
|
1003
|
+
})
|
|
1004
|
+
return [signature, false]
|
|
1005
|
+
}
|
|
1006
|
+
throw new Error(
|
|
1007
|
+
`Key type "${keyType}" is not supported.\n\nKey:\n` +
|
|
1008
|
+
Json.stringify(key, null, 2),
|
|
1009
|
+
)
|
|
1010
|
+
})()
|
|
1011
|
+
|
|
1012
|
+
if (wrap)
|
|
1013
|
+
return wrapSignature(signature, {
|
|
1014
|
+
keyType,
|
|
1015
|
+
prehash,
|
|
1016
|
+
publicKey,
|
|
1017
|
+
})
|
|
1018
|
+
return signature
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
export declare namespace sign {
|
|
1022
|
+
type Parameters = {
|
|
1023
|
+
/**
|
|
1024
|
+
* Address to use for replay-safe signing.
|
|
1025
|
+
* `null` if replay-safe signing is not needed (e.g. signing call bundles).
|
|
1026
|
+
*/
|
|
1027
|
+
address: Address.Address | null
|
|
1028
|
+
/**
|
|
1029
|
+
* Payload to sign.
|
|
1030
|
+
*/
|
|
1031
|
+
payload: Hex.Hex
|
|
1032
|
+
/**
|
|
1033
|
+
* Storage to use for keytype-specific caching (e.g. WebAuthn user verification).
|
|
1034
|
+
*/
|
|
1035
|
+
storage?: Storage.Storage | undefined
|
|
1036
|
+
/**
|
|
1037
|
+
* WebAuthn configuration.
|
|
1038
|
+
*/
|
|
1039
|
+
webAuthn?:
|
|
1040
|
+
| {
|
|
1041
|
+
createFn?: WebAuthnP256.createCredential.Options['createFn']
|
|
1042
|
+
getFn?: WebAuthnP256.sign.Options['getFn']
|
|
1043
|
+
}
|
|
1044
|
+
| undefined
|
|
1045
|
+
/**
|
|
1046
|
+
* Whether to wrap the signature with key metadata.
|
|
1047
|
+
* @default true
|
|
1048
|
+
*/
|
|
1049
|
+
wrap?: boolean | undefined
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
/**
|
|
1054
|
+
* Converts a key to a Relay-compatible format.
|
|
1055
|
+
*
|
|
1056
|
+
* @example
|
|
1057
|
+
* TODO
|
|
1058
|
+
*
|
|
1059
|
+
* @param key - Key.
|
|
1060
|
+
* @returns Relay key.
|
|
1061
|
+
*/
|
|
1062
|
+
export function toRelay(
|
|
1063
|
+
key: toRelay.Value,
|
|
1064
|
+
options: toRelay.Options = {},
|
|
1065
|
+
): RequiredBy<Relay, 'prehash'> {
|
|
1066
|
+
const { expiry = 0, prehash = false, publicKey, role = 'admin', type } = key
|
|
1067
|
+
const { feeTokens, orchestrator } = options
|
|
1068
|
+
|
|
1069
|
+
// biome-ignore lint/complexity/useFlatMap: i know
|
|
1070
|
+
const permissions = Object.entries(
|
|
1071
|
+
resolvePermissions(key, {
|
|
1072
|
+
feeTokens,
|
|
1073
|
+
}),
|
|
1074
|
+
)
|
|
1075
|
+
// biome-ignore lint/suspicious/useIterableCallbackReturn: _
|
|
1076
|
+
.map(([key, v]) => {
|
|
1077
|
+
if (key === 'calls') {
|
|
1078
|
+
const calls = v as Key_schema.CallPermissions
|
|
1079
|
+
return calls.map(({ signature, to }) => {
|
|
1080
|
+
const selector = (() => {
|
|
1081
|
+
if (!signature) return Call.anySelector
|
|
1082
|
+
if (Hex.validate(signature)) return signature
|
|
1083
|
+
return AbiFunction.getSelector(signature)
|
|
1084
|
+
})()
|
|
1085
|
+
return {
|
|
1086
|
+
selector,
|
|
1087
|
+
to: to ?? Call.anyTarget,
|
|
1088
|
+
type: 'call',
|
|
1089
|
+
} as const satisfies RelayPermission_schema.CallPermission
|
|
1090
|
+
})
|
|
1091
|
+
}
|
|
1092
|
+
if (key === 'feeToken') return
|
|
1093
|
+
if (key === 'spend') {
|
|
1094
|
+
const value = v as Key_schema.SpendPermissions
|
|
1095
|
+
return value.map(({ limit, period, token }) => {
|
|
1096
|
+
return {
|
|
1097
|
+
limit,
|
|
1098
|
+
period,
|
|
1099
|
+
token,
|
|
1100
|
+
type: 'spend',
|
|
1101
|
+
} as const satisfies RelayPermission_schema.SpendPermission
|
|
1102
|
+
})
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
throw new Error(`Invalid permission type "${key}".`)
|
|
1106
|
+
})
|
|
1107
|
+
.flat()
|
|
1108
|
+
.filter(Boolean) as RelayPermission_schema.Permission[]
|
|
1109
|
+
|
|
1110
|
+
if (key.role === 'session' && orchestrator)
|
|
1111
|
+
permissions.push({
|
|
1112
|
+
selector: Call.anySelector,
|
|
1113
|
+
to: orchestrator,
|
|
1114
|
+
type: 'call',
|
|
1115
|
+
})
|
|
1116
|
+
|
|
1117
|
+
return {
|
|
1118
|
+
expiry,
|
|
1119
|
+
permissions: permissions ?? [],
|
|
1120
|
+
prehash,
|
|
1121
|
+
publicKey: serializePublicKey(publicKey),
|
|
1122
|
+
role: toRelayKeyRole[role],
|
|
1123
|
+
type: toRelayKeyType[type],
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
export declare namespace toRelay {
|
|
1128
|
+
type Value = PartialBy<
|
|
1129
|
+
Pick<
|
|
1130
|
+
Key,
|
|
1131
|
+
'expiry' | 'prehash' | 'permissions' | 'publicKey' | 'role' | 'type'
|
|
1132
|
+
>,
|
|
1133
|
+
'expiry' | 'role'
|
|
1134
|
+
>
|
|
1135
|
+
|
|
1136
|
+
type Options = {
|
|
1137
|
+
/** Fee tokens. */
|
|
1138
|
+
feeTokens?: readonly Tokens.Token[] | undefined
|
|
1139
|
+
/** Orchestrator address. */
|
|
1140
|
+
orchestrator?: Address.Address | undefined
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
/**
|
|
1145
|
+
* Resolves the permissions for the permissions request, and if needed, adds
|
|
1146
|
+
* the fee limit to the spend permissions.
|
|
1147
|
+
*
|
|
1148
|
+
* @param request - Permissions request.
|
|
1149
|
+
* @param options - Options.
|
|
1150
|
+
* @returns Resolved permissions.
|
|
1151
|
+
*/
|
|
1152
|
+
export function resolvePermissions(
|
|
1153
|
+
key: Pick<Key, 'feeToken' | 'permissions'>,
|
|
1154
|
+
options: resolvePermissions.Options,
|
|
1155
|
+
) {
|
|
1156
|
+
const { permissions } = key
|
|
1157
|
+
|
|
1158
|
+
const calls = permissions?.calls ? [...permissions.calls] : []
|
|
1159
|
+
const spend = permissions?.spend ? [...permissions.spend] : []
|
|
1160
|
+
|
|
1161
|
+
const feeTokens = options.feeTokens?.filter((token) => token.feeToken)
|
|
1162
|
+
if (feeTokens && feeTokens.length > 0) {
|
|
1163
|
+
const feeToken = getFeeToken(key, {
|
|
1164
|
+
feeTokens,
|
|
1165
|
+
})
|
|
1166
|
+
|
|
1167
|
+
if (feeToken) {
|
|
1168
|
+
let index = -1
|
|
1169
|
+
let minPeriod: number = toSerializedSpendPeriod.year
|
|
1170
|
+
|
|
1171
|
+
for (let i = 0; i < spend.length; i++) {
|
|
1172
|
+
const s = spend[i]!
|
|
1173
|
+
if (s.token && Address.isEqual(feeToken.address, s.token)) {
|
|
1174
|
+
index = i
|
|
1175
|
+
break
|
|
1176
|
+
}
|
|
1177
|
+
if (!s.token && feeToken.address === zeroAddress) {
|
|
1178
|
+
index = i
|
|
1179
|
+
break
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
const period = toSerializedSpendPeriod[s.period]
|
|
1183
|
+
if (period < minPeriod) minPeriod = period
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
// If there is a token assigned to a spend permission and the fee token
|
|
1187
|
+
// is the same, update the limit to account for the fee.
|
|
1188
|
+
if (index !== -1) {
|
|
1189
|
+
spend[index] = {
|
|
1190
|
+
...spend[index]!,
|
|
1191
|
+
limit: spend[index]!.limit + feeToken.value,
|
|
1192
|
+
}
|
|
1193
|
+
// Assign this as the first spend permission, as it will be used
|
|
1194
|
+
// as the fee token for call bundles that use this key.
|
|
1195
|
+
spend.unshift(spend.splice(index, 1)[0]!)
|
|
1196
|
+
}
|
|
1197
|
+
// Update the spend permissions to account for the fee token.
|
|
1198
|
+
// The fee token permission must be assigned as the first spend
|
|
1199
|
+
// permission as it will be used as the fee token for call bundles
|
|
1200
|
+
// that use this key.
|
|
1201
|
+
else if (typeof minPeriod === 'number')
|
|
1202
|
+
spend.unshift({
|
|
1203
|
+
limit: feeToken.value,
|
|
1204
|
+
period:
|
|
1205
|
+
fromSerializedSpendPeriod[
|
|
1206
|
+
minPeriod as keyof typeof fromSerializedSpendPeriod
|
|
1207
|
+
],
|
|
1208
|
+
token: feeToken.address,
|
|
1209
|
+
})
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
return { ...permissions, calls, spend }
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
export declare namespace resolvePermissions {
|
|
1217
|
+
export type Options = {
|
|
1218
|
+
feeTokens?: Tokens.Tokens | null | undefined
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
/**
|
|
1223
|
+
* Gets the fee limit (in units of the fee token) to be used for the
|
|
1224
|
+
* authorized permissions.
|
|
1225
|
+
*
|
|
1226
|
+
* @param request - The permissions request to get the fee limit for.
|
|
1227
|
+
* @param options - Options.
|
|
1228
|
+
* @returns Fee limit (in units of the fee token).
|
|
1229
|
+
*/
|
|
1230
|
+
export function getFeeToken(
|
|
1231
|
+
key: Pick<Key, 'feeToken' | 'permissions'>,
|
|
1232
|
+
options: getFeeToken.Options,
|
|
1233
|
+
): getFeeToken.ReturnType {
|
|
1234
|
+
const { feeTokens } = options
|
|
1235
|
+
|
|
1236
|
+
if (!key.feeToken) return undefined
|
|
1237
|
+
|
|
1238
|
+
const feeToken = feeTokens.find((token) => {
|
|
1239
|
+
if (key.feeToken!.symbol === token.symbol) return true
|
|
1240
|
+
if (!key.feeToken!.symbol) return token.address === zeroAddress
|
|
1241
|
+
if (key.feeToken!.symbol === 'native') return token.address === zeroAddress
|
|
1242
|
+
return false
|
|
1243
|
+
})
|
|
1244
|
+
if (!feeToken) return undefined
|
|
1245
|
+
|
|
1246
|
+
const value = Value.from(key.feeToken.limit, feeToken.decimals)
|
|
1247
|
+
|
|
1248
|
+
return {
|
|
1249
|
+
...feeToken,
|
|
1250
|
+
value,
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
export declare namespace getFeeToken {
|
|
1255
|
+
export type Options = {
|
|
1256
|
+
feeTokens: Tokens.Tokens
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
export type ReturnType =
|
|
1260
|
+
| (Tokens.Token & {
|
|
1261
|
+
value: bigint
|
|
1262
|
+
})
|
|
1263
|
+
| undefined
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
///////////////////////////////////////////////////////////////////////////
|
|
1267
|
+
// Internal
|
|
1268
|
+
///////////////////////////////////////////////////////////////////////////
|
|
1269
|
+
|
|
1270
|
+
export function serializeWebAuthnSignature(
|
|
1271
|
+
options: serializeWebAuthnSignature.Options,
|
|
1272
|
+
) {
|
|
1273
|
+
const { metadata, signature } = options
|
|
1274
|
+
return AbiParameters.encode(
|
|
1275
|
+
AbiParameters.from([
|
|
1276
|
+
'struct WebAuthnAuth { bytes authenticatorData; string clientDataJSON; uint256 challengeIndex; uint256 typeIndex; bytes32 r; bytes32 s; }',
|
|
1277
|
+
'WebAuthnAuth auth',
|
|
1278
|
+
]),
|
|
1279
|
+
[
|
|
1280
|
+
{
|
|
1281
|
+
authenticatorData: metadata.authenticatorData,
|
|
1282
|
+
challengeIndex: BigInt(metadata.challengeIndex),
|
|
1283
|
+
clientDataJSON: metadata.clientDataJSON,
|
|
1284
|
+
r: Hex.fromNumber(signature.r, { size: 32 }),
|
|
1285
|
+
s: Hex.fromNumber(signature.s, { size: 32 }),
|
|
1286
|
+
typeIndex: BigInt(metadata.typeIndex),
|
|
1287
|
+
},
|
|
1288
|
+
],
|
|
1289
|
+
)
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
export declare namespace serializeWebAuthnSignature {
|
|
1293
|
+
type Options = {
|
|
1294
|
+
metadata: WebAuthnP256.SignMetadata
|
|
1295
|
+
signature: Signature.Signature<false>
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
export function wrapSignature(
|
|
1300
|
+
signature: Hex.Hex,
|
|
1301
|
+
options: wrapSignature.Options,
|
|
1302
|
+
) {
|
|
1303
|
+
const { keyType: type, prehash = false, publicKey } = options
|
|
1304
|
+
|
|
1305
|
+
const keyHash = hash({ publicKey, type })
|
|
1306
|
+
return AbiParameters.encodePacked(
|
|
1307
|
+
['bytes', 'bytes32', 'bool'],
|
|
1308
|
+
[signature, keyHash, prehash],
|
|
1309
|
+
)
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
declare namespace wrapSignature {
|
|
1313
|
+
type Options = {
|
|
1314
|
+
keyType: Key['type']
|
|
1315
|
+
prehash?: boolean | undefined
|
|
1316
|
+
publicKey: Hex.Hex
|
|
1317
|
+
}
|
|
1318
|
+
}
|