Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove empty signature workaround #319

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"dependencies": {
"@algorandfoundation/algokit-subscriber": "^2.0.4",
"@algorandfoundation/algokit-utils": "^7.0.0-beta.16",
"@algorandfoundation/algokit-utils": "^7.0.0-beta.20",
"@auth0/auth0-react": "^2.2.4",
"@blockshake/defly-connect": "^1.1.6",
"@daffiwallet/connect": "^1.0.3",
Expand Down Expand Up @@ -189,7 +189,7 @@
},
"overrides": {
"ws@>7.0.0 <7.5.9": "7.5.10",
"@algorandfoundation/algokit-utils@<7.0.0": "^7.0.0-beta.16",
"@algorandfoundation/algokit-utils@<7.0.0": "^7.0.0-beta.20",
"path-to-regexp@>= 0.2.0 <8.0.0": "8.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ export function TransactionsBuilder({
} satisfies SimulateOptions
const result = await (requireSignaturesOnSimulate
? (await buildComposer(transactions)).simulate(simulateConfig)
: (await buildComposerWithEmptySignatures(transactions)).simulate({ ...simulateConfig, allowEmptySignatures: true }))
: (await buildComposerWithEmptySignatures(transactions)).simulate({
...simulateConfig,
allowEmptySignatures: true,
fixSigners: true,
}))

return onSimulated?.(result)
} catch (error) {
Expand Down
28 changes: 3 additions & 25 deletions src/features/transaction-wizard/data/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { asOnCompleteLabel } from '../mappers/as-description-list-items'
import { algorandClient } from '@/features/common/data/algo-client'
import { BuildTransactionResult } from '../models'
import { asAlgosdkTransactions } from '../mappers'
import { Buffer } from 'buffer'
import { isNfd } from '@/features/nfd/data'

export const requiredMessage = 'Required'
Expand Down Expand Up @@ -143,34 +142,13 @@ export const buildComposer = async (transactions: BuildTransactionResult[]) => {
return composer
}

const nullSigner = algosdk.makeEmptyTransactionSigner()

export const buildComposerWithEmptySignatures = async (transactions: BuildTransactionResult[]) => {
const composer = algorandClient.newGroup()
for (const transaction of transactions) {
const txns = await asAlgosdkTransactions(transaction)
txns.forEach((txn) => composer.addTransaction(txn, fixedEmptyTransactionSigner))
txns.forEach((txn) => composer.addTransaction(txn, nullSigner))
}
return composer
}

// TODO: Remove this fix and use `fixSigners` once nodes have updated to algod 3.26
// This code was lifted for algokit-utils-ts
// https://github.com/algorand/go-algorand/pull/5942
const fixedEmptyTransactionSigner: algosdk.TransactionSigner = async (txns: algosdk.Transaction[], indexes: number[]) => {
const stxns = await algosdk.makeEmptyTransactionSigner()(txns, indexes)
return Promise.all(
stxns.map(async (stxn) => {
const decodedStxn = algosdk.decodeSignedTransaction(stxn)
const sender = algosdk.encodeAddress(decodedStxn.txn.from.publicKey)

const authAddr = (await algorandClient.client.algod.accountInformation(sender).do())['auth-addr']

const stxnObj: { txn: algosdk.EncodedTransaction; sgnr?: Buffer } = { txn: decodedStxn.txn.get_obj_for_encoding() }

if (authAddr !== undefined) {
stxnObj.sgnr = Buffer.from(algosdk.decodeAddress(authAddr).publicKey)
}

return algosdk.encodeObj(stxnObj)
})
)
}
Loading