@clawchatsai/connector 0.0.55 β†’ 0.0.56

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.
Files changed (2) hide show
  1. package/dist/index.js +62 -20
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -813,29 +813,38 @@ async function handleSetup(token) {
813
813
  });
814
814
  });
815
815
  }
816
- async function enrollTotp(config) {
816
+ async function enrollTotp(config, existingSecret) {
817
817
  const readline = await import('node:readline');
818
818
  const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
819
819
  const ask = (q) => new Promise(r => rl.question(q, r));
820
820
  try {
821
- // Generate TOTP secret
822
- const totpSecret = generateTotpSecret();
823
- const email = config.google?.authorizedEmail || config.userId;
824
- const otpauthUri = buildOtpauthUri(totpSecret, email);
825
- // Format secret with spaces for readability
826
- const formatted = totpSecret.match(/.{1,4}/g)?.join(' ') || totpSecret;
827
- console.log('');
828
- console.log(' πŸ” Setting up two-factor authentication');
829
- console.log('');
830
- console.log(' Open this link to scan the QR code with your authenticator app:');
831
- console.log(` ${config.serverUrl.replace('wss://', 'https://').replace(/\/ws\/?$/, '')}/totp-setup#${totpSecret}`);
832
- console.log('');
833
- console.log(` Or enter this code manually: ${formatted}`);
834
- console.log('');
835
- console.log(" Don't have an authenticator app?");
836
- console.log(' Google Authenticator: https://apps.apple.com/app/google-authenticator/id388497605');
837
- console.log(' https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2');
838
- console.log('');
821
+ let totpSecret;
822
+ if (existingSecret) {
823
+ // Reusing secret from another gateway β€” strip spaces, uppercase
824
+ totpSecret = existingSecret.replace(/\s+/g, '').toUpperCase();
825
+ console.log('');
826
+ console.log(' πŸ” Verifying existing TOTP secret…');
827
+ console.log('');
828
+ }
829
+ else {
830
+ // Generate a brand new TOTP secret
831
+ totpSecret = generateTotpSecret();
832
+ const email = config.google?.authorizedEmail || config.userId;
833
+ void buildOtpauthUri(totpSecret, email); // keep import used
834
+ const formatted = totpSecret.match(/.{1,4}/g)?.join(' ') || totpSecret;
835
+ console.log('');
836
+ console.log(' πŸ” Setting up two-factor authentication');
837
+ console.log('');
838
+ console.log(' Open this link to scan the QR code with your authenticator app:');
839
+ console.log(` ${config.serverUrl.replace('wss://', 'https://').replace(/\/ws\/?$/, '')}/totp-setup#${totpSecret}`);
840
+ console.log('');
841
+ console.log(` Or enter this code manually: ${formatted}`);
842
+ console.log('');
843
+ console.log(" Don't have an authenticator app?");
844
+ console.log(' Google Authenticator: https://apps.apple.com/app/google-authenticator/id388497605');
845
+ console.log(' https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2');
846
+ console.log('');
847
+ }
839
848
  // Verification loop
840
849
  let verified = false;
841
850
  for (let attempt = 0; attempt < 5; attempt++) {
@@ -886,6 +895,27 @@ async function enrollTotp(config) {
886
895
  return false;
887
896
  }
888
897
  }
898
+ async function handleShowTotp() {
899
+ const config = loadConfig();
900
+ if (!config) {
901
+ console.error('ClawChats not configured. Run: openclaw clawchats setup <token>');
902
+ return;
903
+ }
904
+ if (!config.totp?.secret) {
905
+ console.error('No TOTP secret found. Run: openclaw clawchats reauth to set one up first.');
906
+ return;
907
+ }
908
+ console.log('');
909
+ console.log('Your TOTP secret (account-level, keep this safe):');
910
+ console.log('');
911
+ console.log(` ${config.totp.secret}`);
912
+ console.log('');
913
+ console.log('To reuse this on a new gateway:');
914
+ console.log(' 1. Generate a setup token at login.clawchats.ai/dashboard');
915
+ console.log(' 2. On the new machine: openclaw clawchats setup <token>');
916
+ console.log(' 3. When prompted for a TOTP secret, paste the value above');
917
+ console.log('');
918
+ }
889
919
  async function handleReauth() {
890
920
  const config = loadConfig();
891
921
  if (!config) {
@@ -896,7 +926,16 @@ async function handleReauth() {
896
926
  console.log('');
897
927
  console.log(' ⚠️ This will invalidate all existing sessions.');
898
928
  console.log(' All connected browsers will need to re-authenticate.');
899
- const success = await enrollTotp(config);
929
+ console.log('');
930
+ const readline = await import('node:readline');
931
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
932
+ const ask = (q) => new Promise(r => rl.question(q, r));
933
+ let existingSecret;
934
+ const reuseAnswer = await ask(' Reuse TOTP from another gateway? Paste secret (or press Enter to generate new): ');
935
+ rl.close();
936
+ if (reuseAnswer.trim())
937
+ existingSecret = reuseAnswer.trim();
938
+ const success = await enrollTotp(config, existingSecret);
900
939
  if (success) {
901
940
  console.log(' All previous sessions have been invalidated.');
902
941
  console.log(' Restart the gateway for changes to take effect: systemctl --user restart openclaw-gateway');
@@ -1073,6 +1112,9 @@ const plugin = {
1073
1112
  cmd.command('reauth')
1074
1113
  .description('Reset two-factor authentication (new TOTP secret + invalidate sessions)')
1075
1114
  .action(() => handleReauth());
1115
+ cmd.command('show-totp')
1116
+ .description('Show your TOTP secret (use when adding ClawChats to a second gateway)')
1117
+ .action(() => handleShowTotp());
1076
1118
  cmd.command('reset')
1077
1119
  .description('Disconnect and remove all ClawChats data')
1078
1120
  .action(() => handleReset());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawchatsai/connector",
3
- "version": "0.0.55",
3
+ "version": "0.0.56",
4
4
  "type": "module",
5
5
  "description": "ClawChats OpenClaw plugin β€” P2P tunnel + local API bridge",
6
6
  "main": "dist/index.js",