-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from anoma/feature/fixed-supply
feat: implement fixed supply logic for `Token` and change message formats
- Loading branch information
Showing
13 changed files
with
256 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,56 @@ | ||
module Authorization.Message; | ||
|
||
import Stdlib.Prelude open; | ||
import Data.Map open; | ||
import Data.Set open; | ||
import Data.Map as Map open using {Map}; | ||
import Data.Set as Set open using {Set}; | ||
import Anoma open; | ||
import AnomaHelpers open; | ||
|
||
-- TODO: Use nullifier once v2 specs are implemented. | ||
type LinkedCommitmentMessage := | ||
mkLinkedCommitmentMessage { | ||
consumed : Helper.Commitment; | ||
created : Helper.Commitment | ||
-- TODO use Helper.Nullifier once we comply with v2 specs | ||
type ResourceRelationship := | ||
mkResourceRelationship { | ||
origin : Helper.Commitment; | ||
mustBeCreated : Set Helper.Commitment; | ||
mustBeConsumed : Set Helper.Commitment | ||
}; | ||
|
||
type LinkedCommitmentSetMessage := | ||
mkLinkedCommitmentSetMessage { | ||
consumed : Helper.Commitment; | ||
createdSet : Set Helper.Commitment | ||
}; | ||
|
||
-- TODO make signing optional | ||
mkLinkedCommitmentExtraDataMapEntry | ||
(self : PrivateKey) | ||
(created : Resource) | ||
(consumed : Resource) | ||
: Pair Bytes32 Bytes := | ||
let | ||
consumedCm : Helper.Commitment := commitment consumed; | ||
createdCm : Helper.Commitment := commitment created; | ||
msg : LinkedCommitmentMessage := | ||
mkLinkedCommitmentMessage@{ | ||
consumed := consumedCm; | ||
created := createdCm | ||
}; | ||
|
||
k : Bytes32 := natToBytes32 consumedCm; | ||
v : Bytes := | ||
natToBytes | ||
(anomaEncode (msg, anomaSignDetached msg self)); | ||
in k, v; | ||
|
||
-- TODO make signing optional | ||
mkLinkedCommitmentSetExtraDataMapEntry | ||
(self : PrivateKey) | ||
(created : List Resource) | ||
(consumed : Resource) | ||
mkResourceRelationshipExtraDataMapEntry | ||
(nullifierKey : PrivateKey) | ||
(mustBeConsumed : List Resource) | ||
(mustBeCreated : List Resource) | ||
(origin : Resource) | ||
: Pair Bytes32 Bytes := | ||
let | ||
consumedCm : Helper.Commitment := commitment consumed; | ||
originCm : Helper.Commitment := commitment origin; | ||
consumedNfs : Set Helper.Nullifier := | ||
Set.fromList | ||
(map \ {r := nullifier r nullifierKey} mustBeConsumed); | ||
createdCms : Set Helper.Commitment := | ||
Data.Set.fromList (map commitment created); | ||
msg : LinkedCommitmentSetMessage := | ||
mkLinkedCommitmentSetMessage@{ | ||
consumed := consumedCm; | ||
createdSet := createdCms | ||
Set.fromList (map commitment mustBeCreated); | ||
msg : ResourceRelationship := | ||
mkResourceRelationship@{ | ||
origin := originCm; | ||
mustBeConsumed := consumedNfs; | ||
mustBeCreated := createdCms | ||
}; | ||
|
||
k : Bytes32 := natToBytes32 consumedCm; | ||
k : Bytes32 := natToBytes32 originCm; | ||
v : Bytes := | ||
natToBytes | ||
(anomaEncode (msg, anomaSignDetached msg self)); | ||
(anomaEncode (msg, anomaSignDetached msg nullifierKey)); | ||
in k, v; | ||
|
||
mkLinkedCommitmentExtraData | ||
(self : PrivateKey) | ||
(consumed : List Resource) | ||
(created : Resource) | ||
: Map Bytes32 Bytes := | ||
Data.Map.fromList | ||
(map | ||
(mkLinkedCommitmentExtraDataMapEntry self created) | ||
consumed); | ||
|
||
mkLinkedCommitmentSetExtraData | ||
(self : PrivateKey) | ||
(consumed : List Resource) | ||
(created : List Resource) | ||
mkResourceRelationshipExtraData | ||
(nullifierKey : PrivateKey) | ||
(origins : List Resource) | ||
(mustBeConsumed : List Resource) | ||
(mustBeCreated : List Resource) | ||
: Map Bytes32 Bytes := | ||
Data.Map.fromList | ||
Map.fromList | ||
(map | ||
(mkLinkedCommitmentSetExtraDataMapEntry self created) | ||
consumed); | ||
(mkResourceRelationshipExtraDataMapEntry | ||
nullifierKey | ||
mustBeConsumed | ||
mustBeCreated) | ||
origins); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.