@polkadot/util#hexAddPrefix TypeScript Examples
The following examples show how to use
@polkadot/util#hexAddPrefix.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: util.ts From crust-apps with Apache License 2.0 | 7 votes |
// split is 65-byte signature into the r, s (combined) and recovery number (derived from v)
export function sigToParts (_signature: string): SignatureParts {
const signature = hexHasPrefix(_signature) ? hexToU8a(_signature) : hexToU8a(hexAddPrefix(_signature));
assert(signature.length === 65, `Invalid signature length, expected 65 found ${signature.length}`);
let v = signature[64];
if (v < 27) {
v += 27;
}
const recovery = v - 27;
assert(recovery === 0 || recovery === 1, 'Invalid signature v value');
return {
recovery,
signature: u8aToBuffer(signature.slice(0, 64))
};
}
Example #2
Source File: runner.ts From polkadot-launch with MIT License | 6 votes |
async function generateNodeKeys(
config: ResolvedLaunchConfig
): Promise<string[]> {
var bootnodes = [];
for (const node of config.relaychain.nodes) {
if (!node.nodeKey) {
node.nodeKey = hexStripPrefix(randomAsHex(32));
}
let pair = await libp2pKeys.generateKeyPairFromSeed(
"Ed25519",
hexToU8a(hexAddPrefix(node.nodeKey!)),
1024
);
let peerId: PeerId = await PeerId.createFromPrivKey(pair.bytes);
bootnodes.push(
`/ip4/127.0.0.1/tcp/${node.port}/p2p/${peerId.toB58String()}`
);
}
return bootnodes;
}