@leather.io/stacks 1.7.1 → 1.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,9 +1,11 @@
1
+ import * as _stacks_common from '@stacks/common';
1
2
  import { PrivateKey } from '@stacks/common';
2
3
  import * as _stacks_transactions from '@stacks/transactions';
3
4
  import { ClarityValue, StacksTransactionWire, AssetString, UnsignedContractCallOptions, UnsignedContractDeployOptions, UnsignedTokenTransferOptions, PostConditionWire, PostCondition } from '@stacks/transactions';
4
5
  import { Signer } from '@leather.io/crypto';
5
6
  import { NetworkModes, ReplaceTypes, Money, TransactionErrorKey, ChainId as ChainId$1 } from '@leather.io/models';
6
7
  import { HDKey } from '@scure/bip32';
8
+ import * as _stacks_network from '@stacks/network';
7
9
  import { ChainId } from '@stacks/network';
8
10
  import BigNumber from 'bignumber.js';
9
11
 
@@ -125,9 +127,48 @@ type StacksUnsignedTokenTransferOptions = ReplaceTypes<UnsignedTokenTransferOpti
125
127
  type StacksUnsignedTransactionOptions = StacksUnsignedContractCallOptions | StacksUnsignedContractDeployOptions | StacksUnsignedTokenTransferOptions;
126
128
 
127
129
  declare function initNonce(nonce: number | string): BigNumber;
128
- declare function generateUnsignedContractCall(options: StacksUnsignedContractCallOptions): Promise<_stacks_transactions.StacksTransactionWire>;
129
- declare function generateUnsignedContractDeploy(options: StacksUnsignedContractDeployOptions): Promise<_stacks_transactions.StacksTransactionWire>;
130
- declare function generateUnsignedStxTokenTransfer(options: StacksUnsignedTokenTransferOptions): Promise<_stacks_transactions.StacksTransactionWire>;
130
+ declare function getUnsignedContractCallParsedOptions(options: StacksUnsignedContractCallOptions): {
131
+ fee: string;
132
+ functionArgs: _stacks_transactions.ClarityValue[];
133
+ nonce: string;
134
+ postConditions: (string | _stacks_transactions.PostConditionWire | _stacks_transactions.PostCondition)[] | undefined;
135
+ contractAddress: string;
136
+ contractName: string;
137
+ network?: (_stacks_network.StacksNetworkName | _stacks_network.StacksNetwork) | undefined;
138
+ publicKey: _stacks_common.PrivateKey;
139
+ functionName: string;
140
+ postConditionMode?: (_stacks_transactions.PostConditionModeName | _stacks_transactions.PostConditionMode) | undefined;
141
+ validateWithAbi?: (boolean | _stacks_transactions.ClarityAbi) | undefined;
142
+ sponsored?: boolean | undefined;
143
+ client?: _stacks_common.ClientOpts | undefined;
144
+ txType: TransactionTypes.ContractCall;
145
+ };
146
+ declare function getUnsignedContractDeployParsedOptions(options: StacksUnsignedContractDeployOptions): {
147
+ fee: string;
148
+ nonce: string;
149
+ postConditions: _stacks_transactions.PostConditionWire[] | undefined;
150
+ contractName: string;
151
+ network?: (_stacks_network.StacksNetworkName | _stacks_network.StacksNetwork) | undefined;
152
+ publicKey: _stacks_common.PublicKey;
153
+ postConditionMode?: (_stacks_transactions.PostConditionModeName | _stacks_transactions.PostConditionMode) | undefined;
154
+ sponsored?: boolean | undefined;
155
+ client?: _stacks_common.ClientOpts | undefined;
156
+ clarityVersion?: _stacks_transactions.ClarityVersion | undefined;
157
+ codeBody: string;
158
+ txType: TransactionTypes.ContractDeploy;
159
+ };
160
+ declare function getUnsignedStxTokenTransferParsedOptions(options: StacksUnsignedTokenTransferOptions): {
161
+ amount: string;
162
+ fee: string;
163
+ nonce: string;
164
+ network?: (_stacks_network.StacksNetworkName | _stacks_network.StacksNetwork) | undefined;
165
+ publicKey: _stacks_common.PublicKey;
166
+ sponsored?: boolean | undefined;
167
+ client?: _stacks_common.ClientOpts | undefined;
168
+ recipient: string | _stacks_transactions.PrincipalCV;
169
+ memo?: string | undefined;
170
+ txType: TransactionTypes.StxTokenTransfer;
171
+ };
131
172
  declare function generateStacksUnsignedTransaction(options: StacksUnsignedTransactionOptions): Promise<_stacks_transactions.StacksTransactionWire>;
132
173
 
133
174
  declare function getPostConditionFromString(postCondition: string): PostConditionWire;
@@ -155,4 +196,4 @@ interface StacksTransaction {
155
196
  }
156
197
  declare function isValidStacksTransaction({ amount, availableBalance, fee, payer, recipient, chainId, }: StacksTransaction): boolean;
157
198
 
158
- export { StacksError, type StacksErrorKey, type StacksSigner, type StacksSignerFn, type StacksUnsignedContractCallOptions, type StacksUnsignedContractDeployOptions, type StacksUnsignedTokenTransferOptions, type StacksUnsignedTransactionOptions, TEST_ACCOUNT_1_STX_ADDRESS, TEST_ACCOUNT_1_STX_ADDRESS_SM, TEST_ACCOUNT_2_STX_ADDRESS, TEST_TESTNET_ACCOUNT_2_STX_ADDRESS, TEST_TESTNET_ACCOUNT_2_STX_ADDRESS_SN, TransactionTypes, cleanHex, createSignFnFromMnemonic, deriveStxPrivateKey, deriveStxPublicKey, ensurePostConditionWireFormat, extractStacksDerivationPathAccountIndex, formatAssetString, formatContractId, generateStacksUnsignedTransaction, generateUnsignedContractCall, generateUnsignedContractDeploy, generateUnsignedStxTokenTransfer, getPostCondition, getPostConditionFromString, getPostConditions, getPrincipalFromAssetString, getStacksAssetStringParts, getStacksBurnAddress, getStacksContractAssetName, getStacksContractName, initNonce, initalizeStacksSigner, isTransactionTypeSupported, isValidAddressChain, isValidStacksAddress, isValidStacksTransaction, makeAccountIndexDerivationPathFactory, makeStxDerivationPath, signMessage, signStacksTransaction, signStructuredDataMessage, stacksChainIdToCoreNetworkMode, stacksRootKeychainToAccountDescriptor, stxDerivationWithAccount, validatePayerNotRecipient, whenStacksChainId };
199
+ export { StacksError, type StacksErrorKey, type StacksSigner, type StacksSignerFn, type StacksUnsignedContractCallOptions, type StacksUnsignedContractDeployOptions, type StacksUnsignedTokenTransferOptions, type StacksUnsignedTransactionOptions, TEST_ACCOUNT_1_STX_ADDRESS, TEST_ACCOUNT_1_STX_ADDRESS_SM, TEST_ACCOUNT_2_STX_ADDRESS, TEST_TESTNET_ACCOUNT_2_STX_ADDRESS, TEST_TESTNET_ACCOUNT_2_STX_ADDRESS_SN, TransactionTypes, cleanHex, createSignFnFromMnemonic, deriveStxPrivateKey, deriveStxPublicKey, ensurePostConditionWireFormat, extractStacksDerivationPathAccountIndex, formatAssetString, formatContractId, generateStacksUnsignedTransaction, getPostCondition, getPostConditionFromString, getPostConditions, getPrincipalFromAssetString, getStacksAssetStringParts, getStacksBurnAddress, getStacksContractAssetName, getStacksContractName, getUnsignedContractCallParsedOptions, getUnsignedContractDeployParsedOptions, getUnsignedStxTokenTransferParsedOptions, initNonce, initalizeStacksSigner, isTransactionTypeSupported, isValidAddressChain, isValidStacksAddress, isValidStacksTransaction, makeAccountIndexDerivationPathFactory, makeStxDerivationPath, signMessage, signStacksTransaction, signStructuredDataMessage, stacksChainIdToCoreNetworkMode, stacksRootKeychainToAccountDescriptor, stxDerivationWithAccount, validatePayerNotRecipient, whenStacksChainId };
package/dist/index.js CHANGED
@@ -235,46 +235,44 @@ function isTransactionTypeSupported(txType) {
235
235
  function initNonce(nonce) {
236
236
  return new BigNumber(nonce, 10);
237
237
  }
238
- function generateUnsignedContractCall(options) {
239
- const { fee, functionArgs, nonce, postConditions } = options;
240
- const fnArgs = functionArgs.map((arg) => deserializeCV(hexToBytes2(cleanHex(arg))));
241
- const parsedOptions = {
242
- fee: fee.amount.toString(),
243
- functionArgs: fnArgs,
244
- nonce: initNonce(nonce).toString(),
245
- postConditions
238
+ function getUnsignedContractCallParsedOptions(options) {
239
+ return {
240
+ ...options,
241
+ fee: options.fee.amount.toString(),
242
+ functionArgs: options.functionArgs.map((arg) => deserializeCV(hexToBytes2(cleanHex(arg)))),
243
+ nonce: initNonce(options.nonce).toString(),
244
+ postConditions: options.postConditions
246
245
  };
247
- return makeUnsignedContractCall({ ...options, ...parsedOptions });
248
- }
249
- function generateUnsignedContractDeploy(options) {
250
- const { fee, nonce, postConditions } = options;
251
- const parsedOptions = {
252
- fee: fee.amount.toString(),
253
- nonce: initNonce(nonce).toString(),
254
- postConditions: getPostConditions(postConditions?.map((pc) => ensurePostConditionWireFormat(pc)))
246
+ }
247
+ function getUnsignedContractDeployParsedOptions(options) {
248
+ return {
249
+ ...options,
250
+ fee: options.fee.amount.toString(),
251
+ nonce: initNonce(options.nonce).toString(),
252
+ postConditions: getPostConditions(
253
+ options.postConditions?.map((pc) => ensurePostConditionWireFormat(pc))
254
+ )
255
255
  };
256
- return makeUnsignedContractDeploy({ ...options, ...parsedOptions });
257
- }
258
- function generateUnsignedStxTokenTransfer(options) {
259
- const { amount, fee, nonce } = options;
260
- const parsedOptions = {
261
- amount: amount.amount.toString(),
262
- fee: fee.amount.toString(),
263
- nonce: initNonce(nonce).toString()
256
+ }
257
+ function getUnsignedStxTokenTransferParsedOptions(options) {
258
+ return {
259
+ ...options,
260
+ amount: options.amount.amount.toString(),
261
+ fee: options.fee.amount.toString(),
262
+ nonce: initNonce(options.nonce).toString()
264
263
  };
265
- return makeUnsignedSTXTokenTransfer({ ...options, ...parsedOptions });
266
264
  }
267
- async function generateStacksUnsignedTransaction(options) {
265
+ function generateStacksUnsignedTransaction(options) {
268
266
  const { txType } = options;
269
267
  const isValid = isTransactionTypeSupported(txType);
270
268
  if (!isValid) throw new Error(`Invalid Transaction Type: ${txType}`);
271
269
  switch (txType) {
272
270
  case "token_transfer" /* StxTokenTransfer */:
273
- return generateUnsignedStxTokenTransfer(options);
271
+ return makeUnsignedSTXTokenTransfer(getUnsignedStxTokenTransferParsedOptions(options));
274
272
  case "contract_call" /* ContractCall */:
275
- return generateUnsignedContractCall(options);
273
+ return makeUnsignedContractCall(getUnsignedContractCallParsedOptions(options));
276
274
  case "smart_contract" /* ContractDeploy */:
277
- return generateUnsignedContractDeploy(options);
275
+ return makeUnsignedContractDeploy(getUnsignedContractDeployParsedOptions(options));
278
276
  default:
279
277
  assertUnreachable(txType);
280
278
  }
@@ -409,9 +407,6 @@ export {
409
407
  formatAssetString,
410
408
  formatContractId,
411
409
  generateStacksUnsignedTransaction,
412
- generateUnsignedContractCall,
413
- generateUnsignedContractDeploy,
414
- generateUnsignedStxTokenTransfer,
415
410
  getPostCondition,
416
411
  getPostConditionFromString,
417
412
  getPostConditions,
@@ -420,6 +415,9 @@ export {
420
415
  getStacksBurnAddress,
421
416
  getStacksContractAssetName,
422
417
  getStacksContractName,
418
+ getUnsignedContractCallParsedOptions,
419
+ getUnsignedContractDeployParsedOptions,
420
+ getUnsignedStxTokenTransferParsedOptions,
423
421
  initNonce,
424
422
  initalizeStacksSigner,
425
423
  isTransactionTypeSupported,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/message-signing.ts","../src/mocks/mocks.ts","../src/signer/signer.ts","../src/stacks.utils.ts","../src/transactions/generate-unsigned-transaction.ts","../src/transactions/post-condition.utils.ts","../src/transactions/transaction.types.ts","../src/validation/stacks-error.ts","../src/validation/address-validation.ts","../src/validation/amount-validation.ts","../src/validation/transaction-validation.ts"],"sourcesContent":["import { bytesToHex } from '@noble/hashes/utils';\nimport { PrivateKey } from '@stacks/common';\nimport { hashMessage } from '@stacks/encryption';\nimport {\n ClarityValue,\n privateKeyToPublic,\n signMessageHashRsv,\n signStructuredData,\n} from '@stacks/transactions';\n\ninterface SignatureData {\n signature: string;\n publicKey: string;\n}\nexport function signMessage(message: string, privateKey: PrivateKey): SignatureData {\n const hash = hashMessage(message);\n return {\n signature: signMessageHashRsv({ privateKey, messageHash: bytesToHex(hash) }),\n publicKey: privateKeyToPublic(privateKey) as string,\n };\n}\n\nexport function signStructuredDataMessage(\n message: ClarityValue,\n domain: ClarityValue,\n privateKey: PrivateKey\n): SignatureData {\n const signature = signStructuredData({\n message,\n domain,\n privateKey,\n });\n\n return {\n signature,\n publicKey: privateKeyToPublic(privateKey) as string,\n };\n}\n","// Stacks test addresses\nexport const TEST_ACCOUNT_1_STX_ADDRESS = 'SPS8CKF63P16J28AYF7PXW9E5AACH0NZNTEFWSFE';\nexport const TEST_ACCOUNT_2_STX_ADDRESS = 'SPXH3HNBPM5YP15VH16ZXZ9AX6CK289K3MCXRKCB';\nexport const TEST_TESTNET_ACCOUNT_2_STX_ADDRESS = 'STXH3HNBPM5YP15VH16ZXZ9AX6CK289K3NVR9T1P';\n// TODO ask about these prefixs\n// TEST_ACCOUNT_.. from extension mocks with prefix changed to SM / SN\nexport const TEST_ACCOUNT_1_STX_ADDRESS_SM = 'SM3FBR6RDNZYC5K4TZWV9VZJ6NGA4VX3YBQ8X2PQ';\nexport const TEST_TESTNET_ACCOUNT_2_STX_ADDRESS_SN = 'SNXH3HNBPM5YP15VH16ZXZ9AX6CK289K3NVR9T1P';\n","import {\n StacksTransactionWire,\n TransactionSigner,\n createStacksPublicKey,\n publicKeyToAddressSingleSig,\n} from '@stacks/transactions';\n\nimport {\n Signer,\n decomposeDescriptor,\n deriveRootKeychainFromMnemonic,\n extractKeyFromDescriptor,\n} from '@leather.io/crypto';\nimport { NetworkModes } from '@leather.io/models';\n\nimport { deriveStxPrivateKey, extractStacksDerivationPathAccountIndex } from '../stacks.utils';\n\n// Warning: mutatitive. Ideally there would be a tx.clone() method\nexport function signStacksTransaction(tx: StacksTransactionWire, privateKey: string) {\n const signer = new TransactionSigner(tx);\n signer.signOrigin(privateKey);\n return tx;\n}\n\nexport type StacksSignerFn = (tx: StacksTransactionWire) => Promise<StacksTransactionWire>;\n\nexport interface StacksSigner extends Signer {\n descriptor: string;\n keyOrigin: string;\n address: string;\n accountIndex: number;\n network: NetworkModes;\n sign: StacksSignerFn;\n}\n\nexport function createSignFnFromMnemonic(\n keyOrigin: string,\n getMnemonicFn: () => Promise<{ mnemonic: string; passphrase?: string }>\n) {\n return async (tx: StacksTransactionWire) => {\n const { mnemonic, passphrase } = await getMnemonicFn();\n const keychain = await deriveRootKeychainFromMnemonic(mnemonic, passphrase);\n const privateKey = deriveStxPrivateKey({\n keychain,\n index: extractStacksDerivationPathAccountIndex(keyOrigin),\n });\n return signStacksTransaction(tx, privateKey);\n };\n}\n\ninterface InitalizeStacksSignerArgs {\n descriptor: string;\n network: NetworkModes;\n signFn: StacksSignerFn;\n}\nexport function initalizeStacksSigner(args: InitalizeStacksSignerArgs): StacksSigner {\n const { descriptor, network, signFn } = args;\n\n const publicKey = createStacksPublicKey(extractKeyFromDescriptor(descriptor)).data;\n\n return {\n ...decomposeDescriptor(descriptor),\n // here we overwrite the accountIndex with the derivation path account index for stx\n accountIndex: extractStacksDerivationPathAccountIndex(descriptor),\n publicKey: publicKey,\n network,\n address: publicKeyToAddressSingleSig(publicKey, network),\n sign: signFn,\n };\n}\n","import { HDKey } from '@scure/bip32';\nimport { ChainId } from '@stacks/network';\nimport { AssetString, compressPrivateKey, privateKeyToPublic } from '@stacks/transactions';\n\nimport {\n DerivationPathDepth,\n createDescriptor,\n createKeyOriginPath,\n extractAddressIndexFromPath,\n} from '@leather.io/crypto';\nimport type { NetworkModes } from '@leather.io/models';\nimport { assertIsTruthy, isString, toHexString } from '@leather.io/utils';\n\nexport const stxDerivationWithAccount = `m/44'/5757'/0'/0/{account}`;\n\nexport function makeAccountIndexDerivationPathFactory(derivationPath: string) {\n return (account: number) => derivationPath.replace('{account}', account.toString());\n}\n\nexport function extractStacksDerivationPathAccountIndex(path: string) {\n if (!path.includes('5757')) throw new Error('Not a valid Stacks derivation path: ' + path);\n return extractAddressIndexFromPath(path);\n}\n\n/**\n * Stacks accounts always use the same derivation path, regardless of network\n */\nexport const makeStxDerivationPath =\n makeAccountIndexDerivationPathFactory(stxDerivationWithAccount);\n\nexport function stacksChainIdToCoreNetworkMode(chainId: ChainId): NetworkModes {\n return whenStacksChainId(chainId)({\n [ChainId.Mainnet]: 'mainnet',\n [ChainId.Testnet]: 'testnet',\n });\n}\n\ninterface WhenStacksChainIdMap<T> {\n [ChainId.Mainnet]: T;\n [ChainId.Testnet]: T;\n}\nexport function whenStacksChainId(chainId: ChainId) {\n return <T>(chainIdMap: WhenStacksChainIdMap<T>): T => chainIdMap[chainId];\n}\n\n// From `@stacks/wallet-sdk` package we are trying not to use\nexport function deriveStxPrivateKey({ keychain, index }: { keychain: HDKey; index: number }) {\n if (keychain.depth !== DerivationPathDepth.Root) throw new Error('Root keychain must be depth 0');\n const accountKeychain = keychain.derive(makeStxDerivationPath(index));\n assertIsTruthy(accountKeychain.privateKey);\n return compressPrivateKey(accountKeychain.privateKey);\n}\n\nexport function deriveStxPublicKey({\n keychain,\n index,\n}: {\n keychain: HDKey;\n index: number;\n}): string {\n return privateKeyToPublic(deriveStxPrivateKey({ keychain, index })) as string;\n}\n\nexport function stacksRootKeychainToAccountDescriptor(keychain: HDKey, accountIndex: number) {\n const fingerprint = toHexString(keychain.fingerprint);\n const publicKey = deriveStxPublicKey({ keychain, index: accountIndex });\n return createDescriptor(\n createKeyOriginPath(fingerprint, makeStxDerivationPath(accountIndex)),\n publicKey\n );\n}\n\nexport function getStacksBurnAddress(chainIdChainId: ChainId): string {\n switch (chainIdChainId) {\n case ChainId.Mainnet:\n return 'SP00000000000003SCNSJTCSE62ZF4MSE';\n case ChainId.Testnet:\n default:\n return 'ST000000000000000000002AMW42H';\n }\n}\n\nexport function cleanHex(hexWithMaybePrefix: string): string {\n if (!isString(hexWithMaybePrefix)) return hexWithMaybePrefix;\n return hexWithMaybePrefix.startsWith('0x')\n ? hexWithMaybePrefix.replace('0x', '')\n : hexWithMaybePrefix;\n}\n\nexport function getPrincipalFromAssetString(assetString: string) {\n return assetString.split('::')[0];\n}\n\nexport function formatContractId(address: string, name: string) {\n return `${address}.${name}`;\n}\n\ninterface FormatAssetStringArgs {\n contractAddress: string;\n contractName: string;\n assetName: string;\n}\nexport function formatAssetString({\n contractAddress,\n contractName,\n assetName,\n}: FormatAssetStringArgs): AssetString {\n return `${contractAddress}.${contractName}::${assetName}`;\n}\n\n/**\n * Gets the contract name.\n *\n * @param identifier - [principal].[contract-name] or [principal].[contract-name]::[asset-name]\n */\nexport function getStacksContractName(identifier: string): string {\n if (identifier.includes('.')) {\n const parts = identifier?.split('.');\n if (identifier.includes('::')) {\n return parts[1].split('::')[0];\n }\n return parts[1];\n }\n return identifier;\n}\n\n/**\n * Gets the asset name.\n *\n * @param identifier - [principal].[contract-name]::[asset-name]\n */\nexport function getStacksContractAssetName(identifier: string): string {\n if (!identifier.includes('::')) return identifier;\n return identifier.split('::')[1];\n}\n\n/**\n * Gets the parts that make up a fully qualified name of an asset.\n *\n * @param identifier - [principal].[contract-name]::[asset-name]\n */\nexport function getStacksAssetStringParts(identifier: string): {\n contractAddress: string;\n contractAssetName: string;\n contractName: string;\n} {\n if (!identifier.includes('.') || !identifier.includes('::')) {\n return {\n contractAddress: identifier,\n contractAssetName: identifier,\n contractName: identifier,\n };\n }\n\n const contractAddress = identifier.split('.')[0];\n const contractAssetName = getStacksContractAssetName(identifier);\n const contractName = getStacksContractName(identifier);\n\n return {\n contractAddress,\n contractAssetName,\n contractName,\n };\n}\n","import { hexToBytes } from '@noble/hashes/utils';\nimport {\n deserializeCV,\n makeUnsignedContractCall,\n makeUnsignedContractDeploy,\n makeUnsignedSTXTokenTransfer,\n} from '@stacks/transactions';\nimport BigNumber from 'bignumber.js';\n\nimport { assertUnreachable } from '@leather.io/utils';\n\nimport { cleanHex } from '../stacks.utils';\nimport { ensurePostConditionWireFormat, getPostConditions } from './post-condition.utils';\nimport {\n StacksUnsignedContractCallOptions,\n StacksUnsignedContractDeployOptions,\n StacksUnsignedTokenTransferOptions,\n StacksUnsignedTransactionOptions,\n TransactionTypes,\n isTransactionTypeSupported,\n} from './transaction.types';\n\nexport function initNonce(nonce: number | string) {\n return new BigNumber(nonce, 10);\n}\n\nexport function generateUnsignedContractCall(options: StacksUnsignedContractCallOptions) {\n const { fee, functionArgs, nonce, postConditions } = options;\n\n const fnArgs = functionArgs.map(arg => deserializeCV(hexToBytes(cleanHex(arg))));\n\n const parsedOptions = {\n fee: fee.amount.toString(),\n functionArgs: fnArgs,\n nonce: initNonce(nonce).toString(),\n postConditions,\n };\n\n return makeUnsignedContractCall({ ...options, ...parsedOptions });\n}\n\nexport function generateUnsignedContractDeploy(options: StacksUnsignedContractDeployOptions) {\n const { fee, nonce, postConditions } = options;\n\n const parsedOptions = {\n fee: fee.amount.toString(),\n nonce: initNonce(nonce).toString(),\n postConditions: getPostConditions(postConditions?.map(pc => ensurePostConditionWireFormat(pc))),\n };\n\n return makeUnsignedContractDeploy({ ...options, ...parsedOptions });\n}\n\nexport function generateUnsignedStxTokenTransfer(options: StacksUnsignedTokenTransferOptions) {\n const { amount, fee, nonce } = options;\n\n const parsedOptions = {\n amount: amount.amount.toString(),\n fee: fee.amount.toString(),\n nonce: initNonce(nonce).toString(),\n };\n\n return makeUnsignedSTXTokenTransfer({ ...options, ...parsedOptions });\n}\n\nexport async function generateStacksUnsignedTransaction(options: StacksUnsignedTransactionOptions) {\n const { txType } = options;\n\n const isValid = isTransactionTypeSupported(txType);\n\n if (!isValid) throw new Error(`Invalid Transaction Type: ${txType}`);\n\n switch (txType) {\n case TransactionTypes.StxTokenTransfer:\n return generateUnsignedStxTokenTransfer(options);\n case TransactionTypes.ContractCall:\n return generateUnsignedContractCall(options);\n case TransactionTypes.ContractDeploy:\n return generateUnsignedContractDeploy(options);\n default:\n assertUnreachable(txType);\n }\n}\n","import { hexToBytes } from '@noble/hashes/utils';\nimport {\n BytesReader,\n PostCondition,\n PostConditionWire,\n deserializePostConditionWire,\n postConditionToWire,\n} from '@stacks/transactions';\n\nimport { isString } from '@leather.io/utils';\n\nexport function getPostConditionFromString(postCondition: string): PostConditionWire {\n try {\n const reader = new BytesReader(hexToBytes(postCondition));\n return deserializePostConditionWire(reader);\n } catch {\n throw new Error('Not a serialized post condition');\n }\n}\n\nexport function ensurePostConditionWireFormat(\n postCondition: string | PostCondition | PostConditionWire\n) {\n if (isString(postCondition)) return getPostConditionFromString(postCondition);\n if ('conditionType' in postCondition) return postCondition;\n return postConditionToWire(postCondition);\n}\n\nexport function getPostCondition(\n postCondition: string | PostCondition | PostConditionWire\n): PostConditionWire {\n return isString(postCondition)\n ? getPostConditionFromString(postCondition)\n : ensurePostConditionWireFormat(postCondition);\n}\n\nexport function getPostConditions(\n postConditions?: (string | PostCondition | PostConditionWire)[]\n): PostConditionWire[] | undefined {\n return postConditions?.map(getPostCondition);\n}\n","import {\n UnsignedContractCallOptions,\n UnsignedContractDeployOptions,\n UnsignedTokenTransferOptions,\n} from '@stacks/transactions';\n\nimport { Money, ReplaceTypes } from '@leather.io/models';\n\nexport enum TransactionTypes {\n ContractCall = 'contract_call',\n ContractDeploy = 'smart_contract',\n StxTokenTransfer = 'token_transfer',\n}\n\nexport function isTransactionTypeSupported(txType: TransactionTypes) {\n return (\n txType === TransactionTypes.ContractCall ||\n txType === TransactionTypes.ContractDeploy ||\n txType === TransactionTypes.StxTokenTransfer\n );\n}\n\nexport type StacksUnsignedContractCallOptions = ReplaceTypes<\n UnsignedContractCallOptions,\n {\n fee: Money;\n functionArgs: string[];\n nonce: number | string;\n }\n> & { txType: TransactionTypes.ContractCall };\n\nexport type StacksUnsignedContractDeployOptions = ReplaceTypes<\n UnsignedContractDeployOptions,\n {\n fee: Money;\n nonce: number | string;\n }\n> & { txType: TransactionTypes.ContractDeploy };\n\nexport type StacksUnsignedTokenTransferOptions = ReplaceTypes<\n UnsignedTokenTransferOptions,\n {\n amount: Money;\n fee: Money;\n nonce: number | string;\n }\n> & { txType: TransactionTypes.StxTokenTransfer };\n\nexport type StacksUnsignedTransactionOptions =\n | StacksUnsignedContractCallOptions\n | StacksUnsignedContractDeployOptions\n | StacksUnsignedTokenTransferOptions;\n","import { TransactionErrorKey } from '@leather.io/models';\n\nexport type StacksErrorKey =\n | TransactionErrorKey\n | 'InvalidSameAddress'\n | 'UnknownBalance'\n | 'UnknownFee'\n | 'UnknownAmount';\n\nexport class StacksError extends Error {\n public message: StacksErrorKey;\n constructor(message: StacksErrorKey) {\n super(message);\n this.name = 'StacksError';\n this.message = message;\n\n // Fix the prototype chain\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n","import { c32addressDecode } from 'c32check';\n\nimport { ChainId } from '@leather.io/models';\nimport { isEmptyString, isUndefined } from '@leather.io/utils';\n\n// taken from stacks-utils.ts\nexport function isValidStacksAddress(address: string) {\n if (isUndefined(address) || isEmptyString(address)) {\n return false;\n }\n try {\n c32addressDecode(address);\n return true;\n } catch {\n return false;\n }\n}\n\nexport function isValidAddressChain(address: string, chainId: ChainId) {\n if (!isValidStacksAddress(address)) {\n return false;\n }\n\n const prefix = address.slice(0, 2);\n switch (chainId) {\n case ChainId.Mainnet:\n return prefix === 'SM' || prefix === 'SP';\n case ChainId.Testnet:\n return prefix === 'SN' || prefix === 'ST';\n default:\n return false;\n }\n}\n\nexport function validatePayerNotRecipient(senderAddress: string, recipientAddress: string) {\n if (!isValidStacksAddress(senderAddress) || !isValidStacksAddress(recipientAddress)) {\n return false;\n }\n if (senderAddress === recipientAddress) {\n return false;\n }\n return true;\n}\n","import BigNumber from 'bignumber.js';\n\nimport { Money } from '@leather.io/models';\nimport { isDefined, stxToMicroStx } from '@leather.io/utils';\n\nimport { StacksError } from './stacks-error';\n\nfunction isMoneyAmountValid(amount: Money) {\n return amount && isDefined(amount.amount) && amount.amount;\n}\n\ninterface IsStxAmountValidArgs {\n availableBalance: Money;\n amount: Money;\n fee: Money;\n}\n\nexport function isStxAmountValid({ availableBalance, amount, fee }: IsStxAmountValidArgs) {\n if (!isMoneyAmountValid(amount)) {\n throw new StacksError('InvalidAmount');\n }\n if (!isMoneyAmountValid(availableBalance)) {\n throw new StacksError('UnknownBalance');\n }\n if (!isMoneyAmountValid(fee)) {\n throw new StacksError('UnknownFee');\n }\n return true;\n}\n\nexport function isStxBalanceSufficient({\n availableBalance: { amount: availableBalanceAmount },\n amount: { amount: desiredSpend },\n fee: { amount: feeAmount },\n}: IsStxAmountValidArgs) {\n const fee = new BigNumber(stxToMicroStx(feeAmount));\n\n if (!availableBalanceAmount) {\n throw new StacksError('UnknownBalance');\n }\n if (!fee.isFinite()) {\n throw new StacksError('UnknownFee');\n }\n\n const availableBalance = new BigNumber(stxToMicroStx(availableBalanceAmount));\n const spendableAmount = availableBalance.minus(fee);\n const amount = new BigNumber(stxToMicroStx(desiredSpend));\n return spendableAmount.isGreaterThanOrEqualTo(amount);\n}\n","import { ChainId, Money } from '@leather.io/models';\n\nimport {\n isValidAddressChain,\n isValidStacksAddress,\n validatePayerNotRecipient,\n} from './address-validation';\nimport { isStxAmountValid, isStxBalanceSufficient } from './amount-validation';\nimport { StacksError } from './stacks-error';\n\ninterface StacksTransaction {\n amount: Money;\n payer: string;\n recipient: string;\n chainId: ChainId;\n availableBalance: Money;\n fee: Money;\n}\n\nexport function isValidStacksTransaction({\n amount,\n availableBalance,\n fee,\n payer,\n recipient,\n chainId,\n}: StacksTransaction) {\n if (!isValidStacksAddress(payer) || !isValidStacksAddress(recipient)) {\n throw new StacksError('InvalidAddress');\n }\n if (!isValidAddressChain(payer, chainId) || !isValidAddressChain(recipient, chainId)) {\n throw new StacksError('InvalidNetworkAddress');\n }\n if (!validatePayerNotRecipient(payer, recipient)) {\n throw new StacksError('InvalidSameAddress');\n }\n\n if (!isStxAmountValid({ availableBalance, amount, fee })) {\n throw new StacksError('InvalidAmount');\n }\n if (!isStxBalanceSufficient({ availableBalance, amount, fee })) {\n throw new StacksError('InsufficientFunds');\n }\n return true;\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;AAE3B,SAAS,mBAAmB;AAC5B;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAMA,SAAS,YAAY,SAAiB,YAAuC;AAClF,QAAM,OAAO,YAAY,OAAO;AAChC,SAAO;AAAA,IACL,WAAW,mBAAmB,EAAE,YAAY,aAAa,WAAW,IAAI,EAAE,CAAC;AAAA,IAC3E,WAAW,mBAAmB,UAAU;AAAA,EAC1C;AACF;AAEO,SAAS,0BACd,SACA,QACA,YACe;AACf,QAAM,YAAY,mBAAmB;AAAA,IACnC;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL;AAAA,IACA,WAAW,mBAAmB,UAAU;AAAA,EAC1C;AACF;;;ACpCO,IAAM,6BAA6B;AACnC,IAAM,6BAA6B;AACnC,IAAM,qCAAqC;AAG3C,IAAM,gCAAgC;AACtC,IAAM,wCAAwC;;;ACPrD;AAAA,EAEE;AA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AAI,YAAY,YAAY;AAAA,EACpC;AAEA,QAAM,mBAAmB,IAAIA,WAAU,cAAc,sBAAsB,CAAC;AAC5E,QAAM,kBAAkB,iBAAiB,MAAM,GAAG;AAClD,QAAM,SAAS,IAAIA,WAAU,cAAc,YAAY,CAAC;AACxD,SAAO,gBAAgB,uBAAuB,MAAM;AACtD;;;AC7BO,SAAS,yBAAyB;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAsB;AACpB,MAAI,CAAC,qBAAqB,KAAK,KAAK,CAAC,qBAAqB,SAAS,GAAG;AACpE,UAAM,IAAI,YAAY,gBAAgB;AAAA,EACxC;AACA,MAAI,CAAC,oBAAoB,OAAO,OAAO,KAAK,CAAC,oBAAoB,WAAW,OAAO,GAAG;AACpF,UAAM,IAAI,YAAY,uBAAuB;AAAA,EAC/C;AACA,MAAI,CAAC,0BAA0B,OAAO,SAAS,GAAG;AAChD,UAAM,IAAI,YAAY,oBAAoB;AAAA,EAC5C;AAEA,MAAI,CAAC,iBAAiB,EAAE,kBAAkB,QAAQ,IAAI,CAAC,GAAG;AACxD,UAAM,IAAI,YAAY,eAAe;AAAA,EACvC;AACA,MAAI,CAAC,uBAAuB,EAAE,kBAAkB,QAAQ,IAAI,CAAC,GAAG;AAC9D,UAAM,IAAI,YAAY,mBAAmB;AAAA,EAC3C;AACA,SAAO;AACT;","names":["privateKeyToPublic","hexToBytes","isString","TransactionTypes","hexToBytes","ChainId","BigNumber","BigNumber"]}
1
+ {"version":3,"sources":["../src/message-signing.ts","../src/mocks/mocks.ts","../src/signer/signer.ts","../src/stacks.utils.ts","../src/transactions/generate-unsigned-transaction.ts","../src/transactions/post-condition.utils.ts","../src/transactions/transaction.types.ts","../src/validation/stacks-error.ts","../src/validation/address-validation.ts","../src/validation/amount-validation.ts","../src/validation/transaction-validation.ts"],"sourcesContent":["import { bytesToHex } from '@noble/hashes/utils';\nimport { PrivateKey } from '@stacks/common';\nimport { hashMessage } from '@stacks/encryption';\nimport {\n ClarityValue,\n privateKeyToPublic,\n signMessageHashRsv,\n signStructuredData,\n} from '@stacks/transactions';\n\ninterface SignatureData {\n signature: string;\n publicKey: string;\n}\nexport function signMessage(message: string, privateKey: PrivateKey): SignatureData {\n const hash = hashMessage(message);\n return {\n signature: signMessageHashRsv({ privateKey, messageHash: bytesToHex(hash) }),\n publicKey: privateKeyToPublic(privateKey) as string,\n };\n}\n\nexport function signStructuredDataMessage(\n message: ClarityValue,\n domain: ClarityValue,\n privateKey: PrivateKey\n): SignatureData {\n const signature = signStructuredData({\n message,\n domain,\n privateKey,\n });\n\n return {\n signature,\n publicKey: privateKeyToPublic(privateKey) as string,\n };\n}\n","// Stacks test addresses\nexport const TEST_ACCOUNT_1_STX_ADDRESS = 'SPS8CKF63P16J28AYF7PXW9E5AACH0NZNTEFWSFE';\nexport const TEST_ACCOUNT_2_STX_ADDRESS = 'SPXH3HNBPM5YP15VH16ZXZ9AX6CK289K3MCXRKCB';\nexport const TEST_TESTNET_ACCOUNT_2_STX_ADDRESS = 'STXH3HNBPM5YP15VH16ZXZ9AX6CK289K3NVR9T1P';\n// TODO ask about these prefixs\n// TEST_ACCOUNT_.. from extension mocks with prefix changed to SM / SN\nexport const TEST_ACCOUNT_1_STX_ADDRESS_SM = 'SM3FBR6RDNZYC5K4TZWV9VZJ6NGA4VX3YBQ8X2PQ';\nexport const TEST_TESTNET_ACCOUNT_2_STX_ADDRESS_SN = 'SNXH3HNBPM5YP15VH16ZXZ9AX6CK289K3NVR9T1P';\n","import {\n StacksTransactionWire,\n TransactionSigner,\n createStacksPublicKey,\n publicKeyToAddressSingleSig,\n} from '@stacks/transactions';\n\nimport {\n Signer,\n decomposeDescriptor,\n deriveRootKeychainFromMnemonic,\n extractKeyFromDescriptor,\n} from '@leather.io/crypto';\nimport { NetworkModes } from '@leather.io/models';\n\nimport { deriveStxPrivateKey, extractStacksDerivationPathAccountIndex } from '../stacks.utils';\n\n// Warning: mutative. Ideally there would be a tx.clone() method\nexport function signStacksTransaction(tx: StacksTransactionWire, privateKey: string) {\n const signer = new TransactionSigner(tx);\n signer.signOrigin(privateKey);\n return tx;\n}\n\nexport type StacksSignerFn = (tx: StacksTransactionWire) => Promise<StacksTransactionWire>;\n\nexport interface StacksSigner extends Signer {\n descriptor: string;\n keyOrigin: string;\n address: string;\n accountIndex: number;\n network: NetworkModes;\n sign: StacksSignerFn;\n}\n\nexport function createSignFnFromMnemonic(\n keyOrigin: string,\n getMnemonicFn: () => Promise<{ mnemonic: string; passphrase?: string }>\n) {\n return async (tx: StacksTransactionWire) => {\n const { mnemonic, passphrase } = await getMnemonicFn();\n const keychain = await deriveRootKeychainFromMnemonic(mnemonic, passphrase);\n const privateKey = deriveStxPrivateKey({\n keychain,\n index: extractStacksDerivationPathAccountIndex(keyOrigin),\n });\n return signStacksTransaction(tx, privateKey);\n };\n}\n\ninterface InitalizeStacksSignerArgs {\n descriptor: string;\n network: NetworkModes;\n signFn: StacksSignerFn;\n}\nexport function initalizeStacksSigner(args: InitalizeStacksSignerArgs): StacksSigner {\n const { descriptor, network, signFn } = args;\n\n const publicKey = createStacksPublicKey(extractKeyFromDescriptor(descriptor)).data;\n\n return {\n ...decomposeDescriptor(descriptor),\n // here we overwrite the accountIndex with the derivation path account index for stx\n accountIndex: extractStacksDerivationPathAccountIndex(descriptor),\n publicKey: publicKey,\n network,\n address: publicKeyToAddressSingleSig(publicKey, network),\n sign: signFn,\n };\n}\n","import { HDKey } from '@scure/bip32';\nimport { ChainId } from '@stacks/network';\nimport { AssetString, compressPrivateKey, privateKeyToPublic } from '@stacks/transactions';\n\nimport {\n DerivationPathDepth,\n createDescriptor,\n createKeyOriginPath,\n extractAddressIndexFromPath,\n} from '@leather.io/crypto';\nimport type { NetworkModes } from '@leather.io/models';\nimport { assertIsTruthy, isString, toHexString } from '@leather.io/utils';\n\nexport const stxDerivationWithAccount = `m/44'/5757'/0'/0/{account}`;\n\nexport function makeAccountIndexDerivationPathFactory(derivationPath: string) {\n return (account: number) => derivationPath.replace('{account}', account.toString());\n}\n\nexport function extractStacksDerivationPathAccountIndex(path: string) {\n if (!path.includes('5757')) throw new Error('Not a valid Stacks derivation path: ' + path);\n return extractAddressIndexFromPath(path);\n}\n\n/**\n * Stacks accounts always use the same derivation path, regardless of network\n */\nexport const makeStxDerivationPath =\n makeAccountIndexDerivationPathFactory(stxDerivationWithAccount);\n\nexport function stacksChainIdToCoreNetworkMode(chainId: ChainId): NetworkModes {\n return whenStacksChainId(chainId)({\n [ChainId.Mainnet]: 'mainnet',\n [ChainId.Testnet]: 'testnet',\n });\n}\n\ninterface WhenStacksChainIdMap<T> {\n [ChainId.Mainnet]: T;\n [ChainId.Testnet]: T;\n}\nexport function whenStacksChainId(chainId: ChainId) {\n return <T>(chainIdMap: WhenStacksChainIdMap<T>): T => chainIdMap[chainId];\n}\n\n// From `@stacks/wallet-sdk` package we are trying not to use\nexport function deriveStxPrivateKey({ keychain, index }: { keychain: HDKey; index: number }) {\n if (keychain.depth !== DerivationPathDepth.Root) throw new Error('Root keychain must be depth 0');\n const accountKeychain = keychain.derive(makeStxDerivationPath(index));\n assertIsTruthy(accountKeychain.privateKey);\n return compressPrivateKey(accountKeychain.privateKey);\n}\n\nexport function deriveStxPublicKey({\n keychain,\n index,\n}: {\n keychain: HDKey;\n index: number;\n}): string {\n return privateKeyToPublic(deriveStxPrivateKey({ keychain, index })) as string;\n}\n\nexport function stacksRootKeychainToAccountDescriptor(keychain: HDKey, accountIndex: number) {\n const fingerprint = toHexString(keychain.fingerprint);\n const publicKey = deriveStxPublicKey({ keychain, index: accountIndex });\n return createDescriptor(\n createKeyOriginPath(fingerprint, makeStxDerivationPath(accountIndex)),\n publicKey\n );\n}\n\nexport function getStacksBurnAddress(chainIdChainId: ChainId): string {\n switch (chainIdChainId) {\n case ChainId.Mainnet:\n return 'SP00000000000003SCNSJTCSE62ZF4MSE';\n case ChainId.Testnet:\n default:\n return 'ST000000000000000000002AMW42H';\n }\n}\n\nexport function cleanHex(hexWithMaybePrefix: string): string {\n if (!isString(hexWithMaybePrefix)) return hexWithMaybePrefix;\n return hexWithMaybePrefix.startsWith('0x')\n ? hexWithMaybePrefix.replace('0x', '')\n : hexWithMaybePrefix;\n}\n\nexport function getPrincipalFromAssetString(assetString: string) {\n return assetString.split('::')[0];\n}\n\nexport function formatContractId(address: string, name: string) {\n return `${address}.${name}`;\n}\n\ninterface FormatAssetStringArgs {\n contractAddress: string;\n contractName: string;\n assetName: string;\n}\nexport function formatAssetString({\n contractAddress,\n contractName,\n assetName,\n}: FormatAssetStringArgs): AssetString {\n return `${contractAddress}.${contractName}::${assetName}`;\n}\n\n/**\n * Gets the contract name.\n *\n * @param identifier - [principal].[contract-name] or [principal].[contract-name]::[asset-name]\n */\nexport function getStacksContractName(identifier: string): string {\n if (identifier.includes('.')) {\n const parts = identifier?.split('.');\n if (identifier.includes('::')) {\n return parts[1].split('::')[0];\n }\n return parts[1];\n }\n return identifier;\n}\n\n/**\n * Gets the asset name.\n *\n * @param identifier - [principal].[contract-name]::[asset-name]\n */\nexport function getStacksContractAssetName(identifier: string): string {\n if (!identifier.includes('::')) return identifier;\n return identifier.split('::')[1];\n}\n\n/**\n * Gets the parts that make up a fully qualified name of an asset.\n *\n * @param identifier - [principal].[contract-name]::[asset-name]\n */\nexport function getStacksAssetStringParts(identifier: string): {\n contractAddress: string;\n contractAssetName: string;\n contractName: string;\n} {\n if (!identifier.includes('.') || !identifier.includes('::')) {\n return {\n contractAddress: identifier,\n contractAssetName: identifier,\n contractName: identifier,\n };\n }\n\n const contractAddress = identifier.split('.')[0];\n const contractAssetName = getStacksContractAssetName(identifier);\n const contractName = getStacksContractName(identifier);\n\n return {\n contractAddress,\n contractAssetName,\n contractName,\n };\n}\n","import { hexToBytes } from '@noble/hashes/utils';\nimport {\n deserializeCV,\n makeUnsignedContractCall,\n makeUnsignedContractDeploy,\n makeUnsignedSTXTokenTransfer,\n} from '@stacks/transactions';\nimport BigNumber from 'bignumber.js';\n\nimport { assertUnreachable } from '@leather.io/utils';\n\nimport { cleanHex } from '../stacks.utils';\nimport { ensurePostConditionWireFormat, getPostConditions } from './post-condition.utils';\nimport {\n StacksUnsignedContractCallOptions,\n StacksUnsignedContractDeployOptions,\n StacksUnsignedTokenTransferOptions,\n StacksUnsignedTransactionOptions,\n TransactionTypes,\n isTransactionTypeSupported,\n} from './transaction.types';\n\nexport function initNonce(nonce: number | string) {\n return new BigNumber(nonce, 10);\n}\n\nexport function getUnsignedContractCallParsedOptions(options: StacksUnsignedContractCallOptions) {\n return {\n ...options,\n fee: options.fee.amount.toString(),\n functionArgs: options.functionArgs.map(arg => deserializeCV(hexToBytes(cleanHex(arg)))),\n nonce: initNonce(options.nonce).toString(),\n postConditions: options.postConditions,\n };\n}\n\nexport function getUnsignedContractDeployParsedOptions(\n options: StacksUnsignedContractDeployOptions\n) {\n return {\n ...options,\n fee: options.fee.amount.toString(),\n nonce: initNonce(options.nonce).toString(),\n postConditions: getPostConditions(\n options.postConditions?.map(pc => ensurePostConditionWireFormat(pc))\n ),\n };\n}\n\nexport function getUnsignedStxTokenTransferParsedOptions(\n options: StacksUnsignedTokenTransferOptions\n) {\n return {\n ...options,\n amount: options.amount.amount.toString(),\n fee: options.fee.amount.toString(),\n nonce: initNonce(options.nonce).toString(),\n };\n}\n\nexport function generateStacksUnsignedTransaction(options: StacksUnsignedTransactionOptions) {\n const { txType } = options;\n\n const isValid = isTransactionTypeSupported(txType);\n\n if (!isValid) throw new Error(`Invalid Transaction Type: ${txType}`);\n\n switch (txType) {\n case TransactionTypes.StxTokenTransfer:\n return makeUnsignedSTXTokenTransfer(getUnsignedStxTokenTransferParsedOptions(options));\n case TransactionTypes.ContractCall:\n return makeUnsignedContractCall(getUnsignedContractCallParsedOptions(options));\n case TransactionTypes.ContractDeploy:\n return makeUnsignedContractDeploy(getUnsignedContractDeployParsedOptions(options));\n default:\n assertUnreachable(txType);\n }\n}\n","import { hexToBytes } from '@noble/hashes/utils';\nimport {\n BytesReader,\n PostCondition,\n PostConditionWire,\n deserializePostConditionWire,\n postConditionToWire,\n} from '@stacks/transactions';\n\nimport { isString } from '@leather.io/utils';\n\nexport function getPostConditionFromString(postCondition: string): PostConditionWire {\n try {\n const reader = new BytesReader(hexToBytes(postCondition));\n return deserializePostConditionWire(reader);\n } catch {\n throw new Error('Not a serialized post condition');\n }\n}\n\nexport function ensurePostConditionWireFormat(\n postCondition: string | PostCondition | PostConditionWire\n) {\n if (isString(postCondition)) return getPostConditionFromString(postCondition);\n if ('conditionType' in postCondition) return postCondition;\n return postConditionToWire(postCondition);\n}\n\nexport function getPostCondition(\n postCondition: string | PostCondition | PostConditionWire\n): PostConditionWire {\n return isString(postCondition)\n ? getPostConditionFromString(postCondition)\n : ensurePostConditionWireFormat(postCondition);\n}\n\nexport function getPostConditions(\n postConditions?: (string | PostCondition | PostConditionWire)[]\n): PostConditionWire[] | undefined {\n return postConditions?.map(getPostCondition);\n}\n","import {\n UnsignedContractCallOptions,\n UnsignedContractDeployOptions,\n UnsignedTokenTransferOptions,\n} from '@stacks/transactions';\n\nimport { Money, ReplaceTypes } from '@leather.io/models';\n\nexport enum TransactionTypes {\n ContractCall = 'contract_call',\n ContractDeploy = 'smart_contract',\n StxTokenTransfer = 'token_transfer',\n}\n\nexport function isTransactionTypeSupported(txType: TransactionTypes) {\n return (\n txType === TransactionTypes.ContractCall ||\n txType === TransactionTypes.ContractDeploy ||\n txType === TransactionTypes.StxTokenTransfer\n );\n}\n\nexport type StacksUnsignedContractCallOptions = ReplaceTypes<\n UnsignedContractCallOptions,\n {\n fee: Money;\n functionArgs: string[];\n nonce: number | string;\n }\n> & { txType: TransactionTypes.ContractCall };\n\nexport type StacksUnsignedContractDeployOptions = ReplaceTypes<\n UnsignedContractDeployOptions,\n {\n fee: Money;\n nonce: number | string;\n }\n> & { txType: TransactionTypes.ContractDeploy };\n\nexport type StacksUnsignedTokenTransferOptions = ReplaceTypes<\n UnsignedTokenTransferOptions,\n {\n amount: Money;\n fee: Money;\n nonce: number | string;\n }\n> & { txType: TransactionTypes.StxTokenTransfer };\n\nexport type StacksUnsignedTransactionOptions =\n | StacksUnsignedContractCallOptions\n | StacksUnsignedContractDeployOptions\n | StacksUnsignedTokenTransferOptions;\n","import { TransactionErrorKey } from '@leather.io/models';\n\nexport type StacksErrorKey =\n | TransactionErrorKey\n | 'InvalidSameAddress'\n | 'UnknownBalance'\n | 'UnknownFee'\n | 'UnknownAmount';\n\nexport class StacksError extends Error {\n public message: StacksErrorKey;\n constructor(message: StacksErrorKey) {\n super(message);\n this.name = 'StacksError';\n this.message = message;\n\n // Fix the prototype chain\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n","import { c32addressDecode } from 'c32check';\n\nimport { ChainId } from '@leather.io/models';\nimport { isEmptyString, isUndefined } from '@leather.io/utils';\n\n// taken from stacks-utils.ts\nexport function isValidStacksAddress(address: string) {\n if (isUndefined(address) || isEmptyString(address)) {\n return false;\n }\n try {\n c32addressDecode(address);\n return true;\n } catch {\n return false;\n }\n}\n\nexport function isValidAddressChain(address: string, chainId: ChainId) {\n if (!isValidStacksAddress(address)) {\n return false;\n }\n\n const prefix = address.slice(0, 2);\n switch (chainId) {\n case ChainId.Mainnet:\n return prefix === 'SM' || prefix === 'SP';\n case ChainId.Testnet:\n return prefix === 'SN' || prefix === 'ST';\n default:\n return false;\n }\n}\n\nexport function validatePayerNotRecipient(senderAddress: string, recipientAddress: string) {\n if (!isValidStacksAddress(senderAddress) || !isValidStacksAddress(recipientAddress)) {\n return false;\n }\n if (senderAddress === recipientAddress) {\n return false;\n }\n return true;\n}\n","import BigNumber from 'bignumber.js';\n\nimport { Money } from '@leather.io/models';\nimport { isDefined, stxToMicroStx } from '@leather.io/utils';\n\nimport { StacksError } from './stacks-error';\n\nfunction isMoneyAmountValid(amount: Money) {\n return amount && isDefined(amount.amount) && amount.amount;\n}\n\ninterface IsStxAmountValidArgs {\n availableBalance: Money;\n amount: Money;\n fee: Money;\n}\n\nexport function isStxAmountValid({ availableBalance, amount, fee }: IsStxAmountValidArgs) {\n if (!isMoneyAmountValid(amount)) {\n throw new StacksError('InvalidAmount');\n }\n if (!isMoneyAmountValid(availableBalance)) {\n throw new StacksError('UnknownBalance');\n }\n if (!isMoneyAmountValid(fee)) {\n throw new StacksError('UnknownFee');\n }\n return true;\n}\n\nexport function isStxBalanceSufficient({\n availableBalance: { amount: availableBalanceAmount },\n amount: { amount: desiredSpend },\n fee: { amount: feeAmount },\n}: IsStxAmountValidArgs) {\n const fee = new BigNumber(stxToMicroStx(feeAmount));\n\n if (!availableBalanceAmount) {\n throw new StacksError('UnknownBalance');\n }\n if (!fee.isFinite()) {\n throw new StacksError('UnknownFee');\n }\n\n const availableBalance = new BigNumber(stxToMicroStx(availableBalanceAmount));\n const spendableAmount = availableBalance.minus(fee);\n const amount = new BigNumber(stxToMicroStx(desiredSpend));\n return spendableAmount.isGreaterThanOrEqualTo(amount);\n}\n","import { ChainId, Money } from '@leather.io/models';\n\nimport {\n isValidAddressChain,\n isValidStacksAddress,\n validatePayerNotRecipient,\n} from './address-validation';\nimport { isStxAmountValid, isStxBalanceSufficient } from './amount-validation';\nimport { StacksError } from './stacks-error';\n\ninterface StacksTransaction {\n amount: Money;\n payer: string;\n recipient: string;\n chainId: ChainId;\n availableBalance: Money;\n fee: Money;\n}\n\nexport function isValidStacksTransaction({\n amount,\n availableBalance,\n fee,\n payer,\n recipient,\n chainId,\n}: StacksTransaction) {\n if (!isValidStacksAddress(payer) || !isValidStacksAddress(recipient)) {\n throw new StacksError('InvalidAddress');\n }\n if (!isValidAddressChain(payer, chainId) || !isValidAddressChain(recipient, chainId)) {\n throw new StacksError('InvalidNetworkAddress');\n }\n if (!validatePayerNotRecipient(payer, recipient)) {\n throw new StacksError('InvalidSameAddress');\n }\n\n if (!isStxAmountValid({ availableBalance, amount, fee })) {\n throw new StacksError('InvalidAmount');\n }\n if (!isStxBalanceSufficient({ availableBalance, amount, fee })) {\n throw new StacksError('Insuf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AQ,IAAI,CAAC,GAAG;AAC9D,UAAM,IAAI,YAAY,mBAAmB;AAAA,EAC3C;AACA,SAAO;AACT;","names":["privateKeyToPublic","hexToBytes","isString","TransactionTypes","hexToBytes","ChainId","BigNumber","BigNumber"]}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@leather.io/stacks",
3
3
  "author": "leather.io",
4
4
  "description": "Stacks package for Leather",
5
- "version": "1.7.1",
5
+ "version": "1.7.2",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
8
  "exports": {
@@ -15,13 +15,13 @@
15
15
  "@stacks/encryption": "7.0.2",
16
16
  "@stacks/network": "7.0.2",
17
17
  "@stacks/stacks-blockchain-api-types": "7.8.2",
18
- "@stacks/transactions": "7.0.2",
18
+ "@stacks/transactions": "7.0.5",
19
19
  "bignumber.js": "9.1.2",
20
20
  "c32check": "2.0.0",
21
- "@leather.io/constants": "0.17.5",
22
- "@leather.io/models": "0.28.0",
23
- "@leather.io/crypto": "1.6.49",
24
- "@leather.io/utils": "0.27.8"
21
+ "@leather.io/crypto": "1.6.50",
22
+ "@leather.io/utils": "0.28.0",
23
+ "@leather.io/constants": "0.18.0",
24
+ "@leather.io/models": "0.29.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "tsup": "8.1.0",