MCPcopy Create free account
hub / github.com/DeepNotesApp/DeepNotes / Keyring

Class Keyring

packages/@stdlib/crypto/src/keyrings/keyring.ts:30–168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28 });
29
30 return new (class Keyring implements Wrappable, IKeyring {
31 keys: Uint8Array[] = [];
32
33 constructor() {
34 if (_wrappedData.topLayer !== DataLayer.Raw) {
35 return;
36 }
37
38 this.keys = decodeKeys(_wrappedData.content);
39
40 if (_wrappedData.metadata.keys == null) {
41 _wrappedData.metadata.keys = new Array(this.keys.length).fill({
42 rotationDate: new Date(),
43 });
44 }
45
46 this.trimExpiredKeys();
47 }
48
49 trimExpiredKeys() {
50 if (_wrappedData.topLayer !== DataLayer.Raw) {
51 throw new Error('Cannot trim keys on non-raw keyring.');
52 }
53
54 const currentDate = new Date();
55
56 const unexpiredIndexes = this.keys
57 .map((_, index) => index)
58 .filter((index) => {
59 return (
60 index === 0 ||
61 addDays(_wrappedData.metadata.keys[index].rotationDate, 1) >
62 currentDate
63 );
64 });
65
66 this.keys = this.keys.filter((_, index) =>
67 unexpiredIndexes.includes(index),
68 );
69 _wrappedData.content = encodeKeys(this.keys);
70
71 _wrappedData.metadata.keys = _wrappedData.metadata.keys.filter(
72 (_, index) => unexpiredIndexes.includes(index),
73 );
74 }
75
76 get layers() {
77 return _wrappedData.layers;
78 }
79 get topLayer() {
80 return _wrappedData.topLayer;
81 }
82 hasLayer(layer: DataLayer) {
83 return _wrappedData.hasLayer(layer);
84 }
85 countLayerType(layer: DataLayer) {
86 return _wrappedData.countLayerType(layer);
87 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected