@bounded-sh/core 0.0.69 → 0.0.71

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 (25) hide show
  1. package/dist/client/config.d.ts +22 -1
  2. package/dist/{index-B3aNfGi6.mjs → index-P4eUuhOB.mjs} +141 -17
  3. package/dist/index-P4eUuhOB.mjs.map +1 -0
  4. package/dist/{index-DlJKTmRv.js → index-yT8ZfzrL.js} +141 -17
  5. package/dist/index-yT8ZfzrL.js.map +1 -0
  6. package/dist/index.js +1 -1
  7. package/dist/index.mjs +1 -1
  8. package/dist/{realtime-store-CkgpUOrE.js → realtime-store-BDpIOFMH.js} +2 -2
  9. package/dist/{realtime-store-CkgpUOrE.js.map → realtime-store-BDpIOFMH.js.map} +1 -1
  10. package/dist/{realtime-store-i8pxSuZE.mjs → realtime-store-Bcnv3f0g.mjs} +2 -2
  11. package/dist/{realtime-store-i8pxSuZE.mjs.map → realtime-store-Bcnv3f0g.mjs.map} +1 -1
  12. package/dist/{solana-message-DnV4FQ__.js → solana-message-Dh9ryO-Y.js} +2 -2
  13. package/dist/{solana-message-DnV4FQ__.js.map → solana-message-Dh9ryO-Y.js.map} +1 -1
  14. package/dist/{solana-message-AXfv2U1S.mjs → solana-message-x8ElgC9P.mjs} +2 -2
  15. package/dist/{solana-message-AXfv2U1S.mjs.map → solana-message-x8ElgC9P.mjs.map} +1 -1
  16. package/dist/{solana-operations-Bte92rmq.mjs → solana-operations-DEWIxJS8.mjs} +127 -8
  17. package/dist/solana-operations-DEWIxJS8.mjs.map +1 -0
  18. package/dist/{solana-operations-DPul1dWo.js → solana-operations-DGEGqFd9.js} +127 -8
  19. package/dist/solana-operations-DGEGqFd9.js.map +1 -0
  20. package/dist/utils/refresh-error.d.ts +9 -0
  21. package/package.json +2 -2
  22. package/dist/index-B3aNfGi6.mjs.map +0 -1
  23. package/dist/index-DlJKTmRv.js.map +0 -1
  24. package/dist/solana-operations-Bte92rmq.mjs.map +0 -1
  25. package/dist/solana-operations-DPul1dWo.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { g as getConfig, b as bufferExports } from './index-B3aNfGi6.mjs';
1
+ import { g as getConfig, b as bufferExports } from './index-P4eUuhOB.mjs';
2
2
  import 'axios';
3
3
  import 'tweetnacl';
4
4
  import 'reconnecting-websocket';
@@ -93,11 +93,36 @@ const BOUNDED_PROGRAM_MAINNET = ['open', 'Tv7fbpYSseNHYmCZFZ1CZgj4r8D9fKNgEz1qo6
93
93
  const BOUNDED_PROGRAM_DEVNET = ['open', 'Tv7fbpYSseNHYmCZFZ1CZgj4r8D9fKNgEz1qo6F'].join('');
94
94
  const COMPUTE_BUDGET_PROGRAM = 'ComputeBudget111111111111111111111111111111';
95
95
  const SYSTEM_PROGRAM_ID = '11111111111111111111111111111111';
96
+ // SPL Associated Token program and the two SPL Token programs it may create an
97
+ // account under. The server builder compiles idempotent ATA-create setup
98
+ // instructions ahead of the Bounded write for every ATA-creating plugin.
99
+ const ASSOCIATED_TOKEN_PROGRAM_ID = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL';
100
+ const TOKEN_PROGRAM_ID = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
101
+ const TOKEN_2022_PROGRAM_ID = 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb';
102
+ const SPL_TOKEN_PROGRAM_IDS = new Set([TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID]);
103
+ // Idempotent ATA create carries a single instruction byte 0x01 (CreateIdempotent)
104
+ // and exactly six accounts: funding, ATA, owner, mint, system program, token
105
+ // program.
106
+ const ATA_CREATE_IDEMPOTENT_DISCRIMINATOR = 1;
107
+ const ATA_CREATE_ACCOUNT_COUNT = 6;
108
+ // System Program `transfer` is instruction index 2 (u32 LE) followed by a u64
109
+ // lamports amount: a 12-byte data payload over exactly two accounts.
110
+ const SYSTEM_TRANSFER_INSTRUCTION_INDEX = 2;
111
+ const SYSTEM_TRANSFER_DATA_LENGTH = 12;
112
+ const SYSTEM_TRANSFER_ACCOUNT_COUNT = 2;
113
+ // Gas-sponsorship top-up cap. Mirrors the server builder's ATA-inclusive
114
+ // absolute maximum (0.05 SOL); the fee payer (the gas sponsor) can only move its
115
+ // OWN lamports up to this bound, and only to a co-signing account.
116
+ const SPONSOR_TOPUP_MAX_LAMPORTS = BigInt(50000000);
117
+ // The four setup/write programs a server-built transaction may reference. System
118
+ // and Associated-Token are typed-validated per instruction below; a bare
119
+ // presence in this set is NOT sufficient authorization.
96
120
  const ALLOWED_SERVER_TX_PROGRAMS = new Set([
97
121
  BOUNDED_PROGRAM_MAINNET,
98
122
  BOUNDED_PROGRAM_DEVNET,
99
123
  COMPUTE_BUDGET_PROGRAM,
100
124
  SYSTEM_PROGRAM_ID,
125
+ ASSOCIATED_TOKEN_PROGRAM_ID,
101
126
  ]);
102
127
  // Canonical set_documents discriminator (single wire format: ra_indices Vec<u8>).
103
128
  const SET_DOCUMENTS_DISCRIMINATOR = '79,46,72,73,24,79,66,245';
@@ -208,11 +233,97 @@ function assertSamePathSet(label, expectedPaths, actualPaths) {
208
233
  throw new Error(`${label} Bounded instruction paths do not match requested write paths (${details})`);
209
234
  }
210
235
  }
211
- function deserializeAndValidateServerTransaction(serializedTransaction, VersionedTransactionClass, options) {
236
+ /** Read a little-endian u64 as a BigInt (lamport amounts can exceed 2^53). */
237
+ function readU64LE(bytes, offset) {
238
+ let value = BigInt(0);
239
+ for (let i = 0; i < 8; i++)
240
+ value |= BigInt(bytes[offset + i]) << BigInt(8 * i);
241
+ return value;
242
+ }
243
+ /**
244
+ * Resolve an instruction's referenced account keys against the transaction's
245
+ * STATIC key list. A setup instruction that reaches into an address-lookup
246
+ * table for any account it needs cannot be validated offline, so it fails
247
+ * closed: every index must resolve to a static key.
248
+ */
249
+ function resolveInstructionAccounts(ix, accountKeys, label) {
250
+ return ix.accountKeyIndexes.map(index => {
251
+ if (index >= accountKeys.length) {
252
+ throw new Error(`${label} setup instruction references an address-lookup-table account (not allowed)`);
253
+ }
254
+ return accountKeys[index];
255
+ });
256
+ }
257
+ /**
258
+ * A server-built idempotent ATA create is authorized ONLY when it is exactly the
259
+ * canonical shape: instruction byte 0x01, six accounts, funded by the
260
+ * transaction fee payer, over the System and an SPL Token program, and where the
261
+ * account being created recomputes to the associated-token-account PDA of its
262
+ * stated owner and mint. Nothing else - no arbitrary account create - passes.
263
+ */
264
+ function validateIdempotentAtaCreate(ix, data, accountKeys, feePayer, PublicKeyCtor, label) {
265
+ if (data.length !== 1 || data[0] !== ATA_CREATE_IDEMPOTENT_DISCRIMINATOR) {
266
+ throw new Error(`${label} contains a non-idempotent or malformed associated-token-account instruction`);
267
+ }
268
+ if (ix.accountKeyIndexes.length !== ATA_CREATE_ACCOUNT_COUNT) {
269
+ throw new Error(`${label} associated-token-account create has an unexpected account layout`);
270
+ }
271
+ const [funding, ata, owner, mint, systemProgram, tokenProgram] = resolveInstructionAccounts(ix, accountKeys, label);
272
+ if (!funding.equals(feePayer)) {
273
+ throw new Error(`${label} associated-token-account create is not funded by the transaction fee payer`);
274
+ }
275
+ if (systemProgram.toBase58() !== SYSTEM_PROGRAM_ID) {
276
+ throw new Error(`${label} associated-token-account create references an unexpected system program`);
277
+ }
278
+ if (!SPL_TOKEN_PROGRAM_IDS.has(tokenProgram.toBase58())) {
279
+ throw new Error(`${label} associated-token-account create references an unexpected token program`);
280
+ }
281
+ const [expectedAta] = PublicKeyCtor.findProgramAddressSync([owner.toBuffer(), tokenProgram.toBuffer(), mint.toBuffer()], new PublicKeyCtor(ASSOCIATED_TOKEN_PROGRAM_ID));
282
+ if (!ata.equals(expectedAta)) {
283
+ throw new Error(`${label} associated-token-account create does not derive the canonical account for its owner and mint`);
284
+ }
285
+ }
286
+ /**
287
+ * A server-built System Program instruction is authorized ONLY as the gas
288
+ * sponsor's top-up: a `transfer` FROM the transaction fee payer (the sponsor),
289
+ * capped at the sponsorship maximum, TO a co-signing account (the sponsored
290
+ * user). The fee payer can therefore only move its OWN lamports, bounded, and
291
+ * only to an account that itself signed the transaction - never a drain to an
292
+ * arbitrary address. Every other System instruction (createAccount, an
293
+ * uncapped or misdirected transfer, ...) is rejected.
294
+ */
295
+ function validateSponsorTransfer(ix, data, accountKeys, feePayer, isAccountSigner, label) {
296
+ const isTransfer = data.length === SYSTEM_TRANSFER_DATA_LENGTH &&
297
+ (data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24)) === SYSTEM_TRANSFER_INSTRUCTION_INDEX;
298
+ if (!isTransfer) {
299
+ throw new Error(`${label} contains an unauthorized System Program instruction`);
300
+ }
301
+ if (ix.accountKeyIndexes.length !== SYSTEM_TRANSFER_ACCOUNT_COUNT) {
302
+ throw new Error(`${label} contains an unauthorized System Program instruction`);
303
+ }
304
+ const [from, to] = resolveInstructionAccounts(ix, accountKeys, label);
305
+ if (!from.equals(feePayer)) {
306
+ throw new Error(`${label} System Program transfer must originate from the transaction fee payer (gas sponsor)`);
307
+ }
308
+ const lamports = readU64LE(data, 4);
309
+ if (lamports > SPONSOR_TOPUP_MAX_LAMPORTS) {
310
+ throw new Error(`${label} System Program transfer exceeds the gas-sponsorship cap`);
311
+ }
312
+ const recipientIndex = ix.accountKeyIndexes[1];
313
+ if (!isAccountSigner(recipientIndex) || to.equals(feePayer)) {
314
+ throw new Error(`${label} System Program transfer recipient must be a co-signing sponsored account`);
315
+ }
316
+ }
317
+ function deserializeAndValidateServerTransaction(serializedTransaction, web3, options) {
212
318
  var _a;
319
+ const { VersionedTransaction: VersionedTransactionClass, PublicKey: PublicKeyCtor } = web3;
213
320
  const transaction = VersionedTransactionClass.deserialize(bufferExports.Buffer.from(serializedTransaction, 'base64'));
214
321
  const { label, expectedAppId, expectedWritePaths } = options;
215
322
  const accountKeys = transaction.message.staticAccountKeys;
323
+ if (accountKeys.length === 0)
324
+ throw new Error(`${label} has no static account keys`);
325
+ const feePayer = accountKeys[0];
326
+ const isAccountSigner = (index) => transaction.message.isAccountSigner(index);
216
327
  let boundedInstructionCount = 0;
217
328
  const actualWritePaths = [];
218
329
  for (const ix of transaction.message.compiledInstructions) {
@@ -222,9 +333,17 @@ function deserializeAndValidateServerTransaction(serializedTransaction, Versione
222
333
  if (!ALLOWED_SERVER_TX_PROGRAMS.has(programId))
223
334
  throw new Error(`${label} contains unauthorized program: ${programId}`);
224
335
  const data = ix.data instanceof Uint8Array ? ix.data : bufferExports.Buffer.from((_a = ix.data) !== null && _a !== void 0 ? _a : []);
225
- if (programId === SYSTEM_PROGRAM_ID)
226
- throw new Error(`${label} contains unauthorized System Program instruction`);
227
- if (programId === BOUNDED_PROGRAM_MAINNET || programId === BOUNDED_PROGRAM_DEVNET) {
336
+ // Typed setup checks replace the old blanket System-Program ban: each of the
337
+ // two setup shapes the server builder emits (idempotent ATA create, gas
338
+ // sponsor top-up) is bound to recompute to the values this write needs, and
339
+ // anything else fails closed.
340
+ if (programId === SYSTEM_PROGRAM_ID) {
341
+ validateSponsorTransfer(ix, data, accountKeys, feePayer, isAccountSigner, label);
342
+ }
343
+ else if (programId === ASSOCIATED_TOKEN_PROGRAM_ID) {
344
+ validateIdempotentAtaCreate(ix, data, accountKeys, feePayer, PublicKeyCtor, label);
345
+ }
346
+ else if (programId === BOUNDED_PROGRAM_MAINNET || programId === BOUNDED_PROGRAM_DEVNET) {
228
347
  boundedInstructionCount++;
229
348
  const parsed = parseBoundedSetDocumentsInstruction(data, label);
230
349
  if (parsed.appId !== expectedAppId)
@@ -239,11 +358,11 @@ function deserializeAndValidateServerTransaction(serializedTransaction, Versione
239
358
  }
240
359
  async function handlePreBuiltTransaction(tx, authProvider, options, expectedWritePaths) {
241
360
  var _a, _b, _c, _d, _e, _f, _g, _h;
242
- const { Connection, VersionedTransaction } = await import('@solana/web3.js');
361
+ const { Connection, VersionedTransaction, PublicKey } = await import('@solana/web3.js');
243
362
  // Honor a wallet client's immutable config snapshot for the expected app-id
244
363
  // binding and RPC endpoint (CTA-05); otherwise read the global init() config.
245
364
  const config = (_b = (_a = options === null || options === void 0 ? void 0 : options._overrides) === null || _a === void 0 ? void 0 : _a._config) !== null && _b !== void 0 ? _b : await getConfig();
246
- const transaction = deserializeAndValidateServerTransaction(tx.serializedTransaction, VersionedTransaction, {
365
+ const transaction = deserializeAndValidateServerTransaction(tx.serializedTransaction, { VersionedTransaction, PublicKey }, {
247
366
  label: 'Pre-built transaction', expectedAppId: config.appId, expectedWritePaths,
248
367
  });
249
368
  const shouldSubmit = (options === null || options === void 0 ? void 0 : options.shouldSubmitTx) !== false;
@@ -332,4 +451,4 @@ async function handlePreBuiltTransaction(tx, authProvider, options, expectedWrit
332
451
  }
333
452
 
334
453
  export { deriveTransactionSignature, handlePreBuiltTransaction, isDefinitiveSolanaSendFailure };
335
- //# sourceMappingURL=solana-operations-Bte92rmq.mjs.map
454
+ //# sourceMappingURL=solana-operations-DEWIxJS8.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solana-operations-DEWIxJS8.mjs","sources":["../.rollup-tmp/client/solana-operations.js"],"sourcesContent":["import { Buffer } from 'buffer';\nimport { getConfig } from './config';\nconst BASE58_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';\n/**\n * Minimal base58 encoder, used ONLY to derive a Solana transaction signature\n * from already-signed bytes. Core deliberately does not take a `bs58`\n * dependency for eighteen lines of arithmetic.\n */\nfunction encodeBase58(bytes) {\n if (bytes.length === 0)\n return '';\n const digits = [0];\n for (const byte of bytes) {\n let carry = byte;\n for (let i = 0; i < digits.length; i++) {\n carry += digits[i] << 8;\n digits[i] = carry % 58;\n carry = (carry / 58) | 0;\n }\n while (carry > 0) {\n digits.push(carry % 58);\n carry = (carry / 58) | 0;\n }\n }\n let out = '';\n for (let i = 0; i < bytes.length && bytes[i] === 0; i++)\n out += BASE58_ALPHABET[0];\n for (let i = digits.length - 1; i >= 0; i--)\n out += BASE58_ALPHABET[digits[i]];\n return out;\n}\n/**\n * Derive the transaction signature from the SIGNED bytes, before broadcasting.\n *\n * Without this the signature is only learned when `sendRawTransaction` resolves,\n * so an RPC that accepted the bytes but whose response was lost throws with\n * nothing recorded — and a retry builds a DIFFERENT transaction that can land\n * beside the first.\n */\nexport function deriveTransactionSignature(signedTransaction) {\n var _a;\n const signature = (_a = signedTransaction.signatures) === null || _a === void 0 ? void 0 : _a[0];\n if (!signature || signature.length === 0) {\n throw new Error('Signed Solana transaction carries no signature to broadcast');\n }\n if (signature.every(byte => byte === 0)) {\n throw new Error('Signed Solana transaction carries an empty fee-payer signature');\n }\n return encodeBase58(Uint8Array.from(signature));\n}\n/**\n * Whether a send failure PROVES the transaction was never accepted. A preflight\n * rejection, a signature-verification failure, or an oversized/invalid\n * transaction is definitive and keeps throwing. A transport failure (timeout,\n * socket reset, aborted fetch) is ambiguous — the node may hold the bytes — and\n * must resolve as `submitted` carrying the pre-derived signature.\n *\n * \"already processed\" is deliberately NOT definitive: it means the signature\n * landed, which is the opposite of a failure.\n */\nconst DEFINITIVE_SEND_FAILURE_MARKERS = [\n 'simulation failed',\n 'preflight',\n 'blockhash not found',\n 'signature verification failure',\n 'transaction too large',\n 'invalid transaction',\n 'insufficient funds for rent',\n 'attempt to debit an account but found no record of a prior credit',\n];\nexport function isDefinitiveSolanaSendFailure(error) {\n var _a, _b, _c;\n const err = error;\n if (err && Array.isArray(err.logs))\n return true;\n if (err && String((_a = err.name) !== null && _a !== void 0 ? _a : '') === 'SendTransactionError')\n return true;\n const message = String((_c = (_b = err === null || err === void 0 ? void 0 : err.message) !== null && _b !== void 0 ? _b : err) !== null && _c !== void 0 ? _c : '').toLowerCase();\n if (!message)\n return false;\n if (message.includes('already been processed') || message.includes('already processed'))\n return false;\n return DEFINITIVE_SEND_FAILURE_MARKERS.some(marker => message.includes(marker));\n}\nfunction errorText(error) {\n const message = error === null || error === void 0 ? void 0 : error.message;\n return typeof message === 'string' && message.length > 0 ? message : String(error);\n}\nconst BOUNDED_PROGRAM_MAINNET = ['open', 'Tv7fbpYSseNHYmCZFZ1CZgj4r8D9fKNgEz1qo6F'].join('');\nconst BOUNDED_PROGRAM_DEVNET = ['open', 'Tv7fbpYSseNHYmCZFZ1CZgj4r8D9fKNgEz1qo6F'].join('');\nconst COMPUTE_BUDGET_PROGRAM = 'ComputeBudget111111111111111111111111111111';\nconst SYSTEM_PROGRAM_ID = '11111111111111111111111111111111';\n// SPL Associated Token program and the two SPL Token programs it may create an\n// account under. The server builder compiles idempotent ATA-create setup\n// instructions ahead of the Bounded write for every ATA-creating plugin.\nconst ASSOCIATED_TOKEN_PROGRAM_ID = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL';\nconst TOKEN_PROGRAM_ID = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';\nconst TOKEN_2022_PROGRAM_ID = 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb';\nconst SPL_TOKEN_PROGRAM_IDS = new Set([TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID]);\n// Idempotent ATA create carries a single instruction byte 0x01 (CreateIdempotent)\n// and exactly six accounts: funding, ATA, owner, mint, system program, token\n// program.\nconst ATA_CREATE_IDEMPOTENT_DISCRIMINATOR = 1;\nconst ATA_CREATE_ACCOUNT_COUNT = 6;\n// System Program `transfer` is instruction index 2 (u32 LE) followed by a u64\n// lamports amount: a 12-byte data payload over exactly two accounts.\nconst SYSTEM_TRANSFER_INSTRUCTION_INDEX = 2;\nconst SYSTEM_TRANSFER_DATA_LENGTH = 12;\nconst SYSTEM_TRANSFER_ACCOUNT_COUNT = 2;\n// Gas-sponsorship top-up cap. Mirrors the server builder's ATA-inclusive\n// absolute maximum (0.05 SOL); the fee payer (the gas sponsor) can only move its\n// OWN lamports up to this bound, and only to a co-signing account.\nconst SPONSOR_TOPUP_MAX_LAMPORTS = BigInt(50000000);\n// The four setup/write programs a server-built transaction may reference. System\n// and Associated-Token are typed-validated per instruction below; a bare\n// presence in this set is NOT sufficient authorization.\nconst ALLOWED_SERVER_TX_PROGRAMS = new Set([\n BOUNDED_PROGRAM_MAINNET,\n BOUNDED_PROGRAM_DEVNET,\n COMPUTE_BUDGET_PROGRAM,\n SYSTEM_PROGRAM_ID,\n ASSOCIATED_TOKEN_PROGRAM_ID,\n]);\n// Canonical set_documents discriminator (single wire format: ra_indices Vec<u8>).\nconst SET_DOCUMENTS_DISCRIMINATOR = '79,46,72,73,24,79,66,245';\nconst ALLOWED_BOUNDED_SET_DISCRIMINATORS = new Set([\n SET_DOCUMENTS_DISCRIMINATOR,\n]);\nclass BorshCursor {\n constructor(data, offset, label) {\n this.data = data;\n this.offset = offset;\n this.label = label;\n }\n requireBytes(length, field) {\n if (this.offset + length > this.data.length) {\n throw new Error(`${this.label} has malformed Bounded instruction data while reading ${field}`);\n }\n }\n readU8(field) { this.requireBytes(1, field); return this.data[this.offset++]; }\n readU32(field) {\n this.requireBytes(4, field);\n const value = this.data[this.offset] | (this.data[this.offset + 1] << 8) |\n (this.data[this.offset + 2] << 16) | (this.data[this.offset + 3] << 24);\n this.offset += 4;\n return value >>> 0;\n }\n skip(length, field) { this.requireBytes(length, field); this.offset += length; }\n readString(field) {\n const length = this.readU32(`${field} length`);\n this.requireBytes(length, field);\n const raw = this.data.slice(this.offset, this.offset + length);\n this.offset += length;\n return Buffer.from(raw).toString('utf8');\n }\n skipBytes(field) { this.skip(this.readU32(`${field} length`), field); }\n isAtEnd() { return this.offset === this.data.length; }\n}\nfunction skipBoundedFieldValue(cursor) {\n const option = cursor.readU8('operation value option');\n if (option === 0)\n return;\n if (option !== 1)\n throw new Error('Server transaction has malformed Bounded field value option');\n const variant = cursor.readU8('operation value variant');\n if (variant === 0 || variant === 1)\n cursor.skip(8, 'operation numeric value');\n else if (variant === 2)\n cursor.skip(1, 'operation bool value');\n else if (variant === 3)\n cursor.readString('operation string value');\n else if (variant === 4)\n cursor.skip(32, 'operation address value');\n else\n throw new Error(`Server transaction has unsupported Bounded field value variant: ${variant}`);\n}\nfunction normalizeOnchainPath(path) {\n let normalized = path.startsWith('/') ? path.slice(1) : path;\n if (normalized.endsWith('*') && normalized.length > 1)\n normalized = normalized.slice(0, -1);\n if (normalized.endsWith('/'))\n normalized = normalized.slice(0, -1);\n return normalized;\n}\nfunction parseBoundedSetDocumentsInstruction(data, label) {\n if (data.length < 8)\n throw new Error(`${label} has malformed Bounded instruction data`);\n const discriminator = Array.from(data.slice(0, 8)).join(',');\n if (!ALLOWED_BOUNDED_SET_DISCRIMINATORS.has(discriminator)) {\n throw new Error(`${label} contains unsupported Bounded instruction`);\n }\n const cursor = new BorshCursor(data, 8, label);\n const appId = cursor.readString('appId');\n const documentPaths = [];\n const documentCount = cursor.readU32('documents length');\n for (let i = 0; i < documentCount; i++) {\n documentPaths.push(normalizeOnchainPath(cursor.readString('document path')));\n const operationCount = cursor.readU32('operations length');\n for (let j = 0; j < operationCount; j++) {\n cursor.readString('operation key');\n skipBoundedFieldValue(cursor);\n cursor.skip(1, 'operation kind');\n }\n }\n const deletePaths = [];\n const deleteCount = cursor.readU32('delete paths length');\n for (let i = 0; i < deleteCount; i++)\n deletePaths.push(normalizeOnchainPath(cursor.readString('delete path')));\n const txDataCount = cursor.readU32('txData length');\n for (let i = 0; i < txDataCount; i++) {\n cursor.readString('txData plugin function key');\n cursor.skipBytes('txData bytes');\n cursor.skipBytes('txData raIndices');\n }\n const simulate = cursor.readU8('simulate');\n if (simulate !== 0 && simulate !== 1)\n throw new Error(`${label} has malformed Bounded simulate flag`);\n if (!cursor.isAtEnd())\n throw new Error(`${label} has trailing Bounded instruction data`);\n return { appId, documentPaths, deletePaths };\n}\nfunction assertSamePathSet(label, expectedPaths, actualPaths) {\n const expected = new Set(expectedPaths.map(normalizeOnchainPath).filter(Boolean));\n const actual = new Set(actualPaths.map(normalizeOnchainPath).filter(Boolean));\n const missing = [...expected].filter(path => !actual.has(path));\n const extra = [...actual].filter(path => !expected.has(path));\n if (missing.length || extra.length) {\n const details = [missing.length ? `missing paths: ${missing.join(', ')}` : '', extra.length ? `unexpected paths: ${extra.join(', ')}` : '']\n .filter(Boolean).join('; ');\n throw new Error(`${label} Bounded instruction paths do not match requested write paths (${details})`);\n }\n}\n/** Read a little-endian u64 as a BigInt (lamport amounts can exceed 2^53). */\nfunction readU64LE(bytes, offset) {\n let value = BigInt(0);\n for (let i = 0; i < 8; i++)\n value |= BigInt(bytes[offset + i]) << BigInt(8 * i);\n return value;\n}\n/**\n * Resolve an instruction's referenced account keys against the transaction's\n * STATIC key list. A setup instruction that reaches into an address-lookup\n * table for any account it needs cannot be validated offline, so it fails\n * closed: every index must resolve to a static key.\n */\nfunction resolveInstructionAccounts(ix, accountKeys, label) {\n return ix.accountKeyIndexes.map(index => {\n if (index >= accountKeys.length) {\n throw new Error(`${label} setup instruction references an address-lookup-table account (not allowed)`);\n }\n return accountKeys[index];\n });\n}\n/**\n * A server-built idempotent ATA create is authorized ONLY when it is exactly the\n * canonical shape: instruction byte 0x01, six accounts, funded by the\n * transaction fee payer, over the System and an SPL Token program, and where the\n * account being created recomputes to the associated-token-account PDA of its\n * stated owner and mint. Nothing else - no arbitrary account create - passes.\n */\nfunction validateIdempotentAtaCreate(ix, data, accountKeys, feePayer, PublicKeyCtor, label) {\n if (data.length !== 1 || data[0] !== ATA_CREATE_IDEMPOTENT_DISCRIMINATOR) {\n throw new Error(`${label} contains a non-idempotent or malformed associated-token-account instruction`);\n }\n if (ix.accountKeyIndexes.length !== ATA_CREATE_ACCOUNT_COUNT) {\n throw new Error(`${label} associated-token-account create has an unexpected account layout`);\n }\n const [funding, ata, owner, mint, systemProgram, tokenProgram] = resolveInstructionAccounts(ix, accountKeys, label);\n if (!funding.equals(feePayer)) {\n throw new Error(`${label} associated-token-account create is not funded by the transaction fee payer`);\n }\n if (systemProgram.toBase58() !== SYSTEM_PROGRAM_ID) {\n throw new Error(`${label} associated-token-account create references an unexpected system program`);\n }\n if (!SPL_TOKEN_PROGRAM_IDS.has(tokenProgram.toBase58())) {\n throw new Error(`${label} associated-token-account create references an unexpected token program`);\n }\n const [expectedAta] = PublicKeyCtor.findProgramAddressSync([owner.toBuffer(), tokenProgram.toBuffer(), mint.toBuffer()], new PublicKeyCtor(ASSOCIATED_TOKEN_PROGRAM_ID));\n if (!ata.equals(expectedAta)) {\n throw new Error(`${label} associated-token-account create does not derive the canonical account for its owner and mint`);\n }\n}\n/**\n * A server-built System Program instruction is authorized ONLY as the gas\n * sponsor's top-up: a `transfer` FROM the transaction fee payer (the sponsor),\n * capped at the sponsorship maximum, TO a co-signing account (the sponsored\n * user). The fee payer can therefore only move its OWN lamports, bounded, and\n * only to an account that itself signed the transaction - never a drain to an\n * arbitrary address. Every other System instruction (createAccount, an\n * uncapped or misdirected transfer, ...) is rejected.\n */\nfunction validateSponsorTransfer(ix, data, accountKeys, feePayer, isAccountSigner, label) {\n const isTransfer = data.length === SYSTEM_TRANSFER_DATA_LENGTH &&\n (data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24)) === SYSTEM_TRANSFER_INSTRUCTION_INDEX;\n if (!isTransfer) {\n throw new Error(`${label} contains an unauthorized System Program instruction`);\n }\n if (ix.accountKeyIndexes.length !== SYSTEM_TRANSFER_ACCOUNT_COUNT) {\n throw new Error(`${label} contains an unauthorized System Program instruction`);\n }\n const [from, to] = resolveInstructionAccounts(ix, accountKeys, label);\n if (!from.equals(feePayer)) {\n throw new Error(`${label} System Program transfer must originate from the transaction fee payer (gas sponsor)`);\n }\n const lamports = readU64LE(data, 4);\n if (lamports > SPONSOR_TOPUP_MAX_LAMPORTS) {\n throw new Error(`${label} System Program transfer exceeds the gas-sponsorship cap`);\n }\n const recipientIndex = ix.accountKeyIndexes[1];\n if (!isAccountSigner(recipientIndex) || to.equals(feePayer)) {\n throw new Error(`${label} System Program transfer recipient must be a co-signing sponsored account`);\n }\n}\nfunction deserializeAndValidateServerTransaction(serializedTransaction, web3, options) {\n var _a;\n const { VersionedTransaction: VersionedTransactionClass, PublicKey: PublicKeyCtor } = web3;\n const transaction = VersionedTransactionClass.deserialize(Buffer.from(serializedTransaction, 'base64'));\n const { label, expectedAppId, expectedWritePaths } = options;\n const accountKeys = transaction.message.staticAccountKeys;\n if (accountKeys.length === 0)\n throw new Error(`${label} has no static account keys`);\n const feePayer = accountKeys[0];\n const isAccountSigner = (index) => transaction.message.isAccountSigner(index);\n let boundedInstructionCount = 0;\n const actualWritePaths = [];\n for (const ix of transaction.message.compiledInstructions) {\n if (ix.programIdIndex >= accountKeys.length)\n throw new Error(`${label} has program ID in lookup table (not allowed)`);\n const programId = accountKeys[ix.programIdIndex].toBase58();\n if (!ALLOWED_SERVER_TX_PROGRAMS.has(programId))\n throw new Error(`${label} contains unauthorized program: ${programId}`);\n const data = ix.data instanceof Uint8Array ? ix.data : Buffer.from((_a = ix.data) !== null && _a !== void 0 ? _a : []);\n // Typed setup checks replace the old blanket System-Program ban: each of the\n // two setup shapes the server builder emits (idempotent ATA create, gas\n // sponsor top-up) is bound to recompute to the values this write needs, and\n // anything else fails closed.\n if (programId === SYSTEM_PROGRAM_ID) {\n validateSponsorTransfer(ix, data, accountKeys, feePayer, isAccountSigner, label);\n }\n else if (programId === ASSOCIATED_TOKEN_PROGRAM_ID) {\n validateIdempotentAtaCreate(ix, data, accountKeys, feePayer, PublicKeyCtor, label);\n }\n else if (programId === BOUNDED_PROGRAM_MAINNET || programId === BOUNDED_PROGRAM_DEVNET) {\n boundedInstructionCount++;\n const parsed = parseBoundedSetDocumentsInstruction(data, label);\n if (parsed.appId !== expectedAppId)\n throw new Error(`${label} Bounded instruction appId does not match configured appId`);\n actualWritePaths.push(...parsed.documentPaths, ...parsed.deletePaths);\n }\n }\n if (boundedInstructionCount !== 1)\n throw new Error(`${label} must contain exactly one Bounded set-documents instruction`);\n assertSamePathSet(label, expectedWritePaths, actualWritePaths);\n return transaction;\n}\nexport async function handlePreBuiltTransaction(tx, authProvider, options, expectedWritePaths) {\n var _a, _b, _c, _d, _e, _f, _g, _h;\n const { Connection, VersionedTransaction, PublicKey } = await import(\"@solana/web3.js\");\n // Honor a wallet client's immutable config snapshot for the expected app-id\n // binding and RPC endpoint (CTA-05); otherwise read the global init() config.\n const config = (_b = (_a = options === null || options === void 0 ? void 0 : options._overrides) === null || _a === void 0 ? void 0 : _a._config) !== null && _b !== void 0 ? _b : await getConfig();\n const transaction = deserializeAndValidateServerTransaction(tx.serializedTransaction, { VersionedTransaction, PublicKey }, {\n label: 'Pre-built transaction', expectedAppId: config.appId, expectedWritePaths,\n });\n const shouldSubmit = (options === null || options === void 0 ? void 0 : options.shouldSubmitTx) !== false;\n const rpcUrl = (_c = config.rpcUrl) === null || _c === void 0 ? void 0 : _c.trim();\n const injectedRpc = (_d = options === null || options === void 0 ? void 0 : options._overrides) === null || _d === void 0 ? void 0 : _d._solanaRpc;\n if (shouldSubmit && !rpcUrl && !injectedRpc) {\n throw new Error(`Pre-built Solana transaction submission requires init({ rpcUrl }) for ${tx.network}`);\n }\n const signedTx = await authProvider.signTransaction(transaction);\n const rawTx = signedTx.serialize();\n const signedTransaction = Buffer.from(rawTx).toString('base64');\n // Keep the worker's expiry fence instead of discarding it: it is what makes\n // bounded same-signature reconciliation (and therefore the retry-safe\n // `expired_not_landed` exit) possible at all.\n const fence = { blockhash: tx.blockhash, lastValidBlockHeight: tx.lastValidBlockHeight };\n if (!shouldSubmit) {\n // Signed and NOT sent. There is no signature and nothing to mirror.\n return { outcome: 'signed', lane: 'solana', transactionSignature: null, signedTransaction, fence };\n }\n // Derive the signature from the signed bytes BEFORE broadcasting, so a send\n // whose response is lost still yields a reconcilable identifier.\n const signature = deriveTransactionSignature(signedTx);\n const connection = injectedRpc !== null && injectedRpc !== void 0 ? injectedRpc : new Connection(rpcUrl, 'confirmed');\n try {\n await connection.sendRawTransaction(rawTx, { skipPreflight: false, maxRetries: 3 });\n }\n catch (error) {\n // A definitive rejection never entered the network — keep throwing.\n if (isDefinitiveSolanaSendFailure(error))\n throw error;\n // Ambiguous transport outcome: the node may hold these exact bytes. Report\n // the pre-derived signature so the caller reconciles it instead of building\n // a second transaction that could land beside the first.\n return {\n outcome: 'submitted',\n lane: 'solana',\n transactionSignature: signature,\n signedTransaction,\n fence,\n reason: `Broadcast response was lost or inconclusive: ${errorText(error)}`,\n };\n }\n let confirmation;\n try {\n confirmation = await connection.confirmTransaction({\n signature, blockhash: tx.blockhash, lastValidBlockHeight: tx.lastValidBlockHeight,\n }, 'confirmed');\n }\n catch (error) {\n // The bytes were accepted; only the confirmation outcome is unknown.\n return {\n outcome: 'submitted',\n lane: 'solana',\n transactionSignature: signature,\n signedTransaction,\n fence,\n reason: `Confirmation outcome unknown: ${errorText(error)}`,\n };\n }\n // #310: \"confirmed\" only means the network recorded the transaction, not that it\n // succeeded - a landed-but-failed transaction carries an err. Report it as a failure\n // (with on-chain logs) instead of a fake success, mirroring the server keypair provider.\n if ((_e = confirmation.value) === null || _e === void 0 ? void 0 : _e.err) {\n let logMessages;\n try {\n const txInfo = await connection.getTransaction(signature, {\n maxSupportedTransactionVersion: 0,\n commitment: 'confirmed',\n });\n logMessages = (_f = txInfo === null || txInfo === void 0 ? void 0 : txInfo.meta) === null || _f === void 0 ? void 0 : _f.logMessages;\n }\n catch (_j) {\n // Log retrieval is diagnostic only; the on-chain error is the verdict.\n }\n const errorMessage = logMessages ? JSON.stringify(logMessages) : JSON.stringify(confirmation.value.err);\n throw new Error(`Transaction failed: ${errorMessage}`);\n }\n return {\n outcome: 'confirmed',\n lane: 'solana',\n transactionSignature: signature,\n signedTransaction,\n fence,\n confirmationContextSlot: (_h = (_g = confirmation.context) === null || _g === void 0 ? void 0 : _g.slot) !== null && _h !== void 0 ? _h : 0,\n };\n}\n"],"names":["Buffer"],"mappings":";;;;;AAEA,MAAM,eAAe,GAAG,4DAA4D;AACpF;AACA;AACA;AACA;AACA;AACA,SAAS,YAAY,CAAC,KAAK,EAAE;AAC7B,IAAI,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;AAC1B,QAAQ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AAC,GAAG,EAAE,CAAC,WAAW;AAChJ,QAAQ;AACR,QAAQ,OAAO,EAAE,EAAE;AACnB;AACA,QAAQ;AACR,QAAQ,MAAM,YAAY,GAAG,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC;AAC/G,QAAQ,MAAM,IAAI,KAAK,CAAC,CAAC,oBAAoB,EAAE,YAAY,CAAC,CAAC,CAAC;AAC9D,IAAI;AACJ,IAAI,OAAO;AACX,QAAQ,OAAO,EAAE,WAAW;AAC5B,QAAQ,IAAI,EAAE,QAAQ;AACtB,QAAQ,oBAAoB,EAAE,SAAS;AACvC,QAAQ,iBAAiB;AACzB,QAAQ,KAAK;AACb,QAAQ,uBAAuB,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,YAAY,CAAC,OAAO,MAAM,IAAI,IAAI,EAAE,KAAK,MAAM,GAAG,MAAM,GAAG,EAAE,CAAC,IAAI,MAAM,IAAI,IAAI,EAAE,KAAK,MAAM,GAAG,EAAE,GAAG,CAAC;AACnJ,KAAK;AACL;;;;"}
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-DlJKTmRv.js');
3
+ var index = require('./index-yT8ZfzrL.js');
4
4
  require('axios');
5
5
  require('tweetnacl');
6
6
  require('reconnecting-websocket');
@@ -95,11 +95,36 @@ const BOUNDED_PROGRAM_MAINNET = ['open', 'Tv7fbpYSseNHYmCZFZ1CZgj4r8D9fKNgEz1qo6
95
95
  const BOUNDED_PROGRAM_DEVNET = ['open', 'Tv7fbpYSseNHYmCZFZ1CZgj4r8D9fKNgEz1qo6F'].join('');
96
96
  const COMPUTE_BUDGET_PROGRAM = 'ComputeBudget111111111111111111111111111111';
97
97
  const SYSTEM_PROGRAM_ID = '11111111111111111111111111111111';
98
+ // SPL Associated Token program and the two SPL Token programs it may create an
99
+ // account under. The server builder compiles idempotent ATA-create setup
100
+ // instructions ahead of the Bounded write for every ATA-creating plugin.
101
+ const ASSOCIATED_TOKEN_PROGRAM_ID = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL';
102
+ const TOKEN_PROGRAM_ID = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
103
+ const TOKEN_2022_PROGRAM_ID = 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb';
104
+ const SPL_TOKEN_PROGRAM_IDS = new Set([TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID]);
105
+ // Idempotent ATA create carries a single instruction byte 0x01 (CreateIdempotent)
106
+ // and exactly six accounts: funding, ATA, owner, mint, system program, token
107
+ // program.
108
+ const ATA_CREATE_IDEMPOTENT_DISCRIMINATOR = 1;
109
+ const ATA_CREATE_ACCOUNT_COUNT = 6;
110
+ // System Program `transfer` is instruction index 2 (u32 LE) followed by a u64
111
+ // lamports amount: a 12-byte data payload over exactly two accounts.
112
+ const SYSTEM_TRANSFER_INSTRUCTION_INDEX = 2;
113
+ const SYSTEM_TRANSFER_DATA_LENGTH = 12;
114
+ const SYSTEM_TRANSFER_ACCOUNT_COUNT = 2;
115
+ // Gas-sponsorship top-up cap. Mirrors the server builder's ATA-inclusive
116
+ // absolute maximum (0.05 SOL); the fee payer (the gas sponsor) can only move its
117
+ // OWN lamports up to this bound, and only to a co-signing account.
118
+ const SPONSOR_TOPUP_MAX_LAMPORTS = BigInt(50000000);
119
+ // The four setup/write programs a server-built transaction may reference. System
120
+ // and Associated-Token are typed-validated per instruction below; a bare
121
+ // presence in this set is NOT sufficient authorization.
98
122
  const ALLOWED_SERVER_TX_PROGRAMS = new Set([
99
123
  BOUNDED_PROGRAM_MAINNET,
100
124
  BOUNDED_PROGRAM_DEVNET,
101
125
  COMPUTE_BUDGET_PROGRAM,
102
126
  SYSTEM_PROGRAM_ID,
127
+ ASSOCIATED_TOKEN_PROGRAM_ID,
103
128
  ]);
104
129
  // Canonical set_documents discriminator (single wire format: ra_indices Vec<u8>).
105
130
  const SET_DOCUMENTS_DISCRIMINATOR = '79,46,72,73,24,79,66,245';
@@ -210,11 +235,97 @@ function assertSamePathSet(label, expectedPaths, actualPaths) {
210
235
  throw new Error(`${label} Bounded instruction paths do not match requested write paths (${details})`);
211
236
  }
212
237
  }
213
- function deserializeAndValidateServerTransaction(serializedTransaction, VersionedTransactionClass, options) {
238
+ /** Read a little-endian u64 as a BigInt (lamport amounts can exceed 2^53). */
239
+ function readU64LE(bytes, offset) {
240
+ let value = BigInt(0);
241
+ for (let i = 0; i < 8; i++)
242
+ value |= BigInt(bytes[offset + i]) << BigInt(8 * i);
243
+ return value;
244
+ }
245
+ /**
246
+ * Resolve an instruction's referenced account keys against the transaction's
247
+ * STATIC key list. A setup instruction that reaches into an address-lookup
248
+ * table for any account it needs cannot be validated offline, so it fails
249
+ * closed: every index must resolve to a static key.
250
+ */
251
+ function resolveInstructionAccounts(ix, accountKeys, label) {
252
+ return ix.accountKeyIndexes.map(index => {
253
+ if (index >= accountKeys.length) {
254
+ throw new Error(`${label} setup instruction references an address-lookup-table account (not allowed)`);
255
+ }
256
+ return accountKeys[index];
257
+ });
258
+ }
259
+ /**
260
+ * A server-built idempotent ATA create is authorized ONLY when it is exactly the
261
+ * canonical shape: instruction byte 0x01, six accounts, funded by the
262
+ * transaction fee payer, over the System and an SPL Token program, and where the
263
+ * account being created recomputes to the associated-token-account PDA of its
264
+ * stated owner and mint. Nothing else - no arbitrary account create - passes.
265
+ */
266
+ function validateIdempotentAtaCreate(ix, data, accountKeys, feePayer, PublicKeyCtor, label) {
267
+ if (data.length !== 1 || data[0] !== ATA_CREATE_IDEMPOTENT_DISCRIMINATOR) {
268
+ throw new Error(`${label} contains a non-idempotent or malformed associated-token-account instruction`);
269
+ }
270
+ if (ix.accountKeyIndexes.length !== ATA_CREATE_ACCOUNT_COUNT) {
271
+ throw new Error(`${label} associated-token-account create has an unexpected account layout`);
272
+ }
273
+ const [funding, ata, owner, mint, systemProgram, tokenProgram] = resolveInstructionAccounts(ix, accountKeys, label);
274
+ if (!funding.equals(feePayer)) {
275
+ throw new Error(`${label} associated-token-account create is not funded by the transaction fee payer`);
276
+ }
277
+ if (systemProgram.toBase58() !== SYSTEM_PROGRAM_ID) {
278
+ throw new Error(`${label} associated-token-account create references an unexpected system program`);
279
+ }
280
+ if (!SPL_TOKEN_PROGRAM_IDS.has(tokenProgram.toBase58())) {
281
+ throw new Error(`${label} associated-token-account create references an unexpected token program`);
282
+ }
283
+ const [expectedAta] = PublicKeyCtor.findProgramAddressSync([owner.toBuffer(), tokenProgram.toBuffer(), mint.toBuffer()], new PublicKeyCtor(ASSOCIATED_TOKEN_PROGRAM_ID));
284
+ if (!ata.equals(expectedAta)) {
285
+ throw new Error(`${label} associated-token-account create does not derive the canonical account for its owner and mint`);
286
+ }
287
+ }
288
+ /**
289
+ * A server-built System Program instruction is authorized ONLY as the gas
290
+ * sponsor's top-up: a `transfer` FROM the transaction fee payer (the sponsor),
291
+ * capped at the sponsorship maximum, TO a co-signing account (the sponsored
292
+ * user). The fee payer can therefore only move its OWN lamports, bounded, and
293
+ * only to an account that itself signed the transaction - never a drain to an
294
+ * arbitrary address. Every other System instruction (createAccount, an
295
+ * uncapped or misdirected transfer, ...) is rejected.
296
+ */
297
+ function validateSponsorTransfer(ix, data, accountKeys, feePayer, isAccountSigner, label) {
298
+ const isTransfer = data.length === SYSTEM_TRANSFER_DATA_LENGTH &&
299
+ (data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24)) === SYSTEM_TRANSFER_INSTRUCTION_INDEX;
300
+ if (!isTransfer) {
301
+ throw new Error(`${label} contains an unauthorized System Program instruction`);
302
+ }
303
+ if (ix.accountKeyIndexes.length !== SYSTEM_TRANSFER_ACCOUNT_COUNT) {
304
+ throw new Error(`${label} contains an unauthorized System Program instruction`);
305
+ }
306
+ const [from, to] = resolveInstructionAccounts(ix, accountKeys, label);
307
+ if (!from.equals(feePayer)) {
308
+ throw new Error(`${label} System Program transfer must originate from the transaction fee payer (gas sponsor)`);
309
+ }
310
+ const lamports = readU64LE(data, 4);
311
+ if (lamports > SPONSOR_TOPUP_MAX_LAMPORTS) {
312
+ throw new Error(`${label} System Program transfer exceeds the gas-sponsorship cap`);
313
+ }
314
+ const recipientIndex = ix.accountKeyIndexes[1];
315
+ if (!isAccountSigner(recipientIndex) || to.equals(feePayer)) {
316
+ throw new Error(`${label} System Program transfer recipient must be a co-signing sponsored account`);
317
+ }
318
+ }
319
+ function deserializeAndValidateServerTransaction(serializedTransaction, web3, options) {
214
320
  var _a;
321
+ const { VersionedTransaction: VersionedTransactionClass, PublicKey: PublicKeyCtor } = web3;
215
322
  const transaction = VersionedTransactionClass.deserialize(index.bufferExports.Buffer.from(serializedTransaction, 'base64'));
216
323
  const { label, expectedAppId, expectedWritePaths } = options;
217
324
  const accountKeys = transaction.message.staticAccountKeys;
325
+ if (accountKeys.length === 0)
326
+ throw new Error(`${label} has no static account keys`);
327
+ const feePayer = accountKeys[0];
328
+ const isAccountSigner = (index) => transaction.message.isAccountSigner(index);
218
329
  let boundedInstructionCount = 0;
219
330
  const actualWritePaths = [];
220
331
  for (const ix of transaction.message.compiledInstructions) {
@@ -224,9 +335,17 @@ function deserializeAndValidateServerTransaction(serializedTransaction, Versione
224
335
  if (!ALLOWED_SERVER_TX_PROGRAMS.has(programId))
225
336
  throw new Error(`${label} contains unauthorized program: ${programId}`);
226
337
  const data = ix.data instanceof Uint8Array ? ix.data : index.bufferExports.Buffer.from((_a = ix.data) !== null && _a !== void 0 ? _a : []);
227
- if (programId === SYSTEM_PROGRAM_ID)
228
- throw new Error(`${label} contains unauthorized System Program instruction`);
229
- if (programId === BOUNDED_PROGRAM_MAINNET || programId === BOUNDED_PROGRAM_DEVNET) {
338
+ // Typed setup checks replace the old blanket System-Program ban: each of the
339
+ // two setup shapes the server builder emits (idempotent ATA create, gas
340
+ // sponsor top-up) is bound to recompute to the values this write needs, and
341
+ // anything else fails closed.
342
+ if (programId === SYSTEM_PROGRAM_ID) {
343
+ validateSponsorTransfer(ix, data, accountKeys, feePayer, isAccountSigner, label);
344
+ }
345
+ else if (programId === ASSOCIATED_TOKEN_PROGRAM_ID) {
346
+ validateIdempotentAtaCreate(ix, data, accountKeys, feePayer, PublicKeyCtor, label);
347
+ }
348
+ else if (programId === BOUNDED_PROGRAM_MAINNET || programId === BOUNDED_PROGRAM_DEVNET) {
230
349
  boundedInstructionCount++;
231
350
  const parsed = parseBoundedSetDocumentsInstruction(data, label);
232
351
  if (parsed.appId !== expectedAppId)
@@ -241,11 +360,11 @@ function deserializeAndValidateServerTransaction(serializedTransaction, Versione
241
360
  }
242
361
  async function handlePreBuiltTransaction(tx, authProvider, options, expectedWritePaths) {
243
362
  var _a, _b, _c, _d, _e, _f, _g, _h;
244
- const { Connection, VersionedTransaction } = await import('@solana/web3.js');
363
+ const { Connection, VersionedTransaction, PublicKey } = await import('@solana/web3.js');
245
364
  // Honor a wallet client's immutable config snapshot for the expected app-id
246
365
  // binding and RPC endpoint (CTA-05); otherwise read the global init() config.
247
366
  const config = (_b = (_a = options === null || options === void 0 ? void 0 : options._overrides) === null || _a === void 0 ? void 0 : _a._config) !== null && _b !== void 0 ? _b : await index.getConfig();
248
- const transaction = deserializeAndValidateServerTransaction(tx.serializedTransaction, VersionedTransaction, {
367
+ const transaction = deserializeAndValidateServerTransaction(tx.serializedTransaction, { VersionedTransaction, PublicKey }, {
249
368
  label: 'Pre-built transaction', expectedAppId: config.appId, expectedWritePaths,
250
369
  });
251
370
  const shouldSubmit = (options === null || options === void 0 ? void 0 : options.shouldSubmitTx) !== false;
@@ -336,4 +455,4 @@ async function handlePreBuiltTransaction(tx, authProvider, options, expectedWrit
336
455
  exports.deriveTransactionSignature = deriveTransactionSignature;
337
456
  exports.handlePreBuiltTransaction = handlePreBuiltTransaction;
338
457
  exports.isDefinitiveSolanaSendFailure = isDefinitiveSolanaSendFailure;
339
- //# sourceMappingURL=solana-operations-DPul1dWo.js.map
458
+ //# sourceMappingURL=solana-operations-DGEGqFd9.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solana-operations-DGEGqFd9.js","sources":["../.rollup-tmp/client/solana-operations.js"],"sourcesContent":["import { Buffer } from 'buffer';\nimport { getConfig } from './config';\nconst BASE58_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';\n/**\n * Minimal base58 encoder, used ONLY to derive a Solana transaction signature\n * from already-signed bytes. Core deliberately does not take a `bs58`\n * dependency for eighteen lines of arithmetic.\n */\nfunction encodeBase58(bytes) {\n if (bytes.length === 0)\n return '';\n const digits = [0];\n for (const byte of bytes) {\n let carry = byte;\n for (let i = 0; i < digits.length; i++) {\n carry += digits[i] << 8;\n digits[i] = carry % 58;\n carry = (carry / 58) | 0;\n }\n while (carry > 0) {\n digits.push(carry % 58);\n carry = (carry / 58) | 0;\n }\n }\n let out = '';\n for (let i = 0; i < bytes.length && bytes[i] === 0; i++)\n out += BASE58_ALPHABET[0];\n for (let i = digits.length - 1; i >= 0; i--)\n out += BASE58_ALPHABET[digits[i]];\n return out;\n}\n/**\n * Derive the transaction signature from the SIGNED bytes, before broadcasting.\n *\n * Without this the signature is only learned when `sendRawTransaction` resolves,\n * so an RPC that accepted the bytes but whose response was lost throws with\n * nothing recorded — and a retry builds a DIFFERENT transaction that can land\n * beside the first.\n */\nexport function deriveTransactionSignature(signedTransaction) {\n var _a;\n const signature = (_a = signedTransaction.signatures) === null || _a === void 0 ? void 0 : _a[0];\n if (!signature || signature.length === 0) {\n throw new Error('Signed Solana transaction carries no signature to broadcast');\n }\n if (signature.every(byte => byte === 0)) {\n throw new Error('Signed Solana transaction carries an empty fee-payer signature');\n }\n return encodeBase58(Uint8Array.from(signature));\n}\n/**\n * Whether a send failure PROVES the transaction was never accepted. A preflight\n * rejection, a signature-verification failure, or an oversized/invalid\n * transaction is definitive and keeps throwing. A transport failure (timeout,\n * socket reset, aborted fetch) is ambiguous — the node may hold the bytes — and\n * must resolve as `submitted` carrying the pre-derived signature.\n *\n * \"already processed\" is deliberately NOT definitive: it means the signature\n * landed, which is the opposite of a failure.\n */\nconst DEFINITIVE_SEND_FAILURE_MARKERS = [\n 'simulation failed',\n 'preflight',\n 'blockhash not found',\n 'signature verification failure',\n 'transaction too large',\n 'invalid transaction',\n 'insufficient funds for rent',\n 'attempt to debit an account but found no record of a prior credit',\n];\nexport function isDefinitiveSolanaSendFailure(error) {\n var _a, _b, _c;\n const err = error;\n if (err && Array.isArray(err.logs))\n return true;\n if (err && String((_a = err.name) !== null && _a !== void 0 ? _a : '') === 'SendTransactionError')\n return true;\n const message = String((_c = (_b = err === null || err === void 0 ? void 0 : err.message) !== null && _b !== void 0 ? _b : err) !== null && _c !== void 0 ? _c : '').toLowerCase();\n if (!message)\n return false;\n if (message.includes('already been processed') || message.includes('already processed'))\n return false;\n return DEFINITIVE_SEND_FAILURE_MARKERS.some(marker => message.includes(marker));\n}\nfunction errorText(error) {\n const message = error === null || error === void 0 ? void 0 : error.message;\n return typeof message === 'string' && message.length > 0 ? message : String(error);\n}\nconst BOUNDED_PROGRAM_MAINNET = ['open', 'Tv7fbpYSseNHYmCZFZ1CZgj4r8D9fKNgEz1qo6F'].join('');\nconst BOUNDED_PROGRAM_DEVNET = ['open', 'Tv7fbpYSseNHYmCZFZ1CZgj4r8D9fKNgEz1qo6F'].join('');\nconst COMPUTE_BUDGET_PROGRAM = 'ComputeBudget111111111111111111111111111111';\nconst SYSTEM_PROGRAM_ID = '11111111111111111111111111111111';\n// SPL Associated Token program and the two SPL Token programs it may create an\n// account under. The server builder compiles idempotent ATA-create setup\n// instructions ahead of the Bounded write for every ATA-creating plugin.\nconst ASSOCIATED_TOKEN_PROGRAM_ID = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL';\nconst TOKEN_PROGRAM_ID = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';\nconst TOKEN_2022_PROGRAM_ID = 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb';\nconst SPL_TOKEN_PROGRAM_IDS = new Set([TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID]);\n// Idempotent ATA create carries a single instruction byte 0x01 (CreateIdempotent)\n// and exactly six accounts: funding, ATA, owner, mint, system program, token\n// program.\nconst ATA_CREATE_IDEMPOTENT_DISCRIMINATOR = 1;\nconst ATA_CREATE_ACCOUNT_COUNT = 6;\n// System Program `transfer` is instruction index 2 (u32 LE) followed by a u64\n// lamports amount: a 12-byte data payload over exactly two accounts.\nconst SYSTEM_TRANSFER_INSTRUCTION_INDEX = 2;\nconst SYSTEM_TRANSFER_DATA_LENGTH = 12;\nconst SYSTEM_TRANSFER_ACCOUNT_COUNT = 2;\n// Gas-sponsorship top-up cap. Mirrors the server builder's ATA-inclusive\n// absolute maximum (0.05 SOL); the fee payer (the gas sponsor) can only move its\n// OWN lamports up to this bound, and only to a co-signing account.\nconst SPONSOR_TOPUP_MAX_LAMPORTS = BigInt(50000000);\n// The four setup/write programs a server-built transaction may reference. System\n// and Associated-Token are typed-validated per instruction below; a bare\n// presence in this set is NOT sufficient authorization.\nconst ALLOWED_SERVER_TX_PROGRAMS = new Set([\n BOUNDED_PROGRAM_MAINNET,\n BOUNDED_PROGRAM_DEVNET,\n COMPUTE_BUDGET_PROGRAM,\n SYSTEM_PROGRAM_ID,\n ASSOCIATED_TOKEN_PROGRAM_ID,\n]);\n// Canonical set_documents discriminator (single wire format: ra_indices Vec<u8>).\nconst SET_DOCUMENTS_DISCRIMINATOR = '79,46,72,73,24,79,66,245';\nconst ALLOWED_BOUNDED_SET_DISCRIMINATORS = new Set([\n SET_DOCUMENTS_DISCRIMINATOR,\n]);\nclass BorshCursor {\n constructor(data, offset, label) {\n this.data = data;\n this.offset = offset;\n this.label = label;\n }\n requireBytes(length, field) {\n if (this.offset + length > this.data.length) {\n throw new Error(`${this.label} has malformed Bounded instruction data while reading ${field}`);\n }\n }\n readU8(field) { this.requireBytes(1, field); return this.data[this.offset++]; }\n readU32(field) {\n this.requireBytes(4, field);\n const value = this.data[this.offset] | (this.data[this.offset + 1] << 8) |\n (this.data[this.offset + 2] << 16) | (this.data[this.offset + 3] << 24);\n this.offset += 4;\n return value >>> 0;\n }\n skip(length, field) { this.requireBytes(length, field); this.offset += length; }\n readString(field) {\n const length = this.readU32(`${field} length`);\n this.requireBytes(length, field);\n const raw = this.data.slice(this.offset, this.offset + length);\n this.offset += length;\n return Buffer.from(raw).toString('utf8');\n }\n skipBytes(field) { this.skip(this.readU32(`${field} length`), field); }\n isAtEnd() { return this.offset === this.data.length; }\n}\nfunction skipBoundedFieldValue(cursor) {\n const option = cursor.readU8('operation value option');\n if (option === 0)\n return;\n if (option !== 1)\n throw new Error('Server transaction has malformed Bounded field value option');\n const variant = cursor.readU8('operation value variant');\n if (variant === 0 || variant === 1)\n cursor.skip(8, 'operation numeric value');\n else if (variant === 2)\n cursor.skip(1, 'operation bool value');\n else if (variant === 3)\n cursor.readString('operation string value');\n else if (variant === 4)\n cursor.skip(32, 'operation address value');\n else\n throw new Error(`Server transaction has unsupported Bounded field value variant: ${variant}`);\n}\nfunction normalizeOnchainPath(path) {\n let normalized = path.startsWith('/') ? path.slice(1) : path;\n if (normalized.endsWith('*') && normalized.length > 1)\n normalized = normalized.slice(0, -1);\n if (normalized.endsWith('/'))\n normalized = normalized.slice(0, -1);\n return normalized;\n}\nfunction parseBoundedSetDocumentsInstruction(data, label) {\n if (data.length < 8)\n throw new Error(`${label} has malformed Bounded instruction data`);\n const discriminator = Array.from(data.slice(0, 8)).join(',');\n if (!ALLOWED_BOUNDED_SET_DISCRIMINATORS.has(discriminator)) {\n throw new Error(`${label} contains unsupported Bounded instruction`);\n }\n const cursor = new BorshCursor(data, 8, label);\n const appId = cursor.readString('appId');\n const documentPaths = [];\n const documentCount = cursor.readU32('documents length');\n for (let i = 0; i < documentCount; i++) {\n documentPaths.push(normalizeOnchainPath(cursor.readString('document path')));\n const operationCount = cursor.readU32('operations length');\n for (let j = 0; j < operationCount; j++) {\n cursor.readString('operation key');\n skipBoundedFieldValue(cursor);\n cursor.skip(1, 'operation kind');\n }\n }\n const deletePaths = [];\n const deleteCount = cursor.readU32('delete paths length');\n for (let i = 0; i < deleteCount; i++)\n deletePaths.push(normalizeOnchainPath(cursor.readString('delete path')));\n const txDataCount = cursor.readU32('txData length');\n for (let i = 0; i < txDataCount; i++) {\n cursor.readString('txData plugin function key');\n cursor.skipBytes('txData bytes');\n cursor.skipBytes('txData raIndices');\n }\n const simulate = cursor.readU8('simulate');\n if (simulate !== 0 && simulate !== 1)\n throw new Error(`${label} has malformed Bounded simulate flag`);\n if (!cursor.isAtEnd())\n throw new Error(`${label} has trailing Bounded instruction data`);\n return { appId, documentPaths, deletePaths };\n}\nfunction assertSamePathSet(label, expectedPaths, actualPaths) {\n const expected = new Set(expectedPaths.map(normalizeOnchainPath).filter(Boolean));\n const actual = new Set(actualPaths.map(normalizeOnchainPath).filter(Boolean));\n const missing = [...expected].filter(path => !actual.has(path));\n const extra = [...actual].filter(path => !expected.has(path));\n if (missing.length || extra.length) {\n const details = [missing.length ? `missing paths: ${missing.join(', ')}` : '', extra.length ? `unexpected paths: ${extra.join(', ')}` : '']\n .filter(Boolean).join('; ');\n throw new Error(`${label} Bounded instruction paths do not match requested write paths (${details})`);\n }\n}\n/** Read a little-endian u64 as a BigInt (lamport amounts can exceed 2^53). */\nfunction readU64LE(bytes, offset) {\n let value = BigInt(0);\n for (let i = 0; i < 8; i++)\n value |= BigInt(bytes[offset + i]) << BigInt(8 * i);\n return value;\n}\n/**\n * Resolve an instruction's referenced account keys against the transaction's\n * STATIC key list. A setup instruction that reaches into an address-lookup\n * table for any account it needs cannot be validated offline, so it fails\n * closed: every index must resolve to a static key.\n */\nfunction resolveInstructionAccounts(ix, accountKeys, label) {\n return ix.accountKeyIndexes.map(index => {\n if (index >= accountKeys.length) {\n throw new Error(`${label} setup instruction references an address-lookup-table account (not allowed)`);\n }\n return accountKeys[index];\n });\n}\n/**\n * A server-built idempotent ATA create is authorized ONLY when it is exactly the\n * canonical shape: instruction byte 0x01, six accounts, funded by the\n * transaction fee payer, over the System and an SPL Token program, and where the\n * account being created recomputes to the associated-token-account PDA of its\n * stated owner and mint. Nothing else - no arbitrary account create - passes.\n */\nfunction validateIdempotentAtaCreate(ix, data, accountKeys, feePayer, PublicKeyCtor, label) {\n if (data.length !== 1 || data[0] !== ATA_CREATE_IDEMPOTENT_DISCRIMINATOR) {\n throw new Error(`${label} contains a non-idempotent or malformed associated-token-account instruction`);\n }\n if (ix.accountKeyIndexes.length !== ATA_CREATE_ACCOUNT_COUNT) {\n throw new Error(`${label} associated-token-account create has an unexpected account layout`);\n }\n const [funding, ata, owner, mint, systemProgram, tokenProgram] = resolveInstructionAccounts(ix, accountKeys, label);\n if (!funding.equals(feePayer)) {\n throw new Error(`${label} associated-token-account create is not funded by the transaction fee payer`);\n }\n if (systemProgram.toBase58() !== SYSTEM_PROGRAM_ID) {\n throw new Error(`${label} associated-token-account create references an unexpected system program`);\n }\n if (!SPL_TOKEN_PROGRAM_IDS.has(tokenProgram.toBase58())) {\n throw new Error(`${label} associated-token-account create references an unexpected token program`);\n }\n const [expectedAta] = PublicKeyCtor.findProgramAddressSync([owner.toBuffer(), tokenProgram.toBuffer(), mint.toBuffer()], new PublicKeyCtor(ASSOCIATED_TOKEN_PROGRAM_ID));\n if (!ata.equals(expectedAta)) {\n throw new Error(`${label} associated-token-account create does not derive the canonical account for its owner and mint`);\n }\n}\n/**\n * A server-built System Program instruction is authorized ONLY as the gas\n * sponsor's top-up: a `transfer` FROM the transaction fee payer (the sponsor),\n * capped at the sponsorship maximum, TO a co-signing account (the sponsored\n * user). The fee payer can therefore only move its OWN lamports, bounded, and\n * only to an account that itself signed the transaction - never a drain to an\n * arbitrary address. Every other System instruction (createAccount, an\n * uncapped or misdirected transfer, ...) is rejected.\n */\nfunction validateSponsorTransfer(ix, data, accountKeys, feePayer, isAccountSigner, label) {\n const isTransfer = data.length === SYSTEM_TRANSFER_DATA_LENGTH &&\n (data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24)) === SYSTEM_TRANSFER_INSTRUCTION_INDEX;\n if (!isTransfer) {\n throw new Error(`${label} contains an unauthorized System Program instruction`);\n }\n if (ix.accountKeyIndexes.length !== SYSTEM_TRANSFER_ACCOUNT_COUNT) {\n throw new Error(`${label} contains an unauthorized System Program instruction`);\n }\n const [from, to] = resolveInstructionAccounts(ix, accountKeys, label);\n if (!from.equals(feePayer)) {\n throw new Error(`${label} System Program transfer must originate from the transaction fee payer (gas sponsor)`);\n }\n const lamports = readU64LE(data, 4);\n if (lamports > SPONSOR_TOPUP_MAX_LAMPORTS) {\n throw new Error(`${label} System Program transfer exceeds the gas-sponsorship cap`);\n }\n const recipientIndex = ix.accountKeyIndexes[1];\n if (!isAccountSigner(recipientIndex) || to.equals(feePayer)) {\n throw new Error(`${label} System Program transfer recipient must be a co-signing sponsored account`);\n }\n}\nfunction deserializeAndValidateServerTransaction(serializedTransaction, web3, options) {\n var _a;\n const { VersionedTransaction: VersionedTransactionClass, PublicKey: PublicKeyCtor } = web3;\n const transaction = VersionedTransactionClass.deserialize(Buffer.from(serializedTransaction, 'base64'));\n const { label, expectedAppId, expectedWritePaths } = options;\n const accountKeys = transaction.message.staticAccountKeys;\n if (accountKeys.length === 0)\n throw new Error(`${label} has no static account keys`);\n const feePayer = accountKeys[0];\n const isAccountSigner = (index) => transaction.message.isAccountSigner(index);\n let boundedInstructionCount = 0;\n const actualWritePaths = [];\n for (const ix of transaction.message.compiledInstructions) {\n if (ix.programIdIndex >= accountKeys.length)\n throw new Error(`${label} has program ID in lookup table (not allowed)`);\n const programId = accountKeys[ix.programIdIndex].toBase58();\n if (!ALLOWED_SERVER_TX_PROGRAMS.has(programId))\n throw new Error(`${label} contains unauthorized program: ${programId}`);\n const data = ix.data instanceof Uint8Array ? ix.data : Buffer.from((_a = ix.data) !== null && _a !== void 0 ? _a : []);\n // Typed setup checks replace the old blanket System-Program ban: each of the\n // two setup shapes the server builder emits (idempotent ATA create, gas\n // sponsor top-up) is bound to recompute to the values this write needs, and\n // anything else fails closed.\n if (programId === SYSTEM_PROGRAM_ID) {\n validateSponsorTransfer(ix, data, accountKeys, feePayer, isAccountSigner, label);\n }\n else if (programId === ASSOCIATED_TOKEN_PROGRAM_ID) {\n validateIdempotentAtaCreate(ix, data, accountKeys, feePayer, PublicKeyCtor, label);\n }\n else if (programId === BOUNDED_PROGRAM_MAINNET || programId === BOUNDED_PROGRAM_DEVNET) {\n boundedInstructionCount++;\n const parsed = parseBoundedSetDocumentsInstruction(data, label);\n if (parsed.appId !== expectedAppId)\n throw new Error(`${label} Bounded instruction appId does not match configured appId`);\n actualWritePaths.push(...parsed.documentPaths, ...parsed.deletePaths);\n }\n }\n if (boundedInstructionCount !== 1)\n throw new Error(`${label} must contain exactly one Bounded set-documents instruction`);\n assertSamePathSet(label, expectedWritePaths, actualWritePaths);\n return transaction;\n}\nexport async function handlePreBuiltTransaction(tx, authProvider, options, expectedWritePaths) {\n var _a, _b, _c, _d, _e, _f, _g, _h;\n const { Connection, VersionedTransaction, PublicKey } = await import(\"@solana/web3.js\");\n // Honor a wallet client's immutable config snapshot for the expected app-id\n // binding and RPC endpoint (CTA-05); otherwise read the global init() config.\n const config = (_b = (_a = options === null || options === void 0 ? void 0 : options._overrides) === null || _a === void 0 ? void 0 : _a._config) !== null && _b !== void 0 ? _b : await getConfig();\n const transaction = deserializeAndValidateServerTransaction(tx.serializedTransaction, { VersionedTransaction, PublicKey }, {\n label: 'Pre-built transaction', expectedAppId: config.appId, expectedWritePaths,\n });\n const shouldSubmit = (options === null || options === void 0 ? void 0 : options.shouldSubmitTx) !== false;\n const rpcUrl = (_c = config.rpcUrl) === null || _c === void 0 ? void 0 : _c.trim();\n const injectedRpc = (_d = options === null || options === void 0 ? void 0 : options._overrides) === null || _d === void 0 ? void 0 : _d._solanaRpc;\n if (shouldSubmit && !rpcUrl && !injectedRpc) {\n throw new Error(`Pre-built Solana transaction submission requires init({ rpcUrl }) for ${tx.network}`);\n }\n const signedTx = await authProvider.signTransaction(transaction);\n const rawTx = signedTx.serialize();\n const signedTransaction = Buffer.from(rawTx).toString('base64');\n // Keep the worker's expiry fence instead of discarding it: it is what makes\n // bounded same-signature reconciliation (and therefore the retry-safe\n // `expired_not_landed` exit) possible at all.\n const fence = { blockhash: tx.blockhash, lastValidBlockHeight: tx.lastValidBlockHeight };\n if (!shouldSubmit) {\n // Signed and NOT sent. There is no signature and nothing to mirror.\n return { outcome: 'signed', lane: 'solana', transactionSignature: null, signedTransaction, fence };\n }\n // Derive the signature from the signed bytes BEFORE broadcasting, so a send\n // whose response is lost still yields a reconcilable identifier.\n const signature = deriveTransactionSignature(signedTx);\n const connection = injectedRpc !== null && injectedRpc !== void 0 ? injectedRpc : new Connection(rpcUrl, 'confirmed');\n try {\n await connection.sendRawTransaction(rawTx, { skipPreflight: false, maxRetries: 3 });\n }\n catch (error) {\n // A definitive rejection never entered the network — keep throwing.\n if (isDefinitiveSolanaSendFailure(error))\n throw error;\n // Ambiguous transport outcome: the node may hold these exact bytes. Report\n // the pre-derived signature so the caller reconciles it instead of building\n // a second transaction that could land beside the first.\n return {\n outcome: 'submitted',\n lane: 'solana',\n transactionSignature: signature,\n signedTransaction,\n fence,\n reason: `Broadcast response was lost or inconclusive: ${errorText(error)}`,\n };\n }\n let confirmation;\n try {\n confirmation = await connection.confirmTransaction({\n signature, blockhash: tx.blockhash, lastValidBlockHeight: tx.lastValidBlockHeight,\n }, 'confirmed');\n }\n catch (error) {\n // The bytes were accepted; only the confirmation outcome is unknown.\n return {\n outcome: 'submitted',\n lane: 'solana',\n transactionSignature: signature,\n signedTransaction,\n fence,\n reason: `Confirmation outcome unknown: ${errorText(error)}`,\n };\n }\n // #310: \"confirmed\" only means the network recorded the transaction, not that it\n // succeeded - a landed-but-failed transaction carries an err. Report it as a failure\n // (with on-chain logs) instead of a fake success, mirroring the server keypair provider.\n if ((_e = confirmation.value) === null || _e === void 0 ? void 0 : _e.err) {\n let logMessages;\n try {\n const txInfo = await connection.getTransaction(signature, {\n maxSupportedTransactionVersion: 0,\n commitment: 'confirmed',\n });\n logMessages = (_f = txInfo === null || txInfo === void 0 ? void 0 : txInfo.meta) === null || _f === void 0 ? void 0 : _f.logMessages;\n }\n catch (_j) {\n // Log retrieval is diagnostic only; the on-chain error is the verdict.\n }\n const errorMessage = logMessages ? JSON.stringify(logMessages) : JSON.stringify(confirmation.value.err);\n throw new Error(`Transaction failed: ${errorMessage}`);\n }\n return {\n outcome: 'confirmed',\n lane: 'solana',\n transactionSignature: signature,\n signedTransaction,\n fence,\n confirmationContextSlot: (_h = (_g = confirmation.context) === null || _g === void 0 ? void 0 : _g.slot) !== null && _h !== void 0 ? _h : 0,\n };\n}\n"],"names":["Buffer","getConfig"],"mappings":";;;;;;;AAEA,MAAM,eAAe,GAAG,4DAA4D;AACpF;AACA;AACA;AACA;AACA;AACA,SAAS,YAAY,CAAC,KAAK,EAAE;AAC7B,IAAI,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;AAC1B,QAAQ,OAAO,EAAE;AACjB,IAAI,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC;AACtB,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;AAC9B,QAAQ,IAAI,KAAK,GAAG,IAAI;AACxB,QAAQ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AAChD,YAAY,KAAK,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;AACnC,YAAY,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,EAAE;AAClC,YAAY,KAAK,GAAG,CAAC,KAAK,GAAG,EAAE,IAAI,CAAC;AACpC,QAAQ;AACR,QAAQ,OAAO,KAAK,GAAG,CAAC,EAAE;AAC1B,YAAY,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,uBAAuB,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,YAAY,CAAC,OAAO,MAAM,IAAI,IAAI,EAAE,KAAK,MAAM,GAAG,MAAM,GAAG,EAAE,CAAC,IAAI,MAAM,IAAI,IAAI,EAAE,KAAK,MAAM,GAAG,EAAE,GAAG,CAAC;AACnJ,KAAK;AACL;;;;;;"}
@@ -0,0 +1,9 @@
1
+ export declare function isDefinitiveRejection(err: unknown): boolean;
2
+ export declare const TRANSPORT_RETENTION_GRACE_MS: number;
3
+ /**
4
+ * May a session whose refresh failed WITHOUT a definitive rejection be kept?
5
+ *
6
+ * `expSeconds` is the id token's `exp` claim. Fails closed: a missing or
7
+ * non-numeric expiry is not a usable bound, so such a session is never retained.
8
+ */
9
+ export declare function mayRetainAfterTransportFailure(expSeconds: unknown, now?: number): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bounded-sh/core",
3
- "version": "0.0.69",
3
+ "version": "0.0.71",
4
4
  "description": "Shared client, data-plane, and transport primitives for Bounded, the full-stack app builder and runtime for AI-built apps: policy-enforced operations, files, functions, and realtime.",
5
5
  "homepage": "https://bounded.sh/docs/sdk",
6
6
  "main": "./dist/index.js",
@@ -16,7 +16,7 @@
16
16
  "scripts": {
17
17
  "build": "rm -rf ./dist ./.rollup-tmp && tsc -p tsconfig.build.json --outDir .rollup-tmp --declarationDir .rollup-tmp --emitDeclarationOnly false && rollup -c && tsc -p tsconfig.build.json --emitDeclarationOnly --declarationDir dist && rm -rf ./.rollup-tmp",
18
18
  "watch": "rollup -c -w",
19
- "test": "node src/client/run-config-network-test.mjs && node src/client/run-read-principal-test.mjs && node src/client/run-principal-collision-test.mjs && node src/client/run-abortable-read-test.mjs && node src/utils/run-api-abort-test.mjs && node src/utils/run-api-transient-get-retry-test.mjs && node src/utils/run-auth-api-issuer-switch-test.mjs && node src/utils/run-auth-api-server-credential-test.mjs && node src/utils/run-auth-api-revoke-test.mjs && node src/utils/run-session-manager-binding-test.mjs && node src/utils/run-web-session-manager-signout-test.mjs && node src/utils/run-auth-api-refresh-per-token-test.mjs && node src/utils/run-core-platform-encode-test.mjs && node src/utils/rn-session-manager-example.source.test.mjs && node src/utils/run-session-protocol-test.mjs && node src/utils/run-auth-token-freshness-test.mjs && node src/utils/run-api-401-recovery-test.mjs && node src/utils/run-server-session-manager-test.mjs && node src/utils/api-refresh-inflight-key.source.test.mjs && node src/client/run-row-shape-test.mjs && node src/client/run-transport-test.mjs && node src/client/run-queries-coalesce-test.mjs && node src/client/run-runexpression-overrides-test.mjs && node src/client/run-subscribe-query-test.mjs && node src/client/subscribe-query-defaults.source.test.mjs && node src/client/run-public-export-surface-test.mjs && node src/client/run-decline-cause-test.mjs && node src/client/run-live-auth-test.mjs && node src/client/run-live-view-principal-test.mjs && node src/client/run-subscription-auth-error-test.mjs && node src/client/run-subscription-confirmation-retry-test.mjs && node src/client/subscription-handoff-grace.source.test.mjs && node src/client/run-onchain-validation-test.mjs && node src/client/run-set-result-test.mjs && node src/client/run-reconcile-set-result-test.mjs && node src/client/run-set-file-result-test.mjs && node src/client/run-set-result-types-test.mjs && node src/utils/evm/run-evm-utils-test.mjs && node src/client/websocket-auth-url.test.mjs && node src/client/run-create-client-http-test.mjs && node src/client/run-create-client-subscribe-test.mjs && node src/client/run-wallet-config-binding-test.mjs && node src/client/run-functions-timeout-test.mjs && node src/run-user-address-nullable-test.mjs",
19
+ "test": "node src/client/run-config-network-test.mjs && node src/client/run-read-principal-test.mjs && node src/client/run-principal-collision-test.mjs && node src/client/run-abortable-read-test.mjs && node src/utils/run-api-abort-test.mjs && node src/utils/run-api-transient-get-retry-test.mjs && node src/utils/run-auth-api-issuer-switch-test.mjs && node src/utils/run-auth-api-server-credential-test.mjs && node src/utils/run-auth-api-revoke-test.mjs && node src/utils/run-session-manager-binding-test.mjs && node src/utils/run-web-session-manager-signout-test.mjs && node src/utils/run-web-session-manager-refresh-transport-test.mjs && node src/utils/refresh-error.source.test.mjs && node src/utils/run-auth-api-refresh-per-token-test.mjs && node src/utils/run-core-platform-encode-test.mjs && node src/utils/rn-session-manager-example.source.test.mjs && node src/utils/run-session-protocol-test.mjs && node src/utils/run-auth-token-freshness-test.mjs && node src/utils/run-api-401-recovery-test.mjs && node src/utils/run-server-session-manager-test.mjs && node src/utils/api-refresh-inflight-key.source.test.mjs && node src/client/run-row-shape-test.mjs && node src/client/run-transport-test.mjs && node src/client/run-queries-coalesce-test.mjs && node src/client/run-runexpression-overrides-test.mjs && node src/client/run-subscribe-query-test.mjs && node src/client/subscribe-query-defaults.source.test.mjs && node src/client/run-public-export-surface-test.mjs && node src/client/run-decline-cause-test.mjs && node src/client/run-live-auth-test.mjs && node src/client/run-live-view-principal-test.mjs && node src/client/run-subscription-auth-error-test.mjs && node src/client/run-subscription-confirmation-retry-test.mjs && node src/client/subscription-handoff-grace.source.test.mjs && node src/client/run-onchain-validation-test.mjs && node src/client/run-set-result-test.mjs && node src/client/run-reconcile-set-result-test.mjs && node src/client/run-set-file-result-test.mjs && node src/client/run-set-result-types-test.mjs && node src/utils/evm/run-evm-utils-test.mjs && node src/client/websocket-auth-url.test.mjs && node src/client/run-create-client-http-test.mjs && node src/client/run-create-client-subscribe-test.mjs && node src/client/run-wallet-config-binding-test.mjs && node src/client/run-functions-timeout-test.mjs && node src/run-user-address-nullable-test.mjs",
20
20
  "prepare": "npm run build"
21
21
  },
22
22
  "files": [