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

54 lines
1.7 KiB
Go

package nearanchor
import "testing"
// TestParseSecretKeyMatchesNearAPIJS cross-checks ParseSecretKey's
// derived public key against a real keypair generated by near-api-js
// (`KeyPair.fromRandom('ed25519')` in
// ~/products/blockhain/cred402/node_modules/near-api-js — a separate,
// unrelated repo, used here only as a reference oracle) — proof this
// package decodes NEAR's "ed25519:<base58 seed+pubkey>" secret key
// format exactly the way the official SDK does, not just a format this
// package invented and agrees with itself about.
func TestParseSecretKeyMatchesNearAPIJS(t *testing.T) {
const secret = "ed25519:29YzhBfbdfUNwxPCeCx3CjGjLDMS9gQkGJDTkk5xayJJmGGeXwKmRGzNofjjqB3kwbjdfGCtDr4hkAtNq7oVCkdN"
const wantPublic = "ed25519:9DkDC24MnA2XKkALp8CsGYQ7cPA3N5ghig9tGeMeSR68"
_, public, err := ParseSecretKey(secret)
if err != nil {
t.Fatalf("ParseSecretKey: %v", err)
}
if public != wantPublic {
t.Fatalf("derived public key = %q, want %q", public, wantPublic)
}
}
func TestGenerateKeyPairRoundTrips(t *testing.T) {
secret, public, err := GenerateKeyPair()
if err != nil {
t.Fatalf("GenerateKeyPair: %v", err)
}
_, derivedPublic, err := ParseSecretKey(secret)
if err != nil {
t.Fatalf("ParseSecretKey on freshly generated key: %v", err)
}
if derivedPublic != public {
t.Fatalf("GenerateKeyPair's own public key %q does not match ParseSecretKey's derived public key %q", public, derivedPublic)
}
}
func TestParseSecretKeyRejectsBadInput(t *testing.T) {
cases := []string{
"",
"not-a-key",
"secp256k1:abc",
"ed25519:", // empty payload decodes to 0 bytes, not 64
}
for _, c := range cases {
if _, _, err := ParseSecretKey(c); err == nil {
t.Errorf("ParseSecretKey(%q) succeeded, want error", c)
}
}
}