tenjin-cli 0.1.0-alpha.0
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/LICENSE +21 -0
- package/NOTICE.md +52 -0
- package/README.md +124 -0
- package/dist/_esm-ZH2J4QEH.js +3737 -0
- package/dist/_esm-ZH2J4QEH.js.map +1 -0
- package/dist/ccip-FXWZDDF5.js +17 -0
- package/dist/ccip-FXWZDDF5.js.map +1 -0
- package/dist/chunk-376LHMK2.js +100 -0
- package/dist/chunk-376LHMK2.js.map +1 -0
- package/dist/chunk-3IMLRUZE.js +44 -0
- package/dist/chunk-3IMLRUZE.js.map +1 -0
- package/dist/chunk-CPUZRZ2A.js +410 -0
- package/dist/chunk-CPUZRZ2A.js.map +1 -0
- package/dist/chunk-F5DZJLU3.js +2058 -0
- package/dist/chunk-F5DZJLU3.js.map +1 -0
- package/dist/chunk-FIYZLITH.js +14577 -0
- package/dist/chunk-FIYZLITH.js.map +1 -0
- package/dist/chunk-LTTRND4A.js +135 -0
- package/dist/chunk-LTTRND4A.js.map +1 -0
- package/dist/chunk-PAAL45FJ.js +7307 -0
- package/dist/chunk-PAAL45FJ.js.map +1 -0
- package/dist/chunk-QHIEYBLV.js +320 -0
- package/dist/chunk-QHIEYBLV.js.map +1 -0
- package/dist/chunk-SXQQ2ZSR.js +887 -0
- package/dist/chunk-SXQQ2ZSR.js.map +1 -0
- package/dist/chunk-TX5T3LKJ.js +2249 -0
- package/dist/chunk-TX5T3LKJ.js.map +1 -0
- package/dist/chunk-WOHCAMDQ.js +4474 -0
- package/dist/chunk-WOHCAMDQ.js.map +1 -0
- package/dist/chunk-ZPZFPVDN.js +67 -0
- package/dist/chunk-ZPZFPVDN.js.map +1 -0
- package/dist/cli-LMHGCZ5S.js +3763 -0
- package/dist/cli-LMHGCZ5S.js.map +1 -0
- package/dist/config-XVXZ3V2Q.js +206 -0
- package/dist/config-XVXZ3V2Q.js.map +1 -0
- package/dist/doctor-MVLZRVPU.js +338 -0
- package/dist/doctor-MVLZRVPU.js.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/mine.wasm-GQECMSGN.js +11 -0
- package/dist/mine.wasm-GQECMSGN.js.map +1 -0
- package/dist/secp256k1-35YNNB6F.js +18 -0
- package/dist/secp256k1-35YNNB6F.js.map +1 -0
- package/dist/usdc-OQUOFF6R.js +18 -0
- package/dist/usdc-OQUOFF6R.js.map +1 -0
- package/dist/wallet-NRKWLKHX.js +153 -0
- package/dist/wallet-NRKWLKHX.js.map +1 -0
- package/dist/wallet-QUWK2PA4.js +22 -0
- package/dist/wallet-QUWK2PA4.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
writeFileAtomicExclusive
|
|
4
|
+
} from "./chunk-ZPZFPVDN.js";
|
|
5
|
+
import {
|
|
6
|
+
CliError,
|
|
7
|
+
external_exports,
|
|
8
|
+
walletPath
|
|
9
|
+
} from "./chunk-FIYZLITH.js";
|
|
10
|
+
|
|
11
|
+
// src/lib/wallet/store.ts
|
|
12
|
+
import { readFile, stat } from "fs/promises";
|
|
13
|
+
var PRIVATE_KEY_RE = /^0x[0-9a-f]{64}$/i;
|
|
14
|
+
var ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
|
|
15
|
+
var WalletRecordSchema = external_exports.object({
|
|
16
|
+
schemaVersion: external_exports.literal(1),
|
|
17
|
+
provider: external_exports.literal("local"),
|
|
18
|
+
address: external_exports.string().regex(ADDRESS_RE, "expected a 0x-prefixed 20-byte address"),
|
|
19
|
+
privateKey: external_exports.string().regex(PRIVATE_KEY_RE, "expected a 0x-prefixed 32-byte hex key"),
|
|
20
|
+
createdAt: external_exports.string()
|
|
21
|
+
});
|
|
22
|
+
async function walletFileExists(dir) {
|
|
23
|
+
return await walletFileMode(dir) !== null;
|
|
24
|
+
}
|
|
25
|
+
async function walletFileMode(dir) {
|
|
26
|
+
try {
|
|
27
|
+
return (await stat(walletPath(dir))).mode & 511;
|
|
28
|
+
} catch (err) {
|
|
29
|
+
if (isNotFound(err)) return null;
|
|
30
|
+
throw err;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function readWalletRecord(dir) {
|
|
34
|
+
const path = walletPath(dir);
|
|
35
|
+
let raw;
|
|
36
|
+
try {
|
|
37
|
+
raw = await readFile(path, "utf8");
|
|
38
|
+
} catch (err) {
|
|
39
|
+
if (isNotFound(err)) return null;
|
|
40
|
+
throw new CliError("WALLET_INVALID_KEY", `Could not read the wallet file at ${path}.`, {
|
|
41
|
+
fix: `Check file permissions on ${path}.`,
|
|
42
|
+
cause: err
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
let json;
|
|
46
|
+
try {
|
|
47
|
+
json = JSON.parse(raw);
|
|
48
|
+
} catch (err) {
|
|
49
|
+
throw new CliError("WALLET_INVALID_KEY", `The wallet file at ${path} is not valid JSON.`, {
|
|
50
|
+
fix: `Move ${path} aside, then run \`tenjin wallet create\` or \`tenjin wallet import\`.`,
|
|
51
|
+
cause: err
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
const parsed = WalletRecordSchema.safeParse(json);
|
|
55
|
+
if (!parsed.success) {
|
|
56
|
+
throw new CliError(
|
|
57
|
+
"WALLET_INVALID_KEY",
|
|
58
|
+
`The wallet file at ${path} is not a valid wallet record.`,
|
|
59
|
+
{
|
|
60
|
+
fix: `Move ${path} aside, then run \`tenjin wallet create\` or \`tenjin wallet import\`.`,
|
|
61
|
+
details: parsed.error.issues
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
return parsed.data;
|
|
66
|
+
}
|
|
67
|
+
async function writeWalletRecord(dir, record) {
|
|
68
|
+
const validated = WalletRecordSchema.parse(record);
|
|
69
|
+
const path = walletPath(dir);
|
|
70
|
+
try {
|
|
71
|
+
await writeFileAtomicExclusive(path, `${JSON.stringify(validated, null, 2)}
|
|
72
|
+
`, {
|
|
73
|
+
mode: 384,
|
|
74
|
+
dirMode: 448
|
|
75
|
+
});
|
|
76
|
+
} catch (err) {
|
|
77
|
+
if (hasCode(err, "EEXIST")) {
|
|
78
|
+
throw new CliError("WALLET_EXISTS", `A wallet already exists at ${path}.`, {
|
|
79
|
+
fix: `Keys are non-recoverable; move it aside first (e.g. \`mv ${path} ${path}.bak\`) to create a new one.`,
|
|
80
|
+
cause: err
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
throw err;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function isNotFound(err) {
|
|
87
|
+
return hasCode(err, "ENOENT");
|
|
88
|
+
}
|
|
89
|
+
function hasCode(err, code) {
|
|
90
|
+
return typeof err === "object" && err !== null && "code" in err && err.code === code;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export {
|
|
94
|
+
PRIVATE_KEY_RE,
|
|
95
|
+
walletFileExists,
|
|
96
|
+
walletFileMode,
|
|
97
|
+
readWalletRecord,
|
|
98
|
+
writeWalletRecord
|
|
99
|
+
};
|
|
100
|
+
//# sourceMappingURL=chunk-376LHMK2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/wallet/store.ts"],"sourcesContent":["import { readFile, stat } from 'node:fs/promises';\nimport { z } from 'zod';\nimport { CliError } from '../errors';\nimport { writeFileAtomicExclusive } from '../atomic-json';\nimport { walletPath } from '../paths';\n\n/** A 0x-prefixed 32-byte hex private key (case-insensitive). */\nexport const PRIVATE_KEY_RE = /^0x[0-9a-f]{64}$/i;\nconst ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;\n\n/**\n * The persisted wallet record. The `provider` discriminator keeps the schema\n * from implying every future wallet embeds a raw key; `address` is stored EIP-55\n * checksummed so `show`/`doctor` never derive it from the key. Validated on read\n * (a corrupt file is WALLET_INVALID_KEY, never a silent partial parse).\n */\nexport const WalletRecordSchema = z.object({\n schemaVersion: z.literal(1),\n provider: z.literal('local'),\n address: z.string().regex(ADDRESS_RE, 'expected a 0x-prefixed 20-byte address'),\n privateKey: z.string().regex(PRIVATE_KEY_RE, 'expected a 0x-prefixed 32-byte hex key'),\n createdAt: z.string(),\n});\nexport type WalletRecord = z.infer<typeof WalletRecordSchema>;\n\nexport async function walletFileExists(dir: string): Promise<boolean> {\n return (await walletFileMode(dir)) !== null;\n}\n\n/** File permission bits (`mode & 0o777`), or null when the wallet file is absent. */\nexport async function walletFileMode(dir: string): Promise<number | null> {\n try {\n return (await stat(walletPath(dir))).mode & 0o777;\n } catch (err) {\n if (isNotFound(err)) return null;\n throw err;\n }\n}\n\n/** Read + validate the wallet record; null when absent, WALLET_INVALID_KEY when corrupt. */\nexport async function readWalletRecord(dir: string): Promise<WalletRecord | null> {\n const path = walletPath(dir);\n let raw: string;\n try {\n raw = await readFile(path, 'utf8');\n } catch (err) {\n if (isNotFound(err)) return null;\n throw new CliError('WALLET_INVALID_KEY', `Could not read the wallet file at ${path}.`, {\n fix: `Check file permissions on ${path}.`,\n cause: err,\n });\n }\n let json: unknown;\n try {\n json = JSON.parse(raw);\n } catch (err) {\n throw new CliError('WALLET_INVALID_KEY', `The wallet file at ${path} is not valid JSON.`, {\n fix: `Move ${path} aside, then run \\`tenjin wallet create\\` or \\`tenjin wallet import\\`.`,\n cause: err,\n });\n }\n const parsed = WalletRecordSchema.safeParse(json);\n if (!parsed.success) {\n throw new CliError(\n 'WALLET_INVALID_KEY',\n `The wallet file at ${path} is not a valid wallet record.`,\n {\n fix: `Move ${path} aside, then run \\`tenjin wallet create\\` or \\`tenjin wallet import\\`.`,\n details: parsed.error.issues,\n },\n );\n }\n return parsed.data;\n}\n\n/**\n * Persist a validated record at 0600 in a 0700 dir, NO-CLOBBER. The exclusive\n * write — not an earlier existence check — is the authority: two concurrent\n * `create`/`import` runs can both pass a pre-check, but only one can win the\n * atomic commit; the loser surfaces as WALLET_EXISTS instead of silently\n * overwriting (and losing) a non-recoverable key.\n */\nexport async function writeWalletRecord(dir: string, record: WalletRecord): Promise<void> {\n const validated = WalletRecordSchema.parse(record);\n const path = walletPath(dir);\n try {\n await writeFileAtomicExclusive(path, `${JSON.stringify(validated, null, 2)}\\n`, {\n mode: 0o600,\n dirMode: 0o700,\n });\n } catch (err) {\n if (hasCode(err, 'EEXIST')) {\n throw new CliError('WALLET_EXISTS', `A wallet already exists at ${path}.`, {\n fix: `Keys are non-recoverable; move it aside first (e.g. \\`mv ${path} ${path}.bak\\`) to create a new one.`,\n cause: err,\n });\n }\n throw err;\n }\n}\n\nfunction isNotFound(err: unknown): boolean {\n return hasCode(err, 'ENOENT');\n}\n\nfunction hasCode(err: unknown, code: string): boolean {\n return (\n typeof err === 'object' &&\n err !== null &&\n 'code' in err &&\n (err as { code?: unknown }).code === code\n );\n}\n"],"mappings":";;;;;;;;;;;AAAA,SAAS,UAAU,YAAY;AAOxB,IAAM,iBAAiB;AAC9B,IAAM,aAAa;AAQZ,IAAM,qBAAqB,iBAAE,OAAO;AAAA,EACzC,eAAe,iBAAE,QAAQ,CAAC;AAAA,EAC1B,UAAU,iBAAE,QAAQ,OAAO;AAAA,EAC3B,SAAS,iBAAE,OAAO,EAAE,MAAM,YAAY,wCAAwC;AAAA,EAC9E,YAAY,iBAAE,OAAO,EAAE,MAAM,gBAAgB,wCAAwC;AAAA,EACrF,WAAW,iBAAE,OAAO;AACtB,CAAC;AAGD,eAAsB,iBAAiB,KAA+B;AACpE,SAAQ,MAAM,eAAe,GAAG,MAAO;AACzC;AAGA,eAAsB,eAAe,KAAqC;AACxE,MAAI;AACF,YAAQ,MAAM,KAAK,WAAW,GAAG,CAAC,GAAG,OAAO;AAAA,EAC9C,SAAS,KAAK;AACZ,QAAI,WAAW,GAAG,EAAG,QAAO;AAC5B,UAAM;AAAA,EACR;AACF;AAGA,eAAsB,iBAAiB,KAA2C;AAChF,QAAM,OAAO,WAAW,GAAG;AAC3B,MAAI;AACJ,MAAI;AACF,UAAM,MAAM,SAAS,MAAM,MAAM;AAAA,EACnC,SAAS,KAAK;AACZ,QAAI,WAAW,GAAG,EAAG,QAAO;AAC5B,UAAM,IAAI,SAAS,sBAAsB,qCAAqC,IAAI,KAAK;AAAA,MACrF,KAAK,6BAA6B,IAAI;AAAA,MACtC,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AACA,MAAI;AACJ,MAAI;AACF,WAAO,KAAK,MAAM,GAAG;AAAA,EACvB,SAAS,KAAK;AACZ,UAAM,IAAI,SAAS,sBAAsB,sBAAsB,IAAI,uBAAuB;AAAA,MACxF,KAAK,QAAQ,IAAI;AAAA,MACjB,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AACA,QAAM,SAAS,mBAAmB,UAAU,IAAI;AAChD,MAAI,CAAC,OAAO,SAAS;AACnB,UAAM,IAAI;AAAA,MACR;AAAA,MACA,sBAAsB,IAAI;AAAA,MAC1B;AAAA,QACE,KAAK,QAAQ,IAAI;AAAA,QACjB,SAAS,OAAO,MAAM;AAAA,MACxB;AAAA,IACF;AAAA,EACF;AACA,SAAO,OAAO;AAChB;AASA,eAAsB,kBAAkB,KAAa,QAAqC;AACxF,QAAM,YAAY,mBAAmB,MAAM,MAAM;AACjD,QAAM,OAAO,WAAW,GAAG;AAC3B,MAAI;AACF,UAAM,yBAAyB,MAAM,GAAG,KAAK,UAAU,WAAW,MAAM,CAAC,CAAC;AAAA,GAAM;AAAA,MAC9E,MAAM;AAAA,MACN,SAAS;AAAA,IACX,CAAC;AAAA,EACH,SAAS,KAAK;AACZ,QAAI,QAAQ,KAAK,QAAQ,GAAG;AAC1B,YAAM,IAAI,SAAS,iBAAiB,8BAA8B,IAAI,KAAK;AAAA,QACzE,KAAK,4DAA4D,IAAI,IAAI,IAAI;AAAA,QAC7E,OAAO;AAAA,MACT,CAAC;AAAA,IACH;AACA,UAAM;AAAA,EACR;AACF;AAEA,SAAS,WAAW,KAAuB;AACzC,SAAO,QAAQ,KAAK,QAAQ;AAC9B;AAEA,SAAS,QAAQ,KAAc,MAAuB;AACpD,SACE,OAAO,QAAQ,YACf,QAAQ,QACR,UAAU,OACT,IAA2B,SAAS;AAEzC;","names":[]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
9
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
10
|
+
}) : x)(function(x) {
|
|
11
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
12
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
13
|
+
});
|
|
14
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
15
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
16
|
+
};
|
|
17
|
+
var __export = (target, all) => {
|
|
18
|
+
for (var name in all)
|
|
19
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
20
|
+
};
|
|
21
|
+
var __copyProps = (to, from, except, desc) => {
|
|
22
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
|
+
for (let key of __getOwnPropNames(from))
|
|
24
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
25
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
26
|
+
}
|
|
27
|
+
return to;
|
|
28
|
+
};
|
|
29
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
30
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
31
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
32
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
33
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
34
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
35
|
+
mod
|
|
36
|
+
));
|
|
37
|
+
|
|
38
|
+
export {
|
|
39
|
+
__require,
|
|
40
|
+
__commonJS,
|
|
41
|
+
__export,
|
|
42
|
+
__toESM
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=chunk-3IMLRUZE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/cryptoNode.js
|
|
4
|
+
import * as nc from "crypto";
|
|
5
|
+
var crypto = nc && typeof nc === "object" && "webcrypto" in nc ? nc.webcrypto : nc && typeof nc === "object" && "randomBytes" in nc ? nc : void 0;
|
|
6
|
+
|
|
7
|
+
// node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/utils.js
|
|
8
|
+
function isBytes(a) {
|
|
9
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
10
|
+
}
|
|
11
|
+
function anumber(n) {
|
|
12
|
+
if (!Number.isSafeInteger(n) || n < 0)
|
|
13
|
+
throw new Error("positive integer expected, got " + n);
|
|
14
|
+
}
|
|
15
|
+
function abytes(b, ...lengths) {
|
|
16
|
+
if (!isBytes(b))
|
|
17
|
+
throw new Error("Uint8Array expected");
|
|
18
|
+
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
19
|
+
throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
|
|
20
|
+
}
|
|
21
|
+
function ahash(h) {
|
|
22
|
+
if (typeof h !== "function" || typeof h.create !== "function")
|
|
23
|
+
throw new Error("Hash should be wrapped by utils.createHasher");
|
|
24
|
+
anumber(h.outputLen);
|
|
25
|
+
anumber(h.blockLen);
|
|
26
|
+
}
|
|
27
|
+
function aexists(instance, checkFinished = true) {
|
|
28
|
+
if (instance.destroyed)
|
|
29
|
+
throw new Error("Hash instance has been destroyed");
|
|
30
|
+
if (checkFinished && instance.finished)
|
|
31
|
+
throw new Error("Hash#digest() has already been called");
|
|
32
|
+
}
|
|
33
|
+
function aoutput(out, instance) {
|
|
34
|
+
abytes(out);
|
|
35
|
+
const min = instance.outputLen;
|
|
36
|
+
if (out.length < min) {
|
|
37
|
+
throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function u32(arr) {
|
|
41
|
+
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
42
|
+
}
|
|
43
|
+
function clean(...arrays) {
|
|
44
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
45
|
+
arrays[i].fill(0);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function createView(arr) {
|
|
49
|
+
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
50
|
+
}
|
|
51
|
+
function rotr(word, shift) {
|
|
52
|
+
return word << 32 - shift | word >>> shift;
|
|
53
|
+
}
|
|
54
|
+
var isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
|
|
55
|
+
function byteSwap(word) {
|
|
56
|
+
return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
|
|
57
|
+
}
|
|
58
|
+
function byteSwap32(arr) {
|
|
59
|
+
for (let i = 0; i < arr.length; i++) {
|
|
60
|
+
arr[i] = byteSwap(arr[i]);
|
|
61
|
+
}
|
|
62
|
+
return arr;
|
|
63
|
+
}
|
|
64
|
+
var swap32IfBE = isLE ? (u) => u : byteSwap32;
|
|
65
|
+
function utf8ToBytes(str) {
|
|
66
|
+
if (typeof str !== "string")
|
|
67
|
+
throw new Error("string expected");
|
|
68
|
+
return new Uint8Array(new TextEncoder().encode(str));
|
|
69
|
+
}
|
|
70
|
+
function toBytes(data) {
|
|
71
|
+
if (typeof data === "string")
|
|
72
|
+
data = utf8ToBytes(data);
|
|
73
|
+
abytes(data);
|
|
74
|
+
return data;
|
|
75
|
+
}
|
|
76
|
+
function concatBytes(...arrays) {
|
|
77
|
+
let sum = 0;
|
|
78
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
79
|
+
const a = arrays[i];
|
|
80
|
+
abytes(a);
|
|
81
|
+
sum += a.length;
|
|
82
|
+
}
|
|
83
|
+
const res = new Uint8Array(sum);
|
|
84
|
+
for (let i = 0, pad = 0; i < arrays.length; i++) {
|
|
85
|
+
const a = arrays[i];
|
|
86
|
+
res.set(a, pad);
|
|
87
|
+
pad += a.length;
|
|
88
|
+
}
|
|
89
|
+
return res;
|
|
90
|
+
}
|
|
91
|
+
var Hash = class {
|
|
92
|
+
};
|
|
93
|
+
function createHasher(hashCons) {
|
|
94
|
+
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
|
95
|
+
const tmp = hashCons();
|
|
96
|
+
hashC.outputLen = tmp.outputLen;
|
|
97
|
+
hashC.blockLen = tmp.blockLen;
|
|
98
|
+
hashC.create = () => hashCons();
|
|
99
|
+
return hashC;
|
|
100
|
+
}
|
|
101
|
+
function randomBytes(bytesLength = 32) {
|
|
102
|
+
if (crypto && typeof crypto.getRandomValues === "function") {
|
|
103
|
+
return crypto.getRandomValues(new Uint8Array(bytesLength));
|
|
104
|
+
}
|
|
105
|
+
if (crypto && typeof crypto.randomBytes === "function") {
|
|
106
|
+
return Uint8Array.from(crypto.randomBytes(bytesLength));
|
|
107
|
+
}
|
|
108
|
+
throw new Error("crypto.getRandomValues must be defined");
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// node_modules/.pnpm/@noble+curves@1.9.1/node_modules/@noble/curves/esm/abstract/utils.js
|
|
112
|
+
var _0n = /* @__PURE__ */ BigInt(0);
|
|
113
|
+
var _1n = /* @__PURE__ */ BigInt(1);
|
|
114
|
+
function isBytes2(a) {
|
|
115
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
116
|
+
}
|
|
117
|
+
function abytes2(item) {
|
|
118
|
+
if (!isBytes2(item))
|
|
119
|
+
throw new Error("Uint8Array expected");
|
|
120
|
+
}
|
|
121
|
+
function abool(title, value) {
|
|
122
|
+
if (typeof value !== "boolean")
|
|
123
|
+
throw new Error(title + " boolean expected, got " + value);
|
|
124
|
+
}
|
|
125
|
+
function numberToHexUnpadded(num) {
|
|
126
|
+
const hex = num.toString(16);
|
|
127
|
+
return hex.length & 1 ? "0" + hex : hex;
|
|
128
|
+
}
|
|
129
|
+
function hexToNumber(hex) {
|
|
130
|
+
if (typeof hex !== "string")
|
|
131
|
+
throw new Error("hex string expected, got " + typeof hex);
|
|
132
|
+
return hex === "" ? _0n : BigInt("0x" + hex);
|
|
133
|
+
}
|
|
134
|
+
var hasHexBuiltin = (
|
|
135
|
+
// @ts-ignore
|
|
136
|
+
typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function"
|
|
137
|
+
);
|
|
138
|
+
var hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
|
139
|
+
function bytesToHex(bytes) {
|
|
140
|
+
abytes2(bytes);
|
|
141
|
+
if (hasHexBuiltin)
|
|
142
|
+
return bytes.toHex();
|
|
143
|
+
let hex = "";
|
|
144
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
145
|
+
hex += hexes[bytes[i]];
|
|
146
|
+
}
|
|
147
|
+
return hex;
|
|
148
|
+
}
|
|
149
|
+
var asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
150
|
+
function asciiToBase16(ch) {
|
|
151
|
+
if (ch >= asciis._0 && ch <= asciis._9)
|
|
152
|
+
return ch - asciis._0;
|
|
153
|
+
if (ch >= asciis.A && ch <= asciis.F)
|
|
154
|
+
return ch - (asciis.A - 10);
|
|
155
|
+
if (ch >= asciis.a && ch <= asciis.f)
|
|
156
|
+
return ch - (asciis.a - 10);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
function hexToBytes(hex) {
|
|
160
|
+
if (typeof hex !== "string")
|
|
161
|
+
throw new Error("hex string expected, got " + typeof hex);
|
|
162
|
+
if (hasHexBuiltin)
|
|
163
|
+
return Uint8Array.fromHex(hex);
|
|
164
|
+
const hl = hex.length;
|
|
165
|
+
const al = hl / 2;
|
|
166
|
+
if (hl % 2)
|
|
167
|
+
throw new Error("hex string expected, got unpadded hex of length " + hl);
|
|
168
|
+
const array = new Uint8Array(al);
|
|
169
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
170
|
+
const n1 = asciiToBase16(hex.charCodeAt(hi));
|
|
171
|
+
const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
|
|
172
|
+
if (n1 === void 0 || n2 === void 0) {
|
|
173
|
+
const char = hex[hi] + hex[hi + 1];
|
|
174
|
+
throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
|
175
|
+
}
|
|
176
|
+
array[ai] = n1 * 16 + n2;
|
|
177
|
+
}
|
|
178
|
+
return array;
|
|
179
|
+
}
|
|
180
|
+
function bytesToNumberBE(bytes) {
|
|
181
|
+
return hexToNumber(bytesToHex(bytes));
|
|
182
|
+
}
|
|
183
|
+
function bytesToNumberLE(bytes) {
|
|
184
|
+
abytes2(bytes);
|
|
185
|
+
return hexToNumber(bytesToHex(Uint8Array.from(bytes).reverse()));
|
|
186
|
+
}
|
|
187
|
+
function numberToBytesBE(n, len) {
|
|
188
|
+
return hexToBytes(n.toString(16).padStart(len * 2, "0"));
|
|
189
|
+
}
|
|
190
|
+
function numberToBytesLE(n, len) {
|
|
191
|
+
return numberToBytesBE(n, len).reverse();
|
|
192
|
+
}
|
|
193
|
+
function ensureBytes(title, hex, expectedLength) {
|
|
194
|
+
let res;
|
|
195
|
+
if (typeof hex === "string") {
|
|
196
|
+
try {
|
|
197
|
+
res = hexToBytes(hex);
|
|
198
|
+
} catch (e) {
|
|
199
|
+
throw new Error(title + " must be hex string or Uint8Array, cause: " + e);
|
|
200
|
+
}
|
|
201
|
+
} else if (isBytes2(hex)) {
|
|
202
|
+
res = Uint8Array.from(hex);
|
|
203
|
+
} else {
|
|
204
|
+
throw new Error(title + " must be hex string or Uint8Array");
|
|
205
|
+
}
|
|
206
|
+
const len = res.length;
|
|
207
|
+
if (typeof expectedLength === "number" && len !== expectedLength)
|
|
208
|
+
throw new Error(title + " of length " + expectedLength + " expected, got " + len);
|
|
209
|
+
return res;
|
|
210
|
+
}
|
|
211
|
+
function concatBytes2(...arrays) {
|
|
212
|
+
let sum = 0;
|
|
213
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
214
|
+
const a = arrays[i];
|
|
215
|
+
abytes2(a);
|
|
216
|
+
sum += a.length;
|
|
217
|
+
}
|
|
218
|
+
const res = new Uint8Array(sum);
|
|
219
|
+
for (let i = 0, pad = 0; i < arrays.length; i++) {
|
|
220
|
+
const a = arrays[i];
|
|
221
|
+
res.set(a, pad);
|
|
222
|
+
pad += a.length;
|
|
223
|
+
}
|
|
224
|
+
return res;
|
|
225
|
+
}
|
|
226
|
+
function utf8ToBytes2(str) {
|
|
227
|
+
if (typeof str !== "string")
|
|
228
|
+
throw new Error("string expected");
|
|
229
|
+
return new Uint8Array(new TextEncoder().encode(str));
|
|
230
|
+
}
|
|
231
|
+
var isPosBig = (n) => typeof n === "bigint" && _0n <= n;
|
|
232
|
+
function inRange(n, min, max) {
|
|
233
|
+
return isPosBig(n) && isPosBig(min) && isPosBig(max) && min <= n && n < max;
|
|
234
|
+
}
|
|
235
|
+
function aInRange(title, n, min, max) {
|
|
236
|
+
if (!inRange(n, min, max))
|
|
237
|
+
throw new Error("expected valid " + title + ": " + min + " <= n < " + max + ", got " + n);
|
|
238
|
+
}
|
|
239
|
+
function bitLen(n) {
|
|
240
|
+
let len;
|
|
241
|
+
for (len = 0; n > _0n; n >>= _1n, len += 1)
|
|
242
|
+
;
|
|
243
|
+
return len;
|
|
244
|
+
}
|
|
245
|
+
var bitMask = (n) => (_1n << BigInt(n)) - _1n;
|
|
246
|
+
var u8n = (len) => new Uint8Array(len);
|
|
247
|
+
var u8fr = (arr) => Uint8Array.from(arr);
|
|
248
|
+
function createHmacDrbg(hashLen, qByteLen, hmacFn) {
|
|
249
|
+
if (typeof hashLen !== "number" || hashLen < 2)
|
|
250
|
+
throw new Error("hashLen must be a number");
|
|
251
|
+
if (typeof qByteLen !== "number" || qByteLen < 2)
|
|
252
|
+
throw new Error("qByteLen must be a number");
|
|
253
|
+
if (typeof hmacFn !== "function")
|
|
254
|
+
throw new Error("hmacFn must be a function");
|
|
255
|
+
let v = u8n(hashLen);
|
|
256
|
+
let k = u8n(hashLen);
|
|
257
|
+
let i = 0;
|
|
258
|
+
const reset = () => {
|
|
259
|
+
v.fill(1);
|
|
260
|
+
k.fill(0);
|
|
261
|
+
i = 0;
|
|
262
|
+
};
|
|
263
|
+
const h = (...b) => hmacFn(k, v, ...b);
|
|
264
|
+
const reseed = (seed = u8n(0)) => {
|
|
265
|
+
k = h(u8fr([0]), seed);
|
|
266
|
+
v = h();
|
|
267
|
+
if (seed.length === 0)
|
|
268
|
+
return;
|
|
269
|
+
k = h(u8fr([1]), seed);
|
|
270
|
+
v = h();
|
|
271
|
+
};
|
|
272
|
+
const gen = () => {
|
|
273
|
+
if (i++ >= 1e3)
|
|
274
|
+
throw new Error("drbg: tried 1000 values");
|
|
275
|
+
let len = 0;
|
|
276
|
+
const out = [];
|
|
277
|
+
while (len < qByteLen) {
|
|
278
|
+
v = h();
|
|
279
|
+
const sl = v.slice();
|
|
280
|
+
out.push(sl);
|
|
281
|
+
len += v.length;
|
|
282
|
+
}
|
|
283
|
+
return concatBytes2(...out);
|
|
284
|
+
};
|
|
285
|
+
const genUntil = (seed, pred) => {
|
|
286
|
+
reset();
|
|
287
|
+
reseed(seed);
|
|
288
|
+
let res = void 0;
|
|
289
|
+
while (!(res = pred(gen())))
|
|
290
|
+
reseed();
|
|
291
|
+
reset();
|
|
292
|
+
return res;
|
|
293
|
+
};
|
|
294
|
+
return genUntil;
|
|
295
|
+
}
|
|
296
|
+
var validatorFns = {
|
|
297
|
+
bigint: (val) => typeof val === "bigint",
|
|
298
|
+
function: (val) => typeof val === "function",
|
|
299
|
+
boolean: (val) => typeof val === "boolean",
|
|
300
|
+
string: (val) => typeof val === "string",
|
|
301
|
+
stringOrUint8Array: (val) => typeof val === "string" || isBytes2(val),
|
|
302
|
+
isSafeInteger: (val) => Number.isSafeInteger(val),
|
|
303
|
+
array: (val) => Array.isArray(val),
|
|
304
|
+
field: (val, object) => object.Fp.isValid(val),
|
|
305
|
+
hash: (val) => typeof val === "function" && Number.isSafeInteger(val.outputLen)
|
|
306
|
+
};
|
|
307
|
+
function validateObject(object, validators, optValidators = {}) {
|
|
308
|
+
const checkField = (fieldName, type, isOptional) => {
|
|
309
|
+
const checkVal = validatorFns[type];
|
|
310
|
+
if (typeof checkVal !== "function")
|
|
311
|
+
throw new Error("invalid validator function");
|
|
312
|
+
const val = object[fieldName];
|
|
313
|
+
if (isOptional && val === void 0)
|
|
314
|
+
return;
|
|
315
|
+
if (!checkVal(val, object)) {
|
|
316
|
+
throw new Error("param " + String(fieldName) + " is invalid. Expected " + type + ", got " + val);
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
for (const [fieldName, type] of Object.entries(validators))
|
|
320
|
+
checkField(fieldName, type, false);
|
|
321
|
+
for (const [fieldName, type] of Object.entries(optValidators))
|
|
322
|
+
checkField(fieldName, type, true);
|
|
323
|
+
return object;
|
|
324
|
+
}
|
|
325
|
+
function memoized(fn) {
|
|
326
|
+
const map = /* @__PURE__ */ new WeakMap();
|
|
327
|
+
return (arg, ...args) => {
|
|
328
|
+
const val = map.get(arg);
|
|
329
|
+
if (val !== void 0)
|
|
330
|
+
return val;
|
|
331
|
+
const computed = fn(arg, ...args);
|
|
332
|
+
map.set(arg, computed);
|
|
333
|
+
return computed;
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/_u64.js
|
|
338
|
+
var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
339
|
+
var _32n = /* @__PURE__ */ BigInt(32);
|
|
340
|
+
function fromBig(n, le = false) {
|
|
341
|
+
if (le)
|
|
342
|
+
return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
|
|
343
|
+
return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
|
344
|
+
}
|
|
345
|
+
function split(lst, le = false) {
|
|
346
|
+
const len = lst.length;
|
|
347
|
+
let Ah = new Uint32Array(len);
|
|
348
|
+
let Al = new Uint32Array(len);
|
|
349
|
+
for (let i = 0; i < len; i++) {
|
|
350
|
+
const { h, l } = fromBig(lst[i], le);
|
|
351
|
+
[Ah[i], Al[i]] = [h, l];
|
|
352
|
+
}
|
|
353
|
+
return [Ah, Al];
|
|
354
|
+
}
|
|
355
|
+
var rotlSH = (h, l, s) => h << s | l >>> 32 - s;
|
|
356
|
+
var rotlSL = (h, l, s) => l << s | h >>> 32 - s;
|
|
357
|
+
var rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s;
|
|
358
|
+
var rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
|
|
359
|
+
|
|
360
|
+
export {
|
|
361
|
+
anumber,
|
|
362
|
+
abytes,
|
|
363
|
+
ahash,
|
|
364
|
+
aexists,
|
|
365
|
+
aoutput,
|
|
366
|
+
u32,
|
|
367
|
+
clean,
|
|
368
|
+
createView,
|
|
369
|
+
rotr,
|
|
370
|
+
swap32IfBE,
|
|
371
|
+
toBytes,
|
|
372
|
+
concatBytes,
|
|
373
|
+
Hash,
|
|
374
|
+
createHasher,
|
|
375
|
+
randomBytes,
|
|
376
|
+
isBytes2 as isBytes,
|
|
377
|
+
abytes2,
|
|
378
|
+
abool,
|
|
379
|
+
numberToHexUnpadded,
|
|
380
|
+
bytesToHex,
|
|
381
|
+
hexToBytes,
|
|
382
|
+
bytesToNumberBE,
|
|
383
|
+
bytesToNumberLE,
|
|
384
|
+
numberToBytesBE,
|
|
385
|
+
numberToBytesLE,
|
|
386
|
+
ensureBytes,
|
|
387
|
+
concatBytes2,
|
|
388
|
+
utf8ToBytes2 as utf8ToBytes,
|
|
389
|
+
inRange,
|
|
390
|
+
aInRange,
|
|
391
|
+
bitLen,
|
|
392
|
+
bitMask,
|
|
393
|
+
createHmacDrbg,
|
|
394
|
+
validateObject,
|
|
395
|
+
memoized,
|
|
396
|
+
split,
|
|
397
|
+
rotlSH,
|
|
398
|
+
rotlSL,
|
|
399
|
+
rotlBH,
|
|
400
|
+
rotlBL
|
|
401
|
+
};
|
|
402
|
+
/*! Bundled license information:
|
|
403
|
+
|
|
404
|
+
@noble/hashes/esm/utils.js:
|
|
405
|
+
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
406
|
+
|
|
407
|
+
@noble/curves/esm/abstract/utils.js:
|
|
408
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
409
|
+
*/
|
|
410
|
+
//# sourceMappingURL=chunk-CPUZRZ2A.js.map
|