Skip to content

Commit

Permalink
add flag to result indicating if network id is included in the tx body
Browse files Browse the repository at this point in the history
  • Loading branch information
mkv-vcm committed Nov 22, 2021
1 parent f6b04b6 commit 8335970
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/interactions/signTx.ts
Expand Up @@ -741,9 +741,12 @@ export function* signTransaction(version: Version, request: ParsedSigningRequest
witnesses.push(witness)
}

const isNetworkIdIncludedInTxBody = getCompatibility(version).supportsAlonzo

return {
txHashHex,
witnesses,
auxiliaryDataSupplement,
isNetworkIdIncludedInTxBody,
}
}
5 changes: 5 additions & 0 deletions src/types/public.ts
Expand Up @@ -934,6 +934,11 @@ export type SignedTransactionData = {
* the caller with information needed to assemble the transation containing these auxiliary data.
*/
auxiliaryDataSupplement: TxAuxiliaryDataSupplement | null,
/**
* A flag to note if network id is part of the tx body, since that cannot be detected any other way,
* and the exact same transaction creating different tx bodies and hashes might cause problems
*/
isNetworkIdIncludedInTxBody: boolean,
};

/**
Expand Down
11 changes: 6 additions & 5 deletions test/integration/__fixtures__/signTx.ts
@@ -1,9 +1,10 @@
import type { AssetGroup, DeviceOwnedAddress, ErrorBase, SignedTransactionData, Transaction, TxInput, TxOutput, TxOutputDestination } from "../../../src/Ada"
import type { AssetGroup, DeviceOwnedAddress, ErrorBase, Transaction, TxInput, TxOutput, TxOutputDestination } from "../../../src/Ada"
import {DeviceStatusError, InvalidDataReason, TxAuxiliaryDataSupplementType} from "../../../src/Ada"
import { AddressType, CertificateType, Networks, TxAuxiliaryDataType, TxOutputDestinationType, utils } from "../../../src/Ada"
import type { BIP32Path} from '../../../src/types/public'
import { StakeCredentialParamsType, TransactionSigningMode } from '../../../src/types/public'
import { str_to_path } from "../../../src/utils/address"
import type { NetworkIdlessTestResult } from "../../test_utils"

export const inputs: Record<
| 'utxoByron'
Expand Down Expand Up @@ -590,7 +591,7 @@ export type TestcaseByron = {
tx: Transaction
signingMode: TransactionSigningMode
txBody?: string
result: SignedTransactionData
result: NetworkIdlessTestResult
}

export const testsByron: TestcaseByron[] = [
Expand Down Expand Up @@ -678,7 +679,7 @@ export type TestcaseShelley = {
additionalWitnessPaths: BIP32Path[]
txBody?: string
txAuxiliaryData?: string,
result: SignedTransactionData
result: NetworkIdlessTestResult
}

export const testsShelleyNoCertificates: TestcaseShelley[] = [
Expand Down Expand Up @@ -1919,7 +1920,7 @@ export type TestcaseAllegra = {
tx: Transaction
signingMode: TransactionSigningMode
txBody: string
result: SignedTransactionData
result: NetworkIdlessTestResult
}
export const testsAllegra: TestcaseAllegra[] = [
{
Expand Down Expand Up @@ -1983,7 +1984,7 @@ export type TestcaseMary = {
signingMode: TransactionSigningMode
txBody: string,
txAuxiliaryData?: string,
result: SignedTransactionData
result: NetworkIdlessTestResult
}

export const testsMary: TestcaseMary[] = [
Expand Down
5 changes: 3 additions & 2 deletions test/integration/__fixtures__/signTxPoolRegistration.ts
@@ -1,9 +1,10 @@
import type { Certificate, ErrorBase,MultiHostRelayParams, PoolKey, PoolMetadataParams, PoolOwner, PoolRegistrationParams, PoolRewardAccount, Relay, SignedTransactionData, SingleHostHostnameRelayParams, Transaction, TxInput, TxOutput, Withdrawal} from "../../../src/Ada"
import type { Certificate, ErrorBase,MultiHostRelayParams, PoolKey, PoolMetadataParams, PoolOwner, PoolRegistrationParams, PoolRewardAccount, Relay, SingleHostHostnameRelayParams, Transaction, TxInput, TxOutput, Withdrawal} from "../../../src/Ada"
import { DeviceStatusError,StakeCredentialParamsType } from "../../../src/Ada"
import { PoolKeyType, PoolRewardAccountType } from "../../../src/Ada"
import { CertificateType, InvalidDataReason, Networks, PoolOwnerType, RelayType, TxOutputDestinationType, utils } from "../../../src/Ada"
import type { BIP32Path} from '../../../src/types/public'
import { str_to_path } from "../../../src/utils/address"
import type { NetworkIdlessTestResult } from "../../test_utils"

export const inputs: Record<
| 'utxoNoPath'
Expand Down Expand Up @@ -523,7 +524,7 @@ export type Testcase = {
testname: string
tx: Transaction
txBody?: string,
result: SignedTransactionData
result: NetworkIdlessTestResult
}

export const poolRegistrationOwnerTestcases: Testcase[] = [
Expand Down
8 changes: 7 additions & 1 deletion test/integration/signTx.test.ts
Expand Up @@ -2,6 +2,7 @@ import { expect } from "chai"

import type Ada from "../../src/Ada"
import { describeWithoutValidation, getAda, hashTxBody } from "../test_utils"
import type { NetworkIdlessTestResult } from "../test_utils"
import {
testsAllegra,
testsByron,
Expand Down Expand Up @@ -39,7 +40,12 @@ function describePositiveTest(name: string, tests: any[]) {
signingMode,
additionalWitnessPaths: additionalWitnessPathsIfPresent,
})
expect(response).to.deep.equal(expected)
const networklessResponse: NetworkIdlessTestResult = {
txHashHex: response.txHashHex,
witnesses: response.witnesses,
auxiliaryDataSupplement: response.auxiliaryDataSupplement,
}
expect(networklessResponse).to.deep.equal(expected)
})
}
})
Expand Down
7 changes: 7 additions & 0 deletions test/test_utils.ts
Expand Up @@ -7,6 +7,7 @@ import type { FixlenHexString} from "types/internal"
import Ada from "../src/Ada"
import { InvalidDataReason } from "../src/errors/index"
import * as parseModule from "../src/utils/parse"
import type { Witness, TxAuxiliaryDataSupplement } from "../src/types/public"

export async function getTransport() {
return await TransportNodeHid.create(1000)
Expand Down Expand Up @@ -81,3 +82,9 @@ export function hashTxBody(txBodyHex: string): TxHash {
b2.update(Buffer.from(txBodyHex, 'hex'))
return parseModule.parseHexStringOfLength(b2.digest('hex'), 32, InvalidDataReason.INVALID_B2_HASH)
}

export type NetworkIdlessTestResult = {
txHashHex: string,
witnesses: Array<Witness>,
auxiliaryDataSupplement: TxAuxiliaryDataSupplement | null,
}

0 comments on commit 8335970

Please sign in to comment.