@brainai/satp-client 2.0.6 → 2.0.8
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 +201 -0
- package/README.md +63 -35
- package/idls/v3/attestations_v3.json +439 -0
- package/idls/v3/escrow_v3.json +972 -0
- package/idls/v3/identity_v3.json +1344 -0
- package/idls/v3/reputation_v3.json +140 -0
- package/idls/v3/reviews_v3.json +300 -0
- package/idls/v3/validation_v3.json +146 -0
- package/package.json +12 -4
- package/src/attestation-request.js +176 -0
- package/src/index.d.ts +221 -0
- package/src/index.js +12 -1
- package/src/runtime-authorization-evidence.js +350 -0
- package/src/runtime-policy-adapter.js +335 -5
- package/examples/adoption-quickstarts.js +0 -173
- package/examples/integration-patterns.js +0 -495
- package/examples/runtime-policy-adapter.js +0 -107
- package/examples/x402-discovery-evidence-lookup.js +0 -66
- package/examples/x402-reputation-evidence-lookup-client.js +0 -182
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
const assert = require('node:assert/strict');
|
|
5
|
-
const {
|
|
6
|
-
X402_PAYMENT_IS_NOT_ACTION_AUTHORIZATION,
|
|
7
|
-
buildRuntimePolicyActionDescriptorFromX402Discovery,
|
|
8
|
-
} = require('../src');
|
|
9
|
-
|
|
10
|
-
const LOOKUP_SCHEMA_VERSION = 'satp.x402ReputationEvidenceLookup.v1';
|
|
11
|
-
|
|
12
|
-
const discoveryMetadata = {
|
|
13
|
-
schemaVersion: 'satp.x402DiscoveryMetadata.v1',
|
|
14
|
-
protocol: 'x402',
|
|
15
|
-
action: 'satp.reputationEvidence.lookup',
|
|
16
|
-
endpoint: 'https://satp-provider.example/v1/satp/evidence/reputation',
|
|
17
|
-
resource: 'satp://evidence/reputation',
|
|
18
|
-
paymentRequired: true,
|
|
19
|
-
accepts: [
|
|
20
|
-
{
|
|
21
|
-
scheme: 'exact',
|
|
22
|
-
network: '<provider-selected-payment-network>',
|
|
23
|
-
asset: '<provider-selected-asset>',
|
|
24
|
-
payTo: '<provider-controlled-recipient>',
|
|
25
|
-
maxAmountRequired: '<provider-disclosed-maximum>',
|
|
26
|
-
resource: 'https://satp-provider.example/v1/satp/evidence/reputation',
|
|
27
|
-
description: 'Read-only SATP reputation evidence lookup',
|
|
28
|
-
mimeType: 'application/json',
|
|
29
|
-
maxTimeoutSeconds: 60,
|
|
30
|
-
},
|
|
31
|
-
],
|
|
32
|
-
guardrail: X402_PAYMENT_IS_NOT_ACTION_AUTHORIZATION,
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
function buildLookupUrl(endpoint, request) {
|
|
36
|
-
const url = new URL(endpoint);
|
|
37
|
-
if (request.agentId) url.searchParams.set('agentId', request.agentId);
|
|
38
|
-
if (request.wallet) url.searchParams.set('wallet', request.wallet);
|
|
39
|
-
if (request.network) url.searchParams.set('network', request.network);
|
|
40
|
-
if (request.include) url.searchParams.set('include', request.include.join(','));
|
|
41
|
-
if (request.minEvidenceUpdatedAt) url.searchParams.set('minEvidenceUpdatedAt', request.minEvidenceUpdatedAt);
|
|
42
|
-
if (request.trace) url.searchParams.set('trace', request.trace);
|
|
43
|
-
return url;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function assertLookupBoundary(body) {
|
|
47
|
-
assert.equal(body.schemaVersion, LOOKUP_SCHEMA_VERSION);
|
|
48
|
-
assert.equal(body.policyBoundary.guardrail, X402_PAYMENT_IS_NOT_ACTION_AUTHORIZATION);
|
|
49
|
-
assert.equal(body.policyBoundary.paymentAuthorization, false);
|
|
50
|
-
assert.equal(body.policyBoundary.actionAuthorization, false);
|
|
51
|
-
assert.equal(body.policyBoundary.spendAuthorized, false);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async function fetchSatpReputationEvidence({
|
|
55
|
-
fetchImpl,
|
|
56
|
-
endpoint = discoveryMetadata.endpoint,
|
|
57
|
-
request,
|
|
58
|
-
x402PaymentHeader,
|
|
59
|
-
}) {
|
|
60
|
-
if (typeof fetchImpl !== 'function') throw new Error('fetchImpl is required for this offline example');
|
|
61
|
-
const url = buildLookupUrl(endpoint, request);
|
|
62
|
-
const response = await fetchImpl(url, {
|
|
63
|
-
method: 'GET',
|
|
64
|
-
headers: {
|
|
65
|
-
Accept: 'application/json',
|
|
66
|
-
'X-PAYMENT': x402PaymentHeader,
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
const body = await response.json();
|
|
70
|
-
assertLookupBoundary(body);
|
|
71
|
-
if (!response.ok) {
|
|
72
|
-
throw new Error(body.error && body.error.code ? body.error.code : 'satp_lookup_failed');
|
|
73
|
-
}
|
|
74
|
-
return body;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function createMockFetch() {
|
|
78
|
-
return async function mockFetch(url, options = {}) {
|
|
79
|
-
assert.equal(url.pathname, '/v1/satp/evidence/reputation');
|
|
80
|
-
assert.equal(url.searchParams.get('agentId'), 'brainChain');
|
|
81
|
-
assert.equal(options.headers.Accept, 'application/json');
|
|
82
|
-
assert.equal(options.headers['X-PAYMENT'], 'fixture-x402-payment-proof');
|
|
83
|
-
|
|
84
|
-
return {
|
|
85
|
-
ok: true,
|
|
86
|
-
async json() {
|
|
87
|
-
return {
|
|
88
|
-
schemaVersion: LOOKUP_SCHEMA_VERSION,
|
|
89
|
-
lookup: {
|
|
90
|
-
lookupId: 'lkp_fixture_brainchain_devnet_01',
|
|
91
|
-
agentId: 'brainChain',
|
|
92
|
-
wallet: '7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgBNG',
|
|
93
|
-
network: 'devnet',
|
|
94
|
-
queriedAt: '2026-07-28T03:18:00Z',
|
|
95
|
-
},
|
|
96
|
-
reputation: {
|
|
97
|
-
score: 88,
|
|
98
|
-
tier: 'trusted',
|
|
99
|
-
sourceProgram: 'reputation_v3',
|
|
100
|
-
computedAt: '2026-07-28T03:10:00Z',
|
|
101
|
-
},
|
|
102
|
-
evidence: {
|
|
103
|
-
attestations: [
|
|
104
|
-
{
|
|
105
|
-
claimType: 'github_verified',
|
|
106
|
-
issuer: 'satp-attestation-authority',
|
|
107
|
-
status: 'valid',
|
|
108
|
-
},
|
|
109
|
-
],
|
|
110
|
-
},
|
|
111
|
-
proof: {
|
|
112
|
-
source: 'satp',
|
|
113
|
-
programSet: 'v3',
|
|
114
|
-
trace: 'redacted',
|
|
115
|
-
evidenceUpdatedAt: '2026-07-28T03:10:00Z',
|
|
116
|
-
},
|
|
117
|
-
policyBoundary: {
|
|
118
|
-
paymentAuthorization: false,
|
|
119
|
-
actionAuthorization: false,
|
|
120
|
-
spendAuthorized: false,
|
|
121
|
-
livePaymentRequiredByClient: false,
|
|
122
|
-
guardrail: X402_PAYMENT_IS_NOT_ACTION_AUTHORIZATION,
|
|
123
|
-
message: 'x402 payment grants lookup access only and does not authorize SATP agent actions.',
|
|
124
|
-
},
|
|
125
|
-
};
|
|
126
|
-
},
|
|
127
|
-
};
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
async function runExample() {
|
|
132
|
-
const descriptor = buildRuntimePolicyActionDescriptorFromX402Discovery(discoveryMetadata, {
|
|
133
|
-
sourceKind: 'well-known-x402',
|
|
134
|
-
maxCostUsd: 0,
|
|
135
|
-
});
|
|
136
|
-
assert.equal(descriptor.operation, 'satp.reputationEvidence.lookup');
|
|
137
|
-
assert.equal(descriptor.paymentAuthorization, false);
|
|
138
|
-
assert.equal(descriptor.actionAuthorization, false);
|
|
139
|
-
assert.equal(descriptor.spendAuthorized, false);
|
|
140
|
-
assert.equal(descriptor.livePaymentRequired, false);
|
|
141
|
-
|
|
142
|
-
const body = await fetchSatpReputationEvidence({
|
|
143
|
-
fetchImpl: createMockFetch(),
|
|
144
|
-
request: {
|
|
145
|
-
agentId: 'brainChain',
|
|
146
|
-
network: 'devnet',
|
|
147
|
-
include: ['identity', 'reputation', 'attestations', 'policy'],
|
|
148
|
-
trace: 'redacted',
|
|
149
|
-
},
|
|
150
|
-
x402PaymentHeader: 'fixture-x402-payment-proof',
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
return {
|
|
154
|
-
endpoint: discoveryMetadata.endpoint,
|
|
155
|
-
lookupId: body.lookup.lookupId,
|
|
156
|
-
score: body.reputation.score,
|
|
157
|
-
guardrail: body.policyBoundary.guardrail,
|
|
158
|
-
paymentAuthorization: body.policyBoundary.paymentAuthorization,
|
|
159
|
-
actionAuthorization: body.policyBoundary.actionAuthorization,
|
|
160
|
-
spendAuthorized: body.policyBoundary.spendAuthorized,
|
|
161
|
-
livePaymentRequired: descriptor.livePaymentRequired,
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if (require.main === module) {
|
|
166
|
-
runExample()
|
|
167
|
-
.then((result) => console.log(JSON.stringify(result, null, 2)))
|
|
168
|
-
.catch((err) => {
|
|
169
|
-
console.error(err.message);
|
|
170
|
-
process.exitCode = 1;
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
module.exports = {
|
|
175
|
-
LOOKUP_SCHEMA_VERSION,
|
|
176
|
-
discoveryMetadata,
|
|
177
|
-
buildLookupUrl,
|
|
178
|
-
assertLookupBoundary,
|
|
179
|
-
fetchSatpReputationEvidence,
|
|
180
|
-
createMockFetch,
|
|
181
|
-
runExample,
|
|
182
|
-
};
|