Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return u8aConcat(
bnToU8a(u8a.length, 32, true),
u8a
);
})();
case 'Timestamp':
if (value instanceof Date) {
value = Math.ceil(value.getTime() / 1000);
}
return bnToU8a(value, 64, true);
case 'u128':
return bnToU8a(value, 128, true);
// TODO enums?
case 'VoteThreshold':
return bnToU8a(value || 0, 8, true);
default:
// tslint:disable-next-line
(type as never);
throw new Error(`No formatter for ${type}`);
}
} catch (error) {
console.error('Failed encoding', type, 'with', value, error);
throw error;
}
}
);
})();
case 'Timestamp':
if (value instanceof Date) {
value = Math.ceil(value.getTime() / 1000);
}
return bnToU8a(value, 64, true);
case 'u128':
return bnToU8a(value, 128, true);
// TODO enums?
case 'VoteThreshold':
return bnToU8a(value || 0, 8, true);
default:
// tslint:disable-next-line
(type as never);
throw new Error(`No formatter for ${type}`);
}
} catch (error) {
console.error('Failed encoding', type, 'with', value, error);
throw error;
}
}
return bnToU8a((value as BN), sizes.AccountIndex, true);
case 'ParachainId':
case 'PropIndex':
case 'ReferendumIndex':
case 'SessionKey':
case 'VoteIndex':
case 'VoteThreshold':
case 'u32':
return bnToU8a((value as BN), 32, true);
case 'String':
return u8aFromString((value as string));
case 'Timestamp':
return bnToU8a((value as Date).getTime(), 64, true);
default:
// tslint:disable-next-line
(type as never);
throw new Error('Unable to find handler');
}
} catch (error) {
console.error('formatParams', value, index, paramTypes[index], error);
throw error;
}
});
}
? addrPrefixes.none
: addrPrefixes.publicKey,
addressDecode(value)
);
case 'Balance':
return bnToU8a(value, sizes.Balance.get(version) || defaultSizes.Balance, true);
case 'BlockNumber':
case 'Gas':
case 'SessionKey':
case 'u64':
return bnToU8a(value, 64, true);
case 'bool':
return bnToU8a(value ? 1 : 0, 8, true);
case 'Bytes':
case 'Code':
return u8aToU8a(value);
// FIXME Here we should pass through the actual objects
case 'Call':
case 'CandidateReceipt':
case 'Digest':
case 'Header':
case 'MisbehaviorReport':
case 'Proposal':
return u8aToU8a(value);
// TODO Here we should do actual length conversions, i.e. 256/512
case 'Hash':
// FIXME Here we should pass through the actual objects
case 'Call':
case 'CandidateReceipt':
case 'Digest':
case 'Header':
case 'MisbehaviorReport':
case 'Proposal':
return u8aToU8a(value);
// TODO Here we should do actual length conversions, i.e. 256/512
case 'Hash':
case 'Signature':
return u8aToU8a(value);
case 'AccountIndex':
return bnToU8a(value, sizes.AccountIndex.get(version) || defaultSizes.Balance, true);
case 'KeyValue':
case 'StorageKeyValue':
return keyValue(value);
case 'ParachainId':
case 'PropIndex':
case 'ReferendumIndex':
case 'VoteIndex':
case 'u32':
return bnToU8a(value, 32, true);
case 'StorageKey':
return storageKey(value);
case 'String':
export default function signMessage (publicKey: Uint8Array, nonce: BN | number, value: Uint8Array, apiSupport: EncodingVersions): Signed {
const message = encodeCall(publicKey, nonce, value, apiSupport);
const signature = keyring.getPair(publicKey).sign(message);
const data = u8aConcat(
prefixes.publicKey,
message,
signature
);
console.log(`signMessage (${apiSupport}) : message :: ${u8aToHex(message)}`);
console.log(`signMessage (${apiSupport}) : signature :: ${u8aToHex(signature)}`);
console.log(`signMessage (${apiSupport}) : data :: ${u8aToHex(data)}`);
return {
data: u8aConcat(
bnToU8a(data.length, 32, true),
data
),
message,
signature
};
}
export default function encodeLength (...values: Array): Uint8Array {
const length = values.reduce((length, u8a) => {
return length + u8a.length;
}, 0);
return u8aConcat(
bnToU8a(length, 32, true),
...values
);
}
({ description, key = '', params, type, isDeprecated = false, isHidden = false, isSigned = false, isUnhashed = false, subscribe }: CreateItemOptions): SectionItem => ({
description,
index: u8aConcat(sectionIndex, bnToU8a(index, 8, true)),
isDeprecated,
isHidden,
isSigned,
isSubscription: !isUndefined(subscribe),
isUnhashed,
key,
name,
params,
section,
subscribe: subscribe || ['', ''],
type
});
}
return (() => {
const u8a = u8aFromString(value);
return u8aConcat(
bnToU8a(u8a.length, 32, true),
u8a
);
})();
const type = paramTypes[index];
switch (type) {
case 'AccountId':
return addressDecode((value as Uint8Array));
case 'Balance':
return bnToU8a((value as BN), sizes.Balance, true);
case 'u128':
return bnToU8a((value as BN), 128, true);
case 'BlockNumber':
case 'Gas':
case 'u64':
return bnToU8a((value as BN), 64, true);
case 'bool':
return new Uint8Array([value ? 1 : 0]);
case 'Bytes':
case 'Call':
case 'CandidateReceipt':
case 'Code':
case 'Digest':
case 'Hash':
case 'Header':
case 'KeyValue':
case 'KeyValueStorage':
case 'MisbehaviorReport':
case 'Proposal':
case 'Signature':