I am building a daap and i want the user to be able to mint their app-tokens but the policy of the token must include the signature of the app wallet as well, for this I did the policy with the following code: where appKeyHash and clientKeyHash are the respective hashes for client and app addresses
const nativeScripts = Loader.Cardano.NativeScripts.new();
const script = Loader.Cardano.ScriptPubkey.new(clientKeyHash);
const nativeScript = Loader.Cardano.NativeScript.new_script_pubkey(script);
const appScript = Loader.Cardano.ScriptPubkey.new(appKeyHash);
const appNativeScript =
Loader.Cardano.NativeScript.new_script_pubkey(appScript);
const lockScript = Loader.Cardano.NativeScript.new_timelock_expiry(
Loader.Cardano.TimelockExpiry.new(ttl)
);
nativeScripts.add(nativeScript);
nativeScripts.add(appNativeScript);
nativeScripts.add(lockScript);
const finalScript = Loader.Cardano.NativeScript.new_script_all(
Loader.Cardano.ScriptAll.new(nativeScripts)
);
const policyId = Buffer.from(
Loader.Cardano.ScriptHash.from_bytes(
finalScript.hash().to_bytes()
).to_bytes(),
"hex"
).toString("hex");
Then I do all the transaction fee calculation and use Nami wallet to partial-sign the Tx (in the client side). Then I send to my backend the partial-signed transaction, and I add one vkeywitness using the private key of the app and Cardano-Serialization-Lib with the following code:
const tx = CardanoWasm.Transaction.from_bytes(Buffer.from(txString, "hex"));
const body = tx.body();
const txHash = CardanoWasm.hash_transaction(body);
const txWitnesses = tx.witness_set();
const txVkeys = txWitnesses.vkeys();
const txScripts = txWitnesses.native_scripts();
const addWitnesses = CardanoWasm.TransactionWitnessSet.new();
const vkeyWitnesses = CardanoWasm.Vkeywitnesses.new();
const vkeyWitness = CardanoWasm.make_vkey_witness(txHash, prvKey);
vkeyWitnesses.add(vkeyWitness);
addWitnesses.set_vkeys(vkeyWitnesses);
const addVkeys = addWitnesses.vkeys();
const addScripts = addWitnesses.native_scripts();
const totalVkeys = CardanoWasm.Vkeywitnesses.new();
const totalScripts = CardanoWasm.NativeScripts.new();
if (txVkeys) {
for (let i = 0; i < txVkeys.len(); i++) {
totalVkeys.add(txVkeys.get(i));
}
}
if (txScripts) {
for (let i = 0; i < txScripts.len(); i++) {
totalScripts.add(txScripts.get(i));
}
}
if (addVkeys) {
for (let i = 0; i < addVkeys.len(); i++) {
totalVkeys.add(addVkeys.get(i));
}
}
if (addScripts) {
for (let i = 0; i < addScripts.len(); i++) {
totalScripts.add(addScripts.get(i));
}
}
const totalWitnesses = CardanoWasm.TransactionWitnessSet.new();
totalWitnesses.set_vkeys(totalVkeys);
totalWitnesses.set_native_scripts(totalScripts);
const signedTx = CardanoWasm.Transaction.new(
tx.body(),
totalWitnesses,
tx.auxiliary_data()
);
Where tx is the hex-CBOR transaction i get from my front end (with the front-end witnessvkey already attached)
But when i try to send it i get the following error :
"transaction submit error ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (ScriptWitnessNotValidatingUTXOW (fromList [ScriptHash \"afae51e0836484a4196a3ef11018ab78990008df6459e70f7db6cfb4\"]))),UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (FeeTooSmallUTxO (Coin 187325) (Coin 187193))))])"
The first error its because i am not correctly validating the transaction, the seccond is because the fees go up a little because I added one extra signature. I am not worried about the seccond error, what i do not underestand is
why is happening the first error:
WrappedShelleyEraFailure (ScriptWitnessNotValidatingUTXOW (fromList [ScriptHash \"afae51e0836484a4196a3ef11018ab78990008df6459e70f7db6cfb4\"])))
Even if i signed the Tx with the correponding privakekeys ?