-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulti-wallet-build.fif
71 lines (59 loc) · 1.45 KB
/
multi-wallet-build.fif
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env fift -s
"TonUtil.fif" include
"Asm.fif" include
{ ."usage: " @' $0 type ." <seq-no> <n> <signature-index> [<wallet-name>]" cr
."Signs request with <seqno> for the wallet with the name specified by <wallet-name> parameter" cr
."('new-multi-wallet' by default)" cr 1 halt
} : usage
$# dup
$1 parse-int =: seqno
$2 parse-int =: n
$3 parse-int =: signature-index
def? $4 { @' $4 } { "new-multi-wallet" } cond constant wallet-name
wallet-name +".addr" load-address
2dup 2constant wallet_addr
.s
wallet-name +".req" seqno (.) $+ file>B B>boc
0
1 {
.s
wallet-name +".req" seqno (.) $+ over (.) ".sign" swap $+ $+ dup file-exists? {
dup ."Signature found : " type cr
file>B over 8 u>B B+
rot
1 +
rot
.s
} {
dup ."Signature not found : " type cr
drop
.s
} cond
1+
.s
} n times drop
.s
dup 0 > {
swap
<b swap B, dictnew dict,
swap
{
."Processing" cr
b> .s swap
<b swap B, swap dict,
} swap 1 - times
b> } { ."No additional signatures" cr
dictnew
} cond
seqno wallet-name +".req" swap (.) $+ file>B B>boc <s
swap
<b signature-index 8 u, swap dict, swap s, b> dup
signature-index wallet-name +".pk" swap (.) $+ .s file>B
swap
hash swap ed25519_sign_uint
<b swap B, swap <s s, b>
.s
<b b{1000100} s, wallet_addr addr, 0 Gram, b{00} s, swap <s s, b>
2 boc+>B dup Bx. cr
wallet-name +".req" seqno (.) $+ +"_" signature-index (.) $+ +".boc" 2dup B>file // state
."(Saved wallet request " type .")" cr