@renown/sdk 6.0.0-staging.4 → 6.0.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 (233) hide show
  1. package/README.md +47 -437
  2. package/dist/index.d.ts +77 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +173 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/node.d.ts +136 -0
  7. package/dist/node.d.ts.map +1 -0
  8. package/dist/node.js +305 -0
  9. package/dist/node.js.map +1 -0
  10. package/dist/renown-builder-BLM2JCDq.js +815 -0
  11. package/dist/renown-builder-BLM2JCDq.js.map +1 -0
  12. package/dist/utils-BGF8Qb5f.d.ts +689 -0
  13. package/dist/utils-BGF8Qb5f.d.ts.map +1 -0
  14. package/package.json +18 -40
  15. package/dist/e2e/fixtures/main.d.ts +0 -2
  16. package/dist/e2e/fixtures/main.d.ts.map +0 -1
  17. package/dist/e2e/fixtures/main.js +0 -97
  18. package/dist/e2e/fixtures/main.js.map +0 -1
  19. package/dist/e2e/fixtures/vite.config.d.ts +0 -3
  20. package/dist/e2e/fixtures/vite.config.d.ts.map +0 -1
  21. package/dist/e2e/fixtures/vite.config.js +0 -10
  22. package/dist/e2e/fixtures/vite.config.js.map +0 -1
  23. package/dist/e2e/renown-components.spec.d.ts +0 -2
  24. package/dist/e2e/renown-components.spec.d.ts.map +0 -1
  25. package/dist/e2e/renown-components.spec.js +0 -155
  26. package/dist/e2e/renown-components.spec.js.map +0 -1
  27. package/dist/playwright.config.d.ts +0 -3
  28. package/dist/playwright.config.d.ts.map +0 -1
  29. package/dist/playwright.config.js +0 -25
  30. package/dist/playwright.config.js.map +0 -1
  31. package/dist/src/assets/assets.d.ts +0 -19
  32. package/dist/src/assets/renown-hover.svg +0 -17
  33. package/dist/src/assets/renown-light.svg +0 -15
  34. package/dist/src/assets/renown-short-hover.png +0 -0
  35. package/dist/src/assets/renown-short.png +0 -0
  36. package/dist/src/assets/renown.svg +0 -16
  37. package/dist/src/common.d.ts +0 -21
  38. package/dist/src/common.d.ts.map +0 -1
  39. package/dist/src/common.js +0 -113
  40. package/dist/src/common.js.map +0 -1
  41. package/dist/src/components/RenownAuthButton.d.ts +0 -62
  42. package/dist/src/components/RenownAuthButton.d.ts.map +0 -1
  43. package/dist/src/components/RenownAuthButton.js +0 -82
  44. package/dist/src/components/RenownAuthButton.js.map +0 -1
  45. package/dist/src/components/RenownLoginButton.d.ts +0 -48
  46. package/dist/src/components/RenownLoginButton.d.ts.map +0 -1
  47. package/dist/src/components/RenownLoginButton.js +0 -175
  48. package/dist/src/components/RenownLoginButton.js.map +0 -1
  49. package/dist/src/components/RenownUserButton.d.ts +0 -66
  50. package/dist/src/components/RenownUserButton.d.ts.map +0 -1
  51. package/dist/src/components/RenownUserButton.js +0 -216
  52. package/dist/src/components/RenownUserButton.js.map +0 -1
  53. package/dist/src/components/icons.d.ts +0 -25
  54. package/dist/src/components/icons.d.ts.map +0 -1
  55. package/dist/src/components/icons.js +0 -24
  56. package/dist/src/components/icons.js.map +0 -1
  57. package/dist/src/components/image-data.d.ts +0 -3
  58. package/dist/src/components/image-data.d.ts.map +0 -1
  59. package/dist/src/components/image-data.js +0 -4
  60. package/dist/src/components/image-data.js.map +0 -1
  61. package/dist/src/components/index.d.ts +0 -8
  62. package/dist/src/components/index.d.ts.map +0 -1
  63. package/dist/src/components/index.js +0 -5
  64. package/dist/src/components/index.js.map +0 -1
  65. package/dist/src/constants.d.ts +0 -130
  66. package/dist/src/constants.d.ts.map +0 -1
  67. package/dist/src/constants.js +0 -40
  68. package/dist/src/constants.js.map +0 -1
  69. package/dist/src/crypto/browser-key-storage.d.ts +0 -10
  70. package/dist/src/crypto/browser-key-storage.d.ts.map +0 -1
  71. package/dist/src/crypto/browser-key-storage.js +0 -76
  72. package/dist/src/crypto/browser-key-storage.js.map +0 -1
  73. package/dist/src/crypto/index.d.ts +0 -7
  74. package/dist/src/crypto/index.d.ts.map +0 -1
  75. package/dist/src/crypto/index.js +0 -9
  76. package/dist/src/crypto/index.js.map +0 -1
  77. package/dist/src/crypto/memory-key-storage.d.ts +0 -9
  78. package/dist/src/crypto/memory-key-storage.d.ts.map +0 -1
  79. package/dist/src/crypto/memory-key-storage.js +0 -18
  80. package/dist/src/crypto/memory-key-storage.js.map +0 -1
  81. package/dist/src/crypto/node-key-storage.d.ts +0 -21
  82. package/dist/src/crypto/node-key-storage.d.ts.map +0 -1
  83. package/dist/src/crypto/node-key-storage.js +0 -107
  84. package/dist/src/crypto/node-key-storage.js.map +0 -1
  85. package/dist/src/crypto/node.d.ts +0 -2
  86. package/dist/src/crypto/node.d.ts.map +0 -1
  87. package/dist/src/crypto/node.js +0 -3
  88. package/dist/src/crypto/node.js.map +0 -1
  89. package/dist/src/crypto/renown-crypto-builder.d.ts +0 -11
  90. package/dist/src/crypto/renown-crypto-builder.d.ts.map +0 -1
  91. package/dist/src/crypto/renown-crypto-builder.js +0 -34
  92. package/dist/src/crypto/renown-crypto-builder.js.map +0 -1
  93. package/dist/src/crypto/renown-crypto.d.ts +0 -26
  94. package/dist/src/crypto/renown-crypto.d.ts.map +0 -1
  95. package/dist/src/crypto/renown-crypto.js +0 -56
  96. package/dist/src/crypto/renown-crypto.js.map +0 -1
  97. package/dist/src/crypto/signer.d.ts +0 -74
  98. package/dist/src/crypto/signer.d.ts.map +0 -1
  99. package/dist/src/crypto/signer.js +0 -306
  100. package/dist/src/crypto/signer.js.map +0 -1
  101. package/dist/src/crypto/types.d.ts +0 -27
  102. package/dist/src/crypto/types.d.ts.map +0 -1
  103. package/dist/src/crypto/types.js +0 -2
  104. package/dist/src/crypto/types.js.map +0 -1
  105. package/dist/src/crypto/utils.d.ts +0 -13
  106. package/dist/src/crypto/utils.d.ts.map +0 -1
  107. package/dist/src/crypto/utils.js +0 -39
  108. package/dist/src/crypto/utils.js.map +0 -1
  109. package/dist/src/event/event.browser.d.ts +0 -10
  110. package/dist/src/event/event.browser.d.ts.map +0 -1
  111. package/dist/src/event/event.browser.js +0 -24
  112. package/dist/src/event/event.browser.js.map +0 -1
  113. package/dist/src/event/event.node.d.ts +0 -8
  114. package/dist/src/event/event.node.d.ts.map +0 -1
  115. package/dist/src/event/event.node.js +0 -17
  116. package/dist/src/event/event.node.js.map +0 -1
  117. package/dist/src/event/memory.d.ts +0 -8
  118. package/dist/src/event/memory.d.ts.map +0 -1
  119. package/dist/src/event/memory.js +0 -16
  120. package/dist/src/event/memory.js.map +0 -1
  121. package/dist/src/event/types.d.ts +0 -16
  122. package/dist/src/event/types.d.ts.map +0 -1
  123. package/dist/src/event/types.js +0 -2
  124. package/dist/src/event/types.js.map +0 -1
  125. package/dist/src/hooks/index.d.ts +0 -2
  126. package/dist/src/hooks/index.d.ts.map +0 -1
  127. package/dist/src/hooks/index.js +0 -2
  128. package/dist/src/hooks/index.js.map +0 -1
  129. package/dist/src/hooks/use-user.d.ts +0 -21
  130. package/dist/src/hooks/use-user.d.ts.map +0 -1
  131. package/dist/src/hooks/use-user.js +0 -30
  132. package/dist/src/hooks/use-user.js.map +0 -1
  133. package/dist/src/index.browser.d.ts +0 -4
  134. package/dist/src/index.browser.d.ts.map +0 -1
  135. package/dist/src/index.browser.js +0 -4
  136. package/dist/src/index.browser.js.map +0 -1
  137. package/dist/src/index.d.ts +0 -15
  138. package/dist/src/index.d.ts.map +0 -1
  139. package/dist/src/index.js +0 -15
  140. package/dist/src/index.js.map +0 -1
  141. package/dist/src/index.node.d.ts +0 -4
  142. package/dist/src/index.node.d.ts.map +0 -1
  143. package/dist/src/index.node.js +0 -4
  144. package/dist/src/index.node.js.map +0 -1
  145. package/dist/src/init.browser.d.ts +0 -52
  146. package/dist/src/init.browser.d.ts.map +0 -1
  147. package/dist/src/init.browser.js +0 -66
  148. package/dist/src/init.browser.js.map +0 -1
  149. package/dist/src/init.node.d.ts +0 -29
  150. package/dist/src/init.node.d.ts.map +0 -1
  151. package/dist/src/init.node.js +0 -30
  152. package/dist/src/init.node.js.map +0 -1
  153. package/dist/src/lib/renown/constants.d.ts +0 -130
  154. package/dist/src/lib/renown/constants.d.ts.map +0 -1
  155. package/dist/src/lib/renown/constants.js +0 -40
  156. package/dist/src/lib/renown/constants.js.map +0 -1
  157. package/dist/src/lib/renown/credential.d.ts +0 -2
  158. package/dist/src/lib/renown/credential.d.ts.map +0 -1
  159. package/dist/src/lib/renown/credential.js +0 -68
  160. package/dist/src/lib/renown/credential.js.map +0 -1
  161. package/dist/src/lib/renown/did-parser.d.ts +0 -28
  162. package/dist/src/lib/renown/did-parser.d.ts.map +0 -1
  163. package/dist/src/lib/renown/did-parser.js +0 -57
  164. package/dist/src/lib/renown/did-parser.js.map +0 -1
  165. package/dist/src/lib/renown/index.d.ts +0 -4
  166. package/dist/src/lib/renown/index.d.ts.map +0 -1
  167. package/dist/src/lib/renown/index.js +0 -4
  168. package/dist/src/lib/renown/index.js.map +0 -1
  169. package/dist/src/lib/renown/utils.d.ts +0 -33
  170. package/dist/src/lib/renown/utils.d.ts.map +0 -1
  171. package/dist/src/lib/renown/utils.js +0 -188
  172. package/dist/src/lib/renown/utils.js.map +0 -1
  173. package/dist/src/lib/session-storage.d.ts +0 -40
  174. package/dist/src/lib/session-storage.d.ts.map +0 -1
  175. package/dist/src/lib/session-storage.js +0 -107
  176. package/dist/src/lib/session-storage.js.map +0 -1
  177. package/dist/src/node.d.ts +0 -10
  178. package/dist/src/node.d.ts.map +0 -1
  179. package/dist/src/node.js +0 -10
  180. package/dist/src/node.js.map +0 -1
  181. package/dist/src/providers/index.d.ts +0 -3
  182. package/dist/src/providers/index.d.ts.map +0 -1
  183. package/dist/src/providers/index.js +0 -2
  184. package/dist/src/providers/index.js.map +0 -1
  185. package/dist/src/providers/renown-user-provider.d.ts +0 -76
  186. package/dist/src/providers/renown-user-provider.d.ts.map +0 -1
  187. package/dist/src/providers/renown-user-provider.js +0 -166
  188. package/dist/src/providers/renown-user-provider.js.map +0 -1
  189. package/dist/src/renown-builder.d.ts +0 -60
  190. package/dist/src/renown-builder.d.ts.map +0 -1
  191. package/dist/src/renown-builder.js +0 -115
  192. package/dist/src/renown-builder.js.map +0 -1
  193. package/dist/src/storage/common.d.ts +0 -17
  194. package/dist/src/storage/common.d.ts.map +0 -1
  195. package/dist/src/storage/common.js +0 -20
  196. package/dist/src/storage/common.js.map +0 -1
  197. package/dist/src/storage/storage.browser.d.ts +0 -10
  198. package/dist/src/storage/storage.browser.d.ts.map +0 -1
  199. package/dist/src/storage/storage.browser.js +0 -27
  200. package/dist/src/storage/storage.browser.js.map +0 -1
  201. package/dist/src/storage/storage.node.d.ts +0 -11
  202. package/dist/src/storage/storage.node.d.ts.map +0 -1
  203. package/dist/src/storage/storage.node.js +0 -42
  204. package/dist/src/storage/storage.node.js.map +0 -1
  205. package/dist/src/types.d.ts +0 -104
  206. package/dist/src/types.d.ts.map +0 -1
  207. package/dist/src/types.js +0 -2
  208. package/dist/src/types.js.map +0 -1
  209. package/dist/src/utils.d.ts +0 -18
  210. package/dist/src/utils.d.ts.map +0 -1
  211. package/dist/src/utils.js +0 -88
  212. package/dist/src/utils.js.map +0 -1
  213. package/dist/test/auth.test.d.ts +0 -2
  214. package/dist/test/auth.test.d.ts.map +0 -1
  215. package/dist/test/auth.test.js +0 -13
  216. package/dist/test/auth.test.js.map +0 -1
  217. package/dist/test/crypto/signer.test.d.ts +0 -2
  218. package/dist/test/crypto/signer.test.d.ts.map +0 -1
  219. package/dist/test/crypto/signer.test.js +0 -184
  220. package/dist/test/crypto/signer.test.js.map +0 -1
  221. package/dist/test/script.test.d.ts +0 -2
  222. package/dist/test/script.test.d.ts.map +0 -1
  223. package/dist/test/script.test.js +0 -144
  224. package/dist/test/script.test.js.map +0 -1
  225. package/dist/test/storage.node.test.d.ts +0 -2
  226. package/dist/test/storage.node.test.d.ts.map +0 -1
  227. package/dist/test/storage.node.test.js +0 -66
  228. package/dist/test/storage.node.test.js.map +0 -1
  229. package/dist/tsconfig.tsbuildinfo +0 -1
  230. package/dist/vitest.config.d.ts +0 -3
  231. package/dist/vitest.config.d.ts.map +0 -1
  232. package/dist/vitest.config.js +0 -7
  233. package/dist/vitest.config.js.map +0 -1
@@ -1,57 +0,0 @@
1
- /**
2
- * DID parsing utilities for extracting information from DID strings
3
- */
4
- /**
5
- * Parse a DID:pkh string to extract network, chain ID, and address information
6
- * @param did - The DID string in format "did:pkh:networkId:chainId:address"
7
- * @returns Parsed DID information
8
- * @throws Error if the DID format is invalid
9
- */
10
- export function parsePkhDid(did) {
11
- const parts = did.split(":");
12
- if (!did.startsWith("did:pkh:") || parts.length !== 5) {
13
- throw new Error("Invalid pkh did");
14
- }
15
- const [, , networkId, chainIdStr, address] = parts;
16
- if (!address.startsWith("0x")) {
17
- throw new Error(`Invalid address: ${address}`);
18
- }
19
- const chainId = Number(chainIdStr);
20
- if (isNaN(chainId)) {
21
- throw new Error(`Invalid chain id: ${chainIdStr}`);
22
- }
23
- return {
24
- chainId,
25
- networkId,
26
- address: address,
27
- };
28
- }
29
- /**
30
- * Extract Ethereum address from a DID:pkh string
31
- * @param did - The DID string
32
- * @returns Ethereum address or null if invalid
33
- */
34
- export function extractEthAddressFromDid(did) {
35
- try {
36
- const parsed = parsePkhDid(did);
37
- return parsed.address;
38
- }
39
- catch {
40
- return null;
41
- }
42
- }
43
- /**
44
- * Extract chain ID from a DID:pkh string
45
- * @param did - The DID string
46
- * @returns Chain ID or null if invalid
47
- */
48
- export function extractChainIdFromDid(did) {
49
- try {
50
- const parsed = parsePkhDid(did);
51
- return parsed.chainId;
52
- }
53
- catch {
54
- return null;
55
- }
56
- }
57
- //# sourceMappingURL=did-parser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"did-parser.js","sourceRoot":"","sources":["../../../../src/lib/renown/did-parser.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtD,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IACD,MAAM,CAAC,EAAE,AAAD,EAAG,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC;IAEnD,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAAC;IACjD,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;IACnC,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,qBAAqB,UAAU,EAAE,CAAC,CAAC;IACrD,CAAC;IAED,OAAO;QACL,OAAO;QACP,SAAS;QACT,OAAO,EAAE,OAA4B;KACtC,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,GAAW;IAClD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;QAChC,OAAO,MAAM,CAAC,OAAO,CAAC;IACxB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAW;IAC/C,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;QAChC,OAAO,MAAM,CAAC,OAAO,CAAC;IACxB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -1,4 +0,0 @@
1
- export * from "./constants.js";
2
- export * from "./did-parser.js";
3
- export * from "./utils.js";
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/renown/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC"}
@@ -1,4 +0,0 @@
1
- export * from "./constants.js";
2
- export * from "./did-parser.js";
3
- export * from "./utils.js";
4
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/renown/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC"}
@@ -1,33 +0,0 @@
1
- import type { IRenown } from "@renown/sdk";
2
- import type { IRenownCrypto } from "../../crypto/index.js";
3
- export type LoginStatus = "initial" | "checking" | "authorized" | "not-authorized";
4
- export interface User {
5
- did: string;
6
- address: string;
7
- name?: string;
8
- email?: string;
9
- avatar?: string;
10
- ethAddress?: string;
11
- documentId?: string;
12
- }
13
- export declare function fetchProfileDataForUser(user: User): Promise<User>;
14
- declare global {
15
- interface Window {
16
- renown?: IRenown;
17
- reactor?: {
18
- setGenerateJwtHandler: (handler: (driveUrl: string) => Promise<string>) => void;
19
- removeJwtHandler: () => void;
20
- };
21
- renownCrypto?: IRenownCrypto;
22
- }
23
- }
24
- export declare function openRenown(documentId?: string): void;
25
- export declare function handleRenownReturn(): Promise<void>;
26
- export declare function login(userDid: string | undefined, renown: IRenown | undefined, renownCrypto: IRenownCrypto | undefined): Promise<User | undefined>;
27
- export declare function logout(): Promise<void>;
28
- /**
29
- * Re-authenticate using stored session data
30
- * This allows calling renown.login without needing to go through the full auth flow again
31
- */
32
- export declare function reauthenticateFromSession(): Promise<User | null>;
33
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/lib/renown/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE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
2
- import { RENOWN_CHAIN_ID, RENOWN_NETWORK_ID, RENOWN_URL } from "./constants.js";
3
- import { extractEthAddressFromDid } from "./did-parser.js";
4
- // Helper function to fetch user profile from renown API
5
- async function fetchUserProfileFromRenown(ethAddress) {
6
- try {
7
- const response = await fetch(`${RENOWN_URL}/api/profile`, {
8
- method: "POST",
9
- headers: {
10
- "Content-Type": "application/json",
11
- },
12
- body: JSON.stringify({
13
- ethAddress,
14
- }),
15
- });
16
- if (!response.ok) {
17
- throw new Error(`HTTP error! status: ${response.status}`);
18
- }
19
- const result = (await response.json());
20
- const profile = result.profile;
21
- if (profile) {
22
- return {
23
- documentId: profile.documentId,
24
- username: profile.username,
25
- ethAddress: profile.ethAddress,
26
- userImage: profile.userImage,
27
- createdAt: profile.createdAt,
28
- updatedAt: profile.updatedAt,
29
- };
30
- }
31
- return null;
32
- }
33
- catch (error) {
34
- console.error("Error fetching user profile from renown:", error);
35
- return null;
36
- }
37
- }
38
- // Helper function to fetch profile data for a user
39
- export async function fetchProfileDataForUser(user) {
40
- try {
41
- const ethAddress = extractEthAddressFromDid(user.did);
42
- if (!ethAddress) {
43
- console.warn("Could not extract ETH address from DID:", user.did);
44
- return user;
45
- }
46
- // Get profile data from renown API
47
- const profile = await fetchUserProfileFromRenown(ethAddress);
48
- if (profile) {
49
- return {
50
- ...user,
51
- name: profile.username || undefined,
52
- avatar: profile.userImage || undefined,
53
- ethAddress: profile.ethAddress || undefined,
54
- documentId: profile.documentId,
55
- };
56
- }
57
- // If no profile found, return user with ethAddress
58
- return {
59
- ...user,
60
- ethAddress,
61
- };
62
- }
63
- catch (error) {
64
- console.error("Failed to fetch profile data for user:", error);
65
- return user;
66
- }
67
- }
68
- export function openRenown(documentId) {
69
- // If documentId is provided, open the profile page directly
70
- if (documentId) {
71
- const profileUrl = `${RENOWN_URL}/profile/${documentId}`;
72
- window.open(profileUrl, "_blank")?.focus();
73
- return;
74
- }
75
- // Otherwise, open the auth flow
76
- const url = new URL(RENOWN_URL);
77
- // Get DID from renownCrypto if available
78
- const connectDid = window.renownCrypto?.did;
79
- if (!connectDid) {
80
- throw new Error("Keypair not found - authentication may not be properly initialized");
81
- }
82
- url.searchParams.set("connect", connectDid);
83
- url.searchParams.set("network", RENOWN_NETWORK_ID);
84
- url.searchParams.set("chain", RENOWN_CHAIN_ID);
85
- const returnUrl = new URL(window.location.pathname, window.location.origin);
86
- url.searchParams.set("returnUrl", returnUrl.toJSON());
87
- window.open(url, "_self")?.focus();
88
- }
89
- // Check for return from Renown authentication and handle login
90
- export async function handleRenownReturn() {
91
- if (typeof window === "undefined")
92
- return;
93
- const urlParams = new URLSearchParams(window.location.search);
94
- const userDid = decodeURIComponent(urlParams.get("user") ?? "");
95
- // If we have authentication parameters, attempt login
96
- if (userDid && window.renown && window.renownCrypto) {
97
- try {
98
- await login(userDid, window.renown, window.renownCrypto);
99
- // Clean up URL parameters
100
- const cleanUrl = new URL(window.location.href);
101
- cleanUrl.searchParams.delete("user");
102
- window.history.replaceState({}, "", cleanUrl.toString());
103
- }
104
- catch (error) {
105
- console.error("Failed to handle Renown return:", error);
106
- }
107
- }
108
- }
109
- export async function login(userDid, renown, renownCrypto) {
110
- if (!renown || !renownCrypto) {
111
- return;
112
- }
113
- // Validate that userDid is a valid pkh DID format
114
- if (userDid && !userDid.startsWith("did:pkh:")) {
115
- console.warn("Invalid DID format for login:", userDid, "- expected did:pkh: format");
116
- return;
117
- }
118
- try {
119
- const user = renown.user;
120
- if (user?.did && (user.did === userDid || !userDid)) {
121
- // Fetch profile data for the user
122
- const userWithProfile = await fetchProfileDataForUser(user);
123
- // Set up JWT handler if reactor is available
124
- // Store user data in sessionStorage for persistence
125
- SessionStorageManager.setUserData({
126
- user: userWithProfile,
127
- userDid: userWithProfile.did,
128
- loginStatus: "authorized",
129
- timestamp: Date.now(),
130
- });
131
- return userWithProfile;
132
- }
133
- if (!userDid) {
134
- return;
135
- }
136
- const newUser = await renown.login(userDid);
137
- // Fetch profile data for the user
138
- const userWithProfile = await fetchProfileDataForUser(newUser);
139
- // Set up JWT handler if reactor is available
140
- // Store user data in sessionStorage for persistence
141
- SessionStorageManager.setUserData({
142
- user: userWithProfile,
143
- userDid: userWithProfile.did,
144
- loginStatus: "authorized",
145
- timestamp: Date.now(),
146
- });
147
- return userWithProfile;
148
- }
149
- catch (error) {
150
- console.error("Renown login error:", error);
151
- throw error;
152
- }
153
- }
154
- export async function logout() {
155
- const renown = window.renown;
156
- const reactor = window.reactor;
157
- // Clear sessionStorage data
158
- SessionStorageManager.clearUserData();
159
- await renown?.logout();
160
- reactor?.removeJwtHandler();
161
- }
162
- /**
163
- * Re-authenticate using stored session data
164
- * This allows calling renown.login without needing to go through the full auth flow again
165
- */
166
- export async function reauthenticateFromSession() {
167
- if (typeof window === "undefined" || !window.renown || !window.renownCrypto) {
168
- return null;
169
- }
170
- const storedUserDid = SessionStorageManager.getStoredUserDid();
171
- if (!storedUserDid) {
172
- return null;
173
- }
174
- try {
175
- const currentUser = await login(storedUserDid, window.renown, window.renownCrypto);
176
- if (currentUser) {
177
- // Fetch profile data for the restored user
178
- const userWithProfile = await fetchProfileDataForUser(currentUser);
179
- return userWithProfile;
180
- }
181
- return null;
182
- }
183
- catch (error) {
184
- console.error("Failed to re-authenticate from session:", error);
185
- return null;
186
- }
187
- }
188
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/lib/renown/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAChF,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AA4B3D,wDAAwD;AACxD,KAAK,UAAU,0BAA0B,CACvC,UAAkB;IAElB,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,UA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AC"}
@@ -1,40 +0,0 @@
1
- import type { User } from "./renown/utils.js";
2
- export interface SessionUserData {
3
- user: User;
4
- userDid: string;
5
- loginStatus: "authorized";
6
- timestamp: number;
7
- }
8
- /**
9
- * Session storage utilities for Renown authentication
10
- * Stores user data in sessionStorage to persist across page reloads
11
- * but clears when the browser session ends
12
- */
13
- export declare class SessionStorageManager {
14
- /**
15
- * Store user authentication data in sessionStorage
16
- */
17
- static setUserData(userData: SessionUserData): void;
18
- /**
19
- * Retrieve user authentication data from sessionStorage
20
- */
21
- static getUserData(): SessionUserData | null;
22
- /**
23
- * Check if user data exists in sessionStorage
24
- */
25
- static hasUserData(): boolean;
26
- /**
27
- * Clear all user authentication data from sessionStorage
28
- */
29
- static clearUserData(): void;
30
- /**
31
- * Check if stored user data is still valid (not expired)
32
- * You can implement expiration logic here if needed
33
- */
34
- static isUserDataValid(userData: SessionUserData): boolean;
35
- /**
36
- * Get the stored user DID for easy re-authentication
37
- */
38
- static getStoredUserDid(): string | null;
39
- }
40
- //# sourceMappingURL=session-storage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"session-storage.d.ts","sourceRoot":"","sources":["../../../src/lib/session-storage.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAQ9C,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,YAAY,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,qBAAa,qBAAqB;IAChC;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI;IAmBnD;;OAEG;IACH,MAAM,CAAC,WAAW,IAAI,eAAe,GAAG,IAAI;IA8B5C;;OAEG;IACH,MAAM,CAAC,WAAW,IAAI,OAAO;IAU7B;;OAEG;IACH,MAAM,CAAC,aAAa,IAAI,IAAI;IAa5B;;;OAGG;IACH,MAAM,CAAC,eAAe,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO;IAM1D;;OAEG;IACH,MAAM,CAAC,gBAAgB,IAAI,MAAM,GAAG,IAAI;CAUzC"}
@@ -1,107 +0,0 @@
1
- "use client";
2
- const SESSION_STORAGE_KEYS = {
3
- USER: "renown_user",
4
- LOGIN_STATUS: "renown_login_status",
5
- USER_DID: "renown_user_did",
6
- };
7
- /**
8
- * Session storage utilities for Renown authentication
9
- * Stores user data in sessionStorage to persist across page reloads
10
- * but clears when the browser session ends
11
- */
12
- export class SessionStorageManager {
13
- /**
14
- * Store user authentication data in sessionStorage
15
- */
16
- static setUserData(userData) {
17
- if (typeof window === "undefined")
18
- return;
19
- try {
20
- sessionStorage.setItem(SESSION_STORAGE_KEYS.USER, JSON.stringify(userData.user));
21
- sessionStorage.setItem(SESSION_STORAGE_KEYS.USER_DID, userData.userDid);
22
- sessionStorage.setItem(SESSION_STORAGE_KEYS.LOGIN_STATUS, userData.loginStatus);
23
- sessionStorage.setItem("renown_timestamp", userData.timestamp.toString());
24
- }
25
- catch (error) {
26
- console.error("Failed to store user data in sessionStorage:", error);
27
- }
28
- }
29
- /**
30
- * Retrieve user authentication data from sessionStorage
31
- */
32
- static getUserData() {
33
- if (typeof window === "undefined")
34
- return null;
35
- try {
36
- const userStr = sessionStorage.getItem(SESSION_STORAGE_KEYS.USER);
37
- const userDid = sessionStorage.getItem(SESSION_STORAGE_KEYS.USER_DID);
38
- const loginStatus = sessionStorage.getItem(SESSION_STORAGE_KEYS.LOGIN_STATUS);
39
- const timestampStr = sessionStorage.getItem("renown_timestamp");
40
- if (!userStr || !userDid || !loginStatus || !timestampStr) {
41
- return null;
42
- }
43
- const user = JSON.parse(userStr);
44
- const timestamp = parseInt(timestampStr, 10);
45
- return {
46
- user,
47
- userDid,
48
- loginStatus: loginStatus,
49
- timestamp,
50
- };
51
- }
52
- catch (error) {
53
- console.error("Failed to retrieve user data from sessionStorage:", error);
54
- return null;
55
- }
56
- }
57
- /**
58
- * Check if user data exists in sessionStorage
59
- */
60
- static hasUserData() {
61
- if (typeof window === "undefined")
62
- return false;
63
- return !!(sessionStorage.getItem(SESSION_STORAGE_KEYS.USER) &&
64
- sessionStorage.getItem(SESSION_STORAGE_KEYS.USER_DID) &&
65
- sessionStorage.getItem(SESSION_STORAGE_KEYS.LOGIN_STATUS));
66
- }
67
- /**
68
- * Clear all user authentication data from sessionStorage
69
- */
70
- static clearUserData() {
71
- if (typeof window === "undefined")
72
- return;
73
- try {
74
- sessionStorage.removeItem(SESSION_STORAGE_KEYS.USER);
75
- sessionStorage.removeItem(SESSION_STORAGE_KEYS.USER_DID);
76
- sessionStorage.removeItem(SESSION_STORAGE_KEYS.LOGIN_STATUS);
77
- sessionStorage.removeItem("renown_timestamp");
78
- }
79
- catch (error) {
80
- console.error("Failed to clear user data from sessionStorage:", error);
81
- }
82
- }
83
- /**
84
- * Check if stored user data is still valid (not expired)
85
- * You can implement expiration logic here if needed
86
- */
87
- static isUserDataValid(userData) {
88
- // For now, we consider session data valid for the entire browser session
89
- // You can add expiration logic here if needed
90
- return true;
91
- }
92
- /**
93
- * Get the stored user DID for easy re-authentication
94
- */
95
- static getStoredUserDid() {
96
- if (typeof window === "undefined")
97
- return null;
98
- try {
99
- return sessionStorage.getItem(SESSION_STORAGE_KEYS.USER_DID);
100
- }
101
- catch (error) {
102
- console.error("Failed to get stored user DID:", error);
103
- return null;
104
- }
105
- }
106
- }
107
- //# sourceMappingURL=session-storage.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"session-storage.js","sourceRoot":"","sources":["../../../src/lib/session-storage.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAIb,MAAM,oBAAoB,GAAG;IAC3B,IAAI,EAAE,aAAa;IACnB,YAAY,EAAE,qBAAqB;IACnC,QAAQ,EAAE,iBAAiB;CACnB,CAAC;AASX;;;;GAIG;AACH,MAAM,OAAO,qBAAqB;IAChC;;OAEG;IACH,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,gBAAgB;QACrB,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO,IAAI,CAAC;QAE/C,IAAI,CAAC;YACH,OAAO,cAAc,CAAC,OAAO,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;QAC/D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAC;YACvD,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;CACF"}
@@ -1,10 +0,0 @@
1
- export * from "./common.js";
2
- export * from "./crypto/index.js";
3
- export * from "./crypto/node-key-storage.js";
4
- export * from "./renown-builder.js";
5
- export * from "./event/event.node.js";
6
- export * from "./init.node.js";
7
- export * from "./storage/storage.node.js";
8
- export * from "./types.js";
9
- export * from "./utils.js";
10
- //# sourceMappingURL=node.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/node.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
package/dist/src/node.js DELETED
@@ -1,10 +0,0 @@
1
- export * from "./common.js";
2
- export * from "./crypto/index.js";
3
- export * from "./crypto/node-key-storage.js";
4
- export * from "./renown-builder.js";
5
- export * from "./event/event.node.js";
6
- export * from "./init.node.js";
7
- export * from "./storage/storage.node.js";
8
- export * from "./types.js";
9
- export * from "./utils.js";
10
- //# sourceMappingURL=node.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/node.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
@@ -1,3 +0,0 @@
1
- export { RenownUserProvider, RenownUserContext, } from "./renown-user-provider.js";
2
- export type { RenownUserContextValue } from "./renown-user-provider.js";
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,2BAA2B,CAAC;AACnC,YAAY,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC"}
@@ -1,2 +0,0 @@
1
- export { RenownUserProvider, RenownUserContext, } from "./renown-user-provider.js";
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,2BAA2B,CAAC"}
@@ -1,76 +0,0 @@
1
- import type { IRenownCrypto } from "../crypto/index.js";
2
- import type { LoginStatus, User } from "../lib/renown/index.js";
3
- import type { IRenown } from "../types.js";
4
- export interface RenownUserContextValue {
5
- /** Current authenticated user, null if not authenticated */
6
- user: User | null;
7
- /** Current login status */
8
- loginStatus: LoginStatus;
9
- /** Whether auth operations are in progress */
10
- isLoading: boolean;
11
- /** Whether the user system has been initialized */
12
- isInitialized: boolean;
13
- /** Login with optional DID (defaults to renownCrypto DID) */
14
- login: (userDid?: string) => Promise<void>;
15
- /** Logout the current user */
16
- logout: () => Promise<void>;
17
- /** Open Renown portal for authentication */
18
- openRenown: () => void;
19
- /** RenownCrypto instance for cryptographic operations */
20
- renownCrypto: IRenownCrypto | null;
21
- /** Renown SDK instance */
22
- renown: IRenown | null;
23
- }
24
- export declare const RenownUserContext: import("react").Context<RenownUserContextValue | null>;
25
- interface RenownUserProviderProps {
26
- children: React.ReactNode;
27
- /**
28
- * Name of the application. Will be part of the credential.
29
- */
30
- appName?: string;
31
- /**
32
- * Renown service URL
33
- * @default 'https://www.renown.id'
34
- */
35
- renownUrl?: string;
36
- /**
37
- * Network ID (e.g., 'eip155')
38
- * @default 'eip155'
39
- */
40
- networkId?: string;
41
- /**
42
- * Chain ID (e.g., '1' for Ethereum mainnet)
43
- * @default '1'
44
- */
45
- chainId?: string;
46
- /**
47
- * Custom loading component shown during initialization
48
- * If not provided, renders children immediately (no loading screen)
49
- */
50
- loadingComponent?: React.ReactNode;
51
- /**
52
- * Custom error component shown if initialization fails
53
- * Receives the error and a retry function
54
- */
55
- errorComponent?: (error: Error, retry: () => void) => React.ReactNode;
56
- }
57
- /**
58
- * RenownUserProvider - Central user provider for Renown
59
- *
60
- * Automatically initializes the Renown SDK and provides user state.
61
- * Handles initialization, login, logout, and session management.
62
- *
63
- * Usage:
64
- * ```tsx
65
- * // Wrap your app
66
- * <RenownUserProvider renownUrl="https://www.renown.id">
67
- * <YourApp />
68
- * </RenownUserProvider>
69
- *
70
- * // In any component
71
- * const { user, login, logout } = useUser()
72
- * ```
73
- */
74
- export declare function RenownUserProvider({ children, appName, renownUrl, networkId, chainId, loadingComponent, errorComponent, }: RenownUserProviderProps): import("react/jsx-runtime").JSX.Element;
75
- export {};
76
- //# sourceMappingURL=renown-user-provider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"renown-user-provider.d.ts","sourceRoot":"","sources":["../../../src/providers/renown-user-provider.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGxD,OAAO,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAShE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CA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