@zerodev/wallet-core 0.0.1-alpha.9 → 0.0.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 +68 -18
- package/dist/_cjs/actions/auth/authenticateWithEmail.js +1 -2
- package/dist/_cjs/actions/auth/authenticateWithEmail.js.map +1 -1
- package/dist/_cjs/actions/auth/authenticateWithOAuth.js +2 -3
- package/dist/_cjs/actions/auth/authenticateWithOAuth.js.map +1 -1
- package/dist/_cjs/actions/auth/getAuthProxyConfigId.js +10 -0
- package/dist/_cjs/actions/auth/getAuthProxyConfigId.js.map +1 -0
- package/dist/_cjs/actions/auth/getAuthenticators.js +16 -0
- package/dist/_cjs/actions/auth/getAuthenticators.js.map +1 -0
- package/dist/_cjs/actions/auth/getOAuthLoginUrl.js +18 -0
- package/dist/_cjs/actions/auth/getOAuthLoginUrl.js.map +1 -0
- package/dist/_cjs/actions/auth/getParentOrgId.js +10 -0
- package/dist/_cjs/actions/auth/getParentOrgId.js.map +1 -0
- package/dist/_cjs/actions/auth/getWhoami.js +18 -4
- package/dist/_cjs/actions/auth/getWhoami.js.map +1 -1
- package/dist/_cjs/actions/auth/index.js +9 -3
- package/dist/_cjs/actions/auth/index.js.map +1 -1
- package/dist/_cjs/actions/auth/loginWithStamp.js +5 -6
- package/dist/_cjs/actions/auth/loginWithStamp.js.map +1 -1
- package/dist/_cjs/actions/auth/registerWithOTP.js +1 -2
- package/dist/_cjs/actions/auth/registerWithOTP.js.map +1 -1
- package/dist/_cjs/actions/auth/registerWithPasskey.js +1 -2
- package/dist/_cjs/actions/auth/registerWithPasskey.js.map +1 -1
- package/dist/_cjs/actions/index.js +9 -3
- package/dist/_cjs/actions/index.js.map +1 -1
- package/dist/_cjs/actions/wallet/getUserWallet.js +3 -5
- package/dist/_cjs/actions/wallet/getUserWallet.js.map +1 -1
- package/dist/_cjs/actions/wallet/index.js +9 -3
- package/dist/_cjs/actions/wallet/index.js.map +1 -1
- package/dist/_cjs/actions/wallet/sign7702Authorization.js +16 -0
- package/dist/_cjs/actions/wallet/sign7702Authorization.js.map +1 -0
- package/dist/_cjs/actions/wallet/signMessage.js +17 -0
- package/dist/_cjs/actions/wallet/signMessage.js.map +1 -0
- package/dist/_cjs/actions/wallet/signTransaction.js +9 -18
- package/dist/_cjs/actions/wallet/signTransaction.js.map +1 -1
- package/dist/_cjs/actions/wallet/signTypedDataV4.js +17 -0
- package/dist/_cjs/actions/wallet/signTypedDataV4.js.map +1 -0
- package/dist/_cjs/actions/wallet/signUserOperation.js +17 -0
- package/dist/_cjs/actions/wallet/signUserOperation.js.map +1 -0
- package/dist/_cjs/actions/wallet/signingUtils.js +64 -0
- package/dist/_cjs/actions/wallet/signingUtils.js.map +1 -0
- package/dist/_cjs/adapters/viem.js +60 -27
- package/dist/_cjs/adapters/viem.js.map +1 -1
- package/dist/_cjs/client/authProxy.js +1 -1
- package/dist/_cjs/client/authProxy.js.map +1 -1
- package/dist/_cjs/client/createClient.js +5 -5
- package/dist/_cjs/client/createClient.js.map +1 -1
- package/dist/_cjs/client/decorators/client.js +9 -4
- package/dist/_cjs/client/decorators/client.js.map +1 -1
- package/dist/_cjs/client/index.js.map +1 -1
- package/dist/_cjs/client/transports/createTransport.js +6 -5
- package/dist/_cjs/client/transports/createTransport.js.map +1 -1
- package/dist/_cjs/client/transports/rest.js +40 -28
- package/dist/_cjs/client/transports/rest.js.map +1 -1
- package/dist/_cjs/constants.js +4 -4
- package/dist/_cjs/constants.js.map +1 -1
- package/dist/_cjs/core/{createZeroDevWallet.js → createZeroDevWalletCore.js} +94 -86
- package/dist/_cjs/core/createZeroDevWalletCore.js.map +1 -0
- package/dist/_cjs/index.js +14 -8
- package/dist/_cjs/index.js.map +1 -1
- package/dist/_cjs/index.native.js +39 -0
- package/dist/_cjs/index.native.js.map +1 -0
- package/dist/_cjs/native/createZeroDevWallet.js +13 -0
- package/dist/_cjs/native/createZeroDevWallet.js.map +1 -0
- package/dist/_cjs/native/stampers/passkey.js +30 -0
- package/dist/_cjs/native/stampers/passkey.js.map +1 -0
- package/dist/_cjs/native/stampers/secureStore.js +112 -0
- package/dist/_cjs/native/stampers/secureStore.js.map +1 -0
- package/dist/_cjs/native/storage/asyncStorage.js +11 -0
- package/dist/_cjs/native/storage/asyncStorage.js.map +1 -0
- package/dist/_cjs/stampers/iframeStamper.js +3 -0
- package/dist/_cjs/stampers/iframeStamper.js.map +1 -1
- package/dist/_cjs/stampers/indexedDbStamper.js +20 -2
- package/dist/_cjs/stampers/indexedDbStamper.js.map +1 -1
- package/dist/_cjs/stampers/noopPasskeyStamper.js +16 -0
- package/dist/_cjs/stampers/noopPasskeyStamper.js.map +1 -0
- package/dist/_cjs/stampers/webauthnStamper.js +23 -3
- package/dist/_cjs/stampers/webauthnStamper.js.map +1 -1
- package/dist/_cjs/stubs/native-on-web.js +12 -0
- package/dist/_cjs/stubs/native-on-web.js.map +1 -0
- package/dist/_cjs/utils/encryptOtpAttempt.js +57 -0
- package/dist/_cjs/utils/encryptOtpAttempt.js.map +1 -0
- package/dist/_cjs/utils/exportPrivateKey.js +1 -1
- package/dist/_cjs/utils/exportPrivateKey.js.map +1 -1
- package/dist/_cjs/utils/exportWallet.js +52 -61
- package/dist/_cjs/utils/exportWallet.js.map +1 -1
- package/dist/_cjs/utils/hpke.js +78 -0
- package/dist/_cjs/utils/hpke.js.map +1 -0
- package/dist/_cjs/utils/platform.js +19 -0
- package/dist/_cjs/utils/platform.js.map +1 -0
- package/dist/_cjs/utils/resolveOrganizationId.js +20 -0
- package/dist/_cjs/utils/resolveOrganizationId.js.map +1 -0
- package/dist/_cjs/utils/utils.js +5 -6
- package/dist/_cjs/utils/utils.js.map +1 -1
- package/dist/_cjs/web/createZeroDevWallet.js +21 -0
- package/dist/_cjs/web/createZeroDevWallet.js.map +1 -0
- package/dist/_esm/actions/auth/authenticateWithEmail.js +1 -2
- package/dist/_esm/actions/auth/authenticateWithEmail.js.map +1 -1
- package/dist/_esm/actions/auth/authenticateWithOAuth.js +8 -7
- package/dist/_esm/actions/auth/authenticateWithOAuth.js.map +1 -1
- package/dist/_esm/actions/auth/getAuthProxyConfigId.js +13 -0
- package/dist/_esm/actions/auth/getAuthProxyConfigId.js.map +1 -0
- package/dist/_esm/actions/auth/getAuthenticators.js +36 -0
- package/dist/_esm/actions/auth/getAuthenticators.js.map +1 -0
- package/dist/_esm/actions/auth/getOAuthLoginUrl.js +23 -0
- package/dist/_esm/actions/auth/getOAuthLoginUrl.js.map +1 -0
- package/dist/_esm/actions/auth/getParentOrgId.js +17 -0
- package/dist/_esm/actions/auth/getParentOrgId.js.map +1 -0
- package/dist/_esm/actions/auth/getWhoami.js +28 -6
- package/dist/_esm/actions/auth/getWhoami.js.map +1 -1
- package/dist/_esm/actions/auth/index.js +4 -1
- package/dist/_esm/actions/auth/index.js.map +1 -1
- package/dist/_esm/actions/auth/loginWithStamp.js +9 -6
- package/dist/_esm/actions/auth/loginWithStamp.js.map +1 -1
- package/dist/_esm/actions/auth/registerWithOTP.js +5 -2
- package/dist/_esm/actions/auth/registerWithOTP.js.map +1 -1
- package/dist/_esm/actions/auth/registerWithPasskey.js +1 -3
- package/dist/_esm/actions/auth/registerWithPasskey.js.map +1 -1
- package/dist/_esm/actions/index.js +2 -2
- package/dist/_esm/actions/index.js.map +1 -1
- package/dist/_esm/actions/wallet/getUserWallet.js +5 -5
- package/dist/_esm/actions/wallet/getUserWallet.js.map +1 -1
- package/dist/_esm/actions/wallet/index.js +4 -1
- package/dist/_esm/actions/wallet/index.js.map +1 -1
- package/dist/_esm/actions/wallet/sign7702Authorization.js +13 -0
- package/dist/_esm/actions/wallet/sign7702Authorization.js.map +1 -0
- package/dist/_esm/actions/wallet/signMessage.js +14 -0
- package/dist/_esm/actions/wallet/signMessage.js.map +1 -0
- package/dist/_esm/actions/wallet/signTransaction.js +9 -36
- package/dist/_esm/actions/wallet/signTransaction.js.map +1 -1
- package/dist/_esm/actions/wallet/signTypedDataV4.js +14 -0
- package/dist/_esm/actions/wallet/signTypedDataV4.js.map +1 -0
- package/dist/_esm/actions/wallet/signUserOperation.js +14 -0
- package/dist/_esm/actions/wallet/signUserOperation.js.map +1 -0
- package/dist/_esm/actions/wallet/signingUtils.js +69 -0
- package/dist/_esm/actions/wallet/signingUtils.js.map +1 -0
- package/dist/_esm/adapters/viem.js +63 -30
- package/dist/_esm/adapters/viem.js.map +1 -1
- package/dist/_esm/client/authProxy.js +9 -4
- package/dist/_esm/client/authProxy.js.map +1 -1
- package/dist/_esm/client/createClient.js +5 -5
- package/dist/_esm/client/createClient.js.map +1 -1
- package/dist/_esm/client/decorators/client.js +9 -4
- package/dist/_esm/client/decorators/client.js.map +1 -1
- package/dist/_esm/client/index.js +1 -1
- package/dist/_esm/client/index.js.map +1 -1
- package/dist/_esm/client/transports/createTransport.js +6 -5
- package/dist/_esm/client/transports/createTransport.js.map +1 -1
- package/dist/_esm/client/transports/rest.js +44 -29
- package/dist/_esm/client/transports/rest.js.map +1 -1
- package/dist/_esm/constants.js +10 -3
- package/dist/_esm/constants.js.map +1 -1
- package/dist/_esm/core/{createZeroDevWallet.js → createZeroDevWalletCore.js} +115 -90
- package/dist/_esm/core/createZeroDevWalletCore.js.map +1 -0
- package/dist/_esm/index.js +13 -5
- package/dist/_esm/index.js.map +1 -1
- package/dist/_esm/index.native.js +19 -0
- package/dist/_esm/index.native.js.map +1 -0
- package/dist/_esm/native/createZeroDevWallet.js +10 -0
- package/dist/_esm/native/createZeroDevWallet.js.map +1 -0
- package/dist/_esm/native/stampers/passkey.js +27 -0
- package/dist/_esm/native/stampers/passkey.js.map +1 -0
- package/dist/_esm/native/stampers/secureStore.js +120 -0
- package/dist/_esm/native/stampers/secureStore.js.map +1 -0
- package/dist/_esm/native/storage/asyncStorage.js +13 -0
- package/dist/_esm/native/storage/asyncStorage.js.map +1 -0
- package/dist/_esm/stampers/iframeStamper.js +3 -0
- package/dist/_esm/stampers/iframeStamper.js.map +1 -1
- package/dist/_esm/stampers/indexedDbStamper.js +20 -2
- package/dist/_esm/stampers/indexedDbStamper.js.map +1 -1
- package/dist/_esm/stampers/noopPasskeyStamper.js +18 -0
- package/dist/_esm/stampers/noopPasskeyStamper.js.map +1 -0
- package/dist/_esm/stampers/webauthnStamper.js +23 -4
- package/dist/_esm/stampers/webauthnStamper.js.map +1 -1
- package/dist/_esm/stubs/native-on-web.js +25 -0
- package/dist/_esm/stubs/native-on-web.js.map +1 -0
- package/dist/_esm/utils/encryptOtpAttempt.js +81 -0
- package/dist/_esm/utils/encryptOtpAttempt.js.map +1 -0
- package/dist/_esm/utils/exportPrivateKey.js +1 -1
- package/dist/_esm/utils/exportPrivateKey.js.map +1 -1
- package/dist/_esm/utils/exportWallet.js +52 -61
- package/dist/_esm/utils/exportWallet.js.map +1 -1
- package/dist/_esm/utils/hpke.js +119 -0
- package/dist/_esm/utils/hpke.js.map +1 -0
- package/dist/_esm/utils/platform.js +16 -0
- package/dist/_esm/utils/platform.js.map +1 -0
- package/dist/_esm/utils/resolveOrganizationId.js +27 -0
- package/dist/_esm/utils/resolveOrganizationId.js.map +1 -0
- package/dist/_esm/utils/utils.js +5 -6
- package/dist/_esm/utils/utils.js.map +1 -1
- package/dist/_esm/web/createZeroDevWallet.js +18 -0
- package/dist/_esm/web/createZeroDevWallet.js.map +1 -0
- package/dist/_types/actions/auth/authenticateWithEmail.d.ts +0 -6
- package/dist/_types/actions/auth/authenticateWithEmail.d.ts.map +1 -1
- package/dist/_types/actions/auth/authenticateWithOAuth.d.ts +10 -4
- package/dist/_types/actions/auth/authenticateWithOAuth.d.ts.map +1 -1
- package/dist/_types/actions/auth/getAuthProxyConfigId.d.ts +12 -0
- package/dist/_types/actions/auth/getAuthProxyConfigId.d.ts.map +1 -0
- package/dist/_types/actions/auth/getAuthenticators.d.ts +65 -0
- package/dist/_types/actions/auth/getAuthenticators.d.ts.map +1 -0
- package/dist/_types/actions/auth/getOAuthLoginUrl.d.ts +30 -0
- package/dist/_types/actions/auth/getOAuthLoginUrl.d.ts.map +1 -0
- package/dist/_types/actions/auth/getParentOrgId.d.ts +17 -0
- package/dist/_types/actions/auth/getParentOrgId.d.ts.map +1 -0
- package/dist/_types/actions/auth/getWhoami.d.ts +9 -2
- package/dist/_types/actions/auth/getWhoami.d.ts.map +1 -1
- package/dist/_types/actions/auth/index.d.ts +5 -2
- package/dist/_types/actions/auth/index.d.ts.map +1 -1
- package/dist/_types/actions/auth/loginWithStamp.d.ts +2 -5
- package/dist/_types/actions/auth/loginWithStamp.d.ts.map +1 -1
- package/dist/_types/actions/auth/registerWithOTP.d.ts +10 -3
- package/dist/_types/actions/auth/registerWithOTP.d.ts.map +1 -1
- package/dist/_types/actions/auth/registerWithPasskey.d.ts +0 -7
- package/dist/_types/actions/auth/registerWithPasskey.d.ts.map +1 -1
- package/dist/_types/actions/index.d.ts +2 -2
- package/dist/_types/actions/index.d.ts.map +1 -1
- package/dist/_types/actions/wallet/index.d.ts +4 -1
- package/dist/_types/actions/wallet/index.d.ts.map +1 -1
- package/dist/_types/actions/wallet/sign7702Authorization.d.ts +19 -0
- package/dist/_types/actions/wallet/sign7702Authorization.d.ts.map +1 -0
- package/dist/_types/actions/wallet/signMessage.d.ts +19 -0
- package/dist/_types/actions/wallet/signMessage.d.ts.map +1 -0
- package/dist/_types/actions/wallet/signTransaction.d.ts +1 -19
- package/dist/_types/actions/wallet/signTransaction.d.ts.map +1 -1
- package/dist/_types/actions/wallet/signTypedDataV4.d.ts +21 -0
- package/dist/_types/actions/wallet/signTypedDataV4.d.ts.map +1 -0
- package/dist/_types/actions/wallet/signUserOperation.d.ts +21 -0
- package/dist/_types/actions/wallet/signUserOperation.d.ts.map +1 -0
- package/dist/_types/actions/wallet/signingUtils.d.ts +32 -0
- package/dist/_types/actions/wallet/signingUtils.d.ts.map +1 -0
- package/dist/_types/adapters/viem.d.ts +1 -1
- package/dist/_types/adapters/viem.d.ts.map +1 -1
- package/dist/_types/client/authProxy.d.ts +13 -7
- package/dist/_types/client/authProxy.d.ts.map +1 -1
- package/dist/_types/client/decorators/client.d.ts +32 -6
- package/dist/_types/client/decorators/client.d.ts.map +1 -1
- package/dist/_types/client/index.d.ts +1 -1
- package/dist/_types/client/index.d.ts.map +1 -1
- package/dist/_types/client/transports/createTransport.d.ts +2 -0
- package/dist/_types/client/transports/createTransport.d.ts.map +1 -1
- package/dist/_types/client/transports/rest.d.ts +13 -5
- package/dist/_types/client/transports/rest.d.ts.map +1 -1
- package/dist/_types/client/types.d.ts +9 -9
- package/dist/_types/client/types.d.ts.map +1 -1
- package/dist/_types/constants.d.ts +3 -3
- package/dist/_types/constants.d.ts.map +1 -1
- package/dist/_types/core/{createZeroDevWallet.d.ts → createZeroDevWalletCore.d.ts} +30 -10
- package/dist/_types/core/createZeroDevWalletCore.d.ts.map +1 -0
- package/dist/_types/index.d.ts +7 -7
- package/dist/_types/index.d.ts.map +1 -1
- package/dist/_types/index.native.d.ts +19 -0
- package/dist/_types/index.native.d.ts.map +1 -0
- package/dist/_types/native/createZeroDevWallet.d.ts +12 -0
- package/dist/_types/native/createZeroDevWallet.d.ts.map +1 -0
- package/dist/_types/native/stampers/passkey.d.ts +5 -0
- package/dist/_types/native/stampers/passkey.d.ts.map +1 -0
- package/dist/_types/native/stampers/secureStore.d.ts +3 -0
- package/dist/_types/native/stampers/secureStore.d.ts.map +1 -0
- package/dist/_types/native/storage/asyncStorage.d.ts +3 -0
- package/dist/_types/native/storage/asyncStorage.d.ts.map +1 -0
- package/dist/_types/stampers/iframeStamper.d.ts.map +1 -1
- package/dist/_types/stampers/indexedDbStamper.d.ts +2 -2
- package/dist/_types/stampers/indexedDbStamper.d.ts.map +1 -1
- package/dist/_types/stampers/noopPasskeyStamper.d.ts +8 -0
- package/dist/_types/stampers/noopPasskeyStamper.d.ts.map +1 -0
- package/dist/_types/stampers/types.d.ts +39 -5
- package/dist/_types/stampers/types.d.ts.map +1 -1
- package/dist/_types/stampers/webauthnStamper.d.ts +2 -2
- package/dist/_types/stampers/webauthnStamper.d.ts.map +1 -1
- package/dist/_types/stubs/native-on-web.d.ts +6 -0
- package/dist/_types/stubs/native-on-web.d.ts.map +1 -0
- package/dist/_types/types/session.d.ts +2 -3
- package/dist/_types/types/session.d.ts.map +1 -1
- package/dist/_types/utils/buildClientSignature.d.ts +3 -3
- package/dist/_types/utils/buildClientSignature.d.ts.map +1 -1
- package/dist/_types/utils/encryptOtpAttempt.d.ts +40 -0
- package/dist/_types/utils/encryptOtpAttempt.d.ts.map +1 -0
- package/dist/_types/utils/exportPrivateKey.d.ts +1 -1
- package/dist/_types/utils/exportPrivateKey.d.ts.map +1 -1
- package/dist/_types/utils/exportWallet.d.ts +1 -1
- package/dist/_types/utils/exportWallet.d.ts.map +1 -1
- package/dist/_types/utils/hpke.d.ts +38 -0
- package/dist/_types/utils/hpke.d.ts.map +1 -0
- package/dist/_types/utils/platform.d.ts +2 -0
- package/dist/_types/utils/platform.d.ts.map +1 -0
- package/dist/_types/utils/resolveOrganizationId.d.ts +16 -0
- package/dist/_types/utils/resolveOrganizationId.d.ts.map +1 -0
- package/dist/_types/utils/utils.d.ts.map +1 -1
- package/dist/_types/web/createZeroDevWallet.d.ts +18 -0
- package/dist/_types/web/createZeroDevWallet.d.ts.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +100 -11
- package/src/actions/auth/authenticateWithEmail.ts +1 -9
- package/src/actions/auth/authenticateWithOAuth.ts +12 -7
- package/src/actions/auth/getAuthProxyConfigId.ts +20 -0
- package/src/actions/auth/getAuthenticators.ts +89 -0
- package/src/actions/auth/getOAuthLoginUrl.ts +48 -0
- package/src/actions/auth/getParentOrgId.ts +25 -0
- package/src/actions/auth/getWhoami.ts +33 -6
- package/src/actions/auth/index.ts +21 -5
- package/src/actions/auth/loginWithStamp.ts +11 -12
- package/src/actions/auth/registerWithOTP.ts +11 -5
- package/src/actions/auth/registerWithPasskey.ts +1 -10
- package/src/actions/index.ts +26 -7
- package/src/actions/wallet/getUserWallet.ts +5 -5
- package/src/actions/wallet/index.ts +22 -4
- package/src/actions/wallet/sign7702Authorization.ts +48 -0
- package/src/actions/wallet/signMessage.ts +47 -0
- package/src/actions/wallet/signTransaction.ts +19 -38
- package/src/actions/wallet/signTypedDataV4.ts +52 -0
- package/src/actions/wallet/signUserOperation.ts +56 -0
- package/src/actions/wallet/signingUtils.ts +110 -0
- package/src/adapters/viem.ts +75 -43
- package/src/client/authProxy.ts +14 -8
- package/src/client/createClient.ts +6 -6
- package/src/client/decorators/client.ts +78 -19
- package/src/client/index.ts +4 -1
- package/src/client/transports/createTransport.ts +8 -5
- package/src/client/transports/rest.ts +57 -34
- package/src/client/types.ts +9 -9
- package/src/constants.ts +12 -4
- package/src/core/{createZeroDevWallet.ts → createZeroDevWalletCore.ts} +147 -122
- package/src/index.native.ts +102 -0
- package/src/index.ts +49 -16
- package/src/native/createZeroDevWallet.ts +26 -0
- package/src/native/stampers/passkey.ts +39 -0
- package/src/native/stampers/secureStore.ts +139 -0
- package/src/native/storage/asyncStorage.ts +18 -0
- package/src/stampers/iframeStamper.ts +3 -0
- package/src/stampers/indexedDbStamper.ts +27 -4
- package/src/stampers/noopPasskeyStamper.ts +21 -0
- package/src/stampers/types.ts +39 -5
- package/src/stampers/webauthnStamper.ts +27 -6
- package/src/stubs/native-on-web.ts +29 -0
- package/src/types/session.ts +2 -3
- package/src/utils/buildClientSignature.ts +3 -3
- package/src/utils/encryptOtpAttempt.ts +142 -0
- package/src/utils/exportPrivateKey.ts +2 -2
- package/src/utils/exportWallet.ts +66 -75
- package/src/utils/hpke.ts +219 -0
- package/src/utils/platform.ts +21 -0
- package/src/utils/resolveOrganizationId.ts +28 -0
- package/src/utils/utils.ts +5 -6
- package/src/web/createZeroDevWallet.ts +45 -0
- package/dist/_cjs/actions/auth/getUserEmail.js +0 -19
- package/dist/_cjs/actions/auth/getUserEmail.js.map +0 -1
- package/dist/_cjs/actions/wallet/signRawPayload.js +0 -27
- package/dist/_cjs/actions/wallet/signRawPayload.js.map +0 -1
- package/dist/_cjs/core/createZeroDevWallet.js.map +0 -1
- package/dist/_cjs/stampers/index.js +0 -10
- package/dist/_cjs/stampers/index.js.map +0 -1
- package/dist/_esm/actions/auth/getUserEmail.js +0 -33
- package/dist/_esm/actions/auth/getUserEmail.js.map +0 -1
- package/dist/_esm/actions/wallet/signRawPayload.js +0 -42
- package/dist/_esm/actions/wallet/signRawPayload.js.map +0 -1
- package/dist/_esm/core/createZeroDevWallet.js.map +0 -1
- package/dist/_esm/stampers/index.js +0 -4
- package/dist/_esm/stampers/index.js.map +0 -1
- package/dist/_types/actions/auth/getUserEmail.d.ts +0 -32
- package/dist/_types/actions/auth/getUserEmail.d.ts.map +0 -1
- package/dist/_types/actions/wallet/signRawPayload.d.ts +0 -39
- package/dist/_types/actions/wallet/signRawPayload.d.ts.map +0 -1
- package/dist/_types/core/createZeroDevWallet.d.ts.map +0 -1
- package/dist/_types/stampers/index.d.ts +0 -5
- package/dist/_types/stampers/index.d.ts.map +0 -1
- package/src/actions/auth/getUserEmail.ts +0 -52
- package/src/actions/wallet/signRawPayload.ts +0 -75
- package/src/stampers/index.ts +0 -8
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wraps the OTP code + client public key in a Turnkey-compatible HPKE bundle
|
|
3
|
+
* for the `/v1/otp_verify_v2` auth-proxy endpoint.
|
|
4
|
+
*
|
|
5
|
+
* Bundle flow (RFC 9180 mode_base over Turnkey's TLS Fetcher enclave):
|
|
6
|
+
* 1. The backend's /init/otp returns a signed envelope that contains an
|
|
7
|
+
* ephemeral HPKE public key (`targetPublic`) generated fresh by the
|
|
8
|
+
* enclave for this OTP attempt.
|
|
9
|
+
* 2. We verify the envelope's ECDSA signature against a pinned production
|
|
10
|
+
* key (`TURNKEY_TLS_FETCHER_SIGN_PUBLIC_KEY`) so a compromised proxy
|
|
11
|
+
* cannot substitute its own ephemeral key.
|
|
12
|
+
* 3. We HPKE-seal `{otp_code, public_key}` to `targetPublic`. The auth proxy
|
|
13
|
+
* forwards the ciphertext to the enclave; only the enclave can decrypt
|
|
14
|
+
* it. The enclave then issues a `verificationToken` bound to the public
|
|
15
|
+
* key embedded in the plaintext.
|
|
16
|
+
*
|
|
17
|
+
* See: tkhq/go-sdk `examples/email_otp` and `pkg/enclave_encrypt`.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { p256 } from '@noble/curves/nist.js'
|
|
21
|
+
import { bytesToHex, hexToBytes } from '@noble/hashes/utils.js'
|
|
22
|
+
import { TURNKEY_TLS_FETCHER_SIGN_PUBLIC_KEY } from '../constants.js'
|
|
23
|
+
import { hpkeSealP256 } from './hpke.js'
|
|
24
|
+
|
|
25
|
+
const BUNDLE_DATA_VERSION = 'v1.0.0'
|
|
26
|
+
|
|
27
|
+
type EncryptionTargetEnvelope = {
|
|
28
|
+
version: string
|
|
29
|
+
/** Hex-encoded JSON: `{ targetPublic, organizationId, userId? }` */
|
|
30
|
+
data: string
|
|
31
|
+
/** Hex-encoded ECDSA-P256 signature over the raw `data` bytes (DER). */
|
|
32
|
+
dataSignature: string
|
|
33
|
+
/** Hex-encoded uncompressed P-256 pubkey of the signing enclave. */
|
|
34
|
+
enclaveQuorumPublic: string
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
type SignedTargetData = {
|
|
38
|
+
targetPublic: string
|
|
39
|
+
organizationId?: string
|
|
40
|
+
userId?: string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type EncryptOtpAttemptParams = {
|
|
44
|
+
/** The OTP code the user entered. */
|
|
45
|
+
otpCode: string
|
|
46
|
+
/**
|
|
47
|
+
* The client's session public key (compressed P-256 hex). The enclave binds
|
|
48
|
+
* this key into the `verificationToken` it issues.
|
|
49
|
+
*/
|
|
50
|
+
publicKey: string
|
|
51
|
+
/** The signed envelope returned by `/auth/init/otp`. */
|
|
52
|
+
encryptionTargetBundle: string
|
|
53
|
+
/**
|
|
54
|
+
* Test-only override for the pinned signing key. Production callers should
|
|
55
|
+
* leave this undefined; it exists so tests don't have to use the real key.
|
|
56
|
+
*/
|
|
57
|
+
dangerouslyOverrideSignerPublicKey?: string
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Returns a JSON string ready to be sent as `encryptedOtpBundle` on
|
|
62
|
+
* `POST /v1/otp_verify_v2`.
|
|
63
|
+
*/
|
|
64
|
+
export async function encryptOtpAttempt({
|
|
65
|
+
otpCode,
|
|
66
|
+
publicKey,
|
|
67
|
+
encryptionTargetBundle,
|
|
68
|
+
dangerouslyOverrideSignerPublicKey,
|
|
69
|
+
}: EncryptOtpAttemptParams): Promise<string> {
|
|
70
|
+
const expectedSignerHex =
|
|
71
|
+
dangerouslyOverrideSignerPublicKey ?? TURNKEY_TLS_FETCHER_SIGN_PUBLIC_KEY
|
|
72
|
+
|
|
73
|
+
let envelope: EncryptionTargetEnvelope
|
|
74
|
+
try {
|
|
75
|
+
envelope = JSON.parse(encryptionTargetBundle)
|
|
76
|
+
} catch (err) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
`encryptOtpAttempt: failed to parse encryption target bundle: ${(err as Error).message}`,
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (envelope.version !== BUNDLE_DATA_VERSION) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
`encryptOtpAttempt: unsupported bundle version ${envelope.version}`,
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (
|
|
89
|
+
envelope.enclaveQuorumPublic.toLowerCase() !==
|
|
90
|
+
expectedSignerHex.toLowerCase()
|
|
91
|
+
) {
|
|
92
|
+
throw new Error(
|
|
93
|
+
'encryptOtpAttempt: enclave quorum public key does not match pinned signing key',
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const dataBytes = hexToBytes(envelope.data)
|
|
98
|
+
const signatureBytes = hexToBytes(envelope.dataSignature)
|
|
99
|
+
const signerPublicKeyBytes = hexToBytes(envelope.enclaveQuorumPublic)
|
|
100
|
+
|
|
101
|
+
// The Go side does sha256(data) then ASN.1 DER ECDSA verify, without
|
|
102
|
+
// enforcing low-S. Match that here.
|
|
103
|
+
const valid = p256.verify(signatureBytes, dataBytes, signerPublicKeyBytes, {
|
|
104
|
+
prehash: true,
|
|
105
|
+
format: 'der',
|
|
106
|
+
lowS: false,
|
|
107
|
+
})
|
|
108
|
+
if (!valid) {
|
|
109
|
+
throw new Error('encryptOtpAttempt: invalid enclave signature on bundle')
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
let signedData: SignedTargetData
|
|
113
|
+
try {
|
|
114
|
+
signedData = JSON.parse(new TextDecoder().decode(dataBytes))
|
|
115
|
+
} catch (err) {
|
|
116
|
+
throw new Error(
|
|
117
|
+
`encryptOtpAttempt: failed to parse signed bundle data: ${(err as Error).message}`,
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
if (!signedData.targetPublic) {
|
|
121
|
+
throw new Error('encryptOtpAttempt: missing targetPublic in signed data')
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const targetPublicKey = hexToBytes(signedData.targetPublic)
|
|
125
|
+
|
|
126
|
+
// Plaintext shape matches what the Go example marshals:
|
|
127
|
+
// { otp_code: string, public_key: string }
|
|
128
|
+
const plaintext = new TextEncoder().encode(
|
|
129
|
+
JSON.stringify({ otp_code: otpCode, public_key: publicKey }),
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
const { encappedPublic, ciphertext } = await hpkeSealP256({
|
|
133
|
+
receiverPublicKey: targetPublicKey,
|
|
134
|
+
plaintext,
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
// Wire format = the Go SDK's `ClientSendMsg`: Bytes fields hex-encoded.
|
|
138
|
+
return JSON.stringify({
|
|
139
|
+
encappedPublic: bytesToHex(encappedPublic),
|
|
140
|
+
ciphertext: bytesToHex(ciphertext),
|
|
141
|
+
})
|
|
142
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ZeroDevWalletSDK } from '../core/
|
|
1
|
+
import type { ZeroDevWalletSDK } from '../core/createZeroDevWalletCore.js'
|
|
2
2
|
import type { KeyFormat } from '../stampers/types.js'
|
|
3
3
|
|
|
4
4
|
export type ExportPrivateKeyParameters = {
|
|
@@ -72,7 +72,7 @@ export async function exportPrivateKey(
|
|
|
72
72
|
})
|
|
73
73
|
|
|
74
74
|
const stamperKey =
|
|
75
|
-
session.stamperType === '
|
|
75
|
+
session.stamperType === 'apiKey' ? 'apiKeyStamper' : 'passkeyStamper'
|
|
76
76
|
const stamper = wallet.client[stamperKey]
|
|
77
77
|
if (!stamper) {
|
|
78
78
|
throw new Error(`Stamper '${stamperKey}' not found on wallet.client`)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ZeroDevWalletSDK } from '../core/
|
|
1
|
+
import type { ZeroDevWalletSDK } from '../core/createZeroDevWalletCore.js'
|
|
2
2
|
|
|
3
3
|
export type ExportWalletParameters = {
|
|
4
4
|
/** Wallet to use for the export */
|
|
@@ -43,88 +43,79 @@ export async function exportWallet(
|
|
|
43
43
|
): Promise<{ exportBundle: string; walletId: string; organizationId: string }> {
|
|
44
44
|
const { targetPublicKey, wallet } = params
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const { organizationId } = session
|
|
46
|
+
const session = await wallet.getSession()
|
|
47
|
+
if (!session) {
|
|
48
|
+
throw new Error('Session not found')
|
|
49
|
+
}
|
|
50
|
+
const { organizationId } = session
|
|
52
51
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
const listWalletsBody = JSON.stringify({
|
|
53
|
+
organizationId,
|
|
54
|
+
})
|
|
56
55
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
throw new Error('Failed to stamp list wallets body')
|
|
65
|
-
}
|
|
56
|
+
const listWalletsStamp =
|
|
57
|
+
await wallet.client[
|
|
58
|
+
session.stamperType === 'apiKey' ? 'apiKeyStamper' : 'passkeyStamper'
|
|
59
|
+
].stamp(listWalletsBody)
|
|
60
|
+
if (!listWalletsStamp) {
|
|
61
|
+
throw new Error('Failed to stamp list wallets body')
|
|
62
|
+
}
|
|
66
63
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
},
|
|
64
|
+
const listWalletsResponse = await fetch(
|
|
65
|
+
'https://api.turnkey.com/public/v1/query/list_wallets',
|
|
66
|
+
{
|
|
67
|
+
method: 'POST',
|
|
68
|
+
body: listWalletsBody,
|
|
69
|
+
headers: {
|
|
70
|
+
[listWalletsStamp.stampHeaderName]: listWalletsStamp.stampHeaderValue,
|
|
75
71
|
},
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
72
|
+
},
|
|
73
|
+
)
|
|
74
|
+
if (!listWalletsResponse.ok) {
|
|
75
|
+
throw new Error('Failed to list wallets')
|
|
76
|
+
}
|
|
77
|
+
const listWalletsData = await listWalletsResponse.json()
|
|
81
78
|
|
|
82
|
-
|
|
79
|
+
const walletId = listWalletsData.wallets[0].walletId
|
|
83
80
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
'
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
headers: {
|
|
109
|
-
[exportWalletStamp.stampHeaderName]:
|
|
110
|
-
exportWalletStamp.stampHeaderValue,
|
|
111
|
-
},
|
|
81
|
+
const exportWalletBody = JSON.stringify({
|
|
82
|
+
type: 'ACTIVITY_TYPE_EXPORT_WALLET',
|
|
83
|
+
timestampMs: Date.now().toString(),
|
|
84
|
+
organizationId: organizationId,
|
|
85
|
+
parameters: {
|
|
86
|
+
walletId: walletId,
|
|
87
|
+
targetPublicKey,
|
|
88
|
+
language: 'MNEMONIC_LANGUAGE_ENGLISH',
|
|
89
|
+
},
|
|
90
|
+
})
|
|
91
|
+
const exportWalletStamp =
|
|
92
|
+
await wallet.client[
|
|
93
|
+
session.stamperType === 'apiKey' ? 'apiKeyStamper' : 'passkeyStamper'
|
|
94
|
+
].stamp(exportWalletBody)
|
|
95
|
+
if (!exportWalletStamp) {
|
|
96
|
+
throw new Error('Failed to stamp export wallet body')
|
|
97
|
+
}
|
|
98
|
+
const exportWalletResponse = await fetch(
|
|
99
|
+
'https://api.turnkey.com/public/v1/submit/export_wallet',
|
|
100
|
+
{
|
|
101
|
+
method: 'POST',
|
|
102
|
+
body: exportWalletBody,
|
|
103
|
+
headers: {
|
|
104
|
+
[exportWalletStamp.stampHeaderName]: exportWalletStamp.stampHeaderValue,
|
|
112
105
|
},
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const exportBundle =
|
|
120
|
-
exportWalletData?.activity?.result?.exportWalletResult?.exportBundle
|
|
106
|
+
},
|
|
107
|
+
)
|
|
108
|
+
if (!exportWalletResponse.ok) {
|
|
109
|
+
throw new Error('Failed to export wallet')
|
|
110
|
+
}
|
|
111
|
+
const exportWalletData = await exportWalletResponse.json()
|
|
121
112
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
113
|
+
const exportBundle =
|
|
114
|
+
exportWalletData?.activity?.result?.exportWalletResult?.exportBundle
|
|
125
115
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
throw new Error('Error exporting wallet')
|
|
116
|
+
if (!exportBundle) {
|
|
117
|
+
throw new Error('Export bundle not found in response')
|
|
129
118
|
}
|
|
119
|
+
|
|
120
|
+
return { exportBundle, walletId, organizationId }
|
|
130
121
|
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HPKE (RFC 9180) seal for Turnkey enclave-encrypted requests.
|
|
3
|
+
*
|
|
4
|
+
* Suite: DHKEM(P-256, HKDF-SHA256) / HKDF-SHA256 / AES-256-GCM
|
|
5
|
+
* - KEM ID = 0x0010 (DHKEM-P256-HKDF-SHA256)
|
|
6
|
+
* - KDF ID = 0x0001 (HKDF-SHA256)
|
|
7
|
+
* - AEAD ID = 0x0002 (AES-256-GCM)
|
|
8
|
+
*
|
|
9
|
+
* Wire format and AAD construction match Turnkey's enclave_encrypt Go package:
|
|
10
|
+
* info = "turnkey_hpke"
|
|
11
|
+
* aad = enc || pkR (both 65-byte uncompressed P-256 points)
|
|
12
|
+
*
|
|
13
|
+
* References:
|
|
14
|
+
* - RFC 9180 §4 / §5
|
|
15
|
+
* - tkhq/go-sdk/pkg/enclave_encrypt
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { gcm } from '@noble/ciphers/aes.js'
|
|
19
|
+
import { p256 } from '@noble/curves/nist.js'
|
|
20
|
+
import { expand, extract } from '@noble/hashes/hkdf.js'
|
|
21
|
+
import { sha256 } from '@noble/hashes/sha2.js'
|
|
22
|
+
|
|
23
|
+
const KEM_ID = 0x0010
|
|
24
|
+
const KDF_ID = 0x0001
|
|
25
|
+
const AEAD_ID = 0x0002
|
|
26
|
+
|
|
27
|
+
// Output sizes for the chosen primitives.
|
|
28
|
+
const NH = 32 // SHA-256 output
|
|
29
|
+
const NK = 32 // AES-256 key
|
|
30
|
+
const NN = 12 // AES-GCM nonce
|
|
31
|
+
const NPK = 65 // uncompressed P-256 point: 0x04 || X || Y
|
|
32
|
+
|
|
33
|
+
const TURNKEY_HPKE_INFO = new TextEncoder().encode('turnkey_hpke')
|
|
34
|
+
|
|
35
|
+
const HPKE_VERSION = new TextEncoder().encode('HPKE-v1')
|
|
36
|
+
|
|
37
|
+
// suite_id for the HPKE context: "HPKE" || I2OSP(KEM,2) || I2OSP(KDF,2) || I2OSP(AEAD,2)
|
|
38
|
+
const HPKE_SUITE_ID = concat(
|
|
39
|
+
new TextEncoder().encode('HPKE'),
|
|
40
|
+
i2osp(KEM_ID, 2),
|
|
41
|
+
i2osp(KDF_ID, 2),
|
|
42
|
+
i2osp(AEAD_ID, 2),
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
// suite_id for the KEM scope: "KEM" || I2OSP(KEM,2)
|
|
46
|
+
const KEM_SUITE_ID = concat(new TextEncoder().encode('KEM'), i2osp(KEM_ID, 2))
|
|
47
|
+
|
|
48
|
+
function concat(...parts: Uint8Array[]): Uint8Array {
|
|
49
|
+
const total = parts.reduce((sum, p) => sum + p.length, 0)
|
|
50
|
+
const out = new Uint8Array(total)
|
|
51
|
+
let offset = 0
|
|
52
|
+
for (const p of parts) {
|
|
53
|
+
out.set(p, offset)
|
|
54
|
+
offset += p.length
|
|
55
|
+
}
|
|
56
|
+
return out
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function i2osp(n: number, len: number): Uint8Array {
|
|
60
|
+
const out = new Uint8Array(len)
|
|
61
|
+
for (let i = len - 1; i >= 0; i--) {
|
|
62
|
+
out[i] = n & 0xff
|
|
63
|
+
n >>>= 8
|
|
64
|
+
}
|
|
65
|
+
return out
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// LabeledExtract(salt, label, ikm, suite_id) =
|
|
69
|
+
// HKDF-Extract(salt, "HPKE-v1" || suite_id || label || ikm)
|
|
70
|
+
function labeledExtract(
|
|
71
|
+
salt: Uint8Array,
|
|
72
|
+
label: string,
|
|
73
|
+
ikm: Uint8Array,
|
|
74
|
+
suiteId: Uint8Array,
|
|
75
|
+
): Uint8Array {
|
|
76
|
+
const labeledIkm = concat(
|
|
77
|
+
HPKE_VERSION,
|
|
78
|
+
suiteId,
|
|
79
|
+
new TextEncoder().encode(label),
|
|
80
|
+
ikm,
|
|
81
|
+
)
|
|
82
|
+
return extract(sha256, labeledIkm, salt)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// LabeledExpand(prk, label, info, L, suite_id) =
|
|
86
|
+
// HKDF-Expand(prk, I2OSP(L,2) || "HPKE-v1" || suite_id || label || info, L)
|
|
87
|
+
function labeledExpand(
|
|
88
|
+
prk: Uint8Array,
|
|
89
|
+
label: string,
|
|
90
|
+
info: Uint8Array,
|
|
91
|
+
length: number,
|
|
92
|
+
suiteId: Uint8Array,
|
|
93
|
+
): Uint8Array {
|
|
94
|
+
const labeledInfo = concat(
|
|
95
|
+
i2osp(length, 2),
|
|
96
|
+
HPKE_VERSION,
|
|
97
|
+
suiteId,
|
|
98
|
+
new TextEncoder().encode(label),
|
|
99
|
+
info,
|
|
100
|
+
)
|
|
101
|
+
return expand(sha256, prk, labeledInfo, length)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// DHKEM Encap: returns (sharedSecret, enc)
|
|
105
|
+
// sharedSecret is 32 bytes; enc is the serialized ephemeral pubkey (65 bytes uncompressed).
|
|
106
|
+
function encap(receiverPublicKey: Uint8Array): {
|
|
107
|
+
sharedSecret: Uint8Array
|
|
108
|
+
enc: Uint8Array
|
|
109
|
+
} {
|
|
110
|
+
const ephSk = p256.utils.randomSecretKey()
|
|
111
|
+
const ephPkUncompressed = p256.getPublicKey(ephSk, false)
|
|
112
|
+
|
|
113
|
+
// ECDH: returns the serialized shared point. Pass isCompressed=true so the
|
|
114
|
+
// first byte is the SEC1 prefix and bytes [1, 33) are the x-coordinate.
|
|
115
|
+
const sharedPoint = p256.getSharedSecret(
|
|
116
|
+
ephSk,
|
|
117
|
+
receiverPublicKey,
|
|
118
|
+
/* isCompressed */ true,
|
|
119
|
+
)
|
|
120
|
+
const dh = sharedPoint.slice(1, 33)
|
|
121
|
+
|
|
122
|
+
const kemContext = concat(ephPkUncompressed, receiverPublicKey)
|
|
123
|
+
|
|
124
|
+
const eaePrk = labeledExtract(new Uint8Array(0), 'eae_prk', dh, KEM_SUITE_ID)
|
|
125
|
+
const sharedSecret = labeledExpand(
|
|
126
|
+
eaePrk,
|
|
127
|
+
'shared_secret',
|
|
128
|
+
kemContext,
|
|
129
|
+
NH,
|
|
130
|
+
KEM_SUITE_ID,
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
return { sharedSecret, enc: ephPkUncompressed }
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// KeySchedule for mode_base: returns (key, base_nonce).
|
|
137
|
+
function keySchedule(
|
|
138
|
+
sharedSecret: Uint8Array,
|
|
139
|
+
info: Uint8Array,
|
|
140
|
+
): { key: Uint8Array; baseNonce: Uint8Array } {
|
|
141
|
+
const empty = new Uint8Array(0)
|
|
142
|
+
|
|
143
|
+
const pskIdHash = labeledExtract(empty, 'psk_id_hash', empty, HPKE_SUITE_ID)
|
|
144
|
+
const infoHash = labeledExtract(empty, 'info_hash', info, HPKE_SUITE_ID)
|
|
145
|
+
|
|
146
|
+
// mode_base = 0x00 prepended to (psk_id_hash || info_hash)
|
|
147
|
+
const keyScheduleContext = concat(new Uint8Array([0]), pskIdHash, infoHash)
|
|
148
|
+
|
|
149
|
+
const secret = labeledExtract(sharedSecret, 'secret', empty, HPKE_SUITE_ID)
|
|
150
|
+
|
|
151
|
+
const key = labeledExpand(
|
|
152
|
+
secret,
|
|
153
|
+
'key',
|
|
154
|
+
keyScheduleContext,
|
|
155
|
+
NK,
|
|
156
|
+
HPKE_SUITE_ID,
|
|
157
|
+
)
|
|
158
|
+
const baseNonce = labeledExpand(
|
|
159
|
+
secret,
|
|
160
|
+
'base_nonce',
|
|
161
|
+
keyScheduleContext,
|
|
162
|
+
NN,
|
|
163
|
+
HPKE_SUITE_ID,
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
return { key, baseNonce }
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function aesGcmSeal(
|
|
170
|
+
key: Uint8Array,
|
|
171
|
+
nonce: Uint8Array,
|
|
172
|
+
aad: Uint8Array,
|
|
173
|
+
plaintext: Uint8Array,
|
|
174
|
+
): Uint8Array {
|
|
175
|
+
// Returns ciphertext || tag (16 bytes appended) — matches the single-blob
|
|
176
|
+
// format Turnkey's `Sealer.Seal` and Web Crypto's AES-GCM produce.
|
|
177
|
+
return gcm(key, nonce, aad).encrypt(plaintext)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export type HpkeSealResult = {
|
|
181
|
+
/** Ephemeral sender public key (uncompressed P-256, 65 bytes). */
|
|
182
|
+
encappedPublic: Uint8Array
|
|
183
|
+
/** AES-256-GCM ciphertext with a 16-byte authentication tag appended. */
|
|
184
|
+
ciphertext: Uint8Array
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Single-shot HPKE seal in mode_base for Turnkey's TLS Fetcher enclave.
|
|
189
|
+
*
|
|
190
|
+
* Uses the fixed Turnkey `info = "turnkey_hpke"` and the AAD shape
|
|
191
|
+
* `enc || receiverPublicKey` so the resulting bundle is decryptable by
|
|
192
|
+
* `enclave_encrypt.EnclaveEncryptServer.Decrypt`.
|
|
193
|
+
*
|
|
194
|
+
* @param receiverPublicKey - The enclave's ephemeral target public key
|
|
195
|
+
* (uncompressed P-256, 65 bytes), extracted from the encryption target bundle.
|
|
196
|
+
* @param plaintext - The bytes to encrypt (e.g. the JSON-encoded OTP attempt).
|
|
197
|
+
*/
|
|
198
|
+
export async function hpkeSealP256({
|
|
199
|
+
receiverPublicKey,
|
|
200
|
+
plaintext,
|
|
201
|
+
}: {
|
|
202
|
+
receiverPublicKey: Uint8Array
|
|
203
|
+
plaintext: Uint8Array
|
|
204
|
+
}): Promise<HpkeSealResult> {
|
|
205
|
+
if (receiverPublicKey.length !== NPK) {
|
|
206
|
+
throw new Error(
|
|
207
|
+
`hpkeSealP256: receiverPublicKey must be ${NPK} bytes (uncompressed P-256), got ${receiverPublicKey.length}`,
|
|
208
|
+
)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const { sharedSecret, enc } = encap(receiverPublicKey)
|
|
212
|
+
const { key, baseNonce } = keySchedule(sharedSecret, TURNKEY_HPKE_INFO)
|
|
213
|
+
|
|
214
|
+
// First message of the context, sequence 0 → nonce = base_nonce.
|
|
215
|
+
const aad = concat(enc, receiverPublicKey)
|
|
216
|
+
const ciphertext = aesGcmSeal(key, baseNonce, aad, plaintext)
|
|
217
|
+
|
|
218
|
+
return { encappedPublic: enc, ciphertext }
|
|
219
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function isReactNative(): boolean {
|
|
2
|
+
if (
|
|
3
|
+
typeof navigator !== 'undefined' &&
|
|
4
|
+
(navigator as { product?: string }).product === 'ReactNative'
|
|
5
|
+
) {
|
|
6
|
+
return true
|
|
7
|
+
}
|
|
8
|
+
if (
|
|
9
|
+
typeof window !== 'undefined' &&
|
|
10
|
+
Object.hasOwn(window, 'ReactNativeWebView')
|
|
11
|
+
) {
|
|
12
|
+
return true
|
|
13
|
+
}
|
|
14
|
+
if (
|
|
15
|
+
typeof globalThis !== 'undefined' &&
|
|
16
|
+
Object.hasOwn(globalThis, 'HermesEngine')
|
|
17
|
+
) {
|
|
18
|
+
return true
|
|
19
|
+
}
|
|
20
|
+
return false
|
|
21
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds a memoized resolver for the Turnkey parent org that stamp-login is
|
|
3
|
+
* signed against. Resolution order:
|
|
4
|
+
* 1. explicit override (self-hosted / local backends)
|
|
5
|
+
* 2. value fetched from the backend, cached after the first success
|
|
6
|
+
* 3. fallback (the known prod parent org) if the fetch fails
|
|
7
|
+
*
|
|
8
|
+
* The fetch is only attempted when there's no override, and only once — a
|
|
9
|
+
* failure is cached as the fallback so we don't refetch on every login.
|
|
10
|
+
*/
|
|
11
|
+
export function createOrganizationIdResolver(opts: {
|
|
12
|
+
organizationId?: string | undefined
|
|
13
|
+
fetchParentOrgId: () => Promise<string>
|
|
14
|
+
fallback: string
|
|
15
|
+
}): () => Promise<string> {
|
|
16
|
+
let cached: string | undefined
|
|
17
|
+
return async function resolveOrganizationId(): Promise<string> {
|
|
18
|
+
if (opts.organizationId) return opts.organizationId
|
|
19
|
+
if (cached === undefined) {
|
|
20
|
+
try {
|
|
21
|
+
cached = await opts.fetchParentOrgId()
|
|
22
|
+
} catch {
|
|
23
|
+
cached = opts.fallback
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return cached
|
|
27
|
+
}
|
|
28
|
+
}
|
package/src/utils/utils.ts
CHANGED
|
@@ -18,7 +18,8 @@ export function parseSession(
|
|
|
18
18
|
throw new Error('Invalid JWT: Missing payload')
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
const
|
|
21
|
+
const base64 = payload.replace(/-/g, '+').replace(/_/g, '/')
|
|
22
|
+
const decoded = JSON.parse(atob(base64))
|
|
22
23
|
const {
|
|
23
24
|
exp,
|
|
24
25
|
public_key: publicKey,
|
|
@@ -68,11 +69,9 @@ export const generateRandomBuffer = (): ArrayBuffer => {
|
|
|
68
69
|
* @returns {string} - The encoded challenge.
|
|
69
70
|
*/
|
|
70
71
|
export const base64UrlEncode = (challenge: ArrayBuffer): string => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
.replace(/\//g, '_')
|
|
75
|
-
.replace(/=/g, '')
|
|
72
|
+
const bytes = new Uint8Array(challenge)
|
|
73
|
+
const binary = String.fromCharCode(...bytes)
|
|
74
|
+
return btoa(binary).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '')
|
|
76
75
|
}
|
|
77
76
|
|
|
78
77
|
/**
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createZeroDevWalletCore,
|
|
3
|
+
type ZeroDevWalletConfigCore,
|
|
4
|
+
type ZeroDevWalletSDK,
|
|
5
|
+
} from '../core/createZeroDevWalletCore.js'
|
|
6
|
+
import { createIndexedDbStamper } from '../stampers/indexedDbStamper.js'
|
|
7
|
+
import type { ApiKeyStamper, PasskeyStamper } from '../stampers/types.js'
|
|
8
|
+
import { createWebauthnStamper } from '../stampers/webauthnStamper.js'
|
|
9
|
+
import { createWebStorageAdapter } from '../storage/adapters.js'
|
|
10
|
+
import type { StorageAdapter } from '../storage/manager.js'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Web config: all four web-defaulted fields are optional overrides.
|
|
14
|
+
* `rpId` falls back to `window.location.hostname`; the others fall back to
|
|
15
|
+
* IndexedDB / WebAuthn / sessionStorage-backed implementations. RN consumers
|
|
16
|
+
* go through `@zerodev/wallet-core/react-native`, which exposes the strict
|
|
17
|
+
* `ZeroDevWalletConfigCore` shape directly.
|
|
18
|
+
*/
|
|
19
|
+
export type ZeroDevWalletConfig = Omit<
|
|
20
|
+
ZeroDevWalletConfigCore,
|
|
21
|
+
'apiKeyStamper' | 'passkeyStamper' | 'rpId' | 'sessionStorage'
|
|
22
|
+
> & {
|
|
23
|
+
rpId?: string
|
|
24
|
+
sessionStorage?: StorageAdapter
|
|
25
|
+
apiKeyStamper?: ApiKeyStamper
|
|
26
|
+
passkeyStamper?: PasskeyStamper
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function createZeroDevWallet(
|
|
30
|
+
config: ZeroDevWalletConfig,
|
|
31
|
+
): Promise<ZeroDevWalletSDK> {
|
|
32
|
+
const rpId = config.rpId ?? window.location.hostname
|
|
33
|
+
const apiKeyStamper = config.apiKeyStamper ?? (await createIndexedDbStamper())
|
|
34
|
+
const passkeyStamper =
|
|
35
|
+
config.passkeyStamper ?? (await createWebauthnStamper({ rpId }))
|
|
36
|
+
const sessionStorage = config.sessionStorage ?? createWebStorageAdapter()
|
|
37
|
+
|
|
38
|
+
return createZeroDevWalletCore({
|
|
39
|
+
...config,
|
|
40
|
+
rpId,
|
|
41
|
+
apiKeyStamper,
|
|
42
|
+
passkeyStamper,
|
|
43
|
+
sessionStorage,
|
|
44
|
+
})
|
|
45
|
+
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getUserEmail = getUserEmail;
|
|
4
|
-
async function getUserEmail(client, params) {
|
|
5
|
-
const { organizationId, projectId, token } = params;
|
|
6
|
-
return await client.request({
|
|
7
|
-
path: `${projectId}/user-email`,
|
|
8
|
-
method: 'POST',
|
|
9
|
-
body: {
|
|
10
|
-
organizationId,
|
|
11
|
-
},
|
|
12
|
-
headers: {
|
|
13
|
-
Authorization: `Bearer ${token}`,
|
|
14
|
-
},
|
|
15
|
-
stamp: true,
|
|
16
|
-
stampPostion: 'headers',
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=getUserEmail.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getUserEmail.js","sourceRoot":"","sources":["../../../../src/actions/auth/getUserEmail.ts"],"names":[],"mappings":";;AAiCA,oCAkBC;AAlBM,KAAK,UAAU,YAAY,CAChC,MAAc,EACd,MAA8B;IAE9B,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;IAEnD,OAAO,MAAM,MAAM,CAAC,OAAO,CAAC;QAC1B,IAAI,EAAE,GAAG,SAAS,aAAa;QAC/B,MAAM,EAAE,MAAM;QACd,IAAI,EAAE;YACJ,cAAc;SACf;QACD,OAAO,EAAE;YACP,aAAa,EAAE,UAAU,KAAK,EAAE;SACjC;QACD,KAAK,EAAE,IAAI;QACX,YAAY,EAAE,SAAS;KACxB,CAAC,CAAA;AACJ,CAAC"}
|