diff --git a/bindings/e2eAuth.go b/bindings/e2eAuth.go index b2277eb3e3c77ae54ab933dae3b23c9edee9ef25..801a2829ec1feb9584a90bd80015b9d5f35baefe 100644 --- a/bindings/e2eAuth.go +++ b/bindings/e2eAuth.go @@ -35,12 +35,12 @@ import ( // // Parameters: // - partnerContact - the marshalled bytes of the contact.Contact object. -// - myFacts - stringified list of fact.FactList. +// - factsListJson - the JSON marshalled bytes of [fact.FactList]. // // Returns: // - int64 - ID of the round (convert to uint64) func (e *E2e) Request(partnerContact, factsListJson []byte) (int64, error) { - var factsList []Fact + var factsList fact.FactList err := json.Unmarshal(factsListJson, &factsList) if err != nil { return 0, err @@ -51,15 +51,7 @@ func (e *E2e) Request(partnerContact, factsListJson []byte) (int64, error) { return 0, err } - myFacts := fact.FactList{} - for _, f := range factsList { - myFacts = append(myFacts, fact.Fact{ - Fact: f.Fact, - T: fact.FactType(f.Type), - }) - } - - roundID, err := e.api.GetAuth().Request(partner, myFacts) + roundID, err := e.api.GetAuth().Request(partner, factsList) return int64(roundID), err } diff --git a/bindings/identity.go b/bindings/identity.go index f1b56803184de8491f3c93ad43d89008f6227bd4..9b45a95274e50f22c47f678df568f42503b19d4a 100644 --- a/bindings/identity.go +++ b/bindings/identity.go @@ -99,8 +99,8 @@ func (c *Cmix) GetReceptionRegistrationValidationSignature() []byte { // GetIDFromContact accepts a marshalled contact.Contact object and returns a // marshalled id.ID object. -func GetIDFromContact(marshaled []byte) ([]byte, error) { - cnt, err := contact.Unmarshal(marshaled) +func GetIDFromContact(marshaledContact []byte) ([]byte, error) { + cnt, err := contact.Unmarshal(marshaledContact) if err != nil { return nil, err } @@ -110,8 +110,8 @@ func GetIDFromContact(marshaled []byte) ([]byte, error) { // GetPubkeyFromContact accepts a marshalled contact.Contact object and returns // a JSON marshalled large.Int DH public key. -func GetPubkeyFromContact(marshaled []byte) ([]byte, error) { - cnt, err := contact.Unmarshal(marshaled) +func GetPubkeyFromContact(marshaledContact []byte) ([]byte, error) { + cnt, err := contact.Unmarshal(marshaledContact) if err != nil { return nil, err } @@ -123,67 +123,41 @@ func GetPubkeyFromContact(marshaled []byte) ([]byte, error) { // Fact Functions // //////////////////////////////////////////////////////////////////////////////// -// Fact is an internal fact type for use in the bindings layer. -// -// JSON example: -// { -// "Fact": "Zezima", -// "Type": 0 -// } -type Fact struct { - Fact string - Type int -} - // SetFactsOnContact replaces the facts on the contact with the passed in facts // pass in empty facts in order to clear the facts. // // Parameters: -// - marshaled - JSON marshalled contact.Contact object -// - facts - JSON marshalled Fact object. -func SetFactsOnContact(marshaled []byte, facts []byte) ([]byte, error) { - cnt, err := contact.Unmarshal(marshaled) +// - marshaledContact - the JSON marshalled bytes of contact.Contact object. +// - factListJSON - the JSON marshalled bytes of [fact.FactList]. +func SetFactsOnContact(marshaledContact []byte, factListJSON []byte) ([]byte, error) { + cnt, err := contact.Unmarshal(marshaledContact) if err != nil { return nil, err } - factsList := make([]Fact, 0) - err = json.Unmarshal(facts, &factsList) + var factsList fact.FactList + err = json.Unmarshal(factListJSON, &factsList) if err != nil { return nil, err } - realFactList := make(fact.FactList, 0, len(factsList)) - for i := range factsList { - realFactList = append(realFactList, fact.Fact{ - Fact: factsList[i].Fact, - T: fact.FactType(factsList[i].Type), - }) - } + cnt.Facts = factsList - cnt.Facts = realFactList return cnt.Marshal(), nil } -// GetFactsFromContact accepts a marshalled contact.Contact object and returns -// its marshalled list of Fact objects. -func GetFactsFromContact(marshaled []byte) ([]byte, error) { - cnt, err := contact.Unmarshal(marshaled) +// GetFactsFromContact returns the fact list in the contact.Contact object. +// +// Parameters: +// - marshaledContact - the JSON marshalled bytes by of contact.Contact object. +// +// Returns: +// - []byte - the JSON marshalled bytes of [fact.FactList]. +func GetFactsFromContact(marshaledContact []byte) ([]byte, error) { + cnt, err := contact.Unmarshal(marshaledContact) if err != nil { return nil, err } - factsList := make([]Fact, len(cnt.Facts)) - for i := range cnt.Facts { - factsList = append(factsList, Fact{ - Fact: cnt.Facts[i].Fact, - Type: int(cnt.Facts[i].T), - }) - } - - factsListMarshaled, err := json.Marshal(&factsList) - if err != nil { - return nil, err - } - return factsListMarshaled, nil + return json.Marshal(&cnt.Facts) } diff --git a/bindings/identity_test.go b/bindings/identity_test.go index 662f1f5c000021def40a17a50d9c9646b8a78779..949d51b2451f574d4fdfb2f634f9995588fa88fa 100644 --- a/bindings/identity_test.go +++ b/bindings/identity_test.go @@ -41,22 +41,6 @@ func TestIdentity_JSON(t *testing.T) { t.Log(string(im)) } -func TestFacts_JSON(t *testing.T) { - fl := []Fact{ - { - Fact: "Zezima", - Type: 0, - }, - { - Fact: "Zezima@osrs.org", - Type: 2, - }, - } - flm, _ := json.Marshal(fl) - t.Log("Marshalled []Fact") - t.Log(string(flm)) -} - func getGroup() *cyclic.Group { return cyclic.NewGroup( large.NewIntFromString("E2EE983D031DC1DB6F1A7A67DF0E9A8E5561DB8E8D4941"+ diff --git a/bindings/ud.go b/bindings/ud.go index 6ce8f8b3af073057e210675ff3203ef5ba364746..8a19f48211d437d4343b9b4c38b0f170deb82630 100644 --- a/bindings/ud.go +++ b/bindings/ud.go @@ -165,8 +165,8 @@ func NewOrLoadUd(e2eID int, follower UdNetworkStatus, // Parameters: // - e2eID - e2e object ID in the tracker // - follower - network follower func wrapped in UdNetworkStatus -// - emailFactJson - nullable JSON marshalled email fact.Fact -// - phoneFactJson - nullable JSON marshalled phone fact.Fact +// - emailFactJson - nullable JSON marshalled email [fact.Fact] +// - phoneFactJson - nullable JSON marshalled phone [fact.Fact] // - cert is the TLS certificate for the UD server this call will connect with. // You may use the UD server run by the xx network team by using E2e.GetUdCertFromNdf. // - contactFile is the data within a marshalled contact.Contact. This represents the @@ -213,7 +213,7 @@ func NewUdManagerFromBackup(e2eID int, follower UdNetworkStatus, emailFactJson, return udTrackerSingleton.make(u), nil } -// GetFacts returns a JSON marshalled list of fact.Fact objects that exist +// GetFacts returns a JSON marshalled list of [fact.Fact] objects that exist // within the Store's registeredFacts map. func (ud *UserDiscovery) GetFacts() []byte { jsonData, err := json.Marshal(ud.api.GetFacts()) @@ -246,7 +246,7 @@ func (ud *UserDiscovery) ConfirmFact(confirmationID, code string) error { // along with the code to finalize the fact. // // Parameters: -// - factJson - a JSON marshalled fact.Fact +// - factJson - a JSON marshalled [fact.Fact] func (ud *UserDiscovery) SendRegisterFact(factJson []byte) (string, error) { var f fact.Fact err := json.Unmarshal(factJson, &f) @@ -262,7 +262,7 @@ func (ud *UserDiscovery) SendRegisterFact(factJson []byte) (string, error) { // be associated with this user. // // Parameters: -// - factJson - a JSON marshalled fact.Fact +// - factJson - a JSON marshalled [fact.Fact] func (ud *UserDiscovery) PermanentDeleteAccount(factJson []byte) error { var f fact.Fact err := json.Unmarshal(factJson, &f) @@ -277,7 +277,7 @@ func (ud *UserDiscovery) PermanentDeleteAccount(factJson []byte) error { // passed in is not UD service does not associate this fact with this user. // // Parameters: -// - factJson - a JSON marshalled fact.Fact +// - factJson - a JSON marshalled [fact.Fact] func (ud *UserDiscovery) RemoveFact(factJson []byte) error { var f fact.Fact err := json.Unmarshal(factJson, &f) @@ -385,7 +385,7 @@ type UdSearchCallback interface { // - e2eID - e2e object ID in the tracker // - udContact - the marshalled bytes of the contact.Contact for the user // discovery server -// - factListJSON - the JSON marshalled bytes of fact.FactList +// - factListJSON - the JSON marshalled bytes of [fact.FactList] // - singleRequestParams - the JSON marshalled bytes of single.RequestParams // // Returns: