11//! Public key type and functions.
22
3+ use crate :: memory:: { sol_memcmp, sol_memcpy} ;
4+
5+ /// Number of bytes in a pubkey
6+ pub const PUBKEY_BYTES : usize = 32 ;
7+
38/// maximum length of derived `Pubkey` seed
49pub const MAX_SEED_LEN : usize = 32 ;
510
@@ -9,10 +14,28 @@ pub const MAX_SEEDS: usize = 16;
914/// The address of a [Solana account][account].
1015///
1116/// [account]: https://solana.com/docs/core/accounts
12- pub type Pubkey = [ u8 ; 32 ] ;
17+ pub type Pubkey = [ u8 ; PUBKEY_BYTES ] ;
18+
19+ /// Checks two pubkeys for equality in a computationally efficient way using
20+ /// `sol_memcmp`.
21+ pub fn compare ( a : & Pubkey , b : & Pubkey ) -> bool {
22+ // Safety:
23+ //
24+ // This method guarantees that the two arrays are of the same length.
25+ unsafe { sol_memcmp ( a, b, PUBKEY_BYTES ) == 0 }
26+ }
27+
28+ /// Copy `source` pubkey into `destination` in a computationally efficient way
29+ /// using `sol_memcpy`.
30+ pub fn copy ( destination : & mut Pubkey , source : & Pubkey ) {
31+ // Safety:
32+ //
33+ // This method guarantees that the two arrays are of the same length.
34+ unsafe { sol_memcpy ( destination, source, PUBKEY_BYTES ) }
35+ }
1336
1437/// Log a `Pubkey` from a program
15- pub fn log_pubkey ( pubkey : & Pubkey ) {
38+ pub fn log ( pubkey : & Pubkey ) {
1639 #[ cfg( target_os = "solana" ) ]
1740 unsafe {
1841 crate :: syscalls:: sol_log_pubkey ( pubkey as * const _ as * const u8 )
0 commit comments