Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated noble curves for point fix #42

Merged
merged 5 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 15 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tlock-js",
"version": "0.8.0",
"version": "0.9.0",
"description": "A library to encrypt data that can only be decrypted in the future using drand",
"source": "src/index.ts",
"main": "index.js",
Expand Down Expand Up @@ -42,11 +42,10 @@
"typescript": "^5.1.6"
},
"dependencies": {
"@noble/bls12-381": "^1.4.0",
"@noble/hashes": "^1.3.1",
"@noble/hashes": "^1.4.0",
"@stablelib/chacha20poly1305": "^1.0.1",
"buffer": "^6.0.3",
"drand-client": "1.2.3"
"drand-client": "1.2.5"
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No noble/curves in here?

"browserslist": [
"> 0.5%",
Expand Down
99 changes: 99 additions & 0 deletions src/crypto/fp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import * as mod from "@noble/curves/abstract/modular"

// these are all some helpers around the field elements used in the BLS lib that got abstracted away
// when migrating from @noble/bls12-381 -> @noble/curves
declare const Fp: Readonly<mod.IField<bigint> & Required<Pick<mod.IField<bigint>, "isOdd">>>;
type Fp = bigint;
type BigintTuple = [bigint, bigint];
type Fp2 = {
c0: bigint;
c1: bigint;
};

function fp2FromBigTuple(t: BigintTuple): Fp2 {
return {
c0: t[0],
c1: t[1]
}
}

declare const Fp2: mod.IField<Fp2>
type BigintSix = [bigint, bigint, bigint, bigint, bigint, bigint]
type Fp6 = {
c0: Fp2;
c1: Fp2;
c2: Fp2;
};

declare const Fp6: mod.IField<Fp6>

function fp6FromBigSix(b: BigintSix): Fp6 {
return {
c0: {
c0: b[0],
c1: b[1],
},
c1: {
c0: b[2],
c1: b[3],
},
c2: {
c0: b[4],
c1: b[5],
}
}
}

type Fp12 = {
c0: Fp6;
c1: Fp6;
};
type BigintTwelve = [
bigint,
bigint,
bigint,
bigint,
bigint,
bigint,
bigint,
bigint,
bigint,
bigint,
bigint,
bigint
];

function fp12FromBigTwelve(b: BigintTwelve): Fp12 {
return {
c0: {
c0: {
c0: b[0],
c1: b[1],
},
c1: {
c0: b[2],
c1: b[3],
},
c2: {
c0: b[4],
c1: b[5],
}
},
c1: {
c0: {
c0: b[6],
c1: b[7],
},
c1: {
c0: b[8],
c1: b[9],
},
c2: {
c0: b[10],
c1: b[11],
}
}
}
}

export {Fp, Fp2, Fp6, Fp12, fp2FromBigTuple, fp6FromBigSix, fp12FromBigTwelve, BigintTwelve}
Loading
Loading