Move solana-specific parts of crypto/ into sdk/
This commit is contained in:
parent
0e1afcbb26
commit
ae5d254e73
|
@ -0,0 +1,24 @@
|
|||
[package]
|
||||
name = "spl-zk-token-program-sdk"
|
||||
description = "Solana Program Library ZkToken Program SDK"
|
||||
authors = ["Solana Maintainers <maintainers@solana.foundation>"]
|
||||
repository = "https://github.com/solana-labs/solana-program-library"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
bytemuck = { version = "1.7.2", features = ["derive"] }
|
||||
#getrandom = { version = "0.1", features = ["dummy"] }
|
||||
num-derive = "0.3"
|
||||
num-traits = "0.2"
|
||||
solana-program = "=1.7.11"
|
||||
spl-zk-token-crypto = { path = "../crypto" }
|
||||
|
||||
#[features]
|
||||
#test-bpf = []
|
||||
#
|
||||
#[dev-dependencies]
|
||||
#assert_matches = "1.4.0"
|
||||
#solana-program-test = "=1.7.11"
|
||||
#solana-validator = "=1.7.11"
|
|
@ -0,0 +1,2 @@
|
|||
pub mod zk_token_proof_instruction;
|
||||
pub mod zk_token_proof_program;
|
|
@ -0,0 +1,92 @@
|
|||
///! Instructions provided by the ZkToken Proof program
|
||||
pub use spl_zk_token_crypto::instruction::*;
|
||||
|
||||
use {
|
||||
bytemuck::Pod,
|
||||
num_derive::{FromPrimitive, ToPrimitive},
|
||||
num_traits::{FromPrimitive, ToPrimitive},
|
||||
solana_program::{instruction::Instruction, pubkey::Pubkey},
|
||||
spl_zk_token_crypto::pod::*,
|
||||
};
|
||||
|
||||
#[derive(Clone, Copy, Debug, FromPrimitive, ToPrimitive, PartialEq)]
|
||||
#[repr(u8)]
|
||||
pub enum ProofInstruction {
|
||||
/// Verify a `UpdateAccountPkData` struct
|
||||
///
|
||||
/// Accounts expected by this instruction:
|
||||
/// None
|
||||
///
|
||||
/// Data expected by this instruction:
|
||||
/// `UpdateAccountPkData`
|
||||
///
|
||||
VerifyUpdateAccountPk,
|
||||
|
||||
/// Verify a `CloseAccountData` struct
|
||||
///
|
||||
/// Accounts expected by this instruction:
|
||||
/// None
|
||||
///
|
||||
/// Data expected by this instruction:
|
||||
/// `CloseAccountData`
|
||||
///
|
||||
VerifyCloseAccount,
|
||||
|
||||
/// Verify a `WithdrawData` struct
|
||||
///
|
||||
/// Accounts expected by this instruction:
|
||||
/// None
|
||||
///
|
||||
/// Data expected by this instruction:
|
||||
/// `WithdrawData`
|
||||
///
|
||||
VerifyWithdraw,
|
||||
|
||||
/// Verify a `TransferRangeProofData` struct
|
||||
///
|
||||
/// Accounts expected by this instruction:
|
||||
/// None
|
||||
///
|
||||
/// Data expected by this instruction:
|
||||
/// `TransferRangeProofData`
|
||||
///
|
||||
VerifyTransferRangeProofData,
|
||||
|
||||
/// Verify a `TransferValidityProofData` struct
|
||||
///
|
||||
/// Accounts expected by this instruction:
|
||||
/// None
|
||||
///
|
||||
/// Data expected by this instruction:
|
||||
/// `TransferValidityProofData`
|
||||
///
|
||||
VerifyTransferValidityProofData,
|
||||
}
|
||||
|
||||
impl ProofInstruction {
|
||||
pub fn encode<T: Pod>(&self, proof: &T) -> Instruction {
|
||||
let mut data = vec![ToPrimitive::to_u8(self).unwrap()];
|
||||
data.extend_from_slice(pod_bytes_of(proof));
|
||||
Instruction {
|
||||
program_id: crate::zk_token_proof_program::id(),
|
||||
accounts: vec![],
|
||||
data,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode_type(program_id: &Pubkey, input: &[u8]) -> Option<Self> {
|
||||
if *program_id != crate::zk_token_proof_program::id() || input.is_empty() {
|
||||
None
|
||||
} else {
|
||||
FromPrimitive::from_u8(input[0])
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode_data<T: Pod>(input: &[u8]) -> Option<&T> {
|
||||
if input.is_empty() {
|
||||
None
|
||||
} else {
|
||||
pod_from_bytes(&input[1..])
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
// Program Id of the ZkToken Proof program
|
||||
solana_program::declare_id!("ZkTokenProof1111111111111111111111111111111");
|
Loading…
Reference in New Issue