@ltorresu82/firmagob-client 0.1.0 → 0.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/README.md +4 -1
- package/dist/firmagob-client.d.ts +2 -1
- package/dist/firmagob-client.js +6 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# @ltorresu82/firmagob-client
|
|
2
2
|
|
|
3
|
+
[](https://github.com/ltorresu82/firmagob-client/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/@ltorresu82/firmagob-client)
|
|
5
|
+
|
|
3
6
|
Cliente TypeScript para integrar FirmaGob Chile sin depender de librerias PDF deprecadas.
|
|
4
7
|
|
|
5
8
|
Estado inicial:
|
|
@@ -50,7 +53,7 @@ const response = await client.signHashes([
|
|
|
50
53
|
]);
|
|
51
54
|
```
|
|
52
55
|
|
|
53
|
-
El JWT incluye los claims `entity`, `run`, `purpose`
|
|
56
|
+
El JWT incluye los claims `entity`, `run`, `purpose`, `expiration` e `iat`. Por defecto el token expira en 5 minutos, alineado con los ejemplos oficiales. `expiration` se serializa como `yyyy-MM-dd'T'HH:mm:ss`. Se puede ajustar con `tokenTtlSeconds` si el ambiente lo requiere.
|
|
54
57
|
|
|
55
58
|
## PDF con firma externa
|
|
56
59
|
|
package/dist/firmagob-client.js
CHANGED
|
@@ -57,12 +57,14 @@ export class FirmaGobClient {
|
|
|
57
57
|
}
|
|
58
58
|
createToken(now = new Date()) {
|
|
59
59
|
const tokenTtlSeconds = this.config.tokenTtlSeconds ?? DEFAULT_TOKEN_TTL_SECONDS;
|
|
60
|
+
const expiration = new Date(now.getTime() + tokenTtlSeconds * 1000);
|
|
60
61
|
const header = base64UrlEncodeJson({ alg: "HS256", typ: "JWT" });
|
|
61
62
|
const payload = base64UrlEncodeJson({
|
|
62
63
|
entity: this.config.entity,
|
|
63
64
|
run: this.config.run,
|
|
64
65
|
purpose: this.config.purpose ?? Purpose.Unattended,
|
|
65
|
-
expiration:
|
|
66
|
+
expiration: formatFirmaGobDateTime(expiration),
|
|
67
|
+
iat: Math.floor(now.getTime() / 1000),
|
|
66
68
|
});
|
|
67
69
|
const unsignedToken = `${header}.${payload}`;
|
|
68
70
|
const signature = createHmac("sha256", this.config.secret)
|
|
@@ -108,6 +110,9 @@ function assertRequired(name, value) {
|
|
|
108
110
|
function base64UrlEncodeJson(value) {
|
|
109
111
|
return Buffer.from(JSON.stringify(value)).toString("base64url");
|
|
110
112
|
}
|
|
113
|
+
function formatFirmaGobDateTime(date) {
|
|
114
|
+
return date.toISOString().slice(0, 19);
|
|
115
|
+
}
|
|
111
116
|
function parseJsonResponse(body) {
|
|
112
117
|
try {
|
|
113
118
|
return JSON.parse(body);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ltorresu82/firmagob-client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Cliente TypeScript para integrar FirmaGob Chile con firma por hash y PDFs firmados externamente",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"clean": "node -e \"import('node:fs').then(fs => fs.rmSync('dist', { recursive: true, force: true }))\"",
|
|
17
17
|
"build": "npm run clean && tsc -p tsconfig.build.json",
|
|
18
18
|
"build:test": "npm run clean && tsc -p tsconfig.json",
|
|
19
|
-
"test": "npm run build:test && node --test dist
|
|
19
|
+
"test": "npm run build:test && node --test dist/firmagob-client.test.js dist/pdf-external-signature.test.js",
|
|
20
20
|
"validate:sandbox": "npm run build && node examples/sign-hash-sandbox.js",
|
|
21
21
|
"validate:sandbox:dry-run": "npm run build && node examples/sign-hash-sandbox.js --dry-run",
|
|
22
22
|
"publish:dry-run": "npm publish --dry-run --access public",
|