@zerodev/wallet-core 0.0.2 → 0.0.4
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/dist/_cjs/actions/auth/getAuthenticators.js.map +1 -1
- package/dist/_cjs/actions/auth/index.js +3 -1
- package/dist/_cjs/actions/auth/index.js.map +1 -1
- package/dist/_cjs/actions/auth/logout.js +23 -0
- package/dist/_cjs/actions/auth/logout.js.map +1 -0
- package/dist/_cjs/actions/index.js +2 -1
- package/dist/_cjs/actions/index.js.map +1 -1
- package/dist/_cjs/actions/wallet/signingUtils.js +23 -3
- package/dist/_cjs/actions/wallet/signingUtils.js.map +1 -1
- package/dist/_cjs/adapters/viem.js +26 -9
- package/dist/_cjs/adapters/viem.js.map +1 -1
- package/dist/_cjs/client/decorators/client.js +1 -0
- package/dist/_cjs/client/decorators/client.js.map +1 -1
- package/dist/_cjs/client/transports/rest.js.map +1 -1
- package/dist/_cjs/core/createZeroDevWalletCore.js +297 -168
- package/dist/_cjs/core/createZeroDevWalletCore.js.map +1 -1
- package/dist/_cjs/index.js +2 -1
- package/dist/_cjs/index.js.map +1 -1
- package/dist/_cjs/index.native.js +2 -1
- package/dist/_cjs/index.native.js.map +1 -1
- package/dist/_cjs/native/stampers/secureStore.js +94 -17
- package/dist/_cjs/native/stampers/secureStore.js.map +1 -1
- package/dist/_cjs/stampers/indexedDbStamper.js +34 -0
- package/dist/_cjs/stampers/indexedDbStamper.js.map +1 -1
- package/dist/_cjs/stampers/webauthnStamper.js +4 -0
- package/dist/_cjs/stampers/webauthnStamper.js.map +1 -1
- package/dist/_cjs/storage/manager.js +144 -17
- package/dist/_cjs/storage/manager.js.map +1 -1
- package/dist/_cjs/utils/buildClientSignature.js +4 -1
- package/dist/_cjs/utils/buildClientSignature.js.map +1 -1
- package/dist/_cjs/utils/derToRawSignature.js +12 -0
- package/dist/_cjs/utils/derToRawSignature.js.map +1 -1
- package/dist/_cjs/utils/exportPrivateKey.js +1 -1
- package/dist/_cjs/utils/exportPrivateKey.js.map +1 -1
- package/dist/_cjs/utils/utils.js +27 -6
- package/dist/_cjs/utils/utils.js.map +1 -1
- package/dist/_esm/actions/auth/getAuthenticators.js +3 -2
- package/dist/_esm/actions/auth/getAuthenticators.js.map +1 -1
- package/dist/_esm/actions/auth/index.js +1 -0
- package/dist/_esm/actions/auth/index.js.map +1 -1
- package/dist/_esm/actions/auth/logout.js +21 -0
- package/dist/_esm/actions/auth/logout.js.map +1 -0
- package/dist/_esm/actions/index.js +1 -1
- package/dist/_esm/actions/index.js.map +1 -1
- package/dist/_esm/actions/wallet/signingUtils.js +24 -4
- package/dist/_esm/actions/wallet/signingUtils.js.map +1 -1
- package/dist/_esm/adapters/viem.js +27 -10
- package/dist/_esm/adapters/viem.js.map +1 -1
- package/dist/_esm/client/decorators/client.js +2 -1
- package/dist/_esm/client/decorators/client.js.map +1 -1
- package/dist/_esm/client/transports/rest.js.map +1 -1
- package/dist/_esm/core/createZeroDevWalletCore.js +320 -186
- package/dist/_esm/core/createZeroDevWalletCore.js.map +1 -1
- package/dist/_esm/index.js +1 -1
- package/dist/_esm/index.js.map +1 -1
- package/dist/_esm/index.native.js +1 -1
- package/dist/_esm/index.native.js.map +1 -1
- package/dist/_esm/native/stampers/secureStore.js +111 -18
- package/dist/_esm/native/stampers/secureStore.js.map +1 -1
- package/dist/_esm/stampers/indexedDbStamper.js +36 -0
- package/dist/_esm/stampers/indexedDbStamper.js.map +1 -1
- package/dist/_esm/stampers/webauthnStamper.js +7 -0
- package/dist/_esm/stampers/webauthnStamper.js.map +1 -1
- package/dist/_esm/storage/manager.js +150 -22
- package/dist/_esm/storage/manager.js.map +1 -1
- package/dist/_esm/utils/buildClientSignature.js +4 -1
- package/dist/_esm/utils/buildClientSignature.js.map +1 -1
- package/dist/_esm/utils/derToRawSignature.js +12 -0
- package/dist/_esm/utils/derToRawSignature.js.map +1 -1
- package/dist/_esm/utils/exportPrivateKey.js +1 -1
- package/dist/_esm/utils/exportPrivateKey.js.map +1 -1
- package/dist/_esm/utils/utils.js +27 -6
- package/dist/_esm/utils/utils.js.map +1 -1
- package/dist/_types/actions/auth/getAuthenticators.d.ts +19 -2
- package/dist/_types/actions/auth/getAuthenticators.d.ts.map +1 -1
- package/dist/_types/actions/auth/index.d.ts +2 -1
- package/dist/_types/actions/auth/index.d.ts.map +1 -1
- package/dist/_types/actions/auth/logout.d.ts +11 -0
- package/dist/_types/actions/auth/logout.d.ts.map +1 -0
- package/dist/_types/actions/index.d.ts +1 -1
- package/dist/_types/actions/index.d.ts.map +1 -1
- package/dist/_types/actions/wallet/signingUtils.d.ts.map +1 -1
- package/dist/_types/adapters/viem.d.ts.map +1 -1
- package/dist/_types/client/decorators/client.d.ts +3 -1
- package/dist/_types/client/decorators/client.d.ts.map +1 -1
- package/dist/_types/client/transports/rest.d.ts +3 -3
- package/dist/_types/client/transports/rest.d.ts.map +1 -1
- package/dist/_types/core/createZeroDevWalletCore.d.ts +8 -1
- package/dist/_types/core/createZeroDevWalletCore.d.ts.map +1 -1
- package/dist/_types/index.d.ts +2 -2
- package/dist/_types/index.d.ts.map +1 -1
- package/dist/_types/index.native.d.ts +2 -2
- package/dist/_types/index.native.d.ts.map +1 -1
- package/dist/_types/native/stampers/secureStore.d.ts.map +1 -1
- package/dist/_types/stampers/indexedDbStamper.d.ts.map +1 -1
- package/dist/_types/stampers/types.d.ts +6 -0
- package/dist/_types/stampers/types.d.ts.map +1 -1
- package/dist/_types/stampers/webauthnStamper.d.ts.map +1 -1
- package/dist/_types/storage/manager.d.ts +3 -0
- package/dist/_types/storage/manager.d.ts.map +1 -1
- package/dist/_types/types/session.d.ts +2 -0
- package/dist/_types/types/session.d.ts.map +1 -1
- package/dist/_types/utils/buildClientSignature.d.ts +1 -1
- package/dist/_types/utils/buildClientSignature.d.ts.map +1 -1
- package/dist/_types/utils/derToRawSignature.d.ts.map +1 -1
- package/dist/_types/utils/utils.d.ts +1 -1
- package/dist/_types/utils/utils.d.ts.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/actions/auth/getAuthenticators.ts +20 -2
- package/src/actions/auth/index.ts +6 -0
- package/src/actions/auth/logout.ts +35 -0
- package/src/actions/index.ts +4 -0
- package/src/actions/wallet/signingUtils.ts +43 -4
- package/src/adapters/viem.ts +40 -12
- package/src/client/decorators/client.ts +7 -0
- package/src/client/transports/rest.ts +4 -4
- package/src/core/createZeroDevWalletCore.ts +393 -205
- package/src/index.native.ts +4 -0
- package/src/index.ts +4 -0
- package/src/native/stampers/secureStore.ts +119 -24
- package/src/stampers/indexedDbStamper.ts +47 -0
- package/src/stampers/types.ts +6 -0
- package/src/stampers/webauthnStamper.ts +7 -0
- package/src/storage/manager.ts +205 -25
- package/src/types/session.ts +2 -0
- package/src/utils/buildClientSignature.ts +4 -2
- package/src/utils/derToRawSignature.ts +16 -2
- package/src/utils/exportPrivateKey.ts +1 -1
- package/src/utils/utils.ts +30 -9
package/package.json
CHANGED
|
@@ -37,6 +37,21 @@ export type ApiKeyAuthenticator = {
|
|
|
37
37
|
[key: string]: unknown
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
/** A temporary session key registered for an authenticated SDK session. */
|
|
41
|
+
export type SessionKeyAuthenticator = {
|
|
42
|
+
/** Current backend wire casing (the Go model has no JSON tags). */
|
|
43
|
+
ApiKey?: string
|
|
44
|
+
KeyType?: string
|
|
45
|
+
ExpiresAt?: string
|
|
46
|
+
TurnkeyId?: string
|
|
47
|
+
/** Forward-compatible casing if the backend adds JSON tags. */
|
|
48
|
+
apiKey?: string
|
|
49
|
+
keyType?: string
|
|
50
|
+
expiresAt?: string
|
|
51
|
+
turnkeyId?: string
|
|
52
|
+
[key: string]: unknown
|
|
53
|
+
}
|
|
54
|
+
|
|
40
55
|
export type GetAuthenticatorsReturnType = {
|
|
41
56
|
/** OAuth providers linked to the user (null if none) */
|
|
42
57
|
oauths: OAuthAuthenticator[] | null
|
|
@@ -46,13 +61,16 @@ export type GetAuthenticatorsReturnType = {
|
|
|
46
61
|
emailContacts: EmailContact[] | null
|
|
47
62
|
/** API keys associated with the user (null if none) */
|
|
48
63
|
apiKeys: ApiKeyAuthenticator[] | null
|
|
64
|
+
/** Temporary session keys associated with the user (null if none) */
|
|
65
|
+
sessionKeys: SessionKeyAuthenticator[] | null
|
|
49
66
|
}
|
|
50
67
|
|
|
51
68
|
/**
|
|
52
|
-
* Fetches all authenticators (oauths, passkeys, emailContacts, apiKeys
|
|
69
|
+
* Fetches all authenticators (oauths, passkeys, emailContacts, apiKeys,
|
|
70
|
+
* sessionKeys) for
|
|
53
71
|
* the authenticated user within the given project/sub-organization.
|
|
54
72
|
*
|
|
55
|
-
* Corresponds to `
|
|
73
|
+
* Corresponds to `GET /api/v1/{projectId}/authenticators`.
|
|
56
74
|
*
|
|
57
75
|
* @param client - The ZeroDev Wallet client
|
|
58
76
|
* @param params - The parameters for the authenticators request
|
|
@@ -17,6 +17,7 @@ export {
|
|
|
17
17
|
getAuthenticators,
|
|
18
18
|
type OAuthAuthenticator,
|
|
19
19
|
type PasskeyAuthenticator,
|
|
20
|
+
type SessionKeyAuthenticator,
|
|
20
21
|
} from './getAuthenticators.js'
|
|
21
22
|
export {
|
|
22
23
|
type GetAuthProxyConfigIdReturnType,
|
|
@@ -46,6 +47,11 @@ export {
|
|
|
46
47
|
type LoginWithStampReturnType,
|
|
47
48
|
loginWithStamp,
|
|
48
49
|
} from './loginWithStamp.js'
|
|
50
|
+
export {
|
|
51
|
+
type LogoutParameters,
|
|
52
|
+
type LogoutReturnType,
|
|
53
|
+
logout,
|
|
54
|
+
} from './logout.js'
|
|
49
55
|
export {
|
|
50
56
|
type OtpContact,
|
|
51
57
|
type RegisterWithOTPParameters,
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Client } from '../../client/types.js'
|
|
2
|
+
|
|
3
|
+
export type LogoutParameters = {
|
|
4
|
+
projectId: string
|
|
5
|
+
organizationId: string
|
|
6
|
+
userId: string
|
|
7
|
+
apiKeyId: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type LogoutReturnType = Record<string, never>
|
|
11
|
+
|
|
12
|
+
/** Revokes the caller's current Turnkey session key. */
|
|
13
|
+
export async function logout(
|
|
14
|
+
client: Client,
|
|
15
|
+
params: LogoutParameters,
|
|
16
|
+
): Promise<LogoutReturnType> {
|
|
17
|
+
const body = {
|
|
18
|
+
organizationId: params.organizationId,
|
|
19
|
+
parameters: {
|
|
20
|
+
apiKeyIds: [params.apiKeyId],
|
|
21
|
+
userId: params.userId,
|
|
22
|
+
},
|
|
23
|
+
timestampMs: Date.now().toString(),
|
|
24
|
+
type: 'ACTIVITY_TYPE_DELETE_API_KEYS',
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return await client.request({
|
|
28
|
+
path: `${params.projectId}/auth/logout`,
|
|
29
|
+
method: 'POST',
|
|
30
|
+
body,
|
|
31
|
+
stamp: true,
|
|
32
|
+
stampWith: 'apiKey',
|
|
33
|
+
stampPostion: 'headers',
|
|
34
|
+
})
|
|
35
|
+
}
|
package/src/actions/index.ts
CHANGED
|
@@ -23,7 +23,10 @@ export {
|
|
|
23
23
|
getWhoami,
|
|
24
24
|
type LoginWithOTPParameters,
|
|
25
25
|
type LoginWithOTPReturnType,
|
|
26
|
+
type LogoutParameters,
|
|
27
|
+
type LogoutReturnType,
|
|
26
28
|
loginWithOTP,
|
|
29
|
+
logout,
|
|
27
30
|
type OAuthAuthenticator,
|
|
28
31
|
type OtpContact,
|
|
29
32
|
type PasskeyAuthenticator,
|
|
@@ -33,6 +36,7 @@ export {
|
|
|
33
36
|
type RegisterWithPasskeyReturnType,
|
|
34
37
|
registerWithOTP,
|
|
35
38
|
registerWithPasskey,
|
|
39
|
+
type SessionKeyAuthenticator,
|
|
36
40
|
} from './auth/index.js'
|
|
37
41
|
|
|
38
42
|
// Wallet actions
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { canonicalizeEx } from 'json-canonicalize'
|
|
2
2
|
import type { Hex } from 'viem'
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
hashMessage,
|
|
5
|
+
isAddress,
|
|
6
|
+
isAddressEqual,
|
|
7
|
+
keccak256,
|
|
8
|
+
recoverAddress,
|
|
9
|
+
toHex,
|
|
10
|
+
zeroAddress,
|
|
11
|
+
} from 'viem'
|
|
4
12
|
import type { Client } from '../../client/types.js'
|
|
5
13
|
|
|
6
14
|
export type TurnkeyPayload = {
|
|
@@ -20,13 +28,25 @@ export function buildTurnkeyPayload(
|
|
|
20
28
|
address: Hex,
|
|
21
29
|
payloadHash: string,
|
|
22
30
|
): TurnkeyPayload {
|
|
31
|
+
if (
|
|
32
|
+
!isAddress(address, { strict: false }) ||
|
|
33
|
+
isAddressEqual(address, zeroAddress)
|
|
34
|
+
) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
`Refusing to sign with an invalid or zero address: ${address}`,
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
const normalizedPayloadHash = payloadHash.replace(/^0x/, '')
|
|
40
|
+
if (!/^[0-9a-fA-F]{64}$/.test(normalizedPayloadHash)) {
|
|
41
|
+
throw new Error('Refusing to sign a payload that is not a 32-byte hex hash')
|
|
42
|
+
}
|
|
23
43
|
return {
|
|
24
44
|
type: 'ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2',
|
|
25
45
|
timestampMs: Date.now().toString(),
|
|
26
46
|
organizationId,
|
|
27
47
|
parameters: {
|
|
28
48
|
signWith: address,
|
|
29
|
-
payload:
|
|
49
|
+
payload: normalizedPayloadHash,
|
|
30
50
|
encoding: 'PAYLOAD_ENCODING_HEXADECIMAL',
|
|
31
51
|
hashFunction: 'HASH_FUNCTION_NO_OP',
|
|
32
52
|
},
|
|
@@ -63,7 +83,7 @@ export async function sendSigningRequest(
|
|
|
63
83
|
const fullBodyString = canonicalizeEx(fullBody)
|
|
64
84
|
const outerStamp = await client.apiKeyStamper.stamp(fullBodyString)
|
|
65
85
|
|
|
66
|
-
const
|
|
86
|
+
const response = await client.request({
|
|
67
87
|
path: `${projectId}/${path}`,
|
|
68
88
|
method: 'POST',
|
|
69
89
|
body: fullBody,
|
|
@@ -72,8 +92,27 @@ export async function sendSigningRequest(
|
|
|
72
92
|
Authorization: `Bearer ${token}`,
|
|
73
93
|
},
|
|
74
94
|
})
|
|
95
|
+
const signature = response?.signature
|
|
96
|
+
if (typeof signature !== 'string' || !signature) {
|
|
97
|
+
throw new Error('Signing response did not contain a valid signature')
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const normalizedSignature = (
|
|
101
|
+
signature.startsWith('0x') ? signature : `0x${signature}`
|
|
102
|
+
) as Hex
|
|
103
|
+
const recoveredAddress = await recoverAddress({
|
|
104
|
+
hash: `0x${turnkeyPayload.parameters.payload}`,
|
|
105
|
+
signature: normalizedSignature,
|
|
106
|
+
})
|
|
107
|
+
if (
|
|
108
|
+
!isAddressEqual(recoveredAddress, turnkeyPayload.parameters.signWith as Hex)
|
|
109
|
+
) {
|
|
110
|
+
throw new Error(
|
|
111
|
+
`Signing response did not recover to expected owner ${turnkeyPayload.parameters.signWith}.`,
|
|
112
|
+
)
|
|
113
|
+
}
|
|
75
114
|
|
|
76
|
-
return
|
|
115
|
+
return normalizedSignature
|
|
77
116
|
}
|
|
78
117
|
|
|
79
118
|
/**
|
package/src/adapters/viem.ts
CHANGED
|
@@ -6,9 +6,12 @@ import {
|
|
|
6
6
|
hashTypedData,
|
|
7
7
|
isAddress,
|
|
8
8
|
isAddressEqual,
|
|
9
|
+
keccak256,
|
|
9
10
|
type LocalAccount,
|
|
10
11
|
numberToHex,
|
|
11
12
|
parseSignature,
|
|
13
|
+
recoverAddress,
|
|
14
|
+
recoverMessageAddress,
|
|
12
15
|
type SerializeTransactionFn,
|
|
13
16
|
type SignableMessage,
|
|
14
17
|
serializeTransaction,
|
|
@@ -36,11 +39,12 @@ export async function toViemAccount(
|
|
|
36
39
|
params: ToViemAccountParams,
|
|
37
40
|
): Promise<LocalAccount> {
|
|
38
41
|
const { client, organizationId, projectId, getToken } = params
|
|
42
|
+
const token = await getToken()
|
|
39
43
|
|
|
40
44
|
const walletResponse = await client.getUserWallet({
|
|
41
45
|
organizationId,
|
|
42
46
|
projectId,
|
|
43
|
-
token
|
|
47
|
+
token,
|
|
44
48
|
})
|
|
45
49
|
const address = walletResponse.walletAddresses[0]
|
|
46
50
|
if (
|
|
@@ -53,6 +57,15 @@ export async function toViemAccount(
|
|
|
53
57
|
)
|
|
54
58
|
}
|
|
55
59
|
|
|
60
|
+
const assertOwner = async (recovered: Promise<Hex>) => {
|
|
61
|
+
const recoveredAddress = await recovered
|
|
62
|
+
if (!isAddressEqual(address, recoveredAddress)) {
|
|
63
|
+
throw new Error(
|
|
64
|
+
`Signing response did not recover to wallet owner ${address}.`,
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
56
69
|
// Modified from: https://github.com/tkhq/sdk/blob/4e439bf2973ea13b51d981d7c24a4841d4e5fd5f/packages/viem/src/index.ts#L419-L461
|
|
57
70
|
const signTransactionInternal = async <
|
|
58
71
|
TTransactionSerializable extends TransactionSerializable,
|
|
@@ -76,9 +89,12 @@ export async function toViemAccount(
|
|
|
76
89
|
address,
|
|
77
90
|
unsignedTransaction: nonHexPrefixedSerializedTx,
|
|
78
91
|
})
|
|
92
|
+
await assertOwner(
|
|
93
|
+
recoverAddress({ hash: keccak256(serializedTx), signature }),
|
|
94
|
+
)
|
|
79
95
|
|
|
80
96
|
const { r, s, v, yParity } = parseSignature(signature)
|
|
81
|
-
return
|
|
97
|
+
return serializer(transaction, { r, s, v, yParity })
|
|
82
98
|
}
|
|
83
99
|
|
|
84
100
|
return toAccount({
|
|
@@ -86,7 +102,7 @@ export async function toViemAccount(
|
|
|
86
102
|
|
|
87
103
|
async signMessage({ message }: { message: SignableMessage }): Promise<Hex> {
|
|
88
104
|
if (typeof message === 'string') {
|
|
89
|
-
|
|
105
|
+
const signature = await client.signMessage({
|
|
90
106
|
organizationId,
|
|
91
107
|
projectId,
|
|
92
108
|
token: await getToken(),
|
|
@@ -94,13 +110,15 @@ export async function toViemAccount(
|
|
|
94
110
|
message,
|
|
95
111
|
encoding: 'utf8',
|
|
96
112
|
})
|
|
113
|
+
await assertOwner(recoverMessageAddress({ message, signature }))
|
|
114
|
+
return signature
|
|
97
115
|
}
|
|
98
116
|
// Raw message (Hex or ByteArray)
|
|
99
117
|
const raw =
|
|
100
118
|
typeof message.raw === 'string'
|
|
101
119
|
? message.raw.replace(/^0x/, '')
|
|
102
120
|
: bytesToHex(message.raw).slice(2)
|
|
103
|
-
|
|
121
|
+
const signature = await client.signMessage({
|
|
104
122
|
organizationId,
|
|
105
123
|
projectId,
|
|
106
124
|
token: await getToken(),
|
|
@@ -108,6 +126,13 @@ export async function toViemAccount(
|
|
|
108
126
|
message: raw,
|
|
109
127
|
encoding: 'hex',
|
|
110
128
|
})
|
|
129
|
+
await assertOwner(
|
|
130
|
+
recoverMessageAddress({
|
|
131
|
+
message: { raw: `0x${raw}` as Hex },
|
|
132
|
+
signature,
|
|
133
|
+
}),
|
|
134
|
+
)
|
|
135
|
+
return signature
|
|
111
136
|
},
|
|
112
137
|
|
|
113
138
|
signTransaction: async <
|
|
@@ -137,17 +162,20 @@ export async function toViemAccount(
|
|
|
137
162
|
}),
|
|
138
163
|
},
|
|
139
164
|
} as Parameters<typeof serializeTypedData>[0])
|
|
140
|
-
|
|
165
|
+
const typedDataHash = hashTypedData(
|
|
166
|
+
typedData as Parameters<typeof hashTypedData>[0],
|
|
167
|
+
)
|
|
168
|
+
const signature = await client.signTypedDataV4({
|
|
141
169
|
organizationId,
|
|
142
170
|
projectId,
|
|
143
171
|
token: await getToken(),
|
|
144
172
|
address,
|
|
145
173
|
unsignedTypedDataV4: serializedTypedData,
|
|
146
174
|
encoding: 'utf8',
|
|
147
|
-
typedDataHash:
|
|
148
|
-
typedData as Parameters<typeof hashTypedData>[0],
|
|
149
|
-
).slice(2),
|
|
175
|
+
typedDataHash: typedDataHash.slice(2),
|
|
150
176
|
})
|
|
177
|
+
await assertOwner(recoverAddress({ hash: typedDataHash, signature }))
|
|
178
|
+
return signature
|
|
151
179
|
},
|
|
152
180
|
|
|
153
181
|
async signAuthorization(
|
|
@@ -184,15 +212,15 @@ export async function toViemAccount(
|
|
|
184
212
|
unsignedTransaction,
|
|
185
213
|
hashedAuthorization: hashedAuthorization.slice(2),
|
|
186
214
|
})
|
|
187
|
-
|
|
188
|
-
|
|
215
|
+
await assertOwner(
|
|
216
|
+
recoverAddress({ hash: hashedAuthorization, signature }),
|
|
217
|
+
)
|
|
189
218
|
|
|
190
219
|
return {
|
|
191
220
|
address: authAddress,
|
|
192
221
|
chainId,
|
|
193
222
|
nonce,
|
|
194
|
-
...
|
|
195
|
-
yParity: parsedSignature.v === BigInt(27) ? 0 : 1,
|
|
223
|
+
...parseSignature(signature),
|
|
196
224
|
} as SignAuthorizationReturnType
|
|
197
225
|
},
|
|
198
226
|
})
|
|
@@ -28,7 +28,10 @@ import {
|
|
|
28
28
|
getWhoami,
|
|
29
29
|
type LoginWithOTPParameters,
|
|
30
30
|
type LoginWithOTPReturnType,
|
|
31
|
+
type LogoutParameters,
|
|
32
|
+
type LogoutReturnType,
|
|
31
33
|
loginWithOTP,
|
|
34
|
+
logout,
|
|
32
35
|
type RegisterWithOTPParameters,
|
|
33
36
|
type RegisterWithOTPReturnType,
|
|
34
37
|
type RegisterWithPasskeyParameters,
|
|
@@ -85,6 +88,9 @@ export type ZeroDevWalletActions = {
|
|
|
85
88
|
params: GetAuthenticatorsParameters,
|
|
86
89
|
) => Promise<GetAuthenticatorsReturnType>
|
|
87
90
|
|
|
91
|
+
/** Revokes the caller's current Turnkey session key. */
|
|
92
|
+
logout: (params: LogoutParameters) => Promise<LogoutReturnType>
|
|
93
|
+
|
|
88
94
|
// Wallet actions
|
|
89
95
|
/**
|
|
90
96
|
* Gets the user's wallet information
|
|
@@ -203,6 +209,7 @@ export function zeroDevWalletActions(client: Client): ZeroDevWalletActions {
|
|
|
203
209
|
authenticateWithOAuth: (params) => authenticateWithOAuth(client, params),
|
|
204
210
|
getWhoami: (params) => getWhoami(client, params),
|
|
205
211
|
getAuthenticators: (params) => getAuthenticators(client, params),
|
|
212
|
+
logout: (params) => logout(client, params),
|
|
206
213
|
|
|
207
214
|
// Wallet actions
|
|
208
215
|
getUserWallet: (params) => getUserWallet(client, params),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { canonicalizeEx } from 'json-canonicalize'
|
|
2
2
|
import { RestRequestError, RestTimeoutError } from '../../errors/request.js'
|
|
3
|
-
import type {
|
|
3
|
+
import type { Stamper } from '../../stampers/types.js'
|
|
4
4
|
import type { StamperType } from '../../types/session.js'
|
|
5
5
|
|
|
6
6
|
export type RestRequestArgs = {
|
|
@@ -40,8 +40,8 @@ export type RestTransportConfig = {
|
|
|
40
40
|
timeoutMs?: number
|
|
41
41
|
key?: string
|
|
42
42
|
name?: string
|
|
43
|
-
apiKeyStamper:
|
|
44
|
-
passkeyStamper:
|
|
43
|
+
apiKeyStamper: Stamper
|
|
44
|
+
passkeyStamper: Stamper
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
export function rest(url: string, cfg: RestTransportConfig): RestTransport {
|
|
@@ -64,7 +64,7 @@ export function rest(url: string, cfg: RestTransportConfig): RestTransport {
|
|
|
64
64
|
|
|
65
65
|
// Handle stamping if requested
|
|
66
66
|
if (args.stamp) {
|
|
67
|
-
let stamper:
|
|
67
|
+
let stamper: Stamper
|
|
68
68
|
if (args.stampWith === 'apiKey') {
|
|
69
69
|
stamper = cfg.apiKeyStamper
|
|
70
70
|
} else if (args.stampWith === 'passkey') {
|