Changeset View
Changeset View
Standalone View
Standalone View
web/grpc/identity-service-client-wrapper.js
Show All 12 Lines | import { | ||||
signedDeviceListHistoryValidator, | signedDeviceListHistoryValidator, | ||||
type SignedMessage, | type SignedMessage, | ||||
type IdentityServiceAuthLayer, | type IdentityServiceAuthLayer, | ||||
type IdentityServiceClient, | type IdentityServiceClient, | ||||
type DeviceOlmOutboundKeys, | type DeviceOlmOutboundKeys, | ||||
deviceOlmOutboundKeysValidator, | deviceOlmOutboundKeysValidator, | ||||
type UserDevicesOlmOutboundKeys, | type UserDevicesOlmOutboundKeys, | ||||
type IdentityAuthResult, | type IdentityAuthResult, | ||||
type IdentityDeviceKeyUpload, | type IdentityNewDeviceKeyUpload, | ||||
identityDeviceTypes, | identityDeviceTypes, | ||||
identityAuthResultValidator, | identityAuthResultValidator, | ||||
type UserDevicesOlmInboundKeys, | type UserDevicesOlmInboundKeys, | ||||
type DeviceOlmInboundKeys, | type DeviceOlmInboundKeys, | ||||
deviceOlmInboundKeysValidator, | deviceOlmInboundKeysValidator, | ||||
userDeviceOlmInboundKeysValidator, | userDeviceOlmInboundKeysValidator, | ||||
} from 'lib/types/identity-service-types.js'; | } from 'lib/types/identity-service-types.js'; | ||||
import { getMessageForException } from 'lib/utils/errors.js'; | import { getMessageForException } from 'lib/utils/errors.js'; | ||||
Show All 14 Lines | import { | ||||
SecondaryDeviceKeysUploadRequest, | SecondaryDeviceKeysUploadRequest, | ||||
} from '../protobufs/identity-unauth-structs.cjs'; | } from '../protobufs/identity-unauth-structs.cjs'; | ||||
import * as IdentityUnauthClient from '../protobufs/identity-unauth.cjs'; | import * as IdentityUnauthClient from '../protobufs/identity-unauth.cjs'; | ||||
class IdentityServiceClientWrapper implements IdentityServiceClient { | class IdentityServiceClientWrapper implements IdentityServiceClient { | ||||
overridedOpaqueFilepath: ?string; | overridedOpaqueFilepath: ?string; | ||||
authClient: ?IdentityAuthClient.IdentityClientServicePromiseClient; | authClient: ?IdentityAuthClient.IdentityClientServicePromiseClient; | ||||
unauthClient: IdentityUnauthClient.IdentityClientServicePromiseClient; | unauthClient: IdentityUnauthClient.IdentityClientServicePromiseClient; | ||||
getDeviceKeyUpload: () => Promise<IdentityDeviceKeyUpload>; | getNewDeviceKeyUpload: () => Promise<IdentityNewDeviceKeyUpload>; | ||||
constructor( | constructor( | ||||
platformDetails: PlatformDetails, | platformDetails: PlatformDetails, | ||||
overridedOpaqueFilepath: ?string, | overridedOpaqueFilepath: ?string, | ||||
authLayer: ?IdentityServiceAuthLayer, | authLayer: ?IdentityServiceAuthLayer, | ||||
getDeviceKeyUpload: () => Promise<IdentityDeviceKeyUpload>, | getNewDeviceKeyUpload: () => Promise<IdentityNewDeviceKeyUpload>, | ||||
) { | ) { | ||||
this.overridedOpaqueFilepath = overridedOpaqueFilepath; | this.overridedOpaqueFilepath = overridedOpaqueFilepath; | ||||
if (authLayer) { | if (authLayer) { | ||||
this.authClient = IdentityServiceClientWrapper.createAuthClient( | this.authClient = IdentityServiceClientWrapper.createAuthClient( | ||||
platformDetails, | platformDetails, | ||||
authLayer, | authLayer, | ||||
); | ); | ||||
} | } | ||||
this.unauthClient = | this.unauthClient = | ||||
IdentityServiceClientWrapper.createUnauthClient(platformDetails); | IdentityServiceClientWrapper.createUnauthClient(platformDetails); | ||||
this.getDeviceKeyUpload = getDeviceKeyUpload; | this.getNewDeviceKeyUpload = getNewDeviceKeyUpload; | ||||
} | } | ||||
static determineSocketAddr(): string { | static determineSocketAddr(): string { | ||||
return process.env.IDENTITY_SOCKET_ADDR ?? identityServiceConfig.defaultURL; | return process.env.IDENTITY_SOCKET_ADDR ?? identityServiceConfig.defaultURL; | ||||
} | } | ||||
static createAuthClient( | static createAuthClient( | ||||
platformDetails: PlatformDetails, | platformDetails: PlatformDetails, | ||||
▲ Show 20 Lines • Show All 271 Lines • ▼ Show 20 Lines | ) => Promise<IdentityAuthResult> = async ( | ||||
password: string, | password: string, | ||||
) => { | ) => { | ||||
const client = this.unauthClient; | const client = this.unauthClient; | ||||
if (!client) { | if (!client) { | ||||
throw new Error('Identity service client is not initialized'); | throw new Error('Identity service client is not initialized'); | ||||
} | } | ||||
const [identityDeviceKeyUpload] = await Promise.all([ | const [identityDeviceKeyUpload] = await Promise.all([ | ||||
this.getDeviceKeyUpload(), | this.getNewDeviceKeyUpload(), | ||||
initOpaque(this.overridedOpaqueFilepath), | initOpaque(this.overridedOpaqueFilepath), | ||||
]); | ]); | ||||
const opaqueLogin = new Login(); | const opaqueLogin = new Login(); | ||||
const startRequestBytes = opaqueLogin.start(password); | const startRequestBytes = opaqueLogin.start(password); | ||||
const deviceKeyUpload = authDeviceKeyUpload(identityDeviceKeyUpload); | const deviceKeyUpload = authNewDeviceKeyUpload(identityDeviceKeyUpload); | ||||
const loginStartRequest = new OpaqueLoginStartRequest(); | const loginStartRequest = new OpaqueLoginStartRequest(); | ||||
loginStartRequest.setUsername(username); | loginStartRequest.setUsername(username); | ||||
loginStartRequest.setOpaqueLoginRequest(startRequestBytes); | loginStartRequest.setOpaqueLoginRequest(startRequestBytes); | ||||
loginStartRequest.setDeviceKeyUpload(deviceKeyUpload); | loginStartRequest.setDeviceKeyUpload(deviceKeyUpload); | ||||
let loginStartResponse; | let loginStartResponse; | ||||
try { | try { | ||||
Show All 31 Lines | logInWalletUser: ( | ||||
walletAddress: string, | walletAddress: string, | ||||
siweMessage: string, | siweMessage: string, | ||||
siweSignature: string, | siweSignature: string, | ||||
) => Promise<IdentityAuthResult> = async ( | ) => Promise<IdentityAuthResult> = async ( | ||||
walletAddress: string, | walletAddress: string, | ||||
siweMessage: string, | siweMessage: string, | ||||
siweSignature: string, | siweSignature: string, | ||||
) => { | ) => { | ||||
const identityDeviceKeyUpload = await this.getDeviceKeyUpload(); | const identityDeviceKeyUpload = await this.getNewDeviceKeyUpload(); | ||||
const deviceKeyUpload = authDeviceKeyUpload(identityDeviceKeyUpload); | const deviceKeyUpload = authNewDeviceKeyUpload(identityDeviceKeyUpload); | ||||
const loginRequest = new WalletAuthRequest(); | const loginRequest = new WalletAuthRequest(); | ||||
loginRequest.setSiweMessage(siweMessage); | loginRequest.setSiweMessage(siweMessage); | ||||
loginRequest.setSiweSignature(siweSignature); | loginRequest.setSiweSignature(siweSignature); | ||||
loginRequest.setDeviceKeyUpload(deviceKeyUpload); | loginRequest.setDeviceKeyUpload(deviceKeyUpload); | ||||
let loginResponse; | let loginResponse; | ||||
try { | try { | ||||
Show All 12 Lines | class IdentityServiceClientWrapper implements IdentityServiceClient { | ||||
uploadKeysForRegisteredDeviceAndLogIn: ( | uploadKeysForRegisteredDeviceAndLogIn: ( | ||||
ownerUserID: string, | ownerUserID: string, | ||||
nonceChallengeResponse: SignedMessage, | nonceChallengeResponse: SignedMessage, | ||||
) => Promise<IdentityAuthResult> = async ( | ) => Promise<IdentityAuthResult> = async ( | ||||
ownerUserID, | ownerUserID, | ||||
nonceChallengeResponse, | nonceChallengeResponse, | ||||
) => { | ) => { | ||||
const identityDeviceKeyUpload = await this.getDeviceKeyUpload(); | const identityDeviceKeyUpload = await this.getNewDeviceKeyUpload(); | ||||
const deviceKeyUpload = authDeviceKeyUpload(identityDeviceKeyUpload); | const deviceKeyUpload = authNewDeviceKeyUpload(identityDeviceKeyUpload); | ||||
const challengeResponse = JSON.stringify(nonceChallengeResponse); | const challengeResponse = JSON.stringify(nonceChallengeResponse); | ||||
const request = new SecondaryDeviceKeysUploadRequest(); | const request = new SecondaryDeviceKeysUploadRequest(); | ||||
request.setUserId(ownerUserID); | request.setUserId(ownerUserID); | ||||
request.setChallengeResponse(challengeResponse); | request.setChallengeResponse(challengeResponse); | ||||
request.setDeviceKeyUpload(deviceKeyUpload); | request.setDeviceKeyUpload(deviceKeyUpload); | ||||
let response; | let response; | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | ) => { | ||||
); | ); | ||||
return assertWithValidator( | return assertWithValidator( | ||||
deviceListUpdates, | deviceListUpdates, | ||||
signedDeviceListHistoryValidator, | signedDeviceListHistoryValidator, | ||||
); | ); | ||||
}; | }; | ||||
} | } | ||||
function authDeviceKeyUpload( | function authNewDeviceKeyUpload( | ||||
uploadData: IdentityDeviceKeyUpload, | uploadData: IdentityNewDeviceKeyUpload, | ||||
): DeviceKeyUpload { | ): DeviceKeyUpload { | ||||
const { | const { | ||||
keyPayload, | keyPayload, | ||||
keyPayloadSignature, | keyPayloadSignature, | ||||
contentPrekey, | contentPrekey, | ||||
contentPrekeySignature, | contentPrekeySignature, | ||||
notifPrekey, | notifPrekey, | ||||
notifPrekeySignature, | notifPrekeySignature, | ||||
Show All 31 Lines |