1 import { type WasmAccount, WasmApiBitcoinAddressesCreationPayload } from '@proton/andromeda';
2 import { type DecryptedAddressKey } from '@proton/shared/lib/interfaces';
4 import { signData } from './crypto';
6 export const computeAddress = async (
7 wasmAccount: WasmAccount,
8 walletAccountAddressKey: DecryptedAddressKey,
9 bitcoinAddressIndex?: number | null
11 const { address, index } = bitcoinAddressIndex
12 ? await wasmAccount.peekReceiveAddress(bitcoinAddressIndex)
13 : await wasmAccount.getNextReceiveAddress();
15 const signature = await signData(address, 'wallet.bitcoin-address', [walletAccountAddressKey.privateKey]);
18 BitcoinAddressIndex: index,
19 BitcoinAddress: address,
20 BitcoinAddressSignature: signature,
24 export const removeMasterPrefix = (derivationPath: string) => {
25 return derivationPath.replace(/m\//, '');
28 export const generateBitcoinAddressesPayloadToFillPool = async ({
31 walletAccountAddressKey,
33 addressesToCreate: number;
34 wasmAccount: WasmAccount;
35 walletAccountAddressKey: DecryptedAddressKey;
37 if (addressesToCreate > 0) {
38 const payload = new WasmApiBitcoinAddressesCreationPayload();
40 for (let i = 1; i <= addressesToCreate; i++) {
42 const addressData = await computeAddress(wasmAccount, walletAccountAddressKey);
43 payload.push(addressData);
45 console.error('Could not create bitcoin address creation payload', e);