@novasamatech/handoff-service 0.8.12 → 0.9.0

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/dist/codec.js CHANGED
@@ -1,4 +1,5 @@
1
- import { Bytes, Struct, Vector, u64 } from 'scale-ts';
1
+ import { Bytes } from '@novasamatech/scale';
2
+ import { Struct, Vector, u64 } from 'scale-ts';
2
3
  /**
3
4
  * Internal metadata stored in the HOP pool that references all chunks of an uploaded file.
4
5
  * This is not part of the chat message — it's only used by the file loader.
@@ -3,7 +3,7 @@ export type FileEncryption = {
3
3
  decrypt(data: Uint8Array): Uint8Array;
4
4
  };
5
5
  /**
6
- * AES-256-GCM encryption for file chunks and metadata.
6
+ * ChaCha20-Poly1305 (IETF, RFC 8439) encryption for file chunks and metadata.
7
7
  * Format: nonce (12 bytes) || ciphertext || tag (16 bytes)
8
8
  */
9
9
  export declare function createFileEncryption(key: Uint8Array): FileEncryption;
@@ -1,22 +1,22 @@
1
- import { gcm } from '@noble/ciphers/aes.js';
1
+ import { chacha20poly1305 } from '@noble/ciphers/chacha.js';
2
2
  import { randomBytes } from '@noble/hashes/utils.js';
3
3
  import { mergeUint8 } from '@polkadot-api/utils';
4
4
  /**
5
- * AES-256-GCM encryption for file chunks and metadata.
5
+ * ChaCha20-Poly1305 (IETF, RFC 8439) encryption for file chunks and metadata.
6
6
  * Format: nonce (12 bytes) || ciphertext || tag (16 bytes)
7
7
  */
8
8
  export function createFileEncryption(key) {
9
9
  return {
10
10
  encrypt(data) {
11
11
  const nonce = randomBytes(12);
12
- const aes = gcm(key, nonce);
13
- return mergeUint8([nonce, aes.encrypt(data)]);
12
+ const aead = chacha20poly1305(key, nonce);
13
+ return mergeUint8([nonce, aead.encrypt(data)]);
14
14
  },
15
15
  decrypt(encryptedData) {
16
16
  const nonce = encryptedData.slice(0, 12);
17
17
  const ciphertext = encryptedData.slice(12);
18
- const aes = gcm(key, nonce);
19
- return aes.decrypt(ciphertext);
18
+ const aead = chacha20poly1305(key, nonce);
19
+ return aead.decrypt(ciphertext);
20
20
  },
21
21
  };
22
22
  }
@@ -1,3 +1,4 @@
1
+ import { chacha20poly1305 } from '@noble/ciphers/chacha.js';
1
2
  import { randomBytes } from '@noble/hashes/utils.js';
2
3
  import { describe, expect, it } from 'vitest';
3
4
  import { createFileEncryption } from './encryption.js';
@@ -35,6 +36,23 @@ describe('file encryption', () => {
35
36
  const encrypted = enc1.encrypt(plaintext);
36
37
  expect(() => enc2.decrypt(encrypted)).toThrow();
37
38
  });
39
+ it('encrypts with ChaCha20-Poly1305 (external reader decrypts nonce || ct || tag)', () => {
40
+ const key = randomBytes(32);
41
+ const plaintext = new TextEncoder().encode('file chunk');
42
+ const encrypted = createFileEncryption(key).encrypt(plaintext);
43
+ const nonce = encrypted.slice(0, 12);
44
+ const body = encrypted.slice(12);
45
+ const decrypted = chacha20poly1305(key, nonce).decrypt(body);
46
+ expect(decrypted).toEqual(plaintext);
47
+ });
48
+ it('decrypts a ChaCha20-Poly1305 ciphertext built externally', () => {
49
+ const key = randomBytes(32);
50
+ const plaintext = new TextEncoder().encode('external chunk');
51
+ const nonce = randomBytes(12);
52
+ const body = chacha20poly1305(key, nonce).encrypt(plaintext);
53
+ const decrypted = createFileEncryption(key).decrypt(new Uint8Array([...nonce, ...body]));
54
+ expect(decrypted).toEqual(plaintext);
55
+ });
38
56
  it('handles empty data', () => {
39
57
  const key = randomBytes(32);
40
58
  const encryption = createFileEncryption(key);
package/dist/rpc/scale.js CHANGED
@@ -1,4 +1,5 @@
1
- import { Bytes, Enum } from 'scale-ts';
1
+ import { Bytes } from '@novasamatech/scale';
2
+ import { Enum } from 'scale-ts';
2
3
  /**
3
4
  * SCALE-encoded MultiSigner:
4
5
  * 0 = Ed25519 (32 bytes)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@novasamatech/handoff-service",
3
3
  "type": "module",
4
- "version": "0.8.12",
4
+ "version": "0.9.0",
5
5
  "description": "HOP (Handoff Pool) file transfer service for P2P chat",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -27,6 +27,7 @@
27
27
  "dependencies": {
28
28
  "@noble/ciphers": "2.2.0",
29
29
  "@noble/hashes": "2.2.0",
30
+ "@novasamatech/scale": "0.9.0",
30
31
  "@polkadot-api/utils": "^0.4.0",
31
32
  "@scure/sr25519": "2.2.0",
32
33
  "neverthrow": "^8.2.0",