tenjin-cli 0.1.0-alpha.1 → 0.1.0-alpha.3
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/NOTICE.md +33 -0
- package/README.md +167 -16
- package/dist/{_esm-ZH2J4QEH.js → _esm-C5CRWCYU.js} +2 -2
- package/dist/_esm-FEASBWRP.js +881 -0
- package/dist/buy-EE6SEXP6.js +1598 -0
- package/dist/buy-EE6SEXP6.js.map +1 -0
- package/dist/candidate-ERMSYYQZ.js +127 -0
- package/dist/candidate-ERMSYYQZ.js.map +1 -0
- package/dist/{ccip-UCLT5VOW.js → ccip-NQXCEK2U.js} +6 -5
- package/dist/ccip-XR5NE5QK.js +19 -0
- package/dist/chunk-2I4QTOLB.js +11 -0
- package/dist/chunk-2I4QTOLB.js.map +1 -0
- package/dist/chunk-3OV7E5G5.js +18 -0
- package/dist/chunk-3OV7E5G5.js.map +1 -0
- package/dist/chunk-4ONXEEQL.js +152 -0
- package/dist/chunk-4ONXEEQL.js.map +1 -0
- package/dist/chunk-5CLSD5YN.js +209 -0
- package/dist/chunk-5CLSD5YN.js.map +1 -0
- package/dist/chunk-662MSGZB.js +286 -0
- package/dist/chunk-662MSGZB.js.map +1 -0
- package/dist/chunk-7KUW4MJD.js +59 -0
- package/dist/chunk-7KUW4MJD.js.map +1 -0
- package/dist/{doctor-3QBYN46N.js → chunk-AWPAWHNX.js} +88 -93
- package/dist/chunk-AWPAWHNX.js.map +1 -0
- package/dist/chunk-CYOF7ROH.js +70 -0
- package/dist/chunk-CYOF7ROH.js.map +1 -0
- package/dist/chunk-DXTQ3CSI.js +171 -0
- package/dist/chunk-DXTQ3CSI.js.map +1 -0
- package/dist/{chunk-EZROUI5U.js → chunk-ESPNTPQ2.js} +80 -8
- package/dist/chunk-ESPNTPQ2.js.map +1 -0
- package/dist/chunk-FJPLRISB.js +79 -0
- package/dist/chunk-FJPLRISB.js.map +1 -0
- package/dist/chunk-GO75V3NZ.js +160 -0
- package/dist/chunk-GO75V3NZ.js.map +1 -0
- package/dist/chunk-HIVZG55D.js +204 -0
- package/dist/chunk-HIVZG55D.js.map +1 -0
- package/dist/chunk-HSDCI7OV.js +7806 -0
- package/dist/chunk-HSDCI7OV.js.map +1 -0
- package/dist/chunk-JPHG2JW3.js +96 -0
- package/dist/chunk-JPHG2JW3.js.map +1 -0
- package/dist/{chunk-ZPZFPVDN.js → chunk-MUBUQVC3.js} +1 -1
- package/dist/chunk-MUBUQVC3.js.map +1 -0
- package/dist/{chunk-T4LKNY7T.js → chunk-NCE5NSN6.js} +166 -11
- package/dist/chunk-NCE5NSN6.js.map +1 -0
- package/dist/{chunk-YG2DO46P.js → chunk-OYMYCW7J.js} +18 -3
- package/dist/{chunk-YG2DO46P.js.map → chunk-OYMYCW7J.js.map} +1 -1
- package/dist/{chunk-Q53IYV2G.js → chunk-QVX5MWJZ.js} +20 -17
- package/dist/{chunk-Q53IYV2G.js.map → chunk-QVX5MWJZ.js.map} +1 -1
- package/dist/{chunk-CUWUHTIL.js → chunk-RBJPAZFI.js} +16 -202
- package/dist/chunk-RBJPAZFI.js.map +1 -0
- package/dist/chunk-RRN3YTK7.js +6199 -0
- package/dist/chunk-RRN3YTK7.js.map +1 -0
- package/dist/chunk-RY4XKNV3.js +140 -0
- package/dist/chunk-RY4XKNV3.js.map +1 -0
- package/dist/chunk-S3IGX57D.js +14682 -0
- package/dist/chunk-S3IGX57D.js.map +1 -0
- package/dist/chunk-TLCMMYLY.js +126 -0
- package/dist/chunk-TLCMMYLY.js.map +1 -0
- package/dist/{chunk-IPOWB3G3.js → chunk-UGX7YPX2.js} +3314 -306
- package/dist/chunk-UGX7YPX2.js.map +1 -0
- package/dist/chunk-UO22YNY4.js +69 -0
- package/dist/chunk-UO22YNY4.js.map +1 -0
- package/dist/{config-CEFTL5ZL.js → chunk-XHC6FCGZ.js} +115 -18
- package/dist/chunk-XHC6FCGZ.js.map +1 -0
- package/dist/chunk-XJIW7USF.js +217 -0
- package/dist/chunk-XJIW7USF.js.map +1 -0
- package/dist/{chunk-BRJHUQSY.js → chunk-YALGASEU.js} +1548 -1452
- package/dist/chunk-YALGASEU.js.map +1 -0
- package/dist/{chunk-DXPYFVKG.js → chunk-YN5SHIXQ.js} +6 -6
- package/dist/chunk-YN5SHIXQ.js.map +1 -0
- package/dist/chunk-Z52RA3NC.js +137 -0
- package/dist/chunk-Z52RA3NC.js.map +1 -0
- package/dist/{chunk-EXBMF5X7.js → chunk-Z6MFJV5Z.js} +151 -19
- package/dist/chunk-Z6MFJV5Z.js.map +1 -0
- package/dist/chunk-ZABPQJ3M.js +83 -0
- package/dist/chunk-ZABPQJ3M.js.map +1 -0
- package/dist/{chunk-LPRVHM7P.js → chunk-ZMHYXMO6.js} +1655 -114
- package/dist/chunk-ZMHYXMO6.js.map +1 -0
- package/dist/{chunk-3IMLRUZE.js → chunk-ZXTAQYNA.js} +6 -2
- package/dist/{cli-WA65NP4Y.js → cli-SBXI5AMS.js} +177 -177
- package/dist/cli-SBXI5AMS.js.map +1 -0
- package/dist/config-VELDKLHY.js +21 -0
- package/dist/doctor-T3KWNNP2.js +20 -0
- package/dist/doctor-T3KWNNP2.js.map +1 -0
- package/dist/ethersCompat-Df4a6QIZ-3YZIAXDK.js +18 -0
- package/dist/ethersCompat-Df4a6QIZ-3YZIAXDK.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/inspect-LMKOXE4Y.js +96 -0
- package/dist/inspect-LMKOXE4Y.js.map +1 -0
- package/dist/install-LEX3ENQ6.js +387 -0
- package/dist/install-LEX3ENQ6.js.map +1 -0
- package/dist/lookup-ZPN2Q67N.js +129 -0
- package/dist/lookup-ZPN2Q67N.js.map +1 -0
- package/dist/{mine.wasm-GQECMSGN.js → mine.wasm-6PIT3DK6.js} +2 -2
- package/dist/outcome-N7TAK6WR.js +66 -0
- package/dist/outcome-N7TAK6WR.js.map +1 -0
- package/dist/publish-BKBQQAW4.js +1478 -0
- package/dist/publish-BKBQQAW4.js.map +1 -0
- package/dist/{secp256k1-BEZS642W.js → secp256k1-N3ZHU7LB.js} +5 -4
- package/dist/secp256k1-N3ZHU7LB.js.map +1 -0
- package/dist/usdc-JIAJW4SV.js +22 -0
- package/dist/usdc-JIAJW4SV.js.map +1 -0
- package/dist/viemAdapter-By13KInL-ZZE6UV4Y.js +14 -0
- package/dist/viemAdapter-By13KInL-ZZE6UV4Y.js.map +1 -0
- package/dist/{wallet-XD576HF3.js → wallet-CWEMYVIH.js} +28 -22
- package/dist/{wallet-XD576HF3.js.map → wallet-CWEMYVIH.js.map} +1 -1
- package/dist/wallet-PA54CRBL.js +30 -0
- package/dist/wallet-PA54CRBL.js.map +1 -0
- package/package.json +19 -16
- package/skills/tenjin/SKILL.md +199 -0
- package/skills/tenjin-publish/SKILL.md +111 -0
- package/skills/tenjin-search/SKILL.md +133 -0
- package/dist/chunk-BRJHUQSY.js.map +0 -1
- package/dist/chunk-CUWUHTIL.js.map +0 -1
- package/dist/chunk-DXPYFVKG.js.map +0 -1
- package/dist/chunk-EXBMF5X7.js.map +0 -1
- package/dist/chunk-EZROUI5U.js.map +0 -1
- package/dist/chunk-IPOWB3G3.js.map +0 -1
- package/dist/chunk-LPRVHM7P.js.map +0 -1
- package/dist/chunk-T4LKNY7T.js.map +0 -1
- package/dist/chunk-ZPZFPVDN.js.map +0 -1
- package/dist/cli-WA65NP4Y.js.map +0 -1
- package/dist/config-CEFTL5ZL.js.map +0 -1
- package/dist/doctor-3QBYN46N.js.map +0 -1
- package/dist/usdc-44R6XZF2.js +0 -18
- package/dist/wallet-ELBTBMXO.js +0 -20
- /package/dist/{_esm-ZH2J4QEH.js.map → _esm-C5CRWCYU.js.map} +0 -0
- /package/dist/{ccip-UCLT5VOW.js.map → _esm-FEASBWRP.js.map} +0 -0
- /package/dist/{chunk-3IMLRUZE.js.map → ccip-NQXCEK2U.js.map} +0 -0
- /package/dist/{secp256k1-BEZS642W.js.map → ccip-XR5NE5QK.js.map} +0 -0
- /package/dist/{usdc-44R6XZF2.js.map → chunk-ZXTAQYNA.js.map} +0 -0
- /package/dist/{wallet-ELBTBMXO.js.map → config-VELDKLHY.js.map} +0 -0
- /package/dist/{mine.wasm-GQECMSGN.js.map → mine.wasm-6PIT3DK6.js.map} +0 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
withFileLock
|
|
4
|
+
} from "./chunk-YBMMV4Y4.js";
|
|
5
|
+
import {
|
|
6
|
+
writeFileAtomic
|
|
7
|
+
} from "./chunk-MUBUQVC3.js";
|
|
8
|
+
import {
|
|
9
|
+
external_exports
|
|
10
|
+
} from "./chunk-OYMYCW7J.js";
|
|
11
|
+
|
|
12
|
+
// src/lib/lookup-store.ts
|
|
13
|
+
import { mkdir, readFile } from "fs/promises";
|
|
14
|
+
import { join } from "path";
|
|
15
|
+
var MAX_ENTRIES = 50;
|
|
16
|
+
var StoredCandidateSchema = external_exports.object({
|
|
17
|
+
resourceId: external_exports.string(),
|
|
18
|
+
url: external_exports.string(),
|
|
19
|
+
title: external_exports.string(),
|
|
20
|
+
price: external_exports.string()
|
|
21
|
+
});
|
|
22
|
+
var StoredLookupSchema = external_exports.object({
|
|
23
|
+
lookupId: external_exports.string(),
|
|
24
|
+
at: external_exports.string(),
|
|
25
|
+
question: external_exports.string(),
|
|
26
|
+
decision: external_exports.string(),
|
|
27
|
+
candidates: external_exports.array(StoredCandidateSchema)
|
|
28
|
+
});
|
|
29
|
+
var StoreSchema = external_exports.object({
|
|
30
|
+
schemaVersion: external_exports.literal(1),
|
|
31
|
+
lookups: external_exports.array(StoredLookupSchema)
|
|
32
|
+
});
|
|
33
|
+
function storePath(dataDir) {
|
|
34
|
+
return join(dataDir, "lookups.json");
|
|
35
|
+
}
|
|
36
|
+
async function loadLookups(dataDir) {
|
|
37
|
+
let raw;
|
|
38
|
+
try {
|
|
39
|
+
raw = await readFile(storePath(dataDir), "utf8");
|
|
40
|
+
} catch {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
let json;
|
|
44
|
+
try {
|
|
45
|
+
json = JSON.parse(raw);
|
|
46
|
+
} catch {
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
const parsed = StoreSchema.safeParse(json);
|
|
50
|
+
return parsed.success ? parsed.data.lookups : [];
|
|
51
|
+
}
|
|
52
|
+
async function recordLookup(dataDir, entry) {
|
|
53
|
+
await mkdir(dataDir, { recursive: true, mode: 448 });
|
|
54
|
+
const lockPath = `${storePath(dataDir)}.lock`;
|
|
55
|
+
await withFileLock(lockPath, async () => {
|
|
56
|
+
const existing = await loadLookups(dataDir);
|
|
57
|
+
const lookups = [entry, ...existing.filter((l) => l.lookupId !== entry.lookupId)].slice(
|
|
58
|
+
0,
|
|
59
|
+
MAX_ENTRIES
|
|
60
|
+
);
|
|
61
|
+
await writeFileAtomic(
|
|
62
|
+
storePath(dataDir),
|
|
63
|
+
`${JSON.stringify({ schemaVersion: 1, lookups }, null, 2)}
|
|
64
|
+
`,
|
|
65
|
+
{ mode: 420, dirMode: 448 }
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async function latestLookup(dataDir) {
|
|
70
|
+
const lookups = await loadLookups(dataDir);
|
|
71
|
+
return lookups[0] ?? null;
|
|
72
|
+
}
|
|
73
|
+
async function findStoredCandidate(dataDir, resourceId) {
|
|
74
|
+
for (const lookup of await loadLookups(dataDir)) {
|
|
75
|
+
const hit = lookup.candidates.find((c) => c.resourceId === resourceId);
|
|
76
|
+
if (hit) return hit;
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
async function findLookupForResource(dataDir, match) {
|
|
81
|
+
for (const lookup of await loadLookups(dataDir)) {
|
|
82
|
+
const hit = lookup.candidates.some(
|
|
83
|
+
(c) => match.resourceId !== void 0 && c.resourceId === match.resourceId || match.url !== void 0 && c.url === match.url
|
|
84
|
+
);
|
|
85
|
+
if (hit) return lookup.lookupId;
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export {
|
|
91
|
+
recordLookup,
|
|
92
|
+
latestLookup,
|
|
93
|
+
findStoredCandidate,
|
|
94
|
+
findLookupForResource
|
|
95
|
+
};
|
|
96
|
+
//# sourceMappingURL=chunk-JPHG2JW3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/lookup-store.ts"],"sourcesContent":["import { mkdir, readFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { z } from 'zod';\nimport { writeFileAtomic } from './atomic-json';\nimport { withFileLock } from './lock';\n\n/**\n * A small local ledger of recent lookups so `outcome --last` can target the most\n * recent one and `buy <resourceId>` can resolve the payable read URL a candidate\n * carried (the read route is keyed by handle/slug, not id, so an id alone can't\n * build the URL). Bounded and best-effort: a corrupt file reads as empty rather\n * than blocking a command. NOT an entitlement record, that is the library receipt.\n */\n\nconst MAX_ENTRIES = 50;\n\nconst StoredCandidateSchema = z.object({\n resourceId: z.string(),\n url: z.string(),\n title: z.string(),\n price: z.string(),\n});\nexport type StoredCandidate = z.infer<typeof StoredCandidateSchema>;\n\nconst StoredLookupSchema = z.object({\n lookupId: z.string(),\n at: z.string(),\n question: z.string(),\n decision: z.string(),\n candidates: z.array(StoredCandidateSchema),\n});\nexport type StoredLookup = z.infer<typeof StoredLookupSchema>;\n\nconst StoreSchema = z.object({\n schemaVersion: z.literal(1),\n lookups: z.array(StoredLookupSchema),\n});\n\nfunction storePath(dataDir: string): string {\n return join(dataDir, 'lookups.json');\n}\n\nexport async function loadLookups(dataDir: string): Promise<StoredLookup[]> {\n let raw: string;\n try {\n raw = await readFile(storePath(dataDir), 'utf8');\n } catch {\n return [];\n }\n let json: unknown;\n try {\n json = JSON.parse(raw);\n } catch {\n return [];\n }\n const parsed = StoreSchema.safeParse(json);\n return parsed.success ? parsed.data.lookups : [];\n}\n\n/** Prepend a lookup (newest first), cap to MAX_ENTRIES, persist under a lock so\n * concurrent lookups don't drop each other's entry. */\nexport async function recordLookup(dataDir: string, entry: StoredLookup): Promise<void> {\n await mkdir(dataDir, { recursive: true, mode: 0o700 });\n const lockPath = `${storePath(dataDir)}.lock`;\n await withFileLock(lockPath, async () => {\n const existing = await loadLookups(dataDir);\n const lookups = [entry, ...existing.filter((l) => l.lookupId !== entry.lookupId)].slice(\n 0,\n MAX_ENTRIES,\n );\n await writeFileAtomic(\n storePath(dataDir),\n `${JSON.stringify({ schemaVersion: 1, lookups }, null, 2)}\\n`,\n { mode: 0o644, dirMode: 0o700 },\n );\n });\n}\n\nexport async function latestLookup(dataDir: string): Promise<StoredLookup | null> {\n const lookups = await loadLookups(dataDir);\n return lookups[0] ?? null;\n}\n\n/** The stored candidate for a resourceId across recent lookups (newest first). */\nexport async function findStoredCandidate(\n dataDir: string,\n resourceId: string,\n): Promise<StoredCandidate | null> {\n for (const lookup of await loadLookups(dataDir)) {\n const hit = lookup.candidates.find((c) => c.resourceId === resourceId);\n if (hit) return hit;\n }\n return null;\n}\n\n/** The most recent lookupId that surfaced this resource (by id or url), for\n * purchase attribution (`X-Tenjin-Lookup-Id`). Null when no local lookup did. */\nexport async function findLookupForResource(\n dataDir: string,\n match: { resourceId?: string; url?: string },\n): Promise<string | null> {\n for (const lookup of await loadLookups(dataDir)) {\n const hit = lookup.candidates.some(\n (c) =>\n (match.resourceId !== undefined && c.resourceId === match.resourceId) ||\n (match.url !== undefined && c.url === match.url),\n );\n if (hit) return lookup.lookupId;\n }\n return null;\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,OAAO,gBAAgB;AAChC,SAAS,YAAY;AAarB,IAAM,cAAc;AAEpB,IAAM,wBAAwB,iBAAE,OAAO;AAAA,EACrC,YAAY,iBAAE,OAAO;AAAA,EACrB,KAAK,iBAAE,OAAO;AAAA,EACd,OAAO,iBAAE,OAAO;AAAA,EAChB,OAAO,iBAAE,OAAO;AAClB,CAAC;AAGD,IAAM,qBAAqB,iBAAE,OAAO;AAAA,EAClC,UAAU,iBAAE,OAAO;AAAA,EACnB,IAAI,iBAAE,OAAO;AAAA,EACb,UAAU,iBAAE,OAAO;AAAA,EACnB,UAAU,iBAAE,OAAO;AAAA,EACnB,YAAY,iBAAE,MAAM,qBAAqB;AAC3C,CAAC;AAGD,IAAM,cAAc,iBAAE,OAAO;AAAA,EAC3B,eAAe,iBAAE,QAAQ,CAAC;AAAA,EAC1B,SAAS,iBAAE,MAAM,kBAAkB;AACrC,CAAC;AAED,SAAS,UAAU,SAAyB;AAC1C,SAAO,KAAK,SAAS,cAAc;AACrC;AAEA,eAAsB,YAAY,SAA0C;AAC1E,MAAI;AACJ,MAAI;AACF,UAAM,MAAM,SAAS,UAAU,OAAO,GAAG,MAAM;AAAA,EACjD,QAAQ;AACN,WAAO,CAAC;AAAA,EACV;AACA,MAAI;AACJ,MAAI;AACF,WAAO,KAAK,MAAM,GAAG;AAAA,EACvB,QAAQ;AACN,WAAO,CAAC;AAAA,EACV;AACA,QAAM,SAAS,YAAY,UAAU,IAAI;AACzC,SAAO,OAAO,UAAU,OAAO,KAAK,UAAU,CAAC;AACjD;AAIA,eAAsB,aAAa,SAAiB,OAAoC;AACtF,QAAM,MAAM,SAAS,EAAE,WAAW,MAAM,MAAM,IAAM,CAAC;AACrD,QAAM,WAAW,GAAG,UAAU,OAAO,CAAC;AACtC,QAAM,aAAa,UAAU,YAAY;AACvC,UAAM,WAAW,MAAM,YAAY,OAAO;AAC1C,UAAM,UAAU,CAAC,OAAO,GAAG,SAAS,OAAO,CAAC,MAAM,EAAE,aAAa,MAAM,QAAQ,CAAC,EAAE;AAAA,MAChF;AAAA,MACA;AAAA,IACF;AACA,UAAM;AAAA,MACJ,UAAU,OAAO;AAAA,MACjB,GAAG,KAAK,UAAU,EAAE,eAAe,GAAG,QAAQ,GAAG,MAAM,CAAC,CAAC;AAAA;AAAA,MACzD,EAAE,MAAM,KAAO,SAAS,IAAM;AAAA,IAChC;AAAA,EACF,CAAC;AACH;AAEA,eAAsB,aAAa,SAA+C;AAChF,QAAM,UAAU,MAAM,YAAY,OAAO;AACzC,SAAO,QAAQ,CAAC,KAAK;AACvB;AAGA,eAAsB,oBACpB,SACA,YACiC;AACjC,aAAW,UAAU,MAAM,YAAY,OAAO,GAAG;AAC/C,UAAM,MAAM,OAAO,WAAW,KAAK,CAAC,MAAM,EAAE,eAAe,UAAU;AACrE,QAAI,IAAK,QAAO;AAAA,EAClB;AACA,SAAO;AACT;AAIA,eAAsB,sBACpB,SACA,OACwB;AACxB,aAAW,UAAU,MAAM,YAAY,OAAO,GAAG;AAC/C,UAAM,MAAM,OAAO,WAAW;AAAA,MAC5B,CAAC,MACE,MAAM,eAAe,UAAa,EAAE,eAAe,MAAM,cACzD,MAAM,QAAQ,UAAa,EAAE,QAAQ,MAAM;AAAA,IAChD;AACA,QAAI,IAAK,QAAO,OAAO;AAAA,EACzB;AACA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/atomic-json.ts"],"sourcesContent":["import { chmod, link, mkdir, open, rename, rm, writeFile } from 'node:fs/promises';\nimport { randomBytes } from 'node:crypto';\nimport { basename, dirname, join } from 'node:path';\n\n/** fs modes are no-ops on Windows; the 0600/0700 custody story does not apply. */\nconst isWindows = process.platform === 'win32';\n\nexport interface AtomicWriteOptions {\n /** Mode for the written file (ignored on win32). Default 0o644. */\n mode?: number;\n /** Mode for the parent dir when this call creates it (ignored on win32). Default 0o755. */\n dirMode?: number;\n}\n\n/**\n * Write `data` to `targetPath` atomically: a uniquely-named temp file is created\n * in the SAME directory (so the rename is atomic — a cross-filesystem rename is\n * not), given the final mode at open time, then renamed over the target. A\n * reader therefore sees either the old file or the fully-written new one, never\n * a partial write.\n *\n * The temp file is born with the caller's `mode` (0o600 for a wallet key) so the\n * bytes are never written through a world-readable descriptor; the follow-up\n * chmod only makes the mode exact under an unusual umask and only ever touches\n * the temp path, so the live target still appears atomically at its final mode.\n */\nexport async function writeFileAtomic(\n targetPath: string,\n data: string | Buffer,\n opts: AtomicWriteOptions = {},\n): Promise<void> {\n const dir = dirname(targetPath);\n const fileMode = opts.mode ?? 0o644;\n const dirMode = opts.dirMode ?? 0o755;\n\n await mkdir(dir, { recursive: true, ...(isWindows ? {} : { mode: dirMode }) });\n\n const tmpPath = join(dir, `.${basename(targetPath)}.${randomBytes(6).toString('hex')}.tmp`);\n try {\n await writeFile(tmpPath, data, isWindows ? undefined : { mode: fileMode });\n if (!isWindows) await chmod(tmpPath, fileMode);\n await rename(tmpPath, targetPath);\n } catch (err) {\n await rm(tmpPath, { force: true }).catch(() => undefined);\n throw err;\n }\n}\n\n/**\n * Like {@link writeFileAtomic} but NO-CLOBBER and crash-durable: the commit fails\n * with `EEXIST` when `targetPath` already exists instead of replacing it, and the\n * new entry is fsynced before returning. This is what a wallet key needs — two\n * concurrent `create`/`import` runs must not both \"succeed\" and silently lose one\n * key; the loser gets a distinguishable EEXIST the wallet layer maps to\n * WALLET_EXISTS.\n *\n * The temp file is fsynced, then `link()` commits it — link is atomic and throws\n * EEXIST if the target already exists, so the check-then-write race is closed at\n * the filesystem, not by an earlier stat. The parent dir is then fsynced so the\n * new entry survives a crash. On win32, link semantics differ and a directory\n * cannot be fsynced, so we fall back to an exclusive `wx` open (still atomic\n * create-or-EEXIST, just not crash-durable — win32 has no 0600 custody story to\n * protect anyway).\n */\nexport async function writeFileAtomicExclusive(\n targetPath: string,\n data: string,\n opts: AtomicWriteOptions = {},\n): Promise<void> {\n const dir = dirname(targetPath);\n const fileMode = opts.mode ?? 0o644;\n const dirMode = opts.dirMode ?? 0o755;\n\n await mkdir(dir, { recursive: true, ...(isWindows ? {} : { mode: dirMode }) });\n\n if (isWindows) {\n const handle = await open(targetPath, 'wx');\n try {\n await handle.writeFile(data);\n await handle.sync();\n } finally {\n await handle.close();\n }\n return;\n }\n\n const tmpPath = join(dir, `.${basename(targetPath)}.${randomBytes(6).toString('hex')}.tmp`);\n try {\n const handle = await open(tmpPath, 'wx', fileMode);\n try {\n await handle.writeFile(data);\n await handle.chmod(fileMode); // exact mode even under an unusual umask\n await handle.sync();\n } finally {\n await handle.close();\n }\n await link(tmpPath, targetPath); // atomic; throws EEXIST when the target exists\n await fsyncDir(dir);\n } finally {\n // On success the temp is now a redundant link to the target; on EEXIST it is\n // the orphaned write. Either way remove it before returning/throwing.\n await rm(tmpPath, { force: true }).catch(() => undefined);\n }\n}\n\n/** fsync a directory so a freshly linked entry is durable. Never called on win32. */\nasync function fsyncDir(dir: string): Promise<void> {\n const handle = await open(dir, 'r');\n try {\n await handle.sync();\n } finally {\n await handle.close();\n }\n}\n"],"mappings":";;;AAAA,SAAS,OAAO,MAAM,OAAO,MAAM,QAAQ,IAAI,iBAAiB;AAChE,SAAS,mBAAmB;AAC5B,SAAS,UAAU,SAAS,YAAY;AAGxC,IAAM,YAAY,QAAQ,aAAa;AAqBvC,eAAsB,gBACpB,YACA,MACA,OAA2B,CAAC,GACb;AACf,QAAM,MAAM,QAAQ,UAAU;AAC9B,QAAM,WAAW,KAAK,QAAQ;AAC9B,QAAM,UAAU,KAAK,WAAW;AAEhC,QAAM,MAAM,KAAK,EAAE,WAAW,MAAM,GAAI,YAAY,CAAC,IAAI,EAAE,MAAM,QAAQ,EAAG,CAAC;AAE7E,QAAM,UAAU,KAAK,KAAK,IAAI,SAAS,UAAU,CAAC,IAAI,YAAY,CAAC,EAAE,SAAS,KAAK,CAAC,MAAM;AAC1F,MAAI;AACF,UAAM,UAAU,SAAS,MAAM,YAAY,SAAY,EAAE,MAAM,SAAS,CAAC;AACzE,QAAI,CAAC,UAAW,OAAM,MAAM,SAAS,QAAQ;AAC7C,UAAM,OAAO,SAAS,UAAU;AAAA,EAClC,SAAS,KAAK;AACZ,UAAM,GAAG,SAAS,EAAE,OAAO,KAAK,CAAC,EAAE,MAAM,MAAM,MAAS;AACxD,UAAM;AAAA,EACR;AACF;AAkBA,eAAsB,yBACpB,YACA,MACA,OAA2B,CAAC,GACb;AACf,QAAM,MAAM,QAAQ,UAAU;AAC9B,QAAM,WAAW,KAAK,QAAQ;AAC9B,QAAM,UAAU,KAAK,WAAW;AAEhC,QAAM,MAAM,KAAK,EAAE,WAAW,MAAM,GAAI,YAAY,CAAC,IAAI,EAAE,MAAM,QAAQ,EAAG,CAAC;AAE7E,MAAI,WAAW;AACb,UAAM,SAAS,MAAM,KAAK,YAAY,IAAI;AAC1C,QAAI;AACF,YAAM,OAAO,UAAU,IAAI;AAC3B,YAAM,OAAO,KAAK;AAAA,IACpB,UAAE;AACA,YAAM,OAAO,MAAM;AAAA,IACrB;AACA;AAAA,EACF;AAEA,QAAM,UAAU,KAAK,KAAK,IAAI,SAAS,UAAU,CAAC,IAAI,YAAY,CAAC,EAAE,SAAS,KAAK,CAAC,MAAM;AAC1F,MAAI;AACF,UAAM,SAAS,MAAM,KAAK,SAAS,MAAM,QAAQ;AACjD,QAAI;AACF,YAAM,OAAO,UAAU,IAAI;AAC3B,YAAM,OAAO,MAAM,QAAQ;AAC3B,YAAM,OAAO,KAAK;AAAA,IACpB,UAAE;AACA,YAAM,OAAO,MAAM;AAAA,IACrB;AACA,UAAM,KAAK,SAAS,UAAU;AAC9B,UAAM,SAAS,GAAG;AAAA,EACpB,UAAE;AAGA,UAAM,GAAG,SAAS,EAAE,OAAO,KAAK,CAAC,EAAE,MAAM,MAAM,MAAS;AAAA,EAC1D;AACF;AAGA,eAAe,SAAS,KAA4B;AAClD,QAAM,SAAS,MAAM,KAAK,KAAK,GAAG;AAClC,MAAI;AACF,UAAM,OAAO,KAAK;AAAA,EACpB,UAAE;AACA,UAAM,OAAO,MAAM;AAAA,EACrB;AACF;","names":[]}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
|
-
secp256k1,
|
|
4
3
|
sha256
|
|
5
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-RY4XKNV3.js";
|
|
5
|
+
import {
|
|
6
|
+
secp256k1
|
|
7
|
+
} from "./chunk-QVX5MWJZ.js";
|
|
6
8
|
import {
|
|
7
9
|
BaseError,
|
|
8
10
|
BytesSizeMismatchError,
|
|
@@ -12,6 +14,7 @@ import {
|
|
|
12
14
|
InvalidLegacyVError,
|
|
13
15
|
InvalidSerializableTransactionError,
|
|
14
16
|
InvalidStorageKeySizeError,
|
|
17
|
+
LruMap,
|
|
15
18
|
TipAboveFeeCapError,
|
|
16
19
|
bytesRegex,
|
|
17
20
|
bytesToHex,
|
|
@@ -20,6 +23,7 @@ import {
|
|
|
20
23
|
concatHex,
|
|
21
24
|
createCursor,
|
|
22
25
|
encodeAbiParameters,
|
|
26
|
+
formatBlockParameter,
|
|
23
27
|
from2 as from,
|
|
24
28
|
fromBytes,
|
|
25
29
|
hexToBigInt,
|
|
@@ -29,7 +33,6 @@ import {
|
|
|
29
33
|
isAddress,
|
|
30
34
|
isHex,
|
|
31
35
|
keccak256,
|
|
32
|
-
keccak_256,
|
|
33
36
|
maxUint256,
|
|
34
37
|
numberToHex,
|
|
35
38
|
size,
|
|
@@ -39,7 +42,98 @@ import {
|
|
|
39
42
|
toBytes,
|
|
40
43
|
toHex,
|
|
41
44
|
trim
|
|
42
|
-
} from "./chunk-
|
|
45
|
+
} from "./chunk-YALGASEU.js";
|
|
46
|
+
import {
|
|
47
|
+
keccak_256
|
|
48
|
+
} from "./chunk-HIVZG55D.js";
|
|
49
|
+
|
|
50
|
+
// node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/_esm/actions/public/getTransactionCount.js
|
|
51
|
+
async function getTransactionCount(client, { address, blockHash, blockNumber, blockTag = "latest", requireCanonical }) {
|
|
52
|
+
const block = formatBlockParameter({
|
|
53
|
+
blockHash,
|
|
54
|
+
blockNumber,
|
|
55
|
+
blockTag,
|
|
56
|
+
requireCanonical
|
|
57
|
+
});
|
|
58
|
+
const count = await client.request({
|
|
59
|
+
method: "eth_getTransactionCount",
|
|
60
|
+
params: [address, block]
|
|
61
|
+
}, {
|
|
62
|
+
dedupe: typeof blockNumber === "bigint" || blockHash !== void 0
|
|
63
|
+
});
|
|
64
|
+
return hexToNumber(count);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/_esm/utils/nonceManager.js
|
|
68
|
+
function createNonceManager(parameters) {
|
|
69
|
+
const { source } = parameters;
|
|
70
|
+
const deltaMap = /* @__PURE__ */ new Map();
|
|
71
|
+
const nonceMap = new LruMap(8192);
|
|
72
|
+
const promiseMap = /* @__PURE__ */ new Map();
|
|
73
|
+
const getKey = ({ address, chainId }) => `${address}.${chainId}`;
|
|
74
|
+
const resetCache = (key) => {
|
|
75
|
+
deltaMap.delete(key);
|
|
76
|
+
promiseMap.delete(key);
|
|
77
|
+
};
|
|
78
|
+
return {
|
|
79
|
+
async consume({ address, chainId, client }) {
|
|
80
|
+
const key = getKey({ address, chainId });
|
|
81
|
+
const promise = this.get({ address, chainId, client });
|
|
82
|
+
this.increment({ address, chainId });
|
|
83
|
+
const nonce = await promise;
|
|
84
|
+
await source.set({ address, chainId }, nonce);
|
|
85
|
+
nonceMap.set(key, nonce);
|
|
86
|
+
return nonce;
|
|
87
|
+
},
|
|
88
|
+
async increment({ address, chainId }) {
|
|
89
|
+
const key = getKey({ address, chainId });
|
|
90
|
+
const delta = deltaMap.get(key) ?? 0;
|
|
91
|
+
deltaMap.set(key, delta + 1);
|
|
92
|
+
},
|
|
93
|
+
async get({ address, chainId, client }) {
|
|
94
|
+
const key = getKey({ address, chainId });
|
|
95
|
+
let promise = promiseMap.get(key);
|
|
96
|
+
if (!promise) {
|
|
97
|
+
promise = (async () => {
|
|
98
|
+
try {
|
|
99
|
+
const nonce = await source.get({ address, chainId, client });
|
|
100
|
+
const previousNonce = nonceMap.get(key) ?? 0;
|
|
101
|
+
if (previousNonce > 0 && nonce <= previousNonce)
|
|
102
|
+
return previousNonce + 1;
|
|
103
|
+
nonceMap.delete(key);
|
|
104
|
+
return nonce;
|
|
105
|
+
} finally {
|
|
106
|
+
resetCache(key);
|
|
107
|
+
}
|
|
108
|
+
})();
|
|
109
|
+
promiseMap.set(key, promise);
|
|
110
|
+
}
|
|
111
|
+
const delta = deltaMap.get(key) ?? 0;
|
|
112
|
+
return delta + await promise;
|
|
113
|
+
},
|
|
114
|
+
reset({ address, chainId }) {
|
|
115
|
+
const key = getKey({ address, chainId });
|
|
116
|
+
nonceMap.delete(key);
|
|
117
|
+
resetCache(key);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function jsonRpc() {
|
|
122
|
+
return {
|
|
123
|
+
async get(parameters) {
|
|
124
|
+
const { address, client } = parameters;
|
|
125
|
+
return getTransactionCount(client, {
|
|
126
|
+
address,
|
|
127
|
+
blockTag: "pending"
|
|
128
|
+
});
|
|
129
|
+
},
|
|
130
|
+
set() {
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
var nonceManager = /* @__PURE__ */ createNonceManager({
|
|
135
|
+
source: jsonRpc()
|
|
136
|
+
});
|
|
43
137
|
|
|
44
138
|
// node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/_esm/utils/signature/serializeSignature.js
|
|
45
139
|
function serializeSignature({ r, s, to = "hex", v, yParity }) {
|
|
@@ -65,6 +159,12 @@ function toRlp(bytes, to = "hex") {
|
|
|
65
159
|
return bytesToHex(cursor.bytes);
|
|
66
160
|
return cursor.bytes;
|
|
67
161
|
}
|
|
162
|
+
function bytesToRlp(bytes, to = "bytes") {
|
|
163
|
+
return toRlp(bytes, to);
|
|
164
|
+
}
|
|
165
|
+
function hexToRlp(hex, to = "hex") {
|
|
166
|
+
return toRlp(hex, to);
|
|
167
|
+
}
|
|
68
168
|
function getEncodable(bytes) {
|
|
69
169
|
if (Array.isArray(bytes))
|
|
70
170
|
return getEncodableList(bytes.map((x) => getEncodable(x)));
|
|
@@ -192,13 +292,10 @@ function blobsToProofs(parameters) {
|
|
|
192
292
|
return to === "bytes" ? proofs : proofs.map((x) => bytesToHex(x));
|
|
193
293
|
}
|
|
194
294
|
|
|
195
|
-
// node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/sha256.js
|
|
196
|
-
var sha2562 = sha256;
|
|
197
|
-
|
|
198
295
|
// node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/_esm/utils/hash/sha256.js
|
|
199
|
-
function
|
|
296
|
+
function sha2562(value, to_) {
|
|
200
297
|
const to = to_ || "hex";
|
|
201
|
-
const bytes =
|
|
298
|
+
const bytes = sha256(isHex(value, { strict: false }) ? toBytes(value) : value);
|
|
202
299
|
if (to === "bytes")
|
|
203
300
|
return bytes;
|
|
204
301
|
return toHex(bytes);
|
|
@@ -208,7 +305,7 @@ function sha2563(value, to_) {
|
|
|
208
305
|
function commitmentToVersionedHash(parameters) {
|
|
209
306
|
const { commitment, version = 1 } = parameters;
|
|
210
307
|
const to = parameters.to ?? (typeof commitment === "string" ? "hex" : "bytes");
|
|
211
|
-
const versionedHash =
|
|
308
|
+
const versionedHash = sha2562(commitment, "bytes");
|
|
212
309
|
versionedHash.set([version], 0);
|
|
213
310
|
return to === "bytes" ? versionedHash : bytesToHex(versionedHash);
|
|
214
311
|
}
|
|
@@ -786,6 +883,31 @@ function encodeField({ types, name, type, value }) {
|
|
|
786
883
|
}
|
|
787
884
|
|
|
788
885
|
// node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/_esm/utils/typedData.js
|
|
886
|
+
function serializeTypedData(parameters) {
|
|
887
|
+
const { domain: domain_, message: message_, primaryType, types } = parameters;
|
|
888
|
+
const normalizeData = (struct, data_) => {
|
|
889
|
+
const data = { ...data_ };
|
|
890
|
+
for (const param of struct) {
|
|
891
|
+
const { name, type } = param;
|
|
892
|
+
if (type === "address")
|
|
893
|
+
data[name] = data[name].toLowerCase();
|
|
894
|
+
}
|
|
895
|
+
return data;
|
|
896
|
+
};
|
|
897
|
+
const domain = (() => {
|
|
898
|
+
if (!types.EIP712Domain)
|
|
899
|
+
return {};
|
|
900
|
+
if (!domain_)
|
|
901
|
+
return {};
|
|
902
|
+
return normalizeData(types.EIP712Domain, domain_);
|
|
903
|
+
})();
|
|
904
|
+
const message = (() => {
|
|
905
|
+
if (primaryType === "EIP712Domain")
|
|
906
|
+
return void 0;
|
|
907
|
+
return normalizeData(types[primaryType], message_);
|
|
908
|
+
})();
|
|
909
|
+
return stringify({ domain, message, primaryType, types });
|
|
910
|
+
}
|
|
789
911
|
function validateTypedData(parameters) {
|
|
790
912
|
const { domain, message, primaryType, types } = parameters;
|
|
791
913
|
const validateData = (struct, data) => {
|
|
@@ -845,6 +967,14 @@ function getTypesForEIP712Domain({ domain }) {
|
|
|
845
967
|
domain?.salt && { name: "salt", type: "bytes32" }
|
|
846
968
|
].filter(Boolean);
|
|
847
969
|
}
|
|
970
|
+
function domainSeparator({ domain }) {
|
|
971
|
+
return hashDomain({
|
|
972
|
+
domain,
|
|
973
|
+
types: {
|
|
974
|
+
EIP712Domain: getTypesForEIP712Domain({ domain })
|
|
975
|
+
}
|
|
976
|
+
});
|
|
977
|
+
}
|
|
848
978
|
function validateReference(type) {
|
|
849
979
|
if (type === "address" || type === "bool" || type === "string" || type.startsWith("bytes") || type.startsWith("uint") || type.startsWith("int"))
|
|
850
980
|
throw new InvalidStructTypeError({ type });
|
|
@@ -883,18 +1013,43 @@ function hashAuthorization(parameters) {
|
|
|
883
1013
|
}
|
|
884
1014
|
|
|
885
1015
|
export {
|
|
1016
|
+
getTransactionCount,
|
|
1017
|
+
createNonceManager,
|
|
1018
|
+
nonceManager,
|
|
886
1019
|
serializeSignature,
|
|
887
1020
|
publicKeyToAddress,
|
|
888
1021
|
toRlp,
|
|
1022
|
+
bytesToRlp,
|
|
1023
|
+
hexToRlp,
|
|
889
1024
|
hashAuthorization,
|
|
1025
|
+
presignMessagePrefix,
|
|
1026
|
+
toPrefixedMessage,
|
|
890
1027
|
hashMessage,
|
|
891
1028
|
blobsToCommitments,
|
|
892
1029
|
blobsToProofs,
|
|
1030
|
+
sha2562 as sha256,
|
|
1031
|
+
commitmentToVersionedHash,
|
|
893
1032
|
commitmentsToVersionedHashes,
|
|
1033
|
+
toBlobs,
|
|
894
1034
|
toBlobSidecars,
|
|
1035
|
+
assertTransactionEIP7702,
|
|
1036
|
+
assertTransactionEIP4844,
|
|
1037
|
+
assertTransactionEIP1559,
|
|
1038
|
+
assertTransactionEIP2930,
|
|
1039
|
+
assertTransactionLegacy,
|
|
895
1040
|
getTransactionType,
|
|
1041
|
+
serializeAccessList,
|
|
896
1042
|
serializeTransaction,
|
|
1043
|
+
InvalidDomainError,
|
|
1044
|
+
InvalidPrimaryTypeError,
|
|
1045
|
+
InvalidStructTypeError,
|
|
1046
|
+
serializeTypedData,
|
|
1047
|
+
validateTypedData,
|
|
1048
|
+
getTypesForEIP712Domain,
|
|
1049
|
+
domainSeparator,
|
|
897
1050
|
hashTypedData,
|
|
1051
|
+
hashDomain,
|
|
1052
|
+
hashStruct,
|
|
898
1053
|
keccak2562 as keccak256
|
|
899
1054
|
};
|
|
900
|
-
//# sourceMappingURL=chunk-
|
|
1055
|
+
//# sourceMappingURL=chunk-NCE5NSN6.js.map
|