@learncard/learn-cloud-plugin 2.3.29 → 2.3.31

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/package.json CHANGED
@@ -1,64 +1,66 @@
1
1
  {
2
- "name": "@learncard/learn-cloud-plugin",
3
- "version": "2.3.29",
4
- "description": "",
5
- "type": "module",
6
- "main": "./dist/index.cjs",
7
- "module": "./dist/learn-cloud-plugin.esm.js",
8
- "exports": {
9
- ".": {
10
- "import": {
11
- "types": "./dist/index.d.ts",
12
- "default": "./dist/learn-cloud-plugin.esm.js"
13
- },
14
- "require": {
15
- "types": "./dist/index.d.cts",
16
- "default": "./dist/index.cjs"
17
- }
18
- }
19
- },
20
- "files": [
21
- "dist"
22
- ],
23
- "author": "Learning Economy Foundation (www.learningeconomy.io)",
24
- "license": "MIT",
25
- "homepage": "https://github.com/learningeconomy/LearnCard/tree/main/packages/plugins/learn-cloud/README.md",
26
- "repository": {
27
- "type": "git",
28
- "url": "https://github.com/learningeconomy/LearnCard"
29
- },
30
- "bugs": {
31
- "url": "https://github.com/learningeconomy/LearnCard/issues"
32
- },
33
- "devDependencies": {
34
- "@types/jest": "^29.2.2",
35
- "@types/lodash": "^4.14.191",
36
- "@types/node": "^17.0.31",
37
- "aqu": "0.4.3",
38
- "esbuild": "^0.27.1",
39
- "esbuild-jest": "^0.5.0",
40
- "esbuild-plugin-copy": "^1.3.0",
41
- "jest": "^29.3.0",
42
- "shx": "^0.3.4",
43
- "ts-jest": "^29.0.3",
44
- "@learncard/learn-cloud-service": "^2.5.22",
45
- "@learncard/types": "5.17.4"
46
- },
47
- "types": "./dist/index.d.ts",
48
- "dependencies": {
49
- "json-stringify-deterministic": "^1.0.8",
50
- "lodash": "^4.17.21",
51
- "pbkdf2-hmac": "^1.2.1",
52
- "@learncard/core": "9.4.24",
53
- "@learncard/helpers": "^1.3.6",
54
- "@learncard/didkit-plugin": "1.9.4",
55
- "@learncard/learn-cloud-client": "1.6.29"
56
- },
57
- "sideEffects": false,
58
- "scripts": {
59
- "build": "node ./scripts/build.mjs && shx cp ./scripts/mixedEntypoint.js ./dist/index.cjs && tsc --p tsconfig.json && shx cp ./dist/index.d.ts ./dist/index.d.cts",
60
- "test": "jest --passWithNoTests",
61
- "test:watch": "jest --watch",
62
- "test:coverage": "jest --silent --ci --coverage --coverageReporters=\"text\" --coverageReporters=\"text-summary\""
63
- }
64
- }
2
+ "name": "@learncard/learn-cloud-plugin",
3
+ "version": "2.3.31",
4
+ "description": "",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/learn-cloud-plugin.esm.js",
8
+ "exports": {
9
+ ".": {
10
+ "development": "./src/index.ts",
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/learn-cloud-plugin.esm.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ }
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "src"
24
+ ],
25
+ "scripts": {
26
+ "build": "node ./scripts/build.mjs && shx cp ./scripts/mixedEntypoint.js ./dist/index.cjs && tsc --p tsconfig.json && shx cp ./dist/index.d.ts ./dist/index.d.cts",
27
+ "test": "jest --passWithNoTests",
28
+ "test:watch": "jest --watch",
29
+ "test:coverage": "jest --silent --ci --coverage --coverageReporters=\"text\" --coverageReporters=\"text-summary\""
30
+ },
31
+ "author": "Learning Economy Foundation (www.learningeconomy.io)",
32
+ "license": "MIT",
33
+ "homepage": "https://github.com/learningeconomy/LearnCard/tree/main/packages/plugins/learn-cloud/README.md",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "https://github.com/learningeconomy/LearnCard"
37
+ },
38
+ "bugs": {
39
+ "url": "https://github.com/learningeconomy/LearnCard/issues"
40
+ },
41
+ "devDependencies": {
42
+ "@learncard/learn-cloud-service": "^2.5.24",
43
+ "@learncard/types": "5.17.5",
44
+ "@types/jest": "^29.2.2",
45
+ "@types/lodash": "^4.14.191",
46
+ "@types/node": "^17.0.31",
47
+ "aqu": "0.4.3",
48
+ "esbuild": "^0.27.1",
49
+ "esbuild-jest": "^0.5.0",
50
+ "esbuild-plugin-copy": "^1.3.0",
51
+ "jest": "^29.3.0",
52
+ "shx": "^0.3.4",
53
+ "ts-jest": "^29.0.3"
54
+ },
55
+ "types": "./dist/index.d.ts",
56
+ "dependencies": {
57
+ "@learncard/core": "9.4.26",
58
+ "@learncard/didkit-plugin": "1.9.6",
59
+ "@learncard/helpers": "^1.3.8",
60
+ "@learncard/learn-cloud-client": "1.6.31",
61
+ "json-stringify-deterministic": "^1.0.8",
62
+ "lodash": "^4.17.21",
63
+ "pbkdf2-hmac": "^1.2.1"
64
+ },
65
+ "sideEffects": false
66
+ }
package/src/helpers.ts ADDED
@@ -0,0 +1,87 @@
1
+ import { JWE, EncryptedRecord } from '@learncard/types';
2
+ import stringify from 'json-stringify-deterministic';
3
+ import pbkdf2Hmac from 'pbkdf2-hmac';
4
+
5
+ import { LearnCloudDependentLearnCard } from './types';
6
+
7
+ export const hash = async (
8
+ learnCard: LearnCloudDependentLearnCard,
9
+ message: string
10
+ ): Promise<string> => {
11
+ const lcHash = await learnCard.invoke.hash?.(message, 'PBKDF2-HMAC-SHA256');
12
+
13
+ if (lcHash) return lcHash;
14
+
15
+ const crypto = learnCard.invoke.crypto();
16
+
17
+ const uint8Message = new TextEncoder().encode(message);
18
+
19
+ const pk = learnCard.id.keypair('secp256k1').d;
20
+ const hmacKey = await pbkdf2Hmac(pk, 'salt', 1000, 32);
21
+ const cryptoKey = await crypto.subtle.importKey(
22
+ 'raw',
23
+ hmacKey,
24
+ { name: 'HMAC', hash: 'SHA-256' },
25
+ false,
26
+ ['sign']
27
+ );
28
+
29
+ const digestBuffer = await crypto.subtle.sign('HMAC', cryptoKey, uint8Message);
30
+
31
+ const digestArray = Array.from(new Uint8Array(digestBuffer));
32
+
33
+ return digestArray.map(byte => (byte as any).toString(16).padStart(2, '0')).join('');
34
+ };
35
+
36
+ export const generateJWE = async (
37
+ learnCard: LearnCloudDependentLearnCard,
38
+ learnCloudDid: string,
39
+ item: any
40
+ ): Promise<JWE> => {
41
+ return learnCard.invoke.createDagJwe(item, [learnCloudDid]);
42
+ };
43
+
44
+ export const decryptJWE = async <T>(
45
+ learnCard: LearnCloudDependentLearnCard,
46
+ jwe: JWE
47
+ ): Promise<T> => {
48
+ return learnCard.invoke.decryptDagJwe<T>(jwe);
49
+ };
50
+
51
+ export const generateEncryptedFieldsArray = async (
52
+ learnCard: LearnCloudDependentLearnCard,
53
+ record: Record<string, any>,
54
+ unencryptedFields: string[] = []
55
+ ): Promise<string[]> => {
56
+ const entries = Object.entries(record);
57
+
58
+ return (
59
+ await Promise.all(
60
+ entries.map(async ([key, value]) => {
61
+ if (!unencryptedFields.includes(key)) {
62
+ const result = await hash(learnCard, `${key}:${stringify(value)}`);
63
+
64
+ return result;
65
+ }
66
+
67
+ return '';
68
+ })
69
+ )
70
+ ).filter(Boolean);
71
+ };
72
+
73
+ export const generateEncryptedRecord = async (
74
+ learnCard: LearnCloudDependentLearnCard,
75
+ record: Record<string, any>,
76
+ unencryptedFields: string[] = []
77
+ ): Promise<EncryptedRecord> => {
78
+ const encryptedRecord = await learnCard.invoke.createDagJwe(record);
79
+
80
+ const fields = await generateEncryptedFieldsArray(learnCard, record, unencryptedFields);
81
+
82
+ const unencryptedEntries = Object.fromEntries(
83
+ Object.entries(record).filter(([key]) => unencryptedFields.includes(key))
84
+ );
85
+
86
+ return { ...unencryptedEntries, encryptedRecord, fields };
87
+ };
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './types';
2
+ export * from './plugin';