@welshare/react 0.3.0 → 0.5.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 (53) hide show
  1. package/README.md +37 -48
  2. package/dist/esm/components/connect-button.d.ts.map +1 -1
  3. package/dist/esm/components/connect-button.js +1 -4
  4. package/dist/esm/components/welshare-logo.d.ts +1 -1
  5. package/dist/esm/hooks/use-welshare.d.ts.map +1 -1
  6. package/dist/esm/hooks/use-welshare.js +11 -8
  7. package/dist/esm/index.d.ts +1 -2
  8. package/dist/esm/index.d.ts.map +1 -1
  9. package/dist/esm/index.js +3 -3
  10. package/dist/esm/lib/uploads.d.ts +1 -1
  11. package/dist/esm/lib/uploads.d.ts.map +1 -1
  12. package/dist/esm/lib/uploads.js +2 -4
  13. package/dist/esm/types.d.ts +1 -1
  14. package/dist/esm/types.d.ts.map +1 -1
  15. package/dist/node_modules/@welshare/react/.turbo/turbo-lint.log +14 -0
  16. package/dist/node_modules/@welshare/react/README.md +37 -48
  17. package/dist/node_modules/@welshare/react/dist/esm/components/connect-button.d.ts.map +1 -1
  18. package/dist/node_modules/@welshare/react/dist/esm/components/connect-button.js +1 -4
  19. package/dist/node_modules/@welshare/react/dist/esm/components/welshare-logo.d.ts +1 -1
  20. package/dist/node_modules/@welshare/react/dist/esm/hooks/use-welshare.d.ts.map +1 -1
  21. package/dist/node_modules/@welshare/react/dist/esm/hooks/use-welshare.js +11 -8
  22. package/dist/node_modules/@welshare/react/dist/esm/index.d.ts +1 -2
  23. package/dist/node_modules/@welshare/react/dist/esm/index.d.ts.map +1 -1
  24. package/dist/node_modules/@welshare/react/dist/esm/index.js +3 -3
  25. package/dist/node_modules/@welshare/react/dist/esm/lib/uploads.d.ts +1 -1
  26. package/dist/node_modules/@welshare/react/dist/esm/lib/uploads.d.ts.map +1 -1
  27. package/dist/node_modules/@welshare/react/dist/esm/lib/uploads.js +2 -4
  28. package/dist/node_modules/@welshare/react/dist/esm/types.d.ts +1 -1
  29. package/dist/node_modules/@welshare/react/dist/esm/types.d.ts.map +1 -1
  30. package/dist/node_modules/@welshare/react/eslint.config.mjs +2 -2
  31. package/dist/node_modules/@welshare/react/package.json +1 -8
  32. package/dist/node_modules/@welshare/react/src/components/connect-button.tsx +1 -4
  33. package/dist/node_modules/@welshare/react/src/components/welshare-logo.tsx +1 -1
  34. package/dist/node_modules/@welshare/react/src/hooks/use-welshare.ts +18 -10
  35. package/dist/node_modules/@welshare/react/src/index.ts +8 -4
  36. package/dist/node_modules/@welshare/react/src/lib/uploads.ts +4 -6
  37. package/dist/node_modules/@welshare/react/src/types.ts +12 -11
  38. package/dist/node_modules/@welshare/react/tsconfig.json +3 -12
  39. package/package.json +2 -9
  40. package/dist/esm/lib/encryption.d.ts +0 -9
  41. package/dist/esm/lib/encryption.d.ts.map +0 -1
  42. package/dist/esm/lib/encryption.js +0 -54
  43. package/dist/esm/utils.d.ts +0 -12
  44. package/dist/esm/utils.d.ts.map +0 -1
  45. package/dist/esm/utils.js +0 -8
  46. package/dist/node_modules/@welshare/react/dist/esm/lib/encryption.d.ts +0 -9
  47. package/dist/node_modules/@welshare/react/dist/esm/lib/encryption.d.ts.map +0 -1
  48. package/dist/node_modules/@welshare/react/dist/esm/lib/encryption.js +0 -54
  49. package/dist/node_modules/@welshare/react/dist/esm/utils.d.ts +0 -12
  50. package/dist/node_modules/@welshare/react/dist/esm/utils.d.ts.map +0 -1
  51. package/dist/node_modules/@welshare/react/dist/esm/utils.js +0 -8
  52. package/dist/node_modules/@welshare/react/src/lib/encryption.ts +0 -89
  53. package/dist/node_modules/@welshare/react/src/utils.ts +0 -22
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ### Disclaimer, notes on maturity
4
4
 
5
- This library is in Alpha / demo state at this moment. We're using it to review the security aspects while data is in transfer and in rest. There's absolutely no guarantee or warrant that at this point any data is safe. All data can be lost at any time - even though we're using resources that puts decentralization and resilience values to the front. Be **very** careful if you're integrating this into user facing code. Welshare Health wallets are controlled by cryptographic material which _can_ be stored in non custodial / MPC environments (Privy). While that's considered very safe, we can't guarantee at this point that we've already got each aspect of inter application communication or key derivation features right, so don't connect wallets that store significant value with the welshare wallet yet.
5
+ This library is in Alpha / demo state at this moment. We're using it to review the security aspects while data is in transfer and in rest. There's absolutely no guarantee or warrant that at this point any data is safe, even though we're using resources that prioritize decentralization and resilience. Welshare Health wallets are controlled by cryptographic material which _can_ be stored in non custodial / MPC environments (Privy). While that's considered very safe, we can't guarantee at this point that we've already got each aspect of inter application communication or key derivation features right, so don't connect wallets that store significant value with the welshare wallet yet.
6
6
 
7
7
  ## Purpose
8
8
 
@@ -32,9 +32,10 @@ If you want to submit questionnaire data, your application must first register a
32
32
 
33
33
  At the moment there are only two supported submission types: Fhir compatible QuestionnaireResponses and our custom "Reflex" app submissions. Both types are identified by schema uids that are accessible on the `Schemas` export.
34
34
 
35
- ```
35
+ ```js
36
36
  export const Schemas = {
37
- QuestionnaireResponse: "b14b538f-7de3-4767-ad77-464d755d78bd"
37
+ QuestionnaireResponse: "b14b538f-7de3-4767-ad77-464d755d78bd",
38
+ BinaryFile: "9d696baf-483f-4cc0-b748-23a22c1705f5",
38
39
  };
39
40
  ```
40
41
 
@@ -83,46 +84,40 @@ export function QuestionnaireForm() {
83
84
 
84
85
  ### Binary file uploads (e.g. images)
85
86
 
86
- binary file uploads require a lot of back and forth with the wallet dialog that we wrapped into one convenient upload API. If you want to include binary uploads into your questionnaires, you would typically hook into your own form, upload the file using the `uploadFile` function exposed by the `useWelshare` hook and use the response information to in the respective questionnaire form answer item.
87
+ Before data hits any server, the SDK encrypts all files with a new random symmetric AES (GCM / 256 bits) key. Users request a presigned upload url and post the encrypted file to an S3 compatible API that's currently operated by Welshare. Ultimately, they encrypt the encryption key for a Nillion _owned_ BinaryData collection and store it across Nillion nodes (no single node can recover the key). At the time of insertion, they currently also grant ACL read rights for the application (Technically, this is the welshare builder keypair at the moment).
87
88
 
88
- Each download should contain a reference to the resource that initiated its upload. As Welshare right now is mostly about questionnaires, you should use a combination of the resource type (questionnaire), the questionnaire id and the answer item's id
89
+ #### Upload via Wallet Dialog
89
90
 
90
91
  ```ts
91
- const reference = `questionnaire/${questionnaireId}/${answerItemId}`;
92
+ const { isConnected, openWallet, uploadFile, submitData } = useWelshare({
93
+ applicationId: process.env.NEXT_PUBLIC_WELSHARE_APP_ID || "",
94
+ });
95
+
96
+ // Upload file (wallet dialog handles auth)
97
+ const { url: uploadedFileUrl, binaryFileUid } = await uploadFile(
98
+ userFile,
99
+ `questionnaire/${questionnaireId}/${linkId}`
100
+ );
101
+
102
+ // Use in QuestionnaireResponse
103
+ const responseItem = {
104
+ answer: [
105
+ {
106
+ valueAttachment: {
107
+ id: binaryFileUid,
108
+ contentType: userFile.type,
109
+ size: userFile.size,
110
+ title: userFile.name,
111
+ url: uploadedFileUrl,
112
+ },
113
+ },
114
+ ],
115
+ };
92
116
  ```
93
117
 
94
- Binary files are addressed as items of type `valueAttachment` in Fhir. See https://www.hl7.org/fhir/questionnaireresponse.html
95
-
96
- Before uploading, welshare encrypts all files with a new random symmetric AES (GCM / 256 bits) key. Users request a presigned upload url and post the encrypted file to an S3 compatible API of ours. Finally, they encrypt the encryption key on a user controlled Nillion *owned* collection for binary data and grant respective access rights for the application. The application a user used to upload the file is by default able to download the file again (Technically, that application is always welshare right now. This will change to the "builder" address of the respective app and the hpmp enclave keys, which allow AI access to the files)
118
+ Binary files are addressed as `valueAttachment` items in FHIR. See https://www.hl7.org/fhir/questionnaireresponse.html
97
119
 
98
- Here's an example how to use it:
99
-
100
- ```ts
101
- const { isConnected, openWallet, uploadFile, submitData } = useWelshare({
102
- applicationId: process.env.NEXT_PUBLIC_WELSHARE_APP_ID || ""
103
- })
104
- //... let users select a file on their box
105
-
106
- const { url: uploadedFileUrl, binaryFileUid } = await uploadFile(
107
- userFile,
108
- reference: `questionnaire/${questionnaireId}/<linkId>`
109
- );
110
-
111
- const responseItem = {
112
- answer = [
113
- {
114
- valueAttachment: {
115
- id: binaryFileUid,
116
- contentType: userFile.type,
117
- size: userFile.size,
118
- title: userFile.name,
119
- url: uploadedFileUrl,
120
- },
121
- },
122
- ];
123
- }
124
- // insert the responseItem into your QuestionnaireResponse
125
- ```
120
+ For applications that manage storage keypairs directly and need more control over the upload process, see the [Binary File Uploads section in the SDK documentation](../welshare/README.md#binary-file-uploads).
126
121
 
127
122
  ## API
128
123
 
@@ -143,21 +138,15 @@ those are configured in the `useWelshare` options parameter and called back duri
143
138
 
144
139
  ## Security Notes
145
140
 
146
- No part of this application deals with a "blockchain" directly (Nillion nodes are validated by a custom chain but that's not a fact relevant for end users' security in this scope).
147
-
148
- The EVM addresses that control a user profile are (supposedly) never leaked to a third party.
149
-
150
- The key derivation mechanism that creates new storage keys that users use to sign messages is not guaranteed to be 100% sound. At this moment it's used as a cryptographic authenticator, but the derivation mechanism will change in the future, rendering already existing keys obsolete. We're not guaranteeing that your key material stays trivially derivable.
141
+ No part of this application interacts with a "blockchain" (Nillion nodes are validated by a custom chain but that's relevant for end users' security or privacy).
151
142
 
152
- Data is stored on [nilDB (by Nillion)](https://docs.nillion.com/build/private-storage/quickstart), a system that can enforces access control, encryption at rest and storage redundancy. While technically possible, the current library does not MPC-encrypt any information. The data is sent to nilDB by a _user client_ that's controlled by the user's own key material. Welshare only delegates NUCs (access rights) to the users. Right now the welshare builder _can_ read any data users upload. This concept will eventually change - welshare's goal is to only make user originated information available inside trusted execution environments.
143
+ The EVM addresses that control a user profile are never disclosed to third parties, hence they cannot correlate the wallet control keys with the keys that control the actual data.
153
144
 
154
- ## Development
145
+ The key derivation mechanism is used for creating self signed cryptographic authentication tokens, but the mechanism that keys are derived will very likely change in the future. Existing keys might render obsolete at that point which will require users to manually migrate their data. We don't guarantee that the current key derivation mechanism will be part of this SDK's exposed feature set forever. However, users will always be able to derive keys on their own, as long as they know the rules and don't lose the required secret inputs (e.g. signing keys or salts).
155
146
 
156
- This package is built using:
147
+ Data is stored on [nilDB (by Nillion)](https://docs.nillion.com/build/private-storage/quickstart), a protocol that enforces access control lists, encrypts data at rest and stores records redundantly. Plain data documents are not generally encrypted at this point in time, however. Binary uploads are end to end encrypted in the way that's described above.
157
148
 
158
- - TypeScript
159
- - Tshy for build management
160
- - Vitest for testing
149
+ All data that's sent to nilDB via _user client_ is exclusively controlled by the user's own key material. Welshare only delegates NUCs (access rights) to the users. Be aware that right now the welshare builder key _can_ read any data users upload. This will structurally improve once Nillion supports delegated reads for non builder grantees. Welshare's goal is to make user originated information available exclusively for code that runs in execution environments trusted by the users.
161
150
 
162
151
  ## License
163
152
 
@@ -1 +1 @@
1
- {"version":3,"file":"connect-button.d.ts","sourceRoot":"","sources":["../../../src/components/connect-button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,eAAO,MAAM,qBAAqB,UAAW;IAC3C,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B,4CAiGA,CAAC"}
1
+ {"version":3,"file":"connect-button.d.ts","sourceRoot":"","sources":["../../../src/components/connect-button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,eAAO,MAAM,qBAAqB,UAAW;IAC3C,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B,4CA8FA,CAAC"}
@@ -55,8 +55,5 @@ export const ConnectWelshareButton = (props) => {
55
55
  const handleBlur = (e) => {
56
56
  e.currentTarget.style.boxShadow = "0 2px 6px rgba(1, 152, 255, 0.2)";
57
57
  };
58
- return (_jsx("button", { onClick: props.openWallet, style: buttonStyles, onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, onMouseDown: handleMouseDown, onFocus: handleFocus, onBlur: handleBlur, type: "button", children: _jsx(_Fragment, { children: props.children || (_jsxs(_Fragment, { children: [_jsx("span", { className: "", children: _jsx(WelshareLogo, { width: 24, height: 18, style: {
59
- "marginRight": "4px",
60
- color: "#ffffff",
61
- } }) }), _jsx("span", { children: "Connect Welshare Profile" })] })) }) }));
58
+ return (_jsx("button", { onClick: props.openWallet, style: buttonStyles, onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, onMouseDown: handleMouseDown, onFocus: handleFocus, onBlur: handleBlur, type: "button", children: _jsx(_Fragment, { children: props.children || (_jsxs(_Fragment, { children: [_jsx("span", { className: "", children: _jsx(WelshareLogo, { width: 24, height: 18, style: { marginRight: "4px", color: "#ffffff" } }) }), _jsx("span", { children: "Connect Welshare Profile" })] })) }) }));
62
59
  };
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React from "react";
2
2
  export interface WelshareLogoProps {
3
3
  className?: string;
4
4
  style?: React.CSSProperties;
@@ -1 +1 @@
1
- {"version":3,"file":"use-welshare.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-welshare.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,iBAAiB,EACjB,kBAAkB,EAElB,yBAAyB,EAC1B,MAAM,YAAY,CAAC;AAKpB,eAAO,MAAM,WAAW,UAAW,yBAAyB;;;;;uBAwLlD,IAAI,aACC,MAAM,KAChB,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAE,CAAC;iBA0C9B,CAAC,YACT,kBAAkB,cAChB,iBAAiB,CAAC,CAAC,CAAC;;;CAqEnC,CAAC"}
1
+ {"version":3,"file":"use-welshare.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-welshare.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,iBAAiB,EACjB,kBAAkB,EAElB,yBAAyB,EAC1B,MAAM,YAAY,CAAC;AAQpB,eAAO,MAAM,WAAW,UAAW,yBAAyB;;;;;uBA8LlD,IAAI,aACC,MAAM,KAChB,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAE,CAAC;iBAuC9B,CAAC,YACT,kBAAkB,cAChB,iBAAiB,CAAC,CAAC,CAAC;;;CAuEnC,CAAC"}
@@ -1,4 +1,4 @@
1
- import { getBaseUrl, WELSHARE_API_ENVIRONMENT } from "@welshare/sdk/environment";
1
+ import { getBaseUrl, WELSHARE_API_ENVIRONMENT, } from "@welshare/sdk/environment";
2
2
  import { useEffect, useRef, useState } from "react";
3
3
  import { encryptAndUploadFile } from "../lib/uploads.js";
4
4
  export const useWelshare = (props) => {
@@ -13,7 +13,7 @@ export const useWelshare = (props) => {
13
13
  // Resolve the base URL from environment or apiBaseUrl
14
14
  const resolvedBaseUrl = props.environment
15
15
  ? getBaseUrl(props.environment)
16
- : props.apiBaseUrl ?? getBaseUrl(WELSHARE_API_ENVIRONMENT.production);
16
+ : (props.apiBaseUrl ?? getBaseUrl(WELSHARE_API_ENVIRONMENT.production));
17
17
  const options = {
18
18
  ...props,
19
19
  apiBaseUrl: resolvedBaseUrl,
@@ -133,7 +133,13 @@ export const useWelshare = (props) => {
133
133
  return () => {
134
134
  window.removeEventListener("message", handleMessage);
135
135
  };
136
- }, [WELSHARE_WALLET_URL, dialogWindow, messageIdCounter, options.applicationId, options.callbacks]);
136
+ }, [
137
+ WELSHARE_WALLET_URL,
138
+ dialogWindow,
139
+ messageIdCounter,
140
+ options.applicationId,
141
+ options.callbacks,
142
+ ]);
137
143
  /**
138
144
  * Starts a file upload and returns a promise that resolves with the uploaded file URL
139
145
  * @param file The file to upload
@@ -164,10 +170,7 @@ export const useWelshare = (props) => {
164
170
  const message = {
165
171
  type: "REQUEST_UPLOAD_CREDENTIALS",
166
172
  id: String(messageIdCounter),
167
- payload: {
168
- ...payload,
169
- applicationId: options.applicationId,
170
- },
173
+ payload: { ...payload, applicationId: options.applicationId },
171
174
  };
172
175
  dialogWindow.postMessage(message, WELSHARE_WALLET_URL);
173
176
  setMessageIdCounter((prev) => prev + 1);
@@ -212,7 +215,7 @@ export const useWelshare = (props) => {
212
215
  .filter(([_, value]) => value !== undefined && value !== null)
213
216
  .map(([key, value]) => `social.${key}=${encodeURIComponent(String(value))}`);
214
217
  if (socialEntries.length > 0) {
215
- socialParams = `&${socialEntries.join('&')}`;
218
+ socialParams = `&${socialEntries.join("&")}`;
216
219
  }
217
220
  }
218
221
  const walletUrl = `${WELSHARE_WALLET_URL}?applicationId=${options.applicationId}${socialParams}`;
@@ -2,8 +2,7 @@ export { ConnectWelshareButton } from "./components/connect-button.js";
2
2
  export { WelshareLogo } from "./components/welshare-logo.js";
3
3
  export { useWelshare } from "./hooks/use-welshare.js";
4
4
  export { WELSHARE_API_ENVIRONMENT, resolveEnvironment, getBaseUrl, type WelshareApiEnvironment, type WelshareEnvironmentName, type NillionClusterConfig, } from "@welshare/sdk/environment";
5
- export { decrypt, encodeEncryptionKey, encryptFile, generateRandomAESKey } from "./lib/encryption.js";
6
- export { decodeEncryptionKey, type EncryptionKey } from "./utils.js";
5
+ export { decrypt, encodeEncryptionKey, encryptFile, generateRandomAESKey, decodeEncryptionKey, ALGORITHM, type EncryptionKey, type Algorithm, } from "@welshare/sdk";
7
6
  export { browserDownload, encryptAndUploadFile } from "./lib/uploads.js";
8
7
  export declare const Schemas: {
9
8
  QuestionnaireResponse: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAG7D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGtD,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,UAAU,EACV,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,GAC1B,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EACL,OAAO,EACP,mBAAmB,EACnB,WAAW,EACX,oBAAoB,EACrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAErE,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAGzE,eAAO,MAAM,OAAO;;;;CAInB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAG7D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGtD,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,UAAU,EACV,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,GAC1B,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EACL,OAAO,EACP,mBAAmB,EACnB,WAAW,EACX,oBAAoB,EACpB,mBAAmB,EACnB,SAAS,EACT,KAAK,aAAa,EAClB,KAAK,SAAS,GACf,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAGzE,eAAO,MAAM,OAAO;;;;CAInB,CAAC"}
package/dist/esm/index.js CHANGED
@@ -5,9 +5,9 @@ export { WelshareLogo } from "./components/welshare-logo.js";
5
5
  export { useWelshare } from "./hooks/use-welshare.js";
6
6
  // ---- Environment (re-exported from @welshare/sdk) ----
7
7
  export { WELSHARE_API_ENVIRONMENT, resolveEnvironment, getBaseUrl, } from "@welshare/sdk/environment";
8
- // ---- Utils ----
9
- export { decrypt, encodeEncryptionKey, encryptFile, generateRandomAESKey } from "./lib/encryption.js";
10
- export { decodeEncryptionKey } from "./utils.js";
8
+ // ---- Encryption utilities (re-exported from @welshare/sdk) ----
9
+ export { decrypt, encodeEncryptionKey, encryptFile, generateRandomAESKey, decodeEncryptionKey, ALGORITHM, } from "@welshare/sdk";
10
+ // ---- Upload utilities (local, for frame-based upload flow) ----
11
11
  export { browserDownload, encryptAndUploadFile } from "./lib/uploads.js";
12
12
  //todo: import them from the SDK
13
13
  export const Schemas = {
@@ -1,4 +1,4 @@
1
- import { EncryptionKey } from "@/utils.js";
1
+ import { type EncryptionKey } from "@welshare/sdk";
2
2
  export declare const encryptAndUploadFile: (file: File, presignedUrl: string) => Promise<EncryptionKey>;
3
3
  export declare const browserDownload: (decryptedFile: File) => void;
4
4
  //# sourceMappingURL=uploads.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"uploads.d.ts","sourceRoot":"","sources":["../../../src/lib/uploads.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAO3C,eAAO,MAAM,oBAAoB,SACzB,IAAI,gBACI,MAAM,KACnB,OAAO,CAAC,aAAa,CAkBvB,CAAC;AAEF,eAAO,MAAM,eAAe,kBAAmB,IAAI,SASlD,CAAA"}
1
+ {"version":3,"file":"uploads.d.ts","sourceRoot":"","sources":["../../../src/lib/uploads.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAInB,MAAM,eAAe,CAAC;AAEvB,eAAO,MAAM,oBAAoB,SACzB,IAAI,gBACI,MAAM,KACnB,OAAO,CAAC,aAAa,CAgBvB,CAAC;AAEF,eAAO,MAAM,eAAe,kBAAmB,IAAI,SASlD,CAAC"}
@@ -1,4 +1,4 @@
1
- import { encodeEncryptionKey, encryptFile, generateRandomAESKey, } from "./encryption.js";
1
+ import { encodeEncryptionKey, encryptFile, generateRandomAESKey, } from "@welshare/sdk";
2
2
  export const encryptAndUploadFile = async (file, presignedUrl) => {
3
3
  const encryptionKey = await generateRandomAESKey();
4
4
  const { encryptedData, iv } = await encryptFile(file, encryptionKey);
@@ -6,9 +6,7 @@ export const encryptAndUploadFile = async (file, presignedUrl) => {
6
6
  const uploadResponse = await fetch(presignedUrl, {
7
7
  method: "PUT",
8
8
  body: encryptedData,
9
- headers: {
10
- "Content-Type": file.type,
11
- },
9
+ headers: { "Content-Type": file.type },
12
10
  });
13
11
  if (!uploadResponse.ok) {
14
12
  throw new Error(`Failed to upload file ${uploadResponse.status}`);
@@ -1,4 +1,4 @@
1
- import { EncryptionKey } from "./utils.js";
1
+ import type { EncryptionKey } from "@welshare/sdk";
2
2
  import type { WelshareApiEnvironment, WelshareEnvironmentName } from "@welshare/sdk/environment";
3
3
  export interface DialogMessage {
4
4
  type: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEjG,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAA;AAEvC,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAClC,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,IAAI,CAAC;IAChB,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,UAAU,EAAE,CAAC,CAAC;CACf;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAA;AAED,MAAM,WAAW,+BAA+B;IAC9C,SAAS,CAAC,EAAE,IAAI,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,2BAA4B,SAAQ,+BAA+B;IAClF,aAAa,EAAE,aAAa,CAAC;IA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E;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,aAAa,EAAE,MAAM,CAAA;SAAE,KAAK,IAAI,CAAC;QAClE,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;KAChC,CAAC;CACH;AAED,MAAM,WAAW,2BAA4B,SAAQ,aAAa;IAChE,OAAO,EACH,iBAAiB,CAAC,OAAO,CAAC,GAC1B,2BAA2B,GAC3B,+BAA+B,CAAC;CACrC;AAED,MAAM,WAAW,yBAAyB;IACxC,aAAa,EAAE,MAAM,CAAC;IACtB,kBAAkB,CAAC,EAAE;QACnB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;IACF;;;;OAIG;IACH,WAAW,CAAC,EAAE,sBAAsB,GAAG,uBAAuB,CAAC;IAC/D;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE;QACT,cAAc,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;QAC5D,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,iBAAiB,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;QAC3D,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;QAClC,cAAc,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,IAAI,CAAC;QACjD,eAAe,CAAC,EAAE,MAAM,IAAI,CAAC;QAC7B,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;KAC5B,CAAC;CACH"}
@@ -0,0 +1,14 @@
1
+
2
+ > @welshare/react@0.4.0 lint /Users/stadolf/work/welshare/workspace/surveys-monorepo/packages/welshare-react
3
+ > eslint . --max-warnings 25
4
+
5
+
6
+ /Users/stadolf/work/welshare/workspace/surveys-monorepo/packages/welshare-react/src/hooks/use-welshare.ts
7
+ 110:11 warning Unexpected lexical declaration in case block no-case-declarations
8
+ 290:19 warning '_' is defined but never used @typescript-eslint/no-unused-vars
9
+
10
+ /Users/stadolf/work/welshare/workspace/surveys-monorepo/packages/welshare-react/src/types.ts
11
+ 9:13 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
12
+
13
+ ✖ 3 problems (0 errors, 3 warnings)
14
+
@@ -2,7 +2,7 @@
2
2
 
3
3
  ### Disclaimer, notes on maturity
4
4
 
5
- This library is in Alpha / demo state at this moment. We're using it to review the security aspects while data is in transfer and in rest. There's absolutely no guarantee or warrant that at this point any data is safe. All data can be lost at any time - even though we're using resources that puts decentralization and resilience values to the front. Be **very** careful if you're integrating this into user facing code. Welshare Health wallets are controlled by cryptographic material which _can_ be stored in non custodial / MPC environments (Privy). While that's considered very safe, we can't guarantee at this point that we've already got each aspect of inter application communication or key derivation features right, so don't connect wallets that store significant value with the welshare wallet yet.
5
+ This library is in Alpha / demo state at this moment. We're using it to review the security aspects while data is in transfer and in rest. There's absolutely no guarantee or warrant that at this point any data is safe, even though we're using resources that prioritize decentralization and resilience. Welshare Health wallets are controlled by cryptographic material which _can_ be stored in non custodial / MPC environments (Privy). While that's considered very safe, we can't guarantee at this point that we've already got each aspect of inter application communication or key derivation features right, so don't connect wallets that store significant value with the welshare wallet yet.
6
6
 
7
7
  ## Purpose
8
8
 
@@ -32,9 +32,10 @@ If you want to submit questionnaire data, your application must first register a
32
32
 
33
33
  At the moment there are only two supported submission types: Fhir compatible QuestionnaireResponses and our custom "Reflex" app submissions. Both types are identified by schema uids that are accessible on the `Schemas` export.
34
34
 
35
- ```
35
+ ```js
36
36
  export const Schemas = {
37
- QuestionnaireResponse: "b14b538f-7de3-4767-ad77-464d755d78bd"
37
+ QuestionnaireResponse: "b14b538f-7de3-4767-ad77-464d755d78bd",
38
+ BinaryFile: "9d696baf-483f-4cc0-b748-23a22c1705f5",
38
39
  };
39
40
  ```
40
41
 
@@ -83,46 +84,40 @@ export function QuestionnaireForm() {
83
84
 
84
85
  ### Binary file uploads (e.g. images)
85
86
 
86
- binary file uploads require a lot of back and forth with the wallet dialog that we wrapped into one convenient upload API. If you want to include binary uploads into your questionnaires, you would typically hook into your own form, upload the file using the `uploadFile` function exposed by the `useWelshare` hook and use the response information to in the respective questionnaire form answer item.
87
+ Before data hits any server, the SDK encrypts all files with a new random symmetric AES (GCM / 256 bits) key. Users request a presigned upload url and post the encrypted file to an S3 compatible API that's currently operated by Welshare. Ultimately, they encrypt the encryption key for a Nillion _owned_ BinaryData collection and store it across Nillion nodes (no single node can recover the key). At the time of insertion, they currently also grant ACL read rights for the application (Technically, this is the welshare builder keypair at the moment).
87
88
 
88
- Each download should contain a reference to the resource that initiated its upload. As Welshare right now is mostly about questionnaires, you should use a combination of the resource type (questionnaire), the questionnaire id and the answer item's id
89
+ #### Upload via Wallet Dialog
89
90
 
90
91
  ```ts
91
- const reference = `questionnaire/${questionnaireId}/${answerItemId}`;
92
+ const { isConnected, openWallet, uploadFile, submitData } = useWelshare({
93
+ applicationId: process.env.NEXT_PUBLIC_WELSHARE_APP_ID || "",
94
+ });
95
+
96
+ // Upload file (wallet dialog handles auth)
97
+ const { url: uploadedFileUrl, binaryFileUid } = await uploadFile(
98
+ userFile,
99
+ `questionnaire/${questionnaireId}/${linkId}`
100
+ );
101
+
102
+ // Use in QuestionnaireResponse
103
+ const responseItem = {
104
+ answer: [
105
+ {
106
+ valueAttachment: {
107
+ id: binaryFileUid,
108
+ contentType: userFile.type,
109
+ size: userFile.size,
110
+ title: userFile.name,
111
+ url: uploadedFileUrl,
112
+ },
113
+ },
114
+ ],
115
+ };
92
116
  ```
93
117
 
94
- Binary files are addressed as items of type `valueAttachment` in Fhir. See https://www.hl7.org/fhir/questionnaireresponse.html
95
-
96
- Before uploading, welshare encrypts all files with a new random symmetric AES (GCM / 256 bits) key. Users request a presigned upload url and post the encrypted file to an S3 compatible API of ours. Finally, they encrypt the encryption key on a user controlled Nillion *owned* collection for binary data and grant respective access rights for the application. The application a user used to upload the file is by default able to download the file again (Technically, that application is always welshare right now. This will change to the "builder" address of the respective app and the hpmp enclave keys, which allow AI access to the files)
118
+ Binary files are addressed as `valueAttachment` items in FHIR. See https://www.hl7.org/fhir/questionnaireresponse.html
97
119
 
98
- Here's an example how to use it:
99
-
100
- ```ts
101
- const { isConnected, openWallet, uploadFile, submitData } = useWelshare({
102
- applicationId: process.env.NEXT_PUBLIC_WELSHARE_APP_ID || ""
103
- })
104
- //... let users select a file on their box
105
-
106
- const { url: uploadedFileUrl, binaryFileUid } = await uploadFile(
107
- userFile,
108
- reference: `questionnaire/${questionnaireId}/<linkId>`
109
- );
110
-
111
- const responseItem = {
112
- answer = [
113
- {
114
- valueAttachment: {
115
- id: binaryFileUid,
116
- contentType: userFile.type,
117
- size: userFile.size,
118
- title: userFile.name,
119
- url: uploadedFileUrl,
120
- },
121
- },
122
- ];
123
- }
124
- // insert the responseItem into your QuestionnaireResponse
125
- ```
120
+ For applications that manage storage keypairs directly and need more control over the upload process, see the [Binary File Uploads section in the SDK documentation](../welshare/README.md#binary-file-uploads).
126
121
 
127
122
  ## API
128
123
 
@@ -143,21 +138,15 @@ those are configured in the `useWelshare` options parameter and called back duri
143
138
 
144
139
  ## Security Notes
145
140
 
146
- No part of this application deals with a "blockchain" directly (Nillion nodes are validated by a custom chain but that's not a fact relevant for end users' security in this scope).
147
-
148
- The EVM addresses that control a user profile are (supposedly) never leaked to a third party.
149
-
150
- The key derivation mechanism that creates new storage keys that users use to sign messages is not guaranteed to be 100% sound. At this moment it's used as a cryptographic authenticator, but the derivation mechanism will change in the future, rendering already existing keys obsolete. We're not guaranteeing that your key material stays trivially derivable.
141
+ No part of this application interacts with a "blockchain" (Nillion nodes are validated by a custom chain but that's relevant for end users' security or privacy).
151
142
 
152
- Data is stored on [nilDB (by Nillion)](https://docs.nillion.com/build/private-storage/quickstart), a system that can enforces access control, encryption at rest and storage redundancy. While technically possible, the current library does not MPC-encrypt any information. The data is sent to nilDB by a _user client_ that's controlled by the user's own key material. Welshare only delegates NUCs (access rights) to the users. Right now the welshare builder _can_ read any data users upload. This concept will eventually change - welshare's goal is to only make user originated information available inside trusted execution environments.
143
+ The EVM addresses that control a user profile are never disclosed to third parties, hence they cannot correlate the wallet control keys with the keys that control the actual data.
153
144
 
154
- ## Development
145
+ The key derivation mechanism is used for creating self signed cryptographic authentication tokens, but the mechanism that keys are derived will very likely change in the future. Existing keys might render obsolete at that point which will require users to manually migrate their data. We don't guarantee that the current key derivation mechanism will be part of this SDK's exposed feature set forever. However, users will always be able to derive keys on their own, as long as they know the rules and don't lose the required secret inputs (e.g. signing keys or salts).
155
146
 
156
- This package is built using:
147
+ Data is stored on [nilDB (by Nillion)](https://docs.nillion.com/build/private-storage/quickstart), a protocol that enforces access control lists, encrypts data at rest and stores records redundantly. Plain data documents are not generally encrypted at this point in time, however. Binary uploads are end to end encrypted in the way that's described above.
157
148
 
158
- - TypeScript
159
- - Tshy for build management
160
- - Vitest for testing
149
+ All data that's sent to nilDB via _user client_ is exclusively controlled by the user's own key material. Welshare only delegates NUCs (access rights) to the users. Be aware that right now the welshare builder key _can_ read any data users upload. This will structurally improve once Nillion supports delegated reads for non builder grantees. Welshare's goal is to make user originated information available exclusively for code that runs in execution environments trusted by the users.
161
150
 
162
151
  ## License
163
152
 
@@ -1 +1 @@
1
- {"version":3,"file":"connect-button.d.ts","sourceRoot":"","sources":["../../../src/components/connect-button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,eAAO,MAAM,qBAAqB,UAAW;IAC3C,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B,4CAiGA,CAAC"}
1
+ {"version":3,"file":"connect-button.d.ts","sourceRoot":"","sources":["../../../src/components/connect-button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,eAAO,MAAM,qBAAqB,UAAW;IAC3C,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B,4CA8FA,CAAC"}
@@ -55,8 +55,5 @@ export const ConnectWelshareButton = (props) => {
55
55
  const handleBlur = (e) => {
56
56
  e.currentTarget.style.boxShadow = "0 2px 6px rgba(1, 152, 255, 0.2)";
57
57
  };
58
- return (_jsx("button", { onClick: props.openWallet, style: buttonStyles, onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, onMouseDown: handleMouseDown, onFocus: handleFocus, onBlur: handleBlur, type: "button", children: _jsx(_Fragment, { children: props.children || (_jsxs(_Fragment, { children: [_jsx("span", { className: "", children: _jsx(WelshareLogo, { width: 24, height: 18, style: {
59
- "marginRight": "4px",
60
- color: "#ffffff",
61
- } }) }), _jsx("span", { children: "Connect Welshare Profile" })] })) }) }));
58
+ return (_jsx("button", { onClick: props.openWallet, style: buttonStyles, onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, onMouseDown: handleMouseDown, onFocus: handleFocus, onBlur: handleBlur, type: "button", children: _jsx(_Fragment, { children: props.children || (_jsxs(_Fragment, { children: [_jsx("span", { className: "", children: _jsx(WelshareLogo, { width: 24, height: 18, style: { marginRight: "4px", color: "#ffffff" } }) }), _jsx("span", { children: "Connect Welshare Profile" })] })) }) }));
62
59
  };
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React from "react";
2
2
  export interface WelshareLogoProps {
3
3
  className?: string;
4
4
  style?: React.CSSProperties;
@@ -1 +1 @@
1
- {"version":3,"file":"use-welshare.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-welshare.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,iBAAiB,EACjB,kBAAkB,EAElB,yBAAyB,EAC1B,MAAM,YAAY,CAAC;AAKpB,eAAO,MAAM,WAAW,UAAW,yBAAyB;;;;;uBAwLlD,IAAI,aACC,MAAM,KAChB,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAE,CAAC;iBA0C9B,CAAC,YACT,kBAAkB,cAChB,iBAAiB,CAAC,CAAC,CAAC;;;CAqEnC,CAAC"}
1
+ {"version":3,"file":"use-welshare.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-welshare.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,iBAAiB,EACjB,kBAAkB,EAElB,yBAAyB,EAC1B,MAAM,YAAY,CAAC;AAQpB,eAAO,MAAM,WAAW,UAAW,yBAAyB;;;;;uBA8LlD,IAAI,aACC,MAAM,KAChB,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAE,CAAC;iBAuC9B,CAAC,YACT,kBAAkB,cAChB,iBAAiB,CAAC,CAAC,CAAC;;;CAuEnC,CAAC"}
@@ -1,4 +1,4 @@
1
- import { getBaseUrl, WELSHARE_API_ENVIRONMENT } from "@welshare/sdk/environment";
1
+ import { getBaseUrl, WELSHARE_API_ENVIRONMENT, } from "@welshare/sdk/environment";
2
2
  import { useEffect, useRef, useState } from "react";
3
3
  import { encryptAndUploadFile } from "../lib/uploads.js";
4
4
  export const useWelshare = (props) => {
@@ -13,7 +13,7 @@ export const useWelshare = (props) => {
13
13
  // Resolve the base URL from environment or apiBaseUrl
14
14
  const resolvedBaseUrl = props.environment
15
15
  ? getBaseUrl(props.environment)
16
- : props.apiBaseUrl ?? getBaseUrl(WELSHARE_API_ENVIRONMENT.production);
16
+ : (props.apiBaseUrl ?? getBaseUrl(WELSHARE_API_ENVIRONMENT.production));
17
17
  const options = {
18
18
  ...props,
19
19
  apiBaseUrl: resolvedBaseUrl,
@@ -133,7 +133,13 @@ export const useWelshare = (props) => {
133
133
  return () => {
134
134
  window.removeEventListener("message", handleMessage);
135
135
  };
136
- }, [WELSHARE_WALLET_URL, dialogWindow, messageIdCounter, options.applicationId, options.callbacks]);
136
+ }, [
137
+ WELSHARE_WALLET_URL,
138
+ dialogWindow,
139
+ messageIdCounter,
140
+ options.applicationId,
141
+ options.callbacks,
142
+ ]);
137
143
  /**
138
144
  * Starts a file upload and returns a promise that resolves with the uploaded file URL
139
145
  * @param file The file to upload
@@ -164,10 +170,7 @@ export const useWelshare = (props) => {
164
170
  const message = {
165
171
  type: "REQUEST_UPLOAD_CREDENTIALS",
166
172
  id: String(messageIdCounter),
167
- payload: {
168
- ...payload,
169
- applicationId: options.applicationId,
170
- },
173
+ payload: { ...payload, applicationId: options.applicationId },
171
174
  };
172
175
  dialogWindow.postMessage(message, WELSHARE_WALLET_URL);
173
176
  setMessageIdCounter((prev) => prev + 1);
@@ -212,7 +215,7 @@ export const useWelshare = (props) => {
212
215
  .filter(([_, value]) => value !== undefined && value !== null)
213
216
  .map(([key, value]) => `social.${key}=${encodeURIComponent(String(value))}`);
214
217
  if (socialEntries.length > 0) {
215
- socialParams = `&${socialEntries.join('&')}`;
218
+ socialParams = `&${socialEntries.join("&")}`;
216
219
  }
217
220
  }
218
221
  const walletUrl = `${WELSHARE_WALLET_URL}?applicationId=${options.applicationId}${socialParams}`;
@@ -2,8 +2,7 @@ export { ConnectWelshareButton } from "./components/connect-button.js";
2
2
  export { WelshareLogo } from "./components/welshare-logo.js";
3
3
  export { useWelshare } from "./hooks/use-welshare.js";
4
4
  export { WELSHARE_API_ENVIRONMENT, resolveEnvironment, getBaseUrl, type WelshareApiEnvironment, type WelshareEnvironmentName, type NillionClusterConfig, } from "@welshare/sdk/environment";
5
- export { decrypt, encodeEncryptionKey, encryptFile, generateRandomAESKey } from "./lib/encryption.js";
6
- export { decodeEncryptionKey, type EncryptionKey } from "./utils.js";
5
+ export { decrypt, encodeEncryptionKey, encryptFile, generateRandomAESKey, decodeEncryptionKey, ALGORITHM, type EncryptionKey, type Algorithm, } from "@welshare/sdk";
7
6
  export { browserDownload, encryptAndUploadFile } from "./lib/uploads.js";
8
7
  export declare const Schemas: {
9
8
  QuestionnaireResponse: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAG7D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGtD,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,UAAU,EACV,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,GAC1B,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EACL,OAAO,EACP,mBAAmB,EACnB,WAAW,EACX,oBAAoB,EACrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAErE,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAGzE,eAAO,MAAM,OAAO;;;;CAInB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAG7D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGtD,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,UAAU,EACV,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,GAC1B,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EACL,OAAO,EACP,mBAAmB,EACnB,WAAW,EACX,oBAAoB,EACpB,mBAAmB,EACnB,SAAS,EACT,KAAK,aAAa,EAClB,KAAK,SAAS,GACf,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAGzE,eAAO,MAAM,OAAO;;;;CAInB,CAAC"}
@@ -5,9 +5,9 @@ export { WelshareLogo } from "./components/welshare-logo.js";
5
5
  export { useWelshare } from "./hooks/use-welshare.js";
6
6
  // ---- Environment (re-exported from @welshare/sdk) ----
7
7
  export { WELSHARE_API_ENVIRONMENT, resolveEnvironment, getBaseUrl, } from "@welshare/sdk/environment";
8
- // ---- Utils ----
9
- export { decrypt, encodeEncryptionKey, encryptFile, generateRandomAESKey } from "./lib/encryption.js";
10
- export { decodeEncryptionKey } from "./utils.js";
8
+ // ---- Encryption utilities (re-exported from @welshare/sdk) ----
9
+ export { decrypt, encodeEncryptionKey, encryptFile, generateRandomAESKey, decodeEncryptionKey, ALGORITHM, } from "@welshare/sdk";
10
+ // ---- Upload utilities (local, for frame-based upload flow) ----
11
11
  export { browserDownload, encryptAndUploadFile } from "./lib/uploads.js";
12
12
  //todo: import them from the SDK
13
13
  export const Schemas = {
@@ -1,4 +1,4 @@
1
- import { EncryptionKey } from "@/utils.js";
1
+ import { type EncryptionKey } from "@welshare/sdk";
2
2
  export declare const encryptAndUploadFile: (file: File, presignedUrl: string) => Promise<EncryptionKey>;
3
3
  export declare const browserDownload: (decryptedFile: File) => void;
4
4
  //# sourceMappingURL=uploads.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"uploads.d.ts","sourceRoot":"","sources":["../../../src/lib/uploads.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAO3C,eAAO,MAAM,oBAAoB,SACzB,IAAI,gBACI,MAAM,KACnB,OAAO,CAAC,aAAa,CAkBvB,CAAC;AAEF,eAAO,MAAM,eAAe,kBAAmB,IAAI,SASlD,CAAA"}
1
+ {"version":3,"file":"uploads.d.ts","sourceRoot":"","sources":["../../../src/lib/uploads.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAInB,MAAM,eAAe,CAAC;AAEvB,eAAO,MAAM,oBAAoB,SACzB,IAAI,gBACI,MAAM,KACnB,OAAO,CAAC,aAAa,CAgBvB,CAAC;AAEF,eAAO,MAAM,eAAe,kBAAmB,IAAI,SASlD,CAAC"}
@@ -1,4 +1,4 @@
1
- import { encodeEncryptionKey, encryptFile, generateRandomAESKey, } from "./encryption.js";
1
+ import { encodeEncryptionKey, encryptFile, generateRandomAESKey, } from "@welshare/sdk";
2
2
  export const encryptAndUploadFile = async (file, presignedUrl) => {
3
3
  const encryptionKey = await generateRandomAESKey();
4
4
  const { encryptedData, iv } = await encryptFile(file, encryptionKey);
@@ -6,9 +6,7 @@ export const encryptAndUploadFile = async (file, presignedUrl) => {
6
6
  const uploadResponse = await fetch(presignedUrl, {
7
7
  method: "PUT",
8
8
  body: encryptedData,
9
- headers: {
10
- "Content-Type": file.type,
11
- },
9
+ headers: { "Content-Type": file.type },
12
10
  });
13
11
  if (!uploadResponse.ok) {
14
12
  throw new Error(`Failed to upload file ${uploadResponse.status}`);
@@ -1,4 +1,4 @@
1
- import { EncryptionKey } from "./utils.js";
1
+ import type { EncryptionKey } from "@welshare/sdk";
2
2
  import type { WelshareApiEnvironment, WelshareEnvironmentName } from "@welshare/sdk/environment";
3
3
  export interface DialogMessage {
4
4
  type: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEjG,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAA;AAEvC,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAClC,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,IAAI,CAAC;IAChB,QAAQ,EA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