CodeSampleX

Пример

github.com/flynn/noise v1.0.0: DH25519

Проверенный пример — golang github.com/flynn/noise v1.0.0: DH25519. Контракт выполнен на go 1.26 · linux debian/x64 · docker и пройден.

sha256:cabda4d72f253faea939878a055a3e5389ccccc68113dc379174b787c0dc1190

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда linux 24 · ubuntu · glibc 2.39 x64 go

Среды запусков проверки

Окружение Контракт Этапы Запуск
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-04

Кейс

HOW
Цель
verify github.com/flynn/noise.DH25519 in pkg:golang/github.com/flynn/noise@v1.0.0
Пакеты
Символы
  • github.com/flynn/noise.DH25519
Создан
2026-09-04T05:10:45Z

Контракт

  1. noise.DH25519 reports DHName as "25519" and DHLen as 32
  2. noise.DH25519.GenerateKeypair creates a DHKey containing 32-byte private and public keys
  3. noise.DH25519.DH computes identical 32-byte shared secrets for both parties in a Diffie-Hellman exchange
  4. noise.DH25519 keypairs and cipher suite enable authenticated HandshakeXX exchange with encrypt and decrypt

Файлы

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

Скачать артефакт с исходным кодом (tar.gz)

Исходный код

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 github.com/flynn/noise.DH25519 in pkg:golang/github.com/flynn/noise@v1.0.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/flynn/noise@v1.0.0
Demonstrate these symbols/APIs:
  - github.com/flynn/noise.DH25519

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:3733c2da84f2735ff92f6cec043f552f28199d5785267ec4dbb888a42ff56fb2","contract":["noise.DH25519 reports DHName as \"25519\" and DHLen as 32","noise.DH25519.GenerateKeypair creates a DHKey containing 32-byte private and public keys","noise.DH25519.DH computes identical 32-byte shared secrets for both parties in a Diffie-Hellman exchange","noise.DH25519 keypairs and cipher suite enable authenticated HandshakeXX exchange with encrypt and decrypt"],"goal":"verify github.com/flynn/noise.DH25519 in pkg:golang/github.com/flynn/noise@v1.0.0","kind":"HOW","packages":["pkg:golang/github.com/flynn/noise@v1.0.0"],"schemaVersion":1,"symbols":["github.com/flynn/noise.DH25519"]},"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/github.com/flynn/noise@v1.0.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/flynn/noise@v1.0.0","symbols":["github.com/flynn/noise.DH25519"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.22.0

require github.com/flynn/noise v1.0.0

require (
	golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect
	golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect
)
go.sum
github.com/flynn/noise v1.0.0 h1:DlTHqmzmvcEiKj+4RYo/imoswx/4r6iBlCMfVtrMXpQ=
github.com/flynn/noise v1.0.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 h1:It14KIkyBFYkHkwZ7k45minvA9aorojkyjGk9KJ5B/w=
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
main.go
package main

import (
	"bytes"
	"crypto/rand"
	"fmt"
	"os"

	"github.com/flynn/noise"
)

func main() {
	dh := noise.DH25519
	fmt.Printf("Noise DH: %s (Key size: %d bytes)\n", dh.DHName(), dh.DHLen())

	aliceKey, err := dh.GenerateKeypair(rand.Reader)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to generate Alice keypair: %v\n", err)
		os.Exit(1)
	}

	bobKey, err := dh.GenerateKeypair(rand.Reader)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to generate Bob keypair: %v\n", err)
		os.Exit(1)
	}

	aliceShared, err := dh.DH(aliceKey.Private, bobKey.Public)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Alice DH failed: %v\n", err)
		os.Exit(1)
	}

	bobShared, err := dh.DH(bobKey.Private, aliceKey.Public)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Bob DH failed: %v\n", err)
		os.Exit(1)
	}

	if !bytes.Equal(aliceShared, bobShared) {
		fmt.Fprintf(os.Stderr, "Shared secret mismatch\n")
		os.Exit(1)
	}

	fmt.Println("DH25519 shared secret successfully agreed between parties")
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/flynn/noise.DH25519 in pkg:golang/github.com/flynn/noise@v1.0.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/flynn/noise@v1.0.0"
  ],
  "symbols": [
    "github.com/flynn/noise.DH25519"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"crypto/rand"
	"fmt"
	"os"

	"github.com/flynn/noise"
)

func main() {
	// Assertion 1: noise.DH25519 reports DHName as "25519" and DHLen as 32
	dh := noise.DH25519
	if dh.DHName() != "25519" {
		fmt.Fprintf(os.Stderr, "FAIL: DHName expected 25519, got %s\n", dh.DHName())
		os.Exit(1)
	}
	if dh.DHLen() != 32 {
		fmt.Fprintf(os.Stderr, "FAIL: DHLen expected 32, got %d\n", dh.DHLen())
		os.Exit(1)
	}

	// Assertion 2: noise.DH25519.GenerateKeypair creates a DHKey containing 32-byte private and public keys
	aliceKey, err := dh.GenerateKeypair(rand.Reader)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: GenerateKeypair(alice) failed: %v\n", err)
		os.Exit(1)
	}
	if len(aliceKey.Private) != 32 || len(aliceKey.Public) != 32 {
		fmt.Fprintf(os.Stderr, "FAIL: Alice key lengths invalid: priv=%d pub=%d\n", len(aliceKey.Private), len(aliceKey.Public))
		os.Exit(1)
	}

	bobKey, err := dh.GenerateKeypair(nil)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: GenerateKeypair(bob) failed: %v\n", err)
		os.Exit(1)
	}
	if len(bobKey.Private) != 32 || len(bobKey.Public) != 32 {
		fmt.Fprintf(os.Stderr, "FAIL: Bob key lengths invalid: priv=%d pub=%d\n", len(bobKey.Private), len(bobKey.Public))
		os.Exit(1)
	}

	if bytes.Equal(aliceKey.Public, bobKey.Public) {
		fmt.Fprintf(os.Stderr, "FAIL: Generated identical public keys for different keypairs\n")
		os.Exit(1)
	}

	// Assertion 3: noise.DH25519.DH computes identical 32-byte shared secrets for both parties in a Diffie-Hellman exchange
	aliceSecret, err := dh.DH(aliceKey.Private, bobKey.Public)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: Alice DH calculation failed: %v\n", err)
		os.Exit(1)
	}
	if len(aliceSecret) != 32 {
		fmt.Fprintf(os.Stderr, "FAIL: Alice shared secret length is %d, expected 32\n", len(aliceSecret))
		os.Exit(1)
	}

	bobSecret, err := dh.DH(bobKey.Private, aliceKey.Public)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: Bob DH calculation failed: %v\n", err)
		os.Exit(1)
	}

	if !bytes.Equal(aliceSecret, bobSecret) {
		fmt.Fprintf(os.Stderr, "FAIL: Shared secrets do not match between Alice and Bob\n")
		os.Exit(1)
	}

	// Assertion 4: noise.DH25519 keypairs and cipher suite enable authenticated HandshakeXX exchange with encrypt and decrypt
	cs := noise.NewCipherSuite(noise.DH25519, noise.CipherChaChaPoly, noise.HashSHA256)

	initHs, err := noise.NewHandshakeState(noise.Config{
		CipherSuite:   cs,
		Pattern:       noise.HandshakeXX,
		Initiator:     true,
		StaticKeypair: aliceKey,
	})
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: NewHandshakeState initiator failed: %v\n", err)
		os.Exit(1)
	}

	respHs, err := noise.NewHandshakeState(noise.Config{
		CipherSuite:   cs,
		Pattern:       noise.HandshakeXX,
		Initiator:     false,
		StaticKeypair: bobKey,
	})
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: NewHandshakeState responder failed: %v\n", err)
		os.Exit(1)
	}

	// XX Handshake message 1 (-> e)
	msg1, _, _, err := initHs.WriteMessage(nil, nil)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: initHs message 1 write failed: %v\n", err)
		os.Exit(1)
	}
	_, _, _, err = respHs.ReadMessage(nil, msg1)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: respHs message 1 read failed: %v\n", err)
		os.Exit(1)
	}

	// XX Handshake message 2 (<- e, ee, s, es)
	msg2, _, _, err := respHs.WriteMessage(nil, nil)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: respHs message 2 write failed: %v\n", err)
		os.Exit(1)
	}
	_, _, _, err = initHs.ReadMessage(nil, msg2)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: initHs message 2 read failed: %v\n", err)
		os.Exit(1)
	}

	// XX Handshake message 3 (-> s, se)
	msg3, initSend, initRecv, err := initHs.WriteMessage(nil, nil)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: initHs message 3 write failed: %v\n", err)
		os.Exit(1)
	}
	_, respRecv, respSend, err := respHs.ReadMessage(nil, msg3)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: respHs message 3 read failed: %v\n", err)
		os.Exit(1)
	}

	if initSend == nil || initRecv == nil || respSend == nil || respRecv == nil {
		fmt.Fprintf(os.Stderr, "FAIL: Handshake did not produce active CipherStates\n")
		os.Exit(1)
	}

	msg := []byte("authenticated payload using DH25519")
	ciphertext, err := initSend.Encrypt(nil, nil, msg)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: initSend.Encrypt failed: %v\n", err)
		os.Exit(1)
	}

	plaintext, err := respRecv.Decrypt(nil, nil, ciphertext)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: respRecv.Decrypt failed: %v\n", err)
		os.Exit(1)
	}

	if !bytes.Equal(plaintext, msg) {
		fmt.Fprintf(os.Stderr, "FAIL: decrypted plaintext does not match original\n")
		os.Exit(1)
	}

	fmt.Println("PASS: github.com/flynn/noise.DH25519 contract verified")
}

Исходный сидер

аноним