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 getActionParams(action: ActionsOrderAction, signers: string[]) {
let params = '';
const signerIndex = signers.indexOf(action['senderId']);
if (signerIndex === -1) {
throw new ProviderError(ProviderIssue.WRONG_INPUT, 'SenderId not a signer.');
}
if (action.kind == ActionsOrderActionKind.CREATE_ASSET) {
params = rightPad(`0x${action['assetImprint']}`, 64);
params += leftPad(bigNumberify(action['assetId']).toHexString(), 64, '0', false);
params += action['receiverId'].substr(2);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.SET_ABILITIES) {
const bitAbilities = getBitfieldFromAbilities(action.abilities);
params = leftPad(bitAbilities, 64, '0', true);
params += action['receiverId'].substr(2);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.TRANSFER_ASSET) {
params = leftPad(bigNumberify(action['assetId']).toHexString(), 64, '0', true);
params += action['receiverId'].substr(2);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.TRANSFER_VALUE) {
params = leftPad(bigNumberify(action['value']).toHexString(), 64, '0', true);
params += action['receiverId'].substr(2);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.UPDATE_ASSET_IMPRINT) {
const signerIndex = signers.indexOf(action['senderId']);
if (signerIndex === -1) {
throw new ProviderError(ProviderIssue.WRONG_INPUT, 'SenderId not a signer.');
}
if (action.kind == ActionsOrderActionKind.CREATE_ASSET) {
params = rightPad(`0x${action['assetImprint']}`, 64);
params += leftPad(bigNumberify(action['assetId']).toHexString(), 64, '0', false);
params += action['receiverId'].substr(2);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.SET_ABILITIES) {
const bitAbilities = getBitfieldFromAbilities(action.abilities);
params = leftPad(bitAbilities, 64, '0', true);
params += action['receiverId'].substr(2);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.TRANSFER_ASSET) {
params = leftPad(bigNumberify(action['assetId']).toHexString(), 64, '0', true);
params += action['receiverId'].substr(2);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.TRANSFER_VALUE) {
params = leftPad(bigNumberify(action['value']).toHexString(), 64, '0', true);
params += action['receiverId'].substr(2);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.UPDATE_ASSET_IMPRINT) {
params = rightPad(`0x${action['assetImprint']}`, 64);
params += leftPad(bigNumberify(action['assetId']).toHexString(), 64, '0', false);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.DESTROY_ASSET) {
params = leftPad(bigNumberify(action['assetId']).toHexString(), 64, '0', true);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
}
return params;
}
} else if (action.kind == ActionsOrderActionKind.SET_ABILITIES) {
const bitAbilities = getBitfieldFromAbilities(action.abilities);
params = leftPad(bitAbilities, 64, '0', true);
params += action['receiverId'].substr(2);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.TRANSFER_ASSET) {
params = leftPad(bigNumberify(action['assetId']).toHexString(), 64, '0', true);
params += action['receiverId'].substr(2);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.TRANSFER_VALUE) {
params = leftPad(bigNumberify(action['value']).toHexString(), 64, '0', true);
params += action['receiverId'].substr(2);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.UPDATE_ASSET_IMPRINT) {
params = rightPad(`0x${action['assetImprint']}`, 64);
params += leftPad(bigNumberify(action['assetId']).toHexString(), 64, '0', false);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.DESTROY_ASSET) {
params = leftPad(bigNumberify(action['assetId']).toHexString(), 64, '0', true);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
}
return params;
}
actionsHash.substr(2),
`0000000${getActionProxy(gateway, action)}`,
action.ledgerId.substr(2),
getActionParams(action, order.signers).substr(2),
].join('')),
);
}
return keccak256(
hexToBytes([
'0x',
gateway.config.actionsOrderId.substr(2),
parseAddresses(order.signers),
actionsHash.substr(2),
leftPad(toInteger(order.seed), 64, '0', false),
leftPad(toSeconds(order.expiration), 64, '0', false),
].join('')),
);
}
export function getActionParams(action: ActionsOrderAction, signers: string[]) {
let params = '';
const signerIndex = signers.indexOf(action['senderId']);
if (signerIndex === -1) {
throw new ProviderError(ProviderIssue.WRONG_INPUT, 'SenderId not a signer.');
}
if (action.kind == ActionsOrderActionKind.CREATE_ASSET) {
params = rightPad(`0x${action['assetImprint']}`, 64);
params += leftPad(bigNumberify(action['assetId']).toHexString(), 64, '0', false);
params += action['receiverId'].substr(2);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.SET_ABILITIES) {
const bitAbilities = getBitfieldFromAbilities(action.abilities);
params = leftPad(bitAbilities, 64, '0', true);
params += action['receiverId'].substr(2);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.TRANSFER_ASSET) {
params = leftPad(bigNumberify(action['assetId']).toHexString(), 64, '0', true);
params += action['receiverId'].substr(2);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.TRANSFER_VALUE) {
params = leftPad(bigNumberify(action['value']).toHexString(), 64, '0', true);
params += action['receiverId'].substr(2);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.UPDATE_ASSET_IMPRINT) {
params = rightPad(`0x${action['assetImprint']}`, 64);
params += leftPad(bigNumberify(action['assetId']).toHexString(), 64, '0', false);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.DESTROY_ASSET) {
params = leftPad(bigNumberify(action['assetId']).toHexString(), 64, '0', true);
params += leftPad(bigNumberify(action['assetId']).toHexString(), 64, '0', false);
params += action['receiverId'].substr(2);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.SET_ABILITIES) {
const bitAbilities = getBitfieldFromAbilities(action.abilities);
params = leftPad(bitAbilities, 64, '0', true);
params += action['receiverId'].substr(2);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.TRANSFER_ASSET) {
params = leftPad(bigNumberify(action['assetId']).toHexString(), 64, '0', true);
params += action['receiverId'].substr(2);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.TRANSFER_VALUE) {
params = leftPad(bigNumberify(action['value']).toHexString(), 64, '0', true);
params += action['receiverId'].substr(2);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.UPDATE_ASSET_IMPRINT) {
params = rightPad(`0x${action['assetImprint']}`, 64);
params += leftPad(bigNumberify(action['assetId']).toHexString(), 64, '0', false);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.DESTROY_ASSET) {
params = leftPad(bigNumberify(action['assetId']).toHexString(), 64, '0', true);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
}
return params;
}
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.TRANSFER_ASSET) {
params = leftPad(bigNumberify(action['assetId']).toHexString(), 64, '0', true);
params += action['receiverId'].substr(2);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.TRANSFER_VALUE) {
params = leftPad(bigNumberify(action['value']).toHexString(), 64, '0', true);
params += action['receiverId'].substr(2);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.UPDATE_ASSET_IMPRINT) {
params = rightPad(`0x${action['assetImprint']}`, 64);
params += leftPad(bigNumberify(action['assetId']).toHexString(), 64, '0', false);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.DESTROY_ASSET) {
params = leftPad(bigNumberify(action['assetId']).toHexString(), 64, '0', true);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
}
return params;
}
'0x',
actionsHash.substr(2),
`0000000${getActionProxy(gateway, action)}`,
action.ledgerId.substr(2),
getActionParams(action, order.signers).substr(2),
].join('')),
);
}
return keccak256(
hexToBytes([
'0x',
gateway.config.actionsOrderId.substr(2),
parseAddresses(order.signers),
actionsHash.substr(2),
leftPad(toInteger(order.seed), 64, '0', false),
leftPad(toSeconds(order.expiration), 64, '0', false),
].join('')),
);
}
addresses.forEach((signer) => {
encoded += leftPad(signer.substr(2), 64, '0', false);
});
return encoded;