@leather.io/stacks 1.5.26 → 1.6.0

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,11 +1,24 @@
1
+ import { PrivateKey } from '@stacks/common';
1
2
  import * as _stacks_transactions from '@stacks/transactions';
2
- import { StacksTransactionWire, UnsignedContractCallOptions, UnsignedContractDeployOptions, UnsignedTokenTransferOptions, PostConditionWire, PostCondition, AssetString, ClarityValue } from '@stacks/transactions';
3
+ import { ClarityValue, StacksTransactionWire, AssetString, UnsignedContractCallOptions, UnsignedContractDeployOptions, UnsignedTokenTransferOptions, PostConditionWire, PostCondition } from '@stacks/transactions';
3
4
  import { Signer } from '@leather.io/crypto';
4
- import { NetworkModes, ReplaceTypes, Money } from '@leather.io/models';
5
- import BigNumber from 'bignumber.js';
5
+ import { NetworkModes, ReplaceTypes, Money, ChainId as ChainId$1 } from '@leather.io/models';
6
6
  import { HDKey } from '@scure/bip32';
7
7
  import { ChainId } from '@stacks/network';
8
- import { PrivateKey } from '@stacks/common';
8
+ import BigNumber from 'bignumber.js';
9
+
10
+ interface SignatureData {
11
+ signature: string;
12
+ publicKey: string;
13
+ }
14
+ declare function signMessage(message: string, privateKey: PrivateKey): SignatureData;
15
+ declare function signStructuredDataMessage(message: ClarityValue, domain: ClarityValue, privateKey: PrivateKey): SignatureData;
16
+
17
+ declare const TEST_ACCOUNT_1_STX_ADDRESS = "SPS8CKF63P16J28AYF7PXW9E5AACH0NZNTEFWSFE";
18
+ declare const TEST_ACCOUNT_2_STX_ADDRESS = "SPXH3HNBPM5YP15VH16ZXZ9AX6CK289K3MCXRKCB";
19
+ declare const TEST_TESTNET_ACCOUNT_2_STX_ADDRESS = "STXH3HNBPM5YP15VH16ZXZ9AX6CK289K3NVR9T1P";
20
+ declare const TEST_ACCOUNT_1_STX_ADDRESS_SM = "SM3FBR6RDNZYC5K4TZWV9VZJ6NGA4VX3YBQ8X2PQ";
21
+ declare const TEST_TESTNET_ACCOUNT_2_STX_ADDRESS_SN = "SNXH3HNBPM5YP15VH16ZXZ9AX6CK289K3NVR9T1P";
9
22
 
10
23
  declare function signStacksTransaction(tx: StacksTransactionWire, privateKey: string): StacksTransactionWire;
11
24
  type StacksSignerFn = (tx: StacksTransactionWire) => Promise<StacksTransactionWire>;
@@ -28,45 +41,6 @@ interface InitalizeStacksSignerArgs {
28
41
  }
29
42
  declare function initalizeStacksSigner(args: InitalizeStacksSignerArgs): StacksSigner;
30
43
 
31
- declare enum TransactionTypes {
32
- ContractCall = "contract_call",
33
- ContractDeploy = "smart_contract",
34
- StxTokenTransfer = "token_transfer"
35
- }
36
- declare function isTransactionTypeSupported(txType: TransactionTypes): txType is TransactionTypes;
37
- type StacksUnsignedContractCallOptions = ReplaceTypes<UnsignedContractCallOptions, {
38
- fee: Money;
39
- functionArgs: string[];
40
- nonce: number | string;
41
- }> & {
42
- txType: TransactionTypes.ContractCall;
43
- };
44
- type StacksUnsignedContractDeployOptions = ReplaceTypes<UnsignedContractDeployOptions, {
45
- fee: Money;
46
- nonce: number | string;
47
- }> & {
48
- txType: TransactionTypes.ContractDeploy;
49
- };
50
- type StacksUnsignedTokenTransferOptions = ReplaceTypes<UnsignedTokenTransferOptions, {
51
- amount: Money;
52
- fee: Money;
53
- nonce: number | string;
54
- }> & {
55
- txType: TransactionTypes.StxTokenTransfer;
56
- };
57
- type StacksUnsignedTransactionOptions = StacksUnsignedContractCallOptions | StacksUnsignedContractDeployOptions | StacksUnsignedTokenTransferOptions;
58
-
59
- declare function initNonce(nonce: number | string): BigNumber;
60
- declare function generateUnsignedContractCall(options: StacksUnsignedContractCallOptions): Promise<_stacks_transactions.StacksTransactionWire>;
61
- declare function generateUnsignedContractDeploy(options: StacksUnsignedContractDeployOptions): Promise<_stacks_transactions.StacksTransactionWire>;
62
- declare function generateUnsignedStxTokenTransfer(options: StacksUnsignedTokenTransferOptions): Promise<_stacks_transactions.StacksTransactionWire>;
63
- declare function generateStacksUnsignedTransaction(options: StacksUnsignedTransactionOptions): Promise<_stacks_transactions.StacksTransactionWire>;
64
-
65
- declare function getPostConditionFromString(postCondition: string): PostConditionWire;
66
- declare function ensurePostConditionWireFormat(postCondition: string | PostCondition | PostConditionWire): PostConditionWire;
67
- declare function getPostCondition(postCondition: string | PostCondition | PostConditionWire): PostConditionWire;
68
- declare function getPostConditions(postConditions?: (string | PostCondition | PostConditionWire)[]): PostConditionWire[] | undefined;
69
-
70
44
  declare const stxDerivationWithAccount = "m/44'/5757'/0'/0/{account}";
71
45
  declare function makeAccountIndexDerivationPathFactory(derivationPath: string): (account: number) => string;
72
46
  declare function extractStacksDerivationPathAccountIndex(path: string): number;
@@ -122,11 +96,56 @@ declare function getStacksAssetStringParts(identifier: string): {
122
96
  contractName: string;
123
97
  };
124
98
 
125
- interface SignatureData {
126
- signature: string;
127
- publicKey: string;
99
+ declare enum TransactionTypes {
100
+ ContractCall = "contract_call",
101
+ ContractDeploy = "smart_contract",
102
+ StxTokenTransfer = "token_transfer"
128
103
  }
129
- declare function signMessage(message: string, privateKey: PrivateKey): SignatureData;
130
- declare function signStructuredDataMessage(message: ClarityValue, domain: ClarityValue, privateKey: PrivateKey): SignatureData;
104
+ declare function isTransactionTypeSupported(txType: TransactionTypes): txType is TransactionTypes;
105
+ type StacksUnsignedContractCallOptions = ReplaceTypes<UnsignedContractCallOptions, {
106
+ fee: Money;
107
+ functionArgs: string[];
108
+ nonce: number | string;
109
+ }> & {
110
+ txType: TransactionTypes.ContractCall;
111
+ };
112
+ type StacksUnsignedContractDeployOptions = ReplaceTypes<UnsignedContractDeployOptions, {
113
+ fee: Money;
114
+ nonce: number | string;
115
+ }> & {
116
+ txType: TransactionTypes.ContractDeploy;
117
+ };
118
+ type StacksUnsignedTokenTransferOptions = ReplaceTypes<UnsignedTokenTransferOptions, {
119
+ amount: Money;
120
+ fee: Money;
121
+ nonce: number | string;
122
+ }> & {
123
+ txType: TransactionTypes.StxTokenTransfer;
124
+ };
125
+ type StacksUnsignedTransactionOptions = StacksUnsignedContractCallOptions | StacksUnsignedContractDeployOptions | StacksUnsignedTokenTransferOptions;
126
+
127
+ 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>;
131
+ declare function generateStacksUnsignedTransaction(options: StacksUnsignedTransactionOptions): Promise<_stacks_transactions.StacksTransactionWire>;
132
+
133
+ declare function getPostConditionFromString(postCondition: string): PostConditionWire;
134
+ declare function ensurePostConditionWireFormat(postCondition: string | PostCondition | PostConditionWire): PostConditionWire;
135
+ declare function getPostCondition(postCondition: string | PostCondition | PostConditionWire): PostConditionWire;
136
+ declare function getPostConditions(postConditions?: (string | PostCondition | PostConditionWire)[]): PostConditionWire[] | undefined;
137
+
138
+ type TransactionErrorKey = 'InvalidAddress' | 'InsufficientFunds' | 'InvalidNetworkAddress';
139
+ type StacksErrorKey = TransactionErrorKey | 'InvalidSameAddress';
140
+ declare class StacksError extends Error {
141
+ message: StacksErrorKey;
142
+ constructor(message: StacksErrorKey);
143
+ }
144
+
145
+ declare function isValidStacksAddress(address: string): boolean;
146
+ declare function isValidAddressChain(address: string, chainId: ChainId$1): boolean;
147
+ declare function validatePayerNotRecipient(senderAddress: string, recipientAddress: string): boolean;
148
+
149
+ declare function isValidStacksTransaction(senderAddress: string, recipientAddress: string, chainId: ChainId$1): void;
131
150
 
132
- export { type StacksSigner, type StacksSignerFn, type StacksUnsignedContractCallOptions, type StacksUnsignedContractDeployOptions, type StacksUnsignedTokenTransferOptions, type StacksUnsignedTransactionOptions, TransactionTypes, cleanHex, createSignFnFromMnemonic, deriveStxPrivateKey, deriveStxPublicKey, ensurePostConditionWireFormat, extractStacksDerivationPathAccountIndex, formatAssetString, formatContractId, generateStacksUnsignedTransaction, generateUnsignedContractCall, generateUnsignedContractDeploy, generateUnsignedStxTokenTransfer, getPostCondition, getPostConditionFromString, getPostConditions, getPrincipalFromAssetString, getStacksAssetStringParts, getStacksBurnAddress, getStacksContractAssetName, getStacksContractName, initNonce, initalizeStacksSigner, isTransactionTypeSupported, makeAccountIndexDerivationPathFactory, makeStxDerivationPath, signMessage, signStacksTransaction, signStructuredDataMessage, stacksChainIdToCoreNetworkMode, stacksRootKeychainToAccountDescriptor, stxDerivationWithAccount, whenStacksChainId };
151
+ 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 };
package/dist/index.js CHANGED
@@ -1,3 +1,37 @@
1
+ // src/message-signing.ts
2
+ import { bytesToHex } from "@noble/hashes/utils";
3
+ import { hashMessage } from "@stacks/encryption";
4
+ import {
5
+ privateKeyToPublic,
6
+ signMessageHashRsv,
7
+ signStructuredData
8
+ } from "@stacks/transactions";
9
+ function signMessage(message, privateKey) {
10
+ const hash = hashMessage(message);
11
+ return {
12
+ signature: signMessageHashRsv({ privateKey, messageHash: bytesToHex(hash) }),
13
+ publicKey: privateKeyToPublic(privateKey)
14
+ };
15
+ }
16
+ function signStructuredDataMessage(message, domain, privateKey) {
17
+ const signature = signStructuredData({
18
+ message,
19
+ domain,
20
+ privateKey
21
+ });
22
+ return {
23
+ signature,
24
+ publicKey: privateKeyToPublic(privateKey)
25
+ };
26
+ }
27
+
28
+ // src/mocks/mocks.ts
29
+ var TEST_ACCOUNT_1_STX_ADDRESS = "SPS8CKF63P16J28AYF7PXW9E5AACH0NZNTEFWSFE";
30
+ var TEST_ACCOUNT_2_STX_ADDRESS = "SPXH3HNBPM5YP15VH16ZXZ9AX6CK289K3MCXRKCB";
31
+ var TEST_TESTNET_ACCOUNT_2_STX_ADDRESS = "STXH3HNBPM5YP15VH16ZXZ9AX6CK289K3NVR9T1P";
32
+ var TEST_ACCOUNT_1_STX_ADDRESS_SM = "SM3FBR6RDNZYC5K4TZWV9VZJ6NGA4VX3YBQ8X2PQ";
33
+ var TEST_TESTNET_ACCOUNT_2_STX_ADDRESS_SN = "SNXH3HNBPM5YP15VH16ZXZ9AX6CK289K3NVR9T1P";
34
+
1
35
  // src/signer/signer.ts
2
36
  import {
3
37
  TransactionSigner,
@@ -12,7 +46,7 @@ import {
12
46
 
13
47
  // src/stacks.utils.ts
14
48
  import { ChainId } from "@stacks/network";
15
- import { compressPrivateKey, privateKeyToPublic } from "@stacks/transactions";
49
+ import { compressPrivateKey, privateKeyToPublic as privateKeyToPublic2 } from "@stacks/transactions";
16
50
  import {
17
51
  DerivationPathDepth,
18
52
  createDescriptor,
@@ -48,7 +82,7 @@ function deriveStxPublicKey({
48
82
  keychain,
49
83
  index
50
84
  }) {
51
- return privateKeyToPublic(deriveStxPrivateKey({ keychain, index }));
85
+ return privateKeyToPublic2(deriveStxPrivateKey({ keychain, index }));
52
86
  }
53
87
  function stacksRootKeychainToAccountDescriptor(keychain, accountIndex) {
54
88
  const fingerprint = toHexString(keychain.fingerprint);
@@ -246,33 +280,75 @@ async function generateStacksUnsignedTransaction(options) {
246
280
  }
247
281
  }
248
282
 
249
- // src/message-signing.ts
250
- import { bytesToHex } from "@noble/hashes/utils";
251
- import { hashMessage } from "@stacks/encryption";
252
- import {
253
- privateKeyToPublic as privateKeyToPublic2,
254
- signMessageHashRsv,
255
- signStructuredData
256
- } from "@stacks/transactions";
257
- function signMessage(message, privateKey) {
258
- const hash = hashMessage(message);
259
- return {
260
- signature: signMessageHashRsv({ privateKey, messageHash: bytesToHex(hash) }),
261
- publicKey: privateKeyToPublic2(privateKey)
262
- };
283
+ // src/validation/stacks-error.ts
284
+ var StacksError = class extends Error {
285
+ message;
286
+ constructor(message) {
287
+ super(message);
288
+ this.name = "BitcoinError";
289
+ this.message = message;
290
+ Object.setPrototypeOf(this, new.target.prototype);
291
+ }
292
+ };
293
+
294
+ // src/validation/address-validation.ts
295
+ import { c32addressDecode } from "c32check";
296
+ import { ChainId as ChainId2 } from "@leather.io/models";
297
+ import { isEmptyString, isUndefined } from "@leather.io/utils";
298
+ function isValidStacksAddress(address) {
299
+ if (isUndefined(address) || isEmptyString(address)) {
300
+ return false;
301
+ }
302
+ try {
303
+ c32addressDecode(address);
304
+ return true;
305
+ } catch {
306
+ return false;
307
+ }
263
308
  }
264
- function signStructuredDataMessage(message, domain, privateKey) {
265
- const signature = signStructuredData({
266
- message,
267
- domain,
268
- privateKey
269
- });
270
- return {
271
- signature,
272
- publicKey: privateKeyToPublic2(privateKey)
273
- };
309
+ function isValidAddressChain(address, chainId) {
310
+ if (!isValidStacksAddress(address)) {
311
+ return false;
312
+ }
313
+ const prefix = address.slice(0, 2);
314
+ switch (chainId) {
315
+ case ChainId2.Mainnet:
316
+ return prefix === "SM" || prefix === "SP";
317
+ case ChainId2.Testnet:
318
+ return prefix === "SN" || prefix === "ST";
319
+ default:
320
+ return false;
321
+ }
322
+ }
323
+ function validatePayerNotRecipient(senderAddress, recipientAddress) {
324
+ if (!isValidStacksAddress(senderAddress) || !isValidStacksAddress(recipientAddress)) {
325
+ return false;
326
+ }
327
+ if (senderAddress === recipientAddress) {
328
+ return false;
329
+ }
330
+ return true;
331
+ }
332
+
333
+ // src/validation/transaction-validation.ts
334
+ function isValidStacksTransaction(senderAddress, recipientAddress, chainId) {
335
+ if (!isValidStacksAddress(senderAddress) || !isValidStacksAddress(recipientAddress)) {
336
+ throw new StacksError("InvalidAddress");
337
+ }
338
+ if (!isValidAddressChain(senderAddress, chainId) || !isValidAddressChain(recipientAddress, chainId)) {
339
+ throw new StacksError("InvalidNetworkAddress");
340
+ }
341
+ if (!validatePayerNotRecipient(senderAddress, recipientAddress)) {
342
+ throw new StacksError("InvalidSameAddress");
343
+ }
274
344
  }
275
345
  export {
346
+ StacksError,
347
+ TEST_ACCOUNT_1_STX_ADDRESS,
348
+ TEST_ACCOUNT_1_STX_ADDRESS_SM,
349
+ TEST_ACCOUNT_2_STX_ADDRESS,
350
+ TEST_TESTNET_ACCOUNT_2_STX_ADDRESS,
351
+ TEST_TESTNET_ACCOUNT_2_STX_ADDRESS_SN,
276
352
  TransactionTypes,
277
353
  cleanHex,
278
354
  createSignFnFromMnemonic,
@@ -297,6 +373,9 @@ export {
297
373
  initNonce,
298
374
  initalizeStacksSigner,
299
375
  isTransactionTypeSupported,
376
+ isValidAddressChain,
377
+ isValidStacksAddress,
378
+ isValidStacksTransaction,
300
379
  makeAccountIndexDerivationPathFactory,
301
380
  makeStxDerivationPath,
302
381
  signMessage,
@@ -305,6 +384,7 @@ export {
305
384
  stacksChainIdToCoreNetworkMode,
306
385
  stacksRootKeychainToAccountDescriptor,
307
386
  stxDerivationWithAccount,
387
+ validatePayerNotRecipient,
308
388
  whenStacksChainId
309
389
  };
310
390
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../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/message-signing.ts"],"sourcesContent":["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 { 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(priv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oBAAmB,UAAU;AAAA,EAC1C;AACF;","names":["hexToBytes","isString","TransactionTypes","hexToBytes","privateKeyToPublic"]}
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/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","type TransactionErrorKey = 'InvalidAddress' | 'InsufficientFunds' | 'InvalidNetworkAddress';\n\nexport type StacksErrorKey = TransactionErrorKey | 'InvalidSameAddress';\n\nexport class StacksError extends Error {\n public message: StacksErrorKey;\n constructor(message: StacksErrorKey) {\n super(message);\n this.name = 'BitcoinError';\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 { ChainId } from '@leather.io/models';\n\nimport {\n isValidAddressChain,\n isValidStacksAddress,\n validatePayerNotRecipient,\n} from './address-validation';\nimport { StacksError } from './stacks-error';\n\nexport function isValidStacksTransaction(\n senderAddress: string,\n recipientAddress: string,\n chainId: ChainId\n) {\n if (!isValidStacksAddress(senderAddress) || !isValidStacksAddress(recipientAddress)) {\n throw new StacksError('InvalidAddress');\n }\n if (\n !isValidAddressChain(senderAddress, chainId) ||\n !isValidAddressChain(recipientAddress, chainId)\n ) {\n throw new StacksError('InvalidNetworkAddress');\n }\n if (!validatePayerNotRecipient(senderAddress, recipientAddress)) {\n throw new StacksError('InvalidSameAddress');\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;AAAA,EACA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qBAAqB,OAAO,GAAG;AAClC,WAAO;AAAA,EACT;AAEA,QAAM,SAAS,QAAQ,MAAM,GAAG,CAAC;AACjC,UAAQ,SAAS;AAAA,IACf,KAAKA,SAAQ;AACX,aAAO,WAAW,QAAQ,WAAW;AAAA,IACvC,KAAKA,SAAQ;AACX,aAAO,WAAW,QAAQ,WAAW;AAAA,IACvC;AACE,aAAO;AAAA,EACX;AACF;AAEO,SAAS,0BAA0B,eAAuB,kBAA0B;AACzF,MAAI,CAAC,qBAAqB,aAAa,KAAK,CAAC,qBAAqB,gBAAgB,GAAG;AACnF,WAAO;AAAA,EACT;AACA,MAAI,kBAAkB,kBAAkB;AACtC,WAAO;AAAA,EACT;AACA,SAAO;AACT;;;ACjCO,SAAS,yBACd,eACA,kBACA,SACA;AACA,MAAI,CAAC,qBAAqB,aAAa,KAAK,CAAC,qBAAqB,gBAAgB,GAAG;AACnF,UAAM,IAAI,YAAY,gBAAgB;AAAA,EACxC;AACA,MACE,CAAC,oBAAoB,eAAe,OAAO,KAC3C,CAAC,oBAAoB,kBAAkB,OAAO,GAC9C;AACA,UAAM,IAAI,YAAY,uBAAuB;AAAA,EAC/C;AACA,MAAI,CAAC,0BAA0B,eAAe,gBAAgB,GAAG;AAC/D,UAAM,IAAI,YAAY,oBAAoB;AAAA,EAC5C;AACF;","names":["privateKeyToPublic","hexToBytes","isString","TransactionTypes","hexToBytes","ChainId"]}
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.5.26",
5
+ "version": "1.6.0",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
8
  "exports": {
@@ -17,14 +17,15 @@
17
17
  "@stacks/stacks-blockchain-api-types": "7.8.2",
18
18
  "@stacks/transactions": "7.0.2",
19
19
  "bignumber.js": "9.1.2",
20
- "@leather.io/constants": "0.16.0",
21
- "@leather.io/crypto": "1.6.41",
22
- "@leather.io/utils": "0.27.1",
23
- "@leather.io/models": "0.26.0"
20
+ "c32check": "2.0.0",
21
+ "@leather.io/constants": "0.17.1",
22
+ "@leather.io/crypto": "1.6.43",
23
+ "@leather.io/models": "0.26.1",
24
+ "@leather.io/utils": "0.27.3"
24
25
  },
25
26
  "devDependencies": {
26
27
  "tsup": "8.1.0",
27
- "vitest": "2.1.5"
28
+ "vitest": "2.1.9"
28
29
  },
29
30
  "files": [
30
31
  "dist"