Skip to content

Commit 23f4941

Browse files
author
dtfiedler
committed
Merge remote-tracking branch 'upstream/edge'
2 parents 1c24edf + a0aed0a commit 23f4941

77 files changed

Lines changed: 7311 additions & 1560 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,4 @@ mkdocs-site-manifest.csv
4545

4646
!test/admissible-report-wallet.json
4747
!test/admissible-report.json
48+
!test/config.json

‎Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ compile:
66
WAMR_VERSION = 2.2.0
77
WAMR_DIR = _build/wamr
88

9-
GENESIS_WASM_BRANCH = tillathehun0/cu-experimental
9+
GENESIS_WASM_BRANCH = feat/http-checkpoint
1010
GENESIS_WASM_REPO = https://github.com/permaweb/ao.git
1111
GENESIS_WASM_SERVER_DIR = _build/genesis_wasm/genesis-wasm-server
1212

‎rebar.config‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727
]},
2828
{relx, [
2929
{overlay, [
30-
{copy, "_build/genesis_wasm/genesis-wasm-server", "genesis-wasm-server"}
30+
{copy,
31+
"_build/genesis_wasm/genesis-wasm-server",
32+
"genesis-wasm-server"
33+
}
3134
]}
3235
]}
3336
]},
@@ -56,7 +59,8 @@
5659
]}.
5760

5861
{cargo_opts, [
59-
{src_dir, "native/dev_snp_nif"}
62+
{src_dir, "native/dev_snp_nif"},
63+
{src_dir, "deps/elmdb/native/elmdb_nif"}
6064
]}.
6165

6266
{overrides, []}.
@@ -82,7 +86,7 @@
8286
{ compile, "rm -f native/hb_keccak/*.o native/hb_keccak/*.d"},
8387
{ compile, "mkdir -p priv/html"},
8488
{ compile, "cp -R src/html/* priv/html"},
85-
{ compile, "cp _build/default/lib/elmdb/priv/* priv/ 2>/dev/null || true" }
89+
{ compile, "cp _build/default/lib/elmdb/priv/crates/elmdb_nif/elmdb_nif.so _build/default/lib/elmdb/priv/elmdb_nif.so 2>/dev/null || true" }
8690
]}.
8791

8892
{provider_hooks, [
@@ -111,8 +115,7 @@
111115
]}.
112116

113117
{deps, [
114-
{elmdb, {git, "https://github.com/samcamwilliams/elmdb", {ref, "5feb2b039e40adb3b2b70241d1c212ad162f5659"}}},
115-
{lmdb, {git, "https://github.com/twilson63/erlang-lmdb", {ref, "8a4fedc38c7a44eef6af816b5e840bd362d67f1a"}}},
118+
{elmdb, { git, "https://github.com/twilson63/elmdb-rs.git", { ref, "de062ac813b8576512a59aa0b4c289899b99ba71" }}},
116119
{b64fast, {git, "https://github.com/ArweaveTeam/b64fast.git", {ref, "58f0502e49bf73b29d95c6d02460d1fb8d2a5273"}}},
117120
{cowboy, {git, "https://github.com/ninenines/cowboy", {ref, "022013b6c4e967957c7e0e7e7cdefa107fc48741"}}},
118121
{gun, {git, "https://github.com/ninenines/gun", {ref, "8efcedd3a089e6ab5317e4310fed424a4ee130f8"}}},
@@ -131,7 +134,7 @@
131134
]}.
132135

133136
% Increase `scale_timeouts` when running on a slower machine.
134-
{eunit_opts, [verbose, {scale_timeouts, 1}]}.
137+
{eunit_opts, [verbose, {scale_timeouts, 10}]}.
135138

136139
{relx, [
137140
{release, {'hb', "0.0.1"}, [hb, b64fast, cowboy, gun, luerl, prometheus, prometheus_cowboy, elmdb]},
@@ -175,4 +178,4 @@
175178
{preprocess, true},
176179
{private, true},
177180
{hidden, true}
178-
]}.
181+
]}.

‎rebar.lock‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{"1.2.0",
2-
[{<<"accept">>,{pkg,<<"accept">>,<<"0.3.5">>},2},
2+
[{<<"accept">>,{pkg,<<"accept">>,<<"0.3.7">>},2},
33
{<<"b64fast">>,
44
{git,"https://github.com/ArweaveTeam/b64fast.git",
55
{ref,"58f0502e49bf73b29d95c6d02460d1fb8d2a5273"}},
@@ -10,42 +10,38 @@
1010
0},
1111
{<<"cowlib">>,
1212
{git,"https://github.com/ninenines/cowlib",
13-
{ref,"1c3d5defba28e92a88ce45c440d57e178ab1c514"}},
13+
{ref,"e2d7749f61b89cc6f8779ba66a5a8ab0fe85c827"}},
1414
1},
1515
{<<"elmdb">>,
16-
{git,"https://github.com/samcamwilliams/elmdb",
17-
{ref,"5feb2b039e40adb3b2b70241d1c212ad162f5659"}},
16+
{git,"https://github.com/twilson63/elmdb-rs.git",
17+
{ref,"de062ac813b8576512a59aa0b4c289899b99ba71"}},
1818
0},
1919
{<<"gun">>,
2020
{git,"https://github.com/ninenines/gun",
2121
{ref,"8efcedd3a089e6ab5317e4310fed424a4ee130f8"}},
2222
0},
23-
{<<"lmdb">>,
24-
{git,"https://github.com/twilson63/erlang-lmdb",
25-
{ref,"8a4fedc38c7a44eef6af816b5e840bd362d67f1a"}},
26-
0},
2723
{<<"luerl">>,{pkg,<<"luerl">>,<<"1.3.0">>},0},
2824
{<<"prometheus">>,{pkg,<<"prometheus">>,<<"4.11.0">>},0},
2925
{<<"prometheus_cowboy">>,{pkg,<<"prometheus_cowboy">>,<<"0.1.8">>},0},
30-
{<<"prometheus_httpd">>,{pkg,<<"prometheus_httpd">>,<<"2.1.11">>},1},
26+
{<<"prometheus_httpd">>,{pkg,<<"prometheus_httpd">>,<<"2.1.15">>},1},
3127
{<<"quantile_estimator">>,{pkg,<<"quantile_estimator">>,<<"0.2.1">>},1},
3228
{<<"ranch">>,
3329
{git,"https://github.com/ninenines/ranch",
3430
{ref,"a692f44567034dacf5efcaa24a24183788594eb7"}},
3531
1}]}.
3632
[
3733
{pkg_hash,[
38-
{<<"accept">>, <<"B33B127ABCA7CC948BBE6CAA4C263369ABF1347CFA9D8E699C6D214660F10CD1">>},
34+
{<<"accept">>, <<"CD6E34A2D7E28CA38B2D3CB233734CA0C221EFBC1F171F91FEC5F162CC2D18DA">>},
3935
{<<"luerl">>, <<"B56423DDB721432AB980B818FEECB84ADBAB115E2E11522CF94BCD0729CAA501">>},
4036
{<<"prometheus">>, <<"B95F8DE8530F541BD95951E18E355A840003672E5EDA4788C5FA6183406BA29A">>},
4137
{<<"prometheus_cowboy">>, <<"CFCE0BC7B668C5096639084FCD873826E6220EA714BF60A716F5BD080EF2A99C">>},
42-
{<<"prometheus_httpd">>, <<"F616ED9B85B536B195D94104063025A91F904A4CFC20255363F49A197D96C896">>},
38+
{<<"prometheus_httpd">>, <<"8F767D819A5D36275EAB9264AFF40D87279151646776069BF69FBDBBD562BD75">>},
4339
{<<"quantile_estimator">>, <<"EF50A361F11B5F26B5F16D0696E46A9E4661756492C981F7B2229EF42FF1CD15">>}]},
4440
{pkg_hash_ext,[
45-
{<<"accept">>, <<"11B18C220BCC2EAB63B5470C038EF10EB6783BCB1FCDB11AA4137DEFA5AC1BB8">>},
41+
{<<"accept">>, <<"CA69388943F5DAD2E7232A5478F16086E3C872F48E32B88B378E1885A59F5649">>},
4642
{<<"luerl">>, <<"6B3138AA829F0FBC4CD0F083F273B4030A2B6CE99155194A6DB8C67B2C3480A4">>},
4743
{<<"prometheus">>, <<"719862351AABF4DF7079B05DC085D2BBCBE3AC0AC3009E956671B1D5AB88247D">>},
4844
{<<"prometheus_cowboy">>, <<"BA286BECA9302618418892D37BCD5DC669A6CC001F4EB6D6AF85FF81F3F4F34C">>},
49-
{<<"prometheus_httpd">>, <<"0BBE831452CFDF9588538EB2F570B26F30C348ADAE5E95A7D87F35A5910BCF92">>},
45+
{<<"prometheus_httpd">>, <<"67736D000745184D5013C58A63E947821AB90CB9320BC2E6AE5D3061C6FFE039">>},
5046
{<<"quantile_estimator">>, <<"282A8A323CA2A845C9E6F787D166348F776C1D4A41EDE63046D72D422E3DA946">>}]}
5147
].

‎src/ar_timestamp.erl‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ cache(Current) ->
5757
%% @doc Refresh the timestamp cache periodically.
5858
refresher(TSServer) ->
5959
timer:sleep(?TIMEOUT),
60-
TS =
61-
case hb_opts:get(mode) of
62-
debug -> { 0, 0, << 0:256 >> };
63-
prod -> hb_client:arweave_timestamp()
64-
end,
60+
TS = hb_client:arweave_timestamp(),
6561
TSServer ! {refresh, TS},
6662
refresher(TSServer).

‎src/ar_wallet.erl‎

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
-export([sign/2, sign/3, hmac/1, hmac/2, verify/3, verify/4]).
33
-export([to_pubkey/1, to_pubkey/2, to_address/1, to_address/2, new/0, new/1]).
44
-export([new_keyfile/2, load_keyfile/1, load_keyfile/2, load_key/1, load_key/2]).
5+
-export([to_json/1, from_json/1, from_json/2]).
56
-include("include/ar.hrl").
67
-include_lib("public_key/include/public_key.hrl").
78

@@ -18,6 +19,7 @@ new(KeyType = {KeyAlg, PublicExpnt}) when KeyType =:= {rsa, 65537} ->
1819
= crypto:generate_key(KeyAlg, {4096, PublicExpnt}),
1920
{{KeyType, Priv, Pub}, {KeyType, Pub}}.
2021

22+
2123
%% @doc Sign some data with a private key.
2224
sign(Key, Data) ->
2325
sign(Key, Data, sha256).
@@ -91,50 +93,19 @@ new_keyfile(KeyType, WalletName) ->
9193
{?RSA_SIGN_ALG, PublicExpnt} ->
9294
{[Expnt, Pb], [Expnt, Pb, Prv, P1, P2, E1, E2, C]} =
9395
crypto:generate_key(rsa, {?RSA_PRIV_KEY_SZ, PublicExpnt}),
94-
Ky =
95-
hb_json:encode(
96-
#{
97-
kty => <<"RSA">>,
98-
ext => true,
99-
e => hb_util:encode(Expnt),
100-
n => hb_util:encode(Pb),
101-
d => hb_util:encode(Prv),
102-
p => hb_util:encode(P1),
103-
q => hb_util:encode(P2),
104-
dp => hb_util:encode(E1),
105-
dq => hb_util:encode(E2),
106-
qi => hb_util:encode(C)
107-
}
108-
),
96+
PrivKey = {KeyType, Prv, Pb},
97+
Ky = to_json(PrivKey),
10998
{Pb, Prv, Ky};
11099
{?ECDSA_SIGN_ALG, secp256k1} ->
111100
{OrigPub, Prv} = crypto:generate_key(ecdh, secp256k1),
112-
<<4:8, PubPoint/binary>> = OrigPub,
113-
PubPointMid = byte_size(PubPoint) div 2,
114-
<<X:PubPointMid/binary, Y:PubPointMid/binary>> = PubPoint,
115-
Ky =
116-
hb_json:encode(
117-
#{
118-
kty => <<"EC">>,
119-
crv => <<"secp256k1">>,
120-
x => hb_util:encode(X),
121-
y => hb_util:encode(Y),
122-
d => hb_util:encode(Prv)
123-
}
124-
),
125-
{compress_ecdsa_pubkey(OrigPub), Prv, Ky};
101+
CompressedPub = compress_ecdsa_pubkey(OrigPub),
102+
PrivKey = {KeyType, Prv, CompressedPub},
103+
Ky = to_json(PrivKey),
104+
{CompressedPub, Prv, Ky};
126105
{?EDDSA_SIGN_ALG, ed25519} ->
127106
{{_, Prv, Pb}, _} = new(KeyType),
128-
Ky =
129-
hb_json:encode(
130-
#{
131-
kty => <<"OKP">>,
132-
alg => <<"EdDSA">>,
133-
crv => <<"Ed25519">>,
134-
x => hb_util:encode(Pb),
135-
d => hb_util:encode(Prv)
136-
}
137-
),
107+
PrivKey = {KeyType, Prv, Pb},
108+
Ky = to_json(PrivKey),
138109
{Pb, Prv, Ky}
139110
end,
140111
Filename = wallet_filepath(WalletName, Pub, KeyType),
@@ -179,7 +150,44 @@ load_keyfile(File) ->
179150
%% @doc Extract the public and private key from a keyfile.
180151
load_keyfile(File, Opts) ->
181152
{ok, Body} = file:read_file(File),
182-
Key = hb_json:decode(Body),
153+
from_json(Body, Opts).
154+
155+
%% @doc Convert a wallet private key to JSON (JWK) format
156+
to_json({PrivKey, _PubKey}) ->
157+
to_json(PrivKey);
158+
to_json({{?RSA_SIGN_ALG, PublicExpnt}, Priv, Pub}) when PublicExpnt =:= 65537 ->
159+
hb_json:encode(#{
160+
kty => <<"RSA">>,
161+
ext => true,
162+
e => hb_util:encode(<<PublicExpnt:32>>),
163+
n => hb_util:encode(Pub),
164+
d => hb_util:encode(Priv)
165+
});
166+
to_json({{?ECDSA_SIGN_ALG, secp256k1}, Priv, CompressedPub}) ->
167+
% For ECDSA, we need to expand the compressed pubkey to get X,Y coordinates
168+
% This is a simplified version - ideally we'd implement pubkey expansion
169+
hb_json:encode(#{
170+
kty => <<"EC">>,
171+
crv => <<"secp256k1">>,
172+
d => hb_util:encode(Priv)
173+
% TODO: Add x and y coordinates from expanded pubkey
174+
});
175+
to_json({{?EDDSA_SIGN_ALG, ed25519}, Priv, Pub}) ->
176+
hb_json:encode(#{
177+
kty => <<"OKP">>,
178+
alg => <<"EdDSA">>,
179+
crv => <<"Ed25519">>,
180+
x => hb_util:encode(Pub),
181+
d => hb_util:encode(Priv)
182+
}).
183+
184+
%% @doc Parse a wallet from JSON (JWK) format
185+
from_json(JsonBinary) ->
186+
from_json(JsonBinary, #{}).
187+
188+
%% @doc Parse a wallet from JSON (JWK) format with options
189+
from_json(JsonBinary, Opts) ->
190+
Key = hb_json:decode(JsonBinary),
183191
{Pub, Priv, KeyType} =
184192
case hb_maps:get(<<"kty">>, Key, undefined, Opts) of
185193
<<"EC">> ->

0 commit comments

Comments
 (0)