mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
update libsignal + no dependency on proto files + no native deps
This commit is contained in:
1697
WASignalGroup/GroupProtocol.js
Normal file
1697
WASignalGroup/GroupProtocol.js
Normal file
File diff suppressed because it is too large
Load Diff
1
WASignalGroup/generate-proto.sh
Normal file
1
WASignalGroup/generate-proto.sh
Normal file
@@ -0,0 +1 @@
|
||||
yarn pbjs -t static-module -w commonjs -o ./WASignalGroup/GroupProtocol.js ./WASignalGroup/group.proto
|
||||
@@ -13,22 +13,23 @@ message SenderKeyMessage {
|
||||
optional bytes signingKey = 4;
|
||||
}
|
||||
|
||||
message SenderChainKey {
|
||||
optional uint32 iteration = 1;
|
||||
optional bytes seed = 2;
|
||||
}
|
||||
|
||||
message SenderMessageKey {
|
||||
optional uint32 iteration = 1;
|
||||
optional bytes seed = 2;
|
||||
}
|
||||
|
||||
message SenderSigningKey {
|
||||
optional bytes public = 1;
|
||||
optional bytes private = 2;
|
||||
}
|
||||
|
||||
message SenderKeyStateStructure {
|
||||
message SenderChainKey {
|
||||
optional uint32 iteration = 1;
|
||||
optional bytes seed = 2;
|
||||
}
|
||||
|
||||
message SenderMessageKey {
|
||||
optional uint32 iteration = 1;
|
||||
optional bytes seed = 2;
|
||||
}
|
||||
|
||||
message SenderSigningKey {
|
||||
optional bytes public = 1;
|
||||
optional bytes private = 2;
|
||||
}
|
||||
|
||||
|
||||
optional uint32 senderKeyId = 1;
|
||||
optional SenderChainKey senderChainKey = 2;
|
||||
|
||||
@@ -1,13 +1,3 @@
|
||||
const path = require('path');
|
||||
const protobuf = require('protobufjs');
|
||||
const { groupproto } = require('./GroupProtocol')
|
||||
|
||||
const protodir = path.resolve(__dirname);
|
||||
const group = protobuf.loadSync(path.join(protodir, 'group.proto')).lookup('groupproto');
|
||||
|
||||
module.exports = {
|
||||
SenderKeyDistributionMessage: group.lookup('SenderKeyDistributionMessage'),
|
||||
SenderKeyMessage: group.lookup('SenderKeyMessage'),
|
||||
SenderKeyStateStructure: group.lookup('SenderKeyStateStructure'),
|
||||
SenderChainKey: group.lookup('SenderChainKey'),
|
||||
SenderSigningKey: group.lookup('SenderSigningKey'),
|
||||
};
|
||||
module.exports = groupproto
|
||||
@@ -17,7 +17,7 @@
|
||||
"multi-device"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "mocha --timeout 240000 -r ts-node/register src/Tests/Tests.*.ts",
|
||||
"test": "jest",
|
||||
"prepare": "tsc",
|
||||
"lint": "eslint '*/*.ts' --quiet --fix",
|
||||
"build:all": "tsc && typedoc",
|
||||
@@ -34,9 +34,10 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@hapi/boom": "^9.1.3",
|
||||
"curve25519-js": "^0.0.4",
|
||||
"got": "^11.8.1",
|
||||
"jimp": "^0.16.1",
|
||||
"libsignal": "^2.0.1",
|
||||
"libsignal": "git+https://github.com/adiwajshing/libsignal-node",
|
||||
"music-metadata": "^7.4.1",
|
||||
"pino": "^6.7.0",
|
||||
"protobufjs": "^6.10.1",
|
||||
@@ -48,8 +49,8 @@
|
||||
"files": [
|
||||
"lib/*",
|
||||
"WAProto/*",
|
||||
"WASignalGroup/*",
|
||||
"WABinary/*"
|
||||
"WASignalGroup/*.js",
|
||||
"WABinary/*.js"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@types/got": "^9.6.11",
|
||||
|
||||
@@ -1,32 +1,24 @@
|
||||
import CurveCrypto from 'libsignal/src/curve25519_wrapper'
|
||||
import * as curveJs from 'curve25519-js'
|
||||
import { createCipheriv, createDecipheriv, createHash, createHmac, randomBytes } from 'crypto'
|
||||
import { KeyPair } from '../Types'
|
||||
|
||||
export const Curve = {
|
||||
generateKeyPair: (): KeyPair => {
|
||||
const { pubKey, privKey } = CurveCrypto.keyPair(randomBytes(32))
|
||||
const { public: pubKey, private: privKey } = curveJs.generateKeyPair(randomBytes(32))
|
||||
return {
|
||||
private: Buffer.from(privKey),
|
||||
public: Buffer.from(pubKey)
|
||||
}
|
||||
},
|
||||
sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) => {
|
||||
const shared = CurveCrypto.sharedSecret(publicKey, privateKey)
|
||||
const shared = curveJs.sharedKey(privateKey, publicKey)
|
||||
return Buffer.from(shared)
|
||||
},
|
||||
sign: (privateKey: Uint8Array, buf: Uint8Array) => (
|
||||
Buffer.from(CurveCrypto.sign(privateKey, buf))
|
||||
Buffer.from(curveJs.sign(privateKey, buf, null))
|
||||
),
|
||||
verify: (pubKey: Uint8Array, message: Uint8Array, signature: Uint8Array) => {
|
||||
try {
|
||||
CurveCrypto.verify(pubKey, message, signature)
|
||||
return true
|
||||
} catch(error) {
|
||||
if(error.message.includes('Invalid')) {
|
||||
return false
|
||||
}
|
||||
throw error
|
||||
}
|
||||
return curveJs.verify(pubKey, message, signature)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
11
yarn.lock
11
yarn.lock
@@ -1570,6 +1570,11 @@ cssstyle@^2.3.0:
|
||||
dependencies:
|
||||
cssom "~0.3.6"
|
||||
|
||||
curve25519-js@^0.0.4:
|
||||
version "0.0.4"
|
||||
resolved "https://registry.yarnpkg.com/curve25519-js/-/curve25519-js-0.0.4.tgz#e6ad967e8cd284590d657bbfc90d8b50e49ba060"
|
||||
integrity sha512-axn2UMEnkhyDUPWOwVKBMVIzSQy2ejH2xRGy1wq81dqRwApXfIzfbE3hIX0ZRFBIihf/KDqK158DLwESu4AK1w==
|
||||
|
||||
data-urls@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/data-urls/-/data-urls-2.0.0.tgz#156485a72963a970f5d5821aaf642bef2bf2db9b"
|
||||
@@ -2698,11 +2703,11 @@ levn@~0.3.0:
|
||||
prelude-ls "~1.1.2"
|
||||
type-check "~0.3.2"
|
||||
|
||||
libsignal@^2.0.1:
|
||||
"libsignal@git+https://github.com/adiwajshing/libsignal-node":
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/libsignal/-/libsignal-2.0.1.tgz#c276025c184ae4ebbd7d75c12c0be9f3b50cc19e"
|
||||
integrity sha512-kqdl/BK5i0WCa4NxhtiBsjSzztB/FtUp3mVVLKBFicWH8rDsq95tEIqNcCaVlflLxOm6T/HRb/zv8IsCe7aopA==
|
||||
resolved "git+https://github.com/adiwajshing/libsignal-node#11de21293c352a57d0c25d29c66963029873d953"
|
||||
dependencies:
|
||||
curve25519-js "^0.0.4"
|
||||
protobufjs "6.8.8"
|
||||
|
||||
load-bmfont@^1.3.1, load-bmfont@^1.4.0:
|
||||
|
||||
Reference in New Issue
Block a user