@welshare/react 0.2.1 → 0.2.2
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.
- package/dist/esm/index.d.ts +3 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +4 -3
- package/dist/esm/lib/encryption.d.ts +1 -11
- package/dist/esm/lib/encryption.d.ts.map +1 -1
- package/dist/esm/lib/encryption.js +2 -9
- package/dist/esm/lib/uploads.d.ts +2 -1
- package/dist/esm/lib/uploads.d.ts.map +1 -1
- package/dist/esm/lib/uploads.js +10 -0
- package/dist/esm/types.d.ts +1 -1
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/utils.d.ts +12 -0
- package/dist/esm/utils.d.ts.map +1 -0
- package/dist/esm/utils.js +8 -0
- package/dist/node_modules/@welshare/react/.DS_Store +0 -0
- package/dist/node_modules/@welshare/react/dist/esm/index.d.ts +3 -2
- package/dist/node_modules/@welshare/react/dist/esm/index.d.ts.map +1 -1
- package/dist/node_modules/@welshare/react/dist/esm/index.js +4 -3
- package/dist/node_modules/@welshare/react/dist/esm/lib/encryption.d.ts +1 -11
- package/dist/node_modules/@welshare/react/dist/esm/lib/encryption.d.ts.map +1 -1
- package/dist/node_modules/@welshare/react/dist/esm/lib/encryption.js +2 -9
- package/dist/node_modules/@welshare/react/dist/esm/lib/uploads.d.ts +2 -1
- package/dist/node_modules/@welshare/react/dist/esm/lib/uploads.d.ts.map +1 -1
- package/dist/node_modules/@welshare/react/dist/esm/lib/uploads.js +10 -0
- package/dist/node_modules/@welshare/react/dist/esm/types.d.ts +1 -1
- package/dist/node_modules/@welshare/react/dist/esm/types.d.ts.map +1 -1
- package/dist/node_modules/@welshare/react/dist/esm/utils.d.ts +12 -0
- package/dist/node_modules/@welshare/react/dist/esm/utils.d.ts.map +1 -0
- package/dist/node_modules/@welshare/react/dist/esm/utils.js +8 -0
- package/dist/node_modules/@welshare/react/package.json +8 -1
- package/dist/node_modules/@welshare/react/src/index.ts +5 -5
- package/dist/node_modules/@welshare/react/src/lib/encryption.ts +3 -24
- package/dist/node_modules/@welshare/react/src/lib/uploads.ts +12 -1
- package/dist/node_modules/@welshare/react/src/types.ts +1 -1
- package/dist/node_modules/@welshare/react/src/utils.ts +22 -0
- package/package.json +8 -1
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
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
|
-
export {
|
|
5
|
-
export {
|
|
4
|
+
export { decrypt, encodeEncryptionKey, encryptFile, generateRandomAESKey } from "./lib/encryption.js";
|
|
5
|
+
export { decodeEncryptionKey, type EncryptionKey } from "./utils.js";
|
|
6
|
+
export { browserDownload, encryptAndUploadFile } from "./lib/uploads.js";
|
|
6
7
|
export declare const Schemas: {
|
|
7
8
|
QuestionnaireResponse: string;
|
|
8
9
|
ReflexSubmission: string;
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,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;AAEzE,eAAO,MAAM,OAAO;;;;CAInB,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -4,11 +4,12 @@ export { ConnectWelshareButton } from "./components/connect-button.js";
|
|
|
4
4
|
export { WelshareLogo } from "./components/welshare-logo.js";
|
|
5
5
|
// ---- hooks ----
|
|
6
6
|
export { useWelshare } from "./hooks/use-welshare.js";
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
7
|
+
export { decrypt, encodeEncryptionKey, encryptFile, generateRandomAESKey } from "./lib/encryption.js";
|
|
8
|
+
export { decodeEncryptionKey } from "./utils.js";
|
|
9
|
+
export { browserDownload, encryptAndUploadFile } from "./lib/uploads.js";
|
|
9
10
|
//todo: import them from the SDK or a dedicated SDK constants export
|
|
10
11
|
export const Schemas = {
|
|
11
12
|
QuestionnaireResponse: "b14b538f-7de3-4767-ad77-464d755d78bd", //QuestionnaireResponseSchema.schemaUid,
|
|
12
13
|
ReflexSubmission: "f5cf2d8a-1f78-4f21-b4bd-082e983b830c", //ReflexSubmissionSchema.schemaUid,
|
|
13
|
-
BinaryFile: "9d696baf-483f-4cc0-b748-23a22c1705f5" //BinaryFilesSchema.schemaUid,
|
|
14
|
+
BinaryFile: "9d696baf-483f-4cc0-b748-23a22c1705f5", //BinaryFilesSchema.schemaUid,
|
|
14
15
|
};
|
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
export type Algorithm = "AES-GCM";
|
|
1
|
+
import { EncryptionKey } from "../utils.js";
|
|
3
2
|
export declare const generateRandomAESKey: () => Promise<CryptoKey>;
|
|
4
3
|
export declare const encryptFile: (file: File, key: CryptoKey) => Promise<{
|
|
5
4
|
encryptedData: ArrayBuffer;
|
|
6
5
|
iv: Uint8Array;
|
|
7
6
|
}>;
|
|
8
|
-
export type EncryptionKey = {
|
|
9
|
-
algorithm: Algorithm;
|
|
10
|
-
key: string;
|
|
11
|
-
iv: string;
|
|
12
|
-
};
|
|
13
7
|
export declare const encodeEncryptionKey: (key: CryptoKey, iv: Uint8Array) => Promise<EncryptionKey>;
|
|
14
|
-
export declare const decodeEncryptionKey: (encryptionKey: EncryptionKey) => {
|
|
15
|
-
key: Uint8Array<ArrayBuffer>;
|
|
16
|
-
iv: Uint8Array<ArrayBuffer>;
|
|
17
|
-
};
|
|
18
8
|
export declare const decrypt: (encryptedData: ArrayBuffer, encryptionKey: EncryptionKey) => Promise<ArrayBuffer | null>;
|
|
19
9
|
//# sourceMappingURL=encryption.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encryption.d.ts","sourceRoot":"","sources":["../../../src/lib/encryption.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"encryption.d.ts","sourceRoot":"","sources":["../../../src/lib/encryption.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,aAAa,EAAuB,MAAM,aAAa,CAAC;AAE5E,eAAO,MAAM,oBAAoB,QAAa,OAAO,CAAC,SAAS,CAU9D,CAAC;AAIF,eAAO,MAAM,WAAW,SAChB,IAAI,OACL,SAAS,KACb,OAAO,CAAC;IAAE,aAAa,EAAE,WAAW,CAAC;IAAC,EAAE,EAAE,UAAU,CAAA;CAAE,CAgBxD,CAAC;AAEF,eAAO,MAAM,mBAAmB,QACzB,SAAS,MACV,UAAU,KACb,OAAO,CAAC,aAAa,CAgBvB,CAAC;AAGF,eAAO,MAAM,OAAO,kBACH,WAAW,iBACX,aAAa,KAC3B,OAAO,CAAC,WAAW,GAAG,IAAI,CA0B5B,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { ALGORITHM, decodeEncryptionKey } from "../utils.js";
|
|
2
2
|
export const generateRandomAESKey = async () => {
|
|
3
3
|
// Generate a 256-bit AES-GCM key for file encryption
|
|
4
4
|
return window.crypto.subtle.generateKey({
|
|
@@ -36,13 +36,6 @@ export const encodeEncryptionKey = async (key, iv) => {
|
|
|
36
36
|
iv: ivHex,
|
|
37
37
|
};
|
|
38
38
|
};
|
|
39
|
-
export const decodeEncryptionKey = (encryptionKey) => {
|
|
40
|
-
const keyBytes = new Uint8Array(encryptionKey.key
|
|
41
|
-
.match(/.{1,2}/g)
|
|
42
|
-
.map((byte) => parseInt(byte, 16)));
|
|
43
|
-
const ivBytes = new Uint8Array(encryptionKey.iv.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
|
|
44
|
-
return { key: keyBytes, iv: ivBytes };
|
|
45
|
-
};
|
|
46
39
|
// Helper function to decrypt a file using encoded encryption key
|
|
47
40
|
export const decrypt = async (encryptedData, encryptionKey) => {
|
|
48
41
|
try {
|
|
@@ -50,7 +43,7 @@ export const decrypt = async (encryptedData, encryptionKey) => {
|
|
|
50
43
|
const key = await window.crypto.subtle.importKey("raw", keyBytes, { name: ALGORITHM }, false, ["decrypt"]);
|
|
51
44
|
const decryptedData = await window.crypto.subtle.decrypt({
|
|
52
45
|
name: ALGORITHM,
|
|
53
|
-
iv,
|
|
46
|
+
iv: iv,
|
|
54
47
|
}, key, encryptedData);
|
|
55
48
|
return decryptedData;
|
|
56
49
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { EncryptionKey } from "
|
|
1
|
+
import { EncryptionKey } from "@/utils.js";
|
|
2
2
|
export declare const encryptAndUploadFile: (file: File, presignedUrl: string) => Promise<EncryptionKey>;
|
|
3
|
+
export declare const browserDownload: (decryptedFile: File) => void;
|
|
3
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,
|
|
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"}
|
package/dist/esm/lib/uploads.js
CHANGED
|
@@ -15,3 +15,13 @@ export const encryptAndUploadFile = async (file, presignedUrl) => {
|
|
|
15
15
|
}
|
|
16
16
|
return encodeEncryptionKey(encryptionKey, iv);
|
|
17
17
|
};
|
|
18
|
+
export const browserDownload = (decryptedFile) => {
|
|
19
|
+
const downloadUrl = window.URL.createObjectURL(decryptedFile);
|
|
20
|
+
const a = document.createElement("a");
|
|
21
|
+
a.href = downloadUrl;
|
|
22
|
+
a.download = decryptedFile.name;
|
|
23
|
+
document.body.appendChild(a);
|
|
24
|
+
a.click();
|
|
25
|
+
document.body.removeChild(a);
|
|
26
|
+
window.URL.revokeObjectURL(downloadUrl);
|
|
27
|
+
};
|
package/dist/esm/types.d.ts
CHANGED
package/dist/esm/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,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;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ACT,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,12 @@
|
|
|
1
|
+
export declare const ALGORITHM = "AES-GCM";
|
|
2
|
+
export type Algorithm = "AES-GCM";
|
|
3
|
+
export type EncryptionKey = {
|
|
4
|
+
algorithm: Algorithm;
|
|
5
|
+
key: string;
|
|
6
|
+
iv: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const decodeEncryptionKey: (encryptionKey: EncryptionKey) => {
|
|
9
|
+
key: BufferSource;
|
|
10
|
+
iv: BufferSource;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,YAAY,CAAC;AACnC,MAAM,MAAM,SAAS,GAAG,SAAS,CAAC;AAElC,MAAM,MAAM,aAAa,GAAG;IAC1B,SAAS,EAAE,SAAS,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,eAAO,MAAM,mBAAmB,kBACf,aAAa,KAC3B;IAAE,GAAG,EAAE,YAAY,CAAC;IAAC,EAAE,EAAE,YAAY,CAAA;CAUvC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const ALGORITHM = "AES-GCM";
|
|
2
|
+
export const decodeEncryptionKey = (encryptionKey) => {
|
|
3
|
+
const keyBytes = new Uint8Array(encryptionKey.key
|
|
4
|
+
.match(/.{1,2}/g)
|
|
5
|
+
.map((byte) => parseInt(byte, 16)));
|
|
6
|
+
const ivBytes = new Uint8Array(encryptionKey.iv.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
|
|
7
|
+
return { key: keyBytes, iv: ivBytes };
|
|
8
|
+
};
|
|
Binary file
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
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
|
-
export {
|
|
5
|
-
export {
|
|
4
|
+
export { decrypt, encodeEncryptionKey, encryptFile, generateRandomAESKey } from "./lib/encryption.js";
|
|
5
|
+
export { decodeEncryptionKey, type EncryptionKey } from "./utils.js";
|
|
6
|
+
export { browserDownload, encryptAndUploadFile } from "./lib/uploads.js";
|
|
6
7
|
export declare const Schemas: {
|
|
7
8
|
QuestionnaireResponse: string;
|
|
8
9
|
ReflexSubmission: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,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;AAEzE,eAAO,MAAM,OAAO;;;;CAInB,CAAC"}
|
|
@@ -4,11 +4,12 @@ export { ConnectWelshareButton } from "./components/connect-button.js";
|
|
|
4
4
|
export { WelshareLogo } from "./components/welshare-logo.js";
|
|
5
5
|
// ---- hooks ----
|
|
6
6
|
export { useWelshare } from "./hooks/use-welshare.js";
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
7
|
+
export { decrypt, encodeEncryptionKey, encryptFile, generateRandomAESKey } from "./lib/encryption.js";
|
|
8
|
+
export { decodeEncryptionKey } from "./utils.js";
|
|
9
|
+
export { browserDownload, encryptAndUploadFile } from "./lib/uploads.js";
|
|
9
10
|
//todo: import them from the SDK or a dedicated SDK constants export
|
|
10
11
|
export const Schemas = {
|
|
11
12
|
QuestionnaireResponse: "b14b538f-7de3-4767-ad77-464d755d78bd", //QuestionnaireResponseSchema.schemaUid,
|
|
12
13
|
ReflexSubmission: "f5cf2d8a-1f78-4f21-b4bd-082e983b830c", //ReflexSubmissionSchema.schemaUid,
|
|
13
|
-
BinaryFile: "9d696baf-483f-4cc0-b748-23a22c1705f5" //BinaryFilesSchema.schemaUid,
|
|
14
|
+
BinaryFile: "9d696baf-483f-4cc0-b748-23a22c1705f5", //BinaryFilesSchema.schemaUid,
|
|
14
15
|
};
|
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
export type Algorithm = "AES-GCM";
|
|
1
|
+
import { EncryptionKey } from "../utils.js";
|
|
3
2
|
export declare const generateRandomAESKey: () => Promise<CryptoKey>;
|
|
4
3
|
export declare const encryptFile: (file: File, key: CryptoKey) => Promise<{
|
|
5
4
|
encryptedData: ArrayBuffer;
|
|
6
5
|
iv: Uint8Array;
|
|
7
6
|
}>;
|
|
8
|
-
export type EncryptionKey = {
|
|
9
|
-
algorithm: Algorithm;
|
|
10
|
-
key: string;
|
|
11
|
-
iv: string;
|
|
12
|
-
};
|
|
13
7
|
export declare const encodeEncryptionKey: (key: CryptoKey, iv: Uint8Array) => Promise<EncryptionKey>;
|
|
14
|
-
export declare const decodeEncryptionKey: (encryptionKey: EncryptionKey) => {
|
|
15
|
-
key: Uint8Array<ArrayBuffer>;
|
|
16
|
-
iv: Uint8Array<ArrayBuffer>;
|
|
17
|
-
};
|
|
18
8
|
export declare const decrypt: (encryptedData: ArrayBuffer, encryptionKey: EncryptionKey) => Promise<ArrayBuffer | null>;
|
|
19
9
|
//# sourceMappingURL=encryption.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encryption.d.ts","sourceRoot":"","sources":["../../../src/lib/encryption.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"encryption.d.ts","sourceRoot":"","sources":["../../../src/lib/encryption.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,aAAa,EAAuB,MAAM,aAAa,CAAC;AAE5E,eAAO,MAAM,oBAAoB,QAAa,OAAO,CAAC,SAAS,CAU9D,CAAC;AAIF,eAAO,MAAM,WAAW,SAChB,IAAI,OACL,SAAS,KACb,OAAO,CAAC;IAAE,aAAa,EAAE,WAAW,CAAC;IAAC,EAAE,EAAE,UAAU,CAAA;CAAE,CAgBxD,CAAC;AAEF,eAAO,MAAM,mBAAmB,QACzB,SAAS,MACV,UAAU,KACb,OAAO,CAAC,aAAa,CAgBvB,CAAC;AAGF,eAAO,MAAM,OAAO,kBACH,WAAW,iBACX,aAAa,KAC3B,OAAO,CAAC,WAAW,GAAG,IAAI,CA0B5B,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { ALGORITHM, decodeEncryptionKey } from "../utils.js";
|
|
2
2
|
export const generateRandomAESKey = async () => {
|
|
3
3
|
// Generate a 256-bit AES-GCM key for file encryption
|
|
4
4
|
return window.crypto.subtle.generateKey({
|
|
@@ -36,13 +36,6 @@ export const encodeEncryptionKey = async (key, iv) => {
|
|
|
36
36
|
iv: ivHex,
|
|
37
37
|
};
|
|
38
38
|
};
|
|
39
|
-
export const decodeEncryptionKey = (encryptionKey) => {
|
|
40
|
-
const keyBytes = new Uint8Array(encryptionKey.key
|
|
41
|
-
.match(/.{1,2}/g)
|
|
42
|
-
.map((byte) => parseInt(byte, 16)));
|
|
43
|
-
const ivBytes = new Uint8Array(encryptionKey.iv.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
|
|
44
|
-
return { key: keyBytes, iv: ivBytes };
|
|
45
|
-
};
|
|
46
39
|
// Helper function to decrypt a file using encoded encryption key
|
|
47
40
|
export const decrypt = async (encryptedData, encryptionKey) => {
|
|
48
41
|
try {
|
|
@@ -50,7 +43,7 @@ export const decrypt = async (encryptedData, encryptionKey) => {
|
|
|
50
43
|
const key = await window.crypto.subtle.importKey("raw", keyBytes, { name: ALGORITHM }, false, ["decrypt"]);
|
|
51
44
|
const decryptedData = await window.crypto.subtle.decrypt({
|
|
52
45
|
name: ALGORITHM,
|
|
53
|
-
iv,
|
|
46
|
+
iv: iv,
|
|
54
47
|
}, key, encryptedData);
|
|
55
48
|
return decryptedData;
|
|
56
49
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { EncryptionKey } from "
|
|
1
|
+
import { EncryptionKey } from "@/utils.js";
|
|
2
2
|
export declare const encryptAndUploadFile: (file: File, presignedUrl: string) => Promise<EncryptionKey>;
|
|
3
|
+
export declare const browserDownload: (decryptedFile: File) => void;
|
|
3
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,
|
|
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"}
|
|
@@ -15,3 +15,13 @@ export const encryptAndUploadFile = async (file, presignedUrl) => {
|
|
|
15
15
|
}
|
|
16
16
|
return encodeEncryptionKey(encryptionKey, iv);
|
|
17
17
|
};
|
|
18
|
+
export const browserDownload = (decryptedFile) => {
|
|
19
|
+
const downloadUrl = window.URL.createObjectURL(decryptedFile);
|
|
20
|
+
const a = document.createElement("a");
|
|
21
|
+
a.href = downloadUrl;
|
|
22
|
+
a.download = decryptedFile.name;
|
|
23
|
+
document.body.appendChild(a);
|
|
24
|
+
a.click();
|
|
25
|
+
document.body.removeChild(a);
|
|
26
|
+
window.URL.revokeObjectURL(downloadUrl);
|
|
27
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,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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AAC,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,12 @@
|
|
|
1
|
+
export declare const ALGORITHM = "AES-GCM";
|
|
2
|
+
export type Algorithm = "AES-GCM";
|
|
3
|
+
export type EncryptionKey = {
|
|
4
|
+
algorithm: Algorithm;
|
|
5
|
+
key: string;
|
|
6
|
+
iv: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const decodeEncryptionKey: (encryptionKey: EncryptionKey) => {
|
|
9
|
+
key: BufferSource;
|
|
10
|
+
iv: BufferSource;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,YAAY,CAAC;AACnC,MAAM,MAAM,SAAS,GAAG,SAAS,CAAC;AAElC,MAAM,MAAM,aAAa,GAAG;IAC1B,SAAS,EAAE,SAAS,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,eAAO,MAAM,mBAAmB,kBACf,aAAa,KAC3B;IAAE,GAAG,EAAE,YAAY,CAAC;IAAC,EAAE,EAAE,YAAY,CAAA;CAUvC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const ALGORITHM = "AES-GCM";
|
|
2
|
+
export const decodeEncryptionKey = (encryptionKey) => {
|
|
3
|
+
const keyBytes = new Uint8Array(encryptionKey.key
|
|
4
|
+
.match(/.{1,2}/g)
|
|
5
|
+
.map((byte) => parseInt(byte, 16)));
|
|
6
|
+
const ivBytes = new Uint8Array(encryptionKey.iv.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
|
|
7
|
+
return { key: keyBytes, iv: ivBytes };
|
|
8
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@welshare/react",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "React library for integrating with Welshare's sovereign data sharing platform",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -58,6 +58,7 @@
|
|
|
58
58
|
"exports": {
|
|
59
59
|
"./package.json": "./package.json",
|
|
60
60
|
"./types": "./src/types.ts",
|
|
61
|
+
"./utils": "./src/utils.ts",
|
|
61
62
|
".": "./src/index.ts"
|
|
62
63
|
}
|
|
63
64
|
},
|
|
@@ -69,6 +70,12 @@
|
|
|
69
70
|
"default": "./dist/esm/types.js"
|
|
70
71
|
}
|
|
71
72
|
},
|
|
73
|
+
"./utils": {
|
|
74
|
+
"import": {
|
|
75
|
+
"types": "./dist/esm/utils.d.ts",
|
|
76
|
+
"default": "./dist/esm/utils.js"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
72
79
|
".": {
|
|
73
80
|
"import": {
|
|
74
81
|
"types": "./dist/esm/index.d.ts",
|
|
@@ -6,17 +6,17 @@ export { WelshareLogo } from "./components/welshare-logo.js";
|
|
|
6
6
|
export { useWelshare } from "./hooks/use-welshare.js";
|
|
7
7
|
|
|
8
8
|
export {
|
|
9
|
-
decodeEncryptionKey,
|
|
10
9
|
decrypt,
|
|
11
10
|
encodeEncryptionKey,
|
|
12
11
|
encryptFile,
|
|
13
|
-
generateRandomAESKey
|
|
14
|
-
type EncryptionKey
|
|
12
|
+
generateRandomAESKey
|
|
15
13
|
} from "./lib/encryption.js";
|
|
16
|
-
export {
|
|
14
|
+
export { decodeEncryptionKey, type EncryptionKey } from "./utils.js";
|
|
15
|
+
|
|
16
|
+
export { browserDownload, encryptAndUploadFile } from "./lib/uploads.js";
|
|
17
17
|
//todo: import them from the SDK or a dedicated SDK constants export
|
|
18
18
|
export const Schemas = {
|
|
19
19
|
QuestionnaireResponse: "b14b538f-7de3-4767-ad77-464d755d78bd", //QuestionnaireResponseSchema.schemaUid,
|
|
20
20
|
ReflexSubmission: "f5cf2d8a-1f78-4f21-b4bd-082e983b830c", //ReflexSubmissionSchema.schemaUid,
|
|
21
|
-
BinaryFile: "9d696baf-483f-4cc0-b748-23a22c1705f5" //BinaryFilesSchema.schemaUid,
|
|
21
|
+
BinaryFile: "9d696baf-483f-4cc0-b748-23a22c1705f5", //BinaryFilesSchema.schemaUid,
|
|
22
22
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export type Algorithm = "AES-GCM";
|
|
1
|
+
import { ALGORITHM, EncryptionKey, decodeEncryptionKey } from "../utils.js";
|
|
3
2
|
|
|
4
3
|
export const generateRandomAESKey = async (): Promise<CryptoKey> => {
|
|
5
4
|
// Generate a 256-bit AES-GCM key for file encryption
|
|
@@ -36,12 +35,6 @@ export const encryptFile = async (
|
|
|
36
35
|
return { encryptedData, iv };
|
|
37
36
|
};
|
|
38
37
|
|
|
39
|
-
export type EncryptionKey = {
|
|
40
|
-
algorithm: Algorithm;
|
|
41
|
-
key: string;
|
|
42
|
-
iv: string;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
38
|
export const encodeEncryptionKey = async (
|
|
46
39
|
key: CryptoKey,
|
|
47
40
|
iv: Uint8Array
|
|
@@ -63,20 +56,6 @@ export const encodeEncryptionKey = async (
|
|
|
63
56
|
};
|
|
64
57
|
};
|
|
65
58
|
|
|
66
|
-
export const decodeEncryptionKey = (
|
|
67
|
-
encryptionKey: EncryptionKey
|
|
68
|
-
): { key: Uint8Array<ArrayBuffer>; iv: Uint8Array<ArrayBuffer> } => {
|
|
69
|
-
const keyBytes = new Uint8Array(
|
|
70
|
-
encryptionKey.key
|
|
71
|
-
.match(/.{1,2}/g)!
|
|
72
|
-
.map((byte: string) => parseInt(byte, 16))
|
|
73
|
-
);
|
|
74
|
-
const ivBytes = new Uint8Array(
|
|
75
|
-
encryptionKey.iv.match(/.{1,2}/g)!.map((byte: string) => parseInt(byte, 16))
|
|
76
|
-
);
|
|
77
|
-
return { key: keyBytes, iv: ivBytes };
|
|
78
|
-
};
|
|
79
|
-
|
|
80
59
|
// Helper function to decrypt a file using encoded encryption key
|
|
81
60
|
export const decrypt = async (
|
|
82
61
|
encryptedData: ArrayBuffer,
|
|
@@ -87,7 +66,7 @@ export const decrypt = async (
|
|
|
87
66
|
|
|
88
67
|
const key = await window.crypto.subtle.importKey(
|
|
89
68
|
"raw",
|
|
90
|
-
keyBytes,
|
|
69
|
+
keyBytes as BufferSource,
|
|
91
70
|
{ name: ALGORITHM },
|
|
92
71
|
false,
|
|
93
72
|
["decrypt"]
|
|
@@ -96,7 +75,7 @@ export const decrypt = async (
|
|
|
96
75
|
const decryptedData = await window.crypto.subtle.decrypt(
|
|
97
76
|
{
|
|
98
77
|
name: ALGORITHM,
|
|
99
|
-
iv,
|
|
78
|
+
iv: iv as BufferSource,
|
|
100
79
|
},
|
|
101
80
|
key,
|
|
102
81
|
encryptedData
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { EncryptionKey } from "@/utils.js";
|
|
1
2
|
import {
|
|
2
3
|
encodeEncryptionKey,
|
|
3
4
|
encryptFile,
|
|
4
|
-
EncryptionKey,
|
|
5
5
|
generateRandomAESKey,
|
|
6
6
|
} from "./encryption.js";
|
|
7
7
|
|
|
@@ -27,3 +27,14 @@ export const encryptAndUploadFile = async (
|
|
|
27
27
|
|
|
28
28
|
return encodeEncryptionKey(encryptionKey, iv);
|
|
29
29
|
};
|
|
30
|
+
|
|
31
|
+
export const browserDownload = (decryptedFile: File) => {
|
|
32
|
+
const downloadUrl = window.URL.createObjectURL(decryptedFile);
|
|
33
|
+
const a = document.createElement("a");
|
|
34
|
+
a.href = downloadUrl;
|
|
35
|
+
a.download = decryptedFile.name;
|
|
36
|
+
document.body.appendChild(a);
|
|
37
|
+
a.click();
|
|
38
|
+
document.body.removeChild(a);
|
|
39
|
+
window.URL.revokeObjectURL(downloadUrl);
|
|
40
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const ALGORITHM = "AES-GCM";
|
|
2
|
+
export type Algorithm = "AES-GCM";
|
|
3
|
+
|
|
4
|
+
export type EncryptionKey = {
|
|
5
|
+
algorithm: Algorithm;
|
|
6
|
+
key: string;
|
|
7
|
+
iv: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const decodeEncryptionKey = (
|
|
11
|
+
encryptionKey: EncryptionKey
|
|
12
|
+
): { key: BufferSource; iv: BufferSource } => {
|
|
13
|
+
const keyBytes = new Uint8Array(
|
|
14
|
+
encryptionKey.key
|
|
15
|
+
.match(/.{1,2}/g)!
|
|
16
|
+
.map((byte: string) => parseInt(byte, 16))
|
|
17
|
+
);
|
|
18
|
+
const ivBytes = new Uint8Array(
|
|
19
|
+
encryptionKey.iv.match(/.{1,2}/g)!.map((byte: string) => parseInt(byte, 16))
|
|
20
|
+
);
|
|
21
|
+
return { key: keyBytes, iv: ivBytes };
|
|
22
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@welshare/react",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "React library for integrating with Welshare's sovereign data sharing platform",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"exports": {
|
|
50
50
|
"./package.json": "./package.json",
|
|
51
51
|
"./types": "./src/types.ts",
|
|
52
|
+
"./utils": "./src/utils.ts",
|
|
52
53
|
".": "./src/index.ts"
|
|
53
54
|
}
|
|
54
55
|
},
|
|
@@ -60,6 +61,12 @@
|
|
|
60
61
|
"default": "./dist/esm/types.js"
|
|
61
62
|
}
|
|
62
63
|
},
|
|
64
|
+
"./utils": {
|
|
65
|
+
"import": {
|
|
66
|
+
"types": "./dist/esm/utils.d.ts",
|
|
67
|
+
"default": "./dist/esm/utils.js"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
63
70
|
".": {
|
|
64
71
|
"import": {
|
|
65
72
|
"types": "./dist/esm/index.d.ts",
|