Skip to content

Commit

Permalink
refactor!: rename/replace occurences of 'staking' with 'stake' where …
Browse files Browse the repository at this point in the history
…appropriate

'staking' refers to an action, while reward account balance is 'stake',
keys are 'stake keys' and credentials are 'stake credentials'

BREAKING CHANGE: rename AddressEntity.stakingCredentialHash -> stakeCredentialHash
- rename BaseAddress.getStakingCredential -> getStakeCredential
  • Loading branch information
mkazlauskas committed Aug 9, 2023
1 parent baf45d6 commit 05fc4c4
Show file tree
Hide file tree
Showing 18 changed files with 80 additions and 81 deletions.
16 changes: 8 additions & 8 deletions packages/core/src/Cardano/Address/BaseAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { InvalidArgumentError } from '@cardano-sdk/util';
import { NetworkId } from '../ChainId';

/**
* A base address directly specifies the staking key that should control the stake for that address. The staking rights
* associated with funds held in this address may be exercised by the owner of the staking key. Base addresses can be
* used in transactions without registering the staking key in advance.
* A base address directly specifies the stake key that should control the stake for that address. The staking rights
* associated with funds held in this address may be exercised by the owner of the stake key. Base addresses can be
* used in transactions without registering the stake key in advance.
*
* The stake rights can only be exercised by registering the stake key and delegating to a stake pool. Once the stake
* key is registered, the stake rights can be exercised for base addresses used in transactions before or after the key
Expand Down Expand Up @@ -37,7 +37,7 @@ export class BaseAddress {
*
* @param networkId The Network identifier.
* @param payment The payment credential.
* @param stake The staking credential.
* @param stake The stake credential.
*/
static fromCredentials(networkId: NetworkId, payment: Credential, stake: Credential): BaseAddress {
let type = AddressType.BasePaymentKeyStakeKey;
Expand All @@ -62,9 +62,9 @@ export class BaseAddress {
}

/**
* Gets the payment staking part of the base address.
* Gets the stake credential part of the base address.
*/
getStakingCredential(): Credential {
getStakeCredential(): Credential {
return this.#delegationPart;
}

Expand Down Expand Up @@ -131,7 +131,7 @@ export class BaseAddress {

const network = data[0] & 0b0000_1111;
const paymentCredential = Hash28ByteBase16(Buffer.from(data.slice(1, 29)).toString('hex'));
const stakingCredential = Hash28ByteBase16(Buffer.from(data.slice(29, 57)).toString('hex'));
const stakeCredential = Hash28ByteBase16(Buffer.from(data.slice(29, 57)).toString('hex'));

const delegationCredType =
type === AddressType.BasePaymentKeyStakeScript || type === AddressType.BasePaymentScriptStakeScript
Expand All @@ -145,7 +145,7 @@ export class BaseAddress {

return new Address({
delegationPart: {
hash: stakingCredential,
hash: stakeCredential,
type: delegationCredType
},
networkId: network,
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/Cardano/Address/PointerAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export type CertIndex = OpaqueNumber<'CertIndex'>;
export const CertIndex = (value: number): CertIndex => value as unknown as CertIndex;

/**
* A pointer that indirectly specifies the staking key that should control the stake for the address. It references
* A pointer that indirectly specifies the stake key that should control the stake for the address. It references
* a stake key by a location on the blockchain of the stake key registration certificate.
*/
export type Pointer = {
Expand All @@ -75,7 +75,7 @@ export type Pointer = {
};

/**
* A pointer address indirectly specifies the staking key that should control the stake for the address. It references
* A pointer address indirectly specifies the stake key that should control the stake for the address. It references
* a stake key by a stake key pointer, which is a location on the blockchain of the stake key registration certificate
* for that key.
*/
Expand Down Expand Up @@ -103,7 +103,7 @@ export class PointerAddress {
*
* @param networkId The Network identifier.
* @param payment The payment credential.
* @param pointer A pointer that indirectly specifies the staking key location on chain.
* @param pointer A pointer that indirectly specifies the stake key location on chain.
*/
static fromCredentials(networkId: NetworkId, payment: Credential, pointer: Pointer): PointerAddress {
let type = AddressType.PointerKey;
Expand All @@ -126,7 +126,7 @@ export class PointerAddress {
}

/**
* The stake credential pointer. This pointer indirectly specifies the staking key that should control
* The stake credential pointer. This pointer indirectly specifies the stake key that should control
* the stake for the address.
*/
getStakePointer(): Pointer {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/Cardano/Address/RewardAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { InvalidArgumentError } from '@cardano-sdk/util';
import { NetworkId } from '../ChainId';

/**
* A reward address is a cryptographic hash of the public staking key of the address. Reward account addresses are used
* A reward address is a cryptographic hash of the public stake key of the address. Reward account addresses are used
* to distribute rewards for participating in the proof-of-stake protocol (either directly or via delegation).
*/
export class RewardAddress {
Expand Down Expand Up @@ -47,7 +47,7 @@ export class RewardAddress {
/**
* Gets the payment credential part of the reward address.
*
* Note: by convention, the key inside reward addresses are NOT considered staking credentials,
* Note: by convention, the key inside reward addresses are NOT considered stake credentials,
* pointer addresses and the chain history is required to resolve its associated credential
*/
getPaymentCredential(): Credential {
Expand Down Expand Up @@ -116,7 +116,7 @@ export class RewardAddress {

return new Address({
networkId: network,
// Note: by convention, the key inside reward addresses are NOT considered staking credentials,
// Note: by convention, the key inside reward addresses are NOT considered stake credentials,
// pointer addresses and the chain history is required to resolve its associated credential
paymentPart: {
hash: stakeCredential,
Expand Down
15 changes: 7 additions & 8 deletions packages/core/src/Cardano/util/addressesShareAnyKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { PaymentAddress } from '../Address/PaymentAddress';
import { Pointer } from '../Address/PointerAddress';

type PaymentId = { credential: Credential } | { byronRoot: Hash28ByteBase16 };
type StakingId = { credential: Credential } | { pointer: Pointer };
type AddressKeyIDs = { paymentId?: PaymentId; stakingId?: StakingId };
type StakeId = { credential: Credential } | { pointer: Pointer };
type AddressKeyIDs = { paymentId?: PaymentId; stakeId?: StakeId };

/**
* Payment ID is either
Expand All @@ -31,7 +31,7 @@ const getAddressKeyIDs = (input: Address | PaymentAddress): AddressKeyIDs => {
const baseAddr = address.asBase()!;
return {
paymentId: { credential: baseAddr.getPaymentCredential() },
stakingId: { credential: baseAddr.getStakingCredential() }
stakeId: { credential: baseAddr.getStakeCredential() }
};
}
case AddressType.Byron:
Expand All @@ -50,14 +50,14 @@ const getAddressKeyIDs = (input: Address | PaymentAddress): AddressKeyIDs => {
const pointerAddr = address.asPointer()!;
return {
paymentId: { credential: pointerAddr.getPaymentCredential() },
stakingId: { pointer: pointerAddr.getStakePointer() }
stakeId: { pointer: pointerAddr.getStakePointer() }
};
}
case AddressType.RewardKey:
case AddressType.RewardScript: {
const rewardAddr = address.asReward()!;
return {
stakingId: { credential: rewardAddr.getPaymentCredential() }
stakeId: { credential: rewardAddr.getPaymentCredential() }
};
}
}
Expand All @@ -74,7 +74,7 @@ const isPaymentIdPresentAndEquals = (id1: PaymentId | undefined, id2: PaymentId
return false;
};

const isStakingIdPresentAndEquals = (id1: StakingId | undefined, id2: StakingId | undefined) => {
const isStakeIdPresentAndEquals = (id1: StakeId | undefined, id2: StakeId | undefined) => {
if (!id1 || !id2) return false;
if ('credential' in id1 && 'credential' in id2) {
return id1.credential.hash === id2.credential.hash;
Expand All @@ -94,7 +94,6 @@ export const addressesShareAnyKey = (address1: PaymentAddress, address2: Payment
const ids1 = getAddressKeyIDs(address1);
const ids2 = getAddressKeyIDs(address2);
return (
isPaymentIdPresentAndEquals(ids1.paymentId, ids2.paymentId) ||
isStakingIdPresentAndEquals(ids1.stakingId, ids2.stakingId)
isPaymentIdPresentAndEquals(ids1.paymentId, ids2.paymentId) || isStakeIdPresentAndEquals(ids1.stakeId, ids2.stakeId)
);
};
20 changes: 10 additions & 10 deletions packages/core/test/Cardano/Address/Address.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe('Cardano/Address', () => {
expect(address.asEnterprise()).toBeUndefined();

expect(baseAddress!.getPaymentCredential()).toEqual(cip19TestVectors.KEY_PAYMENT_CREDENTIAL);
expect(baseAddress!.getStakingCredential()).toEqual(cip19TestVectors.KEY_STAKING_CREDENTIAL);
expect(baseAddress!.getStakeCredential()).toEqual(cip19TestVectors.KEY_STAKE_CREDENTIAL);
expect(address.getNetworkId()).toBe(Cardano.NetworkId.Mainnet);
expect(address.getType()).toBe(Cardano.AddressType.BasePaymentKeyStakeKey);
expect(address.toBech32()).toBe(cip19TestVectors.basePaymentKeyStakeKey);
Expand All @@ -140,7 +140,7 @@ describe('Cardano/Address', () => {
expect(address.asEnterprise()).toBeUndefined();

expect(baseAddress!.getPaymentCredential()).toEqual(cip19TestVectors.KEY_PAYMENT_CREDENTIAL);
expect(baseAddress!.getStakingCredential()).toEqual(cip19TestVectors.KEY_STAKING_CREDENTIAL);
expect(baseAddress!.getStakeCredential()).toEqual(cip19TestVectors.KEY_STAKE_CREDENTIAL);
expect(address.getNetworkId()).toBe(Cardano.NetworkId.Testnet);
expect(address.getType()).toBe(Cardano.AddressType.BasePaymentKeyStakeKey);
expect(address.toBech32()).toBe(cip19TestVectors.testnetBasePaymentKeyStakeKey);
Expand All @@ -164,7 +164,7 @@ describe('Cardano/Address', () => {
expect(address.asEnterprise()).toBeUndefined();

expect(baseAddress!.getPaymentCredential()).toEqual(cip19TestVectors.SCRIPT_CREDENTIAL);
expect(baseAddress!.getStakingCredential()).toEqual(cip19TestVectors.KEY_STAKING_CREDENTIAL);
expect(baseAddress!.getStakeCredential()).toEqual(cip19TestVectors.KEY_STAKE_CREDENTIAL);
expect(address.getNetworkId()).toBe(Cardano.NetworkId.Mainnet);
expect(address.getType()).toBe(Cardano.AddressType.BasePaymentScriptStakeKey);
expect(address.toBech32()).toBe(cip19TestVectors.basePaymentScriptStakeKey);
Expand All @@ -186,7 +186,7 @@ describe('Cardano/Address', () => {
expect(address.asEnterprise()).toBeUndefined();

expect(baseAddress!.getPaymentCredential()).toEqual(cip19TestVectors.SCRIPT_CREDENTIAL);
expect(baseAddress!.getStakingCredential()).toEqual(cip19TestVectors.KEY_STAKING_CREDENTIAL);
expect(baseAddress!.getStakeCredential()).toEqual(cip19TestVectors.KEY_STAKE_CREDENTIAL);
expect(address.getNetworkId()).toBe(Cardano.NetworkId.Testnet);
expect(address.getType()).toBe(Cardano.AddressType.BasePaymentScriptStakeKey);
expect(address.toBech32()).toBe(cip19TestVectors.testnetBasePaymentScriptStakeKey);
Expand All @@ -210,7 +210,7 @@ describe('Cardano/Address', () => {
expect(address.asEnterprise()).toBeUndefined();

expect(baseAddress!.getPaymentCredential()).toEqual(cip19TestVectors.KEY_PAYMENT_CREDENTIAL);
expect(baseAddress!.getStakingCredential()).toEqual(cip19TestVectors.SCRIPT_CREDENTIAL);
expect(baseAddress!.getStakeCredential()).toEqual(cip19TestVectors.SCRIPT_CREDENTIAL);
expect(address.getNetworkId()).toBe(Cardano.NetworkId.Mainnet);
expect(address.getType()).toBe(Cardano.AddressType.BasePaymentKeyStakeScript);
expect(address.toBech32()).toBe(cip19TestVectors.basePaymentKeyStakeScript);
Expand All @@ -232,7 +232,7 @@ describe('Cardano/Address', () => {
expect(address.asEnterprise()).toBeUndefined();

expect(baseAddress!.getPaymentCredential()).toEqual(cip19TestVectors.KEY_PAYMENT_CREDENTIAL);
expect(baseAddress!.getStakingCredential()).toEqual(cip19TestVectors.SCRIPT_CREDENTIAL);
expect(baseAddress!.getStakeCredential()).toEqual(cip19TestVectors.SCRIPT_CREDENTIAL);
expect(address.getNetworkId()).toBe(Cardano.NetworkId.Testnet);
expect(address.getType()).toBe(Cardano.AddressType.BasePaymentKeyStakeScript);
expect(address.toBech32()).toBe(cip19TestVectors.testnetBasePaymentKeyStakeScript);
Expand All @@ -256,7 +256,7 @@ describe('Cardano/Address', () => {
expect(address.asEnterprise()).toBeUndefined();

expect(baseAddress!.getPaymentCredential()).toEqual(cip19TestVectors.SCRIPT_CREDENTIAL);
expect(baseAddress!.getStakingCredential()).toEqual(cip19TestVectors.SCRIPT_CREDENTIAL);
expect(baseAddress!.getStakeCredential()).toEqual(cip19TestVectors.SCRIPT_CREDENTIAL);
expect(address.getNetworkId()).toBe(Cardano.NetworkId.Mainnet);
expect(address.getType()).toBe(Cardano.AddressType.BasePaymentScriptStakeScript);
expect(address.toBech32()).toBe(cip19TestVectors.basePaymentScriptStakeScript);
Expand All @@ -278,7 +278,7 @@ describe('Cardano/Address', () => {
expect(address.asEnterprise()).toBeUndefined();

expect(baseAddress!.getPaymentCredential()).toEqual(cip19TestVectors.SCRIPT_CREDENTIAL);
expect(baseAddress!.getStakingCredential()).toEqual(cip19TestVectors.SCRIPT_CREDENTIAL);
expect(baseAddress!.getStakeCredential()).toEqual(cip19TestVectors.SCRIPT_CREDENTIAL);
expect(address.getNetworkId()).toBe(Cardano.NetworkId.Testnet);
expect(address.getType()).toBe(Cardano.AddressType.BasePaymentScriptStakeScript);
expect(address.toBech32()).toBe(cip19TestVectors.testnetBasePaymentScriptStakeScript);
Expand Down Expand Up @@ -509,7 +509,7 @@ describe('Cardano/Address', () => {
expect(address.asBase()).toBeUndefined();
expect(address.asPointer()).toBeUndefined();

expect(reward!.getPaymentCredential()).toEqual(cip19TestVectors.KEY_STAKING_CREDENTIAL);
expect(reward!.getPaymentCredential()).toEqual(cip19TestVectors.KEY_STAKE_CREDENTIAL);
expect(address.getNetworkId()).toBe(Cardano.NetworkId.Mainnet);
expect(address.getType()).toBe(Cardano.AddressType.RewardKey);
expect(address.toBech32()).toBe(cip19TestVectors.rewardKey);
Expand All @@ -528,7 +528,7 @@ describe('Cardano/Address', () => {
expect(address.asBase()).toBeUndefined();
expect(address.asPointer()).toBeUndefined();

expect(reward!.getPaymentCredential()).toEqual(cip19TestVectors.KEY_STAKING_CREDENTIAL);
expect(reward!.getPaymentCredential()).toEqual(cip19TestVectors.KEY_STAKE_CREDENTIAL);
expect(address.getNetworkId()).toBe(Cardano.NetworkId.Testnet);
expect(address.getType()).toBe(Cardano.AddressType.RewardKey);
expect(address.toBech32()).toBe(cip19TestVectors.testnetRewardKey);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/Cardano/Address/BaseAddress.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('Cardano/Address/BaseAddress', () => {
const address = Cardano.BaseAddress.fromCredentials(
Cardano.NetworkId.Mainnet,
cip19TestVectors.KEY_PAYMENT_CREDENTIAL,
cip19TestVectors.KEY_STAKING_CREDENTIAL
cip19TestVectors.KEY_STAKE_CREDENTIAL
);
expect(address.toAddress().toBech32()).toEqual(cip19TestVectors.basePaymentKeyStakeKey);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/Cardano/Address/RewardAddress.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('Cardano/Address/RewardAddress', () => {
it('fromCredentials can build the correct RewardAddress instance', () => {
const address = Cardano.RewardAddress.fromCredentials(
Cardano.NetworkId.Mainnet,
cip19TestVectors.KEY_STAKING_CREDENTIAL
cip19TestVectors.KEY_STAKE_CREDENTIAL
);
expect(address.toAddress().toBech32()).toEqual(cip19TestVectors.rewardKey);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('addressesShareAnyKey', () => {
).toBe(true);
});

it('returns true when addresses have the same staking credential key hash', () => {
it('returns true when addresses have the same stake credential key hash', () => {
const addr1 = Cardano.BaseAddress.fromCredentials(
Cardano.NetworkId.Mainnet,
{
Expand Down
Loading

0 comments on commit 05fc4c4

Please sign in to comment.