github-actions f8e40a939e Publish pinocchio-pubkey v0.3.0 4 месяцев назад
..
src 3fecb3e569 pubkey: Use qualified name for `Pubkey` (#207) 4 месяцев назад
Cargo.toml f8e40a939e Publish pinocchio-pubkey v0.3.0 4 месяцев назад
README.md 60d0dbf4b8 pubkey(readme): Add information about retrieving and generating public keys (#169) 5 месяцев назад

README.md

pinocchio-pubkey

pinocchio-pubkey

Companion Pubkey helpers for pinocchio.

Overview

This crate provides two convenience macros to resolve Pubkeys at compile time:

  • pubkey!: takes a pubkey value as a base58 &str and generates its correspondent Pubkey (byte array)
  • declare_id!: takes a pubkey value as a base58 &str (usually representing a program address) and generates an ID constant, check_id() and id() helpers

It also defines a from_str helper that takes a &str and returns the correspondent Pubkey value.

Examples

Once the project is built the first time with cargo build-sbf, a new keypair is automatically generated. A public key can be retrieved with:

solana-keygen pubkey ./target/deploy/your_program-keypair.json

Instead of the autogenerated keypair, a vanity key can be used. You can move the vanity keypair to ./target/deploy/your_program-keypair.json.

Remember to back up the keypair file securely, it is necessary for deploy the program.

Public keys can be embedded into the program code in the following ways.

1) Creating a Pubkey constant value from a static &str:

use pinocchio::pubkey::Pubkey;

pub const AUTHORITY: Pubkey = pinocchio_pubkey::pubkey!("7qtAvP4CJuSKauWHtHZJt9wmQRgvcFeUcU3xKrFzxKf1");

2) Declaring the program address of a program (usually on your lib.rs):

pinocchio_pubkey::declare_id!("Ping111111111111111111111111111111111111111");

3) Creating a Pubkey from a &str:

let address = String::from("7qtAvP4CJuSKauWHtHZJt9wmQRgvcFeUcU3xKrFzxKf1");
let owner = pinocchio_pubkey::from_str(&address);

License

The code is licensed under the Apache License Version 2.0