Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
94a1852b
Commit
94a1852b
authored
Oct 17, 2018
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use async function instead of explicit promises
parent
abd9786c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
34 deletions
+32
-34
src/converse-omemo.js
src/converse-omemo.js
+32
-34
No files found.
src/converse-omemo.js
View file @
94a1852b
...
...
@@ -729,46 +729,44 @@
});
},
generateBundle
()
{
async
generateBundle
()
{
/* The first thing that needs to happen if a client wants to
* start using OMEMO is they need to generate an IdentityKey
* and a Device ID. The IdentityKey is a Curve25519 [6]
* public/private Key pair. The Device ID is a randomly
* generated integer between 1 and 2^31 - 1.
*/
const
bundle
=
{};
return
libsignal
.
KeyHelper
.
generateIdentityKeyPair
()
.
then
(
identity_keypair
=>
{
const
identity_key
=
u
.
arrayBufferToBase64
(
identity_keypair
.
pubKey
),
device_id
=
generateDeviceID
();
bundle
[
'
identity_key
'
]
=
identity_key
;
bundle
[
'
device_id
'
]
=
device_id
;
this
.
save
({
'
device_id
'
:
device_id
,
'
identity_keypair
'
:
{
'
privKey
'
:
u
.
arrayBufferToBase64
(
identity_keypair
.
privKey
),
'
pubKey
'
:
identity_key
},
'
identity_key
'
:
identity_key
});
return
libsignal
.
KeyHelper
.
generateSignedPreKey
(
identity_keypair
,
0
);
}).
then
(
signed_prekey
=>
{
_converse
.
omemo_store
.
storeSignedPreKey
(
signed_prekey
);
bundle
[
'
signed_prekey
'
]
=
{
'
id
'
:
signed_prekey
.
keyId
,
'
public_key
'
:
u
.
arrayBufferToBase64
(
signed_prekey
.
keyPair
.
privKey
),
'
signature
'
:
u
.
arrayBufferToBase64
(
signed_prekey
.
signature
)
}
return
Promise
.
all
(
_
.
map
(
_
.
range
(
0
,
_converse
.
NUM_PREKEYS
),
id
=>
libsignal
.
KeyHelper
.
generatePreKey
(
id
)));
}).
then
(
keys
=>
{
_
.
forEach
(
keys
,
k
=>
_converse
.
omemo_store
.
storePreKey
(
k
.
keyId
,
k
.
keyPair
));
const
devicelist
=
_converse
.
devicelists
.
get
(
_converse
.
bare_jid
),
device
=
devicelist
.
devices
.
create
({
'
id
'
:
bundle
.
device_id
,
'
jid
'
:
_converse
.
bare_jid
}),
marshalled_keys
=
_
.
map
(
keys
,
k
=>
({
'
id
'
:
k
.
keyId
,
'
key
'
:
u
.
arrayBufferToBase64
(
k
.
keyPair
.
pubKey
)}));
bundle
[
'
prekeys
'
]
=
marshalled_keys
;
device
.
save
(
'
bundle
'
,
bundle
);
});
const
identity_keypair
=
await
libsignal
.
KeyHelper
.
generateIdentityKeyPair
();
const
bundle
=
{},
identity_key
=
u
.
arrayBufferToBase64
(
identity_keypair
.
pubKey
),
device_id
=
generateDeviceID
();
bundle
[
'
identity_key
'
]
=
identity_key
;
bundle
[
'
device_id
'
]
=
device_id
;
this
.
save
({
'
device_id
'
:
device_id
,
'
identity_keypair
'
:
{
'
privKey
'
:
u
.
arrayBufferToBase64
(
identity_keypair
.
privKey
),
'
pubKey
'
:
identity_key
},
'
identity_key
'
:
identity_key
});
const
signed_prekey
=
await
libsignal
.
KeyHelper
.
generateSignedPreKey
(
identity_keypair
,
0
);
_converse
.
omemo_store
.
storeSignedPreKey
(
signed_prekey
);
bundle
[
'
signed_prekey
'
]
=
{
'
id
'
:
signed_prekey
.
keyId
,
'
public_key
'
:
u
.
arrayBufferToBase64
(
signed_prekey
.
keyPair
.
privKey
),
'
signature
'
:
u
.
arrayBufferToBase64
(
signed_prekey
.
signature
)
}
const
keys
=
await
Promise
.
all
(
_
.
map
(
_
.
range
(
0
,
_converse
.
NUM_PREKEYS
),
id
=>
libsignal
.
KeyHelper
.
generatePreKey
(
id
)));
_
.
forEach
(
keys
,
k
=>
_converse
.
omemo_store
.
storePreKey
(
k
.
keyId
,
k
.
keyPair
));
const
devicelist
=
_converse
.
devicelists
.
get
(
_converse
.
bare_jid
),
device
=
devicelist
.
devices
.
create
({
'
id
'
:
bundle
.
device_id
,
'
jid
'
:
_converse
.
bare_jid
}),
marshalled_keys
=
_
.
map
(
keys
,
k
=>
({
'
id
'
:
k
.
keyId
,
'
key
'
:
u
.
arrayBufferToBase64
(
k
.
keyPair
.
pubKey
)}));
bundle
[
'
prekeys
'
]
=
marshalled_keys
;
device
.
save
(
'
bundle
'
,
bundle
);
},
fetchSession
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment