@privy-io/node 0.1.0-alpha.2 → 0.1.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 (164) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/client.d.mts +3 -3
  3. package/client.d.mts.map +1 -1
  4. package/client.d.ts +3 -3
  5. package/client.d.ts.map +1 -1
  6. package/client.js +1 -1
  7. package/client.js.map +1 -1
  8. package/client.mjs +1 -1
  9. package/client.mjs.map +1 -1
  10. package/index.d.mts +6 -0
  11. package/index.d.mts.map +1 -1
  12. package/index.d.ts +6 -0
  13. package/index.d.ts.map +1 -1
  14. package/index.js +7 -1
  15. package/index.js.map +1 -1
  16. package/index.mjs +2 -0
  17. package/index.mjs.map +1 -1
  18. package/internal/utils/values.js +3 -3
  19. package/internal/utils/values.js.map +1 -1
  20. package/internal/utils/values.mjs +3 -3
  21. package/internal/utils/values.mjs.map +1 -1
  22. package/lib/auth.d.mts +68 -0
  23. package/lib/auth.d.mts.map +1 -0
  24. package/lib/auth.d.ts +68 -0
  25. package/lib/auth.d.ts.map +1 -0
  26. package/lib/auth.js +130 -0
  27. package/lib/auth.js.map +1 -0
  28. package/lib/auth.mjs +123 -0
  29. package/lib/auth.mjs.map +1 -0
  30. package/lib/identity-token.d.mts +15 -0
  31. package/lib/identity-token.d.mts.map +1 -0
  32. package/lib/identity-token.d.ts +15 -0
  33. package/lib/identity-token.d.ts.map +1 -0
  34. package/lib/identity-token.js +273 -0
  35. package/lib/identity-token.js.map +1 -0
  36. package/lib/identity-token.mjs +268 -0
  37. package/lib/identity-token.mjs.map +1 -0
  38. package/lib/user-utils.d.mts +22 -0
  39. package/lib/user-utils.d.mts.map +1 -0
  40. package/lib/user-utils.d.ts +22 -0
  41. package/lib/user-utils.d.ts.map +1 -0
  42. package/lib/user-utils.js +15 -0
  43. package/lib/user-utils.js.map +1 -0
  44. package/lib/user-utils.mjs +11 -0
  45. package/lib/user-utils.mjs.map +1 -0
  46. package/package.json +19 -1
  47. package/public-api/PrivyClient.d.mts +2 -1
  48. package/public-api/PrivyClient.d.mts.map +1 -1
  49. package/public-api/PrivyClient.d.ts +2 -1
  50. package/public-api/PrivyClient.d.ts.map +1 -1
  51. package/public-api/PrivyClient.js +10 -3
  52. package/public-api/PrivyClient.js.map +1 -1
  53. package/public-api/PrivyClient.mjs +10 -3
  54. package/public-api/PrivyClient.mjs.map +1 -1
  55. package/public-api/services/ethereum.d.mts.map +1 -1
  56. package/public-api/services/ethereum.d.ts.map +1 -1
  57. package/public-api/services/ethereum.js +0 -6
  58. package/public-api/services/ethereum.js.map +1 -1
  59. package/public-api/services/ethereum.mjs +0 -6
  60. package/public-api/services/ethereum.mjs.map +1 -1
  61. package/public-api/services/solana.d.mts.map +1 -1
  62. package/public-api/services/solana.d.ts.map +1 -1
  63. package/public-api/services/solana.js +0 -3
  64. package/public-api/services/solana.js.map +1 -1
  65. package/public-api/services/solana.mjs +0 -3
  66. package/public-api/services/solana.mjs.map +1 -1
  67. package/public-api/services/users.d.mts +23 -1
  68. package/public-api/services/users.d.mts.map +1 -1
  69. package/public-api/services/users.d.ts +23 -1
  70. package/public-api/services/users.d.ts.map +1 -1
  71. package/public-api/services/users.js +24 -0
  72. package/public-api/services/users.js.map +1 -1
  73. package/public-api/services/users.mjs +24 -0
  74. package/public-api/services/users.mjs.map +1 -1
  75. package/public-api/services/utils/auth.d.mts +18 -0
  76. package/public-api/services/utils/auth.d.mts.map +1 -0
  77. package/public-api/services/utils/auth.d.ts +18 -0
  78. package/public-api/services/utils/auth.d.ts.map +1 -0
  79. package/public-api/services/utils/auth.js +33 -0
  80. package/public-api/services/utils/auth.js.map +1 -0
  81. package/public-api/services/utils/auth.mjs +29 -0
  82. package/public-api/services/utils/auth.mjs.map +1 -0
  83. package/public-api/services/utils/request-formatter.d.mts +5 -0
  84. package/public-api/services/utils/request-formatter.d.mts.map +1 -0
  85. package/public-api/services/utils/request-formatter.d.ts +5 -0
  86. package/public-api/services/utils/request-formatter.d.ts.map +1 -0
  87. package/public-api/services/utils/request-formatter.js +12 -0
  88. package/public-api/services/utils/request-formatter.js.map +1 -0
  89. package/public-api/services/utils/request-formatter.mjs +8 -0
  90. package/public-api/services/utils/request-formatter.mjs.map +1 -0
  91. package/public-api/services/utils/request-signer.d.mts +25 -0
  92. package/public-api/services/utils/request-signer.d.mts.map +1 -0
  93. package/public-api/services/utils/request-signer.d.ts +25 -0
  94. package/public-api/services/utils/request-signer.d.ts.map +1 -0
  95. package/public-api/services/utils/request-signer.js +17 -0
  96. package/public-api/services/utils/request-signer.js.map +1 -0
  97. package/public-api/services/utils/request-signer.mjs +13 -0
  98. package/public-api/services/utils/request-signer.mjs.map +1 -0
  99. package/public-api/services/utils.d.mts +12 -22
  100. package/public-api/services/utils.d.mts.map +1 -1
  101. package/public-api/services/utils.d.ts +12 -22
  102. package/public-api/services/utils.d.ts.map +1 -1
  103. package/public-api/services/utils.js +15 -9
  104. package/public-api/services/utils.js.map +1 -1
  105. package/public-api/services/utils.mjs +16 -10
  106. package/public-api/services/utils.mjs.map +1 -1
  107. package/resources/index.d.mts +1 -1
  108. package/resources/index.d.mts.map +1 -1
  109. package/resources/index.d.ts +1 -1
  110. package/resources/index.d.ts.map +1 -1
  111. package/resources/policies.d.mts +2 -1
  112. package/resources/policies.d.mts.map +1 -1
  113. package/resources/policies.d.ts +2 -1
  114. package/resources/policies.d.ts.map +1 -1
  115. package/resources/users.d.mts +35 -24
  116. package/resources/users.d.mts.map +1 -1
  117. package/resources/users.d.ts +35 -24
  118. package/resources/users.d.ts.map +1 -1
  119. package/resources/users.js +16 -16
  120. package/resources/users.js.map +1 -1
  121. package/resources/users.mjs +16 -16
  122. package/resources/users.mjs.map +1 -1
  123. package/resources/wallets/wallets.d.mts +3 -18
  124. package/resources/wallets/wallets.d.mts.map +1 -1
  125. package/resources/wallets/wallets.d.ts +3 -18
  126. package/resources/wallets/wallets.d.ts.map +1 -1
  127. package/resources/wallets/wallets.js.map +1 -1
  128. package/resources/wallets/wallets.mjs.map +1 -1
  129. package/src/client.ts +4 -4
  130. package/src/index.ts +15 -0
  131. package/src/internal/utils/values.ts +3 -3
  132. package/src/lib/auth.ts +210 -0
  133. package/src/lib/identity-token.ts +280 -0
  134. package/src/lib/user-utils.ts +31 -0
  135. package/src/public-api/PrivyClient.ts +12 -2
  136. package/src/public-api/services/ethereum.ts +0 -8
  137. package/src/public-api/services/solana.ts +0 -4
  138. package/src/public-api/services/users.ts +36 -2
  139. package/src/public-api/services/utils/auth.ts +41 -0
  140. package/src/public-api/services/utils/request-formatter.ts +6 -0
  141. package/src/public-api/services/utils/request-signer.ts +35 -0
  142. package/src/public-api/services/utils.ts +21 -31
  143. package/src/resources/index.ts +1 -1
  144. package/src/resources/policies.ts +2 -1
  145. package/src/resources/users.ts +50 -29
  146. package/src/resources/wallets/wallets.ts +6 -30
  147. package/src/version.ts +1 -1
  148. package/src/viem.ts +223 -0
  149. package/version.d.mts +1 -1
  150. package/version.d.mts.map +1 -1
  151. package/version.d.ts +1 -1
  152. package/version.d.ts.map +1 -1
  153. package/version.js +1 -1
  154. package/version.js.map +1 -1
  155. package/version.mjs +1 -1
  156. package/version.mjs.map +1 -1
  157. package/viem.d.mts +22 -0
  158. package/viem.d.mts.map +1 -0
  159. package/viem.d.ts +22 -0
  160. package/viem.d.ts.map +1 -0
  161. package/viem.js +183 -0
  162. package/viem.js.map +1 -0
  163. package/viem.mjs +180 -0
  164. package/viem.mjs.map +1 -0
package/lib/auth.d.mts ADDED
@@ -0,0 +1,68 @@
1
+ import { CryptoKey, JWTVerifyGetKey } from 'jose';
2
+ import { PrivyAPIError } from "../core/error.mjs";
3
+ import { User } from "../resources.mjs";
4
+ export type VerifyAuthTokenInput = {
5
+ /** The authentication token to verify. */
6
+ auth_token: string;
7
+ /** The Privy app ID to verify the token against. */
8
+ app_id: string;
9
+ /**
10
+ * The verification key to use to verify the token, or a mechanism to get the it such as via JWKS.
11
+ * You can find this verification key (or a JWKS endpoint) in the Privy dashboard.
12
+ * @see {@link createRemoteJWKSet}
13
+ * @see {@link importSPKI}
14
+ */
15
+ verification_key: CryptoKey | JWTVerifyGetKey | string;
16
+ };
17
+ export type VerifyAuthTokenResponse = {
18
+ /** The Privy app ID for which the token was issued. */
19
+ app_id: string;
20
+ /** The issuer of the token. */
21
+ issuer: string;
22
+ /** The issued at unix timestamp of the token. */
23
+ issued_at: number;
24
+ /** The expiration unix timestamp of the token. */
25
+ expiration: number;
26
+ /** The ID of the session for which the token was issued. */
27
+ session_id: string;
28
+ /** The ID of the user for which the token was issued. */
29
+ user_id: string;
30
+ };
31
+ /**
32
+ * Verifies a Privy-issued authentication token.
33
+ *
34
+ * @returns The payload of the token if it is valid.
35
+ * @throws If the token is invalid.
36
+ */
37
+ export declare function verifyAuthToken({ auth_token: authToken, app_id: appId, verification_key: verificationKeyOrString, }: VerifyAuthTokenInput): Promise<VerifyAuthTokenResponse>;
38
+ export type VerifyIdentityTokenInput = {
39
+ /** The identity token to verify. */
40
+ identity_token: string;
41
+ /** The Privy app ID to verify the token against. */
42
+ app_id: string;
43
+ /**
44
+ * The verification key to use to verify the token, or a mechanism to get the it such as via JWKS.
45
+ * You can find this verification key (or a JWKS endpoint) in the Privy dashboard.
46
+ * @see {@link createRemoteJWKSet}
47
+ * @see {@link importSPKI}
48
+ */
49
+ verification_key: CryptoKey | JWTVerifyGetKey | string;
50
+ };
51
+ /**
52
+ * Verifies an identity token, parsing it into a `User` object if it is valid.
53
+ *
54
+ * @returns The user object parsed from the identity token.
55
+ * @throws If the token or its payload is invalid.
56
+ */
57
+ export declare function verifyIdentityToken({ identity_token: identityToken, app_id: appId, verification_key: verificationKeyOrString, }: VerifyIdentityTokenInput): Promise<User>;
58
+ export declare class InvalidAuthTokenError extends PrivyAPIError {
59
+ }
60
+ export interface CreatePrivyAppJWKSInput {
61
+ appId: string;
62
+ apiUrl: string;
63
+ headers: Record<string, string>;
64
+ verificationKeyOverride?: string | undefined;
65
+ }
66
+ export type PrivyAppJWKS = JWTVerifyGetKey;
67
+ export declare function createPrivyAppJWKS({ appId, apiUrl, headers, verificationKeyOverride, }: CreatePrivyAppJWKSInput): PrivyAppJWKS;
68
+ //# sourceMappingURL=auth.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.mts","sourceRoot":"","sources":["../src/lib/auth.ts"],"names":[],"mappings":"OAAO,EAEL,SAAS,EAIT,eAAe,EAEhB,MAAM,MAAM;OACN,EAAE,aAAa,EAAE;OAEjB,EAAE,IAAI,EAAE;AAKf,MAAM,MAAM,oBAAoB,GAAG;IACjC,0CAA0C;IAC1C,UAAU,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,gBAAgB,EAAE,SAAS,GAAG,eAAe,GAAG,MAAM,CAAC;CACxD,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,uDAAuD;IACvD,MAAM,EAAE,MAAM,CAAC;IACf,+BAA+B;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,iDAAiD;IACjD,SAAS,EAAE,MAAM,CAAC;IAClB,kDAAkD;IAClD,UAAU,EAAE,MAAM,CAAC;IACnB,4DAA4D;IAC5D,UAAU,EAAE,MAAM,CAAC;IACnB,yDAAyD;IACzD,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAkCF;;;;;GAKG;AACH,wBAAsB,eAAe,CAAC,EACpC,UAAU,EAAE,SAAS,EACrB,MAAM,EAAE,KAAK,EACb,gBAAgB,EAAE,uBAAuB,GAC1C,EAAE,oBAAoB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAczD;AAED,MAAM,MAAM,wBAAwB,GAAG;IACrC,oCAAoC;IACpC,cAAc,EAAE,MAAM,CAAC;IACvB,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,gBAAgB,EAAE,SAAS,GAAG,eAAe,GAAG,MAAM,CAAC;CACxD,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,mBAAmB,CAAC,EACxC,cAAc,EAAE,aAAa,EAC7B,MAAM,EAAE,KAAK,EACb,gBAAgB,EAAE,uBAAuB,GAC1C,EAAE,wBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC,CAY1C;AAED,qBAAa,qBAAsB,SAAQ,aAAa;CAAG;AAgC3D,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,uBAAuB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC9C;AAED,MAAM,MAAM,YAAY,GAAG,eAAe,CAAC;AAE3C,wBAAgB,kBAAkB,CAAC,EACjC,KAAK,EACL,MAAM,EACN,OAAO,EACP,uBAAuB,GACxB,EAAE,uBAAuB,GAAG,YAAY,CAsBxC"}
package/lib/auth.d.ts ADDED
@@ -0,0 +1,68 @@
1
+ import { CryptoKey, JWTVerifyGetKey } from 'jose';
2
+ import { PrivyAPIError } from "../core/error.js";
3
+ import { User } from "../resources.js";
4
+ export type VerifyAuthTokenInput = {
5
+ /** The authentication token to verify. */
6
+ auth_token: string;
7
+ /** The Privy app ID to verify the token against. */
8
+ app_id: string;
9
+ /**
10
+ * The verification key to use to verify the token, or a mechanism to get the it such as via JWKS.
11
+ * You can find this verification key (or a JWKS endpoint) in the Privy dashboard.
12
+ * @see {@link createRemoteJWKSet}
13
+ * @see {@link importSPKI}
14
+ */
15
+ verification_key: CryptoKey | JWTVerifyGetKey | string;
16
+ };
17
+ export type VerifyAuthTokenResponse = {
18
+ /** The Privy app ID for which the token was issued. */
19
+ app_id: string;
20
+ /** The issuer of the token. */
21
+ issuer: string;
22
+ /** The issued at unix timestamp of the token. */
23
+ issued_at: number;
24
+ /** The expiration unix timestamp of the token. */
25
+ expiration: number;
26
+ /** The ID of the session for which the token was issued. */
27
+ session_id: string;
28
+ /** The ID of the user for which the token was issued. */
29
+ user_id: string;
30
+ };
31
+ /**
32
+ * Verifies a Privy-issued authentication token.
33
+ *
34
+ * @returns The payload of the token if it is valid.
35
+ * @throws If the token is invalid.
36
+ */
37
+ export declare function verifyAuthToken({ auth_token: authToken, app_id: appId, verification_key: verificationKeyOrString, }: VerifyAuthTokenInput): Promise<VerifyAuthTokenResponse>;
38
+ export type VerifyIdentityTokenInput = {
39
+ /** The identity token to verify. */
40
+ identity_token: string;
41
+ /** The Privy app ID to verify the token against. */
42
+ app_id: string;
43
+ /**
44
+ * The verification key to use to verify the token, or a mechanism to get the it such as via JWKS.
45
+ * You can find this verification key (or a JWKS endpoint) in the Privy dashboard.
46
+ * @see {@link createRemoteJWKSet}
47
+ * @see {@link importSPKI}
48
+ */
49
+ verification_key: CryptoKey | JWTVerifyGetKey | string;
50
+ };
51
+ /**
52
+ * Verifies an identity token, parsing it into a `User` object if it is valid.
53
+ *
54
+ * @returns The user object parsed from the identity token.
55
+ * @throws If the token or its payload is invalid.
56
+ */
57
+ export declare function verifyIdentityToken({ identity_token: identityToken, app_id: appId, verification_key: verificationKeyOrString, }: VerifyIdentityTokenInput): Promise<User>;
58
+ export declare class InvalidAuthTokenError extends PrivyAPIError {
59
+ }
60
+ export interface CreatePrivyAppJWKSInput {
61
+ appId: string;
62
+ apiUrl: string;
63
+ headers: Record<string, string>;
64
+ verificationKeyOverride?: string | undefined;
65
+ }
66
+ export type PrivyAppJWKS = JWTVerifyGetKey;
67
+ export declare function createPrivyAppJWKS({ appId, apiUrl, headers, verificationKeyOverride, }: CreatePrivyAppJWKSInput): PrivyAppJWKS;
68
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/lib/auth.ts"],"names":[],"mappings":"OAAO,EAEL,SAAS,EAIT,eAAe,EAEhB,MAAM,MAAM;OACN,EAAE,aAAa,EAAE;OAEjB,EAAE,IAAI,EAAE;AAKf,M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AM,EAAE,MAAM,CAAC,CAAC;IAChC,uBAAuB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC9C;AAED,MAAM,MAAM,YAAY,GAAG,eAAe,CAAC;AAE3C,wBAAgB,kBAAkB,CAAC,EACjC,KAAK,EACL,MAAM,EACN,OAAO,EACP,uBAAuB,GACxB,EAAE,uBAAuB,GAAG,YAAY,CAsBxC"}
package/lib/auth.js ADDED
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidAuthTokenError = void 0;
4
+ exports.verifyAuthToken = verifyAuthToken;
5
+ exports.verifyIdentityToken = verifyIdentityToken;
6
+ exports.createPrivyAppJWKS = createPrivyAppJWKS;
7
+ const jose_1 = require("jose");
8
+ const error_1 = require("../core/error.js");
9
+ const identity_token_1 = require("./identity-token.js");
10
+ const JWT_ALGORITHM = 'ES256';
11
+ const JWT_ISSUER = 'privy.io';
12
+ /**
13
+ * Verifies a JWT issued by privy.io for the given app ID.
14
+ * This serves both auth tokens and identity tokens.
15
+ * @returns The verify result along with the token's payload.
16
+ * @throws If the token is invalid.
17
+ */
18
+ async function verifyPrivyIssuedJwt(jwt, appId, verificationKey) {
19
+ // Because of a type difference, the calls cannot be merged into one.
20
+ let verifiedToken;
21
+ if (typeof verificationKey !== 'function') {
22
+ verifiedToken = await (0, jose_1.jwtVerify)(jwt, verificationKey, {
23
+ typ: 'JWT',
24
+ algorithms: [JWT_ALGORITHM],
25
+ issuer: JWT_ISSUER,
26
+ audience: appId,
27
+ }).catch(mapAndThrowJoseErrors);
28
+ }
29
+ else {
30
+ verifiedToken = await (0, jose_1.jwtVerify)(jwt, verificationKey, {
31
+ typ: 'JWT',
32
+ algorithms: [JWT_ALGORITHM],
33
+ issuer: JWT_ISSUER,
34
+ audience: appId,
35
+ }).catch(mapAndThrowJoseErrors);
36
+ }
37
+ return verifiedToken;
38
+ }
39
+ /**
40
+ * Verifies a Privy-issued authentication token.
41
+ *
42
+ * @returns The payload of the token if it is valid.
43
+ * @throws If the token is invalid.
44
+ */
45
+ async function verifyAuthToken({ auth_token: authToken, app_id: appId, verification_key: verificationKeyOrString, }) {
46
+ const verificationKey = typeof verificationKeyOrString === 'string' ?
47
+ await (0, jose_1.importSPKI)(verificationKeyOrString, JWT_ALGORITHM)
48
+ : verificationKeyOrString;
49
+ const verifiedToken = await verifyPrivyIssuedJwt(authToken, appId, verificationKey);
50
+ return {
51
+ app_id: throwIfNotString(verifiedToken.payload.aud),
52
+ issuer: throwIfNotString(verifiedToken.payload.iss),
53
+ issued_at: throwIfNotNumber(verifiedToken.payload.iat),
54
+ expiration: throwIfNotNumber(verifiedToken.payload.exp),
55
+ session_id: throwIfNotString(verifiedToken.payload['sid']),
56
+ user_id: throwIfNotString(verifiedToken.payload.sub),
57
+ };
58
+ }
59
+ /**
60
+ * Verifies an identity token, parsing it into a `User` object if it is valid.
61
+ *
62
+ * @returns The user object parsed from the identity token.
63
+ * @throws If the token or its payload is invalid.
64
+ */
65
+ async function verifyIdentityToken({ identity_token: identityToken, app_id: appId, verification_key: verificationKeyOrString, }) {
66
+ const verificationKey = typeof verificationKeyOrString === 'string' ?
67
+ await (0, jose_1.importSPKI)(verificationKeyOrString, JWT_ALGORITHM)
68
+ : verificationKeyOrString;
69
+ const verifiedToken = await verifyPrivyIssuedJwt(identityToken, appId, verificationKey);
70
+ if (!verifiedToken.payload) {
71
+ throw new InvalidAuthTokenError('Unable to parse identity token');
72
+ }
73
+ return (0, identity_token_1.parseUserFromIdentityTokenPayload)(verifiedToken.payload);
74
+ }
75
+ class InvalidAuthTokenError extends error_1.PrivyAPIError {
76
+ }
77
+ exports.InvalidAuthTokenError = InvalidAuthTokenError;
78
+ /** Used for asserting the values in the token payload are strings. */
79
+ function throwIfNotString(value) {
80
+ if (!value || typeof value !== 'string') {
81
+ throw new InvalidAuthTokenError("Token's payload is invalid");
82
+ }
83
+ return value;
84
+ }
85
+ /** Used for asserting the values in the token payload are numbers. */
86
+ function throwIfNotNumber(value) {
87
+ if (!value || typeof value !== 'number') {
88
+ throw new InvalidAuthTokenError("Token's payload is invalid");
89
+ }
90
+ return value;
91
+ }
92
+ /**
93
+ * Used to catch errors thrown by async `jose` functions and map to our own error types.
94
+ * This method will **always** throw an error, so it's return type is `never`.
95
+ */
96
+ function mapAndThrowJoseErrors(error) {
97
+ if (error instanceof jose_1.errors.JWTExpired) {
98
+ throw new InvalidAuthTokenError('Authentication token expired');
99
+ }
100
+ else if (error instanceof jose_1.errors.JWTClaimValidationFailed || error instanceof jose_1.errors.JWTInvalid) {
101
+ throw new InvalidAuthTokenError('Authentication token is invalid');
102
+ }
103
+ else {
104
+ throw new InvalidAuthTokenError('Failed to verify authentication token');
105
+ }
106
+ }
107
+ function createPrivyAppJWKS({ appId, apiUrl, headers, verificationKeyOverride, }) {
108
+ if (verificationKeyOverride !== undefined) {
109
+ // Use a closure to cache the verification key once imported
110
+ let verificationKey;
111
+ return async () => {
112
+ if (verificationKey === undefined) {
113
+ try {
114
+ verificationKey = await (0, jose_1.importSPKI)(verificationKeyOverride, JWT_ALGORITHM);
115
+ }
116
+ catch (error) {
117
+ throw new InvalidAuthTokenError('Failed to import the provided verification key override');
118
+ }
119
+ }
120
+ return verificationKey;
121
+ };
122
+ }
123
+ const url = new URL(`${apiUrl}/v1/apps/${appId}/jwks.json`);
124
+ return (0, jose_1.createRemoteJWKSet)(url, {
125
+ cacheMaxAge: 60 * 60 * 1000, // 60 minutes
126
+ cooldownDuration: 10 * 60 * 1000, // 10 minutes
127
+ headers,
128
+ });
129
+ }
130
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/lib/auth.ts"],"names":[],"mappings":";;;AAmFA,0CAkBC;AAsBD,kDAgBC;AA2CD,gDA2BC;AAjND,+BAQc;AACd,4CAA8C;AAC9C,wDAAqE;AAGrE,MAAM,aAAa,GAAG,OAAO,CAAC;AAC9B,MAAM,UA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Aa;QAC1C,gBAAgB,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,aAAa;QAC/C,OAAO;KACR,CAAC,CAAC;AACL,CAAC"}
package/lib/auth.mjs ADDED
@@ -0,0 +1,123 @@
1
+ import { createRemoteJWKSet, importSPKI, errors as joseErrors, jwtVerify, } from 'jose';
2
+ import { PrivyAPIError } from "../core/error.mjs";
3
+ import { parseUserFromIdentityTokenPayload } from "./identity-token.mjs";
4
+ const JWT_ALGORITHM = 'ES256';
5
+ const JWT_ISSUER = 'privy.io';
6
+ /**
7
+ * Verifies a JWT issued by privy.io for the given app ID.
8
+ * This serves both auth tokens and identity tokens.
9
+ * @returns The verify result along with the token's payload.
10
+ * @throws If the token is invalid.
11
+ */
12
+ async function verifyPrivyIssuedJwt(jwt, appId, verificationKey) {
13
+ // Because of a type difference, the calls cannot be merged into one.
14
+ let verifiedToken;
15
+ if (typeof verificationKey !== 'function') {
16
+ verifiedToken = await jwtVerify(jwt, verificationKey, {
17
+ typ: 'JWT',
18
+ algorithms: [JWT_ALGORITHM],
19
+ issuer: JWT_ISSUER,
20
+ audience: appId,
21
+ }).catch(mapAndThrowJoseErrors);
22
+ }
23
+ else {
24
+ verifiedToken = await jwtVerify(jwt, verificationKey, {
25
+ typ: 'JWT',
26
+ algorithms: [JWT_ALGORITHM],
27
+ issuer: JWT_ISSUER,
28
+ audience: appId,
29
+ }).catch(mapAndThrowJoseErrors);
30
+ }
31
+ return verifiedToken;
32
+ }
33
+ /**
34
+ * Verifies a Privy-issued authentication token.
35
+ *
36
+ * @returns The payload of the token if it is valid.
37
+ * @throws If the token is invalid.
38
+ */
39
+ export async function verifyAuthToken({ auth_token: authToken, app_id: appId, verification_key: verificationKeyOrString, }) {
40
+ const verificationKey = typeof verificationKeyOrString === 'string' ?
41
+ await importSPKI(verificationKeyOrString, JWT_ALGORITHM)
42
+ : verificationKeyOrString;
43
+ const verifiedToken = await verifyPrivyIssuedJwt(authToken, appId, verificationKey);
44
+ return {
45
+ app_id: throwIfNotString(verifiedToken.payload.aud),
46
+ issuer: throwIfNotString(verifiedToken.payload.iss),
47
+ issued_at: throwIfNotNumber(verifiedToken.payload.iat),
48
+ expiration: throwIfNotNumber(verifiedToken.payload.exp),
49
+ session_id: throwIfNotString(verifiedToken.payload['sid']),
50
+ user_id: throwIfNotString(verifiedToken.payload.sub),
51
+ };
52
+ }
53
+ /**
54
+ * Verifies an identity token, parsing it into a `User` object if it is valid.
55
+ *
56
+ * @returns The user object parsed from the identity token.
57
+ * @throws If the token or its payload is invalid.
58
+ */
59
+ export async function verifyIdentityToken({ identity_token: identityToken, app_id: appId, verification_key: verificationKeyOrString, }) {
60
+ const verificationKey = typeof verificationKeyOrString === 'string' ?
61
+ await importSPKI(verificationKeyOrString, JWT_ALGORITHM)
62
+ : verificationKeyOrString;
63
+ const verifiedToken = await verifyPrivyIssuedJwt(identityToken, appId, verificationKey);
64
+ if (!verifiedToken.payload) {
65
+ throw new InvalidAuthTokenError('Unable to parse identity token');
66
+ }
67
+ return parseUserFromIdentityTokenPayload(verifiedToken.payload);
68
+ }
69
+ export class InvalidAuthTokenError extends PrivyAPIError {
70
+ }
71
+ /** Used for asserting the values in the token payload are strings. */
72
+ function throwIfNotString(value) {
73
+ if (!value || typeof value !== 'string') {
74
+ throw new InvalidAuthTokenError("Token's payload is invalid");
75
+ }
76
+ return value;
77
+ }
78
+ /** Used for asserting the values in the token payload are numbers. */
79
+ function throwIfNotNumber(value) {
80
+ if (!value || typeof value !== 'number') {
81
+ throw new InvalidAuthTokenError("Token's payload is invalid");
82
+ }
83
+ return value;
84
+ }
85
+ /**
86
+ * Used to catch errors thrown by async `jose` functions and map to our own error types.
87
+ * This method will **always** throw an error, so it's return type is `never`.
88
+ */
89
+ function mapAndThrowJoseErrors(error) {
90
+ if (error instanceof joseErrors.JWTExpired) {
91
+ throw new InvalidAuthTokenError('Authentication token expired');
92
+ }
93
+ else if (error instanceof joseErrors.JWTClaimValidationFailed || error instanceof joseErrors.JWTInvalid) {
94
+ throw new InvalidAuthTokenError('Authentication token is invalid');
95
+ }
96
+ else {
97
+ throw new InvalidAuthTokenError('Failed to verify authentication token');
98
+ }
99
+ }
100
+ export function createPrivyAppJWKS({ appId, apiUrl, headers, verificationKeyOverride, }) {
101
+ if (verificationKeyOverride !== undefined) {
102
+ // Use a closure to cache the verification key once imported
103
+ let verificationKey;
104
+ return async () => {
105
+ if (verificationKey === undefined) {
106
+ try {
107
+ verificationKey = await importSPKI(verificationKeyOverride, JWT_ALGORITHM);
108
+ }
109
+ catch (error) {
110
+ throw new InvalidAuthTokenError('Failed to import the provided verification key override');
111
+ }
112
+ }
113
+ return verificationKey;
114
+ };
115
+ }
116
+ const url = new URL(`${apiUrl}/v1/apps/${appId}/jwks.json`);
117
+ return createRemoteJWKSet(url, {
118
+ cacheMaxAge: 60 * 60 * 1000, // 60 minutes
119
+ cooldownDuration: 10 * 60 * 1000, // 10 minutes
120
+ headers,
121
+ });
122
+ }
123
+ //# sourceMappingURL=auth.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.mjs","sourceRoot":"","sources":["../src/lib/auth.ts"],"names":[],"mappings":"OAAO,EACL,kBAAkB,EAElB,UAAU,EACV,MAAM,IAAI,UAAU,EACpB,SAAS,GAGV,MAAM,MAAM;OACN,EAAE,aAAa,EAAE;OACjB,EAAE,iCAAiC,EAAE;AAG5C,MAAM,aAAa,GAAG,OAAO,CAAC;AAC9B,MAAM,UAAU,GAAG,UAAU,CAAC;AA+B9B;;;;;GAKG;AACH,KAAK,UAAU,oBAAoB,CACjC,GAAW,EACX,KAAa,EACb,eAA4C;IAE5C,qEAAqE;IACrE,IAAI,aAA8B,CAAC;IACnC,IAAI,OAAO,eAAe,KAAK,UAAU,EAAE,CAAC;QAC1C,aAAa,GAAG,MAAM,SAAS,CAAC,GAAG,EAAE,eAAe,EAAE;YACpD,GAAG,EAAE,KAAK;YACV,UAAU,EAAE,CAAC,aAAa,CAAC;YAC3B,MAAM,EAAE,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AAU,CAAC,UAAU,EAAE,CAAC;QAC1G,MAAM,IAAI,qBAAqB,CAAC,iCAAiC,CAAC,CAAC;IACrE,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,qBAAqB,CAAC,uCAAuC,CAAC,CAAC;IAC3E,CAAC;AACH,CAAC;AAWD,MAAM,UAAU,kBAAkB,CAAC,EACjC,KAAK,EACL,MAAM,EACN,OAAO,EACP,uBAAuB,GACC;IACxB,IAAI,uBAAuB,KAAK,SAAS,EAAE,CAAC;QAC1C,4DAA4D;QAC5D,IAAI,eAA0B,CAAC;QAC/B,OAAO,KAAK,IAAI,EAAE;YAChB,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;gBAClC,IAAI,CAAC;oBACH,eAAe,GAAG,MAAM,UAAU,CAAC,uBAAuB,EAAE,aAAa,CAAC,CAAC;gBAC7E,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,MAAM,IAAI,qBAAqB,CAAC,yDAAyD,CAAC,CAAC;gBAC7F,CAAC;YACH,CAAC;YACD,OAAO,eAAe,CAAC;QACzB,CAAC,CAAC;IACJ,CAAC;IAED,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,MAAM,YAAY,KAAK,YAAY,CAAC,CAAC;IAC5D,OAAO,kBAAkB,CAAC,GAAG,EAAE;QAC7B,WAAW,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,aAAa;QAC1C,gBAAgB,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,aAAa;QAC/C,OAAO;KACR,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { JWTPayload } from 'jose';
2
+ import { User } from "../resources.mjs";
3
+ import { PrivyAPIError } from "../error.mjs";
4
+ /**
5
+ * Parses the payload of an identity token (JWT) into a `User` object.
6
+ * Note that the user object may be incomplete due to the size constraints of the identity token.
7
+ *
8
+ * @param payload The payload of the identity token.
9
+ * @returns The user object parsed from the identity token.
10
+ * @throws If the payload is invalid.
11
+ */
12
+ export declare function parseUserFromIdentityTokenPayload(payload: JWTPayload): User;
13
+ export declare class InvalidIdentityTokenError extends PrivyAPIError {
14
+ }
15
+ //# sourceMappingURL=identity-token.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity-token.d.mts","sourceRoot":"","sources":["../src/lib/identity-token.ts"],"names":[],"mappings":"OAAO,EAAE,UAAU,EAAE,MAAM,MAAM;OAC1B,EAAE,IAAI,EAAE;OACR,EAAE,aAAa,EAAE;AAGxB;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,CAY3E;AA8PD,qBAAa,yBAA0B,SAAQ,aAAa;CAAG"}
@@ -0,0 +1,15 @@
1
+ import { JWTPayload } from 'jose';
2
+ import { User } from "../resources.js";
3
+ import { PrivyAPIError } from "../error.js";
4
+ /**
5
+ * Parses the payload of an identity token (JWT) into a `User` object.
6
+ * Note that the user object may be incomplete due to the size constraints of the identity token.
7
+ *
8
+ * @param payload The payload of the identity token.
9
+ * @returns The user object parsed from the identity token.
10
+ * @throws If the payload is invalid.
11
+ */
12
+ export declare function parseUserFromIdentityTokenPayload(payload: JWTPayload): User;
13
+ export declare class InvalidIdentityTokenError extends PrivyAPIError {
14
+ }
15
+ //# sourceMappingURL=identity-token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity-token.d.ts","sourceRoot":"","sources":["../src/lib/identity-token.ts"],"names":[],"mappings":"OAAO,EAAE,UAAU,EAAE,MAAM,MAAM;OAC1B,EAAE,IAAI,EAAE;OACR,EAAE,aAAa,EAAE;AAGxB;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,CAY3E;AA8PD,qBAAa,yBAA0B,SAAQ,aAAa;CAAG"}