Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
() => {
const fileData = libs.crypto
.bytesToString(libs.crypto.base64Decode(reader.result.split(',')[1]));
this.backup = FromBackupCtrl.parseUsers(fileData);
this.readError = null;
}
).catch(() => {
onSubmit() {
const users = Object.entries(this.checkedHash)
.filter(item => item[1])
.map(([address]) => this.userList.find(user => user.address === address));
const stringifyUsers = JSON.stringify(users);
const saveUsers = !this.needPassword ?
stringifyUsers :
encryptSeed(stringifyUsers, this.password, 10000);
const saveData = {
encrypted: this.needPassword,
encryptionRounds: this.needPassword ? 10000 : undefined,
saveUsers
};
const dataToSaveInBytes = crypto.stringToBytes(JSON.stringify(saveData));
saveData.hashSum = crypto.base58Encode(crypto.sha256(dataToSaveInBytes));
const toSave = {
type: 'wavesBackup',
lastOpenVersion: this.settings.lastOpenVersion,
data: crypto.base64Encode(crypto.stringToBytes(JSON.stringify(saveData))),
checkSum: saveData.hashSum,
time: Date.now()
};
utils.downloadFile(`accountsBackup-${toSave.time}.json`, JSON.stringify(toSave, null, 4));
}
if (verified === false) {
res.status(403);
res.json({ message: 'Signature is not valid' });
}
const recipient = process.env.NETWORK === 'testnet' ? address(process.env.SPONSOR_SEED, 'T') : address(process.env.SPONSOR_SEED);
const signedTranserTx = transfer({
amount: 1,
recipient: recipient,
assetId: process.env.ASSET_ID,
feeAssetId: process.env.ASSET_ID,
chainId: process.env.NETWORK === 'testnet' ? 'T' : 'W',
attachment: Base58.encode(Buffer.from(ipfsHash))
}, process.env.SPONSOR_SEED);
broadcast(signedTranserTx, process.env.NODE_URL)
.then(tx => {
res.json({tx: tx});
})
.catch(e => {
console.log('Error', e);
res.status(400)
res.json({'error': e.message});
})
});
onSubmit() {
const users = Object.entries(this.checkedHash)
.filter(item => item[1])
.map(([address]) => this.userList.find(user => user.address === address));
const stringifyUsers = JSON.stringify(users);
const saveUsers = !this.needPassword ?
stringifyUsers :
encryptSeed(stringifyUsers, this.password, 10000);
const saveData = {
encrypted: this.needPassword,
encryptionRounds: this.needPassword ? 10000 : undefined,
saveUsers
};
const dataToSaveInBytes = crypto.stringToBytes(JSON.stringify(saveData));
saveData.hashSum = crypto.base58Encode(crypto.sha256(dataToSaveInBytes));
const toSave = {
type: 'wavesBackup',
lastOpenVersion: this.settings.lastOpenVersion,
data: crypto.base64Encode(crypto.stringToBytes(JSON.stringify(saveData))),
checkSum: saveData.hashSum,
const controller = function (Base, $scope, user, utils) {
const { encryptSeed } = require('@waves/waves-transactions').seedUtils;
const { crypto } = require('@waves/waves-transactions').libs;
const { publicKey: getPublicKey, address: getAddress, base58Decode } = crypto;
const checkAccount = (account) => {
if (!account) {
return false;
}
const { address, userType, networkByte } = account;
let publicKey = '';
switch (userType) {
case 'seed':
try {
if (/^base58:/.test(account.seed)) {
publicKey = getPublicKey(base58Decode(account.seed.replace('base58:', '')));
const controller = function (Base, $scope, user, utils) {
const { encryptSeed } = require('@waves/waves-transactions').seedUtils;
const { crypto } = require('@waves/waves-transactions').libs;
const { publicKey: getPublicKey, address: getAddress, base58Decode } = crypto;
const checkAccount = (account) => {
if (!account) {
return false;
}
const { address, userType, networkByte } = account;
let publicKey = '';
switch (userType) {
case 'seed':
try {
if (/^base58:/.test(account.seed)) {
if (!ipfsHash) {
res.status(400);
res.json({ message: 'IPFS Hash is not provided' })
}
const bytes = Uint8Array.from(publicKey);
const verified = verifySignature(publicKey, bytes, signature);
if (verified === false) {
res.status(403);
res.json({ message: 'Signature is not valid' });
}
const recipient = process.env.NETWORK === 'testnet' ? address(process.env.SPONSOR_SEED, 'T') : address(process.env.SPONSOR_SEED);
const signedTranserTx = transfer({
amount: 1,
recipient: recipient,
assetId: process.env.ASSET_ID,
feeAssetId: process.env.ASSET_ID,
chainId: process.env.NETWORK === 'testnet' ? 'T' : 'W',
attachment: Base58.encode(Buffer.from(ipfsHash))
}, process.env.SPONSOR_SEED);
broadcast(signedTranserTx, process.env.NODE_URL)
.then(tx => {
res.json({tx: tx});
})
.catch(e => {
console.log('Error', e);
res.status(400)
res.json({'error': e.message});
static createUserId() {
const date = Date.now();
const random = Math.round(Math.random() * 1000000000);
return libs.crypto.base58Encode(libs.crypto.sha256(libs.crypto.stringToBytes(`${date}-${random}`)));
}
]).then(([seed, privateKey, publicKey, encodedSeed]) => {
let canSeed = encodedSeed && seed && typeof seed === 'string';
try {
canSeed = canSeed && libs.crypto.stringToBytes(seed)
.join(',') === libs.crypto.base58Decode(encodedSeed).join(',');
} catch (e) {
canSeed = false;
}
this.phrase = canSeed ? seed : null;
this.encodedSeed = encodedSeed;
this.privateKey = privateKey;
this.publicKey = publicKey;
this.allowParing = canSeed;
$scope.$digest();
});
}
export function networkByteFromAddress(address: string): string {
return String.fromCharCode(libs.crypto.base58Decode(address)[1]);
}