@t402/stacks 2.4.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/README.md +178 -0
- package/dist/exact-direct/client/index.cjs +167 -0
- package/dist/exact-direct/client/index.cjs.map +1 -0
- package/dist/exact-direct/client/index.d.cts +39 -0
- package/dist/exact-direct/client/index.d.ts +39 -0
- package/dist/exact-direct/client/index.mjs +139 -0
- package/dist/exact-direct/client/index.mjs.map +1 -0
- package/dist/exact-direct/facilitator/index.cjs +395 -0
- package/dist/exact-direct/facilitator/index.cjs.map +1 -0
- package/dist/exact-direct/facilitator/index.d.cts +55 -0
- package/dist/exact-direct/facilitator/index.d.ts +55 -0
- package/dist/exact-direct/facilitator/index.mjs +367 -0
- package/dist/exact-direct/facilitator/index.mjs.map +1 -0
- package/dist/exact-direct/server/index.cjs +247 -0
- package/dist/exact-direct/server/index.cjs.map +1 -0
- package/dist/exact-direct/server/index.d.cts +109 -0
- package/dist/exact-direct/server/index.d.ts +109 -0
- package/dist/exact-direct/server/index.mjs +218 -0
- package/dist/exact-direct/server/index.mjs.map +1 -0
- package/dist/index.cjs +261 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +126 -0
- package/dist/index.d.ts +126 -0
- package/dist/index.mjs +212 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types-Bxzo3eQ1.d.cts +172 -0
- package/dist/types-Bxzo3eQ1.d.ts +172 -0
- package/package.json +102 -0
- package/src/constants.ts +66 -0
- package/src/exact-direct/client/index.ts +5 -0
- package/src/exact-direct/client/scheme.ts +115 -0
- package/src/exact-direct/facilitator/index.ts +4 -0
- package/src/exact-direct/facilitator/scheme.ts +308 -0
- package/src/exact-direct/server/index.ts +9 -0
- package/src/exact-direct/server/register.ts +57 -0
- package/src/exact-direct/server/scheme.ts +216 -0
- package/src/index.ts +78 -0
- package/src/tokens.ts +96 -0
- package/src/types.ts +184 -0
- package/src/utils.ts +198 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
// src/constants.ts
|
|
2
|
+
var STACKS_CAIP2_NAMESPACE = "stacks";
|
|
3
|
+
var STACKS_MAINNET_CAIP2 = "stacks:1";
|
|
4
|
+
var STACKS_TESTNET_CAIP2 = "stacks:2147483648";
|
|
5
|
+
var SCHEME_EXACT_DIRECT = "exact-direct";
|
|
6
|
+
var DEFAULT_MAINNET_API = "https://api.mainnet.hiro.so";
|
|
7
|
+
var DEFAULT_TESTNET_API = "https://api.testnet.hiro.so";
|
|
8
|
+
var STACKS_NETWORKS = {
|
|
9
|
+
[STACKS_MAINNET_CAIP2]: {
|
|
10
|
+
name: "Stacks Mainnet",
|
|
11
|
+
caip2: STACKS_MAINNET_CAIP2,
|
|
12
|
+
apiUrl: DEFAULT_MAINNET_API,
|
|
13
|
+
chainId: 1,
|
|
14
|
+
addressPrefix: "SP",
|
|
15
|
+
isTestnet: false
|
|
16
|
+
},
|
|
17
|
+
[STACKS_TESTNET_CAIP2]: {
|
|
18
|
+
name: "Stacks Testnet",
|
|
19
|
+
caip2: STACKS_TESTNET_CAIP2,
|
|
20
|
+
apiUrl: DEFAULT_TESTNET_API,
|
|
21
|
+
chainId: 2147483648,
|
|
22
|
+
addressPrefix: "ST",
|
|
23
|
+
isTestnet: true
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
function getNetworkConfig(network) {
|
|
27
|
+
return STACKS_NETWORKS[network];
|
|
28
|
+
}
|
|
29
|
+
function isStacksNetwork(network) {
|
|
30
|
+
return network.startsWith(`${STACKS_CAIP2_NAMESPACE}:`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/tokens.ts
|
|
34
|
+
var SUSDC_MAINNET = {
|
|
35
|
+
contractAddress: "SP3Y2ZSH8P7D50B0VBTSX11S7XSG24M1VB9YFQA4K.token-susdc",
|
|
36
|
+
symbol: "sUSDC",
|
|
37
|
+
name: "Stacks USDC",
|
|
38
|
+
decimals: 6,
|
|
39
|
+
issuer: "Stacks"
|
|
40
|
+
};
|
|
41
|
+
var SUSDC_TESTNET = {
|
|
42
|
+
contractAddress: "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.token-susdc",
|
|
43
|
+
symbol: "sUSDC",
|
|
44
|
+
name: "Test Stacks USDC",
|
|
45
|
+
decimals: 6
|
|
46
|
+
};
|
|
47
|
+
var TOKEN_REGISTRY = {
|
|
48
|
+
[STACKS_MAINNET_CAIP2]: {
|
|
49
|
+
sUSDC: SUSDC_MAINNET
|
|
50
|
+
},
|
|
51
|
+
[STACKS_TESTNET_CAIP2]: {
|
|
52
|
+
sUSDC: SUSDC_TESTNET
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var DEFAULT_TOKENS = {
|
|
56
|
+
[STACKS_MAINNET_CAIP2]: SUSDC_MAINNET,
|
|
57
|
+
[STACKS_TESTNET_CAIP2]: SUSDC_TESTNET
|
|
58
|
+
};
|
|
59
|
+
function getTokenConfig(network, symbol = "sUSDC") {
|
|
60
|
+
return TOKEN_REGISTRY[network]?.[symbol];
|
|
61
|
+
}
|
|
62
|
+
function getDefaultToken(network) {
|
|
63
|
+
return DEFAULT_TOKENS[network];
|
|
64
|
+
}
|
|
65
|
+
function getContractAddress(network, symbol = "sUSDC") {
|
|
66
|
+
return getTokenConfig(network, symbol)?.contractAddress;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// src/utils.ts
|
|
70
|
+
function isValidPrincipal(address) {
|
|
71
|
+
if (!address || typeof address !== "string") {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
const parts = address.split(".");
|
|
75
|
+
const principal = parts[0];
|
|
76
|
+
const principalRegex = /^(SP|ST)[0-9A-HJ-NP-Za-km-z]{33,41}$/;
|
|
77
|
+
if (!principalRegex.test(principal)) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
if (parts.length === 2) {
|
|
81
|
+
const contractName = parts[1];
|
|
82
|
+
const contractNameRegex = /^[a-zA-Z][a-zA-Z0-9\-_]{0,127}$/;
|
|
83
|
+
return contractNameRegex.test(contractName);
|
|
84
|
+
}
|
|
85
|
+
return parts.length === 1;
|
|
86
|
+
}
|
|
87
|
+
function isValidTxId(hash) {
|
|
88
|
+
if (!hash || typeof hash !== "string") {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
return /^0x[a-fA-F0-9]{64}$/.test(hash);
|
|
92
|
+
}
|
|
93
|
+
function comparePrincipals(a, b) {
|
|
94
|
+
return a === b;
|
|
95
|
+
}
|
|
96
|
+
function formatAmount(amount, decimals) {
|
|
97
|
+
const amountBigInt = BigInt(amount);
|
|
98
|
+
const divisor = BigInt(10 ** decimals);
|
|
99
|
+
const wholePart = amountBigInt / divisor;
|
|
100
|
+
const fractionalPart = amountBigInt % divisor;
|
|
101
|
+
if (fractionalPart === 0n) {
|
|
102
|
+
return wholePart.toString();
|
|
103
|
+
}
|
|
104
|
+
const fractionalStr = fractionalPart.toString().padStart(decimals, "0");
|
|
105
|
+
const trimmedFractional = fractionalStr.replace(/0+$/, "");
|
|
106
|
+
return `${wholePart}.${trimmedFractional}`;
|
|
107
|
+
}
|
|
108
|
+
function parseAmount(amount, decimals) {
|
|
109
|
+
const parts = amount.split(".");
|
|
110
|
+
const wholePart = parts[0] || "0";
|
|
111
|
+
const fractionalPart = (parts[1] || "").padEnd(decimals, "0").slice(0, decimals);
|
|
112
|
+
return BigInt(wholePart + fractionalPart).toString();
|
|
113
|
+
}
|
|
114
|
+
function extractTokenTransfer(result, contractAddress) {
|
|
115
|
+
if (result.txStatus !== "success") {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
if (result.txType !== "contract_call") {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
if (result.contractCall) {
|
|
122
|
+
const { contractId, functionName } = result.contractCall;
|
|
123
|
+
if (functionName !== "transfer") {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
if (contractAddress && contractId !== contractAddress) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
const transferEvent = result.events.find(
|
|
130
|
+
(e) => e.eventType === "fungible_token_asset" && e.asset?.assetEventType === "transfer"
|
|
131
|
+
);
|
|
132
|
+
if (transferEvent?.asset) {
|
|
133
|
+
return {
|
|
134
|
+
contractAddress: contractId,
|
|
135
|
+
from: transferEvent.asset.sender,
|
|
136
|
+
to: transferEvent.asset.recipient,
|
|
137
|
+
amount: transferEvent.asset.amount,
|
|
138
|
+
success: true
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
if (result.contractCall.functionArgs.length >= 3) {
|
|
142
|
+
const amountArg = result.contractCall.functionArgs[0];
|
|
143
|
+
const senderArg = result.contractCall.functionArgs[1];
|
|
144
|
+
const recipientArg = result.contractCall.functionArgs[2];
|
|
145
|
+
const senderMatch = senderArg?.repr?.match(/^'?(S[PT][0-9A-HJ-NP-Za-km-z]+)/);
|
|
146
|
+
const recipientMatch = recipientArg?.repr?.match(/^'?(S[PT][0-9A-HJ-NP-Za-km-z]+)/);
|
|
147
|
+
const amountMatch = amountArg?.repr?.match(/^u(\d+)$/);
|
|
148
|
+
if (senderMatch && recipientMatch && amountMatch) {
|
|
149
|
+
return {
|
|
150
|
+
contractAddress: contractId,
|
|
151
|
+
from: senderMatch[1],
|
|
152
|
+
to: recipientMatch[1],
|
|
153
|
+
amount: amountMatch[1],
|
|
154
|
+
success: true
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
function extractTokenTransferFromPostConditions(result, contractAddress) {
|
|
162
|
+
if (result.txStatus !== "success") {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
for (const pc of result.postConditions) {
|
|
166
|
+
if (pc.asset) {
|
|
167
|
+
const assetContractAddress = `${pc.asset.contractAddress}.${pc.asset.contractName}`;
|
|
168
|
+
if (contractAddress && assetContractAddress !== contractAddress) {
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
const transferEvent = result.events.find(
|
|
172
|
+
(e) => e.eventType === "fungible_token_asset" && e.asset?.assetEventType === "transfer" && e.asset?.sender === pc.principal.address
|
|
173
|
+
);
|
|
174
|
+
if (transferEvent?.asset) {
|
|
175
|
+
return {
|
|
176
|
+
contractAddress: assetContractAddress,
|
|
177
|
+
from: transferEvent.asset.sender,
|
|
178
|
+
to: transferEvent.asset.recipient,
|
|
179
|
+
amount: transferEvent.asset.amount,
|
|
180
|
+
success: true
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
export {
|
|
188
|
+
DEFAULT_MAINNET_API,
|
|
189
|
+
DEFAULT_TESTNET_API,
|
|
190
|
+
DEFAULT_TOKENS,
|
|
191
|
+
SCHEME_EXACT_DIRECT,
|
|
192
|
+
STACKS_CAIP2_NAMESPACE,
|
|
193
|
+
STACKS_MAINNET_CAIP2,
|
|
194
|
+
STACKS_NETWORKS,
|
|
195
|
+
STACKS_TESTNET_CAIP2,
|
|
196
|
+
SUSDC_MAINNET,
|
|
197
|
+
SUSDC_TESTNET,
|
|
198
|
+
TOKEN_REGISTRY,
|
|
199
|
+
comparePrincipals,
|
|
200
|
+
extractTokenTransfer,
|
|
201
|
+
extractTokenTransferFromPostConditions,
|
|
202
|
+
formatAmount,
|
|
203
|
+
getContractAddress,
|
|
204
|
+
getDefaultToken,
|
|
205
|
+
getNetworkConfig,
|
|
206
|
+
getTokenConfig,
|
|
207
|
+
isStacksNetwork,
|
|
208
|
+
isValidPrincipal,
|
|
209
|
+
isValidTxId,
|
|
210
|
+
parseAmount
|
|
211
|
+
};
|
|
212
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts","../src/tokens.ts","../src/utils.ts"],"sourcesContent":["/**\n * Stacks T402 Constants\n *\n * Stacks is a Bitcoin Layer 2 that brings smart contracts and DeFi\n * to Bitcoin. SIP-010 is the fungible token standard on Stacks.\n */\n\n// CAIP-2 namespace for Stacks\nexport const STACKS_CAIP2_NAMESPACE = \"stacks\";\n\n// CAIP-2 network identifiers\n// Stacks Mainnet (chain ID: 1)\nexport const STACKS_MAINNET_CAIP2 = \"stacks:1\";\n\n// Stacks Testnet (chain ID: 2147483648)\nexport const STACKS_TESTNET_CAIP2 = \"stacks:2147483648\";\n\n// Scheme identifier\nexport const SCHEME_EXACT_DIRECT = \"exact-direct\";\n\n// Default API endpoints (Hiro API)\nexport const DEFAULT_MAINNET_API = \"https://api.mainnet.hiro.so\";\nexport const DEFAULT_TESTNET_API = \"https://api.testnet.hiro.so\";\n\n// Network configurations\nexport interface StacksNetworkConfig {\n readonly name: string;\n readonly caip2: string;\n readonly apiUrl: string;\n readonly chainId: number;\n readonly addressPrefix: string;\n readonly isTestnet: boolean;\n}\n\nexport const STACKS_NETWORKS: Record<string, StacksNetworkConfig> = {\n [STACKS_MAINNET_CAIP2]: {\n name: \"Stacks Mainnet\",\n caip2: STACKS_MAINNET_CAIP2,\n apiUrl: DEFAULT_MAINNET_API,\n chainId: 1,\n addressPrefix: \"SP\",\n isTestnet: false,\n },\n [STACKS_TESTNET_CAIP2]: {\n name: \"Stacks Testnet\",\n caip2: STACKS_TESTNET_CAIP2,\n apiUrl: DEFAULT_TESTNET_API,\n chainId: 2147483648,\n addressPrefix: \"ST\",\n isTestnet: true,\n },\n};\n\n/**\n * Get network configuration by CAIP-2 identifier\n */\nexport function getNetworkConfig(network: string): StacksNetworkConfig | undefined {\n return STACKS_NETWORKS[network];\n}\n\n/**\n * Check if a network identifier is a Stacks network\n */\nexport function isStacksNetwork(network: string): boolean {\n return network.startsWith(`${STACKS_CAIP2_NAMESPACE}:`);\n}\n","/**\n * Stacks Token Registry\n *\n * On Stacks, tokens are SIP-010 fungible tokens identified by\n * their contract address (principal.contract-name).\n */\n\nimport {\n STACKS_MAINNET_CAIP2,\n STACKS_TESTNET_CAIP2,\n} from \"./constants.js\";\n\n/**\n * Token configuration for Stacks SIP-010 tokens\n */\nexport interface TokenConfig {\n /** Contract address (principal.contract-name) */\n readonly contractAddress: string;\n /** Token symbol */\n readonly symbol: string;\n /** Token name */\n readonly name: string;\n /** Decimal places */\n readonly decimals: number;\n /** Token issuer */\n readonly issuer?: string;\n}\n\n/**\n * sUSDC on Stacks Mainnet\n * Contract: SP3Y2ZSH8P7D50B0VBTSX11S7XSG24M1VB9YFQA4K.token-susdc\n * Decimals: 6\n */\nexport const SUSDC_MAINNET: TokenConfig = {\n contractAddress: \"SP3Y2ZSH8P7D50B0VBTSX11S7XSG24M1VB9YFQA4K.token-susdc\",\n symbol: \"sUSDC\",\n name: \"Stacks USDC\",\n decimals: 6,\n issuer: \"Stacks\",\n};\n\n/**\n * sUSDC on Stacks Testnet\n * Contract: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.token-susdc\n * Decimals: 6\n */\nexport const SUSDC_TESTNET: TokenConfig = {\n contractAddress: \"ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.token-susdc\",\n symbol: \"sUSDC\",\n name: \"Test Stacks USDC\",\n decimals: 6,\n};\n\n/**\n * Network-specific token registries\n */\nexport const TOKEN_REGISTRY: Record<string, Record<string, TokenConfig>> = {\n [STACKS_MAINNET_CAIP2]: {\n sUSDC: SUSDC_MAINNET,\n },\n [STACKS_TESTNET_CAIP2]: {\n sUSDC: SUSDC_TESTNET,\n },\n};\n\n/**\n * Default tokens per network\n */\nexport const DEFAULT_TOKENS: Record<string, TokenConfig> = {\n [STACKS_MAINNET_CAIP2]: SUSDC_MAINNET,\n [STACKS_TESTNET_CAIP2]: SUSDC_TESTNET,\n};\n\n/**\n * Get token configuration by network and symbol\n */\nexport function getTokenConfig(\n network: string,\n symbol: string = \"sUSDC\",\n): TokenConfig | undefined {\n return TOKEN_REGISTRY[network]?.[symbol];\n}\n\n/**\n * Get the default token for a network\n */\nexport function getDefaultToken(network: string): TokenConfig | undefined {\n return DEFAULT_TOKENS[network];\n}\n\n/**\n * Get contract address for a token on a network\n */\nexport function getContractAddress(network: string, symbol: string = \"sUSDC\"): string | undefined {\n return getTokenConfig(network, symbol)?.contractAddress;\n}\n","/**\n * Stacks Utility Functions\n */\n\nimport type { StacksTransactionResult, ParsedTokenTransfer } from \"./types.js\";\n\n/**\n * Validate a Stacks principal address format\n * Stacks addresses start with SP (mainnet) or ST (testnet)\n * followed by alphanumeric characters (base58-like encoding)\n */\nexport function isValidPrincipal(address: string): boolean {\n if (!address || typeof address !== \"string\") {\n return false;\n }\n\n // Standard principal: SP/ST prefix + base58 characters (33-41 chars total)\n // Contract principal: standard-principal.contract-name\n const parts = address.split(\".\");\n const principal = parts[0];\n\n // Check principal format: SP or ST prefix + alphanumeric (base58 chars)\n const principalRegex = /^(SP|ST)[0-9A-HJ-NP-Za-km-z]{33,41}$/;\n if (!principalRegex.test(principal)) {\n return false;\n }\n\n // If it's a contract principal, validate contract name\n if (parts.length === 2) {\n const contractName = parts[1];\n // Contract names: 1-128 chars, alphanumeric + hyphen + underscore\n const contractNameRegex = /^[a-zA-Z][a-zA-Z0-9\\-_]{0,127}$/;\n return contractNameRegex.test(contractName);\n }\n\n // Standard principal (no contract part) or exactly one dot for contract\n return parts.length === 1;\n}\n\n/**\n * Validate a Stacks transaction ID format\n * Transaction IDs are 0x-prefixed 64-character hex strings\n */\nexport function isValidTxId(hash: string): boolean {\n if (!hash || typeof hash !== \"string\") {\n return false;\n }\n return /^0x[a-fA-F0-9]{64}$/.test(hash);\n}\n\n/**\n * Compare two Stacks principals (case-sensitive)\n */\nexport function comparePrincipals(a: string, b: string): boolean {\n return a === b;\n}\n\n/**\n * Format an amount with decimals for display\n */\nexport function formatAmount(amount: string, decimals: number): string {\n const amountBigInt = BigInt(amount);\n const divisor = BigInt(10 ** decimals);\n const wholePart = amountBigInt / divisor;\n const fractionalPart = amountBigInt % divisor;\n\n if (fractionalPart === 0n) {\n return wholePart.toString();\n }\n\n const fractionalStr = fractionalPart.toString().padStart(decimals, \"0\");\n const trimmedFractional = fractionalStr.replace(/0+$/, \"\");\n return `${wholePart}.${trimmedFractional}`;\n}\n\n/**\n * Parse an amount string to the smallest unit (with decimals applied)\n */\nexport function parseAmount(amount: string, decimals: number): string {\n const parts = amount.split(\".\");\n const wholePart = parts[0] || \"0\";\n const fractionalPart = (parts[1] || \"\").padEnd(decimals, \"0\").slice(0, decimals);\n return BigInt(wholePart + fractionalPart).toString();\n}\n\n/**\n * Extract token transfer details from a Stacks transaction result\n * Looks for ft_transfer events matching the expected contract\n */\nexport function extractTokenTransfer(\n result: StacksTransactionResult,\n contractAddress?: string,\n): ParsedTokenTransfer | null {\n if (result.txStatus !== \"success\") {\n return null;\n }\n\n // Check if this is a contract-call transaction\n if (result.txType !== \"contract_call\") {\n return null;\n }\n\n // Check contract call is a transfer function\n if (result.contractCall) {\n const { contractId, functionName } = result.contractCall;\n\n if (functionName !== \"transfer\") {\n return null;\n }\n\n // If contractAddress specified, verify it matches\n if (contractAddress && contractId !== contractAddress) {\n return null;\n }\n\n // Look for ft_transfer event\n const transferEvent = result.events.find(\n (e) => e.eventType === \"fungible_token_asset\" && e.asset?.assetEventType === \"transfer\",\n );\n\n if (transferEvent?.asset) {\n return {\n contractAddress: contractId,\n from: transferEvent.asset.sender,\n to: transferEvent.asset.recipient,\n amount: transferEvent.asset.amount,\n success: true,\n };\n }\n\n // Fallback: extract from function args if events not available\n if (result.contractCall.functionArgs.length >= 3) {\n const amountArg = result.contractCall.functionArgs[0];\n const senderArg = result.contractCall.functionArgs[1];\n const recipientArg = result.contractCall.functionArgs[2];\n\n // Parse principal from repr (format: 'SP...')\n const senderMatch = senderArg?.repr?.match(/^'?(S[PT][0-9A-HJ-NP-Za-km-z]+)/);\n const recipientMatch = recipientArg?.repr?.match(/^'?(S[PT][0-9A-HJ-NP-Za-km-z]+)/);\n const amountMatch = amountArg?.repr?.match(/^u(\\d+)$/);\n\n if (senderMatch && recipientMatch && amountMatch) {\n return {\n contractAddress: contractId,\n from: senderMatch[1],\n to: recipientMatch[1],\n amount: amountMatch[1],\n success: true,\n };\n }\n }\n }\n\n return null;\n}\n\n/**\n * Extract token transfer from post conditions (alternative method)\n */\nexport function extractTokenTransferFromPostConditions(\n result: StacksTransactionResult,\n contractAddress?: string,\n): ParsedTokenTransfer | null {\n if (result.txStatus !== \"success\") {\n return null;\n }\n\n // Look for fungible token post conditions\n for (const pc of result.postConditions) {\n if (pc.asset) {\n const assetContractAddress = `${pc.asset.contractAddress}.${pc.asset.contractName}`;\n\n if (contractAddress && assetContractAddress !== contractAddress) {\n continue;\n }\n\n // Find corresponding ft_transfer event for recipient\n const transferEvent = result.events.find(\n (e) =>\n e.eventType === \"fungible_token_asset\" &&\n e.asset?.assetEventType === \"transfer\" &&\n e.asset?.sender === pc.principal.address,\n );\n\n if (transferEvent?.asset) {\n return {\n contractAddress: assetContractAddress,\n from: transferEvent.asset.sender,\n to: transferEvent.asset.recipient,\n amount: transferEvent.asset.amount,\n success: true,\n };\n }\n }\n }\n\n return null;\n}\n"],"mappings":";AAQO,IAAM,yBAAyB;AAI/B,IAAM,uBAAuB;AAG7B,IAAM,uBAAuB;AAG7B,IAAM,sBAAsB;AAG5B,IAAM,sBAAsB;AAC5B,IAAM,sBAAsB;AAY5B,IAAM,kBAAuD;AAAA,EAClE,CAAC,oBAAoB,GAAG;AAAA,IACtB,MAAM;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,eAAe;AAAA,IACf,WAAW;AAAA,EACb;AAAA,EACA,CAAC,oBAAoB,GAAG;AAAA,IACtB,MAAM;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,eAAe;AAAA,IACf,WAAW;AAAA,EACb;AACF;AAKO,SAAS,iBAAiB,SAAkD;AACjF,SAAO,gBAAgB,OAA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UAC5B,SAAS;AAAA,QACX;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { Network } from '@t402/core/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Stacks T402 Types
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Payment payload for exact-direct scheme on Stacks
|
|
9
|
+
*/
|
|
10
|
+
type ExactDirectStacksPayload = {
|
|
11
|
+
/** Transaction ID (0x-prefixed hex, 64 chars) */
|
|
12
|
+
txId: string;
|
|
13
|
+
/** Sender address (Stacks principal) */
|
|
14
|
+
from: string;
|
|
15
|
+
/** Recipient address (Stacks principal) */
|
|
16
|
+
to: string;
|
|
17
|
+
/** Amount in smallest unit (atomic) */
|
|
18
|
+
amount: string;
|
|
19
|
+
/** SIP-010 contract address (principal.contract-name) */
|
|
20
|
+
contractAddress: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Result of a Stacks transaction query from Hiro API
|
|
24
|
+
*/
|
|
25
|
+
interface StacksTransactionResult {
|
|
26
|
+
/** Transaction ID */
|
|
27
|
+
txId: string;
|
|
28
|
+
/** Transaction type */
|
|
29
|
+
txType: string;
|
|
30
|
+
/** Transaction status */
|
|
31
|
+
txStatus: "success" | "abort_by_response" | "abort_by_post_condition" | "pending";
|
|
32
|
+
/** Block hash */
|
|
33
|
+
blockHash: string;
|
|
34
|
+
/** Block height */
|
|
35
|
+
blockHeight: number;
|
|
36
|
+
/** Burn block time (unix timestamp) */
|
|
37
|
+
burnBlockTime: number;
|
|
38
|
+
/** Sender address */
|
|
39
|
+
senderAddress: string;
|
|
40
|
+
/** Contract call details (for contract-call transactions) */
|
|
41
|
+
contractCall?: StacksContractCall;
|
|
42
|
+
/** Post-condition mode */
|
|
43
|
+
postConditionMode: string;
|
|
44
|
+
/** Post conditions */
|
|
45
|
+
postConditions: StacksPostCondition[];
|
|
46
|
+
/** Events */
|
|
47
|
+
events: StacksEvent[];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Stacks contract call details
|
|
51
|
+
*/
|
|
52
|
+
interface StacksContractCall {
|
|
53
|
+
/** Contract ID (principal.contract-name) */
|
|
54
|
+
contractId: string;
|
|
55
|
+
/** Function name */
|
|
56
|
+
functionName: string;
|
|
57
|
+
/** Function arguments */
|
|
58
|
+
functionArgs: StacksFunctionArg[];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Stacks function argument
|
|
62
|
+
*/
|
|
63
|
+
interface StacksFunctionArg {
|
|
64
|
+
/** Hex-encoded value */
|
|
65
|
+
hex: string;
|
|
66
|
+
/** Human-readable representation */
|
|
67
|
+
repr: string;
|
|
68
|
+
/** Argument type */
|
|
69
|
+
type: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Stacks post condition
|
|
73
|
+
*/
|
|
74
|
+
interface StacksPostCondition {
|
|
75
|
+
/** Principal (sender) */
|
|
76
|
+
principal: {
|
|
77
|
+
type_id: string;
|
|
78
|
+
address: string;
|
|
79
|
+
contract_name?: string;
|
|
80
|
+
};
|
|
81
|
+
/** Condition code */
|
|
82
|
+
conditionCode: string;
|
|
83
|
+
/** Amount */
|
|
84
|
+
amount: string;
|
|
85
|
+
/** Asset info */
|
|
86
|
+
asset?: {
|
|
87
|
+
contractAddress: string;
|
|
88
|
+
contractName: string;
|
|
89
|
+
assetName: string;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Stacks transaction event
|
|
94
|
+
*/
|
|
95
|
+
interface StacksEvent {
|
|
96
|
+
/** Event type */
|
|
97
|
+
eventType: string;
|
|
98
|
+
/** Event index */
|
|
99
|
+
eventIndex: number;
|
|
100
|
+
/** Fungible token transfer asset event (for ft_transfer events) */
|
|
101
|
+
asset?: {
|
|
102
|
+
assetEventType: string;
|
|
103
|
+
assetId: string;
|
|
104
|
+
sender: string;
|
|
105
|
+
recipient: string;
|
|
106
|
+
amount: string;
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Parsed token transfer from transaction events
|
|
111
|
+
*/
|
|
112
|
+
interface ParsedTokenTransfer {
|
|
113
|
+
/** Contract address (principal.contract-name) */
|
|
114
|
+
contractAddress: string;
|
|
115
|
+
/** Sender address */
|
|
116
|
+
from: string;
|
|
117
|
+
/** Recipient address */
|
|
118
|
+
to: string;
|
|
119
|
+
/** Amount transferred (atomic units) */
|
|
120
|
+
amount: string;
|
|
121
|
+
/** Whether the transfer was successful */
|
|
122
|
+
success: boolean;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Signer interface for Stacks facilitator
|
|
126
|
+
*/
|
|
127
|
+
interface FacilitatorStacksSigner {
|
|
128
|
+
/**
|
|
129
|
+
* Get the facilitator's addresses for a network
|
|
130
|
+
*/
|
|
131
|
+
getAddresses(network: Network): string[];
|
|
132
|
+
/**
|
|
133
|
+
* Query a transaction by ID from Hiro API
|
|
134
|
+
*/
|
|
135
|
+
queryTransaction(txId: string): Promise<StacksTransactionResult | null>;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Client signer interface for signing transactions
|
|
139
|
+
*/
|
|
140
|
+
interface ClientStacksSigner {
|
|
141
|
+
/**
|
|
142
|
+
* Get the signer's address
|
|
143
|
+
*/
|
|
144
|
+
getAddress(): Promise<string>;
|
|
145
|
+
/**
|
|
146
|
+
* Sign and submit a SIP-010 token transfer
|
|
147
|
+
* Returns the transaction ID
|
|
148
|
+
*/
|
|
149
|
+
transferToken(contractAddress: string, to: string, amount: string): Promise<{
|
|
150
|
+
txId: string;
|
|
151
|
+
}>;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Configuration for Stacks server
|
|
155
|
+
*/
|
|
156
|
+
interface StacksServerConfig {
|
|
157
|
+
/** Custom API URL */
|
|
158
|
+
apiUrl?: string;
|
|
159
|
+
/** Facilitator addresses per network */
|
|
160
|
+
facilitatorAddresses?: Record<string, string>;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Configuration for Stacks facilitator
|
|
164
|
+
*/
|
|
165
|
+
interface StacksFacilitatorConfig {
|
|
166
|
+
/** Maximum age of transaction to accept (in seconds) */
|
|
167
|
+
maxTransactionAge?: number;
|
|
168
|
+
/** Duration to cache used transaction IDs */
|
|
169
|
+
usedTxCacheDuration?: number;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export type { ClientStacksSigner as C, ExactDirectStacksPayload as E, FacilitatorStacksSigner as F, ParsedTokenTransfer as P, StacksTransactionResult as S, StacksContractCall as a, StacksFunctionArg as b, StacksPostCondition as c, StacksEvent as d, StacksServerConfig as e, StacksFacilitatorConfig as f };
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { Network } from '@t402/core/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Stacks T402 Types
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Payment payload for exact-direct scheme on Stacks
|
|
9
|
+
*/
|
|
10
|
+
type ExactDirectStacksPayload = {
|
|
11
|
+
/** Transaction ID (0x-prefixed hex, 64 chars) */
|
|
12
|
+
txId: string;
|
|
13
|
+
/** Sender address (Stacks principal) */
|
|
14
|
+
from: string;
|
|
15
|
+
/** Recipient address (Stacks principal) */
|
|
16
|
+
to: string;
|
|
17
|
+
/** Amount in smallest unit (atomic) */
|
|
18
|
+
amount: string;
|
|
19
|
+
/** SIP-010 contract address (principal.contract-name) */
|
|
20
|
+
contractAddress: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Result of a Stacks transaction query from Hiro API
|
|
24
|
+
*/
|
|
25
|
+
interface StacksTransactionResult {
|
|
26
|
+
/** Transaction ID */
|
|
27
|
+
txId: string;
|
|
28
|
+
/** Transaction type */
|
|
29
|
+
txType: string;
|
|
30
|
+
/** Transaction status */
|
|
31
|
+
txStatus: "success" | "abort_by_response" | "abort_by_post_condition" | "pending";
|
|
32
|
+
/** Block hash */
|
|
33
|
+
blockHash: string;
|
|
34
|
+
/** Block height */
|
|
35
|
+
blockHeight: number;
|
|
36
|
+
/** Burn block time (unix timestamp) */
|
|
37
|
+
burnBlockTime: number;
|
|
38
|
+
/** Sender address */
|
|
39
|
+
senderAddress: string;
|
|
40
|
+
/** Contract call details (for contract-call transactions) */
|
|
41
|
+
contractCall?: StacksContractCall;
|
|
42
|
+
/** Post-condition mode */
|
|
43
|
+
postConditionMode: string;
|
|
44
|
+
/** Post conditions */
|
|
45
|
+
postConditions: StacksPostCondition[];
|
|
46
|
+
/** Events */
|
|
47
|
+
events: StacksEvent[];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Stacks contract call details
|
|
51
|
+
*/
|
|
52
|
+
interface StacksContractCall {
|
|
53
|
+
/** Contract ID (principal.contract-name) */
|
|
54
|
+
contractId: string;
|
|
55
|
+
/** Function name */
|
|
56
|
+
functionName: string;
|
|
57
|
+
/** Function arguments */
|
|
58
|
+
functionArgs: StacksFunctionArg[];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Stacks function argument
|
|
62
|
+
*/
|
|
63
|
+
interface StacksFunctionArg {
|
|
64
|
+
/** Hex-encoded value */
|
|
65
|
+
hex: string;
|
|
66
|
+
/** Human-readable representation */
|
|
67
|
+
repr: string;
|
|
68
|
+
/** Argument type */
|
|
69
|
+
type: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Stacks post condition
|
|
73
|
+
*/
|
|
74
|
+
interface StacksPostCondition {
|
|
75
|
+
/** Principal (sender) */
|
|
76
|
+
principal: {
|
|
77
|
+
type_id: string;
|
|
78
|
+
address: string;
|
|
79
|
+
contract_name?: string;
|
|
80
|
+
};
|
|
81
|
+
/** Condition code */
|
|
82
|
+
conditionCode: string;
|
|
83
|
+
/** Amount */
|
|
84
|
+
amount: string;
|
|
85
|
+
/** Asset info */
|
|
86
|
+
asset?: {
|
|
87
|
+
contractAddress: string;
|
|
88
|
+
contractName: string;
|
|
89
|
+
assetName: string;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Stacks transaction event
|
|
94
|
+
*/
|
|
95
|
+
interface StacksEvent {
|
|
96
|
+
/** Event type */
|
|
97
|
+
eventType: string;
|
|
98
|
+
/** Event index */
|
|
99
|
+
eventIndex: number;
|
|
100
|
+
/** Fungible token transfer asset event (for ft_transfer events) */
|
|
101
|
+
asset?: {
|
|
102
|
+
assetEventType: string;
|
|
103
|
+
assetId: string;
|
|
104
|
+
sender: string;
|
|
105
|
+
recipient: string;
|
|
106
|
+
amount: string;
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Parsed token transfer from transaction events
|
|
111
|
+
*/
|
|
112
|
+
interface ParsedTokenTransfer {
|
|
113
|
+
/** Contract address (principal.contract-name) */
|
|
114
|
+
contractAddress: string;
|
|
115
|
+
/** Sender address */
|
|
116
|
+
from: string;
|
|
117
|
+
/** Recipient address */
|
|
118
|
+
to: string;
|
|
119
|
+
/** Amount transferred (atomic units) */
|
|
120
|
+
amount: string;
|
|
121
|
+
/** Whether the transfer was successful */
|
|
122
|
+
success: boolean;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Signer interface for Stacks facilitator
|
|
126
|
+
*/
|
|
127
|
+
interface FacilitatorStacksSigner {
|
|
128
|
+
/**
|
|
129
|
+
* Get the facilitator's addresses for a network
|
|
130
|
+
*/
|
|
131
|
+
getAddresses(network: Network): string[];
|
|
132
|
+
/**
|
|
133
|
+
* Query a transaction by ID from Hiro API
|
|
134
|
+
*/
|
|
135
|
+
queryTransaction(txId: string): Promise<StacksTransactionResult | null>;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Client signer interface for signing transactions
|
|
139
|
+
*/
|
|
140
|
+
interface ClientStacksSigner {
|
|
141
|
+
/**
|
|
142
|
+
* Get the signer's address
|
|
143
|
+
*/
|
|
144
|
+
getAddress(): Promise<string>;
|
|
145
|
+
/**
|
|
146
|
+
* Sign and submit a SIP-010 token transfer
|
|
147
|
+
* Returns the transaction ID
|
|
148
|
+
*/
|
|
149
|
+
transferToken(contractAddress: string, to: string, amount: string): Promise<{
|
|
150
|
+
txId: string;
|
|
151
|
+
}>;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Configuration for Stacks server
|
|
155
|
+
*/
|
|
156
|
+
interface StacksServerConfig {
|
|
157
|
+
/** Custom API URL */
|
|
158
|
+
apiUrl?: string;
|
|
159
|
+
/** Facilitator addresses per network */
|
|
160
|
+
facilitatorAddresses?: Record<string, string>;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Configuration for Stacks facilitator
|
|
164
|
+
*/
|
|
165
|
+
interface StacksFacilitatorConfig {
|
|
166
|
+
/** Maximum age of transaction to accept (in seconds) */
|
|
167
|
+
maxTransactionAge?: number;
|
|
168
|
+
/** Duration to cache used transaction IDs */
|
|
169
|
+
usedTxCacheDuration?: number;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export type { ClientStacksSigner as C, ExactDirectStacksPayload as E, FacilitatorStacksSigner as F, ParsedTokenTransfer as P, StacksTransactionResult as S, StacksContractCall as a, StacksFunctionArg as b, StacksPostCondition as c, StacksEvent as d, StacksServerConfig as e, StacksFacilitatorConfig as f };
|
package/package.json
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@t402/stacks",
|
|
3
|
+
"version": "2.4.0",
|
|
4
|
+
"description": "T402 Stacks mechanism - SIP-010 token transfers on Bitcoin L2",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/cjs/index.cjs",
|
|
7
|
+
"module": "./dist/esm/index.mjs",
|
|
8
|
+
"types": "./dist/esm/index.d.mts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/esm/index.d.mts",
|
|
13
|
+
"default": "./dist/esm/index.mjs"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/cjs/index.d.cts",
|
|
17
|
+
"default": "./dist/cjs/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"./exact-direct/client": {
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./dist/esm/exact-direct/client/index.d.mts",
|
|
23
|
+
"default": "./dist/esm/exact-direct/client/index.mjs"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./dist/cjs/exact-direct/client/index.d.cts",
|
|
27
|
+
"default": "./dist/cjs/exact-direct/client/index.cjs"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"./exact-direct/server": {
|
|
31
|
+
"import": {
|
|
32
|
+
"types": "./dist/esm/exact-direct/server/index.d.mts",
|
|
33
|
+
"default": "./dist/esm/exact-direct/server/index.mjs"
|
|
34
|
+
},
|
|
35
|
+
"require": {
|
|
36
|
+
"types": "./dist/cjs/exact-direct/server/index.d.cts",
|
|
37
|
+
"default": "./dist/cjs/exact-direct/server/index.cjs"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"./exact-direct/facilitator": {
|
|
41
|
+
"import": {
|
|
42
|
+
"types": "./dist/esm/exact-direct/facilitator/index.d.mts",
|
|
43
|
+
"default": "./dist/esm/exact-direct/facilitator/index.mjs"
|
|
44
|
+
},
|
|
45
|
+
"require": {
|
|
46
|
+
"types": "./dist/cjs/exact-direct/facilitator/index.d.cts",
|
|
47
|
+
"default": "./dist/cjs/exact-direct/facilitator/index.cjs"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"files": [
|
|
52
|
+
"dist",
|
|
53
|
+
"src"
|
|
54
|
+
],
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@t402/core": "2.4.0"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"@stacks/transactions": ">=7.0.0"
|
|
60
|
+
},
|
|
61
|
+
"peerDependenciesMeta": {
|
|
62
|
+
"@stacks/transactions": {
|
|
63
|
+
"optional": true
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@types/node": "^25.2.0",
|
|
68
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
69
|
+
"tsup": "^8.3.5",
|
|
70
|
+
"typescript": "^5.7.2",
|
|
71
|
+
"vitest": "^3.2.4"
|
|
72
|
+
},
|
|
73
|
+
"keywords": [
|
|
74
|
+
"t402",
|
|
75
|
+
"stacks",
|
|
76
|
+
"bitcoin",
|
|
77
|
+
"sip-010",
|
|
78
|
+
"payment",
|
|
79
|
+
"cryptocurrency",
|
|
80
|
+
"web3"
|
|
81
|
+
],
|
|
82
|
+
"author": "T402 Team",
|
|
83
|
+
"license": "Apache-2.0",
|
|
84
|
+
"repository": {
|
|
85
|
+
"type": "git",
|
|
86
|
+
"url": "https://github.com/t402-io/t402.git",
|
|
87
|
+
"directory": "typescript/packages/mechanisms/stacks"
|
|
88
|
+
},
|
|
89
|
+
"bugs": {
|
|
90
|
+
"url": "https://github.com/t402-io/t402/issues"
|
|
91
|
+
},
|
|
92
|
+
"homepage": "https://t402.io",
|
|
93
|
+
"scripts": {
|
|
94
|
+
"build": "tsup",
|
|
95
|
+
"dev": "tsup --watch",
|
|
96
|
+
"test": "vitest run",
|
|
97
|
+
"test:watch": "vitest",
|
|
98
|
+
"test:coverage": "vitest run --coverage",
|
|
99
|
+
"typecheck": "tsc --noEmit",
|
|
100
|
+
"clean": "rm -rf dist"
|
|
101
|
+
}
|
|
102
|
+
}
|