2018-08-07 01:55:15 +03:00
|
|
|
:: urbit-style key generation and derivation functions
|
|
|
|
::
|
2018-08-10 21:36:26 +03:00
|
|
|
/- keygen
|
|
|
|
::
|
2018-10-26 05:10:40 +03:00
|
|
|
/+ bip32, bip39
|
2018-08-07 01:55:15 +03:00
|
|
|
::
|
2018-08-29 01:58:22 +03:00
|
|
|
=, keygen
|
2018-08-10 21:36:26 +03:00
|
|
|
::
|
2018-08-13 22:33:27 +03:00
|
|
|
|%
|
2018-08-07 01:55:15 +03:00
|
|
|
++ argon2u
|
2018-11-13 05:12:22 +03:00
|
|
|
|= [who=ship tic=byts]
|
2018-08-07 01:55:15 +03:00
|
|
|
^- @
|
2018-11-13 05:12:22 +03:00
|
|
|
~| [%who who (met 3 who)]
|
|
|
|
:: ?> (lte (met 3 who) 4)
|
2018-10-23 02:37:42 +03:00
|
|
|
%- (argon2-urbit:argon2:crypto 32)
|
2018-11-13 05:12:22 +03:00
|
|
|
:- tic
|
2018-11-14 01:13:56 +03:00
|
|
|
=- [(met 3 -) (swp 3 -)]
|
2018-11-13 05:12:22 +03:00
|
|
|
%- crip
|
|
|
|
(weld "urbitkeygen" (a-co:co who))
|
2018-08-07 01:55:15 +03:00
|
|
|
::
|
2018-08-13 22:33:27 +03:00
|
|
|
++ child-node-from-seed
|
2018-11-13 05:12:22 +03:00
|
|
|
|= [seed=@ typ=tape pass=(unit @t)]
|
2018-08-13 22:33:27 +03:00
|
|
|
^- node
|
2018-11-13 05:12:22 +03:00
|
|
|
=+ sed=(seed:ds 32^seed typ)
|
2018-10-26 05:10:40 +03:00
|
|
|
=+ nom=(from-entropy:bip39 32^sed)
|
2018-11-13 05:12:22 +03:00
|
|
|
:+ typ nom
|
2018-10-31 03:15:56 +03:00
|
|
|
%- wallet:ds
|
2018-10-26 05:10:40 +03:00
|
|
|
%+ to-seed:bip39 nom
|
|
|
|
(trip (fall pass ''))
|
2018-08-13 22:33:27 +03:00
|
|
|
::
|
2018-11-24 00:52:49 +03:00
|
|
|
++ derive-network-seed
|
|
|
|
|= [mngs=@ rev=@ud]
|
|
|
|
^- @ux
|
|
|
|
=+ (seed:ds 64^mngs (weld "network" (a-co:co rev)))
|
|
|
|
?: =(0 rev) -
|
|
|
|
:: hash again to prevent length extension attacks
|
|
|
|
(sha-256l:sha 32 -)
|
|
|
|
::
|
2019-10-09 22:19:04 +03:00
|
|
|
++ ownership-wallet-from-ticket
|
|
|
|
|= [who=ship ticket=byts pass=(unit @t)]
|
|
|
|
^- node
|
|
|
|
=+ master-seed=(argon2u who ticket)
|
|
|
|
(child-node-from-seed master-seed "ownership" pass)
|
|
|
|
::
|
2018-08-14 02:36:21 +03:00
|
|
|
++ full-wallet-from-ticket
|
2018-11-13 05:12:22 +03:00
|
|
|
:: who: username
|
|
|
|
:: ticket: password
|
|
|
|
:: rev: network key revision
|
|
|
|
:: pass: optional passphrase
|
|
|
|
::
|
|
|
|
|= [who=ship ticket=byts rev=@ud pass=(unit @t)]
|
2018-11-06 04:58:47 +03:00
|
|
|
^- vault
|
2018-11-13 05:12:22 +03:00
|
|
|
=+ master-seed=(argon2u who ticket)
|
|
|
|
=/ cn :: child node
|
|
|
|
|= typ=nodetype
|
|
|
|
(child-node-from-seed master-seed typ pass)
|
2018-08-10 21:36:26 +03:00
|
|
|
::
|
2018-11-13 05:12:22 +03:00
|
|
|
:- ^= ownership ^- node
|
|
|
|
(cn "ownership")
|
2018-08-10 21:36:26 +03:00
|
|
|
::
|
2018-11-13 05:12:22 +03:00
|
|
|
:- ^= voting ^- node
|
|
|
|
(cn "voting")
|
2018-08-10 21:36:26 +03:00
|
|
|
::
|
2018-11-13 05:12:22 +03:00
|
|
|
=/ management=node
|
|
|
|
(cn "management")
|
2018-10-31 03:15:56 +03:00
|
|
|
:- management=management
|
2018-08-10 21:36:26 +03:00
|
|
|
::
|
2018-11-13 05:12:22 +03:00
|
|
|
:- ^= transfer ^- node
|
|
|
|
(cn "transfer")
|
2018-08-10 21:36:26 +03:00
|
|
|
::
|
2018-11-13 05:12:22 +03:00
|
|
|
:- ^= spawn ^- node
|
|
|
|
(cn "spawn")
|
2018-08-10 21:36:26 +03:00
|
|
|
::
|
2018-11-13 05:12:22 +03:00
|
|
|
^= network ^- uode
|
|
|
|
=/ mad :: management seed
|
2018-10-26 05:10:40 +03:00
|
|
|
%+ to-seed:bip39
|
2018-11-13 05:12:22 +03:00
|
|
|
seed:management
|
2018-10-26 05:10:40 +03:00
|
|
|
(trip (fall pass ''))
|
2018-11-24 00:52:49 +03:00
|
|
|
=+ sed=(derive-network-seed mad rev)
|
2018-11-13 05:12:22 +03:00
|
|
|
[rev sed (urbit:ds sed)]
|
2018-08-10 21:36:26 +03:00
|
|
|
::
|
2018-10-26 05:10:40 +03:00
|
|
|
++ ds :: derive from raw seed
|
2018-10-31 03:15:56 +03:00
|
|
|
|%
|
2018-08-10 21:36:26 +03:00
|
|
|
++ wallet
|
2018-10-31 03:15:56 +03:00
|
|
|
|= seed=@
|
2018-08-10 21:36:26 +03:00
|
|
|
^- ^wallet
|
2018-10-31 03:15:56 +03:00
|
|
|
=+ => (from-seed:bip32 64^seed)
|
|
|
|
(derive-path "m/44'/60'/0'/0/0")
|
2018-10-26 05:10:40 +03:00
|
|
|
:+ [public-key private-key]
|
2018-12-18 01:38:24 +03:00
|
|
|
(address-from-prv:key:ethereum private-key)
|
2018-10-26 05:10:40 +03:00
|
|
|
chain-code
|
2018-08-10 21:36:26 +03:00
|
|
|
::
|
|
|
|
++ urbit
|
2018-10-31 03:15:56 +03:00
|
|
|
|= seed=@
|
2018-08-10 21:36:26 +03:00
|
|
|
^- edkeys
|
|
|
|
=+ =< [pub=pub:ex sec=sec:ex]
|
2018-10-23 02:37:42 +03:00
|
|
|
(pit:nu:crub:crypto 256 seed)
|
2018-08-10 21:36:26 +03:00
|
|
|
:- ^= auth
|
|
|
|
:- (rsh 3 1 (end 3 33 pub))
|
|
|
|
(rsh 3 1 (end 3 33 sec))
|
|
|
|
^= crypt
|
|
|
|
:- (rsh 3 33 pub)
|
|
|
|
(rsh 3 33 sec)
|
|
|
|
::
|
|
|
|
++ seed
|
2018-11-13 05:12:22 +03:00
|
|
|
|= [seed=byts salt=tape]
|
2018-10-23 02:37:42 +03:00
|
|
|
^- @ux
|
2018-10-31 03:15:56 +03:00
|
|
|
%- sha-256l:sha
|
2018-10-31 04:18:17 +03:00
|
|
|
:- (add wid.seed (lent salt))
|
|
|
|
(cat 3 (crip (flop salt)) dat.seed)
|
2018-08-10 21:36:26 +03:00
|
|
|
--
|
2018-08-07 01:55:15 +03:00
|
|
|
--
|