@invisible-labs/sdk 0.7.0-devnet → 0.9.0-devnet

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.
Files changed (39) hide show
  1. package/README.md +7 -0
  2. package/dist/.invisible-sdk-build-target.json +1 -1
  3. package/dist/{chunk-HJFMDMPY.js → chunk-6AKBRYKO.js} +3 -3
  4. package/dist/{chunk-HJFMDMPY.js.map → chunk-6AKBRYKO.js.map} +1 -1
  5. package/dist/{chunk-DCTYBUY3.js → chunk-AIKC2XQS.js} +3 -3
  6. package/dist/{chunk-DCTYBUY3.js.map → chunk-AIKC2XQS.js.map} +1 -1
  7. package/dist/{chunk-Y7AK6RBV.js → chunk-EOPZVOVP.js} +11 -6
  8. package/dist/chunk-EOPZVOVP.js.map +1 -0
  9. package/dist/{chunk-EBWTAXNT.js → chunk-EPWTRF5U.js} +3 -3
  10. package/dist/{chunk-EBWTAXNT.js.map → chunk-EPWTRF5U.js.map} +1 -1
  11. package/dist/{chunk-4X5OCCQW.js → chunk-HWRMSK7E.js} +7 -5
  12. package/dist/chunk-HWRMSK7E.js.map +1 -0
  13. package/dist/{chunk-3MDHAS4D.js → chunk-ISIWWGSR.js} +16 -6
  14. package/dist/chunk-ISIWWGSR.js.map +1 -0
  15. package/dist/{chunk-3TGQ4CZ3.js → chunk-QF5TSUQE.js} +169 -32
  16. package/dist/chunk-QF5TSUQE.js.map +1 -0
  17. package/dist/{chunk-QRN46R3F.js → chunk-RWKG7N7I.js} +10 -3
  18. package/dist/chunk-RWKG7N7I.js.map +1 -0
  19. package/dist/coordinator-DHL3AP7V.js +4 -0
  20. package/dist/{coordinator-PEWHNZ7I.js.map → coordinator-DHL3AP7V.js.map} +1 -1
  21. package/dist/events.js +3 -3
  22. package/dist/index.d.ts +1 -1
  23. package/dist/index.js +8 -8
  24. package/dist/lp.d.ts +10 -1
  25. package/dist/lp.js +178 -65
  26. package/dist/lp.js.map +1 -1
  27. package/dist/stats.js +1 -1
  28. package/dist/storage.js +2 -2
  29. package/dist/{types.generated-YhFu9ZBR.d.ts → types.generated-DrM2M4DZ.d.ts} +6 -2
  30. package/dist/user.d.ts +18 -9
  31. package/dist/user.js +85 -29
  32. package/dist/user.js.map +1 -1
  33. package/package.json +1 -1
  34. package/dist/chunk-3MDHAS4D.js.map +0 -1
  35. package/dist/chunk-3TGQ4CZ3.js.map +0 -1
  36. package/dist/chunk-4X5OCCQW.js.map +0 -1
  37. package/dist/chunk-QRN46R3F.js.map +0 -1
  38. package/dist/chunk-Y7AK6RBV.js.map +0 -1
  39. package/dist/coordinator-PEWHNZ7I.js +0 -4
@@ -1,4 +1,4 @@
1
- import { PolicyValidationError, AttestationError } from './chunk-QRN46R3F.js';
1
+ import { PolicyValidationError, AttestationError } from './chunk-RWKG7N7I.js';
2
2
 
3
3
  // src/core/solanaAddress.ts
4
4
  var SOLANA_PUBLIC_KEY_BYTE_LENGTH = 32;
@@ -119,5 +119,5 @@ function assertAttested(session) {
119
119
  }
120
120
 
121
121
  export { assertAttested, hex, lamports, publicKey, requestId, solanaAddressFromPublicKeyBytes };
122
- //# sourceMappingURL=chunk-EBWTAXNT.js.map
123
- //# sourceMappingURL=chunk-EBWTAXNT.js.map
122
+ //# sourceMappingURL=chunk-EPWTRF5U.js.map
123
+ //# sourceMappingURL=chunk-EPWTRF5U.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/core/solanaAddress.ts","../src/core/brands.ts","../src/session/guards.ts"],"names":[],"mappings":";;;AAEA,IAAM,6BAAA,GAAgC,EAAA;AACtC,IAAM,yBAAA,GAA4B,EAAA;AAClC,IAAM,yBAAA,GAA4B,EAAA;AAClC,IAAM,eAAA,GAAkB,4DAAA;AACxB,IAAM,YAAA,GAAe,MAAA,CAAO,eAAA,CAAgB,MAAM,CAAA;AAClD,IAAM,wBAAA,GAA2B,GAAA;AACjC,IAAM,SAAA,GAAY,KAAA;AAClB,IAAM,eAAA,GAAkB,EAAA;AACxB,IAAM,2BA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;AAEA,SAAS,+BAA+B,KAAA,EAAsB;AAC5D,EAAA,MAAM,IAAI,qBAAA;AAAA,IACR,6BAAA;AAAA,IACA,mEAAmE,KAAK,CAAA;AAAA,GAC1E;AACF;;;AC3DO,SAAS,SAAS,KAAA,EAAyB;AAChD,EAAA,IAAI,CAAC,MAAA,CAAO,aAAA,CAAc,KAAK,CAAA,IAAK,QAAQ,CAAA,EAAG;AAC7C,IAAA,MAAM,IAAI,qBAAA;AAAA,MACR,gBAAA;AAAA,MACA,CAAA,uDAAA,EAA0D,MAAA,CAAO,KAAK,CAAC,CAAA;AAAA,KACzE;AAAA,EACF;AACA,EAAA,OAAO,KAAA;AACT;AASO,SAAS,UAAU,KAAA,EAA0B;AAClD,EAAA,4BAAA,CAA6B,KAAK,CAAA;AAClC,EAAA,OAAO,KAAA;AACT;AAQO,SAAS,UAAU,KAAA,EAA0B;AAClD,EAAA,IAAI,KAAA,CAAM,WAAW,CAAA,EAAG;AACtB,IAAA,MAAM,IAAI,MAAM,sCAAsC,CAAA;AAAA,EACxD;AACA,EAAA,OAAO,KAAA;AACT;AAOO,SAAS,IAAI,KAAA,EAAoB;AACtC,EAAA,IAAI,CAAC,aAAA,CAAc,IAAA,CAAK,KAAK,CAAA,EAAG;AAC9B,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,mBAAA,EAAsB,KAAK,CAAA,CAAE,CAAA;AAAA,EAC/C;AACA,EAAA,OAAO,KAAA;AACT;;;ACpEO,SAAS,eAAe,OAAA,EAAwB;AACrD,EAAA,IAAI,CAAC,QAAQ,QAAA,EAAU;AACrB,IAAA,MAAM,IAAI,gBAAA;AAAA,MACR,cAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AACF","file":"chunk-EBWTAXNT.js","sourcesContent":["import { PolicyValidationError } from \"./errors.js\";\n\nconst SOLANA_PUBLIC_KEY_BYTE_LENGTH = 32;\nconst SOLANA_ADDRESS_MIN_LENGTH = 32;\nconst SOLANA_ADDRESS_MAX_LENGTH = 44;\nconst BASE58_ALPHABET = \"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz\";\nconst BASE58_RADIX = BigInt(BASE58_ALPHABET.length);\nconst BASE58_LEADING_ZERO_CHAR = \"1\";\nconst BYTE_MASK = 0xffn;\nconst BYTE_RADIX_BITS = 8n;\nconst MAX_SOLANA_PUBLIC_KEY_VALUE = (1n << (BigInt(SOLANA_PUBLIC_KEY_BYTE_LENGTH) * 8n)) - 1n;\n\nconst BASE58_DIGITS = new Map<string, number>(\n Array.from(BASE58_ALPHABET, (character, index) => [character, index]),\n);\n\nexport function assertCanonicalSolanaAddress(value: unknown): asserts value is string {\n if (typeof value !== \"string\") {\n throw new PolicyValidationError(\n \"INVALID_DESTINATION_ADDRESS\",\n `destination address must be a string, received ${typeof value}`,\n );\n }\n if (\n value.trim() !== value ||\n value.length < SOLANA_ADDRESS_MIN_LENGTH ||\n value.length > SOLANA_ADDRESS_MAX_LENGTH\n ) {\n throwInvalidDestinationAddress(value);\n }\n\n const decoded = decodeBase58SolanaAddress(value);\n if (encodeBase58(decoded) !== value) {\n throwInvalidDestinationAddress(value);\n }\n}\n\n/** Encode a 32-byte Ed25519 public key as its canonical Solana address. */\nexport function solanaAddressFromPublicKeyBytes(bytes: Uint8Array): string {\n if (bytes.byteLength !== SOLANA_PUBLIC_KEY_BYTE_LENGTH) {\n throw new PolicyValidationError(\n \"INVALID_DESTINATION_ADDRESS\",\n `Solana public key must be ${SOLANA_PUBLIC_KEY_BYTE_LENGTH} bytes, received ${bytes.byteLength}`,\n );\n }\n return encodeBase58(bytes);\n}\n\nfunction decodeBase58SolanaAddress(value: string): Uint8Array {\n let decoded = 0n;\n for (const character of value) {\n const digit = BASE58_DIGITS.get(character);\n if (digit === undefined) {\n throwInvalidDestinationAddress(value);\n }\n decoded = decoded * BASE58_RADIX + BigInt(digit);\n if (decoded > MAX_SOLANA_PUBLIC_KEY_VALUE) {\n throwInvalidDestinationAddress(value);\n }\n }\n\n const bytes = new Uint8Array(SOLANA_PUBLIC_KEY_BYTE_LENGTH);\n for (let index = SOLANA_PUBLIC_KEY_BYTE_LENGTH - 1; index >= 0; index -= 1) {\n bytes[index] = Number(decoded & BYTE_MASK);\n decoded >>= BYTE_RADIX_BITS;\n }\n return bytes;\n}\n\nfunction encodeBase58(bytes: Uint8Array): string {\n let leadingZeros = 0;\n for (const byte of bytes) {\n if (byte !== 0) break;\n leadingZeros += 1;\n }\n\n let value = 0n;\n for (const byte of bytes) {\n value = (value << BYTE_RADIX_BITS) + BigInt(byte);\n }\n\n let encoded = \"\";\n while (value > 0n) {\n const digit = Number(value % BASE58_RADIX);\n encoded = BASE58_ALPHABET[digit]! + encoded;\n value /= BASE58_RADIX;\n }\n\n return BASE58_LEADING_ZERO_CHAR.repeat(leadingZeros) + encoded;\n}\n\nfunction throwInvalidDestinationAddress(value: string): never {\n throw new PolicyValidationError(\n \"INVALID_DESTINATION_ADDRESS\",\n `destination address must be a canonical 32-byte Solana address: ${value}`,\n );\n}\n","/**\n * Branded scalar types.\n *\n * Branding makes structurally-identical primitives (a lamport amount, a base58\n * address, a correlation id) non-interchangeable at the type level, so the\n * compiler catches \"passed a request id where an address was expected\" before\n * it reaches the wire. The brand exists only at compile time; at runtime these\n * are plain `number` / `string`.\n *\n * Construct branded values through the smart constructors here. These\n * constructors enforce scalar-level invariants; payout-policy semantics stay in\n * the validation module.\n */\n\nimport { PolicyValidationError } from \"./errors.js\";\nimport { assertCanonicalSolanaAddress } from \"./solanaAddress.js\";\n\n/** Attach a compile-time-only brand `B` to base type `T`. */\nexport type Brand<T, B extends string> = T & { readonly __brand: B };\n\n/** A non-negative integer amount of lamports (1 SOL = 1_000_000_000 lamports). */\nexport type Lamports = Brand<number, \"Lamports\">;\n\n/** A Solana account address as base58 text. */\nexport type PublicKey = Brand<string, \"PublicKey\">;\n\n/** A client-generated correlation id for one logical command. */\nexport type RequestId = Brand<string, \"RequestId\">;\n\n/** Lowercase hexadecimal text (no `0x` prefix). */\nexport type Hex = Brand<string, \"Hex\">;\n\n/**\n * Brand a number as {@link Lamports}.\n *\n * @throws PolicyValidationError `INVALID_AMOUNT` if not a non-negative safe integer.\n */\nexport function lamports(value: number): Lamports {\n if (!Number.isSafeInteger(value) || value < 0) {\n throw new PolicyValidationError(\n \"INVALID_AMOUNT\",\n `lamports must be a non-negative safe integer, received ${String(value)}`,\n );\n }\n return value as Lamports;\n}\n\n/**\n * Brand a string as a {@link PublicKey}.\n *\n * Enforces canonical base58 encoding of a 32-byte Solana public key.\n *\n * @throws PolicyValidationError `INVALID_DESTINATION_ADDRESS` if obviously malformed.\n */\nexport function publicKey(value: string): PublicKey {\n assertCanonicalSolanaAddress(value);\n return value as PublicKey;\n}\n\n/**\n * Brand a non-empty string as a {@link RequestId}.\n *\n * @throws PolicyValidationError `INVALID_AMOUNT` is not appropriate here; an empty\n * id is a programming error, so this throws a plain `Error`.\n */\nexport function requestId(value: string): RequestId {\n if (value.length === 0) {\n throw new Error(\"requestId must be a non-empty string\");\n }\n return value as RequestId;\n}\n\n/**\n * Brand a string as lowercase {@link Hex}.\n *\n * @throws Error if the string contains non-hex characters.\n */\nexport function hex(value: string): Hex {\n if (!/^[0-9a-f]*$/.test(value)) {\n throw new Error(`not lowercase hex: ${value}`);\n }\n return value as Hex;\n}\n","/**\n * Session guards used by mutating commands.\n */\n\nimport { AttestationError } from \"../core/errors.js\";\nimport type { Session } from \"../core/session.js\";\n\n/**\n * Assert the session has passed attestation. Every mutating actor command calls\n * this before touching the wire, so an unattested session can never sign or\n * send sensitive material.\n *\n * @throws AttestationError `NOT_ATTESTED` when the session is not attested.\n */\nexport function assertAttested(session: Session): void {\n if (!session.attested) {\n throw new AttestationError(\n \"NOT_ATTESTED\",\n \"session is not attested; sensitive commands are blocked until attestation completes\",\n );\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/core/solanaAddress.ts","../src/core/brands.ts","../src/session/guards.ts"],"names":[],"mappings":";;;AAEA,IAAM,6BAAA,GA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AAC,QAAQ,QAAA,EAAU;AACrB,IAAA,MAAM,IAAI,gBAAA;AAAA,MACR,cAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AACF","file":"chunk-EPWTRF5U.js","sourcesContent":["import { PolicyValidationError } from \"./errors.js\";\n\nconst SOLANA_PUBLIC_KEY_BYTE_LENGTH = 32;\nconst SOLANA_ADDRESS_MIN_LENGTH = 32;\nconst SOLANA_ADDRESS_MAX_LENGTH = 44;\nconst BASE58_ALPHABET = \"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz\";\nconst BASE58_RADIX = BigInt(BASE58_ALPHABET.length);\nconst BASE58_LEADING_ZERO_CHAR = \"1\";\nconst BYTE_MASK = 0xffn;\nconst BYTE_RADIX_BITS = 8n;\nconst MAX_SOLANA_PUBLIC_KEY_VALUE = (1n << (BigInt(SOLANA_PUBLIC_KEY_BYTE_LENGTH) * 8n)) - 1n;\n\nconst BASE58_DIGITS = new Map<string, number>(\n Array.from(BASE58_ALPHABET, (character, index) => [character, index]),\n);\n\nexport function assertCanonicalSolanaAddress(value: unknown): asserts value is string {\n if (typeof value !== \"string\") {\n throw new PolicyValidationError(\n \"INVALID_DESTINATION_ADDRESS\",\n `destination address must be a string, received ${typeof value}`,\n );\n }\n if (\n value.trim() !== value ||\n value.length < SOLANA_ADDRESS_MIN_LENGTH ||\n value.length > SOLANA_ADDRESS_MAX_LENGTH\n ) {\n throwInvalidDestinationAddress(value);\n }\n\n const decoded = decodeBase58SolanaAddress(value);\n if (encodeBase58(decoded) !== value) {\n throwInvalidDestinationAddress(value);\n }\n}\n\n/** Encode a 32-byte Ed25519 public key as its canonical Solana address. */\nexport function solanaAddressFromPublicKeyBytes(bytes: Uint8Array): string {\n if (bytes.byteLength !== SOLANA_PUBLIC_KEY_BYTE_LENGTH) {\n throw new PolicyValidationError(\n \"INVALID_DESTINATION_ADDRESS\",\n `Solana public key must be ${SOLANA_PUBLIC_KEY_BYTE_LENGTH} bytes, received ${bytes.byteLength}`,\n );\n }\n return encodeBase58(bytes);\n}\n\nfunction decodeBase58SolanaAddress(value: string): Uint8Array {\n let decoded = 0n;\n for (const character of value) {\n const digit = BASE58_DIGITS.get(character);\n if (digit === undefined) {\n throwInvalidDestinationAddress(value);\n }\n decoded = decoded * BASE58_RADIX + BigInt(digit);\n if (decoded > MAX_SOLANA_PUBLIC_KEY_VALUE) {\n throwInvalidDestinationAddress(value);\n }\n }\n\n const bytes = new Uint8Array(SOLANA_PUBLIC_KEY_BYTE_LENGTH);\n for (let index = SOLANA_PUBLIC_KEY_BYTE_LENGTH - 1; index >= 0; index -= 1) {\n bytes[index] = Number(decoded & BYTE_MASK);\n decoded >>= BYTE_RADIX_BITS;\n }\n return bytes;\n}\n\nfunction encodeBase58(bytes: Uint8Array): string {\n let leadingZeros = 0;\n for (const byte of bytes) {\n if (byte !== 0) break;\n leadingZeros += 1;\n }\n\n let value = 0n;\n for (const byte of bytes) {\n value = (value << BYTE_RADIX_BITS) + BigInt(byte);\n }\n\n let encoded = \"\";\n while (value > 0n) {\n const digit = Number(value % BASE58_RADIX);\n encoded = BASE58_ALPHABET[digit]! + encoded;\n value /= BASE58_RADIX;\n }\n\n return BASE58_LEADING_ZERO_CHAR.repeat(leadingZeros) + encoded;\n}\n\nfunction throwInvalidDestinationAddress(value: string): never {\n throw new PolicyValidationError(\n \"INVALID_DESTINATION_ADDRESS\",\n `destination address must be a canonical 32-byte Solana address: ${value}`,\n );\n}\n","/**\n * Branded scalar types.\n *\n * Branding makes structurally-identical primitives (a lamport amount, a base58\n * address, a correlation id) non-interchangeable at the type level, so the\n * compiler catches \"passed a request id where an address was expected\" before\n * it reaches the wire. The brand exists only at compile time; at runtime these\n * are plain `number` / `string`.\n *\n * Construct branded values through the smart constructors here. These\n * constructors enforce scalar-level invariants; payout-policy semantics stay in\n * the validation module.\n */\n\nimport { PolicyValidationError } from \"./errors.js\";\nimport { assertCanonicalSolanaAddress } from \"./solanaAddress.js\";\n\n/** Attach a compile-time-only brand `B` to base type `T`. */\nexport type Brand<T, B extends string> = T & { readonly __brand: B };\n\n/** A non-negative integer amount of lamports (1 SOL = 1_000_000_000 lamports). */\nexport type Lamports = Brand<number, \"Lamports\">;\n\n/** A Solana account address as base58 text. */\nexport type PublicKey = Brand<string, \"PublicKey\">;\n\n/** A client-generated correlation id for one logical command. */\nexport type RequestId = Brand<string, \"RequestId\">;\n\n/** Lowercase hexadecimal text (no `0x` prefix). */\nexport type Hex = Brand<string, \"Hex\">;\n\n/**\n * Brand a number as {@link Lamports}.\n *\n * @throws PolicyValidationError `INVALID_AMOUNT` if not a non-negative safe integer.\n */\nexport function lamports(value: number): Lamports {\n if (!Number.isSafeInteger(value) || value < 0) {\n throw new PolicyValidationError(\n \"INVALID_AMOUNT\",\n `lamports must be a non-negative safe integer, received ${String(value)}`,\n );\n }\n return value as Lamports;\n}\n\n/**\n * Brand a string as a {@link PublicKey}.\n *\n * Enforces canonical base58 encoding of a 32-byte Solana public key.\n *\n * @throws PolicyValidationError `INVALID_DESTINATION_ADDRESS` if obviously malformed.\n */\nexport function publicKey(value: string): PublicKey {\n assertCanonicalSolanaAddress(value);\n return value as PublicKey;\n}\n\n/**\n * Brand a non-empty string as a {@link RequestId}.\n *\n * @throws PolicyValidationError `INVALID_AMOUNT` is not appropriate here; an empty\n * id is a programming error, so this throws a plain `Error`.\n */\nexport function requestId(value: string): RequestId {\n if (value.length === 0) {\n throw new Error(\"requestId must be a non-empty string\");\n }\n return value as RequestId;\n}\n\n/**\n * Brand a string as lowercase {@link Hex}.\n *\n * @throws Error if the string contains non-hex characters.\n */\nexport function hex(value: string): Hex {\n if (!/^[0-9a-f]*$/.test(value)) {\n throw new Error(`not lowercase hex: ${value}`);\n }\n return value as Hex;\n}\n","/**\n * Session guards used by mutating commands.\n */\n\nimport { AttestationError } from \"../core/errors.js\";\nimport type { Session } from \"../core/session.js\";\n\n/**\n * Assert the session has passed attestation. Every mutating actor command calls\n * this before touching the wire, so an unattested session can never sign or\n * send sensitive material.\n *\n * @throws AttestationError `NOT_ATTESTED` when the session is not attested.\n */\nexport function assertAttested(session: Session): void {\n if (!session.attested) {\n throw new AttestationError(\n \"NOT_ATTESTED\",\n \"session is not attested; sensitive commands are blocked until attestation completes\",\n );\n }\n}\n"]}
@@ -2,8 +2,10 @@
2
2
  var LP_POSITION_ID_MIN_LENGTH = 3;
3
3
  var LP_POSITION_ID_MAX_LENGTH = 96;
4
4
  var LP_POSITION_ID_PATTERN = /^[A-Za-z0-9_-]+$/;
5
- var LP_DEFAULT_TARGET_SHARDS = 200;
6
- var LP_MAX_TARGET_SHARDS = 300;
5
+ var LP_DEFAULT_TARGET_SHARDS = 500;
6
+ var LP_MAX_INITIAL_SHARDS = 500;
7
+ var LP_MAX_TOTAL_SHARDS = 4294967295;
8
+ var LP_SHARD_PAGE_SIZE = 50;
7
9
  var LP_DEFAULT_REFILL_BATCH_SIZE = 50;
8
10
  var LP_MAX_REFILL_BATCH_SIZE = 50;
9
11
  var PRODUCT_MIN_ENTRY_LAMPORTS = 15e8;
@@ -12,6 +14,6 @@ function isValidLpPositionId(lpPositionId) {
12
14
  return lpPositionId.length >= LP_POSITION_ID_MIN_LENGTH && lpPositionId.length <= LP_POSITION_ID_MAX_LENGTH && LP_POSITION_ID_PATTERN.test(lpPositionId);
13
15
  }
14
16
 
15
- export { LP_DEFAULT_REFILL_BATCH_SIZE, LP_DEFAULT_TARGET_SHARDS, LP_MAX_REFILL_BATCH_SIZE, LP_MAX_TARGET_SHARDS, PRODUCT_MAX_ENTRY_LAMPORTS, PRODUCT_MIN_ENTRY_LAMPORTS, isValidLpPositionId };
16
- //# sourceMappingURL=chunk-4X5OCCQW.js.map
17
- //# sourceMappingURL=chunk-4X5OCCQW.js.map
17
+ export { LP_DEFAULT_REFILL_BATCH_SIZE, LP_DEFAULT_TARGET_SHARDS, LP_MAX_INITIAL_SHARDS, LP_MAX_REFILL_BATCH_SIZE, LP_MAX_TOTAL_SHARDS, LP_SHARD_PAGE_SIZE, PRODUCT_MAX_ENTRY_LAMPORTS, PRODUCT_MIN_ENTRY_LAMPORTS, isValidLpPositionId };
18
+ //# sourceMappingURL=chunk-HWRMSK7E.js.map
19
+ //# sourceMappingURL=chunk-HWRMSK7E.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../shared/src/index.ts"],"names":[],"mappings":";AAgBO,IAAM,yBAAA,GAA4B,CAAA;AAClC,IAAM,yBAAA,GAA4B,EAAA;AAClC,IAAM,sBAAA,GAAyB,kBAAA;AAC/B,IAAM,wBAAA,GAA2B;AACjC,IAAM,qBAAA,GAAwB;AAC9B,IAAM,mBAAA,GAAsB;AAC5B,IAAM,kBAAA,GAAqB;AAC3B,IAAM,4BAAA,GAA+B;AACrC,IAAM,wBAAA,GAA2B;AAKjC,IAAM,0BAAA,GAA6B;AACnC,IAAM,0BAAA,GAA6B;AAGnC,SAAS,oBAAoB,YAAA,EAA+B;AACjE,EAAA,OACE,YAAA,CAAa,UAAU,yBAAA,IACvB,YAAA,CAAa,UAAU,yBAAA,IACvB,sBAAA,CAAuB,KAAK,YAAY,CAAA;AAE5C","file":"chunk-HWRMSK7E.js","sourcesContent":["/**\n * Shared workspace entrypoint.\n *\n * Keep exports here pure and reusable across workspaces. Do not put React,\n * DOM-only, libp2p runtime state, or feature-specific glue in this package.\n */\nexport function sleep(ms: number): Promise<void> {\n if (ms <= 0) {\n return Promise.resolve();\n }\n\n return new Promise((resolve) => {\n setTimeout(resolve, ms);\n });\n}\n\nexport const LP_POSITION_ID_MIN_LENGTH = 3;\nexport const LP_POSITION_ID_MAX_LENGTH = 96;\nexport const LP_POSITION_ID_PATTERN = /^[A-Za-z0-9_-]+$/;\nexport const LP_DEFAULT_TARGET_SHARDS = 500;\nexport const LP_MAX_INITIAL_SHARDS = 500;\nexport const LP_MAX_TOTAL_SHARDS = 0xffff_ffff;\nexport const LP_SHARD_PAGE_SIZE = 50;\nexport const LP_DEFAULT_REFILL_BATCH_SIZE = 50;\nexport const LP_MAX_REFILL_BATCH_SIZE = 50;\n\n// Temporary TypeScript mirrors of the Rust TEE entry limits, plus the distinct\n// mainnet UI default. Keep them guarded by `npm run product-limits:check` until\n// cross-language generated product constants exist.\nexport const PRODUCT_MIN_ENTRY_LAMPORTS = 1_500_000_000;\nexport const PRODUCT_MAX_ENTRY_LAMPORTS = 100_000_000_000;\nexport const PRODUCT_DEFAULT_MAINNET_ENTRY_LAMPORTS = 1_500_000_000;\n\nexport function isValidLpPositionId(lpPositionId: string): boolean {\n return (\n lpPositionId.length >= LP_POSITION_ID_MIN_LENGTH &&\n lpPositionId.length <= LP_POSITION_ID_MAX_LENGTH &&\n LP_POSITION_ID_PATTERN.test(lpPositionId)\n );\n}\n"]}
@@ -1,5 +1,5 @@
1
- import { getSessionState } from './chunk-HJFMDMPY.js';
2
- import { TransportError, CommandError } from './chunk-QRN46R3F.js';
1
+ import { getSessionState } from './chunk-6AKBRYKO.js';
2
+ import { TransportError, CommandError, COORDINATOR_CAPACITY_FULL_ERROR_CODE, COORDINATOR_CAPACITY_FULL_USER_MESSAGE } from './chunk-RWKG7N7I.js';
3
3
 
4
4
  // src/coordinator/protocolClient.ts
5
5
  var MAX_COORDINATOR_REQUEST_ID = 4294967295;
@@ -32,7 +32,7 @@ var CoordinatorMessageType = {
32
32
  };
33
33
  var protocolPromise = null;
34
34
  function loadProtocol() {
35
- protocolPromise ??= import('./coordinator-PEWHNZ7I.js');
35
+ protocolPromise ??= import('./coordinator-DHL3AP7V.js');
36
36
  return protocolPromise;
37
37
  }
38
38
  var runtimes = /* @__PURE__ */ new WeakMap();
@@ -270,8 +270,10 @@ function rejectMatchingOutOfBandErrors(runtime, swapId, error) {
270
270
  }
271
271
  function commandErrorFromCoordinatorError(payload) {
272
272
  const coordinatorCode = toCoordinatorWireErrorCode(payload.code);
273
- return new CommandError(commandCodeFromCoordinatorCode(coordinatorCode), payload.message, {
273
+ const message = coordinatorCode === COORDINATOR_CAPACITY_FULL_ERROR_CODE ? COORDINATOR_CAPACITY_FULL_USER_MESSAGE : payload.message;
274
+ return new CommandError(commandCodeFromCoordinatorCode(coordinatorCode), message, {
274
275
  coordinatorCode,
276
+ coordinatorMessage: payload.message,
275
277
  ...payload.failed_req_id !== void 0 ? { failedReqId: payload.failed_req_id } : {}
276
278
  });
277
279
  }
@@ -281,6 +283,11 @@ function commandCodeFromCoordinatorCode(code) {
281
283
  case "ERR_UNKNOWN_SWAP":
282
284
  case "ERR_SWAP_NOT_REFUNDABLE":
283
285
  return "REJECTED_STATE";
286
+ case "ERR_INITIALIZATION_BUSY":
287
+ case "ERR_PRESEAL_ADMISSION_BUSY":
288
+ return "RETRYABLE_BUSY";
289
+ case COORDINATOR_CAPACITY_FULL_ERROR_CODE:
290
+ return "REJECTED_RESOURCE_CAP";
284
291
  case "ERR_INTERNAL":
285
292
  case "ERR_SETTLEMENT_FAILED":
286
293
  return "REJECTED_STALE_JOB";
@@ -302,6 +309,9 @@ function toCoordinatorWireErrorCode(code) {
302
309
  case "ERR_SWAP_NOT_REFUNDABLE":
303
310
  case "ERR_DKG_FAILURE":
304
311
  case "ERR_INTERNAL":
312
+ case "ERR_INITIALIZATION_BUSY":
313
+ case "ERR_PRESEAL_ADMISSION_BUSY":
314
+ case COORDINATOR_CAPACITY_FULL_ERROR_CODE:
305
315
  case "ERR_INVALID_DEPOSIT":
306
316
  case "ERR_SETTLEMENT_FAILED":
307
317
  return code;
@@ -325,5 +335,5 @@ function rejectAll(runtime, error) {
325
335
  }
326
336
 
327
337
  export { CoordinatorMessageType, EnvelopeKind, closeProtocolRuntime, onEnvelope, requestEnvelope };
328
- //# sourceMappingURL=chunk-3MDHAS4D.js.map
329
- //# sourceMappingURL=chunk-3MDHAS4D.js.map
338
+ //# sourceMappingURL=chunk-ISIWWGSR.js.map
339
+ //# sourceMappingURL=chunk-ISIWWGSR.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/coordinator/protocolClient.ts"],"names":["pending"],"mappings":";;;;AAaA,IAAM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ACT;AACE,MAAA,OAAO,cAAA;AAAA;AAEb;AAcA,SAAS,SAAA,CAAU,SAA0B,KAAA,EAAoB;AAC/D,EAAA,KAAA,MAAW,CAAC,KAAA,EAAO,OAAO,KAAK,OAAA,CAAQ,OAAA,CAAQ,SAAQ,EAAG;AACxD,IAAA,OAAA,CAAQ,OAAA,CAAQ,OAAO,KAAK,CAAA;AAC5B,IAAA,qBAAA,CAAsB,OAAO,CAAA;AAC7B,IAAA,OAAA,CAAQ,OAAO,KAAK,CAAA;AAAA,EACtB;AACA,EAAA,KAAA,MAAW,CAAC,IAAA,EAAM,OAAO,KAAK,OAAA,CAAQ,WAAA,CAAY,SAAQ,EAAG;AAC3D,IAAA,OAAA,CAAQ,WAAA,CAAY,OAAO,IAAI,CAAA;AAC/B,IAAA,KAAA,MAAW,UAAU,OAAA,EAAS;AAC5B,MAAA,IAAI,MAAA,CAAO,KAAA,EAAO,YAAA,CAAa,MAAA,CAAO,KAAK,CAAA;AAC3C,MAAA,MAAA,CAAO,OAAO,KAAK,CAAA;AAAA,IACrB;AAAA,EACF;AACF","file":"chunk-ISIWWGSR.js","sourcesContent":["import {\n COORDINATOR_CAPACITY_FULL_ERROR_CODE,\n COORDINATOR_CAPACITY_FULL_USER_MESSAGE,\n CommandError,\n TransportError,\n type CommandErrorCode,\n type CoordinatorWireErrorCode,\n} from \"../core/errors.js\";\nimport type { Session } from \"../core/session.js\";\nimport { getSessionState, type SessionState } from \"../session/state.js\";\nimport type { Unsubscribe } from \"../transport/types.js\";\n\nconst COORDINATOR_ENVELOPE_VERSION = 2;\nconst MAX_COORDINATOR_REQUEST_ID = 0xffff_ffff;\nconst OUT_OF_BAND_REQUEST_ID = 0;\n\nexport const EnvelopeKind = {\n REQUEST: \"request\",\n RESPONSE: \"response\",\n PUSH: \"push\",\n ERROR: \"error\",\n} as const;\n\nexport type EnvelopeKind = (typeof EnvelopeKind)[keyof typeof EnvelopeKind];\n\nexport const CoordinatorMessageType = {\n ContractRequest: \"ContractRequest\",\n LpCreateAuthorization: \"LpCreateAuthorization\",\n DkgInit: \"DkgInit\",\n DkgRound1: \"DkgRound1\",\n DkgRound2: \"DkgRound2\",\n DkgComplete: \"DkgComplete\",\n DelegateShare: \"DelegateShare\",\n DelegateAck: \"DelegateAck\",\n DepositConfirmed: \"DepositConfirmed\",\n Sync: \"Sync\",\n SyncRequired: \"SyncRequired\",\n Refill: \"Refill\",\n PayoutExecuted: \"PayoutExecuted\",\n WithdrawRequest: \"WithdrawRequest\",\n WithdrawAccepted: \"WithdrawAccepted\",\n WithdrawExecuted: \"WithdrawExecuted\",\n LpCommand: \"LpCommand\",\n Error: \"Error\",\n} as const;\n\nexport type CoordinatorMessageType =\n (typeof CoordinatorMessageType)[keyof typeof CoordinatorMessageType];\n\nexport type Envelope = {\n readonly version: typeof COORDINATOR_ENVELOPE_VERSION;\n readonly kind: EnvelopeKind;\n readonly type: CoordinatorMessageType;\n readonly swap_id: string | null;\n readonly req_id: number;\n readonly timestamp_ms: number;\n readonly payload: unknown;\n};\n\ntype ProtocolModule = {\n readonly ENVELOPE_VERSION: typeof COORDINATOR_ENVELOPE_VERSION;\n readonly EnvelopeKind: typeof EnvelopeKind;\n readonly CoordinatorMessageType: typeof CoordinatorMessageType;\n readonly encodeValidated: (envelope: Envelope) => Uint8Array;\n readonly decode: (raw: Uint8Array) => { ok: true; value: Envelope } | { ok: false; error: Error };\n readonly asErrorPayload: (envelope: Envelope) => {\n readonly code: string;\n readonly failed_req_id?: number;\n readonly message: string;\n };\n};\n\nlet protocolPromise: Promise<ProtocolModule> | null = null;\n\nfunction loadProtocol(): Promise<ProtocolModule> {\n protocolPromise ??= import(\"protocol/coordinator\") as Promise<ProtocolModule>;\n return protocolPromise;\n}\n\nexport type ProtocolLogDirection = \"in\" | \"out\" | \"info\";\nexport type ProtocolLogHandler = (message: string, direction: ProtocolLogDirection) => void;\nexport type ProtocolEnvelopeHandler = (envelope: Envelope) => void;\n\nexport interface RequestEnvelopeOptions {\n readonly swapId?: string | null;\n readonly timeoutMs?: number;\n readonly signal?: AbortSignal;\n readonly onLog?: ProtocolLogHandler;\n /** Reject this request when the coordinator reports a swap-scoped error without a request id. */\n readonly rejectMatchingOutOfBandErrors?: boolean;\n /** Contract allocation responses must carry the server-assigned swap_id. */\n readonly requireNonNullResponseSwapId?: boolean;\n}\n\nexport interface AwaitPushOptions {\n /** Exact business routing key. Omit only for legacy wildcard waiters. */\n readonly swapId?: string | null;\n readonly timeoutMs?: number | null;\n}\n\ntype PendingRequest = {\n readonly expectedSwapId: string | null;\n readonly resolve: (envelope: Envelope) => void;\n readonly reject: (error: Error) => void;\n readonly timer: ReturnType<typeof setTimeout> | null;\n readonly signal?: AbortSignal;\n readonly abortHandler?: () => void;\n readonly swapId: string | null;\n readonly rejectMatchingOutOfBandErrors: boolean;\n readonly requireNonNullResponseSwapId: boolean;\n};\n\ntype PushWaiter = {\n readonly swapId?: string | null;\n readonly resolve: (envelope: Envelope) => void;\n readonly reject: (error: Error) => void;\n readonly timer: ReturnType<typeof setTimeout> | null;\n};\n\ntype ProtocolRuntime = {\n reqCounter: number;\n readonly pending: Map<number, PendingRequest>;\n readonly pushWaiters: Map<CoordinatorMessageType, PushWaiter[]>;\n readonly envelopeHandlers: Set<ProtocolEnvelopeHandler>;\n unsubscribeChannel: Unsubscribe | null;\n unsubscribeTransport: Unsubscribe | null;\n};\n\nconst runtimes = new WeakMap<SessionState, ProtocolRuntime>();\n\nexport async function requestEnvelope(\n session: Session,\n type: CoordinatorMessageType,\n payload: unknown,\n options: RequestEnvelopeOptions = {},\n): Promise<Envelope> {\n throwIfRequestAborted(options.signal);\n const protocol = await loadProtocol();\n throwIfRequestAborted(options.signal);\n const state = getSessionState(session);\n const runtime = ensureProtocolRuntime(state);\n const channel = state.channel;\n if (!state.attested || channel === null) {\n throw new TransportError(\"CONNECTION_LOST\", \"coordinator request requires an attested channel\");\n }\n\n if (runtime.reqCounter >= MAX_COORDINATOR_REQUEST_ID) {\n throw new CommandError(\"REJECTED_STATE\", \"coordinator request id space exhausted\");\n }\n const reqId = runtime.reqCounter + 1;\n runtime.reqCounter = reqId;\n const envelope: Envelope = {\n version: protocol.ENVELOPE_VERSION,\n kind: protocol.EnvelopeKind.REQUEST,\n type,\n swap_id: options.swapId ?? null,\n req_id: reqId,\n timestamp_ms: Date.now(),\n payload,\n };\n const frame = protocol.encodeValidated(envelope);\n\n return new Promise((resolve, reject) => {\n const abortHandler =\n options.signal === undefined\n ? undefined\n : () => rejectPending(runtime, reqId, createRequestAbortError());\n const timer =\n options.timeoutMs === undefined\n ? null\n : setTimeout(() => {\n rejectPending(\n runtime,\n reqId,\n new CommandError(\n \"REJECTED_STALE_JOB\",\n `coordinator request timed out for ${type} after ${options.timeoutMs}ms`,\n ),\n );\n }, options.timeoutMs);\n\n runtime.pending.set(reqId, {\n expectedSwapId: options.swapId ?? null,\n resolve,\n reject,\n timer,\n signal: options.signal,\n abortHandler,\n swapId: envelope.swap_id,\n rejectMatchingOutOfBandErrors: options.rejectMatchingOutOfBandErrors === true,\n requireNonNullResponseSwapId: options.requireNonNullResponseSwapId === true,\n });\n if (abortHandler !== undefined) {\n options.signal?.addEventListener(\"abort\", abortHandler, { once: true });\n if (options.signal?.aborted === true) {\n abortHandler();\n return;\n }\n }\n options.onLog?.(`-> ${type} req_id=${reqId}`, \"out\");\n try {\n channel.send(frame);\n } catch (error) {\n rejectPending(runtime, reqId, error instanceof Error ? error : new Error(String(error)));\n }\n });\n}\n\nexport function awaitPush(\n session: Session,\n type: CoordinatorMessageType,\n options: AwaitPushOptions = {},\n): Promise<Envelope> {\n const state = getSessionState(session);\n const runtime = ensureProtocolRuntime(state);\n const timeoutMs = options.timeoutMs === undefined ? 30_000 : options.timeoutMs;\n\n return new Promise((resolve, reject) => {\n const timer =\n timeoutMs === null\n ? null\n : setTimeout(() => {\n removePushWaiter(runtime, type, waiter);\n reject(new CommandError(\"REJECTED_STALE_JOB\", `timed out waiting for ${type} push`));\n }, timeoutMs);\n const waiter: PushWaiter = { swapId: options.swapId, resolve, reject, timer };\n const waiters = runtime.pushWaiters.get(type) ?? [];\n waiters.push(waiter);\n runtime.pushWaiters.set(type, waiters);\n });\n}\n\nexport function onEnvelope(session: Session, handler: ProtocolEnvelopeHandler): Unsubscribe {\n const runtime = ensureProtocolRuntime(getSessionState(session));\n runtime.envelopeHandlers.add(handler);\n return () => runtime.envelopeHandlers.delete(handler);\n}\n\nexport function closeProtocolRuntime(session: Session): void {\n const state = getSessionState(session);\n const runtime = runtimes.get(state);\n if (!runtime) return;\n const error = new TransportError(\"CONNECTION_LOST\", \"coordinator protocol runtime closed\");\n rejectAll(runtime, error);\n runtime.unsubscribeChannel?.();\n runtime.unsubscribeTransport?.();\n runtimes.delete(state);\n}\n\nfunction ensureProtocolRuntime(state: SessionState): ProtocolRuntime {\n const existing = runtimes.get(state);\n if (existing) return existing;\n\n const runtime: ProtocolRuntime = {\n reqCounter: 0,\n pending: new Map(),\n pushWaiters: new Map(),\n envelopeHandlers: new Set(),\n unsubscribeChannel: null,\n unsubscribeTransport: null,\n };\n\n if (state.channel === null) {\n throw new TransportError(\"CONNECTION_LOST\", \"coordinator protocol requires a live channel\");\n }\n runtime.unsubscribeChannel = state.channel.onMessage((frame) => handleFrame(runtime, frame));\n runtime.unsubscribeTransport = state.transport.onStateChange((transportState) => {\n if (transportState === \"closing\" || transportState === \"closed\") {\n rejectAll(runtime, new TransportError(\"CONNECTION_LOST\", \"coordinator transport closed\"));\n }\n });\n\n runtimes.set(state, runtime);\n return runtime;\n}\n\nfunction handleFrame(runtime: ProtocolRuntime, frame: Uint8Array): void {\n void handleFrameAsync(runtime, frame);\n}\n\nasync function handleFrameAsync(runtime: ProtocolRuntime, frame: Uint8Array): Promise<void> {\n const protocol = await loadProtocol();\n const decoded = protocol.decode(frame);\n if (!decoded.ok) {\n rejectAll(runtime, decoded.error);\n return;\n }\n\n const envelope = decoded.value;\n if (envelope.kind === protocol.EnvelopeKind.RESPONSE) {\n const pending = runtime.pending.get(envelope.req_id);\n if (pending && !pendingRequestMatchesSwapId(pending, envelope.swap_id)) {\n rejectPending(\n runtime,\n envelope.req_id,\n requestSwapIdMismatchError(envelope.req_id, pending.expectedSwapId, envelope.swap_id),\n );\n return;\n }\n }\n\n const errorPayload =\n envelope.kind === protocol.EnvelopeKind.ERROR ? protocol.asErrorPayload(envelope) : null;\n if (errorPayload?.failed_req_id !== undefined) {\n const pending = runtime.pending.get(errorPayload.failed_req_id);\n if (pending && !pendingRequestMatchesSwapId(pending, envelope.swap_id, false)) {\n rejectPending(\n runtime,\n errorPayload.failed_req_id,\n requestSwapIdMismatchError(\n errorPayload.failed_req_id,\n pending.expectedSwapId,\n envelope.swap_id,\n ),\n );\n return;\n }\n }\n\n for (const handler of runtime.envelopeHandlers) handler(envelope);\n\n if (envelope.kind === protocol.EnvelopeKind.ERROR) {\n const payload = errorPayload!;\n const error = commandErrorFromCoordinatorError(payload);\n if (payload.failed_req_id === undefined || payload.failed_req_id === OUT_OF_BAND_REQUEST_ID) {\n if (envelope.swap_id !== null) {\n rejectMatchingOutOfBandErrors(runtime, envelope.swap_id, error);\n }\n return;\n }\n const pending = runtime.pending.get(payload.failed_req_id);\n if (!pending) return;\n if (!pendingRequestMatchesSwapId(pending, envelope.swap_id, false)) {\n rejectPending(\n runtime,\n payload.failed_req_id,\n requestSwapIdMismatchError(payload.failed_req_id, pending.expectedSwapId, envelope.swap_id),\n );\n return;\n }\n rejectPending(runtime, payload.failed_req_id, error);\n return;\n }\n\n if (envelope.kind === protocol.EnvelopeKind.PUSH) {\n resolvePushWaiter(runtime, envelope);\n return;\n }\n\n if (envelope.kind !== protocol.EnvelopeKind.RESPONSE) return;\n const pending = runtime.pending.get(envelope.req_id);\n if (!pending) return;\n if (!pendingRequestMatchesSwapId(pending, envelope.swap_id)) {\n rejectPending(\n runtime,\n envelope.req_id,\n requestSwapIdMismatchError(envelope.req_id, pending.expectedSwapId, envelope.swap_id),\n );\n return;\n }\n runtime.pending.delete(envelope.req_id);\n cleanupPendingRequest(pending);\n pending.resolve(envelope);\n}\n\nfunction pendingRequestMatchesSwapId(\n pending: PendingRequest,\n responseSwapId: string | null,\n enforceNonNullResponseSwapId = true,\n): boolean {\n if (\n enforceNonNullResponseSwapId &&\n pending.requireNonNullResponseSwapId &&\n responseSwapId === null\n ) {\n return false;\n }\n return pending.expectedSwapId === null || pending.expectedSwapId === responseSwapId;\n}\n\nfunction requestSwapIdMismatchError(\n reqId: number,\n expectedSwapId: string | null,\n receivedSwapId: string | null,\n): CommandError {\n return new CommandError(\n \"REJECTED_STATE\",\n `coordinator response swap_id mismatch for req_id=${reqId}: expected ${expectedSwapId ?? \"null\"}, received ${receivedSwapId ?? \"null\"}`,\n { failedReqId: reqId },\n );\n}\n\nfunction resolvePushWaiter(runtime: ProtocolRuntime, envelope: Envelope): void {\n const waiters = runtime.pushWaiters.get(envelope.type);\n const waiterIndex = waiters?.findIndex(\n (candidate) => candidate.swapId === undefined || candidate.swapId === envelope.swap_id,\n );\n const waiter =\n waiters && waiterIndex !== undefined && waiterIndex >= 0\n ? waiters.splice(waiterIndex, 1)[0]\n : undefined;\n if (!waiter || !waiters) return;\n if (waiters.length === 0) {\n runtime.pushWaiters.delete(envelope.type);\n }\n if (waiter.timer) clearTimeout(waiter.timer);\n waiter.resolve(envelope);\n}\n\nfunction rejectPending(runtime: ProtocolRuntime, reqId: number, error: Error): void {\n const pending = runtime.pending.get(reqId);\n if (!pending) return;\n runtime.pending.delete(reqId);\n cleanupPendingRequest(pending);\n pending.reject(error);\n}\n\nfunction cleanupPendingRequest(pending: PendingRequest): void {\n if (pending.timer) clearTimeout(pending.timer);\n if (pending.signal !== undefined && pending.abortHandler !== undefined) {\n pending.signal.removeEventListener(\"abort\", pending.abortHandler);\n }\n}\n\nfunction throwIfRequestAborted(signal: AbortSignal | undefined): void {\n if (signal?.aborted === true) throw createRequestAbortError();\n}\n\nfunction createRequestAbortError(): DOMException {\n return new DOMException(\"coordinator request aborted\", \"AbortError\");\n}\n\nfunction rejectMatchingOutOfBandErrors(\n runtime: ProtocolRuntime,\n swapId: string,\n error: Error,\n): void {\n for (const [reqId, pending] of runtime.pending) {\n if (!pending.rejectMatchingOutOfBandErrors || pending.swapId !== swapId) continue;\n rejectPending(runtime, reqId, error);\n }\n}\n\nfunction commandErrorFromCoordinatorError(payload: {\n readonly code: string;\n readonly failed_req_id?: number;\n readonly message: string;\n}): CommandError {\n const coordinatorCode = toCoordinatorWireErrorCode(payload.code);\n const message =\n coordinatorCode === COORDINATOR_CAPACITY_FULL_ERROR_CODE\n ? COORDINATOR_CAPACITY_FULL_USER_MESSAGE\n : payload.message;\n return new CommandError(commandCodeFromCoordinatorCode(coordinatorCode), message, {\n coordinatorCode,\n coordinatorMessage: payload.message,\n ...(payload.failed_req_id !== undefined ? { failedReqId: payload.failed_req_id } : {}),\n });\n}\n\nfunction commandCodeFromCoordinatorCode(code: CoordinatorWireErrorCode): CommandErrorCode {\n switch (code) {\n case \"ERR_UNEXPECTED_TYPE\":\n case \"ERR_UNKNOWN_SWAP\":\n case \"ERR_SWAP_NOT_REFUNDABLE\":\n return \"REJECTED_STATE\";\n case \"ERR_INITIALIZATION_BUSY\":\n case \"ERR_PRESEAL_ADMISSION_BUSY\":\n return \"RETRYABLE_BUSY\";\n case COORDINATOR_CAPACITY_FULL_ERROR_CODE:\n return \"REJECTED_RESOURCE_CAP\";\n case \"ERR_INTERNAL\":\n case \"ERR_SETTLEMENT_FAILED\":\n return \"REJECTED_STALE_JOB\";\n case \"ERR_INVALID_PAYLOAD\":\n case \"ERR_POLICY_VIOLATION\":\n case \"ERR_INVALID_RECOVERY_CODE\":\n case \"ERR_DKG_FAILURE\":\n case \"ERR_INVALID_DEPOSIT\":\n return \"REJECTED_GUARD\";\n }\n}\n\nfunction toCoordinatorWireErrorCode(code: string): CoordinatorWireErrorCode {\n switch (code) {\n case \"ERR_INVALID_PAYLOAD\":\n case \"ERR_UNEXPECTED_TYPE\":\n case \"ERR_UNKNOWN_SWAP\":\n case \"ERR_POLICY_VIOLATION\":\n case \"ERR_INVALID_RECOVERY_CODE\":\n case \"ERR_SWAP_NOT_REFUNDABLE\":\n case \"ERR_DKG_FAILURE\":\n case \"ERR_INTERNAL\":\n case \"ERR_INITIALIZATION_BUSY\":\n case \"ERR_PRESEAL_ADMISSION_BUSY\":\n case COORDINATOR_CAPACITY_FULL_ERROR_CODE:\n case \"ERR_INVALID_DEPOSIT\":\n case \"ERR_SETTLEMENT_FAILED\":\n return code;\n default:\n return \"ERR_INTERNAL\";\n }\n}\n\nfunction removePushWaiter(\n runtime: ProtocolRuntime,\n type: CoordinatorMessageType,\n waiter: PushWaiter,\n): void {\n const waiters = runtime.pushWaiters.get(type);\n if (!waiters) return;\n const index = waiters.indexOf(waiter);\n if (index >= 0) waiters.splice(index, 1);\n if (waiters.length === 0) runtime.pushWaiters.delete(type);\n}\n\nfunction rejectAll(runtime: ProtocolRuntime, error: Error): void {\n for (const [reqId, pending] of runtime.pending.entries()) {\n runtime.pending.delete(reqId);\n cleanupPendingRequest(pending);\n pending.reject(error);\n }\n for (const [type, waiters] of runtime.pushWaiters.entries()) {\n runtime.pushWaiters.delete(type);\n for (const waiter of waiters) {\n if (waiter.timer) clearTimeout(waiter.timer);\n waiter.reject(error);\n }\n }\n}\n"]}
@@ -18,6 +18,12 @@ var ErrorCode = {
18
18
  ERR_DKG_FAILURE: "ERR_DKG_FAILURE",
19
19
  /** Catch-all for unexpected coordinator-side failures. */
20
20
  ERR_INTERNAL: "ERR_INTERNAL",
21
+ /** Admission lock acquisition timed out before any sealed write; the SDK may retry. */
22
+ ERR_PRESEAL_ADMISSION_BUSY: "ERR_PRESEAL_ADMISSION_BUSY",
23
+ /** A known initialization boundary did not commit; resume the same authenticated command. */
24
+ ERR_INITIALIZATION_BUSY: "ERR_INITIALIZATION_BUSY",
25
+ /** Global transfer capacity is full; reject without retrying or writing sealed state. */
26
+ ERR_ADMISSION_CAPACITY_FULL: "ERR_ADMISSION_CAPACITY_FULL",
21
27
  /** Deposit did not satisfy coordinator validation or funding policy. */
22
28
  ERR_INVALID_DEPOSIT: "ERR_INVALID_DEPOSIT",
23
29
  /** Autonomous payout/refund signing failed after the swap was accepted. */
@@ -423,6 +429,7 @@ var coordinator_envelope_schema_default = {
423
429
  $schema: "https://json-schema.org/draft/2020-12/schema",
424
430
  $id: "https://invisible.local/schemas/coordinator-envelope.v2.schema.json",
425
431
  title: "Invisible Coordinator Envelope v2",
432
+ maxEncodedJsonBytes: 524288,
426
433
  type: "object",
427
434
  additionalProperties: false,
428
435
  required: ["version", "kind", "type", "swap_id", "req_id", "timestamp_ms", "payload"],
@@ -952,12 +959,12 @@ var coordinator_envelope_schema_default = {
952
959
  lpShardIndex: {
953
960
  type: "integer",
954
961
  minimum: 0,
955
- maximum: 299
962
+ maximum: 4294967294
956
963
  },
957
964
  lpShardCount: {
958
965
  type: "integer",
959
966
  minimum: 0,
960
- maximum: 300
967
+ maximum: 500
961
968
  },
962
969
  positiveU32: {
963
970
  type: "integer",
@@ -1265,7 +1272,7 @@ var coordinator_envelope_schema_default = {
1265
1272
  lpCreationRefillThreshold: {
1266
1273
  type: "integer",
1267
1274
  minimum: 0,
1268
- maximum: 300
1275
+ maximum: 500
1269
1276
  },
1270
1277
  payoutSpec: {
1271
1278
  oneOf: [
@@ -1369,6 +1376,10 @@ var coordinator_envelope_schema_default = {
1369
1376
  }
1370
1377
  ],
1371
1378
  properties: {
1379
+ economics: {
1380
+ description: "Sealed fee ownership and retry semantics. Missing predecessor snapshots are legacy.",
1381
+ enum: ["legacy", "zero_protocol_fees"]
1382
+ },
1372
1383
  asset: {
1373
1384
  const: "SOL"
1374
1385
  },
@@ -1746,6 +1757,9 @@ var coordinator_envelope_schema_default = {
1746
1757
  contract_id: {
1747
1758
  $ref: "#/$defs/string"
1748
1759
  },
1760
+ deposit_origin_address: {
1761
+ anyOf: [{ type: "null" }, { $ref: "#/$defs/string" }]
1762
+ },
1749
1763
  status: {
1750
1764
  $ref: "#/$defs/normalUserContractStatus"
1751
1765
  },
@@ -2141,6 +2155,9 @@ var coordinator_envelope_schema_default = {
2141
2155
  "ERR_SWAP_NOT_REFUNDABLE",
2142
2156
  "ERR_DKG_FAILURE",
2143
2157
  "ERR_INTERNAL",
2158
+ "ERR_PRESEAL_ADMISSION_BUSY",
2159
+ "ERR_INITIALIZATION_BUSY",
2160
+ "ERR_ADMISSION_CAPACITY_FULL",
2144
2161
  "ERR_INVALID_DEPOSIT",
2145
2162
  "ERR_SETTLEMENT_FAILED"
2146
2163
  ]
@@ -2671,6 +2688,8 @@ var coordinator_envelope_schema_default = {
2671
2688
  type: "object",
2672
2689
  additionalProperties: false,
2673
2690
  properties: {
2691
+ shard_start_index: { $ref: "#/$defs/lpShardIndex" },
2692
+ shards_snapshot_hash: { $ref: "#/$defs/lpShardSnapshotHash" },
2674
2693
  redemption_history_cursor: {
2675
2694
  $ref: "#/$defs/lpRedemptionId"
2676
2695
  }
@@ -2710,7 +2729,7 @@ var coordinator_envelope_schema_default = {
2710
2729
  shard_count: {
2711
2730
  type: "integer",
2712
2731
  minimum: 1,
2713
- maximum: 300
2732
+ maximum: 500
2714
2733
  },
2715
2734
  shard_amount_lamports: {
2716
2735
  $ref: "#/$defs/positiveSafeUInt"
@@ -2718,11 +2737,11 @@ var coordinator_envelope_schema_default = {
2718
2737
  refill_threshold: {
2719
2738
  type: "integer",
2720
2739
  minimum: 0,
2721
- maximum: 300
2740
+ maximum: 500
2722
2741
  },
2723
2742
  addresses: {
2724
2743
  type: "array",
2725
- maxItems: 300,
2744
+ maxItems: 500,
2726
2745
  items: {
2727
2746
  $ref: "#/$defs/lpAddress"
2728
2747
  }
@@ -2786,7 +2805,7 @@ var coordinator_envelope_schema_default = {
2786
2805
  addresses: {
2787
2806
  type: "array",
2788
2807
  minItems: 1,
2789
- maxItems: 300,
2808
+ maxItems: 500,
2790
2809
  items: {
2791
2810
  $ref: "#/$defs/lpAddress"
2792
2811
  }
@@ -2950,7 +2969,7 @@ var coordinator_envelope_schema_default = {
2950
2969
  },
2951
2970
  value: {
2952
2971
  type: "array",
2953
- maxItems: 300,
2972
+ maxItems: 500,
2954
2973
  items: {
2955
2974
  $ref: "#/$defs/lpShardView"
2956
2975
  }
@@ -3078,6 +3097,20 @@ var coordinator_envelope_schema_default = {
3078
3097
  lpPositionView: {
3079
3098
  type: "object",
3080
3099
  additionalProperties: false,
3100
+ dependentRequired: {
3101
+ shards_total_count: ["shards_snapshot_hash"],
3102
+ shards_snapshot_hash: ["shards_total_count"],
3103
+ shards_next_index: ["shards_total_count", "shards_snapshot_hash"]
3104
+ },
3105
+ allOf: [
3106
+ {
3107
+ if: {
3108
+ properties: { shards_snapshot_hash: {} },
3109
+ required: ["shards_snapshot_hash"]
3110
+ },
3111
+ then: { properties: { shards: { type: "array", maxItems: 50 } } }
3112
+ }
3113
+ ],
3081
3114
  required: [
3082
3115
  "lp_position_id",
3083
3116
  "status",
@@ -3101,7 +3134,7 @@ var coordinator_envelope_schema_default = {
3101
3134
  target_shard_count: {
3102
3135
  type: "integer",
3103
3136
  minimum: 0,
3104
- maximum: 300
3137
+ maximum: 4294967295
3105
3138
  },
3106
3139
  auth_public_key: {
3107
3140
  $ref: "#/$defs/base64url32Bytes"
@@ -3121,15 +3154,18 @@ var coordinator_envelope_schema_default = {
3121
3154
  refill_threshold: {
3122
3155
  type: "integer",
3123
3156
  minimum: 0,
3124
- maximum: 300
3157
+ maximum: 500
3125
3158
  },
3126
3159
  shards: {
3127
3160
  type: "array",
3128
- maxItems: 300,
3161
+ maxItems: 500,
3129
3162
  items: {
3130
3163
  $ref: "#/$defs/lpShardView"
3131
3164
  }
3132
3165
  },
3166
+ shards_total_count: { $ref: "#/$defs/u32" },
3167
+ shards_next_index: { $ref: "#/$defs/lpShardIndex" },
3168
+ shards_snapshot_hash: { $ref: "#/$defs/lpShardSnapshotHash" },
3133
3169
  created_at_ms: {
3134
3170
  $ref: "#/$defs/positiveSafeUInt"
3135
3171
  },
@@ -3213,6 +3249,9 @@ var coordinator_envelope_schema_default = {
3213
3249
  ]
3214
3250
  },
3215
3251
  properties: {
3252
+ economic_return: {
3253
+ $ref: "#/$defs/lpEconomicReturnSummary"
3254
+ },
3216
3255
  lp_position_id: {
3217
3256
  $ref: "#/$defs/lpId"
3218
3257
  },
@@ -3278,9 +3317,9 @@ var coordinator_envelope_schema_default = {
3278
3317
  },
3279
3318
  withdrawal_tx_hashes: {
3280
3319
  type: "array",
3281
- maxItems: 300,
3320
+ maxItems: 500,
3282
3321
  items: {
3283
- $ref: "#/$defs/lpTxSignature"
3322
+ $ref: "#/$defs/lpViewTxSignature"
3284
3323
  }
3285
3324
  },
3286
3325
  redemption_history: {
@@ -3288,7 +3327,8 @@ var coordinator_envelope_schema_default = {
3288
3327
  maxItems: 32,
3289
3328
  items: {
3290
3329
  $ref: "#/$defs/lpRedemptionHistory"
3291
- }
3330
+ },
3331
+ maxEncodedJsonBytes: 32768
3292
3332
  },
3293
3333
  redemption_history_has_more: {
3294
3334
  type: "boolean"
@@ -3382,7 +3422,7 @@ var coordinator_envelope_schema_default = {
3382
3422
  minItems: 1,
3383
3423
  maxItems: 1e3,
3384
3424
  items: {
3385
- $ref: "#/$defs/lpAddress"
3425
+ $ref: "#/$defs/lpViewAddress"
3386
3426
  }
3387
3427
  },
3388
3428
  destination_count: {
@@ -3392,7 +3432,7 @@ var coordinator_envelope_schema_default = {
3392
3432
  type: "array",
3393
3433
  maxItems: 32,
3394
3434
  items: {
3395
- $ref: "#/$defs/lpTxSignature"
3435
+ $ref: "#/$defs/lpViewTxSignature"
3396
3436
  }
3397
3437
  },
3398
3438
  tx_signature_count: {
@@ -3421,13 +3461,13 @@ var coordinator_envelope_schema_default = {
3421
3461
  $ref: "#/$defs/lpId"
3422
3462
  },
3423
3463
  shard_id: {
3424
- $ref: "#/$defs/lpShardId"
3464
+ $ref: "#/$defs/lpViewShardId"
3425
3465
  },
3426
3466
  index: {
3427
3467
  $ref: "#/$defs/lpShardIndex"
3428
3468
  },
3429
3469
  address: {
3430
- $ref: "#/$defs/lpAddress"
3470
+ $ref: "#/$defs/lpViewAddress"
3431
3471
  },
3432
3472
  amount_lamports: {
3433
3473
  $ref: "#/$defs/safeUInt"
@@ -3454,7 +3494,7 @@ var coordinator_envelope_schema_default = {
3454
3494
  $ref: "#/$defs/positiveSafeUInt"
3455
3495
  },
3456
3496
  payout_tx_signature: {
3457
- $ref: "#/$defs/lpTxSignature"
3497
+ $ref: "#/$defs/lpViewTxSignature"
3458
3498
  }
3459
3499
  }
3460
3500
  },
@@ -3528,7 +3568,7 @@ var coordinator_envelope_schema_default = {
3528
3568
  },
3529
3569
  tx_signatures: {
3530
3570
  type: "array",
3531
- maxItems: 300,
3571
+ maxItems: 500,
3532
3572
  items: {
3533
3573
  $ref: "#/$defs/lpTxSignature"
3534
3574
  }
@@ -3543,25 +3583,98 @@ var coordinator_envelope_schema_default = {
3543
3583
  $ref: "#/$defs/safeUInt"
3544
3584
  }
3545
3585
  }
3586
+ },
3587
+ lpShardSnapshotHash: {
3588
+ type: "string",
3589
+ minLength: 64,
3590
+ maxLength: 64,
3591
+ pattern: "^[0-9a-f]{64}$"
3592
+ },
3593
+ lpViewShardId: {
3594
+ type: "string",
3595
+ minLength: 1,
3596
+ maxLength: 113,
3597
+ pattern: "^[A-Za-z0-9_:-]+$"
3598
+ },
3599
+ lpViewAddress: {
3600
+ type: "string",
3601
+ minLength: 1,
3602
+ maxLength: 44
3603
+ },
3604
+ lpViewTxSignature: {
3605
+ type: "string",
3606
+ minLength: 1,
3607
+ maxLength: 88
3608
+ },
3609
+ unsignedLamportTotalString: {
3610
+ type: "string",
3611
+ minLength: 1,
3612
+ maxLength: 39,
3613
+ pattern: "^(0|[1-9][0-9]*)$"
3614
+ },
3615
+ signedLamportTotalString: {
3616
+ type: "string",
3617
+ minLength: 1,
3618
+ maxLength: 40,
3619
+ pattern: "^(0|-?[1-9][0-9]*)$"
3620
+ },
3621
+ lpEconomicReturnSummary: {
3622
+ type: "object",
3623
+ additionalProperties: false,
3624
+ required: [
3625
+ "provider_reward_lamports",
3626
+ "source_expense_compensation_lamports",
3627
+ "charged_reimbursement_loss_lamports",
3628
+ "net_economic_return_lamports"
3629
+ ],
3630
+ properties: {
3631
+ provider_reward_lamports: {
3632
+ $ref: "#/$defs/unsignedLamportTotalString"
3633
+ },
3634
+ source_expense_compensation_lamports: {
3635
+ $ref: "#/$defs/unsignedLamportTotalString"
3636
+ },
3637
+ charged_reimbursement_loss_lamports: {
3638
+ $ref: "#/$defs/unsignedLamportTotalString"
3639
+ },
3640
+ net_economic_return_lamports: {
3641
+ $ref: "#/$defs/signedLamportTotalString"
3642
+ }
3643
+ }
3546
3644
  }
3547
3645
  }
3548
3646
  };
3549
3647
 
3550
3648
  // ../../protocol/src/coordinator/envelope.ts
3551
3649
  var ENVELOPE_VERSION = 2;
3552
- var MAX_FRAME_SIZE = 256 * 1024;
3650
+ var MAX_FRAME_SIZE = 512 * 1024;
3553
3651
  var COORDINATOR_ENVELOPE_SCHEMA = coordinator_envelope_schema_default;
3554
- var LP_MAX_TARGET_SHARDS = 300;
3652
+ var LP_MAX_TOTAL_SHARDS = 4294967295;
3555
3653
  var LP_WITHDRAW_REQUEST_PATH = "lp_command.withdrawRequest";
3556
3654
  var UNKNOWN_SWAP_ID = "<unknown>";
3557
3655
  var binaryFieldNames = new Set(COORDINATOR_BINARY_FIELD_NAMES);
3558
- var ajv = new Ajv2020({
3559
- allErrors: true,
3560
- strict: true
3561
- });
3562
- var validateWireEnvelope = ajv.compile(coordinator_envelope_schema_default);
3563
3656
  var textEncoder = new TextEncoder();
3564
3657
  var textDecoder = new TextDecoder("utf-8", { fatal: true });
3658
+ var MAX_ENCODED_JSON_BYTES_KEYWORD = "maxEncodedJsonBytes";
3659
+ function createCoordinatorSchemaValidator() {
3660
+ const ajv = new Ajv2020({ allErrors: true, strict: true });
3661
+ ajv.addKeyword({
3662
+ keyword: MAX_ENCODED_JSON_BYTES_KEYWORD,
3663
+ schemaType: "number",
3664
+ metaSchema: { type: "integer", minimum: 0, maximum: Number.MAX_SAFE_INTEGER },
3665
+ validate: (limit, value) => {
3666
+ try {
3667
+ const encoded = JSON.stringify(value);
3668
+ return encoded !== void 0 && textEncoder.encode(encoded).byteLength <= limit;
3669
+ } catch {
3670
+ return false;
3671
+ }
3672
+ },
3673
+ errors: false
3674
+ });
3675
+ return ajv.compile(coordinator_envelope_schema_default);
3676
+ }
3677
+ var validateWireEnvelope = createCoordinatorSchemaValidator();
3565
3678
  function encode(env) {
3566
3679
  return textEncoder.encode(JSON.stringify(toWireEnvelope(env)));
3567
3680
  }
@@ -3581,6 +3694,8 @@ function safeEncode(env) {
3581
3694
  if (!validateWireEnvelope(wire)) {
3582
3695
  return { ok: false, error: schemaError(wire, validateWireEnvelope.errors ?? []) };
3583
3696
  }
3697
+ const economicReturnError = validateLpEconomicReturnSemantics(wire);
3698
+ if (economicReturnError) return { ok: false, error: economicReturnError };
3584
3699
  const encoded = textEncoder.encode(JSON.stringify(wire));
3585
3700
  if (encoded.byteLength > MAX_FRAME_SIZE) {
3586
3701
  return {
@@ -3721,10 +3836,10 @@ function validateUniqueLpAddresses(path, addresses) {
3721
3836
  function validateLpDkgFinalizeRange(path, startIndex, addressCount) {
3722
3837
  if (addressCount === 0) return;
3723
3838
  const lastIndex = startIndex + addressCount - 1;
3724
- if (lastIndex >= LP_MAX_TARGET_SHARDS) {
3839
+ if (lastIndex >= LP_MAX_TOTAL_SHARDS) {
3725
3840
  throw new CoordinatorError(
3726
3841
  ErrorCode.ERR_INVALID_PAYLOAD,
3727
- `${path}.addresses end index (${lastIndex}) must be <= ${LP_MAX_TARGET_SHARDS - 1}`
3842
+ `${path}.addresses end index (${lastIndex}) must be <= ${LP_MAX_TOTAL_SHARDS - 1}`
3728
3843
  );
3729
3844
  }
3730
3845
  }
@@ -3759,6 +3874,8 @@ function decode(raw) {
3759
3874
  if (!validateWireEnvelope(parsed)) {
3760
3875
  return { ok: false, error: schemaError(parsed, validateWireEnvelope.errors ?? []) };
3761
3876
  }
3877
+ const economicReturnError = validateLpEconomicReturnSemantics(parsed);
3878
+ if (economicReturnError) return { ok: false, error: economicReturnError };
3762
3879
  try {
3763
3880
  return { ok: true, value: fromWireEnvelope(parsed) };
3764
3881
  } catch (error) {
@@ -4118,7 +4235,27 @@ var asErrorPayload = (e) => {
4118
4235
  }
4119
4236
  return payload;
4120
4237
  };
4238
+ var LP_ECONOMIC_UNSIGNED_TOTAL_MAX = (1n << 128n) - 1n;
4239
+ var LP_ECONOMIC_SIGNED_TOTAL_MIN = -(1n << 127n);
4240
+ var LP_ECONOMIC_SIGNED_TOTAL_MAX = (1n << 127n) - 1n;
4241
+ function validateLpEconomicReturnSemantics(wire) {
4242
+ const payload = wire.payload;
4243
+ if (!payload || payload.case !== "position") return void 0;
4244
+ const summary = payload.value?.actor_sync?.economic_return;
4245
+ if (!summary) return void 0;
4246
+ const reward = BigInt(summary.provider_reward_lamports);
4247
+ const compensation = BigInt(summary.source_expense_compensation_lamports);
4248
+ const loss = BigInt(summary.charged_reimbursement_loss_lamports);
4249
+ const net = BigInt(summary.net_economic_return_lamports);
4250
+ if (reward > LP_ECONOMIC_UNSIGNED_TOTAL_MAX || compensation > LP_ECONOMIC_UNSIGNED_TOTAL_MAX || loss > LP_ECONOMIC_UNSIGNED_TOTAL_MAX || net < LP_ECONOMIC_SIGNED_TOTAL_MIN || net > LP_ECONOMIC_SIGNED_TOTAL_MAX || net !== reward - loss) {
4251
+ return new CoordinatorError(
4252
+ ErrorCode.ERR_INVALID_PAYLOAD,
4253
+ "LP economic return invariant is invalid"
4254
+ );
4255
+ }
4256
+ return void 0;
4257
+ }
4121
4258
 
4122
- export { COORDINATOR_BINARY_FIELD_NAMES, COORDINATOR_ENVELOPE_SCHEMA, COORDINATOR_SCHEMA_PAYLOAD_CATEGORIES, CoordinatorError, CoordinatorMessageType, DEFAULT_PAYOUT_WINDOW_ID, DIRECTION_BY_TYPE, ENVELOPE_VERSION, EnvelopeKind, ErrorCode, INITIAL_STATE, MAX_FRAME_SIZE, MessageDirection, PAYOUT_WINDOW_OPTIONS, TERMINAL_STATES, TRANSITIONS, VALID_SWAP_STATES, asDelegateAckPayload, asDelegateSharePayload, asDelegateShareResponsePayload, asDepositConfirmedPayload, asDkgCompletePayload, asDkgInitPayload, asDkgInitResponsePayload, asDkgRound1Payload, asDkgRound1ResponsePayload, asDkgRound2Payload, asDkgRound2ResponsePayload, asErrorPayload, asLpCommandResponsePayload, asPayoutExecutedPayload, asSwapRequestPayload, asSwapRequestResponsePayload, asSyncRequiredPayload, asSyncUserRequestPayload, asSyncUserResponsePayload, asWithdrawAcceptedPayload, asWithdrawExecutedPayload, asWithdrawRequestPayload, decode, encode, encodeLpCommandForSigning, encodeValidated, isAllowedInState, isAllowedKindForType, isPayoutWindowId, isValidEnvelopeKind, isValidErrorCode, isValidMessageType, isValidSwapState, lpSignedCommandEnvelope, nextState, payloadCategory, payoutWindowLabelForId, payoutWindowOptionById, safeEncode, scheduledPayoutWindowOptions, scheduledPayoutWindowSeconds };
4123
- //# sourceMappingURL=chunk-3TGQ4CZ3.js.map
4124
- //# sourceMappingURL=chunk-3TGQ4CZ3.js.map
4259
+ export { COORDINATOR_BINARY_FIELD_NAMES, COORDINATOR_ENVELOPE_SCHEMA, COORDINATOR_SCHEMA_PAYLOAD_CATEGORIES, CoordinatorError, CoordinatorMessageType, DEFAULT_PAYOUT_WINDOW_ID, DIRECTION_BY_TYPE, ENVELOPE_VERSION, EnvelopeKind, ErrorCode, INITIAL_STATE, MAX_ENCODED_JSON_BYTES_KEYWORD, MAX_FRAME_SIZE, MessageDirection, PAYOUT_WINDOW_OPTIONS, TERMINAL_STATES, TRANSITIONS, VALID_SWAP_STATES, asDelegateAckPayload, asDelegateSharePayload, asDelegateShareResponsePayload, asDepositConfirmedPayload, asDkgCompletePayload, asDkgInitPayload, asDkgInitResponsePayload, asDkgRound1Payload, asDkgRound1ResponsePayload, asDkgRound2Payload, asDkgRound2ResponsePayload, asErrorPayload, asLpCommandResponsePayload, asPayoutExecutedPayload, asSwapRequestPayload, asSwapRequestResponsePayload, asSyncRequiredPayload, asSyncUserRequestPayload, asSyncUserResponsePayload, asWithdrawAcceptedPayload, asWithdrawExecutedPayload, asWithdrawRequestPayload, createCoordinatorSchemaValidator, decode, encode, encodeLpCommandForSigning, encodeValidated, isAllowedInState, isAllowedKindForType, isPayoutWindowId, isValidEnvelopeKind, isValidErrorCode, isValidMessageType, isValidSwapState, lpSignedCommandEnvelope, nextState, payloadCategory, payoutWindowLabelForId, payoutWindowOptionById, safeEncode, scheduledPayoutWindowOptions, scheduledPayoutWindowSeconds };
4260
+ //# sourceMappingURL=chunk-QF5TSUQE.js.map
4261
+ //# sourceMappingURL=chunk-QF5TSUQE.js.map