@@ -5,13 +5,14 @@ import * as assert from 'assert';
55import {
66 GenerateLightningQrDataParams ,
77 GenerateQrDataParams ,
8- GenerateVaultQrDataParams ,
8+ GenerateSafeQrDataParams ,
9+ KeycardEntity ,
910 MasterPublicKeyQrDataEntry ,
1011 QrData ,
1112 QrDataEntry ,
12- VaultKeycardRoots ,
13- VaultRootKeyType ,
14- VAULT_ROOT_ORDER ,
13+ SafeKeycardRoots ,
14+ SafeRootKeyType ,
15+ SAFE_ROOT_ORDER ,
1516} from './types' ;
1617
1718function getPubFromKey ( key : Keychain ) : string | undefined {
@@ -135,13 +136,15 @@ function generateUserMasterPublicKeyQRData(publicKey: string): MasterPublicKeyQr
135136async function generatePasscodeQrData (
136137 passphrase : string ,
137138 passcodeEncryptionCode : string ,
138- encryptionVersion ?: 1 | 2
139+ encryptionVersion ?: 1 | 2 ,
140+ entityNoun : KeycardEntity = 'wallet'
139141) : Promise < QrDataEntry > {
140- const encryptedWalletPasscode = await encrypt ( passcodeEncryptionCode , passphrase , { encryptionVersion } ) ;
142+ const encryptedPasscode = await encrypt ( passcodeEncryptionCode , passphrase , { encryptionVersion } ) ;
143+ const titleNoun = entityNoun === 'safe' ? 'Safe' : 'Wallet' ;
141144 return {
142- title : ' D: Encrypted Wallet Password' ,
143- description : ' This is the wallet password, encrypted client-side with a key held by BitGo.' ,
144- data : encryptedWalletPasscode ,
145+ title : ` D: Encrypted ${ titleNoun } Password` ,
146+ description : ` This is the ${ entityNoun } password, encrypted client-side with a key held by BitGo.` ,
147+ data : encryptedPasscode ,
145148 } ;
146149}
147150
@@ -220,69 +223,70 @@ export async function generateLightningQrData(params: GenerateLightningQrDataPar
220223 return qrData ;
221224}
222225
223- function selectRootPrivateKey ( keychain : Keychain , slot : VaultRootKeyType , role : 'user' | 'backup' ) : string {
226+ function selectRootPrivateKey ( keychain : Keychain , slot : SafeRootKeyType , role : 'user' | 'backup' ) : string {
224227 // Prefer the compact MPCv2 reduced share; fall back to encryptedPrv (e.g. multisig roots).
225228 const data = keychain . reducedEncryptedPrv ?? keychain . encryptedPrv ;
226- assert . ok ( data , `Vault ${ role } root ${ slot } is missing encrypted private key material` ) ;
229+ assert . ok ( data , `Safe ${ role } root ${ slot } is missing encrypted private key material` ) ;
227230 return data ;
228231}
229232
230- function selectRootPublicKey ( keychain : Keychain , slot : VaultRootKeyType ) : string {
233+ function selectRootPublicKey ( keychain : Keychain , slot : SafeRootKeyType ) : string {
231234 const pub = getPubFromKey ( keychain ) ;
232- assert . ok ( pub , `Vault BitGo root ${ slot } is missing a public key` ) ;
235+ assert . ok ( pub , `Safe BitGo root ${ slot } is missing a public key` ) ;
233236 return pub ;
234237}
235238
236239/**
237240 * Serializes one box's four roots into a single JSON object keyed by rootKeyType, e.g.
238- * `{"secp256k1Multisig":"<encPrv>","ecdsaMpc":"<reducedEncPrv>",...}`. This keeps the vault
241+ * `{"secp256k1Multisig":"<encPrv>","ecdsaMpc":"<reducedEncPrv>",...}`. This keeps the safe
239242 * keycard on the existing 4-box layout — one box (= one QR/data block) per role — with the
240243 * four roots packed into each box's data. `splitKeys` fragments the box if it exceeds the QR
241- * threshold, exactly as for a normal wallet keycard. Reversed by {@link parseVaultKeycardBox }.
244+ * threshold, exactly as for a normal wallet keycard. Reversed by {@link parseSafeKeycardBox }.
242245 */
243- function buildVaultBoxData (
244- roots : Record < VaultRootKeyType , KeychainsTriplet > ,
245- select : ( root : KeychainsTriplet , slot : VaultRootKeyType ) => string
246+ function buildSafeBoxData (
247+ roots : Record < SafeRootKeyType , KeychainsTriplet > ,
248+ select : ( root : KeychainsTriplet , slot : SafeRootKeyType ) => string
246249) : string {
247- const box : VaultKeycardRoots = { } as VaultKeycardRoots ;
248- for ( const slot of VAULT_ROOT_ORDER ) {
250+ const box : SafeKeycardRoots = { } as SafeKeycardRoots ;
251+ for ( const slot of SAFE_ROOT_ORDER ) {
249252 const root = roots [ slot ] ;
250- assert . ok ( root , `Vault is missing the ${ slot } root` ) ;
253+ assert . ok ( root , `Safe is missing the ${ slot } root` ) ;
251254 box [ slot ] = select ( root , slot ) ;
252255 }
253256 return JSON . stringify ( box ) ;
254257}
255258
256259/**
257- * Builds vault keycard QR data in the existing wallet {@link QrData} shape: boxes A (user),
260+ * Builds safe keycard QR data in the existing wallet {@link QrData} shape: boxes A (user),
258261 * B (backup), C (BitGo), D (passcode). Each of A/B/C carries a JSON object of the four roots,
259- * so the vault renders and parses through the same {@link drawKeycard} path as a wallet.
262+ * so the safe renders and parses through the same {@link drawKeycard} path as a wallet.
260263 */
261- export async function generateVaultQrData ( params : GenerateVaultQrDataParams ) : Promise < QrData > {
264+ export async function generateSafeQrData ( params : GenerateSafeQrDataParams ) : Promise < QrData > {
262265 const { roots } = params ;
263266 const qrData : QrData = {
264267 user : {
265268 title : 'A: User Key' ,
266- description : 'Your 4 root private keys, encrypted with your wallet password.' ,
267- data : buildVaultBoxData ( roots , ( root , slot ) => selectRootPrivateKey ( root . userKeychain , slot , 'user' ) ) ,
269+ description : 'Your 4 root private keys, encrypted with your safe password.' ,
270+ data : buildSafeBoxData ( roots , ( root , slot ) => selectRootPrivateKey ( root . userKeychain , slot , 'user' ) ) ,
268271 } ,
269272 backup : {
270273 title : 'B: Backup Key' ,
271- description : 'Your 4 root backup keys, encrypted with your wallet password.' ,
272- data : buildVaultBoxData ( roots , ( root , slot ) => selectRootPrivateKey ( root . backupKeychain , slot , 'backup' ) ) ,
274+ description : 'Your 4 root backup keys, encrypted with your safe password.' ,
275+ data : buildSafeBoxData ( roots , ( root , slot ) => selectRootPrivateKey ( root . backupKeychain , slot , 'backup' ) ) ,
273276 } ,
274277 bitgo : {
275278 title : 'C: BitGo Key' ,
276279 description : 'The public parts of the 4 root keys held by BitGo.' ,
277- data : buildVaultBoxData ( roots , ( root , slot ) => selectRootPublicKey ( root . bitgoKeychain , slot ) ) ,
280+ data : buildSafeBoxData ( roots , ( root , slot ) => selectRootPublicKey ( root . bitgoKeychain , slot ) ) ,
278281 } ,
279282 } ;
280283
281284 if ( params . passphrase && params . passcodeEncryptionCode ) {
282285 qrData . passcode = await generatePasscodeQrData (
283286 params . passphrase ,
284287 params . passcodeEncryptionCode ,
285- params . encryptionVersion
288+ params . encryptionVersion ,
289+ 'safe'
286290 ) ;
287291 }
288292
0 commit comments