@kingdomchain/wallet-client 0.5.0 → 0.6.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.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;
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;