Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function encode(private_key, public_key, memo, testNonce) {
assert(memo, 'memo is required')
assert.equal(typeof memo, 'string', 'memo')
if(!/^#/.test(memo)) return memo
memo = memo.substring(1)
assert(private_key, 'private_key is required')
assert(public_key, 'public_key is required')
const mbuf = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN)
mbuf.writeVString(memo)
memo = new Buffer(mbuf.copy(0, mbuf.offset).toBinary(), 'binary')
const {nonce, message, checksum} = Aes.encrypt(private_key, public_key, memo, testNonce)
memo = encMemo.fromObject({
from: private_key.toPublicKey(),
to: public_key,
nonce,
check: checksum,
encrypted: message
})
// serialize
memo = encMemo.toBuffer(memo)
return '#' + base58.encode(new Buffer(memo, 'binary'))
}
throw new TypeError('public_key is required')
nonce = toLongObj(nonce)
if (!nonce)
throw new TypeError('nonce is required')
if (!Buffer.isBuffer(message)) {
if (typeof message !== 'string')
throw new TypeError('message should be buffer or string')
message = new Buffer(message, 'binary')
}
if (checksum && typeof checksum !== 'number')
throw new TypeError('checksum should be a number')
const S = private_key.get_shared_secret(public_key);
let ebuf = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN)
ebuf.writeUint64(nonce)
ebuf.append(S.toString('binary'), 'binary')
ebuf = new Buffer(ebuf.copy(0, ebuf.offset).toBinary(), 'binary')
const encryption_key = hash.sha512(ebuf)
// D E B U G
// console.log('crypt', {
// priv_to_pub: private_key.toPublicKey().toString(),
// pub: public_key.toString(),
// nonce: nonce.toString(),
// message: message.length,
// checksum,
// S: S.toString('hex'),
// encryption_key: encryption_key.toString('hex'),
// })
private getBytes(genesisBlock) {
const size = 4 + 4 + 4 + 8 + 4 + 4 + 8 + 8 + 4 + 4 + 4 + 32 + 32 + 64;
const byteBuffer = new ByteBuffer(size, true);
byteBuffer.writeInt(genesisBlock.version);
byteBuffer.writeInt(genesisBlock.timestamp);
byteBuffer.writeInt(genesisBlock.height);
for (let i = 0; i < 8; i++) {
byteBuffer.writeByte(0); // no previous block
}
byteBuffer.writeInt(genesisBlock.numberOfTransactions);
byteBuffer.writeLong(genesisBlock.totalAmount);
byteBuffer.writeLong(genesisBlock.totalFee);
byteBuffer.writeLong(genesisBlock.reward);
byteBuffer.writeInt(genesisBlock.payloadLength);
const payloadHashBuffer = Buffer.from(genesisBlock.payloadHash, "hex");
if (businessUpdateAsset.website) {
businessWebsite = Buffer.from(businessUpdateAsset.website, "utf8");
businessWebsiteLength = businessWebsite.length;
}
if (businessUpdateAsset.vat) {
businessVat = Buffer.from(businessUpdateAsset.vat, "utf8");
businessVatLength = businessVat.length;
}
if (businessUpdateAsset.repository) {
businessRepository = Buffer.from(businessUpdateAsset.repository, "utf8");
businessRepositoryLength = businessRepository.length;
}
const buffer: ByteBuffer = new ByteBuffer(
businessNameLength + businessWebsiteLength + businessVatLength + businessRepositoryLength + 4,
true,
);
buffer.writeByte(businessNameLength);
if (businessNameLength !== 0) {
buffer.append(businessName);
}
buffer.writeByte(businessWebsiteLength);
if (businessWebsiteLength !== 0) {
buffer.append(businessWebsite);
}
buffer.writeByte(businessVatLength);
if (businessVatLength !== 0) {
public static serialize(block: IBlockData, includeSignature: boolean = true): Buffer {
const buffer: ByteBuffer = new ByteBuffer(512, true);
this.serializeHeader(block, buffer);
if (includeSignature) {
this.serializeSignature(block, buffer);
}
return buffer.flip().toBuffer();
}
private getByteBuffer(serialized: Buffer | string): ByteBuffer {
if (!(serialized instanceof Buffer)) {
serialized = Buffer.from(serialized, "hex");
}
const buffer: ByteBuffer = new ByteBuffer(serialized.length, true);
buffer.append(serialized);
buffer.reset();
return buffer;
}
}
write(classFile) {
this.buf = new ByteBuffer();
this.classFile = classFile;
this.buf.writeUint8(0xCA);
this.buf.writeUint8(0xFE);
this.buf.writeUint8(0xBA);
this.buf.writeUint8(0xBE);
this.buf.writeUint16(classFile.minor_version);
this.buf.writeUint16(classFile.major_version);
this.buf.writeUint16(classFile.constant_pool_count);
this._writeConstantPool(classFile.constant_pool);
this.buf.writeUint16(classFile.access_flags);
this.buf.writeUint16(classFile.this_class);
this.buf.writeUint16(classFile.super_class);
public serialize(options?: ISerializeOptions): ByteBuffer {
const { data } = this;
const buffer: ByteBuffer = new ByteBuffer(4 + 1 + 4 + 24, true);
buffer.writeUint64(+data.amount.toFixed());
buffer.writeByte(data.timelockType);
buffer.writeUint64(data.timelock);
buffer.append(bs58check.decode(data.recipientId));
return buffer;
}