@kingdomchain/wallet-client 0.5.0 → 0.6.1

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.d.ts CHANGED
@@ -497,6 +497,8 @@ interface EmbeddedWalletScopeOptions {
497
497
  }
498
498
  interface CreateEmbeddedWalletOptions extends EmbeddedWalletScopeOptions {
499
499
  passcode: string;
500
+ /** When true, replaces an existing vault on this account (e.g. an intentional reset). */
501
+ replaceExisting?: boolean;
500
502
  }
501
503
  interface UnlockEmbeddedWalletOptions extends EmbeddedWalletScopeOptions {
502
504
  passcode?: string;
@@ -698,7 +700,9 @@ declare function fetchFeeGrantGranter(restUrl: string, grantee: string): Promise
698
700
 
699
701
  declare class CitizenTxError extends Error {
700
702
  readonly code: CitizenTxErrorCode;
701
- constructor(message: string, code: CitizenTxErrorCode, cause?: unknown);
703
+ /** Raw on-chain log from a failed DeliverTx/indexed tx, when available. */
704
+ readonly rawLog?: string;
705
+ constructor(message: string, code: CitizenTxErrorCode, cause?: unknown, rawLog?: string);
702
706
  }
703
707
  type CitizenTxErrorCode = "INSUFFICIENT_FEE" | "INSUFFICIENT_BALANCE" | "SEQUENCE_MISMATCH" | "TX_FAILED" | "TIMEOUT" | "INVALID_INPUT";
704
708
  interface BroadcastConfirmOptions {
package/dist/index.js CHANGED
@@ -2953,10 +2953,16 @@ async function migrateLegacyEmbeddedWallet(options) {
2953
2953
  return session;
2954
2954
  }
2955
2955
  async function createEmbeddedWallet(options) {
2956
+ const scopeId = scopeFromOptions(options);
2957
+ const existing = await loadVaultForScope(scopeId);
2958
+ if (existing && !options.replaceExisting) {
2959
+ throw new EmbeddedWalletVaultError(
2960
+ "An embedded wallet already exists on this account; pass replaceExisting to create over it"
2961
+ );
2962
+ }
2956
2963
  const createdAt = (/* @__PURE__ */ new Date()).toISOString();
2957
2964
  const plaintext = await createHdDerivedPlaintext(createdAt);
2958
2965
  const { address, vault } = await encryptPlaintextWithPasscode(plaintext, options.passcode);
2959
- const scopeId = scopeFromOptions(options);
2960
2966
  await saveVaultToIndexedDb(vault, { scopeId });
2961
2967
  lockEmbeddedWallet();
2962
2968
  activeScopeId = scopeId;
@@ -3267,12 +3273,15 @@ async function fetchFeeGrantGranter(restUrl, grantee) {
3267
3273
  }
3268
3274
  }
3269
3275
  var CitizenTxError = class extends Error {
3270
- constructor(message, code, cause) {
3276
+ constructor(message, code, cause, rawLog) {
3271
3277
  super(message, { cause });
3272
3278
  this.code = code;
3273
3279
  this.name = "CitizenTxError";
3280
+ this.rawLog = rawLog;
3274
3281
  }
3275
3282
  code;
3283
+ /** Raw on-chain log from a failed DeliverTx/indexed tx, when available. */
3284
+ rawLog;
3276
3285
  };
3277
3286
  var DEFAULT_GAS = "200000";
3278
3287
  var DEFAULT_FEE_UKDR = "5000";
@@ -3350,6 +3359,7 @@ async function broadcastAndConfirmTx(client, signerAddress, messages, fee, memo
3350
3359
  try {
3351
3360
  deliverTx = await client.signAndBroadcast(signerAddress, messages, fee, memo);
3352
3361
  } catch (err) {
3362
+ console.error("[citizenTx] broadcast threw before inclusion:", err);
3353
3363
  const message = err instanceof Error ? err.message : String(err);
3354
3364
  if (message.toLowerCase().includes("insufficient")) {
3355
3365
  throw new CitizenTxError(citizenTxErrorMessage("INSUFFICIENT_FEE"), "INSUFFICIENT_FEE", err);
@@ -3357,8 +3367,12 @@ async function broadcastAndConfirmTx(client, signerAddress, messages, fee, memo
3357
3367
  throw new CitizenTxError(citizenTxErrorMessage("TX_FAILED"), "TX_FAILED", err);
3358
3368
  }
3359
3369
  if (deliverTx.code !== 0) {
3370
+ console.error("[citizenTx] deliverTx failed:", {
3371
+ code: deliverTx.code,
3372
+ rawLog: deliverTx.rawLog
3373
+ });
3360
3374
  const code = classifyBroadcastFailure(deliverTx.rawLog ?? "", deliverTx.code);
3361
- throw new CitizenTxError(citizenTxErrorMessage(code), code);
3375
+ throw new CitizenTxError(citizenTxErrorMessage(code), code, void 0, deliverTx.rawLog ?? "");
3362
3376
  }
3363
3377
  const hash = deliverTx.transactionHash;
3364
3378
  const deadline = Date.now() + timeoutMs;
@@ -3366,8 +3380,12 @@ async function broadcastAndConfirmTx(client, signerAddress, messages, fee, memo
3366
3380
  const indexed = await client.getTx(hash);
3367
3381
  if (indexed) {
3368
3382
  if (indexed.code !== 0) {
3383
+ console.error("[citizenTx] indexed tx failed:", {
3384
+ code: indexed.code,
3385
+ rawLog: indexed.rawLog
3386
+ });
3369
3387
  const code = classifyBroadcastFailure(indexed.rawLog ?? "", indexed.code);
3370
- throw new CitizenTxError(citizenTxErrorMessage(code), code);
3388
+ throw new CitizenTxError(citizenTxErrorMessage(code), code, void 0, indexed.rawLog ?? "");
3371
3389
  }
3372
3390
  return {
3373
3391
  hash,