0.1.8 • Published 4 years ago

js-smp v0.1.8

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

js-smp

js-smp is a typescript implementation of the SMP(Socialist Millionaires' Problem) Protocol, which allows two people to compare whether their secrets are equaled, without leaking any other information.

This implementation is based on the Socialist Millionaires' Protocol in Off-the-record Messaging(OTR) version 3. See

Installation

npm install js-smp

Usage

SMPStateMachine holds what you need!

import { SMPStateMachine } from 'js-smp';

/* Initialize Alice */
// A secret can be either these types.
const aliceSecret: number | string | BN | Uint8Array = 'alice-small-serect';
const alice = new SMPStateMachine(aliceSecret);

/* Initialize Bob */
const bobSecret: number | string | BN | Uint8Array = 'bob-big-serect';
const bob = new SMPStateMachine(bobSecret);

// Alice initiate SMP.
// SMP is initiated by passing `null` to `transit`, and the first message is returned.
const msg1 = alice.transit(null);

// Bob receives `msg1` and replies `msg2`.
const msg2 = bob.transit(msg1);

// Alice receives `msg2` and replies `msg3`.
const msg3 = alice.transit(msg2);

// Bob receives `msg3` and replies `msg4`. Bob gets the result.
const msg4 = bob.transit(msg3);
const bobResult = bob.getResult();

// Alice receives `msg4` and nothing to reply. Alice gets the result.
alice.transit(msg4);
const aliceResult = alice.getResult();

// result=false, because `aliceSecret !== bobSecret`.
console.log(`result=${aliceResult}`);

Through the wire

Serialization and deserialization are done by TLV.serialize and TLV.deserialize(bytes). Messages returned from SMPStateMachine.transit are in TLV format. Working with the network is made easy. The wire types and messages can be found in src/dataTypes.ts and src/msgs.ts.

import { TLV } from 'js-smp';
const msg2: TLV = bob.transit(msg1);
const msg2bytes: Uint8Array = msg2.serialize();

/* Send `msg2bytes` over the wire to Alice... */

/* Receive `msg3bytes` over the wire from Alice... */
const msg3 = TLV.deserialize(msg3bytes);
const msg4: TLV = bob.transit(msg3);
0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago