77 decryptAppPairingToken ,
88 generateAppPairingKeyPair ,
99} from "@/utils/appPairingCrypto" ;
10+ import { emojiHash } from "@/utils/emojiHash" ;
1011import { openBrowser } from "@/utils/browser" ;
1112import { renderQrCode } from "@/utils/qrCode" ;
1213
@@ -225,6 +226,7 @@ async function loginWithAppPairing(context: CommandContext): Promise<string> {
225226 const keyPair = generateAppPairingKeyPair ( ) ;
226227 const publicKey = keyPair . publicKeyBase64 ;
227228 const secretKey = keyPair . secretKey ;
229+ const emoji = formatEmojiHash ( keyPair . publicKeyBytes ) ;
228230
229231 const initial = await requestAppPairing ( context . env , appId , publicKey ) ;
230232
@@ -239,7 +241,7 @@ async function loginWithAppPairing(context: CommandContext): Promise<string> {
239241 const pairingUrl = buildPairingUrl ( initial . requestId ) ;
240242 const method = await selectAuthMethod ( ) ;
241243
242- await presentAppPairing ( method , pairingUrl , initial . requestId ) ;
244+ await presentAppPairing ( method , pairingUrl , initial . requestId , emoji ) ;
243245 console . log ( "Waiting for authorization..." ) ;
244246
245247 return await pollForAppToken ( {
@@ -264,10 +266,14 @@ async function selectAuthMethod(): Promise<DeviceAuthMethod> {
264266async function presentAppPairing (
265267 method : DeviceAuthMethod ,
266268 pairingUrl : string ,
267- requestId : string
269+ requestId : string ,
270+ emojiHashValue : string | null
268271) : Promise < void > {
269272 console . log ( `Pairing request: ${ requestId } ` ) ;
270273 console . log ( `Open this URL to approve the app: ${ pairingUrl } ` ) ;
274+ if ( emojiHashValue ) {
275+ console . log ( `Emoji hash: ${ emojiHashValue } ` ) ;
276+ }
271277
272278 if ( method === "browser" ) {
273279 const opened = await openBrowser ( pairingUrl ) ;
@@ -281,6 +287,14 @@ async function presentAppPairing(
281287 console . log ( qrCode ) ;
282288}
283289
290+ function formatEmojiHash ( publicKeyBytes : Uint8Array ) : string | null {
291+ const emojis = emojiHash ( publicKeyBytes , 4 ) ;
292+ if ( emojis . length === 0 ) {
293+ return null ;
294+ }
295+ return emojis . join ( " " ) ;
296+ }
297+
284298async function pollForAppToken ( opts : {
285299 env : Environment ;
286300 appId : string ;
0 commit comments