@imolko/ultra-event-signature 0.1.0-beta → 0.2.0-beta
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 +103 -7
- package/dist-node/canonical-json.d.ts +10 -0
- package/dist-node/canonical-json.d.ts.map +1 -0
- package/dist-node/canonical-json.js +148 -0
- package/dist-node/canonical-json.js.map +1 -0
- package/dist-node/crypto.d.ts +26 -0
- package/dist-node/crypto.d.ts.map +1 -0
- package/dist-node/crypto.js +48 -0
- package/dist-node/crypto.js.map +1 -0
- package/dist-node/dsse.d.ts +11 -0
- package/dist-node/dsse.d.ts.map +1 -0
- package/dist-node/dsse.js +67 -0
- package/dist-node/dsse.js.map +1 -0
- package/dist-node/errors.d.ts +26 -0
- package/dist-node/errors.d.ts.map +1 -0
- package/dist-node/errors.js +52 -0
- package/dist-node/errors.js.map +1 -0
- package/dist-node/index.d.ts +15 -8
- package/dist-node/index.d.ts.map +1 -1
- package/dist-node/index.js +22 -9
- package/dist-node/index.js.map +1 -1
- package/dist-node/key-set.d.ts +9 -0
- package/dist-node/key-set.d.ts.map +1 -0
- package/dist-node/key-set.js +120 -0
- package/dist-node/key-set.js.map +1 -0
- package/dist-node/pae.d.ts +18 -0
- package/dist-node/pae.d.ts.map +1 -0
- package/dist-node/pae.js +30 -0
- package/dist-node/pae.js.map +1 -0
- package/dist-node/patterns.d.ts +13 -0
- package/dist-node/patterns.d.ts.map +1 -0
- package/dist-node/patterns.js +16 -0
- package/dist-node/patterns.js.map +1 -0
- package/dist-node/payload-type.d.ts +10 -0
- package/dist-node/payload-type.d.ts.map +1 -0
- package/dist-node/payload-type.js +49 -0
- package/dist-node/payload-type.js.map +1 -0
- package/dist-node/policy-evaluation.d.ts +34 -0
- package/dist-node/policy-evaluation.d.ts.map +1 -0
- package/dist-node/policy-evaluation.js +121 -0
- package/dist-node/policy-evaluation.js.map +1 -0
- package/dist-node/policy.d.ts +13 -0
- package/dist-node/policy.d.ts.map +1 -0
- package/dist-node/policy.js +156 -0
- package/dist-node/policy.js.map +1 -0
- package/dist-node/sign.d.ts +13 -0
- package/dist-node/sign.d.ts.map +1 -0
- package/dist-node/sign.js +94 -0
- package/dist-node/sign.js.map +1 -0
- package/dist-node/types.d.ts +122 -0
- package/dist-node/types.d.ts.map +1 -0
- package/dist-node/types.js +3 -0
- package/dist-node/types.js.map +1 -0
- package/dist-node/verify.d.ts +10 -0
- package/dist-node/verify.d.ts.map +1 -0
- package/dist-node/verify.js +171 -0
- package/dist-node/verify.js.map +1 -0
- package/docs/emitter-checklist.md +120 -0
- package/package.json +11 -5
package/README.md
CHANGED
|
@@ -22,6 +22,87 @@ Custody never enters this package: private keys and key sets arrive as arguments
|
|
|
22
22
|
A library that can read a key from disk or from the environment is a library that
|
|
23
23
|
will.
|
|
24
24
|
|
|
25
|
+
## Public surface
|
|
26
|
+
|
|
27
|
+
| Export | Status |
|
|
28
|
+
|---|---|
|
|
29
|
+
| `SIGNATURE_FORMAT_VERSION`, `DSSE_PREAMBLE`, `SIGNATURE_ALGORITHM`, `PAE_DIGEST_ALGORITHM` | exported |
|
|
30
|
+
| `signFact`, `verifyFact` | spec 1, S2 |
|
|
31
|
+
| `parseKeySet`, `parseTrustPolicy` | spec 1, S3 |
|
|
32
|
+
| `factPayloadType`, `toDsseEnvelope` | spec 1, S4 |
|
|
33
|
+
| `signFactKey`, `verifyFactKeyBundle`, `factKeyFingerprint` | spec 2, S6 |
|
|
34
|
+
|
|
35
|
+
The canonical JSON and the PAE are internal on purpose: a consumer that can call
|
|
36
|
+
them can get them half-right. The only published derivation is
|
|
37
|
+
`factPayloadType`, which returns the `payloadType` the format signs. The pure
|
|
38
|
+
entry point imports only `node:crypto`; the CLI lives in `bin/` and is imported
|
|
39
|
+
by nothing in `dist-node/index.js`.
|
|
40
|
+
|
|
41
|
+
## Interoperability helpers
|
|
42
|
+
|
|
43
|
+
Two helpers convert a fact into the shapes the rest of the ecosystem speaks,
|
|
44
|
+
without turning the converter into a verdict:
|
|
45
|
+
|
|
46
|
+
- `factPayloadType(envelope)` derives
|
|
47
|
+
`application/vnd.nixailabs.fact.<type>.<dataVersion>+json`, where `dataVersion`
|
|
48
|
+
is the last path segment of `dataschema`. A missing `type`/`dataschema`, an
|
|
49
|
+
empty version or a version containing `?`/`#` is `invalid`.
|
|
50
|
+
- `toDsseEnvelope(signed)` emits the DSSE statement of [05 §6](docs/spec/05-integration.md):
|
|
51
|
+
`payload` is base64 **standard** of the canonical covered content and `sig` is
|
|
52
|
+
base64 **standard** of the same 64 signature bytes. It does not verify the
|
|
53
|
+
signature, consult the key set or evaluate the policy.
|
|
54
|
+
|
|
55
|
+
Both return a flat `ParseResult` (`{ kind: 'parsed', value }` or
|
|
56
|
+
`{ kind: 'invalid', issues }`) and never throw.
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import { factPayloadType, toDsseEnvelope } from "@imolko/ultra-event-signature";
|
|
60
|
+
|
|
61
|
+
const payloadType = factPayloadType(signedEnvelope);
|
|
62
|
+
if (payloadType.kind === "parsed") {
|
|
63
|
+
console.log(payloadType.value);
|
|
64
|
+
// application/vnd.nixailabs.fact.com.example.v1.ping.1.0.0+json
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const dsse = toDsseEnvelope(signedEnvelope);
|
|
68
|
+
if (dsse.kind === "parsed") {
|
|
69
|
+
console.log(dsse.value.signatures[0].keyid); // securityKeyId
|
|
70
|
+
console.log(dsse.value.payload); // base64(canonicalJson(covered))
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Because the payload and the signature are the ones the fact already carries,
|
|
75
|
+
stock DSSE tooling, `cosign` and a transparency log consume a fact without a
|
|
76
|
+
custom verifier.
|
|
77
|
+
|
|
78
|
+
## Emitter kit
|
|
79
|
+
|
|
80
|
+
The flow an emitter needs before its first production fact is written down so it
|
|
81
|
+
can be handed over without the surrounding conversation:
|
|
82
|
+
|
|
83
|
+
- [**Emitter checklist**](docs/emitter-checklist.md) — the ten items of
|
|
84
|
+
[05 §1](docs/spec/05-integration.md#1-the-emitter-kit), the integer-only rule
|
|
85
|
+
for `data`, add-then-cut rotation and the custody warning.
|
|
86
|
+
- [**Runnable signer**](examples/emitter-sign.mjs) — signs the `minimal-ping`
|
|
87
|
+
vector, verifies it against a test key set and policy, and prints the verdict,
|
|
88
|
+
the `securityKeyId` and the signature. Run it after `npm run build` with
|
|
89
|
+
`npm run example:sign`.
|
|
90
|
+
|
|
91
|
+
The signer uses the test key from [04 §1](docs/spec/04-conformance.md#1-the-test-key).
|
|
92
|
+
That key is **publicly known**: it exists to compare bytes and must never be
|
|
93
|
+
used in a production key set, policy or image.
|
|
94
|
+
|
|
95
|
+
## Delivery tools
|
|
96
|
+
|
|
97
|
+
- **CLI** under `bin/` (spec 2): builds, signs, verifies and fingerprints a
|
|
98
|
+
fact-key bundle, and reports the document digest and the key fingerprint.
|
|
99
|
+
- **CI component** (spec 3): wraps the CLI in a reusable pipeline job. Its
|
|
100
|
+
self-test accepts the published vector and rejects a mutated bundle.
|
|
101
|
+
|
|
102
|
+
Both are delivery, not custody. They receive key material as arguments, never
|
|
103
|
+
store it, and a valid bundle never grants the key any authority — the policy in
|
|
104
|
+
[03 — trust policy](docs/spec/03-trust-policy.md) decides what a key may sign.
|
|
105
|
+
|
|
25
106
|
## Why a separate package
|
|
26
107
|
|
|
27
108
|
`@imolko/ultra-ddd` already has the two insertion points for event signing
|
|
@@ -55,16 +136,31 @@ and [`vectors/fact-key.v1.json`](vectors/fact-key.v1.json).
|
|
|
55
136
|
|
|
56
137
|
## Status
|
|
57
138
|
|
|
58
|
-
**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
the
|
|
62
|
-
|
|
139
|
+
**Wave A implemented.** `src/index.ts` exports the format constants, `signFact`,
|
|
140
|
+
`verifyFact`, the key-set and trust-policy parsers, and the interoperability
|
|
141
|
+
helpers. The fact-key bundle, its CLI under `bin/` and the reusable CI component
|
|
142
|
+
land in the next two specs. The wire format and its vectors are frozen, and the
|
|
143
|
+
package still has zero runtime dependencies — the only runtime import is
|
|
144
|
+
`node:crypto`.
|
|
145
|
+
|
|
146
|
+
The decisions this package serves are recorded in the store platform's project
|
|
147
|
+
tier: `PJ-049` (a fact is trusted by the key that signed it) and `PJ-050`
|
|
148
|
+
(Sentinel is the admission point and forwards the emitter's signature), in
|
|
149
|
+
`imolko/nixai-stores/generator` under `docs/adr/`. This repository keeps its own
|
|
150
|
+
project decisions in [docs/adr/](docs/adr/): [PJ-001](docs/adr/PJ-001-modulo-commonjs-libreria-desde-ultra-tsconfig.md)
|
|
151
|
+
(CommonJS build), [PJ-002](docs/adr/PJ-002-sin-capa-domain-release-fuera-del-paquete.md)
|
|
152
|
+
(no domain layer), [PJ-003](docs/adr/PJ-003-fact-key-cli-componente-ci-producto-lockstep.md)
|
|
153
|
+
(fact-key, CLI and CI component as product), [PJ-004](docs/adr/PJ-004-resultados-planos-sin-dependencias-runtime.md)
|
|
154
|
+
(flat results, zero runtime dependencies), [PJ-005](docs/adr/PJ-005-regla-tenencia-politica.md)
|
|
155
|
+
(the tenancy rule) and [PJ-006](docs/adr/PJ-006-orden-de-pasos-en-verifyfact.md)
|
|
156
|
+
(the key is resolved before the digest in `verifyFact`).
|
|
63
157
|
|
|
64
158
|
## Engineering rules
|
|
65
159
|
|
|
66
|
-
- Zero runtime dependencies. `node:crypto` only. Node
|
|
67
|
-
-
|
|
160
|
+
- Zero runtime dependencies. `node:crypto` only. Node 22.14+.
|
|
161
|
+
- The library entry point is pure: no I/O, no environment, no filesystem, no
|
|
162
|
+
network, no clock. The CLI is the only file-reading surface and lives outside
|
|
163
|
+
the built entry point's import graph.
|
|
68
164
|
- Deterministic: the same envelope and key produce the same signature bytes
|
|
69
165
|
(Ed25519 per RFC 8032), which is what makes the vectors assertable.
|
|
70
166
|
- Test-first. Every test carries `@name` / `@scenario` JSDoc.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ParseResult } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Serializa un valor a la forma canónica de 01 §3.
|
|
4
|
+
*
|
|
5
|
+
* @param value Valor a serializar.
|
|
6
|
+
* @returns `parsed` con el string canónico, o `invalid` con un token estable
|
|
7
|
+
* cuando el valor no es representable.
|
|
8
|
+
*/
|
|
9
|
+
export declare function canonicalJson(value: unknown): ParseResult<string>;
|
|
10
|
+
//# sourceMappingURL=canonical-json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical-json.d.ts","sourceRoot":"","sources":["../src/canonical-json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAsJ3C;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAAC,MAAM,CAAC,CAMjE"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.canonicalJson = canonicalJson;
|
|
4
|
+
/**
|
|
5
|
+
* Serialización canónica del formato v1 (01 §3).
|
|
6
|
+
*
|
|
7
|
+
* El contrato es exactamente el de la spec: claves propias y enumerables
|
|
8
|
+
* ordenadas por unidad UTF-16, claves ASCII, enteros seguros, `undefined`
|
|
9
|
+
* omitido en objetos y nada de `toJSON` ni normalización Unicode. Un cambio en
|
|
10
|
+
* esta regla es un cambio de formato, no una optimización.
|
|
11
|
+
*/
|
|
12
|
+
const KEY_PATTERN = /^[A-Za-z0-9_.-]+$/;
|
|
13
|
+
const invalid = (issue) => ({
|
|
14
|
+
kind: "invalid",
|
|
15
|
+
issues: [issue],
|
|
16
|
+
});
|
|
17
|
+
const parsed = (value) => ({
|
|
18
|
+
kind: "parsed",
|
|
19
|
+
value,
|
|
20
|
+
});
|
|
21
|
+
function hasSymbolKeys(value) {
|
|
22
|
+
return Object.getOwnPropertySymbols(value).length > 0;
|
|
23
|
+
}
|
|
24
|
+
function serializeNumber(value) {
|
|
25
|
+
if (Number.isNaN(value)) {
|
|
26
|
+
return invalid("canonical:number:nan");
|
|
27
|
+
}
|
|
28
|
+
if (!Number.isFinite(value)) {
|
|
29
|
+
return invalid("canonical:number:infinite");
|
|
30
|
+
}
|
|
31
|
+
if (Object.is(value, -0)) {
|
|
32
|
+
return invalid("canonical:number:negative-zero");
|
|
33
|
+
}
|
|
34
|
+
if (!Number.isInteger(value)) {
|
|
35
|
+
return invalid("canonical:number:fraction");
|
|
36
|
+
}
|
|
37
|
+
if (!Number.isSafeInteger(value)) {
|
|
38
|
+
return invalid("canonical:number:unsafe-integer");
|
|
39
|
+
}
|
|
40
|
+
return parsed(String(value));
|
|
41
|
+
}
|
|
42
|
+
function serializeArray(value, stack) {
|
|
43
|
+
if (stack.has(value)) {
|
|
44
|
+
return invalid("canonical:cycle");
|
|
45
|
+
}
|
|
46
|
+
if (hasSymbolKeys(value)) {
|
|
47
|
+
return invalid("canonical:symbol");
|
|
48
|
+
}
|
|
49
|
+
stack.add(value);
|
|
50
|
+
try {
|
|
51
|
+
const parts = [];
|
|
52
|
+
for (const element of value) {
|
|
53
|
+
const encoded = serialize(element, stack);
|
|
54
|
+
if (encoded.kind !== "parsed") {
|
|
55
|
+
return encoded;
|
|
56
|
+
}
|
|
57
|
+
parts.push(encoded.value);
|
|
58
|
+
}
|
|
59
|
+
return parsed(`[${parts.join(",")}]`);
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
stack.delete(value);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function serializePlainObject(value, stack) {
|
|
66
|
+
if (stack.has(value)) {
|
|
67
|
+
return invalid("canonical:cycle");
|
|
68
|
+
}
|
|
69
|
+
if (hasSymbolKeys(value)) {
|
|
70
|
+
return invalid("canonical:symbol");
|
|
71
|
+
}
|
|
72
|
+
stack.add(value);
|
|
73
|
+
try {
|
|
74
|
+
const parts = [];
|
|
75
|
+
for (const key of Object.keys(value).sort()) {
|
|
76
|
+
if (!KEY_PATTERN.test(key)) {
|
|
77
|
+
return invalid("canonical:key");
|
|
78
|
+
}
|
|
79
|
+
const member = value[key];
|
|
80
|
+
if (member === undefined) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const encoded = serialize(member, stack);
|
|
84
|
+
if (encoded.kind !== "parsed") {
|
|
85
|
+
return encoded;
|
|
86
|
+
}
|
|
87
|
+
parts.push(`${JSON.stringify(key)}:${encoded.value}`);
|
|
88
|
+
}
|
|
89
|
+
return parsed(`{${parts.join(",")}}`);
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
stack.delete(value);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Serializa un valor hoja: `null`, string, boolean o número.
|
|
97
|
+
*
|
|
98
|
+
* Devuelve `undefined` cuando el valor es un objeto y lo resuelve el recorrido
|
|
99
|
+
* estructural; así cada función decide sobre un único grupo de tipos.
|
|
100
|
+
*/
|
|
101
|
+
function serializeLeaf(value) {
|
|
102
|
+
if (value === null) {
|
|
103
|
+
return parsed("null");
|
|
104
|
+
}
|
|
105
|
+
if (typeof value === "string") {
|
|
106
|
+
return parsed(JSON.stringify(value));
|
|
107
|
+
}
|
|
108
|
+
if (typeof value === "boolean") {
|
|
109
|
+
return parsed(value ? "true" : "false");
|
|
110
|
+
}
|
|
111
|
+
if (typeof value === "number") {
|
|
112
|
+
return serializeNumber(value);
|
|
113
|
+
}
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
function serialize(value, stack) {
|
|
117
|
+
const leaf = serializeLeaf(value);
|
|
118
|
+
if (leaf !== undefined) {
|
|
119
|
+
return leaf;
|
|
120
|
+
}
|
|
121
|
+
if (typeof value !== "object") {
|
|
122
|
+
return invalid(`canonical:${typeof value}`);
|
|
123
|
+
}
|
|
124
|
+
if (Array.isArray(value)) {
|
|
125
|
+
return serializeArray(value, stack);
|
|
126
|
+
}
|
|
127
|
+
const prototype = Object.getPrototypeOf(value);
|
|
128
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
129
|
+
return invalid("canonical:object");
|
|
130
|
+
}
|
|
131
|
+
return serializePlainObject(value, stack);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Serializa un valor a la forma canónica de 01 §3.
|
|
135
|
+
*
|
|
136
|
+
* @param value Valor a serializar.
|
|
137
|
+
* @returns `parsed` con el string canónico, o `invalid` con un token estable
|
|
138
|
+
* cuando el valor no es representable.
|
|
139
|
+
*/
|
|
140
|
+
function canonicalJson(value) {
|
|
141
|
+
try {
|
|
142
|
+
return serialize(value, new Set());
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
return invalid("canonical:internal");
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=canonical-json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical-json.js","sourceRoot":"","sources":["../src/canonical-json.ts"],"names":[],"mappings":";;AA6JA,sCAMC;AAjKD;;;;;;;GAOG;AAEH,MAAM,WAAW,GAAG,mBAAmB,CAAC;AAExC,MAAM,OAAO,GAAG,CAAC,KAAa,EAAsB,EAAE,CAAC,CAAC;IACtD,IAAI,EAAE,SAAS;IACf,MAAM,EAAE,CAAC,KAAK,CAAC;CAChB,CAAC,CAAC;AAEH,MAAM,MAAM,GAAG,CAAC,KAAa,EAAuB,EAAE,CAAC,CAAC;IACtD,IAAI,EAAE,QAAQ;IACd,KAAK;CACN,CAAC,CAAC;AAEH,SAAS,aAAa,CAAC,KAAa;IAClC,OAAO,MAAM,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AACxD,CAAC;AAED,SAAS,eAAe,CAAC,KAAa;IACpC,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACzC,CAAC;IAC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C;QACzD,OAAO,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACrC,CAAC;IAED,OAAO,oBAAoB,CAAC,KAAgC,EAAE,KAAK,CAAC,CAAC;AACvE,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,aAAa,CAAC,KAAc;IAC1C,IAAI,CAAC;QACH,OAAO,SAAS,CAAC,KAAK,EAAE,IAAI,GAAG,EAAU,CAAC,CAAC;IAC7C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACvC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type KeyObject } from "node:crypto";
|
|
2
|
+
/**
|
|
3
|
+
* Port criptográfico del formato v1 (02 §6).
|
|
4
|
+
*
|
|
5
|
+
* La firma y la verificación son Ed25519 sobre `node:crypto`; el digest es
|
|
6
|
+
* SHA-256. Este módulo no lee archivos, no consulta el reloj y no depende del
|
|
7
|
+
* entorno: recibe bytes y `KeyObject`. Un backend alternativo puede sustituir
|
|
8
|
+
* estas funciones sin cambiar los bytes de firma.
|
|
9
|
+
*/
|
|
10
|
+
/** Calcula SHA-256 sobre los bytes recibidos. */
|
|
11
|
+
export declare function sha256(bytes: Uint8Array): Uint8Array;
|
|
12
|
+
/** Firma el preimage con una clave privada Ed25519. */
|
|
13
|
+
export declare function sign(preimage: Uint8Array, privateKey: KeyObject): Uint8Array;
|
|
14
|
+
/** Verifica una firma Ed25519 sobre el preimage con una clave pública. */
|
|
15
|
+
export declare function verify(input: {
|
|
16
|
+
readonly preimage: Uint8Array;
|
|
17
|
+
readonly signature: Uint8Array;
|
|
18
|
+
readonly publicKey: KeyObject;
|
|
19
|
+
}): boolean;
|
|
20
|
+
/** Reconstruye una clave pública Ed25519 a partir de su JWK. */
|
|
21
|
+
export declare function publicKeyFromJwk(x: string): KeyObject;
|
|
22
|
+
/** Convierte bytes a hex minúsculas. */
|
|
23
|
+
export declare function bytesToHex(bytes: Uint8Array): string;
|
|
24
|
+
/** Convierte hex minúsculas a bytes; el llamador valida la forma antes. */
|
|
25
|
+
export declare function hexToBytes(hex: string): Uint8Array;
|
|
26
|
+
//# sourceMappingURL=crypto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,SAAS,EACf,MAAM,aAAa,CAAC;AAErB;;;;;;;GAOG;AAEH,iDAAiD;AACjD,wBAAgB,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAEpD;AAED,uDAAuD;AACvD,wBAAgB,IAAI,CAAC,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,GAAG,UAAU,CAE5E;AAED,0EAA0E;AAC1E,wBAAgB,MAAM,CAAC,KAAK,EAAE;IAC5B,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;CAC/B,GAAG,OAAO,CAWV;AAED,gEAAgE;AAChE,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAGrD;AAED,wCAAwC;AACxC,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAEpD;AAED,2EAA2E;AAC3E,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAElD"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sha256 = sha256;
|
|
4
|
+
exports.sign = sign;
|
|
5
|
+
exports.verify = verify;
|
|
6
|
+
exports.publicKeyFromJwk = publicKeyFromJwk;
|
|
7
|
+
exports.bytesToHex = bytesToHex;
|
|
8
|
+
exports.hexToBytes = hexToBytes;
|
|
9
|
+
const node_crypto_1 = require("node:crypto");
|
|
10
|
+
/**
|
|
11
|
+
* Port criptográfico del formato v1 (02 §6).
|
|
12
|
+
*
|
|
13
|
+
* La firma y la verificación son Ed25519 sobre `node:crypto`; el digest es
|
|
14
|
+
* SHA-256. Este módulo no lee archivos, no consulta el reloj y no depende del
|
|
15
|
+
* entorno: recibe bytes y `KeyObject`. Un backend alternativo puede sustituir
|
|
16
|
+
* estas funciones sin cambiar los bytes de firma.
|
|
17
|
+
*/
|
|
18
|
+
/** Calcula SHA-256 sobre los bytes recibidos. */
|
|
19
|
+
function sha256(bytes) {
|
|
20
|
+
return new Uint8Array((0, node_crypto_1.createHash)("sha256").update(bytes).digest());
|
|
21
|
+
}
|
|
22
|
+
/** Firma el preimage con una clave privada Ed25519. */
|
|
23
|
+
function sign(preimage, privateKey) {
|
|
24
|
+
return new Uint8Array((0, node_crypto_1.sign)(null, preimage, privateKey));
|
|
25
|
+
}
|
|
26
|
+
/** Verifica una firma Ed25519 sobre el preimage con una clave pública. */
|
|
27
|
+
function verify(input) {
|
|
28
|
+
try {
|
|
29
|
+
return (0, node_crypto_1.verify)(null, input.preimage, input.publicKey, input.signature);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** Reconstruye una clave pública Ed25519 a partir de su JWK. */
|
|
36
|
+
function publicKeyFromJwk(x) {
|
|
37
|
+
const jwk = { kty: "OKP", crv: "Ed25519", x };
|
|
38
|
+
return (0, node_crypto_1.createPublicKey)({ key: jwk, format: "jwk" });
|
|
39
|
+
}
|
|
40
|
+
/** Convierte bytes a hex minúsculas. */
|
|
41
|
+
function bytesToHex(bytes) {
|
|
42
|
+
return Buffer.from(bytes).toString("hex");
|
|
43
|
+
}
|
|
44
|
+
/** Convierte hex minúsculas a bytes; el llamador valida la forma antes. */
|
|
45
|
+
function hexToBytes(hex) {
|
|
46
|
+
return new Uint8Array(Buffer.from(hex, "hex"));
|
|
47
|
+
}
|
|
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C,CAAC;AAC5C,CAAC;AAED,2EAA2E;AAC3E,SAAgB,UAAU,CAAC,GAAW;IACpC,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DsseEnvelope, Envelope, ParseResult } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Convierte un hecho firmado en un sobre DSSE.
|
|
4
|
+
*
|
|
5
|
+
* @param signed Sobre con `type`, `dataschema`, `securityKeyId` y
|
|
6
|
+
* `securityToken`.
|
|
7
|
+
* @returns `parsed` con el sobre DSSE, o `invalid` cuando falta una coordenada
|
|
8
|
+
* o el contenido no es representable. Nunca lanza.
|
|
9
|
+
*/
|
|
10
|
+
export declare function toDsseEnvelope(signed: Envelope): ParseResult<DsseEnvelope>;
|
|
11
|
+
//# sourceMappingURL=dsse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dsse.d.ts","sourceRoot":"","sources":["../src/dsse.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAgBnE;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,QAAQ,GAAG,WAAW,CAAC,YAAY,CAAC,CA2C1E"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toDsseEnvelope = toDsseEnvelope;
|
|
4
|
+
const canonical_json_1 = require("./canonical-json");
|
|
5
|
+
const errors_1 = require("./errors");
|
|
6
|
+
const patterns_1 = require("./patterns");
|
|
7
|
+
const payload_type_1 = require("./payload-type");
|
|
8
|
+
const sign_1 = require("./sign");
|
|
9
|
+
/**
|
|
10
|
+
* Adaptador de un hecho firmado al sobre DSSE (05 §6).
|
|
11
|
+
*
|
|
12
|
+
* El hecho no duplica el payload: lleva la firma sobre el contenido canónico.
|
|
13
|
+
* La conversión reconstruye ese contenido, lo canoniza otra vez y lo publica en
|
|
14
|
+
* el sobre que consume el tooling DSSE. No verifica la firma ni consulta el key
|
|
15
|
+
* set: es un conversor, no un veredicto (02 §2).
|
|
16
|
+
*/
|
|
17
|
+
const DSSE_STATEMENT_TYPE = "https://in-toto.io/Statement/v1";
|
|
18
|
+
const base64 = (bytes) => Buffer.from(bytes).toString("base64");
|
|
19
|
+
/**
|
|
20
|
+
* Convierte un hecho firmado en un sobre DSSE.
|
|
21
|
+
*
|
|
22
|
+
* @param signed Sobre con `type`, `dataschema`, `securityKeyId` y
|
|
23
|
+
* `securityToken`.
|
|
24
|
+
* @returns `parsed` con el sobre DSSE, o `invalid` cuando falta una coordenada
|
|
25
|
+
* o el contenido no es representable. Nunca lanza.
|
|
26
|
+
*/
|
|
27
|
+
function toDsseEnvelope(signed) {
|
|
28
|
+
try {
|
|
29
|
+
if (!(0, errors_1.isPlainObject)(signed)) {
|
|
30
|
+
return (0, errors_1.invalid)("invalid:envelope");
|
|
31
|
+
}
|
|
32
|
+
const payloadType = (0, payload_type_1.factPayloadType)(signed);
|
|
33
|
+
if (payloadType.kind !== "parsed") {
|
|
34
|
+
return (0, errors_1.invalid)(...payloadType.issues);
|
|
35
|
+
}
|
|
36
|
+
const keyId = signed["securityKeyId"];
|
|
37
|
+
if (typeof keyId !== "string" || keyId.length === 0) {
|
|
38
|
+
return (0, errors_1.invalid)("missing:securityKeyId");
|
|
39
|
+
}
|
|
40
|
+
const token = signed["securityToken"];
|
|
41
|
+
if (typeof token !== "string") {
|
|
42
|
+
return (0, errors_1.invalid)("missing:securityToken");
|
|
43
|
+
}
|
|
44
|
+
if (!patterns_1.HEX128.test(token)) {
|
|
45
|
+
return (0, errors_1.invalid)("invalid:securityToken");
|
|
46
|
+
}
|
|
47
|
+
const canonical = (0, canonical_json_1.canonicalJson)((0, sign_1.coveredContent)(signed));
|
|
48
|
+
if (canonical.kind !== "parsed") {
|
|
49
|
+
return (0, errors_1.invalid)(...canonical.issues);
|
|
50
|
+
}
|
|
51
|
+
return (0, errors_1.parsed)({
|
|
52
|
+
_type: DSSE_STATEMENT_TYPE,
|
|
53
|
+
payloadType: payloadType.value,
|
|
54
|
+
payload: base64(new TextEncoder().encode(canonical.value)),
|
|
55
|
+
signatures: [
|
|
56
|
+
{
|
|
57
|
+
keyid: keyId,
|
|
58
|
+
sig: base64(new Uint8Array(Buffer.from(token, "hex"))),
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return (0, errors_1.invalid)("dsse:internal");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=dsse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dsse.js","sourceRoot":"","sources":["../src/dsse.ts"],"names":[],"mappings":";;AA6BA,wCA2CC;AAxED,qDAAiD;AACjD,qCAA0D;AAC1D,yCAAoC;AACpC,iDAAiD;AACjD,iCAAwC;AAGxC;;;;;;;GAOG;AAEH,MAAM,mBAAmB,GAAG,iCAA0C,CAAC;AAEvE,MAAM,MAAM,GAAG,CAAC,KAAiB,EAAU,EAAE,CAC3C,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAExC;;;;;;;GAOG;AACH,SAAgB,cAAc,CAAC,MAAgB;IAC7C,IAAI,CAAC;QACH,IAAI,CAAC,IAAA,sBAAa,EAAC,MAAM,CAAC,EAAE,CAAC;YAC3B,OAAO,IAAA,gBAAO,EAAC,kBAAkB,CAAC,CAAC;QACrC,CAAC;QAED,MAAM,WAAW,GAAG,IAAA,8BAAe,EAAC,MAAM,CAAC,CAAC;QAC5C,IAAI,WAAW,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAClC,OAAO,IAAA,gBAAO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;IAClC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ParseResult } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Constructores y guardas compartidos por los parsers y las operaciones.
|
|
4
|
+
*
|
|
5
|
+
* El canal de error es siempre un `ParseResult`/`SignResult`/`SignatureVerdict`
|
|
6
|
+
* con tokens estables; ningún camino usa una excepción como control de flujo.
|
|
7
|
+
*/
|
|
8
|
+
/** La rama invalid que comparten todos los resultados del paquete. */
|
|
9
|
+
export interface InvalidResult {
|
|
10
|
+
readonly kind: "invalid";
|
|
11
|
+
readonly issues: readonly string[];
|
|
12
|
+
}
|
|
13
|
+
/** Construye una rama invalid con uno o más tokens estables. */
|
|
14
|
+
export declare function invalid(...issues: string[]): InvalidResult;
|
|
15
|
+
/** Construye un `ParseResult` parsed. */
|
|
16
|
+
export declare function parsed<T>(value: T): ParseResult<T>;
|
|
17
|
+
/** Distingue un registro JSON plano de un array, `null` o una instancia. */
|
|
18
|
+
export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
|
|
19
|
+
/**
|
|
20
|
+
* Normaliza la entrada de un parser: acepta un documento ya parseado o un
|
|
21
|
+
* string JSON y nunca lee un archivo.
|
|
22
|
+
*/
|
|
23
|
+
export declare function readDocument(document: unknown | string, prefix: string): ParseResult<Record<string, unknown>>;
|
|
24
|
+
/** Devuelve el primer miembro no permitido, si existe. */
|
|
25
|
+
export declare function firstUnknownMember(value: Record<string, unknown>, allowed: readonly string[]): string | undefined;
|
|
26
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C;;;;;GAKG;AAEH,sEAAsE;AACtE,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CACpC;AAED,gEAAgE;AAChE,wBAAgB,OAAO,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG,aAAa,CAE1D;AAED,yCAAyC;AACzC,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAElD;AAED,4EAA4E;AAC5E,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAW9E;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,OAAO,GAAG,MAAM,EAC1B,MAAM,EAAE,MAAM,GACb,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAgBtC;AAED,0DAA0D;AAC1D,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,OAAO,EAAE,SAAS,MAAM,EAAE,GACzB,MAAM,GAAG,SAAS,CAEpB"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.invalid = invalid;
|
|
4
|
+
exports.parsed = parsed;
|
|
5
|
+
exports.isPlainObject = isPlainObject;
|
|
6
|
+
exports.readDocument = readDocument;
|
|
7
|
+
exports.firstUnknownMember = firstUnknownMember;
|
|
8
|
+
/** Construye una rama invalid con uno o más tokens estables. */
|
|
9
|
+
function invalid(...issues) {
|
|
10
|
+
return { kind: "invalid", issues };
|
|
11
|
+
}
|
|
12
|
+
/** Construye un `ParseResult` parsed. */
|
|
13
|
+
function parsed(value) {
|
|
14
|
+
return { kind: "parsed", value };
|
|
15
|
+
}
|
|
16
|
+
/** Distingue un registro JSON plano de un array, `null` o una instancia. */
|
|
17
|
+
function isPlainObject(value) {
|
|
18
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const prototype = Object.getPrototypeOf(value);
|
|
23
|
+
return prototype === Object.prototype || prototype === null;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Normaliza la entrada de un parser: acepta un documento ya parseado o un
|
|
31
|
+
* string JSON y nunca lee un archivo.
|
|
32
|
+
*/
|
|
33
|
+
function readDocument(document, prefix) {
|
|
34
|
+
let value = document;
|
|
35
|
+
if (typeof document === "string") {
|
|
36
|
+
try {
|
|
37
|
+
value = JSON.parse(document);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return invalid(`${prefix}:json`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (!isPlainObject(value)) {
|
|
44
|
+
return invalid(`${prefix}:structure`);
|
|
45
|
+
}
|
|
46
|
+
return parsed(value);
|
|
47
|
+
}
|
|
48
|
+
/** Devuelve el primer miembro no permitido, si existe. */
|
|
49
|
+
function firstUnknownMember(value, allowed) {
|
|
50
|
+
return Object.keys(value).find((key) => !allowed.includes(key));
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;AAgBA,0BAEC;AAGD,wBAEC;AAGD,sCAWC;AAMD,oCAmBC;AAGD,gDAKC;AAvDD,gEAAgE;AAChE,SAAgB,OAAO,CAAC,GAAG,MAAgB;IACzC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;AACrC,CAAC;AAED,yCAAyC;AACzC,SAAgB,MAAM,CAAI,KAAQ;IAChC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AACn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1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Superficie pública del formato v1 de firma de hechos.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Solo se exportan las operaciones que fija `docs/spec/02-api.md`: firmar,
|
|
5
|
+
* verificar, parsear los dos documentos de confianza y los helpers de
|
|
6
|
+
* interoperabilidad. La forma canónica, el PAE y el módulo DSSE quedan
|
|
7
|
+
* internos a propósito: un consumidor que puede llamarlos a medias puede
|
|
8
|
+
* producir una firma que no verifica.
|
|
8
9
|
*
|
|
9
|
-
* Formato: `docs/spec/01-wire-format.md`.
|
|
10
|
+
* Formato: `docs/spec/01-wire-format.md`. API: `docs/spec/02-api.md`.
|
|
10
11
|
*/
|
|
12
|
+
export { toDsseEnvelope } from "./dsse";
|
|
13
|
+
export { parseKeySet } from "./key-set";
|
|
14
|
+
export { DSSE_PREAMBLE } from "./pae";
|
|
15
|
+
export { factPayloadType } from "./payload-type";
|
|
16
|
+
export { parseTrustPolicy } from "./policy";
|
|
17
|
+
export { signFact } from "./sign";
|
|
18
|
+
export { verifyFact } from "./verify";
|
|
19
|
+
export type { DsseEnvelope, Envelope, KeySet, ParseResult, SignOptions, SignResult, SignatureRejection, SignatureVerdict, TrustPolicy, VerifyOptions, } from "./types";
|
|
11
20
|
/** Versión del formato de firma (campo `signatureFormat` del key set). */
|
|
12
21
|
export declare const SIGNATURE_FORMAT_VERSION: "1";
|
|
13
|
-
/** Prefijo de autenticación de DSSE, tal como lo fija PAE. */
|
|
14
|
-
export declare const DSSE_PREAMBLE: "DSSEv1";
|
|
15
22
|
/** Algoritmo de firma del formato v1. Ed25519 per RFC 8032. */
|
|
16
23
|
export declare const SIGNATURE_ALGORITHM: "Ed25519";
|
|
17
24
|
/**
|
package/dist-node/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,YAAY,EACV,YAAY,EACZ,QAAQ,EACR,MAAM,EACN,WAAW,EACX,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,gBAAgB,EAChB,WAAW,EACX,aAAa,GACd,MAAM,SAAS,CAAC;AAEjB,0EAA0E;AAC1E,eAAO,MAAM,wBAAwB,EAAG,GAAY,CAAC;AAErD,+DAA+D;AAC/D,eAAO,MAAM,mBAAmB,EAAG,SAAkB,CAAC;AAEtD;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAG,QAAiB,CAAC"}
|
package/dist-node/index.js
CHANGED
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Superficie pública del formato v1 de firma de hechos.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* Solo se exportan las operaciones que fija `docs/spec/02-api.md`: firmar,
|
|
6
|
+
* verificar, parsear los dos documentos de confianza y los helpers de
|
|
7
|
+
* interoperabilidad. La forma canónica, el PAE y el módulo DSSE quedan
|
|
8
|
+
* internos a propósito: un consumidor que puede llamarlos a medias puede
|
|
9
|
+
* producir una firma que no verifica.
|
|
9
10
|
*
|
|
10
|
-
* Formato: `docs/spec/01-wire-format.md`.
|
|
11
|
+
* Formato: `docs/spec/01-wire-format.md`. API: `docs/spec/02-api.md`.
|
|
11
12
|
*/
|
|
12
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.PAE_DIGEST_ALGORITHM = exports.SIGNATURE_ALGORITHM = exports.DSSE_PREAMBLE = exports.
|
|
14
|
+
exports.PAE_DIGEST_ALGORITHM = exports.SIGNATURE_ALGORITHM = exports.SIGNATURE_FORMAT_VERSION = exports.verifyFact = exports.signFact = exports.parseTrustPolicy = exports.factPayloadType = exports.DSSE_PREAMBLE = exports.parseKeySet = exports.toDsseEnvelope = void 0;
|
|
15
|
+
var dsse_1 = require("./dsse");
|
|
16
|
+
Object.defineProperty(exports, "toDsseEnvelope", { enumerable: true, get: function () { return dsse_1.toDsseEnvelope; } });
|
|
17
|
+
var key_set_1 = require("./key-set");
|
|
18
|
+
Object.defineProperty(exports, "parseKeySet", { enumerable: true, get: function () { return key_set_1.parseKeySet; } });
|
|
19
|
+
var pae_1 = require("./pae");
|
|
20
|
+
Object.defineProperty(exports, "DSSE_PREAMBLE", { enumerable: true, get: function () { return pae_1.DSSE_PREAMBLE; } });
|
|
21
|
+
var payload_type_1 = require("./payload-type");
|
|
22
|
+
Object.defineProperty(exports, "factPayloadType", { enumerable: true, get: function () { return payload_type_1.factPayloadType; } });
|
|
23
|
+
var policy_1 = require("./policy");
|
|
24
|
+
Object.defineProperty(exports, "parseTrustPolicy", { enumerable: true, get: function () { return policy_1.parseTrustPolicy; } });
|
|
25
|
+
var sign_1 = require("./sign");
|
|
26
|
+
Object.defineProperty(exports, "signFact", { enumerable: true, get: function () { return sign_1.signFact; } });
|
|
27
|
+
var verify_1 = require("./verify");
|
|
28
|
+
Object.defineProperty(exports, "verifyFact", { enumerable: true, get: function () { return verify_1.verifyFact; } });
|
|
14
29
|
/** Versión del formato de firma (campo `signatureFormat` del key set). */
|
|
15
30
|
exports.SIGNATURE_FORMAT_VERSION = "1";
|
|
16
|
-
/** Prefijo de autenticación de DSSE, tal como lo fija PAE. */
|
|
17
|
-
exports.DSSE_PREAMBLE = "DSSEv1";
|
|
18
31
|
/** Algoritmo de firma del formato v1. Ed25519 per RFC 8032. */
|
|
19
32
|
exports.SIGNATURE_ALGORITHM = "Ed25519";
|
|
20
33
|
/**
|