CodeSampleX

Exemple

go.step.sm/crypto v0.89.0

Échantillon vérifié pour golang go.step.sm/crypto v0.89.0. Le contrat s'est exécuté sur go 1.26 · linux debian/x64 · docker et a réussi.

sha256:9b05e91884ba176149ce62174fe0338c44460b19e6ad8e9cca6eedf41df431cb

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 go

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-09-02

Cas

HOW
Objectif
verify pkg:golang/go.step.sm/crypto@v0.89.0
Paquets
Créé
2026-09-02T21:40:10Z

Contrat

  1. fingerprint.New generates lowercase hex-encoded SHA-256 fingerprint for input data with HexFingerprint
  2. fingerprint.Fingerprint encodes precomputed digest using Base64Fingerprint with standard padding
  3. fingerprint.Fingerprint encodes precomputed digest using Base64URLFingerprint with URL-safe characters
  4. fingerprint.Fingerprint encodes precomputed digest using Base64RawFingerprint and Base64RawURLFingerprint without padding
  5. fingerprint.Fingerprint encodes precomputed digest into visual emoji representation using EmojiFingerprint
  6. fingerprint.New returns an error when an unavailable hash algorithm is requested
  7. fingerprint.New returns an error and fingerprint.Fingerprint returns empty string for unknown encoding values

Fichiers

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.go

Télécharger l’artefact source (tar.gz)

Code source

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify pkg:golang/go.step.sm/crypto@v0.89.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/go.step.sm/crypto@v0.89.0

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:b9d62eb8d8d6b98a5f477f29b6e0f294bbcefddcb05820a83c08f55745d4f8b0","contract":["fingerprint.New generates lowercase hex-encoded SHA-256 fingerprint for input data with HexFingerprint","fingerprint.Fingerprint encodes precomputed digest using Base64Fingerprint with standard padding","fingerprint.Fingerprint encodes precomputed digest using Base64URLFingerprint with URL-safe characters","fingerprint.Fingerprint encodes precomputed digest using Base64RawFingerprint and Base64RawURLFingerprint without padding","fingerprint.Fingerprint encodes precomputed digest into visual emoji representation using EmojiFingerprint","fingerprint.New returns an error when an unavailable hash algorithm is requested","fingerprint.New returns an error and fingerprint.Fingerprint returns empty string for unknown encoding values"],"goal":"verify pkg:golang/go.step.sm/crypto@v0.89.0","kind":"HOW","packages":["pkg:golang/go.step.sm/crypto@v0.89.0"],"schemaVersion":1},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/go.step.sm/crypto@v0.89.0"],"schemaVersion":1,"subject":"pkg:golang/go.step.sm/crypto@v0.89.0","verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require go.step.sm/crypto v0.89.0
go.sum
go.step.sm/crypto v0.89.0 h1:NPxryE+cZ4XDwXOQY2U6Gu+mOzOihuRLPIsX7WtPzZM=
go.step.sm/crypto v0.89.0/go.mod h1:IEgE6DndnYojbDyHU7eYXpwWzpu4ftkouw7nyI6jsxg=
main.go
package main

import (
	"crypto"
	_ "crypto/sha256"
	"fmt"
	"log"

	"go.step.sm/crypto/fingerprint"
)

func main() {
	certData := []byte("example-x509-certificate-payload")

	hexFP, err := fingerprint.New(certData, crypto.SHA256, fingerprint.HexFingerprint)
	if err != nil {
		log.Fatalf("failed to generate hex fingerprint: %v", err)
	}
	fmt.Printf("Hex Fingerprint: %s\n", hexFP)

	digest := []byte{
		0x38, 0x01, 0x16, 0x21, 0xec, 0xdc, 0xc2, 0x17,
		0x2e, 0x93, 0x3a, 0x1e, 0xf2, 0x31, 0x7e, 0xfc,
		0x53, 0x5a, 0x16, 0x1c, 0x00, 0x33, 0x3a, 0xee,
		0x3f, 0x84, 0xab, 0xfa, 0xb4, 0xe6, 0x40, 0xbf,
	}

	b64 := fingerprint.Fingerprint(digest, fingerprint.Base64Fingerprint)
	fmt.Printf("Base64: %s\n", b64)

	b64URL := fingerprint.Fingerprint(digest, fingerprint.Base64URLFingerprint)
	fmt.Printf("Base64URL: %s\n", b64URL)

	b64Raw := fingerprint.Fingerprint(digest, fingerprint.Base64RawFingerprint)
	fmt.Printf("Base64Raw: %s\n", b64Raw)

	b64RawURL := fingerprint.Fingerprint(digest, fingerprint.Base64RawURLFingerprint)
	fmt.Printf("Base64RawURL: %s\n", b64RawURL)

	emojiFP := fingerprint.Fingerprint(digest, fingerprint.EmojiFingerprint)
	fmt.Printf("Emoji Fingerprint: %s\n", emojiFP)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/go.step.sm/crypto@v0.89.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/go.step.sm/crypto@v0.89.0"
  ]
}
test/contract.go
package main

import (
	"crypto"
	_ "crypto/sha256"
	"fmt"
	"os"
	"strings"

	"go.step.sm/crypto/fingerprint"
)

func main() {
	if err := runContract(); err != nil {
		fmt.Fprintf(os.Stderr, "Contract verification failed: %v\n", err)
		os.Exit(1)
	}
	fmt.Println("All contract assertions passed.")
}

func runContract() error {
	sampleData := []byte("Lorem ipsum dolor sit amet")

	// Assertion 1: fingerprint.New generates lowercase hex-encoded SHA-256 fingerprint for input data with HexFingerprint
	hexFP, err := fingerprint.New(sampleData, crypto.SHA256, fingerprint.HexFingerprint)
	if err != nil {
		return fmt.Errorf("fingerprint.New(HexFingerprint) failed: %w", err)
	}
	expectedHex := "16aba5393ad72c0041f5600ad3c2c52ec437a2f0c7fc08fadfc3c0fe9641d7a3"
	if hexFP != expectedHex {
		return fmt.Errorf("hex fingerprint mismatch: got %q, want %q", hexFP, expectedHex)
	}
	if hexFP != strings.ToLower(hexFP) {
		return fmt.Errorf("hex fingerprint is not lowercase: %q", hexFP)
	}

	digest := []byte{
		0x38, 0x01, 0x16, 0x21, 0xec, 0xdc, 0xc2, 0x17,
		0x2e, 0x93, 0x3a, 0x1e, 0xf2, 0x31, 0x7e, 0xfc,
		0x53, 0x5a, 0x16, 0x1c, 0x00, 0x33, 0x3a, 0xee,
		0x3f, 0x84, 0xab, 0xfa, 0xb4, 0xe6, 0x40, 0xbf,
	}

	// Assertion 2: fingerprint.Fingerprint encodes precomputed digest using Base64Fingerprint with standard padding
	b64 := fingerprint.Fingerprint(digest, fingerprint.Base64Fingerprint)
	expectedB64 := "OAEWIezcwhcukzoe8jF+/FNaFhwAMzruP4Sr+rTmQL8="
	if b64 != expectedB64 {
		return fmt.Errorf("Base64Fingerprint mismatch: got %q, want %q", b64, expectedB64)
	}

	// Assertion 3: fingerprint.Fingerprint encodes precomputed digest using Base64URLFingerprint with URL-safe characters
	b64URL := fingerprint.Fingerprint(digest, fingerprint.Base64URLFingerprint)
	expectedB64URL := "OAEWIezcwhcukzoe8jF-_FNaFhwAMzruP4Sr-rTmQL8="
	if b64URL != expectedB64URL {
		return fmt.Errorf("Base64URLFingerprint mismatch: got %q, want %q", b64URL, expectedB64URL)
	}

	// Assertion 4: fingerprint.Fingerprint encodes precomputed digest using Base64RawFingerprint and Base64RawURLFingerprint without padding
	b64Raw := fingerprint.Fingerprint(digest, fingerprint.Base64RawFingerprint)
	expectedB64Raw := "OAEWIezcwhcukzoe8jF+/FNaFhwAMzruP4Sr+rTmQL8"
	if b64Raw != expectedB64Raw {
		return fmt.Errorf("Base64RawFingerprint mismatch: got %q, want %q", b64Raw, expectedB64Raw)
	}
	if strings.HasSuffix(b64Raw, "=") {
		return fmt.Errorf("Base64RawFingerprint should not have padding: %q", b64Raw)
	}

	b64RawURL := fingerprint.Fingerprint(digest, fingerprint.Base64RawURLFingerprint)
	expectedB64RawURL := "OAEWIezcwhcukzoe8jF-_FNaFhwAMzruP4Sr-rTmQL8"
	if b64RawURL != expectedB64RawURL {
		return fmt.Errorf("Base64RawURLFingerprint mismatch: got %q, want %q", b64RawURL, expectedB64RawURL)
	}
	if strings.HasSuffix(b64RawURL, "=") {
		return fmt.Errorf("Base64RawURLFingerprint should not have padding: %q", b64RawURL)
	}

	// Assertion 5: fingerprint.Fingerprint encodes precomputed digest into visual emoji representation using EmojiFingerprint
	emojiFP := fingerprint.Fingerprint(digest, fingerprint.EmojiFingerprint)
	expectedEmoji := "💨🎱🌼📆🎠🎉🎿🚙🍪🌊♦️💡✌️🐮🔒❌🖕😬🌼👦👍👑♦️🇬🇧👂🔬📌♿🚀🚜🍆🐑"
	if emojiFP != expectedEmoji {
		return fmt.Errorf("EmojiFingerprint mismatch: got %q, want %q", emojiFP, expectedEmoji)
	}

	// Assertion 6: fingerprint.New returns an error when an unavailable hash algorithm is requested
	unavailableHash := crypto.Hash(9999)
	if _, err := fingerprint.New(sampleData, unavailableHash, fingerprint.HexFingerprint); err == nil {
		return fmt.Errorf("fingerprint.New should return error for unavailable hash algorithm")
	}

	// Assertion 7: fingerprint.New returns an error and fingerprint.Fingerprint returns empty string for unknown encoding values
	unknownEncoding := fingerprint.Encoding(9999)
	if _, err := fingerprint.New(sampleData, crypto.SHA256, unknownEncoding); err == nil {
		return fmt.Errorf("fingerprint.New should return error for unknown encoding")
	}
	if got := fingerprint.Fingerprint(digest, unknownEncoding); got != "" {
		return fmt.Errorf("fingerprint.Fingerprint should return empty string for unknown encoding, got %q", got)
	}

	return nil
}

Seeder d'origine

anonyme