@stacks/codec 1.4.1 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  `@stacks/codec` is a Node.js [native addon](https://nodejs.org/api/addons.html) library written in
4
4
  Rust, which provides functions for decoding binary/wire formats used in the Stacks blockchain.
5
- Features include Clarity values, transactions, post-conditions, Stacks and Bitcoin addresses, and
6
- more.
5
+ Features include Clarity values, transactions, post-conditions, Stacks and Bitcoin addresses, PoX
6
+ synthetic event parsing, and more.
7
7
 
8
8
  Various ASM/SIMD optimizations are used in areas which are prone to causing CPU bottlenecks when
9
9
  used in hot paths, e.g. decoding raw Clarity values on the fly.
@@ -379,6 +379,34 @@ assert.deepStrictEqual(decoded, {
379
379
  ```
380
380
  </details>
381
381
 
382
+ ### Decoding PoX synthetic events
383
+
384
+ Decode serialized Clarity values from PoX contract log events into structured PoX synthetic event objects. This is useful for parsing stacking, delegation, and unlocking events emitted by the PoX contract.
385
+
386
+ ```ts
387
+ import { decodePoxSyntheticEvent, PoxEventName } from '@stacks/codec';
388
+
389
+ // Serialized hex string of a PoX synthetic event Clarity value (ResponseOk wrapping a Tuple)
390
+ const rawClarityHex = '0x0700...';
391
+
392
+ const event = decodePoxSyntheticEvent(rawClarityHex, 'mainnet');
393
+
394
+ if (event !== null) {
395
+ console.log(event.name); // e.g. 'stack-stx'
396
+ console.log(event.stacker); // e.g. 'SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7'
397
+ console.log(event.locked); // String-quoted u128, e.g. '1000000'
398
+ console.log(event.balance); // String-quoted u128, e.g. '500000'
399
+ console.log(event.burnchain_unlock_height); // String-quoted u128, e.g. '150000'
400
+ console.log(event.pox_addr); // BTC address string or null
401
+ console.log(event.pox_addr_raw); // Hex-encoded raw PoX address or null
402
+ console.log(event.data); // Event-specific fields (varies by event type)
403
+ }
404
+ ```
405
+
406
+ Supported event types: `handle-unlock`, `stack-stx`, `stack-increase`, `stack-extend`, `delegate-stx`, `delegate-stack-stx`, `delegate-stack-increase`, `delegate-stack-extend`, `stack-aggregation-commit`, `stack-aggregation-commit-indexed`, `stack-aggregation-increase`, `revoke-delegate-stx`.
407
+
408
+ Returns `null` when the Clarity value is a `ResponseErr` (indicating a non-event). Bitcoin address encoding supports P2PKH, P2SH, P2WPKH (segwit v0), P2WSH (segwit v0), and P2TR (taproot/segwit v1) address formats.
409
+
382
410
  ## Project Layout
383
411
 
384
412
  The directory structure of this project is:
package/index.d.ts CHANGED
@@ -55,11 +55,13 @@ export interface PostConditionAssetInfo {
55
55
  }
56
56
  export declare enum PostConditionNonfungibleConditionCodeID {
57
57
  Sent = 16,
58
- NotSent = 17
58
+ NotSent = 17,
59
+ MaybeSent = 18
59
60
  }
60
61
  export declare enum PostConditionNonFungibleConditionName {
61
62
  Sent = "sent",
62
- NotSent = "not_sent"
63
+ NotSent = "not_sent",
64
+ MaybeSent = "maybe_sent"
63
65
  }
64
66
  export declare enum PostConditionFungibleConditionCodeID {
65
67
  SentEq = 1,
@@ -334,7 +336,9 @@ export declare enum PostConditionModeID {
334
336
  /** This transaction may affect other assets not listed in the post-conditions. */
335
337
  Allow = 1,
336
338
  /** This transaction may NOT affect other assets besides those listed in the post-conditions. */
337
- Deny = 2
339
+ Deny = 2,
340
+ /** Deny for the transaction origin; allow for everyone else (SIP-040). */
341
+ Originator = 3
338
342
  }
339
343
  export interface ClarityValueCommon {
340
344
  /** Clarity repr value */
@@ -519,3 +523,200 @@ export interface StacksWorkScore {
519
523
  /** String-quoted unsigned integer - work score */
520
524
  work: string;
521
525
  }
526
+ export declare enum PoxEventName {
527
+ HandleUnlock = "handle-unlock",
528
+ StackStx = "stack-stx",
529
+ StackIncrease = "stack-increase",
530
+ StackExtend = "stack-extend",
531
+ DelegateStx = "delegate-stx",
532
+ DelegateStackStx = "delegate-stack-stx",
533
+ DelegateStackIncrease = "delegate-stack-increase",
534
+ DelegateStackExtend = "delegate-stack-extend",
535
+ StackAggregationCommit = "stack-aggregation-commit",
536
+ StackAggregationCommitIndexed = "stack-aggregation-commit-indexed",
537
+ StackAggregationIncrease = "stack-aggregation-increase",
538
+ RevokeDelegateStx = "revoke-delegate-stx"
539
+ }
540
+ export interface PoxEventBase {
541
+ stacker: string;
542
+ /** String-quoted unsigned integer */
543
+ locked: string;
544
+ /** String-quoted unsigned integer */
545
+ balance: string;
546
+ /** String-quoted unsigned integer */
547
+ burnchain_unlock_height: string;
548
+ pox_addr: string | null;
549
+ pox_addr_raw: string | null;
550
+ }
551
+ export interface PoxEventHandleUnlock extends PoxEventBase {
552
+ name: PoxEventName.HandleUnlock;
553
+ data: {
554
+ /** String-quoted unsigned integer */
555
+ first_cycle_locked: string;
556
+ /** String-quoted unsigned integer */
557
+ first_unlocked_cycle: string;
558
+ };
559
+ }
560
+ export interface PoxEventStackStx extends PoxEventBase {
561
+ name: PoxEventName.StackStx;
562
+ data: {
563
+ /** String-quoted unsigned integer */
564
+ lock_amount: string;
565
+ /** String-quoted unsigned integer */
566
+ lock_period: string;
567
+ /** String-quoted unsigned integer */
568
+ start_burn_height: string;
569
+ /** String-quoted unsigned integer */
570
+ unlock_burn_height: string;
571
+ /** Hex string or null */
572
+ signer_key: string | null;
573
+ /** String-quoted unsigned integer or null */
574
+ end_cycle_id: string | null;
575
+ /** String-quoted unsigned integer or null */
576
+ start_cycle_id: string | null;
577
+ };
578
+ }
579
+ export interface PoxEventStackIncrease extends PoxEventBase {
580
+ name: PoxEventName.StackIncrease;
581
+ data: {
582
+ /** String-quoted unsigned integer */
583
+ increase_by: string;
584
+ /** String-quoted unsigned integer */
585
+ total_locked: string;
586
+ /** Hex string or null */
587
+ signer_key: string | null;
588
+ /** String-quoted unsigned integer or null */
589
+ end_cycle_id: string | null;
590
+ /** String-quoted unsigned integer or null */
591
+ start_cycle_id: string | null;
592
+ };
593
+ }
594
+ export interface PoxEventStackExtend extends PoxEventBase {
595
+ name: PoxEventName.StackExtend;
596
+ data: {
597
+ /** String-quoted unsigned integer */
598
+ extend_count: string;
599
+ /** String-quoted unsigned integer */
600
+ unlock_burn_height: string;
601
+ /** Hex string or null */
602
+ signer_key: string | null;
603
+ /** String-quoted unsigned integer or null */
604
+ end_cycle_id: string | null;
605
+ /** String-quoted unsigned integer or null */
606
+ start_cycle_id: string | null;
607
+ };
608
+ }
609
+ export interface PoxEventDelegateStx extends PoxEventBase {
610
+ name: PoxEventName.DelegateStx;
611
+ data: {
612
+ /** String-quoted unsigned integer */
613
+ amount_ustx: string;
614
+ delegate_to: string;
615
+ /** String-quoted unsigned integer or null */
616
+ unlock_burn_height: string | null;
617
+ /** String-quoted unsigned integer or null */
618
+ end_cycle_id: string | null;
619
+ /** String-quoted unsigned integer or null */
620
+ start_cycle_id: string | null;
621
+ };
622
+ }
623
+ export interface PoxEventDelegateStackStx extends PoxEventBase {
624
+ name: PoxEventName.DelegateStackStx;
625
+ data: {
626
+ /** String-quoted unsigned integer */
627
+ lock_amount: string;
628
+ /** String-quoted unsigned integer */
629
+ unlock_burn_height: string;
630
+ /** String-quoted unsigned integer */
631
+ start_burn_height: string;
632
+ /** String-quoted unsigned integer */
633
+ lock_period: string;
634
+ delegator: string;
635
+ /** String-quoted unsigned integer or null */
636
+ end_cycle_id: string | null;
637
+ /** String-quoted unsigned integer or null */
638
+ start_cycle_id: string | null;
639
+ };
640
+ }
641
+ export interface PoxEventDelegateStackIncrease extends PoxEventBase {
642
+ name: PoxEventName.DelegateStackIncrease;
643
+ data: {
644
+ /** String-quoted unsigned integer */
645
+ increase_by: string;
646
+ /** String-quoted unsigned integer */
647
+ total_locked: string;
648
+ delegator: string;
649
+ /** String-quoted unsigned integer or null */
650
+ end_cycle_id: string | null;
651
+ /** String-quoted unsigned integer or null */
652
+ start_cycle_id: string | null;
653
+ };
654
+ }
655
+ export interface PoxEventDelegateStackExtend extends PoxEventBase {
656
+ name: PoxEventName.DelegateStackExtend;
657
+ data: {
658
+ /** String-quoted unsigned integer */
659
+ unlock_burn_height: string;
660
+ /** String-quoted unsigned integer */
661
+ extend_count: string;
662
+ delegator: string;
663
+ /** String-quoted unsigned integer or null */
664
+ end_cycle_id: string | null;
665
+ /** String-quoted unsigned integer or null */
666
+ start_cycle_id: string | null;
667
+ };
668
+ }
669
+ export interface PoxEventStackAggregationCommit extends PoxEventBase {
670
+ name: PoxEventName.StackAggregationCommit;
671
+ data: {
672
+ /** String-quoted unsigned integer */
673
+ reward_cycle: string;
674
+ /** String-quoted unsigned integer */
675
+ amount_ustx: string;
676
+ /** Hex string or null */
677
+ signer_key: string | null;
678
+ /** String-quoted unsigned integer or null */
679
+ end_cycle_id: string | null;
680
+ /** String-quoted unsigned integer or null */
681
+ start_cycle_id: string | null;
682
+ };
683
+ }
684
+ export interface PoxEventStackAggregationCommitIndexed extends PoxEventBase {
685
+ name: PoxEventName.StackAggregationCommitIndexed;
686
+ data: {
687
+ /** String-quoted unsigned integer */
688
+ reward_cycle: string;
689
+ /** String-quoted unsigned integer */
690
+ amount_ustx: string;
691
+ /** Hex string or null */
692
+ signer_key: string | null;
693
+ /** String-quoted unsigned integer or null */
694
+ end_cycle_id: string | null;
695
+ /** String-quoted unsigned integer or null */
696
+ start_cycle_id: string | null;
697
+ };
698
+ }
699
+ export interface PoxEventStackAggregationIncrease extends PoxEventBase {
700
+ name: PoxEventName.StackAggregationIncrease;
701
+ data: {
702
+ /** String-quoted unsigned integer */
703
+ reward_cycle: string;
704
+ /** String-quoted unsigned integer */
705
+ amount_ustx: string;
706
+ /** String-quoted unsigned integer or null */
707
+ end_cycle_id: string | null;
708
+ /** String-quoted unsigned integer or null */
709
+ start_cycle_id: string | null;
710
+ };
711
+ }
712
+ export interface PoxEventRevokeDelegateStx extends PoxEventBase {
713
+ name: PoxEventName.RevokeDelegateStx;
714
+ data: {
715
+ delegate_to: string;
716
+ /** String-quoted unsigned integer or null */
717
+ end_cycle_id: string | null;
718
+ /** String-quoted unsigned integer or null */
719
+ start_cycle_id: string | null;
720
+ };
721
+ }
722
+ export declare type DecodedPoxSyntheticEvent = PoxEventHandleUnlock | PoxEventStackStx | PoxEventStackIncrease | PoxEventStackExtend | PoxEventDelegateStx | PoxEventDelegateStackStx | PoxEventDelegateStackIncrease | PoxEventDelegateStackExtend | PoxEventStackAggregationCommit | PoxEventStackAggregationCommitIndexed | PoxEventStackAggregationIncrease | PoxEventRevokeDelegateStx;
package/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.ClarityTypeID = exports.PostConditionModeID = exports.AnchorModeID = exports.TransactionVersion = exports.TxPublicKeyEncoding = exports.TxAuthFieldTypeID = exports.ClarityVersion = exports.TxSpendingConditionMultiSigHashMode = exports.TxSpendingConditionSingleSigHashMode = exports.PostConditionAuthFlag = exports.TxPayloadTypeID = exports.TenureChangeCause = exports.PrincipalTypeID = exports.PostConditionPrincipalTypeID = exports.PostConditionFungibleConditionCodeName = exports.PostConditionFungibleConditionCodeID = exports.PostConditionNonFungibleConditionName = exports.PostConditionNonfungibleConditionCodeID = exports.PostConditionAssetInfoID = exports.StacksNativeEncodingBindings = void 0;
17
+ exports.PoxEventName = exports.ClarityTypeID = exports.PostConditionModeID = exports.AnchorModeID = exports.TransactionVersion = exports.TxPublicKeyEncoding = exports.TxAuthFieldTypeID = exports.ClarityVersion = exports.TxSpendingConditionMultiSigHashMode = exports.TxSpendingConditionSingleSigHashMode = exports.PostConditionAuthFlag = exports.TxPayloadTypeID = exports.TenureChangeCause = exports.PrincipalTypeID = exports.PostConditionPrincipalTypeID = exports.PostConditionFungibleConditionCodeName = exports.PostConditionFungibleConditionCodeID = exports.PostConditionNonFungibleConditionName = exports.PostConditionNonfungibleConditionCodeID = exports.PostConditionAssetInfoID = exports.StacksNativeEncodingBindings = void 0;
18
18
  const bindings = require("./loader");
19
19
  __exportStar(require("./loader"), exports);
20
20
  exports.StacksNativeEncodingBindings = bindings;
@@ -29,11 +29,13 @@ var PostConditionNonfungibleConditionCodeID;
29
29
  (function (PostConditionNonfungibleConditionCodeID) {
30
30
  PostConditionNonfungibleConditionCodeID[PostConditionNonfungibleConditionCodeID["Sent"] = 16] = "Sent";
31
31
  PostConditionNonfungibleConditionCodeID[PostConditionNonfungibleConditionCodeID["NotSent"] = 17] = "NotSent";
32
+ PostConditionNonfungibleConditionCodeID[PostConditionNonfungibleConditionCodeID["MaybeSent"] = 18] = "MaybeSent";
32
33
  })(PostConditionNonfungibleConditionCodeID = exports.PostConditionNonfungibleConditionCodeID || (exports.PostConditionNonfungibleConditionCodeID = {}));
33
34
  var PostConditionNonFungibleConditionName;
34
35
  (function (PostConditionNonFungibleConditionName) {
35
36
  PostConditionNonFungibleConditionName["Sent"] = "sent";
36
37
  PostConditionNonFungibleConditionName["NotSent"] = "not_sent";
38
+ PostConditionNonFungibleConditionName["MaybeSent"] = "maybe_sent";
37
39
  })(PostConditionNonFungibleConditionName = exports.PostConditionNonFungibleConditionName || (exports.PostConditionNonFungibleConditionName = {}));
38
40
  var PostConditionFungibleConditionCodeID;
39
41
  (function (PostConditionFungibleConditionCodeID) {
@@ -161,6 +163,8 @@ var PostConditionModeID;
161
163
  PostConditionModeID[PostConditionModeID["Allow"] = 1] = "Allow";
162
164
  /** This transaction may NOT affect other assets besides those listed in the post-conditions. */
163
165
  PostConditionModeID[PostConditionModeID["Deny"] = 2] = "Deny";
166
+ /** Deny for the transaction origin; allow for everyone else (SIP-040). */
167
+ PostConditionModeID[PostConditionModeID["Originator"] = 3] = "Originator";
164
168
  })(PostConditionModeID = exports.PostConditionModeID || (exports.PostConditionModeID = {}));
165
169
  var ClarityTypeID;
166
170
  (function (ClarityTypeID) {
@@ -180,3 +184,21 @@ var ClarityTypeID;
180
184
  ClarityTypeID[ClarityTypeID["StringAscii"] = 13] = "StringAscii";
181
185
  ClarityTypeID[ClarityTypeID["StringUtf8"] = 14] = "StringUtf8";
182
186
  })(ClarityTypeID = exports.ClarityTypeID || (exports.ClarityTypeID = {}));
187
+ // ============================================================================
188
+ // PoX Synthetic Event Types
189
+ // ============================================================================
190
+ var PoxEventName;
191
+ (function (PoxEventName) {
192
+ PoxEventName["HandleUnlock"] = "handle-unlock";
193
+ PoxEventName["StackStx"] = "stack-stx";
194
+ PoxEventName["StackIncrease"] = "stack-increase";
195
+ PoxEventName["StackExtend"] = "stack-extend";
196
+ PoxEventName["DelegateStx"] = "delegate-stx";
197
+ PoxEventName["DelegateStackStx"] = "delegate-stack-stx";
198
+ PoxEventName["DelegateStackIncrease"] = "delegate-stack-increase";
199
+ PoxEventName["DelegateStackExtend"] = "delegate-stack-extend";
200
+ PoxEventName["StackAggregationCommit"] = "stack-aggregation-commit";
201
+ PoxEventName["StackAggregationCommitIndexed"] = "stack-aggregation-commit-indexed";
202
+ PoxEventName["StackAggregationIncrease"] = "stack-aggregation-increase";
203
+ PoxEventName["RevokeDelegateStx"] = "revoke-delegate-stx";
204
+ })(PoxEventName = exports.PoxEventName || (exports.PoxEventName = {}));
package/loader.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { DecodedPostConditionsResult, DecodedTxResult, DecodedNakamotoBlockResult, DecodedStacksBlockResult, ClarityValue, ClarityValueAbstract } from ".";
1
+ import type { DecodedPostConditionsResult, DecodedTxResult, DecodedNakamotoBlockResult, DecodedStacksBlockResult, ClarityValue, ClarityValueAbstract, DecodedPoxSyntheticEvent } from ".";
2
2
 
3
3
  export function getVersion(): string;
4
4
 
@@ -60,6 +60,17 @@ export function stacksAddressFromParts(version: number, hash160: string | Buffer
60
60
 
61
61
  export function memoToString(memo: string | Buffer): string;
62
62
 
63
+ /**
64
+ * Decode a serialized Clarity value representing a PoX synthetic print event.
65
+ * @param arg - Hex string or Buffer containing the serialized Clarity value
66
+ * @param network - The Stacks network type
67
+ * @returns The decoded PoX event, or null if the Clarity value is a ResponseErr
68
+ */
69
+ export function decodePoxSyntheticEvent(
70
+ arg: string | Buffer,
71
+ network: 'mainnet' | 'testnet' | 'devnet' | 'mocknet'
72
+ ): DecodedPoxSyntheticEvent | null;
73
+
63
74
  export function startProfiler(): string;
64
75
 
65
76
  export function stopProfiler(): Buffer;
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stacks/codec",
3
- "version": "1.4.1",
3
+ "version": "1.6.0",
4
4
  "description": "Encoding & decoding functions for the Stacks blockchain exposed as a fast native Node.js addon",
5
5
  "main": "index.js",
6
6
  "scripts": {