@multiplatform.one/keycloak 6.1.0 → 6.4.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 (78) hide show
  1. package/README.md +58 -0
  2. package/dist/cjs/index.cjs +28 -1
  3. package/dist/cjs/index.native.cjs +36 -5
  4. package/dist/esm/index.js +28 -1
  5. package/dist/esm/index.native.js +36 -5
  6. package/package.json +18 -16
  7. package/src/betterAuth/expoAuthFlow.native.ts +56 -5
  8. package/src/frappeToken.ts +81 -4
  9. package/types/Authenticated.d.ts +9 -0
  10. package/types/Authenticated.d.ts.map +1 -0
  11. package/types/Loading.d.ts +6 -0
  12. package/types/Loading.d.ts.map +1 -0
  13. package/types/authConfig.d.ts +10 -0
  14. package/types/authConfig.d.ts.map +1 -0
  15. package/types/betterAuth/client.d.ts +798 -0
  16. package/types/betterAuth/client.d.ts.map +1 -0
  17. package/types/betterAuth/expoAuthFlow.native.d.ts +31 -0
  18. package/types/betterAuth/expoAuthFlow.native.d.ts.map +1 -0
  19. package/types/betterAuth/expoClient.d.ts +803 -0
  20. package/types/betterAuth/expoClient.d.ts.map +1 -0
  21. package/types/betterAuth/index.d.ts +3 -0
  22. package/types/betterAuth/index.d.ts.map +1 -0
  23. package/types/frappeToken.d.ts +19 -0
  24. package/types/frappeToken.d.ts.map +1 -0
  25. package/types/frappeToken.native.d.ts +15 -0
  26. package/types/frappeToken.native.d.ts.map +1 -0
  27. package/types/hooks/index.d.ts +4 -0
  28. package/types/hooks/index.d.ts.map +1 -0
  29. package/types/hooks/useAuthConfig.d.ts +2 -0
  30. package/types/hooks/useAuthConfig.d.ts.map +1 -0
  31. package/types/hooks/useTokensFromQuery/index.d.ts +2 -0
  32. package/types/hooks/useTokensFromQuery/index.d.ts.map +1 -0
  33. package/types/hooks/useTokensFromQuery/index.native.d.ts +2 -0
  34. package/types/hooks/useTokensFromQuery/index.native.d.ts.map +1 -0
  35. package/types/hooks/useTokensFromState.d.ts +2 -0
  36. package/types/hooks/useTokensFromState.d.ts.map +1 -0
  37. package/types/index.d.ts +10 -0
  38. package/types/index.d.ts.map +1 -0
  39. package/types/keycloak/base.d.ts +50 -0
  40. package/types/keycloak/base.d.ts.map +1 -0
  41. package/types/keycloak/config.d.ts +12 -0
  42. package/types/keycloak/config.d.ts.map +1 -0
  43. package/types/keycloak/context.d.ts +3 -0
  44. package/types/keycloak/context.d.ts.map +1 -0
  45. package/types/keycloak/index.d.ts +20 -0
  46. package/types/keycloak/index.d.ts.map +1 -0
  47. package/types/keycloak/index.native.d.ts +7 -0
  48. package/types/keycloak/index.native.d.ts.map +1 -0
  49. package/types/keycloak/index.webext.d.ts +19 -0
  50. package/types/keycloak/index.webext.d.ts.map +1 -0
  51. package/types/one.d.ts +28 -0
  52. package/types/one.d.ts.map +1 -0
  53. package/types/provider/AfterAuth.d.ts +6 -0
  54. package/types/provider/AfterAuth.d.ts.map +1 -0
  55. package/types/provider/KeycloakProvider.d.ts +17 -0
  56. package/types/provider/KeycloakProvider.d.ts.map +1 -0
  57. package/types/provider/authProvider/index.d.ts +13 -0
  58. package/types/provider/authProvider/index.d.ts.map +1 -0
  59. package/types/provider/authProvider/index.native.d.ts +15 -0
  60. package/types/provider/authProvider/index.native.d.ts.map +1 -0
  61. package/types/provider/authProvider/index.webext.d.ts +14 -0
  62. package/types/provider/authProvider/index.webext.d.ts.map +1 -0
  63. package/types/provider/authProvider/shared.d.ts +38 -0
  64. package/types/provider/authProvider/shared.d.ts.map +1 -0
  65. package/types/provider/index.d.ts +4 -0
  66. package/types/provider/index.d.ts.map +1 -0
  67. package/types/session/index.d.ts +29 -0
  68. package/types/session/index.d.ts.map +1 -0
  69. package/types/session/index.native.d.ts +13 -0
  70. package/types/session/index.native.d.ts.map +1 -0
  71. package/types/session/index.webext.d.ts +11 -0
  72. package/types/session/index.webext.d.ts.map +1 -0
  73. package/types/state.d.ts +18 -0
  74. package/types/state.d.ts.map +1 -0
  75. package/types/token.d.ts +129 -0
  76. package/types/token.d.ts.map +1 -0
  77. package/types/types.d.ts +19 -0
  78. package/types/types.d.ts.map +1 -0
@@ -0,0 +1,129 @@
1
+ import type { KeycloakTokenParsed } from "@multiplatform.one/keycloak-js";
2
+ /**
3
+ * Wallet types supported by siwe-keycloak extension.
4
+ * Currently supports Ethereum wallets, with Solana and Sui planned.
5
+ */
6
+ export type WalletType = "ethereum" | "solana" | "sui";
7
+ /**
8
+ * Structure of wallet data within a chain type.
9
+ * Contains an array of wallet addresses for that chain.
10
+ */
11
+ export interface WalletTypeInfo {
12
+ addresses: string[];
13
+ }
14
+ /**
15
+ * Map of wallet types to their wallet info.
16
+ * This is the structure inside token.crypto.wallets
17
+ */
18
+ export interface WalletsMap {
19
+ [walletType: string]: WalletTypeInfo;
20
+ }
21
+ /**
22
+ * The crypto claim structure added to tokens by siwe-wallet-mapper.
23
+ * Contains wallet information from the siwe-keycloak extension.
24
+ */
25
+ export interface CryptoClaim {
26
+ wallets: WalletsMap;
27
+ }
28
+ /**
29
+ * Extracts wallet addresses from a JWT token that includes the siwe-wallet-mapper claims.
30
+ *
31
+ * The siwe-keycloak extension adds a "crypto" claim with the following structure:
32
+ * ```json
33
+ * {
34
+ * "crypto": {
35
+ * "wallets": {
36
+ * "ethereum": {
37
+ * "addresses": ["0x1234...", "0x5678..."]
38
+ * }
39
+ * }
40
+ * }
41
+ * }
42
+ * ```
43
+ *
44
+ * @param token - JWT access token or ID token string
45
+ * @returns Object containing wallet addresses by type, or empty object if no wallets
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const wallets = getWalletsFromToken(accessToken);
50
+ * // { ethereum: { addresses: ['0x1234...'] } }
51
+ *
52
+ * const ethAddresses = wallets.ethereum?.addresses ?? [];
53
+ * // ['0x1234...']
54
+ * ```
55
+ */
56
+ export declare function getWalletsFromToken(token: string): WalletsMap;
57
+ /**
58
+ * Extracts all wallet addresses of a specific type from a JWT token.
59
+ *
60
+ * @param token - JWT access token or ID token string
61
+ * @param walletType - The wallet type to extract (e.g., "ethereum", "solana")
62
+ * @returns Array of wallet addresses, or empty array if none found
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const addresses = getWalletAddresses(accessToken, 'ethereum');
67
+ * // ['0x1234...', '0x5678...']
68
+ * ```
69
+ */
70
+ export declare function getWalletAddresses(token: string, walletType?: WalletType): string[];
71
+ /**
72
+ * Checks if a user has any wallet addresses in their token.
73
+ *
74
+ * @param token - JWT access token or ID token string
75
+ * @returns true if the user has at least one wallet address
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * if (hasWallets(accessToken)) {
80
+ * // User authenticated with a wallet or has registered wallets
81
+ * }
82
+ * ```
83
+ */
84
+ export declare function hasWallets(token: string): boolean;
85
+ /**
86
+ * Gets all wallet addresses across all chain types from a token.
87
+ *
88
+ * @param token - JWT access token or ID token string
89
+ * @returns Array of objects with walletType and address
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * const allWallets = getAllWalletAddresses(accessToken);
94
+ * // [
95
+ * // { walletType: 'ethereum', address: '0x1234...' },
96
+ * // { walletType: 'ethereum', address: '0x5678...' },
97
+ * // { walletType: 'solana', address: 'AbCd...' }
98
+ * // ]
99
+ * ```
100
+ */
101
+ export declare function getAllWalletAddresses(token: string): Array<{
102
+ walletType: string;
103
+ address: string;
104
+ }>;
105
+ export declare function validOrRefreshableToken(token?: string | false, refreshToken?: string | boolean): string | false | undefined;
106
+ export declare function validOrRefreshableToken(token?: string | boolean, refreshToken?: string | boolean): string | boolean | undefined;
107
+ export declare function isTokenExpired(token: string): boolean;
108
+ export interface TokenParsed extends KeycloakTokenParsed {
109
+ jti?: string;
110
+ sid?: string;
111
+ typ?: "Bearer" | string;
112
+ }
113
+ /**
114
+ * Extended token interface that includes wallet claims from siwe-keycloak.
115
+ */
116
+ export interface TokenWithWallets extends TokenParsed {
117
+ /**
118
+ * Crypto claim containing wallet addresses.
119
+ * Added by the siwe-wallet-mapper protocol mapper.
120
+ */
121
+ crypto?: CryptoClaim;
122
+ }
123
+ export interface AccessTokenParsed extends TokenWithWallets {
124
+ email?: string;
125
+ email_verified?: boolean;
126
+ preferred_username?: string;
127
+ scope?: string;
128
+ }
129
+ //# sourceMappingURL=token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../src/token.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAE1E;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,QAAQ,GAAG,KAAK,CAAC;AAEvD;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,CAAC,UAAU,EAAE,MAAM,GAAG,cAAc,CAAC;CACtC;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,UAAU,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAO7D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,GAAE,UAAuB,GAAG,MAAM,EAAE,CAG/F;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAGjD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,MAAM,GACZ,KAAK,CAAC;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAahD;AAED,wBAAgB,uBAAuB,CACrC,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,EACtB,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,GAC9B,MAAM,GAAG,KAAK,GAAG,SAAS,CAAC;AAC9B,wBAAgB,uBAAuB,CACrC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,EACxB,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,GAC9B,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;AAYhC,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,WAI3C;AAED,MAAM,WAAW,WAAY,SAAQ,mBAAmB;IACtD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,WAAW;IACnD;;;OAGG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,iBAAkB,SAAQ,gBAAgB;IACzD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
@@ -0,0 +1,19 @@
1
+ declare global {
2
+ interface Window {
3
+ ReactNativeWebView: {
4
+ postMessage: (body: string) => unknown;
5
+ };
6
+ webkit: {
7
+ messageHandlers: {
8
+ [key: string]: {
9
+ postMessage: (body: string) => unknown;
10
+ };
11
+ };
12
+ };
13
+ }
14
+ }
15
+ export interface KeycloakMock {
16
+ email?: string;
17
+ username: string;
18
+ }
19
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,kBAAkB,EAAE;YAClB,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;SACxC,CAAC;QACF,MAAM,EAAE;YACN,eAAe,EAAE;gBACf,CAAC,GAAG,EAAE,MAAM,GAAG;oBACb,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;iBACxC,CAAC;aACH,CAAC;SACH,CAAC;KACH;CACF;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB"}