MCPcopy Create free account
hub / github.com/NoteProtocol/NoteWallet / createAccount

Method createAccount

src/btc/btc-wallet.ts:56–100  ·  view source on GitHub ↗
(
    rootPath: string = this.rootPath,
    index: number = 0,
    target = 0
  )

Source from the content-addressed store, hash-verified

54 }
55
56 createAccount(
57 rootPath: string = this.rootPath,
58 index: number = 0,
59 target = 0
60 ): IWalletAccount {
61 const account = super.createAccount(rootPath, index, target);
62 const privateKeyBuffer = new PrivateKey(account.privateKey).toBuffer();
63 const publicKeyBuffer = new PublicKey(account.publicKey).toBuffer();
64
65 const xOnlyPubkey = publicKeyBuffer.slice(1, 33);
66
67 // Used for signing, since the output and address are using a tweaked key
68 // We must tweak the signer in the same way.
69 const privateKey = ECPair.fromPrivateKey(privateKeyBuffer);
70 const tweakedPrivateKey = privateKey.tweak(
71 bitcoin.crypto.taggedHash("TapTweak", xOnlyPubkey)
72 );
73
74 account.tweakedPrivateKey = tweakedPrivateKey.toWIF();
75 account.xOnlyPubkey = xOnlyPubkey.toString("hex");
76
77 const network =
78 bitcoin.networks[
79 this.config.network === "livenet" ? "bitcoin" : "testnet"
80 ];
81 const addressP2WPKH = generateP2WPHKAddress(
82 Buffer.from(account.publicKey, "hex"),
83 network
84 );
85 account.mainAddress = addressP2WPKH;
86
87 const addressP2TRNote = generateP2TRNoteAddress(
88 Buffer.from(account.publicKey, "hex"),
89 network
90 );
91 account.tokenAddress = addressP2TRNote;
92
93 const addressP2TRNoteV1 = generateP2TRNoteAddressV1(
94 Buffer.from(account.publicKey, "hex"),
95 network
96 );
97 account.addressP2TRNoteV1 = addressP2TRNoteV1;
98
99 return account;
100 }
101
102 async sendEstimate(toAddresses: ISendToAddress[], feePerKb?: number) {
103 const utxos = await this.fetchAllAccountUtxos();

Callers 3

importMnemonicFunction · 0.80
generateSpecAccountsFunction · 0.80
switchAccountFunction · 0.80

Calls 3

generateP2WPHKAddressFunction · 0.90
generateP2TRNoteAddressFunction · 0.90

Tested by

no test coverage detected