diff --git a/src/core/crypto/veiled/VeiledInvoice.ts b/src/core/crypto/veiled/VeiledInvoice.ts index c915457a..f1cdc252 100644 --- a/src/core/crypto/veiled/VeiledInvoice.ts +++ b/src/core/crypto/veiled/VeiledInvoice.ts @@ -2,10 +2,10 @@ import { bytesToNumberLE, concatBytes, numberToBytesLE } from "@noble/curves/abs import { RistrettoPoint } from "@noble/curves/ed25519"; import { utf8ToBytes } from "@noble/hashes/utils"; import { H_RISTRETTO, TwistedEd25519PrivateKey, TwistedEd25519PublicKey } from "../twistedEd25519"; -import { TwistedElGamal, TwistedElGamalCiphertext } from "../twistedElGamal"; +import { TwistedElGamalCiphertext } from "../twistedElGamal"; import { ed25519GenListOfRandom, ed25519modN } from "../utils"; import { PROOF_CHUNK_SIZE, SIGMA_PROOF_TRANSFER_SIZE } from "./consts"; -import { genFiatShamirChallenge, publicKeyToU8 } from "./helpers"; +import { genFiatShamirChallenge } from "./helpers"; import { RangeProofExecutor } from "../rangeProof"; import { VeiledAmount } from "./veiledAmount"; @@ -18,39 +18,30 @@ export type VeiledInvoiceSigmaProof = { }; export type CreateVeiledInvoiceOpArgs = { - senderDecryptionKey: TwistedEd25519PrivateKey; + creatorDecryptionKey: TwistedEd25519PrivateKey; + payerPublicKey: TwistedEd25519PublicKey; invoiceValueAmount: bigint; - encryptedInvoiceValue: TwistedElGamalCiphertext[]; - auditorEncryptionKeys?: TwistedEd25519PublicKey[]; randomness?: bigint[]; }; export class VeiledInvoice { - senderDecryptionKey: TwistedEd25519PrivateKey; + creatorDecryptionKey: TwistedEd25519PrivateKey; - veiledInvoiceValue: VeiledAmount; - - auditorEncryptionKeys: TwistedEd25519PublicKey[]; - - auditorsU8EncryptionKeys: Uint8Array[]; + payerPublicKey: TwistedEd25519PublicKey; - auditorsVBList: TwistedElGamalCiphertext[][]; + veiledInvoiceValue: VeiledAmount; randomness: bigint[]; constructor(args: { - senderDecryptionKey: TwistedEd25519PrivateKey; + creatorDecryptionKey: TwistedEd25519PrivateKey; + payerPublicKey: TwistedEd25519PublicKey; veiledInvoiceValue: VeiledAmount; - auditorEncryptionKeys: TwistedEd25519PublicKey[]; - auditorsU8EncryptionKeys: Uint8Array[]; - auditorsVBList: TwistedElGamalCiphertext[][]; randomness: bigint[]; }) { - this.senderDecryptionKey = args.senderDecryptionKey; + this.creatorDecryptionKey = args.creatorDecryptionKey; + this.payerPublicKey = args.payerPublicKey; this.veiledInvoiceValue = args.veiledInvoiceValue; - this.auditorEncryptionKeys = args.auditorEncryptionKeys; - this.auditorsU8EncryptionKeys = args.auditorsU8EncryptionKeys; - this.auditorsVBList = args.auditorsVBList; this.randomness = args.randomness; } @@ -60,21 +51,12 @@ export class VeiledInvoice { const veiledInvoiceValue = VeiledAmount.fromAmount(args.invoiceValueAmount, { chunksCount: 2, }); - veiledInvoiceValue.encrypt(args.senderDecryptionKey.publicKey(), randomness); - - const auditorsU8PublicKeys = args.auditorEncryptionKeys?.map((pk) => publicKeyToU8(pk)) ?? []; - - const auditorsVBList = - args.auditorEncryptionKeys?.map((el) => - veiledInvoiceValue.amountChunks.map((chunk, i) => TwistedElGamal.encryptWithPK(chunk, el, randomness[i])), - ) || []; + veiledInvoiceValue.encrypt(args.payerPublicKey, randomness); return new VeiledInvoice({ - senderDecryptionKey: args.senderDecryptionKey, + creatorDecryptionKey: args.creatorDecryptionKey, + payerPublicKey: args.payerPublicKey, veiledInvoiceValue, - auditorEncryptionKeys: args.auditorEncryptionKeys ?? [], - auditorsU8EncryptionKeys: auditorsU8PublicKeys, - auditorsVBList, randomness, }); } @@ -119,10 +101,10 @@ export class VeiledInvoice { } async genSigmaProof(): Promise { - if (this.randomness && this.randomness.length !== VeiledAmount.CHUNKS_COUNT) + if (this.randomness && this.randomness.length !== this.veiledInvoiceValue.chunksCount) throw new TypeError("Invalid length list of randomness"); - const senderPKRistretto = RistrettoPoint.fromHex(this.senderDecryptionKey.publicKey().toUint8Array()); + const senderPKRistretto = RistrettoPoint.fromHex(this.payerPublicKey.toUint8Array()); // Prover selects random x1j[], x2j[], where j in {0, 1} const j = 2; @@ -140,7 +122,7 @@ export class VeiledInvoice { utf8ToBytes(VeiledInvoice.FIAT_SHAMIR_SIGMA_DST), RistrettoPoint.BASE.toRawBytes(), H_RISTRETTO.toRawBytes(), - this.senderDecryptionKey.publicKey().toUint8Array(), + this.payerPublicKey.toUint8Array(), ...this.veiledInvoiceValue.amountEncrypted!.map((el) => el.serialize()).flat(), ...X1List.map((el) => el.toRawBytes()), ...X2List.map((el) => el.toRawBytes()), @@ -160,8 +142,7 @@ export class VeiledInvoice { } static verifySigmaProof(opts: { - senderPublicKey: TwistedEd25519PublicKey; - recipientPublicKey: TwistedEd25519PublicKey; + payerPublicKey: TwistedEd25519PublicKey; encryptedInvoiceAmount: TwistedElGamalCiphertext[]; sigmaProof: VeiledInvoiceSigmaProof; }): boolean { @@ -172,7 +153,7 @@ export class VeiledInvoice { utf8ToBytes(VeiledInvoice.FIAT_SHAMIR_SIGMA_DST), RistrettoPoint.BASE.toRawBytes(), H_RISTRETTO.toRawBytes(), - opts.senderPublicKey.toUint8Array(), + opts.payerPublicKey.toUint8Array(), ...opts.encryptedInvoiceAmount.map((el) => el.serialize()).flat(), ...opts.sigmaProof.X1List, ...opts.sigmaProof.X2List, @@ -188,12 +169,22 @@ export class VeiledInvoice { .add(opts.encryptedInvoiceAmount[idx].C.multiply(p)), ); - const senderPKRistretto = RistrettoPoint.fromHex(opts.senderPublicKey.toString()); + const senderPKRistretto = RistrettoPoint.fromHex(opts.payerPublicKey.toUint8Array()); const X2List = alpha2LEList .slice(0, j) .map((el, idx) => senderPKRistretto.multiply(el).add(opts.encryptedInvoiceAmount[idx].D.multiply(p))); + console.log( + "X1List", + X1List.every((X1, i) => X1.equals(RistrettoPoint.fromHex(opts.sigmaProof.X1List[i]))), + ); + + console.log( + "X2List", + X2List.every((X2, i) => X2.equals(RistrettoPoint.fromHex(opts.sigmaProof.X2List[i]))), + ); + return ( X1List.every((X1, i) => X1.equals(RistrettoPoint.fromHex(opts.sigmaProof.X1List[i]))) && X2List.every((X2, i) => X2.equals(RistrettoPoint.fromHex(opts.sigmaProof.X2List[i]))) @@ -205,7 +196,7 @@ export class VeiledInvoice { this.veiledInvoiceValue.amountChunks.map((chunk) => RangeProofExecutor.generateRangeZKP({ v: chunk, - r: this.senderDecryptionKey.toUint8Array(), + r: this.creatorDecryptionKey.toUint8Array(), valBase: RistrettoPoint.BASE.toRawBytes(), randBase: H_RISTRETTO.toRawBytes(), }), diff --git a/src/core/crypto/veiled/veiledTransfer.ts b/src/core/crypto/veiled/veiledTransfer.ts index ba49d571..86fedb0c 100644 --- a/src/core/crypto/veiled/veiledTransfer.ts +++ b/src/core/crypto/veiled/veiledTransfer.ts @@ -133,7 +133,9 @@ export class VeiledTransfer { let veiledInvoiceAmount: VeiledAmount | undefined; if (args.veiledInvoiceAmount) { + console.log("try to decrypt invoice payment"); veiledInvoiceAmount = await VeiledAmount.fromEncrypted(args.veiledInvoiceAmount, args.senderDecryptionKey); + console.log("decrypted invoice payment", veiledInvoiceAmount.amount); } let veiledMinTransferAmount: VeiledAmount | undefined; @@ -349,7 +351,9 @@ export class VeiledTransfer { ); let alpha7List: bigint[] | undefined; if (this.veiledInvoiceAmount?.amountChunks?.length) { - alpha7List = x7List.slice(0, j).map((el, idx) => el - p * this.veiledInvoiceAmount!.amountChunks[idx]); + alpha7List = x7List + .slice(0, j) + .map((el, idx) => ed25519modN(el - p * this.veiledInvoiceAmount!.amountChunks[idx])); } return { @@ -372,7 +376,7 @@ export class VeiledTransfer { } static verifySigmaProof(opts: { - senderPrivateKey: TwistedEd25519PrivateKey; + senderPublicKey: TwistedEd25519PublicKey; recipientPublicKey: TwistedEd25519PublicKey; encryptedActualBalance: TwistedElGamalCiphertext[]; encryptedActualBalanceAfterTransfer: TwistedElGamalCiphertext[]; @@ -397,7 +401,7 @@ export class VeiledTransfer { const alpha6LEList = opts.sigmaProof.alpha6List.map((a) => bytesToNumberLE(a)); // const alpha7LEList = opts.sigmaProof.alpha7List?.map((a) => bytesToNumberLE(a)) ?? []; - const senderPublicKeyU8 = publicKeyToU8(opts.senderPrivateKey.publicKey()); + const senderPublicKeyU8 = publicKeyToU8(opts.senderPublicKey); const recipientPublicKeyU8 = publicKeyToU8(opts.recipientPublicKey); const senderPKRistretto = RistrettoPoint.fromHex(senderPublicKeyU8); const recipientPKRistretto = RistrettoPoint.fromHex(recipientPublicKeyU8); @@ -498,6 +502,17 @@ export class VeiledTransfer { ); } + console.log({ + X1: X1.equals(RistrettoPoint.fromHex(opts.sigmaProof.X1)), + X2List: X2List.every((X2, i) => X2.equals(RistrettoPoint.fromHex(opts.sigmaProof.X2List[i]))), + X3List: X3List.every((X3, i) => X3.equals(RistrettoPoint.fromHex(opts.sigmaProof.X3List[i]))), + X4List: X4List.every((X4, i) => X4.equals(RistrettoPoint.fromHex(opts.sigmaProof.X4List[i]))), + X5: X5.equals(RistrettoPoint.fromHex(opts.sigmaProof.X5)), + X6List: X6List.every((X6, i) => X6.equals(RistrettoPoint.fromHex(opts.sigmaProof.X6List[i]))), + X7List: X7List.flat().every((X7, i) => X7.equals(RistrettoPoint.fromHex(proofX7List[i]))), + X8List: X8List.flat().every((X8, i) => X8.equals(RistrettoPoint.fromHex(proofX8List[i]))), + }); + return ( X1.equals(RistrettoPoint.fromHex(opts.sigmaProof.X1)) && X2List.every((X2, i) => X2.equals(RistrettoPoint.fromHex(opts.sigmaProof.X2List[i]))) && diff --git a/tests/unit/veiled/VeiledInvoice.test.ts b/tests/unit/veiled/VeiledInvoice.test.ts deleted file mode 100644 index 3b5921c9..00000000 --- a/tests/unit/veiled/VeiledInvoice.test.ts +++ /dev/null @@ -1,390 +0,0 @@ -import { - KangarooRistretto, - RangeProofExecutor, - TwistedEd25519PrivateKey, - VeiledAmount, - VeiledTransfer, - VeiledTransferRangeProof, - VeiledTransferSigmaProof, -} from "../../../src"; -import { generateRangeZKP, verifyRangeZKP } from "./wasmRangeProof"; -import { loadTableMap } from "./helpers"; -import { longTestTimeout } from "../helper"; - -/** !important: for testing purposes */ -RangeProofExecutor.setGenerateRangeZKP(generateRangeZKP); -RangeProofExecutor.setVerifyRangeZKP(verifyRangeZKP); - -describe("Create and pay veiled invoice", () => { - const alice = TwistedEd25519PrivateKey.generate(); - const aliceBalance = VeiledAmount.fromAmount(50n); - aliceBalance.encrypt(alice.publicKey()); - - const bob = TwistedEd25519PrivateKey.generate(); - const bobBalance = VeiledAmount.fromAmount(25n); - bobBalance.encrypt(bob.publicKey()); - - const PAYMENT_AMOUNT = 10n; - - it("Pre load table map", async () => { - const [table16, table32, table48] = await Promise.all([ - loadTableMap( - "https://raw.githubusercontent.com/distributed-lab/pollard-kangaroo-plus-testing/refs/heads/tables/output_8_8000_16_64.json", - ), - loadTableMap( - "https://raw.githubusercontent.com/distributed-lab/pollard-kangaroo-plus-testing/refs/heads/tables/output_2048_4000_32_128.json", - ), - loadTableMap( - "https://raw.githubusercontent.com/distributed-lab/pollard-kangaroo-plus-testing/refs/heads/tables/output_65536_40000_48_128.json", - ), - ]); - - KangarooRistretto.setTableWithParams({ - table: table16, - n: 8_000, - w: 8n, - r: 64n, - secretSize: 16, - }); - KangarooRistretto.setTableWithParams({ - table: table32, - n: 4_000, - w: 2048n, - r: 128n, - secretSize: 32, - }); - KangarooRistretto.setTableWithParams({ - table: table48, - n: 40_000, - w: 65536n, - r: 128n, - secretSize: 48, - }); - - expect(Object.keys(KangarooRistretto.tablesMapWithParams).length).toEqual(3); - }); - - let invoice: VeiledTransfer; - it( - `Alice create invoice(${PAYMENT_AMOUNT}) to Bob`, - async () => { - const encryptedMinAmount = VeiledAmount.fromAmount(PAYMENT_AMOUNT); - encryptedMinAmount.encrypt(alice.publicKey()); - - invoice = await VeiledTransfer.create({ - senderDecryptionKey: alice, - encryptedActualBalance: aliceBalance.amountEncrypted!, - amountToTransfer: PAYMENT_AMOUNT, - recipientEncryptionKey: bob.publicKey(), - encryptedMinAmount: encryptedMinAmount.amountEncrypted!, - }); - - expect(invoice).toBeDefined(); - }, - longTestTimeout, - ); - - let sigmaProof: VeiledTransferSigmaProof; - it("Alice generate sigma proof", async () => { - sigmaProof = await invoice.genSigmaProof(); - - expect(sigmaProof).toBeDefined(); - }); - - let rangeProof: VeiledTransferRangeProof; - it("Alice generate range proof", async () => { - rangeProof = await invoice.genRangeProof(); - - expect(rangeProof).toBeDefined(); - }); - - it("verify sigma proof", async () => { - const result = VeiledTransfer.verifySigmaProof({ - senderPrivateKey: alice, - recipientPublicKey: bob.publicKey(), - encryptedActualBalance: aliceBalance.amountEncrypted!, - encryptedActualBalanceAfterTransfer: invoice.veiledAmountAfterTransfer?.amountEncrypted!, - encryptedTransferAmountByRecipient: invoice.encryptedAmountByRecipient, - sigmaProof, - }); - expect(result).toBeTruthy(); - }); - - it("verify range proof", async () => { - const isValid = await VeiledTransfer.verifyRangeProof({ - encryptedAmountByRecipient: invoice.encryptedAmountByRecipient, - encryptedActualBalanceAfterTransfer: invoice.veiledAmountAfterTransfer.amountEncrypted!, - rangeProofAmount: rangeProof.rangeProofAmount, - rangeProofNewBalance: rangeProof.rangeProofNewBalance, - rangeProofAmountDiff: rangeProof.rangeProofAmountDiff, - }); - - expect(isValid).toBeTruthy(); - }); - - it("fail gen invalid range proof", async () => { - const encryptedMinAmount = VeiledAmount.fromAmount(PAYMENT_AMOUNT); - encryptedMinAmount.encrypt(alice.publicKey()); - - const invalidPayment = await VeiledTransfer.create({ - senderDecryptionKey: alice, - encryptedActualBalance: aliceBalance.amountEncrypted!, - amountToTransfer: 5n, - recipientEncryptionKey: bob.publicKey(), - encryptedMinAmount: encryptedMinAmount.amountEncrypted, - }); - - try { - await invalidPayment.genRangeProof(); - } catch (error) { - expect((error as Error).message === "Amount to transfer is less than the minimum amount"); - } - }); - - it("fail verify invalid range proof", async () => { - // range proof for minAmount = PAYMENT_AMOUNT and transferAmount = PAYMENT_AMOUNT - const invalidRangeProof: VeiledTransferRangeProof = { - rangeProofAmount: [ - new Uint8Array([ - 122, 32, 245, 132, 247, 117, 214, 75, 164, 251, 47, 114, 171, 187, 152, 174, 74, 9, 78, 188, 128, 103, 137, - 193, 237, 227, 217, 249, 111, 30, 141, 100, 182, 254, 249, 150, 45, 106, 94, 141, 26, 85, 251, 157, 124, 253, - 220, 21, 89, 181, 30, 99, 192, 190, 53, 134, 113, 12, 55, 107, 209, 56, 246, 108, 74, 192, 238, 70, 139, 147, - 26, 189, 41, 17, 230, 196, 199, 176, 22, 195, 98, 217, 236, 7, 160, 149, 79, 46, 7, 55, 75, 129, 145, 62, 88, - 56, 40, 244, 217, 229, 110, 224, 180, 107, 2, 108, 232, 76, 250, 208, 94, 241, 145, 92, 81, 109, 115, 31, 229, - 116, 124, 92, 205, 72, 170, 122, 151, 127, 234, 133, 90, 158, 140, 206, 139, 67, 91, 123, 220, 237, 200, 112, - 88, 192, 113, 213, 32, 75, 73, 197, 115, 212, 234, 38, 169, 43, 57, 54, 7, 10, 1, 132, 218, 154, 144, 217, - 171, 137, 216, 40, 159, 77, 63, 210, 63, 99, 91, 79, 85, 57, 230, 200, 113, 191, 37, 107, 84, 234, 197, 78, 6, - 3, 245, 185, 243, 19, 15, 240, 27, 37, 159, 121, 230, 178, 144, 220, 153, 125, 118, 200, 67, 58, 207, 202, - 241, 79, 221, 208, 248, 115, 181, 191, 73, 4, 106, 60, 195, 196, 174, 177, 87, 168, 70, 8, 212, 6, 250, 152, - 168, 132, 244, 110, 209, 99, 218, 29, 148, 233, 255, 1, 231, 139, 231, 14, 167, 7, 126, 170, 92, 114, 132, - 108, 166, 20, 84, 66, 187, 90, 76, 169, 2, 154, 30, 20, 98, 73, 150, 251, 180, 62, 2, 79, 218, 28, 68, 66, 11, - 127, 152, 20, 140, 169, 172, 187, 88, 168, 75, 176, 224, 126, 55, 129, 244, 179, 147, 55, 191, 59, 5, 114, 66, - 132, 18, 163, 40, 201, 130, 67, 63, 42, 154, 242, 210, 23, 14, 223, 6, 186, 111, 123, 241, 150, 101, 129, 211, - 221, 17, 184, 182, 111, 212, 78, 120, 139, 56, 17, 175, 53, 107, 200, 8, 89, 220, 116, 44, 186, 74, 91, 16, - 61, 254, 133, 83, 43, 162, 248, 206, 44, 45, 142, 104, 179, 32, 103, 1, 183, 87, 212, 241, 128, 55, 14, 221, - 76, 46, 71, 169, 144, 227, 148, 175, 57, 160, 175, 195, 218, 29, 82, 211, 135, 88, 255, 168, 179, 254, 4, 254, - 245, 191, 97, 33, 107, 164, 180, 124, 82, 182, 79, 133, 103, 109, 97, 113, 228, 219, 162, 74, 52, 155, 121, 0, - 108, 136, 28, 230, 3, 217, 69, 221, 171, 148, 149, 61, 75, 194, 232, 225, 57, 96, 69, 72, 1, 139, 35, 195, 14, - 235, 56, 142, 42, 101, 166, 13, 170, 204, 42, 11, 216, 21, 193, 44, 230, 0, 150, 138, 84, 10, 82, 252, 73, 16, - 62, 66, 33, 172, 160, 3, 145, 215, 32, 194, 251, 66, 76, 65, 92, 188, 133, 93, 98, 7, 95, 4, 183, 23, 117, - 132, 230, 47, 104, 106, 97, 194, 253, 41, 26, 63, 163, 237, 181, 16, 25, 165, 127, 175, 248, 180, 40, 87, 15, - 201, 0, 227, 118, 112, 99, 80, 63, 123, 221, 37, 79, 158, 56, 215, 45, 88, 182, 27, 164, 64, 213, 22, 197, 86, - 139, 23, 43, 255, 115, 168, 164, 193, 76, 160, 231, 185, 67, 23, 145, 176, 213, 131, 27, 161, 6, 217, 158, 74, - 127, 143, 234, 29, 104, 211, 92, 53, 244, 212, 89, 244, 116, 203, 22, 166, 73, 200, 193, 28, 220, 168, 58, 28, - 103, 44, 234, 23, 12, - ]), - new Uint8Array([ - 136, 88, 135, 141, 190, 209, 64, 172, 129, 207, 11, 138, 64, 72, 132, 213, 187, 196, 204, 100, 200, 154, 26, - 209, 115, 123, 0, 52, 157, 247, 89, 95, 6, 128, 150, 139, 138, 88, 124, 67, 132, 118, 248, 68, 130, 225, 124, - 89, 61, 180, 198, 114, 98, 236, 250, 121, 177, 30, 73, 38, 116, 54, 222, 108, 114, 231, 100, 180, 212, 21, - 157, 72, 168, 135, 218, 151, 19, 179, 224, 219, 150, 49, 82, 194, 187, 162, 207, 131, 134, 33, 131, 245, 28, - 80, 37, 59, 244, 168, 248, 98, 16, 240, 87, 154, 73, 106, 85, 18, 219, 0, 4, 25, 246, 90, 169, 86, 217, 51, - 156, 247, 137, 76, 112, 64, 40, 253, 113, 64, 48, 106, 166, 74, 229, 168, 5, 146, 199, 154, 204, 156, 175, 17, - 215, 138, 3, 120, 218, 183, 186, 127, 84, 249, 12, 51, 56, 80, 62, 213, 197, 15, 248, 27, 183, 140, 35, 109, - 102, 205, 226, 208, 251, 39, 88, 63, 50, 135, 192, 63, 2, 245, 30, 143, 221, 76, 93, 31, 131, 55, 98, 44, 237, - 3, 144, 86, 119, 112, 95, 158, 18, 54, 27, 205, 44, 138, 35, 52, 240, 172, 172, 217, 62, 193, 255, 151, 240, - 252, 1, 18, 233, 201, 31, 40, 249, 1, 2, 221, 144, 161, 40, 235, 216, 87, 145, 132, 92, 135, 206, 18, 79, 249, - 177, 86, 235, 63, 148, 39, 154, 139, 182, 88, 161, 238, 251, 94, 153, 18, 84, 242, 230, 168, 85, 93, 151, 15, - 164, 41, 152, 135, 133, 148, 82, 27, 87, 133, 156, 2, 42, 222, 146, 218, 183, 140, 231, 251, 180, 56, 33, 15, - 14, 70, 118, 214, 65, 157, 245, 233, 11, 45, 120, 174, 200, 36, 146, 206, 83, 23, 3, 197, 20, 12, 146, 28, 48, - 65, 38, 202, 74, 248, 241, 34, 190, 114, 108, 110, 162, 114, 152, 150, 248, 6, 58, 216, 224, 170, 176, 78, 87, - 63, 174, 147, 195, 67, 149, 54, 71, 113, 122, 181, 34, 53, 145, 72, 44, 19, 233, 33, 46, 79, 166, 144, 201, - 69, 49, 46, 131, 138, 212, 116, 252, 25, 171, 158, 198, 95, 113, 184, 147, 170, 244, 233, 186, 19, 112, 33, - 218, 167, 129, 89, 135, 155, 23, 25, 144, 140, 208, 236, 36, 46, 73, 156, 40, 135, 54, 154, 138, 252, 203, - 199, 92, 6, 80, 8, 117, 78, 124, 103, 124, 66, 211, 50, 5, 163, 82, 16, 221, 4, 201, 90, 190, 254, 37, 175, - 17, 146, 71, 247, 25, 84, 69, 248, 75, 103, 89, 158, 102, 254, 175, 94, 64, 144, 58, 155, 141, 249, 152, 1, - 138, 180, 94, 123, 45, 186, 71, 65, 234, 109, 235, 223, 195, 108, 45, 145, 186, 2, 102, 18, 209, 162, 101, 99, - 88, 162, 9, 232, 44, 71, 209, 86, 97, 57, 25, 67, 147, 30, 16, 70, 232, 52, 25, 58, 104, 33, 241, 44, 43, 76, - 223, 224, 159, 178, 18, 112, 180, 177, 194, 163, 101, 143, 223, 140, 182, 70, 25, 91, 133, 246, 159, 175, 158, - 100, 4, 59, 129, 41, 174, 75, 201, 183, 55, 161, 220, 160, 236, 89, 91, 255, 189, 226, 179, 127, 85, 135, 130, - 214, 197, 51, 11, 105, 132, 92, 196, 13, 200, 61, 16, 246, 145, 88, 185, 120, 45, 144, 29, 135, 7, 3, 155, - 132, 102, 133, 160, 198, 127, 126, 92, 214, 139, 100, 51, 129, 17, 168, 144, 62, 178, 136, 88, 63, 143, 46, - 184, 112, 164, 164, 120, 247, 243, 0, - ]), - ], - rangeProofNewBalance: [ - new Uint8Array([ - 174, 247, 24, 13, 240, 79, 73, 124, 99, 10, 91, 144, 223, 229, 163, 226, 191, 60, 228, 127, 248, 178, 52, 22, - 99, 1, 131, 165, 95, 199, 221, 38, 48, 116, 129, 107, 242, 150, 83, 123, 27, 91, 35, 22, 180, 92, 39, 162, - 102, 16, 95, 149, 179, 115, 144, 116, 124, 136, 20, 187, 181, 56, 84, 16, 26, 4, 94, 142, 119, 48, 136, 89, - 93, 79, 31, 47, 181, 107, 210, 26, 124, 246, 26, 86, 238, 61, 75, 144, 242, 140, 208, 125, 251, 229, 147, 8, - 162, 43, 178, 66, 152, 34, 245, 30, 148, 214, 222, 87, 91, 97, 192, 152, 153, 239, 156, 246, 39, 76, 94, 116, - 216, 4, 8, 32, 146, 227, 71, 33, 172, 82, 149, 116, 36, 216, 183, 95, 102, 49, 97, 45, 139, 132, 105, 255, - 207, 209, 225, 33, 55, 8, 168, 98, 197, 50, 150, 60, 50, 76, 204, 15, 247, 236, 64, 40, 86, 134, 34, 162, 255, - 158, 254, 14, 147, 180, 247, 98, 7, 193, 170, 189, 182, 87, 148, 86, 61, 220, 102, 245, 107, 24, 90, 12, 200, - 200, 163, 138, 87, 21, 157, 18, 119, 66, 116, 8, 56, 88, 99, 157, 16, 228, 40, 149, 121, 126, 71, 196, 48, - 149, 231, 153, 150, 154, 94, 6, 138, 209, 246, 209, 173, 201, 76, 30, 145, 237, 8, 10, 210, 182, 231, 29, 197, - 38, 103, 113, 89, 157, 137, 165, 86, 93, 174, 80, 7, 223, 172, 56, 60, 37, 248, 88, 224, 227, 2, 201, 72, 88, - 50, 168, 47, 164, 254, 80, 95, 51, 207, 116, 255, 175, 153, 125, 40, 245, 49, 40, 98, 239, 186, 97, 158, 79, - 14, 81, 56, 161, 19, 154, 4, 156, 62, 221, 167, 157, 30, 191, 170, 205, 224, 254, 112, 42, 15, 7, 19, 86, 233, - 244, 129, 201, 100, 100, 0, 80, 202, 69, 216, 249, 121, 82, 152, 137, 32, 53, 64, 230, 74, 237, 57, 159, 225, - 91, 212, 155, 130, 146, 216, 237, 31, 214, 30, 65, 221, 18, 106, 129, 215, 134, 34, 250, 174, 11, 107, 172, - 91, 120, 201, 98, 108, 3, 9, 112, 113, 123, 115, 173, 196, 23, 183, 115, 28, 77, 136, 97, 6, 65, 6, 60, 66, 0, - 54, 43, 129, 255, 143, 71, 32, 144, 118, 216, 224, 43, 147, 102, 0, 233, 242, 212, 25, 226, 46, 37, 219, 136, - 60, 83, 45, 58, 10, 235, 220, 209, 142, 175, 190, 127, 123, 203, 81, 204, 245, 147, 247, 176, 113, 206, 43, - 87, 235, 230, 214, 7, 27, 75, 125, 52, 108, 38, 104, 12, 64, 115, 15, 150, 60, 56, 115, 0, 224, 153, 226, 61, - 237, 129, 35, 128, 183, 115, 228, 189, 189, 237, 16, 167, 155, 61, 142, 113, 244, 78, 22, 78, 12, 241, 170, - 188, 49, 215, 208, 121, 233, 167, 226, 46, 237, 0, 189, 7, 10, 217, 28, 33, 231, 225, 159, 65, 221, 122, 141, - 123, 136, 199, 191, 110, 238, 9, 65, 41, 20, 200, 192, 58, 201, 214, 7, 28, 80, 224, 255, 116, 158, 253, 50, - 183, 146, 216, 140, 194, 232, 217, 213, 99, 142, 25, 25, 120, 174, 240, 56, 145, 76, 89, 22, 58, 89, 121, 164, - 21, 54, 36, 248, 97, 230, 23, 97, 81, 40, 92, 82, 78, 54, 48, 191, 218, 215, 94, 222, 2, 202, 196, 136, 191, - 41, 242, 82, 240, 160, 100, 190, 238, 196, 250, 89, 121, 88, 152, 229, 99, 253, 158, 29, 12, 56, 108, 73, 157, - 37, 30, 215, 5, - ]), - new Uint8Array([ - 146, 140, 63, 104, 87, 105, 192, 49, 197, 251, 247, 40, 172, 217, 26, 150, 6, 241, 225, 201, 138, 57, 36, 31, - 28, 82, 167, 116, 234, 98, 48, 107, 114, 129, 111, 52, 50, 106, 199, 156, 142, 222, 29, 47, 49, 49, 183, 214, - 54, 186, 188, 160, 80, 132, 181, 49, 91, 72, 226, 105, 154, 117, 79, 44, 170, 17, 131, 75, 33, 34, 89, 146, - 18, 13, 237, 6, 107, 118, 90, 185, 239, 172, 75, 159, 154, 117, 113, 208, 5, 134, 9, 13, 177, 177, 35, 66, - 218, 87, 238, 158, 126, 240, 87, 77, 39, 102, 248, 72, 135, 246, 66, 188, 179, 128, 229, 86, 197, 222, 174, - 70, 45, 53, 63, 167, 172, 91, 3, 105, 152, 54, 229, 186, 236, 233, 149, 20, 70, 75, 53, 108, 124, 120, 35, 38, - 113, 224, 56, 254, 254, 237, 122, 141, 109, 23, 40, 121, 178, 163, 152, 8, 58, 203, 103, 160, 249, 173, 29, - 153, 5, 255, 134, 221, 144, 50, 51, 242, 123, 3, 91, 136, 74, 242, 196, 31, 150, 35, 157, 79, 111, 168, 121, - 14, 203, 6, 124, 110, 97, 223, 168, 91, 255, 115, 77, 194, 184, 86, 1, 195, 206, 240, 73, 87, 244, 174, 117, - 88, 213, 120, 241, 215, 185, 245, 75, 2, 220, 248, 167, 110, 94, 206, 253, 29, 131, 248, 28, 94, 220, 156, 0, - 158, 66, 120, 238, 23, 26, 173, 35, 193, 219, 156, 255, 32, 233, 254, 59, 87, 150, 90, 135, 148, 153, 109, - 185, 49, 3, 152, 190, 24, 23, 116, 223, 55, 68, 62, 2, 140, 76, 235, 192, 146, 98, 211, 62, 251, 113, 187, - 162, 76, 246, 45, 122, 219, 151, 100, 164, 242, 150, 212, 178, 137, 183, 104, 169, 66, 49, 245, 1, 3, 7, 73, - 78, 227, 177, 171, 255, 244, 46, 10, 7, 97, 210, 241, 137, 86, 47, 46, 20, 99, 188, 179, 115, 110, 72, 139, - 112, 197, 146, 13, 96, 76, 210, 156, 127, 16, 163, 18, 33, 196, 249, 97, 45, 28, 172, 222, 176, 67, 246, 46, - 164, 151, 221, 122, 243, 211, 241, 91, 78, 34, 103, 230, 10, 169, 218, 154, 137, 187, 172, 74, 26, 69, 11, - 145, 160, 75, 218, 94, 63, 49, 30, 96, 97, 110, 102, 195, 165, 69, 202, 111, 216, 214, 252, 31, 7, 32, 154, - 51, 251, 68, 5, 221, 66, 161, 238, 57, 63, 26, 200, 240, 242, 22, 175, 102, 218, 164, 139, 22, 8, 171, 119, - 250, 82, 104, 196, 27, 143, 191, 54, 245, 111, 73, 174, 124, 74, 231, 72, 59, 86, 51, 166, 50, 211, 3, 147, - 123, 37, 24, 166, 146, 125, 218, 227, 79, 2, 206, 159, 160, 18, 110, 167, 112, 79, 211, 255, 37, 12, 59, 232, - 84, 122, 111, 198, 248, 189, 104, 24, 202, 125, 232, 219, 41, 174, 229, 174, 159, 83, 67, 127, 105, 189, 37, - 88, 130, 58, 232, 166, 57, 19, 195, 151, 148, 242, 51, 154, 111, 40, 72, 146, 191, 78, 147, 33, 138, 10, 223, - 215, 24, 50, 219, 196, 7, 164, 156, 244, 138, 29, 168, 200, 1, 117, 94, 54, 98, 247, 89, 82, 209, 219, 80, - 206, 191, 5, 168, 190, 167, 140, 20, 37, 174, 78, 213, 49, 30, 196, 75, 59, 10, 51, 58, 76, 45, 139, 245, 71, - 12, 159, 0, 102, 9, 48, 239, 14, 40, 144, 48, 156, 122, 200, 15, 153, 167, 27, 91, 52, 88, 80, 21, 39, 62, - 218, 246, 163, 12, 125, 246, 16, 174, 116, 14, - ]), - new Uint8Array([ - 116, 112, 27, 163, 109, 29, 58, 147, 230, 237, 34, 58, 245, 197, 223, 18, 44, 136, 212, 68, 48, 255, 174, 220, - 203, 200, 179, 55, 45, 197, 195, 27, 6, 247, 207, 29, 163, 36, 212, 50, 18, 35, 118, 25, 223, 204, 116, 103, - 254, 116, 49, 33, 66, 176, 130, 57, 51, 18, 120, 202, 94, 252, 8, 94, 62, 161, 224, 34, 88, 248, 108, 196, - 184, 55, 250, 102, 2, 95, 70, 230, 130, 231, 159, 79, 202, 95, 180, 20, 96, 212, 98, 205, 66, 224, 70, 68, - 144, 193, 3, 159, 175, 15, 30, 204, 108, 33, 151, 20, 117, 17, 221, 100, 161, 13, 37, 67, 93, 224, 85, 2, 51, - 143, 105, 99, 30, 182, 63, 6, 146, 101, 10, 221, 124, 143, 71, 212, 225, 144, 255, 6, 49, 138, 213, 176, 82, - 220, 186, 119, 41, 254, 62, 131, 150, 225, 79, 177, 32, 203, 90, 13, 201, 29, 2, 235, 252, 83, 157, 54, 82, - 14, 211, 25, 208, 185, 147, 124, 12, 197, 91, 94, 36, 255, 42, 26, 65, 230, 139, 100, 32, 229, 187, 2, 80, 76, - 52, 210, 79, 124, 28, 141, 24, 13, 31, 87, 14, 56, 99, 172, 203, 189, 213, 215, 0, 125, 48, 117, 200, 197, - 158, 185, 224, 116, 208, 2, 126, 40, 241, 201, 79, 117, 193, 193, 27, 252, 91, 228, 232, 70, 36, 137, 224, - 161, 85, 237, 106, 193, 23, 49, 128, 227, 94, 207, 104, 220, 245, 63, 8, 221, 111, 192, 57, 88, 70, 193, 91, - 222, 50, 121, 75, 53, 64, 26, 144, 165, 212, 153, 250, 150, 213, 135, 210, 123, 210, 53, 241, 22, 43, 48, 78, - 229, 26, 119, 219, 1, 28, 178, 139, 8, 101, 85, 172, 219, 254, 219, 197, 89, 225, 24, 155, 5, 190, 147, 21, - 143, 144, 37, 123, 5, 156, 2, 124, 22, 123, 108, 194, 211, 29, 190, 156, 35, 138, 95, 121, 59, 251, 191, 229, - 166, 66, 76, 193, 77, 150, 192, 192, 39, 140, 248, 160, 194, 133, 81, 94, 61, 169, 117, 255, 34, 108, 161, 13, - 120, 88, 120, 206, 14, 137, 10, 96, 220, 132, 98, 206, 119, 64, 113, 115, 243, 152, 138, 196, 84, 46, 58, 12, - 9, 200, 214, 25, 35, 200, 150, 22, 207, 67, 175, 192, 62, 122, 255, 84, 28, 43, 106, 80, 20, 121, 173, 23, - 160, 194, 232, 224, 31, 65, 38, 34, 128, 66, 238, 187, 201, 10, 26, 175, 20, 92, 84, 6, 51, 20, 189, 117, 189, - 82, 204, 89, 178, 214, 199, 79, 175, 42, 190, 231, 75, 128, 37, 118, 93, 98, 182, 0, 59, 233, 87, 13, 235, - 199, 179, 55, 239, 123, 189, 90, 246, 54, 41, 100, 86, 133, 70, 161, 38, 9, 98, 255, 153, 162, 96, 154, 213, - 77, 155, 91, 234, 40, 120, 122, 245, 24, 114, 246, 221, 193, 148, 251, 197, 98, 156, 103, 130, 108, 113, 203, - 4, 111, 238, 12, 232, 254, 74, 148, 31, 239, 238, 148, 1, 96, 200, 53, 107, 193, 21, 126, 95, 168, 74, 36, 83, - 18, 237, 243, 210, 101, 103, 199, 199, 42, 200, 99, 9, 57, 1, 100, 71, 152, 243, 243, 74, 104, 88, 24, 187, - 81, 175, 245, 67, 204, 80, 172, 218, 11, 31, 110, 60, 228, 141, 113, 44, 242, 121, 13, 114, 21, 1, 221, 210, - 123, 113, 227, 90, 235, 88, 102, 17, 10, 99, 105, 190, 19, 102, 224, 177, 85, 160, 230, 169, 97, 171, 249, - 249, 25, 108, 146, 152, 46, 4, - ]), - new Uint8Array([ - 136, 179, 60, 151, 216, 238, 107, 68, 140, 64, 21, 153, 66, 114, 26, 78, 203, 130, 196, 22, 141, 107, 113, 20, - 171, 7, 65, 179, 52, 41, 56, 69, 110, 149, 13, 135, 233, 116, 98, 203, 67, 183, 192, 3, 55, 40, 219, 20, 96, - 237, 54, 152, 142, 20, 51, 254, 112, 119, 195, 178, 191, 247, 26, 67, 12, 192, 6, 181, 99, 232, 187, 99, 75, - 252, 228, 233, 22, 68, 17, 37, 182, 152, 35, 231, 215, 237, 41, 108, 67, 226, 194, 25, 159, 48, 9, 67, 136, - 51, 187, 78, 175, 22, 124, 185, 147, 253, 215, 228, 210, 58, 246, 18, 0, 243, 204, 76, 100, 101, 150, 168, - 138, 129, 140, 83, 209, 73, 245, 24, 198, 158, 86, 240, 102, 203, 37, 174, 63, 225, 199, 236, 87, 105, 128, - 161, 18, 139, 38, 62, 148, 160, 172, 202, 181, 40, 77, 120, 118, 241, 253, 2, 95, 216, 25, 137, 165, 243, 192, - 26, 237, 249, 89, 70, 93, 117, 184, 112, 160, 222, 203, 45, 61, 128, 149, 169, 89, 234, 205, 163, 130, 228, - 113, 14, 80, 200, 233, 36, 132, 202, 60, 101, 183, 19, 112, 125, 89, 238, 119, 18, 90, 75, 45, 155, 246, 241, - 195, 222, 66, 177, 92, 193, 120, 173, 22, 13, 152, 177, 194, 79, 100, 143, 54, 206, 73, 53, 232, 182, 71, 14, - 203, 41, 185, 157, 65, 45, 97, 30, 20, 80, 23, 175, 145, 29, 156, 235, 9, 17, 72, 211, 198, 241, 60, 203, 117, - 212, 59, 21, 228, 195, 23, 193, 144, 144, 9, 88, 45, 102, 242, 245, 223, 138, 124, 173, 114, 184, 225, 43, - 205, 80, 154, 106, 147, 253, 181, 149, 45, 190, 219, 216, 162, 104, 92, 191, 243, 67, 131, 162, 1, 13, 14, 24, - 212, 9, 24, 190, 173, 125, 90, 145, 68, 84, 92, 81, 6, 36, 31, 242, 210, 44, 143, 201, 16, 185, 245, 58, 63, - 148, 28, 21, 13, 91, 216, 129, 5, 210, 202, 78, 207, 126, 215, 173, 69, 69, 242, 123, 161, 167, 17, 155, 240, - 95, 111, 40, 71, 13, 86, 29, 70, 102, 162, 246, 1, 235, 159, 78, 177, 213, 101, 46, 169, 239, 167, 245, 65, - 118, 2, 55, 39, 89, 155, 43, 14, 133, 211, 188, 118, 181, 212, 181, 210, 55, 61, 1, 118, 179, 188, 147, 207, - 55, 27, 97, 47, 1, 115, 12, 151, 122, 134, 57, 27, 70, 29, 141, 144, 152, 138, 245, 203, 171, 84, 57, 152, 14, - 153, 178, 126, 134, 114, 150, 175, 149, 33, 105, 254, 215, 5, 199, 35, 53, 64, 155, 251, 252, 236, 103, 217, - 146, 142, 142, 145, 239, 86, 69, 100, 94, 122, 50, 133, 26, 166, 134, 80, 132, 123, 36, 24, 175, 240, 237, 51, - 123, 144, 238, 182, 230, 32, 33, 191, 151, 112, 18, 12, 7, 152, 206, 199, 52, 8, 219, 156, 98, 46, 82, 39, - 244, 191, 45, 154, 192, 193, 47, 12, 109, 92, 168, 249, 163, 18, 125, 201, 87, 149, 147, 49, 150, 45, 226, 29, - 101, 80, 199, 47, 85, 67, 222, 202, 28, 108, 166, 5, 99, 220, 201, 52, 51, 170, 140, 246, 255, 36, 43, 162, - 73, 77, 96, 0, 22, 183, 183, 56, 175, 120, 57, 94, 73, 194, 245, 124, 58, 248, 243, 255, 184, 183, 77, 59, 8, - 51, 238, 86, 200, 51, 238, 45, 30, 222, 134, 97, 159, 104, 34, 186, 38, 112, 215, 5, 142, 147, 96, 79, 199, - 152, 14, 85, 249, 26, 119, 28, 9, - ]), - ], - rangeProofAmountDiff: [ - new Uint8Array([ - 64, 135, 131, 140, 183, 31, 22, 14, 3, 196, 86, 236, 199, 94, 87, 78, 127, 28, 114, 170, 56, 250, 109, 82, - 105, 166, 140, 134, 105, 234, 100, 127, 192, 45, 217, 25, 102, 41, 228, 116, 88, 178, 247, 215, 179, 170, 233, - 252, 77, 241, 80, 39, 29, 159, 139, 37, 187, 177, 11, 189, 7, 112, 120, 81, 224, 83, 212, 166, 248, 62, 17, - 172, 143, 221, 110, 211, 126, 135, 114, 25, 218, 195, 70, 163, 29, 137, 72, 149, 224, 210, 53, 23, 62, 11, - 245, 56, 138, 49, 9, 60, 137, 37, 172, 110, 154, 8, 51, 145, 72, 242, 12, 36, 16, 156, 221, 61, 245, 41, 55, - 53, 5, 96, 146, 233, 232, 119, 116, 41, 137, 109, 70, 44, 183, 198, 193, 122, 209, 148, 51, 246, 240, 30, 59, - 11, 67, 176, 156, 129, 15, 147, 243, 194, 143, 166, 248, 111, 143, 225, 10, 11, 141, 240, 173, 204, 88, 119, - 184, 113, 91, 144, 149, 131, 38, 60, 41, 17, 105, 115, 44, 66, 220, 191, 36, 144, 200, 162, 246, 17, 22, 240, - 19, 8, 56, 63, 61, 217, 204, 62, 195, 108, 170, 128, 33, 150, 15, 249, 198, 195, 255, 114, 187, 167, 216, 211, - 244, 176, 186, 26, 0, 16, 96, 164, 97, 13, 236, 182, 169, 39, 121, 166, 162, 196, 34, 27, 183, 143, 84, 47, - 144, 17, 55, 133, 234, 124, 155, 131, 164, 253, 71, 123, 3, 216, 153, 65, 15, 35, 248, 227, 188, 196, 111, 46, - 215, 193, 163, 102, 152, 103, 75, 239, 148, 253, 115, 211, 144, 237, 89, 193, 205, 103, 158, 226, 187, 147, - 163, 218, 102, 39, 152, 131, 110, 228, 93, 68, 226, 27, 74, 184, 7, 206, 227, 143, 252, 55, 109, 8, 192, 169, - 135, 151, 107, 26, 26, 124, 121, 20, 241, 67, 250, 100, 22, 188, 7, 20, 73, 6, 32, 255, 107, 213, 245, 210, - 128, 37, 215, 147, 41, 52, 188, 192, 145, 52, 86, 215, 23, 141, 155, 109, 161, 99, 96, 117, 234, 23, 209, 144, - 178, 41, 37, 144, 11, 24, 203, 203, 252, 246, 160, 174, 239, 242, 21, 112, 182, 4, 84, 109, 0, 102, 109, 93, - 98, 104, 123, 76, 170, 185, 145, 250, 126, 82, 62, 166, 216, 254, 77, 212, 0, 126, 22, 181, 134, 112, 13, 229, - 107, 86, 59, 61, 221, 254, 35, 37, 193, 205, 132, 27, 238, 251, 221, 37, 96, 41, 78, 187, 170, 71, 8, 175, 70, - 183, 179, 112, 111, 29, 0, 157, 232, 35, 162, 53, 11, 99, 83, 216, 166, 90, 138, 31, 208, 109, 59, 137, 65, - 22, 160, 41, 13, 145, 75, 86, 224, 139, 41, 127, 85, 243, 137, 226, 197, 179, 10, 93, 21, 209, 22, 81, 63, - 182, 43, 121, 90, 210, 83, 13, 199, 31, 69, 144, 183, 31, 135, 165, 3, 181, 113, 196, 172, 139, 219, 69, 227, - 20, 85, 229, 105, 71, 243, 32, 235, 134, 12, 31, 74, 141, 205, 81, 143, 129, 119, 19, 198, 198, 63, 242, 75, - 200, 42, 170, 244, 83, 240, 233, 253, 57, 141, 166, 150, 127, 0, 49, 4, 202, 202, 34, 48, 239, 41, 155, 255, - 197, 103, 105, 160, 70, 133, 184, 56, 51, 191, 103, 72, 155, 20, 161, 119, 78, 251, 173, 87, 98, 71, 148, 156, - 83, 209, 3, 63, 84, 36, 218, 111, 135, 89, 54, 100, 163, 12, 213, 156, 75, 83, 67, 86, 13, 232, 192, 254, 130, - 217, 226, 102, 198, 201, 203, 36, 125, 91, 3, - ]), - new Uint8Array([ - 2, 239, 154, 72, 98, 105, 52, 76, 182, 234, 87, 14, 172, 210, 166, 110, 133, 217, 78, 90, 4, 23, 218, 208, - 182, 254, 202, 6, 2, 82, 251, 83, 124, 11, 108, 93, 161, 38, 37, 56, 83, 166, 33, 81, 11, 184, 18, 30, 187, - 157, 134, 244, 96, 25, 123, 164, 68, 52, 104, 49, 213, 142, 197, 82, 156, 205, 252, 57, 124, 101, 156, 148, - 107, 37, 163, 140, 241, 53, 144, 34, 253, 120, 40, 89, 239, 239, 184, 19, 6, 91, 252, 57, 255, 84, 208, 112, - 4, 170, 117, 125, 146, 203, 62, 168, 222, 152, 14, 205, 221, 170, 35, 63, 99, 55, 94, 126, 101, 96, 204, 220, - 23, 66, 8, 223, 84, 93, 217, 54, 205, 9, 50, 249, 188, 156, 42, 45, 169, 216, 58, 232, 248, 222, 243, 239, - 156, 105, 205, 65, 88, 247, 105, 73, 104, 129, 32, 67, 50, 8, 42, 1, 150, 171, 62, 73, 115, 219, 2, 14, 239, - 166, 105, 186, 81, 99, 21, 68, 96, 251, 139, 174, 224, 143, 235, 177, 117, 222, 165, 235, 111, 152, 147, 3, - 192, 120, 27, 59, 41, 82, 225, 59, 220, 200, 119, 83, 7, 215, 163, 143, 188, 177, 36, 60, 29, 172, 92, 157, - 39, 98, 80, 173, 37, 126, 141, 3, 170, 193, 43, 194, 0, 30, 241, 95, 111, 161, 166, 230, 64, 167, 96, 64, 178, - 48, 196, 108, 194, 1, 151, 77, 220, 169, 120, 153, 208, 138, 192, 82, 230, 64, 132, 225, 234, 246, 206, 166, - 50, 99, 9, 234, 163, 11, 37, 180, 243, 186, 111, 190, 104, 152, 60, 82, 40, 178, 175, 234, 160, 76, 69, 35, - 90, 179, 212, 69, 64, 134, 140, 0, 192, 42, 201, 95, 59, 232, 177, 207, 128, 214, 149, 25, 67, 37, 93, 184, - 72, 11, 211, 33, 248, 186, 143, 97, 96, 15, 205, 188, 143, 23, 188, 191, 112, 25, 16, 156, 191, 62, 116, 51, - 25, 161, 233, 164, 191, 209, 90, 157, 253, 217, 172, 25, 1, 76, 239, 20, 44, 65, 15, 183, 142, 179, 73, 253, - 126, 240, 148, 213, 32, 110, 133, 231, 237, 253, 187, 155, 148, 167, 92, 44, 54, 218, 96, 220, 191, 228, 136, - 10, 252, 165, 24, 180, 6, 128, 111, 87, 26, 188, 112, 75, 3, 252, 21, 126, 170, 255, 92, 61, 152, 166, 236, - 112, 62, 46, 126, 113, 209, 60, 116, 90, 130, 180, 45, 29, 0, 183, 52, 44, 74, 134, 60, 202, 7, 227, 171, 175, - 152, 137, 194, 206, 9, 199, 240, 204, 120, 206, 154, 106, 21, 0, 94, 50, 58, 199, 246, 44, 3, 180, 93, 95, 83, - 125, 179, 77, 40, 131, 66, 73, 222, 29, 166, 82, 76, 128, 69, 141, 117, 101, 24, 141, 54, 58, 3, 14, 254, 208, - 63, 8, 22, 219, 207, 86, 57, 11, 31, 16, 164, 139, 48, 207, 33, 47, 210, 39, 84, 249, 157, 121, 127, 129, 240, - 68, 176, 41, 105, 118, 182, 223, 14, 115, 165, 171, 15, 49, 156, 197, 246, 56, 133, 80, 112, 84, 213, 242, - 251, 66, 169, 167, 69, 12, 175, 111, 244, 120, 172, 130, 244, 53, 242, 29, 15, 86, 221, 127, 175, 241, 204, - 233, 138, 212, 72, 47, 16, 63, 174, 82, 248, 29, 58, 115, 145, 252, 111, 89, 67, 15, 182, 201, 192, 14, 194, - 105, 239, 57, 46, 142, 149, 157, 90, 136, 230, 113, 227, 66, 5, 1, 242, 191, 14, 104, 142, 54, 30, 103, 128, - 71, 154, 51, 251, 197, 236, 10, - ]), - ], - }; - - const invalidAmount = VeiledAmount.fromAmount(5n); - invalidAmount.encrypt(bob.publicKey()); - - const isValid = await VeiledTransfer.verifyRangeProof({ - encryptedAmountByRecipient: invalidAmount.amountEncrypted!, - encryptedActualBalanceAfterTransfer: invoice.veiledAmountAfterTransfer.amountEncrypted!, - ...invalidRangeProof, - }); - - expect(isValid).toBeFalsy(); - }); -}); diff --git a/tests/unit/veiled/veiledProofs.test.ts b/tests/unit/veiled/veiledProofs.test.ts index 9bf2124a..3a5eff14 100644 --- a/tests/unit/veiled/veiledProofs.test.ts +++ b/tests/unit/veiled/veiledProofs.test.ts @@ -16,6 +16,7 @@ import { toTwistedEd25519PrivateKey } from "../../../src/core/crypto/veiled/help import { generateRangeZKP, verifyRangeZKP } from "./wasmRangeProof"; import { loadTableMapJSON } from "./helpers"; import { createKangaroo } from "./kangaroo/wasmPollardKangaroo"; +import { VeiledInvoice, VeiledInvoiceSigmaProof } from "../../../src/core/crypto/veiled/VeiledInvoice"; /** !important: for testing purposes */ RangeProofExecutor.setGenerateRangeZKP(generateRangeZKP); @@ -186,7 +187,7 @@ describe("Generate 'veiled coin' proofs", () => { // // ); test("Verify transfer sigma proof", () => { const isValid = VeiledTransfer.verifySigmaProof({ - senderPrivateKey: aliceVeiledDecryptionKey, + senderPublicKey: aliceVeiledDecryptionKey.publicKey(), recipientPublicKey: bobVeiledDecryptionKey.publicKey(), encryptedActualBalance: aliceVeiledAmount.amountEncrypted!, encryptedActualBalanceAfterTransfer: veiledTransfer.veiledAmountAfterTransfer?.amountEncrypted!, @@ -233,7 +234,7 @@ describe("Generate 'veiled coin' proofs", () => { }); test("Verify transfer with auditors sigma proof", () => { const isValid = VeiledTransfer.verifySigmaProof({ - senderPrivateKey: aliceVeiledDecryptionKey, + senderPublicKey: aliceVeiledDecryptionKey.publicKey(), recipientPublicKey: bobVeiledDecryptionKey.publicKey(), encryptedActualBalance: aliceVeiledAmount.amountEncrypted!, encryptedActualBalanceAfterTransfer: veiledTransferWithAuditors.veiledAmountAfterTransfer!.amountEncrypted!, @@ -257,7 +258,7 @@ describe("Generate 'veiled coin' proofs", () => { // }); const isValid = VeiledTransfer.verifySigmaProof({ - senderPrivateKey: aliceVeiledDecryptionKey, + senderPublicKey: aliceVeiledDecryptionKey.publicKey(), recipientPublicKey: bobVeiledDecryptionKey.publicKey(), encryptedActualBalance: aliceVeiledAmount.amountEncrypted!, encryptedActualBalanceAfterTransfer: veiledTransferWithAuditors.veiledAmountAfterTransfer!.amountEncrypted!, @@ -292,6 +293,92 @@ describe("Generate 'veiled coin' proofs", () => { expect(isValid).toBeTruthy(); }); + const INVOICE_AMOUNT = 5n; + const newBobDecryptionKey = TwistedEd25519PrivateKey.generate(); + let veiledInvoice: VeiledInvoice; + test("Bob Generates an invoice", async () => { + veiledInvoice = await VeiledInvoice.create({ + creatorDecryptionKey: newBobDecryptionKey, + payerPublicKey: aliceVeiledDecryptionKey.publicKey(), + invoiceValueAmount: INVOICE_AMOUNT, + }); + + expect(veiledInvoice).toBeDefined(); + }); + + let invoiceSigmaProof: VeiledInvoiceSigmaProof; + test("Generate invoice sigma proof", async () => { + invoiceSigmaProof = await veiledInvoice.genSigmaProof(); + + expect(invoiceSigmaProof).toBeDefined(); + }); + + test("Verify invoice sigma proof", async () => { + const isSigmaProofValid = VeiledInvoice.verifySigmaProof({ + payerPublicKey: aliceVeiledDecryptionKey.publicKey(), + encryptedInvoiceAmount: veiledInvoice.veiledInvoiceValue.amountEncrypted!, + sigmaProof: invoiceSigmaProof, + }); + + expect(isSigmaProofValid).toBeTruthy(); + }); + + let invoiceRangeProof: Uint8Array[]; + test("Generate invoice range proof", async () => { + invoiceRangeProof = await veiledInvoice.genRangeProof(); + + expect(invoiceRangeProof).toBeDefined(); + }); + + test("Verify invoice range proof", async () => { + const isRangeProofValid = VeiledInvoice.verifyRangeProof({ + encryptedInvoiceAmount: veiledInvoice.veiledInvoiceValue.amountEncrypted!, + rangeProof: invoiceRangeProof, + }); + + expect(isRangeProofValid).toBeTruthy(); + }); + + let invoicePayment: VeiledTransfer; + test("Generate invoice payment", async () => { + invoicePayment = await VeiledTransfer.create({ + senderDecryptionKey: aliceVeiledDecryptionKey, + encryptedActualBalance: aliceVeiledAmount.amountEncrypted!, + amountToTransfer: INVOICE_AMOUNT, + recipientEncryptionKey: newBobDecryptionKey.publicKey(), + + veiledInvoiceAmount: veiledInvoice.veiledInvoiceValue.amountEncrypted!, + }); + + expect(invoicePayment).toBeDefined(); + }); + + test("Generate and verify invoice payment proofs", async () => { + const [{ sigmaProof, rangeProof }, encryptedAmountAfterTransfer, encryptedAmountByRecipient] = + await invoicePayment.authorizeTransfer(); + + const isSigmaProofValid = VeiledTransfer.verifySigmaProof({ + senderPublicKey: aliceVeiledDecryptionKey.publicKey(), + recipientPublicKey: newBobDecryptionKey.publicKey(), + encryptedActualBalance: aliceVeiledAmount.amountEncrypted!, + encryptedActualBalanceAfterTransfer: encryptedAmountAfterTransfer, + encryptedTransferAmountByRecipient: encryptedAmountByRecipient, + + encryptedInvoiceAmount: veiledInvoice.veiledInvoiceValue.amountEncrypted!, + sigmaProof, + }); + + const isRangeProofValid = await VeiledTransfer.verifyRangeProof({ + encryptedAmountByRecipient, + encryptedActualBalanceAfterTransfer: encryptedAmountAfterTransfer, + rangeProofAmount: rangeProof.rangeProofAmount, + rangeProofNewBalance: rangeProof.rangeProofNewBalance, + }); + + expect(isSigmaProofValid).toBeTruthy(); + expect(isRangeProofValid).toBeTruthy(); + }); + const newAliceVeiledPrivateKey = TwistedEd25519PrivateKey.generate(); let veiledKeyRotation: VeiledKeyRotation; let veiledKeyRotationSigmaProof: VeiledKeyRotationSigmaProof;