diff --git a/bindings/channels.go b/bindings/channels.go index a70a0bda2dd5862a97743abf5eff95db85e8e693..d3563bdd1a7ffdcece5ecbf7a508c2236fc115ad 100644 --- a/bindings/channels.go +++ b/bindings/channels.go @@ -355,7 +355,7 @@ func LoadChannelsManager(cmixID int, storageTag string, // // Example JSON: // { -// "Channel": "\u003cSpeakeasy-v1:My_Channel,description:Here is information about my channel.,level:Public,secrets:8AS3SczFvAYZftWuj4ZkOM9muFPIwq/0HuVCUJgTK8w=,GpPl1510/G07J4RfdYX9J5plTX3WNLVm+uuGmCwgFeU=,5,1,mRfdUGM6WxWjjCuLzO+2+zc3BQh2zMT2CHD8ZnBwpVI=\u003e", +// "Channel": "\u003cSpeakeasy-v2:Test_Channel|description:Channel description.|level:Public|secrets:8AS3SczFvAYZftWuj4ZkOM9muFPIwq/0HuVCUJgTK8w=|GpPl1510/G07J4RfdYX9J5plTX3WNLVm+uuGmCwgFeU=|5|1|mRfdUGM6WxWjjCuLzO+2+zc3BQh2zMT2CHD8ZnBwpVI=\u003e", // "PrivateKey": "-----BEGIN RSA PRIVATE KEY-----\nMDECAQACBgDMIU9LpQIDAQABAgYAvCd9ewECAw0tzQIDD305AgMFu4UCAwd+kQID\nAQxc\n-----END RSA PRIVATE KEY-----" // } type ChannelGeneration struct { @@ -454,6 +454,74 @@ func makeChannelPrivateKeyStoreKey(channelID *id.ID) string { return channelPrivateKeyStoreKey + "/" + channelID.String() } +// DecodePublicURL decodes the channel URL into a channel pretty print. This +// function can only be used for public channel URLs. To get the privacy level +// of a channel URL, use [GetShareUrlType]. +// +// Parameters: +// - url - The channel's share URL. Should be received from another user or +// generated via [GetShareURL]. +// +// Returns: +// - The channel pretty print. +func DecodePublicURL(url string) (string, error) { + c, err := cryptoBroadcast.DecodeShareURL(url, "") + if err != nil { + return "", err + } + + return c.PrettyPrint(), nil +} + +// DecodePrivateURL decodes the channel URL, using the password, into a channel +// pretty print. This function can only be used for private or secret channel +// URLs. To get the privacy level of a channel URL, use [GetShareUrlType]. +// +// Parameters: +// - url - The channel's share URL. Should be received from another user or +// generated via [GetShareURL]. +// - password - The password needed to decrypt the secret data in the URL. +// +// Returns: +// - The channel pretty print. +func DecodePrivateURL(url, password string) (string, error) { + c, err := cryptoBroadcast.DecodeShareURL(url, password) + if err != nil { + return "", err + } + + return c.PrettyPrint(), nil +} + +// GetChannelJSON returns the JSON of the channel for the given pretty print. +// +// Parameters: +// - prettyPrint - The pretty print of the channel. +// +// Returns: +// - JSON of the [broadcast.Channel] object. +// +// Example JSON of [broadcast.Channel]: +// { +// "ReceptionID": "Ja/+Jh+1IXZYUOn+IzE3Fw/VqHOscomD0Q35p4Ai//kD", +// "Name": "My_Channel", +// "Description": "Here is information about my channel.", +// "Salt": "+tlrU/htO6rrV3UFDfpQALUiuelFZ+Cw9eZCwqRHk+g=", +// "RsaPubKeyHash": "PViT1mYkGBj6AYmE803O2RpA7BX24EjgBdldu3pIm4o=", +// "RsaPubKeyLength": 5, +// "RSASubPayloads": 1, +// "Secret": "JxZt/wPx2luoPdHY6jwbXqNlKnixVU/oa9DgypZOuyI=", +// "Level": 0 +// } +func GetChannelJSON(prettyPrint string) ([]byte, error) { + c, err := cryptoBroadcast.NewChannelFromPrettyPrint(prettyPrint) + if err != nil { + return nil, nil + } + + return json.Marshal(c) +} + // ChannelInfo contains information about a channel. // // Example of ChannelInfo JSON: @@ -474,7 +542,7 @@ type ChannelInfo struct { // - prettyPrint - The pretty print of the channel. // // The pretty print will be of the format: -// <Speakeasy-v1:Test Channel,description:This is a test channel,secrets:YxHhRAKy2D4XU2oW5xnW/3yaqOeh8nO+ZSd3nUmiQ3c=,6pXN2H9FXcOj7pjJIZoq6nMi4tGX2s53fWH5ze2dU1g=,493,1,MVjkHlm0JuPxQNAn6WHsPdOw9M/BUF39p7XB/QEkQyc=> +// <Speakeasy-v2:Test_Channel|description:Channel description.|level:Public|secrets:+oHcqDbJPZaT3xD5NcdLY8OjOMtSQNKdKgLPmr7ugdU=|rCI0wr01dHFStjSFMvsBzFZClvDIrHLL5xbCOPaUOJ0=|493|1|7cBhJxVfQxWo+DypOISRpeWdQBhuQpAZtUbQHjBm8NQ=> // // Returns: // - []byte - JSON of [ChannelInfo], which describes all relevant channel info. @@ -508,7 +576,7 @@ func getChannelInfo(prettyPrint string) (*cryptoBroadcast.Channel, []byte, error // another user or generated via GenerateChannel. // // The pretty print will be of the format: -// <Speakeasy-v1:Test Channel,description:This is a test channel,secrets:YxHhRAKy2D4XU2oW5xnW/3yaqOeh8nO+ZSd3nUmiQ3c=,6pXN2H9FXcOj7pjJIZoq6nMi4tGX2s53fWH5ze2dU1g=,493,1,MVjkHlm0JuPxQNAn6WHsPdOw9M/BUF39p7XB/QEkQyc=> +// <Speakeasy-v2:Test_Channel|description:Channel description.|level:Public|secrets:+oHcqDbJPZaT3xD5NcdLY8OjOMtSQNKdKgLPmr7ugdU=|rCI0wr01dHFStjSFMvsBzFZClvDIrHLL5xbCOPaUOJ0=|493|1|7cBhJxVfQxWo+DypOISRpeWdQBhuQpAZtUbQHjBm8NQ=> // // Returns: // - []byte - JSON of [ChannelInfo], which describes all relevant channel info. @@ -524,40 +592,6 @@ func (cm *ChannelsManager) JoinChannel(channelPretty string) ([]byte, error) { return info, err } -// JoinChannelFromURL joins the given channel from a URL. It will fail if the -// channel has already been joined. A password is required unless it is of the -// privacy level [broadcast.Public], in which case it can be left empty. To get -// the privacy level of a channel URL, use [GetShareUrlType]. -// -// Parameters: -// - url - The channel's share URL. Should be received from another user or -// generated via [GetShareURL]. -// - password - The password needed to decrypt the secret data in the URL. Only -// required for private or secret channels. -// -// Returns: -// - []byte - [ChannelInfo] describes all relevant channel info. -func (cm *ChannelsManager) JoinChannelFromURL(url, password string) ([]byte, error) { - c, err := cryptoBroadcast.DecodeShareURL(url, password) - if err != nil { - return nil, err - } - - info, err := json.Marshal(&ChannelInfo{ - Name: c.Name, - Description: c.Description, - ChannelID: c.ReceptionID.String(), - }) - if err != nil { - return nil, err - } - - // Join the channel using the API - err = cm.api.JoinChannel(c) - - return info, err -} - // GetChannels returns the IDs of all channels that have been joined. // // Returns: diff --git a/fileTransfer/store/received.go b/fileTransfer/store/received.go index 189025a711b89537022a99ec72d19eaf98e63c91..6ec51f2e0188bc4d1ab05b7ec2c2ee044588951c 100644 --- a/fileTransfer/store/received.go +++ b/fileTransfer/store/received.go @@ -100,7 +100,7 @@ func (r *Received) AddTransfer(key *ftCrypto.TransferKey, _, exists := r.transfers[*tid] if exists { - return nil, errors.Errorf(errAddExistingReceivedTransfer, tid) + return nil, errors.Errorf(errAddExistingReceivedTransfer, *tid) } rt, err := newReceivedTransfer( diff --git a/fileTransfer/store/sent.go b/fileTransfer/store/sent.go index a7f89a598dd79ec14b421b0101d0dae5ab7e05cf..d5e22ad8e976bb7d21c7e5e0c100496c19b363b3 100644 --- a/fileTransfer/store/sent.go +++ b/fileTransfer/store/sent.go @@ -108,7 +108,7 @@ func (s *Sent) AddTransfer(recipient *id.ID, key *ftCrypto.TransferKey, _, exists := s.transfers[*tid] if exists { - return nil, errors.Errorf(errAddExistingSentTransfer, tid) + return nil, errors.Errorf(errAddExistingSentTransfer, *tid) } st, err := newSentTransfer( diff --git a/go.sum b/go.sum index d0d57a09e6e110ba1ee655370a4c4eb8c5905418..cb1c28515f9fcf2f60f522263d0fcc8ee9df2cdd 100644 --- a/go.sum +++ b/go.sum @@ -642,12 +642,8 @@ gitlab.com/elixxir/comms v0.0.4-0.20221023190124-3441c3fdc3de/go.mod h1:rW7xdbHn gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c= gitlab.com/elixxir/crypto v0.0.3/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA= gitlab.com/elixxir/crypto v0.0.7-0.20221017173452-565da4101a3b/go.mod h1:1rftbwSVdy49LkBIkPr+w+P2mDOerYeBKoZuB3r0yqI= -gitlab.com/elixxir/crypto v0.0.7-0.20221017204335-9201b3672f3a h1:RxobrpD5owwdyNg5KTqBINJ8z0zsXsbu+UhMEC80wIE= -gitlab.com/elixxir/crypto v0.0.7-0.20221017204335-9201b3672f3a/go.mod h1:1rftbwSVdy49LkBIkPr+w+P2mDOerYeBKoZuB3r0yqI= -gitlab.com/elixxir/crypto v0.0.7-0.20221020231252-3c82f61ce90f h1:Gb9CUZ4Ln3iB/qFS7paZ1AwYObdhf4aYy9RJq79lSDI= -gitlab.com/elixxir/crypto v0.0.7-0.20221020231252-3c82f61ce90f/go.mod h1:1rftbwSVdy49LkBIkPr+w+P2mDOerYeBKoZuB3r0yqI= -gitlab.com/elixxir/crypto v0.0.7-0.20221021211329-2d8ef59a4df1 h1:e4/JCQBNzEeVqs5XJx+QskxtvJVHt4NwVpPJa0Q+xlk= -gitlab.com/elixxir/crypto v0.0.7-0.20221021211329-2d8ef59a4df1/go.mod h1:1rftbwSVdy49LkBIkPr+w+P2mDOerYeBKoZuB3r0yqI= +gitlab.com/elixxir/crypto v0.0.7-0.20221022003355-d8a6158b32a7 h1:+8DHBxZxJcmJSmcUFK4ZjjXgwV3wSo9O4+4NCaLdO4c= +gitlab.com/elixxir/crypto v0.0.7-0.20221022003355-d8a6158b32a7/go.mod h1:P/S3pEPYl7fuHQ1m4mL2pIaCxAjYIXrJml/pnfofI+U= gitlab.com/elixxir/ekv v0.2.1 h1:dtwbt6KmAXG2Tik5d60iDz2fLhoFBgWwST03p7T+9Is= gitlab.com/elixxir/ekv v0.2.1/go.mod h1:USLD7xeDnuZEavygdrgzNEwZXeLQJK/w1a+htpN+JEU= gitlab.com/elixxir/primitives v0.0.0-20200731184040-494269b53b4d/go.mod h1:OQgUZq7SjnE0b+8+iIAT2eqQF+2IFHn73tOo+aV11mg=