@utxopia/sdk 0.1.0-alpha.6 → 0.1.0-alpha.7

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/client.js CHANGED
@@ -25,6 +25,7 @@ import { setupKeysFromWallet, setupKeysFromSeed, setupKeysFromAuthSignature, rec
25
25
  import { scanUnifiedNotesMulti, scanAnnouncementsViewOnlyMulti, computeNullifierHashForNote, computeNullifierBytes, isDepositForViewerHex, createDepositFromConfig, createTweakDeposit, depositViewingNode, createStealthOutputWithKeys, } from "./stealth";
26
26
  import { selectUtxos } from "./psbt";
27
27
  import { hexToBytes } from "./crypto";
28
+ import { getAddressEncoder } from "@solana/kit";
28
29
  import { EventClient } from "./event-client";
29
30
  // ─── Client ─────────────────────────────────────────────────────────
30
31
  let _instance = null;
@@ -183,25 +184,17 @@ export class UTXOpiaClient {
183
184
  const cached = this._tokenIdCache.get(mintAddress);
184
185
  if (cached !== undefined)
185
186
  return cached;
186
- // If it's a base58 address, convert via PublicKey
187
- let bytes;
188
- try {
189
- // Try as raw hex first (64 chars)
190
- if (mintAddress.length === 64 && /^[0-9a-fA-F]+$/.test(mintAddress)) {
191
- bytes = hexToBytes(mintAddress);
192
- }
193
- else {
194
- // Assume base58 PublicKey need to decode
195
- // Use the SDK's reduceToField which handles the conversion
196
- const { PublicKey } = require("@solana/web3.js");
197
- bytes = new PublicKey(mintAddress).toBytes();
198
- }
199
- }
200
- catch {
201
- // Lazy on purpose: a base58 mint padded to 64 is not hex, so computing
202
- // this eagerly threw before the branch above ever ran.
203
- bytes = hexToBytes(mintAddress.padStart(64, "0"));
204
- }
187
+ // 64 hex chars is a raw token id; anything else is a base58 mint.
188
+ //
189
+ // Decoded with getAddressEncoder, the same path pda.ts uses, because
190
+ // require("@solana/web3.js") is not callable from an ESM browser bundle —
191
+ // it threw for every base58 mint, and the hex fallback behind it threw
192
+ // again on the same input. There is no fallback now: both branches are
193
+ // total for their input, and a malformed mint should raise, not be padded
194
+ // into a different token's id.
195
+ const bytes = mintAddress.length === 64 && /^[0-9a-fA-F]+$/.test(mintAddress)
196
+ ? hexToBytes(mintAddress)
197
+ : new Uint8Array(getAddressEncoder().encode(mintAddress));
205
198
  const tokenId = computeTokenId(bytes);
206
199
  this._tokenIdCache.set(mintAddress, tokenId);
207
200
  return tokenId;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utxopia/sdk",
3
- "version": "0.1.0-alpha.6",
3
+ "version": "0.1.0-alpha.7",
4
4
  "description": "UTXOpia SDK - Private Bitcoin across Solana and Sui",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/src/client.ts CHANGED
@@ -55,6 +55,7 @@ import {
55
55
  } from "./stealth";
56
56
  import { selectUtxos, type UtxoDescriptor } from "./psbt";
57
57
  import { hexToBytes, bytesToHex, bigintToBytes } from "./crypto";
58
+ import { getAddressEncoder, type Address } from "@solana/kit";
58
59
  import { EventClient } from "./event-client";
59
60
  import { type DepositOpReturnContext, type BitcoinNetwork } from "./taproot";
60
61
 
@@ -269,23 +270,18 @@ export class UTXOpiaClient {
269
270
  const cached = this._tokenIdCache.get(mintAddress);
270
271
  if (cached !== undefined) return cached;
271
272
 
272
- // If it's a base58 address, convert via PublicKey
273
- let bytes: Uint8Array;
274
- try {
275
- // Try as raw hex first (64 chars)
276
- if (mintAddress.length === 64 && /^[0-9a-fA-F]+$/.test(mintAddress)) {
277
- bytes = hexToBytes(mintAddress);
278
- } else {
279
- // Assume base58 PublicKey need to decode
280
- // Use the SDK's reduceToField which handles the conversion
281
- const { PublicKey } = require("@solana/web3.js");
282
- bytes = new PublicKey(mintAddress).toBytes();
283
- }
284
- } catch {
285
- // Lazy on purpose: a base58 mint padded to 64 is not hex, so computing
286
- // this eagerly threw before the branch above ever ran.
287
- bytes = hexToBytes(mintAddress.padStart(64, "0"));
288
- }
273
+ // 64 hex chars is a raw token id; anything else is a base58 mint.
274
+ //
275
+ // Decoded with getAddressEncoder, the same path pda.ts uses, because
276
+ // require("@solana/web3.js") is not callable from an ESM browser bundle —
277
+ // it threw for every base58 mint, and the hex fallback behind it threw
278
+ // again on the same input. There is no fallback now: both branches are
279
+ // total for their input, and a malformed mint should raise, not be padded
280
+ // into a different token's id.
281
+ const bytes =
282
+ mintAddress.length === 64 && /^[0-9a-fA-F]+$/.test(mintAddress)
283
+ ? hexToBytes(mintAddress)
284
+ : new Uint8Array(getAddressEncoder().encode(mintAddress as Address));
289
285
 
290
286
  const tokenId = computeTokenId(bytes);
291
287
  this._tokenIdCache.set(mintAddress, tokenId);