@atlasauth/pca-bbs 0.0.0-stage → 0.2.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Atlas Authorization
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,60 @@
1
- # Temporary Holding Version
1
+ # @atlasauth/pca-bbs
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ BBS signatures (BLS12-381-SHA-256, following the IRTF CFRG BBS draft) for Proof-Carrying Authority (PCA). A PCA capability is issued as a multi-message BBS credential, then presented with selective disclosure and an unlinkable zero-knowledge proof of possession. An agent can reveal only the attributes a tool needs (for example the scope caveat) while hiding the rest (holder, budget, expiry), and two presentations of the same credential cannot be correlated.
4
+
5
+ There are two layers:
6
+
7
+ - the BBS core: `keyGen`, `createGenerators`, `messagesToScalars`, `sign`, `verify`, `proofGen`, `proofVerify`;
8
+ - the PCA layer: map a capability to an ordered attribute vector (`iss`, `sub`, then `cav:<i>:<type>` per caveat), issue it, present a subset, verify the presentation.
9
+
10
+ ## Install
11
+
12
+ ```sh
13
+ npm i @atlasauth/pca-bbs
14
+ ```
15
+
16
+ Depends on `@atlasauth/pca`, `@noble/curves` and `@noble/hashes` (installed automatically).
17
+
18
+ ## Usage
19
+
20
+ ```ts
21
+ import {
22
+ generateKeyPair, issueCapabilityCredential, presentCredential, verifyCredential, verifyPresentation,
23
+ } from '@atlasauth/pca-bbs';
24
+
25
+ const bytes = (s: string) => new TextEncoder().encode(s);
26
+
27
+ const capability = {
28
+ issuer: 'issuer-public-key',
29
+ holder: 'agent-public-key',
30
+ caveats: [
31
+ { type: 'scope', actions: ['search:read'] },
32
+ { type: 'budget_alloc', limit: 100 },
33
+ ],
34
+ };
35
+
36
+ const { sk, pk } = generateKeyPair();
37
+ const cred = issueCapabilityCredential(capability, { sk, pk });
38
+ verifyCredential(cred); // true: every attribute is signed by the issuer
39
+
40
+ // Reveal only the scope caveat, bound to one action so the proof cannot be replayed elsewhere.
41
+ const pres = presentCredential(cred, {
42
+ disclose: ['cav:0:scope'],
43
+ presentationHeader: bytes('action:search?q=atlas'),
44
+ });
45
+
46
+ verifyPresentation(pres); // true
47
+ verifyPresentation(pres, { pk, presentationHeader: bytes('action:search?q=atlas') }); // pin issuer + context
48
+ ```
49
+
50
+ `presentCredential` throws if a requested attribute name does not exist. Pass a pinned `pk` and your own `presentationHeader` to `verifyPresentation` so the verifier asserts its own expectations rather than trusting the values carried in the presentation.
51
+
52
+ ## Status
53
+
54
+ Cryptography is unaudited. The BBS implementation follows the CFRG draft and is checked against its test vectors, but the draft is not a final standard. BBS on BLS12-381 is not post-quantum.
55
+
56
+ Source and issues: https://github.com/Atlas-Authorization/pca
57
+
58
+ ## License
59
+
60
+ MIT - see LICENSE
package/dist/bbs.d.ts ADDED
@@ -0,0 +1,85 @@
1
+ /**
2
+ * BBS signatures over BLS12-381, faithful to draft-irtf-cfrg-bbs-signatures (the 2023–2024 CFRG
3
+ * draft; this implementation follows draft-07's core protocol and octet encodings).
4
+ *
5
+ * Ciphersuite: **BLS12-381-SHA-256** — `BBS_BLS12381G1_XMD:SHA-256_SSWU_RO_`.
6
+ * - signatures/generators live in G1 (48-byte compressed points), public keys in G2 (96-byte
7
+ * compressed points), scalars are 32 bytes big-endian in the field of order `r`;
8
+ * - hashing uses `expand_message_xmd` with SHA-256 (RFC 9380), `expand_len = 48`;
9
+ * - the api_id is `ciphersuite_id || "H2G_HM2S_"`.
10
+ *
11
+ * A BBS signature covers an ORDERED VECTOR of messages. From one signature a holder can produce an
12
+ * unlimited number of zero-knowledge proofs, each revealing an arbitrary SUBSET of the messages and
13
+ * proving knowledge of the rest — with two properties that make this the privacy frontier for agent
14
+ * authority:
15
+ * - SELECTIVE DISCLOSURE: the verifier learns only the disclosed messages;
16
+ * - UNLINKABILITY: the signature value `A` is never shown (it is blinded into `Ā`, `B̄`, `D` with
17
+ * fresh randomness every time), so two presentations of the same credential cannot be correlated.
18
+ *
19
+ * Implementation notes:
20
+ * - Scalar arithmetic uses the curve's own scalar field `Fr` (order `r`); point arithmetic uses
21
+ * `multiplyUnsafe` (variable-time). This mirrors the draft's reference clarity and is appropriate
22
+ * for the public blinding operations here; it is NOT a constant-time implementation and callers
23
+ * holding long-lived secret keys in an adversarial co-tenant should keep that in mind.
24
+ * - All cross-language octet encodings (point/scalar/integer serialization, challenge and domain
25
+ * inputs) follow the draft so a conforming verifier in another language interoperates.
26
+ */
27
+ import { bls12_381 } from '@noble/curves/bls12-381';
28
+ /** A point of G1 (signatures, generators, proof commitments). */
29
+ export type G1Point = InstanceType<typeof bls12_381.G1.ProjectivePoint>;
30
+ /** A point of G2 (public keys). */
31
+ export type G2Point = InstanceType<typeof bls12_381.G2.ProjectivePoint>;
32
+ /** Order of the BBS scalar field (the prime subgroup order `r`). */
33
+ export declare const R: bigint;
34
+ /** The ciphersuite identifier (without the api_id suffix). */
35
+ export declare const CIPHERSUITE_ID = "BBS_BLS12381G1_XMD:SHA-256_SSWU_RO_";
36
+ /** api_id = ciphersuite_id || "H2G_HM2S_". */
37
+ export declare const API_ID = "BBS_BLS12381G1_XMD:SHA-256_SSWU_RO_H2G_HM2S_";
38
+ /** hash_to_scalar(msg, dst) = OS2IP(expand_message_xmd(msg, dst, 48)) mod r (draft §4.2.2). */
39
+ export declare function hashToScalar(msg: Uint8Array, dst: string): bigint;
40
+ /** MapMessageToScalarAsHash: one message octet string -> one scalar (draft §4.2). */
41
+ export declare function mapMessageToScalarAsHash(message: Uint8Array): bigint;
42
+ /** messages_to_scalars: map each message octet string to its scalar (draft §4.2). */
43
+ export declare function messagesToScalars(messages: readonly Uint8Array[]): bigint[];
44
+ /**
45
+ * create_generators(count): the deterministic generator sequence `(Q_1, H_1, ..., H_{count-1})`
46
+ * (draft §4.1). Each generator is the hash-to-curve of a chained `expand_message` ratchet.
47
+ */
48
+ export declare function createGenerators(count: number): G1Point[];
49
+ /**
50
+ * KeyGen: derive a secret scalar `SK` from key material and optional context info (draft §3.4.1).
51
+ * Requires at least 32 octets of key material. Returns the scalar; never 0.
52
+ */
53
+ export declare function keyGen(keyMaterial: Uint8Array, keyInfo?: Uint8Array): bigint;
54
+ /** SkToPk: the public key octets `point_to_octets_E2(SK · BP2)` (draft §3.4.2). */
55
+ export declare function skToPk(sk: bigint): Uint8Array;
56
+ /** Convenience: generate a fresh (SK scalar, PK octets) pair from the system CSPRNG. */
57
+ export declare function generateKeyPair(): {
58
+ sk: bigint;
59
+ pk: Uint8Array;
60
+ };
61
+ /** A 32-octet big-endian secret scalar (e.g. to serialize or parse a given SK). */
62
+ export declare function skToBytes(sk: bigint): Uint8Array;
63
+ export declare function skFromBytes(bytes: Uint8Array): bigint;
64
+ /**
65
+ * Sign(SK, PK, header, messages): produce an 80-octet BBS signature over the ordered message vector.
66
+ * `header` is an optional application-bound context signed into the credential (not selectively
67
+ * disclosable). Returns `signature_to_octets(A, e)`.
68
+ */
69
+ export declare function sign(sk: bigint, pk: Uint8Array, header: Uint8Array, messages: readonly Uint8Array[]): Uint8Array;
70
+ /** Verify(PK, signature, header, messages): true iff the signature covers exactly these messages. */
71
+ export declare function verify(pk: Uint8Array, signature: Uint8Array, header: Uint8Array, messages: readonly Uint8Array[]): boolean;
72
+ /**
73
+ * ProofGen(PK, signature, header, ph, messages, disclosed_indexes): a zero-knowledge
74
+ * proof-of-knowledge of the signature that selectively discloses the messages at
75
+ * `disclosed_indexes`. `ph` is the presentation header (binds the proof to a context, e.g. a nonce
76
+ * or the request it authorizes). The proof is randomized: each call produces different octets.
77
+ */
78
+ export declare function proofGen(pk: Uint8Array, signature: Uint8Array, header: Uint8Array, ph: Uint8Array, messages: readonly Uint8Array[], disclosedIndexes: readonly number[]): Uint8Array;
79
+ /**
80
+ * ProofVerify(PK, proof, header, ph, disclosed_messages, disclosed_indexes): true iff `proof` is a
81
+ * valid selective-disclosure proof under `PK` revealing exactly `disclosed_messages` at
82
+ * `disclosed_indexes`, bound to `header` and `ph`. `disclosed_messages[k]` must correspond to
83
+ * `disclosed_indexes[k]`.
84
+ */
85
+ export declare function proofVerify(pk: Uint8Array, proof: Uint8Array, header: Uint8Array, ph: Uint8Array, disclosedMessages: readonly Uint8Array[], disclosedIndexes: readonly number[]): boolean;
package/dist/bbs.js ADDED
@@ -0,0 +1,454 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.API_ID = exports.CIPHERSUITE_ID = exports.R = void 0;
4
+ exports.hashToScalar = hashToScalar;
5
+ exports.mapMessageToScalarAsHash = mapMessageToScalarAsHash;
6
+ exports.messagesToScalars = messagesToScalars;
7
+ exports.createGenerators = createGenerators;
8
+ exports.keyGen = keyGen;
9
+ exports.skToPk = skToPk;
10
+ exports.generateKeyPair = generateKeyPair;
11
+ exports.skToBytes = skToBytes;
12
+ exports.skFromBytes = skFromBytes;
13
+ exports.sign = sign;
14
+ exports.verify = verify;
15
+ exports.proofGen = proofGen;
16
+ exports.proofVerify = proofVerify;
17
+ /**
18
+ * BBS signatures over BLS12-381, faithful to draft-irtf-cfrg-bbs-signatures (the 2023–2024 CFRG
19
+ * draft; this implementation follows draft-07's core protocol and octet encodings).
20
+ *
21
+ * Ciphersuite: **BLS12-381-SHA-256** — `BBS_BLS12381G1_XMD:SHA-256_SSWU_RO_`.
22
+ * - signatures/generators live in G1 (48-byte compressed points), public keys in G2 (96-byte
23
+ * compressed points), scalars are 32 bytes big-endian in the field of order `r`;
24
+ * - hashing uses `expand_message_xmd` with SHA-256 (RFC 9380), `expand_len = 48`;
25
+ * - the api_id is `ciphersuite_id || "H2G_HM2S_"`.
26
+ *
27
+ * A BBS signature covers an ORDERED VECTOR of messages. From one signature a holder can produce an
28
+ * unlimited number of zero-knowledge proofs, each revealing an arbitrary SUBSET of the messages and
29
+ * proving knowledge of the rest — with two properties that make this the privacy frontier for agent
30
+ * authority:
31
+ * - SELECTIVE DISCLOSURE: the verifier learns only the disclosed messages;
32
+ * - UNLINKABILITY: the signature value `A` is never shown (it is blinded into `Ā`, `B̄`, `D` with
33
+ * fresh randomness every time), so two presentations of the same credential cannot be correlated.
34
+ *
35
+ * Implementation notes:
36
+ * - Scalar arithmetic uses the curve's own scalar field `Fr` (order `r`); point arithmetic uses
37
+ * `multiplyUnsafe` (variable-time). This mirrors the draft's reference clarity and is appropriate
38
+ * for the public blinding operations here; it is NOT a constant-time implementation and callers
39
+ * holding long-lived secret keys in an adversarial co-tenant should keep that in mind.
40
+ * - All cross-language octet encodings (point/scalar/integer serialization, challenge and domain
41
+ * inputs) follow the draft so a conforming verifier in another language interoperates.
42
+ */
43
+ const bls12_381_1 = require("@noble/curves/bls12-381");
44
+ const hash_to_curve_1 = require("@noble/curves/abstract/hash-to-curve");
45
+ const utils_1 = require("@noble/curves/abstract/utils");
46
+ const sha256_1 = require("@noble/hashes/sha256");
47
+ const utils_2 = require("@noble/hashes/utils");
48
+ // ---- curve handles ----------------------------------------------------------------------------
49
+ const G1 = bls12_381_1.bls12_381.G1.ProjectivePoint;
50
+ const G2 = bls12_381_1.bls12_381.G2.ProjectivePoint;
51
+ const Fr = bls12_381_1.bls12_381.fields.Fr;
52
+ const Fp12 = bls12_381_1.bls12_381.fields.Fp12;
53
+ /** Order of the BBS scalar field (the prime subgroup order `r`). */
54
+ exports.R = Fr.ORDER;
55
+ // ---- ciphersuite constants (BLS12-381-SHA-256) ------------------------------------------------
56
+ /** The ciphersuite identifier (without the api_id suffix). */
57
+ exports.CIPHERSUITE_ID = 'BBS_BLS12381G1_XMD:SHA-256_SSWU_RO_';
58
+ /** api_id = ciphersuite_id || "H2G_HM2S_". */
59
+ exports.API_ID = `${exports.CIPHERSUITE_ID}H2G_HM2S_`;
60
+ const OCTET_SCALAR_LENGTH = 32;
61
+ const OCTET_POINT_LENGTH = 48; // G1, compressed
62
+ const EXPAND_LEN = 48;
63
+ const H2S_DST = `${exports.API_ID}H2S_`;
64
+ const MAP_DST = `${exports.API_ID}MAP_MSG_TO_SCALAR_AS_HASH_`;
65
+ const SEED_DST = `${exports.API_ID}SIG_GENERATOR_SEED_`;
66
+ const GEN_DST = `${exports.API_ID}SIG_GENERATOR_DST_`;
67
+ const GEN_SEED = `${exports.API_ID}MESSAGE_GENERATOR_SEED`;
68
+ const KEYGEN_DST = `${exports.CIPHERSUITE_ID}KEYGEN_DST_`;
69
+ /**
70
+ * P1: the fixed G1 generator of the BLS12-381-SHA-256 ciphersuite (draft §7.2.2), as published.
71
+ * Signing commits the message vector against P1, Q_1 and the per-message generators H_i.
72
+ */
73
+ const P1_HEX = 'a8ce256102840821a3e94ea9025e4662b205762f9776b3a766c872b948f1fd225e7c59698588e70d11406d161b4e28c9';
74
+ const P1 = G1.fromHex(P1_HEX);
75
+ /** The base point of G2 (public keys are `SK · BP2`). */
76
+ const BP2 = G2.BASE;
77
+ // ---- small octet / scalar helpers -------------------------------------------------------------
78
+ const TEXT = new TextEncoder();
79
+ function ascii(s) {
80
+ return TEXT.encode(s);
81
+ }
82
+ /** I2OSP: non-negative integer -> fixed-length big-endian octets (RFC 8017 §4.1). */
83
+ function i2osp(n, len) {
84
+ return (0, utils_1.numberToBytesBE)(n, len);
85
+ }
86
+ /** OS2IP: big-endian octets -> non-negative integer (RFC 8017 §4.2). */
87
+ function os2ip(b) {
88
+ return (0, utils_1.bytesToNumberBE)(b);
89
+ }
90
+ /** Checked array read (keeps `noUncheckedIndexedAccess` honest without non-null assertions). */
91
+ function at(arr, i) {
92
+ const v = arr[i];
93
+ if (v === undefined)
94
+ throw new RangeError(`bbs: index ${i} out of range (len ${arr.length})`);
95
+ return v;
96
+ }
97
+ /** expand_message_xmd with SHA-256 (RFC 9380 §5.3.1). */
98
+ function expand(msg, dst, len) {
99
+ return (0, hash_to_curve_1.expand_message_xmd)(msg, ascii(dst), len, sha256_1.sha256);
100
+ }
101
+ /** hash_to_scalar(msg, dst) = OS2IP(expand_message_xmd(msg, dst, 48)) mod r (draft §4.2.2). */
102
+ function hashToScalar(msg, dst) {
103
+ return Fr.create(os2ip(expand(msg, dst, EXPAND_LEN)));
104
+ }
105
+ /** MapMessageToScalarAsHash: one message octet string -> one scalar (draft §4.2). */
106
+ function mapMessageToScalarAsHash(message) {
107
+ return hashToScalar(message, MAP_DST);
108
+ }
109
+ /** messages_to_scalars: map each message octet string to its scalar (draft §4.2). */
110
+ function messagesToScalars(messages) {
111
+ return messages.map((m) => mapMessageToScalarAsHash(m));
112
+ }
113
+ /**
114
+ * create_generators(count): the deterministic generator sequence `(Q_1, H_1, ..., H_{count-1})`
115
+ * (draft §4.1). Each generator is the hash-to-curve of a chained `expand_message` ratchet.
116
+ */
117
+ function createGenerators(count) {
118
+ if (!Number.isInteger(count) || count < 0)
119
+ throw new RangeError('bbs: generator count must be a non-negative integer');
120
+ const gens = [];
121
+ let v = expand(ascii(GEN_SEED), SEED_DST, EXPAND_LEN);
122
+ for (let i = 1; i <= count; i++) {
123
+ v = expand((0, utils_1.concatBytes)(v, i2osp(BigInt(i), 8)), SEED_DST, EXPAND_LEN);
124
+ const h2c = bls12_381_1.bls12_381.G1.hashToCurve(v, { DST: GEN_DST });
125
+ gens.push(G1.fromAffine(h2c.toAffine()));
126
+ }
127
+ return gens;
128
+ }
129
+ function serialize(els) {
130
+ const parts = [];
131
+ for (const el of els) {
132
+ switch (el.t) {
133
+ case 'g1':
134
+ parts.push(el.v.toRawBytes(true));
135
+ break;
136
+ case 'g2':
137
+ parts.push(el.v.toRawBytes(true));
138
+ break;
139
+ case 'scalar':
140
+ parts.push(i2osp(el.v, OCTET_SCALAR_LENGTH));
141
+ break;
142
+ case 'int':
143
+ parts.push(i2osp(BigInt(el.v), 8));
144
+ break;
145
+ }
146
+ }
147
+ return (0, utils_1.concatBytes)(...parts);
148
+ }
149
+ // ---- point arithmetic helpers -----------------------------------------------------------------
150
+ function g1mul(P, s) {
151
+ const sc = Fr.create(s);
152
+ return sc === 0n ? G1.ZERO : P.multiplyUnsafe(sc);
153
+ }
154
+ function g2mul(P, s) {
155
+ const sc = Fr.create(s);
156
+ return sc === 0n ? G2.ZERO : P.multiplyUnsafe(sc);
157
+ }
158
+ // ---- key generation (draft §3.4) --------------------------------------------------------------
159
+ /**
160
+ * KeyGen: derive a secret scalar `SK` from key material and optional context info (draft §3.4.1).
161
+ * Requires at least 32 octets of key material. Returns the scalar; never 0.
162
+ */
163
+ function keyGen(keyMaterial, keyInfo = new Uint8Array(0)) {
164
+ if (keyMaterial.length < 32)
165
+ throw new RangeError('bbs: key material must be at least 32 octets');
166
+ if (keyInfo.length > 65535)
167
+ throw new RangeError('bbs: key info must be at most 65535 octets');
168
+ const deriveInput = (0, utils_1.concatBytes)(keyMaterial, i2osp(BigInt(keyInfo.length), 2), keyInfo);
169
+ const sk = hashToScalar(deriveInput, KEYGEN_DST);
170
+ if (sk === 0n)
171
+ throw new Error('bbs: derived SK is zero (retry with different key material)');
172
+ return sk;
173
+ }
174
+ /** SkToPk: the public key octets `point_to_octets_E2(SK · BP2)` (draft §3.4.2). */
175
+ function skToPk(sk) {
176
+ return g2mul(BP2, sk).toRawBytes(true);
177
+ }
178
+ /** Convenience: generate a fresh (SK scalar, PK octets) pair from the system CSPRNG. */
179
+ function generateKeyPair() {
180
+ const sk = keyGen((0, utils_2.randomBytes)(32));
181
+ return { sk, pk: skToPk(sk) };
182
+ }
183
+ /** A 32-octet big-endian secret scalar (e.g. to serialize or parse a given SK). */
184
+ function skToBytes(sk) {
185
+ return i2osp(sk, OCTET_SCALAR_LENGTH);
186
+ }
187
+ function skFromBytes(bytes) {
188
+ if (bytes.length !== OCTET_SCALAR_LENGTH)
189
+ throw new RangeError('bbs: SK must be 32 octets');
190
+ const sk = os2ip(bytes);
191
+ if (sk === 0n || sk >= exports.R)
192
+ throw new RangeError('bbs: SK out of range');
193
+ return sk;
194
+ }
195
+ function signatureToOctets(A, e) {
196
+ return (0, utils_1.concatBytes)(A.toRawBytes(true), i2osp(e, OCTET_SCALAR_LENGTH));
197
+ }
198
+ function octetsToSignature(sig) {
199
+ if (sig.length !== OCTET_POINT_LENGTH + OCTET_SCALAR_LENGTH) {
200
+ throw new RangeError('bbs: signature must be 80 octets');
201
+ }
202
+ const A = G1.fromHex(sig.subarray(0, OCTET_POINT_LENGTH));
203
+ if (A.equals(G1.ZERO))
204
+ throw new Error('bbs: signature point A is the identity');
205
+ const e = os2ip(sig.subarray(OCTET_POINT_LENGTH));
206
+ if (e <= 0n || e >= exports.R)
207
+ throw new RangeError('bbs: signature scalar e out of range');
208
+ return { A, e };
209
+ }
210
+ // ---- domain (draft §4.2.3) --------------------------------------------------------------------
211
+ function calculateDomain(pk, Q1, H, header) {
212
+ const els = [{ t: 'int', v: H.length }, { t: 'g1', v: Q1 }];
213
+ for (const h of H)
214
+ els.push({ t: 'g1', v: h });
215
+ const domOcts = (0, utils_1.concatBytes)(serialize(els), ascii(exports.API_ID));
216
+ const domInput = (0, utils_1.concatBytes)(pk, domOcts, i2osp(BigInt(header.length), 8), header);
217
+ return hashToScalar(domInput, H2S_DST);
218
+ }
219
+ /** B = P1 + Q_1·domain + Σ H_i·msg_i (the common commitment used by Sign/Verify/ProofGen). */
220
+ function computeB(Q1, H, domain, msgScalars) {
221
+ let B = P1.add(g1mul(Q1, domain));
222
+ for (let i = 0; i < msgScalars.length; i++) {
223
+ B = B.add(g1mul(at(H, i), at(msgScalars, i)));
224
+ }
225
+ return B;
226
+ }
227
+ // ---- Sign / Verify (draft §3.5.1 / §3.5.2, cores §3.6.1 / §3.6.2) -----------------------------
228
+ /**
229
+ * Sign(SK, PK, header, messages): produce an 80-octet BBS signature over the ordered message vector.
230
+ * `header` is an optional application-bound context signed into the credential (not selectively
231
+ * disclosable). Returns `signature_to_octets(A, e)`.
232
+ */
233
+ function sign(sk, pk, header, messages) {
234
+ const msgScalars = messagesToScalars(messages);
235
+ const L = msgScalars.length;
236
+ const gens = createGenerators(L + 1);
237
+ const Q1 = at(gens, 0);
238
+ const H = gens.slice(1);
239
+ const domain = calculateDomain(pk, Q1, H, header);
240
+ // e = hash_to_scalar(serialize(SK, msg_1, ..., msg_L, domain), H2S_DST) (deterministic nonce)
241
+ const eEls = [{ t: 'scalar', v: sk }];
242
+ for (const m of msgScalars)
243
+ eEls.push({ t: 'scalar', v: m });
244
+ eEls.push({ t: 'scalar', v: domain });
245
+ const e = hashToScalar(serialize(eEls), H2S_DST);
246
+ const B = computeB(Q1, H, domain, msgScalars);
247
+ const A = g1mul(B, Fr.inv(Fr.add(sk, e))); // A = B · 1/(SK + e)
248
+ return signatureToOctets(A, e);
249
+ }
250
+ /** Verify(PK, signature, header, messages): true iff the signature covers exactly these messages. */
251
+ function verify(pk, signature, header, messages) {
252
+ let parsed;
253
+ let W;
254
+ try {
255
+ parsed = octetsToSignature(signature);
256
+ W = G2.fromHex(pk);
257
+ }
258
+ catch {
259
+ return false;
260
+ }
261
+ if (W.equals(G2.ZERO))
262
+ return false;
263
+ const msgScalars = messagesToScalars(messages);
264
+ const L = msgScalars.length;
265
+ const gens = createGenerators(L + 1);
266
+ const Q1 = at(gens, 0);
267
+ const H = gens.slice(1);
268
+ const domain = calculateDomain(pk, Q1, H, header);
269
+ const B = computeB(Q1, H, domain, msgScalars);
270
+ // Pairing check: e(A, W + BP2·e) == e(B, BP2) ⇔ e(A, (SK+e)·BP2) == e(B, BP2).
271
+ const lhs = bls12_381_1.bls12_381.pairing(parsed.A, W.add(g2mul(BP2, parsed.e)));
272
+ const rhs = bls12_381_1.bls12_381.pairing(B, BP2);
273
+ return Fp12.eql(lhs, rhs);
274
+ }
275
+ // ---- random scalars (draft §4.2.1) ------------------------------------------------------------
276
+ function calculateRandomScalars(count) {
277
+ const out = [];
278
+ for (let i = 0; i < count; i++)
279
+ out.push(Fr.create(os2ip((0, utils_2.randomBytes)(EXPAND_LEN))));
280
+ return out;
281
+ }
282
+ // ---- challenge (draft §3.7.4 ProofChallengeCalculate) -----------------------------------------
283
+ function calculateChallenge(Abar, Bbar, D, T1, T2, disclosedIndexes, disclosedMsgs, domain, ph) {
284
+ const els = [{ t: 'int', v: disclosedIndexes.length }];
285
+ for (let k = 0; k < disclosedIndexes.length; k++) {
286
+ els.push({ t: 'int', v: at(disclosedIndexes, k) });
287
+ els.push({ t: 'scalar', v: at(disclosedMsgs, k) });
288
+ }
289
+ els.push({ t: 'g1', v: Abar }, { t: 'g1', v: Bbar }, { t: 'g1', v: D }, { t: 'g1', v: T1 }, { t: 'g1', v: T2 }, { t: 'scalar', v: domain });
290
+ const cOcts = (0, utils_1.concatBytes)(serialize(els), i2osp(BigInt(ph.length), 8), ph);
291
+ return hashToScalar(cOcts, H2S_DST);
292
+ }
293
+ function proofToOctets(p) {
294
+ const parts = [p.Abar.toRawBytes(true), p.Bbar.toRawBytes(true), p.D.toRawBytes(true)];
295
+ parts.push(i2osp(p.eHat, OCTET_SCALAR_LENGTH), i2osp(p.r1Hat, OCTET_SCALAR_LENGTH), i2osp(p.r3Hat, OCTET_SCALAR_LENGTH));
296
+ for (const m of p.mHat)
297
+ parts.push(i2osp(m, OCTET_SCALAR_LENGTH));
298
+ parts.push(i2osp(p.c, OCTET_SCALAR_LENGTH));
299
+ return (0, utils_1.concatBytes)(...parts);
300
+ }
301
+ function readScalar(proof, offset) {
302
+ const v = os2ip(proof.subarray(offset, offset + OCTET_SCALAR_LENGTH));
303
+ if (v >= exports.R)
304
+ throw new RangeError('bbs: proof scalar out of range');
305
+ return v;
306
+ }
307
+ function octetsToProof(proof) {
308
+ const fixed = 3 * OCTET_POINT_LENGTH + 4 * OCTET_SCALAR_LENGTH; // 3 points + eHat,r1Hat,r3Hat,c
309
+ if (proof.length < fixed || (proof.length - fixed) % OCTET_SCALAR_LENGTH !== 0) {
310
+ throw new RangeError('bbs: malformed proof length');
311
+ }
312
+ let o = 0;
313
+ const Abar = G1.fromHex(proof.subarray(o, (o += OCTET_POINT_LENGTH)));
314
+ const Bbar = G1.fromHex(proof.subarray(o, (o += OCTET_POINT_LENGTH)));
315
+ const D = G1.fromHex(proof.subarray(o, (o += OCTET_POINT_LENGTH)));
316
+ const eHat = readScalar(proof, o);
317
+ o += OCTET_SCALAR_LENGTH;
318
+ const r1Hat = readScalar(proof, o);
319
+ o += OCTET_SCALAR_LENGTH;
320
+ const r3Hat = readScalar(proof, o);
321
+ o += OCTET_SCALAR_LENGTH;
322
+ const U = (proof.length - fixed) / OCTET_SCALAR_LENGTH;
323
+ const mHat = [];
324
+ for (let i = 0; i < U; i++) {
325
+ mHat.push(readScalar(proof, o));
326
+ o += OCTET_SCALAR_LENGTH;
327
+ }
328
+ const c = readScalar(proof, o);
329
+ if (Abar.equals(G1.ZERO) || Bbar.equals(G1.ZERO) || D.equals(G1.ZERO)) {
330
+ throw new Error('bbs: proof contains the identity point');
331
+ }
332
+ return { Abar, Bbar, D, eHat, r1Hat, r3Hat, mHat, c };
333
+ }
334
+ // ---- index-set helpers ------------------------------------------------------------------------
335
+ function validateIndexes(indexes, L) {
336
+ const seen = new Set();
337
+ for (const i of indexes) {
338
+ if (!Number.isInteger(i) || i < 0 || i >= L)
339
+ throw new RangeError(`bbs: disclosed index ${i} out of range [0, ${L})`);
340
+ if (seen.has(i))
341
+ throw new RangeError(`bbs: duplicate disclosed index ${i}`);
342
+ seen.add(i);
343
+ }
344
+ }
345
+ function undisclosedAscending(disclosed, L) {
346
+ const out = [];
347
+ for (let i = 0; i < L; i++)
348
+ if (!disclosed.has(i))
349
+ out.push(i);
350
+ return out;
351
+ }
352
+ // ---- ProofGen (draft §3.5.3, core §3.6.3) -----------------------------------------------------
353
+ /**
354
+ * ProofGen(PK, signature, header, ph, messages, disclosed_indexes): a zero-knowledge
355
+ * proof-of-knowledge of the signature that selectively discloses the messages at
356
+ * `disclosed_indexes`. `ph` is the presentation header (binds the proof to a context, e.g. a nonce
357
+ * or the request it authorizes). The proof is randomized: each call produces different octets.
358
+ */
359
+ function proofGen(pk, signature, header, ph, messages, disclosedIndexes) {
360
+ const { A, e } = octetsToSignature(signature);
361
+ const msgScalars = messagesToScalars(messages);
362
+ const L = msgScalars.length;
363
+ validateIndexes(disclosedIndexes, L);
364
+ const disclosedSet = new Set(disclosedIndexes);
365
+ const disclosed = [...disclosedSet].sort((a, b) => a - b);
366
+ const undisclosed = undisclosedAscending(disclosedSet, L);
367
+ const U = undisclosed.length;
368
+ const gens = createGenerators(L + 1);
369
+ const Q1 = at(gens, 0);
370
+ const H = gens.slice(1);
371
+ const domain = calculateDomain(pk, Q1, H, header);
372
+ const B = computeB(Q1, H, domain, msgScalars);
373
+ const rs = calculateRandomScalars(5 + U);
374
+ const r1 = at(rs, 0);
375
+ const r2 = at(rs, 1);
376
+ const eTilde = at(rs, 2);
377
+ const r1Tilde = at(rs, 3);
378
+ const r3Tilde = at(rs, 4);
379
+ const mTilde = rs.slice(5);
380
+ const D = g1mul(B, r2);
381
+ const Abar = g1mul(A, Fr.mul(r1, r2));
382
+ const Bbar = g1mul(D, r1).subtract(g1mul(Abar, e));
383
+ const T1 = g1mul(Abar, eTilde).add(g1mul(D, r1Tilde));
384
+ let T2 = g1mul(D, r3Tilde);
385
+ for (let k = 0; k < U; k++)
386
+ T2 = T2.add(g1mul(at(H, at(undisclosed, k)), at(mTilde, k)));
387
+ const disclosedMsgs = disclosed.map((i) => at(msgScalars, i));
388
+ const c = calculateChallenge(Abar, Bbar, D, T1, T2, disclosed, disclosedMsgs, domain, ph);
389
+ const r3 = Fr.inv(r2);
390
+ const eHat = Fr.add(eTilde, Fr.mul(e, c));
391
+ const r1Hat = Fr.sub(r1Tilde, Fr.mul(r1, c));
392
+ const r3Hat = Fr.sub(r3Tilde, Fr.mul(r3, c));
393
+ const mHat = [];
394
+ for (let k = 0; k < U; k++)
395
+ mHat.push(Fr.add(at(mTilde, k), Fr.mul(at(msgScalars, at(undisclosed, k)), c)));
396
+ return proofToOctets({ Abar, Bbar, D, eHat, r1Hat, r3Hat, mHat, c });
397
+ }
398
+ // ---- ProofVerify (draft §3.5.4, core §3.6.4) --------------------------------------------------
399
+ /**
400
+ * ProofVerify(PK, proof, header, ph, disclosed_messages, disclosed_indexes): true iff `proof` is a
401
+ * valid selective-disclosure proof under `PK` revealing exactly `disclosed_messages` at
402
+ * `disclosed_indexes`, bound to `header` and `ph`. `disclosed_messages[k]` must correspond to
403
+ * `disclosed_indexes[k]`.
404
+ */
405
+ function proofVerify(pk, proof, header, ph, disclosedMessages, disclosedIndexes) {
406
+ let p;
407
+ let W;
408
+ try {
409
+ p = octetsToProof(proof);
410
+ W = G2.fromHex(pk);
411
+ }
412
+ catch {
413
+ return false;
414
+ }
415
+ if (W.equals(G2.ZERO))
416
+ return false;
417
+ if (disclosedMessages.length !== disclosedIndexes.length)
418
+ return false;
419
+ const U = p.mHat.length;
420
+ const R_count = disclosedIndexes.length;
421
+ const L = R_count + U;
422
+ let disclosed;
423
+ try {
424
+ validateIndexes(disclosedIndexes, L);
425
+ const disclosedScalars = messagesToScalars(disclosedMessages);
426
+ disclosed = disclosedIndexes.map((idx, k) => ({ idx, msg: at(disclosedScalars, k) }));
427
+ }
428
+ catch {
429
+ return false;
430
+ }
431
+ disclosed.sort((a, b) => a.idx - b.idx);
432
+ const disclosedSet = new Set(disclosed.map((d) => d.idx));
433
+ const undisclosed = undisclosedAscending(disclosedSet, L);
434
+ const gens = createGenerators(L + 1);
435
+ const Q1 = at(gens, 0);
436
+ const H = gens.slice(1);
437
+ const domain = calculateDomain(pk, Q1, H, header);
438
+ // T1 = B̄·c + Ā·ê + D·r̂1
439
+ const T1 = g1mul(p.Bbar, p.c).add(g1mul(p.Abar, p.eHat)).add(g1mul(p.D, p.r1Hat));
440
+ // Bv = P1 + Q_1·domain + Σ_{disclosed} H_i·msg_i
441
+ let Bv = P1.add(g1mul(Q1, domain));
442
+ for (const d of disclosed)
443
+ Bv = Bv.add(g1mul(at(H, d.idx), d.msg));
444
+ // T2 = Bv·c + D·r̂3 + Σ_{undisclosed} H_j·m̂_j
445
+ let T2 = g1mul(Bv, p.c).add(g1mul(p.D, p.r3Hat));
446
+ for (let k = 0; k < U; k++)
447
+ T2 = T2.add(g1mul(at(H, at(undisclosed, k)), at(p.mHat, k)));
448
+ const cv = calculateChallenge(p.Abar, p.Bbar, p.D, T1, T2, disclosed.map((d) => d.idx), disclosed.map((d) => d.msg), domain, ph);
449
+ if (cv !== p.c)
450
+ return false;
451
+ // Final pairing: e(Ā, W) == e(B̄, BP2).
452
+ return Fp12.eql(bls12_381_1.bls12_381.pairing(p.Abar, W), bls12_381_1.bls12_381.pairing(p.Bbar, BP2));
453
+ }
454
+ //# sourceMappingURL=bbs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bbs.js","sourceRoot":"","sources":["../src/bbs.ts"],"names":[],"mappings":";;;AAwGA,oCAEC;AAGD,4DAEC;AAGD,8CAEC;AAMD,4CAUC;AAiDD,wBAOC;AAGD,wBAEC;AAGD,0CAGC;AAGD,8BAEC;AACD,kCAKC;AAkDD,oBAiBC;AAGD,wBAsBC;A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SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,EAC3B,MAAM,EACN,EAAE,CACH,CAAC;IACF,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IAE7B,wCAAwC;IACxC,OAAO,IAAI,CAAC,GAAG,CAAC,qBAAS,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,qBAAS,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;AAChF,CAAC"}
@@ -0,0 +1,112 @@
1
+ /**
2
+ * PCA layer: a Proof-Carrying Authority capability as a multi-message BBS credential.
3
+ *
4
+ * A PCA {@link Capability} authorizes a holder under an issuer, constrained by an append-only list
5
+ * of caveats (scopes/limits). Normally a capability travels as a signed chain and is presented
6
+ * whole — every attribute is visible to whoever verifies it. That is fine for a server, but it
7
+ * leaks: a tool that only needs to know "the holder may call search" also learns the budget caveat,
8
+ * the delegation lineage, and a stable signature value it can use to correlate requests.
9
+ *
10
+ * Here we map the capability's attributes to an ORDERED BBS message vector and sign it once. The
11
+ * holder can then present it with SELECTIVE DISCLOSURE: reveal only the attributes a given tool
12
+ * needs, and prove in zero knowledge that the issuer signed the rest — without showing them, and
13
+ * without showing the signature. Because every presentation re-randomizes the signature, two
14
+ * presentations of the same credential are UNLINKABLE.
15
+ *
16
+ * ## Attribute ↔ message mapping
17
+ *
18
+ * The message vector is, in order:
19
+ * - index 0: `iss` — the issuer public key
20
+ * - index 1: `sub` — the holder (subject) public key
21
+ * - index 2..: one message per caveat, name `cav:<i>:<type>`, value the strict-canonical JSON of
22
+ * the caveat object (so a caveat's full content is one atomically-disclosable attribute).
23
+ *
24
+ * Each message's octets are `utf8(name) || 0x00 || utf8(value)`: the NUL separator makes the name
25
+ * unambiguous, and binding the name into the signed message means a verifier that reconstructs a
26
+ * disclosed attribute from `{name, value}` gets byte-identical octets, so disclosing index `i` as a
27
+ * different attribute cannot verify.
28
+ *
29
+ * ## Relationship to a PCActn
30
+ *
31
+ * A PCActn (proof-carrying action) normally carries the capability chain plus a signed action/plan
32
+ * commitment, which the adjudicator verifies in full. For privacy-sensitive flows, the capability
33
+ * component can instead be carried as a {@link BBSPresentation}: the agent discloses only the
34
+ * attributes the action needs (e.g. the scope caveat that authorizes this exact tool call) and
35
+ * proves knowledge of the issuer's signature over the whole credential. The presentation header
36
+ * (`ph`) binds the proof to the action — pass the PCActn's action/nonce digest as `presentationHeader`
37
+ * so a proof minted for one action cannot be replayed against another. The adjudicator then checks
38
+ * the BBS proof in place of the raw signed chain; the undisclosed attributes stay hidden and the
39
+ * action is still cryptographically bound to an issuer-signed grant.
40
+ */
41
+ import type { Capability } from '@atlasauth/pca';
42
+ /** One disclosable attribute of a capability credential, at its position in the message vector. */
43
+ export interface CredentialAttribute {
44
+ /** Position in the BBS message vector (0 = issuer, 1 = holder, 2.. = caveats). */
45
+ index: number;
46
+ /** Stable attribute name (`iss`, `sub`, or `cav:<i>:<type>`). */
47
+ name: string;
48
+ /** The attribute's value (a key for `iss`/`sub`, strict-canonical JSON for a caveat). */
49
+ value: string;
50
+ }
51
+ /** A capability signed as a BBS credential. Portable; `signature` is the issuer's BBS signature. */
52
+ export interface BBSCredential {
53
+ /** b64u of the issuer's BBS public key (G2 point). */
54
+ issuerPublicKey: string;
55
+ /** b64u of the signed header (application context bound into the signature). */
56
+ header: string;
57
+ /** The ordered attribute vector that was signed. */
58
+ attributes: CredentialAttribute[];
59
+ /** b64u of the 80-octet BBS signature. */
60
+ signature: string;
61
+ }
62
+ /** A selective-disclosure presentation of a {@link BBSCredential}. Self-contained and verifiable. */
63
+ export interface BBSPresentation {
64
+ /** b64u of the issuer's BBS public key the proof is under. */
65
+ issuerPublicKey: string;
66
+ /** b64u of the credential header the proof was made over. */
67
+ header: string;
68
+ /** b64u of the presentation header (`ph`) binding the proof to a context/action. */
69
+ presentationHeader: string;
70
+ /** Total number of messages in the credential (L). */
71
+ messageCount: number;
72
+ /** The attributes actually revealed, each at its original index. */
73
+ disclosed: CredentialAttribute[];
74
+ /** b64u of the BBS proof octets. */
75
+ proof: string;
76
+ }
77
+ /** Build the ordered attribute vector for a capability (issuer, holder, then each caveat). */
78
+ export declare function capabilityAttributes(capability: Pick<Capability, 'issuer' | 'holder' | 'caveats'>): CredentialAttribute[];
79
+ /**
80
+ * issueCapabilityCredential: sign a capability's attributes as a BBS credential.
81
+ * `header` is optional application context bound into the signature (not selectively disclosable).
82
+ */
83
+ export declare function issueCapabilityCredential(capability: Pick<Capability, 'issuer' | 'holder' | 'caveats'>, opts: {
84
+ sk: bigint;
85
+ pk: Uint8Array;
86
+ header?: Uint8Array;
87
+ }): BBSCredential;
88
+ /** Verify a whole credential against its issuer key (no disclosure — checks every attribute). */
89
+ export declare function verifyCredential(cred: BBSCredential): boolean;
90
+ /**
91
+ * presentCredential: produce a selective-disclosure proof revealing only the named attributes.
92
+ * `presentationHeader` binds the proof to a context (e.g. the PCActn action digest / a nonce).
93
+ */
94
+ export declare function presentCredential(cred: BBSCredential, opts: {
95
+ disclose: readonly string[];
96
+ presentationHeader?: Uint8Array;
97
+ }): BBSPresentation;
98
+ /**
99
+ * verifyPresentation: check a selective-disclosure proof. Verifies that the issuer (`pk`) signed a
100
+ * credential whose disclosed attributes are exactly `disclosed` at their indexes, bound to
101
+ * `presentationHeader`. The undisclosed attributes stay hidden.
102
+ *
103
+ * `pk`, `disclosed` and `presentationHeader` default to the values carried in the presentation, so
104
+ * `verifyPresentation(pres)` checks it as-is; pass them to assert the verifier's own expectations
105
+ * (e.g. a pinned issuer key, the exact attributes the tool requires, or the action digest the proof
106
+ * must be bound to).
107
+ */
108
+ export declare function verifyPresentation(pres: BBSPresentation, opts?: {
109
+ pk?: Uint8Array;
110
+ disclosed?: readonly CredentialAttribute[];
111
+ presentationHeader?: Uint8Array;
112
+ }): boolean;
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.capabilityAttributes = capabilityAttributes;
4
+ exports.issueCapabilityCredential = issueCapabilityCredential;
5
+ exports.verifyCredential = verifyCredential;
6
+ exports.presentCredential = presentCredential;
7
+ exports.verifyPresentation = verifyPresentation;
8
+ const pca_1 = require("@atlasauth/pca");
9
+ const bbs_1 = require("./bbs");
10
+ const NAME_ISSUER = 'iss';
11
+ const NAME_HOLDER = 'sub';
12
+ const NUL = 0x00;
13
+ const TEXT = new TextEncoder();
14
+ /** Deterministic message octets for one attribute: utf8(name) || 0x00 || utf8(value). */
15
+ function encodeAttribute(name, value) {
16
+ const n = TEXT.encode(name);
17
+ const v = TEXT.encode(value);
18
+ const out = new Uint8Array(n.length + 1 + v.length);
19
+ out.set(n, 0);
20
+ out[n.length] = NUL;
21
+ out.set(v, n.length + 1);
22
+ return out;
23
+ }
24
+ function encode(attr) {
25
+ return encodeAttribute(attr.name, attr.value);
26
+ }
27
+ /** Build the ordered attribute vector for a capability (issuer, holder, then each caveat). */
28
+ function capabilityAttributes(capability) {
29
+ const attrs = [
30
+ { index: 0, name: NAME_ISSUER, value: capability.issuer },
31
+ { index: 1, name: NAME_HOLDER, value: capability.holder },
32
+ ];
33
+ const caveats = Array.isArray(capability.caveats) ? capability.caveats : [];
34
+ caveats.forEach((cv, i) => {
35
+ attrs.push({ index: i + 2, name: `cav:${i}:${cv.type}`, value: (0, pca_1.canonicalizeStrict)(cv) });
36
+ });
37
+ return attrs;
38
+ }
39
+ /**
40
+ * issueCapabilityCredential: sign a capability's attributes as a BBS credential.
41
+ * `header` is optional application context bound into the signature (not selectively disclosable).
42
+ */
43
+ function issueCapabilityCredential(capability, opts) {
44
+ const attributes = capabilityAttributes(capability);
45
+ const header = opts.header ?? new Uint8Array(0);
46
+ const messages = attributes.map(encode);
47
+ const signature = (0, bbs_1.sign)(opts.sk, opts.pk, header, messages);
48
+ return {
49
+ issuerPublicKey: (0, pca_1.b64u)(opts.pk),
50
+ header: (0, pca_1.b64u)(header),
51
+ attributes,
52
+ signature: (0, pca_1.b64u)(signature),
53
+ };
54
+ }
55
+ /** Verify a whole credential against its issuer key (no disclosure — checks every attribute). */
56
+ function verifyCredential(cred) {
57
+ let pk;
58
+ let header;
59
+ let signature;
60
+ try {
61
+ pk = (0, pca_1.unb64u)(cred.issuerPublicKey);
62
+ header = (0, pca_1.unb64u)(cred.header);
63
+ signature = (0, pca_1.unb64u)(cred.signature);
64
+ }
65
+ catch {
66
+ return false;
67
+ }
68
+ const messages = cred.attributes.map(encode);
69
+ return (0, bbs_1.verify)(pk, signature, header, messages);
70
+ }
71
+ /**
72
+ * presentCredential: produce a selective-disclosure proof revealing only the named attributes.
73
+ * `presentationHeader` binds the proof to a context (e.g. the PCActn action digest / a nonce).
74
+ */
75
+ function presentCredential(cred, opts) {
76
+ const pk = (0, pca_1.unb64u)(cred.issuerPublicKey);
77
+ const header = (0, pca_1.unb64u)(cred.header);
78
+ const signature = (0, pca_1.unb64u)(cred.signature);
79
+ const ph = opts.presentationHeader ?? new Uint8Array(0);
80
+ const wanted = new Set(opts.disclose);
81
+ const messages = cred.attributes.map(encode);
82
+ const disclosedIndexes = [];
83
+ const disclosed = [];
84
+ for (const attr of cred.attributes) {
85
+ if (wanted.has(attr.name)) {
86
+ disclosedIndexes.push(attr.index);
87
+ disclosed.push(attr);
88
+ }
89
+ }
90
+ const missing = [...wanted].filter((name) => !disclosed.some((d) => d.name === name));
91
+ if (missing.length > 0)
92
+ throw new RangeError(`presentCredential: unknown attribute(s): ${missing.join(', ')}`);
93
+ const proof = (0, bbs_1.proofGen)(pk, signature, header, ph, messages, disclosedIndexes);
94
+ return {
95
+ issuerPublicKey: cred.issuerPublicKey,
96
+ header: cred.header,
97
+ presentationHeader: (0, pca_1.b64u)(ph),
98
+ messageCount: cred.attributes.length,
99
+ disclosed,
100
+ proof: (0, pca_1.b64u)(proof),
101
+ };
102
+ }
103
+ /**
104
+ * verifyPresentation: check a selective-disclosure proof. Verifies that the issuer (`pk`) signed a
105
+ * credential whose disclosed attributes are exactly `disclosed` at their indexes, bound to
106
+ * `presentationHeader`. The undisclosed attributes stay hidden.
107
+ *
108
+ * `pk`, `disclosed` and `presentationHeader` default to the values carried in the presentation, so
109
+ * `verifyPresentation(pres)` checks it as-is; pass them to assert the verifier's own expectations
110
+ * (e.g. a pinned issuer key, the exact attributes the tool requires, or the action digest the proof
111
+ * must be bound to).
112
+ */
113
+ function verifyPresentation(pres, opts) {
114
+ let pk;
115
+ let header;
116
+ let proof;
117
+ try {
118
+ pk = opts?.pk ?? (0, pca_1.unb64u)(pres.issuerPublicKey);
119
+ header = (0, pca_1.unb64u)(pres.header);
120
+ proof = (0, pca_1.unb64u)(pres.proof);
121
+ }
122
+ catch {
123
+ return false;
124
+ }
125
+ // If the verifier pinned an issuer key, it must match the one the presentation claims.
126
+ if (opts?.pk !== undefined && (0, pca_1.b64u)(opts.pk) !== pres.issuerPublicKey)
127
+ return false;
128
+ const ph = opts?.presentationHeader ?? safeDecode(pres.presentationHeader);
129
+ if (ph === null)
130
+ return false;
131
+ // If the verifier pinned a presentation header, it must match the one the proof was made over.
132
+ if (opts?.presentationHeader !== undefined && opts.presentationHeader.length > 0 && (0, pca_1.b64u)(ph) !== pres.presentationHeader) {
133
+ return false;
134
+ }
135
+ const disclosed = opts?.disclosed ?? pres.disclosed;
136
+ // When the verifier asserts its own expected disclosure, it must match what the presentation shows.
137
+ if (opts?.disclosed !== undefined && !sameDisclosure(opts.disclosed, pres.disclosed))
138
+ return false;
139
+ const ordered = [...disclosed].sort((a, b) => a.index - b.index);
140
+ const disclosedMessages = ordered.map(encode);
141
+ const disclosedIndexes = ordered.map((d) => d.index);
142
+ if (disclosedIndexes.some((i) => i >= pres.messageCount || i < 0))
143
+ return false;
144
+ return (0, bbs_1.proofVerify)(pk, proof, header, ph, disclosedMessages, disclosedIndexes);
145
+ }
146
+ function safeDecode(s) {
147
+ try {
148
+ return (0, pca_1.unb64u)(s);
149
+ }
150
+ catch {
151
+ return null;
152
+ }
153
+ }
154
+ function sameDisclosure(a, b) {
155
+ if (a.length !== b.length)
156
+ return false;
157
+ const key = (x) => `${x.index}\u0000${x.name}\u0000${x.value}`;
158
+ const sa = a.map(key).sort();
159
+ const sb = b.map(key).sort();
160
+ return sa.every((v, i) => v === sb[i]);
161
+ }
162
+ //# sourceMappingURL=credential.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credential.js","sourceRoot":"","sources":["../src/credential.ts"],"names":[],"mappings":";;AAuGA,oDAUC;AAMD,8DAcC;AAGD,4CAaC;AAMD,8CA+BC;AAYD,gDAmCC;AAhMD,wCAAkE;AAClE,+BAA4D;AAE5D,MAAM,WAAW,GAAG,KAAK,CAAC;AAC1B,MAAM,WAAW,GAAG,KAAK,CAAC;AAC1B,MAAM,GAAG,GAAG,IAAI,CAAC;AACjB,MAAM,IAAI,GAAG,IAAI,WAAW,EAAE,CAAC;AAwC/B,yFAAyF;AACzF,SAAS,eAAe,CAAC,IAAY,EAAE,KAAa;IAClD,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC5B,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC7B,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC;IACpD,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACd,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC;IACpB,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACzB,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,MAAM,CAAC,IAAyB;IACvC,OAAO,eAAe,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;AAChD,CA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signatures, BLS12-381-SHA-256) for PCA.
3
+ *
4
+ * Two layers:
5
+ * - the BBS core ({@link ./bbs}): KeyGen, create_generators, messages_to_scalars, Sign, Verify,
6
+ * ProofGen, ProofVerify — faithful to the CFRG draft, verified against its test vector;
7
+ * - the PCA layer ({@link ./credential}): a {@link Capability} issued as a multi-message BBS
8
+ * credential, then presented with selective disclosure + an unlinkable proof of knowledge.
9
+ */
10
+ export * from './bbs';
11
+ export * from './credential';
package/dist/index.js ADDED
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /**
18
+ * @atlasauth/pca-bbs — BBS signatures (draft-irtf-cfrg-bbs-signatures, BLS12-381-SHA-256) for PCA.
19
+ *
20
+ * Two layers:
21
+ * - the BBS core ({@link ./bbs}): KeyGen, create_generators, messages_to_scalars, Sign, Verify,
22
+ * ProofGen, ProofVerify — faithful to the CFRG draft, verified against its test vector;
23
+ * - the PCA layer ({@link ./credential}): a {@link Capability} issued as a multi-message BBS
24
+ * credential, then presented with selective disclosure + an unlinkable proof of knowledge.
25
+ */
26
+ __exportStar(require("./bbs"), exports);
27
+ __exportStar(require("./credential"), exports);
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;GAQG;AACH,wCAAsB;AACtB,+CAA6B"}
package/package.json CHANGED
@@ -1,6 +1,59 @@
1
1
  {
2
2
  "name": "@atlasauth/pca-bbs",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "description": "BBS signatures (CFRG draft) for PCA: issue a capability as a multi-message BBS credential, then present it with selective disclosure + unlinkable zero-knowledge proof-of-possession, so an agent reveals only the attributes a tool needs and uses can't be correlated.",
5
+ "keywords": [
6
+ "bbs signatures",
7
+ "selective disclosure",
8
+ "zero-knowledge",
9
+ "credentials",
10
+ "agent authorization",
11
+ "proof-carrying authority",
12
+ "pca",
13
+ "ai agents"
14
+ ],
15
+ "license": "MIT",
16
+ "homepage": "https://github.com/Atlas-Authorization/pca#readme",
17
+ "bugs": {
18
+ "url": "https://github.com/Atlas-Authorization/pca/issues"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/Atlas-Authorization/pca.git",
23
+ "directory": "packages/pca-bbs"
24
+ },
25
+ "main": "./dist/index.js",
26
+ "types": "./dist/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "default": "./dist/index.js"
31
+ },
32
+ "./package.json": "./package.json"
33
+ },
34
+ "dependencies": {
35
+ "@noble/curves": "^1.6.0",
36
+ "@noble/hashes": "^1.5.0",
37
+ "@atlasauth/pca": "0.2.0"
38
+ },
39
+ "devDependencies": {
40
+ "typescript": "^5.6.3",
41
+ "vitest": "^2.1.4"
42
+ },
43
+ "files": [
44
+ "dist",
45
+ "README.md",
46
+ "LICENSE"
47
+ ],
48
+ "engines": {
49
+ "node": ">=20"
50
+ },
51
+ "publishConfig": {
52
+ "access": "public"
53
+ },
54
+ "scripts": {
55
+ "build": "tsc -p tsconfig.build.json",
56
+ "typecheck": "tsc -p tsconfig.json --noEmit",
57
+ "test": "vitest run"
58
+ }
6
59
  }