@session.js/blinded-session-id 1.0.7 → 1.0.8

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @session.js/blinded-session-id
2
2
 
3
- Utility JavaScript library with methods to work with Session's blinded Session ID. Uses [noble v2](https://www.npmjs.com/package/@noble/ciphers) under the hood.
3
+ Utility JavaScript library with methods to work with Session's blinded Session ID. Uses @noble/curves v2, @noble/hashes v2 and @session.js/scalars under the hood.
4
4
 
5
5
  Example of unblinded Session ID (05-prefixed):
6
6
  `057aeb66e45660c3bdfb7c62706f6440226af43ec13f3b6f899c1dd4db1b8fce5b`
@@ -23,7 +23,6 @@ Blinded IDs are used on Session SOGS to conceal identity of room's users.
23
23
  - [Unblinding 25-prefixed Session IDs](#unblinding-25-prefixed-session-ids)
24
24
  - [Advanced usage](#advanced-usage)
25
25
  - [getBlindingK](#getblindingk)
26
- - [Acknowledgements](#acknowledgements)
27
26
  - [Made for Session.js](#made-for-sessionjs)
28
27
  - [Donate](#donate)
29
28
  - [License](#license)
@@ -155,7 +154,7 @@ Unblinding 25-prefixed Session IDs is impossible.
155
154
  generates a hash for blinding/unblinding using blake2b
156
155
 
157
156
  ```ts
158
- import { getBlindingK } from "@session.js/blinded-session-id/utils.js";
157
+ import { getBlindingK } from "@session.js/blinded-session-id/utils";
159
158
 
160
159
  const sogsPublicKey = new Uint8Array([
161
160
  203, 79, 214, 25, 155, 132, 220, 54, 100, 240, 55, 51, 84, 52, 26, 1, 0, 126, 202, 169, 154, 56,
@@ -165,9 +164,6 @@ getBlindingK(sogsPublicKey);
165
164
  // => Uint8Array(32) [ 27, 203, 111, 10, 221, 88, 187, 146, 221, 11, 206, 55, 7, 86, 218, 223, 21, 123, 29, 214, 198, 182, 3, 40, 188, 123, 190, 73, 35, 122, 140, 13 ]
166
165
  ```
167
166
 
168
- ## Acknowledgements
169
-
170
- Credit to li0ard for [https://github.com/theinfinityway/session_id/](https://github.com/theinfinityway/session_id/) (MIT license) and src/scalar-math.ts
171
167
  ## Made for Session.js
172
168
 
173
169
  Use Session messenger programmatically with [Session.js](https://git.hloth.dev/session.js/client): Session bots, custom Session clients, and more.
package/dist/blinding.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { hexToBytes } from "@noble/curves/utils.js";
2
2
  import { SessionValidationError, SessionValidationErrorCode } from "@session.js/errors";
3
- import { multiplyPointToScalar, curve25519ToEd25519, ed25519ToCurve25519 } from "./scalar-math";
3
+ import { multiplyPointToScalar, curve25519ToEd25519, ed25519ToCurve25519 } from "@session.js/scalars";
4
4
  import { getBlindingK, hexRegex, keyToSessionId } from "./utils";
5
5
  export function blindKey15({ ed25519PublicKey, serverPublicKey, }) {
6
6
  const blindingKInput = serverPublicKey;
@@ -1,7 +1,7 @@
1
1
  import { ed25519 } from "@noble/curves/ed25519.js";
2
2
  import { hexToBytes } from "@noble/curves/utils.js";
3
3
  import { SessionValidationError, SessionValidationErrorCode } from "@session.js/errors";
4
- import { invertScalar, multiplyPointToScalar } from "./scalar-math";
4
+ import { invertScalar, multiplyPointToScalar } from "@session.js/scalars";
5
5
  import { getBlindingK, hexRegex, keyToSessionId } from "./utils";
6
6
  export function unblindKey15({ blindedKey, serverPublicKey, }) {
7
7
  const blindingKInput = serverPublicKey;
package/dist/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { blake2b } from "@noble/hashes/blake2.js";
2
2
  import { bytesToHex } from "@noble/curves/utils.js";
3
- import { scalarReduce } from "./scalar-math";
3
+ import { scalarReduce } from "@session.js/scalars";
4
4
  export const hexRegex = /^[0-9a-fA-F]+$/i;
5
5
  export function getBlindingK(input) {
6
6
  const serverPkHash = blake2b(input, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@session.js/blinded-session-id",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Utility JavaScript library with methods to work with Session's blinded Session ID",
5
5
  "homepage": "https://git.hloth.dev/session.js/blinded-session-id#readme",
6
6
  "bugs": {
@@ -14,6 +14,16 @@
14
14
  "license": "MIT",
15
15
  "author": "Viktor Shchelochkov <hi@hloth.dev> (https://hloth.dev)",
16
16
  "type": "module",
17
+ "exports": {
18
+ ".": {
19
+ "import": "./dist/index.js",
20
+ "types": "./dist/index.d.ts"
21
+ },
22
+ "./utils": {
23
+ "import": "./dist/utils.js",
24
+ "types": "./dist/utils.d.ts"
25
+ }
26
+ },
17
27
  "main": "dist/index.js",
18
28
  "types": "dist/index.d.ts",
19
29
  "files": [
@@ -28,7 +38,8 @@
28
38
  "dependencies": {
29
39
  "@noble/curves": "^2.0.1",
30
40
  "@noble/hashes": "^2.0.1",
31
- "@session.js/errors": "^1.0.11"
41
+ "@session.js/errors": "^1.0.11",
42
+ "@session.js/scalars": "^1.0.0"
32
43
  },
33
44
  "devDependencies": {
34
45
  "@eslint/compat": "^2.0.1",
@@ -1,7 +0,0 @@
1
- export declare function scalarAdd(scalarA: Uint8Array, scalarB: Uint8Array): Uint8Array;
2
- export declare function scalarMul(scalarA: Uint8Array, scalarB: Uint8Array): Uint8Array;
3
- export declare function scalarReduce(scalar: Uint8Array): Uint8Array;
4
- export declare function invertScalar(scalar: Uint8Array): Uint8Array;
5
- export declare function multiplyPointToScalar(scalar: Uint8Array, point: Uint8Array): Uint8Array;
6
- export declare function ed25519ToCurve25519(ed25519Pk: Uint8Array): Uint8Array;
7
- export declare function curve25519ToEd25519(x25519Pk: Uint8Array): Uint8Array;
@@ -1,43 +0,0 @@
1
- import { ed25519 } from "@noble/curves/ed25519.js";
2
- import { mod } from "@noble/curves/abstract/modular.js";
3
- import { bytesToNumberLE, numberToBytesLE } from "@noble/curves/utils.js";
4
- export function scalarAdd(scalarA, scalarB) {
5
- const a = bytesToNumberLE(scalarA);
6
- const b = bytesToNumberLE(scalarB);
7
- const result = ed25519.Point.Fn.add(a, b);
8
- return numberToBytesLE(result, 32);
9
- }
10
- export function scalarMul(scalarA, scalarB) {
11
- const a = bytesToNumberLE(scalarA);
12
- const b = bytesToNumberLE(scalarB);
13
- const result = ed25519.Point.Fn.mul(a, b);
14
- return numberToBytesLE(result, 32);
15
- }
16
- export function scalarReduce(scalar) {
17
- const scalarNum = bytesToNumberLE(scalar);
18
- const result = mod(scalarNum, ed25519.Point.Fn.ORDER);
19
- return numberToBytesLE(result, 32);
20
- }
21
- export function invertScalar(scalar) {
22
- const s = bytesToNumberLE(scalar);
23
- const inverted = ed25519.Point.Fn.inv(s);
24
- return numberToBytesLE(inverted, 32);
25
- }
26
- export function multiplyPointToScalar(scalar, point) {
27
- const L = ed25519.Point.Fn.ORDER;
28
- const s = mod(bytesToNumberLE(scalar), L);
29
- const P = ed25519.Point.fromBytes(point);
30
- if (P.isSmallOrder()) {
31
- throw new Error("scalarMultEd25519NoClamp: invalid point (small order)");
32
- }
33
- return P.multiply(s).toBytes();
34
- }
35
- export function ed25519ToCurve25519(ed25519Pk) {
36
- const seed = ed25519Pk.slice(0, 32);
37
- return ed25519.utils.toMontgomerySecret(seed);
38
- }
39
- export function curve25519ToEd25519(x25519Pk) {
40
- const f = ed25519.Point.Fp;
41
- const x = f.fromBytes(x25519Pk);
42
- return f.toBytes(f.div(f.sub(x, f.ONE), f.add(x, f.ONE)));
43
- }