Skip to content

Commit

Permalink
extend datum hash policies
Browse files Browse the repository at this point in the history
  • Loading branch information
mkv-vcm committed Oct 12, 2021
1 parent b7ccbee commit 438e55d
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/errors/invalidDataReason.ts
Expand Up @@ -193,4 +193,9 @@ export enum InvalidDataReason {
"invalid required count - higher than number of total scripts",
DERIVE_NATIVE_SCRIPT_HASH_UNKNOWN_TYPE = "unknown script type",
DERIVE_NATIVE_SCRIPT_HASH_INVALID_DISPLAY_FORMAT = "invalid native script hash display format",

/**
* For errors that we don't want to check on the LedgerJS side
*/
LEDGER_POLICY = "Action rejected by Ledger's security policy"
}
81 changes: 78 additions & 3 deletions test/integration/__fixtures__/signTx.ts
Expand Up @@ -49,6 +49,7 @@ const destinations: Record<
| 'externalShelleyScripthash'
| 'internalBaseWithStakingKeyHash'
| 'internalBaseWithStakingPath'
| 'internalBaseWithStakingScript'
| 'internalBaseWithStakingPathNonReasonable'
| 'internalEnterprise'
| 'internalPointer'
Expand Down Expand Up @@ -117,6 +118,16 @@ const destinations: Record<
},
},
},
internalBaseWithStakingScript: {
type: TxOutputDestinationType.DEVICE_OWNED,
params: {
type: AddressType.BASE_PAYMENT_KEY_STAKE_SCRIPT,
params: {
spendingPath: str_to_path("1852'/1815'/0'/0/0"),
stakingScriptHash: "122a946b9ad3d2ddf029d3a828f0468aece76895f15c9efbd69b4277",
},
},
},
internalBaseWithStakingPathNonReasonable: {
type: TxOutputDestinationType.DEVICE_OWNED,
params: {
Expand Down Expand Up @@ -274,7 +285,10 @@ export const outputs: Record<
| 'multiassetTokensNotUnique'
| 'trezorParity'
| 'datumHash'
| 'datumHashExternal'
| 'datumHashWithTokens'
| 'datumHashStakePath'
| 'datumHashStakePathExternal'
, TxOutput
> = {
externalByronMainnet: {
Expand Down Expand Up @@ -523,12 +537,18 @@ export const outputs: Record<
],
},
datumHash: {
destination: destinations.internalBaseWithStakingPath,
destination: destinations.internalBaseWithStakingScript,
amount: 7120787,
datumHashHex: "ffd4d009f554ba4fd8ed1f1d703244819861a9d34fd4753bcf3ff32f043ce188",
},
datumHashExternal: {
// destination: destinations.multiassetThirdParty,
destination: destinations.externalShelleyScripthash,
amount: 7120787,
datumHashHex: "ffd4d009f554ba4fd8ed1f1d703244819861a9d34fd4753bcf3ff32f043ce188",
},
datumHashWithTokens: {
destination: destinations.internalBaseWithStakingPath,
destination: destinations.internalBaseWithStakingScript,
amount: 7120787,
tokenBundle: [
{
Expand All @@ -547,6 +567,16 @@ export const outputs: Record<
],
datumHashHex: "ffd4d009f554ba4fd8ed1f1d703244819861a9d34fd4753bcf3ff32f043ce188",
},
datumHashStakePath: {
destination: destinations.internalBaseWithStakingPath,
amount: 7120787,
datumHashHex: "ffd4d009f554ba4fd8ed1f1d703244819861a9d34fd4753bcf3ff32f043ce188",
},
datumHashStakePathExternal: {
destination: destinations.externalShelley,
amount: 7120787,
datumHashHex: "ffd4d009f554ba4fd8ed1f1d703244819861a9d34fd4753bcf3ff32f043ce188",
},
}

const byronBase = {
Expand Down Expand Up @@ -955,7 +985,7 @@ export const testsShelleyNoCertificates: TestcaseShelley[] = [
},
},
{
testname: "Sign tx with datum hash in output",
testname: "Sign tx with datum hash in output - internal address",
tx: {
...shelleyBase,
outputs: [outputs.datumHash],
Expand All @@ -976,6 +1006,29 @@ export const testsShelleyNoCertificates: TestcaseShelley[] = [
auxiliaryDataSupplement: null,
},
},
{
testname: "Sign tx with datum hash in output - external address",
tx: {
...shelleyBase,
network: Networks.Testnet,
outputs: [outputs.datumHashExternal],
},
signingMode: TransactionSigningMode.ORDINARY_TRANSACTION,
additionalWitnessPaths: [],
txBody: "a500818258203b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b70001818358390114c16d7f43243bd81478e68b9db53a8528fd4fb1078d58d54a7f11241d227aefa4b773149170885aadba30aab3127cc611ddbc4999def61c1a006ca7935820ffd4d009f554ba4fd8ed1f1d703244819861a9d34fd4753bcf3ff32f043ce18802182a030a0f01",
result: {
txHashHex:
"b3a20534d53101c40d2011811e6dbf7644aa3d9baebba1e72161bf94b4a2db2b",
witnesses: [
{
path: str_to_path("1852'/1815'/0'/0/0"),
witnessSignatureHex:
"3051ab97dcaab66c31be3ab1255db7176e1aaa38193e4f233694797afaa40bce48c7c0557dcc537117dc1c851ee0f132714fe9167f57c12e9fd124ae9629bb0f",
},
],
auxiliaryDataSupplement: null,
},
},
{
testname: "Sign tx with datum hash in output with tokens",
tx: {
Expand Down Expand Up @@ -1535,6 +1588,28 @@ export const testsShelleyRejects: TestcaseRejectShelley[] = [
errMsg: "Action rejected by Ledger's security policy",
rejectReason: InvalidDataReason.OUTPUT_INVALID_ADDRESS_PARAMS,
},
{
testname: "Reject tx for datum hash without script hash part - internal address",
tx: {
...shelleyBase,
outputs: [outputs.datumHashStakePath],
},
signingMode: TransactionSigningMode.ORDINARY_TRANSACTION,
errCls: DeviceStatusError,
errMsg: "Action rejected by Ledger's security policy",
rejectReason: InvalidDataReason.LEDGER_POLICY,
},
{
testname: "Reject tx for datum hash without script hash part - external address",
tx: {
...shelleyBase,
outputs: [outputs.datumHashStakePathExternal],
},
signingMode: TransactionSigningMode.ORDINARY_TRANSACTION,
errCls: DeviceStatusError,
errMsg: "Action rejected by Ledger's security policy",
rejectReason: InvalidDataReason.LEDGER_POLICY,
},
]


Expand Down
1 change: 0 additions & 1 deletion test/integration/signTx.test.ts
Expand Up @@ -9,7 +9,6 @@ import {
testsInvalidTokenBundleOrdering,
testsMary,
testsShelleyNoCertificates,
testsShelleyRejects,
testsShelleyWithCertificates,
testsShelleyRejects,
} from "./__fixtures__/signTx"
Expand Down

0 comments on commit 438e55d

Please sign in to comment.