Skip to content

Commit

Permalink
[SQUASH] withdrawal and certificate related renamings
Browse files Browse the repository at this point in the history
  • Loading branch information
mkv-vcm authored and janmazak committed Jul 28, 2021
1 parent 3b250ea commit 276763e
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 31 deletions.
14 changes: 7 additions & 7 deletions src/interactions/serialization/txCertificate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ import { validate } from "../../utils/parse"
import { StakeCredentialType, ParsedCertificate, Uint8_t } from "../../types/internal"
import { CertificateType } from "../../types/internal"
import { unreachable } from "../../utils/assert"
import { hex_to_buf, path_to_buf, uint8_to_buf, uint64_to_buf, multisig_identifier_to_buf } from "../../utils/serialize"
import { hex_to_buf, path_to_buf, uint8_to_buf, uint64_to_buf, stake_credential_to_buf } from "../../utils/serialize"

export function serializeTxCertificatePreMultisig(
certificate: ParsedCertificate,
) {
switch (certificate.type) {
case CertificateType.STAKE_REGISTRATION:
case CertificateType.STAKE_DEREGISTRATION: {
validate(StakeCredentialType.KEY_PATH == certificate.identifier.type, InvalidDataReason.CERTIFICATE_INVALID_IDENTIFIER)
validate(StakeCredentialType.KEY_PATH == certificate.stakeCredential.type, InvalidDataReason.CERTIFICATE_INVALID_IDENTIFIER)
return Buffer.concat([
uint8_to_buf(certificate.type as Uint8_t),
path_to_buf(certificate.identifier.path),
path_to_buf(certificate.stakeCredential.path),
])
}
case CertificateType.STAKE_DELEGATION: {
validate(StakeCredentialType.KEY_PATH == certificate.identifier.type, InvalidDataReason.CERTIFICATE_INVALID_IDENTIFIER)
validate(StakeCredentialType.KEY_PATH == certificate.stakeCredential.type, InvalidDataReason.CERTIFICATE_INVALID_IDENTIFIER)
return Buffer.concat([
uint8_to_buf(certificate.type as Uint8_t),
path_to_buf(certificate.identifier.path),
path_to_buf(certificate.stakeCredential.path),
hex_to_buf(certificate.poolKeyHashHex),
])
}
Expand Down Expand Up @@ -50,13 +50,13 @@ export function serializeTxCertificate(
case CertificateType.STAKE_DEREGISTRATION: {
return Buffer.concat([
uint8_to_buf(certificate.type as Uint8_t),
multisig_identifier_to_buf(certificate.identifier),
stake_credential_to_buf(certificate.stakeCredential),
])
}
case CertificateType.STAKE_DELEGATION: {
return Buffer.concat([
uint8_to_buf(certificate.type as Uint8_t),
multisig_identifier_to_buf(certificate.identifier),
stake_credential_to_buf(certificate.stakeCredential),
hex_to_buf(certificate.poolKeyHashHex),
])
}
Expand Down
8 changes: 4 additions & 4 deletions src/interactions/serialization/txOther.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { InvalidDataReason } from "../../errors/invalidDataReason"
import { validate } from "../../utils/parse"
import { Int64_str, StakeCredentialType, ParsedAssetGroup, ParsedInput, ParsedToken, ParsedWithdrawal, Uint32_t, Uint64_str, ValidBIP32Path } from "../../types/internal"
import { hex_to_buf, path_to_buf, uint32_to_buf, uint64_to_buf, multisig_identifier_to_buf } from "../../utils/serialize"
import { hex_to_buf, path_to_buf, uint32_to_buf, uint64_to_buf, stake_credential_to_buf } from "../../utils/serialize"
import type {SerializeTokenAmountFn} from "../signTx"

export function serializeTxInput(
Expand All @@ -16,10 +16,10 @@ export function serializeTxInput(
export function serializeTxWithdrawalPreMultisig(
withdrawal: ParsedWithdrawal
) {
validate(StakeCredentialType.KEY_PATH == withdrawal.identifier.type, InvalidDataReason.WITHDRAWAL_INVALID_IDENTIFIER)
validate(StakeCredentialType.KEY_PATH == withdrawal.stakeCredential.type, InvalidDataReason.WITHDRAWAL_INVALID_IDENTIFIER)
return Buffer.concat([
uint64_to_buf(withdrawal.amount),
path_to_buf(withdrawal.identifier.path),
path_to_buf(withdrawal.stakeCredential.path),
])
}

Expand All @@ -28,7 +28,7 @@ export function serializeTxWithdrawal(
) {
return Buffer.concat([
uint64_to_buf(withdrawal.amount),
multisig_identifier_to_buf(withdrawal.identifier),
stake_credential_to_buf(withdrawal.stakeCredential),
])
}

Expand Down
10 changes: 5 additions & 5 deletions src/interactions/signTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,15 +559,15 @@ function generateWitnessPaths(request: ParsedSigningRequest): ValidBIP32Path[] {
} else if (cert.type === CertificateType.STAKE_POOL_RETIREMENT) {
_insert(cert.path)
} else {
if (StakeCredentialType.KEY_PATH == cert.identifier.type) {
_insert(cert.identifier.path)
if (StakeCredentialType.KEY_PATH == cert.stakeCredential.type) {
_insert(cert.stakeCredential.path)
}
}
}

for (const withdrawal of tx.withdrawals) {
if (StakeCredentialType.KEY_PATH == withdrawal.identifier.type) {
_insert(withdrawal.identifier.path)
if (StakeCredentialType.KEY_PATH == withdrawal.stakeCredential.type) {
_insert(withdrawal.stakeCredential.path)
}
}

Expand Down Expand Up @@ -596,7 +596,7 @@ function ensureRequestSupportedByAppVersion(version: Version, request: ParsedSig
(c.type === CertificateType.STAKE_DELEGATION ||
c.type === CertificateType.STAKE_DEREGISTRATION ||
c.type === CertificateType.STAKE_REGISTRATION) &&
c.identifier.type === StakeCredentialType.SCRIPT_HASH)
c.stakeCredential.type === StakeCredentialType.SCRIPT_HASH)

if (hasPoolRetirement && !getCompatibility(version).supportsPoolRetirement) {
throw new DeviceVersionUnsupported(`Pool retirement certificate not supported by Ledger app version ${version}.`)
Expand Down
4 changes: 2 additions & 2 deletions src/parsing/certificate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ export function parseCertificate(cert: Certificate): ParsedCertificate {
validate((cert.params as any).poolKeyHashHex == null, InvalidDataReason.CERTIFICATE_SUPERFLUOUS_POOL_KEY_HASH)
return {
type: cert.type,
identifier: parseStakeCredential(cert.params.identifier, InvalidDataReason.CERTIFICATE_INVALID_SCRIPT_HASH)
stakeCredential: parseStakeCredential(cert.params.identifier, InvalidDataReason.CERTIFICATE_INVALID_SCRIPT_HASH)
}
}
case CertificateType.STAKE_DELEGATION: {
return {
type: cert.type,
identifier: parseStakeCredential(cert.params.identifier, InvalidDataReason.CERTIFICATE_INVALID_SCRIPT_HASH),
stakeCredential: parseStakeCredential(cert.params.identifier, InvalidDataReason.CERTIFICATE_INVALID_SCRIPT_HASH),
poolKeyHashHex: parseHexStringOfLength(cert.params.poolKeyHashHex, KEY_HASH_LENGTH, InvalidDataReason.CERTIFICATE_INVALID_POOL_KEY_HASH),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/parsing/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function parseTxInput(input: TxInput): ParsedInput {
function parseWithdrawal(params: Withdrawal): ParsedWithdrawal {
return {
amount: parseUint64_str(params.amount, { max: MAX_LOVELACE_SUPPLY_STR }, InvalidDataReason.WITHDRAWAL_INVALID_AMOUNT),
identifier: parseStakeCredential(params.identifier, InvalidDataReason.WITHDRAWAL_INVALID_IDENTIFIER),
stakeCredential: parseStakeCredential(params.stakeCredential, InvalidDataReason.WITHDRAWAL_INVALID_IDENTIFIER),
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/types/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ export type ParsedStakeCredential =

export type ParsedCertificate = {
type: CertificateType.STAKE_REGISTRATION
identifier: ParsedStakeCredential
stakeCredential: ParsedStakeCredential
} | {
type: CertificateType.STAKE_DEREGISTRATION
identifier: ParsedStakeCredential
stakeCredential: ParsedStakeCredential
} | {
type: CertificateType.STAKE_DELEGATION
identifier: ParsedStakeCredential
stakeCredential: ParsedStakeCredential
poolKeyHashHex: FixlenHexString<typeof KEY_HASH_LENGTH>
} | {
type: CertificateType.STAKE_POOL_REGISTRATION
Expand Down Expand Up @@ -132,7 +132,7 @@ export type ParsedInput = {

export type ParsedWithdrawal = {
amount: Uint64_str
identifier: ParsedStakeCredential
stakeCredential: ParsedStakeCredential
}


Expand Down
2 changes: 1 addition & 1 deletion src/types/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ export type Withdrawal = {
/**
* Path to rewards account being withdrawn
*/
identifier: StakeCredentialParams,
stakeCredential: StakeCredentialParams,
/**
* Amount (in Lovelace) being withdrawn.
* Note that Amount *must* be all accumulated rewards.
Expand Down
12 changes: 6 additions & 6 deletions src/utils/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ export function path_to_buf(path: Array<number>): Buffer {
return data
}

export function multisig_identifier_to_buf(identifier: ParsedStakeCredential): Buffer {
if (StakeCredentialType.KEY_PATH == identifier.type) {
export function stake_credential_to_buf(stakeCredential: ParsedStakeCredential): Buffer {
if (StakeCredentialType.KEY_PATH == stakeCredential.type) {
return Buffer.concat([
uint8_to_buf(identifier.type as Uint8_t),
path_to_buf(identifier.path),
uint8_to_buf(stakeCredential.type as Uint8_t),
path_to_buf(stakeCredential.path),
])
} else {
return Buffer.concat([
uint8_to_buf(identifier.type as Uint8_t),
hex_to_buf(identifier.scriptHash),
uint8_to_buf(stakeCredential.type as Uint8_t),
hex_to_buf(stakeCredential.scriptHash),
])
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/__fixtures__/signTxPoolRegistration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ export const withdrawals: Record<
, Withdrawal
> = {
withdrawal0: {
identifier: {
stakeCredential: {
path: str_to_path("1852'/1815'/0'/2/0"),
},
amount: "111",
Expand Down

0 comments on commit 276763e

Please sign in to comment.