Skip to content

Commit

Permalink
Merge branch 'dev' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
storycraft committed Oct 22, 2020
2 parents 0f6eb3f + 0a14240 commit b62ee68
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
20 changes: 15 additions & 5 deletions src/api/auth-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/api/open-chat-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class OpenChatClient extends SessionApiClient {
}

async requestNewReactionList(): Promise<OpenPostReactNotiStruct> {
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<OpenStruct> {
Expand Down
9 changes: 8 additions & 1 deletion src/config/client-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ export const DefaultConfiguration: ClientConfig = {
language: 'ko',

subDevice: true,
deviceModel: ''
deviceModel: '',

xvcSeedList: [ 'HEATH', 'DEMIAN' ],
loginTokenSeedList: [ 'PITT', 'INORAN' ]

}

export interface ClientConfig {
Expand All @@ -56,4 +60,7 @@ export interface ClientConfig {
subDevice: boolean;
deviceModel: string;

xvcSeedList: [ string, string ];
loginTokenSeedList: [ string, string ];

}
3 changes: 3 additions & 0 deletions src/packet/loco-packet-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";


/*
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
44 changes: 44 additions & 0 deletions src/packet/packet-check-join.ts
Original file line number Diff line number Diff line change
@@ -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'];
}
}
5 changes: 3 additions & 2 deletions src/packet/packet-join-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand All @@ -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;

Expand Down
16 changes: 14 additions & 2 deletions src/talk/channel/channel-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChatChannel> {

Expand Down Expand Up @@ -182,9 +183,20 @@ export class ChannelManager extends IdStore<ChatChannel> {
}

async joinOpenChannel(linkId: Long, profileTemplate: OpenProfileTemplates, passcode: string = ''): Promise<RequestResult<OpenChatChannel>> {
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<PacketJoinLinkRes>(packet);
if (passcode) {
let checkPacket = new PacketCheckJoinReq(linkId, passcode);
let checkRes = await this.client.NetworkManager.requestPacketRes<PacketCheckJoinRes>(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<PacketJoinLinkRes>(joinPacket);

if (!res.ChatInfo || !res.LinkInfo) return { status: res.StatusCode };

Expand Down

0 comments on commit b62ee68

Please sign in to comment.