/
wallet.go
98 lines (84 loc) · 4.86 KB
/
wallet.go
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
/*
Copyright ArxanFintech Technology Ltd. 2017-2018 All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package wallet
import (
"github.com/arxanchain/sdk-go-common/crypto/sign/ed25519"
pw "github.com/arxanchain/sdk-go-common/protos/wallet"
commdid "github.com/arxanchain/sdk-go-common/structs/did"
"github.com/arxanchain/sdk-go-common/structs/pki"
)
////////////////////////////////////////////////////////////////////////////////
// Wallet Structs
// Register wallet request structure
type RegisterWalletBody struct {
Id commdid.Identifier `json:"id,omitempty"` //Wallet ID. Optional, if empty, generated by wallet service
Type pw.DidType `json:"type,omitempty"` //Wallet Type: 1: Common type; 2: Organization; 3: Personal
Access string `json:"access,omitempty"` //Register user name
Phone string `json:"phone,omitempty"` //Register user phone
Email string `json:"email,omitempty"` //Register user email
Secret string `json:"secret,omitempty"` //Register user passwd
AuthInfo interface{} `json:"auth_info,omitempty"` //Register user auth info
Metadata []byte `json:"metadata,omitempty"` //Wallet Metadata
Indexs *IndexTags `json:"indexs,omitempty"` //Wallet indexs
IsPlain bool `json:"is_plain,omitempty"` //Optional, if false, wallet will generate keypair; else, user upload his own keypair
PublicKey *ed25519.PublicKey `json:"public_key,omitempty"` //Wallet public key. Optional, if empty, keypaire auto generated by wallet service
}
// Register subwallet request structure
type RegisterSubWalletBody struct {
Id commdid.Identifier `json:"id,omitempty"` //main wallet id
Type pw.DidType `json:"type,omitempty"` //Subwallet Type: 4: Independent type; 5: Dependent type; 11: Cash type; 12: Fee type; 13: Loan type; 14: Interest type; 21: DAPP type
Symbol string `json:"symbol,omitempty"` //Subwallet symbol
Metadata []byte `json:"metadata,omitempty"` //Subwallet metadata
Indexs *IndexTags `json:"indexs,omitempty"` //Register user indexs
IsPlain bool `json:"is_plain,omitempty"` //Optional, if false, wallet will generate keypair; else, user upload his own keypair
PublicKey *ed25519.PublicKey `json:"public_key,omitempty"` //User public key. Optional, if empty, keypaire auto generated by wallet service
}
// WalletRequest common struct for transfer
type WalletRequest struct {
Payload string `json:"payload,omitempty"`
Signature *pki.SignatureBody `json:"signature,omitempty"`
}
// WalletResponse common struct for wallet API response
type WalletResponse struct {
Code int `json:"code,omitempty"`
Message string `json:"message,omitempty"`
Id commdid.Identifier `json:"id,omitempty"`
Endpoint string `json:"endpoint,omitempty"`
KeyPair *KeyPair `json:"key_pair,omitempty"`
SecurityCode string `json:"security_code,omitempty"`
Created int64 `json:"created,omitempty"`
TokenId string `json:"token_id,omitempty"`
TransactionIds []string `json:"transaction_ids,omitempty"`
}
type KeyPair struct {
PrivateKey string `json:"private_key,omitempty"` //base64 encoded ed25519 private key
PublicKey string `json:"public_key,omitempty"` //base64 encoded ed25519 public key
}
// Balance ...
type Balance struct {
Id string `json:"id,omitempty"` //ctoken id
Amount int64 `json:"amount,omitempty"` //ctoken amount
}
type WalletBalance struct {
ColoredTokens map[string]*Balance `json:"colored_tokens,omitempty"` //all the colored tokens in wallet
DigitalAssets map[string]*Balance `json:"digital_assets,omitempty"` //all the digital assets in wallet
}
type WalletInfo struct {
Id commdid.Identifier `json:"id,omitempty"`
Type pw.DidType `json:"type,omitempty"`
Endpoint commdid.DidEndpoint `json:"endpoint,omitempty"`
Status pw.Status `json:"status,omitempty"`
Created int64 `json:"created,omitempty"`
Updated int64 `json:"updated,omitempty"`
HDS map[commdid.Identifier]*WalletInfo `json:"hds,omitempty"`
}