@stacks/codec 1.4.1 → 1.5.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
@@ -519,3 +519,200 @@ export interface StacksWorkScore {
519
519
  /** String-quoted unsigned integer - work score */
520
520
  work: string;
521
521
  }
522
+ export declare enum PoxEventName {
523
+ HandleUnlock = "handle-unlock",
524
+ StackStx = "stack-stx",
525
+ StackIncrease = "stack-increase",
526
+ StackExtend = "stack-extend",
527
+ DelegateStx = "delegate-stx",
528
+ DelegateStackStx = "delegate-stack-stx",
529
+ DelegateStackIncrease = "delegate-stack-increase",
530
+ DelegateStackExtend = "delegate-stack-extend",
531
+ StackAggregationCommit = "stack-aggregation-commit",
532
+ StackAggregationCommitIndexed = "stack-aggregation-commit-indexed",
533
+ StackAggregationIncrease = "stack-aggregation-increase",
534
+ RevokeDelegateStx = "revoke-delegate-stx"
535
+ }
536
+ export interface PoxEventBase {
537
+ stacker: string;
538
+ /** String-quoted unsigned integer */
539
+ locked: string;
540
+ /** String-quoted unsigned integer */
541
+ balance: string;
542
+ /** String-quoted unsigned integer */
543
+ burnchain_unlock_height: string;
544
+ pox_addr: string | null;
545
+ pox_addr_raw: string | null;
546
+ }
547
+ export interface PoxEventHandleUnlock extends PoxEventBase {
548
+ name: PoxEventName.HandleUnlock;
549
+ data: {
550
+ /** String-quoted unsigned integer */
551
+ first_cycle_locked: string;
552
+ /** String-quoted unsigned integer */
553
+ first_unlocked_cycle: string;
554
+ };
555
+ }
556
+ export interface PoxEventStackStx extends PoxEventBase {
557
+ name: PoxEventName.StackStx;
558
+ data: {
559
+ /** String-quoted unsigned integer */
560
+ lock_amount: string;
561
+ /** String-quoted unsigned integer */
562
+ lock_period: string;
563
+ /** String-quoted unsigned integer */
564
+ start_burn_height: string;
565
+ /** String-quoted unsigned integer */
566
+ unlock_burn_height: string;
567
+ /** Hex string or null */
568
+ signer_key: string | null;
569
+ /** String-quoted unsigned integer or null */
570
+ end_cycle_id: string | null;
571
+ /** String-quoted unsigned integer or null */
572
+ start_cycle_id: string | null;
573
+ };
574
+ }
575
+ export interface PoxEventStackIncrease extends PoxEventBase {
576
+ name: PoxEventName.StackIncrease;
577
+ data: {
578
+ /** String-quoted unsigned integer */
579
+ increase_by: string;
580
+ /** String-quoted unsigned integer */
581
+ total_locked: string;
582
+ /** Hex string or null */
583
+ signer_key: string | null;
584
+ /** String-quoted unsigned integer or null */
585
+ end_cycle_id: string | null;
586
+ /** String-quoted unsigned integer or null */
587
+ start_cycle_id: string | null;
588
+ };
589
+ }
590
+ export interface PoxEventStackExtend extends PoxEventBase {
591
+ name: PoxEventName.StackExtend;
592
+ data: {
593
+ /** String-quoted unsigned integer */
594
+ extend_count: string;
595
+ /** String-quoted unsigned integer */
596
+ unlock_burn_height: string;
597
+ /** Hex string or null */
598
+ signer_key: string | null;
599
+ /** String-quoted unsigned integer or null */
600
+ end_cycle_id: string | null;
601
+ /** String-quoted unsigned integer or null */
602
+ start_cycle_id: string | null;
603
+ };
604
+ }
605
+ export interface PoxEventDelegateStx extends PoxEventBase {
606
+ name: PoxEventName.DelegateStx;
607
+ data: {
608
+ /** String-quoted unsigned integer */
609
+ amount_ustx: string;
610
+ delegate_to: string;
611
+ /** String-quoted unsigned integer or null */
612
+ unlock_burn_height: string | null;
613
+ /** String-quoted unsigned integer or null */
614
+ end_cycle_id: string | null;
615
+ /** String-quoted unsigned integer or null */
616
+ start_cycle_id: string | null;
617
+ };
618
+ }
619
+ export interface PoxEventDelegateStackStx extends PoxEventBase {
620
+ name: PoxEventName.DelegateStackStx;
621
+ data: {
622
+ /** String-quoted unsigned integer */
623
+ lock_amount: string;
624
+ /** String-quoted unsigned integer */
625
+ unlock_burn_height: string;
626
+ /** String-quoted unsigned integer */
627
+ start_burn_height: string;
628
+ /** String-quoted unsigned integer */
629
+ lock_period: string;
630
+ delegator: string;
631
+ /** String-quoted unsigned integer or null */
632
+ end_cycle_id: string | null;
633
+ /** String-quoted unsigned integer or null */
634
+ start_cycle_id: string | null;
635
+ };
636
+ }
637
+ export interface PoxEventDelegateStackIncrease extends PoxEventBase {
638
+ name: PoxEventName.DelegateStackIncrease;
639
+ data: {
640
+ /** String-quoted unsigned integer */
641
+ increase_by: string;
642
+ /** String-quoted unsigned integer */
643
+ total_locked: string;
644
+ delegator: string;
645
+ /** String-quoted unsigned integer or null */
646
+ end_cycle_id: string | null;
647
+ /** String-quoted unsigned integer or null */
648
+ start_cycle_id: string | null;
649
+ };
650
+ }
651
+ export interface PoxEventDelegateStackExtend extends PoxEventBase {
652
+ name: PoxEventName.DelegateStackExtend;
653
+ data: {
654
+ /** String-quoted unsigned integer */
655
+ unlock_burn_height: string;
656
+ /** String-quoted unsigned integer */
657
+ extend_count: string;
658
+ delegator: string;
659
+ /** String-quoted unsigned integer or null */
660
+ end_cycle_id: string | null;
661
+ /** String-quoted unsigned integer or null */
662
+ start_cycle_id: string | null;
663
+ };
664
+ }
665
+ export interface PoxEventStackAggregationCommit extends PoxEventBase {
666
+ name: PoxEventName.StackAggregationCommit;
667
+ data: {
668
+ /** String-quoted unsigned integer */
669
+ reward_cycle: string;
670
+ /** String-quoted unsigned integer */
671
+ amount_ustx: string;
672
+ /** Hex string or null */
673
+ signer_key: string | null;
674
+ /** String-quoted unsigned integer or null */
675
+ end_cycle_id: string | null;
676
+ /** String-quoted unsigned integer or null */
677
+ start_cycle_id: string | null;
678
+ };
679
+ }
680
+ export interface PoxEventStackAggregationCommitIndexed extends PoxEventBase {
681
+ name: PoxEventName.StackAggregationCommitIndexed;
682
+ data: {
683
+ /** String-quoted unsigned integer */
684
+ reward_cycle: string;
685
+ /** String-quoted unsigned integer */
686
+ amount_ustx: string;
687
+ /** Hex string or null */
688
+ signer_key: string | null;
689
+ /** String-quoted unsigned integer or null */
690
+ end_cycle_id: string | null;
691
+ /** String-quoted unsigned integer or null */
692
+ start_cycle_id: string | null;
693
+ };
694
+ }
695
+ export interface PoxEventStackAggregationIncrease extends PoxEventBase {
696
+ name: PoxEventName.StackAggregationIncrease;
697
+ data: {
698
+ /** String-quoted unsigned integer */
699
+ reward_cycle: string;
700
+ /** String-quoted unsigned integer */
701
+ amount_ustx: string;
702
+ /** String-quoted unsigned integer or null */
703
+ end_cycle_id: string | null;
704
+ /** String-quoted unsigned integer or null */
705
+ start_cycle_id: string | null;
706
+ };
707
+ }
708
+ export interface PoxEventRevokeDelegateStx extends PoxEventBase {
709
+ name: PoxEventName.RevokeDelegateStx;
710
+ data: {
711
+ delegate_to: string;
712
+ /** String-quoted unsigned integer or null */
713
+ end_cycle_id: string | null;
714
+ /** String-quoted unsigned integer or null */
715
+ start_cycle_id: string | null;
716
+ };
717
+ }
718
+ 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;
@@ -180,3 +180,21 @@ var ClarityTypeID;
180
180
  ClarityTypeID[ClarityTypeID["StringAscii"] = 13] = "StringAscii";
181
181
  ClarityTypeID[ClarityTypeID["StringUtf8"] = 14] = "StringUtf8";
182
182
  })(ClarityTypeID = exports.ClarityTypeID || (exports.ClarityTypeID = {}));
183
+ // ============================================================================
184
+ // PoX Synthetic Event Types
185
+ // ============================================================================
186
+ var PoxEventName;
187
+ (function (PoxEventName) {
188
+ PoxEventName["HandleUnlock"] = "handle-unlock";
189
+ PoxEventName["StackStx"] = "stack-stx";
190
+ PoxEventName["StackIncrease"] = "stack-increase";
191
+ PoxEventName["StackExtend"] = "stack-extend";
192
+ PoxEventName["DelegateStx"] = "delegate-stx";
193
+ PoxEventName["DelegateStackStx"] = "delegate-stack-stx";
194
+ PoxEventName["DelegateStackIncrease"] = "delegate-stack-increase";
195
+ PoxEventName["DelegateStackExtend"] = "delegate-stack-extend";
196
+ PoxEventName["StackAggregationCommit"] = "stack-aggregation-commit";
197
+ PoxEventName["StackAggregationCommitIndexed"] = "stack-aggregation-commit-indexed";
198
+ PoxEventName["StackAggregationIncrease"] = "stack-aggregation-increase";
199
+ PoxEventName["RevokeDelegateStx"] = "revoke-delegate-stx";
200
+ })(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.5.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": {