I'm trying to mint a native asset reusing the keys that Nami already uses. This is to make a minting service that is connected to a specific wallet, and that wallet is always able to mint more tokens if they want to.
However, it doesn't seem like Nami is providing all the signatures that I need. When submitting the transaction I get the following error:
transaction submit error ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (MissingScriptWitnessesUTXOW (fromList [ScriptHash \"9f84ae8b52e374a0cd09e7ec10854309f8dd7b1f5caf69dd658ed6c5\"]))),UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (UtxosFailure (CollectErrors [NoRedeemer (Minting (PolicyID {policyID = ScriptHash \"9f84ae8b52e374a0cd09e7ec10854309f8dd7b1f5caf69dd658ed6c5\"})),NoWitness (ScriptHash \"9f84ae8b52e374a0cd09e7ec10854309f8dd7b1f5caf69dd658ed6c5\")]))))])
I seem to be missing the witness for the native asset script. Is there any way of making Nami sign this or is it impossible? Note that I'm already using the signTx(...)
endpoint so it seems to be signing the entire transaction just not what is required by the minting script.
Code:
async function mint(mintData: MintData, wasm: any, walletConnector: WalletConnector){
const userAddress: Address = wasm.Address.from_bytes(
Buffer.from(mintData.address, "hex")
)
const p = await initTx()
const txBuilder: TransactionBuilder = wasm.TransactionBuilder.new(
wasm.TransactionBuilderConfigBuilder.new()
.fee_algo(wasm.LinearFee.new(wasm.BigNum.from_str(p.linearFee.minFeeA),
wasm.BigNum.from_str(p.linearFee.minFeeB)))
.pool_deposit(wasm.BigNum.from_str(p.poolDeposit))
.key_deposit(wasm.BigNum.from_str(p.keyDeposit))
.coins_per_utxo_word(wasm.BigNum.from_str(p.coinsPerUtxoWord))
.max_value_size(p.maxValSize)
.max_tx_size(p.maxTxSize)
.build()
);
const invalidHereafter=10
if (p.slot === null){
return
}
const ttl = p.slot+invalidHereafter
const timelockExpiry = wasm.TimelockExpiry.new(ttl)
const timeLockedPolicyScript = wasm.NativeScript.new_timelock_expiry(timelockExpiry)
const policyScripts = wasm.NativeScripts.new()
policyScripts.add(timeLockedPolicyScript)
const scriptHash = wasm.ScriptHash.from_bytes(timeLockedPolicyScript.hash().to_bytes())
const policyID = bytesToString(timeLockedPolicyScript.hash().to_bytes())
//const assetName = Buffer.from(mintData.tokenName, 'hex')
txBuilder.add_mint_asset_and_output_min_required_coin(
timeLockedPolicyScript,
wasm.AssetName.new(mintData.tokenName),
wasm.Int.new_i32(mintData.amount),
userAddress,
);
const valueFilter: Value = wasm.Value.new(wasm.BigNum.from_str("5000000"))
//Add inputs
const utxos: TransactionUnspentOutputs = wasm.TransactionUnspentOutputs.new();
(await walletConnector.getUtxos(Buffer.from(valueFilter.to_bytes()).toString('hex')))
.forEach(rawUTXO => {
const utxo: TransactionUnspentOutput = wasm.TransactionUnspentOutput.from_bytes(Buffer.from(rawUTXO, "hex"))
utxos.add(utxo)
})
txBuilder.add_inputs_from(utxos, 0)
txBuilder.add_change_if_needed(userAddress)
const toBeSignedTx: Transaction = txBuilder.build_tx();
const rawToBeSignedTx: string = Buffer.from(toBeSignedTx.to_bytes()).toString('hex')
const rawWitnesses: string = await walletConnector.signTx(rawToBeSignedTx)
const witnessSet = wasm.TransactionWitnessSet.from_bytes(
Buffer.from(rawWitnesses, "hex")
)
const witnessSets: TransactionWitnessSets = wasm.TransactionWitnessSets.new()
witnessSets.add(witnessSet)
const submitTx: Transaction =
wasm.Transaction.new(
toBeSignedTx.body(),
witnessSet
)
const rawSubmitTx: string = Buffer.from(submitTx.to_bytes()).toString('hex')
walletConnector.submitTx(rawSubmitTx) // <- Error occurs when submitting
}
signData(...)
I'll update the post if that turns out to be the solution