t27.aiEnglish

Ключ это пара

Вы узнаете

Почему у ключа две половины, какую из них можно отдавать и какая никогда не покидает ваш компьютер.

Чтобы доказать хосту кода, кто вы, без пароля, делают пару ключей: публичную половину, которую раздают, и приватную, которая никогда не покидает ваш компьютер. Хост хранит публичную половину и присылает вызов, на который может ответить только приватная. В key_pair.t27 у пары 2 половины, 1 общая и 1 хранится у вас, и 0 копий приватной половины уходят на хост, в чат или в репозиторий. Текст ключа в спецификации выдуманная заглушка, а не ключ. Никогда не вставляйте настоящую приватную половину в запрос: агент, который её увидел, ею владеет.

Попробуйте

В виджете найдите половину, которую можно вставить на хост, и половину, которая не идёт никуда; затем в окне спецификации подложите PRIVATE_COPIES_SENT = 1 и прочитайте, какой тест покраснеет.

Открыть интерактивный урок →

A key is a pair ↗

The two halves of a key pair: the public half you hand out and the private half that never leaves your machine, with a made-up placeholder in place of a real key. Lesson 9 of the course Vibecoding from zero with t27.

specs/vibecoding/key_pair.t27

// SPDX-License-Identifier: Apache-2.0
; specs/vibecoding/key_pair.t27 -- lesson "A key is a pair" of the course "Vibecoding from zero with t27"
; To prove who you are to a code host without typing a password, you make a key pair: a public half
; you hand out freely and a private half that never leaves your machine. The host keeps the public
; half; only the owner of the private half can answer its challenge. The text below is a made-up
; placeholder, not a key: no real key or token is ever written into a spec, a prompt or a repository.
; ASCII only, English only.

module vibecoding_key_pair;

pub const PLACEHOLDER_PUBLIC : str = "EXAMPLE-PUBLIC-KEY-NOT-REAL";

; A pair has two halves.
pub const HALVES : u8 = 2;
; How many halves you give to the host or paste into a chat, and how many stay with you.
pub const HALVES_SHARED : u8 = 1;
pub const HALVES_KEPT : u8 = 1;
; How many copies of the private half go to a host, a chat or a repository.
pub const PRIVATE_COPIES_SENT : u8 = 0;

test a_pair_is_two_halves_one_shared_one_kept {
    assert HALVES_SHARED + HALVES_KEPT == HALVES;
}

test the_placeholder_is_text_not_a_secret {
    assert PLACEHOLDER_PUBLIC == "EXAMPLE-PUBLIC-KEY-NOT-REAL";
}

test the_private_half_is_never_sent {
    assert PRIVATE_COPIES_SENT == 0;
}

; Negative control: plant the bug "the private half was pasted somewhere" (PRIVATE_COPIES_SENT = 1)
; and the test above turns red; with the line as written it stays green.
test negative_control_the_kept_half_has_no_copies {
    assert PRIVATE_COPIES_SENT < HALVES_KEPT;
}

Открыть спеку урока в плеере ↗

Все уроки