Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
////////////////////////////////////////////////////////////////////////////////
//go:build js && wasm
package bindings
import (
"gitlab.com/elixxir/client/bindings"
"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)
//
// Returns:
// - throws a TypeError if the identity cannot be stored in storage
func StoreReceptionIdentity(_ js.Value, args []js.Value) interface{} {
identity := CopyBytesToGo(args[1])
err := bindings.StoreReceptionIdentity(
args[0].String(), identity, args[2].Int())
if err != nil {
Throw(TypeError, err.Error())
return nil
}
return nil
}
// LoadReceptionIdentity loads the given identity in Cmix storage with the given
// key.
//
// Parameters:
// - args[0] - storage key (string)
// - args[1] - ID of Cmix object in tracker (int)
//
// Returns:
// - JSON of the stored [xxdk.ReceptionIdentity] object (Uint8Array)
// - throws a TypeError if the identity cannot be retrieved from storage
func LoadReceptionIdentity(_ js.Value, args []js.Value) interface{} {
ri, err := bindings.LoadReceptionIdentity(args[0].String(), args[1].Int())
if err != nil {
Throw(TypeError, err.Error())
return nil
}
return CopyBytesToJS(ri)
}
// MakeReceptionIdentity generates a new cryptographic identity for receiving
// messages.
//
// Returns:
// - JSON of the [xxdk.ReceptionIdentity] object (Uint8Array)
// - throws a TypeError if creating a new identity fails
func (c *Cmix) MakeReceptionIdentity(js.Value, []js.Value) interface{} {
ri, err := c.api.MakeReceptionIdentity()
if err != nil {
Throw(TypeError, err.Error())
return nil
}
return CopyBytesToJS(ri)
}
// MakeLegacyReceptionIdentity generates the legacy identity for receiving
// messages.
//
// Returns:
// - JSON of the [xxdk.ReceptionIdentity] object (Uint8Array)
// - throws a TypeError if creating a new legacy identity fails
func (c *Cmix) MakeLegacyReceptionIdentity(js.Value, []js.Value) interface{} {
ri, err := c.api.MakeLegacyReceptionIdentity()
if err != nil {
Throw(TypeError, err.Error())
return nil
}
return CopyBytesToJS(ri)
}
// GetReceptionRegistrationValidationSignature returns the signature provided by
// the xx network.
//
// Returns:
// - signature (Uint8Array)
func (c *Cmix) GetReceptionRegistrationValidationSignature(
js.Value, []js.Value) interface{} {
return CopyBytesToJS(c.api.GetReceptionRegistrationValidationSignature())
}
////////////////////////////////////////////////////////////////////////////////
// Contact Functions //
////////////////////////////////////////////////////////////////////////////////
// GetIDFromContact returns the ID in the [contact.Contact] object.
//
// Parameters:
// - args[0] - marshalled bytes of [contact.Contact] (string)
//
// Returns:
// - marshalled [id.ID] object (Uint8Array)
// - throws a TypeError if loading the ID from the contact file fails
func GetIDFromContact(_ js.Value, args []js.Value) interface{} {
cID, err := bindings.GetIDFromContact([]byte(args[0].String()))
if err != nil {
Throw(TypeError, err.Error())
return nil
}
return CopyBytesToJS(cID)
}
// GetPubkeyFromContact returns the DH public key in the [contact.Contact]
// object.
//
// Parameters:
// - args[0] - JSON of [contact.Contact] (string)
//
// Returns:
// - bytes of the [cyclic.Int] object (Uint8Array)
// - throws a TypeError if loading the public key from the contact file fails
func GetPubkeyFromContact(_ js.Value, args []js.Value) interface{} {
key, err := bindings.GetPubkeyFromContact([]byte(args[0].String()))
if err != nil {
Throw(TypeError, err.Error())
return nil
}
return CopyBytesToJS(key)
}
////////////////////////////////////////////////////////////////////////////////
// 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] - JSON of [contact.Contact] (Uint8Array)
// - args[1] - JSON of [fact.FactList] (Uint8Array)
//
// Returns:
// - marshalled bytes of the modified [contact.Contact] (string)
// - throws a TypeError if loading or modifying the contact fails
func SetFactsOnContact(_ js.Value, args []js.Value) interface{} {
marshaledContact := CopyBytesToGo(args[0])
factListJSON := CopyBytesToGo(args[1])
c, err := bindings.SetFactsOnContact(marshaledContact, factListJSON)
if err != nil {
Throw(TypeError, err.Error())
return nil
}
return c
}
// GetFactsFromContact returns the fact list in the [contact.Contact] object.
//
// Parameters:
// - args[0] - JSON of [contact.Contact] (Uint8Array)
//
// Returns:
// - JSON of [fact.FactList] (Uint8Array)
// - throws a TypeError if loading the contact fails
func GetFactsFromContact(_ js.Value, args []js.Value) interface{} {
fl, err := bindings.GetFactsFromContact(CopyBytesToGo(args[0]))
if err != nil {
Throw(TypeError, err.Error())
return nil
}
return CopyBytesToJS(fl)
}