Skip to content

Commit bbc4d03

Browse files
authored
Merge pull request #14 from anoma/feature/deps-update
feat: update dependencies
2 parents 2d92a04 + 505c715 commit bbc4d03

26 files changed

+180
-308
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.history
33
*.nockma
44
.DS_Store
5+
.vscode/*

AnomaHelpers.juvix

Lines changed: 25 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,13 @@ import Anoma open;
88
import Data.Set as Set open using {Set};
99
import Data.Map as Map open using {Map};
1010

11-
-- Should be added to the `juvix-stdlib`
12-
type Either Error Result :=
13-
| left Error
14-
| right Result;
15-
16-
--- Returns the leftmost element of the list satisfying the predicate or
17-
--- nothing if there's no such element.
18-
find {A} (predicate : A → Bool) : List A → Maybe A
19-
| nil := nothing
20-
| (x :: xs) :=
21-
if
22-
| predicate x := just x
23-
| else := find predicate xs;
24-
2511
-- Should be added to the `juvix-anoma-stdlib`
12+
instance
13+
PublicKey-Show : Show PublicKey := mkShow \ {k := natToString (PublicKey.unPublicKey k)};
14+
15+
instance
16+
PrivateKey-Show : Show PrivateKey := mkShow \ {k := natToString (PrivateKey.unPrivateKey k)};
17+
2618
type Bytes32 := mkBytes32 {unBytes32 : Nat};
2719

2820
instance
@@ -36,8 +28,7 @@ instance
3628
Bytes32-Eq : Eq Bytes32 := Stdlib.Trait.Ord.Eq.fromOrdToEq;
3729

3830
instance
39-
Bytes32-Show : Show Bytes32 :=
40-
mkShow \ {b := natToString (Bytes32.unBytes32 b)};
31+
Bytes32-Show : Show Bytes32 := mkShow \ {b := natToString (Bytes32.unBytes32 b)};
4132

4233
natToBytes32 : Nat -> Bytes32 := mkBytes32;
4334

@@ -52,8 +43,7 @@ Bytes-Ord : Ord Bytes :=
5243

5344
natToBytes : Nat -> Bytes := mkBytes;
5445

55-
getLogic (r : Resource) : Nat :=
56-
anomaEncode (Resource.logic r);
46+
getLogic (r : Resource) : Nat := anomaEncode (Resource.logic r);
5747

5848
type Error := mkError {msg : String};
5949

@@ -64,8 +54,7 @@ type InsufficientElementsError :=
6454
};
6555

6656
instance
67-
InsufficientElementsError-Show
68-
: Show InsufficientElementsError :=
57+
InsufficientElementsError-Show : Show InsufficientElementsError :=
6958
mkShow
7059
\ {e :=
7160
"InsufficientElementsError:\n{"
@@ -83,8 +72,7 @@ type InsufficientQuantityError :=
8372
};
8473

8574
instance
86-
InsufficientQuantityError-Show
87-
: Show InsufficientQuantityError :=
75+
InsufficientQuantityError-Show : Show InsufficientQuantityError :=
8876
mkShow
8977
\ {e :=
9078
"InsufficientQuantityError:\n{"
@@ -114,16 +102,10 @@ InvalidLogicError-Show : Show InvalidLogicError :=
114102
++str "}"};
115103

116104
isCreated (r : Resource) (tx : Transaction) : Bool :=
117-
elem
118-
(==)
119-
r
120-
(ResourcePartition.created (partitionResources tx));
105+
elem (==) r (ResourcePartition.created (partitionResources tx));
121106

122107
isConsumed (r : Resource) (tx : Transaction) : Bool :=
123-
elem
124-
(==)
125-
r
126-
(ResourcePartition.consumed (partitionResources tx));
108+
elem (==) r (ResourcePartition.consumed (partitionResources tx));
127109

128110
type Lifecycle :=
129111
| Consumed
@@ -151,32 +133,22 @@ ephemerality (r : Resource) : Ephemerality :=
151133
| isEphemeral r := Ephemeral
152134
| else := NonEphemeral;
153135

154-
isNullifierPresent
155-
(nf : Helper.Nullifier) (tx : Transaction) : Bool :=
136+
isNullifierPresent (nf : Nullifier) (tx : Transaction) : Bool :=
156137
elem (==) nf (Transaction.nullifiers tx);
157138

158-
isSubset {A} {{Ord A}} (sub sup : Set A) : Bool :=
159-
all (x in Set.toList sub)
160-
Set.member? x sup;
139+
isSubset {A} {{Ord A}} (sub sup : Set A) : Bool := all (x in Set.toList sub) Set.member? x sup;
161140

162141
isSublist {A} {{Ord A}} (sub sup : List A) : Bool :=
163142
all (x in sub)
164143
Set.member? x (Set.fromList sup);
165144

166-
commitmentSet (tx : Transaction) : Set Helper.Commitment :=
167-
Set.fromList (Transaction.commitments tx);
145+
commitmentSet (tx : Transaction) : Set Commitment := Set.fromList (Transaction.commitments tx);
168146

169-
nullifierSet (tx : Transaction) : Set Helper.Nullifier :=
170-
Set.fromList (Transaction.nullifiers tx);
147+
nullifierSet (tx : Transaction) : Set Nullifier := Set.fromList (Transaction.nullifiers tx);
171148

172-
lookupExtraData
173-
{Value : Type}
174-
(key : Bytes32)
175-
(tx : Transaction)
176-
: Maybe Value :=
149+
lookupExtraData {Value : Type} (key : Bytes32) (tx : Transaction) : Maybe Value :=
177150
let
178-
keyValueMap : Map Bytes32 Value :=
179-
anomaDecode (Transaction.extra tx);
151+
keyValueMap : Map Bytes32 Value := anomaDecode (Transaction.extra tx);
180152
in Map.lookup key keyValueMap;
181153

182154
mkTransaction
@@ -190,28 +162,24 @@ mkTransaction
190162
commitments := map commitment created;
191163
nullifiers := map (r in consumed) nullifier r nullifierKey;
192164
proofs := consumed ++ created;
165+
complianceProofs := [];
193166
delta := [];
194167
extra := anomaEncode (extraData);
195168
preference := 0
196169
};
197170

198-
composeTransactions (tx1 tx2 : Transaction) : Transaction :=
171+
compose (tx1 tx2 : Transaction) : Transaction :=
199172
Transaction.mk@{
200173
roots := Transaction.roots tx1 ++ Transaction.roots tx2;
201-
commitments :=
202-
Transaction.commitments tx1
203-
++ Transaction.commitments tx2;
204-
nullifiers :=
205-
Transaction.nullifiers tx1 ++ Transaction.nullifiers tx2;
174+
commitments := Transaction.commitments tx1 ++ Transaction.commitments tx2;
175+
nullifiers := Transaction.nullifiers tx1 ++ Transaction.nullifiers tx2;
206176
proofs := Transaction.proofs tx1 ++ Transaction.proofs tx2;
177+
complianceProofs := Transaction.complianceProofs tx1 ++ Transaction.complianceProofs tx2;
207178
delta := Transaction.delta tx1 ++ Transaction.delta tx2;
208179
extra :=
209180
let
210-
kvList1 : List (Pair Bytes32 Bytes) :=
211-
Map.toList (anomaDecode (Transaction.extra tx1));
212-
kvList2 : List (Pair Bytes32 Bytes) :=
213-
Map.toList (anomaDecode (Transaction.extra tx2));
181+
kvList1 : List (Pair Bytes32 Bytes) := Map.toList (anomaDecode (Transaction.extra tx1));
182+
kvList2 : List (Pair Bytes32 Bytes) := Map.toList (anomaDecode (Transaction.extra tx2));
214183
in anomaEncode (Map.fromList (kvList1 ++ kvList2));
215-
216184
preference := 0
217185
};

Authorization/Check.juvix

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,22 @@ import AnomaHelpers open;
77
import Authorization.Message open;
88

99
-- TODO use nullifer instead of commitment
10-
isAuthorizedBy
11-
(signer : PublicKey)
12-
(self : Resource)
13-
(_tx : Transaction)
14-
: Bool :=
10+
isAuthorizedBy (signer : PublicKey) (self : Resource) (tx : Transaction) : Bool :=
1511
let
1612
cm := commitment self;
1713
in case
1814
lookupExtraData@{
19-
key := natToBytes32 cm;
15+
key := natToBytes32 (anomaEncode cm);
2016
Value := Pair ResourceRelationship Signature;
21-
tx := _tx
17+
tx
2218
}
2319
of
2420
| nothing := false
2521
| just (msg, sig) :=
2622
ResourceRelationship.origin msg == cm
2723
&& anomaVerifyDetached sig msg signer
28-
&& isSubset
29-
(ResourceRelationship.mustBeConsumed msg)
30-
(nullifierSet _tx)
31-
&& isSubset
32-
(ResourceRelationship.mustBeCreated msg)
33-
(commitmentSet _tx);
24+
&& isSubset (ResourceRelationship.mustBeConsumed msg) (nullifierSet tx)
25+
&& isSubset (ResourceRelationship.mustBeCreated msg) (commitmentSet tx);
3426

3527
type UnauthorizedError :=
3628
mkUnauthorizedError {

Authorization/Identities.juvix

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,24 @@ module Authorization.Identities;
22

33
import Anoma open;
44

5-
--- The keypair generated from the seed `0x0000000000000000000000000000000000000000000000000000000000000000`
5+
--- The ;KeyPair; generated from the seed `0x0000000000000000000000000000000000000000000000000000000000000000`
66
--- (see, e.g., https://cyphr.me/ed25519_tool/ed.html) in little-endian byte order.
7-
universal : KeyPair :=
8-
mkKeyPair@{
9-
pubKey :=
10-
0x29da598ba148c03aa643e21d77153265730d6f2ad0a8a3622da4b6cebc276a3b;
11-
privKey :=
12-
0x29da598ba148c03aa643e21d77153265730d6f2ad0a8a3622da4b6cebc276a3b0000000000000000000000000000000000000000000000000000000000000000
13-
};
7+
module Universal;
8+
keyPair : KeyPair :=
9+
KeyPair.mk@{
10+
pubKey := PublicKey.mk 0x29da598ba148c03aa643e21d77153265730d6f2ad0a8a3622da4b6cebc276a3b;
11+
privKey :=
12+
PrivateKey.mk
13+
0x29da598ba148c03aa643e21d77153265730d6f2ad0a8a3622da4b6cebc276a3b0000000000000000000000000000000000000000000000000000000000000000
14+
};
1415

15-
universalPubKey : PublicKey := KeyPair.pubKey universal;
16+
pubKey : PublicKey := KeyPair.pubKey keyPair;
1617

17-
universalPrivKey : PublicKey := KeyPair.privKey universal;
18+
privKey : PrivateKey := KeyPair.privKey keyPair;
19+
end;
20+
21+
--- The zero ;PublicKey; `0x0000000000000000000000000000000000000000000000000000000000000000`
22+
--- for which the ;PrivateKey; is not known.
23+
module Zero;
24+
pubKey : PublicKey := PublicKey.mk 0x0;
25+
end;

Authorization/Message.juvix

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import Data.Set as Set open using {Set};
66
import Anoma open;
77
import AnomaHelpers open;
88

9-
-- TODO use Helper.Nullifier once we comply with v2 specs
9+
-- TODO use Nullifier once we comply with v2 specs
1010
type ResourceRelationship :=
1111
mkResourceRelationship {
12-
origin : Helper.Commitment;
13-
mustBeCreated : Set Helper.Commitment;
14-
mustBeConsumed : Set Helper.Commitment
12+
origin : Commitment;
13+
mustBeCreated : Set Commitment;
14+
mustBeConsumed : Set Nullifier
1515
};
1616

1717
-- TODO make signing optional
@@ -22,23 +22,18 @@ mkResourceRelationshipExtraDataMapEntry
2222
(origin : Resource)
2323
: Pair Bytes32 Bytes :=
2424
let
25-
originCm : Helper.Commitment := commitment origin;
26-
consumedNfs : Set Helper.Nullifier :=
27-
Set.fromList
28-
(map \ {r := nullifier r nullifierKey} mustBeConsumed);
29-
createdCms : Set Helper.Commitment :=
30-
Set.fromList (map commitment mustBeCreated);
25+
originCm : Commitment := commitment origin;
26+
consumedNfs : Set Nullifier :=
27+
Set.fromList (map \ {r := nullifier r nullifierKey} mustBeConsumed);
28+
createdCms : Set Commitment := Set.fromList (map commitment mustBeCreated);
3129
msg : ResourceRelationship :=
3230
mkResourceRelationship@{
3331
origin := originCm;
3432
mustBeConsumed := consumedNfs;
3533
mustBeCreated := createdCms
3634
};
37-
38-
k : Bytes32 := natToBytes32 originCm;
39-
v : Bytes :=
40-
natToBytes
41-
(anomaEncode (msg, anomaSignDetached msg nullifierKey));
35+
k : Bytes32 := natToBytes32 (anomaEncode originCm);
36+
v : Bytes := natToBytes (anomaEncode (msg, anomaSignDetached msg nullifierKey));
4237
in k, v;
4338

4439
mkResourceRelationshipExtraData
@@ -49,8 +44,5 @@ mkResourceRelationshipExtraData
4944
: Map Bytes32 Bytes :=
5045
Map.fromList
5146
(map
52-
(mkResourceRelationshipExtraDataMapEntry
53-
nullifierKey
54-
mustBeConsumed
55-
mustBeCreated)
47+
(mkResourceRelationshipExtraDataMapEntry nullifierKey mustBeConsumed mustBeCreated)
5648
origins);

Authorization/Owner.juvix

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ type Owner := mkOwner {owner : PublicKey};
88
instance
99
Owner-Eq : Eq Owner :=
1010
mkEq@{
11-
eq (d1 d2 : Owner) : Bool :=
12-
Owner.owner d1 == Owner.owner d2
11+
eq (d1 d2 : Owner) : Bool := Owner.owner d1 == Owner.owner d2
1312
};
1413

15-
getOwner (r : Resource) : PublicKey :=
16-
Owner.owner (anomaDecode (Resource.data r));
14+
getOwner (r : Resource) : PublicKey := Owner.owner (anomaDecode (Resource.data r));

Intent/DSL.juvix

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,18 @@ exactly (a : Asset) : QuantifiedAssets :=
5151
assets := [a]
5252
};
5353

54-
want
55-
(a : QuantifiedAssets) : Pair Intention QuantifiedAssets :=
56-
Want, a;
54+
want (a : QuantifiedAssets) : Pair Intention QuantifiedAssets := Want, a;
5755

58-
give
59-
(a : QuantifiedAssets) : Pair Intention QuantifiedAssets :=
60-
Give, a;
56+
give (a : QuantifiedAssets) : Pair Intention QuantifiedAssets := Give, a;
6157

6258
syntax operator for pair;
6359

64-
for
65-
(l : Pair Intention QuantifiedAssets)
66-
(qs : QuantifiedAssets)
67-
: Clause :=
60+
for (l : Pair Intention QuantifiedAssets) (qs : QuantifiedAssets) : Clause :=
6861
mkClause@{
6962
lhs := l;
7063
rhs := qs
7164
};
7265

73-
intent (clauses : List Clause) : Resource :=
74-
mkIntent clauses;
66+
intent (clauses : List Clause) : Resource := mkIntent clauses;
7567

7668
axiom mkIntent : List Clause -> Resource;

Package.juvix

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ module Package;
33
import PackageDescription.V2 open;
44

55
package : Package :=
6-
defaultPackage
7-
{name := "anoma-app-patterns";
8-
version := mkVersion 0 0 1;
9-
dependencies := [ github "anoma" "juvix-anoma-stdlib" "v0.1.0"
10-
; github "anoma" "juvix-stdlib" "v0.4.0"
11-
; github "anoma" "juvix-containers" "v0.12.1"
12-
]};
6+
defaultPackage@?{
7+
name := "anoma-app-patterns";
8+
version := mkVersion 0 0 1;
9+
dependencies :=
10+
[ github "anoma" "juvix-anoma-stdlib" "v0.4.0"
11+
; github "anoma" "juvix-stdlib" "v0.5.0"
12+
; github "anoma" "juvix-containers" "v0.13.0"
13+
]
14+
};

0 commit comments

Comments
 (0)