clawntenna 0.8.8 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -6
- package/dist/cli/index.js +115 -7
- package/dist/index.cjs +146 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +104 -3
- package/dist/index.d.ts +104 -3
- package/dist/index.js +136 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -136,6 +136,14 @@ interface EscrowConfig {
|
|
|
136
136
|
enabled: boolean;
|
|
137
137
|
timeout: bigint;
|
|
138
138
|
}
|
|
139
|
+
interface DepositTimer {
|
|
140
|
+
depositId: bigint;
|
|
141
|
+
expired: boolean;
|
|
142
|
+
remainingSeconds: number;
|
|
143
|
+
deadline: number;
|
|
144
|
+
formattedRemaining: string;
|
|
145
|
+
canClaim: boolean;
|
|
146
|
+
}
|
|
139
147
|
interface ClawtennaOptions {
|
|
140
148
|
chain?: ChainName;
|
|
141
149
|
chainId?: number;
|
|
@@ -209,6 +217,8 @@ declare class Clawntenna {
|
|
|
209
217
|
private ecdhPrivateKey;
|
|
210
218
|
private ecdhPublicKey;
|
|
211
219
|
private topicKeys;
|
|
220
|
+
private tokenDecimalsCache;
|
|
221
|
+
private static ERC20_DECIMALS_ABI;
|
|
212
222
|
constructor(options?: ClawtennaOptions);
|
|
213
223
|
get address(): string | null;
|
|
214
224
|
/**
|
|
@@ -254,8 +264,47 @@ declare class Clawntenna {
|
|
|
254
264
|
updateFrontendUrl(appId: number, frontendUrl: string): Promise<ethers.TransactionResponse>;
|
|
255
265
|
getApplication(appId: number): Promise<Application>;
|
|
256
266
|
getTopicMessageFee(topicId: number): Promise<TopicMessageFee>;
|
|
257
|
-
|
|
258
|
-
|
|
267
|
+
/**
|
|
268
|
+
* Set topic creation fee for an application (app admin only).
|
|
269
|
+
* feeAmount accepts:
|
|
270
|
+
* - bigint: raw token units (e.g. 150000n for 0.15 USDC)
|
|
271
|
+
* - string | number: human-readable amount — decimals are auto-resolved from the token contract
|
|
272
|
+
* (e.g. '0.15' or 0.15 with USDC → 150000n, '0.01' with native ETH → 10000000000000000n)
|
|
273
|
+
*/
|
|
274
|
+
setTopicCreationFee(appId: number, feeToken: string, feeAmount: bigint | string | number): Promise<ethers.TransactionResponse>;
|
|
275
|
+
/**
|
|
276
|
+
* Set per-message fee for a topic (topic admin only).
|
|
277
|
+
* feeAmount accepts:
|
|
278
|
+
* - bigint: raw token units (e.g. 150000n for 0.15 USDC)
|
|
279
|
+
* - string | number: human-readable amount — decimals are auto-resolved from the token contract
|
|
280
|
+
* (e.g. '0.15' or 0.15 with USDC → 150000n, '0.01' with native ETH → 10000000000000000n)
|
|
281
|
+
*/
|
|
282
|
+
setTopicMessageFee(topicId: number, feeToken: string, feeAmount: bigint | string | number): Promise<ethers.TransactionResponse>;
|
|
283
|
+
/**
|
|
284
|
+
* Get the number of decimals for an ERC-20 token.
|
|
285
|
+
* Returns 18 for native ETH (address(0)).
|
|
286
|
+
* Results are cached per token address.
|
|
287
|
+
*/
|
|
288
|
+
getTokenDecimals(tokenAddress: string): Promise<number>;
|
|
289
|
+
/**
|
|
290
|
+
* Convert a human-readable token amount to raw units (bigint).
|
|
291
|
+
* Looks up the token's on-chain decimals automatically.
|
|
292
|
+
*
|
|
293
|
+
* Examples:
|
|
294
|
+
* parseTokenAmount('0xUSDC...', '0.15') → 150000n (USDC = 6 decimals)
|
|
295
|
+
* parseTokenAmount('0xUSDC...', 10) → 10000000n (USDC = 6 decimals)
|
|
296
|
+
* parseTokenAmount(ZeroAddress, '0.01') → 10000000000000000n (native ETH = 18 decimals)
|
|
297
|
+
*/
|
|
298
|
+
parseTokenAmount(tokenAddress: string, amount: string | number): Promise<bigint>;
|
|
299
|
+
/**
|
|
300
|
+
* Convert raw token units (bigint) to a human-readable string.
|
|
301
|
+
* Looks up the token's on-chain decimals automatically.
|
|
302
|
+
*
|
|
303
|
+
* Examples:
|
|
304
|
+
* formatTokenAmount('0xUSDC...', 150000n) → '0.15'
|
|
305
|
+
* formatTokenAmount(ZeroAddress, 10000000000000000n) → '0.01'
|
|
306
|
+
*/
|
|
307
|
+
formatTokenAmount(tokenAddress: string, amount: bigint): Promise<string>;
|
|
259
308
|
private requireEscrow;
|
|
260
309
|
/**
|
|
261
310
|
* Enable escrow for a topic (topic owner only).
|
|
@@ -312,6 +361,11 @@ declare class Clawntenna {
|
|
|
312
361
|
* Returns false if no escrow deposit exists for the tx.
|
|
313
362
|
*/
|
|
314
363
|
isMessageRefunded(txHash: string): Promise<boolean>;
|
|
364
|
+
/**
|
|
365
|
+
* Get timer info for a deposit — remaining time, expiry status, and claimability.
|
|
366
|
+
* Useful for building countdown UIs.
|
|
367
|
+
*/
|
|
368
|
+
getDepositTimer(depositId: number): Promise<DepositTimer>;
|
|
315
369
|
/**
|
|
316
370
|
* Derive ECDH keypair from wallet signature (deterministic).
|
|
317
371
|
* Requires a signer capable of signing messages.
|
|
@@ -572,6 +626,53 @@ declare const IDENTITY_REGISTRY_ABI: readonly ["function register() returns (uin
|
|
|
572
626
|
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)"];
|
|
573
627
|
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)"];
|
|
574
628
|
|
|
629
|
+
/**
|
|
630
|
+
* Pure escrow timer utilities — no ethers.js dependency.
|
|
631
|
+
*/
|
|
632
|
+
declare const ESCROW_MIN_TIMEOUT = 60;
|
|
633
|
+
declare const ESCROW_MAX_TIMEOUT = 604800;
|
|
634
|
+
declare const ESCROW_TIMEOUT_OPTIONS: readonly [{
|
|
635
|
+
readonly value: 300;
|
|
636
|
+
readonly label: "5 minutes";
|
|
637
|
+
}, {
|
|
638
|
+
readonly value: 3600;
|
|
639
|
+
readonly label: "1 hour";
|
|
640
|
+
}, {
|
|
641
|
+
readonly value: 21600;
|
|
642
|
+
readonly label: "6 hours";
|
|
643
|
+
}, {
|
|
644
|
+
readonly value: 86400;
|
|
645
|
+
readonly label: "1 day";
|
|
646
|
+
}, {
|
|
647
|
+
readonly value: 259200;
|
|
648
|
+
readonly label: "3 days";
|
|
649
|
+
}, {
|
|
650
|
+
readonly value: 604800;
|
|
651
|
+
readonly label: "7 days";
|
|
652
|
+
}];
|
|
653
|
+
declare const DEPOSIT_STATUS_LABELS: readonly ["Pending", "Released", "Refunded"];
|
|
654
|
+
/**
|
|
655
|
+
* Format a timeout in seconds into a human-readable string.
|
|
656
|
+
* Examples: 300 → "5m", 3600 → "1h", 86400 → "1d", 5400 → "1h 30m"
|
|
657
|
+
*/
|
|
658
|
+
declare function formatTimeout(seconds: number): string;
|
|
659
|
+
/**
|
|
660
|
+
* Check whether a deposit has expired (eligible for refund).
|
|
661
|
+
*/
|
|
662
|
+
declare function isDepositExpired(depositedAt: bigint, timeout: bigint, nowSeconds?: number): boolean;
|
|
663
|
+
/**
|
|
664
|
+
* Seconds remaining until a deposit becomes refundable. Returns 0 if already expired.
|
|
665
|
+
*/
|
|
666
|
+
declare function timeUntilRefund(depositedAt: bigint, timeout: bigint, nowSeconds?: number): number;
|
|
667
|
+
/**
|
|
668
|
+
* Get the absolute deadline timestamp (seconds since epoch) when a deposit becomes refundable.
|
|
669
|
+
*/
|
|
670
|
+
declare function getDepositDeadline(depositedAt: bigint, timeout: bigint): number;
|
|
671
|
+
/**
|
|
672
|
+
* Validate that a timeout value is within allowed bounds.
|
|
673
|
+
*/
|
|
674
|
+
declare function isValidTimeout(seconds: number): boolean;
|
|
675
|
+
|
|
575
676
|
/**
|
|
576
677
|
* Derive AES-256 key for a public/public_limited topic.
|
|
577
678
|
* Uses PBKDF2 with SHA-256, matching the web frontend exactly.
|
|
@@ -649,4 +750,4 @@ declare function decryptTopicKey(encryptedKey: Uint8Array, ourPrivateKey: Uint8A
|
|
|
649
750
|
declare function bytesToHex(bytes: Uint8Array): string;
|
|
650
751
|
declare function hexToBytes(hex: string): Uint8Array;
|
|
651
752
|
|
|
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 };
|
|
753
|
+
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, DEPOSIT_STATUS_LABELS, DepositStatus, type DepositTimer, ESCROW_ABI, ESCROW_MAX_TIMEOUT, ESCROW_MIN_TIMEOUT, ESCROW_TIMEOUT_OPTIONS, 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, formatTimeout, getChain, getDepositDeadline, hexToBytes, isDepositExpired, isValidTimeout, keypairFromPrivateKey, timeUntilRefund };
|
package/dist/index.d.ts
CHANGED
|
@@ -136,6 +136,14 @@ interface EscrowConfig {
|
|
|
136
136
|
enabled: boolean;
|
|
137
137
|
timeout: bigint;
|
|
138
138
|
}
|
|
139
|
+
interface DepositTimer {
|
|
140
|
+
depositId: bigint;
|
|
141
|
+
expired: boolean;
|
|
142
|
+
remainingSeconds: number;
|
|
143
|
+
deadline: number;
|
|
144
|
+
formattedRemaining: string;
|
|
145
|
+
canClaim: boolean;
|
|
146
|
+
}
|
|
139
147
|
interface ClawtennaOptions {
|
|
140
148
|
chain?: ChainName;
|
|
141
149
|
chainId?: number;
|
|
@@ -209,6 +217,8 @@ declare class Clawntenna {
|
|
|
209
217
|
private ecdhPrivateKey;
|
|
210
218
|
private ecdhPublicKey;
|
|
211
219
|
private topicKeys;
|
|
220
|
+
private tokenDecimalsCache;
|
|
221
|
+
private static ERC20_DECIMALS_ABI;
|
|
212
222
|
constructor(options?: ClawtennaOptions);
|
|
213
223
|
get address(): string | null;
|
|
214
224
|
/**
|
|
@@ -254,8 +264,47 @@ declare class Clawntenna {
|
|
|
254
264
|
updateFrontendUrl(appId: number, frontendUrl: string): Promise<ethers.TransactionResponse>;
|
|
255
265
|
getApplication(appId: number): Promise<Application>;
|
|
256
266
|
getTopicMessageFee(topicId: number): Promise<TopicMessageFee>;
|
|
257
|
-
|
|
258
|
-
|
|
267
|
+
/**
|
|
268
|
+
* Set topic creation fee for an application (app admin only).
|
|
269
|
+
* feeAmount accepts:
|
|
270
|
+
* - bigint: raw token units (e.g. 150000n for 0.15 USDC)
|
|
271
|
+
* - string | number: human-readable amount — decimals are auto-resolved from the token contract
|
|
272
|
+
* (e.g. '0.15' or 0.15 with USDC → 150000n, '0.01' with native ETH → 10000000000000000n)
|
|
273
|
+
*/
|
|
274
|
+
setTopicCreationFee(appId: number, feeToken: string, feeAmount: bigint | string | number): Promise<ethers.TransactionResponse>;
|
|
275
|
+
/**
|
|
276
|
+
* Set per-message fee for a topic (topic admin only).
|
|
277
|
+
* feeAmount accepts:
|
|
278
|
+
* - bigint: raw token units (e.g. 150000n for 0.15 USDC)
|
|
279
|
+
* - string | number: human-readable amount — decimals are auto-resolved from the token contract
|
|
280
|
+
* (e.g. '0.15' or 0.15 with USDC → 150000n, '0.01' with native ETH → 10000000000000000n)
|
|
281
|
+
*/
|
|
282
|
+
setTopicMessageFee(topicId: number, feeToken: string, feeAmount: bigint | string | number): Promise<ethers.TransactionResponse>;
|
|
283
|
+
/**
|
|
284
|
+
* Get the number of decimals for an ERC-20 token.
|
|
285
|
+
* Returns 18 for native ETH (address(0)).
|
|
286
|
+
* Results are cached per token address.
|
|
287
|
+
*/
|
|
288
|
+
getTokenDecimals(tokenAddress: string): Promise<number>;
|
|
289
|
+
/**
|
|
290
|
+
* Convert a human-readable token amount to raw units (bigint).
|
|
291
|
+
* Looks up the token's on-chain decimals automatically.
|
|
292
|
+
*
|
|
293
|
+
* Examples:
|
|
294
|
+
* parseTokenAmount('0xUSDC...', '0.15') → 150000n (USDC = 6 decimals)
|
|
295
|
+
* parseTokenAmount('0xUSDC...', 10) → 10000000n (USDC = 6 decimals)
|
|
296
|
+
* parseTokenAmount(ZeroAddress, '0.01') → 10000000000000000n (native ETH = 18 decimals)
|
|
297
|
+
*/
|
|
298
|
+
parseTokenAmount(tokenAddress: string, amount: string | number): Promise<bigint>;
|
|
299
|
+
/**
|
|
300
|
+
* Convert raw token units (bigint) to a human-readable string.
|
|
301
|
+
* Looks up the token's on-chain decimals automatically.
|
|
302
|
+
*
|
|
303
|
+
* Examples:
|
|
304
|
+
* formatTokenAmount('0xUSDC...', 150000n) → '0.15'
|
|
305
|
+
* formatTokenAmount(ZeroAddress, 10000000000000000n) → '0.01'
|
|
306
|
+
*/
|
|
307
|
+
formatTokenAmount(tokenAddress: string, amount: bigint): Promise<string>;
|
|
259
308
|
private requireEscrow;
|
|
260
309
|
/**
|
|
261
310
|
* Enable escrow for a topic (topic owner only).
|
|
@@ -312,6 +361,11 @@ declare class Clawntenna {
|
|
|
312
361
|
* Returns false if no escrow deposit exists for the tx.
|
|
313
362
|
*/
|
|
314
363
|
isMessageRefunded(txHash: string): Promise<boolean>;
|
|
364
|
+
/**
|
|
365
|
+
* Get timer info for a deposit — remaining time, expiry status, and claimability.
|
|
366
|
+
* Useful for building countdown UIs.
|
|
367
|
+
*/
|
|
368
|
+
getDepositTimer(depositId: number): Promise<DepositTimer>;
|
|
315
369
|
/**
|
|
316
370
|
* Derive ECDH keypair from wallet signature (deterministic).
|
|
317
371
|
* Requires a signer capable of signing messages.
|
|
@@ -572,6 +626,53 @@ declare const IDENTITY_REGISTRY_ABI: readonly ["function register() returns (uin
|
|
|
572
626
|
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)"];
|
|
573
627
|
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)"];
|
|
574
628
|
|
|
629
|
+
/**
|
|
630
|
+
* Pure escrow timer utilities — no ethers.js dependency.
|
|
631
|
+
*/
|
|
632
|
+
declare const ESCROW_MIN_TIMEOUT = 60;
|
|
633
|
+
declare const ESCROW_MAX_TIMEOUT = 604800;
|
|
634
|
+
declare const ESCROW_TIMEOUT_OPTIONS: readonly [{
|
|
635
|
+
readonly value: 300;
|
|
636
|
+
readonly label: "5 minutes";
|
|
637
|
+
}, {
|
|
638
|
+
readonly value: 3600;
|
|
639
|
+
readonly label: "1 hour";
|
|
640
|
+
}, {
|
|
641
|
+
readonly value: 21600;
|
|
642
|
+
readonly label: "6 hours";
|
|
643
|
+
}, {
|
|
644
|
+
readonly value: 86400;
|
|
645
|
+
readonly label: "1 day";
|
|
646
|
+
}, {
|
|
647
|
+
readonly value: 259200;
|
|
648
|
+
readonly label: "3 days";
|
|
649
|
+
}, {
|
|
650
|
+
readonly value: 604800;
|
|
651
|
+
readonly label: "7 days";
|
|
652
|
+
}];
|
|
653
|
+
declare const DEPOSIT_STATUS_LABELS: readonly ["Pending", "Released", "Refunded"];
|
|
654
|
+
/**
|
|
655
|
+
* Format a timeout in seconds into a human-readable string.
|
|
656
|
+
* Examples: 300 → "5m", 3600 → "1h", 86400 → "1d", 5400 → "1h 30m"
|
|
657
|
+
*/
|
|
658
|
+
declare function formatTimeout(seconds: number): string;
|
|
659
|
+
/**
|
|
660
|
+
* Check whether a deposit has expired (eligible for refund).
|
|
661
|
+
*/
|
|
662
|
+
declare function isDepositExpired(depositedAt: bigint, timeout: bigint, nowSeconds?: number): boolean;
|
|
663
|
+
/**
|
|
664
|
+
* Seconds remaining until a deposit becomes refundable. Returns 0 if already expired.
|
|
665
|
+
*/
|
|
666
|
+
declare function timeUntilRefund(depositedAt: bigint, timeout: bigint, nowSeconds?: number): number;
|
|
667
|
+
/**
|
|
668
|
+
* Get the absolute deadline timestamp (seconds since epoch) when a deposit becomes refundable.
|
|
669
|
+
*/
|
|
670
|
+
declare function getDepositDeadline(depositedAt: bigint, timeout: bigint): number;
|
|
671
|
+
/**
|
|
672
|
+
* Validate that a timeout value is within allowed bounds.
|
|
673
|
+
*/
|
|
674
|
+
declare function isValidTimeout(seconds: number): boolean;
|
|
675
|
+
|
|
575
676
|
/**
|
|
576
677
|
* Derive AES-256 key for a public/public_limited topic.
|
|
577
678
|
* Uses PBKDF2 with SHA-256, matching the web frontend exactly.
|
|
@@ -649,4 +750,4 @@ declare function decryptTopicKey(encryptedKey: Uint8Array, ourPrivateKey: Uint8A
|
|
|
649
750
|
declare function bytesToHex(bytes: Uint8Array): string;
|
|
650
751
|
declare function hexToBytes(hex: string): Uint8Array;
|
|
651
752
|
|
|
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 };
|
|
753
|
+
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, DEPOSIT_STATUS_LABELS, DepositStatus, type DepositTimer, ESCROW_ABI, ESCROW_MAX_TIMEOUT, ESCROW_MIN_TIMEOUT, ESCROW_TIMEOUT_OPTIONS, 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, formatTimeout, getChain, getDepositDeadline, hexToBytes, isDepositExpired, isValidTimeout, keypairFromPrivateKey, timeUntilRefund };
|
package/dist/index.js
CHANGED
|
@@ -433,7 +433,51 @@ function hexToBytes(hex) {
|
|
|
433
433
|
|
|
434
434
|
// src/client.ts
|
|
435
435
|
import { randomBytes as randomBytes3 } from "@noble/hashes/utils";
|
|
436
|
-
|
|
436
|
+
|
|
437
|
+
// src/escrow.ts
|
|
438
|
+
var ESCROW_MIN_TIMEOUT = 60;
|
|
439
|
+
var ESCROW_MAX_TIMEOUT = 604800;
|
|
440
|
+
var ESCROW_TIMEOUT_OPTIONS = [
|
|
441
|
+
{ value: 300, label: "5 minutes" },
|
|
442
|
+
{ value: 3600, label: "1 hour" },
|
|
443
|
+
{ value: 21600, label: "6 hours" },
|
|
444
|
+
{ value: 86400, label: "1 day" },
|
|
445
|
+
{ value: 259200, label: "3 days" },
|
|
446
|
+
{ value: 604800, label: "7 days" }
|
|
447
|
+
];
|
|
448
|
+
var DEPOSIT_STATUS_LABELS = ["Pending", "Released", "Refunded"];
|
|
449
|
+
function formatTimeout(seconds) {
|
|
450
|
+
if (seconds <= 0) return "0s";
|
|
451
|
+
const days = Math.floor(seconds / 86400);
|
|
452
|
+
const hours = Math.floor(seconds % 86400 / 3600);
|
|
453
|
+
const minutes = Math.floor(seconds % 3600 / 60);
|
|
454
|
+
const secs = seconds % 60;
|
|
455
|
+
const parts = [];
|
|
456
|
+
if (days > 0) parts.push(`${days}d`);
|
|
457
|
+
if (hours > 0) parts.push(`${hours}h`);
|
|
458
|
+
if (minutes > 0) parts.push(`${minutes}m`);
|
|
459
|
+
if (secs > 0 && days === 0 && hours === 0) parts.push(`${secs}s`);
|
|
460
|
+
return parts.join(" ") || "0s";
|
|
461
|
+
}
|
|
462
|
+
function isDepositExpired(depositedAt, timeout, nowSeconds) {
|
|
463
|
+
const now = BigInt(nowSeconds ?? Math.floor(Date.now() / 1e3));
|
|
464
|
+
return now >= depositedAt + timeout;
|
|
465
|
+
}
|
|
466
|
+
function timeUntilRefund(depositedAt, timeout, nowSeconds) {
|
|
467
|
+
const now = BigInt(nowSeconds ?? Math.floor(Date.now() / 1e3));
|
|
468
|
+
const deadline = depositedAt + timeout;
|
|
469
|
+
if (now >= deadline) return 0;
|
|
470
|
+
return Number(deadline - now);
|
|
471
|
+
}
|
|
472
|
+
function getDepositDeadline(depositedAt, timeout) {
|
|
473
|
+
return Number(depositedAt + timeout);
|
|
474
|
+
}
|
|
475
|
+
function isValidTimeout(seconds) {
|
|
476
|
+
return Number.isInteger(seconds) && seconds >= ESCROW_MIN_TIMEOUT && seconds <= ESCROW_MAX_TIMEOUT;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// src/client.ts
|
|
480
|
+
var Clawntenna = class _Clawntenna {
|
|
437
481
|
provider;
|
|
438
482
|
wallet;
|
|
439
483
|
registry;
|
|
@@ -446,6 +490,9 @@ var Clawntenna = class {
|
|
|
446
490
|
ecdhPrivateKey = null;
|
|
447
491
|
ecdhPublicKey = null;
|
|
448
492
|
topicKeys = /* @__PURE__ */ new Map();
|
|
493
|
+
// Token decimals cache (ERC-20 decimals never change)
|
|
494
|
+
tokenDecimalsCache = /* @__PURE__ */ new Map();
|
|
495
|
+
static ERC20_DECIMALS_ABI = ["function decimals() view returns (uint8)"];
|
|
449
496
|
constructor(options = {}) {
|
|
450
497
|
const chainName = options.chain ?? "base";
|
|
451
498
|
const chain = CHAINS[chainName];
|
|
@@ -710,13 +757,70 @@ var Clawntenna = class {
|
|
|
710
757
|
const [token, amount] = await this.registry.getTopicMessageFee(topicId);
|
|
711
758
|
return { token, amount };
|
|
712
759
|
}
|
|
760
|
+
/**
|
|
761
|
+
* Set topic creation fee for an application (app admin only).
|
|
762
|
+
* feeAmount accepts:
|
|
763
|
+
* - bigint: raw token units (e.g. 150000n for 0.15 USDC)
|
|
764
|
+
* - string | number: human-readable amount — decimals are auto-resolved from the token contract
|
|
765
|
+
* (e.g. '0.15' or 0.15 with USDC → 150000n, '0.01' with native ETH → 10000000000000000n)
|
|
766
|
+
*/
|
|
713
767
|
async setTopicCreationFee(appId, feeToken, feeAmount) {
|
|
714
768
|
if (!this.wallet) throw new Error("Wallet required");
|
|
715
|
-
|
|
769
|
+
const rawAmount = typeof feeAmount === "bigint" ? feeAmount : await this.parseTokenAmount(feeToken, feeAmount);
|
|
770
|
+
return this.registry.setTopicCreationFee(appId, feeToken, rawAmount);
|
|
716
771
|
}
|
|
772
|
+
/**
|
|
773
|
+
* Set per-message fee for a topic (topic admin only).
|
|
774
|
+
* feeAmount accepts:
|
|
775
|
+
* - bigint: raw token units (e.g. 150000n for 0.15 USDC)
|
|
776
|
+
* - string | number: human-readable amount — decimals are auto-resolved from the token contract
|
|
777
|
+
* (e.g. '0.15' or 0.15 with USDC → 150000n, '0.01' with native ETH → 10000000000000000n)
|
|
778
|
+
*/
|
|
717
779
|
async setTopicMessageFee(topicId, feeToken, feeAmount) {
|
|
718
780
|
if (!this.wallet) throw new Error("Wallet required");
|
|
719
|
-
|
|
781
|
+
const rawAmount = typeof feeAmount === "bigint" ? feeAmount : await this.parseTokenAmount(feeToken, feeAmount);
|
|
782
|
+
return this.registry.setTopicMessageFee(topicId, feeToken, rawAmount);
|
|
783
|
+
}
|
|
784
|
+
// ===== TOKEN AMOUNTS =====
|
|
785
|
+
/**
|
|
786
|
+
* Get the number of decimals for an ERC-20 token.
|
|
787
|
+
* Returns 18 for native ETH (address(0)).
|
|
788
|
+
* Results are cached per token address.
|
|
789
|
+
*/
|
|
790
|
+
async getTokenDecimals(tokenAddress) {
|
|
791
|
+
if (tokenAddress === ethers.ZeroAddress) return 18;
|
|
792
|
+
const key = tokenAddress.toLowerCase();
|
|
793
|
+
const cached = this.tokenDecimalsCache.get(key);
|
|
794
|
+
if (cached !== void 0) return cached;
|
|
795
|
+
const erc20 = new ethers.Contract(tokenAddress, _Clawntenna.ERC20_DECIMALS_ABI, this.provider);
|
|
796
|
+
const decimals = Number(await erc20.decimals());
|
|
797
|
+
this.tokenDecimalsCache.set(key, decimals);
|
|
798
|
+
return decimals;
|
|
799
|
+
}
|
|
800
|
+
/**
|
|
801
|
+
* Convert a human-readable token amount to raw units (bigint).
|
|
802
|
+
* Looks up the token's on-chain decimals automatically.
|
|
803
|
+
*
|
|
804
|
+
* Examples:
|
|
805
|
+
* parseTokenAmount('0xUSDC...', '0.15') → 150000n (USDC = 6 decimals)
|
|
806
|
+
* parseTokenAmount('0xUSDC...', 10) → 10000000n (USDC = 6 decimals)
|
|
807
|
+
* parseTokenAmount(ZeroAddress, '0.01') → 10000000000000000n (native ETH = 18 decimals)
|
|
808
|
+
*/
|
|
809
|
+
async parseTokenAmount(tokenAddress, amount) {
|
|
810
|
+
const decimals = await this.getTokenDecimals(tokenAddress);
|
|
811
|
+
return ethers.parseUnits(String(amount), decimals);
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* Convert raw token units (bigint) to a human-readable string.
|
|
815
|
+
* Looks up the token's on-chain decimals automatically.
|
|
816
|
+
*
|
|
817
|
+
* Examples:
|
|
818
|
+
* formatTokenAmount('0xUSDC...', 150000n) → '0.15'
|
|
819
|
+
* formatTokenAmount(ZeroAddress, 10000000000000000n) → '0.01'
|
|
820
|
+
*/
|
|
821
|
+
async formatTokenAmount(tokenAddress, amount) {
|
|
822
|
+
const decimals = await this.getTokenDecimals(tokenAddress);
|
|
823
|
+
return ethers.formatUnits(amount, decimals);
|
|
720
824
|
}
|
|
721
825
|
// ===== ESCROW =====
|
|
722
826
|
requireEscrow() {
|
|
@@ -844,6 +948,25 @@ var Clawntenna = class {
|
|
|
844
948
|
const status = await this.getMessageDepositStatus(txHash);
|
|
845
949
|
return status === 2 /* Refunded */;
|
|
846
950
|
}
|
|
951
|
+
/**
|
|
952
|
+
* Get timer info for a deposit — remaining time, expiry status, and claimability.
|
|
953
|
+
* Useful for building countdown UIs.
|
|
954
|
+
*/
|
|
955
|
+
async getDepositTimer(depositId) {
|
|
956
|
+
const d = await this.getDeposit(depositId);
|
|
957
|
+
const nowSeconds = Math.floor(Date.now() / 1e3);
|
|
958
|
+
const remaining = timeUntilRefund(d.depositedAt, d.timeout, nowSeconds);
|
|
959
|
+
const expired = remaining === 0;
|
|
960
|
+
const canClaim = expired && d.status === 0 /* Pending */ ? await this.canClaimRefund(depositId) : false;
|
|
961
|
+
return {
|
|
962
|
+
depositId: d.id,
|
|
963
|
+
expired,
|
|
964
|
+
remainingSeconds: remaining,
|
|
965
|
+
deadline: getDepositDeadline(d.depositedAt, d.timeout),
|
|
966
|
+
formattedRemaining: formatTimeout(remaining),
|
|
967
|
+
canClaim
|
|
968
|
+
};
|
|
969
|
+
}
|
|
847
970
|
// ===== ECDH (Private Topics) =====
|
|
848
971
|
/**
|
|
849
972
|
* Derive ECDH keypair from wallet signature (deterministic).
|
|
@@ -1360,8 +1483,12 @@ export {
|
|
|
1360
1483
|
CHAINS,
|
|
1361
1484
|
CHAIN_IDS,
|
|
1362
1485
|
Clawntenna,
|
|
1486
|
+
DEPOSIT_STATUS_LABELS,
|
|
1363
1487
|
DepositStatus,
|
|
1364
1488
|
ESCROW_ABI,
|
|
1489
|
+
ESCROW_MAX_TIMEOUT,
|
|
1490
|
+
ESCROW_MIN_TIMEOUT,
|
|
1491
|
+
ESCROW_TIMEOUT_OPTIONS,
|
|
1365
1492
|
IDENTITY_REGISTRY_ABI,
|
|
1366
1493
|
KEY_MANAGER_ABI,
|
|
1367
1494
|
PERMISSION_ADMIN,
|
|
@@ -1390,8 +1517,13 @@ export {
|
|
|
1390
1517
|
encrypt,
|
|
1391
1518
|
encryptMessage,
|
|
1392
1519
|
encryptTopicKeyForUser,
|
|
1520
|
+
formatTimeout,
|
|
1393
1521
|
getChain,
|
|
1522
|
+
getDepositDeadline,
|
|
1394
1523
|
hexToBytes,
|
|
1395
|
-
|
|
1524
|
+
isDepositExpired,
|
|
1525
|
+
isValidTimeout,
|
|
1526
|
+
keypairFromPrivateKey,
|
|
1527
|
+
timeUntilRefund
|
|
1396
1528
|
};
|
|
1397
1529
|
//# sourceMappingURL=index.js.map
|