@freesignal/protocol 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/crypto.d.ts CHANGED
@@ -16,61 +16,7 @@
16
16
  * You should have received a copy of the GNU General Public License
17
17
  * along with this program. If not, see <https://www.gnu.org/licenses/>
18
18
  */
19
- export type HashAlgorithms = 'sha224' | 'sha256' | 'sha384' | 'sha512';
20
- export type HmacAlgorithms = 'kmac128' | 'kmac256';
21
- interface UUIDv4 {
22
- toString(): string;
23
- toJSON(): string;
24
- toBuffer(): Uint8Array;
25
- }
26
- export interface Crypto {
27
- hash(message: Uint8Array, algorithm?: HashAlgorithms): Uint8Array;
28
- hmac(key: Uint8Array, message: Uint8Array, length?: number, algorithm?: HmacAlgorithms): Uint8Array;
29
- hkdf(key: Uint8Array, salt: Uint8Array, info?: Uint8Array | string, length?: number): Uint8Array;
30
- readonly KeyPair: typeof Crypto.KeyPair;
31
- readonly box: Crypto.box;
32
- readonly ECDH: Crypto.ECDH;
33
- readonly EdDSA: Crypto.EdDSA;
34
- readonly UUID: Crypto.UUID;
35
- randomBytes(n: number): Uint8Array;
36
- scalarMult(n: Uint8Array, p: Uint8Array): Uint8Array;
37
- }
38
- export declare namespace Crypto {
39
- type KeyPair = {
40
- readonly publicKey: Uint8Array;
41
- readonly secretKey: Uint8Array;
42
- };
43
- namespace KeyPair {
44
- function isKeyPair(obj: any): boolean;
45
- }
46
- interface box {
47
- readonly keyLength: number;
48
- readonly nonceLength: number;
49
- encrypt(msg: Uint8Array, nonce: Uint8Array, key: Uint8Array): Uint8Array;
50
- decrypt(msg: Uint8Array, nonce: Uint8Array, key: Uint8Array): Uint8Array | undefined;
51
- }
52
- interface ECDH {
53
- readonly publicKeyLength: number;
54
- readonly secretKeyLength: number;
55
- keyPair(secretKey?: Uint8Array): KeyPair;
56
- sharedKey(publicKey: Uint8Array, secretKey: Uint8Array): Uint8Array;
57
- }
58
- interface EdDSA {
59
- readonly publicKeyLength: number;
60
- readonly secretKeyLength: number;
61
- readonly signatureLength: number;
62
- readonly seedLength: number;
63
- keyPair(secretKey?: Uint8Array): KeyPair;
64
- keyPairFromSeed(seed: Uint8Array): KeyPair;
65
- sign(msg: Uint8Array, secretKey: Uint8Array): Uint8Array;
66
- verify(msg: Uint8Array, sig: Uint8Array, publicKey: Uint8Array): boolean;
67
- }
68
- interface UUID {
69
- generate(): UUIDv4;
70
- stringify(arr: Uint8Array, offset?: number): string;
71
- parse(uuid: string): Uint8Array;
72
- }
73
- }
19
+ import { Crypto } from './types';
74
20
  declare const crypto: Crypto;
75
21
  declare namespace crypto {
76
22
  type KeyPair = Crypto.KeyPair;
package/crypto.js CHANGED
@@ -21,14 +21,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
21
21
  return (mod && mod.__esModule) ? mod : { "default": mod };
22
22
  };
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.Crypto = void 0;
25
24
  const js_sha3_1 = require("js-sha3");
26
25
  const tweetnacl_1 = __importDefault(require("tweetnacl"));
27
26
  const uuid_1 = require("uuid");
28
27
  const utils_1 = require("./utils");
29
- var Crypto;
30
- (function (Crypto) {
31
- })(Crypto || (exports.Crypto = Crypto = {}));
32
28
  class CryptoConstructor {
33
29
  constructor() {
34
30
  this.KeyPair = {
package/data.d.ts CHANGED
@@ -44,7 +44,7 @@ export declare namespace Datagram {
44
44
  const version = 1;
45
45
  function create(sender: Uint8Array | string, receiver: Uint8Array | string, protocol: Protocols, payload?: Uint8Array | Encodable): DatagramConstructor;
46
46
  function isDatagram(obj: any): boolean;
47
- function from(data: Uint8Array): DatagramConstructor;
47
+ function from(data: Uint8Array | Datagram | string): DatagramConstructor;
48
48
  }
49
49
  declare class DatagramConstructor implements Encodable, Datagram {
50
50
  readonly id: string;
package/data.js CHANGED
@@ -70,7 +70,12 @@ var Datagram;
70
70
  }
71
71
  Datagram.isDatagram = isDatagram;
72
72
  function from(data) {
73
- return new DatagramConstructor(data);
73
+ if (typeof data === 'string') {
74
+ const decoded = (0, utils_1.decodeBase64)(data);
75
+ return new DatagramConstructor(decoded);
76
+ }
77
+ else
78
+ return new DatagramConstructor(data);
74
79
  }
75
80
  Datagram.from = from;
76
81
  })(Datagram || (exports.Datagram = Datagram = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@freesignal/protocol",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Signal Protocol implementation in javascript",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "author": "Christian Braghette",
package/types.d.ts CHANGED
@@ -58,4 +58,59 @@ export interface KeyExchangeDataBundle {
58
58
  readonly signature: string;
59
59
  readonly onetimePreKey: string[];
60
60
  }
61
+ interface UUIDv4 {
62
+ toString(): string;
63
+ toJSON(): string;
64
+ toBuffer(): Uint8Array;
65
+ }
66
+ export interface Crypto {
67
+ hash(message: Uint8Array, algorithm?: Crypto.HashAlgorithms): Uint8Array;
68
+ hmac(key: Uint8Array, message: Uint8Array, length?: number, algorithm?: Crypto.HmacAlgorithms): Uint8Array;
69
+ hkdf(key: Uint8Array, salt: Uint8Array, info?: Uint8Array | string, length?: number): Uint8Array;
70
+ readonly KeyPair: typeof Crypto.KeyPair;
71
+ readonly box: Crypto.box;
72
+ readonly ECDH: Crypto.ECDH;
73
+ readonly EdDSA: Crypto.EdDSA;
74
+ readonly UUID: Crypto.UUID;
75
+ randomBytes(n: number): Uint8Array;
76
+ scalarMult(n: Uint8Array, p: Uint8Array): Uint8Array;
77
+ }
78
+ export declare namespace Crypto {
79
+ type HashAlgorithms = 'sha224' | 'sha256' | 'sha384' | 'sha512';
80
+ type HmacAlgorithms = 'kmac128' | 'kmac256';
81
+ type KeyPair = {
82
+ readonly publicKey: Uint8Array;
83
+ readonly secretKey: Uint8Array;
84
+ };
85
+ namespace KeyPair {
86
+ function isKeyPair(obj: any): boolean;
87
+ }
88
+ interface box {
89
+ readonly keyLength: number;
90
+ readonly nonceLength: number;
91
+ encrypt(msg: Uint8Array, nonce: Uint8Array, key: Uint8Array): Uint8Array;
92
+ decrypt(msg: Uint8Array, nonce: Uint8Array, key: Uint8Array): Uint8Array | undefined;
93
+ }
94
+ interface ECDH {
95
+ readonly publicKeyLength: number;
96
+ readonly secretKeyLength: number;
97
+ keyPair(secretKey?: Uint8Array): KeyPair;
98
+ sharedKey(publicKey: Uint8Array, secretKey: Uint8Array): Uint8Array;
99
+ }
100
+ interface EdDSA {
101
+ readonly publicKeyLength: number;
102
+ readonly secretKeyLength: number;
103
+ readonly signatureLength: number;
104
+ readonly seedLength: number;
105
+ keyPair(secretKey?: Uint8Array): KeyPair;
106
+ keyPairFromSeed(seed: Uint8Array): KeyPair;
107
+ sign(msg: Uint8Array, secretKey: Uint8Array): Uint8Array;
108
+ verify(msg: Uint8Array, sig: Uint8Array, publicKey: Uint8Array): boolean;
109
+ }
110
+ interface UUID {
111
+ generate(): UUIDv4;
112
+ stringify(arr: Uint8Array, offset?: number): string;
113
+ parse(uuid: string): Uint8Array;
114
+ }
115
+ }
61
116
  export {};
package/types.js CHANGED
@@ -18,7 +18,7 @@
18
18
  * along with this program. If not, see <https://www.gnu.org/licenses/>
19
19
  */
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.Encodable = void 0;
21
+ exports.Crypto = exports.Encodable = void 0;
22
22
  var Encodable;
23
23
  (function (Encodable) {
24
24
  const properties = ['encode', 'toString', 'toJSON'];
@@ -27,3 +27,6 @@ var Encodable;
27
27
  }
28
28
  Encodable.isEncodable = isEncodable;
29
29
  })(Encodable || (exports.Encodable = Encodable = {}));
30
+ var Crypto;
31
+ (function (Crypto) {
32
+ })(Crypto || (exports.Crypto = Crypto = {}));