### Starting Demo Application Testnet Shell Source: https://github.com/cryptape/nostr-binding/blob/main/README.md This command sequence navigates into the demo package directory, installs dependencies using pnpm, and starts the development server. It explicitly sets the NETWORK environment variable to 'testnet' to configure the application for the CKB test network. ```sh cd packages/demo pnpm i && NETWORK=testnet pnpm run dev ``` -------------------------------- ### Starting Development Server with npm - shellscript Source: https://github.com/cryptape/nostr-binding/blob/main/packages/demo/README.md Runs the Vite development server for local development. This command starts the application with hot module replacement and other development features, enabling rapid iteration. ```shellscript npm run dev ``` -------------------------------- ### Starting Local CKB Devnet Shell Source: https://github.com/cryptape/nostr-binding/blob/main/README.md This command initiates a local CKB development network node using the `offckb` tool. This step is a prerequisite for running the Nostr binding demo locally and requires `offckb` version >= 0.3.0-rc1 to be installed on the system. ```sh offckb node ``` -------------------------------- ### Starting Demo Application Devnet Shell Source: https://github.com/cryptape/nostr-binding/blob/main/README.md This command navigates to the demo package directory, installs dependencies if needed, and starts the development server. It sets the NETWORK environment variable to 'devnet' to connect the application to the local CKB development network after scripts have been deployed. ```sh cd packages/demo pnpm i && NETWORK=devnet pnpm run dev ``` -------------------------------- ### Starting Development Server (Bash) Source: https://github.com/cryptape/nostr-binding/blob/main/packages/book-app/README.md Instructions on how to start the local development server for the Nostr workshop book app using various popular JavaScript package managers. This is the first step to run the application locally for development or testing. ```bash npm run dev ``` ```bash yarn dev ``` ```bash pnpm dev ``` ```bash bun dev ``` -------------------------------- ### Running Production App with npm - sh Source: https://github.com/cryptape/nostr-binding/blob/main/packages/demo/README.md Starts the application in production mode after it has been built. This command serves the optimized production build, typically using the built-in Remix app server or a similar Node.js environment. ```sh npm start ``` -------------------------------- ### Installing Nostr Binding SDK - Bash Source: https://github.com/cryptape/nostr-binding/blob/main/packages/sdk/README.md Provides the command line instruction to install the required Nostr binding SDK package using npm, a Node.js package manager. This is the first step to use the SDK in a JavaScript/TypeScript project. Requires Node.js and npm installed. ```bash npm install @nostr-binding/sdk ``` -------------------------------- ### Building Production App with npm - sh Source: https://github.com/cryptape/nostr-binding/blob/main/packages/demo/README.md Builds the application for production deployment. This command compiles and optimizes the code, producing the necessary static assets and server files in the build directory. ```sh npm run build ``` -------------------------------- ### Nostr NIP-01 Event Tags Example JSONC Source: https://github.com/cryptape/nostr-binding/blob/main/packages/book-app/scripts/01.md Illustrates the structure and content of the 'tags' array within a Nostr event. It shows examples of standard tag types ('e' for event reference, 'p' for pubkey reference, 'a' for address reference) and a custom 'alt' tag, demonstrating that tags are arrays of strings and may include optional data like recommended relay URLs. ```JSONC { "tags": [ [ "e", "5c83da77af1dec6d7289834998ad7aafbd9e2191396d75ec3cc27f5a77226f36", "wss://nostr.example.com", ], ["p", "f7234bd4c1394dda46d09f35bd384dd30cc552ad5541990f98844fb06676e9ca"], [ "a", "30023:f7234bd4c1394dda46d09f35bd384dd30cc552ad5541990f98844fb06676e9ca:abcd", "wss://nostr.example.com", ], ["alt", "reply"], // ... ], // ... } ``` -------------------------------- ### Displaying Project Structure Bash Source: https://github.com/cryptape/nostr-binding/blob/main/README.md This snippet displays the directory structure of the repository, showing the organization of contracts, deployment information, and packages including the demo and SDK. It helps users understand where different parts of the project are located. ```bash │── contracts # scripts source code │ ├── ckb-nostr-utils │ ├── nostr-binding │ └── nostr-lock ├── deployment # script deploy info │ ├── mainnet │ └── testnet │── packages │ ├── book-app # a simple workshop app │ ├── demo # a simple demo using sdk │ └── sdk # javascript sdk for nostr-binding protocol ``` -------------------------------- ### JSON Note with Nonce Tag (Mining Example) Source: https://github.com/cryptape/nostr-binding/blob/main/packages/book-app/scripts/13.md Example JSON structure for a Nostr note demonstrating the use of the `nonce` tag for Proof of Work mining. The second element of the tag is a counter updated during mining, and the third is the target difficulty. ```json { "content": "It's just me mining my own business", "tags": [["nonce", "1", "21"]] } ``` -------------------------------- ### Listing Uploaded NIP-30041 Event IDs Source: https://github.com/cryptape/nostr-binding/blob/main/packages/book-app/scripts/README.md This snippet lists the hexadecimal event IDs generated by the preceding executions of the `scripts/upload-30041.js` script. These IDs correspond to the uploaded NIP-30041 events. ```bash bd7917bc8e43b4dced4f720c553f4cce6e76a2e3d39c30127d27959e4ff67bbf 6bc9de97231f35749534438d94fc4d06fecc7d16e9f4bc1032bc84398edc536e ef488ab9cf957a15c514f23f63f89e5c1b17987c49b8eeb7d8a7ca9ac25db517 1c61d6daac89e159702845dae77133f1e1e7e334a459c057925df5ee31a5c600 ``` -------------------------------- ### JSON Mined Nostr Note Example Source: https://github.com/cryptape/nostr-binding/blob/main/packages/book-app/scripts/13.md Example JSON structure for a Nostr note that has successfully been mined. It shows the resulting `id` with leading zeroes, the `nonce` tag with the final counter value and target difficulty, and other standard note fields. ```json { "id": "000006d8c378af1779d2feebc7603a125d99eca0ccf1085959b307f64e5dd358", "pubkey": "a48380f4cfcc1ad5378294fcac36439770f9c878dd880ffa94bb74ea54a6f243", "created_at": 1651794653, "kind": 1, "tags": [["nonce", "776797", "20"]], "content": "It's just me mining my own business", "sig": "284622fc0a3f4f1303455d5175f7ba962a3300d136085b9566801bc2e0699de0c7e31e44c81fb40ad9049173742e904713c3594a1da0fc5d2382a25c11aba977" } ``` -------------------------------- ### Deploying CKB Scripts Devnet Shell Source: https://github.com/cryptape/nostr-binding/blob/main/README.md This command navigates to the demo directory and deploys the compiled CKB scripts to the running local development network using the `offckb deploy` command. It specifies the 'devnet' network for deployment, and the script information is automatically updated in the app's configuration. ```sh cd packages/demo offckb deploy --network devnet ``` -------------------------------- ### Executing NIP-30041 Upload Script and Output Source: https://github.com/cryptape/nostr-binding/blob/main/packages/book-app/scripts/README.md This snippet shows multiple executions of the `node scripts/upload-30041.js` command. The command is used to upload content related to specific NIPs (identified by the 'Title' output) as NIP-30041 events. Each execution includes the public and secret keys used and reports the generated event ID. ```bash node scripts/upload-30041.js Public key (hex): 79dff8f82963424e0bb02708a22e44b4980893e3a4be0fa3cb60a43b946764e3 Secret key (hex): e267c86832e53c782f31615e66d36a6e701e0820fa945a6e30b4c1890884817f Title: NIP-01 sent event_id: bd7917bc8e43b4dced4f720c553f4cce6e76a2e3d39c30127d27959e4ff67bbf node scripts/upload-30041.js Public key (hex): 79dff8f82963424e0bb02708a22e44b4980893e3a4be0fa3cb60a43b946764e3 Secret key (hex): e267c86832e53c782f31615e66d36a6e701e0820fa945a6e30b4c1890884817f Title: NIP-02 sent event_id: 6bc9de97231f35749534438d94fc4d06fecc7d16e9f4bc1032bc84398edc536e node scripts/upload-30041.js Public key (hex): 79dff8f82963424e0bb02708a22e44b4980893e3a4be0fa3cb60a43b946764e3 Secret key (hex): e267c86832e53c782f31615e66d36a6e701e0820fa945a6e30b4c1890884817f Title: NIP-07 sent event_id: ef488ab9cf957a15c514f23f63f89e5c1b17987c49b8eeb7d8a7ca9ac25db517 node scripts/upload-30041.js Public key (hex): 79dff8f82963424e0bb02708a22e44b4980893e3a4be0fa3cb60a43b946764e3 Secret key (hex): e267c86832e53c782f31615e66d36a6e701e0820fa945a6e30b4c1890884817f Title: NIP-13 sent event_id: 1c61d6daac89e159702845dae77133f1e1e7e334a459c057925df5ee31a5c600 ``` -------------------------------- ### Depositing CKB Local Devnet Shell Source: https://github.com/cryptape/nostr-binding/blob/main/README.md This command uses the `offckb deposit` tool to transfer a specified amount of CKB (in Shannon) to a target address on the local devnet. The target address is expected to correspond to a Nostr account, enabling it to hold CKB assets bound via the protocol. ```sh offckb deposit --network devnet ``` -------------------------------- ### Getting Relay List (NIP-07) - TypeScript Source: https://github.com/cryptape/nostr-binding/blob/main/packages/book-app/scripts/07.md Describes the optional method `window.nostr.getRelays` which asynchronously returns a basic map of Nostr relay URLs and their associated policies (read/write) from the perspective of the browser extension or environment. ```TypeScript async window.nostr.getRelays(): { [url: string]: {read: boolean, write: boolean} } // returns a basic map of relay urls to relay policies ``` -------------------------------- ### Building CKB Scripts Rust Shell Source: https://github.com/cryptape/nostr-binding/blob/main/README.md This command compiles the CKB scripts written in Rust using the `make build` command. It requires various dependencies like Rust (with riscv64 target), Clang 16+, and standard Unix utilities. The compiled script binaries are placed in the `build/release` directory. ```sh make build ``` -------------------------------- ### Example Nostr Event Tag for CKB Sighash All Source: https://github.com/cryptape/nostr-binding/blob/main/docs/nostr-lock-script.md Demonstrates the structure of the required `ckb_sighash_all` tag within the Nostr event. This tag must contain the hexadecimal string representation of the CKB `sighash_all` message as its second element. ```JSON ["ckb_sighash_all", "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff"] ``` -------------------------------- ### Example Dummy Nostr Event for CKB Signing Procedure Source: https://github.com/cryptape/nostr-binding/blob/main/docs/nostr-lock-script.md Provides a template for a dummy Nostr event used during the CKB transaction signing process. This dummy event helps determine the final event length to accurately calculate the `sighash_all` before the actual event content is finalized and signed. ```JSON { "id": "00..00", "pubkey": "00..00", "created_at": 123456, "kind": 23334, "tags": [ ["ckb_sighash_all", "0000000000000000000000000000000000000000000000000000000000000000"] ], "content": "Signing a CKB transaction\n\nIMPORTANT: Please verify the integrity and authenticity of the connected Nostr client before signing this message\n", "sig": "00..00" } ``` -------------------------------- ### Setting Network Environment Variable - shellscript Source: https://github.com/cryptape/nostr-binding/blob/main/packages/demo/README.md Sets the NETWORK environment variable to specify the target network (devnet, testnet, or mainnet) for the application. This variable allows configuring network-specific settings or endpoints. ```shellscript export NETWORK=devnet # or testnet, mainnet ``` -------------------------------- ### Example CKB Transaction for Unlocking by Key Source: https://github.com/cryptape/nostr-binding/blob/main/docs/nostr-lock-script.md Shows a conceptual CKB transaction structure demonstrating how to unlock a cell secured by the Nostr lock script using the Schnorr key method. It highlights the required script arguments (zero PoW difficulty, non-zero pubkey hash) and the content of the `WitnessArgs` lock field, including the Nostr event with a valid Schnorr public key and signature matching the script args. ```Structure Description CellDeps: Nostr lock script cell Inputs: Cell Data: <...> Type: <...> Lock: code_hash: args: Outputs: Any cell Witnesses: WitnessArgs Lock: > { "id": "0011...eeff", "pubkey": , "created_at": , "kind": 23334, "tags": [ ["ckb_sighash_all", "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff"] ], "content": "Signing a CKB transaction\n\nIMPORTANT: Please verify the integrity and authenticity of connected Nostr client before signing this message\n", "sig": } ``` -------------------------------- ### Example Nostr Event Tag for PoW Nonce Source: https://github.com/cryptape/nostr-binding/blob/main/docs/nostr-lock-script.md Illustrates the structure of the `nonce` tag used for unlocking via Proof-of-Work. It includes a mutable string value for mining attempts and the required PoW difficulty level as a decimal string in the third element. ```JSON ["nonce", "000000000000000000000000000000000000", "24"] ``` -------------------------------- ### Performing Reproducible Build using Docker (Bash) Source: https://github.com/cryptape/nostr-binding/blob/main/docs/nostr-lock-script.md This bash script sequence clones the Nostr binding repository from GitHub, checks out a specific commit (ec480b0), and then executes a script within a Docker environment to perform a reproducible build of the CKB lock script. It requires Git and Docker to be installed. ```bash git clone https://github.com/cryptape/nostr-binding.git cd nostr-binding git checkout ec480b0 bash scripts/reproducible_build_docker ``` -------------------------------- ### Example CKB Transaction for Unlocking by PoW Source: https://github.com/cryptape/nostr-binding/blob/main/docs/nostr-lock-script.md Shows a conceptual CKB transaction structure demonstrating how to unlock a cell secured by the Nostr lock script using the Proof-of-Work method. It highlights the required script arguments (non-zero PoW difficulty, zeroed pubkey hash) and the content of the `WitnessArgs` lock field, including the Nostr event with the `nonce` tag meeting the difficulty requirement. ```Structure Description CellDeps: Nostr lock script cell Inputs: Cell Data: <...> Type: <...> Lock: code_hash: args: Outputs: Any cell Witnesses: WitnessArgs Lock: > { "id": "000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "pubkey": "0000...00", "created_at": , "kind": 23334, "tags": [ ["nonce", "quick brown fox", "24"], ["ckb_sighash_all", "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff"] ], "content": "Signing a CKB transaction\n\nIMPORTANT: Please verify the integrity and authenticity of connected Nostr client before signing this message\n", "sig": "0000...00" } ``` -------------------------------- ### Getting Public Key (NIP-07) - TypeScript Source: https://github.com/cryptape/nostr-binding/blob/main/packages/book-app/scripts/07.md Describes the required method `window.nostr.getPublicKey` which asynchronously returns the user's Nostr public key as a hexadecimal string. This method allows web applications to retrieve the public key without direct access to the user's private key. ```TypeScript async window.nostr.getPublicKey(): string // returns a public key as hex ``` -------------------------------- ### Structure of a Nostr Kind 3 Follow List Event JSON Source: https://github.com/cryptape/nostr-binding/blob/main/packages/book-app/scripts/02.md This snippet shows an example structure of a Nostr kind 3 event, representing a user's follow list. It includes the required 'kind' field set to 3, and a 'tags' array containing 'p' tags for followed profiles, each listing a public key, an optional relay URL, and an optional petname. The 'content' field is explicitly empty as per NIP-02. ```JSON { "kind": 3, "tags": [ ["p", "91cf9..4e5ca", "wss://alicerelay.com/", "alice"], ["p", "14aeb..8dad4", "wss://bobrelay.com/nostr", "bob"], ["p", "612ae..e610f", "ws://carolrelay.com/ws", "carol"] ], "content": "", ...other fields } ``` -------------------------------- ### Querying Nostr Relays by ID Prefix (Shell) Source: https://github.com/cryptape/nostr-binding/blob/main/packages/book-app/scripts/13.md Shell command demonstrating how to query a Nostr relay using `websocat` to filter notes based on an ID prefix. This allows retrieving notes that meet a certain minimum difficulty requirement (e.g., starting with "000000000"). Uses `jq` to parse the response. ```shell $ echo '["REQ", "subid", {"ids": ["000000000"]}]' | websocat wss://some-relay.com | jq -c '.[2]' ``` -------------------------------- ### Configuring CKB Network Target (Bash) Source: https://github.com/cryptape/nostr-binding/blob/main/packages/book-app/README.md Explains how to configure the target CKB network for the application by editing the `.env` file. The application can be configured to connect to the devnet, testnet, or mainnet CKB network. ```bash NEXT_PUBLIC_NETWORK=devnet # devnet, testnet or mainnet ``` -------------------------------- ### Using Nostr Binding SDK for CKB - TypeScript Source: https://github.com/cryptape/nostr-binding/blob/main/packages/sdk/README.md Shows how to initialize the Nostr Binding SDK with testnet configurations, generate CKB addresses from Nostr public keys, and define a signer function for Nostr events. It demonstrates two methods for signing CKB transactions using a Nostr signer: `signTx` for direct signing and `prepareTx` followed by `signPreparedTx` for a more controlled process. Finally, it shows how to fetch the required cell dependencies for Nostr lock and binding scripts. Requires `@nostr-binding/sdk` and potentially `@ckb-lumos/lumos`. ```typescript import { NostrBindingSDK, TESTNET_CONFIGS } from '@nostr-binding/sdk'; const sdk = new NostrBindingSDK(TESTNET_CONFIGS); const nostrPublicKey = '0x45c41f21e1cf715fa6d9ca20b8e002a574db7bb49e96ee89834c66dac5446b7a'; const nostrLockScript = sdk.lock.buildScript(nostrPublicKey); const ckbAddress = sdk.lock.encodeToCKBAddress(nostrPublicKey); //**** Signed a nostr-lock input transaction ****// // construct a nostr signer first const signer = async (event: EventToSign) => { //...nostr signing event code const signedEvent: SignedEvent = //... return signedEvent; }; // sdk.lock.signTx will overwrite the witness lock with dummyLock and then generate sigHashAll, // sign it and return signed transaction. It is a easy way to do nostr lock signing if // transaction fee estimation is not a problem to you. After calling this function, witness // is auto-filled with signedEvent. tx = await sdk.lock.signTx(tx, signer); // or prepare your transaction first import { createTransactionFromSkeleton } from "@ckb-lumos/lumos/helpers"; const tx = createTransactionFromSkeleton(txSkeleton); // fill-in the witness of nostr-lock with corresponding dummyLock const {transaction, lockIndexes} = await sdk.lock.prepareTx(transaction: Transaction); // sdk.lock.signPreparedTx will checks if the transaction is placed with correct Nostr-lock dummyLock // and then directly generate sigHashAll from the giving transaction, sign it and return // signed transaction. You need to call prepareTx before this function. const signedTx = await sdk.lock.signPreparedTx(transaction, lockIndexes, signer); //**** Get Nostr Scripts CellDeps ****// const lockCellDeps = await sdk.lock.buildCellDeps(); const bindingCellDeps = await sdk.binding.buildCellDeps(); ``` -------------------------------- ### Building Nostr Lock Script (Shell) Source: https://github.com/cryptape/nostr-binding/blob/main/contracts/nostr-lock/README.md This command executes the build process for the Nostr Lock Script. It uses the `make` utility to run the default build target defined in the project's Makefile. ```Shell make build ``` -------------------------------- ### Signing Nostr Event (NIP-07) - TypeScript Source: https://github.com/cryptape/nostr-binding/blob/main/packages/book-app/scripts/07.md Defines the required method `window.nostr.signEvent` for asynchronously signing a Nostr event. It takes a partial event object (without `id`, `pubkey`, and `sig`), adds the user's public key, generates the event ID, signs the event using the user's private key, and returns the complete, signed `Event` object. ```TypeScript async window.nostr.signEvent(event: { created_at: number, kind: number, tags: string[][], content: string }): Event // takes an event object, adds `id`, `pubkey` and `sig` and returns it ``` -------------------------------- ### Building Deployed Script Reproducibly - Bash Source: https://github.com/cryptape/nostr-binding/blob/main/docs/nostr-binding-type-script.md Provides a sequence of Bash commands to reproduce the build process for the deployed Nostr binding script. It involves cloning the specific git repository and commit, then executing a build script within a Docker environment to ensure consistency and verifiability of the deployed code. ```Bash git clone https://github.com/cryptape/nostr-binding.git cd nostr-binding git checkout ec480b0 bash scripts/reproducible_build_docker ``` -------------------------------- ### Nostr NIP-01 Event Wire Format JSONC Source: https://github.com/cryptape/nostr-binding/blob/main/packages/book-app/scripts/01.md Defines the standard JSON structure for Nostr events as transmitted over the wire. It specifies the mandatory fields: id (SHA256 hash), pubkey (creator's public key), created_at (Unix timestamp), kind (integer), tags (array of arrays), content (string), and sig (Schnorr signature), explaining the data type and purpose of each. ```JSONC { "id": <32-bytes lowercase hex-encoded sha256 of the serialized event data>, "pubkey": <32-bytes lowercase hex-encoded public key of the event creator>, "created_at": , "kind": , "tags": [ [...], // ... ], "content": , "sig": <64-bytes lowercase hex of the signature of the sha256 hash of the serialized event data, which is the same as the "id" field> } ``` -------------------------------- ### Minting Nostr Binding Cell Transaction - CKB/YAML Source: https://github.com/cryptape/nostr-binding/blob/main/docs/nostr-binding-type-script.md Illustrates the structure of a CKB transaction used to create (mint) a new cell associated with a Nostr event. It shows the configuration of cell dependencies, inputs (consuming a normal cell to generate the global unique ID), outputs (creating the Nostr binding cell with the specified type script and args), and the witness containing the NIP-01 compliant Nostr event JSON. ```YAML CellDeps: Nostr binding type script cell Inputs: normal cell (consumed to generated global unique ID) Outputs: Nostr binding cell Data: <...> Lock: <...> Type: code_hash: args: Witnesses: WitnessArgs lock: <...> input_type: <...> output_type: > { "id": "0011...eeff", "pubkey": , "created_at": , "kind": <0~65535>, "tags": [ ["ckb_global_unique_id", "aabb...0011"] ], "content": , "sig": } ``` -------------------------------- ### Defining Nostr Asset Metadata Event Structure (JSON) Source: https://github.com/cryptape/nostr-binding/blob/main/docs/lightpaper.md Describes the JSON format for a Nostr Event used to define metadata for a set of Nostr assets bound to CKB. It uses 'kind: 23332' and includes optional tags for common asset metadata fields such as 'name', 'symbol', 'decimals', and 'description'. The 'content' field for this event kind is typically left empty. ```JSON { "id": <32-bytes lowercase hex-encoded sha256 of the serialized event data>, "pubkey": <32-bytes lowercase hex-encoded public key of the event creator>, "created_at": , "kind": <23332>, "tags": [ ["name", ], ["symbol", ], ["decimals", ], ["description", ] [...], // ... ], "content": "", "sig": <64-bytes lowercase hex of the signature of the sha256 hash of the serialized event data, which is the same as the "id" field> } ``` -------------------------------- ### Encrypting NIP-44 Message (NIP-07) - TypeScript Source: https://github.com/cryptape/nostr-binding/blob/main/packages/book-app/scripts/07.md Specifies the optional method `window.nostr.nip44.encrypt` for encrypting plaintext using a recipient's public key according to the NIP-44 standard. It asynchronously returns the ciphertext. ```TypeScript async window.nostr.nip44.encrypt(pubkey, plaintext): string // returns ciphertext as specified in nip-44 ``` -------------------------------- ### Encrypting NIP-04 Message (NIP-07) - TypeScript Source: https://github.com/cryptape/nostr-binding/blob/main/packages/book-app/scripts/07.md Specifies the optional and deprecated method `window.nostr.nip04.encrypt` for encrypting plaintext using a recipient's public key according to the NIP-04 standard. It asynchronously returns the ciphertext combined with the initialization vector. ```TypeScript async window.nostr.nip04.encrypt(pubkey, plaintext): string // returns ciphertext and iv as specified in nip-04 (deprecated) ``` -------------------------------- ### Validating Nostr PoW in C Source: https://github.com/cryptape/nostr-binding/blob/main/packages/book-app/scripts/13.md C code snippet providing a function `countLeadingZeroes` to calculate the number of leading zero bits in a hexadecimal string (like a Nostr event ID). It also includes a simple `main` function to demonstrate its usage with a command-line argument. Requires standard C libraries and potentially `__builtin_clz` (GCC/Clang). ```c #include #include #include int countLeadingZeroes(const char *hex) { int count = 0; for (int i = 0; i < strlen(hex); i++) { int nibble = (int)strtol((char[]){hex[i], '\0'}, NULL, 16); if (nibble == 0) { count += 4; } else { count += __builtin_clz(nibble) - 28; break; } } return count; } int main(int argc, char *argv[]) { if (argc != 2) { fprintf(stderr, "Usage: %s \n", argv[0]); return 1; } const char *hex_string = argv[1]; int result = countLeadingZeroes(hex_string); printf("Leading zeroes in hex string %s: %d\n", hex_string, result); return 0; } ``` -------------------------------- ### Defining CKB Script Structure (CKB/Structure) Source: https://github.com/cryptape/nostr-binding/blob/main/docs/lightpaper.md Describes the structure of a CKB Script, which can be either a lock or type script used within a CKB Cell to define validation rules. It includes a 'code_hash' referencing the script's executable code, 'args' providing parameters to the script, and 'hash_type' indicating how the 'code_hash' should be interpreted. ```CKB/Structure Script: { code_hash: HexString args: HexString hash_type: Uint8, there are 4 allowed values: {0: "data", 1: "type", 2: "data1", 3: "data2"} } ``` -------------------------------- ### Defining Nostr Lock Script Structure (CKB/Structure) Source: https://github.com/cryptape/nostr-binding/blob/main/docs/lightpaper.md Defines the structure of the Nostr lock script on CKB, designed to allow unlocking CKB Cells using Nostr Events as witnesses. It uses 'hash_type: "data2"', a specific 'code_hash' ('NOSTR_LOCK_DATA_HASH'), and its 'args' contain the required Nostr public key for unlocking, optionally followed by a value indicating a minimum Proof-of-Work difficulty the unlocking event must meet. The witness field expects a serialized Nostr unlock Event. ```CKB/Structure lock: hash_type: "data2" code_hash: NOSTR_LOCK_DATA_HASH args: NOSTR_PUBLICKEY <32 bytes> | POW difficulties <4 bytes> witness: ``` -------------------------------- ### Describing Nostr Event Structure in CKB Witness Source: https://github.com/cryptape/nostr-binding/blob/main/docs/nostr-lock-script.md Outlines the expected JSON structure for the Nostr event required in the `lock` field of the `WitnessArgs` when unlocking a CKB cell with the Nostr lock script. It details each field's purpose and expected format according to NIP-01. ```Structure Description { "id": <32-bytes lowercase hex-encoded sha256 of the serialized event data>, "pubkey": <32-bytes lowercase hex-encoded public key of the event creator>, "created_at": , "kind": , "tags": [ [...], // ... ], "content": , "sig": <64-bytes lowercase hex of the signature of the sha256 hash of the serialized event data, which is the same as the "id" field> } ``` -------------------------------- ### Describing CKB Nostr Lock Script Structure Source: https://github.com/cryptape/nostr-binding/blob/main/docs/nostr-lock-script.md Defines the required fields and arguments for a cell secured by the Nostr lock script on CKB. It specifies the script's code hash, hash type, and arguments that include PoW difficulty and Schnorr pubkey hash. ```Structure Description Code hash: nostr lock script code hash Hash type: nostr lock script hash type Args: ``` -------------------------------- ### Nostr Client Subscription Filter Structure JSON Source: https://github.com/cryptape/nostr-binding/blob/main/packages/book-app/scripts/01.md Defines the structure of the JSON object used within a 'REQ' message to filter events. It allows clients to specify criteria such as event IDs, author public keys, kinds, tags, time ranges ('since', 'until'), and a limit for the initial query. Multiple conditions within a single filter are combined with AND, while multiple filters in a REQ message are combined with OR. ```json { "ids": , "authors": , "kinds": , "#": , "since": = to this to pass>, "until": , "limit": } ``` -------------------------------- ### Defining Nostr Unlock Event Structure (JSON) Source: https://github.com/cryptape/nostr-binding/blob/main/docs/lightpaper.md Specifies the JSON format for a Nostr Event used as a witness to unlock a CKB Cell protected by the Nostr lock script. It uses 'kind: "<23334>"' and includes tags to link to the corresponding CKB transaction, such as the serialized raw transaction ('ckb_raw_tx') and its hash ('ckb_tx_hash'). An optional 'nonce' tag can be included for Proof-of-Work requirements defined in the lock script args. ```JSON { "id": <32-bytes lowercase hex-encoded sha256 of the serialized event data>, "pubkey": <32-bytes lowercase hex-encoded public key of the event creator>, "created_at": , "kind": "<23334>", "tags": [ ["ckb_raw_tx", ], ["ckb_tx_hash", ], ["nonce", , ],// optional [...], // ... ], "content": , "sig": <64-bytes lowercase hex of the signature of the sha256 hash of the serialized event data, which is the same as the "id" field> } ``` -------------------------------- ### Decrypting NIP-44 Message (NIP-07) - TypeScript Source: https://github.com/cryptape/nostr-binding/blob/main/packages/book-app/scripts/07.md Specifies the optional method `window.nostr.nip44.decrypt` for decrypting ciphertext using a recipient's public key according to the NIP-44 standard. It asynchronously returns the original plaintext. ```TypeScript async window.nostr.nip44.decrypt(pubkey, ciphertext): string // takes ciphertext as specified in nip-44 ``` -------------------------------- ### Transferring Nostr Binding Cell Transaction - CKB/YAML Source: https://github.com/cryptape/nostr-binding/blob/main/docs/nostr-binding-type-script.md Shows the transaction structure for transferring an existing CKB cell with the Nostr binding type script. It depicts the cell dependencies, inputs (consuming the existing Nostr binding cell), and outputs (creating a new cell with the same Nostr binding type script and arguments). The witness field is indicated as being arbitrary or ignored in this context. ```YAML CellDeps: Nostr binding type script cell Inputs: Nostr binding cell Data: <...> Lock: <...> Type: code_hash: args: Outputs: Nostr binding cell Data: <...> Lock: <...> Type: code_hash: args: Witnesses: <...> ``` -------------------------------- ### Decrypting NIP-04 Message (NIP-07) - TypeScript Source: https://github.com/cryptape/nostr-binding/blob/main/packages/book-app/scripts/07.md Specifies the optional and deprecated method `window.nostr.nip04.decrypt` for decrypting ciphertext combined with an initialization vector using a recipient's public key according to the NIP-04 standard. It asynchronously returns the original plaintext. ```TypeScript async window.nostr.nip04.decrypt(pubkey, ciphertext): string // takes ciphertext and iv as specified in nip-04 (deprecated) ``` -------------------------------- ### Defining Nostr Event Structure (JSON) Source: https://github.com/cryptape/nostr-binding/blob/main/docs/lightpaper.md Describes the standard JSON format for a Nostr Event, which is the core data unit in the protocol used for distributing messages via relays. It includes required fields like unique ID, public key, timestamp, event type ('kind'), arbitrary tags, content, and a digital signature for verification. ```JSON { "id": <32-bytes lowercase hex-encoded sha256 of the serialized event data>, "pubkey": <32-bytes lowercase hex-encoded public key of the event creator>, "created_at": , "kind": , "tags": [ [...], // ... ], "content": , "sig": <64-bytes lowercase hex of the signature of the sha256 hash of the serialized event data, which is the same as the "id" field> } ``` -------------------------------- ### Defining Nostr Asset Event Structure (JSON) Source: https://github.com/cryptape/nostr-binding/blob/main/docs/lightpaper.md Specifies the JSON format for a Nostr Event that represents an asset issued on Nostr and bound to a CKB Cell. It uses 'kind: 23333', includes tags to link to a metadata event ('e') and the bound CKB Cell's type ID ('cell_type_id'), and uses the 'content' field to store asset-specific data like token denomination or NFT content. ```JSON { "id": <32-bytes lowercase hex-encoded sha256 of the serialized event data>, "pubkey": <32-bytes lowercase hex-encoded public key of the event creator>, "created_at": , "kind": <23333>, "tags": [ ["e", ], ["cell_type_id", ], [...], // ... ], "content": , "sig": <64-bytes lowercase hex of the signature of the sha256 hash of the serialized event data, which is the same as the "id" field> } ``` -------------------------------- ### Defining Nostr Binding Script Structure (CKB/Structure) Source: https://github.com/cryptape/nostr-binding/blob/main/docs/lightpaper.md Describes the structure of the Nostr binding type script used on CKB to enforce a 1-to-1 mapping between a CKB Cell and a specific Nostr Event. It uses 'hash_type: "type"', a predefined 'code_hash' ('NOSTR_BINDING_TYPE_HASH'), and its 'args' are a concatenation of the Nostr Event ID and the CKB Cell's type ID. The transaction's witness field must contain the corresponding serialized Nostr asset Event. ```CKB/Structure type: hash_type: "type" code_hash: NOSTR_BINDING_TYPE_HASH args: BINDING_ARGS lock: any lock witness: BINDING_ARGS = NOSTR_EVENT_ID(32 bytes) + TYPE_ID(32 bytes) ``` -------------------------------- ### Defining CKB Cell Structure (CKB/Structure) Source: https://github.com/cryptape/nostr-binding/blob/main/docs/lightpaper.md Defines the structure of a CKB Cell, a generalized UTXO on the CKB blockchain. It contains fields for its storage capacity (measured in shannons), a lock script for ownership control, an optional type script for defining asset or data type, and a data field for storing arbitrary bytes. ```CKB/Structure Cell: { capacity: HexString; # represent the total storage space size of the Cell. The basic unit for capcaity is shannon, where 1 CKB equals 10**8 shannons. lock: Script; # a piece of code type: Script; # a piece of code data: HexString; # this field can store arbitrary bytes, which means it can hold any type of data } ``` -------------------------------- ### Validating Nostr PoW in JavaScript Source: https://github.com/cryptape/nostr-binding/blob/main/packages/book-app/scripts/13.md JavaScript function `countLeadingZeroes` to calculate the number of leading zero bits in a hexadecimal string. It iterates through the hex characters, using `parseInt` and `Math.clz32` to determine the leading zeroes. ```javascript // hex should be a hexadecimal string (with no 0x prefix) function countLeadingZeroes(hex) { let count = 0; for (let i = 0; i < hex.length; i++) { const nibble = parseInt(hex[i], 16); if (nibble === 0) { count += 4; } else { count += Math.clz32(nibble) - 28; break; } } return count; } ``` -------------------------------- ### Burning Nostr Binding Cell Transaction - CKB/YAML Source: https://github.com/cryptape/nostr-binding/blob/main/docs/nostr-binding-type-script.md Details the structure of a CKB transaction designed to burn (consume) a cell utilizing the Nostr binding type script. It outlines the necessary cell dependencies, inputs (the Nostr binding cell to be burned), and outputs (other cells, indicating the binding cell is not recreated). The witness field is shown as arbitrary or ignored. ```YAML CellDeps: Nostr binding type script cell Inputs: Nostr binding cell Data: <...> Lock: <...> Type: code_hash: args: Outputs: Other cells Witnesses: <...> ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.