hedera-curb 0.4.0 → 0.4.2

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/audit.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Client } from '@hiero-ledger/sdk';
2
- import type { CurbConfig } from './config';
3
- import type { CurbRecord } from './records';
2
+ import type { CurbConfig } from './config.js';
3
+ import type { CurbRecord } from './records.js';
4
4
  /**
5
5
  * Create an immutable HCS audit topic. No admin key (config can't change) and no submit key
6
6
  * (records come from whichever client runs the hooks; junk writes are filtered on read by decode).
@@ -1,10 +1,10 @@
1
1
  import { RejectToolPolicy } from '@hashgraph/hedera-agent-kit/policies';
2
2
  import { HcsAuditTrailHook } from '@hashgraph/hedera-agent-kit/hooks';
3
- import { SpendLimitPolicy } from './policies/spend-limit';
4
- import { CounterpartyAllowlistPolicy } from './policies/counterparty-allowlist';
5
- import { ApprovalTierPolicy } from './policies/approval-tier';
6
- import { CurbAuditHook } from './hooks/curb-audit-hook';
7
- import type { CurbDeps } from './deps';
3
+ import { SpendLimitPolicy } from './policies/spend-limit.js';
4
+ import { CounterpartyAllowlistPolicy } from './policies/counterparty-allowlist.js';
5
+ import { ApprovalTierPolicy } from './policies/approval-tier.js';
6
+ import { CurbAuditHook } from './hooks/curb-audit-hook.js';
7
+ import type { CurbDeps } from './deps.js';
8
8
  /**
9
9
  * The ordered Curb policy + audit stack, ready to drop into `configuration.context.hooks`.
10
10
  * Hard-disables account-mutating / allowance-granting tools, then governs every transfer
@@ -1,11 +1,11 @@
1
1
  import { RejectToolPolicy } from '@hashgraph/hedera-agent-kit/policies';
2
2
  import { HcsAuditTrailHook } from '@hashgraph/hedera-agent-kit/hooks';
3
3
  import { coreAccountPluginToolNames } from '@hashgraph/hedera-agent-kit/plugins';
4
- import { GOVERNED_TRANSFER_TOOLS } from './tools';
5
- import { SpendLimitPolicy } from './policies/spend-limit';
6
- import { CounterpartyAllowlistPolicy } from './policies/counterparty-allowlist';
7
- import { ApprovalTierPolicy } from './policies/approval-tier';
8
- import { CurbAuditHook } from './hooks/curb-audit-hook';
4
+ import { GOVERNED_TRANSFER_TOOLS } from './tools.js';
5
+ import { SpendLimitPolicy } from './policies/spend-limit.js';
6
+ import { CounterpartyAllowlistPolicy } from './policies/counterparty-allowlist.js';
7
+ import { ApprovalTierPolicy } from './policies/approval-tier.js';
8
+ import { CurbAuditHook } from './hooks/curb-audit-hook.js';
9
9
  /**
10
10
  * The ordered Curb policy + audit stack, ready to drop into `configuration.context.hooks`.
11
11
  * Hard-disables account-mutating / allowance-granting tools, then governs every transfer
package/dist/cli.js CHANGED
@@ -6,9 +6,24 @@ import { createAuditTopic } from './audit.js';
6
6
  import { createPolicyRegistry, publishPolicyVersion } from './policy-registry.js';
7
7
  import { DEFAULT_CONFIG } from './config.js';
8
8
  const flag = (name) => {
9
- const i = process.argv.indexOf(`--${name}`);
9
+ const eq = process.argv.find((a) => a.startsWith(`--${name}=`)); // support --name=value
10
+ if (eq)
11
+ return eq.slice(name.length + 3);
12
+ const i = process.argv.indexOf(`--${name}`); // and --name value
10
13
  return i >= 0 ? process.argv[i + 1] : undefined;
11
14
  };
15
+ // a numeric flag must parse to a positive, finite number — otherwise we'd publish a garbage policy (NaN caps).
16
+ const num = (name, def) => {
17
+ const raw = flag(name);
18
+ if (raw === undefined)
19
+ return def;
20
+ const n = Number(raw);
21
+ if (!Number.isFinite(n) || n <= 0) {
22
+ console.error(`Invalid --${name}: "${raw}" (expected a positive number).`);
23
+ process.exit(1);
24
+ }
25
+ return n;
26
+ };
12
27
  function parseKey(s) {
13
28
  for (const parse of [PrivateKey.fromStringECDSA, PrivateKey.fromStringED25519, PrivateKey.fromStringDer]) {
14
29
  try {
@@ -29,6 +44,9 @@ async function init() {
29
44
  console.error('Missing credentials. Pass --account and --key, or set HEDERA_OPERATOR_ID / HEDERA_OPERATOR_KEY.');
30
45
  process.exit(1);
31
46
  }
47
+ // validate all input (flags + key) BEFORE any on-chain work, so bad input never creates topics
48
+ const perTask = num('per-task', DEFAULT_CONFIG.perTask);
49
+ const perDay = num('per-day', DEFAULT_CONFIG.perDay);
32
50
  console.log(`Provisioning Curb on ${network}…`);
33
51
  const client = Client.forName(network).setOperator(account, parseKey(key));
34
52
  const auditTopicId = await createAuditTopic(client);
@@ -37,8 +55,8 @@ async function init() {
37
55
  agentAccountId: agent,
38
56
  auditTopicId,
39
57
  ...DEFAULT_CONFIG,
40
- perTask: Number(flag('per-task') ?? DEFAULT_CONFIG.perTask),
41
- perDay: Number(flag('per-day') ?? DEFAULT_CONFIG.perDay),
58
+ perTask,
59
+ perDay,
42
60
  };
43
61
  await publishPolicyVersion(client, config, policyTopicId, 'initial policy').catch(() => { });
44
62
  console.log(`\n✓ Audit topic: ${auditTopicId}`);
@@ -1,7 +1,7 @@
1
1
  import type { Client } from '@hiero-ledger/sdk';
2
- import { buildCurbHooks } from './build-hooks';
3
- import { type CurbStore } from './store';
4
- import { type CurbConfig, type Currency } from './config';
2
+ import { buildCurbHooks } from './build-hooks.js';
3
+ import { type CurbStore } from './store.js';
4
+ import { type CurbConfig, type Currency } from './config.js';
5
5
  export interface CreateCurbOptions {
6
6
  /** Operator client — used to create topics and write the audit trail. */
7
7
  client: Client;
@@ -1,8 +1,8 @@
1
- import { buildCurbHooks } from './build-hooks';
2
- import { InMemoryCurbStore } from './store';
3
- import { createAuditTopic } from './audit';
4
- import { createPolicyRegistry, publishPolicyVersion } from './policy-registry';
5
- import { DEFAULT_CONFIG } from './config';
1
+ import { buildCurbHooks } from './build-hooks.js';
2
+ import { InMemoryCurbStore } from './store.js';
3
+ import { createAuditTopic } from './audit.js';
4
+ import { createPolicyRegistry, publishPolicyVersion } from './policy-registry.js';
5
+ import { DEFAULT_CONFIG } from './config.js';
6
6
  /**
7
7
  * One-call setup for Curb. Auto-creates the audit topic (and an HCS-2 policy registry), defaults the
8
8
  * store to in-memory, publishes the initial policy version, and returns ready-to-use Agent Kit hooks.
package/dist/deps.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { CurbConfig } from './config';
2
- import type { CurbStore } from './store';
1
+ import type { CurbConfig } from './config.js';
2
+ import type { CurbStore } from './store.js';
3
3
  /** Everything every Curb policy and hook needs at construction time. */
4
4
  export interface CurbDeps {
5
5
  cfg: CurbConfig;
package/dist/extract.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import crypto from 'node:crypto';
2
2
  import { Hbar } from '@hiero-ledger/sdk';
3
- import { GOVERNED_TRANSFER_TOOLS } from './tools';
3
+ import { GOVERNED_TRANSFER_TOOLS } from './tools.js';
4
4
  /** Deterministic key for a payment (agent + recipient + amount) — used for spend holds and approvals. */
5
5
  export function paymentKey(agent, recipient, amount) {
6
6
  return crypto.createHash('sha256').update(`${agent}:${recipient}:${amount}`).digest('hex').slice(0, 16);
@@ -1,5 +1,5 @@
1
1
  import { AbstractHook, type PostSecondaryActionParams } from '@hashgraph/hedera-agent-kit';
2
- import type { CurbDeps } from '../deps';
2
+ import type { CurbDeps } from '../deps.js';
3
3
  /** Records every settled payment on HCS and advances the durable daily-spend counter. */
4
4
  export declare class CurbAuditHook extends AbstractHook {
5
5
  private d;
@@ -1,7 +1,7 @@
1
1
  import { AbstractHook } from '@hashgraph/hedera-agent-kit';
2
- import { GOVERNED_TRANSFER_TOOLS } from '../tools';
3
- import { extractPayment, paymentKey } from '../extract';
4
- import { writeRecord } from '../audit';
2
+ import { GOVERNED_TRANSFER_TOOLS } from '../tools.js';
3
+ import { extractPayment, paymentKey } from '../extract.js';
4
+ import { writeRecord } from '../audit.js';
5
5
  // `toolResult` is typed `any` in the kit; these are the observed shapes for tx id.
6
6
  function extractTxId(toolResult) {
7
7
  return (toolResult?.raw?.transactionId ??
package/dist/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
- export * from './config';
2
- export * from './records';
3
- export * from './store';
4
- export * from './deps';
5
- export * from './tools';
6
- export * from './extract';
7
- export * from './audit';
8
- export * from './policy-registry';
9
- export * from './policies/spend-limit';
10
- export * from './policies/counterparty-allowlist';
11
- export * from './policies/approval-tier';
12
- export * from './hooks/curb-audit-hook';
13
- export * from './build-hooks';
14
- export * from './create-curb';
1
+ export * from './config.js';
2
+ export * from './records.js';
3
+ export * from './store.js';
4
+ export * from './deps.js';
5
+ export * from './tools.js';
6
+ export * from './extract.js';
7
+ export * from './audit.js';
8
+ export * from './policy-registry.js';
9
+ export * from './policies/spend-limit.js';
10
+ export * from './policies/counterparty-allowlist.js';
11
+ export * from './policies/approval-tier.js';
12
+ export * from './hooks/curb-audit-hook.js';
13
+ export * from './build-hooks.js';
14
+ export * from './create-curb.js';
package/dist/index.js CHANGED
@@ -1,14 +1,14 @@
1
- export * from './config';
2
- export * from './records';
3
- export * from './store';
4
- export * from './deps';
5
- export * from './tools';
6
- export * from './extract';
7
- export * from './audit';
8
- export * from './policy-registry';
9
- export * from './policies/spend-limit';
10
- export * from './policies/counterparty-allowlist';
11
- export * from './policies/approval-tier';
12
- export * from './hooks/curb-audit-hook';
13
- export * from './build-hooks';
14
- export * from './create-curb';
1
+ export * from './config.js';
2
+ export * from './records.js';
3
+ export * from './store.js';
4
+ export * from './deps.js';
5
+ export * from './tools.js';
6
+ export * from './extract.js';
7
+ export * from './audit.js';
8
+ export * from './policy-registry.js';
9
+ export * from './policies/spend-limit.js';
10
+ export * from './policies/counterparty-allowlist.js';
11
+ export * from './policies/approval-tier.js';
12
+ export * from './hooks/curb-audit-hook.js';
13
+ export * from './build-hooks.js';
14
+ export * from './create-curb.js';
@@ -1,5 +1,5 @@
1
1
  import { AbstractPolicy, type PostParamsNormalizationParams } from '@hashgraph/hedera-agent-kit';
2
- import type { CurbDeps } from '../deps';
2
+ import type { CurbDeps } from '../deps.js';
3
3
  /**
4
4
  * Tiered human-in-the-loop:
5
5
  * - below `autoUnder` → auto-approve
@@ -1,8 +1,8 @@
1
1
  import crypto from 'node:crypto';
2
2
  import { AbstractPolicy } from '@hashgraph/hedera-agent-kit';
3
- import { GOVERNED_TRANSFER_TOOLS } from '../tools';
4
- import { extractPayment } from '../extract';
5
- import { writeRecord } from '../audit';
3
+ import { GOVERNED_TRANSFER_TOOLS } from '../tools.js';
4
+ import { extractPayment } from '../extract.js';
5
+ import { writeRecord } from '../audit.js';
6
6
  /**
7
7
  * Tiered human-in-the-loop:
8
8
  * - below `autoUnder` → auto-approve
@@ -1,5 +1,5 @@
1
1
  import { AbstractPolicy, type PostParamsNormalizationParams } from '@hashgraph/hedera-agent-kit';
2
- import type { CurbDeps } from '../deps';
2
+ import type { CurbDeps } from '../deps.js';
3
3
  /** Blocks payments to any account not on the allowlist. */
4
4
  export declare class CounterpartyAllowlistPolicy extends AbstractPolicy {
5
5
  private d;
@@ -1,7 +1,7 @@
1
1
  import { AbstractPolicy } from '@hashgraph/hedera-agent-kit';
2
- import { GOVERNED_TRANSFER_TOOLS } from '../tools';
3
- import { extractPayment } from '../extract';
4
- import { writeRecord } from '../audit';
2
+ import { GOVERNED_TRANSFER_TOOLS } from '../tools.js';
3
+ import { extractPayment } from '../extract.js';
4
+ import { writeRecord } from '../audit.js';
5
5
  /** Blocks payments to any account not on the allowlist. */
6
6
  export class CounterpartyAllowlistPolicy extends AbstractPolicy {
7
7
  d;
@@ -1,5 +1,5 @@
1
1
  import { AbstractPolicy, type PostParamsNormalizationParams } from '@hashgraph/hedera-agent-kit';
2
- import type { CurbDeps } from '../deps';
2
+ import type { CurbDeps } from '../deps.js';
3
3
  /**
4
4
  * Blocks a payment that would breach the per-task or rolling daily budget.
5
5
  * The daily check is an **atomic reserve** (a short-lived hold) so two concurrent payments can't both
@@ -1,7 +1,7 @@
1
1
  import { AbstractPolicy } from '@hashgraph/hedera-agent-kit';
2
- import { GOVERNED_TRANSFER_TOOLS } from '../tools';
3
- import { extractPayment, paymentKey } from '../extract';
4
- import { writeRecord } from '../audit';
2
+ import { GOVERNED_TRANSFER_TOOLS } from '../tools.js';
3
+ import { extractPayment, paymentKey } from '../extract.js';
4
+ import { writeRecord } from '../audit.js';
5
5
  /**
6
6
  * Blocks a payment that would breach the per-task or rolling daily budget.
7
7
  * The daily check is an **atomic reserve** (a short-lived hold) so two concurrent payments can't both
@@ -1,5 +1,5 @@
1
1
  import { Client } from '@hiero-ledger/sdk';
2
- import type { CurbConfig } from './config';
2
+ import type { CurbConfig } from './config.js';
3
3
  /** The policy fields that are versioned on-chain. */
4
4
  export interface PolicySnapshot {
5
5
  currency: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hedera-curb",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Verifiable spend-control policies for Hedera AI agents — drop-in Hedera Agent Kit hooks for budgets, allowlists, human approval, and an immutable HCS audit trail.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,7 +14,8 @@
14
14
  ".": {
15
15
  "types": "./dist/index.d.ts",
16
16
  "import": "./dist/index.js"
17
- }
17
+ },
18
+ "./package.json": "./package.json"
18
19
  },
19
20
  "files": ["dist", "README.md"],
20
21
  "sideEffects": false,