diff --git a/Cargo.lock b/Cargo.lock index 8d7d857266..ccf3d714e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1578,6 +1578,7 @@ dependencies = [ "fish_hash", "ironfish", "ironfish_mpc", + "jubjub 0.9.0 (git+https://github.com/iron-fish/jubjub.git?branch=blstrs)", "napi", "napi-build", "napi-derive", diff --git a/ironfish-rust-nodejs/Cargo.toml b/ironfish-rust-nodejs/Cargo.toml index 8208f5dd2d..11417cbcb9 100644 --- a/ironfish-rust-nodejs/Cargo.toml +++ b/ironfish-rust-nodejs/Cargo.toml @@ -32,6 +32,7 @@ ironfish = { path = "../ironfish-rust" } ironfish_mpc = { path = "../ironfish-mpc" } napi = { version = "2.13.2", features = ["napi6"] } napi-derive = "2.13.0" +jubjub = { git = "https://github.com/iron-fish/jubjub.git", branch = "blstrs" } rand = "0.8.5" [build-dependencies] diff --git a/ironfish-rust-nodejs/index.d.ts b/ironfish-rust-nodejs/index.d.ts index 5c2a1d9c57..d3a126bbc1 100644 --- a/ironfish-rust-nodejs/index.d.ts +++ b/ironfish-rust-nodejs/index.d.ts @@ -242,7 +242,7 @@ export class Transaction { * aka: self.value_balance - intended_transaction_fee - change = 0 */ post(spenderHexKey: string, changeGoesTo: string | undefined | null, intendedTransactionFee: bigint): Buffer - build(proofGenerationKeyStr: string, viewKeyStr: string, outgoingViewKeyStr: string, intendedTransactionFee: bigint, changeGoesTo?: string | undefined | null): Buffer + build(proofAuthorizingKeyStr: string, viewKeyStr: string, outgoingViewKeyStr: string, intendedTransactionFee: bigint, changeGoesTo?: string | undefined | null): Buffer setExpiration(sequence: number): void } export type NativeUnsignedTransaction = UnsignedTransaction diff --git a/ironfish-rust-nodejs/src/structs/transaction.rs b/ironfish-rust-nodejs/src/structs/transaction.rs index 3d7459df09..dadfea99ee 100644 --- a/ironfish-rust-nodejs/src/structs/transaction.rs +++ b/ironfish-rust-nodejs/src/structs/transaction.rs @@ -14,6 +14,7 @@ use ironfish::frost::round1::SigningCommitments; use ironfish::frost::round2::SignatureShare; use ironfish::frost::Identifier; use ironfish::frost::SigningPackage; +use ironfish::serializing::fr::FrSerializable; use ironfish::serializing::hex_to_vec_bytes; use ironfish::serializing::{bytes_to_hex, hex_to_bytes}; use ironfish::transaction::unsigned::UnsignedTransaction; @@ -22,7 +23,6 @@ use ironfish::transaction::{ TRANSACTION_FEE_SIZE, TRANSACTION_PUBLIC_KEY_SIZE, TRANSACTION_SIGNATURE_SIZE, }; use ironfish::{ - keys::proof_generation_key::{ProofGenerationKey, ProofGenerationKeySerializable}, MerkleNoteHash, OutgoingViewKey, ProposedTransaction, PublicAddress, SaplingKey, Transaction, ViewKey, }; @@ -327,7 +327,7 @@ impl NativeTransaction { #[napi] pub fn build( &mut self, - proof_generation_key_str: String, + proof_authorizing_key_str: String, view_key_str: String, outgoing_view_key_str: String, intended_transaction_fee: BigInt, @@ -336,8 +336,9 @@ impl NativeTransaction { let view_key = ViewKey::from_hex(&view_key_str).map_err(to_napi_err)?; let outgoing_view_key = OutgoingViewKey::from_hex(&outgoing_view_key_str).map_err(to_napi_err)?; - let proof_generation_key = ProofGenerationKey::from_hex(&proof_generation_key_str) - .map_err(|_| to_napi_err("PublicKeyPackage hex to bytes failed"))?; + let proof_authorizing_key = jubjub::Fr::from_hex(&proof_authorizing_key_str) + .map_err(|_| to_napi_err("PublicKeyPackage authorizing key hex to bytes failed"))?; + let change_address = match change_goes_to { Some(address) => Some(PublicAddress::from_hex(&address).map_err(to_napi_err)?), None => None, @@ -345,7 +346,7 @@ impl NativeTransaction { let unsigned_transaction = self .transaction .build( - proof_generation_key, + proof_authorizing_key, view_key, outgoing_view_key, intended_transaction_fee.get_i64().0, diff --git a/ironfish-rust-nodejs/tests/unsigned.test.slow.ts b/ironfish-rust-nodejs/tests/unsigned.test.slow.ts index 7aee70d933..d7697d699a 100644 --- a/ironfish-rust-nodejs/tests/unsigned.test.slow.ts +++ b/ironfish-rust-nodejs/tests/unsigned.test.slow.ts @@ -12,7 +12,7 @@ describe("UnsignedTransaction", () => { const proposedTx = new Transaction(2); proposedTx.mint(asset, 5n); const unsignedTxBuffer = proposedTx.build( - key.viewKey.slice(0, 64) + key.proofAuthorizingKey, //todo(rahul): change this to accept just proof authorizing key when the interface changes + key.proofAuthorizingKey, key.viewKey, key.outgoingViewKey, 0n diff --git a/ironfish-rust/src/transaction/mod.rs b/ironfish-rust/src/transaction/mod.rs index 7d3f3febd2..dbbab6a8e8 100644 --- a/ironfish-rust/src/transaction/mod.rs +++ b/ironfish-rust/src/transaction/mod.rs @@ -231,7 +231,7 @@ impl ProposedTransaction { pub fn build( &mut self, - proof_generation_key: ProofGenerationKey, + proof_authorizing_key: jubjub::Fr, view_key: ViewKey, outgoing_view_key: OutgoingViewKey, intended_transaction_fee: i64, @@ -239,6 +239,11 @@ impl ProposedTransaction { ) -> Result { let public_address = view_key.public_address()?; + let proof_generation_key = ProofGenerationKey { + ak: view_key.authorizing_key, + nsk: proof_authorizing_key, + }; + // skip adding change notes if this is special case of a miners fee transaction let is_miners_fee = self.outputs.iter().any(|output| output.get_is_miners_fee()); if !is_miners_fee { @@ -337,7 +342,7 @@ impl ProposedTransaction { let i64_fee = i64::try_from(intended_transaction_fee)?; let unsigned = self.build( - spender_key.sapling_proof_generation_key(), + spender_key.proof_authorizing_key, spender_key.view_key().clone(), spender_key.outgoing_view_key().clone(), i64_fee, @@ -377,7 +382,7 @@ impl ProposedTransaction { output.set_is_miners_fee(); } let unsigned = self.build( - spender_key.sapling_proof_generation_key(), + spender_key.proof_authorizing_key, spender_key.view_key().clone(), spender_key.outgoing_view_key().clone(), *self.value_balances.fee(), diff --git a/ironfish-rust/src/transaction/tests.rs b/ironfish-rust/src/transaction/tests.rs index bfbe016bd8..64dd7b99e1 100644 --- a/ironfish-rust/src/transaction/tests.rs +++ b/ironfish-rust/src/transaction/tests.rs @@ -242,7 +242,7 @@ fn test_proposed_transaction_build() { let unsigned_transaction = transaction .build( - spender_key.sapling_proof_generation_key(), + spender_key.proof_authorizing_key, spender_key.view_key().clone(), spender_key.outgoing_view_key().clone(), intended_fee, @@ -685,7 +685,7 @@ fn test_sign_simple() { // build transaction, generate proofs let unsigned_transaction = transaction .build( - spender_key.sapling_proof_generation_key(), + spender_key.proof_authorizing_key, spender_key.view_key().clone(), spender_key.outgoing_view_key().clone(), 1, @@ -779,7 +779,7 @@ fn test_sign_frost() { // build UnsignedTransaction without signing let mut unsigned_transaction = transaction .build( - key_packages.proof_generation_key, + key_packages.proof_generation_key.nsk, key_packages.view_key, key_packages.outgoing_view_key, intended_fee, diff --git a/ironfish/src/primitives/rawTransaction.ts b/ironfish/src/primitives/rawTransaction.ts index 42846856ba..4343c3bd9c 100644 --- a/ironfish/src/primitives/rawTransaction.ts +++ b/ironfish/src/primitives/rawTransaction.ts @@ -163,14 +163,14 @@ export class RawTransaction { } build( - proofGenerationKey: string, + proofAuthorizingKey: string, viewKey: string, outgoingViewKey: string, ): UnsignedTransaction { const builder = this._build() const serialized = builder.build( - proofGenerationKey, + proofAuthorizingKey, viewKey, outgoingViewKey, this.fee, diff --git a/ironfish/src/testUtilities/fixtures/transactions.ts b/ironfish/src/testUtilities/fixtures/transactions.ts index 36003b283f..1f81ad9898 100644 --- a/ironfish/src/testUtilities/fixtures/transactions.ts +++ b/ironfish/src/testUtilities/fixtures/transactions.ts @@ -128,11 +128,7 @@ export async function useUnsignedTxFixture( Assert.isNotNull(from.spendingKey) const key = generateKeyFromPrivateKey(from.spendingKey) const unsignedBuffer = raw - .build( - key.viewKey.slice(0, 64) + key.proofAuthorizingKey, //todo(rahul): change this to accept just proof authorizing key when the interface changes - key.viewKey, - key.outgoingViewKey, - ) + .build(key.proofAuthorizingKey, key.viewKey, key.outgoingViewKey) .serialize() return new UnsignedTransaction(unsignedBuffer) }) diff --git a/ironfish/src/wallet/wallet.test.slow.ts b/ironfish/src/wallet/wallet.test.slow.ts index c6fb98a20f..9b7a1c1185 100644 --- a/ironfish/src/wallet/wallet.test.slow.ts +++ b/ironfish/src/wallet/wallet.test.slow.ts @@ -1272,7 +1272,7 @@ describe('Wallet', () => { }) const unsignedTransaction = rawTransaction.build( - trustedDealerPackage.proofGenerationKey, + trustedDealerPackage.proofGenerationKey.slice(64, 128), trustedDealerPackage.viewKey, trustedDealerPackage.outgoingViewKey, )