我如何从 xpub 中导出 BTC m44 地址?

How can I derive BTC m44 addresses from xpub?

我查看了斯旺的地址推导库https://github.com/swan-bitcoin/xpub-tool

我试图获取 m44 地址,但我得到了 m84。为什么?你知道强制returnm44是什么参数吗?我试图通过 path: "m/44'/0'/0'/0", 但没有帮助。

你有什么想法吗?

addressFromXPub("xpub6C5oXscLYZwgq2DB42TFC32QcoPa1MeCWUNPZSjydunniCM77TRcBfFnjScJeToVXS5RBDr53Ls5RXvDHujmFSL4Fqc9kkpsMjU1vg68xv7"
  );

export const addressFromXPub = (key) => {
  console.log(
    addressesFromExtPubKey({
      extPubKey: key,
      network: "mainnet",
      addressCount: 3,
    })
  );
};
[
    {path: "m/84'/0'/0'/0/0", address: "bc1qfgnqm6g46ys0h9gh606m76wemka2rrttrac90x"
    },
    {path: "m/84'/0'/0'/0/1", address: "bc1qnvzdj2m4wsrcrtl30j5c304qa77v4h2s8ajp0r"
    },
    {path: "m/84'/0'/0'/0/2", address: "bc1qjf5u77e6clwkxgf7a0shw7zq2nhqr4vjys7an0"
    }
]

来自官方docs

Address derivation will default to bech32 (native SegWit) unless a different purpose is specified. For example: to derive wrapped SegWit addresses (starting with 3...) specify the appropriate purpose with purpose: Purpose.P2SH.

因此,要获得 m44,您需要设置 purpose:Purpose.P2PKH

样本

const lib = require('@swan-bitcoin/xpub-lib/lib/derivation')
const Purpose = require('@swan-bitcoin/xpub-lib/lib/purpose')

console.log(
    lib.addressesFromExtPubKey({
        extPubKey: 'xpub6C5oXscLYZwgq2DB42TFC32QcoPa1MeCWUNPZSjydunniCM77TRcBfFnjScJeToVXS5RBDr53Ls5RXvDHujmFSL4Fqc9kkpsMjU1vg68xv7',
        network: "mainnet",
        addressCount: 3,
        purpose: Purpose.Purpose.P2PKH
    })
);

结果:

[
  {
    path: "m/44'/0'/0'/0/0",
    address: '17m4bFvDU8wNn5XAyXRqQUKUPLf5GByybS'
  },
  {
    path: "m/44'/0'/0'/0/1",
    address: '1F8fYbrGGfSYyKfWGzz4YdFbNrMbdRzJer'
  },
  {
    path: "m/44'/0'/0'/0/2",
    address: '1EMAQrBE3ZmhQcQLDWKfakMognoXotM8pU'
  }
]