stxer 0.6.1 → 0.8.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/CHANGELOG.md +118 -0
- package/README.md +300 -55
- package/dist/ast.d.ts +1 -1
- package/dist/batch-api.d.ts +2 -1
- package/dist/bitcoin.d.ts +121 -0
- package/dist/index.d.ts +3 -1
- package/dist/simulation-api.d.ts +52 -3
- package/dist/simulation.d.ts +70 -3
- package/dist/stxer.cjs.development.js +917 -104
- package/dist/stxer.cjs.development.js.map +1 -1
- package/dist/stxer.cjs.production.min.js +1 -1
- package/dist/stxer.cjs.production.min.js.map +1 -1
- package/dist/stxer.esm.js +897 -107
- package/dist/stxer.esm.js.map +1 -1
- package/dist/transaction.d.ts +71 -0
- package/dist/types.d.ts +547 -54
- package/package.json +17 -10
- package/src/ast.ts +1 -1
- package/src/batch-api.ts +9 -8
- package/src/bitcoin.ts +391 -0
- package/src/index.ts +7 -10
- package/src/simulation-api.ts +110 -13
- package/src/simulation.ts +245 -46
- package/src/transaction.ts +141 -0
- package/src/types.ts +594 -59
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transaction-building helpers for the simulator.
|
|
3
|
+
*
|
|
4
|
+
* The simulator does NOT verify signatures — it derives `tx-sender`
|
|
5
|
+
* from the `signer` field (= hash160 of the public key) plus the
|
|
6
|
+
* `hashMode` byte. By overriding those two fields on an *unsigned*
|
|
7
|
+
* transaction, you can simulate any sender without a private key.
|
|
8
|
+
*
|
|
9
|
+
* {@link setSender} performs the override; {@link buildUnsignedContractCallHex}
|
|
10
|
+
* combines the unsigned-tx builder from `@stacks/transactions` with
|
|
11
|
+
* `setSender` and returns a hex string ready to drop into a
|
|
12
|
+
* `{ Transaction: <hex> }` simulation step.
|
|
13
|
+
*/
|
|
14
|
+
import { type StacksNetworkName } from '@stacks/network';
|
|
15
|
+
import { type ClarityValue, PostConditionMode, type StacksTransactionWire } from '@stacks/transactions';
|
|
16
|
+
/**
|
|
17
|
+
* Override the spending condition's `signer` (and `hashMode`) so the
|
|
18
|
+
* simulator treats `tx-sender` as `sender`.
|
|
19
|
+
*
|
|
20
|
+
* Single-sig and multi-sig flavours are both handled — the multi-sig
|
|
21
|
+
* spending condition is rebuilt with empty signature fields because
|
|
22
|
+
* the simulator never validates signatures.
|
|
23
|
+
*/
|
|
24
|
+
export declare function setSender(tx: StacksTransactionWire, sender: string): StacksTransactionWire;
|
|
25
|
+
export interface ContractCallTxArgs {
|
|
26
|
+
/** Principal to set as `tx-sender`. */
|
|
27
|
+
sender: string;
|
|
28
|
+
/** Fully-qualified contract id, e.g. `"SP1G48….dia-oracle"`. */
|
|
29
|
+
contract: string;
|
|
30
|
+
functionName: string;
|
|
31
|
+
functionArgs: ClarityValue[];
|
|
32
|
+
/** microSTX. Defaults to 1_000. */
|
|
33
|
+
fee?: number;
|
|
34
|
+
/** Nonce to declare. Caller is responsible for sequencing. */
|
|
35
|
+
nonce: number;
|
|
36
|
+
network?: StacksNetworkName;
|
|
37
|
+
/**
|
|
38
|
+
* Post-condition mode. Defaults to `Allow` so the simulator runs
|
|
39
|
+
* the call regardless of asset movements; switch to `Deny` + an
|
|
40
|
+
* explicit list when a test wants to assert post-condition
|
|
41
|
+
* enforcement.
|
|
42
|
+
*/
|
|
43
|
+
postConditionMode?: PostConditionMode;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Build an unsigned contract-call transaction with `sender` patched
|
|
47
|
+
* in via {@link setSender}, then return the serialized hex (no `0x`
|
|
48
|
+
* prefix). Drop the result directly into `{ Transaction: <hex> }`.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* import { Cl } from '@stacks/transactions';
|
|
53
|
+
* import { buildUnsignedContractCallHex } from 'stxer';
|
|
54
|
+
*
|
|
55
|
+
* const txHex = await buildUnsignedContractCallHex({
|
|
56
|
+
* sender: 'SP3573...',
|
|
57
|
+
* contract: 'SM3VDXK...sbtc-deposit',
|
|
58
|
+
* functionName: 'complete-deposit-wrapper',
|
|
59
|
+
* functionArgs: [Cl.bufferFromHex(txid), Cl.uint(0), Cl.uint(amount), ...],
|
|
60
|
+
* nonce: 5,
|
|
61
|
+
* });
|
|
62
|
+
* await submitSimulationSteps(sim, { steps: [{ Transaction: txHex }] });
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare function buildUnsignedContractCallHex(args: ContractCallTxArgs): Promise<string>;
|
|
66
|
+
/**
|
|
67
|
+
* Build a `Cl.contractPrincipal` from a `"SP….name"` id string.
|
|
68
|
+
* Trips on standard principals or malformed ids — those should use
|
|
69
|
+
* `Cl.principal` directly.
|
|
70
|
+
*/
|
|
71
|
+
export declare function ftPrincipal(contractId: string): ClarityValue;
|