@learncard/core 9.4.24 → 9.4.25
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/README.md +1 -1
- package/dist/core.cjs.development.cjs.map +2 -2
- package/dist/core.cjs.production.min.cjs.map +2 -2
- package/dist/core.esm.js.map +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/types/LearnCard.d.ts.map +1 -1
- package/dist/wallet/base/helpers.d.ts.map +1 -1
- package/dist/wallet/base/wallet.d.ts.map +1 -1
- package/dist/wallet/plugins/test-cache/types.d.ts.map +1 -1
- package/dist/wallet/plugins/test-index/types.d.ts.map +1 -1
- package/dist/wallet/plugins/test-storage/types.d.ts.map +1 -1
- package/package.json +60 -58
- package/src/index.ts +8 -0
- package/src/polyfills.ts +22 -0
- package/src/types/LearnCard.ts +7 -0
- package/src/types/global.d.ts +4 -0
- package/src/types/helpers.ts +4 -0
- package/src/types/planes.ts +212 -0
- package/src/types/utilities.ts +39 -0
- package/src/types/wallet.ts +176 -0
- package/src/wallet/base/crypto.ts +5 -0
- package/src/wallet/base/helpers.ts +73 -0
- package/src/wallet/base/index.ts +2 -0
- package/src/wallet/base/wallet.ts +832 -0
- package/src/wallet/plugins/index.ts +3 -0
- package/src/wallet/plugins/test-cache/index.ts +67 -0
- package/src/wallet/plugins/test-cache/types.ts +3 -0
- package/src/wallet/plugins/test-index/index.ts +37 -0
- package/src/wallet/plugins/test-index/types.ts +3 -0
- package/src/wallet/plugins/test-storage/index.ts +82 -0
- package/src/wallet/plugins/test-storage/types.ts +3 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { CredentialRecord, StoredCredentialEnvelope, VC, VP } from '@learncard/types';
|
|
2
|
+
import { TestCachePlugin } from './types';
|
|
3
|
+
|
|
4
|
+
export const getTestCache = (): TestCachePlugin => {
|
|
5
|
+
let index: Record<string, CredentialRecord[]> = {};
|
|
6
|
+
let paginatedIndex: Record<
|
|
7
|
+
string,
|
|
8
|
+
{ records: CredentialRecord[]; hasMore: boolean; cursor?: string }
|
|
9
|
+
> = {};
|
|
10
|
+
let vcs: Record<string, VC | VP | StoredCredentialEnvelope | undefined> = {};
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
name: 'Test Cache',
|
|
14
|
+
displayName: 'Test Cache',
|
|
15
|
+
description: '[Testing] Tests Caching Implementation',
|
|
16
|
+
cache: {
|
|
17
|
+
getIndex: async (_learnCard, name, query) => {
|
|
18
|
+
_learnCard.debug?.('Test Cache, getIndex', { name, query, value: index });
|
|
19
|
+
return index[name];
|
|
20
|
+
},
|
|
21
|
+
setIndex: async (_learnCard, name, query, value) => {
|
|
22
|
+
_learnCard.debug?.('Test Cache, setIndex', { name, query, value });
|
|
23
|
+
index[name] = value as any;
|
|
24
|
+
return true;
|
|
25
|
+
},
|
|
26
|
+
getIndexPage: async (_learnCard, name, query, paginationOptions) => {
|
|
27
|
+
_learnCard.debug?.('Test Cache, getIndex', {
|
|
28
|
+
name,
|
|
29
|
+
query,
|
|
30
|
+
paginationOptions,
|
|
31
|
+
value: index,
|
|
32
|
+
});
|
|
33
|
+
return paginatedIndex[name];
|
|
34
|
+
},
|
|
35
|
+
setIndexPage: async (_learnCard, name, query, value, paginationOptions) => {
|
|
36
|
+
_learnCard.debug?.('Test Cache, setIndex', {
|
|
37
|
+
name,
|
|
38
|
+
query,
|
|
39
|
+
paginationOptions,
|
|
40
|
+
value,
|
|
41
|
+
});
|
|
42
|
+
paginatedIndex[name] = value as any;
|
|
43
|
+
return true;
|
|
44
|
+
},
|
|
45
|
+
flushIndex: async _learnCard => {
|
|
46
|
+
_learnCard.debug?.('Test Cache, flushIndex');
|
|
47
|
+
index = {};
|
|
48
|
+
return true;
|
|
49
|
+
},
|
|
50
|
+
getVc: async (_learnCard, uri) => {
|
|
51
|
+
_learnCard.debug?.('Test Cache, getVc', { uri, value: vcs[uri] });
|
|
52
|
+
return vcs[uri];
|
|
53
|
+
},
|
|
54
|
+
setVc: async (_learnCard, uri, vc) => {
|
|
55
|
+
_learnCard.debug?.('Test Cache, setVc', { uri, value: vc });
|
|
56
|
+
vcs[uri] = vc;
|
|
57
|
+
return true;
|
|
58
|
+
},
|
|
59
|
+
flushVc: async _learnCard => {
|
|
60
|
+
_learnCard.debug?.('Test Cache, flushVc');
|
|
61
|
+
vcs = {};
|
|
62
|
+
return true;
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
methods: {},
|
|
66
|
+
};
|
|
67
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { CredentialRecord, VC } from '@learncard/types';
|
|
2
|
+
import { TestIndexPlugin } from './types';
|
|
3
|
+
|
|
4
|
+
export const getTestIndex = (): TestIndexPlugin => {
|
|
5
|
+
let index: CredentialRecord[] = [];
|
|
6
|
+
|
|
7
|
+
return {
|
|
8
|
+
name: 'Test Index',
|
|
9
|
+
displayName: 'Test Index',
|
|
10
|
+
description: '[Testing] Tests Index Implementations',
|
|
11
|
+
index: {
|
|
12
|
+
get: async (_learnCard, query) => {
|
|
13
|
+
_learnCard.debug?.('Test Storage, index, get', { query });
|
|
14
|
+
|
|
15
|
+
return index;
|
|
16
|
+
},
|
|
17
|
+
add: async (_learnCard, record) => {
|
|
18
|
+
_learnCard.debug?.('Test Storage, index, add', { record });
|
|
19
|
+
|
|
20
|
+
index.push(record);
|
|
21
|
+
|
|
22
|
+
return true;
|
|
23
|
+
},
|
|
24
|
+
update: async () => false, // TODO: Implement
|
|
25
|
+
remove: async (_learnCard, id) => {
|
|
26
|
+
_learnCard.debug?.('Test Storage, index, remove', { id });
|
|
27
|
+
|
|
28
|
+
let recordIndex = index.findIndex(record => record.id === id);
|
|
29
|
+
|
|
30
|
+
index.splice(recordIndex, 1);
|
|
31
|
+
|
|
32
|
+
return true;
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
methods: {},
|
|
36
|
+
};
|
|
37
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { CredentialRecord, StoredCredentialEnvelope, VC, VP } from '@learncard/types';
|
|
2
|
+
import { TestStoragePlugin } from './types';
|
|
3
|
+
|
|
4
|
+
type StoredItem = VC | VP | StoredCredentialEnvelope;
|
|
5
|
+
|
|
6
|
+
export const getTestStorage = (): TestStoragePlugin => {
|
|
7
|
+
const index: CredentialRecord[] = [];
|
|
8
|
+
const vcs: StoredItem[] = [];
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
name: 'Test Storage',
|
|
12
|
+
displayName: 'Test Storage',
|
|
13
|
+
description: '[Testing] Tests Storage Implementations',
|
|
14
|
+
read: {
|
|
15
|
+
get: async (_learnCard, uri) => {
|
|
16
|
+
_learnCard.debug?.('Test Storage, read, get', { uri });
|
|
17
|
+
|
|
18
|
+
if (!uri) return undefined;
|
|
19
|
+
|
|
20
|
+
const [_lc, method, vcIndex] = uri.split(':');
|
|
21
|
+
|
|
22
|
+
if (method !== 'test') return undefined;
|
|
23
|
+
|
|
24
|
+
return vcs[Number.parseInt(vcIndex)];
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
store: {
|
|
28
|
+
upload: async (_learnCard, vc) => {
|
|
29
|
+
_learnCard.debug?.('Test Storage, store, upload', { vc });
|
|
30
|
+
|
|
31
|
+
const vcIndex = vcs.length;
|
|
32
|
+
|
|
33
|
+
vcs.push(vc);
|
|
34
|
+
|
|
35
|
+
return `lc:test:${vcIndex}`;
|
|
36
|
+
},
|
|
37
|
+
delete: async (_learnCard, uri) => {
|
|
38
|
+
_learnCard.debug?.('Test Storage, store, delete', { uri });
|
|
39
|
+
|
|
40
|
+
if (!uri) return false;
|
|
41
|
+
|
|
42
|
+
const [_lc, method, vcIndex] = uri.split(':');
|
|
43
|
+
|
|
44
|
+
if (method !== 'test') return false;
|
|
45
|
+
|
|
46
|
+
const vcIdx = Number.parseInt(vcIndex);
|
|
47
|
+
|
|
48
|
+
if (vcIdx >= 0 && vcIdx < vcs.length) {
|
|
49
|
+
vcs[vcIdx] = undefined as unknown as StoredItem;
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return false;
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
index: {
|
|
57
|
+
get: async (_learnCard, query) => {
|
|
58
|
+
_learnCard.debug?.('Test Storage, index, get', { query });
|
|
59
|
+
|
|
60
|
+
return index;
|
|
61
|
+
},
|
|
62
|
+
add: async (_learnCard, record) => {
|
|
63
|
+
_learnCard.debug?.('Test Storage, index, add', { record });
|
|
64
|
+
|
|
65
|
+
index.push(record);
|
|
66
|
+
|
|
67
|
+
return true;
|
|
68
|
+
},
|
|
69
|
+
update: async () => false, // TODO: Implement
|
|
70
|
+
remove: async (_learnCard, id) => {
|
|
71
|
+
_learnCard.debug?.('Test Storage, index, remove', { id });
|
|
72
|
+
|
|
73
|
+
const recordIndex = index.findIndex(record => record.id === id);
|
|
74
|
+
|
|
75
|
+
index.splice(recordIndex, 1);
|
|
76
|
+
|
|
77
|
+
return true;
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
methods: {},
|
|
81
|
+
};
|
|
82
|
+
};
|