Documentation ¶
Overview ¶
Package tokens comments. TODO: package comments for these crypto utils. ed25519 jwt.
Index ¶
- Constants
- Variables
- func FindPublicKey(thekey string) string
- func Get32xTokenLocal() string
- func GetBoxKeyPairFromPassphrase(pass string) ([32]byte, [32]byte)
- func GetFirebaseApp(ctx context.Context) (*firebase.App, error)
- func GetImpromptuGiantToken() string
- func GetImpromptuGiantTokenLocal() string
- func GetKnotFreePayload(token string) (string, string, error)
- func GetPrivateKey(first4 string) string
- func GetRandomB36String() string
- func GetRandomB64String() string
- func LoadPrivateKeys(fname string) error
- func LoadPublicKeys()
- func LogNewToken(ctx context.Context, token *KnotFreeTokenPayload, remoteAddr string) error
- func MakeNameToken(data *SubscriptionNameReservationPayload, privateKey []byte) ([]byte, error)
- func MakeRandomPhrase(amount int) string
- func MakeToken(data *KnotFreeTokenPayload, privateKey []byte) ([]byte, error)
- func SavePublicKey(key string, publicKey string)
- type CountReader
- type KnotFreeContactPrices
- type KnotFreeContactStats
- type KnotFreeTokenPayload
- type SubscriptionNameReservationPayload
- type TokenLogStruct
- type TokenReply
- type TokenRequest
- type TokenType
- type ZeroReader
Constants ¶
const Test32xToken = "" /* 287-byte string literal not displayed */
Variables ¶
var AliceSecretPhrase string = "join_red_this_string_plain_does_quart_simple_buy_line_fun_look_original_deal"
name alice_vociferous_mcgrath
var BobSecretPhrase string = "tail_wait_king_particular_track_third_arrive_agree_plural_charge_rise_grew_continent_fact"
building_bob_bottomline_boldness
var CharlieSecretPhrase string = "sense_trouble_lost_final_crowd_child_fear_buy_card_apple_such_it_as_note"
var English_words = `` /* 5823-byte string literal not displayed */
var OneConnectionToken = KnotFreeContactPrices{ Stats: KnotFreeContactStats{ Connections: 1, Subscriptions: 25, Input: 38, Output: 38, }, Price: 0.0005 * 2, }
as per Civo 11/2022.
var PublicKeys string = `` /* 2817-byte string literal not displayed */
no point loading them all the time. ed25519 one per line. _9sh is being used to sign tokens 8ZNP is unused yRst is used as seed to cluster box keypair the others are unused so far and the private part unloaded.
var StrangerSecretPhrase string = "dummy-dummy-dummy-dummy-dummy-dummy-dummy-dummy-dummy-dummy-dummy"
var XxxxSampleSmallToken = `` /* 408-byte string literal not displayed */
SampleSmallToken is a small token signed by "_9sh" (below) p.Input = 20 p.Output = 20 p.Subscriptions = 2 p.Connections = 2 and, it's expired.
Functions ¶
func Get32xTokenLocal ¶ added in v0.1.6
func Get32xTokenLocal() string
func GetBoxKeyPairFromPassphrase ¶ added in v0.1.4
func GetImpromptuGiantToken ¶
func GetImpromptuGiantToken() string
GetImpromptuGiantToken is GiantX32 256k connections is GiantX32
func GetImpromptuGiantTokenLocal ¶
func GetImpromptuGiantTokenLocal() string
func GetKnotFreePayload ¶
GetKnotFreePayload returns the trimmed token and the issuer. We allow all kinds of not b64 junk around our JWT's it is tolerant of junk before and after the token. Only return the issuer. Let Verify get the claims. yes, we end up unmarshaling KnotFreeTokenPayload twice.
func GetRandomB36String ¶ added in v0.1.6
func GetRandomB36String() string
GetRandomB32String returns 24 bytes but only 24 * 5.1699 = 124 bits of random. but it's url compatible
func GetRandomB64String ¶
func GetRandomB64String() string
GetRandomB64String returns 18 bytes or 18 * 8 = 144 bits of randomness aka 24 bytes
func LogNewToken ¶
func LogNewToken(ctx context.Context, token *KnotFreeTokenPayload, remoteAddr string) error
LogNewToken to make a record that this token was delivered to customer. Let's not include the whole jwt.
func MakeNameToken ¶
func MakeNameToken(data *SubscriptionNameReservationPayload, privateKey []byte) ([]byte, error)
MakeNameToken is
func MakeRandomPhrase ¶
func MakeToken ¶
func MakeToken(data *KnotFreeTokenPayload, privateKey []byte) ([]byte, error)
MakeToken is
func SavePublicKey ¶
SavePublicKey goes with FindPublicKey. We're using the first couple of bytes, in base54, of the 32byte public key as a name and looking them up in a gadget here. publicKey is actually an immutable array of bytes and not utf8. Is that going to be a problem?
Types ¶
type CountReader ¶
type CountReader struct {
// contains filtered or unexported fields
}
CountReader is too public
type KnotFreeContactPrices ¶ added in v0.1.4
type KnotFreeContactPrices struct { Stats KnotFreeContactStats Price float64 `json:"pr"` }
func GetTokenStatsAndPrice ¶ added in v0.1.4
func GetTokenStatsAndPrice(ttype TokenType) KnotFreeContactPrices
func GetTokenTenKStatsAndPrice ¶ added in v0.1.4
func GetTokenTenKStatsAndPrice() KnotFreeContactPrices
func ScaleTokenPrice ¶ added in v0.1.4
func ScaleTokenPrice(in KnotFreeContactPrices, factor float64) KnotFreeContactPrices
type KnotFreeContactStats ¶
type KnotFreeContactStats struct { // Input float64 `json:"in"` // bytes per sec float32 Output float64 `json:"out"` // bytes per sec Subscriptions float64 `json:"su"` // seconds per sec Connections float64 `json:"co"` // seconds per sec }
KnotFreeContactStats is the numeric part of the token claims it is floats to and fractions in json
type KnotFreeTokenPayload ¶
type KnotFreeTokenPayload struct { // ExpirationTime uint32 `json:"exp,omitempty"` // unix seconds Issuer string `json:"iss"` // first 4 bytes (or more) of base64 public key of issuer JWTID string `json:"jti,omitempty"` // a unique serial number for this Issuer KnotFreeContactStats // limits on what we're allowed to do. URL string `json:"url"` // address of the service eg. "knotfree.net" or knotfree0.com for localhost }
KnotFreeTokenPayload is our JWT 'claims'.
func GetSampleBigToken ¶
func GetSampleBigToken(startTime uint32, serviceUrl string) *KnotFreeTokenPayload
GetSampleBigToken is used for testing. 256k connections is GiantX32
func GetSampleTokenFromStats ¶ added in v0.1.6
func GetSampleTokenFromStats(startTime uint32, serviceUrl string, stats KnotFreeContactStats) *KnotFreeTokenPayload
GetSampleTokenFromStats is used for testing.
func VerifyToken ¶
func VerifyToken(ticket []byte, publicKey []byte) (*KnotFreeTokenPayload, bool)
VerifyToken is
type SubscriptionNameReservationPayload ¶
type SubscriptionNameReservationPayload struct { // ExpirationTime uint32 `json:"exp,omitempty"` // unix seconds Issuer string `json:"iss"` // first 4 bytes (or more) of base64 public key of issuer JWTID string `json:"jti,omitempty"` // a unique serial number for this Issuer. must be public key of user Name string `json:"name"` // the subscription name }
func VerifyNameToken ¶
func VerifyNameToken(ticket []byte, publicKey []byte) (*SubscriptionNameReservationPayload, bool)
VerifyToken is
type TokenLogStruct ¶
type TokenLogStruct struct { RemoteAddr string When uint32 // unix time Token *KnotFreeTokenPayload }
type TokenReply ¶
type TokenReply struct { Pkey string `json:"pkey"` // a curve25519 pub key of server Payload string `json:"payload"` Nonce string `json:"nonce"` }
TokenReply is created here and boxed and sent back to js
type TokenRequest ¶
type TokenRequest struct { // Pkey string `json:"pkey"` // a curve25519 pub key of caller Payload *KnotFreeTokenPayload `json:"payload"` Comment string `json:"comment"` }
TokenRequest is created in javascript and sent as json.
type TokenType ¶ added in v0.1.4
type TokenType int
const ( Tiny TokenType = iota TinyX2 TinyX4 // this is the free one , 4 connections TinyX8 Small // 16 connections Medium // 32 connections MediumX2 // 64 connections Large // 128 connections LargeX2 // 256 connections LargeX4 // 512 connections LargeX8 // 1024 connections LargeX16 // 2048 connections LargeX32 // 4096 connections Giant // 8192 GiantX2 // 16384 now it's more than one vn GiantX4 // 32768 GiantX8 // 64k GiantX16 // 128k GiantX32 // 256k GiantX64 // 1m GiantX128 // 2m GiantX256 // 4m )
these are powers of two