@claw-network/node 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/README.md +49 -0
- package/dist/api/api-key-store.d.ts +74 -0
- package/dist/api/api-key-store.d.ts.map +1 -0
- package/dist/api/api-key-store.js +170 -0
- package/dist/api/api-key-store.js.map +1 -0
- package/dist/api/auth.d.ts +30 -0
- package/dist/api/auth.d.ts.map +1 -0
- package/dist/api/auth.js +115 -0
- package/dist/api/auth.js.map +1 -0
- package/dist/api/legacy.d.ts +26 -0
- package/dist/api/legacy.d.ts.map +1 -0
- package/dist/api/legacy.js +281 -0
- package/dist/api/legacy.js.map +1 -0
- package/dist/api/middleware.d.ts +35 -0
- package/dist/api/middleware.d.ts.map +1 -0
- package/dist/api/middleware.js +75 -0
- package/dist/api/middleware.js.map +1 -0
- package/dist/api/response.d.ts +85 -0
- package/dist/api/response.d.ts.map +1 -0
- package/dist/api/response.js +185 -0
- package/dist/api/response.js.map +1 -0
- package/dist/api/router.d.ts +45 -0
- package/dist/api/router.d.ts.map +1 -0
- package/dist/api/router.js +183 -0
- package/dist/api/router.js.map +1 -0
- package/dist/api/routes/admin.d.ts +11 -0
- package/dist/api/routes/admin.d.ts.map +1 -0
- package/dist/api/routes/admin.js +124 -0
- package/dist/api/routes/admin.js.map +1 -0
- package/dist/api/routes/contracts.d.ts +7 -0
- package/dist/api/routes/contracts.d.ts.map +1 -0
- package/dist/api/routes/contracts.js +665 -0
- package/dist/api/routes/contracts.js.map +1 -0
- package/dist/api/routes/dao.d.ts +7 -0
- package/dist/api/routes/dao.d.ts.map +1 -0
- package/dist/api/routes/dao.js +549 -0
- package/dist/api/routes/dao.js.map +1 -0
- package/dist/api/routes/dev.d.ts +9 -0
- package/dist/api/routes/dev.d.ts.map +1 -0
- package/dist/api/routes/dev.js +273 -0
- package/dist/api/routes/dev.js.map +1 -0
- package/dist/api/routes/escrows.d.ts +7 -0
- package/dist/api/routes/escrows.d.ts.map +1 -0
- package/dist/api/routes/escrows.js +454 -0
- package/dist/api/routes/escrows.js.map +1 -0
- package/dist/api/routes/identities.d.ts +7 -0
- package/dist/api/routes/identities.d.ts.map +1 -0
- package/dist/api/routes/identities.js +245 -0
- package/dist/api/routes/identities.js.map +1 -0
- package/dist/api/routes/markets-capabilities.d.ts +7 -0
- package/dist/api/routes/markets-capabilities.d.ts.map +1 -0
- package/dist/api/routes/markets-capabilities.js +477 -0
- package/dist/api/routes/markets-capabilities.js.map +1 -0
- package/dist/api/routes/markets-disputes.d.ts +7 -0
- package/dist/api/routes/markets-disputes.d.ts.map +1 -0
- package/dist/api/routes/markets-disputes.js +102 -0
- package/dist/api/routes/markets-disputes.js.map +1 -0
- package/dist/api/routes/markets-info.d.ts +7 -0
- package/dist/api/routes/markets-info.d.ts.map +1 -0
- package/dist/api/routes/markets-info.js +523 -0
- package/dist/api/routes/markets-info.js.map +1 -0
- package/dist/api/routes/markets-search.d.ts +7 -0
- package/dist/api/routes/markets-search.d.ts.map +1 -0
- package/dist/api/routes/markets-search.js +38 -0
- package/dist/api/routes/markets-search.js.map +1 -0
- package/dist/api/routes/markets-tasks.d.ts +7 -0
- package/dist/api/routes/markets-tasks.d.ts.map +1 -0
- package/dist/api/routes/markets-tasks.js +539 -0
- package/dist/api/routes/markets-tasks.js.map +1 -0
- package/dist/api/routes/node.d.ts +7 -0
- package/dist/api/routes/node.d.ts.map +1 -0
- package/dist/api/routes/node.js +53 -0
- package/dist/api/routes/node.js.map +1 -0
- package/dist/api/routes/nonce.d.ts +10 -0
- package/dist/api/routes/nonce.d.ts.map +1 -0
- package/dist/api/routes/nonce.js +65 -0
- package/dist/api/routes/nonce.js.map +1 -0
- package/dist/api/routes/reputations.d.ts +7 -0
- package/dist/api/routes/reputations.d.ts.map +1 -0
- package/dist/api/routes/reputations.js +243 -0
- package/dist/api/routes/reputations.js.map +1 -0
- package/dist/api/routes/transfers.d.ts +7 -0
- package/dist/api/routes/transfers.d.ts.map +1 -0
- package/dist/api/routes/transfers.js +88 -0
- package/dist/api/routes/transfers.js.map +1 -0
- package/dist/api/routes/wallets.d.ts +7 -0
- package/dist/api/routes/wallets.d.ts.map +1 -0
- package/dist/api/routes/wallets.js +132 -0
- package/dist/api/routes/wallets.js.map +1 -0
- package/dist/api/schemas/common.d.ts +45 -0
- package/dist/api/schemas/common.d.ts.map +1 -0
- package/dist/api/schemas/common.js +30 -0
- package/dist/api/schemas/common.js.map +1 -0
- package/dist/api/schemas/contracts.d.ts +284 -0
- package/dist/api/schemas/contracts.d.ts.map +1 -0
- package/dist/api/schemas/contracts.js +79 -0
- package/dist/api/schemas/contracts.js.map +1 -0
- package/dist/api/schemas/dao.d.ts +271 -0
- package/dist/api/schemas/dao.d.ts.map +1 -0
- package/dist/api/schemas/dao.js +78 -0
- package/dist/api/schemas/dao.js.map +1 -0
- package/dist/api/schemas/identity.d.ts +75 -0
- package/dist/api/schemas/identity.d.ts.map +1 -0
- package/dist/api/schemas/identity.js +32 -0
- package/dist/api/schemas/identity.js.map +1 -0
- package/dist/api/schemas/markets.d.ts +822 -0
- package/dist/api/schemas/markets.d.ts.map +1 -0
- package/dist/api/schemas/markets.js +246 -0
- package/dist/api/schemas/markets.js.map +1 -0
- package/dist/api/schemas/wallet.d.ts +163 -0
- package/dist/api/schemas/wallet.d.ts.map +1 -0
- package/dist/api/schemas/wallet.js +54 -0
- package/dist/api/schemas/wallet.js.map +1 -0
- package/dist/api/server.d.ts +45 -0
- package/dist/api/server.d.ts.map +1 -0
- package/dist/api/server.js +131 -0
- package/dist/api/server.js.map +1 -0
- package/dist/api/types.d.ts +69 -0
- package/dist/api/types.d.ts.map +1 -0
- package/dist/api/types.js +196 -0
- package/dist/api/types.js.map +1 -0
- package/dist/daemon.d.ts +11 -0
- package/dist/daemon.d.ts.map +1 -0
- package/dist/daemon.js +248 -0
- package/dist/daemon.js.map +1 -0
- package/dist/index.d.ts +137 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +795 -0
- package/dist/index.js.map +1 -0
- package/dist/indexer/index.d.ts +10 -0
- package/dist/indexer/index.d.ts.map +1 -0
- package/dist/indexer/index.js +7 -0
- package/dist/indexer/index.js.map +1 -0
- package/dist/indexer/indexer.d.ts +60 -0
- package/dist/indexer/indexer.d.ts.map +1 -0
- package/dist/indexer/indexer.js +408 -0
- package/dist/indexer/indexer.js.map +1 -0
- package/dist/indexer/query.d.ts +141 -0
- package/dist/indexer/query.d.ts.map +1 -0
- package/dist/indexer/query.js +244 -0
- package/dist/indexer/query.js.map +1 -0
- package/dist/indexer/store.d.ts +95 -0
- package/dist/indexer/store.d.ts.map +1 -0
- package/dist/indexer/store.js +250 -0
- package/dist/indexer/store.js.map +1 -0
- package/dist/logger.d.ts +13 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +37 -0
- package/dist/logger.js.map +1 -0
- package/dist/p2p/sync.d.ts +105 -0
- package/dist/p2p/sync.d.ts.map +1 -0
- package/dist/p2p/sync.js +875 -0
- package/dist/p2p/sync.js.map +1 -0
- package/dist/policy/liquidity-policy.d.ts +17 -0
- package/dist/policy/liquidity-policy.d.ts.map +1 -0
- package/dist/policy/liquidity-policy.js +112 -0
- package/dist/policy/liquidity-policy.js.map +1 -0
- package/dist/services/chain-config.d.ts +226 -0
- package/dist/services/chain-config.d.ts.map +1 -0
- package/dist/services/chain-config.js +105 -0
- package/dist/services/chain-config.js.map +1 -0
- package/dist/services/contract-provider.d.ts +44 -0
- package/dist/services/contract-provider.d.ts.map +1 -0
- package/dist/services/contract-provider.js +167 -0
- package/dist/services/contract-provider.js.map +1 -0
- package/dist/services/contracts-service.d.ts +192 -0
- package/dist/services/contracts-service.d.ts.map +1 -0
- package/dist/services/contracts-service.js +336 -0
- package/dist/services/contracts-service.js.map +1 -0
- package/dist/services/dao-service.d.ts +245 -0
- package/dist/services/dao-service.d.ts.map +1 -0
- package/dist/services/dao-service.js +389 -0
- package/dist/services/dao-service.js.map +1 -0
- package/dist/services/identity-service.d.ts +150 -0
- package/dist/services/identity-service.d.ts.map +1 -0
- package/dist/services/identity-service.js +286 -0
- package/dist/services/identity-service.js.map +1 -0
- package/dist/services/index.d.ts +20 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +15 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/reputation-service.d.ts +128 -0
- package/dist/services/reputation-service.d.ts.map +1 -0
- package/dist/services/reputation-service.js +204 -0
- package/dist/services/reputation-service.js.map +1 -0
- package/dist/services/wallet-service.d.ts +201 -0
- package/dist/services/wallet-service.d.ts.map +1 -0
- package/dist/services/wallet-service.js +402 -0
- package/dist/services/wallet-service.js.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IdentityService — on-chain identity operations for ClawIdentity.
|
|
3
|
+
*
|
|
4
|
+
* This service is the single point of truth for all DID write/read
|
|
5
|
+
* operations that hit the chain. API route handlers delegate to it;
|
|
6
|
+
* it calls the ClawIdentity smart contract via ContractProvider and
|
|
7
|
+
* reads cached DID data from IndexerQuery when available.
|
|
8
|
+
*
|
|
9
|
+
* Design decisions:
|
|
10
|
+
* - DID string → bytes32 hash via `keccak256(toUtf8Bytes(did))`.
|
|
11
|
+
* - Ed25519 public keys are 32-byte `Uint8Array`/hex strings.
|
|
12
|
+
* - `rotationProof` is accepted but NOT verified on-chain in the
|
|
13
|
+
* current contract version (deferred to Phase 2 T-0.14).
|
|
14
|
+
* - Capability CRUD stays off-chain (P2P / event store); this
|
|
15
|
+
* service covers only registerDID / rotateKey / revokeDID /
|
|
16
|
+
* addPlatformLink and their view counterparts.
|
|
17
|
+
*/
|
|
18
|
+
import { getBytes, keccak256, solidityPacked, toUtf8Bytes } from 'ethers';
|
|
19
|
+
import { createLogger } from '../logger.js';
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// Utilities
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
/**
|
|
24
|
+
* Derive a unique, deterministic EVM address for a DID.
|
|
25
|
+
*
|
|
26
|
+
* The address is a pseudo-address (no one holds its private key) used
|
|
27
|
+
* solely as a balance-holding account on the ERC-20 token contract.
|
|
28
|
+
* Token operations (mint / burn) are executed by the node signer which
|
|
29
|
+
* holds MINTER_ROLE and BURNER_ROLE.
|
|
30
|
+
*
|
|
31
|
+
* Formula: `'0x' + keccak256("clawnet:did-address:" + did)[last 20 bytes]`
|
|
32
|
+
*/
|
|
33
|
+
export function deriveAddressForDid(did) {
|
|
34
|
+
const hash = keccak256(toUtf8Bytes('clawnet:did-address:' + did));
|
|
35
|
+
// Take last 20 bytes (40 hex chars) of the 32-byte hash
|
|
36
|
+
return '0x' + hash.slice(26);
|
|
37
|
+
}
|
|
38
|
+
const KEY_PURPOSE_MAP = {
|
|
39
|
+
authentication: 0,
|
|
40
|
+
assertion: 1,
|
|
41
|
+
keyAgreement: 2,
|
|
42
|
+
recovery: 3,
|
|
43
|
+
};
|
|
44
|
+
const KEY_PURPOSE_REVERSE = {
|
|
45
|
+
0: 'authentication',
|
|
46
|
+
1: 'assertion',
|
|
47
|
+
2: 'keyAgreement',
|
|
48
|
+
3: 'recovery',
|
|
49
|
+
};
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
// IdentityService
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
export class IdentityService {
|
|
54
|
+
contracts;
|
|
55
|
+
indexer;
|
|
56
|
+
log;
|
|
57
|
+
constructor(contracts, indexer, logger) {
|
|
58
|
+
this.contracts = contracts;
|
|
59
|
+
this.indexer = indexer;
|
|
60
|
+
this.log = logger ?? createLogger({ level: 'info' });
|
|
61
|
+
}
|
|
62
|
+
// ========================================================================
|
|
63
|
+
// READ operations
|
|
64
|
+
// ========================================================================
|
|
65
|
+
/**
|
|
66
|
+
* Resolve a DID to its full on-chain document.
|
|
67
|
+
*
|
|
68
|
+
* Reads the DIDRecord + active KeyRecord + platform links from the
|
|
69
|
+
* ClawIdentity contract.
|
|
70
|
+
*
|
|
71
|
+
* @returns The DID document, or `null` if not registered.
|
|
72
|
+
*/
|
|
73
|
+
async resolve(did) {
|
|
74
|
+
const didHash = this.hashDid(did);
|
|
75
|
+
const identity = this.contracts.identity;
|
|
76
|
+
try {
|
|
77
|
+
const active = await identity.isActive(didHash);
|
|
78
|
+
const controller = await identity.getController(didHash);
|
|
79
|
+
if (controller === '0x0000000000000000000000000000000000000000') {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
const publicKeyBytes = await identity.getActiveKey(didHash);
|
|
83
|
+
const activeKeyHash = keccak256(getBytes(publicKeyBytes));
|
|
84
|
+
// Get key record for purpose
|
|
85
|
+
const keyRecord = await identity.getKeyRecord(didHash, activeKeyHash);
|
|
86
|
+
const purpose = KEY_PURPOSE_REVERSE[Number(keyRecord.purpose)] ?? 'authentication';
|
|
87
|
+
// DID record for timestamps
|
|
88
|
+
const didRecord = await identity.dids(didHash);
|
|
89
|
+
const createdAt = Number(didRecord.createdAt);
|
|
90
|
+
const updatedAt = Number(didRecord.updatedAt);
|
|
91
|
+
// Platform links
|
|
92
|
+
const linkHashes = await identity.getPlatformLinks(didHash);
|
|
93
|
+
return {
|
|
94
|
+
did,
|
|
95
|
+
didHash,
|
|
96
|
+
controller,
|
|
97
|
+
publicKey: publicKeyBytes,
|
|
98
|
+
keyPurpose: purpose,
|
|
99
|
+
isActive: active,
|
|
100
|
+
createdAt,
|
|
101
|
+
updatedAt,
|
|
102
|
+
platformLinks: linkHashes,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Get the controller EVM address for a DID.
|
|
111
|
+
*
|
|
112
|
+
* @returns The controller address, or `null` if not registered.
|
|
113
|
+
*/
|
|
114
|
+
async getController(did) {
|
|
115
|
+
const didHash = this.hashDid(did);
|
|
116
|
+
try {
|
|
117
|
+
const controller = await this.contracts.identity.getController(didHash);
|
|
118
|
+
if (controller === '0x0000000000000000000000000000000000000000') {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
return controller;
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Check if a DID is active on-chain.
|
|
129
|
+
*/
|
|
130
|
+
async isActive(did) {
|
|
131
|
+
const didHash = this.hashDid(did);
|
|
132
|
+
try {
|
|
133
|
+
return await this.contracts.identity.isActive(didHash);
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Resolve a DID from the indexer cache (faster, eventually consistent).
|
|
141
|
+
*
|
|
142
|
+
* @returns Cached DID record or `null`.
|
|
143
|
+
*/
|
|
144
|
+
getCachedDid(did) {
|
|
145
|
+
if (!this.indexer)
|
|
146
|
+
return null;
|
|
147
|
+
const didHash = this.hashDid(did);
|
|
148
|
+
return this.indexer.getDid(didHash);
|
|
149
|
+
}
|
|
150
|
+
// ========================================================================
|
|
151
|
+
// WRITE operations
|
|
152
|
+
// ========================================================================
|
|
153
|
+
/**
|
|
154
|
+
* Register a new DID on-chain.
|
|
155
|
+
*
|
|
156
|
+
* @param did Full DID string (`did:claw:z6Mk...`)
|
|
157
|
+
* @param publicKey Ed25519 public key (32 bytes, hex-encoded with `0x` prefix)
|
|
158
|
+
* @param purpose Key purpose (default: `authentication`)
|
|
159
|
+
* @param evmAddress EVM address for cross-reference (default: signer address)
|
|
160
|
+
*/
|
|
161
|
+
async registerDID(did, publicKey, purpose = 'authentication', evmAddress) {
|
|
162
|
+
const didHash = this.hashDid(did);
|
|
163
|
+
const purposeNum = KEY_PURPOSE_MAP[purpose];
|
|
164
|
+
const evmAddr = evmAddress ?? '0x0000000000000000000000000000000000000000';
|
|
165
|
+
// Contract defaults controller to msg.sender when evmAddress is zero
|
|
166
|
+
const controller = evmAddr === '0x0000000000000000000000000000000000000000'
|
|
167
|
+
? this.contracts.signerAddress
|
|
168
|
+
: evmAddr;
|
|
169
|
+
this.log.info('Identity register: %s (purpose=%s)', did, purpose);
|
|
170
|
+
// H-01: sign registration digest for on-chain verification
|
|
171
|
+
const message = solidityPacked(['string', 'bytes32', 'address'], ['clawnet:register:v1:', didHash, controller]);
|
|
172
|
+
const digest = keccak256(message);
|
|
173
|
+
const evmSig = await this.contracts.signer.signMessage(getBytes(digest));
|
|
174
|
+
const tx = await this.contracts.identity.registerDID(didHash, publicKey, purposeNum, evmAddr, evmSig);
|
|
175
|
+
const receipt = await tx.wait();
|
|
176
|
+
return {
|
|
177
|
+
txHash: receipt.hash,
|
|
178
|
+
did,
|
|
179
|
+
controller,
|
|
180
|
+
timestamp: Date.now(),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Rotate the active key for a DID.
|
|
185
|
+
*
|
|
186
|
+
* @param did Full DID string
|
|
187
|
+
* @param newPublicKey New Ed25519 public key (hex, 32 bytes)
|
|
188
|
+
* @param rotationProof Signature proof from old key (hex).
|
|
189
|
+
* Not verified on-chain in current contract version.
|
|
190
|
+
*/
|
|
191
|
+
async rotateKey(did, newPublicKey, rotationProof = '0x') {
|
|
192
|
+
const didHash = this.hashDid(did);
|
|
193
|
+
this.log.info('Identity rotate key: %s', did);
|
|
194
|
+
const tx = await this.contracts.identity.rotateKey(didHash, newPublicKey, rotationProof);
|
|
195
|
+
const receipt = await tx.wait();
|
|
196
|
+
// Extract old/new key hashes from the KeyRotated event
|
|
197
|
+
let oldKeyHash = '';
|
|
198
|
+
let newKeyHash = '';
|
|
199
|
+
for (const log of receipt.logs) {
|
|
200
|
+
try {
|
|
201
|
+
const parsed = this.contracts.identity.interface.parseLog({
|
|
202
|
+
topics: log.topics,
|
|
203
|
+
data: log.data,
|
|
204
|
+
});
|
|
205
|
+
if (parsed?.name === 'KeyRotated') {
|
|
206
|
+
oldKeyHash = parsed.args[1];
|
|
207
|
+
newKeyHash = parsed.args[2];
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
// Not our event — skip.
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
txHash: receipt.hash,
|
|
217
|
+
did,
|
|
218
|
+
oldKeyHash,
|
|
219
|
+
newKeyHash,
|
|
220
|
+
timestamp: Date.now(),
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Permanently revoke a DID. This cannot be undone.
|
|
225
|
+
*/
|
|
226
|
+
async revokeDID(did) {
|
|
227
|
+
const didHash = this.hashDid(did);
|
|
228
|
+
this.log.info('Identity revoke: %s', did);
|
|
229
|
+
const tx = await this.contracts.identity.revokeDID(didHash);
|
|
230
|
+
const receipt = await tx.wait();
|
|
231
|
+
return {
|
|
232
|
+
txHash: receipt.hash,
|
|
233
|
+
did,
|
|
234
|
+
timestamp: Date.now(),
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Anchor a platform link hash to a DID on-chain.
|
|
239
|
+
*/
|
|
240
|
+
async addPlatformLink(did, linkHash) {
|
|
241
|
+
const didHash = this.hashDid(did);
|
|
242
|
+
this.log.info('Identity add platform link: %s', did);
|
|
243
|
+
const tx = await this.contracts.identity.addPlatformLink(didHash, linkHash);
|
|
244
|
+
const receipt = await tx.wait();
|
|
245
|
+
return {
|
|
246
|
+
txHash: receipt.hash,
|
|
247
|
+
did,
|
|
248
|
+
linkHash,
|
|
249
|
+
timestamp: Date.now(),
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
// ========================================================================
|
|
253
|
+
// Helpers
|
|
254
|
+
// ========================================================================
|
|
255
|
+
/**
|
|
256
|
+
* Ensure a DID is registered on-chain. If already registered, returns
|
|
257
|
+
* the existing controller. If not, auto-registers via `batchRegisterDID`
|
|
258
|
+
* (REGISTRAR_ROLE — no ECDSA signature needed) with a **unique derived
|
|
259
|
+
* address** as controller so each DID has its own balance slot.
|
|
260
|
+
*
|
|
261
|
+
* @param did Full DID string (`did:claw:z...`)
|
|
262
|
+
* @param publicKey Ed25519 public key (32 bytes, hex 0x-prefixed)
|
|
263
|
+
* @returns The controller (EVM) address (unique per DID).
|
|
264
|
+
*/
|
|
265
|
+
async ensureRegistered(did, publicKey) {
|
|
266
|
+
// Check if already registered
|
|
267
|
+
const existing = await this.getController(did);
|
|
268
|
+
if (existing)
|
|
269
|
+
return existing;
|
|
270
|
+
const didHash = this.hashDid(did);
|
|
271
|
+
const controller = deriveAddressForDid(did);
|
|
272
|
+
this.log.info('Identity auto-register (batchRegisterDID): %s → %s', did, controller);
|
|
273
|
+
const tx = await this.contracts.identity.batchRegisterDID([didHash], [publicKey], [KEY_PURPOSE_MAP.authentication], [controller]);
|
|
274
|
+
await tx.wait();
|
|
275
|
+
return controller;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Hash a DID string to bytes32 for on-chain use.
|
|
279
|
+
*
|
|
280
|
+
* Uses keccak256(toUtf8Bytes(did)) — consistent with WalletService.
|
|
281
|
+
*/
|
|
282
|
+
hashDid(did) {
|
|
283
|
+
return keccak256(toUtf8Bytes(did));
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
//# sourceMappingURL=identity-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity-service.js","sourceRoot":"","sources":["../../src/services/identity-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAE1E,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAI5C,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E;;;;;;;;;GASG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAW;IAC7C,MAAM,I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
|
4
|
+
* Re-exports the chain configuration schema and the ContractProvider —
|
|
5
|
+
* the foundational building blocks on which individual module services
|
|
6
|
+
* (WalletService, IdentityService, …) will be built in later phases.
|
|
7
|
+
*/
|
|
8
|
+
export { ChainConfigSchema, ContractAddressesSchema, SignerConfigSchema, parseDeploymentAddresses, CONTRACT_NAMES, CONTRACT_KEYS, type ChainConfig, type ContractAddresses, type ContractKey, type SignerConfig, } from './chain-config.js';
|
|
9
|
+
export { ContractProvider } from './contract-provider.js';
|
|
10
|
+
export { WalletService } from './wallet-service.js';
|
|
11
|
+
export type { TransferResult, BalanceResult, EscrowView, EscrowActionResult, EscrowCreateResult, TransactionHistoryResult, } from './wallet-service.js';
|
|
12
|
+
export { IdentityService } from './identity-service.js';
|
|
13
|
+
export type { KeyPurpose, DIDRegistrationResult, KeyRotationResult, DIDRevocationResult, PlatformLinkResult, DIDDocument, } from './identity-service.js';
|
|
14
|
+
export { ReputationService } from './reputation-service.js';
|
|
15
|
+
export type { ReputationDimensionName, ReputationProfile, ReviewRecordResult, AnchorResult, ReviewListResult, ReviewItem, } from './reputation-service.js';
|
|
16
|
+
export { ContractsService } from './contracts-service.js';
|
|
17
|
+
export type { ContractStatus, MilestoneStatus, DisputeResolution, ServiceContractView, MilestoneView, ContractCreateResult, ContractTxResult, MilestoneTxResult, ContractListResult, ServiceContractListItem, } from './contracts-service.js';
|
|
18
|
+
export { DaoService } from './dao-service.js';
|
|
19
|
+
export type { ProposalType, ProposalStatus, VoteSupport, ProposalView, VoteReceipt, VotingPowerResult, ProposalCreateResult, ProposalTxResult, VoteCastResult, TreasuryView, TreasuryDepositResult, GovParam, GovParamsResult, ProposalListResult, VoteListResult, } from './dao-service.js';
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,iBAAiB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
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service layer barrel exports.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the chain configuration schema and the ContractProvider —
|
|
5
|
+
* the foundational building blocks on which individual module services
|
|
6
|
+
* (WalletService, IdentityService, …) will be built in later phases.
|
|
7
|
+
*/
|
|
8
|
+
export { ChainConfigSchema, ContractAddressesSchema, SignerConfigSchema, parseDeploymentAddresses, CONTRACT_NAMES, CONTRACT_KEYS, } from './chain-config.js';
|
|
9
|
+
export { ContractProvider } from './contract-provider.js';
|
|
10
|
+
export { WalletService } from './wallet-service.js';
|
|
11
|
+
export { IdentityService } from './identity-service.js';
|
|
12
|
+
export { ReputationService } from './reputation-service.js';
|
|
13
|
+
export { ContractsService } from './contracts-service.js';
|
|
14
|
+
export { DaoService } from './dao-service.js';
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,kBAAkB,EAClB,wBAAwB,EACxB,cAAc,EACd,aAAa,GAKd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAUpD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAUxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAU5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAc1D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ReputationService — on-chain reputation operations for ClawReputation.
|
|
3
|
+
*
|
|
4
|
+
* This service handles all reputation write/read operations that hit the
|
|
5
|
+
* chain. Route handlers delegate to it; it calls ClawReputation.sol via
|
|
6
|
+
* ContractProvider and reads indexed review data from IndexerQuery.
|
|
7
|
+
*
|
|
8
|
+
* Design decisions:
|
|
9
|
+
* - DID → bytes32 hash via `keccak256(toUtf8Bytes(did))`.
|
|
10
|
+
* - Review hash is `keccak256(toUtf8Bytes(reviewId))` where
|
|
11
|
+
* `reviewId` is the opaque identifier from the REST layer.
|
|
12
|
+
* - `anchorReputation` requires ANCHOR_ROLE — the node signer
|
|
13
|
+
* must hold that role on the contract.
|
|
14
|
+
* - `recordReview` also requires ANCHOR_ROLE.
|
|
15
|
+
* - Scores are uint16, max 1000 (contract-enforced).
|
|
16
|
+
*/
|
|
17
|
+
import { createLogger } from '../logger.js';
|
|
18
|
+
import type { ContractProvider } from './contract-provider.js';
|
|
19
|
+
import type { IndexerQuery } from '../indexer/query.js';
|
|
20
|
+
type Logger = ReturnType<typeof createLogger>;
|
|
21
|
+
export type ReputationDimensionName = 'transaction' | 'fulfillment' | 'quality' | 'social' | 'behavior';
|
|
22
|
+
export interface ReputationProfile {
|
|
23
|
+
did: string;
|
|
24
|
+
score: number;
|
|
25
|
+
epoch: number;
|
|
26
|
+
dimensions: {
|
|
27
|
+
transaction: number;
|
|
28
|
+
fulfillment: number;
|
|
29
|
+
quality: number;
|
|
30
|
+
social: number;
|
|
31
|
+
behavior: number;
|
|
32
|
+
};
|
|
33
|
+
merkleRoot: string;
|
|
34
|
+
timestamp: number;
|
|
35
|
+
}
|
|
36
|
+
export interface ReviewRecordResult {
|
|
37
|
+
txHash: string;
|
|
38
|
+
reviewHash: string;
|
|
39
|
+
subjectDid: string;
|
|
40
|
+
reviewerDid: string;
|
|
41
|
+
timestamp: number;
|
|
42
|
+
}
|
|
43
|
+
export interface AnchorResult {
|
|
44
|
+
txHash: string;
|
|
45
|
+
did: string;
|
|
46
|
+
overallScore: number;
|
|
47
|
+
epoch: number;
|
|
48
|
+
timestamp: number;
|
|
49
|
+
}
|
|
50
|
+
export interface ReviewListResult {
|
|
51
|
+
reviews: ReviewItem[];
|
|
52
|
+
total: number;
|
|
53
|
+
pagination: {
|
|
54
|
+
limit: number;
|
|
55
|
+
offset: number;
|
|
56
|
+
hasMore: boolean;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export interface ReviewItem {
|
|
60
|
+
reviewHash: string;
|
|
61
|
+
reviewerDid: string;
|
|
62
|
+
subjectDid: string;
|
|
63
|
+
relatedTxHash: string;
|
|
64
|
+
timestamp: number;
|
|
65
|
+
}
|
|
66
|
+
export declare class ReputationService {
|
|
67
|
+
private readonly contracts;
|
|
68
|
+
private readonly indexer?;
|
|
69
|
+
private readonly log;
|
|
70
|
+
constructor(contracts: ContractProvider, indexer?: IndexerQuery | undefined, logger?: Logger);
|
|
71
|
+
/**
|
|
72
|
+
* Fetch an agent's on-chain reputation profile.
|
|
73
|
+
*
|
|
74
|
+
* Reads `getReputation()` for the top-level score and epoch, then
|
|
75
|
+
* `getLatestSnapshot()` for dimensional scores and merkle root.
|
|
76
|
+
*
|
|
77
|
+
* @returns Profile, or `null` if DID has no reputation on-chain.
|
|
78
|
+
*/
|
|
79
|
+
getProfile(did: string): Promise<ReputationProfile | null>;
|
|
80
|
+
/**
|
|
81
|
+
* Get reviews for a DID from the indexer.
|
|
82
|
+
*
|
|
83
|
+
* @param subjectDid The DID whose reviews to fetch.
|
|
84
|
+
* @param opts Pagination options.
|
|
85
|
+
*/
|
|
86
|
+
getReviews(subjectDid: string, opts?: {
|
|
87
|
+
limit?: number;
|
|
88
|
+
offset?: number;
|
|
89
|
+
}): ReviewListResult | null;
|
|
90
|
+
/**
|
|
91
|
+
* Verify a review anchor on-chain.
|
|
92
|
+
*/
|
|
93
|
+
verifyReview(reviewId: string): Promise<{
|
|
94
|
+
reviewerDid: string;
|
|
95
|
+
subjectDid: string;
|
|
96
|
+
txHash: string;
|
|
97
|
+
timestamp: number;
|
|
98
|
+
exists: boolean;
|
|
99
|
+
} | null>;
|
|
100
|
+
/**
|
|
101
|
+
* Record a review on-chain.
|
|
102
|
+
*
|
|
103
|
+
* The node signer must have ANCHOR_ROLE on ClawReputation.
|
|
104
|
+
*
|
|
105
|
+
* @param reviewId Opaque review identifier (hashed to bytes32).
|
|
106
|
+
* @param reviewerDid Reviewer's full DID string.
|
|
107
|
+
* @param subjectDid Subject's full DID string.
|
|
108
|
+
* @param relatedTxHash Associated transaction hash (bytes32).
|
|
109
|
+
*/
|
|
110
|
+
recordReview(reviewId: string, reviewerDid: string, subjectDid: string, relatedTxHash: string): Promise<ReviewRecordResult>;
|
|
111
|
+
/**
|
|
112
|
+
* Anchor a reputation snapshot on-chain.
|
|
113
|
+
*
|
|
114
|
+
* The node signer must have ANCHOR_ROLE on ClawReputation.
|
|
115
|
+
*
|
|
116
|
+
* @param did Agent's full DID string.
|
|
117
|
+
* @param overallScore 0–1000.
|
|
118
|
+
* @param dimensionScores [transaction, fulfillment, quality, social, behavior] — each 0–1000.
|
|
119
|
+
* @param merkleRoot Merkle root of all reviews in this epoch.
|
|
120
|
+
*/
|
|
121
|
+
anchorReputation(did: string, overallScore: number, dimensionScores: [number, number, number, number, number], merkleRoot: string): Promise<AnchorResult>;
|
|
122
|
+
/** Hash a DID string to bytes32. */
|
|
123
|
+
private hashDid;
|
|
124
|
+
/** Hash an opaque identifier string to bytes32. */
|
|
125
|
+
private hashId;
|
|
126
|
+
}
|
|
127
|
+
export {};
|
|
128
|
+
//# sourceMappingURL=reputation-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reputation-service.d.ts","sourceRoot":"","sources":["../../src/services/reputation-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAgB,MAAM,qBAA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