How to use the @liskhq/lisk-cryptography.getAddressFromPublicKey function in @liskhq/lisk-cryptography

To help you get started, we’ve selected a few @liskhq/lisk-cryptography examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LiskHQ / lisk-sdk / framework / src / modules / chain / blocks / block_v2.js View on Github external
const block = {
		id: raw.b_id,
		version: parseInt(raw.b_version),
		timestamp: parseInt(raw.b_timestamp),
		height: parseInt(raw.b_height),
		maxHeightPreviouslyForged: parseInt(raw.b_maxHeightPreviouslyForged),
		prevotedConfirmedUptoHeight: parseInt(raw.b_prevotedConfirmedUptoHeight),
		previousBlock: raw.b_previousBlock,
		numberOfTransactions: parseInt(raw.b_numberOfTransactions),
		totalAmount: new BigNum(raw.b_totalAmount),
		totalFee: new BigNum(raw.b_totalFee),
		reward: new BigNum(raw.b_reward),
		payloadLength: parseInt(raw.b_payloadLength),
		payloadHash: raw.b_payloadHash,
		generatorPublicKey: raw.b_generatorPublicKey,
		generatorId: getAddressFromPublicKey(raw.b_generatorPublicKey),
		blockSignature: raw.b_blockSignature,
		confirmations: parseInt(raw.b_confirmations),
	};
	block.totalForged = block.totalFee.plus(block.reward).toString();
	return block;
};
github LiskHQ / lisk-sdk-examples / transport / client / scripts / create_and_initialize_packet_account.js View on Github external
const getPacketCredentials = () => {
    const passphrase = Mnemonic.generateMnemonic();
    const keys = cryptography.getPrivateAndPublicKeyFromPassphrase(
        passphrase
    );
    const credentials = {
        address: cryptography.getAddressFromPublicKey(keys.publicKey),
        passphrase: passphrase,
        publicKey: keys.publicKey,
        privateKey: keys.privateKey
    };
    return credentials;
};
github LiskHQ / lisk-sdk-examples / elements / lisk-transactions / src / 3_vote_transaction.ts View on Github external
try {
			validateAddress(this.recipientId);
		} catch (err) {
			errors.push(
				new TransactionError(
					'RecipientId must be set for vote transaction',
					this.id,
					'.recipientId',
					this.recipientId,
				),
			);
		}

		if (
			this.recipientPublicKey &&
			this.recipientId !== getAddressFromPublicKey(this.recipientPublicKey)
		) {
			errors.push(
				new TransactionError(
					'recipientId does not match recipientPublicKey.',
					this.id,
					'.recipientId',
				),
			);
		}

		if (!this.fee.eq(VOTE_FEE)) {
			errors.push(
				new TransactionError(
					`Fee must be equal to ${VOTE_FEE}`,
					this.id,
					'.fee',
github LiskArchive / lisk-elements / packages / lisk-transactions / src / 0_transfer.ts View on Github external
'Either recipientId or recipientPublicKey must be provided.',
		);
	}

	if (typeof recipientId !== 'undefined') {
		validateAddress(recipientId);
	}

	if (typeof recipientPublicKey !== 'undefined') {
		validatePublicKey(recipientPublicKey);
	}

	if (
		recipientId &&
		recipientPublicKey &&
		recipientId !== cryptography.getAddressFromPublicKey(recipientPublicKey)
	) {
		throw new Error('recipientId does not match recipientPublicKey.');
	}

	if (data && data.length > 0) {
		if (typeof data !== 'string') {
			throw new Error(
				'Invalid encoding in transaction data. Data must be utf-8 encoded string.',
			);
		}
		if (data.length > BYTESIZES.DATA) {
			throw new Error('Transaction data field cannot exceed 64 bytes.');
		}
	}
};
github LiskHQ / lisk-sdk / framework / src / modules / chain / forger / forger.js View on Github external
} = getPrivateAndPublicKeyBytesFromPassphrase(passphrase);

			keypair = {
				publicKey: publicKeyBytes,
				privateKey: privateKeyBytes,
			};
		} else {
			throw new Error(`Delegate with publicKey: ${publicKey} not found`);
		}

		if (keypair.publicKey.toString('hex') !== publicKey) {
			throw new Error('Invalid password and public key combination');
		}

		const filters = {
			address: getAddressFromPublicKey(keypair.publicKey.toString('hex')),
		};

		const [account] = await this.storage.entities.Account.get(filters);

		if (account && account.isDelegate) {
			if (forging) {
				this.keypairs[keypair.publicKey.toString('hex')] = keypair;
				this.logger.info(`Forging enabled on account: ${account.address}`);
			} else {
				delete this.keypairs[keypair.publicKey.toString('hex')];
				this.logger.info(`Forging disabled on account: ${account.address}`);
			}

			return {
				publicKey,
				forging,
github LiskHQ / lisk-sdk-examples / scripts / create_sendable_transaction_base_trs.js View on Github external
amount,
		asset,
		fee,
		type,
		recipientId,
		recipientPublicKey,
		senderPublicKey,
		passphrase,
		secondPassphrase,
		timestamp,
	} = inputs;

	inputs.asset = asset || {};
	inputs.timestamp = inputs.timestamp || 0;
	const recipientIdFromPublicKey = recipientPublicKey
		? getAddressFromPublicKey(recipientPublicKey)
		: undefined;

	inputs.recipientId = recipientIdFromPublicKey
		? recipientIdFromPublicKey
		: inputs.recipientId;


	if (!passphrase) {
		throw "Cannot sign a transaction without a passphrase. Specify your passphrase as in the input object (and optional second passphrase)";
	}

	const transaction = new Transaction(
		{
			asset: data ? { data } : asset,
			amount,
			fee,
github LiskHQ / lisk-sdk / framework / src / modules / chain / rounds / round.js View on Github external
p = new Promise((resolve, reject) => {
				const data = {
					publicKey: remainderDelegate,
					balance: feesRemaining,
					round: self.scope.round,
					fees: feesRemaining,
				};

				const address = getAddressFromPublicKey(data.publicKey);

				self.scope.library.account.merge(
					address,
					data,
					(err, account) => {
						if (err) {
							return reject(err);
						}
						return resolve(account);
					},
					self.t,
				);
			});
github LiskHQ / lisk-sdk / elements / lisk-transactions / src / utils / address.ts View on Github external
export const validateSenderIdAndPublicKey = (
	id: string,
	senderId: string,
	senderPublicKey: string,
): TransactionError | undefined => {
	const actualAddress = getAddressFromPublicKey(senderPublicKey);

	return senderId.toUpperCase() !== actualAddress.toUpperCase()
		? new TransactionError(
				'`senderId` does not match `senderPublicKey`',
				id,
				'.senderId',
				actualAddress,
				senderId,
		  )
		: undefined;
};
github LiskArchive / lisk-elements / packages / lisk-transactions / src / base_transaction.ts View on Github external
public getRequiredAttributes(): object {
		return {
			ACCOUNTS: [cryptography.getAddressFromPublicKey(this.senderPublicKey)],
		};
	}
github LiskArchive / lisk-elements / packages / lisk-node / tools / candidate.ts View on Github external
value.votedDelegatesPublicKeys.forEach((pk: string) => {
						const address = getAddressFromPublicKey(pk);
						if (resultMap.has(address)) {
							const original = resultMap.get(address);
							resultMap.set(
								address,
								new BigNum(original as string).add(value.balance).toString(),
							);
						} else {
							resultMap.set(address, value.balance);
						}
					});
				}