Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
raw.push(hexlify(value));
});
if (transaction.chainId != null && transaction.chainId !== 0) {
raw.push(hexlify(transaction.chainId));
raw.push("0x");
raw.push("0x");
}
const unsignedTransaction = RLP.encode(raw);
// Requesting an unsigned transation
if (!signature) {
return unsignedTransaction;
}
// The splitSignature will ensure the transaction has a recoveryParam in the
// case that the signTransaction function only adds a v.
const sig = splitSignature(signature);
// We pushed a chainId and null r, s on for hashing only; remove those
let v = 27 + sig.recoveryParam;
if (raw.length === 9) {
raw.pop();
raw.pop();
raw.pop();
v += transaction.chainId * 2 + 8;
}
raw.push(hexlify(v));
raw.push(stripZeros(arrayify(sig.r)));
raw.push(stripZeros(arrayify(sig.s)));
return RLP.encode(raw);
}
export function parse(rawTransaction) {
}
raw.push(bytes_1.hexlify(value));
});
if (transaction.chainId != null && transaction.chainId !== 0) {
raw.push(bytes_1.hexlify(transaction.chainId));
raw.push("0x");
raw.push("0x");
}
var unsignedTransaction = RLP.encode(raw);
// Requesting an unsigned transation
if (!signature) {
return unsignedTransaction;
}
// The splitSignature will ensure the transaction has a recoveryParam in the
// case that the signTransaction function only adds a v.
var sig = bytes_1.splitSignature(signature);
// We pushed a chainId and null r, s on for hashing only; remove those
var v = 27 + sig.recoveryParam;
if (raw.length === 9) {
raw.pop();
raw.pop();
raw.pop();
v += transaction.chainId * 2 + 8;
}
raw.push(bytes_1.hexlify(v));
raw.push(bytes_1.stripZeros(bytes_1.arrayify(sig.r)));
raw.push(bytes_1.stripZeros(bytes_1.arrayify(sig.s)));
return RLP.encode(raw);
}
exports.serialize = serialize;
export function recoverPublicKey(digest: BytesLike, signature: SignatureLike): string {
const sig = splitSignature(signature);
const rs = { r: arrayify(sig.r), s: arrayify(sig.s) };
return "0x" + getCurve().recoverPubKey(arrayify(digest), rs, sig.recoveryParam).encode("hex", false);
}
signDigest(digest) {
const keyPair = getCurve().keyFromPrivate(arrayify(this.privateKey));
const signature = keyPair.sign(arrayify(digest), { canonical: true });
return splitSignature({
recoveryParam: signature.recoveryParam,
r: hexZeroPad("0x" + signature.r.toString(16), 32),
s: hexZeroPad("0x" + signature.s.toString(16), 32),
});
}
computeSharedSecret(otherKey) {
signDigest(digest: BytesLike): Signature {
const keyPair = getCurve().keyFromPrivate(arrayify(this.privateKey));
const signature = keyPair.sign(arrayify(digest), { canonical: true });
return splitSignature({
recoveryParam: signature.recoveryParam,
r: hexZeroPad("0x" + signature.r.toString(16), 32),
s: hexZeroPad("0x" + signature.s.toString(16), 32),
})
}
export function recoverPublicKey(digest, signature) {
const sig = splitSignature(signature);
const rs = { r: arrayify(sig.r), s: arrayify(sig.s) };
return "0x" + getCurve().recoverPubKey(arrayify(digest), rs, sig.recoveryParam).encode("hex", false);
}
export function computePublicKey(key, compressed) {
function recoverPublicKey(digest, signature) {
var sig = bytes_1.splitSignature(signature);
var rs = { r: bytes_1.arrayify(sig.r), s: bytes_1.arrayify(sig.s) };
return "0x" + getCurve().recoverPubKey(bytes_1.arrayify(digest), rs, sig.recoveryParam).encode("hex", false);
}
exports.recoverPublicKey = recoverPublicKey;