// GetIdentity returns the public identity corresponding to the given address // if it exists. func (c *Client) GetIdentity(address string) (*identity.Public, error) { addr, err := bmutil.DecodeAddress(address) if err != nil { return nil, fmt.Errorf("Address decode failed: %v", addr) } res, err := c.bmd.GetIdentity(context.Background(), &pb.GetIdentityRequest{ Address: address, }) if grpc.Code(err) == codes.NotFound { return nil, ErrIdentityNotFound } else if err != nil { return nil, err } signKey, err := btcec.ParsePubKey(res.SigningKey, btcec.S256()) if err != nil { return nil, err } encKey, err := btcec.ParsePubKey(res.EncryptionKey, btcec.S256()) if err != nil { return nil, err } return identity.NewPublic(signKey, encKey, &pow.Data{ res.NonceTrials, res.ExtraBytes, }, addr.Version, addr.Stream), nil }
// BroadcastRead creates a Bitmessage object from an unencrypted // wire.MsgBroadcast. func BroadcastRead(msg *cipher.Broadcast) (*Bmail, error) { header := msg.Object().Header() data := msg.Bitmessage() sign, _ := data.SigningKey.ToBtcec() encr, _ := data.EncryptionKey.ToBtcec() from := identity.NewPublic(sign, encr, data.Pow, data.FromAddressVersion, data.FromStreamNumber) fromAddress, err := from.Address.Encode() if err != nil { return nil, err } return &Bmail{ From: "*****@*****.**", To: bmToEmail(fromAddress), Expiration: header.Expiration(), Content: data.Content, }, nil }
// MsgRead creates a Bitmessage object from an unencrypted wire.MsgMsg. func MsgRead(msg *cipher.Message, toAddress string, ofChan bool) (*Bmail, error) { data := msg.Bitmessage() object := msg.Object() header := object.Header() sign, _ := data.SigningKey.ToBtcec() encr, _ := data.EncryptionKey.ToBtcec() from := identity.NewPublic(sign, encr, data.Pow, data.FromAddressVersion, data.FromStreamNumber) fromAddress, err := from.Address.Encode() if err != nil { return nil, err } return &Bmail{ From: bmToEmail(fromAddress), To: bmToEmail(toAddress), Expiration: header.Expiration(), Ack: msg.Ack(), OfChannel: ofChan, Content: data.Content, object: object.MsgObject(), }, nil }