spd-lib 1.0.9 → 1.1.1
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/index.js +22 -16
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -44,10 +44,7 @@ this.salt = salt;
|
|
|
44
44
|
throw new Error('Invalid output path or salt.');
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
const
|
|
48
|
-
publicKey: Array.from(this.keyPair.publicKey)
|
|
49
|
-
};
|
|
50
|
-
const spdData = JSON.stringify({ keyPair, data: this.data, salt: Array.from(this.salt) });
|
|
47
|
+
const spdData = JSON.stringify({ data: this.data, salt: Array.from(this.salt) });
|
|
51
48
|
const compressedSpdData = zlib.deflateSync(spdData);
|
|
52
49
|
fs.writeFileSync(outputPath, compressedSpdData, { mode: 0o600 });
|
|
53
50
|
}
|
|
@@ -61,14 +58,14 @@ this.salt = salt;
|
|
|
61
58
|
await sodium.ready;
|
|
62
59
|
const compressedSpdData = fs.readFileSync(spdPath);
|
|
63
60
|
const spdData = zlib.inflateSync(compressedSpdData).toString('utf8');
|
|
64
|
-
const {
|
|
61
|
+
const { data, salt } = JSON.parse(spdData);
|
|
65
62
|
|
|
66
63
|
const { pqcKey } = await new SPD().convertPasscodeToPQCKeySalted(passcode, new Uint8Array(salt));
|
|
67
64
|
const pbk = pqcKey.publicKey;
|
|
68
65
|
const spd = new SPD();
|
|
69
66
|
spd.userKey = pbk;
|
|
70
67
|
spd.keyPair = {
|
|
71
|
-
publicKey:
|
|
68
|
+
publicKey: pbk.publicKey
|
|
72
69
|
};
|
|
73
70
|
spd.data = data.map(dat => ({
|
|
74
71
|
dataName: dat.dataName,
|
|
@@ -117,15 +114,12 @@ this.salt = salt;
|
|
|
117
114
|
}
|
|
118
115
|
|
|
119
116
|
saveData() {
|
|
120
|
-
const
|
|
121
|
-
publicKey: Array.from(this.keyPair.publicKey)
|
|
122
|
-
};
|
|
123
|
-
const spdData = JSON.stringify({ keyPair, data: this.data, salt: Array.from(this.salt) });
|
|
117
|
+
const spdData = JSON.stringify({ data: this.data, salt: Array.from(this.salt) });
|
|
124
118
|
const compressedSpdData = zlib.deflateSync(spdData);
|
|
125
119
|
return compressedSpdData;
|
|
126
120
|
}
|
|
127
121
|
|
|
128
|
-
async loadFromString(spdData, passcode) {
|
|
122
|
+
static async loadFromString(spdData, passcode) {
|
|
129
123
|
if (!spdData || typeof spdData !== 'string' || !spdData.trim() || !passcode || typeof passcode !== 'string' || !passcode.trim()) {
|
|
130
124
|
throw new Error('Invalid SPD path or passcode.');
|
|
131
125
|
}
|
|
@@ -133,14 +127,14 @@ this.salt = salt;
|
|
|
133
127
|
await sodium.ready;
|
|
134
128
|
const spdDataBuffer = Buffer.from(spdData, 'base64');
|
|
135
129
|
const spdData2 = zlib.inflateSync(spdDataBuffer).toString('utf8');
|
|
136
|
-
const {
|
|
130
|
+
const { data, salt } = JSON.parse(spdData2);
|
|
137
131
|
|
|
138
132
|
const { pqcKey } = await new SPD().convertPasscodeToPQCKeySalted(passcode, new Uint8Array(salt));
|
|
139
133
|
const pbk = pqcKey.publicKey;
|
|
140
134
|
const spd = new SPD();
|
|
141
135
|
spd.userKey = pbk;
|
|
142
136
|
spd.keyPair = {
|
|
143
|
-
publicKey:
|
|
137
|
+
publicKey: pbk.publicKey
|
|
144
138
|
};
|
|
145
139
|
spd.data = data.map(dat => ({
|
|
146
140
|
dataName: dat.dataName,
|
|
@@ -297,6 +291,18 @@ this.salt = salt;
|
|
|
297
291
|
}
|
|
298
292
|
}
|
|
299
293
|
|
|
300
|
-
|
|
301
|
-
SPD
|
|
302
|
-
|
|
294
|
+
(async()=>{
|
|
295
|
+
const spd = new SPD();
|
|
296
|
+
const passcode = 'thisisatests';
|
|
297
|
+
await spd.setPassKey(passcode);
|
|
298
|
+
await spd.addData('test', 'test');
|
|
299
|
+
const data = spd.saveData().toString('base64')
|
|
300
|
+
console.log(data)
|
|
301
|
+
const LSPD =await SPD.loadFromString(data,passcode)
|
|
302
|
+
const ED = await LSPD.extractData();
|
|
303
|
+
console.log(ED);
|
|
304
|
+
})()
|
|
305
|
+
|
|
306
|
+
//module.exports = {
|
|
307
|
+
// SPD,
|
|
308
|
+
//};
|