-
Notifications
You must be signed in to change notification settings - Fork 17
fix(typecheck): close auth/sqlit/wallet type and API gaps #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -212,6 +212,11 @@ async function authenticateWithDWS( | |
| export const loginCommand = new Command('login') | ||
| .description('Authenticate with Jeju Network using your wallet') | ||
| .option('-n, --network <network>', 'Network to authenticate with', 'testnet') | ||
| .option( | ||
| '--address <address>', | ||
| 'Wallet address to authenticate (required for --external mode)', | ||
| ) | ||
| .option('--signature <signature>', 'Wallet signature from --external flow') | ||
| .option( | ||
| '-k, --private-key <key>', | ||
| 'Private key (or use DEPLOYER_PRIVATE_KEY env)', | ||
|
|
@@ -256,6 +261,15 @@ export const loginCommand = new Command('login') | |
| } | ||
|
|
||
| if (options.external) { | ||
| if (!options.address) { | ||
| logger.error('External auth requires --address.') | ||
| logger.info( | ||
| 'Example: jeju login --external --address 0xYourAddress --network localnet', | ||
| ) | ||
| return | ||
| } | ||
|
|
||
| const address = options.address as Address | ||
| // External signing - output message for user to sign elsewhere | ||
| const nonce = bytesToHex(randomBytes(32)) | ||
| const timestamp = Date.now() | ||
|
|
@@ -266,14 +280,50 @@ export const loginCommand = new Command('login') | |
| timestamp, | ||
| ) | ||
|
|
||
| logger.info('Sign the following message with your wallet:\n') | ||
| console.log('---') | ||
| console.log(message) | ||
| console.log('---\n') | ||
| if (!options.signature) { | ||
| logger.info('Sign the following message with your wallet:\n') | ||
| console.log('---') | ||
| console.log(message) | ||
| console.log('---\n') | ||
|
|
||
| logger.info('Then run:') | ||
| logger.info( | ||
| `jeju login --network ${network} --address ${address} --signature <your-signature>`, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The suggested command omits Useful? React with 👍 / 👎. |
||
| ) | ||
| return | ||
| } | ||
|
|
||
| // Complete external login with provided signature | ||
| const signature = options.signature | ||
| const isValid = await verifyMessage({ address, message, signature }) | ||
| if (!isValid) { | ||
| logger.error('Signature verification failed') | ||
| return | ||
| } | ||
|
|
||
| const authResult = await authenticateWithDWS( | ||
| address, | ||
| signature, | ||
| message, | ||
| network, | ||
| ) | ||
|
|
||
| const credentials: Credentials = { | ||
| version: 1, | ||
| network, | ||
| address, | ||
| keyType: 'external', | ||
| authToken: authResult.token, | ||
| createdAt: Date.now(), | ||
| expiresAt: authResult.expiresAt, | ||
| } | ||
|
|
||
| logger.info('Then run:') | ||
| saveCredentials(credentials) | ||
| logger.success(`Logged in as ${address}`) | ||
| logger.info(`Network: ${network}`) | ||
| logger.info(`Expires at: ${new Date(authResult.expiresAt).toLocaleDateString()}`) | ||
| logger.info( | ||
| `jeju login --network ${network} --signature <your-signature> --address <your-address>`, | ||
| 'Use `jeju login` again if your token expires or you change wallets.', | ||
| ) | ||
| return | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The external flow rebuilds
messagewith a fresh random nonce/timestamp before checkingoptions.signature, so the second invocation cannot verify the signature from the first invocation's printed message. In the two-step flow (--external --addressfirst, then--external --address --signature),verifyMessagewill always fail because the signed payload changed between runs.Useful? React with 👍 / 👎.