XMR的技术概念

Monero 的技术点

参考文档:

  • https://monerodocs.org/
  • https://github.com/monerobook/monerobook/blob/master/chapters/5.md
  • wallet_rpc 文档(不是最新): https://web.getmonero.org/resources/developer-guides/wallet-rpc.html
  • daemon_rpc文档(不是最新): https://web.getmonero.org/resources/developer-guides/daemon-rpc.html
  • 最新版的WalletRPC接口列表: https://github.com/monero-project/monero/blob/756f06cd839a3260407d28ed6084435b0b8b744c/src/wallet/wallet_rpc_server.h

几个可执行文件的用途

ExecutableDescription
monerodThe full node daemon. Does not require a wallet. Documentation.
monero-wallet-guiWallet logic and graphical user interface. Requires monerod running.
monero-wallet-cliWallet logic and commandline user interface. Requires monerod running.
monero-wallet-rpcWallet logic and HTTP API (JSON-RPC protocol). Requires monerod running.
monero-blockchain-export(导出本地区块数据)Tool to export blockchain to blockchain.raw file.
monero-blockchain-import(导入下载好区块数据的工具)Tool to import blockchain.raw - ideally your own trusted copy.
monero-gen-trusted-multisig(多重签名相关)Tool to generate a set of multisig wallets. See chapter on multisignatures.
monero-blockchain-mark-spent-outputs(普通开发者不需要关心)Advanced tool to mitigate potential privacy issues related to Monero forks. You normally shouldn’t be concerned with that. See the commit and pull request.
monero-blockchain-usage(普通开发者不需要关心)Advanced tool to mitigate potential privacy issues related to Monero forks. You normally shouldn’t be concerned with that. See the commit and the pull request.
monero-blockchain-ancestry(普通开发者不需要关心)Advanced research tool to learn ancestors of a transaction, block or chain. Irrelevant for normal users. See this pull request.
monero-blockchain-depth(普通开发者不需要关心)Advanced research tool to learn depth of a transaction, block or chain. Irrelevant for normal users. See this commit.

交互

https://monerodocs.org/interacting/overview/

monorodmonero-wallet-rpc的API是分开的 (与比特币的bitcoind不同), 即:

  • monorod只有节点相关的API,
  • monero-wallet-rpc只有钱包相关的API,

所以, 需要同时运行两个守护进程才能使用所有API(也可以使用信任的远程公共节点).

Executablep2p networknode commands via keyboardnode HTTP APIwallet commands via keyboardwallet HTTP APIwallet via GUI
monerod
monero-wallet-cli
monero-wallet-rpc
monero-wallet-gui

monerod数据目录

https://monerodocs.org/interacting/overview/#data-directory

  • 在Linux上默认目录是$HOME/.bitmonero/如果是测试网, 则会生成子目录stagenettestnet

  • 可以通过 --config-file指定配置文件bitmonero.conf的目录

  • 可以通过在 --data-dir 制定区块数据存放目录

  • data目录

    • lmdb/ - the blockchain database directory
    • p2pstate.bin - saved memory of discovered and rated peers
    • bitmonero.log - log file

启动与停止

  • 后台启动 monerod --config-file=/root/.bitmonero.conf --detach (如果需要同步全节点, 可以参考上一篇关于同步全节点文档)

  • 优雅的停止 ./monerod exit

RPC API

https://monerodocs.org/interacting/monerod-reference/#node-rpc-api

  • monerod 提供了一下数据

    • 区块链数据(状态, 区块内容, 交易, 等等…)
    • 节点本身的状态信息和数据等
    • 提供钱包的接口(send transactions)

公私钥,地址, 钱包等相关概念

可以参考: https://www.monero.how/monero-glossary

  • mnemonic seed (助记词) , 即 HD(分层确定性钱包) 中的助记词

  • primary address (原始地址), 即索引为0的子账户

  • Spendable Wallet (可转账钱包)

  • View Only Wallet (观察钱包)

  • PaymentID

    https://monero.stackexchange.com/a/4343

    payment id 是交易附加的一段信息

  • Private spend key

    参考: https://monerodocs.org/cryptography/asymmetric/private-key/#private-spend-key

    真正的私钥, 用来花费门罗币的私钥, 即进行交易签名的私钥

  • Private view key

    参考: https://monerodocs.org/cryptography/asymmetric/private-key/#private-view-key

    用来解密入账交易(incoming), 因为门罗币的交易信息(源地址,目的地址,金额等等)是不透明的.

  • Public view key

    用来识别入账交易( 交易的发送方会使用 Public view key 对交易进行加密 ), 接收方则需用 Private view key 对内容进行解密.

  • Public spend key

    用来指定UTXO的接收方, (交易的发送方会制定 UTXO的公钥为 Public Spend Key) , 接收方花费此笔UTXO 时则需要 使用 Private Spend Key 进行签名

  • Tx_Key

    用于证明交易 详情可以参考RPC接口 get_tx_keycheck_tx_key

地址分类

Standard 标准地址

https://monerodocs.org/public-address/standard-address/

  • 即默认地址, 有 public spend key public veiw key组成
  • 一共 69 个字节, 经过特殊的base58编码(和一般的base58不同)形成95个字符长度字符串
IndexSize in bytesDescription
01identifies the network and address type; 18 - main chain; 53 - test chain; stagenet是24
132public spend key
3332public view key
654checksum ([Keccak-f1600] hash of the previous 65 bytes, trimmed to first 4 bytes)

标准地址生成流程

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

标准地址生成源码

def public_address(self, net=const.NET_MAIN):
    """Returns the master :class:`Address <monero.address.Address>` represented by the seed.

    :param net: the network, one of `const.NET_*`; default is `const.NET_MAIN`

    :rtype: :class:`Address <monero.address.Address>`
    """
    # backward compatibility
    _net = net[:-3] if net.endswith('net') else net
    if _net != net:
        warnings.warn(
            "Argument '{:s}' is deprecated and will not be accepted in 0.8, "
            "use one of monero.const.NET_*".format(net),
            DeprecationWarning)
        net = _net
    if net not in const.NETS:
        raise ValueError(
            "Invalid net argument '{:s}'. Must be one of monero.const.NET_*".format(net))
    netbyte = (18, 53, 24)[const.NETS.index(net)]
    data = "{:x}{:s}{:s}".format(netbyte, self.public_spend_key(),self.public_view_key())
    h = keccak_256()
    h.update(unhexlify(data))
    checksum = h.hexdigest()
    return address(base58.encode(data + checksum[0:8]))
Subaddress 子地址

https://monerodocs.org/public-address/subaddress/

这里的子地址, 并不是真正意义上的子地址, 和BTC的地址概念不同

子地址生成流程

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

问题: m 虽然是 sub_private_view_key 但是似乎并作为解析output的view key使用

Subaddress地址生成源码


def get_address(master_addr, major, minor, seed : Seed):
    """
    Calculates sub-address for account index (`major`) and address index within
    the account (`minor`).

    :rtype: :class:`BaseAddress <monero.address.BaseAddress>`
    """
    # ensure indexes are within uint32
    if major < 0 or major >= 2 ** 32:
        raise ValueError('major index {} is outside uint32 range'.format(major))
    if minor < 0 or minor >= 2 ** 32:
        raise ValueError('minor index {} is outside uint32 range'.format(minor))
    master_address = master_addr  #self.address()
    if major == minor == 0:  #如果是  (0, 0) 则直接返回
        return master_address


    priv_view_key =  seed.secret_view_key()
    master_svk = unhexlify(priv_view_key)

    pub_spend_key = seed.public_spend_key()
    master_psk = unhexlify( pub_spend_key  )

    # master_svk = unhexlify(self.view_key())
    # master_psk = unhexlify(self.address().spend_key())

    # m = Hs("SubAddr\0" || master_svk || major || minor)
    hsdata = b''.join([
        b'SubAddr\0', master_svk,
        struct.pack('<I', major), struct.pack('<I', minor)])
    m = keccak_256(hsdata).digest()
    
    # D = master_psk + m * B
    D = ed25519.edwards_add(
        ed25519.decodepoint(master_psk),
        ed25519.scalarmult_B(ed25519.decodeint(m)))

    # C = master_svk * D
    C = ed25519.scalarmult(D, ed25519.decodeint(master_svk))
    netbyte = bytearray([const.SUBADDR_NETBYTES[const.NETS.index(master_address.net)]])
    data = netbyte + ed25519.encodepoint(D) + ed25519.encodepoint(C)
    checksum = keccak_256(data).digest()[:4]
    return address.SubAddress(base58.encode(hexlify(data + checksum)))

更多关于子地址: 3_XMR地址生成.md

Integrated 集成地址
  • 一共77字节, 经过base58编码后地址字符串长度为: 106 字符
IndexSize in bytesDescription
01identifies the network and address type; 19 - main chain; 54 - test chain
132public spend key
3332public view key
658compact payment ID - 8 bytes randomly generated by the recipient; note that it does not need encryption in the address itself but it is hidden in a transaction paying to integrated address to prevent linking payment with the address by external observers
734checksum ([Keccak-f1600] hash of the previous 73 bytes, trimmed to first 4 bytes)

主链和测试链

https://monerodocs.org/infrastructure/networks/

  • Mainnet

    主链 , 18080 P2P , 18081 JSON-RPC server

  • Stagenet

    • 测试链, 开发者用, 38080 P2P , 38081 JSON-RPC server
    • 可以指定远程 daemon节点 monero-stagenet.exan.tech:38081
    • 获取测试币的水龙头: https://community.xmr.to/faucet/stagenet/
  • Testnet 测试链

    • 测试链, 开发者用
  • Private Testnet 私有测试链

钱包客户端

monero-wallet-gui
  • 下载地址: https://github.com/monero-project/monero-gui/releases

  • 使用方法, 可以选择测试网, “高级设置>>stagenet” , 远程节点设置为monero-stagenet.exan.tech:38081

    外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

monero-wallet-cli
  • 使用方法: monero-wallet-cli --stagenet --daemon-address monero-stagenet.exan.tech:38081 --trusted-daemon --wallet-file=/root/.bitmonero/stagenet/wallet_files/yqq_stagenet
  • 下载地址: https://github.com/monero-project/monero/releases

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

区块和交易

移至: 4_XMR交易过程.md

  • 14
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值