@privy-io/node 0.6.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/client.d.mts +7 -7
- package/client.d.mts.map +1 -1
- package/client.d.ts +7 -7
- package/client.d.ts.map +1 -1
- package/client.js.map +1 -1
- package/client.mjs.map +1 -1
- package/index.d.mts +2 -1
- package/index.d.mts.map +1 -1
- package/index.d.ts +2 -1
- package/index.d.ts.map +1 -1
- package/index.js +4 -1
- package/index.js.map +1 -1
- package/index.mjs +2 -1
- package/index.mjs.map +1 -1
- package/lib/auth.d.mts +30 -2
- package/lib/auth.d.mts.map +1 -1
- package/lib/auth.d.ts +30 -2
- package/lib/auth.d.ts.map +1 -1
- package/lib/auth.js +14 -5
- package/lib/auth.js.map +1 -1
- package/lib/auth.mjs +11 -3
- package/lib/auth.mjs.map +1 -1
- package/lib/cryptography.d.mts +35 -3
- package/lib/cryptography.d.mts.map +1 -1
- package/lib/cryptography.d.ts +35 -3
- package/lib/cryptography.d.ts.map +1 -1
- package/lib/cryptography.js +53 -6
- package/lib/cryptography.js.map +1 -1
- package/lib/cryptography.mjs +50 -3
- package/lib/cryptography.mjs.map +1 -1
- package/lib/identity-token.d.mts.map +1 -1
- package/lib/identity-token.d.ts.map +1 -1
- package/lib/identity-token.js +0 -1
- package/lib/identity-token.js.map +1 -1
- package/lib/identity-token.mjs +0 -1
- package/lib/identity-token.mjs.map +1 -1
- package/package.json +13 -1
- package/public-api/services/utils/auth.d.mts +10 -1
- package/public-api/services/utils/auth.d.mts.map +1 -1
- package/public-api/services/utils/auth.d.ts +10 -1
- package/public-api/services/utils/auth.d.ts.map +1 -1
- package/public-api/services/utils/auth.js +16 -5
- package/public-api/services/utils/auth.js.map +1 -1
- package/public-api/services/utils/auth.mjs +17 -6
- package/public-api/services/utils/auth.mjs.map +1 -1
- package/resources/apps.d.mts +25 -0
- package/resources/apps.d.mts.map +1 -1
- package/resources/apps.d.ts +25 -0
- package/resources/apps.d.ts.map +1 -1
- package/resources/index.d.mts +3 -3
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +3 -3
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs.map +1 -1
- package/resources/policies.d.mts +68 -115
- package/resources/policies.d.mts.map +1 -1
- package/resources/policies.d.ts +68 -115
- package/resources/policies.d.ts.map +1 -1
- package/resources/policies.js.map +1 -1
- package/resources/policies.mjs.map +1 -1
- package/resources/users.d.mts +642 -381
- package/resources/users.d.mts.map +1 -1
- package/resources/users.d.ts +642 -381
- package/resources/users.d.ts.map +1 -1
- package/resources/wallets/index.d.mts +1 -1
- package/resources/wallets/index.d.mts.map +1 -1
- package/resources/wallets/index.d.ts +1 -1
- package/resources/wallets/index.d.ts.map +1 -1
- package/resources/wallets/index.js.map +1 -1
- package/resources/wallets/index.mjs.map +1 -1
- package/resources/wallets/wallets.d.mts +98 -4
- package/resources/wallets/wallets.d.mts.map +1 -1
- package/resources/wallets/wallets.d.ts +98 -4
- package/resources/wallets/wallets.d.ts.map +1 -1
- package/resources/wallets/wallets.js +1 -1
- package/resources/wallets/wallets.js.map +1 -1
- package/resources/wallets/wallets.mjs +1 -1
- package/resources/wallets/wallets.mjs.map +1 -1
- package/solana-kit.d.mts +53 -0
- package/solana-kit.d.mts.map +1 -0
- package/solana-kit.d.ts +53 -0
- package/solana-kit.d.ts.map +1 -0
- package/solana-kit.js +92 -0
- package/solana-kit.js.map +1 -0
- package/solana-kit.mjs +89 -0
- package/solana-kit.mjs.map +1 -0
- package/src/client.ts +131 -3
- package/src/index.ts +5 -0
- package/src/lib/auth.ts +42 -6
- package/src/lib/cryptography.ts +72 -3
- package/src/lib/identity-token.ts +38 -18
- package/src/public-api/services/utils/auth.ts +19 -6
- package/src/resources/apps.ts +44 -0
- package/src/resources/index.ts +66 -2
- package/src/resources/policies.ts +105 -191
- package/src/resources/users.ts +942 -625
- package/src/resources/wallets/index.ts +6 -0
- package/src/resources/wallets/wallets.ts +125 -3
- package/src/solana-kit.ts +148 -0
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/src/client.ts
CHANGED
|
@@ -51,21 +51,78 @@ import {
|
|
|
51
51
|
PolicyUpdateParams,
|
|
52
52
|
PolicyUpdateRuleParams,
|
|
53
53
|
PolicyUpdateRuleResponse,
|
|
54
|
+
SuiTransactionCommandCondition,
|
|
55
|
+
SuiTransactionCommandOperator,
|
|
56
|
+
SuiTransferObjectsCommandCondition,
|
|
57
|
+
SuiTransferObjectsCommandField,
|
|
58
|
+
TronTransactionCondition,
|
|
54
59
|
} from './resources/policies';
|
|
55
60
|
import { TransactionGetResponse, Transactions } from './resources/transactions';
|
|
56
61
|
import {
|
|
57
62
|
AuthenticatedUser,
|
|
63
|
+
CrossAppEmbeddedWallet,
|
|
64
|
+
CrossAppSmartWallet,
|
|
65
|
+
CustomMetadata,
|
|
66
|
+
EmbeddedWalletRecoveryMethod,
|
|
58
67
|
LinkedAccount,
|
|
68
|
+
LinkedAccountAppleInput,
|
|
69
|
+
LinkedAccountAppleOAuth,
|
|
70
|
+
LinkedAccountAuthorizationKey,
|
|
71
|
+
LinkedAccountBaseWallet,
|
|
59
72
|
LinkedAccountBitcoinSegwitEmbeddedWallet,
|
|
60
73
|
LinkedAccountBitcoinTaprootEmbeddedWallet,
|
|
74
|
+
LinkedAccountCrossApp,
|
|
61
75
|
LinkedAccountCurveSigningEmbeddedWallet,
|
|
76
|
+
LinkedAccountCustomJwt,
|
|
77
|
+
LinkedAccountCustomJwtInput,
|
|
78
|
+
LinkedAccountCustomOAuth,
|
|
79
|
+
LinkedAccountDiscordInput,
|
|
80
|
+
LinkedAccountDiscordOAuth,
|
|
81
|
+
LinkedAccountEmail,
|
|
82
|
+
LinkedAccountEmailInput,
|
|
62
83
|
LinkedAccountEmbeddedWallet,
|
|
63
84
|
LinkedAccountEmbeddedWalletWithID,
|
|
85
|
+
LinkedAccountEthereum,
|
|
64
86
|
LinkedAccountEthereumEmbeddedWallet,
|
|
87
|
+
LinkedAccountFarcaster,
|
|
88
|
+
LinkedAccountFarcasterInput,
|
|
89
|
+
LinkedAccountGitHubInput,
|
|
90
|
+
LinkedAccountGitHubOAuth,
|
|
91
|
+
LinkedAccountGoogleInput,
|
|
92
|
+
LinkedAccountGoogleOAuth,
|
|
93
|
+
LinkedAccountInput,
|
|
94
|
+
LinkedAccountInstagramInput,
|
|
95
|
+
LinkedAccountInstagramOAuth,
|
|
96
|
+
LinkedAccountLineInput,
|
|
97
|
+
LinkedAccountLineOAuth,
|
|
98
|
+
LinkedAccountLinkedInInput,
|
|
99
|
+
LinkedAccountLinkedInOAuth,
|
|
100
|
+
LinkedAccountPasskey,
|
|
101
|
+
LinkedAccountPhone,
|
|
102
|
+
LinkedAccountPhoneInput,
|
|
65
103
|
LinkedAccountSmartWallet,
|
|
104
|
+
LinkedAccountSolana,
|
|
66
105
|
LinkedAccountSolanaEmbeddedWallet,
|
|
106
|
+
LinkedAccountSpotifyInput,
|
|
107
|
+
LinkedAccountSpotifyOAuth,
|
|
108
|
+
LinkedAccountTelegram,
|
|
109
|
+
LinkedAccountTelegramInput,
|
|
110
|
+
LinkedAccountTiktokInput,
|
|
111
|
+
LinkedAccountTiktokOAuth,
|
|
112
|
+
LinkedAccountTwitchInput,
|
|
113
|
+
LinkedAccountTwitchOAuth,
|
|
114
|
+
LinkedAccountTwitterInput,
|
|
115
|
+
LinkedAccountTwitterOAuth,
|
|
116
|
+
LinkedAccountType,
|
|
117
|
+
LinkedAccountWalletInput,
|
|
118
|
+
LinkedMfaMethod,
|
|
119
|
+
OAuthTokens,
|
|
120
|
+
PasskeyMfaMethod,
|
|
121
|
+
SMSMfaMethod,
|
|
67
122
|
SmartWalletType,
|
|
123
|
+
TotpMfaMethod,
|
|
68
124
|
User,
|
|
125
|
+
UserBatchCreateInput,
|
|
69
126
|
UserCreateParams,
|
|
70
127
|
UserGetByCustomAuthIDParams,
|
|
71
128
|
UserGetByDiscordUsernameParams,
|
|
@@ -84,11 +141,16 @@ import {
|
|
|
84
141
|
UserSearchParams,
|
|
85
142
|
UserSetCustomMetadataParams,
|
|
86
143
|
UserUnlinkLinkedAccountParams,
|
|
144
|
+
UserWithIdentityToken,
|
|
87
145
|
Users,
|
|
88
146
|
UsersCursor,
|
|
89
147
|
} from './resources/users';
|
|
90
148
|
import {
|
|
91
149
|
CurveSigningChainType,
|
|
150
|
+
CustodialWallet,
|
|
151
|
+
CustodialWalletChainType,
|
|
152
|
+
CustodialWalletCreateInput,
|
|
153
|
+
CustodialWalletProvider,
|
|
92
154
|
EthereumPersonalSignRpcInput,
|
|
93
155
|
EthereumPersonalSignRpcResponse,
|
|
94
156
|
EthereumSecp256k1SignRpcInput,
|
|
@@ -105,12 +167,14 @@ import {
|
|
|
105
167
|
EthereumSignUserOperationRpcResponse,
|
|
106
168
|
ExtendedChainType,
|
|
107
169
|
FirstClassChainType,
|
|
170
|
+
HpkeImportConfig,
|
|
108
171
|
SolanaSignAndSendTransactionRpcInput,
|
|
109
172
|
SolanaSignAndSendTransactionRpcResponse,
|
|
110
173
|
SolanaSignMessageRpcInput,
|
|
111
174
|
SolanaSignMessageRpcResponse,
|
|
112
175
|
SolanaSignTransactionRpcInput,
|
|
113
176
|
SolanaSignTransactionRpcResponse,
|
|
177
|
+
SuiCommandName,
|
|
114
178
|
Wallet,
|
|
115
179
|
WalletAuthenticateWithJwtParams,
|
|
116
180
|
WalletAuthenticateWithJwtResponse,
|
|
@@ -253,7 +317,7 @@ export class PrivyAPI {
|
|
|
253
317
|
baseURL: string;
|
|
254
318
|
maxRetries: number;
|
|
255
319
|
timeout: number;
|
|
256
|
-
logger: Logger
|
|
320
|
+
logger: Logger;
|
|
257
321
|
logLevel: LogLevel | undefined;
|
|
258
322
|
fetchOptions: MergedRequestInit | undefined;
|
|
259
323
|
|
|
@@ -925,6 +989,12 @@ export declare namespace PrivyAPI {
|
|
|
925
989
|
type WalletChainType as WalletChainType,
|
|
926
990
|
type ExtendedChainType as ExtendedChainType,
|
|
927
991
|
type WalletCustodian as WalletCustodian,
|
|
992
|
+
type CustodialWalletProvider as CustodialWalletProvider,
|
|
993
|
+
type CustodialWalletChainType as CustodialWalletChainType,
|
|
994
|
+
type CustodialWalletCreateInput as CustodialWalletCreateInput,
|
|
995
|
+
type CustodialWallet as CustodialWallet,
|
|
996
|
+
type HpkeImportConfig as HpkeImportConfig,
|
|
997
|
+
type SuiCommandName as SuiCommandName,
|
|
928
998
|
type EthereumPersonalSignRpcInput as EthereumPersonalSignRpcInput,
|
|
929
999
|
type EthereumSignTransactionRpcInput as EthereumSignTransactionRpcInput,
|
|
930
1000
|
type EthereumSendTransactionRpcInput as EthereumSendTransactionRpcInput,
|
|
@@ -969,6 +1039,17 @@ export declare namespace PrivyAPI {
|
|
|
969
1039
|
type AuthenticatedUser as AuthenticatedUser,
|
|
970
1040
|
type LinkedAccount as LinkedAccount,
|
|
971
1041
|
type User as User,
|
|
1042
|
+
type LinkedAccountEmail as LinkedAccountEmail,
|
|
1043
|
+
type LinkedAccountPhone as LinkedAccountPhone,
|
|
1044
|
+
type LinkedAccountBaseWallet as LinkedAccountBaseWallet,
|
|
1045
|
+
type LinkedAccountEthereum as LinkedAccountEthereum,
|
|
1046
|
+
type SmartWalletType as SmartWalletType,
|
|
1047
|
+
type LinkedAccountSmartWallet as LinkedAccountSmartWallet,
|
|
1048
|
+
type LinkedAccountSolana as LinkedAccountSolana,
|
|
1049
|
+
type LinkedAccountFarcaster as LinkedAccountFarcaster,
|
|
1050
|
+
type LinkedAccountPasskey as LinkedAccountPasskey,
|
|
1051
|
+
type LinkedAccountTelegram as LinkedAccountTelegram,
|
|
1052
|
+
type EmbeddedWalletRecoveryMethod as EmbeddedWalletRecoveryMethod,
|
|
972
1053
|
type LinkedAccountEthereumEmbeddedWallet as LinkedAccountEthereumEmbeddedWallet,
|
|
973
1054
|
type LinkedAccountSolanaEmbeddedWallet as LinkedAccountSolanaEmbeddedWallet,
|
|
974
1055
|
type LinkedAccountBitcoinSegwitEmbeddedWallet as LinkedAccountBitcoinSegwitEmbeddedWallet,
|
|
@@ -976,8 +1057,50 @@ export declare namespace PrivyAPI {
|
|
|
976
1057
|
type LinkedAccountCurveSigningEmbeddedWallet as LinkedAccountCurveSigningEmbeddedWallet,
|
|
977
1058
|
type LinkedAccountEmbeddedWallet as LinkedAccountEmbeddedWallet,
|
|
978
1059
|
type LinkedAccountEmbeddedWalletWithID as LinkedAccountEmbeddedWalletWithID,
|
|
979
|
-
type
|
|
980
|
-
type
|
|
1060
|
+
type LinkedAccountGoogleOAuth as LinkedAccountGoogleOAuth,
|
|
1061
|
+
type LinkedAccountTwitterOAuth as LinkedAccountTwitterOAuth,
|
|
1062
|
+
type LinkedAccountDiscordOAuth as LinkedAccountDiscordOAuth,
|
|
1063
|
+
type LinkedAccountGitHubOAuth as LinkedAccountGitHubOAuth,
|
|
1064
|
+
type LinkedAccountLinkedInOAuth as LinkedAccountLinkedInOAuth,
|
|
1065
|
+
type LinkedAccountSpotifyOAuth as LinkedAccountSpotifyOAuth,
|
|
1066
|
+
type LinkedAccountInstagramOAuth as LinkedAccountInstagramOAuth,
|
|
1067
|
+
type LinkedAccountTiktokOAuth as LinkedAccountTiktokOAuth,
|
|
1068
|
+
type LinkedAccountLineOAuth as LinkedAccountLineOAuth,
|
|
1069
|
+
type LinkedAccountTwitchOAuth as LinkedAccountTwitchOAuth,
|
|
1070
|
+
type LinkedAccountAppleOAuth as LinkedAccountAppleOAuth,
|
|
1071
|
+
type LinkedAccountCustomOAuth as LinkedAccountCustomOAuth,
|
|
1072
|
+
type LinkedAccountCustomJwt as LinkedAccountCustomJwt,
|
|
1073
|
+
type CrossAppEmbeddedWallet as CrossAppEmbeddedWallet,
|
|
1074
|
+
type CrossAppSmartWallet as CrossAppSmartWallet,
|
|
1075
|
+
type LinkedAccountCrossApp as LinkedAccountCrossApp,
|
|
1076
|
+
type LinkedAccountAuthorizationKey as LinkedAccountAuthorizationKey,
|
|
1077
|
+
type LinkedAccountType as LinkedAccountType,
|
|
1078
|
+
type CustomMetadata as CustomMetadata,
|
|
1079
|
+
type LinkedAccountWalletInput as LinkedAccountWalletInput,
|
|
1080
|
+
type LinkedAccountEmailInput as LinkedAccountEmailInput,
|
|
1081
|
+
type LinkedAccountPhoneInput as LinkedAccountPhoneInput,
|
|
1082
|
+
type LinkedAccountGoogleInput as LinkedAccountGoogleInput,
|
|
1083
|
+
type LinkedAccountTwitterInput as LinkedAccountTwitterInput,
|
|
1084
|
+
type LinkedAccountDiscordInput as LinkedAccountDiscordInput,
|
|
1085
|
+
type LinkedAccountGitHubInput as LinkedAccountGitHubInput,
|
|
1086
|
+
type LinkedAccountSpotifyInput as LinkedAccountSpotifyInput,
|
|
1087
|
+
type LinkedAccountInstagramInput as LinkedAccountInstagramInput,
|
|
1088
|
+
type LinkedAccountTiktokInput as LinkedAccountTiktokInput,
|
|
1089
|
+
type LinkedAccountLineInput as LinkedAccountLineInput,
|
|
1090
|
+
type LinkedAccountTwitchInput as LinkedAccountTwitchInput,
|
|
1091
|
+
type LinkedAccountAppleInput as LinkedAccountAppleInput,
|
|
1092
|
+
type LinkedAccountLinkedInInput as LinkedAccountLinkedInInput,
|
|
1093
|
+
type LinkedAccountFarcasterInput as LinkedAccountFarcasterInput,
|
|
1094
|
+
type LinkedAccountTelegramInput as LinkedAccountTelegramInput,
|
|
1095
|
+
type LinkedAccountCustomJwtInput as LinkedAccountCustomJwtInput,
|
|
1096
|
+
type LinkedAccountInput as LinkedAccountInput,
|
|
1097
|
+
type UserBatchCreateInput as UserBatchCreateInput,
|
|
1098
|
+
type SMSMfaMethod as SMSMfaMethod,
|
|
1099
|
+
type TotpMfaMethod as TotpMfaMethod,
|
|
1100
|
+
type PasskeyMfaMethod as PasskeyMfaMethod,
|
|
1101
|
+
type LinkedMfaMethod as LinkedMfaMethod,
|
|
1102
|
+
type OAuthTokens as OAuthTokens,
|
|
1103
|
+
type UserWithIdentityToken as UserWithIdentityToken,
|
|
981
1104
|
type UsersCursor as UsersCursor,
|
|
982
1105
|
type UserCreateParams as UserCreateParams,
|
|
983
1106
|
type UserListParams as UserListParams,
|
|
@@ -1002,6 +1125,11 @@ export declare namespace PrivyAPI {
|
|
|
1002
1125
|
export {
|
|
1003
1126
|
Policies as Policies,
|
|
1004
1127
|
type Policy as Policy,
|
|
1128
|
+
type SuiTransactionCommandOperator as SuiTransactionCommandOperator,
|
|
1129
|
+
type SuiTransferObjectsCommandField as SuiTransferObjectsCommandField,
|
|
1130
|
+
type TronTransactionCondition as TronTransactionCondition,
|
|
1131
|
+
type SuiTransactionCommandCondition as SuiTransactionCommandCondition,
|
|
1132
|
+
type SuiTransferObjectsCommandCondition as SuiTransferObjectsCommandCondition,
|
|
1005
1133
|
type PolicyCreateRuleResponse as PolicyCreateRuleResponse,
|
|
1006
1134
|
type PolicyDeleteResponse as PolicyDeleteResponse,
|
|
1007
1135
|
type PolicyDeleteRuleResponse as PolicyDeleteRuleResponse,
|
package/src/index.ts
CHANGED
|
@@ -9,6 +9,9 @@ export { type PrivyUsersService } from './public-api/services/users';
|
|
|
9
9
|
export { type PrivyUtils } from './public-api/services/utils';
|
|
10
10
|
export {
|
|
11
11
|
InvalidAuthTokenError,
|
|
12
|
+
verifyAccessToken,
|
|
13
|
+
type VerifyAccessTokenResponse,
|
|
14
|
+
type VerifyAccessTokenInput,
|
|
12
15
|
verifyAuthToken,
|
|
13
16
|
type VerifyAuthTokenResponse,
|
|
14
17
|
type VerifyAuthTokenInput,
|
|
@@ -29,6 +32,8 @@ export {
|
|
|
29
32
|
generateAuthorizationSignatures,
|
|
30
33
|
} from './lib/authorization';
|
|
31
34
|
|
|
35
|
+
export { generateP256KeyPair, type P256KeyPair } from './lib/cryptography';
|
|
36
|
+
|
|
32
37
|
export { type EmbeddedWalletLinkedAccount, isEmbeddedWalletLinkedAccount } from './lib/user-utils';
|
|
33
38
|
|
|
34
39
|
export { APIPromise } from './core/api-promise';
|
package/src/lib/auth.ts
CHANGED
|
@@ -14,6 +14,23 @@ import { User } from '../resources';
|
|
|
14
14
|
const JWT_ALGORITHM = 'ES256';
|
|
15
15
|
const JWT_ISSUER = 'privy.io';
|
|
16
16
|
|
|
17
|
+
export type VerifyAccessTokenInput = {
|
|
18
|
+
/** The access token to verify. */
|
|
19
|
+
access_token: string;
|
|
20
|
+
/** The Privy app ID to verify the token against. */
|
|
21
|
+
app_id: string;
|
|
22
|
+
/**
|
|
23
|
+
* The verification key to use to verify the token, or a mechanism to get the it such as via JWKS.
|
|
24
|
+
* You can find this verification key (or a JWKS endpoint) in the Privy dashboard.
|
|
25
|
+
* @see {@link createRemoteJWKSet}
|
|
26
|
+
* @see {@link importSPKI}
|
|
27
|
+
*/
|
|
28
|
+
verification_key: CryptoKey | JWTVerifyGetKey | string;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated Use `VerifyAccessTokenInput` instead.
|
|
33
|
+
*/
|
|
17
34
|
export type VerifyAuthTokenInput = {
|
|
18
35
|
/** The authentication token to verify. */
|
|
19
36
|
auth_token: string;
|
|
@@ -28,7 +45,7 @@ export type VerifyAuthTokenInput = {
|
|
|
28
45
|
verification_key: CryptoKey | JWTVerifyGetKey | string;
|
|
29
46
|
};
|
|
30
47
|
|
|
31
|
-
export type
|
|
48
|
+
export type VerifyAccessTokenResponse = {
|
|
32
49
|
/** The Privy app ID for which the token was issued. */
|
|
33
50
|
app_id: string;
|
|
34
51
|
/** The issuer of the token. */
|
|
@@ -43,6 +60,11 @@ export type VerifyAuthTokenResponse = {
|
|
|
43
60
|
user_id: string;
|
|
44
61
|
};
|
|
45
62
|
|
|
63
|
+
/**
|
|
64
|
+
* @deprecated Use `VerifyAccessTokenResponse` instead.
|
|
65
|
+
*/
|
|
66
|
+
export type VerifyAuthTokenResponse = VerifyAccessTokenResponse;
|
|
67
|
+
|
|
46
68
|
/**
|
|
47
69
|
* Verifies a JWT issued by privy.io for the given app ID.
|
|
48
70
|
* This serves both auth tokens and identity tokens.
|
|
@@ -76,21 +98,21 @@ async function verifyPrivyIssuedJwt(
|
|
|
76
98
|
}
|
|
77
99
|
|
|
78
100
|
/**
|
|
79
|
-
* Verifies a Privy-issued
|
|
101
|
+
* Verifies a Privy-issued access token.
|
|
80
102
|
*
|
|
81
103
|
* @returns The payload of the token if it is valid.
|
|
82
104
|
* @throws If the token is invalid.
|
|
83
105
|
*/
|
|
84
|
-
export async function
|
|
85
|
-
|
|
106
|
+
export async function verifyAccessToken({
|
|
107
|
+
access_token: accessToken,
|
|
86
108
|
app_id: appId,
|
|
87
109
|
verification_key: verificationKeyOrString,
|
|
88
|
-
}:
|
|
110
|
+
}: VerifyAccessTokenInput): Promise<VerifyAccessTokenResponse> {
|
|
89
111
|
const verificationKey =
|
|
90
112
|
typeof verificationKeyOrString === 'string' ?
|
|
91
113
|
await importSPKI(verificationKeyOrString, JWT_ALGORITHM)
|
|
92
114
|
: verificationKeyOrString;
|
|
93
|
-
const verifiedToken = await verifyPrivyIssuedJwt(
|
|
115
|
+
const verifiedToken = await verifyPrivyIssuedJwt(accessToken, appId, verificationKey);
|
|
94
116
|
return {
|
|
95
117
|
app_id: throwIfNotString(verifiedToken.payload.aud),
|
|
96
118
|
issuer: throwIfNotString(verifiedToken.payload.iss),
|
|
@@ -101,6 +123,20 @@ export async function verifyAuthToken({
|
|
|
101
123
|
};
|
|
102
124
|
}
|
|
103
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Verifies a Privy-issued authentication token.
|
|
128
|
+
*
|
|
129
|
+
* @returns The payload of the token if it is valid.
|
|
130
|
+
* @throws If the token is invalid.
|
|
131
|
+
* @deprecated Use `verifyAccessToken` instead.
|
|
132
|
+
*/
|
|
133
|
+
export const verifyAuthToken = ({
|
|
134
|
+
auth_token,
|
|
135
|
+
app_id,
|
|
136
|
+
verification_key,
|
|
137
|
+
}: VerifyAuthTokenInput): Promise<VerifyAuthTokenResponse> =>
|
|
138
|
+
verifyAccessToken({ access_token: auth_token, app_id, verification_key });
|
|
139
|
+
|
|
104
140
|
export type VerifyIdentityTokenInput = {
|
|
105
141
|
/** The identity token to verify. */
|
|
106
142
|
identity_token: string;
|
package/src/lib/cryptography.ts
CHANGED
|
@@ -2,6 +2,74 @@ import { Chacha20Poly1305 } from '@hpke/chacha20poly1305';
|
|
|
2
2
|
import { CipherSuite, DhkemP256HkdfSha256, HkdfSha256 } from '@hpke/core';
|
|
3
3
|
import { p256 } from '@noble/curves/nist';
|
|
4
4
|
import type { PrivKey } from '@noble/curves/utils';
|
|
5
|
+
import { toBase64 } from '../internal/utils/base64';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Returns the runtime's `SubtleCrypto` implementation.
|
|
9
|
+
*
|
|
10
|
+
* We rely on `globalThis.crypto.subtle` for broad runtime support (Node.js 20+, Deno, Bun, Workers/Edge).
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
function getSubtleCrypto(): typeof globalThis.crypto.subtle {
|
|
15
|
+
const subtle = (globalThis as any).crypto?.subtle;
|
|
16
|
+
if (!subtle) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
'`crypto.subtle` is not defined as a global; Either run in a runtime that provides WebCrypto, or polyfill `globalThis.crypto`',
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
return subtle;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface P256KeyPair {
|
|
25
|
+
/**
|
|
26
|
+
* The base64-encoded SPKI-formatted public key, with no PEM headers.
|
|
27
|
+
*
|
|
28
|
+
* This is the format accepted by Privy when specifying a P-256 public key owner.
|
|
29
|
+
*/
|
|
30
|
+
publicKey: string;
|
|
31
|
+
/**
|
|
32
|
+
* The base64-encoded PKCS8-formatted private key, with no PEM headers.
|
|
33
|
+
*
|
|
34
|
+
* This is the format accepted by {@link AuthorizationContext.authorization_private_keys} and
|
|
35
|
+
* {@link generateAuthorizationSignature}.
|
|
36
|
+
*/
|
|
37
|
+
privateKey: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Generates a P-256 key pair suitable for Privy resource ownership and request
|
|
42
|
+
* authorization signing.
|
|
43
|
+
*
|
|
44
|
+
* @returns A P-256 key pair, in base64-encoded DER format.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* const keypair = await generateP256KeyPair();
|
|
48
|
+
* const wallet = await privy.wallets().create({
|
|
49
|
+
* chain_type: '...',
|
|
50
|
+
* owner: { public_key: keypair.publicKey },
|
|
51
|
+
* });
|
|
52
|
+
* const response = await privy.wallets().rawSign(wallet.id, {
|
|
53
|
+
* params: { hash: '...' },
|
|
54
|
+
* authorization_context: {
|
|
55
|
+
* authorization_private_keys: [keypair.privateKey]
|
|
56
|
+
* },
|
|
57
|
+
* });
|
|
58
|
+
*/
|
|
59
|
+
export async function generateP256KeyPair(): Promise<P256KeyPair> {
|
|
60
|
+
const subtle = getSubtleCrypto();
|
|
61
|
+
const keyPair = await subtle.generateKey({ name: 'ECDSA', namedCurve: 'P-256' }, true, ['sign', 'verify']);
|
|
62
|
+
|
|
63
|
+
const [publicKeyDer, privateKeyDer] = await Promise.all([
|
|
64
|
+
subtle.exportKey('spki', keyPair.publicKey),
|
|
65
|
+
subtle.exportKey('pkcs8', keyPair.privateKey),
|
|
66
|
+
]);
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
publicKey: toBase64(new Uint8Array(publicKeyDer)),
|
|
70
|
+
privateKey: toBase64(new Uint8Array(privateKeyDer)),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
5
73
|
|
|
6
74
|
/**
|
|
7
75
|
* Imports a P-256 private key for use with the `@noble/curves` library.
|
|
@@ -53,7 +121,8 @@ export async function setupHPKERecipient(): Promise<HPKERecipient> {
|
|
|
53
121
|
});
|
|
54
122
|
|
|
55
123
|
const keypair = await suite.kem.generateKeyPair();
|
|
56
|
-
const
|
|
124
|
+
const subtle = getSubtleCrypto();
|
|
125
|
+
const publicKeySpki = await subtle.exportKey('spki', keypair.publicKey);
|
|
57
126
|
|
|
58
127
|
return {
|
|
59
128
|
publicKeySpki: new Uint8Array(publicKeySpki),
|
|
@@ -113,5 +182,5 @@ export async function setupHPKESender(): Promise<HPKESender> {
|
|
|
113
182
|
}
|
|
114
183
|
|
|
115
184
|
/** This prefix is no longer used, but we need to support existing keys */
|
|
116
|
-
|
|
117
|
-
|
|
185
|
+
const WALLET_API_PRIVATE_KEY_PREFIX = 'wallet-api:';
|
|
186
|
+
const AUTHORIZATION_PRIVATE_KEY_PREFIX = 'wallet-auth:';
|
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
import { JWTPayload } from 'jose';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
User,
|
|
4
|
+
LinkedAccount,
|
|
5
|
+
LinkedAccountSmartWallet,
|
|
6
|
+
LinkedAccountEmbeddedWallet,
|
|
7
|
+
LinkedAccountEmail,
|
|
8
|
+
LinkedAccountPhone,
|
|
9
|
+
LinkedAccountFarcaster,
|
|
10
|
+
LinkedAccountGoogleOAuth,
|
|
11
|
+
LinkedAccountTwitterOAuth,
|
|
12
|
+
LinkedAccountDiscordOAuth,
|
|
13
|
+
LinkedAccountGitHubOAuth,
|
|
14
|
+
LinkedAccountSpotifyOAuth,
|
|
15
|
+
LinkedAccountInstagramOAuth,
|
|
16
|
+
LinkedAccountTiktokOAuth,
|
|
17
|
+
LinkedAccountLinkedInOAuth,
|
|
18
|
+
LinkedAccountAppleOAuth,
|
|
19
|
+
LinkedAccountCrossApp,
|
|
20
|
+
LinkedAccountCustomJwt,
|
|
21
|
+
LinkedAccountTelegram,
|
|
22
|
+
LinkedAccountPasskey,
|
|
23
|
+
} from '../resources';
|
|
3
24
|
import { PrivyAPIError } from '../error';
|
|
4
25
|
import { ExternalWalletLinkedAccount } from './user-utils';
|
|
5
26
|
|
|
@@ -48,7 +69,7 @@ function mapIdLinkedAccountToUserLinkedAccount(account: any): LinkedAccount | nu
|
|
|
48
69
|
first_verified_at: null,
|
|
49
70
|
verified_at: account.lv,
|
|
50
71
|
latest_verified_at: account.lv,
|
|
51
|
-
} satisfies
|
|
72
|
+
} satisfies LinkedAccountEmail;
|
|
52
73
|
}
|
|
53
74
|
if (account.type === 'phone') {
|
|
54
75
|
return {
|
|
@@ -57,7 +78,7 @@ function mapIdLinkedAccountToUserLinkedAccount(account: any): LinkedAccount | nu
|
|
|
57
78
|
first_verified_at: null,
|
|
58
79
|
verified_at: account.lv,
|
|
59
80
|
latest_verified_at: account.lv,
|
|
60
|
-
} satisfies
|
|
81
|
+
} satisfies LinkedAccountPhone;
|
|
61
82
|
}
|
|
62
83
|
|
|
63
84
|
// Parses all wallet types
|
|
@@ -113,7 +134,7 @@ function mapIdLinkedAccountToUserLinkedAccount(account: any): LinkedAccount | nu
|
|
|
113
134
|
verified_at: account.lv,
|
|
114
135
|
latest_verified_at: account.lv,
|
|
115
136
|
owner_address: account.oa,
|
|
116
|
-
} satisfies
|
|
137
|
+
} satisfies LinkedAccountFarcaster;
|
|
117
138
|
}
|
|
118
139
|
if (account.type === 'google_oauth') {
|
|
119
140
|
return {
|
|
@@ -124,7 +145,7 @@ function mapIdLinkedAccountToUserLinkedAccount(account: any): LinkedAccount | nu
|
|
|
124
145
|
first_verified_at: null,
|
|
125
146
|
verified_at: account.lv,
|
|
126
147
|
latest_verified_at: account.lv,
|
|
127
|
-
} satisfies
|
|
148
|
+
} satisfies LinkedAccountGoogleOAuth;
|
|
128
149
|
}
|
|
129
150
|
if (account.type === 'twitter_oauth') {
|
|
130
151
|
// We send along three potential URL shapes here based on possible profile picture URLs, all
|
|
@@ -148,7 +169,7 @@ function mapIdLinkedAccountToUserLinkedAccount(account: any): LinkedAccount | nu
|
|
|
148
169
|
first_verified_at: null,
|
|
149
170
|
verified_at: account.lv,
|
|
150
171
|
latest_verified_at: account.lv,
|
|
151
|
-
} satisfies
|
|
172
|
+
} satisfies LinkedAccountTwitterOAuth;
|
|
152
173
|
}
|
|
153
174
|
if (account.type === 'discord_oauth') {
|
|
154
175
|
return {
|
|
@@ -159,7 +180,7 @@ function mapIdLinkedAccountToUserLinkedAccount(account: any): LinkedAccount | nu
|
|
|
159
180
|
first_verified_at: null,
|
|
160
181
|
verified_at: account.lv,
|
|
161
182
|
latest_verified_at: account.lv,
|
|
162
|
-
} satisfies
|
|
183
|
+
} satisfies LinkedAccountDiscordOAuth;
|
|
163
184
|
}
|
|
164
185
|
if (account.type === 'github_oauth') {
|
|
165
186
|
return {
|
|
@@ -171,7 +192,7 @@ function mapIdLinkedAccountToUserLinkedAccount(account: any): LinkedAccount | nu
|
|
|
171
192
|
first_verified_at: null,
|
|
172
193
|
verified_at: account.lv,
|
|
173
194
|
latest_verified_at: account.lv,
|
|
174
|
-
} satisfies
|
|
195
|
+
} satisfies LinkedAccountGitHubOAuth;
|
|
175
196
|
}
|
|
176
197
|
if (account.type === 'spotify_oauth') {
|
|
177
198
|
return {
|
|
@@ -182,7 +203,7 @@ function mapIdLinkedAccountToUserLinkedAccount(account: any): LinkedAccount | nu
|
|
|
182
203
|
first_verified_at: null,
|
|
183
204
|
verified_at: account.lv,
|
|
184
205
|
latest_verified_at: account.lv,
|
|
185
|
-
} satisfies
|
|
206
|
+
} satisfies LinkedAccountSpotifyOAuth;
|
|
186
207
|
}
|
|
187
208
|
if (account.type === 'instagram_oauth') {
|
|
188
209
|
return {
|
|
@@ -192,7 +213,7 @@ function mapIdLinkedAccountToUserLinkedAccount(account: any): LinkedAccount | nu
|
|
|
192
213
|
first_verified_at: null,
|
|
193
214
|
verified_at: account.lv,
|
|
194
215
|
latest_verified_at: account.lv,
|
|
195
|
-
} satisfies
|
|
216
|
+
} satisfies LinkedAccountInstagramOAuth;
|
|
196
217
|
}
|
|
197
218
|
if (account.type === 'tiktok_oauth') {
|
|
198
219
|
return {
|
|
@@ -203,7 +224,7 @@ function mapIdLinkedAccountToUserLinkedAccount(account: any): LinkedAccount | nu
|
|
|
203
224
|
first_verified_at: null,
|
|
204
225
|
verified_at: account.lv,
|
|
205
226
|
latest_verified_at: account.lv,
|
|
206
|
-
} satisfies
|
|
227
|
+
} satisfies LinkedAccountTiktokOAuth;
|
|
207
228
|
}
|
|
208
229
|
if (account.type === 'linkedin_oauth') {
|
|
209
230
|
return {
|
|
@@ -213,7 +234,7 @@ function mapIdLinkedAccountToUserLinkedAccount(account: any): LinkedAccount | nu
|
|
|
213
234
|
first_verified_at: null,
|
|
214
235
|
verified_at: account.lv,
|
|
215
236
|
latest_verified_at: account.lv,
|
|
216
|
-
} satisfies
|
|
237
|
+
} satisfies LinkedAccountLinkedInOAuth;
|
|
217
238
|
}
|
|
218
239
|
if (account.type === 'apple_oauth') {
|
|
219
240
|
return {
|
|
@@ -223,7 +244,7 @@ function mapIdLinkedAccountToUserLinkedAccount(account: any): LinkedAccount | nu
|
|
|
223
244
|
first_verified_at: null,
|
|
224
245
|
verified_at: account.lv,
|
|
225
246
|
latest_verified_at: account.lv,
|
|
226
|
-
} satisfies
|
|
247
|
+
} satisfies LinkedAccountAppleOAuth;
|
|
227
248
|
}
|
|
228
249
|
if (account.type === 'cross_app') {
|
|
229
250
|
return {
|
|
@@ -235,7 +256,7 @@ function mapIdLinkedAccountToUserLinkedAccount(account: any): LinkedAccount | nu
|
|
|
235
256
|
first_verified_at: null,
|
|
236
257
|
verified_at: account.lv,
|
|
237
258
|
latest_verified_at: account.lv,
|
|
238
|
-
} satisfies
|
|
259
|
+
} satisfies LinkedAccountCrossApp;
|
|
239
260
|
}
|
|
240
261
|
if (account.type === 'custom_auth') {
|
|
241
262
|
return {
|
|
@@ -244,7 +265,7 @@ function mapIdLinkedAccountToUserLinkedAccount(account: any): LinkedAccount | nu
|
|
|
244
265
|
first_verified_at: null,
|
|
245
266
|
verified_at: account.lv,
|
|
246
267
|
latest_verified_at: account.lv,
|
|
247
|
-
} satisfies
|
|
268
|
+
} satisfies LinkedAccountCustomJwt;
|
|
248
269
|
}
|
|
249
270
|
|
|
250
271
|
if (account.type === 'telegram') {
|
|
@@ -255,8 +276,7 @@ function mapIdLinkedAccountToUserLinkedAccount(account: any): LinkedAccount | nu
|
|
|
255
276
|
first_verified_at: null,
|
|
256
277
|
verified_at: account.lv,
|
|
257
278
|
latest_verified_at: account.lv,
|
|
258
|
-
|
|
259
|
-
} satisfies LinkedAccount.LinkedAccountTelegram;
|
|
279
|
+
} satisfies LinkedAccountTelegram;
|
|
260
280
|
}
|
|
261
281
|
|
|
262
282
|
if (account.type === 'passkey') {
|
|
@@ -267,7 +287,7 @@ function mapIdLinkedAccountToUserLinkedAccount(account: any): LinkedAccount | nu
|
|
|
267
287
|
verified_at: account.lv,
|
|
268
288
|
latest_verified_at: account.lv,
|
|
269
289
|
enrolled_in_mfa: false, // not a part of the identity token
|
|
270
|
-
} satisfies
|
|
290
|
+
} satisfies LinkedAccountPasskey;
|
|
271
291
|
}
|
|
272
292
|
|
|
273
293
|
return null;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { PrivyAPI } from '../../../client';
|
|
2
2
|
import {
|
|
3
3
|
PrivyAppJWKS,
|
|
4
|
-
|
|
4
|
+
verifyAccessToken,
|
|
5
|
+
VerifyAccessTokenResponse,
|
|
5
6
|
VerifyAuthTokenResponse,
|
|
6
7
|
verifyIdentityToken,
|
|
7
8
|
} from '../../../lib/auth';
|
|
@@ -17,20 +18,32 @@ export class PrivyAuthUtils {
|
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
|
-
* Verifies the
|
|
21
|
+
* Verifies the access token, and returns the payload if it is valid.
|
|
21
22
|
*
|
|
22
|
-
* @param
|
|
23
|
+
* @param accessToken - The access token to verify.
|
|
23
24
|
* @returns The payload of the token if it is valid.
|
|
24
25
|
* @throws If the token is invalid.
|
|
25
26
|
*/
|
|
26
|
-
public async
|
|
27
|
-
return
|
|
28
|
-
|
|
27
|
+
public async verifyAccessToken(accessToken: string): Promise<VerifyAccessTokenResponse> {
|
|
28
|
+
return verifyAccessToken({
|
|
29
|
+
access_token: accessToken,
|
|
29
30
|
app_id: this.privyAppID,
|
|
30
31
|
verification_key: this.appJwks,
|
|
31
32
|
});
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Verifies the authentication token, and returns the payload if it is valid.
|
|
37
|
+
*
|
|
38
|
+
* @param authToken - The authentication token to verify.
|
|
39
|
+
* @returns The payload of the token if it is valid.
|
|
40
|
+
* @throws If the token is invalid.
|
|
41
|
+
* @deprecated Use `verifyAccessToken` instead.
|
|
42
|
+
*/
|
|
43
|
+
public async verifyAuthToken(authToken: string): Promise<VerifyAuthTokenResponse> {
|
|
44
|
+
return this.verifyAccessToken(authToken);
|
|
45
|
+
}
|
|
46
|
+
|
|
34
47
|
public async verifyIdentityToken(identityToken: string): Promise<User> {
|
|
35
48
|
return verifyIdentityToken({
|
|
36
49
|
identity_token: identityToken,
|
package/src/resources/apps.ts
CHANGED
|
@@ -85,6 +85,8 @@ export interface AppResponse {
|
|
|
85
85
|
|
|
86
86
|
show_wallet_login_first: boolean;
|
|
87
87
|
|
|
88
|
+
smart_wallet_config: AppResponse.Enabled | AppResponse.UnionMember1;
|
|
89
|
+
|
|
88
90
|
sms_auth: boolean;
|
|
89
91
|
|
|
90
92
|
solana_wallet_auth: boolean;
|
|
@@ -171,6 +173,48 @@ export namespace AppResponse {
|
|
|
171
173
|
}
|
|
172
174
|
}
|
|
173
175
|
|
|
176
|
+
export interface Enabled {
|
|
177
|
+
enabled: false;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export interface UnionMember1 {
|
|
181
|
+
configured_networks: Array<UnionMember1.ConfiguredNetwork>;
|
|
182
|
+
|
|
183
|
+
enabled: true;
|
|
184
|
+
|
|
185
|
+
smart_wallet_type:
|
|
186
|
+
| 'safe'
|
|
187
|
+
| 'kernel'
|
|
188
|
+
| 'light_account'
|
|
189
|
+
| 'biconomy'
|
|
190
|
+
| 'coinbase_smart_wallet'
|
|
191
|
+
| 'thirdweb';
|
|
192
|
+
|
|
193
|
+
smart_wallet_version?: string;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export namespace UnionMember1 {
|
|
197
|
+
export interface ConfiguredNetwork {
|
|
198
|
+
bundler_url: string;
|
|
199
|
+
|
|
200
|
+
chain_id: string;
|
|
201
|
+
|
|
202
|
+
chain_name?: string;
|
|
203
|
+
|
|
204
|
+
paymaster_context?: ConfiguredNetwork.PaymasterContext;
|
|
205
|
+
|
|
206
|
+
paymaster_url?: string;
|
|
207
|
+
|
|
208
|
+
rpc_url?: string;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export namespace ConfiguredNetwork {
|
|
212
|
+
export interface PaymasterContext {
|
|
213
|
+
policy_id: string;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
174
218
|
export interface FundingConfig {
|
|
175
219
|
cross_chain_bridging_enabled: boolean;
|
|
176
220
|
|