-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.lisp
110 lines (98 loc) · 4.45 KB
/
example.lisp
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
(in-package :resource-machine)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Generating test resources
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; yes, it is in the transparent situation.
;; But in the shielded situation, the encryption of resources is
;; public. Users can fetch and decrypt.
;; public key is useful for concealing the private key when someone
;; sends you funds
(defun generate-resoruce-x ()
"Randomly generate out a resource `*x*', making a fresh private key"
(let ((private (generate-key-pair :ed25519)))
(make-instance 'nullifyable-resouce
:resource (make-resource-x-resource
:quantity 1
:nonce 1
:npk (nullifier-key private))
:npr-key private)))
(defun generate-resoruce-y ()
"Randomly generate out a resource `*y*', making a fresh private key"
(let ((private (generate-key-pair :ed25519)))
(make-instance 'nullifyable-resouce
:resource (make-resource-y-resource
:quantity 1
:nonce 1
:npk (nullifier-key private))
:npr-key private)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Example
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; resource-logic ---> x-for-y
;; an x is coming in a y is coming out
;; we have an x, we also have a y
;; we now call prove
;; we can potentially cut this, or keep this as resource x's keys
(defparameter *private* (generate-key-pair :ed25519))
(defparameter *public*
(make-public-key :ed25519 :y (ed25519-public-key (ed25519-key-x *private*))))
;; swap x for y
(defun alice-intent ()
(let* ((resource-x (generate-resoruce-x))
(private (generate-key-pair :ed25519))
(x-nullifier (npk (resource resource-x)))
(ephemeral-resource
(make-resource-x-for-y x-nullifier
(kind (make-resource-y-resource))
1
;; set real label later
:label 1
:quantity 1
:eph 1
:npk (nullifier-key private))))
(list (create-intent :commited (list ephemeral-resource)
:nullified (list resource-x)
:anchors (list 0)) ; figure out what I ought to put here
(make-instance 'nullifyable-resouce
:npr-key private
:resource ephemeral-resource)
x-nullifier)))
(defun bob-intent ()
(let* ((resource-y (generate-resoruce-y))
(private (generate-key-pair :ed25519))
(y-nullifier (npk (resource resource-y)))
(ephemeral-resource
(make-resource-x-for-y y-nullifier
(kind (make-resource-x-resource))
1
;; set real label later
:label 2
:quantity 1
:eph 1
:npk (nullifier-key private))))
(list (create-intent :commited (list ephemeral-resource)
:nullified (list resource-y)
:anchors (list 0)) ; figure out what I ought to put here
(make-instance 'nullifyable-resouce
:npr-key private
:resource ephemeral-resource)
y-nullifier)))
;; (mapcar (lambda (x) (funcall (program x) (inputs x)))
;; (pr (car (alice-intent))))
(defun solve-bob-alice ()
(mvlet* ((a-intent a-eph x-npk (values-list (alice-intent)))
(b-intent b-eph y-npk (values-list (bob-intent)))
;; time to commit the new resources that help satisfy the
;; nullified resource
(alice-y (make-resource-y-resource
:npk x-npk
:quantity 1))
(bob-x (make-resource-x-resource
:npk y-npk
:quantity 1)))
(combine-transactions
(create-intent :commited (list alice-y bob-x)
:nullified (list b-eph a-eph)
;; plz help here
:anchors nil)
a-intent b-intent)))