@secondlayer/shared 6.33.0 → 6.33.1

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.
@@ -33,6 +33,15 @@ declare function getX402Token(symbol: X402TokenSymbol): X402Token;
33
33
  /**\\n* Optimistic-serve reputation: the Redis key + TTL for a payer principal's\\n* "strike" counter (reverted/dropped payments). Single-sourced so the API gate\\n* (reader) and the worker reconciler (writer, on revert) agree without a\\n* cross-package import.\\n*/
34
34
  declare const X402_STRIKE_TTL_SECONDS: number;
35
35
  declare function x402StrikeKey(principal: string): string;
36
+ /**
37
+ * Normalize an x402 payment txid to the form stored in `decoded_events`.
38
+ * Broadcast/ledger txids are bare lowercase hex; the index stores them
39
+ * `0x`-prefixed. Querying `decoded_events` with the bare form silently never
40
+ * matches — which wedged the rail's confirmation layer (optimistic payments
41
+ * reverted + struck the payer; confirmed-tier never confirmed). Idempotent and
42
+ * case-normalizing, so it's safe to apply at every index query site.
43
+ */
44
+ declare function toIndexTxId(txid: string): string;
36
45
  /** Resolve a token by its x402 `asset` string (the value carried in `accepts[].asset`). */
37
46
  declare function findX402TokenByAsset(asset: string): X402Token | undefined;
38
- export { x402StrikeKey, getX402Token, findX402TokenByAsset, X402_TOKEN_SYMBOLS, X402_TOKENS, X402_STRIKE_TTL_SECONDS, X402_NETWORK, X402TokenSymbol, X402Token, X402Network };
47
+ export { x402StrikeKey, toIndexTxId, getX402Token, findX402TokenByAsset, X402_TOKEN_SYMBOLS, X402_TOKENS, X402_STRIKE_TTL_SECONDS, X402_NETWORK, X402TokenSymbol, X402Token, X402Network };
package/dist/src/x402.js CHANGED
@@ -53,6 +53,10 @@ var X402_STRIKE_TTL_SECONDS = 24 * 60 * 60;
53
53
  function x402StrikeKey(principal) {
54
54
  return `x402:strikes:${principal}`;
55
55
  }
56
+ function toIndexTxId(txid) {
57
+ const hex = txid.startsWith("0x") ? txid.slice(2) : txid;
58
+ return `0x${hex.toLowerCase()}`;
59
+ }
56
60
  function findX402TokenByAsset(asset) {
57
61
  for (const symbol of X402_TOKEN_SYMBOLS) {
58
62
  if (X402_TOKENS[symbol].asset === asset)
@@ -62,6 +66,7 @@ function findX402TokenByAsset(asset) {
62
66
  }
63
67
  export {
64
68
  x402StrikeKey,
69
+ toIndexTxId,
65
70
  getX402Token,
66
71
  findX402TokenByAsset,
67
72
  X402_TOKEN_SYMBOLS,
@@ -70,5 +75,5 @@ export {
70
75
  X402_NETWORK
71
76
  };
72
77
 
73
- //# debugId=7AA9D65F1DB692C864756E2164756E21
78
+ //# debugId=AA279D8400B972DA64756E2164756E21
74
79
  //# sourceMappingURL=x402.js.map
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/x402.ts"],
4
4
  "sourcesContent": [
5
- "/**\n * x402 payment-rail shared constants: the v1 token set + CAIP-2 network ids.\n *\n * Single-sourced here (not in the API package) so the SDK/MCP client and the\n * API facilitator agree on asset ids, decimals, and the `accepts[]` asset-string\n * format. All ids are mainnet and confirmed on-chain (2026-06). Per-call prices\n * are NOT here — they are API-local (see `packages/api/src/x402/catalog.ts`) and\n * exposed to clients at runtime via `GET /x402/supported`.\n */\n\n/** CAIP-2 network ids used in x402 v2 `accepts[]` entries. */\nexport const X402_NETWORK = {\n\tmainnet: \"stacks:1\",\n\ttestnet: \"stacks:2147483648\",\n} as const;\n\nexport type X402Network = (typeof X402_NETWORK)[keyof typeof X402_NETWORK];\n\nexport type X402TokenSymbol = \"STX\" | \"sBTC\" | \"USDCx\";\n\nexport type X402Token = {\n\tsymbol: X402TokenSymbol;\n\t/** x402 `asset` string: `\"STX\"` for native, else the `<addr>.<contract>` id. */\n\tasset: string;\n\t/** SIP-010 contract id (`<addr>.<contract>`); `null` for native STX. */\n\tcontractId: string | null;\n\t/** SIP-010 fungible-token asset name (the `::<name>` suffix); `null` for STX. */\n\tassetName: string | null;\n\t/** Fully-qualified SIP-010 asset identifier (`<id>::<name>`); `null` for STX. */\n\tassetIdentifier: string | null;\n\tdecimals: number;\n};\n\n/** v1 token set. sBTC + USDCx ids verified against the deployed mainnet contracts. */\nexport const X402_TOKENS: Record<X402TokenSymbol, X402Token> = {\n\tSTX: {\n\t\tsymbol: \"STX\",\n\t\tasset: \"STX\",\n\t\tcontractId: null,\n\t\tassetName: null,\n\t\tassetIdentifier: null,\n\t\tdecimals: 6,\n\t},\n\tsBTC: {\n\t\tsymbol: \"sBTC\",\n\t\tasset: \"SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token\",\n\t\tcontractId: \"SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token\",\n\t\tassetName: \"sbtc-token\",\n\t\tassetIdentifier:\n\t\t\t\"SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token::sbtc-token\",\n\t\tdecimals: 8,\n\t},\n\tUSDCx: {\n\t\tsymbol: \"USDCx\",\n\t\tasset: \"SP120SBRBQJ00MCWS7TM5R8WJNTTKD5K0HFRC2CNE.usdcx\",\n\t\tcontractId: \"SP120SBRBQJ00MCWS7TM5R8WJNTTKD5K0HFRC2CNE.usdcx\",\n\t\tassetName: \"usdcx-token\",\n\t\tassetIdentifier:\n\t\t\t\"SP120SBRBQJ00MCWS7TM5R8WJNTTKD5K0HFRC2CNE.usdcx::usdcx-token\",\n\t\tdecimals: 6,\n\t},\n} as const;\n\nexport const X402_TOKEN_SYMBOLS = Object.keys(X402_TOKENS) as X402TokenSymbol[];\n\nexport function getX402Token(symbol: X402TokenSymbol): X402Token {\n\treturn X402_TOKENS[symbol];\n}\n\n/**\n * Optimistic-serve reputation: the Redis key + TTL for a payer principal's\n * \"strike\" counter (reverted/dropped payments). Single-sourced so the API gate\n * (reader) and the worker reconciler (writer, on revert) agree without a\n * cross-package import.\n */\nexport const X402_STRIKE_TTL_SECONDS: number = 24 * 60 * 60;\n\nexport function x402StrikeKey(principal: string): string {\n\treturn `x402:strikes:${principal}`;\n}\n\n/** Resolve a token by its x402 `asset` string (the value carried in `accepts[].asset`). */\nexport function findX402TokenByAsset(asset: string): X402Token | undefined {\n\tfor (const symbol of X402_TOKEN_SYMBOLS) {\n\t\tif (X402_TOKENS[symbol].asset === asset) return X402_TOKENS[symbol];\n\t}\n\treturn undefined;\n}\n"
5
+ "/**\n * x402 payment-rail shared constants: the v1 token set + CAIP-2 network ids.\n *\n * Single-sourced here (not in the API package) so the SDK/MCP client and the\n * API facilitator agree on asset ids, decimals, and the `accepts[]` asset-string\n * format. All ids are mainnet and confirmed on-chain (2026-06). Per-call prices\n * are NOT here — they are API-local (see `packages/api/src/x402/catalog.ts`) and\n * exposed to clients at runtime via `GET /x402/supported`.\n */\n\n/** CAIP-2 network ids used in x402 v2 `accepts[]` entries. */\nexport const X402_NETWORK = {\n\tmainnet: \"stacks:1\",\n\ttestnet: \"stacks:2147483648\",\n} as const;\n\nexport type X402Network = (typeof X402_NETWORK)[keyof typeof X402_NETWORK];\n\nexport type X402TokenSymbol = \"STX\" | \"sBTC\" | \"USDCx\";\n\nexport type X402Token = {\n\tsymbol: X402TokenSymbol;\n\t/** x402 `asset` string: `\"STX\"` for native, else the `<addr>.<contract>` id. */\n\tasset: string;\n\t/** SIP-010 contract id (`<addr>.<contract>`); `null` for native STX. */\n\tcontractId: string | null;\n\t/** SIP-010 fungible-token asset name (the `::<name>` suffix); `null` for STX. */\n\tassetName: string | null;\n\t/** Fully-qualified SIP-010 asset identifier (`<id>::<name>`); `null` for STX. */\n\tassetIdentifier: string | null;\n\tdecimals: number;\n};\n\n/** v1 token set. sBTC + USDCx ids verified against the deployed mainnet contracts. */\nexport const X402_TOKENS: Record<X402TokenSymbol, X402Token> = {\n\tSTX: {\n\t\tsymbol: \"STX\",\n\t\tasset: \"STX\",\n\t\tcontractId: null,\n\t\tassetName: null,\n\t\tassetIdentifier: null,\n\t\tdecimals: 6,\n\t},\n\tsBTC: {\n\t\tsymbol: \"sBTC\",\n\t\tasset: \"SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token\",\n\t\tcontractId: \"SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token\",\n\t\tassetName: \"sbtc-token\",\n\t\tassetIdentifier:\n\t\t\t\"SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token::sbtc-token\",\n\t\tdecimals: 8,\n\t},\n\tUSDCx: {\n\t\tsymbol: \"USDCx\",\n\t\tasset: \"SP120SBRBQJ00MCWS7TM5R8WJNTTKD5K0HFRC2CNE.usdcx\",\n\t\tcontractId: \"SP120SBRBQJ00MCWS7TM5R8WJNTTKD5K0HFRC2CNE.usdcx\",\n\t\tassetName: \"usdcx-token\",\n\t\tassetIdentifier:\n\t\t\t\"SP120SBRBQJ00MCWS7TM5R8WJNTTKD5K0HFRC2CNE.usdcx::usdcx-token\",\n\t\tdecimals: 6,\n\t},\n} as const;\n\nexport const X402_TOKEN_SYMBOLS = Object.keys(X402_TOKENS) as X402TokenSymbol[];\n\nexport function getX402Token(symbol: X402TokenSymbol): X402Token {\n\treturn X402_TOKENS[symbol];\n}\n\n/**\n * Optimistic-serve reputation: the Redis key + TTL for a payer principal's\n * \"strike\" counter (reverted/dropped payments). Single-sourced so the API gate\n * (reader) and the worker reconciler (writer, on revert) agree without a\n * cross-package import.\n */\nexport const X402_STRIKE_TTL_SECONDS: number = 24 * 60 * 60;\n\nexport function x402StrikeKey(principal: string): string {\n\treturn `x402:strikes:${principal}`;\n}\n\n/**\n * Normalize an x402 payment txid to the form stored in `decoded_events`.\n * Broadcast/ledger txids are bare lowercase hex; the index stores them\n * `0x`-prefixed. Querying `decoded_events` with the bare form silently never\n * matches — which wedged the rail's confirmation layer (optimistic payments\n * reverted + struck the payer; confirmed-tier never confirmed). Idempotent and\n * case-normalizing, so it's safe to apply at every index query site.\n */\nexport function toIndexTxId(txid: string): string {\n\tconst hex = txid.startsWith(\"0x\") ? txid.slice(2) : txid;\n\treturn `0x${hex.toLowerCase()}`;\n}\n\n/** Resolve a token by its x402 `asset` string (the value carried in `accepts[].asset`). */\nexport function findX402TokenByAsset(asset: string): X402Token | undefined {\n\tfor (const symbol of X402_TOKEN_SYMBOLS) {\n\t\tif (X402_TOKENS[symbol].asset === asset) return X402_TOKENS[symbol];\n\t}\n\treturn undefined;\n}\n"
6
6
  ],
7
- "mappings": ";;;;;;;;;;;;;;;;;AAWO,IAAM,eAAe;AAAA,EAC3B,SAAS;AAAA,EACT,SAAS;AACV;AAoBO,IAAM,cAAkD;AAAA,EAC9D,KAAK;AAAA,IACJ,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,WAAW;AAAA,IACX,iBAAiB;AAAA,IACjB,UAAU;AAAA,EACX;AAAA,EACA,MAAM;AAAA,IACL,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,WAAW;AAAA,IACX,iBACC;AAAA,IACD,UAAU;AAAA,EACX;AAAA,EACA,OAAO;AAAA,IACN,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,WAAW;AAAA,IACX,iBACC;AAAA,IACD,UAAU;AAAA,EACX;AACD;AAEO,IAAM,qBAAqB,OAAO,KAAK,WAAW;AAElD,SAAS,YAAY,CAAC,QAAoC;AAAA,EAChE,OAAO,YAAY;AAAA;AASb,IAAM,0BAAkC,KAAK,KAAK;AAElD,SAAS,aAAa,CAAC,WAA2B;AAAA,EACxD,OAAO,gBAAgB;AAAA;AAIjB,SAAS,oBAAoB,CAAC,OAAsC;AAAA,EAC1E,WAAW,UAAU,oBAAoB;AAAA,IACxC,IAAI,YAAY,QAAQ,UAAU;AAAA,MAAO,OAAO,YAAY;AAAA,EAC7D;AAAA,EACA;AAAA;",
8
- "debugId": "7AA9D65F1DB692C864756E2164756E21",
7
+ "mappings": ";;;;;;;;;;;;;;;;;AAWO,IAAM,eAAe;AAAA,EAC3B,SAAS;AAAA,EACT,SAAS;AACV;AAoBO,IAAM,cAAkD;AAAA,EAC9D,KAAK;AAAA,IACJ,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,WAAW;AAAA,IACX,iBAAiB;AAAA,IACjB,UAAU;AAAA,EACX;AAAA,EACA,MAAM;AAAA,IACL,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,WAAW;AAAA,IACX,iBACC;AAAA,IACD,UAAU;AAAA,EACX;AAAA,EACA,OAAO;AAAA,IACN,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,WAAW;AAAA,IACX,iBACC;AAAA,IACD,UAAU;AAAA,EACX;AACD;AAEO,IAAM,qBAAqB,OAAO,KAAK,WAAW;AAElD,SAAS,YAAY,CAAC,QAAoC;AAAA,EAChE,OAAO,YAAY;AAAA;AASb,IAAM,0BAAkC,KAAK,KAAK;AAElD,SAAS,aAAa,CAAC,WAA2B;AAAA,EACxD,OAAO,gBAAgB;AAAA;AAWjB,SAAS,WAAW,CAAC,MAAsB;AAAA,EACjD,MAAM,MAAM,KAAK,WAAW,IAAI,IAAI,KAAK,MAAM,CAAC,IAAI;AAAA,EACpD,OAAO,KAAK,IAAI,YAAY;AAAA;AAItB,SAAS,oBAAoB,CAAC,OAAsC;AAAA,EAC1E,WAAW,UAAU,oBAAoB;AAAA,IACxC,IAAI,YAAY,QAAQ,UAAU;AAAA,MAAO,OAAO,YAAY;AAAA,EAC7D;AAAA,EACA;AAAA;",
8
+ "debugId": "AA279D8400B972DA64756E2164756E21",
9
9
  "names": []
10
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@secondlayer/shared",
3
- "version": "6.33.0",
3
+ "version": "6.33.1",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",