@@ -2,7 +2,13 @@ import { BaseCoin } from '@bitgo/statics';
22import { Keychain } from '@bitgo/sdk-core' ;
33import { encrypt } from '@bitgo/sdk-api' ;
44import * as assert from 'assert' ;
5- import { GenerateQrDataParams , MasterPublicKeyQrDataEntry , QrData , QrDataEntry } from './types' ;
5+ import {
6+ GenerateLightningQrDataParams ,
7+ GenerateQrDataParams ,
8+ MasterPublicKeyQrDataEntry ,
9+ QrData ,
10+ QrDataEntry ,
11+ } from './types' ;
612
713function getPubFromKey ( key : Keychain ) : string | undefined {
814 switch ( key . type ) {
@@ -123,6 +129,15 @@ function generateUserMasterPublicKeyQRData(publicKey: string): MasterPublicKeyQr
123129 } ;
124130}
125131
132+ function generatePasscodeQrData ( passphrase : string , passcodeEncryptionCode : string ) : QrDataEntry {
133+ const encryptedWalletPasscode = encrypt ( passcodeEncryptionCode , passphrase ) ;
134+ return {
135+ title : 'D: Encrypted wallet Password' ,
136+ description : 'This is the wallet password, encrypted client-side with a key held by BitGo.' ,
137+ data : encryptedWalletPasscode ,
138+ } ;
139+ }
140+
126141function generateBackupMasterPublicKeyQRData ( publicKey : string ) : MasterPublicKeyQrDataEntry {
127142 return {
128143 title : 'F: Master Backup Public Key' ,
@@ -159,13 +174,30 @@ export function generateQrData({
159174 } ;
160175
161176 if ( passphrase && passcodeEncryptionCode ) {
162- const encryptedWalletPasscode = encrypt ( passcodeEncryptionCode , passphrase ) ;
177+ qrData . passcode = generatePasscodeQrData ( passphrase , passcodeEncryptionCode ) ;
178+ }
163179
164- qrData . passcode = {
165- title : 'D: Encrypted wallet Password' ,
166- description : 'This is the wallet password, encrypted client-side with a key held by BitGo.' ,
167- data : encryptedWalletPasscode ,
168- } ;
180+ return qrData ;
181+ }
182+
183+ export function generateLightningQrData ( {
184+ userAuthKeychain,
185+ passcodeEncryptionCode,
186+ passphrase,
187+ } : GenerateLightningQrDataParams ) : QrData {
188+ assert . ok ( userAuthKeychain . encryptedPrv , 'userAuthKeychain must have an encryptedPrv' ) ;
189+
190+ const qrData : QrData = {
191+ user : {
192+ title : 'A: User Auth Key' ,
193+ description :
194+ 'This is your user authentication private key, encrypted with your wallet password.\r\nIt is used to authenticate payment and wallet operations.' ,
195+ data : userAuthKeychain . encryptedPrv ,
196+ } ,
197+ } ;
198+
199+ if ( passphrase && passcodeEncryptionCode ) {
200+ qrData . passcode = generatePasscodeQrData ( passphrase , passcodeEncryptionCode ) ;
169201 }
170202
171203 return qrData ;
0 commit comments