Friday, November 24, 2023

EventId's in Nostr - from CGPT4

The mathematical operation used to derive the event.id in your getSignedEvent function is the SHA-256 hash function, applied to a string representation of the event's data.

async function getSignedEvent(event, privateKey) {
          var eventData = JSON.stringify([
          0,            // Reserved for future use
          event['pubkey'],  // The sender's public key
          event['created_at'],  // Unix timestamp
          event['kind'],    // Message "kind" or type
          event['tags'],    // Tags idnetify replies/recipients
          event['content']  // Your note contents
          ])
          event.id = sha256( eventData ).toString( 'hex' )
          event.sig = await schnorr.sign( event.id, privateKey )
          return event
       }        

Let's break down this process:

String Representation of Event Data:

First, a string eventData is created from the event object. This string is a JSON representation that includes several fields of the event object, such as the sender's public key (event['pubkey']), timestamp (event['created_at']), message type (event['kind']), tags (event['tags']), and content (event['content']).

These fields are combined into an array and then serialized into a JSON string.

Applying the SHA-256 Hash Function:

The SHA-256 hash function is then applied to this string. SHA-256 stands for Secure Hash Algorithm 256-bit and is a member of the SHA-2 cryptographic hash functions designed by the NSA.

Cryptographic hash functions like SHA-256 have several key properties:

  • Deterministic: The same input will always produce the same output.
  • Fixed Size: Regardless of the input size, the output (hash) is always of a fixed length. In the case of SHA-256, the output is 256 bits (32 bytes) long.
  • Fast Computation: The hash value is quick to compute for any given input.
  • Pre-image Resistance: Given a hash value, it's computationally infeasible to find the original input.
  • Small Changes in Input Produce Significant Changes: Even a tiny change in the input will produce a significantly different output.
  • Collision Resistance: It's extremely unlikely (though not impossible) that two different inputs will produce the same output hash.

Creating event.id:

The output of the SHA-256 hash function (applied to eventData) is then converted to a hexadecimal string. This hex string becomes the value of event.id.

This event.id serves as a unique identifier for the event, and due to the properties of the SHA-256 hash, it also ensures the integrity of the event's data. Any change in the event's data would result in a completely different event.id.

In summary, the event.id is derived through a process of serialization (converting the event data to a JSON string) and hashing (applying SHA-256 to this string). This process is fundamental in many cryptographic applications, including blockchain and digital signatures, as it ensures data integrity and uniqueness.

Monday, August 07, 2023

The Change We Deserve Comes at a Steep Price




At 41 years of age, I am starting to become a grumpy old man. So when I saw people on FB "debating" how the Germans can do this, I start to philosophize about how we are, as we are today. What made the Germans and the Japanese so orderly? I am sure that some young one, would be studying these cultures as a topic of their thesis some day. 

I replied to the FB thread and posited a challenge and a rhetorical question: 

I'm happy that we are discussing this. It's a little bit of social science and a little bit of philosophy.

I've been following some Japanese "shorts" showing how orderly Japan is, and marveling at how they do that as well.

Among the answers I found here are:
  1. Law enforcement
  2. Discipline - with some dissent
  3. Culture - with some reservations
  4. Fines
  5. Education
I would offer the notion that it's all of the above. Now, if we combine these 5 ideas, we'll actually get to the bottom of this.

The problem with **law enforcement** is the sheer number of **undisciplined** people in our country. The **culture** of **corruption** is deeply ingrained, that **fines** are subverted because **corruption** allows people to make bribes. Our **education** system has also been **corrupted** because all that is being taught today, is to get out of the country so that "you'll make it.". **Law enforcement** is also difficult because our **leaders** are not accountable. They are often exempted. The mass **culture** is of personal gratification rather than collective responsibility. More often than not, the defense of errant drivers is **what about that guy**. Or, what about politician X, who did not even pay estate tax. ad infinitum. 

So here are the boldest questions: the change we need is going to be tough. It has to be cultural. And it will require changes.

Are we really ready for the change that we need?
Do we really even want to change?

Have a pleasant morning to all of us.

P.S. Lawrence Celestino - you really remind me of my younger self. I hope you are successful in your - in **our** dream of an orderly society. The question really is - what is the next BIG STEP? Is it still possible given the leadership we currently have?

Are there people willing to risk their lives to make this happen? Because, as you have said - people are violent. That is true.

Friday, December 23, 2022

c++ study notes

 terms: flooding network propagation


--- cpp


statement - type of instruction that causes the program to perform some action.


function - a collection of statements that execute sequentially


Declaration statements

Jump statements

Expression statements

Compound statements

Selection statements (conditionals)

Iteration statements (loops)

Try blocks


####################

Rule


Every C++ program must have a special function named main (all lower case letters). When the program is run, the statements inside of main are executed in sequential order.

####################


preprocessor directive

#include <iostream>


{

function body

}


// single line comments

/* multiple line comments */


data is any information that can be moved, processed, or stored by a computer.


 value - a single piece of data stored somewhere


In C++, direct memory access is not allowed. Instead, we access memory indirectly through an object. 


An object is a region of storage (usually memory) that has a value and other associated properties


 A named object is called a variable, and the name of the object is called an identifier.


runtime - when the program is run


instantiation - object is created and assigned a memory address


variable - a named region of memory


identifier - name that a variable is accessed by


type - tells the program how to interpret a value in memory.


copy assignment / assignement = after a variable has been defined, you can give it a value 


= assignment operator


initialization - variable defined and provided an initial value


initializer - the value used to initialize a variable


4 ways to initialize


int a; // no initializer

int b = 5; // initializer after equals sign - copy initialization

int c( 6 ); // initializer in parenthesis - direct initialization

int d { 7 }; // initializer in braces


copy initialization - when initializer follows an equal sign

direct initialization 

brace initialization/uniform initialization/list initialization


 3 kinds of brace initialization

 - int width { 5 }; // direct brace initialization of value 5 into variable width (preferred)

 - int height = { 6 }; // copy brace initialization of value 6 into variable height

 - int depth {}; // value initialization (see next section


value initialization and zero initialization

- variable initialized with empty braces

- value assigned is 0

- zero initialization



Initialization gives a variable an initial value at the point when it is created. Assignment gives a variable a value at some point after the variable is created.


Direct brace initialization.


<< - insertion operator - cout


>> - extraction operator - cin


using namespace std; - "using directive" avoid


std::endl vs ‘\n’


######

Best practice


Prefer ‘\n’ over std::endl when outputting text to the console.

######


_____1.6


- initialization - object given value at the point of definition

- assignment - object given value beyond the point of definition

- uninitialized - object not given a known value yet


always initialize your variables


Undefined behavior - executing code whose behavior not well defined in c++


_____1.7 


keywords - 92 words reserved by c++ for 

identifiers - override, final, import, and module.


ide changes color to blue of these words


c++ is case sensitive


always start lowercase

not number

no symbols

no space

no reserved words


snake_case

camelCase or interCapped


######

Best practice


When working in an existing program, use the conventions of that program (even if they don’t conform to modern best practices). Use modern best practices when you’re writing new programs.

######


_ underscores - OS, library, and/or compiler use


correct (follows convention)

incorrect (does not follow convention)

invalid (will not compile)


_____1.8 Whitespace


_____1.9 Literals and operators


literals or literal constant - fixed values inserted into source code


arity, the number of operatands an operator takes as input


- unary

- binary

- tertiary


_____1.10 Expressions


Expression

An expression is a combination of literals, variables, operators, and function calls that can be executed to produce a singular value. 


Evaluation 

The process of executing an expression is called evaluation, 


Result

and the single value produced is called the result of the expression.


_____2.1


function = reusable sequence of statements to do a job

user-defined function = function that user writes himself

function call = an expression that tells the CPU to interrupt the current function and execute another function


caller = the function that initiated the function call

callee or called function = the function being called


### syntax to define a user defined function


return-type identifier() // identifier replaced with the name of your function

{

// Your code here

}


the curly braces identify the function body


###


metasyntactic variable - placeholder names


_____2.2


return value

return type 

return statement

return value


""""""

When you write a user-defined function, you get to determine whether your function will return a value back to the caller or not. To return a value back to the caller, two things are needed.


First, your function has to indicate what type of value will be returned. This is done by setting the function’s return type, which is the type that is defined before the function’s name. In the example above, function getValueFromUser has a return type of void, and function main has a return type of int. Note that this doesn’t determine what specific value is returned -- only the type of the value.


Second, inside the function that will return a value, we use a return statement to indicate the specific value being returned to the caller. The specific value returned from a function is called the return value. When the return statement is executed, the return value is copied from the function back to the caller. This process is called return by value.""""""


status code 

exit code

return code


DRY = Don't Repeat Yourself


_____2.3 Function parameters and arguments



function parameter - is a variable used in a function. 


A function parameter is a variable used in a function. Function parameters work almost identically to variables defined inside the function, but with one difference: they are always initialized with a value provided by the caller of the function.


argument - value that is passed from the caller to the function when a function call is made


pass by value - parameters of the function created as variables, value is copied


//This is a hard topic, learn more about passing of value


**function prototyping


_____2.4 Local scope


Function parameters, as well as variables defined inside the function body, are called local variables (as opposed to global variables, which we’ll discuss in a future chapter).


An identifier’s scope determines where the identifier can be accessed within the source code. When an identifier can be accessed, we say it is in scope. When an identifier can not be accessed, we say it is out of scope.


_____2.5 Why functions are useful and how to use them effectively


- organization

- reusability

- testing

- extensibility

- abstraction


refactoring - when a function is split into multiple sub-functions 


_____2.6 forward declarations


A forward declaration allows us to tell the compiler about the existence of an identifier before actually defining the identifier.


function prototyping - a declaration statement. Is composed of 


    - return type

    - name

    - parameters



#### ODR #####


One Definition Rule


1. Within a given file, a function, object, type, or template can only have one definition.

2. Within a given program, an object or normal function can only have one definition. This distinction is made because programs can have more than one file (we’ll cover this in the next lesson).

3. Types, templates, inline functions, and variables are allowed to have identical definitions in different files. 


Declaration - a statement that tells the compiler about the existence of an identifier and its type information. 


in C++ - all definitions are also declarations


but not all declarations are definitions


Pure declarations - "An example of this is the function prototype -- it satisfies the compiler, but not the linker. These declarations that aren’t definitions are called pure declarations. Other types of pure declarations include forward declarations for variables and type declarations (you will encounter these in future lessons, no need to worry about them now)."


Function prototype - A function prototype is a declaration statement that includes a function’s name, return type, and parameters. It does not include the function body.


Forward declaration - A forward declaration tells the compiler that an identifier exists before it is actually defined.

 - according to Bucky this is actually called "Function prototyping"


Notes:


Compiler fails to compile if function does not have the same number of parameters.


Other compiler link problems - if a function is undefined (no body), linker can't resolve the function call.  


Violating ODR rule 2 - "Within a given program, an object or normal function can only have one definition"


_____2.8 naming collisions and namespaces


:: in std::cout - scope resolution operator 

The identifier to the left of the :: symbol identifies the namespace that the name to the right of the :: symbol is contained within. If no identifier to the left of the :: symbol is provided, the global namespace is assumed.


using directive - (using namespace std) -  tells the compiler to check a specified namespace when trying to resolve an identifier that has no namespace prefix


_____2.9 introduction to the pre-processor


Prior to compilation, program goes through translation.


Translation has many phases.


Preprocessor directive (or simply directive) scans from top to bottom of file. Start with # and end with a new line.


Macro defines 


a macro is a rule that defines how input text is converted into replacement output text.


object-like macros

function-like macros


Object-like macros can be defined in one of two ways:


#define identifier

#define identifier substitution_text


When the preprocessor encounters this directive, any further occurrence of the identifier is replaced by substitution_text. The identifier is traditionally typed in all capital letters, using underscores to represent spaces.


Tuesday, April 05, 2022

Fatherhood is like...

 Having a JP Drain stuck on your tummy and with people harnessed while you try to climb a mountain.

Wednesday, November 24, 2021

Trying to Install c-lightning

In my work with walletscrutiny.com, I had to test an app called Spark Wallet. The app needs a c-lightning node, which means installing c-lightning.

Several issues cropped up. 

One, the instructions given here, are for Ubuntu, and not for Linux Mint, which is the machine I'm trying this. 

Issue 1: 

sudo add-apt-repository -u ppa:lightningnetwork/ppa

does not work. No such option as -u

I removed the -u and it worked.

Issue 2:

gpg: keyserver receive failed: General error

Issue 3:

Package 'snapd' has no installation candidate
Fixed by moving a file that causes the restriction, which enabled snap.

2021-11-24 Installing Bitcoin-Core

Friday, August 27, 2021

How to find Private Key in Mycelium Bitcoin Wallet

1. Accounts Tab > My HD Accounts

2. Three Dots

3. Export

4. Show Private

* BIP32 Root Key Shows Up, starts with xprv

5. Use Mnemonic Code Converter - Recovers HD Wallet using mnemonic keywords

    a. Download/access here:

        https://iancoleman.github.io/bip39/ >> redirects to:

        https://iancoleman.io/bip39/


7. Copy BIP32 Root Key shown in the wallet

8. Paste in the "BIP32 Root Key" field

9. Click on BIP32 TAB, Under Derivation Path

10. Shows BIP32 Extended Private Key field.

Source: Reddit

Saturday, July 24, 2021

TheNewBoston.com Blockchain and Cryptocurrency Project


2.6 million people know Bucky Roberts. 

There are 481,000,000 views on his youtube channel. 

What he started has caught on like wildfire.

What did Bucky Roberts do?

P.S. This is not Bucky Roberts

Coding Tutorials

It all began with simple coding tutorials on YouTube. It started sometime in 2008 with a tutorial on XHTML. From there, it branched out to Photoshop, Dreamweaver, Adobe Flash, CSS, Adobe Illustrator, Javascript, Web Design, E-Commerce, PHP, C++, How to Build a Computer, Robotics Electronics, Python, Java, Adobe After Effects, Game Development, 3DS Max, Blender, Assassin's Creed Walkthroughs, --- and more.

He also ran a vlog where he talked about any topic he thinks about. By 2010, thenewboston was starting to take shape as a podcast and later on - a social media network

Everything seemed to be on the up and up, but then sometime between 2015 to 2020, Bucky went on an unannounced sabbatical. 

Where in the World is Bucky Roberts?

People missed him so much that you could find entire threads about "Where is Bucky Roberts now?" littered all around the Internet:

Work and Penguin Chess




Hello World - Bucky Roberts Comes Back


After a lot of speculation, Bucky uploads "Hello World" on Nov. 6, 2021.



Sunday, July 11, 2021

Creating Freecodecamp Tribute Page


I started getting back into my freecodecamp.com HTML and CSS tutorials. When I started in 2017, I figured that it's something that I could use. I guess, back then I wanted to put up my own business startup. Nowadays when I send a job application to some companies on LinkedIn, I can't help but be skeptical. 

Practically anybody who can think of a cool name, think of a clever dot com domain, could "pretend" to be a legitimate company. 

I'm still grappling with this idea of remote businesses - since they could be prone to abuse. As you get older, you tend to get more cautious. 

Friday, June 11, 2021

Stepping on Broken Glass

One of the things I've learned as I soon reach my 40's is that blogging can be a bit like stepping on shards of glass. And no, it won't be like some Tony Robbins spectacle. It can be excruciating. Unresolved reasoning plus the dawning of a reality that is not as rational as we'd hope to be clouds the mind. This lends the blogger, some dangerous hesitation. Social media, with all the events that transpired has shown the variety of opinions that are proliferating in the wild. Like a goat's diarrhea, the blogger can be put-off from sharing his thoughts out of fear for real-world consequences that can have a direct impact on your physical wellbeing. As I watch the transformation of social discourse across various mediums, each and every one of us fits into a certain mold. Stereotypes. We say what we say, because of our background, our upbringing, education, exposure and experiences. It's very rare to transcend that. It takes a huge amount of intellectual humility to come to grips that even imperfect opinions have a set of eyes and a brain with its own experiences, with its own background and with its own categories. This is where silence can become a weapon. In an age of inundation, sitting down cross-legged with eyes closed can be a welcome refuge from the circus that social discourse has become.

EventId's in Nostr - from CGPT4

The mathematical operation used to derive the event.id in your getSignedEvent function is the SHA-256 hash function, applied to a string rep...