Skip to content

Instantly share code, notes, and snippets.

@kannapoix

kannapoix/bip47.rb

Created Aug 24, 2019
Embed
What would you like to do?
# bip47 Pyament Code @ https://github.com/bitcoin/bips/blob/master/bip-0047.mediawiki#version-1
# bitcoionrb @ https://github.com/chaintope/bitcoinrb
require 'bitcoin'
include Bitcoin
bip32_master = Bitcoin::ExtKey.generate_master('64dca76abc9c6f0cf3d212d248c380c4622c8f93b2c425ec6a5567fd5db57e10d3e6f94a2f6af4ac2edb8998072aad92098db73558c323777abf5bd1082d970a')
depth3 = bip32_master.derive(47, harden=true).derive(0, harden=true).derive(0, harden=true)
chain_code = depth3.chain_code
prefix = '47'
byte0 = '01'
byte1 = '00'
byte2 = '02'
byte3_34 = depth3.pub.slice(2...depth3.pub.length)
byte35_66 = chain_code.unpack('H*').first
byte67_79 = '0' * 26
row_payment_code = prefix + byte0 + byte1 + byte2 + byte3_34 + byte35_66 + byte67_79
base58_payment_code = Bitcoin::Base58.encode(row_payment_code + Bitcoin.calc_checksum(row_payment_code))
p base58_payment_code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment