@leather.io/stacks 1.5.18 → 1.5.19
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 +40 -29
- package/dist/index.js +76 -55
- package/dist/index.js.map +1 -1
- package/package.json +9 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import * as _stacks_transactions from '@stacks/transactions';
|
|
2
|
-
import {
|
|
2
|
+
import { StacksTransactionWire, UnsignedContractCallOptions, UnsignedContractDeployOptions, UnsignedTokenTransferOptions, PostConditionWire, PostCondition, AssetString, ClarityValue } from '@stacks/transactions';
|
|
3
3
|
import { Signer } from '@leather.io/crypto';
|
|
4
4
|
import { NetworkModes, ReplaceTypes, Money } from '@leather.io/models';
|
|
5
5
|
import BigNumber from 'bignumber.js';
|
|
6
6
|
import { HDKey } from '@scure/bip32';
|
|
7
|
+
import { ChainId } from '@stacks/network';
|
|
8
|
+
import { PrivateKey } from '@stacks/common';
|
|
7
9
|
|
|
8
|
-
declare function signStacksTransaction(tx:
|
|
9
|
-
type StacksSignerFn = (tx:
|
|
10
|
+
declare function signStacksTransaction(tx: StacksTransactionWire, privateKey: string): StacksTransactionWire;
|
|
11
|
+
type StacksSignerFn = (tx: StacksTransactionWire) => Promise<StacksTransactionWire>;
|
|
10
12
|
interface StacksSigner extends Signer {
|
|
11
13
|
descriptor: string;
|
|
12
14
|
keyOrigin: string;
|
|
@@ -18,7 +20,7 @@ interface StacksSigner extends Signer {
|
|
|
18
20
|
declare function createSignFnFromMnemonic(keyOrigin: string, getMnemonicFn: () => Promise<{
|
|
19
21
|
mnemonic: string;
|
|
20
22
|
passphrase?: string;
|
|
21
|
-
}>): (tx:
|
|
23
|
+
}>): (tx: StacksTransactionWire) => Promise<StacksTransactionWire>;
|
|
22
24
|
interface InitalizeStacksSignerArgs {
|
|
23
25
|
descriptor: string;
|
|
24
26
|
network: NetworkModes;
|
|
@@ -55,14 +57,15 @@ type StacksUnsignedTokenTransferOptions = ReplaceTypes<UnsignedTokenTransferOpti
|
|
|
55
57
|
type StacksUnsignedTransactionOptions = StacksUnsignedContractCallOptions | StacksUnsignedContractDeployOptions | StacksUnsignedTokenTransferOptions;
|
|
56
58
|
|
|
57
59
|
declare function initNonce(nonce: number | string): BigNumber;
|
|
58
|
-
declare function generateUnsignedContractCall(options: StacksUnsignedContractCallOptions): Promise<_stacks_transactions.
|
|
59
|
-
declare function generateUnsignedContractDeploy(options: StacksUnsignedContractDeployOptions): Promise<_stacks_transactions.
|
|
60
|
-
declare function generateUnsignedStxTokenTransfer(options: StacksUnsignedTokenTransferOptions): Promise<_stacks_transactions.
|
|
61
|
-
declare function generateStacksUnsignedTransaction(options: StacksUnsignedTransactionOptions): Promise<_stacks_transactions.
|
|
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>;
|
|
62
64
|
|
|
63
|
-
declare function getPostConditionFromString(postCondition: string):
|
|
64
|
-
declare function
|
|
65
|
-
declare function
|
|
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;
|
|
66
69
|
|
|
67
70
|
declare const stxDerivationWithAccount = "m/44'/5757'/0'/0/{account}";
|
|
68
71
|
declare function makeAccountIndexDerivationPathFactory(derivationPath: string): (account: number) => string;
|
|
@@ -71,41 +74,49 @@ declare function extractStacksDerivationPathAccountIndex(path: string): number;
|
|
|
71
74
|
* Stacks accounts always use the same derivation path, regardless of network
|
|
72
75
|
*/
|
|
73
76
|
declare const makeStxDerivationPath: (account: number) => string;
|
|
74
|
-
declare function stacksChainIdToCoreNetworkMode(chainId:
|
|
77
|
+
declare function stacksChainIdToCoreNetworkMode(chainId: ChainId): NetworkModes;
|
|
75
78
|
interface WhenStacksChainIdMap<T> {
|
|
76
|
-
[
|
|
77
|
-
[
|
|
79
|
+
[ChainId.Mainnet]: T;
|
|
80
|
+
[ChainId.Testnet]: T;
|
|
78
81
|
}
|
|
79
|
-
declare function whenStacksChainId(chainId:
|
|
82
|
+
declare function whenStacksChainId(chainId: ChainId): <T>(chainIdMap: WhenStacksChainIdMap<T>) => T;
|
|
80
83
|
declare function deriveStxPrivateKey({ keychain, index }: {
|
|
81
84
|
keychain: HDKey;
|
|
82
85
|
index: number;
|
|
83
86
|
}): string;
|
|
84
|
-
declare function deriveStxPublicKey({ keychain, index }: {
|
|
87
|
+
declare function deriveStxPublicKey({ keychain, index, }: {
|
|
85
88
|
keychain: HDKey;
|
|
86
89
|
index: number;
|
|
87
|
-
}):
|
|
90
|
+
}): string;
|
|
88
91
|
declare function stacksRootKeychainToAccountDescriptor(keychain: HDKey, accountIndex: number): string;
|
|
89
|
-
declare function getStacksBurnAddress(
|
|
92
|
+
declare function getStacksBurnAddress(chainIdChainId: ChainId): string;
|
|
90
93
|
declare function cleanHex(hexWithMaybePrefix: string): string;
|
|
94
|
+
declare function getPrincipalFromAssetString(assetString: string): string;
|
|
95
|
+
declare function formatContractId(address: string, name: string): string;
|
|
96
|
+
interface FormatAssetStringArgs {
|
|
97
|
+
contractAddress: string;
|
|
98
|
+
contractName: string;
|
|
99
|
+
assetName: string;
|
|
100
|
+
}
|
|
101
|
+
declare function formatAssetString({ contractAddress, contractName, assetName, }: FormatAssetStringArgs): AssetString;
|
|
91
102
|
/**
|
|
92
|
-
* Gets the contract name
|
|
103
|
+
* Gets the contract name.
|
|
93
104
|
*
|
|
94
|
-
* @param
|
|
105
|
+
* @param identifier - [principal].[contract-name] or [principal].[contract-name]::[asset-name]
|
|
95
106
|
*/
|
|
96
|
-
declare function getStacksContractName(
|
|
107
|
+
declare function getStacksContractName(identifier: string): string;
|
|
97
108
|
/**
|
|
98
|
-
* Gets the asset name
|
|
109
|
+
* Gets the asset name.
|
|
99
110
|
*
|
|
100
|
-
* @param
|
|
111
|
+
* @param identifier - [principal].[contract-name]::[asset-name]
|
|
101
112
|
*/
|
|
102
|
-
declare function getStacksContractAssetName(
|
|
113
|
+
declare function getStacksContractAssetName(identifier: string): string;
|
|
103
114
|
/**
|
|
104
115
|
* Gets the parts that make up a fully qualified name of an asset.
|
|
105
116
|
*
|
|
106
|
-
* @param
|
|
117
|
+
* @param identifier - [principal].[contract-name]::[asset-name]
|
|
107
118
|
*/
|
|
108
|
-
declare function
|
|
119
|
+
declare function getStacksAssetStringParts(identifier: string): {
|
|
109
120
|
contractAddress: string;
|
|
110
121
|
contractAssetName: string;
|
|
111
122
|
contractName: string;
|
|
@@ -115,7 +126,7 @@ interface SignatureData {
|
|
|
115
126
|
signature: string;
|
|
116
127
|
publicKey: string;
|
|
117
128
|
}
|
|
118
|
-
declare function signMessage(message: string, privateKey:
|
|
119
|
-
declare function signStructuredDataMessage(message: ClarityValue, domain: ClarityValue, privateKey:
|
|
129
|
+
declare function signMessage(message: string, privateKey: PrivateKey): SignatureData;
|
|
130
|
+
declare function signStructuredDataMessage(message: ClarityValue, domain: ClarityValue, privateKey: PrivateKey): SignatureData;
|
|
120
131
|
|
|
121
|
-
export { type StacksSigner, type StacksSignerFn, type StacksUnsignedContractCallOptions, type StacksUnsignedContractDeployOptions, type StacksUnsignedTokenTransferOptions, type StacksUnsignedTransactionOptions, TransactionTypes, cleanHex, createSignFnFromMnemonic, deriveStxPrivateKey, deriveStxPublicKey, extractStacksDerivationPathAccountIndex, generateStacksUnsignedTransaction, generateUnsignedContractCall, generateUnsignedContractDeploy, generateUnsignedStxTokenTransfer, getPostCondition, getPostConditionFromString, getPostConditions, getStacksBurnAddress, getStacksContractAssetName,
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
// src/signer/signer.ts
|
|
2
2
|
import {
|
|
3
|
-
AddressVersion,
|
|
4
3
|
TransactionSigner,
|
|
5
|
-
createStacksPrivateKey as createStacksPrivateKey2,
|
|
6
4
|
createStacksPublicKey,
|
|
7
|
-
|
|
5
|
+
publicKeyToAddressSingleSig
|
|
8
6
|
} from "@stacks/transactions";
|
|
9
7
|
import {
|
|
10
8
|
decomposeDescriptor,
|
|
11
9
|
deriveRootKeychainFromMnemonic,
|
|
12
10
|
extractKeyFromDescriptor
|
|
13
11
|
} from "@leather.io/crypto";
|
|
14
|
-
import { whenNetwork } from "@leather.io/utils";
|
|
15
12
|
|
|
16
13
|
// src/stacks.utils.ts
|
|
17
|
-
import {
|
|
18
|
-
import { compressPrivateKey } from "@stacks/
|
|
19
|
-
import { ChainID, createStacksPrivateKey, getPublicKey } from "@stacks/transactions";
|
|
14
|
+
import { ChainId } from "@stacks/network";
|
|
15
|
+
import { compressPrivateKey, privateKeyToPublic } from "@stacks/transactions";
|
|
20
16
|
import {
|
|
21
17
|
DerivationPathDepth,
|
|
22
18
|
createDescriptor,
|
|
@@ -34,7 +30,10 @@ function extractStacksDerivationPathAccountIndex(path) {
|
|
|
34
30
|
}
|
|
35
31
|
var makeStxDerivationPath = makeAccountIndexDerivationPathFactory(stxDerivationWithAccount);
|
|
36
32
|
function stacksChainIdToCoreNetworkMode(chainId) {
|
|
37
|
-
return whenStacksChainId(chainId)({
|
|
33
|
+
return whenStacksChainId(chainId)({
|
|
34
|
+
[ChainId.Mainnet]: "mainnet",
|
|
35
|
+
[ChainId.Testnet]: "testnet"
|
|
36
|
+
});
|
|
38
37
|
}
|
|
39
38
|
function whenStacksChainId(chainId) {
|
|
40
39
|
return (chainIdMap) => chainIdMap[chainId];
|
|
@@ -43,24 +42,27 @@ function deriveStxPrivateKey({ keychain, index }) {
|
|
|
43
42
|
if (keychain.depth !== DerivationPathDepth.Root) throw new Error("Root keychain must be depth 0");
|
|
44
43
|
const accountKeychain = keychain.derive(makeStxDerivationPath(index));
|
|
45
44
|
assertIsTruthy(accountKeychain.privateKey);
|
|
46
|
-
return
|
|
45
|
+
return compressPrivateKey(accountKeychain.privateKey);
|
|
47
46
|
}
|
|
48
|
-
function deriveStxPublicKey({
|
|
49
|
-
|
|
47
|
+
function deriveStxPublicKey({
|
|
48
|
+
keychain,
|
|
49
|
+
index
|
|
50
|
+
}) {
|
|
51
|
+
return privateKeyToPublic(deriveStxPrivateKey({ keychain, index }));
|
|
50
52
|
}
|
|
51
53
|
function stacksRootKeychainToAccountDescriptor(keychain, accountIndex) {
|
|
52
54
|
const fingerprint = toHexString(keychain.fingerprint);
|
|
53
55
|
const publicKey = deriveStxPublicKey({ keychain, index: accountIndex });
|
|
54
56
|
return createDescriptor(
|
|
55
57
|
createKeyOriginPath(fingerprint, makeStxDerivationPath(accountIndex)),
|
|
56
|
-
|
|
58
|
+
publicKey
|
|
57
59
|
);
|
|
58
60
|
}
|
|
59
|
-
function getStacksBurnAddress(
|
|
60
|
-
switch (
|
|
61
|
-
case
|
|
61
|
+
function getStacksBurnAddress(chainIdChainId) {
|
|
62
|
+
switch (chainIdChainId) {
|
|
63
|
+
case ChainId.Mainnet:
|
|
62
64
|
return "SP00000000000003SCNSJTCSE62ZF4MSE";
|
|
63
|
-
case
|
|
65
|
+
case ChainId.Testnet:
|
|
64
66
|
default:
|
|
65
67
|
return "ST000000000000000000002AMW42H";
|
|
66
68
|
}
|
|
@@ -69,31 +71,44 @@ function cleanHex(hexWithMaybePrefix) {
|
|
|
69
71
|
if (!isString(hexWithMaybePrefix)) return hexWithMaybePrefix;
|
|
70
72
|
return hexWithMaybePrefix.startsWith("0x") ? hexWithMaybePrefix.replace("0x", "") : hexWithMaybePrefix;
|
|
71
73
|
}
|
|
72
|
-
function
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
function getPrincipalFromAssetString(assetString) {
|
|
75
|
+
return assetString.split("::")[0];
|
|
76
|
+
}
|
|
77
|
+
function formatContractId(address, name) {
|
|
78
|
+
return `${address}.${name}`;
|
|
79
|
+
}
|
|
80
|
+
function formatAssetString({
|
|
81
|
+
contractAddress,
|
|
82
|
+
contractName,
|
|
83
|
+
assetName
|
|
84
|
+
}) {
|
|
85
|
+
return `${contractAddress}.${contractName}::${assetName}`;
|
|
86
|
+
}
|
|
87
|
+
function getStacksContractName(identifier) {
|
|
88
|
+
if (identifier.includes(".")) {
|
|
89
|
+
const parts = identifier?.split(".");
|
|
90
|
+
if (identifier.includes("::")) {
|
|
76
91
|
return parts[1].split("::")[0];
|
|
77
92
|
}
|
|
78
93
|
return parts[1];
|
|
79
94
|
}
|
|
80
|
-
return
|
|
95
|
+
return identifier;
|
|
81
96
|
}
|
|
82
|
-
function getStacksContractAssetName(
|
|
83
|
-
if (!
|
|
84
|
-
return
|
|
97
|
+
function getStacksContractAssetName(identifier) {
|
|
98
|
+
if (!identifier.includes("::")) return identifier;
|
|
99
|
+
return identifier.split("::")[1];
|
|
85
100
|
}
|
|
86
|
-
function
|
|
87
|
-
if (!
|
|
101
|
+
function getStacksAssetStringParts(identifier) {
|
|
102
|
+
if (!identifier.includes(".") || !identifier.includes("::")) {
|
|
88
103
|
return {
|
|
89
|
-
contractAddress:
|
|
90
|
-
contractAssetName:
|
|
91
|
-
contractName:
|
|
104
|
+
contractAddress: identifier,
|
|
105
|
+
contractAssetName: identifier,
|
|
106
|
+
contractName: identifier
|
|
92
107
|
};
|
|
93
108
|
}
|
|
94
|
-
const contractAddress =
|
|
95
|
-
const contractAssetName = getStacksContractAssetName(
|
|
96
|
-
const contractName = getStacksContractName(
|
|
109
|
+
const contractAddress = identifier.split(".")[0];
|
|
110
|
+
const contractAssetName = getStacksContractAssetName(identifier);
|
|
111
|
+
const contractName = getStacksContractName(identifier);
|
|
97
112
|
return {
|
|
98
113
|
contractAddress,
|
|
99
114
|
contractAssetName,
|
|
@@ -104,7 +119,7 @@ function getStacksContractIdStringParts(contractId) {
|
|
|
104
119
|
// src/signer/signer.ts
|
|
105
120
|
function signStacksTransaction(tx, privateKey) {
|
|
106
121
|
const signer = new TransactionSigner(tx);
|
|
107
|
-
signer.signOrigin(
|
|
122
|
+
signer.signOrigin(privateKey);
|
|
108
123
|
return tx;
|
|
109
124
|
}
|
|
110
125
|
function createSignFnFromMnemonic(keyOrigin, getMnemonicFn) {
|
|
@@ -120,20 +135,14 @@ function createSignFnFromMnemonic(keyOrigin, getMnemonicFn) {
|
|
|
120
135
|
}
|
|
121
136
|
function initalizeStacksSigner(args) {
|
|
122
137
|
const { descriptor, network, signFn } = args;
|
|
123
|
-
const publicKey = createStacksPublicKey(extractKeyFromDescriptor(descriptor));
|
|
138
|
+
const publicKey = createStacksPublicKey(extractKeyFromDescriptor(descriptor)).data;
|
|
124
139
|
return {
|
|
125
140
|
...decomposeDescriptor(descriptor),
|
|
126
141
|
// here we overwrite the accountIndex with the derivation path account index for stx
|
|
127
142
|
accountIndex: extractStacksDerivationPathAccountIndex(descriptor),
|
|
128
|
-
publicKey
|
|
143
|
+
publicKey,
|
|
129
144
|
network,
|
|
130
|
-
address:
|
|
131
|
-
whenNetwork(network)({
|
|
132
|
-
mainnet: AddressVersion.MainnetSingleSig,
|
|
133
|
-
testnet: AddressVersion.TestnetSingleSig
|
|
134
|
-
}),
|
|
135
|
-
publicKey
|
|
136
|
-
),
|
|
145
|
+
address: publicKeyToAddressSingleSig(publicKey, network),
|
|
137
146
|
sign: signFn
|
|
138
147
|
};
|
|
139
148
|
}
|
|
@@ -151,18 +160,27 @@ import { assertUnreachable } from "@leather.io/utils";
|
|
|
151
160
|
|
|
152
161
|
// src/transactions/post-condition.utils.ts
|
|
153
162
|
import { hexToBytes } from "@noble/hashes/utils";
|
|
154
|
-
import {
|
|
163
|
+
import {
|
|
164
|
+
BytesReader,
|
|
165
|
+
deserializePostConditionWire,
|
|
166
|
+
postConditionToWire
|
|
167
|
+
} from "@stacks/transactions";
|
|
155
168
|
import { isString as isString2 } from "@leather.io/utils";
|
|
156
169
|
function getPostConditionFromString(postCondition) {
|
|
157
170
|
try {
|
|
158
171
|
const reader = new BytesReader(hexToBytes(postCondition));
|
|
159
|
-
return
|
|
172
|
+
return deserializePostConditionWire(reader);
|
|
160
173
|
} catch {
|
|
161
174
|
throw new Error("Not a serialized post condition");
|
|
162
175
|
}
|
|
163
176
|
}
|
|
177
|
+
function ensurePostConditionWireFormat(postCondition) {
|
|
178
|
+
if (isString2(postCondition)) return getPostConditionFromString(postCondition);
|
|
179
|
+
if ("conditionType" in postCondition) return postCondition;
|
|
180
|
+
return postConditionToWire(postCondition);
|
|
181
|
+
}
|
|
164
182
|
function getPostCondition(postCondition) {
|
|
165
|
-
return isString2(postCondition) ? getPostConditionFromString(postCondition) : postCondition;
|
|
183
|
+
return isString2(postCondition) ? getPostConditionFromString(postCondition) : ensurePostConditionWireFormat(postCondition);
|
|
166
184
|
}
|
|
167
185
|
function getPostConditions(postConditions) {
|
|
168
186
|
return postConditions?.map(getPostCondition);
|
|
@@ -190,7 +208,7 @@ function generateUnsignedContractCall(options) {
|
|
|
190
208
|
fee: fee.amount.toString(),
|
|
191
209
|
functionArgs: fnArgs,
|
|
192
210
|
nonce: initNonce(nonce).toString(),
|
|
193
|
-
postConditions
|
|
211
|
+
postConditions
|
|
194
212
|
};
|
|
195
213
|
return makeUnsignedContractCall({ ...options, ...parsedOptions });
|
|
196
214
|
}
|
|
@@ -199,7 +217,7 @@ function generateUnsignedContractDeploy(options) {
|
|
|
199
217
|
const parsedOptions = {
|
|
200
218
|
fee: fee.amount.toString(),
|
|
201
219
|
nonce: initNonce(nonce).toString(),
|
|
202
|
-
postConditions: getPostConditions(postConditions)
|
|
220
|
+
postConditions: getPostConditions(postConditions?.map((pc) => ensurePostConditionWireFormat(pc)))
|
|
203
221
|
};
|
|
204
222
|
return makeUnsignedContractDeploy({ ...options, ...parsedOptions });
|
|
205
223
|
}
|
|
@@ -229,19 +247,18 @@ async function generateStacksUnsignedTransaction(options) {
|
|
|
229
247
|
}
|
|
230
248
|
|
|
231
249
|
// src/message-signing.ts
|
|
232
|
-
import { bytesToHex
|
|
250
|
+
import { bytesToHex } from "@noble/hashes/utils";
|
|
233
251
|
import { hashMessage } from "@stacks/encryption";
|
|
234
252
|
import {
|
|
235
|
-
|
|
236
|
-
publicKeyToString,
|
|
253
|
+
privateKeyToPublic as privateKeyToPublic2,
|
|
237
254
|
signMessageHashRsv,
|
|
238
255
|
signStructuredData
|
|
239
256
|
} from "@stacks/transactions";
|
|
240
257
|
function signMessage(message, privateKey) {
|
|
241
258
|
const hash = hashMessage(message);
|
|
242
259
|
return {
|
|
243
|
-
signature: signMessageHashRsv({ privateKey, messageHash:
|
|
244
|
-
publicKey:
|
|
260
|
+
signature: signMessageHashRsv({ privateKey, messageHash: bytesToHex(hash) }),
|
|
261
|
+
publicKey: privateKeyToPublic2(privateKey)
|
|
245
262
|
};
|
|
246
263
|
}
|
|
247
264
|
function signStructuredDataMessage(message, domain, privateKey) {
|
|
@@ -249,10 +266,10 @@ function signStructuredDataMessage(message, domain, privateKey) {
|
|
|
249
266
|
message,
|
|
250
267
|
domain,
|
|
251
268
|
privateKey
|
|
252
|
-
})
|
|
269
|
+
});
|
|
253
270
|
return {
|
|
254
271
|
signature,
|
|
255
|
-
publicKey:
|
|
272
|
+
publicKey: privateKeyToPublic2(privateKey)
|
|
256
273
|
};
|
|
257
274
|
}
|
|
258
275
|
export {
|
|
@@ -261,7 +278,10 @@ export {
|
|
|
261
278
|
createSignFnFromMnemonic,
|
|
262
279
|
deriveStxPrivateKey,
|
|
263
280
|
deriveStxPublicKey,
|
|
281
|
+
ensurePostConditionWireFormat,
|
|
264
282
|
extractStacksDerivationPathAccountIndex,
|
|
283
|
+
formatAssetString,
|
|
284
|
+
formatContractId,
|
|
265
285
|
generateStacksUnsignedTransaction,
|
|
266
286
|
generateUnsignedContractCall,
|
|
267
287
|
generateUnsignedContractDeploy,
|
|
@@ -269,9 +289,10 @@ export {
|
|
|
269
289
|
getPostCondition,
|
|
270
290
|
getPostConditionFromString,
|
|
271
291
|
getPostConditions,
|
|
292
|
+
getPrincipalFromAssetString,
|
|
293
|
+
getStacksAssetStringParts,
|
|
272
294
|
getStacksBurnAddress,
|
|
273
295
|
getStacksContractAssetName,
|
|
274
|
-
getStacksContractIdStringParts,
|
|
275
296
|
getStacksContractName,
|
|
276
297
|
initNonce,
|
|
277
298
|
initalizeStacksSigner,
|
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 AddressVersion,\n StacksTransaction,\n TransactionSigner,\n createStacksPrivateKey,\n createStacksPublicKey,\n publicKeyToAddress,\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';\nimport { whenNetwork } from '@leather.io/utils';\n\nimport { deriveStxPrivateKey, extractStacksDerivationPathAccountIndex } from '../stacks.utils';\n\n// Warning: mutatitive. Ideally there would be a tx.clone() method\nexport function signStacksTransaction(tx: StacksTransaction, privateKey: string) {\n const signer = new TransactionSigner(tx);\n signer.signOrigin(createStacksPrivateKey(privateKey));\n return tx;\n}\n\nexport type StacksSignerFn = (tx: StacksTransaction) => Promise<StacksTransaction>;\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: StacksTransaction) => {\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));\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.data,\n network,\n address: publicKeyToAddress(\n whenNetwork(network)({\n mainnet: AddressVersion.MainnetSingleSig,\n testnet: AddressVersion.TestnetSingleSig,\n }),\n publicKey\n ),\n sign: signFn,\n };\n}\n","import { bytesToHex } from '@noble/hashes/utils';\nimport { HDKey } from '@scure/bip32';\nimport { compressPrivateKey } from '@stacks/encryption';\nimport { ChainID, createStacksPrivateKey, getPublicKey } 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)({ [ChainID.Mainnet]: 'mainnet', [ChainID.Testnet]: 'testnet' });\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 bytesToHex(compressPrivateKey(accountKeychain.privateKey));\n}\n\nexport function deriveStxPublicKey({ keychain, index }: { keychain: HDKey; index: number }) {\n return getPublicKey(createStacksPrivateKey(deriveStxPrivateKey({ keychain, index })));\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 bytesToHex(publicKey.data)\n );\n}\n\nexport function getStacksBurnAddress(chainId: ChainID): string {\n switch (chainId) {\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\n/**\n * Gets the contract name of a fully qualified name of an asset.\n *\n * @param contractId - the source string: [principal].[contract-name] or [principal].[contract-name]::[asset-name]\n */\nexport function getStacksContractName(contractId: string): string {\n if (contractId.includes('.')) {\n const parts = contractId?.split('.');\n if (contractId.includes('::')) {\n return parts[1].split('::')[0];\n }\n return parts[1];\n }\n return contractId;\n}\n\n/**\n * Gets the asset name from a a fully qualified name of an asset.\n *\n * @param contractId - the fully qualified name of the asset: [principal].[contract-name]::[asset-name]\n */\nexport function getStacksContractAssetName(contractId: string): string {\n if (!contractId.includes('::')) return contractId;\n return contractId.split('::')[1];\n}\n\n/**\n * Gets the parts that make up a fully qualified name of an asset.\n *\n * @param contractId - the fully qualified name of the asset: [principal].[contract-name]::[asset-name]\n */\nexport function getStacksContractIdStringParts(contractId: string): {\n contractAddress: string;\n contractAssetName: string;\n contractName: string;\n} {\n if (!contractId.includes('.') || !contractId.includes('::')) {\n return {\n contractAddress: contractId,\n contractAssetName: contractId,\n contractName: contractId,\n };\n }\n\n const contractAddress = contractId.split('.')[0];\n const contractAssetName = getStacksContractAssetName(contractId);\n const contractName = getStacksContractName(contractId);\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 { 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: getPostConditions(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),\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 { BytesReader, PostCondition, deserializePostCondition } from '@stacks/transactions';\n\nimport { isString } from '@leather.io/utils';\n\nexport function getPostConditionFromString(postCondition: string): PostCondition {\n try {\n const reader = new BytesReader(hexToBytes(postCondition));\n return deserializePostCondition(reader);\n } catch {\n throw new Error('Not a serialized post condition');\n }\n}\n\nexport function getPostCondition(postCondition: string | PostCondition): PostCondition {\n return isString(postCondition) ? getPostConditionFromString(postCondition) : postCondition;\n}\n\nexport function getPostConditions(\n postConditions?: (string | PostCondition)[]\n): PostCondition[] | 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 { hashMessage } from '@stacks/encryption';\nimport {\n ClarityValue,\n StacksPrivateKey,\n getPublicKey,\n publicKeyToString,\n signMessageHashRsv,\n signStructuredData,\n} from '@stacks/transactions';\n\ninterface SignatureData {\n signature: string;\n publicKey: string;\n}\n\nexport function signMessage(message: string, privateKey: StacksPrivateKey): SignatureData {\n const hash = hashMessage(message);\n return {\n signature: signMessageHashRsv({ privateKey, messageHash: bytesToHex(hash) }).data,\n publicKey: publicKeyToString(getPublicKey(privateKey)),\n };\n}\n\nexport function signStructuredDataMessage(\n message: ClarityValue,\n domain: ClarityValue,\n privateKey: StacksPrivateKey\n): SignatureData {\n const signature = signStructuredData({\n message,\n domain,\n privateKey,\n }).data;\n\n return {\n signature,\n publicKey: publicKeyToString(getPublicKey(privateKey)),\n };\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EAEA;AAAA,EACA,0BAAAA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,mBAAmB;;;AChB5B,SAAS,kBAAkB;AAE3B,SAAS,0BAA0B;AACnC,SAAS,SAAS,wBAAwB,oBAAoB;AAE9D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,gBAAgB,UAAU,mBAAmB;AAE/C,IAAM,2BAA2B;AAEjC,SAAS,sCAAsC,gBAAwB;AAC5E,SAAO,CAAC,YAAoB,eAAe,QAAQ,aAAa,QAAQ,SAAS,CAAC;AACpF;AAEO,SAAS,wCAAwC,MAAc;AACpE,MAAI,CAA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AA,EAC5B;AACF;;;AGlFA,SAAS,cAAAC,mBAAkB;AAC3B,SAAS,mBAAmB;AAC5B;AAAA,EAGE,gBAAAC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAOA,SAAS,YAAY,SAAiB,YAA6C;AACxF,QAAM,OAAO,YAAY,OAAO;AAChC,SAAO;AAAA,IACL,WAAW,mBAAmB,EAAE,YAAY,aAAaD,YAAW,IAAI,EAAE,CAAC,EAAE;AAAA,IAC7E,WAAW,kBAAkBC,cAAa,UAAU,CAAC;AAAA,EACvD;AACF;AAEO,SAAS,0BACd,SACA,QACA,YACe;AACf,QAAM,YAAY,mBAAmB;AAAA,IACnC;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC,EAAE;AAEH,SAAO;AAAA,IACL;AAAA,IACA,WAAW,kBAAkBA,cAAa,UAAU,CAAC;AAAA,EACvD;AACF;","names":["createStacksPrivateKey","createStacksPrivateKey","hexToBytes","isString","TransactionTypes","hexToBytes","bytesToHex","getPublicKey"]}
|
|
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(privateKey) as string,\n };\n}\n"],"mappings":";AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACXP,SAAS,eAAe;AACxB,SAAsB,oBAAoB,0BAA0B;AAEpE;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,gBAAgB,UAAU,mBAAmB;AAE/C,IAAM,2BAA2B;AAEjC,SAAS,sCAAsC,gBAAwB;AAC5E,SAAO,CAAC,YAAoB,eAAe,QAAQ,aAAa,QAAQ,SAAS,CAAC;AACpF;AAEO,SAAS,wCAAwC,MAAc;AACpE,MAAI,CAAC,KAAK,SAAS,MAAM,EAAG,OAAM,IAAI,MAAM,yCAAyC,IAAI;AACzF,SAAO,4BAA4B,IAAI;AACzC;AAKO,IAAM,wBACX,sCAAsC,wBAAwB;AAEzD,SAAS,+BAA+B,SAAgC;AAC7E,SAAO,kBAAkB,OAAO,EAAE;AAAA,IAChC,CAAC,QAAQ,OAAO,GAAG;A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;AACE,aAAO,6BAA6B,OAAO;AAAA,IAC7C;AACE,aAAO,+BAA+B,OAAO;AAAA,IAC/C;AACE,wBAAkB,MAAM;AAAA,EAC5B;AACF;;;AGlFA,SAAS,kBAAkB;AAE3B,SAAS,mBAAmB;AAC5B;AAAA,EAEE,sBAAAC;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,WAAWA,oBAAmB,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,WAAWA,oBAAmB,UAAU;AAAA,EAC1C;AACF;","names":["hexToBytes","isString","TransactionTypes","hexToBytes","privateKeyToPublic"]}
|
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.
|
|
5
|
+
"version": "1.5.19",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"exports": {
|
|
@@ -11,15 +11,16 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@noble/hashes": "1.5.0",
|
|
13
13
|
"@scure/bip32": "1.5.0",
|
|
14
|
-
"@stacks/
|
|
15
|
-
"@stacks/
|
|
14
|
+
"@stacks/common": "7.0.2",
|
|
15
|
+
"@stacks/encryption": "7.0.2",
|
|
16
|
+
"@stacks/network": "7.0.2",
|
|
16
17
|
"@stacks/stacks-blockchain-api-types": "7.8.2",
|
|
17
|
-
"@stacks/transactions": "
|
|
18
|
+
"@stacks/transactions": "7.0.2",
|
|
18
19
|
"bignumber.js": "9.1.2",
|
|
19
|
-
"@leather.io/
|
|
20
|
-
"@leather.io/constants": "0.15.
|
|
21
|
-
"@leather.io/
|
|
22
|
-
"@leather.io/
|
|
20
|
+
"@leather.io/models": "0.25.1",
|
|
21
|
+
"@leather.io/constants": "0.15.5",
|
|
22
|
+
"@leather.io/utils": "0.25.1",
|
|
23
|
+
"@leather.io/crypto": "1.6.34"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
26
|
"tsup": "8.1.0",
|