@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,119 @@
1
+ /**
2
+ * ABI for an individual TheQ00bs contract (one per user).
3
+ * READ-ONLY subset — the SDK uses this to inspect q00b sides and token holders
4
+ * for trust-path resolution.
5
+ */
6
+ export declare const THE_Q00BS_ABI: readonly [{
7
+ readonly inputs: readonly [{
8
+ readonly internalType: "address";
9
+ readonly name: "owner";
10
+ readonly type: "address";
11
+ }];
12
+ readonly name: "tokensOfOwner";
13
+ readonly outputs: readonly [{
14
+ readonly internalType: "uint256[]";
15
+ readonly name: "";
16
+ readonly type: "uint256[]";
17
+ }];
18
+ readonly stateMutability: "view";
19
+ readonly type: "function";
20
+ }, {
21
+ readonly inputs: readonly [{
22
+ readonly internalType: "uint256";
23
+ readonly name: "tokenId";
24
+ readonly type: "uint256";
25
+ }];
26
+ readonly name: "tokenURI";
27
+ readonly outputs: readonly [{
28
+ readonly internalType: "string";
29
+ readonly name: "";
30
+ readonly type: "string";
31
+ }];
32
+ readonly stateMutability: "view";
33
+ readonly type: "function";
34
+ }, {
35
+ readonly inputs: readonly [];
36
+ readonly name: "totalSupply";
37
+ readonly outputs: readonly [{
38
+ readonly internalType: "uint256";
39
+ readonly name: "";
40
+ readonly type: "uint256";
41
+ }];
42
+ readonly stateMutability: "view";
43
+ readonly type: "function";
44
+ }, {
45
+ readonly inputs: readonly [{
46
+ readonly internalType: "address";
47
+ readonly name: "owner";
48
+ readonly type: "address";
49
+ }];
50
+ readonly name: "balanceOf";
51
+ readonly outputs: readonly [{
52
+ readonly internalType: "uint256";
53
+ readonly name: "";
54
+ readonly type: "uint256";
55
+ }];
56
+ readonly stateMutability: "view";
57
+ readonly type: "function";
58
+ }, {
59
+ readonly inputs: readonly [{
60
+ readonly internalType: "uint256";
61
+ readonly name: "";
62
+ readonly type: "uint256";
63
+ }];
64
+ readonly name: "tokenInfos";
65
+ readonly outputs: readonly [{
66
+ readonly internalType: "bool";
67
+ readonly name: "exists";
68
+ readonly type: "bool";
69
+ }, {
70
+ readonly internalType: "address";
71
+ readonly name: "q00bOwner";
72
+ readonly type: "address";
73
+ }, {
74
+ readonly internalType: "uint256";
75
+ readonly name: "id";
76
+ readonly type: "uint256";
77
+ }, {
78
+ readonly internalType: "string";
79
+ readonly name: "q00bName";
80
+ readonly type: "string";
81
+ }, {
82
+ readonly internalType: "string";
83
+ readonly name: "metadataUrl";
84
+ readonly type: "string";
85
+ }];
86
+ readonly stateMutability: "view";
87
+ readonly type: "function";
88
+ }, {
89
+ readonly inputs: readonly [];
90
+ readonly name: "owner";
91
+ readonly outputs: readonly [{
92
+ readonly internalType: "address";
93
+ readonly name: "";
94
+ readonly type: "address";
95
+ }];
96
+ readonly stateMutability: "view";
97
+ readonly type: "function";
98
+ }, {
99
+ readonly inputs: readonly [];
100
+ readonly name: "initialOwner";
101
+ readonly outputs: readonly [{
102
+ readonly internalType: "address";
103
+ readonly name: "";
104
+ readonly type: "address";
105
+ }];
106
+ readonly stateMutability: "view";
107
+ readonly type: "function";
108
+ }, {
109
+ readonly inputs: readonly [];
110
+ readonly name: "factoryAddress";
111
+ readonly outputs: readonly [{
112
+ readonly internalType: "address";
113
+ readonly name: "";
114
+ readonly type: "address";
115
+ }];
116
+ readonly stateMutability: "view";
117
+ readonly type: "function";
118
+ }];
119
+ //# sourceMappingURL=TheQ00bs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TheQ00bs.d.ts","sourceRoot":"","sources":["../../src/abis/TheQ00bs.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+DhB,CAAC"}
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.THE_Q00BS_ABI = void 0;
4
+ /**
5
+ * ABI for an individual TheQ00bs contract (one per user).
6
+ * READ-ONLY subset — the SDK uses this to inspect q00b sides and token holders
7
+ * for trust-path resolution.
8
+ */
9
+ exports.THE_Q00BS_ABI = [
10
+ {
11
+ inputs: [{ internalType: 'address', name: 'owner', type: 'address' }],
12
+ name: 'tokensOfOwner',
13
+ outputs: [{ internalType: 'uint256[]', name: '', type: 'uint256[]' }],
14
+ stateMutability: 'view',
15
+ type: 'function',
16
+ },
17
+ {
18
+ inputs: [{ internalType: 'uint256', name: 'tokenId', type: 'uint256' }],
19
+ name: 'tokenURI',
20
+ outputs: [{ internalType: 'string', name: '', type: 'string' }],
21
+ stateMutability: 'view',
22
+ type: 'function',
23
+ },
24
+ {
25
+ inputs: [],
26
+ name: 'totalSupply',
27
+ outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
28
+ stateMutability: 'view',
29
+ type: 'function',
30
+ },
31
+ {
32
+ inputs: [{ internalType: 'address', name: 'owner', type: 'address' }],
33
+ name: 'balanceOf',
34
+ outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
35
+ stateMutability: 'view',
36
+ type: 'function',
37
+ },
38
+ {
39
+ inputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
40
+ name: 'tokenInfos',
41
+ outputs: [
42
+ { internalType: 'bool', name: 'exists', type: 'bool' },
43
+ { internalType: 'address', name: 'q00bOwner', type: 'address' },
44
+ { internalType: 'uint256', name: 'id', type: 'uint256' },
45
+ { internalType: 'string', name: 'q00bName', type: 'string' },
46
+ { internalType: 'string', name: 'metadataUrl', type: 'string' },
47
+ ],
48
+ stateMutability: 'view',
49
+ type: 'function',
50
+ },
51
+ {
52
+ inputs: [],
53
+ name: 'owner',
54
+ outputs: [{ internalType: 'address', name: '', type: 'address' }],
55
+ stateMutability: 'view',
56
+ type: 'function',
57
+ },
58
+ {
59
+ inputs: [],
60
+ name: 'initialOwner',
61
+ outputs: [{ internalType: 'address', name: '', type: 'address' }],
62
+ stateMutability: 'view',
63
+ type: 'function',
64
+ },
65
+ {
66
+ inputs: [],
67
+ name: 'factoryAddress',
68
+ outputs: [{ internalType: 'address', name: '', type: 'address' }],
69
+ stateMutability: 'view',
70
+ type: 'function',
71
+ },
72
+ ];
73
+ //# sourceMappingURL=TheQ00bs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TheQ00bs.js","sourceRoot":"","sources":["../../src/abis/TheQ00bs.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACU,QAAA,aAAa,GAAG;IAC3B;QACE,MAAM,EAAE,CAAC,EAAE,YAAY,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QACrE,IAAI,EAAE,eAAe;QACrB,OAAO,EAAE,CAAC,EAAE,YAAY,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;QACrE,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,UAAU;KACjB;IACD;QACE,MAAM,EAAE,CAAC,EAAE,YAAY,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QACvE,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,CAAC,EAAE,YAAY,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;QAC/D,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,UAAU;KACjB;IACD;QACE,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,aAAa;QACnB,OAAO,EAAE,CAAC,EAAE,YAAY,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QACjE,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,UAAU;KACjB;IACD;QACE,MAAM,EAAE,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E,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QACjE,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,UAAU;KACjB;IACD;QACE,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE,CAAC,EAAE,YAAY,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QACjE,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,UAAU;KACjB;CACO,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * ABI barrel export — import any ABI from '@q00bs/agent-sdk'.
3
+ */
4
+ export { Q00B_FACTORY_ABI } from './Q00bFactory';
5
+ export { THE_Q00BS_ABI } from './TheQ00bs';
6
+ export { AGENT_REGISTRY_ABI } from './AgentRegistry';
7
+ export { AGENT_ESCROW_ABI } from './AgentEscrow';
8
+ export { CONSENSUS_MODULE_ABI } from './ConsensusModule';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/abis/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CONSENSUS_MODULE_ABI = exports.AGENT_ESCROW_ABI = exports.AGENT_REGISTRY_ABI = exports.THE_Q00BS_ABI = exports.Q00B_FACTORY_ABI = void 0;
4
+ /**
5
+ * ABI barrel export — import any ABI from '@q00bs/agent-sdk'.
6
+ */
7
+ var Q00bFactory_1 = require("./Q00bFactory");
8
+ Object.defineProperty(exports, "Q00B_FACTORY_ABI", { enumerable: true, get: function () { return Q00bFactory_1.Q00B_FACTORY_ABI; } });
9
+ var TheQ00bs_1 = require("./TheQ00bs");
10
+ Object.defineProperty(exports, "THE_Q00BS_ABI", { enumerable: true, get: function () { return TheQ00bs_1.THE_Q00BS_ABI; } });
11
+ var AgentRegistry_1 = require("./AgentRegistry");
12
+ Object.defineProperty(exports, "AGENT_REGISTRY_ABI", { enumerable: true, get: function () { return AgentRegistry_1.AGENT_REGISTRY_ABI; } });
13
+ var AgentEscrow_1 = require("./AgentEscrow");
14
+ Object.defineProperty(exports, "AGENT_ESCROW_ABI", { enumerable: true, get: function () { return AgentEscrow_1.AGENT_ESCROW_ABI; } });
15
+ var ConsensusModule_1 = require("./ConsensusModule");
16
+ Object.defineProperty(exports, "CONSENSUS_MODULE_ABI", { enumerable: true, get: function () { return ConsensusModule_1.CONSENSUS_MODULE_ABI; } });
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/abis/index.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,6CAAiD;AAAxC,+GAAA,gBAAgB,OAAA;AACzB,uCAA2C;AAAlC,yGAAA,aAAa,OAAA;AACtB,iDAAqD;AAA5C,mHAAA,kBAAkB,OAAA;AAC3B,6CAAiD;AAAxC,+GAAA,gBAAgB,OAAA;AACzB,qDAAyD;AAAhD,uHAAA,oBAAoB,OAAA"}
@@ -0,0 +1,111 @@
1
+ /**
2
+ * @q00bs/agent-sdk — Blockchain Client
3
+ *
4
+ * Creates viem public + wallet clients for reading/writing to Base mainnet.
5
+ * All contract interactions go through these two clients:
6
+ *
7
+ * publicClient → read-only calls (getAgent, canCommunicate, etc.)
8
+ * walletClient → write calls that require a signer (registerAgent, createEscrow, etc.)
9
+ *
10
+ * TWO WALLET MODES:
11
+ *
12
+ * MODE 1: Raw Private Key (legacy)
13
+ * - Private key loaded from env var and used by viem directly.
14
+ * - Simpler but riskier for autonomous agents (key exposure).
15
+ *
16
+ * MODE 2: Privy Server Wallet (recommended for ClawBot agents)
17
+ * - Private key is held by Privy's secure enclave — NEVER in your code.
18
+ * - Transaction policies (spend limits, contract whitelists) enforced server-side.
19
+ * - Same pattern used by OpenClaw agents:
20
+ * https://privy.io/blog/securely-equipping-openclaw-agents-with-privy-wallets
21
+ * - For write calls, the SDK routes through PrivyWalletManager instead of viem.
22
+ * - Read calls still use viem publicClient (no signing needed).
23
+ *
24
+ * WHY VIEM?
25
+ * The existing q00bs app uses wagmi (which wraps viem). Using viem directly
26
+ * keeps the SDK lightweight (~50 KB) and avoids pulling in React dependencies.
27
+ */
28
+ import { type PublicClient, type WalletClient, type Chain, type Transport, type Account } from 'viem';
29
+ import type { Logger, PrivyConfig } from './types';
30
+ import { PrivyWalletManager } from './privy';
31
+ export interface ClientConfig {
32
+ /** Hex private key (0x...). Required for Mode 1 (raw key). Ignored if using Privy. */
33
+ privateKey?: string;
34
+ /** Base mainnet RPC URL. Defaults to public endpoint. */
35
+ rpcUrl?: string;
36
+ /** Optional logger. */
37
+ logger?: Logger;
38
+ }
39
+ /** Config for Mode 2: Privy-managed wallet. */
40
+ export interface PrivyClientConfig {
41
+ /** Privy configuration (appId, appSecret, optional walletId). */
42
+ privy: PrivyConfig;
43
+ /** Base mainnet RPC URL. Defaults to public endpoint. */
44
+ rpcUrl?: string;
45
+ /** Optional logger. */
46
+ logger?: Logger;
47
+ }
48
+ export interface BlockchainClients {
49
+ /** Read-only client for view/pure calls. */
50
+ publicClient: PublicClient<Transport, Chain>;
51
+ /** Signing client for state-changing transactions (undefined in Privy mode). */
52
+ walletClient?: WalletClient<Transport, Chain, Account>;
53
+ /** The account derived from the private key (undefined in Privy mode). */
54
+ account?: Account;
55
+ /** The chain object (Base). */
56
+ chain: Chain;
57
+ /** Privy wallet manager — set when using Privy mode. */
58
+ privyWalletManager?: PrivyWalletManager;
59
+ /** Which mode is active. */
60
+ mode: 'privateKey' | 'privy';
61
+ }
62
+ /**
63
+ * Initialize viem clients for Base mainnet using a raw private key (Mode 1).
64
+ *
65
+ * @param config - Private key and optional RPC URL.
66
+ * @returns An object with publicClient, walletClient, account, and chain.
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * const clients = createClients({
71
+ * privateKey: process.env.AGENT_PRIVATE_KEY!,
72
+ * rpcUrl: process.env.BASE_RPC_URL,
73
+ * });
74
+ * ```
75
+ */
76
+ export declare function createClients(config: ClientConfig): BlockchainClients;
77
+ /**
78
+ * Initialize viem read client + Privy wallet manager (Mode 2).
79
+ *
80
+ * This is the RECOMMENDED mode for ClawBot / OpenClaw agents. Instead
81
+ * of managing a private key, you configure Privy credentials and the
82
+ * SDK creates a policy-enforced wallet through Privy's API.
83
+ *
84
+ * @param config - Privy config (appId, appSecret) and optional RPC URL.
85
+ * @returns An object with publicClient, privyWalletManager, and chain.
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * const clients = createPrivyClients({
90
+ * privy: {
91
+ * appId: process.env.PRIVY_APP_ID!,
92
+ * appSecret: process.env.PRIVY_APP_SECRET!,
93
+ * walletId: process.env.PRIVY_WALLET_ID, // optional
94
+ * },
95
+ * });
96
+ * ```
97
+ */
98
+ export declare function createPrivyClients(config: PrivyClientConfig): BlockchainClients;
99
+ declare const LOG_LEVELS: {
100
+ readonly debug: 0;
101
+ readonly info: 1;
102
+ readonly warn: 2;
103
+ readonly error: 3;
104
+ };
105
+ /**
106
+ * Create a minimal, no-dependency logger.
107
+ * Prefixes all messages with [Q00BS] and respects log level.
108
+ */
109
+ export declare function createLogger(level?: keyof typeof LOG_LEVELS): Logger;
110
+ export {};
111
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EA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;;;;;CAAoD,CAAC;AAErE;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,GAAE,MAAM,OAAO,UAAmB,GAAG,MAAM,CAiB5E"}
package/dist/client.js ADDED
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ /**
3
+ * @q00bs/agent-sdk — Blockchain Client
4
+ *
5
+ * Creates viem public + wallet clients for reading/writing to Base mainnet.
6
+ * All contract interactions go through these two clients:
7
+ *
8
+ * publicClient → read-only calls (getAgent, canCommunicate, etc.)
9
+ * walletClient → write calls that require a signer (registerAgent, createEscrow, etc.)
10
+ *
11
+ * TWO WALLET MODES:
12
+ *
13
+ * MODE 1: Raw Private Key (legacy)
14
+ * - Private key loaded from env var and used by viem directly.
15
+ * - Simpler but riskier for autonomous agents (key exposure).
16
+ *
17
+ * MODE 2: Privy Server Wallet (recommended for ClawBot agents)
18
+ * - Private key is held by Privy's secure enclave — NEVER in your code.
19
+ * - Transaction policies (spend limits, contract whitelists) enforced server-side.
20
+ * - Same pattern used by OpenClaw agents:
21
+ * https://privy.io/blog/securely-equipping-openclaw-agents-with-privy-wallets
22
+ * - For write calls, the SDK routes through PrivyWalletManager instead of viem.
23
+ * - Read calls still use viem publicClient (no signing needed).
24
+ *
25
+ * WHY VIEM?
26
+ * The existing q00bs app uses wagmi (which wraps viem). Using viem directly
27
+ * keeps the SDK lightweight (~50 KB) and avoids pulling in React dependencies.
28
+ */
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.createClients = createClients;
31
+ exports.createPrivyClients = createPrivyClients;
32
+ exports.createLogger = createLogger;
33
+ const viem_1 = require("viem");
34
+ const accounts_1 = require("viem/accounts");
35
+ const chains_1 = require("viem/chains");
36
+ const constants_1 = require("./constants");
37
+ const privy_1 = require("./privy");
38
+ /**
39
+ * Initialize viem clients for Base mainnet using a raw private key (Mode 1).
40
+ *
41
+ * @param config - Private key and optional RPC URL.
42
+ * @returns An object with publicClient, walletClient, account, and chain.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * const clients = createClients({
47
+ * privateKey: process.env.AGENT_PRIVATE_KEY!,
48
+ * rpcUrl: process.env.BASE_RPC_URL,
49
+ * });
50
+ * ```
51
+ */
52
+ function createClients(config) {
53
+ // Validate private key format
54
+ if (!config.privateKey || !config.privateKey.startsWith('0x')) {
55
+ throw new Error('Private key must start with 0x. Set the AGENT_PRIVATE_KEY environment variable.');
56
+ }
57
+ const rpcUrl = config.rpcUrl || constants_1.DEFAULT_RPC_URL;
58
+ const account = (0, accounts_1.privateKeyToAccount)(config.privateKey);
59
+ config.logger?.info(`Initialized wallet: ${account.address}`);
60
+ config.logger?.info(`RPC endpoint: ${rpcUrl.replace(/\/\/.*@/, '//<redacted>@')}`);
61
+ const publicClient = (0, viem_1.createPublicClient)({
62
+ chain: chains_1.base,
63
+ transport: (0, viem_1.http)(rpcUrl),
64
+ });
65
+ const walletClient = (0, viem_1.createWalletClient)({
66
+ chain: chains_1.base,
67
+ transport: (0, viem_1.http)(rpcUrl),
68
+ account,
69
+ });
70
+ return { publicClient, walletClient, account, chain: chains_1.base, mode: 'privateKey' };
71
+ }
72
+ /**
73
+ * Initialize viem read client + Privy wallet manager (Mode 2).
74
+ *
75
+ * This is the RECOMMENDED mode for ClawBot / OpenClaw agents. Instead
76
+ * of managing a private key, you configure Privy credentials and the
77
+ * SDK creates a policy-enforced wallet through Privy's API.
78
+ *
79
+ * @param config - Privy config (appId, appSecret) and optional RPC URL.
80
+ * @returns An object with publicClient, privyWalletManager, and chain.
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * const clients = createPrivyClients({
85
+ * privy: {
86
+ * appId: process.env.PRIVY_APP_ID!,
87
+ * appSecret: process.env.PRIVY_APP_SECRET!,
88
+ * walletId: process.env.PRIVY_WALLET_ID, // optional
89
+ * },
90
+ * });
91
+ * ```
92
+ */
93
+ function createPrivyClients(config) {
94
+ const rpcUrl = config.rpcUrl || constants_1.DEFAULT_RPC_URL;
95
+ const logger = config.logger || createLogger('info');
96
+ logger.info('Initializing Privy-managed wallet mode...');
97
+ logger.info(`RPC endpoint: ${rpcUrl.replace(/\/\/.*@/, '//<redacted>@')}`);
98
+ const publicClient = (0, viem_1.createPublicClient)({
99
+ chain: chains_1.base,
100
+ transport: (0, viem_1.http)(rpcUrl),
101
+ });
102
+ const privyWalletManager = new privy_1.PrivyWalletManager(config.privy, logger);
103
+ return {
104
+ publicClient,
105
+ chain: chains_1.base,
106
+ privyWalletManager,
107
+ mode: 'privy',
108
+ };
109
+ }
110
+ // ─────────────────────────────────────────────────────────────
111
+ // LOGGER FACTORY
112
+ // ─────────────────────────────────────────────────────────────
113
+ const LOG_LEVELS = { debug: 0, info: 1, warn: 2, error: 3 };
114
+ /**
115
+ * Create a minimal, no-dependency logger.
116
+ * Prefixes all messages with [Q00BS] and respects log level.
117
+ */
118
+ function createLogger(level = 'info') {
119
+ const threshold = LOG_LEVELS[level];
120
+ const log = (lvl, msg, ...args) => {
121
+ if (LOG_LEVELS[lvl] >= threshold) {
122
+ const prefix = `[Q00BS][${lvl.toUpperCase()}]`;
123
+ // eslint-disable-next-line no-console
124
+ console[lvl === 'debug' ? 'log' : lvl](prefix, msg, ...args);
125
+ }
126
+ };
127
+ return {
128
+ debug: (msg, ...args) => log('debug', msg, ...args),
129
+ info: (msg, ...args) => log('info', msg, ...args),
130
+ warn: (msg, ...args) => log('warn', msg, ...args),
131
+ error: (msg, ...args) => log('error', msg, ...args),
132
+ };
133
+ }
134
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;;AAsEH,sCA0BC;AAuBD,gDAoBC;AAYD,oCAiBC;AAtKD,+BASc;AACd,4CAAoD;AACpD,wCAAmC;AACnC,2CAA8C;AAE9C,mCAA6C;AAwC7C;;;;;;;;;;;;;GAaG;AACH,SAAgB,aAAa,CAAC,MAAoB;IAChD,8BAA8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AG,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QACjD,IAAI,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QACjD,KAAK,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;KACpD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * @q00bs/agent-sdk — Consensus Module
3
+ *
4
+ * Handles multi-agent voting for high-stakes actions.
5
+ *
6
+ * WHEN IS CONSENSUS NEEDED?
7
+ * Actions above certain ETH thresholds require approval from peer agents
8
+ * in the initiator's trust network. This prevents rogue agents from
9
+ * unilaterally making expensive decisions.
10
+ *
11
+ * Value ≤ 0.01 ETH → No consensus (auto-approved)
12
+ * Value ≤ 0.10 ETH → 2 of 6 peer agents must approve
13
+ * Value ≤ 1.00 ETH → 4 of 6 peer agents must approve
14
+ * Value > 1.00 ETH → 4 of 6 peer agents + the human owner must approve
15
+ *
16
+ * FLOW:
17
+ * 1. Initiator calls requestConsensus() → gets a requestId.
18
+ * 2. Peer agents in the trust network call vote() with approve/reject.
19
+ * 3. If human approval is required, the owner calls humanApprove().
20
+ * 4. Once thresholds are met, the contract sets state to APPROVED.
21
+ * 5. Initiator calls markExecuted() after completing the action.
22
+ */
23
+ import type { PublicClient, WalletClient, Chain, Transport, Account } from 'viem';
24
+ import type { ConsensusParams, ConsensusResult, ConsensusRecord, Logger } from './types';
25
+ export declare class ConsensusManager {
26
+ private publicClient;
27
+ private walletClient;
28
+ private consensusAddress;
29
+ private logger;
30
+ constructor(publicClient: PublicClient<Transport, Chain>, walletClient: WalletClient<Transport, Chain, Account>, consensusAddress: string, logger: Logger);
31
+ /**
32
+ * Request consensus for an action.
33
+ *
34
+ * @param agentId - Your agent's on-chain ID.
35
+ * @param params - Action description, value, and optional timeout.
36
+ * @returns The new consensus request ID.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * const requestId = await consensus.request(1, {
41
+ * actionDescription: 'Transfer 0.5 ETH to agent 7 for data processing',
42
+ * valueEth: '0.5',
43
+ * timeoutMs: 3600000, // 1 hour
44
+ * });
45
+ * ```
46
+ */
47
+ request(agentId: number, params: ConsensusParams): Promise<number>;
48
+ /**
49
+ * Vote on a consensus request.
50
+ *
51
+ * @param requestId - The consensus request to vote on.
52
+ * @param voterAgentId - Your agent's on-chain ID.
53
+ * @param approve - true to approve, false to reject.
54
+ */
55
+ vote(requestId: number, voterAgentId: number, approve: boolean): Promise<string>;
56
+ /**
57
+ * Mark a consensus request as executed (after the approved action is done).
58
+ *
59
+ * @param requestId - The request to finalize.
60
+ */
61
+ markExecuted(requestId: number): Promise<string>;
62
+ /**
63
+ * Read a consensus request from the chain.
64
+ *
65
+ * @param requestId - The request to query.
66
+ */
67
+ get(requestId: number): Promise<ConsensusRecord>;
68
+ /**
69
+ * Check if a consensus request has been approved.
70
+ *
71
+ * @param requestId - The request to check.
72
+ */
73
+ isApproved(requestId: number): Promise<boolean>;
74
+ /**
75
+ * Poll for consensus result (blocking, with timeout).
76
+ * Useful when you need to wait for peer agents to vote.
77
+ *
78
+ * @param requestId - The request to wait on.
79
+ * @param pollIntervalMs - How often to check (default: 10s).
80
+ * @param timeoutMs - Maximum wait time (default: matches request timeout).
81
+ */
82
+ waitForResult(requestId: number, pollIntervalMs?: number, timeoutMs?: number): Promise<ConsensusResult>;
83
+ private parseRequestIdFromReceipt;
84
+ }
85
+ //# sourceMappingURL=consensus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consensus.d.ts","sourceRoot":"","sources":["../src/consensus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,KAAK,E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