@q00bs/agent-sdk 1.0.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.
Files changed (85) hide show
  1. package/dist/Q00bsAgent.d.ts +331 -0
  2. package/dist/Q00bsAgent.d.ts.map +1 -0
  3. package/dist/Q00bsAgent.js +695 -0
  4. package/dist/Q00bsAgent.js.map +1 -0
  5. package/dist/abis/AgentEscrow.d.ts +336 -0
  6. package/dist/abis/AgentEscrow.d.ts.map +1 -0
  7. package/dist/abis/AgentEscrow.js +206 -0
  8. package/dist/abis/AgentEscrow.js.map +1 -0
  9. package/dist/abis/AgentRegistry.d.ts +496 -0
  10. package/dist/abis/AgentRegistry.d.ts.map +1 -0
  11. package/dist/abis/AgentRegistry.js +280 -0
  12. package/dist/abis/AgentRegistry.js.map +1 -0
  13. package/dist/abis/ConsensusModule.d.ts +270 -0
  14. package/dist/abis/ConsensusModule.d.ts.map +1 -0
  15. package/dist/abis/ConsensusModule.js +157 -0
  16. package/dist/abis/ConsensusModule.js.map +1 -0
  17. package/dist/abis/ERC8004Identity.d.ts +293 -0
  18. package/dist/abis/ERC8004Identity.d.ts.map +1 -0
  19. package/dist/abis/ERC8004Identity.js +223 -0
  20. package/dist/abis/ERC8004Identity.js.map +1 -0
  21. package/dist/abis/ERC8004Reputation.d.ts +362 -0
  22. package/dist/abis/ERC8004Reputation.d.ts.map +1 -0
  23. package/dist/abis/ERC8004Reputation.js +229 -0
  24. package/dist/abis/ERC8004Reputation.js.map +1 -0
  25. package/dist/abis/ERC8004Validation.d.ts +234 -0
  26. package/dist/abis/ERC8004Validation.d.ts.map +1 -0
  27. package/dist/abis/ERC8004Validation.js +162 -0
  28. package/dist/abis/ERC8004Validation.js.map +1 -0
  29. package/dist/abis/Q00bFactory.d.ts +123 -0
  30. package/dist/abis/Q00bFactory.d.ts.map +1 -0
  31. package/dist/abis/Q00bFactory.js +65 -0
  32. package/dist/abis/Q00bFactory.js.map +1 -0
  33. package/dist/abis/TheQ00bs.d.ts +119 -0
  34. package/dist/abis/TheQ00bs.d.ts.map +1 -0
  35. package/dist/abis/TheQ00bs.js +73 -0
  36. package/dist/abis/TheQ00bs.js.map +1 -0
  37. package/dist/abis/index.d.ts +9 -0
  38. package/dist/abis/index.d.ts.map +1 -0
  39. package/dist/abis/index.js +17 -0
  40. package/dist/abis/index.js.map +1 -0
  41. package/dist/client.d.ts +111 -0
  42. package/dist/client.d.ts.map +1 -0
  43. package/dist/client.js +134 -0
  44. package/dist/client.js.map +1 -0
  45. package/dist/consensus.d.ts +85 -0
  46. package/dist/consensus.d.ts.map +1 -0
  47. package/dist/consensus.js +227 -0
  48. package/dist/consensus.js.map +1 -0
  49. package/dist/constants.d.ts +85 -0
  50. package/dist/constants.d.ts.map +1 -0
  51. package/dist/constants.js +113 -0
  52. package/dist/constants.js.map +1 -0
  53. package/dist/discovery.d.ts +70 -0
  54. package/dist/discovery.d.ts.map +1 -0
  55. package/dist/discovery.js +214 -0
  56. package/dist/discovery.js.map +1 -0
  57. package/dist/erc8004.d.ts +311 -0
  58. package/dist/erc8004.d.ts.map +1 -0
  59. package/dist/erc8004.js +824 -0
  60. package/dist/erc8004.js.map +1 -0
  61. package/dist/errors.d.ts +107 -0
  62. package/dist/errors.d.ts.map +1 -0
  63. package/dist/errors.js +210 -0
  64. package/dist/errors.js.map +1 -0
  65. package/dist/escrow.d.ts +86 -0
  66. package/dist/escrow.d.ts.map +1 -0
  67. package/dist/escrow.js +267 -0
  68. package/dist/escrow.js.map +1 -0
  69. package/dist/index.d.ts +51 -0
  70. package/dist/index.d.ts.map +1 -0
  71. package/dist/index.js +118 -0
  72. package/dist/index.js.map +1 -0
  73. package/dist/privy.d.ts +197 -0
  74. package/dist/privy.d.ts.map +1 -0
  75. package/dist/privy.js +524 -0
  76. package/dist/privy.js.map +1 -0
  77. package/dist/trust.d.ts +49 -0
  78. package/dist/trust.d.ts.map +1 -0
  79. package/dist/trust.js +117 -0
  80. package/dist/trust.js.map +1 -0
  81. package/dist/types.d.ts +472 -0
  82. package/dist/types.d.ts.map +1 -0
  83. package/dist/types.js +36 -0
  84. package/dist/types.js.map +1 -0
  85. package/package.json +30 -0
@@ -0,0 +1,197 @@
1
+ /**
2
+ * @q00bs/agent-sdk — Privy Wallet Manager
3
+ *
4
+ * This module integrates Privy's server-side wallet API to give each
5
+ * Q00bs agent a custody-free wallet with built-in spending policies.
6
+ *
7
+ * WHY THIS EXISTS:
8
+ * Raw private keys in env vars are a security liability for autonomous agents.
9
+ * Privy holds key material in a secure enclave and enforces transaction policies
10
+ * BEFORE signing. This is the same pattern used by OpenClaw agents:
11
+ * https://privy.io/blog/securely-equipping-openclaw-agents-with-privy-wallets
12
+ *
13
+ * ARCHITECTURE:
14
+ * ┌──────────────────┐ ┌──────────────────┐ ┌────────────┐
15
+ * │ Q00bsAgent SDK │────▶│ Privy Server API │────▶│ Base L2 │
16
+ * │ (your agent) │ │ (policy check + │ │ (on-chain) │
17
+ * │ │ │ key custody) │ │ │
18
+ * └──────────────────┘ └──────────────────┘ └────────────┘
19
+ *
20
+ * 1. Agent calls createWallet() or getWallet() via this module.
21
+ * 2. Privy provisions a wallet with a policy (spend limits, allowed contracts).
22
+ * 3. Agent sends transactions via sendTransaction() — Privy checks policy, signs, broadcasts.
23
+ * 4. Private key NEVER leaves Privy's secure infrastructure.
24
+ *
25
+ * SECURITY PRINCIPLES (from Privy's guide):
26
+ * 1. Always attach policies at wallet creation
27
+ * 2. Validate every transaction (destination, amount, chain)
28
+ * 3. Protect credentials (app secret never in agent prompts/memory)
29
+ * 4. Guard against prompt injection
30
+ * 5. Require explicit confirmation for security-weakening changes
31
+ */
32
+ import type { PrivyConfig, PrivyWalletPolicy, PrivyWalletInfo, PrivyTransactionRequest, PrivyTransactionResult, Logger } from './types';
33
+ /**
34
+ * Manages Privy server wallets for Q00bs agents.
35
+ *
36
+ * Each agent gets a dedicated wallet with a policy that mirrors its
37
+ * on-chain AgentPermissions. Three layers of defense:
38
+ * Layer 1: Privy policy (server-side, instant reject)
39
+ * Layer 2: SDK pre-validation (local check before API call)
40
+ * Layer 3: Smart contract modifiers (on-chain, final authority)
41
+ *
42
+ * USAGE:
43
+ * ```ts
44
+ * const manager = new PrivyWalletManager({
45
+ * appId: process.env.PRIVY_APP_ID!,
46
+ * appSecret: process.env.PRIVY_APP_SECRET!,
47
+ * }, logger);
48
+ *
49
+ * // Create a new agent wallet with spending policies
50
+ * const wallet = await manager.createWallet({
51
+ * name: 'ResearchBot #47 Limits',
52
+ * rules: [
53
+ * { type: 'max_transaction_value', value: '0.1' },
54
+ * { type: 'daily_spend_limit', value: '1.0' },
55
+ * { type: 'allowed_chains', value: [8453] }, // Base only
56
+ * { type: 'allowed_contracts', value: ['0xRegistryAddress', '0xEscrowAddress'] },
57
+ * ],
58
+ * });
59
+ *
60
+ * // Send a transaction through Privy (policy-checked + signed)
61
+ * const result = await manager.sendTransaction(wallet.walletId, {
62
+ * to: '0xEscrowContract',
63
+ * data: '0x...', // encoded createEscrow() call
64
+ * value: '0x2386F26FC10000', // 0.01 ETH in hex
65
+ * });
66
+ * ```
67
+ */
68
+ export declare class PrivyWalletManager {
69
+ private config;
70
+ private logger;
71
+ private authHeaders;
72
+ private _walletInfo?;
73
+ /** The current wallet info (set after createWallet/getWallet). */
74
+ get walletInfo(): PrivyWalletInfo | undefined;
75
+ /** The wallet's Ethereum address (or undefined if not initialized). */
76
+ get address(): string | undefined;
77
+ constructor(config: PrivyConfig, logger: Logger);
78
+ /**
79
+ * Create a new Privy server wallet for this agent.
80
+ *
81
+ * This provisions a fresh Ethereum wallet in Privy's secure enclave
82
+ * and attaches the specified spending policy. The private key NEVER
83
+ * leaves Privy — it exists only in their HSM.
84
+ *
85
+ * @param policy - Spending policy to enforce on this wallet.
86
+ * @returns Info about the newly created wallet.
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * const wallet = await manager.createWallet({
91
+ * name: 'DataBot Spending Limits',
92
+ * rules: [
93
+ * { type: 'max_transaction_value', value: '0.1', description: 'Max 0.1 ETH per tx' },
94
+ * { type: 'daily_spend_limit', value: '1.0', description: 'Max 1 ETH per day' },
95
+ * { type: 'allowed_chains', value: [8453] },
96
+ * ],
97
+ * });
98
+ * console.log(`Agent wallet created: ${wallet.address}`);
99
+ * ```
100
+ */
101
+ createWallet(policy?: PrivyWalletPolicy): Promise<PrivyWalletInfo>;
102
+ /**
103
+ * Retrieve an existing Privy wallet by its ID.
104
+ *
105
+ * @param walletId - The Privy wallet ID (from a previous createWallet call).
106
+ * @returns Info about the existing wallet.
107
+ */
108
+ getWallet(walletId: string): Promise<PrivyWalletInfo>;
109
+ /**
110
+ * Initialize the wallet — either load an existing one or create a new one.
111
+ *
112
+ * @param policy - Policy to use if creating a new wallet.
113
+ * @returns The wallet info.
114
+ */
115
+ initialize(policy?: PrivyWalletPolicy): Promise<PrivyWalletInfo>;
116
+ /**
117
+ * Attach or update a spending policy on a Privy wallet.
118
+ *
119
+ * Policies are the key security layer for agentic wallets. They define:
120
+ * - Max value per transaction
121
+ * - Daily spending cap
122
+ * - Allowed contract addresses (whitelist)
123
+ * - Allowed chains (e.g. Base only)
124
+ * - Function selector whitelist
125
+ * - Human approval requirements for high-value actions
126
+ *
127
+ * @param walletId - The wallet to apply the policy to.
128
+ * @param policy - The policy definition.
129
+ */
130
+ setPolicy(walletId: string, policy: PrivyWalletPolicy): Promise<void>;
131
+ /**
132
+ * Build a default policy from Q00bs AgentPermissions.
133
+ *
134
+ * This translates on-chain permission parameters into Privy policy rules,
135
+ * ensuring the server-side guard matches the on-chain guard.
136
+ *
137
+ * @param maxTxValueEth - Max ETH per transaction (e.g. '0.1').
138
+ * @param dailyLimitEth - Max ETH per day (e.g. '1.0').
139
+ * @param allowedContracts - Contract addresses the agent can interact with.
140
+ * @param requireHumanApproval - Whether to require human approval for high-value txs.
141
+ * @returns A PrivyWalletPolicy ready to attach.
142
+ */
143
+ static buildDefaultPolicy(maxTxValueEth?: string, dailyLimitEth?: string, allowedContracts?: string[], requireHumanApproval?: boolean): PrivyWalletPolicy;
144
+ /**
145
+ * Send a transaction through Privy.
146
+ *
147
+ * Privy validates the transaction against the wallet's policy BEFORE signing.
148
+ * If the policy rejects it, a PrivyPolicyViolationError is thrown and
149
+ * nothing is broadcast to the network.
150
+ *
151
+ * @param walletId - The Privy wallet ID to send from.
152
+ * @param tx - Transaction parameters (to, value, data, etc.).
153
+ * @returns Transaction hash and policy status.
154
+ *
155
+ * @example
156
+ * ```ts
157
+ * const result = await manager.sendTransaction(walletId, {
158
+ * to: escrowContractAddress,
159
+ * data: encodedCalldata,
160
+ * value: parseEther('0.01').toString(16),
161
+ * chainId: 8453,
162
+ * });
163
+ * console.log(`TX hash: ${result.hash}`);
164
+ * ```
165
+ */
166
+ sendTransaction(walletId: string, tx: PrivyTransactionRequest): Promise<PrivyTransactionResult>;
167
+ /**
168
+ * Sign a message with the Privy wallet (for SIWE, EIP-712, etc.).
169
+ *
170
+ * @param walletId - The Privy wallet ID.
171
+ * @param message - The message to sign.
172
+ * @returns The signature hex string.
173
+ */
174
+ signMessage(walletId: string, message: string): Promise<string>;
175
+ /**
176
+ * Sign typed data (EIP-712) with the Privy wallet.
177
+ *
178
+ * @param walletId - The Privy wallet ID.
179
+ * @param typedData - The EIP-712 typed data object.
180
+ * @returns The signature hex string.
181
+ */
182
+ signTypedData(walletId: string, typedData: Record<string, unknown>): Promise<string>;
183
+ /**
184
+ * SDK-level pre-validation before hitting the Privy API.
185
+ * This catches obvious errors instantly without a network round-trip.
186
+ */
187
+ private preValidateTransaction;
188
+ /**
189
+ * Convert our PrivyWalletPolicy to Privy's API format.
190
+ */
191
+ private convertToPrivyPolicy;
192
+ /**
193
+ * Map our rule type names to Privy's API rule type names.
194
+ */
195
+ private mapRuleType;
196
+ }
197
+ //# sourceMappingURL=privy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"privy.d.ts","sourceRoot":"","sources":["../src/privy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;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