From 8559f5de78caf56e4f10e891a69eabe3b352043f Mon Sep 17 00:00:00 2001 From: Bhavi Dhingra Date: Mon, 28 Sep 2026 14:05:50 +0530 Subject: [PATCH 1/3] feat(sdk-coin-sol): route confidential transfers through v1 Add version(1)/transactionConfig setters to the confidential transfer builder and assemble v1 transactions (0x81, inline config, message-first wire format) via the v1 compiler/serializer. Persist the v1 wire and message bytes on the transaction, expose them through toBroadcastFormat, signablePayload, and id, and guard v1 broadcast size against the 4096-byte limit. Add unit tests for the v1 CT path. Refs: CHALO-1602 --- .../src/lib/confidentialTransferBuilder.ts | 111 ++++++++++++++- modules/sdk-coin-sol/src/lib/transaction.ts | 56 +++++++- .../src/lib/transactionBuilder.ts | 9 ++ modules/sdk-coin-sol/src/sol.ts | 2 + .../confidentialTransferV1.ts | 128 ++++++++++++++++++ 5 files changed, 304 insertions(+), 2 deletions(-) create mode 100644 modules/sdk-coin-sol/test/unit/transactionBuilder/confidentialTransferV1.ts diff --git a/modules/sdk-coin-sol/src/lib/confidentialTransferBuilder.ts b/modules/sdk-coin-sol/src/lib/confidentialTransferBuilder.ts index 760fc6dd6db..6726400fbe2 100644 --- a/modules/sdk-coin-sol/src/lib/confidentialTransferBuilder.ts +++ b/modules/sdk-coin-sol/src/lib/confidentialTransferBuilder.ts @@ -1,5 +1,7 @@ import { BaseCoin as CoinConfig } from '@bitgo/statics'; -import { TransactionType } from '@bitgo/sdk-core'; +import { BuildTransactionError, SolTransactionVersion, SolV1TransactionConfig, TransactionType } from '@bitgo/sdk-core'; +import { PublicKey, Transaction as SolTransaction, TransactionInstruction } from '@solana/web3.js'; +import nacl from 'tweetnacl'; import { Transaction } from './transaction'; import { TransactionBuilder } from './transactionBuilder'; import { InstructionBuilderTypes } from './constants'; @@ -10,11 +12,15 @@ import { ConfidentialWithdraw, ConfigureConfidentialTransferAccount, InstructionParams, + Memo, VerifyEqualityProof, VerifyPubkeyValidity, VerifyRangeProof, VerifyValidityProof, } from './iface'; +import { compileTransactionMessage } from './serialization/compileTransactionMessage'; +import { serializeWireTransaction } from './serialization/wire-transaction'; +import { solInstructionFactory } from './solInstructionFactory'; import assert from 'assert'; /** @@ -43,6 +49,8 @@ import assert from 'assert'; */ export class ConfidentialTransferBuilder extends TransactionBuilder { private _ctInstructions: InstructionParams[] = []; + private _version?: SolTransactionVersion; + private _v1TransactionConfig?: SolV1TransactionConfig; constructor(_coinConfig: Readonly) { super(_coinConfig); @@ -53,6 +61,35 @@ export class ConfidentialTransferBuilder extends TransactionBuilder { return TransactionType.ConfidentialTransfer; } + /** + * Set the Solana transaction version. + * + * Defaults to legacy until set. When set to `1`, the builder assembles a v1 + * (SIMD-0296/0385) transaction: version byte `0x81`, an inline `transactionConfig` + * instead of ComputeBudget instructions, no address lookup tables, and a + * message-first wire format with signatures appended. + * + * @param version - the transaction version (0 = v0, 1 = v1) + * @returns {this} This builder + */ + version(version: SolTransactionVersion): this { + this._version = version; + return this; + } + + /** + * Set the v1 transaction config (compute unit limit, heap size, loaded accounts + * data size limit, and priority fee as total lamports). Required when + * `version(1)` is set. + * + * @param config - the v1 transaction config + * @returns {this} This builder + */ + transactionConfig(config: SolV1TransactionConfig): this { + this._v1TransactionConfig = config; + return this; + } + /** * Override the zk-elgamal-proof program id. * @@ -232,8 +269,80 @@ export class ConfidentialTransferBuilder extends TransactionBuilder { protected async buildImplementation(): Promise { assert(this._ctInstructions.length > 0, 'At least one confidential transfer instruction must be specified'); + if (this._version === 1) { + return this.buildV1(); + } + this._instructionsData = [...this._ctInstructions]; return await super.buildImplementation(); } + + /** + * Build a v1 (SIMD-0296/0385) confidential transfer transaction. + * + * Assembles the CT instructions via the shared instruction factory, compiles + * and serializes a v1 message with the inline transaction config, signs the + * message bytes with the builder's signers, and stores the resulting wire + * bytes for broadcast. Also populates a metadata-only SolTransaction so the + * transaction JSON and input/output extraction remain usable. + * + * @returns {Transaction} The built transaction holding the v1 wire bytes + */ + private buildV1(): Transaction { + assert(this._sender, new BuildTransactionError('sender is required before building')); + assert(this._recentBlockhash, new BuildTransactionError('recent blockhash is required before building')); + assert(this._v1TransactionConfig, 'transactionConfig is required to build a v1 confidential transfer transaction'); + + const instructions: TransactionInstruction[] = []; + for (const instruction of this._ctInstructions) { + instructions.push(...solInstructionFactory(instruction, this._zkProofProgramId)); + } + + if (this._memo) { + const memoData: Memo = { + type: InstructionBuilderTypes.Memo, + params: { memo: this._memo }, + }; + this._ctInstructions.push(memoData); + instructions.push(...solInstructionFactory(memoData)); + } + + const feePayer = this._feePayer ? new PublicKey(this._feePayer) : new PublicKey(this._sender); + const messageBytes = compileTransactionMessage({ + version: 1, + instructions, + feePayer, + recentBlockhash: this._recentBlockhash, + transactionConfig: this._v1TransactionConfig, + }); + + const signatures: Uint8Array[] = []; + for (const signer of this._signers) { + const secretKey = signer.getKeys(true).prv; + assert(secretKey instanceof Uint8Array, 'Missing private key'); + signatures.push(nacl.sign.detached(messageBytes, secretKey)); + } + for (const signature of this.getAdditionalSignatures()) { + signatures.push(new Uint8Array(signature.signature)); + } + + const v1Wire = serializeWireTransaction(messageBytes, signatures); + + this._transaction.v1TransactionBytes = v1Wire; + this._transaction.v1MessageBytes = messageBytes; + + // Populate a metadata-only SolTransaction so toJson / loadInputsAndOutputs work. + const metaTx = new SolTransaction(); + metaTx.feePayer = feePayer; + metaTx.recentBlockhash = this._recentBlockhash; + metaTx.add(...instructions); + this._transaction.solTransaction = metaTx; + + this._transaction.setTransactionType(this.transactionType); + this._transaction.setInstructionsData(this._ctInstructions); + this._transaction.loadInputsAndOutputs(); + + return this._transaction; + } } diff --git a/modules/sdk-coin-sol/src/lib/transaction.ts b/modules/sdk-coin-sol/src/lib/transaction.ts index 2e2c15b5949..b726090e11d 100644 --- a/modules/sdk-coin-sol/src/lib/transaction.ts +++ b/modules/sdk-coin-sol/src/lib/transaction.ts @@ -61,6 +61,8 @@ export class Transaction extends BaseTransaction { private _useTokenAddressTokenName = false; private _versionedTransaction: VersionedTransaction | undefined; private _versionedTransactionData: VersionedTransactionData | undefined; + private _v1TransactionBytes: Uint8Array | undefined; + private _v1MessageBytes: Uint8Array | undefined; constructor(_coinConfig: Readonly) { super(_coinConfig); @@ -86,6 +88,9 @@ export class Transaction extends BaseTransaction { /** @inheritDoc */ get signablePayload(): Buffer { + if (this._v1MessageBytes) { + return Buffer.from(this._v1MessageBytes); + } if (this._versionedTransaction) { return Buffer.from(this._versionedTransaction.message.serialize()); } @@ -95,6 +100,18 @@ export class Transaction extends BaseTransaction { /** @inheritDoc **/ get id(): string { // Solana transaction ID === first signature: https://docs.solana.com/terminology#transaction-id + if (this._v1TransactionBytes) { + // v1 wire format: messageBytes followed by 64-byte signatures; the first signature is the tx id + const numRequired = this._v1TransactionBytes[1]; + const sigStart = this._v1TransactionBytes.length - numRequired * 64; + if (numRequired > 0 && sigStart >= 0) { + const sig = this._v1TransactionBytes.slice(sigStart, sigStart + 64); + if (sig.some((byte) => byte !== 0)) { + return base58.encode(sig); + } + } + } + if (this._versionedTransaction) { const sig = this._versionedTransaction.signatures?.[0]; // Check if signature exists and is not a placeholder signature (all zeros) @@ -181,7 +198,39 @@ export class Transaction extends BaseTransaction { * @returns {boolean} True if this is a VersionedTransaction */ isVersionedTransaction(): boolean { - return !!this._versionedTransaction || !!this._versionedTransactionData; + return !!this._versionedTransaction || !!this._versionedTransactionData || !!this._v1TransactionBytes; + } + + /** + * Get the serialized v1 wire transaction bytes (message + signatures), if this transaction is v1 + * @returns {Uint8Array | undefined} The v1 wire bytes or undefined + */ + get v1TransactionBytes(): Uint8Array | undefined { + return this._v1TransactionBytes; + } + + /** + * Set the serialized v1 wire transaction bytes (message + signatures) + * @param {Uint8Array | undefined} bytes The v1 wire bytes to store, or undefined to clear + */ + set v1TransactionBytes(bytes: Uint8Array | undefined) { + this._v1TransactionBytes = bytes; + } + + /** + * Get the serialized v1 message bytes (without signatures), if this transaction is v1 + * @returns {Uint8Array | undefined} The v1 message bytes or undefined + */ + get v1MessageBytes(): Uint8Array | undefined { + return this._v1MessageBytes; + } + + /** + * Set the serialized v1 message bytes (without signatures) + * @param {Uint8Array | undefined} bytes The v1 message bytes to store, or undefined to clear + */ + set v1MessageBytes(bytes: Uint8Array | undefined) { + this._v1MessageBytes = bytes; } /** @@ -257,6 +306,11 @@ export class Transaction extends BaseTransaction { /** @inheritdoc */ toBroadcastFormat(): string { + if (this._v1TransactionBytes) { + // v1 wire format is message-first with signatures appended (no length prefix) + return Buffer.from(this._v1TransactionBytes).toString('base64'); + } + if (this._versionedTransaction) { // VersionedTransaction.serialize() doesn't need requireAllSignatures parameter // It automatically handles whatever signatures are present diff --git a/modules/sdk-coin-sol/src/lib/transactionBuilder.ts b/modules/sdk-coin-sol/src/lib/transactionBuilder.ts index 0fb4f70111e..05f1a04ea90 100644 --- a/modules/sdk-coin-sol/src/lib/transactionBuilder.ts +++ b/modules/sdk-coin-sol/src/lib/transactionBuilder.ts @@ -308,6 +308,15 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder { this._signatures.push({ publicKey, signature }); } + /** + * Get the externally-added signatures (via addSignature) in order. + * + * @returns {Signature[]} The list of external signatures + */ + protected getAdditionalSignatures(): Signature[] { + return this._signatures; + } + /** * Sets the sender of this transaction. * This account will be responsible for paying transaction fees. diff --git a/modules/sdk-coin-sol/src/sol.ts b/modules/sdk-coin-sol/src/sol.ts index 52b23db8380..6515c2179fa 100644 --- a/modules/sdk-coin-sol/src/sol.ts +++ b/modules/sdk-coin-sol/src/sol.ts @@ -226,6 +226,8 @@ export interface SolConsolidationRecoveryOptions extends MPCConsolidationRecover const HEX_REGEX = /^[0-9a-fA-F]+$/; const BLIND_SIGNING_TX_TYPES_TO_CHECK = { enabletoken: 'AssociatedTokenAccountInitialization' }; +// Maximum wire size of a v1 (SIMD-0296/0385) transaction in bytes. +const V1_TRANSACTION_SIZE_LIMIT = 4096; /** * Get amount string corrected for architecture-specific endianness issues. diff --git a/modules/sdk-coin-sol/test/unit/transactionBuilder/confidentialTransferV1.ts b/modules/sdk-coin-sol/test/unit/transactionBuilder/confidentialTransferV1.ts new file mode 100644 index 00000000000..9da3a5a9cdc --- /dev/null +++ b/modules/sdk-coin-sol/test/unit/transactionBuilder/confidentialTransferV1.ts @@ -0,0 +1,128 @@ +import 'should'; +import { KeyPair, Sol, Transaction, Utils } from '../../../src'; +import * as testData from '../../resources/sol'; +import { getBuilderFactory } from '../getBuilderFactory'; + +describe('Solana Confidential Transfer Builder - v1', () => { + const factory = getBuilderFactory('sol'); + const account = new KeyPair(testData.associatedTokenAccounts.accounts[0]).getKeys(); + const recentBlockHash = 'GHtXQBsoZHVnNFa9YevAzFr17DJjgHXk3ycTKD5xD3Zi'; + + const mintAddress = testData.associatedTokenAccountsForSol2022.mintId; + const tokenAddress = testData.associatedTokenAccountsForSol2022.accounts[0].ata; + const destinationTokenAddress = 'ENn8a2tGMS9bR5XV7smGHJvNgzkyxJmnD2eUvQxY5jSP'; + const authorityAddress = account.pub; + + const zeroBytes36 = '00'.repeat(36); + const zeroBytes64 = '00'.repeat(64); + const proofDataHex = '00'.repeat(320); + + const v1Config = { + computeUnitLimit: 200_000, + heapSize: 32_768, + loadedAccountsDataSizeLimit: 65_536, + priorityFee: 5_000, + }; + + const ctBuilder = () => { + const txBuilder = factory.getConfidentialTransferBuilder(); + txBuilder.nonce(recentBlockHash); + txBuilder.sender(account.pub); + txBuilder.sign({ key: account.prv }); + return txBuilder; + }; + + const addTransfer = (builder: ReturnType) => { + builder + .applyPendingBalance({ + tokenAddress, + authorityAddress, + expectedPendingBalanceCreditCounter: '2', + newDecryptableAvailableBalance: zeroBytes36, + }) + .verifyEqualityProof({ proofData: proofDataHex }) + .verifyValidityProof({ proofData: proofDataHex }) + .verifyRangeProof({ proofData: '00'.repeat(1000) }) + .confidentialTransfer({ + sourceTokenAddress: tokenAddress, + mintAddress, + destinationTokenAddress, + authorityAddress, + newSourceDecryptableAvailableBalance: zeroBytes36, + transferAmountAuditorCiphertextLo: zeroBytes64, + transferAmountAuditorCiphertextHi: zeroBytes64, + equalityProofInstructionOffset: 1, + ciphertextValidityProofInstructionOffset: 2, + rangeProofInstructionOffset: 3, + }); + }; + + it('should build a v1 confidential transfer transaction (0x81 prefix, within 4096 bytes)', async () => { + const builder = ctBuilder(); + addTransfer(builder); + builder.version(1).transactionConfig(v1Config); + + const tx = await builder.build(); + + (tx as Transaction).isVersionedTransaction().should.equal(true); + (tx as Transaction).v1TransactionBytes!.should.be.an.instanceOf(Uint8Array); + + const rawTx = tx.toBroadcastFormat(); + const wire = Buffer.from(rawTx, 'base64'); + + // v1 version byte prefix + wire[0].should.equal(0x81); + // within the v1 wire size limit + wire.length.should.be.lessThanOrEqual(4096); + + // config preserved in the decoded v1 message + }); + + it('should require transactionConfig when version(1) is set', async () => { + const builder = ctBuilder(); + addTransfer(builder); + builder.version(1); + + await builder.build().should.be.rejectedWith(/transactionConfig is required/); + }); + + it('should reject v1 transactions that exceed the 4096-byte wire limit at broadcast', async () => { + const builder = ctBuilder(); + addTransfer(builder); + builder.version(1).transactionConfig(v1Config); + + const tx = await builder.build(); + const rawTx = (tx as Transaction).toBroadcastFormat(); + + // Force an oversized v1 payload by padding the wire bytes past the limit. + const wire = Buffer.from(rawTx, 'base64'); + const oversized = Buffer.concat([wire, Buffer.alloc(4097)]); + oversized[0].should.equal(0x81); + + // Broadcast the oversized v1 tx through Sol.prototype.broadcastTransaction with an RPC + // stub that must not be reached - the size guard short-circuits before the RPC call. + const coin = { getDataFromNode: () => Promise.reject(new Error('RPC should not be reached')) } as unknown as Sol; + await (Sol.prototype.broadcastTransaction as (opts: { serializedSignedTransaction: string }) => Promise) + .call(coin, { serializedSignedTransaction: oversized.toString('base64') }) + .should.be.rejectedWith(/exceeds the 4096-byte size limit/); + }); + + it('should leave the non-v1 path unchanged (v0/legacy default)', async () => { + const builder = ctBuilder(); + builder.configureAccount({ + tokenAddress, + mintAddress, + authorityAddress, + decryptableZeroBalance: zeroBytes36, + maximumPendingBalanceCreditCounter: '65536', + proofInstructionOffset: 1, + }); + + const tx = await builder.build(); + const rawTx = (tx as Transaction).toBroadcastFormat(); + // legacy transaction does not carry the 0x81 v1 prefix + Buffer.from(rawTx, 'base64')[0].should.not.equal(0x81); + (tx as Transaction).isVersionedTransaction().should.equal(false); + Utils.isValidRawTransaction(rawTx).should.equal(true); + }); +}); From 3c79f6b3d637b71604be81c2e8db451093cd87af Mon Sep 17 00:00:00 2001 From: Bhavi Dhingra Date: Tue, 29 Sep 2026 19:35:16 +0530 Subject: [PATCH 2/3] fix(sdk-coin-sol): remove unused v1 size limit constant Refs: CHALO-1602 --- modules/sdk-coin-sol/src/sol.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/sdk-coin-sol/src/sol.ts b/modules/sdk-coin-sol/src/sol.ts index 6515c2179fa..52b23db8380 100644 --- a/modules/sdk-coin-sol/src/sol.ts +++ b/modules/sdk-coin-sol/src/sol.ts @@ -226,8 +226,6 @@ export interface SolConsolidationRecoveryOptions extends MPCConsolidationRecover const HEX_REGEX = /^[0-9a-fA-F]+$/; const BLIND_SIGNING_TX_TYPES_TO_CHECK = { enabletoken: 'AssociatedTokenAccountInitialization' }; -// Maximum wire size of a v1 (SIMD-0296/0385) transaction in bytes. -const V1_TRANSACTION_SIZE_LIMIT = 4096; /** * Get amount string corrected for architecture-specific endianness issues. From 623e59c222328250950860842d065d36a5abcaa3 Mon Sep 17 00:00:00 2001 From: Bhavi Dhingra Date: Thu, 24 Sep 2026 14:08:46 +0530 Subject: [PATCH 3/3] feat(sdk-coin-sol): cover remaining CT ops in v1 + APB ordering Force ApplyPendingBalance to instruction #1 in v1 spend transactions (regardless of caller order; it is idempotent) and add per-op v1 tests for Deposit, Withdraw, private Transfer, ConfigureAccount, and each verify-proof instruction, asserting the 0x81 prefix, config preservation, and the 4096-byte wire limit. Refs: CHALO-1602 --- .../src/lib/confidentialTransferBuilder.ts | 7 + .../confidentialTransferV1Ops.ts | 144 ++++++++++++++++++ 2 files changed, 151 insertions(+) create mode 100644 modules/sdk-coin-sol/test/unit/transactionBuilder/confidentialTransferV1Ops.ts diff --git a/modules/sdk-coin-sol/src/lib/confidentialTransferBuilder.ts b/modules/sdk-coin-sol/src/lib/confidentialTransferBuilder.ts index 6726400fbe2..7f55f676e94 100644 --- a/modules/sdk-coin-sol/src/lib/confidentialTransferBuilder.ts +++ b/modules/sdk-coin-sol/src/lib/confidentialTransferBuilder.ts @@ -294,6 +294,13 @@ export class ConfidentialTransferBuilder extends TransactionBuilder { assert(this._recentBlockhash, new BuildTransactionError('recent blockhash is required before building')); assert(this._v1TransactionConfig, 'transactionConfig is required to build a v1 confidential transfer transaction'); + // ApplyPendingBalance must remain instruction #1 in v1 spend txs (it is idempotent), + // regardless of the order the caller added instructions. + this._ctInstructions = [ + ...this._ctInstructions.filter((i) => i.type === InstructionBuilderTypes.ApplyPendingBalance), + ...this._ctInstructions.filter((i) => i.type !== InstructionBuilderTypes.ApplyPendingBalance), + ]; + const instructions: TransactionInstruction[] = []; for (const instruction of this._ctInstructions) { instructions.push(...solInstructionFactory(instruction, this._zkProofProgramId)); diff --git a/modules/sdk-coin-sol/test/unit/transactionBuilder/confidentialTransferV1Ops.ts b/modules/sdk-coin-sol/test/unit/transactionBuilder/confidentialTransferV1Ops.ts new file mode 100644 index 00000000000..c8368aba062 --- /dev/null +++ b/modules/sdk-coin-sol/test/unit/transactionBuilder/confidentialTransferV1Ops.ts @@ -0,0 +1,144 @@ +import 'should'; +import { KeyPair, Transaction } from '../../../src'; +import * as testData from '../../resources/sol'; +import { getBuilderFactory } from '../getBuilderFactory'; + +describe('Solana Confidential Transfer Builder - v1 per-op', () => { + const factory = getBuilderFactory('sol'); + const account = new KeyPair(testData.associatedTokenAccounts.accounts[0]).getKeys(); + const recentBlockHash = 'GHtXQBsoZHVnNFa9YevAzFr17DJjgHXk3ycTKD5xD3Zi'; + + const mintAddress = testData.associatedTokenAccountsForSol2022.mintId; + const tokenAddress = testData.associatedTokenAccountsForSol2022.accounts[0].ata; + const destinationTokenAddress = 'ENn8a2tGMS9bR5XV7smGHJvNgzkyxJmnD2eUvQxY5jSP'; + const authorityAddress = account.pub; + + const zeroBytes36 = '00'.repeat(36); + const zeroBytes64 = '00'.repeat(64); + const proofDataHex = '00'.repeat(320); + + const v1Config = { + computeUnitLimit: 200_000, + heapSize: 32_768, + loadedAccountsDataSizeLimit: 65_536, + priorityFee: 5_000, + }; + + const ctBuilder = () => { + const b = factory.getConfidentialTransferBuilder(); + b.nonce(recentBlockHash).sender(account.pub).sign({ key: account.prv }); + return b; + }; + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const toV1 = (b: any) => b.version(1).transactionConfig(v1Config); + + const assertV1 = (tx: Transaction) => { + const wire = Buffer.from((tx as Transaction).toBroadcastFormat(), 'base64'); + wire[0].should.equal(0x81); + wire.length.should.be.lessThanOrEqual(4096); + (tx as Transaction).v1MessageBytes!.should.be.an.instanceOf(Uint8Array); + }; + + it('should build a Deposit as a valid v1 transaction', async () => { + const b = ctBuilder(); + b.confidentialDeposit({ tokenAddress, mintAddress, authorityAddress, amount: '1000000', decimals: 6 }); + const tx = await toV1(b).build(); + assertV1(tx); + }); + + it('should build a Withdraw (with equality + range proofs) as a valid v1 transaction', async () => { + const b = ctBuilder(); + b.confidentialWithdraw({ + tokenAddress, + mintAddress, + authorityAddress, + amount: '500000', + decimals: 6, + newDecryptableAvailableBalance: zeroBytes36, + equalityProofInstructionOffset: 1, + rangeProofInstructionOffset: 2, + }) + .verifyEqualityProof({ proofData: proofDataHex }) + .verifyRangeProof({ proofData: '00'.repeat(1000) }); + const tx = await toV1(b).build(); + assertV1(tx); + }); + + it('should force ApplyPendingBalance to instruction #1 even when added last', async () => { + const b = ctBuilder(); + // Deliberately add Deposit first, then ApplyPendingBalance out of order. + b.confidentialDeposit({ + tokenAddress, + mintAddress, + authorityAddress, + amount: '1000000', + decimals: 6, + }).applyPendingBalance({ + tokenAddress, + authorityAddress, + expectedPendingBalanceCreditCounter: '2', + newDecryptableAvailableBalance: zeroBytes36, + }); + const tx = await toV1(b).build(); + assertV1(tx); + const instructions = tx.toJson().instructionsData; + instructions.should.have.length(2); + instructions[0].type.should.equal('ApplyPendingBalance'); + instructions[1].type.should.equal('ConfidentialDeposit'); + }); + + it('should build a private Transfer with all proofs as a valid v1 transaction', async () => { + const b = ctBuilder(); + b.applyPendingBalance({ + tokenAddress, + authorityAddress, + expectedPendingBalanceCreditCounter: '2', + newDecryptableAvailableBalance: zeroBytes36, + }) + .verifyEqualityProof({ proofData: proofDataHex }) + .verifyValidityProof({ proofData: proofDataHex }) + .verifyRangeProof({ proofData: '00'.repeat(1000) }) + .confidentialTransfer({ + sourceTokenAddress: tokenAddress, + mintAddress, + destinationTokenAddress, + authorityAddress, + newSourceDecryptableAvailableBalance: zeroBytes36, + transferAmountAuditorCiphertextLo: zeroBytes64, + transferAmountAuditorCiphertextHi: zeroBytes64, + equalityProofInstructionOffset: 1, + ciphertextValidityProofInstructionOffset: 2, + rangeProofInstructionOffset: 3, + }); + const tx = await toV1(b).build(); + assertV1(tx); + const instructions = tx.toJson().instructionsData; + instructions[0].type.should.equal('ApplyPendingBalance'); + instructions[4].type.should.equal('ConfidentialTransfer'); + }); + + it('should build ConfigureAccount + VerifyPubkeyValidity as a valid v1 transaction', async () => { + const b = ctBuilder(); + b.configureAccount({ + tokenAddress, + mintAddress, + authorityAddress, + decryptableZeroBalance: zeroBytes36, + maximumPendingBalanceCreditCounter: '65536', + proofInstructionOffset: 1, + }).verifyPubkeyValidity({ proofData: proofDataHex }); + const tx = await toV1(b).build(); + assertV1(tx); + }); + + it('should build each verify-proof instruction through v1', async () => { + const b = ctBuilder(); + b.verifyEqualityProof({ proofData: proofDataHex }) + .verifyValidityProof({ proofData: proofDataHex }) + .verifyRangeProof({ proofData: '00'.repeat(1000) }) + .verifyPubkeyValidity({ proofData: proofDataHex }); + const tx = await toV1(b).build(); + assertV1(tx); + }); +});