Repository navigation
Expand file tree
/
Copy pathtrustgraph.d.ts
More file actions
103 lines (94 loc) · 3.39 KB
/
Copy pathtrustgraph.d.ts
File metadata and controls
103 lines (94 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// TypeScript types for the Trust Graph JavaScript packages.
//
// `@trustgraph/trustgraph` (native, napi-rs) and `@trustgraph/trustgraph-wasm`
// (WebAssembly) share this API exactly: both wrap `trustgraph_core::api`.
/** One statement of trust: `source` trusts `target`, about `content`, `value` much. */
export interface TrustAtom {
source: string;
target: string;
content?: string;
/** A decimal in -1..=1, as a string (e.g. "0.9"). */
value?: string;
/** RFC 3339, e.g. "2026-01-01T00:00:00Z". */
timestamp?: string;
extra?: Record<string, string>;
}
/** An atom as accepted on input: `value` may also be a number. */
export type TrustAtomInput = Omit<TrustAtom, "value"> & { value?: string | number };
/** A Trust Atom as a W3C Verifiable Credential 2.0, optionally signed. */
export interface Credential {
"@context": string[];
type: string[];
issuer: string;
validFrom?: string;
credentialSubject: {
id: string;
content?: string;
value?: string;
extra?: Record<string, string>;
};
proof?: {
type: "DataIntegrityProof";
cryptosuite: "eddsa-jcs-2022";
created: string;
verificationMethod: string;
proofPurpose: "assertionMethod";
"@context"?: string[];
proofValue: string;
};
}
export interface KeyInfo {
/** `did:key:z6Mk…` */
did: string;
publicKeyMultibase: string;
/** Keep this secret. */
secretKeyMultibase: string;
}
export interface Verification {
valid: boolean;
id?: string;
issuer?: string;
atom?: TrustAtom;
error?: string;
}
export interface LensOptions {
/** Maximum hops, 1..=10. Default 3. */
depth?: number;
/** Weight of each hop after the first, 0..=1. Default 0.5. */
decay?: number;
/** Only follow and score trust about this topic. */
topic?: string;
/** Ignore unsigned atoms. */
signedOnly?: boolean;
/** Return at most this many entries. */
limit?: number;
}
export interface LensEntry {
target: string;
/** -1..=1 */
score: number;
/** 0..=1: how much the root trusts the most trusted rater (1 = own rating). */
confidence: number;
hops: number;
raters: number;
}
/** Atoms and/or signed credentials. */
export type Item = TrustAtomInput | Credential;
export function version(): string;
/** Generates a new identity from a secure random source. Not deterministic: call it in a client or action, not inside a reactive query. */
export function generateKeypair(): KeyInfo;
/** Derives an identity from a 32-byte seed you supply (deterministic). */
export function keypairFromSeed(seed: Uint8Array): KeyInfo;
export function parseAtom(input: Item): TrustAtom;
/** Content ID (`Qm…`). */
export function atomId(input: Item): string;
/** Canonical JSON (RFC 8785), exactly as hashed. */
export function canonicalAtom(input: Item): string;
export function toCredential(atom: TrustAtomInput): Credential;
/** `created` is RFC 3339, e.g. `new Date().toISOString()`. */
export function signAtom(atom: TrustAtomInput, secretKeyMultibase: string, created: string): Credential;
export function verify(credential: Credential): Verification;
/** The Agent Lens: everything `root` can see in `items`, best first. */
export function lens(items: Item[], root: string, options?: LensOptions | null): LensEntry[];
/** Rollup atoms (unsigned) for `root`'s lens, timestamped `at` (RFC 3339). */
export function rollup(items: Item[], root: string, options: LensOptions | null | undefined, at: string): TrustAtom[];