MCPcopy Create free account
hub / github.com/DNAProject/DNA / NewAccount

Method NewAccount

account/client.go:144–174  ·  view source on GitHub ↗
(label string, typeCode keypair.KeyType, curveCode byte, sigScheme s.SignatureScheme, passwd []byte)

Source from the content-addressed store, hash-verified

142}
143
144func (this *ClientImpl) NewAccount(label string, typeCode keypair.KeyType, curveCode byte, sigScheme s.SignatureScheme, passwd []byte) (*Account, error) {
145 if len(passwd) == 0 {
146 return nil, fmt.Errorf("password cannot empty")
147 }
148 prvkey, pubkey, err := keypair.GenerateKeyPair(typeCode, curveCode)
149 if err != nil {
150 return nil, fmt.Errorf("generateKeyPair error: %s", err)
151 }
152 address := types.AddressFromPubKey(pubkey)
153 addressBase58 := address.ToBase58()
154 prvSecret, err := keypair.EncryptPrivateKey(prvkey, addressBase58, passwd)
155 if err != nil {
156 return nil, fmt.Errorf("encryptPrivateKey error: %s", err)
157 }
158 accData := &AccountData{}
159 accData.Label = label
160 accData.SetKeyPair(prvSecret)
161 accData.SigSch = sigScheme.Name()
162 accData.PubKey = hex.EncodeToString(keypair.SerializePublicKey(pubkey))
163
164 err = this.addAccountData(accData)
165 if err != nil {
166 return nil, err
167 }
168 return &Account{
169 PrivateKey: prvkey,
170 PublicKey: pubkey,
171 Address: address,
172 SigScheme: sigScheme,
173 }, nil
174}
175
176func (this *ClientImpl) addAccountData(accData *AccountData) error {
177 if !this.checkSigScheme(accData.Alg, accData.SigSch) {

Callers 1

TestImportAccountFunction · 0.95

Calls 5

SetKeyPairMethod · 0.95
addAccountDataMethod · 0.95
AddressFromPubKeyFunction · 0.92
ErrorfMethod · 0.80
ToBase58Method · 0.80

Tested by 1

TestImportAccountFunction · 0.76