@helios-lang/crypto
Advanced tools
Comparing version
{ | ||
"name": "@helios-lang/crypto", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "Cryptography primitives used throughout HeliosLang codebase", | ||
@@ -27,7 +27,7 @@ "main": "src/index.js", | ||
"dependencies": { | ||
"@helios-lang/codec-utils": "^0.3.3", | ||
"@helios-lang/type-utils": "0.2.8" | ||
"@helios-lang/codec-utils": "^0.3.4", | ||
"@helios-lang/type-utils": "0.2.9" | ||
}, | ||
"scripts": { | ||
"build": "pnpm run prettify && pnpm run lint && pnpm run build:types && pnpm run test:suite", | ||
"build": "pnpm run prettify && pnpm run lint && pnpm run build:types && pnpm run test:suite && pnpm run test:integ", | ||
"build:docs": "typedoc --tsconfig ./jsconfig.json", | ||
@@ -37,3 +37,4 @@ "build:types": "tsc -p jsconfig.json --noEmit false --emitDeclarationOnly", | ||
"prettify": "prettier . --write", | ||
"test": "pnpm run test:pretty && pnpm run lint && pnpm run test:types && pnpm run test:suite", | ||
"test": "pnpm run test:pretty && pnpm run lint && pnpm run test:types && pnpm run test:suite && pnpm run test:integ", | ||
"test:integ": "pnpm --prefix ./test/all-pure run test", | ||
"test:pretty": "prettier . --check", | ||
@@ -40,0 +41,0 @@ "test:suite": "node --test --experimental-test-coverage", |
@@ -9,3 +9,3 @@ import { makeBase32 } from "@helios-lang/codec-utils" | ||
const BECH32_PAYLOAD_CODEC = makeBase32({ | ||
const BECH32_PAYLOAD_CODEC = /* @__PURE__ */ makeBase32({ | ||
alphabet: BECH32_BASE32_ALPHABET | ||
@@ -12,0 +12,0 @@ }) |
@@ -17,10 +17,10 @@ import { makeUInt64, makeUInt64Fast } from "@helios-lang/codec-utils" | ||
const IV = [ | ||
makeUInt64Fast(0x6a09e667, 0xf3bcc908), | ||
makeUInt64Fast(0xbb67ae85, 0x84caa73b), | ||
makeUInt64Fast(0x3c6ef372, 0xfe94f82b), | ||
makeUInt64Fast(0xa54ff53a, 0x5f1d36f1), | ||
makeUInt64Fast(0x510e527f, 0xade682d1), | ||
makeUInt64Fast(0x9b05688c, 0x2b3e6c1f), | ||
makeUInt64Fast(0x1f83d9ab, 0xfb41bd6b), | ||
makeUInt64Fast(0x5be0cd19, 0x137e2179) | ||
/* @__PURE__ */ makeUInt64Fast(0x6a09e667, 0xf3bcc908), | ||
/* @__PURE__ */ makeUInt64Fast(0xbb67ae85, 0x84caa73b), | ||
/* @__PURE__ */ makeUInt64Fast(0x3c6ef372, 0xfe94f82b), | ||
/* @__PURE__ */ makeUInt64Fast(0xa54ff53a, 0x5f1d36f1), | ||
/* @__PURE__ */ makeUInt64Fast(0x510e527f, 0xade682d1), | ||
/* @__PURE__ */ makeUInt64Fast(0x9b05688c, 0x2b3e6c1f), | ||
/* @__PURE__ */ makeUInt64Fast(0x1f83d9ab, 0xfb41bd6b), | ||
/* @__PURE__ */ makeUInt64Fast(0x5be0cd19, 0x137e2179) | ||
] | ||
@@ -27,0 +27,0 @@ |
@@ -33,3 +33,3 @@ import { | ||
*/ | ||
const CAP = WIDTH - RATE | ||
const CAP = /* @__PURE__ */ (() => WIDTH - RATE)() | ||
@@ -59,26 +59,26 @@ /** | ||
const RC = [ | ||
makeUInt64Fast(0x00000000, 0x00000001), | ||
makeUInt64Fast(0x00000000, 0x00008082), | ||
makeUInt64Fast(0x80000000, 0x0000808a), | ||
makeUInt64Fast(0x80000000, 0x80008000), | ||
makeUInt64Fast(0x00000000, 0x0000808b), | ||
makeUInt64Fast(0x00000000, 0x80000001), | ||
makeUInt64Fast(0x80000000, 0x80008081), | ||
makeUInt64Fast(0x80000000, 0x00008009), | ||
makeUInt64Fast(0x00000000, 0x0000008a), | ||
makeUInt64Fast(0x00000000, 0x00000088), | ||
makeUInt64Fast(0x00000000, 0x80008009), | ||
makeUInt64Fast(0x00000000, 0x8000000a), | ||
makeUInt64Fast(0x00000000, 0x8000808b), | ||
makeUInt64Fast(0x80000000, 0x0000008b), | ||
makeUInt64Fast(0x80000000, 0x00008089), | ||
makeUInt64Fast(0x80000000, 0x00008003), | ||
makeUInt64Fast(0x80000000, 0x00008002), | ||
makeUInt64Fast(0x80000000, 0x00000080), | ||
makeUInt64Fast(0x00000000, 0x0000800a), | ||
makeUInt64Fast(0x80000000, 0x8000000a), | ||
makeUInt64Fast(0x80000000, 0x80008081), | ||
makeUInt64Fast(0x80000000, 0x00008080), | ||
makeUInt64Fast(0x00000000, 0x80000001), | ||
makeUInt64Fast(0x80000000, 0x80008008) | ||
/* @__PURE__ */ makeUInt64Fast(0x00000000, 0x00000001), | ||
/* @__PURE__ */ makeUInt64Fast(0x00000000, 0x00008082), | ||
/* @__PURE__ */ makeUInt64Fast(0x80000000, 0x0000808a), | ||
/* @__PURE__ */ makeUInt64Fast(0x80000000, 0x80008000), | ||
/* @__PURE__ */ makeUInt64Fast(0x00000000, 0x0000808b), | ||
/* @__PURE__ */ makeUInt64Fast(0x00000000, 0x80000001), | ||
/* @__PURE__ */ makeUInt64Fast(0x80000000, 0x80008081), | ||
/* @__PURE__ */ makeUInt64Fast(0x80000000, 0x00008009), | ||
/* @__PURE__ */ makeUInt64Fast(0x00000000, 0x0000008a), | ||
/* @__PURE__ */ makeUInt64Fast(0x00000000, 0x00000088), | ||
/* @__PURE__ */ makeUInt64Fast(0x00000000, 0x80008009), | ||
/* @__PURE__ */ makeUInt64Fast(0x00000000, 0x8000000a), | ||
/* @__PURE__ */ makeUInt64Fast(0x00000000, 0x8000808b), | ||
/* @__PURE__ */ makeUInt64Fast(0x80000000, 0x0000008b), | ||
/* @__PURE__ */ makeUInt64Fast(0x80000000, 0x00008089), | ||
/* @__PURE__ */ makeUInt64Fast(0x80000000, 0x00008003), | ||
/* @__PURE__ */ makeUInt64Fast(0x80000000, 0x00008002), | ||
/* @__PURE__ */ makeUInt64Fast(0x80000000, 0x00000080), | ||
/* @__PURE__ */ makeUInt64Fast(0x00000000, 0x0000800a), | ||
/* @__PURE__ */ makeUInt64Fast(0x80000000, 0x8000000a), | ||
/* @__PURE__ */ makeUInt64Fast(0x80000000, 0x80008081), | ||
/* @__PURE__ */ makeUInt64Fast(0x80000000, 0x00008080), | ||
/* @__PURE__ */ makeUInt64Fast(0x00000000, 0x80000001), | ||
/* @__PURE__ */ makeUInt64Fast(0x80000000, 0x80008008) | ||
] | ||
@@ -85,0 +85,0 @@ |
@@ -21,2 +21,2 @@ import { ShortAffineImpl } from "../../common/index.js" | ||
*/ | ||
export const affineCurve1 = new AffineCurve1Impl() | ||
export const affineCurve1 = (() => /* @__PURE__ */ new AffineCurve1Impl())() |
@@ -21,2 +21,2 @@ import { ShortAffineImpl } from "../../common/index.js" | ||
*/ | ||
export const affineCurve2 = new AffineCurve2Impl() | ||
export const affineCurve2 = (() => /* @__PURE__ */ new AffineCurve2Impl())() |
@@ -33,2 +33,3 @@ import { ShortProjectedImpl } from "../../common/index.js" | ||
*/ | ||
export const projectedCurve1 = new ProjectedCurve1Impl() | ||
export const projectedCurve1 = (() => | ||
/* @__PURE__ */ new ProjectedCurve1Impl())() |
@@ -7,3 +7,3 @@ import { ShortProjectedImpl } from "../../common/index.js" | ||
* @import { FieldElement12, Point3, ProjectedCurve2 } from "../../../index.js" | ||
* @import { FieldElement6, ShortProjected } from "../../../internal.js" | ||
* @import { FieldElement6 } from "../../../internal.js" | ||
*/ | ||
@@ -14,3 +14,3 @@ | ||
*/ | ||
const ut_root = [F2.ZERO, F2.ONE, F2.ZERO] | ||
const ut_root = /* @__PURE__ */ (() => [F2.ZERO, F2.ONE, F2.ZERO])() | ||
@@ -21,3 +21,3 @@ /** | ||
*/ | ||
const wsq = [ut_root, F6.ZERO] | ||
const wsq = [ut_root, /* @__PURE__ */ (() => F6.ZERO)()] | ||
@@ -28,6 +28,6 @@ /** | ||
*/ | ||
const wcu = [F6.ZERO, ut_root] | ||
const wcu = [/* @__PURE__ */ (() => F6.ZERO)(), ut_root] | ||
const wsq_inv = F12.invert(wsq) | ||
const wcu_inv = F12.invert(wcu) | ||
const wsq_inv = /* @__PURE__ */ F12.invert(wsq) | ||
const wcu_inv = /* @__PURE__ */ F12.invert(wcu) | ||
@@ -111,2 +111,3 @@ // 1 / F2(2)^((p-1)/3) in GF(p²) | ||
*/ | ||
export const projectedCurve2 = new ProjectedCurve2Impl() | ||
export const projectedCurve2 = (() => | ||
/* @__PURE__ */ new ProjectedCurve2Impl())() |
import { FieldWithOpsImpl, makeScalarField } from "../../common/index.js" | ||
import { CURVE1 } from "../constants.js" | ||
const P14 = (CURVE1.P + 1n) / 4n | ||
const P14 = /* @__PURE__ */ (() => (CURVE1.P + 1n) / 4n)() | ||
@@ -43,2 +43,2 @@ /** | ||
export const F1 = new FieldWithSqrt() | ||
export const F1 = (() => /* @__PURE__ */ new FieldWithSqrt())() |
@@ -108,2 +108,2 @@ import { FieldWithOpsImpl, makeQuadraticFieldExt } from "../../common/index.js" | ||
*/ | ||
export const F12 = new Field12WithExtendedOpsImpl() | ||
export const F12 = (() => /* @__PURE__ */ new Field12WithExtendedOpsImpl())() |
@@ -14,3 +14,3 @@ import { FieldWithOpsImpl, makeQuadraticFieldExt } from "../../common/index.js" | ||
const P_MINUS_9_DIV_16 = (CURVE1.P ** 2n - 9n) / 16n | ||
const P_MINUS_9_DIV_16 = /* @__PURE__ */ (() => (CURVE1.P ** 2n - 9n) / 16n)() | ||
@@ -32,3 +32,3 @@ // For Fp2 roots of unity. | ||
*/ | ||
const ROOTS_OF_UNITY = [ | ||
const ROOTS_OF_UNITY = /* @__PURE__ */ (() => [ | ||
[1n, 0n], | ||
@@ -42,3 +42,3 @@ [rv1, -rv1], | ||
[-rv1, -rv1] | ||
] | ||
])() | ||
@@ -48,3 +48,3 @@ /** | ||
*/ | ||
const ETAs = [ | ||
const ETAs = /* @__PURE__ */ (() => [ | ||
[ev1, ev2], | ||
@@ -54,3 +54,3 @@ [-ev2, ev1], | ||
[-ev4, ev3] | ||
] | ||
])() | ||
@@ -231,2 +231,2 @@ /** | ||
export const F2 = new FieldWithExtraOps() | ||
export const F2 = (() => /* @__PURE__ */ new FieldWithExtraOps())() |
@@ -101,2 +101,2 @@ import { makeCubicFieldExt, FieldWithOpsImpl } from "../../common/index.js" | ||
*/ | ||
export const F6 = new FieldWithPowp() | ||
export const F6 = (() => /* @__PURE__ */ new FieldWithPowp())() |
@@ -97,3 +97,3 @@ import { decodeIntBE, encodeIntBE } from "@helios-lang/codec-utils" | ||
const L = Math.ceil((381 + 128) / 8) | ||
const L = /* @__PURE__ */ (() => Math.ceil((381 + 128) / 8))() | ||
@@ -100,0 +100,0 @@ /** |
@@ -103,3 +103,3 @@ import { CURVE1 } from "./constants.js" | ||
const CURVEx = CURVE1.X | ||
const CURVEx = /* @__PURE__ */ (() => CURVE1.X)() | ||
@@ -106,0 +106,0 @@ /** |
/** | ||
* @import { AssertExtends } from "@helios-lang/type-utils" | ||
* @import { CubicFieldExt, FieldWithOps } from "../../internal.js" | ||
@@ -4,0 +3,0 @@ */ |
@@ -19,4 +19,4 @@ // Decimal representations of large numbers because that's most common in literature | ||
// Note: the negative number is already included in this parameter | ||
export const D = | ||
-4513249062541557337682894930092624173785641285191125241628941591882900924598840740n // -121665n/121666n == -121665n * invert(121666n) | ||
export const D = /* @__PURE__ */ (() => | ||
-4513249062541557337682894930092624173785641285191125241628941591882900924598840740n)() // -121665n/121666n == -121665n * invert(121666n) | ||
@@ -23,0 +23,0 @@ // Generator point |
@@ -181,2 +181,4 @@ import { sha2_512 } from "../../digest/index.js" | ||
*/ | ||
export const Ed25519 = makeEdDSA({ curve: new ExtendedCurveImpl() }) | ||
export const Ed25519 = /* @__PURE__ */ makeEdDSA({ | ||
curve: /* @__PURE__ */ new ExtendedCurveImpl() | ||
}) |
@@ -50,3 +50,3 @@ import { | ||
*/ | ||
export const F = new WithSqrtImpl() | ||
export const F = (() => /* @__PURE__ */ new WithSqrtImpl())() | ||
@@ -56,2 +56,4 @@ /** | ||
*/ | ||
export const Z = makeFieldWithOps(makeScalarField(N)) | ||
export const Z = /* @__PURE__ */ makeFieldWithOps( | ||
/* @__PURE__ */ makeScalarField(N) | ||
) |
@@ -11,2 +11,2 @@ import { ShortAffineImpl } from "../common/index.js" | ||
*/ | ||
export const affineCurve = new ShortAffineImpl(F, 7n) | ||
export const affineCurve = (() => /* @__PURE__ */ new ShortAffineImpl(F, 7n))() |
@@ -170,2 +170,3 @@ import { hmacDrbg } from "../../rand/index.js" | ||
*/ | ||
export const ECDSASecp256k1 = new ECDSAImpl(projectedCurve) | ||
export const ECDSASecp256k1 = (() => | ||
/* @__PURE__ */ new ECDSAImpl(projectedCurve))() |
@@ -41,3 +41,3 @@ import { | ||
export const F = new WithSqrt() | ||
export const F = (() => /* @__PURE__ */ new WithSqrt())() | ||
@@ -47,2 +47,4 @@ /** | ||
*/ | ||
export const Z = makeFieldWithOps(makeScalarField(N)) | ||
export const Z = /* @__PURE__ */ makeFieldWithOps( | ||
/* @__PURE__ */ makeScalarField(N) | ||
) |
@@ -11,2 +11,3 @@ import { ShortProjectedImpl } from "../common/index.js" | ||
*/ | ||
export const projectedCurve = new ShortProjectedImpl(F, 7n) | ||
export const projectedCurve = (() => | ||
/* @__PURE__ */ new ShortProjectedImpl(F, 7n))() |
@@ -215,2 +215,4 @@ import { encodeUtf8 } from "@helios-lang/codec-utils" | ||
*/ | ||
export const SchnorrSecp256k1 = makeSchnorr({ curve: projectedCurve }) | ||
export const SchnorrSecp256k1 = /* @__PURE__ */ makeSchnorr({ | ||
curve: projectedCurve | ||
}) |
/** | ||
* @import { AssertExtends } from "@helios-lang/type-utils" | ||
* @import { CubicFieldExt, FieldWithOps } from "../../internal.js" | ||
@@ -4,0 +3,0 @@ */ |
export const P: 57896044618658097711785492504343953926634992332820282019728792003956564819949n; | ||
export const N: 7237005577332262213973186563042994240857116359379907606001950938285454250989n; | ||
export const D: -4513249062541557337682894930092624173785641285191125241628941591882900924598840740n; | ||
export const D: bigint; | ||
export namespace G { | ||
@@ -5,0 +5,0 @@ let x: bigint; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
765444
0.16%8401
0.12%+ Added
- Removed