mirror of
https://github.com/Hmac512/typescript-mpc-tls.git
synced 2026-01-09 12:08:01 -05:00
initial commit
This commit is contained in:
3
.env
Normal file
3
.env
Normal file
@@ -0,0 +1,3 @@
|
||||
# Local env vars for debugging
|
||||
TS_NODE_IGNORE="false"
|
||||
TS_NODE_FILES="true"
|
||||
1
.eslintignore
Normal file
1
.eslintignore
Normal file
@@ -0,0 +1 @@
|
||||
src/types/global.d.ts
|
||||
32
.eslintrc.js
Normal file
32
.eslintrc.js
Normal file
@@ -0,0 +1,32 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
parser: '@typescript-eslint/parser',
|
||||
plugins: ['@typescript-eslint', 'node', 'prettier'],
|
||||
parserOptions: {
|
||||
tsconfigRootDir: __dirname,
|
||||
project: ['./tsconfig.json'],
|
||||
},
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:node/recommended',
|
||||
'plugin:@typescript-eslint/eslint-recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:@typescript-eslint/recommended-requiring-type-checking',
|
||||
'plugin:prettier/recommended',
|
||||
],
|
||||
rules: {
|
||||
'prettier/prettier': 'warn',
|
||||
'node/no-missing-import': 'off',
|
||||
'node/no-empty-function': 'off',
|
||||
'node/no-unsupported-features/es-syntax': 'off',
|
||||
'node/no-missing-require': 'off',
|
||||
'node/shebang': 'off',
|
||||
'@typescript-eslint/no-use-before-define': 'off',
|
||||
quotes: ['warn', 'single', { avoidEscape: true }],
|
||||
'node/no-unpublished-import': 'off',
|
||||
'@typescript-eslint/no-unsafe-assignment': 'off',
|
||||
'@typescript-eslint/no-var-requires': 'off',
|
||||
'@typescript-eslint/ban-ts-comment': 'off',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
},
|
||||
};
|
||||
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
# Set the repository to show as TypeScript rather than JS in GitHub
|
||||
*.js linguist-detectable=false
|
||||
28
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
28
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
---
|
||||
name: "🐛 Bug Report"
|
||||
about: Report a reproducible bug or regression.
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
## Current Behavior
|
||||
|
||||
<!-- Describe how the issue manifests. -->
|
||||
|
||||
## Expected Behavior
|
||||
|
||||
<!-- Describe what the desired behavior would be. -->
|
||||
|
||||
## Steps to Reproduce the Problem
|
||||
|
||||
1.
|
||||
1.
|
||||
1.
|
||||
|
||||
## Environment
|
||||
|
||||
- Version: <!-- Version set in package.json -->
|
||||
- Platform: <!-- Win/Mac/Linux -->
|
||||
- Node.js Version: <!-- Output of running `node -v` -->
|
||||
34
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
34
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
---
|
||||
name: 🌈 Feature request
|
||||
about: Suggest an amazing new idea for this project
|
||||
title: ''
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
## Feature Request
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
<!-- A clear and concise description of what the problem is. Ex. I have an issue when [...] -->
|
||||
|
||||
**Describe the solution you'd like**
|
||||
<!-- A clear and concise description of what you want to happen. Add any considered drawbacks. -->
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
<!-- A clear and concise description of any alternative solutions or features you've considered. -->
|
||||
|
||||
## Are you willing to resolve this issue by submitting a Pull Request?
|
||||
|
||||
<!--
|
||||
Remember that first-time contributors are welcome! 🙌
|
||||
-->
|
||||
|
||||
- [ ] Yes, I have the time, and I know how to start.
|
||||
- [ ] Yes, I have the time, but I don't know how to start. I would need guidance.
|
||||
- [ ] No, I don't have the time, although I believe I could do it if I had the time...
|
||||
- [ ] No, I don't have the time and I wouldn't even know how to start.
|
||||
|
||||
<!--
|
||||
👋 Have a great day and thank you for the feature request!
|
||||
-->
|
||||
42
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
42
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
<!--
|
||||
😀 Wonderful! Thank you for opening a pull request.
|
||||
|
||||
Please fill in the information below to expedite the review
|
||||
and (hopefully) merge of your change.
|
||||
-->
|
||||
|
||||
### Description of change
|
||||
|
||||
<!--
|
||||
Please be clear and concise what the change is intended to do,
|
||||
why this change is needed, and how you've verified that it
|
||||
corrects what you intended.
|
||||
|
||||
In some cases it may be helpful to include the current behavior
|
||||
and the new behavior.
|
||||
|
||||
If the change is related to an open issue, you can link it here.
|
||||
If you include `Fixes #0000` (replacing `0000` with the issue number)
|
||||
when this is merged it will automatically mark the issue as fixed and
|
||||
close it.
|
||||
-->
|
||||
|
||||
### Pull-Request Checklist
|
||||
|
||||
<!--
|
||||
Please make sure to review and check all of the following.
|
||||
|
||||
If an item is not applicable, you can add "N/A" to the end.
|
||||
-->
|
||||
|
||||
- [ ] Code is up-to-date with the `main` branch
|
||||
- [ ] `npm run lint` passes with this change
|
||||
- [ ] `npm run test` passes with this change
|
||||
- [ ] This pull request links relevant issues as `Fixes #0000`
|
||||
- [ ] There are new or updated unit tests validating the change
|
||||
- [ ] Documentation has been updated to reflect this change
|
||||
- [ ] The new commits follow conventions outlined in the [conventional commit spec](https://www.conventionalcommits.org/en/v1.0.0/)
|
||||
|
||||
<!--
|
||||
🎉 Thank you for contributing!
|
||||
-->
|
||||
21
.github/workflows/codeql-analysis.yml
vendored
Normal file
21
.github/workflows/codeql-analysis.yml
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
# Reusable workflow for code analysis; to eject, you can replace this file with
|
||||
# https://github.com/ryansonshine/ryansonshine/blob/main/.github/workflows/codeql-analysis.yml
|
||||
name: "CodeQL"
|
||||
|
||||
permissions:
|
||||
security-events: write
|
||||
actions: read
|
||||
contents: read
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [main]
|
||||
schedule:
|
||||
- cron: "36 7 * * 6"
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
uses: ryansonshine/ryansonshine/.github/workflows/codeql-analysis.yml@main
|
||||
9
.github/workflows/pr.yml
vendored
Normal file
9
.github/workflows/pr.yml
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
# Reusable workflow for PRs; to eject, you can replace this file with
|
||||
# https://github.com/ryansonshine/ryansonshine/blob/main/.github/workflows/pr.yml
|
||||
name: Pull Request
|
||||
|
||||
on: [pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
uses: ryansonshine/ryansonshine/.github/workflows/pr.yml@main
|
||||
16
.github/workflows/release.yml
vendored
Normal file
16
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
# Reusable workflow for releases; to eject, you can replace this file with
|
||||
# https://github.com/ryansonshine/ryansonshine/blob/main/.github/workflows/release.yml
|
||||
name: Release
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
jobs:
|
||||
release:
|
||||
permissions:
|
||||
contents: write
|
||||
issues: write
|
||||
pull-requests: write
|
||||
uses: ryansonshine/ryansonshine/.github/workflows/release.yml@main
|
||||
secrets:
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
1
.husky/.gitignore
vendored
Normal file
1
.husky/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
_
|
||||
4
.husky/pre-commit
Executable file
4
.husky/pre-commit
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
npx lint-staged
|
||||
4
.husky/prepare-commit-msg
Executable file
4
.husky/prepare-commit-msg
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
exec </dev/tty && node_modules/.bin/cz --hook || true
|
||||
4
.prettierrc
Normal file
4
.prettierrc
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"tabWidth": 2,
|
||||
"useTabs": false
|
||||
}
|
||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 Ryan Sonshine
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
117
README.md
Normal file
117
README.md
Normal file
@@ -0,0 +1,117 @@
|
||||
# typescript-npm-package-template
|
||||
|
||||
> Template to kickstart creating a Node.js module using TypeScript and VSCode
|
||||
|
||||
Inspired by [node-module-boilerplate](https://github.com/sindresorhus/node-module-boilerplate)
|
||||
|
||||
## Features
|
||||
|
||||
- [Semantic Release](https://github.com/semantic-release/semantic-release)
|
||||
- [Issue Templates](https://github.com/ryansonshine/typescript-npm-package-template/tree/main/.github/ISSUE_TEMPLATE)
|
||||
- [GitHub Actions](https://github.com/ryansonshine/typescript-npm-package-template/tree/main/.github/workflows)
|
||||
- [Codecov](https://about.codecov.io/)
|
||||
- [VSCode Launch Configurations](https://github.com/ryansonshine/typescript-npm-package-template/blob/main/.vscode/launch.json)
|
||||
- [TypeScript](https://www.typescriptlang.org/)
|
||||
- [Husky](https://github.com/typicode/husky)
|
||||
- [Lint Staged](https://github.com/okonet/lint-staged)
|
||||
- [Commitizen](https://github.com/search?q=commitizen)
|
||||
- [Jest](https://jestjs.io/)
|
||||
- [ESLint](https://eslint.org/)
|
||||
- [Prettier](https://prettier.io/)
|
||||
|
||||
## Getting started
|
||||
|
||||
### Set up your repository
|
||||
|
||||
**Click the "Use this template" button.**
|
||||
|
||||
Alternatively, create a new directory and then run:
|
||||
|
||||
```bash
|
||||
curl -fsSL https://github.com/ryansonshine/typescript-npm-package-template/archive/main.tar.gz | tar -xz --strip-components=1
|
||||
```
|
||||
|
||||
Replace `FULL_NAME`, `GITHUB_USER`, and `REPO_NAME` in the script below with your own details to personalize your new package:
|
||||
|
||||
```bash
|
||||
FULL_NAME="John Smith"
|
||||
GITHUB_USER="johnsmith"
|
||||
REPO_NAME="my-cool-package"
|
||||
sed -i.mybak "s/\([\/\"]\)(ryansonshine)/$GITHUB_USER/g; s/typescript-npm-package-template\|my-package-name/$REPO_NAME/g; s/Ryan Sonshine/$FULL_NAME/g" package.json package-lock.json README.md
|
||||
rm *.mybak
|
||||
```
|
||||
|
||||
### Add NPM Token
|
||||
|
||||
Add your npm token to your GitHub repository secrets as `NPM_TOKEN`.
|
||||
|
||||
### Add Codecov integration
|
||||
|
||||
Enable the Codecov GitHub App [here](https://github.com/apps/codecov).
|
||||
|
||||
**Remove everything from here and above**
|
||||
|
||||
---
|
||||
|
||||
# my-package-name
|
||||
|
||||
[![npm package][npm-img]][npm-url]
|
||||
[![Build Status][build-img]][build-url]
|
||||
[![Downloads][downloads-img]][downloads-url]
|
||||
[![Issues][issues-img]][issues-url]
|
||||
[![Code Coverage][codecov-img]][codecov-url]
|
||||
[![Commitizen Friendly][commitizen-img]][commitizen-url]
|
||||
[![Semantic Release][semantic-release-img]][semantic-release-url]
|
||||
|
||||
> My awesome module
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
npm install my-package-name
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```ts
|
||||
import { myPackage } from 'my-package-name';
|
||||
|
||||
myPackage('hello');
|
||||
//=> 'hello from my package'
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### myPackage(input, options?)
|
||||
|
||||
#### input
|
||||
|
||||
Type: `string`
|
||||
|
||||
Lorem ipsum.
|
||||
|
||||
#### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
##### postfix
|
||||
|
||||
Type: `string`
|
||||
Default: `rainbows`
|
||||
|
||||
Lorem ipsum.
|
||||
|
||||
[build-img]:https://github.com/ryansonshine/typescript-npm-package-template/actions/workflows/release.yml/badge.svg
|
||||
[build-url]:https://github.com/ryansonshine/typescript-npm-package-template/actions/workflows/release.yml
|
||||
[downloads-img]:https://img.shields.io/npm/dt/typescript-npm-package-template
|
||||
[downloads-url]:https://www.npmtrends.com/typescript-npm-package-template
|
||||
[npm-img]:https://img.shields.io/npm/v/typescript-npm-package-template
|
||||
[npm-url]:https://www.npmjs.com/package/typescript-npm-package-template
|
||||
[issues-img]:https://img.shields.io/github/issues/ryansonshine/typescript-npm-package-template
|
||||
[issues-url]:https://github.com/ryansonshine/typescript-npm-package-template/issues
|
||||
[codecov-img]:https://codecov.io/gh/ryansonshine/typescript-npm-package-template/branch/main/graph/badge.svg
|
||||
[codecov-url]:https://codecov.io/gh/ryansonshine/typescript-npm-package-template
|
||||
[semantic-release-img]:https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
|
||||
[semantic-release-url]:https://github.com/semantic-release/semantic-release
|
||||
[commitizen-img]:https://img.shields.io/badge/commitizen-friendly-brightgreen.svg
|
||||
[commitizen-url]:http://commitizen.github.io/cz-cli/
|
||||
15
jest.config.js
Normal file
15
jest.config.js
Normal file
@@ -0,0 +1,15 @@
|
||||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
testMatch: ['**/test/**/*.spec.ts'],
|
||||
collectCoverageFrom: [
|
||||
'<rootDir>/src/**/*.ts',
|
||||
'!<rootDir>/src/types/**/*.ts',
|
||||
],
|
||||
globals: {
|
||||
'ts-jest': {
|
||||
diagnostics: false,
|
||||
isolatedModules: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
24166
package-lock.json
generated
Normal file
24166
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
128
package.json
Normal file
128
package.json
Normal file
@@ -0,0 +1,128 @@
|
||||
{
|
||||
"name": "typescript-npm-package-template",
|
||||
"version": "0.0.0-development",
|
||||
"description": "A template for creating npm packages using TypeScript and VSCode",
|
||||
"main": "./lib/index.js",
|
||||
"files": [
|
||||
"lib/**/*"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsc --project tsconfig.build.json",
|
||||
"clean": "rm -rf ./lib/",
|
||||
"cm": "cz",
|
||||
"lint": "eslint ./src/ --fix",
|
||||
"prepare": "husky install",
|
||||
"semantic-release": "semantic-release",
|
||||
"test:watch": "jest --watch",
|
||||
"test": "jest --coverage",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/ryansonshine/typescript-npm-package-template.git"
|
||||
},
|
||||
"license": "MIT",
|
||||
"author": {
|
||||
"name": "Ryan Sonshine",
|
||||
"email": "ryansonshine@users.noreply.github.com",
|
||||
"url": "https://github.com/ryansonshine"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.0"
|
||||
},
|
||||
"keywords": [
|
||||
"boilerplate",
|
||||
"template",
|
||||
"typescript",
|
||||
"vscode",
|
||||
"jest",
|
||||
"husky",
|
||||
"commitizen",
|
||||
"semantic-release",
|
||||
"codecov"
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://github.com/ryansonshine/typescript-npm-package-template/issues"
|
||||
},
|
||||
"homepage": "https://github.com/ryansonshine/typescript-npm-package-template#readme",
|
||||
"devDependencies": {
|
||||
"@ryansonshine/commitizen": "^4.2.8",
|
||||
"@ryansonshine/cz-conventional-changelog": "^3.3.4",
|
||||
"@types/jest": "^27.5.2",
|
||||
"@types/node": "^12.20.11",
|
||||
"@typescript-eslint/eslint-plugin": "^4.22.0",
|
||||
"@typescript-eslint/parser": "^4.22.0",
|
||||
"conventional-changelog-conventionalcommits": "^5.0.0",
|
||||
"eslint": "^7.25.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"eslint-plugin-prettier": "^3.4.0",
|
||||
"husky": "^6.0.0",
|
||||
"jest": "^27.2.0",
|
||||
"lint-staged": "^13.2.1",
|
||||
"prettier": "^2.2.1",
|
||||
"semantic-release": "^21.0.1",
|
||||
"ts-jest": "^27.0.5",
|
||||
"ts-node": "^10.2.1",
|
||||
"typescript": "^4.2.4"
|
||||
},
|
||||
"config": {
|
||||
"commitizen": {
|
||||
"path": "./node_modules/@ryansonshine/cz-conventional-changelog"
|
||||
}
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.ts": "eslint --cache --cache-location .eslintcache --fix"
|
||||
},
|
||||
"release": {
|
||||
"branches": [
|
||||
"main"
|
||||
],
|
||||
"plugins": [
|
||||
[
|
||||
"@semantic-release/commit-analyzer",
|
||||
{
|
||||
"preset": "conventionalcommits",
|
||||
"releaseRules": [
|
||||
{
|
||||
"type": "build",
|
||||
"scope": "deps",
|
||||
"release": "patch"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
[
|
||||
"@semantic-release/release-notes-generator",
|
||||
{
|
||||
"preset": "conventionalcommits",
|
||||
"presetConfig": {
|
||||
"types": [
|
||||
{
|
||||
"type": "feat",
|
||||
"section": "Features"
|
||||
},
|
||||
{
|
||||
"type": "fix",
|
||||
"section": "Bug Fixes"
|
||||
},
|
||||
{
|
||||
"type": "build",
|
||||
"section": "Dependencies and Other Build Updates",
|
||||
"hidden": false
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"@semantic-release/npm",
|
||||
"@semantic-release/github"
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"@noble/curves": "^1.3.0",
|
||||
"js-crypto-key-utils": "^1.0.7",
|
||||
"tree-range-set": "^1.0.4",
|
||||
"ts-chacha20": "^1.2.0"
|
||||
}
|
||||
}
|
||||
12
src/encoder.ts
Normal file
12
src/encoder.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import Chacha20 from "ts-chacha20";
|
||||
|
||||
|
||||
const DELTA_STREAM_ID = 18446744073709551615
|
||||
|
||||
export class ChaChaEncoder {
|
||||
seed: Uint8Array
|
||||
delta?: Uint8Array
|
||||
constructor(seed: number[]) {
|
||||
this.seed = new Uint8Array(seed)
|
||||
}
|
||||
}
|
||||
17
src/index.ts
Normal file
17
src/index.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { ProofInterface } from "../test/proof";
|
||||
import { verifySubstrings } from "./substrings";
|
||||
|
||||
export const verify = (proof: ProofInterface, publicKey: string): boolean => {
|
||||
const { session, substrings } = proof;
|
||||
|
||||
const { server_name, header } = session;
|
||||
|
||||
const time = parseUnixTimestamp(header.handshake_summary.time);
|
||||
const isVerified = verifySubstrings(substrings, header);
|
||||
return true;
|
||||
};
|
||||
|
||||
const parseUnixTimestamp = (timestamp: number): Date => {
|
||||
// The timestamp needs to be in milliseconds, so we multiply by 1000
|
||||
return new Date(timestamp * 1000);
|
||||
};
|
||||
135
src/substrings.ts
Normal file
135
src/substrings.ts
Normal file
@@ -0,0 +1,135 @@
|
||||
import { Direction, SessionHeaderInterface, SubstringsProofInterface } from "../test/proof";
|
||||
import { RangeSet, Range } from "tree-range-set";
|
||||
import { ChaChaEncoder } from "./encoder";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const MAX_TOTAL_COMMITTED_DATA = 1_000_000_000;
|
||||
export const TX_TRANSCRIPT_ID = "tx";
|
||||
export const RX_TRANSCRIPT_ID = "rx";
|
||||
export type TranscriptId = typeof TX_TRANSCRIPT_ID | typeof RX_TRANSCRIPT_ID;
|
||||
|
||||
export const verifySubstrings = (substringsProof: SubstringsProofInterface, header: SessionHeaderInterface) => {
|
||||
|
||||
const { openings, inclusion_proof } = substringsProof
|
||||
|
||||
|
||||
let indicies: number[] = []
|
||||
let expectedHashes = []
|
||||
|
||||
let sent = new Uint8Array(new Array(header.sent_len).fill(0))
|
||||
let recv = new Uint8Array(new Array(header.recv_len).fill(0))
|
||||
|
||||
|
||||
let sent_ranges = RangeSet.numeric()
|
||||
let recv_ranges = RangeSet.numeric()
|
||||
|
||||
let total_opened = 0
|
||||
|
||||
header.encoder_seed
|
||||
const encoder = new ChaChaEncoder(header.encoder_seed)
|
||||
|
||||
for (const key in openings) {
|
||||
console.log(key)
|
||||
const [{ ranges, direction }, opening] = openings[key]
|
||||
|
||||
|
||||
let opened_len = 0
|
||||
|
||||
const rangeSet = RangeSet.numeric()
|
||||
let maxR = 0
|
||||
ranges.forEach((range) => {
|
||||
const newRange = Range.close(range.start, range.end)
|
||||
rangeSet.add(newRange)
|
||||
opened_len += newRange.upper - newRange.lower
|
||||
maxR = Math.max(maxR, newRange.upper)
|
||||
})
|
||||
|
||||
|
||||
total_opened += opened_len;
|
||||
|
||||
// Make sure the amount of data being proved is bounded.
|
||||
if (total_opened > MAX_TOTAL_COMMITTED_DATA) {
|
||||
throw new Error("Too much data opened")
|
||||
}
|
||||
|
||||
|
||||
// Make sure the opening length matches the ranges length.
|
||||
if (opening.Blake3.data.length != opened_len) {
|
||||
throw new Error("InvalidOpening")
|
||||
}
|
||||
|
||||
|
||||
// Match direction
|
||||
if (direction === "Sent") {
|
||||
let intersects = false
|
||||
for (const sentRange of sent_ranges.subranges) {
|
||||
for (const range of rangeSet.subranges) {
|
||||
if (sentRange.intersection(range).isEmpty === false) {
|
||||
intersects = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (intersects) break
|
||||
}
|
||||
|
||||
if (intersects) throw new Error("Duplicate Data")
|
||||
}
|
||||
|
||||
if (direction === "Received") {
|
||||
let intersects = false
|
||||
for (const sentRange of recv_ranges.subranges) {
|
||||
for (const range of rangeSet.subranges) {
|
||||
if (sentRange.intersection(range).isEmpty === false) {
|
||||
intersects = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (intersects) break
|
||||
}
|
||||
|
||||
if (intersects) throw new Error("Duplicate Data")
|
||||
}
|
||||
|
||||
|
||||
let transcriptLength = 0
|
||||
|
||||
if (direction === "Sent") transcriptLength = header.sent_len
|
||||
if (direction === "Received") transcriptLength = header.recv_len
|
||||
|
||||
if (maxR > transcriptLength) throw new Error("RangeOutOfBounds")
|
||||
|
||||
|
||||
let encodings = getValueIds(rangeSet, direction)
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
export const getValueIds = (ranges: RangeSet<number>, direction: Direction): string[] => {
|
||||
|
||||
|
||||
let id = direction === "Sent" ? TX_TRANSCRIPT_ID : RX_TRANSCRIPT_ID
|
||||
const ids = []
|
||||
|
||||
|
||||
|
||||
for (const range of ranges.subranges) {
|
||||
for (let idx: number = range.lower; idx < range.upper; idx++) {
|
||||
ids.push(`${id}/${idx}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return ids
|
||||
}
|
||||
15
test/index.spec.ts
Normal file
15
test/index.spec.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { verify } from '../src';
|
||||
import { NotaryPublicKey } from './notary';
|
||||
import { Proof } from './proof';
|
||||
|
||||
describe('index', () => {
|
||||
describe('verify', () => {
|
||||
it('should return true', () => {
|
||||
const message = 'Hello';
|
||||
|
||||
const result = verify(Proof, NotaryPublicKey);
|
||||
|
||||
expect(result).toBeTruthy()
|
||||
});
|
||||
});
|
||||
});
|
||||
4
test/notary.pub
Normal file
4
test/notary.pub
Normal file
@@ -0,0 +1,4 @@
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEBv36FI4ZFszJa0DQFJ3wWCXvVLFr
|
||||
cRzMG5kaTeHGoSzDu6cFqx3uEWYpFGo6C0EOUgf+mEgbktLrXocv5yHzKg==
|
||||
-----END PUBLIC KEY-----
|
||||
5
test/notary.ts
Normal file
5
test/notary.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export const NotaryPublicKey = `-----BEGIN PUBLIC KEY-----
|
||||
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEBv36FI4ZFszJa0DQFJ3wWCXvVLFr
|
||||
cRzMG5kaTeHGoSzDu6cFqx3uEWYpFGo6C0EOUgf+mEgbktLrXocv5yHzKg==
|
||||
-----END PUBLIC KEY-----
|
||||
`
|
||||
6395
test/proof.ts
Normal file
6395
test/proof.ts
Normal file
File diff suppressed because it is too large
Load Diff
6
tsconfig.build.json
Normal file
6
tsconfig.build.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"exclude": [
|
||||
"test/**/*.spec.ts",
|
||||
]
|
||||
}
|
||||
72
tsconfig.json
Normal file
72
tsconfig.json
Normal file
@@ -0,0 +1,72 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
||||
|
||||
/* Basic Options */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
||||
// "lib": [], /* Specify library files to be included in the compilation. */
|
||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||
// "checkJs": true, /* Report errors in .js files. */
|
||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
|
||||
"declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||
"outDir": "./lib/", /* Redirect output structure to the directory. */
|
||||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
// "composite": true, /* Enable project compilation */
|
||||
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
||||
// "removeComments": true, /* Do not emit comments to output. */
|
||||
// "noEmit": true, /* Do not emit outputs. */
|
||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||
|
||||
/* Strict Type-Checking Options */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
||||
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
||||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||
|
||||
/* Additional Checks */
|
||||
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
|
||||
// "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */
|
||||
|
||||
/* Module Resolution Options */
|
||||
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||
// "types": [], /* Type declaration files to be included in compilation. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||
|
||||
/* Experimental Options */
|
||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||
|
||||
/* Advanced Options */
|
||||
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
||||
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
||||
},
|
||||
"include": ["src/**/*.ts", "test/**/*.ts"]
|
||||
}
|
||||
Reference in New Issue
Block a user