Skip to content

blowfishxyz/blowfish-signature-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sign example

The following example walks you through how to get started by creating and importing a keystore file, extracting and importing the public keys in the required formats and verifying the contents of a sample data file using both implementations in Rust and Node.js.

The workflow to be used:

  1. Creates a pair of 4096-bit RSA private and public keys, in both PEM and DER formats
  2. Imports a signature persisted in HEX format and a file with plain text contents
  3. Recreates the original byte array representation and hashes it using SHA-256
  4. And finally uses the public key provided to verify the data contents matches the signature provided

Generate keys

In order to get us started, we will need a set of keys to be used for signing and verifing the contents of the dataprovided.

Create a private/public key pair based on RSA in PEM format.

openssl genrsa -out key.pem 4096

Output the DER representation of the private key, needed for the Rust signing implementation.

openssl rsa -in key.pem \
            -inform PEM \
            -outform DER \
            -out key.der

Extract a public key from the private one in DER representation to be used by the Rust verification implementation.

openssl rsa -in key.der \
            -inform DER \
            -RSAPublicKey_out \
            -outform DER \
            -out key.pub.der

Extract a public key from the private one in PEM representation to be used by the Node.js verification implementation.

openssl rsa -in key.pem \
            -inform PEM \
            -RSAPublicKey_out \
            -outform PEM \
            -out key.pub.pem

Run the example

  1. Sign the data.txt with the private key and create the data.txt.sign file by running the Rust sign implementation.
cargo run -- sign

Note: This example already comes with data.txt and data.txt.sign files, but feel free to change the contents of the first one to verify the correct behavior of the implementations.

  1. Verify the contents in data.txt.sign using the public key and the contents of data.txt. For this, one of the following options can be used:

    1. Run the Rust verification implementation under the /rust directory:
    cargo run -- verify
    1. Run the Node.js verification implementation under the /ts directory:
    npm start

Run the API request example

Runs an example making a request to the Blowfish scan Solana transactions API and verifies the returned signature against the response body with the public key.

For this example to work, you need to provide a valid Blowfish API_KEY to the terminal command.

API_KEY={your-key-here} cargo run -- request

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published