import { flattened } from '@airgap/angular-core' ; import { AccountShareResponse , AirGapWallet , AirGapWalletStatus , IACMessageDefinitionObjectV3 , IACMessageType } from '@airgap/coinlib-core' ; import { generateId } from '@airgap/coinlib-core/serializer-v3/utils/generateId' ; import { Injectable } from '@angular/core' ; import { MnemonicSecret } from '../../models/secret' ; import { SecretsService } from '../secrets/secrets.service' ; @ Injectable ( { providedIn : 'root' } ) export class ShareUrlService { constructor ( private readonly secretsService ) { } public async generateShareWalletURL ( wallet ) { const secret = this . secretsService . findByPublicKey ( wallet . publicKey ) ; const accountShareResponse = { publicKey : wallet . publicKey , isExtendedPublicKey : wallet . isExtendedPublicKey , derivationPath : wallet . derivationPath , masterFingerprint : wallet . masterFingerprint , isActive : wallet . status === AirGapWalletStatus . ACTIVE , groupId : secret . fingerprint ?? '' , groupLabel : secret . label ?? '' } ; const deserializedTxSigningRequest = { id : generateId ( 8 ) , protocol : wallet . protocol . identifier , type : IACMessageType . AccountShareResponse , payload : accountShareResponse } ; if ( deserializedTxSigningRequest . type === IACMessageType . AccountShareResponse ) { deserializedTxSigningRequest . payload ; } return [ deserializedTxSigningRequest ] ; } public async generateShareSecretsURL ( secrets ) { const deserializedTxSigningRequests = flattened ( secrets . map ( ( secret ) => { return secret . wallets . filter ( ( wallet ) => wallet . status !== AirGapWalletStatus . DELETED ) . map ( ( wallet ) => { const accountShareResponse = { publicKey : wallet . publicKey , isExtendedPublicKey : wallet . isExtendedPublicKey , derivationPath : wallet . derivationPath , masterFingerprint : wallet . masterFingerprint , isActive : wallet . status === AirGapWalletStatus . ACTIVE , groupId : secret . fingerprint , groupLabel : secret . label } ; return { id : generateId ( 8 ) , protocol : wallet . protocol . identifier , type : IACMessageType . AccountShareResponse , payload : accountShareResponse } ; } ) ; } ) ) ; return deserializedTxSigningRequests ; } }