Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 submit (api: RxApiInterface, { nonce, publicKey, value }: QueueTx): Promise {
const message = encodeCall(publicKey, nonce, value);
const signature = keyring.getPair(publicKey).sign(message);
console.log('submitExtrinsic: message =', u8aToHex(message));
console.log('submitExtrinsic: signature =', u8aToHex(signature));
return api.author
.submitExtrinsic(u8aConcat(message, signature))
.toPromise()
.then((result) => {
console.log('submitExtrinsic: result=', result);
return 'sent';
})
.catch((error) => {
console.error('submitExtrinsic: error=', error);
return 'error';
});
}
toHex (): string {
return u8aToHex(this.toU8a());
}
l.debug(() => ['storing', u8aToHex(data)]);
l.debug(() => ['put', 'key ->', u8aToHex(key), 'value ->', u8aToHex(value, 256)]);
const format = (value: any): string => {
if (isU8a(value)) {
return u8aToHex(value);
} else if (Array.isArray(value)) {
return `[${value.map((v) => format(v))}]`;
} else if (value) {
return 'object';
}
return 'empty';
};
l.debug(() => ['received', u8aToHex(result)]);
function formatSingleType (formatters: FormattersFunctionMap, type: Param$Types, value: any): any {
if (type === 'StorageKey') {
const [key, ...params]: [SectionItem, Array] = value;
return u8aToHex(
createStorageKey(key).apply(null, params)
);
}
const formatter = formatters.get(type);
if (isUndefined(formatter)) {
l.debug(() => `Unable to find default formatter for '${typeToString(type)}', falling back to echo`);
return echo(value);
}
try {
return formatter(value);
} catch (error) {
throw new Error(`Error formatting '${value.toString()}' as '${typeToString(type)}': ${error.message}`);
l.debug(() => `sending ${u8aToHex(encoded)} <= ${utf8}`);