@blockrun/llm 3.8.4 → 3.9.0

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.cjs CHANGED
@@ -564,7 +564,7 @@ function getCostSummary() {
564
564
  }
565
565
 
566
566
  // src/version.ts
567
- var SDK_VERSION = "3.8.4";
567
+ var SDK_VERSION = "3.9.0";
568
568
  var USER_AGENT = `blockrun-ts/${SDK_VERSION}`;
569
569
 
570
570
  // src/client.ts
@@ -4903,16 +4903,51 @@ async function createSolanaWallet() {
4903
4903
  };
4904
4904
  }
4905
4905
  async function solanaKeyToBytes(privateKey) {
4906
+ const key = privateKey.trim();
4907
+ if (key.startsWith("[")) {
4908
+ let parsed;
4909
+ try {
4910
+ parsed = JSON.parse(key);
4911
+ } catch {
4912
+ throw new Error(
4913
+ "Invalid Solana private key: looks like a JSON byte array but is not valid JSON"
4914
+ );
4915
+ }
4916
+ if (!Array.isArray(parsed) || !parsed.every((n) => Number.isInteger(n) && n >= 0 && n <= 255)) {
4917
+ throw new Error(
4918
+ "Invalid Solana private key: JSON array must contain only byte values (0-255)"
4919
+ );
4920
+ }
4921
+ if (parsed.length !== 64) {
4922
+ throw new Error(
4923
+ `Invalid Solana key length: expected 64 bytes, got ${parsed.length}`
4924
+ );
4925
+ }
4926
+ return Uint8Array.from(parsed);
4927
+ }
4928
+ const hex = key.startsWith("0x") || key.startsWith("0X") ? key.slice(2) : key;
4929
+ if (/^[0-9a-fA-F]+$/.test(hex) && (hex.length === 64 || hex.length === 128)) {
4930
+ if (hex.length === 64) {
4931
+ throw new Error(
4932
+ "Invalid Solana private key: this is a 32-byte hex key \u2014 the EVM (Base) wallet format, not a Solana key. Solana keys are 64 bytes, usually base58-encoded (86-88 characters)."
4933
+ );
4934
+ }
4935
+ const bytes = new Uint8Array(64);
4936
+ for (let i = 0; i < 64; i++) bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
4937
+ return bytes;
4938
+ }
4906
4939
  try {
4907
4940
  const bs58 = await import("bs58");
4908
- const bytes = (bs58.default ?? bs58).decode(privateKey);
4941
+ const bytes = (bs58.default ?? bs58).decode(key);
4909
4942
  if (bytes.length !== 64) {
4910
4943
  throw new Error(`Invalid Solana key length: expected 64 bytes, got ${bytes.length}`);
4911
4944
  }
4912
4945
  return bytes;
4913
4946
  } catch (err) {
4914
4947
  const msg = err instanceof Error ? err.message : String(err);
4915
- throw new Error(`Invalid Solana private key: ${msg}`);
4948
+ throw new Error(
4949
+ `Invalid Solana private key: ${msg}. Expected a base58-encoded 64-byte key (standard Solana format), a 64-byte hex string, or a Solana CLI JSON byte array.`
4950
+ );
4916
4951
  }
4917
4952
  }
4918
4953
  async function solanaPublicKey(privateKey) {
@@ -5052,16 +5087,27 @@ Your current wallet is backed up first. You can also set
5052
5087
  SOLANA_WALLET_KEY=<private-key> for a single run without changing anything.
5053
5088
  `;
5054
5089
  }
5090
+ async function solanaPublicKeyFrom(privateKey, source) {
5091
+ try {
5092
+ return await solanaPublicKey(privateKey);
5093
+ } catch (err) {
5094
+ const msg = err instanceof Error ? err.message : String(err);
5095
+ throw new Error(`${msg} (key loaded from ${source})`);
5096
+ }
5097
+ }
5055
5098
  async function getOrCreateSolanaWallet() {
5056
5099
  const envKey = typeof process !== "undefined" && process.env ? process.env.SOLANA_WALLET_KEY : void 0;
5057
5100
  if (envKey) {
5058
- const address2 = await solanaPublicKey(envKey);
5101
+ const address2 = await solanaPublicKeyFrom(
5102
+ envKey,
5103
+ "the SOLANA_WALLET_KEY environment variable"
5104
+ );
5059
5105
  return { privateKey: envKey, address: address2, isNew: false };
5060
5106
  }
5061
5107
  if (fs3.existsSync(SOLANA_WALLET_FILE)) {
5062
5108
  const fileKey = fs3.readFileSync(SOLANA_WALLET_FILE, "utf-8").trim();
5063
5109
  if (fileKey) {
5064
- const address2 = await solanaPublicKey(fileKey);
5110
+ const address2 = await solanaPublicKeyFrom(fileKey, SOLANA_WALLET_FILE);
5065
5111
  return { privateKey: fileKey, address: address2, isNew: false };
5066
5112
  }
5067
5113
  }
package/dist/index.d.cts CHANGED
@@ -2860,8 +2860,11 @@ declare function createSolanaWallet(): Promise<{
2860
2860
  privateKey: string;
2861
2861
  }>;
2862
2862
  /**
2863
- * Convert a bs58 private key string to Uint8Array (64 bytes).
2864
- * Accepts: bs58-encoded 64-byte key (standard Solana format).
2863
+ * Convert a Solana private key string to Uint8Array (64 bytes).
2864
+ * Accepts: bs58-encoded 64-byte key (standard Solana format), the Solana CLI
2865
+ * JSON byte-array format (~/.config/solana/id.json), or a 64-byte hex string
2866
+ * (with or without 0x). A 32-byte hex key is rejected with an explicit hint
2867
+ * that it is the EVM (Base) wallet format, not a Solana key.
2865
2868
  */
2866
2869
  declare function solanaKeyToBytes(privateKey: string): Promise<Uint8Array>;
2867
2870
  /**
package/dist/index.d.ts CHANGED
@@ -2860,8 +2860,11 @@ declare function createSolanaWallet(): Promise<{
2860
2860
  privateKey: string;
2861
2861
  }>;
2862
2862
  /**
2863
- * Convert a bs58 private key string to Uint8Array (64 bytes).
2864
- * Accepts: bs58-encoded 64-byte key (standard Solana format).
2863
+ * Convert a Solana private key string to Uint8Array (64 bytes).
2864
+ * Accepts: bs58-encoded 64-byte key (standard Solana format), the Solana CLI
2865
+ * JSON byte-array format (~/.config/solana/id.json), or a 64-byte hex string
2866
+ * (with or without 0x). A 32-byte hex key is rejected with an explicit hint
2867
+ * that it is the EVM (Base) wallet format, not a Solana key.
2865
2868
  */
2866
2869
  declare function solanaKeyToBytes(privateKey: string): Promise<Uint8Array>;
2867
2870
  /**
package/dist/index.js CHANGED
@@ -451,7 +451,7 @@ function getCostSummary() {
451
451
  }
452
452
 
453
453
  // src/version.ts
454
- var SDK_VERSION = "3.8.4";
454
+ var SDK_VERSION = "3.9.0";
455
455
  var USER_AGENT = `blockrun-ts/${SDK_VERSION}`;
456
456
 
457
457
  // src/client.ts
@@ -4790,16 +4790,51 @@ async function createSolanaWallet() {
4790
4790
  };
4791
4791
  }
4792
4792
  async function solanaKeyToBytes(privateKey) {
4793
+ const key = privateKey.trim();
4794
+ if (key.startsWith("[")) {
4795
+ let parsed;
4796
+ try {
4797
+ parsed = JSON.parse(key);
4798
+ } catch {
4799
+ throw new Error(
4800
+ "Invalid Solana private key: looks like a JSON byte array but is not valid JSON"
4801
+ );
4802
+ }
4803
+ if (!Array.isArray(parsed) || !parsed.every((n) => Number.isInteger(n) && n >= 0 && n <= 255)) {
4804
+ throw new Error(
4805
+ "Invalid Solana private key: JSON array must contain only byte values (0-255)"
4806
+ );
4807
+ }
4808
+ if (parsed.length !== 64) {
4809
+ throw new Error(
4810
+ `Invalid Solana key length: expected 64 bytes, got ${parsed.length}`
4811
+ );
4812
+ }
4813
+ return Uint8Array.from(parsed);
4814
+ }
4815
+ const hex = key.startsWith("0x") || key.startsWith("0X") ? key.slice(2) : key;
4816
+ if (/^[0-9a-fA-F]+$/.test(hex) && (hex.length === 64 || hex.length === 128)) {
4817
+ if (hex.length === 64) {
4818
+ throw new Error(
4819
+ "Invalid Solana private key: this is a 32-byte hex key \u2014 the EVM (Base) wallet format, not a Solana key. Solana keys are 64 bytes, usually base58-encoded (86-88 characters)."
4820
+ );
4821
+ }
4822
+ const bytes = new Uint8Array(64);
4823
+ for (let i = 0; i < 64; i++) bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
4824
+ return bytes;
4825
+ }
4793
4826
  try {
4794
4827
  const bs58 = await import("bs58");
4795
- const bytes = (bs58.default ?? bs58).decode(privateKey);
4828
+ const bytes = (bs58.default ?? bs58).decode(key);
4796
4829
  if (bytes.length !== 64) {
4797
4830
  throw new Error(`Invalid Solana key length: expected 64 bytes, got ${bytes.length}`);
4798
4831
  }
4799
4832
  return bytes;
4800
4833
  } catch (err) {
4801
4834
  const msg = err instanceof Error ? err.message : String(err);
4802
- throw new Error(`Invalid Solana private key: ${msg}`);
4835
+ throw new Error(
4836
+ `Invalid Solana private key: ${msg}. Expected a base58-encoded 64-byte key (standard Solana format), a 64-byte hex string, or a Solana CLI JSON byte array.`
4837
+ );
4803
4838
  }
4804
4839
  }
4805
4840
  async function solanaPublicKey(privateKey) {
@@ -4939,16 +4974,27 @@ Your current wallet is backed up first. You can also set
4939
4974
  SOLANA_WALLET_KEY=<private-key> for a single run without changing anything.
4940
4975
  `;
4941
4976
  }
4977
+ async function solanaPublicKeyFrom(privateKey, source) {
4978
+ try {
4979
+ return await solanaPublicKey(privateKey);
4980
+ } catch (err) {
4981
+ const msg = err instanceof Error ? err.message : String(err);
4982
+ throw new Error(`${msg} (key loaded from ${source})`);
4983
+ }
4984
+ }
4942
4985
  async function getOrCreateSolanaWallet() {
4943
4986
  const envKey = typeof process !== "undefined" && process.env ? process.env.SOLANA_WALLET_KEY : void 0;
4944
4987
  if (envKey) {
4945
- const address2 = await solanaPublicKey(envKey);
4988
+ const address2 = await solanaPublicKeyFrom(
4989
+ envKey,
4990
+ "the SOLANA_WALLET_KEY environment variable"
4991
+ );
4946
4992
  return { privateKey: envKey, address: address2, isNew: false };
4947
4993
  }
4948
4994
  if (fs3.existsSync(SOLANA_WALLET_FILE)) {
4949
4995
  const fileKey = fs3.readFileSync(SOLANA_WALLET_FILE, "utf-8").trim();
4950
4996
  if (fileKey) {
4951
- const address2 = await solanaPublicKey(fileKey);
4997
+ const address2 = await solanaPublicKeyFrom(fileKey, SOLANA_WALLET_FILE);
4952
4998
  return { privateKey: fileKey, address: address2, isNew: false };
4953
4999
  }
4954
5000
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockrun/llm",
3
- "version": "3.8.4",
3
+ "version": "3.9.0",
4
4
  "type": "module",
5
5
  "description": "BlockRun SDK - Pay-per-request AI (LLM, Image, Video, Music, Voice) via x402 on Base and Solana",
6
6
  "main": "dist/index.cjs",