Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
@polkadot/ui-keyring
Advanced tools
A wrapper extending the base @polkadot/keyring interface for usage in the browser: Key management of user accounts including generation and retrieval of keyring pairs from a variety of input combinations.
A wrapper extending the base @polkadot/keyring interface for usage in the browser: Key management of user accounts including generation and retrieval of keyring pairs from a variety of input combinations.
All module methods are exposed through a single default export.
import keyring from @polkadot/ui-keyring
render () {
// encode publicKey to ss58 address
const address = keyring.encodeAddress(publicKey);
// get keyring pair from ss58 address
const pair = keyring.getPair(address);
// ask questions about that particular keyring pair
const isLocked = pair.isLocked;
const meta = pair.meta;
// save account from pair
keyring.saveAccount(pair, password);
// save address without unlocking it
keyring.saveAddress(address, { ...meta });
}
Option 1: Declarative subscribe/unsubscribe w/ react-with-observable (recommended 'React' way)
import accountObservable from '@polkadot/ui-keyring/observable/accounts';
import { SingleAddress, SubjectInfo } from '@polkadot/ui-keyring/observable/types';
import React from 'react';
import { Subscribe } from 'react-with-observable';
import { map } from 'rxjs';
class MyReactComponent extends React.PureComponent {
render () {
<Subscribe>
{accountObservable.subject.pipe(
map((allAccounts: SubjectInfo) =>
!allAccounts
? this.renderEmpty()
: Object.values(allAccounts).map((account: SingleAddress) =>
// Your component goes here
console.log(account.json.address)
)
))}
</Subscribe>
}
renderEmpty () {
return (
<div> no accounts to display ... </div>
);
}
}
Option 2: Imperative subscribe/unsubscribe
import accountObservable from '@polkadot/ui-keyring/observable/accounts';
import { SingleAddress, SubjectInfo } from '@polkadot/ui-keyring/observable/types';
import React from 'react';
import { Subscription } from 'rxjs';
type State = {
allAccounts?: SubjectInfo,
subscriptions?: [Subscription]
}
class MyReactComponent extends React.PureComponent<State> {
componentDidMount () {
const accountSubscription = accountObservable.subject.subscribe((observedAccounts) => {
this.setState({
accounts: observedAccounts
});
})
this.setState({
subscriptions: [accountSubscription]
});
}
componentWillUnmount () {
const { subscriptions } = this.state;
for (s in subscriptions) {
s.subject.unsubscribe();
}
}
render () {
const { accounts } = this.state;
return (
<h1>All Accounts</h1>
{
Object.keys(accounts).map((address: SingleAddress) => {
return <p> {address} </p>;
})
}
)
}
}
isExternal
meta key to true?
If you have any unanswered/undocumented questions, please raise an issue here.
Keyring is core to many polkadot/substrate apps.
FAQs
A wrapper extending the base @polkadot/keyring interface for usage in the browser: Key management of user accounts including generation and retrieval of keyring pairs from a variety of input combinations.
We found that @polkadot/ui-keyring demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.