clawntenna 0.8.7 → 0.8.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -29,6 +29,7 @@ interface ChainConfig {
29
29
  keyManager: string;
30
30
  schemaRegistry: string;
31
31
  identityRegistry?: string;
32
+ escrow?: string;
32
33
  }
33
34
  type ChainName = 'base' | 'avalanche' | 'baseSepolia';
34
35
  interface Application {
@@ -114,6 +115,27 @@ interface TopicSchemaBinding {
114
115
  version: number;
115
116
  body: string;
116
117
  }
118
+ declare enum DepositStatus {
119
+ Pending = 0,
120
+ Released = 1,
121
+ Refunded = 2
122
+ }
123
+ interface EscrowDeposit {
124
+ id: bigint;
125
+ topicId: bigint;
126
+ sender: string;
127
+ recipient: string;
128
+ token: string;
129
+ amount: bigint;
130
+ appOwner: string;
131
+ depositedAt: bigint;
132
+ timeout: bigint;
133
+ status: DepositStatus;
134
+ }
135
+ interface EscrowConfig {
136
+ enabled: boolean;
137
+ timeout: bigint;
138
+ }
117
139
  interface ClawtennaOptions {
118
140
  chain?: ChainName;
119
141
  chainId?: number;
@@ -122,6 +144,7 @@ interface ClawtennaOptions {
122
144
  registryAddress?: string;
123
145
  keyManagerAddress?: string;
124
146
  schemaRegistryAddress?: string;
147
+ escrowAddress?: string;
125
148
  }
126
149
  interface ReadOptions {
127
150
  limit?: number;
@@ -132,6 +155,7 @@ interface SendOptions {
132
155
  replyText?: string;
133
156
  replyAuthor?: string;
134
157
  mentions?: string[];
158
+ skipRefundCheck?: boolean;
135
159
  }
136
160
  interface Credentials {
137
161
  version: 2;
@@ -180,6 +204,7 @@ declare class Clawntenna {
180
204
  readonly keyManager: ethers.Contract;
181
205
  readonly schemaRegistry: ethers.Contract;
182
206
  readonly identityRegistry: ethers.Contract | null;
207
+ readonly escrow: ethers.Contract | null;
183
208
  readonly chainName: ChainName;
184
209
  private ecdhPrivateKey;
185
210
  private ecdhPublicKey;
@@ -231,6 +256,62 @@ declare class Clawntenna {
231
256
  getTopicMessageFee(topicId: number): Promise<TopicMessageFee>;
232
257
  setTopicCreationFee(appId: number, feeToken: string, feeAmount: bigint): Promise<ethers.TransactionResponse>;
233
258
  setTopicMessageFee(topicId: number, feeToken: string, feeAmount: bigint): Promise<ethers.TransactionResponse>;
259
+ private requireEscrow;
260
+ /**
261
+ * Enable escrow for a topic (topic owner only).
262
+ */
263
+ enableEscrow(topicId: number, timeout: number): Promise<ethers.TransactionResponse>;
264
+ /**
265
+ * Disable escrow for a topic (topic owner only).
266
+ */
267
+ disableEscrow(topicId: number): Promise<ethers.TransactionResponse>;
268
+ /**
269
+ * Check if escrow is enabled for a topic.
270
+ */
271
+ isEscrowEnabled(topicId: number): Promise<boolean>;
272
+ /**
273
+ * Get escrow config for a topic (enabled + timeout).
274
+ */
275
+ getEscrowConfig(topicId: number): Promise<EscrowConfig>;
276
+ /**
277
+ * Get full deposit details by ID.
278
+ */
279
+ getDeposit(depositId: number): Promise<EscrowDeposit>;
280
+ /**
281
+ * Get deposit status (0=Pending, 1=Released, 2=Refunded).
282
+ */
283
+ getDepositStatus(depositId: number): Promise<DepositStatus>;
284
+ /**
285
+ * Get pending deposit IDs for a topic.
286
+ */
287
+ getPendingDeposits(topicId: number): Promise<bigint[]>;
288
+ /**
289
+ * Check if a deposit can be refunded (timeout expired and still pending).
290
+ */
291
+ canClaimRefund(depositId: number): Promise<boolean>;
292
+ /**
293
+ * Claim a refund for a single deposit.
294
+ */
295
+ claimRefund(depositId: number): Promise<ethers.TransactionResponse>;
296
+ /**
297
+ * Batch claim refunds for multiple deposits.
298
+ */
299
+ batchClaimRefunds(depositIds: number[]): Promise<ethers.TransactionResponse>;
300
+ /**
301
+ * Parse a transaction receipt to extract the depositId from a DepositRecorded event.
302
+ * Returns null if no DepositRecorded event is found (e.g. no escrow on this tx).
303
+ */
304
+ getMessageDepositId(txHash: string): Promise<bigint | null>;
305
+ /**
306
+ * Get the deposit status for a message by its transaction hash.
307
+ * Returns null if the message has no associated escrow deposit.
308
+ */
309
+ getMessageDepositStatus(txHash: string): Promise<DepositStatus | null>;
310
+ /**
311
+ * Check if a message's escrow deposit was refunded.
312
+ * Returns false if no escrow deposit exists for the tx.
313
+ */
314
+ isMessageRefunded(txHash: string): Promise<boolean>;
234
315
  /**
235
316
  * Derive ECDH keypair from wallet signature (deterministic).
236
317
  * Requires a signer capable of signing messages.
@@ -485,9 +566,10 @@ declare const ROLE_TOPIC_MANAGER = Role.TOPIC_MANAGER;
485
566
  declare const ROLE_ADMIN = Role.ADMIN;
486
567
  declare const ROLE_OWNER_DELEGATE = Role.OWNER_DELEGATE;
487
568
 
488
- declare const REGISTRY_ABI: readonly ["function applications(uint256) view returns (uint256 id, string name, string description, string frontendUrl, address owner, uint64 createdAt, uint32 memberCount, uint32 topicCount, bool active, bool allowPublicTopicCreation)", "function getApplication(uint256 appId) view returns (tuple(uint256 id, string name, string description, string frontendUrl, address owner, uint64 createdAt, uint32 memberCount, uint32 topicCount, bool active, bool allowPublicTopicCreation, address topicCreationFeeToken, uint256 topicCreationFeeAmount))", "function applicationCount() view returns (uint256)", "function applicationNames(string) view returns (uint256)", "function topics(uint256) view returns (uint256 id, uint256 applicationId, string name, string description, address owner, address creator, uint64 createdAt, uint64 lastMessageAt, uint256 messageCount, uint8 accessLevel, bool active)", "function getTopic(uint256 topicId) view returns (tuple(uint256 id, uint256 applicationId, string name, string description, address owner, address creator, uint64 createdAt, uint64 lastMessageAt, uint256 messageCount, uint8 accessLevel, bool active))", "function topicCount() view returns (uint256)", "function getApplicationTopics(uint256 appId) view returns (uint256[])", "function members(uint256 appId, address user) view returns (address account, string nickname, uint8 roles, uint64 joinedAt)", "function getMember(uint256 appId, address account) view returns (tuple(address account, string nickname, uint8 roles, uint64 joinedAt))", "function isMember(uint256 appId, address account) view returns (bool)", "function getApplicationMembers(uint256 appId) view returns (address[])", "function canReadTopic(uint256 topicId, address user) view returns (bool)", "function canWriteToTopic(uint256 topicId, address user) view returns (bool)", "function getTopicPermission(uint256 topicId, address user) view returns (uint8)", "function topicPermissions(uint256, address) view returns (uint8)", "function getNickname(uint256 appId, address user) view returns (string)", "function hasNickname(uint256 appId, address user) view returns (bool)", "function canChangeNickname(uint256 appId, address user) view returns (bool canChange, uint256 timeRemaining)", "function appNicknameCooldown(uint256 appId) view returns (uint256)", "function getTopicMessageFee(uint256 topicId) view returns (address token, uint256 amount)", "function createApplication(string name, string description, string frontendUrl, bool allowPublicTopicCreation) returns (uint256)", "function updateApplicationFrontendUrl(uint256 appId, string frontendUrl)", "function createTopic(uint256 appId, string name, string description, uint8 accessLevel) returns (uint256)", "function setTopicPermission(uint256 topicId, address user, uint8 permission)", "function addMember(uint256 appId, address member, string nickname, uint8 roles)", "function removeMember(uint256 appId, address member)", "function updateMemberRoles(uint256 appId, address member, uint8 roles)", "function updateMemberNickname(uint256 appId, string nickname)", "function setNickname(uint256 appId, string nickname)", "function clearNickname(uint256 appId)", "function setNicknameCooldown(uint256 appId, uint256 cooldownSeconds)", "function sendMessage(uint256 topicId, bytes payload)", "function setTopicCreationFee(uint256 appId, address feeTokenAddr, uint256 feeAmount)", "function setTopicMessageFee(uint256 topicId, address feeTokenAddr, uint256 feeAmount)", "event ApplicationCreated(uint256 indexed applicationId, string name, address indexed owner)", "event TopicCreated(uint256 indexed topicId, uint256 indexed applicationId, string name, address indexed creator, uint8 accessLevel)", "event MemberAdded(uint256 indexed applicationId, address indexed member, string nickname, uint8 roles)", "event MemberRemoved(uint256 indexed applicationId, address indexed member)", "event MemberRolesUpdated(uint256 indexed applicationId, address indexed member, uint8 roles)", "event NicknameUpdated(uint256 indexed applicationId, address indexed member, string nickname)", "event UserNicknameSet(uint256 indexed applicationId, address indexed user, string nickname)", "event TopicPermissionSet(uint256 indexed topicId, address indexed user, uint8 permission)", "event MessageSent(uint256 indexed topicId, address indexed sender, bytes payload, uint256 timestamp)", "event TopicMessageFeeUpdated(uint256 indexed topicId, address token, uint256 amount)", "function registerAgentIdentity(uint256 appId, uint256 tokenId)", "function clearAgentIdentity(uint256 appId)", "function getAgentTokenId(uint256 appId, address user) view returns (uint256)", "function hasAgentIdentity(uint256 appId, address user) view returns (bool)", "event AgentIdentityRegistered(uint256 indexed applicationId, address indexed user, uint256 tokenId)", "event AgentIdentityCleared(uint256 indexed applicationId, address indexed user)", "function exportMemberData(uint256 appId, address user) view returns (bytes)", "function exportApplicationData(uint256 appId) view returns (bytes)"];
569
+ declare const REGISTRY_ABI: readonly ["function applications(uint256) view returns (uint256 id, string name, string description, string frontendUrl, address owner, uint64 createdAt, uint32 memberCount, uint32 topicCount, bool active, bool allowPublicTopicCreation)", "function getApplication(uint256 appId) view returns (tuple(uint256 id, string name, string description, string frontendUrl, address owner, uint64 createdAt, uint32 memberCount, uint32 topicCount, bool active, bool allowPublicTopicCreation, address topicCreationFeeToken, uint256 topicCreationFeeAmount))", "function applicationCount() view returns (uint256)", "function applicationNames(string) view returns (uint256)", "function topics(uint256) view returns (uint256 id, uint256 applicationId, string name, string description, address owner, address creator, uint64 createdAt, uint64 lastMessageAt, uint256 messageCount, uint8 accessLevel, bool active)", "function getTopic(uint256 topicId) view returns (tuple(uint256 id, uint256 applicationId, string name, string description, address owner, address creator, uint64 createdAt, uint64 lastMessageAt, uint256 messageCount, uint8 accessLevel, bool active))", "function topicCount() view returns (uint256)", "function getApplicationTopics(uint256 appId) view returns (uint256[])", "function members(uint256 appId, address user) view returns (address account, string nickname, uint8 roles, uint64 joinedAt)", "function getMember(uint256 appId, address account) view returns (tuple(address account, string nickname, uint8 roles, uint64 joinedAt))", "function isMember(uint256 appId, address account) view returns (bool)", "function getApplicationMembers(uint256 appId) view returns (address[])", "function canReadTopic(uint256 topicId, address user) view returns (bool)", "function canWriteToTopic(uint256 topicId, address user) view returns (bool)", "function getTopicPermission(uint256 topicId, address user) view returns (uint8)", "function topicPermissions(uint256, address) view returns (uint8)", "function getNickname(uint256 appId, address user) view returns (string)", "function hasNickname(uint256 appId, address user) view returns (bool)", "function canChangeNickname(uint256 appId, address user) view returns (bool canChange, uint256 timeRemaining)", "function appNicknameCooldown(uint256 appId) view returns (uint256)", "function getTopicMessageFee(uint256 topicId) view returns (address token, uint256 amount)", "function PLATFORM_FEE_BPS() view returns (uint256)", "function PLATFORM_FEE_BPS_V7() view returns (uint256)", "function APP_OWNER_FEE_BPS() view returns (uint256)", "function BPS_DENOMINATOR() view returns (uint256)", "function createApplication(string name, string description, string frontendUrl, bool allowPublicTopicCreation) returns (uint256)", "function updateApplicationFrontendUrl(uint256 appId, string frontendUrl)", "function createTopic(uint256 appId, string name, string description, uint8 accessLevel) returns (uint256)", "function setTopicPermission(uint256 topicId, address user, uint8 permission)", "function addMember(uint256 appId, address member, string nickname, uint8 roles)", "function removeMember(uint256 appId, address member)", "function updateMemberRoles(uint256 appId, address member, uint8 roles)", "function updateMemberNickname(uint256 appId, string nickname)", "function setNickname(uint256 appId, string nickname)", "function clearNickname(uint256 appId)", "function setNicknameCooldown(uint256 appId, uint256 cooldownSeconds)", "function sendMessage(uint256 topicId, bytes payload)", "function setTopicCreationFee(uint256 appId, address feeTokenAddr, uint256 feeAmount)", "function setTopicMessageFee(uint256 topicId, address feeTokenAddr, uint256 feeAmount)", "event ApplicationCreated(uint256 indexed applicationId, string name, address indexed owner)", "event TopicCreated(uint256 indexed topicId, uint256 indexed applicationId, string name, address indexed creator, uint8 accessLevel)", "event MemberAdded(uint256 indexed applicationId, address indexed member, string nickname, uint8 roles)", "event MemberRemoved(uint256 indexed applicationId, address indexed member)", "event MemberRolesUpdated(uint256 indexed applicationId, address indexed member, uint8 roles)", "event NicknameUpdated(uint256 indexed applicationId, address indexed member, string nickname)", "event UserNicknameSet(uint256 indexed applicationId, address indexed user, string nickname)", "event TopicPermissionSet(uint256 indexed topicId, address indexed user, uint8 permission)", "event MessageSent(uint256 indexed topicId, address indexed sender, bytes payload, uint256 timestamp)", "event TopicMessageFeeUpdated(uint256 indexed topicId, address token, uint256 amount)", "event FeeCollected(address indexed token, uint256 totalAmount, address indexed recipient, uint256 recipientAmount, address indexed appOwner, uint256 appOwnerAmount, uint256 platformAmount)", "function registerAgentIdentity(uint256 appId, uint256 tokenId)", "function clearAgentIdentity(uint256 appId)", "function getAgentTokenId(uint256 appId, address user) view returns (uint256)", "function hasAgentIdentity(uint256 appId, address user) view returns (bool)", "event AgentIdentityRegistered(uint256 indexed applicationId, address indexed user, uint256 tokenId)", "event AgentIdentityCleared(uint256 indexed applicationId, address indexed user)", "function exportMemberData(uint256 appId, address user) view returns (bytes)", "function exportApplicationData(uint256 appId) view returns (bytes)"];
489
570
  declare const SCHEMA_REGISTRY_ABI: readonly ["function schemaCount() view returns (uint256)", "function getSchema(uint256 schemaId) view returns (uint256 id, string name, string description, address creator, uint64 createdAt, uint256 versionCount, bool active)", "function getSchemaWithApp(uint256 schemaId) view returns (uint256 id, string name, string description, address creator, uint64 createdAt, uint256 versionCount, bool active, uint256 applicationId)", "function getSchemaBody(uint256 schemaId, uint256 version) view returns (string)", "function getSchemaVersion(uint256 schemaId, uint256 version) view returns (string body, uint64 publishedAt)", "function schemaApplicationId(uint256 schemaId) view returns (uint256)", "function getApplicationSchemas(uint256 applicationId) view returns (uint256[])", "function getApplicationSchemaCount(uint256 applicationId) view returns (uint256)", "function getTopicSchema(uint256 topicId) view returns (uint256 schemaId, uint256 version, string body)", "function contractVersion() view returns (string)", "function createAppSchema(uint256 applicationId, string name, string description, string body) returns (uint256)", "function publishSchemaVersion(uint256 schemaId, string body) returns (uint256)", "function deactivateSchema(uint256 schemaId)", "function setTopicSchema(uint256 topicId, uint256 schemaId, uint256 version)", "function clearTopicSchema(uint256 topicId)", "event AppSchemaCreated(uint256 indexed schemaId, uint256 indexed applicationId, string name, address indexed creator)", "event SchemaVersionPublished(uint256 indexed schemaId, uint256 version)", "event SchemaDeactivated(uint256 indexed schemaId)", "event TopicSchemaSet(uint256 indexed topicId, uint256 indexed schemaId, uint256 version)", "event TopicSchemaCleared(uint256 indexed topicId)", "event SchemaAssignedToApp(uint256 indexed schemaId, uint256 indexed applicationId)"];
490
571
  declare const IDENTITY_REGISTRY_ABI: readonly ["function register() returns (uint256)", "function register(string agentURI) returns (uint256)", "function register(string agentURI, tuple(string metadataKey, bytes metadataValue)[] metadata) returns (uint256)", "function getMetadata(uint256 agentId, string metadataKey) view returns (bytes)", "function setMetadata(uint256 agentId, string metadataKey, bytes metadataValue)", "function setAgentURI(uint256 agentId, string newURI)", "function getAgentWallet(uint256 agentId) view returns (address)", "function setAgentWallet(uint256 agentId, address newWallet, uint256 deadline, bytes signature)", "function unsetAgentWallet(uint256 agentId)", "function ownerOf(uint256 tokenId) view returns (address)", "function balanceOf(address owner) view returns (uint256)", "function tokenOfOwnerByIndex(address owner, uint256 index) view returns (uint256)", "function tokenURI(uint256 tokenId) view returns (string)", "function isAuthorizedOrOwner(address spender, uint256 agentId) view returns (bool)", "function getVersion() pure returns (string)", "event Registered(uint256 indexed agentId, string agentURI, address indexed owner)"];
572
+ declare const ESCROW_ABI: readonly ["function getVersion() pure returns (string)", "function registry() view returns (address)", "function treasury() view returns (address)", "function depositCount() view returns (uint256)", "function isEscrowEnabled(uint256 topicId) view returns (bool)", "function topicEscrowEnabled(uint256 topicId) view returns (bool)", "function topicEscrowTimeout(uint256 topicId) view returns (uint64)", "function getDeposit(uint256 depositId) view returns (uint256 id, uint256 topicId, address sender, address recipient, address token, uint256 amount, address appOwner, uint64 depositedAt, uint64 timeout, uint8 status)", "function getDepositStatus(uint256 depositId) view returns (uint8)", "function getPendingDeposits(uint256 topicId) view returns (uint256[])", "function canClaimRefund(uint256 depositId) view returns (bool)", "function enableEscrow(uint256 topicId, uint64 timeoutSeconds)", "function disableEscrow(uint256 topicId)", "function claimRefund(uint256 depositId)", "function batchClaimRefunds(uint256[] depositIds)", "event EscrowEnabled(uint256 indexed topicId, uint64 timeout)", "event EscrowDisabled(uint256 indexed topicId)", "event DepositRecorded(uint256 indexed depositId, uint256 indexed topicId, address indexed sender, uint256 amount)", "event DepositReleased(uint256 indexed depositId, uint256 indexed topicId, uint256 recipientAmount, uint256 appOwnerAmount, uint256 platformAmount)", "event DepositRefunded(uint256 indexed depositId, uint256 indexed topicId, address indexed sender, uint256 amount)"];
491
573
  declare const KEY_MANAGER_ABI: readonly ["function hasPublicKey(address user) view returns (bool)", "function getPublicKey(address user) view returns (bytes)", "function publicKeys(address) view returns (bytes)", "function hasKeyAccess(uint256 topicId, address user) view returns (bool)", "function getMyKey(uint256 topicId) view returns (bytes encryptedKey, bytes granterPublicKey, address granter, uint256 keyVersion, uint256 currentVersion)", "function getKeyGrant(uint256 topicId, address user) view returns (tuple(bytes encryptedKey, bytes granterPublicKey, address granter, uint256 keyVersion, uint64 grantedAt))", "function keyVersions(uint256 topicId) view returns (uint256)", "function registerPublicKey(bytes publicKey)", "function grantKeyAccess(uint256 topicId, address user, bytes encryptedKey)", "function batchGrantKeyAccess(uint256 topicId, address[] users, bytes[] encryptedKeys)", "function revokeKeyAccess(uint256 topicId, address user)", "function rotateKey(uint256 topicId)", "function exportUserData(address user, uint256[] topicIds) view returns (bytes)", "event PublicKeyRegistered(address indexed user, bytes publicKey)", "event PublicKeyUpdated(address indexed user, bytes publicKey)", "event KeyAccessGranted(uint256 indexed topicId, address indexed user, address indexed granter, uint256 version)", "event KeyAccessRevoked(uint256 indexed topicId, address indexed user)", "event KeyRotated(uint256 indexed topicId, uint256 newVersion)"];
492
574
 
493
575
  /**
@@ -567,4 +649,4 @@ declare function decryptTopicKey(encryptedKey: Uint8Array, ourPrivateKey: Uint8A
567
649
  declare function bytesToHex(bytes: Uint8Array): string;
568
650
  declare function hexToBytes(hex: string): Uint8Array;
569
651
 
570
- export { ACCESS_PRIVATE, ACCESS_PUBLIC, ACCESS_PUBLIC_LIMITED, AccessLevel, type Application, CHAINS, CHAIN_IDS, type ChainConfig, type ChainName, Clawntenna, type ClawtennaOptions, type CredentialApp, type CredentialChain, type Credentials, type CredentialsV1, type EncryptedPayload, IDENTITY_REGISTRY_ABI, KEY_MANAGER_ABI, type KeyGrant, type Member, type Message, type MessageContent, PERMISSION_ADMIN, PERMISSION_NONE, PERMISSION_READ, PERMISSION_READ_WRITE, PERMISSION_WRITE, Permission, REGISTRY_ABI, ROLE_ADMIN, ROLE_MEMBER, ROLE_OWNER_DELEGATE, ROLE_SUPPORT_MANAGER, ROLE_TOPIC_MANAGER, type ReadOptions, Role, SCHEMA_REGISTRY_ABI, type SchemaInfo, type SendOptions, type Topic, type TopicMessageFee, type TopicSchemaBinding, bytesToHex, computeSharedSecret, decrypt, decryptMessage, decryptTopicKey, deriveAESKeyFromSecret, deriveKeyFromPassphrase, deriveKeypairFromSignature, derivePublicTopicKey, encrypt, encryptMessage, encryptTopicKeyForUser, getChain, hexToBytes, keypairFromPrivateKey };
652
+ export { ACCESS_PRIVATE, ACCESS_PUBLIC, ACCESS_PUBLIC_LIMITED, AccessLevel, type Application, CHAINS, CHAIN_IDS, type ChainConfig, type ChainName, Clawntenna, type ClawtennaOptions, type CredentialApp, type CredentialChain, type Credentials, type CredentialsV1, DepositStatus, ESCROW_ABI, type EncryptedPayload, type EscrowConfig, type EscrowDeposit, IDENTITY_REGISTRY_ABI, KEY_MANAGER_ABI, type KeyGrant, type Member, type Message, type MessageContent, PERMISSION_ADMIN, PERMISSION_NONE, PERMISSION_READ, PERMISSION_READ_WRITE, PERMISSION_WRITE, Permission, REGISTRY_ABI, ROLE_ADMIN, ROLE_MEMBER, ROLE_OWNER_DELEGATE, ROLE_SUPPORT_MANAGER, ROLE_TOPIC_MANAGER, type ReadOptions, Role, SCHEMA_REGISTRY_ABI, type SchemaInfo, type SendOptions, type Topic, type TopicMessageFee, type TopicSchemaBinding, bytesToHex, computeSharedSecret, decrypt, decryptMessage, decryptTopicKey, deriveAESKeyFromSecret, deriveKeyFromPassphrase, deriveKeypairFromSignature, derivePublicTopicKey, encrypt, encryptMessage, encryptTopicKeyForUser, getChain, hexToBytes, keypairFromPrivateKey };
package/dist/index.d.ts CHANGED
@@ -29,6 +29,7 @@ interface ChainConfig {
29
29
  keyManager: string;
30
30
  schemaRegistry: string;
31
31
  identityRegistry?: string;
32
+ escrow?: string;
32
33
  }
33
34
  type ChainName = 'base' | 'avalanche' | 'baseSepolia';
34
35
  interface Application {
@@ -114,6 +115,27 @@ interface TopicSchemaBinding {
114
115
  version: number;
115
116
  body: string;
116
117
  }
118
+ declare enum DepositStatus {
119
+ Pending = 0,
120
+ Released = 1,
121
+ Refunded = 2
122
+ }
123
+ interface EscrowDeposit {
124
+ id: bigint;
125
+ topicId: bigint;
126
+ sender: string;
127
+ recipient: string;
128
+ token: string;
129
+ amount: bigint;
130
+ appOwner: string;
131
+ depositedAt: bigint;
132
+ timeout: bigint;
133
+ status: DepositStatus;
134
+ }
135
+ interface EscrowConfig {
136
+ enabled: boolean;
137
+ timeout: bigint;
138
+ }
117
139
  interface ClawtennaOptions {
118
140
  chain?: ChainName;
119
141
  chainId?: number;
@@ -122,6 +144,7 @@ interface ClawtennaOptions {
122
144
  registryAddress?: string;
123
145
  keyManagerAddress?: string;
124
146
  schemaRegistryAddress?: string;
147
+ escrowAddress?: string;
125
148
  }
126
149
  interface ReadOptions {
127
150
  limit?: number;
@@ -132,6 +155,7 @@ interface SendOptions {
132
155
  replyText?: string;
133
156
  replyAuthor?: string;
134
157
  mentions?: string[];
158
+ skipRefundCheck?: boolean;
135
159
  }
136
160
  interface Credentials {
137
161
  version: 2;
@@ -180,6 +204,7 @@ declare class Clawntenna {
180
204
  readonly keyManager: ethers.Contract;
181
205
  readonly schemaRegistry: ethers.Contract;
182
206
  readonly identityRegistry: ethers.Contract | null;
207
+ readonly escrow: ethers.Contract | null;
183
208
  readonly chainName: ChainName;
184
209
  private ecdhPrivateKey;
185
210
  private ecdhPublicKey;
@@ -231,6 +256,62 @@ declare class Clawntenna {
231
256
  getTopicMessageFee(topicId: number): Promise<TopicMessageFee>;
232
257
  setTopicCreationFee(appId: number, feeToken: string, feeAmount: bigint): Promise<ethers.TransactionResponse>;
233
258
  setTopicMessageFee(topicId: number, feeToken: string, feeAmount: bigint): Promise<ethers.TransactionResponse>;
259
+ private requireEscrow;
260
+ /**
261
+ * Enable escrow for a topic (topic owner only).
262
+ */
263
+ enableEscrow(topicId: number, timeout: number): Promise<ethers.TransactionResponse>;
264
+ /**
265
+ * Disable escrow for a topic (topic owner only).
266
+ */
267
+ disableEscrow(topicId: number): Promise<ethers.TransactionResponse>;
268
+ /**
269
+ * Check if escrow is enabled for a topic.
270
+ */
271
+ isEscrowEnabled(topicId: number): Promise<boolean>;
272
+ /**
273
+ * Get escrow config for a topic (enabled + timeout).
274
+ */
275
+ getEscrowConfig(topicId: number): Promise<EscrowConfig>;
276
+ /**
277
+ * Get full deposit details by ID.
278
+ */
279
+ getDeposit(depositId: number): Promise<EscrowDeposit>;
280
+ /**
281
+ * Get deposit status (0=Pending, 1=Released, 2=Refunded).
282
+ */
283
+ getDepositStatus(depositId: number): Promise<DepositStatus>;
284
+ /**
285
+ * Get pending deposit IDs for a topic.
286
+ */
287
+ getPendingDeposits(topicId: number): Promise<bigint[]>;
288
+ /**
289
+ * Check if a deposit can be refunded (timeout expired and still pending).
290
+ */
291
+ canClaimRefund(depositId: number): Promise<boolean>;
292
+ /**
293
+ * Claim a refund for a single deposit.
294
+ */
295
+ claimRefund(depositId: number): Promise<ethers.TransactionResponse>;
296
+ /**
297
+ * Batch claim refunds for multiple deposits.
298
+ */
299
+ batchClaimRefunds(depositIds: number[]): Promise<ethers.TransactionResponse>;
300
+ /**
301
+ * Parse a transaction receipt to extract the depositId from a DepositRecorded event.
302
+ * Returns null if no DepositRecorded event is found (e.g. no escrow on this tx).
303
+ */
304
+ getMessageDepositId(txHash: string): Promise<bigint | null>;
305
+ /**
306
+ * Get the deposit status for a message by its transaction hash.
307
+ * Returns null if the message has no associated escrow deposit.
308
+ */
309
+ getMessageDepositStatus(txHash: string): Promise<DepositStatus | null>;
310
+ /**
311
+ * Check if a message's escrow deposit was refunded.
312
+ * Returns false if no escrow deposit exists for the tx.
313
+ */
314
+ isMessageRefunded(txHash: string): Promise<boolean>;
234
315
  /**
235
316
  * Derive ECDH keypair from wallet signature (deterministic).
236
317
  * Requires a signer capable of signing messages.
@@ -485,9 +566,10 @@ declare const ROLE_TOPIC_MANAGER = Role.TOPIC_MANAGER;
485
566
  declare const ROLE_ADMIN = Role.ADMIN;
486
567
  declare const ROLE_OWNER_DELEGATE = Role.OWNER_DELEGATE;
487
568
 
488
- declare const REGISTRY_ABI: readonly ["function applications(uint256) view returns (uint256 id, string name, string description, string frontendUrl, address owner, uint64 createdAt, uint32 memberCount, uint32 topicCount, bool active, bool allowPublicTopicCreation)", "function getApplication(uint256 appId) view returns (tuple(uint256 id, string name, string description, string frontendUrl, address owner, uint64 createdAt, uint32 memberCount, uint32 topicCount, bool active, bool allowPublicTopicCreation, address topicCreationFeeToken, uint256 topicCreationFeeAmount))", "function applicationCount() view returns (uint256)", "function applicationNames(string) view returns (uint256)", "function topics(uint256) view returns (uint256 id, uint256 applicationId, string name, string description, address owner, address creator, uint64 createdAt, uint64 lastMessageAt, uint256 messageCount, uint8 accessLevel, bool active)", "function getTopic(uint256 topicId) view returns (tuple(uint256 id, uint256 applicationId, string name, string description, address owner, address creator, uint64 createdAt, uint64 lastMessageAt, uint256 messageCount, uint8 accessLevel, bool active))", "function topicCount() view returns (uint256)", "function getApplicationTopics(uint256 appId) view returns (uint256[])", "function members(uint256 appId, address user) view returns (address account, string nickname, uint8 roles, uint64 joinedAt)", "function getMember(uint256 appId, address account) view returns (tuple(address account, string nickname, uint8 roles, uint64 joinedAt))", "function isMember(uint256 appId, address account) view returns (bool)", "function getApplicationMembers(uint256 appId) view returns (address[])", "function canReadTopic(uint256 topicId, address user) view returns (bool)", "function canWriteToTopic(uint256 topicId, address user) view returns (bool)", "function getTopicPermission(uint256 topicId, address user) view returns (uint8)", "function topicPermissions(uint256, address) view returns (uint8)", "function getNickname(uint256 appId, address user) view returns (string)", "function hasNickname(uint256 appId, address user) view returns (bool)", "function canChangeNickname(uint256 appId, address user) view returns (bool canChange, uint256 timeRemaining)", "function appNicknameCooldown(uint256 appId) view returns (uint256)", "function getTopicMessageFee(uint256 topicId) view returns (address token, uint256 amount)", "function createApplication(string name, string description, string frontendUrl, bool allowPublicTopicCreation) returns (uint256)", "function updateApplicationFrontendUrl(uint256 appId, string frontendUrl)", "function createTopic(uint256 appId, string name, string description, uint8 accessLevel) returns (uint256)", "function setTopicPermission(uint256 topicId, address user, uint8 permission)", "function addMember(uint256 appId, address member, string nickname, uint8 roles)", "function removeMember(uint256 appId, address member)", "function updateMemberRoles(uint256 appId, address member, uint8 roles)", "function updateMemberNickname(uint256 appId, string nickname)", "function setNickname(uint256 appId, string nickname)", "function clearNickname(uint256 appId)", "function setNicknameCooldown(uint256 appId, uint256 cooldownSeconds)", "function sendMessage(uint256 topicId, bytes payload)", "function setTopicCreationFee(uint256 appId, address feeTokenAddr, uint256 feeAmount)", "function setTopicMessageFee(uint256 topicId, address feeTokenAddr, uint256 feeAmount)", "event ApplicationCreated(uint256 indexed applicationId, string name, address indexed owner)", "event TopicCreated(uint256 indexed topicId, uint256 indexed applicationId, string name, address indexed creator, uint8 accessLevel)", "event MemberAdded(uint256 indexed applicationId, address indexed member, string nickname, uint8 roles)", "event MemberRemoved(uint256 indexed applicationId, address indexed member)", "event MemberRolesUpdated(uint256 indexed applicationId, address indexed member, uint8 roles)", "event NicknameUpdated(uint256 indexed applicationId, address indexed member, string nickname)", "event UserNicknameSet(uint256 indexed applicationId, address indexed user, string nickname)", "event TopicPermissionSet(uint256 indexed topicId, address indexed user, uint8 permission)", "event MessageSent(uint256 indexed topicId, address indexed sender, bytes payload, uint256 timestamp)", "event TopicMessageFeeUpdated(uint256 indexed topicId, address token, uint256 amount)", "function registerAgentIdentity(uint256 appId, uint256 tokenId)", "function clearAgentIdentity(uint256 appId)", "function getAgentTokenId(uint256 appId, address user) view returns (uint256)", "function hasAgentIdentity(uint256 appId, address user) view returns (bool)", "event AgentIdentityRegistered(uint256 indexed applicationId, address indexed user, uint256 tokenId)", "event AgentIdentityCleared(uint256 indexed applicationId, address indexed user)", "function exportMemberData(uint256 appId, address user) view returns (bytes)", "function exportApplicationData(uint256 appId) view returns (bytes)"];
569
+ declare const REGISTRY_ABI: readonly ["function applications(uint256) view returns (uint256 id, string name, string description, string frontendUrl, address owner, uint64 createdAt, uint32 memberCount, uint32 topicCount, bool active, bool allowPublicTopicCreation)", "function getApplication(uint256 appId) view returns (tuple(uint256 id, string name, string description, string frontendUrl, address owner, uint64 createdAt, uint32 memberCount, uint32 topicCount, bool active, bool allowPublicTopicCreation, address topicCreationFeeToken, uint256 topicCreationFeeAmount))", "function applicationCount() view returns (uint256)", "function applicationNames(string) view returns (uint256)", "function topics(uint256) view returns (uint256 id, uint256 applicationId, string name, string description, address owner, address creator, uint64 createdAt, uint64 lastMessageAt, uint256 messageCount, uint8 accessLevel, bool active)", "function getTopic(uint256 topicId) view returns (tuple(uint256 id, uint256 applicationId, string name, string description, address owner, address creator, uint64 createdAt, uint64 lastMessageAt, uint256 messageCount, uint8 accessLevel, bool active))", "function topicCount() view returns (uint256)", "function getApplicationTopics(uint256 appId) view returns (uint256[])", "function members(uint256 appId, address user) view returns (address account, string nickname, uint8 roles, uint64 joinedAt)", "function getMember(uint256 appId, address account) view returns (tuple(address account, string nickname, uint8 roles, uint64 joinedAt))", "function isMember(uint256 appId, address account) view returns (bool)", "function getApplicationMembers(uint256 appId) view returns (address[])", "function canReadTopic(uint256 topicId, address user) view returns (bool)", "function canWriteToTopic(uint256 topicId, address user) view returns (bool)", "function getTopicPermission(uint256 topicId, address user) view returns (uint8)", "function topicPermissions(uint256, address) view returns (uint8)", "function getNickname(uint256 appId, address user) view returns (string)", "function hasNickname(uint256 appId, address user) view returns (bool)", "function canChangeNickname(uint256 appId, address user) view returns (bool canChange, uint256 timeRemaining)", "function appNicknameCooldown(uint256 appId) view returns (uint256)", "function getTopicMessageFee(uint256 topicId) view returns (address token, uint256 amount)", "function PLATFORM_FEE_BPS() view returns (uint256)", "function PLATFORM_FEE_BPS_V7() view returns (uint256)", "function APP_OWNER_FEE_BPS() view returns (uint256)", "function BPS_DENOMINATOR() view returns (uint256)", "function createApplication(string name, string description, string frontendUrl, bool allowPublicTopicCreation) returns (uint256)", "function updateApplicationFrontendUrl(uint256 appId, string frontendUrl)", "function createTopic(uint256 appId, string name, string description, uint8 accessLevel) returns (uint256)", "function setTopicPermission(uint256 topicId, address user, uint8 permission)", "function addMember(uint256 appId, address member, string nickname, uint8 roles)", "function removeMember(uint256 appId, address member)", "function updateMemberRoles(uint256 appId, address member, uint8 roles)", "function updateMemberNickname(uint256 appId, string nickname)", "function setNickname(uint256 appId, string nickname)", "function clearNickname(uint256 appId)", "function setNicknameCooldown(uint256 appId, uint256 cooldownSeconds)", "function sendMessage(uint256 topicId, bytes payload)", "function setTopicCreationFee(uint256 appId, address feeTokenAddr, uint256 feeAmount)", "function setTopicMessageFee(uint256 topicId, address feeTokenAddr, uint256 feeAmount)", "event ApplicationCreated(uint256 indexed applicationId, string name, address indexed owner)", "event TopicCreated(uint256 indexed topicId, uint256 indexed applicationId, string name, address indexed creator, uint8 accessLevel)", "event MemberAdded(uint256 indexed applicationId, address indexed member, string nickname, uint8 roles)", "event MemberRemoved(uint256 indexed applicationId, address indexed member)", "event MemberRolesUpdated(uint256 indexed applicationId, address indexed member, uint8 roles)", "event NicknameUpdated(uint256 indexed applicationId, address indexed member, string nickname)", "event UserNicknameSet(uint256 indexed applicationId, address indexed user, string nickname)", "event TopicPermissionSet(uint256 indexed topicId, address indexed user, uint8 permission)", "event MessageSent(uint256 indexed topicId, address indexed sender, bytes payload, uint256 timestamp)", "event TopicMessageFeeUpdated(uint256 indexed topicId, address token, uint256 amount)", "event FeeCollected(address indexed token, uint256 totalAmount, address indexed recipient, uint256 recipientAmount, address indexed appOwner, uint256 appOwnerAmount, uint256 platformAmount)", "function registerAgentIdentity(uint256 appId, uint256 tokenId)", "function clearAgentIdentity(uint256 appId)", "function getAgentTokenId(uint256 appId, address user) view returns (uint256)", "function hasAgentIdentity(uint256 appId, address user) view returns (bool)", "event AgentIdentityRegistered(uint256 indexed applicationId, address indexed user, uint256 tokenId)", "event AgentIdentityCleared(uint256 indexed applicationId, address indexed user)", "function exportMemberData(uint256 appId, address user) view returns (bytes)", "function exportApplicationData(uint256 appId) view returns (bytes)"];
489
570
  declare const SCHEMA_REGISTRY_ABI: readonly ["function schemaCount() view returns (uint256)", "function getSchema(uint256 schemaId) view returns (uint256 id, string name, string description, address creator, uint64 createdAt, uint256 versionCount, bool active)", "function getSchemaWithApp(uint256 schemaId) view returns (uint256 id, string name, string description, address creator, uint64 createdAt, uint256 versionCount, bool active, uint256 applicationId)", "function getSchemaBody(uint256 schemaId, uint256 version) view returns (string)", "function getSchemaVersion(uint256 schemaId, uint256 version) view returns (string body, uint64 publishedAt)", "function schemaApplicationId(uint256 schemaId) view returns (uint256)", "function getApplicationSchemas(uint256 applicationId) view returns (uint256[])", "function getApplicationSchemaCount(uint256 applicationId) view returns (uint256)", "function getTopicSchema(uint256 topicId) view returns (uint256 schemaId, uint256 version, string body)", "function contractVersion() view returns (string)", "function createAppSchema(uint256 applicationId, string name, string description, string body) returns (uint256)", "function publishSchemaVersion(uint256 schemaId, string body) returns (uint256)", "function deactivateSchema(uint256 schemaId)", "function setTopicSchema(uint256 topicId, uint256 schemaId, uint256 version)", "function clearTopicSchema(uint256 topicId)", "event AppSchemaCreated(uint256 indexed schemaId, uint256 indexed applicationId, string name, address indexed creator)", "event SchemaVersionPublished(uint256 indexed schemaId, uint256 version)", "event SchemaDeactivated(uint256 indexed schemaId)", "event TopicSchemaSet(uint256 indexed topicId, uint256 indexed schemaId, uint256 version)", "event TopicSchemaCleared(uint256 indexed topicId)", "event SchemaAssignedToApp(uint256 indexed schemaId, uint256 indexed applicationId)"];
490
571
  declare const IDENTITY_REGISTRY_ABI: readonly ["function register() returns (uint256)", "function register(string agentURI) returns (uint256)", "function register(string agentURI, tuple(string metadataKey, bytes metadataValue)[] metadata) returns (uint256)", "function getMetadata(uint256 agentId, string metadataKey) view returns (bytes)", "function setMetadata(uint256 agentId, string metadataKey, bytes metadataValue)", "function setAgentURI(uint256 agentId, string newURI)", "function getAgentWallet(uint256 agentId) view returns (address)", "function setAgentWallet(uint256 agentId, address newWallet, uint256 deadline, bytes signature)", "function unsetAgentWallet(uint256 agentId)", "function ownerOf(uint256 tokenId) view returns (address)", "function balanceOf(address owner) view returns (uint256)", "function tokenOfOwnerByIndex(address owner, uint256 index) view returns (uint256)", "function tokenURI(uint256 tokenId) view returns (string)", "function isAuthorizedOrOwner(address spender, uint256 agentId) view returns (bool)", "function getVersion() pure returns (string)", "event Registered(uint256 indexed agentId, string agentURI, address indexed owner)"];
572
+ declare const ESCROW_ABI: readonly ["function getVersion() pure returns (string)", "function registry() view returns (address)", "function treasury() view returns (address)", "function depositCount() view returns (uint256)", "function isEscrowEnabled(uint256 topicId) view returns (bool)", "function topicEscrowEnabled(uint256 topicId) view returns (bool)", "function topicEscrowTimeout(uint256 topicId) view returns (uint64)", "function getDeposit(uint256 depositId) view returns (uint256 id, uint256 topicId, address sender, address recipient, address token, uint256 amount, address appOwner, uint64 depositedAt, uint64 timeout, uint8 status)", "function getDepositStatus(uint256 depositId) view returns (uint8)", "function getPendingDeposits(uint256 topicId) view returns (uint256[])", "function canClaimRefund(uint256 depositId) view returns (bool)", "function enableEscrow(uint256 topicId, uint64 timeoutSeconds)", "function disableEscrow(uint256 topicId)", "function claimRefund(uint256 depositId)", "function batchClaimRefunds(uint256[] depositIds)", "event EscrowEnabled(uint256 indexed topicId, uint64 timeout)", "event EscrowDisabled(uint256 indexed topicId)", "event DepositRecorded(uint256 indexed depositId, uint256 indexed topicId, address indexed sender, uint256 amount)", "event DepositReleased(uint256 indexed depositId, uint256 indexed topicId, uint256 recipientAmount, uint256 appOwnerAmount, uint256 platformAmount)", "event DepositRefunded(uint256 indexed depositId, uint256 indexed topicId, address indexed sender, uint256 amount)"];
491
573
  declare const KEY_MANAGER_ABI: readonly ["function hasPublicKey(address user) view returns (bool)", "function getPublicKey(address user) view returns (bytes)", "function publicKeys(address) view returns (bytes)", "function hasKeyAccess(uint256 topicId, address user) view returns (bool)", "function getMyKey(uint256 topicId) view returns (bytes encryptedKey, bytes granterPublicKey, address granter, uint256 keyVersion, uint256 currentVersion)", "function getKeyGrant(uint256 topicId, address user) view returns (tuple(bytes encryptedKey, bytes granterPublicKey, address granter, uint256 keyVersion, uint64 grantedAt))", "function keyVersions(uint256 topicId) view returns (uint256)", "function registerPublicKey(bytes publicKey)", "function grantKeyAccess(uint256 topicId, address user, bytes encryptedKey)", "function batchGrantKeyAccess(uint256 topicId, address[] users, bytes[] encryptedKeys)", "function revokeKeyAccess(uint256 topicId, address user)", "function rotateKey(uint256 topicId)", "function exportUserData(address user, uint256[] topicIds) view returns (bytes)", "event PublicKeyRegistered(address indexed user, bytes publicKey)", "event PublicKeyUpdated(address indexed user, bytes publicKey)", "event KeyAccessGranted(uint256 indexed topicId, address indexed user, address indexed granter, uint256 version)", "event KeyAccessRevoked(uint256 indexed topicId, address indexed user)", "event KeyRotated(uint256 indexed topicId, uint256 newVersion)"];
492
574
 
493
575
  /**
@@ -567,4 +649,4 @@ declare function decryptTopicKey(encryptedKey: Uint8Array, ourPrivateKey: Uint8A
567
649
  declare function bytesToHex(bytes: Uint8Array): string;
568
650
  declare function hexToBytes(hex: string): Uint8Array;
569
651
 
570
- export { ACCESS_PRIVATE, ACCESS_PUBLIC, ACCESS_PUBLIC_LIMITED, AccessLevel, type Application, CHAINS, CHAIN_IDS, type ChainConfig, type ChainName, Clawntenna, type ClawtennaOptions, type CredentialApp, type CredentialChain, type Credentials, type CredentialsV1, type EncryptedPayload, IDENTITY_REGISTRY_ABI, KEY_MANAGER_ABI, type KeyGrant, type Member, type Message, type MessageContent, PERMISSION_ADMIN, PERMISSION_NONE, PERMISSION_READ, PERMISSION_READ_WRITE, PERMISSION_WRITE, Permission, REGISTRY_ABI, ROLE_ADMIN, ROLE_MEMBER, ROLE_OWNER_DELEGATE, ROLE_SUPPORT_MANAGER, ROLE_TOPIC_MANAGER, type ReadOptions, Role, SCHEMA_REGISTRY_ABI, type SchemaInfo, type SendOptions, type Topic, type TopicMessageFee, type TopicSchemaBinding, bytesToHex, computeSharedSecret, decrypt, decryptMessage, decryptTopicKey, deriveAESKeyFromSecret, deriveKeyFromPassphrase, deriveKeypairFromSignature, derivePublicTopicKey, encrypt, encryptMessage, encryptTopicKeyForUser, getChain, hexToBytes, keypairFromPrivateKey };
652
+ export { ACCESS_PRIVATE, ACCESS_PUBLIC, ACCESS_PUBLIC_LIMITED, AccessLevel, type Application, CHAINS, CHAIN_IDS, type ChainConfig, type ChainName, Clawntenna, type ClawtennaOptions, type CredentialApp, type CredentialChain, type Credentials, type CredentialsV1, DepositStatus, ESCROW_ABI, type EncryptedPayload, type EscrowConfig, type EscrowDeposit, IDENTITY_REGISTRY_ABI, KEY_MANAGER_ABI, type KeyGrant, type Member, type Message, type MessageContent, PERMISSION_ADMIN, PERMISSION_NONE, PERMISSION_READ, PERMISSION_READ_WRITE, PERMISSION_WRITE, Permission, REGISTRY_ABI, ROLE_ADMIN, ROLE_MEMBER, ROLE_OWNER_DELEGATE, ROLE_SUPPORT_MANAGER, ROLE_TOPIC_MANAGER, type ReadOptions, Role, SCHEMA_REGISTRY_ABI, type SchemaInfo, type SendOptions, type Topic, type TopicMessageFee, type TopicSchemaBinding, bytesToHex, computeSharedSecret, decrypt, decryptMessage, decryptTopicKey, deriveAESKeyFromSecret, deriveKeyFromPassphrase, deriveKeypairFromSignature, derivePublicTopicKey, encrypt, encryptMessage, encryptTopicKeyForUser, getChain, hexToBytes, keypairFromPrivateKey };
package/dist/index.js CHANGED
@@ -12,7 +12,8 @@ var CHAINS = {
12
12
  registry: "0xf39b193aedC1Ec9FD6C5ccc24fBAe58ba9f52413",
13
13
  keyManager: "0x5562B553a876CBdc8AA4B3fb0687f22760F4759e",
14
14
  schemaRegistry: "0xB7eB50e9058198b99b5b2589E6D70b2d99d5440a",
15
- identityRegistry: "0x8004AA63c570c570eBF15376c0dB199918BFe9Fb"
15
+ identityRegistry: "0x8004AA63c570c570eBF15376c0dB199918BFe9Fb",
16
+ escrow: "0x74e376C53f4afd5Cd32a77dDc627f477FcFC2333"
16
17
  },
17
18
  base: {
18
19
  chainId: 8453,
@@ -83,6 +84,10 @@ var REGISTRY_ABI = [
83
84
  "function appNicknameCooldown(uint256 appId) view returns (uint256)",
84
85
  // Fees
85
86
  "function getTopicMessageFee(uint256 topicId) view returns (address token, uint256 amount)",
87
+ "function PLATFORM_FEE_BPS() view returns (uint256)",
88
+ "function PLATFORM_FEE_BPS_V7() view returns (uint256)",
89
+ "function APP_OWNER_FEE_BPS() view returns (uint256)",
90
+ "function BPS_DENOMINATOR() view returns (uint256)",
86
91
  // ===== WRITE FUNCTIONS =====
87
92
  // Applications
88
93
  "function createApplication(string name, string description, string frontendUrl, bool allowPublicTopicCreation) returns (uint256)",
@@ -115,6 +120,7 @@ var REGISTRY_ABI = [
115
120
  "event TopicPermissionSet(uint256 indexed topicId, address indexed user, uint8 permission)",
116
121
  "event MessageSent(uint256 indexed topicId, address indexed sender, bytes payload, uint256 timestamp)",
117
122
  "event TopicMessageFeeUpdated(uint256 indexed topicId, address token, uint256 amount)",
123
+ "event FeeCollected(address indexed token, uint256 totalAmount, address indexed recipient, uint256 recipientAmount, address indexed appOwner, uint256 appOwnerAmount, uint256 platformAmount)",
118
124
  // Agent identity (V5)
119
125
  "function registerAgentIdentity(uint256 appId, uint256 tokenId)",
120
126
  "function clearAgentIdentity(uint256 appId)",
@@ -176,6 +182,31 @@ var IDENTITY_REGISTRY_ABI = [
176
182
  "function getVersion() pure returns (string)",
177
183
  "event Registered(uint256 indexed agentId, string agentURI, address indexed owner)"
178
184
  ];
185
+ var ESCROW_ABI = [
186
+ // ===== READ FUNCTIONS =====
187
+ "function getVersion() pure returns (string)",
188
+ "function registry() view returns (address)",
189
+ "function treasury() view returns (address)",
190
+ "function depositCount() view returns (uint256)",
191
+ "function isEscrowEnabled(uint256 topicId) view returns (bool)",
192
+ "function topicEscrowEnabled(uint256 topicId) view returns (bool)",
193
+ "function topicEscrowTimeout(uint256 topicId) view returns (uint64)",
194
+ "function getDeposit(uint256 depositId) view returns (uint256 id, uint256 topicId, address sender, address recipient, address token, uint256 amount, address appOwner, uint64 depositedAt, uint64 timeout, uint8 status)",
195
+ "function getDepositStatus(uint256 depositId) view returns (uint8)",
196
+ "function getPendingDeposits(uint256 topicId) view returns (uint256[])",
197
+ "function canClaimRefund(uint256 depositId) view returns (bool)",
198
+ // ===== WRITE FUNCTIONS =====
199
+ "function enableEscrow(uint256 topicId, uint64 timeoutSeconds)",
200
+ "function disableEscrow(uint256 topicId)",
201
+ "function claimRefund(uint256 depositId)",
202
+ "function batchClaimRefunds(uint256[] depositIds)",
203
+ // ===== EVENTS =====
204
+ "event EscrowEnabled(uint256 indexed topicId, uint64 timeout)",
205
+ "event EscrowDisabled(uint256 indexed topicId)",
206
+ "event DepositRecorded(uint256 indexed depositId, uint256 indexed topicId, address indexed sender, uint256 amount)",
207
+ "event DepositReleased(uint256 indexed depositId, uint256 indexed topicId, uint256 recipientAmount, uint256 appOwnerAmount, uint256 platformAmount)",
208
+ "event DepositRefunded(uint256 indexed depositId, uint256 indexed topicId, address indexed sender, uint256 amount)"
209
+ ];
179
210
  var KEY_MANAGER_ABI = [
180
211
  // ===== READ FUNCTIONS =====
181
212
  "function hasPublicKey(address user) view returns (bool)",
@@ -230,6 +261,12 @@ var Role = /* @__PURE__ */ ((Role2) => {
230
261
  Role2[Role2["OWNER_DELEGATE"] = 16] = "OWNER_DELEGATE";
231
262
  return Role2;
232
263
  })(Role || {});
264
+ var DepositStatus = /* @__PURE__ */ ((DepositStatus2) => {
265
+ DepositStatus2[DepositStatus2["Pending"] = 0] = "Pending";
266
+ DepositStatus2[DepositStatus2["Released"] = 1] = "Released";
267
+ DepositStatus2[DepositStatus2["Refunded"] = 2] = "Refunded";
268
+ return DepositStatus2;
269
+ })(DepositStatus || {});
233
270
 
234
271
  // src/constants.ts
235
272
  var ACCESS_PUBLIC = 0 /* PUBLIC */;
@@ -403,6 +440,7 @@ var Clawntenna = class {
403
440
  keyManager;
404
441
  schemaRegistry;
405
442
  identityRegistry;
443
+ escrow;
406
444
  chainName;
407
445
  // In-memory ECDH state
408
446
  ecdhPrivateKey = null;
@@ -418,12 +456,15 @@ var Clawntenna = class {
418
456
  const registryAddr = options.registryAddress ?? chain.registry;
419
457
  const keyManagerAddr = options.keyManagerAddress ?? chain.keyManager;
420
458
  const schemaRegistryAddr = options.schemaRegistryAddress ?? chain.schemaRegistry;
421
- if (options.privateKey) {
422
- this.wallet = new ethers.Wallet(options.privateKey, this.provider);
423
- this.registry = new ethers.Contract(registryAddr, REGISTRY_ABI, this.wallet);
424
- this.keyManager = new ethers.Contract(keyManagerAddr, KEY_MANAGER_ABI, this.wallet);
425
- this.schemaRegistry = new ethers.Contract(schemaRegistryAddr, SCHEMA_REGISTRY_ABI, this.wallet);
426
- this.identityRegistry = chain.identityRegistry ? new ethers.Contract(chain.identityRegistry, IDENTITY_REGISTRY_ABI, this.wallet) : null;
459
+ const escrowAddr = options.escrowAddress ?? chain.escrow;
460
+ const signer = options.privateKey ? new ethers.Wallet(options.privateKey, this.provider) : null;
461
+ const runner = signer ?? this.provider;
462
+ if (signer) {
463
+ this.wallet = signer;
464
+ this.registry = new ethers.Contract(registryAddr, REGISTRY_ABI, signer);
465
+ this.keyManager = new ethers.Contract(keyManagerAddr, KEY_MANAGER_ABI, signer);
466
+ this.schemaRegistry = new ethers.Contract(schemaRegistryAddr, SCHEMA_REGISTRY_ABI, signer);
467
+ this.identityRegistry = chain.identityRegistry ? new ethers.Contract(chain.identityRegistry, IDENTITY_REGISTRY_ABI, signer) : null;
427
468
  } else {
428
469
  this.wallet = null;
429
470
  this.registry = new ethers.Contract(registryAddr, REGISTRY_ABI, this.provider);
@@ -431,6 +472,7 @@ var Clawntenna = class {
431
472
  this.schemaRegistry = new ethers.Contract(schemaRegistryAddr, SCHEMA_REGISTRY_ABI, this.provider);
432
473
  this.identityRegistry = chain.identityRegistry ? new ethers.Contract(chain.identityRegistry, IDENTITY_REGISTRY_ABI, this.provider) : null;
433
474
  }
475
+ this.escrow = escrowAddr ? new ethers.Contract(escrowAddr, ESCROW_ABI, runner) : null;
434
476
  }
435
477
  get address() {
436
478
  return this.wallet?.address ?? null;
@@ -442,6 +484,12 @@ var Clawntenna = class {
442
484
  */
443
485
  async sendMessage(topicId, text, options) {
444
486
  if (!this.wallet) throw new Error("Wallet required to send messages");
487
+ if (options?.replyTo && this.escrow && !options?.skipRefundCheck) {
488
+ const refunded = await this.isMessageRefunded(options.replyTo);
489
+ if (refunded) {
490
+ throw new Error(`Cannot reply: escrow deposit was refunded (tx: ${options.replyTo})`);
491
+ }
492
+ }
445
493
  let replyText = options?.replyText;
446
494
  let replyAuthor = options?.replyAuthor;
447
495
  if (options?.replyTo && (!replyText || !replyAuthor)) {
@@ -670,6 +718,132 @@ var Clawntenna = class {
670
718
  if (!this.wallet) throw new Error("Wallet required");
671
719
  return this.registry.setTopicMessageFee(topicId, feeToken, feeAmount);
672
720
  }
721
+ // ===== ESCROW =====
722
+ requireEscrow() {
723
+ if (!this.escrow) {
724
+ throw new Error("Escrow not available on this chain. Use baseSepolia or pass escrowAddress.");
725
+ }
726
+ return this.escrow;
727
+ }
728
+ /**
729
+ * Enable escrow for a topic (topic owner only).
730
+ */
731
+ async enableEscrow(topicId, timeout) {
732
+ if (!this.wallet) throw new Error("Wallet required");
733
+ return this.requireEscrow().enableEscrow(topicId, timeout);
734
+ }
735
+ /**
736
+ * Disable escrow for a topic (topic owner only).
737
+ */
738
+ async disableEscrow(topicId) {
739
+ if (!this.wallet) throw new Error("Wallet required");
740
+ return this.requireEscrow().disableEscrow(topicId);
741
+ }
742
+ /**
743
+ * Check if escrow is enabled for a topic.
744
+ */
745
+ async isEscrowEnabled(topicId) {
746
+ return this.requireEscrow().isEscrowEnabled(topicId);
747
+ }
748
+ /**
749
+ * Get escrow config for a topic (enabled + timeout).
750
+ */
751
+ async getEscrowConfig(topicId) {
752
+ const escrow = this.requireEscrow();
753
+ const [enabled, timeout] = await Promise.all([
754
+ escrow.isEscrowEnabled(topicId),
755
+ escrow.topicEscrowTimeout(topicId)
756
+ ]);
757
+ return { enabled, timeout };
758
+ }
759
+ /**
760
+ * Get full deposit details by ID.
761
+ */
762
+ async getDeposit(depositId) {
763
+ const d = await this.requireEscrow().getDeposit(depositId);
764
+ return {
765
+ id: d.id,
766
+ topicId: d.topicId,
767
+ sender: d.sender,
768
+ recipient: d.recipient,
769
+ token: d.token,
770
+ amount: d.amount,
771
+ appOwner: d.appOwner,
772
+ depositedAt: d.depositedAt,
773
+ timeout: d.timeout,
774
+ status: Number(d.status)
775
+ };
776
+ }
777
+ /**
778
+ * Get deposit status (0=Pending, 1=Released, 2=Refunded).
779
+ */
780
+ async getDepositStatus(depositId) {
781
+ const status = await this.requireEscrow().getDepositStatus(depositId);
782
+ return Number(status);
783
+ }
784
+ /**
785
+ * Get pending deposit IDs for a topic.
786
+ */
787
+ async getPendingDeposits(topicId) {
788
+ return this.requireEscrow().getPendingDeposits(topicId);
789
+ }
790
+ /**
791
+ * Check if a deposit can be refunded (timeout expired and still pending).
792
+ */
793
+ async canClaimRefund(depositId) {
794
+ return this.requireEscrow().canClaimRefund(depositId);
795
+ }
796
+ /**
797
+ * Claim a refund for a single deposit.
798
+ */
799
+ async claimRefund(depositId) {
800
+ if (!this.wallet) throw new Error("Wallet required");
801
+ return this.requireEscrow().claimRefund(depositId);
802
+ }
803
+ /**
804
+ * Batch claim refunds for multiple deposits.
805
+ */
806
+ async batchClaimRefunds(depositIds) {
807
+ if (!this.wallet) throw new Error("Wallet required");
808
+ return this.requireEscrow().batchClaimRefunds(depositIds);
809
+ }
810
+ /**
811
+ * Parse a transaction receipt to extract the depositId from a DepositRecorded event.
812
+ * Returns null if no DepositRecorded event is found (e.g. no escrow on this tx).
813
+ */
814
+ async getMessageDepositId(txHash) {
815
+ if (!this.escrow) return null;
816
+ const receipt = await this.provider.getTransactionReceipt(txHash);
817
+ if (!receipt) return null;
818
+ const iface = this.escrow.interface;
819
+ for (const log of receipt.logs) {
820
+ try {
821
+ const parsed = iface.parseLog(log);
822
+ if (parsed?.name === "DepositRecorded") {
823
+ return parsed.args.depositId;
824
+ }
825
+ } catch {
826
+ }
827
+ }
828
+ return null;
829
+ }
830
+ /**
831
+ * Get the deposit status for a message by its transaction hash.
832
+ * Returns null if the message has no associated escrow deposit.
833
+ */
834
+ async getMessageDepositStatus(txHash) {
835
+ const depositId = await this.getMessageDepositId(txHash);
836
+ if (depositId === null) return null;
837
+ return this.getDepositStatus(Number(depositId));
838
+ }
839
+ /**
840
+ * Check if a message's escrow deposit was refunded.
841
+ * Returns false if no escrow deposit exists for the tx.
842
+ */
843
+ async isMessageRefunded(txHash) {
844
+ const status = await this.getMessageDepositStatus(txHash);
845
+ return status === 2 /* Refunded */;
846
+ }
673
847
  // ===== ECDH (Private Topics) =====
674
848
  /**
675
849
  * Derive ECDH keypair from wallet signature (deterministic).
@@ -1186,6 +1360,8 @@ export {
1186
1360
  CHAINS,
1187
1361
  CHAIN_IDS,
1188
1362
  Clawntenna,
1363
+ DepositStatus,
1364
+ ESCROW_ABI,
1189
1365
  IDENTITY_REGISTRY_ABI,
1190
1366
  KEY_MANAGER_ABI,
1191
1367
  PERMISSION_ADMIN,