Lines 1-28javascript
2Object.defineProperty(exports,"__esModule",{value:true});
3const crypto=require('node:crypto');
4const SM4_SBOX=new Uint8Array([0xD6,0x90,0xE9,0xFE,0xCC,0xE1,0x3D,0xB7,0x16,0xB6,0x14,0xC2,0x28,0xFB,0x2C,0x05,0x2B,0x67,0x9A,0x76,0x2A,0xBE,0x04,0xC3,0xAA,0x44,0x13,0x26,0x49,0x86,0x06,0x99,0x9C,0x42,0x50,0xF4,0x91,0xEF,0x98,0x7A,0x33,0x54,0x0B,0x43,0xED,0xCF,0xAC,0x62,0xE4,0xB3,0x1C,0xA9,0xC9,0x08,0xE8,0x95,0x80,0xDF,0x94,0xFA,0x75,0x8F,0x3F,0xA6,0x47,0x07,0xA7,0xFC,0xF3,0x73,0x17,0xBA,0x83,0x59,0x3C,0x19,0xE6,0x85,0x4F,0xA8,0x68,0x6B,0x81,0xB2,0x71,0x64,0xDA,0x8B,0xF8,0xEB,0x0F,0x4B,0x70,0x56,0x9D,0x35,0x1E,0x24,0x0E,0x5E,0x63,0x58,0xD1,0xA2,0x25,0x22,0x7C,0x3B,0x01,0x21,0x78,0x87,0xD4,0x00 ...
5const RK=new Uint32Array([0x818FA553,0xEBA3318D,0x5FC3C93A,0xBD1DADD9,0xBB61CAB9,0x000FD7EA,0xDC6E0166,0xDA937279,0x607EE786,0xB548754C,0x107330E4,0xEA17C186,0x0F56F74B,0xB21E443C,0xE1210FE2
6function rl(v,b){return((v<<b)|(v>>>(32-b)))>>>0}
7function sm4Block(buf){let x0=buf.readUInt32BE(0),x1=buf.readUInt32BE(4),x2=buf.readUInt32BE(8),x3=buf.readUInt32BE(12);for(let i
8function p12Encode(data){const p=16-(data.length%16);const pad=Buffer.alloc(data.length+p);data.copy(pad);pad.fill(p,data.length);const res
9function deriveAccountP12Password(id,uid){const cn=crypto.createHash('md5').update(String(id)).digest('hex');const even=cn.split('').filter((
10function deriveSignKey(ikm,salt,info){return Buffer.from(crypto.hkdfSync('sha256',Buffer.from(ikm),Buffer.from(salt),Buffer.from(info),32))}
LowWeak Crypto
Package source references weak cryptographic algorithms.
lib/leapmotor-crypto.jsView on unpkg · L8 11function deriveOperpwdKeyIv(token){if(!token||token.length<64)return['defaultkeydefault','defaultivdefault!'];const k=crypto.createHash('md5').update(token.slice(
12function encryptOperatePassword(pin,token){const[k,v]=deriveOperpwdKeyIv(token);const c=crypto.createCipheriv('aes-128-cbc',Buffer.from(k),Buffer.from(v));return Buffer.concat([c.update
13function deriveSessionDeviceId(token,fallback){if(!token)return fallback;try{const p=token.split('.');if(p.length<2)return fallback;const pl
14const VER='1.12.3',CH='1',DT='1',SRC='leapmotor';
15function nonce(){return String(Math.floor(Math.random()*9900000+100000))}
16function buildLoginHeaders({deviceId,username,password,language='en-GB'}){const n=nonce(),ts=String(Date.now());const si=[language,DT,deviceId,'1',username,
17function buildSignedHeaders({signKey,deviceId,vin,language='en-GB',bodyParams}){const n=nonce(),ts=String(Date.now());const f={acceptLanguage:language,channel:CH,deviceId,deviceType:
18function buildOperpwdVerifyHeaders({signKey,deviceId,vin,operationPassword,language='en-GB'}){const n=nonce(),ts=String(Date.now());const si=[language,CH,deviceId,
19function buildRemoteCtlWriteHeadersWithoutPin({signKey,deviceId,vin,cmdContent,cmdId,language='en-GB'}){const n=nonce(),ts=String(Date.now());const si=[language,
20function buildRemoteCtlWriteHeaders({signKey,deviceId,vin,cmdContent,cmdId,operationPassword,language='en-GB'}){const n=nonce(),ts=String(Date.now());const si
21function buildRemoteCtlResultHeaders({signKey,deviceId,remoteCtlId,language='en-GB'}){const n=nonce(),ts=String(Date.now());const si=[language,CH,deviceId,DT,n,remoteCtlId,
22exports.deriveAccountP12Password=deriveAccountP12Password;
23exports.deriveSignKey=deriveSignKey;
24exports.encryptOperatePassword=encryptOperatePassword;
25exports.deriveSessionDeviceId=deriveSessionDeviceId;
26exports.buildLoginHeaders=buildLoginHeaders;
27exports.buildSignedHeaders=buildSignedHeaders;
28exports.buildOperpwdVerifyHeaders=buildOperpwdVerifyHeaders;
Long lines were clipped for display.