Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@cosmjs/proto-signing
Advanced tools
Utilities for protobuf based signing (Cosmos SDK 0.40+)
@cosmjs/proto-signing is a JavaScript library for creating, signing, and broadcasting transactions in the Cosmos ecosystem. It provides tools for working with protocol buffers and signing transactions using various key management solutions.
Creating a Signer
This feature allows you to create a signer using a mnemonic. The code sample demonstrates how to create a wallet from a mnemonic and retrieve the first account's address.
const { DirectSecp256k1HdWallet } = require('@cosmjs/proto-signing');
async function createSigner() {
const mnemonic = 'your mnemonic here';
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic);
const [firstAccount] = await wallet.getAccounts();
console.log(firstAccount.address);
}
createSigner();
Signing a Transaction
This feature allows you to sign a transaction. The code sample demonstrates how to create a transaction body, encode it, and sign it using a wallet created from a mnemonic.
const { DirectSecp256k1HdWallet, Registry, encodePubkey, makeAuthInfoBytes, makeSignDoc, TxBodyEncodeObject } = require('@cosmjs/proto-signing');
const { coins } = require('@cosmjs/stargate');
async function signTransaction() {
const mnemonic = 'your mnemonic here';
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic);
const [firstAccount] = await wallet.getAccounts();
const registry = new Registry();
const txBody = {
typeUrl: '/cosmos.tx.v1beta1.TxBody',
value: {
messages: [
{
typeUrl: '/cosmos.bank.v1beta1.MsgSend',
value: {
fromAddress: firstAccount.address,
toAddress: 'cosmos1recipientaddress',
amount: coins(1000, 'ucosm'),
},
},
],
},
};
const txBodyBytes = registry.encode(txBody);
const gasLimit = 200000;
const authInfoBytes = makeAuthInfoBytes(
[{ pubkey: encodePubkey(firstAccount.pubkey), sequence: 0 }],
coins(2000, 'ucosm'),
gasLimit
);
const chainId = 'cosmoshub-4';
const signDoc = makeSignDoc(txBodyBytes, authInfoBytes, chainId, 0);
const { signed, signature } = await wallet.signDirect(firstAccount.address, signDoc);
console.log(signed, signature);
}
signTransaction();
Broadcasting a Transaction
This feature allows you to broadcast a signed transaction to the Cosmos network. The code sample demonstrates how to connect to a Cosmos RPC endpoint and broadcast a signed transaction.
const { StargateClient } = require('@cosmjs/stargate');
async function broadcastTransaction() {
const client = await StargateClient.connect('https://rpc.cosmos.network');
const txRaw = 'your signed transaction here';
const result = await client.broadcastTx(txRaw);
console.log(result);
}
broadcastTransaction();
cosmos-client is a JavaScript library for interacting with the Cosmos SDK-based blockchains. It provides functionalities for creating, signing, and broadcasting transactions, similar to @cosmjs/proto-signing, but with a different API design and additional features for querying blockchain data.
Utilities for protobuf based signing (for Cosmos SDK 0.40+) as documented in ADR-020 and The 3 levels of proto encoding.
This package is part of the cosmjs repository, licensed under the Apache License 2.0 (see NOTICE and LICENSE).
FAQs
Utilities for protobuf based signing (Cosmos SDK 0.40+)
The npm package @cosmjs/proto-signing receives a total of 165,747 weekly downloads. As such, @cosmjs/proto-signing popularity was classified as popular.
We found that @cosmjs/proto-signing 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.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.