@liskhq/lisk-transactions
Advanced tools
Comparing version 5.2.2 to 6.0.0-beta.0
@@ -1,13 +0,10 @@ | ||
interface BaseFee { | ||
readonly moduleID: number; | ||
readonly assetID: number; | ||
readonly baseFee: string; | ||
} | ||
interface Options { | ||
export interface Options { | ||
readonly minFeePerByte?: number; | ||
readonly baseFees?: BaseFee[]; | ||
readonly numberOfSignatures?: number; | ||
readonly numberOfEmptySignatures?: number; | ||
readonly additionalFee?: bigint; | ||
} | ||
export declare const computeMinFee: (assetSchema: object, trx: Record<string, unknown>, options?: Options | undefined) => bigint; | ||
export {}; | ||
export declare const DEFAULT_MIN_FEE_PER_BYTE = 1000; | ||
export declare const DEFAULT_NUMBER_OF_SIGNATURES = 1; | ||
export declare const DEFAULT_SIGNATURE_BYTE_SIZE = 64; | ||
export declare const computeMinFee: (trx: Record<string, unknown>, assetSchema?: object, options?: Options) => bigint; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.computeMinFee = void 0; | ||
exports.computeMinFee = exports.DEFAULT_SIGNATURE_BYTE_SIZE = exports.DEFAULT_NUMBER_OF_SIGNATURES = exports.DEFAULT_MIN_FEE_PER_BYTE = void 0; | ||
const sign_1 = require("./sign"); | ||
const DEFAULT_MIN_FEE_PER_BYTE = 1000; | ||
const DEFAULT_NUMBER_OF_SIGNATURES = 1; | ||
const DEFAULT_BASE_FEE = '0'; | ||
const DEFAULT_SIGNATURE_BYTE_SIZE = 64; | ||
const computeTransactionMinFee = (assetSchema, trx, options) => { | ||
var _a, _b, _c, _d, _e; | ||
const mockSignatures = new Array((_a = options === null || options === void 0 ? void 0 : options.numberOfSignatures) !== null && _a !== void 0 ? _a : DEFAULT_NUMBER_OF_SIGNATURES).fill(Buffer.alloc(DEFAULT_SIGNATURE_BYTE_SIZE)); | ||
exports.DEFAULT_MIN_FEE_PER_BYTE = 1000; | ||
exports.DEFAULT_NUMBER_OF_SIGNATURES = 1; | ||
exports.DEFAULT_SIGNATURE_BYTE_SIZE = 64; | ||
const computeMinFee = (trx, assetSchema, options) => { | ||
var _a, _b, _c; | ||
const mockSignatures = new Array((_a = options === null || options === void 0 ? void 0 : options.numberOfSignatures) !== null && _a !== void 0 ? _a : exports.DEFAULT_NUMBER_OF_SIGNATURES).fill(Buffer.alloc(exports.DEFAULT_SIGNATURE_BYTE_SIZE)); | ||
if (options === null || options === void 0 ? void 0 : options.numberOfEmptySignatures) { | ||
mockSignatures.push(...new Array(options.numberOfEmptySignatures).fill(Buffer.alloc(0))); | ||
} | ||
const size = sign_1.getBytes(assetSchema, { | ||
...trx, | ||
signatures: mockSignatures, | ||
}).length; | ||
const baseFee = (_d = (_c = (_b = options === null || options === void 0 ? void 0 : options.baseFees) === null || _b === void 0 ? void 0 : _b.find(bf => bf.moduleID === trx.moduleID && bf.assetID === trx.assetID)) === null || _c === void 0 ? void 0 : _c.baseFee) !== null && _d !== void 0 ? _d : DEFAULT_BASE_FEE; | ||
return BigInt(size * ((_e = options === null || options === void 0 ? void 0 : options.minFeePerByte) !== null && _e !== void 0 ? _e : DEFAULT_MIN_FEE_PER_BYTE)) + BigInt(baseFee); | ||
}; | ||
const computeMinFee = (assetSchema, trx, options) => { | ||
const { fee, ...trxWithoutFee } = trx; | ||
trxWithoutFee.fee = BigInt(0); | ||
let minFee = computeTransactionMinFee(assetSchema, trxWithoutFee, options); | ||
while (minFee > BigInt(trxWithoutFee.fee)) { | ||
trxWithoutFee.fee = minFee; | ||
minFee = computeTransactionMinFee(assetSchema, trxWithoutFee, options); | ||
} | ||
const { ...transaction } = trx; | ||
transaction.signatures = mockSignatures; | ||
transaction.fee = BigInt(0); | ||
const additionalFee = (_b = options === null || options === void 0 ? void 0 : options.additionalFee) !== null && _b !== void 0 ? _b : BigInt(0); | ||
let minFee = additionalFee; | ||
do { | ||
transaction.fee = minFee; | ||
const transactionSize = (0, sign_1.getBytes)(transaction, assetSchema).length; | ||
minFee = | ||
BigInt(transactionSize * ((_c = options === null || options === void 0 ? void 0 : options.minFeePerByte) !== null && _c !== void 0 ? _c : exports.DEFAULT_MIN_FEE_PER_BYTE)) + | ||
additionalFee; | ||
} while (minFee > BigInt(transaction.fee)); | ||
return minFee; | ||
@@ -31,0 +27,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
export declare const convertBeddowsToLSK: (beddowsAmount?: string | undefined) => string; | ||
export declare const convertLSKToBeddows: (lskAmount?: string | undefined) => string; | ||
export declare const convertBeddowsToLSK: (beddowsAmount?: string) => string; | ||
export declare const convertLSKToBeddows: (lskAmount?: string) => string; |
@@ -1,4 +0,6 @@ | ||
export { computeMinFee } from './fee'; | ||
export { Options, computeMinFee, DEFAULT_MIN_FEE_PER_BYTE, DEFAULT_NUMBER_OF_SIGNATURES, DEFAULT_SIGNATURE_BYTE_SIZE, } from './fee'; | ||
export { convertBeddowsToLSK, convertLSKToBeddows } from './format'; | ||
export { getBytes, getSigningBytes, signTransaction, signMultiSignatureTransaction, signMultiSignatureTransactionWithPrivateKey, signTransactionWithPrivateKey, } from './sign'; | ||
export { MultiSignatureKeys, getBytes, getSigningBytes, signTransaction, signMultiSignatureTransaction, signTransactionWithPrivateKey, signMultiSignatureTransactionWithPrivateKey, } from './sign'; | ||
export { validateTransaction } from './validate'; | ||
export * from './constants'; | ||
export { baseTransactionSchema } from './schema'; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.validateTransaction = exports.signTransactionWithPrivateKey = exports.signMultiSignatureTransactionWithPrivateKey = exports.signMultiSignatureTransaction = exports.signTransaction = exports.getSigningBytes = exports.getBytes = exports.convertLSKToBeddows = exports.convertBeddowsToLSK = exports.computeMinFee = void 0; | ||
exports.baseTransactionSchema = exports.validateTransaction = exports.signMultiSignatureTransactionWithPrivateKey = exports.signTransactionWithPrivateKey = exports.signMultiSignatureTransaction = exports.signTransaction = exports.getSigningBytes = exports.getBytes = exports.convertLSKToBeddows = exports.convertBeddowsToLSK = exports.DEFAULT_SIGNATURE_BYTE_SIZE = exports.DEFAULT_NUMBER_OF_SIGNATURES = exports.DEFAULT_MIN_FEE_PER_BYTE = exports.computeMinFee = void 0; | ||
var fee_1 = require("./fee"); | ||
Object.defineProperty(exports, "computeMinFee", { enumerable: true, get: function () { return fee_1.computeMinFee; } }); | ||
Object.defineProperty(exports, "DEFAULT_MIN_FEE_PER_BYTE", { enumerable: true, get: function () { return fee_1.DEFAULT_MIN_FEE_PER_BYTE; } }); | ||
Object.defineProperty(exports, "DEFAULT_NUMBER_OF_SIGNATURES", { enumerable: true, get: function () { return fee_1.DEFAULT_NUMBER_OF_SIGNATURES; } }); | ||
Object.defineProperty(exports, "DEFAULT_SIGNATURE_BYTE_SIZE", { enumerable: true, get: function () { return fee_1.DEFAULT_SIGNATURE_BYTE_SIZE; } }); | ||
var format_1 = require("./format"); | ||
@@ -14,6 +31,9 @@ Object.defineProperty(exports, "convertBeddowsToLSK", { enumerable: true, get: function () { return format_1.convertBeddowsToLSK; } }); | ||
Object.defineProperty(exports, "signMultiSignatureTransaction", { enumerable: true, get: function () { return sign_1.signMultiSignatureTransaction; } }); | ||
Object.defineProperty(exports, "signTransactionWithPrivateKey", { enumerable: true, get: function () { return sign_1.signTransactionWithPrivateKey; } }); | ||
Object.defineProperty(exports, "signMultiSignatureTransactionWithPrivateKey", { enumerable: true, get: function () { return sign_1.signMultiSignatureTransactionWithPrivateKey; } }); | ||
Object.defineProperty(exports, "signTransactionWithPrivateKey", { enumerable: true, get: function () { return sign_1.signTransactionWithPrivateKey; } }); | ||
var validate_1 = require("./validate"); | ||
Object.defineProperty(exports, "validateTransaction", { enumerable: true, get: function () { return validate_1.validateTransaction; } }); | ||
__exportStar(require("./constants"), exports); | ||
var schema_1 = require("./schema"); | ||
Object.defineProperty(exports, "baseTransactionSchema", { enumerable: true, get: function () { return schema_1.baseTransactionSchema; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -6,7 +6,7 @@ export declare const baseTransactionSchema: { | ||
properties: { | ||
moduleID: { | ||
module: { | ||
dataType: string; | ||
fieldNumber: number; | ||
}; | ||
assetID: { | ||
command: { | ||
dataType: string; | ||
@@ -27,3 +27,3 @@ fieldNumber: number; | ||
}; | ||
asset: { | ||
params: { | ||
dataType: string; | ||
@@ -30,0 +30,0 @@ fieldNumber: number; |
@@ -5,12 +5,12 @@ "use strict"; | ||
exports.baseTransactionSchema = { | ||
$id: 'lisk/base-transaction', | ||
$id: '/lisk/baseTransaction', | ||
type: 'object', | ||
required: ['moduleID', 'assetID', 'nonce', 'fee', 'senderPublicKey', 'asset'], | ||
required: ['module', 'command', 'nonce', 'fee', 'senderPublicKey', 'params'], | ||
properties: { | ||
moduleID: { | ||
dataType: 'uint32', | ||
module: { | ||
dataType: 'string', | ||
fieldNumber: 1, | ||
}, | ||
assetID: { | ||
dataType: 'uint32', | ||
command: { | ||
dataType: 'string', | ||
fieldNumber: 2, | ||
@@ -30,3 +30,3 @@ }, | ||
}, | ||
asset: { | ||
params: { | ||
dataType: 'bytes', | ||
@@ -33,0 +33,0 @@ fieldNumber: 6, |
/// <reference types="node" /> | ||
interface MultiSignatureKeys { | ||
export interface MultiSignatureKeys { | ||
readonly mandatoryKeys: Array<Buffer>; | ||
readonly optionalKeys: Array<Buffer>; | ||
} | ||
export declare const getSigningBytes: (assetSchema: object, transactionObject: Record<string, unknown>) => Buffer; | ||
export declare const getBytes: (assetSchema: object, transactionObject: Record<string, unknown>) => Buffer; | ||
export declare const signTransaction: (assetSchema: object, transactionObject: Record<string, unknown>, networkIdentifier: Buffer, passphrase: string) => Record<string, unknown>; | ||
export declare const signMultiSignatureTransaction: (assetSchema: object, transactionObject: Record<string, unknown>, networkIdentifier: Buffer, passphrase: string, keys: MultiSignatureKeys, includeSenderSignature?: boolean) => Record<string, unknown>; | ||
export declare const signTransactionWithPrivateKey: (assetSchema: object, transactionObject: Record<string, unknown>, networkIdentifier: Buffer, privateKey: Buffer) => Record<string, unknown>; | ||
export declare const signMultiSignatureTransactionWithPrivateKey: (assetSchema: object, transactionObject: Record<string, unknown>, networkIdentifier: Buffer, privateKey: Buffer, keys: MultiSignatureKeys, includeSenderSignature?: boolean) => Record<string, unknown>; | ||
export {}; | ||
export declare const getSigningBytes: (transactionObject: Record<string, unknown>, paramsSchema?: object) => Buffer; | ||
export declare const getBytes: (transactionObject: Record<string, unknown>, paramsSchema?: object) => Buffer; | ||
export declare const signTransaction: (transactionObject: Record<string, unknown>, chainID: Buffer, privateKey: Buffer, paramsSchema?: object) => Record<string, unknown>; | ||
export declare const signMultiSignatureTransaction: (transactionObject: Record<string, unknown>, chainID: Buffer, privateKey: Buffer, keys: MultiSignatureKeys, paramsSchema?: object) => Record<string, unknown>; | ||
export declare const signTransactionWithPrivateKey: (transactionObject: Record<string, unknown>, chainID: Buffer, privateKey: Buffer, paramsSchema?: object) => Record<string, unknown>; | ||
export declare const signMultiSignatureTransactionWithPrivateKey: (transactionObject: Record<string, unknown>, chainID: Buffer, privateKey: Buffer, keys: MultiSignatureKeys, paramsSchema?: object) => Record<string, unknown>; |
@@ -8,14 +8,22 @@ "use strict"; | ||
const schema_1 = require("./schema"); | ||
const getSigningBytes = (assetSchema, transactionObject) => { | ||
const validationErrors = validate_1.validateTransaction(assetSchema, transactionObject); | ||
const constants_1 = require("./constants"); | ||
const getSigningBytes = (transactionObject, paramsSchema) => { | ||
const validationErrors = (0, validate_1.validateTransaction)(transactionObject, paramsSchema); | ||
if (validationErrors) { | ||
throw validationErrors; | ||
} | ||
if (typeof transactionObject.asset !== 'object' || transactionObject.asset === null) { | ||
throw new Error('Asset must be of type object and not null'); | ||
if (typeof transactionObject.params !== 'object' || | ||
transactionObject.params === null || | ||
!paramsSchema) { | ||
const transactionBytes = lisk_codec_1.codec.encode(schema_1.baseTransactionSchema, { | ||
...transactionObject, | ||
params: Buffer.alloc(0), | ||
signatures: [], | ||
}); | ||
return transactionBytes; | ||
} | ||
const assetBytes = lisk_codec_1.codec.encode(assetSchema, transactionObject.asset); | ||
const paramsBytes = lisk_codec_1.codec.encode(paramsSchema, transactionObject.params); | ||
const transactionBytes = lisk_codec_1.codec.encode(schema_1.baseTransactionSchema, { | ||
...transactionObject, | ||
asset: assetBytes, | ||
params: paramsBytes, | ||
signatures: [], | ||
@@ -26,10 +34,16 @@ }); | ||
exports.getSigningBytes = getSigningBytes; | ||
const getBytes = (assetSchema, transactionObject) => { | ||
if (typeof transactionObject.asset !== 'object' || transactionObject.asset === null) { | ||
throw new Error('Asset must be of type object and not null'); | ||
const getBytes = (transactionObject, paramsSchema) => { | ||
if (typeof transactionObject.params !== 'object' || | ||
transactionObject.params === null || | ||
!paramsSchema) { | ||
const transactionBytes = lisk_codec_1.codec.encode(schema_1.baseTransactionSchema, { | ||
...transactionObject, | ||
params: Buffer.alloc(0), | ||
}); | ||
return transactionBytes; | ||
} | ||
const assetBytes = lisk_codec_1.codec.encode(assetSchema, transactionObject.asset); | ||
const paramsBytes = lisk_codec_1.codec.encode(paramsSchema, transactionObject.params); | ||
const transactionBytes = lisk_codec_1.codec.encode(schema_1.baseTransactionSchema, { | ||
...transactionObject, | ||
asset: assetBytes, | ||
params: paramsBytes, | ||
}); | ||
@@ -39,102 +53,23 @@ return transactionBytes; | ||
exports.getBytes = getBytes; | ||
const signTransaction = (assetSchema, transactionObject, networkIdentifier, passphrase) => { | ||
if (!networkIdentifier.length) { | ||
throw new Error('Network identifier is required to sign a transaction'); | ||
const signTransaction = (transactionObject, chainID, privateKey, paramsSchema) => { | ||
if (!chainID.length) { | ||
throw new Error('ChainID is required to sign a transaction'); | ||
} | ||
if (!passphrase) { | ||
throw new Error('Passphrase is required to sign a transaction'); | ||
} | ||
const validationErrors = validate_1.validateTransaction(assetSchema, transactionObject); | ||
if (validationErrors) { | ||
throw validationErrors; | ||
} | ||
const { publicKey } = lisk_cryptography_1.getAddressAndPublicKeyFromPassphrase(passphrase); | ||
if (!Buffer.isBuffer(transactionObject.senderPublicKey) || | ||
!transactionObject.senderPublicKey.equals(publicKey)) { | ||
throw new Error('Transaction senderPublicKey does not match public key from passphrase'); | ||
} | ||
const transactionWithNetworkIdentifierBytes = Buffer.concat([ | ||
networkIdentifier, | ||
exports.getSigningBytes(assetSchema, transactionObject), | ||
]); | ||
const signature = lisk_cryptography_1.signData(transactionWithNetworkIdentifierBytes, passphrase); | ||
transactionObject.signatures = [signature]; | ||
return { ...transactionObject, id: lisk_cryptography_1.hash(exports.getBytes(assetSchema, transactionObject)) }; | ||
}; | ||
exports.signTransaction = signTransaction; | ||
const sanitizeSignaturesArray = (transactionObject, keys, includeSenderSignature) => { | ||
const numberOfSignatures = (includeSenderSignature ? 1 : 0) + keys.mandatoryKeys.length + keys.optionalKeys.length; | ||
for (let i = 0; i < numberOfSignatures; i += 1) { | ||
if (Array.isArray(transactionObject.signatures) && | ||
transactionObject.signatures[i] === undefined) { | ||
transactionObject.signatures[i] = Buffer.alloc(0); | ||
} | ||
} | ||
}; | ||
const signMultiSignatureTransaction = (assetSchema, transactionObject, networkIdentifier, passphrase, keys, includeSenderSignature = false) => { | ||
if (!networkIdentifier.length) { | ||
throw new Error('Network identifier is required to sign a transaction'); | ||
} | ||
if (!passphrase) { | ||
throw new Error('Passphrase is required to sign a transaction'); | ||
} | ||
if (!Array.isArray(transactionObject.signatures)) { | ||
throw new Error('Signatures must be of type array'); | ||
} | ||
const validationErrors = validate_1.validateTransaction(assetSchema, transactionObject); | ||
if (validationErrors) { | ||
throw validationErrors; | ||
} | ||
keys.mandatoryKeys.sort((publicKeyA, publicKeyB) => publicKeyA.compare(publicKeyB)); | ||
keys.optionalKeys.sort((publicKeyA, publicKeyB) => publicKeyA.compare(publicKeyB)); | ||
const { publicKey } = lisk_cryptography_1.getAddressAndPublicKeyFromPassphrase(passphrase); | ||
const transactionWithNetworkIdentifierBytes = Buffer.concat([ | ||
networkIdentifier, | ||
exports.getSigningBytes(assetSchema, transactionObject), | ||
]); | ||
const signature = lisk_cryptography_1.signData(transactionWithNetworkIdentifierBytes, passphrase); | ||
if (includeSenderSignature && | ||
Buffer.isBuffer(transactionObject.senderPublicKey) && | ||
publicKey.equals(transactionObject.senderPublicKey)) { | ||
transactionObject.signatures[0] = signature; | ||
} | ||
const mandatoryKeyIndex = keys.mandatoryKeys.findIndex(aPublicKey => aPublicKey.equals(publicKey)); | ||
const optionalKeyIndex = keys.optionalKeys.findIndex(aPublicKey => aPublicKey.equals(publicKey)); | ||
if (mandatoryKeyIndex !== -1) { | ||
const signatureOffset = includeSenderSignature ? 1 : 0; | ||
transactionObject.signatures[mandatoryKeyIndex + signatureOffset] = signature; | ||
} | ||
if (optionalKeyIndex !== -1) { | ||
const signatureOffset = includeSenderSignature ? 1 : 0; | ||
transactionObject.signatures[keys.mandatoryKeys.length + optionalKeyIndex + signatureOffset] = signature; | ||
} | ||
sanitizeSignaturesArray(transactionObject, keys, includeSenderSignature); | ||
return { ...transactionObject, id: lisk_cryptography_1.hash(exports.getBytes(assetSchema, transactionObject)) }; | ||
}; | ||
exports.signMultiSignatureTransaction = signMultiSignatureTransaction; | ||
const signTransactionWithPrivateKey = (assetSchema, transactionObject, networkIdentifier, privateKey) => { | ||
if (!networkIdentifier.length) { | ||
throw new Error('Network identifier is required to sign a transaction'); | ||
} | ||
if (!privateKey.length || privateKey.length !== 64) { | ||
throw new Error('Private key must be 64 bytes'); | ||
} | ||
const validationErrors = validate_1.validateTransaction(assetSchema, transactionObject); | ||
const validationErrors = (0, validate_1.validateTransaction)(transactionObject, paramsSchema); | ||
if (validationErrors) { | ||
throw validationErrors; | ||
} | ||
const transactionWithNetworkIdentifierBytes = Buffer.concat([ | ||
networkIdentifier, | ||
exports.getSigningBytes(assetSchema, transactionObject), | ||
]); | ||
const signature = lisk_cryptography_1.signDataWithPrivateKey(transactionWithNetworkIdentifierBytes, privateKey); | ||
const signature = lisk_cryptography_1.ed.signDataWithPrivateKey(constants_1.TAG_TRANSACTION, chainID, (0, exports.getSigningBytes)(transactionObject, paramsSchema), privateKey); | ||
transactionObject.signatures = [signature]; | ||
return { ...transactionObject, id: lisk_cryptography_1.hash(exports.getBytes(assetSchema, transactionObject)) }; | ||
return { ...transactionObject, id: lisk_cryptography_1.utils.hash((0, exports.getBytes)(transactionObject, paramsSchema)) }; | ||
}; | ||
exports.signTransactionWithPrivateKey = signTransactionWithPrivateKey; | ||
const signMultiSignatureTransactionWithPrivateKey = (assetSchema, transactionObject, networkIdentifier, privateKey, keys, includeSenderSignature = false) => { | ||
if (!networkIdentifier.length) { | ||
throw new Error('Network identifier is required to sign a transaction'); | ||
exports.signTransaction = signTransaction; | ||
const signMultiSignatureTransaction = (transactionObject, chainID, privateKey, keys, paramsSchema) => { | ||
if (!chainID.length) { | ||
throw new Error('ChainID is required to sign a transaction'); | ||
} | ||
if (!privateKey.length || privateKey.length !== 64) { | ||
if (!privateKey || privateKey.length !== 64) { | ||
throw new Error('Private key must be 64 bytes'); | ||
@@ -145,3 +80,3 @@ } | ||
} | ||
const validationErrors = validate_1.validateTransaction(assetSchema, transactionObject); | ||
const validationErrors = (0, validate_1.validateTransaction)(transactionObject, paramsSchema); | ||
if (validationErrors) { | ||
@@ -152,27 +87,18 @@ throw validationErrors; | ||
keys.optionalKeys.sort((publicKeyA, publicKeyB) => publicKeyA.compare(publicKeyB)); | ||
const transactionWithNetworkIdentifierBytes = Buffer.concat([ | ||
networkIdentifier, | ||
exports.getSigningBytes(assetSchema, transactionObject), | ||
]); | ||
const signature = lisk_cryptography_1.signDataWithPrivateKey(transactionWithNetworkIdentifierBytes, privateKey); | ||
const signerPublicKey = lisk_cryptography_1.getPublicKey(privateKey); | ||
if (includeSenderSignature && | ||
Buffer.isBuffer(transactionObject.senderPublicKey) && | ||
signerPublicKey.equals(transactionObject.senderPublicKey)) { | ||
transactionObject.signatures[0] = signature; | ||
const signature = lisk_cryptography_1.ed.signDataWithPrivateKey(constants_1.TAG_TRANSACTION, chainID, (0, exports.getSigningBytes)(transactionObject, paramsSchema), privateKey); | ||
const publicKey = lisk_cryptography_1.ed.getPublicKeyFromPrivateKey(privateKey); | ||
const accountKeys = keys.mandatoryKeys.concat(keys.optionalKeys); | ||
for (let i = 0; i < accountKeys.length; i += 1) { | ||
if (accountKeys[i].equals(publicKey)) { | ||
transactionObject.signatures[i] = signature; | ||
} | ||
else if (transactionObject.signatures[i] === undefined) { | ||
transactionObject.signatures[i] = Buffer.alloc(0); | ||
} | ||
} | ||
const mandatoryKeyIndex = keys.mandatoryKeys.findIndex(aPublicKey => aPublicKey.equals(signerPublicKey)); | ||
const optionalKeyIndex = keys.optionalKeys.findIndex(aPublicKey => aPublicKey.equals(signerPublicKey)); | ||
if (mandatoryKeyIndex !== -1) { | ||
const signatureOffset = includeSenderSignature ? 1 : 0; | ||
transactionObject.signatures[mandatoryKeyIndex + signatureOffset] = signature; | ||
} | ||
if (optionalKeyIndex !== -1) { | ||
const signatureOffset = includeSenderSignature ? 1 : 0; | ||
transactionObject.signatures[keys.mandatoryKeys.length + optionalKeyIndex + signatureOffset] = signature; | ||
} | ||
sanitizeSignaturesArray(transactionObject, keys, includeSenderSignature); | ||
return { ...transactionObject, id: lisk_cryptography_1.hash(exports.getBytes(assetSchema, transactionObject)) }; | ||
return { ...transactionObject, id: lisk_cryptography_1.utils.hash((0, exports.getBytes)(transactionObject, paramsSchema)) }; | ||
}; | ||
exports.signMultiSignatureTransactionWithPrivateKey = signMultiSignatureTransactionWithPrivateKey; | ||
exports.signMultiSignatureTransaction = signMultiSignatureTransaction; | ||
exports.signTransactionWithPrivateKey = exports.signTransaction; | ||
exports.signMultiSignatureTransactionWithPrivateKey = exports.signMultiSignatureTransaction; | ||
//# sourceMappingURL=sign.js.map |
import { LiskValidationError } from '@liskhq/lisk-validator'; | ||
export declare const validateTransaction: (assetSchema: object, transactionObject: Record<string, unknown>) => LiskValidationError | Error | undefined; | ||
export declare const validateTransaction: (transactionObject: Record<string, unknown>, paramsSchema?: object) => LiskValidationError | Error | undefined; |
@@ -6,18 +6,15 @@ "use strict"; | ||
const schema_1 = require("./schema"); | ||
const validateTransaction = (assetSchema, transactionObject) => { | ||
const transactionObjectWithEmptyAsset = { | ||
const validateTransaction = (transactionObject, paramsSchema) => { | ||
const transactionObjectWithEmptyParameters = { | ||
...transactionObject, | ||
asset: Buffer.alloc(0), | ||
params: Buffer.alloc(0), | ||
}; | ||
const schemaErrors = lisk_validator_1.validator.validate(schema_1.baseTransactionSchema, transactionObjectWithEmptyAsset); | ||
if (schemaErrors.length) { | ||
return new lisk_validator_1.LiskValidationError([...schemaErrors]); | ||
lisk_validator_1.validator.validate(schema_1.baseTransactionSchema, transactionObjectWithEmptyParameters); | ||
if (!paramsSchema) { | ||
return undefined; | ||
} | ||
if (typeof transactionObject.asset !== 'object' || transactionObject.asset === null) { | ||
return new Error('Transaction object asset must be of type object and not null'); | ||
if (typeof transactionObject.params !== 'object' || transactionObject.params === null) { | ||
return new Error('Transaction object params must be of type object and not null'); | ||
} | ||
const assetSchemaErrors = lisk_validator_1.validator.validate(assetSchema, transactionObject.asset); | ||
if (assetSchemaErrors.length) { | ||
return new lisk_validator_1.LiskValidationError([...assetSchemaErrors]); | ||
} | ||
lisk_validator_1.validator.validate(paramsSchema, transactionObject.params); | ||
return undefined; | ||
@@ -24,0 +21,0 @@ }; |
{ | ||
"name": "@liskhq/lisk-transactions", | ||
"version": "5.2.2", | ||
"version": "6.0.0-beta.0", | ||
"description": "Utility functions related to transactions according to the Lisk protocol", | ||
"author": "Lisk Foundation <admin@lisk.io>, lightcurve GmbH <admin@lightcurve.io>", | ||
"author": "Lisk Foundation <admin@lisk.com>, lightcurve GmbH <admin@lightcurve.io>", | ||
"license": "Apache-2.0", | ||
@@ -27,38 +27,37 @@ "keywords": [ | ||
"format": "prettier --write '**/*'", | ||
"lint": "eslint --ext .js,.ts .", | ||
"lint": "eslint --ext .ts .", | ||
"lint:fix": "eslint --fix --ext .js,.ts .", | ||
"test": "jest", | ||
"test:coverage": "jest --coverage=true --coverage-reporters=text", | ||
"test:ci": "jest --coverage=true --coverage-reporters=json --verbose", | ||
"test:ci": "jest --coverage=true --coverage-reporters=json", | ||
"test:watch": "npm test -- --watch", | ||
"prebuild": "rm -r dist-node/* || mkdir dist-node || true", | ||
"build": "tsc", | ||
"build:check": "node -e \"require('./dist-node')\"", | ||
"prepublishOnly": "npm run lint && npm test && npm run build && npm run build:check" | ||
"build:check": "node -e \"require('./dist-node')\"" | ||
}, | ||
"dependencies": { | ||
"@liskhq/lisk-codec": "^0.2.2", | ||
"@liskhq/lisk-cryptography": "^3.2.1", | ||
"@liskhq/lisk-validator": "^0.6.2" | ||
"@liskhq/lisk-codec": "^0.3.0-beta.0", | ||
"@liskhq/lisk-cryptography": "^4.0.0-beta.0", | ||
"@liskhq/lisk-validator": "^0.7.0-beta.0" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "26.0.21", | ||
"@types/jest-when": "2.7.2", | ||
"@types/node": "16.11.26", | ||
"@typescript-eslint/eslint-plugin": "4.19.0", | ||
"@typescript-eslint/parser": "4.19.0", | ||
"eslint": "7.22.0", | ||
"@types/jest": "29.2.3", | ||
"@types/jest-when": "3.5.2", | ||
"@types/node": "16.18.3", | ||
"@typescript-eslint/eslint-plugin": "5.44.0", | ||
"@typescript-eslint/parser": "5.44.0", | ||
"eslint": "8.28.0", | ||
"eslint-config-lisk-base": "2.0.1", | ||
"eslint-plugin-import": "2.22.1", | ||
"eslint-plugin-jest": "24.3.2", | ||
"jest": "26.6.3", | ||
"jest-extended": "0.11.5", | ||
"jest-when": "3.2.1", | ||
"prettier": "2.2.1", | ||
"source-map-support": "0.5.19", | ||
"ts-jest": "26.5.4", | ||
"ts-node": "9.1.1", | ||
"tsconfig-paths": "3.9.0", | ||
"typescript": "4.2.3" | ||
"eslint-plugin-import": "2.26.0", | ||
"eslint-plugin-jest": "27.1.6", | ||
"jest": "29.3.1", | ||
"jest-extended": "3.2.0", | ||
"jest-when": "3.5.2", | ||
"prettier": "2.8.0", | ||
"source-map-support": "0.5.21", | ||
"ts-jest": "29.0.3", | ||
"ts-node": "10.9.1", | ||
"tsconfig-paths": "4.1.0", | ||
"typescript": "5.0.2" | ||
} | ||
} |
@@ -28,2 +28,2 @@ # @liskhq/lisk-transactions | ||
[lisk core github]: https://github.com/LiskHQ/lisk | ||
[lisk documentation site]: https://lisk.io/documentation/lisk-elements | ||
[lisk documentation site]: https://lisk.com/documentation/lisk-sdk/references/lisk-elements/transactions.html |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
25
41182
355
1
+ Added@liskhq/lisk-codec@0.3.0(transitive)
+ Added@liskhq/lisk-cryptography@4.1.0(transitive)
+ Added@liskhq/lisk-passphrase@4.1.0(transitive)
+ Added@liskhq/lisk-utils@0.3.0(transitive)
+ Added@liskhq/lisk-validator@0.7.0(transitive)
+ Added@types/node@11.11.6(transitive)
+ Addedbip39@3.0.3(transitive)
+ Addedcipher-base@1.0.6(transitive)
+ Addedcreate-hash@1.2.0(transitive)
+ Addedcreate-hmac@1.1.7(transitive)
+ Addedhash-base@3.1.0(transitive)
+ Addedhash-wasm@4.9.0(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedmd5.js@1.3.5(transitive)
+ Addedpbkdf2@3.1.2(transitive)
+ Addedrandombytes@2.1.0(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedripemd160@2.0.2(transitive)
+ Addedsha.js@2.4.11(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
- Removed@liskhq/lisk-codec@0.2.2(transitive)
- Removed@liskhq/lisk-utils@0.2.1(transitive)
- Removed@liskhq/lisk-validator@0.6.2(transitive)