@dotrino/geo 0.8.0 → 0.9.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/LICENSE +0 -0
- package/README.md +0 -0
- package/package.json +1 -1
- package/src/canonical.js +0 -0
- package/src/geohash.js +0 -0
- package/src/index.d.ts +0 -0
- package/src/index.js +16 -3
package/LICENSE
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
File without changes
|
package/package.json
CHANGED
package/src/canonical.js
CHANGED
|
File without changes
|
package/src/geohash.js
CHANGED
|
File without changes
|
package/src/index.d.ts
CHANGED
|
File without changes
|
package/src/index.js
CHANGED
|
@@ -45,6 +45,11 @@ export function createGeoClient ({ signData, getPublicKeyJwk, baseUrl = DEFAULT_
|
|
|
45
45
|
const doFetch = f || (typeof fetch !== 'undefined' ? fetch.bind(globalThis) : null)
|
|
46
46
|
if (!doFetch) throw new Error('dotrino-geo: no fetch available; inject it in opts.fetch')
|
|
47
47
|
const base = baseUrl.replace(/\/+$/, '')
|
|
48
|
+
// PARA QUIÉN va lo que firmamos. Sale del `baseUrl` y no de una constante: quien
|
|
49
|
+
// autohospeda su índice tiene otro destinatario, y tenerlo fijo haría que un pin firmado
|
|
50
|
+
// para el nuestro sirviera ante el suyo — que es justo lo que el destinatario evita.
|
|
51
|
+
// Si el `baseUrl` no es una URL, revienta AQUÍ, al crear el cliente, y no al publicar.
|
|
52
|
+
const aud = new URL(base).origin
|
|
48
53
|
|
|
49
54
|
/**
|
|
50
55
|
* Publica (o reemplaza) el pin de esta identidad.
|
|
@@ -68,6 +73,7 @@ export function createGeoClient ({ signData, getPublicKeyJwk, baseUrl = DEFAULT_
|
|
|
68
73
|
const ts = now ?? Date.now()
|
|
69
74
|
const data = {
|
|
70
75
|
publickey,
|
|
76
|
+
aud,
|
|
71
77
|
lat: round(lat, 6),
|
|
72
78
|
lng: round(lng, 6),
|
|
73
79
|
geohash: encodeGeohash(lat, lng, geohashPrecision),
|
|
@@ -122,12 +128,19 @@ export function createGeoClient ({ signData, getPublicKeyJwk, baseUrl = DEFAULT_
|
|
|
122
128
|
*/
|
|
123
129
|
async function removePin ({ now } = {}) {
|
|
124
130
|
const publickey = await getPublicKeyJwk()
|
|
125
|
-
const data = { publickey, action: 'remove', issuedAt: now ?? Date.now() }
|
|
126
|
-
|
|
131
|
+
const data = { publickey, aud, action: 'remove', issuedAt: now ?? Date.now() }
|
|
132
|
+
// MANDABA EL PAQUETE ENTERO EN `signature`. `signData` devuelve `{signature, publickey,
|
|
133
|
+
// chain}` desde hace versiones, y aquí se metía ese objeto donde el servidor espera la
|
|
134
|
+
// firma en base64: retirar un pin antes de que expirara respondía 401 siempre. Y sin la
|
|
135
|
+
// cadena tampoco se podía retirar el pin desde un aparato que no fuera el de la llave.
|
|
136
|
+
const firma = await signData(data)
|
|
137
|
+
const sobre = typeof firma === 'string'
|
|
138
|
+
? { data, signature: firma }
|
|
139
|
+
: { data, signature: firma.signature, ...(firma.publickey ? { signer: firma.publickey } : {}), ...(firma.chain?.length ? { chain: firma.chain } : {}) }
|
|
127
140
|
const res = await doFetch(`${base}/pins`, {
|
|
128
141
|
method: 'DELETE',
|
|
129
142
|
headers: { 'content-type': 'application/json' },
|
|
130
|
-
body: JSON.stringify(
|
|
143
|
+
body: JSON.stringify(sobre)
|
|
131
144
|
})
|
|
132
145
|
return handle(res)
|
|
133
146
|
}
|