@startale/app-sdk 1.0.0
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/LICENSE +13 -0
- package/README.md +116 -0
- package/dist/app-sdk.js +36226 -0
- package/dist/app-sdk.js.map +1 -0
- package/dist/app-sdk.min.js +15 -0
- package/dist/app-sdk.min.js.map +1 -0
- package/dist/browser-entry.d.ts +15 -0
- package/dist/browser-entry.d.ts.map +1 -0
- package/dist/browser-entry.js +19 -0
- package/dist/browser-entry.js.map +1 -0
- package/dist/core/communicator/Communicator.d.ts +47 -0
- package/dist/core/communicator/Communicator.d.ts.map +1 -0
- package/dist/core/communicator/Communicator.js +107 -0
- package/dist/core/communicator/Communicator.js.map +1 -0
- package/dist/core/constants.d.ts +5 -0
- package/dist/core/constants.d.ts.map +1 -0
- package/dist/core/constants.js +6 -0
- package/dist/core/constants.js.map +1 -0
- package/dist/core/error/constants.d.ts +96 -0
- package/dist/core/error/constants.d.ts.map +1 -0
- package/dist/core/error/constants.js +94 -0
- package/dist/core/error/constants.js.map +1 -0
- package/dist/core/error/errors.d.ts +74 -0
- package/dist/core/error/errors.d.ts.map +1 -0
- package/dist/core/error/errors.js +138 -0
- package/dist/core/error/errors.js.map +1 -0
- package/dist/core/error/serialize.d.ts +13 -0
- package/dist/core/error/serialize.d.ts.map +1 -0
- package/dist/core/error/serialize.js +43 -0
- package/dist/core/error/serialize.js.map +1 -0
- package/dist/core/error/utils.d.ts +31 -0
- package/dist/core/error/utils.d.ts.map +1 -0
- package/dist/core/error/utils.js +109 -0
- package/dist/core/error/utils.js.map +1 -0
- package/dist/core/message/ConfigMessage.d.ts +6 -0
- package/dist/core/message/ConfigMessage.d.ts.map +1 -0
- package/dist/core/message/ConfigMessage.js +2 -0
- package/dist/core/message/ConfigMessage.js.map +1 -0
- package/dist/core/message/Message.d.ts +8 -0
- package/dist/core/message/Message.d.ts.map +1 -0
- package/dist/core/message/Message.js +2 -0
- package/dist/core/message/Message.js.map +1 -0
- package/dist/core/message/RPCMessage.d.ts +31 -0
- package/dist/core/message/RPCMessage.d.ts.map +1 -0
- package/dist/core/message/RPCMessage.js +2 -0
- package/dist/core/message/RPCMessage.js.map +1 -0
- package/dist/core/message/RPCRequest.d.ts +6 -0
- package/dist/core/message/RPCRequest.d.ts.map +1 -0
- package/dist/core/message/RPCRequest.js +2 -0
- package/dist/core/message/RPCRequest.js.map +1 -0
- package/dist/core/message/RPCResponse.d.ts +23 -0
- package/dist/core/message/RPCResponse.d.ts.map +1 -0
- package/dist/core/message/RPCResponse.js +2 -0
- package/dist/core/message/RPCResponse.js.map +1 -0
- package/dist/core/provider/interface.d.ts +94 -0
- package/dist/core/provider/interface.d.ts.map +1 -0
- package/dist/core/provider/interface.js +4 -0
- package/dist/core/provider/interface.js.map +1 -0
- package/dist/core/rpc/coinbase_fetchSpendPermissions.d.ts +50 -0
- package/dist/core/rpc/coinbase_fetchSpendPermissions.d.ts.map +1 -0
- package/dist/core/rpc/coinbase_fetchSpendPermissions.js +2 -0
- package/dist/core/rpc/coinbase_fetchSpendPermissions.js.map +1 -0
- package/dist/core/rpc/wallet_addSubAccount.d.ts +37 -0
- package/dist/core/rpc/wallet_addSubAccount.d.ts.map +1 -0
- package/dist/core/rpc/wallet_addSubAccount.js +2 -0
- package/dist/core/rpc/wallet_addSubAccount.js.map +1 -0
- package/dist/core/rpc/wallet_connect.d.ts +64 -0
- package/dist/core/rpc/wallet_connect.d.ts.map +1 -0
- package/dist/core/rpc/wallet_connect.js +2 -0
- package/dist/core/rpc/wallet_connect.js.map +1 -0
- package/dist/core/rpc/wallet_getSubAccount.d.ts +14 -0
- package/dist/core/rpc/wallet_getSubAccount.d.ts.map +1 -0
- package/dist/core/rpc/wallet_getSubAccount.js +2 -0
- package/dist/core/rpc/wallet_getSubAccount.js.map +1 -0
- package/dist/core/rpc/wallet_prepareCalls.d.ts +28 -0
- package/dist/core/rpc/wallet_prepareCalls.d.ts.map +1 -0
- package/dist/core/rpc/wallet_prepareCalls.js +2 -0
- package/dist/core/rpc/wallet_prepareCalls.js.map +1 -0
- package/dist/core/rpc/wallet_sendPreparedCalls.d.ts +47 -0
- package/dist/core/rpc/wallet_sendPreparedCalls.d.ts.map +1 -0
- package/dist/core/rpc/wallet_sendPreparedCalls.js +2 -0
- package/dist/core/rpc/wallet_sendPreparedCalls.js.map +1 -0
- package/dist/core/telemetry/events/communicator.d.ts +4 -0
- package/dist/core/telemetry/events/communicator.d.ts.map +1 -0
- package/dist/core/telemetry/events/communicator.js +20 -0
- package/dist/core/telemetry/events/communicator.js.map +1 -0
- package/dist/core/telemetry/events/dialog.d.ts +15 -0
- package/dist/core/telemetry/events/dialog.d.ts.map +1 -0
- package/dist/core/telemetry/events/dialog.js +24 -0
- package/dist/core/telemetry/events/dialog.js.map +1 -0
- package/dist/core/telemetry/events/payment.d.ts +31 -0
- package/dist/core/telemetry/events/payment.d.ts.map +1 -0
- package/dist/core/telemetry/events/payment.js +68 -0
- package/dist/core/telemetry/events/payment.js.map +1 -0
- package/dist/core/telemetry/events/provider.d.ts +14 -0
- package/dist/core/telemetry/events/provider.d.ts.map +1 -0
- package/dist/core/telemetry/events/provider.js +30 -0
- package/dist/core/telemetry/events/provider.js.map +1 -0
- package/dist/core/telemetry/events/scw-signer.d.ts +27 -0
- package/dist/core/telemetry/events/scw-signer.d.ts.map +1 -0
- package/dist/core/telemetry/events/scw-signer.js +65 -0
- package/dist/core/telemetry/events/scw-signer.js.map +1 -0
- package/dist/core/telemetry/events/scw-sub-account.d.ts +40 -0
- package/dist/core/telemetry/events/scw-sub-account.d.ts.map +1 -0
- package/dist/core/telemetry/events/scw-sub-account.js +96 -0
- package/dist/core/telemetry/events/scw-sub-account.js.map +1 -0
- package/dist/core/telemetry/events/spend-permission.d.ts +6 -0
- package/dist/core/telemetry/events/spend-permission.d.ts.map +1 -0
- package/dist/core/telemetry/events/spend-permission.js +21 -0
- package/dist/core/telemetry/events/spend-permission.js.map +1 -0
- package/dist/core/telemetry/initCCA.d.ts +2 -0
- package/dist/core/telemetry/initCCA.d.ts.map +1 -0
- package/dist/core/telemetry/initCCA.js +43 -0
- package/dist/core/telemetry/initCCA.js.map +1 -0
- package/dist/core/telemetry/logEvent.d.ts +72 -0
- package/dist/core/telemetry/logEvent.d.ts.map +1 -0
- package/dist/core/telemetry/logEvent.js +62 -0
- package/dist/core/telemetry/logEvent.js.map +1 -0
- package/dist/core/telemetry/telemetry-content.d.ts +2 -0
- package/dist/core/telemetry/telemetry-content.d.ts.map +1 -0
- package/dist/core/telemetry/telemetry-content.js +5526 -0
- package/dist/core/telemetry/telemetry-content.js.map +1 -0
- package/dist/core/telemetry/utils.d.ts +2 -0
- package/dist/core/telemetry/utils.d.ts.map +1 -0
- package/dist/core/telemetry/utils.js +7 -0
- package/dist/core/telemetry/utils.js.map +1 -0
- package/dist/core/type/index.d.ts +21 -0
- package/dist/core/type/index.d.ts.map +1 -0
- package/dist/core/type/index.js +10 -0
- package/dist/core/type/index.js.map +1 -0
- package/dist/core/type/util.d.ts +28 -0
- package/dist/core/type/util.d.ts.map +1 -0
- package/dist/core/type/util.js +158 -0
- package/dist/core/type/util.js.map +1 -0
- package/dist/core/username/getDisplayableUsername.d.ts +3 -0
- package/dist/core/username/getDisplayableUsername.d.ts.map +1 -0
- package/dist/core/username/getDisplayableUsername.js +7 -0
- package/dist/core/username/getDisplayableUsername.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/interface/builder/core/BaseAccountProvider.d.ts +11 -0
- package/dist/interface/builder/core/BaseAccountProvider.d.ts.map +1 -0
- package/dist/interface/builder/core/BaseAccountProvider.js +141 -0
- package/dist/interface/builder/core/BaseAccountProvider.js.map +1 -0
- package/dist/interface/builder/core/createBaseAccountSDK.d.ts +27 -0
- package/dist/interface/builder/core/createBaseAccountSDK.d.ts.map +1 -0
- package/dist/interface/builder/core/createBaseAccountSDK.js +149 -0
- package/dist/interface/builder/core/createBaseAccountSDK.js.map +1 -0
- package/dist/interface/builder/core/getInjectedProvider.d.ts +13 -0
- package/dist/interface/builder/core/getInjectedProvider.d.ts.map +1 -0
- package/dist/interface/builder/core/getInjectedProvider.js +10 -0
- package/dist/interface/builder/core/getInjectedProvider.js.map +1 -0
- package/dist/interface/payment/base.d.ts +32 -0
- package/dist/interface/payment/base.d.ts.map +1 -0
- package/dist/interface/payment/base.js +16 -0
- package/dist/interface/payment/base.js.map +1 -0
- package/dist/interface/payment/constants.d.ts +56 -0
- package/dist/interface/payment/constants.d.ts.map +1 -0
- package/dist/interface/payment/constants.js +45 -0
- package/dist/interface/payment/constants.js.map +1 -0
- package/dist/interface/payment/getPaymentStatus.d.ts +28 -0
- package/dist/interface/payment/getPaymentStatus.d.ts.map +1 -0
- package/dist/interface/payment/getPaymentStatus.js +243 -0
- package/dist/interface/payment/getPaymentStatus.js.map +1 -0
- package/dist/interface/payment/index.d.ts +9 -0
- package/dist/interface/payment/index.d.ts.map +1 -0
- package/dist/interface/payment/index.js +9 -0
- package/dist/interface/payment/index.js.map +1 -0
- package/dist/interface/payment/pay.d.ts +29 -0
- package/dist/interface/payment/pay.d.ts.map +1 -0
- package/dist/interface/payment/pay.js +90 -0
- package/dist/interface/payment/pay.js.map +1 -0
- package/dist/interface/payment/types.d.ts +123 -0
- package/dist/interface/payment/types.d.ts.map +1 -0
- package/dist/interface/payment/types.js +5 -0
- package/dist/interface/payment/types.js.map +1 -0
- package/dist/interface/payment/utils/sdkManager.d.ts +61 -0
- package/dist/interface/payment/utils/sdkManager.d.ts.map +1 -0
- package/dist/interface/payment/utils/sdkManager.js +84 -0
- package/dist/interface/payment/utils/sdkManager.js.map +1 -0
- package/dist/interface/payment/utils/translatePayment.d.ts +45 -0
- package/dist/interface/payment/utils/translatePayment.d.ts.map +1 -0
- package/dist/interface/payment/utils/translatePayment.js +70 -0
- package/dist/interface/payment/utils/translatePayment.js.map +1 -0
- package/dist/interface/payment/utils/validation.d.ts +16 -0
- package/dist/interface/payment/utils/validation.d.ts.map +1 -0
- package/dist/interface/payment/utils/validation.js +47 -0
- package/dist/interface/payment/utils/validation.js.map +1 -0
- package/dist/interface/public-utilities/spend-permission/index.d.ts +8 -0
- package/dist/interface/public-utilities/spend-permission/index.d.ts.map +1 -0
- package/dist/interface/public-utilities/spend-permission/index.js +8 -0
- package/dist/interface/public-utilities/spend-permission/index.js.map +1 -0
- package/dist/interface/public-utilities/spend-permission/methods/fetchPermissions.d.ts +14 -0
- package/dist/interface/public-utilities/spend-permission/methods/fetchPermissions.d.ts.map +1 -0
- package/dist/interface/public-utilities/spend-permission/methods/fetchPermissions.js +52 -0
- package/dist/interface/public-utilities/spend-permission/methods/fetchPermissions.js.map +1 -0
- package/dist/interface/public-utilities/spend-permission/methods/getHash.d.ts +9 -0
- package/dist/interface/public-utilities/spend-permission/methods/getHash.d.ts.map +1 -0
- package/dist/interface/public-utilities/spend-permission/methods/getHash.js +54 -0
- package/dist/interface/public-utilities/spend-permission/methods/getHash.js.map +1 -0
- package/dist/interface/public-utilities/spend-permission/methods/getPermissionStatus.d.ts +8 -0
- package/dist/interface/public-utilities/spend-permission/methods/getPermissionStatus.d.ts.map +1 -0
- package/dist/interface/public-utilities/spend-permission/methods/getPermissionStatus.js +85 -0
- package/dist/interface/public-utilities/spend-permission/methods/getPermissionStatus.js.map +1 -0
- package/dist/interface/public-utilities/spend-permission/methods/prepareRevokeCallData.d.ts +10 -0
- package/dist/interface/public-utilities/spend-permission/methods/prepareRevokeCallData.d.ts.map +1 -0
- package/dist/interface/public-utilities/spend-permission/methods/prepareRevokeCallData.js +51 -0
- package/dist/interface/public-utilities/spend-permission/methods/prepareRevokeCallData.js.map +1 -0
- package/dist/interface/public-utilities/spend-permission/methods/prepareSpendCallData.d.ts +11 -0
- package/dist/interface/public-utilities/spend-permission/methods/prepareSpendCallData.d.ts.map +1 -0
- package/dist/interface/public-utilities/spend-permission/methods/prepareSpendCallData.js +104 -0
- package/dist/interface/public-utilities/spend-permission/methods/prepareSpendCallData.js.map +1 -0
- package/dist/interface/public-utilities/spend-permission/methods/requestRevoke.d.ts +11 -0
- package/dist/interface/public-utilities/spend-permission/methods/requestRevoke.d.ts.map +1 -0
- package/dist/interface/public-utilities/spend-permission/methods/requestRevoke.js +64 -0
- package/dist/interface/public-utilities/spend-permission/methods/requestRevoke.js.map +1 -0
- package/dist/interface/public-utilities/spend-permission/methods/requestSpendPermission.d.ts +20 -0
- package/dist/interface/public-utilities/spend-permission/methods/requestSpendPermission.d.ts.map +1 -0
- package/dist/interface/public-utilities/spend-permission/methods/requestSpendPermission.js +67 -0
- package/dist/interface/public-utilities/spend-permission/methods/requestSpendPermission.js.map +1 -0
- package/dist/interface/public-utilities/spend-permission/utils.d.ts +81 -0
- package/dist/interface/public-utilities/spend-permission/utils.d.ts.map +1 -0
- package/dist/interface/public-utilities/spend-permission/utils.js +130 -0
- package/dist/interface/public-utilities/spend-permission/utils.js.map +1 -0
- package/dist/interface/public-utilities/spend-permission/withTelemetry.d.ts +2 -0
- package/dist/interface/public-utilities/spend-permission/withTelemetry.d.ts.map +1 -0
- package/dist/interface/public-utilities/spend-permission/withTelemetry.js +30 -0
- package/dist/interface/public-utilities/spend-permission/withTelemetry.js.map +1 -0
- package/dist/kms/crypto-key/index.d.ts +18 -0
- package/dist/kms/crypto-key/index.d.ts.map +1 -0
- package/dist/kms/crypto-key/index.js +97 -0
- package/dist/kms/crypto-key/index.js.map +1 -0
- package/dist/kms/crypto-key/storage.d.ts +7 -0
- package/dist/kms/crypto-key/storage.d.ts.map +1 -0
- package/dist/kms/crypto-key/storage.js +20 -0
- package/dist/kms/crypto-key/storage.js.map +1 -0
- package/dist/sign/app-sdk/SCWKeyManager.d.ts +15 -0
- package/dist/sign/app-sdk/SCWKeyManager.d.ts.map +1 -0
- package/dist/sign/app-sdk/SCWKeyManager.js +82 -0
- package/dist/sign/app-sdk/SCWKeyManager.js.map +1 -0
- package/dist/sign/app-sdk/Signer.d.ts +38 -0
- package/dist/sign/app-sdk/Signer.d.ts.map +1 -0
- package/dist/sign/app-sdk/Signer.js +659 -0
- package/dist/sign/app-sdk/Signer.js.map +1 -0
- package/dist/sign/app-sdk/utils/constants.d.ts +1945 -0
- package/dist/sign/app-sdk/utils/constants.d.ts.map +1 -0
- package/dist/sign/app-sdk/utils/constants.js +1321 -0
- package/dist/sign/app-sdk/utils/constants.js.map +1 -0
- package/dist/sign/app-sdk/utils/createSmartAccount.d.ts +63 -0
- package/dist/sign/app-sdk/utils/createSmartAccount.d.ts.map +1 -0
- package/dist/sign/app-sdk/utils/createSmartAccount.js +291 -0
- package/dist/sign/app-sdk/utils/createSmartAccount.js.map +1 -0
- package/dist/sign/app-sdk/utils/createSubAccountSigner.d.ts +23 -0
- package/dist/sign/app-sdk/utils/createSubAccountSigner.d.ts.map +1 -0
- package/dist/sign/app-sdk/utils/createSubAccountSigner.js +233 -0
- package/dist/sign/app-sdk/utils/createSubAccountSigner.js.map +1 -0
- package/dist/sign/app-sdk/utils/findOwnerIndex.d.ts +32 -0
- package/dist/sign/app-sdk/utils/findOwnerIndex.d.ts.map +1 -0
- package/dist/sign/app-sdk/utils/findOwnerIndex.js +56 -0
- package/dist/sign/app-sdk/utils/findOwnerIndex.js.map +1 -0
- package/dist/sign/app-sdk/utils/handleAddSubAccountOwner.d.ts +8 -0
- package/dist/sign/app-sdk/utils/handleAddSubAccountOwner.d.ts.map +1 -0
- package/dist/sign/app-sdk/utils/handleAddSubAccountOwner.js +78 -0
- package/dist/sign/app-sdk/utils/handleAddSubAccountOwner.js.map +1 -0
- package/dist/sign/app-sdk/utils/handleInsufficientBalance.d.ts +18 -0
- package/dist/sign/app-sdk/utils/handleInsufficientBalance.d.ts.map +1 -0
- package/dist/sign/app-sdk/utils/handleInsufficientBalance.js +27 -0
- package/dist/sign/app-sdk/utils/handleInsufficientBalance.js.map +1 -0
- package/dist/sign/app-sdk/utils/presentAddOwnerDialog.d.ts +2 -0
- package/dist/sign/app-sdk/utils/presentAddOwnerDialog.d.ts.map +1 -0
- package/dist/sign/app-sdk/utils/presentAddOwnerDialog.js +46 -0
- package/dist/sign/app-sdk/utils/presentAddOwnerDialog.js.map +1 -0
- package/dist/sign/app-sdk/utils/routeThroughGlobalAccount.d.ts +33 -0
- package/dist/sign/app-sdk/utils/routeThroughGlobalAccount.d.ts.map +1 -0
- package/dist/sign/app-sdk/utils/routeThroughGlobalAccount.js +76 -0
- package/dist/sign/app-sdk/utils/routeThroughGlobalAccount.js.map +1 -0
- package/dist/sign/app-sdk/utils.d.ts +220 -0
- package/dist/sign/app-sdk/utils.d.ts.map +1 -0
- package/dist/sign/app-sdk/utils.js +439 -0
- package/dist/sign/app-sdk/utils.js.map +1 -0
- package/dist/store/chain-clients/store.d.ts +10 -0
- package/dist/store/chain-clients/store.d.ts.map +1 -0
- package/dist/store/chain-clients/store.js +3 -0
- package/dist/store/chain-clients/store.js.map +1 -0
- package/dist/store/chain-clients/utils.d.ts +13 -0
- package/dist/store/chain-clients/utils.d.ts.map +1 -0
- package/dist/store/chain-clients/utils.js +77 -0
- package/dist/store/chain-clients/utils.js.map +1 -0
- package/dist/store/correlation-ids/store.d.ts +7 -0
- package/dist/store/correlation-ids/store.d.ts.map +1 -0
- package/dist/store/correlation-ids/store.js +32 -0
- package/dist/store/correlation-ids/store.js.map +1 -0
- package/dist/store/store.d.ts +186 -0
- package/dist/store/store.d.ts.map +1 -0
- package/dist/store/store.js +167 -0
- package/dist/store/store.js.map +1 -0
- package/dist/ui/Dialog/Dialog-css.d.ts +3 -0
- package/dist/ui/Dialog/Dialog-css.d.ts.map +1 -0
- package/dist/ui/Dialog/Dialog-css.js +2 -0
- package/dist/ui/Dialog/Dialog-css.js.map +1 -0
- package/dist/ui/Dialog/Dialog.d.ts +28 -0
- package/dist/ui/Dialog/Dialog.d.ts.map +1 -0
- package/dist/ui/Dialog/Dialog.js +150 -0
- package/dist/ui/Dialog/Dialog.js.map +1 -0
- package/dist/ui/Dialog/index.d.ts +3 -0
- package/dist/ui/Dialog/index.d.ts.map +1 -0
- package/dist/ui/Dialog/index.js +15 -0
- package/dist/ui/Dialog/index.js.map +1 -0
- package/dist/ui/assets/BaseLogo.d.ts +4 -0
- package/dist/ui/assets/BaseLogo.d.ts.map +1 -0
- package/dist/ui/assets/BaseLogo.js +7 -0
- package/dist/ui/assets/BaseLogo.js.map +1 -0
- package/dist/ui/assets/BasePayLogo.d.ts +3 -0
- package/dist/ui/assets/BasePayLogo.d.ts.map +1 -0
- package/dist/ui/assets/BasePayLogo.js +4 -0
- package/dist/ui/assets/BasePayLogo.js.map +1 -0
- package/dist/ui/assets/colors.d.ts +18 -0
- package/dist/ui/assets/colors.d.ts.map +1 -0
- package/dist/ui/assets/colors.js +19 -0
- package/dist/ui/assets/colors.js.map +1 -0
- package/dist/ui/assets/fontFaceCSS.d.ts +2 -0
- package/dist/ui/assets/fontFaceCSS.d.ts.map +1 -0
- package/dist/ui/assets/fontFaceCSS.js +11 -0
- package/dist/ui/assets/fontFaceCSS.js.map +1 -0
- package/dist/ui/assets/index.d.ts +6 -0
- package/dist/ui/assets/index.d.ts.map +1 -0
- package/dist/ui/assets/index.js +6 -0
- package/dist/ui/assets/index.js.map +1 -0
- package/dist/ui/assets/injectFontStyle.d.ts +2 -0
- package/dist/ui/assets/injectFontStyle.d.ts.map +1 -0
- package/dist/ui/assets/injectFontStyle.js +12 -0
- package/dist/ui/assets/injectFontStyle.js.map +1 -0
- package/dist/util/assertPresence.d.ts +3 -0
- package/dist/util/assertPresence.d.ts.map +1 -0
- package/dist/util/assertPresence.js +18 -0
- package/dist/util/assertPresence.js.map +1 -0
- package/dist/util/assertSubAccount.d.ts +3 -0
- package/dist/util/assertSubAccount.d.ts.map +1 -0
- package/dist/util/assertSubAccount.js +26 -0
- package/dist/util/assertSubAccount.js.map +1 -0
- package/dist/util/checkCrossOriginOpenerPolicy.d.ts +2 -0
- package/dist/util/checkCrossOriginOpenerPolicy.d.ts.map +1 -0
- package/dist/util/checkCrossOriginOpenerPolicy.js +56 -0
- package/dist/util/checkCrossOriginOpenerPolicy.js.map +1 -0
- package/dist/util/cipher.d.ts +12 -0
- package/dist/util/cipher.d.ts.map +1 -0
- package/dist/util/cipher.js +65 -0
- package/dist/util/cipher.js.map +1 -0
- package/dist/util/encoding.d.ts +20 -0
- package/dist/util/encoding.d.ts.map +1 -0
- package/dist/util/encoding.js +48 -0
- package/dist/util/encoding.js.map +1 -0
- package/dist/util/get.d.ts +2 -0
- package/dist/util/get.d.ts.map +1 -0
- package/dist/util/get.js +14 -0
- package/dist/util/get.js.map +1 -0
- package/dist/util/provider.d.ts +10 -0
- package/dist/util/provider.d.ts.map +1 -0
- package/dist/util/provider.js +56 -0
- package/dist/util/provider.js.map +1 -0
- package/dist/util/validatePreferences.d.ts +13 -0
- package/dist/util/validatePreferences.d.ts.map +1 -0
- package/dist/util/validatePreferences.js +30 -0
- package/dist/util/validatePreferences.js.map +1 -0
- package/dist/util/web.d.ts +3 -0
- package/dist/util/web.d.ts.map +1 -0
- package/dist/util/web.js +100 -0
- package/dist/util/web.js.map +1 -0
- package/dist/vendor-js/CCA/ca.d.ts +2 -0
- package/dist/vendor-js/CCA/ca.d.ts.map +1 -0
- package/dist/vendor-js/CCA/ca.js +4608 -0
- package/dist/vendor-js/CCA/ca.js.map +1 -0
- package/package.json +109 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Signer.d.ts","sourceRoot":"","sources":["../../../src/sign/app-sdk/Signer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAA;AAWjE,OAAO,EACN,WAAW,EACX,qBAAqB,EACrB,gBAAgB,EAChB,MAAM,6BAA6B,CAAA;AAkEpC,KAAK,kBAAkB,GAAG;IACzB,QAAQ,EAAE,WAAW,CAAA;IACrB,YAAY,EAAE,YAAY,CAAA;IAC1B,QAAQ,EAAE,qBAAqB,GAAG,IAAI,CAAA;CACtC,CAAA;AAED,qBAAa,MAAM;IAClB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAc;IAC3C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAe;IAC1C,OAAO,CAAC,QAAQ,CAA8B;IAE9C,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,KAAK,CAAU;gBAEX,MAAM,EAAE,kBAAkB;IAetC,IAAW,WAAW,YAErB;IAEK,SAAS,CAAC,IAAI,EAAE,gBAAgB;IAgDhC,OAAO,CAAC,OAAO,EAAE,gBAAgB;IAkBjC,QAAQ,CAAC,OAAO,EAAE,gBAAgB;YAuL1B,kBAAkB;YAWlB,cAAc;IAkFtB,OAAO;IAiBb;;;OAGG;YACW,wBAAwB;YAcxB,4BAA4B;YAmD5B,wBAAwB;YASxB,oBAAoB;YA0BpB,oBAAoB;YAkBpB,sBAAsB;IAmDpC,OAAO,CAAC,WAAW;YAmBL,aAAa;IA0D3B,OAAO,CAAC,gCAAgC;YAc1B,6BAA6B;CAqL3C"}
|
|
@@ -0,0 +1,659 @@
|
|
|
1
|
+
import { CB_WALLET_RPC_URL } from '../../core/constants.js';
|
|
2
|
+
import { hexToNumber, isAddressEqual, numberToHex } from 'viem';
|
|
3
|
+
import { isActionableHttpRequestError, isViemError, standardErrors, } from '../../core/error/errors.js';
|
|
4
|
+
import { logHandshakeCompleted, logHandshakeError, logHandshakeStarted, logRequestCompleted, logRequestError, logRequestStarted, } from '../../core/telemetry/events/scw-signer.js';
|
|
5
|
+
import { logAddOwnerCompleted, logAddOwnerError, logAddOwnerStarted, logInsufficientBalanceErrorHandlingCompleted, logInsufficientBalanceErrorHandlingError, logInsufficientBalanceErrorHandlingStarted, logSubAccountRequestCompleted, logSubAccountRequestError, logSubAccountRequestStarted, } from '../../core/telemetry/events/scw-sub-account.js';
|
|
6
|
+
import { parseErrorMessageFromAny } from '../../core/telemetry/utils.js';
|
|
7
|
+
import { ensureIntNumber, hexStringFromNumber } from '../../core/type/util.js';
|
|
8
|
+
import { FALLBACK_CHAINS, createClients, getClient, } from '../../store/chain-clients/utils.js';
|
|
9
|
+
import { correlationIds } from '../../store/correlation-ids/store.js';
|
|
10
|
+
import { spendPermissions, store } from '../../store/store.js';
|
|
11
|
+
import { assertArrayPresence, assertPresence } from '../../util/assertPresence.js';
|
|
12
|
+
import { assertSubAccount } from '../../util/assertSubAccount.js';
|
|
13
|
+
import { decryptContent, encryptContent, exportKeyToHexString, importKeyFromHexString, } from '../../util/cipher.js';
|
|
14
|
+
import { fetchRPCRequest } from '../../util/provider.js';
|
|
15
|
+
import { getCryptoKeyAccount } from '../../kms/crypto-key/index.js';
|
|
16
|
+
import { SCWKeyManager } from './SCWKeyManager.js';
|
|
17
|
+
import { addSenderToRequest, appendWithoutDuplicates, assertFetchPermissionsRequest, assertGetCapabilitiesParams, assertParamsChainId, fillMissingParamsForFetchPermissions, getCachedWalletConnectResponse, getSenderFromRequest, initSubAccountConfig, injectRequestCapabilities, makeDataSuffix, prependWithoutDuplicates, requestHasCapability, } from './utils.js';
|
|
18
|
+
import { createSubAccountSigner } from './utils/createSubAccountSigner.js';
|
|
19
|
+
import { findOwnerIndex } from './utils/findOwnerIndex.js';
|
|
20
|
+
import { handleAddSubAccountOwner } from './utils/handleAddSubAccountOwner.js';
|
|
21
|
+
import { handleInsufficientBalanceError } from './utils/handleInsufficientBalance.js';
|
|
22
|
+
import { routeThroughGlobalAccount } from './utils/routeThroughGlobalAccount.js';
|
|
23
|
+
export class Signer {
|
|
24
|
+
constructor(params) {
|
|
25
|
+
var _a, _b, _c, _d;
|
|
26
|
+
this.communicator = params.communicator;
|
|
27
|
+
this.callback = params.callback;
|
|
28
|
+
this.keyManager = new SCWKeyManager();
|
|
29
|
+
const { account, chains } = store.getState();
|
|
30
|
+
this.accounts = (_a = account.accounts) !== null && _a !== void 0 ? _a : [];
|
|
31
|
+
this.chain = (_b = account.chain) !== null && _b !== void 0 ? _b : {
|
|
32
|
+
id: (_d = (_c = params.metadata.appChainIds) === null || _c === void 0 ? void 0 : _c[0]) !== null && _d !== void 0 ? _d : 1,
|
|
33
|
+
};
|
|
34
|
+
// Use fallback chains if no chains are provided
|
|
35
|
+
createClients(chains !== null && chains !== void 0 ? chains : FALLBACK_CHAINS);
|
|
36
|
+
}
|
|
37
|
+
get isConnected() {
|
|
38
|
+
return this.accounts.length > 0;
|
|
39
|
+
}
|
|
40
|
+
async handshake(args) {
|
|
41
|
+
var _a, _b, _c;
|
|
42
|
+
const correlationId = correlationIds.get(args);
|
|
43
|
+
logHandshakeStarted({ method: args.method, correlationId });
|
|
44
|
+
try {
|
|
45
|
+
// Open the popup before constructing the request message.
|
|
46
|
+
// This is to ensure that the popup is not blocked by some browsers (i.e. Safari)
|
|
47
|
+
await ((_b = (_a = this.communicator).waitForPopupLoaded) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
48
|
+
const handshakeMessage = await this.createRequestMessage({
|
|
49
|
+
handshake: {
|
|
50
|
+
method: args.method,
|
|
51
|
+
params: (_c = args.params) !== null && _c !== void 0 ? _c : [],
|
|
52
|
+
},
|
|
53
|
+
}, correlationId);
|
|
54
|
+
const response = await this.communicator.postRequestAndWaitForResponse(handshakeMessage);
|
|
55
|
+
// store peer's public key
|
|
56
|
+
if ('failure' in response.content) {
|
|
57
|
+
throw response.content.failure;
|
|
58
|
+
}
|
|
59
|
+
const peerPublicKey = await importKeyFromHexString('public', response.sender);
|
|
60
|
+
await this.keyManager.setPeerPublicKey(peerPublicKey);
|
|
61
|
+
const decrypted = await this.decryptResponseMessage(response);
|
|
62
|
+
this.handleResponse(args, decrypted);
|
|
63
|
+
logHandshakeCompleted({ method: args.method, correlationId });
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
logHandshakeError({
|
|
67
|
+
method: args.method,
|
|
68
|
+
correlationId,
|
|
69
|
+
errorMessage: parseErrorMessageFromAny(error),
|
|
70
|
+
});
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async request(request) {
|
|
75
|
+
const correlationId = correlationIds.get(request);
|
|
76
|
+
logRequestStarted({ method: request.method, correlationId });
|
|
77
|
+
try {
|
|
78
|
+
const result = await this._request(request);
|
|
79
|
+
logRequestCompleted({ method: request.method, correlationId });
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
logRequestError({
|
|
84
|
+
method: request.method,
|
|
85
|
+
correlationId,
|
|
86
|
+
errorMessage: parseErrorMessageFromAny(error),
|
|
87
|
+
});
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async _request(request) {
|
|
92
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
93
|
+
if (this.accounts.length === 0) {
|
|
94
|
+
switch (request.method) {
|
|
95
|
+
case 'wallet_switchEthereumChain': {
|
|
96
|
+
assertParamsChainId(request.params);
|
|
97
|
+
this.chain.id = Number(request.params[0].chainId);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
case 'wallet_connect': {
|
|
101
|
+
// Wait for the popup to be loaded before making async calls
|
|
102
|
+
await ((_b = (_a = this.communicator).waitForPopupLoaded) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
103
|
+
await initSubAccountConfig();
|
|
104
|
+
// Check if addSubAccount capability is present and if so, inject the the sub account capabilities
|
|
105
|
+
let capabilitiesToInject = {};
|
|
106
|
+
if (requestHasCapability(request, 'addSubAccount')) {
|
|
107
|
+
capabilitiesToInject =
|
|
108
|
+
(_d = (_c = store.subAccountsConfig.get()) === null || _c === void 0 ? void 0 : _c.capabilities) !== null && _d !== void 0 ? _d : {};
|
|
109
|
+
}
|
|
110
|
+
const modifiedRequest = injectRequestCapabilities(request, capabilitiesToInject);
|
|
111
|
+
return this.sendRequestToPopup(modifiedRequest);
|
|
112
|
+
}
|
|
113
|
+
case 'wallet_sendCalls':
|
|
114
|
+
case 'wallet_sign': {
|
|
115
|
+
return this.sendRequestToPopup(request);
|
|
116
|
+
}
|
|
117
|
+
default:
|
|
118
|
+
throw standardErrors.provider.unauthorized();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (this.shouldRequestUseSubAccountSigner(request)) {
|
|
122
|
+
const correlationId = correlationIds.get(request);
|
|
123
|
+
logSubAccountRequestStarted({ method: request.method, correlationId });
|
|
124
|
+
try {
|
|
125
|
+
const result = await this.sendRequestToSubAccountSigner(request);
|
|
126
|
+
logSubAccountRequestCompleted({
|
|
127
|
+
method: request.method,
|
|
128
|
+
correlationId,
|
|
129
|
+
});
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
logSubAccountRequestError({
|
|
134
|
+
method: request.method,
|
|
135
|
+
correlationId,
|
|
136
|
+
errorMessage: parseErrorMessageFromAny(error),
|
|
137
|
+
});
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
switch (request.method) {
|
|
142
|
+
case 'eth_requestAccounts':
|
|
143
|
+
case 'eth_accounts': {
|
|
144
|
+
const subAccount = store.subAccounts.get();
|
|
145
|
+
const subAccountsConfig = store.subAccountsConfig.get();
|
|
146
|
+
if (subAccount === null || subAccount === void 0 ? void 0 : subAccount.address) {
|
|
147
|
+
// if auto sub accounts are enabled and we have a sub account, we need to return it as a top level account
|
|
148
|
+
// otherwise, we just append it to the accounts array
|
|
149
|
+
this.accounts = (subAccountsConfig === null || subAccountsConfig === void 0 ? void 0 : subAccountsConfig.enableAutoSubAccounts)
|
|
150
|
+
? prependWithoutDuplicates(this.accounts, subAccount.address)
|
|
151
|
+
: appendWithoutDuplicates(this.accounts, subAccount.address);
|
|
152
|
+
}
|
|
153
|
+
(_e = this.callback) === null || _e === void 0 ? void 0 : _e.call(this, 'connect', { chainId: numberToHex(this.chain.id) });
|
|
154
|
+
return this.accounts;
|
|
155
|
+
}
|
|
156
|
+
case 'eth_coinbase':
|
|
157
|
+
return this.accounts[0];
|
|
158
|
+
case 'net_version':
|
|
159
|
+
return this.chain.id;
|
|
160
|
+
case 'eth_chainId':
|
|
161
|
+
return numberToHex(this.chain.id);
|
|
162
|
+
case 'wallet_getCapabilities':
|
|
163
|
+
return this.handleGetCapabilitiesRequest(request);
|
|
164
|
+
case 'wallet_getUserInfo':
|
|
165
|
+
return this.handleGetUserInfoRequest(request);
|
|
166
|
+
case 'wallet_switchEthereumChain':
|
|
167
|
+
return this.handleSwitchChainRequest(request);
|
|
168
|
+
case 'eth_ecRecover':
|
|
169
|
+
case 'personal_sign':
|
|
170
|
+
case 'wallet_sign':
|
|
171
|
+
case 'personal_ecRecover':
|
|
172
|
+
case 'eth_signTransaction':
|
|
173
|
+
case 'eth_sendTransaction':
|
|
174
|
+
case 'eth_signTypedData_v1':
|
|
175
|
+
case 'eth_signTypedData_v3':
|
|
176
|
+
case 'eth_signTypedData_v4':
|
|
177
|
+
case 'eth_signTypedData':
|
|
178
|
+
case 'wallet_addEthereumChain':
|
|
179
|
+
case 'wallet_watchAsset':
|
|
180
|
+
case 'wallet_sendCalls':
|
|
181
|
+
case 'wallet_showCallsStatus':
|
|
182
|
+
case 'wallet_grantPermissions':
|
|
183
|
+
return this.sendRequestToPopup(request);
|
|
184
|
+
case 'wallet_connect': {
|
|
185
|
+
// Return cached wallet connect response if available, unless signInWithEthereum capability is present
|
|
186
|
+
// SIWE requires fresh signatures/nonces so we should not use cached responses
|
|
187
|
+
const hasSiweCapability = requestHasCapability(request, 'signInWithEthereum');
|
|
188
|
+
if (!hasSiweCapability) {
|
|
189
|
+
const cachedResponse = await getCachedWalletConnectResponse();
|
|
190
|
+
if (cachedResponse) {
|
|
191
|
+
return cachedResponse;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// Wait for the popup to be loaded before making async calls
|
|
195
|
+
await ((_g = (_f = this.communicator).waitForPopupLoaded) === null || _g === void 0 ? void 0 : _g.call(_f));
|
|
196
|
+
await initSubAccountConfig();
|
|
197
|
+
const subAccountsConfig = store.subAccountsConfig.get();
|
|
198
|
+
const modifiedRequest = injectRequestCapabilities(request, (_h = subAccountsConfig === null || subAccountsConfig === void 0 ? void 0 : subAccountsConfig.capabilities) !== null && _h !== void 0 ? _h : {});
|
|
199
|
+
const result = await this.sendRequestToPopup(modifiedRequest);
|
|
200
|
+
(_j = this.callback) === null || _j === void 0 ? void 0 : _j.call(this, 'connect', { chainId: numberToHex(this.chain.id) });
|
|
201
|
+
return result;
|
|
202
|
+
}
|
|
203
|
+
// Sub Account Support
|
|
204
|
+
case 'wallet_getSubAccounts': {
|
|
205
|
+
const subAccount = store.subAccounts.get();
|
|
206
|
+
if (subAccount === null || subAccount === void 0 ? void 0 : subAccount.address) {
|
|
207
|
+
return {
|
|
208
|
+
subAccounts: [subAccount],
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
if (!this.chain.rpcUrl) {
|
|
212
|
+
throw standardErrors.rpc.internal('No RPC URL set for chain');
|
|
213
|
+
}
|
|
214
|
+
const response = (await fetchRPCRequest(request, this.chain.rpcUrl));
|
|
215
|
+
assertArrayPresence(response.subAccounts, 'subAccounts');
|
|
216
|
+
if (response.subAccounts.length > 0) {
|
|
217
|
+
// cache the sub account
|
|
218
|
+
assertSubAccount(response.subAccounts[0]);
|
|
219
|
+
const subAccount = response.subAccounts[0];
|
|
220
|
+
store.subAccounts.set({
|
|
221
|
+
address: subAccount.address,
|
|
222
|
+
factory: subAccount.factory,
|
|
223
|
+
factoryData: subAccount.factoryData,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
return response;
|
|
227
|
+
}
|
|
228
|
+
case 'wallet_addSubAccount':
|
|
229
|
+
return this.addSubAccount(request);
|
|
230
|
+
case 'coinbase_fetchPermissions': {
|
|
231
|
+
assertFetchPermissionsRequest(request);
|
|
232
|
+
const completeRequest = fillMissingParamsForFetchPermissions(request);
|
|
233
|
+
const permissions = (await fetchRPCRequest(completeRequest, CB_WALLET_RPC_URL));
|
|
234
|
+
const requestedChainId = hexToNumber((_k = completeRequest.params) === null || _k === void 0 ? void 0 : _k[0].chainId);
|
|
235
|
+
store.spendPermissions.set(permissions.permissions.map((permission) => (Object.assign(Object.assign({}, permission), { chainId: requestedChainId }))));
|
|
236
|
+
return permissions;
|
|
237
|
+
}
|
|
238
|
+
default:
|
|
239
|
+
if (!this.chain.rpcUrl) {
|
|
240
|
+
throw standardErrors.rpc.internal('No RPC URL set for chain');
|
|
241
|
+
}
|
|
242
|
+
return fetchRPCRequest(request, this.chain.rpcUrl);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
async sendRequestToPopup(request) {
|
|
246
|
+
var _a, _b;
|
|
247
|
+
// Open the popup before constructing the request message.
|
|
248
|
+
// This is to ensure that the popup is not blocked by some browsers (i.e. Safari)
|
|
249
|
+
await ((_b = (_a = this.communicator).waitForPopupLoaded) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
250
|
+
const response = await this.sendEncryptedRequest(request);
|
|
251
|
+
const decrypted = await this.decryptResponseMessage(response);
|
|
252
|
+
return this.handleResponse(request, decrypted);
|
|
253
|
+
}
|
|
254
|
+
async handleResponse(request, decrypted) {
|
|
255
|
+
var _a, _b, _c, _d, _e;
|
|
256
|
+
const result = decrypted.result;
|
|
257
|
+
if ('error' in result)
|
|
258
|
+
throw result.error;
|
|
259
|
+
switch (request.method) {
|
|
260
|
+
case 'eth_requestAccounts': {
|
|
261
|
+
const accounts = result.value;
|
|
262
|
+
this.accounts = accounts;
|
|
263
|
+
store.account.set({
|
|
264
|
+
accounts,
|
|
265
|
+
chain: this.chain,
|
|
266
|
+
});
|
|
267
|
+
(_a = this.callback) === null || _a === void 0 ? void 0 : _a.call(this, 'accountsChanged', accounts);
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
case 'wallet_connect': {
|
|
271
|
+
const response = result.value;
|
|
272
|
+
const accounts = response.accounts.map((account) => account.address);
|
|
273
|
+
this.accounts = accounts;
|
|
274
|
+
store.account.set({
|
|
275
|
+
accounts,
|
|
276
|
+
});
|
|
277
|
+
const userInfo = response.userInfo;
|
|
278
|
+
store.userInfo.set(userInfo);
|
|
279
|
+
const account = response.accounts.at(0);
|
|
280
|
+
const capabilities = account === null || account === void 0 ? void 0 : account.capabilities;
|
|
281
|
+
if (capabilities === null || capabilities === void 0 ? void 0 : capabilities.subAccounts) {
|
|
282
|
+
const capabilityResponse = capabilities === null || capabilities === void 0 ? void 0 : capabilities.subAccounts;
|
|
283
|
+
assertArrayPresence(capabilityResponse, 'subAccounts');
|
|
284
|
+
assertSubAccount(capabilityResponse[0]);
|
|
285
|
+
store.subAccounts.set({
|
|
286
|
+
address: capabilityResponse[0].address,
|
|
287
|
+
factory: capabilityResponse[0].factory,
|
|
288
|
+
factoryData: capabilityResponse[0].factoryData,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
let accounts_ = [this.accounts[0]];
|
|
292
|
+
const subAccount = store.subAccounts.get();
|
|
293
|
+
const subAccountsConfig = store.subAccountsConfig.get();
|
|
294
|
+
if (subAccount === null || subAccount === void 0 ? void 0 : subAccount.address) {
|
|
295
|
+
// Sub account should be returned as a top level account if auto sub accounts are enabled
|
|
296
|
+
this.accounts = (subAccountsConfig === null || subAccountsConfig === void 0 ? void 0 : subAccountsConfig.enableAutoSubAccounts)
|
|
297
|
+
? prependWithoutDuplicates(this.accounts, subAccount.address)
|
|
298
|
+
: appendWithoutDuplicates(this.accounts, subAccount.address);
|
|
299
|
+
}
|
|
300
|
+
const spendPermissions = (_c = (_b = response === null || response === void 0 ? void 0 : response.accounts) === null || _b === void 0 ? void 0 : _b[0].capabilities) === null || _c === void 0 ? void 0 : _c.spendPermissions;
|
|
301
|
+
if (spendPermissions && 'permissions' in spendPermissions) {
|
|
302
|
+
store.spendPermissions.set(spendPermissions === null || spendPermissions === void 0 ? void 0 : spendPermissions.permissions);
|
|
303
|
+
}
|
|
304
|
+
(_d = this.callback) === null || _d === void 0 ? void 0 : _d.call(this, 'accountsChanged', accounts_);
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
case 'wallet_addSubAccount': {
|
|
308
|
+
assertSubAccount(result.value);
|
|
309
|
+
const subAccount = result.value;
|
|
310
|
+
store.subAccounts.set(subAccount);
|
|
311
|
+
const subAccountsConfig = store.subAccountsConfig.get();
|
|
312
|
+
this.accounts = (subAccountsConfig === null || subAccountsConfig === void 0 ? void 0 : subAccountsConfig.enableAutoSubAccounts)
|
|
313
|
+
? prependWithoutDuplicates(this.accounts, subAccount.address)
|
|
314
|
+
: appendWithoutDuplicates(this.accounts, subAccount.address);
|
|
315
|
+
(_e = this.callback) === null || _e === void 0 ? void 0 : _e.call(this, 'accountsChanged', this.accounts);
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
default:
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
return result.value;
|
|
322
|
+
}
|
|
323
|
+
async cleanup() {
|
|
324
|
+
var _a, _b;
|
|
325
|
+
const metadata = store.config.get().metadata;
|
|
326
|
+
await this.keyManager.clear();
|
|
327
|
+
// clear the store
|
|
328
|
+
store.account.clear();
|
|
329
|
+
store.subAccounts.clear();
|
|
330
|
+
store.spendPermissions.clear();
|
|
331
|
+
store.chains.clear();
|
|
332
|
+
// reset the signer
|
|
333
|
+
this.accounts = [];
|
|
334
|
+
this.chain = {
|
|
335
|
+
id: (_b = (_a = metadata === null || metadata === void 0 ? void 0 : metadata.appChainIds) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : 1,
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* @returns `null` if the request was successful.
|
|
340
|
+
* https://eips.ethereum.org/EIPS/eip-3326#wallet_switchethereumchain
|
|
341
|
+
*/
|
|
342
|
+
async handleSwitchChainRequest(request) {
|
|
343
|
+
assertParamsChainId(request.params);
|
|
344
|
+
const chainId = ensureIntNumber(request.params[0].chainId);
|
|
345
|
+
const localResult = this.updateChain(chainId);
|
|
346
|
+
if (localResult)
|
|
347
|
+
return null;
|
|
348
|
+
const popupResult = await this.sendRequestToPopup(request);
|
|
349
|
+
if (popupResult === null) {
|
|
350
|
+
this.updateChain(chainId);
|
|
351
|
+
}
|
|
352
|
+
return popupResult;
|
|
353
|
+
}
|
|
354
|
+
async handleGetCapabilitiesRequest(request) {
|
|
355
|
+
assertGetCapabilitiesParams(request.params);
|
|
356
|
+
const requestedAccount = request.params[0];
|
|
357
|
+
const filterChainIds = request.params[1]; // Optional second parameter
|
|
358
|
+
if (!this.accounts.some((account) => isAddressEqual(account, requestedAccount))) {
|
|
359
|
+
throw standardErrors.provider.unauthorized('no active account found when getting capabilities');
|
|
360
|
+
}
|
|
361
|
+
const capabilities = store.getState().account.capabilities;
|
|
362
|
+
// Return empty object if capabilities is undefined
|
|
363
|
+
if (!capabilities) {
|
|
364
|
+
return {};
|
|
365
|
+
}
|
|
366
|
+
// If no filter is provided, return all capabilities
|
|
367
|
+
if (!filterChainIds || filterChainIds.length === 0) {
|
|
368
|
+
return capabilities;
|
|
369
|
+
}
|
|
370
|
+
// Convert filter chain IDs to numbers once for efficient lookup
|
|
371
|
+
const filterChainNumbers = new Set(filterChainIds.map((chainId) => hexToNumber(chainId)));
|
|
372
|
+
// Filter capabilities
|
|
373
|
+
const filteredCapabilities = Object.fromEntries(Object.entries(capabilities).filter(([capabilityKey]) => {
|
|
374
|
+
try {
|
|
375
|
+
const capabilityChainNumber = hexToNumber(capabilityKey);
|
|
376
|
+
return filterChainNumbers.has(capabilityChainNumber);
|
|
377
|
+
}
|
|
378
|
+
catch (_a) {
|
|
379
|
+
// If capabilityKey is not a valid hex string, exclude it
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
}));
|
|
383
|
+
return filteredCapabilities;
|
|
384
|
+
}
|
|
385
|
+
async handleGetUserInfoRequest(_request) {
|
|
386
|
+
const userInfo = store.getState().userInfo;
|
|
387
|
+
if (!userInfo) {
|
|
388
|
+
throw standardErrors.provider.unauthorized('No user info found');
|
|
389
|
+
}
|
|
390
|
+
return userInfo;
|
|
391
|
+
}
|
|
392
|
+
async sendEncryptedRequest(request) {
|
|
393
|
+
const sharedSecret = await this.keyManager.getSharedSecret();
|
|
394
|
+
if (!sharedSecret) {
|
|
395
|
+
throw standardErrors.provider.unauthorized('No shared secret found when encrypting request');
|
|
396
|
+
}
|
|
397
|
+
const encrypted = await encryptContent({
|
|
398
|
+
action: request,
|
|
399
|
+
chainId: this.chain.id,
|
|
400
|
+
}, sharedSecret);
|
|
401
|
+
const correlationId = correlationIds.get(request);
|
|
402
|
+
const message = await this.createRequestMessage({ encrypted }, correlationId);
|
|
403
|
+
return this.communicator.postRequestAndWaitForResponse(message);
|
|
404
|
+
}
|
|
405
|
+
async createRequestMessage(content, correlationId) {
|
|
406
|
+
const publicKey = await exportKeyToHexString('public', await this.keyManager.getOwnPublicKey());
|
|
407
|
+
return {
|
|
408
|
+
id: crypto.randomUUID(),
|
|
409
|
+
correlationId,
|
|
410
|
+
sender: publicKey,
|
|
411
|
+
content,
|
|
412
|
+
timestamp: new Date(),
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
async decryptResponseMessage(message) {
|
|
416
|
+
var _a, _b, _c;
|
|
417
|
+
const content = message.content;
|
|
418
|
+
// throw protocol level error
|
|
419
|
+
if ('failure' in content) {
|
|
420
|
+
throw content.failure;
|
|
421
|
+
}
|
|
422
|
+
const sharedSecret = await this.keyManager.getSharedSecret();
|
|
423
|
+
if (!sharedSecret) {
|
|
424
|
+
throw standardErrors.provider.unauthorized('Invalid session: no shared secret found when decrypting response');
|
|
425
|
+
}
|
|
426
|
+
const response = await decryptContent(content.encrypted, sharedSecret);
|
|
427
|
+
const availableChains = (_a = response.data) === null || _a === void 0 ? void 0 : _a.chains;
|
|
428
|
+
if (availableChains) {
|
|
429
|
+
const nativeCurrencies = (_b = response.data) === null || _b === void 0 ? void 0 : _b.nativeCurrencies;
|
|
430
|
+
const chains = Object.entries(availableChains).map(([id, rpcUrl]) => {
|
|
431
|
+
const nativeCurrency = nativeCurrencies === null || nativeCurrencies === void 0 ? void 0 : nativeCurrencies[Number(id)];
|
|
432
|
+
return Object.assign({ id: Number(id), rpcUrl }, (nativeCurrency ? { nativeCurrency } : {}));
|
|
433
|
+
});
|
|
434
|
+
store.chains.set(chains);
|
|
435
|
+
this.updateChain(this.chain.id, chains);
|
|
436
|
+
createClients(chains);
|
|
437
|
+
}
|
|
438
|
+
const walletCapabilities = (_c = response.data) === null || _c === void 0 ? void 0 : _c.capabilities;
|
|
439
|
+
if (walletCapabilities) {
|
|
440
|
+
store.account.set({
|
|
441
|
+
capabilities: walletCapabilities,
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
return response;
|
|
445
|
+
}
|
|
446
|
+
updateChain(chainId, newAvailableChains) {
|
|
447
|
+
var _a;
|
|
448
|
+
const state = store.getState();
|
|
449
|
+
const chains = newAvailableChains !== null && newAvailableChains !== void 0 ? newAvailableChains : state.chains;
|
|
450
|
+
const chain = chains === null || chains === void 0 ? void 0 : chains.find((chain) => chain.id === chainId);
|
|
451
|
+
if (!chain)
|
|
452
|
+
return false;
|
|
453
|
+
if (chain !== this.chain) {
|
|
454
|
+
this.chain = chain;
|
|
455
|
+
store.account.set({
|
|
456
|
+
chain,
|
|
457
|
+
});
|
|
458
|
+
(_a = this.callback) === null || _a === void 0 ? void 0 : _a.call(this, 'chainChanged', hexStringFromNumber(chain.id));
|
|
459
|
+
}
|
|
460
|
+
return true;
|
|
461
|
+
}
|
|
462
|
+
async addSubAccount(request) {
|
|
463
|
+
var _a, _b, _c, _d;
|
|
464
|
+
const state = store.getState();
|
|
465
|
+
const subAccount = state.subAccount;
|
|
466
|
+
const subAccountsConfig = store.subAccountsConfig.get();
|
|
467
|
+
if (subAccount === null || subAccount === void 0 ? void 0 : subAccount.address) {
|
|
468
|
+
this.accounts = (subAccountsConfig === null || subAccountsConfig === void 0 ? void 0 : subAccountsConfig.enableAutoSubAccounts)
|
|
469
|
+
? prependWithoutDuplicates(this.accounts, subAccount.address)
|
|
470
|
+
: appendWithoutDuplicates(this.accounts, subAccount.address);
|
|
471
|
+
(_a = this.callback) === null || _a === void 0 ? void 0 : _a.call(this, 'accountsChanged', this.accounts);
|
|
472
|
+
return subAccount;
|
|
473
|
+
}
|
|
474
|
+
// Wait for the popup to be loaded before sending the request
|
|
475
|
+
await ((_c = (_b = this.communicator).waitForPopupLoaded) === null || _c === void 0 ? void 0 : _c.call(_b));
|
|
476
|
+
if (Array.isArray(request.params) &&
|
|
477
|
+
request.params.length > 0 &&
|
|
478
|
+
request.params[0].account &&
|
|
479
|
+
request.params[0].account.type === 'create') {
|
|
480
|
+
let keys;
|
|
481
|
+
if (request.params[0].account.keys &&
|
|
482
|
+
request.params[0].account.keys.length > 0) {
|
|
483
|
+
keys = request.params[0].account.keys;
|
|
484
|
+
}
|
|
485
|
+
else {
|
|
486
|
+
const config = (_d = store.subAccountsConfig.get()) !== null && _d !== void 0 ? _d : {};
|
|
487
|
+
const { account: ownerAccount } = config.toOwnerAccount
|
|
488
|
+
? await config.toOwnerAccount()
|
|
489
|
+
: await getCryptoKeyAccount();
|
|
490
|
+
if (!ownerAccount) {
|
|
491
|
+
throw standardErrors.provider.unauthorized('could not get subaccount owner account when adding sub account');
|
|
492
|
+
}
|
|
493
|
+
keys = [
|
|
494
|
+
{
|
|
495
|
+
type: ownerAccount.address ? 'address' : 'webauthn-p256',
|
|
496
|
+
publicKey: ownerAccount.address || ownerAccount.publicKey,
|
|
497
|
+
},
|
|
498
|
+
];
|
|
499
|
+
}
|
|
500
|
+
request.params[0].account.keys = keys;
|
|
501
|
+
}
|
|
502
|
+
const response = await this.sendRequestToPopup(request);
|
|
503
|
+
assertSubAccount(response);
|
|
504
|
+
return response;
|
|
505
|
+
}
|
|
506
|
+
shouldRequestUseSubAccountSigner(_request) {
|
|
507
|
+
// Always false since in our case sub accounts are smart accounts.
|
|
508
|
+
return false;
|
|
509
|
+
// Commented out in case we implement ERC-7895 in the future.
|
|
510
|
+
// const sender = getSenderFromRequest(request);
|
|
511
|
+
// const subAccount = store.subAccounts.get();
|
|
512
|
+
// if (sender) {
|
|
513
|
+
// return sender.toLowerCase() === subAccount?.address.toLowerCase();
|
|
514
|
+
// }
|
|
515
|
+
// return false;
|
|
516
|
+
}
|
|
517
|
+
async sendRequestToSubAccountSigner(request) {
|
|
518
|
+
var _a;
|
|
519
|
+
const subAccount = store.subAccounts.get();
|
|
520
|
+
const subAccountsConfig = store.subAccountsConfig.get();
|
|
521
|
+
const config = store.config.get();
|
|
522
|
+
assertPresence(subAccount === null || subAccount === void 0 ? void 0 : subAccount.address, standardErrors.provider.unauthorized('no active sub account when sending request to sub account signer'));
|
|
523
|
+
// Get the owner account from the config
|
|
524
|
+
const ownerAccount = (subAccountsConfig === null || subAccountsConfig === void 0 ? void 0 : subAccountsConfig.toOwnerAccount)
|
|
525
|
+
? await subAccountsConfig.toOwnerAccount()
|
|
526
|
+
: await getCryptoKeyAccount();
|
|
527
|
+
assertPresence(ownerAccount === null || ownerAccount === void 0 ? void 0 : ownerAccount.account, standardErrors.provider.unauthorized('no active sub account owner when sending request to sub account signer'));
|
|
528
|
+
const sender = getSenderFromRequest(request);
|
|
529
|
+
// if sender is undefined, we inject the active sub account
|
|
530
|
+
// address into the params for the supported request methods
|
|
531
|
+
if (sender === undefined) {
|
|
532
|
+
request = addSenderToRequest(request, subAccount.address);
|
|
533
|
+
}
|
|
534
|
+
const client = getClient(this.chain.id);
|
|
535
|
+
assertPresence(client, standardErrors.rpc.internal(`client not found for chainId ${this.chain.id} when sending request to sub account signer`));
|
|
536
|
+
const globalAccountAddress = this.accounts.find((account) => account.toLowerCase() !== subAccount.address.toLowerCase());
|
|
537
|
+
assertPresence(globalAccountAddress, standardErrors.provider.unauthorized('no global account found when sending request to sub account signer'));
|
|
538
|
+
const dataSuffix = makeDataSuffix({
|
|
539
|
+
attribution: (_a = config.preference) === null || _a === void 0 ? void 0 : _a.attribution,
|
|
540
|
+
dappOrigin: window.location.origin,
|
|
541
|
+
});
|
|
542
|
+
if (['eth_sendTransaction', 'wallet_sendCalls'].includes(request.method)) {
|
|
543
|
+
// If we have never had a spend permission, we need to do this tx through the global account
|
|
544
|
+
// Only perform this check if unstable_enableAutoSpendPermissions is enabled
|
|
545
|
+
const subAccountsConfig = store.subAccountsConfig.get();
|
|
546
|
+
if ((subAccountsConfig === null || subAccountsConfig === void 0 ? void 0 : subAccountsConfig.unstable_enableAutoSpendPermissions) !== false) {
|
|
547
|
+
const storedSpendPermissions = spendPermissions.get();
|
|
548
|
+
if (storedSpendPermissions.length === 0) {
|
|
549
|
+
const result = await routeThroughGlobalAccount({
|
|
550
|
+
request,
|
|
551
|
+
globalAccountAddress,
|
|
552
|
+
subAccountAddress: subAccount.address,
|
|
553
|
+
client,
|
|
554
|
+
globalAccountRequest: this.sendRequestToPopup.bind(this),
|
|
555
|
+
chainId: this.chain.id,
|
|
556
|
+
});
|
|
557
|
+
return result;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
const publicKey = ownerAccount.account.type === 'local'
|
|
562
|
+
? ownerAccount.account.address
|
|
563
|
+
: ownerAccount.account.publicKey;
|
|
564
|
+
let ownerIndex = await findOwnerIndex({
|
|
565
|
+
address: subAccount.address,
|
|
566
|
+
factory: subAccount.factory,
|
|
567
|
+
factoryData: subAccount.factoryData,
|
|
568
|
+
publicKey,
|
|
569
|
+
client,
|
|
570
|
+
});
|
|
571
|
+
if (ownerIndex === -1) {
|
|
572
|
+
const correlationId = correlationIds.get(request);
|
|
573
|
+
logAddOwnerStarted({ method: request.method, correlationId });
|
|
574
|
+
try {
|
|
575
|
+
ownerIndex = await handleAddSubAccountOwner({
|
|
576
|
+
ownerAccount: ownerAccount.account,
|
|
577
|
+
globalAccountRequest: this.sendRequestToPopup.bind(this),
|
|
578
|
+
chainId: this.chain.id,
|
|
579
|
+
});
|
|
580
|
+
logAddOwnerCompleted({ method: request.method, correlationId });
|
|
581
|
+
}
|
|
582
|
+
catch (error) {
|
|
583
|
+
logAddOwnerError({
|
|
584
|
+
method: request.method,
|
|
585
|
+
correlationId,
|
|
586
|
+
errorMessage: parseErrorMessageFromAny(error),
|
|
587
|
+
});
|
|
588
|
+
return standardErrors.provider.unauthorized('failed to add sub account owner when sending request to sub account signer');
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
const { request: subAccountRequest } = await createSubAccountSigner({
|
|
592
|
+
address: subAccount.address,
|
|
593
|
+
owner: ownerAccount.account,
|
|
594
|
+
client: client,
|
|
595
|
+
factory: subAccount.factory,
|
|
596
|
+
factoryData: subAccount.factoryData,
|
|
597
|
+
parentAddress: globalAccountAddress,
|
|
598
|
+
attribution: dataSuffix ? { suffix: dataSuffix } : undefined,
|
|
599
|
+
ownerIndex,
|
|
600
|
+
});
|
|
601
|
+
try {
|
|
602
|
+
const result = await subAccountRequest(request);
|
|
603
|
+
return result;
|
|
604
|
+
}
|
|
605
|
+
catch (error) {
|
|
606
|
+
// Skip insufficient balance error handling if unstable_enableAutoSpendPermissions is disabled
|
|
607
|
+
const subAccountsConfig = store.subAccountsConfig.get();
|
|
608
|
+
if ((subAccountsConfig === null || subAccountsConfig === void 0 ? void 0 : subAccountsConfig.unstable_enableAutoSpendPermissions) === false) {
|
|
609
|
+
throw error;
|
|
610
|
+
}
|
|
611
|
+
let errorObject;
|
|
612
|
+
if (isViemError(error)) {
|
|
613
|
+
errorObject = JSON.parse(error.details);
|
|
614
|
+
}
|
|
615
|
+
else if (isActionableHttpRequestError(error)) {
|
|
616
|
+
errorObject = error;
|
|
617
|
+
}
|
|
618
|
+
else {
|
|
619
|
+
throw error;
|
|
620
|
+
}
|
|
621
|
+
if (!(isActionableHttpRequestError(errorObject) && errorObject.data)) {
|
|
622
|
+
throw error;
|
|
623
|
+
}
|
|
624
|
+
if (!errorObject.data) {
|
|
625
|
+
throw error;
|
|
626
|
+
}
|
|
627
|
+
const correlationId = correlationIds.get(request);
|
|
628
|
+
logInsufficientBalanceErrorHandlingStarted({
|
|
629
|
+
method: request.method,
|
|
630
|
+
correlationId,
|
|
631
|
+
});
|
|
632
|
+
try {
|
|
633
|
+
const result = await handleInsufficientBalanceError({
|
|
634
|
+
errorData: errorObject.data,
|
|
635
|
+
globalAccountAddress,
|
|
636
|
+
subAccountAddress: subAccount.address,
|
|
637
|
+
client,
|
|
638
|
+
request,
|
|
639
|
+
globalAccountRequest: this.request.bind(this),
|
|
640
|
+
});
|
|
641
|
+
logInsufficientBalanceErrorHandlingCompleted({
|
|
642
|
+
method: request.method,
|
|
643
|
+
correlationId,
|
|
644
|
+
});
|
|
645
|
+
return result;
|
|
646
|
+
}
|
|
647
|
+
catch (handlingError) {
|
|
648
|
+
console.error(handlingError);
|
|
649
|
+
logInsufficientBalanceErrorHandlingError({
|
|
650
|
+
method: request.method,
|
|
651
|
+
correlationId,
|
|
652
|
+
errorMessage: parseErrorMessageFromAny(handlingError),
|
|
653
|
+
});
|
|
654
|
+
throw error;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
//# sourceMappingURL=Signer.js.map
|