Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules
*.swp
npm-debug.log
build
.vscode
70 changes: 70 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"targets": [{
"target_name": "signal_crypto",
"cflags!": [ "-fno-exceptions" ],
"cflags_cc!": [ "-fno-exceptions" ],
"sources": [
"./native/curve25519-donna.c",
"./native/ed25519/additions/compare.c",
"./native/ed25519/additions/curve_sigs.c",
"./native/ed25519/additions/sign_modified.c",
"./native/ed25519/fe_0.c",
"./native/ed25519/fe_1.c",
"./native/ed25519/fe_add.c",
"./native/ed25519/fe_cmov.c",
"./native/ed25519/fe_copy.c",
"./native/ed25519/fe_frombytes.c",
"./native/ed25519/fe_invert.c",
"./native/ed25519/fe_isnegative.c",
"./native/ed25519/fe_isnonzero.c",
"./native/ed25519/fe_mul.c",
"./native/ed25519/fe_neg.c",
"./native/ed25519/fe_pow22523.c",
"./native/ed25519/fe_sq.c",
"./native/ed25519/fe_sq2.c",
"./native/ed25519/fe_sub.c",
"./native/ed25519/fe_tobytes.c",
"./native/ed25519/ge_add.c",
"./native/ed25519/ge_double_scalarmult.c",
"./native/ed25519/ge_frombytes.c",
"./native/ed25519/ge_madd.c",
"./native/ed25519/ge_msub.c",
"./native/ed25519/ge_p1p1_to_p2.c",
"./native/ed25519/ge_p1p1_to_p3.c",
"./native/ed25519/ge_p2_0.c",
"./native/ed25519/ge_p2_dbl.c",
"./native/ed25519/ge_p3_0.c",
"./native/ed25519/ge_p3_dbl.c",
"./native/ed25519/ge_p3_to_cached.c",
"./native/ed25519/ge_p3_to_p2.c",
"./native/ed25519/ge_p3_tobytes.c",
"./native/ed25519/ge_precomp_0.c",
"./native/ed25519/ge_scalarmult_base.c",
"./native/ed25519/ge_sub.c",
"./native/ed25519/ge_tobytes.c",
"./native/ed25519/open.c",
"./native/ed25519/sc_muladd.c",
"./native/ed25519/sc_reduce.c",
"./native/ed25519/sign.c",
"./native/ed25519/sha512/sha2big.c",
"./native/ed25519/sha512/crypto_hash_sha512.c",
"./src/crypto_binding.cpp"
],
"include_dirs": [
"<!(node -p \"require('node-addon-api').include_dir\")",
"native/ed25519/nacl_includes",
"native/ed25519",
"native/ed25519/sha512"
],
"defines": [
"NAPI_DISABLE_CPP_EXCEPTIONS",
"SPH_UPTR",
"SPH_UNALIGNED",
"SPH_BIG_ENDIAN=0",
"SPH_LITTLE_ENDIAN=1",
"SPH_SPARCV9_GCC_32",
"SPH_SMALL_FOOTPRINT=0",
"SPH_64"
]
}]
}
55 changes: 55 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
interface E2ESession {
registrationId: number;
identityKey: Uint8Array;
signedPreKey: {
keyId: number;
publicKey: Uint8Array;
signature: Uint8Array;
};
preKey: {
keyId: number;
publicKey: Uint8Array;
};
}

export interface SignalStorage {
loadSession(id: string): Promise<SessionRecord | null | undefined>;
storeSession(id: string, session: SessionRecord): Promise<void>;
isTrustedIdentity(
identifier: string,
identityKey: Uint8Array,
direction: number
): boolean;
loadPreKey(
id: number | string
): Promise<{ privKey: Buffer; pubKey: Buffer } | undefined>;
removePreKey(id: number): void;
loadSignedPreKey(): { privKey: Buffer; pubKey: Buffer };
getOurRegistrationId(): Promise<number> | number;
getOurIdentity(): { privKey: Buffer; pubKey: Buffer };
}

export class ProtocolAddress {
constructor(name: string, deviceId: number);
public id: string;
public deviceId: number;
public toString(): string;
}

export class SessionRecord {
static deserialize(serialized: Uint8Array): SessionRecord;
public serialize(): Uint8Array;
public haveOpenSession(): boolean;
}

export class SessionCipher {
constructor(storage: SignalStorage, remoteAddress: ProtocolAddress);
public decryptPreKeyWhisperMessage(ciphertext: Uint8Array): Promise<Buffer>;
public decryptWhisperMessage(ciphertext: Uint8Array): Promise<Buffer>;
public encrypt(data: Uint8Array): Promise<{ type: number; body: string }>;
}

export class SessionBuilder {
constructor(storage: SignalStorage, remoteAddress: ProtocolAddress);
public initOutgoing(session: E2ESession): Promise<void>;
}
Loading