Skip to content

Instantly share code, notes, and snippets.

@kannapoix
Created August 24, 2019 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kannapoix/45d3440c887c6b5d8c12e32bbe5040fb to your computer and use it in GitHub Desktop.
Save kannapoix/45d3440c887c6b5d8c12e32bbe5040fb to your computer and use it in GitHub Desktop.
# 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