decane-connect-kit 2.3.1 → 2.4.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
@@ -175,6 +175,7 @@ declare class ApiClient {
175
175
  getAddresses(jwt: string): Promise<{
176
176
  evm: string | null;
177
177
  solana: string | null;
178
+ tron: string | null;
178
179
  }>;
179
180
  putShare(jwt: string, share: {
180
181
  ciphertext: Uint8Array;
@@ -182,6 +183,7 @@ declare class ApiClient {
182
183
  wrappedShareMeta: WrappedShareMeta;
183
184
  evmAddress: string;
184
185
  solanaAddress: string;
186
+ tronAddress: string;
185
187
  }): Promise<void>;
186
188
  getWebAuthnRegisterOptions(jwt: string, rpId: string, rpName: string): Promise<_simplewebauthn_browser.PublicKeyCredentialCreationOptionsJSON>;
187
189
  postWebAuthnRegister(jwt: string, response: _simplewebauthn_browser.RegistrationResponseJSON, origin: string): Promise<void>;
@@ -327,7 +329,7 @@ interface SignedAuthorization {
327
329
  s: string;
328
330
  }
329
331
 
330
- type Chain = `evm:${number}` | `solana:${'mainnet' | 'devnet'}`;
332
+ type Chain = `evm:${number}` | `solana:${'mainnet' | 'devnet'}` | `tron:${'mainnet' | 'shasta' | 'nile'}`;
331
333
  interface DecaneConnectConfig {
332
334
  /** Dashboard project ID (public). Sent with every request so the backend can
333
335
  * confirm the API key below actually belongs to this project. */
@@ -405,6 +407,7 @@ interface ConnectResult {
405
407
  addresses: {
406
408
  evm?: string;
407
409
  solana?: string;
410
+ tron?: string;
408
411
  };
409
412
  isNewUser: boolean;
410
413
  }
@@ -510,10 +513,19 @@ interface DecaneConnect {
510
513
  */
511
514
  getAccessToken(): string | null;
512
515
  signSolanaTransaction(tx: Uint8Array): Promise<Uint8Array>;
516
+ /**
517
+ * Sign a Tron transaction. Pass the transaction's `raw_data_hex` (the value
518
+ * TronWeb puts on a built transaction). The enclave computes the txID
519
+ * (sha256(raw_data)) and signs it with the same secp256k1 key as the EVM
520
+ * wallet; returns the 65-byte recoverable signature as 0x-hex. Attach it to
521
+ * the transaction's `signature` array and broadcast via TronWeb / a full node.
522
+ */
523
+ signTronTransaction(rawDataHex: string): Promise<string>;
513
524
  disconnect(): Promise<void>;
514
525
  getAddresses(): {
515
526
  evm?: string;
516
527
  solana?: string;
528
+ tron?: string;
517
529
  } | null;
518
530
  /**
519
531
  * Native-token balance for a chain (defaults to the first configured EVM
@@ -780,6 +792,7 @@ interface SocialAuthState {
780
792
  addresses: {
781
793
  evm?: string;
782
794
  solana?: string;
795
+ tron?: string;
783
796
  } | null;
784
797
  isNewUser: boolean;
785
798
  isUnlocked: boolean;
@@ -864,6 +877,7 @@ declare function useSocialAuth(): {
864
877
  addresses: {
865
878
  evm?: string;
866
879
  solana?: string;
880
+ tron?: string;
867
881
  } | null;
868
882
  sessionExpiresAt: number | null;
869
883
  canUsePasskey: boolean;
@@ -897,6 +911,7 @@ declare function useSocialWallet(): {
897
911
  addresses: {
898
912
  evm?: string;
899
913
  solana?: string;
914
+ tron?: string;
900
915
  } | null;
901
916
  sessionExpiresAt: number | null;
902
917
  needsReconnect: boolean;
@@ -917,6 +932,7 @@ declare function useSocialWallet(): {
917
932
  gasPrice?: bigint;
918
933
  }) => Promise<string>;
919
934
  signSolanaTransaction: (tx: Uint8Array) => Promise<Uint8Array<ArrayBufferLike>>;
935
+ signTronTransaction: (rawDataHex: string) => Promise<string>;
920
936
  signTypedData: (req: {
921
937
  chain: string;
922
938
  domain: Record<string, unknown>;
package/dist/index.d.ts CHANGED
@@ -175,6 +175,7 @@ declare class ApiClient {
175
175
  getAddresses(jwt: string): Promise<{
176
176
  evm: string | null;
177
177
  solana: string | null;
178
+ tron: string | null;
178
179
  }>;
179
180
  putShare(jwt: string, share: {
180
181
  ciphertext: Uint8Array;
@@ -182,6 +183,7 @@ declare class ApiClient {
182
183
  wrappedShareMeta: WrappedShareMeta;
183
184
  evmAddress: string;
184
185
  solanaAddress: string;
186
+ tronAddress: string;
185
187
  }): Promise<void>;
186
188
  getWebAuthnRegisterOptions(jwt: string, rpId: string, rpName: string): Promise<_simplewebauthn_browser.PublicKeyCredentialCreationOptionsJSON>;
187
189
  postWebAuthnRegister(jwt: string, response: _simplewebauthn_browser.RegistrationResponseJSON, origin: string): Promise<void>;
@@ -327,7 +329,7 @@ interface SignedAuthorization {
327
329
  s: string;
328
330
  }
329
331
 
330
- type Chain = `evm:${number}` | `solana:${'mainnet' | 'devnet'}`;
332
+ type Chain = `evm:${number}` | `solana:${'mainnet' | 'devnet'}` | `tron:${'mainnet' | 'shasta' | 'nile'}`;
331
333
  interface DecaneConnectConfig {
332
334
  /** Dashboard project ID (public). Sent with every request so the backend can
333
335
  * confirm the API key below actually belongs to this project. */
@@ -405,6 +407,7 @@ interface ConnectResult {
405
407
  addresses: {
406
408
  evm?: string;
407
409
  solana?: string;
410
+ tron?: string;
408
411
  };
409
412
  isNewUser: boolean;
410
413
  }
@@ -510,10 +513,19 @@ interface DecaneConnect {
510
513
  */
511
514
  getAccessToken(): string | null;
512
515
  signSolanaTransaction(tx: Uint8Array): Promise<Uint8Array>;
516
+ /**
517
+ * Sign a Tron transaction. Pass the transaction's `raw_data_hex` (the value
518
+ * TronWeb puts on a built transaction). The enclave computes the txID
519
+ * (sha256(raw_data)) and signs it with the same secp256k1 key as the EVM
520
+ * wallet; returns the 65-byte recoverable signature as 0x-hex. Attach it to
521
+ * the transaction's `signature` array and broadcast via TronWeb / a full node.
522
+ */
523
+ signTronTransaction(rawDataHex: string): Promise<string>;
513
524
  disconnect(): Promise<void>;
514
525
  getAddresses(): {
515
526
  evm?: string;
516
527
  solana?: string;
528
+ tron?: string;
517
529
  } | null;
518
530
  /**
519
531
  * Native-token balance for a chain (defaults to the first configured EVM
@@ -780,6 +792,7 @@ interface SocialAuthState {
780
792
  addresses: {
781
793
  evm?: string;
782
794
  solana?: string;
795
+ tron?: string;
783
796
  } | null;
784
797
  isNewUser: boolean;
785
798
  isUnlocked: boolean;
@@ -864,6 +877,7 @@ declare function useSocialAuth(): {
864
877
  addresses: {
865
878
  evm?: string;
866
879
  solana?: string;
880
+ tron?: string;
867
881
  } | null;
868
882
  sessionExpiresAt: number | null;
869
883
  canUsePasskey: boolean;
@@ -897,6 +911,7 @@ declare function useSocialWallet(): {
897
911
  addresses: {
898
912
  evm?: string;
899
913
  solana?: string;
914
+ tron?: string;
900
915
  } | null;
901
916
  sessionExpiresAt: number | null;
902
917
  needsReconnect: boolean;
@@ -917,6 +932,7 @@ declare function useSocialWallet(): {
917
932
  gasPrice?: bigint;
918
933
  }) => Promise<string>;
919
934
  signSolanaTransaction: (tx: Uint8Array) => Promise<Uint8Array<ArrayBufferLike>>;
935
+ signTronTransaction: (rawDataHex: string) => Promise<string>;
920
936
  signTypedData: (req: {
921
937
  chain: string;
922
938
  domain: Record<string, unknown>;
package/dist/index.js CHANGED
@@ -1892,7 +1892,7 @@ function createDecane(config) {
1892
1892
 
1893
1893
  // src/social/client.ts
1894
1894
  init_errors();
1895
- import { Wallet } from "ethers";
1895
+ import { Wallet, sha256 as sha2562, encodeBase58 as encodeBase582 } from "ethers";
1896
1896
  import { Transaction as Transaction2, VersionedTransaction, Keypair } from "@solana/web3.js";
1897
1897
 
1898
1898
  // src/social/events.ts
@@ -1986,7 +1986,8 @@ var ApiClient = class {
1986
1986
  iv: bytesToB64(share.iv),
1987
1987
  wrappedShareMeta: btoa(JSON.stringify(share.wrappedShareMeta)),
1988
1988
  evmAddress: share.evmAddress,
1989
- solanaAddress: share.solanaAddress
1989
+ solanaAddress: share.solanaAddress,
1990
+ tronAddress: share.tronAddress
1990
1991
  })
1991
1992
  });
1992
1993
  }
@@ -2127,6 +2128,9 @@ var Storage = class {
2127
2128
  }
2128
2129
  };
2129
2130
 
2131
+ // src/social/session.ts
2132
+ import { sha256, encodeBase58 } from "ethers";
2133
+
2130
2134
  // src/social/teeClient.ts
2131
2135
  import { startAuthentication } from "@simplewebauthn/browser";
2132
2136
 
@@ -2407,6 +2411,11 @@ var TeeClient = class {
2407
2411
 
2408
2412
  // src/social/session.ts
2409
2413
  init_errors();
2414
+ function evmToTronAddress(evmAddress) {
2415
+ const hex41 = "41" + evmAddress.toLowerCase().replace(/^0x/, "");
2416
+ const checksum = sha256(sha256("0x" + hex41)).slice(2, 10);
2417
+ return encodeBase58("0x" + hex41 + checksum);
2418
+ }
2410
2419
  var SessionManager = class {
2411
2420
  constructor(events, durationMs, teeUrl, requireAssertionPerSignature = false) {
2412
2421
  this.events = events;
@@ -2416,6 +2425,7 @@ var SessionManager = class {
2416
2425
  this.tee = null;
2417
2426
  this.evmAddress = null;
2418
2427
  this.solanaAddress = null;
2428
+ this.tronAddress = null;
2419
2429
  this.expiresAt = null;
2420
2430
  this.timeoutId = null;
2421
2431
  }
@@ -2442,6 +2452,7 @@ var SessionManager = class {
2442
2452
  this.tee.adoptHandle(handle, this.requireAssertionPerSignature);
2443
2453
  this.evmAddress = addresses.evm;
2444
2454
  this.solanaAddress = addresses.solana;
2455
+ this.tronAddress = addresses.tron ?? evmToTronAddress(addresses.evm);
2445
2456
  this.expiresAt = expiresAtMs;
2446
2457
  this.setExpiryTimer(expiresAtMs - Date.now());
2447
2458
  this.events.emit("session-started");
@@ -2468,15 +2479,17 @@ var SessionManager = class {
2468
2479
  "requireAssertionPerSignature was requested but this signer does not support it \u2014 refusing to open a session with weaker authority than configured."
2469
2480
  );
2470
2481
  }
2471
- const addresses = verified ?? fallback;
2472
- if (!addresses) {
2482
+ const resolved = verified ?? fallback;
2483
+ if (!resolved) {
2473
2484
  this.tee = null;
2474
2485
  throw new Error(
2475
2486
  "No addresses available for this wallet \u2014 the signer could not derive them and none are recorded"
2476
2487
  );
2477
2488
  }
2489
+ const addresses = { evm: resolved.evm, solana: resolved.solana, tron: resolved.tron ?? evmToTronAddress(resolved.evm) };
2478
2490
  this.evmAddress = addresses.evm;
2479
2491
  this.solanaAddress = addresses.solana;
2492
+ this.tronAddress = addresses.tron;
2480
2493
  const serverTtlMs = this.tee.sessionExpiresIn();
2481
2494
  const effectiveMs = serverTtlMs != null ? Math.min(this.durationMs, serverTtlMs * 1e3) : this.durationMs;
2482
2495
  this.expiresAt = Date.now() + effectiveMs;
@@ -2493,6 +2506,7 @@ var SessionManager = class {
2493
2506
  this.tee = null;
2494
2507
  this.evmAddress = null;
2495
2508
  this.solanaAddress = null;
2509
+ this.tronAddress = null;
2496
2510
  this.expiresAt = null;
2497
2511
  if (this.timeoutId) {
2498
2512
  clearTimeout(this.timeoutId);
@@ -2511,7 +2525,11 @@ var SessionManager = class {
2511
2525
  }
2512
2526
  addresses() {
2513
2527
  if (!this.evmAddress || !this.solanaAddress) return null;
2514
- return { evm: this.evmAddress, solana: this.solanaAddress };
2528
+ return {
2529
+ evm: this.evmAddress,
2530
+ solana: this.solanaAddress,
2531
+ tron: this.tronAddress ?? evmToTronAddress(this.evmAddress)
2532
+ };
2515
2533
  }
2516
2534
  };
2517
2535
 
@@ -3364,9 +3382,11 @@ async function createDecaneConnect(config) {
3364
3382
  let shareSet;
3365
3383
  let evmAddress;
3366
3384
  let solanaAddress;
3385
+ let tronAddress;
3367
3386
  try {
3368
3387
  evmAddress = new Wallet(toHex2(master)).address;
3369
3388
  solanaAddress = Keypair.fromSeed(master).publicKey.toBase58();
3389
+ tronAddress = evmToTronAddress2(evmAddress);
3370
3390
  shareSet = await splitMaster(master, 1);
3371
3391
  } finally {
3372
3392
  zeroize(master);
@@ -3397,10 +3417,11 @@ async function createDecaneConnect(config) {
3397
3417
  // credential IDs, prfSalt, pinSalt stay on-device — never sent to server
3398
3418
  },
3399
3419
  evmAddress,
3400
- solanaAddress
3420
+ solanaAddress,
3421
+ tronAddress
3401
3422
  });
3402
3423
  zeroize(shareSet.server);
3403
- const addresses = { evm: evmAddress, solana: solanaAddress };
3424
+ const addresses = { evm: evmAddress, solana: solanaAddress, tron: tronAddress };
3404
3425
  if (unlockMethod === "passkey" && meta.credentialId && meta.prfSalt) {
3405
3426
  try {
3406
3427
  await api.putRecoveryBackup(jwt, {
@@ -3423,6 +3444,7 @@ async function createDecaneConnect(config) {
3423
3444
  }
3424
3445
  addresses.evm = evmAddress = confirmed.evm;
3425
3446
  addresses.solana = solanaAddress = confirmed.solana;
3447
+ addresses.tron = tronAddress = confirmed.tron ?? evmToTronAddress2(confirmed.evm);
3426
3448
  if (config.offerRecoveryAtSignup !== false && config.onRecoveryShareOffer) {
3427
3449
  try {
3428
3450
  const choice = await config.onRecoveryShareOffer({ evmAddress, solanaAddress });
@@ -3446,7 +3468,7 @@ async function createDecaneConnect(config) {
3446
3468
  }
3447
3469
  async function returningUserUnlock(userId, jwt) {
3448
3470
  const rawAddresses = await api.getAddresses(jwt);
3449
- const recordedAddresses = rawAddresses.evm && rawAddresses.solana ? { evm: rawAddresses.evm, solana: rawAddresses.solana } : null;
3471
+ const recordedAddresses = rawAddresses.evm && rawAddresses.solana ? { evm: rawAddresses.evm, solana: rawAddresses.solana, tron: rawAddresses.tron ?? evmToTronAddress2(rawAddresses.evm) } : null;
3450
3472
  const stored = await storage.getShare(userId);
3451
3473
  let deviceShare;
3452
3474
  if (!stored) {
@@ -3528,7 +3550,7 @@ async function createDecaneConnect(config) {
3528
3550
  throw new ShareCorruptedError();
3529
3551
  }
3530
3552
  const rawAddresses = await api.getAddresses(result.jwt);
3531
- const recordedAddresses = rawAddresses.evm && rawAddresses.solana ? { evm: rawAddresses.evm, solana: rawAddresses.solana } : null;
3553
+ const recordedAddresses = rawAddresses.evm && rawAddresses.solana ? { evm: rawAddresses.evm, solana: rawAddresses.solana, tron: rawAddresses.tron ?? evmToTronAddress2(rawAddresses.evm) } : null;
3532
3554
  const addresses = await session.start(deviceShare, result.jwt, recordedAddresses);
3533
3555
  zeroize(deviceShare);
3534
3556
  auth = { jwt: result.jwt, userId, addresses };
@@ -3660,6 +3682,10 @@ async function createDecaneConnect(config) {
3660
3682
  const sig = await signSolanaMessage(tee, req.chain, msg, auth?.jwt);
3661
3683
  return bufferToB64u(sig);
3662
3684
  }
3685
+ if (req.chain.startsWith("tron:")) {
3686
+ const msg = typeof req.message === "string" ? req.message : new TextDecoder().decode(req.message);
3687
+ return tee.sign({ chain: req.chain, kind: "message", payload: msg }, auth?.jwt);
3688
+ }
3663
3689
  throw new CallSequenceError(`Unsupported chain: ${req.chain}`);
3664
3690
  },
3665
3691
  async sendTransaction(req) {
@@ -3761,6 +3787,14 @@ async function createDecaneConnect(config) {
3761
3787
  const solChain = config.chains.find((c) => c.startsWith("solana:")) ?? "solana:mainnet";
3762
3788
  return signSolanaTransaction(tee, solChain, tx, auth?.jwt);
3763
3789
  },
3790
+ async signTronTransaction(rawDataHex) {
3791
+ const tee = session.requireActive();
3792
+ const tronChain = config.chains.find((c) => c.startsWith("tron:")) ?? "tron:mainnet";
3793
+ return tee.sign(
3794
+ { chain: tronChain, kind: "transaction", payload: rawDataHex.replace(/^0x/, "") },
3795
+ auth?.jwt
3796
+ );
3797
+ },
3764
3798
  async disconnect() {
3765
3799
  session.end();
3766
3800
  if (auth?.jwt) {
@@ -3916,12 +3950,19 @@ function b64uToBuffer(b64u) {
3916
3950
  function toHex2(bytes) {
3917
3951
  return "0x" + Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
3918
3952
  }
3953
+ function evmToTronAddress2(evmAddress) {
3954
+ const hex41 = "41" + evmAddress.toLowerCase().replace(/^0x/, "");
3955
+ const checksum = sha2562(sha2562("0x" + hex41)).slice(2, 10);
3956
+ return encodeBase582("0x" + hex41 + checksum);
3957
+ }
3919
3958
  async function deriveAddressesFromShares(a, b) {
3920
3959
  const master = await combineShares(a, b);
3921
3960
  try {
3961
+ const evm = new Wallet(toHex2(master)).address;
3922
3962
  return {
3923
- evm: new Wallet(toHex2(master)).address,
3924
- solana: Keypair.fromSeed(master).publicKey.toBase58()
3963
+ evm,
3964
+ solana: Keypair.fromSeed(master).publicKey.toBase58(),
3965
+ tron: evmToTronAddress2(evm)
3925
3966
  };
3926
3967
  } finally {
3927
3968
  zeroize(master);
@@ -5943,6 +5984,11 @@ function DecaneKit({ config, children }) {
5943
5984
  if (!sdk) throw new Error("Social wallet not connected");
5944
5985
  return sdk.signSolanaTransaction(tx);
5945
5986
  }, []);
5987
+ const socialSignTronTransaction = useCallback3(async (rawDataHex) => {
5988
+ const sdk = socialRef.current;
5989
+ if (!sdk) throw new Error("Social wallet not connected");
5990
+ return sdk.signTronTransaction(rawDataHex);
5991
+ }, []);
5946
5992
  const socialSignTypedData = useCallback3(async (req) => {
5947
5993
  const sdk = socialRef.current;
5948
5994
  if (!sdk) throw new Error("Social wallet not connected");
@@ -6033,6 +6079,7 @@ function DecaneKit({ config, children }) {
6033
6079
  socialGetBalances,
6034
6080
  socialGetEthereumProvider,
6035
6081
  socialSignAuthorization,
6082
+ socialSignTronTransaction,
6036
6083
  socialGetAccessToken,
6037
6084
  socialSignSolanaTransaction,
6038
6085
  socialSignTypedData,
@@ -6253,6 +6300,7 @@ function useSocialWallet() {
6253
6300
  socialSignMessage,
6254
6301
  socialSendTransaction,
6255
6302
  socialSignSolanaTransaction,
6303
+ socialSignTronTransaction,
6256
6304
  socialSignTypedData,
6257
6305
  socialGetBalance,
6258
6306
  socialGetBalances,
@@ -6295,6 +6343,10 @@ function useSocialWallet() {
6295
6343
  (tx) => run(() => socialSignSolanaTransaction(tx)),
6296
6344
  [socialSignSolanaTransaction]
6297
6345
  );
6346
+ const signTronTransaction = useCallback4(
6347
+ (rawDataHex) => run(() => socialSignTronTransaction(rawDataHex)),
6348
+ [socialSignTronTransaction]
6349
+ );
6298
6350
  const signTypedData = useCallback4(
6299
6351
  (req) => run(() => socialSignTypedData(req)),
6300
6352
  [socialSignTypedData]
@@ -6376,6 +6428,7 @@ function useSocialWallet() {
6376
6428
  signMessage,
6377
6429
  sendTransaction,
6378
6430
  signSolanaTransaction: signSolanaTransaction2,
6431
+ signTronTransaction,
6379
6432
  signTypedData,
6380
6433
  // Balances (native token; read-only, works while locked)
6381
6434
  getBalance,