github.com/0chain/gosdk@v1.17.11/wasmsdk/zbox.go (about) 1 //go:build js && wasm 2 // +build js,wasm 3 4 package main 5 6 import ( 7 "context" 8 "errors" 9 10 "github.com/0chain/gosdk/zboxapi" 11 ) 12 13 var ( 14 zboxApiClient = zboxapi.NewClient() 15 ErrZboxApiNotInitialized = errors.New("0box: please call setWallet to create 0box api client") 16 ) 17 18 func setZbox(host, appType string) { 19 20 } 21 22 // getCsrfToken gets csrf token from 0box api 23 func getCsrfToken() (string, error) { 24 if zboxApiClient == nil { 25 return "", ErrZboxApiNotInitialized 26 } 27 return zboxApiClient.GetCsrfToken(context.TODO()) 28 } 29 30 // createJwtToken creates JWT token with the help of the provided userID. 31 func createJwtToken(userID, accessToken string) (string, error) { 32 if zboxApiClient == nil { 33 return "", ErrZboxApiNotInitialized 34 } 35 return zboxApiClient.CreateJwtToken(context.TODO(), userID, accessToken) 36 } 37 38 // refreshJwtToken refreshes JWT token for the given userID. 39 func refreshJwtToken(userID string, token string) (string, error) { 40 if zboxApiClient == nil { 41 return "", ErrZboxApiNotInitialized 42 } 43 return zboxApiClient.RefreshJwtToken(context.TODO(), userID, token) 44 }