Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing canonical signature produced by Legder #180

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"graphql": "16.7.1",
"hdwallet-babyjub": "^0.0.2",
"idb": "^7.0.0",
"libzkbob-rs-wasm-web": "1.6.0-beta2",
"libzkbob-rs-wasm-web-mt": "1.6.0-beta2",
"libzkbob-rs-wasm-web": "1.6.0",
"libzkbob-rs-wasm-web-mt": "1.6.0",
"promise-throttle": "^1.1.2",
"regenerator-runtime": "^0.13.9",
"tronweb": "^5.3.0",
Expand Down
18 changes: 9 additions & 9 deletions src/networks/evm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -611,18 +611,18 @@ export class EvmNetwork extends MultiRpcManager implements NetworkBackend, RpcMa
public toCompactSignature(signature: string): string {
signature = truncateHexPrefix(signature);

if (signature.length > 128) {
if (signature.length == 130) {
// it seems it's an extended signature, let's compact it!
const v = signature.slice(128, 130);
if (v == "1c") {
const v = signature.slice(128).toLowerCase();
if (v == '1c' || v == '01') {
return `0x${signature.slice(0, 64)}${(parseInt(signature[64], 16) | 8).toString(16)}${signature.slice(65, 128)}`;
} else if (v != "1b") {
throw new InternalError("Invalid signature: v should be 27 or 28");
} else if (v != '1b' && v != '00') {
throw new InternalError('Invalid signature: v should be 27(0) or 28(1)');
}

return '0x' + signature.slice(0, 128);
} else if (signature.length < 128) {
throw new InternalError("invalid signature: it should consist at least 64 bytes (128 chars)");
} else if (signature.length != 128) {
throw new InternalError('Invalid signature: it should consist of 64 or 65 bytes (128\\130 chars)');
}

// it seems the signature already compact
Expand All @@ -636,9 +636,9 @@ export class EvmNetwork extends MultiRpcManager implements NetworkBackend, RpcMa
if (sig.length == 128) {
return `0x` + sig;
} else if (sig.length == 130) {
let v = "1b";
let v = '1b';
if (parseInt(sig[64], 16) > 7) {
v = "1c";
v = '1c';
sig = sig.slice(0, 64) + `${(parseInt(sig[64], 16) & 7).toString(16)}` + sig.slice(65);
}
return `0x` + sig + v;
Expand Down
26 changes: 13 additions & 13 deletions src/networks/tron/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,18 +546,18 @@ export class TronNetwork extends MultiRpcManager implements NetworkBackend, RpcM
public toCompactSignature(signature: string): string {
signature = truncateHexPrefix(signature);

if (signature.length > 128) {
if (signature.length == 130) {
// it seems it's an extended signature, let's compact it!
const v = signature.slice(128, 130);
if (v == "1c") {
const v = signature.slice(128).toLowerCase();
if (v == '1c' || v == '01') {
return `0x${signature.slice(0, 64)}${(parseInt(signature[64], 16) | 8).toString(16)}${signature.slice(65, 128)}`;
} else if (v != "1b") {
throw new InternalError("Invalid signature: v should be 27 or 28");
} else if (v != '1b' && v != '00') {
throw new InternalError('Invalid signature: v should be 27(0) or 28(1)');
}

return '0x' + signature.slice(0, 128);
} else if (signature.length < 128) {
throw new InternalError("invalid signature: it should consist at least 64 bytes (128 chars)");
} else if (signature.length != 128) {
throw new InternalError('Invalid signature: it should consist of 64 or 65 bytes (128\\130 chars)');
}

// it seems the signature already compact
Expand All @@ -569,13 +569,13 @@ export class TronNetwork extends MultiRpcManager implements NetworkBackend, RpcM

if ((sig.length % 2) == 0) {
if (sig.length == 128) {
return `0x` + sig;
return `0x` + sig;
} else if (sig.length == 130) {
let v = "1b";
if (parseInt(sig[64], 16) > 7) {
v = "1c";
sig = sig.slice(0, 64) + `${(parseInt(sig[64], 16) & 7).toString(16)}` + sig.slice(65);
}
let v = '1b';
if (parseInt(sig[64], 16) > 7) {
v = '1c';
sig = sig.slice(0, 64) + `${(parseInt(sig[64], 16) & 7).toString(16)}` + sig.slice(65);
}
return `0x` + sig + v;
} else {
throw new InternalError(`Incorrect signature length (${sig.length}), expected 64 or 65 bytes (128 or 130 chars)`);
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4986,15 +4986,15 @@ levn@^0.3.0, levn@~0.3.0:
prelude-ls "~1.1.2"
type-check "~0.3.2"

libzkbob-rs-wasm-web-mt@1.6.0-beta2:
version "1.6.0-beta2"
resolved "https://registry.yarnpkg.com/libzkbob-rs-wasm-web-mt/-/libzkbob-rs-wasm-web-mt-1.6.0-beta2.tgz#a324d891d4c0418d185d64aba06a126d7e626cab"
integrity sha512-BKXR/Gsl0uGhjWGhiLhDJ/ckq4+cnNgjxVGARWkXyRRXyHzUNBL9VHf4HQwxNVwOK/Vl3rRTA0A3wukOpXL5Qg==

libzkbob-rs-wasm-web@1.6.0-beta2:
version "1.6.0-beta2"
resolved "https://registry.yarnpkg.com/libzkbob-rs-wasm-web/-/libzkbob-rs-wasm-web-1.6.0-beta2.tgz#bb3b87758efb7082fcb2ee0fce5a0da85119cd99"
integrity sha512-XbR7x7kcYAJIEVPa+HppkfpWvbgX2pSB5fjSfUN16c5UUwY+ahrmqKpTBenPF4HvhrglmBpworQjCWo8d2HcrQ==
libzkbob-rs-wasm-web-mt@1.6.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/libzkbob-rs-wasm-web-mt/-/libzkbob-rs-wasm-web-mt-1.6.0.tgz#9437cdd240fb1ac47e6e3fbc7e34f45ade5af19e"
integrity sha512-nAfmUh8ZrQ5WfEc3v7+vWWRWjOy3uFWn/LRdIce7zmnq1t8X91MD+RgnPcHxbgDpz5eGpSn5V/OSc3XYPwm9aw==

libzkbob-rs-wasm-web@1.6.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/libzkbob-rs-wasm-web/-/libzkbob-rs-wasm-web-1.6.0.tgz#050887671fb1af20adb22a144e95e06c59e42460"
integrity sha512-Mtpc/pqutA2tUzb8nir7Ec2oXTSPbYvjf969QsJKcdJR/JmCGbv1gmylxjVdL7QnAUTH3ldt0jj5CU8v8X6yzw==

lie@3.1.1:
version "3.1.1"
Expand Down