From 0f9efd58bab2c99206d4aa6fd4dc102725bdc4fc Mon Sep 17 00:00:00 2001 From: EvgenKor Date: Mon, 8 Jan 2024 15:39:44 +0300 Subject: [PATCH 1/2] Parsing canonical signature produced by Legder (0/1 instead 1b/1c) --- src/networks/evm/index.ts | 18 +++++++++--------- src/networks/tron/index.ts | 26 +++++++++++++------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/networks/evm/index.ts b/src/networks/evm/index.ts index fe255af..8bcc5eb 100644 --- a/src/networks/evm/index.ts +++ b/src/networks/evm/index.ts @@ -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 @@ -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; diff --git a/src/networks/tron/index.ts b/src/networks/tron/index.ts index 23ab264..2efb65d 100644 --- a/src/networks/tron/index.ts +++ b/src/networks/tron/index.ts @@ -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 @@ -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)`); From a056f9e81f8dd435c586f0e50e24591d8b247cb2 Mon Sep 17 00:00:00 2001 From: EvgenKor Date: Mon, 8 Jan 2024 16:12:22 +0300 Subject: [PATCH 2/2] Updating wasm library version to the production one --- package.json | 4 ++-- yarn.lock | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index bc7ce1a..d55c6d2 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/yarn.lock b/yarn.lock index 24dc136..0615178 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"