spd-lib 1.1.3 → 1.1.5

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.
Files changed (2) hide show
  1. package/index.js +25 -8
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -51,8 +51,10 @@ this.salt = salt;
51
51
 
52
52
 
53
53
  static async loadFromFile(spdPath, passcode) {
54
+ return new Promise(async (res,rej)=>{
55
+ try{
54
56
  if (!spdPath || typeof spdPath !== 'string' || !spdPath.trim() || !passcode || typeof passcode !== 'string' || !passcode.trim()) {
55
- throw new Error('Invalid SPD path or passcode.');
57
+ rej(new Error('Invalid SPD path or passcode.'));
56
58
  }
57
59
 
58
60
  await sodium.ready;
@@ -77,13 +79,19 @@ this.salt = salt;
77
79
  spd.data.forEach(dat => {
78
80
  const calculatedHash = crypto.createHash('sha256').update(Buffer.from(dat.data)).digest('hex');
79
81
  if (calculatedHash !== dat.hash) {
80
- throw new Error(`Data integrity check failed for ${dat.dataName}`);
82
+ rej(new Error(`Data integrity check failed for ${dat.dataName}`));
81
83
  }
82
84
  });
83
- return spd;
85
+ res(spd);
86
+ }catch{
87
+ rej()
88
+ }
89
+ })
84
90
  }
85
91
 
86
92
  async extractData() {
93
+ return new Promise(async(res,rej)=>{
94
+ try{
87
95
  await sodium.ready;
88
96
  let extractedFiles = {};
89
97
  this.data.forEach(async dat => {
@@ -92,7 +100,11 @@ this.salt = salt;
92
100
  const dt = decompressedData.toString('utf8');
93
101
  extractedFiles[dat.dataName] = await this.CSTI(dt, dat.dataType);
94
102
  });
95
- return extractedFiles;
103
+ res(extractedFiles);
104
+ }catch{
105
+ rej()
106
+ }
107
+ })
96
108
  }
97
109
 
98
110
 
@@ -120,15 +132,16 @@ this.salt = salt;
120
132
  }
121
133
 
122
134
  static async loadFromString(spdData, passcode) {
135
+ return new Promise(async (res,rej)=>{
136
+ try{
123
137
  if (!spdData || typeof spdData !== 'string' || !spdData.trim() || !passcode || typeof passcode !== 'string' || !passcode.trim()) {
124
- throw new Error('Invalid SPD path or passcode.');
138
+ rej(new Error('Invalid SPD path or passcode.'));
125
139
  }
126
140
 
127
141
  await sodium.ready;
128
142
  const spdDataBuffer = Buffer.from(spdData, 'base64');
129
143
  const spdData2 = zlib.inflateSync(spdDataBuffer).toString('utf8');
130
144
  const { data, salt } = JSON.parse(spdData2);
131
-
132
145
  const { pqcKey } = await new SPD().convertPasscodeToPQCKeySalted(passcode, new Uint8Array(salt));
133
146
  const pbk = pqcKey.publicKey;
134
147
  const spd = new SPD();
@@ -146,10 +159,14 @@ this.salt = salt;
146
159
  spd.data.forEach(dat => {
147
160
  const calculatedHash = crypto.createHash('sha256').update(Buffer.from(dat.data)).digest('hex');
148
161
  if (calculatedHash !== dat.hash) {
149
- throw new Error(`Data integrity check failed for ${dat.dataName}`);
162
+ rej(new Error(`Data integrity check failed for ${dat.dataName}`));
150
163
  }
151
164
  });
152
- return spd;
165
+ res(spd);
166
+ }catch{
167
+ rej()
168
+ }
169
+ })
153
170
  }
154
171
 
155
172
  async convertPasscodeToPQCKeySalted(passcode, salt) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spd-lib",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "SPD or Secure Packaged Data is a compress PQC protected file format to store sensitive data localy",
5
5
  "main": "index.js",
6
6
  "scripts": {