decane-connect-kit 2.27.0 → 2.28.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.cts CHANGED
@@ -1276,6 +1276,18 @@ declare class RecoveryWalletMismatchError extends DecaneConnectError {
1276
1276
  declare class ExportNotAuthorizedError extends DecaneConnectError {
1277
1277
  constructor();
1278
1278
  }
1279
+ /**
1280
+ * POST /share answered 409: a wallet the enclave can restore already exists
1281
+ * for this account, so the one this device just generated must not replace
1282
+ * its server share (the sealed auth share matches the existing one, and
1283
+ * writing over it would lose the key). Happens when the app's server created
1284
+ * the wallet moments before this sign-in, or a stale tab raced a newer one.
1285
+ * The client discards what it generated and provisions instead; nothing for
1286
+ * the caller to do, which is why this never reaches them.
1287
+ */
1288
+ declare class WalletExistsError extends DecaneConnectError {
1289
+ constructor();
1290
+ }
1279
1291
  /**
1280
1292
  * Wallet creation stopped because the enclave did not seal the wallet's
1281
1293
  * recovery share (enrolment). Creation blocks on that step in every tier,
@@ -1753,4 +1765,4 @@ declare class WeakPasswordError extends Error {
1753
1765
  */
1754
1766
  declare function validateUnlockPassword(password: string): void;
1755
1767
 
1756
- export { type ActiveSession, AttestationError, type AuthProfile, type AuthResult, BUILT_IN_CHAINS, type BalanceResult, type CAIP25Method, type CAIP25SessionRequest, type CAIP25SessionResult, CHAINS, CallSequenceError, type Chain, type ChainDescriptor, type ChainId, type ChainScope, type ChainSupport, type ChainType, type ConnectMode, type ConnectResult, type DecaneConfig, type DecaneConnect, type DecaneConnectConfig, DecaneConnectError, DecaneError, DecaneErrorCode, DecaneKit, DecaneLogo, DecaneMark, type DecaneProvider, DecaneWordmark, type Eip1193Provider, EnclaveHttpError, type EthereumProviderOptions, ExportNotAuthorizedError, InvalidAccessTokenError, InvalidApiKeyError, InvalidPinError, InvalidRecoveryFileError, type KingsChatTokens, MIN_PASSWORD_LENGTH, NetworkError, NewDeviceError, OriginNotAllowedError, type PortableBackup, PromptPasswordNotConfiguredError, PromptPinNotConfiguredError, ProvisioningRateLimitedError, ProvisioningTimeoutError, ReconnectRequiredError, type RecordTransactionInput, RecoveryFailedError, type RecoveryProgress, type RecoveryShareFile, RecoveryWalletMismatchError, type SdkEvent, type SendTransactionRequest, SessionExpiredError, ShareCorruptedError, type SignMessageRequest, type SignTypedDataRequest, type SignedAuthorization, type SocialAuthState, type SocialConfig, SocialWalletModal, StaleDeviceShareError, type Theme, type TransactionRecord, type TxParams, type UnifiedWalletAccount, UnlockRequiredError, UnlockTokenRejectedError, UserCancelledError, WalletEnrolmentError, WalletSelector, WeakPasswordError, WebAuthnNotSupportedError, type WrappedShareMeta, WrongPasswordError, WrongUnlockPasswordError, createDecane, createDecaneConnect, createEthereumProvider, loginWithKingsChatPopup, startEmailAuth, useChainSwitch, useDecane, useEthereumProvider, useSendTransaction, useSignMessage, useSignTypedData, useSocialAuth, useSocialBalance, useSocialWallet, useWalletSelector, validateUnlockPassword, verifyEmailCode };
1768
+ export { type ActiveSession, AttestationError, type AuthProfile, type AuthResult, BUILT_IN_CHAINS, type BalanceResult, type CAIP25Method, type CAIP25SessionRequest, type CAIP25SessionResult, CHAINS, CallSequenceError, type Chain, type ChainDescriptor, type ChainId, type ChainScope, type ChainSupport, type ChainType, type ConnectMode, type ConnectResult, type DecaneConfig, type DecaneConnect, type DecaneConnectConfig, DecaneConnectError, DecaneError, DecaneErrorCode, DecaneKit, DecaneLogo, DecaneMark, type DecaneProvider, DecaneWordmark, type Eip1193Provider, EnclaveHttpError, type EthereumProviderOptions, ExportNotAuthorizedError, InvalidAccessTokenError, InvalidApiKeyError, InvalidPinError, InvalidRecoveryFileError, type KingsChatTokens, MIN_PASSWORD_LENGTH, NetworkError, NewDeviceError, OriginNotAllowedError, type PortableBackup, PromptPasswordNotConfiguredError, PromptPinNotConfiguredError, ProvisioningRateLimitedError, ProvisioningTimeoutError, ReconnectRequiredError, type RecordTransactionInput, RecoveryFailedError, type RecoveryProgress, type RecoveryShareFile, RecoveryWalletMismatchError, type SdkEvent, type SendTransactionRequest, SessionExpiredError, ShareCorruptedError, type SignMessageRequest, type SignTypedDataRequest, type SignedAuthorization, type SocialAuthState, type SocialConfig, SocialWalletModal, StaleDeviceShareError, type Theme, type TransactionRecord, type TxParams, type UnifiedWalletAccount, UnlockRequiredError, UnlockTokenRejectedError, UserCancelledError, WalletEnrolmentError, WalletExistsError, WalletSelector, WeakPasswordError, WebAuthnNotSupportedError, type WrappedShareMeta, WrongPasswordError, WrongUnlockPasswordError, createDecane, createDecaneConnect, createEthereumProvider, loginWithKingsChatPopup, startEmailAuth, useChainSwitch, useDecane, useEthereumProvider, useSendTransaction, useSignMessage, useSignTypedData, useSocialAuth, useSocialBalance, useSocialWallet, useWalletSelector, validateUnlockPassword, verifyEmailCode };
package/dist/index.d.ts CHANGED
@@ -1276,6 +1276,18 @@ declare class RecoveryWalletMismatchError extends DecaneConnectError {
1276
1276
  declare class ExportNotAuthorizedError extends DecaneConnectError {
1277
1277
  constructor();
1278
1278
  }
1279
+ /**
1280
+ * POST /share answered 409: a wallet the enclave can restore already exists
1281
+ * for this account, so the one this device just generated must not replace
1282
+ * its server share (the sealed auth share matches the existing one, and
1283
+ * writing over it would lose the key). Happens when the app's server created
1284
+ * the wallet moments before this sign-in, or a stale tab raced a newer one.
1285
+ * The client discards what it generated and provisions instead; nothing for
1286
+ * the caller to do, which is why this never reaches them.
1287
+ */
1288
+ declare class WalletExistsError extends DecaneConnectError {
1289
+ constructor();
1290
+ }
1279
1291
  /**
1280
1292
  * Wallet creation stopped because the enclave did not seal the wallet's
1281
1293
  * recovery share (enrolment). Creation blocks on that step in every tier,
@@ -1753,4 +1765,4 @@ declare class WeakPasswordError extends Error {
1753
1765
  */
1754
1766
  declare function validateUnlockPassword(password: string): void;
1755
1767
 
1756
- export { type ActiveSession, AttestationError, type AuthProfile, type AuthResult, BUILT_IN_CHAINS, type BalanceResult, type CAIP25Method, type CAIP25SessionRequest, type CAIP25SessionResult, CHAINS, CallSequenceError, type Chain, type ChainDescriptor, type ChainId, type ChainScope, type ChainSupport, type ChainType, type ConnectMode, type ConnectResult, type DecaneConfig, type DecaneConnect, type DecaneConnectConfig, DecaneConnectError, DecaneError, DecaneErrorCode, DecaneKit, DecaneLogo, DecaneMark, type DecaneProvider, DecaneWordmark, type Eip1193Provider, EnclaveHttpError, type EthereumProviderOptions, ExportNotAuthorizedError, InvalidAccessTokenError, InvalidApiKeyError, InvalidPinError, InvalidRecoveryFileError, type KingsChatTokens, MIN_PASSWORD_LENGTH, NetworkError, NewDeviceError, OriginNotAllowedError, type PortableBackup, PromptPasswordNotConfiguredError, PromptPinNotConfiguredError, ProvisioningRateLimitedError, ProvisioningTimeoutError, ReconnectRequiredError, type RecordTransactionInput, RecoveryFailedError, type RecoveryProgress, type RecoveryShareFile, RecoveryWalletMismatchError, type SdkEvent, type SendTransactionRequest, SessionExpiredError, ShareCorruptedError, type SignMessageRequest, type SignTypedDataRequest, type SignedAuthorization, type SocialAuthState, type SocialConfig, SocialWalletModal, StaleDeviceShareError, type Theme, type TransactionRecord, type TxParams, type UnifiedWalletAccount, UnlockRequiredError, UnlockTokenRejectedError, UserCancelledError, WalletEnrolmentError, WalletSelector, WeakPasswordError, WebAuthnNotSupportedError, type WrappedShareMeta, WrongPasswordError, WrongUnlockPasswordError, createDecane, createDecaneConnect, createEthereumProvider, loginWithKingsChatPopup, startEmailAuth, useChainSwitch, useDecane, useEthereumProvider, useSendTransaction, useSignMessage, useSignTypedData, useSocialAuth, useSocialBalance, useSocialWallet, useWalletSelector, validateUnlockPassword, verifyEmailCode };
1768
+ export { type ActiveSession, AttestationError, type AuthProfile, type AuthResult, BUILT_IN_CHAINS, type BalanceResult, type CAIP25Method, type CAIP25SessionRequest, type CAIP25SessionResult, CHAINS, CallSequenceError, type Chain, type ChainDescriptor, type ChainId, type ChainScope, type ChainSupport, type ChainType, type ConnectMode, type ConnectResult, type DecaneConfig, type DecaneConnect, type DecaneConnectConfig, DecaneConnectError, DecaneError, DecaneErrorCode, DecaneKit, DecaneLogo, DecaneMark, type DecaneProvider, DecaneWordmark, type Eip1193Provider, EnclaveHttpError, type EthereumProviderOptions, ExportNotAuthorizedError, InvalidAccessTokenError, InvalidApiKeyError, InvalidPinError, InvalidRecoveryFileError, type KingsChatTokens, MIN_PASSWORD_LENGTH, NetworkError, NewDeviceError, OriginNotAllowedError, type PortableBackup, PromptPasswordNotConfiguredError, PromptPinNotConfiguredError, ProvisioningRateLimitedError, ProvisioningTimeoutError, ReconnectRequiredError, type RecordTransactionInput, RecoveryFailedError, type RecoveryProgress, type RecoveryShareFile, RecoveryWalletMismatchError, type SdkEvent, type SendTransactionRequest, SessionExpiredError, ShareCorruptedError, type SignMessageRequest, type SignTypedDataRequest, type SignedAuthorization, type SocialAuthState, type SocialConfig, SocialWalletModal, StaleDeviceShareError, type Theme, type TransactionRecord, type TxParams, type UnifiedWalletAccount, UnlockRequiredError, UnlockTokenRejectedError, UserCancelledError, WalletEnrolmentError, WalletExistsError, WalletSelector, WeakPasswordError, WebAuthnNotSupportedError, type WrappedShareMeta, WrongPasswordError, WrongUnlockPasswordError, createDecane, createDecaneConnect, createEthereumProvider, loginWithKingsChatPopup, startEmailAuth, useChainSwitch, useDecane, useEthereumProvider, useSendTransaction, useSignMessage, useSignTypedData, useSocialAuth, useSocialBalance, useSocialWallet, useWalletSelector, validateUnlockPassword, verifyEmailCode };
package/dist/index.js CHANGED
@@ -37,11 +37,12 @@ __export(errors_exports, {
37
37
  UnlockTokenRejectedError: () => UnlockTokenRejectedError,
38
38
  UserCancelledError: () => UserCancelledError,
39
39
  WalletEnrolmentError: () => WalletEnrolmentError,
40
+ WalletExistsError: () => WalletExistsError,
40
41
  WebAuthnNotSupportedError: () => WebAuthnNotSupportedError,
41
42
  WrongPasswordError: () => WrongPasswordError,
42
43
  WrongUnlockPasswordError: () => WrongUnlockPasswordError
43
44
  });
44
- var DecaneConnectError, InvalidApiKeyError, OriginNotAllowedError, SessionExpiredError, UnlockRequiredError, ReconnectRequiredError, UserCancelledError, WebAuthnNotSupportedError, InvalidPinError, CallSequenceError, NetworkError, ShareCorruptedError, ProvisioningTimeoutError, NewDeviceError, StaleDeviceShareError, PromptPinNotConfiguredError, PromptPasswordNotConfiguredError, WrongUnlockPasswordError, InvalidAccessTokenError, UnlockTokenRejectedError, AttestationError, RecoveryFailedError, InvalidRecoveryFileError, WrongPasswordError, RecoveryWalletMismatchError, ExportNotAuthorizedError, WalletEnrolmentError, ProvisioningRateLimitedError, EnclaveHttpError;
45
+ var DecaneConnectError, InvalidApiKeyError, OriginNotAllowedError, SessionExpiredError, UnlockRequiredError, ReconnectRequiredError, UserCancelledError, WebAuthnNotSupportedError, InvalidPinError, CallSequenceError, NetworkError, ShareCorruptedError, ProvisioningTimeoutError, NewDeviceError, StaleDeviceShareError, PromptPinNotConfiguredError, PromptPasswordNotConfiguredError, WrongUnlockPasswordError, InvalidAccessTokenError, UnlockTokenRejectedError, AttestationError, RecoveryFailedError, InvalidRecoveryFileError, WrongPasswordError, RecoveryWalletMismatchError, ExportNotAuthorizedError, WalletExistsError, WalletEnrolmentError, ProvisioningRateLimitedError, EnclaveHttpError;
45
46
  var init_errors = __esm({
46
47
  "src/social/errors.ts"() {
47
48
  "use strict";
@@ -190,6 +191,11 @@ var init_errors = __esm({
190
191
  super("EXPORT_NOT_AUTHORIZED", "Export requires a fresh security check", true);
191
192
  }
192
193
  };
194
+ WalletExistsError = class extends DecaneConnectError {
195
+ constructor() {
196
+ super("WALLET_EXISTS", "This account already has a wallet; opening it instead.", true);
197
+ }
198
+ };
193
199
  WalletEnrolmentError = class extends DecaneConnectError {
194
200
  constructor(cause) {
195
201
  super(
@@ -2023,7 +2029,9 @@ var ERROR_MAP = {
2023
2029
  // The backend's authMiddleware code for an expired/revoked JWT. Surfacing it
2024
2030
  // as ReconnectRequiredError routes callers to the sign-in UI instead of a
2025
2031
  // generic failure message.
2026
- UNAUTHORIZED: ReconnectRequiredError
2032
+ UNAUTHORIZED: ReconnectRequiredError,
2033
+ // A restorable wallet already exists: the client provisions instead of creating.
2034
+ WALLET_EXISTS: WalletExistsError
2027
2035
  };
2028
2036
  var REQUEST_TIMEOUT_MS = 3e4;
2029
2037
  var ApiClient = class {
@@ -2428,7 +2436,7 @@ function dropCollateral(teeUrl) {
2428
2436
  // src/social/attestation.ts
2429
2437
  init_errors();
2430
2438
 
2431
- // ../../infra/tee-measurement.json
2439
+ // ../infra/tee-measurement.json
2432
2440
  var tee_measurement_default = {
2433
2441
  signerVersion: "0.2.10",
2434
2442
  acceptedMrtd: [
@@ -4390,24 +4398,37 @@ async function createDecaneConnect(config) {
4390
4398
  if (unlockTokenKey) await attachUnlockToken(userId, jwt, unlockTokenKey);
4391
4399
  }
4392
4400
  const serverIv = generateRandomBytes(12);
4393
- await withDeadline(api.putShare(jwt, {
4394
- ciphertext: shareSet.server,
4395
- iv: serverIv,
4396
- wrappedShareMeta: {
4397
- // The server records this on the wallet_created event and nothing else.
4398
- unlockMethod: identityTier ? "identity" : unlockMethod
4399
- // credential IDs, prfSalt, pinSalt stay on-device — never sent to server
4400
- },
4401
- evmAddress,
4402
- solanaAddress,
4403
- tronAddress,
4404
- // Provisional until the enclave has sealed the auth share, just below. A
4405
- // backend that knows the flag keeps this row invisible to hasShare until
4406
- // then, so a creation that fails past this point leaves no wallet behind
4407
- // and the next sign-in simply creates again — with a new key, which is
4408
- // why the backend also replaces the recorded addresses outright.
4409
- pendingEnrolment: true
4410
- }), remainingBudget(), "storing your wallet");
4401
+ try {
4402
+ await withDeadline(api.putShare(jwt, {
4403
+ ciphertext: shareSet.server,
4404
+ iv: serverIv,
4405
+ wrappedShareMeta: {
4406
+ // The server records this on the wallet_created event and nothing else.
4407
+ unlockMethod: identityTier ? "identity" : unlockMethod
4408
+ // credential IDs, prfSalt, pinSalt stay on-device — never sent to server
4409
+ },
4410
+ evmAddress,
4411
+ solanaAddress,
4412
+ tronAddress,
4413
+ // Provisional until the enclave has sealed the auth share, just below. A
4414
+ // backend that knows the flag keeps this row invisible to hasShare until
4415
+ // then, so a creation that fails past this point leaves no wallet behind
4416
+ // and the next sign-in simply creates again — with a new key, which is
4417
+ // why the backend also replaces the recorded addresses outright.
4418
+ pendingEnrolment: true
4419
+ }), remainingBudget(), "storing your wallet");
4420
+ } catch (e) {
4421
+ if (e instanceof WalletExistsError) {
4422
+ zeroize(shareSet.server);
4423
+ zeroize(shareSet.device);
4424
+ zeroize(shareSet.recovery);
4425
+ if (wrappingKey) await storage2.deleteShare(userId).catch(() => {
4426
+ });
4427
+ events.emit("wallet-unlocking");
4428
+ return returningUserUnlock(userId, jwt);
4429
+ }
4430
+ throw e;
4431
+ }
4411
4432
  zeroize(shareSet.server);
4412
4433
  try {
4413
4434
  await enrolBlocking(jwt, new Uint8Array(shareSet.recovery), remainingBudget());
@@ -8977,6 +8998,7 @@ export {
8977
8998
  UnlockTokenRejectedError,
8978
8999
  UserCancelledError,
8979
9000
  WalletEnrolmentError,
9001
+ WalletExistsError,
8980
9002
  WalletSelector,
8981
9003
  WeakPasswordError,
8982
9004
  WebAuthnNotSupportedError,