@zerodev/wallet-core 0.0.1-alpha.10
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 +310 -0
- package/dist/_cjs/actions/auth/authenticateWithEmail.js +17 -0
- package/dist/_cjs/actions/auth/authenticateWithEmail.js.map +1 -0
- package/dist/_cjs/actions/auth/authenticateWithOAuth.js +13 -0
- package/dist/_cjs/actions/auth/authenticateWithOAuth.js.map +1 -0
- package/dist/_cjs/actions/auth/getAuthProxyConfigId.js +10 -0
- package/dist/_cjs/actions/auth/getAuthProxyConfigId.js.map +1 -0
- package/dist/_cjs/actions/auth/getUserEmail.js +19 -0
- package/dist/_cjs/actions/auth/getUserEmail.js.map +1 -0
- package/dist/_cjs/actions/auth/getWhoami.js +15 -0
- package/dist/_cjs/actions/auth/getWhoami.js.map +1 -0
- package/dist/_cjs/actions/auth/index.js +22 -0
- package/dist/_cjs/actions/auth/index.js.map +1 -0
- package/dist/_cjs/actions/auth/loginWithOTP.js +15 -0
- package/dist/_cjs/actions/auth/loginWithOTP.js.map +1 -0
- package/dist/_cjs/actions/auth/loginWithStamp.js +39 -0
- package/dist/_cjs/actions/auth/loginWithStamp.js.map +1 -0
- package/dist/_cjs/actions/auth/registerWithOTP.js +16 -0
- package/dist/_cjs/actions/auth/registerWithOTP.js.map +1 -0
- package/dist/_cjs/actions/auth/registerWithPasskey.js +17 -0
- package/dist/_cjs/actions/auth/registerWithPasskey.js.map +1 -0
- package/dist/_cjs/actions/index.js +17 -0
- package/dist/_cjs/actions/index.js.map +1 -0
- package/dist/_cjs/actions/wallet/getUserWallet.js +18 -0
- package/dist/_cjs/actions/wallet/getUserWallet.js.map +1 -0
- package/dist/_cjs/actions/wallet/index.js +10 -0
- package/dist/_cjs/actions/wallet/index.js.map +1 -0
- package/dist/_cjs/actions/wallet/signRawPayload.js +27 -0
- package/dist/_cjs/actions/wallet/signRawPayload.js.map +1 -0
- package/dist/_cjs/actions/wallet/signTransaction.js +26 -0
- package/dist/_cjs/actions/wallet/signTransaction.js.map +1 -0
- package/dist/_cjs/adapters/viem.js +92 -0
- package/dist/_cjs/adapters/viem.js.map +1 -0
- package/dist/_cjs/client/authProxy.js +31 -0
- package/dist/_cjs/client/authProxy.js.map +1 -0
- package/dist/_cjs/client/createClient.js +49 -0
- package/dist/_cjs/client/createClient.js.map +1 -0
- package/dist/_cjs/client/decorators/client.js +23 -0
- package/dist/_cjs/client/decorators/client.js.map +1 -0
- package/dist/_cjs/client/index.js +11 -0
- package/dist/_cjs/client/index.js.map +1 -0
- package/dist/_cjs/client/transports/createTransport.js +31 -0
- package/dist/_cjs/client/transports/createTransport.js.map +1 -0
- package/dist/_cjs/client/transports/rest.js +104 -0
- package/dist/_cjs/client/transports/rest.js.map +1 -0
- package/dist/_cjs/client/types.js +3 -0
- package/dist/_cjs/client/types.js.map +1 -0
- package/dist/_cjs/constants.js +9 -0
- package/dist/_cjs/constants.js.map +1 -0
- package/dist/_cjs/core/createZeroDevWallet.js +302 -0
- package/dist/_cjs/core/createZeroDevWallet.js.map +1 -0
- package/dist/_cjs/errors/request.js +61 -0
- package/dist/_cjs/errors/request.js.map +1 -0
- package/dist/_cjs/index.js +35 -0
- package/dist/_cjs/index.js.map +1 -0
- package/dist/_cjs/package.json +1 -0
- package/dist/_cjs/polyfills/window.js +26 -0
- package/dist/_cjs/polyfills/window.js.map +1 -0
- package/dist/_cjs/stampers/iframeStamper.js +35 -0
- package/dist/_cjs/stampers/iframeStamper.js.map +1 -0
- package/dist/_cjs/stampers/index.js +10 -0
- package/dist/_cjs/stampers/index.js.map +1 -0
- package/dist/_cjs/stampers/indexedDbStamper.js +23 -0
- package/dist/_cjs/stampers/indexedDbStamper.js.map +1 -0
- package/dist/_cjs/stampers/types.js +3 -0
- package/dist/_cjs/stampers/types.js.map +1 -0
- package/dist/_cjs/stampers/webauthnStamper.js +17 -0
- package/dist/_cjs/stampers/webauthnStamper.js.map +1 -0
- package/dist/_cjs/storage/adapters.js +18 -0
- package/dist/_cjs/storage/adapters.js.map +1 -0
- package/dist/_cjs/storage/manager.js +108 -0
- package/dist/_cjs/storage/manager.js.map +1 -0
- package/dist/_cjs/types/session.js +9 -0
- package/dist/_cjs/types/session.js.map +1 -0
- package/dist/_cjs/utils/buildClientSignature.js +39 -0
- package/dist/_cjs/utils/buildClientSignature.js.map +1 -0
- package/dist/_cjs/utils/derToRawSignature.js +63 -0
- package/dist/_cjs/utils/derToRawSignature.js.map +1 -0
- package/dist/_cjs/utils/exportPrivateKey.js +55 -0
- package/dist/_cjs/utils/exportPrivateKey.js.map +1 -0
- package/dist/_cjs/utils/exportWallet.js +70 -0
- package/dist/_cjs/utils/exportWallet.js.map +1 -0
- package/dist/_cjs/utils/utils.js +75 -0
- package/dist/_cjs/utils/utils.js.map +1 -0
- package/dist/_esm/actions/auth/authenticateWithEmail.js +18 -0
- package/dist/_esm/actions/auth/authenticateWithEmail.js.map +1 -0
- package/dist/_esm/actions/auth/authenticateWithOAuth.js +29 -0
- package/dist/_esm/actions/auth/authenticateWithOAuth.js.map +1 -0
- package/dist/_esm/actions/auth/getAuthProxyConfigId.js +13 -0
- package/dist/_esm/actions/auth/getAuthProxyConfigId.js.map +1 -0
- package/dist/_esm/actions/auth/getUserEmail.js +33 -0
- package/dist/_esm/actions/auth/getUserEmail.js.map +1 -0
- package/dist/_esm/actions/auth/getWhoami.js +28 -0
- package/dist/_esm/actions/auth/getWhoami.js.map +1 -0
- package/dist/_esm/actions/auth/index.js +10 -0
- package/dist/_esm/actions/auth/index.js.map +1 -0
- package/dist/_esm/actions/auth/loginWithOTP.js +38 -0
- package/dist/_esm/actions/auth/loginWithOTP.js.map +1 -0
- package/dist/_esm/actions/auth/loginWithStamp.js +52 -0
- package/dist/_esm/actions/auth/loginWithStamp.js.map +1 -0
- package/dist/_esm/actions/auth/registerWithOTP.js +35 -0
- package/dist/_esm/actions/auth/registerWithOTP.js.map +1 -0
- package/dist/_esm/actions/auth/registerWithPasskey.js +36 -0
- package/dist/_esm/actions/auth/registerWithPasskey.js.map +1 -0
- package/dist/_esm/actions/index.js +5 -0
- package/dist/_esm/actions/index.js.map +1 -0
- package/dist/_esm/actions/wallet/getUserWallet.js +31 -0
- package/dist/_esm/actions/wallet/getUserWallet.js.map +1 -0
- package/dist/_esm/actions/wallet/index.js +4 -0
- package/dist/_esm/actions/wallet/index.js.map +1 -0
- package/dist/_esm/actions/wallet/signRawPayload.js +42 -0
- package/dist/_esm/actions/wallet/signRawPayload.js.map +1 -0
- package/dist/_esm/actions/wallet/signTransaction.js +41 -0
- package/dist/_esm/actions/wallet/signTransaction.js.map +1 -0
- package/dist/_esm/adapters/viem.js +94 -0
- package/dist/_esm/adapters/viem.js.map +1 -0
- package/dist/_esm/client/authProxy.js +41 -0
- package/dist/_esm/client/authProxy.js.map +1 -0
- package/dist/_esm/client/createClient.js +60 -0
- package/dist/_esm/client/createClient.js.map +1 -0
- package/dist/_esm/client/decorators/client.js +44 -0
- package/dist/_esm/client/decorators/client.js.map +1 -0
- package/dist/_esm/client/index.js +4 -0
- package/dist/_esm/client/index.js.map +1 -0
- package/dist/_esm/client/transports/createTransport.js +33 -0
- package/dist/_esm/client/transports/createTransport.js.map +1 -0
- package/dist/_esm/client/transports/rest.js +103 -0
- package/dist/_esm/client/transports/rest.js.map +1 -0
- package/dist/_esm/client/types.js +2 -0
- package/dist/_esm/client/types.js.map +1 -0
- package/dist/_esm/constants.js +6 -0
- package/dist/_esm/constants.js.map +1 -0
- package/dist/_esm/core/createZeroDevWallet.js +308 -0
- package/dist/_esm/core/createZeroDevWallet.js.map +1 -0
- package/dist/_esm/errors/request.js +60 -0
- package/dist/_esm/errors/request.js.map +1 -0
- package/dist/_esm/index.js +23 -0
- package/dist/_esm/index.js.map +1 -0
- package/dist/_esm/package.json +1 -0
- package/dist/_esm/polyfills/window.js +24 -0
- package/dist/_esm/polyfills/window.js.map +1 -0
- package/dist/_esm/stampers/iframeStamper.js +32 -0
- package/dist/_esm/stampers/iframeStamper.js.map +1 -0
- package/dist/_esm/stampers/index.js +4 -0
- package/dist/_esm/stampers/index.js.map +1 -0
- package/dist/_esm/stampers/indexedDbStamper.js +20 -0
- package/dist/_esm/stampers/indexedDbStamper.js.map +1 -0
- package/dist/_esm/stampers/types.js +2 -0
- package/dist/_esm/stampers/types.js.map +1 -0
- package/dist/_esm/stampers/webauthnStamper.js +15 -0
- package/dist/_esm/stampers/webauthnStamper.js.map +1 -0
- package/dist/_esm/storage/adapters.js +15 -0
- package/dist/_esm/storage/adapters.js.map +1 -0
- package/dist/_esm/storage/manager.js +118 -0
- package/dist/_esm/storage/manager.js.map +1 -0
- package/dist/_esm/types/session.js +6 -0
- package/dist/_esm/types/session.js.map +1 -0
- package/dist/_esm/utils/buildClientSignature.js +64 -0
- package/dist/_esm/utils/buildClientSignature.js.map +1 -0
- package/dist/_esm/utils/derToRawSignature.js +89 -0
- package/dist/_esm/utils/derToRawSignature.js.map +1 -0
- package/dist/_esm/utils/exportPrivateKey.js +83 -0
- package/dist/_esm/utils/exportPrivateKey.js.map +1 -0
- package/dist/_esm/utils/exportWallet.js +98 -0
- package/dist/_esm/utils/exportWallet.js.map +1 -0
- package/dist/_esm/utils/utils.js +105 -0
- package/dist/_esm/utils/utils.js.map +1 -0
- package/dist/_types/actions/auth/authenticateWithEmail.d.ts +33 -0
- package/dist/_types/actions/auth/authenticateWithEmail.d.ts.map +1 -0
- package/dist/_types/actions/auth/authenticateWithOAuth.d.ts +38 -0
- package/dist/_types/actions/auth/authenticateWithOAuth.d.ts.map +1 -0
- 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/getUserEmail.d.ts +32 -0
- package/dist/_types/actions/auth/getUserEmail.d.ts.map +1 -0
- package/dist/_types/actions/auth/getWhoami.d.ts +35 -0
- package/dist/_types/actions/auth/getWhoami.d.ts.map +1 -0
- package/dist/_types/actions/auth/index.d.ts +10 -0
- package/dist/_types/actions/auth/index.d.ts.map +1 -0
- package/dist/_types/actions/auth/loginWithOTP.d.ts +41 -0
- package/dist/_types/actions/auth/loginWithOTP.d.ts.map +1 -0
- package/dist/_types/actions/auth/loginWithStamp.d.ts +37 -0
- package/dist/_types/actions/auth/loginWithStamp.d.ts.map +1 -0
- package/dist/_types/actions/auth/registerWithOTP.d.ts +46 -0
- package/dist/_types/actions/auth/registerWithOTP.d.ts.map +1 -0
- package/dist/_types/actions/auth/registerWithPasskey.d.ts +53 -0
- package/dist/_types/actions/auth/registerWithPasskey.d.ts.map +1 -0
- package/dist/_types/actions/index.d.ts +3 -0
- package/dist/_types/actions/index.d.ts.map +1 -0
- package/dist/_types/actions/wallet/getUserWallet.d.ts +34 -0
- package/dist/_types/actions/wallet/getUserWallet.d.ts.map +1 -0
- package/dist/_types/actions/wallet/index.d.ts +4 -0
- package/dist/_types/actions/wallet/index.d.ts.map +1 -0
- package/dist/_types/actions/wallet/signRawPayload.d.ts +39 -0
- package/dist/_types/actions/wallet/signRawPayload.d.ts.map +1 -0
- package/dist/_types/actions/wallet/signTransaction.d.ts +35 -0
- package/dist/_types/actions/wallet/signTransaction.d.ts.map +1 -0
- package/dist/_types/adapters/viem.d.ts +10 -0
- package/dist/_types/adapters/viem.d.ts.map +1 -0
- package/dist/_types/client/authProxy.d.ts +36 -0
- package/dist/_types/client/authProxy.d.ts.map +1 -0
- package/dist/_types/client/createClient.d.ts +17 -0
- package/dist/_types/client/createClient.d.ts.map +1 -0
- package/dist/_types/client/decorators/client.d.ts +81 -0
- package/dist/_types/client/decorators/client.d.ts.map +1 -0
- package/dist/_types/client/index.d.ts +5 -0
- package/dist/_types/client/index.d.ts.map +1 -0
- package/dist/_types/client/transports/createTransport.d.ts +17 -0
- package/dist/_types/client/transports/createTransport.d.ts.map +1 -0
- package/dist/_types/client/transports/rest.d.ts +35 -0
- package/dist/_types/client/transports/rest.d.ts.map +1 -0
- package/dist/_types/client/types.d.ts +59 -0
- package/dist/_types/client/types.d.ts.map +1 -0
- package/dist/_types/constants.d.ts +6 -0
- package/dist/_types/constants.d.ts.map +1 -0
- package/dist/_types/core/createZeroDevWallet.d.ts +52 -0
- package/dist/_types/core/createZeroDevWallet.d.ts.map +1 -0
- package/dist/_types/errors/request.d.ts +12 -0
- package/dist/_types/errors/request.d.ts.map +1 -0
- package/dist/_types/index.d.ts +20 -0
- package/dist/_types/index.d.ts.map +1 -0
- package/dist/_types/polyfills/window.d.ts +15 -0
- package/dist/_types/polyfills/window.d.ts.map +1 -0
- package/dist/_types/stampers/iframeStamper.d.ts +7 -0
- package/dist/_types/stampers/iframeStamper.d.ts.map +1 -0
- package/dist/_types/stampers/index.d.ts +5 -0
- package/dist/_types/stampers/index.d.ts.map +1 -0
- package/dist/_types/stampers/indexedDbStamper.d.ts +3 -0
- package/dist/_types/stampers/indexedDbStamper.d.ts.map +1 -0
- package/dist/_types/stampers/types.d.ts +25 -0
- package/dist/_types/stampers/types.d.ts.map +1 -0
- package/dist/_types/stampers/webauthnStamper.d.ts +5 -0
- package/dist/_types/stampers/webauthnStamper.d.ts.map +1 -0
- package/dist/_types/storage/adapters.d.ts +3 -0
- package/dist/_types/storage/adapters.d.ts.map +1 -0
- package/dist/_types/storage/manager.d.ts +19 -0
- package/dist/_types/storage/manager.d.ts.map +1 -0
- package/dist/_types/types/session.d.ts +17 -0
- package/dist/_types/types/session.d.ts.map +1 -0
- package/dist/_types/utils/buildClientSignature.d.ts +25 -0
- package/dist/_types/utils/buildClientSignature.d.ts.map +1 -0
- package/dist/_types/utils/derToRawSignature.d.ts +11 -0
- package/dist/_types/utils/derToRawSignature.d.ts.map +1 -0
- package/dist/_types/utils/exportPrivateKey.d.ts +47 -0
- package/dist/_types/utils/exportPrivateKey.d.ts.map +1 -0
- package/dist/_types/utils/exportWallet.d.ts +44 -0
- package/dist/_types/utils/exportWallet.d.ts.map +1 -0
- package/dist/_types/utils/utils.d.ts +52 -0
- package/dist/_types/utils/utils.d.ts.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +74 -0
- package/src/actions/auth/authenticateWithEmail.ts +52 -0
- package/src/actions/auth/authenticateWithOAuth.ts +52 -0
- package/src/actions/auth/getAuthProxyConfigId.ts +20 -0
- package/src/actions/auth/getUserEmail.ts +52 -0
- package/src/actions/auth/getWhoami.ts +51 -0
- package/src/actions/auth/index.ts +47 -0
- package/src/actions/auth/loginWithOTP.ts +57 -0
- package/src/actions/auth/loginWithStamp.ts +79 -0
- package/src/actions/auth/registerWithOTP.ts +64 -0
- package/src/actions/auth/registerWithPasskey.ts +72 -0
- package/src/actions/index.ts +41 -0
- package/src/actions/wallet/getUserWallet.ts +53 -0
- package/src/actions/wallet/index.ts +17 -0
- package/src/actions/wallet/signRawPayload.ts +75 -0
- package/src/actions/wallet/signTransaction.ts +64 -0
- package/src/adapters/viem.ts +162 -0
- package/src/client/authProxy.ts +78 -0
- package/src/client/createClient.ts +90 -0
- package/src/client/decorators/client.ts +171 -0
- package/src/client/index.ts +19 -0
- package/src/client/transports/createTransport.ts +54 -0
- package/src/client/transports/rest.ts +138 -0
- package/src/client/types.ts +64 -0
- package/src/constants.ts +5 -0
- package/src/core/createZeroDevWallet.ts +447 -0
- package/src/errors/request.ts +36 -0
- package/src/index.ts +79 -0
- package/src/polyfills/window.ts +24 -0
- package/src/stampers/iframeStamper.ts +49 -0
- package/src/stampers/index.ts +8 -0
- package/src/stampers/indexedDbStamper.ts +22 -0
- package/src/stampers/types.ts +35 -0
- package/src/stampers/webauthnStamper.ts +21 -0
- package/src/storage/adapters.ts +20 -0
- package/src/storage/manager.ts +170 -0
- package/src/types/session.ts +18 -0
- package/src/utils/buildClientSignature.ts +86 -0
- package/src/utils/derToRawSignature.ts +103 -0
- package/src/utils/exportPrivateKey.ts +116 -0
- package/src/utils/exportWallet.ts +130 -0
- package/src/utils/utils.ts +136 -0
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
import { getWebAuthnAttestation } from '@turnkey/http'
|
|
2
|
+
import type { LocalAccount } from 'viem/accounts'
|
|
3
|
+
import type { EmailCustomization } from '../actions/auth/index.js'
|
|
4
|
+
import { toViemAccount } from '../adapters/viem.js'
|
|
5
|
+
import {
|
|
6
|
+
createAuthProxyClient,
|
|
7
|
+
createClient,
|
|
8
|
+
type ZeroDevWalletClient,
|
|
9
|
+
zeroDevWalletTransport,
|
|
10
|
+
} from '../client/index.js'
|
|
11
|
+
import {
|
|
12
|
+
DEFAULT_ORGANIZATION_ID,
|
|
13
|
+
DEFAULT_SESSION_EXPIRATION_IN_SECONDS,
|
|
14
|
+
KMS_SERVER_URL,
|
|
15
|
+
} from '../constants.js'
|
|
16
|
+
import { createIndexedDbStamper } from '../stampers/indexedDbStamper.js'
|
|
17
|
+
import { createWebauthnStamper } from '../stampers/webauthnStamper.js'
|
|
18
|
+
import { createWebStorageAdapter } from '../storage/adapters.js'
|
|
19
|
+
import {
|
|
20
|
+
createStorageManager,
|
|
21
|
+
type StorageAdapter,
|
|
22
|
+
} from '../storage/manager.js'
|
|
23
|
+
import { SessionType, type ZeroDevWalletSession } from '../types/session.js'
|
|
24
|
+
import { buildClientSignature } from '../utils/buildClientSignature.js'
|
|
25
|
+
import {
|
|
26
|
+
base64UrlEncode,
|
|
27
|
+
generateCompressedPublicKeyFromKeyPair,
|
|
28
|
+
generateRandomBuffer,
|
|
29
|
+
humanReadableDateTime,
|
|
30
|
+
parseSession,
|
|
31
|
+
} from '../utils/utils.js'
|
|
32
|
+
export interface ZeroDevWalletConfig {
|
|
33
|
+
organizationId?: string
|
|
34
|
+
proxyBaseUrl?: string
|
|
35
|
+
projectId: string
|
|
36
|
+
sessionStorage?: StorageAdapter
|
|
37
|
+
rpId?: string
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Re-export EmailCustomization for convenience
|
|
41
|
+
export type { EmailCustomization } from '../actions/auth/index.js'
|
|
42
|
+
export type { StorageAdapter, StorageManager } from '../storage/manager.js'
|
|
43
|
+
// Re-export new session types
|
|
44
|
+
export type { StamperType, ZeroDevWalletSession } from '../types/session.js'
|
|
45
|
+
|
|
46
|
+
export type AuthParams =
|
|
47
|
+
| {
|
|
48
|
+
type: 'oauth'
|
|
49
|
+
provider: string
|
|
50
|
+
}
|
|
51
|
+
| {
|
|
52
|
+
type: 'passkey'
|
|
53
|
+
email: string
|
|
54
|
+
mode: 'register' | 'login'
|
|
55
|
+
}
|
|
56
|
+
| {
|
|
57
|
+
type: 'otp'
|
|
58
|
+
mode: 'sendOtp'
|
|
59
|
+
email: string
|
|
60
|
+
contact: {
|
|
61
|
+
type: 'email' | 'sms'
|
|
62
|
+
contact: string
|
|
63
|
+
}
|
|
64
|
+
emailCustomization?: EmailCustomization
|
|
65
|
+
}
|
|
66
|
+
| {
|
|
67
|
+
type: 'otp'
|
|
68
|
+
mode: 'verifyOtp'
|
|
69
|
+
otpId: string
|
|
70
|
+
otpCode: string
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface ZeroDevWalletSDK {
|
|
74
|
+
client: ZeroDevWalletClient
|
|
75
|
+
auth: (params: AuthParams) => Promise<any>
|
|
76
|
+
|
|
77
|
+
getPublicKey: () => Promise<string | null>
|
|
78
|
+
|
|
79
|
+
getSession: () => Promise<ZeroDevWalletSession | undefined>
|
|
80
|
+
getAllSessions: () => Promise<Record<string, ZeroDevWalletSession>>
|
|
81
|
+
switchSession: (
|
|
82
|
+
sessionId: string,
|
|
83
|
+
) => Promise<ZeroDevWalletSession | undefined>
|
|
84
|
+
clearSession: (sessionId: string) => Promise<void>
|
|
85
|
+
clearAllSessions: () => Promise<void>
|
|
86
|
+
refreshSession: (
|
|
87
|
+
sessionId?: string,
|
|
88
|
+
) => Promise<ZeroDevWalletSession | undefined>
|
|
89
|
+
|
|
90
|
+
logout: () => Promise<boolean>
|
|
91
|
+
|
|
92
|
+
toAccount: () => Promise<LocalAccount>
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export async function createZeroDevWallet(
|
|
96
|
+
config: ZeroDevWalletConfig,
|
|
97
|
+
): Promise<ZeroDevWalletSDK> {
|
|
98
|
+
const {
|
|
99
|
+
projectId,
|
|
100
|
+
sessionStorage,
|
|
101
|
+
rpId = window.location.hostname,
|
|
102
|
+
organizationId = DEFAULT_ORGANIZATION_ID,
|
|
103
|
+
} = config
|
|
104
|
+
|
|
105
|
+
const sessionStorageManager = createStorageManager(
|
|
106
|
+
sessionStorage || createWebStorageAdapter(),
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
const indexedDbStamper = await createIndexedDbStamper()
|
|
110
|
+
|
|
111
|
+
const webauthnStamper = await createWebauthnStamper({ rpId })
|
|
112
|
+
|
|
113
|
+
const client = createClient({
|
|
114
|
+
indexedDbStamper,
|
|
115
|
+
webauthnStamper,
|
|
116
|
+
transport: zeroDevWalletTransport({
|
|
117
|
+
baseUrl: config.proxyBaseUrl || `${KMS_SERVER_URL}/api/v1`,
|
|
118
|
+
}),
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
let cachedAuthProxyConfigId: string | undefined
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
client,
|
|
125
|
+
async getPublicKey() {
|
|
126
|
+
await client.indexedDbStamper.resetKeyPair()
|
|
127
|
+
const compressedPublicKey = await client.indexedDbStamper.getPublicKey()
|
|
128
|
+
return compressedPublicKey
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
async getSession() {
|
|
132
|
+
return sessionStorageManager.getActiveSession()
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
async getAllSessions() {
|
|
136
|
+
const sessions = await sessionStorageManager.listSessions()
|
|
137
|
+
const sessionMap: Record<string, ZeroDevWalletSession> = {}
|
|
138
|
+
for (const session of sessions) {
|
|
139
|
+
sessionMap[session.id] = session
|
|
140
|
+
}
|
|
141
|
+
return sessionMap
|
|
142
|
+
},
|
|
143
|
+
|
|
144
|
+
async switchSession(sessionId: string) {
|
|
145
|
+
await sessionStorageManager.setActiveSession(sessionId)
|
|
146
|
+
const session = await sessionStorageManager.getActiveSession()
|
|
147
|
+
|
|
148
|
+
return session
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
async clearSession(sessionId: string) {
|
|
152
|
+
await sessionStorageManager.clearSession(sessionId)
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
async clearAllSessions() {
|
|
156
|
+
await sessionStorageManager.clearAllSessions()
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
async refreshSession(sessionId?: string) {
|
|
160
|
+
const activeSession = sessionId
|
|
161
|
+
? await sessionStorageManager.getSession(sessionId)
|
|
162
|
+
: await sessionStorageManager.getActiveSession()
|
|
163
|
+
if (!activeSession) {
|
|
164
|
+
throw new Error('No active session')
|
|
165
|
+
}
|
|
166
|
+
if (activeSession.stamperType === 'indexedDb') {
|
|
167
|
+
const newKeyPair = await crypto.subtle.generateKey(
|
|
168
|
+
{
|
|
169
|
+
name: 'ECDSA',
|
|
170
|
+
namedCurve: 'P-256',
|
|
171
|
+
},
|
|
172
|
+
false,
|
|
173
|
+
['sign', 'verify'],
|
|
174
|
+
)
|
|
175
|
+
const compressedPublicKeyHex =
|
|
176
|
+
await generateCompressedPublicKeyFromKeyPair(newKeyPair)
|
|
177
|
+
const data = await client.loginWithStamp({
|
|
178
|
+
targetPublicKey: compressedPublicKeyHex,
|
|
179
|
+
projectId,
|
|
180
|
+
organizationId: activeSession.organizationId,
|
|
181
|
+
stampWith: 'indexedDb',
|
|
182
|
+
})
|
|
183
|
+
await client.indexedDbStamper.resetKeyPair(newKeyPair)
|
|
184
|
+
const parsedSession = parseSession(data.session)
|
|
185
|
+
const session: ZeroDevWalletSession = {
|
|
186
|
+
id: `session_indexedDb_${Date.now()}`,
|
|
187
|
+
userId: parsedSession.userId,
|
|
188
|
+
organizationId: parsedSession.organizationId,
|
|
189
|
+
stamperType: 'indexedDb',
|
|
190
|
+
sessionType: SessionType.READ_WRITE,
|
|
191
|
+
token: data.session,
|
|
192
|
+
expiry: parsedSession.expiry,
|
|
193
|
+
createdAt: Date.now(),
|
|
194
|
+
}
|
|
195
|
+
await sessionStorageManager.clearSession(activeSession.id)
|
|
196
|
+
await sessionStorageManager.storeSession(session, session.id)
|
|
197
|
+
return session
|
|
198
|
+
}
|
|
199
|
+
throw new Error('Invalid session type')
|
|
200
|
+
},
|
|
201
|
+
|
|
202
|
+
// [TODO] refactor to smaller utils/actions
|
|
203
|
+
async auth(params: AuthParams) {
|
|
204
|
+
switch (params.type) {
|
|
205
|
+
case 'oauth': {
|
|
206
|
+
// Backend OAuth flow - the backend reads the OAuth session from a cookie
|
|
207
|
+
// set during the OAuth popup flow via /oauth/google/login
|
|
208
|
+
const data = await client.authenticateWithOAuth({
|
|
209
|
+
provider: params.provider,
|
|
210
|
+
projectId,
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
if (data.session) {
|
|
214
|
+
// Parse the JWT to get session data
|
|
215
|
+
const parsedSession = parseSession(data.session)
|
|
216
|
+
const publicKey = await client.indexedDbStamper.getPublicKey()
|
|
217
|
+
const session: ZeroDevWalletSession = {
|
|
218
|
+
id: `session_oauth_${Date.now()}`,
|
|
219
|
+
userId: parsedSession.userId,
|
|
220
|
+
organizationId: parsedSession.organizationId,
|
|
221
|
+
stamperType: 'indexedDb',
|
|
222
|
+
sessionType: parsedSession.sessionType || SessionType.READ_WRITE,
|
|
223
|
+
token: data.session,
|
|
224
|
+
expiry: parsedSession.expiry,
|
|
225
|
+
createdAt: Date.now(),
|
|
226
|
+
publicKey: publicKey || '',
|
|
227
|
+
}
|
|
228
|
+
await sessionStorageManager.storeSession(session, session.id)
|
|
229
|
+
}
|
|
230
|
+
return data
|
|
231
|
+
}
|
|
232
|
+
case 'passkey': {
|
|
233
|
+
const { type } = params
|
|
234
|
+
if (
|
|
235
|
+
type === 'passkey' &&
|
|
236
|
+
'mode' in params &&
|
|
237
|
+
params.mode === 'register'
|
|
238
|
+
) {
|
|
239
|
+
const { email } = params
|
|
240
|
+
await client.indexedDbStamper.resetKeyPair()
|
|
241
|
+
const tempPublicKey = await client.indexedDbStamper.getPublicKey()
|
|
242
|
+
if (!tempPublicKey) {
|
|
243
|
+
throw new Error('Failed to get public key')
|
|
244
|
+
}
|
|
245
|
+
const challenge = generateRandomBuffer()
|
|
246
|
+
const encodedChallenge = base64UrlEncode(challenge)
|
|
247
|
+
const authenticatorUserId = generateRandomBuffer()
|
|
248
|
+
const name = `ZeroDevWallet-${humanReadableDateTime()}-${email}`
|
|
249
|
+
const attestation = await getWebAuthnAttestation({
|
|
250
|
+
publicKey: {
|
|
251
|
+
rp: { id: rpId, name: '' },
|
|
252
|
+
challenge,
|
|
253
|
+
pubKeyCredParams: [
|
|
254
|
+
{
|
|
255
|
+
type: 'public-key',
|
|
256
|
+
alg: -7,
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
type: 'public-key',
|
|
260
|
+
alg: -257,
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
|
+
user: {
|
|
264
|
+
id: authenticatorUserId,
|
|
265
|
+
name,
|
|
266
|
+
displayName: name,
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
})
|
|
270
|
+
const data = await client.registerWithPasskey({
|
|
271
|
+
email,
|
|
272
|
+
attestation,
|
|
273
|
+
challenge: encodedChallenge,
|
|
274
|
+
projectId,
|
|
275
|
+
encodedPublicKey: tempPublicKey,
|
|
276
|
+
})
|
|
277
|
+
const newKeyPair = await crypto.subtle.generateKey(
|
|
278
|
+
{
|
|
279
|
+
name: 'ECDSA',
|
|
280
|
+
namedCurve: 'P-256',
|
|
281
|
+
},
|
|
282
|
+
false,
|
|
283
|
+
['sign', 'verify'],
|
|
284
|
+
)
|
|
285
|
+
const compressedPublicKeyHex =
|
|
286
|
+
await generateCompressedPublicKeyFromKeyPair(newKeyPair)
|
|
287
|
+
const loginData = await client.loginWithStamp({
|
|
288
|
+
projectId,
|
|
289
|
+
targetPublicKey: compressedPublicKeyHex,
|
|
290
|
+
organizationId: data.subOrganizationId,
|
|
291
|
+
})
|
|
292
|
+
await client.indexedDbStamper.resetKeyPair(newKeyPair)
|
|
293
|
+
const parsedSession = parseSession(loginData.session)
|
|
294
|
+
const session: ZeroDevWalletSession = {
|
|
295
|
+
id: `session_indexedDb_${Date.now()}`,
|
|
296
|
+
stamperType: 'indexedDb',
|
|
297
|
+
createdAt: Date.now(),
|
|
298
|
+
sessionType: SessionType.READ_WRITE,
|
|
299
|
+
userId: parsedSession.userId,
|
|
300
|
+
organizationId: parsedSession.organizationId,
|
|
301
|
+
expiry:
|
|
302
|
+
Date.now() +
|
|
303
|
+
Number(DEFAULT_SESSION_EXPIRATION_IN_SECONDS) * 1000,
|
|
304
|
+
token: loginData.session,
|
|
305
|
+
}
|
|
306
|
+
await sessionStorageManager.storeSession(session, session.id)
|
|
307
|
+
return data
|
|
308
|
+
}
|
|
309
|
+
if (
|
|
310
|
+
type === 'passkey' &&
|
|
311
|
+
'mode' in params &&
|
|
312
|
+
params.mode === 'login'
|
|
313
|
+
) {
|
|
314
|
+
await client.indexedDbStamper.resetKeyPair()
|
|
315
|
+
const generatedPublicKey =
|
|
316
|
+
await client.indexedDbStamper.getPublicKey()
|
|
317
|
+
if (!generatedPublicKey) {
|
|
318
|
+
throw new Error('Failed to get public key')
|
|
319
|
+
}
|
|
320
|
+
const loginData = await client.loginWithStamp({
|
|
321
|
+
targetPublicKey: generatedPublicKey,
|
|
322
|
+
projectId,
|
|
323
|
+
organizationId,
|
|
324
|
+
stampWith: 'webauthn',
|
|
325
|
+
})
|
|
326
|
+
const parsedSession = parseSession(loginData.session)
|
|
327
|
+
const session: ZeroDevWalletSession = {
|
|
328
|
+
id: `session_indexedDb_${Date.now()}`,
|
|
329
|
+
stamperType: 'indexedDb',
|
|
330
|
+
createdAt: Date.now(),
|
|
331
|
+
sessionType: SessionType.READ_WRITE,
|
|
332
|
+
userId: parsedSession.userId,
|
|
333
|
+
organizationId: parsedSession.organizationId,
|
|
334
|
+
expiry:
|
|
335
|
+
Date.now() +
|
|
336
|
+
Number(DEFAULT_SESSION_EXPIRATION_IN_SECONDS) * 1000,
|
|
337
|
+
token: loginData.session,
|
|
338
|
+
}
|
|
339
|
+
await sessionStorageManager.storeSession(session, session.id)
|
|
340
|
+
return loginData
|
|
341
|
+
}
|
|
342
|
+
throw new Error('Passkey authentication requires passkey parameter')
|
|
343
|
+
}
|
|
344
|
+
case 'otp': {
|
|
345
|
+
const { type, mode } = params
|
|
346
|
+
|
|
347
|
+
if (type === 'otp' && mode === 'sendOtp') {
|
|
348
|
+
const { email, contact, emailCustomization } = params
|
|
349
|
+
|
|
350
|
+
const data = await client.registerWithOTP({
|
|
351
|
+
email,
|
|
352
|
+
contact,
|
|
353
|
+
projectId,
|
|
354
|
+
...(emailCustomization && { emailCustomization }),
|
|
355
|
+
})
|
|
356
|
+
|
|
357
|
+
return data
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
if (type === 'otp' && mode === 'verifyOtp') {
|
|
361
|
+
const { otpId, otpCode } = params
|
|
362
|
+
|
|
363
|
+
// Step 1: Generate new key pair
|
|
364
|
+
await client.indexedDbStamper.resetKeyPair()
|
|
365
|
+
const targetPublicKey = await client.indexedDbStamper.getPublicKey()
|
|
366
|
+
|
|
367
|
+
if (!targetPublicKey) {
|
|
368
|
+
throw new Error('Failed to get public key')
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// Step 2: Verify OTP via Auth Proxy
|
|
372
|
+
if (!cachedAuthProxyConfigId) {
|
|
373
|
+
const { authProxyConfigId } = await client.getAuthProxyConfigId()
|
|
374
|
+
cachedAuthProxyConfigId = authProxyConfigId
|
|
375
|
+
}
|
|
376
|
+
const authProxyClient = createAuthProxyClient({
|
|
377
|
+
authProxyConfigId: cachedAuthProxyConfigId,
|
|
378
|
+
})
|
|
379
|
+
|
|
380
|
+
const { verificationToken } = await authProxyClient.verifyOtp({
|
|
381
|
+
otpId,
|
|
382
|
+
otpCode,
|
|
383
|
+
public_key: targetPublicKey,
|
|
384
|
+
})
|
|
385
|
+
|
|
386
|
+
// Step 3: Build client signature
|
|
387
|
+
const clientSignature = await buildClientSignature({
|
|
388
|
+
verificationToken,
|
|
389
|
+
publicKey: targetPublicKey,
|
|
390
|
+
stamper: client.indexedDbStamper,
|
|
391
|
+
})
|
|
392
|
+
|
|
393
|
+
// Step 4: Login via backend (not Auth Proxy!)
|
|
394
|
+
const data = await client.loginWithOTP({
|
|
395
|
+
verificationToken,
|
|
396
|
+
clientSignature,
|
|
397
|
+
projectId,
|
|
398
|
+
})
|
|
399
|
+
|
|
400
|
+
if (data.session) {
|
|
401
|
+
// Parse the JWT to get session data
|
|
402
|
+
const parsedSession = parseSession(data.session)
|
|
403
|
+
const session: ZeroDevWalletSession = {
|
|
404
|
+
id: `session_otp_${Date.now()}`,
|
|
405
|
+
userId: parsedSession.userId,
|
|
406
|
+
organizationId: parsedSession.organizationId,
|
|
407
|
+
stamperType: 'indexedDb',
|
|
408
|
+
sessionType:
|
|
409
|
+
parsedSession.sessionType || SessionType.READ_WRITE,
|
|
410
|
+
token: data.session,
|
|
411
|
+
expiry: parsedSession.expiry,
|
|
412
|
+
createdAt: Date.now(),
|
|
413
|
+
publicKey: targetPublicKey,
|
|
414
|
+
}
|
|
415
|
+
await sessionStorageManager.storeSession(session, session.id)
|
|
416
|
+
}
|
|
417
|
+
return data
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
throw new Error('OTP authentication requires mode parameter')
|
|
421
|
+
}
|
|
422
|
+
default:
|
|
423
|
+
throw new Error(`Unknown auth type: ${(params as any).type}`)
|
|
424
|
+
}
|
|
425
|
+
},
|
|
426
|
+
|
|
427
|
+
async logout() {
|
|
428
|
+
await sessionStorageManager.clearAllSessions()
|
|
429
|
+
await client.indexedDbStamper.resetKeyPair()
|
|
430
|
+
return true
|
|
431
|
+
},
|
|
432
|
+
|
|
433
|
+
async toAccount(): Promise<LocalAccount> {
|
|
434
|
+
const session = await sessionStorageManager.getActiveSession()
|
|
435
|
+
if (!session) {
|
|
436
|
+
throw new Error('No active session')
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
return toViemAccount({
|
|
440
|
+
client,
|
|
441
|
+
organizationId: session.organizationId,
|
|
442
|
+
projectId,
|
|
443
|
+
token: session.token ?? '',
|
|
444
|
+
})
|
|
445
|
+
},
|
|
446
|
+
}
|
|
447
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export class RestRequestError extends Error {
|
|
2
|
+
constructor(
|
|
3
|
+
public url: string,
|
|
4
|
+
public status?: number,
|
|
5
|
+
public body?: unknown,
|
|
6
|
+
public override cause?: unknown,
|
|
7
|
+
) {
|
|
8
|
+
// Extract error message from backend response format
|
|
9
|
+
// Backend format: { error: "error_code", message: "human readable message" }
|
|
10
|
+
let errorMessage = `Request failed (${status || 'unknown'}): `
|
|
11
|
+
|
|
12
|
+
if (body && typeof body === 'object') {
|
|
13
|
+
const errorBody = body as any
|
|
14
|
+
|
|
15
|
+
// Prefer message (detailed), fallback to error (code)
|
|
16
|
+
if (errorBody.message && errorBody.error) {
|
|
17
|
+
// Both present: show error code + message
|
|
18
|
+
errorMessage += `${errorBody.error} - ${errorBody.message}`
|
|
19
|
+
} else if (errorBody.message) {
|
|
20
|
+
errorMessage += `${errorBody.message}`
|
|
21
|
+
} else if (errorBody.error) {
|
|
22
|
+
errorMessage += `${errorBody.error}`
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
super(errorMessage)
|
|
27
|
+
this.name = 'RestRequestError'
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class RestTimeoutError extends Error {
|
|
32
|
+
constructor(public url: string) {
|
|
33
|
+
super(`Request timed out: ${url}`)
|
|
34
|
+
this.name = 'RestTimeoutError'
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
// Auth types
|
|
3
|
+
AuthenticateWithEmailParameters,
|
|
4
|
+
AuthenticateWithEmailReturnType,
|
|
5
|
+
AuthenticateWithOAuthParameters,
|
|
6
|
+
AuthenticateWithOAuthReturnType,
|
|
7
|
+
EmailCustomization,
|
|
8
|
+
// Wallet types
|
|
9
|
+
GetUserWalletParameters,
|
|
10
|
+
GetUserWalletReturnType,
|
|
11
|
+
GetWhoamiParameters,
|
|
12
|
+
GetWhoamiReturnType,
|
|
13
|
+
LoginWithOTPParameters,
|
|
14
|
+
LoginWithOTPReturnType,
|
|
15
|
+
OtpContact,
|
|
16
|
+
RegisterWithOTPParameters,
|
|
17
|
+
RegisterWithOTPReturnType,
|
|
18
|
+
SignRawPayloadParameters,
|
|
19
|
+
SignRawPayloadReturnType,
|
|
20
|
+
SignTransactionParameters,
|
|
21
|
+
SignTransactionReturnType,
|
|
22
|
+
} from './actions/index.js'
|
|
23
|
+
|
|
24
|
+
// Actions
|
|
25
|
+
export {
|
|
26
|
+
// Auth actions
|
|
27
|
+
authenticateWithEmail,
|
|
28
|
+
authenticateWithOAuth,
|
|
29
|
+
// Wallet actions
|
|
30
|
+
getUserWallet,
|
|
31
|
+
getWhoami,
|
|
32
|
+
loginWithOTP,
|
|
33
|
+
registerWithOTP,
|
|
34
|
+
signRawPayload,
|
|
35
|
+
signTransaction,
|
|
36
|
+
} from './actions/index.js'
|
|
37
|
+
export type { ToViemAccountParams } from './adapters/viem.js'
|
|
38
|
+
// Adapters
|
|
39
|
+
export { toViemAccount } from './adapters/viem.js'
|
|
40
|
+
export type { ZeroDevWalletActions } from './client/decorators/client.js'
|
|
41
|
+
// Client decorators
|
|
42
|
+
export { zeroDevWalletActions } from './client/decorators/client.js'
|
|
43
|
+
export type { Client, ClientConfig, Transport } from './client/index.js'
|
|
44
|
+
// Client
|
|
45
|
+
export {
|
|
46
|
+
createBaseClient,
|
|
47
|
+
createClient,
|
|
48
|
+
type ZeroDevWalletClient,
|
|
49
|
+
zeroDevWalletTransport,
|
|
50
|
+
} from './client/index.js'
|
|
51
|
+
// Constants
|
|
52
|
+
export { KMS_SERVER_URL } from './constants.js'
|
|
53
|
+
export type {
|
|
54
|
+
AuthParams,
|
|
55
|
+
ZeroDevWalletConfig,
|
|
56
|
+
ZeroDevWalletSDK,
|
|
57
|
+
} from './core/createZeroDevWallet.js'
|
|
58
|
+
// Core
|
|
59
|
+
export { createZeroDevWallet } from './core/createZeroDevWallet.js'
|
|
60
|
+
// Stampers
|
|
61
|
+
export {
|
|
62
|
+
createIframeStamper,
|
|
63
|
+
createIndexedDbStamper,
|
|
64
|
+
createWebauthnStamper,
|
|
65
|
+
} from './stampers/index.js'
|
|
66
|
+
export type {
|
|
67
|
+
IframeStamper,
|
|
68
|
+
IndexedDbStamper,
|
|
69
|
+
WebauthnStamper,
|
|
70
|
+
} from './stampers/types.js'
|
|
71
|
+
// Storage
|
|
72
|
+
export type { StorageAdapter, StorageManager } from './storage/manager.js'
|
|
73
|
+
// Session types
|
|
74
|
+
export type { StamperType, ZeroDevWalletSession } from './types/session.js'
|
|
75
|
+
export type { KeyFormat } from './utils/exportPrivateKey.js'
|
|
76
|
+
export { exportPrivateKey } from './utils/exportPrivateKey.js'
|
|
77
|
+
export { exportWallet } from './utils/exportWallet.js'
|
|
78
|
+
// Utils
|
|
79
|
+
export { normalizeTimestamp } from './utils/utils.js'
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const loadWindow = () => {
|
|
2
|
+
if (typeof window !== 'undefined') {
|
|
3
|
+
return window
|
|
4
|
+
}
|
|
5
|
+
return {
|
|
6
|
+
localStorage: {
|
|
7
|
+
getItem: (_key: string): string | null => {
|
|
8
|
+
return null
|
|
9
|
+
},
|
|
10
|
+
setItem: (_key: string, _value: string) => {},
|
|
11
|
+
removeItem: (_key: string) => {},
|
|
12
|
+
clear: () => {},
|
|
13
|
+
key: (_index: number): string | null => {
|
|
14
|
+
return null
|
|
15
|
+
},
|
|
16
|
+
length: 0,
|
|
17
|
+
},
|
|
18
|
+
location: {
|
|
19
|
+
hostname: '',
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default loadWindow()
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
KeyFormat,
|
|
3
|
+
IframeStamper as TurnkeyIframeStamper,
|
|
4
|
+
} from '@turnkey/iframe-stamper'
|
|
5
|
+
import type { IframeStamper, KeyFormat as KeyFormatType } from './types.js'
|
|
6
|
+
|
|
7
|
+
export async function createIframeStamper(cfg: {
|
|
8
|
+
iframeUrl: string
|
|
9
|
+
iframeContainer: HTMLElement | null | undefined
|
|
10
|
+
iframeElementId: string
|
|
11
|
+
}): Promise<IframeStamper> {
|
|
12
|
+
const inner = new TurnkeyIframeStamper({
|
|
13
|
+
iframeUrl: cfg.iframeUrl,
|
|
14
|
+
iframeContainer: cfg.iframeContainer,
|
|
15
|
+
iframeElementId: cfg.iframeElementId,
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
async init() {
|
|
20
|
+
return await inner.init()
|
|
21
|
+
},
|
|
22
|
+
async injectCredentialBundle(bundle: string) {
|
|
23
|
+
return await inner.injectCredentialBundle(bundle)
|
|
24
|
+
},
|
|
25
|
+
async getPublicKey() {
|
|
26
|
+
return await inner.getEmbeddedPublicKey()
|
|
27
|
+
},
|
|
28
|
+
async stamp(payload: string) {
|
|
29
|
+
return await inner.stamp(payload)
|
|
30
|
+
},
|
|
31
|
+
async clear() {
|
|
32
|
+
await inner.clear()
|
|
33
|
+
},
|
|
34
|
+
async injectWalletExportBundle(bundle: string, organizationId: string) {
|
|
35
|
+
return await inner.injectWalletExportBundle(bundle, organizationId)
|
|
36
|
+
},
|
|
37
|
+
async injectKeyExportBundle(
|
|
38
|
+
bundle: string,
|
|
39
|
+
organizationId: string,
|
|
40
|
+
keyFormat?: KeyFormatType,
|
|
41
|
+
) {
|
|
42
|
+
return await inner.injectKeyExportBundle(
|
|
43
|
+
bundle,
|
|
44
|
+
organizationId,
|
|
45
|
+
keyFormat ? KeyFormat[keyFormat] : KeyFormat.Hexadecimal,
|
|
46
|
+
)
|
|
47
|
+
},
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { createIframeStamper } from './iframeStamper.js'
|
|
2
|
+
export { createIndexedDbStamper } from './indexedDbStamper.js'
|
|
3
|
+
export type {
|
|
4
|
+
IframeStamper,
|
|
5
|
+
IndexedDbStamper,
|
|
6
|
+
WebauthnStamper,
|
|
7
|
+
} from './types.js'
|
|
8
|
+
export { createWebauthnStamper } from './webauthnStamper.js'
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IndexedDbStamper as TurnkeyIndexedDbStamper } from '@turnkey/indexed-db-stamper'
|
|
2
|
+
import type { IndexedDbStamper } from './types.js'
|
|
3
|
+
|
|
4
|
+
export async function createIndexedDbStamper(): Promise<IndexedDbStamper> {
|
|
5
|
+
const inner = new TurnkeyIndexedDbStamper()
|
|
6
|
+
await inner.init()
|
|
7
|
+
|
|
8
|
+
return {
|
|
9
|
+
async getPublicKey() {
|
|
10
|
+
return await inner.getPublicKey()
|
|
11
|
+
},
|
|
12
|
+
async stamp(payload: string) {
|
|
13
|
+
return await inner.stamp(payload)
|
|
14
|
+
},
|
|
15
|
+
async clear() {
|
|
16
|
+
await inner.clear()
|
|
17
|
+
},
|
|
18
|
+
async resetKeyPair(externalKeyPair?: CryptoKeyPair) {
|
|
19
|
+
await inner.resetKeyPair(externalKeyPair)
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Base stamper that transport depends on */
|
|
2
|
+
export type Stamp = {
|
|
3
|
+
stampHeaderName: string
|
|
4
|
+
stampHeaderValue: string
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export type Stamper = {
|
|
8
|
+
/** retrieve public key compressed or otherwise as per the stamper */
|
|
9
|
+
getPublicKey: () => Promise<string | null>
|
|
10
|
+
/** produce Turnkey header value for a given request body */
|
|
11
|
+
stamp: (payload: string) => Promise<Stamp>
|
|
12
|
+
/** clear local state (embedded key, IDB keypair, etc.) */
|
|
13
|
+
clear: () => Promise<void>
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type KeyFormat = 'Hexadecimal' | 'Solana'
|
|
17
|
+
|
|
18
|
+
export type IframeStamper = Stamper & {
|
|
19
|
+
init(): Promise<string>
|
|
20
|
+
injectCredentialBundle(bundle: string): Promise<boolean>
|
|
21
|
+
injectWalletExportBundle(
|
|
22
|
+
bundle: string,
|
|
23
|
+
organizationId: string,
|
|
24
|
+
): Promise<boolean>
|
|
25
|
+
injectKeyExportBundle(
|
|
26
|
+
bundle: string,
|
|
27
|
+
organizationId: string,
|
|
28
|
+
keyFormat?: KeyFormat,
|
|
29
|
+
): Promise<boolean>
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type IndexedDbStamper = Stamper & {
|
|
33
|
+
resetKeyPair: (externalKeyPair?: CryptoKeyPair) => Promise<void>
|
|
34
|
+
}
|
|
35
|
+
export type WebauthnStamper = Stamper
|