@privy-io/node 0.6.2 → 0.8.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.
Files changed (134) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/client.d.mts +10 -7
  3. package/client.d.mts.map +1 -1
  4. package/client.d.ts +10 -7
  5. package/client.d.ts.map +1 -1
  6. package/client.js +3 -0
  7. package/client.js.map +1 -1
  8. package/client.mjs +3 -0
  9. package/client.mjs.map +1 -1
  10. package/index.d.mts +2 -1
  11. package/index.d.mts.map +1 -1
  12. package/index.d.ts +2 -1
  13. package/index.d.ts.map +1 -1
  14. package/index.js +4 -1
  15. package/index.js.map +1 -1
  16. package/index.mjs +2 -1
  17. package/index.mjs.map +1 -1
  18. package/lib/auth.d.mts +30 -2
  19. package/lib/auth.d.mts.map +1 -1
  20. package/lib/auth.d.ts +30 -2
  21. package/lib/auth.d.ts.map +1 -1
  22. package/lib/auth.js +14 -5
  23. package/lib/auth.js.map +1 -1
  24. package/lib/auth.mjs +11 -3
  25. package/lib/auth.mjs.map +1 -1
  26. package/lib/cryptography.d.mts +35 -3
  27. package/lib/cryptography.d.mts.map +1 -1
  28. package/lib/cryptography.d.ts +35 -3
  29. package/lib/cryptography.d.ts.map +1 -1
  30. package/lib/cryptography.js +53 -6
  31. package/lib/cryptography.js.map +1 -1
  32. package/lib/cryptography.mjs +50 -3
  33. package/lib/cryptography.mjs.map +1 -1
  34. package/lib/identity-token.d.mts.map +1 -1
  35. package/lib/identity-token.d.ts.map +1 -1
  36. package/lib/identity-token.js +0 -1
  37. package/lib/identity-token.js.map +1 -1
  38. package/lib/identity-token.mjs +0 -1
  39. package/lib/identity-token.mjs.map +1 -1
  40. package/package.json +13 -1
  41. package/public-api/services/utils/auth.d.mts +10 -1
  42. package/public-api/services/utils/auth.d.mts.map +1 -1
  43. package/public-api/services/utils/auth.d.ts +10 -1
  44. package/public-api/services/utils/auth.d.ts.map +1 -1
  45. package/public-api/services/utils/auth.js +16 -5
  46. package/public-api/services/utils/auth.js.map +1 -1
  47. package/public-api/services/utils/auth.mjs +17 -6
  48. package/public-api/services/utils/auth.mjs.map +1 -1
  49. package/resources/aggregations.d.mts +296 -0
  50. package/resources/aggregations.d.mts.map +1 -0
  51. package/resources/aggregations.d.ts +296 -0
  52. package/resources/aggregations.d.ts.map +1 -0
  53. package/resources/aggregations.js +9 -0
  54. package/resources/aggregations.js.map +1 -0
  55. package/resources/aggregations.mjs +5 -0
  56. package/resources/aggregations.mjs.map +1 -0
  57. package/resources/apps.d.mts +25 -0
  58. package/resources/apps.d.mts.map +1 -1
  59. package/resources/apps.d.ts +25 -0
  60. package/resources/apps.d.ts.map +1 -1
  61. package/resources/index.d.mts +4 -3
  62. package/resources/index.d.mts.map +1 -1
  63. package/resources/index.d.ts +4 -3
  64. package/resources/index.d.ts.map +1 -1
  65. package/resources/index.js +3 -1
  66. package/resources/index.js.map +1 -1
  67. package/resources/index.mjs +1 -0
  68. package/resources/index.mjs.map +1 -1
  69. package/resources/key-quorums.d.mts +4 -1
  70. package/resources/key-quorums.d.mts.map +1 -1
  71. package/resources/key-quorums.d.ts +4 -1
  72. package/resources/key-quorums.d.ts.map +1 -1
  73. package/resources/policies.d.mts +87 -131
  74. package/resources/policies.d.mts.map +1 -1
  75. package/resources/policies.d.ts +87 -131
  76. package/resources/policies.d.ts.map +1 -1
  77. package/resources/policies.js.map +1 -1
  78. package/resources/policies.mjs.map +1 -1
  79. package/resources/users.d.mts +642 -381
  80. package/resources/users.d.mts.map +1 -1
  81. package/resources/users.d.ts +642 -381
  82. package/resources/users.d.ts.map +1 -1
  83. package/resources/wallets/balance.d.mts +3 -3
  84. package/resources/wallets/balance.d.mts.map +1 -1
  85. package/resources/wallets/balance.d.ts +3 -3
  86. package/resources/wallets/balance.d.ts.map +1 -1
  87. package/resources/wallets/index.d.mts +1 -1
  88. package/resources/wallets/index.d.mts.map +1 -1
  89. package/resources/wallets/index.d.ts +1 -1
  90. package/resources/wallets/index.d.ts.map +1 -1
  91. package/resources/wallets/index.js.map +1 -1
  92. package/resources/wallets/index.mjs.map +1 -1
  93. package/resources/wallets/transactions.d.mts +3 -3
  94. package/resources/wallets/transactions.d.mts.map +1 -1
  95. package/resources/wallets/transactions.d.ts +3 -3
  96. package/resources/wallets/transactions.d.ts.map +1 -1
  97. package/resources/wallets/wallets.d.mts +215 -53
  98. package/resources/wallets/wallets.d.mts.map +1 -1
  99. package/resources/wallets/wallets.d.ts +215 -53
  100. package/resources/wallets/wallets.d.ts.map +1 -1
  101. package/resources/wallets/wallets.js +1 -1
  102. package/resources/wallets/wallets.js.map +1 -1
  103. package/resources/wallets/wallets.mjs +1 -1
  104. package/resources/wallets/wallets.mjs.map +1 -1
  105. package/solana-kit.d.mts +53 -0
  106. package/solana-kit.d.mts.map +1 -0
  107. package/solana-kit.d.ts +53 -0
  108. package/solana-kit.d.ts.map +1 -0
  109. package/solana-kit.js +92 -0
  110. package/solana-kit.js.map +1 -0
  111. package/solana-kit.mjs +89 -0
  112. package/solana-kit.mjs.map +1 -0
  113. package/src/client.ts +150 -3
  114. package/src/index.ts +5 -0
  115. package/src/lib/auth.ts +42 -6
  116. package/src/lib/cryptography.ts +72 -3
  117. package/src/lib/identity-token.ts +38 -18
  118. package/src/public-api/services/utils/auth.ts +19 -6
  119. package/src/resources/aggregations.ts +497 -0
  120. package/src/resources/apps.ts +44 -0
  121. package/src/resources/index.ts +74 -2
  122. package/src/resources/key-quorums.ts +4 -1
  123. package/src/resources/policies.ts +124 -207
  124. package/src/resources/users.ts +942 -625
  125. package/src/resources/wallets/balance.ts +11 -3
  126. package/src/resources/wallets/index.ts +6 -0
  127. package/src/resources/wallets/transactions.ts +11 -3
  128. package/src/resources/wallets/wallets.ts +283 -52
  129. package/src/solana-kit.ts +148 -0
  130. package/src/version.ts +1 -1
  131. package/version.d.mts +1 -1
  132. package/version.d.ts +1 -1
  133. package/version.js +1 -1
  134. package/version.mjs +1 -1
package/src/client.ts CHANGED
@@ -19,6 +19,14 @@ import { AbstractPage, type CursorParams, CursorResponse } from './core/paginati
19
19
  import * as Uploads from './core/uploads';
20
20
  import * as API from './resources/index';
21
21
  import { APIPromise } from './core/api-promise';
22
+ import {
23
+ Aggregation,
24
+ AggregationGroupBy,
25
+ AggregationMethod,
26
+ AggregationMetric,
27
+ AggregationWindow,
28
+ Aggregations,
29
+ } from './resources/aggregations';
22
30
  import { Analytics, AnalyticsEventInput } from './resources/analytics';
23
31
  import { AppResponse, Apps } from './resources/apps';
24
32
  import {
@@ -51,21 +59,78 @@ import {
51
59
  PolicyUpdateParams,
52
60
  PolicyUpdateRuleParams,
53
61
  PolicyUpdateRuleResponse,
62
+ SuiTransactionCommandCondition,
63
+ SuiTransactionCommandOperator,
64
+ SuiTransferObjectsCommandCondition,
65
+ SuiTransferObjectsCommandField,
66
+ TronTransactionCondition,
54
67
  } from './resources/policies';
55
68
  import { TransactionGetResponse, Transactions } from './resources/transactions';
56
69
  import {
57
70
  AuthenticatedUser,
71
+ CrossAppEmbeddedWallet,
72
+ CrossAppSmartWallet,
73
+ CustomMetadata,
74
+ EmbeddedWalletRecoveryMethod,
58
75
  LinkedAccount,
76
+ LinkedAccountAppleInput,
77
+ LinkedAccountAppleOAuth,
78
+ LinkedAccountAuthorizationKey,
79
+ LinkedAccountBaseWallet,
59
80
  LinkedAccountBitcoinSegwitEmbeddedWallet,
60
81
  LinkedAccountBitcoinTaprootEmbeddedWallet,
82
+ LinkedAccountCrossApp,
61
83
  LinkedAccountCurveSigningEmbeddedWallet,
84
+ LinkedAccountCustomJwt,
85
+ LinkedAccountCustomJwtInput,
86
+ LinkedAccountCustomOAuth,
87
+ LinkedAccountDiscordInput,
88
+ LinkedAccountDiscordOAuth,
89
+ LinkedAccountEmail,
90
+ LinkedAccountEmailInput,
62
91
  LinkedAccountEmbeddedWallet,
63
92
  LinkedAccountEmbeddedWalletWithID,
93
+ LinkedAccountEthereum,
64
94
  LinkedAccountEthereumEmbeddedWallet,
95
+ LinkedAccountFarcaster,
96
+ LinkedAccountFarcasterInput,
97
+ LinkedAccountGitHubInput,
98
+ LinkedAccountGitHubOAuth,
99
+ LinkedAccountGoogleInput,
100
+ LinkedAccountGoogleOAuth,
101
+ LinkedAccountInput,
102
+ LinkedAccountInstagramInput,
103
+ LinkedAccountInstagramOAuth,
104
+ LinkedAccountLineInput,
105
+ LinkedAccountLineOAuth,
106
+ LinkedAccountLinkedInInput,
107
+ LinkedAccountLinkedInOAuth,
108
+ LinkedAccountPasskey,
109
+ LinkedAccountPhone,
110
+ LinkedAccountPhoneInput,
65
111
  LinkedAccountSmartWallet,
112
+ LinkedAccountSolana,
66
113
  LinkedAccountSolanaEmbeddedWallet,
114
+ LinkedAccountSpotifyInput,
115
+ LinkedAccountSpotifyOAuth,
116
+ LinkedAccountTelegram,
117
+ LinkedAccountTelegramInput,
118
+ LinkedAccountTiktokInput,
119
+ LinkedAccountTiktokOAuth,
120
+ LinkedAccountTwitchInput,
121
+ LinkedAccountTwitchOAuth,
122
+ LinkedAccountTwitterInput,
123
+ LinkedAccountTwitterOAuth,
124
+ LinkedAccountType,
125
+ LinkedAccountWalletInput,
126
+ LinkedMfaMethod,
127
+ OAuthTokens,
128
+ PasskeyMfaMethod,
129
+ SMSMfaMethod,
67
130
  SmartWalletType,
131
+ TotpMfaMethod,
68
132
  User,
133
+ UserBatchCreateInput,
69
134
  UserCreateParams,
70
135
  UserGetByCustomAuthIDParams,
71
136
  UserGetByDiscordUsernameParams,
@@ -84,11 +149,16 @@ import {
84
149
  UserSearchParams,
85
150
  UserSetCustomMetadataParams,
86
151
  UserUnlinkLinkedAccountParams,
152
+ UserWithIdentityToken,
87
153
  Users,
88
154
  UsersCursor,
89
155
  } from './resources/users';
90
156
  import {
91
157
  CurveSigningChainType,
158
+ CustodialWallet,
159
+ CustodialWalletChainType,
160
+ CustodialWalletCreateInput,
161
+ CustodialWalletProvider,
92
162
  EthereumPersonalSignRpcInput,
93
163
  EthereumPersonalSignRpcResponse,
94
164
  EthereumSecp256k1SignRpcInput,
@@ -105,12 +175,14 @@ import {
105
175
  EthereumSignUserOperationRpcResponse,
106
176
  ExtendedChainType,
107
177
  FirstClassChainType,
178
+ HpkeImportConfig,
108
179
  SolanaSignAndSendTransactionRpcInput,
109
180
  SolanaSignAndSendTransactionRpcResponse,
110
181
  SolanaSignMessageRpcInput,
111
182
  SolanaSignMessageRpcResponse,
112
183
  SolanaSignTransactionRpcInput,
113
184
  SolanaSignTransactionRpcResponse,
185
+ SuiCommandName,
114
186
  Wallet,
115
187
  WalletAuthenticateWithJwtParams,
116
188
  WalletAuthenticateWithJwtResponse,
@@ -253,7 +325,7 @@ export class PrivyAPI {
253
325
  baseURL: string;
254
326
  maxRetries: number;
255
327
  timeout: number;
256
- logger: Logger | undefined;
328
+ logger: Logger;
257
329
  logLevel: LogLevel | undefined;
258
330
  fetchOptions: MergedRequestInit | undefined;
259
331
 
@@ -900,6 +972,7 @@ export class PrivyAPI {
900
972
  clientAuth: API.ClientAuth = new API.ClientAuth(this);
901
973
  analytics: API.Analytics = new API.Analytics(this);
902
974
  apps: API.Apps = new API.Apps(this);
975
+ aggregations: API.Aggregations = new API.Aggregations(this);
903
976
  }
904
977
 
905
978
  PrivyAPI.Wallets = Wallets;
@@ -910,6 +983,7 @@ PrivyAPI.KeyQuorums = KeyQuorums;
910
983
  PrivyAPI.ClientAuth = ClientAuth;
911
984
  PrivyAPI.Analytics = Analytics;
912
985
  PrivyAPI.Apps = Apps;
986
+ PrivyAPI.Aggregations = Aggregations;
913
987
 
914
988
  export declare namespace PrivyAPI {
915
989
  export type RequestOptions = Opts.RequestOptions;
@@ -925,6 +999,12 @@ export declare namespace PrivyAPI {
925
999
  type WalletChainType as WalletChainType,
926
1000
  type ExtendedChainType as ExtendedChainType,
927
1001
  type WalletCustodian as WalletCustodian,
1002
+ type CustodialWalletProvider as CustodialWalletProvider,
1003
+ type CustodialWalletChainType as CustodialWalletChainType,
1004
+ type CustodialWalletCreateInput as CustodialWalletCreateInput,
1005
+ type CustodialWallet as CustodialWallet,
1006
+ type HpkeImportConfig as HpkeImportConfig,
1007
+ type SuiCommandName as SuiCommandName,
928
1008
  type EthereumPersonalSignRpcInput as EthereumPersonalSignRpcInput,
929
1009
  type EthereumSignTransactionRpcInput as EthereumSignTransactionRpcInput,
930
1010
  type EthereumSendTransactionRpcInput as EthereumSendTransactionRpcInput,
@@ -969,6 +1049,17 @@ export declare namespace PrivyAPI {
969
1049
  type AuthenticatedUser as AuthenticatedUser,
970
1050
  type LinkedAccount as LinkedAccount,
971
1051
  type User as User,
1052
+ type LinkedAccountEmail as LinkedAccountEmail,
1053
+ type LinkedAccountPhone as LinkedAccountPhone,
1054
+ type LinkedAccountBaseWallet as LinkedAccountBaseWallet,
1055
+ type LinkedAccountEthereum as LinkedAccountEthereum,
1056
+ type SmartWalletType as SmartWalletType,
1057
+ type LinkedAccountSmartWallet as LinkedAccountSmartWallet,
1058
+ type LinkedAccountSolana as LinkedAccountSolana,
1059
+ type LinkedAccountFarcaster as LinkedAccountFarcaster,
1060
+ type LinkedAccountPasskey as LinkedAccountPasskey,
1061
+ type LinkedAccountTelegram as LinkedAccountTelegram,
1062
+ type EmbeddedWalletRecoveryMethod as EmbeddedWalletRecoveryMethod,
972
1063
  type LinkedAccountEthereumEmbeddedWallet as LinkedAccountEthereumEmbeddedWallet,
973
1064
  type LinkedAccountSolanaEmbeddedWallet as LinkedAccountSolanaEmbeddedWallet,
974
1065
  type LinkedAccountBitcoinSegwitEmbeddedWallet as LinkedAccountBitcoinSegwitEmbeddedWallet,
@@ -976,8 +1067,50 @@ export declare namespace PrivyAPI {
976
1067
  type LinkedAccountCurveSigningEmbeddedWallet as LinkedAccountCurveSigningEmbeddedWallet,
977
1068
  type LinkedAccountEmbeddedWallet as LinkedAccountEmbeddedWallet,
978
1069
  type LinkedAccountEmbeddedWalletWithID as LinkedAccountEmbeddedWalletWithID,
979
- type SmartWalletType as SmartWalletType,
980
- type LinkedAccountSmartWallet as LinkedAccountSmartWallet,
1070
+ type LinkedAccountGoogleOAuth as LinkedAccountGoogleOAuth,
1071
+ type LinkedAccountTwitterOAuth as LinkedAccountTwitterOAuth,
1072
+ type LinkedAccountDiscordOAuth as LinkedAccountDiscordOAuth,
1073
+ type LinkedAccountGitHubOAuth as LinkedAccountGitHubOAuth,
1074
+ type LinkedAccountLinkedInOAuth as LinkedAccountLinkedInOAuth,
1075
+ type LinkedAccountSpotifyOAuth as LinkedAccountSpotifyOAuth,
1076
+ type LinkedAccountInstagramOAuth as LinkedAccountInstagramOAuth,
1077
+ type LinkedAccountTiktokOAuth as LinkedAccountTiktokOAuth,
1078
+ type LinkedAccountLineOAuth as LinkedAccountLineOAuth,
1079
+ type LinkedAccountTwitchOAuth as LinkedAccountTwitchOAuth,
1080
+ type LinkedAccountAppleOAuth as LinkedAccountAppleOAuth,
1081
+ type LinkedAccountCustomOAuth as LinkedAccountCustomOAuth,
1082
+ type LinkedAccountCustomJwt as LinkedAccountCustomJwt,
1083
+ type CrossAppEmbeddedWallet as CrossAppEmbeddedWallet,
1084
+ type CrossAppSmartWallet as CrossAppSmartWallet,
1085
+ type LinkedAccountCrossApp as LinkedAccountCrossApp,
1086
+ type LinkedAccountAuthorizationKey as LinkedAccountAuthorizationKey,
1087
+ type LinkedAccountType as LinkedAccountType,
1088
+ type CustomMetadata as CustomMetadata,
1089
+ type LinkedAccountWalletInput as LinkedAccountWalletInput,
1090
+ type LinkedAccountEmailInput as LinkedAccountEmailInput,
1091
+ type LinkedAccountPhoneInput as LinkedAccountPhoneInput,
1092
+ type LinkedAccountGoogleInput as LinkedAccountGoogleInput,
1093
+ type LinkedAccountTwitterInput as LinkedAccountTwitterInput,
1094
+ type LinkedAccountDiscordInput as LinkedAccountDiscordInput,
1095
+ type LinkedAccountGitHubInput as LinkedAccountGitHubInput,
1096
+ type LinkedAccountSpotifyInput as LinkedAccountSpotifyInput,
1097
+ type LinkedAccountInstagramInput as LinkedAccountInstagramInput,
1098
+ type LinkedAccountTiktokInput as LinkedAccountTiktokInput,
1099
+ type LinkedAccountLineInput as LinkedAccountLineInput,
1100
+ type LinkedAccountTwitchInput as LinkedAccountTwitchInput,
1101
+ type LinkedAccountAppleInput as LinkedAccountAppleInput,
1102
+ type LinkedAccountLinkedInInput as LinkedAccountLinkedInInput,
1103
+ type LinkedAccountFarcasterInput as LinkedAccountFarcasterInput,
1104
+ type LinkedAccountTelegramInput as LinkedAccountTelegramInput,
1105
+ type LinkedAccountCustomJwtInput as LinkedAccountCustomJwtInput,
1106
+ type LinkedAccountInput as LinkedAccountInput,
1107
+ type UserBatchCreateInput as UserBatchCreateInput,
1108
+ type SMSMfaMethod as SMSMfaMethod,
1109
+ type TotpMfaMethod as TotpMfaMethod,
1110
+ type PasskeyMfaMethod as PasskeyMfaMethod,
1111
+ type LinkedMfaMethod as LinkedMfaMethod,
1112
+ type OAuthTokens as OAuthTokens,
1113
+ type UserWithIdentityToken as UserWithIdentityToken,
981
1114
  type UsersCursor as UsersCursor,
982
1115
  type UserCreateParams as UserCreateParams,
983
1116
  type UserListParams as UserListParams,
@@ -1002,6 +1135,11 @@ export declare namespace PrivyAPI {
1002
1135
  export {
1003
1136
  Policies as Policies,
1004
1137
  type Policy as Policy,
1138
+ type SuiTransactionCommandOperator as SuiTransactionCommandOperator,
1139
+ type SuiTransferObjectsCommandField as SuiTransferObjectsCommandField,
1140
+ type TronTransactionCondition as TronTransactionCondition,
1141
+ type SuiTransactionCommandCondition as SuiTransactionCommandCondition,
1142
+ type SuiTransferObjectsCommandCondition as SuiTransferObjectsCommandCondition,
1005
1143
  type PolicyCreateRuleResponse as PolicyCreateRuleResponse,
1006
1144
  type PolicyDeleteResponse as PolicyDeleteResponse,
1007
1145
  type PolicyDeleteRuleResponse as PolicyDeleteRuleResponse,
@@ -1038,4 +1176,13 @@ export declare namespace PrivyAPI {
1038
1176
  export { Analytics as Analytics, type AnalyticsEventInput as AnalyticsEventInput };
1039
1177
 
1040
1178
  export { Apps as Apps, type AppResponse as AppResponse };
1179
+
1180
+ export {
1181
+ Aggregations as Aggregations,
1182
+ type AggregationMethod as AggregationMethod,
1183
+ type AggregationMetric as AggregationMetric,
1184
+ type AggregationWindow as AggregationWindow,
1185
+ type AggregationGroupBy as AggregationGroupBy,
1186
+ type Aggregation as Aggregation,
1187
+ };
1041
1188
  }
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 VerifyAuthTokenResponse = {
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 authentication token.
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 verifyAuthToken({
85
- auth_token: authToken,
106
+ export async function verifyAccessToken({
107
+ access_token: accessToken,
86
108
  app_id: appId,
87
109
  verification_key: verificationKeyOrString,
88
- }: VerifyAuthTokenInput): Promise<VerifyAuthTokenResponse> {
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(authToken, appId, verificationKey);
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;
@@ -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 publicKeySpki = await crypto.subtle.exportKey('spki', keypair.publicKey);
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
- export const WALLET_API_PRIVATE_KEY_PREFIX = 'wallet-api:';
117
- export const AUTHORIZATION_PRIVATE_KEY_PREFIX = 'wallet-auth:';
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 { User, LinkedAccount, LinkedAccountSmartWallet, LinkedAccountEmbeddedWallet } from '../resources';
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 LinkedAccount.LinkedAccountEmail;
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 LinkedAccount.LinkedAccountPhone;
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 LinkedAccount.LinkedAccountFarcaster;
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 LinkedAccount.LinkedAccountGoogleOAuth;
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 LinkedAccount.LinkedAccountTwitterOAuth;
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 LinkedAccount.LinkedAccountDiscordOAuth;
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 LinkedAccount.LinkedAccountGitHubOAuth;
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 LinkedAccount.LinkedAccountSpotifyOAuth;
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 LinkedAccount.LinkedAccountInstagramOAuth;
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 LinkedAccount.LinkedAccountTiktokOAuth;
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 LinkedAccount.LinkedAccountLinkedInOAuth;
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 LinkedAccount.LinkedAccountAppleOAuth;
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 LinkedAccount.LinkedAccountCrossApp;
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 LinkedAccount.LinkedAccountCustomJwt;
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
- telegramUserId: account.telegram_user_id,
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 LinkedAccount.LinkedAccountPasskey;
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
- verifyAuthToken,
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 authentication token, and returns the payload if it is valid.
21
+ * Verifies the access token, and returns the payload if it is valid.
21
22
  *
22
- * @param authToken - The authentication token to verify.
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 verifyAuthToken(authToken: string): Promise<VerifyAuthTokenResponse> {
27
- return verifyAuthToken({
28
- auth_token: authToken,
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,