1
0
mirror of https://github.com/danog/toncontest.git synced 2024-11-30 04:29:14 +01:00
toncontest/wallet/wallet-create.fif

71 lines
2.4 KiB
Plaintext
Raw Normal View History

2019-09-29 15:51:54 +02:00
"TonUtil.fif" include
2019-10-03 21:54:25 +02:00
2019-10-05 19:27:18 +02:00
{ dup ."Loading public key from file " type cr
file>B dup Blen 32 <> abort"Public key must be exactly 32 bytes long"
} : load-pubkey
{ ."usage: " @' $0 type ." <workchain-id> <wallet-name> <n> <k> [<key1> <key2> ...] [<boc1> <boc2>]" cr cr
."Creates a new multisignature wallet in specified workchain composed of <n> (1-10) public keys." cr
."Min <k> (1-10) signatures required to send an order; load <n> pre-existing public keys from files <key1...n>." cr
."Optionally load a number of pre-generated partially signed orders <boc1...m> to preload into the contract." cr cr
."Create or generate public key files from private keys using gen-pub.fif key" cr cr
1 halt
2019-09-29 15:51:54 +02:00
} : usage
2019-10-05 19:27:18 +02:00
$# 5 < ' usage if
2019-09-29 15:51:54 +02:00
$1 parse-workchain-id =: wc // set workchain id from command line argument
2019-10-05 19:27:18 +02:00
$2 constant file-base
$3 (number) 1 <> abort"<n> must be a number!" constant n
$4 (number) 1 <> abort"<k> must be a number!" constant k
$# 4 n + - constant m
2019-09-29 15:51:54 +02:00
2019-10-05 19:27:18 +02:00
n 1 < n 10 > or abort"<n> must be between 1 and 10"
k 1 < k 10 > or abort"<k> must be between 1 and 10"
k n <= not abort"<k> must smaller than or equal to <n>"
$# 4 n + < abort"Not enough keys were provided in args!"
5 { dup $() swap 1+ } n times drop
n tuple constant keys-files
5 n + { dup $() swap 1+ } m times drop
m tuple constant messages
."Creating new advanced wallet in workchain " wc .
."with n=" n .
."k=" k .
."m=" m . cr
keys-files explode { } swap times
2019-09-29 15:51:54 +02:00
// code
2019-10-05 19:27:18 +02:00
"wallet-code.fif" include
// data
// storage$_ seqno:uint32 minSigs:(## 4) keys:(HashmapE 4 ^PubKey) messages:(HashmapE 256 ^(MultiSigWrapperStorage X))
// {k:(## 4)} { k > 0 } { k >= 3 } { n >= k } { n <= 10 } = Storage X;
2019-09-29 15:51:54 +02:00
<b 0 32 u,
2019-10-05 19:27:18 +02:00
k 4 u,
2019-09-29 15:51:54 +02:00
file-base +".pk" load-generate-keypair
constant wallet_pk
B,
2019-10-05 19:27:18 +02:00
b>
// no libraries
null
2019-09-29 15:51:54 +02:00
<b b{0011} s, 3 roll ref, rot ref, swap dict, b> // create StateInit
dup ."StateInit: " <s csr. cr
dup hash wc swap 2dup 2constant wallet_addr
."new wallet address = " 2dup .addr cr
2dup file-base +".addr" save-address-verbose
."Non-bounceable address (for init): " 2dup 7 .Addr cr
."Bounceable address (for later access): " 6 .Addr cr
<b 0 32 u, -1 32 i, b>
dup ."signing message: " <s csr. cr
dup hash wallet_pk ed25519_sign_uint rot
<b b{1000100} s, wallet_addr addr, b{000010} s, swap <s s, b{0} s, swap B, swap <s s, b>
dup ."External message for initialization is " <s csr. cr
2 boc+>B dup Bx. cr
file-base +"-query.boc" tuck B>file
."(Saved wallet creating query to file " type .")" cr