Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async grantAbilities(accountId: string | OrderGatewayBase, abilities: AssetLedgerAbility[]): Promise {
if (typeof accountId !== 'string') {
accountId = await (accountId as any).getProxyAccountId(0); // OrderGatewayProxy.XCERT_CREATE
}
accountId = this._provider.encoder.normalizeAddress(accountId as string);
let bitAbilities = bigNumberify(0);
abilities.forEach((ability) => {
bitAbilities = bitAbilities.add(ability);
});
return grantAbilities(this, accountId, bitAbilities);
}
public set accountId(id: string) {
this._accountId = normalizeAddress(id);
this.emit(ProviderEvent.ACCOUNT_CHANGE, id);
}
export function getValue(value: string) {
return leftPad(bigNumberify(value).toHexString(), 64, '0', true);
}
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;
}
public async approveValue(value: string, accountId: string): Promise {
accountId = this._provider.encoder.normalizeAddress(accountId as string);
const approvedValue = await this.getApprovedValue(this.provider.accountId, accountId);
if (!bigNumberify(value).isZero() && !bigNumberify(approvedValue).isZero()) {
throw new ProviderError(ProviderIssue.ERC20_APPROVAL_RACE_CONDITION);
}
return approveAccount(this, accountId, value);
}
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) {
export function getValue(value: string) {
return leftPad(bigNumberify(value).toHexString(), 64, '0', true);
}
export function createOrderHash(gateway: Gateway, order: ValueLedgerDeployOrder) {
const tokenData = keccak256(
hexToBytes([
'0x',
stringToHex(order.valueLedgerData.name),
stringToHex(order.valueLedgerData.symbol),
getValue(order.valueLedgerData.supply).substr(2),
leftPad(bigNumberify(order.valueLedgerData.decimals).toHexString(), 2, '0', false),
order.valueLedgerData.ownerId.substr(2),
].join('')),
);
const transferData = keccak256(
hexToBytes([
'0x',
order.tokenTransferData.ledgerId.substr(2),
order.tokenTransferData.receiverId.substr(2),
getValue(order.tokenTransferData.value).substr(2),
].join('')),
);
return keccak256(
hexToBytes([
'0x',
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;
}
export function getValue(value: string) {
return leftPad(bigNumberify(value).toHexString(), 64, '0', true);
}