@ocap/chain-node 1.32.2 → 1.32.3
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/esm/did-tls.d.mts +192 -0
- package/esm/did-tls.mjs +1606 -0
- package/esm/env.d.mts +17 -2
- package/esm/env.mjs +126 -1
- package/esm/follower-config.mjs +1 -1
- package/esm/index.d.mts +6 -4
- package/esm/index.mjs +5 -3
- package/esm/mesh-egress.d.mts +30 -0
- package/esm/mesh-egress.mjs +152 -0
- package/esm/start-chain-node.d.mts +6 -1
- package/esm/start-chain-node.mjs +774 -47
- package/esm/types.d.mts +63 -2
- package/lib/did-tls.cjs +1628 -0
- package/lib/did-tls.d.cts +192 -0
- package/lib/env.cjs +131 -1
- package/lib/env.d.cts +17 -2
- package/lib/follower-config.cjs +1 -1
- package/lib/index.cjs +30 -1
- package/lib/index.d.cts +6 -4
- package/lib/mesh-egress.cjs +155 -0
- package/lib/mesh-egress.d.cts +30 -0
- package/lib/start-chain-node.cjs +778 -48
- package/lib/start-chain-node.d.cts +6 -1
- package/lib/types.d.cts +62 -1
- package/package.json +16 -16
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
//#region src/did-tls.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Zero-CA X.509v3 DID-TLS certificate issuer, strict bounded ASN.1 DER parser,
|
|
4
|
+
* and fail-closed peer verifier (`@ocap/chain-node`, #2025).
|
|
5
|
+
*
|
|
6
|
+
* Wire-compatible 1:1 with `arc` DID-TLS (`OID 1.3.101.112` Ed25519 and
|
|
7
|
+
* `OID 1.3.6.1.4.1.59489.1.1` P-256 `DIDBindingProof` Cloudflare mTLS bridge).
|
|
8
|
+
* Uses `node:crypto` + `@arcblock/did` with zero `openssl` CLI subprocesses.
|
|
9
|
+
*/
|
|
10
|
+
/** Hard upper bound on accepted DER certificate size (16 KiB). */
|
|
11
|
+
declare const MAX_CERT_BYTES = 16384;
|
|
12
|
+
declare const MAX_DID_TLS_CERT_BYTES = 16384;
|
|
13
|
+
/** Hard upper bound on PEM string input length before base64 decoding. */
|
|
14
|
+
declare const MAX_DID_TLS_PEM_CHARS = 32768;
|
|
15
|
+
/** Hard upper bound on DID length inside X.509 Subject/Issuer/SAN. */
|
|
16
|
+
declare const MAX_DID_TLS_DID_LENGTH = 512;
|
|
17
|
+
/** Private Enterprise Number extension OID for ARC DID-TLS P-256 binding proof. */
|
|
18
|
+
declare const DID_TLS_BINDING_PROOF_OID = "1.3.6.1.4.1.59489.1.1";
|
|
19
|
+
/** Domain separation tag for Ed25519 DID-TLS P-256 binding signatures. */
|
|
20
|
+
declare const DID_TLS_BINDING_DOMAIN = "ARC-DID-TLS-BINDING-V1";
|
|
21
|
+
/** HKDF-SHA256 salt for deterministic P-256 key derivation from a 32-byte DID seed. */
|
|
22
|
+
declare const DID_TLS_P256_HKDF_SALT = "arc-did-tls-p256-salt-v1";
|
|
23
|
+
/** HKDF-SHA256 info prefix for deterministic P-256 key derivation. */
|
|
24
|
+
declare const DID_TLS_P256_HKDF_INFO_PREFIX = "arc-did-tls-p256-key-v1:";
|
|
25
|
+
/** Default clock skew tolerance in seconds for certificate validity checks. */
|
|
26
|
+
declare const DEFAULT_DID_TLS_CLOCK_SKEW_SECONDS = 60;
|
|
27
|
+
type DidTlsWireAlgorithm = 'ed25519' | 'p256';
|
|
28
|
+
type DidTlsRole = 'server' | 'client' | 'dual' | 'ca';
|
|
29
|
+
type DidTlsEndpointRole = 'server' | 'client';
|
|
30
|
+
type DidTlsRejectReason = 'malformed-cert' | 'oversized-cert' | 'unsupported-version' | 'unsupported-algorithm' | 'unsupported-critical-extension' | 'duplicate-extension' | 'invalid-did' | 'subject-did-mismatch' | 'no-trust-policy' | 'untrusted-issuer' | 'subject-not-allowed' | 'issuer-key-mismatch' | 'missing-did-binding-proof' | 'invalid-did-binding-proof' | 'invalid-signature' | 'cert-not-yet-valid' | 'cert-expired' | 'ca-cert-as-leaf' | 'invalid-key-usage' | 'role-mismatch' | 'host-mismatch';
|
|
31
|
+
interface IssueDidTlsCertificateOptions {
|
|
32
|
+
/** Subject W3C DID (`CN=<subjectDid>` and `SAN URI=<subjectDid>`). Bare OCAP DIDs are canonicalized to `did:abt:...`. */
|
|
33
|
+
subjectDid?: string;
|
|
34
|
+
/** 32-byte Ed25519 seed or 64-byte TweetNaCl secret key (`Uint8Array`, hex, or `z...` Base58btc). */
|
|
35
|
+
subjectSeed: Uint8Array | string;
|
|
36
|
+
/** Issuer W3C DID (defaults to `subjectDid` for self-issued certificates). */
|
|
37
|
+
issuerDid?: string;
|
|
38
|
+
/** Issuer Ed25519 seed/secretKey (defaults to `subjectSeed` when self-issued). */
|
|
39
|
+
issuerSeed?: Uint8Array | string;
|
|
40
|
+
/** TLS wire key/signature algorithm (`'ed25519'` default, or `'p256'` Cloudflare mTLS bridge). */
|
|
41
|
+
wireAlgorithm?: DidTlsWireAlgorithm;
|
|
42
|
+
/** Certificate role (`'dual'` default, `'server'`, `'client'`, or `'ca'`). */
|
|
43
|
+
role?: DidTlsRole;
|
|
44
|
+
/** Additional DNS SubjectAltName entries (exact hostnames or leftmost `*.domain.tld`). */
|
|
45
|
+
dnsNames?: readonly string[];
|
|
46
|
+
/** Additional IPv4 / IPv6 SubjectAltName entries. */
|
|
47
|
+
ipAddresses?: readonly string[];
|
|
48
|
+
/** Validity start timestamp (truncated to whole seconds; defaults to current UTC second). */
|
|
49
|
+
notBefore?: Date;
|
|
50
|
+
/** Explicit validity end timestamp (overrides `validityDays`). */
|
|
51
|
+
notAfter?: Date;
|
|
52
|
+
/** Validity duration in days (`1..3650`, default `365`) when `notAfter` is omitted. */
|
|
53
|
+
validityDays?: number;
|
|
54
|
+
/** Optional explicit positive serial number (`1..20` bytes) for deterministic fixtures. */
|
|
55
|
+
serialNumber?: Uint8Array;
|
|
56
|
+
}
|
|
57
|
+
interface IssuedDidTlsCertificate {
|
|
58
|
+
certificatePem: string;
|
|
59
|
+
certificateDer: Uint8Array;
|
|
60
|
+
privateKeyPem: string;
|
|
61
|
+
privateKeyPkcs8Der: Uint8Array;
|
|
62
|
+
subjectDid: string;
|
|
63
|
+
issuerDid: string;
|
|
64
|
+
subjectEd25519PublicKey: Uint8Array;
|
|
65
|
+
subjectEd25519PublicKeyHex: string;
|
|
66
|
+
issuerEd25519PublicKey: Uint8Array;
|
|
67
|
+
issuerEd25519PublicKeyHex: string;
|
|
68
|
+
spkiSha256Hex: string;
|
|
69
|
+
wireAlgorithm: DidTlsWireAlgorithm;
|
|
70
|
+
role: DidTlsRole;
|
|
71
|
+
dnsNames: string[];
|
|
72
|
+
ipAddresses: string[];
|
|
73
|
+
notBefore: Date;
|
|
74
|
+
notAfter: Date;
|
|
75
|
+
serialNumberHex: string;
|
|
76
|
+
}
|
|
77
|
+
interface DidTlsKeyUsageFlags {
|
|
78
|
+
digitalSignature: boolean;
|
|
79
|
+
keyCertSign: boolean;
|
|
80
|
+
cRLSign: boolean;
|
|
81
|
+
}
|
|
82
|
+
interface ParsedDidBindingProof {
|
|
83
|
+
version: number;
|
|
84
|
+
issuerDid: string;
|
|
85
|
+
issuerEd25519PublicKey: Uint8Array;
|
|
86
|
+
issuerTlsSpkiDer: Uint8Array;
|
|
87
|
+
extensionsDigest: Uint8Array;
|
|
88
|
+
signature: Uint8Array;
|
|
89
|
+
}
|
|
90
|
+
interface ParsedDidTlsCertificate {
|
|
91
|
+
version: number;
|
|
92
|
+
serialNumberHex: string;
|
|
93
|
+
wireAlgorithm: DidTlsWireAlgorithm;
|
|
94
|
+
issuerDid: string;
|
|
95
|
+
subjectDid: string;
|
|
96
|
+
notBefore: Date;
|
|
97
|
+
notAfter: Date;
|
|
98
|
+
tbsDer: Uint8Array;
|
|
99
|
+
spkiDer: Uint8Array;
|
|
100
|
+
subjectPublicKeyRaw: Uint8Array;
|
|
101
|
+
signatureValue: Uint8Array;
|
|
102
|
+
isCA: boolean;
|
|
103
|
+
pathLenConstraint?: number;
|
|
104
|
+
keyUsage: DidTlsKeyUsageFlags;
|
|
105
|
+
roles: DidTlsEndpointRole[];
|
|
106
|
+
uriSans: string[];
|
|
107
|
+
dnsNames: string[];
|
|
108
|
+
ipAddresses: string[];
|
|
109
|
+
subjectKeyIdentifierHex?: string;
|
|
110
|
+
authorityKeyIdentifierHex?: string;
|
|
111
|
+
coreExtensionsDer: Uint8Array;
|
|
112
|
+
didBindingProof?: ParsedDidBindingProof;
|
|
113
|
+
}
|
|
114
|
+
type DidTlsAllowedIssuerPinsInput = ReadonlyMap<string, Uint8Array | string> | Readonly<Record<string, Uint8Array | string>> | ReadonlyArray<Uint8Array | string> | ReadonlySet<string>;
|
|
115
|
+
interface DidTlsPeerVerifyPolicy {
|
|
116
|
+
/**
|
|
117
|
+
* Fail-closed pinned 32-byte Ed25519 issuer public keys.
|
|
118
|
+
* Accepts:
|
|
119
|
+
* - `Map<issuerDid, pubkey>` / `Record<issuerDid, pubkey>`
|
|
120
|
+
* - Array/Set of `<pubkey>` (`Uint8Array(32)`, hex, `0x` hex, `z...` multibase/base58) or `<issuerDid>=<pubkey>`
|
|
121
|
+
*/
|
|
122
|
+
allowedIssuerPublicKeys?: DidTlsAllowedIssuerPinsInput;
|
|
123
|
+
/** Optional self-issued peer DID -> 32-byte Ed25519 public key map. */
|
|
124
|
+
allowedSubjectPublicKeys?: ReadonlyMap<string, Uint8Array | string>;
|
|
125
|
+
/** Optional subject DID allowlist restricting which subjects an issuer may certify. */
|
|
126
|
+
allowedSubjectDids?: Iterable<string>;
|
|
127
|
+
/** Expected TLS endpoint role (`'client'` default for server mTLS peer check, or `'server'`). */
|
|
128
|
+
expectedRole?: DidTlsEndpointRole;
|
|
129
|
+
/** Expected DNS hostname or IPv4/IPv6 literal matched against SANs. */
|
|
130
|
+
expectedHost?: string;
|
|
131
|
+
/** Reference timestamp for validity check (defaults to `Date.now()`). */
|
|
132
|
+
now?: Date | number;
|
|
133
|
+
/** Allowed clock skew in seconds (defaults to `60`). */
|
|
134
|
+
clockSkewSeconds?: number;
|
|
135
|
+
}
|
|
136
|
+
type DidTlsTrustPolicy = DidTlsPeerVerifyPolicy;
|
|
137
|
+
type DidTlsVerificationResult = {
|
|
138
|
+
ok: true;
|
|
139
|
+
subjectDid: string;
|
|
140
|
+
issuerDid: string;
|
|
141
|
+
issuerPublicKeyHex: string;
|
|
142
|
+
spkiSha256Hex: string;
|
|
143
|
+
wireAlgorithm: DidTlsWireAlgorithm;
|
|
144
|
+
roles: DidTlsEndpointRole[];
|
|
145
|
+
dnsNames: string[];
|
|
146
|
+
ipAddresses: string[];
|
|
147
|
+
notBefore: Date;
|
|
148
|
+
notAfter: Date;
|
|
149
|
+
} | {
|
|
150
|
+
ok: false;
|
|
151
|
+
reason: DidTlsRejectReason;
|
|
152
|
+
detail: string;
|
|
153
|
+
};
|
|
154
|
+
declare function didTlsBytesToHex(bytes: Uint8Array): string;
|
|
155
|
+
declare function didTlsHexToBytes(input: string, expectedLength?: number): Uint8Array;
|
|
156
|
+
declare function isValidW3cDidSyntax(value: unknown): value is string;
|
|
157
|
+
/**
|
|
158
|
+
* Normalize either a bare OCAP DID (`z1...`) or a W3C DID (`did:abt:z1...`, `did:spaces:z1...`, `did:arc:...`)
|
|
159
|
+
* into its canonical W3C DID string (`did:...`).
|
|
160
|
+
*/
|
|
161
|
+
declare function canonicalizeTlsDid(rawDid: string, fieldName?: string): string;
|
|
162
|
+
/**
|
|
163
|
+
* Extract a validated 32-byte Ed25519 secret seed from a 32-byte seed or 64-byte OCAP/TweetNaCl
|
|
164
|
+
* Ed25519 secret key (`Uint8Array`, `0x`/bare hex, or `z...` Base58btc).
|
|
165
|
+
* Never echoes key material in error messages.
|
|
166
|
+
*/
|
|
167
|
+
declare function extractEd25519SeedFromSecretKey(secretKey: Uint8Array | string, label?: string): Uint8Array;
|
|
168
|
+
/**
|
|
169
|
+
* Decode a pinned 32-byte Ed25519 public key from `Uint8Array(32)`, 64-char hex (`0x` optional),
|
|
170
|
+
* `did:key:z6Mk...`, multibase `z6Mk...` (`0xed 0x01` + 32 bytes), or OCAP `z...` Base58btc (32 bytes).
|
|
171
|
+
*/
|
|
172
|
+
declare function decodeEd25519PublicKeyPin(input: Uint8Array | string, label?: string): Uint8Array;
|
|
173
|
+
/**
|
|
174
|
+
* Derive the 32-byte Ed25519 public key from a 32-byte seed (or 64-byte Ed25519 secret key).
|
|
175
|
+
*/
|
|
176
|
+
declare function deriveEd25519PublicKeyFromSeed(seed: Uint8Array | string): Uint8Array;
|
|
177
|
+
/**
|
|
178
|
+
* Deterministically derive an ECDSA P-256 keypair from a 32-byte Ed25519 DID seed
|
|
179
|
+
* and canonical W3C DID string via HKDF-SHA256 with rejection sampling over `[1, n-1]`.
|
|
180
|
+
*/
|
|
181
|
+
declare function deriveDidTlsP256KeyPair(seed: Uint8Array | string, did: string): {
|
|
182
|
+
privateKeyScalar: Uint8Array;
|
|
183
|
+
publicKeyUncompressed: Uint8Array;
|
|
184
|
+
spkiDer: Uint8Array;
|
|
185
|
+
pkcs8Der: Uint8Array;
|
|
186
|
+
};
|
|
187
|
+
declare function issueDidTlsCertificate(options: IssueDidTlsCertificateOptions): IssuedDidTlsCertificate;
|
|
188
|
+
declare function parseDidTlsCertificate(certDerOrPem: Uint8Array | Buffer | string): ParsedDidTlsCertificate;
|
|
189
|
+
declare function verifyDidTlsCertificate(certDerOrPem: Uint8Array | Buffer | string, policy: DidTlsPeerVerifyPolicy): DidTlsVerificationResult;
|
|
190
|
+
declare function verifyDidTlsPeerCertificate(certDerOrPem: Uint8Array | Buffer | string, policy: DidTlsPeerVerifyPolicy): DidTlsVerificationResult;
|
|
191
|
+
//#endregion
|
|
192
|
+
export { DEFAULT_DID_TLS_CLOCK_SKEW_SECONDS, DID_TLS_BINDING_DOMAIN, DID_TLS_BINDING_PROOF_OID, DID_TLS_P256_HKDF_INFO_PREFIX, DID_TLS_P256_HKDF_SALT, DidTlsAllowedIssuerPinsInput, DidTlsEndpointRole, DidTlsKeyUsageFlags, DidTlsPeerVerifyPolicy, DidTlsRejectReason, DidTlsRole, DidTlsTrustPolicy, DidTlsVerificationResult, DidTlsWireAlgorithm, IssueDidTlsCertificateOptions, IssuedDidTlsCertificate, MAX_CERT_BYTES, MAX_DID_TLS_CERT_BYTES, MAX_DID_TLS_DID_LENGTH, MAX_DID_TLS_PEM_CHARS, ParsedDidBindingProof, ParsedDidTlsCertificate, canonicalizeTlsDid, decodeEd25519PublicKeyPin, deriveDidTlsP256KeyPair, deriveEd25519PublicKeyFromSeed, didTlsBytesToHex, didTlsHexToBytes, extractEd25519SeedFromSecretKey, isValidW3cDidSyntax, issueDidTlsCertificate, parseDidTlsCertificate, verifyDidTlsCertificate, verifyDidTlsPeerCertificate };
|