UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

1 lines • 24.4 kB
{"version":3,"file":"near-signer.cjs","names":["isPrivateKey","NearTransactionError","FileKeyStore","isNearCliInstalled","Near","executeKeychainTransaction","parseKey"],"sources":["../../../src/services/auth/near-signer.ts"],"sourcesContent":["import { isPrivateKey, Near, type PrivateKey, parseKey } from \"near-kit\";\nimport { FileKeyStore } from \"near-kit/keys/file\";\nimport type { TxStatus } from \"../registry/confirm\";\nimport type { NetworkId } from \"../registry/fastkv\";\nimport { executeKeychainTransaction, isNearCliInstalled, NearTransactionError } from \"./near-cli\";\n\nexport type SigningKeySource = \"provided\" | \"credentials-file\";\n\nexport interface ResolvedSigningKey {\n source: SigningKeySource;\n privateKey: string;\n}\n\nexport interface RegistryWriteRequest {\n account: string;\n contract: string;\n method: string;\n args: Record<string, string>;\n network: NetworkId;\n privateKey?: string;\n}\n\nexport type SigningStrategy =\n | { strategy: \"near-kit\"; privateKey: string; source: SigningKeySource }\n | { strategy: \"near-cli-keychain\" };\n\nexport interface NearTransactionResult {\n success: true;\n txHash?: string;\n signedWith: \"env\" | \"credentials-file\" | \"near-cli-keychain\";\n}\n\n/** near-kit's default mainnet RPC (free.rpc.fastnear.com) accepts signed\n * broadcasts via send_tx and silently drops them post-acceptance (2026-11-04:\n * every publish broadcast since 02:42 died UNKNOWN_TRANSACTION while the same\n * endpoint served fresh nonce views, from CI runners and local machines\n * alike). NEAR_RPC_URL pins the signing stack to an endpoint with a real\n * transaction pool — set it to https://rpc.mainnet.near.org. Mirrors the\n * auth plugin's dev-wiring convention (plugins/auth/plugin.dev.ts). */\nexport function resolveNearRpcUrl(): string | undefined {\n return process.env.NEAR_RPC_URL || undefined;\n}\n\nfunction assertPrivateKey(key: string): PrivateKey {\n if (!isPrivateKey(key)) {\n throw new NearTransactionError(\n `Invalid private key format: must start with \"ed25519:\" or \"secp256k1:\" (got a ${key.length}-character value).`,\n );\n }\n return key as PrivateKey;\n}\n\nexport async function resolveSigningKey(opts: {\n privateKey?: string;\n account: string;\n network: NetworkId;\n}): Promise<ResolvedSigningKey> {\n const explicitKey =\n opts.privateKey || process.env.NEAR_PRIVATE_KEY || process.env.BOS_NEAR_PRIVATE_KEY;\n if (explicitKey) {\n return { source: \"provided\", privateKey: explicitKey };\n }\n\n const keyStore = new FileKeyStore(\"~/.near-credentials\", opts.network);\n const keyPair = await keyStore.get(opts.account);\n if (keyPair?.secretKey) {\n return { source: \"credentials-file\", privateKey: keyPair.secretKey };\n }\n\n throw new NearTransactionError(\"No signing key available\");\n}\n\nexport async function resolveSigningStrategy(opts: {\n privateKey?: string;\n account: string;\n network: NetworkId;\n}): Promise<SigningStrategy> {\n try {\n const resolved = await resolveSigningKey(opts);\n return { strategy: \"near-kit\", privateKey: resolved.privateKey, source: resolved.source };\n } catch {\n // fall through to the near-cli-rs keychain\n }\n\n if (process.stdin.isTTY && (await isNearCliInstalled())) {\n return { strategy: \"near-cli-keychain\" };\n }\n\n throw new NearTransactionError(\n `No signing key available for ${opts.account} on ${opts.network}. ` +\n `Set NEAR_PRIVATE_KEY (or BOS_NEAR_PRIVATE_KEY), store credentials at ` +\n `~/.near-credentials/${opts.network}/${opts.account}.json, or sign with the ` +\n `near-cli-rs keychain (install it, then retry from an interactive terminal). ` +\n `Generate a publish key with: bos login --key`,\n );\n}\n\nexport function describeSigningStrategy(strategy: SigningStrategy): string {\n if (strategy.strategy === \"near-cli-keychain\") {\n return \"near-cli-rs keychain\";\n }\n return strategy.source === \"provided\"\n ? \"the environment or --private-key flag\"\n : `~/.near-credentials`;\n}\n\n/** The gas one registry write attaches. A FastKV publish targets the codeless\n * namespace account — it executes as CodeDoesNotExist (the designed success\n * state) and burns almost nothing, so 30 Tgas is generous. The previous 300\n * Tgas inflated the prepayment lock to ~0.30 NEAR and pushed under-funded\n * accounts into silent broadcast drops (2026-11-04 outage: NotEnoughBalance\n * surfaced as \"dropped at broadcast\" on every deploy for 14 hours). */\nexport const PUBLISH_ATTACHED_GAS = \"30 Tgas\";\nexport const PUBLISH_ATTACHED_GAS_UNITS = 30_000_000_000_000n;\n\n/** Admission prices the prepayment at the shard's worst-case gas price, so\n * the publish account must hold attached_gas × gas_price — not burn it. A 2×\n * safety margin covers intra-epoch price adjustment; the head-block\n * `gas_price` under-reports it (observed 2026-11-04: admission priced at\n * ~1.003 nanoNEAR/gas while the head RPC reported 1e8 yoctoNEAR/gas). */\nconst PUBLISH_BALANCE_SAFETY = 2n;\nconst PUBLISH_BALANCE_LOW_HEADROOM = 3n;\n\nasync function submitWithNearKit(\n tx: RegistryWriteRequest,\n privateKey: string,\n): Promise<NearTransactionResult> {\n const near = new Near({\n network: tx.network,\n defaultSignerId: tx.account,\n privateKey: assertPrivateKey(privateKey),\n rpcUrl: resolveNearRpcUrl(),\n });\n\n let outcome: Awaited<\n ReturnType<ReturnType<ReturnType<Near[\"transaction\"]>[\"functionCall\"]>[\"send\"]>\n >;\n // The builder caches the signed transaction, so its hash survives even when\n // send() throws on the designed execution failure below.\n const pending = near.transaction(tx.account).functionCall(tx.contract, tx.method, tx.args, {\n gas: PUBLISH_ATTACHED_GAS,\n attachedDeposit: \"0 yocto\",\n });\n let txHash: string | undefined;\n try {\n // EXECUTED_OPTIMISTIC waits for the pool's verdict instead of accepting\n // the hash fire-and-forget: admission rejections (NotEnoughBalance,\n // stale nonce, missing key) surface here with their real reason, never\n // as a silent broadcast the confirm loop can only call \"dropped\".\n outcome = await pending.send({ waitUntil: \"EXECUTED_OPTIMISTIC\" });\n txHash = outcome?.transaction?.hash;\n } catch (error) {\n if (error instanceof Error && DESIGNED_EXECUTION_FAILURE.test(error.name)) {\n // The codeless namespace executes every publish as CodeDoesNotExist —\n // that is the designed success state (ADR 0001, action-indexed writes).\n txHash ??= (error as { transaction?: { hash?: string } }).transaction?.hash;\n txHash ??=\n typeof pending.getHash === \"function\" ? (pending.getHash() ?? undefined) : undefined;\n return { success: true, txHash, signedWith: \"env\" };\n }\n const rejection = describePublishRejection(error, tx.account);\n if (rejection) throw new NearTransactionError(rejection);\n throw error;\n }\n\n return { success: true, txHash, signedWith: \"env\" };\n}\n\nexport async function submitRegistryWrite(\n tx: RegistryWriteRequest,\n strategy?: SigningStrategy,\n): Promise<NearTransactionResult> {\n const resolved = strategy ?? (await resolveSigningStrategy(tx));\n\n if (resolved.strategy === \"near-cli-keychain\") {\n const result = await executeKeychainTransaction({\n account: tx.account,\n contract: tx.contract,\n method: tx.method,\n args: tx.args,\n network: tx.network,\n });\n return { ...result, signedWith: \"near-cli-keychain\" };\n }\n\n return submitWithNearKit(tx, resolved.privateKey);\n}\n\n/** Classify a broadcast transaction for the publish-confirmation machine.\n * The wait level is NONE — one cheap RPC read of the current state, never a\n * wait-for-inclusion poll (the confirmation loop paces itself). The registry\n * namespace account is codeless: publishes execute with CodeDoesNotExist and\n * that is the designed success state, so a failed execution reads as\n * `included` — only a transaction the chain has never seen (`unknown`), a\n * consumed nonce or a missing publish key (`invalid`), or an unusable probe\n * (`unreachable`, informative-only) classify differently. Discrimination goes\n * through near-kit's `error.name` (every class sets it; the classes are not\n * re-exported from the package root). */\nexport async function classifyTransactionOutcome(\n txHash: string,\n accountId: string,\n network: NetworkId,\n): Promise<TxStatus> {\n const near = new Near({ network, defaultSignerId: accountId, rpcUrl: resolveNearRpcUrl() });\n try {\n await near.getTransactionStatus(txHash, accountId, \"NONE\");\n return \"included\";\n } catch (error) {\n if (!(error instanceof Error)) return \"unreachable\";\n const congested =\n error.name === \"InvalidTransactionError\" &&\n (Boolean((error as { shardCongested?: boolean }).shardCongested) ||\n Boolean((error as { shardStuck?: boolean }).shardStuck));\n switch (error.name) {\n case \"ContractNotDeployedError\":\n case \"FunctionCallError\":\n case \"ContractExecutionError\":\n case \"InvalidTransactionError\":\n return congested ? \"unknown\" : \"included\";\n case \"InvalidNonceError\":\n case \"AccessKeyDoesNotExistError\":\n case \"AccountDoesNotExistError\":\n return \"invalid\";\n case \"NetworkError\":\n return /not found|unknown/i.test(error.message) ? \"unknown\" : \"unreachable\";\n default:\n return \"unreachable\";\n }\n }\n}\n\n/** One publish prepays 30 Tgas; the floor covers a full-price (1e9 yoctoNEAR\n * per gas unit) inclusion burn of a failed execution. */\nconst MIN_PUBLISH_ALLOWANCE_YOCTO = 30_000_000_000_000_000_000_000n;\n\nexport interface PublishKeyHealth {\n ok: boolean;\n warning?: string;\n error?: string;\n}\n\ninterface ScopedAccessKeyPermission {\n receiver_id: string;\n method_names: string[];\n allowance?: string | null;\n balance?: string;\n}\n\n/** Verify the signing key exists on the publisher account and is scoped to\n * exactly what a publish calls (`__fastdata_kv` on the registry namespace)\n * before the build train runs — a rotated or exhausted key otherwise surfaces\n * only as an UNKNOWN_TRANSACTION broadcast that never appears on-chain. Probe\n * failures are soft: an unreachable registry RPC must not block an\n * otherwise-valid publish. */\nexport async function checkPublishKeyHealth(input: {\n account: string;\n contract: string;\n privateKey: string;\n network: NetworkId;\n}): Promise<PublishKeyHealth> {\n const near = new Near({\n network: input.network,\n defaultSignerId: input.account,\n rpcUrl: resolveNearRpcUrl(),\n });\n const publicKey = parseKey(input.privateKey).publicKey.toString();\n let view: Awaited<ReturnType<Near[\"getAccessKey\"]>>;\n try {\n view = await near.getAccessKey(input.account, publicKey);\n } catch (error) {\n if (!(error instanceof Error)) {\n return { ok: true, warning: \"key health check skipped (registry RPC unreachable)\" };\n }\n if (error.name === \"AccountDoesNotExistError\") {\n return {\n ok: false,\n error: `publisher account ${input.account} does not exist on ${input.network}`,\n };\n }\n if (error.name === \"AccessKeyDoesNotExistError\") {\n return {\n ok: false,\n error: publishKeyRepairHint(input.account, input.contract, publicKey),\n };\n }\n return { ok: true, warning: \"key health check skipped (registry RPC unreachable)\" };\n }\n if (!view) {\n return { ok: false, error: publishKeyRepairHint(input.account, input.contract, publicKey) };\n }\n const permission = view.permission as\n | \"FullAccess\"\n | { FunctionCall?: ScopedAccessKeyPermission; GasKeyFunctionCall?: ScopedAccessKeyPermission };\n if (typeof permission !== \"object\") {\n return { ok: true };\n }\n const isGasKey = \"GasKeyFunctionCall\" in permission;\n const scoped = isGasKey ? permission.GasKeyFunctionCall : permission.FunctionCall;\n if (!scoped) {\n return { ok: true };\n }\n const kind = isGasKey ? \"gas key\" : \"publish key\";\n if (scoped.receiver_id !== input.contract) {\n return {\n ok: false,\n error:\n `the signing ${kind} is scoped to receiver ${scoped.receiver_id}, but publishes call ` +\n `${input.contract} — ${publishKeyRepairHint(input.account, input.contract, publicKey)}`,\n };\n }\n if (scoped.method_names.length > 0 && !scoped.method_names.includes(\"__fastdata_kv\")) {\n return {\n ok: false,\n error:\n `the signing ${kind} is scoped to methods [${scoped.method_names.join(\", \")}], but ` +\n `publishes call \\`__fastdata_kv\\` — ${publishKeyRepairHint(input.account, input.contract, publicKey)}`,\n };\n }\n const capped = scoped.allowance ?? scoped.balance;\n if (capped && BigInt(capped) < MIN_PUBLISH_ALLOWANCE_YOCTO) {\n return {\n ok: false,\n error:\n `the signing ${kind}'s remaining ${isGasKey ? \"balance\" : \"allowance\"} (${capped} ` +\n `yoctoNEAR) is below one publish's prepaid gas (~${MIN_PUBLISH_ALLOWANCE_YOCTO} ` +\n \"yoctoNEAR) — re-add the key without an allowance cap\",\n };\n }\n return { ok: true };\n}\n\n/** Execution failures whose name marks the designed CodeDoesNotExist success\n * (the registry namespace account is codeless). Everything else with the\n * InvalidTxError wire shape is a real admission rejection. */\nconst DESIGNED_EXECUTION_FAILURE =\n /^(ContractNotDeployedError|FunctionCallError|ContractExecutionError)$/;\n\n/** Turn a near-kit admission rejection into a human reason, or null when the\n * error is not one (execution outcomes are designed success; congestion means\n * the tx lands later). Discriminates on the `InvalidTxError` wire shape the\n * RPC returns for pre-inclusion rejections — e.g. the 2026-11-04 outage where\n * `NotEnoughBalance` surfaced only as \"dropped at broadcast\". */\nexport function describePublishRejection(error: unknown, account: string): string | null {\n if (!(error instanceof Error) || error.name !== \"InvalidTransactionError\") return null;\n const congested =\n Boolean((error as { shardCongested?: boolean }).shardCongested) ||\n Boolean((error as { shardStuck?: boolean }).shardStuck);\n if (congested) return null;\n const invalidTx = (error as { data?: { InvalidTxError?: Record<string, unknown> } }).data\n ?.InvalidTxError;\n if (!invalidTx) return null;\n if (invalidTx.NotEnoughBalance) {\n const { balance, cost } = invalidTx.NotEnoughBalance as { balance: string; cost: string };\n try {\n return (\n `the publish account ${account} holds ${formatNearAmount(BigInt(balance))} NEAR but ` +\n `this publish needs ${formatNearAmount(BigInt(cost))} NEAR to prepay its gas — ` +\n `top up the account`\n );\n } catch {\n return `the publish account ${account} cannot cover this publish's gas prepayment — top up the account`;\n }\n }\n if (invalidTx.InvalidNonce) {\n return `stale nonce — another publish signed with this key in the same window; resubmit`;\n }\n if (invalidTx.AccessKeyDoesNotExist || invalidTx.InvalidSignerKey) {\n return `the signing key is not an access key on ${account} — re-mint with \\`bos login --key\\``;\n }\n if (invalidTx.Expired) {\n return `the transaction's block reference expired before inclusion — resubmit`;\n }\n return `the transaction was rejected at admission: ${JSON.stringify(invalidTx)}`;\n}\n\n/** Format a yoctoNEAR bigint for humans — integer part plus up to 6 decimals,\n * trailing zeros trimmed (0.0000284 stays honest; 300000000000000000000000\n * reads as \"0.3\"). */\nexport function formatNearAmount(yocto: bigint): string {\n const whole = yocto / 10n ** 24n;\n const frac = (yocto % 10n ** 24n).toString().padStart(24, \"0\").slice(0, 6).replace(/0+$/, \"\");\n return frac ? `${whole}.${frac}` : `${whole}`;\n}\n\n/** The admission bound: balance must cover attached gas at the (worst-case)\n * gas price — the burn is nearly zero, the prepayment lock is not. */\nexport function classifyPublishBalance(\n balance: bigint,\n required: bigint,\n): { ok: boolean; low: boolean } {\n const ok = balance >= required;\n return { ok, low: ok && balance < required * PUBLISH_BALANCE_LOW_HEADROOM };\n}\n\nexport interface PublishBalanceHealth {\n ok: boolean;\n warning?: string;\n error?: string;\n}\n\n/** Check the publish account can actually prepay its gas before the build\n * train runs — a balance a hair under the prepayment lock surfaces only as a\n * silent broadcast drop otherwise (the 2026-11-04 outage: 0.30089 NEAR held,\n * 0.30092 NEAR required, every deploy dead for 14 hours). Soft-skips when the\n * registry RPC is unreachable, like the key health check. */\nexport async function checkPublishBalance(input: {\n account: string;\n network: NetworkId;\n}): Promise<PublishBalanceHealth> {\n const near = new Near({\n network: input.network,\n defaultSignerId: input.account,\n rpcUrl: resolveNearRpcUrl(),\n });\n let balance: bigint;\n let minGasPrice: bigint;\n try {\n const [view, config] = await Promise.all([\n near.getBalance(input.account),\n near.rpc.call(\"EXPERIMENTAL_protocol_config\", { finality: \"final\" }) as Promise<{\n min_gas_price: string;\n }>,\n ]);\n balance = BigInt(view);\n minGasPrice = BigInt(config.min_gas_price);\n } catch {\n return { ok: true, warning: \"balance check skipped (registry RPC unreachable)\" };\n }\n const required = PUBLISH_ATTACHED_GAS_UNITS * minGasPrice * PUBLISH_BALANCE_SAFETY;\n const classified = classifyPublishBalance(balance, required);\n if (!classified.ok) {\n return {\n ok: false,\n error:\n `the publish account ${input.account} holds ${formatNearAmount(balance)} NEAR but ` +\n `prepaying ${PUBLISH_ATTACHED_GAS} at the current gas price needs ` +\n `${formatNearAmount(required)} NEAR — top up the account`,\n };\n }\n if (classified.low) {\n return {\n ok: true,\n warning:\n `publish account ${input.account} is low: ${formatNearAmount(balance)} NEAR ` +\n `(one publish locks ~${formatNearAmount(required)} NEAR) — top up soon`,\n };\n }\n return { ok: true };\n}\n\nfunction publishKeyRepairHint(account: string, contract: string, publicKey: string): string {\n return (\n `the signing key ${publicKey} is not a publish key on ${account}. Fix on-chain, then re-run: ` +\n `\\`near account add-key ${account} ${publicKey} --receiver-id ${contract} ` +\n '--method-names __fastdata_kv network-config mainnet\" ' +\n \"signed by any existing full-access signer, or re-mint with `bos login --key` and update NEAR_PRIVATE_KEY\"\n );\n}\n"],"mappings":";;;;;;;;;;;;AAuCA,SAAgB,oBAAwC;CACtD,OAAO,QAAQ,IAAI,gBAAgB;AACrC;AAEA,SAAS,iBAAiB,KAAyB;CACjD,IAAI,KAACA,uBAAa,GAAG,GACnB,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