@orbitmem/sdk 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/README.md +104 -0
- package/dist/agent/agent-adapter.d.ts +3 -0
- package/dist/agent/agent-adapter.d.ts.map +1 -0
- package/dist/agent/agent-adapter.js +3 -0
- package/dist/agent/agent-adapter.js.map +1 -0
- package/dist/agent/client.d.ts +5 -0
- package/dist/agent/client.d.ts.map +1 -0
- package/dist/agent/client.js +146 -0
- package/dist/agent/client.js.map +1 -0
- package/dist/agent/index.d.ts +2 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +2 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/client.d.ts +3 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +118 -0
- package/dist/client.js.map +1 -0
- package/dist/contracts.d.ts +19 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +28 -0
- package/dist/contracts.js.map +1 -0
- package/dist/data/index.d.ts +5 -0
- package/dist/data/index.d.ts.map +1 -0
- package/dist/data/index.js +5 -0
- package/dist/data/index.js.map +1 -0
- package/dist/data/orbitdb.d.ts +10 -0
- package/dist/data/orbitdb.d.ts.map +1 -0
- package/dist/data/orbitdb.js +39 -0
- package/dist/data/orbitdb.js.map +1 -0
- package/dist/data/pricing.d.ts +7 -0
- package/dist/data/pricing.d.ts.map +1 -0
- package/dist/data/pricing.js +55 -0
- package/dist/data/pricing.js.map +1 -0
- package/dist/data/serialization.d.ts +28 -0
- package/dist/data/serialization.d.ts.map +1 -0
- package/dist/data/serialization.js +76 -0
- package/dist/data/serialization.js.map +1 -0
- package/dist/data/vault.d.ts +21 -0
- package/dist/data/vault.d.ts.map +1 -0
- package/dist/data/vault.js +284 -0
- package/dist/data/vault.js.map +1 -0
- package/dist/discovery/discovery-layer.d.ts +3 -0
- package/dist/discovery/discovery-layer.d.ts.map +1 -0
- package/dist/discovery/discovery-layer.js +205 -0
- package/dist/discovery/discovery-layer.js.map +1 -0
- package/dist/discovery/index.d.ts +4 -0
- package/dist/discovery/index.d.ts.map +1 -0
- package/dist/discovery/index.js +4 -0
- package/dist/discovery/index.js.map +1 -0
- package/dist/discovery/mock-registry.d.ts +30 -0
- package/dist/discovery/mock-registry.d.ts.map +1 -0
- package/dist/discovery/mock-registry.js +71 -0
- package/dist/discovery/mock-registry.js.map +1 -0
- package/dist/discovery/on-chain-registry.d.ts +35 -0
- package/dist/discovery/on-chain-registry.d.ts.map +1 -0
- package/dist/discovery/on-chain-registry.js +199 -0
- package/dist/discovery/on-chain-registry.js.map +1 -0
- package/dist/encryption/aes.d.ts +15 -0
- package/dist/encryption/aes.d.ts.map +1 -0
- package/dist/encryption/aes.js +63 -0
- package/dist/encryption/aes.js.map +1 -0
- package/dist/encryption/encryption-layer.d.ts +8 -0
- package/dist/encryption/encryption-layer.d.ts.map +1 -0
- package/dist/encryption/encryption-layer.js +82 -0
- package/dist/encryption/encryption-layer.js.map +1 -0
- package/dist/encryption/index.d.ts +6 -0
- package/dist/encryption/index.d.ts.map +1 -0
- package/dist/encryption/index.js +4 -0
- package/dist/encryption/index.js.map +1 -0
- package/dist/encryption/lit.d.ts +23 -0
- package/dist/encryption/lit.d.ts.map +1 -0
- package/dist/encryption/lit.js +113 -0
- package/dist/encryption/lit.js.map +1 -0
- package/dist/encryption/vault-key.d.ts +37 -0
- package/dist/encryption/vault-key.d.ts.map +1 -0
- package/dist/encryption/vault-key.js +43 -0
- package/dist/encryption/vault-key.js.map +1 -0
- package/dist/identity/identity-layer.d.ts +3 -0
- package/dist/identity/identity-layer.d.ts.map +1 -0
- package/dist/identity/identity-layer.js +99 -0
- package/dist/identity/identity-layer.js.map +1 -0
- package/dist/identity/index.d.ts +4 -0
- package/dist/identity/index.d.ts.map +1 -0
- package/dist/identity/index.js +4 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/identity/ows-adapter.d.ts +15 -0
- package/dist/identity/ows-adapter.d.ts.map +1 -0
- package/dist/identity/ows-adapter.js +67 -0
- package/dist/identity/ows-adapter.js.map +1 -0
- package/dist/identity/session.d.ts +10 -0
- package/dist/identity/session.d.ts.map +1 -0
- package/dist/identity/session.js +36 -0
- package/dist/identity/session.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/persistence/create-agent.d.ts +11 -0
- package/dist/persistence/create-agent.d.ts.map +1 -0
- package/dist/persistence/create-agent.js +47 -0
- package/dist/persistence/create-agent.js.map +1 -0
- package/dist/persistence/index.d.ts +3 -0
- package/dist/persistence/index.d.ts.map +1 -0
- package/dist/persistence/index.js +3 -0
- package/dist/persistence/index.js.map +1 -0
- package/dist/persistence/persistence-layer.d.ts +12 -0
- package/dist/persistence/persistence-layer.d.ts.map +1 -0
- package/dist/persistence/persistence-layer.js +194 -0
- package/dist/persistence/persistence-layer.js.map +1 -0
- package/dist/transport/index.d.ts +3 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/index.js +3 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/transport/relay-session.d.ts +41 -0
- package/dist/transport/relay-session.d.ts.map +1 -0
- package/dist/transport/relay-session.js +86 -0
- package/dist/transport/relay-session.js.map +1 -0
- package/dist/transport/transport-layer.d.ts +32 -0
- package/dist/transport/transport-layer.d.ts.map +1 -0
- package/dist/transport/transport-layer.js +110 -0
- package/dist/transport/transport-layer.js.map +1 -0
- package/dist/types.d.ts +1319 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/package.json +91 -0
- package/src/__tests__/client.test.ts +30 -0
- package/src/__tests__/orbitdb-availability.ts +8 -0
- package/src/agent/__tests__/agent-adapter.test.ts +50 -0
- package/src/agent/__tests__/client.test.ts +50 -0
- package/src/agent/agent-adapter.ts +2 -0
- package/src/agent/client.ts +158 -0
- package/src/agent/index.ts +1 -0
- package/src/client.ts +134 -0
- package/src/contracts.ts +44 -0
- package/src/data/__tests__/pricing.test.ts +73 -0
- package/src/data/__tests__/vault-encryption.test.ts +346 -0
- package/src/data/__tests__/vault.test.ts +75 -0
- package/src/data/index.ts +8 -0
- package/src/data/orbitdb.ts +47 -0
- package/src/data/pricing.ts +63 -0
- package/src/data/serialization.ts +108 -0
- package/src/data/vault.ts +382 -0
- package/src/discovery/__tests__/discovery.test.ts +49 -0
- package/src/discovery/__tests__/on-chain-registry.test.ts +176 -0
- package/src/discovery/discovery-layer.ts +244 -0
- package/src/discovery/index.ts +3 -0
- package/src/discovery/mock-registry.ts +96 -0
- package/src/discovery/on-chain-registry.ts +237 -0
- package/src/encryption/__tests__/aes.test.ts +64 -0
- package/src/encryption/__tests__/encryption-layer.test.ts +80 -0
- package/src/encryption/__tests__/lit.test.ts +97 -0
- package/src/encryption/aes.ts +109 -0
- package/src/encryption/encryption-layer.ts +100 -0
- package/src/encryption/index.ts +5 -0
- package/src/encryption/lit.ts +161 -0
- package/src/encryption/vault-key.ts +63 -0
- package/src/identity/__tests__/identity.test.ts +31 -0
- package/src/identity/__tests__/ows-adapter.test.ts +47 -0
- package/src/identity/identity-layer.ts +123 -0
- package/src/identity/index.ts +3 -0
- package/src/identity/ows-adapter.ts +80 -0
- package/src/identity/session.ts +57 -0
- package/src/index.ts +12 -0
- package/src/persistence/__tests__/create-agent.test.ts +9 -0
- package/src/persistence/__tests__/persistence.test.ts +242 -0
- package/src/persistence/create-agent.ts +55 -0
- package/src/persistence/index.ts +2 -0
- package/src/persistence/persistence-layer.ts +236 -0
- package/src/transport/__tests__/solana-transport.test.ts +112 -0
- package/src/transport/__tests__/transport.test.ts +84 -0
- package/src/transport/index.ts +2 -0
- package/src/transport/relay-session.ts +118 -0
- package/src/transport/transport-layer.ts +171 -0
- package/src/types/orbitdb.d.ts +9 -0
- package/src/types.ts +1496 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,1319 @@
|
|
|
1
|
+
/** EVM hex address */
|
|
2
|
+
export type EvmAddress = `0x${string}`;
|
|
3
|
+
/** Solana base58 public key */
|
|
4
|
+
export type SolanaPublicKey = string;
|
|
5
|
+
/** Unified address across chains */
|
|
6
|
+
export type WalletAddress = EvmAddress | SolanaPublicKey;
|
|
7
|
+
/** Content Identifier (IPFS / Filecoin) */
|
|
8
|
+
export type CID = string;
|
|
9
|
+
/** OrbitDB database address */
|
|
10
|
+
export type OrbitAddress = string;
|
|
11
|
+
/** Supported chain families */
|
|
12
|
+
export type ChainFamily = "passkey" | "evm" | "solana";
|
|
13
|
+
/** EVM chain identifiers */
|
|
14
|
+
export type EvmChain = "ethereum" | "polygon" | "optimism" | "arbitrum" | "base" | "base-sepolia";
|
|
15
|
+
/** Solana cluster identifiers */
|
|
16
|
+
export type SolanaCluster = "mainnet-beta" | "devnet" | "testnet";
|
|
17
|
+
/** Unified chain type */
|
|
18
|
+
export type Chain = EvmChain | SolanaCluster;
|
|
19
|
+
/** Encryption engine choice */
|
|
20
|
+
export type EncryptionEngine = "lit" | "aes";
|
|
21
|
+
/**
|
|
22
|
+
* Data visibility level.
|
|
23
|
+
*
|
|
24
|
+
* - `public`: Plaintext. Anyone with the vault address can read via Relay.
|
|
25
|
+
* Use for agent profiles, public preferences, discovery metadata.
|
|
26
|
+
*
|
|
27
|
+
* - `private`: Encrypted with owner-only key (AES, wallet-derived).
|
|
28
|
+
* Only the wallet that wrote it can decrypt.
|
|
29
|
+
*
|
|
30
|
+
* - `shared`: Encrypted with access conditions (Lit or AES shared key).
|
|
31
|
+
* Specific agents / addresses can decrypt if conditions are met.
|
|
32
|
+
*/
|
|
33
|
+
export type Visibility = "public" | "private" | "shared";
|
|
34
|
+
/** Signature algorithm determined by chain family */
|
|
35
|
+
export type SignatureAlgorithm = "p256" | "ecdsa-secp256k1" | "ed25519";
|
|
36
|
+
/** Configuration for the Identity Layer */
|
|
37
|
+
export interface IdentityConfig {
|
|
38
|
+
/** Supported chain families (default: ["evm"]) */
|
|
39
|
+
chains?: ChainFamily[];
|
|
40
|
+
/** OWS wallet name for CLI / server-side usage */
|
|
41
|
+
owsWallet?: string;
|
|
42
|
+
/** CAIP-2 chain ID for OWS signing (e.g., "eip155:84532"). Defaults to "eip155:84532" (Base Sepolia) */
|
|
43
|
+
owsChain?: string;
|
|
44
|
+
/** Porto Passkey config (optional if not using passkey auth) */
|
|
45
|
+
passkey?: {
|
|
46
|
+
/** WebAuthn Relying Party ID (e.g., "app.orbitmem.xyz") */
|
|
47
|
+
rpId: string;
|
|
48
|
+
/** Display name shown during biometric prompts */
|
|
49
|
+
rpName: string;
|
|
50
|
+
/**
|
|
51
|
+
* EVM chain to delegate the smart account to (EIP-7702).
|
|
52
|
+
* Porto creates a P256-backed EOA and can delegate to EVM chains.
|
|
53
|
+
*/
|
|
54
|
+
delegationChain?: EvmChain;
|
|
55
|
+
/** Whether to enable session keys via EIP-7715 */
|
|
56
|
+
enableSessionKeys?: boolean;
|
|
57
|
+
};
|
|
58
|
+
/** EVM-specific config (optional if only Solana/Passkey) */
|
|
59
|
+
evm?: {
|
|
60
|
+
chains: EvmChain[];
|
|
61
|
+
/** WalletConnect project ID for mobile wallet support */
|
|
62
|
+
walletConnectProjectId?: string;
|
|
63
|
+
/** Supported wallet adapters */
|
|
64
|
+
adapters?: EvmWalletAdapter[];
|
|
65
|
+
};
|
|
66
|
+
/** Solana-specific config (optional if only EVM) */
|
|
67
|
+
solana?: {
|
|
68
|
+
cluster: SolanaCluster;
|
|
69
|
+
/** Supported wallet adapters */
|
|
70
|
+
adapters?: SolanaWalletAdapter[];
|
|
71
|
+
};
|
|
72
|
+
/** Session key TTL in seconds (default: 3600) */
|
|
73
|
+
sessionTTL?: number;
|
|
74
|
+
}
|
|
75
|
+
export type EvmWalletAdapter = "metamask" | "walletconnect" | "coinbase" | "rabby" | "injected";
|
|
76
|
+
export type SolanaWalletAdapter = "phantom" | "solflare" | "backpack" | "glow" | "injected";
|
|
77
|
+
/** Result of a successful wallet connection */
|
|
78
|
+
export interface WalletConnection {
|
|
79
|
+
/** Which chain family was connected */
|
|
80
|
+
family: ChainFamily;
|
|
81
|
+
/** The wallet address (EVM hex / Solana base58 / Porto-derived EVM address) */
|
|
82
|
+
address: WalletAddress;
|
|
83
|
+
/** Which specific chain / cluster (undefined for passkey until delegation) */
|
|
84
|
+
chain?: Chain;
|
|
85
|
+
/** Signature algorithm available */
|
|
86
|
+
signatureAlgorithm: SignatureAlgorithm;
|
|
87
|
+
/** Display name from wallet (if available) */
|
|
88
|
+
displayName?: string;
|
|
89
|
+
/** WebAuthn credential ID (only for passkey connections) */
|
|
90
|
+
credentialId?: string;
|
|
91
|
+
/** Connection timestamp */
|
|
92
|
+
connectedAt: number;
|
|
93
|
+
}
|
|
94
|
+
/** Session key — ephemeral key derived from wallet signature */
|
|
95
|
+
export interface SessionKey {
|
|
96
|
+
/** Ephemeral session identifier */
|
|
97
|
+
id: string;
|
|
98
|
+
/** The parent wallet address that created this session */
|
|
99
|
+
parentAddress: WalletAddress;
|
|
100
|
+
/** Chain family of the parent wallet */
|
|
101
|
+
family: ChainFamily;
|
|
102
|
+
/** Session-specific address (derived) */
|
|
103
|
+
sessionAddress: WalletAddress;
|
|
104
|
+
/** Permissions granted */
|
|
105
|
+
permissions: SessionPermission[];
|
|
106
|
+
/** Expiry timestamp (unix ms) */
|
|
107
|
+
expiresAt: number;
|
|
108
|
+
/** Whether the session is currently valid */
|
|
109
|
+
isActive: boolean;
|
|
110
|
+
/** Signature algorithm used for session signing */
|
|
111
|
+
algorithm: SignatureAlgorithm;
|
|
112
|
+
}
|
|
113
|
+
export type SessionPermission = {
|
|
114
|
+
type: "vault:read";
|
|
115
|
+
keys?: string[];
|
|
116
|
+
} | {
|
|
117
|
+
type: "vault:write";
|
|
118
|
+
keys?: string[];
|
|
119
|
+
} | {
|
|
120
|
+
type: "vault:delete";
|
|
121
|
+
keys?: string[];
|
|
122
|
+
} | {
|
|
123
|
+
type: "relay:fetch";
|
|
124
|
+
} | {
|
|
125
|
+
type: "encrypt";
|
|
126
|
+
engines?: EncryptionEngine[];
|
|
127
|
+
} | {
|
|
128
|
+
type: "decrypt";
|
|
129
|
+
engines?: EncryptionEngine[];
|
|
130
|
+
} | {
|
|
131
|
+
type: "storacha:archive";
|
|
132
|
+
} | {
|
|
133
|
+
type: "storacha:retrieve";
|
|
134
|
+
};
|
|
135
|
+
/** Identity Layer interface */
|
|
136
|
+
export interface IIdentityLayer {
|
|
137
|
+
/**
|
|
138
|
+
* Connect a wallet or create/use a Passkey.
|
|
139
|
+
*
|
|
140
|
+
* - `passkey`: Triggers biometric prompt (FaceID/TouchID/Windows Hello).
|
|
141
|
+
* Creates a P256-backed account via Porto. The derived address is EVM-
|
|
142
|
+
* compatible via EIP-7702 smart account delegation.
|
|
143
|
+
*
|
|
144
|
+
* - `evm`: Opens the selected EVM wallet adapter.
|
|
145
|
+
*
|
|
146
|
+
* - `solana`: Opens the selected Solana wallet adapter.
|
|
147
|
+
*/
|
|
148
|
+
connect(opts: {
|
|
149
|
+
method: ChainFamily;
|
|
150
|
+
/** Preferred adapter (for evm/solana only — ignored for passkey) */
|
|
151
|
+
adapter?: EvmWalletAdapter | SolanaWalletAdapter;
|
|
152
|
+
/** Specific chain/cluster to target */
|
|
153
|
+
targetChain?: Chain;
|
|
154
|
+
}): Promise<WalletConnection>;
|
|
155
|
+
/**
|
|
156
|
+
* Create a new Porto Passkey credential.
|
|
157
|
+
* Only available when method='passkey'. Triggers WebAuthn registration.
|
|
158
|
+
*/
|
|
159
|
+
createPasskey(): Promise<{
|
|
160
|
+
credentialId: string;
|
|
161
|
+
publicKey: Uint8Array;
|
|
162
|
+
address: EvmAddress;
|
|
163
|
+
}>;
|
|
164
|
+
/**
|
|
165
|
+
* Disconnect the current wallet.
|
|
166
|
+
*/
|
|
167
|
+
disconnect(): Promise<void>;
|
|
168
|
+
/**
|
|
169
|
+
* Sign a challenge message to prove wallet ownership.
|
|
170
|
+
* Used internally during session creation.
|
|
171
|
+
*/
|
|
172
|
+
signChallenge(message: string): Promise<{
|
|
173
|
+
signature: Uint8Array;
|
|
174
|
+
algorithm: SignatureAlgorithm;
|
|
175
|
+
}>;
|
|
176
|
+
/**
|
|
177
|
+
* Create an ephemeral session key with scoped permissions.
|
|
178
|
+
* The session key is derived from a wallet signature.
|
|
179
|
+
*/
|
|
180
|
+
createSessionKey(permissions: SessionPermission[], opts?: {
|
|
181
|
+
ttl?: number;
|
|
182
|
+
}): Promise<SessionKey>;
|
|
183
|
+
/**
|
|
184
|
+
* Resume an existing session (e.g., after page reload).
|
|
185
|
+
* Returns null if expired or not found.
|
|
186
|
+
*/
|
|
187
|
+
resumeSession(sessionId: string): Promise<SessionKey | null>;
|
|
188
|
+
/**
|
|
189
|
+
* Revoke a session key immediately.
|
|
190
|
+
*/
|
|
191
|
+
revokeSession(sessionId: string): Promise<void>;
|
|
192
|
+
/**
|
|
193
|
+
* Get the current wallet connection (or null).
|
|
194
|
+
*/
|
|
195
|
+
getConnection(): WalletConnection | null;
|
|
196
|
+
/**
|
|
197
|
+
* Get the active session (or null).
|
|
198
|
+
*/
|
|
199
|
+
getActiveSession(): SessionKey | null;
|
|
200
|
+
/**
|
|
201
|
+
* Subscribe to connection state changes.
|
|
202
|
+
*/
|
|
203
|
+
onConnectionChange(callback: (connection: WalletConnection | null) => void): () => void;
|
|
204
|
+
}
|
|
205
|
+
/** Signed HTTP request envelope */
|
|
206
|
+
export interface SignedRequest {
|
|
207
|
+
/** Original request URL */
|
|
208
|
+
url: string;
|
|
209
|
+
/** HTTP method */
|
|
210
|
+
method: "GET" | "POST" | "PUT" | "DELETE";
|
|
211
|
+
/** Request headers (signature headers injected automatically) */
|
|
212
|
+
headers: Record<string, string>;
|
|
213
|
+
/** Request body (if any) */
|
|
214
|
+
body?: unknown;
|
|
215
|
+
/** ERC-8128 signature metadata */
|
|
216
|
+
proof: {
|
|
217
|
+
/** The session address that signed */
|
|
218
|
+
signer: WalletAddress;
|
|
219
|
+
/** Chain family of the signer */
|
|
220
|
+
family: ChainFamily;
|
|
221
|
+
/** Signature bytes */
|
|
222
|
+
signature: Uint8Array;
|
|
223
|
+
/** Signature algorithm */
|
|
224
|
+
algorithm: SignatureAlgorithm;
|
|
225
|
+
/** Timestamp of signing (unix ms) */
|
|
226
|
+
timestamp: number;
|
|
227
|
+
/** Nonce to prevent replay */
|
|
228
|
+
nonce: string;
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
/** Verification result */
|
|
232
|
+
export interface VerificationResult {
|
|
233
|
+
/** Whether the signature is valid */
|
|
234
|
+
valid: boolean;
|
|
235
|
+
/** Recovered signer address */
|
|
236
|
+
signer: WalletAddress;
|
|
237
|
+
/** Chain family */
|
|
238
|
+
family: ChainFamily;
|
|
239
|
+
/** Whether the nonce has been seen before (replay detection) */
|
|
240
|
+
isReplay: boolean;
|
|
241
|
+
}
|
|
242
|
+
/** Transport Layer interface */
|
|
243
|
+
export interface ITransportLayer {
|
|
244
|
+
/**
|
|
245
|
+
* Create and sign an HTTP request using ERC-8128.
|
|
246
|
+
* Automatically uses the active session key.
|
|
247
|
+
*/
|
|
248
|
+
createSignedRequest(request: {
|
|
249
|
+
url: string;
|
|
250
|
+
method: "GET" | "POST" | "PUT" | "DELETE";
|
|
251
|
+
headers?: Record<string, string>;
|
|
252
|
+
body?: unknown;
|
|
253
|
+
}): Promise<SignedRequest>;
|
|
254
|
+
/**
|
|
255
|
+
* Verify an incoming signed request.
|
|
256
|
+
* Used by Relay Nodes to authenticate agent requests.
|
|
257
|
+
*/
|
|
258
|
+
verifyRequest(request: SignedRequest): Promise<VerificationResult>;
|
|
259
|
+
/**
|
|
260
|
+
* Send a signed request and return the response.
|
|
261
|
+
* Convenience method that wraps createSignedRequest + fetch.
|
|
262
|
+
*/
|
|
263
|
+
fetch(url: string, init?: {
|
|
264
|
+
method?: "GET" | "POST" | "PUT" | "DELETE";
|
|
265
|
+
headers?: Record<string, string>;
|
|
266
|
+
body?: unknown;
|
|
267
|
+
}): Promise<Response>;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Vault path — supports nested access via slash-separated strings
|
|
271
|
+
* or string arrays. Examples:
|
|
272
|
+
* "travel/dietary"
|
|
273
|
+
* "travel/budget/max"
|
|
274
|
+
* ["travel", "passport", "number"]
|
|
275
|
+
*/
|
|
276
|
+
export type VaultPath = string | string[];
|
|
277
|
+
/** Vault configuration */
|
|
278
|
+
export interface VaultConfig {
|
|
279
|
+
/** OrbitDB database name (default: derived from wallet address) */
|
|
280
|
+
dbName?: string;
|
|
281
|
+
/** Database type: "nested" uses @orbitdb/nested-db for JSON-like
|
|
282
|
+
* hierarchical storage with path-based access (default: "nested") */
|
|
283
|
+
databaseType?: "nested" | "keyvalue";
|
|
284
|
+
/** Relay node multiaddr for syncing */
|
|
285
|
+
relayNode?: string;
|
|
286
|
+
/** Auto-sync interval in ms (default: 30000) */
|
|
287
|
+
syncInterval?: number;
|
|
288
|
+
/** Enable offline-first mode (default: true) */
|
|
289
|
+
offlineFirst?: boolean;
|
|
290
|
+
}
|
|
291
|
+
/** A single vault entry with metadata */
|
|
292
|
+
export interface VaultEntry<T = unknown> {
|
|
293
|
+
/** The stored value (plaintext if public, encrypted blob if private/shared) */
|
|
294
|
+
value: T;
|
|
295
|
+
/** Visibility level */
|
|
296
|
+
visibility: Visibility;
|
|
297
|
+
/** Who wrote this entry (wallet address) */
|
|
298
|
+
author: WalletAddress;
|
|
299
|
+
/** Chain family of the author */
|
|
300
|
+
authorChain: ChainFamily;
|
|
301
|
+
/** When it was written (unix ms) */
|
|
302
|
+
timestamp: number;
|
|
303
|
+
/** Whether this entry is encrypted (false for public) */
|
|
304
|
+
encrypted: boolean;
|
|
305
|
+
/** Which encryption engine was used (undefined for public) */
|
|
306
|
+
encryptionEngine?: EncryptionEngine;
|
|
307
|
+
/** OrbitDB entry hash */
|
|
308
|
+
hash: string;
|
|
309
|
+
}
|
|
310
|
+
/** Sync status */
|
|
311
|
+
export interface SyncStatus {
|
|
312
|
+
/** Whether currently syncing */
|
|
313
|
+
syncing: boolean;
|
|
314
|
+
/** Number of local entries pending push */
|
|
315
|
+
pendingPush: number;
|
|
316
|
+
/** Number of remote entries pending pull */
|
|
317
|
+
pendingPull: number;
|
|
318
|
+
/** Last successful sync timestamp */
|
|
319
|
+
lastSynced: number | null;
|
|
320
|
+
/** Connected peers count */
|
|
321
|
+
connectedPeers: number;
|
|
322
|
+
}
|
|
323
|
+
/** Per-path read pricing for MPP monetization */
|
|
324
|
+
export interface VaultPricing {
|
|
325
|
+
/** Price amount as decimal string (e.g. "0.005") */
|
|
326
|
+
amount: string;
|
|
327
|
+
/** Currency identifier (e.g. "USDC") */
|
|
328
|
+
currency: string;
|
|
329
|
+
}
|
|
330
|
+
/** Pricing CRUD for vault data monetization */
|
|
331
|
+
export interface IVaultPricing {
|
|
332
|
+
/** Set per-read price for a vault path. Use "_default" as path for vault-wide fallback. */
|
|
333
|
+
setPrice(path: string, pricing: VaultPricing): Promise<void>;
|
|
334
|
+
/** Get price for a path. Falls back to "_default" pricing if no per-path price. Returns null if free. */
|
|
335
|
+
getPrice(path: string): Promise<VaultPricing | null>;
|
|
336
|
+
/** Remove price for a path (reverts to _default or free). */
|
|
337
|
+
removePrice(path: string): Promise<void>;
|
|
338
|
+
/** List all explicitly priced paths. */
|
|
339
|
+
listPrices(): Promise<Array<{
|
|
340
|
+
path: string;
|
|
341
|
+
} & VaultPricing>>;
|
|
342
|
+
}
|
|
343
|
+
/** Data Layer interface — backed by @orbitdb/nested-db */
|
|
344
|
+
export interface IDataLayer {
|
|
345
|
+
/**
|
|
346
|
+
* Store a value at a nested path.
|
|
347
|
+
*
|
|
348
|
+
* Paths use "/" separators or string arrays:
|
|
349
|
+
* vault.put("travel/dietary", "vegan")
|
|
350
|
+
* vault.put(["travel", "budget"], { min: 1000, max: 2000 })
|
|
351
|
+
*
|
|
352
|
+
* Each path can have its own visibility & encryption:
|
|
353
|
+
* vault.put("travel/dietary", "vegan", { visibility: "public" })
|
|
354
|
+
* vault.put("travel/passport", { ... }, { visibility: "private" })
|
|
355
|
+
* vault.put("travel/budget", { ... }, {
|
|
356
|
+
* visibility: "shared",
|
|
357
|
+
* engine: "lit",
|
|
358
|
+
* accessConditions: [reputationCondition({ minScore: 70 })],
|
|
359
|
+
* })
|
|
360
|
+
*
|
|
361
|
+
* Default visibility is `private` (encrypted, owner-only).
|
|
362
|
+
*/
|
|
363
|
+
put<T = unknown>(path: VaultPath, value: T, opts?: {
|
|
364
|
+
/** Visibility level (default: 'private') */
|
|
365
|
+
visibility?: Visibility;
|
|
366
|
+
/** Encryption engine override (for 'shared'; 'private' defaults to 'aes') */
|
|
367
|
+
engine?: EncryptionEngine;
|
|
368
|
+
/** Lit access conditions (required if visibility='shared' + engine='lit') */
|
|
369
|
+
accessConditions?: LitAccessCondition[];
|
|
370
|
+
/** AES shared key source (for visibility='shared' + engine='aes') */
|
|
371
|
+
sharedKeySource?: AESKeySource;
|
|
372
|
+
}): Promise<VaultEntry<T>>;
|
|
373
|
+
/**
|
|
374
|
+
* Insert a nested object, merging with existing data.
|
|
375
|
+
* Equivalent to calling put() for each leaf path.
|
|
376
|
+
*
|
|
377
|
+
* vault.insert({ travel: { dietary: "vegan", budget: 2000 } })
|
|
378
|
+
* // same as:
|
|
379
|
+
* vault.put("travel/dietary", "vegan")
|
|
380
|
+
* vault.put("travel/budget", 2000)
|
|
381
|
+
*
|
|
382
|
+
* @param prefix - Optional root prefix for all paths
|
|
383
|
+
* @param obj - Nested object to merge
|
|
384
|
+
* @param opts - Visibility/encryption applied to all leaf entries
|
|
385
|
+
*/
|
|
386
|
+
insert<T extends Record<string, unknown> = Record<string, unknown>>(obj: T, opts?: {
|
|
387
|
+
prefix?: string;
|
|
388
|
+
visibility?: Visibility;
|
|
389
|
+
engine?: EncryptionEngine;
|
|
390
|
+
accessConditions?: LitAccessCondition[];
|
|
391
|
+
}): Promise<void>;
|
|
392
|
+
/**
|
|
393
|
+
* Retrieve a value by path.
|
|
394
|
+
*
|
|
395
|
+
* vault.get("travel") → { dietary: "vegan", budget: 2000, passport: {...} }
|
|
396
|
+
* vault.get("travel/dietary") → "vegan"
|
|
397
|
+
* vault.get("travel/budget") → 2000
|
|
398
|
+
*
|
|
399
|
+
* Returns the subtree if the path points to a nested object.
|
|
400
|
+
* Auto-decrypts if the caller has permission.
|
|
401
|
+
* Returns null if the path or any ancestor does not exist.
|
|
402
|
+
*/
|
|
403
|
+
get<T = unknown>(path: VaultPath): Promise<VaultEntry<T> | null>;
|
|
404
|
+
/**
|
|
405
|
+
* Delete a path and all its children from the vault.
|
|
406
|
+
*
|
|
407
|
+
* vault.del("travel/passport") → deletes only passport
|
|
408
|
+
* vault.del("travel") → deletes entire travel subtree
|
|
409
|
+
*/
|
|
410
|
+
del(path: VaultPath): Promise<void>;
|
|
411
|
+
/**
|
|
412
|
+
* List all leaf keys, optionally filtered by path prefix.
|
|
413
|
+
*
|
|
414
|
+
* vault.keys() → ["travel/dietary", "travel/budget", "travel/passport/number", ...]
|
|
415
|
+
* vault.keys("travel") → ["travel/dietary", "travel/budget", ...]
|
|
416
|
+
*/
|
|
417
|
+
keys(prefix?: string): Promise<string[]>;
|
|
418
|
+
/**
|
|
419
|
+
* Get the entire vault as a nested JSON object.
|
|
420
|
+
*
|
|
421
|
+
* vault.all() → { travel: { dietary: "vegan", budget: 2000, ... } }
|
|
422
|
+
*/
|
|
423
|
+
all<T = Record<string, unknown>>(): Promise<T>;
|
|
424
|
+
/**
|
|
425
|
+
* Query entries by filter.
|
|
426
|
+
*/
|
|
427
|
+
query<T = unknown>(filter: {
|
|
428
|
+
prefix?: string;
|
|
429
|
+
author?: WalletAddress;
|
|
430
|
+
visibility?: Visibility;
|
|
431
|
+
since?: number;
|
|
432
|
+
limit?: number;
|
|
433
|
+
}): Promise<VaultEntry<T>[]>;
|
|
434
|
+
/**
|
|
435
|
+
* Force sync with the relay node.
|
|
436
|
+
*/
|
|
437
|
+
sync(): Promise<SyncStatus>;
|
|
438
|
+
/**
|
|
439
|
+
* Get current sync status.
|
|
440
|
+
*/
|
|
441
|
+
getSyncStatus(): SyncStatus;
|
|
442
|
+
/**
|
|
443
|
+
* Subscribe to real-time changes.
|
|
444
|
+
*/
|
|
445
|
+
onChange(callback: (event: {
|
|
446
|
+
type: "put" | "delete";
|
|
447
|
+
path: string;
|
|
448
|
+
entry?: VaultEntry;
|
|
449
|
+
}) => void): () => void;
|
|
450
|
+
/**
|
|
451
|
+
* Export the entire vault as an encrypted snapshot.
|
|
452
|
+
*/
|
|
453
|
+
exportSnapshot(): Promise<{
|
|
454
|
+
data: Uint8Array;
|
|
455
|
+
entryCount: number;
|
|
456
|
+
timestamp: number;
|
|
457
|
+
}>;
|
|
458
|
+
/**
|
|
459
|
+
* Import a snapshot into the vault (merge with CRDT).
|
|
460
|
+
*/
|
|
461
|
+
importSnapshot(data: Uint8Array): Promise<{
|
|
462
|
+
merged: number;
|
|
463
|
+
conflicts: number;
|
|
464
|
+
}>;
|
|
465
|
+
}
|
|
466
|
+
/** Lit Protocol access control condition (EVM) */
|
|
467
|
+
export interface LitEvmCondition {
|
|
468
|
+
conditionType: "evmBasic" | "evmContract";
|
|
469
|
+
contractAddress: EvmAddress | "";
|
|
470
|
+
standardContractType: "" | "ERC20" | "ERC721" | "ERC1155";
|
|
471
|
+
chain: EvmChain;
|
|
472
|
+
method: string;
|
|
473
|
+
parameters: string[];
|
|
474
|
+
returnValueTest: {
|
|
475
|
+
comparator: ">" | "<" | ">=" | "<=" | "=" | "!=";
|
|
476
|
+
value: string;
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
/** Lit Protocol access control condition (Solana) */
|
|
480
|
+
export interface LitSolanaCondition {
|
|
481
|
+
conditionType: "solRpc";
|
|
482
|
+
method: string;
|
|
483
|
+
params: string[];
|
|
484
|
+
chain: "solana";
|
|
485
|
+
returnValueTest: {
|
|
486
|
+
comparator: string;
|
|
487
|
+
value: string;
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
/** Boolean operator for combining conditions */
|
|
491
|
+
export interface LitBooleanOperator {
|
|
492
|
+
operator: "and" | "or";
|
|
493
|
+
}
|
|
494
|
+
/** Unified Lit access condition */
|
|
495
|
+
export type LitAccessCondition = LitEvmCondition | LitSolanaCondition | LitBooleanOperator;
|
|
496
|
+
/** Lit-encrypted blob */
|
|
497
|
+
export interface LitEncryptedData {
|
|
498
|
+
engine: "lit";
|
|
499
|
+
/** Encrypted data bytes */
|
|
500
|
+
ciphertext: Uint8Array;
|
|
501
|
+
/** Encrypted symmetric key (held by Lit MPC network) */
|
|
502
|
+
dataToEncryptHash: string;
|
|
503
|
+
/** The access conditions required for decryption */
|
|
504
|
+
accessControlConditions: LitAccessCondition[];
|
|
505
|
+
/** Chain used for condition evaluation */
|
|
506
|
+
chain: Chain;
|
|
507
|
+
}
|
|
508
|
+
/** AES key derivation source */
|
|
509
|
+
export type AESKeySource = {
|
|
510
|
+
type: "wallet-signature";
|
|
511
|
+
message?: string;
|
|
512
|
+
} | {
|
|
513
|
+
type: "password";
|
|
514
|
+
password: string;
|
|
515
|
+
} | {
|
|
516
|
+
type: "raw";
|
|
517
|
+
key: Uint8Array;
|
|
518
|
+
};
|
|
519
|
+
/** AES-encrypted blob */
|
|
520
|
+
export interface AESEncryptedData {
|
|
521
|
+
engine: "aes";
|
|
522
|
+
/** AES-256-GCM ciphertext */
|
|
523
|
+
ciphertext: Uint8Array;
|
|
524
|
+
/** Initialization vector */
|
|
525
|
+
iv: Uint8Array;
|
|
526
|
+
/** Authentication tag */
|
|
527
|
+
authTag: Uint8Array;
|
|
528
|
+
/** Key derivation metadata (no secret material) */
|
|
529
|
+
keyDerivation: {
|
|
530
|
+
source: "wallet-signature" | "password" | "raw";
|
|
531
|
+
/** Salt used for HKDF/PBKDF2 */
|
|
532
|
+
salt: Uint8Array;
|
|
533
|
+
/** Algorithm used for key derivation */
|
|
534
|
+
kdf: "hkdf-sha256" | "pbkdf2-sha256";
|
|
535
|
+
/** Iterations (if PBKDF2) */
|
|
536
|
+
iterations?: number;
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
/** Union of encrypted data types */
|
|
540
|
+
export type EncryptedData = LitEncryptedData | AESEncryptedData;
|
|
541
|
+
/** Encryption Layer configuration */
|
|
542
|
+
export interface EncryptionConfig {
|
|
543
|
+
/** Default encryption engine */
|
|
544
|
+
defaultEngine: EncryptionEngine;
|
|
545
|
+
/** Lit Protocol configuration (required if using 'lit') */
|
|
546
|
+
lit?: {
|
|
547
|
+
/** Lit network: 'cayenne' | 'manzano' | 'habanero' */
|
|
548
|
+
network: "cayenne" | "manzano" | "habanero";
|
|
549
|
+
/** Debug mode */
|
|
550
|
+
debug?: boolean;
|
|
551
|
+
};
|
|
552
|
+
/** AES configuration */
|
|
553
|
+
aes?: {
|
|
554
|
+
/** Default key derivation function */
|
|
555
|
+
kdf: "hkdf-sha256" | "pbkdf2-sha256";
|
|
556
|
+
/** PBKDF2 iterations (default: 100000) */
|
|
557
|
+
iterations?: number;
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
/** Encryption Layer interface */
|
|
561
|
+
export interface IEncryptionLayer {
|
|
562
|
+
/**
|
|
563
|
+
* Encrypt data using the specified engine.
|
|
564
|
+
*
|
|
565
|
+
* - `lit`: Requires `accessConditions`. Data is encrypted with a symmetric
|
|
566
|
+
* key that is then split across the Lit MPC network. Decryption requires
|
|
567
|
+
* meeting the on-chain conditions.
|
|
568
|
+
*
|
|
569
|
+
* - `aes`: Requires `keySource`. Data is encrypted locally with
|
|
570
|
+
* AES-256-GCM. The key is derived from the wallet signature, a password,
|
|
571
|
+
* or provided directly. No network calls needed.
|
|
572
|
+
*/
|
|
573
|
+
encrypt(data: Uint8Array | string, opts: EncryptLitOptions | EncryptAESOptions): Promise<EncryptedData>;
|
|
574
|
+
/**
|
|
575
|
+
* Decrypt data. Automatically detects engine from the blob metadata.
|
|
576
|
+
*
|
|
577
|
+
* - `lit`: Requests decryption from the Lit MPC network. The caller must
|
|
578
|
+
* meet the access conditions (wallet signed auth).
|
|
579
|
+
*
|
|
580
|
+
* - `aes`: Derives the key locally and decrypts. The caller must provide
|
|
581
|
+
* the same key source used during encryption.
|
|
582
|
+
*/
|
|
583
|
+
decrypt(encrypted: EncryptedData, opts?: DecryptOptions): Promise<Uint8Array>;
|
|
584
|
+
/**
|
|
585
|
+
* Grant an agent address access to Lit-encrypted data.
|
|
586
|
+
* Only applicable for engine='lit'. Adds the address to the access
|
|
587
|
+
* control conditions and re-encrypts the symmetric key.
|
|
588
|
+
*/
|
|
589
|
+
grantAccess(encrypted: LitEncryptedData, agentAddress: WalletAddress, opts?: {
|
|
590
|
+
/** Chain to evaluate the condition on */
|
|
591
|
+
chain?: Chain;
|
|
592
|
+
/** Time-limited access (unix timestamp) */
|
|
593
|
+
expiresAt?: number;
|
|
594
|
+
}): Promise<LitEncryptedData>;
|
|
595
|
+
/**
|
|
596
|
+
* Revoke an agent's access to Lit-encrypted data.
|
|
597
|
+
*/
|
|
598
|
+
revokeAccess(encrypted: LitEncryptedData, agentAddress: WalletAddress): Promise<LitEncryptedData>;
|
|
599
|
+
/**
|
|
600
|
+
* Derive an AES-256 key from a wallet signature.
|
|
601
|
+
* Useful for pre-generating keys for batch operations.
|
|
602
|
+
*/
|
|
603
|
+
deriveAESKey(source: AESKeySource): Promise<CryptoKey>;
|
|
604
|
+
/**
|
|
605
|
+
* Check if the current session can decrypt the given blob.
|
|
606
|
+
* For Lit: simulates condition evaluation.
|
|
607
|
+
* For AES: checks if the key source is available.
|
|
608
|
+
*/
|
|
609
|
+
canDecrypt(encrypted: EncryptedData): Promise<boolean>;
|
|
610
|
+
}
|
|
611
|
+
/** Options for Lit encryption */
|
|
612
|
+
export interface EncryptLitOptions {
|
|
613
|
+
engine: "lit";
|
|
614
|
+
/** Access control conditions (who can decrypt) */
|
|
615
|
+
accessConditions: LitAccessCondition[];
|
|
616
|
+
/** Chain for condition evaluation */
|
|
617
|
+
chain?: Chain;
|
|
618
|
+
}
|
|
619
|
+
/** Options for AES encryption */
|
|
620
|
+
export interface EncryptAESOptions {
|
|
621
|
+
engine: "aes";
|
|
622
|
+
/** How to derive/obtain the AES key */
|
|
623
|
+
keySource: AESKeySource;
|
|
624
|
+
}
|
|
625
|
+
/** Lit Protocol auth signature — proves wallet ownership to Lit nodes */
|
|
626
|
+
export interface LitAuthSig {
|
|
627
|
+
sig: string;
|
|
628
|
+
derivedVia: string;
|
|
629
|
+
signedMessage: string;
|
|
630
|
+
address: string;
|
|
631
|
+
}
|
|
632
|
+
/** Options for decryption (engine auto-detected from blob) */
|
|
633
|
+
export interface DecryptOptions {
|
|
634
|
+
/** For AES: provide key source if not cached */
|
|
635
|
+
keySource?: AESKeySource;
|
|
636
|
+
/** For Lit: wallet auth signature used to obtain sessionSigs */
|
|
637
|
+
authSig?: LitAuthSig;
|
|
638
|
+
}
|
|
639
|
+
/** Configuration for the persistence layer — determines mode from shape */
|
|
640
|
+
export interface StorachaConfig {
|
|
641
|
+
/** Mock mode for testing (in-memory) */
|
|
642
|
+
mock?: boolean;
|
|
643
|
+
/** Relay URL for managed persistence (free/paid tiers) */
|
|
644
|
+
relayUrl?: string;
|
|
645
|
+
/** Serialized UCAN delegation proof for direct Storacha uploads (BYOS) */
|
|
646
|
+
proof?: string;
|
|
647
|
+
/** Optional IPFS gateway URL (default: https://w3s.link) */
|
|
648
|
+
gatewayUrl?: string;
|
|
649
|
+
/** Auto-archive interval in ms (0 = manual only) */
|
|
650
|
+
autoArchiveInterval?: number;
|
|
651
|
+
/** Maximum snapshot size in bytes (default: 10MB) */
|
|
652
|
+
maxSnapshotSize?: number;
|
|
653
|
+
}
|
|
654
|
+
/** A stored snapshot on Filecoin/IPFS */
|
|
655
|
+
export interface Snapshot {
|
|
656
|
+
/** Content identifier */
|
|
657
|
+
cid: CID;
|
|
658
|
+
/** Size in bytes */
|
|
659
|
+
size: number;
|
|
660
|
+
/** When it was archived */
|
|
661
|
+
archivedAt: number;
|
|
662
|
+
/** Who created this snapshot */
|
|
663
|
+
author: WalletAddress;
|
|
664
|
+
/** Number of vault entries in this snapshot */
|
|
665
|
+
entryCount: number;
|
|
666
|
+
/** Whether the snapshot data is encrypted */
|
|
667
|
+
encrypted: boolean;
|
|
668
|
+
/** Filecoin deal status */
|
|
669
|
+
filecoinStatus: "pending" | "active" | "expired";
|
|
670
|
+
}
|
|
671
|
+
/** Persistence Layer interface */
|
|
672
|
+
export interface IPersistenceLayer {
|
|
673
|
+
/**
|
|
674
|
+
* Archive the current vault state to Filecoin/IPFS.
|
|
675
|
+
* The snapshot is always encrypted (using the vault's encryption).
|
|
676
|
+
*/
|
|
677
|
+
archive(opts?: {
|
|
678
|
+
/** Optional label for this snapshot */
|
|
679
|
+
label?: string;
|
|
680
|
+
/** Whether to also pin to Filecoin (default: true) */
|
|
681
|
+
pinToFilecoin?: boolean;
|
|
682
|
+
}): Promise<Snapshot>;
|
|
683
|
+
/**
|
|
684
|
+
* Retrieve a snapshot by CID.
|
|
685
|
+
*/
|
|
686
|
+
retrieve(cid: CID): Promise<Uint8Array>;
|
|
687
|
+
/**
|
|
688
|
+
* Restore the vault from a snapshot.
|
|
689
|
+
* Merges with existing data using CRDT resolution.
|
|
690
|
+
*/
|
|
691
|
+
restore(cid: CID): Promise<{
|
|
692
|
+
merged: number;
|
|
693
|
+
conflicts: number;
|
|
694
|
+
}>;
|
|
695
|
+
/**
|
|
696
|
+
* List all snapshots for the current wallet.
|
|
697
|
+
*/
|
|
698
|
+
listSnapshots(opts?: {
|
|
699
|
+
limit?: number;
|
|
700
|
+
offset?: number;
|
|
701
|
+
}): Promise<Snapshot[]>;
|
|
702
|
+
/**
|
|
703
|
+
* Delete a snapshot (removes IPFS pin, Filecoin deal remains).
|
|
704
|
+
*/
|
|
705
|
+
deleteSnapshot(cid: CID): Promise<void>;
|
|
706
|
+
/**
|
|
707
|
+
* Get Filecoin deal status for a snapshot.
|
|
708
|
+
*/
|
|
709
|
+
getDealStatus(cid: CID): Promise<{
|
|
710
|
+
status: "pending" | "active" | "expired";
|
|
711
|
+
dealId?: string;
|
|
712
|
+
provider?: string;
|
|
713
|
+
expiresAt?: number;
|
|
714
|
+
}>;
|
|
715
|
+
}
|
|
716
|
+
/** Individual feedback entry */
|
|
717
|
+
export interface FeedbackEntry {
|
|
718
|
+
/** Feedback giver address */
|
|
719
|
+
clientAddress: WalletAddress;
|
|
720
|
+
/** Feedback value (fixed-point) */
|
|
721
|
+
value: number;
|
|
722
|
+
/** Decimal precision */
|
|
723
|
+
valueDecimals: number;
|
|
724
|
+
/** Primary tag (e.g., "starred", "successRate", "responseTime") */
|
|
725
|
+
tag1?: string;
|
|
726
|
+
/** Secondary tag */
|
|
727
|
+
tag2?: string;
|
|
728
|
+
/** Service endpoint the feedback is about */
|
|
729
|
+
endpoint?: string;
|
|
730
|
+
/** URI to off-chain feedback details */
|
|
731
|
+
feedbackURI?: string;
|
|
732
|
+
/** Keccak256 hash of feedbackURI content */
|
|
733
|
+
feedbackHash?: string;
|
|
734
|
+
/** Whether this feedback has been revoked */
|
|
735
|
+
isRevoked: boolean;
|
|
736
|
+
}
|
|
737
|
+
/** Validation request */
|
|
738
|
+
export interface ValidationRequest {
|
|
739
|
+
/** Agent that performed the task */
|
|
740
|
+
agentId: number;
|
|
741
|
+
/** Task identifier */
|
|
742
|
+
taskId: string;
|
|
743
|
+
/** Validation method requested */
|
|
744
|
+
method: "stake-reexecution" | "zkml" | "tee" | "trusted-judge";
|
|
745
|
+
/** Validation status */
|
|
746
|
+
status: "pending" | "validated" | "rejected" | "expired";
|
|
747
|
+
/** Validator address */
|
|
748
|
+
validator?: EvmAddress;
|
|
749
|
+
/** Validation result data (method-specific) */
|
|
750
|
+
resultData?: Uint8Array;
|
|
751
|
+
}
|
|
752
|
+
/** Discovery Layer configuration */
|
|
753
|
+
export interface DiscoveryConfig {
|
|
754
|
+
/** Data Identity Registry contract address */
|
|
755
|
+
dataRegistry: EvmAddress;
|
|
756
|
+
/** Shared Reputation Registry contract address */
|
|
757
|
+
reputationRegistry: EvmAddress;
|
|
758
|
+
/** Validation Registry contract address (optional) */
|
|
759
|
+
validationRegistry?: EvmAddress;
|
|
760
|
+
/** Chain where registries are deployed */
|
|
761
|
+
registryChain: EvmChain;
|
|
762
|
+
/** Minimum data quality score for agent consumption (0-100, optional) */
|
|
763
|
+
minDataScore?: number;
|
|
764
|
+
/** viem public client for on-chain reads (enables on-chain mode when provided) */
|
|
765
|
+
publicClient?: import("viem").PublicClient;
|
|
766
|
+
/** viem wallet client for on-chain writes (register, rate, revoke) */
|
|
767
|
+
walletClient?: import("viem").WalletClient;
|
|
768
|
+
/** Block number at which contracts were deployed (for event queries) */
|
|
769
|
+
deployBlock?: bigint;
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* ERC-8004 Data Registration — a user's vault entry registered as
|
|
773
|
+
* an on-chain discoverable asset with quality metadata.
|
|
774
|
+
*
|
|
775
|
+
* This is the key innovation: treating data as a first-class entity
|
|
776
|
+
* in ERC-8004, not just agents. Agents can discover, evaluate, and
|
|
777
|
+
* choose which data sources to consume based on verifiable scores.
|
|
778
|
+
*/
|
|
779
|
+
export interface DataRegistration {
|
|
780
|
+
/** ERC-721 token ID in the Data Registry */
|
|
781
|
+
dataId: number;
|
|
782
|
+
/** Registry reference: "{namespace}:{chainId}:{registryAddress}" */
|
|
783
|
+
dataRegistry: string;
|
|
784
|
+
/** Owner's vault address (OrbitDB) */
|
|
785
|
+
vaultAddress: OrbitAddress;
|
|
786
|
+
/** Vault key this registration refers to */
|
|
787
|
+
vaultKey: string;
|
|
788
|
+
/** Human-readable name */
|
|
789
|
+
name: string;
|
|
790
|
+
/** Description of the data (what it contains, intended use) */
|
|
791
|
+
description: string;
|
|
792
|
+
/** Visibility of the underlying data */
|
|
793
|
+
visibility: Visibility;
|
|
794
|
+
/** Data schema identifier (e.g., "orbitmem:dietary:v1") */
|
|
795
|
+
schema?: string;
|
|
796
|
+
/** Data category tags */
|
|
797
|
+
tags: DataTag[];
|
|
798
|
+
/** Whether the data is currently available */
|
|
799
|
+
active: boolean;
|
|
800
|
+
/** Owner wallet address */
|
|
801
|
+
owner: WalletAddress;
|
|
802
|
+
/** Owner chain family */
|
|
803
|
+
ownerChain: ChainFamily;
|
|
804
|
+
/** When the data was last updated (unix ms) */
|
|
805
|
+
lastUpdated: number;
|
|
806
|
+
/** When this registration was created */
|
|
807
|
+
registeredAt: number;
|
|
808
|
+
}
|
|
809
|
+
/** Standard data quality/verification tags */
|
|
810
|
+
export type DataTag = "verified" | "kyc-backed" | "self-attested" | "machine-generated" | "human-curated" | "time-sensitive" | "immutable" | string;
|
|
811
|
+
/** Data Registration File (resolves from dataURI, similar to agent registration) */
|
|
812
|
+
export interface DataRegistrationFile {
|
|
813
|
+
type: "https://eips.ethereum.org/EIPS/eip-8004#data-registration-v1";
|
|
814
|
+
name: string;
|
|
815
|
+
description: string;
|
|
816
|
+
/** Data schema/format */
|
|
817
|
+
schema?: {
|
|
818
|
+
/** Schema identifier (e.g., "orbitmem:dietary:v1") */
|
|
819
|
+
id: string;
|
|
820
|
+
/** Schema version */
|
|
821
|
+
version: string;
|
|
822
|
+
/** Link to schema definition */
|
|
823
|
+
definitionUrl?: string;
|
|
824
|
+
};
|
|
825
|
+
/** Access information */
|
|
826
|
+
access: {
|
|
827
|
+
/** OrbitMem vault address */
|
|
828
|
+
vaultAddress: string;
|
|
829
|
+
/** Vault path (nested) */
|
|
830
|
+
path: string;
|
|
831
|
+
/** Visibility level */
|
|
832
|
+
visibility: Visibility;
|
|
833
|
+
/** Required encryption engine for decryption */
|
|
834
|
+
encryptionEngine?: EncryptionEngine;
|
|
835
|
+
/** Relay node endpoint */
|
|
836
|
+
relayEndpoint: string;
|
|
837
|
+
};
|
|
838
|
+
/** Quality metadata */
|
|
839
|
+
quality: {
|
|
840
|
+
/** How often the data is updated */
|
|
841
|
+
updateFrequency?: "realtime" | "hourly" | "daily" | "weekly" | "monthly" | "static";
|
|
842
|
+
/** Data provenance / source */
|
|
843
|
+
provenance?: string;
|
|
844
|
+
/** Verification method */
|
|
845
|
+
verificationMethod?: "kyc" | "tee-attestation" | "zkml" | "oracle" | "self-attested";
|
|
846
|
+
};
|
|
847
|
+
tags: DataTag[];
|
|
848
|
+
active: boolean;
|
|
849
|
+
registrations: Array<{
|
|
850
|
+
dataId: number;
|
|
851
|
+
dataRegistry: string;
|
|
852
|
+
}>;
|
|
853
|
+
}
|
|
854
|
+
/**
|
|
855
|
+
* Aggregated data quality score.
|
|
856
|
+
*
|
|
857
|
+
* Agents use this to decide whether to consume a data source.
|
|
858
|
+
* Scores are derived from on-chain feedback submitted by agents
|
|
859
|
+
* who have previously consumed this data.
|
|
860
|
+
*/
|
|
861
|
+
export interface DataScore {
|
|
862
|
+
/** Data Registration ID */
|
|
863
|
+
dataId: number;
|
|
864
|
+
/** Vault address of the data owner */
|
|
865
|
+
vaultAddress: OrbitAddress;
|
|
866
|
+
/** Vault key */
|
|
867
|
+
vaultKey: string;
|
|
868
|
+
/** Overall quality score (0-100) */
|
|
869
|
+
quality: number;
|
|
870
|
+
/** Freshness — how recently the data was updated */
|
|
871
|
+
freshness: {
|
|
872
|
+
lastUpdated: number;
|
|
873
|
+
/** Freshness score (0-100, decays over time) */
|
|
874
|
+
score: number;
|
|
875
|
+
};
|
|
876
|
+
/** Accuracy — based on agent feedback after consumption */
|
|
877
|
+
accuracy: {
|
|
878
|
+
score: number;
|
|
879
|
+
feedbackCount: number;
|
|
880
|
+
};
|
|
881
|
+
/** Completeness — whether data has all expected fields */
|
|
882
|
+
completeness: {
|
|
883
|
+
score: number;
|
|
884
|
+
feedbackCount: number;
|
|
885
|
+
};
|
|
886
|
+
/** Whether the data has been independently verified */
|
|
887
|
+
verified: boolean;
|
|
888
|
+
/** Verification method used */
|
|
889
|
+
verificationMethod?: string;
|
|
890
|
+
/** Total number of times agents have consumed this data */
|
|
891
|
+
consumptionCount: number;
|
|
892
|
+
/** Total feedback entries */
|
|
893
|
+
totalFeedback: number;
|
|
894
|
+
/** Breakdown by tag */
|
|
895
|
+
tagScores: Record<string, {
|
|
896
|
+
value: number;
|
|
897
|
+
count: number;
|
|
898
|
+
}>;
|
|
899
|
+
}
|
|
900
|
+
/** Feedback specifically about data quality (agent → data) */
|
|
901
|
+
export interface DataFeedbackEntry extends FeedbackEntry {
|
|
902
|
+
/** The vault key the feedback is about */
|
|
903
|
+
vaultKey: string;
|
|
904
|
+
/** Specific quality dimension */
|
|
905
|
+
qualityDimension?: "accuracy" | "completeness" | "freshness" | "schema-compliance" | "usefulness";
|
|
906
|
+
}
|
|
907
|
+
/** Discovery Layer interface — bidirectional trust protocol */
|
|
908
|
+
export interface IDiscoveryLayer {
|
|
909
|
+
/**
|
|
910
|
+
* Register a vault entry as an on-chain discoverable data asset.
|
|
911
|
+
* Mints an ERC-721 token in the Data Registry.
|
|
912
|
+
*
|
|
913
|
+
* This allows agents to discover and evaluate the data before
|
|
914
|
+
* requesting access. The registration includes quality metadata,
|
|
915
|
+
* schema info, and access instructions.
|
|
916
|
+
*/
|
|
917
|
+
registerData(opts: {
|
|
918
|
+
/** Vault path to register (e.g. "travel/dietary") */
|
|
919
|
+
key: string;
|
|
920
|
+
/** Human-readable name */
|
|
921
|
+
name: string;
|
|
922
|
+
/** Description */
|
|
923
|
+
description: string;
|
|
924
|
+
/** Schema identifier */
|
|
925
|
+
schema?: string;
|
|
926
|
+
/** Quality/verification tags */
|
|
927
|
+
tags: DataTag[];
|
|
928
|
+
/** Data registration file URI (IPFS, HTTPS, or data: URI) */
|
|
929
|
+
registrationURI?: string;
|
|
930
|
+
}): Promise<DataRegistration>;
|
|
931
|
+
/**
|
|
932
|
+
* Update an existing data registration (e.g., after data changes).
|
|
933
|
+
*/
|
|
934
|
+
updateDataRegistration(dataId: number, updates: Partial<Pick<DataRegistration, "name" | "description" | "tags" | "active">>): Promise<DataRegistration>;
|
|
935
|
+
/**
|
|
936
|
+
* Search for data assets by query.
|
|
937
|
+
* Agents use this to discover available data sources.
|
|
938
|
+
*/
|
|
939
|
+
findData(query: {
|
|
940
|
+
/** Search by keyword in name/description */
|
|
941
|
+
keyword?: string;
|
|
942
|
+
/** Filter by schema */
|
|
943
|
+
schema?: string;
|
|
944
|
+
/** Filter by tags */
|
|
945
|
+
tags?: DataTag[];
|
|
946
|
+
/** Filter by visibility */
|
|
947
|
+
visibility?: Visibility;
|
|
948
|
+
/** Minimum quality score */
|
|
949
|
+
minQuality?: number;
|
|
950
|
+
/** Only verified data */
|
|
951
|
+
verifiedOnly?: boolean;
|
|
952
|
+
/** Only data updated within this many milliseconds */
|
|
953
|
+
maxAge?: number;
|
|
954
|
+
limit?: number;
|
|
955
|
+
}): Promise<DataRegistration[]>;
|
|
956
|
+
/**
|
|
957
|
+
* Get the aggregated quality score for a data source.
|
|
958
|
+
* Agents call this to evaluate data before consuming.
|
|
959
|
+
*/
|
|
960
|
+
getDataScore(vaultAddress: OrbitAddress, path: string): Promise<DataScore>;
|
|
961
|
+
/**
|
|
962
|
+
* Get the quality score by data registration ID.
|
|
963
|
+
*/
|
|
964
|
+
getDataScoreById(dataId: number): Promise<DataScore>;
|
|
965
|
+
/**
|
|
966
|
+
* Submit feedback about data quality (agent → data).
|
|
967
|
+
* Called by agents after consuming data.
|
|
968
|
+
*/
|
|
969
|
+
rateData(feedback: {
|
|
970
|
+
/** Data Registration ID */
|
|
971
|
+
dataId: number;
|
|
972
|
+
/** Score value */
|
|
973
|
+
value: number;
|
|
974
|
+
valueDecimals?: number;
|
|
975
|
+
/** Quality dimension being rated */
|
|
976
|
+
qualityDimension?: "accuracy" | "completeness" | "freshness" | "schema-compliance" | "usefulness";
|
|
977
|
+
/** Primary tag */
|
|
978
|
+
tag1?: string;
|
|
979
|
+
/** Secondary tag */
|
|
980
|
+
tag2?: string;
|
|
981
|
+
feedbackURI?: string;
|
|
982
|
+
}): Promise<{
|
|
983
|
+
txHash: string;
|
|
984
|
+
feedbackIndex: number;
|
|
985
|
+
}>;
|
|
986
|
+
/**
|
|
987
|
+
* Request task validation via the Validation Registry.
|
|
988
|
+
*/
|
|
989
|
+
requestValidation(request: {
|
|
990
|
+
agentId: number;
|
|
991
|
+
taskId: string;
|
|
992
|
+
method: "stake-reexecution" | "zkml" | "tee" | "trusted-judge";
|
|
993
|
+
taskData?: Uint8Array;
|
|
994
|
+
}): Promise<ValidationRequest>;
|
|
995
|
+
/**
|
|
996
|
+
* Check validation status.
|
|
997
|
+
*/
|
|
998
|
+
getValidationStatus(agentId: number, taskId: string): Promise<ValidationRequest | null>;
|
|
999
|
+
/**
|
|
1000
|
+
* Create a Lit access condition gated on data quality score.
|
|
1001
|
+
* Agents can require minimum data quality before processing.
|
|
1002
|
+
* (Used in agent-side logic, not encryption.)
|
|
1003
|
+
*/
|
|
1004
|
+
createDataQualityCondition(opts: {
|
|
1005
|
+
minQuality: number;
|
|
1006
|
+
verifiedOnly?: boolean;
|
|
1007
|
+
maxAge?: number;
|
|
1008
|
+
}): LitEvmCondition;
|
|
1009
|
+
}
|
|
1010
|
+
/** Full OrbitMem SDK configuration */
|
|
1011
|
+
export interface OrbitMemConfig {
|
|
1012
|
+
/** Network preset — "base-sepolia" (default) or "base" (mainnet).
|
|
1013
|
+
* Sets contract addresses and relay URL. Overridden by explicit
|
|
1014
|
+
* discovery/persistence config. */
|
|
1015
|
+
network?: import("./contracts.js").NetworkId;
|
|
1016
|
+
/** Identity layer config */
|
|
1017
|
+
identity: IdentityConfig;
|
|
1018
|
+
/** Vault (data layer) config */
|
|
1019
|
+
vault?: VaultConfig;
|
|
1020
|
+
/** Encryption layer config */
|
|
1021
|
+
encryption?: EncryptionConfig;
|
|
1022
|
+
/** Persistence layer config */
|
|
1023
|
+
persistence?: StorachaConfig;
|
|
1024
|
+
/** Discovery layer config (ERC-8004 bidirectional trust) */
|
|
1025
|
+
discovery?: DiscoveryConfig;
|
|
1026
|
+
/** Enable debug logging */
|
|
1027
|
+
debug?: boolean;
|
|
1028
|
+
}
|
|
1029
|
+
/**
|
|
1030
|
+
* The OrbitMem SDK client.
|
|
1031
|
+
*
|
|
1032
|
+
* Usage:
|
|
1033
|
+
* ```ts
|
|
1034
|
+
* import { createOrbitMem } from '@orbitmem/sdk';
|
|
1035
|
+
*
|
|
1036
|
+
* const orbitmem = await createOrbitMem({
|
|
1037
|
+
* identity: {
|
|
1038
|
+
* chains: ['passkey', 'evm', 'solana'],
|
|
1039
|
+
* passkey: {
|
|
1040
|
+
* rpId: 'app.orbitmem.xyz',
|
|
1041
|
+
* rpName: 'OrbitMem',
|
|
1042
|
+
* delegationChain: 'base',
|
|
1043
|
+
* },
|
|
1044
|
+
* evm: { chains: ['base', 'ethereum'], adapters: ['metamask'] },
|
|
1045
|
+
* solana: { cluster: 'mainnet-beta', adapters: ['phantom'] },
|
|
1046
|
+
* },
|
|
1047
|
+
* encryption: { defaultEngine: 'lit' },
|
|
1048
|
+
* persistence: { mock: true },
|
|
1049
|
+
* });
|
|
1050
|
+
*
|
|
1051
|
+
* // Connect via Passkey (biometric — zero extensions)
|
|
1052
|
+
* const conn = await orbitmem.connect({ method: 'passkey' });
|
|
1053
|
+
*
|
|
1054
|
+
* // Or connect via traditional wallet
|
|
1055
|
+
* // const conn = await orbitmem.connect({ method: 'evm' });
|
|
1056
|
+
*
|
|
1057
|
+
* // Store shared data — per-path visibility with nested-db
|
|
1058
|
+
* await orbitmem.vault.put('travel/dietary', 'vegan', {
|
|
1059
|
+
* visibility: 'public', // agents can read freely
|
|
1060
|
+
* });
|
|
1061
|
+
*
|
|
1062
|
+
* await orbitmem.vault.put('travel/budget', { min: 1000, max: 2000 }, {
|
|
1063
|
+
* visibility: 'shared',
|
|
1064
|
+
* engine: 'lit',
|
|
1065
|
+
* accessConditions: [reputationCondition({ minScore: 70 })],
|
|
1066
|
+
* });
|
|
1067
|
+
*
|
|
1068
|
+
* await orbitmem.vault.put('travel/passport', { number: 'XX123' }, {
|
|
1069
|
+
* visibility: 'private', // owner-only, AES encrypted
|
|
1070
|
+
* });
|
|
1071
|
+
*
|
|
1072
|
+
* // Or bulk insert a nested object
|
|
1073
|
+
* await orbitmem.vault.insert({
|
|
1074
|
+
* profile: { name: 'Alice', bio: 'Traveler' },
|
|
1075
|
+
* }, { visibility: 'public' });
|
|
1076
|
+
*
|
|
1077
|
+
* // Read subtree
|
|
1078
|
+
* await orbitmem.vault.get('travel');
|
|
1079
|
+
* // → { dietary: 'vegan', budget: { min: 1000, max: 2000 }, passport: { number: 'XX123' } }
|
|
1080
|
+
*
|
|
1081
|
+
* // Register for agent discovery (ERC-8004)
|
|
1082
|
+
* await orbitmem.discovery.registerData({
|
|
1083
|
+
* key: 'travel/dietary',
|
|
1084
|
+
* name: 'Dietary Preferences',
|
|
1085
|
+
* description: 'Dietary restrictions for booking agents',
|
|
1086
|
+
* tags: ['verified', 'human-curated'],
|
|
1087
|
+
* });
|
|
1088
|
+
* ```
|
|
1089
|
+
*/
|
|
1090
|
+
export interface IOrbitMem {
|
|
1091
|
+
/** Identity layer — wallet connection & session management */
|
|
1092
|
+
readonly identity: IIdentityLayer;
|
|
1093
|
+
/** Data layer — local-first P2P vault */
|
|
1094
|
+
readonly vault: IDataLayer;
|
|
1095
|
+
/** Encryption layer — Lit Protocol & AES-256-GCM */
|
|
1096
|
+
readonly encryption: IEncryptionLayer;
|
|
1097
|
+
/** Transport layer — ERC-8128 signed HTTP */
|
|
1098
|
+
readonly transport: ITransportLayer;
|
|
1099
|
+
/** Persistence layer — Storacha / Filecoin archival */
|
|
1100
|
+
readonly persistence: IPersistenceLayer;
|
|
1101
|
+
/** Discovery layer — ERC-8004 agent trust & reputation */
|
|
1102
|
+
readonly discovery: IDiscoveryLayer;
|
|
1103
|
+
/** Vault pricing CRUD (MPP pay-per-read) */
|
|
1104
|
+
readonly pricing: IVaultPricing;
|
|
1105
|
+
/**
|
|
1106
|
+
* Connect a wallet or passkey (shortcut for identity.connect).
|
|
1107
|
+
*/
|
|
1108
|
+
connect(opts: {
|
|
1109
|
+
method: ChainFamily;
|
|
1110
|
+
adapter?: EvmWalletAdapter | SolanaWalletAdapter;
|
|
1111
|
+
}): Promise<WalletConnection>;
|
|
1112
|
+
/**
|
|
1113
|
+
* Disconnect and clean up all layers.
|
|
1114
|
+
*/
|
|
1115
|
+
disconnect(): Promise<void>;
|
|
1116
|
+
/**
|
|
1117
|
+
* Encrypt data with the configured default engine.
|
|
1118
|
+
*/
|
|
1119
|
+
encrypt(data: Uint8Array | string, opts: EncryptLitOptions | EncryptAESOptions): Promise<EncryptedData>;
|
|
1120
|
+
/**
|
|
1121
|
+
* Decrypt data (auto-detects engine).
|
|
1122
|
+
*/
|
|
1123
|
+
decrypt(encrypted: EncryptedData, opts?: DecryptOptions): Promise<Uint8Array>;
|
|
1124
|
+
/**
|
|
1125
|
+
* Destroy the client and release all resources.
|
|
1126
|
+
*/
|
|
1127
|
+
destroy(): Promise<void>;
|
|
1128
|
+
}
|
|
1129
|
+
/** Factory function signature */
|
|
1130
|
+
export declare function createOrbitMem(config: OrbitMemConfig): Promise<IOrbitMem>;
|
|
1131
|
+
/**
|
|
1132
|
+
* Agent-side adapter for reading OrbitMem-encrypted data.
|
|
1133
|
+
* This is what an OpenClaw agent (or any framework) would use
|
|
1134
|
+
* to fetch and decrypt user data from the Relay Node.
|
|
1135
|
+
*/
|
|
1136
|
+
export interface IOrbitMemClient {
|
|
1137
|
+
/**
|
|
1138
|
+
* Discover registered data sources by query.
|
|
1139
|
+
* Agents use this to find available data from users.
|
|
1140
|
+
*/
|
|
1141
|
+
discoverData(query: {
|
|
1142
|
+
keyword?: string;
|
|
1143
|
+
schema?: string;
|
|
1144
|
+
tags?: DataTag[];
|
|
1145
|
+
minQuality?: number;
|
|
1146
|
+
verifiedOnly?: boolean;
|
|
1147
|
+
maxAge?: number;
|
|
1148
|
+
limit?: number;
|
|
1149
|
+
}): Promise<DataRegistration[]>;
|
|
1150
|
+
/**
|
|
1151
|
+
* Get the quality score for a specific data source.
|
|
1152
|
+
* Agents should check this BEFORE consuming data.
|
|
1153
|
+
*/
|
|
1154
|
+
getDataScore(vaultAddress: OrbitAddress, path: string): Promise<DataScore>;
|
|
1155
|
+
/**
|
|
1156
|
+
* Submit feedback about consumed data quality (agent → data).
|
|
1157
|
+
* Called after the agent has used the data for a task.
|
|
1158
|
+
*/
|
|
1159
|
+
rateData(feedback: {
|
|
1160
|
+
dataId: number;
|
|
1161
|
+
value: number;
|
|
1162
|
+
valueDecimals?: number;
|
|
1163
|
+
qualityDimension?: "accuracy" | "completeness" | "freshness" | "schema-compliance" | "usefulness";
|
|
1164
|
+
tag1?: string;
|
|
1165
|
+
tag2?: string;
|
|
1166
|
+
feedbackURI?: string;
|
|
1167
|
+
}): Promise<{
|
|
1168
|
+
txHash: string;
|
|
1169
|
+
feedbackIndex: number;
|
|
1170
|
+
}>;
|
|
1171
|
+
/**
|
|
1172
|
+
* Read public (unencrypted) data from a user's vault.
|
|
1173
|
+
* No decryption or access conditions needed — public data is plaintext.
|
|
1174
|
+
* Uses ERC-8128 signed request for transport authentication only.
|
|
1175
|
+
*/
|
|
1176
|
+
readPublicData<T = unknown>(request: {
|
|
1177
|
+
/** The user's vault address (OrbitDB) */
|
|
1178
|
+
vaultAddress: OrbitAddress;
|
|
1179
|
+
/** The nested path to read */
|
|
1180
|
+
path: string;
|
|
1181
|
+
/** Relay node URL */
|
|
1182
|
+
relayUrl: string;
|
|
1183
|
+
}): Promise<T | null>;
|
|
1184
|
+
/**
|
|
1185
|
+
* List all public keys in a user's vault.
|
|
1186
|
+
* Useful for agent discovery — see what data a user has made available.
|
|
1187
|
+
*/
|
|
1188
|
+
listPublicKeys(request: {
|
|
1189
|
+
vaultAddress: OrbitAddress;
|
|
1190
|
+
relayUrl: string;
|
|
1191
|
+
prefix?: string;
|
|
1192
|
+
}): Promise<string[]>;
|
|
1193
|
+
/**
|
|
1194
|
+
* Fetch encrypted (private/shared) data from a OrbitMem Relay Node.
|
|
1195
|
+
* Uses ERC-8128 signed request for authentication.
|
|
1196
|
+
*/
|
|
1197
|
+
fetchUserData(request: {
|
|
1198
|
+
/** The user's vault address (OrbitDB) */
|
|
1199
|
+
vaultAddress: OrbitAddress;
|
|
1200
|
+
/** The nested path to read */
|
|
1201
|
+
path: string;
|
|
1202
|
+
/** Relay node URL */
|
|
1203
|
+
relayUrl: string;
|
|
1204
|
+
}): Promise<EncryptedData>;
|
|
1205
|
+
/**
|
|
1206
|
+
* Decrypt fetched data.
|
|
1207
|
+
* For Lit: The agent must meet the access conditions.
|
|
1208
|
+
* For AES: The agent must have the shared key.
|
|
1209
|
+
*/
|
|
1210
|
+
decrypt(encrypted: EncryptedData, opts?: {
|
|
1211
|
+
/** For AES: shared key provided by the user out-of-band */
|
|
1212
|
+
sharedKey?: Uint8Array;
|
|
1213
|
+
}): Promise<Uint8Array>;
|
|
1214
|
+
/**
|
|
1215
|
+
* Full lifecycle: discover → evaluate → fetch → decrypt → execute → rate.
|
|
1216
|
+
*
|
|
1217
|
+
* 1. Checks data score (rejects if below minQuality threshold)
|
|
1218
|
+
* 2. Fetches encrypted data
|
|
1219
|
+
* 3. Decrypts and passes plaintext to callback
|
|
1220
|
+
* 4. Zeroes plaintext buffer after callback
|
|
1221
|
+
* 5. Optionally submits quality feedback
|
|
1222
|
+
*/
|
|
1223
|
+
withUserData<R>(request: {
|
|
1224
|
+
vaultAddress: OrbitAddress;
|
|
1225
|
+
path: string;
|
|
1226
|
+
relayUrl: string;
|
|
1227
|
+
/** Reject data below this quality score (default: from config) */
|
|
1228
|
+
minQuality?: number;
|
|
1229
|
+
}, callback: (plaintext: Uint8Array, dataScore: DataScore) => Promise<R>, opts?: {
|
|
1230
|
+
sharedKey?: Uint8Array;
|
|
1231
|
+
/** Auto-submit quality feedback after execution */
|
|
1232
|
+
autoRate?: {
|
|
1233
|
+
value: number;
|
|
1234
|
+
qualityDimension?: "accuracy" | "completeness" | "freshness" | "schema-compliance" | "usefulness";
|
|
1235
|
+
};
|
|
1236
|
+
}): Promise<R>;
|
|
1237
|
+
}
|
|
1238
|
+
/** @deprecated Use IOrbitMemClient instead */
|
|
1239
|
+
export type IOrbitMemAgentAdapter = IOrbitMemClient;
|
|
1240
|
+
/** Client configuration */
|
|
1241
|
+
export interface ClientConfig {
|
|
1242
|
+
/** The agent's wallet connection (for signing requests & Lit auth) */
|
|
1243
|
+
wallet: {
|
|
1244
|
+
family: ChainFamily;
|
|
1245
|
+
address: WalletAddress;
|
|
1246
|
+
signMessage: (message: Uint8Array) => Promise<Uint8Array>;
|
|
1247
|
+
};
|
|
1248
|
+
/** Lit Protocol config (if agent needs Lit decryption) */
|
|
1249
|
+
lit?: EncryptionConfig["lit"];
|
|
1250
|
+
/** Discovery config (for data evaluation) */
|
|
1251
|
+
discovery?: {
|
|
1252
|
+
/** Data Registry contract address */
|
|
1253
|
+
dataRegistry: EvmAddress;
|
|
1254
|
+
/** Reputation Registry contract address */
|
|
1255
|
+
reputationRegistry: EvmAddress;
|
|
1256
|
+
/** Registry chain */
|
|
1257
|
+
registryChain: EvmChain;
|
|
1258
|
+
/** Minimum data quality score to accept (default: 0 = accept all) */
|
|
1259
|
+
minDataQuality?: number;
|
|
1260
|
+
};
|
|
1261
|
+
}
|
|
1262
|
+
/** @deprecated Use ClientConfig instead */
|
|
1263
|
+
export type AgentAdapterConfig = ClientConfig;
|
|
1264
|
+
/** Factory for client */
|
|
1265
|
+
export declare function createOrbitMemClient(config: ClientConfig): IOrbitMemClient;
|
|
1266
|
+
/** @deprecated Use createOrbitMemClient instead */
|
|
1267
|
+
export declare function createOrbitMemAgentAdapter(config: ClientConfig): IOrbitMemClient;
|
|
1268
|
+
export type OrbitMemEvent = {
|
|
1269
|
+
type: "connection:changed";
|
|
1270
|
+
connection: WalletConnection | null;
|
|
1271
|
+
} | {
|
|
1272
|
+
type: "session:created";
|
|
1273
|
+
session: SessionKey;
|
|
1274
|
+
} | {
|
|
1275
|
+
type: "session:expired";
|
|
1276
|
+
sessionId: string;
|
|
1277
|
+
} | {
|
|
1278
|
+
type: "vault:updated";
|
|
1279
|
+
path: string;
|
|
1280
|
+
entry: VaultEntry;
|
|
1281
|
+
} | {
|
|
1282
|
+
type: "vault:deleted";
|
|
1283
|
+
path: string;
|
|
1284
|
+
} | {
|
|
1285
|
+
type: "vault:synced";
|
|
1286
|
+
status: SyncStatus;
|
|
1287
|
+
} | {
|
|
1288
|
+
type: "snapshot:archived";
|
|
1289
|
+
snapshot: Snapshot;
|
|
1290
|
+
} | {
|
|
1291
|
+
type: "snapshot:restored";
|
|
1292
|
+
cid: CID;
|
|
1293
|
+
merged: number;
|
|
1294
|
+
} | {
|
|
1295
|
+
type: "discovery:dataRegistered";
|
|
1296
|
+
data: DataRegistration;
|
|
1297
|
+
} | {
|
|
1298
|
+
type: "discovery:dataRated";
|
|
1299
|
+
dataId: number;
|
|
1300
|
+
txHash: string;
|
|
1301
|
+
} | {
|
|
1302
|
+
type: "discovery:validationComplete";
|
|
1303
|
+
agentId: number;
|
|
1304
|
+
taskId: string;
|
|
1305
|
+
status: string;
|
|
1306
|
+
} | {
|
|
1307
|
+
type: "error";
|
|
1308
|
+
layer: string;
|
|
1309
|
+
error: Error;
|
|
1310
|
+
};
|
|
1311
|
+
export interface IOrbitMemEventEmitter {
|
|
1312
|
+
on<E extends OrbitMemEvent["type"]>(event: E, handler: (payload: Extract<OrbitMemEvent, {
|
|
1313
|
+
type: E;
|
|
1314
|
+
}>) => void): () => void;
|
|
1315
|
+
once<E extends OrbitMemEvent["type"]>(event: E, handler: (payload: Extract<OrbitMemEvent, {
|
|
1316
|
+
type: E;
|
|
1317
|
+
}>) => void): () => void;
|
|
1318
|
+
}
|
|
1319
|
+
//# sourceMappingURL=types.d.ts.map
|