@ethersproject/bytes#zeroPad TypeScript Examples
The following examples show how to use
@ethersproject/bytes#zeroPad.
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: boolean.ts From fuels-ts with Apache License 2.0 | 6 votes |
encode(value: boolean): Uint8Array {
let bytes;
try {
bytes = toArray(value ? 1 : 0);
} catch (error) {
this.throwError('Invalid bool', value);
}
if (bytes.length > 1) {
this.throwError('Invalid bool', value);
}
return zeroPad(bytes, 8);
}
Example #2
Source File: byte.ts From fuels-ts with Apache License 2.0 | 6 votes |
encode(value: number): Uint8Array {
let bytes;
try {
bytes = toArray(value);
} catch (error) {
this.throwError('Invalid Byte', value);
}
if (bytes.length > 1) {
this.throwError('Invalid Byte', value);
}
return zeroPad(bytes, 8);
}
Example #3
Source File: number.ts From fuels-ts with Apache License 2.0 | 6 votes |
encode(value: number | bigint): Uint8Array {
let bytes;
try {
bytes = toArray(value);
} catch (error) {
this.throwError(`Invalid ${this.baseType}`, value);
}
if (bytes.length > this.length) {
this.throwError(`Invalid ${this.baseType}`, value);
}
return zeroPad(bytes, 8);
}
Example #4
Source File: signer.ts From fuels-ts with Apache License 2.0 | 6 votes |
/**
* Sign data using the Signer instance
*
* Signature is a 64 byte array of the concatenated r and s values with the compressed recoveryParam byte. [Read more](FuelLabs/fuel-specs/specs/protocol/cryptographic_primitives.md#public-key-cryptography)
*
* @param data - The data to be sign
* @returns hashed signature
*/
sign(data: BytesLike) {
const keyPair = getCurve().keyFromPrivate(arrayify(this.privateKey), 'hex');
const signature = keyPair.sign(arrayify(data), {
canonical: true,
});
const r = zeroPad(signature.r.toArray(), 32);
const s = zeroPad(signature.s.toArray(), 32);
// add recoveryParam to first s byte
s[0] |= (signature.recoveryParam || 0) << 7;
return hexlify(concat([r, s]));
}