M client.rkt => client.rkt +1 -14
@@ 33,20 33,7 @@
[#:struct (exn:fail:network:http:error exn:fail:network) ([code : Any] [type : Any])])
(require/typed crypto
[crypto-random-bytes (Natural -> Bytes)])
-
-(define num-bytes (assert (/ 1024 8) natural?))
-
-(define (gen)
- (let* ([bstr (crypto-random-bytes num-bytes)])
- (cast (bytes->integer bstr #f #t 0 num-bytes) Natural)))
-
-(define (random-poly [degree : Natural] [constant : Natural])
- (let ([coefficients (build-vector degree (λ (_) (gen)))])
- (λ ([x : Natural]) : Natural
- (cast (+ constant
- (for/sum : Integer ([i degree])
- (* (expt x (add1 i)) (vector-ref coefficients i))))
- Natural))))
+(require "poly.rkt")
(define (natural->hex-string [n : Natural])
(bytes->hex-string
A poly.rkt => poly.rkt +25 -0
@@ 0,0 1,25 @@
+#lang typed/racket
+(require/typed binaryio
+ [bytes->integer (->* (Bytes Boolean) (Boolean Natural Natural) Integer)]
+ [integer->bytes (->* (Integer Natural Boolean) (Boolean Bytes Natural) Bytes)]
+ [integer-bytes-length (Integer Boolean -> Natural)])
+(require/typed crypto
+ [crypto-random-bytes (Natural -> Bytes)])
+
+(define-type Poly (Natural -> Natural))
+
+(define num-bytes (assert (/ 1024 8) natural?))
+
+(define (gen)
+ (let* ([bstr (crypto-random-bytes num-bytes)])
+ (cast (bytes->integer bstr #f #t 0 num-bytes) Natural)))
+
+(define (random-poly [degree : Natural] [constant : Natural]) : Poly
+ (let ([coefficients (build-vector degree (λ (_) (gen)))])
+ (λ ([x : Natural]) : Natural
+ (cast (+ constant
+ (for/sum : Integer ([i degree])
+ (* (expt x (add1 i)) (vector-ref coefficients i))))
+ Natural))))
+
+(provide (all-defined-out))