Refactor provisioning flow
This commit is contained in:
parent
a80da0ad24
commit
b2c3b1f43e
4 changed files with 373 additions and 225 deletions
|
@ -15,7 +15,7 @@ import { SignalService as Proto } from '../protobuf';
|
|||
import { strictAssert } from '../util/assert';
|
||||
import { dropNull } from '../util/dropNull';
|
||||
|
||||
type ProvisionDecryptResult = {
|
||||
export type ProvisionDecryptResult = Readonly<{
|
||||
aciKeyPair: KeyPairType;
|
||||
pniKeyPair?: KeyPairType;
|
||||
number?: string;
|
||||
|
@ -26,14 +26,12 @@ type ProvisionDecryptResult = {
|
|||
readReceipts?: boolean;
|
||||
profileKey?: Uint8Array;
|
||||
masterKey?: Uint8Array;
|
||||
};
|
||||
}>;
|
||||
|
||||
class ProvisioningCipherInner {
|
||||
keyPair?: KeyPairType;
|
||||
|
||||
async decrypt(
|
||||
provisionEnvelope: Proto.ProvisionEnvelope
|
||||
): Promise<ProvisionDecryptResult> {
|
||||
decrypt(provisionEnvelope: Proto.ProvisionEnvelope): ProvisionDecryptResult {
|
||||
strictAssert(
|
||||
provisionEnvelope.publicKey,
|
||||
'Missing publicKey in ProvisionEnvelope'
|
||||
|
@ -77,7 +75,7 @@ class ProvisioningCipherInner {
|
|||
strictAssert(aci, 'Missing aci in provisioning message');
|
||||
strictAssert(pni, 'Missing pni in provisioning message');
|
||||
|
||||
const ret: ProvisionDecryptResult = {
|
||||
return {
|
||||
aciKeyPair,
|
||||
pniKeyPair,
|
||||
number: dropNull(provisionMessage.number),
|
||||
|
@ -86,17 +84,16 @@ class ProvisioningCipherInner {
|
|||
provisioningCode: dropNull(provisionMessage.provisioningCode),
|
||||
userAgent: dropNull(provisionMessage.userAgent),
|
||||
readReceipts: provisionMessage.readReceipts ?? false,
|
||||
profileKey: Bytes.isNotEmpty(provisionMessage.profileKey)
|
||||
? provisionMessage.profileKey
|
||||
: undefined,
|
||||
masterKey: Bytes.isNotEmpty(provisionMessage.masterKey)
|
||||
? provisionMessage.masterKey
|
||||
: undefined,
|
||||
};
|
||||
if (Bytes.isNotEmpty(provisionMessage.profileKey)) {
|
||||
ret.profileKey = provisionMessage.profileKey;
|
||||
}
|
||||
if (Bytes.isNotEmpty(provisionMessage.masterKey)) {
|
||||
ret.masterKey = provisionMessage.masterKey;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
async getPublicKey(): Promise<Uint8Array> {
|
||||
getPublicKey(): Uint8Array {
|
||||
if (!this.keyPair) {
|
||||
this.keyPair = generateKeyPair();
|
||||
}
|
||||
|
@ -119,7 +116,7 @@ export default class ProvisioningCipher {
|
|||
|
||||
decrypt: (
|
||||
provisionEnvelope: Proto.ProvisionEnvelope
|
||||
) => Promise<ProvisionDecryptResult>;
|
||||
) => ProvisionDecryptResult;
|
||||
|
||||
getPublicKey: () => Promise<Uint8Array>;
|
||||
getPublicKey: () => Uint8Array;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue