Here we propose the example of simple transaction from default account(ed25519) to any other account
Also, read more about our default ed25519 accounts in MasteringKlyntar
Generate keypair
import {crypto} from'web1337';let mnemonic =""// mnemonic should be empty in case you generate a new pairlet mnemonicPassword =""// set the password for your mnemoniclet bip44Path = [44,7331,0,0] // 7331 is KLY ID and the next values - derivation pathlet keypair =awaitcrypto.ed25519.generateDefaultEd25519Keypair(mnemonic,mnemonicPassword,bip44Path);console.log(keypair);
import"fmt"import ed25519 "github.com/KLYN74R/Web1337Golang/crypto_primitives/ed25519"funcmain() { mnemonic :=""// mnemonic should be empty in case you generate a new pair mnemonicPassword :=""// set the password for your mnemonic bip44Path := []uint32{44, 7331, 0, 0} // 7331 is KLY ID and the next values - derivation path keypair := ed25519.GenerateKeyPair(mnemonic, mnemonicPassword, bip44Path) fmt.Println(keypair)}
Output:
{mnemonic:'job october hold grape novel horror stay major pledge bonus energy fringe',bip44Path:"m/44'/7331'/0'/0'",pub:'GbjtpGjt1G9pJe667cQcBswRMGq9XogmrGEGUj94enuc',prv:'MC4CAQAwBQYDK2VwBCIEIMOJVCiaURXxlZrkXe+fa2r061eqdOQAxux1/gxDGRi9'}
Tricks with BIP-44
By default, you get the new mnemonic and key pair with m/44'/7331'/0'/0' path. But, to generate many accounts from a single seed do this:
Get the mnemonic from the first generation
Change the path to 1,2,3... to build the HD chain of accounts
For the first pair in future chain of accounts we don't set the mnemonic and BIP-44 path. Mnemonic will be randomly generated and path will be m/44'/7331'/0'/0'. The last parameter is the password that will be used to get the seed from your mnemonic.
That's why - choose the password with the high entropy, ommiting typical passwords from well known wordlists to make brute force impossible. Also, DON'T SHARE YOUR MNEMONIC PHRASE - YOU WILL LOST CONTROL OF YOUR ACCOUNT.
let txStatus =awaitweb1337.sendTransaction(signedTx);console.log(txStatus);// After that - you can check the tx receipt// TxID - it's a BLAKE3 hash of transaction signaturelet receipt =awaitweb1337.getTransactionReceiptById(web1337.BLAKE3(signedTx.sig));console.log(receipt);
isOk - status to check if tx successfully processed or not
Ed25519 => BLS(multisig address) transaction
A transfer transaction to a multisig address is literally 1 step more complicated. So, when you are going to send something to a multisig address, depending on whether the recipient's account already exists on the network, you need to specify an additional rev_t field that indicates the reverse threshold.
What is reverse threshold?
Imagine that you and your 3 friends are going to manage some resources together, whether it be native KLY coins or some tokens. For this, it is obviously worth using a multisig address.
Let's assume that you agree that the decision is considered accepted if the voting threshold of 3/4 is reached (3 out of 4 friends agree to spend coins or call some kind of smart contract). So, if the threshold is 3/4, then the reverse threshold in this case will be 1 (because 4-3 = 1).
Here are some examples for other cases:
Reverse threshold = 3 for a situation where you need 7/10 agreements
Reverse threshold = 2 for a situation where you need 3/5 agreements
And so on
The reverse threshold was introduced in response to the ability of BLS signatures and public keys to aggregation. Since the situation is often such that
T>TβN
where:
N is the number of sides of the multi-signature
T is the threshold
and when checking the signature we need to know whether the threshold has been reached, then we need to do this:
Present the consenting parties as an aggregated public key and an aggregated BLS signature
In a separate array, present the public BLS keys of those who do not agree with the decision (or could not vote for some reason)
Going back to the 4 friends example, if we have a threshold of 3/4, then it makes more sense to aggregate 3 signatures and 3 public keys into 1 and separately present 1 public key of the one who disagrees than to provide 3 separate keys and signatures from 4.
Let's look at a specific example
You and 3 your friends generate multisig pairs(public + private key) locally. Let's do it with Web1337:
When you need to send something to multisig account you need to set the reverse threshold if account still not exists or use `rev_t` property of already existed account
So, if account 68Bpgi6MbRX9q3T9h8DDWomPGu85HqWSfPMT23r6g29xyn1dN7qfquwxpfFNMdMpU1 still not in state - use this template:
constmyKeyPair= { mnemonic:'south badge state hedgehog carpet aerobic float million enforce opinion hungry race', bip44Path:"m/44'/7331'/0'/0'", pub:'2VEzwUdvSRuv1k2JaAEaMiL7LLNDTUf9bXSapqccCcSb', prv:'MC4CAQAwBQYDK2VwBCIEIDEf/4H5iiY3ebAfWsFIFkeZrB8HpcvBYK5zjEe9/8ga'};constshardID='7GPupbq1vtKUgaqVeHiDbEJcxS7sSjwPnbht4eRaDBAEJv8ZKHNCSu2Am3CuWnHjta';constrecipient='68Bpgi6MbRX9q3T9h8DDWomPGu85HqWSfPMT23r6g29xyn1dN7qfquwxpfFNMdMpU1';constfrom=myKeyPair.pub;constmyPrivateKey=myKeyPair.prv;constnonce=0;constfee=1;constamountInKLY=13.37;// In our example with 4 friends, since we want 3/4 agreements// to use account, the reverse threshold will be 4-3=1// Use the formula rev_t = N-T where N - number of sides, T-thresholdconstreverseThreshold=1;let signedTx = await web1337.createDefaultTransaction(shardID,from,myPrivateKey,nonce,recipient,fee,amountInKLY,reverseThreshold);
console.log(signedTx);
As you see, new multisig account is created and binded to shard where sender sends KLY. Also, the rev_t is set to 1 what means that the number of dissenting sides can be 1.
In case account was already in state - get the rev_t from information about account:
In this transaction you send your assets to the BLAKE3 hash of public key of some post-quantum signatures schemes like DIlithium or BLISS (we support 2 algorithms)
We'll talk about PQC accounts later. Just now, as a sender you just need to know only the address of recipient - it's 256-bit hash of public key
constmyKeyPair= { mnemonic:'south badge state hedgehog carpet aerobic float million enforce opinion hungry race', bip44Path:"m/44'/7331'/0'/0'", pub:'2VEzwUdvSRuv1k2JaAEaMiL7LLNDTUf9bXSapqccCcSb', prv:'MC4CAQAwBQYDK2VwBCIEIDEf/4H5iiY3ebAfWsFIFkeZrB8HpcvBYK5zjEe9/8ga'};constshardID='7GPupbq1vtKUgaqVeHiDbEJcxS7sSjwPnbht4eRaDBAEJv8ZKHNCSu2Am3CuWnHjta';// It might be Dilithium or BLISS, but doesn't matter for youconstrecipientPQC='f5091405e28455880fc4191cbda9f1e57f72399e732222d4639294b66d3a5076';constfrom=myKeyPair.pub;constmyPrivateKey=myKeyPair.prv;constnonce=0;constfee=1;constamountInKLY=13.37;let signedTx = await web1337.createDefaultTransaction(shardID,from,myPrivateKey,nonce,recipientTblsRootPub,fee,amountInKLY);
console.log(signedTx);