forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
513b8ac
commit 1f460af
Showing
5 changed files
with
36 additions
and
34 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,3 @@ | ||
//! `Keypair` Javascript interface | ||
#![cfg(target_arch = "wasm32")] | ||
#![allow(non_snake_case)] | ||
use { | ||
crate::signer::{keypair::Keypair, Signer}, | ||
solana_program::{pubkey::Pubkey, wasm::display_to_jsvalue}, | ||
wasm_bindgen::prelude::*, | ||
}; | ||
|
||
#[wasm_bindgen] | ||
impl Keypair { | ||
/// Create a new `Keypair ` | ||
#[wasm_bindgen(constructor)] | ||
pub fn constructor() -> Keypair { | ||
Keypair::new() | ||
} | ||
|
||
/// Convert a `Keypair` to a `Uint8Array` | ||
pub fn toBytes(&self) -> Box<[u8]> { | ||
self.to_bytes().into() | ||
} | ||
|
||
/// Recover a `Keypair` from a `Uint8Array` | ||
pub fn fromBytes(bytes: &[u8]) -> Result<Keypair, JsValue> { | ||
Keypair::from_bytes(bytes).map_err(display_to_jsvalue) | ||
} | ||
|
||
/// Return the `Pubkey` for this `Keypair` | ||
#[wasm_bindgen(js_name = pubkey)] | ||
pub fn js_pubkey(&self) -> Pubkey { | ||
// `wasm_bindgen` does not support traits (`Signer) yet | ||
self.pubkey() | ||
} | ||
} | ||
//! This module is empty but has not yet been removed because that would | ||
//! technically be a breaking change. There was never anything to import | ||
//! from here. |