@totemsdk/provider-bond 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 +21 -0
- package/README.md +233 -0
- package/dist/bond-proof.d.ts +4 -0
- package/dist/bond-proof.js +63 -0
- package/dist/constants.d.ts +16 -0
- package/dist/constants.js +24 -0
- package/dist/errors.d.ts +32 -0
- package/dist/errors.js +75 -0
- package/dist/identity.d.ts +5 -0
- package/dist/identity.js +86 -0
- package/dist/incidents.d.ts +5 -0
- package/dist/incidents.js +43 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +69 -0
- package/dist/manifest.d.ts +6 -0
- package/dist/manifest.js +61 -0
- package/dist/memory-store.d.ts +17 -0
- package/dist/memory-store.js +46 -0
- package/dist/policy.d.ts +4 -0
- package/dist/policy.js +146 -0
- package/dist/probes.d.ts +3 -0
- package/dist/probes.js +27 -0
- package/dist/registry.d.ts +13 -0
- package/dist/registry.js +80 -0
- package/dist/scoring.d.ts +3 -0
- package/dist/scoring.js +107 -0
- package/dist/serialization.d.ts +6 -0
- package/dist/serialization.js +58 -0
- package/dist/types.d.ts +204 -0
- package/dist/types.js +2 -0
- package/package.json +76 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeProviderBondState = serializeProviderBondState;
|
|
4
|
+
exports.parseProviderBondState = parseProviderBondState;
|
|
5
|
+
exports.serializeProviderBondRecord = serializeProviderBondRecord;
|
|
6
|
+
exports.parseProviderBondRecord = parseProviderBondRecord;
|
|
7
|
+
exports.canonicalJson = canonicalJson;
|
|
8
|
+
const errors_js_1 = require("./errors.js");
|
|
9
|
+
function canonicalJson(value) {
|
|
10
|
+
if (value === null || value === undefined)
|
|
11
|
+
return 'null';
|
|
12
|
+
if (typeof value === 'bigint')
|
|
13
|
+
return JSON.stringify({ __bigint: value.toString() });
|
|
14
|
+
if (typeof value === 'number') {
|
|
15
|
+
if (!Number.isFinite(value))
|
|
16
|
+
throw new errors_js_1.ProviderSerializationError('Cannot serialize NaN or Infinity');
|
|
17
|
+
return JSON.stringify(value);
|
|
18
|
+
}
|
|
19
|
+
if (typeof value === 'function')
|
|
20
|
+
throw new errors_js_1.ProviderSerializationError('Cannot serialize functions');
|
|
21
|
+
if (typeof value === 'symbol')
|
|
22
|
+
throw new errors_js_1.ProviderSerializationError('Cannot serialize symbols');
|
|
23
|
+
if (typeof value === 'string' || typeof value === 'boolean')
|
|
24
|
+
return JSON.stringify(value);
|
|
25
|
+
if (Array.isArray(value)) {
|
|
26
|
+
const items = value.map((v) => canonicalJson(v));
|
|
27
|
+
return `[${items.join(',')}]`;
|
|
28
|
+
}
|
|
29
|
+
if (typeof value === 'object') {
|
|
30
|
+
const keys = Object.keys(value).sort();
|
|
31
|
+
const pairs = keys.map((k) => {
|
|
32
|
+
const v = value[k];
|
|
33
|
+
if (v === undefined)
|
|
34
|
+
return null;
|
|
35
|
+
return `${JSON.stringify(k)}:${canonicalJson(v)}`;
|
|
36
|
+
}).filter((p) => p !== null);
|
|
37
|
+
return `{${pairs.join(',')}}`;
|
|
38
|
+
}
|
|
39
|
+
return JSON.stringify(value);
|
|
40
|
+
}
|
|
41
|
+
function bigIntReviver(_key, value) {
|
|
42
|
+
if (value && typeof value === 'object' && '__bigint' in value) {
|
|
43
|
+
return BigInt(value.__bigint);
|
|
44
|
+
}
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
function serializeProviderBondState(state) {
|
|
48
|
+
return canonicalJson(state);
|
|
49
|
+
}
|
|
50
|
+
function parseProviderBondState(json) {
|
|
51
|
+
return JSON.parse(json, bigIntReviver);
|
|
52
|
+
}
|
|
53
|
+
function serializeProviderBondRecord(record) {
|
|
54
|
+
return canonicalJson(record);
|
|
55
|
+
}
|
|
56
|
+
function parseProviderBondRecord(json) {
|
|
57
|
+
return JSON.parse(json, bigIntReviver);
|
|
58
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
export type BondAsset = 'MINIMA' | 'TOTEM' | string;
|
|
2
|
+
export type BondPurpose = 'hard-collateral' | 'service-level' | 'reputation' | 'governance' | 'marketplace-access' | 'dispute-bond' | 'grant-accountability' | 'app-specific' | 'community-specific';
|
|
3
|
+
export type BondStatus = 'declared' | 'pending' | 'active' | 'expiring' | 'expired' | 'invalid' | 'disputed';
|
|
4
|
+
export type BondLockType = 'manual-attestation' | 'visible-balance' | 'declared-reserve' | 'future-l1-lock' | 'future-covenant';
|
|
5
|
+
export type ProviderBondVerifyCode = 'OK' | 'MANIFEST_SIGNATURE_INVALID' | 'MANIFEST_EXPIRED' | 'IDENTITY_NOT_AUTHORISED' | 'IDENTITY_REVOKED' | 'IDENTITY_EXPIRED' | 'BOND_EXTENSION_HASH_MISMATCH' | 'BOND_OWNER_NOT_AUTHORISED' | 'BOND_RECOVERY_NOT_AUTHORISED' | 'PROBE_SIGNER_NOT_AUTHORISED' | 'INCIDENT_SIGNER_NOT_AUTHORISED' | 'SCORE_SIGNER_NOT_AUTHORISED' | 'BOND_PROOF_INVALID' | 'BOND_AMOUNT_INSUFFICIENT' | 'BOND_ASSET_NOT_ACCEPTED' | 'BOND_PURPOSE_NOT_ACCEPTED' | 'REQUIRES_LIVE_VERIFIER' | 'UNSUPPORTED_PROOF_TYPE';
|
|
6
|
+
export type ProviderRecommendation = 'recommended' | 'acceptable' | 'risky' | 'avoid' | 'offline' | 'unbonded' | 'expired';
|
|
7
|
+
export type ProbeType = 'heartbeat' | 'endpoint' | 'latency' | 'service-capability' | 'bond-proof-freshness' | 'manual-observation';
|
|
8
|
+
export type IncidentType = 'downtime' | 'high-latency' | 'failed-probe' | 'invalid-response' | 'invalid-bond-proof' | 'manual-dispute';
|
|
9
|
+
export type IncidentSeverity = 'low' | 'medium' | 'high' | 'critical';
|
|
10
|
+
export type IncidentStatus = 'open' | 'acknowledged' | 'resolved' | 'rejected';
|
|
11
|
+
export type BondProofType = 'manual' | 'declared' | 'visible-balance' | 'totem-proof' | 'future-live-chain';
|
|
12
|
+
export interface ProviderBondVerifyResult {
|
|
13
|
+
ok: boolean;
|
|
14
|
+
reason?: string;
|
|
15
|
+
code?: ProviderBondVerifyCode | string;
|
|
16
|
+
requiresLiveVerifier?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface BondStatusContext {
|
|
19
|
+
now?: number;
|
|
20
|
+
currentHeight?: bigint;
|
|
21
|
+
expiringThresholdBlocks?: bigint;
|
|
22
|
+
}
|
|
23
|
+
export interface ProviderBondAssetDeclaration {
|
|
24
|
+
bondId: string;
|
|
25
|
+
asset: BondAsset;
|
|
26
|
+
amount: bigint;
|
|
27
|
+
purpose: BondPurpose;
|
|
28
|
+
lockType: BondLockType;
|
|
29
|
+
status: BondStatus;
|
|
30
|
+
createdAt?: number;
|
|
31
|
+
expiresAtBlock?: bigint;
|
|
32
|
+
metadata?: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
export interface BondProofRef {
|
|
35
|
+
proofId: string;
|
|
36
|
+
bondId: string;
|
|
37
|
+
providerId: string;
|
|
38
|
+
proofType: BondProofType;
|
|
39
|
+
asset: BondAsset;
|
|
40
|
+
amount?: bigint;
|
|
41
|
+
createdAt?: number;
|
|
42
|
+
expiresAt?: number;
|
|
43
|
+
proof?: unknown;
|
|
44
|
+
metadata?: Record<string, unknown>;
|
|
45
|
+
}
|
|
46
|
+
export interface ProviderBondExtension {
|
|
47
|
+
providerId: string;
|
|
48
|
+
bondId?: string;
|
|
49
|
+
bondOwnerAddress?: string;
|
|
50
|
+
bondRecoveryAddress?: string;
|
|
51
|
+
probeSignerAddress?: string;
|
|
52
|
+
incidentSignerAddress?: string;
|
|
53
|
+
scoreSignerAddress?: string;
|
|
54
|
+
bondStack?: ProviderBondAssetDeclaration[];
|
|
55
|
+
bondProofs?: BondProofRef[];
|
|
56
|
+
liquidityBondRefs?: string[];
|
|
57
|
+
score?: ProviderScore;
|
|
58
|
+
incidentSummary?: IncidentSummary;
|
|
59
|
+
extensionHash?: string;
|
|
60
|
+
metadata?: Record<string, unknown>;
|
|
61
|
+
}
|
|
62
|
+
export interface ProviderBondManifest {
|
|
63
|
+
edgeServiceManifestId: string;
|
|
64
|
+
edgeService: import('@totemsdk/manifest').EdgeServiceManifest;
|
|
65
|
+
signedEdgeService?: import('@totemsdk/manifest').SignedManifest<import('@totemsdk/manifest').EdgeServiceManifest>;
|
|
66
|
+
providerBond: ProviderBondExtension;
|
|
67
|
+
}
|
|
68
|
+
export interface ProviderScore {
|
|
69
|
+
providerId: string;
|
|
70
|
+
score: number;
|
|
71
|
+
recommendation: ProviderRecommendation;
|
|
72
|
+
bondScore: number;
|
|
73
|
+
identityScore: number;
|
|
74
|
+
reliabilityScore: number;
|
|
75
|
+
incidentScore: number;
|
|
76
|
+
computedAt: number;
|
|
77
|
+
reasons: string[];
|
|
78
|
+
}
|
|
79
|
+
export interface IncidentSummary {
|
|
80
|
+
total: number;
|
|
81
|
+
open: number;
|
|
82
|
+
critical: number;
|
|
83
|
+
high: number;
|
|
84
|
+
medium: number;
|
|
85
|
+
low: number;
|
|
86
|
+
lastIncidentAt?: number;
|
|
87
|
+
}
|
|
88
|
+
export interface ProbeResult {
|
|
89
|
+
probeId: string;
|
|
90
|
+
providerId: string;
|
|
91
|
+
type: ProbeType;
|
|
92
|
+
ok: boolean;
|
|
93
|
+
latencyMs?: number;
|
|
94
|
+
observedAt: number;
|
|
95
|
+
message?: string;
|
|
96
|
+
metadata?: Record<string, unknown>;
|
|
97
|
+
}
|
|
98
|
+
export interface IncidentRecord {
|
|
99
|
+
incidentId: string;
|
|
100
|
+
providerId: string;
|
|
101
|
+
type: IncidentType;
|
|
102
|
+
severity: IncidentSeverity;
|
|
103
|
+
status: IncidentStatus;
|
|
104
|
+
createdAt: number;
|
|
105
|
+
resolvedAt?: number;
|
|
106
|
+
message?: string;
|
|
107
|
+
metadata?: Record<string, unknown>;
|
|
108
|
+
}
|
|
109
|
+
export interface ProviderPolicy {
|
|
110
|
+
serviceType?: string;
|
|
111
|
+
minScore?: number;
|
|
112
|
+
requireIdentity?: boolean;
|
|
113
|
+
requireActiveBond?: boolean;
|
|
114
|
+
requireMinimaHardCollateral?: boolean;
|
|
115
|
+
minBondAmount?: bigint;
|
|
116
|
+
acceptedAssets?: BondAsset[];
|
|
117
|
+
acceptedPurposes?: BondPurpose[];
|
|
118
|
+
maxIncidentSeverity?: IncidentSeverity;
|
|
119
|
+
maxHeartbeatAgeMs?: number;
|
|
120
|
+
now?: number;
|
|
121
|
+
}
|
|
122
|
+
export interface PolicyMatch {
|
|
123
|
+
providerId: string;
|
|
124
|
+
provider: ProviderBondManifest;
|
|
125
|
+
matched: boolean;
|
|
126
|
+
score?: ProviderScore;
|
|
127
|
+
reasons: string[];
|
|
128
|
+
failures: string[];
|
|
129
|
+
}
|
|
130
|
+
export interface ProviderBondRegistryState {
|
|
131
|
+
providers: Record<string, ProviderBondManifest>;
|
|
132
|
+
bondProofs: Record<string, BondProofRef[]>;
|
|
133
|
+
probes: Record<string, ProbeResult[]>;
|
|
134
|
+
incidents: Record<string, IncidentRecord[]>;
|
|
135
|
+
scores: Record<string, ProviderScore>;
|
|
136
|
+
updatedAt?: number;
|
|
137
|
+
}
|
|
138
|
+
export interface ProviderScoringWeights {
|
|
139
|
+
identity: number;
|
|
140
|
+
bond: number;
|
|
141
|
+
reliability: number;
|
|
142
|
+
incidents: number;
|
|
143
|
+
}
|
|
144
|
+
export interface ComputeProviderScoreParams {
|
|
145
|
+
provider: ProviderBondManifest;
|
|
146
|
+
bondProofs?: BondProofRef[];
|
|
147
|
+
probes?: ProbeResult[];
|
|
148
|
+
incidents?: IncidentRecord[];
|
|
149
|
+
now?: number;
|
|
150
|
+
currentHeight?: bigint;
|
|
151
|
+
weights?: ProviderScoringWeights;
|
|
152
|
+
}
|
|
153
|
+
export interface CreateProviderBondManifestParams {
|
|
154
|
+
edgeService: import('@totemsdk/manifest').EdgeServiceManifest;
|
|
155
|
+
signedEdgeService?: import('@totemsdk/manifest').SignedManifest<import('@totemsdk/manifest').EdgeServiceManifest>;
|
|
156
|
+
providerBond: ProviderBondExtension;
|
|
157
|
+
}
|
|
158
|
+
export interface VerifyProviderBondManifestParams {
|
|
159
|
+
manifest: ProviderBondManifest;
|
|
160
|
+
identityGraph?: unknown;
|
|
161
|
+
now?: number;
|
|
162
|
+
}
|
|
163
|
+
export interface BindProviderManifestToIdentityParams {
|
|
164
|
+
manifest: ProviderBondManifest;
|
|
165
|
+
identityGraph: unknown;
|
|
166
|
+
}
|
|
167
|
+
export interface VerifyProviderManifestIdentityParams {
|
|
168
|
+
manifest: ProviderBondManifest;
|
|
169
|
+
identityGraph: unknown;
|
|
170
|
+
}
|
|
171
|
+
export interface VerifyProviderBondAddressesParams {
|
|
172
|
+
manifest: ProviderBondManifest;
|
|
173
|
+
identityGraph: unknown;
|
|
174
|
+
}
|
|
175
|
+
export interface AssertProviderControlsAddressParams {
|
|
176
|
+
manifest: ProviderBondManifest;
|
|
177
|
+
address: string;
|
|
178
|
+
identityGraph: unknown;
|
|
179
|
+
}
|
|
180
|
+
export interface BondProofVerifier {
|
|
181
|
+
verify(proof: BondProofRef): Promise<ProviderBondVerifyResult>;
|
|
182
|
+
}
|
|
183
|
+
export interface VerifyBondStackParams {
|
|
184
|
+
bondStack: ProviderBondAssetDeclaration[];
|
|
185
|
+
bondProofs?: BondProofRef[];
|
|
186
|
+
verifier?: BondProofVerifier;
|
|
187
|
+
}
|
|
188
|
+
export interface RecordProbeParams {
|
|
189
|
+
providerId: string;
|
|
190
|
+
type: ProbeType;
|
|
191
|
+
ok: boolean;
|
|
192
|
+
latencyMs?: number;
|
|
193
|
+
message?: string;
|
|
194
|
+
metadata?: Record<string, unknown>;
|
|
195
|
+
now?: number;
|
|
196
|
+
}
|
|
197
|
+
export interface RecordIncidentParams {
|
|
198
|
+
providerId: string;
|
|
199
|
+
type: IncidentType;
|
|
200
|
+
severity: IncidentSeverity;
|
|
201
|
+
message?: string;
|
|
202
|
+
metadata?: Record<string, unknown>;
|
|
203
|
+
now?: number;
|
|
204
|
+
}
|
package/dist/types.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@totemsdk/provider-bond",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Provider trust layer for Totem Edge — prove, record, score and filter infrastructure providers",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"require": "./dist/index.js",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"prepare": "tsc",
|
|
17
|
+
"clean": "rm -rf dist",
|
|
18
|
+
"test": "jest --passWithNoTests"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@totemsdk/core": "^1.1.0",
|
|
27
|
+
"@totemsdk/identity": "^0.1.2",
|
|
28
|
+
"@totemsdk/manifest": "^0.1.2",
|
|
29
|
+
"@totemsdk/proof": "^0.1.1"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@noble/hashes": "^2.0.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependenciesMeta": {
|
|
35
|
+
"@noble/hashes": {
|
|
36
|
+
"optional": false
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@noble/hashes": "^2.2.0",
|
|
41
|
+
"@types/jest": "^29.5.14",
|
|
42
|
+
"@types/node": "^20.19.43",
|
|
43
|
+
"jest": "^29.7.0",
|
|
44
|
+
"ts-jest": "^29.4.11",
|
|
45
|
+
"typescript": "^5.0.0"
|
|
46
|
+
},
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=18.0.0"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"license": "MIT",
|
|
54
|
+
"author": "Totem SDK",
|
|
55
|
+
"homepage": "https://totemsdk.com",
|
|
56
|
+
"bugs": {
|
|
57
|
+
"url": "https://github.com/MrGheek/axia-totem/issues"
|
|
58
|
+
},
|
|
59
|
+
"repository": {
|
|
60
|
+
"type": "git",
|
|
61
|
+
"url": "git+https://github.com/MrGheek/axia-totem.git",
|
|
62
|
+
"directory": "packages/totem-sdk/packages/provider-bond"
|
|
63
|
+
},
|
|
64
|
+
"keywords": [
|
|
65
|
+
"totem",
|
|
66
|
+
"totemsdk",
|
|
67
|
+
"minima",
|
|
68
|
+
"blockchain",
|
|
69
|
+
"quantum-resistant",
|
|
70
|
+
"wots",
|
|
71
|
+
"provider",
|
|
72
|
+
"bond",
|
|
73
|
+
"reputation",
|
|
74
|
+
"trust"
|
|
75
|
+
]
|
|
76
|
+
}
|