@dotrino/identity 0.83.1 → 0.84.0
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 +17 -0
- package/package.json +1 -1
- package/src/index.d.ts +2 -0
- package/src/index.js +1 -1
- package/vault/assertion.js +39 -1
package/README.md
CHANGED
|
@@ -143,6 +143,23 @@ const v = await verifyAssertion(prueba, { audience: 'https://proxy.dotrino.com',
|
|
|
143
143
|
- **Verificar no necesita el iframe ni clave alguna**: `@dotrino/identity/assertion` es un
|
|
144
144
|
módulo puro y lo puede importar un servidor.
|
|
145
145
|
|
|
146
|
+
**Y su hermana, para lo que se publica** (0.84.0+). Un pin de geo o una atestación de
|
|
147
|
+
reputación se firman y se sueltan: no hay nadie al otro lado que pueda dar un reto de
|
|
148
|
+
antemano, así que ahí no cabe una prueba entera — lo que falta es el destinatario, y solo
|
|
149
|
+
eso. Sin él, un pin firmado para geo lo acepta igual reputación.
|
|
150
|
+
|
|
151
|
+
```js
|
|
152
|
+
import { verifySignedFor } from '@dotrino/identity/assertion'
|
|
153
|
+
|
|
154
|
+
const pin = { op: 'pin', aud: 'https://geo.dotrino.com', lat, lon, iat: Date.now() }
|
|
155
|
+
const { signature, publickey, chain } = await id.signData(pin)
|
|
156
|
+
// en el servidor:
|
|
157
|
+
const v = await verifySignedFor({ data: pin, signature, publickey, chain, audience: 'https://geo.dotrino.com' })
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
`aud` es obligatorio igual que en la prueba; `exp` es opcional, porque la caducidad de lo
|
|
161
|
+
publicado la lleva el servicio (el TTL del pin) y no el cuerpo.
|
|
162
|
+
|
|
146
163
|
Diseño y hacia dónde va (inicio de sesión y federación):
|
|
147
164
|
[`dotrino-vault/docs/inicio-de-sesion.md`](../dotrino-vault/docs/inicio-de-sesion.md).
|
|
148
165
|
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -270,3 +270,5 @@ export function claimsAllowed (scopes?: string[]): Set<string>
|
|
|
270
270
|
export function assertionBody (args: { sub: string; aud: string; nonce: string; scopes?: string[]; claims?: AssertionClaims; iat: number; exp: number }): Omit<Assertion, 'signature' | 'publickey' | 'chain'>
|
|
271
271
|
/** ¿Vale esta prueba, PARA MÍ y AHORA? `audience` y `nonce` son obligatorios; sin modo permisivo. */
|
|
272
272
|
export function verifyAssertion (assertion: Assertion, opts: { audience: string; nonce: string; expectedProfileId?: string | null; now?: number; maxSkewMs?: number }): Promise<VerifiedAssertion>
|
|
273
|
+
/** ¿Este contenido firmado (un pin, una atestación) va dirigido a mí? `aud` obligatorio; `exp` opcional. */
|
|
274
|
+
export function verifySignedFor (args: { data: any; signature: string; publickey: string; chain: any[]; audience: string; expectedProfileId?: string | null; now?: number; maxSkewMs?: number }): Promise<{ ok: boolean; reason?: string; profileId?: string; signer?: string; seq?: number; aud?: string }>
|
package/src/index.js
CHANGED
|
@@ -740,4 +740,4 @@ export { makeDeviceKey, makeDeviceEncKey, importDeviceEncKey, signWithDevice, ve
|
|
|
740
740
|
// PARA QUIÉN vale una firma, y hasta cuándo. Verificar NO necesita el iframe ni la clave
|
|
741
741
|
// de nadie, así que un servicio puede importarlo suelto (`@dotrino/identity/assertion`, que
|
|
742
742
|
// no arrastra el cliente del vault); aquí se reexporta para quien ya tiene esto cargado.
|
|
743
|
-
export { verifyAssertion, newAssertionNonce, cleanScopes, claimsAllowed, assertionBody, SCOPES, SCOPE_CLAIMS, ASSERTION_MAX_TTL_MS, ASSERTION_DEFAULT_TTL_MS, ASSERTION_MAX_SKEW_MS } from '../vault/assertion.js'
|
|
743
|
+
export { verifyAssertion, verifySignedFor, newAssertionNonce, cleanScopes, claimsAllowed, assertionBody, SCOPES, SCOPE_CLAIMS, ASSERTION_MAX_TTL_MS, ASSERTION_DEFAULT_TTL_MS, ASSERTION_MAX_SKEW_MS } from '../vault/assertion.js'
|
package/vault/assertion.js
CHANGED
|
@@ -174,4 +174,42 @@ export async function verifyAssertion (assertion, opts = {}) {
|
|
|
174
174
|
return { ok: true, profileId: v.profileId, signer: v.signer, seq: v.seq, scopes: [...a.scopes], claims: { ...(a.claims || {}) }, aud: a.aud, exp: a.exp }
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
|
|
177
|
+
/**
|
|
178
|
+
* ¿ESTE CONTENIDO FIRMADO VA DIRIGIDO A MÍ? La otra mitad del destinatario, y **no es lo
|
|
179
|
+
* mismo que una prueba**: conviene tener claras las dos, porque confundirlas lleva a pedir
|
|
180
|
+
* un reto donde no hay quien lo emita.
|
|
181
|
+
*
|
|
182
|
+
* · **Prueba** (`verifyAssertion`) — autenticación INTERACTIVA: alguien me habla, yo le
|
|
183
|
+
* mando un reto y quiero saber quién es AHORA. Lleva `nonce` porque hay dos partes.
|
|
184
|
+
* · **Contenido dirigido** (esto) — un pin de geo, una atestación de reputación: se
|
|
185
|
+
* firma y se publica, sin nadie al otro lado que pueda dar un reto de antemano. Lo que
|
|
186
|
+
* falta ahí es `aud`, y solo `aud`: sin él, un pin firmado para geo lo acepta igual
|
|
187
|
+
* reputación.
|
|
188
|
+
*
|
|
189
|
+
* `aud` es obligatorio, como en la prueba. `exp` es OPCIONAL, y esa es la diferencia real:
|
|
190
|
+
* lo publicado tiene su propia caducidad (el TTL del pin, la vigencia de la atestación) y
|
|
191
|
+
* quien la lleva es el servicio; si el cuerpo trae `exp`, se respeta.
|
|
192
|
+
*/
|
|
193
|
+
/**
|
|
194
|
+
* @param {{ data?: any, signature?: string, publickey?: string, chain?: any[], audience?: string, expectedProfileId?: string|null, now?: number, maxSkewMs?: number }} [args]
|
|
195
|
+
*/
|
|
196
|
+
export async function verifySignedFor (args = {}) {
|
|
197
|
+
const { data, signature, publickey, chain, audience, expectedProfileId = null, now = Date.now(), maxSkewMs = ASSERTION_MAX_SKEW_MS } = args
|
|
198
|
+
if (typeof audience !== 'string' || !audience.trim()) return { ok: false, reason: 'no-audience' }
|
|
199
|
+
if (!data || typeof data !== 'object') return { ok: false, reason: 'shape' }
|
|
200
|
+
if (typeof data.aud !== 'string' || !data.aud) return { ok: false, reason: 'sin-destinatario' }
|
|
201
|
+
if (data.aud !== audience.trim()) return { ok: false, reason: 'otro-destinatario' }
|
|
202
|
+
if (data.exp != null) {
|
|
203
|
+
if (!Number.isFinite(data.exp)) return { ok: false, reason: 'shape' }
|
|
204
|
+
if (data.exp <= now) return { ok: false, reason: 'vencida' }
|
|
205
|
+
}
|
|
206
|
+
if (data.iat != null) {
|
|
207
|
+
if (!Number.isFinite(data.iat)) return { ok: false, reason: 'shape' }
|
|
208
|
+
if (data.iat > now + maxSkewMs) return { ok: false, reason: 'del-futuro' }
|
|
209
|
+
}
|
|
210
|
+
const v = await verifySignedBy({ data, signature, publickey, chain, expectedProfileId })
|
|
211
|
+
if (!v.ok) return { ok: false, reason: 'firma:' + v.reason }
|
|
212
|
+
return { ok: true, profileId: v.profileId, signer: v.signer, seq: v.seq, aud: data.aud }
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export default { ASSERTION_V, ASSERTION_MAX_TTL_MS, ASSERTION_DEFAULT_TTL_MS, ASSERTION_MAX_SKEW_MS, SCOPES, SCOPE_CLAIMS, newAssertionNonce, cleanScopes, claimsAllowed, assertionBody, verifyAssertion, verifySignedFor }
|