twin3-sdk 0.0.0-stage → 0.2.10-pre-alpha
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 +67 -0
- package/README.md +175 -2
- package/human-score.d.ts +70 -0
- package/index.d.ts +1493 -0
- package/js/comm/counterparty.js +386 -0
- package/js/human-score.js +199 -0
- package/js/index.js +6566 -0
- package/js/state.js +508 -0
- package/package.json +54 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
Twin3 SDK Proprietary License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Twin3 AI Limited (the "Licensor"). All rights reserved.
|
|
4
|
+
|
|
5
|
+
This software, together with its documentation, specifications, protocol
|
|
6
|
+
designs, test vectors, and cryptographic constructions (the "Software"), is the
|
|
7
|
+
proprietary property of the Licensor. It is not open-source software. Making a
|
|
8
|
+
distribution artifact publicly downloadable from a package registry or source
|
|
9
|
+
host does not place the Software in the public domain, does not grant any
|
|
10
|
+
open-source licence, and does not waive any right reserved below.
|
|
11
|
+
|
|
12
|
+
1. Limited licence
|
|
13
|
+
Subject to continuous compliance with these terms, the Licensor grants you a
|
|
14
|
+
personal, non-exclusive, non-transferable, non-sublicensable, revocable
|
|
15
|
+
licence to download, install, and execute unmodified official distribution
|
|
16
|
+
artifacts of the Software, solely to evaluate the Software and to build and
|
|
17
|
+
operate applications that interoperate with it.
|
|
18
|
+
|
|
19
|
+
2. Restrictions
|
|
20
|
+
Except where applicable law expressly prohibits such a restriction, you may
|
|
21
|
+
not: copy the Software beyond what is required to exercise the licence in
|
|
22
|
+
section 1; modify, adapt, translate, or create derivative works of the
|
|
23
|
+
Software; redistribute, publish, sublicense, sell, rent, lease, or provide
|
|
24
|
+
the Software to any third party, whether standalone or embedded in another
|
|
25
|
+
product or service; remove, obscure, or alter any proprietary or attribution
|
|
26
|
+
notice; or reverse engineer, decompile, or disassemble the Software.
|
|
27
|
+
|
|
28
|
+
3. Reservation of rights
|
|
29
|
+
All rights not expressly granted in section 1 are reserved by the Licensor,
|
|
30
|
+
including every copyright, patent, trade secret, trademark, database, and
|
|
31
|
+
other intellectual property right in the Software. No patent licence is
|
|
32
|
+
granted by implication, estoppel, or otherwise. No trademark licence is
|
|
33
|
+
granted.
|
|
34
|
+
|
|
35
|
+
4. Contributions and derivative work
|
|
36
|
+
Nothing in this licence grants any right to fork the Software, publish a
|
|
37
|
+
derivative of it, or contribute to it. Any such activity requires prior
|
|
38
|
+
written permission from the Licensor.
|
|
39
|
+
|
|
40
|
+
5. Termination
|
|
41
|
+
This licence terminates automatically and immediately upon any breach of
|
|
42
|
+
these terms. On termination you must stop using the Software and destroy all
|
|
43
|
+
copies in your possession or control. Sections 2, 3, 6, 7, and 8 survive
|
|
44
|
+
termination.
|
|
45
|
+
|
|
46
|
+
6. No warranty
|
|
47
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
48
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
49
|
+
FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT. THE SOFTWARE
|
|
50
|
+
IMPLEMENTS SECURITY AND SETTLEMENT PROTOCOLS; THE LICENSOR DOES NOT WARRANT
|
|
51
|
+
THAT IT IS FREE OF DEFECTS OR FIT FOR ANY PARTICULAR DEPLOYMENT.
|
|
52
|
+
|
|
53
|
+
7. Limitation of liability
|
|
54
|
+
TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSOR SHALL NOT BE
|
|
55
|
+
LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
|
56
|
+
CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE
|
|
57
|
+
SOFTWARE OR ITS USE, INCLUDING ANY INDIRECT, INCIDENTAL, SPECIAL,
|
|
58
|
+
CONSEQUENTIAL, EXEMPLARY, OR PUNITIVE DAMAGES, OR ANY LOSS OF PROFITS,
|
|
59
|
+
REVENUE, DATA, OR DIGITAL ASSETS.
|
|
60
|
+
|
|
61
|
+
8. Entire terms
|
|
62
|
+
These terms are the entire licence for the Software and supersede any prior
|
|
63
|
+
or contemporaneous understanding. A separate written agreement signed by the
|
|
64
|
+
Licensor may grant broader rights; only that agreement can vary these terms.
|
|
65
|
+
|
|
66
|
+
For commercial licensing, redistribution rights, or any permission not granted
|
|
67
|
+
above, contact core@twin3.ai.
|
package/README.md
CHANGED
|
@@ -1,3 +1,176 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Twin3 SDK (`twin3-sdk`)
|
|
2
|
+
> **The Universal Capability Motherboard for Autonomous AI Agents & Self-Sovereign Humans**
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
[English](README.md) | [繁體中文](README_ZH.md) | [GitHub: twin3-team/twin3-sdk](https://github.com/twin3-team/twin3-sdk)
|
|
5
|
+
|
|
6
|
+
[](https://python.org)
|
|
7
|
+
[](#the-seven-layer-symbiotic-architecture)
|
|
8
|
+
[](#dual-application-projections)
|
|
9
|
+
[](https://github.com/twin3-team/twin3-sdk)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## 1. Overview & Vision
|
|
14
|
+
|
|
15
|
+
**Twin3 SDK** is a domain-agnostic, cryptographically secure foundational runtime designed to bridge autonomous AI agents and self-sovereign human individuals into a single symbiotic economic network.
|
|
16
|
+
|
|
17
|
+
As AI models evolve toward fully autonomous trading actors, the primary barrier to adoption is not intelligence, but **counterparty trust, deterministic authorization, cryptographic non-repudiation, and autonomous financial settlement**.
|
|
18
|
+
|
|
19
|
+
Twin3 SDK solves this by establishing a **Seven-Layer Symbiotic Architecture (L1 to L7)**. It serves as the universal hardware-like motherboard, while domain-specific applications plug into it as specialized software projections:
|
|
20
|
+
1. **Agent ID (Enterprise Projection)**: Powers B2B autonomous commerce, procurement negotiation, and Dun & Bradstreet (D-U-N-S) enterprise identity verification across 20 commercial capabilities.
|
|
21
|
+
2. **Human ID (Sovereign Projection)**: Protects 140,000+ real-world human identity assets, providing Passkey (WebAuthn) biometrics, personal sovereign cards, and paid anti-spam inboxes.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 2. The Seven-Layer Symbiotic Architecture
|
|
26
|
+
|
|
27
|
+
Twin3 SDK organizes all distributed primitives into seven clean, composable layers:
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
┌─────────────────────────────────────────────────────────┐
|
|
31
|
+
│ Twin3 SDK Core Engine │
|
|
32
|
+
├────┬───────────────────────┬────────────────────────────┤
|
|
33
|
+
│ L1 │ Discovery Layer │ twin3.discovery │
|
|
34
|
+
│ L2 │ Trust & Identity │ twin3.trust │
|
|
35
|
+
│ L3 │ Communication Layer │ twin3.comm │
|
|
36
|
+
│ L4 │ Shield & Guardrails │ twin3.shield │
|
|
37
|
+
│ L5 │ Matrix Understanding │ twin3.matrix │
|
|
38
|
+
│ L6 │ Clearing & Settlement │ twin3.settlement │
|
|
39
|
+
│ L7 │ Governance & Audit │ twin3.governance │
|
|
40
|
+
└────┴───────────────────────┴────────────────────────────┘
|
|
41
|
+
▲ ▲
|
|
42
|
+
│ │
|
|
43
|
+
┌────────────────────┴───────────┐ ┌────────────┴─────────────────┐
|
|
44
|
+
│ Agent ID (Enterprise) │ │ Human ID (Sovereign) │
|
|
45
|
+
├────────────────────────────────┤ ├──────────────────────────────┤
|
|
46
|
+
│ • A2A 5-Stage Commercial Loop │ │ • Sovereign Identity Card │
|
|
47
|
+
│ • D-U-N-S Entity Verification │ │ • 140,000 Personality Vectors│
|
|
48
|
+
│ • Manufacturing Tolerance Match│ │ • Passkey WebAuthn Login │
|
|
49
|
+
│ • Corporate Multi-Sig Escrow │ │ • Paid Threshold Inbox │
|
|
50
|
+
└────────────────────────────────┘ └──────────────────────────────┘
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Layer Breakdown
|
|
54
|
+
|
|
55
|
+
| Layer | Module Path | Purpose | Key Primitives & Protocols |
|
|
56
|
+
| :--- | :--- | :--- | :--- |
|
|
57
|
+
| **L1 Discovery** | `twin3.discovery` | Agent Card & Sovereign Card specifications, public inbox declaration, in-memory registry. | `AgentCard`, `SovereignCard`, `build_declaration`, `DiscoveryRegistry` |
|
|
58
|
+
| **L2 Trust** | `twin3.trust` | Cryptographic identity handshake, public/private key verification, authority anchoring. | `create_challenge` / `complete_challenge` / `verify_binding`, `PasskeyAdapter`, `AuthorityAnchor`, `resolve_did_web`, nonce and sign-count stores |
|
|
59
|
+
| **L3 Communication** | `twin3.comm` | Non-repudiable message packaging, counterparty attention ladder, task inbox. | `build_envelope` / `validate_envelope` (Ed25519), `CounterpartyTable`, `TaskInbox`, owner access grants |
|
|
60
|
+
| **L4 Shield** | `twin3.shield` | Differential tampering defense, prompt injection filtering, and authorization guardrails. | `scan_text` / `scan_envelope` (T0–T3), `IntelEngine` (T1), `Ensemble` (T4), `diff_plans` / `authorize_execution` (T5), `MemoryGuard` |
|
|
61
|
+
| **L5 Matrix** | `twin3.matrix` | High-density vector space topological mapping and semantic cosine matching. | `DenseVector256`, `feature_distance`, `HumanMatrixSchema`, `EnterpriseMatrixSchema` |
|
|
62
|
+
| **L6 Settlement** | `twin3.settlement` | Signed-receipt verification for HTTP 402 gates, with externally supplied chain-finality and replay controls. | `PaymentDemand`, `PaymentReceipt`, `X402SettlementEngine` |
|
|
63
|
+
| **L7 Governance** | `twin3.governance` | Immutable evidence trail, appeals, advisory reputation federation, provisional arbitration helper. | `EvidenceTrail`, `open_appeal` / `resolve_appeal`, `export_reputation` / `import_reputation`, `ArbitrationEngine` (experimental), `DisputeCase` (experimental) |
|
|
64
|
+
|
|
65
|
+
`(experimental)` marks a capability whose row in [`tests/capability-inventory.json`](tests/capability-inventory.json) is not yet `available`: it is importable today and its surface may still change. Everything unmarked is `available`. A name written `Class.method` is a method, not a module export. Every name in this table is checked against a real public export by [`tests/test_readme_capability_claims.py`](tests/test_readme_capability_claims.py).
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## 3. Pull Request Lineage & Provenance
|
|
70
|
+
|
|
71
|
+
The primitives in `twin3-sdk` are extracted from the `twin3-team/agent-id` Inbox line (PRs #615–#642, merged 2026-09-03 → 2026-09-05; spec: `docs/architecture/inbox-module-spec.md` in that repo). What each layer inherited:
|
|
72
|
+
|
|
73
|
+
* **Envelope, KYA handshake, counterparty ladder** — `agent_id/inbox/{envelope,kya,counterparty}.py`: canonical-JSON signed envelopes with `authority:"none"`, the mutual Ed25519 challenge that binds a declared identity to a key, and the G0→G3 attention ladder keyed on the counterparty rather than the request.
|
|
74
|
+
* **Task inbox and state machine** — `agent_id/inbox/state.py`: intake gate, review gate, rate limits, stale expiry, hash-chained audit.
|
|
75
|
+
* **Shield T0–T5** — `agent_id/inbox/{shield,intel,classifier,plandiff,corpus}.py`: deterministic layers, URL/domain/hash intelligence, the T4 ensemble, plan diffing, and the corpus that publishes error rates.
|
|
76
|
+
* **Settlement policy** — `agent_id/inbox/payments.py`: owner policy, signed quotes and receipts behind HTTP 402.
|
|
77
|
+
* **Governance** — `agent_id/inbox/governance.py`: appeals, pardons, advisory reputation federation.
|
|
78
|
+
* **Canonical Matrix Core**: High-density 256-Byte vector topological clustering powering 140k natural human personality profiles and industrial tolerance matching.
|
|
79
|
+
|
|
80
|
+
The 2026-09-05 sync also adds the **AI-era hardening** (mandatory T5, identity-cost tier caps, provenance-gated memory, rotation demotes, paid ≠ authorized). See `CHANGELOG.md`.
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## 4. Package Distribution & Integration Model
|
|
85
|
+
|
|
86
|
+
### Why Not File Copying?
|
|
87
|
+
Copying code (`vendoring`) causes **protocol drift** where Agent ID and Human ID implementations diverge within weeks, breaking cross-network signature validation.
|
|
88
|
+
|
|
89
|
+
### Why Not Pure HTTP Microservices?
|
|
90
|
+
Cryptographic signatures (ECDSA/Ed25519) and 256-bit vector operations execute in under 0.2 milliseconds locally. Routing them through remote HTTP hops adds unnecessary latency and exposes private signing keys to network attack vectors.
|
|
91
|
+
|
|
92
|
+
### The Standard Solution: Semantic Package Dependencies
|
|
93
|
+
Twin3 SDK follows standard modern packaging conventions (`pyproject.toml` / `npm`). Production consumers must use immutable registry artifacts and exact version pins; local links are development-only.
|
|
94
|
+
|
|
95
|
+
#### 1. Development Mode (Local Symlink / Editable Install)
|
|
96
|
+
During local development, both `agent-id` and `XHuman_ID` link directly to the local SDK workspace:
|
|
97
|
+
```bash
|
|
98
|
+
# In agent-id or XHuman_ID virtual environment:
|
|
99
|
+
pip install -e /path/to/twin3-sdk
|
|
100
|
+
```
|
|
101
|
+
**Benefits**:
|
|
102
|
+
* Zero code duplication.
|
|
103
|
+
* Any protocol or algorithm improvement in `twin3-sdk` is reflected in both applications in **0 milliseconds**.
|
|
104
|
+
|
|
105
|
+
#### 2. Production Distribution
|
|
106
|
+
The next release candidate is `0.2.10-pre-alpha` for npm and `0.2.10a0` for Python. It is not a production dependency until the GitHub release workflows have built, attested, rehearsed, and published the exact tagged artifacts. Consumers must then pin the exact released version and lock its registry integrity; never use a mutable range for a cryptographic protocol dependency. This candidate stays pre-alpha. Marketplace or sales copy may offer it for evaluation; it is not a stable release, and the npm dist-tag is `next`, not `latest`.
|
|
107
|
+
|
|
108
|
+
`package.json` `engines` sets Node.js to `>=18` and does not set an npm engine. Any npm that can install a tarball can consume the package. Packing this repository was checked with npm 10 or newer; the stricter npm version in the release runbook applies only to Trusted Publishing.
|
|
109
|
+
|
|
110
|
+
After the release workflow has published that exact version, install the pin. These commands are not evidence that the registry already serves the package:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
npm install twin3-sdk@0.2.10-pre-alpha
|
|
114
|
+
pip install twin3-sdk==0.2.10a0
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Until publication, evaluate the packed npm tarball only. Do not install from a git URL or a version range:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
npm pack --ignore-scripts
|
|
121
|
+
npm install ./twin3-sdk-0.2.10-pre-alpha.tgz
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## 5. Dual-Application Projections
|
|
127
|
+
|
|
128
|
+
### 🏢 Agent ID (Enterprise Commerce Projection)
|
|
129
|
+
Agent ID consumes Twin3 SDK to execute the **5-Stage A2A Autonomous Commercial Loop**:
|
|
130
|
+
1. **Discovery**: Queries `twin3.discovery` for available suppliers and verified agent cards.
|
|
131
|
+
2. **Understand**: Uses `twin3.matrix` to compute tolerance matching against industrial RFQs.
|
|
132
|
+
3. **Negotiate**: Uses `twin3.comm` and `twin3.shield` to exchange signed quotes without prompt-tampering risks.
|
|
133
|
+
4. **Settle**: Uses the Twin3 signed-receipt adapter at an HTTP 402 gate. Acceptance additionally requires a trusted signer key, a chain-specific finality verifier, and a shared replay store.
|
|
134
|
+
5. **Dispute**: Invokes `twin3.governance` to resolve contractual non-performance.
|
|
135
|
+
|
|
136
|
+
### 👤 Human ID (Personal Sovereignty Projection)
|
|
137
|
+
Human ID consumes Twin3 SDK to empower natural individuals:
|
|
138
|
+
1. **140,000 Real Personality Assets**: Computes high-density personality matching via `twin3.matrix` without risking underlying database schemas.
|
|
139
|
+
2. **Passkey WebAuthn Login**: Binds biometric secure enclaves to decentralized keys via `twin3.trust`.
|
|
140
|
+
3. **Paid Inbox**: Protects individual inboxes against spam using `twin3.comm` and the signed-receipt adapter ($5 paywall threshold); the application supplies chain verification and shared replay state.
|
|
141
|
+
4. **Sovereign Card**: Renders non-custodial credentials using `twin3.discovery`.
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## 6. Directory Structure
|
|
146
|
+
|
|
147
|
+
```
|
|
148
|
+
twin3-sdk/
|
|
149
|
+
├── pyproject.toml # Standard packaging definition (PEP 621)
|
|
150
|
+
├── README.md # Canonical English manual
|
|
151
|
+
├── LICENSE # Proprietary licence, all rights reserved
|
|
152
|
+
├── js/index.js # Node runtime; js/comm/counterparty.js = Inbox line, counterparty side
|
|
153
|
+
├── twin3/ # Core SDK namespace
|
|
154
|
+
│ ├── __init__.py
|
|
155
|
+
│ ├── _compat.py # One import surface mirroring agent_id.inbox
|
|
156
|
+
│ ├── discovery/ # L1: Cards, Endpoints, agents.json, public inbox declaration
|
|
157
|
+
│ ├── trust/ # L2: KYA Handshake, did:web, Passkey Adapter
|
|
158
|
+
│ ├── comm/ # L3: Envelope, Counterparty Table, TaskInbox, export, client (counterparty side)
|
|
159
|
+
│ ├── shield/ # L4: T0–T3 defense, T1 intel, T4 classifier, T5 plan diff, corpus, memory gate
|
|
160
|
+
│ ├── matrix/ # L5: 256-Byte Vector Topology Engine
|
|
161
|
+
│ ├── settlement/ # L6: HTTP 402 Micropayments, owner policy, quotes, receipts
|
|
162
|
+
│ └── governance/ # L7: Evidence Trail, Arbitration, appeals, federation
|
|
163
|
+
└── tests/ # Hermetic standalone Python and Node test suites
|
|
164
|
+
├── test_{discovery,trust,comm,shield,matrix,settlement,governance}.py
|
|
165
|
+
├── test_{envelope,counterparty,kya_gate,inbox_gate,plan_diff_gate}.py # ported contracts
|
|
166
|
+
├── test_{classifier,intel,corpus_eval,settlement_policy,governance_gate,declaration,export}.py
|
|
167
|
+
└── test_ai_era_hardening.py # the five hardening rules
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## 7. License
|
|
173
|
+
|
|
174
|
+
**Proprietary. All rights reserved.** Twin3 SDK is not open-source software. See [`LICENSE`](LICENSE) for the exact terms.
|
|
175
|
+
|
|
176
|
+
Distribution artifacts are published to public package registries so that anyone can install and evaluate the SDK and build against it — **open access is not open source**. Public availability grants no right to copy, modify, redistribute, fork, or create derivative works, and no patent or trademark licence. For commercial licensing or redistribution rights, contact core@twin3.ai.
|
package/human-score.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export type PolicyId = 'HV-LADDER-BETA-1';
|
|
2
|
+
export type MethodId = 'google'|'passkey'|'telegram'|'line'|'discord'|'totp'|'recaptcha';
|
|
3
|
+
export class HumanScoreError extends Error { readonly code:string; constructor(code:string); }
|
|
4
|
+
export interface HumanScorePolicy {
|
|
5
|
+
readonly policy_id:PolicyId; readonly policy_hash:string; readonly release_state:'candidate';
|
|
6
|
+
readonly algorithm_version:'human-score-ladder-v1'; readonly schema_version:'human-score-ladder-v1';
|
|
7
|
+
readonly scale:Readonly<{min:0;max:255;decimals:0}>; readonly raw_scale:Readonly<{min:0;max:255}>;
|
|
8
|
+
readonly methods:readonly MethodId[];
|
|
9
|
+
readonly anchor:Readonly<{methods:readonly ['google','passkey'];raw_points:60;aggregation:'max'}>;
|
|
10
|
+
readonly additive_methods:Readonly<{telegram:45;line:30;discord:30;totp:20;recaptcha:5}>;
|
|
11
|
+
readonly requires_anchor:true; readonly technical_raw_cap:190; readonly social_raw_cap:65; readonly total_raw_cap:255;
|
|
12
|
+
readonly technical_validity:string;
|
|
13
|
+
readonly social:Readonly<{exponent:2;direct_floor:0.75;previous_mix:0.25;budget:5;max_targets:20;saturation_mass:10;full_days:90;end_days:180}>;
|
|
14
|
+
readonly epoch:Readonly<{interval_ms:number;freshness_ms:number}>;
|
|
15
|
+
readonly mint:Readonly<{enabled:false;reason:'ladder_mint_policy_not_approved'}>;
|
|
16
|
+
}
|
|
17
|
+
export type MethodEvidence = {status:'passed';verified_at:string;expires_at:string} |
|
|
18
|
+
{status:'not_completed'|'failed'|'revoked'|'unknown'} | null;
|
|
19
|
+
export type EvidenceMap = Readonly<Record<MethodId,MethodEvidence>>;
|
|
20
|
+
export interface TechnicalResult {
|
|
21
|
+
readonly anchor_present:boolean; readonly anchor_raw:number; readonly technical_raw:number;
|
|
22
|
+
readonly additive_raw:Readonly<Record<'telegram'|'line'|'discord'|'totp'|'recaptcha',number>>;
|
|
23
|
+
readonly pending_anchor_methods:readonly MethodId[];
|
|
24
|
+
}
|
|
25
|
+
export interface ScoreSubject {subject_id:string;created_at:string;method_evidence:EvidenceMap;}
|
|
26
|
+
export interface WitnessEdge {
|
|
27
|
+
id:string;source_subject_id:string;target_subject_id:string;statement_version:'human_witness_v1'|'support_v1';
|
|
28
|
+
status:'accepted'|'pending'|'revoked'|'blocked';accepted_at?:string;confirmed_at?:string;
|
|
29
|
+
}
|
|
30
|
+
interface SnapshotBase {
|
|
31
|
+
readonly schema_version:'human-score-ladder-v1';readonly subject_id:string;
|
|
32
|
+
readonly policy_id:PolicyId;readonly policy_hash:string;readonly epoch_id:string;
|
|
33
|
+
readonly as_of:string;readonly computed_at:string;readonly next_scheduled_at:string;readonly fresh_until:string;
|
|
34
|
+
readonly scale:Readonly<{min:0;max:255;decimals:0}>;readonly received_count:number;readonly outgoing_count:number;
|
|
35
|
+
readonly seed_reason:'policy_activation'|'new_subject'|null;readonly reasons:readonly string[];
|
|
36
|
+
}
|
|
37
|
+
export interface ReadyScoreSnapshot extends SnapshotBase {
|
|
38
|
+
readonly status:'ready';readonly score:number;readonly score_units:number;readonly social_reputation_units:number;
|
|
39
|
+
readonly technical_raw:number;readonly social_raw:number;readonly total_raw:number;readonly anchor_present:boolean;
|
|
40
|
+
readonly breakdown:TechnicalResult;readonly effective_mass:number;readonly counted_source_count:number;
|
|
41
|
+
}
|
|
42
|
+
export interface UnavailableScoreSnapshot extends SnapshotBase {
|
|
43
|
+
readonly status:'unavailable';readonly score:null;readonly score_units:null;readonly social_reputation_units:null;
|
|
44
|
+
}
|
|
45
|
+
export type ScoreSnapshot = ReadyScoreSnapshot|UnavailableScoreSnapshot;
|
|
46
|
+
export interface PreviousEpoch {
|
|
47
|
+
schema_version:'human-score-ladder-epoch-v1';policy_id:PolicyId;policy_hash:string;epoch_id:string;as_of:string;status:'complete';
|
|
48
|
+
snapshots:readonly ({subject_id:string}&(
|
|
49
|
+
{status:'ready';score_units:number;social_reputation_units:number}|
|
|
50
|
+
{status:'unavailable'|'invalidated';score_units:null;social_reputation_units:null}))[];
|
|
51
|
+
}
|
|
52
|
+
export type EpochInput = {
|
|
53
|
+
policy_id:PolicyId;policy_hash:string;as_of:string;computed_at:string;
|
|
54
|
+
coverage:{subjects:true;evidence:true;witnesses:true};subjects:readonly ScoreSubject[];edges:readonly WitnessEdge[];
|
|
55
|
+
}&({mode:'policy_activation';activation_as_of:string;previous:null}|{mode:'daily';previous:PreviousEpoch});
|
|
56
|
+
export interface HumanScoreEpoch extends PreviousEpoch {readonly snapshots:readonly ScoreSnapshot[];}
|
|
57
|
+
export function getHumanScorePolicy(id:PolicyId):HumanScorePolicy;
|
|
58
|
+
export function scoreUnits(value:number):number;
|
|
59
|
+
export function rawToHumanScore(raw:number):number;
|
|
60
|
+
export function freshnessFactor(ageDays:number,fullDays?:number,endDays?:number):number;
|
|
61
|
+
export function calculateTechnicalScore(evidence:EvidenceMap,asOf:string):Readonly<TechnicalResult>|null;
|
|
62
|
+
export function socialRaw(mass:number):number;
|
|
63
|
+
export function socialEdgeWeight(input:{technical_raw:number;previous_score_units:number;outgoing_count:number;age_days:number}):number;
|
|
64
|
+
export function previewTechnicalDelta(input:{evidence:EvidenceMap;as_of:string;method_id:MethodId;social_raw?:number}):Readonly<
|
|
65
|
+
{status:'unavailable';delta_units:null;authorization_required:true}|
|
|
66
|
+
{status:'conditional';technical_raw_before:number;technical_raw_after:number;delta_units:number;same_epoch_only:true;authorization_required:true}>;
|
|
67
|
+
export function calculateHumanScoreEpoch(input:EpochInput):HumanScoreEpoch;
|
|
68
|
+
export function evaluateHumanScoreThresholds(snapshot:ScoreSnapshot):Readonly<{
|
|
69
|
+
meets_thresholds:false;mint_authorized:false;authorization_required:true;reasons:readonly string[];
|
|
70
|
+
}>;
|