@kynesyslabs/demosdk 1.0.17 → 1.0.21
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/.eslintignore +6 -0
- package/.eslintrc.cjs +31 -0
- package/.gitattributes +4 -0
- package/.github/workflows/publish.yml +43 -0
- package/.github/workflows/test:multichain.yml +35 -0
- package/.gitignore +8 -0
- package/.prettierrc +13 -0
- package/build/encryption/FHE/index.js +0 -1
- package/build/encryption/FHE/index.js.map +1 -1
- package/build/encryption/PQC/index.d.ts +26 -1
- package/build/encryption/PQC/index.js +185 -2
- package/build/encryption/PQC/index.js.map +1 -1
- package/build/encryption/index.d.ts +2 -0
- package/build/encryption/index.js +3 -1
- package/build/encryption/index.js.map +1 -1
- package/build/encryption/zK/index.d.ts +1 -2
- package/build/encryption/zK/index.js +25 -3
- package/build/encryption/zK/index.js.map +1 -1
- package/build/encryption/zK/interactive/index.d.ts +16 -0
- package/build/encryption/zK/interactive/index.js +43 -0
- package/build/encryption/zK/interactive/index.js.map +1 -0
- package/build/encryption/zK/primer.d.ts +2 -0
- package/build/encryption/zK/primer.js +69 -0
- package/build/encryption/zK/primer.js.map +1 -0
- package/build/multichain/core/evm.d.ts +6 -6
- package/build/multichain/core/solana.d.ts +1 -1
- package/build/multichain/core/solana.js.map +1 -1
- package/build/multichain/core/xrp.js +0 -1
- package/build/multichain/core/xrp.js.map +1 -1
- package/build/multichain/localsdk/solana.d.ts +8 -0
- package/build/multichain/localsdk/solana.js +36 -0
- package/build/multichain/localsdk/solana.js.map +1 -0
- package/build/multichain/websdk/multiversx.d.ts +1 -1
- package/build/tests/multichain/chainProviders.d.ts +29 -0
- package/build/tests/multichain/chainProviders.js +34 -0
- package/build/tests/multichain/chainProviders.js.map +1 -0
- package/build/tests/multichain/evm.test.d.ts +1 -0
- package/build/tests/multichain/evm.test.js +53 -0
- package/build/tests/multichain/evm.test.js.map +1 -0
- package/build/tests/multichain/ibc.test.d.ts +1 -0
- package/build/tests/multichain/ibc.test.js +74 -0
- package/build/tests/multichain/ibc.test.js.map +1 -0
- package/build/tests/multichain/index.d.ts +1 -0
- package/build/tests/multichain/index.js +94 -0
- package/build/tests/multichain/index.js.map +1 -0
- package/build/tests/multichain/multiversx.test.d.ts +1 -0
- package/build/tests/multichain/multiversx.test.js +49 -0
- package/build/tests/multichain/multiversx.test.js.map +1 -0
- package/build/tests/multichain/solana.spec.d.ts +1 -0
- package/build/tests/multichain/solana.spec.js +50 -0
- package/build/tests/multichain/solana.spec.js.map +1 -0
- package/build/tests/multichain/template.test.d.ts +0 -0
- package/build/tests/multichain/template.test.js +33 -0
- package/build/tests/multichain/template.test.js.map +1 -0
- package/build/tests/multichain/xrpl.test.d.ts +1 -0
- package/build/tests/multichain/xrpl.test.js +57 -0
- package/build/tests/multichain/xrpl.test.js.map +1 -0
- package/build/tests/utils/index.d.ts +14 -0
- package/build/tests/utils/index.js +34 -0
- package/build/tests/utils/index.js.map +1 -0
- package/build/tests/utils/wallets.d.ts +21 -0
- package/build/tests/utils/wallets.js +48 -0
- package/build/tests/utils/wallets.js.map +1 -0
- package/build/tests/utils.test.d.ts +1 -0
- package/build/tests/utils.test.js +19 -0
- package/build/tests/utils.test.js.map +1 -0
- package/build/websdk/DemosWebAuth.d.ts +3 -3
- package/build/websdk/Web2Transactions.d.ts +1 -1
- package/build/websdk/demos.d.ts +4 -4
- package/build/websdk/rsa.d.ts +2 -2
- package/build/websdk/utils/skeletons.d.ts +10 -10
- package/documentation/multichain/README.md +85 -0
- package/documentation/multichain/ibc.md +3 -0
- package/documentation/multichain/solana.md +13 -0
- package/jest.config.ts +20 -0
- package/package.json +57 -49
- package/src/encryption/Cryptography.ts +128 -0
- package/src/encryption/FHE/index.ts +35 -0
- package/src/encryption/Hashing.ts +20 -0
- package/src/encryption/PQC/index.ts +260 -0
- package/src/encryption/index.ts +5 -0
- package/src/encryption/zK/index.ts +1 -0
- package/src/encryption/zK/interactive/index.ts +47 -0
- package/src/encryption/zK/primer.ts +71 -0
- package/src/index.ts +8 -0
- package/src/multichain/archive/btc.ts +72 -0
- package/src/multichain/archive/demos.ts +51 -0
- package/src/multichain/archive/tron.ts +86 -0
- package/src/multichain/archive/xlm.ts +65 -0
- package/src/multichain/core/README.md +1 -0
- package/src/multichain/core/evm.ts +275 -0
- package/src/multichain/core/ibc.ts +318 -0
- package/src/multichain/core/index.ts +29 -0
- package/src/multichain/core/multiversx.ts +310 -0
- package/src/multichain/core/solana.ts +336 -0
- package/src/multichain/core/types/defaultChain.ts +254 -0
- package/src/multichain/core/types/interfaces.ts +102 -0
- package/src/multichain/core/utils.ts +22 -0
- package/src/multichain/core/xrp.ts +253 -0
- package/src/multichain/index.ts +3 -0
- package/src/multichain/localsdk/README.md +1 -0
- package/src/multichain/localsdk/evm.ts +77 -0
- package/src/multichain/localsdk/ibc.ts +25 -0
- package/src/multichain/localsdk/index.ts +4 -0
- package/src/multichain/localsdk/multiversx.ts +66 -0
- package/src/multichain/localsdk/solana.ts +37 -0
- package/src/multichain/localsdk/xrp.ts +56 -0
- package/src/multichain/websdk/README.md +1 -0
- package/src/multichain/websdk/evm.ts +9 -0
- package/src/multichain/websdk/ibc.ts +10 -0
- package/src/multichain/websdk/index.ts +4 -0
- package/src/multichain/websdk/multiversx.ts +84 -0
- package/src/multichain/websdk/xrp.ts +9 -0
- package/src/tests/multichain/chainProviders.ts +32 -0
- package/src/tests/multichain/evm.test.ts +64 -0
- package/src/tests/multichain/ibc.test.ts +93 -0
- package/src/tests/multichain/index.ts +105 -0
- package/src/tests/multichain/multiversx.test.ts +57 -0
- package/src/tests/multichain/solana.spec.ts +56 -0
- package/src/tests/multichain/template.test.ts +37 -0
- package/src/tests/multichain/xrpl.test.ts +71 -0
- package/src/tests/utils/index.ts +34 -0
- package/src/tests/utils/wallets.ts +46 -0
- package/src/tests/utils.test.ts +21 -0
- package/src/types/blockchain/ISignature.ts +6 -0
- package/src/types/blockchain/Transaction.ts +34 -0
- package/src/types/blockchain/TxFee.ts +5 -0
- package/src/types/blockchain/ValidityData.ts +15 -0
- package/src/types/blockchain/addressInfo.ts +7 -0
- package/src/types/blockchain/blocks.ts +29 -0
- package/src/types/blockchain/genesisTypes.ts +39 -0
- package/src/types/blockchain/rawTransaction.ts +27 -0
- package/src/types/blockchain/statusNative.ts +6 -0
- package/src/types/blockchain/statusProperties.ts +8 -0
- package/src/types/communication/transmit.ts +27 -0
- package/src/types/gls/Operation.ts +25 -0
- package/src/types/gls/StateChange.ts +33 -0
- package/src/types/index.ts +60 -0
- package/src/types/network/ExecutionResult.ts +9 -0
- package/src/types/network/SecurityTypes.ts +18 -0
- package/src/types/peers/Peer.ts +18 -0
- package/src/types/web2/index.ts +76 -0
- package/src/types/xm/index.ts +21 -0
- package/src/utils/dataManipulation.ts +37 -0
- package/src/utils/index.ts +1 -0
- package/src/websdk/DemosTransactions.ts +74 -0
- package/src/websdk/DemosWebAuth.ts +186 -0
- package/src/websdk/Web2Transactions.ts +41 -0
- package/src/websdk/XMTransactions.ts +140 -0
- package/src/websdk/demos.ts +461 -0
- package/src/websdk/index.ts +15 -0
- package/src/websdk/rsa.ts +85 -0
- package/src/websdk/types/IBuffer.ts +4 -0
- package/src/websdk/types/KeyPair.ts +9 -0
- package/src/websdk/utils/bufferizer.ts +16 -0
- package/src/websdk/utils/forge_converter.ts +72 -0
- package/src/websdk/utils/required.ts +44 -0
- package/src/websdk/utils/sha256.ts +13 -0
- package/src/websdk/utils/skeletons.ts +69 -0
- package/tsconfig.json +34 -0
- package/yarn.lock +3705 -0
package/.eslintignore
ADDED
package/.eslintrc.cjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
env: {
|
|
3
|
+
commonjs: true,
|
|
4
|
+
es6: true,
|
|
5
|
+
node: true,
|
|
6
|
+
jest: true,
|
|
7
|
+
},
|
|
8
|
+
globals: {
|
|
9
|
+
NodeJS: "readonly",
|
|
10
|
+
},
|
|
11
|
+
extends: "eslint:recommended",
|
|
12
|
+
parserOptions: {
|
|
13
|
+
ecmaVersion: 2020,
|
|
14
|
+
sourceType: "module",
|
|
15
|
+
},
|
|
16
|
+
parser: "@typescript-eslint/parser",
|
|
17
|
+
plugins: ["@typescript-eslint"],
|
|
18
|
+
rules: {
|
|
19
|
+
// indent: ["error", 4, { SwitchCase: 1 }],
|
|
20
|
+
"linebreak-style": ["error", "unix"],
|
|
21
|
+
quotes: ["error", "double"],
|
|
22
|
+
semi: ["error", "never"],
|
|
23
|
+
// "no-console": "warn",
|
|
24
|
+
// no-unused-vars is disabled
|
|
25
|
+
"no-unused-vars": ["off"],
|
|
26
|
+
"switch-colon-spacing": ["error", { after: true, before: false }],
|
|
27
|
+
"no-extra-semi": "error",
|
|
28
|
+
"comma-dangle": ["error", "always-multiline"],
|
|
29
|
+
"no-restricted-imports": ["warn"],
|
|
30
|
+
},
|
|
31
|
+
}
|
package/.gitattributes
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
name: Build and Publish
|
|
2
|
+
|
|
3
|
+
# INFO: This workflow can't push to the repository
|
|
4
|
+
permissions: read-all
|
|
5
|
+
|
|
6
|
+
# INFO: Run workflow on changes to the sdks
|
|
7
|
+
on:
|
|
8
|
+
push:
|
|
9
|
+
branches:
|
|
10
|
+
- back-to-legacy-yarn
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build:
|
|
14
|
+
name: Build
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
if: startsWith(github.event.head_commit.message, 'release')
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v3
|
|
19
|
+
- name: Setup Node 18
|
|
20
|
+
uses: actions/setup-node@v3
|
|
21
|
+
with:
|
|
22
|
+
node-version: 18.x
|
|
23
|
+
always-auth: true
|
|
24
|
+
- name: Cache dependencies
|
|
25
|
+
uses: actions/cache@v3
|
|
26
|
+
with:
|
|
27
|
+
path: ~/.npm
|
|
28
|
+
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
|
|
29
|
+
restore-keys: |
|
|
30
|
+
${{ runner.os }}-node-
|
|
31
|
+
- name: Install dependencies
|
|
32
|
+
run: |
|
|
33
|
+
yarn install
|
|
34
|
+
- name: Build package
|
|
35
|
+
run: |
|
|
36
|
+
yarn build
|
|
37
|
+
- name: Create .npmrc
|
|
38
|
+
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_PUBLISH_KEY }}" > ~/.npmrc
|
|
39
|
+
- name: Publish 🎉
|
|
40
|
+
run: |
|
|
41
|
+
yarn publish
|
|
42
|
+
# env:
|
|
43
|
+
# NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_KEY }}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
name: Chain tests
|
|
2
|
+
|
|
3
|
+
# INFO: This workflow can't push to the repository
|
|
4
|
+
permissions: read-all
|
|
5
|
+
|
|
6
|
+
# INFO: Run workflow on changes to the sdks
|
|
7
|
+
on:
|
|
8
|
+
push:
|
|
9
|
+
paths:
|
|
10
|
+
- 'src/multichain/**'
|
|
11
|
+
- 'src/tests/multichain/**'
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
test:
|
|
15
|
+
name: XM Chain tests
|
|
16
|
+
runs-on: ubuntu-latest
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v3
|
|
19
|
+
- name: Setup Node 18
|
|
20
|
+
uses: actions/setup-node@v3
|
|
21
|
+
with:
|
|
22
|
+
node-version: 18.x
|
|
23
|
+
- name: Cache dependencies
|
|
24
|
+
uses: actions/cache@v3
|
|
25
|
+
with:
|
|
26
|
+
path: ~/.npm
|
|
27
|
+
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
|
|
28
|
+
restore-keys: |
|
|
29
|
+
${{ runner.os }}-node-
|
|
30
|
+
- name: Install dependencies
|
|
31
|
+
run: |
|
|
32
|
+
yarn install --frozen-lockfile
|
|
33
|
+
- name: Run tests
|
|
34
|
+
run: |
|
|
35
|
+
yarn test:multichain
|
package/.gitignore
ADDED
package/.prettierrc
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json.schemastore.org/prettierrc",
|
|
3
|
+
"arrowParens": "avoid",
|
|
4
|
+
"bracketSpacing": true,
|
|
5
|
+
"endOfLine": "lf",
|
|
6
|
+
"printWidth": 80,
|
|
7
|
+
"singleQuote": false,
|
|
8
|
+
"tabWidth": 4,
|
|
9
|
+
"semi": false,
|
|
10
|
+
"trailingComma": "all",
|
|
11
|
+
"useTabs": false,
|
|
12
|
+
"SwitchCase": 1
|
|
13
|
+
}
|
|
@@ -7,7 +7,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
// LINK https://s0l0ist.github.io/seal-sandbox/
|
|
8
8
|
const node_seal_1 = __importDefault(require("node-seal"));
|
|
9
9
|
// Initialize SEAL completely
|
|
10
|
-
// @ts-expect-error
|
|
11
10
|
let seal = null;
|
|
12
11
|
(async () => {
|
|
13
12
|
seal = await (0, node_seal_1.default)();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/encryption/FHE/index.ts"],"names":[],"mappings":";;;;;AAAA,+DAA+D;AAC/D,+CAA+C;AAC/C,0DAA4B;AAI5B,6BAA6B;AAC7B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/encryption/FHE/index.ts"],"names":[],"mappings":";;;;;AAAA,+DAA+D;AAC/D,+CAA+C;AAC/C,0DAA4B;AAI5B,6BAA6B;AAC7B,IAAI,IAAI,GAAgB,IAAI,CAAC;AAC7B,CAAC,KAAK,IAAG,EAAE;IACP,IAAI,GAAG,MAAM,IAAA,mBAAI,GAAE,CAAC;AACxB,CAAC,CAAC,EAAE,CAAC;AAEL,MAAqB,GAAG;IAUpB;QACI,wBAAwB;QACxB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;QACtC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,CAAA;QAC7C,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAA;QAC7B,IAAI,CAAC,QAAQ,GAAG,CAAC,EAAE,EAAC,EAAE,EAAC,EAAE,CAAC,CAAA;QAC1B,IAAI,CAAC,OAAO,GAAG,EAAE,CAAA;QACjB,+BAA+B;QAC/B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QACvD,0BAA0B;IAC9B,CAAC;CAEJ;AAtBD,sBAsBC"}
|
|
@@ -1,2 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export interface IKeypair {
|
|
3
|
+
privateKey: Uint8Array;
|
|
4
|
+
publicKey: Uint8Array;
|
|
5
|
+
}
|
|
6
|
+
export default class Enigma {
|
|
7
|
+
signingKeyPair: IKeypair;
|
|
8
|
+
mcelieceKeypair: IKeypair;
|
|
9
|
+
private kem;
|
|
10
|
+
constructor();
|
|
11
|
+
init(): Promise<void>;
|
|
12
|
+
combinedSign(message: string, additionalData?: string): Promise<Uint8Array>;
|
|
13
|
+
combinedVerify(signed: Uint8Array, publicKey: Uint8Array, additionalData?: string): Promise<Uint8Array>;
|
|
14
|
+
sign(message: string | Uint8Array, additionalData?: string | Uint8Array): Promise<Uint8Array>;
|
|
15
|
+
verify(signature: Uint8Array, message: string | Uint8Array, publicKey: Uint8Array, additionalData?: string | Uint8Array): Promise<boolean>;
|
|
16
|
+
exportSigningKeys(passphrase?: string): Promise<any>;
|
|
17
|
+
importSigningKeys(storage: any, passphrase?: string): Promise<any>;
|
|
18
|
+
generateSecrets(peerPublicKey: any): Promise<{
|
|
19
|
+
secret: any;
|
|
20
|
+
shared: any;
|
|
21
|
+
}>;
|
|
22
|
+
deriveSharedSecret(shared: any): Promise<any>;
|
|
23
|
+
hash(input: string | Buffer): Promise<string>;
|
|
24
|
+
checkHash(input: string | Buffer, hash: string): Promise<boolean>;
|
|
25
|
+
encrypt(input: string, key: string): Promise<Buffer>;
|
|
26
|
+
decrypt(input: Buffer, key: string): Promise<Buffer>;
|
|
2
27
|
}
|
|
@@ -1,6 +1,189 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
6
|
+
/* INFO Enigma - An experimental wrapper for Post Quantum Cryptography in Typescript designed with ease of use in mind
|
|
7
|
+
|
|
8
|
+
LICENSE
|
|
9
|
+
|
|
10
|
+
© 2023 by KyneSys Labs, licensed under CC BY-NC-ND 4.0
|
|
11
|
+
|
|
12
|
+
Full license text: https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode
|
|
13
|
+
Human readable license: https://creativecommons.org/licenses/by-nc-nd/4.0/
|
|
14
|
+
|
|
15
|
+
KyneSys Labs: https://www.kynesys.xyz/
|
|
16
|
+
|
|
17
|
+
This module incorporates two Post Quantum Cryptography methods:
|
|
18
|
+
- Rijndael: symmetric encryption algorithm considered the state of the art of its category
|
|
19
|
+
- Argon2: quantum-safe hashing algorithm
|
|
20
|
+
- McEliece: post-quantum cryptography algorithm that uses a keypair to share secrets between two parties.
|
|
21
|
+
- Dilithium: post-quantum cryptography algorithm that uses a keypair to sign and verify messages.
|
|
22
|
+
|
|
23
|
+
The Rijdael algorithm is a symmetric encryption algorithm and as many of the most used symmetric encryption algorithms
|
|
24
|
+
is considered to be quantum-safe. While even standard AES-256 is considered to be quantum-safe, the Rijndael algorithm
|
|
25
|
+
is considered to improve robustness, performance, and security when compared to standard AES-256 as AES specification
|
|
26
|
+
is a subset of Rijdael algorithm itself.
|
|
27
|
+
|
|
28
|
+
The Argon2 algorithm is a quantum-safe hashing algorithm that is designed to protect against various dehashing attacks.
|
|
29
|
+
It is used to replace less secure hashing algorithms such as SHA-1, SHA-256, and so on.
|
|
30
|
+
|
|
31
|
+
The McEliece algorithm is used to encrypt and decrypt messages, much like a symmetric classic encryption algorithm.
|
|
32
|
+
Thanks to its post-quantum security, however, it is not possible to retrieve the secrets as easily as with a classic algorithm.
|
|
33
|
+
We use McEliece to exchange a long-term secret between two parties. This secret will be the base to generate one-time secrets
|
|
34
|
+
encrypted with McEliece itself that will be used to generate one-time symmetric keys.
|
|
35
|
+
|
|
36
|
+
The Dilithium algorithm is used to sign and verify messages, much like algorithms like ed25519.
|
|
37
|
+
Apart from providing post quantum security, the Dilithium algorithm is also capable of generating combined signed messages
|
|
38
|
+
that can be used to verify signatures without sharing the initial message, as proofs of authenticity.
|
|
39
|
+
|
|
40
|
+
Credits:
|
|
41
|
+
- https://github.com/Snack-X for https://github.com/Snack-X/rijndael-js
|
|
42
|
+
- https://github.com/ranisalt for https://github.com/ranisalt/node-argon2
|
|
43
|
+
- https://github.com/cyph for its https://github.com/cyph/pqcrypto.js library (superdilithium, supersphincs and a lot of knowledge)
|
|
44
|
+
- https://github.com/tniessen for its https://github.com/tniessen/node-mceliece-nist library (mceliece and a lot of knowledge too)
|
|
45
|
+
- I can't find the ntru library developer unfortunately, feel free to contact me if its you
|
|
46
|
+
|
|
47
|
+
*/
|
|
48
|
+
const argon2_1 = __importDefault(require("argon2"));
|
|
49
|
+
// import { superSphincs } from "supersphincs" // Same as above, just replace the two strings
|
|
50
|
+
const mceliece_nist_1 = require("mceliece-nist");
|
|
51
|
+
const rijndael_js_1 = __importDefault(require("rijndael-js"));
|
|
52
|
+
const superdilithium_1 = require("superdilithium");
|
|
53
|
+
// INFO Main class
|
|
54
|
+
class Enigma {
|
|
55
|
+
constructor() {
|
|
56
|
+
this.signingKeyPair = null;
|
|
57
|
+
this.mcelieceKeypair = null;
|
|
58
|
+
this.kem = new mceliece_nist_1.McEliece("mceliece8192128");
|
|
59
|
+
}
|
|
60
|
+
async init() {
|
|
61
|
+
this.signingKeyPair = await superdilithium_1.superDilithium.keyPair();
|
|
62
|
+
this.mcelieceKeypair = this.kem.keypair();
|
|
63
|
+
}
|
|
64
|
+
/* SECTION Signatures with superDilithium */
|
|
65
|
+
async combinedSign(message, additionalData = null) {
|
|
66
|
+
let bufMessage = Buffer.from(message, "utf8");
|
|
67
|
+
let signed;
|
|
68
|
+
if (additionalData) {
|
|
69
|
+
let bufAdditionalData = Buffer.from(additionalData, "utf8");
|
|
70
|
+
signed = await superdilithium_1.superDilithium.sign(bufMessage, this.signingKeyPair.privateKey, bufAdditionalData);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
signed = await superdilithium_1.superDilithium.sign(bufMessage, this.signingKeyPair.privateKey);
|
|
74
|
+
}
|
|
75
|
+
return signed;
|
|
76
|
+
}
|
|
77
|
+
async combinedVerify(signed, publicKey, additionalData = null) {
|
|
78
|
+
let verifyData;
|
|
79
|
+
if (additionalData) {
|
|
80
|
+
let bufAdditionalData = Buffer.from(additionalData, "utf8");
|
|
81
|
+
verifyData = await superdilithium_1.superDilithium.open(signed, publicKey, bufAdditionalData);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
verifyData = await superdilithium_1.superDilithium.open(signed, publicKey);
|
|
85
|
+
}
|
|
86
|
+
return verifyData;
|
|
87
|
+
}
|
|
88
|
+
async sign(message, additionalData = null) {
|
|
89
|
+
if (typeof message === "string") {
|
|
90
|
+
message = Buffer.from(message, "utf8");
|
|
91
|
+
}
|
|
92
|
+
if (typeof additionalData === "string") {
|
|
93
|
+
additionalData = Buffer.from(additionalData, "utf8");
|
|
94
|
+
}
|
|
95
|
+
// Signing
|
|
96
|
+
let signed;
|
|
97
|
+
if (additionalData) {
|
|
98
|
+
signed = await superdilithium_1.superDilithium.signDetached(message, this.signingKeyPair.privateKey, additionalData);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
signed = await superdilithium_1.superDilithium.signDetached(message, this.signingKeyPair.privateKey);
|
|
102
|
+
}
|
|
103
|
+
return signed;
|
|
104
|
+
}
|
|
105
|
+
async verify(signature, message, publicKey, additionalData = null) {
|
|
106
|
+
if (typeof message === "string") {
|
|
107
|
+
message = Buffer.from(message, "utf8");
|
|
108
|
+
}
|
|
109
|
+
if (typeof additionalData === "string") {
|
|
110
|
+
additionalData = Buffer.from(additionalData, "utf8");
|
|
111
|
+
}
|
|
112
|
+
// Verifying
|
|
113
|
+
let verified;
|
|
114
|
+
if (additionalData) {
|
|
115
|
+
verified = await superdilithium_1.superDilithium.verifyDetached(signature, message, publicKey, additionalData);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
verified = await superdilithium_1.superDilithium.verifyDetached(signature, message, publicKey);
|
|
119
|
+
}
|
|
120
|
+
return verified;
|
|
121
|
+
}
|
|
122
|
+
async exportSigningKeys(passphrase = null) {
|
|
123
|
+
let storage;
|
|
124
|
+
if (passphrase) {
|
|
125
|
+
storage = await superdilithium_1.superDilithium.exportKeys(this.signingKeyPair, passphrase);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
storage = await superdilithium_1.superDilithium.exportKeys(this.signingKeyPair);
|
|
129
|
+
}
|
|
130
|
+
return storage;
|
|
131
|
+
}
|
|
132
|
+
async importSigningKeys(storage, passphrase = null) {
|
|
133
|
+
if (passphrase) {
|
|
134
|
+
this.signingKeyPair = await superdilithium_1.superDilithium.importKeys(storage, passphrase);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
this.signingKeyPair = await superdilithium_1.superDilithium.importKeys(storage);
|
|
138
|
+
}
|
|
139
|
+
return this.signingKeyPair;
|
|
140
|
+
}
|
|
141
|
+
/* SECTION Keys generation and incapsulation with McEliece */
|
|
142
|
+
// Incapsulate a secret with a public key
|
|
143
|
+
async generateSecrets(peerPublicKey) {
|
|
144
|
+
let { key, encryptedKey } = await this.kem.generateKey(peerPublicKey);
|
|
145
|
+
let normalizedResult = {
|
|
146
|
+
secret: key,
|
|
147
|
+
shared: encryptedKey,
|
|
148
|
+
};
|
|
149
|
+
return normalizedResult;
|
|
150
|
+
}
|
|
151
|
+
// Decapsulate a secret from a shared secret
|
|
152
|
+
async deriveSharedSecret(shared) {
|
|
153
|
+
let secret = await this.kem.decryptKey(this.mcelieceKeypair.privateKey, shared);
|
|
154
|
+
return secret;
|
|
155
|
+
}
|
|
156
|
+
/* SECTION Hashing with Argon2 */
|
|
157
|
+
async hash(input) {
|
|
158
|
+
if (typeof input === "string") {
|
|
159
|
+
input = Buffer.from(input, "utf8");
|
|
160
|
+
}
|
|
161
|
+
let hash = await argon2_1.default.hash(input);
|
|
162
|
+
return hash;
|
|
163
|
+
}
|
|
164
|
+
async checkHash(input, hash) {
|
|
165
|
+
if (typeof input === "string") {
|
|
166
|
+
input = Buffer.from(input, "utf8");
|
|
167
|
+
}
|
|
168
|
+
if (await argon2_1.default.verify(hash, input)) {
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/* SECTION Symmetric encryption and decryption with Rijndael */
|
|
176
|
+
async encrypt(input, key) {
|
|
177
|
+
// Key can be 16/24/32 bytes long (128/192/256 bit)
|
|
178
|
+
let cipher = new rijndael_js_1.default(key, "cbc");
|
|
179
|
+
let ciphertext = Buffer.from(cipher.encrypt(input, "256", "Ut enim ad minim veniam, quis no")); // TODO Custom iv same block size
|
|
180
|
+
return ciphertext;
|
|
181
|
+
}
|
|
182
|
+
async decrypt(input, key) {
|
|
183
|
+
let cipher = new rijndael_js_1.default(key, "cbc");
|
|
184
|
+
let plainbuffer = Buffer.from(cipher.decrypt(input, "256", "Ut enim ad minim veniam, quis no"));
|
|
185
|
+
return plainbuffer;
|
|
186
|
+
}
|
|
4
187
|
}
|
|
5
|
-
exports.default =
|
|
188
|
+
exports.default = Enigma;
|
|
6
189
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/encryption/PQC/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/encryption/PQC/index.ts"],"names":[],"mappings":";;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyCE;AACF,oDAA2B;AAC3B,6FAA6F;AAC7F,iDAAwC;AACxC,8DAAkC;AAClC,mDAA+C;AAU/C,kBAAkB;AAClB,MAAqB,MAAM;IAMvB;QALA,mBAAc,GAAa,IAAI,CAAA;QAC/B,oBAAe,GAAa,IAAI,CAAA;QAExB,QAAG,GAAa,IAAI,wBAAQ,CAAC,iBAAiB,CAAC,CAAA;IAExC,CAAC;IAEhB,KAAK,CAAC,IAAI;QACN,IAAI,CAAC,cAAc,GAAG,MAAM,+BAAc,CAAC,OAAO,EAAE,CAAA;QACpD,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAA;IAC7C,CAAC;IAED,4CAA4C;IAE5C,KAAK,CAAC,YAAY,CACd,OAAe,EACf,iBAAyB,IAAI;QAE7B,IAAI,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;QAC7C,IAAI,MAAkB,CAAA;QACtB,IAAI,cAAc,EAAE,CAAC;YACjB,IAAI,iBAAiB,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,CAAA;YAC3D,MAAM,GAAG,MAAM,+BAAc,CAAC,IAAI,CAC9B,UAAU,EACV,IAAI,CAAC,cAAc,CAAC,UAAU,EAC9B,iBAAiB,CACpB,CAAA;QACL,CAAC;aAAM,CAAC;YACJ,MAAM,GAAG,MAAM,+BAAc,CAAC,IAAI,CAC9B,UAAU,EACV,IAAI,CAAC,cAAc,CAAC,UAAU,CACjC,CAAA;QACL,CAAC;QACD,OAAO,MAAM,CAAA;IACjB,CAAC;IAED,KAAK,CAAC,cAA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mD;QACnD,IAAI,MAAM,GAAG,IAAI,qBAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;QACrC,IAAI,UAAU,GAAG,MAAM,CAAC,IAAI,CACxB,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,kCAAkC,CAAC,CACnE,CAAA,CAAC,iCAAiC;QACnC,OAAO,UAAU,CAAA;IACrB,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,KAAa,EAAE,GAAW;QACpC,IAAI,MAAM,GAAG,IAAI,qBAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;QACrC,IAAI,WAAW,GAAG,MAAM,CAAC,IAAI,CACzB,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,kCAAkC,CAAC,CACnE,CAAA;QACD,OAAO,WAAW,CAAA;IACtB,CAAC;CACJ;AA1MD,yBA0MC"}
|
|
@@ -23,8 +23,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.zK = exports.PQC = exports.FHE = void 0;
|
|
26
|
+
exports.Hashing = exports.Cryptography = exports.zK = exports.PQC = exports.FHE = void 0;
|
|
27
27
|
exports.FHE = __importStar(require("./FHE"));
|
|
28
28
|
exports.PQC = __importStar(require("./PQC"));
|
|
29
29
|
exports.zK = __importStar(require("./zK"));
|
|
30
|
+
exports.Cryptography = __importStar(require("./Cryptography"));
|
|
31
|
+
exports.Hashing = __importStar(require("./Hashing"));
|
|
30
32
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/encryption/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA4B;AAC5B,6CAA4B;AAC5B,2CAA0B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/encryption/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA4B;AAC5B,6CAA4B;AAC5B,2CAA0B;AAC1B,+DAA8C;AAC9C,qDAAoC"}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
}
|
|
1
|
+
export * as interactive from './interactive';
|
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
exports.default = zK;
|
|
26
|
+
exports.interactive = void 0;
|
|
27
|
+
exports.interactive = __importStar(require("./interactive")); // interactive.Prover and interactive.Verifier
|
|
6
28
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/encryption/zK/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/encryption/zK/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6DAA4C,CAAC,8CAA8C"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import bigInt from "big-integer";
|
|
2
|
+
export declare class Prover {
|
|
3
|
+
private secret;
|
|
4
|
+
modulus: any;
|
|
5
|
+
private randomValue;
|
|
6
|
+
constructor(prime1: any, prime2: any, secret: bigInt.BigInteger);
|
|
7
|
+
generateCommitment(): any;
|
|
8
|
+
respondToChallenge(challenge: number): any;
|
|
9
|
+
}
|
|
10
|
+
export declare class Verifier {
|
|
11
|
+
private modulus;
|
|
12
|
+
private commitment;
|
|
13
|
+
constructor(modulus: any);
|
|
14
|
+
generateChallenge(commitment: any): number;
|
|
15
|
+
verifyResponse(response: any, challenge: number): boolean;
|
|
16
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Verifier = exports.Prover = void 0;
|
|
7
|
+
const big_integer_1 = __importDefault(require("big-integer"));
|
|
8
|
+
class Prover {
|
|
9
|
+
constructor(prime1, prime2, secret) {
|
|
10
|
+
this.modulus = prime1.multiply(prime2);
|
|
11
|
+
this.secret = secret;
|
|
12
|
+
}
|
|
13
|
+
generateCommitment() {
|
|
14
|
+
this.randomValue = big_integer_1.default.randBetween(2, this.modulus.subtract(2));
|
|
15
|
+
return this.randomValue.modPow(2, this.modulus);
|
|
16
|
+
}
|
|
17
|
+
respondToChallenge(challenge) {
|
|
18
|
+
return challenge === 0
|
|
19
|
+
? this.randomValue
|
|
20
|
+
: this.randomValue.multiply(this.secret).mod(this.modulus);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.Prover = Prover;
|
|
24
|
+
class Verifier {
|
|
25
|
+
constructor(modulus) {
|
|
26
|
+
this.modulus = modulus;
|
|
27
|
+
}
|
|
28
|
+
generateChallenge(commitment) {
|
|
29
|
+
this.commitment = commitment;
|
|
30
|
+
return Math.round(Math.random());
|
|
31
|
+
}
|
|
32
|
+
verifyResponse(response, challenge) {
|
|
33
|
+
const responseSquared = response.modPow(2, this.modulus);
|
|
34
|
+
if (challenge === 0) {
|
|
35
|
+
return responseSquared.equals(this.commitment);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return !responseSquared.equals(this.commitment);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.Verifier = Verifier;
|
|
43
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/encryption/zK/interactive/index.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAgC;AAGhC,MAAa,MAAM;IAKf,YAAY,MAAW,EAAE,MAAW,EAAE,MAAyB;QAC3D,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;QACtC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACxB,CAAC;IAED,kBAAkB;QACd,IAAI,CAAC,WAAW,GAAG,qBAAM,CAAC,WAAW,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAA;QAClE,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;IACnD,CAAC;IAED,kBAAkB,CAAC,SAAiB;QAChC,OAAO,SAAS,KAAK,CAAC;YAClB,CAAC,CAAC,IAAI,CAAC,WAAW;YAClB,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAClE,CAAC;CACJ;AApBD,wBAoBC;AAED,MAAa,QAAQ;IAIjB,YAAY,OAAY;QACpB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IAC1B,CAAC;IAED,iBAAiB,CAAC,UAAe;QAC7B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAA;IACpC,CAAC;IAED,cAAc,CAAC,QAAa,EAAE,SAAiB;QAC3C,MAAM,eAAe,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;QACxD,IAAI,SAAS,KAAK,CAAC,EAAE,CAAC;YAClB,OAAO,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QAClD,CAAC;aAAM,CAAC;YACJ,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QACnD,CAAC;IACL,CAAC;CACJ;AArBD,4BAqBC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const big_integer_1 = __importDefault(require("big-integer"));
|
|
7
|
+
function isSmallPrimeDivisorPresent(n) {
|
|
8
|
+
const smallPrimes = [
|
|
9
|
+
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,
|
|
10
|
+
71, 73, 79, 83, 89, 97,
|
|
11
|
+
];
|
|
12
|
+
for (const prime of smallPrimes) {
|
|
13
|
+
if (n.mod(prime).isZero()) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
function millerRabinTest(n, k) {
|
|
20
|
+
if (n.leq(1) || n.equals(2))
|
|
21
|
+
return n.equals(2);
|
|
22
|
+
if (n.isEven())
|
|
23
|
+
return false;
|
|
24
|
+
// Optimization: Check for small prime divisors first
|
|
25
|
+
if (isSmallPrimeDivisorPresent(n))
|
|
26
|
+
return false;
|
|
27
|
+
let r = 0;
|
|
28
|
+
let d = n.minus(1);
|
|
29
|
+
const two = (0, big_integer_1.default)(2);
|
|
30
|
+
// Precompute values
|
|
31
|
+
const nMinusOne = n.minus(1);
|
|
32
|
+
const nMinusTwo = n.minus(2);
|
|
33
|
+
while (d.isEven()) {
|
|
34
|
+
r++;
|
|
35
|
+
d = d.divide(two);
|
|
36
|
+
}
|
|
37
|
+
for (let i = 0; i < k; i++) {
|
|
38
|
+
const a = big_integer_1.default.randBetween(two, nMinusTwo);
|
|
39
|
+
let x = a.modPow(d, n);
|
|
40
|
+
if (x.equals(1) || x.equals(nMinusOne))
|
|
41
|
+
continue;
|
|
42
|
+
let continueLoop = false;
|
|
43
|
+
for (let j = 0; j < r - 1; j++) {
|
|
44
|
+
x = x.modPow(two, n);
|
|
45
|
+
if (x.equals(nMinusOne)) {
|
|
46
|
+
continueLoop = true;
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (continueLoop)
|
|
51
|
+
continue;
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
function generateLargePrime(bits, testRounds) {
|
|
57
|
+
if (bits < 2)
|
|
58
|
+
throw new Error("Bit-length must be >= 2");
|
|
59
|
+
// Precompute powers of two
|
|
60
|
+
const twoPowBitsMinusOne = (0, big_integer_1.default)(2).pow(bits - 1);
|
|
61
|
+
const twoPowBits = (0, big_integer_1.default)(2).pow(bits);
|
|
62
|
+
let prime;
|
|
63
|
+
do {
|
|
64
|
+
prime = big_integer_1.default.randBetween(twoPowBitsMinusOne, twoPowBits.subtract(1));
|
|
65
|
+
} while (!millerRabinTest(prime, testRounds));
|
|
66
|
+
return prime;
|
|
67
|
+
}
|
|
68
|
+
exports.default = generateLargePrime;
|
|
69
|
+
//# sourceMappingURL=primer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"primer.js","sourceRoot":"","sources":["../../../../src/encryption/zK/primer.ts"],"names":[],"mappings":";;;;;AAAA,8DAAgD;AAEhD,SAAS,0BAA0B,CAAC,CAAa;IAC7C,MAAM,WAAW,GAAG;QAChB,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE;QACtE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE;KACzB,CAAA;IACD,KAAK,MAAM,KAAK,IAAI,WAAW,EAAE,CAAC;QAC9B,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;YACxB,OAAO,IAAI,CAAA;QACf,CAAC;IACL,CAAC;IACD,OAAO,KAAK,CAAA;AAChB,CAAC;AAED,SAAS,eAAe,CAAC,CAAa,EAAE,CAAS;IAC7C,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IAC/C,IAAI,CAAC,CA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ACnB,MAAK;YACT,CAAC;QACL,CAAC;QACD,IAAI,YAAY;YAAE,SAAQ;QAC1B,OAAO,KAAK,CAAA;IAChB,CAAC;IACD,OAAO,IAAI,CAAA;AACf,CAAC;AAED,SAAwB,kBAAkB,CACtC,IAAY,EACZ,UAAkB;IAElB,IAAI,IAAI,GAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;IAExD,2BAA2B;IAC3B,MAAM,kBAAkB,GAAG,IAAA,qBAAM,EAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,CAAA;IAClD,MAAM,UAAU,GAAG,IAAA,qBAAM,EAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAEtC,IAAI,KAAiB,CAAA;IACrB,GAAG,CAAC;QACA,KAAK,GAAG,qBAAM,CAAC,WAAW,CAAC,kBAAkB,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAA;IAC1E,CAAC,QAAQ,CAAC,eAAe,CAAC,KAAK,EAAE,UAAU,CAAC,EAAC;IAE7C,OAAO,KAAK,CAAA;AAChB,CAAC;AAhBD,qCAgBC"}
|
|
@@ -23,23 +23,23 @@ export declare class EVM extends DefaultChain implements IEVMDefaultChain {
|
|
|
23
23
|
prepareTransfers(payments: IPayOptions[]): Promise<string[]>;
|
|
24
24
|
prepareBaseTxWithType(): Promise<{
|
|
25
25
|
type: number;
|
|
26
|
-
maxFeePerGas: bigint
|
|
27
|
-
maxPriorityFeePerGas: bigint
|
|
26
|
+
maxFeePerGas: bigint;
|
|
27
|
+
maxPriorityFeePerGas: bigint;
|
|
28
28
|
gasLimit: number;
|
|
29
29
|
chainId: number;
|
|
30
30
|
} | {
|
|
31
|
-
gasPrice: bigint
|
|
31
|
+
gasPrice: bigint;
|
|
32
32
|
gasLimit: number;
|
|
33
33
|
chainId: number;
|
|
34
34
|
}>;
|
|
35
35
|
getEmptyTransaction(): Promise<{
|
|
36
36
|
type: number;
|
|
37
|
-
maxFeePerGas: bigint
|
|
38
|
-
maxPriorityFeePerGas: bigint
|
|
37
|
+
maxFeePerGas: bigint;
|
|
38
|
+
maxPriorityFeePerGas: bigint;
|
|
39
39
|
gasLimit: number;
|
|
40
40
|
chainId: number;
|
|
41
41
|
} | {
|
|
42
|
-
gasPrice: bigint
|
|
42
|
+
gasPrice: bigint;
|
|
43
43
|
gasLimit: number;
|
|
44
44
|
chainId: number;
|
|
45
45
|
}>;
|
|
@@ -33,7 +33,7 @@ export declare class SOLANA extends DefaultChain implements SolanaDefaultChain {
|
|
|
33
33
|
getBalance(address: string): Promise<string>;
|
|
34
34
|
info(): Promise<string>;
|
|
35
35
|
signTransaction(tx: Transaction, options?: SignTxOptions): Promise<Transaction>;
|
|
36
|
-
readNonce(address: string): Promise<NonceAccount
|
|
36
|
+
readNonce(address: string): Promise<NonceAccount>;
|
|
37
37
|
createNonceAccount(): Promise<string>;
|
|
38
38
|
signTransactions(transactions: Transaction[], options?: SignTxOptions): Promise<Transaction[]>;
|
|
39
39
|
getAddress(): string;
|