@conto_finance/create-conto-agent 0.3.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/CHANGELOG.md +29 -0
- package/README.md +47 -0
- package/dist/chunk-2U2MPMMD.js +155 -0
- package/dist/{chunk-ICDSTI2Z.js → chunk-5OT7YKV4.js} +295 -172
- package/dist/chunk-TJJY5NFH.js +76 -0
- package/dist/cli.js +405 -113
- package/dist/{config-EKAEJVZR.js → config-LEPHM5HT.js} +11 -1
- package/dist/index.js +18 -7
- package/dist/lib/rule-values.d.ts +52 -0
- package/dist/lib/rule-values.js +12 -0
- package/package.json +19 -11
- package/dist/chunk-OS5PZNRM.js +0 -87
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// src/lib/rule-values.ts
|
|
2
|
+
function parseTrustScoreInput(input) {
|
|
3
|
+
const trimmed = input.trim();
|
|
4
|
+
if (trimmed === "") return { ok: false, error: "Enter a trust score between 0.0 and 1.0." };
|
|
5
|
+
const score = Number(trimmed);
|
|
6
|
+
if (!Number.isFinite(score)) {
|
|
7
|
+
return { ok: false, error: "Trust score must be a number between 0.0 and 1.0." };
|
|
8
|
+
}
|
|
9
|
+
if (score > 1 && score <= 100) {
|
|
10
|
+
return {
|
|
11
|
+
ok: false,
|
|
12
|
+
error: `Trust scores use a 0.0 to 1.0 scale. For ${trimmed}%, enter ${String(score / 100)}.`
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
if (score < 0 || score > 1) {
|
|
16
|
+
return { ok: false, error: "Trust score must be between 0.0 and 1.0." };
|
|
17
|
+
}
|
|
18
|
+
return { ok: true, value: String(score) };
|
|
19
|
+
}
|
|
20
|
+
var VELOCITY_PERIODS = ["HOUR", "DAY", "WEEK", "MONTH"];
|
|
21
|
+
function buildVelocityCountValue(input, period) {
|
|
22
|
+
const trimmed = input.trim();
|
|
23
|
+
const count = Number(trimmed);
|
|
24
|
+
if (trimmed === "" || !Number.isInteger(count) || count < 1) {
|
|
25
|
+
return { ok: false, error: "Max transactions must be a whole number of 1 or more." };
|
|
26
|
+
}
|
|
27
|
+
const normalizedPeriod = period.toUpperCase();
|
|
28
|
+
if (!VELOCITY_PERIODS.includes(normalizedPeriod)) {
|
|
29
|
+
return { ok: false, error: `Period must be one of ${VELOCITY_PERIODS.join(", ")}.` };
|
|
30
|
+
}
|
|
31
|
+
return { ok: true, value: JSON.stringify({ maxCount: count, period: normalizedPeriod }) };
|
|
32
|
+
}
|
|
33
|
+
var EVM_ADDRESS = /^0x[a-fA-F0-9]{40}$/;
|
|
34
|
+
var SOLANA_ADDRESS = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
|
|
35
|
+
var MAX_PAYMENT_AMOUNT = 1e9;
|
|
36
|
+
function validatePaymentRequest(input) {
|
|
37
|
+
const errors = [];
|
|
38
|
+
const amount = Number(input.amount);
|
|
39
|
+
if (!Number.isFinite(amount) || amount <= 0) {
|
|
40
|
+
errors.push("Amount must be a positive number.");
|
|
41
|
+
} else if (amount > MAX_PAYMENT_AMOUNT) {
|
|
42
|
+
errors.push(`Amount must be at most ${MAX_PAYMENT_AMOUNT}.`);
|
|
43
|
+
} else if (Math.abs(Math.round(amount * 100) - amount * 100) > 1e-6) {
|
|
44
|
+
errors.push("Amount can have at most 2 decimal places.");
|
|
45
|
+
}
|
|
46
|
+
if (!EVM_ADDRESS.test(input.address) && !SOLANA_ADDRESS.test(input.address)) {
|
|
47
|
+
errors.push("Recipient must be an EVM (0x...) or Solana address.");
|
|
48
|
+
}
|
|
49
|
+
if (input.purpose !== void 0 && input.purpose.length > 500) {
|
|
50
|
+
errors.push("Purpose must be 500 characters or fewer.");
|
|
51
|
+
}
|
|
52
|
+
if (input.category !== void 0 && input.category.length > 50) {
|
|
53
|
+
errors.push("Category must be 50 characters or fewer.");
|
|
54
|
+
}
|
|
55
|
+
if (input.walletId !== void 0 && input.walletId.length === 0) {
|
|
56
|
+
errors.push("Wallet ID cannot be empty.");
|
|
57
|
+
}
|
|
58
|
+
if (errors.length > 0) return { ok: false, errors };
|
|
59
|
+
return {
|
|
60
|
+
ok: true,
|
|
61
|
+
body: {
|
|
62
|
+
amount,
|
|
63
|
+
recipientAddress: input.address,
|
|
64
|
+
...input.purpose !== void 0 ? { purpose: input.purpose } : {},
|
|
65
|
+
...input.category !== void 0 ? { category: input.category } : {},
|
|
66
|
+
...input.walletId !== void 0 ? { walletId: input.walletId } : {}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export {
|
|
72
|
+
parseTrustScoreInput,
|
|
73
|
+
VELOCITY_PERIODS,
|
|
74
|
+
buildVelocityCountValue,
|
|
75
|
+
validatePaymentRequest
|
|
76
|
+
};
|