From 3c6bc99fedbb4686f8642f4e2fc24b86303a54c7 Mon Sep 17 00:00:00 2001 From: janniks Date: Thu, 30 May 2024 10:32:57 -0600 Subject: [PATCH] refactor: move types --- packages/transactions/src/builders.ts | 3 +-- packages/transactions/src/cl.ts | 1 - packages/transactions/src/keys.ts | 4 ++-- packages/transactions/src/pc.ts | 9 ++------- packages/transactions/src/postcondition-types.ts | 16 +--------------- packages/transactions/src/postcondition.ts | 2 +- packages/transactions/src/types.ts | 15 +++++++++++++++ 7 files changed, 22 insertions(+), 28 deletions(-) diff --git a/packages/transactions/src/builders.ts b/packages/transactions/src/builders.ts index 73f9a1a1b..96ebdc0e5 100644 --- a/packages/transactions/src/builders.ts +++ b/packages/transactions/src/builders.ts @@ -41,7 +41,6 @@ import { } from './postcondition'; import { Asset, - AssetString, FungiblePostCondition, NonFungiblePostCondition, PostCondition, @@ -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 { diff --git a/packages/transactions/src/cl.ts b/packages/transactions/src/cl.ts index 1e320f566..d35ff5f45 100644 --- a/packages/transactions/src/cl.ts +++ b/packages/transactions/src/cl.ts @@ -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 /////////////////////////////////////////////////////////////////// /** diff --git a/packages/transactions/src/keys.ts b/packages/transactions/src/keys.ts index 48b4d38a0..b87838144 100644 --- a/packages/transactions/src/keys.ts +++ b/packages/transactions/src/keys.ts @@ -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({ diff --git a/packages/transactions/src/pc.ts b/packages/transactions/src/pc.ts index 1cef9969d..ba6425026 100644 --- a/packages/transactions/src/pc.ts +++ b/packages/transactions/src/pc.ts @@ -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 // diff --git a/packages/transactions/src/postcondition-types.ts b/packages/transactions/src/postcondition-types.ts index bc994df5e..aae8f02fc 100644 --- a/packages/transactions/src/postcondition-types.ts +++ b/packages/transactions/src/postcondition-types.ts @@ -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 `
.` - */ -export type ContractIdString = `${string}.${string}`; - -/** - * An asset name string given as `::` aka `.::` - */ -export type AssetString = `${ContractIdString}::${string}`; +import { AssetString } from './types'; export interface StandardPrincipal { readonly type: StacksMessageType.Principal; diff --git a/packages/transactions/src/postcondition.ts b/packages/transactions/src/postcondition.ts index d38fdf33a..4c4675666 100644 --- a/packages/transactions/src/postcondition.ts +++ b/packages/transactions/src/postcondition.ts @@ -8,7 +8,6 @@ import { } from './constants'; import { Asset, - AssetString, FungiblePostCondition, NonFungiblePostCondition, PostConditionPrincipal, @@ -16,6 +15,7 @@ import { parseAssetString, parsePrincipalString, } from './postcondition-types'; +import { AssetString } from './types'; export function createSTXPostCondition( principal: string | PostConditionPrincipal, diff --git a/packages/transactions/src/types.ts b/packages/transactions/src/types.ts index ced488a1a..4250f494d 100644 --- a/packages/transactions/src/types.ts +++ b/packages/transactions/src/types.ts @@ -61,6 +61,21 @@ import { rightPadHexToLength, } from './utils'; +/** + * An address string encoded as c32check + */ +export type AddressString = string; + +/** + * A contract identifier string given as `
.` + */ +export type ContractIdString = `${string}.${string}`; + +/** + * An asset name string given as `::` aka `.::` + */ +export type AssetString = `${ContractIdString}::${string}`; + export type StacksMessage = | Address | PostConditionPrincipal