caelum0x 07136e7b73 feat(near-hackathon): fold Ration's audit-anchor work into this repo as ONE combined NEAR submission
Owner directive (2026-11-11): submit a single project to the NEAR
Hackathon instead of two separate entries from the same person. Vendors
Ration's NEAR audit-anchor work (github.com/caelum0x/ration, commit
cff0ed3 + follow-ups) into ration-anchor/ as a first-class component:

- contracts-near/audit_anchor (NEAR Rust contract, 5/5 cargo tests
  green, target/ deleted)
- signer/ — a new, self-contained Go module (no dependency on Ration's
  other services or go.work) with the hand-rolled NEAR transaction
  signer + JSON-RPC client (cross-checked byte-for-byte against
  near-api-js) and the hash-chained audit ledger it anchors; 15/15 Go
  tests green (go test ./... -race)
- docs/ and media/ — Ration's original pitch deck, demo recordings, and
  submission checklist

Re-verified live via raw NEAR Testnet JSON-RPC this pass:
ration-anchor-286ca315f1.testnet still deployed and queryable, the
deliberate replay-rejection transaction still fails with nearcore's own
"sequence must strictly advance" panic — no redeploy needed.

Provenance notes added throughout (package doc comments, lib.rs header,
README) crediting the origin repo. README.md and HACKATHON.md rewritten
to tell one story: Cred402's SpendGuard enforces the protocol-level
spending limit, the vendored Audit Anchor proves the tamper-evident
spend history, both independently verifiable on NEAR Testnet. No mainnet
claims anywhere (see prior overclaim fix 524f2dd). cred402's own build
(npm run typecheck) and existing tests are untouched.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-11 15:32:24 +03:00

70 lines
2.4 KiB
Go

package nearanchor
import (
"fmt"
"os"
)
// defaultFunctionCallGas is 100 Tgas — nearcore's own convention for a
// single, simple contract call (the protocol-wide max per function
// call is 300 Tgas); commit_anchor/new are both small, O(1) methods, so
// this is comfortably more than either ever needs.
const defaultFunctionCallGas = 100_000_000_000_000
// Config holds everything the near-anchor CLI needs, read from the
// environment (RATION_NEAR_ANCHOR_* — matches every other Go service in
// this repo's env-var-based config convention, see
// services/audit-log/internal/config). None of these have safe
// defaults for SignerAccountID/SignerSecretKey/ContractID — Load
// returns an error rather than silently anchoring to nothing or signing
// with an empty key.
type Config struct {
RPCURL string
FaucetURL string
DataDir string
AuditLogPath string
ContractID string
SignerAccountID string
SignerSecretKey string
Gas uint64
}
// LoadForCommit reads the subset of config needed to read the local
// chain tip and submit it on-chain (near-anchor commit/verify) —
// ContractID, SignerAccountID and SignerSecretKey are required; the
// rest have the same sane defaults the rest of this repo already uses.
func LoadForCommit() (Config, error) {
cfg := Config{
RPCURL: getenvDefault("RATION_NEAR_ANCHOR_RPC_URL", DefaultRPCURL),
FaucetURL: getenvDefault("RATION_NEAR_ANCHOR_FAUCET_URL", DefaultFaucetURL),
DataDir: getenvDefault("RATION_AUDIT_LOG_DATA_DIR", "./data"),
ContractID: os.Getenv("RATION_NEAR_ANCHOR_CONTRACT_ID"),
SignerAccountID: os.Getenv("RATION_NEAR_ANCHOR_SIGNER_ACCOUNT_ID"),
SignerSecretKey: os.Getenv("RATION_NEAR_ANCHOR_SIGNER_SECRET_KEY"),
Gas: defaultFunctionCallGas,
}
cfg.AuditLogPath = os.Getenv("RATION_NEAR_ANCHOR_AUDIT_LOG_PATH")
var missing []string
if cfg.ContractID == "" {
missing = append(missing, "RATION_NEAR_ANCHOR_CONTRACT_ID")
}
if cfg.SignerAccountID == "" {
missing = append(missing, "RATION_NEAR_ANCHOR_SIGNER_ACCOUNT_ID")
}
if cfg.SignerSecretKey == "" {
missing = append(missing, "RATION_NEAR_ANCHOR_SIGNER_SECRET_KEY")
}
if len(missing) > 0 {
return Config{}, fmt.Errorf("nearanchor: missing required env var(s): %v", missing)
}
return cfg, nil
}
func getenvDefault(key, def string) string {
if v := os.Getenv(key); v != "" {
return v
}
return def
}