From a2a10e2b1a8d921010dd67ee1ae28d1ef456329b Mon Sep 17 00:00:00 2001 From: Kelong Cong Date: Thu, 7 Nov 2024 09:56:33 +0100 Subject: [PATCH] Fix input proof encoding; the gateway does not return 0x prefix --- src/sdk/encrypt.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/sdk/encrypt.ts b/src/sdk/encrypt.ts index c2f5f2b..f82f97f 100644 --- a/src/sdk/encrypt.ts +++ b/src/sdk/encrypt.ts @@ -286,6 +286,8 @@ export const createEncryptedInput = console.log('verify_proven_ct failed with error', e); throw new Error("Gateway didn't response correctly"); } + + // Note that the hex strings returned by the gateway do have have the 0x prefix let handles: Uint8Array[] = []; if (json.response.handles && json.response.handles.length > 0) { handles = json.response.handles.map(fromHexString); @@ -294,7 +296,7 @@ export const createEncryptedInput = const kmsSignatures = json.response.kms_signatures; // inputProof is len(list_handles) + numSignersKMS + hashCT + list_handles + signatureCopro + signatureKMSSigners (1+1+32+NUM_HANDLES*32+65+65*numSignersKMS) - let inputProof = '0x' + numberToHex(handles.length); // for coprocessor : numHandles + numSignersKMS + hashCT + list_handles + signatureCopro + signatureKMSSigners (total len : 1+1+32+NUM_HANDLES*32+65+65*numSignersKMS) + let inputProof = numberToHex(handles.length); // for coprocessor : numHandles + numSignersKMS + hashCT + list_handles + signatureCopro + signatureKMSSigners (total len : 1+1+32+NUM_HANDLES*32+65+65*numSignersKMS) // for native : numHandles + numSignersKMS + list_handles + signatureKMSSigners + bundleCiphertext (total len : 1+1+NUM_HANDLES*32+65*numSignersKMS+bundleCiphertext.length) const numSigners = kmsSignatures.length; inputProof += numberToHex(numSigners); @@ -305,15 +307,15 @@ export const createEncryptedInput = const listHandlesStr = handles.map((i) => toHexString(i)); listHandlesStr.map((handle) => (inputProof += handle)); - inputProof += json.response.proof_of_storage.slice(2); + inputProof += json.response.proof_of_storage; - kmsSignatures.map((sigKMS) => (inputProof += sigKMS.slice(2))); + kmsSignatures.map((sigKMS) => (inputProof += sigKMS)); } else { // native const listHandlesStr = handles.map((i) => toHexString(i)); listHandlesStr.map((handle) => (inputProof += handle)); - kmsSignatures.map((sigKMS) => (inputProof += sigKMS.slice(2))); + kmsSignatures.map((sigKMS) => (inputProof += sigKMS)); inputProof += toHexString(ciphertext); }