@outpost-protocol/core 0.1.0 → 0.1.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.
package/dist/base32.d.ts CHANGED
@@ -3,6 +3,11 @@
3
3
  * Valid in QR Alphanumeric Mode with zero whitespace or Markdown characters.
4
4
  */
5
5
  export declare const BASE32_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
6
+ /**
7
+ * Hard cap on framed/raw Base32 wire input length in characters (exact parity with Rust `outpost-wire`, `AUD6-M11`).
8
+ * Rejects multi-megabyte inputs in O(1) before trimming, slicing, or allocating decode buffers.
9
+ */
10
+ export declare const MAX_FRAMED_BASE32_LEN = 32768;
6
11
  /**
7
12
  * Encode arbitrary bytes to unpadded uppercase RFC 4648 Base32 (`A-Z`, `2-7`).
8
13
  */
package/dist/base32.js CHANGED
@@ -4,6 +4,11 @@ import { appendCrc32c, verifyAndStripCrc32c } from "./crc32c.js";
4
4
  * Valid in QR Alphanumeric Mode with zero whitespace or Markdown characters.
5
5
  */
6
6
  export const BASE32_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
7
+ /**
8
+ * Hard cap on framed/raw Base32 wire input length in characters (exact parity with Rust `outpost-wire`, `AUD6-M11`).
9
+ * Rejects multi-megabyte inputs in O(1) before trimming, slicing, or allocating decode buffers.
10
+ */
11
+ export const MAX_FRAMED_BASE32_LEN = 32_768;
7
12
  const DECODE_MAP = (() => {
8
13
  const map = new Int8Array(128);
9
14
  map.fill(-1);
@@ -50,6 +55,9 @@ export function decodeBase32(input) {
50
55
  if (input.length === 0) {
51
56
  return new Uint8Array(0);
52
57
  }
58
+ if (input.length > MAX_FRAMED_BASE32_LEN) {
59
+ throw new Error(`Base32 input length (${input.length}) exceeds maximum allowed length (${MAX_FRAMED_BASE32_LEN})`);
60
+ }
53
61
  // Valid unpadded RFC 4648 Base32 lengths mod 8 are 0, 2, 4, 5, 7.
54
62
  const rem = input.length % 8;
55
63
  if (rem === 1 || rem === 3 || rem === 6) {
@@ -105,6 +113,9 @@ export function encodeFramed(hrp, payload) {
105
113
  * returning uppercase `hrp` and verified `payload`.
106
114
  */
107
115
  export function splitFramed(text) {
116
+ if (text.length > MAX_FRAMED_BASE32_LEN) {
117
+ throw new Error(`Framed Base32 input length (${text.length}) exceeds maximum allowed length (${MAX_FRAMED_BASE32_LEN})`);
118
+ }
108
119
  const trimmed = text.trim();
109
120
  const sepIndex = trimmed.indexOf("1");
110
121
  if (sepIndex <= 0) {
package/dist/bcur.js CHANGED
@@ -1,4 +1,4 @@
1
- import { decodeBase32, encodeBase32 } from "./base32.js";
1
+ import { decodeBase32, encodeBase32, MAX_FRAMED_BASE32_LEN } from "./base32.js";
2
2
  import { appendCrc32c, verifyAndStripCrc32c } from "./crc32c.js";
3
3
  import { bytesEqual } from "./xdr.js";
4
4
  /**
@@ -49,6 +49,9 @@ export function encodeUrSmesh(payload, maxChunkBytes = DEFAULT_UR_SMESH_MAX_CHUN
49
49
  * Verifies frame header format, bounds, strict Base32, and per-frame CRC32C.
50
50
  */
51
51
  export function parseUrSmeshFrame(frame) {
52
+ if (frame.length > MAX_FRAMED_BASE32_LEN) {
53
+ throw new Error(`ur:smesh frame length (${frame.length}) exceeds maximum allowed length (${MAX_FRAMED_BASE32_LEN})`);
54
+ }
52
55
  const upper = frame.trim().toUpperCase();
53
56
  const parts = upper.split("/");
54
57
  if (parts.length !== 3 || parts[0] !== UR_SMESH_PREFIX) {
package/dist/wire.d.ts CHANGED
@@ -8,6 +8,8 @@ export declare const HRP_SMESHC = "SMESHC";
8
8
  export declare const SMESHI1_BYTE_LENGTH = 174;
9
9
  export declare const CLASSIC_MAX_BASE_FEE = 100;
10
10
  export declare const MAX_MEMO_UTF8_BYTES = 32;
11
+ /** Hard cap on skipped unknown odd TLVs in `SREQ1` (exact parity with Rust `outpost-wire`, `AUD6-M11`). */
12
+ export declare const MAX_SREQ1_UNKNOWN_TLVS = 32;
11
13
  export declare const GENESIS_MIN_EXIT_DELAY_SECS = 259200n;
12
14
  export declare const GENESIS_MAX_EXIT_DELAY_SECS = 2592000n;
13
15
  /**
package/dist/wire.js CHANGED
@@ -1,4 +1,4 @@
1
- import { decodeFramed, encodeFramed, splitFramed } from "./base32.js";
1
+ import { decodeFramed, encodeFramed, MAX_FRAMED_BASE32_LEN, splitFramed } from "./base32.js";
2
2
  import { parseUrSmeshFrame, UR_SMESH_PREFIX } from "./bcur.js";
3
3
  import { assertBigInt, assertBytesLength, assertSortedUniqueWitnesses, assertU16, assertU32, assertU8, concatBytes, decodeI64Be, decodeU128Be, decodeU16Be, decodeU32Be, decodeU64Be, encodeI64Be, encodeU128Be, encodeU16Be, encodeU32Be, encodeU64Be, encodeU8, MAX_I128, MAX_I64, MAX_U128, MAX_U64, MAX_WITNESSES, } from "./digest.js";
4
4
  import { assertNetworkHint, assertValidWireAddress, decodeWireAddress, decodeWireToken, encodeWireAddress, encodeWireToken, WIRE_ADDRESS_BYTE_LENGTH, } from "./xdr.js";
@@ -13,6 +13,8 @@ export const HRP_SMESHC = "SMESHC";
13
13
  export const SMESHI1_BYTE_LENGTH = 174;
14
14
  export const CLASSIC_MAX_BASE_FEE = 100;
15
15
  export const MAX_MEMO_UTF8_BYTES = 32;
16
+ /** Hard cap on skipped unknown odd TLVs in `SREQ1` (exact parity with Rust `outpost-wire`, `AUD6-M11`). */
17
+ export const MAX_SREQ1_UNKNOWN_TLVS = 32;
16
18
  export const GENESIS_MIN_EXIT_DELAY_SECS = 259200n; // 72 hours (SPEC §2.3)
17
19
  export const GENESIS_MAX_EXIT_DELAY_SECS = 2592000n; // 30 days (SPEC §2.3)
18
20
  /**
@@ -226,6 +228,7 @@ export function decodeSreq1Bytes(raw) {
226
228
  let acceptedFactoryVers;
227
229
  let memo;
228
230
  const seenKnownTlvs = new Set();
231
+ let unknownOddTlvCount = 0;
229
232
  while (offset < raw.length) {
230
233
  if (offset + 2 > raw.length) {
231
234
  throw new Error(`Truncated SREQ1 TLV header at offset ${offset}`);
@@ -315,6 +318,12 @@ export function decodeSreq1Bytes(raw) {
315
318
  if ((tlvType & 1) === 0) {
316
319
  throw new Error(`Unknown critical (even) SREQ1 TLV type 0x${tlvType.toString(16).padStart(2, "0")}`);
317
320
  }
321
+ // AUD6-M11: Bound skipped unknown odd TLVs so adversarial packets packed with
322
+ // thousands of 0-byte unknown odd TLVs are rejected cleanly.
323
+ unknownOddTlvCount += 1;
324
+ if (unknownOddTlvCount > MAX_SREQ1_UNKNOWN_TLVS) {
325
+ throw new Error(`SREQ1 unknown odd TLV count exceeds maximum (${MAX_SREQ1_UNKNOWN_TLVS})`);
326
+ }
318
327
  // Odd unknown TLV: skip safely
319
328
  break;
320
329
  }
@@ -954,8 +963,11 @@ export function decodeSmeshc1(encoded) {
954
963
  * `"UNVERIFIED — requires online witness co-signing before handing over goods"`.
955
964
  */
956
965
  export function classifyPayload(encoded) {
966
+ if (encoded.length > MAX_FRAMED_BASE32_LEN) {
967
+ throw new Error(`Encoded wire payload length (${encoded.length}) exceeds maximum allowed length (${MAX_FRAMED_BASE32_LEN})`);
968
+ }
957
969
  const trimmed = encoded.trim();
958
- if (trimmed.toUpperCase().startsWith(`${UR_SMESH_PREFIX}/`)) {
970
+ if (trimmed.slice(0, UR_SMESH_PREFIX.length + 1).toUpperCase() === `${UR_SMESH_PREFIX}/`) {
959
971
  return {
960
972
  mode: "ur_smesh_frame",
961
973
  prefix: "UR:SMESH",
@@ -162,6 +162,7 @@ export class WitnessClient {
162
162
  method,
163
163
  headers,
164
164
  ...(serializedBody !== undefined ? { body: serializedBody } : {}),
165
+ redirect: "error",
165
166
  signal: controller.signal,
166
167
  });
167
168
  const text = await readBoundedResponseText(res, this.maxResponseBytes);
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@outpost-protocol/core",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Outpost v1.2 offline Stellar payment wire codec, cryptographic digests, BLE transport, and wallet SDK",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://outpost.cash",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "https://github.com/Outpost-cash/outpost-protocol.git",
9
+ "url": "git+https://github.com/Outpost-cash/outpost-protocol.git",
10
10
  "directory": "packages/core"
11
11
  },
12
12
  "bugs": {