@pooflabs/core 0.0.45 → 0.0.47

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
@@ -3166,6 +3166,12 @@ async function genSolanaMessage(address, nonce) {
3166
3166
  // Serialization Helpers
3167
3167
  // ─────────────────────────────────────────────────────────────
3168
3168
  function isHexString(value) {
3169
+ // Only strings can be hex-encoded. Numbers, BNs, and other shapes coming back
3170
+ // from the API for u64Val/i64Val should fall through to `new BN(value)` which
3171
+ // accepts those shapes natively. Without this guard, calling .startsWith on a
3172
+ // non-string blows up with TypeError.
3173
+ if (typeof value !== "string")
3174
+ return false;
3169
3175
  // Matches strings containing only 0-9, a-f, or A-F (optionally prefixed with 0x)
3170
3176
  let testValue = value;
3171
3177
  // Handle negative values
@@ -3261,8 +3267,11 @@ async function buildSetDocumentsTransaction(connection, idl, anchorProvider, pay
3261
3267
  }
3262
3268
  else if (idl.address === "poof4b5pk1L9tmThvBmaABjcyjfhFGbMbQP5BXk2QZp") {
3263
3269
  const program = new Program(idl, anchorProvider);
3270
+ // Targets `set_documents_v2` (Vec<u8> ra_indices). The on-chain program
3271
+ // also exposes the legacy `set_documents` (Vec<u64>) so SDKs already on npm
3272
+ // continue to work — but new releases of this SDK speak v2 only.
3264
3273
  tx = await program.methods
3265
- .setDocuments(args.app_id, prepareAnchorArgs(args.documents), args.delete_paths, args.txData, simulate)
3274
+ .setDocumentsV2(args.app_id, prepareAnchorArgs(args.documents), args.delete_paths, args.txData, simulate)
3266
3275
  .preInstructions(instructions)
3267
3276
  .accounts({
3268
3277
  payer: payerPublicKey
@@ -3617,11 +3626,17 @@ async function makeApiRequest(method, urlPath, data, _overrides) {
3617
3626
  if (_overrides === null || _overrides === void 0 ? void 0 : _overrides.headers) {
3618
3627
  Object.assign(headers, _overrides.headers);
3619
3628
  }
3629
+ // Writes (PUT/POST/DELETE) can take significantly longer than reads —
3630
+ // server-side they may trigger ad-hoc LUT creation (create + extend +
3631
+ // wait-for-finalization, ~15-30s on mainnet). Use a larger default for
3632
+ // non-GET so the SDK doesn't time out before client-api responds.
3633
+ const isRead = method.toUpperCase() === "GET";
3634
+ const defaultTimeout = isRead ? 30000 : 90000;
3620
3635
  const requestConfig = {
3621
3636
  method,
3622
3637
  url: `${config.apiUrl}${urlPath.startsWith("/") ? urlPath : `/${urlPath}`}`,
3623
3638
  headers,
3624
- timeout: (_a = _overrides === null || _overrides === void 0 ? void 0 : _overrides.timeout) !== null && _a !== void 0 ? _a : 30000,
3639
+ timeout: (_a = _overrides === null || _overrides === void 0 ? void 0 : _overrides.timeout) !== null && _a !== void 0 ? _a : defaultTimeout,
3625
3640
  };
3626
3641
  if (method !== "GET" && method !== "get") {
3627
3642
  requestConfig.data = data ? JSON.stringify(data) : {};
@@ -4266,21 +4281,38 @@ async function setMany(many, options) {
4266
4281
  setDocumentData: tx.transactionArgs.setDocumentData,
4267
4282
  deletePaths: tx.transactionArgs.deletePaths,
4268
4283
  idl: tx.idl,
4269
- txData: (_b = (_a = tx.txData) === null || _a === void 0 ? void 0 : _a.map((txData) => {
4270
- var _a;
4271
- return ({
4272
- pluginFunctionKey: txData.pluginFunctionKey,
4273
- txData: bufferExports.Buffer.from(txData.txData),
4274
- raIndices: (_a = txData.raIndices) === null || _a === void 0 ? void 0 : _a.map((raIndex) => {
4275
- if (isHexString(raIndex)) {
4276
- return new BN(raIndex, "hex");
4284
+ txData: (_b = (_a = tx.txData) === null || _a === void 0 ? void 0 : _a.map((txData) => ({
4285
+ pluginFunctionKey: txData.pluginFunctionKey,
4286
+ txData: bufferExports.Buffer.from(txData.txData),
4287
+ // raIndices is Vec<u8> on-chain (serialized as Buffer/bytes). The server may send
4288
+ // it as a Buffer, a number[], a Uint8Array, or — over JSON — as Node's serialized
4289
+ // Buffer shape {type: "Buffer", data: number[]} (the default `JSON.stringify(buf)`
4290
+ // output). Normalise all of those to Buffer here. Each value must fit in u8 (matches
4291
+ // Solana's instruction-level account indexing); throw clearly if anything is out of range.
4292
+ raIndices: (() => {
4293
+ const raw = txData.raIndices;
4294
+ if (raw == null)
4295
+ return bufferExports.Buffer.alloc(0);
4296
+ if (bufferExports.Buffer.isBuffer(raw))
4297
+ return raw;
4298
+ if (raw instanceof Uint8Array)
4299
+ return bufferExports.Buffer.from(raw);
4300
+ // Node's JSON-serialised Buffer: {type: "Buffer", data: number[]}
4301
+ const arrayLike = Array.isArray(raw)
4302
+ ? raw
4303
+ : (raw && typeof raw === 'object' && Array.isArray(raw.data))
4304
+ ? raw.data
4305
+ : (() => { throw new Error(`raIndices has unexpected shape: ${typeof raw}`); })();
4306
+ const bytes = arrayLike.map((raIndex) => {
4307
+ const n = isHexString(raIndex) ? parseInt(raIndex, 16) : Number(raIndex);
4308
+ if (!Number.isInteger(n) || n < 0 || n > 255) {
4309
+ throw new Error(`raIndex ${raIndex} is not a valid u8 (must be integer in 0..255)`);
4277
4310
  }
4278
- else {
4279
- return new BN(raIndex);
4280
- }
4281
- }),
4282
- });
4283
- })) !== null && _b !== void 0 ? _b : [],
4311
+ return n;
4312
+ });
4313
+ return bufferExports.Buffer.from(bytes);
4314
+ })(),
4315
+ }))) !== null && _b !== void 0 ? _b : [],
4284
4316
  };
4285
4317
  const config = await getConfig();
4286
4318
  const solTransaction = {