diff --git a/package.json b/package.json index d2370ff6..af6877a3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-kakao", - "version": "3.1.1", + "version": "3.1.2", "description": "Loco protocol compatible library", "main": "dist/index.js", "scripts": { diff --git a/src/api/auth-client.ts b/src/api/auth-client.ts index 16976722..638fb94f 100644 --- a/src/api/auth-client.ts +++ b/src/api/auth-client.ts @@ -72,7 +72,7 @@ export class AuthClient extends WebApiClient implements AccessDataProvider { } get Host() { - return 'ac-sb-talk.kakao.com'; + return 'katalk.kakao.com'; } get Agent() { @@ -220,14 +220,24 @@ export class AuthClient extends WebApiClient implements AccessDataProvider { } calculateFullXVCKey(userAgent: string, email: string): string { - let res = `HEATH|${userAgent}|DEMIAN|${email}|${this.deviceUUID}`; + let config = this.ConfigProvider.Configuration; - let hash = crypto.createHash('sha512'); - - hash.update(res); + let source = `${config.xvcSeedList[0]}|${userAgent}|${config.xvcSeedList[1]}|${email}|${this.deviceUUID}`; + let hash = crypto.createHash('sha512'); + hash.update(source); return hash.digest('hex'); } + + generateAutoLoginToken(): string { + let accessData = this.getLatestAccessData(); + let config = this.ConfigProvider.Configuration; + let source = `${config.loginTokenSeedList[0]}|${accessData.autoLoginEmail}|${accessData.refreshToken}|${this.deviceUUID}|${config.loginTokenSeedList[1]}`; + + let hash = crypto.createHash('sha512'); + hash.update(source); + return hash.digest('hex'); + } logout() { this.currentLogin = null; diff --git a/src/api/open-chat-client.ts b/src/api/open-chat-client.ts index 745f8fba..471dc4c1 100644 --- a/src/api/open-chat-client.ts +++ b/src/api/open-chat-client.ts @@ -47,7 +47,7 @@ export class OpenChatClient extends SessionApiClient { } async requestNewReactionList(): Promise { - return this.requestMapped('GET', OpenChatClient.getProfileApiPath('reacts/newMark'), OpenPostReactNotiStruct.MAPPER); + return this.requestMapped('GET', OpenChatClient.getProfileApiPath('reacts/newMark'), OpenPostReactNotiStruct.MAPPER); } async setRecommend(linkId: Long): Promise { diff --git a/src/config/client-config.ts b/src/config/client-config.ts index 208f9f42..318043c3 100644 --- a/src/config/client-config.ts +++ b/src/config/client-config.ts @@ -29,7 +29,11 @@ export const DefaultConfiguration: ClientConfig = { language: 'ko', subDevice: true, - deviceModel: '' + deviceModel: '', + + xvcSeedList: [ 'HEATH', 'DEMIAN' ], + loginTokenSeedList: [ 'PITT', 'INORAN' ] + } export interface ClientConfig { @@ -56,4 +60,7 @@ export interface ClientConfig { subDevice: boolean; deviceModel: string; + xvcSeedList: [ string, string ]; + loginTokenSeedList: [ string, string ]; + } \ No newline at end of file diff --git a/src/packet/loco-packet-list.ts b/src/packet/loco-packet-list.ts index 10754292..a0b81a5c 100644 --- a/src/packet/loco-packet-list.ts +++ b/src/packet/loco-packet-list.ts @@ -68,6 +68,7 @@ import { PacketKickLeaveRes, PacketKickLeaveReq } from "./packet-kick-leave"; import { PacketMultiPostReq, PacketMultiPostRes } from "./media/packet-multi-post"; import { PacketMultiShipReq, PacketMultiShipRes } from "./packet-multi-ship"; import { PacketForwardReq, PacketForwardRes } from "./packet-forward"; +import { PacketCheckJoinReq, PacketCheckJoinRes } from "./packet-check-join"; /* @@ -145,6 +146,7 @@ export namespace LocoPacketList { requestPacketMap.set('JOININFO', PacketJoinInfoReq); requestPacketMap.set('SETMEMTYPE', PacketSetMemTypeReq); requestPacketMap.set('JOINLINK', PacketJoinLinkReq); + requestPacketMap.set('CHECKJOIN', PacketCheckJoinReq); requestPacketMap.set('UPLINKPROF', PacketUpdateLinkProfileReq); requestPacketMap.set('SYNCMSG', PacketSyncMessageReq); @@ -245,6 +247,7 @@ export namespace LocoPacketList { responsePacketMap.set('SETMEMTYPE', PacketSetMemTypeRes); responsePacketMap.set('LINKKICKED', PacketLinkKickedRes); responsePacketMap.set('JOINLINK', PacketJoinLinkRes); + responsePacketMap.set('CHECKJOIN', PacketCheckJoinRes); responsePacketMap.set('UPLINKPROF', PacketUpdateLinkProfileRes); responsePacketMap.set('SYNCLINKPF', PacketSyncProfileRes); diff --git a/src/packet/packet-check-join.ts b/src/packet/packet-check-join.ts new file mode 100644 index 00000000..217e67c0 --- /dev/null +++ b/src/packet/packet-check-join.ts @@ -0,0 +1,44 @@ +import { Long } from "bson"; +/* + * Created on Thu Oct 22 2020 + * + * Copyright (c) storycraft. Licensed under the MIT Licence. + */ + +import { LocoBsonRequestPacket, LocoBsonResponsePacket } from "./loco-bson-packet"; + +export class PacketCheckJoinReq extends LocoBsonRequestPacket { + + constructor( + public LinkId: Long = Long.ZERO, + public Passcode: string = '' + ) { + super(); + } + + get PacketName() { + return 'CHECKJOIN'; + } + + toBodyJson() { + return { 'li': this.LinkId, 'pc': this.Passcode }; + } +} + +export class PacketCheckJoinRes extends LocoBsonResponsePacket { + + constructor( + status: number, + public Token: string = '' + ) { + super(status); + } + + get PacketName() { + return 'CHECKJOIN'; + } + + readBodyJson(rawBody: any) { + this.Token = rawBody['tk']; + } +} \ No newline at end of file diff --git a/src/packet/packet-join-link.ts b/src/packet/packet-join-link.ts index 22fb437a..fb3d0d8c 100644 --- a/src/packet/packet-join-link.ts +++ b/src/packet/packet-join-link.ts @@ -16,7 +16,7 @@ export class PacketJoinLinkReq extends LocoBsonRequestPacket { constructor( public LinkId: Long = Long.ZERO, public Referer: string = '', - public ChannelKey: string = '', + public JoinToken: string = '', public ProfileType: OpenProfileType = OpenProfileType.MAIN, @@ -36,10 +36,11 @@ export class PacketJoinLinkReq extends LocoBsonRequestPacket { let obj: any = { 'li': this.LinkId, 'ref': this.Referer, - 'tk': this.ChannelKey, 'ptp': this.ProfileType }; + if (this.JoinToken) obj['tk'] = this.JoinToken; + if (this.ProfileType === OpenProfileType.KAKAO_ANON) { if (this.Nickname !== '') obj['nn'] = this.Nickname; diff --git a/src/talk/channel/channel-manager.ts b/src/talk/channel/channel-manager.ts index b0b90eec..b5e137ca 100644 --- a/src/talk/channel/channel-manager.ts +++ b/src/talk/channel/channel-manager.ts @@ -37,6 +37,7 @@ import { OpenProfileTemplates } from "../open/open-link-profile-template"; import { PacketAddMemberReq, PacketAddMemberRes } from "../../packet/packet-add-member"; import { PacketKickLeaveReq, PacketKickLeaveRes } from "../../packet/packet-kick-leave"; import { JsonUtil } from "../../util/json-util"; +import { PacketCheckJoinReq, PacketCheckJoinRes } from "../../packet/packet-check-join"; export class ChannelManager extends IdStore { @@ -182,9 +183,20 @@ export class ChannelManager extends IdStore { } async joinOpenChannel(linkId: Long, profileTemplate: OpenProfileTemplates, passcode: string = ''): Promise> { - let packet = new PacketJoinLinkReq(linkId, 'EW:', passcode, profileTemplate.type, profileTemplate.anonNickname, profileTemplate.anonProfilePath, profileTemplate.profileLinkId); + let joinToken: string = ''; - let res = await this.client.NetworkManager.requestPacketRes(packet); + if (passcode) { + let checkPacket = new PacketCheckJoinReq(linkId, passcode); + let checkRes = await this.client.NetworkManager.requestPacketRes(checkPacket); + + if (checkRes.StatusCode !== StatusCode.SUCCESS) return { status: checkRes.StatusCode }; + + joinToken = checkRes.Token; + } + + let joinPacket = new PacketJoinLinkReq(linkId, 'EW:', joinToken, profileTemplate.type, profileTemplate.anonNickname, profileTemplate.anonProfilePath, profileTemplate.profileLinkId); + + let res = await this.client.NetworkManager.requestPacketRes(joinPacket); if (!res.ChatInfo || !res.LinkInfo) return { status: res.StatusCode };