()
| 15 | import { logger } from './logger'; |
| 16 | |
| 17 | export async function doAuth(): Promise<Credentials | null> { |
| 18 | console.clear(); |
| 19 | console.log('\nMobile Authentication\n'); |
| 20 | |
| 21 | // Generating ephemeral key |
| 22 | const secret = new Uint8Array(randomBytes(32)); |
| 23 | const keypair = tweetnacl.box.keyPair.fromSecretKey(secret); |
| 24 | |
| 25 | // Create a new authentication request |
| 26 | try { |
| 27 | await axios.post(`${configuration.serverUrl}/v1/auth/request`, { |
| 28 | publicKey: encodeBase64(keypair.publicKey), |
| 29 | supportsV2: true |
| 30 | }); |
| 31 | } catch (error) { |
| 32 | console.log('Failed to create authentication request, please try again later.'); |
| 33 | return null; |
| 34 | } |
| 35 | |
| 36 | console.log('Scan this QR code with your Consortium mobile app:\n'); |
| 37 | |
| 38 | const authUrl = 'consortium://terminal?' + encodeBase64Url(keypair.publicKey); |
| 39 | displayQRCode(authUrl); |
| 40 | |
| 41 | console.log('\nOr manually enter this URL:'); |
| 42 | console.log(authUrl); |
| 43 | console.log(''); |
| 44 | |
| 45 | return await waitForAuthentication(keypair); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Wait for authentication to complete and return credentials |
no test coverage detected