caelum0x cff0ed3129 feat(near-hackathon): anchor audit-log's hash-chain tip to NEAR Testnet
Adds a focused NEAR Hackathon 2026 entry built on Ration's existing,
real audit-log service rather than a Ration-on-NEAR rewrite: a minimal
NEAR smart contract (contracts-near/audit_anchor) storing/verifying
{tenant_id, chain_tip_hash, sequence, occurred_at_unix}, plus a
from-scratch Go NEAR transaction signer and CLI
(services/audit-log/internal/nearanchor, cmd/near-anchor) that reads
audit-log's real local chain tip and anchors it on-chain.

Verified live on NEAR Testnet (account ration-anchor-286ca315f1.testnet):
contract deployed and code_hash-matched, two successful on-chain
anchors, one deliberate replay correctly rejected by nearcore's own
sequence guard, and a real (non-mocked) Go integration test passing
against the live contract. Transaction encoding cross-checked
byte-for-byte against near-api-js. Zero regressions in existing Go/Rust
suites. Full detail and every tx hash in docs/near-hackathon/.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-11-09 14:19:33 +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)
}
}
}