Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
cardano-wallet
Advanced tools
This is a new version of the Cardano Wasm binding for Icarus/Yoroi. It exposes everything one needs to be able to build a cardano wallet in javascript.
npm i --save cardano-wallet
You can seek documentation here regarding how to use this package in your project.
Now remember, with great power comes great responsibility. You can now write a cardano wallet, redeem your certificates, create and sign transactions.
The example below shows you how to create/retrieve a wallet from the mnemonics and the password.
import * as Cardano from "cardano-wallet";
const MNEMONICS = "crowd captain hungry tray powder motor coast oppose month shed parent mystery torch resemble index";
const PASSWORD = "Cardano Rust for the winners!";
// to connect the wallet to mainnet
let settings = Cardano.BlockchainSettings.mainnet();
// recover the entropy
let entropy = Cardano.Entropy.from_english_mnemonics(MNEMONICS);
// recover the wallet
let wallet = Cardano.Bip44RootPrivateKey.recover(entropy, PASSWORD);
// create a wallet account
let account = wallet.bip44_account(Cardano.AccountIndex.new(0 | 0x80000000));
let account_public = account.public();
// create an address
let chain_pub = account_public.bip44_chain(false);
let key_pub = chain_pub.address_key(Cardano.AddressKeyIndex.new(0));
let address = key_pub.bootstrap_era_address(settings);
console.log("Address m/bip44/ada/'0/0/0", address.to_base58());
The example below shows how to create a transaction, this transaction is not ready to be sent through the network. It shows that there is separation of concerns between the transaction you build/prepare and signing the transaction in the last example.
// assuming the xprv and the settings from the example above are available in this scope
const inputs = [
{ pointer: { id: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", index: 1 }, value: 1 },
{ pointer: { id: "fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210", index: 0 }, value: 1 }
];
const outputs = [
{ address: "Ae2tdPwUPEZCEhYAUVU7evPfQCJjyuwM6n81x6hSjU9TBMSy2YwZEVydssL", value: "1826205" }
];
// the fee algorithm (i.e. the function to compute the fees of a transaction)
const fee_algorithm = Wallet.LinearFeeAlgorithm.default();
let transaction_builder = new Wallet.TransactionBuilder();
for (let index = 0; index < inputs.length; index++) {
const pointer = Wallet.TxoPointer.from_json(inputs[index].pointer);
const value = Wallet.Coin.from(inputs[index].value, 0);
transaction_builder.add_input(pointer, value);
}
for (let index = 0; index < outputs.length; index++) {
const txout = Wallet.TxOut.from_json(outputs[index]);
transaction_builder.add_output(txout);
}
// verify the balance and the fees:
const balance = transaction_builder.get_balance(fee_algorithm);
if (balance.is_negative()) {
console.error("not enough inputs, ", balance.value().to_str());
throw Error("Not enough inputs");
} else {
if (balance.is_zero()) {
console.info("Perfect balance no dust");
} else {
console.warn("Loosing some coins in extra fees: ", balance.value().to_str());
}
}
// Warning: this function does not throw exception if the transaction is not
// balanced. This is your job to make sure your transaction's inputs and outputs
// and fees are balanced.
let transaction = transaction_builder.make_transaction();
This function shows how to sign a transaction so it can be accepted by the network.
You need to make sure:
// retrieve the prepared transaction from the previous example
let transaction_finalizer = new Wallet.TransactionFinalized(transaction);
for (let index = 0; index < inputs.length; index++) {
const witness = Wallet.Witness.new_extended_key(
settings,
key_prv,
transaction_finalizer.id()
);
transaction_finalizer.add_witness(witness);
}
// at this stage the transaction is ready to be sent
const signed_transaction = transaction_finalizer.finalize();
console.log("ready to send transaction: ", signed_transaction.to_hex());
console.log(signed_transaction.to_json());
wasm-pack build --target browser
npm install
npm run serve
FAQs
Cardano Wallet, from rust to JS via Wasm
We found that cardano-wallet demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.