What is Nostr?
Vineyy /
npub1xue…28gp
2024-07-07 06:40:34

Vineyy on Nostr: Nostr Binding Script The Nostr Binding Script is a CKB Type Script that defines the ...

Nostr Binding Script

The Nostr Binding Script is a CKB Type Script that defines the binding rules between a Nostr Event and a CKB Cell. It ensures that the Cell using this script as its Type Script is the only live Cell in the blockchain that is bound to a specific Nostr Event.

The structure of the Nostr Binding Script is as follows:


type:
hash_type: "type"
code_hash: NOSTR_BINDING_TYPE_HASH
args: BINDING_ARGS
lock: any Lock Script
witness: <Nostr Bound Event, serialized in JSON>

Where,
BINDING_ARGS = NOSTR_EVENT_ID(32 bytes) + TYPE_ID(32 bytes)
For example, to create a CKB Cell bound to a Nostr Event, the Type Script should be set as:


type:
hash_type: "type"
code_hash: 0x1234567890abcdef... (pre-defined Nostr Binding script hash)
args: 0xabcd...0123...(Nostr Event ID) + 0x1122...ffee...(TYPE_ID of this Cell)
The args field consists of two parts:

The first 32 bytes are the ID of the Nostr Event to be bound
The last 32 bytes are the TYPE_ID of this Cell, to ensure global uniqueness
The Nostr Binding Script will verify the Nostr Event provided in the witness, ensuring its ID matches the one in the args. The TYPE_ID also guarantees that there is only one live Cell in the blockchain with this type hash.

This establishes a one-to-one correspondence between the Nostr Event and the CKB Cell. The Cell's lock field can be set to any lock script to control the ownership of the Cell.

Nostr Lock Script

The Nostr Lock Script is a CKB Lock Script that uses a Nostr Event as the unlocking proof. This allows Nostr clients to directly generate signed events to unlock CKB Cells, simplifying user operations.

The structure of the Nostr Lock Script is as follows:


lock:
hash_type: "data2"
code_hash: NOSTR_LOCK_DATA_HASH
args: NOSTR_Public_Key (32 bytes) | POW_Difficulty (4 bytes)
witness: <Nostr Unlocking Event, serialized in JSON>
Where:

The code_hash is the pre-defined Nostr lock script hash
The args are set to the user's Nostr public key. The optional last 4 bytes can be used to set the POW difficulty
The witness provides the signed Nostr unlocking Event as the unlocking proof
For example, if Alice's Nostr public key is 0x1234...abcd, she can create a lock script as follows:


lock:
hash_type: "data2"
code_hash: 0xdcba...4321... (pre-defined Nostr Lock script hash)
args: 0x1234...abcd
When Alice wants to unlock this Cell, she needs to sign a specific format of Nostr Event (refer to the detailed format in the original text) using her Nostr private key, which includes the complete CKB transaction to be unlocked. Then, she provides this signed Nostr Event in the transaction's witness.

The Nostr Lock Script will verify that the Event's signature matches the public key in the args, and if so, it will allow the unlocking.

The Nostr Lock Script enables Nostr clients to "outsource" the CKB transactions, where the user only needs to sign and generate the Event in the Nostr client. This significantly reduces the complexity of the client development. It even allows third-party relay servers to monitor the Nostr network for these Events and help users construct and submit the actual CKB transactions to the chain, achieving a seamless user experienc
Author Public Key
npub1xueyls4zahuqgtqmwztq52j6pmsmw2ngueudjd03h86ehegydvfqp528gp