Newer
Older
////////////////////////////////////////////////////////////////////////////////
// //
// Use of this source code is governed by a license that can be found in the //
////////////////////////////////////////////////////////////////////////////////
//go:build js && wasm

Richard T. Carback III
committed
"gitlab.com/elixxir/client/v4/bindings"
"gitlab.com/elixxir/client/v4/xxdk"
"gitlab.com/elixxir/wasm-utils/exception"
"gitlab.com/elixxir/wasm-utils/utils"
"syscall/js"
)
////////////////////////////////////////////////////////////////////////////////
// ReceptionIdentity //
////////////////////////////////////////////////////////////////////////////////
// StoreReceptionIdentity stores the given identity in [Cmix] storage with the
// given key. This is the ideal way to securely store identities, as the caller
// of this function is only required to store the given key separately rather
// than the keying material.
//
// Parameters:
// - args[0] - Storage key (string).
// - args[1] - JSON of the [xxdk.ReceptionIdentity] object (Uint8Array).
// - args[2] - ID of [Cmix] object in tracker (int).
// - Throws an error if the identity cannot be stored in storage.
func StoreReceptionIdentity(_ js.Value, args []js.Value) any {
err := bindings.StoreReceptionIdentity(
args[0].String(), identity, args[2].Int())
if err != nil {
// LoadReceptionIdentity loads the given identity in [Cmix] storage with the
// given key.
// - args[0] - Storage key (string).
// - args[1] - ID of [Cmix] object in tracker (int).
// - JSON of the stored [xxdk.ReceptionIdentity] object (Uint8Array).
// - Throws an error if the identity cannot be retrieved from storage.
func LoadReceptionIdentity(_ js.Value, args []js.Value) any {
ri, err := bindings.LoadReceptionIdentity(args[0].String(), args[1].Int())
if err != nil {
}
// MakeReceptionIdentity generates a new cryptographic identity for receiving
// messages.
//
// - Resolves to the JSON of the [xxdk.ReceptionIdentity] object (Uint8Array).
// - Rejected with an error if creating a new identity fails.
func (c *Cmix) MakeReceptionIdentity(js.Value, []js.Value) any {
promiseFn := func(resolve, reject func(args ...any) js.Value) {
ri, err := c.api.MakeReceptionIdentity()
if err != nil {
}
// MakeLegacyReceptionIdentity generates the legacy identity for receiving
// messages.
//
// - Resolves to the JSON of the [xxdk.ReceptionIdentity] object (Uint8Array).
// - Rejected with an error if creating a new legacy identity fails.
func (c *Cmix) MakeLegacyReceptionIdentity(js.Value, []js.Value) any {
promiseFn := func(resolve, reject func(args ...any) js.Value) {
ri, err := c.api.MakeLegacyReceptionIdentity()
if err != nil {
} else {
resolve(utils.CopyBytesToJS(ri))
}
}
// GetReceptionRegistrationValidationSignature returns the signature provided by
// the xx network.
//
// Returns:
// - Reception registration validation signature (Uint8Array).
func (c *Cmix) GetReceptionRegistrationValidationSignature(
return utils.CopyBytesToJS(
c.api.GetReceptionRegistrationValidationSignature())
}
////////////////////////////////////////////////////////////////////////////////
// Contact Functions //
////////////////////////////////////////////////////////////////////////////////

Jono Wenger
committed
// GetContactFromReceptionIdentity returns the [contact.Contact] object from the
// [xxdk.ReceptionIdentity].
//
// Parameters:
// - args[0] - JSON of [xxdk.ReceptionIdentity] (Uint8Array).

Jono Wenger
committed
//
// Returns:
// - Marshalled bytes of [contact.Contact] (string).
// - Throws an error if unmarshalling the identity fails.
func GetContactFromReceptionIdentity(_ js.Value, args []js.Value) any {

Jono Wenger
committed
// Note that this function does not appear in normal bindings

Jono Wenger
committed
identity, err := xxdk.UnmarshalReceptionIdentity(identityJSON)
if err != nil {

Jono Wenger
committed
return nil
}
return utils.CopyBytesToJS(identity.GetContact().Marshal())

Jono Wenger
committed
}
// GetIDFromContact returns the ID in the [contact.Contact] object.
//
// Parameters:
// - args[0] - Marshalled bytes of [contact.Contact] (Uint8Array).
// - Marshalled bytes of [id.ID] (Uint8Array).
// - Throws an error if loading the ID from the contact file fails.
func GetIDFromContact(_ js.Value, args []js.Value) any {
cID, err := bindings.GetIDFromContact(utils.CopyBytesToGo(args[0]))
}
// GetPubkeyFromContact returns the DH public key in the [contact.Contact]
// object.
//
// Parameters:
// - args[0] - Marshalled [contact.Contact] (string).
// - Bytes of the [cyclic.Int] object (Uint8Array).
// - Throws an error if loading the public key from the contact file fails.
func GetPubkeyFromContact(_ js.Value, args []js.Value) any {
key, err := bindings.GetPubkeyFromContact([]byte(args[0].String()))
if err != nil {
}
////////////////////////////////////////////////////////////////////////////////
// Fact Functions //
////////////////////////////////////////////////////////////////////////////////
// SetFactsOnContact replaces the facts on the contact with the passed in facts
// pass in empty facts in order to clear the facts.
//
// Parameters:
// - args[0] - Marshalled bytes of [contact.Contact] (Uint8Array).
// - args[1] - JSON of [fact.FactList] (Uint8Array).
// - Marshalled bytes of the modified [contact.Contact] (string).
// - Throws an error if loading or modifying the contact fails.
func SetFactsOnContact(_ js.Value, args []js.Value) any {
marshaledContact := utils.CopyBytesToGo(args[0])
factListJSON := utils.CopyBytesToGo(args[1])
c, err := bindings.SetFactsOnContact(marshaledContact, factListJSON)
if err != nil {
return nil
}
return c
}
// GetFactsFromContact returns the fact list in the [contact.Contact] object.
//
// Parameters:
// - args[0] - Marshalled bytes of [contact.Contact] (Uint8Array).
func GetFactsFromContact(_ js.Value, args []js.Value) any {
fl, err := bindings.GetFactsFromContact(utils.CopyBytesToGo(args[0]))