@dotrino/vaultd 0.162.1 → 0.162.2
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/lib/src/core/libVersion.js +1 -1
- package/lib/src/sealed.js +7 -36
- package/package.json +1 -1
package/lib/src/sealed.js
CHANGED
|
@@ -16,30 +16,13 @@
|
|
|
16
16
|
* P-256 + AES-GCM, llaves como JWK string.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
function b64 (buf) {
|
|
22
|
-
const bytes = new Uint8Array(buf)
|
|
23
|
-
let s = ''
|
|
24
|
-
for (let i = 0; i < bytes.length; i++) s += String.fromCharCode(bytes[i])
|
|
25
|
-
return btoa(s)
|
|
26
|
-
}
|
|
19
|
+
import { wrapForMember, openWrap } from '@dotrino/identity/content'
|
|
27
20
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i)
|
|
32
|
-
return out
|
|
33
|
-
}
|
|
21
|
+
// El sobre es el MISMO que el de las llaves de contenido de identity (ECDH P-256 efímero
|
|
22
|
+
// → AES-256-GCM, `epk` en JWK): aquí solo se le mete un JSON en vez de una CEK. Antes
|
|
23
|
+
// estaba escrito otra vez en este archivo, byte a byte igual.
|
|
34
24
|
|
|
35
|
-
|
|
36
|
-
const pub = await subtle.importKey(
|
|
37
|
-
'jwk', JSON.parse(publicJwkStr),
|
|
38
|
-
{ name: 'ECDH', namedCurve: 'P-256' }, false, []
|
|
39
|
-
)
|
|
40
|
-
const bits = await subtle.deriveBits({ name: 'ECDH', public: pub }, privateKey, 256)
|
|
41
|
-
return subtle.importKey('raw', bits, { name: 'AES-GCM' }, false, ['encrypt', 'decrypt'])
|
|
42
|
-
}
|
|
25
|
+
const subtle = globalThis.crypto.subtle
|
|
43
26
|
|
|
44
27
|
/**
|
|
45
28
|
* Genera la llave ECDH EFÍMERA del solicitante (una por petición).
|
|
@@ -57,17 +40,7 @@ export async function makeEphemeralKey () {
|
|
|
57
40
|
* @returns {Promise<{epk:string, iv:string, ct:string}>}
|
|
58
41
|
*/
|
|
59
42
|
export async function seal ({ ek, payload }) {
|
|
60
|
-
|
|
61
|
-
const key = await deriveAesKey(eph.privateKey, ek)
|
|
62
|
-
const iv = globalThis.crypto.getRandomValues(new Uint8Array(12))
|
|
63
|
-
const pt = new TextEncoder().encode(JSON.stringify(payload))
|
|
64
|
-
const ct = await subtle.encrypt({ name: 'AES-GCM', iv }, key, pt)
|
|
65
|
-
const epkJwk = await subtle.exportKey('jwk', eph.publicKey)
|
|
66
|
-
return {
|
|
67
|
-
epk: JSON.stringify({ kty: epkJwk.kty, crv: epkJwk.crv, x: epkJwk.x, y: epkJwk.y }),
|
|
68
|
-
iv: b64(iv),
|
|
69
|
-
ct: b64(ct)
|
|
70
|
-
}
|
|
43
|
+
return wrapForMember({ cek: JSON.stringify(payload), memberEncPub: ek })
|
|
71
44
|
}
|
|
72
45
|
|
|
73
46
|
/**
|
|
@@ -78,7 +51,5 @@ export async function openSealed ({ privateKey, enc }) {
|
|
|
78
51
|
if (!enc || typeof enc.epk !== 'string' || typeof enc.iv !== 'string' || typeof enc.ct !== 'string') {
|
|
79
52
|
throw new Error('invalid sealed envelope')
|
|
80
53
|
}
|
|
81
|
-
|
|
82
|
-
const pt = await subtle.decrypt({ name: 'AES-GCM', iv: fromB64(enc.iv) }, key, fromB64(enc.ct))
|
|
83
|
-
return JSON.parse(new TextDecoder().decode(pt))
|
|
54
|
+
return JSON.parse(await openWrap({ wrap: enc, myEncPrivateKey: privateKey }))
|
|
84
55
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/vaultd",
|
|
3
|
-
"version": "0.162.
|
|
3
|
+
"version": "0.162.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Certificador personal de Dotrino: daemon headless que custodia la clave maestra y delega capacidades a tus dispositivos por el proxy. Tu CA propia.",
|
|
6
6
|
"bin": {
|