0.0.2 • Published 5 years ago
bvcadt-crypto-core v0.0.2
bvcadt-crypto-core
const API = require('bvcadt-crypto-core');
const wallet = API.generateAddress().wallet;
const wallet1 = API.generateAddress(wallet.secret).wallet;
console.log(JSON.stringify(wallet));
console.log(JSON.stringify(wallet1));
console.log("valid: " + API.isValidAddress(wallet.address).wallet + "\n");
const address = "bpfaZZjXW2vLZqgUihwYq3VKKLVt7x2xyT";
const secret = "snD5uxaSjpNnCVrvfmn3mj8rRXGD9";
const to = "bfFqAsr23bFyEYYeqy9HJGBzAMdnGtTW18"; // shUCAJ8E8YvL7Y6KvsNa1JmhzACsP
const memoType = API.base.utils.convertStringToHex("TEXT");
const memoData = API.base.utils.convertStringToHex("hello");
const txJson = {
"TransactionType": "Payment",
"Account": address,
"Destination": to,
"Amount": "1000000",
"Fee": "10000",
"Flags": 2147483648,
"Memos": [{
"Memo": {
"MemoType": memoType,
"MemoData": memoData
}
}],
"Sequence": 1
};
// Sign
const resSign = API.sign(txJson, secret);
console.log("hash : " + resSign.hash);
console.log("txBlob: " + resSign.signedTransaction + "\n");
// MultiSign
const mTxJson = {
"TransactionType": "Payment",
"Account": address,
"Amount": "1000000",
"Destination": to,
"Sequence": 1,
"Flags": 2147483648,
"Fee": "" + (100 * (2 + 1))
};
const signedFor = API.signFor(mTxJson, 'shaVtrLD6Kopcha3ePjn4fCqgHvtR', 'bPRDVxsqUWTt3LSRmSRHR7uumb39Frn4gR');
console.log(JSON.stringify(signedFor));
const signedFor1 = API.signFor(mTxJson, 'saw37toPPJ2tA18f2Hmj4VsfC1Nyz', 'bFYZML6ZNWVysdapxFTUxmEKKgRuzXoZe');
console.log(JSON.stringify(signedFor1));
mTxJson.SigningPubKey = '';
mTxJson.Signers = [];
mTxJson.Signers = mTxJson.Signers.concat(signedFor.Signers);
mTxJson.Signers = mTxJson.Signers.concat(signedFor1.Signers);
console.log(JSON.stringify(mTxJson));
const serialized = API.serialize(mTxJson);
console.log(JSON.stringify(serialized));