Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zauth support (wasm/clis) #1460

Merged
merged 121 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
c62ca58
Update sprint 1.12 (#1341)
Hitenjain14 Dec 22, 2023
3a57362
fix trailing whitespace (#1343)
Hitenjain14 Dec 23, 2023
ad762e4
Merge staging changes (#1346)
peterlimg Dec 27, 2023
9b9fdd7
fix upload select (#1351)
Hitenjain14 Jan 4, 2024
f3ec2cc
fix workdir in mobile sdk (#1345)
Hitenjain14 Jan 4, 2024
5569b3d
set option to download to disk in wasm (#1348)
Hitenjain14 Jan 4, 2024
199dfd0
fix panic in hash chan (#1352)
Hitenjain14 Jan 4, 2024
2e55c3f
Fix merge conflict in sprint-1.12 (#1354)
Hitenjain14 Jan 4, 2024
4ed3f42
repair in batches (#1347)
Hitenjain14 Jan 4, 2024
edf037a
Merge staging (#1365)
Hitenjain14 Jan 12, 2024
e1a614f
Fix stake pool stats (#1356)
Jayashsatolia403 Jan 21, 2024
0056303
list pagination (#1368)
Hitenjain14 Jan 21, 2024
97b6a5b
Fix sync in windows (#1370)
Roshan-Mehta Jan 21, 2024
09c3757
Add option for mimeType (#1372)
Hitenjain14 Jan 21, 2024
9bc91c6
fix shutdown blobber (#1374)
boddumanohar Jan 21, 2024
6f48750
Merge remote-tracking branch 'origin/staging' into sprint-1.12
dabasov Jan 21, 2024
e7db14c
Cancel upload (#1332)
Hitenjain14 Jan 22, 2024
716e99b
Fix auth response on wasm (#1359)
peterlimg Jan 22, 2024
de8ef8c
Download buffer (#1363)
Hitenjain14 Jan 22, 2024
703cbd0
fix req complete cb (#1381)
Hitenjain14 Jan 29, 2024
312b5cf
get hardfork round by name (#1385)
Hitenjain14 Feb 2, 2024
5cae7a4
made GetFreeAllocationBlobbers public
dabasov Feb 2, 2024
e3d651b
Add miner/sharder stake and unstake support
peterlimg Feb 3, 2024
7deed8a
Add collect rewards for miner/sharder
peterlimg Feb 3, 2024
36e5b10
fixed resp format
dabasov Feb 3, 2024
ccda3cd
fixed resp format
dabasov Feb 3, 2024
b9512d3
Merge branch 'sprint-1.12' into feature/wasm-sc-txn
peterlimg Feb 4, 2024
004db9d
[wasm] Expose minersc - stakePool/unstakePool collect rewards (#1386)
peterlimg Feb 4, 2024
30b02db
Use zcncore transaction for storagesc to support 2fa
peterlimg Feb 5, 2024
86956f1
Remove duplicate Execute transaction in packages
peterlimg Feb 5, 2024
077bcf7
Expose claim rewards to wasm
peterlimg Feb 6, 2024
7e1e0a0
Fix collect rewards
peterlimg Feb 6, 2024
293689e
Merge branch 'staging' into sprint-1.12
dabasov Feb 8, 2024
c713e1b
Merge branch 'sprint-1.12' into feature/wasm-sc-txn
peterlimg Feb 9, 2024
9d83189
Fix transaction output
peterlimg Feb 9, 2024
0736880
Fix send token
peterlimg Feb 14, 2024
0c0f5e4
2FA file operation support
peterlimg Mar 2, 2024
9b0727d
Fix 2FA copy/rename operations
peterlimg Mar 11, 2024
67c92b1
Differ 2FA Sign and normal Sign
peterlimg Mar 12, 2024
ccc75a1
Add SplitKeysWallet to split keys and return wallet
peterlimg Apr 9, 2024
02dc138
Add methods to set split keys and persist
peterlimg Apr 9, 2024
928e2fe
Add isSplit field to wallet to indicate whether the wallet is split o…
peterlimg Apr 9, 2024
8d3abd1
Fix send with zauth
peterlimg Apr 9, 2024
2ab99c2
Add zauth functions
peterlimg Apr 11, 2024
7e4ef8e
Add zauth config for zboxcli
peterlimg Apr 12, 2024
cf1a8b6
Merge branch 'sprint-1.14' into feature/wasm-sc-txn
peterlimg Apr 12, 2024
f8dadd0
Resolve conflicts for setClientInfoWithSign
peterlimg Apr 12, 2024
3ebb76d
Merge branch 'zauth' into zauth-sc-zbox
peterlimg Apr 12, 2024
abc4aac
Update to support zauth server signing
peterlimg Apr 12, 2024
bab6137
Add zauth wasm
peterlimg Apr 16, 2024
67f00a8
Merge branch 'sprint-1.14' into zauth
peterlimg Apr 16, 2024
de58136
Update CallZauthSetup func
peterlimg Apr 25, 2024
b4c6cb1
Add wasm methods to support zvault and zauth
peterlimg Apr 26, 2024
91c0b7d
Merge branch 'sprint-1.14' into zauth
peterlimg Apr 26, 2024
66e47d0
Adjust zvault callback funcs
peterlimg Apr 27, 2024
6ad2c68
Update setWallet to introduce isSplit and peerPublicKey
peterlimg Apr 27, 2024
14206b9
Register zauth server properly
peterlimg Apr 27, 2024
3cbafb7
Init ZCNSDK with split option
peterlimg Apr 27, 2024
8256289
Clean up debug logs
peterlimg Apr 27, 2024
bb21816
Fix write marker signature verify
peterlimg Apr 28, 2024
e90ddfb
Merge branch 'sprint-1.14' into zauth
peterlimg May 8, 2024
8a35d81
Adjust wasm auth sign
peterlimg May 11, 2024
b59695a
Adjust wasm auth common sign
peterlimg May 12, 2024
9a9c771
ScryptEncrypt key does not have to be 32, it's the derivate key from …
peterlimg May 12, 2024
525999d
Add passphrase requirement for auth keys store and generate
peterlimg May 12, 2024
e044811
Add multiple users support zauth server
peterlimg May 12, 2024
50398c2
Fix wasm panic on auth error
peterlimg May 13, 2024
183e980
Fix invalid signature after updating allocation
peterlimg May 1, 2024
bc3d2c5
Merge branch 'sprint-1.16' into zauth-sprint
peterlimg Jun 21, 2024
fb4e204
Merge branch 'refs/heads/staging' into zauth-sprint
peterlimg Jun 22, 2024
b68ef0a
Fix errors after meging staging
peterlimg Jun 22, 2024
d25db1e
Add missing functions for wasm worker mode
peterlimg Jun 23, 2024
96f969b
Add revoke and expiredAt field to split wallet for zauth
peterlimg Jun 24, 2024
3aa20c6
Add CallZauthRevoke
peterlimg Jun 24, 2024
6123e8e
Add CallZauthDelete method
peterlimg Jun 28, 2024
48266c7
Add zauthServer address env to web worker
peterlimg Jun 28, 2024
0eaba21
Add more zvault wasm methods
peterlimg Jun 28, 2024
5856049
Remove pubkey from registerZauthServer
peterlimg Jun 29, 2024
eb7343e
Fix BLE with web worker
peterlimg Jun 26, 2024
276821f
Fix none BLE sign
peterlimg Jun 26, 2024
72b611d
Comment unused method
peterlimg Jun 29, 2024
f001735
Update worker wallet with event
peterlimg Jun 26, 2024
3e26c77
Fix conflicts after cherry-pick
peterlimg Jun 29, 2024
0f07bce
Fix sign
peterlimg Jun 29, 2024
040d0c6
fix: renamed header used for jwt session creation (#1553)
YarikRevich Jul 16, 2024
c6ae0a4
Feature: add additional zvault endpoints for WASM (#1554)
YarikRevich Jul 16, 2024
dd8169e
fix: fixed signature hash function (#1564)
YarikRevich Jul 25, 2024
390bc6d
feature: added shared wallets retrieval calls (#1567)
YarikRevich Jul 27, 2024
456707b
feature: migrated to use user id instead of phone number to issue jwt…
YarikRevich Aug 4, 2024
e979186
Merge pull request #1572 from 0chain/feature/jwt-token-firebase
dabasov Aug 5, 2024
28f95c0
hotfix: fixed mobilesdk signature
YarikRevich Aug 9, 2024
c24d664
Merge remote-tracking branch 'origin' into zauth
Hitenjain14 Aug 14, 2024
325dcaf
Merge branch 'sprint-1.17' into zauth
dabasov Aug 15, 2024
48c63d5
fix merge errors
dabasov Aug 15, 2024
b4b6430
fix: debug
YarikRevich Aug 16, 2024
885ce57
fix: debug
YarikRevich Aug 16, 2024
fbfec22
fix: debug
YarikRevich Aug 16, 2024
9076aff
fix: debug
YarikRevich Aug 16, 2024
8676cfb
fix: debug
YarikRevich Aug 16, 2024
7a9a501
fix: debug
YarikRevich Aug 16, 2024
145f70d
fix: debug
YarikRevich Aug 16, 2024
26999fd
fix: debug
YarikRevich Aug 16, 2024
c652297
fix: fixed bugs
YarikRevich Aug 16, 2024
21153ff
fix: fixed bugs
YarikRevich Aug 16, 2024
f2fc002
fix: fixed bugs
YarikRevich Aug 16, 2024
ac7d416
fix: fixed bugs
YarikRevich Aug 17, 2024
fbc411c
Merge pull request #1579 from 0chain/fix/zauth-mobile
dabasov Aug 17, 2024
88874a4
Merge branch 'sprint-1.17' into zauth
dabasov Aug 17, 2024
ce83471
fix: fixed sign function initialization
YarikRevich Aug 25, 2024
996204b
Merge pull request #1586 from 0chain/fix/sign-initialization
dabasov Aug 25, 2024
fd876bc
fix start processor for upload in wasm
Hitenjain14 Aug 28, 2024
cbb3c74
initalize sub map
Hitenjain14 Aug 28, 2024
4963fd8
Merge pull request #1591 from 0chain/fix/upload-processor
dabasov Aug 28, 2024
9e4f654
Merge branch 'sprint-1.17' into zauth
dabasov Aug 28, 2024
2f3176e
Merge branch 'sprint-1.17' into zauth
YarikRevich Aug 29, 2024
55b9e82
fix: failing dex transaction
YarikRevich Aug 30, 2024
b7d198d
Merge pull request #1592 from 0chain/fix/dex-transaction
dabasov Aug 31, 2024
ed5faba
fix: return transaction nonce if certain status code received
YarikRevich Aug 31, 2024
4389726
Merge branch 'sprint-1.17' into zauth
dabasov Sep 1, 2024
bc62a1f
Merge branch 'zauth' into fix/transaction-nonce
dabasov Sep 1, 2024
ce7fb54
Merge pull request #1593 from 0chain/fix/transaction-nonce
dabasov Sep 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions core/conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ type Config struct {
// ZboxAppType app type name
ZboxAppType string `json:"zbox_app_type"`
// SharderConsensous is consensous for when quering for SCRestAPI calls
SharderConsensous int `json:"sharder_consensous"`
SharderConsensous int `json:"sharder_consensous"`
ZauthServer string `json:"zauth_server"`
V *viper.Viper `json:"-"`
}

// LoadConfigFile load and parse SDK Config from file
Expand All @@ -104,7 +106,14 @@ func LoadConfigFile(file string) (Config, error) {
return cfg, thrown.Throw(ErrBadParsing, err.Error())
}

return LoadConfig(v)
cfg, err = LoadConfig(v)
if err != nil {
return cfg, err
}

cfg.V = v

return cfg, nil
}

// LoadConfig load and parse config
Expand Down Expand Up @@ -170,9 +179,9 @@ func LoadConfig(v Reader) (Config, error) {

cfg.SignatureScheme = v.GetString("signature_scheme")
cfg.ChainID = v.GetString("chain_id")
cfg.ZauthServer = v.GetString("zauth.server")

return cfg, nil

}

func isURL(s string) bool {
Expand Down
4 changes: 4 additions & 0 deletions core/conf/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func TestLoadConfig(t *testing.T) {
var mockDefaultReader = func() Reader {
reader := &mocks.Reader{}
reader.On("GetString", "block_worker").Return("http://127.0.0.1:9091/dns")
reader.On("GetString", "zauth.server").Return("http://127.0.0.1:8090/")
reader.On("GetInt", "min_submit").Return(0)
reader.On("GetInt", "min_confirmation").Return(0)
reader.On("GetInt", "max_txn_query").Return(0)
Expand Down Expand Up @@ -41,6 +42,7 @@ func TestLoadConfig(t *testing.T) {

reader := &mocks.Reader{}
reader.On("GetString", "block_worker").Return("")
reader.On("GetString", "zauth.server").Return("")
reader.On("GetInt", "min_submit").Return(0)
reader.On("GetInt", "min_confirmation").Return(0)
reader.On("GetInt", "max_txn_query").Return(0)
Expand Down Expand Up @@ -85,6 +87,7 @@ func TestLoadConfig(t *testing.T) {

reader := &mocks.Reader{}
reader.On("GetString", "block_worker").Return("https://127.0.0.1:9091/dns")
reader.On("GetString", "zauth.server").Return("http://127.0.0.1:8090/")
reader.On("GetInt", "min_submit").Return(101)
reader.On("GetInt", "min_confirmation").Return(0)
reader.On("GetInt", "max_txn_query").Return(0)
Expand Down Expand Up @@ -119,6 +122,7 @@ func TestLoadConfig(t *testing.T) {

reader := &mocks.Reader{}
reader.On("GetString", "block_worker").Return("https://127.0.0.1:9091/dns")
reader.On("GetString", "zauth.server").Return("http://127.0.0.1:8090/")
reader.On("GetInt", "min_submit").Return(0)
reader.On("GetInt", "min_confirmation").Return(101)
reader.On("GetInt", "max_txn_query").Return(0)
Expand Down
14 changes: 13 additions & 1 deletion core/sys/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ var (
Sleep = time.Sleep

// Sign sign method. it should be initialized on different platform.
Sign SignFunc
Sign SignFunc
SignWithAuth SignFunc

// Verify verify method. it should be initialized on different platform.
Verify VerifyFunc
Expand All @@ -23,4 +24,15 @@ var (
VerifyWith VerifyWithFunc

Authorize AuthorizeFunc

AuthCommon AuthorizeFunc
)

// SetAuthorize sets the authorize callback function
func SetAuthorize(auth AuthorizeFunc) {
Authorize = auth
}

func SetAuthCommon(auth AuthorizeFunc) {
AuthCommon = auth
}
5 changes: 3 additions & 2 deletions core/transaction/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,15 @@ func NewTransactionReceipt(t *Transaction) *TxnReceipt {
return &TxnReceipt{Transaction: t}
}

func (t *Transaction) VerifyTransaction(verifyHandler VerifyFunc) (bool, error) {
// VerifySigWith verify the signature with the given public key and handler
func (t *Transaction) VerifySigWith(pubkey string, verifyHandler VerifyFunc) (bool, error) {
// Store the hash
hash := t.Hash
t.ComputeHashData()
if t.Hash != hash {
return false, errors.New("verify_transaction", fmt.Sprintf(`{"error":"hash_mismatch", "expected":"%v", "actual":%v"}`, t.Hash, hash))
}
return verifyHandler(t.PublicKey, t.Signature, t.Hash)
return verifyHandler(pubkey, t.Signature, t.Hash)
}

func SendTransactionSync(txn *Transaction, miners []string) error {
Expand Down
3 changes: 1 addition & 2 deletions core/version/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

//====== THIS IS AUTOGENERATED FILE. DO NOT MODIFY ========

package version
const VERSIONSTR = "v1.16.3-10-g66360b13"

const VERSIONSTR = "v1.16.3-10-g66360b13"
7 changes: 6 additions & 1 deletion core/zcncrypto/bls0chain_herumi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,14 @@ func TestCombinedSignAndVerify(t *testing.T) {
}

func TestSplitKey(t *testing.T) {
primaryKeyStr := `c36f2f92b673cf057a32e8bd0ca88888e7ace40337b737e9c7459fdc4c521918`
primaryKeyStr := `872eac6370c72093535fa395ad41a08ee90c9d0d46df9461eb2515451f389d1b`
// primaryKeyStr := `c36f2f92b673cf057a32e8bd0ca88888e7ace40337b737e9c7459fdc4c521918`
sig0 := NewSignatureScheme("bls0chain")
err := sig0.SetPrivateKey(primaryKeyStr)
if err != nil {
t.Fatalf("Set private key failed - %s", errors.Top(err))
}
data = "823bb3dc0b80a6c86922a884e63908cb9e963ef488688b41e32cbf4d84471a1f"
hash := Sha3Sum256(data)
signature, err := sig0.Sign(hash)
if err != nil {
Expand All @@ -170,15 +172,18 @@ func TestSplitKey(t *testing.T) {
for i := 0; i < numSplitKeys; i++ {
sigAggScheme[i] = NewSignatureScheme("bls0chain")
err = sigAggScheme[i].SetPrivateKey(w.Keys[i].PrivateKey)
fmt.Println("seckey:", sigAggScheme[i].GetPrivateKey())

require.NoError(t, err)
}
var aggrSig string
for i := 1; i < numSplitKeys; i++ {
tmpSig, _ := sigAggScheme[i].Sign(hash)
fmt.Println("tmpSig:", tmpSig)
aggrSig, _ = sigAggScheme[0].Add(tmpSig, hash)
}
if aggrSig != signature {
t.Fatalf("split key signature failed")
}
fmt.Println("aggrSig:", aggrSig)
}
47 changes: 27 additions & 20 deletions core/zcncrypto/signature_scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package zcncrypto

import (
"encoding/json"
"fmt"
"os"

"github.com/0chain/errors"
"github.com/0chain/gosdk/core/encryption"
Expand All @@ -20,26 +22,15 @@ type KeyPair struct {

// Wallet represents client wallet information
type Wallet struct {
// ClientID client unique identifier
ClientID string `json:"client_id"`

// ClientKey client public key
ClientKey string `json:"client_key"`

// Keys private and public key pair
Keys []KeyPair `json:"keys"`

// Mnemonic recovery phrase of the wallet
Mnemonic string `json:"mnemonics"`

// Version version of the wallet
Version string `json:"version"`

// DateCreated date of wallet creation
DateCreated string `json:"date_created"`

// Nonce nonce of the wallet
Nonce int64 `json:"nonce"`
ClientID string `json:"client_id"`
ClientKey string `json:"client_key"`
PeerPublicKey string `json:"peer_public_key"` // Peer public key exists only in split wallet
Keys []KeyPair `json:"keys"`
Mnemonic string `json:"mnemonics"`
Version string `json:"version"`
DateCreated string `json:"date_created"`
Nonce int64 `json:"nonce"`
IsSplit bool `json:"is_split"`
}

// SignatureScheme - an encryption scheme for signing and verifying messages
Expand Down Expand Up @@ -96,6 +87,22 @@ func (w *Wallet) Sign(hash, scheme string) (string, error) {
return sigScheme.Sign(hash)
}

// SetSplitKeys sets split keys and wipes out mnemonic and original primary keys
func (w *Wallet) SetSplitKeys(sw *Wallet) {
*w = *sw
}

func (w *Wallet) SaveTo(file string) error {
d, err := json.Marshal(w)
if err != nil {
return err
}

fmt.Println("Saving wallet to file: ", string(d))

return os.WriteFile(file, d, 0644)
}

func IsMnemonicValid(mnemonic string) bool {
return bip39.IsMnemonicValid(mnemonic)
}
Expand Down
14 changes: 7 additions & 7 deletions mobilesdk/zboxapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,30 @@ func GetCsrfToken() (string, error) {

// CreateJwtSession create a jwt session for the given phone number
// - phoneNumber is the phone number
func CreateJwtSession(phoneNumber string) (int64, error) {
func CreateJwtSession(userID string) (int64, error) {
if zboxApiClient == nil {
return 0, ErrZboxApiNotInitialized
}
return zboxApiClient.CreateJwtSession(context.TODO(), phoneNumber)
return zboxApiClient.CreateJwtSession(context.TODO(), userID)
}

// CreateJwtToken create a fresh jwt token for the given phone number
// CreateJwtToken create a fresh jwt token for the given user id
// - phoneNumber is the phone number
// - jwtSessionID is the jwt session id
// - otp is the one time password
func CreateJwtToken(phoneNumber string, jwtSessionID int64, otp string) (string, error) {
func CreateJwtToken(userID string, jwtSessionID int64) (string, error) {
if zboxApiClient == nil {
return "", ErrZboxApiNotInitialized
}
return zboxApiClient.CreateJwtToken(context.TODO(), phoneNumber, jwtSessionID, otp)
return zboxApiClient.CreateJwtToken(context.TODO(), userID, jwtSessionID)
}

// RefreshJwtToken refresh jwt token
// - phoneNumber is the phone number for which the token is to be refreshed
// - token is the token to be refreshed
func RefreshJwtToken(phoneNumber string, token string) (string, error) {
func RefreshJwtToken(userID string, token string) (string, error) {
if zboxApiClient == nil {
return "", ErrZboxApiNotInitialized
}
return zboxApiClient.RefreshJwtToken(context.TODO(), phoneNumber, token)
return zboxApiClient.RefreshJwtToken(context.TODO(), userID, token)
}
11 changes: 9 additions & 2 deletions mobilesdk/zcn/smartcontract.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package zcn
import (
"encoding/json"
"fmt"
"strconv"
"sync"

"github.com/0chain/gosdk/zcncore"
Expand All @@ -19,13 +20,19 @@ func Faucet(methodName, jsonInput string, zcnToken float64) (string, error) {
func ExecuteSmartContract(address, methodName, input string, sasToken string) (string, error) {
wg := &sync.WaitGroup{}
cb := &transactionCallback{wg: wg}
txn, err := zcncore.NewTransaction(cb, "0", 0)
txn, err := zcncore.NewTransaction(cb, 0, 0)
if err != nil {
return "", err
}

wg.Add(1)
err = txn.ExecuteSmartContract(address, methodName, input, sasToken)

v, err := strconv.ParseUint(sasToken, 10, 64)
if err != nil {
return "", fmt.Errorf("invalid token value: %v, err: %v", sasToken, err)
}

_, err = txn.ExecuteSmartContract(address, methodName, input, v)
if err != nil {
return "", err

Expand Down
5 changes: 5 additions & 0 deletions wasmsdk/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,11 @@ func unlockStakePool(providerType, fee uint64, providerID string) (int64, error)
return unstake, err
}

func collectRewards(providerType int, providerID string) (string, error) {
hash, _, err := sdk.CollectRewards(providerID, sdk.ProviderType(providerType))
return hash, err
}

// getSkatePoolInfo is to get information about the stake pool for the allocation
// - providerType: provider type (1: miner, 2:sharder, 3:blobber, 4:validator, 5:authorizer)
// - providerID: provider id
Expand Down
61 changes: 61 additions & 0 deletions wasmsdk/auth_txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ import (
"syscall/js"

"github.com/0chain/gosdk/core/sys"
"github.com/0chain/gosdk/wasmsdk/jsbridge"
"github.com/0chain/gosdk/zcncore"
)

type AuthCallbackFunc func(msg string) string

var authMsgCallback AuthCallbackFunc
var authCallback AuthCallbackFunc
var authResponseC chan string
var authMsgResponseC chan string
var authMsgLock = make(chan struct{}, 1)

// registerAuthorizer Register the callback function to authorize the transaction.
// This function is called from JavaScript.
Expand All @@ -30,6 +35,62 @@ func registerAuthorizer(this js.Value, args []js.Value) interface{} {
return nil
}

func registerZauthServer(serverAddr string) {
fmt.Println("registerZauthServer...")
jsbridge.SetZauthServer(serverAddr)
sys.SetAuthorize(zcncore.ZauthSignTxn(serverAddr))
sys.SetAuthCommon(zcncore.ZauthAuthCommon(serverAddr))
}

// zvaultNewWallet generates new split wallet
func zvaultNewWallet(serverAddr, token string) (string, error) {
return zcncore.CallZvaultNewWalletString(serverAddr, token, "")
}

// zvaultNewSplit generates new split wallet from existing clientID
func zvaultNewSplit(clientID, serverAddr, token string) (string, error) {
return zcncore.CallZvaultNewWalletString(serverAddr, token, clientID)
}

func zvaultStoreKey(serverAddr, token, privateKey string) (string, error) {
return zcncore.CallZvaultStoreKeyString(serverAddr, token, privateKey)
}

func zvaultRetrieveKeys(serverAddr, token, clientID string) (string, error) {
return zcncore.CallZvaultRetrieveKeys(serverAddr, token, clientID)
}

func zvaultRevokeKey(serverAddr, token, clientID, publicKey string) error {
return zcncore.CallZvaultRevokeKey(serverAddr, token, clientID, publicKey)
}

func zvaultDeletePrimaryKey(serverAddr, token, clientID string) error {
return zcncore.CallZvaultDeletePrimaryKey(serverAddr, token, clientID)
}

func zvaultRetrieveWallets(serverAddr, token string) (string, error) {
return zcncore.CallZvaultRetrieveWallets(serverAddr, token)
}

func zvaultRetrieveSharedWallets(serverAddr, token string) (string, error) {
return zcncore.CallZvaultRetrieveSharedWallets(serverAddr, token)
}

func registerAuthCommon(this js.Value, args []js.Value) interface{} {
authMsgCallback = parseAuthorizerCallback(args[0])
authMsgResponseC = make(chan string, 1)

sys.AuthCommon = func(msg string) (string, error) {
authMsgLock <- struct{}{}
defer func() {
<-authMsgLock
}()
authMsgCallback(msg)
return <-authMsgResponseC, nil
}
return nil
}

// authResponse Publishes the response to the authorization request.
// `response` is the response to the authorization request.
func authResponse(response string) {
Expand Down
Loading
Loading