Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bip32.red
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ bip32key: context [
/local I Il Ir
][
I: checksum/with bin 'SHA512 "Bitcoin seed"
if not secp256/prikey-valid? Il: copy/part I 32 [return none]
if not secp256/privkey-valid? Il: copy/part I 32 [return none]
Ir: copy/part skip I 32 32
reduce [Il Ir]
]
Expand All @@ -38,7 +38,7 @@ bip32key: context [
repend data [pub to binary! index]
]
I: checksum/with data 'SHA512 cpar
if not secp256/prikey-valid? Il: copy/part I 32 [return none]
if not secp256/privkey-valid? Il: copy/part I 32 [return none]
Ir: copy/part skip I 32 32
if none? child: secp256/privkey-tweak-add kpar Il [return none]
reduce [child Ir]
Expand All @@ -56,7 +56,7 @@ bip32key: context [
pub: secp256/serialize-pubkey kpar true
repend data [pub to binary! index]
I: checksum/with data 'SHA512 cpar
if not secp256/prikey-valid? Il: copy/part I 32 [return none]
if not secp256/privkey-valid? Il: copy/part I 32 [return none]
Ir: copy/part skip I 32 32
pub2: secp256/create-pubkey Il
child: secp256/pubkey-combine reduce [pub2 kpar]
Expand Down
17 changes: 9 additions & 8 deletions bip39.red
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ Red [

#include %pbkdf2.red

urandom: routine [
urandom: function [
len [integer!]
/local
data [byte-ptr!]
][
data: allocate len
crypto/urandom data len
stack/set-last as red-value! binary/load data len
free data
return: [binary!]
] [
data: make binary! len
loop len [
insert data
back tail to-binary (random/secure 256) - 1
]
data
]

word-list: context [
Expand Down
23 changes: 23 additions & 0 deletions eth-wallet-test.red
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Red [
File: %eth-wallet-test.red
Author: "bitbegin"
Notes: {Primarily a part of %eth-wallet.red}
]

#include %eth-wallet.red

eth-wallet/init [abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about] "TREZOR"
;eth-wallet/bip32-path: [8000002Ch 8000003Ch 80000000h 0]

print "0x9c32F71D4DB8Fb9e1A58B0a80dF79935e7256FA6" == eth-wallet/get-address 0
print "0x7AF7283bd1462C3b957e8FAc28Dc19cBbF2FAdfe" == eth-wallet/get-address 1
print "0x05f48E30fCb69ADcd2A591Ebc7123be8BE72D7a1" == eth-wallet/get-address 2

print #{62f1d86b246c81bdd8f6c166d56896a4a5e1eddbcaebe06480e5c0bc74c28224} = eth-wallet/get-private 0
print #{49ee230b1605382ac1c40079191bca937fc30e8c2fa845b7de27a96ffcc4ddbf} = eth-wallet/get-private 1
print #{eef2c0702151930b84cffcaa642af58e692956314519114e78f3211a6465f28b} = eth-wallet/get-private 2

eth-wallet/private-key: #{4646464646464646464646464646464646464646464646464646464646464646}
data: reduce [9 #{04A817C800} 21000 #{3535353535353535353535353535353535353535} #{0DE0B6B3A7640000} #{}]
print #{f86c098504a817c800825208943535353535353535353535353535353535353535880de0b6b3a76400008025a028ef61340bd939bc2195fe537567866003e1a15d3c71ff63e1590620aa636276a067cbe9d8997f761aecb703304b3800ccf555c9f3dc64214b297fb1966a3b6d83}
= eth-wallet/sign-transaction none data 1
20 changes: 2 additions & 18 deletions eth-wallet.red
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ eth-wallet: context [

; tx: [
; nonce [integer!]
; gas-price [hex!]
; gas-price [binary!]
; gas-limit [integer!]
; to-address [binary!]
; amount [hex!] ;-- Wei
; amount [binary!] ;-- Wei
; data [binary!]
; ]
sign-transaction: func [
Expand Down Expand Up @@ -94,19 +94,3 @@ eth-wallet: context [
xprv/6
]
]

eth-wallet/init [abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about] "TREZOR"
;eth-wallet/bip32-path: [8000002Ch 8000003Ch 80000000h 0]

print "0x9c32F71D4DB8Fb9e1A58B0a80dF79935e7256FA6" == eth-wallet/get-address 0
print "0x7AF7283bd1462C3b957e8FAc28Dc19cBbF2FAdfe" == eth-wallet/get-address 1
print "0x05f48E30fCb69ADcd2A591Ebc7123be8BE72D7a1" == eth-wallet/get-address 2

print #{62f1d86b246c81bdd8f6c166d56896a4a5e1eddbcaebe06480e5c0bc74c28224} = eth-wallet/get-private 0
print #{49ee230b1605382ac1c40079191bca937fc30e8c2fa845b7de27a96ffcc4ddbf} = eth-wallet/get-private 1
print #{eef2c0702151930b84cffcaa642af58e692956314519114e78f3211a6465f28b} = eth-wallet/get-private 2

eth-wallet/private-key: #{4646464646464646464646464646464646464646464646464646464646464646}
data: reduce [9 to hex! #{04A817C800} 21000 #{3535353535353535353535353535353535353535} to hex! #{0DE0B6B3A7640000} #{}]
print #{f86c098504a817c800825208943535353535353535353535353535353535353535880de0b6b3a76400008025a028ef61340bd939bc2195fe537567866003e1a15d3c71ff63e1590620aa636276a067cbe9d8997f761aecb703304b3800ccf555c9f3dc64214b297fb1966a3b6d83}
= eth-wallet/sign-transaction none data 1
3 changes: 2 additions & 1 deletion pbkdf2.red
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pbkdf2: context [
blk-size: alg-digest-size alg
output: make binary! key-len
i: 1
salt-tail: tail salt
salt-tail: tail copy salt
while [key-len > 0][
value: head change salt-tail to-string to-binary i
value: sum: checksum/with value alg password
Expand All @@ -44,6 +44,7 @@ pbkdf2: context [
len: either key-len > blk-size [blk-size][key-len]
append/part output sum len
key-len: key-len - len
i: i + 1
]
output
]
Expand Down
5 changes: 4 additions & 1 deletion ripemd160.red
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ context [
data: binary/rs-head as red-binary! ins
len: binary/rs-length? as red-binary! ins
]
TYPE_STRING [data: as byte-ptr! unicode/to-utf8 as red-string! ins :len]
TYPE_STRING [
len: string/rs-length? as red-string! ins
data: as byte-ptr! unicode/to-utf8 as red-string! ins :len
]
default [
fire [TO_ERROR(script invalid-arg) stack/arguments]
]
Expand Down
6 changes: 1 addition & 5 deletions rlp.red
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ rlp: context [
]
rejoin [encode-length length? buffer 192 buffer]
][
buffer: either hex? data [
trim/head to binary! data
][
to binary! data
]
buffer: to binary! data
if number? data [buffer: trim/head buffer]
either all [1 = length? buffer buffer/1 < 128][
buffer
Expand Down
6 changes: 3 additions & 3 deletions secp256k1.red
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Red [
Title: "bip39"
Title: "libsecp256k1 bindings"
Author: "bitbegin"
File: %bip39.red
File: %secp256k1.red
Tabs: 4
License: "BSD-3 - https://github.com/red/red/blob/master/BSD-3-License.txt"
]
Expand Down Expand Up @@ -305,7 +305,7 @@ secp256: context [
free data
]

prikey-valid?: routine [
privkey-valid?: routine [
private-key [binary!]
return: [logic!]
/local
Expand Down