tenjin-cli 0.1.0-alpha.0 → 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.
- package/NOTICE.md +33 -0
- package/README.md +198 -18
- package/dist/{_esm-ZH2J4QEH.js → _esm-C5CRWCYU.js} +2 -2
- package/dist/_esm-FEASBWRP.js +881 -0
- package/dist/buy-U35DQ6XM.js +1598 -0
- package/dist/buy-U35DQ6XM.js.map +1 -0
- package/dist/candidate-RLYCQMF5.js +127 -0
- package/dist/candidate-RLYCQMF5.js.map +1 -0
- package/dist/{ccip-FXWZDDF5.js → ccip-NQXCEK2U.js} +6 -5
- package/dist/ccip-XR5NE5QK.js +19 -0
- package/dist/chunk-27ONARHV.js +171 -0
- package/dist/chunk-27ONARHV.js.map +1 -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-5CLSD5YN.js +209 -0
- package/dist/chunk-5CLSD5YN.js.map +1 -0
- package/dist/chunk-7KUW4MJD.js +59 -0
- package/dist/chunk-7KUW4MJD.js.map +1 -0
- package/dist/{doctor-MVLZRVPU.js → chunk-7PHSZKQS.js} +88 -93
- package/dist/chunk-7PHSZKQS.js.map +1 -0
- package/dist/chunk-CYOF7ROH.js +70 -0
- package/dist/chunk-CYOF7ROH.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-LTTRND4A.js → chunk-IYLHQMT5.js} +85 -9
- package/dist/chunk-IYLHQMT5.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-N62ROTMC.js +79 -0
- package/dist/chunk-N62ROTMC.js.map +1 -0
- package/dist/{chunk-SXQQ2ZSR.js → chunk-NCE5NSN6.js} +186 -18
- package/dist/chunk-NCE5NSN6.js.map +1 -0
- package/dist/{chunk-FIYZLITH.js → chunk-OYMYCW7J.js} +23 -4
- package/dist/{chunk-FIYZLITH.js.map → chunk-OYMYCW7J.js.map} +1 -1
- package/dist/chunk-QNP7H47L.js +152 -0
- package/dist/chunk-QNP7H47L.js.map +1 -0
- package/dist/{chunk-TX5T3LKJ.js → chunk-QVX5MWJZ.js} +21 -17
- package/dist/{chunk-TX5T3LKJ.js.map → chunk-QVX5MWJZ.js.map} +1 -1
- package/dist/{chunk-CPUZRZ2A.js → chunk-RBJPAZFI.js} +25 -170
- 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/{config-XVXZ3V2Q.js → chunk-TFGSOPWR.js} +117 -62
- package/dist/chunk-TFGSOPWR.js.map +1 -0
- package/dist/chunk-TLCMMYLY.js +126 -0
- package/dist/chunk-TLCMMYLY.js.map +1 -0
- package/dist/{chunk-PAAL45FJ.js → chunk-UGX7YPX2.js} +3446 -448
- 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/chunk-UPIEAMGH.js +160 -0
- package/dist/chunk-UPIEAMGH.js.map +1 -0
- package/dist/chunk-XJIW7USF.js +217 -0
- package/dist/chunk-XJIW7USF.js.map +1 -0
- package/dist/{chunk-F5DZJLU3.js → chunk-YALGASEU.js} +2065 -1258
- package/dist/chunk-YALGASEU.js.map +1 -0
- package/dist/chunk-YBMMV4Y4.js +51 -0
- package/dist/chunk-YBMMV4Y4.js.map +1 -0
- package/dist/chunk-YIYQ2ZNT.js +286 -0
- package/dist/chunk-YIYQ2ZNT.js.map +1 -0
- package/dist/{chunk-376LHMK2.js → chunk-YN5SHIXQ.js} +36 -10
- 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-Z6MFJV5Z.js +1330 -0
- 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-WOHCAMDQ.js → chunk-ZMHYXMO6.js} +1887 -1029
- package/dist/chunk-ZMHYXMO6.js.map +1 -0
- package/dist/{chunk-3IMLRUZE.js → chunk-ZXTAQYNA.js} +6 -2
- package/dist/{cli-LMHGCZ5S.js → cli-4NNBEQYH.js} +175 -179
- package/dist/cli-4NNBEQYH.js.map +1 -0
- package/dist/config-2VSXWWHK.js +21 -0
- package/dist/doctor-JJPNIBYH.js +20 -0
- package/dist/doctor-JJPNIBYH.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-JGYJWFDP.js +96 -0
- package/dist/inspect-JGYJWFDP.js.map +1 -0
- package/dist/install-ZQRMSRGW.js +378 -0
- package/dist/install-ZQRMSRGW.js.map +1 -0
- package/dist/lookup-WYVTOMVY.js +113 -0
- package/dist/lookup-WYVTOMVY.js.map +1 -0
- package/dist/{mine.wasm-GQECMSGN.js → mine.wasm-6PIT3DK6.js} +2 -2
- package/dist/outcome-HKKT6QIA.js +66 -0
- package/dist/outcome-HKKT6QIA.js.map +1 -0
- package/dist/publish-D76B3MBK.js +1480 -0
- package/dist/publish-D76B3MBK.js.map +1 -0
- package/dist/{secp256k1-35YNNB6F.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-6QKS6UHW.js +179 -0
- package/dist/wallet-6QKS6UHW.js.map +1 -0
- package/dist/wallet-PA54CRBL.js +30 -0
- package/dist/wallet-PA54CRBL.js.map +1 -0
- package/package.json +20 -15
- package/skills/tenjin/SKILL.md +199 -0
- package/skills/tenjin-publish/SKILL.md +96 -0
- package/skills/tenjin-search/SKILL.md +122 -0
- package/dist/chunk-376LHMK2.js.map +0 -1
- package/dist/chunk-CPUZRZ2A.js.map +0 -1
- package/dist/chunk-F5DZJLU3.js.map +0 -1
- package/dist/chunk-LTTRND4A.js.map +0 -1
- package/dist/chunk-PAAL45FJ.js.map +0 -1
- package/dist/chunk-QHIEYBLV.js +0 -320
- package/dist/chunk-QHIEYBLV.js.map +0 -1
- package/dist/chunk-SXQQ2ZSR.js.map +0 -1
- package/dist/chunk-WOHCAMDQ.js.map +0 -1
- package/dist/chunk-ZPZFPVDN.js.map +0 -1
- package/dist/cli-LMHGCZ5S.js.map +0 -1
- package/dist/config-XVXZ3V2Q.js.map +0 -1
- package/dist/doctor-MVLZRVPU.js.map +0 -1
- package/dist/usdc-OQUOFF6R.js +0 -18
- package/dist/wallet-NRKWLKHX.js +0 -153
- package/dist/wallet-NRKWLKHX.js.map +0 -1
- package/dist/wallet-QUWK2PA4.js +0 -22
- /package/dist/{_esm-ZH2J4QEH.js.map → _esm-C5CRWCYU.js.map} +0 -0
- /package/dist/{ccip-FXWZDDF5.js.map → _esm-FEASBWRP.js.map} +0 -0
- /package/dist/{chunk-3IMLRUZE.js.map → ccip-NQXCEK2U.js.map} +0 -0
- /package/dist/{secp256k1-35YNNB6F.js.map → ccip-XR5NE5QK.js.map} +0 -0
- /package/dist/{usdc-OQUOFF6R.js.map → chunk-ZXTAQYNA.js.map} +0 -0
- /package/dist/{wallet-QUWK2PA4.js.map → config-2VSXWWHK.js.map} +0 -0
- /package/dist/{mine.wasm-GQECMSGN.js.map → mine.wasm-6PIT3DK6.js.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/src/cryptoNode.ts","../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/src/utils.ts","../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/src/_u64.ts"],"sourcesContent":["/**\n * Internal webcrypto alias.\n * We prefer WebCrypto aka globalThis.crypto, which exists in node.js 16+.\n * Falls back to Node.js built-in crypto for Node.js <=v14.\n * See utils.ts for details.\n * @module\n */\n// @ts-ignore\nimport * as nc from 'node:crypto';\nexport const crypto: any =\n nc && typeof nc === 'object' && 'webcrypto' in nc\n ? (nc.webcrypto as any)\n : nc && typeof nc === 'object' && 'randomBytes' in nc\n ? nc\n : undefined;\n","/**\n * Utilities for hex, bytes, CSPRNG.\n * @module\n */\n/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */\n\n// We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.\n// node.js versions earlier than v19 don't declare it in global scope.\n// For node.js, package.json#exports field mapping rewrites import\n// from `crypto` to `cryptoNode`, which imports native module.\n// Makes the utils un-importable in browsers without a bundler.\n// Once node.js 18 is deprecated (2025-04-30), we can just drop the import.\nimport { crypto } from '@noble/hashes/crypto';\n\n/** Checks if something is Uint8Array. Be careful: nodejs Buffer will return true. */\nexport function isBytes(a: unknown): a is Uint8Array {\n return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');\n}\n\n/** Asserts something is positive integer. */\nexport function anumber(n: number): void {\n if (!Number.isSafeInteger(n) || n < 0) throw new Error('positive integer expected, got ' + n);\n}\n\n/** Asserts something is Uint8Array. */\nexport function abytes(b: Uint8Array | undefined, ...lengths: number[]): void {\n if (!isBytes(b)) throw new Error('Uint8Array expected');\n if (lengths.length > 0 && !lengths.includes(b.length))\n throw new Error('Uint8Array expected of length ' + lengths + ', got length=' + b.length);\n}\n\n/** Asserts something is hash */\nexport function ahash(h: IHash): void {\n if (typeof h !== 'function' || typeof h.create !== 'function')\n throw new Error('Hash should be wrapped by utils.createHasher');\n anumber(h.outputLen);\n anumber(h.blockLen);\n}\n\n/** Asserts a hash instance has not been destroyed / finished */\nexport function aexists(instance: any, checkFinished = true): void {\n if (instance.destroyed) throw new Error('Hash instance has been destroyed');\n if (checkFinished && instance.finished) throw new Error('Hash#digest() has already been called');\n}\n\n/** Asserts output is properly-sized byte array */\nexport function aoutput(out: any, instance: any): void {\n abytes(out);\n const min = instance.outputLen;\n if (out.length < min) {\n throw new Error('digestInto() expects output buffer of length at least ' + min);\n }\n}\n\n/** Generic type encompassing 8/16/32-byte arrays - but not 64-byte. */\n// prettier-ignore\nexport type TypedArray = Int8Array | Uint8ClampedArray | Uint8Array |\n Uint16Array | Int16Array | Uint32Array | Int32Array;\n\n/** Cast u8 / u16 / u32 to u8. */\nexport function u8(arr: TypedArray): Uint8Array {\n return new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);\n}\n\n/** Cast u8 / u16 / u32 to u32. */\nexport function u32(arr: TypedArray): Uint32Array {\n return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));\n}\n\n/** Zeroize a byte array. Warning: JS provides no guarantees. */\nexport function clean(...arrays: TypedArray[]): void {\n for (let i = 0; i < arrays.length; i++) {\n arrays[i].fill(0);\n }\n}\n\n/** Create DataView of an array for easy byte-level manipulation. */\nexport function createView(arr: TypedArray): DataView {\n return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);\n}\n\n/** The rotate right (circular right shift) operation for uint32 */\nexport function rotr(word: number, shift: number): number {\n return (word << (32 - shift)) | (word >>> shift);\n}\n\n/** The rotate left (circular left shift) operation for uint32 */\nexport function rotl(word: number, shift: number): number {\n return (word << shift) | ((word >>> (32 - shift)) >>> 0);\n}\n\n/** Is current platform little-endian? Most are. Big-Endian platform: IBM */\nexport const isLE: boolean = /* @__PURE__ */ (() =>\n new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44)();\n\n/** The byte swap operation for uint32 */\nexport function byteSwap(word: number): number {\n return (\n ((word << 24) & 0xff000000) |\n ((word << 8) & 0xff0000) |\n ((word >>> 8) & 0xff00) |\n ((word >>> 24) & 0xff)\n );\n}\n/** Conditionally byte swap if on a big-endian platform */\nexport const swap8IfBE: (n: number) => number = isLE\n ? (n: number) => n\n : (n: number) => byteSwap(n);\n\n/** @deprecated */\nexport const byteSwapIfBE: typeof swap8IfBE = swap8IfBE;\n/** In place byte swap for Uint32Array */\nexport function byteSwap32(arr: Uint32Array): Uint32Array {\n for (let i = 0; i < arr.length; i++) {\n arr[i] = byteSwap(arr[i]);\n }\n return arr;\n}\n\nexport const swap32IfBE: (u: Uint32Array) => Uint32Array = isLE\n ? (u: Uint32Array) => u\n : byteSwap32;\n\n// Built-in hex conversion https://caniuse.com/mdn-javascript_builtins_uint8array_fromhex\nconst hasHexBuiltin: boolean = /* @__PURE__ */ (() =>\n // @ts-ignore\n typeof Uint8Array.from([]).toHex === 'function' && typeof Uint8Array.fromHex === 'function')();\n\n// Array where index 0xf0 (240) is mapped to string 'f0'\nconst hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) =>\n i.toString(16).padStart(2, '0')\n);\n\n/**\n * Convert byte array to hex string. Uses built-in function, when available.\n * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'\n */\nexport function bytesToHex(bytes: Uint8Array): string {\n abytes(bytes);\n // @ts-ignore\n if (hasHexBuiltin) return bytes.toHex();\n // pre-caching improves the speed 6x\n let hex = '';\n for (let i = 0; i < bytes.length; i++) {\n hex += hexes[bytes[i]];\n }\n return hex;\n}\n\n// We use optimized technique to convert hex string to byte array\nconst asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 } as const;\nfunction asciiToBase16(ch: number): number | undefined {\n if (ch >= asciis._0 && ch <= asciis._9) return ch - asciis._0; // '2' => 50-48\n if (ch >= asciis.A && ch <= asciis.F) return ch - (asciis.A - 10); // 'B' => 66-(65-10)\n if (ch >= asciis.a && ch <= asciis.f) return ch - (asciis.a - 10); // 'b' => 98-(97-10)\n return;\n}\n\n/**\n * Convert hex string to byte array. Uses built-in function, when available.\n * @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])\n */\nexport function hexToBytes(hex: string): Uint8Array {\n if (typeof hex !== 'string') throw new Error('hex string expected, got ' + typeof hex);\n // @ts-ignore\n if (hasHexBuiltin) return Uint8Array.fromHex(hex);\n const hl = hex.length;\n const al = hl / 2;\n if (hl % 2) throw new Error('hex string expected, got unpadded hex of length ' + hl);\n const array = new Uint8Array(al);\n for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {\n const n1 = asciiToBase16(hex.charCodeAt(hi));\n const n2 = asciiToBase16(hex.charCodeAt(hi + 1));\n if (n1 === undefined || n2 === undefined) {\n const char = hex[hi] + hex[hi + 1];\n throw new Error('hex string expected, got non-hex character \"' + char + '\" at index ' + hi);\n }\n array[ai] = n1 * 16 + n2; // multiply first octet, e.g. 'a3' => 10*16+3 => 160 + 3 => 163\n }\n return array;\n}\n\n/**\n * There is no setImmediate in browser and setTimeout is slow.\n * Call of async fn will return Promise, which will be fullfiled only on\n * next scheduler queue processing step and this is exactly what we need.\n */\nexport const nextTick = async (): Promise<void> => {};\n\n/** Returns control to thread each 'tick' ms to avoid blocking. */\nexport async function asyncLoop(\n iters: number,\n tick: number,\n cb: (i: number) => void\n): Promise<void> {\n let ts = Date.now();\n for (let i = 0; i < iters; i++) {\n cb(i);\n // Date.now() is not monotonic, so in case if clock goes backwards we return return control too\n const diff = Date.now() - ts;\n if (diff >= 0 && diff < tick) continue;\n await nextTick();\n ts += diff;\n }\n}\n\n// Global symbols, but ts doesn't see them: https://github.com/microsoft/TypeScript/issues/31535\ndeclare const TextEncoder: any;\ndeclare const TextDecoder: any;\n\n/**\n * Converts string to bytes using UTF8 encoding.\n * @example utf8ToBytes('abc') // Uint8Array.from([97, 98, 99])\n */\nexport function utf8ToBytes(str: string): Uint8Array {\n if (typeof str !== 'string') throw new Error('string expected');\n return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809\n}\n\n/**\n * Converts bytes to string using UTF8 encoding.\n * @example bytesToUtf8(Uint8Array.from([97, 98, 99])) // 'abc'\n */\nexport function bytesToUtf8(bytes: Uint8Array): string {\n return new TextDecoder().decode(bytes);\n}\n\n/** Accepted input of hash functions. Strings are converted to byte arrays. */\nexport type Input = string | Uint8Array;\n/**\n * Normalizes (non-hex) string or Uint8Array to Uint8Array.\n * Warning: when Uint8Array is passed, it would NOT get copied.\n * Keep in mind for future mutable operations.\n */\nexport function toBytes(data: Input): Uint8Array {\n if (typeof data === 'string') data = utf8ToBytes(data);\n abytes(data);\n return data;\n}\n\n/** KDFs can accept string or Uint8Array for user convenience. */\nexport type KDFInput = string | Uint8Array;\n/**\n * Helper for KDFs: consumes uint8array or string.\n * When string is passed, does utf8 decoding, using TextDecoder.\n */\nexport function kdfInputToBytes(data: KDFInput): Uint8Array {\n if (typeof data === 'string') data = utf8ToBytes(data);\n abytes(data);\n return data;\n}\n\n/** Copies several Uint8Arrays into one. */\nexport function concatBytes(...arrays: Uint8Array[]): Uint8Array {\n let sum = 0;\n for (let i = 0; i < arrays.length; i++) {\n const a = arrays[i];\n abytes(a);\n sum += a.length;\n }\n const res = new Uint8Array(sum);\n for (let i = 0, pad = 0; i < arrays.length; i++) {\n const a = arrays[i];\n res.set(a, pad);\n pad += a.length;\n }\n return res;\n}\n\ntype EmptyObj = {};\nexport function checkOpts<T1 extends EmptyObj, T2 extends EmptyObj>(\n defaults: T1,\n opts?: T2\n): T1 & T2 {\n if (opts !== undefined && {}.toString.call(opts) !== '[object Object]')\n throw new Error('options should be object or undefined');\n const merged = Object.assign(defaults, opts);\n return merged as T1 & T2;\n}\n\n/** Hash interface. */\nexport type IHash = {\n (data: Uint8Array): Uint8Array;\n blockLen: number;\n outputLen: number;\n create: any;\n};\n\n/** For runtime check if class implements interface */\nexport abstract class Hash<T extends Hash<T>> {\n abstract blockLen: number; // Bytes per block\n abstract outputLen: number; // Bytes in output\n abstract update(buf: Input): this;\n // Writes digest into buf\n abstract digestInto(buf: Uint8Array): void;\n abstract digest(): Uint8Array;\n /**\n * Resets internal state. Makes Hash instance unusable.\n * Reset is impossible for keyed hashes if key is consumed into state. If digest is not consumed\n * by user, they will need to manually call `destroy()` when zeroing is necessary.\n */\n abstract destroy(): void;\n /**\n * Clones hash instance. Unsafe: doesn't check whether `to` is valid. Can be used as `clone()`\n * when no options are passed.\n * Reasons to use `_cloneInto` instead of clone: 1) performance 2) reuse instance => all internal\n * buffers are overwritten => causes buffer overwrite which is used for digest in some cases.\n * There are no guarantees for clean-up because it's impossible in JS.\n */\n abstract _cloneInto(to?: T): T;\n // Safe version that clones internal state\n abstract clone(): T;\n}\n\n/**\n * XOF: streaming API to read digest in chunks.\n * Same as 'squeeze' in keccak/k12 and 'seek' in blake3, but more generic name.\n * When hash used in XOF mode it is up to user to call '.destroy' afterwards, since we cannot\n * destroy state, next call can require more bytes.\n */\nexport type HashXOF<T extends Hash<T>> = Hash<T> & {\n xof(bytes: number): Uint8Array; // Read 'bytes' bytes from digest stream\n xofInto(buf: Uint8Array): Uint8Array; // read buf.length bytes from digest stream into buf\n};\n\n/** Hash function */\nexport type CHash = ReturnType<typeof createHasher>;\n/** Hash function with output */\nexport type CHashO = ReturnType<typeof createOptHasher>;\n/** XOF with output */\nexport type CHashXO = ReturnType<typeof createXOFer>;\n\n/** Wraps hash function, creating an interface on top of it */\nexport function createHasher<T extends Hash<T>>(\n hashCons: () => Hash<T>\n): {\n (msg: Input): Uint8Array;\n outputLen: number;\n blockLen: number;\n create(): Hash<T>;\n} {\n const hashC = (msg: Input): Uint8Array => hashCons().update(toBytes(msg)).digest();\n const tmp = hashCons();\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = () => hashCons();\n return hashC;\n}\n\nexport function createOptHasher<H extends Hash<H>, T extends Object>(\n hashCons: (opts?: T) => Hash<H>\n): {\n (msg: Input, opts?: T): Uint8Array;\n outputLen: number;\n blockLen: number;\n create(opts?: T): Hash<H>;\n} {\n const hashC = (msg: Input, opts?: T): Uint8Array => hashCons(opts).update(toBytes(msg)).digest();\n const tmp = hashCons({} as T);\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = (opts?: T) => hashCons(opts);\n return hashC;\n}\n\nexport function createXOFer<H extends HashXOF<H>, T extends Object>(\n hashCons: (opts?: T) => HashXOF<H>\n): {\n (msg: Input, opts?: T): Uint8Array;\n outputLen: number;\n blockLen: number;\n create(opts?: T): HashXOF<H>;\n} {\n const hashC = (msg: Input, opts?: T): Uint8Array => hashCons(opts).update(toBytes(msg)).digest();\n const tmp = hashCons({} as T);\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = (opts?: T) => hashCons(opts);\n return hashC;\n}\nexport const wrapConstructor: typeof createHasher = createHasher;\nexport const wrapConstructorWithOpts: typeof createOptHasher = createOptHasher;\nexport const wrapXOFConstructorWithOpts: typeof createXOFer = createXOFer;\n\n/** Cryptographically secure PRNG. Uses internal OS-level `crypto.getRandomValues`. */\nexport function randomBytes(bytesLength = 32): Uint8Array {\n if (crypto && typeof crypto.getRandomValues === 'function') {\n return crypto.getRandomValues(new Uint8Array(bytesLength));\n }\n // Legacy Node.js compatibility\n if (crypto && typeof crypto.randomBytes === 'function') {\n return Uint8Array.from(crypto.randomBytes(bytesLength));\n }\n throw new Error('crypto.getRandomValues must be defined');\n}\n","/**\n * Internal helpers for u64. BigUint64Array is too slow as per 2025, so we implement it using Uint32Array.\n * @todo re-check https://issues.chromium.org/issues/42212588\n * @module\n */\nconst U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);\nconst _32n = /* @__PURE__ */ BigInt(32);\n\nfunction fromBig(\n n: bigint,\n le = false\n): {\n h: number;\n l: number;\n} {\n if (le) return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };\n return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };\n}\n\nfunction split(lst: bigint[], le = false): Uint32Array[] {\n const len = lst.length;\n let Ah = new Uint32Array(len);\n let Al = new Uint32Array(len);\n for (let i = 0; i < len; i++) {\n const { h, l } = fromBig(lst[i], le);\n [Ah[i], Al[i]] = [h, l];\n }\n return [Ah, Al];\n}\n\nconst toBig = (h: number, l: number): bigint => (BigInt(h >>> 0) << _32n) | BigInt(l >>> 0);\n// for Shift in [0, 32)\nconst shrSH = (h: number, _l: number, s: number): number => h >>> s;\nconst shrSL = (h: number, l: number, s: number): number => (h << (32 - s)) | (l >>> s);\n// Right rotate for Shift in [1, 32)\nconst rotrSH = (h: number, l: number, s: number): number => (h >>> s) | (l << (32 - s));\nconst rotrSL = (h: number, l: number, s: number): number => (h << (32 - s)) | (l >>> s);\n// Right rotate for Shift in (32, 64), NOTE: 32 is special case.\nconst rotrBH = (h: number, l: number, s: number): number => (h << (64 - s)) | (l >>> (s - 32));\nconst rotrBL = (h: number, l: number, s: number): number => (h >>> (s - 32)) | (l << (64 - s));\n// Right rotate for shift===32 (just swaps l&h)\nconst rotr32H = (_h: number, l: number): number => l;\nconst rotr32L = (h: number, _l: number): number => h;\n// Left rotate for Shift in [1, 32)\nconst rotlSH = (h: number, l: number, s: number): number => (h << s) | (l >>> (32 - s));\nconst rotlSL = (h: number, l: number, s: number): number => (l << s) | (h >>> (32 - s));\n// Left rotate for Shift in (32, 64), NOTE: 32 is special case.\nconst rotlBH = (h: number, l: number, s: number): number => (l << (s - 32)) | (h >>> (64 - s));\nconst rotlBL = (h: number, l: number, s: number): number => (h << (s - 32)) | (l >>> (64 - s));\n\n// JS uses 32-bit signed integers for bitwise operations which means we cannot\n// simple take carry out of low bit sum by shift, we need to use division.\nfunction add(\n Ah: number,\n Al: number,\n Bh: number,\n Bl: number\n): {\n h: number;\n l: number;\n} {\n const l = (Al >>> 0) + (Bl >>> 0);\n return { h: (Ah + Bh + ((l / 2 ** 32) | 0)) | 0, l: l | 0 };\n}\n// Addition with more than 2 elements\nconst add3L = (Al: number, Bl: number, Cl: number): number => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);\nconst add3H = (low: number, Ah: number, Bh: number, Ch: number): number =>\n (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0;\nconst add4L = (Al: number, Bl: number, Cl: number, Dl: number): number =>\n (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);\nconst add4H = (low: number, Ah: number, Bh: number, Ch: number, Dh: number): number =>\n (Ah + Bh + Ch + Dh + ((low / 2 ** 32) | 0)) | 0;\nconst add5L = (Al: number, Bl: number, Cl: number, Dl: number, El: number): number =>\n (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);\nconst add5H = (low: number, Ah: number, Bh: number, Ch: number, Dh: number, Eh: number): number =>\n (Ah + Bh + Ch + Dh + Eh + ((low / 2 ** 32) | 0)) | 0;\n\n// prettier-ignore\nexport {\n add, add3H, add3L, add4H, add4L, add5H, add5L, fromBig, rotlBH, rotlBL, rotlSH, rotlSL, rotr32H, rotr32L, rotrBH, rotrBL, rotrSH, rotrSL, shrSH, shrSL, split, toBig\n};\n// prettier-ignore\nconst u64: { fromBig: typeof fromBig; split: typeof split; toBig: (h: number, l: number) => bigint; shrSH: (h: number, _l: number, s: number) => number; shrSL: (h: number, l: number, s: number) => number; rotrSH: (h: number, l: number, s: number) => number; rotrSL: (h: number, l: number, s: number) => number; rotrBH: (h: number, l: number, s: number) => number; rotrBL: (h: number, l: number, s: number) => number; rotr32H: (_h: number, l: number) => number; rotr32L: (h: number, _l: number) => number; rotlSH: (h: number, l: number, s: number) => number; rotlSL: (h: number, l: number, s: number) => number; rotlBH: (h: number, l: number, s: number) => number; rotlBL: (h: number, l: number, s: number) => number; add: typeof add; add3L: (Al: number, Bl: number, Cl: number) => number; add3H: (low: number, Ah: number, Bh: number, Ch: number) => number; add4L: (Al: number, Bl: number, Cl: number, Dl: number) => number; add4H: (low: number, Ah: number, Bh: number, Ch: number, Dh: number) => number; add5H: (low: number, Ah: number, Bh: number, Ch: number, Dh: number, Eh: number) => number; add5L: (Al: number, Bl: number, Cl: number, Dl: number, El: number) => number; } = {\n fromBig, split, toBig,\n shrSH, shrSL,\n rotrSH, rotrSL, rotrBH, rotrBL,\n rotr32H, rotr32L,\n rotlSH, rotlSL, rotlBH, rotlBL,\n add, add3L, add3H, add4L, add4H, add5H, add5L,\n};\nexport default u64;\n"],"mappings":";;;AAQA,YAAY,QAAQ;AACb,IAAM,SACX,MAAM,OAAO,OAAO,YAAY,eAAe,KACvC,eACJ,MAAM,OAAO,OAAO,YAAY,iBAAiB,KAC/C,KACA;;;ACCF,SAAU,QAAQ,GAAU;AAChC,SAAO,aAAa,cAAe,YAAY,OAAO,CAAC,KAAK,EAAE,YAAY,SAAS;AACrF;AAGM,SAAU,QAAQ,GAAS;AAC/B,MAAI,CAAC,OAAO,cAAc,CAAC,KAAK,IAAI;AAAG,UAAM,IAAI,MAAM,oCAAoC,CAAC;AAC9F;AAGM,SAAU,OAAO,MAA8B,SAAiB;AACpE,MAAI,CAAC,QAAQ,CAAC;AAAG,UAAM,IAAI,MAAM,qBAAqB;AACtD,MAAI,QAAQ,SAAS,KAAK,CAAC,QAAQ,SAAS,EAAE,MAAM;AAClD,UAAM,IAAI,MAAM,mCAAmC,UAAU,kBAAkB,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AI,UAAU,GAAG,GAAG,OAAQ,KAAK,OAAQ,UAAU,EAAC;AAC/E,SAAO,EAAE,GAAG,OAAQ,KAAK,OAAQ,UAAU,IAAI,GAAG,GAAG,OAAO,IAAI,UAAU,IAAI,EAAC;AACjF;AAEA,SAAS,MAAM,KAAe,KAAK,OAAK;AACtC,QAAM,MAAM,IAAI;AAChB,MAAI,KAAK,IAAI,YAAY,GAAG;AAC5B,MAAI,KAAK,IAAI,YAAY,GAAG;AAC5B,WAAS,IAAI,GAAG,IAAI,KAAK,KAAK;AAC5B,UAAM,EAAE,GAAG,EAAC,IAAK,QAAQ,IAAI,CAAC,GAAG,EAAE;AACnC,KAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;EACxB;AACA,SAAO,CAAC,IAAI,EAAE;AAChB;AAgBA,IAAM,SAAS,CAAC,GAAW,GAAW,MAAuB,KAAK,IAAM,MAAO,KAAK;AACpF,IAAM,SAAS,CAAC,GAAW,GAAW,MAAuB,KAAK,IAAM,MAAO,KAAK;AAEpF,IAAM,SAAS,CAAC,GAAW,GAAW,MAAuB,KAAM,IAAI,KAAQ,MAAO,KAAK;AAC3F,IAAM,SAAS,CAAC,GAAW,GAAW,MAAuB,KAAM,IAAI,KAAQ,MAAO,KAAK;","names":[]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
findStoredCandidate
|
|
4
|
+
} from "./chunk-JPHG2JW3.js";
|
|
5
|
+
import {
|
|
6
|
+
UUID_RE
|
|
7
|
+
} from "./chunk-3OV7E5G5.js";
|
|
8
|
+
import {
|
|
9
|
+
CliError
|
|
10
|
+
} from "./chunk-OYMYCW7J.js";
|
|
11
|
+
|
|
12
|
+
// src/lib/resource-ref.ts
|
|
13
|
+
function assertOnBaseOrigin(url, baseUrl, what) {
|
|
14
|
+
let target;
|
|
15
|
+
let base;
|
|
16
|
+
try {
|
|
17
|
+
target = new URL(url);
|
|
18
|
+
base = new URL(baseUrl);
|
|
19
|
+
} catch {
|
|
20
|
+
throw new CliError("USAGE", `Invalid ${what}: ${JSON.stringify(url)}`, {
|
|
21
|
+
fix: "Pass an absolute https URL on the configured base URL."
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
if (target.origin !== base.origin) {
|
|
25
|
+
throw new CliError(
|
|
26
|
+
"USAGE",
|
|
27
|
+
`${what} origin ${target.origin} does not match the configured base URL ${base.origin}.`,
|
|
28
|
+
{
|
|
29
|
+
fix: "The CLI signs SIWX and payments only for the configured base URL. Pass --base-url if you meant a different deployment."
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async function resolveResourceRef(arg, dataDir, baseUrl) {
|
|
35
|
+
const trimmed = arg.trim();
|
|
36
|
+
if (/^https?:\/\//i.test(trimmed)) {
|
|
37
|
+
assertOnBaseOrigin(trimmed, baseUrl, "resource URL");
|
|
38
|
+
return { url: trimmed };
|
|
39
|
+
}
|
|
40
|
+
if (UUID_RE.test(trimmed)) {
|
|
41
|
+
const candidate = await findStoredCandidate(dataDir, trimmed);
|
|
42
|
+
if (candidate === null) {
|
|
43
|
+
throw new CliError("RESOURCE_NOT_FOUND", `No local lookup knows resource ${trimmed}.`, {
|
|
44
|
+
fix: "Run `tenjin lookup` to surface it first, or pass the full read URL."
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
assertOnBaseOrigin(candidate.url, baseUrl, "stored candidate URL");
|
|
48
|
+
return { url: candidate.url, resourceId: trimmed };
|
|
49
|
+
}
|
|
50
|
+
throw new CliError("USAGE", `Not a resource URL or id: ${JSON.stringify(arg)}`, {
|
|
51
|
+
fix: "Pass a full https read URL (a candidate `url`) or a resourceId uuid."
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export {
|
|
56
|
+
assertOnBaseOrigin,
|
|
57
|
+
resolveResourceRef
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=chunk-7KUW4MJD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/resource-ref.ts"],"sourcesContent":["import { CliError } from './errors';\nimport { findStoredCandidate } from './lookup-store';\nimport { UUID_RE } from './ids';\n\n/**\n * Resolve a `<resource-url-or-id>` CLI argument to the payable read URL. A full\n * http(s) URL must live on the configured base URL's origin; a bare uuid is a\n * resourceId, resolved to its URL through the local lookup store (the read route\n * is keyed by handle/slug, so an id alone cannot build the URL). Anything else is\n * a usage error with a clear fix.\n *\n * The origin pin is a MONEY-PATH trust boundary, not pedantry: `buy` sends a\n * wallet-signed SIWX header (a bearer credential scoped to the configured\n * domain) and an EIP-3009 payment authorization to whatever host the resolved\n * URL names. An off-origin URL, whether typed by hand or planted in a lookup\n * candidate, would hand both to that host. Nothing signed may leave for a host\n * the user did not configure.\n */\n\nexport interface ResourceRef {\n url: string;\n resourceId?: string;\n}\n\n/** Throws USAGE unless `url` parses and shares the base URL's origin. */\nexport function assertOnBaseOrigin(url: string, baseUrl: string, what: string): void {\n let target: URL;\n let base: URL;\n try {\n target = new URL(url);\n base = new URL(baseUrl);\n } catch {\n throw new CliError('USAGE', `Invalid ${what}: ${JSON.stringify(url)}`, {\n fix: 'Pass an absolute https URL on the configured base URL.',\n });\n }\n if (target.origin !== base.origin) {\n throw new CliError(\n 'USAGE',\n `${what} origin ${target.origin} does not match the configured base URL ${base.origin}.`,\n {\n fix: 'The CLI signs SIWX and payments only for the configured base URL. Pass --base-url if you meant a different deployment.',\n },\n );\n }\n}\n\nexport async function resolveResourceRef(\n arg: string,\n dataDir: string,\n baseUrl: string,\n): Promise<ResourceRef> {\n const trimmed = arg.trim();\n if (/^https?:\\/\\//i.test(trimmed)) {\n assertOnBaseOrigin(trimmed, baseUrl, 'resource URL');\n return { url: trimmed };\n }\n if (UUID_RE.test(trimmed)) {\n const candidate = await findStoredCandidate(dataDir, trimmed);\n if (candidate === null) {\n throw new CliError('RESOURCE_NOT_FOUND', `No local lookup knows resource ${trimmed}.`, {\n fix: 'Run `tenjin lookup` to surface it first, or pass the full read URL.',\n });\n }\n // The stored url was origin-checked at lookup time, but the config can have\n // changed since; re-assert against the CURRENT base URL before any send.\n assertOnBaseOrigin(candidate.url, baseUrl, 'stored candidate URL');\n return { url: candidate.url, resourceId: trimmed };\n }\n throw new CliError('USAGE', `Not a resource URL or id: ${JSON.stringify(arg)}`, {\n fix: 'Pass a full https read URL (a candidate `url`) or a resourceId uuid.',\n });\n}\n"],"mappings":";;;;;;;;;;;;AAyBO,SAAS,mBAAmB,KAAa,SAAiB,MAAoB;AACnF,MAAI;AACJ,MAAI;AACJ,MAAI;AACF,aAAS,IAAI,IAAI,GAAG;AACpB,WAAO,IAAI,IAAI,OAAO;AAAA,EACxB,QAAQ;AACN,UAAM,IAAI,SAAS,SAAS,WAAW,IAAI,KAAK,KAAK,UAAU,GAAG,CAAC,IAAI;AAAA,MACrE,KAAK;AAAA,IACP,CAAC;AAAA,EACH;AACA,MAAI,OAAO,WAAW,KAAK,QAAQ;AACjC,UAAM,IAAI;AAAA,MACR;AAAA,MACA,GAAG,IAAI,WAAW,OAAO,MAAM,2CAA2C,KAAK,MAAM;AAAA,MACrF;AAAA,QACE,KAAK;AAAA,MACP;AAAA,IACF;AAAA,EACF;AACF;AAEA,eAAsB,mBACpB,KACA,SACA,SACsB;AACtB,QAAM,UAAU,IAAI,KAAK;AACzB,MAAI,gBAAgB,KAAK,OAAO,GAAG;AACjC,uBAAmB,SAAS,SAAS,cAAc;AACnD,WAAO,EAAE,KAAK,QAAQ;AAAA,EACxB;AACA,MAAI,QAAQ,KAAK,OAAO,GAAG;AACzB,UAAM,YAAY,MAAM,oBAAoB,SAAS,OAAO;AAC5D,QAAI,cAAc,MAAM;AACtB,YAAM,IAAI,SAAS,sBAAsB,kCAAkC,OAAO,KAAK;AAAA,QACrF,KAAK;AAAA,MACP,CAAC;AAAA,IACH;AAGA,uBAAmB,UAAU,KAAK,SAAS,sBAAsB;AACjE,WAAO,EAAE,KAAK,UAAU,KAAK,YAAY,QAAQ;AAAA,EACnD;AACA,QAAM,IAAI,SAAS,SAAS,6BAA6B,KAAK,UAAU,GAAG,CAAC,IAAI;AAAA,IAC9E,KAAK;AAAA,EACP,CAAC;AACH;","names":[]}
|
|
@@ -1,94 +1,27 @@
|
|
|
1
1
|
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
CLIENT_HEADER,
|
|
4
|
+
fetchJson,
|
|
5
|
+
trimSlash
|
|
6
|
+
} from "./chunk-QNP7H47L.js";
|
|
2
7
|
import {
|
|
3
8
|
loadRawConfig,
|
|
4
9
|
resolveSettings,
|
|
5
10
|
toMoney
|
|
6
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-IYLHQMT5.js";
|
|
7
12
|
import {
|
|
8
13
|
walletFileExists
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-ZPZFPVDN.js";
|
|
14
|
+
} from "./chunk-YN5SHIXQ.js";
|
|
11
15
|
import {
|
|
12
16
|
CliError,
|
|
13
17
|
configPath
|
|
14
|
-
} from "./chunk-
|
|
15
|
-
import "./chunk-3IMLRUZE.js";
|
|
18
|
+
} from "./chunk-OYMYCW7J.js";
|
|
16
19
|
|
|
17
20
|
// src/commands/doctor.ts
|
|
18
21
|
import { styleText } from "util";
|
|
19
22
|
import { Stream } from "stream";
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
async function fetchJson(url, opts) {
|
|
23
|
-
const doFetch = opts.fetchImpl ?? fetch;
|
|
24
|
-
const controller = new AbortController();
|
|
25
|
-
let timedOut = false;
|
|
26
|
-
const timer = setTimeout(() => {
|
|
27
|
-
timedOut = true;
|
|
28
|
-
controller.abort();
|
|
29
|
-
}, opts.timeoutMs);
|
|
30
|
-
try {
|
|
31
|
-
let res;
|
|
32
|
-
try {
|
|
33
|
-
res = await doFetch(url, { signal: controller.signal });
|
|
34
|
-
} catch (err) {
|
|
35
|
-
return timedOut ? timeoutFailure(url, opts.timeoutMs) : { ok: false, kind: "network", message: `Request to ${url} failed: ${errorMessage(err)}` };
|
|
36
|
-
}
|
|
37
|
-
const requestId = res.headers.get("x-request-id") ?? void 0;
|
|
38
|
-
if (!res.ok) {
|
|
39
|
-
return {
|
|
40
|
-
ok: false,
|
|
41
|
-
kind: "http",
|
|
42
|
-
status: res.status,
|
|
43
|
-
...requestId !== void 0 ? { requestId } : {},
|
|
44
|
-
message: `Request to ${url} failed with status ${res.status}`
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
let json;
|
|
48
|
-
try {
|
|
49
|
-
json = await res.json();
|
|
50
|
-
} catch (err) {
|
|
51
|
-
if (timedOut) return timeoutFailure(url, opts.timeoutMs);
|
|
52
|
-
if (err instanceof SyntaxError) {
|
|
53
|
-
return {
|
|
54
|
-
ok: false,
|
|
55
|
-
kind: "invalid-json",
|
|
56
|
-
status: res.status,
|
|
57
|
-
...requestId !== void 0 ? { requestId } : {},
|
|
58
|
-
message: `Response from ${url} was not valid JSON`
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
return {
|
|
62
|
-
ok: false,
|
|
63
|
-
kind: "network",
|
|
64
|
-
status: res.status,
|
|
65
|
-
...requestId !== void 0 ? { requestId } : {},
|
|
66
|
-
message: `Request to ${url} failed while reading the response body: ${errorMessage(err)}`
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
return {
|
|
70
|
-
ok: true,
|
|
71
|
-
status: res.status,
|
|
72
|
-
json,
|
|
73
|
-
...requestId !== void 0 ? { requestId } : {}
|
|
74
|
-
};
|
|
75
|
-
} finally {
|
|
76
|
-
clearTimeout(timer);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
function timeoutFailure(url, timeoutMs) {
|
|
80
|
-
return {
|
|
81
|
-
ok: false,
|
|
82
|
-
kind: "timeout",
|
|
83
|
-
message: `Request to ${url} timed out after ${timeoutMs}ms`
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
function errorMessage(err) {
|
|
87
|
-
return err instanceof Error ? err.message : String(err);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// src/commands/doctor.ts
|
|
91
|
-
async function runDoctor(ctx, deps = {}) {
|
|
23
|
+
var POCKET_MONEY_CEILING_ATOMIC = 20000000n;
|
|
24
|
+
async function collectDoctorChecks(ctx, deps = {}) {
|
|
92
25
|
const env = deps.env ?? process.env;
|
|
93
26
|
const { config, check: configCheck } = await loadConfigForDoctor(ctx.dataDir);
|
|
94
27
|
const settings = resolveSettings({ config, flags: { baseUrl: ctx.flags.baseUrl }, env });
|
|
@@ -97,21 +30,27 @@ async function runDoctor(ctx, deps = {}) {
|
|
|
97
30
|
checkNode(),
|
|
98
31
|
configCheck,
|
|
99
32
|
await checkApiContract(baseUrl, ctx.flags.timeout, deps.fetchImpl),
|
|
100
|
-
await checkReadPath(baseUrl, ctx.flags.timeout, deps.fetchImpl)
|
|
33
|
+
await checkReadPath(baseUrl, ctx.flags.timeout, deps.fetchImpl),
|
|
34
|
+
await checkLookupContract(baseUrl, ctx.flags.timeout, deps.fetchImpl)
|
|
101
35
|
];
|
|
102
36
|
for (const result of await checkWallet(ctx, deps, env, settings.rpcUrl.value)) {
|
|
103
37
|
built.push({ result });
|
|
104
38
|
}
|
|
105
39
|
const checks = built.map((b) => b.result);
|
|
106
40
|
const firstFail = built.find((b) => b.result.required && b.result.status === "fail");
|
|
107
|
-
if (firstFail
|
|
108
|
-
|
|
109
|
-
|
|
41
|
+
if (firstFail === void 0) return { checks };
|
|
42
|
+
return { checks, failure: { code: firstFail.failCode ?? "INTERNAL", result: firstFail.result } };
|
|
43
|
+
}
|
|
44
|
+
async function runDoctor(ctx, deps = {}) {
|
|
45
|
+
const { checks, failure } = await collectDoctorChecks(ctx, deps);
|
|
46
|
+
if (failure !== void 0) {
|
|
47
|
+
const r = failure.result;
|
|
48
|
+
throw new CliError(failure.code, r.detail, {
|
|
110
49
|
...r.fix !== void 0 ? { fix: r.fix } : {},
|
|
111
50
|
details: { checks }
|
|
112
51
|
});
|
|
113
52
|
}
|
|
114
|
-
return { data: { status: "pass", checks }, humanLines:
|
|
53
|
+
return { data: { status: "pass", checks }, humanLines: renderDoctorHuman(ctx.io, checks) };
|
|
115
54
|
}
|
|
116
55
|
function checkNode() {
|
|
117
56
|
const version = process.versions.node;
|
|
@@ -156,7 +95,11 @@ async function loadConfigForDoctor(dataDir) {
|
|
|
156
95
|
}
|
|
157
96
|
async function checkApiContract(baseUrl, timeoutMs, fetchImpl) {
|
|
158
97
|
const url = `${trimSlash(baseUrl)}/openapi.json`;
|
|
159
|
-
const res = await fetchJson(url, {
|
|
98
|
+
const res = await fetchJson(url, {
|
|
99
|
+
timeoutMs,
|
|
100
|
+
fetchImpl,
|
|
101
|
+
headers: { "x-tenjin-client": CLIENT_HEADER }
|
|
102
|
+
});
|
|
160
103
|
if (!res.ok) {
|
|
161
104
|
const malformed = res.kind === "invalid-json";
|
|
162
105
|
return {
|
|
@@ -192,9 +135,52 @@ async function checkApiContract(baseUrl, timeoutMs, fetchImpl) {
|
|
|
192
135
|
}
|
|
193
136
|
};
|
|
194
137
|
}
|
|
138
|
+
async function checkLookupContract(baseUrl, timeoutMs, fetchImpl) {
|
|
139
|
+
const url = `${trimSlash(baseUrl)}/openapi.json`;
|
|
140
|
+
const res = await fetchJson(url, {
|
|
141
|
+
timeoutMs,
|
|
142
|
+
fetchImpl,
|
|
143
|
+
headers: { "x-tenjin-client": CLIENT_HEADER }
|
|
144
|
+
});
|
|
145
|
+
if (!res.ok) {
|
|
146
|
+
return {
|
|
147
|
+
result: {
|
|
148
|
+
name: "lookup-contract",
|
|
149
|
+
status: "warn",
|
|
150
|
+
required: false,
|
|
151
|
+
detail: `Could not confirm the lookup endpoint at ${url}`,
|
|
152
|
+
fix: "Check --base-url; lookup/buy need the A2 endpoints deployed."
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
const present = hasLookupPath(res.json);
|
|
157
|
+
return {
|
|
158
|
+
result: present ? {
|
|
159
|
+
name: "lookup-contract",
|
|
160
|
+
status: "ok",
|
|
161
|
+
required: false,
|
|
162
|
+
detail: "Lookup endpoint advertised"
|
|
163
|
+
} : {
|
|
164
|
+
name: "lookup-contract",
|
|
165
|
+
status: "warn",
|
|
166
|
+
required: false,
|
|
167
|
+
detail: "This deployment does not advertise POST /api/agent/lookup (A2 not deployed)",
|
|
168
|
+
fix: "lookup/buy need A2 deployed; point --base-url at a deploy that has it."
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function hasLookupPath(json) {
|
|
173
|
+
if (!isRecord(json)) return false;
|
|
174
|
+
const paths = json.paths;
|
|
175
|
+
return isRecord(paths) && "/api/agent/lookup" in paths;
|
|
176
|
+
}
|
|
195
177
|
async function checkReadPath(baseUrl, timeoutMs, fetchImpl) {
|
|
196
178
|
const url = `${trimSlash(baseUrl)}/api/articles?limit=1`;
|
|
197
|
-
const res = await fetchJson(url, {
|
|
179
|
+
const res = await fetchJson(url, {
|
|
180
|
+
timeoutMs,
|
|
181
|
+
fetchImpl,
|
|
182
|
+
headers: { "x-tenjin-client": CLIENT_HEADER }
|
|
183
|
+
});
|
|
198
184
|
if (!res.ok) {
|
|
199
185
|
return {
|
|
200
186
|
result: {
|
|
@@ -227,7 +213,7 @@ async function checkReadPath(baseUrl, timeoutMs, fetchImpl) {
|
|
|
227
213
|
async function checkWallet(ctx, deps, env, rpcUrl) {
|
|
228
214
|
const provider = deps.provider ?? await resolveLocalProviderOrNull(ctx, env);
|
|
229
215
|
if (provider === null) return [noWalletCheck()];
|
|
230
|
-
const { describeWallet } = await import("./wallet-
|
|
216
|
+
const { describeWallet } = await import("./wallet-PA54CRBL.js");
|
|
231
217
|
let desc;
|
|
232
218
|
try {
|
|
233
219
|
desc = await describeWallet(provider);
|
|
@@ -253,7 +239,7 @@ async function resolveLocalProviderOrNull(ctx, env) {
|
|
|
253
239
|
const envKey = env.TENJIN_WALLET_KEY;
|
|
254
240
|
const envKeySet = typeof envKey === "string" && envKey.length > 0;
|
|
255
241
|
if (!envKeySet && !await walletFileExists(ctx.dataDir)) return null;
|
|
256
|
-
const { resolveWalletProvider } = await import("./wallet-
|
|
242
|
+
const { resolveWalletProvider } = await import("./wallet-PA54CRBL.js");
|
|
257
243
|
return resolveWalletProvider(ctx);
|
|
258
244
|
}
|
|
259
245
|
function noWalletCheck() {
|
|
@@ -276,7 +262,7 @@ function walletWarn(err) {
|
|
|
276
262
|
}
|
|
277
263
|
async function checkBalance(address, rpcUrl) {
|
|
278
264
|
try {
|
|
279
|
-
const { getUsdcBalance } = await import("./usdc-
|
|
265
|
+
const { getUsdcBalance } = await import("./usdc-JIAJW4SV.js");
|
|
280
266
|
const balance = await getUsdcBalance(address, rpcUrl);
|
|
281
267
|
if (balance === 0n) {
|
|
282
268
|
return {
|
|
@@ -288,6 +274,15 @@ async function checkBalance(address, rpcUrl) {
|
|
|
288
274
|
};
|
|
289
275
|
}
|
|
290
276
|
const money = toMoney(balance.toString());
|
|
277
|
+
if (balance > POCKET_MONEY_CEILING_ATOMIC) {
|
|
278
|
+
return {
|
|
279
|
+
name: "balance",
|
|
280
|
+
status: "warn",
|
|
281
|
+
required: false,
|
|
282
|
+
detail: `Balance ${money.usd} USDC is above the ~$20 pocket-money ceiling`,
|
|
283
|
+
fix: "Keep only small change in the CLI wallet; sweep the excess to cold storage."
|
|
284
|
+
};
|
|
285
|
+
}
|
|
291
286
|
return {
|
|
292
287
|
name: "balance",
|
|
293
288
|
status: "ok",
|
|
@@ -304,7 +299,7 @@ async function checkBalance(address, rpcUrl) {
|
|
|
304
299
|
};
|
|
305
300
|
}
|
|
306
301
|
}
|
|
307
|
-
function
|
|
302
|
+
function renderDoctorHuman(io, checks) {
|
|
308
303
|
const nameWidth = Math.max(...checks.map((c) => c.name.length));
|
|
309
304
|
const lines = [];
|
|
310
305
|
for (const c of checks) {
|
|
@@ -329,10 +324,10 @@ function infoVersion(json) {
|
|
|
329
324
|
function isRecord(value) {
|
|
330
325
|
return typeof value === "object" && value !== null;
|
|
331
326
|
}
|
|
332
|
-
|
|
333
|
-
return url.replace(/\/+$/, "");
|
|
334
|
-
}
|
|
327
|
+
|
|
335
328
|
export {
|
|
336
|
-
|
|
329
|
+
collectDoctorChecks,
|
|
330
|
+
runDoctor,
|
|
331
|
+
renderDoctorHuman
|
|
337
332
|
};
|
|
338
|
-
//# sourceMappingURL=
|
|
333
|
+
//# sourceMappingURL=chunk-7PHSZKQS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/doctor.ts"],"sourcesContent":["import { styleText } from 'node:util';\nimport { Stream } from 'node:stream';\nimport { CliError } from '../lib/errors';\nimport { fetchJson } from '../lib/http';\nimport { CLIENT_HEADER } from '../lib/client-meta';\nimport { loadRawConfig, resolveSettings } from '../lib/config';\nimport { trimSlash } from '../lib/url';\nimport { configPath } from '../lib/paths';\nimport { toMoney } from '../lib/money';\nimport { walletFileExists } from '../lib/wallet/store';\nimport type { PartialConfig } from '../lib/config';\nimport type { ErrorCode } from '../schemas';\nimport type { Io } from '../lib/output';\nimport type { WalletDescription, WalletProvider } from '../lib/wallet';\nimport type { CommandContext, CommandResult } from '../context';\n\n/**\n * One environment/reachability check. The doctor agent builds the check list\n * against this shape without changing it: `required` drives the exit code (exit\n * 0 iff every required check is ok), `status` drives the TTY rendering, and a\n * `fix` is mandatory on every failure (spec 10). Warn-level checks never fail\n * the command.\n */\nexport interface CheckResult {\n name: string;\n status: 'ok' | 'warn' | 'fail';\n required: boolean;\n detail: string;\n fix?: string;\n}\n\n/** ~$20 in atomic USDC (6 decimals). Above this, the pocket-money wallet warns. */\nconst POCKET_MONEY_CEILING_ATOMIC = 20_000_000n;\n\n/**\n * A CheckResult plus the error code to raise if it is a *required* failure. Only\n * required checks carry a `failCode`; the outcome step raises the first one, so\n * the failure envelope's `error.code` names what actually broke (api-contract\n * unreachable vs malformed differ) while still carrying the whole check list.\n */\ninterface BuiltCheck {\n result: CheckResult;\n failCode?: ErrorCode;\n}\n\nexport interface DoctorDeps {\n /** Environment for wallet-key detection and settings precedence. */\n env?: NodeJS.ProcessEnv;\n /** Injected fetch for the reachability checks; tests pass a canned stub. */\n fetchImpl?: typeof fetch;\n /** Inject the active wallet provider. When set, NO local fs/env is consulted —\n * the provider owns its own describe() and diagnostics(), so a remote provider's\n * checks can't be contaminated by a stale local wallet file. */\n provider?: WalletProvider;\n}\n\n/**\n * The full check list plus the first required failure, if any. `install` reuses\n * this to run the doctor checks as its last step and EMBED the summary without\n * throwing (D39: doctor is diagnostics, it never blocks the caller); `runDoctor`\n * wraps it and turns a required failure into the thrown failure envelope.\n */\nexport interface DoctorChecks {\n checks: CheckResult[];\n failure?: { code: ErrorCode; result: CheckResult };\n}\n\nexport async function collectDoctorChecks(\n ctx: CommandContext,\n deps: DoctorDeps = {},\n): Promise<DoctorChecks> {\n const env = deps.env ?? process.env;\n const { config, check: configCheck } = await loadConfigForDoctor(ctx.dataDir);\n const settings = resolveSettings({ config, flags: { baseUrl: ctx.flags.baseUrl }, env });\n const baseUrl = settings.baseUrl.value;\n\n const built: BuiltCheck[] = [\n checkNode(),\n configCheck,\n await checkApiContract(baseUrl, ctx.flags.timeout, deps.fetchImpl),\n await checkReadPath(baseUrl, ctx.flags.timeout, deps.fetchImpl),\n await checkLookupContract(baseUrl, ctx.flags.timeout, deps.fetchImpl),\n ];\n\n // The wallet/custody/balance checks all come from the ACTIVE provider: it owns\n // describe() and diagnostics(), so doctor never runs its own fs/env probe.\n for (const result of await checkWallet(ctx, deps, env, settings.rpcUrl.value)) {\n built.push({ result });\n }\n\n const checks = built.map((b) => b.result);\n const firstFail = built.find((b) => b.result.required && b.result.status === 'fail');\n if (firstFail === undefined) return { checks };\n return { checks, failure: { code: firstFail.failCode ?? 'INTERNAL', result: firstFail.result } };\n}\n\nexport async function runDoctor(\n ctx: CommandContext,\n deps: DoctorDeps = {},\n): Promise<CommandResult> {\n const { checks, failure } = await collectDoctorChecks(ctx, deps);\n if (failure !== undefined) {\n const r = failure.result;\n throw new CliError(failure.code, r.detail, {\n ...(r.fix !== undefined ? { fix: r.fix } : {}),\n details: { checks },\n });\n }\n\n return { data: { status: 'pass', checks }, humanLines: renderDoctorHuman(ctx.io, checks) };\n}\n\nfunction checkNode(): BuiltCheck {\n const version = process.versions.node;\n const major = Number.parseInt(version.split('.')[0] ?? '0', 10);\n if (major >= 22) {\n return { result: { name: 'node', status: 'ok', required: true, detail: `Node ${version}` } };\n }\n return {\n result: {\n name: 'node',\n status: 'fail',\n required: true,\n detail: `Node ${version} is unsupported (need >= 22)`,\n fix: 'Install Node 22 or newer',\n },\n failCode: 'NODE_UNSUPPORTED',\n };\n}\n\n/**\n * loadRawConfig throws CONFIG_INVALID on a bad file (which we convert into a\n * failing check) but the config value is also needed for baseUrl/rpcUrl\n * resolution; an invalid file falls back to {} so the reachability checks still\n * run and appear in the list, and config is reported as the first required fail.\n */\nasync function loadConfigForDoctor(\n dataDir: string,\n): Promise<{ config: PartialConfig; check: BuiltCheck }> {\n try {\n const config = await loadRawConfig(dataDir);\n const detail =\n Object.keys(config).length === 0\n ? 'No config file; using defaults'\n : `Config at ${configPath(dataDir)} is valid`;\n return { config, check: { result: { name: 'config', status: 'ok', required: true, detail } } };\n } catch (err) {\n if (err instanceof CliError && err.code === 'CONFIG_INVALID') {\n return {\n config: {},\n check: {\n result: {\n name: 'config',\n status: 'fail',\n required: true,\n detail: err.message,\n ...(err.fix !== undefined ? { fix: err.fix } : {}),\n },\n failCode: 'CONFIG_INVALID',\n },\n };\n }\n throw err;\n }\n}\n\nasync function checkApiContract(\n baseUrl: string,\n timeoutMs: number,\n fetchImpl?: typeof fetch,\n): Promise<BuiltCheck> {\n const url = `${trimSlash(baseUrl)}/openapi.json`;\n const res = await fetchJson(url, {\n timeoutMs,\n fetchImpl,\n headers: { 'x-tenjin-client': CLIENT_HEADER },\n });\n if (!res.ok) {\n const malformed = res.kind === 'invalid-json';\n return {\n result: {\n name: 'api-contract',\n status: 'fail',\n required: true,\n detail: malformed\n ? `OpenAPI document at ${url} was not valid JSON`\n : `Could not reach the Tenjin API at ${url}: ${res.message}`,\n fix: malformed\n ? 'Point --base-url at a Tenjin API (expected an OpenAPI document).'\n : 'Check your network connection and --base-url.',\n },\n failCode: malformed ? 'CONTRACT_MISMATCH' : 'API_UNREACHABLE',\n };\n }\n const version = infoVersion(res.json);\n if (version === undefined) {\n return {\n result: {\n name: 'api-contract',\n status: 'fail',\n required: true,\n detail: `OpenAPI document at ${url} is missing a string info.version`,\n fix: 'Point --base-url at a Tenjin API (expected an OpenAPI document).',\n },\n failCode: 'CONTRACT_MISMATCH',\n };\n }\n return {\n result: {\n name: 'api-contract',\n status: 'ok',\n required: true,\n detail: `Tenjin API ${version} at ${baseUrl}`,\n },\n };\n}\n\n/**\n * WARN-level (never fails doctor): is the A2 lookup endpoint advertised in the\n * OpenAPI doc? Absent means the deployment predates A2 (the buy/lookup path will\n * not work against it yet). Warn-only because doctor's job is a working READ path,\n * and lookup is additive.\n */\nasync function checkLookupContract(\n baseUrl: string,\n timeoutMs: number,\n fetchImpl?: typeof fetch,\n): Promise<BuiltCheck> {\n const url = `${trimSlash(baseUrl)}/openapi.json`;\n const res = await fetchJson(url, {\n timeoutMs,\n fetchImpl,\n headers: { 'x-tenjin-client': CLIENT_HEADER },\n });\n if (!res.ok) {\n return {\n result: {\n name: 'lookup-contract',\n status: 'warn',\n required: false,\n detail: `Could not confirm the lookup endpoint at ${url}`,\n fix: 'Check --base-url; lookup/buy need the A2 endpoints deployed.',\n },\n };\n }\n const present = hasLookupPath(res.json);\n return {\n result: present\n ? {\n name: 'lookup-contract',\n status: 'ok',\n required: false,\n detail: 'Lookup endpoint advertised',\n }\n : {\n name: 'lookup-contract',\n status: 'warn',\n required: false,\n detail: 'This deployment does not advertise POST /api/agent/lookup (A2 not deployed)',\n fix: 'lookup/buy need A2 deployed; point --base-url at a deploy that has it.',\n },\n };\n}\n\nfunction hasLookupPath(json: unknown): boolean {\n if (!isRecord(json)) return false;\n const paths = json.paths;\n return isRecord(paths) && '/api/agent/lookup' in paths;\n}\n\nasync function checkReadPath(\n baseUrl: string,\n timeoutMs: number,\n fetchImpl?: typeof fetch,\n): Promise<BuiltCheck> {\n // The shipped public read path. The A2 lookup-contract check is a B2 follow-up.\n // Probe the UNFILTERED listing: the server logs every nonblank first-page `q`\n // as agent search demand, so a `q` here would fabricate that demand into the\n // experiment this CLI exists to measure. Never add a `q` to this probe.\n const url = `${trimSlash(baseUrl)}/api/articles?limit=1`;\n const res = await fetchJson(url, {\n timeoutMs,\n fetchImpl,\n headers: { 'x-tenjin-client': CLIENT_HEADER },\n });\n if (!res.ok) {\n return {\n result: {\n name: 'read-path',\n status: 'fail',\n required: true,\n detail: `Read path ${url} failed: ${res.message}`,\n fix: 'Check your network connection and --base-url.',\n },\n failCode: 'API_UNREACHABLE',\n };\n }\n const items = isRecord(res.json) ? res.json.items : undefined;\n if (!Array.isArray(items)) {\n return {\n result: {\n name: 'read-path',\n status: 'fail',\n required: true,\n detail: `Read path ${url} did not return an items array`,\n fix: 'Point --base-url at a Tenjin API.',\n },\n failCode: 'API_UNREACHABLE',\n };\n }\n return {\n result: { name: 'read-path', status: 'ok', required: true, detail: `Read path OK at ${url}` },\n };\n}\n\n/**\n * Diagnose the wallet the CLI would actually use, entirely through the ACTIVE\n * provider. An injected provider owns everything — no local file or env is touched.\n * With no injected provider we do ONE cheap fs/env probe purely to decide whether\n * any credential exists: none → emit the \"no wallet\" warn WITHOUT importing the\n * wallet lib (that import statically pulls viem, and a no-wallet run must not parse\n * it). Otherwise the provider describes itself (address + source), reports its own\n * custody warnings, and the balance probes describe()'s address. A custody problem\n * (bad key, provider refusal) is warn-level, never a hard fail.\n */\nasync function checkWallet(\n ctx: CommandContext,\n deps: DoctorDeps,\n env: NodeJS.ProcessEnv,\n rpcUrl: string,\n): Promise<CheckResult[]> {\n const provider = deps.provider ?? (await resolveLocalProviderOrNull(ctx, env));\n if (provider === null) return [noWalletCheck()];\n\n const { describeWallet } = await import('../lib/wallet');\n let desc: WalletDescription;\n try {\n desc = await describeWallet(provider);\n } catch (err) {\n if (err instanceof CliError && err.code === 'WALLET_MISSING') return [noWalletCheck()];\n return [walletWarn(err)];\n }\n\n const checks: CheckResult[] = [\n {\n name: 'wallet',\n status: 'ok',\n required: false,\n detail: `Wallet ${desc.address} (${desc.credentialSource})`,\n },\n ];\n // Custody warnings are the provider's own (perms, env-shadow for the local\n // provider; none for a remote one). Render each as a warn check; the fix text,\n // when there is one, is carried inline in the warning string.\n for (const warning of (await provider.diagnostics()).warnings) {\n checks.push({ name: 'wallet-custody', status: 'warn', required: false, detail: warning });\n }\n checks.push(await checkBalance(desc.address, rpcUrl));\n return checks;\n}\n\n/**\n * The active local provider, or null when no credential exists at all. The null\n * path never imports the wallet lib, keeping a no-wallet doctor run off viem.\n */\nasync function resolveLocalProviderOrNull(\n ctx: CommandContext,\n env: NodeJS.ProcessEnv,\n): Promise<WalletProvider | null> {\n const envKey = env.TENJIN_WALLET_KEY;\n const envKeySet = typeof envKey === 'string' && envKey.length > 0;\n if (!envKeySet && !(await walletFileExists(ctx.dataDir))) return null;\n const { resolveWalletProvider } = await import('../lib/wallet');\n return resolveWalletProvider(ctx);\n}\n\nfunction noWalletCheck(): CheckResult {\n return {\n name: 'wallet',\n status: 'warn',\n required: false,\n detail: 'No wallet; needed only for buy/publish',\n fix: 'tenjin wallet create',\n };\n}\n\nfunction walletWarn(err: unknown): CheckResult {\n return {\n name: 'wallet',\n status: 'warn',\n required: false,\n detail: err instanceof Error ? err.message : String(err),\n ...(err instanceof CliError && err.fix !== undefined ? { fix: err.fix } : {}),\n };\n}\n\n/**\n * Balance is best-effort: a zero balance is a fundable warning and an RPC flake\n * must never fail doctor. viem loads only here, via a lazy import, so a doctor\n * run without a wallet never parses the viem chunk.\n */\nasync function checkBalance(address: string, rpcUrl: string): Promise<CheckResult> {\n try {\n const { getUsdcBalance } = await import('../lib/usdc');\n const balance = await getUsdcBalance(address as `0x${string}`, rpcUrl);\n if (balance === 0n) {\n return {\n name: 'balance',\n status: 'warn',\n required: false,\n detail: 'Wallet USDC balance is 0',\n fix: 'Send USDC on Base. $5 covers ~50 typical resources.',\n };\n }\n const money = toMoney(balance.toString());\n // Pocket-money posture (roadmap B2): a plaintext-adjacent local key should\n // hold only small change, so a balance over ~$20 is a warn, not an error.\n if (balance > POCKET_MONEY_CEILING_ATOMIC) {\n return {\n name: 'balance',\n status: 'warn',\n required: false,\n detail: `Balance ${money.usd} USDC is above the ~$20 pocket-money ceiling`,\n fix: 'Keep only small change in the CLI wallet; sweep the excess to cold storage.',\n };\n }\n return {\n name: 'balance',\n status: 'ok',\n required: false,\n detail: `Balance ${money.usd} USDC (${money.atomic} atomic)`,\n };\n } catch (err) {\n return {\n name: 'balance',\n status: 'warn',\n required: false,\n detail: `Could not read balance: ${err instanceof Error ? err.message : String(err)}`,\n fix: 'Check rpcUrl or retry; a balance read failure never fails doctor.',\n };\n }\n}\n\nexport function renderDoctorHuman(io: Io, checks: CheckResult[]): string[] {\n const nameWidth = Math.max(...checks.map((c) => c.name.length));\n const lines: string[] = [];\n for (const c of checks) {\n const icon =\n c.status === 'ok'\n ? paint(io, 'green', '✓')\n : c.status === 'warn'\n ? paint(io, 'yellow', '!')\n : paint(io, 'red', '✗');\n lines.push(`${icon} ${c.name.padEnd(nameWidth)} ${paint(io, 'dim', c.detail)}`);\n if (c.status !== 'ok' && c.fix !== undefined) {\n lines.push(` ${paint(io, 'dim', `fix: ${c.fix}`)}`);\n }\n }\n return lines;\n}\n\n/**\n * Color for stderr, honoring NO_COLOR and the target's color depth: styleText\n * takes the stderr stream when it is a genuine Stream (it throws on anything\n * else, so a test/redirected sink falls back to the default plain check).\n */\nfunction paint(io: Io, format: Parameters<typeof styleText>[0], text: string): string {\n if (io.stderr instanceof Stream) return styleText(format, text, { stream: io.stderr });\n return styleText(format, text);\n}\n\nfunction infoVersion(json: unknown): string | undefined {\n if (!isRecord(json)) return undefined;\n const info = json.info;\n if (!isRecord(info)) return undefined;\n return typeof info.version === 'string' ? info.version : undefined;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AA+BvB,IAAM,8BAA8B;AAmCpC,eAAsB,oBACpB,KACA,OAAmB,CAAC,GACG;AACvB,QAAM,MAAM,KAAK,OAAO,QAAQ;AAChC,QAAM,EAAE,QAAQ,OAAO,YAAY,IAAI,MAAM,oBAAoB,IAAI,OAAO;AAC5E,QAAM,WAAW,gBAAgB,EAAE,QAAQ,OAAO,EAAE,SAAS,IAAI,MAAM,QAAQ,GAAG,IAAI,CAAC;AACvF,QAAM,UAAU,SAAS,QAAQ;AAEjC,QAAM,QAAsB;AAAA,IAC1B,UAAU;AAAA,IACV;AAAA,IACA,MAAM,iBAAiB,SAAS,IAAI,MAAM,SAAS,KAAK,SAAS;AAAA,IACjE,MAAM,cAAc,SAAS,IAAI,MAAM,SAAS,KAAK,SAAS;AAAA,IAC9D,MAAM,oBAAoB,SAAS,IAAI,MAAM,SAAS,KAAK,SAAS;AAAA,EACtE;AAIA,aAAW,UAAU,MAAM,YAAY,KAAK,MAAM,KAAK,SAAS,OAAO,KAAK,GAAG;AAC7E,UAAM,KAAK,EAAE,OAAO,CAAC;AAAA,EACvB;AAEA,QAAM,SAAS,MAAM,IAAI,CAAC,MAAM,EAAE,MAAM;AACxC,QAAM,YAAY,MAAM,KAAK,CAAC,MAAM,EAAE,OAAO,YAAY,EAAE,OAAO,WAAW,MAAM;AACnF,MAAI,cAAc,OAAW,QAAO,EAAE,OAAO;AAC7C,SAAO,EAAE,QAAQ,SAAS,EAAE,MAAM,UAAU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
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
a2 as a,
|
|
4
|
+
i2 as i,
|
|
5
|
+
p,
|
|
6
|
+
r,
|
|
7
|
+
t
|
|
8
|
+
} from "./chunk-HSDCI7OV.js";
|
|
9
|
+
|
|
10
|
+
// node_modules/.pnpm/@signinwithethereum+siwe@4.2.0_viem@2.55.2_typescript@6.0.3_zod@4.4.3_/node_modules/@signinwithethereum/siwe/dist/viemAdapter-By13KInL.js
|
|
11
|
+
var a2 = /* @__PURE__ */ t({ createViemConfig: () => s });
|
|
12
|
+
var o = [{
|
|
13
|
+
inputs: [{
|
|
14
|
+
name: "_message",
|
|
15
|
+
type: "bytes32"
|
|
16
|
+
}, {
|
|
17
|
+
name: "_signature",
|
|
18
|
+
type: "bytes"
|
|
19
|
+
}],
|
|
20
|
+
name: "isValidSignature",
|
|
21
|
+
outputs: [{
|
|
22
|
+
name: "",
|
|
23
|
+
type: "bytes4"
|
|
24
|
+
}],
|
|
25
|
+
stateMutability: "view",
|
|
26
|
+
type: "function"
|
|
27
|
+
}];
|
|
28
|
+
async function s(e) {
|
|
29
|
+
let a3;
|
|
30
|
+
try {
|
|
31
|
+
a3 = await import("./_esm-FEASBWRP.js");
|
|
32
|
+
} catch {
|
|
33
|
+
throw new r(i.MISSING_PROVIDER_LIBRARY, "viem installed (npm install viem)", "viem not found");
|
|
34
|
+
}
|
|
35
|
+
let s2 = {
|
|
36
|
+
verifyMessage: async (e2, t2) => a3.recoverMessageAddress({
|
|
37
|
+
message: e2,
|
|
38
|
+
signature: t2
|
|
39
|
+
}),
|
|
40
|
+
hashMessage: (e2) => a3.hashMessage(e2),
|
|
41
|
+
getAddress: (e2) => a3.getAddress(e2)
|
|
42
|
+
};
|
|
43
|
+
if (e?.publicClient) {
|
|
44
|
+
let t2 = e.publicClient;
|
|
45
|
+
s2.checkContractWalletSignature = async (e2, i2, s3, c) => {
|
|
46
|
+
let l = t2.chain?.id;
|
|
47
|
+
if (l == null && t2.getChainId && (l = await t2.getChainId()), l == null) throw new p("EIP-1271/EIP-6492 verification requires a viem publicClient with chain.id or getChainId().");
|
|
48
|
+
if (l !== c) throw new p(`publicClient chainId ${l} does not match message chainId ${c}.`);
|
|
49
|
+
if (t2.verifyMessage) return t2.verifyMessage({
|
|
50
|
+
address: e2,
|
|
51
|
+
message: i2,
|
|
52
|
+
signature: s3
|
|
53
|
+
});
|
|
54
|
+
let u = a3.hashMessage(i2);
|
|
55
|
+
return await t2.readContract({
|
|
56
|
+
address: e2,
|
|
57
|
+
abi: o,
|
|
58
|
+
functionName: "isValidSignature",
|
|
59
|
+
args: [u, s3]
|
|
60
|
+
}) === a;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return s2;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export {
|
|
67
|
+
a2 as a,
|
|
68
|
+
s
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=chunk-CYOF7ROH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../node_modules/.pnpm/@signinwithethereum+siwe@4.2.0_viem@2.55.2_typescript@6.0.3_zod@4.4.3_/node_modules/@signinwithethereum/siwe/dist/viemAdapter-By13KInL.js"],"sourcesContent":["import { t as e } from \"./rolldown-runtime-CAFD8bLK.js\";\nimport { d as t, o as n, t as r, u as i } from \"./utils-9-kzgPFC.js\";\n//#region lib/viemAdapter.ts\nvar a = /* @__PURE__ */ e({ createViemConfig: () => s }), o = [{\n\tinputs: [{\n\t\tname: \"_message\",\n\t\ttype: \"bytes32\"\n\t}, {\n\t\tname: \"_signature\",\n\t\ttype: \"bytes\"\n\t}],\n\tname: \"isValidSignature\",\n\toutputs: [{\n\t\tname: \"\",\n\t\ttype: \"bytes4\"\n\t}],\n\tstateMutability: \"view\",\n\ttype: \"function\"\n}];\nasync function s(e) {\n\tlet a;\n\ttry {\n\t\ta = await import(\"viem\");\n\t} catch {\n\t\tthrow new i(t.MISSING_PROVIDER_LIBRARY, \"viem installed (npm install viem)\", \"viem not found\");\n\t}\n\tlet s = {\n\t\tverifyMessage: async (e, t) => a.recoverMessageAddress({\n\t\t\tmessage: e,\n\t\t\tsignature: t\n\t\t}),\n\t\thashMessage: (e) => a.hashMessage(e),\n\t\tgetAddress: (e) => a.getAddress(e)\n\t};\n\tif (e?.publicClient) {\n\t\tlet t = e.publicClient;\n\t\ts.checkContractWalletSignature = async (e, i, s, c) => {\n\t\t\tlet l = t.chain?.id;\n\t\t\tif (l == null && t.getChainId && (l = await t.getChainId()), l == null) throw new r(\"EIP-1271/EIP-6492 verification requires a viem publicClient with chain.id or getChainId().\");\n\t\t\tif (l !== c) throw new r(`publicClient chainId ${l} does not match message chainId ${c}.`);\n\t\t\tif (t.verifyMessage) return t.verifyMessage({\n\t\t\t\taddress: e,\n\t\t\t\tmessage: i,\n\t\t\t\tsignature: s\n\t\t\t});\n\t\t\tlet u = a.hashMessage(i);\n\t\t\treturn await t.readContract({\n\t\t\t\taddress: e,\n\t\t\t\tabi: o,\n\t\t\t\tfunctionName: \"isValidSignature\",\n\t\t\t\targs: [u, s]\n\t\t\t}) === n;\n\t\t};\n\t}\n\treturn s;\n}\n//#endregion\nexport { a as n, s as t };\n"],"mappings":";;;;;;;;;;AAGA,IAAIA,KAAoB,kBAAE,EAAE,kBAAkB,MAAM,EAAE,CAAC;AAAvD,IAA0D,IAAI,CAAC;AAAA,EAC9D,QAAQ,CAAC;AAAA,IACR,MAAM;AAAA,IACN,MAAM;AAAA,EACP,GAAG;AAAA,IACF,MAAM;AAAA,IACN,MAAM;AAAA,EACP,CAAC;AAAA,EACD,MAAM;AAAA,EACN,SAAS,CAAC;AAAA,IACT,MAAM;AAAA,IACN,MAAM;AAAA,EACP,CAAC;AAAA,EACD,iBAAiB;AAAA,EACjB,MAAM;AACP,CAAC;AACD,eAAe,EAAE,GAAG;AACnB,MAAIA;AACJ,MAAI;AACH,IAAA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