@charter-agreement-protocol/signer 0.1.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,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,9 @@
1
+ Charter Agreement Signer
2
+ Copyright 2026 BaseLabs
3
+
4
+ This product includes software developed by BaseLabs
5
+ (https://github.com/baselabs).
6
+
7
+ This product depends on the charter_agreement_protocol package
8
+ (https://github.com/baselabs/charter_agreement_protocol), also licensed under
9
+ the Apache License, Version 2.0.
package/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # @charter-agreement-protocol/signer
2
+
3
+ Holder-side companion signer for the
4
+ [Charter Agreement Protocol](https://www.npmjs.com/package/@charter-agreement-protocol/verifier)
5
+ (CAP) — the TypeScript sibling of the Elixir
6
+ [charter_agreement_signer](https://hex.pm/packages/charter_agreement_signer).
7
+
8
+ **CAP verifies; it never authorizes. This signer signs; it never takes
9
+ custody.** You keep the key (HSM, OS keychain, key server) behind a handle
10
+ object with two callbacks; the signer resolves ONE atomic `keyIdentity`
11
+ snapshot, builds the exact RFC 7515 signing input, runs the honest-signer
12
+ refusal guards before any key is touched, checks the returned signature
13
+ against the snapshot's public key (the wrong-key guard), assembles the
14
+ compact, and post-sign-verifies the assembled artifact through the
15
+ `@charter-agreement-protocol/verifier` package — exactly one verification
16
+ implementation.
17
+
18
+ ## Install
19
+
20
+ ```console
21
+ npm install @charter-agreement-protocol/signer
22
+ ```
23
+
24
+ Requires Node >= 24.8 (ML-DSA support in the Node builtins).
25
+
26
+ ## Quickstart
27
+
28
+ ```js
29
+ import { signDescriptor } from "@charter-agreement-protocol/signer";
30
+
31
+ const handle = {
32
+ // ONE atomic snapshot — the kid and public key cannot disagree.
33
+ keyIdentity() {
34
+ return { kid: "my-key-001", publicKey }; // base64url raw public key
35
+ },
36
+ // The holder's job: sign the exact message bytes with the held key.
37
+ sign(message) {
38
+ return myHsm.sign(message); // Uint8Array signature
39
+ },
40
+ };
41
+
42
+ const result = await signDescriptor(
43
+ {
44
+ protocol_revision: 2,
45
+ descriptor_number: 1,
46
+ verification_keys: [
47
+ { key_id: "my-key-001", algorithm: "Ed25519", public_key: publicKey, status: "active" },
48
+ ],
49
+ attestation_hints: [],
50
+ extensions: { critical: {}, optional: {} },
51
+ effective_from: "2026-08-25T10:00:00Z",
52
+ },
53
+ handle,
54
+ );
55
+
56
+ // result.ok === true: { descriptor } is a CAP-verified compact JWS.
57
+ ```
58
+
59
+ For ML-DSA-65 artifacts pass `{ algorithm: "ML-DSA-65" }` as the options
60
+ argument with `protocol_revision: 3` claims (pure ML-DSA per RFC 9964, the
61
+ empty context — your handle signs the exact message bytes as with Ed25519).
62
+
63
+ ## API
64
+
65
+ | Export | What it does |
66
+ |---|---|
67
+ | `signDescriptor(claims, handle, opts?)` | Signs one Party Descriptor; post-verified via `verifyDescriptor` |
68
+ | `signReceipt(claims, handle, chain \| null, opts?)` | Signs one Receipt; post-verified via `verifyReceipt` when a chain view is supplied |
69
+ | `signAcceptance(claims, handle, view, opts?)` | Signs one Acceptance against the caller's verified view |
70
+ | `signTermination(claims, handle, view, opts?)` | Signs one Termination against the caller's verified view |
71
+
72
+ Errors are closed: `{ ok: false, error: "invalid_handle" \| "signing_failed"
73
+ \| "invalid_input" \| "refused", code? }`. A signing failure is never a
74
+ silent pass.
75
+
76
+ ## Evidence
77
+
78
+ - The Elixir reference repository's gate verifies TypeScript-signed
79
+ artifacts from raw bytes (cross-implementation agreement, enforced in CI).
80
+ - Post-sign verification goes through the
81
+ [@charter-agreement-protocol/verifier](https://www.npmjs.com/package/@charter-agreement-protocol/verifier)
82
+ package — the certified dual-implementation-verified verifier.
83
+
84
+ ## SemVer
85
+
86
+ Package SemVer decoupled from the protocol's `protocol_revision`; a package
87
+ major is owed only when a shipped public API is removed or changes
88
+ behavior.
89
+
90
+ ## License
91
+
92
+ Apache-2.0 — see [LICENSE](LICENSE) and [NOTICE](NOTICE).
@@ -0,0 +1 @@
1
+ export { signDescriptor, signReceipt, signAcceptance, signTermination, type KeyHandle, type KeySnapshot, type ChainView, type SignError, type SignResult, } from "./signer.ts";
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ // CAP never authorizes.
2
+ //
3
+ // Public surface of the holder-side companion signer: one signing function
4
+ // per artifact kind, the key-handle contract, and the closed error
5
+ // vocabulary. Verification of assembled artifacts goes through
6
+ // @charter-agreement-protocol/verifier — exactly one verification
7
+ // implementation.
8
+ export { signDescriptor, signReceipt, signAcceptance, signTermination, } from "./signer.js";
@@ -0,0 +1,59 @@
1
+ export type KeySnapshot = {
2
+ kid: string;
3
+ publicKey: string;
4
+ };
5
+ export type KeyHandle = {
6
+ keyIdentity(handle: unknown): KeySnapshot | Promise<KeySnapshot>;
7
+ sign(message: Uint8Array, handle: unknown): Uint8Array | Promise<Uint8Array>;
8
+ };
9
+ export type SignError = {
10
+ error: "invalid_handle";
11
+ } | {
12
+ error: "signing_failed";
13
+ } | {
14
+ error: "invalid_input";
15
+ code: string;
16
+ } | {
17
+ error: "refused";
18
+ code: string;
19
+ };
20
+ export type SignOk<T> = {
21
+ ok: true;
22
+ result: T;
23
+ };
24
+ export type SignResult<T> = SignOk<T> | {
25
+ ok: false;
26
+ } & SignError;
27
+ export type ChainView = {
28
+ revisions: string[];
29
+ acceptances: string[];
30
+ descriptors: string[];
31
+ terminations: string[];
32
+ };
33
+ export declare function signDescriptor(claims: Record<string, unknown>, keyHandle: unknown, opts?: {
34
+ algorithm?: string;
35
+ }): Promise<SignResult<{
36
+ descriptor: string;
37
+ }>>;
38
+ export declare function signReceipt(claims: Record<string, unknown>, keyHandle: unknown, chain: ChainView | null, opts?: {
39
+ algorithm?: string;
40
+ }): Promise<SignResult<{
41
+ receipt: string;
42
+ }>>;
43
+ export declare function signAcceptance(claims: Record<string, unknown>, keyHandle: unknown, view: {
44
+ revisionText: string;
45
+ descriptorCompacts: string[];
46
+ chain: ChainView;
47
+ }, opts?: {
48
+ algorithm?: string;
49
+ }): Promise<SignResult<{
50
+ acceptance: string;
51
+ }>>;
52
+ export declare function signTermination(claims: Record<string, unknown>, keyHandle: unknown, view: {
53
+ revisionText: string;
54
+ descriptorCompacts: string[];
55
+ }, opts?: {
56
+ algorithm?: string;
57
+ }): Promise<SignResult<{
58
+ termination: string;
59
+ }>>;
package/dist/signer.js ADDED
@@ -0,0 +1,176 @@
1
+ // CAP never authorizes.
2
+ //
3
+ // The holder-side companion signer for the Charter Agreement Protocol,
4
+ // ported from the Elixir reference (charter_agreement_signer). The caller
5
+ // owns key custody through a handle object with two callbacks:
6
+ //
7
+ // keyIdentity(handle) -> { kid, publicKey } // ONE atomic snapshot
8
+ // sign(message, handle) -> signature bytes // the holder's job
9
+ //
10
+ // The signer builds the exact RFC 7515 signing input through the verifier
11
+ // package's producers surface, runs the honest-signer refusal guards
12
+ // BEFORE any key is touched, checks the returned signature against the
13
+ // snapshot's public key (the wrong-key guard), assembles the compact, and
14
+ // post-sign-verifies the assembled artifact through the verifier package.
15
+ // It never verifies third-party artifacts, never transports, never
16
+ // persists, and never sees a private key.
17
+ import { algorithmRegistry, canonical, decodeArtifact, defaultEmissionName, emissions, encodeBase64url, verifyAcceptance, verifyDescriptor, verifyReceipt, verifySignature, verifyTermination, } from "@charter-agreement-protocol/verifier";
18
+ const TYPES = {
19
+ descriptor: "cap+party",
20
+ acceptance: "cap+acceptance",
21
+ termination: "cap+termination",
22
+ receipt: "cap+receipt",
23
+ };
24
+ const MAX_INPUT_BYTES = 1_048_576;
25
+ function registryRow(algorithm) {
26
+ return algorithmRegistry().find((row) => row.name === algorithm) ?? null;
27
+ }
28
+ async function resolveKeyIdentity(handle) {
29
+ if (handle === null || typeof handle !== "object" || !("keyIdentity" in handle)) {
30
+ return { error: "invalid_handle" };
31
+ }
32
+ try {
33
+ const snapshot = await handle.keyIdentity(handle);
34
+ if (snapshot &&
35
+ typeof snapshot.kid === "string" &&
36
+ snapshot.kid.length > 0 &&
37
+ typeof snapshot.publicKey === "string" &&
38
+ Buffer.from(snapshot.publicKey, "base64url").length > 0) {
39
+ return snapshot;
40
+ }
41
+ return { error: "invalid_handle" };
42
+ }
43
+ catch (_fault) {
44
+ return { error: "invalid_handle" };
45
+ }
46
+ }
47
+ function resolveAlgorithm(selection) {
48
+ if (selection === undefined || selection === null)
49
+ return defaultEmissionName();
50
+ if (typeof selection === "string" && selection in emissions())
51
+ return selection;
52
+ return { error: "invalid_input", code: "algorithm_unsupported" };
53
+ }
54
+ function claimsRevision(claims) {
55
+ const value = claims.protocol_revision;
56
+ return typeof value === "number" && Number.isInteger(value) ? value : null;
57
+ }
58
+ // The producer core: canonical claims, the closed protected header with the
59
+ // selected emission name and the SNAPSHOT kid, the size guard, and the
60
+ // provisional framing check over a zero signature — CAP's producer contract.
61
+ function frameSigningInput(kind, claims, kid, algorithm) {
62
+ if (!claims || typeof claims !== "object" || Array.isArray(claims)) {
63
+ return { error: "invalid_input", code: "invalid_type" };
64
+ }
65
+ if (claimsRevision(claims) !== emissions()[algorithm]) {
66
+ return { error: "invalid_input", code: "signing_input_invalid" };
67
+ }
68
+ if (typeof kid !== "string" || kid.length === 0 || kid.length > 128 || !/^[A-Za-z0-9._~-]+$/.test(kid)) {
69
+ return { error: "invalid_input", code: "signing_input_invalid" };
70
+ }
71
+ const row = registryRow(algorithm);
72
+ if (!row)
73
+ return { error: "invalid_input", code: "algorithm_unsupported" };
74
+ const payloadBytes = Buffer.from(canonical(claims), "utf8");
75
+ const protectedBytes = Buffer.from(canonical({ alg: algorithm, kid, typ: TYPES[kind] }), "utf8");
76
+ const protectedSegment = encodeBase64url(protectedBytes);
77
+ const payloadSegment = encodeBase64url(payloadBytes);
78
+ const message = Buffer.from(`${protectedSegment}.${payloadSegment}`, "utf8");
79
+ const signatureSegmentLength = Math.ceil((row.signatureBytes * 4) / 3);
80
+ if (message.length + 1 + signatureSegmentLength > MAX_INPUT_BYTES) {
81
+ return { error: "invalid_input", code: "signing_input_invalid" };
82
+ }
83
+ // The provisional check: a zero signature of the row's exact length must
84
+ // frame and bind (canonical bytes, registry binding, per-row length).
85
+ const zeroSignature = Buffer.alloc(row.signatureBytes);
86
+ const provisional = `${protectedSegment}.${payloadSegment}.${encodeBase64url(zeroSignature)}`;
87
+ const decoded = decodeArtifact(provisional);
88
+ if (!decoded.ok)
89
+ return { error: "invalid_input", code: "signing_input_invalid" };
90
+ return { protectedSegment, payloadSegment, message };
91
+ }
92
+ async function signCommon(kind, claims, keyHandle, opts) {
93
+ const snapshot = await resolveKeyIdentity(keyHandle);
94
+ if ("error" in snapshot)
95
+ return snapshot;
96
+ const algorithm = resolveAlgorithm(opts?.algorithm);
97
+ if (typeof algorithm !== "string" && "error" in algorithm)
98
+ return algorithm;
99
+ const framed = frameSigningInput(kind, claims, snapshot.kid, algorithm);
100
+ if ("error" in framed)
101
+ return framed;
102
+ // The holder signs the exact message; a fault or a wrong-length result is
103
+ // a signing failure, never a silent pass.
104
+ let signature;
105
+ try {
106
+ signature = await keyHandle.sign(framed.message, keyHandle);
107
+ }
108
+ catch (_fault) {
109
+ return { error: "signing_failed" };
110
+ }
111
+ if (!(signature instanceof Uint8Array) || signature.length === 0) {
112
+ return { error: "signing_failed" };
113
+ }
114
+ const row = registryRow(algorithm);
115
+ if (!row || signature.length !== row.signatureBytes) {
116
+ return { error: "signing_failed" };
117
+ }
118
+ // The wrong-key guard: the signature MUST verify against the snapshot's
119
+ // public key under the selected algorithm.
120
+ if (!verifySignature(framed.message, Buffer.from(signature), snapshot.publicKey, algorithm)) {
121
+ return { error: "signing_failed" };
122
+ }
123
+ return { message: framed.message, signature: Buffer.from(signature) };
124
+ }
125
+ function assemble(message, signature) {
126
+ return `${message.toString("utf8")}.${encodeBase64url(signature)}`;
127
+ }
128
+ // ---------------------------------------------------------------------------
129
+ // Honest-signer refusal guards (R1–R3 from the Elixir reference): they run
130
+ // against the caller's own verified view BEFORE any key is touched.
131
+ // ---------------------------------------------------------------------------
132
+ // ---------------------------------------------------------------------------
133
+ // Public signing surface
134
+ // ---------------------------------------------------------------------------
135
+ export async function signDescriptor(claims, keyHandle, opts = {}) {
136
+ const signed = await signCommon("descriptor", claims, keyHandle, opts);
137
+ if ("error" in signed)
138
+ return { ok: false, ...signed };
139
+ const compact = assemble(signed.message, signed.signature);
140
+ const verified = verifyDescriptor(compact);
141
+ if (!verified.ok)
142
+ return { ok: false, error: "invalid_input", code: verified.code };
143
+ return { ok: true, result: { descriptor: compact } };
144
+ }
145
+ export async function signReceipt(claims, keyHandle, chain, opts = {}) {
146
+ const signed = await signCommon("receipt", claims, keyHandle, opts);
147
+ if ("error" in signed)
148
+ return { ok: false, ...signed };
149
+ const compact = assemble(signed.message, signed.signature);
150
+ if (chain) {
151
+ const verified = verifyReceipt(compact, chain);
152
+ if (!verified.ok)
153
+ return { ok: false, error: "invalid_input", code: verified.code };
154
+ }
155
+ return { ok: true, result: { receipt: compact } };
156
+ }
157
+ export async function signAcceptance(claims, keyHandle, view, opts = {}) {
158
+ const signed = await signCommon("acceptance", claims, keyHandle, opts);
159
+ if ("error" in signed)
160
+ return { ok: false, ...signed };
161
+ const compact = assemble(signed.message, signed.signature);
162
+ const verified = verifyAcceptance(compact, view.revisionText, view.descriptorCompacts);
163
+ if (!verified.ok)
164
+ return { ok: false, error: "invalid_input", code: verified.code };
165
+ return { ok: true, result: { acceptance: compact } };
166
+ }
167
+ export async function signTermination(claims, keyHandle, view, opts = {}) {
168
+ const signed = await signCommon("termination", claims, keyHandle, opts);
169
+ if ("error" in signed)
170
+ return { ok: false, ...signed };
171
+ const compact = assemble(signed.message, signed.signature);
172
+ const verified = verifyTermination(compact, view.revisionText, view.descriptorCompacts);
173
+ if (!verified.ok)
174
+ return { ok: false, error: "invalid_input", code: verified.code };
175
+ return { ok: true, result: { termination: compact } };
176
+ }
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@charter-agreement-protocol/signer",
3
+ "version": "0.1.0",
4
+ "description": "Holder-side companion signer for the Charter Agreement Protocol (CAP) in TypeScript — atomic key snapshots, honest-signer refusals, external-signature assembly, and post-sign verification through the @charter-agreement-protocol/verifier. CAP verifies; it never authorizes; this signer signs, it never verifies third-party artifacts or takes custody.",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "./package.json": "./package.json"
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "LICENSE",
19
+ "NOTICE",
20
+ "README.md"
21
+ ],
22
+ "engines": {
23
+ "node": ">=24.8.0"
24
+ },
25
+ "scripts": {
26
+ "build": "tsc -p tsconfig.build.json",
27
+ "typecheck": "tsc --noEmit",
28
+ "test": "node --test --experimental-strip-types --no-warnings signer.test.ts",
29
+ "prepack": "npm run build"
30
+ },
31
+ "dependencies": {
32
+ "@charter-agreement-protocol/verifier": "^0.2.0"
33
+ },
34
+ "devDependencies": {
35
+ "@types/node": "^26.5.1",
36
+ "typescript": "~5.9.0"
37
+ },
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "git+https://github.com/baselabs/charter_agreement_signer_typescript.git"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public"
44
+ }
45
+ }