Skip to content

Commit

Permalink
refactor: move types
Browse files Browse the repository at this point in the history
  • Loading branch information
janniks committed Jun 6, 2024
1 parent 969af6a commit 3c6bc99
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 28 deletions.
3 changes: 1 addition & 2 deletions packages/transactions/src/builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import {
} from './postcondition';
import {
Asset,
AssetString,
FungiblePostCondition,
NonFungiblePostCondition,
PostCondition,
Expand All @@ -51,7 +50,7 @@ import {
} from './postcondition-types';
import { TransactionSigner } from './signer';
import { StacksTransaction } from './transaction';
import { createLPList } from './types';
import { AssetString, createLPList } from './types';
import { defaultApiFromNetwork, omit } from './utils';

export interface MultiSigOptions {
Expand Down
1 change: 0 additions & 1 deletion packages/transactions/src/cl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ export const contractPrincipal = contractPrincipalCV;
* @see {@link serialize}, {@link deserialize}
*/
export const standardPrincipal = standardPrincipalCV;
// todo: add .principal method that detects `.` inside string for both standard and contract principals

// Sequences ///////////////////////////////////////////////////////////////////
/**
Expand Down
4 changes: 2 additions & 2 deletions packages/transactions/src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ export function signWithKey(privateKey: PrivateKey, messageHash: string): Messag
}

/**
* Signs a message using a private key. The resulting signature along with the
* original message can be verified using {@link verifyMessageSignatureRsv}
* Signs a message hash using a private key. The resulting signature along with
* the original message can be verified using {@link verifyMessageSignatureRsv}
* @returns A recoverable signature (in RSV order)
*/
export function signMessageHashRsv({
Expand Down
9 changes: 2 additions & 7 deletions packages/transactions/src/pc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@ import {
} from './builders';
import { ClarityValue } from './clarity';
import { FungibleConditionCode, NonFungibleConditionCode } from './constants';
import {
AddressString,
AssetString,
ContractIdString,
createAsset,
NonFungiblePostCondition,
} from './postcondition-types';
import { createAsset, NonFungiblePostCondition } from './postcondition-types';
import { AddressString, AssetString, ContractIdString } from './types';

/// `Pc.` Post Condition Builder
//
Expand Down
16 changes: 1 addition & 15 deletions packages/transactions/src/postcondition-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,7 @@ import { c32addressDecode } from 'c32check';
import { Address } from './common';
import { ClarityValue } from './clarity';
import { exceedsMaxLengthBytes } from './utils';

/**
* An address string encoded as c32check
*/
export type AddressString = string;

/**
* A contract identifier string given as `<address>.<contract-name>`
*/
export type ContractIdString = `${string}.${string}`;

/**
* An asset name string given as `<contract-id>::<token-name>` aka `<contract-address>.<contract-name>::<token-name>`
*/
export type AssetString = `${ContractIdString}::${string}`;
import { AssetString } from './types';

export interface StandardPrincipal {
readonly type: StacksMessageType.Principal;
Expand Down
2 changes: 1 addition & 1 deletion packages/transactions/src/postcondition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import {
} from './constants';
import {
Asset,
AssetString,
FungiblePostCondition,
NonFungiblePostCondition,
PostConditionPrincipal,
STXPostCondition,
parseAssetString,
parsePrincipalString,
} from './postcondition-types';
import { AssetString } from './types';

export function createSTXPostCondition(
principal: string | PostConditionPrincipal,
Expand Down
15 changes: 15 additions & 0 deletions packages/transactions/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ import {
rightPadHexToLength,
} from './utils';

/**
* An address string encoded as c32check
*/
export type AddressString = string;

/**
* A contract identifier string given as `<address>.<contract-name>`
*/
export type ContractIdString = `${string}.${string}`;

/**
* An asset name string given as `<contract-id>::<token-name>` aka `<contract-address>.<contract-name>::<token-name>`
*/
export type AssetString = `${ContractIdString}::${string}`;

export type StacksMessage =
| Address
| PostConditionPrincipal
Expand Down

0 comments on commit 3c6bc99

Please sign in to comment.