tenjin-cli 0.1.0-alpha.1 → 0.1.0-alpha.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.
Files changed (133) hide show
  1. package/NOTICE.md +33 -0
  2. package/README.md +164 -16
  3. package/dist/{_esm-ZH2J4QEH.js → _esm-C5CRWCYU.js} +2 -2
  4. package/dist/_esm-FEASBWRP.js +881 -0
  5. package/dist/buy-U35DQ6XM.js +1598 -0
  6. package/dist/buy-U35DQ6XM.js.map +1 -0
  7. package/dist/candidate-RLYCQMF5.js +127 -0
  8. package/dist/candidate-RLYCQMF5.js.map +1 -0
  9. package/dist/{ccip-UCLT5VOW.js → ccip-NQXCEK2U.js} +6 -5
  10. package/dist/ccip-XR5NE5QK.js +19 -0
  11. package/dist/chunk-27ONARHV.js +171 -0
  12. package/dist/chunk-27ONARHV.js.map +1 -0
  13. package/dist/chunk-2I4QTOLB.js +11 -0
  14. package/dist/chunk-2I4QTOLB.js.map +1 -0
  15. package/dist/chunk-3OV7E5G5.js +18 -0
  16. package/dist/chunk-3OV7E5G5.js.map +1 -0
  17. package/dist/chunk-5CLSD5YN.js +209 -0
  18. package/dist/chunk-5CLSD5YN.js.map +1 -0
  19. package/dist/chunk-7KUW4MJD.js +59 -0
  20. package/dist/chunk-7KUW4MJD.js.map +1 -0
  21. package/dist/{doctor-3QBYN46N.js → chunk-7PHSZKQS.js} +88 -93
  22. package/dist/chunk-7PHSZKQS.js.map +1 -0
  23. package/dist/chunk-CYOF7ROH.js +70 -0
  24. package/dist/chunk-CYOF7ROH.js.map +1 -0
  25. package/dist/chunk-HIVZG55D.js +204 -0
  26. package/dist/chunk-HIVZG55D.js.map +1 -0
  27. package/dist/chunk-HSDCI7OV.js +7806 -0
  28. package/dist/chunk-HSDCI7OV.js.map +1 -0
  29. package/dist/{chunk-EZROUI5U.js → chunk-IYLHQMT5.js} +85 -9
  30. package/dist/chunk-IYLHQMT5.js.map +1 -0
  31. package/dist/chunk-JPHG2JW3.js +96 -0
  32. package/dist/chunk-JPHG2JW3.js.map +1 -0
  33. package/dist/{chunk-ZPZFPVDN.js → chunk-MUBUQVC3.js} +1 -1
  34. package/dist/chunk-MUBUQVC3.js.map +1 -0
  35. package/dist/chunk-N62ROTMC.js +79 -0
  36. package/dist/chunk-N62ROTMC.js.map +1 -0
  37. package/dist/{chunk-T4LKNY7T.js → chunk-NCE5NSN6.js} +166 -11
  38. package/dist/chunk-NCE5NSN6.js.map +1 -0
  39. package/dist/{chunk-YG2DO46P.js → chunk-OYMYCW7J.js} +18 -3
  40. package/dist/{chunk-YG2DO46P.js.map → chunk-OYMYCW7J.js.map} +1 -1
  41. package/dist/chunk-QNP7H47L.js +152 -0
  42. package/dist/chunk-QNP7H47L.js.map +1 -0
  43. package/dist/{chunk-Q53IYV2G.js → chunk-QVX5MWJZ.js} +20 -17
  44. package/dist/{chunk-Q53IYV2G.js.map → chunk-QVX5MWJZ.js.map} +1 -1
  45. package/dist/{chunk-CUWUHTIL.js → chunk-RBJPAZFI.js} +16 -202
  46. package/dist/chunk-RBJPAZFI.js.map +1 -0
  47. package/dist/chunk-RRN3YTK7.js +6199 -0
  48. package/dist/chunk-RRN3YTK7.js.map +1 -0
  49. package/dist/chunk-RY4XKNV3.js +140 -0
  50. package/dist/chunk-RY4XKNV3.js.map +1 -0
  51. package/dist/chunk-S3IGX57D.js +14682 -0
  52. package/dist/chunk-S3IGX57D.js.map +1 -0
  53. package/dist/{config-CEFTL5ZL.js → chunk-TFGSOPWR.js} +115 -18
  54. package/dist/chunk-TFGSOPWR.js.map +1 -0
  55. package/dist/chunk-TLCMMYLY.js +126 -0
  56. package/dist/chunk-TLCMMYLY.js.map +1 -0
  57. package/dist/{chunk-IPOWB3G3.js → chunk-UGX7YPX2.js} +3314 -306
  58. package/dist/chunk-UGX7YPX2.js.map +1 -0
  59. package/dist/chunk-UO22YNY4.js +69 -0
  60. package/dist/chunk-UO22YNY4.js.map +1 -0
  61. package/dist/chunk-UPIEAMGH.js +160 -0
  62. package/dist/chunk-UPIEAMGH.js.map +1 -0
  63. package/dist/chunk-XJIW7USF.js +217 -0
  64. package/dist/chunk-XJIW7USF.js.map +1 -0
  65. package/dist/{chunk-BRJHUQSY.js → chunk-YALGASEU.js} +1548 -1452
  66. package/dist/chunk-YALGASEU.js.map +1 -0
  67. package/dist/chunk-YIYQ2ZNT.js +286 -0
  68. package/dist/chunk-YIYQ2ZNT.js.map +1 -0
  69. package/dist/{chunk-DXPYFVKG.js → chunk-YN5SHIXQ.js} +6 -6
  70. package/dist/chunk-YN5SHIXQ.js.map +1 -0
  71. package/dist/chunk-Z52RA3NC.js +137 -0
  72. package/dist/chunk-Z52RA3NC.js.map +1 -0
  73. package/dist/{chunk-EXBMF5X7.js → chunk-Z6MFJV5Z.js} +151 -19
  74. package/dist/chunk-Z6MFJV5Z.js.map +1 -0
  75. package/dist/chunk-ZABPQJ3M.js +83 -0
  76. package/dist/chunk-ZABPQJ3M.js.map +1 -0
  77. package/dist/{chunk-LPRVHM7P.js → chunk-ZMHYXMO6.js} +1655 -114
  78. package/dist/chunk-ZMHYXMO6.js.map +1 -0
  79. package/dist/{chunk-3IMLRUZE.js → chunk-ZXTAQYNA.js} +6 -2
  80. package/dist/{cli-WA65NP4Y.js → cli-4NNBEQYH.js} +177 -177
  81. package/dist/cli-4NNBEQYH.js.map +1 -0
  82. package/dist/config-2VSXWWHK.js +21 -0
  83. package/dist/doctor-JJPNIBYH.js +20 -0
  84. package/dist/doctor-JJPNIBYH.js.map +1 -0
  85. package/dist/ethersCompat-Df4a6QIZ-3YZIAXDK.js +18 -0
  86. package/dist/ethersCompat-Df4a6QIZ-3YZIAXDK.js.map +1 -0
  87. package/dist/index.js +1 -1
  88. package/dist/inspect-JGYJWFDP.js +96 -0
  89. package/dist/inspect-JGYJWFDP.js.map +1 -0
  90. package/dist/install-ZQRMSRGW.js +378 -0
  91. package/dist/install-ZQRMSRGW.js.map +1 -0
  92. package/dist/lookup-WYVTOMVY.js +113 -0
  93. package/dist/lookup-WYVTOMVY.js.map +1 -0
  94. package/dist/{mine.wasm-GQECMSGN.js → mine.wasm-6PIT3DK6.js} +2 -2
  95. package/dist/outcome-HKKT6QIA.js +66 -0
  96. package/dist/outcome-HKKT6QIA.js.map +1 -0
  97. package/dist/publish-D76B3MBK.js +1480 -0
  98. package/dist/publish-D76B3MBK.js.map +1 -0
  99. package/dist/{secp256k1-BEZS642W.js → secp256k1-N3ZHU7LB.js} +5 -4
  100. package/dist/secp256k1-N3ZHU7LB.js.map +1 -0
  101. package/dist/usdc-JIAJW4SV.js +22 -0
  102. package/dist/usdc-JIAJW4SV.js.map +1 -0
  103. package/dist/viemAdapter-By13KInL-ZZE6UV4Y.js +14 -0
  104. package/dist/viemAdapter-By13KInL-ZZE6UV4Y.js.map +1 -0
  105. package/dist/{wallet-XD576HF3.js → wallet-6QKS6UHW.js} +28 -22
  106. package/dist/{wallet-XD576HF3.js.map → wallet-6QKS6UHW.js.map} +1 -1
  107. package/dist/wallet-PA54CRBL.js +30 -0
  108. package/dist/wallet-PA54CRBL.js.map +1 -0
  109. package/package.json +19 -16
  110. package/skills/tenjin/SKILL.md +199 -0
  111. package/skills/tenjin-publish/SKILL.md +96 -0
  112. package/skills/tenjin-search/SKILL.md +122 -0
  113. package/dist/chunk-BRJHUQSY.js.map +0 -1
  114. package/dist/chunk-CUWUHTIL.js.map +0 -1
  115. package/dist/chunk-DXPYFVKG.js.map +0 -1
  116. package/dist/chunk-EXBMF5X7.js.map +0 -1
  117. package/dist/chunk-EZROUI5U.js.map +0 -1
  118. package/dist/chunk-IPOWB3G3.js.map +0 -1
  119. package/dist/chunk-LPRVHM7P.js.map +0 -1
  120. package/dist/chunk-T4LKNY7T.js.map +0 -1
  121. package/dist/chunk-ZPZFPVDN.js.map +0 -1
  122. package/dist/cli-WA65NP4Y.js.map +0 -1
  123. package/dist/config-CEFTL5ZL.js.map +0 -1
  124. package/dist/doctor-3QBYN46N.js.map +0 -1
  125. package/dist/usdc-44R6XZF2.js +0 -18
  126. package/dist/wallet-ELBTBMXO.js +0 -20
  127. /package/dist/{_esm-ZH2J4QEH.js.map → _esm-C5CRWCYU.js.map} +0 -0
  128. /package/dist/{ccip-UCLT5VOW.js.map → _esm-FEASBWRP.js.map} +0 -0
  129. /package/dist/{chunk-3IMLRUZE.js.map → ccip-NQXCEK2U.js.map} +0 -0
  130. /package/dist/{secp256k1-BEZS642W.js.map → ccip-XR5NE5QK.js.map} +0 -0
  131. /package/dist/{usdc-44R6XZF2.js.map → chunk-ZXTAQYNA.js.map} +0 -0
  132. /package/dist/{wallet-ELBTBMXO.js.map → config-2VSXWWHK.js.map} +0 -0
  133. /package/dist/{mine.wasm-GQECMSGN.js.map → mine.wasm-6PIT3DK6.js.map} +0 -0
@@ -1,4 +1,25 @@
1
1
  import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
+ import {
3
+ PRIVATE_KEY_RE,
4
+ readWalletRecord,
5
+ walletFileMode,
6
+ writeWalletRecord
7
+ } from "./chunk-YN5SHIXQ.js";
8
+ import {
9
+ withFileLock
10
+ } from "./chunk-YBMMV4Y4.js";
11
+ import {
12
+ evaluateSpendPolicy
13
+ } from "./chunk-UO22YNY4.js";
14
+ import {
15
+ writeFileAtomic
16
+ } from "./chunk-MUBUQVC3.js";
17
+ import {
18
+ CliError,
19
+ external_exports,
20
+ passphraseBlobPath,
21
+ walletPath
22
+ } from "./chunk-OYMYCW7J.js";
2
23
  import {
3
24
  hashAuthorization,
4
25
  hashMessage,
@@ -7,12 +28,12 @@ import {
7
28
  publicKeyToAddress,
8
29
  serializeSignature,
9
30
  serializeTransaction
10
- } from "./chunk-T4LKNY7T.js";
31
+ } from "./chunk-NCE5NSN6.js";
11
32
  import {
12
33
  hmac,
13
34
  secp256k1,
14
35
  sha256
15
- } from "./chunk-Q53IYV2G.js";
36
+ } from "./chunk-QVX5MWJZ.js";
16
37
  import {
17
38
  InvalidAddressError,
18
39
  concat3 as concat,
@@ -27,7 +48,7 @@ import {
27
48
  slice3 as slice,
28
49
  toHex,
29
50
  toHex2
30
- } from "./chunk-BRJHUQSY.js";
51
+ } from "./chunk-YALGASEU.js";
31
52
  import {
32
53
  ahash,
33
54
  anumber,
@@ -39,21 +60,7 @@ import {
39
60
  rotl,
40
61
  swap32IfBE,
41
62
  u32
42
- } from "./chunk-CUWUHTIL.js";
43
- import {
44
- PRIVATE_KEY_RE,
45
- readWalletRecord,
46
- walletFileMode,
47
- writeWalletRecord
48
- } from "./chunk-DXPYFVKG.js";
49
- import {
50
- writeFileAtomic
51
- } from "./chunk-ZPZFPVDN.js";
52
- import {
53
- CliError,
54
- passphraseBlobPath,
55
- walletPath
56
- } from "./chunk-YG2DO46P.js";
63
+ } from "./chunk-5CLSD5YN.js";
57
64
 
58
65
  // node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/pbkdf2.js
59
66
  function pbkdf2Init(hash, _password, _salt, _opts) {
@@ -1166,11 +1173,134 @@ function walletRecord(address, keystore) {
1166
1173
  };
1167
1174
  }
1168
1175
 
1176
+ // src/lib/wallet/spend.ts
1177
+ import { mkdir, readFile as readFile2 } from "fs/promises";
1178
+ import { randomUUID } from "crypto";
1179
+ import { join } from "path";
1180
+ var DEFAULT_WINDOW_MS = 864e5;
1181
+ var RESERVATION_TTL_MS = 6e5;
1182
+ var ReservationSchema = external_exports.object({
1183
+ id: external_exports.string(),
1184
+ amountAtomic: external_exports.string().regex(/^\d+$/),
1185
+ atMs: external_exports.number()
1186
+ });
1187
+ var LedgerSchema = external_exports.object({
1188
+ schemaVersion: external_exports.literal(2),
1189
+ windowStartMs: external_exports.number(),
1190
+ committedAtomic: external_exports.string().regex(/^\d+$/),
1191
+ reservations: external_exports.array(ReservationSchema)
1192
+ });
1193
+ function emptyLedger(nowMs) {
1194
+ return { schemaVersion: 2, windowStartMs: nowMs, committedAtomic: "0", reservations: [] };
1195
+ }
1196
+ function createLocalSpendAuthorizer(deps) {
1197
+ const windowMs = deps.windowMs ?? DEFAULT_WINDOW_MS;
1198
+ const now = deps.now ?? Date.now;
1199
+ const path = join(deps.dir, "session.json");
1200
+ const lockPath = `${path}.lock`;
1201
+ const freshen = (ledger, nowMs) => {
1202
+ if (ledger === null || nowMs - ledger.windowStartMs >= windowMs) return emptyLedger(nowMs);
1203
+ return {
1204
+ ...ledger,
1205
+ reservations: ledger.reservations.filter((r) => nowMs - r.atMs < RESERVATION_TTL_MS)
1206
+ };
1207
+ };
1208
+ const spentOf = (ledger) => ledger.reservations.reduce(
1209
+ (sum, r) => sum + BigInt(r.amountAtomic),
1210
+ BigInt(ledger.committedAtomic)
1211
+ );
1212
+ const persist = async (ledger) => {
1213
+ await writeFileAtomic(path, `${JSON.stringify(ledger, null, 2)}
1214
+ `, {
1215
+ mode: 384,
1216
+ dirMode: 448
1217
+ });
1218
+ };
1219
+ async function withLedger(fn) {
1220
+ await mkdir(deps.dir, { recursive: true, mode: 448 });
1221
+ return withFileLock(lockPath, async () => {
1222
+ const nowMs = now();
1223
+ const ledger = freshen(await readLedger(path), nowMs);
1224
+ return fn(ledger, nowMs);
1225
+ });
1226
+ }
1227
+ return {
1228
+ policyEnforcement: "client-only",
1229
+ async authorize(req) {
1230
+ return withLedger(async (ledger) => {
1231
+ const sessionSpentAtomic = spentOf(ledger);
1232
+ const evaluation = evaluateSpendPolicy(deps.policy, {
1233
+ amountAtomic: req.amountAtomic,
1234
+ creator: req.creator,
1235
+ ...req.maxPriceAtomic !== void 0 ? { maxPriceAtomic: req.maxPriceAtomic } : {},
1236
+ sessionSpentAtomic
1237
+ });
1238
+ const base = {
1239
+ ...evaluation,
1240
+ amountAtomic: req.amountAtomic,
1241
+ sessionSpentAtomic,
1242
+ sessionBudgetAtomic: deps.policy.sessionBudgetAtomic,
1243
+ policyEnforcement: "client-only"
1244
+ };
1245
+ if (evaluation.decision === "deny" || deps.policy.sessionBudgetAtomic === 0n) {
1246
+ return base;
1247
+ }
1248
+ const reservation = {
1249
+ id: randomUUID(),
1250
+ amountAtomic: req.amountAtomic.toString(),
1251
+ atMs: now()
1252
+ };
1253
+ await persist({ ...ledger, reservations: [...ledger.reservations, reservation] });
1254
+ return { ...base, reservationId: reservation.id };
1255
+ });
1256
+ },
1257
+ async commit(reservationId, amountAtomic) {
1258
+ await withLedger(async (ledger) => {
1259
+ const reservation = reservationId !== void 0 ? ledger.reservations.find((r) => r.id === reservationId) : void 0;
1260
+ const settled = reservation !== void 0 ? BigInt(reservation.amountAtomic) : amountAtomic;
1261
+ await persist({
1262
+ ...ledger,
1263
+ committedAtomic: (BigInt(ledger.committedAtomic) + settled).toString(),
1264
+ reservations: reservationId !== void 0 ? ledger.reservations.filter((r) => r.id !== reservationId) : ledger.reservations
1265
+ });
1266
+ });
1267
+ },
1268
+ async release(reservationId) {
1269
+ if (reservationId === void 0) return;
1270
+ await withLedger(async (ledger) => {
1271
+ if (!ledger.reservations.some((r) => r.id === reservationId)) return;
1272
+ await persist({
1273
+ ...ledger,
1274
+ reservations: ledger.reservations.filter((r) => r.id !== reservationId)
1275
+ });
1276
+ });
1277
+ }
1278
+ };
1279
+ }
1280
+ async function readLedger(path) {
1281
+ let raw;
1282
+ try {
1283
+ raw = await readFile2(path, "utf8");
1284
+ } catch {
1285
+ return null;
1286
+ }
1287
+ try {
1288
+ const parsed = LedgerSchema.safeParse(JSON.parse(raw));
1289
+ return parsed.success ? parsed.data : null;
1290
+ } catch {
1291
+ return null;
1292
+ }
1293
+ }
1294
+
1169
1295
  // src/lib/wallet/index.ts
1170
1296
  function resolveWalletProvider(ctx, opts = {}) {
1171
1297
  if (opts.provider !== void 0) return opts.provider;
1172
1298
  return createLocalProvider({ dir: ctx.dataDir, env: process.env });
1173
1299
  }
1300
+ function resolveSpendAuthorizer(ctx, policy, opts = {}) {
1301
+ if (opts.authorizer !== void 0) return opts.authorizer;
1302
+ return createLocalSpendAuthorizer({ dir: ctx.dataDir, policy });
1303
+ }
1174
1304
  async function describeWallet(provider) {
1175
1305
  try {
1176
1306
  return await provider.describe();
@@ -1187,7 +1317,9 @@ async function describeWallet(provider) {
1187
1317
  export {
1188
1318
  resolvePassphraseForCreate,
1189
1319
  createLocalWallet,
1320
+ createLocalSpendAuthorizer,
1190
1321
  resolveWalletProvider,
1322
+ resolveSpendAuthorizer,
1191
1323
  describeWallet
1192
1324
  };
1193
1325
  /*! Bundled license information:
@@ -1195,4 +1327,4 @@ export {
1195
1327
  @noble/ciphers/esm/utils.js:
1196
1328
  (*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) *)
1197
1329
  */
1198
- //# sourceMappingURL=chunk-EXBMF5X7.js.map
1330
+ //# sourceMappingURL=chunk-Z6MFJV5Z.js.map