@paybond/kit 0.1.0 → 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,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 reasonable and customary use in describing the
141
+ origin of the Work and 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 of
171
+ 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/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # `@paybond/kit`
2
2
 
3
- Paybond Kit for TypeScript provides a tenant-bound Harbor client, gateway-backed service-account sessions, capability verification, canonical signing helpers for intent creation and evidence submission, and tenant-scoped ledger provenance reads.
4
-
5
- It does **not** currently expose a first-class Signal client or Signal analytics/reputation API surface. Signal remains a separate platform surface today.
3
+ Paybond Kit for TypeScript provides a tenant-bound Harbor client, gateway-backed service-account sessions, capability verification, canonical signing helpers for intent creation and evidence submission, tenant-scoped ledger provenance reads, and tenant-scoped Signal analytics and reputation reads.
6
4
 
7
5
  Install the public package with:
8
6
 
@@ -10,15 +8,19 @@ Install the public package with:
10
8
  npm install @paybond/kit
11
9
  ```
12
10
 
11
+ ## Open source
12
+
13
+ `@paybond/kit` is distributed as open-source software under the Apache 2.0 license. The published npm package includes the full license text in `LICENSE`.
14
+
13
15
  ## Requirements
14
16
 
15
- - Node.js 20+
17
+ - Node.js 22+
16
18
  - A `paybond_sk_...` service-account API key
17
19
  - Reachable Gateway and Harbor base URLs
18
20
 
19
21
  ## Tenant isolation
20
22
 
21
- Every session is bound to the tenant realm echoed by the gateway `POST /v1/auth/harbor-access` exchange.
23
+ Every session is bound to the tenant realm echoed by gateway-authenticated service-account introspection and Harbor access exchange flows.
22
24
 
23
25
  - Do not pass tenant ids by hand for normal SDK usage.
24
26
  - Construct one `Paybond` session per tenant/service account.
@@ -55,6 +57,8 @@ try {
55
57
 
56
58
  - `Paybond.open(...)` for gateway-authenticated, tenant-derived Harbor sessions
57
59
  - `HarborClient` for capability verification, intent creation, evidence submission, and ledger reads
60
+ - `GatewaySignalClient` and `ServiceAccountSignalSession` for tenant-scoped Signal reads
61
+ - `paybond.signal` on `Paybond` sessions opened from one service-account API key
58
62
  - `PaybondIntents` helpers for principal-signed intent creation and payee-signed evidence submission
59
63
  - Low-level signing helpers exported for advanced callers
60
64
 
@@ -62,8 +66,6 @@ try {
62
66
 
63
67
  ## What it does not include
64
68
 
65
- - No first-class `SignalClient`
66
- - No Signal reputation or analytics fetch API
67
69
  - No operator-tier settlement or console workflows
68
70
 
69
71
  ## Docs
package/dist/index.d.ts CHANGED
@@ -44,6 +44,19 @@ export declare class GatewayAuthError extends Error {
44
44
  bodyText?: string;
45
45
  });
46
46
  }
47
+ /**
48
+ * Structured HTTP failure from gateway Signal read routes.
49
+ */
50
+ export declare class SignalHttpError extends Error {
51
+ readonly statusCode: number;
52
+ readonly url: string;
53
+ readonly bodyText: string;
54
+ constructor(message: string, init: {
55
+ statusCode: number;
56
+ url: string;
57
+ bodyText: string;
58
+ });
59
+ }
47
60
  /**
48
61
  * Exchanges a `paybond_sk_` API key for short-lived Harbor JWTs and caches tenant realm from the
49
62
  * gateway response (no separate tenant env var for the default path).
@@ -191,6 +204,42 @@ export declare class HarborClient {
191
204
  */
192
205
  getLedgerMerkleLatest(): Promise<Record<string, unknown>>;
193
206
  }
207
+ type GatewaySignalClientOptions = {
208
+ staticGatewayBearerToken: string;
209
+ maxRetries?: number;
210
+ };
211
+ /**
212
+ * Tenant-bound reader for gateway Signal routes.
213
+ */
214
+ export declare class GatewaySignalClient {
215
+ private readonly base;
216
+ readonly tenantId: string;
217
+ private readonly bearerToken;
218
+ private readonly maxRetries;
219
+ constructor(gatewayBaseUrl: string, tenantId: string, options: GatewaySignalClientOptions);
220
+ private fetchGetWithRetries;
221
+ private assertTenant;
222
+ private scoreQuery;
223
+ getReputationReceipt(operatorDid: string, scoreVersion?: string): Promise<Record<string, unknown> | null>;
224
+ getPortfolioSummary(scoreVersion?: string): Promise<Record<string, unknown>>;
225
+ getOperatorExplanation(operatorDid: string, scoreVersion?: string): Promise<Record<string, unknown> | null>;
226
+ getOperatorReviewStatus(operatorDid: string, scoreVersion?: string): Promise<Record<string, unknown> | null>;
227
+ }
228
+ export type ServiceAccountSignalSessionInit = {
229
+ gatewayBaseUrl: string;
230
+ apiKey: string;
231
+ principalPath?: string;
232
+ maxRetries?: number;
233
+ };
234
+ /**
235
+ * Read-only tenant-bound Signal session for one service-account API key.
236
+ */
237
+ export declare class ServiceAccountSignalSession {
238
+ readonly signal: GatewaySignalClient;
239
+ private constructor();
240
+ static open(init: ServiceAccountSignalSessionInit): Promise<ServiceAccountSignalSession>;
241
+ aclose(): Promise<void>;
242
+ }
194
243
  /** Parameters for {@link PaybondIntents.create} (tenant is taken from the bound Harbor client). */
195
244
  export type PaybondCreateIntentParams = Omit<BuildSignedCreateIntentParams, "tenantId" | "intentId"> & {
196
245
  intentId?: string;
@@ -221,6 +270,7 @@ export declare class PaybondIntents {
221
270
  */
222
271
  export declare class Paybond {
223
272
  readonly harbor: HarborClient;
273
+ readonly signal: GatewaySignalClient;
224
274
  readonly intents: PaybondIntents;
225
275
  private readonly session;
226
276
  private constructor();
package/dist/index.js CHANGED
@@ -32,6 +32,21 @@ export class GatewayAuthError extends Error {
32
32
  this.bodyText = init?.bodyText;
33
33
  }
34
34
  }
35
+ /**
36
+ * Structured HTTP failure from gateway Signal read routes.
37
+ */
38
+ export class SignalHttpError extends Error {
39
+ statusCode;
40
+ url;
41
+ bodyText;
42
+ constructor(message, init) {
43
+ super(message);
44
+ this.name = "SignalHttpError";
45
+ this.statusCode = init.statusCode;
46
+ this.url = init.url;
47
+ this.bodyText = init.bodyText;
48
+ }
49
+ }
35
50
  function normalizeBase(url) {
36
51
  return url.trim().replace(/\/+$/, "");
37
52
  }
@@ -507,6 +522,226 @@ export class HarborClient {
507
522
  return body;
508
523
  }
509
524
  }
525
+ const DEFAULT_PRINCIPAL_PATH = "/v1/auth/principal";
526
+ function assertJSONObject(value) {
527
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
528
+ throw new Error("expected JSON object");
529
+ }
530
+ return value;
531
+ }
532
+ /**
533
+ * Tenant-bound reader for gateway Signal routes.
534
+ */
535
+ export class GatewaySignalClient {
536
+ base;
537
+ tenantId;
538
+ bearerToken;
539
+ maxRetries;
540
+ constructor(gatewayBaseUrl, tenantId, options) {
541
+ this.base = normalizeBase(gatewayBaseUrl) + "/";
542
+ this.tenantId = tenantId.trim();
543
+ this.bearerToken = options.staticGatewayBearerToken.trim();
544
+ this.maxRetries = Math.max(1, options.maxRetries ?? 3);
545
+ }
546
+ async fetchGetWithRetries(url) {
547
+ let lastErr;
548
+ for (let attempt = 0; attempt < this.maxRetries; attempt++) {
549
+ let res;
550
+ try {
551
+ res = await fetch(url, {
552
+ method: "GET",
553
+ headers: {
554
+ accept: "application/json",
555
+ authorization: `Bearer ${this.bearerToken}`,
556
+ },
557
+ });
558
+ }
559
+ catch (e) {
560
+ lastErr = e;
561
+ if (attempt + 1 >= this.maxRetries)
562
+ throw e;
563
+ await new Promise((r) => setTimeout(r, backoffMs(attempt)));
564
+ continue;
565
+ }
566
+ if ([429, 500, 502, 503, 504].includes(res.status)) {
567
+ if (attempt + 1 >= this.maxRetries) {
568
+ return res;
569
+ }
570
+ const raSec = parseRetryAfterSeconds(res.headers.get("retry-after"));
571
+ const delayMs = raSec != null ? raSec * 1000 : backoffMs(attempt);
572
+ await new Promise((r) => setTimeout(r, delayMs));
573
+ continue;
574
+ }
575
+ return res;
576
+ }
577
+ throw lastErr instanceof Error ? lastErr : new Error(String(lastErr));
578
+ }
579
+ assertTenant(body, url) {
580
+ const tid = String(body.tenant_id ?? "");
581
+ if (tid !== this.tenantId) {
582
+ throw new Error(`signal tenant mismatch: client=${this.tenantId} gateway=${tid} url=${url}`);
583
+ }
584
+ }
585
+ scoreQuery(scoreVersion) {
586
+ if (!scoreVersion || !scoreVersion.trim()) {
587
+ return "";
588
+ }
589
+ return `?score_version=${encodeURIComponent(scoreVersion.trim())}`;
590
+ }
591
+ async getReputationReceipt(operatorDid, scoreVersion) {
592
+ const enc = encodeURIComponent(operatorDid);
593
+ const url = `${this.base}reputation/${enc}${this.scoreQuery(scoreVersion)}`;
594
+ const res = await this.fetchGetWithRetries(url);
595
+ const text = await res.text();
596
+ if (res.status === 404) {
597
+ return null;
598
+ }
599
+ if (!res.ok) {
600
+ throw new SignalHttpError(`Signal receipt HTTP ${res.status}: ${text}`, {
601
+ statusCode: res.status,
602
+ url,
603
+ bodyText: text,
604
+ });
605
+ }
606
+ const body = assertJSONObject(JSON.parse(text));
607
+ const receipt = assertJSONObject(body.receipt);
608
+ const tenant = String(receipt.tenant_id ?? "");
609
+ const echoedOperator = String(receipt.operator_did ?? "");
610
+ if (tenant !== this.tenantId) {
611
+ throw new Error(`signal receipt tenant mismatch: client=${this.tenantId} gateway=${tenant}`);
612
+ }
613
+ if (echoedOperator !== operatorDid) {
614
+ throw new Error(`signal receipt operator mismatch: requested=${operatorDid} gateway=${echoedOperator}`);
615
+ }
616
+ return body;
617
+ }
618
+ async getPortfolioSummary(scoreVersion) {
619
+ const url = `${this.base}signal/v1/portfolio/summary${this.scoreQuery(scoreVersion)}`;
620
+ const res = await this.fetchGetWithRetries(url);
621
+ const text = await res.text();
622
+ if (!res.ok) {
623
+ throw new SignalHttpError(`Signal portfolio summary HTTP ${res.status}: ${text}`, {
624
+ statusCode: res.status,
625
+ url,
626
+ bodyText: text,
627
+ });
628
+ }
629
+ const body = assertJSONObject(JSON.parse(text));
630
+ this.assertTenant(body, url);
631
+ return body;
632
+ }
633
+ async getOperatorExplanation(operatorDid, scoreVersion) {
634
+ const enc = encodeURIComponent(operatorDid);
635
+ const url = `${this.base}signal/v1/operators/${enc}/explanation${this.scoreQuery(scoreVersion)}`;
636
+ const res = await this.fetchGetWithRetries(url);
637
+ const text = await res.text();
638
+ if (res.status === 404) {
639
+ return null;
640
+ }
641
+ if (!res.ok) {
642
+ throw new SignalHttpError(`Signal explanation HTTP ${res.status}: ${text}`, {
643
+ statusCode: res.status,
644
+ url,
645
+ bodyText: text,
646
+ });
647
+ }
648
+ const body = assertJSONObject(JSON.parse(text));
649
+ this.assertTenant(body, url);
650
+ if (String(body.operator_did ?? "") !== operatorDid) {
651
+ throw new Error(`signal explanation operator mismatch: requested=${operatorDid} gateway=${String(body.operator_did ?? "")}`);
652
+ }
653
+ return body;
654
+ }
655
+ async getOperatorReviewStatus(operatorDid, scoreVersion) {
656
+ const enc = encodeURIComponent(operatorDid);
657
+ const url = `${this.base}signal/v1/operators/${enc}/review-status${this.scoreQuery(scoreVersion)}`;
658
+ const res = await this.fetchGetWithRetries(url);
659
+ const text = await res.text();
660
+ if (res.status === 404) {
661
+ return null;
662
+ }
663
+ if (!res.ok) {
664
+ throw new SignalHttpError(`Signal review status HTTP ${res.status}: ${text}`, {
665
+ statusCode: res.status,
666
+ url,
667
+ bodyText: text,
668
+ });
669
+ }
670
+ const body = assertJSONObject(JSON.parse(text));
671
+ this.assertTenant(body, url);
672
+ if (String(body.operator_did ?? "") !== operatorDid) {
673
+ throw new Error(`signal review operator mismatch: requested=${operatorDid} gateway=${String(body.operator_did ?? "")}`);
674
+ }
675
+ return body;
676
+ }
677
+ }
678
+ async function resolveGatewayTenantId(gatewayBaseUrl, apiKey, principalPath, maxRetries) {
679
+ const base = normalizeBase(gatewayBaseUrl);
680
+ const path = principalPath.startsWith("/") ? principalPath : `/${principalPath}`;
681
+ const url = `${base}${path}`;
682
+ let lastErr;
683
+ for (let attempt = 0; attempt < maxRetries; attempt++) {
684
+ let res;
685
+ try {
686
+ res = await fetch(url, {
687
+ method: "GET",
688
+ headers: {
689
+ accept: "application/json",
690
+ authorization: `Bearer ${apiKey.trim()}`,
691
+ },
692
+ });
693
+ }
694
+ catch (e) {
695
+ lastErr = e;
696
+ if (attempt + 1 >= maxRetries) {
697
+ throw e;
698
+ }
699
+ await new Promise((r) => setTimeout(r, backoffMs(attempt)));
700
+ continue;
701
+ }
702
+ const text = await res.text();
703
+ if (!res.ok) {
704
+ if ([429, 500, 502, 503, 504].includes(res.status) && attempt + 1 < maxRetries) {
705
+ const raSec = parseRetryAfterSeconds(res.headers.get("retry-after"));
706
+ const delayMs = raSec != null ? raSec * 1000 : backoffMs(attempt);
707
+ await new Promise((r) => setTimeout(r, delayMs));
708
+ continue;
709
+ }
710
+ throw new GatewayAuthError(`gateway principal HTTP ${res.status}`, {
711
+ statusCode: res.status,
712
+ bodyText: text,
713
+ });
714
+ }
715
+ const body = assertJSONObject(JSON.parse(text));
716
+ const tenant = String(body.tenant_id ?? "").trim();
717
+ if (!tenant) {
718
+ throw new GatewayAuthError("gateway principal JSON missing tenant_id", {
719
+ bodyText: text,
720
+ });
721
+ }
722
+ return tenant;
723
+ }
724
+ throw lastErr instanceof Error ? lastErr : new Error(String(lastErr));
725
+ }
726
+ /**
727
+ * Read-only tenant-bound Signal session for one service-account API key.
728
+ */
729
+ export class ServiceAccountSignalSession {
730
+ signal;
731
+ constructor(signal) {
732
+ this.signal = signal;
733
+ }
734
+ static async open(init) {
735
+ const tenantId = await resolveGatewayTenantId(init.gatewayBaseUrl, init.apiKey, init.principalPath ?? DEFAULT_PRINCIPAL_PATH, Math.max(1, init.maxRetries ?? 3));
736
+ return new ServiceAccountSignalSession(new GatewaySignalClient(init.gatewayBaseUrl, tenantId, {
737
+ staticGatewayBearerToken: init.apiKey,
738
+ maxRetries: init.maxRetries ?? 3,
739
+ }));
740
+ }
741
+ async aclose() {
742
+ await Promise.resolve();
743
+ }
744
+ }
510
745
  /**
511
746
  * Ergonomic intent helpers: principal-signed intent create and payee-signed evidence.
512
747
  */
@@ -545,17 +780,23 @@ export class PaybondIntents {
545
780
  */
546
781
  export class Paybond {
547
782
  harbor;
783
+ signal;
548
784
  intents;
549
785
  session;
550
- constructor(session) {
786
+ constructor(session, signal) {
551
787
  this.session = session;
552
788
  this.harbor = session.harbor;
789
+ this.signal = signal;
553
790
  this.intents = new PaybondIntents(session.harbor);
554
791
  }
555
792
  /** Open a tenant-bound session via gateway `harbor-access` exchange. */
556
793
  static async open(init) {
557
794
  const session = await ServiceAccountHarborSession.open(init);
558
- return new Paybond(session);
795
+ const signal = new GatewaySignalClient(init.gatewayBaseUrl, session.harbor.tenantId, {
796
+ staticGatewayBearerToken: init.apiKey,
797
+ maxRetries: init.maxRetries ?? 3,
798
+ });
799
+ return new Paybond(session, signal);
559
800
  }
560
801
  async rotateHarborToken() {
561
802
  await this.session.rotateHarborToken();
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@paybond/kit",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Paybond Kit for TypeScript: tenant-bound Harbor sessions, capability verification, and signed intent/evidence flows.",
5
- "license": "(MIT OR Apache-2.0)",
5
+ "license": "Apache-2.0",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
8
8
  "types": "dist/index.d.ts",
@@ -14,19 +14,19 @@
14
14
  },
15
15
  "files": [
16
16
  "dist",
17
- "README.md"
17
+ "README.md",
18
+ "LICENSE"
18
19
  ],
19
20
  "engines": {
20
- "node": ">=20"
21
+ "node": ">=22"
21
22
  },
22
23
  "repository": {
23
24
  "type": "git",
24
- "url": "https://github.com/nonameuserd/pacta.git",
25
- "directory": "kit/ts"
25
+ "url": "git+https://github.com/nonameuserd/paybond-kit.git"
26
26
  },
27
- "homepage": "https://github.com/nonameuserd/pacta/tree/main/kit/ts",
27
+ "homepage": "https://github.com/nonameuserd/paybond-kit",
28
28
  "bugs": {
29
- "url": "https://github.com/nonameuserd/pacta/issues"
29
+ "url": "https://github.com/nonameuserd/paybond-kit/issues"
30
30
  },
31
31
  "keywords": [
32
32
  "paybond",