@pooflabs/core 0.0.47-rc1 → 0.0.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -3188,6 +3188,12 @@ async function genSolanaMessage(address, nonce) {
3188
3188
  // Serialization Helpers
3189
3189
  // ─────────────────────────────────────────────────────────────
3190
3190
  function isHexString(value) {
3191
+ // Only strings can be hex-encoded. Numbers, BNs, and other shapes coming back
3192
+ // from the API for u64Val/i64Val should fall through to `new BN(value)` which
3193
+ // accepts those shapes natively. Without this guard, calling .startsWith on a
3194
+ // non-string blows up with TypeError.
3195
+ if (typeof value !== "string")
3196
+ return false;
3191
3197
  // Matches strings containing only 0-9, a-f, or A-F (optionally prefixed with 0x)
3192
3198
  let testValue = value;
3193
3199
  // Handle negative values
@@ -3283,8 +3289,11 @@ async function buildSetDocumentsTransaction(connection, idl, anchorProvider, pay
3283
3289
  }
3284
3290
  else if (idl.address === "poof4b5pk1L9tmThvBmaABjcyjfhFGbMbQP5BXk2QZp") {
3285
3291
  const program = new Program(idl, anchorProvider);
3292
+ // Targets `set_documents_v2` (Vec<u8> ra_indices). The on-chain program
3293
+ // also exposes the legacy `set_documents` (Vec<u64>) so SDKs already on npm
3294
+ // continue to work — but new releases of this SDK speak v2 only.
3286
3295
  tx = await program.methods
3287
- .setDocuments(args.app_id, prepareAnchorArgs(args.documents), args.delete_paths, args.txData, simulate)
3296
+ .setDocumentsV2(args.app_id, prepareAnchorArgs(args.documents), args.delete_paths, args.txData, simulate)
3288
3297
  .preInstructions(instructions)
3289
3298
  .accounts({
3290
3299
  payer: payerPublicKey
@@ -3639,11 +3648,17 @@ async function makeApiRequest(method, urlPath, data, _overrides) {
3639
3648
  if (_overrides === null || _overrides === void 0 ? void 0 : _overrides.headers) {
3640
3649
  Object.assign(headers, _overrides.headers);
3641
3650
  }
3651
+ // Writes (PUT/POST/DELETE) can take significantly longer than reads —
3652
+ // server-side they may trigger ad-hoc LUT creation (create + extend +
3653
+ // wait-for-finalization, ~15-30s on mainnet). Use a larger default for
3654
+ // non-GET so the SDK doesn't time out before client-api responds.
3655
+ const isRead = method.toUpperCase() === "GET";
3656
+ const defaultTimeout = isRead ? 30000 : 90000;
3642
3657
  const requestConfig = {
3643
3658
  method,
3644
3659
  url: `${config.apiUrl}${urlPath.startsWith("/") ? urlPath : `/${urlPath}`}`,
3645
3660
  headers,
3646
- timeout: (_a = _overrides === null || _overrides === void 0 ? void 0 : _overrides.timeout) !== null && _a !== void 0 ? _a : 30000,
3661
+ timeout: (_a = _overrides === null || _overrides === void 0 ? void 0 : _overrides.timeout) !== null && _a !== void 0 ? _a : defaultTimeout,
3647
3662
  };
3648
3663
  if (method !== "GET" && method !== "get") {
3649
3664
  requestConfig.data = data ? JSON.stringify(data) : {};
@@ -4288,21 +4303,38 @@ async function setMany(many, options) {
4288
4303
  setDocumentData: tx.transactionArgs.setDocumentData,
4289
4304
  deletePaths: tx.transactionArgs.deletePaths,
4290
4305
  idl: tx.idl,
4291
- txData: (_b = (_a = tx.txData) === null || _a === void 0 ? void 0 : _a.map((txData) => {
4292
- var _a;
4293
- return ({
4294
- pluginFunctionKey: txData.pluginFunctionKey,
4295
- txData: bufferExports.Buffer.from(txData.txData),
4296
- raIndices: (_a = txData.raIndices) === null || _a === void 0 ? void 0 : _a.map((raIndex) => {
4297
- if (isHexString(raIndex)) {
4298
- return new BN(raIndex, "hex");
4306
+ txData: (_b = (_a = tx.txData) === null || _a === void 0 ? void 0 : _a.map((txData) => ({
4307
+ pluginFunctionKey: txData.pluginFunctionKey,
4308
+ txData: bufferExports.Buffer.from(txData.txData),
4309
+ // raIndices is Vec<u8> on-chain (serialized as Buffer/bytes). The server may send
4310
+ // it as a Buffer, a number[], a Uint8Array, or — over JSON — as Node's serialized
4311
+ // Buffer shape {type: "Buffer", data: number[]} (the default `JSON.stringify(buf)`
4312
+ // output). Normalise all of those to Buffer here. Each value must fit in u8 (matches
4313
+ // Solana's instruction-level account indexing); throw clearly if anything is out of range.
4314
+ raIndices: (() => {
4315
+ const raw = txData.raIndices;
4316
+ if (raw == null)
4317
+ return bufferExports.Buffer.alloc(0);
4318
+ if (bufferExports.Buffer.isBuffer(raw))
4319
+ return raw;
4320
+ if (raw instanceof Uint8Array)
4321
+ return bufferExports.Buffer.from(raw);
4322
+ // Node's JSON-serialised Buffer: {type: "Buffer", data: number[]}
4323
+ const arrayLike = Array.isArray(raw)
4324
+ ? raw
4325
+ : (raw && typeof raw === 'object' && Array.isArray(raw.data))
4326
+ ? raw.data
4327
+ : (() => { throw new Error(`raIndices has unexpected shape: ${typeof raw}`); })();
4328
+ const bytes = arrayLike.map((raIndex) => {
4329
+ const n = isHexString(raIndex) ? parseInt(raIndex, 16) : Number(raIndex);
4330
+ if (!Number.isInteger(n) || n < 0 || n > 255) {
4331
+ throw new Error(`raIndex ${raIndex} is not a valid u8 (must be integer in 0..255)`);
4299
4332
  }
4300
- else {
4301
- return new BN(raIndex);
4302
- }
4303
- }),
4304
- });
4305
- })) !== null && _b !== void 0 ? _b : [],
4333
+ return n;
4334
+ });
4335
+ return bufferExports.Buffer.from(bytes);
4336
+ })(),
4337
+ }))) !== null && _b !== void 0 ? _b : [],
4306
4338
  };
4307
4339
  const config = await getConfig();
4308
4340
  const solTransaction = {