Skip to content
This repository has been archived by the owner on Sep 21, 2023. It is now read-only.

Commit

Permalink
Add pairings & more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Aug 28, 2019
1 parent 609a875 commit 7e11c0e
Show file tree
Hide file tree
Showing 10 changed files with 1,849 additions and 576 deletions.
50 changes: 43 additions & 7 deletions README.md
Expand Up @@ -85,6 +85,7 @@ const HASH_MESSAGES = ["deadbeef", "111111", "aaaaaabbbbbb"];
- [`aggregatePublicKeys(publicKeys)`](#aggregatepublickeyspublickeys)
- [`aggregateSignatures(signatures)`](#aggregatesignaturessignatures)
- [`verifyMultiple(hashes, publicKeys, signature, domain)`](#verifymultiplehashes-publickeys-signature-domain)
- [`pairing(4dPoint, 2dPoint)`](#pairing4dpoint-2dpoint)
- [Helpers](#helpers)

##### `getPublicKey(privateKey)`
Expand All @@ -94,7 +95,7 @@ function getPublicKey(privateKey: Uint8Array | string | bigint): Uint8Array;
- `privateKey: Uint8Array | string | bigint` will be used to generate public key.
Public key is generated by executing scalar multiplication of a base Point(x, y) by a fixed
integer. The result is another `Point(x, y)` which we will by default encode to hex Uint8Array.
- Returns `Uint8Array`: endcoded publicKey for signature verification
- Returns `Uint8Array`: encoded publicKey for signature verification

##### `sign(hash, privateKey, domain)`
```typescript
Expand All @@ -106,8 +107,8 @@ function sign(
```
- `hash: Uint8Array | string` - message hash which would be signed
- `privateKey: Uint8Array | string | bigint` - private key which will sign the hash
- `domain: Uint8Array | string | bigint` - version of signature. Different domains will give different signatures. Setting a new domain in an upgraded system prevents it from being affected by the old messages and signatures.
- Returns encoded signature.
- `domain: Uint8Array | string | bigint` - signature version. Different domains will give different signatures. Setting a new domain in an upgraded system prevents it from being affected by the old messages and signatures.
- Returns `Uint8Array`: encoded signature

##### `verify(hash, publicKey, signature, domain)`
```typescript
Expand All @@ -121,21 +122,21 @@ function verify(
- `hash: Uint8Array | string` - message hash that needs to be verified
- `publicKey: Uint8Array | string` - e.g. that was generated from `privateKey` by `getPublicKey`
- `signature: Uint8Array | string` - object returned by the `sign` or `aggregateSignatures` function
- Returns `Promise<boolean>`: `Promise<true>` if `signature == hash`; otherwise `Promise<false>`
- Returns `Promise<boolean>`: `true` / `false` whether the signature matches hash

##### `aggregatePublicKeys(publicKeys)`
```typescript
function aggregatePublicKeys(publicKeys: Uint8Array[] | string[]): Uint8Array;
```
- `publicKeys: Uint8Array[] | string[]` - e.g. that have been generated from `privateKey` by `getPublicKey`
- Returns `Uint8Array`: one aggregated public key which calculated from putted public keys
- Returns `Uint8Array`: one aggregated public key which calculated from public keys

##### `aggregateSignatures(signatures)`
```typescript
function aggregateSignatures(signatures: Uint8Array[] | string[]): Uint8Array;
```
- `signatures: Uint8Array[] | string[]` - e.g. that have been generated by `sign`
- Returns `Uint8Array`: one aggregated signature which calculated from putted signatures
- Returns `Uint8Array`: one aggregated signature which calculated from signatures

##### `verifyMultiple(hashes, publicKeys, signature, domain)`
```typescript
Expand All @@ -149,7 +150,20 @@ function verifyMultiple(
- `hashes: Uint8Array[] | string[]` - messages hashes that needs to be verified
- `publicKeys: Uint8Array[] | string[]` - e.g. that were generated from `privateKeys` by `getPublicKey`
- `signature: Uint8Array | string` - object returned by the `aggregateSignatures` function
- Returns `Promise<boolean>`: `Promise<true>` if `signature == hashes`; otherwise `Promise<false>`
- Returns `Promise<boolean>`: `true` / `false` whether the signature matches hashes

##### `pairing(4dPoint, 2dPoint)`
```typescript
function pairing(
4dPoint: Point<[bigint, bigint]>,
2dPoint: Point<bigint>,
withFinalExponent: boolean = true
): Point<[bigint, bigint, bigint, bigint, bigint, bigint, bigint, bigint, bigint, bigint, bigint, bigint]>
```
- `4dPoint: Point<[bigint, bigint]>` - 4d point ((`(x, x_1), (y, y_1)`))
- `2dPoint: Point<bigint>` - simple point (`x, y` are encoded in the `bigint`).
- `withFinalExponent: boolean` - if the flag setted as true then result will be powered by curve order else will be not.
- Returns `Point<BigintTwelve>`: paired 12 dimensional point.

##### Helpers

Expand All @@ -159,6 +173,28 @@ bls.P // 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabf
// Prime order
bls.PRIME_ORDER // 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001n
// Base point for Hash
bls.G1 // 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001n
// x = 3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507
// y = 1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569
// Base point for Signature
bls.G2
// x = 3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758, 352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160
// y = 927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582, 1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905
// Class for subgroup number representation
bls.Fp
// Class for subgroup two dimensional number representation
bls.Fp2
// Class for subgroup twelve dimensional number representation
bls.Fp12
// Class for elliptic curve point representation
bls.Point
```

## Curve Description
Expand Down

0 comments on commit 7e11c0e

Please sign in to comment.