3
3
-export ([checksig1 /3 , checksig1 /2 ]).
4
4
-export ([signhash /3 , signhash1 /3 ]).
5
5
-export ([packsig /1 , unpacksig /1 ]).
6
+ -export ([add_localdata /2 ]).
7
+ -export ([set_localdata /2 ]).
8
+ -export ([get_localdata /1 ]).
6
9
-export ([pack_sign_ed /1 , unpack_sign_ed /1 ]).
7
10
-export ([add_sig /2 ]).
8
11
-export ([extract_pubkey /1 , extract_pubkeys /1 ]).
@@ -118,8 +121,9 @@ decode_edval(240, <<KL:8/integer, Rest/binary>>=Raw) ->
118
121
{240 , Raw }
119
122
end ;
120
123
121
- decode_edval (254 , Bin ) -> {purpose , Bin };
124
+ % decode_edval(254, Bin) -> {purpose, Bin};
122
125
decode_edval (255 , Bin ) -> {signature , Bin };
126
+ decode_edval (254 , Bin ) -> {local_data , Bin };
123
127
decode_edval (Key , BinVal ) -> {Key , BinVal }.
124
128
125
129
encode_edval (timestamp , Integer ) -> <<1 , 8 , Integer :64 /big >>;
@@ -134,7 +138,7 @@ encode_edval(baldep, {Address,Seq}) ->
134
138
8 = size (Address ),
135
139
<<7 , 16 , Address /binary , Seq :64 /big >>;
136
140
encode_edval (signature , PK ) -> <<255 , (size (PK )):8 /integer , PK /binary >>;
137
- encode_edval (purpose , PK ) -> <<254 , (size (PK )):8 /integer , PK /binary >>;
141
+ % encode_edval(purpose, PK) -> <<254, (size(PK)):8/integer, PK/binary>>;
138
142
encode_edval (N , PK ) when is_binary (N ) andalso is_binary (PK ) ->
139
143
TS = size (N )+ size (PK )+ 1 ,
140
144
if TS >= 64 ->
@@ -144,23 +148,64 @@ encode_edval(N, PK) when is_binary(N) andalso is_binary(PK) ->
144
148
end ;
145
149
encode_edval (_ , _ ) -> <<>>.
146
150
147
- splitsig (<<255 , SLen :8 /integer , Signature :SLen /binary , Rest /binary >>) ->
148
- {Signature , Rest }.
151
+ splitsig (Bin ) ->
152
+ splitsig (Bin ,#{}).
153
+
154
+ splitsig (<<255 , SLen :8 /integer , Signature :SLen /binary , Rest /binary >>,A ) ->
155
+ A #{signature => Signature ,
156
+ binextra => Rest };
157
+
158
+ splitsig (<<254 , LLen :8 /integer , LocalData :LLen /binary , Rest /binary >>,A ) ->
159
+ splitsig (Rest ,A #{local_data => LocalData }).
149
160
150
161
unpacksig (HSig ) when is_map (HSig ) ->
151
162
HSig ;
152
163
153
164
unpacksig (BSig ) when is_binary (BSig ) ->
154
- {Signature , Hdr }= splitsig (BSig ),
155
- #{ binextra => (Hdr ),
156
- signature => (Signature ),
157
- extra => unpack_sign_ed (Hdr )
158
- }.
165
+ #{binextra := BE }= Split = splitsig (BSig ),
166
+ Split #{extra => unpack_sign_ed (BE )}.
167
+
168
+ get_localdata (<<254 , LLen :8 /integer , LD0 :LLen /binary , _Rest /binary >>) ->
169
+ LD0 ;
170
+ get_localdata (#{local_data := LD0 }) ->
171
+ LD0 ;
172
+ get_localdata (_ ) ->
173
+ <<>>.
174
+
175
+ add_localdata (<<255 ,_ /binary >> = Sig , LD ) ->
176
+ <<254 , (size (LD )):8 /integer , LD /binary , Sig /binary >>;
177
+
178
+ add_localdata (#{local_data := LD0 }= Sig ,LD1 ) ->
179
+ Sig #{
180
+ local_data => <<LD0 /binary ,LD1 /binary >>
181
+ };
182
+
183
+ add_localdata (#{}= Sig ,LD1 ) ->
184
+ Sig #{
185
+ local_data => <<LD1 /binary >>
186
+ }.
187
+
188
+ set_localdata (<<255 ,_ /binary >> = Sig , LD ) ->
189
+ <<254 , (size (LD )):8 /integer , LD /binary , Sig /binary >>;
190
+
191
+ set_localdata (<<254 , LLen :8 /integer , _LD0 :LLen /binary , Rest /binary >>, LD1 ) ->
192
+ <<254 , (size (LD1 )):8 /integer , LD1 /binary , Rest /binary >>;
193
+
194
+ set_localdata (#{}= Sig ,LD1 ) ->
195
+ Sig #{ local_data => <<LD1 /binary >> }.
159
196
160
197
packsig (BinSig ) when is_binary (BinSig ) ->
161
198
BinSig ;
199
+
200
+ packsig (#{local_data := LD , signature := Signature , binextra := BinExtra }) ->
201
+ <<254 , (size (LD )):8 /integer , LD /binary ,
202
+ 255 , (size (Signature )):8 /integer , Signature /binary ,
203
+ BinExtra /binary >>;
204
+
162
205
packsig (#{signature := Signature , binextra := BinExtra }) ->
163
- <<255 , (size (Signature )):8 /integer , Signature /binary , BinExtra /binary >>.
206
+ <<255 , (size (Signature )):8 /integer , Signature /binary ,
207
+ BinExtra /binary >>.
208
+
164
209
165
210
add_sig (OldSigs , NewSigs ) ->
166
211
Apply = fun (#{extra := EPL }= Sig , Acc ) ->
0 commit comments