@skeinlabs/sdk 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,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
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/README.md CHANGED
@@ -1,3 +1,122 @@
1
- # Temporary Holding Version
1
+ # @skeinlabs/sdk
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
+ TypeScript client for [Skein](https://skeinlabs.site): one call returns a
4
+ listing verdict for an EVM token (**APPROVE**, **REJECT**, **ESCALATE** or
5
+ **ABSTAIN**), with reasons, open risks, cost and a hash anyone can recompute.
6
+
7
+ - `verdict()`, `quote()`, `verify()`, `stream()`, `bom()`, `submit()` / `wait()`
8
+ - typed errors (`SkeinError`, `SpendCapError`) carrying the API's codes
9
+ - retries that reuse the idempotency key, so a retried call is never charged twice
10
+ - a per-call spend cap, checked **before** any payment
11
+ - two ways to pay: a Skein partner key, or per call through Telegraph escrow
12
+ - every verdict signed by Skein, checkable offline with `@skeinlabs/sdk/attest`
13
+ - no runtime dependencies (the Telegraph and attest entries need `viem`)
14
+
15
+ **[Read the full tutorial →](https://skeinlabs.site/tutorial)**
16
+
17
+ ## Install
18
+
19
+ ```sh
20
+ npm install @skeinlabs/sdk
21
+ # for the Telegraph rail, also:
22
+ npm install viem
23
+ ```
24
+
25
+ Node 20 or later, or any runtime with `fetch` (Bun, Deno, edge workers, browsers).
26
+
27
+ ## Quote (free, no key)
28
+
29
+ ```ts
30
+ import { Skein } from "@skeinlabs/sdk";
31
+
32
+ const skein = new Skein({ apiUrl: "https://api.skeinlabs.site" });
33
+ const q = await skein.quote({ subject: { chainId: 8453, token: "0x4200000000000000000000000000000000000006" } });
34
+ console.log(q.priceUsdc, q.checks?.map((c) => c.check));
35
+ ```
36
+
37
+ ## Verdict (partner key)
38
+
39
+ ```ts
40
+ import { Skein, SkeinError, SpendCapError } from "@skeinlabs/sdk";
41
+
42
+ const skein = new Skein({
43
+ apiUrl: "https://api.skeinlabs.site",
44
+ payer: { kind: "apiKey", key: process.env.SKEIN_API_KEY! },
45
+ maxUsdcPerCall: 0.3, // refused before paying above this
46
+ });
47
+
48
+ try {
49
+ const v = await skein.verdict({
50
+ subject: { chainId: 8453, token: "0x…" },
51
+ policy: "dex-list@0.2.0",
52
+ context: { socialHandle: "project_handle", repoUrl: "https://github.com/org/repo" }, // optional: buys bot and code checks
53
+ onEvent: (e) => console.log(e.type), // plan, purchase, finding, decision, done
54
+ });
55
+ if (v.verdict !== "APPROVE") console.log("needs a human:", v.reasons.map((r) => r.detail));
56
+ const report = await skein.verify(v.id); // recompute it from the raw paid answers
57
+ console.log(report.ok ? "verified" : report.problems);
58
+ } catch (e) {
59
+ if (e instanceof SpendCapError) console.log(`quoted ${e.priceUsdc} USDC, cap ${e.capUsdc}`);
60
+ else if (e instanceof SkeinError) console.log(e.code, e.message);
61
+ else throw e;
62
+ }
63
+ ```
64
+
65
+ ## Verdict (pay per call through Telegraph)
66
+
67
+ No Skein account: each verdict is one paid Telegraph ask, settled from your
68
+ own escrow on the Telegraph network.
69
+
70
+ ```ts
71
+ import { Skein } from "@skeinlabs/sdk";
72
+ import { TelegraphClient, TESTNET, viemSigner } from "@skeinlabs/sdk/telegraph";
73
+
74
+ const client = new TelegraphClient({
75
+ network: TESTNET, // Sepolia escrow
76
+ signer: viemSigner(process.env.PAYER_KEY as `0x${string}`), // a burner, never a treasury key
77
+ maxUusdcPerCall: 300_000, // 0.30 USDC: no 402 challenge is signed above this
78
+ });
79
+ const skein = new Skein({ apiUrl: "https://api.skeinlabs.site", payer: { kind: "telegraph", client } });
80
+ const v = await skein.verdict({ subject: { chainId: 1, token: "0x…" } });
81
+ console.log(v.verdict, v.payment); // { rail: "telegraph", minerId, amountUsdc, receiptHash, signalHash }
82
+ ```
83
+
84
+ ## Check Skein's signature yourself
85
+
86
+ Every verdict is signed by Skein (EIP-191) over its id, subject, outcome,
87
+ policy, verdict hash, receipts root and cost. The signer's address is published
88
+ at `https://api.skeinlabs.site/v1/status` (`attester`). The check rebuilds the
89
+ message from the verdict's own fields, so an edited verdict fails even with the
90
+ original signature attached:
91
+
92
+ ```ts
93
+ import { verifyAttestation } from "@skeinlabs/sdk/attest"; // needs viem
94
+
95
+ const { attester } = await (await fetch("https://api.skeinlabs.site/v1/status")).json();
96
+ const check = await verifyAttestation(v, { signer: attester });
97
+ if (!check.ok) throw new Error(check.problems.join("; "));
98
+ ```
99
+
100
+ Pin the attester address in your own config rather than fetching it on every call.
101
+
102
+ ## API
103
+
104
+ | Method | Cost | What it does |
105
+ |---|---|---|
106
+ | `quote({ subject, policy? })` | free | What a verdict would buy and cost, or why it would be refused |
107
+ | `verdict(req)` | paid | Buys one verdict and resolves once it is sealed |
108
+ | `submit(req)` / `wait(id)` | paid | The same in two steps, for queues and long-running jobs |
109
+ | `get(id)` | free | A stored verdict, or `{ status: "running" }` |
110
+ | `stream(id)` | free | The verdict's live events as an async iterator |
111
+ | `bom(id)` | free | The bill of materials: every paid input and its receipt |
112
+ | `verify(id)` | free | Recomputes the verdict hash and the receipts' Merkle root |
113
+
114
+ Options: `apiUrl`, `payer`, `maxUsdcPerCall`, `retries` (2), `maxRetryWaitMs`
115
+ (10 s), `requestTimeoutMs` (15 s), `timeoutMs` (120 s), `fetch`.
116
+
117
+ Verdicts are risk evidence, not investment advice. Treat anything but
118
+ `APPROVE` as "do not proceed without a human".
119
+
120
+ ## License
121
+
122
+ Apache-2.0
@@ -0,0 +1,51 @@
1
+ import { A as Attestation } from './types-B_RIoOCq.js';
2
+
3
+ /**
4
+ * The message Skein signs for every verdict (EIP-191 personal_sign, the same
5
+ * scheme Telegraph uses for escrow payments). It names everything a reader
6
+ * relies on (the subject, the outcome, the policy and engine, the verdict hash
7
+ * and the receipts' Merkle root, the cost) in plain lines, so a signature can
8
+ * travel with a listing memo or a payment and be checked by anyone who knows
9
+ * Skein's published attester address. Nothing secret, no dependencies: the API
10
+ * signs it and @skeinlabs/sdk/attest rebuilds it to verify.
11
+ */
12
+ interface AttestedVerdict {
13
+ id: string;
14
+ subject: {
15
+ chainId: number;
16
+ token: string;
17
+ };
18
+ verdict: string;
19
+ riskBps: number;
20
+ confidenceBps: number;
21
+ policy: {
22
+ id: string;
23
+ version: string;
24
+ };
25
+ engineVersion: string;
26
+ verdictHash: string;
27
+ bom: {
28
+ root: string;
29
+ };
30
+ cost: {
31
+ priceUsdc: number;
32
+ upstreamUsdc: number;
33
+ };
34
+ network: string;
35
+ createdAt: string;
36
+ }
37
+ declare function attestationMessage(v: AttestedVerdict): string;
38
+
39
+ interface AttestationCheck {
40
+ ok: boolean;
41
+ /** Who signed it, as the verdict claims. */
42
+ signer: string | null;
43
+ problems: string[];
44
+ }
45
+ declare function verifyAttestation(v: AttestedVerdict & {
46
+ attestation?: Attestation | null;
47
+ }, opts: {
48
+ signer: string;
49
+ }): Promise<AttestationCheck>;
50
+
51
+ export { type AttestationCheck, type AttestedVerdict, attestationMessage, verifyAttestation };
package/dist/attest.js ADDED
@@ -0,0 +1,47 @@
1
+ // src/attest.ts
2
+ import { verifyMessage } from "viem";
3
+
4
+ // ../engine/src/attest.ts
5
+ var ATTESTATION_TITLE = "Skein verdict attestation v1";
6
+ function attestationMessage(v) {
7
+ return [
8
+ ATTESTATION_TITLE,
9
+ `id: ${v.id}`,
10
+ `subject: eip155:${v.subject.chainId}:${v.subject.token.toLowerCase()}`,
11
+ `verdict: ${v.verdict}`,
12
+ `risk_bps: ${v.riskBps}`,
13
+ `confidence_bps: ${v.confidenceBps}`,
14
+ `policy: ${v.policy.id}@${v.policy.version}`,
15
+ `engine: ${v.engineVersion}`,
16
+ `verdict_hash: ${v.verdictHash}`,
17
+ `bom_root: ${v.bom.root}`,
18
+ `price_usdc: ${v.cost.priceUsdc}`,
19
+ `upstream_usdc: ${v.cost.upstreamUsdc}`,
20
+ `network: ${v.network}`,
21
+ `created_at: ${v.createdAt}`
22
+ ].join("\n");
23
+ }
24
+
25
+ // src/attest.ts
26
+ async function verifyAttestation(v, opts) {
27
+ const a = v.attestation;
28
+ if (!a) return { ok: false, signer: null, problems: ["the verdict carries no attestation (the API has no attestation key set)"] };
29
+ const problems = [];
30
+ if (a.scheme !== "eip191") problems.push(`unknown scheme ${a.scheme}`);
31
+ if (a.signer.toLowerCase() !== opts.signer.toLowerCase()) problems.push(`signed by ${a.signer}, not the expected ${opts.signer}`);
32
+ const rebuilt = attestationMessage(v);
33
+ if (rebuilt !== a.message) problems.push("the signed message does not match the verdict's fields");
34
+ let valid = false;
35
+ try {
36
+ valid = await verifyMessage({ address: opts.signer, message: rebuilt, signature: a.signature });
37
+ } catch {
38
+ valid = false;
39
+ }
40
+ if (!valid) problems.push("the signature does not recover to the expected signer for this verdict");
41
+ return { ok: problems.length === 0, signer: a.signer, problems };
42
+ }
43
+ export {
44
+ attestationMessage,
45
+ verifyAttestation
46
+ };
47
+ //# sourceMappingURL=attest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/attest.ts","../../engine/src/attest.ts"],"sourcesContent":["/**\n * Check a Skein verdict's signature yourself (needs viem). Import from\n * \"@skeinlabs/sdk/attest\".\n *\n * import { verifyAttestation } from \"@skeinlabs/sdk/attest\";\n * const r = await verifyAttestation(v, { signer: SKEIN_ATTESTER }); // the address at /v1/status\n * if (!r.ok) throw new Error(r.problems.join(\"; \"));\n *\n * It rebuilds the signed message from the verdict's own fields, so a verdict\n * whose outcome, hash, cost or subject was edited after signing fails, even\n * when the attached message and signature are left untouched.\n */\nimport { verifyMessage } from \"viem\";\nimport { attestationMessage, type AttestedVerdict } from \"@skein/engine/attest\";\nimport type { Attestation } from \"./types\";\n\nexport { attestationMessage, type AttestedVerdict };\n\nexport interface AttestationCheck {\n ok: boolean;\n /** Who signed it, as the verdict claims. */\n signer: string | null;\n problems: string[];\n}\n\nexport async function verifyAttestation(v: AttestedVerdict & { attestation?: Attestation | null }, opts: { signer: string }): Promise<AttestationCheck> {\n const a = v.attestation;\n if (!a) return { ok: false, signer: null, problems: [\"the verdict carries no attestation (the API has no attestation key set)\"] };\n const problems: string[] = [];\n if (a.scheme !== \"eip191\") problems.push(`unknown scheme ${a.scheme}`);\n if (a.signer.toLowerCase() !== opts.signer.toLowerCase()) problems.push(`signed by ${a.signer}, not the expected ${opts.signer}`);\n const rebuilt = attestationMessage(v);\n if (rebuilt !== a.message) problems.push(\"the signed message does not match the verdict's fields\");\n let valid = false;\n try {\n valid = await verifyMessage({ address: opts.signer as `0x${string}`, message: rebuilt, signature: a.signature as `0x${string}` });\n } catch {\n valid = false;\n }\n if (!valid) problems.push(\"the signature does not recover to the expected signer for this verdict\");\n return { ok: problems.length === 0, signer: a.signer, problems };\n}\n","/**\n * The message Skein signs for every verdict (EIP-191 personal_sign, the same\n * scheme Telegraph uses for escrow payments). It names everything a reader\n * relies on (the subject, the outcome, the policy and engine, the verdict hash\n * and the receipts' Merkle root, the cost) in plain lines, so a signature can\n * travel with a listing memo or a payment and be checked by anyone who knows\n * Skein's published attester address. Nothing secret, no dependencies: the API\n * signs it and @skeinlabs/sdk/attest rebuilds it to verify.\n */\nexport interface AttestedVerdict {\n id: string;\n subject: { chainId: number; token: string };\n verdict: string;\n riskBps: number;\n confidenceBps: number;\n policy: { id: string; version: string };\n engineVersion: string;\n verdictHash: string;\n bom: { root: string };\n cost: { priceUsdc: number; upstreamUsdc: number };\n network: string;\n createdAt: string;\n}\n\nexport const ATTESTATION_SCHEME = \"eip191\";\nexport const ATTESTATION_TITLE = \"Skein verdict attestation v1\";\n\nexport function attestationMessage(v: AttestedVerdict): string {\n return [\n ATTESTATION_TITLE,\n `id: ${v.id}`,\n `subject: eip155:${v.subject.chainId}:${v.subject.token.toLowerCase()}`,\n `verdict: ${v.verdict}`,\n `risk_bps: ${v.riskBps}`,\n `confidence_bps: ${v.confidenceBps}`,\n `policy: ${v.policy.id}@${v.policy.version}`,\n `engine: ${v.engineVersion}`,\n `verdict_hash: ${v.verdictHash}`,\n `bom_root: ${v.bom.root}`,\n `price_usdc: ${v.cost.priceUsdc}`,\n `upstream_usdc: ${v.cost.upstreamUsdc}`,\n `network: ${v.network}`,\n `created_at: ${v.createdAt}`,\n ].join(\"\\n\");\n}\n\nexport interface Attestation {\n scheme: typeof ATTESTATION_SCHEME;\n signer: string;\n message: string;\n signature: string;\n}\n"],"mappings":";AAYA,SAAS,qBAAqB;;;ACavB,IAAM,oBAAoB;AAE1B,SAAS,mBAAmB,GAA4B;AAC7D,SAAO;AAAA,IACL;AAAA,IACA,OAAO,EAAE,EAAE;AAAA,IACX,mBAAmB,EAAE,QAAQ,OAAO,IAAI,EAAE,QAAQ,MAAM,YAAY,CAAC;AAAA,IACrE,YAAY,EAAE,OAAO;AAAA,IACrB,aAAa,EAAE,OAAO;AAAA,IACtB,mBAAmB,EAAE,aAAa;AAAA,IAClC,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,OAAO;AAAA,IAC1C,WAAW,EAAE,aAAa;AAAA,IAC1B,iBAAiB,EAAE,WAAW;AAAA,IAC9B,aAAa,EAAE,IAAI,IAAI;AAAA,IACvB,eAAe,EAAE,KAAK,SAAS;AAAA,IAC/B,kBAAkB,EAAE,KAAK,YAAY;AAAA,IACrC,YAAY,EAAE,OAAO;AAAA,IACrB,eAAe,EAAE,SAAS;AAAA,EAC5B,EAAE,KAAK,IAAI;AACb;;;ADnBA,eAAsB,kBAAkB,GAA2D,MAAqD;AACtJ,QAAM,IAAI,EAAE;AACZ,MAAI,CAAC,EAAG,QAAO,EAAE,IAAI,OAAO,QAAQ,MAAM,UAAU,CAAC,yEAAyE,EAAE;AAChI,QAAM,WAAqB,CAAC;AAC5B,MAAI,EAAE,WAAW,SAAU,UAAS,KAAK,kBAAkB,EAAE,MAAM,EAAE;AACrE,MAAI,EAAE,OAAO,YAAY,MAAM,KAAK,OAAO,YAAY,EAAG,UAAS,KAAK,aAAa,EAAE,MAAM,sBAAsB,KAAK,MAAM,EAAE;AAChI,QAAM,UAAU,mBAAmB,CAAC;AACpC,MAAI,YAAY,EAAE,QAAS,UAAS,KAAK,wDAAwD;AACjG,MAAI,QAAQ;AACZ,MAAI;AACF,YAAQ,MAAM,cAAc,EAAE,SAAS,KAAK,QAAyB,SAAS,SAAS,WAAW,EAAE,UAA2B,CAAC;AAAA,EAClI,QAAQ;AACN,YAAQ;AAAA,EACV;AACA,MAAI,CAAC,MAAO,UAAS,KAAK,wEAAwE;AAClG,SAAO,EAAE,IAAI,SAAS,WAAW,GAAG,QAAQ,EAAE,QAAQ,SAAS;AACjE;","names":[]}
@@ -0,0 +1,187 @@
1
+ import { T as TelegraphAsker, S as Subject, Q as Quote, V as VerdictObject, B as Bom, a as VerifyReport, b as VerdictEvent } from './types-B_RIoOCq.js';
2
+ export { A as Attestation, c as BomLine, C as CheckStatus, F as Finding, d as TelegraphAskOutcomeFail, e as TelegraphAskOutcomeOk, f as Verdict } from './types-B_RIoOCq.js';
3
+
4
+ /** One parsed server-sent event. */
5
+ interface RawEvent {
6
+ event: string;
7
+ data: string;
8
+ id?: string;
9
+ }
10
+ /**
11
+ * Parses a text/event-stream body into events (WHATWG rules: fields per line,
12
+ * a blank line dispatches, "data" lines join with \n, ":" lines are comments).
13
+ * Works on any fetch Response, in Node or the browser.
14
+ */
15
+ declare function parseSse(body: ReadableStream<Uint8Array>, signal?: AbortSignal): AsyncGenerator<RawEvent>;
16
+
17
+ /** The intent Skein serves on Telegraph (plan A; see miner/INTENT.md). */
18
+ declare const SKEIN_INTENT = "FRAUD_RISK_TOKEN_LISTING";
19
+ /**
20
+ * How a verdict is paid for:
21
+ * - apiKey: a Skein partner key against the HTTP API (free during the hackathon);
22
+ * - telegraph: one paid Telegraph ask, routed to the Skein miner or pinned to it.
23
+ * `client` is any Telegraph client, e.g. new TelegraphClient(...) from @skeinlabs/sdk/telegraph,
24
+ * which enforces its own per-call price cap on the 402 challenge.
25
+ */
26
+ type Payer = {
27
+ kind: "apiKey";
28
+ key: string;
29
+ } | {
30
+ kind: "telegraph";
31
+ client: TelegraphAsker;
32
+ minerId?: string;
33
+ intent?: string;
34
+ };
35
+ interface SkeinOptions {
36
+ /** e.g. https://api.skeinlabs.site (with or without /v1). */
37
+ apiUrl: string;
38
+ payer?: Payer;
39
+ /** Refuse, before paying, any verdict whose quoted price is above this. */
40
+ maxUsdcPerCall?: number;
41
+ /** Retries for network errors, 429 and retryable 5xx. Default 2. */
42
+ retries?: number;
43
+ /** The most the SDK sleeps between retries of one call, in total; a longer Retry-After throws instead. Default 10 s. */
44
+ maxRetryWaitMs?: number;
45
+ /** Each HTTP request (submit, quote, get, verify) gives up after this. Default 15 s. */
46
+ requestTimeoutMs?: number;
47
+ /** How long verdict() waits for a result. Default 120 s. */
48
+ timeoutMs?: number;
49
+ fetch?: typeof fetch;
50
+ }
51
+ interface VerdictRequest {
52
+ subject: Subject;
53
+ /** "dex-list@0.1.0", or an id for its latest version. */
54
+ policy?: string;
55
+ /**
56
+ * Optional evidence about the project. socialHandle buys the social-bot
57
+ * check, repoUrl (github.com or gitlab.com) buys the code review.
58
+ * `social` and `repo` are accepted as aliases.
59
+ */
60
+ context?: VerdictContextInput;
61
+ /** Reuse to make a retried call return the original verdict. Generated when omitted. */
62
+ idempotencyKey?: string;
63
+ /** Called with each live event (API key path). */
64
+ onEvent?: (e: VerdictEvent) => void;
65
+ signal?: AbortSignal;
66
+ /** A quote you already fetched for this request, so verdict() does not fetch another. */
67
+ quote?: Quote;
68
+ }
69
+ interface VerdictContextInput {
70
+ deployer?: string;
71
+ socialHandle?: string;
72
+ repoUrl?: string;
73
+ treasuryAddresses?: string[];
74
+ pool?: string;
75
+ /** Alias of socialHandle. */
76
+ social?: string;
77
+ /** Alias of repoUrl. */
78
+ repo?: string;
79
+ }
80
+ /** The API's field names: aliases mapped, empty values dropped. */
81
+ declare function canonicalContext(c: VerdictContextInput | undefined): Record<string, unknown> | undefined;
82
+ type Payment = {
83
+ rail: "apiKey";
84
+ } | {
85
+ rail: "telegraph";
86
+ minerId: string;
87
+ amountUsdc: number;
88
+ receiptHash: string | null;
89
+ signalHash: string | null;
90
+ };
91
+ type VerdictResult = VerdictObject & {
92
+ payment: Payment;
93
+ };
94
+ /** Every API error, with the API's code (BUDGET_TOO_LOW, RATE_LIMITED, …) or an SDK code. */
95
+ declare class SkeinError extends Error {
96
+ readonly code: string;
97
+ readonly status: number;
98
+ readonly details?: unknown | undefined;
99
+ /**
100
+ * Set when money moved (or may have) before the failure: a Telegraph ask
101
+ * that was paid but produced no verdict. Count it against your caps.
102
+ */
103
+ readonly payment?: {
104
+ amountUsdc: number;
105
+ billing: "paid" | "unknown";
106
+ receiptHash?: string | null;
107
+ } | undefined;
108
+ constructor(code: string, message: string, status?: number, details?: unknown | undefined,
109
+ /**
110
+ * Set when money moved (or may have) before the failure: a Telegraph ask
111
+ * that was paid but produced no verdict. Count it against your caps.
112
+ */
113
+ payment?: {
114
+ amountUsdc: number;
115
+ billing: "paid" | "unknown";
116
+ receiptHash?: string | null;
117
+ } | undefined);
118
+ }
119
+ /** The quoted price is above maxUsdcPerCall; nothing was paid. */
120
+ declare class SpendCapError extends SkeinError {
121
+ readonly priceUsdc: number;
122
+ readonly capUsdc: number;
123
+ constructor(priceUsdc: number, capUsdc: number);
124
+ }
125
+ declare class Skein {
126
+ private readonly opts;
127
+ private readonly base;
128
+ private readonly fetch;
129
+ private readonly retries;
130
+ private readonly timeoutMs;
131
+ constructor(opts: SkeinOptions);
132
+ private readonly maxRetryWaitMs;
133
+ private readonly requestTimeoutMs;
134
+ /** One HTTP request with its own deadline, still cancellable by the caller's signal. */
135
+ private request;
136
+ /**
137
+ * A raw call with typed errors and retries. POSTs are retried only with an
138
+ * idempotency key. Retries sleep at most maxRetryWaitMs in total: a
139
+ * Retry-After past that (a daily cap until midnight) throws at once.
140
+ */
141
+ private call;
142
+ /** What a verdict would buy and cost, without buying. Free. */
143
+ quote(req: {
144
+ subject: Subject;
145
+ policy?: string;
146
+ }): Promise<Quote>;
147
+ /** A stored verdict, or { status: "running" } while it is being made. */
148
+ get(id: string): Promise<VerdictObject | {
149
+ id: string;
150
+ status: "running";
151
+ }>;
152
+ /** The bill of materials: every paid input and its receipt. */
153
+ bom(id: string): Promise<Bom>;
154
+ /** Recompute a verdict from its raw paid answers. */
155
+ verify(id: string): Promise<VerifyReport>;
156
+ /** The live events of a verdict, replayed from the start; ends after done, refused or error. */
157
+ stream(id: string, opts?: {
158
+ signal?: AbortSignal;
159
+ }): AsyncGenerator<VerdictEvent>;
160
+ /**
161
+ * Buys one verdict and returns it once it is sealed. With maxUsdcPerCall
162
+ * set, the price is quoted first and the call refused before any payment.
163
+ */
164
+ verdict(req: VerdictRequest): Promise<VerdictResult>;
165
+ /**
166
+ * Starts a verdict on the partner-key rail and returns at once: the id while
167
+ * it runs, or the verdict itself when it is cached or replayed. Pair with
168
+ * wait(id). Spend-cap checks are the caller's (verdict() does them).
169
+ */
170
+ submit(req: VerdictRequest): Promise<{
171
+ id: string;
172
+ status: "running";
173
+ } | VerdictResult>;
174
+ /**
175
+ * Waits for a submitted verdict: follows its event stream (falling back to
176
+ * polling if the stream drops) and throws a SkeinError if it is refused.
177
+ */
178
+ wait(id: string, opts?: {
179
+ onEvent?: (e: VerdictEvent) => void;
180
+ signal?: AbortSignal;
181
+ timeoutMs?: number;
182
+ }): Promise<VerdictResult>;
183
+ private viaApi;
184
+ private viaTelegraph;
185
+ }
186
+
187
+ export { Bom, type Payer, type Payment, Quote, SKEIN_INTENT, Skein, SkeinError, type SkeinOptions, SpendCapError, Subject, TelegraphAsker, type VerdictContextInput, VerdictEvent, VerdictObject, type VerdictRequest, type VerdictResult, VerifyReport, canonicalContext, parseSse };